zincjs 1.16.2 → 1.16.4
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/build/zinc.frontend.js +1 -1
- package/build/zinc.js +50 -49
- package/build/zinc.js.map +1 -1
- package/package.json +1 -1
- package/src/primitives/lines2.js +4 -3
- package/src/primitives/pointset.js +8 -2
- package/src/primitives/textureVolume.js +317 -0
- package/src/primitives/zincObject.js +53 -50
- package/src/shaders/volumeRender_old.js +287 -0
package/package.json
CHANGED
package/src/primitives/lines2.js
CHANGED
|
@@ -8,7 +8,7 @@ const LineSegmentsGeometry = require("../three/line/LineSegmentsGeometry").LineS
|
|
|
8
8
|
* Provides an object which stores lines.
|
|
9
9
|
* This is created when a valid json file containing lines is read into a {@link Zinc.Scene}
|
|
10
10
|
* object.
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
12
|
* @class
|
|
13
13
|
* @author Alan Wu
|
|
14
14
|
* @return {Lines}
|
|
@@ -20,7 +20,7 @@ const Lines2 = function () {
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Create the line segements using geometry and material.
|
|
23
|
-
*
|
|
23
|
+
*
|
|
24
24
|
* @param {Array} arrayIn - Geometry of lines to be rendered.
|
|
25
25
|
* @param {THREE.Material} materialIn - Material to be set for the lines.
|
|
26
26
|
* @param {Object} options - Provide various options
|
|
@@ -43,7 +43,7 @@ const Lines2 = function () {
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Set the width for the lines.
|
|
46
|
-
*
|
|
46
|
+
*
|
|
47
47
|
* @param {Number} width - Width of the lines.
|
|
48
48
|
*/
|
|
49
49
|
this.setWidth = width => {
|
|
@@ -121,6 +121,7 @@ const Lines2 = function () {
|
|
|
121
121
|
if (!mesh || 0 > i || maxIndex >= this.drawRange) {
|
|
122
122
|
return;
|
|
123
123
|
} else {
|
|
124
|
+
|
|
124
125
|
let index = i * 3;
|
|
125
126
|
coords.forEach(coord => {
|
|
126
127
|
positions[index++] = coord[0];
|
|
@@ -66,7 +66,10 @@ const Pointset = function () {
|
|
|
66
66
|
*/
|
|
67
67
|
this.addPoints = (coords, labels, colour) => {
|
|
68
68
|
if (coords && coords.length > 0) {
|
|
69
|
-
let current = this.drawRange
|
|
69
|
+
let current = this.drawRange;
|
|
70
|
+
if (current === -1) {
|
|
71
|
+
current = 0;
|
|
72
|
+
}
|
|
70
73
|
const geometry = this.addVertices(coords);
|
|
71
74
|
let mesh = this.getMorph();
|
|
72
75
|
if (!mesh) {
|
|
@@ -76,13 +79,15 @@ const Pointset = function () {
|
|
|
76
79
|
geometry.colorsNeedUpdate = true;
|
|
77
80
|
this.createMesh(geometry, material, options);
|
|
78
81
|
}
|
|
82
|
+
|
|
79
83
|
let end = current + coords.length;
|
|
80
84
|
let index = 0;
|
|
81
85
|
if ((Array.isArray(labels) && labels.length === coords.length) ||
|
|
82
86
|
(typeof labels === "string")) {
|
|
87
|
+
const size = labelSets.length;
|
|
83
88
|
for (current; current + index < end;) {
|
|
84
89
|
const labelText = typeof labels === "string" ? labels : labels[index];
|
|
85
|
-
addLabel(index, coords[index], labelText,
|
|
90
|
+
addLabel(current + index, coords[index], labelText, this._lod._material.color);
|
|
86
91
|
index++;
|
|
87
92
|
}
|
|
88
93
|
}
|
|
@@ -199,6 +204,7 @@ const Pointset = function () {
|
|
|
199
204
|
}
|
|
200
205
|
Pointset.prototype.render.call(this, delta, playAnimation, cameraControls, options);
|
|
201
206
|
}
|
|
207
|
+
|
|
202
208
|
}
|
|
203
209
|
|
|
204
210
|
Pointset.prototype = Object.create((require('./zincObject').ZincObject).prototype);
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
const THREE = require('three');
|
|
2
|
+
const shader = require("../shaders/volumeRender.js");
|
|
3
|
+
/**
|
|
4
|
+
* Provides a class which create a texture stacks in a block
|
|
5
|
+
* with shaders allowing slices of texture to be displayed.
|
|
6
|
+
*
|
|
7
|
+
* @param {TextureArray} textureIn - An object of texture array
|
|
8
|
+
* holding texture information.
|
|
9
|
+
*
|
|
10
|
+
* @class
|
|
11
|
+
* @author Alan Wu
|
|
12
|
+
* @return {TextureSlides}
|
|
13
|
+
*/
|
|
14
|
+
const TextureSlides = function (textureIn) {
|
|
15
|
+
(require('./texturePrimitive.js').TexturePrimitive).call(this, textureIn);
|
|
16
|
+
this.isTextureVolume = true;
|
|
17
|
+
const textureSettings = [];
|
|
18
|
+
this.morph = new THREE.Group();
|
|
19
|
+
this.group = this.morph;
|
|
20
|
+
this.morph.userData = this;
|
|
21
|
+
let edgesLine = undefined;
|
|
22
|
+
let flipY = true;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
@typedef SLIDE_SETTINGS
|
|
26
|
+
@type {Set}
|
|
27
|
+
@property {String} direction - the value must be x, y or z, specify the
|
|
28
|
+
direction the slide should be facing.
|
|
29
|
+
@property {Number} value - Normalised value of the location on direction.
|
|
30
|
+
@property {String} id - ID of the mesh, it is only available if the settings
|
|
31
|
+
is returned from {@link TextureSlides.createSlide} or
|
|
32
|
+
{@link TextureSlides.getTextureSettings}.
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Create the slides required for visualisation based on the slide settings.
|
|
36
|
+
* The slides themselves are {THREE.PlanGeometry} objects.
|
|
37
|
+
*
|
|
38
|
+
* @param {SLIDE_SETTINGS} slideSettings - An array to each slide settings.
|
|
39
|
+
*/
|
|
40
|
+
this.createSlides = slideSettings => {
|
|
41
|
+
slideSettings.forEach(slide => this.createSlide(slide));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Set the value of the uniforms for a specific mesh in this
|
|
46
|
+
* texture slide object.
|
|
47
|
+
*
|
|
48
|
+
* @param {THREE.Mesh} mesh - Mesh to be modified
|
|
49
|
+
* @param {SLIDE_SETTINGS} slideSettings - Slide settings.
|
|
50
|
+
*/
|
|
51
|
+
const setUniformSlideSettingsOfMesh = (mesh, settings) => {
|
|
52
|
+
const material = mesh.material;
|
|
53
|
+
const uniforms = material.uniforms;
|
|
54
|
+
mesh.rotation.x = 0;
|
|
55
|
+
mesh.rotation.y = 0;
|
|
56
|
+
mesh.rotation.z = 0;
|
|
57
|
+
mesh.position.x = 0;
|
|
58
|
+
mesh.position.y = 0;
|
|
59
|
+
mesh.position.z = 0;
|
|
60
|
+
switch (settings.direction) {
|
|
61
|
+
case "x":
|
|
62
|
+
const rotation = -Math.PI / 2;
|
|
63
|
+
mesh.rotation.y = rotation;
|
|
64
|
+
uniforms.direction.value = 1;
|
|
65
|
+
uniforms.slide.value.set(settings.value, 0, 0);
|
|
66
|
+
mesh.position.x = settings.value;
|
|
67
|
+
break;
|
|
68
|
+
case "y":
|
|
69
|
+
mesh.rotation.x = Math.PI / 2;
|
|
70
|
+
uniforms.direction.value = 2;
|
|
71
|
+
uniforms.slide.value.set(0, settings.value, 0);
|
|
72
|
+
mesh.position.y = settings.value;
|
|
73
|
+
break;
|
|
74
|
+
case "z":
|
|
75
|
+
uniforms.direction.value = 3;
|
|
76
|
+
uniforms.slide.value.set(0, 0, settings.value);
|
|
77
|
+
mesh.position.z = settings.value;
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
material.needsUpdate = true;
|
|
83
|
+
this.boundingBoxUpdateRequired = true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Modify the mesh based on a setting
|
|
88
|
+
*
|
|
89
|
+
* @param {SLIDE_SETTINGS} settings - s.
|
|
90
|
+
*/
|
|
91
|
+
this.modifySlideSettings = (settings) => {
|
|
92
|
+
if (settings && settings.id &&
|
|
93
|
+
settings.id in idTextureMap &&
|
|
94
|
+
idTextureMap[settings.id]) {
|
|
95
|
+
setUniformSlideSettingsOfMesh(idTextureMap[settings.id], settings);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Create a slide required for visualisation based on the slide settings.
|
|
101
|
+
* The slide itself is an {THREE.PlanGeometry} object.
|
|
102
|
+
*
|
|
103
|
+
* @param {SLIDE_SETTINGS} settings -settings of the slide to be created.
|
|
104
|
+
* @return {SLIDE_SETTINGS} - Returned settings, it includes the newly
|
|
105
|
+
* created mesh's id.
|
|
106
|
+
*/
|
|
107
|
+
this.createSlide = settings => {
|
|
108
|
+
if (this.texture && this.texture.isTextureArray && this.texture.isReady()) {
|
|
109
|
+
if (settings && settings.direction && settings.value !== undefined) {
|
|
110
|
+
const geometry = new THREE.PlaneGeometry(1, 1);
|
|
111
|
+
geometry.translate(0.5, 0.5, 0);
|
|
112
|
+
const uniforms = shader.getUniforms();
|
|
113
|
+
uniforms.diffuse.value = this.texture.impl;
|
|
114
|
+
uniforms.depth.value = this.texture.size.depth;
|
|
115
|
+
uniforms.flipY.value = flipY;
|
|
116
|
+
|
|
117
|
+
const options = {
|
|
118
|
+
fs: shader.fs,
|
|
119
|
+
vs: shader.vs,
|
|
120
|
+
uniforms: uniforms,
|
|
121
|
+
glslVersion: shader.glslVersion,
|
|
122
|
+
side: THREE.DoubleSide,
|
|
123
|
+
transparent: false
|
|
124
|
+
};
|
|
125
|
+
const material = this.texture.getMaterial(options);
|
|
126
|
+
material.needsUpdate = true;
|
|
127
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
128
|
+
mesh.name = this.groupName;
|
|
129
|
+
mesh.userData = this;
|
|
130
|
+
const slideSettings = {
|
|
131
|
+
value: settings.value,
|
|
132
|
+
direction: settings.direction,
|
|
133
|
+
id: mesh.id,
|
|
134
|
+
};
|
|
135
|
+
textureSettings.push(slideSettings);
|
|
136
|
+
setUniformSlideSettingsOfMesh(mesh, slideSettings);
|
|
137
|
+
idTextureMap[mesh.id] = mesh;
|
|
138
|
+
this.morph.add(mesh);
|
|
139
|
+
this.boundingBoxUpdateRequired = true;
|
|
140
|
+
return slideSettings;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Return a copy of texture settings used by this object.
|
|
147
|
+
*
|
|
148
|
+
* @return {SLIDE_SETTINGS} - Returned the list of settings.
|
|
149
|
+
*/
|
|
150
|
+
this.getTextureSettings = () => {
|
|
151
|
+
return [...textureSettings];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Return a copy of texture settings with corresponding id used by this object.
|
|
156
|
+
*
|
|
157
|
+
* @return {SLIDE_SETTINGS} - Returned a copy of settings with corresponding id.
|
|
158
|
+
*/
|
|
159
|
+
this.getTextureSettingsWithId = (id) => {
|
|
160
|
+
for (let i = 0; i < textureSettings.length; i++) {
|
|
161
|
+
if (id === textureSettings[i].id) {
|
|
162
|
+
return {...textureSettings[i]};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Get the array of slides, return them in an array
|
|
169
|
+
*
|
|
170
|
+
* @return {Array} - Return an array of {@link THREE.Object)
|
|
171
|
+
*/
|
|
172
|
+
this.getSlides = () => {
|
|
173
|
+
if (this.morph) return [...this.morph.children];
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Clean up all internal objects.
|
|
179
|
+
*/
|
|
180
|
+
this.dispose = () => {
|
|
181
|
+
this.morph.children.forEach(slide => {
|
|
182
|
+
if (slide.geometry)
|
|
183
|
+
slide.geometry.dispose();
|
|
184
|
+
if (slide.material)
|
|
185
|
+
slide.material.dispose();
|
|
186
|
+
});
|
|
187
|
+
(require('./texturePrimitive.js').TexturePrimitive).prototype.dispose.call(this);
|
|
188
|
+
this.boundingBoxUpdateRequired = true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//Expand the boundingbox with slide settings
|
|
192
|
+
const expandBoxWithSettings = (box, settings, vector) => {
|
|
193
|
+
if (settings) {
|
|
194
|
+
switch (settings.direction.value) {
|
|
195
|
+
case 1:
|
|
196
|
+
vector.copy(settings.slide.value);
|
|
197
|
+
box.expandByPoint(vector);
|
|
198
|
+
vector.setY(1.0);
|
|
199
|
+
vector.setZ(1.0);
|
|
200
|
+
box.expandByPoint(vector);
|
|
201
|
+
break;
|
|
202
|
+
case 2:
|
|
203
|
+
vector.copy(settings.slide.value);
|
|
204
|
+
box.expandByPoint(vector);
|
|
205
|
+
vector.setX(1.0);
|
|
206
|
+
vector.setZ(1.0);
|
|
207
|
+
box.expandByPoint(vector);
|
|
208
|
+
break;
|
|
209
|
+
case 3:
|
|
210
|
+
vector.copy(settings.slide.value);
|
|
211
|
+
box.expandByPoint(vector);
|
|
212
|
+
vector.setX(1.0);
|
|
213
|
+
vector.setY(1.0);
|
|
214
|
+
box.expandByPoint(vector);
|
|
215
|
+
break;
|
|
216
|
+
default:
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Get the bounding box of this slides.
|
|
224
|
+
* It uses the max and min of the slides position and the
|
|
225
|
+
* transformation to calculate the position of the box.
|
|
226
|
+
*
|
|
227
|
+
* @return {THREE.Box3}.
|
|
228
|
+
*/
|
|
229
|
+
this.getBoundingBox = () => {
|
|
230
|
+
if (this.morph && this.morph.children && this.morph.visible &&
|
|
231
|
+
this.boundingBoxUpdateRequired) {
|
|
232
|
+
this.cachedBoundingBox.makeEmpty();
|
|
233
|
+
const vector = new THREE.Vector3(0, 0, 0);
|
|
234
|
+
this.morph.children.forEach(slide => {
|
|
235
|
+
expandBoxWithSettings(this.cachedBoundingBox, slide.material.uniforms,
|
|
236
|
+
vector);
|
|
237
|
+
});
|
|
238
|
+
this.morph.updateMatrixWorld (true, true);
|
|
239
|
+
this.cachedBoundingBox.applyMatrix4(this.morph.matrixWorld);
|
|
240
|
+
this.boundingBoxUpdateRequired = false;
|
|
241
|
+
}
|
|
242
|
+
return this.cachedBoundingBox;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
this.applyTransformation = (rotation, position, scale) => {
|
|
246
|
+
const matrix = new THREE.Matrix4();
|
|
247
|
+
matrix.set(
|
|
248
|
+
rotation[0],
|
|
249
|
+
rotation[1],
|
|
250
|
+
rotation[2],
|
|
251
|
+
0,
|
|
252
|
+
rotation[3],
|
|
253
|
+
rotation[4],
|
|
254
|
+
rotation[5],
|
|
255
|
+
0,
|
|
256
|
+
rotation[6],
|
|
257
|
+
rotation[7],
|
|
258
|
+
rotation[8],
|
|
259
|
+
0,
|
|
260
|
+
0,
|
|
261
|
+
0,
|
|
262
|
+
0,
|
|
263
|
+
0
|
|
264
|
+
);
|
|
265
|
+
const quaternion = new THREE.Quaternion().setFromRotationMatrix(matrix);
|
|
266
|
+
this.morph.position.set(...position);
|
|
267
|
+
this.morph.quaternion.copy( quaternion );
|
|
268
|
+
this.morph.scale.set(...scale);
|
|
269
|
+
this.morph.updateMatrix();
|
|
270
|
+
this.boundingBoxUpdateRequired = true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
this.setRenderOrder = (order) => {
|
|
274
|
+
//multiilayers
|
|
275
|
+
this.morph.renderOrder = order;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
this.initialise = (textureData, finishCallback) => {
|
|
279
|
+
if (textureData) {
|
|
280
|
+
const locations = textureData.locations;
|
|
281
|
+
if (locations && locations.length > 0) {
|
|
282
|
+
this.applyTransformation(locations[0].orientation,
|
|
283
|
+
locations[0].position, locations[0].scale);
|
|
284
|
+
if ("flipY" in locations[0]) {
|
|
285
|
+
flipY = locations[0].flipY;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
this.createSlides(textureData.settings.slides);
|
|
289
|
+
if (finishCallback != undefined && (typeof finishCallback == 'function')) {
|
|
290
|
+
finishCallback(this);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
this.showEdges = (color) => {
|
|
296
|
+
if (!edgesLine) {
|
|
297
|
+
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
|
|
298
|
+
geometry.translate(0.5, 0.5, 0.5);
|
|
299
|
+
const edges = new THREE.EdgesGeometry( geometry );
|
|
300
|
+
edgesLine = new THREE.LineSegments(edges, new THREE.LineBasicMaterial( { color } ) );
|
|
301
|
+
this.group.add( edgesLine );
|
|
302
|
+
} else {
|
|
303
|
+
edgesLine.material.color = color;
|
|
304
|
+
}
|
|
305
|
+
edgesLine.visible = true;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
this.hideEdges = () => {
|
|
309
|
+
if (edgesLine) {
|
|
310
|
+
edgesLine.visible = false;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
TextureSlides.prototype = Object.create((require('./texturePrimitive.js').TexturePrimitive).prototype);
|
|
316
|
+
TextureSlides.prototype.constructor = TextureSlides;
|
|
317
|
+
exports.TextureSlides = TextureSlides;
|