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
@@ -9,94 +9,87 @@ import * as THREE from 'three/webgpu';
9
9
  * @author Alan Wu
10
10
  * @return {VideoHandler}
11
11
  */
12
- const VideoHandler = function(srcIn) {
13
-
14
- var _this = this;
15
- this.video = undefined;
16
- this.videoTexture = undefined;
17
- var src = srcIn;
18
- var lastTime = 0;
19
- var lastUpdate = 0;
20
- var frameRate = 30;
21
- var videoPlaneLoadedFlag = false;
22
- var lastPlayPos = 0;
23
- var currentPlayPos = 0;
24
- var bufferingDetected = false;
25
-
26
- var checkBuffering = function(delta, playAnimation) {
27
- currentPlayPos = _this.video.currentTime;
28
-
29
- // checking offset should be at most the check interval
30
- // but allow for some margin
31
- var offset = delta - 0.02;
32
-
33
- // if no buffering is currently detected,
34
- // and the position does not seem to increase
35
- // and the _this.video isn't manually paused...
36
- if (!bufferingDetected && (currentPlayPos < (lastPlayPos + offset)) &&
37
- !_this.video.paused) {
38
- bufferingDetected = true;
39
- }
40
-
41
- // if we were buffering but the _this.video has advanced,
42
- // then there is no buffering
43
- if (bufferingDetected && (currentPlayPos > (lastPlayPos + offset)) &&
44
- !_this.video.paused) {
45
- bufferingDetected = false;
46
- }
47
- lastPlayPos = currentPlayPos;
48
- }
49
-
50
- var initialise = function(){
51
- if (document) {
52
- _this.video = document.createElement( 'video' );
53
- _this.video.crossOrigin = "anonymous";
54
- _this.video.src = src;
55
- _this.video.load();
56
- _this.video.loop = true;
12
+ const VideoHandler = function (srcIn) {
13
+ var _this = this;
14
+ this.video = undefined;
15
+ this.videoTexture = undefined;
16
+ var src = srcIn;
17
+ var lastTime = 0;
18
+ var lastUpdate = 0;
19
+ var frameRate = 30;
20
+ var videoPlaneLoadedFlag = false;
21
+ var lastPlayPos = 0;
22
+ var currentPlayPos = 0;
23
+ var bufferingDetected = false;
24
+
25
+ var checkBuffering = function (delta, playAnimation) {
26
+ currentPlayPos = _this.video.currentTime;
27
+
28
+ // checking offset should be at most the check interval
29
+ // but allow for some margin
30
+ var offset = delta - 0.02;
31
+
32
+ // if no buffering is currently detected,
33
+ // and the position does not seem to increase
34
+ // and the _this.video isn't manually paused...
35
+ if (!bufferingDetected && currentPlayPos < lastPlayPos + offset && !_this.video.paused) {
36
+ bufferingDetected = true;
37
+ }
57
38
 
58
- }
59
- }
39
+ // if we were buffering but the _this.video has advanced,
40
+ // then there is no buffering
41
+ if (bufferingDetected && currentPlayPos > lastPlayPos + offset && !_this.video.paused) {
42
+ bufferingDetected = false;
43
+ }
44
+ lastPlayPos = currentPlayPos;
45
+ };
46
+
47
+ var initialise = function () {
48
+ if (document) {
49
+ _this.video = document.createElement('video');
50
+ _this.video.crossOrigin = 'anonymous';
51
+ _this.video.src = src;
52
+ _this.video.load();
53
+ _this.video.loop = true;
54
+ }
55
+ };
60
56
 
61
- this.setMorphTime = function(time, duration){
62
- let actualTime = time / duration * _this.video.duration;
57
+ this.setMorphTime = function (time, duration) {
58
+ let actualTime = (time / duration) * _this.video.duration;
63
59
  if (!Number.isFinite(actualTime)) {
64
60
  actualTime = 0.0;
65
61
  }
66
- _this.video.currentTime = actualTime;
67
- }
68
-
69
- // videoPlaneLoaded connects the video to the video texture once it has loaded
70
- this.getVideoDuration = function() {
71
- return _this.video.duration;
72
- }
73
-
74
- this.createCanvasVideoTexture = function(){
75
- _this.videoTexture = new THREE.VideoTexture( _this.video );
76
- _this.videoTexture.minFilter = THREE.LinearFilter;
77
- _this.videoTexture.magFilter = THREE.LinearFilter;
62
+ _this.video.currentTime = actualTime;
63
+ };
64
+
65
+ // videoPlaneLoaded connects the video to the video texture once it has loaded
66
+ this.getVideoDuration = function () {
67
+ return _this.video.duration;
68
+ };
69
+
70
+ this.createCanvasVideoTexture = function () {
71
+ _this.videoTexture = new THREE.VideoTexture(_this.video);
72
+ _this.videoTexture.minFilter = THREE.LinearFilter;
73
+ _this.videoTexture.magFilter = THREE.LinearFilter;
78
74
  _this.video.currentTime = 0;
79
- return _this.videoTexture;
80
- }
81
-
82
- this.getCurrentTime = function(duration) {
83
- if (_this.video)
84
- return duration * (_this.video.currentTime / _this.video.duration);
85
- else
86
- return 0;
87
- }
88
-
89
- this.isReadyToPlay = function(){
90
- // video.readyState 3 means we have data to load for the current time and foreseeable future
91
- if (_this.video && _this.video.readyState >= 3){
92
- return true;
93
- }
94
- return false;
95
- }
96
-
97
- //this should be handle by scene... check the sync at
98
- initialise();
75
+ return _this.videoTexture;
76
+ };
77
+
78
+ this.getCurrentTime = function (duration) {
79
+ if (_this.video) return duration * (_this.video.currentTime / _this.video.duration);
80
+ else return 0;
81
+ };
82
+
83
+ this.isReadyToPlay = function () {
84
+ // video.readyState 3 means we have data to load for the current time and foreseeable future
85
+ if (_this.video && _this.video.readyState >= 3) {
86
+ return true;
87
+ }
88
+ return false;
89
+ };
99
90
 
100
- }
91
+ //this should be handle by scene... check the sync at
92
+ initialise();
93
+ };
101
94
 
