three-stdlib 2.14.1 → 2.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/csm/CSM.cjs.js +1 -1
  2. package/csm/CSM.js +8 -8
  3. package/csm/CSMFrustum.cjs.js +1 -0
  4. package/csm/CSMFrustum.d.ts +19 -0
  5. package/csm/{Frustum.js → CSMFrustum.js} +8 -7
  6. package/csm/CSMShader.cjs.js +1 -0
  7. package/csm/CSMShader.d.ts +4 -0
  8. package/csm/{Shader.js → CSMShader.js} +52 -36
  9. package/curves/CurveExtras.d.ts +52 -54
  10. package/geometries/ParametricGeometries.cjs.js +1 -1
  11. package/geometries/ParametricGeometries.js +91 -99
  12. package/geometries/ParametricGeometry.cjs.js +1 -0
  13. package/geometries/ParametricGeometry.d.ts +18 -0
  14. package/geometries/ParametricGeometry.js +87 -0
  15. package/index.cjs.js +1 -1
  16. package/index.d.ts +3 -77
  17. package/index.js +4 -1
  18. package/interactive/InteractiveGroup.cjs.js +1 -0
  19. package/interactive/InteractiveGroup.d.ts +5 -0
  20. package/interactive/InteractiveGroup.js +87 -0
  21. package/lines/Line2.cjs.js +1 -1
  22. package/lines/Line2.d.ts +7 -5
  23. package/lines/Line2.js +2 -5
  24. package/lines/LineGeometry.cjs.js +1 -1
  25. package/lines/LineGeometry.d.ts +6 -8
  26. package/lines/LineGeometry.js +28 -39
  27. package/lines/LineMaterial.cjs.js +1 -1
  28. package/lines/LineMaterial.d.ts +23 -19
  29. package/lines/LineMaterial.js +263 -107
  30. package/lines/LineSegments2.cjs.js +1 -1
  31. package/lines/LineSegments2.d.ts +12 -20
  32. package/lines/LineSegments2.js +272 -125
  33. package/lines/LineSegmentsGeometry.cjs.js +1 -1
  34. package/lines/LineSegmentsGeometry.d.ts +18 -16
  35. package/lines/LineSegmentsGeometry.js +30 -40
  36. package/lines/Wireframe.cjs.js +1 -1
  37. package/lines/Wireframe.js +39 -39
  38. package/lines/WireframeGeometry2.cjs.js +1 -1
  39. package/lines/WireframeGeometry2.js +8 -9
  40. package/loaders/GLTFLoader.d.ts +2 -9
  41. package/loaders/LUT3dlLoader.d.ts +2 -2
  42. package/loaders/LUTCubeLoader.d.ts +2 -2
  43. package/loaders/RGBELoader.cjs.js +1 -1
  44. package/loaders/RGBELoader.js +1 -9
  45. package/loaders/VOXLoader.d.ts +2 -2
  46. package/objects/Reflector.d.ts +1 -0
  47. package/objects/ReflectorForSSRPass.d.ts +4 -4
  48. package/objects/Refractor.d.ts +1 -0
  49. package/objects/Water2.d.ts +1 -1
  50. package/package.json +2 -1
  51. package/postprocessing/LUTPass.d.ts +3 -3
  52. package/postprocessing/SSAARenderPass.d.ts +1 -1
  53. package/postprocessing/SSRPass.d.ts +3 -3
  54. package/shaders/BokehShader2.d.ts +27 -72
  55. package/shaders/BokehShader2.js +0 -1
  56. package/shaders/index.cjs.js +1 -1
  57. package/shaders/index.d.ts +2 -1
  58. package/shaders/index.js +1 -1
  59. package/csm/Frustum.cjs.js +0 -1
  60. package/csm/Shader.cjs.js +0 -1
  61. package/loaders/VRMLoader.d.ts +0 -19
  62. package/nodes/Nodes.d.ts +0 -106
  63. package/nodes/accessors/CameraNode.d.ts +0 -29
  64. package/nodes/accessors/NormalNode.d.ts +0 -13
  65. package/nodes/accessors/PositionNode.d.ts +0 -15
  66. package/nodes/accessors/ReflectNode.d.ts +0 -12
  67. package/nodes/accessors/UVNode.d.ts +0 -10
  68. package/nodes/core/AttributeNode.d.ts +0 -13
  69. package/nodes/core/ConstNode.d.ts +0 -22
  70. package/nodes/core/ExpressionNode.d.ts +0 -5
  71. package/nodes/core/FunctionCallNode.d.ts +0 -17
  72. package/nodes/core/FunctionNode.d.ts +0 -28
  73. package/nodes/core/InputNode.d.ts +0 -12
  74. package/nodes/core/Node.d.ts +0 -34
  75. package/nodes/core/NodeBuilder.d.ts +0 -149
  76. package/nodes/core/NodeFrame.d.ts +0 -17
  77. package/nodes/core/NodeUniform.d.ts +0 -17
  78. package/nodes/core/NodeUtils.d.ts +0 -7
  79. package/nodes/core/TempNode.d.ts +0 -23
  80. package/nodes/core/VarNode.d.ts +0 -12
  81. package/nodes/materials/MeshStandardNodeMaterial.d.ts +0 -21
  82. package/nodes/materials/NodeMaterial.d.ts +0 -28
  83. package/nodes/math/CondNode.d.ts +0 -26
  84. package/nodes/math/MathNode.d.ts +0 -57
  85. package/nodes/math/OperatorNode.d.ts +0 -17
  86. package/nodes/procedural/CheckerNode.d.ts +0 -17
  87. package/nodes/utils/JoinNode.d.ts +0 -15
  88. package/nodes/utils/TimerNode.d.ts +0 -19
  89. package/objects/ReflectorRTT.d.ts +0 -6
