zincjs 1.0.17 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zincjs",
3
- "version": "1.0.17",
3
+ "version": "1.2.0",
4
4
  "description": "ZincJS (Web-based-Zinc-Visualisation)",
5
5
  "main": "build/zinc.js",
6
6
  "directories": {
package/src/controls.js CHANGED
@@ -237,9 +237,9 @@ const CameraControls = function ( object, domElement, renderer, scene ) {
237
237
  this.getNDCFromDocumentCoords = (x, y, positionIn) => {
238
238
  updateRect(false);
239
239
  const position = positionIn ? positionIn : new THREE.Vector2();
240
- position.x = ((x - rect.left) / rect.width) * 2 - 1;
241
- position.y = -((y - rect.top) / rect.height) * 2 + 1;
242
- return position;
240
+ const out_x = ((x - rect.left) / rect.width) * 2 - 1;
241
+ const out_y = -((y - rect.top) / rect.height) * 2 + 1;
242
+ return position.set(out_x, out_y);
243
243
  }
244
244
 
245
245
  /**
@@ -581,7 +581,8 @@ const Glyphset = function () {
581
581
  }
582
582
  if (_boundingBox3) {
583
583
  this.cachedBoundingBox.copy(_boundingBox3);
584
- this.cachedBoundingBox.applyMatrix4(this.morph.matrix);
584
+ this.morph.updateWorldMatrix();
585
+ this.cachedBoundingBox.applyMatrix4(this.morph.matrixWorld);
585
586
  this.boundingBoxUpdateRequired = false;
586
587
  } else
587
588
  return undefined;
@@ -86,6 +86,21 @@ const Marker = function(zincObject) {
86
86
  sprite.scale.multiplyScalar(size);
87
87
  }
88
88
 
89
+ /**
90
+ * Clean up this object,
91
+ */
92
+ this.dispose = () => {
93
+ if (this.morph) {
94
+ this.morph.dispose();
95
+ }
96
+ if (spriteMaterial) {
97
+ spriteMaterial.dispose();
98
+ }
99
+ if (sprite) {
100
+ sprite.dispose();
101
+ }
102
+ }
103
+
89
104
  this.isEnabled = () => {
90
105
  return enabled;
91
106
  }
@@ -126,7 +126,8 @@ const TextureSlides = function (textureIn) {
126
126
  const value = slide.material.uniforms.slide.value;
127
127
  this.cachedBoundingBox.expandByPoint(value);
128
128
  });
129
- this.cachedBoundingBox.applyMatrix4(this.morph.matrix);
129
+ this.morph.updateWorldMatrix();
130
+ this.cachedBoundingBox.applyMatrix4(this.morph.matrixWorld);
130
131
  this.boundingBoxUpdateRequired = false;
131
132
  }
132
133
  return this.cachedBoundingBox;
@@ -1,6 +1,12 @@
1
1
  const THREE = require('three');
2
2
  const THREEGeometry = require('../three/Geometry').Geometry;
3
3
 
4
+ let uniqueiId = 0;
5
+
6
+ const getUniqueId = function () {
7
+ return "pr" + uniqueiId++;
8
+ }
9
+
4
10
  /**
5
11
  * Provides the base object for other primitive types.
6
12
  * This class contains multiple base methods.
@@ -44,6 +50,8 @@ const ZincObject = function() {
44
50
  this.anatomicalId = undefined;
45
51
  this.region = undefined;
46
52
  this.animationClip = undefined;
53
+ this.markerMode = "inherited";
54
+ this.uuid = getUniqueId();
47
55
  }
48
56
 
49
57
  /**
@@ -467,7 +475,7 @@ ZincObject.prototype.getClosestVertexIndex = function() {
467
475
  *
468
476
  * @return {THREE.Vector3}
469
477
  */
470
- ZincObject.prototype.getClosestVertex = function() {
478
+ ZincObject.prototype.getClosestVertex = function(applyMatrixWorld) {
471
479
  let position = new THREE.Vector3();
472
480
  if (this.closestVertexIndex == -1) {
473
481
  this.closestVertexIndex = this.getClosestVertexIndex();
@@ -485,16 +493,17 @@ ZincObject.prototype.getClosestVertex = function() {
485
493
  position.add(this._vertex.multiplyScalar(influences[i]));
486
494
  }
487
495
  }
488
- if (found)
489
- return position;
496
+ if (found) {
497
+ return applyMatrixWorld ? position.applyMatrix4(this.morph.matrixWorld) : position;
498
+ }
490
499
  } else {
491
500
  position.fromArray(this.morph.geometry.attributes.position.array,
492
501
  this.closestVertexIndex * 3);
493
- return position;
502
+ return applyMatrixWorld ? position.applyMatrix4(this.morph.matrixWorld) : position;
494
503
  }
495
504
  }
