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
@@ -4,7 +4,6 @@ import { createWebGPUMaterial } from '../tsl/textureSlides.js';
4
4
  import { TexturePrimitive } from './texturePrimitive';
5
5
  import { updateWorldMatrixFromAncestors } from '../utilities';
6
6
 
7
-
8
7
  const cloneData3DTexture = (sourceTex) => {
9
8
  const image = sourceTex.image;
10
9
  const width = image.width;
@@ -23,7 +22,7 @@ const cloneData3DTexture = (sourceTex) => {
23
22
  targetTex.anisotropy = sourceTex.anisotropy;
24
23
  targetTex.needsUpdate = true;
25
24
  return targetTex;
26
- }
25
+ };
27
26
 
28
27
  /**
29
28
  * Provides a class which create a texture stacks in a block
@@ -73,10 +72,10 @@ const TextureSlides = function (textureIn) {
73
72
  *
74
73
  * @param {SLIDE_SETTINGS} slideSettings - An array to each slide settings.
75
74
  */
76
- this.createSlides = slideSettings => {
75
+ this.createSlides = (slideSettings) => {
77
76
  this.requestRender();
78
- slideSettings.forEach(slide => this.createSlide(slide));
79
- }
77
+ slideSettings.forEach((slide) => this.createSlide(slide));
78
+ };
80
79
 
81
80
  /**
82
81
  * Set the value of the uniforms for a specific mesh in this
@@ -95,20 +94,20 @@ const TextureSlides = function (textureIn) {
95
94
  mesh.position.y = 0;
96
95
  mesh.position.z = 0;
97
96
  switch (settings.direction) {
98
- case "x":
97
+ case 'x':
99
98
  const rotation = -Math.PI / 2;
100
99
  mesh.rotation.y = rotation;
101
100
  uniforms.direction.value = 1;
102
101
  uniforms.slide.value.set(settings.value, 0, 0);
103
102
  mesh.position.x = settings.value;
104
103
  break;
105
- case "y":
104
+ case 'y':
106
105
  mesh.rotation.x = Math.PI / 2;
107
106
  uniforms.direction.value = 2;
108
107
  uniforms.slide.value.set(0, settings.value, 0);
109
108
  mesh.position.y = settings.value;
110
109
  break;
111
- case "z":
110
+ case 'z':
112
111
  uniforms.direction.value = 3;
113
112
  uniforms.slide.value.set(0, 0, settings.value);
114
113
  mesh.position.z = settings.value;
@@ -117,7 +116,7 @@ const TextureSlides = function (textureIn) {
117
116
  break;
118
117
  }
119
118
  this.boundingBoxUpdateRequired = true;
120
- }
119
+ };
121
120
 
122
121
  /**
123
122
  * Modify the mesh based on a setting
@@ -126,12 +125,10 @@ const TextureSlides = function (textureIn) {
126
125
  */
127
126
  this.modifySlideSettings = (settings) => {
128
127
  this.requestRender();
129
- if (settings && settings.id &&
130
- settings.id in idTextureMap &&
131
- idTextureMap[settings.id]) {
128
+ if (settings && settings.id && settings.id in idTextureMap && idTextureMap[settings.id]) {
132
129
  setUniformSlideSettingsOfMesh(idTextureMap[settings.id], settings);
133
130
  }
134
- }
131
+ };
135
132
 
136
133
  /**
137
134
  * Create a slide required for visualisation based on the slide settings.
@@ -141,7 +138,7 @@ const TextureSlides = function (textureIn) {
141
138
  * @return {SLIDE_SETTINGS} - Returned settings, it includes the newly
142
139
  * created mesh's id.
143
140
  */
144
- this.createSlide = settings => {
141
+ this.createSlide = (settings) => {
145
142
  this.requestRender();
146
143
  if (this.texture && this.texture.isTextureArray && this.texture.isReady()) {
147
144
  if (settings && settings.direction && settings.value !== undefined) {
@@ -202,7 +199,7 @@ const TextureSlides = function (textureIn) {
202
199
  return slideSettings;
203
200
  }
204
201
  }
205
- }
202
+ };
206
203
 
207
204
  /**
208
205
  * Return a copy of texture settings used by this object.
@@ -211,7 +208,7 @@ const TextureSlides = function (textureIn) {
211
208
  */
212
209
  this.getTextureSettings = () => {
213
210
  return [...textureSettings];
214
- }
211
+ };
215
212
 
