zincjs 1.8.0 → 1.8.2

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.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "ZincJS (Web-based-Zinc-Visualisation)",
5
5
  "main": "build/zinc.js",
6
6
  "directories": {
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
  *
@@ -329,20 +349,22 @@ const CameraControls = function ( object, domElement, renderer, scene ) {
329
349
 
330
350
  const onDocumentMouseMove = event => {
331
351
  updateRect(false);
332
- this.pointer_x = event.clientX - rect.left;
333
- this.pointer_y = event.clientY - rect.top;
334
- if (currentMode === MODE.MINIMAP) {
335
- let minimapCoordinates = this.scene.getNormalisedMinimapCoordinates(this.renderer, event);
336
- if (minimapCoordinates) {
337
- let translation = this.scene.getMinimapDiffFromNormalised(
338
- minimapCoordinates.x, minimapCoordinates.y);
339
- translateViewport(translation);
340
- }
341
- } else {
342
- if ((this._state === STATE.NONE) && (zincRayCaster !== undefined)) {
343
- zincRayCaster.move(this, event.clientX, event.clientY, this.renderer);
344
- }
345
- }
352
+ if (rect) {
353
+ this.pointer_x = event.clientX - rect.left;
354
+ this.pointer_y = event.clientY - rect.top;
355
+ if (currentMode === MODE.MINIMAP) {
356
+ let minimapCoordinates = this.scene.getNormalisedMinimapCoordinates(this.renderer, event);
357
+ if (minimapCoordinates) {
358
+ let translation = this.scene.getMinimapDiffFromNormalised(
359
+ minimapCoordinates.x, minimapCoordinates.y);
360
+ translateViewport(translation);
361
+ }
362
+ } else {
363
+ if ((this._state === STATE.NONE) && (zincRayCaster !== undefined)) {
364
+ zincRayCaster.move(this, event.clientX, event.clientY, this.renderer);
365
+ }
366
+ }
367
+ }
346
368
  }
347
369
 
348
370
  const onDocumentMouseUp = event => {
@@ -987,6 +1009,7 @@ const CameraControls = function ( object, domElement, renderer, scene ) {
987
1009
  } else {
988
1010
  this.cameraObject.lookAt( this.cameraObject.target );
989
1011
  }
1012
+
990
1013
  return updated;
991
1014
  };
992
1015
 
@@ -1476,7 +1499,7 @@ const RayCaster = function (sceneIn, hostSceneIn, callbackFunctionIn, hoverCallb
1476
1499
  const enabled = true;
1477
1500
  const raycaster = new THREE.Raycaster();
1478
1501
  raycaster.params.Line.threshold = 0.1;
1479
- raycaster.params.Points.threshold = 0.1;
1502
+ raycaster.params.Points.threshold = 1;
1480
1503
  const mouse = new THREE.Vector2();
1481
1504
  let awaiting = false;
1482
1505
  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/scene.js CHANGED
@@ -111,10 +111,12 @@ exports.Scene = function (containerIn, rendererIn) {
111
111
 
112
112
  //called from Renderer when panel has been resized
113
113
  this.onWindowResize = () => {
114
- this.camera.aspect = getDrawingWidth() / getDrawingHeight();
114
+ const wHeight = getDrawingHeight();
115
+ this.camera.aspect = getDrawingWidth() / wHeight;
115
116
  this.camera.updateProjectionMatrix();
116
117
  this.minimapScissor.updateRequired = true;
117
118
  zincCameraControls.onResize();
119
+ zincCameraControls.calculateHeightPerPixelAtZeroDepth(wHeight);
118
120
  }
119
121
 
120
122
  /**
@@ -196,6 +198,7 @@ exports.Scene = function (containerIn, rendererIn) {
196
198
  if (boundingBox) {
197
199
  const viewport = zincCameraControls.getViewportFromBoundingBox(boundingBox, 1.0);
198
200
  zincCameraControls.setCurrentCameraSettings(viewport);
201
+ zincCameraControls.calculateHeightPerPixelAtZeroDepth(getDrawingHeight());
199
202
  markerCluster.markerUpdateRequired = true;
200
203
  }
201
204
  }
@@ -594,6 +597,9 @@ exports.Scene = function (containerIn, rendererIn) {
594
597
  if (0 == sceneLoader.toBeDownloaded) {
595
598
  zincCameraControls.setTime(currentTime);
596
599
  options.ndcToBeUpdated = zincCameraControls.update(0);
600
+ if (options.ndcToBeUpdated) {
601
+ zincCameraControls.calculateHeightPerPixelAtZeroDepth(getDrawingHeight());
602
+ }
597
603
  rootRegion.setMorphTime(currentTime, true);
598
604
  rootRegion.renderGeometries(0, 0, playAnimation, zincCameraControls, options, true);
599
605
  } else {
@@ -606,6 +612,9 @@ exports.Scene = function (containerIn, rendererIn) {
606
612
  } else {
607
613
  if (0 == sceneLoader.toBeDownloaded) {
608
614
  options.ndcToBeUpdated = zincCameraControls.update(delta);
615
+ if (options.ndcToBeUpdated) {
616
+ zincCameraControls.calculateHeightPerPixelAtZeroDepth(getDrawingHeight());
617
+ }
609
618
  rootRegion.renderGeometries(playRate, delta, playAnimation, zincCameraControls, options, true);
610
619
  } else {
611
620
  zincCameraControls.update(0);
@@ -422,6 +422,7 @@ exports.SceneLoader = function (sceneIn) {
422
422
  scene.viewAll();
423
423
  if (allCompletedCallback != undefined && (typeof allCompletedCallback == 'function'))
424
424
  allCompletedCallback();
425
+
425
426
  }
426
427
  };
427
428
  };
@@ -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 ) {