@@ -1,5 +1,4 @@
1
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import { Vector2, ShaderLib, UniformsUtils, UniformsLib, ShaderMaterial, Color } from 'three';
1
+ import { UniformsLib, Vector2, ShaderLib, UniformsUtils, ShaderMaterial } from 'three';
3
2
 
4
3
  /**
5
4
  * parameters = {
@@ -13,32 +12,32 @@ import { Vector2, ShaderLib, UniformsUtils, UniformsLib, ShaderMaterial, Color }
13
12
  * resolution: <Vector2>, // to be set by renderer
14
13
  * }
15
14
  */
16
- const LineUniforms = {
15
+ UniformsLib.line = {
16
+ worldUnits: {
17
+ value: 1
18
+ },
17
19
  linewidth: {
18
20
  value: 1
19
21
  },
20
22
  resolution: {
21
23
  value: new Vector2(1, 1)
22
24
  },
25
+ dashOffset: {
26
+ value: 0
27
+ },
23
28
  dashScale: {
24
29
  value: 1
25
30
  },
26
31
  dashSize: {
27
32
  value: 1
28
33
  },
29
- dashOffset: {
30
- value: 0
31
- },
32
34
  gapSize: {
33
35
  value: 1
34
- },
35
- // todo FIX - maybe change to totalSize
36
- opacity: {
37
- value: 1
38
- }
36
+ } // todo FIX - maybe change to totalSize
37
+
39
38
  };
