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
package/src/minimap.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as THREE from 'three/webgpu';
2
- import { copyVector3sArray } from "./utilities";
2
+ import { copyVector3sArray } from './utilities';
3
3
 
4
4
  /**
5
5
  * This provide a full scale minimap. It will always
@@ -11,35 +11,41 @@ import { copyVector3sArray } from "./utilities";
11
11
  */
12
12
  const Minimap = function (sceneIn) {
13
13
  let targetScene = sceneIn;
14
- this.camera = new THREE.OrthographicCamera(
15
- -0.5, 0.5, 0.5, -0.5, 0.01, 10);
14
+ this.camera = new THREE.OrthographicCamera(-0.5, 0.5, 0.5, -0.5, 0.01, 10);
16
15
  this.helper = undefined;
17
16
  let geometry = new THREE.BufferGeometry();
18
- var vertices = new Float32Array( [
19
- -1.0, -1.0, 1.0,
20
- 1.0, -1.0, 1.0,
21
- 1.0, 1.0, 1.0,
22
- 1.0, 1.0, 1.0,
23
- -1.0, 1.0, 1.0,
24
- -1.0, -1.0, 1.0
25
- ] );
26
- let positionAttributes = new THREE.BufferAttribute( vertices, 3 );
27
- geometry.setAttribute( 'position', positionAttributes);
28
- var material = new THREE.MeshBasicMaterial( { color: 0x333333,
17
+ var vertices = new Float32Array([
18
+ -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0,
19
+ ]);
20
+ let positionAttributes = new THREE.BufferAttribute(vertices, 3);
21
+ geometry.setAttribute('position', positionAttributes);
22
+ var material = new THREE.MeshBasicMaterial({
23
+ color: 0x333333,
29
24
  depthTest: false,
30
25
  depthWrite: false,
31
26
  opacity: 0.5,
32
- transparent: true } );
33
- this.mask = new THREE.Mesh( geometry, material );
27
+ transparent: true,
28
+ });
29
+ this.mask = new THREE.Mesh(geometry, material);
34
30
  let _box = new THREE.Box3();
35
31
  let _center = new THREE.Vector3();
36
32
  const _coord = new THREE.Vector3();
37
33
  const _lookAt = new THREE.Vector3();
38
34
  const _target = new THREE.Vector3();
39
- const _corners = [new THREE.Vector3(), new THREE.Vector3(),
40
- new THREE.Vector3(), new THREE.Vector3()];
41
- const _boundaryVertices = [_corners[0], _corners[1], _corners[2],
42
- _corners[2], _corners[3], _corners[0]];
35
+ const _corners = [
36
+ new THREE.Vector3(),
37
+ new THREE.Vector3(),
38
+ new THREE.Vector3(),
39
+ new THREE.Vector3(),
40
+ ];
41
+ const _boundaryVertices = [
42
+ _corners[0],
43
+ _corners[1],
44
+ _corners[2],
45
+ _corners[2],
46
+ _corners[3],
47
+ _corners[0],
48
+ ];
43
49
  //State the minimap was last computed from, it only needs to be updated
44
50
  //when the scene or the main camera changes.
45
51
  const _lastBoundingBox = new THREE.Box3();
@@ -50,36 +56,40 @@ const Minimap = function (sceneIn) {
50
56
  //Matrix4.equals treats NaN as different, e.g. with a zero sized canvas
51
57
  const matrixEquals = (a, b) => {
52
58
  for (let i = 0; i < 16; i++) {
53
- if (!Object.is(a.elements[i], b.elements[i]))
54
- return false;
59
+ if (!Object.is(a.elements[i], b.elements[i])) return false;
55
60
  }
56
61
  return true;
57
- }
62
+ };
58
63
 
59
64
  this.getDiffFromNormalised = (x, y) => {
60
65
  _box.setFromBufferAttribute(positionAttributes).getCenter(_center);
61
66
  _coord.copy(_center).project(this.camera);
62
67
  //Returns a new vector, the caller may keep it
63
68
  return new THREE.Vector3(x, y, _coord.z).unproject(this.camera).sub(_center);
64
- }
69
+ };
65
70
 
