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
@@ -7,142 +7,138 @@ import { GeometryCSGInternal } from './workers/geometryCSGInternal';
7
7
  const ThreeBSP = ThreeBSPWrapper(THREE);
8
8
  const JSONLoader = THREE.BufferGeometryLoader;
9
9
 
10
-
11
10
  const GeometryCSG = function (hostIn) {
12
11
  //ZincGeoemtry of the main geometry
13
12
  let host = undefined;
14
- if (hostIn && hostIn.isGeometry)
15
- host = hostIn;
13
+ if (hostIn && hostIn.isGeometry) host = hostIn;
16
14
  let core = undefined;
17
15
  let worker = undefined;
18
16
  let onProgress = false;
19
17
  let myResolve = undefined;
20
18
 
21
- var createGeometryFromJSON = json => {
22
- const material = host.getMorph().material.clone();
23
- material.morphTargets = false;
24
- const newGeometry = new Geometry();
25
- const JSONParser = new JSONLoader();
26
- const geometry = JSONParser.parse(json);
19
+ var createGeometryFromJSON = (json) => {
20
+ const material = host.getMorph().material.clone();
21
+ material.morphTargets = false;
22
+ const newGeometry = new Geometry();
23
+ const JSONParser = new JSONLoader();
24
+ const geometry = JSONParser.parse(json);
27
25
  const mesh = new THREE.Mesh(geometry.geometry, material);
28
- newGeometry.geometry = mesh.geometry;
26
+ newGeometry.geometry = mesh.geometry;
29
27
  mesh.userData = newGeometry;
30
- newGeometry.setMorph(mesh);
31
- return newGeometry;
32
- }
33
-
34
- var workerEventHandler = ev => {
35
- switch (ev.data.action) {
36
- case 'message':
37
- console.log(ev.data.message);
38
- break;
39
- case 'result':
40
- const csg = new GeometryCSG(createGeometryFromJSON(ev.data.object));
41
- if (myResolve)
42
- myResolve(csg);
43
- myResolve = undefined;
44
- onProgress = false;
45
- break;
46
- default:
47
- throw 'Cannot handle specified action.';
28
+ newGeometry.setMorph(mesh);
29
+ return newGeometry;
30
+ };
31
+
32
+ var workerEventHandler = (ev) => {
33
+ switch (ev.data.action) {
34
+ case 'message':
35
+ console.log(ev.data.message);
36
+ break;
37
+ case 'result':
38
+ const csg = new GeometryCSG(createGeometryFromJSON(ev.data.object));
39
+ if (myResolve) myResolve(csg);
40
+ myResolve = undefined;
41
+ onProgress = false;
42
+ break;
43
+ default:
44
+ throw 'Cannot handle specified action.';
48
45
  }
49
- }
50
-
51
- var initialise = hostIn => {
52
- if (work !== undefined) {
53
- worker = new GeometryWorker();
54
- }
55
- if (!worker) {
56
- core = new GeometryCSGInternal(hostIn);
57
- } else {
58
- if (hostIn && hostIn.isGeometry) {
59
- let mesh = hostIn.getMorph();
60
- let json = mesh.geometry.clone().applyMatrix(mesh.matrix).toJSON();
61
- worker.addEventListener('message', function (ev) {
62
- workerEventHandler(ev);
63
- });
64
- worker.postMessage({action: "initialise", object: json});
65
- }
66
- }
67
- }
46
+ };
47
+
48
+ var initialise = (hostIn) => {
49
+ if (work !== undefined) {
50
+ worker = new GeometryWorker();
51
+ }
52
+ if (!worker) {
53
+ core = new GeometryCSGInternal(hostIn);
54
+ } else {
55
+ if (hostIn && hostIn.isGeometry) {
56
+ let mesh = hostIn.getMorph();
57
+ let json = mesh.geometry.clone().applyMatrix(mesh.matrix).toJSON();
58
+ worker.addEventListener('message', function (ev) {
59
+ workerEventHandler(ev);
60
+ });
61
+ worker.postMessage({ action: 'initialise', object: json });
62
+ }
63
+ }
64
+ };
68
65
 
69
66
  this.getHostGeometry = () => {
70
- const tempCSG = new ThreeBSP(host.getMorph());
67
+ const tempCSG = new ThreeBSP(host.getMorph());
71
68
  return new createZincGeometry(tempCSG);
72
- }
69
+ };
73
70
 
74
71
  this.getGeometry = () => host;
75
72
 
76
- const createZincGeometry = csgMesh => {
77
- const material = host.getMorph().material.clone();
78
- material.morphTargets = false;
79
- const newMesh = csgMesh.toMesh(material);
80
- const newGeometry = new Geometry();
81
- newGeometry.geometry = newMesh.geometry;
82
- newMesh.userData = newGeometry;
83
- newGeometry.setMorph(newMesh);
84
- return newGeometry;
85
- }
86
-
87
- this.setCSG = CSG => {
88
- core.setCSG(CSG);
89
- }
73
+ const createZincGeometry = (csgMesh) => {
74
+ const material = host.getMorph().material.clone();
75
+ material.morphTargets = false;
76
+ const newMesh = csgMesh.toMesh(material);
77
+ const newGeometry = new Geometry();
78
+ newGeometry.geometry = newMesh.geometry;
79
+ newMesh.userData = newGeometry;
80
+ newGeometry.setMorph(newMesh);
81
+ return newGeometry;
82
+ };
83
+
84
+ this.setCSG = (CSG) => {
85
+ core.setCSG(CSG);
86
+ };
90
87
 
91
88
  const sendToWork = (guestGeometry, action, resolve, reject) => {
92
- if (!onProgress) {
93
- let mesh = guestGeometry.getMorph();
94
- const json = mesh.geometry.clone().applyMatrix(mesh.matrix).toJSON();
95
- myResolve = resolve;
96
- onProgress = true;
97
- worker.postMessage({action: action, object: json});
98
- } else {
99
- reject("On progress");
100
- }
101
- }
102
-
103
- this.intersect = guestGeometry => {
104
- return new Promise((resolve, reject) => {
105
- if (worker) {
106
- sendToWork(guestGeometry, "intersect", resolve, reject);
107
- } else {
108
- const result = core.intersect(guestGeometry);
109
- const newCSG = new GeometryCSG(createZincGeometry(result));
110
- newCSG.setCSG(result);
111
- resolve(newCSG);
112
- }
113
- });
114
- };
115
-
116
- this.subtract = guestGeometry => {
117
- return new Promise((resolve, reject) => {
118
- if (worker) {
119
- sendToWork(guestGeometry, "intersect", resolve, reject);
120
- } else {
121
- const result = core.subtract(guestGeometry);
122
- const newCSG = new GeometryCSG(createZincGeometry(result));
123
- newCSG.setCSG(result);
124
- resolve(newCSG);
125
- }
126
- });
127
- }
128
-
129
- this.union = guestGeometry => {
130
- return new Promise((resolve, reject) => {
131
- if (worker) {
132
- sendToWork(guestGeometry, "intersect", resolve, reject);
133
- } else {
134
- const result = core.union(guestGeometry);
135
- const newCSG = new GeometryCSG(createZincGeometry(result));
136
- newCSG.setCSG(result);
137
- resolve(newCSG);
138
- }
139
- });
140
- }
89
+ if (!onProgress) {
90
+ let mesh = guestGeometry.getMorph();
91
+ const json = mesh.geometry.clone().applyMatrix(mesh.matrix).toJSON();
92
+ myResolve = resolve;
93
+ onProgress = true;
94
+ worker.postMessage({ action: action, object: json });
95
+ } else {
96
+ reject('On progress');
97
+ }
98
+ };
99
+
100
+ this.intersect = (guestGeometry) => {
101
+ return new Promise((resolve, reject) => {
102
+ if (worker) {
103
+ sendToWork(guestGeometry, 'intersect', resolve, reject);
104
+ } else {
105
+ const result = core.intersect(guestGeometry);
106
+ const newCSG = new GeometryCSG(createZincGeometry(result));
107
+ newCSG.setCSG(result);
108
+ resolve(newCSG);
109
+ }
110
+ });
111
+ };
112
+
113
+ this.subtract = (guestGeometry) => {
114
+ return new Promise((resolve, reject) => {
115
+ if (worker) {
116
+ sendToWork(guestGeometry, 'intersect', resolve, reject);
117
+ } else {
118
+ const result = core.subtract(guestGeometry);
119
+ const newCSG = new GeometryCSG(createZincGeometry(result));
120
+ newCSG.setCSG(result);
121
+ resolve(newCSG);
122
+ }
123
+ });
124
+ };
125
+
126
+ this.union = (guestGeometry) => {
127
+ return new Promise((resolve, reject) => {
128
+ if (worker) {
129
+ sendToWork(guestGeometry, 'intersect', resolve, reject);
130
+ } else {
131
+ const result = core.union(guestGeometry);
132
+ const newCSG = new GeometryCSG(createZincGeometry(result));
133
+ newCSG.setCSG(result);
134
+ resolve(newCSG);
135
+ }
136
+ });
137
+ };
141
138
 
