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
@@ -25,16 +25,20 @@ const Label = function (textIn, colourIn) {
25
25
  let fontWeight = 500;
26
26
  const textHeight = 0.012;
27
27
  //The canvas resolution is chosen from the size of the text on screen
28
- sprite = createTextSprite(text, textHeight,
29
- colourIn ? colourIn.getStyle() : undefined, "Asap", fontWeight);
28
+ sprite = createTextSprite(
29
+ text,
30
+ textHeight,
31
+ colourIn ? colourIn.getStyle() : undefined,
32
+ 'Asap',
33
+ fontWeight,
34
+ );
30
35
  sprite.center.x = -0.05;
31
36
  sprite.center.y = 0;
32
37
  //SpriteText replaces the texture whenever the text, colour or size
33
38
  //changes, the settings need to be re-applied to the new texture.
34
39
  const applyTextureSettings = () => {
35
40
  applyTextSpriteTextureSettings(sprite);
36
- }
37
-
41
+ };
38
42
 
39
43
  /**
40
44
  * Get the current position in an array containing the x, y and z
@@ -43,10 +47,9 @@ const Label = function (textIn, colourIn) {
43
47
  * @return {Array}
44
48
  */
45
49
  this.getPosition = () => {
46
- if (sprite)
47
- return [sprite.position.x, sprite.position.y, sprite.position.z];
50
+ if (sprite) return [sprite.position.x, sprite.position.y, sprite.position.z];
48
51
  return [0, 0, 0];
49
- }
52
+ };
50
53
 
51
54
  /**
52
55
  * Set the position of the label in 3D coordinates.
@@ -63,14 +66,14 @@ const Label = function (textIn, colourIn) {
63
66
  if (sprite) {
64
67
  sprite.position.set(x, y, z);
65
68
  }
66
- }
69
+ };
67
70
 
68
71
  /**
69
72
  * Set the colour of the label
70
73
  *
71
74
  * @param {THREE.Color} colour - colour to be set
72
75
  */
73
- this.setColour = colourIn => {
76
+ this.setColour = (colourIn) => {
74
77
  if (colourIn) {
75
78
  //Changing the colour redraws the canvas and creates a new texture,
76
79
  //only do it when the colour has changed.
@@ -81,61 +84,60 @@ const Label = function (textIn, colourIn) {
81
84
  }
82
85
  colour = colourIn;
83
86
  }
84
- }
87
+ };
85
88
 
86
89
  /**
87
90
  * Scale the label.
88
91
  *
89
92
  * @param {Number} scaling - Scale to be set.
90
93
  */
91
- this.setScale = scaling => {
92
- if (sprite && scaling > 0.0)
93
- sprite.scale.set(scaling, scaling, 1.0);
94
- }
94
+ this.setScale = (scaling) => {
95
+ if (sprite && scaling > 0.0) sprite.scale.set(scaling, scaling, 1.0);
96
+ };
95
97
 
96
98
  /**
97
99
  * Set depth test for sprite object.
98
100
  *
99
101
  * @param {Boolean} flag - Enable/disable depth test
100
102
  */
101
- this.setDepthTest = flag => {
103
+ this.setDepthTest = (flag) => {
102
104
  if (flag && flag !== sprite.material.depthTest) {
103
105
  sprite.material.depthTest = flag;
104
106
  }
105
- }
107
+ };
106
108
 
107
109
  /**
108
110
  * Set a new text for the label.
109
111
  *
110
112
  * @param {Number} scaling - Scale to be set.
111
113
  */
112
- this.setSize = sizeIn => {
114
+ this.setSize = (sizeIn) => {
113
115
  if (sizeIn > 0.0) {
114
116
  //Redraw at the resolution matching the new size
115
117
  setTextSpriteHeight(sprite, textHeight * sizeIn);
116
118
  size = sizeIn;
117
119
  }
118
- }
120
+ };
119
121
 
120
122
  /**
121
123
  * Set a new text for the label.
122
124
  *
123
125
  * @param {Number} scaling - Scale to be set.
124
126
  */
125
- this.setFontWeight = fontWeightIn => {
127
+ this.setFontWeight = (fontWeightIn) => {
126
128
  if (fontWeightIn && fontWeightIn !== fontWeight) {
127
129
  sprite.fontWeight = fontWeightIn;
128
130
  applyTextureSettings();
129
131
  fontWeight = fontWeightIn;
130
132
  }
131
- }
133
+ };
132
134
 