40
39
  ShaderLib['line'] = {
41
- uniforms: UniformsUtils.merge([UniformsLib.common, UniformsLib.fog, LineUniforms]),
40
+ uniforms: UniformsUtils.merge([UniformsLib.common, UniformsLib.fog, UniformsLib.line]),
42
41
  vertexShader:
43
42
  /* glsl */
44
43
  `
@@ -57,7 +56,23 @@ ShaderLib['line'] = {
57
56
  attribute vec3 instanceColorStart;
58
57
  attribute vec3 instanceColorEnd;
59
58
 
60
- varying vec2 vUv;
59
+ #ifdef WORLD_UNITS
60
+
61
+ varying vec4 worldPos;
62
+ varying vec3 worldStart;
63
+ varying vec3 worldEnd;
64
+
65
+ #ifdef USE_DASH
66
+
67
+ varying vec2 vUv;
68
+
69
+ #endif
70
+
71
+ #else
72
+
73
+ varying vec2 vUv;
74
+
75
+ #endif
61
76
 
62
77
  #ifdef USE_DASH
63
78
 
@@ -94,17 +109,27 @@ ShaderLib['line'] = {
94
109
  #ifdef USE_DASH
95
110
 
96
111
  vLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;
112
+ vUv = uv;
97
113
 
98
114
  #endif
99
115
 
100
116
  float aspect = resolution.x / resolution.y;
101
117
 
102
- vUv = uv;
103
-
104
118
  // camera space
105
119
  vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );
106
120
  vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );
107
121
 
122
+ #ifdef WORLD_UNITS
123
+
124
+ worldStart = start.xyz;
125
+ worldEnd = end.xyz;
126
+
127
+ #else
128
+
129
+ vUv = uv;
130
+
131
+ #endif
132
+
108
133
  // special case for perspective projection, and segments that terminate either in, or behind, the camera plane
109
134
  // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space
110
135
  // but we need to perform ndc-space calculations in the shader, so we must address this issue directly
@@ -131,50 +156,108 @@ ShaderLib['line'] = {
131
156
  vec4 clipEnd = projectionMatrix * end;
132
157
 
133
158
  // ndc space
134
- vec2 ndcStart = clipStart.xy / clipStart.w;
135
- vec2 ndcEnd = clipEnd.xy / clipEnd.w;
159
+ vec3 ndcStart = clipStart.xyz / clipStart.w;
160
+ vec3 ndcEnd = clipEnd.xyz / clipEnd.w;
136
161
 
137
162
  // direction
138
- vec2 dir = ndcEnd - ndcStart;
163
+ vec2 dir = ndcEnd.xy - ndcStart.xy;
139
164
 
140
165
  // account for clip-space aspect ratio
141
166
  dir.x *= aspect;
142
167
  dir = normalize( dir );
143
168
 
144
- // perpendicular to dir
145
- vec2 offset = vec2( dir.y, - dir.x );
169
+ #ifdef WORLD_UNITS
146
170
 
147
- // undo aspect ratio adjustment
148
- dir.x /= aspect;
149
- offset.x /= aspect;
171
+ // get the offset direction as perpendicular to the view vector
172
+ vec3 worldDir = normalize( end.xyz - start.xyz );
173
+ vec3 offset;
174
+ if ( position.y < 0.5 ) {
150
175
 
151
- // sign flip
152
- if ( position.x < 0.0 ) offset *= - 1.0;
176
+ offset = normalize( cross( start.xyz, worldDir ) );
153
177
 
154
- // endcaps
155
- if ( position.y < 0.0 ) {
178
+ } else {
156
179
 
157
- offset += - dir;
180
+ offset = normalize( cross( end.xyz, worldDir ) );
158
181
 
159
- } else if ( position.y > 1.0 ) {
182
+ }
160
183
 
161
- offset += dir;
184
+ // sign flip
185
+ if ( position.x < 0.0 ) offset *= - 1.0;
162
186
 
163
- }
187
+ float forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );
188
+
189
+ // don't extend the line if we're rendering dashes because we
190
+ // won't be rendering the endcaps
191
+ #ifndef USE_DASH
192
+
193
+ // extend the line bounds to encompass endcaps
194
+ start.xyz += - worldDir * linewidth * 0.5;
195
+ end.xyz += worldDir * linewidth * 0.5;
196
+
197
+ // shift the position of the quad so it hugs the forward edge of the line
198
+ offset.xy -= dir * forwardOffset;
199
+ offset.z += 0.5;
200
+
201
+ #endif
202
+
203
+ // endcaps
204
+ if ( position.y > 1.0 || position.y < 0.0 ) {
164
205
 
165
- // adjust for linewidth
166
- offset *= linewidth;
206
+ offset.xy += dir * 2.0 * forwardOffset;
167
207
 
168
- // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...
169
- offset /= resolution.y;
208
+ }
209
+
210
+ // adjust for linewidth
211
+ offset *= linewidth * 0.5;
212
+
213
+ // set the world position
214
+ worldPos = ( position.y < 0.5 ) ? start : end;
215
+ worldPos.xyz += offset;
216
+
217
+ // project the worldpos
218
+ vec4 clip = projectionMatrix * worldPos;
219
+
220
+ // shift the depth of the projected points so the line
221
+ // segments overlap neatly
222
+ vec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;
223
+ clip.z = clipPose.z * clip.w;
224
+
225
+ #else
226
+
227
+ vec2 offset = vec2( dir.y, - dir.x );
228
+ // undo aspect ratio adjustment
229
+ dir.x /= aspect;
230
+ offset.x /= aspect;
231
+
232
+ // sign flip
233
+ if ( position.x < 0.0 ) offset *= - 1.0;
234
+
235
+ // endcaps
236
+ if ( position.y < 0.0 ) {
170
237
 
171
- // select end
172
- vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;
238
+ offset += - dir;
173
239
 
174
- // back to clip space
175
- offset *= clip.w;
240
+ } else if ( position.y > 1.0 ) {
176
241
 
177
- clip.xy += offset;
242
+ offset += dir;
243
+
244
+ }
245
+
246
+ // adjust for linewidth
247
+ offset *= linewidth;
248
+
249
+ // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...
250
+ offset /= resolution.y;
251
+
252
+ // select end
253
+ vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;
254
+
255
+ // back to clip space
256
+ offset *= clip.w;
257
+
258
+ clip.xy += offset;
259
+
260
+ #endif
178
261
 
179
262
  gl_Position = clip;
180
263
 
@@ -191,24 +274,70 @@ ShaderLib['line'] = {
191
274
  `
192
275
  uniform vec3 diffuse;
193
276
  uniform float opacity;
277
+ uniform float linewidth;
194
278
 
195
279
  #ifdef USE_DASH
196
280
 
197
- uniform float dashSize;
198
281
  uniform float dashOffset;
282
+ uniform float dashSize;
199
283
  uniform float gapSize;
200
284
 
201
285
  #endif
202
286
 
203
287
  varying float vLineDistance;
204
288
 
289
+ #ifdef WORLD_UNITS
290
+
291
+ varying vec4 worldPos;
292
+ varying vec3 worldStart;
293
+ varying vec3 worldEnd;
294
+
295
+ #ifdef USE_DASH
296
+
297
+ varying vec2 vUv;
298
+
299
+ #endif
300
+
301
+ #else
302
+
303
+ varying vec2 vUv;
304
+
305
+ #endif
306
+
205
307
  #include <common>
206
308
  #include <color_pars_fragment>
207
309
  #include <fog_pars_fragment>
208
310
  #include <logdepthbuf_pars_fragment>
209
311
  #include <clipping_planes_pars_fragment>
210
312
 
211
- varying vec2 vUv;
313
+ vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {
314
+
315
+ float mua;
316
+ float mub;
317
+
318
+ vec3 p13 = p1 - p3;
319
+ vec3 p43 = p4 - p3;
320
+
321
+ vec3 p21 = p2 - p1;
322
+
323
+ float d1343 = dot( p13, p43 );
324
+ float d4321 = dot( p43, p21 );
325
+ float d1321 = dot( p13, p21 );
326
+ float d4343 = dot( p43, p43 );
327
+ float d2121 = dot( p21, p21 );
328
+
329
+ float denom = d2121 * d4343 - d4321 * d4321;
330
+
331
+ float numer = d1343 * d4321 - d1321 * d4343;
332
+
333
+ mua = numer / denom;
334
+ mua = clamp( mua, 0.0, 1.0 );
335
+ mub = ( d1343 + d4321 * ( mua ) ) / d4343;
336
+ mub = clamp( mub, 0.0, 1.0 );
337
+
338
+ return vec2( mua, mub );
339
+
340
+ }
212
341
 
213
342
  void main() {
214
343
 
@@ -224,31 +353,67 @@ ShaderLib['line'] = {
224
353
 
225
354
  float alpha = opacity;
226
355
 
227
- #ifdef ALPHA_TO_COVERAGE
356
+ #ifdef WORLD_UNITS
228
357
 
229
- // artifacts appear on some hardware if a derivative is taken within a conditional
230
- float a = vUv.x;
231
- float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
232
- float len2 = a * a + b * b;
233
- float dlen = fwidth( len2 );
358
+ // Find the closest points on the view ray and the line segment
359
+ vec3 rayEnd = normalize( worldPos.xyz ) * 1e5;
360
+ vec3 lineDir = worldEnd - worldStart;
361
+ vec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );
234
362
 
235
- if ( abs( vUv.y ) > 1.0 ) {
363
+ vec3 p1 = worldStart + lineDir * params.x;
364
+ vec3 p2 = rayEnd * params.y;
365
+ vec3 delta = p1 - p2;
366
+ float len = length( delta );
367
+ float norm = len / linewidth;
236
368
 
237
- alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );
369
+ #ifndef USE_DASH
238
370
 
239
- }
371
+ #ifdef USE_ALPHA_TO_COVERAGE
372
+
373
+ float dnorm = fwidth( norm );
374
+ alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );
375
+
376
+ #else
377
+
378
+ if ( norm > 0.5 ) {
379
+
380
+ discard;
381
+
382
+ }
383
+
384
+ #endif
385
+
386
+ #endif
240
387
 