142
139
  this.terminateWorker = () => {
143
- if (worker)
144
- worker.terminate();
145
- }
140
+ if (worker) worker.terminate();
141
+ };
146
142
 
147
143
  initialise(hostIn);
148
144
  };
@@ -14,73 +14,69 @@ const ThreeBSP = ThreeBSPWrapper(THREE);
14
14
  */
15
15
  const GlyphsetCSG = function (hostIn) {
16
16
  let host = undefined;
17
- if (hostIn && hostIn.isGlyphset)
18
- host = hostIn;
17
+ if (hostIn && hostIn.isGlyphset) host = hostIn;
19
18
  const hostCSGs = new Array();
20
19
  const currentIntersect = undefined;
21
20
 
22
- this.setGlyphset = hostIn => {
23
- if (hostIn && hostIn.isGlyphset)
24
- host = hostIn;
25
- hostCSG = undefined;
26
- }
21
+ this.setGlyphset = (hostIn) => {
22
+ if (hostIn && hostIn.isGlyphset) host = hostIn;
23
+ hostCSG = undefined;
24
+ };
27
25
 
28
26
  this.getGlyphset = () => {
29
- return host;
30
- }
27
+ return host;
28
+ };
31
29
 
32
30
  const prepareCSGForGlyphs = () => {
33
- return glyph => {
34
- const mesh = glyph.getMesh();
35
- const label = glyph.getLabel();
36
- if (mesh) {
37
- const csg = new ThreeBSP(mesh.geometry.clone().applyMatrix(mesh.matrix));
38
- const store = [];
39
- store.csg = csg;
40
- store.label = label;
41
- if (mesh.material)
42
- store.material = mesh.material.clone();
43
- hostCSGs.push(store);
44
- }
45
- };
31
+ return (glyph) => {
32
+ const mesh = glyph.getMesh();
33
+ const label = glyph.getLabel();
34
+ if (mesh) {
35
+ const csg = new ThreeBSP(mesh.geometry.clone().applyMatrix(mesh.matrix));
36
+ const store = [];
37
+ store.csg = csg;
38
+ store.label = label;
39
+ if (mesh.material) store.material = mesh.material.clone();
40
+ hostCSGs.push(store);
41
+ }
42
+ };
46
43
  };
