three-stdlib 2.14.1 → 2.14.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,162 +1,309 @@
1
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import { Mesh, Vector3, InstancedInterleavedBuffer, InterleavedBufferAttribute, Vector4, Matrix4, Line3, MathUtils } from 'three';
1
+ import { Vector3, Vector4, Matrix4, Line3, Box3, Sphere, Mesh, InstancedInterleavedBuffer, InterleavedBufferAttribute, MathUtils } from 'three';
3
2
  import { LineSegmentsGeometry } from './LineSegmentsGeometry.js';
4
3
  import { LineMaterial } from './LineMaterial.js';
5
4
 
5
+ const _start = new Vector3();
6
+
7
+ const _end = new Vector3();
8
+
9
+ const _start4 = new Vector4();
10
+
11
+ const _end4 = new Vector4();
12
+
13
+ const _ssOrigin = new Vector4();
14
+
15
+ const _ssOrigin3 = new Vector3();
16
+
17
+ const _mvMatrix = new Matrix4();
18
+
19
+ const _line = new Line3();
20
+
21
+ const _closestPoint = new Vector3();
22
+
23
+ const _box = new Box3();
24
+
25
+ const _sphere = new Sphere();
26
+
27
+ const _clipToWorldVector = new Vector4();
28
+
29
+ let _ray, _instanceStart, _instanceEnd, _lineWidth; // Returns the margin required to expand by in world space given the distance from the camera,
30
+ // line width, resolution, and camera projection
31
+
32
+
33
+ function getWorldSpaceHalfWidth(camera, distance, resolution) {
34
+ // transform into clip space, adjust the x and y values by the pixel width offset, then
35
+ // transform back into world space to get world offset. Note clip space is [-1, 1] so full
36
+ // width does not need to be halved.
37
+ _clipToWorldVector.set(0, 0, -distance, 1.0).applyMatrix4(camera.projectionMatrix);
38
+
39
+ _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w);
40
+
41
+ _clipToWorldVector.x = _lineWidth / resolution.width;
42
+ _clipToWorldVector.y = _lineWidth / resolution.height;
43
+
44
+ _clipToWorldVector.applyMatrix4(camera.projectionMatrixInverse);
45
+
46
+ _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w);
47
+
48
+ return Math.abs(Math.max(_clipToWorldVector.x, _clipToWorldVector.y));
49
+ }
50
+
51
+ function raycastWorldUnits(lineSegments, intersects) {
52
+ for (let i = 0, l = _instanceStart.count; i < l; i++) {
53
+ _line.start.fromBufferAttribute(_instanceStart, i);
54
+
55
+ _line.end.fromBufferAttribute(_instanceEnd, i);
56
+
57
+ const pointOnLine = new Vector3();
58
+ const point = new Vector3();
59
+
60
+ _ray.distanceSqToSegment(_line.start, _line.end, point, pointOnLine);
61
+
62
+ const isInside = point.distanceTo(pointOnLine) < _lineWidth * 0.5;
63
+
64
+ if (isInside) {
65
+ intersects.push({
66
+ point,
67
+ pointOnLine,
68
+ distance: _ray.origin.distanceTo(point),
69
+ object: lineSegments,
70
+ face: null,
71
+ faceIndex: i,
72
+ uv: null,
73
+ uv2: null
74
+ });
75
+ }
76
+ }
77
+ }
78
+
79
+ function raycastScreenSpace(lineSegments, camera, intersects) {
80
+ const projectionMatrix = camera.projectionMatrix;
81
+ const material = lineSegments.material;
82
+ const resolution = material.resolution;
83
+ const matrixWorld = lineSegments.matrixWorld;
84
+ const geometry = lineSegments.geometry;
85
+ const instanceStart = geometry.attributes.instanceStart;
86
+ const instanceEnd = geometry.attributes.instanceEnd;
87
+ const near = -camera.near; //
88
+ // pick a point 1 unit out along the ray to avoid the ray origin
89
+ // sitting at the camera origin which will cause "w" to be 0 when
90
+ // applying the projection matrix.
91
+
92
+ _ray.at(1, _ssOrigin); // ndc space [ - 1.0, 1.0 ]
93
+
94
+
95
+ _ssOrigin.w = 1;
96
+
97
+ _ssOrigin.applyMatrix4(camera.matrixWorldInverse);
98
+
99
+ _ssOrigin.applyMatrix4(projectionMatrix);
100
+
101
+ _ssOrigin.multiplyScalar(1 / _ssOrigin.w); // screen space
102
+
103
+
104
+ _ssOrigin.x *= resolution.x / 2;
105
+ _ssOrigin.y *= resolution.y / 2;
106
+ _ssOrigin.z = 0;
107
+
108
+ _ssOrigin3.copy(_ssOrigin);
109
+
110
+ _mvMatrix.multiplyMatrices(camera.matrixWorldInverse, matrixWorld);
111
+
112
+ for (let i = 0, l = instanceStart.count; i < l; i++) {
113
+ _start4.fromBufferAttribute(instanceStart, i);
114
+
115
+ _end4.fromBufferAttribute(instanceEnd, i);
116
+
117
+ _start4.w = 1;
118
+ _end4.w = 1; // camera space
119
+
120
+ _start4.applyMatrix4(_mvMatrix);
121
+
122
+ _end4.applyMatrix4(_mvMatrix); // skip the segment if it's entirely behind the camera
123
+
124
+
125
+ const isBehindCameraNear = _start4.z > near && _end4.z > near;
126
+
127
+ if (isBehindCameraNear) {
128
+ continue;
129
+ } // trim the segment if it extends behind camera near
130
+
131
+
132
+ if (_start4.z > near) {
133
+ const deltaDist = _start4.z - _end4.z;
134
+ const t = (_start4.z - near) / deltaDist;
135
+
136
+ _start4.lerp(_end4, t);
137
+ } else if (_end4.z > near) {
138
+ const deltaDist = _end4.z - _start4.z;
139
+ const t = (_end4.z - near) / deltaDist;
140
+
141
+ _end4.lerp(_start4, t);
142
+ } // clip space
143
+
144
+
145
+ _start4.applyMatrix4(projectionMatrix);
146
+
147
+ _end4.applyMatrix4(projectionMatrix); // ndc space [ - 1.0, 1.0 ]
148
+
149
+
150
+ _start4.multiplyScalar(1 / _start4.w);
151
+
152
+ _end4.multiplyScalar(1 / _end4.w); // screen space
153
+
154
+
155
+ _start4.x *= resolution.x / 2;
156
+ _start4.y *= resolution.y / 2;
157
+ _end4.x *= resolution.x / 2;
158
+ _end4.y *= resolution.y / 2; // create 2d segment
159
+
160
+ _line.start.copy(_start4);
161
+
162
+ _line.start.z = 0;
163
+
164
+ _line.end.copy(_end4);
165
+
166
+ _line.end.z = 0; // get closest point on ray to segment
167
+
168
+ const param = _line.closestPointToPointParameter(_ssOrigin3, true);
169
+
170
+ _line.at(param, _closestPoint); // check if the intersection point is within clip space
171
+
172
+
173
+ const zPos = MathUtils.lerp(_start4.z, _end4.z, param);
174
+ const isInClipSpace = zPos >= -1 && zPos <= 1;
175
+
176
+ const isInside = _ssOrigin3.distanceTo(_closestPoint) < _lineWidth * 0.5;
177
+
178
+ if (isInClipSpace && isInside) {
179
+ _line.start.fromBufferAttribute(instanceStart, i);
180
+
181
+ _line.end.fromBufferAttribute(instanceEnd, i);
182
+
183
+ _line.start.applyMatrix4(matrixWorld);
184
+
185
+ _line.end.applyMatrix4(matrixWorld);
186
+
187
+ const pointOnLine = new Vector3();
188
+ const point = new Vector3();
189
+
190
+ _ray.distanceSqToSegment(_line.start, _line.end, point, pointOnLine);
191
+
192
+ intersects.push({
193
+ point: point,
194
+ pointOnLine: pointOnLine,
195
+ distance: _ray.origin.distanceTo(point),
196
+ object: lineSegments,
197
+ face: null,
198
+ faceIndex: i,
199
+ uv: null,
200
+ uv2: null
201
+ });
202
+ }
203
+ }
204
+ }
205
+
6
206
  class LineSegments2 extends Mesh {
7
- constructor(_geometry = new LineSegmentsGeometry(), _material = new LineMaterial({
207
+ constructor(geometry = new LineSegmentsGeometry(), material = new LineMaterial({
8
208
  color: Math.random() * 0xffffff
9
209
  })) {
10
- super(_geometry, _material);
210
+ super(geometry, material);
211
+ this.isLineSegments2 = true;
212
+ this.type = 'LineSegments2';
213
+ } // for backwards-compatibility, but could be a method of LineSegmentsGeometry...
11
214
 
12
- _defineProperty(this, "type", 'LineSegments2');
13
215
 
14
- _defineProperty(this, "isLineSegments2", true);
216
+ computeLineDistances() {
217
+ const geometry = this.geometry;
218
+ const instanceStart = geometry.attributes.instanceStart;
219
+ const instanceEnd = geometry.attributes.instanceEnd;
220
+ const lineDistances = new Float32Array(2 * instanceStart.count);
15
221
 
16
- _defineProperty(this, "distStart", new Vector3());
222
+ for (let i = 0, j = 0, l = instanceStart.count; i < l; i++, j += 2) {
223
+ _start.fromBufferAttribute(instanceStart, i);
17
224
 
18
- _defineProperty(this, "distEnd", new Vector3());
225
+ _end.fromBufferAttribute(instanceEnd, i);
19
226
 
20
- _defineProperty(this, "computeLineDistances", () => {
21
- const geometry = this.geometry;
22
- const instanceStart = geometry.attributes.instanceStart;
23
- const instanceEnd = geometry.attributes.instanceEnd;
24
- const lineDistances = new Float32Array(2 * instanceStart.data.count);
227
+ lineDistances[j] = j === 0 ? 0 : lineDistances[j - 1];
228
+ lineDistances[j + 1] = lineDistances[j] + _start.distanceTo(_end);
229
+ }
25
230
 
26
- for (let i = 0, j = 0, l = instanceStart.data.count; i < l; i++, j += 2) {
27
- this.distStart.fromBufferAttribute(instanceStart, i);
28
- this.distEnd.fromBufferAttribute(instanceEnd, i);
29
- lineDistances[j] = j === 0 ? 0 : lineDistances[j - 1];
30
- lineDistances[j + 1] = lineDistances[j] + this.distStart.distanceTo(this.distEnd);
31
- }
231
+ const instanceDistanceBuffer = new InstancedInterleavedBuffer(lineDistances, 2, 1); // d0, d1
32
232
 
33
- const instanceDistanceBuffer = new InstancedInterleavedBuffer(lineDistances, 2, 1); // d0, d1
233
+ geometry.setAttribute('instanceDistanceStart', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 0)); // d0
34
234
 
35
- geometry.setAttribute('instanceDistanceStart', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 0)); // d0
235
+ geometry.setAttribute('instanceDistanceEnd', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 1)); // d1
36
236
 
37
- geometry.setAttribute('instanceDistanceEnd', new InterleavedBufferAttribute(instanceDistanceBuffer, 1, 1)); // d1
38
-
39
- return this;
40
- });
237
+ return this;
238
+ }
41
239
 
42
- _defineProperty(this, "rayStart", new Vector4());
240
+ raycast(raycaster, intersects) {
241
+ const worldUnits = this.material.worldUnits;
242
+ const camera = raycaster.camera;
43
243
 
44
- _defineProperty(this, "rayEnd", new Vector4());
244
+ if (camera === null && !worldUnits) {
245
+ console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');
246
+ }
45
247
 
46
- _defineProperty(this, "ssOrigin", new Vector4());
248
+ const threshold = raycaster.params.Line2 !== undefined ? raycaster.params.Line2.threshold || 0 : 0;
249
+ _ray = raycaster.ray;
250
+ const matrixWorld = this.matrixWorld;
251
+ const geometry = this.geometry;
252
+ const material = this.material;
253
+ _lineWidth = material.linewidth + threshold;
254
+ _instanceStart = geometry.attributes.instanceStart;
255
+ _instanceEnd = geometry.attributes.instanceEnd; // check if we intersect the sphere bounds
47
256
 
48
- _defineProperty(this, "ssOrigin3", new Vector3());
257
+ if (geometry.boundingSphere === null) {
258
+ geometry.computeBoundingSphere();
259
+ }
49
260
 
50
- _defineProperty(this, "mvMatrix", new Matrix4());
261
+ _sphere.copy(geometry.boundingSphere).applyMatrix4(matrixWorld); // increase the sphere bounds by the worst case line screen space width
51
262
 
52
- _defineProperty(this, "line", new Line3());
53
263
 
54
- _defineProperty(this, "closestPoint", new Vector3());
264
+ let sphereMargin;
55
265
 
56
- _defineProperty(this, "raycast", (raycaster, intersects) => {
57
- if (raycaster.camera === null) {
58
- console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2.');
59
- }
266
+ if (worldUnits) {
267
+ sphereMargin = _lineWidth * 0.5;
268
+ } else {
269
+ const distanceToSphere = Math.max(camera.near, _sphere.distanceToPoint(_ray.origin));
270
+ sphereMargin = getWorldSpaceHalfWidth(camera, distanceToSphere, material.resolution);
271
+ }
60
272
 
61
- const threshold = 0;
62
- const ray = raycaster.ray;
63
- const camera = raycaster.camera;
64
- const projectionMatrix = camera.projectionMatrix;
65
- const geometry = this.geometry;
66
- const material = this.material;
67
- const resolution = material.resolution;
68
- const lineWidth = material.linewidth + threshold;
69
- const instanceStart = geometry.attributes.instanceStart;
70
- const instanceEnd = geometry.attributes.instanceEnd; // camera forward is negative
273
+ _sphere.radius += sphereMargin;
71
274
 
72
- const near = -camera.near; // pick a point 1 unit out along the ray to avoid the ray origin
73
- // sitting at the camera origin which will cause "w" to be 0 when
74
- // applying the projection matrix.
275
+ if (_ray.intersectsSphere(_sphere) === false) {
276
+ return;
277
+ } // check if we intersect the box bounds
75
278
 
76
- ray.at(1, this.ssOrigin); // ndc space [ - 1.0, 1.0 ]
77
279
 
78
- this.ssOrigin.w = 1;
79
- this.ssOrigin.applyMatrix4(camera.matrixWorldInverse);
80
- this.ssOrigin.applyMatrix4(projectionMatrix);
81
- this.ssOrigin.multiplyScalar(1 / this.ssOrigin.w); // screen space
280
+ if (geometry.boundingBox === null) {
281
+ geometry.computeBoundingBox();
282
+ }
82
283
 
83
- this.ssOrigin.x *= resolution.x / 2;
84
- this.ssOrigin.y *= resolution.y / 2;
85
- this.ssOrigin.z = 0;
86
- this.ssOrigin3.set(this.ssOrigin.x, this.ssOrigin.y, this.ssOrigin.z);
87
- const matrixWorld = this.matrixWorld;
88
- this.mvMatrix.multiplyMatrices(camera.matrixWorldInverse, matrixWorld);
284
+ _box.copy(geometry.boundingBox).applyMatrix4(matrixWorld); // increase the box bounds by the worst case line width
89
285
 
90
- for (let i = 0, l = instanceStart.count; i < l; i++) {
91
- this.rayStart.fromBufferAttribute(instanceStart, i);
92
- this.rayEnd.fromBufferAttribute(instanceEnd, i);
93
- this.rayStart.w = 1;
94
- this.rayEnd.w = 1; // camera space
95
286
 
96
- this.rayStart.applyMatrix4(this.mvMatrix);
97
- this.rayEnd.applyMatrix4(this.mvMatrix); // skip the segment if it's entirely behind the camera
287
+ let boxMargin;
98
288
 
99
- const isBehindCameraNear = this.rayStart.z > near && this.rayEnd.z > near;
289
+ if (worldUnits) {
290
+ boxMargin = _lineWidth * 0.5;
291
+ } else {
292
+ const distanceToBox = Math.max(camera.near, _box.distanceToPoint(_ray.origin));
293
+ boxMargin = getWorldSpaceHalfWidth(camera, distanceToBox, material.resolution);
294
+ }
100
295
 
101
- if (isBehindCameraNear) {
102
- continue;
103
- } // trim the segment if it extends behind camera near
296
+ _box.expandByScalar(boxMargin);
104
297
 
298
+ if (_ray.intersectsBox(_box) === false) {
299
+ return;
300
+ }
105
301
 
106
- if (this.rayStart.z > near) {
107
- const deltaDist = this.rayStart.z - this.rayEnd.z;
108
- const t = (this.rayStart.z - near) / deltaDist;
109
- this.rayStart.lerp(this.rayEnd, t);
110
- } else if (this.rayEnd.z > near) {
111
- const deltaDist = this.rayEnd.z - this.rayStart.z;
112
- const t = (this.rayEnd.z - near) / deltaDist;
113
- this.rayEnd.lerp(this.rayStart, t);
114
- } // clip space
115
-
116
-
117
- this.rayStart.applyMatrix4(projectionMatrix);
118
- this.rayEnd.applyMatrix4(projectionMatrix); // ndc space [ - 1.0, 1.0 ]
119
-
120
- this.rayStart.multiplyScalar(1 / this.rayStart.w);
121
- this.rayEnd.multiplyScalar(1 / this.rayEnd.w); // screen space
122
-
123
- this.rayStart.x *= resolution.x / 2;
124
- this.rayStart.y *= resolution.y / 2;
125
- this.rayEnd.x *= resolution.x / 2;
126
- this.rayEnd.y *= resolution.y / 2; // create 2d segment
127
-
128
- this.line.start.set(this.rayStart.x, this.rayStart.y, this.rayStart.z);
129
- this.line.start.z = 0;
130
- this.line.end.set(this.rayEnd.x, this.rayEnd.y, this.rayEnd.z);
131
- this.line.end.z = 0; // get closest point on ray to segment
132
-
133
- const param = this.line.closestPointToPointParameter(this.ssOrigin3, true);
134
- this.line.at(param, this.closestPoint); // check if the intersection point is within clip space
135
-
136
- const zPos = MathUtils.lerp(this.rayStart.z, this.rayEnd.z, param);
137
- const isInClipSpace = zPos >= -1 && zPos <= 1;
138
- const isInside = this.ssOrigin3.distanceTo(this.closestPoint) < lineWidth * 0.5;
139
-
140
- if (isInClipSpace && isInside) {
141
- this.line.start.fromBufferAttribute(instanceStart, i);
142
- this.line.end.fromBufferAttribute(instanceEnd, i);
143
- this.line.start.applyMatrix4(matrixWorld);
144
- this.line.end.applyMatrix4(matrixWorld);
145
- const pointOnLine = new Vector3();
146
- const point = new Vector3();
147
- ray.distanceSqToSegment(this.line.start, this.line.end, point, pointOnLine);
148
- intersects.push({
149
- distance: ray.origin.distanceTo(point),
150
- point: point,
151
- face: null,
152
- faceIndex: i,
153
- object: this,
154
- uv: undefined,
155
- pointOnLine
156
- });
157
- }
158
- }
159
- });
302
+ if (worldUnits) {
303
+ raycastWorldUnits(this, intersects);
304
+ } else {
305
+ raycastScreenSpace(this, camera, intersects);
306
+ }
160
307
  }
161
308
 
162
309
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@babel/runtime/helpers/defineProperty"),e=require("three");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=r(t);class n extends e.InstancedBufferGeometry{constructor(){super(),i.default(this,"isLineSegmentsGeometry",!0),i.default(this,"type","LineSegmentsGeometry"),i.default(this,"boundingBox",null),i.default(this,"boundingSphere",null),i.default(this,"box",new e.Box3),i.default(this,"vector",new e.Vector3);this.setIndex([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]),this.setAttribute("position",new e.Float32BufferAttribute([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],3)),this.setAttribute("uv",new e.Float32BufferAttribute([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],2))}applyMatrix4(t){const e=this.attributes.instanceStart,r=this.attributes.instanceEnd;return void 0!==e&&(e.applyMatrix4(t),r.applyMatrix4(t),e.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}setPositions(t){let r;if(t instanceof Float32Array)r=t;else{if(!Array.isArray(t))return console.error("LineSegmentsGeometry.setPosition requires either a Float32Array or regular array of numbers"),this;r=new Float32Array(t)}const i=new e.InstancedInterleavedBuffer(r,6,1);return this.setAttribute("instanceStart",new e.InterleavedBufferAttribute(i,3,0)),this.setAttribute("instanceEnd",new e.InterleavedBufferAttribute(i,3,3)),this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(t){let r;if(t instanceof Float32Array)r=t;else{if(!Array.isArray(t))return console.error("LineSegmentsGeometry.setColors requires either a Float32Array or regular array of numbers"),this;r=new Float32Array(t)}const i=new e.InstancedInterleavedBuffer(r,6,1);return this.setAttribute("instanceColorStart",new e.InterleavedBufferAttribute(i,3,0)),this.setAttribute("instanceColorEnd",new e.InterleavedBufferAttribute(i,3,3)),this}fromWireframeGeometry(t){return this.setPositions(Array.from(t.attributes.position.array)),this}fromEdgesGeometry(t){return this.setPositions(Array.from(t.attributes.position.array)),this}fromMesh(t){return this.fromWireframeGeometry(new e.WireframeGeometry(t.geometry)),this}fromLineSegments(t){const e=t.geometry;return e.isBufferGeometry&&this.setPositions(Array.from(e.attributes.position.array)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new e.Box3);const t=this.attributes.instanceStart,r=this.attributes.instanceEnd;void 0!==t&&void 0!==r&&(this.boundingBox.setFromBufferAttribute(t),this.box.setFromBufferAttribute(r),this.boundingBox.union(this.box))}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new e.Sphere),null===this.boundingBox&&this.computeBoundingBox();const t=this.attributes.instanceStart,r=this.attributes.instanceEnd;if(void 0!==t&&void 0!==r){const e=this.boundingSphere.center;this.boundingBox&&this.boundingBox.getCenter(e);let i=0;for(let n=0,s=t.count;n<s;n++)this.vector.fromBufferAttribute(t,n),i=Math.max(i,e.distanceToSquared(this.vector)),this.vector.fromBufferAttribute(r,n),i=Math.max(i,e.distanceToSquared(this.vector));this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.",this)}}toJSON(){}}exports.LineSegmentsGeometry=n;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");const e=new t.Box3,r=new t.Vector3;class i extends t.InstancedBufferGeometry{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type="LineSegmentsGeometry";this.setIndex([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]),this.setAttribute("position",new t.Float32BufferAttribute([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],3)),this.setAttribute("uv",new t.Float32BufferAttribute([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],2))}applyMatrix4(t){const e=this.attributes.instanceStart,r=this.attributes.instanceEnd;return void 0!==e&&(e.applyMatrix4(t),r.applyMatrix4(t),e.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}setPositions(e){let r;e instanceof Float32Array?r=e:Array.isArray(e)&&(r=new Float32Array(e));const i=new t.InstancedInterleavedBuffer(r,6,1);return this.setAttribute("instanceStart",new t.InterleavedBufferAttribute(i,3,0)),this.setAttribute("instanceEnd",new t.InterleavedBufferAttribute(i,3,3)),this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(e){let r;e instanceof Float32Array?r=e:Array.isArray(e)&&(r=new Float32Array(e));const i=new t.InstancedInterleavedBuffer(r,6,1);return this.setAttribute("instanceColorStart",new t.InterleavedBufferAttribute(i,3,0)),this.setAttribute("instanceColorEnd",new t.InterleavedBufferAttribute(i,3,3)),this}fromWireframeGeometry(t){return this.setPositions(t.attributes.position.array),this}fromEdgesGeometry(t){return this.setPositions(t.attributes.position.array),this}fromMesh(e){return this.fromWireframeGeometry(new t.WireframeGeometry(e.geometry)),this}fromLineSegments(t){const e=t.geometry;return this.setPositions(e.attributes.position.array),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new t.Box3);const r=this.attributes.instanceStart,i=this.attributes.instanceEnd;void 0!==r&&void 0!==i&&(this.boundingBox.setFromBufferAttribute(r),e.setFromBufferAttribute(i),this.boundingBox.union(e))}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new t.Sphere),null===this.boundingBox&&this.computeBoundingBox();const e=this.attributes.instanceStart,i=this.attributes.instanceEnd;if(void 0!==e&&void 0!==i){const t=this.boundingSphere.center;this.boundingBox.getCenter(t);let n=0;for(let s=0,o=e.count;s<o;s++)r.fromBufferAttribute(e,s),n=Math.max(n,t.distanceToSquared(r)),r.fromBufferAttribute(i,s),n=Math.max(n,t.distanceToSquared(r));this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.",this)}}toJSON(){}applyMatrix(t){return console.warn("THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4()."),this.applyMatrix4(t)}}exports.LineSegmentsGeometry=i;
@@ -1,21 +1,23 @@
1
- import { Box3, BufferGeometry, InstancedBufferGeometry, LineSegments, Matrix4, Mesh, Sphere } from 'three';
2
- declare class LineSegmentsGeometry extends InstancedBufferGeometry {
3
- readonly isLineSegmentsGeometry = true;
4
- type: string;
5
- boundingBox: Box3 | null;
6
- boundingSphere: Sphere | null;
1
+ import {
2
+ EdgesGeometry,
3
+ InstancedBufferGeometry,
4
+ LineSegments,
5
+ Matrix4,
6
+ Mesh,
7
+ WireframeGeometry,
8
+ } from 'three';
9
+
10
+ export class LineSegmentsGeometry extends InstancedBufferGeometry {
7
11
  constructor();
12
+ readonly isLineSegmentsGeometry: true;
13
+
8
14
  applyMatrix4(matrix: Matrix4): this;
9
- setPositions(array: number[] | Float32Array): this;
10
- setColors(array: number[] | Float32Array): this;
11
- fromWireframeGeometry(geometry: BufferGeometry): this;
12
- fromEdgesGeometry(geometry: BufferGeometry): this;
13
- fromMesh(mesh: Mesh): this;
14
- fromLineSegments(lineSegments: LineSegments): this;
15
- private box;
16
15
  computeBoundingBox(): void;
17
- private vector;
18
16
  computeBoundingSphere(): void;
19
- toJSON(): void;
17
+ fromEdgesGeometry(geometry: EdgesGeometry): this;
18
+ fromLineSegments(lineSegments: LineSegments): this;
19
+ fromMesh(mesh: Mesh): this;
20
+ fromWireframeGeometry(geometry: WireframeGeometry): this;
21
+ setColors(array: number[] | Float32Array): this;
22
+ setPositions(array: number[] | Float32Array): this;
20
23
  }
21
- export { LineSegmentsGeometry };
@@ -1,22 +1,14 @@
1
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import { InstancedBufferGeometry, Box3, Vector3, Float32BufferAttribute, InstancedInterleavedBuffer, InterleavedBufferAttribute, WireframeGeometry, Sphere } from 'three';
1
+ import { Box3, Vector3, InstancedBufferGeometry, Float32BufferAttribute, InstancedInterleavedBuffer, InterleavedBufferAttribute, WireframeGeometry, Sphere } from 'three';
2
+
3
+ const _box = new Box3();
4
+
5
+ const _vector = new Vector3();
3
6
 
4
7
  class LineSegmentsGeometry extends InstancedBufferGeometry {
5
8
  constructor() {
6
9
  super();
7
-
8
- _defineProperty(this, "isLineSegmentsGeometry", true);
9
-
10
- _defineProperty(this, "type", 'LineSegmentsGeometry');
11
-
12
- _defineProperty(this, "boundingBox", null);
13
-
14
- _defineProperty(this, "boundingSphere", null);
15
-
16
- _defineProperty(this, "box", new Box3());
17
-
18
- _defineProperty(this, "vector", new Vector3());
19
-
10
+ this.isLineSegmentsGeometry = true;
11
+ this.type = 'LineSegmentsGeometry';
20
12
  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];
21
13
  const uvs = [-1, 2, 1, 2, -1, 1, 1, 1, -1, -1, 1, -1, -1, -2, 1, -2];
22
14
  const index = [0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5];
@@ -53,9 +45,6 @@ class LineSegmentsGeometry extends InstancedBufferGeometry {
53
45
  lineSegments = array;
54
46
  } else if (Array.isArray(array)) {
55
47
  lineSegments = new Float32Array(array);
56
- } else {
57
- console.error('LineSegmentsGeometry.setPosition requires either a Float32Array or regular array of numbers');
58
- return this;
59
48
  }
60
49
 
61
50
  const instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1); // xyz, xyz
@@ -77,9 +66,6 @@ class LineSegmentsGeometry extends InstancedBufferGeometry {
77
66
  colors = array;
78
67
  } else if (Array.isArray(array)) {
79
68
  colors = new Float32Array(array);
80
- } else {
81
- console.error('LineSegmentsGeometry.setColors requires either a Float32Array or regular array of numbers');
82
- return this;
83
69
  }
84
70
 
85
71
  const instanceColorBuffer = new InstancedInterleavedBuffer(colors, 6, 1); // rgb, rgb
@@ -92,27 +78,25 @@ class LineSegmentsGeometry extends InstancedBufferGeometry {
92
78
  }
93
79
 
94
80
  fromWireframeGeometry(geometry) {
95
- this.setPositions(Array.from(geometry.attributes.position.array));
81
+ this.setPositions(geometry.attributes.position.array);
96
82
  return this;
97
83
  }
98
84
 
99
85
  fromEdgesGeometry(geometry) {
100
- this.setPositions(Array.from(geometry.attributes.position.array));
86
+ this.setPositions(geometry.attributes.position.array);
101
87
  return this;
102
88
  }
103
89
 
104
90
  fromMesh(mesh) {
105
- this.fromWireframeGeometry(new WireframeGeometry(mesh.geometry));
91
+ this.fromWireframeGeometry(new WireframeGeometry(mesh.geometry)); // set colors, maybe
92
+
106
93
  return this;
107
94
  }
108
95
 
109
96
  fromLineSegments(lineSegments) {
110
97
  const geometry = lineSegments.geometry;
111
-
112
- if (geometry.isBufferGeometry) {
113
- this.setPositions(Array.from(geometry.attributes.position.array)); // assumes non-indexed
114
- } // set colors, maybe
115
-
98
+ this.setPositions(geometry.attributes.position.array); // assumes non-indexed
99
+ // set colors, maybe
116
100
 
117
101
  return this;
118
102
  }
@@ -127,8 +111,10 @@ class LineSegmentsGeometry extends InstancedBufferGeometry {
127
111
 
128
112
  if (start !== undefined && end !== undefined) {
129
113
  this.boundingBox.setFromBufferAttribute(start);
130
- this.box.setFromBufferAttribute(end);
131
- this.boundingBox.union(this.box);
114
+
115
+ _box.setFromBufferAttribute(end);
116
+
117
+ this.boundingBox.union(_box);
132
118
  }
133
119
  }
134
120
 
@@ -146,18 +132,17 @@ class LineSegmentsGeometry extends InstancedBufferGeometry {
146
132
 
147
133
  if (start !== undefined && end !== undefined) {
148
134
  const center = this.boundingSphere.center;
149
-
150
- if (this.boundingBox) {
151
- this.boundingBox.getCenter(center);
152
- }
153
-
135
+ this.boundingBox.getCenter(center);
154
136
  let maxRadiusSq = 0;
155
137
 
156
138
  for (let i = 0, il = start.count; i < il; i++) {
157
- this.vector.fromBufferAttribute(start, i);
158
- maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(this.vector));
159
- this.vector.fromBufferAttribute(end, i);
160
- maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(this.vector));
139
+ _vector.fromBufferAttribute(start, i);
140
+
141
+ maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector));
142
+
143
+ _vector.fromBufferAttribute(end, i);
144
+
145
+ maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector));
161
146
  }
