zincjs 1.10.2 → 1.11.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.10.2",
3
+ "version": "1.11.0",
4
4
  "description": "ZincJS (Web-based-Zinc-Visualisation)",
5
5
  "main": "build/zinc.js",
6
6
  "directories": {
@@ -18,7 +18,6 @@ const mergeGeometries = (geometries) => {
18
18
  }
19
19
 
20
20
  const IndexedSourcesHandler = function(urlIn, crossOrigin, onDownloadedCallback) {
21
- const allData = [];
22
21
  const loader = new FileLoader();
23
22
  const jsonLoader = new JSONLoader();
24
23
  loader.crossOrigin = crossOrigin;
@@ -130,7 +129,6 @@ const MultiSourcesHandler = function(numberIn, onLoadCallback) {
130
129
  onLoad(geometry, materials);
131
130
  }
132
131
  }
133
-
134
132
  }
135
133
 
136
134
  exports.PrimitivesLoader = function () {
@@ -161,35 +159,47 @@ exports.PrimitivesLoader = function () {
161
159
  const newOptions = options ? {...options} : {};
162
160
  let indexedLoader = indexedLoaders[url];
163
161
  if (!indexedLoader) {
164
- const onLoadCallback = new onFinally(undefined, this, newOptions);
165
- ++concurrentDownloads;
166
- indexedLoader = new IndexedSourcesHandler(url, this.crossOrigin, onLoadCallback);
167
- indexedLoaders[url] = indexedLoader;
162
+ if (MAX_DOWNLOAD > concurrentDownloads) {
163
+ const onLoadCallback = new onFinally(undefined, this, newOptions);
164
+ ++concurrentDownloads;
165
+ indexedLoader = new IndexedSourcesHandler(url, this.crossOrigin, onLoadCallback);
166
+ indexedLoaders[url] = indexedLoader;
167
+ } else {
168
+ waitingList.push({
169
+ url,
170
+ onLoad,
171
+ onProgress,
172
+ onError,
173
+ options,
174
+ });
175
+ }
176
+ }
177
+ if (indexedLoader) {
178
+ newOptions.isHandler = indexedLoader;
179
+ indexedLoader.load(options.index, onLoad, onProgress, onError);
168
180
  }
169
- newOptions.isHandler = indexedLoader;
170
- indexedLoader.load(options.index, onLoad, onProgress, onError);
171
181
  }
172
182
 
173
183
  const loadFromSingleSource = (url, onLoad, onProgress, onError, options) => {
174
- if (MAX_DOWNLOAD > concurrentDownloads) {
175
- if (options && (options.index !== undefined) ) {
176
- handleIndexedSource(url, onLoad, onProgress, onError, options);
177
- } else {
178
- //Standard loading
184
+ if (options && (options.index !== undefined) ) {
185
+ handleIndexedSource(url, onLoad, onProgress, onError, options);
186
+ } else {
187
+ //Standard loading
188
+ if (MAX_DOWNLOAD > concurrentDownloads) {
179
189
  ++concurrentDownloads;
180
190
  const onLoadCallback = new onFinally(onLoad, this, options);
181
191
  const onErrorCallback = new onFinally(onError, this, options);
182
192
  loader.crossOrigin = this.crossOrigin;
183
193
  loader.load(url, onLoadCallback, onProgress, onErrorCallback);
194
+ } else {
195
+ waitingList.push({
196
+ url,
197
+ onLoad,
198
+ onProgress,
199
+ onError,
200
+ options,
201
+ });
184
202
  }
185
- } else {
186
- waitingList.push({
187
- url,
188
- onLoad,
189
- onProgress,
190
- onError,
191
- options,
192
- });
193
203
  }
194
204
  }
195
205
 
@@ -202,10 +212,18 @@ exports.PrimitivesLoader = function () {
202
212
  }
203
213
 
204
214
  this.loadFromWaitingList = () => {
205
- const item = waitingList.shift();
206
- if (item) {
207
- this.load(item.url, item.onLoad, item.onProgress, item.onError, item.options);
208
- } else {
215
+ while (MAX_DOWNLOAD > concurrentDownloads) {
216
+ const item = waitingList.shift();
217
+ if (item) {
218
+ this.load(item.url, item.onLoad, item.onProgress, item.onError, item.options);
219
+ } else {
220
+ return;
221
+ }
222
+ }
223
+ }
224
+
225
+ this.itemRemainingCheck = () => {
226
+ if (waitingList.length === 0 && concurrentDownloads === 0) {
209
227
  for (let key in indexedLoaders) {
210
228
  if (indexedLoaders.hasOwnProperty(key)) {
211
229
  delete indexedLoaders[key];
@@ -227,6 +245,7 @@ exports.PrimitivesLoader = function () {
227
245
  }
228
246
  }
229
247
  loader.loadFromWaitingList();
248
+ loader.itemRemainingCheck();
230
249
  }
231
250
  }
232
251
 
@@ -28,6 +28,11 @@ const Marker = function(zincObject) {
28
28
  (require('./zincObject').ZincObject).call(this);
29
29
  this.texture = texture;
30
30
  let sprite = undefined;
31
+ let userTexture = undefined;
32
+ let userMaterial = undefined;
33
+ let userSprite = undefined;
34
+ let userUrl = undefined;
35
+ let defaultDisplay = true;
31
36
  this.morph = new THREE.Group();
32
37
  this.group = this.morph;
33
38
  this.parent = zincObject;
@@ -85,6 +90,70 @@ const Marker = function(zincObject) {
85
90
  sprite.scale.multiplyScalar(size);
86
91
  }
87
92
 
93
+ this.setUserSprite = () => {
94
+ if (defaultDisplay && userSprite) {
95
+ this.morph.add(userSprite);
96
+ this.morph.remove(sprite);
97
+ if (label) {
98
+ this.morph.remove(label);
99
+ }
100
+ defaultDisplay = false;
101
+ }
102
+ }
103
+
104
+ this.setImageForUserSprite = (image, size) => {
105
+ if (userSprite) {
106
+ this.morph.remove(userSprite);
107
+ userSprite.dispose();
108
+ }
109
+ if (userTexture) userTexture.dispose();
110
+ if (userMaterial) userMaterial.dispose();
111
+ userTexture = new THREE.Texture();
112
+ userTexture.image = image;
113
+ userTexture.needsUpdate = true;
114
+ userMaterial = new THREE.SpriteMaterial({
115
+ map: userTexture,
116
+ alphaTest: 0.5,
117
+ transparent: true,
118
+ depthTest: false,
119
+ depthWrite: false,
120
+ sizeAttenuation: false
121
+ });
122
+ if (!size) {
123
+ size = [0.05, 0.05, 1];
124
+ }
125
+ userSprite = new THREE.Sprite(userMaterial);
126
+ userSprite.center.set(0.5, 0);
127
+ userSprite.scale.set(size[0], size[1], size[2]);
128
+ userSprite.userData = this;
129
+ this.setUserSprite();
130
+ }
131
+
132
+ this.setDefaultSprite = () => {
133
+ if (!defaultDisplay) {
134
+ defaultDisplay = true;
135
+ this.morph.add(sprite);
136
+ if (userSprite) this.morph.remove(userSprite);
137
+ if (label) this.morph.add(label);
138
+ }
139
+ }
140
+
141
+ this.loadUserSprite = (url, size) => {
142
+ if (url) {
143
+ if (url !== userUrl) {
144
+ userUrl = url;
145
+ const userImage = new Image(128, 128);
146
+ userImage.crossOrigin = "anonymous"
147
+ userImage.onload = () => {
148
+ this.setImageForUserSprite(userImage, size);
149
+ };
150
+ userImage.src = url;
151
+ } else {
152
+ this.setUserSprite();
153
+ }
154
+ }
155
+ }
156
+
88
157
  /**
89
158
  * Clean up this object,
90
159
  */
@@ -550,6 +550,11 @@ ZincObject.prototype.updateMarker = function(playAnimation, options) {
550
550
  this.group.add(this.marker.morph);
551
551
  }
552
552
  this.marker.setNumber(this.markerNumber);
553
+ if (this.markerImgURL) {
554
+ this.marker.loadUserSprite(this.markerImgURL);
555
+ } else {
556
+ this.marker.setDefaultSprite();
557
+ }
553
558
  if (options && options.camera && (ndcToBeUpdated ||
554
559
  options.markerCluster.markerUpdateRequired)) {
555
560
  this.marker.updateNDC(options.camera.cameraObject);
@@ -634,6 +639,7 @@ ZincObject.prototype.getClosestVertexDOMElementCoords = function(scene) {
634
639
  }
635
640
  if (options) {
636
641
  this.markerNumber = options.number;
642
+ this.markerImgURL = options.imgURL;
637
643
  }
638
644
  }
639
645
 
package/src/scene.js CHANGED
@@ -1247,14 +1247,18 @@ exports.Scene = function (containerIn, rendererIn) {
1247
1247
 
1248
1248
  /*
1249
1249
  * Remove all temporary primitives.
1250
+ * Return number of primitives removed;
1250
1251
  */
1251
1252
  this.clearTemporaryPrimitives = () => {
1253
+ let i = 0;
1252
1254
  const children = tempGroup.children;
1253
1255
  children.forEach(child => {
1254
1256
  child.geometry.dispose();
1255
1257
  child.material.dispose();
1258
+ i++;
1256
1259
  });
1257
1260
  tempGroup.clear();
1261
+ return i;
1258
1262
  }
1259
1263
 
1260
1264
  /*