66
- let setCurrentCameraSettings = (diameter, newViewport) => {
67
- if (targetScene.camera.near)
68
- this.camera.near = targetScene.camera.near;
69
- if (newViewport.farPlane)
70
- this.camera.far = newViewport.farPlane;
71
+ let setCurrentCameraSettings = (diameter, newViewport) => {
72
+ if (targetScene.camera.near) this.camera.near = targetScene.camera.near;
73
+ if (newViewport.farPlane) this.camera.far = newViewport.farPlane;
71
74
  if (newViewport.eyePosition)
72
- this.camera.position.set(newViewport.eyePosition[0],
73
- newViewport.eyePosition[1], newViewport.eyePosition[2]);
75
+ this.camera.position.set(
76
+ newViewport.eyePosition[0],
77
+ newViewport.eyePosition[1],
78
+ newViewport.eyePosition[2],
79
+ );
74
80
  if (newViewport.upVector)
75
- this.camera.up.set(newViewport.upVector[0], newViewport.upVector[1],
76
- newViewport.upVector[2]);
81
+ this.camera.up.set(newViewport.upVector[0], newViewport.upVector[1], newViewport.upVector[2]);
77
82
  if (newViewport.targetPosition)
78
- this.camera.lookAt(_lookAt.set(newViewport.targetPosition[0],
79
- newViewport.targetPosition[1], newViewport.targetPosition[2]));
83
+ this.camera.lookAt(
84
+ _lookAt.set(
85
+ newViewport.targetPosition[0],
86
+ newViewport.targetPosition[1],
87
+ newViewport.targetPosition[2],
88
+ ),
89
+ );
80
90
  this.camera.zoom = 1 / diameter;
81
91
  this.camera.updateProjectionMatrix();
82
- }
92
+ };
83
93
 
84
94
  this.getBoundary = () => {
85
95
  const camera = targetScene.camera;
@@ -89,16 +99,20 @@ const Minimap = function (sceneIn) {
89
99
  _corners[2].set(1, 1, _target.z).unproject(camera);
90
100
  _corners[3].set(-1, 1, _target.z).unproject(camera);
91
101
  copyVector3sArray(positionAttributes, _boundaryVertices);
92
- }
102
+ };
93
103
 
94
104
  this.updateCamera = () => {
95
105
  const camera = targetScene.camera;
96
106
  let boundingBox = targetScene.getBoundingBox();
97
107
  //Nothing has changed since the last update
98
- if (_cameraUpdated && boundingBox && boundingBox.equals(_lastBoundingBox) &&
108
+ if (
109
+ _cameraUpdated &&
110
+ boundingBox &&
111
+ boundingBox.equals(_lastBoundingBox) &&
99
112
  _lastNear === camera.near &&
100
113
  matrixEquals(_lastMatrixWorld, camera.matrixWorld) &&
101
- matrixEquals(_lastProjectionMatrix, camera.projectionMatrix)) {
114
+ matrixEquals(_lastProjectionMatrix, camera.projectionMatrix)
115
+ ) {
102
116
  return;
103
117
  }
104
118
  this.getBoundary();
@@ -118,10 +132,16 @@ const Minimap = function (sceneIn) {
118
132
  const centreZ = (boundingBox.min.z + boundingBox.max.z) / 2.0;
119
133
  const clip_factor = 4.0;
120
134
  const viewport = cameraControl.getViewportFromCentreAndRadius(
121
- centreX, centreY, centreZ, radius, 40, radius * clip_factor);
135
+ centreX,
136
+ centreY,
137
+ centreZ,
138
+ radius,
139
+ 40,
140
+ radius * clip_factor,
141
+ );
122
142
  setCurrentCameraSettings(diameter, viewport);
123
143
  }
124
- }
125
- }
144
+ };
145
+ };
126
146
 
127
- export { Minimap };
147
+ export { Minimap };
@@ -1,9 +1,9 @@
1
1
  import * as THREE from 'three/webgpu';
2
2
  import { toBufferGeometry } from '../utilities';
3
3
  import { applyMorphColorNode } from '../tsl/morphColorMaterial';
4
- import { ZincObject} from './zincObject';
4
+ import { ZincObject } from './zincObject';
5
5
 