133
135
  /**
134
136
  * Set a new text for the label.
135
137
  *
136
138
  * @param {Number} scaling - Scale to be set.
137
139
  */
138
- this.setText = textIn => {
140
+ this.setText = (textIn) => {
139
141
  if (textIn && textIn !== sprite.text) {
140
142
  //Force teh texture to update
141
143
  const canvas = sprite._canvas;
@@ -158,16 +160,16 @@ const Label = function (textIn, colourIn) {
158
160
  sprite.material.map.needsUpdate = true;
159
161
  }
160
162
  }
161
- }
163
+ };
162
164
 
163
165
  /**
164
166
  * Set visibility of the label.
165
167
  *
166
168
  * @param {Boolean} flag - Visibility to set
167
169
  */
168
- this.setVisibility = flag => {
170
+ this.setVisibility = (flag) => {
169
171
  sprite.visible = flag;
170
- }
172
+ };
171
173
 
172
174
  /**
173
175
  * Free up the memory
@@ -186,7 +188,7 @@ const Label = function (textIn, colourIn) {
186
188
  sprite._canvas.height = 0;
187
189
  }
188
190
  }
189
- }
191
+ };
190
192
 
191
193
  /**
192
194
  * Get the intrnal sprite.
@@ -195,7 +197,7 @@ const Label = function (textIn, colourIn) {
195
197
  */
196
198
  this.getSprite = () => {
197
199
  return sprite;
198
- }
200
+ };
199
201
 
200
202
  /**
201
203
  * Get the text.
@@ -204,11 +206,7 @@ const Label = function (textIn, colourIn) {
204
206
  */
205
207
  this.getString = () => {
206
208
  return text;
207
- }
208
-
209
+ };
209
210
  };
210
211
 
211
212
  export { Label };
212
-
213
-
214
-
@@ -15,7 +15,7 @@ import { ZincObject } from './zincObject';
15
15
  */
16
16
  const Lines = function () {
17
17
  ZincObject.call(this);
18
- this.isLines = true;
18
+ this.isLines = true;
19
19
 
20
20
  /**
21
21
  * Create the line segements using geometry and material.
@@ -28,10 +28,10 @@ const Lines = function () {
28
28
  * @param {Boolean} options.localMorphColour - A flag to indicate either the colour is
29
29
  * time dependent.
30
30
  */
31
- this.createLineSegment = (geometryIn, materialIn, options) => {
32
- if (geometryIn && materialIn) {
33
- let geometry = toBufferGeometry(geometryIn, options );
34
- if (options.localMorphColour && geometry.morphAttributes[ "color" ]) {
31
+ this.createLineSegment = (geometryIn, materialIn, options) => {
32
+ if (geometryIn && materialIn) {
33
+ let geometry = toBufferGeometry(geometryIn, options);
34
+ if (options.localMorphColour && geometry.morphAttributes['color']) {
35
35
  //Force vertexColors off (even if the caller/material already set
36
36
  //it true from the file's declared material) - NodeMaterial would
37
37
  //otherwise multiply our morph colour blend by the static,
@@ -40,25 +40,25 @@ const Lines = function () {
40
40
  //turning parts of the blend black instead of the intended hue.
41
41
  //applyMorphColorNode's colorNode fully replaces vertex colouring.
42
42
  materialIn.vertexColors = false;
43
- materialIn = applyMorphColorNode(materialIn);
43
+ materialIn = applyMorphColorNode(materialIn);
44
44
  }
45
45
  let line = new LineSegments(geometry, materialIn);
46
46
  this.setMesh(line, options.localTimeEnabled, options.localMorphColour);
47
- }
48
- }
47
+ }
48
+ };
49
49
 
50
50
  /**
51
51
  * Set the width for the lines.
52
52
  *
53
53
  * @param {Number} width - Width of the lines.
54
54
  */
55
- this.setWidth = width => {
56
- this.requestRender();
57
- if (this.morph && this.morph.material) {
58
- this.morph.material.linewidth = width;
59
- this.morph.material.needsUpdate = true;
60
- }
61
- }
55
+ this.setWidth = (width) => {
56
+ this.requestRender();
57
+ if (this.morph && this.morph.material) {
58
+ this.morph.material.linewidth = width;
59
+ this.morph.material.needsUpdate = true;
60
+ }
61
+ };
62
62
 
63
63
  /**
64
64
  * Add new lines to existing lines if it exists, otherwise
@@ -67,21 +67,21 @@ const Lines = function () {
67
67
 
68
68
  * @param {Number} colour - A hex value of the colour for the points
69
69
  */
70
- this.addLines = (coords, colour) => {
70
+ this.addLines = (coords, colour) => {
71
71
  this.requestRender();
72
72
  if (coords && coords.length > 0) {
73
73
  const geometry = this.addVertices(coords);
74
74
  let mesh = this.getMorph();
75
75
  if (!mesh) {
76
- let material = new THREE.LineBasicMaterial({color:colour});
77
- const options = { localTimeEnabled: false, localMorphColour: false};
76
+ let material = new THREE.LineBasicMaterial({ color: colour });
77
+ const options = { localTimeEnabled: false, localMorphColour: false };
78
78
  geometry.colorsNeedUpdate = true;
79
79
  this.createLineSegment(geometry, material, options);
80
80
  }
81
81
  if (this.region) this.region.pickableUpdateRequired = true;
82
82
  }
83
- }
84
- }
83
+ };
84
+ };
85
85
 
86
86
  Lines.prototype = Object.create(ZincObject.prototype);
87
87
  export { Lines };
@@ -15,7 +15,7 @@ import { LineSegmentsGeometry } from '../three/line/LineSegmentsGeometry';
15
15
  */
16
16
  const Lines2 = function () {
17
17
  Lines.call(this);
18
- this.isLines2 = true;
18
+ this.isLines2 = true;
19
19
  //Shared with the GPU buffer of the mesh, edits are made in place
20
20
  let positions = new Float32Array(300);
21
21
 
@@ -31,7 +31,7 @@ const Lines2 = function () {
31
31
  return true;
32
32
  }
33
33
  return false;
34
- }
34
+ };
35
35
 