47
44
 
48
- const prepareCSG = guestGeometry => {
49
- if (host && guestGeometry && guestGeometry.getMorph()) {
50
- if (hostCSGs.length == 0) {
51
- host.forEachGlyph(prepareCSGForGlyphs());
52
- }
53
- const guestCSG = new ThreeBSP(guestGeometry.getMorph());
54
- return guestCSG;
55
- }
56
- return undefined;
45
+ const prepareCSG = (guestGeometry) => {
46
+ if (host && guestGeometry && guestGeometry.getMorph()) {
47
+ if (hostCSGs.length == 0) {
48
+ host.forEachGlyph(prepareCSGForGlyphs());
49
+ }
50
+ const guestCSG = new ThreeBSP(guestGeometry.getMorph());
51
+ return guestCSG;
52
+ }
53
+ return undefined;
57
54
  };
58
55
 
59
- this.intersect = guestGeometry => {
60
- const guestCSG = prepareCSG(guestGeometry);
61
- if ((hostCSGs.length > 0) && guestCSG) {
62
- const glyphset = new Glyphset();
63
- for (let i = 0; i < hostCSGs.length; i++) {
64
- const hostCSG = hostCSGs[i];
65
- const intersect = hostCSG.csg.intersect(guestCSG);
66
- const mesh = intersect.toMesh();
67
- if (mesh && mesh.geometry && (mesh.geometry.vertices.length > 0)) {
68
- if (hostCSG.material) {
69
- mesh.material = hostCSG.material;
70
- mesh.material.side = THREE.DoubleSide;
71
- mesh.material.clippingPlanes = null;
72
- }
73
- const glyph = glyphset.addMeshAsGlyph(mesh, i+1);
74
- glyph.setLabel(hostCSG.label);
75
- }
76
- }
77
- const newCSG = new GlyphsetCSG(glyphset);
78
- return newCSG;
79
- }
80
-
81
- return undefined;
82
- }
56
+ this.intersect = (guestGeometry) => {
57
+ const guestCSG = prepareCSG(guestGeometry);
58
+ if (hostCSGs.length > 0 && guestCSG) {
59
+ const glyphset = new Glyphset();
60
+ for (let i = 0; i < hostCSGs.length; i++) {
61
+ const hostCSG = hostCSGs[i];
62
+ const intersect = hostCSG.csg.intersect(guestCSG);
63
+ const mesh = intersect.toMesh();
64
+ if (mesh && mesh.geometry && mesh.geometry.vertices.length > 0) {
65
+ if (hostCSG.material) {
66
+ mesh.material = hostCSG.material;
67
+ mesh.material.side = THREE.DoubleSide;
68
+ mesh.material.clippingPlanes = null;
69
+ }
70
+ const glyph = glyphset.addMeshAsGlyph(mesh, i + 1);
71
+ glyph.setLabel(hostCSG.label);
72
+ }
73
+ }
74
+ const newCSG = new GlyphsetCSG(glyphset);
75
+ return newCSG;
76
+ }
83
77
 
78
+ return undefined;
79
+ };
84
80
  };
