zincjs 3.0.1 → 3.0.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": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "ZincJS (Web-based-Zinc-Visualisation)",
5
5
  "type": "module",
6
6
  "main": "build/zinc.js",
package/src/renderer.js CHANGED
@@ -38,7 +38,6 @@ const Renderer = function (containerIn) {
38
38
  let contextLostCallbackFunctions_id = 0;
39
39
  let contextRestoredCallbackFunctions = {};
40
40
  let contextRestoredCallbackFunctions_id = 0;
41
- let animated_id = undefined;
42
41
  let cameraOrtho = undefined,
43
42
  sceneOrtho = undefined,
44
43
  logoSprite = undefined;
@@ -179,6 +178,8 @@ const Renderer = function (containerIn) {
179
178
  }
180
179
  renderer = new THREE.WebGPURenderer(parameters);
181
180
  await renderer.init();
181
+ //animate() may have been called before the renderer was ready
182
+ if (isRendering) renderer.setAnimationLoop(this.render);
182
183
  //GPU glyph animation requires the WebGPU backend, the WebGL fallback
183
184
  //cannot index storage buffers freely.
184
185
  setGlyphComputeSupported(renderer.backend?.isWebGPUBackend === true);
@@ -378,22 +379,13 @@ const Renderer = function (containerIn) {
378
379
  currentScene.updateDirectionalLight();
379
380
  };
380
381
 
381
- let runAnimation = () => {
382
- if (isRendering) {
383
- animated_id = requestAnimationFrame(runAnimation);
384
- this.render();
385
- } else {
386
- cancelAnimationFrame(animated_id);
387
- animated_id = undefined;
388
- }
389
- };
390
-
391
382
  /**
392
383
  * Stop the animation and renderer to get into the render loop.
393
384
  */
394
385
  this.stopAnimate = () => {
395
386
  if (isRendering) {
396
387
  isRendering = false;
388
+ renderer?.setAnimationLoop(null);
397
389
  }
398
390
  };
399
391
 
@@ -405,7 +397,10 @@ const Renderer = function (containerIn) {
405
397
  clock.reset();
406
398
  isRendering = true;
407
399
  needsRender = true;
408
- runAnimation();
400
+ //WebGPURenderer always runs its own requestAnimationFrame loop which
401
+ //updates the node frame and the per frame info, render from that loop
402
+ //instead of running a second one.
403
+ renderer?.setAnimationLoop(this.render);
409
404
  }
410
405
  };
411
406
 
@@ -646,7 +641,16 @@ const Renderer = function (containerIn) {
646
641
  }
647
642
  clock.update();
648
643
  const delta = clock.getDelta();
