zincjs 2.3.0 → 2.3.1-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zincjs",
3
- "version": "2.3.0",
3
+ "version": "2.3.1-beta.1",
4
4
  "description": "ZincJS (Web-based-Zinc-Visualisation)",
5
5
  "type": "module",
6
6
  "main": "build/zinc.js",
@@ -68,7 +68,7 @@
68
68
  "css-element-queries": "^1.2.2",
69
69
  "lodash": "^4.17.19",
70
70
  "nifti-reader-js": "0.8.0",
71
- "three": "^0.130.1",
71
+ "three": "^0.185.1",
72
72
  "three-spritetext": "1.6.2"
73
73
  }
74
74
  }
@@ -228,7 +228,7 @@ function getTransformationFromHeader(header, options) {
228
228
  }
229
229
 
230
230
  function createDataTexture(data, width, height, depth, isRGB) {
231
- const dataTexture = new THREE.DataTexture2DArray(
231
+ const dataTexture = new THREE.DataArrayTexture(
232
232
  data, width, height, depth);
233
233
  dataTexture.anisotropy = 4;
234
234
  if (!isRGB) {
package/src/minimap.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as THREE from 'three';
2
+ import { copyVector3sArray } from "./utilities";
2
3
 
3
4
  /**
4
5
  * This provide a full scale minimap. It will always
@@ -66,8 +67,7 @@ const Minimap = function (sceneIn) {
66
67
  let v3 = new THREE.Vector3(1, 1, target.z).unproject(targetScene.camera);
67
68
  let v4 = new THREE.Vector3(-1, 1, target.z).unproject(targetScene.camera);
68
69
  let array = [v1, v2, v3, v3, v4, v1];
69
- positionAttributes.copyVector3sArray(array);
70
- positionAttributes.needsUpdate = true;
70
+ copyVector3sArray(positionAttributes, array);
71
71
  }
72
72
 
73
73
  this.updateCamera = () => {
@@ -2,27 +2,44 @@
2
2
  /**
3
3
  * Provide additional shaders to render time dependent color.
4
4
  */
5
- const augmentMorphColor = function() {
6
- return function(shader) {
7
- shader.vertexShader = shader.vertexShader.replace(
8
- '#include <color_pars_vertex>',
9
- [
10
- 'varying vec3 vColor;',
11
- 'attribute vec3 morphColor0;',
12
- 'attribute vec3 morphColor1;'
13
- ].join( '\n' )
14
- );
15
- shader.vertexShader = shader.vertexShader.replace(
16
- '#include <color_vertex>',
17
- [
18
- 'vColor.xyz = color.xyz;',
19
- '#ifdef USE_MORPHTARGETS',
20
- 'vColor = morphColor0 * morphTargetInfluences[ 0 ];',
21
- 'vColor += morphColor1 * morphTargetInfluences[ 1 ];',
22
- '#endif'
23
- ].join( '\n' )
24
- );
25
- };
5
+
6
+ const augmentMorphColor = function(shader) {
7
+ shader.vertexShader = shader.vertexShader.replace(
8
+ '#include <morphcolor_vertex>',
9
+ `
10
+ #if defined( USE_MORPHCOLORS )
11
+
12
+ // morphTargetBaseInfluence is set based on BufferGeometry.morphTargetsRelative value:
13
+ // When morphTargetsRelative is false, this is set to 1 - sum(influences); this results in normal = sum((target - base) * influence)
14
+ // When morphTargetsRelative is true, this is set to 1; as a result, all morph targets are simply added to the base after weighting
15
+ vColor *= morphTargetBaseInfluence;
16
+
17
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
18
+
19
+ #if defined( USE_COLOR_ALPHA )
20
+
21
+ if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
22
+
23
+ #elif defined( USE_COLOR )
24
+
25
+ if ( morphTargetInfluences[ i ] != 0.0 ) {
26
+ vColor.rgb += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
27
+ vColor.a = 1.0;
28
+ }
29
+
30
+ #endif
31
+
32
+ }
33
+
34
+ #endif
35
+ `
36
+ );
26
37
  }
27
38
 
28
- export { augmentMorphColor };
39
+ const printShader = function (shader) {
40
+ console.log(shader.vertexShader);
41
+ console.log(shader.fragmentShader);
42
+ }
43
+
44
+
45
+ export { augmentMorphColor, printShader };
@@ -8,53 +8,36 @@ const createMeshForGeometry = (geometryIn, materialIn, options) => {
8
8
  let geometry = toBufferGeometry(geometryIn, options);
9
9
 
10
10
  let isTransparent = false;
11
- if (1.0 > options.opacity)
12
- isTransparent = true;
13
-
11
+ if (1.0 > options.opacity) {
12
+ isTransparent = true;
13
+ }
14
14
  let material = undefined;
15
15
  if (geometry._video === undefined) {
16
- const morphTargets = options.localTimeEnabled || options.localMorphColour;
17
16
  if (materialIn) {
18
17
  material = materialIn;
19
- material.morphTargets = morphTargets;
20
- material.morphNormals = options.localTimeEnabled;
21
18
  } else {
22
- if (geometry instanceof THREE.BufferGeometry && geometry.attributes.color === undefined) {
23
- material = new THREE.MeshPhongMaterial({
24
- color : options.colour,
25
- morphTargets : morphTargets,
26
- morphNormals : options.localTimeEnabled,
27
- transparent : isTransparent,
28
- opacity : options.opacity,
29
- side : THREE.DoubleSide
30
- });
31
- } else {
32
- material = new THREE.MeshPhongMaterial({
33
- color : options.colour,
34
- morphTargets : morphTargets,
35
- morphNormals : options.localTimeEnabled,
36
- vertexColors : THREE.VertexColors,
37
- transparent : isTransparent,
38
- opacity : options.opacity,
39
- side : THREE.DoubleSide
40
- });
41
- }
19
+ material = new THREE.MeshPhongMaterial({
20
+ color : options.colour,
21
+ vertexColors : false,
22
+ transparent : isTransparent,
23
+ opacity : options.opacity,
24
+ side : THREE.DoubleSide
25
+ });
42
26
  }
43
27
  //material = PhongToToon(material);
44
28
  if (options.localMorphColour && geometry.morphAttributes[ "color" ]) {
45
- material.onBeforeCompile = augmentMorphColor();
29
+ material.vertexColors = true;
30
+ material.onBeforeCompile = augmentMorphColor;
46
31
  }
47
32
  } else {
48
33
  let videoTexture = geometry._video.createCanvasVideoTexture();
49
34
  material = new THREE.MeshBasicMaterial({
50
- morphTargets : options.localTimeEnabled,
51
35
  color : new THREE.Color(1, 1, 1),
52
36
  transparent : isTransparent,
53
37
  opacity : options.opacity,
54
38
  map : videoTexture,
55
39
  side : THREE.DoubleSide
56
40
  });
57
- this.videoHandler = geometry._video;
58
41
  }
59
42
  return new THREE.Mesh(geometry, material);
60
43
  }
@@ -92,6 +75,7 @@ const Geometry = function () {
92
75
  if (this.morph && this.morph.geometry && (geometryIn != undefined))
93
76
  return;
94
77
  const mesh = createMeshForGeometry(geometryIn, materialIn, options);
78
+ this.videoHandler = mesh.geometry._video;
95
79
  this.setMesh(mesh, options.localTimeEnabled, options.localMorphColour);
96
80
  }
97
81
 
@@ -160,6 +144,17 @@ const Geometry = function () {
160
144
  }
161
145
  }
162
146
 
147
+ /**
148
+ * Check if the geometry is time varying.
149
+ *
150
+ * @return {Boolean}
151
+ */
152
+ this.isTimeVarying = function() {
153
+ if (this.timeEnabled || this.morphColour || this.videoHandler)
154
+ return true;
155
+ return false;
156
+ }
157
+
163
158
 
164
159
  }
165
160
 
@@ -295,6 +295,8 @@ const Glyphset = function () {
295
295
  }
296
296
  }
297
297
  this.morph.instanceMatrix.needsUpdate = true;
298
+ this.boundingBoxUpdateRequired = true;
299
+ this.morph.computeBoundingSphere();
298
300
  };
