zincjs 1.8.3 → 1.8.5

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.8.3",
3
+ "version": "1.8.5",
4
4
  "description": "ZincJS (Web-based-Zinc-Visualisation)",
5
5
  "main": "build/zinc.js",
6
6
  "directories": {
package/src/controls.js CHANGED
@@ -1517,22 +1517,31 @@ const RayCaster = function (sceneIn, hostSceneIn, callbackFunctionIn, hoverCallb
1517
1517
  enable = false;
1518
1518
  }
1519
1519
 
1520
- const getIntersectsObject = (zincCamera, x, y) => {
1521
- zincCamera.getNDCFromDocumentCoords(x, y, mouse);
1520
+ this.getIntersectsObject = (zincCamera) => {
1522
1521
  if (hostScene !== scene) {
1523
1522
  const threejsScene = scene.getThreeJSScene();
1524
1523
  renderer.render(threejsScene, zincCamera.cameraObject);
1525
1524
  }
1526
- raycaster.setFromCamera( mouse, zincCamera.cameraObject);
1527
1525
  let objects = scene.getPickableThreeJSObjects();
1528
1526
  //Reset pickedObjects array
1529
1527
  pickedObjects.length = 0;
1530
1528
  return raycaster.intersectObjects( objects, true, pickedObjects );
1529
+ }
1530
+
1531
+ this.getIntersectsObjectWithOrigin = (zincCamera, origin, direction) => {
1532
+ raycaster.set(origin, direction);
1533
+ return this.getIntersectsObject(zincCamera);
1534
+ }
1535
+
1536
+ const getIntersectsObjectWithCamera = (zincCamera, x, y) => {
1537
+ zincCamera.getNDCFromDocumentCoords(x, y, mouse);
1538
+ raycaster.setFromCamera(mouse, zincCamera.cameraObject);
1539
+ return this.getIntersectsObject(zincCamera);
1531
1540
  };
1532
1541
 
1533
1542
  this.pick = (zincCamera, x, y) => {
1534
1543
  if (enabled && renderer && scene && zincCamera && callbackFunction) {
1535
- getIntersectsObject(zincCamera, x, y);
1544
+ getIntersectsObjectWithCamera(zincCamera, x, y);
1536
1545
  const length = pickedObjects.length;
1537
1546
  for (let i = 0; i < length; i++) {
1538
1547
  let zincObject = pickedObjects[i].object ? pickedObjects[i].object.userData : undefined;
@@ -1548,7 +1557,7 @@ const RayCaster = function (sceneIn, hostSceneIn, callbackFunctionIn, hoverCallb
1548
1557
 
1549
1558
  let hovered = (zincCamera, x, y) => {
1550
1559
  if (enabled && renderer && scene && zincCamera && hoverCallbackFunction) {
1551
- getIntersectsObject(zincCamera, x, y);
1560
+ getIntersectsObjectWithCamera(zincCamera, x, y);
1552
1561
  lastHoveredDate.setTime(Date.now());
1553
1562
  if (pickedObjects.length === 0) {
1554
1563
  //skip hovered callback if the previous one is empty
@@ -42,8 +42,9 @@ exports.Label = function (textIn, colour) {
42
42
  * @param {Number} z - z coordinate to be set.
43
43
  */
44
44
  this.setPosition = (x, y, z) => {
45
- if (sprite)
45
+ if (sprite) {
46
46
  sprite.position.set(x, y, z);
47
+ }
47
48
  }
48
49
 
49
50
  /**
@@ -1,5 +1,4 @@
1
1
  const THREE = require('three');
2
- const createBufferGeometry = require('../utilities').createBufferGeometry;
3
2
  const toBufferGeometry = require('../utilities').toBufferGeometry;
4
3
  const LineSegments2 = require("../three/line/LineSegments2").LineSegments2;
5
4
  const LineMaterial = require("../three/line/LineMaterial").LineMaterial;
@@ -115,7 +114,7 @@ const Lines2 = function () {
115
114
  /**
116
115
  * Edit Vertice in index.
117
116
  */
118
- this.editVertice = function(coords, i) {
117
+ this.editVertices = function(coords, i) {
119
118
  if (coords && coords.length) {
120
119
  let mesh = this.getMorph();
121
120
  const maxIndex = i + coords.length - 1;
@@ -142,7 +141,6 @@ const Lines2 = function () {
142
141
  return positions;
143
142
  }
144
143
 
145
-
146
144
  /**
147
145
  * Add new lines to existing lines if it exists, otherwise
148
146
  * create a new one and add to it.
@@ -2,6 +2,7 @@ const THREE = require('three');
2
2
  const Points = require('../three/Points').Points;
3
3
  const toBufferGeometry = require('../utilities').toBufferGeometry;
4
4
  const getCircularTexture = require('../utilities').getCircularTexture;
5
+ const Label = require('./label').Label;
5
6
 
6
7
  /**
7
8
  * Provides an object which stores points and provides method which controls its position.
@@ -15,6 +16,7 @@ const getCircularTexture = require('../utilities').getCircularTexture;
15
16
  const Pointset = function () {
16
17
  (require('./zincObject').ZincObject).call(this);
17
18
  this.isPointset = true;
19
+ const labelSets = [];
18
20
 
19
21
  /**
20
22
  * Create the pointsets using geometry and material.
@@ -38,16 +40,33 @@ const Pointset = function () {
38
40
  }
39
41
  }
40
42
 
43
+ const addLabel = (index, coord, labelText, colourHex) => {
44
+ if (labelText) {
45
+ const colour = new THREE.Color(colourHex);
46
+ const label = new Label(labelText, colour);
47
+ label.setPosition(coord[0], coord[1], coord[2]);
48
+ const sprite = label.getSprite();
49
+ sprite.material.sizeAttenuation = false;
50
+ sprite.material.alphaTest = 0.5;
51
+ sprite.material.transparent = true;
52
+ sprite.material.depthWrite = false;
53
+ sprite.material.depthTest = false;
54
+ this.group.add(sprite);
55
+ labelSets[index] = label;
56
+ }
57
+ }
58
+
41
59
  /**
42
60
  * Add points to existing mesh if it exists, otherwise
43
61
  * create a new one and add to it.
44
62
  * @param {Array} coords -An array of three components coordinates.
45
- * @param {Array} labels - An array of strings, these are only added
63
+ * @param {Array|String} labels - An array of strings, these are only added
46
64
  * if the number of coords equals to the number labels provided.
47
65
  * @param {Number} colour - A hex value of the colour for the points
48
66
  */
49
67
  this.addPoints = (coords, labels, colour) => {
50
68
  if (coords && coords.length > 0) {
69
+ let current = this.drawRange - 1;
51
70
  const geometry = this.addVertices(coords);
52
71
  let mesh = this.getMorph();
53
72
  if (!mesh) {
@@ -57,6 +76,16 @@ const Pointset = function () {
57
76
  geometry.colorsNeedUpdate = true;
58
77
  this.createMesh(geometry, material, options);
59
78
  }
79
+ let end = current + coords.length;
80
+ let index = 0;
81
+ if ((Array.isArray(labels) && labels.length === coords.length) ||
82
+ (typeof labels === "string")) {
83
+ for (current; current + index < end;) {
84
+ const labelText = typeof labels === "string" ? labels : labels[index];
85
+ addLabel(index, coords[index], labelText, colour);
86
+ index++;
87
+ }
88
+ }
60
89
  if (this.region) this.region.pickableUpdateRequired = true;
61
90
  }
62
91
  }
@@ -86,18 +115,59 @@ const Pointset = function () {
86
115
  }
87
116
  }
88
117
 
89
- /**
90
- * Turn size attenuation on/off based on the flag.
91
- *
92
- * @param {Boolean} flag - Determin either size attenuation
93
- * should be on or off.
118
+ /**
119
+ * Get vertices at index
120
+ */
121
+ this.getVerticesByIndex = function(index) {
122
+ if (index >= 0 && this.drawRange > index) {
123
+ const positionAttribute = this.getMorph().geometry.getAttribute( 'position' );
124
+ return [
125
+ positionAttribute.getX(index),
126
+ positionAttribute.getY(index),
127
+ positionAttribute.getZ(index)
128
+ ];
129
+ }
130
+ return undefined;
131
+ }
132
+
133
+ /**
134
+ * Edit Vertice in index.
94
135
  */
95
- this.render = (delta, playAnimation, cameraControls, options) => {
96
- if (this.morph) {
97
- this.morph.sizePerPixel = cameraControls.pixelHeight;
136
+ this.editVertices = function(coords, i) {
137
+ if (coords && coords.length) {
138
+ let mesh = this.getMorph();
139
+ const maxIndex = i + coords.length - 1;
140
+ if (!mesh || 0 > i || maxIndex >= this.drawRange) {
141
+ return;
142
+ } else {
143
+ const positionAttribute = mesh.geometry.getAttribute( 'position' );
144
+ let index = i;
145
+ coords.forEach(coord => {
146
+ const label = labelSets[index];
147
+ if (label) {
148
+ label.setPosition(coord[0], coord[1], coord[2]);
149
+ }
150
+ positionAttribute.setXYZ(index++, coord[0], coord[1], coord[2]);
151
+
152
+ });
153
+ positionAttribute.needsUpdate = true;
154
+ this.boundingBoxUpdateRequired = true;
98
155
  }
99
- Pointset.prototype.render.call(this, delta, playAnimation, cameraControls, options);
100
156
  }
157
+ }
158
+
159
+ /**
160
+ * Turn size attenuation on/off based on the flag.
161
+ *
162
+ * @param {Boolean} flag - Determin either size attenuation
163
+ * should be on or off.
164
+ */
165
+ this.render = (delta, playAnimation, cameraControls, options) => {
166
+ if (this.morph && cameraControls) {
167
+ this.morph.sizePerPixel = cameraControls.pixelHeight;
168
+ }
169
+ Pointset.prototype.render.call(this, delta, playAnimation, cameraControls, options);
170
+ }
101
171
  }
102
172
 
103
173
  Pointset.prototype = Object.create((require('./zincObject').ZincObject).prototype);
@@ -19,7 +19,7 @@ const TextureSlides = function (textureIn) {
19
19
  this.morph = new THREE.Group();
20
20
  this.group = this.morph;
21
21
  this.morph.userData = this;
22
- let flipY = true;
22
+ let flipY = true;
23
23
 
24
24
  /**
25
25
  @typedef SLIDE_SETTINGS
@@ -51,18 +51,30 @@ const TextureSlides = function (textureIn) {
51
51
  const setUniformSlideSettingsOfMesh = (mesh, settings) => {
52
52
  const material = mesh.material;
53
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;
54
60
  switch (settings.direction) {
55
61
  case "x":
62
+ const rotation = flipY ? -Math.PI / 2 : Math.PI / 2;
63
+ mesh.rotation.y = rotation;
56
64
  uniforms.direction.value = 1;
57
65
  uniforms.slide.value.set(settings.value, 0, 0);
66
+ mesh.position.x = settings.value;
58
67
  break;
59
68
  case "y":
69
+ mesh.rotation.x = Math.PI / 2;
60
70
  uniforms.direction.value = 2;
61
71
  uniforms.slide.value.set(0, settings.value, 0);
72
+ mesh.position.y = settings.value;
62
73
  break;
63
74
  case "z":
64
75
  uniforms.direction.value = 3;
65
76
  uniforms.slide.value.set(0, 0, settings.value);
77
+ mesh.position.z = settings.value;
66
78
  break;
67
79
  default:
68
80
  break;
@@ -113,6 +125,8 @@ const TextureSlides = function (textureIn) {
113
125
  const material = this.texture.getMaterial(options);
114
126
  material.needsUpdate = true;
115
127
  const mesh = new THREE.Mesh(geometry, material);
128
+ mesh.name = this.groupName;
129
+ mesh.userData = this;
116
130
  const slideSettings = {
117
131
  value: settings.value,
118
132
  direction: settings.direction,
@@ -131,12 +145,25 @@ const TextureSlides = function (textureIn) {
131
145
  /**
132
146
  * Return a copy of texture settings used by this object.
133
147
  *
134
- * @return {SLIDE_SETTINGS} - Returned the list of settings..
148
+ * @return {SLIDE_SETTINGS} - Returned the list of settings.
135
149
  */
136
150
  this.getTextureSettings = () => {
137
151
  return [...textureSettings];
138
152
  }
139
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
+
140
167
  /**
141
168
  * Get the array of slides, return them in an array
142
169
  *
package/src/scene.js CHANGED
@@ -1270,13 +1270,67 @@ exports.Scene = function (containerIn, rendererIn) {
1270
1270
  const box = boundingBox ? boundingBox : this.getBoundingBox();
1271
1271
  const dim = new THREE.Vector3().subVectors(box.max, box.min);
1272
1272
  const boxGeo = new THREE.BoxGeometry(dim.x, dim.y, dim.z);
1273
- dim.addVectors(box.min, box.max).multiplyScalar( 0.5 );
1274
1273
  const primitive = region.createGeometryFromThreeJSGeometry(
1275
1274
  group, boxGeo, colour, opacity, visibility, 10000);
1275
+ dim.addVectors(box.min, box.max).multiplyScalar( 0.5 );
1276
1276
  primitive.setPosition(dim.x, dim.y, dim.z);
1277
1277
  return primitive;
1278
1278
  }
1279
1279
 
1280
+ /*
1281
+ * Create primitive based on the bounding box of scene and
1282
+ * add to specify region and group name.
1283
+ */
1284
+ this.addSlicesPrimitive = (regionPath, groups, colours, opacity,
1285
+ visibility, boundingBox = undefined) => {
1286
+ if (groups && groups.length >= 3 &&
1287
+ colours && colours.length >= 3) {
1288
+ let region = rootRegion.findChildFromPath(regionPath);
1289
+ if (region === undefined) {
1290
+ region = rootRegion.createChildFromPath(regionPath);
1291
+ }
1292
+ const box = boundingBox ? boundingBox : this.getBoundingBox();
1293
+ const dim = new THREE.Vector3().subVectors(box.max, box.min);
1294
+ const directions = ["x", "y", "z"];
1295
+ const primitives = [];
1296
+ let index = 0;
1297
+ directions.forEach((direction) => {
1298
+ let planeGeo = undefined;
1299
+ switch(direction) {
1300
+ //YZ plane
1301
+ case "x":
1302
+ planeGeo = new THREE.PlaneGeometry(dim.z, dim.y);
1303
+ planeGeo.rotateY(Math.PI / 2);
1304
+ // code block
1305
+ break;
1306
+ //XZ plane
1307
+ case "y":
1308
+ planeGeo = new THREE.PlaneGeometry(dim.x, dim.z);
1309
+ planeGeo.rotateX(Math.PI / 2);
1310
+ // code block
1311
+ break;
1312
+ //XY plane
1313
+ case "z":
1314
+ planeGeo = new THREE.PlaneGeometry(dim.x, dim.y);
1315
+ // code block
1316
+ break;
1317
+ default:
1318
+ break;
1319
+ }
1320
+ const primitive = region.createGeometryFromThreeJSGeometry(
1321
+ groups[index], planeGeo, colours[index], opacity, visibility, 10001);
1322
+ primitives.push(primitive);
1323
+ index++;
1324
+ });
1325
+
1326
+ dim.addVectors(box.min, box.max).multiplyScalar( 0.5 );
1327
+ primitives.forEach((primitive) => {
1328
+ primitive.setPosition(dim.x, dim.y, dim.z);
1329
+ });
1330
+ return primitives;
1331
+ }
1332
+ }
1333
+
1280
1334
  /*
1281
1335
  * Enable marker cluster to work with markers
1282
1336
  */
@@ -34,18 +34,17 @@ uniform bool flipY;
34
34
  void main() {
35
35
 
36
36
  vec3 slidePos = position.xyz;
37
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position.xyz, 1.0 );
37
38
 
38
39
  if (direction == 1)
39
- slidePos = vec3(slide.x, position.x, position.y);
40
+ slidePos = vec3(slide.x, position.y, position.x);
40
41
  if (direction == 2)
41
42
  slidePos = vec3(position.x, slide.y, position.y);
42
43
  if (direction == 3)
43
44
  slidePos = vec3(position.x, position.y, slide.z);
44
45
 
45
- gl_Position = projectionMatrix * modelViewMatrix * vec4( slidePos, 1.0 );
46
-
47
- if (flipY)
48
- slidePos.y = 1.0 - slidePos.y;
46
+ if (flipY)
47
+ slidePos.y = 1.0 - slidePos.y;
49
48
 
50
49
  vUw.xyz = vec3(slidePos.x, slidePos.y, slidePos.z * depth);
51
50