zincjs 3.0.0 → 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 +4 -1
  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
@@ -2,14 +2,13 @@ import {
2
2
  BufferGeometry,
3
3
  Float32BufferAttribute,
4
4
  LineBasicMaterial,
5
- Matrix4,
5
+ Matrix4,
6
6
  Object3D,
7
7
  Ray,
8
- Sphere,
9
- Vector3
8
+ Sphere,
9
+ Vector3,
10
10
  } from 'three/webgpu';
11
11
 
12
-
13
12
  const _start = /*@__PURE__*/ new Vector3();
14
13
  const _end = /*@__PURE__*/ new Vector3();
15
14
  const _inverseMatrix = /*@__PURE__*/ new Matrix4();
@@ -21,273 +20,224 @@ const _tempA = /*@__PURE__*/ new Vector3();
21
20
  const _tempB = /*@__PURE__*/ new Vector3();
22
21
 
23
22
  class Line extends Object3D {
23
+ constructor(geometry = new BufferGeometry(), material = new LineBasicMaterial()) {
24
+ super();
24
25
 
25
- constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
26
-
27
- super();
28
-
29
- this.type = 'Line';
30
-
31
- this.geometry = geometry;
32
- this.material = material;
33
-
34
- this.updateMorphTargets();
35
-
36
- }
37
-
38
- copy( source ) {
39
-
40
- super.copy( source );
41
-
42
- this.material = source.material;
43
- this.geometry = source.geometry;
44
-
45
- return this;
46
-
47
- }
48
-
49
- computeLineDistances() {
50
-
51
- const geometry = this.geometry;
52
-
53
- if ( geometry.isBufferGeometry ) {
54
-
55
- // we assume non-indexed geometry
56
-
57
- if ( geometry.index === null ) {
58
-
59
- const positionAttribute = geometry.attributes.position;
60
- const lineDistances = [ 0 ];
61
-
62
- for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
26
+ this.type = 'Line';
63
27
 
64
- _start.fromBufferAttribute( positionAttribute, i - 1 );
65
- _end.fromBufferAttribute( positionAttribute, i );
28
+ this.geometry = geometry;
29
+ this.material = material;
66
30
 
67
- lineDistances[ i ] = lineDistances[ i - 1 ];
68
- lineDistances[ i ] += _start.distanceTo( _end );
69
-
70
- }
71
-
72
- geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
73
-
74
- } else {
75
-
76
- console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
77
-
78
- }
79
-
80
- } else if ( geometry.isGeometry ) {
31
+ this.updateMorphTargets();
32
+ }
81
33
 
82
- console.error( 'THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
34
+ copy(source) {
35
+ super.copy(source);
83
36
 
84
- }
37
+ this.material = source.material;
38
+ this.geometry = source.geometry;
85
39
 
86
- return this;
40
+ return this;
41
+ }
87
42
 
88
- }
43
+ computeLineDistances() {
44
+ const geometry = this.geometry;
45
+
46
+ if (geometry.isBufferGeometry) {
47
+ // we assume non-indexed geometry
48
+
49
+ if (geometry.index === null) {
50
+ const positionAttribute = geometry.attributes.position;
51
+ const lineDistances = [0];
52
+
53
+ for (let i = 1, l = positionAttribute.count; i < l; i++) {
54
+ _start.fromBufferAttribute(positionAttribute, i - 1);
55
+ _end.fromBufferAttribute(positionAttribute, i);
56
+
57
+ lineDistances[i] = lineDistances[i - 1];
58
+ lineDistances[i] += _start.distanceTo(_end);
59
+ }
60
+
61
+ geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
62
+ } else {
63
+ console.warn(
64
+ 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.',
65
+ );
66
+ }
67
+ } else if (geometry.isGeometry) {
68
+ console.error(
69
+ 'THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.',
70
+ );
71
+ }
89
72
 
90
- raycast( raycaster, intersects ) {
73
+ return this;
74
+ }
91
75
 
92
- const geometry = this.geometry;
93
- const matrixWorld = this.matrixWorld;
94
- const threshold = raycaster.params.Line.threshold;
76
+ raycast(raycaster, intersects) {
77
+ const geometry = this.geometry;
78
+ const matrixWorld = this.matrixWorld;
79
+ const threshold = raycaster.params.Line.threshold;
95
80
  const drawRange = geometry.drawRange;
96
81
  const morphPosition = geometry.morphAttributes.position;
97
82
 
98
- // Checking boundingSphere distance to ray
99
-
100
- if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
101
-
102
- _sphere.copy( geometry.boundingSphere );
103
- _sphere.applyMatrix4( matrixWorld );
104
- _sphere.radius += threshold;
105
-
106
- if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
107
-
108
- //
109
-
110
- _inverseMatrix.copy( matrixWorld ).invert();
111
- _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
112
-
113
- const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
114
- const localThresholdSq = localThreshold * localThreshold;
115
-
116
- const vStart = new Vector3();
117
- const vEnd = new Vector3();
118
- const interSegment = new Vector3();
119
- const interRay = new Vector3();
120
- const step = this.isLineSegments ? 2 : 1;
121
-
122
- if ( geometry.isBufferGeometry ) {
83
+ // Checking boundingSphere distance to ray
123
84
 
124
- const index = geometry.index;
125
- const attributes = geometry.attributes;
126
- const positionAttribute = attributes.position;
85
+ if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
127
86
 
128
- if ( index !== null ) {
87
+ _sphere.copy(geometry.boundingSphere);
88
+ _sphere.applyMatrix4(matrixWorld);
89
+ _sphere.radius += threshold;
129
90
 
130
- const start = Math.max( 0, drawRange.start );
131
- const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
91
+ if (raycaster.ray.intersectsSphere(_sphere) === false) return;
132
92
 
133
- for ( let i = start, l = end - 1; i < l; i += step ) {
93
+ //
134
94
 
135
- const a = index.getX( i );
136
- const b = index.getX( i + 1 );
95
+ _inverseMatrix.copy(matrixWorld).invert();
96
+ _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix);
137
97
 
138
- calculatePosition( vStart, vEnd, this, positionAttribute, morphPosition, a, b );
98
+ const localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
99
+ const localThresholdSq = localThreshold * localThreshold;
139
100
 
140
- const distSq = _ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
101
+ const vStart = new Vector3();
102
+ const vEnd = new Vector3();
103
+ const interSegment = new Vector3();
104
+ const interRay = new Vector3();
105
+ const step = this.isLineSegments ? 2 : 1;
141
106
 
142
- if ( distSq > localThresholdSq ) continue;
107
+ if (geometry.isBufferGeometry) {
108
+ const index = geometry.index;
109
+ const attributes = geometry.attributes;
110
+ const positionAttribute = attributes.position;
143
111
 
144
- interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
112
+ if (index !== null) {
113
+ const start = Math.max(0, drawRange.start);
114
+ const end = Math.min(index.count, drawRange.start + drawRange.count);
145
115
 
146
- const distance = raycaster.ray.origin.distanceTo( interRay );
116
+ for (let i = start, l = end - 1; i < l; i += step) {
117
+ const a = index.getX(i);
118
+ const b = index.getX(i + 1);
147
119
 
148
- if ( distance < raycaster.near || distance > raycaster.far ) continue;
120
+ calculatePosition(vStart, vEnd, this, positionAttribute, morphPosition, a, b);
149
121
 
150
- intersects.push( {
122
+ const distSq = _ray.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
151
123
 
152
- distance: distance,
153
- // What do we want? intersection point on the ray or on the segment??
154
- // point: raycaster.ray.at( distance ),
155
- point: interSegment.clone().applyMatrix4( this.matrixWorld ),
156
- index: i,
157
- face: null,
158
- faceIndex: null,
159
- object: this
124
+ if (distSq > localThresholdSq) continue;
160
125
 
161
- } );
126
+ interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
162
127
 
163
- }
128
+ const distance = raycaster.ray.origin.distanceTo(interRay);
164
129
 
165
- } else {
130
+ if (distance < raycaster.near || distance > raycaster.far) continue;
166
131
 
167
- const start = Math.max( 0, drawRange.start );
168
- const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
132
+ intersects.push({
133
+ distance: distance,
134
+ // What do we want? intersection point on the ray or on the segment??
135
+ // point: raycaster.ray.at( distance ),
136
+ point: interSegment.clone().applyMatrix4(this.matrixWorld),
137
+ index: i,
138
+ face: null,
139
+ faceIndex: null,
140
+ object: this,
141
+ });
142
+ }
143
+ } else {
144
+ const start = Math.max(0, drawRange.start);
145
+ const end = Math.min(positionAttribute.count, drawRange.start + drawRange.count);
169
146
 
170
- for ( let i = start, l = end - 1; i < l; i += step ) {
147
+ for (let i = start, l = end - 1; i < l; i += step) {
148
+ calculatePosition(vStart, vEnd, this, positionAttribute, morphPosition, i, i + 1);
171
149
 
172
- calculatePosition( vStart, vEnd, this, positionAttribute, morphPosition, i, i+1 );
150
+ const distSq = _ray.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
173
151
 
174
- const distSq = _ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
152
+ if (distSq > localThresholdSq) continue;
175
153
 
176
- if ( distSq > localThresholdSq ) continue;
154
+ interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
177
155
 
178
- interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
156
+ const distance = raycaster.ray.origin.distanceTo(interRay);
179
157
 
180
- const distance = raycaster.ray.origin.distanceTo( interRay );
158
+ if (distance < raycaster.near || distance > raycaster.far) continue;
181
159
 
182
- if ( distance < raycaster.near || distance > raycaster.far ) continue;
183
-
184
- intersects.push( {
185
-
186
- distance: distance,
187
- // What do we want? intersection point on the ray or on the segment??
188
- // point: raycaster.ray.at( distance ),
189
- point: interSegment.clone().applyMatrix4( this.matrixWorld ),
190
- index: i,
191
- face: null,
192
- faceIndex: null,
193
- object: this
194
-
195
- } );
196
-
197
- }
198
-
199
- }
200
-
201
- } else if ( geometry.isGeometry ) {
202
-
203
- console.error( 'THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
204
-
205
- }
206
-
207
- }
208
-
209
- updateMorphTargets() {
210
-
211
- const geometry = this.geometry;
212
-
213
- if ( geometry.isBufferGeometry ) {
214
-
215
- const morphAttributes = geometry.morphAttributes;
216
- const keys = Object.keys( morphAttributes );
217
-
218
- if ( keys.length > 0 ) {
219
-
220
- const morphAttribute = morphAttributes[ keys[ 0 ] ];
221
-
222
- if ( morphAttribute !== undefined ) {
223
-
224
- this.morphTargetInfluences = [];
225
- this.morphTargetDictionary = {};
226
-
227
- for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
228
-
229
- const name = morphAttribute[ m ].name || String( m );
230
-
231
- this.morphTargetInfluences.push( 0 );
232
- this.morphTargetDictionary[ name ] = m;
233
-
234
- }
235
-
236
- }
237
-
238
- }
239
-
240
- } else {
160
+ intersects.push({
161
+ distance: distance,
162
+ // What do we want? intersection point on the ray or on the segment??
163
+ // point: raycaster.ray.at( distance ),
164
+ point: interSegment.clone().applyMatrix4(this.matrixWorld),
165
+ index: i,
166
+ face: null,
167
+ faceIndex: null,
168
+ object: this,
169
+ });
170
+ }
171
+ }
172
+ } else if (geometry.isGeometry) {
173
+ console.error(
174
+ 'THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.',
175
+ );
176
+ }
177
+ }
241
178
 
242
- const morphTargets = geometry.morphTargets;
179
+ updateMorphTargets() {
180
+ const geometry = this.geometry;
243
181
 
244
- if ( morphTargets !== undefined && morphTargets.length > 0 ) {
182
+ if (geometry.isBufferGeometry) {
183
+ const morphAttributes = geometry.morphAttributes;
184
+ const keys = Object.keys(morphAttributes);
245
185
 
246
- console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
186
+ if (keys.length > 0) {
187
+ const morphAttribute = morphAttributes[keys[0]];
247
188
 
248
- }
189
+ if (morphAttribute !== undefined) {
190
+ this.morphTargetInfluences = [];
191
+ this.morphTargetDictionary = {};
249
192
 
250
- }
193
+ for (let m = 0, ml = morphAttribute.length; m < ml; m++) {
194
+ const name = morphAttribute[m].name || String(m);
251
195
 
252
- }
196
+ this.morphTargetInfluences.push(0);
197
+ this.morphTargetDictionary[name] = m;
198
+ }
199
+ }
200
+ }
201
+ } else {
202
+ const morphTargets = geometry.morphTargets;
253
203
 
204
+ if (morphTargets !== undefined && morphTargets.length > 0) {
205
+ console.error(
206
+ 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.',
207
+ );
208
+ }
209
+ }
210
+ }
254
211
  }
