@xeokit/xeokit-sdk 2.4.0-alpha-79 → 2.4.0-alpha-80

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.
@@ -85706,6 +85706,14 @@ class PivotController {
85706
85706
  this._pivoting = false; // True while pivoting
85707
85707
  this._shown = false;
85708
85708
 
85709
+ this._pivotSphereEnabled = false;
85710
+ this._pivotSphere = null;
85711
+ this._pivotSphereSize = 1;
85712
+ this._pivotSphereGeometry = null;
85713
+ this._pivotSphereMaterial = null;
85714
+ this._rtcCenter = math.vec3();
85715
+ this._rtcPos = math.vec3();
85716
+
85709
85717
  this._pivotViewPos = math.vec4();
85710
85718
  this._pivotProjPos = math.vec4();
85711
85719
  this._pivotCanvasPos = math.vec2();
@@ -85721,7 +85729,44 @@ class PivotController {
85721
85729
 
85722
85730
  this._onTick = this._scene.on("tick", () => {
85723
85731
  this.updatePivotElement();
85732
+ this.updatePivotSphere();
85733
+ });
85734
+ }
85735
+
85736
+ createPivotSphere() {
85737
+ const currentPos = this.getPivotPos();
85738
+ const cameraPos = math.vec3();
85739
+ math.decomposeMat4(math.inverseMat4(this._scene.viewer.camera.viewMatrix, math.mat4()), cameraPos, math.vec4(), math.vec3());
85740
+ const length = math.distVec3(cameraPos, currentPos);
85741
+ let radius = (Math.tan(Math.PI / 500) * length) * this._pivotSphereSize;
85742
+
85743
+ if (this._scene.camera.projection == "ortho") {
85744
+ radius /= (this._scene.camera.ortho.scale / 2);
85745
+ }
85746
+
85747
+ worldToRTCPos(currentPos, this._rtcCenter, this._rtcPos);
85748
+ this._pivotSphereGeometry = new VBOGeometry(
85749
+ this._scene,
85750
+ buildSphereGeometry({ radius })
85751
+ );
85752
+ this._pivotSphere = new Mesh(this._scene, {
85753
+ geometry: this._pivotSphereGeometry,
85754
+ material: this._pivotSphereMaterial,
85755
+ pickable: false,
85756
+ position: this._rtcPos,
85757
+ rtcCenter: this._rtcCenter
85724
85758
  });
85759
+ };
85760
+
85761
+ destroyPivotSphere() {
85762
+ if (this._pivotSphere) {
85763
+ this._pivotSphere.destroy();
85764
+ this._pivotSphere = null;
85765
+ }
85766
+ if (this._pivotSphereGeometry) {
85767
+ this._pivotSphereGeometry.destroy();
85768
+ this._pivotSphereGeometry = null;
85769
+ }
85725
85770
  }
85726
85771
 
85727
85772
  updatePivotElement() {
@@ -85760,6 +85805,15 @@ class PivotController {
85760
85805
  }
85761
85806
  }
85762
85807
 
85808
+ updatePivotSphere() {
85809
+ if (this._pivoting && this._pivotSphere) {
85810
+ worldToRTCPos(this.getPivotPos(), this._rtcCenter, this._rtcPos);
85811
+ if(!math.compareVec3(this._rtcPos, this._pivotSphere.position)) {
85812
+ this.destroyPivotSphere();
85813
+ this.createPivotSphere();
85814
+ }
85815
+ }
85816
+ }
85763
85817
  /**
85764
85818
  * Sets the HTML DOM element that will represent the pivot position.
85765
85819
  *
@@ -85769,6 +85823,37 @@ class PivotController {
85769
85823
  this._pivotElement = pivotElement;
85770
85824
  }
85771
85825
 
85826
+ /**
85827
+ * Sets a sphere as the representation of the pivot position.
85828
+ *
85829
+ * @param {Object} [cfg] Sphere configuration.
85830
+ * @param {String} [cfg.size=1] Optional size factor of the sphere. Defaults to 1.
85831
+ * @param {String} [cfg.color=Array] Optional maretial color. Defaults to a red.
85832
+ */
85833
+ enablePivotSphere(cfg = {}) {
85834
+ this.destroyPivotSphere();
85835
+ this._pivotSphereEnabled = true;
85836
+ if (cfg.size) {
85837
+ this._pivotSphereSize = cfg.size;
85838
+ }
85839
+ const color = cfg.color || [1, 0, 0];
85840
+ this._pivotSphereMaterial = new PhongMaterial(this._scene, {
85841
+ emissive: color,
85842
+ ambient: color,
85843
+ specular: [0,0,0],
85844
+ diffuse: [0,0,0],
85845
+ });
85846
+ }
85847
+
85848
+ /**
85849
+ * Remove the sphere as the representation of the pivot position.
85850
+ *
85851
+ */
85852
+ disablePivotSphere() {
85853
+ this.destroyPivotSphere();
85854
+ this._pivotSphereEnabled = false;
85855
+ }
85856
+
85772
85857
  /**
85773
85858
  * Begins pivoting.
85774
85859
  */
@@ -85838,6 +85923,7 @@ class PivotController {
85838
85923
  * Sets the pivot position to the 3D projection of the given 2D canvas coordinates on a sphere centered
85839
85924
  * at the viewpoint. The radius of the sphere is configured via {@link CameraControl#smartPivot}.
85840
85925
  *
85926
+ *
85841
85927
  * @param canvasPos
85842
85928
  */
85843
85929
  setCanvasPivotPos(canvasPos) {
@@ -85921,18 +86007,15 @@ class PivotController {
85921
86007
  if (this._shown) {
85922
86008
  return;
85923
86009
  }
85924
- if (this._hideTimeout !== null) {
85925
- window.clearTimeout(this._hideTimeout);
85926
- this._hideTimeout = null;
85927
- }
85928
86010
  if (this._pivotElement) {
85929
86011
  this.updatePivotElement();
85930
86012
  this._pivotElement.style.visibility = "visible";
85931
- this._shown = true;
85932
- this._hideTimeout = window.setTimeout(() => {
85933
- this.hidePivot();
85934
- }, 1000);
85935
86013
  }
86014
+ if (this._pivotSphereEnabled) {
86015
+ this.destroyPivotSphere();
86016
+ this.createPivotSphere();
86017
+ }
86018
+ this._shown = true;
85936
86019
  }
85937
86020
 
85938
86021
  /**
@@ -85944,13 +86027,12 @@ class PivotController {
85944
86027
  if (!this._shown) {
85945
86028
  return;
85946
86029
  }
85947
- if (this._hideTimeout !== null) {
85948
- window.clearTimeout(this._hideTimeout);
85949
- this._hideTimeout = null;
85950
- }
85951
86030
  if (this._pivotElement) {
85952
86031
  this._pivotElement.style.visibility = "hidden";
85953
86032
  }
86033
+ if (this._pivotSphereEnabled) {
86034
+ this.destroyPivotSphere();
86035
+ }
85954
86036
  this._shown = false;
85955
86037
  }
85956
86038
 
@@ -85962,6 +86044,7 @@ class PivotController {
85962
86044
  }
85963
86045
 
85964
86046
  destroy() {
86047
+ this.destroyPivotSphere();
85965
86048
  this._scene.camera.off(this._onViewMatrix);
85966
86049
  this._scene.camera.off(this._onProjMatrix);
85967
86050
  this._scene.off(this._onTick);
@@ -86838,6 +86921,10 @@ class MousePickHandler {
86838
86921
  if (e.which === 3) {
86839
86922
  rightDown = false;
86840
86923
  }
86924
+
86925
+ if (pivotController.getPivoting()) {
86926
+ pivotController.endPivot();
86927
+ }
86841
86928
  });
86842
86929
 
86843
86930
  canvas.addEventListener('mouseup', this._canvasMouseUpHandler = (e) => {
@@ -87070,6 +87157,10 @@ class KeyboardPanRotateDollyHandler {
87070
87157
  if (keyCode === input.KEY_SHIFT) {
87071
87158
  canvas.style.cursor = null;
87072
87159
  }
87160
+
87161
+ if (controllers.pivotController.getPivoting()) {
87162
+ controllers.pivotController.endPivot();
87163
+ }
87073
87164
  });
87074
87165
 
87075
87166
  this._onTick = scene.on("tick", (e) => {
@@ -87689,6 +87780,12 @@ class TouchPanRotateAndDollyHandler {
87689
87780
  numTouches = touches.length;
87690
87781
  });
87691
87782
 
87783
+ canvas.addEventListener("touchend", this._canvasTouchEndHandler = () => {
87784
+ if (pivotController.getPivoting()) {
87785
+ pivotController.endPivot();
87786
+ }
87787
+ });
87788
+
87692
87789
  canvas.addEventListener("touchmove", this._canvasTouchMoveHandler = (event) => {
87693
87790
 
87694
87791
  if (!(configs.active && configs.pointerEnabled)) {
@@ -87827,6 +87924,7 @@ class TouchPanRotateAndDollyHandler {
87827
87924
  destroy() {
87828
87925
  const canvas = this._scene.canvas.canvas;
87829
87926
  canvas.removeEventListener("touchstart", this._canvasTouchStartHandler);
87927
+ canvas.removeEventListener("touchend", this._canvasTouchEndHandler);
87830
87928
  canvas.removeEventListener("touchmove", this._canvasTouchMoveHandler);
87831
87929
  this._scene.off(this._onTick);
87832
87930
  }
@@ -89675,6 +89773,25 @@ class CameraControl extends Component {
89675
89773
  return this._configs.keyboardLayout;
89676
89774
  }
89677
89775
 
89776
+ /**
89777
+ * Sets a sphere as the representation of the pivot position.
89778
+ *
89779
+ * @param {Object} [cfg] Sphere configuration.
89780
+ * @param {String} [cfg.size=1] Optional size factor of the sphere. Defaults to 1.
89781
+ * @param {String} [cfg.material=PhongMaterial] Optional size factor of the sphere. Defaults to a red opaque material.
89782
+ */
89783
+ enablePivotSphere(cfg = {}) {
89784
+ this._controllers.pivotController.enablePivotSphere(cfg);
89785
+ }
89786
+
89787
+ /**
89788
+ * Remove the sphere as the representation of the pivot position.
89789
+ *
89790
+ */
89791
+ disablePivotSphere() {
89792
+ this._controllers.pivotController.disablePivotSphere();
89793
+ }
89794
+
89678
89795
  /**
89679
89796
  * Sets whether smart default pivoting is enabled.
89680
89797
  *
@@ -85702,6 +85702,14 @@ class PivotController {
85702
85702
  this._pivoting = false; // True while pivoting
85703
85703
  this._shown = false;
85704
85704
 
85705
+ this._pivotSphereEnabled = false;
85706
+ this._pivotSphere = null;
85707
+ this._pivotSphereSize = 1;
85708
+ this._pivotSphereGeometry = null;
85709
+ this._pivotSphereMaterial = null;
85710
+ this._rtcCenter = math.vec3();
85711
+ this._rtcPos = math.vec3();
85712
+
85705
85713
  this._pivotViewPos = math.vec4();
85706
85714
  this._pivotProjPos = math.vec4();
85707
85715
  this._pivotCanvasPos = math.vec2();
@@ -85717,7 +85725,44 @@ class PivotController {
85717
85725
 
85718
85726
  this._onTick = this._scene.on("tick", () => {
85719
85727
  this.updatePivotElement();
85728
+ this.updatePivotSphere();
85729
+ });
85730
+ }
85731
+
85732
+ createPivotSphere() {
85733
+ const currentPos = this.getPivotPos();
85734
+ const cameraPos = math.vec3();
85735
+ math.decomposeMat4(math.inverseMat4(this._scene.viewer.camera.viewMatrix, math.mat4()), cameraPos, math.vec4(), math.vec3());
85736
+ const length = math.distVec3(cameraPos, currentPos);
85737
+ let radius = (Math.tan(Math.PI / 500) * length) * this._pivotSphereSize;
85738
+
85739
+ if (this._scene.camera.projection == "ortho") {
85740
+ radius /= (this._scene.camera.ortho.scale / 2);
85741
+ }
85742
+
85743
+ worldToRTCPos(currentPos, this._rtcCenter, this._rtcPos);
85744
+ this._pivotSphereGeometry = new VBOGeometry(
85745
+ this._scene,
85746
+ buildSphereGeometry({ radius })
85747
+ );
85748
+ this._pivotSphere = new Mesh(this._scene, {
85749
+ geometry: this._pivotSphereGeometry,
85750
+ material: this._pivotSphereMaterial,
85751
+ pickable: false,
85752
+ position: this._rtcPos,
85753
+ rtcCenter: this._rtcCenter
85720
85754
  });
85755
+ };
85756
+
85757
+ destroyPivotSphere() {
85758
+ if (this._pivotSphere) {
85759
+ this._pivotSphere.destroy();
85760
+ this._pivotSphere = null;
85761
+ }
85762
+ if (this._pivotSphereGeometry) {
85763
+ this._pivotSphereGeometry.destroy();
85764
+ this._pivotSphereGeometry = null;
85765
+ }
85721
85766
  }
85722
85767
 
85723
85768
  updatePivotElement() {
@@ -85756,6 +85801,15 @@ class PivotController {
85756
85801
  }
85757
85802
  }
85758
85803
 
85804
+ updatePivotSphere() {
85805
+ if (this._pivoting && this._pivotSphere) {
85806
+ worldToRTCPos(this.getPivotPos(), this._rtcCenter, this._rtcPos);
85807
+ if(!math.compareVec3(this._rtcPos, this._pivotSphere.position)) {
85808
+ this.destroyPivotSphere();
85809
+ this.createPivotSphere();
85810
+ }
85811
+ }
85812
+ }
85759
85813
  /**
85760
85814
  * Sets the HTML DOM element that will represent the pivot position.
85761
85815
  *
@@ -85765,6 +85819,37 @@ class PivotController {
85765
85819
  this._pivotElement = pivotElement;
85766
85820
  }
85767
85821
 
85822
+ /**
85823
+ * Sets a sphere as the representation of the pivot position.
85824
+ *
85825
+ * @param {Object} [cfg] Sphere configuration.
85826
+ * @param {String} [cfg.size=1] Optional size factor of the sphere. Defaults to 1.
85827
+ * @param {String} [cfg.color=Array] Optional maretial color. Defaults to a red.
85828
+ */
85829
+ enablePivotSphere(cfg = {}) {
85830
+ this.destroyPivotSphere();
85831
+ this._pivotSphereEnabled = true;
85832
+ if (cfg.size) {
85833
+ this._pivotSphereSize = cfg.size;
85834
+ }
85835
+ const color = cfg.color || [1, 0, 0];
85836
+ this._pivotSphereMaterial = new PhongMaterial(this._scene, {
85837
+ emissive: color,
85838
+ ambient: color,
85839
+ specular: [0,0,0],
85840
+ diffuse: [0,0,0],
85841
+ });
85842
+ }
85843
+
85844
+ /**
85845
+ * Remove the sphere as the representation of the pivot position.
85846
+ *
85847
+ */
85848
+ disablePivotSphere() {
85849
+ this.destroyPivotSphere();
85850
+ this._pivotSphereEnabled = false;
85851
+ }
85852
+
85768
85853
  /**
85769
85854
  * Begins pivoting.
85770
85855
  */
@@ -85834,6 +85919,7 @@ class PivotController {
85834
85919
  * Sets the pivot position to the 3D projection of the given 2D canvas coordinates on a sphere centered
85835
85920
  * at the viewpoint. The radius of the sphere is configured via {@link CameraControl#smartPivot}.
85836
85921
  *
85922
+ *
85837
85923
  * @param canvasPos
85838
85924
  */
85839
85925
  setCanvasPivotPos(canvasPos) {
@@ -85917,18 +86003,15 @@ class PivotController {
85917
86003
  if (this._shown) {
85918
86004
  return;
85919
86005
  }
85920
- if (this._hideTimeout !== null) {
85921
- window.clearTimeout(this._hideTimeout);
85922
- this._hideTimeout = null;
85923
- }
85924
86006
  if (this._pivotElement) {
85925
86007
  this.updatePivotElement();
85926
86008
  this._pivotElement.style.visibility = "visible";
85927
- this._shown = true;
85928
- this._hideTimeout = window.setTimeout(() => {
85929
- this.hidePivot();
85930
- }, 1000);
85931
86009
  }
86010
+ if (this._pivotSphereEnabled) {
86011
+ this.destroyPivotSphere();
86012
+ this.createPivotSphere();
86013
+ }
86014
+ this._shown = true;
85932
86015
  }
85933
86016
 
85934
86017
  /**
@@ -85940,13 +86023,12 @@ class PivotController {
85940
86023
  if (!this._shown) {
85941
86024
  return;
85942
86025
  }
85943
- if (this._hideTimeout !== null) {
85944
- window.clearTimeout(this._hideTimeout);
85945
- this._hideTimeout = null;
85946
- }
85947
86026
  if (this._pivotElement) {
85948
86027
  this._pivotElement.style.visibility = "hidden";
85949
86028
  }
86029
+ if (this._pivotSphereEnabled) {
86030
+ this.destroyPivotSphere();
86031
+ }
85950
86032
  this._shown = false;
85951
86033
  }
85952
86034
 
@@ -85958,6 +86040,7 @@ class PivotController {
85958
86040
  }
85959
86041
 
85960
86042
  destroy() {
86043
+ this.destroyPivotSphere();
85961
86044
  this._scene.camera.off(this._onViewMatrix);
85962
86045
  this._scene.camera.off(this._onProjMatrix);
85963
86046
  this._scene.off(this._onTick);
@@ -86834,6 +86917,10 @@ class MousePickHandler {
86834
86917
  if (e.which === 3) {
86835
86918
  rightDown = false;
86836
86919
  }
86920
+
86921
+ if (pivotController.getPivoting()) {
86922
+ pivotController.endPivot();
86923
+ }
86837
86924
  });
86838
86925
 
86839
86926
  canvas.addEventListener('mouseup', this._canvasMouseUpHandler = (e) => {
@@ -87066,6 +87153,10 @@ class KeyboardPanRotateDollyHandler {
87066
87153
  if (keyCode === input.KEY_SHIFT) {
87067
87154
  canvas.style.cursor = null;
87068
87155
  }
87156
+
87157
+ if (controllers.pivotController.getPivoting()) {
87158
+ controllers.pivotController.endPivot();
87159
+ }
87069
87160
  });
87070
87161
 
87071
87162
  this._onTick = scene.on("tick", (e) => {
@@ -87685,6 +87776,12 @@ class TouchPanRotateAndDollyHandler {
87685
87776
  numTouches = touches.length;
87686
87777
  });
87687
87778
 
87779
+ canvas.addEventListener("touchend", this._canvasTouchEndHandler = () => {
87780
+ if (pivotController.getPivoting()) {
87781
+ pivotController.endPivot();
87782
+ }
87783
+ });
87784
+
87688
87785
  canvas.addEventListener("touchmove", this._canvasTouchMoveHandler = (event) => {
87689
87786
 
87690
87787
  if (!(configs.active && configs.pointerEnabled)) {
@@ -87823,6 +87920,7 @@ class TouchPanRotateAndDollyHandler {
87823
87920
  destroy() {
87824
87921
  const canvas = this._scene.canvas.canvas;
87825
87922
  canvas.removeEventListener("touchstart", this._canvasTouchStartHandler);
87923
+ canvas.removeEventListener("touchend", this._canvasTouchEndHandler);
87826
87924
  canvas.removeEventListener("touchmove", this._canvasTouchMoveHandler);
87827
87925
  this._scene.off(this._onTick);
87828
87926
  }
@@ -89671,6 +89769,25 @@ class CameraControl extends Component {
89671
89769
  return this._configs.keyboardLayout;
89672
89770
  }
89673
89771
 
89772
+ /**
89773
+ * Sets a sphere as the representation of the pivot position.
89774
+ *
89775
+ * @param {Object} [cfg] Sphere configuration.
89776
+ * @param {String} [cfg.size=1] Optional size factor of the sphere. Defaults to 1.
89777
+ * @param {String} [cfg.material=PhongMaterial] Optional size factor of the sphere. Defaults to a red opaque material.
89778
+ */
89779
+ enablePivotSphere(cfg = {}) {
89780
+ this._controllers.pivotController.enablePivotSphere(cfg);
89781
+ }
89782
+
89783
+ /**
89784
+ * Remove the sphere as the representation of the pivot position.
89785
+ *
89786
+ */
89787
+ disablePivotSphere() {
89788
+ this._controllers.pivotController.disablePivotSphere();
89789
+ }
89790
+
89674
89791
  /**
89675
89792
  * Sets whether smart default pivoting is enabled.
89676
89793
  *