299
301
 
300
302
  /**
@@ -372,7 +374,6 @@ const Glyphset = function () {
372
374
  }
373
375
  updateGlyphsetTransformation(current_positions, current_axis1s, current_axis2s, current_axis3s,
374
376
  current_scales);
375
- this.boundingBoxUpdateRequired = true;
376
377
  if (colors != undefined) {
377
378
  if (morphColours) {
378
379
  const bottom_colors = colors[bottom_frame.toString()];
@@ -472,7 +473,6 @@ const Glyphset = function () {
472
473
  updateGlyphsetHexColors(colors["0"]);
473
474
  }
474
475
  this.ready = true;
475
- this.boundingBoxUpdateRequired = true;
476
476
  };
477
477
 
478
478
  /**
@@ -31,8 +31,10 @@ const Lines = function () {
31
31
  this.createLineSegment = (geometryIn, materialIn, options) => {
32
32
  if (geometryIn && materialIn) {
33
33
  let geometry = toBufferGeometry(geometryIn, options);
34
- if (options.localMorphColour && geometry.morphAttributes[ "color" ])
35
- materialIn.onBeforeCompile = augmentMorphColor();
34
+ if (options.localMorphColour && geometry.morphAttributes[ "color" ]) {
35
+ materialIn.vertexColors = true;
36
+ materialIn.onBeforeCompile = augmentMorphColor;
37
+ }
36
38
  let line = new LineSegments(geometry, materialIn);
37
39
  this.setMesh(line, options.localTimeEnabled, options.localMorphColour);
38
40
  }
@@ -3,11 +3,9 @@ import myImage from '../assets/mapMarker.svg';
3
3
  import { createNewSpriteText } from '../utilities';
4
4
  import { ZincObject } from './zincObject';
5
5
 
6
- const markerImage = new Image(128, 128);
7
- markerImage.src = myImage;
8
- const texture = new THREE.Texture();
9
- texture.image = markerImage;
10
- texture.needsUpdate = true;
6
+ const textureLoader = new THREE.TextureLoader();
7
+ const texture = textureLoader.load(myImage);
8
+ texture.colorSpace = THREE.SRGBColorSpace;
11
9
  const size = [0.02, 0.03, 1];
12
10
  const spriteMaterial = new THREE.SpriteMaterial({
13
11
  map: texture,
@@ -197,6 +195,7 @@ const Marker = function(zincObject) {
197
195
  }
198
196
  if (!label && numberIn) {
199
197
  label = createNewSpriteText(numberIn, 0.012, "black", "Asap", 120, 700);
198
+ label.renderOrder = 10001;
200
199
  this.morph.add(label);
201
200
  }
202
201
  number = numberIn;
@@ -1,11 +1,11 @@
1
1
  import * as THREE from 'three';
2
2
  import { ZincObject } from './zincObject';
3
- const markerImage = new Image(128, 128);
4
3
  import mapMarkerOrange from '../assets/mapMarkerOrange.svg';
5
- markerImage.src = mapMarkerOrange;
6
- const texture = new THREE.Texture();
7
- texture.image = markerImage;
8
- texture.needsUpdate = true;
4
+ import { createNewSpriteText } from '../utilities';
5
+
6
+ const textureLoader = new THREE.TextureLoader();
7
+ const texture = textureLoader.load(mapMarkerOrange);
8
+ texture.colorSpace = THREE.SRGBColorSpace;
9
9
  const size = [0.02, 0.03, 1];
10
10
  const spriteMaterial = new THREE.SpriteMaterial({
11
11
  map: texture,
@@ -15,7 +15,6 @@ const spriteMaterial = new THREE.SpriteMaterial({
15
15
  depthWrite: false,
16
16
  sizeAttenuation: false
17
17
  });
18
- import { createNewSpriteText } from '../utilities';
19
18
 
20
19
  /**
21
20
  * A special graphics type with a tear drop shape.
@@ -46,9 +45,9 @@ const MarkerCluster = function(sceneIn) {
46
45
  *
47
46
  * @param {Number} size - size to be set.
48
47
  */
