zincjs 1.0.13 → 1.0.15

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.
Files changed (45) hide show
  1. package/build/zinc.frontend.js +1 -1
  2. package/build/zinc.js +43 -35
  3. package/build/zinc.js.map +1 -1
  4. package/package.json +3 -3
  5. package/src/assets/disc.png +0 -0
  6. package/src/assets/mapMarker.svg +11 -0
  7. package/src/controls.js +1594 -0
  8. package/src/geometryCSG.js +148 -0
  9. package/src/glyphsetCSG.js +84 -0
  10. package/src/loaders/GLTFToZincJSLoader.js +85 -0
  11. package/src/loaders/JSONLoader.js +697 -0
  12. package/src/loaders/OBJLoader.js +911 -0
  13. package/src/loaders/STLLoader.js +399 -0
  14. package/src/loaders/primitivesLoader.js +46 -0
  15. package/src/minimap.js +82 -0
  16. package/src/primitives/augmentShader.js +22 -0
  17. package/src/primitives/geometry.js +109 -0
  18. package/src/primitives/glyph.js +150 -0
  19. package/src/primitives/glyphset.js +657 -0
  20. package/src/primitives/label.js +51 -0
  21. package/src/primitives/lines.js +35 -0
  22. package/src/primitives/marker.js +88 -0
  23. package/src/primitives/pointset.js +53 -0
  24. package/src/primitives/texturePrimitive.js +16 -0
  25. package/src/primitives/textureSlides.js +118 -0
  26. package/src/primitives/zincObject.js +573 -0
  27. package/src/region.js +554 -0
  28. package/src/renderer.js +612 -0
  29. package/src/scene.js +963 -0
  30. package/src/sceneExporter.js +32 -0
  31. package/src/sceneLoader.js +842 -0
  32. package/src/texture/texture.js +57 -0
  33. package/src/texture/textureArray.js +85 -0
  34. package/src/three/GLTFExporter.js +2448 -0
  35. package/src/three/Geometry.js +2084 -0
  36. package/src/three/Loader.js +344 -0
  37. package/src/three/Points.js +223 -0
  38. package/src/three/line/Line.js +293 -0
  39. package/src/three/line/LineSegments.js +65 -0
  40. package/src/three-js-csg.js +564 -0
  41. package/src/utilities.js +321 -0
  42. package/src/videoHandler.js +92 -0
  43. package/src/workers/geometryCSG.worker.js +73 -0
  44. package/src/workers/geometryCSGInternal.js +58 -0
  45. package/src/zinc.js +38 -0
