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.
- package/README.md +27 -22
- package/build/zinc.js +2 -2
- package/build/zinc.js.map +1 -1
- package/package.json +6 -2
- package/src/controls.js +1332 -1241
- package/src/geometryCSG.js +111 -115
- package/src/glyphsetCSG.js +51 -55
- package/src/loaders/GLTFToZincJSLoader.js +31 -33
- package/src/loaders/JSONLoader.js +339 -449
- package/src/loaders/OBJLoader.js +654 -851
- package/src/loaders/STLLoader.js +271 -329
- package/src/loaders/niftiReader.js +90 -59
- package/src/loaders/primitivesLoader.js +55 -52
- package/src/minimap.js +63 -43
- package/src/primitives/geometry.js +40 -44
- package/src/primitives/glyph.js +16 -19
- package/src/primitives/glyphset.js +229 -185
- package/src/primitives/label.js +29 -31
- package/src/primitives/lines.js +20 -20
- package/src/primitives/lines2.js +33 -39
- package/src/primitives/lod.js +43 -43
- package/src/primitives/marker.js +31 -32
- package/src/primitives/markerCluster.js +32 -35
- package/src/primitives/pointset.js +86 -83
- package/src/primitives/texturePrimitive.js +9 -10
- package/src/primitives/textureSlides.js +84 -97
- package/src/primitives/textureVolume.js +46 -49
- package/src/primitives/tubeLines.js +108 -108
- package/src/primitives/zincObject.js +176 -184
- package/src/region.js +145 -155
- package/src/renderRequests.js +3 -3
- package/src/renderer.js +635 -620
- package/src/scene.js +479 -419
- package/src/sceneExporter.js +22 -17
- package/src/sceneLoader.js +542 -296
- package/src/shaders/rgbVolumeRender.js +11 -18
- package/src/shaders/textureArray.js +5 -12
- package/src/shaders/textureSlide.js +10 -17
- package/src/shaders/volumeRender.js +11 -18
- package/src/shaders/volumeRender_old.js +11 -18
- package/src/shaders/volumeTexture.js +7 -14
- package/src/textSprite.js +23 -19
- package/src/texture/texture.js +14 -15
- package/src/texture/textureArray.js +14 -16
- package/src/three/InstancedPoints.js +2 -9
- package/src/three/Loader.js +334 -315
- package/src/three/line/Line.js +165 -215
- package/src/three/line/LineSegments.js +40 -55
- package/src/three/line/LineSegments2.js +322 -366
- package/src/three/line/LineSegmentsGeometry.js +239 -280
- package/src/three-js-csg.js +260 -252
- package/src/tsl/glyphRenderMaterial.js +12 -3
- package/src/tsl/glyphTransform.js +51 -29
- package/src/tsl/textureSlides.js +23 -24
- package/src/utilities.js +309 -371
- package/src/videoHandler.js +76 -83
- package/src/workers/geometryCSG.worker.js +33 -36
- package/src/workers/geometryCSGInternal.js +39 -44
- package/src/zinc.js +4 -7
- package/vite.config.js +7 -7
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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 };
|