@xeokit/xeokit-sdk 2.4.2-beta-15 → 2.4.2-beta-19

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.
@@ -1045,8 +1045,8 @@ class PointerLens {
1045
1045
  this._lensCanvasContext = this._lensCanvas.getContext('2d');
1046
1046
  this._canvasElement = this.viewer.scene.canvas.canvas;
1047
1047
 
1048
- this._centerPos = null;
1049
- this._cursorPos = null;
1048
+ this._canvasPos = null;
1049
+ this._snappedCanvasPos = null;
1050
1050
  this._lensPosToggle = true;
1051
1051
 
1052
1052
  this._zoomLevel = cfg.zoomLevel || 2;
@@ -1069,14 +1069,14 @@ class PointerLens {
1069
1069
  if (!this._active || !this._visible) {
1070
1070
  return;
1071
1071
  }
1072
- if (!this._centerPos) {
1072
+ if (!this._canvasPos) {
1073
1073
  return;
1074
1074
  }
1075
1075
  const lensRect = this._lensContainer.getBoundingClientRect();
1076
1076
  const canvasRect = this._canvasElement.getBoundingClientRect();
1077
1077
  const pointerOnLens =
1078
- this._centerPos[0] < lensRect.right && this._centerPos[0] > lensRect.left &&
1079
- this._centerPos[1] < lensRect.bottom && this._centerPos[1] > lensRect.top;
1078
+ this._canvasPos[0] < lensRect.right && this._canvasPos[0] > lensRect.left &&
1079
+ this._canvasPos[1] < lensRect.bottom && this._canvasPos[1] > lensRect.top;
1080
1080
  this._lensContainer.style.marginLeft = `25px`;
1081
1081
  if (pointerOnLens) {
1082
1082
  if (this._lensPosToggle) {
@@ -1090,8 +1090,8 @@ class PointerLens {
1090
1090
  const size = Math.max(this._lensCanvas.width, this._lensCanvas.height) / this._zoomLevel;
1091
1091
  this._lensCanvasContext.drawImage(
1092
1092
  this._canvasElement, // source canvas
1093
- this._centerPos[0] - size / 2, // source x (zoom center)
1094
- this._centerPos[1] - size / 2, // source y (zoom center)
1093
+ this._canvasPos[0] - size / 2, // source x (zoom center)
1094
+ this._canvasPos[1] - size / 2, // source y (zoom center)
1095
1095
  size, // source width
1096
1096
  size, // source height
1097
1097
  0, // destination x
@@ -1105,9 +1105,9 @@ class PointerLens {
1105
1105
  (lensRect.top + lensRect.bottom) / 2
1106
1106
  ];
1107
1107
 
1108
- if (this._cursorPos) {
1109
- const deltaX = this._cursorPos[0] - this._centerPos[0];
1110
- const deltaY = this._cursorPos[1] - this._centerPos[1];
1108
+ if (this._snappedCanvasPos) {
1109
+ const deltaX = this._snappedCanvasPos[0] - this._canvasPos[0];
1110
+ const deltaY = this._snappedCanvasPos[1] - this._canvasPos[1];
1111
1111
 
1112
1112
  this._lensCursorDiv.style.marginLeft = `${centerLensCanvas[0] + deltaX * this._zoomLevel - 10}px`;
1113
1113
  this._lensCursorDiv.style.marginTop = `${centerLensCanvas[1] + deltaY * this._zoomLevel - 10}px`;
@@ -1143,10 +1143,10 @@ class PointerLens {
1143
1143
 
1144
1144
  /**
1145
1145
  * Sets the canvas central position of the lens.
1146
- * @param centerPos
1146
+ * @param canvasPos
1147
1147
  */
1148
- set centerPos(centerPos) {
1149
- this._centerPos = centerPos;
1148
+ set canvasPos(canvasPos) {
1149
+ this._canvasPos = canvasPos;
1150
1150
  this.update();
1151
1151
  }
1152
1152
 
@@ -1154,25 +1154,25 @@ class PointerLens {
1154
1154
  * Gets the canvas central position of the lens.
1155
1155
  * @returns {Number[]}
1156
1156
  */
1157
- get centerPos() {
1158
- return this._centerPos;
1157
+ get canvasPos() {
1158
+ return this._canvasPos;
1159
1159
  }
1160
1160
 
1161
1161
  /**
1162
1162
  * Sets the canvas coordinates of the pointer.
1163
- * @param cursorPos
1163
+ * @param snappedCanvasPos
1164
1164
  */
1165
- set cursorPos(cursorPos) {
1166
- this._cursorPos = cursorPos;
1165
+ set snappedCanvasPos(snappedCanvasPos) {
1166
+ this._snappedCanvasPos = snappedCanvasPos;
1167
1167
  this.update();
1168
1168
  }
1169
1169
 
1170
1170
  /**
1171
- * Gets the canvas coordinates of the pointer.
1171
+ * Gets the canvas coordinates of the snapped pointer.
1172
1172
  * @returns {Number[]}
1173
1173
  */
1174
- get cursorPos() {
1175
- return this._cursorPos;
1174
+ get snappedCanvasPos() {
1175
+ return this._snappedCanvasPos;
1176
1176
  }
1177
1177
 
1178
1178
  /**
@@ -12013,8 +12013,8 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
12013
12013
  if (event.snappedToVertex || event.snappedToEdge) {
12014
12014
  if (pointerLens) {
12015
12015
  pointerLens.visible = true;
12016
- pointerLens.centerPos = event.cursorPos || event.canvasPos;
12017
- pointerLens.cursorPos = event.canvasPos;
12016
+ pointerLens.canvasPos = event.canvasPos;
12017
+ pointerLens.snappedCanvasPos = event.snappedCanvasPos || event.canvasPos;
12018
12018
  pointerLens.snapped = true;
12019
12019
  }
12020
12020
  this.markerDiv.style.background = "greenyellow";
@@ -12022,21 +12022,22 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
12022
12022
  } else {
12023
12023
  if (pointerLens) {
12024
12024
  pointerLens.visible = true;
12025
- pointerLens.centerPos = event.cursorPos || event.canvasPos;
12026
- pointerLens.cursorPos = event.canvasPos;
12025
+ pointerLens.canvasPos = event.canvasPos;
12026
+ pointerLens.snappedCanvasPos = event.canvasPos;
12027
12027
  pointerLens.snapped = false;
12028
12028
  }
12029
12029
  this.markerDiv.style.background = "pink";
12030
12030
  this.markerDiv.style.border = "2px solid red";
12031
12031
  }
12032
+ const canvasPos = event.snappedCanvasPos || event.canvasPos;
12032
12033
  mouseHovering = true;
12033
12034
  mouseHoverEntity = event.entity;
12034
12035
  mouseWorldPos.set(event.worldPos);
12035
- mouseHoverCanvasPos.set(event.canvasPos);
12036
+ mouseHoverCanvasPos.set(canvasPos);
12036
12037
  switch (this._mouseState) {
12037
12038
  case MOUSE_FINDING_ORIGIN:
12038
- this.markerDiv.style.marginLeft = `${event.canvasPos[0] - 5}px`;
12039
- this.markerDiv.style.marginTop = `${event.canvasPos[1] - 5}px`;
12039
+ this.markerDiv.style.marginLeft = `${canvasPos[0] - 5}px`;
12040
+ this.markerDiv.style.marginTop = `${canvasPos[1] - 5}px`;
12040
12041
  break;
12041
12042
  case MOUSE_FINDING_CORNER:
12042
12043
  if (this._currentAngleMeasurement) {
@@ -12152,8 +12153,8 @@ class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
12152
12153
  mouseHovering = false;
12153
12154
  if (pointerLens) {
12154
12155
  pointerLens.visible = true;
12155
- pointerLens.centerPos = event.cursorPos;
12156
- pointerLens.cursorPos = event.cursorPos;
12156
+ pointerLens.pointerPos = event.canvasPos;
12157
+ pointerLens.snappedCanvasPos = event.snappedCanvasPos || event.canvasPos;
12157
12158
  pointerLens.snapped = false;
12158
12159
  }
12159
12160
  this.markerDiv.style.marginLeft = `-100px`;
@@ -14793,13 +14794,14 @@ class PickResult {
14793
14794
  */
14794
14795
  this.snappedToVertex = false;
14795
14796
 
14796
- this._canvasPos = new Int16Array([0, 0]);
14797
14797
  this._origin = new Float64Array([0, 0, 0]);
14798
14798
  this._direction = new Float64Array([0, 0, 0]);
14799
14799
  this._indices = new Int32Array(3);
14800
14800
  this._localPos = new Float64Array([0, 0, 0]);
14801
14801
  this._worldPos = new Float64Array([0, 0, 0]);
14802
14802
  this._viewPos = new Float64Array([0, 0, 0]);
14803
+ this._canvasPos = new Int16Array([0, 0]);
14804
+ this._snappedCanvasPos = new Int16Array([0, 0]);
14803
14805
  this._bary = new Float64Array([0, 0, 0]);
14804
14806
  this._worldNormal = new Float64Array([0, 0, 0]);
14805
14807
  this._uv = new Float64Array([0, 0]);
@@ -14808,7 +14810,7 @@ class PickResult {
14808
14810
  }
14809
14811
 
14810
14812
  /**
14811
- * Canvas coordinates when picking with a 2D pointer.
14813
+ * Canvas pick coordinates.
14812
14814
  * @property canvasPos
14813
14815
  * @type {Number[]}
14814
14816
  */
@@ -14926,6 +14928,29 @@ class PickResult {
14926
14928
  }
14927
14929
  }
14928
14930
 
14931
+ /**
14932
+ * Canvas cursor coordinates, snapped when snap picking, otherwise same as {@link PickResult#pointerPos}.
14933
+ * @property snappedCanvasPos
14934
+ * @type {Number[]}
14935
+ */
14936
+ get snappedCanvasPos() {
14937
+ return this._gotSnappedCanvasPos ? this._snappedCanvasPos : null;
14938
+ }
14939
+
14940
+ /**
14941
+ * @private
14942
+ * @param value
14943
+ */
14944
+ set snappedCanvasPos(value) {
14945
+ if (value) {
14946
+ this._snappedCanvasPos[0] = value[0];
14947
+ this._snappedCanvasPos[1] = value[1];
14948
+ this._gotSnappedCanvasPos = true;
14949
+ } else {
14950
+ this._gotSnappedCanvasPos = false;
14951
+ }
14952
+ }
14953
+
14929
14954
  /**
14930
14955
  * Picked World-space point.
14931
14956
  * @property worldPos
@@ -15054,6 +15079,7 @@ class PickResult {
15054
15079
  this.primitive = null;
15055
15080
  this.pickSurfacePrecision = false;
15056
15081
  this._gotCanvasPos = false;
15082
+ this._gotSnappedCanvasPos = false;
15057
15083
  this._gotOrigin = false;
15058
15084
  this._gotDirection = false;
15059
15085
  this._gotIndices = false;
@@ -18450,254 +18476,258 @@ const Renderer$1 = function (scene, options) {
18450
18476
  * @param {number} [snapRadiusInPixels=30]
18451
18477
  * @param {boolean} [snapToVertex=true]
18452
18478
  * @param {boolean} [snapToEdge=true]
18453
- *
18454
- * @returns {{worldPos:number[],snappedWorldPos:null|number[],snappedCanvasPos:null|number[], snapType:null|"vertex"|"edge"}}
18479
+ * @param pickResult
18480
+ * @returns {PickResult}
18455
18481
  */
18456
- this.snapPick = function (canvasPos, snapRadiusInPixels = 30, snapToVertex = true, snapToEdge = true) {
18482
+ this.snapPick = (function () {
18457
18483
 
18458
- if (!snapToVertex && !snapToEdge) {
18459
- return this.pick({canvasPos, pickSurface: true});
18460
- }
18484
+ const _pickResult = new PickResult();
18461
18485
 
18462
- const resolutionScale = scene.canvas.resolutionScale;
18486
+ return function (canvasPos, snapRadiusInPixels, snapToVertex, snapToEdge, pickResult = _pickResult) {
18463
18487
 
18464
- frameCtx.reset();
18465
- frameCtx.backfaces = true;
18466
- frameCtx.frontface = true; // "ccw"
18467
- frameCtx.pickZNear = scene.camera.project.near;
18468
- frameCtx.pickZFar = scene.camera.project.far;
18469
-
18470
- const vertexPickBuffer = renderBufferManager.getRenderBuffer("uniquePickColors-aabs", {
18471
- depthTexture: true,
18472
- size: [
18473
- 2 * snapRadiusInPixels + 1,
18474
- 2 * snapRadiusInPixels + 1,
18475
- ]
18476
- });
18488
+ if (!snapToVertex && !snapToEdge) {
18489
+ return this.pick({canvasPos, pickSurface: true});
18490
+ }
18477
18491
 
18478
- frameCtx.snapVectorA = [
18479
- getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth),
18480
- getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight),
18481
- ];
18492
+ const resolutionScale = scene.canvas.resolutionScale;
18482
18493
 
18483
- frameCtx.snapInvVectorAB = [
18484
- gl.drawingBufferWidth / (2 * snapRadiusInPixels),
18485
- gl.drawingBufferHeight / (2 * snapRadiusInPixels),
18486
- ];
18494
+ frameCtx.reset();
18495
+ frameCtx.backfaces = true;
18496
+ frameCtx.frontface = true; // "ccw"
18497
+ frameCtx.pickZNear = scene.camera.project.near;
18498
+ frameCtx.pickZFar = scene.camera.project.far;
18487
18499
 
18488
- // Bind and clear the snap render target
18500
+ snapRadiusInPixels = snapRadiusInPixels || 30;
18489
18501
 
18490
- vertexPickBuffer.bind(gl.RGBA32I, gl.RGBA32I, gl.RGBA8UI);
18491
- gl.viewport(0, 0, vertexPickBuffer.size[0], vertexPickBuffer.size[1]);
18492
- gl.enable(gl.DEPTH_TEST);
18493
- gl.frontFace(gl.CCW);
18494
- gl.disable(gl.CULL_FACE);
18495
- gl.depthMask(true);
18496
- gl.disable(gl.BLEND);
18497
- gl.depthFunc(gl.LEQUAL);
18498
- gl.clear(gl.DEPTH_BUFFER_BIT);
18499
- gl.clearBufferiv(gl.COLOR, 0, new Int32Array([0, 0, 0, 0]));
18500
- gl.clearBufferiv(gl.COLOR, 1, new Int32Array([0, 0, 0, 0]));
18501
- gl.clearBufferuiv(gl.COLOR, 2, new Uint32Array([0, 0, 0, 0]));
18502
+ const vertexPickBuffer = renderBufferManager.getRenderBuffer("uniquePickColors-aabs", {
18503
+ depthTexture: true,
18504
+ size: [
18505
+ 2 * snapRadiusInPixels + 1,
18506
+ 2 * snapRadiusInPixels + 1,
18507
+ ]
18508
+ });
18502
18509
 
18503
- //////////////////////////////////
18504
- // Set view and proj mats for VBO renderers
18505
- ///////////////////////////////////////
18510
+ frameCtx.snapVectorA = [
18511
+ getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth),
18512
+ getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight),
18513
+ ];
18506
18514
 
18507
- const pickViewMatrix = scene.camera.viewMatrix;
18508
- const pickProjMatrix = scene.camera.projMatrix;
18515
+ frameCtx.snapInvVectorAB = [
18516
+ gl.drawingBufferWidth / (2 * snapRadiusInPixels),
18517
+ gl.drawingBufferHeight / (2 * snapRadiusInPixels),
18518
+ ];
18509
18519
 
18510
- for (let type in drawableTypeInfo) {
18511
- if (drawableTypeInfo.hasOwnProperty(type)) {
18512
- const drawableList = drawableTypeInfo[type].drawableList;
18513
- for (let i = 0, len = drawableList.length; i < len; i++) {
18514
- const drawable = drawableList[i];
18515
- if (drawable.setPickMatrices) { // Eg. SceneModel, which needs pre-loading into texture
18516
- drawable.setPickMatrices(pickViewMatrix, pickProjMatrix);
18520
+ // Bind and clear the snap render target
18521
+
18522
+ vertexPickBuffer.bind(gl.RGBA32I, gl.RGBA32I, gl.RGBA8UI);
18523
+ gl.viewport(0, 0, vertexPickBuffer.size[0], vertexPickBuffer.size[1]);
18524
+ gl.enable(gl.DEPTH_TEST);
18525
+ gl.frontFace(gl.CCW);
18526
+ gl.disable(gl.CULL_FACE);
18527
+ gl.depthMask(true);
18528
+ gl.disable(gl.BLEND);
18529
+ gl.depthFunc(gl.LEQUAL);
18530
+ gl.clear(gl.DEPTH_BUFFER_BIT);
18531
+ gl.clearBufferiv(gl.COLOR, 0, new Int32Array([0, 0, 0, 0]));
18532
+ gl.clearBufferiv(gl.COLOR, 1, new Int32Array([0, 0, 0, 0]));
18533
+ gl.clearBufferuiv(gl.COLOR, 2, new Uint32Array([0, 0, 0, 0]));
18534
+
18535
+ //////////////////////////////////
18536
+ // Set view and proj mats for VBO renderers
18537
+ ///////////////////////////////////////
18538
+
18539
+ const pickViewMatrix = scene.camera.viewMatrix;
18540
+ const pickProjMatrix = scene.camera.projMatrix;
18541
+
18542
+ for (let type in drawableTypeInfo) {
18543
+ if (drawableTypeInfo.hasOwnProperty(type)) {
18544
+ const drawableList = drawableTypeInfo[type].drawableList;
18545
+ for (let i = 0, len = drawableList.length; i < len; i++) {
18546
+ const drawable = drawableList[i];
18547
+ if (drawable.setPickMatrices) { // Eg. SceneModel, which needs pre-loading into texture
18548
+ drawable.setPickMatrices(pickViewMatrix, pickProjMatrix);
18549
+ }
18517
18550
  }
18518
18551
  }
18519
18552
  }
18520
- }
18521
18553
 
18522
- // a) init z-buffer
18523
- gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1, gl.COLOR_ATTACHMENT2]);
18524
- const layerParamsSurface = snapInitDepthBuf(frameCtx);
18554
+ // a) init z-buffer
18555
+ gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1, gl.COLOR_ATTACHMENT2]);
18556
+ const layerParamsSurface = snapInitDepthBuf(frameCtx);
18525
18557
 
18526
- // b) snap-pick
18527
- const layerParamsSnap = [];
18528
- frameCtx.snapPickLayerParams = layerParamsSnap;
18558
+ // b) snap-pick
18559
+ const layerParamsSnap = [];
18560
+ frameCtx.snapPickLayerParams = layerParamsSnap;
18529
18561
 
18530
- gl.depthMask(false);
18531
- gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
18562
+ gl.depthMask(false);
18563
+ gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
18532
18564
 
18533
- if (snapToVertex && snapToEdge) {
18534
- frameCtx.snapMode = "edge";
18535
- snapPickDrawSnapDepths(frameCtx);
18565
+ if (snapToVertex && snapToEdge) {
18566
+ frameCtx.snapMode = "edge";
18567
+ snapPickDrawSnapDepths(frameCtx);
18536
18568
 
18537
- frameCtx.snapMode = "vertex";
18538
- frameCtx.snapPickLayerNumber++;
18569
+ frameCtx.snapMode = "vertex";
18570
+ frameCtx.snapPickLayerNumber++;
18539
18571
 
18540
- snapPickDrawSnapDepths(frameCtx);
18541
- } else {
18542
- frameCtx.snapMode = snapToVertex ? "vertex" : "edge";
18572
+ snapPickDrawSnapDepths(frameCtx);
18573
+ } else {
18574
+ frameCtx.snapMode = snapToVertex ? "vertex" : "edge";
18543
18575
 
18544
- snapPickDrawSnapDepths(frameCtx);
18545
- }
18576
+ snapPickDrawSnapDepths(frameCtx);
18577
+ }
18546
18578
 
18547
- gl.depthMask(true);
18579
+ gl.depthMask(true);
18548
18580
 
18549
- // Read and decode the snapped coordinates
18581
+ // Read and decode the snapped coordinates
18550
18582
 
18551
- const snapPickResultArray = vertexPickBuffer.readArray(gl.RGBA_INTEGER, gl.INT, Int32Array, 4);
18552
- const snapPickNormalResultArray = vertexPickBuffer.readArray(gl.RGBA_INTEGER, gl.INT, Int32Array, 4, 1);
18553
- const snapPickIdResultArray = vertexPickBuffer.readArray(gl.RGBA_INTEGER, gl.UNSIGNED_INT, Uint32Array, 4, 2);
18583
+ const snapPickResultArray = vertexPickBuffer.readArray(gl.RGBA_INTEGER, gl.INT, Int32Array, 4);
18584
+ const snapPickNormalResultArray = vertexPickBuffer.readArray(gl.RGBA_INTEGER, gl.INT, Int32Array, 4, 1);
18585
+ const snapPickIdResultArray = vertexPickBuffer.readArray(gl.RGBA_INTEGER, gl.UNSIGNED_INT, Uint32Array, 4, 2);
18554
18586
 
18555
- vertexPickBuffer.unbind();
18587
+ vertexPickBuffer.unbind();
18556
18588
 
18557
- // result 1) regular hi-precision world position
18589
+ // result 1) regular hi-precision world position
18558
18590
 
18559
- let worldPos = null;
18560
- let worldNormal = null;
18591
+ let worldPos = null;
18561
18592
 
18562
- const middleX = snapRadiusInPixels;
18563
- const middleY = snapRadiusInPixels;
18564
- const middleIndex = (middleX * 4) + (middleY * vertexPickBuffer.size[0] * 4);
18565
- const pickResultMiddleXY = snapPickResultArray.slice(middleIndex, middleIndex + 4);
18566
- const pickNormalResultMiddleXY = snapPickNormalResultArray.slice(middleIndex, middleIndex + 4);
18567
- const pickPickableResultMiddleXY = snapPickIdResultArray.slice(middleIndex, middleIndex + 4);
18593
+ const middleX = snapRadiusInPixels;
18594
+ const middleY = snapRadiusInPixels;
18595
+ const middleIndex = (middleX * 4) + (middleY * vertexPickBuffer.size[0] * 4);
18596
+ const pickResultMiddleXY = snapPickResultArray.slice(middleIndex, middleIndex + 4);
18597
+ const pickNormalResultMiddleXY = snapPickNormalResultArray.slice(middleIndex, middleIndex + 4);
18598
+ const pickPickableResultMiddleXY = snapPickIdResultArray.slice(middleIndex, middleIndex + 4);
18568
18599
 
18569
- if (pickResultMiddleXY[3] !== 0) {
18570
- const pickedLayerParmasSurface = layerParamsSurface[Math.abs(pickResultMiddleXY[3]) % layerParamsSurface.length];
18571
- const origin = pickedLayerParmasSurface.origin;
18572
- const scale = pickedLayerParmasSurface.coordinateScale;
18573
- worldPos = [
18574
- pickResultMiddleXY[0] * scale[0] + origin[0],
18575
- pickResultMiddleXY[1] * scale[1] + origin[1],
18576
- pickResultMiddleXY[2] * scale[2] + origin[2],
18577
- ];
18578
- worldNormal = math.normalizeVec3([
18579
- pickNormalResultMiddleXY[0] / math.MAX_INT,
18580
- pickNormalResultMiddleXY[1] / math.MAX_INT,
18581
- pickNormalResultMiddleXY[2] / math.MAX_INT,
18582
- ]);
18583
-
18584
- const pickID =
18585
- pickPickableResultMiddleXY[0]
18586
- + (pickPickableResultMiddleXY[1] << 8)
18587
- + (pickPickableResultMiddleXY[2] << 16)
18588
- + (pickPickableResultMiddleXY[3] << 24);
18589
-
18590
- pickIDs.items[pickID];
18591
- }
18592
-
18593
- // result 2) hi-precision snapped (to vertex/edge) world position
18594
-
18595
- let snapPickResult = [];
18596
-
18597
- for (let i = 0; i < snapPickResultArray.length; i += 4) {
18598
- if (snapPickResultArray[i + 3] > 0) {
18599
- const pixelNumber = Math.floor(i / 4);
18600
- const w = vertexPickBuffer.size[0];
18601
- const x = pixelNumber % w - Math.floor(w / 2);
18602
- const y = Math.floor(pixelNumber / w) - Math.floor(w / 2);
18603
- const dist = (Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
18604
- snapPickResult.push({
18605
- x,
18606
- y,
18607
- dist,
18608
- isVertex: snapToVertex && snapToEdge ? snapPickResultArray[i + 3] > layerParamsSnap.length / 2 : snapToVertex,
18609
- result: [
18610
- snapPickResultArray[i + 0],
18611
- snapPickResultArray[i + 1],
18612
- snapPickResultArray[i + 2],
18613
- snapPickResultArray[i + 3],
18614
- ],
18615
- normal: [
18616
- snapPickNormalResultArray[i + 0],
18617
- snapPickNormalResultArray[i + 1],
18618
- snapPickNormalResultArray[i + 2],
18619
- snapPickNormalResultArray[i + 3],
18620
- ],
18621
- id: [
18622
- snapPickIdResultArray[i + 0],
18623
- snapPickIdResultArray[i + 1],
18624
- snapPickIdResultArray[i + 2],
18625
- snapPickIdResultArray[i + 3],
18626
- ]
18627
- });
18600
+ if (pickResultMiddleXY[3] !== 0) {
18601
+ const pickedLayerParmasSurface = layerParamsSurface[Math.abs(pickResultMiddleXY[3]) % layerParamsSurface.length];
18602
+ const origin = pickedLayerParmasSurface.origin;
18603
+ const scale = pickedLayerParmasSurface.coordinateScale;
18604
+ worldPos = [
18605
+ pickResultMiddleXY[0] * scale[0] + origin[0],
18606
+ pickResultMiddleXY[1] * scale[1] + origin[1],
18607
+ pickResultMiddleXY[2] * scale[2] + origin[2],
18608
+ ];
18609
+ math.normalizeVec3([
18610
+ pickNormalResultMiddleXY[0] / math.MAX_INT,
18611
+ pickNormalResultMiddleXY[1] / math.MAX_INT,
18612
+ pickNormalResultMiddleXY[2] / math.MAX_INT,
18613
+ ]);
18614
+
18615
+ const pickID =
18616
+ pickPickableResultMiddleXY[0]
18617
+ + (pickPickableResultMiddleXY[1] << 8)
18618
+ + (pickPickableResultMiddleXY[2] << 16)
18619
+ + (pickPickableResultMiddleXY[3] << 24);
18620
+
18621
+ pickIDs.items[pickID];
18622
+ }
18623
+
18624
+ // result 2) hi-precision snapped (to vertex/edge) world position
18625
+
18626
+ let snapPickResult = [];
18627
+
18628
+ for (let i = 0; i < snapPickResultArray.length; i += 4) {
18629
+ if (snapPickResultArray[i + 3] > 0) {
18630
+ const pixelNumber = Math.floor(i / 4);
18631
+ const w = vertexPickBuffer.size[0];
18632
+ const x = pixelNumber % w - Math.floor(w / 2);
18633
+ const y = Math.floor(pixelNumber / w) - Math.floor(w / 2);
18634
+ const dist = (Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
18635
+ snapPickResult.push({
18636
+ x,
18637
+ y,
18638
+ dist,
18639
+ isVertex: snapToVertex && snapToEdge ? snapPickResultArray[i + 3] > layerParamsSnap.length / 2 : snapToVertex,
18640
+ result: [
18641
+ snapPickResultArray[i + 0],
18642
+ snapPickResultArray[i + 1],
18643
+ snapPickResultArray[i + 2],
18644
+ snapPickResultArray[i + 3],
18645
+ ],
18646
+ normal: [
18647
+ snapPickNormalResultArray[i + 0],
18648
+ snapPickNormalResultArray[i + 1],
18649
+ snapPickNormalResultArray[i + 2],
18650
+ snapPickNormalResultArray[i + 3],
18651
+ ],
18652
+ id: [
18653
+ snapPickIdResultArray[i + 0],
18654
+ snapPickIdResultArray[i + 1],
18655
+ snapPickIdResultArray[i + 2],
18656
+ snapPickIdResultArray[i + 3],
18657
+ ]
18658
+ });
18659
+ }
18628
18660
  }
18629
- }
18630
18661
 
18631
- let snappedWorldPos = null;
18632
- let snappedWorldNormal = null;
18633
- let snappedPickable = null;
18634
- let snapType = null;
18662
+ let snappedWorldPos = null;
18663
+ let snappedWorldNormal = null;
18664
+ let snappedPickable = null;
18665
+ let snapType = null;
18635
18666
 
18636
- if (snapPickResult.length > 0) {
18637
- // vertex snap first, then edge snap
18638
- snapPickResult.sort((a, b) => {
18639
- if (a.isVertex !== b.isVertex) {
18640
- return a.isVertex ? -1 : 1;
18641
- } else {
18642
- return a.dist - b.dist;
18643
- }
18644
- });
18667
+ if (snapPickResult.length > 0) {
18668
+ // vertex snap first, then edge snap
18669
+ snapPickResult.sort((a, b) => {
18670
+ if (a.isVertex !== b.isVertex) {
18671
+ return a.isVertex ? -1 : 1;
18672
+ } else {
18673
+ return a.dist - b.dist;
18674
+ }
18675
+ });
18645
18676
 
18646
- snapType = snapPickResult[0].isVertex ? "vertex" : "edge";
18647
- const snapPick = snapPickResult[0].result;
18648
- const snapPickNormal = snapPickResult[0].normal;
18649
- const snapPickId = snapPickResult[0].id;
18677
+ snapType = snapPickResult[0].isVertex ? "vertex" : "edge";
18678
+ const snapPick = snapPickResult[0].result;
18679
+ const snapPickNormal = snapPickResult[0].normal;
18680
+ const snapPickId = snapPickResult[0].id;
18650
18681
 
18651
- const pickedLayerParmas = layerParamsSnap[snapPick[3]];
18682
+ const pickedLayerParmas = layerParamsSnap[snapPick[3]];
18652
18683
 
18653
- const origin = pickedLayerParmas.origin;
18654
- const scale = pickedLayerParmas.coordinateScale;
18684
+ const origin = pickedLayerParmas.origin;
18685
+ const scale = pickedLayerParmas.coordinateScale;
18655
18686
 
18656
- snappedWorldNormal = math.normalizeVec3([
18657
- snapPickNormal[0] / math.MAX_INT,
18658
- snapPickNormal[1] / math.MAX_INT,
18659
- snapPickNormal[2] / math.MAX_INT,
18660
- ]);
18687
+ snappedWorldNormal = math.normalizeVec3([
18688
+ snapPickNormal[0] / math.MAX_INT,
18689
+ snapPickNormal[1] / math.MAX_INT,
18690
+ snapPickNormal[2] / math.MAX_INT,
18691
+ ]);
18661
18692
 
18662
- snappedWorldPos = [
18663
- snapPick[0] * scale[0] + origin[0],
18664
- snapPick[1] * scale[1] + origin[1],
18665
- snapPick[2] * scale[2] + origin[2],
18666
- ];
18693
+ snappedWorldPos = [
18694
+ snapPick[0] * scale[0] + origin[0],
18695
+ snapPick[1] * scale[1] + origin[1],
18696
+ snapPick[2] * scale[2] + origin[2],
18697
+ ];
18667
18698
 
18668
- snappedPickable = pickIDs.items[
18699
+ snappedPickable = pickIDs.items[
18669
18700
  snapPickId[0]
18670
18701
  + (snapPickId[1] << 8)
18671
18702
  + (snapPickId[2] << 16)
18672
18703
  + (snapPickId[3] << 24)
18673
- ];
18674
- }
18704
+ ];
18705
+ }
18675
18706
 
18676
- if (null === worldPos && null == snappedWorldPos) { // If neither regular pick or snap pick, return null
18677
- return null;
18678
- }
18707
+ if (null === worldPos && null == snappedWorldPos) { // If neither regular pick or snap pick, return null
18708
+ return null;
18709
+ }
18679
18710
 
18680
- let snappedCanvasPos = null;
18711
+ let snappedCanvasPos = null;
18681
18712
 
18682
- if (null !== snappedWorldPos) {
18683
- snappedCanvasPos = scene.camera.projectWorldPos(snappedWorldPos);
18684
- }
18713
+ if (null !== snappedWorldPos) {
18714
+ snappedCanvasPos = scene.camera.projectWorldPos(snappedWorldPos);
18715
+ }
18685
18716
 
18686
- const snappedEntity = (snappedPickable && snappedPickable.delegatePickedEntity) ? snappedPickable.delegatePickedEntity() : snappedPickable;
18717
+ const snappedEntity = (snappedPickable && snappedPickable.delegatePickedEntity) ? snappedPickable.delegatePickedEntity() : snappedPickable;
18687
18718
 
18688
- return {
18689
- snapType,
18690
- snappedToVertex: snapType === "vertex",
18691
- snappedToEdge: snapType === "edge",
18692
- worldPos,
18693
- worldNormal,
18694
- snappedWorldPos,
18695
- snappedWorldNormal,
18696
- snappedCanvasPos,
18697
- snappedEntity,
18698
- entity: snappedEntity
18719
+ pickResult.reset();
18720
+ pickResult.snappedToEdge = (snapType === "edge");
18721
+ pickResult.snappedToVertex = (snapType === "vertex");
18722
+ pickResult.worldPos = snappedWorldPos;
18723
+ pickResult.worldNormal = snappedWorldNormal;
18724
+ pickResult.entity = snappedEntity;
18725
+ pickResult.canvasPos = canvasPos;
18726
+ pickResult.snappedCanvasPos = snappedCanvasPos || canvasPos;
18727
+
18728
+ return pickResult;
18699
18729
  };
18700
- };
18730
+ })();
18701
18731
 
18702
18732
  function unpackDepth(depthZ) {
18703
18733
  const vec = [depthZ[0] / 256.0, depthZ[1] / 256.0, depthZ[2] / 256.0, depthZ[3] / 256.0];
@@ -29705,6 +29735,9 @@ class Scene extends Component {
29705
29735
  * @param {Number[]} [params.matrix] 4x4 transformation matrix to define the World-space ray origin and direction, as an alternative to ````origin```` and ````direction````.
29706
29736
  * @param {String[]} [params.includeEntities] IDs of {@link Entity}s to restrict picking to. When given, ignores {@link Entity}s whose IDs are not in this list.
29707
29737
  * @param {String[]} [params.excludeEntities] IDs of {@link Entity}s to ignore. When given, will pick *through* these {@link Entity}s, as if they were not there.
29738
+ * @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels
29739
+ * @param {boolean} [params.snapToVertex=true] Whether to snap to vertex.
29740
+ * @param {boolean} [params.snapToEdge=true] Whether to snap to edge.
29708
29741
  * @param {PickResult} [pickResult] Holds the results of the pick attempt. Will use the Scene's singleton PickResult if you don't supply your own.
29709
29742
  * @returns {PickResult} Holds results of the pick attempt, returned when an {@link Entity} is picked, else null. See method comments for description.
29710
29743
  */
@@ -29739,14 +29772,25 @@ class Scene extends Component {
29739
29772
  this._needRecompile = false;
29740
29773
  }
29741
29774
 
29742
- pickResult = this._renderer.pick(params, pickResult);
29775
+ if (params.snapToEdge || params.snapToVertex) {
29776
+ pickResult = this._renderer.snapPick(
29777
+ params.canvasPos,
29778
+ params.snapRadius || 30,
29779
+ params.snapToVertex,
29780
+ params.snapToEdge,
29781
+ pickResult
29782
+ );
29783
+ } else {
29784
+ pickResult = this._renderer.pick(params, pickResult);
29785
+ }
29743
29786
 
29744
29787
  if (pickResult) {
29745
29788
  if (pickResult.entity && pickResult.entity.fire) {
29746
- pickResult.entity.fire("picked", pickResult); // TODO: PerformanceModelNode doesn't fire events
29789
+ pickResult.entity.fire("picked", pickResult); // TODO: SceneModelEntity doesn't fire events
29747
29790
  }
29748
- return pickResult;
29749
29791
  }
29792
+
29793
+ return pickResult;
29750
29794
  }
29751
29795
 
29752
29796
  /**
@@ -29755,8 +29799,13 @@ class Scene extends Component {
29755
29799
  * @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels
29756
29800
  * @param {boolean} [params.snapToVertex=true] Whether to snap to vertex.
29757
29801
  * @param {boolean} [params.snapToEdge=true] Whether to snap to edge.
29802
+ * @deprecated
29758
29803
  */
29759
29804
  snapPick(params) {
29805
+ if (undefined === this._warnSnapPickDeprecated) {
29806
+ this._warnSnapPickDeprecated = true;
29807
+ this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead");
29808
+ }
29760
29809
  return this._renderer.snapPick(
29761
29810
  params.canvasPos,
29762
29811
  params.snapRadius || 30,
@@ -49929,18 +49978,19 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
49929
49978
  this._snapping
49930
49979
  ? "hoverSnapOrSurface"
49931
49980
  : "hoverSurface", event => {
49981
+ const canvasPos = event.snappedCanvasPos || event.canvasPos;
49932
49982
  mouseHovering = true;
49933
49983
  pointerWorldPos.set(event.worldPos);
49934
49984
  pointerCanvasPos.set(event.canvasPos);
49935
49985
  if (this._mouseState === MOUSE_FIRST_CLICK_EXPECTED) {
49936
- this._markerDiv.style.marginLeft = `${event.canvasPos[0] - 5}px`;
49937
- this._markerDiv.style.marginTop = `${event.canvasPos[1] - 5}px`;
49986
+ this._markerDiv.style.marginLeft = `${canvasPos[0] - 5}px`;
49987
+ this._markerDiv.style.marginTop = `${canvasPos[1] - 5}px`;
49938
49988
  this._markerDiv.style.background = "pink";
49939
49989
  if (event.snappedToVertex || event.snappedToEdge) {
49940
49990
  if (this.pointerLens) {
49941
49991
  this.pointerLens.visible = true;
49942
- this.pointerLens.centerPos = event.cursorPos || event.canvasPos;
49943
- this.pointerLens.cursorPos = event.canvasPos;
49992
+ this.pointerLens.canvasPos = event.canvasPos;
49993
+ this.pointerLens.snappedCanvasPos = event.snappedCanvasPos || event.canvasPos;
49944
49994
  this.pointerLens.snapped = true;
49945
49995
  }
49946
49996
  this._markerDiv.style.background = "greenyellow";
@@ -49948,8 +49998,8 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
49948
49998
  } else {
49949
49999
  if (this.pointerLens) {
49950
50000
  this.pointerLens.visible = true;
49951
- this.pointerLens.centerPos = event.cursorPos || event.canvasPos;
49952
- this.pointerLens.cursorPos = event.canvasPos;
50001
+ this.pointerLens.canvasPos = event.canvasPos;
50002
+ this.pointerLens.snappedCanvasPos = event.canvasPos;
49953
50003
  this.pointerLens.snapped = false;
49954
50004
  }
49955
50005
  this._markerDiv.style.background = "pink";
@@ -50031,8 +50081,8 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
50031
50081
  : "hoverOff", event => {
50032
50082
  if (this.pointerLens) {
50033
50083
  this.pointerLens.visible = true;
50034
- this.pointerLens.centerPos = event.cursorPos || event.canvasPos;
50035
- this.pointerLens.cursorPos = event.canvasPos;
50084
+ this.pointerLens.canvasPos = event.canvasPos;
50085
+ this.pointerLens.snappedCanvasPos = event.snappedCanvasPos || event.canvasPos;
50036
50086
  }
50037
50087
  mouseHovering = false;
50038
50088
  this._markerDiv.style.marginLeft = `-100px`;
@@ -87464,13 +87514,13 @@ class PickController {
87464
87514
  const hasHoverSurfaceSubs = this._cameraControl.hasSubs("hoverSurface");
87465
87515
 
87466
87516
  if (this.scheduleSnapOrPick) {
87467
- const snapPickResult = this._scene.snapPick({
87517
+ const snapPickResult = this._scene.pick({
87468
87518
  canvasPos: this.pickCursorPos,
87469
87519
  snapRadius: this._configs.snapRadius,
87470
87520
  snapToVertex: this._configs.snapToVertex,
87471
87521
  snapToEdge: this._configs.snapToEdge,
87472
87522
  });
87473
- if (snapPickResult && snapPickResult.snappedWorldPos) {
87523
+ if (snapPickResult && (snapPickResult.snappedToEdge || snapPickResult.snappedToVertex)) {
87474
87524
  this.snapPickResult = snapPickResult;
87475
87525
  this.snappedOrPicked = true;
87476
87526
  this._needFireEvents++;
@@ -87552,14 +87602,14 @@ class PickController {
87552
87602
 
87553
87603
  fireEvents() {
87554
87604
 
87555
- if (this._needFireEvents == 0) {
87605
+ if (this._needFireEvents === 0) {
87556
87606
  return;
87557
87607
  }
87558
87608
 
87559
87609
  if (this.hoveredSnappedOrSurfaceOff) {
87560
87610
  this._cameraControl.fire("hoverSnapOrSurfaceOff", {
87561
87611
  canvasPos: this.pickCursorPos,
87562
- cursorPos : this.pickCursorPos
87612
+ pointerPos : this.pickCursorPos
87563
87613
  }, true);
87564
87614
  }
87565
87615
 
@@ -87568,9 +87618,9 @@ class PickController {
87568
87618
  const pickResult = new PickResult();
87569
87619
  pickResult.snappedToVertex = this.snapPickResult.snappedToVertex;
87570
87620
  pickResult.snappedToEdge = this.snapPickResult.snappedToEdge;
87571
- pickResult.worldPos = this.snapPickResult.snappedWorldPos;
87572
- pickResult.cursorPos = this.pickCursorPos;
87573
- pickResult.canvasPos = this.snapPickResult.snappedCanvasPos;
87621
+ pickResult.worldPos = this.snapPickResult.worldPos;
87622
+ pickResult.canvasPos = this.pickCursorPos;
87623
+ pickResult.snappedCanvasPos = this.snapPickResult.snappedCanvasPos;
87574
87624
  this._cameraControl.fire("hoverSnapOrSurface", pickResult, true);
87575
87625
  this.snapPickResult = null;
87576
87626
  } else {