zincjs 2.4.1-beta.7 → 3.0.1

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.
Files changed (60) hide show
  1. package/README.md +27 -22
  2. package/build/zinc.js +2 -2
  3. package/build/zinc.js.map +1 -1
  4. package/package.json +6 -2
  5. package/src/controls.js +1332 -1241
  6. package/src/geometryCSG.js +111 -115
  7. package/src/glyphsetCSG.js +51 -55
  8. package/src/loaders/GLTFToZincJSLoader.js +31 -33
  9. package/src/loaders/JSONLoader.js +339 -449
  10. package/src/loaders/OBJLoader.js +654 -851
  11. package/src/loaders/STLLoader.js +271 -329
  12. package/src/loaders/niftiReader.js +90 -59
  13. package/src/loaders/primitivesLoader.js +55 -52
  14. package/src/minimap.js +63 -43
  15. package/src/primitives/geometry.js +40 -44
  16. package/src/primitives/glyph.js +16 -19
  17. package/src/primitives/glyphset.js +229 -185
  18. package/src/primitives/label.js +29 -31
  19. package/src/primitives/lines.js +20 -20
  20. package/src/primitives/lines2.js +33 -39
  21. package/src/primitives/lod.js +43 -43
  22. package/src/primitives/marker.js +31 -32
  23. package/src/primitives/markerCluster.js +32 -35
  24. package/src/primitives/pointset.js +86 -83
  25. package/src/primitives/texturePrimitive.js +9 -10
  26. package/src/primitives/textureSlides.js +84 -97
  27. package/src/primitives/textureVolume.js +46 -49
  28. package/src/primitives/tubeLines.js +108 -108
  29. package/src/primitives/zincObject.js +176 -184
  30. package/src/region.js +145 -155
  31. package/src/renderRequests.js +3 -3
  32. package/src/renderer.js +635 -620
  33. package/src/scene.js +479 -419
  34. package/src/sceneExporter.js +22 -17
  35. package/src/sceneLoader.js +542 -296
  36. package/src/shaders/rgbVolumeRender.js +11 -18
  37. package/src/shaders/textureArray.js +5 -12
  38. package/src/shaders/textureSlide.js +10 -17
  39. package/src/shaders/volumeRender.js +11 -18
  40. package/src/shaders/volumeRender_old.js +11 -18
  41. package/src/shaders/volumeTexture.js +7 -14
  42. package/src/textSprite.js +23 -19
  43. package/src/texture/texture.js +14 -15
  44. package/src/texture/textureArray.js +14 -16
  45. package/src/three/InstancedPoints.js +2 -9
  46. package/src/three/Loader.js +334 -315
  47. package/src/three/line/Line.js +165 -215
  48. package/src/three/line/LineSegments.js +40 -55
  49. package/src/three/line/LineSegments2.js +322 -366
  50. package/src/three/line/LineSegmentsGeometry.js +239 -280
  51. package/src/three-js-csg.js +260 -252
  52. package/src/tsl/glyphRenderMaterial.js +12 -3
  53. package/src/tsl/glyphTransform.js +51 -29
  54. package/src/tsl/textureSlides.js +23 -24
  55. package/src/utilities.js +309 -371
  56. package/src/videoHandler.js +76 -83
  57. package/src/workers/geometryCSG.worker.js +33 -36
  58. package/src/workers/geometryCSGInternal.js +39 -44
  59. package/src/zinc.js +4 -7
  60. package/vite.config.js +7 -7
@@ -1,12 +1,12 @@
1
1
  import {
2
- Box3,
3
- Float32BufferAttribute,
4
- InstancedBufferGeometry,
5
- InstancedInterleavedBuffer,
6
- InterleavedBufferAttribute,
7
- Sphere,
8
- Vector3,
9
- WireframeGeometry
2
+ Box3,
3
+ Float32BufferAttribute,
4
+ InstancedBufferGeometry,
5
+ InstancedInterleavedBuffer,
6
+ InterleavedBufferAttribute,
7
+ Sphere,
8
+ Vector3,
9
+ WireframeGeometry,
10
10
  } from 'three/webgpu';
