three-stdlib 2.29.0 → 2.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,14 +35,16 @@ class LineMaterial extends THREE.ShaderMaterial {
35
35
  attribute vec3 instanceStart;
36
36
  attribute vec3 instanceEnd;
37
37
 
38
- #ifdef USE_LINE_COLOR_ALPHA
39
- varying vec4 vLineColor;
40
- attribute vec4 instanceColorStart;
41
- attribute vec4 instanceColorEnd;
42
- #else
43
- varying vec3 vLineColor;
44
- attribute vec3 instanceColorStart;
45
- attribute vec3 instanceColorEnd;
38
+ #ifdef USE_COLOR
39
+ #ifdef USE_LINE_COLOR_ALPHA
40
+ varying vec4 vLineColor;
41
+ attribute vec4 instanceColorStart;
42
+ attribute vec4 instanceColorEnd;
43
+ #else
44
+ varying vec3 vLineColor;
45
+ attribute vec3 instanceColorStart;
46
+ attribute vec3 instanceColorEnd;
47
+ #endif
46
48
  #endif
47
49
 
48
50
  #ifdef WORLD_UNITS
@@ -89,7 +91,11 @@ class LineMaterial extends THREE.ShaderMaterial {
89
91
 
90
92
  void main() {
91
93
 
92
- vLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;
94
+ #ifdef USE_COLOR
95
+
96
+ vLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;
97
+
98
+ #endif
93
99
 
94
100
  #ifdef USE_DASH
95
101
 
@@ -295,10 +301,12 @@ class LineMaterial extends THREE.ShaderMaterial {
295
301
  #include <logdepthbuf_pars_fragment>
296
302
  #include <clipping_planes_pars_fragment>
297
303
 
298
- #ifdef USE_LINE_COLOR_ALPHA
299
- varying vec4 vLineColor;
300
- #else
301
- varying vec3 vLineColor;
304
+ #ifdef USE_COLOR
305
+ #ifdef USE_LINE_COLOR_ALPHA
306
+ varying vec4 vLineColor;
307
+ #else
308
+ varying vec3 vLineColor;
309
+ #endif
302
310
  #endif
303
311
 
304
312
  vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {
@@ -409,10 +417,12 @@ class LineMaterial extends THREE.ShaderMaterial {
409
417
  #endif
410
418
 
411
419
  vec4 diffuseColor = vec4( diffuse, alpha );
412
- #ifdef USE_LINE_COLOR_ALPHA
413
- diffuseColor *= vLineColor;
414
- #else
415
- diffuseColor.rgb *= vLineColor;
420
+ #ifdef USE_COLOR
421
+ #ifdef USE_LINE_COLOR_ALPHA
422
+ diffuseColor *= vLineColor;
423
+ #else
424
+ diffuseColor.rgb *= vLineColor;
425
+ #endif
416
426
  #endif
417
427
 
418
428
  #include <logdepthbuf_fragment>
@@ -1 +1 @@
1
- {"version":3,"file":"LineMaterial.cjs","sources":["../../src/lines/LineMaterial.js"],"sourcesContent":["/**\n * parameters = {\n * color: <hex>,\n * linewidth: <float>,\n * dashed: <boolean>,\n * dashScale: <float>,\n * dashSize: <float>,\n * dashOffset: <float>,\n * gapSize: <float>,\n * resolution: <Vector2>, // to be set by renderer\n * }\n */\n\nimport { ShaderMaterial, UniformsLib, UniformsUtils, Vector2, REVISION } from 'three'\n\nclass LineMaterial extends ShaderMaterial {\n constructor(parameters) {\n super({\n type: 'LineMaterial',\n\n uniforms: UniformsUtils.clone(\n UniformsUtils.merge([\n UniformsLib.common,\n UniformsLib.fog,\n {\n worldUnits: { value: 1 },\n linewidth: { value: 1 },\n resolution: { value: new Vector2(1, 1) },\n dashOffset: { value: 0 },\n dashScale: { value: 1 },\n dashSize: { value: 1 },\n gapSize: { value: 1 }, // todo FIX - maybe change to totalSize\n },\n ]),\n ),\n\n vertexShader: /* glsl */ `\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_vertex>\n\t\t\t\t#include <logdepthbuf_pars_vertex>\n\t\t\t\t#include <clipping_planes_pars_vertex>\n\n\t\t\t\tuniform float linewidth;\n\t\t\t\tuniform vec2 resolution;\n\n\t\t\t\tattribute vec3 instanceStart;\n\t\t\t\tattribute vec3 instanceEnd;\n\n\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t\tattribute vec4 instanceColorStart;\n\t\t\t\t\tattribute vec4 instanceColorEnd;\n\t\t\t\t#else\n\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t\tattribute vec3 instanceColorStart;\n\t\t\t\t\tattribute vec3 instanceColorEnd;\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashScale;\n\t\t\t\t\tattribute float instanceDistanceStart;\n\t\t\t\t\tattribute float instanceDistanceEnd;\n\t\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#endif\n\n\t\t\t\tvoid trimSegment( const in vec4 start, inout vec4 end ) {\n\n\t\t\t\t\t// trim end segment so it terminates between the camera plane and the near plane\n\n\t\t\t\t\t// conservative estimate of the near plane\n\t\t\t\t\tfloat a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column\n\t\t\t\t\tfloat b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column\n\t\t\t\t\tfloat nearEstimate = - 0.5 * b / a;\n\n\t\t\t\t\tfloat alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\n\n\t\t\t\t\tend.xyz = mix( start.xyz, end.xyz, alpha );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat aspect = resolution.x / resolution.y;\n\n\t\t\t\t\t// camera space\n\t\t\t\t\tvec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );\n\t\t\t\t\tvec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\tworldStart = start.xyz;\n\t\t\t\t\t\tworldEnd = end.xyz;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\t// special case for perspective projection, and segments that terminate either in, or behind, the camera plane\n\t\t\t\t\t// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space\n\t\t\t\t\t// but we need to perform ndc-space calculations in the shader, so we must address this issue directly\n\t\t\t\t\t// perhaps there is a more elegant solution -- WestLangley\n\n\t\t\t\t\tbool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column\n\n\t\t\t\t\tif ( perspective ) {\n\n\t\t\t\t\t\tif ( start.z < 0.0 && end.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( start, end );\n\n\t\t\t\t\t\t} else if ( end.z < 0.0 && start.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( end, start );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\t// clip space\n\t\t\t\t\tvec4 clipStart = projectionMatrix * start;\n\t\t\t\t\tvec4 clipEnd = projectionMatrix * end;\n\n\t\t\t\t\t// ndc space\n\t\t\t\t\tvec3 ndcStart = clipStart.xyz / clipStart.w;\n\t\t\t\t\tvec3 ndcEnd = clipEnd.xyz / clipEnd.w;\n\n\t\t\t\t\t// direction\n\t\t\t\t\tvec2 dir = ndcEnd.xy - ndcStart.xy;\n\n\t\t\t\t\t// account for clip-space aspect ratio\n\t\t\t\t\tdir.x *= aspect;\n\t\t\t\t\tdir = normalize( dir );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// get the offset direction as perpendicular to the view vector\n\t\t\t\t\t\tvec3 worldDir = normalize( end.xyz - start.xyz );\n\t\t\t\t\t\tvec3 offset;\n\t\t\t\t\t\tif ( position.y < 0.5 ) {\n\n\t\t\t\t\t\t\toffset = normalize( cross( start.xyz, worldDir ) );\n\n\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\toffset = normalize( cross( end.xyz, worldDir ) );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\tfloat forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );\n\n\t\t\t\t\t\t// don't extend the line if we're rendering dashes because we\n\t\t\t\t\t\t// won't be rendering the endcaps\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t// extend the line bounds to encompass endcaps\n\t\t\t\t\t\t\tstart.xyz += - worldDir * linewidth * 0.5;\n\t\t\t\t\t\t\tend.xyz += worldDir * linewidth * 0.5;\n\n\t\t\t\t\t\t\t// shift the position of the quad so it hugs the forward edge of the line\n\t\t\t\t\t\t\toffset.xy -= dir * forwardOffset;\n\t\t\t\t\t\t\toffset.z += 0.5;\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y > 1.0 || position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset.xy += dir * 2.0 * forwardOffset;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth * 0.5;\n\n\t\t\t\t\t\t// set the world position\n\t\t\t\t\t\tworldPos = ( position.y < 0.5 ) ? start : end;\n\t\t\t\t\t\tworldPos.xyz += offset;\n\n\t\t\t\t\t\t// project the worldpos\n\t\t\t\t\t\tvec4 clip = projectionMatrix * worldPos;\n\n\t\t\t\t\t\t// shift the depth of the projected points so the line\n\t\t\t\t\t\t// segments overlap neatly\n\t\t\t\t\t\tvec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;\n\t\t\t\t\t\tclip.z = clipPose.z * clip.w;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvec2 offset = vec2( dir.y, - dir.x );\n\t\t\t\t\t\t// undo aspect ratio adjustment\n\t\t\t\t\t\tdir.x /= aspect;\n\t\t\t\t\t\toffset.x /= aspect;\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset += - dir;\n\n\t\t\t\t\t\t} else if ( position.y > 1.0 ) {\n\n\t\t\t\t\t\t\toffset += dir;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth;\n\n\t\t\t\t\t\t// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...\n\t\t\t\t\t\toffset /= resolution.y;\n\n\t\t\t\t\t\t// select end\n\t\t\t\t\t\tvec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;\n\n\t\t\t\t\t\t// back to clip space\n\t\t\t\t\t\toffset *= clip.w;\n\n\t\t\t\t\t\tclip.xy += offset;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tgl_Position = clip;\n\n\t\t\t\t\tvec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation\n\n\t\t\t\t\t#include <logdepthbuf_vertex>\n\t\t\t\t\t#include <clipping_planes_vertex>\n\t\t\t\t\t#include <fog_vertex>\n\n\t\t\t\t}\n\t\t\t`,\n fragmentShader: /* glsl */ `\n\t\t\t\tuniform vec3 diffuse;\n\t\t\t\tuniform float opacity;\n\t\t\t\tuniform float linewidth;\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashOffset;\n\t\t\t\t\tuniform float dashSize;\n\t\t\t\t\tuniform float gapSize;\n\n\t\t\t\t#endif\n\n\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_fragment>\n\t\t\t\t#include <logdepthbuf_pars_fragment>\n\t\t\t\t#include <clipping_planes_pars_fragment>\n\n\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t#else\n\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t#endif\n\n\t\t\t\tvec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {\n\n\t\t\t\t\tfloat mua;\n\t\t\t\t\tfloat mub;\n\n\t\t\t\t\tvec3 p13 = p1 - p3;\n\t\t\t\t\tvec3 p43 = p4 - p3;\n\n\t\t\t\t\tvec3 p21 = p2 - p1;\n\n\t\t\t\t\tfloat d1343 = dot( p13, p43 );\n\t\t\t\t\tfloat d4321 = dot( p43, p21 );\n\t\t\t\t\tfloat d1321 = dot( p13, p21 );\n\t\t\t\t\tfloat d4343 = dot( p43, p43 );\n\t\t\t\t\tfloat d2121 = dot( p21, p21 );\n\n\t\t\t\t\tfloat denom = d2121 * d4343 - d4321 * d4321;\n\n\t\t\t\t\tfloat numer = d1343 * d4321 - d1321 * d4343;\n\n\t\t\t\t\tmua = numer / denom;\n\t\t\t\t\tmua = clamp( mua, 0.0, 1.0 );\n\t\t\t\t\tmub = ( d1343 + d4321 * ( mua ) ) / d4343;\n\t\t\t\t\tmub = clamp( mub, 0.0, 1.0 );\n\n\t\t\t\t\treturn vec2( mua, mub );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#include <clipping_planes_fragment>\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tif ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n\n\t\t\t\t\t\tif ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat alpha = opacity;\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// Find the closest points on the view ray and the line segment\n\t\t\t\t\t\tvec3 rayEnd = normalize( worldPos.xyz ) * 1e5;\n\t\t\t\t\t\tvec3 lineDir = worldEnd - worldStart;\n\t\t\t\t\t\tvec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );\n\n\t\t\t\t\t\tvec3 p1 = worldStart + lineDir * params.x;\n\t\t\t\t\t\tvec3 p2 = rayEnd * params.y;\n\t\t\t\t\t\tvec3 delta = p1 - p2;\n\t\t\t\t\t\tfloat len = length( delta );\n\t\t\t\t\t\tfloat norm = len / linewidth;\n\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t\tfloat dnorm = fwidth( norm );\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );\n\n\t\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\t\tif ( norm > 0.5 ) {\n\n\t\t\t\t\t\t\t\t\tdiscard;\n\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t// artifacts appear on some hardware if a derivative is taken within a conditional\n\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\t\t\t\t\t\t\tfloat dlen = fwidth( len2 );\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\n\t\t\t\t\t\t\t\tif ( len2 > 1.0 ) discard;\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tvec4 diffuseColor = vec4( diffuse, alpha );\n\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\tdiffuseColor *= vLineColor;\n\t\t\t\t\t#else\n\t\t\t\t\t\tdiffuseColor.rgb *= vLineColor;\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#include <logdepthbuf_fragment>\n\n\t\t\t\t\tgl_FragColor = diffuseColor;\n\n\t\t\t\t\t#include <tonemapping_fragment>\n\t\t\t\t\t#include <${parseInt(REVISION.replace(/\\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>\n\t\t\t\t\t#include <fog_fragment>\n\t\t\t\t\t#include <premultiplied_alpha_fragment>\n\n\t\t\t\t}\n\t\t\t`,\n clipping: true, // required for clipping support\n })\n\n this.isLineMaterial = true\n\n this.onBeforeCompile = function () {\n if (this.transparent) {\n this.defines.USE_LINE_COLOR_ALPHA = '1'\n } else {\n delete this.defines.USE_LINE_COLOR_ALPHA\n }\n }\n\n Object.defineProperties(this, {\n color: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.diffuse.value\n },\n\n set: function (value) {\n this.uniforms.diffuse.value = value\n },\n },\n\n worldUnits: {\n enumerable: true,\n\n get: function () {\n return 'WORLD_UNITS' in this.defines\n },\n\n set: function (value) {\n if (value === true) {\n this.defines.WORLD_UNITS = ''\n } else {\n delete this.defines.WORLD_UNITS\n }\n },\n },\n\n linewidth: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.linewidth.value\n },\n\n set: function (value) {\n this.uniforms.linewidth.value = value\n },\n },\n\n dashed: {\n enumerable: true,\n\n get: function () {\n return Boolean('USE_DASH' in this.defines)\n },\n\n set(value) {\n if (Boolean(value) !== Boolean('USE_DASH' in this.defines)) {\n this.needsUpdate = true\n }\n\n if (value === true) {\n this.defines.USE_DASH = ''\n } else {\n delete this.defines.USE_DASH\n }\n },\n },\n\n dashScale: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashScale.value\n },\n\n set: function (value) {\n this.uniforms.dashScale.value = value\n },\n },\n\n dashSize: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashSize.value\n },\n\n set: function (value) {\n this.uniforms.dashSize.value = value\n },\n },\n\n dashOffset: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashOffset.value\n },\n\n set: function (value) {\n this.uniforms.dashOffset.value = value\n },\n },\n\n gapSize: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.gapSize.value\n },\n\n set: function (value) {\n this.uniforms.gapSize.value = value\n },\n },\n\n opacity: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.opacity.value\n },\n\n set: function (value) {\n this.uniforms.opacity.value = value\n },\n },\n\n resolution: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.resolution.value\n },\n\n set: function (value) {\n this.uniforms.resolution.value.copy(value)\n },\n },\n\n alphaToCoverage: {\n enumerable: true,\n\n get: function () {\n return Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)\n },\n\n set: function (value) {\n if (Boolean(value) !== Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)) {\n this.needsUpdate = true\n }\n\n if (value === true) {\n this.defines.USE_ALPHA_TO_COVERAGE = ''\n this.extensions.derivatives = true\n } else {\n delete this.defines.USE_ALPHA_TO_COVERAGE\n this.extensions.derivatives = false\n }\n },\n },\n })\n\n this.setValues(parameters)\n }\n}\n\nexport { LineMaterial }\n"],"names":["ShaderMaterial","UniformsUtils","UniformsLib","Vector2","REVISION"],"mappings":";;;AAeA,MAAM,qBAAqBA,MAAAA,eAAe;AAAA,EACxC,YAAY,YAAY;AACtB,UAAM;AAAA,MACJ,MAAM;AAAA,MAEN,UAAUC,MAAa,cAAC;AAAA,QACtBA,MAAAA,cAAc,MAAM;AAAA,UAClBC,MAAAA,YAAY;AAAA,UACZA,MAAAA,YAAY;AAAA,UACZ;AAAA,YACE,YAAY,EAAE,OAAO,EAAG;AAAA,YACxB,WAAW,EAAE,OAAO,EAAG;AAAA,YACvB,YAAY,EAAE,OAAO,IAAIC,MAAO,QAAC,GAAG,CAAC,EAAG;AAAA,YACxC,YAAY,EAAE,OAAO,EAAG;AAAA,YACxB,WAAW,EAAE,OAAO,EAAG;AAAA,YACvB,UAAU,EAAE,OAAO,EAAG;AAAA,YACtB,SAAS,EAAE,OAAO,EAAG;AAAA;AAAA,UACtB;AAAA,QACX,CAAS;AAAA,MACF;AAAA,MAED;AAAA;AAAA,QAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AACrC,iBAAK,WAAW,cAAc;AAAA,UAC1C,OAAiB;AACL,mBAAO,KAAK,QAAQ;AACpB,iBAAK,WAAW,cAAc;AAAA,UAC/B;AAAA,QACF;AAAA,MACF;AAAA,IACP,CAAK;AAED,SAAK,UAAU,UAAU;AAAA,EAC1B;AACH;;"}
1
+ {"version":3,"file":"LineMaterial.cjs","sources":["../../src/lines/LineMaterial.js"],"sourcesContent":["/**\n * parameters = {\n * color: <hex>,\n * linewidth: <float>,\n * dashed: <boolean>,\n * dashScale: <float>,\n * dashSize: <float>,\n * dashOffset: <float>,\n * gapSize: <float>,\n * resolution: <Vector2>, // to be set by renderer\n * }\n */\n\nimport { ShaderMaterial, UniformsLib, UniformsUtils, Vector2, REVISION } from 'three'\n\nclass LineMaterial extends ShaderMaterial {\n constructor(parameters) {\n super({\n type: 'LineMaterial',\n\n uniforms: UniformsUtils.clone(\n UniformsUtils.merge([\n UniformsLib.common,\n UniformsLib.fog,\n {\n worldUnits: { value: 1 },\n linewidth: { value: 1 },\n resolution: { value: new Vector2(1, 1) },\n dashOffset: { value: 0 },\n dashScale: { value: 1 },\n dashSize: { value: 1 },\n gapSize: { value: 1 }, // todo FIX - maybe change to totalSize\n },\n ]),\n ),\n\n vertexShader: /* glsl */ `\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_vertex>\n\t\t\t\t#include <logdepthbuf_pars_vertex>\n\t\t\t\t#include <clipping_planes_pars_vertex>\n\n\t\t\t\tuniform float linewidth;\n\t\t\t\tuniform vec2 resolution;\n\n\t\t\t\tattribute vec3 instanceStart;\n\t\t\t\tattribute vec3 instanceEnd;\n\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t\t\tattribute vec4 instanceColorStart;\n\t\t\t\t\t\tattribute vec4 instanceColorEnd;\n\t\t\t\t\t#else\n\t\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t\t\tattribute vec3 instanceColorStart;\n\t\t\t\t\t\tattribute vec3 instanceColorEnd;\n\t\t\t\t\t#endif\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashScale;\n\t\t\t\t\tattribute float instanceDistanceStart;\n\t\t\t\t\tattribute float instanceDistanceEnd;\n\t\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#endif\n\n\t\t\t\tvoid trimSegment( const in vec4 start, inout vec4 end ) {\n\n\t\t\t\t\t// trim end segment so it terminates between the camera plane and the near plane\n\n\t\t\t\t\t// conservative estimate of the near plane\n\t\t\t\t\tfloat a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column\n\t\t\t\t\tfloat b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column\n\t\t\t\t\tfloat nearEstimate = - 0.5 * b / a;\n\n\t\t\t\t\tfloat alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\n\n\t\t\t\t\tend.xyz = mix( start.xyz, end.xyz, alpha );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#ifdef USE_COLOR\n\n\t\t\t\t\t\tvLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat aspect = resolution.x / resolution.y;\n\n\t\t\t\t\t// camera space\n\t\t\t\t\tvec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );\n\t\t\t\t\tvec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\tworldStart = start.xyz;\n\t\t\t\t\t\tworldEnd = end.xyz;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\t// special case for perspective projection, and segments that terminate either in, or behind, the camera plane\n\t\t\t\t\t// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space\n\t\t\t\t\t// but we need to perform ndc-space calculations in the shader, so we must address this issue directly\n\t\t\t\t\t// perhaps there is a more elegant solution -- WestLangley\n\n\t\t\t\t\tbool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column\n\n\t\t\t\t\tif ( perspective ) {\n\n\t\t\t\t\t\tif ( start.z < 0.0 && end.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( start, end );\n\n\t\t\t\t\t\t} else if ( end.z < 0.0 && start.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( end, start );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\t// clip space\n\t\t\t\t\tvec4 clipStart = projectionMatrix * start;\n\t\t\t\t\tvec4 clipEnd = projectionMatrix * end;\n\n\t\t\t\t\t// ndc space\n\t\t\t\t\tvec3 ndcStart = clipStart.xyz / clipStart.w;\n\t\t\t\t\tvec3 ndcEnd = clipEnd.xyz / clipEnd.w;\n\n\t\t\t\t\t// direction\n\t\t\t\t\tvec2 dir = ndcEnd.xy - ndcStart.xy;\n\n\t\t\t\t\t// account for clip-space aspect ratio\n\t\t\t\t\tdir.x *= aspect;\n\t\t\t\t\tdir = normalize( dir );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// get the offset direction as perpendicular to the view vector\n\t\t\t\t\t\tvec3 worldDir = normalize( end.xyz - start.xyz );\n\t\t\t\t\t\tvec3 offset;\n\t\t\t\t\t\tif ( position.y < 0.5 ) {\n\n\t\t\t\t\t\t\toffset = normalize( cross( start.xyz, worldDir ) );\n\n\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\toffset = normalize( cross( end.xyz, worldDir ) );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\tfloat forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );\n\n\t\t\t\t\t\t// don't extend the line if we're rendering dashes because we\n\t\t\t\t\t\t// won't be rendering the endcaps\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t// extend the line bounds to encompass endcaps\n\t\t\t\t\t\t\tstart.xyz += - worldDir * linewidth * 0.5;\n\t\t\t\t\t\t\tend.xyz += worldDir * linewidth * 0.5;\n\n\t\t\t\t\t\t\t// shift the position of the quad so it hugs the forward edge of the line\n\t\t\t\t\t\t\toffset.xy -= dir * forwardOffset;\n\t\t\t\t\t\t\toffset.z += 0.5;\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y > 1.0 || position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset.xy += dir * 2.0 * forwardOffset;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth * 0.5;\n\n\t\t\t\t\t\t// set the world position\n\t\t\t\t\t\tworldPos = ( position.y < 0.5 ) ? start : end;\n\t\t\t\t\t\tworldPos.xyz += offset;\n\n\t\t\t\t\t\t// project the worldpos\n\t\t\t\t\t\tvec4 clip = projectionMatrix * worldPos;\n\n\t\t\t\t\t\t// shift the depth of the projected points so the line\n\t\t\t\t\t\t// segments overlap neatly\n\t\t\t\t\t\tvec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;\n\t\t\t\t\t\tclip.z = clipPose.z * clip.w;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvec2 offset = vec2( dir.y, - dir.x );\n\t\t\t\t\t\t// undo aspect ratio adjustment\n\t\t\t\t\t\tdir.x /= aspect;\n\t\t\t\t\t\toffset.x /= aspect;\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset += - dir;\n\n\t\t\t\t\t\t} else if ( position.y > 1.0 ) {\n\n\t\t\t\t\t\t\toffset += dir;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth;\n\n\t\t\t\t\t\t// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...\n\t\t\t\t\t\toffset /= resolution.y;\n\n\t\t\t\t\t\t// select end\n\t\t\t\t\t\tvec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;\n\n\t\t\t\t\t\t// back to clip space\n\t\t\t\t\t\toffset *= clip.w;\n\n\t\t\t\t\t\tclip.xy += offset;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tgl_Position = clip;\n\n\t\t\t\t\tvec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation\n\n\t\t\t\t\t#include <logdepthbuf_vertex>\n\t\t\t\t\t#include <clipping_planes_vertex>\n\t\t\t\t\t#include <fog_vertex>\n\n\t\t\t\t}\n\t\t\t`,\n fragmentShader: /* glsl */ `\n\t\t\t\tuniform vec3 diffuse;\n\t\t\t\tuniform float opacity;\n\t\t\t\tuniform float linewidth;\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashOffset;\n\t\t\t\t\tuniform float dashSize;\n\t\t\t\t\tuniform float gapSize;\n\n\t\t\t\t#endif\n\n\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_fragment>\n\t\t\t\t#include <logdepthbuf_pars_fragment>\n\t\t\t\t#include <clipping_planes_pars_fragment>\n\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t\t#else\n\t\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t\t#endif\n\t\t\t\t#endif\n\n\t\t\t\tvec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {\n\n\t\t\t\t\tfloat mua;\n\t\t\t\t\tfloat mub;\n\n\t\t\t\t\tvec3 p13 = p1 - p3;\n\t\t\t\t\tvec3 p43 = p4 - p3;\n\n\t\t\t\t\tvec3 p21 = p2 - p1;\n\n\t\t\t\t\tfloat d1343 = dot( p13, p43 );\n\t\t\t\t\tfloat d4321 = dot( p43, p21 );\n\t\t\t\t\tfloat d1321 = dot( p13, p21 );\n\t\t\t\t\tfloat d4343 = dot( p43, p43 );\n\t\t\t\t\tfloat d2121 = dot( p21, p21 );\n\n\t\t\t\t\tfloat denom = d2121 * d4343 - d4321 * d4321;\n\n\t\t\t\t\tfloat numer = d1343 * d4321 - d1321 * d4343;\n\n\t\t\t\t\tmua = numer / denom;\n\t\t\t\t\tmua = clamp( mua, 0.0, 1.0 );\n\t\t\t\t\tmub = ( d1343 + d4321 * ( mua ) ) / d4343;\n\t\t\t\t\tmub = clamp( mub, 0.0, 1.0 );\n\n\t\t\t\t\treturn vec2( mua, mub );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#include <clipping_planes_fragment>\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tif ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n\n\t\t\t\t\t\tif ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat alpha = opacity;\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// Find the closest points on the view ray and the line segment\n\t\t\t\t\t\tvec3 rayEnd = normalize( worldPos.xyz ) * 1e5;\n\t\t\t\t\t\tvec3 lineDir = worldEnd - worldStart;\n\t\t\t\t\t\tvec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );\n\n\t\t\t\t\t\tvec3 p1 = worldStart + lineDir * params.x;\n\t\t\t\t\t\tvec3 p2 = rayEnd * params.y;\n\t\t\t\t\t\tvec3 delta = p1 - p2;\n\t\t\t\t\t\tfloat len = length( delta );\n\t\t\t\t\t\tfloat norm = len / linewidth;\n\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t\tfloat dnorm = fwidth( norm );\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );\n\n\t\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\t\tif ( norm > 0.5 ) {\n\n\t\t\t\t\t\t\t\t\tdiscard;\n\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t// artifacts appear on some hardware if a derivative is taken within a conditional\n\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\t\t\t\t\t\t\tfloat dlen = fwidth( len2 );\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\n\t\t\t\t\t\t\t\tif ( len2 > 1.0 ) discard;\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tvec4 diffuseColor = vec4( diffuse, alpha );\n\t\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\t\tdiffuseColor *= vLineColor;\n\t\t\t\t\t\t#else\n\t\t\t\t\t\t\tdiffuseColor.rgb *= vLineColor;\n\t\t\t\t\t\t#endif\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#include <logdepthbuf_fragment>\n\n\t\t\t\t\tgl_FragColor = diffuseColor;\n\n\t\t\t\t\t#include <tonemapping_fragment>\n\t\t\t\t\t#include <${parseInt(REVISION.replace(/\\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>\n\t\t\t\t\t#include <fog_fragment>\n\t\t\t\t\t#include <premultiplied_alpha_fragment>\n\n\t\t\t\t}\n\t\t\t`,\n clipping: true, // required for clipping support\n })\n\n this.isLineMaterial = true\n\n this.onBeforeCompile = function () {\n if (this.transparent) {\n this.defines.USE_LINE_COLOR_ALPHA = '1'\n } else {\n delete this.defines.USE_LINE_COLOR_ALPHA\n }\n }\n\n Object.defineProperties(this, {\n color: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.diffuse.value\n },\n\n set: function (value) {\n this.uniforms.diffuse.value = value\n },\n },\n\n worldUnits: {\n enumerable: true,\n\n get: function () {\n return 'WORLD_UNITS' in this.defines\n },\n\n set: function (value) {\n if (value === true) {\n this.defines.WORLD_UNITS = ''\n } else {\n delete this.defines.WORLD_UNITS\n }\n },\n },\n\n linewidth: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.linewidth.value\n },\n\n set: function (value) {\n this.uniforms.linewidth.value = value\n },\n },\n\n dashed: {\n enumerable: true,\n\n get: function () {\n return Boolean('USE_DASH' in this.defines)\n },\n\n set(value) {\n if (Boolean(value) !== Boolean('USE_DASH' in this.defines)) {\n this.needsUpdate = true\n }\n\n if (value === true) {\n this.defines.USE_DASH = ''\n } else {\n delete this.defines.USE_DASH\n }\n },\n },\n\n dashScale: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashScale.value\n },\n\n set: function (value) {\n this.uniforms.dashScale.value = value\n },\n },\n\n dashSize: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashSize.value\n },\n\n set: function (value) {\n this.uniforms.dashSize.value = value\n },\n },\n\n dashOffset: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashOffset.value\n },\n\n set: function (value) {\n this.uniforms.dashOffset.value = value\n },\n },\n\n gapSize: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.gapSize.value\n },\n\n set: function (value) {\n this.uniforms.gapSize.value = value\n },\n },\n\n opacity: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.opacity.value\n },\n\n set: function (value) {\n this.uniforms.opacity.value = value\n },\n },\n\n resolution: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.resolution.value\n },\n\n set: function (value) {\n this.uniforms.resolution.value.copy(value)\n },\n },\n\n alphaToCoverage: {\n enumerable: true,\n\n get: function () {\n return Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)\n },\n\n set: function (value) {\n if (Boolean(value) !== Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)) {\n this.needsUpdate = true\n }\n\n if (value === true) {\n this.defines.USE_ALPHA_TO_COVERAGE = ''\n this.extensions.derivatives = true\n } else {\n delete this.defines.USE_ALPHA_TO_COVERAGE\n this.extensions.derivatives = false\n }\n },\n },\n })\n\n this.setValues(parameters)\n }\n}\n\nexport { LineMaterial }\n"],"names":["ShaderMaterial","UniformsUtils","UniformsLib","Vector2","REVISION"],"mappings":";;;AAeA,MAAM,qBAAqBA,MAAAA,eAAe;AAAA,EACxC,YAAY,YAAY;AACtB,UAAM;AAAA,MACJ,MAAM;AAAA,MAEN,UAAUC,MAAa,cAAC;AAAA,QACtBA,MAAAA,cAAc,MAAM;AAAA,UAClBC,MAAAA,YAAY;AAAA,UACZA,MAAAA,YAAY;AAAA,UACZ;AAAA,YACE,YAAY,EAAE,OAAO,EAAG;AAAA,YACxB,WAAW,EAAE,OAAO,EAAG;AAAA,YACvB,YAAY,EAAE,OAAO,IAAIC,MAAO,QAAC,GAAG,CAAC,EAAG;AAAA,YACxC,YAAY,EAAE,OAAO,EAAG;AAAA,YACxB,WAAW,EAAE,OAAO,EAAG;AAAA,YACvB,UAAU,EAAE,OAAO,EAAG;AAAA,YACtB,SAAS,EAAE,OAAO,EAAG;AAAA;AAAA,UACtB;AAAA,QACX,CAAS;AAAA,MACF;AAAA,MAED;AAAA;AAAA,QAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AAO,GAAG;AACvE,iBAAK,cAAc;AAAA,UACpB;AAED,cAAI,UAAU,MAAM;AAClB,iBAAK,QAAQ,wBAAwB;AACrC,iBAAK,WAAW,cAAc;AAAA,UAC1C,OAAiB;AACL,mBAAO,KAAK,QAAQ;AACpB,iBAAK,WAAW,cAAc;AAAA,UAC/B;AAAA,QACF;AAAA,MACF;AAAA,IACP,CAAK;AAED,SAAK,UAAU,UAAU;AAAA,EAC1B;AACH;;"}
@@ -33,14 +33,16 @@ class LineMaterial extends ShaderMaterial {
33
33
  attribute vec3 instanceStart;
34
34
  attribute vec3 instanceEnd;
35
35
 
36
- #ifdef USE_LINE_COLOR_ALPHA
37
- varying vec4 vLineColor;
38
- attribute vec4 instanceColorStart;
39
- attribute vec4 instanceColorEnd;
40
- #else
41
- varying vec3 vLineColor;
42
- attribute vec3 instanceColorStart;
43
- attribute vec3 instanceColorEnd;
36
+ #ifdef USE_COLOR
37
+ #ifdef USE_LINE_COLOR_ALPHA
38
+ varying vec4 vLineColor;
39
+ attribute vec4 instanceColorStart;
40
+ attribute vec4 instanceColorEnd;
41
+ #else
42
+ varying vec3 vLineColor;
43
+ attribute vec3 instanceColorStart;
44
+ attribute vec3 instanceColorEnd;
45
+ #endif
44
46
  #endif
45
47
 
46
48
  #ifdef WORLD_UNITS
@@ -87,7 +89,11 @@ class LineMaterial extends ShaderMaterial {
87
89
 
88
90
  void main() {
89
91
 
90
- vLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;
92
+ #ifdef USE_COLOR
93
+
94
+ vLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;
95
+
96
+ #endif
91
97
 
92
98
  #ifdef USE_DASH
93
99
 
@@ -293,10 +299,12 @@ class LineMaterial extends ShaderMaterial {
293
299
  #include <logdepthbuf_pars_fragment>
294
300
  #include <clipping_planes_pars_fragment>
295
301
 
296
- #ifdef USE_LINE_COLOR_ALPHA
297
- varying vec4 vLineColor;
298
- #else
299
- varying vec3 vLineColor;
302
+ #ifdef USE_COLOR
303
+ #ifdef USE_LINE_COLOR_ALPHA
304
+ varying vec4 vLineColor;
305
+ #else
306
+ varying vec3 vLineColor;
307
+ #endif
300
308
  #endif
301
309
 
302
310
  vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {
@@ -407,10 +415,12 @@ class LineMaterial extends ShaderMaterial {
407
415
  #endif
408
416
 
409
417
  vec4 diffuseColor = vec4( diffuse, alpha );
410
- #ifdef USE_LINE_COLOR_ALPHA
411
- diffuseColor *= vLineColor;
412
- #else
413
- diffuseColor.rgb *= vLineColor;
418
+ #ifdef USE_COLOR
419
+ #ifdef USE_LINE_COLOR_ALPHA
420
+ diffuseColor *= vLineColor;
421
+ #else
422
+ diffuseColor.rgb *= vLineColor;
423
+ #endif
414
424
  #endif
415
425
 
416
426
  #include <logdepthbuf_fragment>
@@ -1 +1 @@
1
- {"version":3,"file":"LineMaterial.js","sources":["../../src/lines/LineMaterial.js"],"sourcesContent":["/**\n * parameters = {\n * color: <hex>,\n * linewidth: <float>,\n * dashed: <boolean>,\n * dashScale: <float>,\n * dashSize: <float>,\n * dashOffset: <float>,\n * gapSize: <float>,\n * resolution: <Vector2>, // to be set by renderer\n * }\n */\n\nimport { ShaderMaterial, UniformsLib, UniformsUtils, Vector2, REVISION } from 'three'\n\nclass LineMaterial extends ShaderMaterial {\n constructor(parameters) {\n super({\n type: 'LineMaterial',\n\n uniforms: UniformsUtils.clone(\n UniformsUtils.merge([\n UniformsLib.common,\n UniformsLib.fog,\n {\n worldUnits: { value: 1 },\n linewidth: { value: 1 },\n resolution: { value: new Vector2(1, 1) },\n dashOffset: { value: 0 },\n dashScale: { value: 1 },\n dashSize: { value: 1 },\n gapSize: { value: 1 }, // todo FIX - maybe change to totalSize\n },\n ]),\n ),\n\n vertexShader: /* glsl */ `\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_vertex>\n\t\t\t\t#include <logdepthbuf_pars_vertex>\n\t\t\t\t#include <clipping_planes_pars_vertex>\n\n\t\t\t\tuniform float linewidth;\n\t\t\t\tuniform vec2 resolution;\n\n\t\t\t\tattribute vec3 instanceStart;\n\t\t\t\tattribute vec3 instanceEnd;\n\n\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t\tattribute vec4 instanceColorStart;\n\t\t\t\t\tattribute vec4 instanceColorEnd;\n\t\t\t\t#else\n\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t\tattribute vec3 instanceColorStart;\n\t\t\t\t\tattribute vec3 instanceColorEnd;\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashScale;\n\t\t\t\t\tattribute float instanceDistanceStart;\n\t\t\t\t\tattribute float instanceDistanceEnd;\n\t\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#endif\n\n\t\t\t\tvoid trimSegment( const in vec4 start, inout vec4 end ) {\n\n\t\t\t\t\t// trim end segment so it terminates between the camera plane and the near plane\n\n\t\t\t\t\t// conservative estimate of the near plane\n\t\t\t\t\tfloat a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column\n\t\t\t\t\tfloat b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column\n\t\t\t\t\tfloat nearEstimate = - 0.5 * b / a;\n\n\t\t\t\t\tfloat alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\n\n\t\t\t\t\tend.xyz = mix( start.xyz, end.xyz, alpha );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat aspect = resolution.x / resolution.y;\n\n\t\t\t\t\t// camera space\n\t\t\t\t\tvec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );\n\t\t\t\t\tvec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\tworldStart = start.xyz;\n\t\t\t\t\t\tworldEnd = end.xyz;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\t// special case for perspective projection, and segments that terminate either in, or behind, the camera plane\n\t\t\t\t\t// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space\n\t\t\t\t\t// but we need to perform ndc-space calculations in the shader, so we must address this issue directly\n\t\t\t\t\t// perhaps there is a more elegant solution -- WestLangley\n\n\t\t\t\t\tbool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column\n\n\t\t\t\t\tif ( perspective ) {\n\n\t\t\t\t\t\tif ( start.z < 0.0 && end.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( start, end );\n\n\t\t\t\t\t\t} else if ( end.z < 0.0 && start.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( end, start );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\t// clip space\n\t\t\t\t\tvec4 clipStart = projectionMatrix * start;\n\t\t\t\t\tvec4 clipEnd = projectionMatrix * end;\n\n\t\t\t\t\t// ndc space\n\t\t\t\t\tvec3 ndcStart = clipStart.xyz / clipStart.w;\n\t\t\t\t\tvec3 ndcEnd = clipEnd.xyz / clipEnd.w;\n\n\t\t\t\t\t// direction\n\t\t\t\t\tvec2 dir = ndcEnd.xy - ndcStart.xy;\n\n\t\t\t\t\t// account for clip-space aspect ratio\n\t\t\t\t\tdir.x *= aspect;\n\t\t\t\t\tdir = normalize( dir );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// get the offset direction as perpendicular to the view vector\n\t\t\t\t\t\tvec3 worldDir = normalize( end.xyz - start.xyz );\n\t\t\t\t\t\tvec3 offset;\n\t\t\t\t\t\tif ( position.y < 0.5 ) {\n\n\t\t\t\t\t\t\toffset = normalize( cross( start.xyz, worldDir ) );\n\n\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\toffset = normalize( cross( end.xyz, worldDir ) );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\tfloat forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );\n\n\t\t\t\t\t\t// don't extend the line if we're rendering dashes because we\n\t\t\t\t\t\t// won't be rendering the endcaps\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t// extend the line bounds to encompass endcaps\n\t\t\t\t\t\t\tstart.xyz += - worldDir * linewidth * 0.5;\n\t\t\t\t\t\t\tend.xyz += worldDir * linewidth * 0.5;\n\n\t\t\t\t\t\t\t// shift the position of the quad so it hugs the forward edge of the line\n\t\t\t\t\t\t\toffset.xy -= dir * forwardOffset;\n\t\t\t\t\t\t\toffset.z += 0.5;\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y > 1.0 || position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset.xy += dir * 2.0 * forwardOffset;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth * 0.5;\n\n\t\t\t\t\t\t// set the world position\n\t\t\t\t\t\tworldPos = ( position.y < 0.5 ) ? start : end;\n\t\t\t\t\t\tworldPos.xyz += offset;\n\n\t\t\t\t\t\t// project the worldpos\n\t\t\t\t\t\tvec4 clip = projectionMatrix * worldPos;\n\n\t\t\t\t\t\t// shift the depth of the projected points so the line\n\t\t\t\t\t\t// segments overlap neatly\n\t\t\t\t\t\tvec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;\n\t\t\t\t\t\tclip.z = clipPose.z * clip.w;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvec2 offset = vec2( dir.y, - dir.x );\n\t\t\t\t\t\t// undo aspect ratio adjustment\n\t\t\t\t\t\tdir.x /= aspect;\n\t\t\t\t\t\toffset.x /= aspect;\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset += - dir;\n\n\t\t\t\t\t\t} else if ( position.y > 1.0 ) {\n\n\t\t\t\t\t\t\toffset += dir;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth;\n\n\t\t\t\t\t\t// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...\n\t\t\t\t\t\toffset /= resolution.y;\n\n\t\t\t\t\t\t// select end\n\t\t\t\t\t\tvec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;\n\n\t\t\t\t\t\t// back to clip space\n\t\t\t\t\t\toffset *= clip.w;\n\n\t\t\t\t\t\tclip.xy += offset;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tgl_Position = clip;\n\n\t\t\t\t\tvec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation\n\n\t\t\t\t\t#include <logdepthbuf_vertex>\n\t\t\t\t\t#include <clipping_planes_vertex>\n\t\t\t\t\t#include <fog_vertex>\n\n\t\t\t\t}\n\t\t\t`,\n fragmentShader: /* glsl */ `\n\t\t\t\tuniform vec3 diffuse;\n\t\t\t\tuniform float opacity;\n\t\t\t\tuniform float linewidth;\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashOffset;\n\t\t\t\t\tuniform float dashSize;\n\t\t\t\t\tuniform float gapSize;\n\n\t\t\t\t#endif\n\n\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_fragment>\n\t\t\t\t#include <logdepthbuf_pars_fragment>\n\t\t\t\t#include <clipping_planes_pars_fragment>\n\n\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t#else\n\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t#endif\n\n\t\t\t\tvec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {\n\n\t\t\t\t\tfloat mua;\n\t\t\t\t\tfloat mub;\n\n\t\t\t\t\tvec3 p13 = p1 - p3;\n\t\t\t\t\tvec3 p43 = p4 - p3;\n\n\t\t\t\t\tvec3 p21 = p2 - p1;\n\n\t\t\t\t\tfloat d1343 = dot( p13, p43 );\n\t\t\t\t\tfloat d4321 = dot( p43, p21 );\n\t\t\t\t\tfloat d1321 = dot( p13, p21 );\n\t\t\t\t\tfloat d4343 = dot( p43, p43 );\n\t\t\t\t\tfloat d2121 = dot( p21, p21 );\n\n\t\t\t\t\tfloat denom = d2121 * d4343 - d4321 * d4321;\n\n\t\t\t\t\tfloat numer = d1343 * d4321 - d1321 * d4343;\n\n\t\t\t\t\tmua = numer / denom;\n\t\t\t\t\tmua = clamp( mua, 0.0, 1.0 );\n\t\t\t\t\tmub = ( d1343 + d4321 * ( mua ) ) / d4343;\n\t\t\t\t\tmub = clamp( mub, 0.0, 1.0 );\n\n\t\t\t\t\treturn vec2( mua, mub );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#include <clipping_planes_fragment>\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tif ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n\n\t\t\t\t\t\tif ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat alpha = opacity;\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// Find the closest points on the view ray and the line segment\n\t\t\t\t\t\tvec3 rayEnd = normalize( worldPos.xyz ) * 1e5;\n\t\t\t\t\t\tvec3 lineDir = worldEnd - worldStart;\n\t\t\t\t\t\tvec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );\n\n\t\t\t\t\t\tvec3 p1 = worldStart + lineDir * params.x;\n\t\t\t\t\t\tvec3 p2 = rayEnd * params.y;\n\t\t\t\t\t\tvec3 delta = p1 - p2;\n\t\t\t\t\t\tfloat len = length( delta );\n\t\t\t\t\t\tfloat norm = len / linewidth;\n\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t\tfloat dnorm = fwidth( norm );\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );\n\n\t\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\t\tif ( norm > 0.5 ) {\n\n\t\t\t\t\t\t\t\t\tdiscard;\n\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t// artifacts appear on some hardware if a derivative is taken within a conditional\n\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\t\t\t\t\t\t\tfloat dlen = fwidth( len2 );\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\n\t\t\t\t\t\t\t\tif ( len2 > 1.0 ) discard;\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tvec4 diffuseColor = vec4( diffuse, alpha );\n\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\tdiffuseColor *= vLineColor;\n\t\t\t\t\t#else\n\t\t\t\t\t\tdiffuseColor.rgb *= vLineColor;\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#include <logdepthbuf_fragment>\n\n\t\t\t\t\tgl_FragColor = diffuseColor;\n\n\t\t\t\t\t#include <tonemapping_fragment>\n\t\t\t\t\t#include <${parseInt(REVISION.replace(/\\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>\n\t\t\t\t\t#include <fog_fragment>\n\t\t\t\t\t#include <premultiplied_alpha_fragment>\n\n\t\t\t\t}\n\t\t\t`,\n clipping: true, // required for clipping support\n })\n\n this.isLineMaterial = true\n\n this.onBeforeCompile = function () {\n if (this.transparent) {\n this.defines.USE_LINE_COLOR_ALPHA = '1'\n } else {\n delete this.defines.USE_LINE_COLOR_ALPHA\n }\n }\n\n Object.defineProperties(this, {\n color: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.diffuse.value\n },\n\n set: function (value) {\n this.uniforms.diffuse.value = value\n },\n },\n\n worldUnits: {\n enumerable: true,\n\n get: function () {\n return 'WORLD_UNITS' in this.defines\n },\n\n set: function (value) {\n if (value === true) {\n this.defines.WORLD_UNITS = ''\n } else {\n delete this.defines.WORLD_UNITS\n }\n },\n },\n\n linewidth: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.linewidth.value\n },\n\n set: function (value) {\n this.uniforms.linewidth.value = value\n },\n },\n\n dashed: {\n enumerable: true,\n\n get: function () {\n return Boolean('USE_DASH' in this.defines)\n },\n\n set(value) {\n if (Boolean(value) !== Boolean('USE_DASH' in this.defines)) {\n this.needsUpdate = true\n }\n\n if (value === true) {\n this.defines.USE_DASH = ''\n } else {\n delete this.defines.USE_DASH\n }\n },\n },\n\n dashScale: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashScale.value\n },\n\n set: function (value) {\n this.uniforms.dashScale.value = value\n },\n },\n\n dashSize: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashSize.value\n },\n\n set: function (value) {\n this.uniforms.dashSize.value = value\n },\n },\n\n dashOffset: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashOffset.value\n },\n\n set: function (value) {\n this.uniforms.dashOffset.value = value\n },\n },\n\n gapSize: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.gapSize.value\n },\n\n set: function (value) {\n this.uniforms.gapSize.value = value\n },\n },\n\n opacity: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.opacity.value\n },\n\n set: function (value) {\n this.uniforms.opacity.value = value\n },\n },\n\n resolution: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.resolution.value\n },\n\n set: function (value) {\n this.uniforms.resolution.value.copy(value)\n },\n },\n\n alphaToCoverage: {\n enumerable: true,\n\n get: function () {\n return Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)\n },\n\n set: function (value) {\n if (Boolean(value) !== Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)) {\n this.needsUpdate = true\n }\n\n if (value === true) {\n this.defines.USE_ALPHA_TO_COVERAGE = ''\n this.extensions.derivatives = true\n } else {\n delete this.defines.USE_ALPHA_TO_COVERAGE\n this.extensions.derivatives = false\n }\n },\n },\n })\n\n this.setValues(parameters)\n }\n}\n\nexport { LineMaterial }\n"],"names":[],"mappings":";AAeA,MAAM,qBAAqB,eAAe;AAAA,EACxC,YAAY,YAAY;AACtB,UAAM;AAAA,MACJ,MAAM;AAAA,MAEN,UAAU,cAAc;AAAA,QACtB,cAAc,MAAM;AAAA,UAClB,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ;AAAA,YACE,YAAY,EAAE,OAAO,EAAG;AAAA,YACxB,WAAW,EAAE,OAAO,EAAG;AAAA,YACvB,YAAY,EAAE,OAAO,IAAI,QAAQ,GAAG,CAAC,EAAG;AAAA,YACxC,YAAY,EAAE,OAAO,EAAG;AAAA,YACxB,WAAW,EAAE,OAAO,EAAG;AAAA,YACvB,UAAU,EAAE,OAAO,EAAG;AAAA,YACtB,SAAS,EAAE,OAAO,EAAG;AAAA;AAAA,UACtB;AAAA,QACX,CAAS;AAAA,MACF;AAAA,MAED;AAAA;AAAA,QAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AAc;AAAA,UACpB;AAED,cAAI,UAAU,MAAM;AAClB,iBAAK,QAAQ,wBAAwB;AACrC,iBAAK,WAAW,cAAc;AAAA,UAC1C,OAAiB;AACL,mBAAO,KAAK,QAAQ;AACpB,iBAAK,WAAW,cAAc;AAAA,UAC/B;AAAA,QACF;AAAA,MACF;AAAA,IACP,CAAK;AAED,SAAK,UAAU,UAAU;AAAA,EAC1B;AACH;"}
1
+ {"version":3,"file":"LineMaterial.js","sources":["../../src/lines/LineMaterial.js"],"sourcesContent":["/**\n * parameters = {\n * color: <hex>,\n * linewidth: <float>,\n * dashed: <boolean>,\n * dashScale: <float>,\n * dashSize: <float>,\n * dashOffset: <float>,\n * gapSize: <float>,\n * resolution: <Vector2>, // to be set by renderer\n * }\n */\n\nimport { ShaderMaterial, UniformsLib, UniformsUtils, Vector2, REVISION } from 'three'\n\nclass LineMaterial extends ShaderMaterial {\n constructor(parameters) {\n super({\n type: 'LineMaterial',\n\n uniforms: UniformsUtils.clone(\n UniformsUtils.merge([\n UniformsLib.common,\n UniformsLib.fog,\n {\n worldUnits: { value: 1 },\n linewidth: { value: 1 },\n resolution: { value: new Vector2(1, 1) },\n dashOffset: { value: 0 },\n dashScale: { value: 1 },\n dashSize: { value: 1 },\n gapSize: { value: 1 }, // todo FIX - maybe change to totalSize\n },\n ]),\n ),\n\n vertexShader: /* glsl */ `\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_vertex>\n\t\t\t\t#include <logdepthbuf_pars_vertex>\n\t\t\t\t#include <clipping_planes_pars_vertex>\n\n\t\t\t\tuniform float linewidth;\n\t\t\t\tuniform vec2 resolution;\n\n\t\t\t\tattribute vec3 instanceStart;\n\t\t\t\tattribute vec3 instanceEnd;\n\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t\t\tattribute vec4 instanceColorStart;\n\t\t\t\t\t\tattribute vec4 instanceColorEnd;\n\t\t\t\t\t#else\n\t\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t\t\tattribute vec3 instanceColorStart;\n\t\t\t\t\t\tattribute vec3 instanceColorEnd;\n\t\t\t\t\t#endif\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashScale;\n\t\t\t\t\tattribute float instanceDistanceStart;\n\t\t\t\t\tattribute float instanceDistanceEnd;\n\t\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#endif\n\n\t\t\t\tvoid trimSegment( const in vec4 start, inout vec4 end ) {\n\n\t\t\t\t\t// trim end segment so it terminates between the camera plane and the near plane\n\n\t\t\t\t\t// conservative estimate of the near plane\n\t\t\t\t\tfloat a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column\n\t\t\t\t\tfloat b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column\n\t\t\t\t\tfloat nearEstimate = - 0.5 * b / a;\n\n\t\t\t\t\tfloat alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\n\n\t\t\t\t\tend.xyz = mix( start.xyz, end.xyz, alpha );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#ifdef USE_COLOR\n\n\t\t\t\t\t\tvLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat aspect = resolution.x / resolution.y;\n\n\t\t\t\t\t// camera space\n\t\t\t\t\tvec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );\n\t\t\t\t\tvec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\tworldStart = start.xyz;\n\t\t\t\t\t\tworldEnd = end.xyz;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\t// special case for perspective projection, and segments that terminate either in, or behind, the camera plane\n\t\t\t\t\t// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space\n\t\t\t\t\t// but we need to perform ndc-space calculations in the shader, so we must address this issue directly\n\t\t\t\t\t// perhaps there is a more elegant solution -- WestLangley\n\n\t\t\t\t\tbool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column\n\n\t\t\t\t\tif ( perspective ) {\n\n\t\t\t\t\t\tif ( start.z < 0.0 && end.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( start, end );\n\n\t\t\t\t\t\t} else if ( end.z < 0.0 && start.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( end, start );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\t// clip space\n\t\t\t\t\tvec4 clipStart = projectionMatrix * start;\n\t\t\t\t\tvec4 clipEnd = projectionMatrix * end;\n\n\t\t\t\t\t// ndc space\n\t\t\t\t\tvec3 ndcStart = clipStart.xyz / clipStart.w;\n\t\t\t\t\tvec3 ndcEnd = clipEnd.xyz / clipEnd.w;\n\n\t\t\t\t\t// direction\n\t\t\t\t\tvec2 dir = ndcEnd.xy - ndcStart.xy;\n\n\t\t\t\t\t// account for clip-space aspect ratio\n\t\t\t\t\tdir.x *= aspect;\n\t\t\t\t\tdir = normalize( dir );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// get the offset direction as perpendicular to the view vector\n\t\t\t\t\t\tvec3 worldDir = normalize( end.xyz - start.xyz );\n\t\t\t\t\t\tvec3 offset;\n\t\t\t\t\t\tif ( position.y < 0.5 ) {\n\n\t\t\t\t\t\t\toffset = normalize( cross( start.xyz, worldDir ) );\n\n\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\toffset = normalize( cross( end.xyz, worldDir ) );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\tfloat forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );\n\n\t\t\t\t\t\t// don't extend the line if we're rendering dashes because we\n\t\t\t\t\t\t// won't be rendering the endcaps\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t// extend the line bounds to encompass endcaps\n\t\t\t\t\t\t\tstart.xyz += - worldDir * linewidth * 0.5;\n\t\t\t\t\t\t\tend.xyz += worldDir * linewidth * 0.5;\n\n\t\t\t\t\t\t\t// shift the position of the quad so it hugs the forward edge of the line\n\t\t\t\t\t\t\toffset.xy -= dir * forwardOffset;\n\t\t\t\t\t\t\toffset.z += 0.5;\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y > 1.0 || position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset.xy += dir * 2.0 * forwardOffset;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth * 0.5;\n\n\t\t\t\t\t\t// set the world position\n\t\t\t\t\t\tworldPos = ( position.y < 0.5 ) ? start : end;\n\t\t\t\t\t\tworldPos.xyz += offset;\n\n\t\t\t\t\t\t// project the worldpos\n\t\t\t\t\t\tvec4 clip = projectionMatrix * worldPos;\n\n\t\t\t\t\t\t// shift the depth of the projected points so the line\n\t\t\t\t\t\t// segments overlap neatly\n\t\t\t\t\t\tvec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;\n\t\t\t\t\t\tclip.z = clipPose.z * clip.w;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvec2 offset = vec2( dir.y, - dir.x );\n\t\t\t\t\t\t// undo aspect ratio adjustment\n\t\t\t\t\t\tdir.x /= aspect;\n\t\t\t\t\t\toffset.x /= aspect;\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset += - dir;\n\n\t\t\t\t\t\t} else if ( position.y > 1.0 ) {\n\n\t\t\t\t\t\t\toffset += dir;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth;\n\n\t\t\t\t\t\t// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...\n\t\t\t\t\t\toffset /= resolution.y;\n\n\t\t\t\t\t\t// select end\n\t\t\t\t\t\tvec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;\n\n\t\t\t\t\t\t// back to clip space\n\t\t\t\t\t\toffset *= clip.w;\n\n\t\t\t\t\t\tclip.xy += offset;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tgl_Position = clip;\n\n\t\t\t\t\tvec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation\n\n\t\t\t\t\t#include <logdepthbuf_vertex>\n\t\t\t\t\t#include <clipping_planes_vertex>\n\t\t\t\t\t#include <fog_vertex>\n\n\t\t\t\t}\n\t\t\t`,\n fragmentShader: /* glsl */ `\n\t\t\t\tuniform vec3 diffuse;\n\t\t\t\tuniform float opacity;\n\t\t\t\tuniform float linewidth;\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashOffset;\n\t\t\t\t\tuniform float dashSize;\n\t\t\t\t\tuniform float gapSize;\n\n\t\t\t\t#endif\n\n\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_fragment>\n\t\t\t\t#include <logdepthbuf_pars_fragment>\n\t\t\t\t#include <clipping_planes_pars_fragment>\n\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t\t#else\n\t\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t\t#endif\n\t\t\t\t#endif\n\n\t\t\t\tvec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {\n\n\t\t\t\t\tfloat mua;\n\t\t\t\t\tfloat mub;\n\n\t\t\t\t\tvec3 p13 = p1 - p3;\n\t\t\t\t\tvec3 p43 = p4 - p3;\n\n\t\t\t\t\tvec3 p21 = p2 - p1;\n\n\t\t\t\t\tfloat d1343 = dot( p13, p43 );\n\t\t\t\t\tfloat d4321 = dot( p43, p21 );\n\t\t\t\t\tfloat d1321 = dot( p13, p21 );\n\t\t\t\t\tfloat d4343 = dot( p43, p43 );\n\t\t\t\t\tfloat d2121 = dot( p21, p21 );\n\n\t\t\t\t\tfloat denom = d2121 * d4343 - d4321 * d4321;\n\n\t\t\t\t\tfloat numer = d1343 * d4321 - d1321 * d4343;\n\n\t\t\t\t\tmua = numer / denom;\n\t\t\t\t\tmua = clamp( mua, 0.0, 1.0 );\n\t\t\t\t\tmub = ( d1343 + d4321 * ( mua ) ) / d4343;\n\t\t\t\t\tmub = clamp( mub, 0.0, 1.0 );\n\n\t\t\t\t\treturn vec2( mua, mub );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#include <clipping_planes_fragment>\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tif ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n\n\t\t\t\t\t\tif ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat alpha = opacity;\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// Find the closest points on the view ray and the line segment\n\t\t\t\t\t\tvec3 rayEnd = normalize( worldPos.xyz ) * 1e5;\n\t\t\t\t\t\tvec3 lineDir = worldEnd - worldStart;\n\t\t\t\t\t\tvec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );\n\n\t\t\t\t\t\tvec3 p1 = worldStart + lineDir * params.x;\n\t\t\t\t\t\tvec3 p2 = rayEnd * params.y;\n\t\t\t\t\t\tvec3 delta = p1 - p2;\n\t\t\t\t\t\tfloat len = length( delta );\n\t\t\t\t\t\tfloat norm = len / linewidth;\n\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t\tfloat dnorm = fwidth( norm );\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );\n\n\t\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\t\tif ( norm > 0.5 ) {\n\n\t\t\t\t\t\t\t\t\tdiscard;\n\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t// artifacts appear on some hardware if a derivative is taken within a conditional\n\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\t\t\t\t\t\t\tfloat dlen = fwidth( len2 );\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\n\t\t\t\t\t\t\t\tif ( len2 > 1.0 ) discard;\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tvec4 diffuseColor = vec4( diffuse, alpha );\n\t\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\t\tdiffuseColor *= vLineColor;\n\t\t\t\t\t\t#else\n\t\t\t\t\t\t\tdiffuseColor.rgb *= vLineColor;\n\t\t\t\t\t\t#endif\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#include <logdepthbuf_fragment>\n\n\t\t\t\t\tgl_FragColor = diffuseColor;\n\n\t\t\t\t\t#include <tonemapping_fragment>\n\t\t\t\t\t#include <${parseInt(REVISION.replace(/\\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>\n\t\t\t\t\t#include <fog_fragment>\n\t\t\t\t\t#include <premultiplied_alpha_fragment>\n\n\t\t\t\t}\n\t\t\t`,\n clipping: true, // required for clipping support\n })\n\n this.isLineMaterial = true\n\n this.onBeforeCompile = function () {\n if (this.transparent) {\n this.defines.USE_LINE_COLOR_ALPHA = '1'\n } else {\n delete this.defines.USE_LINE_COLOR_ALPHA\n }\n }\n\n Object.defineProperties(this, {\n color: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.diffuse.value\n },\n\n set: function (value) {\n this.uniforms.diffuse.value = value\n },\n },\n\n worldUnits: {\n enumerable: true,\n\n get: function () {\n return 'WORLD_UNITS' in this.defines\n },\n\n set: function (value) {\n if (value === true) {\n this.defines.WORLD_UNITS = ''\n } else {\n delete this.defines.WORLD_UNITS\n }\n },\n },\n\n linewidth: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.linewidth.value\n },\n\n set: function (value) {\n this.uniforms.linewidth.value = value\n },\n },\n\n dashed: {\n enumerable: true,\n\n get: function () {\n return Boolean('USE_DASH' in this.defines)\n },\n\n set(value) {\n if (Boolean(value) !== Boolean('USE_DASH' in this.defines)) {\n this.needsUpdate = true\n }\n\n if (value === true) {\n this.defines.USE_DASH = ''\n } else {\n delete this.defines.USE_DASH\n }\n },\n },\n\n dashScale: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashScale.value\n },\n\n set: function (value) {\n this.uniforms.dashScale.value = value\n },\n },\n\n dashSize: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashSize.value\n },\n\n set: function (value) {\n this.uniforms.dashSize.value = value\n },\n },\n\n dashOffset: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.dashOffset.value\n },\n\n set: function (value) {\n this.uniforms.dashOffset.value = value\n },\n },\n\n gapSize: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.gapSize.value\n },\n\n set: function (value) {\n this.uniforms.gapSize.value = value\n },\n },\n\n opacity: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.opacity.value\n },\n\n set: function (value) {\n this.uniforms.opacity.value = value\n },\n },\n\n resolution: {\n enumerable: true,\n\n get: function () {\n return this.uniforms.resolution.value\n },\n\n set: function (value) {\n this.uniforms.resolution.value.copy(value)\n },\n },\n\n alphaToCoverage: {\n enumerable: true,\n\n get: function () {\n return Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)\n },\n\n set: function (value) {\n if (Boolean(value) !== Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)) {\n this.needsUpdate = true\n }\n\n if (value === true) {\n this.defines.USE_ALPHA_TO_COVERAGE = ''\n this.extensions.derivatives = true\n } else {\n delete this.defines.USE_ALPHA_TO_COVERAGE\n this.extensions.derivatives = false\n }\n },\n },\n })\n\n this.setValues(parameters)\n }\n}\n\nexport { LineMaterial }\n"],"names":[],"mappings":";AAeA,MAAM,qBAAqB,eAAe;AAAA,EACxC,YAAY,YAAY;AACtB,UAAM;AAAA,MACJ,MAAM;AAAA,MAEN,UAAU,cAAc;AAAA,QACtB,cAAc,MAAM;AAAA,UAClB,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ;AAAA,YACE,YAAY,EAAE,OAAO,EAAG;AAAA,YACxB,WAAW,EAAE,OAAO,EAAG;AAAA,YACvB,YAAY,EAAE,OAAO,IAAI,QAAQ,GAAG,CAAC,EAAG;AAAA,YACxC,YAAY,EAAE,OAAO,EAAG;AAAA,YACxB,WAAW,EAAE,OAAO,EAAG;AAAA,YACvB,UAAU,EAAE,OAAO,EAAG;AAAA,YACtB,SAAS,EAAE,OAAO,EAAG;AAAA;AAAA,UACtB;AAAA,QACX,CAAS;AAAA,MACF;AAAA,MAED;AAAA;AAAA,QAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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cAAc;AAAA,UACpB;AAED,cAAI,UAAU,MAAM;AAClB,iBAAK,QAAQ,wBAAwB;AACrC,iBAAK,WAAW,cAAc;AAAA,UAC1C,OAAiB;AACL,mBAAO,KAAK,QAAQ;AACpB,iBAAK,WAAW,cAAc;AAAA,UAC/B;AAAA,QACF;AAAA,MACF;AAAA,IACP,CAAK;AAED,SAAK,UAAU,UAAU;AAAA,EAC1B;AACH;"}
@@ -54,7 +54,7 @@ class LineSegmentsGeometry extends THREE.InstancedBufferGeometry {
54
54
  }
55
55
  const instanceColorBuffer = new THREE.InstancedInterleavedBuffer(colors, itemSize * 2, 1);
56
56
  this.setAttribute("instanceColorStart", new THREE.InterleavedBufferAttribute(instanceColorBuffer, itemSize, 0));
57
- this.setAttribute("instanceColorEnd", new THREE.InterleavedBufferAttribute(instanceColorBuffer, itemSize, 3));
57
+ this.setAttribute("instanceColorEnd", new THREE.InterleavedBufferAttribute(instanceColorBuffer, itemSize, itemSize));
58
58
  return this;
59
59
  }
60
60
  fromWireframeGeometry(geometry) {
@@ -1 +1 @@
1
- {"version":3,"file":"LineSegmentsGeometry.cjs","sources":["../../src/lines/LineSegmentsGeometry.js"],"sourcesContent":["import {\n Box3,\n Float32BufferAttribute,\n InstancedBufferGeometry,\n InstancedInterleavedBuffer,\n InterleavedBufferAttribute,\n Sphere,\n Vector3,\n WireframeGeometry,\n} from 'three'\n\nconst _box = new Box3()\nconst _vector = new Vector3()\n\nclass LineSegmentsGeometry extends InstancedBufferGeometry {\n constructor() {\n super()\n\n this.isLineSegmentsGeometry = true\n\n this.type = 'LineSegmentsGeometry'\n\n const positions = [-1, 2, 0, 1, 2, 0, -1, 1, 0, 1, 1, 0, -1, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, 0]\n const uvs = [-1, 2, 1, 2, -1, 1, 1, 1, -1, -1, 1, -1, -1, -2, 1, -2]\n const index = [0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5]\n\n this.setIndex(index)\n this.setAttribute('position', new Float32BufferAttribute(positions, 3))\n this.setAttribute('uv', new Float32BufferAttribute(uvs, 2))\n }\n\n applyMatrix4(matrix) {\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined) {\n start.applyMatrix4(matrix)\n\n end.applyMatrix4(matrix)\n\n start.needsUpdate = true\n }\n\n if (this.boundingBox !== null) {\n this.computeBoundingBox()\n }\n\n if (this.boundingSphere !== null) {\n this.computeBoundingSphere()\n }\n\n return this\n }\n\n setPositions(array) {\n let lineSegments\n\n if (array instanceof Float32Array) {\n lineSegments = array\n } else if (Array.isArray(array)) {\n lineSegments = new Float32Array(array)\n }\n\n const instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1) // xyz, xyz\n\n this.setAttribute('instanceStart', new InterleavedBufferAttribute(instanceBuffer, 3, 0)) // xyz\n this.setAttribute('instanceEnd', new InterleavedBufferAttribute(instanceBuffer, 3, 3)) // xyz\n\n //\n\n this.computeBoundingBox()\n this.computeBoundingSphere()\n\n return this\n }\n\n setColors(array, itemSize = 3) {\n let colors\n\n if (array instanceof Float32Array) {\n colors = array\n } else if (Array.isArray(array)) {\n colors = new Float32Array(array)\n }\n\n const instanceColorBuffer = new InstancedInterleavedBuffer(colors, itemSize * 2, 1) // rgb(a), rgb(a)\n\n this.setAttribute('instanceColorStart', new InterleavedBufferAttribute(instanceColorBuffer, itemSize, 0)) // rgb(a)\n this.setAttribute('instanceColorEnd', new InterleavedBufferAttribute(instanceColorBuffer, itemSize, 3)) // rgb(a)\n\n return this\n }\n\n fromWireframeGeometry(geometry) {\n this.setPositions(geometry.attributes.position.array)\n\n return this\n }\n\n fromEdgesGeometry(geometry) {\n this.setPositions(geometry.attributes.position.array)\n\n return this\n }\n\n fromMesh(mesh) {\n this.fromWireframeGeometry(new WireframeGeometry(mesh.geometry))\n\n // set colors, maybe\n\n return this\n }\n\n fromLineSegments(lineSegments) {\n const geometry = lineSegments.geometry\n\n this.setPositions(geometry.attributes.position.array) // assumes non-indexed\n\n // set colors, maybe\n\n return this\n }\n\n computeBoundingBox() {\n if (this.boundingBox === null) {\n this.boundingBox = new Box3()\n }\n\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined && end !== undefined) {\n this.boundingBox.setFromBufferAttribute(start)\n\n _box.setFromBufferAttribute(end)\n\n this.boundingBox.union(_box)\n }\n }\n\n computeBoundingSphere() {\n if (this.boundingSphere === null) {\n this.boundingSphere = new Sphere()\n }\n\n if (this.boundingBox === null) {\n this.computeBoundingBox()\n }\n\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined && end !== undefined) {\n const center = this.boundingSphere.center\n\n this.boundingBox.getCenter(center)\n\n let maxRadiusSq = 0\n\n for (let i = 0, il = start.count; i < il; i++) {\n _vector.fromBufferAttribute(start, i)\n maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector))\n\n _vector.fromBufferAttribute(end, i)\n maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector))\n }\n\n this.boundingSphere.radius = Math.sqrt(maxRadiusSq)\n\n if (isNaN(this.boundingSphere.radius)) {\n console.error(\n 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.',\n this,\n )\n }\n }\n }\n\n toJSON() {\n // todo\n }\n\n applyMatrix(matrix) {\n console.warn('THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().')\n\n return this.applyMatrix4(matrix)\n }\n}\n\nexport { LineSegmentsGeometry }\n"],"names":["Box3","Vector3","InstancedBufferGeometry","Float32BufferAttribute","InstancedInterleavedBuffer","InterleavedBufferAttribute","WireframeGeometry","Sphere"],"mappings":";;;AAWA,MAAM,OAAO,IAAIA,MAAAA,KAAM;AACvB,MAAM,UAAU,IAAIC,MAAAA,QAAS;AAE7B,MAAM,6BAA6BC,MAAAA,wBAAwB;AAAA,EACzD,cAAc;AACZ,UAAO;AA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;AAE7C,WAAK,uBAAuB,GAAG;AAE/B,WAAK,YAAY,MAAM,IAAI;AAAA,IAC5B;AAAA,EACF;AAAA,EAED,wBAAwB;AACtB,QAAI,KAAK,mBAAmB,MAAM;AAChC,WAAK,iBAAiB,IAAIO,aAAQ;AAAA,IACnC;AAED,QAAI,KAAK,gBAAgB,MAAM;AAC7B,WAAK,mBAAoB;AAAA,IAC1B;AAED,UAAM,QAAQ,KAAK,WAAW;AAC9B,UAAM,MAAM,KAAK,WAAW;AAE5B,QAAI,UAAU,UAAa,QAAQ,QAAW;AAC5C,YAAM,SAAS,KAAK,eAAe;AAEnC,WAAK,YAAY,UAAU,MAAM;AAEjC,UAAI,cAAc;AAElB,eAAS,IAAI,GAAG,KAAK,MAAM,OAAO,IAAI,IAAI,KAAK;AAC7C,gBAAQ,oBAAoB,OAAO,CAAC;AACpC,sBAAc,KAAK,IAAI,aAAa,OAAO,kBAAkB,OAAO,CAAC;AAErE,gBAAQ,oBAAoB,KAAK,CAAC;AAClC,sBAAc,KAAK,IAAI,aAAa,OAAO,kBAAkB,OAAO,CAAC;AAAA,MACtE;AAED,WAAK,eAAe,SAAS,KAAK,KAAK,WAAW;AAElD,UAAI,MAAM,KAAK,eAAe,MAAM,GAAG;AACrC,gBAAQ;AAAA,UACN;AAAA,UACA;AAAA,QACD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAED,SAAS;AAAA,EAER;AAAA,EAED,YAAY,QAAQ;AAClB,YAAQ,KAAK,+EAA+E;AAE5F,WAAO,KAAK,aAAa,MAAM;AAAA,EAChC;AACH;;"}
1
+ {"version":3,"file":"LineSegmentsGeometry.cjs","sources":["../../src/lines/LineSegmentsGeometry.js"],"sourcesContent":["import {\n Box3,\n Float32BufferAttribute,\n InstancedBufferGeometry,\n InstancedInterleavedBuffer,\n InterleavedBufferAttribute,\n Sphere,\n Vector3,\n WireframeGeometry,\n} from 'three'\n\nconst _box = new Box3()\nconst _vector = new Vector3()\n\nclass LineSegmentsGeometry extends InstancedBufferGeometry {\n constructor() {\n super()\n\n this.isLineSegmentsGeometry = true\n\n this.type = 'LineSegmentsGeometry'\n\n const positions = [-1, 2, 0, 1, 2, 0, -1, 1, 0, 1, 1, 0, -1, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, 0]\n const uvs = [-1, 2, 1, 2, -1, 1, 1, 1, -1, -1, 1, -1, -1, -2, 1, -2]\n const index = [0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5]\n\n this.setIndex(index)\n this.setAttribute('position', new Float32BufferAttribute(positions, 3))\n this.setAttribute('uv', new Float32BufferAttribute(uvs, 2))\n }\n\n applyMatrix4(matrix) {\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined) {\n start.applyMatrix4(matrix)\n\n end.applyMatrix4(matrix)\n\n start.needsUpdate = true\n }\n\n if (this.boundingBox !== null) {\n this.computeBoundingBox()\n }\n\n if (this.boundingSphere !== null) {\n this.computeBoundingSphere()\n }\n\n return this\n }\n\n setPositions(array) {\n let lineSegments\n\n if (array instanceof Float32Array) {\n lineSegments = array\n } else if (Array.isArray(array)) {\n lineSegments = new Float32Array(array)\n }\n\n const instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1) // xyz, xyz\n\n this.setAttribute('instanceStart', new InterleavedBufferAttribute(instanceBuffer, 3, 0)) // xyz\n this.setAttribute('instanceEnd', new InterleavedBufferAttribute(instanceBuffer, 3, 3)) // xyz\n\n //\n\n this.computeBoundingBox()\n this.computeBoundingSphere()\n\n return this\n }\n\n setColors(array, itemSize = 3) {\n let colors\n\n if (array instanceof Float32Array) {\n colors = array\n } else if (Array.isArray(array)) {\n colors = new Float32Array(array)\n }\n\n const instanceColorBuffer = new InstancedInterleavedBuffer(colors, itemSize * 2, 1) // rgb(a), rgb(a)\n\n this.setAttribute('instanceColorStart', new InterleavedBufferAttribute(instanceColorBuffer, itemSize, 0)) // rgb(a)\n this.setAttribute('instanceColorEnd', new InterleavedBufferAttribute(instanceColorBuffer, itemSize, itemSize)) // rgb(a)\n\n return this\n }\n\n fromWireframeGeometry(geometry) {\n this.setPositions(geometry.attributes.position.array)\n\n return this\n }\n\n fromEdgesGeometry(geometry) {\n this.setPositions(geometry.attributes.position.array)\n\n return this\n }\n\n fromMesh(mesh) {\n this.fromWireframeGeometry(new WireframeGeometry(mesh.geometry))\n\n // set colors, maybe\n\n return this\n }\n\n fromLineSegments(lineSegments) {\n const geometry = lineSegments.geometry\n\n this.setPositions(geometry.attributes.position.array) // assumes non-indexed\n\n // set colors, maybe\n\n return this\n }\n\n computeBoundingBox() {\n if (this.boundingBox === null) {\n this.boundingBox = new Box3()\n }\n\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined && end !== undefined) {\n this.boundingBox.setFromBufferAttribute(start)\n\n _box.setFromBufferAttribute(end)\n\n this.boundingBox.union(_box)\n }\n }\n\n computeBoundingSphere() {\n if (this.boundingSphere === null) {\n this.boundingSphere = new Sphere()\n }\n\n if (this.boundingBox === null) {\n this.computeBoundingBox()\n }\n\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined && end !== undefined) {\n const center = this.boundingSphere.center\n\n this.boundingBox.getCenter(center)\n\n let maxRadiusSq = 0\n\n for (let i = 0, il = start.count; i < il; i++) {\n _vector.fromBufferAttribute(start, i)\n maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector))\n\n _vector.fromBufferAttribute(end, i)\n maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector))\n }\n\n this.boundingSphere.radius = Math.sqrt(maxRadiusSq)\n\n if (isNaN(this.boundingSphere.radius)) {\n console.error(\n 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.',\n this,\n )\n }\n }\n }\n\n toJSON() {\n // todo\n }\n\n applyMatrix(matrix) {\n console.warn('THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().')\n\n return this.applyMatrix4(matrix)\n }\n}\n\nexport { LineSegmentsGeometry }\n"],"names":["Box3","Vector3","InstancedBufferGeometry","Float32BufferAttribute","InstancedInterleavedBuffer","InterleavedBufferAttribute","WireframeGeometry","Sphere"],"mappings":";;;AAWA,MAAM,OAAO,IAAIA,MAAAA,KAAM;AACvB,MAAM,UAAU,IAAIC,MAAAA,QAAS;AAE7B,MAAM,6BAA6BC,MAAAA,wBAAwB;AAAA,EACzD,cAAc;AACZ,UAAO;AAEP,SAAK,yBAAyB;AAE9B,SAAK,OAAO;AAEZ,UAAM,YAAY,CAAC,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,GAAG,IAAI,CAAC;AAC/F,UAAM,MAAM,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,EAAE;AACnE,UAAM,QAAQ,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEnE,SAAK,SAAS,KAAK;AACnB,SAAK,aAAa,YAAY,IAAIC,MAAAA,uBAAuB,WAAW,CAAC,CAAC;AACtE,SAAK,aAAa,MAAM,IAAIA,MAAAA,uBAAuB,KAAK,CAAC,CAAC;AAAA,EAC3D;AAAA,EAED,aAAa,QAAQ;AACnB,UAAM,QAAQ,KAAK,WAAW;AAC9B,UAAM,MAAM,KAAK,WAAW;AAE5B,QAAI,UAAU,QAAW;AACvB,YAAM,aAAa,MAAM;AAEzB,UAAI,aAAa,MAAM;AAEvB,YAAM,cAAc;AAAA,IACrB;AAED,QAAI,KAAK,gBAAgB,MAAM;AAC7B,WAAK,mBAAoB;AAAA,IAC1B;AAED,QAAI,KA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;AAClB,YAAQ,KAAK,+EAA+E;AAE5F,WAAO,KAAK,aAAa,MAAM;AAAA,EAChC;AACH;;"}
@@ -52,7 +52,7 @@ class LineSegmentsGeometry extends InstancedBufferGeometry {
52
52
  }
53
53
  const instanceColorBuffer = new InstancedInterleavedBuffer(colors, itemSize * 2, 1);
54
54
  this.setAttribute("instanceColorStart", new InterleavedBufferAttribute(instanceColorBuffer, itemSize, 0));
55
- this.setAttribute("instanceColorEnd", new InterleavedBufferAttribute(instanceColorBuffer, itemSize, 3));
55
+ this.setAttribute("instanceColorEnd", new InterleavedBufferAttribute(instanceColorBuffer, itemSize, itemSize));
56
56
  return this;
57
57
  }
58
58
  fromWireframeGeometry(geometry) {
@@ -1 +1 @@
1
- {"version":3,"file":"LineSegmentsGeometry.js","sources":["../../src/lines/LineSegmentsGeometry.js"],"sourcesContent":["import {\n Box3,\n Float32BufferAttribute,\n InstancedBufferGeometry,\n InstancedInterleavedBuffer,\n InterleavedBufferAttribute,\n Sphere,\n Vector3,\n WireframeGeometry,\n} from 'three'\n\nconst _box = new Box3()\nconst _vector = new Vector3()\n\nclass LineSegmentsGeometry extends InstancedBufferGeometry {\n constructor() {\n super()\n\n this.isLineSegmentsGeometry = true\n\n this.type = 'LineSegmentsGeometry'\n\n const positions = [-1, 2, 0, 1, 2, 0, -1, 1, 0, 1, 1, 0, -1, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, 0]\n const uvs = [-1, 2, 1, 2, -1, 1, 1, 1, -1, -1, 1, -1, -1, -2, 1, -2]\n const index = [0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5]\n\n this.setIndex(index)\n this.setAttribute('position', new Float32BufferAttribute(positions, 3))\n this.setAttribute('uv', new Float32BufferAttribute(uvs, 2))\n }\n\n applyMatrix4(matrix) {\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined) {\n start.applyMatrix4(matrix)\n\n end.applyMatrix4(matrix)\n\n start.needsUpdate = true\n }\n\n if (this.boundingBox !== null) {\n this.computeBoundingBox()\n }\n\n if (this.boundingSphere !== null) {\n this.computeBoundingSphere()\n }\n\n return this\n }\n\n setPositions(array) {\n let lineSegments\n\n if (array instanceof Float32Array) {\n lineSegments = array\n } else if (Array.isArray(array)) {\n lineSegments = new Float32Array(array)\n }\n\n const instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1) // xyz, xyz\n\n this.setAttribute('instanceStart', new InterleavedBufferAttribute(instanceBuffer, 3, 0)) // xyz\n this.setAttribute('instanceEnd', new InterleavedBufferAttribute(instanceBuffer, 3, 3)) // xyz\n\n //\n\n this.computeBoundingBox()\n this.computeBoundingSphere()\n\n return this\n }\n\n setColors(array, itemSize = 3) {\n let colors\n\n if (array instanceof Float32Array) {\n colors = array\n } else if (Array.isArray(array)) {\n colors = new Float32Array(array)\n }\n\n const instanceColorBuffer = new InstancedInterleavedBuffer(colors, itemSize * 2, 1) // rgb(a), rgb(a)\n\n this.setAttribute('instanceColorStart', new InterleavedBufferAttribute(instanceColorBuffer, itemSize, 0)) // rgb(a)\n this.setAttribute('instanceColorEnd', new InterleavedBufferAttribute(instanceColorBuffer, itemSize, 3)) // rgb(a)\n\n return this\n }\n\n fromWireframeGeometry(geometry) {\n this.setPositions(geometry.attributes.position.array)\n\n return this\n }\n\n fromEdgesGeometry(geometry) {\n this.setPositions(geometry.attributes.position.array)\n\n return this\n }\n\n fromMesh(mesh) {\n this.fromWireframeGeometry(new WireframeGeometry(mesh.geometry))\n\n // set colors, maybe\n\n return this\n }\n\n fromLineSegments(lineSegments) {\n const geometry = lineSegments.geometry\n\n this.setPositions(geometry.attributes.position.array) // assumes non-indexed\n\n // set colors, maybe\n\n return this\n }\n\n computeBoundingBox() {\n if (this.boundingBox === null) {\n this.boundingBox = new Box3()\n }\n\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined && end !== undefined) {\n this.boundingBox.setFromBufferAttribute(start)\n\n _box.setFromBufferAttribute(end)\n\n this.boundingBox.union(_box)\n }\n }\n\n computeBoundingSphere() {\n if (this.boundingSphere === null) {\n this.boundingSphere = new Sphere()\n }\n\n if (this.boundingBox === null) {\n this.computeBoundingBox()\n }\n\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined && end !== undefined) {\n const center = this.boundingSphere.center\n\n this.boundingBox.getCenter(center)\n\n let maxRadiusSq = 0\n\n for (let i = 0, il = start.count; i < il; i++) {\n _vector.fromBufferAttribute(start, i)\n maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector))\n\n _vector.fromBufferAttribute(end, i)\n maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector))\n }\n\n this.boundingSphere.radius = Math.sqrt(maxRadiusSq)\n\n if (isNaN(this.boundingSphere.radius)) {\n console.error(\n 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.',\n this,\n )\n }\n }\n }\n\n toJSON() {\n // todo\n }\n\n applyMatrix(matrix) {\n console.warn('THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().')\n\n return this.applyMatrix4(matrix)\n }\n}\n\nexport { LineSegmentsGeometry }\n"],"names":[],"mappings":";AAWA,MAAM,OAAO,IAAI,KAAM;AACvB,MAAM,UAAU,IAAI,QAAS;AAE7B,MAAM,6BAA6B,wBAAwB;AAAA,EACzD,cAAc;AACZ,UAAO;AAEP,SAAK,yBAAyB;AAE9B,SAAK,OAAO;AAEZ,UAAM,YAAY,CAAC,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,GAAG,IAAI,CAAC;AAC/F,UAAM,MAAM,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG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K,YAAY,UAAU,MAAM;AAEjC,UAAI,cAAc;AAElB,eAAS,IAAI,GAAG,KAAK,MAAM,OAAO,IAAI,IAAI,KAAK;AAC7C,gBAAQ,oBAAoB,OAAO,CAAC;AACpC,sBAAc,KAAK,IAAI,aAAa,OAAO,kBAAkB,OAAO,CAAC;AAErE,gBAAQ,oBAAoB,KAAK,CAAC;AAClC,sBAAc,KAAK,IAAI,aAAa,OAAO,kBAAkB,OAAO,CAAC;AAAA,MACtE;AAED,WAAK,eAAe,SAAS,KAAK,KAAK,WAAW;AAElD,UAAI,MAAM,KAAK,eAAe,MAAM,GAAG;AACrC,gBAAQ;AAAA,UACN;AAAA,UACA;AAAA,QACD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAED,SAAS;AAAA,EAER;AAAA,EAED,YAAY,QAAQ;AAClB,YAAQ,KAAK,+EAA+E;AAE5F,WAAO,KAAK,aAAa,MAAM;AAAA,EAChC;AACH;"}
1
+ {"version":3,"file":"LineSegmentsGeometry.js","sources":["../../src/lines/LineSegmentsGeometry.js"],"sourcesContent":["import {\n Box3,\n Float32BufferAttribute,\n InstancedBufferGeometry,\n InstancedInterleavedBuffer,\n InterleavedBufferAttribute,\n Sphere,\n Vector3,\n WireframeGeometry,\n} from 'three'\n\nconst _box = new Box3()\nconst _vector = new Vector3()\n\nclass LineSegmentsGeometry extends InstancedBufferGeometry {\n constructor() {\n super()\n\n this.isLineSegmentsGeometry = true\n\n this.type = 'LineSegmentsGeometry'\n\n const positions = [-1, 2, 0, 1, 2, 0, -1, 1, 0, 1, 1, 0, -1, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, 0]\n const uvs = [-1, 2, 1, 2, -1, 1, 1, 1, -1, -1, 1, -1, -1, -2, 1, -2]\n const index = [0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5]\n\n this.setIndex(index)\n this.setAttribute('position', new Float32BufferAttribute(positions, 3))\n this.setAttribute('uv', new Float32BufferAttribute(uvs, 2))\n }\n\n applyMatrix4(matrix) {\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined) {\n start.applyMatrix4(matrix)\n\n end.applyMatrix4(matrix)\n\n start.needsUpdate = true\n }\n\n if (this.boundingBox !== null) {\n this.computeBoundingBox()\n }\n\n if (this.boundingSphere !== null) {\n this.computeBoundingSphere()\n }\n\n return this\n }\n\n setPositions(array) {\n let lineSegments\n\n if (array instanceof Float32Array) {\n lineSegments = array\n } else if (Array.isArray(array)) {\n lineSegments = new Float32Array(array)\n }\n\n const instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1) // xyz, xyz\n\n this.setAttribute('instanceStart', new InterleavedBufferAttribute(instanceBuffer, 3, 0)) // xyz\n this.setAttribute('instanceEnd', new InterleavedBufferAttribute(instanceBuffer, 3, 3)) // xyz\n\n //\n\n this.computeBoundingBox()\n this.computeBoundingSphere()\n\n return this\n }\n\n setColors(array, itemSize = 3) {\n let colors\n\n if (array instanceof Float32Array) {\n colors = array\n } else if (Array.isArray(array)) {\n colors = new Float32Array(array)\n }\n\n const instanceColorBuffer = new InstancedInterleavedBuffer(colors, itemSize * 2, 1) // rgb(a), rgb(a)\n\n this.setAttribute('instanceColorStart', new InterleavedBufferAttribute(instanceColorBuffer, itemSize, 0)) // rgb(a)\n this.setAttribute('instanceColorEnd', new InterleavedBufferAttribute(instanceColorBuffer, itemSize, itemSize)) // rgb(a)\n\n return this\n }\n\n fromWireframeGeometry(geometry) {\n this.setPositions(geometry.attributes.position.array)\n\n return this\n }\n\n fromEdgesGeometry(geometry) {\n this.setPositions(geometry.attributes.position.array)\n\n return this\n }\n\n fromMesh(mesh) {\n this.fromWireframeGeometry(new WireframeGeometry(mesh.geometry))\n\n // set colors, maybe\n\n return this\n }\n\n fromLineSegments(lineSegments) {\n const geometry = lineSegments.geometry\n\n this.setPositions(geometry.attributes.position.array) // assumes non-indexed\n\n // set colors, maybe\n\n return this\n }\n\n computeBoundingBox() {\n if (this.boundingBox === null) {\n this.boundingBox = new Box3()\n }\n\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined && end !== undefined) {\n this.boundingBox.setFromBufferAttribute(start)\n\n _box.setFromBufferAttribute(end)\n\n this.boundingBox.union(_box)\n }\n }\n\n computeBoundingSphere() {\n if (this.boundingSphere === null) {\n this.boundingSphere = new Sphere()\n }\n\n if (this.boundingBox === null) {\n this.computeBoundingBox()\n }\n\n const start = this.attributes.instanceStart\n const end = this.attributes.instanceEnd\n\n if (start !== undefined && end !== undefined) {\n const center = this.boundingSphere.center\n\n this.boundingBox.getCenter(center)\n\n let maxRadiusSq = 0\n\n for (let i = 0, il = start.count; i < il; i++) {\n _vector.fromBufferAttribute(start, i)\n maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector))\n\n _vector.fromBufferAttribute(end, i)\n maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector))\n }\n\n this.boundingSphere.radius = Math.sqrt(maxRadiusSq)\n\n if (isNaN(this.boundingSphere.radius)) {\n console.error(\n 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.',\n this,\n )\n }\n }\n }\n\n toJSON() {\n // todo\n }\n\n applyMatrix(matrix) {\n console.warn('THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().')\n\n return this.applyMatrix4(matrix)\n }\n}\n\nexport { LineSegmentsGeometry }\n"],"names":[],"mappings":";AAWA,MAAM,OAAO,IAAI,KAAM;AACvB,MAAM,UAAU,IAAI,QAAS;AAE7B,MAAM,6BAA6B,wBAAwB;AAAA,EACzD,cAAc;AACZ,UAAO;AAEP,SAAK,yBAAyB;AAE9B,SAAK,OAAO;AAEZ,UAAM,YAAY,CAAC,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,IAA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AAED,UAAM,QAAQ,KAAK,WAAW;AAC9B,UAAM,MAAM,KAAK,WAAW;AAE5B,QAAI,UAAU,UAAa,QAAQ,QAAW;AAC5C,YAAM,SAAS,KAAK,eAAe;AAEnC,WAAK,YAAY,UAAU,MAAM;AAEjC,UAAI,cAAc;AAElB,eAAS,IAAI,GAAG,KAAK,MAAM,OAAO,IAAI,IAAI,KAAK;AAC7C,gBAAQ,oBAAoB,OAAO,CAAC;AACpC,sBAAc,KAAK,IAAI,aAAa,OAAO,kBAAkB,OAAO,CAAC;AAErE,gBAAQ,oBAAoB,KAAK,CAAC;AAClC,sBAAc,KAAK,IAAI,aAAa,OAAO,kBAAkB,OAAO,CAAC;AAAA,MACtE;AAED,WAAK,eAAe,SAAS,KAAK,KAAK,WAAW;AAElD,UAAI,MAAM,KAAK,eAAe,MAAM,GAAG;AACrC,gBAAQ;AAAA,UACN;AAAA,UACA;AAAA,QACD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAED,SAAS;AAAA,EAER;AAAA,EAED,YAAY,QAAQ;AAClB,YAAQ,KAAK,+EAA+E;AAE5F,WAAO,KAAK,aAAa,MAAM;AAAA,EAChC;AACH;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-stdlib",
3
- "version": "2.29.0",
3
+ "version": "2.29.2",
4
4
  "description": "stand-alone library of threejs examples",
5
5
  "keywords": [
6
6
  "three",