zincjs 1.11.7 → 1.12.1
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/build/zinc.frontend.js +1 -1
- package/build/zinc.js +37 -25
- package/build/zinc.js.map +1 -1
- package/package.json +1 -1
- package/src/primitives/glyph.js +21 -7
- package/src/primitives/glyphset.js +45 -25
- package/src/primitives/label.js +1 -1
- package/src/primitives/zincObject.js +0 -4
- package/src/scene.js +4 -2
- package/src/sceneLoader.js +53 -7
- package/src/utilities.js +35 -0
package/package.json
CHANGED
package/src/primitives/glyph.js
CHANGED
|
@@ -24,6 +24,7 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
|
|
|
24
24
|
let label = undefined;
|
|
25
25
|
let labelString = undefined;
|
|
26
26
|
this.isGlyph = true;
|
|
27
|
+
let _position = [0, 0, 0];
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Create a glyph using mesh
|
|
@@ -64,8 +65,6 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
|
|
|
64
65
|
if (this.morph)
|
|
65
66
|
this.morph.name = text;
|
|
66
67
|
}
|
|
67
|
-
if (label)
|
|
68
|
-
this.showLabel();
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
/**
|
|
@@ -75,19 +74,30 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
|
|
|
75
74
|
*/
|
|
76
75
|
this.showLabel = (colour) => {
|
|
77
76
|
if (label) {
|
|
78
|
-
|
|
77
|
+
_position = label.getPosition();
|
|
79
78
|
this.group.remove(label.getSprite());
|
|
80
79
|
label.dispose();
|
|
81
80
|
label = undefined;
|
|
82
81
|
}
|
|
83
82
|
if (labelString && (typeof labelString === 'string' || labelString instanceof String)) {
|
|
84
|
-
let position = [0, 0, 0];
|
|
85
83
|
label = new (require('./label').Label)(labelString, colour);
|
|
86
|
-
label.setPosition(
|
|
84
|
+
label.setPosition(_position[0], _position[1], _position[2]);
|
|
87
85
|
this.group.add(label.getSprite());
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Hide label with the choosen colour.
|
|
91
|
+
*/
|
|
92
|
+
this.hideLabel = () => {
|
|
93
|
+
if (label) {
|
|
94
|
+
_position = label.getPosition();
|
|
95
|
+
this.group.remove(label.getSprite());
|
|
96
|
+
label.dispose();
|
|
97
|
+
label = undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
91
101
|
/**
|
|
92
102
|
* Get the label of this glyph
|
|
93
103
|
* @return {Label}
|
|
@@ -135,8 +145,10 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
|
|
|
135
145
|
this.morph.matrix.elements[15] = 1.0;
|
|
136
146
|
this.morph.matrixAutoUpdate = false;
|
|
137
147
|
}
|
|
138
|
-
|
|
148
|
+
_position = [...position];
|
|
149
|
+
if (label) {
|
|
139
150
|
label.setPosition(position[0], position[1], position[2]);
|
|
151
|
+
}
|
|
140
152
|
}
|
|
141
153
|
|
|
142
154
|
/**
|
|
@@ -149,7 +161,9 @@ const Glyph = function (geometry, materialIn, idIn, glyphsetIn) {
|
|
|
149
161
|
label.setColour(color);
|
|
150
162
|
if (this.secondaryMesh && this.secondaryMesh.material)
|
|
151
163
|
this.secondaryMesh.material.color = colour;
|
|
152
|
-
this.geometry
|
|
164
|
+
if (this.geometry) {
|
|
165
|
+
this.geometry.colorsNeedUpdate = true;
|
|
166
|
+
}
|
|
153
167
|
}
|
|
154
168
|
|
|
155
169
|
/**
|
|
@@ -45,6 +45,7 @@ const Glyphset = function () {
|
|
|
45
45
|
const _current_scales = [];
|
|
46
46
|
const _current_colors = [];
|
|
47
47
|
const _glyph_axis_array = [];
|
|
48
|
+
this.globalScale = 1;
|
|
48
49
|
for (let i = 0; i < 8; i++) {
|
|
49
50
|
_points[i] = new THREE.Vector3();
|
|
50
51
|
}
|
|
@@ -113,7 +114,7 @@ const Glyphset = function () {
|
|
|
113
114
|
const mirrored_point = [0.0, 0.0, 0.0];
|
|
114
115
|
for (var j = 0; j < 3; j++) {
|
|
115
116
|
var sign = (scale[j] < 0.0) ? -1.0 : 1.0;
|
|
116
|
-
axis_scale[j] = sign * baseSize[j] + scale[j] * scaleFactors[j];
|
|
117
|
+
axis_scale[j] = (sign * baseSize[j] + scale[j] * scaleFactors[j]) * this.globalScale;
|
|
117
118
|
}
|
|
118
119
|
for (var j = 0; j < 3; j++) {
|
|
119
120
|
final_axis1[j] = axis1[j] * axis_scale[0];
|
|
@@ -168,7 +169,7 @@ const Glyphset = function () {
|
|
|
168
169
|
let final_point = [0.0, 0.0, 0.0];
|
|
169
170
|
for (var j = 0; j < 3; j++) {
|
|
170
171
|
var sign = (scale[j] < 0.0) ? -1.0 : 1.0;
|
|
171
|
-
axis_scale[j] = sign * baseSize[0] + scale[j] * scaleFactors[0];
|
|
172
|
+
axis_scale[j] = (sign * baseSize[0] + scale[j] * scaleFactors[0]) * this.globalScale;
|
|
172
173
|
}
|
|
173
174
|
for (var j = 0; j < 3; j++) {
|
|
174
175
|
final_point[j] = point[j]
|
|
@@ -196,7 +197,7 @@ const Glyphset = function () {
|
|
|
196
197
|
use_axis1 = axis3;
|
|
197
198
|
use_axis2 = axis1;
|
|
198
199
|
}
|
|
199
|
-
const final_scale1 = baseSize[0] + use_scale * scaleFactors[0];
|
|
200
|
+
const final_scale1 = (baseSize[0] + use_scale * scaleFactors[0]) * this.globalScale;
|
|
200
201
|
final_axis1[0] = use_axis1[0] * final_scale1;
|
|
201
202
|
final_axis1[1] = use_axis1[1] * final_scale1;
|
|
202
203
|
final_axis1[2] = use_axis1[2] * final_scale1;
|
|
@@ -205,7 +206,7 @@ const Glyphset = function () {
|
|
|
205
206
|
final_axis3[2] = final_axis1[0] * use_axis2[1] - final_axis1[1] * use_axis2[0];
|
|
206
207
|
let magnitude = Math.sqrt(final_axis3[0] * final_axis3[0] + final_axis3[1] * final_axis3[1] + final_axis3[2] * final_axis3[2]);
|
|
207
208
|
if (0.0 < magnitude) {
|
|
208
|
-
let scaling = (baseSize[2] + use_scale * scaleFactors[2]) / magnitude;
|
|
209
|
+
let scaling = (baseSize[2] + use_scale * scaleFactors[2]) * this.globalScale / magnitude;
|
|
209
210
|
if ((repeat_mode == "AXES_2D") && (k > 0)) {
|
|
210
211
|
scaling *= -1.0;
|
|
211
212
|
}
|
|
@@ -219,7 +220,7 @@ const Glyphset = function () {
|
|
|
219
220
|
final_axis2[2] = final_axis3[0] * final_axis1[1] - final_axis3[1] * final_axis1[0];
|
|
220
221
|
magnitude = Math.sqrt(final_axis2[0] * final_axis2[0] + final_axis2[1] * final_axis2[1] + final_axis2[2] * final_axis2[2]);
|
|
221
222
|
if (0.0 < magnitude) {
|
|
222
|
-
var scaling = (baseSize[1] + use_scale * scaleFactors[1]) / magnitude;
|
|
223
|
+
var scaling = (baseSize[1] + use_scale * scaleFactors[1]) * this.globalScale / magnitude;
|
|
223
224
|
final_axis2[0] *= scaling;
|
|
224
225
|
final_axis2[1] *= scaling;
|
|
225
226
|
final_axis2[2] *= scaling;
|
|
@@ -282,9 +283,10 @@ const Glyphset = function () {
|
|
|
282
283
|
_transformMatrix.elements[15] = 1.0;
|
|
283
284
|
this.morph.setMatrixAt(current_glyph_index, _transformMatrix);
|
|
284
285
|
const glyph = glyphList[current_glyph_index];
|
|
285
|
-
if (glyph)
|
|
286
|
+
if (glyph) {
|
|
286
287
|
glyph.setTransformation(arrays[j][0], arrays[j][1],
|
|
287
288
|
arrays[j][2], arrays[j][3]);
|
|
289
|
+
}
|
|
288
290
|
current_glyph_index++;
|
|
289
291
|
}
|
|
290
292
|
}
|
|
@@ -323,12 +325,12 @@ const Glyphset = function () {
|
|
|
323
325
|
* the internal time has been updated.
|
|
324
326
|
*/
|
|
325
327
|
const updateMorphGlyphsets = () => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
328
|
+
let current_positions = _current_positions;
|
|
329
|
+
let current_axis1s = _current_axis1s;
|
|
330
|
+
let current_axis2s = _current_axis2s;
|
|
331
|
+
let current_axis3s = _current_axis3s;
|
|
332
|
+
let current_scales = _current_scales;
|
|
333
|
+
let current_colors = _current_colors;
|
|
332
334
|
|
|
333
335
|
const current_time = this.inbuildTime / this.duration * (numberOfTimeSteps - 1);
|
|
334
336
|
const bottom_frame = Math.floor(current_time);
|
|
@@ -402,27 +404,36 @@ const Glyphset = function () {
|
|
|
402
404
|
}
|
|
403
405
|
}
|
|
404
406
|
|
|
407
|
+
/**
|
|
408
|
+
* Hide label with the choosen colour.
|
|
409
|
+
*/
|
|
410
|
+
this.hideLabel = () => {
|
|
411
|
+
for (let i = 0; i < glyphList.length; i++) {
|
|
412
|
+
glyphList[i].hideLabel();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
405
416
|
/**
|
|
406
417
|
* Create the glyphs in the glyphset.
|
|
407
418
|
*
|
|
408
419
|
* @param {Boolean} displayLabels -Flag to determine either the labels should be display or not.
|
|
409
420
|
*/
|
|
410
421
|
const createGlyphs = (displayLabels) => {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
glyphList[i] = glyph;
|
|
421
|
-
this.morph.add(glyph.getGroup());
|
|
422
|
+
for (let i = 0; i < numberOfVertices; i++) {
|
|
423
|
+
const glyph = new (require('./glyph').Glyph)(undefined, undefined, i, this);
|
|
424
|
+
let label = labels ? labels[i] : undefined;
|
|
425
|
+
label = label ? label : this.groupName;
|
|
426
|
+
if (label) {
|
|
427
|
+
glyph.setLabel(label);
|
|
428
|
+
}
|
|
429
|
+
if (numberOfTimeSteps > 0) {
|
|
430
|
+
glyph.setFrustumCulled(false);
|
|
422
431
|
}
|
|
432
|
+
glyphList[i] = glyph;
|
|
433
|
+
this.morph.add(glyph.getGroup());
|
|
423
434
|
}
|
|
424
|
-
if (
|
|
425
|
-
this.showLabel(
|
|
435
|
+
if (displayLabels) {
|
|
436
|
+
this.showLabel();
|
|
426
437
|
}
|
|
427
438
|
//Update the transformation of the glyphs.
|
|
428
439
|
updateGlyphsetTransformation(positions["0"], axis1s["0"],
|
|
@@ -624,6 +635,15 @@ const Glyphset = function () {
|
|
|
624
635
|
return this.inbuildTime;
|
|
625
636
|
}
|
|
626
637
|
|
|
638
|
+
/**
|
|
639
|
+
* Set the objects scale.
|
|
640
|
+
*
|
|
641
|
+
* @return {THREE.Box3}.
|
|
642
|
+
*/
|
|
643
|
+
this.setScaleAll = function(scale) {
|
|
644
|
+
this.globalScale = scale;
|
|
645
|
+
updateMorphGlyphsets();
|
|
646
|
+
}
|
|
627
647
|
|
|
628
648
|
/**
|
|
629
649
|
* Clear this glyphset and its list of glyphs which will release them from the memory.
|
package/src/primitives/label.js
CHANGED
|
@@ -707,8 +707,6 @@ ZincObject.prototype.addVertices = function(coords) {
|
|
|
707
707
|
|
|
708
708
|
/**
|
|
709
709
|
* Set the objects position.
|
|
710
|
-
*
|
|
711
|
-
* @return {THREE.Box3}.
|
|
712
710
|
*/
|
|
713
711
|
ZincObject.prototype.setPosition = function(x, y, z) {
|
|
714
712
|
const group = this.getGroup();
|
|
@@ -726,8 +724,6 @@ ZincObject.prototype.loadAdditionalSources = function(primitivesLoader, sources)
|
|
|
726
724
|
|
|
727
725
|
/**
|
|
728
726
|
* Set the objects scale.
|
|
729
|
-
*
|
|
730
|
-
* @return {THREE.Box3}.
|
|
731
727
|
*/
|
|
732
728
|
ZincObject.prototype.setScaleAll = function(scale) {
|
|
733
729
|
const group = this.getGroup();
|
package/src/scene.js
CHANGED
|
@@ -465,9 +465,11 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
465
465
|
* @param {String} url - Location of the metafile
|
|
466
466
|
* @param {Function} finishCallback - Callback function which will be called
|
|
467
467
|
* for each glyphset and geometry that has been written in.
|
|
468
|
+
* @param {options} Optional settings, it can be used to ignore some regions/groups
|
|
469
|
+
* in the metadata file. Only supports version 1 at this moment.
|
|
468
470
|
*/
|
|
469
|
-
this.loadMetadataURL = (url, finishCallback, allCompletedCallback) => {
|
|
470
|
-
sceneLoader.loadMetadataURL(rootRegion, url, finishCallback, allCompletedCallback);
|
|
471
|
+
this.loadMetadataURL = (url, finishCallback, allCompletedCallback, options) => {
|
|
472
|
+
sceneLoader.loadMetadataURL(rootRegion, url, finishCallback, allCompletedCallback, options);
|
|
471
473
|
}
|
|
472
474
|
|
|
473
475
|
/**
|
package/src/sceneLoader.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const THREE = require('three');
|
|
2
2
|
const resolveURL = require('./utilities').resolveURL;
|
|
3
3
|
const createNewURL = require('./utilities').createNewURL;
|
|
4
|
+
const isRegionGroup = require('./utilities').isRegionGroup;
|
|
4
5
|
|
|
5
6
|
const STLLoader = require('./loaders/STLLoader').STLLoader;
|
|
6
7
|
const OBJLoader = require('./loaders/OBJLoader').OBJLoader;
|
|
@@ -803,6 +804,48 @@ exports.SceneLoader = function (sceneIn) {
|
|
|
803
804
|
}
|
|
804
805
|
}
|
|
805
806
|
|
|
807
|
+
let filterPrimitivesArray = (array, options) => {
|
|
808
|
+
let newArray = array;
|
|
809
|
+
const include = options?.enabled?.include;
|
|
810
|
+
const exclude = options?.enabled?.exclude;
|
|
811
|
+
if (include?.length || exclude?.length) {
|
|
812
|
+
if (include) {
|
|
813
|
+
newArray = array.filter((item) => {
|
|
814
|
+
if (item.Type === "View") {
|
|
815
|
+
return true;
|
|
816
|
+
}
|
|
817
|
+
for (let i = 0; i < include.length; i++) {
|
|
818
|
+
if (isRegionGroup(item.RegionPath, item.GroupName, include[i])) {
|
|
819
|
+
return true;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return false;
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
if (exclude) {
|
|
826
|
+
newArray = newArray.filter((item) => {
|
|
827
|
+
if (item.Type === "View") {
|
|
828
|
+
return true;
|
|
829
|
+
}
|
|
830
|
+
for (let i = 0; i < exclude.length; i++) {
|
|
831
|
+
if (isRegionGroup(item.RegionPath, item.GroupName, exclude[i])) {
|
|
832
|
+
return false;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
return true;
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return newArray;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
let filterMetadataInArray = (metadata, options) => {
|
|
843
|
+
if (Array.isArray(metadata)) {
|
|
844
|
+
return filterPrimitivesArray(metadata, options);
|
|
845
|
+
}
|
|
846
|
+
return metadata;
|
|
847
|
+
}
|
|
848
|
+
|
|
806
849
|
let getNumberOfDownloadsInArray = (array, includeViews) => {
|
|
807
850
|
if (Array.isArray(array)) {
|
|
808
851
|
let count = 0;
|
|
@@ -853,15 +896,16 @@ exports.SceneLoader = function (sceneIn) {
|
|
|
853
896
|
readPrimitivesItem(targetRegion, referenceURL, item, order * 2, callback);
|
|
854
897
|
}
|
|
855
898
|
|
|
856
|
-
let loadVersionOne = (targetRegion, metadata, referenceURL, finishCallback, allCompletedCallback) => {
|
|
857
|
-
|
|
899
|
+
let loadVersionOne = (targetRegion, metadata, referenceURL, finishCallback, allCompletedCallback, options) => {
|
|
900
|
+
const filteredMetada = filterMetadataInArray(metadata, options);
|
|
901
|
+
let numberOfObjects = getNumberOfObjects(filteredMetada);
|
|
858
902
|
// view file does not receive callback
|
|
859
903
|
let callback = new metaFinishCallback(numberOfObjects, finishCallback, allCompletedCallback);
|
|
860
904
|
// Prioritise the view file and settings before loading anything else
|
|
861
905
|
for (let i = 0; i < metadata.length; i++)
|
|
862
|
-
readViewAndSettingsItem(referenceURL,
|
|
906
|
+
readViewAndSettingsItem(referenceURL, filteredMetada[i], callback);
|
|
863
907
|
for (let i = 0; i < metadata.length; i++) {
|
|
864
|
-
readVersionOneRegionPath(targetRegion, referenceURL,
|
|
908
|
+
readVersionOneRegionPath(targetRegion, referenceURL, filteredMetada[i], i, callback);
|
|
865
909
|
}
|
|
866
910
|
}
|
|
867
911
|
|
|
@@ -881,11 +925,13 @@ exports.SceneLoader = function (sceneIn) {
|
|
|
881
925
|
* Load a metadata file from the provided URL into this scene. Once
|
|
882
926
|
* succssful scene proceeds to read each items into scene for visualisations.
|
|
883
927
|
*
|
|
884
|
-
* @param {String} url - Location of the
|
|
928
|
+
* @param {String} url - Location of the metadata file
|
|
885
929
|
* @param {Function} finishCallback - Callback function which will be called
|
|
930
|
+
* @param {options} Optional settings, it can be used to ignore some regions/groups
|
|
931
|
+
* in the metadata file. Only supports version 1 at this moment.
|
|
886
932
|
* for each glyphset and geometry that has been written in.
|
|
887
933
|
*/
|
|
888
|
-
this.loadMetadataURL = (targetRegion, url, finishCallback, allCompletedCallback) => {
|
|
934
|
+
this.loadMetadataURL = (targetRegion, url, finishCallback, allCompletedCallback, options) => {
|
|
889
935
|
const xmlhttp = new XMLHttpRequest();
|
|
890
936
|
const requestURL = resolveURL(url);
|
|
891
937
|
xmlhttp.onreadystatechange = () => {
|
|
@@ -898,7 +944,7 @@ exports.SceneLoader = function (sceneIn) {
|
|
|
898
944
|
referenceURL = (new URL(requestURL)).href;
|
|
899
945
|
const metadata = JSON.parse(xmlhttp.responseText);
|
|
900
946
|
if (Array.isArray(metadata)) {
|
|
901
|
-
loadVersionOne(targetRegion, metadata, referenceURL, finishCallback, allCompletedCallback);
|
|
947
|
+
loadVersionOne(targetRegion, metadata, referenceURL, finishCallback, allCompletedCallback, options);
|
|
902
948
|
} else if (typeof metadata === "object" && metadata !== null) {
|
|
903
949
|
if (metadata.Version == "2.0") {
|
|
904
950
|
loadVersionTwo(targetRegion, metadata, referenceURL, finishCallback, allCompletedCallback);
|
package/src/utilities.js
CHANGED
|
@@ -472,6 +472,40 @@ function createNewSpriteText(text, height, colour, font, pixel, weight) {
|
|
|
472
472
|
return sprite;
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
+
/*
|
|
476
|
+
* Check if the compare path match with the region or/and group.
|
|
477
|
+
* comparePath should be in the form of regionPath/Group.
|
|
478
|
+
* * can be used as wildcard.
|
|
479
|
+
* comparePath will be used to compare both region and group if it
|
|
480
|
+
* is a single string without /
|
|
481
|
+
*/
|
|
482
|
+
function isRegionGroup(regionPath, groupName, comparePath) {
|
|
483
|
+
if (comparePath) {
|
|
484
|
+
const region = regionPath ? regionPath : "";
|
|
485
|
+
const group = groupName ? groupName : "";
|
|
486
|
+
const n = comparePath.lastIndexOf('/');
|
|
487
|
+
if (n > -1) {
|
|
488
|
+
let r = undefined;
|
|
489
|
+
let g = undefined;
|
|
490
|
+
r = comparePath.substring(0, n);
|
|
491
|
+
g = comparePath.substring(n + 1);
|
|
492
|
+
if (r === "*" || r === "**" || r.toLowerCase() === region.toLowerCase()) {
|
|
493
|
+
if (g === "*" || g === "**" || g.toLowerCase() === group.toLowerCase()) {
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
} else {
|
|
498
|
+
//one single value if one of the region / group matches
|
|
499
|
+
if (region.toLowerCase() === comparePath.toLowerCase() ||
|
|
500
|
+
group.toLowerCase() === comparePath.toLowerCase()) {
|
|
501
|
+
return true;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
|
|
475
509
|
exports.getBoundingBox = getBoundingBox;
|
|
476
510
|
exports.createNewURL = createNewURL;
|
|
477
511
|
exports.createBufferGeometry = createBufferGeometry;
|
|
@@ -481,3 +515,4 @@ exports.loadExternalFile = loadExternalFile;
|
|
|
481
515
|
exports.loadExternalFiles = loadExternalFiles;
|
|
482
516
|
exports.PhongToToon = PhongToToon;
|
|
483
517
|
exports.createNewSpriteText = createNewSpriteText;
|
|
518
|
+
exports.isRegionGroup = isRegionGroup;
|