zincjs 1.7.0 → 1.8.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 +34 -14
- package/build/zinc.js.map +1 -1
- package/package.json +1 -1
- package/src/controls.js +22 -1
- package/src/primitives/pointset.js +13 -0
- package/src/region.js +4 -0
- package/src/scene.js +54 -1
- package/src/sceneLoader.js +1 -0
- package/src/three/Points.js +2 -1
- package/src/zinc.js +1 -0
package/package.json
CHANGED
package/src/controls.js
CHANGED
|
@@ -70,6 +70,7 @@ const CameraControls = function ( object, domElement, renderer, scene ) {
|
|
|
70
70
|
this.touchZoomDistanceEnd = 0;
|
|
71
71
|
this.directionalLight = 0;
|
|
72
72
|
this.scrollRate = 50;
|
|
73
|
+
this.pixelHeight = 1;
|
|
73
74
|
let duration = 6000;
|
|
74
75
|
let enabled = true;
|
|
75
76
|
let inbuildTime = 0;
|
|
@@ -224,6 +225,25 @@ const CameraControls = function ( object, domElement, renderer, scene ) {
|
|
|
224
225
|
viewports[defaultViewport]);
|
|
225
226
|
}
|
|
226
227
|
|
|
228
|
+
this.getVisibleHeightAtZDepth = ( depth ) => {
|
|
229
|
+
// compensate for cameras not positioned at z=0
|
|
230
|
+
const cameraOffset = this.cameraObject.position.z;
|
|
231
|
+
if ( depth < cameraOffset ) depth -= cameraOffset;
|
|
232
|
+
else depth += cameraOffset;
|
|
233
|
+
|
|
234
|
+
// vertical fov in radians
|
|
235
|
+
const vFOV = this.cameraObject.fov * Math.PI / 180;
|
|
236
|
+
|
|
237
|
+
// Math.abs to ensure the result is always positive
|
|
238
|
+
return 2 * Math.tan( vFOV / 2 ) * Math.abs( depth );
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
this.calculateHeightPerPixelAtZeroDepth = ( wHeight ) => {
|
|
242
|
+
const height = this.getVisibleHeightAtZDepth(0);
|
|
243
|
+
this.pixelHeight = height / wHeight;
|
|
244
|
+
return this.pixelHeight;
|
|
245
|
+
}
|
|
246
|
+
|
|
227
247
|
/**
|
|
228
248
|
* Get normalised coordinates from windows coordinates.
|
|
229
249
|
*
|
|
@@ -987,6 +1007,7 @@ const CameraControls = function ( object, domElement, renderer, scene ) {
|
|
|
987
1007
|
} else {
|
|
988
1008
|
this.cameraObject.lookAt( this.cameraObject.target );
|
|
989
1009
|
}
|
|
1010
|
+
|
|
990
1011
|
return updated;
|
|
991
1012
|
};
|
|
992
1013
|
|
|
@@ -1476,7 +1497,7 @@ const RayCaster = function (sceneIn, hostSceneIn, callbackFunctionIn, hoverCallb
|
|
|
1476
1497
|
const enabled = true;
|
|
1477
1498
|
const raycaster = new THREE.Raycaster();
|
|
1478
1499
|
raycaster.params.Line.threshold = 0.1;
|
|
1479
|
-
raycaster.params.Points.threshold =
|
|
1500
|
+
raycaster.params.Points.threshold = 1;
|
|
1480
1501
|
const mouse = new THREE.Vector2();
|
|
1481
1502
|
let awaiting = false;
|
|
1482
1503
|
let lastHoveredDate = new Date();
|
|
@@ -85,6 +85,19 @@ const Pointset = function () {
|
|
|
85
85
|
this.morph.material.needsUpdate = true;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Turn size attenuation on/off based on the flag.
|
|
91
|
+
*
|
|
92
|
+
* @param {Boolean} flag - Determin either size attenuation
|
|
93
|
+
* should be on or off.
|
|
94
|
+
*/
|
|
95
|
+
this.render = (delta, playAnimation, cameraControls, options) => {
|
|
96
|
+
if (this.morph) {
|
|
97
|
+
this.morph.sizePerPixel = cameraControls.pixelHeight;
|
|
98
|
+
}
|
|
99
|
+
Pointset.prototype.render.call(this, delta, playAnimation, cameraControls, options);
|
|
100
|
+
}
|
|
88
101
|
}
|
|
89
102
|
|
|
90
103
|
Pointset.prototype = Object.create((require('./zincObject').ZincObject).prototype);
|
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
|
}
|
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());
|
|
@@ -109,10 +111,12 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
109
111
|
|
|
110
112
|
//called from Renderer when panel has been resized
|
|
111
113
|
this.onWindowResize = () => {
|
|
112
|
-
|
|
114
|
+
const wHeight = getDrawingHeight();
|
|
115
|
+
this.camera.aspect = getDrawingWidth() / wHeight;
|
|
113
116
|
this.camera.updateProjectionMatrix();
|
|
114
117
|
this.minimapScissor.updateRequired = true;
|
|
115
118
|
zincCameraControls.onResize();
|
|
119
|
+
zincCameraControls.calculateHeightPerPixelAtZeroDepth(wHeight);
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
/**
|
|
@@ -194,6 +198,7 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
194
198
|
if (boundingBox) {
|
|
195
199
|
const viewport = zincCameraControls.getViewportFromBoundingBox(boundingBox, 1.0);
|
|
196
200
|
zincCameraControls.setCurrentCameraSettings(viewport);
|
|
201
|
+
zincCameraControls.calculateHeightPerPixelAtZeroDepth(getDrawingHeight());
|
|
197
202
|
markerCluster.markerUpdateRequired = true;
|
|
198
203
|
}
|
|
199
204
|
}
|
|
@@ -592,6 +597,9 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
592
597
|
if (0 == sceneLoader.toBeDownloaded) {
|
|
593
598
|
zincCameraControls.setTime(currentTime);
|
|
594
599
|
options.ndcToBeUpdated = zincCameraControls.update(0);
|
|
600
|
+
if (options.ndcToBeUpdated) {
|
|
601
|
+
zincCameraControls.calculateHeightPerPixelAtZeroDepth(getDrawingHeight());
|
|
602
|
+
}
|
|
595
603
|
rootRegion.setMorphTime(currentTime, true);
|
|
596
604
|
rootRegion.renderGeometries(0, 0, playAnimation, zincCameraControls, options, true);
|
|
597
605
|
} else {
|
|
@@ -604,6 +612,9 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
604
612
|
} else {
|
|
605
613
|
if (0 == sceneLoader.toBeDownloaded) {
|
|
606
614
|
options.ndcToBeUpdated = zincCameraControls.update(delta);
|
|
615
|
+
if (options.ndcToBeUpdated) {
|
|
616
|
+
zincCameraControls.calculateHeightPerPixelAtZeroDepth(getDrawingHeight());
|
|
617
|
+
}
|
|
607
618
|
rootRegion.renderGeometries(playRate, delta, playAnimation, zincCameraControls, options, true);
|
|
608
619
|
} else {
|
|
609
620
|
zincCameraControls.update(0);
|
|
@@ -968,6 +979,7 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
968
979
|
markerCluster.clear();
|
|
969
980
|
rootRegion.clear(true);
|
|
970
981
|
this.clearZincObjectAddedCallbacks();
|
|
982
|
+
this.clearZincObjectRemovedCallbacks();
|
|
971
983
|
sceneLoader.toBeDwonloaded = 0;
|
|
972
984
|
if (zincCameraControls) {
|
|
973
985
|
zincCameraControls.calculateMaxAllowedDistance(this);
|
|
@@ -1126,6 +1138,18 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
1126
1138
|
zincObjectAddedCallbacks[zincObjectAddedCallbacks_id] = callbackFunction;
|
|
1127
1139
|
return zincObjectAddedCallbacks_id;
|
|
1128
1140
|
}
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* Add a callback function which will be called everytime zinc object is removed.
|
|
1144
|
+
* @param {Function} callbackFunction - callbackFunction to be added.
|
|
1145
|
+
*
|
|
1146
|
+
* @return {Number}
|
|
1147
|
+
*/
|
|
1148
|
+
this.addZincObjectRemovedCallbacks = callbackFunction => {
|
|
1149
|
+
zincObjectRemovedCallbacks_id = zincObjectRemovedCallbacks_id + 1;
|
|
1150
|
+
zincObjectRemovedCallbacks[zincObjectRemovedCallbacks_id] = callbackFunction;
|
|
1151
|
+
return zincObjectRemovedCallbacks_id;
|
|
1152
|
+
}
|
|
1129
1153
|
|
|
1130
1154
|
/**
|
|
1131
1155
|
* Remove a callback function that is previously added to the scene.
|
|
@@ -1137,6 +1161,16 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
1137
1161
|
}
|
|
1138
1162
|
}
|
|
1139
1163
|
|
|
1164
|
+
/**
|
|
1165
|
+
* Remove a callback function that is previously added to the scene.
|
|
1166
|
+
* @param {Number} id - identifier of the previously added callback function.
|
|
1167
|
+
*/
|
|
1168
|
+
this.removeZincObjectRemovedCallbacks = id => {
|
|
1169
|
+
if (id in zincObjectRemovedCallbacks_id) {
|
|
1170
|
+
delete zincObjectRemovedCallbacks[id];
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1140
1174
|
/**
|
|
1141
1175
|
* Clear all zinc object callback function
|
|
1142
1176
|
*/
|
|
@@ -1145,6 +1179,14 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
1145
1179
|
zincObjectAddedCallbacks_id = 0;
|
|
1146
1180
|
}
|
|
1147
1181
|
|
|
1182
|
+
/**
|
|
1183
|
+
* Clear all zinc object callback function
|
|
1184
|
+
*/
|
|
1185
|
+
this.clearZincObjectRemovedCallbacks = () => {
|
|
1186
|
+
zincObjectRemovedCallbacks = {};
|
|
1187
|
+
zincObjectRemovedCallbacks_id = 0;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1148
1190
|
/**
|
|
1149
1191
|
* Used to trigger zinc object added callback
|
|
1150
1192
|
*/
|
|
@@ -1156,6 +1198,17 @@ exports.Scene = function (containerIn, rendererIn) {
|
|
|
1156
1198
|
}
|
|
1157
1199
|
}
|
|
1158
1200
|
|
|
1201
|
+
/**
|
|
1202
|
+
* Used to trigger zinc object removed callback
|
|
1203
|
+
*/
|
|
1204
|
+
this.triggerObjectRemovedCallback= (zincObject) => {
|
|
1205
|
+
for (let key in zincObjectRemovedCallbacks) {
|
|
1206
|
+
if (zincObjectRemovedCallbacks.hasOwnProperty(key)) {
|
|
1207
|
+
zincObjectRemovedCallbacks[key](zincObject);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1159
1212
|
/*
|
|
1160
1213
|
* Add temporary points to the scene which can be removed
|
|
1161
1214
|
* with clearTemporaryPrimitives method.
|
package/src/sceneLoader.js
CHANGED
package/src/three/Points.js
CHANGED
|
@@ -26,6 +26,7 @@ class Points extends Object3D {
|
|
|
26
26
|
|
|
27
27
|
this.geometry = geometry;
|
|
28
28
|
this.material = material;
|
|
29
|
+
this.sizePerPixel = 1;
|
|
29
30
|
|
|
30
31
|
this.updateMorphTargets();
|
|
31
32
|
|
|
@@ -64,7 +65,7 @@ class Points extends Object3D {
|
|
|
64
65
|
_inverseMatrix.copy( matrixWorld ).invert();
|
|
65
66
|
_ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
|
|
66
67
|
|
|
67
|
-
const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
|
|
68
|
+
const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 ) * this.material.size * this.sizePerPixel;
|
|
68
69
|
const localThresholdSq = localThreshold * localThreshold;
|
|
69
70
|
|
|
70
71
|
if ( geometry.isBufferGeometry ) {
|
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;
|