216
213
  /**
217
214
  * Return a copy of texture settings with corresponding id used by this object.
@@ -221,10 +218,10 @@ const TextureSlides = function (textureIn) {
221
218
  this.getTextureSettingsWithId = (id) => {
222
219
  for (let i = 0; i < textureSettings.length; i++) {
223
220
  if (id === textureSettings[i].id) {
224
- return {...textureSettings[i]};
221
+ return { ...textureSettings[i] };
225
222
  }
226
223
  }
227
- }
224
+ };
228
225
 
229
226
  /**
230
227
  * Get the array of slides, return them in an array
@@ -234,54 +231,50 @@ const TextureSlides = function (textureIn) {
234
231
  this.getSlides = () => {
235
232
  if (this.morph) return [...this.morph.children];
236
233
  return [];
237
- }
234
+ };
238
235
 
239
236
  /**
240
237
  * Remove a slide, this will dispose the slide and its material.
241
238
  *
242
239
  * @param {Slide} slide - Slide to be remvoed
243
240
  */
244
- this.removeSlide = slide => {
241
+ this.removeSlide = (slide) => {
245
242
  this.requestRender();
246
243
  if (slide) {
247
244
  this.removeSlideWithId(slide.id);
248
245
  }
249
- }
246
+ };
250
247
 
251
248
  /**
252
- * Remove a slide, this will dispose the slide and its material.
253
- *
254
- * @param {Number} id - id of slide to be remvoed
255
- */
256
- this.removeSlideWithId = id => {
249
+ * Remove a slide, this will dispose the slide and its material.
250
+ *
251
+ * @param {Number} id - id of slide to be remvoed
252
+ */
253
+ this.removeSlideWithId = (id) => {
257
254
  this.requestRender();
258
255
  if (this.morph && id in idTextureMap && idTextureMap[id]) {
259
256
  if (this.morph.getObjectById(id)) {
260
257
  const slide = idTextureMap[id];
261
258
  this.morph.remove(slide);
262
259
  slide.clear();
263
- if (slide.geometry)
264
- slide.geometry.dispose();
265
- if (slide.material)
266
- slide.material.dispose();
260
+ if (slide.geometry) slide.geometry.dispose();
261
+ if (slide.material) slide.material.dispose();
267
262
  this.boundingBoxUpdateRequired = true;
268
263
  }
269
- const index = textureSettings.findIndex(item => item.id === id);
264
+ const index = textureSettings.findIndex((item) => item.id === id);
270
265
  if (index > -1) {
271
266
  textureSettings.splice(index, 1);
272
267
  }
273
268
  }
274
- }
269
+ };
275
270
 
276
271
  /**
277
272
  * Clean up all internal objects.
278
273
  */
279
274
  this.dispose = () => {
280
- this.morph.children.forEach(slide => {
281
- if (slide.geometry)
282
- slide.geometry.dispose();
283
- if (slide.material)
284
- slide.material.dispose();
275
+ this.morph.children.forEach((slide) => {
276
+ if (slide.geometry) slide.geometry.dispose();
277
+ if (slide.material) slide.material.dispose();
285
278
  });
286
279
  if (maskTexture) {
287
280
  maskTexture.dispose();
@@ -290,7 +283,7 @@ const TextureSlides = function (textureIn) {
290
283
  }
291
284
  TexturePrimitive.prototype.dispose.call(this);
292
285
  this.boundingBoxUpdateRequired = true;
293
- }
286
+ };
294
287
 
295
288
  //Expand the boundingbox with slide settings
296
289
  const expandBoxWithSettings = (box, settings, vector) => {
@@ -321,7 +314,7 @@ const TextureSlides = function (textureIn) {
321
314
  break;
322
315
  }
323
316
  }
324
- }
317
+ };
325
318
 
326
319
  /**
327
320
  * Get the bounding box of this slides.
@@ -331,19 +324,17 @@ const TextureSlides = function (textureIn) {
331
324
  * @return {THREE.Box3}.
332
325
  */