85
81
 
86
82
  export { GlyphsetCSG };
@@ -5,7 +5,6 @@ import { Pointset } from '../primitives/pointset';
5
5
  import { applyMorphColorNode } from '../tsl/morphColorMaterial';
6
6
 
7
7
  const GLTFToZincJSLoader = function () {
8
-
9
8
  const _this = this;
10
9
 
11
10
  /*
@@ -40,7 +39,7 @@ const GLTFToZincJSLoader = function () {
40
39
  });
41
40
  }
42
41
  geometry.morphTargetsRelative = false;
43
- }
42
+ };
44
43
 
45
44
  /*
46
45
  * Zinc renders colour morphs with its own colorNode (see geometry.js and
@@ -54,32 +53,32 @@ const GLTFToZincJSLoader = function () {
54
53
  material.vertexColors = false;
55
54
  return applyMorphColorNode(material);
56
55
  };
57
- object.material = Array.isArray(object.material) ?
58
- object.material.map(setup) : setup(object.material);
59
- }
56
+ object.material = Array.isArray(object.material)
57
+ ? object.material.map(setup)
58
+ : setup(object.material);
59
+ };
60
60
 
61
61
  this.parseGLTFObjects = (object, region, depth, finishCallback) => {
62
62
  let childRegion = region;
63
63
  if (depth !== 0) {
64
- if (object.type === "Object3D") {
65
- if (object.name !== "") {
66
- if (region)
67
- childRegion = region.findOrCreateChildFromPath(object.name);
68
- if (childRegion) {
69
- const group = childRegion.getGroup();
70
- group.position.copy(object.position);
71
- group.rotation.copy(object.rotation);
72
- group.quaternion.copy(object.quaternion);
73
- group.matrixAutoUpdate = true;
74
- }
64
+ if (object.type === 'Object3D') {
65
+ if (object.name !== '') {
66
+ if (region) childRegion = region.findOrCreateChildFromPath(object.name);
67
+ if (childRegion) {
68
+ const group = childRegion.getGroup();
69
+ group.position.copy(object.position);
70
+ group.rotation.copy(object.rotation);
71
+ group.quaternion.copy(object.quaternion);
72
+ group.matrixAutoUpdate = true;
73
+ }
75
74
  }
76
75
  } else {
77
76
  let zincGeometry = undefined;
78
- if (object.type === "Mesh") {
77
+ if (object.type === 'Mesh') {
79
78
  zincGeometry = new Geometry();
80
- } else if (object.type === "LineSegments") {
79
+ } else if (object.type === 'LineSegments') {
81
80
  zincGeometry = new Lines();
82
- } else if (object.type === "Points") {
81
+ } else if (object.type === 'Points') {
83
82
  zincGeometry = new Pointset();
84
83
  }
85
84
  if (zincGeometry) {
@@ -91,31 +90,30 @@ const GLTFToZincJSLoader = function () {
91
90
  localMorphColour = object.geometry.morphAttributes.color ? true : false;
92
91
  }
93
92
  const mesh = object.clone();
94
- if (localMorphColour && !zincGeometry.isPointset)
95
- applyMorphColourMaterial(mesh);
93
+ if (localMorphColour && !zincGeometry.isPointset) applyMorphColourMaterial(mesh);
96
94
  zincGeometry.setMesh(mesh, localTimeEnabled, localMorphColour);
97
95
  const morph = zincGeometry.getMorph();
98
96
  zincGeometry.groupName = morph.name;
99
97
  morph.matrixAutoUpdate = true;
100
98
  region.addZincObject(zincGeometry);
101
- if (finishCallback != undefined && (typeof finishCallback == 'function'))
99
+ if (finishCallback != undefined && typeof finishCallback == 'function')
102
100
  finishCallback(zincGeometry);
103
101
  }
104
102
  }
105
103
  }
106
104
  depth++;
107
- object.children.forEach( child => {
105
+ object.children.forEach((child) => {
108
106
  _this.parseGLTFObjects(child, childRegion, depth, finishCallback);
109
107
  });
110
- }
108
+ };
111
109
 
112
- this.setCamera = scene => {
110
+ this.setCamera = (scene) => {
113
111
  scene.viewAll();
114
112
  const cameraControls = scene.getZincCameraControls();
115
113
  const viewport = cameraControls.getCurrentViewport();
116
114
  cameraControls.addViewport('default', viewport);
117
115
  cameraControls.setDefaultViewport('default');
118
- }
116
+ };
119
117
 
120
118
  /**
121
119
  * Load GLTF into this scene object.
@@ -127,19 +125,19 @@ const GLTFToZincJSLoader = function () {
127
125
  * load has been cancelled, the loaded content will be discarded.
128
126
  */
129
127
  this.load = (scene, region, url, finishCallback, allCompletedCallback, options, isCancelled) => {
130
- const path = url.substring(0, url.lastIndexOf("/") + 1);
131
- const filename = url.substring(url.lastIndexOf("/") + 1, url.length);
128
+ const path = url.substring(0, url.lastIndexOf('/') + 1);
129
+ const filename = url.substring(url.lastIndexOf('/') + 1, url.length);
132
130
  const loader = new GLTFLoader().setPath(path);
133
131
 
134
- loader.load( filename, function ( gltf ) {
132
+ loader.load(filename, function (gltf) {
135
133
  if (isCancelled && isCancelled()) return;
136
- console.log(gltf)
134
+ console.log(gltf);
137
135
  _this.parseGLTFObjects(gltf.scene, region, 0, finishCallback);
138
136
  _this.setCamera(scene);
139
- if (allCompletedCallback != undefined && (typeof allCompletedCallback == 'function'))
137
+ if (allCompletedCallback != undefined && typeof allCompletedCallback == 'function')
140
138
  allCompletedCallback();
141
139
  });
142
- }
143
- }
140
+ };
141
+ };
144
142
 
145
143
  export { GLTFToZincJSLoader };