36
36
  //Fill the unused part of the array with degenerate segments at coord
37
37
  const fillUnused = (start, coord) => {
@@ -40,7 +40,7 @@ const Lines2 = function () {
40
40
  positions[index + 1] = coord[1];
41
41
  positions[index + 2] = coord[2];
42
42
  }
43
- }
43
+ };
44
44
 
45
45
  //Update the line distances without allocating new buffers
46
46
  const updateLineDistances = (mesh) => {
@@ -63,7 +63,7 @@ const Lines2 = function () {
63
63
  distances[i * 2 + 1] = total;
64
64
  }
65
65
  distanceStart.data.needsUpdate = true;
66
- }
66
+ };
67
67
 
68
68
  //Upload the positions after they have been changed
69
69
  const updatePositions = (mesh, reallocated) => {
@@ -79,7 +79,7 @@ const Lines2 = function () {
79
79
  mesh.geometry.computeBoundingSphere();
80
80
  }
81
81
  this.boundingBoxUpdateRequired = true;
82
- }
82
+ };
83
83
 
84
84
  /**
85
85
  * Create the line segements using geometry and material.
@@ -92,8 +92,8 @@ const Lines2 = function () {
92
92
  * @param {Boolean} options.localMorphColour - A flag to indicate either the colour is
93
93
  * time dependent.
94
94
  */
