zincjs 1.2.0 → 1.3.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": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "ZincJS (Web-based-Zinc-Visualisation)",
5
5
  "main": "build/zinc.js",
6
6
  "directories": {
@@ -60,7 +60,7 @@
60
60
  "lodash": "^4.17.19",
61
61
  "promise-polyfill": "^8.1.3",
62
62
  "three": "^0.130.1",
63
- "three-spritetext": "^1.6.2",
63
+ "three-spritetext": "1.6.2",
64
64
  "url-loader": "^2.1.0",
65
65
  "url-polyfill": "^1.1.7",
66
66
  "webworkify-webpack": "^2.1.5"
@@ -4,7 +4,7 @@
4
4
  <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
5
  viewBox="0 0 365 560" enable-background="new 0 0 365 560" xml:space="preserve">
6
6
  <g>
7
- <path fill="#00AEEF" d="M182.9,551.7c0,0.1,0.2,0.3,0.2,0.3S358.3,283,358.3,194.6c0-130.1-88.8-186.7-175.4-186.9
7
+ <path fill="#005974" d="M182.9,551.7c0,0.1,0.2,0.3,0.2,0.3S358.3,283,358.3,194.6c0-130.1-88.8-186.7-175.4-186.9
8
8
  C96.3,7.9,7.5,64.5,7.5,194.6c0,88.4,175.3,357.4,175.3,357.4S182.9,551.7,182.9,551.7z M122.2,187.2c0-33.6,27.2-60.8,60.8-60.8
9
9
  c33.6,0,60.8,27.2,60.8,60.8S216.5,248,182.9,248C149.4,248,122.2,220.8,122.2,187.2z"/>
10
10
  </g>
package/src/controls.js CHANGED
@@ -1594,7 +1594,7 @@ const CameraAutoTumble = function (tumbleDirectionIn, tumbleRateIn, stopOnCamera
1594
1594
  /**
1595
1595
  * @author mrdoob / http://mrdoob.com/
1596
1596
  */
1597
- StereoCameraZoomFixed = function () {
1597
+ const StereoCameraZoomFixed = function () {
1598
1598
 
1599
1599
  this.type = 'StereoCamera';
1600
1600
 
@@ -1732,7 +1732,7 @@ const StereoEffect = function ( renderer ) {
1732
1732
  * W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
1733
1733
  */
1734
1734
 
1735
- ModifiedDeviceOrientationControls = function ( object ) {
1735
+ const ModifiedDeviceOrientationControls = function ( object ) {
1736
1736
 
1737
1737
  const scope = this;
1738
1738
 
@@ -91,13 +91,14 @@ const Marker = function(zincObject) {
91
91
  */
92
92
  this.dispose = () => {
93
93
  if (this.morph) {
94
- this.morph.dispose();
94
+ this.morph.clear();
95
95
  }
96
96
  if (spriteMaterial) {
97
97
  spriteMaterial.dispose();
98
98
  }
99
99
  if (sprite) {
100
- sprite.dispose();
100
+ sprite.clear();
101
+ sprite = undefined;
101
102
  }
102
103
  }
103
104
 
@@ -14,61 +14,125 @@ const shader = require("../shaders/textureSlide.js");
14
14
  const TextureSlides = function (textureIn) {
15
15
  (require('./texturePrimitive').TexturePrimitive).call(this, textureIn);
16
16
  this.isTextureSlides = true;
17
-
17
+ const textureSettings = [];
18
+ const idTextureMap = {};
19
+ this.morph = new THREE.Group();
20
+ this.morph.userData = this;
21
+ const alpha = 1.0;
22
+
18
23
  /**
19
24
  @typedef SLIDE_SETTINGS
20
25
  @type {Set}
21
26
  @property {String} direction - the value must be x, y or z, specify the
22
27
  direction the slide should be facing.
23
28
  @property {Number} value - Normalised value of the location on direction.
29
+ @property {String} id - ID of the mesh, it is only available if the settings
30
+ is returned from {@link TextureSlides.createSlide} or
31
+ {@link TextureSlides.getTextureSettings}.
24
32
  */
25
33
  /**
26
34
  * Create the slides required for visualisation based on the slide settings.
27
- * The slides itself is an {THREE.PlanGeometry} object.
35
+ * The slides themselves are {THREE.PlanGeometry} objects.
28
36
  *
29
37
  * @param {SLIDE_SETTINGS} slideSettings - An array to each slide settings.
30
38
  */
31
39
  this.createSlides = slideSettings => {
32
- if (!this.morph) this.morph = new THREE.Group();
40
+ slideSettings.forEach(slide => this.createSlide(slide));
41
+ }
42
+
43
+ /**
44
+ * Set the value of the uniforms for a specific mesh in this
45
+ * texture slide object.
46
+ *
47
+ * @param {THREE.Mesh} mesh - Mesh to be modified
48
+ * @param {SLIDE_SETTINGS} slideSettings - Slide settings.
49
+ */
50
+ setUniformSlideSettingsOfMesh = (mesh, settings) => {
51
+ const material = mesh.material;
52
+ const uniforms = material.uniforms;
53
+ switch (settings.direction) {
54
+ case "x":
55
+ uniforms.direction.value = 1;
56
+ uniforms.slide.value.set(settings.value, 0, 0);
57
+ break;
58
+ case "y":
59
+ uniforms.direction.value = 2;
60
+ uniforms.slide.value.set(0, settings.value, 0);
61
+ break;
62
+ case "z":
63
+ uniforms.direction.value = 3;
64
+ uniforms.slide.value.set(0, 0, settings.value);
65
+ break;
66
+ default:
67
+ break;
68
+ }
69
+ material.needsUpdate = true;
70
+ this.boundingBoxUpdateRequired = true;
71
+ }
72
+
73
+ /**
74
+ * Modify the mesh based on a setting
75
+ *
76
+ * @param {SLIDE_SETTINGS} settings - s.
77
+ */
78
+ this.modifySlideSettings = (settings) => {
79
+ if (settings && settings.id &&
80
+ settings.id in idTextureMap &&
81
+ idTextureMap[settings.id]) {
82
+ setUniformSlideSettingsOfMesh(idTextureMap[settings.id], settings);
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Create a slide required for visualisation based on the slide settings.
88
+ * The slide itself is an {THREE.PlanGeometry} object.
89
+ *
90
+ * @param {SLIDE_SETTINGS} settings -settings of the slide to be created.
91
+ * @return {SLIDE_SETTINGS} - Returned settings, it includes the newly
92
+ * created mesh's id.
93
+ */
94
+ this.createSlide = settings => {
33
95
  if (this.texture && this.texture.isTextureArray && this.texture.isReady()) {
34
- slideSettings.forEach(slide => {
35
- if (slide.direction && slide.value) {
36
- const geometry = new THREE.PlaneGeometry( 1, 1 );
37
- geometry.translate(0.5, 0.5, 0);
38
- const uniforms = shader.getUniforms();
39
- uniforms.diffuse.value = this.texture.impl;
40
- uniforms.depth.value = this.texture.size.depth;
41
- switch(slide.direction) {
42
- case "x":
43
- uniforms.slide.value.set(slide.value, 0, 0);
44
- break;
45
- case "y":
46
- uniforms.slide.value.set(0, slide.value, 0);
47
- break;
48
- case "z":
49
- uniforms.slide.value.set(0, 0, slide.value);
50
- break;
51
- default:
52
- break;
53
- }
54
- const options = {
55
- fs: shader.fs,
56
- vs: shader.vs,
57
- uniforms: uniforms,
58
- glslVersion: shader.glslVersion,
59
- side: THREE.DoubleSide,
60
- transparent: false
61
- };
62
- const material = this.texture.getMaterial(options);
63
- material.needsUpdate = true;
64
- const mesh = new THREE.Mesh( geometry, material );
65
- this.morph.add(mesh);
66
- }
67
- });
68
- this.boundingBoxUpdateRequired = true;
96
+ if (settings && settings.direction && settings.value !== undefined) {
97
+ const geometry = new THREE.PlaneGeometry(1, 1);
98
+ geometry.translate(0.5, 0.5, 0);
99
+ const uniforms = shader.getUniforms();
100
+ uniforms.diffuse.value = this.texture.impl;
101
+ uniforms.depth.value = this.texture.size.depth;
102
+ const options = {
103
+ fs: shader.fs,
104
+ vs: shader.vs,
105
+ uniforms: uniforms,
106
+ glslVersion: shader.glslVersion,
107
+ side: THREE.DoubleSide,
108
+ transparent: false
109
+ };
110
+ const material = this.texture.getMaterial(options);
111
+ material.needsUpdate = true;
112
+ const mesh = new THREE.Mesh(geometry, material);
113
+ const slideSettings = {
114
+ value: settings.value,
115
+ direction: settings.direction,
116
+ id: mesh.id,
117
+ };
118
+ textureSettings.push(slideSettings);
119
+ setUniformSlideSettingsOfMesh(mesh, slideSettings);
120
+ idTextureMap[mesh.id] = mesh;
121
+ this.morph.add(mesh);
122
+ return slideSettings;
123
+ }
69
124
  }
70
125
  }
71
126
 
127
+ /**
128
+ * Return a copy of texture settings used by this object.
129
+ *
130
+ * @return {SLIDE_SETTINGS} - Returned the list of settings..
131
+ */
132
+ this.getTextureSettings = () => {
133
+ return [...textureSettings];
134
+ }
135
+
72
136
  /**
73
137
  * Get the array of slides, return them in an array
74
138
  *
@@ -82,19 +146,35 @@ const TextureSlides = function (textureIn) {
82
146
  /**
83
147
  * Remove a slide, this will dispose the slide and its material.
84
148
  *
85
- * @param {Slide} slide - An array to each slide settings.
149
+ * @param {Slide} slide - Slide to be remvoed
86
150
  */
87
151
  this.removeSlide = slide => {
88
- if (slide && this.morph) {
89
- if (this.morph.getObjectById(slide.id)) {
152
+ if (slide) {
153
+ this.removeSlideWithId(slide.id);
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Remove a slide, this will dispose the slide and its material.
159
+ *
160
+ * @param {Number} id - id of slide to be remvoed
161
+ */
162
+ this.removeSlideWithId = id => {
163
+ if (this.morph && id in idTextureMap && idTextureMap[id]) {
164
+ if (this.morph.getObjectById(id)) {
165
+ const slide = idTextureMap[id];
90
166
  this.morph.remove(slide);
91
- slide.disppose();
167
+ slide.clear();
92
168
  if (slide.geometry)
93
169
  slide.geometry.dispose();
94
170
  if (slide.material)
95
171
  slide.material.dispose();
96
172
  this.boundingBoxUpdateRequired = true;
97
173
  }
174
+ const index = textureSettings.findIndex(item => item.id === id);
175
+ if (index > -1) {
176
+ textureSettings.splice(index);
177
+ }
98
178
  }
99
179
  }
100
180
 
@@ -102,7 +182,7 @@ const TextureSlides = function (textureIn) {
102
182
  * Clean up all internal objects.
103
183
  */
104
184
  this.dispose = () => {
105
- this.morph.children.forEach(slide=> {
185
+ this.morph.children.forEach(slide => {
106
186
  if (slide.geometry)
107
187
  slide.geometry.dispose();
108
188
  if (slide.material)
@@ -119,10 +199,11 @@ const TextureSlides = function (textureIn) {
119
199
  *
120
200
  * @return {THREE.Box3}.
121
201
  */
122
- this.getBoundingBox = function() {
202
+ this.getBoundingBox = function () {
123
203
  if (this.morph && this.morph.children && this.morph.visible &&
124
204
  this.boundingBoxUpdateRequired) {
125
- this.morph.children.forEach(slide=> {
205
+ this.cachedBoundingBox.makeEmpty();
206
+ this.morph.children.forEach(slide => {
126
207
  const value = slide.material.uniforms.slide.value;
127
208
  this.cachedBoundingBox.expandByPoint(value);
128
209
  });
@@ -134,6 +215,5 @@ const TextureSlides = function (textureIn) {
134
215
  }
135
216
  }
136
217
 
137
-
138
218
  TextureSlides.prototype = Object.create((require('./texturePrimitive').TexturePrimitive).prototype);
139
219
  exports.TextureSlides = TextureSlides;
@@ -312,7 +312,7 @@ ZincObject.prototype.isTimeVarying = function() {
312
312
  *
313
313
  */
314
314
  ZincObject.prototype.getVisibility = function() {
315
- return this.morph.visible;
315
+ return this.morph ? this.morph.visible : false;
316
316
  }
317
317
 
318
318
  /**
@@ -28,16 +28,17 @@ const vs =
28
28
  out vec3 vUw;
29
29
  uniform float depth;
30
30
  uniform vec3 slide;
31
+ uniform int direction;
31
32
 
32
33
  void main() {
33
34
 
34
35
  vec3 slidePos = position.xyz;
35
36
 
36
- if (slide.x > 0.0)
37
+ if (direction == 1)
37
38
  slidePos = vec3(slide.x, position.x, position.y);
38
- if (slide.y > 0.0)
39
+ if (direction == 2)
39
40
  slidePos = vec3(position.x, slide.y, position.y);
40
- if (slide.z > 0.0)
41
+ if (direction == 3)
41
42
  slidePos = vec3(position.x, position.y, slide.z);
42
43
 
43
44
  gl_Position = projectionMatrix * modelViewMatrix * vec4( slidePos, 1.0 );
@@ -51,7 +52,8 @@ const getUniforms = function() {
51
52
  return {
52
53
  diffuse: { value: undefined },
53
54
  depth: { value: 1 },
54
- slide: { value: new THREE.Vector3( 0, 0, 1 ) }
55
+ slide: { value: new THREE.Vector3( 0, 0, 1 ) },
56
+ direction: {value: 1},
55
57
  };
56
58
  }
57
59