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