zincjs 1.6.0 → 1.8.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.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "ZincJS (Web-based-Zinc-Visualisation)",
5
5
  "main": "build/zinc.js",
6
6
  "directories": {
@@ -1,11 +1,34 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
3
2
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
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
- viewBox="0 0 365 560" enable-background="new 0 0 365 560" xml:space="preserve">
6
- <g>
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
- 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
- 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
- </g>
11
- </svg>
3
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="365" height="560" viewBox="0 0 365 560" xml:space="preserve">
4
+ <desc>Created with Fabric.js 5.2.4</desc>
5
+ <defs>
6
+ </defs>
7
+ <rect x="0" y="0" width="100%" height="100%" fill="transparent"></rect>
8
+ <g transform="matrix(0 0 0 0 0 0)" id="808ed283-2524-440f-88ae-3bdb47bb5749" >
9
+ </g>
10
+ <g transform="matrix(1 0 0 1 182.5 280)" id="db30413d-5bff-4b98-ab59-464497ee199e" >
11
+ <rect style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1; visibility: hidden;" vector-effect="non-scaling-stroke" x="-182.5" y="-280" rx="0" ry="0" width="365" height="560" />
12
+ </g>
13
+ <g transform="matrix(0 0 0 0 0 97.5)" >
14
+ <g style="" >
15
+ </g>
16
+ </g>
17
+ <g transform="matrix(0 0 0 0 0 97.5)" >
18
+ <g style="" >
19
+ </g>
20
+ </g>
21
+ <g transform="matrix(0.99 0 0 0.99 182.5 280)" >
22
+ <g style="" vector-effect="non-scaling-stroke" >
23
+ <g transform="matrix(1 0 0 1 0 0)" >
24
+ <rect style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1; visibility: hidden;" vector-effect="non-scaling-stroke" x="-540" y="-540" rx="0" ry="0" width="1080" height="1080" />
25
+ </g>
26
+ <g transform="matrix(1 0 0 1 0 0)" >
27
+ <path style="stroke: rgb(0,0,0); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,89,116); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-182.9, -279.85)" d="M 182.9 551.7 C 182.9 551.8000000000001 183.1 552 183.1 552 C 183.1 552 358.3 283 358.3 194.6 C 358.3 64.5 269.5 7.900000000000006 182.9 7.699999999999989 C 96.3 7.9 7.5 64.5 7.5 194.6 C 7.5 283 182.8 552 182.8 552 C 182.8 552 182.9 551.7 182.9 551.7 z M 122.2 187.2 C 122.2 153.6 149.4 126.39999999999999 183 126.39999999999999 C 216.6 126.39999999999999 243.8 153.6 243.8 187.2 C 243.8 220.79999999999998 216.5 248 182.9 248 C 149.4 248 122.2 220.8 122.2 187.2 z" stroke-linecap="round" />
28
+ </g>
29
+ <g transform="matrix(3.82 0 0 3.82 0 -100.77)" >
30
+ <circle style="stroke: rgb(0,0,0); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" cx="0" cy="0" r="35" />
31
+ </g>
32
+ </g>
33
+ </g>
34
+ </svg>
@@ -4,7 +4,7 @@ markerImage.src = require("../assets/mapMarker.svg");
4
4
  const texture = new THREE.Texture();
5
5
  texture.image = markerImage;
6
6
  texture.needsUpdate = true;
7
- const size = [0.017, 0.025, 1];
7
+ const size = [0.02, 0.03, 1];
8
8
  const spriteMaterial = new THREE.SpriteMaterial({
9
9
  map: texture,
10
10
  alphaTest: 0.5,
@@ -12,7 +12,8 @@ const spriteMaterial = new THREE.SpriteMaterial({
12
12
  depthTest: false,
13
13
  depthWrite: false,
14
14
  sizeAttenuation: false
15
- });
15
+ });
16
+ const createNewSpriteText = require('../utilities').createNewSpriteText;
16
17
 
17
18
  /**
18
19
  * A special graphics type with a tear drop shape.
@@ -33,6 +34,8 @@ const Marker = function(zincObject) {
33
34
  this.isMarker = true;
34
35
  let enabled = false;
35
36
  this.ndc = new THREE.Vector3();
37
+ let number = undefined;
38
+ let label = undefined;
36
39
 
37
40
  let initialise = () => {
38
41
  sprite = new THREE.Sprite(spriteMaterial);
@@ -93,12 +96,38 @@ const Marker = function(zincObject) {
93
96
  sprite.clear();
94
97
  sprite = undefined;
95
98
  }
99
+ if (label) {
100
+ label.material.map.dispose();
101
+ label.material.dispose();
102
+ label = undefined;
103
+ }
96
104
  }
97
105
 
98
106
  this.isEnabled = () => {
99
107
  return enabled;
100
108
  }
101
109
 
110
+ this.setNumber = (numberIn) => {
111
+ if (!numberIn || (number != numberIn)) {
112
+ //remove label
113
+ if (label) {
114
+ this.morph.remove(label);
115
+ label.material.map.dispose();
116
+ label.material.dispose();
117
+ label = undefined;
118
+ }
119
+ }
120
+ if (!label && numberIn) {
121
+ label = createNewSpriteText(numberIn, 0.012, "black", "Asap", 50, 500);
122
+ this.morph.add(label);
123
+ }
124
+ number = numberIn;
125
+ }
126
+
127
+ this.getNumber = () => {
128
+ return number ? number : 1;
129
+ }
130
+
102
131
  /**
103
132
  * Set the visibility of this Geometry.
104
133
  *
@@ -1,5 +1,4 @@
1
1
  const THREE = require('three');
2
- const SpriteText = require('three-spritetext').default;
3
2
  const markerImage = new Image(128, 128);
4
3
  markerImage.src = require("../assets/mapMarkerOrange.svg");
5
4
  const texture = new THREE.Texture();
@@ -14,18 +13,7 @@ const spriteMaterial = new THREE.SpriteMaterial({
14
13
  depthWrite: false,
15
14
  sizeAttenuation: false
16
15
  });
17
-
18
- const createNewLabel = (text, height, colour, font, pixel, weight) => {
19
- const sprite = new SpriteText(text, height, colour, font, pixel, weight);
20
- sprite.material.sizeAttenuation = false;
21
- sprite.material.alphaTest = 0.5;
22
- sprite.material.transparent = true;
23
- sprite.material.depthWrite = false;
24
- sprite.material.depthTest = false;
25
- sprite.center.set(0.5, -1.2);
26
- sprite.renderOrder = 10000;
27
- return sprite;
28
- }
16
+ const createNewSpriteText = require('../utilities').createNewSpriteText;
29
17
 
30
18
  /**
31
19
  * A special graphics type with a tear drop shape.
@@ -93,25 +81,25 @@ const MarkerCluster = function(sceneIn) {
93
81
  "group": localGroup,
94
82
  "marker": sprite,
95
83
  "label": undefined,
96
- "length": 0,
84
+ "number": 0,
97
85
  "min": [0, 0, 0],
98
86
  "max": [1, 1, 1],
99
87
  };
100
88
  }
101
89
 
102
- const activateSpriteForCluster = (sprite, cluster, length) => {
90
+ const activateSpriteForCluster = (sprite, cluster, number) => {
103
91
  sprite.group.visible = true;
104
92
  sprite.group.position.set(
105
93
  cluster.coords[0], cluster.coords[1], cluster.coords[2]
106
94
  );
107
- if (sprite.label === undefined || (length !== sprite.length)) {
95
+ if (sprite.label === undefined || (number !== sprite.number)) {
108
96
  if (sprite.label) {
109
97
  sprite.group.remove(sprite.label);
110
98
  sprite.label.material.map.dispose();
111
99
  sprite.label.material.dispose();
112
100
  }
113
- sprite.label = createNewLabel(length, 0.012, "black", "Asap", 50, 500);
114
- sprite.length = length;
101
+ sprite.label = createNewSpriteText(number, 0.012, "black", "Asap", 50, 500);
102
+ sprite.number = number;
115
103
  sprite.group.add(sprite.label);
116
104
  }
117
105
  sprite.min = cluster.min;
@@ -122,16 +110,18 @@ const MarkerCluster = function(sceneIn) {
122
110
  let currentIndex = 0;
123
111
  clusters.forEach((cluster) => {
124
112
  const length = cluster.members.length;
113
+ let number = 0;
125
114
  if (length === 1) {
126
115
  cluster.members[0].setVisibility(true);
127
116
  } else {
128
117
  cluster.members.forEach((marker) => {
118
+ number += marker.getNumber();
129
119
  marker.setVisibility(false);
130
120
  });
131
121
  if (!sprites[currentIndex]) {
132
122
  sprites.push(createNewSprite(currentIndex));
133
123
  }
134
- activateSpriteForCluster(sprites[currentIndex], cluster, length);
124
+ activateSpriteForCluster(sprites[currentIndex], cluster, number);
135
125
  currentIndex++;
136
126
  }
137
127
  });
@@ -25,7 +25,6 @@ const TexturePrimitive = function (textureIn) {
25
25
  const texture = new (require('../texture/textureArray').TextureArray)();
26
26
  const imgArray = [];
27
27
  textureData.images.source.forEach(img => {
28
- console.log(resolveURL(img))
29
28
  imgArray.push(resolveURL(img));
30
29
  });
31
30
  const _this = this;
@@ -41,6 +41,7 @@ const ZincObject = function() {
41
41
  this.userData = {};
42
42
  this.videoHandler = undefined;
43
43
  this.marker = undefined;
44
+ this.markerNumber = undefined;
44
45
  this.markerUpdateRequired = true;
45
46
  this.closestVertexIndex = -1;
46
47
  this.boundingBoxUpdateRequired = true;
@@ -251,7 +252,6 @@ ZincObject.prototype.setMorphTime = function(time) {
251
252
  }
252
253
  if (timeChanged) {
253
254
  this.boundingBoxUpdateRequired = true;
254
- const morph = this._lod.getCurrentMorph();
255
255
  this._lod.updateMorphColorAttribute(true);
256
256
  if (this.timeEnabled)
257
257
  this.markerUpdateRequired = true;
@@ -548,6 +548,7 @@ ZincObject.prototype.updateMarker = function(playAnimation, options) {
548
548
  this.marker.enable();
549
549
  this.group.add(this.marker.morph);
550
550
  }
551
+ this.marker.setNumber(this.markerNumber);
551
552
  if (options && options.camera && (ndcToBeUpdated ||
552
553
  options.markerCluster.markerUpdateRequired)) {
553
554
  this.marker.updateNDC(options.camera.cameraObject);
@@ -619,7 +620,7 @@ ZincObject.prototype.getClosestVertexDOMElementCoords = function(scene) {
619
620
  *
620
621
  * @return {Boolean}
621
622
  */
622
- ZincObject.prototype.setMarkerMode = function(mode) {
623
+ ZincObject.prototype.setMarkerMode = function(mode, options) {
623
624
  if (mode !== this.markerMode) {
624
625
  if (mode === "on" || mode === "off") {
625
626
  this.markerMode = mode;
@@ -630,6 +631,9 @@ ZincObject.prototype.getClosestVertexDOMElementCoords = function(scene) {
630
631
  this.region.pickableUpdateRequired = true;
631
632
  }
632
633
  }
634
+ if (options) {
635
+ this.markerNumber = options.number;
636
+ }
633
637
  }
634
638
 
635
639
  //Update the geometry and colours depending on the morph.
package/src/region.js CHANGED
@@ -321,7 +321,11 @@ let Region = function (parentIn, sceneIn) {
321
321
  if (zincObject === zincObjects[i]) {
322
322
  group.remove(zincObject.getGroup());
323
323
  zincObjects.splice(i, 1);
324
+ if (scene) {
325
+ scene.triggerObjectRemovedCallback(zincObject);
326
+ }
324
327
  zincObject.dispose();
328
+ this.pickableUpdateRequired = true;
325
329
  return;
326
330
  }
327
331
  }
@@ -750,16 +754,18 @@ let Region = function (parentIn, sceneIn) {
750
754
  //process markers visibility and size, as long as there are more than
751
755
  //one entry in markersList is greater than 1, markers have been enabled.
752
756
  if (options && (playAnimation === false) &&
753
- options?.markerCluster?.markerUpdateRequired) {
754
- const markerDepths = Object.values(options.markersList)
755
- .map((marker) => marker.ndc.z);
756
- if (markerDepths.length > 1) {
757
- const min = Math.min(...markerDepths);
758
- const max = Math.max(...markerDepths);
759
- allObjects.forEach(zincObject => {
760
- zincObject.processMarkerVisual(min, max);
761
- });
762
- }
757
+ options.markerCluster?.markerUpdateRequired) {
758
+ /**
759
+ const markerDepths = Object.values(options.markersList)
760
+ .map((marker) => marker.ndc.z);
761
+ if (markerDepths.length > 1) {
762
+ const min = Math.min(...markerDepths);
763
+ const max = Math.max(...markerDepths);
764
+ allObjects.forEach(zincObject => {
765
+ zincObject.processMarkerVisual(min, max);
766
+ });
767
+ }
768
+ */
763
769
  options.markerCluster.calculate();
764
770
  }
765
771
  }
package/src/scene.js CHANGED
@@ -39,6 +39,8 @@ exports.Scene = function (containerIn, rendererIn) {
39
39
  let minimap = undefined;
40
40
  let zincObjectAddedCallbacks = {};
41
41
  let zincObjectAddedCallbacks_id = 0;
42
+ let zincObjectRemovedCallbacks = {};
43
+ let zincObjectRemovedCallbacks_id = 0;
42
44
  const scene = new THREE.Scene();
43
45
  const rootRegion = new (require('./region').Region)(undefined, this);
44
46
  scene.add(rootRegion.getGroup());
@@ -968,6 +970,7 @@ exports.Scene = function (containerIn, rendererIn) {
968
970
  markerCluster.clear();
969
971
  rootRegion.clear(true);
970
972
  this.clearZincObjectAddedCallbacks();
973
+ this.clearZincObjectRemovedCallbacks();
971
974
  sceneLoader.toBeDwonloaded = 0;
972
975
  if (zincCameraControls) {
973
976
  zincCameraControls.calculateMaxAllowedDistance(this);
@@ -1126,6 +1129,18 @@ exports.Scene = function (containerIn, rendererIn) {
1126
1129
  zincObjectAddedCallbacks[zincObjectAddedCallbacks_id] = callbackFunction;
1127
1130
  return zincObjectAddedCallbacks_id;
1128
1131
  }
1132
+
1133
+ /**
1134
+ * Add a callback function which will be called everytime zinc object is removed.
1135
+ * @param {Function} callbackFunction - callbackFunction to be added.
1136
+ *
1137
+ * @return {Number}
1138
+ */
1139
+ this.addZincObjectRemovedCallbacks = callbackFunction => {
1140
+ zincObjectRemovedCallbacks_id = zincObjectRemovedCallbacks_id + 1;
1141
+ zincObjectRemovedCallbacks[zincObjectRemovedCallbacks_id] = callbackFunction;
1142
+ return zincObjectRemovedCallbacks_id;
1143
+ }
1129
1144
 
1130
1145
  /**
1131
1146
  * Remove a callback function that is previously added to the scene.
@@ -1137,6 +1152,16 @@ exports.Scene = function (containerIn, rendererIn) {
1137
1152
  }
1138
1153
  }
1139
1154
 
1155
+ /**
1156
+ * Remove a callback function that is previously added to the scene.
1157
+ * @param {Number} id - identifier of the previously added callback function.
1158
+ */
1159
+ this.removeZincObjectRemovedCallbacks = id => {
1160
+ if (id in zincObjectRemovedCallbacks_id) {
1161
+ delete zincObjectRemovedCallbacks[id];
1162
+ }
1163
+ }
1164
+
1140
1165
  /**
1141
1166
  * Clear all zinc object callback function
1142
1167
  */
@@ -1145,6 +1170,14 @@ exports.Scene = function (containerIn, rendererIn) {
1145
1170
  zincObjectAddedCallbacks_id = 0;
1146
1171
  }
1147
1172
 
1173
+ /**
1174
+ * Clear all zinc object callback function
1175
+ */
1176
+ this.clearZincObjectRemovedCallbacks = () => {
1177
+ zincObjectRemovedCallbacks = {};
1178
+ zincObjectRemovedCallbacks_id = 0;
1179
+ }
1180
+
1148
1181
  /**
1149
1182
  * Used to trigger zinc object added callback
1150
1183
  */
@@ -1156,6 +1189,17 @@ exports.Scene = function (containerIn, rendererIn) {
1156
1189
  }
1157
1190
  }
1158
1191
 
1192
+ /**
1193
+ * Used to trigger zinc object removed callback
1194
+ */
1195
+ this.triggerObjectRemovedCallback= (zincObject) => {
1196
+ for (let key in zincObjectRemovedCallbacks) {
1197
+ if (zincObjectRemovedCallbacks.hasOwnProperty(key)) {
1198
+ zincObjectRemovedCallbacks[key](zincObject);
1199
+ }
1200
+ }
1201
+ }
1202
+
1159
1203
  /*
1160
1204
  * Add temporary points to the scene which can be removed
1161
1205
  * with clearTemporaryPrimitives method.
package/src/utilities.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const THREE = require('three');
2
2
  const THREEGeometry = require('./three/Geometry').Geometry;
3
+ const SpriteText = require('three-spritetext').default;
3
4
 
4
5
  function resolveURL(url) {
5
6
  let actualURL = url;
@@ -439,6 +440,17 @@ function getCircularTexture() {
439
440
  return texture;
440
441
  }
441
442
 
443
+ function createNewSpriteText(text, height, colour, font, pixel, weight) {
444
+ const sprite = new SpriteText(text, height, colour, font, pixel, weight);
445
+ sprite.material.sizeAttenuation = false;
446
+ sprite.material.alphaTest = 0.5;
447
+ sprite.material.transparent = true;
448
+ sprite.material.depthWrite = false;
449
+ sprite.material.depthTest = false;
450
+ sprite.center.set(0.5, -1.2);
451
+ sprite.renderOrder = 10000;
452
+ return sprite;
453
+ }
442
454
 
443
455
  exports.getBoundingBox = getBoundingBox;
444
456
  exports.createNewURL = createNewURL;
@@ -448,3 +460,4 @@ exports.resolveURL = resolveURL;
448
460
  exports.loadExternalFile = loadExternalFile;
449
461
  exports.loadExternalFiles = loadExternalFiles;
450
462
  exports.PhongToToon = PhongToToon;
463
+ exports.createNewSpriteText = createNewSpriteText;
package/src/zinc.js CHANGED
@@ -18,6 +18,7 @@ const Zinc = function() {
18
18
  this.Glyph = require('./primitives/glyph').Glyph;
19
19
  this.Glyphset = require('./primitives/glyphset').Glyphset;
20
20
  this.Pointset = require('./primitives/pointset').Pointset;
21
+ this.Label = require('./primitives/label').Label;
21
22
  this.Lines = require('./primitives/lines').Lines;
22
23
  this.TextureArray = require('./texture/textureArray').TextureArray;
23
24
  this.TextureSlides = require('./primitives/textureSlides').TextureSlides;