95
- this.createLineSegment = (arrayIn, materialIn, options) => {
96
- if (arrayIn && materialIn) {
95
+ this.createLineSegment = (arrayIn, materialIn, options) => {
96
+ if (arrayIn && materialIn) {
97
97
  const linesGeometry = new LineSegmentsGeometry();
98
98
  linesGeometry.setPositions(arrayIn);
99
99
  linesGeometry.colorsNeedUpdate = true;
@@ -101,26 +101,26 @@ const Lines2 = function () {
101
101
  line.scale.set(1, 1, 1);
102
102
  line.computeLineDistances();
103
103
  this.setMesh(line, options.localTimeEnabled, options.localMorphColour);
104
- }
105
- }
104
+ }
105
+ };
106
106
 
107
107
  /**
108
108
  * Set the width for the lines.
109
109
  *
110
110
  * @param {Number} width - Width of the lines.
111
111
  */
112
- this.setWidth = width => {
113
- this.requestRender();
114
- if (this.morph && this.morph.material) {
115
- this.morph.material.linewidth = width;
116
- this.morph.material.needsUpdate = true;
117
- }
118
- }
112
+ this.setWidth = (width) => {
113
+ this.requestRender();
114
+ if (this.morph && this.morph.material) {
115
+ this.morph.material.linewidth = width;
116
+ this.morph.material.needsUpdate = true;
117
+ }
118
+ };
119
119
 
120
120
  /**
121
121
  * Add new vertices into the array
122
122
  */
123
- this.addVertices = function(coords) {
123
+ this.addVertices = function (coords) {
124
124
  this.requestRender();
125
125
  if (coords && coords.length) {
126
126
  let mesh = this.getMorph();
@@ -129,7 +129,7 @@ const Lines2 = function () {
129
129
  }
130
130
  let index = this.drawRange * 3;
131
131
  const reallocated = ensureCapacity(index + coords.length * 3);
132
- coords.forEach(coord => {
132
+ coords.forEach((coord) => {
133
133
  positions[index++] = coord[0];
134
134
  positions[index++] = coord[1];
135
135
  positions[index++] = coord[2];
@@ -146,22 +146,18 @@ const Lines2 = function () {
146
146
  }
147
147
  }
148
148
  return positions;
149
- }
149
+ };
150
150
 
151
151
  /**
152
152
  * Get the vertices by face index
153
153
  */
154
- this.getVerticesByFaceIndex = function(faceIndex) {
154
+ this.getVerticesByFaceIndex = function (faceIndex) {
155
155
  let vIndex = faceIndex * 2 * 3;
156
156
  const mesh = this.getMorph();
157
- if (mesh && (this.drawRange * 3) > vIndex) {
158
- const position = mesh.geometry.getAttribute( 'instanceStart' );
157
+ if (mesh && this.drawRange * 3 > vIndex) {
158
+ const position = mesh.geometry.getAttribute('instanceStart');
159
159
  return [
160
- [
161
- position.data.array[vIndex],
162
- position.data.array[++vIndex],
163
- position.data.array[++vIndex],
164
- ],
160
+ [position.data.array[vIndex], position.data.array[++vIndex], position.data.array[++vIndex]],
165
161
  [
166
162
  position.data.array[++vIndex],
167
163
  position.data.array[++vIndex],
@@ -170,12 +166,12 @@ const Lines2 = function () {
170
166
  ];
171
167
  }
172
168
  return [];
173
- }
169
+ };
174
170
 
175
171
  /**
176
172
  * Edit Vertice in index.
177
173
  */
178
- this.editVertices = function(coords, i) {
174
+ this.editVertices = function (coords, i) {
179
175
  this.requestRender();
180
176
  if (coords && coords.length) {
181
177
  let mesh = this.getMorph();
@@ -183,9 +179,8 @@ const Lines2 = function () {
183
179
  if (!mesh || 0 > i || maxIndex >= this.drawRange) {
184
180
  return;
185
181
  } else {
186
-
187
182
  let index = i * 3;
188
- coords.forEach(coord => {
183
+ coords.forEach((coord) => {
189
184
  positions[index++] = coord[0];
190
185
  positions[index++] = coord[1];
191
186
  positions[index++] = coord[2];
@@ -195,7 +190,7 @@ const Lines2 = function () {
195
190
  }
196
191
  }
197
192
  return positions;
198
- }
193
+ };
199
194
 
200
195
  /**
201
196
  * Add new lines to existing lines if it exists, otherwise
@@ -204,26 +199,25 @@ const Lines2 = function () {
204
199
 
205
200
  * @param {Number} colour - A hex value of the colour for the points
206
201
  */
207
- this.addLines = (coords, colour) => {
202
+ this.addLines = (coords, colour) => {
208
203
  this.requestRender();
209
204
  if (coords && coords.length > 0) {
210
205
  this.addVertices(coords);
211
206
  let mesh = this.getMorph();
212
207
  if (!mesh) {
213
- const material = new THREE.Line2NodeMaterial( {
208
+ const material = new THREE.Line2NodeMaterial({
214
209
  color: colour,
215
- linewidth:1,
210
+ linewidth: 1,
216
211
  vertexColors: false,
217
212
  worldUnits: false,
218
213
  });
219
- const options = { localTimeEnabled: false, localMorphColour: false};
214
+ const options = { localTimeEnabled: false, localMorphColour: false };
220
215
  this.createLineSegment(positions, material, options);
221
216
  }
222
217
  if (this.region) this.region.pickableUpdateRequired = true;
223
218
  }
224
- }
225
-
226
- }
219
+ };
220
+ };
227
221
 
228
222
  Lines2.prototype = Object.create(Lines.prototype);
229
223
  Lines2.prototype.constructor = Lines2;