496
505
  this.getBoundingBox().getCenter(position);
497
- return position;
506
+ return applyMatrixWorld ? position.applyMatrix4(this.morph.matrixWorld) : position;
498
507
  }
499
508
 
500
509
  /**
@@ -525,10 +534,12 @@ ZincObject.prototype.getBoundingBox = function() {
525
534
  if (found)
526
535
  this.cachedBoundingBox.set(min, max);
527
536
  }
528
- if (!found)
537
+ if (!found) {
529
538
  this.cachedBoundingBox.setFromBufferAttribute(
530
539
  this.morph.geometry.attributes.position);
531
- this.cachedBoundingBox.applyMatrix4(this.morph.matrix);
540
+ }
541
+ this.morph.updateWorldMatrix();
542
+ this.cachedBoundingBox.applyMatrix4(this.morph.matrixWorld);
532
543
  this.boundingBoxUpdateRequired = false;
533
544
  }
534
545
  return this.cachedBoundingBox;
@@ -555,12 +566,27 @@ ZincObject.prototype.dispose = function() {
555
566
  this.groupName = undefined;
556
567
  }
557
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
+
558
584
  /**
559
585
  * Update the marker's position and size based on current viewport.
560
586
  */
561
587
  ZincObject.prototype.updateMarker = function(playAnimation, options) {
562
588
  if ((playAnimation == false) &&
563
- (options && options.displayMarkers))
589
+ (this.markerIsEnabled(options)))
564
590
  {
565
591
  if (this.groupName) {
566
592
  if (!this.marker) {
@@ -568,7 +594,7 @@ ZincObject.prototype.updateMarker = function(playAnimation, options) {
568
594
  this.markerUpdateRequired = true;
569
595
  }
570
596
  if (this.markerUpdateRequired) {
571
- let position = this.getClosestVertex();
597
+ let position = this.getClosestVertex(false);
572
598
  if (position) {
573
599
  this.marker.setPosition(position.x, position.y, position.z);
574
600
  this.markerUpdateRequired = false;
@@ -622,7 +648,7 @@ ZincObject.prototype.setRenderOrder = function(renderOrder) {
622
648
  ZincObject.prototype.getClosestVertexDOMElementCoords = function(scene) {
623
649
  if (scene && scene.camera) {
624
650
  let inView = true;
625
- const position = this.getClosestVertex();
651
+ const position = this.getClosestVertex(true);
626
652
  position.project(scene.camera);
627
653
  position.z = Math.min(Math.max(position.z, 0), 1);
628
654
  if (position.x > 1 || position.x < -1 || position.y > 1 || position.y < -1) {
@@ -635,6 +661,29 @@ ZincObject.prototype.getClosestVertexDOMElementCoords = function(scene) {
635
661
  }
636
662
  }
637
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
+
638
687
  //Update the geometry and colours depending on the morph.
639
688
  ZincObject.prototype.render = function(delta, playAnimation, options) {
640
689
  if (playAnimation == true)
package/src/region.js CHANGED
@@ -1,5 +1,11 @@
1
1
  const { Group, Matrix4 } = require('three');
2
2
 
3
+ let uniqueiId = 0;
4
+
5
+ const getUniqueId = function () {
6
+ return "re" + uniqueiId++;
7
+ }
8
+
3
9
  /**
4
10
  * Provides a hierachical structure to objects, Each region
5
11
  * may contain multiple child regions and {@link ZincObject}.
@@ -20,6 +26,9 @@ let Region = function (parentIn) {
20
26
  let duration = 3000;
21
27
  tMatrix.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
22
28
  this.pickableUpdateRequired = true;
29
+ this.isRegion = true;
30
+ this.uuid = getUniqueId();
31
+
23
32
 
24
33
  /**
25
34
  * Hide all primitives belong to this region.
@@ -329,23 +338,19 @@ let Region = function (parentIn) {
329
338
  /**
330
339
  * Get all pickable objects.
331
340
  */
332
- this.getPickableThreeJSObjects = (objectsList, pickMarkers, transverse) => {
341
+ this.getPickableThreeJSObjects = (objectsList, transverse) => {
333
342
  zincObjects.forEach(zincObject => {
334
343
  if (zincObject.morph && zincObject.morph.visible) {
335
- if (pickMarkers) {
336
- let marker = zincObject.marker;
337
- if (marker && marker.isEnabled()) {
338
- objectsList.push(marker.morph);
339
- }
340
- } else {
341
- objectsList.push(zincObject.morph);
344
+ let marker = zincObject.marker;
345
+ if (marker && marker.isEnabled()) {
346
+ objectsList.push(marker.morph);
342
347
  }
348
+ objectsList.push(zincObject.morph);
343
349
  }
344
350
  });
345
351
  if (transverse) {
346
352
  children.forEach(childRegion => {
347
- childRegion.getPickableThreeJSObjects(objectsList, pickMarkers,
348
- transverse);
353
+ childRegion.getPickableThreeJSObjects(objectsList, transverse);
349
354
  });
350
355
  }
351
356
  this.pickableUpdateRequired = false;
@@ -374,6 +379,8 @@ let Region = function (parentIn) {
374
379
 
375
380
  /**
376
381
  * Get the bounding box of all the object in this and child regions only.
382
+ * Do not include the matrix transformation here, it is done at the primitives
383
+ * level.
377
384
  *
378
385
  * @returns {THREE.Box3}
379
386
  */
@@ -389,8 +396,6 @@ let Region = function (parentIn) {
389
396
  }
390
397
  }
391
398
  });
392
- if (boundingBox1)
393
- boundingBox1.applyMatrix4(group.matrixWorld);
394
399
  if (transverse) {
395
400
  children.forEach(childRegion => {
396
401
  boundingBox2 = childRegion.getBoundingBox(transverse);
@@ -634,10 +639,30 @@ let Region = function (parentIn) {
634
639
  */
635
640
  this.getAllObjects = transverse => {
636
641
  const objectsArray = [...zincObjects];
637
- children.forEach(childRegion => {
638
- let childObjects = childRegion.getAllObjects(transverse);
639
- objectsArray.push(...childObjects);
640
- });
642
+ if (transverse) {
643
+ children.forEach(childRegion => {
644
+ let childObjects = childRegion.getAllObjects(transverse);
645
+ objectsArray.push(...childObjects);
646
+ });
647
+ }
648
+ return objectsArray;
649
+ }
650
+
651
+ /**
652
+ * Get all child regions.
653
+ *
654
+ * @param {Boolean} transverse - Include all regions which are descendants of
655
+ * this reigon when this is set to true.
656
+ * @returns {Array}
657
+ */
658
+ this.getChildRegions = transverse => {
659
+ const objectsArray = [...children];
660
+ if (transverse) {
661
+ children.forEach(childRegion => {
662
+ const childObjects = childRegion.getChildRegions(transverse);
663
+ objectsArray.push(...childObjects);
664
+ });
665
+ }
641
666
  return objectsArray;
642
667
  }
643
668
 
package/src/scene.js CHANGED
@@ -3,6 +3,12 @@ const SceneLoader = require('./sceneLoader').SceneLoader;
3
3
  const SceneExporter = require('./sceneExporter').SceneExporter;
4
4
  const Viewport = require('./controls').Viewport;
5
5
 
6
+ let uniqueiId = 0;
7
+
8
+ const getUniqueId = function () {
9
+ return "sc" + uniqueiId++;
10
+ }
11
+
6
12
  const defaultMetadata = function() {
7
13
  return {
8
14
  Duration: "6 secs",
@@ -62,6 +68,7 @@ exports.Scene = function (containerIn, rendererIn) {
62
68
  let _markerTarget = new THREE.Vector2();
63
69
  let pickableObjectsList = [];
64
70
  this.forcePickableObjectsUpdate = false;
71
+ this.uuid = getUniqueId();
65
72
 
66
73
  const getDrawingWidth = () => {
67
74
  if (container)
@@ -860,8 +867,7 @@ exports.Scene = function (containerIn, rendererIn) {
860
867
  */
861
868
  this.updatePickableThreeJSObjects = () => {
862
869
  pickableObjectsList.splice(0, pickableObjectsList.length);
863
- rootRegion.getPickableThreeJSObjects(pickableObjectsList,
864
- this.displayMarkers, true);
870
+ rootRegion.getPickableThreeJSObjects(pickableObjectsList, true);
865
871
  this.forcePickableObjectsUpdate = false;
866
872
  }
867
873