@xeokit/xeokit-sdk 2.3.0-beta-22 → 2.3.0-beta-24

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.
@@ -12733,7 +12733,6 @@ class PickResult {
12733
12733
 
12734
12734
  /**
12735
12735
  * @private
12736
- * @param value
12737
12736
  */
12738
12737
  constructor() {
12739
12738
 
@@ -12770,6 +12769,12 @@ class PickResult {
12770
12769
  */
12771
12770
  this.pickSurfacePrecision = false;
12772
12771
 
12772
+ /**
12773
+ * True when picked from touch input, else false when from mouse input.
12774
+ * @type {boolean}
12775
+ */
12776
+ this.touchInput = false;
12777
+
12773
12778
  this._canvasPos = new Int16Array([0, 0]);
12774
12779
  this._origin = new Float64Array([0, 0, 0]);
12775
12780
  this._direction = new Float64Array([0, 0, 0]);
@@ -13047,6 +13052,7 @@ class PickResult {
13047
13052
  this._gotBary = false;
13048
13053
  this._gotWorldNormal = false;
13049
13054
  this._gotUV = false;
13055
+ this.touchInput = false;
13050
13056
  }
13051
13057
  }
13052
13058
 
@@ -15950,6 +15956,19 @@ const Renderer = function (scene, options) {
15950
15956
 
15951
15957
  //------------------------------------------------------------------------------------------------------
15952
15958
  // Render deferred bins
15959
+ //
15960
+ // Order:
15961
+ //
15962
+ // 1. Opaque color fill
15963
+ // 2. Opaque edges
15964
+ // 3. Opaque X-ray fill
15965
+ // 4. Opaque X-ray edges
15966
+ // 5. Opaque highlight
15967
+ // 6. Transparent highlight
15968
+ // 7. Selected opaque
15969
+ // 8. Selected transparent
15970
+ // 9. Normal transparent
15971
+ // 10. X-rayed transparent
15953
15972
  //------------------------------------------------------------------------------------------------------
15954
15973
 
15955
15974
  // Opaque color with SAO
@@ -15985,66 +16004,6 @@ const Renderer = function (scene, options) {
15985
16004
  }
15986
16005
  }
15987
16006
 
15988
- // Transparent
15989
-
15990
- if (xrayedFillTransparentBinLen > 0 || xrayEdgesTransparentBinLen > 0 || normalFillTransparentBinLen > 0 || normalEdgesTransparentBinLen > 0) {
15991
- gl.enable(gl.CULL_FACE);
15992
- gl.enable(gl.BLEND);
15993
- if (canvasTransparent) {
15994
- gl.blendEquation(gl.FUNC_ADD);
15995
- gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
15996
- } else {
15997
- gl.blendEquation(gl.FUNC_ADD);
15998
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
15999
- }
16000
- frameCtx.backfaces = false;
16001
- if (!alphaDepthMask) {
16002
- gl.depthMask(false);
16003
- }
16004
-
16005
- // Transparent color edges
16006
-
16007
- if (normalFillTransparentBinLen > 0 || normalEdgesTransparentBinLen > 0) {
16008
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
16009
- }
16010
- if (normalEdgesTransparentBinLen > 0) {
16011
- for (i = 0; i < normalEdgesTransparentBinLen; i++) {
16012
- drawable = normalEdgesTransparentBin[i];
16013
- drawable.drawEdgesColorTransparent(frameCtx);
16014
- }
16015
- }
16016
-
16017
- // Transparent color fill
16018
-
16019
- if (normalFillTransparentBinLen > 0) {
16020
- for (i = 0; i < normalFillTransparentBinLen; i++) {
16021
- drawable = normalFillTransparentBin[i];
16022
- drawable.drawColorTransparent(frameCtx);
16023
- }
16024
- }
16025
-
16026
- // Transparent X-ray edges
16027
-
16028
- if (xrayEdgesTransparentBinLen > 0) {
16029
- for (i = 0; i < xrayEdgesTransparentBinLen; i++) {
16030
- xrayEdgesTransparentBin[i].drawEdgesXRayed(frameCtx);
16031
- }
16032
- }
16033
-
16034
- // Transparent X-ray fill
16035
-
16036
- if (xrayedFillTransparentBinLen > 0) {
16037
- for (i = 0; i < xrayedFillTransparentBinLen; i++) {
16038
- xrayedFillTransparentBin[i].drawSilhouetteXRayed(frameCtx);
16039
- }
16040
- }
16041
-
16042
- gl.disable(gl.BLEND);
16043
- if (!alphaDepthMask) {
16044
- gl.depthMask(true);
16045
- }
16046
- }
16047
-
16048
16007
  // Opaque highlight
16049
16008
 
16050
16009
  if (highlightedFillOpaqueBinLen > 0 || highlightedEdgesOpaqueBinLen > 0) {
@@ -16163,6 +16122,66 @@ const Renderer = function (scene, options) {
16163
16122
  gl.disable(gl.BLEND);
16164
16123
  }
16165
16124
 
16125
+ // Transparent
16126
+
16127
+ if (xrayedFillTransparentBinLen > 0 || xrayEdgesTransparentBinLen > 0 || normalFillTransparentBinLen > 0 || normalEdgesTransparentBinLen > 0) {
16128
+ gl.enable(gl.CULL_FACE);
16129
+ gl.enable(gl.BLEND);
16130
+ if (canvasTransparent) {
16131
+ gl.blendEquation(gl.FUNC_ADD);
16132
+ gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
16133
+ } else {
16134
+ gl.blendEquation(gl.FUNC_ADD);
16135
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
16136
+ }
16137
+ frameCtx.backfaces = false;
16138
+ if (!alphaDepthMask) {
16139
+ gl.depthMask(false);
16140
+ }
16141
+
16142
+ // Transparent color edges
16143
+
16144
+ if (normalFillTransparentBinLen > 0 || normalEdgesTransparentBinLen > 0) {
16145
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
16146
+ }
16147
+ if (normalEdgesTransparentBinLen > 0) {
16148
+ for (i = 0; i < normalEdgesTransparentBinLen; i++) {
16149
+ drawable = normalEdgesTransparentBin[i];
16150
+ drawable.drawEdgesColorTransparent(frameCtx);
16151
+ }
16152
+ }
16153
+
16154
+ // Transparent color fill
16155
+
16156
+ if (normalFillTransparentBinLen > 0) {
16157
+ for (i = 0; i < normalFillTransparentBinLen; i++) {
16158
+ drawable = normalFillTransparentBin[i];
16159
+ drawable.drawColorTransparent(frameCtx);
16160
+ }
16161
+ }
16162
+
16163
+ // Transparent X-ray edges
16164
+
16165
+ if (xrayEdgesTransparentBinLen > 0) {
16166
+ for (i = 0; i < xrayEdgesTransparentBinLen; i++) {
16167
+ xrayEdgesTransparentBin[i].drawEdgesXRayed(frameCtx);
16168
+ }
16169
+ }
16170
+
16171
+ // Transparent X-ray fill
16172
+
16173
+ if (xrayedFillTransparentBinLen > 0) {
16174
+ for (i = 0; i < xrayedFillTransparentBinLen; i++) {
16175
+ xrayedFillTransparentBin[i].drawSilhouetteXRayed(frameCtx);
16176
+ }
16177
+ }
16178
+
16179
+ gl.disable(gl.BLEND);
16180
+ if (!alphaDepthMask) {
16181
+ gl.depthMask(true);
16182
+ }
16183
+ }
16184
+
16166
16185
  const endTime = Date.now();
16167
16186
  const frameStats = stats.frame;
16168
16187
 
@@ -46613,7 +46632,7 @@ class DistanceMeasurementsControl extends Component {
46613
46632
  this._active = false;
46614
46633
 
46615
46634
  this._currentDistMeasurement = null;
46616
- // Keep initial measurement state values to do not force values but put the default ones.
46635
+
46617
46636
  this._currentDistMeasurementInitState = {
46618
46637
  wireVisible: null,
46619
46638
  axisVisible: null,
@@ -46646,7 +46665,7 @@ class DistanceMeasurementsControl extends Component {
46646
46665
  }
46647
46666
 
46648
46667
  const cameraControl = this.plugin.viewer.cameraControl;
46649
-
46668
+ const canvas = this.scene.canvas.canvas;
46650
46669
  let hoveredEntity = null;
46651
46670
  const worldPos = math.vec3();
46652
46671
  const hoverCanvasPos = math.vec2();
@@ -46679,18 +46698,18 @@ class DistanceMeasurementsControl extends Component {
46679
46698
  }
46680
46699
  });
46681
46700
 
46682
- let lastX;
46683
- let lastY;
46684
- const tolerance = 5;
46701
+ let lastMouseCanvasX;
46702
+ let lastMouseCanvasY;
46703
+ const mouseCanvasTolerance = 5;
46685
46704
 
46686
46705
  this._onInputMouseDown = this.plugin.viewer.scene.input.on("mousedown", (coords) => {
46687
- lastX = coords[0];
46688
- lastY = coords[1];
46706
+ lastMouseCanvasX = coords[0];
46707
+ lastMouseCanvasY = coords[1];
46689
46708
  });
46690
46709
 
46691
46710
  this._onInputMouseUp = this.plugin.viewer.scene.input.on("mouseup", (coords) => {
46692
46711
 
46693
- if (coords[0] > lastX + tolerance || coords[0] < lastX - tolerance || coords[1] > lastY + tolerance || coords[1] < lastY - tolerance) {
46712
+ if (coords[0] > lastMouseCanvasX + mouseCanvasTolerance || coords[0] < lastMouseCanvasX - mouseCanvasTolerance || coords[1] > lastMouseCanvasY + mouseCanvasTolerance || coords[1] < lastMouseCanvasY - mouseCanvasTolerance) {
46694
46713
  return;
46695
46714
  }
46696
46715
 
@@ -46767,78 +46786,195 @@ class DistanceMeasurementsControl extends Component {
46767
46786
  this.plugin.viewer.scene.canvas.canvas.style.cursor = "default";
46768
46787
  });
46769
46788
 
46789
+ math.vec3();
46790
+ math.vec3();
46791
+
46792
+ let state = 0;
46793
+
46770
46794
  this._onPickedNothing = cameraControl.on("pickedNothing", e => {
46795
+ console.log("pick nothing");
46771
46796
  if (this._currentDistMeasurement) {
46772
46797
  this._currentDistMeasurement.destroy();
46773
46798
  this._currentDistMeasurement = null;
46774
46799
  }
46800
+ if (this.startDot) {
46801
+ this.startDot.setVisible(false);
46802
+ }
46803
+ state = 0;
46775
46804
  });
46776
46805
 
46777
- //-------------------------------------------------------------------------------------------------------------
46806
+ const tapStartCanvasPos = math.vec2();
46807
+ math.vec2();
46808
+ math.vec2();
46809
+ math.vec2();
46778
46810
 
46779
- // const canvas = this.scene.canvas.canvas;
46780
- // const tapStartCanvasPos = math.vec2();
46781
- // const tapCanvasPos0 = math.vec2();
46782
- // const tapCanvasPos1 = math.vec2();
46783
- // const touch0Vec = math.vec2();
46784
- // const lastCanvasTouchPosList = [];
46785
- // let numTouches = 0;
46786
- // let waitForTick = false;
46787
- //
46788
- // this._onTick = scene.on("tick", () => {
46789
- // waitForTick = false;
46811
+ const startWorldPos = math.vec3();
46812
+ math.vec3();
46813
+
46814
+ const lastCanvasTouchPosList = [];
46815
+
46816
+ this._onTick = scene.on("tick", () => {
46817
+ });
46818
+
46819
+ canvas.addEventListener("touchstart", this._canvasTouchStartHandler = (event) => {
46820
+
46821
+ console.log("touchStart");
46822
+
46823
+ event.preventDefault();
46824
+
46825
+ const touches = event.touches;
46826
+ const changedTouches = event.changedTouches;
46827
+
46828
+ if (touches.length === 1 && changedTouches.length === 1) {
46829
+
46830
+ getCanvasPosFromEvent$4(touches[0], tapStartCanvasPos);
46831
+
46832
+ const pickResult = this.plugin.viewer.scene.pick({
46833
+ canvasPos: tapStartCanvasPos,
46834
+ pickSurface: true,
46835
+ // pickSurfacePrecision: true
46836
+ });
46837
+
46838
+ if (pickResult && pickResult.worldPos) {
46839
+
46840
+ console.log("Finger is down over an object");
46841
+ if (state === 0) {
46842
+ if (this.startDot) {
46843
+ this.startDot.setVisible(true);
46844
+ this.startDot.setPos(tapStartCanvasPos[0], tapStartCanvasPos[1]);
46845
+ }
46846
+ startWorldPos.set(pickResult.worldPos);
46847
+ state = 1;
46848
+ } else {
46849
+ if (this.startDot) {
46850
+ this.startDot.setVisible(false);
46851
+ }
46852
+ }
46853
+ } else {
46854
+ const pickResult = this.plugin.viewer.scene.pick({
46855
+ canvasPos: tapStartCanvasPos,
46856
+ pickSurface: true,
46857
+ pickSurfacePrecision: true
46858
+ });
46859
+ if (pickResult && pickResult.worldPos) {
46860
+ this._currentDistMeasurement = this.plugin.createMeasurement({
46861
+ id: math.createUUID(),
46862
+ origin: {
46863
+ entity: hoveredEntity,
46864
+ worldPos: startWorldPos
46865
+ },
46866
+ target: {
46867
+ entity: hoveredEntity,
46868
+ worldPos: pickResult.worldPos
46869
+ },
46870
+ approximate: true
46871
+ });
46872
+ }
46873
+ if (this.startDot) {
46874
+ this.startDot.setVisible(false);
46875
+ }
46876
+ state = 0;
46877
+ }
46878
+ }
46879
+ while (lastCanvasTouchPosList.length < touches.length) {
46880
+ lastCanvasTouchPosList.push(math.vec2());
46881
+ }
46882
+ for (let i = 0, len = touches.length; i < len; ++i) {
46883
+ getCanvasPosFromEvent$4(touches[i], lastCanvasTouchPosList[i]);
46884
+ }
46885
+ });
46886
+
46887
+ // canvas.addEventListener("touchmove", this._canvasTouchMoveHandler = (event) => {
46888
+ // // event.stopPropagation();
46889
+ // event.preventDefault();
46890
+ // if (this.startDot) {
46891
+ // this.startDot.setVisible(false);
46892
+ // }
46893
+ // state = 0;
46790
46894
  // });
46895
+
46896
+ // canvas.addEventListener("touchend", this._canvasTouchEndHandler = (event) => {
46791
46897
  //
46792
- // canvas.addEventListener("touchstart", this._canvasTouchStartHandler = (event) => {
46898
+ // event.stopPropagation();
46793
46899
  // event.preventDefault();
46900
+ //
46901
+ // const currentTime = Date.now();
46794
46902
  // const touches = event.touches;
46795
46903
  // const changedTouches = event.changedTouches;
46796
- // if (touches.length === 1 && changedTouches.length === 1) {
46797
- // getCanvasPosFromEvent(touches[0], tapStartCanvasPos);
46798
46904
  //
46799
- // if (pickSurfacePrecisionEnabled) {
46800
- // const pickResult = this.plugin.viewer.scene.pick({
46801
- // canvasPos: tapStartCanvasPos,
46802
- // pickSurface: true,
46803
- // // pickSurfacePrecision: true
46804
- // });
46805
- // if (pickResult && pickResult.worldPos) {
46806
- // // this._currentDistMeasurement.target.worldPos = pickResult.worldPos;
46905
+ // if (touches.length === 0 && changedTouches.length === 1) {
46906
+ //
46907
+ // if (tapStartTime > -1 && currentTime - tapStartTime < TAP_INTERVAL) {
46908
+ //
46909
+ // if (lastTapTime > -1 && tapStartTime - lastTapTime < DBL_TAP_INTERVAL) {
46910
+ //
46911
+ // // Double-tap
46912
+ //
46913
+ // getCanvasPosFromEvent(changedTouches[0], pickController.pickCursorPos);
46914
+ // pickController.schedulePickEntity = true;
46915
+ // pickController.schedulePickSurface = pickedSurfaceSubs;
46916
+ //
46917
+ // pickController.update();
46918
+ //
46919
+ // if (pickController.pickResult) {
46920
+ //
46921
+ // cameraControl.fire("doublePicked", pickController.pickResult);
46922
+ //
46923
+ // if (pickController.pickedSurface) {
46924
+ // cameraControl.fire("doublePickedSurface", pickController.pickResult);
46925
+ // }
46926
+ //
46927
+ // if (configs.doublePickFlyTo) {
46928
+ // flyCameraTo(pickController.pickResult);
46929
+ // }
46930
+ // } else {
46931
+ // cameraControl.fire("doublePickedNothing");
46932
+ // if (configs.doublePickFlyTo) {
46933
+ // flyCameraTo();
46934
+ // }
46935
+ // }
46936
+ //
46937
+ // lastTapTime = -1;
46938
+ //
46939
+ // } else if (math.distVec2(activeTouches[0], tapStartPos) < TAP_DISTANCE_THRESHOLD) {
46940
+ //
46941
+ // // Single-tap
46942
+ //
46943
+ // getCanvasPosFromEvent(changedTouches[0], pickController.pickCursorPos);
46944
+ // pickController.schedulePickEntity = true;
46945
+ // pickController.schedulePickSurface = pickedSurfaceSubs;
46946
+ //
46947
+ // pickController.update();
46948
+ //
46949
+ // if (pickController.pickResult) {
46950
+ //
46951
+ // cameraControl.fire("picked", pickController.pickResult);
46952
+ //
46953
+ // if (pickController.pickedSurface) {
46954
+ // cameraControl.fire("pickedSurface", pickController.pickResult);
46955
+ // }
46956
+ //
46957
+ // } else {
46958
+ // cameraControl.fire("pickedNothing");
46959
+ // }
46960
+ //
46961
+ // lastTapTime = currentTime;
46807
46962
  // }
46808
- // // this._currentDistMeasurement.approximate = false;
46809
- // }
46810
46963
  //
46811
- // // TODO: Create start of measurement
46812
- // }
46813
- // while (lastCanvasTouchPosList.length < touches.length) {
46814
- // lastCanvasTouchPosList.push(math.vec2());
46964
+ // tapStartTime = -1
46965
+ // }
46815
46966
  // }
46967
+ //
46968
+ // activeTouches.length = touches.length;
46969
+ //
46816
46970
  // for (let i = 0, len = touches.length; i < len; ++i) {
46817
- // getCanvasPosFromEvent(touches[i], lastCanvasTouchPosList[i]);
46971
+ // activeTouches[i][0] = touches[i].pageX;
46972
+ // activeTouches[i][1] = touches[i].pageY;
46818
46973
  // }
46819
- // numTouches = touches.length;
46820
- // });
46821
46974
  //
46822
- // canvas.addEventListener("touchmove", this._canvasTouchMoveHandler = (event) => {
46823
46975
  // event.stopPropagation();
46824
- // event.preventDefault();
46825
- // if (waitForTick) { // Limit changes detection to one per frame
46826
- // return;
46827
- // }
46828
- // waitForTick = true;
46829
- // const touches = event.touches;
46830
- // if (event.touches.length !== numTouches) {
46831
- // // Two fingers were pressed, then one of them is removed
46832
- // return;
46833
- // }
46834
- // if (numTouches === 1) {
46835
- // getCanvasPosFromEvent(touches[0], tapCanvasPos0);
46836
- // // TODO: update end of distance measurement
46837
- // }
46838
- // for (let i = 0; i < numTouches; ++i) {
46839
- // getCanvasPosFromEvent(touches[i], lastCanvasTouchPosList[i]);
46840
- // }
46841
- // });
46976
+ //
46977
+ // }, {passive: true});
46842
46978
 
46843
46979
  //-------------------------------------------------------------------------------------------------------------
46844
46980
 
@@ -46905,9 +47041,28 @@ class DistanceMeasurementsControl extends Component {
46905
47041
  this.deactivate();
46906
47042
  super.destroy();
46907
47043
  }
46908
-
46909
47044
  }
46910
47045
 
47046
+ const getCanvasPosFromEvent$4 = function (event, canvasPos) {
47047
+ if (!event) {
47048
+ event = window.event;
47049
+ canvasPos[0] = event.x;
47050
+ canvasPos[1] = event.y;
47051
+ } else {
47052
+ let element = event.target;
47053
+ let totalOffsetLeft = 0;
47054
+ let totalOffsetTop = 0;
47055
+ while (element.offsetParent) {
47056
+ totalOffsetLeft += element.offsetLeft;
47057
+ totalOffsetTop += element.offsetTop;
47058
+ element = element.offsetParent;
47059
+ }
47060
+ canvasPos[0] = event.pageX - totalOffsetLeft;
47061
+ canvasPos[1] = event.pageY - totalOffsetTop;
47062
+ }
47063
+ return canvasPos;
47064
+ };
47065
+
46911
47066
  /**
46912
47067
  * {@link Viewer} plugin for measuring point-to-point distances.
46913
47068
  *
@@ -157271,8 +157426,8 @@ class TouchPanRotateAndDollyHandler {
157271
157426
  // Scaling drag-rotate to canvas boundary
157272
157427
 
157273
157428
  const canvasBoundary = scene.canvas.boundary;
157274
- const canvasWidth = canvasBoundary[0];
157275
- const canvasHeight = canvasBoundary[1];
157429
+ const canvasWidth = canvasBoundary[2];
157430
+ const canvasHeight = canvasBoundary[3];
157276
157431
 
157277
157432
  const touches = event.touches;
157278
157433
 
@@ -157548,6 +157703,8 @@ class TouchPickHandler {
157548
157703
 
157549
157704
  if (pickController.pickResult) {
157550
157705
 
157706
+ pickController.pickResult.touchInput = true;
157707
+
157551
157708
  cameraControl.fire("doublePicked", pickController.pickResult);
157552
157709
 
157553
157710
  if (pickController.pickedSurface) {
@@ -157578,6 +157735,8 @@ class TouchPickHandler {
157578
157735
 
157579
157736
  if (pickController.pickResult) {
157580
157737
 
157738
+ pickController.pickResult.touchInput = true;
157739
+
157581
157740
  cameraControl.fire("picked", pickController.pickResult);
157582
157741
 
157583
157742
  if (pickController.pickedSurface) {
@@ -157602,7 +157761,7 @@ class TouchPickHandler {
157602
157761
  activeTouches[i][1] = touches[i].pageY;
157603
157762
  }
157604
157763
 
157605
- e.stopPropagation();
157764
+ // e.stopPropagation();
157606
157765
 
157607
157766
  }, {passive: true});
157608
157767
 
@@ -159753,7 +159912,6 @@ class PropertySet {
159753
159912
  *
159754
159913
  * * Located in {@link Viewer#metaScene}.
159755
159914
  * * Contains {@link MetaModel}s and {@link MetaObject}s.
159756
- * * [Scene Graphs user guide](https://github.com/xeokit/xeokit-sdk/wiki/Scene-Graphs)
159757
159915
  * * [Scene graph example with metadata](http://xeokit.github.io/xeokit-sdk/examples/#sceneRepresentation_SceneGraph_metadata)
159758
159916
  */
159759
159917
  class MetaScene {