333
326
  this.getBoundingBox = () => {
334
- if (this.morph && this.morph.children && this.morph.visible &&
335
- this.boundingBoxUpdateRequired) {
327
+ if (this.morph && this.morph.children && this.morph.visible && this.boundingBoxUpdateRequired) {
336
328
  this.cachedBoundingBox.makeEmpty();
337
329
  const vector = new THREE.Vector3(0, 0, 0);
338
- this.morph.children.forEach(slide => {
339
- expandBoxWithSettings(this.cachedBoundingBox, slide.material.userData.uniforms,
340
- vector);
330
+ this.morph.children.forEach((slide) => {
331
+ expandBoxWithSettings(this.cachedBoundingBox, slide.material.userData.uniforms, vector);
341
332
  });
342
333
  this.cachedBoundingBox.applyMatrix4(updateWorldMatrixFromAncestors(this.morph));
343
334
  this.boundingBoxUpdateRequired = false;
344
335
  }
345
336
  return this.cachedBoundingBox;
346
- }
337
+ };
347
338
 
348
339
  this.applyTransformation = (rotation, position, scale) => {
349
340
  this.requestRender();
@@ -364,56 +355,58 @@ const TextureSlides = function (textureIn) {
364
355
  0,
365
356
  0,
366
357
  0,
367
- 0
358
+ 0,
368
359
  );
369
360
  const quaternion = new THREE.Quaternion().setFromRotationMatrix(matrix);
370
361
  this.morph.position.set(...position);
371
- this.morph.quaternion.copy( quaternion );
362
+ this.morph.quaternion.copy(quaternion);
372
363
  this.morph.scale.set(...scale);
373
364
  this.morph.updateMatrix();
374
365
  this.boundingBoxUpdateRequired = true;
375
- }
366
+ };
376
367
 
377
368
  this.setRenderOrder = (order) => {
378
369
  this.requestRender();
379
370
  //multiilayers
380
371
  this.morph.renderOrder = order;
381
- }
372
+ };
382
373
 
383
374
  this.initialise = (textureData, finishCallback) => {
384
375
  if (textureData) {
385
376
  const locations = textureData.locations;
386
377
  if (locations && locations.length > 0) {
387
- this.applyTransformation(locations[0].orientation,
388
- locations[0].position, locations[0].scale);
389
- if ("flipY" in locations[0]) {
378
+ this.applyTransformation(
379
+ locations[0].orientation,
380
+ locations[0].position,
381
+ locations[0].scale,
382
+ );
383
+ if ('flipY' in locations[0]) {
390
384
  flipY = locations[0].flipY;
391
385
  }
392
- if ("flipZ" in locations[0]) {
386
+ if ('flipZ' in locations[0]) {
393
387
  flipZ = locations[0].flipZ;
394
388
  }
395
389
  }
396
390
  this.createSlides(textureData.settings.slides);
397
- if (finishCallback != undefined && (typeof finishCallback == 'function')) {
391
+ if (finishCallback != undefined && typeof finishCallback == 'function') {
398
392
  finishCallback(this);
399
393
  }
400
394
  }
401
- }
395
+ };
402
396
 
403
397
  this.showEdges = (color) => {
404
398
  this.requestRender();
405
399
  if (!edgesLine) {
406
- const geometry = new THREE.BoxGeometry( 1, 1, 1 );
400
+ const geometry = new THREE.BoxGeometry(1, 1, 1);
407
401
  geometry.translate(0.5, 0.5, 0.5);
408
- const edges = new THREE.EdgesGeometry( geometry );
409
- edgesLine = new THREE.LineSegments(edges, new THREE.LineBasicMaterial( { color } ) );
410
- this.group.add( edgesLine );
402
+ const edges = new THREE.EdgesGeometry(geometry);
403
+ edgesLine = new THREE.LineSegments(edges, new THREE.LineBasicMaterial({ color }));
404
+ this.group.add(edgesLine);
411
405
  } else {
412
406
  edgesLine.material.color = color;
413
407
  }
414
408
  edgesLine.visible = true;
415
- }
416
-
409
+ };
417
410
 
418
411
  this.setUniformsValue = (name, val) => {
419
412
  this.requestRender();
@@ -424,53 +417,53 @@ const TextureSlides = function (textureIn) {
424
417
  uniforms[name].value = val;
425
418
  }
426
419
  });
427
- }
420
+ };
428
421
 
429
422
  this.isAlphaPixelDiscarded = () => {
430
423
  return discardAlpha;
431
- }
424
+ };
432
425
 
433
426
  this.discardAlphaPixel = (flag) => {
434
427
  this.requestRender();
435
428
  discardAlpha = flag;
436
- this.setUniformsValue("discardAlpha", discardAlpha);
437
- }
429
+ this.setUniformsValue('discardAlpha', discardAlpha);
430
+ };
438
431
 
439
432
  this.getBrightness = () => {
440
433
  return brightness;
441
- }
434
+ };
442
435
 
443
436
  this.setBrightness = (brightnessIn) => {
444
437
  this.requestRender();
445
438
  brightness = brightnessIn;
446
- this.setUniformsValue("brightness", brightness);
447
- }
439
+ this.setUniformsValue('brightness', brightness);
440
+ };
448
441
 
449
442
  this.getContrast = () => {
450
443
  return contrast;
451
- }
444
+ };
452
445
 