102
- export { VideoHandler }
95
+ export { VideoHandler };
@@ -1,4 +1,3 @@
1
-
2
1
  import { Geometry } from '../primitives/geometry';
3
2
  import { GeometryCSGInternal } from './geometryCSGInternal';
4
3
  import * as THREE from 'three/webgpu';
@@ -6,7 +5,7 @@ import * as THREE from 'three/webgpu';
6
5
  const JSONLoader = THREE.BufferGeometryLoader;
7
6
  let core = undefined;
8
7
 
9
- var geometryFromJSON = function(object) {
8
+ var geometryFromJSON = function (object) {
10
9
  var JSONParser = new JSONLoader();
11
10
  var geometry = JSONParser.parse(object);
12
11
  var material = new THREE.MeshPhongMaterial();
@@ -14,61 +13,59 @@ var geometryFromJSON = function(object) {
14
13
  var host = new Geometry();
15
14
  host.setMorph(mesh);
16
15
  return host;
17
- }
16
+ };
18
17
 
19
- var initialise = function(object) {
18
+ var initialise = function (object) {
20
19
  var host = geometryFromJSON(object);
21
20
  core = new GeometryCSGInternal(host);
22
- self.postMessage({action:"message", message: "Initialised"});
23
- }
21
+ self.postMessage({ action: 'message', message: 'Initialised' });
22
+ };
24
23
 
25
- var intersect = function(object) {
24
+ var intersect = function (object) {
26
25
  if (core) {
27
26
  var guest = geometryFromJSON(object);
28
27
  var result = core.intersect(guest);
29
28
  var json = result.toBufferGeometry().toJSON();
30
- self.postMessage({action: "result", object: json});
29
+ self.postMessage({ action: 'result', object: json });
31
30
  }
32
- }
31
+ };
33
32
 
34
- var subtract = function(object) {
33
+ var subtract = function (object) {
35
34
  if (core) {
36
35
  var guest = geometryFromJSON(object);
37
36
  var result = core.subtract(guest);
38
37
  var json = result.toBufferGeometry().toJSON();
39
- self.postMessage({action: "result", object: json});
38
+ self.postMessage({ action: 'result', object: json });
40
39
  }
41
- }
40
+ };
42
41
 
43
- var union = function(object) {
42
+ var union = function (object) {
44
43
  if (core) {
45
44
  var guest = geometryFromJSON(object);
46
45
  var result = core.union(guest);
47
46
  var json = result.toBufferGeometry().toJSON();
48
- self.postMessage({action: "result", object: json});
47
+ self.postMessage({ action: 'result', object: json });
49
48
  }
50
- }
49
+ };
51
50
 
52
- self.addEventListener('message',function (ev){
53
- switch (ev.data.action) {
54
- case 'initialise':
55
- initialise(ev.data.object);
56
- break;
57
- case 'intersect':
58
- intersect(ev.data.object);
59
- break;
60
- case 'subtract':
61
- subtract(ev.data.object);
62
- break;
63
- case 'union':
64
- union(ev.data.object);
65
- break;
66
- default:
67
- throw 'Cannot handle specified action.';
68
- }
51
+ self.addEventListener('message', function (ev) {
52
+ switch (ev.data.action) {
53
+ case 'initialise':
54
+ initialise(ev.data.object);
55
+ break;
56
+ case 'intersect':
57
+ intersect(ev.data.object);
58
+ break;
59
+ case 'subtract':
60
+ subtract(ev.data.object);
61
+ break;
62
+ case 'union':
63
+ union(ev.data.object);
64
+ break;
65
+ default:
66
+ throw 'Cannot handle specified action.';
67
+ }
69
68
  });
70
69
 
71
- //var test = ev.data;
72
- //self.postMessage(test, [test]);
73
-
74
-
70
+ //var test = ev.data;
71
+ //self.postMessage(test, [test]);
@@ -2,58 +2,53 @@ import * as THREE from 'three/webgpu';
2
2
  import { ThreeBSPWrapper } from '../three-js-csg';
3
3
  const ThreeBSP = ThreeBSPWrapper(THREE);
4
4
 
5
-
6
5
  const GeometryCSGInternal = function (hostIn) {
7
6
  //ZincGeoemtry of the main geometry
8
7
  let host = undefined;
9
- if (hostIn && hostIn.isGeometry)
10
- host = hostIn;
8
+ if (hostIn && hostIn.isGeometry) host = hostIn;
11
9
  let hostCSG = undefined;
12
10
 
13
- this.setGeometry = hostIn => {
14
- if (hostIn && hostIn.isGeometry)
15
- host = hostIn;
11
+ this.setGeometry = (hostIn) => {
12
+ if (hostIn && hostIn.isGeometry) host = hostIn;
16
13
  hostCSG = undefined;
17
- }
18
-
19
- this.setCSG = csg => {
20
- hostCSG = csg;
21
- }
22
-
23
- const prepareCSG = guestGeometry => {
24
- if (host && host.morph && guestGeometry && guestGeometry.morph) {
25
- if (hostCSG === undefined)
26
- hostCSG = new ThreeBSP(host.morph);
27
- const guestCSG = new ThreeBSP(guestGeometry.morph);
28
- return guestCSG;
29
- }
30
- return undefined;
31
14
  };
32
15
 
33
- this.intersect = guestGeometry => {
34
- const guestCSG = prepareCSG(guestGeometry);
35
- if (hostCSG && guestCSG) {
36
- return hostCSG.intersect(guestCSG);
37
- }
38
- return undefined;
39
- }
40
-
41
- this.subtract = guestGeometry => {
42
- const guestCSG = prepareCSG(guestGeometry);
43
- if (hostCSG && guestCSG) {
44
- return hostCSG.subtract(guestCSG);
45
- }
46
- return undefined;
47
- }
48
-
49
- this.union = guestGeometry => {
50
- const guestCSG = prepareCSG(guestGeometry);
51
- if (hostCSG && guestCSG) {
52
- return hostCSG.union(guestCSG);
53
- }
54
- return undefined;
55
- }
16
+ this.setCSG = (csg) => {
17
+ hostCSG = csg;
18
+ };
19
+
20
+ const prepareCSG = (guestGeometry) => {
21
+ if (host && host.morph && guestGeometry && guestGeometry.morph) {
22
+ if (hostCSG === undefined) hostCSG = new ThreeBSP(host.morph);
23
+ const guestCSG = new ThreeBSP(guestGeometry.morph);
24
+ return guestCSG;
25
+ }
26
+ return undefined;
27
+ };
28
+
29
+ this.intersect = (guestGeometry) => {
30
+ const guestCSG = prepareCSG(guestGeometry);
31
+ if (hostCSG && guestCSG) {
32
+ return hostCSG.intersect(guestCSG);
33
+ }
34
+ return undefined;
35
+ };
36
+
37
+ this.subtract = (guestGeometry) => {
38
+ const guestCSG = prepareCSG(guestGeometry);
39
+ if (hostCSG && guestCSG) {
40
+ return hostCSG.subtract(guestCSG);
41
+ }
42
+ return undefined;
43
+ };
44
+
45
+ this.union = (guestGeometry) => {
46
+ const guestCSG = prepareCSG(guestGeometry);
47
+ if (hostCSG && guestCSG) {
48
+ return hostCSG.union(guestCSG);
49
+ }
50
+ return undefined;
51
+ };
56
52
  };
57
53
 
58
54
  export { GeometryCSGInternal };
59
-
package/src/zinc.js CHANGED
@@ -12,10 +12,7 @@ import { TextureArray } from './texture/textureArray';
12
12
  import { TextureSlides } from './primitives/textureSlides';
13
13
  import { Renderer } from './renderer';
14
14
  import { Scene } from './scene';
15
- import {
16
- createPrimitivesFromNIFTI,
17
- createTextureFromNIFTI
18
- } from './loaders/niftiReader';
15
+ import { createPrimitivesFromNIFTI, createTextureFromNIFTI } from './loaders/niftiReader';
19
16
  //import { GeometryCSG } from './geometryCSG';
20
17
  //import { GlyphsetCSG } from './glyphsetCSG';
21
18
  import {
@@ -24,7 +21,7 @@ import {
24
21
  SmoothCameraTransition,
25
22
  RayCaster,
26
23
  CameraAutoTumble,
27
- StereoEffect
24
+ StereoEffect,
28
25
  } from './controls';
29
26
  import { loadExternalFile, loadExternalFiles } from './utilities';
30
27
 
@@ -36,9 +33,9 @@ const version = PACKAGE.version;
36
33
  * @namespace
37
34
  * @author Alan Wu
38
35
  */
39
- const Zinc = function() {
36
+ const Zinc = function () {
40
37
  this.Revision = version;
41
- this.defaultMaterialColor = 0xFFFFFF;
38
+ this.defaultMaterialColor = 0xffffff;
42
39
  this.defaultOpacity = 1.0;
43
40
  // Assign hoisted modules to the instance
44
41
  this.Geometry = Geometry;
package/vite.config.js CHANGED
@@ -14,24 +14,24 @@ export default defineConfig({
14
14
  },
15
15
  rollupOptions: {
16
16
  external(id) {
17
- if (id.includes("nifti-reader-js")) {
18
- return false
17
+ if (id.includes('nifti-reader-js')) {
18
+ return false;
19
19
  }
20
- return !id.startsWith('.') && !path.isAbsolute(id) && !id.includes('package.json')
20
+ return !id.startsWith('.') && !path.isAbsolute(id) && !id.includes('package.json');
21
21
  },
22
22
  output: {
23
23
  extend: true,
24
24
  globals: {
25
25
  'css-element-queries': 'cssElememtQueries',
26
- 'three': 'THREE',
26
+ three: 'THREE',
27
27
  'three/tsl': 'THREE',
28
28
  'three/webgpu': 'THREE',
29
29
  'three-spritetext': 'SpriteText',
30
30
  'three/examples/jsm/exporters/GLTFExporter': 'GLTFExporter',
31
31
  'three/examples/jsm/loaders/GLTFLoader': 'GLTFLoader',
32
- 'fflate': 'fflate'
33
- }
34
- }
32
+ fflate: 'fflate',
33
+ },
34
+ },
35
35
  },
36
36
  assetsInlineLimit: 8192,
37
37
  },