package/src/region.js ADDED
@@ -0,0 +1,554 @@
1
+ const { Group, Matrix4 } = require('three');
2
+
3
+ let Region = function (parentIn) {
4
+ let parent = parentIn;
5
+ let group = new Group();
6
+ group.matrixAutoUpdate = false;
7
+ group.userData = this;
8
+ let children = [];
9
+ let name = "";
10
+ let zincObjects = [];
11
+ const tMatrix = new Matrix4();
12
+ let duration = 3000;
13
+ tMatrix.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
14
+ this.pickableUpdateRequired = true;
15
+
16
+ this.hideAllPrimitives = () => {
17
+ children.forEach(child => child.hideAllPrimitives());
18
+ zincObjects.forEach(zincObject => zincObject.setVisibility(false));
19
+ }
20
+
21
+ this.showAllPrimitives = () => {
22
+ children.forEach(child => child.showAllPrimitives());
23
+ zincObjects.forEach(zincObject => zincObject.setVisibility(true));
24
+ }
25
+
26
+ /***
27
+ * Set the visibility and propagate it up and down the hierarchies
28
+ * depending on the flag
29
+ */
30
+ this.setVisibility = (flag) => {
31
+ group.visible = flag;
32
+ }
33
+
34
+ this.getVisibility = () => {
35
+ return group.visible;
36
+ }
37
+
38
+ this.getGroup = () => {
39
+ return group;
40
+ }
41
+
42
+ this.setTransformation = transformation => {
43
+ tMatrix.set(...transformation);
44
+ group.matrix.copy(tMatrix);
45
+ group.updateMatrixWorld();
46
+ }
47
+
48
+ this.setName = (nameIn) => {
49
+ if (nameIn && nameIn !== "") {
50
+ name = nameIn;
51
+ }
52
+ }
53
+
54
+ this.getName = () => {
55
+ return name;
56
+ }
57
+
58
+ this.getParent = () => {
59
+ return parent;
60
+ }
61
+
62
+ //This function returns the full path until it reaches the root
63
+ this.getFullSeparatedPath = () => {
64
+ const paths = [];
65
+ if (name !== "") {
66
+ paths.push(name);
67
+ for (let p = parent; p !== undefined;) {
68
+ const parentName = p.getName();
69
+ if (parentName !== "") {
70
+ paths.unshift(parentName);
71
+ }
72
+ p = p.getParent();
73
+ }
74
+ }
75
+ return paths;
76
+ }
77
+
78
+ //This function returns the full path until it reaches the root
79
+ this.getFullPath = () => {
80
+ const paths = this.getFullSeparatedPath();
81
+ if (paths.length > 0) {
82
+ let fullPath = paths.shift();
83
+ paths.forEach(path => {
84
+ fullPath = fullPath.concat("/", path);
85
+ });
86
+ return fullPath;
87
+ }
88
+ return "";
89
+ }
90
+
91
+ this.createChild = (nameIn) => {
92
+ let childRegion = new Region(this);
93
+ childRegion.setName(nameIn);
94
+ children.push(childRegion);
95
+ group.add(childRegion.getGroup());
96
+ return childRegion;
97
+ }
98
+
99
+ this.getChildWithName = childName => {
100
+ if (childName) {
101
+ const lowerChildName = childName.toLowerCase();
102
+ for (let i = 0; i < children.length; i++) {
103
+ if (children[i].getName().toLowerCase() === lowerChildName)
104
+ return children[i];
105
+ }
106
+ }
107
+ return undefined;
108
+ }
109
+
110
+ this.findChildFromSeparatedPath = pathArray => {
111
+ if (pathArray && pathArray.length > 0) {
112
+ if (pathArray[0] === "") {
113
+ pathArray.shift();
114
+ }
115
+ }
116
+ if (pathArray && pathArray.length > 0) {
117
+ const childRegion = this.getChildWithName(pathArray[0]);
118
+ if (childRegion) {
119
+ pathArray.shift();
120
+ return childRegion.findChildFromSeparatedPath(pathArray);
121
+ } else {
122
+ return undefined;
123
+ }
124
+ }
125
+ return this;
126
+ }
127
+
128
+ this.findChildFromPath = (path) => {
129
+ const pathArray = path.split("/");
130
+ return this.findChildFromSeparatedPath(pathArray);
131
+ }
132
+
133
+ this.createChildFromSeparatedPath = pathArray => {
134
+ if (pathArray.length > 0) {
135
+ if (pathArray[0] === "") {
136
+ pathArray.shift();
137
+ }
138
+ }
139
+ if (pathArray.length > 0) {
140
+ let childRegion = this.getChildWithName(pathArray[0]);
141
+ if (!childRegion) {
142
+ childRegion = this.createChild(pathArray[0]);
143
+ }
144
+ pathArray.shift();
145
+ return childRegion.createChildFromSeparatedPath(pathArray);
146
+ }
147
+ return this;
148
+ }
149
+
150
+ this.createChildFromPath = (path) => {
151
+ const pathArray = path.split("/");
152
+ return this.createChildFromSeparatedPath(pathArray);
153
+ }
154
+
155
+ this.findOrCreateChildFromPath = (path) => {
156
+ let childRegion = this.findChildFromPath(path);
157
+ if (!childRegion) {
158
+ childRegion = this.createChildFromPath(path);
159
+ }
160
+ return childRegion;
161
+ }
162
+
163
+ this.addZincObject = zincObject => {
164
+ if (zincObject) {
165
+ zincObject.setRegion(this);
166
+ group.add(zincObject.morph);
167
+ zincObjects.push(zincObject);
168
+ this.pickableUpdateRequired = true;
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Remove a ZincObject from this region if it presents. This will eventually
174
+ * destroy the object and free up the memory.
175
+ * @param {Zinc.Object} zincObject - object to be removed from this region.
176
+ */
177
+ this.removeZincObject = zincObject => {
178
+ for (let i = 0; i < zincObjects.length; i++) {
179
+ if (zincObject === zincObjects[i]) {
180
+ group.remove(zincObject.morph);
181
+ zincObjects.splice(i, 1);
182
+ zincObject.dispose();
183
+ return;
184
+ }
185
+ }
186
+ }
187
+
188
+ this.checkPickableUpdateRequred = (transverse) => {
189
+ if (this.pickableUpdateRequired) return true;
190
+ if (transverse) {
191
+ let flag = false;
192
+ for (let i = 0; i < children.length; i++) {
193
+ flag = children[i].checkPickableUpdateRequred(transverse);
194
+ if (flag) return true;
195
+ }
196
+ }
197
+ return false;
198
+ }
199
+
200
+ /**
201
+ * Get all pickable objects.
202
+ */
203
+ this.getPickableThreeJSObjects = (objectsList, pickMarkers, transverse) => {
204
+ zincObjects.forEach(zincObject => {
205
+ if (zincObject.morph && zincObject.morph.visible) {
206
+ if (pickMarkers) {
207
+ let marker = zincObject.marker;
208
+ if (marker && marker.isEnabled()) {
209
+ objectsList.push(marker.morph);
210
+ }
211
+ } else {
212
+ objectsList.push(zincObject.morph);
213
+ }
214
+ }
215
+ });
216
+ if (transverse) {
217
+ children.forEach(childRegion => {
218
+ childRegion.getPickableThreeJSObjects(objectsList, pickMarkers,
219
+ transverse);
220
+ });
221
+ }
222
+ this.pickableUpdateRequired = false;
223
+ return objectsList;
224
+ }
225
+
226
+ /**
227
+ * Set the default duration value for all zinc objects
228
+ * that are to be loaded into this region.
229
+ * @param {Number} durationIn - duration of the scene.
230
+ */
231
+ this.setDuration = durationIn => {
232
+ duration = durationIn;
233
+ zincObjects.forEach(zincObject => zincObject.setDuration(durationIn));
234
+ children.forEach(childRegion => childRegion.setDuration(durationIn));
235
+ }
236
+
237
+ /**
238
+ * Get the default duration value.
239
+ * returns {Number}
240
+ */
241
+ this.getDuration = () => {
242
+ return duration;
243
+ }
244
+
245
+ /**
246
+ * Get the bounding box of all the object in this and child regions only.
247
+ *
248
+ * @returns {THREE.Box3}
249
+ */
250
+ this.getBoundingBox = transverse => {
251
+ let boundingBox1 = undefined, boundingBox2 = undefined;
252
+ zincObjects.forEach(zincObject => {
253
+ boundingBox2 = zincObject.getBoundingBox();
254
+ if (boundingBox2) {
255
+ if (boundingBox1 == undefined) {
256
+ boundingBox1 = boundingBox2.clone();
257
+ } else {
258
+ boundingBox1.union(boundingBox2);
259
+ }
260
+ }
261
+ });
262
+ if (boundingBox1)
263
+ boundingBox1.applyMatrix4(group.matrixWorld);
264
+ if (transverse) {
265
+ children.forEach(childRegion => {
266
+ boundingBox2 = childRegion.getBoundingBox(transverse);
267
+ if (boundingBox2) {
268
+ if (boundingBox1 == undefined) {
269
+ boundingBox1 = boundingBox2.clone();
270
+ } else {
271
+ boundingBox1.union(boundingBox2);
272
+ }
273
+ }
274
+ });
275
+ }
276
+ return boundingBox1;
277
+ }
278
+
279
+ this.clear = transverse => {
280
+ if (transverse) {
281
+ children.forEach(childRegion => childRegion.clear(transverse));
282
+ }
283
+ zincObjects.forEach(zincObject => {
284
+ group.remove(zincObject.morph);
285
+ zincObject.dispose();
286
+ });
287
+ children = [];
288
+ zincObjects = [];
289
+ }
290
+
291
+ this.objectIsInRegion = (zincObject, transverse) => {
292
+ for (let i = 0; i < zincObjects.length; i++) {
293
+ if (zincObject === zincObjects[i]) {
294
+ return true;
295
+ }
296
+ }
297
+ if (transverse) {
298
+ for (let i = 0; i < children.length; i++) {
299
+ if (children[i].objectIsInRegion(zincObject, transverse))
300
+ return true;
301
+ }
302
+ }
303
+
304
+ return false;
305
+ }
306
+
307
+ /**
308
+ * A function which iterates through the list of geometries and call the callback
309
+ * function with the geometries as the argument.
310
+ * @param {Function} callbackFunction - Callback function with the geometry
311
+ * as an argument.
312
+ */
313
+ this.forEachGeometry = (callbackFunction, transverse) => {
314
+ zincObjects.forEach(zincObject => {
315
+ if (zincObject.isGeometry)
316
+ callbackFunction(zincObject);
317
+ });
318
+ if (transverse)
319
+ children.forEach(childRegion => childRegion.forEachGeometry(
320
+ callbackFunction, transverse));
321
+ }
322
+
323
+ /**
324
+ * A function which iterates through the list of glyphsets and call the callback
325
+ * function with the glyphset as the argument.
326
+ * @param {Function} callbackFunction - Callback function with the glyphset
327
+ * as an argument.
328
+ */
329
+ this.forEachGlyphset = (callbackFunction, transverse) => {
330
+ zincObjects.forEach(zincObject => {
331
+ if (zincObject.isGlyphset)
332
+ callbackFunction(zincObject);
333
+ });
334
+ if (transverse)
335
+ children.forEach(childRegion => childRegion.forEachGlyphset(
336
+ callbackFunction, transverse));
337
+ }
338
+
339
+ /**
340
+ * A function which iterates through the list of pointsets and call the callback
341
+ * function with the pointset as the argument.
342
+ * @param {Function} callbackFunction - Callback function with the pointset
343
+ * as an argument.
344
+ */
345
+ this.forEachPointset = (callbackFunction, transverse) => {
346
+ zincObjects.forEach(zincObject => {
347
+ if (zincObject.isPointset)
348
+ callbackFunction(zincObject);
349
+ });
350
+ if (transverse)
351
+ children.forEach(childRegion => childRegion.forEachPointset(
352
+ callbackFunction, transverse));
353
+ }
354
+
355
+ /**
356
+ * A function which iterates through the list of lines and call the callback
357
+ * function with the lines as the argument.
358
+ * @param {Function} callbackFunction - Callback function with the lines
359
+ * as an argument.
360
+ */
361
+ this.forEachLine = (callbackFunction, transverse) => {
362
+ zincObjects.forEach(zincObject => {
363
+ if (zincObject.isLines)
364
+ callbackFunction(zincObject);
365
+ });
366
+ if (transverse)
367
+ children.forEach(childRegion => childRegion.forEachLine(
368
+ callbackFunction, transverse));
369
+ }
370
+
371
+ this.findObjectsWithAnatomicalId = (anatomicalId, transverse) => {
372
+ zincObjects.forEach(zincObject => {
373
+ if (zincObject.anatomicalId === anatomicalId)
374
+ objectsArray.push(zincObject);
375
+ });
376
+ if (transverse) {
377
+ children.forEach(childRegion => {
378
+ let childObjects = childRegion.findObjectsWithAnatomicalId(anatomicalId, transverse);
379
+ objectsArray.push(...childObjects);
380
+ });
381
+ }
382
+
383
+ return objectsArray;
384
+ }
385
+
386
+ /**
387
+ * Find and return all zinc objects in this and child regions with
388
+ * the matching GroupName.
389
+ *
390
+ * @param {String} groupName - Groupname to match with.
391
+ * @returns {Array}
392
+ */
393
+ this.findObjectsWithGroupName = (groupName, transverse) => {
394
+ const objectsArray = [];
395
+ zincObjects.forEach(zincObject => {
396
+ const lowerObjectName = zincObject.groupName ? zincObject.groupName.toLowerCase() : zincObject.groupName;
397
+ const lowerGroupName = groupName ? groupName.toLowerCase() : groupName;
398
+ if (lowerObjectName === lowerGroupName)
399
+ objectsArray.push(zincObject);
400
+ });
401
+ if (transverse) {
402
+ children.forEach(childRegion => {
403
+ let childObjects = childRegion.findObjectsWithGroupName(groupName, transverse);
404
+ objectsArray.push(...childObjects);
405
+ });
406
+ }
407
+ return objectsArray;
408
+ }
409
+
410
+ /**
411
+ * Find and return all geometries in this and child regions with
412
+ * the matching GroupName.
413
+ *
414
+ * @param {String} groupName - Groupname to match with.
415
+ * @returns {Array}
416
+ */
417
+ this.findGeometriesWithGroupName = (groupName, transverse) => {
418
+ const primitivesArray = this.findObjectsWithGroupName(groupName, transverse);
419
+ const geometriesArray = primitivesArray.filter(primitive => primitive.isGeometry);
420
+ return geometriesArray;
421
+ }
422
+
423
+ /**
424
+ * Find and return all pointsets in this and child regions with
425
+ * the matching groupName.
426
+ *
427
+ * @param {String} groupName - Groupname to match with.
428
+ * @returns {Array}
429
+ */
430
+ this.findPointsetsWithGroupName = (groupName, transverse) => {
431
+ const primitivesArray = this.findObjectsWithGroupName(groupName, transverse);
432
+ const pointsetsArray = primitivesArray.filter(primitive => primitive.isPointset);
433
+ return pointsetsArray;
434
+ }
435
+
436
+ /**
437
+ * Find and return all glyphsets in this and child regions with
438
+ * the matching groupName.
439
+ *
440
+ * @param {String} groupName - Groupname to match with.
441
+ * @returns {Array}
442
+ */
443
+ this.findGlyphsetsWithGroupName = (groupName, transverse) => {
444
+ const primitivesArray = this.findObjectsWithGroupName(groupName, transverse);
445
+ const glyphsetsArray = primitivesArray.filter(primitive => primitive.isGlyphset);
446
+ return glyphsetsArray;
447
+ }
448
+
449
+ /**
450
+ * Find and return all lines in this and child regions with
451
+ * the matching groupName.
452
+ *
453
+ * @param {String} groupName - Groupname to match with.
454
+ * @returns {Array}
455
+ */
456
+ this.findLinesWithGroupName = (groupName, transverse) => {
457
+ const primitivesArray = this.findObjectsWithGroupName(groupName, transverse);
458
+ const linesArray = primitivesArray.filter(primitive => primitive.isLines);
459
+ return linesArray;
460
+ }
461
+
462
+ /**
463
+ * Find and return all lines in this and child regions with
464
+ * the matching groupName.
465
+ *
466
+ * @param {String} groupName - Groupname to match with.
467
+ * @returns {Array}
468
+ */
469
+ this.getAllObjects = transverse => {
470
+ const objectsArray = [...zincObjects];
471
+ children.forEach(childRegion => {
472
+ let childObjects = childRegion.getAllObjects(transverse);
473
+ objectsArray.push(...childObjects);
474
+ });
475
+ return objectsArray;
476
+ }
477
+
478
+ /**
479
+ * Get the current time of the region.
480
+ * Return -1 if no graphics in the region.
481
+ * @return {Number}
482
+ */
483
+ this.getCurrentTime = () => {
484
+ if (zincObjects[0] != undefined) {
485
+ return zincObjects[0].getCurrentTime();
486
+ } else {
487
+ for (let i = 0; i < children.length; i++) {
488
+ const time = children[i].getCurrentTime();
489
+ if (time !== -1)
490
+ return time;
491
+ }
492
+ }
493
+ return -1;
494
+ }
495
+
496
+ /**
497
+ * Set the current time of all the objects of this region.
498
+ * @param {Number} time - Value to set the time to.
499
+ */
500
+ this.setMorphTime = (time, transverse) => {
501
+ zincObjects.forEach(zincObject => {
502
+ zincObject.setMorphTime(time);
503
+ });
504
+ if (transverse) {
505
+ children.forEach(childRegion => {
506
+ childRegion.setMorphTime(time);
507
+ });
508
+ }
509
+ }
510
+
511
+ /**
512
+ * Check if any object in this region is time varying.
513
+ *
514
+ * @return {Boolean}
515
+ */
516
+ this.isTimeVarying = () => {
517
+ for (let i = 0; i < zincObjects.length; i++) {
518
+ if (zincObjects[i].isTimeVarying()) {
519
+ return true;
520
+ }
521
+ }
522
+ for (let i = 0; i < children.length; i++) {
523
+ if (children[i].isTimeVarying()) {
524
+ return true;
525
+ }
526
+ }
527
+
528
+ return false;
529
+ }
530
+
531
+ /**
532
+ * Update geometries and glyphsets based on the calculated time.
533
+ * @private
534
+ */
535
+ this.renderGeometries = (playRate, delta, playAnimation, options, transverse) => {
536
+ // Let video dictates the progress if one is present
537
+ const allObjects = this.getAllObjects(transverse);
538
+ allObjects.forEach(zincObject => {
539
+ zincObject.render(playRate * delta, playAnimation, options);
540
+ });
541
+ //process markers visibility and size
542
+ if (options && options.displayMarkers && (playAnimation === false)) {
543
+ if (options.markerDepths.length > 0) {
544
+ const min = Math.min(...options.markerDepths);
545
+ const max = Math.max(...options.markerDepths);
546
+ allObjects.forEach(zincObject => {
547
+ zincObject.processMarkerVisual(min, max, options);
548
+ });
549
+ }
550
+ }
551
+ }
552
+ }
553
+
554
+ exports.Region = Region;