649
- let changed = currentScene.renderGeometries(playRate, delta, this.playAnimation);
644
+ //Objects are only updated on every frame when render on demand is off
645
+ //or the renderer itself has requested a frame, e.g. on resize
646
+ const forceUpdate = !renderOnDemand || needsRender;
647
+ let changed = currentScene.renderGeometries(
648
+ playRate,
649
+ delta,
650
+ this.playAnimation,
651
+ undefined,
652
+ forceUpdate,
653
+ );
650
654
  if (additionalActiveScenes.length > 0) {
651
655
  //Additional scenes are displayed with the current scene's camera
652
656
  sharedCamera.controls = currentScene.getZincCameraControls();
@@ -654,7 +658,9 @@ const Renderer = function (containerIn) {
654
658
  }
655
659
  for (let i = 0; i < additionalActiveScenes.length; i++) {
656
660
  const sceneItem = additionalActiveScenes[i];
657
- if (sceneItem.renderGeometries(playRate, delta, this.playAnimation, sharedCamera))
661
+ if (
662
+ sceneItem.renderGeometries(playRate, delta, this.playAnimation, sharedCamera, forceUpdate)
663
+ )
658
664
  changed = true;
659
665
  }
660
666
  for (let key in preRenderCallbackFunctions) {
@@ -756,7 +762,6 @@ const Renderer = function (containerIn) {
756
762
  * Dispose all memory allocated, this will effetively destroy all scenes.
757
763
  */
758
764
  this.dispose = () => {
759
- if (isRendering) cancelAnimationFrame(animated_id);
760
765
  for (const key in sceneMap) {
761
766
  if (sceneMap.hasOwnProperty(key)) {
762
767
  sceneMap[key].clearAll();
package/src/scene.js CHANGED
@@ -624,11 +624,25 @@ const Scene = function (containerIn, rendererIn) {
624
624
  * Update geometries and glyphsets based on the calculated time.
625
625
  * @private
626
626
  */
627
- this.renderGeometries = (playRate, delta, playAnimation, sharedCamera) => {
627
+ this.renderGeometries = (playRate, delta, playAnimation, sharedCamera, forceUpdate) => {
628
628
  //Anything requested since the last frame
629
629
  let changed = needsRender;
630
630
  needsRender = false;
631
631
  cameraUpdated = false;
632
+ //These are plain properties, check if they have changed before
633
+ //the objects are updated so markers are toggled on this frame
634
+ if (
635
+ lastDisplayState.displayMarkers !== this.displayMarkers ||
636
+ lastDisplayState.displayMinimap !== this.displayMinimap ||
637
+ lastDisplayState.displayMiniAxes !== this.displayMiniAxes ||
638
+ lastDisplayState.playAnimation !== playAnimation
639
+ ) {
640
+ lastDisplayState.displayMarkers = this.displayMarkers;
641
+ lastDisplayState.displayMinimap = this.displayMinimap;
642
+ lastDisplayState.displayMiniAxes = this.displayMiniAxes;
643
+ lastDisplayState.playAnimation = playAnimation;
644
+ changed = true;
645
+ }
632
646
  //Additional active scenes are displayed with the current scene's camera
633
647
  const cameraControls = sharedCamera ? sharedCamera.controls : zincCameraControls;
634
648
  //Reused on every frame to avoid allocations
@@ -680,25 +694,23 @@ const Scene = function (containerIn, rendererIn) {
680
694
  zincCameraControls.calculateHeightPerPixelAtZeroDepth(getDrawingHeight());
681
695
  }
682
696
  }
683
- rootRegion.renderGeometries(playRate, delta, playAnimation, cameraControls, options, true);
697
+ //Walking every object is costly for large scenes, only do it when
698
+ //something may have changed, LOD and markers depend on the camera
699
+ if (
700
+ forceUpdate ||
701
+ changed ||
702
+ options.ndcToBeUpdated ||
703
+ playAnimation ||
704
+ //Clusters are recalculated during the walk
705
+ (markerCluster.isEnabled() && markerCluster.markerUpdateRequired)
706
+ ) {
707
+ rootRegion.renderGeometries(playRate, delta, playAnimation, cameraControls, options, true);
708
+ }
684
709
  } else if (!sharedCamera && zincCameraControls.update(0)) {
685
710
  changed = true;
686
711
  cameraUpdated = true;
687
712
  }
688
713
  }
689
- //These are plain properties, check if they have changed
690
- if (
691
- lastDisplayState.displayMarkers !== this.displayMarkers ||
692
- lastDisplayState.displayMinimap !== this.displayMinimap ||
693
- lastDisplayState.displayMiniAxes !== this.displayMiniAxes ||
694
- lastDisplayState.playAnimation !== playAnimation
695
- ) {
696
- lastDisplayState.displayMarkers = this.displayMarkers;
697
- lastDisplayState.displayMinimap = this.displayMinimap;
698
- lastDisplayState.displayMiniAxes = this.displayMiniAxes;
699
- lastDisplayState.playAnimation = playAnimation;
700
- changed = true;
701
- }
702
714
  //The flag is only cleared when the minimap is drawn
703
715
  if (this.minimapScissor.updateRequired && (this.displayMinimap || this.displayMiniAxes)) {
704
716
  changed = true;