241
388
  #else
242
389
 
243
- if ( abs( vUv.y ) > 1.0 ) {
390
+ #ifdef USE_ALPHA_TO_COVERAGE
244
391
 
245
- float a = vUv.x;
246
- float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
247
- float len2 = a * a + b * b;
392
+ // artifacts appear on some hardware if a derivative is taken within a conditional
393
+ float a = vUv.x;
394
+ float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
395
+ float len2 = a * a + b * b;
396
+ float dlen = fwidth( len2 );
248
397
 
249
- if ( len2 > 1.0 ) discard;
398
+ if ( abs( vUv.y ) > 1.0 ) {
250
399
 
251
- }
400
+ alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );
401
+
402
+ }
403
+
404
+ #else
405
+
406
+ if ( abs( vUv.y ) > 1.0 ) {
407
+
408
+ float a = vUv.x;
409
+ float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
410
+ float len2 = a * a + b * b;
411
+
412
+ if ( len2 > 1.0 ) discard;
413
+
414
+ }
415
+
416
+ #endif
252
417
 
253
418
  #endif
254
419
 
@@ -269,39 +434,16 @@ ShaderLib['line'] = {
269
434
  };
270
435
 
271
436
  class LineMaterial extends ShaderMaterial {
272
- constructor(parameters = {}) {
437
+ constructor(parameters) {
273
438
  super({
439
+ type: 'LineMaterial',
274
440
  uniforms: UniformsUtils.clone(ShaderLib['line'].uniforms),
275
441
  vertexShader: ShaderLib['line'].vertexShader,
276
442
  fragmentShader: ShaderLib['line'].fragmentShader,
277
443
  clipping: true // required for clipping support
278
444
 
279
445
  });
280
- /**
281
- * Everytime I remove this, everything just breaks,
282
- * so I'm just gonna leave it here.
283
- */
284
-
285
- _defineProperty(this, "isLineMaterial", true);
286
-
287
- _defineProperty(this, "dashed", false);
288
-
289
- _defineProperty(this, "color", new Color(0x000000));
290
-
291
- _defineProperty(this, "lineWidth", 0);
292
-
293
- _defineProperty(this, "dashScale", 0);
294
-
295
- _defineProperty(this, "dashOffset", 0);
296
-
297
- _defineProperty(this, "dashSize", 0);
298
-
299
- _defineProperty(this, "opacity", 0);
300
-
301
- _defineProperty(this, "resolution", new Vector2());
302
-
303
- _defineProperty(this, "alphaToCoverage", false);
304
-
446
+ this.isLineMaterial = true;
305
447
  Object.defineProperties(this, {
306
448
  color: {
307
449
  enumerable: true,
@@ -309,8 +451,20 @@ class LineMaterial extends ShaderMaterial {
309
451
  return this.uniforms.diffuse.value;
310
452
  },
311
453
  set: function (value) {
312
- const colorObj = new Color(value);
313
- this.uniforms.diffuse.value = colorObj.getHex();
454
+ this.uniforms.diffuse.value = value;
455
+ }
456
+ },
457
+ worldUnits: {
458
+ enumerable: true,
459
+ get: function () {
460
+ return 'WORLD_UNITS' in this.defines;
461
+ },
462
+ set: function (value) {
463
+ if (value === true) {
464
+ this.defines.WORLD_UNITS = '';
465
+ } else {
466
+ delete this.defines.WORLD_UNITS;
467
+ }
314
468
  }
315
469
  },
316
470
  linewidth: {
@@ -322,6 +476,25 @@ class LineMaterial extends ShaderMaterial {
322
476
  this.uniforms.linewidth.value = value;
323
477
  }
324
478
  },
479
+ dashed: {
480
+ enumerable: true,
481
+ get: function () {
482
+ return Boolean('USE_DASH' in this.defines);
483
+ },
484
+
485
+ set(value) {
486
+ if (Boolean(value) !== Boolean('USE_DASH' in this.defines)) {
487
+ this.needsUpdate = true;
488
+ }
489
+
490
+ if (value === true) {
491
+ this.defines.USE_DASH = '';
492
+ } else {
493
+ delete this.defines.USE_DASH;
494
+ }
495
+ }
496
+
497
+ },
325
498
  dashScale: {
326
499
  enumerable: true,
327
500
  get: function () {
@@ -379,38 +552,21 @@ class LineMaterial extends ShaderMaterial {
379
552
  alphaToCoverage: {
380
553
  enumerable: true,
381
554
  get: function () {
382
- return Boolean('ALPHA_TO_COVERAGE' in this.defines);
555
+ return Boolean('USE_ALPHA_TO_COVERAGE' in this.defines);
383
556
  },
384
557
  set: function (value) {
385
- if (Boolean(value) !== Boolean('ALPHA_TO_COVERAGE' in this.defines)) {
558
+ if (Boolean(value) !== Boolean('USE_ALPHA_TO_COVERAGE' in this.defines)) {
386
559
  this.needsUpdate = true;
387
560
  }
388
561
 
389
- if (value) {
390
- this.defines.ALPHA_TO_COVERAGE = '';
562
+ if (value === true) {
563
+ this.defines.USE_ALPHA_TO_COVERAGE = '';
391
564
  this.extensions.derivatives = true;
392
565
  } else {
393
- delete this.defines.ALPHA_TO_COVERAGE;
566
+ delete this.defines.USE_ALPHA_TO_COVERAGE;
394
567
  this.extensions.derivatives = false;
395
568
  }
396
569
  }
397
- },
398
- dashed: {
399
- enumerable: true,
400
- get: function () {
401
- return Boolean('USE_DASH' in this.defines);
402
- },
403
- set: function (value) {
404
- if (Boolean(value) !== Boolean('USE_DASH' in this.defines)) {
405
- this.needsUpdate = true;
406
- }
407
-
408
- if (value) {
409
- this.defines.USE_DASH = '';
410
- } else {
411
- delete this.defines.USE_DASH;
412
- }
413
- }
414
570
  }
415
571
  });
416
572
  this.setValues(parameters);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@babel/runtime/helpers/defineProperty"),i=require("three"),e=require("./LineSegmentsGeometry.cjs.js"),s=require("./LineMaterial.cjs.js");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var a=r(t);class n extends i.Mesh{constructor(t=new e.LineSegmentsGeometry,r=new s.LineMaterial({color:16777215*Math.random()})){super(t,r),a.default(this,"type","LineSegments2"),a.default(this,"isLineSegments2",!0),a.default(this,"distStart",new i.Vector3),a.default(this,"distEnd",new i.Vector3),a.default(this,"computeLineDistances",(()=>{const t=this.geometry,e=t.attributes.instanceStart,s=t.attributes.instanceEnd,r=new Float32Array(2*e.data.count);for(let t=0,i=0,a=e.data.count;t<a;t++,i+=2)this.distStart.fromBufferAttribute(e,t),this.distEnd.fromBufferAttribute(s,t),r[i]=0===i?0:r[i-1],r[i+1]=r[i]+this.distStart.distanceTo(this.distEnd);const a=new i.InstancedInterleavedBuffer(r,2,1);return t.setAttribute("instanceDistanceStart",new i.InterleavedBufferAttribute(a,1,0)),t.setAttribute("instanceDistanceEnd",new i.InterleavedBufferAttribute(a,1,1)),this})),a.default(this,"rayStart",new i.Vector4),a.default(this,"rayEnd",new i.Vector4),a.default(this,"ssOrigin",new i.Vector4),a.default(this,"ssOrigin3",new i.Vector3),a.default(this,"mvMatrix",new i.Matrix4),a.default(this,"line",new i.Line3),a.default(this,"closestPoint",new i.Vector3),a.default(this,"raycast",((t,e)=>{null===t.camera&&console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2.');const s=t.ray,r=t.camera,a=r.projectionMatrix,n=this.geometry,h=this.material,l=h.resolution,o=h.linewidth+0,d=n.attributes.instanceStart,y=n.attributes.instanceEnd,c=-r.near;s.at(1,this.ssOrigin),this.ssOrigin.w=1,this.ssOrigin.applyMatrix4(r.matrixWorldInverse),this.ssOrigin.applyMatrix4(a),this.ssOrigin.multiplyScalar(1/this.ssOrigin.w),this.ssOrigin.x*=l.x/2,this.ssOrigin.y*=l.y/2,this.ssOrigin.z=0,this.ssOrigin3.set(this.ssOrigin.x,this.ssOrigin.y,this.ssOrigin.z);const u=this.matrixWorld;this.mvMatrix.multiplyMatrices(r.matrixWorldInverse,u);for(let t=0,r=d.count;t<r;t++){this.rayStart.fromBufferAttribute(d,t),this.rayEnd.fromBufferAttribute(y,t),this.rayStart.w=1,this.rayEnd.w=1,this.rayStart.applyMatrix4(this.mvMatrix),this.rayEnd.applyMatrix4(this.mvMatrix);if(this.rayStart.z>c&&this.rayEnd.z>c)continue;if(this.rayStart.z>c){const t=this.rayStart.z-this.rayEnd.z,i=(this.rayStart.z-c)/t;this.rayStart.lerp(this.rayEnd,i)}else if(this.rayEnd.z>c){const t=this.rayEnd.z-this.rayStart.z,i=(this.rayEnd.z-c)/t;this.rayEnd.lerp(this.rayStart,i)}this.rayStart.applyMatrix4(a),this.rayEnd.applyMatrix4(a),this.rayStart.multiplyScalar(1/this.rayStart.w),this.rayEnd.multiplyScalar(1/this.rayEnd.w),this.rayStart.x*=l.x/2,this.rayStart.y*=l.y/2,this.rayEnd.x*=l.x/2,this.rayEnd.y*=l.y/2,this.line.start.set(this.rayStart.x,this.rayStart.y,this.rayStart.z),this.line.start.z=0,this.line.end.set(this.rayEnd.x,this.rayEnd.y,this.rayEnd.z),this.line.end.z=0;const r=this.line.closestPointToPointParameter(this.ssOrigin3,!0);this.line.at(r,this.closestPoint);const n=i.MathUtils.lerp(this.rayStart.z,this.rayEnd.z,r),h=n>=-1&&n<=1,f=this.ssOrigin3.distanceTo(this.closestPoint)<.5*o;if(h&&f){this.line.start.fromBufferAttribute(d,t),this.line.end.fromBufferAttribute(y,t),this.line.start.applyMatrix4(u),this.line.end.applyMatrix4(u);const r=new i.Vector3,a=new i.Vector3;s.distanceSqToSegment(this.line.start,this.line.end,a,r),e.push({distance:s.origin.distanceTo(a),point:a,face:null,faceIndex:t,object:this,uv:void 0,pointOnLine:r})}}}))}}exports.LineSegments2=n;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three"),e=require("./LineSegmentsGeometry.cjs.js"),n=require("./LineMaterial.cjs.js");const r=new t.Vector3,i=new t.Vector3,a=new t.Vector4,o=new t.Vector4,s=new t.Vector4,c=new t.Vector3,l=new t.Matrix4,u=new t.Line3,p=new t.Vector3,d=new t.Box3,f=new t.Sphere,m=new t.Vector4;let y,x,w,h;function b(t,e,n){return m.set(0,0,-e,1).applyMatrix4(t.projectionMatrix),m.multiplyScalar(1/m.w),m.x=h/n.width,m.y=h/n.height,m.applyMatrix4(t.projectionMatrixInverse),m.multiplyScalar(1/m.w),Math.abs(Math.max(m.x,m.y))}class M extends t.Mesh{constructor(t=new e.LineSegmentsGeometry,r=new n.LineMaterial({color:16777215*Math.random()})){super(t,r),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const e=this.geometry,n=e.attributes.instanceStart,a=e.attributes.instanceEnd,o=new Float32Array(2*n.count);for(let t=0,e=0,s=n.count;t<s;t++,e+=2)r.fromBufferAttribute(n,t),i.fromBufferAttribute(a,t),o[e]=0===e?0:o[e-1],o[e+1]=o[e]+r.distanceTo(i);const s=new t.InstancedInterleavedBuffer(o,2,1);return e.setAttribute("instanceDistanceStart",new t.InterleavedBufferAttribute(s,1,0)),e.setAttribute("instanceDistanceEnd",new t.InterleavedBufferAttribute(s,1,1)),this}raycast(e,n){const r=this.material.worldUnits,i=e.camera;null!==i||r||console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const m=void 0!==e.params.Line2&&e.params.Line2.threshold||0;y=e.ray;const M=this.matrixWorld,S=this.geometry,g=this.material;let B,z;if(h=g.linewidth+m,x=S.attributes.instanceStart,w=S.attributes.instanceEnd,null===S.boundingSphere&&S.computeBoundingSphere(),f.copy(S.boundingSphere).applyMatrix4(M),r)B=.5*h;else{B=b(i,Math.max(i.near,f.distanceToPoint(y.origin)),g.resolution)}if(f.radius+=B,!1!==y.intersectsSphere(f)){if(null===S.boundingBox&&S.computeBoundingBox(),d.copy(S.boundingBox).applyMatrix4(M),r)z=.5*h;else{z=b(i,Math.max(i.near,d.distanceToPoint(y.origin)),g.resolution)}d.expandByScalar(z),!1!==y.intersectsBox(d)&&(r?function(e,n){for(let r=0,i=x.count;r<i;r++){u.start.fromBufferAttribute(x,r),u.end.fromBufferAttribute(w,r);const i=new t.Vector3,a=new t.Vector3;y.distanceSqToSegment(u.start,u.end,a,i),a.distanceTo(i)<.5*h&&n.push({point:a,pointOnLine:i,distance:y.origin.distanceTo(a),object:e,face:null,faceIndex:r,uv:null,uv2:null})}}(this,n):function(e,n,r){const i=n.projectionMatrix,d=e.material.resolution,f=e.matrixWorld,m=e.geometry,x=m.attributes.instanceStart,w=m.attributes.instanceEnd,b=-n.near;y.at(1,s),s.w=1,s.applyMatrix4(n.matrixWorldInverse),s.applyMatrix4(i),s.multiplyScalar(1/s.w),s.x*=d.x/2,s.y*=d.y/2,s.z=0,c.copy(s),l.multiplyMatrices(n.matrixWorldInverse,f);for(let n=0,s=x.count;n<s;n++){if(a.fromBufferAttribute(x,n),o.fromBufferAttribute(w,n),a.w=1,o.w=1,a.applyMatrix4(l),o.applyMatrix4(l),a.z>b&&o.z>b)continue;if(a.z>b){const t=a.z-o.z,e=(a.z-b)/t;a.lerp(o,e)}else if(o.z>b){const t=o.z-a.z,e=(o.z-b)/t;o.lerp(a,e)}a.applyMatrix4(i),o.applyMatrix4(i),a.multiplyScalar(1/a.w),o.multiplyScalar(1/o.w),a.x*=d.x/2,a.y*=d.y/2,o.x*=d.x/2,o.y*=d.y/2,u.start.copy(a),u.start.z=0,u.end.copy(o),u.end.z=0;const s=u.closestPointToPointParameter(c,!0);u.at(s,p);const m=t.MathUtils.lerp(a.z,o.z,s),M=m>=-1&&m<=1,S=c.distanceTo(p)<.5*h;if(M&&S){u.start.fromBufferAttribute(x,n),u.end.fromBufferAttribute(w,n),u.start.applyMatrix4(f),u.end.applyMatrix4(f);const i=new t.Vector3,a=new t.Vector3;y.distanceSqToSegment(u.start,u.end,a,i),r.push({point:a,pointOnLine:i,distance:y.origin.distanceTo(a),object:e,face:null,faceIndex:n,uv:null,uv2:null})}}}(this,i,n))}}}exports.LineSegments2=M;
@@ -1,22 +1,14 @@
1
- import { Mesh, Raycaster, Vector3, Intersection } from 'three';
2
- import { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry';
3
- import { LineMaterial } from '../lines/LineMaterial';
4
- declare class LineSegments2 extends Mesh<LineSegmentsGeometry, LineMaterial> {
5
- type: string;
6
- private isLineSegments2;
1
+ import { Mesh } from 'three';
2
+
3
+ import { LineMaterial } from './LineMaterial';
4
+ import { LineSegmentsGeometry } from './LineSegmentsGeometry';
5
+
6
+ export class LineSegments2 extends Mesh {
7
+ geometry: LineSegmentsGeometry;
8
+ material: LineMaterial;
9
+
7
10
  constructor(geometry?: LineSegmentsGeometry, material?: LineMaterial);
8
- private distStart;
9
- private distEnd;
10
- computeLineDistances: () => this;
11
- private rayStart;
12
- private rayEnd;
13
- private ssOrigin;
14
- private ssOrigin3;
15
- private mvMatrix;
16
- private line;
17
- private closestPoint;
18
- raycast: (raycaster: Raycaster, intersects: Array<Intersection & {
19
- pointOnLine: Vector3;
20
- }>) => void;
11
+ readonly isLineSegments2: true;
12
+
13
+ computeLineDistances(): this;
21
14
  }
22
- export { LineSegments2 };