49
- this.setSpriteSize = size => {
48
+ this.setSpriteSize = sizeIn => {
50
49
  sprite.scale.set(0.015, 0.02, 1);
51
- sprite.scale.multiplyScalar(size);
50
+ sprite.scale.multiplyScalar(sizeIn);
52
51
  }
53
52
 
54
53
  this.clear = () => {
@@ -101,6 +100,7 @@ const MarkerCluster = function(sceneIn) {
101
100
  sprite.label.material.dispose();
102
101
  }
103
102
  sprite.label = createNewSpriteText(number, 0.012, "black", "Asap", 120, 700);
103
+ sprite.label.renderOrder = 10001;
104
104
  sprite.number = number;
105
105
  sprite.group.add(sprite.label);
106
106
  }
@@ -3,6 +3,7 @@ import { Label } from './label';
3
3
  import { Points } from '../three/Points';
4
4
  import { ZincObject } from './zincObject';
5
5
  import { getCircularTexture, toBufferGeometry } from '../utilities';
6
+ import { augmentMorphColor } from './augmentShader';
6
7
 
7
8
  /**
8
9
  * Provides an object which stores points and provides method which controls its position.
@@ -36,11 +37,15 @@ const Pointset = function () {
36
37
  this.createMesh = (geometryIn, materialIn, options) => {
37
38
  if (geometryIn && materialIn) {
38
39
  let geometry = toBufferGeometry(geometryIn, options);
40
+ console.log(geometry, options)
41
+ if (options.localMorphColour && geometry.morphAttributes[ "color" ]) {
42
+ materialIn.vertexColors = true;
43
+ materialIn.onBeforeCompile = augmentMorphColor;
44
+ }
39
45
  const texture = getCircularTexture();
40
46
  materialIn.map = texture;
41
47
  let point = new Points(geometry, materialIn);
42
- this.setMesh(point, options.localTimeEnabled,
43
- options.localMorphColour);
48
+ this.setMesh(point, options.localTimeEnabled, options.localMorphColour);
44
49
  }
45
50
  }
46
51
 
@@ -45,7 +45,6 @@ const ZincObject = function() {
45
45
  this.duration = 6000;
46
46
  this.clipAction = undefined;
47
47
  this.userData = {};
48
- this.videoHandler = undefined;
49
48
  this.marker = undefined;
50
49
  this.markerNumber = undefined;
51
50
  this.markerUpdateRequired = true;
package/src/region.js CHANGED
@@ -816,8 +816,6 @@ let Region = function (parentIn, sceneIn) {
816
816
  const zincGeometry = new Geometry();
817
817
  const material = new THREE.MeshPhongMaterial({
818
818
  color : colour,
819
- morphTargets : false,
820
- morphNormals : false,
821
819
  transparent : true,
822
820
  opacity : opacity,
823
821
  side : THREE.DoubleSide
package/src/renderer.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as THREE from 'three';
2
+ //import { WebGPURenderer } from 'three/webgpu';
2
3
  import { ResizeSensor } from 'css-element-queries';
3
4
  import { Scene } from './scene';
4
5
  /**
@@ -130,7 +131,11 @@ const Renderer = function (containerIn) {
130
131
  container = undefined;
131
132
  canvas = parameters["canvas"];
132
133
  }
133
- renderer = new THREE.WebGLRenderer(parameters);
134
+ //parameters["forceWebGL"] = true;
135
+ //renderer = new WebGPURenderer(parameters);
136
+ //await renderer.init();
137
+
138
+ renderer = new THREE.WebGLRenderer(parameters);
134
139
  if (container !== undefined) {
135
140
  container.appendChild( renderer.domElement );
136
141
  }
package/src/scene.js CHANGED
@@ -157,7 +157,7 @@ const Scene = function (containerIn, rendererIn) {
157
157
  this.ambient = new THREE.AmbientLight(0xffffff, 0.2);
158
158
  scene.add(this.ambient);
159
159
 
160
- this.directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
160
+ this.directionalLight = new THREE.DirectionalLight(0xffffff, 0.7 * Math.PI);
161
161
  scene.add(this.directionalLight);
162
162
  zincCameraControls = new CameraControls(this.camera, rendererIn.domElement, rendererIn, this);
163
163
 
@@ -625,8 +625,6 @@ const Scene = function (containerIn, rendererIn) {
625
625
  zincCameraControls.update(0);
626
626
  }
627
627
  //console.log(videoHandler.video.currentTime / videoHandler.getVideoDuration() * 6000);
628
- } else {
629
- myPlayRate = 0;
630
628
  }
631
629
  } else {
632
630
  if (0 == sceneLoader.toBeDownloaded) {
@@ -158,7 +158,7 @@ const SceneLoader = function (sceneIn) {
158
158
  let localTimeEnabled = 0;
159
159
  if (timeEnabled != undefined && timeEnabled[i] != undefined)
160
160
  localTimeEnabled = timeEnabled[i] ? true : false;
161
- let localMorphColour = 0;
161
+ let localMorphColour = false;
162
162
  if (morphColour != undefined && morphColour[i] != undefined)
163
163
  localMorphColour = morphColour[i] ? true : false;
164
164
  primitivesLoader.load(filename, meshloader(region, colour, opacity, localTimeEnabled, localMorphColour, undefined, undefined,
@@ -218,7 +218,6 @@ const SceneLoader = function (sceneIn) {
218
218
  material.transparent = true;
219
219
  }
220
220
  material.opacity = materials[0].opacity;
221
- material.morphTargets = localTimeEnabled;
222
221
  material.vertexColors = materials[0].vertexColors;
223
222
  }
224
223
  let options = {};
@@ -361,15 +360,19 @@ const SceneLoader = function (sceneIn) {
361
360
  const pointsetloader = (region, localTimeEnabled, localMorphColour, groupName, anatomicalId, renderOrder, finishCallback) => {
362
361
  return (geometry, materials) => {
363
362
  const newPointset = new Pointset();
364
- let material = new THREE.PointsMaterial({ alphaTest: 0.5, size: 10, sizeAttenuation: false });
363
+ let material = new THREE.PointsMaterial(
364
+ {
365
+ alphaTest: 0.05,
366
+ size: 10,
367
+ sizeAttenuation: false,
368
+ });
365
369
  if (materials && materials[0]) {
366
370
  if (1.0 > materials[0].opacity) {
367
371
  material.transparent = true;
368
372
  }
369
373
  material.opacity = materials[0].opacity;
370
374
  material.color = materials[0].color;
371
- material.morphTargets = localTimeEnabled;
372
- material.vertexColors = materials[0].vertexColors;
375
+ material.vertexColors = false;
373
376
  }
374
377
  let options = {};
375
378
  options.localTimeEnabled = localTimeEnabled;
@@ -638,8 +641,9 @@ const SceneLoader = function (sceneIn) {
638
641
  newGeometry.setDuration(scene.getDuration());
639
642
  if (finishCallback != undefined && (typeof finishCallback == 'function'))
640
643
  finishCallback(newGeometry);
641
- if (newGeometry.videoHandler)
644
+ if (newGeometry.videoHandler) {
642
645
  scene.setVideoHandler(newGeometry.videoHandler);
646
+ }
643
647
  return newGeometry;
644
648
  }
645
649
  return undefined;
@@ -48,7 +48,7 @@ const TextureArray = function () {
48
48
  length += data.length;
49
49
  });
50
50
 
51
- this.impl = new THREE.DataTexture2DArray(fullArray, w, h, d);
51
+ this.impl = new THREE.DataArrayTexture(fullArray, w, h, d);
52
52
  this.size = {
53
53
  width: w,
54
54
  height: h,