453
446
  this.setContrast = (contrastIn) => {
454
447
  this.requestRender();
455
- if (contrast >= 0 ) {
448
+ if (contrast >= 0) {
456
449
  contrast = contrastIn;
457
- this.setUniformsValue("contrast", contrast);
450
+ this.setUniformsValue('contrast', contrast);
458
451
  }
459
- }
452
+ };
460
453
 
461
454
  this.getNumberOfChannels = () => {
462
455
  return nChannels;
463
- }
456
+ };
464
457
 
465
458
  this.setNumberOfChannels = (numbersIn) => {
466
459
  this.requestRender();
467
460
  nChannels = numbersIn;
468
- this.setUniformsValue("nChannels", nChannels);
469
- }
461
+ this.setUniformsValue('nChannels', nChannels);
462
+ };
470
463
 
471
464
  this.getMask = () => {
472
465
  return maskTexture;
473
- }
466
+ };
474
467
 
475
468
  this.setMask = (maskTextureIn) => {
476
469
  this.requestRender();
@@ -479,21 +472,21 @@ const TextureSlides = function (textureIn) {
479
472
  this.morph.children.forEach((mesh) => {
480
473
  const material = mesh.material;
481
474
  if (material.userData.uniforms) {
482
- const uniforms = material.userData.uniforms;
475
+ const uniforms = material.userData.uniforms;
483
476
  if (maskTexture) {
484
477
  uniforms.mask.value = maskTexture;
485
478
  }
486
479
  }
487
480
  });
488
- this.setUniformsValue("maskEnabled", maskEnabled);
489
- }
481
+ this.setUniformsValue('maskEnabled', maskEnabled);
482
+ };
490
483
 
491
484
  this.hideEdges = () => {
492
485
  this.requestRender();
493
486
  if (edgesLine) {
494
487
  edgesLine.visible = false;
495
488
  }
496
- }
489
+ };
497
490
 
498
491
  this.updateTimeTexture = () => {
499
492
  const maxIndex = this.textureList.length - 1;
@@ -505,7 +498,7 @@ const TextureSlides = function (textureIn) {
505
498
  const ratio = iTime - t0;
506
499
  this.morph.children.forEach((mesh) => {
507
500
  const material = mesh.material;
508
- if (material.userData.uniforms) {
501
+ if (material.userData.uniforms) {
509
502
  const uniforms = material.userData.uniforms;
510
503
  if (lt0 !== t0) {
511
504
  uniforms.diffuse0.value.image.data = this.textureList[t0].imageData;
@@ -522,7 +515,7 @@ const TextureSlides = function (textureIn) {
522
515
  lt1 = t1;
523
516
  prevTime = normalisedTime;
524
517
  }
525
- }
518
+ };
526
519
 
527
520
  /**
528
521
  * Update the glyphsets if required the render.
@@ -530,34 +523,28 @@ const TextureSlides = function (textureIn) {
530
523
  this.setMorphTime = (time) => {
531
524
  this.requestRender();
532
525
  let newTime = time;
533
- if (time > this.duration)
534
- newTime = this.duration;
535
- else if (0 > time)
536
- newTime = 0;
537
- else
538
- newTime = time;
526
+ if (time > this.duration) newTime = this.duration;
527
+ else if (0 > time) newTime = 0;
528
+ else newTime = time;
539
529
  if (newTime != this.inbuildTime) {
540
530
  this.inbuildTime = newTime;
541
531
  this.updateTimeTexture();
542
532
  }
543
- }
533
+ };
544
534
 
545
535
  /**
546
536
  * Update the glyphsets if required the render.
547
537
  */
548
538
  this.render = (delta, playAnimation, cameraControls, options) => {
549
- //console.log("render", delta, playAnimation, this.textureList)
550
- if (playAnimation == true && this.timeEnabled &&
551
- this.textureList.length > 1) {
539
+ //console.log("render", delta, playAnimation, this.textureList)
540
+ if (playAnimation == true && this.timeEnabled && this.textureList.length > 1) {
552
541
  let targetTime = this.inbuildTime + delta;
553
- if (targetTime > this.duration)
554
- targetTime = targetTime - this.duration;
542
+ if (targetTime > this.duration) targetTime = targetTime - this.duration;
555
543
  this.inbuildTime = targetTime;
556
544
  this.updateTimeTexture();
557
545
  }
558
- }
559
-
560
- }
546
+ };
547
+ };
561
548
 
562
549
  TextureSlides.prototype = Object.create(TexturePrimitive.prototype);
563
550
  TextureSlides.prototype.constructor = TextureSlides;