162
147
 
163
148
  this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
@@ -171,6 +156,11 @@ class LineSegmentsGeometry extends InstancedBufferGeometry {
171
156
  toJSON() {// todo
172
157
  }
173
158
 
159
+ applyMatrix(matrix) {
160
+ console.warn('THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().');
161
+ return this.applyMatrix4(matrix);
162
+ }
163
+
174
164
  }
175
165
 
176
166
  export { LineSegmentsGeometry };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("./LineSegmentsGeometry.cjs.js"),r=require("./LineMaterial.cjs.js");require("@babel/runtime/helpers/defineProperty");var i,n,a=function(i,n){e.Mesh.call(this),this.type="Wireframe",this.geometry=void 0!==i?i:new t.LineSegmentsGeometry,this.material=void 0!==n?n:new r.LineMaterial({color:16777215*Math.random()})};a.prototype=Object.assign(Object.create(e.Mesh.prototype),{constructor:a,isWireframe:!0,computeLineDistances:(i=new e.Vector3,n=new e.Vector3,function(){var t=this.geometry,r=t.attributes.instanceStart,a=t.attributes.instanceEnd,s=new Float32Array(2*r.data.count);for(let e=0,t=0,o=r.data.count;e<o;e++,t+=2)i.fromBufferAttribute(r,e),n.fromBufferAttribute(a,e),s[t]=0===t?0:s[t-1],s[t+1]=s[t]+i.distanceTo(n);var o=new e.InstancedInterleavedBuffer(s,2,1);return t.setAttribute("instanceDistanceStart",new e.InterleavedBufferAttribute(o,1,0)),t.setAttribute("instanceDistanceEnd",new e.InterleavedBufferAttribute(o,1,1)),this})}),exports.Wireframe=a;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("./LineSegmentsGeometry.cjs.js"),r=require("./LineMaterial.cjs.js");const n=new e.Vector3,s=new e.Vector3;class i extends e.Mesh{constructor(e=new t.LineSegmentsGeometry,n=new r.LineMaterial({color:16777215*Math.random()})){super(e,n),this.isWireframe=!0,this.type="Wireframe"}computeLineDistances(){const t=this.geometry,r=t.attributes.instanceStart,i=t.attributes.instanceEnd,a=new Float32Array(2*r.count);for(let e=0,t=0,c=r.count;e<c;e++,t+=2)n.fromBufferAttribute(r,e),s.fromBufferAttribute(i,e),a[t]=0===t?0:a[t-1],a[t+1]=a[t]+n.distanceTo(s);const c=new e.InstancedInterleavedBuffer(a,2,1);return t.setAttribute("instanceDistanceStart",new e.InterleavedBufferAttribute(c,1,0)),t.setAttribute("instanceDistanceEnd",new e.InterleavedBufferAttribute(c,1,1)),this}}exports.Wireframe=i;