6
- const createMeshForGeometry = (geometryIn, materialIn, options) => {
6
+ const createMeshForGeometry = (geometryIn, materialIn, options) => {
7
7
  // First copy the geometry
8
8
  let geometry = toBufferGeometry(geometryIn, options);
9
9
 
@@ -17,14 +17,14 @@ const createMeshForGeometry = (geometryIn, materialIn, options) => {
17
17
  material = materialIn;
18
18
  } else {
19
19
  material = new THREE.MeshPhongMaterial({
20
- color : options.colour,
21
- vertexColors : false,
22
- transparent : isTransparent,
23
- opacity : options.opacity,
24
- side : THREE.DoubleSide
20
+ color: options.colour,
21
+ vertexColors: false,
22
+ transparent: isTransparent,
23
+ opacity: options.opacity,
24
+ side: THREE.DoubleSide,
25
25
  });
26
26
  }
27
- if (options.localMorphColour && geometry.morphAttributes[ "color" ]) {
27
+ if (options.localMorphColour && geometry.morphAttributes['color']) {
28
28
  //Force vertexColors off (even if materialIn already had it true) -
29
29
  //NodeMaterial would otherwise multiply our morph colour blend by
30
30
  //the static, non-morph 'color' attribute (vertexColor() in
@@ -38,15 +38,15 @@ const createMeshForGeometry = (geometryIn, materialIn, options) => {
38
38
  } else {
39
39
  let videoTexture = geometry._video.createCanvasVideoTexture();
40
40
  material = new THREE.MeshBasicMaterial({
41
- color : new THREE.Color(1, 1, 1),
42
- transparent : isTransparent,
43
- opacity : options.opacity,
44
- map : videoTexture,
45
- side : THREE.DoubleSide
41
+ color: new THREE.Color(1, 1, 1),
42
+ transparent: isTransparent,
43
+ opacity: options.opacity,
44
+ map: videoTexture,
45
+ side: THREE.DoubleSide,
46
46
  });
47
47
  }
48
48
  return new THREE.Mesh(geometry, material);
49
- }
49
+ };
50
50
 
51
51
  /**
52
52
  * Provides an object which stores geometry and provides method which controls its animations.
@@ -59,8 +59,8 @@ const createMeshForGeometry = (geometryIn, materialIn, options) => {
59
59
  */
60
60
  const Geometry = function () {
61
61
  ZincObject.call(this);
62
- // THREE.Geometry or THREE.BufferGeometry
63
- this.videoHandler = undefined;
62
+ // THREE.Geometry or THREE.BufferGeometry
63
+ this.videoHandler = undefined;
64
64
  this.isGeometry = true;
65
65
 
66
66
  /**
@@ -76,46 +76,45 @@ const Geometry = function () {
76
76
  * time dependent.
77
77
  * @param {Number} options.opacity - Opacity to be set for the geometry
78
78
  */
79
- this.createMesh = (geometryIn, materialIn, options) => {
79
+ this.createMesh = (geometryIn, materialIn, options) => {
80
80
  //Skip if there is a morph already
81
- if (this.morph && this.morph.geometry && (geometryIn != undefined))
82
- return;
83
- const mesh = createMeshForGeometry(geometryIn, materialIn, options);
81
+ if (this.morph && this.morph.geometry && geometryIn != undefined) return;
82
+ const mesh = createMeshForGeometry(geometryIn, materialIn, options);
84
83
  this.videoHandler = mesh.geometry._video;
85
- this.setMesh(mesh, options.localTimeEnabled, options.localMorphColour);
86
- }
84
+ this.setMesh(mesh, options.localTimeEnabled, options.localMorphColour);
85
+ };
87
86
 
88
87
  /**
89
88
  * Handle transparent mesh, create a clone for backside rendering if it is
90
89
  * transparent.
91
90
  */
92
- this.checkTransparentMesh = function() {
91
+ this.checkTransparentMesh = function () {
93
92
  this._lod.checkTransparentMesh();
94
- }
93
+ };
95
94
 
96
- /**
97
- * Set wireframe display for this geometry.
98
- *
99
- * @param {Boolean} wireframe - Flag to turn on/off wireframe display.
100
- */
101
- this.setWireframe = wireframe => {
102
- this.requestRender();
103
- this.morph.material.wireframe = wireframe;
104
- }
95
+ /**
96
+ * Set wireframe display for this geometry.
97
+ *
98
+ * @param {Boolean} wireframe - Flag to turn on/off wireframe display.
99
+ */
100
+ this.setWireframe = (wireframe) => {
101
+ this.requestRender();
102
+ this.morph.material.wireframe = wireframe;
103
+ };
105
104
 
106
105
  /**
107
106
  * Edit Vertice in index.
108
107
  */
109
- this.editVertices = function(coords, i) {
108
+ this.editVertices = function (coords, i) {
110
109
  this.requestRender();
111
110
  if (coords && coords.length) {
112
111
  let mesh = this.getMorph();
113
- const attribute = mesh.geometry.getAttribute("position");
112
+ const attribute = mesh.geometry.getAttribute('position');
114
113
  if (!mesh || 0 > i) {
115
114
  return;
116
115
  } else {
117
116
  let index = i * 3;
118
- coords.forEach(coord => {
117
+ coords.forEach((coord) => {
119
118
  attribute.array[index++] = coord[0];
120
119
  attribute.array[index++] = coord[1];
121
120
  attribute.array[index++] = coord[2];
@@ -126,21 +125,18 @@ const Geometry = function () {
126
125
  this.boundingBoxUpdateRequired = true;
127
126
  }
128
127
  }
129
- }
128
+ };
130
129
 
131
130
  /**
132
131
  * Check if the geometry is time varying.
133
132
  *
134
133
  * @return {Boolean}
135
134
  */
136
- this.isTimeVarying = function() {
137
- if (this.timeEnabled || this.morphColour || this.videoHandler)
138
- return true;
135
+ this.isTimeVarying = function () {
136
+ if (this.timeEnabled || this.morphColour || this.videoHandler) return true;
139
137
  return false;
140
- }
141
-
142
-
143
- }
138
+ };
139
+ };
144
140
 
145
141
  Geometry.prototype = Object.create(ZincObject.prototype);
146
142
  export { Geometry };
@@ -35,7 +35,7 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
35
35
  *
36
36
  * @returns {Boolean} true if successful
37
37
  */
38
- this.fromMesh = meshIn => {
38
+ this.fromMesh = (meshIn) => {
39
39
  if (meshIn && meshIn.isMesh) {
40
40
  this.morph = meshIn.clone();
41
41
  this.morph.userData = this;
@@ -43,7 +43,7 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
43
43
  return true;
44
44
  }
45
45
  return false;
46
- }
46
+ };
47
47
 
48
48
  if (geometry && material) {
49
49
  this.fromMesh(new THREE.Mesh(geometry, material));
@@ -56,20 +56,19 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
56
56
  */
57
57
  this.getGlyphset = function () {
58
58
  return parent;
59
- }
59
+ };
60
60
 
61
61
  /**
62
62
  * Set and update the text containing this glyph.
63
63
  * @param {String} text - Label to be set for this instance
64
64
  */
65
- this.setLabel = text => {
65
+ this.setLabel = (text) => {
66
66
  parent?.requestRender?.();
67
67
  if (text && (typeof text === 'string' || text instanceof String)) {
68
68
  labelString = text;
69
- if (this.morph)
70
- this.morph.name = text;
69
+ if (this.morph) this.morph.name = text;
71
70
  }
72
- }
71
+ };
73
72
 
74
73
  /**
75
74
  * Display label with the choosen colour. It will replace the current
@@ -96,7 +95,7 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
96
95
  sprite.material.depthWrite = false;
97
96
  this.group.add(label.getSprite());
98
97
  }
99
- }
98
+ };
100
99
 
101
100
  /**
102
101
  * Hide label with the choosen colour.
@@ -109,7 +108,7 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
109
108
  label.dispose();
110
109
  label = undefined;
111
110
  }
112
- }
111
+ };
113
112
 
114
113
  /**
115
114
  * Get the label of this glyph
@@ -117,7 +116,7 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
117
116
  */
118
117
  this.getLabel = () => {
119
118
  return labelString;
120
- }
119
+ };
121
120
 
122
121
  /**
123
122
  * Get the mesh of this glyph.
@@ -125,7 +124,7 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
125
124
  */
126
125
  this.getMesh = () => {
127
126
  return this.morph;
128
- }
127
+ };
129
128
 
130
129
  /**
131
130
  * Set the transformation of this glyph.
@@ -163,7 +162,7 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
163
162
  if (label) {
164
163
  label.setPosition(position[0], position[1], position[2]);
165
164
  }
166
- }
165
+ };
167
166
 
168
167
  /**
169
168
  * Set the color of the glyph and its label. Remembered (see showLabel())
@@ -177,14 +176,13 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
177
176
  this.setColour = (color) => {
178
177
  parent?.requestRender?.();
179
178
  _colour = color ? color.clone() : undefined;
180
- if (label)
181
- label.setColour(color);
179
+ if (label) label.setColour(color);
182
180
  if (this.secondaryMesh && this.secondaryMesh.material)
183
181
  this.secondaryMesh.material.color = color;
184
182
  if (this.geometry) {
185
183
  this.geometry.colorsNeedUpdate = true;
186
184
  }
187
- }
185
+ };
188
186
 
189
187
  /**
190
188
  * Get the last colour set via setColour(), if any.
@@ -200,11 +198,10 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
200
198
  label.dispose();
201
199
  label = undefined;
202
200
  }
203
- if (this.material)
204
- this.material.dispose();
201
+ if (this.material) this.material.dispose();
205
202
  this.morph = undefined;
206
- }
207
- }
203
+ };
204
+ };
208
205
 
209
206
  Glyph.prototype = Object.create(ZincObject.prototype);
210
207
  export { Glyph };