@classcad/mcp 0.1.4 → 0.2.0
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.
- package/README.md +20 -2
- package/dist/auth.d.ts +7 -0
- package/dist/auth.js +2 -2
- package/dist/auth.js.map +1 -1
- package/dist/client.js +27 -0
- package/dist/client.js.map +1 -1
- package/dist/mcp-server.d.ts +1 -1
- package/dist/mcp-server.js +9 -3
- package/dist/mcp-server.js.map +1 -1
- package/dist/queue.d.ts +7 -0
- package/dist/queue.js +22 -9
- package/dist/queue.js.map +1 -1
- package/dist/tools/auth.js +1 -1
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/docs.js +1 -0
- package/dist/tools/docs.js.map +1 -1
- package/dist/tools/lifecycle.js +41 -19
- package/dist/tools/lifecycle.js.map +1 -1
- package/dist/tools/viewer.d.ts +6 -0
- package/dist/tools/viewer.js +110 -0
- package/dist/tools/viewer.js.map +1 -0
- package/dist/viewer/scene.d.ts +60 -0
- package/dist/viewer/scene.js +271 -0
- package/dist/viewer/scene.js.map +1 -0
- package/dist/viewer/server.d.ts +27 -0
- package/dist/viewer/server.js +229 -0
- package/dist/viewer/server.js.map +1 -0
- package/dist/viewer-page/cube.svg +15 -0
- package/dist/viewer-page/fonts/LICENSE.txt +3 -0
- package/dist/viewer-page/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/dist/viewer-page/index.html +135 -0
- package/dist/viewer-page/vendor/LICENSE.txt +21 -0
- package/dist/viewer-page/vendor/VERSION.txt +1 -0
- package/dist/viewer-page/vendor/addons/controls/OrbitControls.js +1963 -0
- package/dist/viewer-page/vendor/addons/lines/LineMaterial.js +726 -0
- package/dist/viewer-page/vendor/addons/lines/LineSegments2.js +434 -0
- package/dist/viewer-page/vendor/addons/lines/LineSegmentsGeometry.js +298 -0
- package/dist/viewer-page/vendor/three.core.min.js +6 -0
- package/dist/viewer-page/vendor/three.module.min.js +6 -0
- package/dist/viewer-page/viewer.css +717 -0
- package/dist/viewer-page/viewer.js +530 -0
- package/package.json +3 -2
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box3,
|
|
3
|
+
InstancedInterleavedBuffer,
|
|
4
|
+
InterleavedBufferAttribute,
|
|
5
|
+
Line3,
|
|
6
|
+
MathUtils,
|
|
7
|
+
Matrix4,
|
|
8
|
+
Mesh,
|
|
9
|
+
Sphere,
|
|
10
|
+
Vector3,
|
|
11
|
+
Vector4
|
|
12
|
+
} from 'three';
|
|
13
|
+
import { LineSegmentsGeometry } from './LineSegmentsGeometry.js';
|
|
14
|
+
import { LineMaterial } from './LineMaterial.js';
|
|
15
|
+
|
|
16
|
+
const _viewport = new Vector4();
|
|
17
|
+
|
|
18
|
+
const _start = new Vector3();
|
|
19
|
+
const _end = new Vector3();
|
|
20
|
+
|
|
21
|
+
const _start4 = new Vector4();
|
|
22
|
+
const _end4 = new Vector4();
|
|
23
|
+
|
|
24
|
+
const _ssOrigin = new Vector4();
|
|
25
|
+
const _ssOrigin3 = new Vector3();
|
|
26
|
+
const _mvMatrix = new Matrix4();
|
|
27
|
+
const _line = new Line3();
|
|
28
|
+
const _closestPoint = new Vector3();
|
|
29
|
+
|
|
30
|
+
const _box = new Box3();
|
|
31
|
+
const _sphere = new Sphere();
|
|
32
|
+
const _clipToWorldVector = new Vector4();
|
|
33
|
+
|
|
34
|
+
let _ray, _lineWidth;
|
|
35
|
+
|
|
36
|
+
// Returns the margin required to expand by in world space given the distance from the camera,
|
|
37
|
+
// line width, resolution, and camera projection
|
|
38
|
+
function getWorldSpaceHalfWidth( camera, distance, resolution ) {
|
|
39
|
+
|
|
40
|
+
// transform into clip space, adjust the x and y values by the pixel width offset, then
|
|
41
|
+
// transform back into world space to get world offset. Note clip space is [-1, 1] so full
|
|
42
|
+
// width does not need to be halved.
|
|
43
|
+
_clipToWorldVector.set( 0, 0, - distance, 1.0 ).applyMatrix4( camera.projectionMatrix );
|
|
44
|
+
_clipToWorldVector.multiplyScalar( 1.0 / _clipToWorldVector.w );
|
|
45
|
+
_clipToWorldVector.x = _lineWidth / resolution.width;
|
|
46
|
+
_clipToWorldVector.y = _lineWidth / resolution.height;
|
|
47
|
+
_clipToWorldVector.applyMatrix4( camera.projectionMatrixInverse );
|
|
48
|
+
_clipToWorldVector.multiplyScalar( 1.0 / _clipToWorldVector.w );
|
|
49
|
+
|
|
50
|
+
return Math.abs( Math.max( _clipToWorldVector.x, _clipToWorldVector.y ) );
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function raycastWorldUnits( lineSegments, intersects ) {
|
|
55
|
+
|
|
56
|
+
const matrixWorld = lineSegments.matrixWorld;
|
|
57
|
+
const geometry = lineSegments.geometry;
|
|
58
|
+
const instanceStart = geometry.attributes.instanceStart;
|
|
59
|
+
const instanceEnd = geometry.attributes.instanceEnd;
|
|
60
|
+
const segmentCount = Math.min( geometry.instanceCount, instanceStart.count );
|
|
61
|
+
|
|
62
|
+
for ( let i = 0, l = segmentCount; i < l; i ++ ) {
|
|
63
|
+
|
|
64
|
+
_line.start.fromBufferAttribute( instanceStart, i );
|
|
65
|
+
_line.end.fromBufferAttribute( instanceEnd, i );
|
|
66
|
+
|
|
67
|
+
_line.applyMatrix4( matrixWorld );
|
|
68
|
+
|
|
69
|
+
const pointOnLine = new Vector3();
|
|
70
|
+
const point = new Vector3();
|
|
71
|
+
|
|
72
|
+
_ray.distanceSqToSegment( _line.start, _line.end, point, pointOnLine );
|
|
73
|
+
const isInside = point.distanceTo( pointOnLine ) < _lineWidth * 0.5;
|
|
74
|
+
|
|
75
|
+
if ( isInside ) {
|
|
76
|
+
|
|
77
|
+
intersects.push( {
|
|
78
|
+
point,
|
|
79
|
+
pointOnLine,
|
|
80
|
+
distance: _ray.origin.distanceTo( point ),
|
|
81
|
+
object: lineSegments,
|
|
82
|
+
face: null,
|
|
83
|
+
faceIndex: i,
|
|
84
|
+
uv: null,
|
|
85
|
+
uv1: null,
|
|
86
|
+
} );
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function raycastScreenSpace( lineSegments, camera, intersects ) {
|
|
95
|
+
|
|
96
|
+
const projectionMatrix = camera.projectionMatrix;
|
|
97
|
+
const material = lineSegments.material;
|
|
98
|
+
const resolution = material.resolution;
|
|
99
|
+
const matrixWorld = lineSegments.matrixWorld;
|
|
100
|
+
|
|
101
|
+
const geometry = lineSegments.geometry;
|
|
102
|
+
const instanceStart = geometry.attributes.instanceStart;
|
|
103
|
+
const instanceEnd = geometry.attributes.instanceEnd;
|
|
104
|
+
const segmentCount = Math.min( geometry.instanceCount, instanceStart.count );
|
|
105
|
+
|
|
106
|
+
const near = - camera.near;
|
|
107
|
+
|
|
108
|
+
//
|
|
109
|
+
|
|
110
|
+
// pick a point 1 unit out along the ray to avoid the ray origin
|
|
111
|
+
// sitting at the camera origin which will cause "w" to be 0 when
|
|
112
|
+
// applying the projection matrix.
|
|
113
|
+
_ray.at( 1, _ssOrigin );
|
|
114
|
+
|
|
115
|
+
// ndc space [ - 1.0, 1.0 ]
|
|
116
|
+
_ssOrigin.w = 1;
|
|
117
|
+
_ssOrigin.applyMatrix4( camera.matrixWorldInverse );
|
|
118
|
+
_ssOrigin.applyMatrix4( projectionMatrix );
|
|
119
|
+
_ssOrigin.multiplyScalar( 1 / _ssOrigin.w );
|
|
120
|
+
|
|
121
|
+
// screen space
|
|
122
|
+
_ssOrigin.x *= resolution.x / 2;
|
|
123
|
+
_ssOrigin.y *= resolution.y / 2;
|
|
124
|
+
_ssOrigin.z = 0;
|
|
125
|
+
|
|
126
|
+
_ssOrigin3.copy( _ssOrigin );
|
|
127
|
+
|
|
128
|
+
_mvMatrix.multiplyMatrices( camera.matrixWorldInverse, matrixWorld );
|
|
129
|
+
|
|
130
|
+
for ( let i = 0, l = segmentCount; i < l; i ++ ) {
|
|
131
|
+
|
|
132
|
+
_start4.fromBufferAttribute( instanceStart, i );
|
|
133
|
+
_end4.fromBufferAttribute( instanceEnd, i );
|
|
134
|
+
|
|
135
|
+
_start4.w = 1;
|
|
136
|
+
_end4.w = 1;
|
|
137
|
+
|
|
138
|
+
// camera space
|
|
139
|
+
_start4.applyMatrix4( _mvMatrix );
|
|
140
|
+
_end4.applyMatrix4( _mvMatrix );
|
|
141
|
+
|
|
142
|
+
// skip the segment if it's entirely behind the camera
|
|
143
|
+
const isBehindCameraNear = _start4.z > near && _end4.z > near;
|
|
144
|
+
if ( isBehindCameraNear ) {
|
|
145
|
+
|
|
146
|
+
continue;
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// trim the segment if it extends behind camera near
|
|
151
|
+
if ( _start4.z > near ) {
|
|
152
|
+
|
|
153
|
+
const deltaDist = _start4.z - _end4.z;
|
|
154
|
+
const t = ( _start4.z - near ) / deltaDist;
|
|
155
|
+
_start4.lerp( _end4, t );
|
|
156
|
+
|
|
157
|
+
} else if ( _end4.z > near ) {
|
|
158
|
+
|
|
159
|
+
const deltaDist = _end4.z - _start4.z;
|
|
160
|
+
const t = ( _end4.z - near ) / deltaDist;
|
|
161
|
+
_end4.lerp( _start4, t );
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// clip space
|
|
166
|
+
_start4.applyMatrix4( projectionMatrix );
|
|
167
|
+
_end4.applyMatrix4( projectionMatrix );
|
|
168
|
+
|
|
169
|
+
// ndc space [ - 1.0, 1.0 ]
|
|
170
|
+
_start4.multiplyScalar( 1 / _start4.w );
|
|
171
|
+
_end4.multiplyScalar( 1 / _end4.w );
|
|
172
|
+
|
|
173
|
+
// screen space
|
|
174
|
+
_start4.x *= resolution.x / 2;
|
|
175
|
+
_start4.y *= resolution.y / 2;
|
|
176
|
+
|
|
177
|
+
_end4.x *= resolution.x / 2;
|
|
178
|
+
_end4.y *= resolution.y / 2;
|
|
179
|
+
|
|
180
|
+
// create 2d segment
|
|
181
|
+
_line.start.copy( _start4 );
|
|
182
|
+
_line.start.z = 0;
|
|
183
|
+
|
|
184
|
+
_line.end.copy( _end4 );
|
|
185
|
+
_line.end.z = 0;
|
|
186
|
+
|
|
187
|
+
// get closest point on ray to segment
|
|
188
|
+
const param = _line.closestPointToPointParameter( _ssOrigin3, true );
|
|
189
|
+
_line.at( param, _closestPoint );
|
|
190
|
+
|
|
191
|
+
// check if the intersection point is within clip space
|
|
192
|
+
const zPos = MathUtils.lerp( _start4.z, _end4.z, param );
|
|
193
|
+
const isInClipSpace = zPos >= - 1 && zPos <= 1;
|
|
194
|
+
|
|
195
|
+
const isInside = _ssOrigin3.distanceTo( _closestPoint ) < _lineWidth * 0.5;
|
|
196
|
+
|
|
197
|
+
if ( isInClipSpace && isInside ) {
|
|
198
|
+
|
|
199
|
+
_line.start.fromBufferAttribute( instanceStart, i );
|
|
200
|
+
_line.end.fromBufferAttribute( instanceEnd, i );
|
|
201
|
+
|
|
202
|
+
_line.start.applyMatrix4( matrixWorld );
|
|
203
|
+
_line.end.applyMatrix4( matrixWorld );
|
|
204
|
+
|
|
205
|
+
const pointOnLine = new Vector3();
|
|
206
|
+
const point = new Vector3();
|
|
207
|
+
|
|
208
|
+
_ray.distanceSqToSegment( _line.start, _line.end, point, pointOnLine );
|
|
209
|
+
|
|
210
|
+
intersects.push( {
|
|
211
|
+
point: point,
|
|
212
|
+
pointOnLine: pointOnLine,
|
|
213
|
+
distance: _ray.origin.distanceTo( point ),
|
|
214
|
+
object: lineSegments,
|
|
215
|
+
face: null,
|
|
216
|
+
faceIndex: i,
|
|
217
|
+
uv: null,
|
|
218
|
+
uv1: null,
|
|
219
|
+
} );
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* A series of lines drawn between pairs of vertices.
|
|
229
|
+
*
|
|
230
|
+
* This adds functionality beyond {@link LineSegments}, like arbitrary line width and changing width
|
|
231
|
+
* to be in world units. {@link Line2} extends this object, forming a polyline instead of individual
|
|
232
|
+
* segments.
|
|
233
|
+
*
|
|
234
|
+
* This module can only be used with {@link WebGLRenderer}. When using {@link WebGPURenderer},
|
|
235
|
+
* import the class from `lines/webgpu/LineSegments2.js`.
|
|
236
|
+
*
|
|
237
|
+
* ```js
|
|
238
|
+
* const geometry = new LineSegmentsGeometry();
|
|
239
|
+
* geometry.setPositions( positions );
|
|
240
|
+
* geometry.setColors( colors );
|
|
241
|
+
*
|
|
242
|
+
* const material = new LineMaterial( { linewidth: 5, vertexColors: true } };
|
|
243
|
+
*
|
|
244
|
+
* const lineSegments = new LineSegments2( geometry, material );
|
|
245
|
+
* scene.add( lineSegments );
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
248
|
+
* @augments Mesh
|
|
249
|
+
* @three_import import { LineSegments2 } from 'three/addons/lines/LineSegments2.js';
|
|
250
|
+
*/
|
|
251
|
+
class LineSegments2 extends Mesh {
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Constructs a new wide line.
|
|
255
|
+
*
|
|
256
|
+
* @param {LineSegmentsGeometry} [geometry] - The line geometry.
|
|
257
|
+
* @param {LineMaterial} [material] - The line material.
|
|
258
|
+
*/
|
|
259
|
+
constructor( geometry = new LineSegmentsGeometry(), material = new LineMaterial( { color: Math.random() * 0xffffff } ) ) {
|
|
260
|
+
|
|
261
|
+
super( geometry, material );
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* This flag can be used for type testing.
|
|
265
|
+
*
|
|
266
|
+
* @type {boolean}
|
|
267
|
+
* @readonly
|
|
268
|
+
* @default true
|
|
269
|
+
*/
|
|
270
|
+
this.isLineSegments2 = true;
|
|
271
|
+
|
|
272
|
+
this.type = 'LineSegments2';
|
|
273
|
+
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Computes an array of distance values which are necessary for rendering dashed lines.
|
|
278
|
+
* For each vertex in the geometry, the method calculates the cumulative length from the
|
|
279
|
+
* current point to the very beginning of the line.
|
|
280
|
+
*
|
|
281
|
+
* @return {LineSegments2} A reference to this instance.
|
|
282
|
+
*/
|
|
283
|
+
computeLineDistances() {
|
|
284
|
+
|
|
285
|
+
// for backwards-compatibility, but could be a method of LineSegmentsGeometry...
|
|
286
|
+
|
|
287
|
+
const geometry = this.geometry;
|
|
288
|
+
|
|
289
|
+
const instanceStart = geometry.attributes.instanceStart;
|
|
290
|
+
const instanceEnd = geometry.attributes.instanceEnd;
|
|
291
|
+
const lineDistances = new Float32Array( 2 * instanceStart.count );
|
|
292
|
+
|
|
293
|
+
for ( let i = 0, j = 0, l = instanceStart.count; i < l; i ++, j += 2 ) {
|
|
294
|
+
|
|
295
|
+
_start.fromBufferAttribute( instanceStart, i );
|
|
296
|
+
_end.fromBufferAttribute( instanceEnd, i );
|
|
297
|
+
|
|
298
|
+
lineDistances[ j ] = ( j === 0 ) ? 0 : lineDistances[ j - 1 ];
|
|
299
|
+
lineDistances[ j + 1 ] = lineDistances[ j ] + _start.distanceTo( _end );
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const instanceDistanceBuffer = new InstancedInterleavedBuffer( lineDistances, 2, 1 ); // d0, d1
|
|
304
|
+
|
|
305
|
+
geometry.setAttribute( 'instanceDistanceStart', new InterleavedBufferAttribute( instanceDistanceBuffer, 1, 0 ) ); // d0
|
|
306
|
+
geometry.setAttribute( 'instanceDistanceEnd', new InterleavedBufferAttribute( instanceDistanceBuffer, 1, 1 ) ); // d1
|
|
307
|
+
|
|
308
|
+
return this;
|
|
309
|
+
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Computes intersection points between a casted ray and this instance.
|
|
314
|
+
*
|
|
315
|
+
* @param {Raycaster} raycaster - The raycaster.
|
|
316
|
+
* @param {Array<Object>} intersects - The target array that holds the intersection points.
|
|
317
|
+
*/
|
|
318
|
+
raycast( raycaster, intersects ) {
|
|
319
|
+
|
|
320
|
+
const worldUnits = this.material.worldUnits;
|
|
321
|
+
const camera = raycaster.camera;
|
|
322
|
+
|
|
323
|
+
if ( camera === null && ! worldUnits ) {
|
|
324
|
+
|
|
325
|
+
console.error( 'LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.' );
|
|
326
|
+
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// early out if no resolution has been set (line was not rendered yet)
|
|
330
|
+
|
|
331
|
+
if ( worldUnits === false && ( this.material.resolution.x === 0 || this.material.resolution.y === 0 ) ) {
|
|
332
|
+
|
|
333
|
+
return;
|
|
334
|
+
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const threshold = ( raycaster.params.Line2 !== undefined ) ? raycaster.params.Line2.threshold || 0 : 0;
|
|
338
|
+
|
|
339
|
+
_ray = raycaster.ray;
|
|
340
|
+
|
|
341
|
+
const matrixWorld = this.matrixWorld;
|
|
342
|
+
const geometry = this.geometry;
|
|
343
|
+
const material = this.material;
|
|
344
|
+
|
|
345
|
+
_lineWidth = material.linewidth + threshold;
|
|
346
|
+
|
|
347
|
+
// check if we intersect the sphere bounds
|
|
348
|
+
if ( geometry.boundingSphere === null ) {
|
|
349
|
+
|
|
350
|
+
geometry.computeBoundingSphere();
|
|
351
|
+
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
_sphere.copy( geometry.boundingSphere ).applyMatrix4( matrixWorld );
|
|
355
|
+
|
|
356
|
+
// increase the sphere bounds by the worst case line screen space width
|
|
357
|
+
let sphereMargin;
|
|
358
|
+
if ( worldUnits ) {
|
|
359
|
+
|
|
360
|
+
sphereMargin = _lineWidth * 0.5;
|
|
361
|
+
|
|
362
|
+
} else {
|
|
363
|
+
|
|
364
|
+
const distanceToSphere = Math.max( camera.near, _sphere.distanceToPoint( _ray.origin ) );
|
|
365
|
+
sphereMargin = getWorldSpaceHalfWidth( camera, distanceToSphere, material.resolution );
|
|
366
|
+
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
_sphere.radius += sphereMargin;
|
|
370
|
+
|
|
371
|
+
if ( _ray.intersectsSphere( _sphere ) === false ) {
|
|
372
|
+
|
|
373
|
+
return;
|
|
374
|
+
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// check if we intersect the box bounds
|
|
378
|
+
if ( geometry.boundingBox === null ) {
|
|
379
|
+
|
|
380
|
+
geometry.computeBoundingBox();
|
|
381
|
+
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
_box.copy( geometry.boundingBox ).applyMatrix4( matrixWorld );
|
|
385
|
+
|
|
386
|
+
// increase the box bounds by the worst case line width
|
|
387
|
+
let boxMargin;
|
|
388
|
+
if ( worldUnits ) {
|
|
389
|
+
|
|
390
|
+
boxMargin = _lineWidth * 0.5;
|
|
391
|
+
|
|
392
|
+
} else {
|
|
393
|
+
|
|
394
|
+
const distanceToBox = Math.max( camera.near, _box.distanceToPoint( _ray.origin ) );
|
|
395
|
+
boxMargin = getWorldSpaceHalfWidth( camera, distanceToBox, material.resolution );
|
|
396
|
+
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
_box.expandByScalar( boxMargin );
|
|
400
|
+
|
|
401
|
+
if ( _ray.intersectsBox( _box ) === false ) {
|
|
402
|
+
|
|
403
|
+
return;
|
|
404
|
+
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if ( worldUnits ) {
|
|
408
|
+
|
|
409
|
+
raycastWorldUnits( this, intersects );
|
|
410
|
+
|
|
411
|
+
} else {
|
|
412
|
+
|
|
413
|
+
raycastScreenSpace( this, camera, intersects );
|
|
414
|
+
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
onBeforeRender( renderer ) {
|
|
420
|
+
|
|
421
|
+
const uniforms = this.material.uniforms;
|
|
422
|
+
|
|
423
|
+
if ( uniforms && uniforms.resolution ) {
|
|
424
|
+
|
|
425
|
+
renderer.getViewport( _viewport );
|
|
426
|
+
this.material.uniforms.resolution.value.set( _viewport.z, _viewport.w );
|
|
427
|
+
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export { LineSegments2 };
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box3,
|
|
3
|
+
Float32BufferAttribute,
|
|
4
|
+
InstancedBufferGeometry,
|
|
5
|
+
InstancedInterleavedBuffer,
|
|
6
|
+
InterleavedBufferAttribute,
|
|
7
|
+
Sphere,
|
|
8
|
+
Vector3,
|
|
9
|
+
WireframeGeometry
|
|
10
|
+
} from 'three';
|
|
11
|
+
|
|
12
|
+
const _box = new Box3();
|
|
13
|
+
const _vector = new Vector3();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A series of vertex pairs, forming line segments.
|
|
17
|
+
*
|
|
18
|
+
* This is used in {@link LineSegments2} to describe the shape.
|
|
19
|
+
*
|
|
20
|
+
* @augments InstancedBufferGeometry
|
|
21
|
+
* @three_import import { LineSegmentsGeometry } from 'three/addons/lines/LineSegmentsGeometry.js';
|
|
22
|
+
*/
|
|
23
|
+
class LineSegmentsGeometry extends InstancedBufferGeometry {
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Constructs a new line segments geometry.
|
|
27
|
+
*/
|
|
28
|
+
constructor() {
|
|
29
|
+
|
|
30
|
+
super();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* This flag can be used for type testing.
|
|
34
|
+
*
|
|
35
|
+
* @type {boolean}
|
|
36
|
+
* @readonly
|
|
37
|
+
* @default true
|
|
38
|
+
*/
|
|
39
|
+
this.isLineSegmentsGeometry = true;
|
|
40
|
+
|
|
41
|
+
this.type = 'LineSegmentsGeometry';
|
|
42
|
+
|
|
43
|
+
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 ];
|
|
44
|
+
const uvs = [ - 1, 2, 1, 2, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 2, 1, - 2 ];
|
|
45
|
+
const index = [ 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5 ];
|
|
46
|
+
|
|
47
|
+
this.setIndex( index );
|
|
48
|
+
this.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
|
|
49
|
+
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Applies the given 4x4 transformation matrix to the geometry.
|
|
55
|
+
*
|
|
56
|
+
* @param {Matrix4} matrix - The matrix to apply.
|
|
57
|
+
* @return {LineSegmentsGeometry} A reference to this instance.
|
|
58
|
+
*/
|
|
59
|
+
applyMatrix4( matrix ) {
|
|
60
|
+
|
|
61
|
+
const start = this.attributes.instanceStart;
|
|
62
|
+
const end = this.attributes.instanceEnd;
|
|
63
|
+
|
|
64
|
+
if ( start !== undefined ) {
|
|
65
|
+
|
|
66
|
+
start.applyMatrix4( matrix );
|
|
67
|
+
|
|
68
|
+
end.applyMatrix4( matrix );
|
|
69
|
+
|
|
70
|
+
start.needsUpdate = true;
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if ( this.boundingBox !== null ) {
|
|
75
|
+
|
|
76
|
+
this.computeBoundingBox();
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if ( this.boundingSphere !== null ) {
|
|
81
|
+
|
|
82
|
+
this.computeBoundingSphere();
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return this;
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Sets the given line positions for this geometry. The length must be a multiple of six since
|
|
92
|
+
* each line segment is defined by a start end vertex in the pattern `(xyz xyz)`.
|
|
93
|
+
*
|
|
94
|
+
* @param {Float32Array|Array<number>} array - The position data to set.
|
|
95
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
96
|
+
*/
|
|
97
|
+
setPositions( array ) {
|
|
98
|
+
|
|
99
|
+
let lineSegments;
|
|
100
|
+
|
|
101
|
+
if ( array instanceof Float32Array ) {
|
|
102
|
+
|
|
103
|
+
lineSegments = array;
|
|
104
|
+
|
|
105
|
+
} else if ( Array.isArray( array ) ) {
|
|
106
|
+
|
|
107
|
+
lineSegments = new Float32Array( array );
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const instanceBuffer = new InstancedInterleavedBuffer( lineSegments, 6, 1 ); // xyz, xyz
|
|
112
|
+
|
|
113
|
+
this.setAttribute( 'instanceStart', new InterleavedBufferAttribute( instanceBuffer, 3, 0 ) ); // xyz
|
|
114
|
+
this.setAttribute( 'instanceEnd', new InterleavedBufferAttribute( instanceBuffer, 3, 3 ) ); // xyz
|
|
115
|
+
|
|
116
|
+
this.instanceCount = this.attributes.instanceStart.count;
|
|
117
|
+
|
|
118
|
+
//
|
|
119
|
+
|
|
120
|
+
this.computeBoundingBox();
|
|
121
|
+
this.computeBoundingSphere();
|
|
122
|
+
|
|
123
|
+
return this;
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Sets the given line colors for this geometry. The length must be a multiple of six since
|
|
129
|
+
* each line segment is defined by a start end color in the pattern `(rgb rgb)`.
|
|
130
|
+
*
|
|
131
|
+
* @param {Float32Array|Array<number>} array - The position data to set.
|
|
132
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
133
|
+
*/
|
|
134
|
+
setColors( array ) {
|
|
135
|
+
|
|
136
|
+
let colors;
|
|
137
|
+
|
|
138
|
+
if ( array instanceof Float32Array ) {
|
|
139
|
+
|
|
140
|
+
colors = array;
|
|
141
|
+
|
|
142
|
+
} else if ( Array.isArray( array ) ) {
|
|
143
|
+
|
|
144
|
+
colors = new Float32Array( array );
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const instanceColorBuffer = new InstancedInterleavedBuffer( colors, 6, 1 ); // rgb, rgb
|
|
149
|
+
|
|
150
|
+
this.setAttribute( 'instanceColorStart', new InterleavedBufferAttribute( instanceColorBuffer, 3, 0 ) ); // rgb
|
|
151
|
+
this.setAttribute( 'instanceColorEnd', new InterleavedBufferAttribute( instanceColorBuffer, 3, 3 ) ); // rgb
|
|
152
|
+
|
|
153
|
+
return this;
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Setups this line segments geometry from the given wireframe geometry.
|
|
159
|
+
*
|
|
160
|
+
* @param {WireframeGeometry} geometry - The geometry that should be used as a data source for this geometry.
|
|
161
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
162
|
+
*/
|
|
163
|
+
fromWireframeGeometry( geometry ) {
|
|
164
|
+
|
|
165
|
+
this.setPositions( geometry.attributes.position.array );
|
|
166
|
+
|
|
167
|
+
return this;
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Setups this line segments geometry from the given edges geometry.
|
|
173
|
+
*
|
|
174
|
+
* @param {EdgesGeometry} geometry - The geometry that should be used as a data source for this geometry.
|
|
175
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
176
|
+
*/
|
|
177
|
+
fromEdgesGeometry( geometry ) {
|
|
178
|
+
|
|
179
|
+
this.setPositions( geometry.attributes.position.array );
|
|
180
|
+
|
|
181
|
+
return this;
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Setups this line segments geometry from the given mesh.
|
|
187
|
+
*
|
|
188
|
+
* @param {Mesh} mesh - The mesh geometry that should be used as a data source for this geometry.
|
|
189
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
190
|
+
*/
|
|
191
|
+
fromMesh( mesh ) {
|
|
192
|
+
|
|
193
|
+
this.fromWireframeGeometry( new WireframeGeometry( mesh.geometry ) );
|
|
194
|
+
|
|
195
|
+
// set colors, maybe
|
|
196
|
+
|
|
197
|
+
return this;
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Setups this line segments geometry from the given line segments.
|
|
203
|
+
*
|
|
204
|
+
* @param {LineSegments} lineSegments - The line segments that should be used as a data source for this geometry.
|
|
205
|
+
* Assumes the source geometry is not using indices.
|
|
206
|
+
* @return {LineSegmentsGeometry} A reference to this geometry.
|
|
207
|
+
*/
|
|
208
|
+
fromLineSegments( lineSegments ) {
|
|
209
|
+
|
|
210
|
+
const geometry = lineSegments.geometry;
|
|
211
|
+
|
|
212
|
+
this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
|
|
213
|
+
|
|
214
|
+
// set colors, maybe
|
|
215
|
+
|
|
216
|
+
return this;
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
computeBoundingBox() {
|
|
221
|
+
|
|
222
|
+
if ( this.boundingBox === null ) {
|
|
223
|
+
|
|
224
|
+
this.boundingBox = new Box3();
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const start = this.attributes.instanceStart;
|
|
229
|
+
const end = this.attributes.instanceEnd;
|
|
230
|
+
|
|
231
|
+
if ( start !== undefined && end !== undefined ) {
|
|
232
|
+
|
|
233
|
+
this.boundingBox.setFromBufferAttribute( start );
|
|
234
|
+
|
|
235
|
+
_box.setFromBufferAttribute( end );
|
|
236
|
+
|
|
237
|
+
this.boundingBox.union( _box );
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
computeBoundingSphere() {
|
|
244
|
+
|
|
245
|
+
if ( this.boundingSphere === null ) {
|
|
246
|
+
|
|
247
|
+
this.boundingSphere = new Sphere();
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if ( this.boundingBox === null ) {
|
|
252
|
+
|
|
253
|
+
this.computeBoundingBox();
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const start = this.attributes.instanceStart;
|
|
258
|
+
const end = this.attributes.instanceEnd;
|
|
259
|
+
|
|
260
|
+
if ( start !== undefined && end !== undefined ) {
|
|
261
|
+
|
|
262
|
+
const center = this.boundingSphere.center;
|
|
263
|
+
|
|
264
|
+
this.boundingBox.getCenter( center );
|
|
265
|
+
|
|
266
|
+
let maxRadiusSq = 0;
|
|
267
|
+
|
|
268
|
+
for ( let i = 0, il = start.count; i < il; i ++ ) {
|
|
269
|
+
|
|
270
|
+
_vector.fromBufferAttribute( start, i );
|
|
271
|
+
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
|
|
272
|
+
|
|
273
|
+
_vector.fromBufferAttribute( end, i );
|
|
274
|
+
maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
|
|
279
|
+
|
|
280
|
+
if ( isNaN( this.boundingSphere.radius ) ) {
|
|
281
|
+
|
|
282
|
+
console.error( 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.', this );
|
|
283
|
+
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
toJSON() {
|
|
291
|
+
|
|
292
|
+
// todo
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export { LineSegmentsGeometry };
|