11
11
 
12
12
  const _box = new Box3();
@@ -21,278 +21,237 @@ const _vector = new Vector3();
21
21
  * @three_import import { LineSegmentsGeometry } from 'three/addons/lines/LineSegmentsGeometry.js';
22
22
  */
23
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
-
24
+ /**
25
+ * Constructs a new line segments geometry.
26
+ */
27
+ constructor() {
28
+ super();
29
+
30
+ /**
31
+ * This flag can be used for type testing.
32
+ *
33
+ * @type {boolean}
34
+ * @readonly
35
+ * @default true
36
+ */
37
+ this.isLineSegmentsGeometry = true;
38
+
39
+ this.type = 'LineSegmentsGeometry';
40
+
41
+ const positions = [
42
+ -1, 2, 0, 1, 2, 0, -1, 1, 0, 1, 1, 0, -1, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, 0,
43
+ ];
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
+ * Applies the given 4x4 transformation matrix to the geometry.
54
+ *
55
+ * @param {Matrix4} matrix - The matrix to apply.
56
+ * @return {LineSegmentsGeometry} A reference to this instance.
57
+ */
58
+ applyMatrix4(matrix) {
59
+ const start = this.attributes.instanceStart;
60
+ const end = this.attributes.instanceEnd;
61
+
62
+ if (start !== undefined) {
63
+ start.applyMatrix4(matrix);
64
+
65
+ end.applyMatrix4(matrix);
66
+
67
+ start.needsUpdate = true;
68
+ }
69
+
70
+ if (this.boundingBox !== null) {
71
+ this.computeBoundingBox();
72
+ }
73
+
74
+ if (this.boundingSphere !== null) {
75
+ this.computeBoundingSphere();
76
+ }
77
+
78
+ return this;
79
+ }
80
+
81
+ /**
82
+ * Sets the given line positions for this geometry. The length must be a multiple of six since
83
+ * each line segment is defined by a start end vertex in the pattern `(xyz xyz)`.
84
+ *
85
+ * @param {Float32Array|Array<number>} array - The position data to set.
86
+ * @return {LineSegmentsGeometry} A reference to this geometry.
87
+ */
88
+ setPositions(array) {
89
+ let lineSegments;
90
+
91
+ if (array instanceof Float32Array) {
92
+ lineSegments = array;
93
+ } else if (Array.isArray(array)) {
94
+ lineSegments = new Float32Array(array);
95
+ }
96
+
97
+ const instanceBuffer = new InstancedInterleavedBuffer(lineSegments, 6, 1); // xyz, xyz
98
+
99
+ this.setAttribute('instanceStart', new InterleavedBufferAttribute(instanceBuffer, 3, 0)); // xyz
100
+ this.setAttribute('instanceEnd', new InterleavedBufferAttribute(instanceBuffer, 3, 3)); // xyz
101
+
102
+ this.instanceCount = this.attributes.instanceStart.count;
103
+
104
+ //
105
+
106
+ this.computeBoundingBox();
107
+ this.computeBoundingSphere();
108
+
109
+ return this;
110
+ }
111
+
112
+ /**
113
+ * Sets the given line colors for this geometry. The length must be a multiple of six since
114
+ * each line segment is defined by a start end color in the pattern `(rgb rgb)`.
115
+ *
116
+ * @param {Float32Array|Array<number>} array - The position data to set.
117
+ * @return {LineSegmentsGeometry} A reference to this geometry.
118
+ */
119
+ setColors(array) {
120
+ let colors;
121
+
122
+ if (array instanceof Float32Array) {
123
+ colors = array;
124
+ } else if (Array.isArray(array)) {
125
+ colors = new Float32Array(array);
126
+ }
127
+
128
+ const instanceColorBuffer = new InstancedInterleavedBuffer(colors, 6, 1); // rgb, rgb
129
+
130
+ this.setAttribute(
131
+ 'instanceColorStart',
132
+ new InterleavedBufferAttribute(instanceColorBuffer, 3, 0),
133
+ ); // rgb
134
+ this.setAttribute(
135
+ 'instanceColorEnd',
136
+ new InterleavedBufferAttribute(instanceColorBuffer, 3, 3),
137
+ ); // rgb
138
+
139
+ return this;
140
+ }
141
+
142
+ /**
143
+ * Setups this line segments geometry from the given wireframe geometry.
144
+ *
145
+ * @param {WireframeGeometry} geometry - The geometry that should be used as a data source for this geometry.
146
+ * @return {LineSegmentsGeometry} A reference to this geometry.
147
+ */
148
+ fromWireframeGeometry(geometry) {
149
+ this.setPositions(geometry.attributes.position.array);
150
+
151
+ return this;
152
+ }
153
+
154
+ /**
155
+ * Setups this line segments geometry from the given edges geometry.
156
+ *
157
+ * @param {EdgesGeometry} geometry - The geometry that should be used as a data source for this geometry.
158
+ * @return {LineSegmentsGeometry} A reference to this geometry.
159
+ */
160
+ fromEdgesGeometry(geometry) {
161
+ this.setPositions(geometry.attributes.position.array);
162
+
163
+ return this;
164
+ }
165
+
166
+ /**
167
+ * Setups this line segments geometry from the given mesh.
168
+ *
169
+ * @param {Mesh} mesh - The mesh geometry that should be used as a data source for this geometry.
170
+ * @return {LineSegmentsGeometry} A reference to this geometry.
171
+ */
172
+ fromMesh(mesh) {
173
+ this.fromWireframeGeometry(new WireframeGeometry(mesh.geometry));
174
+
175
+ // set colors, maybe
176
+
177
+ return this;
178
+ }
179
+
180
+ /**
181
+ * Setups this line segments geometry from the given line segments.
182
+ *
183
+ * @param {LineSegments} lineSegments - The line segments that should be used as a data source for this geometry.
184
+ * Assumes the source geometry is not using indices.
185
+ * @return {LineSegmentsGeometry} A reference to this geometry.
186
+ */
187
+ fromLineSegments(lineSegments) {
188
+ const geometry = lineSegments.geometry;
189
+
190
+ this.setPositions(geometry.attributes.position.array); // assumes non-indexed
191
+
192
+ // set colors, maybe
193
+
194
+ return this;
195
+ }
196
+
197
+ computeBoundingBox() {
198
+ if (this.boundingBox === null) {
199
+ this.boundingBox = new Box3();
200
+ }
201
+
202
+ const start = this.attributes.instanceStart;
203
+ const end = this.attributes.instanceEnd;
204
+
205
+ if (start !== undefined && end !== undefined) {
206
+ this.boundingBox.setFromBufferAttribute(start);
207
+
208
+ _box.setFromBufferAttribute(end);
209
+
210
+ this.boundingBox.union(_box);
211
+ }
212
+ }
213
+
214
+ computeBoundingSphere() {
215
+ if (this.boundingSphere === null) {
216
+ this.boundingSphere = new Sphere();
217
+ }
218
+
219
+ if (this.boundingBox === null) {
220
+ this.computeBoundingBox();
221
+ }
222
+
223
+ const start = this.attributes.instanceStart;
224
+ const end = this.attributes.instanceEnd;
225
+
226
+ if (start !== undefined && end !== undefined) {
227
+ const center = this.boundingSphere.center;
228
+
229
+ this.boundingBox.getCenter(center);
230
+
231
+ let maxRadiusSq = 0;
232
+
233
+ for (let i = 0, il = start.count; i < il; i++) {
234
+ _vector.fromBufferAttribute(start, i);
235
+ maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector));
236
+
237
+ _vector.fromBufferAttribute(end, i);
238
+ maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector));
239
+ }
240
+
241
+ this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
242
+
243
+ if (isNaN(this.boundingSphere.radius)) {
244
+ console.error(
245
+ 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.',
246
+ this,
247
+ );
248
+ }
249
+ }
250
+ }
251
+
252
+ toJSON() {
253
+ // todo
254
+ }
296
255
  }
297
256
 
298
257
  export { LineSegmentsGeometry };