255
212
 
256
- function calculatePosition( vStart, vEnd, object, position, morphPosition, a, b ) {
257
-
258
- vStart.fromBufferAttribute( position, a );
259
- vEnd.fromBufferAttribute( position, b );
213
+ function calculatePosition(vStart, vEnd, object, position, morphPosition, a, b) {
214
+ vStart.fromBufferAttribute(position, a);
215
+ vEnd.fromBufferAttribute(position, b);
260
216
 
261
217
  var morphInfluences = object.morphTargetInfluences;
262
218
 
263
- if ( morphPosition && morphInfluences ) {
264
-
265
- _morphA.set( 0, 0, 0 );
266
- _morphB.set( 0, 0, 0 );
267
-
268
- for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
219
+ if (morphPosition && morphInfluences) {
220
+ _morphA.set(0, 0, 0);
221
+ _morphB.set(0, 0, 0);
269
222
 
270
- var influence = morphInfluences[ i ];
271
- var morphAttribute = morphPosition[ i ];
223
+ for (var i = 0, il = morphPosition.length; i < il; i++) {
224
+ var influence = morphInfluences[i];
225
+ var morphAttribute = morphPosition[i];
272
226
 
273
- if ( influence === 0 ) continue;
227
+ if (influence === 0) continue;
274
228
 
275
- _tempA.fromBufferAttribute( morphAttribute, a );
276
- _tempB.fromBufferAttribute( morphAttribute, b );
277
-
278
- _morphA.addScaledVector( _tempA.sub( vStart ), influence );
279
- _morphB.addScaledVector( _tempB.sub( vEnd ), influence );
229
+ _tempA.fromBufferAttribute(morphAttribute, a);
230
+ _tempB.fromBufferAttribute(morphAttribute, b);
280
231
 
232
+ _morphA.addScaledVector(_tempA.sub(vStart), influence);
233
+ _morphB.addScaledVector(_tempB.sub(vEnd), influence);
281
234
  }
282
235
 
283
- vStart.add( _morphA );
284
- vEnd.add( _morphB );
285
-
236
+ vStart.add(_morphA);
237
+ vEnd.add(_morphB);
286
238
  }
287
-
288
239
  }
289
240
 
290
241
  Line.prototype.isLine = true;
291
242
 
292
-
293
- export { Line };
243
+ export { Line };
@@ -1,65 +1,50 @@
1
1
  import { Line } from './Line.js';
2
- import {
3
- Float32BufferAttribute,
4
- Vector3
5
- } from 'three/webgpu';
2
+ import { Float32BufferAttribute, Vector3 } from 'three/webgpu';
6
3
 
7
4
  const _start = /*@__PURE__*/ new Vector3();
8
5
  const _end = /*@__PURE__*/ new Vector3();
9
6
 
10
7
  class LineSegments extends Line {
11
-
12
- constructor( geometry, material ) {
13
-
14
- super( geometry, material );
15
-
16
- this.type = 'LineSegments';
17
-
18
- }
19
-
20
- computeLineDistances() {
21
-
22
- const geometry = this.geometry;
23
-
24
- if ( geometry.isBufferGeometry ) {
25
-
26
- // we assume non-indexed geometry
27
-
28
- if ( geometry.index === null ) {
29
-
30
- const positionAttribute = geometry.attributes.position;
31
- const lineDistances = [];
32
-
33
- for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
34
-
35
- _start.fromBufferAttribute( positionAttribute, i );
36
- _end.fromBufferAttribute( positionAttribute, i + 1 );
37
-
38
- lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
39
- lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );
40
-
41
- }
42
-
43
- geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
44
-
45
- } else {
46
-
47
- console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
48
-
49
- }
50
-
51
- } else if ( geometry.isGeometry ) {
52
-
53
- console.error( 'THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
54
-
55
- }
56
-
57
- return this;
58
-
59
- }
60
-
8
+ constructor(geometry, material) {
9
+ super(geometry, material);
10
+
11
+ this.type = 'LineSegments';
12
+ }
13
+
14
+ computeLineDistances() {
15
+ const geometry = this.geometry;
16
+
17
+ if (geometry.isBufferGeometry) {
18
+ // we assume non-indexed geometry
19
+
20
+ if (geometry.index === null) {
21
+ const positionAttribute = geometry.attributes.position;
22
+ const lineDistances = [];
23
+
24
+ for (let i = 0, l = positionAttribute.count; i < l; i += 2) {
25
+ _start.fromBufferAttribute(positionAttribute, i);
26
+ _end.fromBufferAttribute(positionAttribute, i + 1);
27
+
28
+ lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
29
+ lineDistances[i + 1] = lineDistances[i] + _start.distanceTo(_end);
30
+ }
31
+
32
+ geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
33
+ } else {
34
+ console.warn(
35
+ 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.',
36
+ );
37
+ }
38
+ } else if (geometry.isGeometry) {
39
+ console.error(
40
+ 'THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.',
41
+ );
42
+ }
43
+
44
+ return this;
45
+ }
61
46
  }
62
47
 
63
48
  LineSegments.prototype.isLineSegments = true;
64
49
 
65
- export { LineSegments };
50
+ export { LineSegments };