zincjs 1.1.0 → 1.3.0
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/CHANGELOG.md +22 -1
- package/build/zinc.frontend.js +1 -1
- package/build/zinc.js +55 -11
- package/build/zinc.js.map +1 -1
- package/package.json +1 -1
- package/src/assets/mapMarker.svg +1 -1
- package/src/primitives/marker.js +3 -2
- package/src/primitives/textureSlides.js +126 -46
- package/src/primitives/zincObject.js +41 -2
- package/src/region.js +6 -10
- package/src/scene.js +1 -2
- package/src/shaders/textureSlide.js +6 -4
package/package.json
CHANGED
package/src/assets/mapMarker.svg
CHANGED
|
@@ -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="#
|
|
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/primitives/marker.js
CHANGED
|
@@ -91,13 +91,14 @@ const Marker = function(zincObject) {
|
|
|
91
91
|
*/
|
|
92
92
|
this.dispose = () => {
|
|
93
93
|
if (this.morph) {
|
|
94
|
-
this.morph.
|
|
94
|
+
this.morph.clear();
|
|
95
95
|
}
|
|
96
96
|
if (spriteMaterial) {
|
|
97
97
|
spriteMaterial.dispose();
|
|
98
98
|
}
|
|
99
99
|
if (sprite) {
|
|
100
|
-
sprite.
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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 -
|
|
149
|
+
* @param {Slide} slide - Slide to be remvoed
|
|
86
150
|
*/
|
|
87
151
|
this.removeSlide = slide => {
|
|
88
|
-
if (slide
|
|
89
|
-
|
|
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.
|
|
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.
|
|
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;
|
|
@@ -50,6 +50,7 @@ const ZincObject = function() {
|
|
|
50
50
|
this.anatomicalId = undefined;
|
|
51
51
|
this.region = undefined;
|
|
52
52
|
this.animationClip = undefined;
|
|
53
|
+
this.markerMode = "inherited";
|
|
53
54
|
this.uuid = getUniqueId();
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -311,7 +312,7 @@ ZincObject.prototype.isTimeVarying = function() {
|
|
|
311
312
|
*
|
|
312
313
|
*/
|
|
313
314
|
ZincObject.prototype.getVisibility = function() {
|
|
314
|
-
return this.morph.visible;
|
|
315
|
+
return this.morph ? this.morph.visible : false;
|
|
315
316
|
}
|
|
316
317
|
|
|
317
318
|
/**
|
|
@@ -565,12 +566,27 @@ ZincObject.prototype.dispose = function() {
|
|
|
565
566
|
this.groupName = undefined;
|
|
566
567
|
}
|
|
567
568
|
|
|
569
|
+
/**
|
|
570
|
+
* Check if marker is enabled based on the objects settings with
|
|
571
|
+
* the provided scene options.
|
|
572
|
+
*
|
|
573
|
+
* @return {Boolean}
|
|
574
|
+
*/
|
|
575
|
+
ZincObject.prototype.markerIsEnabled = function(options) {
|
|
576
|
+
if (this.markerMode === "on" || (options && options.displayMarkers &&
|
|
577
|
+
(this.markerMode === "inherited"))) {
|
|
578
|
+
|
|
579
|
+
return true;
|
|
580
|
+
}
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
|
|
568
584
|
/**
|
|
569
585
|
* Update the marker's position and size based on current viewport.
|
|
570
586
|
*/
|
|
571
587
|
ZincObject.prototype.updateMarker = function(playAnimation, options) {
|
|
572
588
|
if ((playAnimation == false) &&
|
|
573
|
-
(options
|
|
589
|
+
(this.markerIsEnabled(options)))
|
|
574
590
|
{
|
|
575
591
|
if (this.groupName) {
|
|
576
592
|
if (!this.marker) {
|
|
@@ -645,6 +661,29 @@ ZincObject.prototype.getClosestVertexDOMElementCoords = function(scene) {
|
|
|
645
661
|
}
|
|
646
662
|
}
|
|
647
663
|
|
|
664
|
+
/**
|
|
665
|
+
* Set marker mode for this zinc object which determine rather the
|
|
666
|
+
* markers should be displayed or not.
|
|
667
|
+
*
|
|
668
|
+
* @param {string} mode - There are three options:
|
|
669
|
+
* "on" - marker is enabled regardless of settings of scene
|
|
670
|
+
* "off" - marker is disabled regardless of settings of scene
|
|
671
|
+
* "inherited" - Marker settings on scene will determine the visibility
|
|
672
|
+
* of the marker.
|
|
673
|
+
*
|
|
674
|
+
* @return {Boolean}
|
|
675
|
+
*/
|
|
676
|
+
ZincObject.prototype.setMarkerMode = function(mode) {
|
|
677
|
+
if (mode !== this.markerMode) {
|
|
678
|
+
if (mode === "on" || mode === "off") {
|
|
679
|
+
this.markerMode = mode;
|
|
680
|
+
} else {
|
|
681
|
+
this.markerMode = "inherited";
|
|
682
|
+
}
|
|
683
|
+
if (this.region) this.region.pickableUpdateRequired = true;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
648
687
|
//Update the geometry and colours depending on the morph.
|
|
649
688
|
ZincObject.prototype.render = function(delta, playAnimation, options) {
|
|
650
689
|
if (playAnimation == true)
|
package/src/region.js
CHANGED
|
@@ -338,23 +338,19 @@ let Region = function (parentIn) {
|
|
|
338
338
|
/**
|
|
339
339
|
* Get all pickable objects.
|
|
340
340
|
*/
|
|
341
|
-
this.getPickableThreeJSObjects = (objectsList,
|
|
341
|
+
this.getPickableThreeJSObjects = (objectsList, transverse) => {
|
|
342
342
|
zincObjects.forEach(zincObject => {
|
|
343
343
|
if (zincObject.morph && zincObject.morph.visible) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
objectsList.push(marker.morph);
|
|
348
|
-
}
|
|
349
|
-
} else {
|
|
350
|
-
objectsList.push(zincObject.morph);
|
|
344
|
+
let marker = zincObject.marker;
|
|
345
|
+
if (marker && marker.isEnabled()) {
|
|
346
|
+
objectsList.push(marker.morph);
|
|
351
347
|
}
|
|
348
|
+
objectsList.push(zincObject.morph);
|
|
352
349
|
}
|
|
353
350
|
});
|
|
354
351
|
if (transverse) {
|
|
355
352
|
children.forEach(childRegion => {
|
|
356
|
-
childRegion.getPickableThreeJSObjects(objectsList,
|
|
357
|
-
transverse);
|
|
353
|
+
childRegion.getPickableThreeJSObjects(objectsList, transverse);
|
|
358
354
|
});
|
|
359
355
|
}
|
|
360
356
|
this.pickableUpdateRequired = false;
|
package/src/scene.js
CHANGED
|
@@ -867,8 +867,7 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
867
867
|
*/
|
|
868
868
|
this.updatePickableThreeJSObjects = () => {
|
|
869
869
|
pickableObjectsList.splice(0, pickableObjectsList.length);
|
|
870
|
-
rootRegion.getPickableThreeJSObjects(pickableObjectsList,
|
|
871
|
-
this.displayMarkers, true);
|
|
870
|
+
rootRegion.getPickableThreeJSObjects(pickableObjectsList, true);
|
|
872
871
|
this.forcePickableObjectsUpdate = false;
|
|
873
872
|
}
|
|
874
873
|
|
|
@@ -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 (
|
|
37
|
+
if (direction == 1)
|
|
37
38
|
slidePos = vec3(slide.x, position.x, position.y);
|
|
38
|
-
if (
|
|
39
|
+
if (direction == 2)
|
|
39
40
|
slidePos = vec3(position.x, slide.y, position.y);
|
|
40
|
-
if (
|
|
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
|
|