@xeokit/xeokit-sdk 2.4.2-beta-15 → 2.4.2-beta-20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/xeokit-sdk.cjs.js +308 -250
- package/dist/xeokit-sdk.es.js +308 -250
- package/dist/xeokit-sdk.es5.js +41 -30
- package/dist/xeokit-sdk.min.cjs.js +3 -3
- package/dist/xeokit-sdk.min.es.js +2 -2
- package/dist/xeokit-sdk.min.es5.js +2 -2
- package/package.json +1 -1
- package/src/extras/PointerLens/PointerLens.js +21 -21
- package/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsMouseControl.js +10 -9
- package/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsMouseControl.js +9 -8
- package/src/viewer/scene/CameraControl/lib/controllers/PickController.js +15 -7
- package/src/viewer/scene/scene/Scene.js +22 -3
- package/src/viewer/scene/webgl/PickResult.js +27 -2
- package/src/viewer/scene/webgl/Renderer.js +212 -207
package/dist/xeokit-sdk.cjs.js
CHANGED
|
@@ -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.
|
|
1049
|
-
this.
|
|
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.
|
|
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.
|
|
1079
|
-
this.
|
|
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.
|
|
1094
|
-
this.
|
|
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.
|
|
1109
|
-
const deltaX = this.
|
|
1110
|
-
const deltaY = this.
|
|
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
|
|
1146
|
+
* @param canvasPos
|
|
1147
1147
|
*/
|
|
1148
|
-
set
|
|
1149
|
-
this.
|
|
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
|
|
1158
|
-
return this.
|
|
1157
|
+
get canvasPos() {
|
|
1158
|
+
return this._canvasPos;
|
|
1159
1159
|
}
|
|
1160
1160
|
|
|
1161
1161
|
/**
|
|
1162
1162
|
* Sets the canvas coordinates of the pointer.
|
|
1163
|
-
* @param
|
|
1163
|
+
* @param snappedCanvasPos
|
|
1164
1164
|
*/
|
|
1165
|
-
set
|
|
1166
|
-
this.
|
|
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
|
|
1175
|
-
return this.
|
|
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.
|
|
12017
|
-
pointerLens.
|
|
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.
|
|
12026
|
-
pointerLens.
|
|
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(
|
|
12036
|
+
mouseHoverCanvasPos.set(canvasPos);
|
|
12036
12037
|
switch (this._mouseState) {
|
|
12037
12038
|
case MOUSE_FINDING_ORIGIN:
|
|
12038
|
-
this.markerDiv.style.marginLeft = `${
|
|
12039
|
-
this.markerDiv.style.marginTop = `${
|
|
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.
|
|
12156
|
-
pointerLens.
|
|
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
|
|
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 {
|
|
18479
|
+
* @param pickResult
|
|
18480
|
+
* @returns {PickResult}
|
|
18455
18481
|
*/
|
|
18456
|
-
this.snapPick = function (
|
|
18482
|
+
this.snapPick = (function () {
|
|
18457
18483
|
|
|
18458
|
-
|
|
18459
|
-
return this.pick({canvasPos, pickSurface: true});
|
|
18460
|
-
}
|
|
18484
|
+
const _pickResult = new PickResult();
|
|
18461
18485
|
|
|
18462
|
-
|
|
18486
|
+
return function (canvasPos, snapRadiusInPixels, snapToVertex, snapToEdge, pickResult = _pickResult) {
|
|
18463
18487
|
|
|
18464
|
-
|
|
18465
|
-
|
|
18466
|
-
|
|
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
|
-
|
|
18479
|
-
getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth),
|
|
18480
|
-
getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight),
|
|
18481
|
-
];
|
|
18492
|
+
const resolutionScale = scene.canvas.resolutionScale;
|
|
18482
18493
|
|
|
18483
|
-
|
|
18484
|
-
|
|
18485
|
-
|
|
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
|
-
|
|
18500
|
+
snapRadiusInPixels = snapRadiusInPixels || 30;
|
|
18489
18501
|
|
|
18490
|
-
|
|
18491
|
-
|
|
18492
|
-
|
|
18493
|
-
|
|
18494
|
-
|
|
18495
|
-
|
|
18496
|
-
|
|
18497
|
-
|
|
18498
|
-
|
|
18499
|
-
|
|
18500
|
-
|
|
18501
|
-
|
|
18502
|
+
const vertexPickBuffer = renderBufferManager.getRenderBuffer("uniquePickColors-aabs", {
|
|
18503
|
+
depthTexture: true,
|
|
18504
|
+
size: [
|
|
18505
|
+
2 * snapRadiusInPixels + 1,
|
|
18506
|
+
2 * snapRadiusInPixels + 1,
|
|
18507
|
+
]
|
|
18508
|
+
});
|
|
18509
|
+
|
|
18510
|
+
frameCtx.snapVectorA = [
|
|
18511
|
+
getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth),
|
|
18512
|
+
getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight),
|
|
18513
|
+
];
|
|
18502
18514
|
|
|
18503
|
-
|
|
18504
|
-
|
|
18505
|
-
|
|
18515
|
+
frameCtx.snapInvVectorAB = [
|
|
18516
|
+
gl.drawingBufferWidth / (2 * snapRadiusInPixels),
|
|
18517
|
+
gl.drawingBufferHeight / (2 * snapRadiusInPixels),
|
|
18518
|
+
];
|
|
18506
18519
|
|
|
18507
|
-
|
|
18508
|
-
const pickProjMatrix = scene.camera.projMatrix;
|
|
18520
|
+
// Bind and clear the snap render target
|
|
18509
18521
|
|
|
18510
|
-
|
|
18511
|
-
|
|
18512
|
-
|
|
18513
|
-
|
|
18514
|
-
|
|
18515
|
-
|
|
18516
|
-
|
|
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
|
-
|
|
18523
|
-
|
|
18524
|
-
|
|
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
|
-
|
|
18527
|
-
|
|
18528
|
-
|
|
18558
|
+
// b) snap-pick
|
|
18559
|
+
const layerParamsSnap = [];
|
|
18560
|
+
frameCtx.snapPickLayerParams = layerParamsSnap;
|
|
18529
18561
|
|
|
18530
|
-
|
|
18531
|
-
|
|
18562
|
+
gl.depthMask(false);
|
|
18563
|
+
gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
|
|
18532
18564
|
|
|
18533
|
-
|
|
18534
|
-
|
|
18535
|
-
|
|
18565
|
+
if (snapToVertex && snapToEdge) {
|
|
18566
|
+
frameCtx.snapMode = "edge";
|
|
18567
|
+
snapPickDrawSnapDepths(frameCtx);
|
|
18536
18568
|
|
|
18537
|
-
|
|
18538
|
-
|
|
18569
|
+
frameCtx.snapMode = "vertex";
|
|
18570
|
+
frameCtx.snapPickLayerNumber++;
|
|
18539
18571
|
|
|
18540
|
-
|
|
18541
|
-
|
|
18542
|
-
|
|
18572
|
+
snapPickDrawSnapDepths(frameCtx);
|
|
18573
|
+
} else {
|
|
18574
|
+
frameCtx.snapMode = snapToVertex ? "vertex" : "edge";
|
|
18543
18575
|
|
|
18544
|
-
|
|
18545
|
-
|
|
18576
|
+
snapPickDrawSnapDepths(frameCtx);
|
|
18577
|
+
}
|
|
18546
18578
|
|
|
18547
|
-
|
|
18579
|
+
gl.depthMask(true);
|
|
18548
18580
|
|
|
18549
|
-
|
|
18581
|
+
// Read and decode the snapped coordinates
|
|
18550
18582
|
|
|
18551
|
-
|
|
18552
|
-
|
|
18553
|
-
|
|
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
|
-
|
|
18587
|
+
vertexPickBuffer.unbind();
|
|
18556
18588
|
|
|
18557
|
-
|
|
18589
|
+
// result 1) regular hi-precision world position
|
|
18558
18590
|
|
|
18559
|
-
|
|
18560
|
-
let worldNormal = null;
|
|
18591
|
+
let worldPos = null;
|
|
18561
18592
|
|
|
18562
|
-
|
|
18563
|
-
|
|
18564
|
-
|
|
18565
|
-
|
|
18566
|
-
|
|
18567
|
-
|
|
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
|
-
|
|
18570
|
-
|
|
18571
|
-
|
|
18572
|
-
|
|
18573
|
-
|
|
18574
|
-
|
|
18575
|
-
|
|
18576
|
-
|
|
18577
|
-
|
|
18578
|
-
|
|
18579
|
-
|
|
18580
|
-
|
|
18581
|
-
|
|
18582
|
-
|
|
18583
|
-
|
|
18584
|
-
|
|
18585
|
-
|
|
18586
|
-
|
|
18587
|
-
|
|
18588
|
-
|
|
18589
|
-
|
|
18590
|
-
|
|
18591
|
-
|
|
18592
|
-
|
|
18593
|
-
|
|
18594
|
-
|
|
18595
|
-
|
|
18596
|
-
|
|
18597
|
-
|
|
18598
|
-
|
|
18599
|
-
|
|
18600
|
-
|
|
18601
|
-
|
|
18602
|
-
|
|
18603
|
-
|
|
18604
|
-
|
|
18605
|
-
|
|
18606
|
-
|
|
18607
|
-
|
|
18608
|
-
|
|
18609
|
-
|
|
18610
|
-
|
|
18611
|
-
|
|
18612
|
-
|
|
18613
|
-
|
|
18614
|
-
|
|
18615
|
-
|
|
18616
|
-
|
|
18617
|
-
|
|
18618
|
-
|
|
18619
|
-
|
|
18620
|
-
|
|
18621
|
-
|
|
18622
|
-
|
|
18623
|
-
|
|
18624
|
-
|
|
18625
|
-
|
|
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
|
-
|
|
18632
|
-
|
|
18633
|
-
|
|
18634
|
-
|
|
18662
|
+
let snappedWorldPos = null;
|
|
18663
|
+
let snappedWorldNormal = null;
|
|
18664
|
+
let snappedPickable = null;
|
|
18665
|
+
let snapType = null;
|
|
18635
18666
|
|
|
18636
|
-
|
|
18637
|
-
|
|
18638
|
-
|
|
18639
|
-
|
|
18640
|
-
|
|
18641
|
-
|
|
18642
|
-
|
|
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
|
-
|
|
18647
|
-
|
|
18648
|
-
|
|
18649
|
-
|
|
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
|
-
|
|
18682
|
+
const pickedLayerParmas = layerParamsSnap[snapPick[3]];
|
|
18652
18683
|
|
|
18653
|
-
|
|
18654
|
-
|
|
18684
|
+
const origin = pickedLayerParmas.origin;
|
|
18685
|
+
const scale = pickedLayerParmas.coordinateScale;
|
|
18655
18686
|
|
|
18656
|
-
|
|
18657
|
-
|
|
18658
|
-
|
|
18659
|
-
|
|
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
|
-
|
|
18663
|
-
|
|
18664
|
-
|
|
18665
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18677
|
-
|
|
18678
|
-
|
|
18707
|
+
if (null === worldPos && null == snappedWorldPos) { // If neither regular pick or snap pick, return null
|
|
18708
|
+
return null;
|
|
18709
|
+
}
|
|
18679
18710
|
|
|
18680
|
-
|
|
18711
|
+
let snappedCanvasPos = null;
|
|
18681
18712
|
|
|
18682
|
-
|
|
18683
|
-
|
|
18684
|
-
|
|
18713
|
+
if (null !== snappedWorldPos) {
|
|
18714
|
+
snappedCanvasPos = scene.camera.projectWorldPos(snappedWorldPos);
|
|
18715
|
+
}
|
|
18685
18716
|
|
|
18686
|
-
|
|
18717
|
+
const snappedEntity = (snappedPickable && snappedPickable.delegatePickedEntity) ? snappedPickable.delegatePickedEntity() : snappedPickable;
|
|
18687
18718
|
|
|
18688
|
-
|
|
18689
|
-
snapType
|
|
18690
|
-
snappedToVertex
|
|
18691
|
-
|
|
18692
|
-
|
|
18693
|
-
|
|
18694
|
-
|
|
18695
|
-
|
|
18696
|
-
|
|
18697
|
-
|
|
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
|
-
|
|
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:
|
|
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 = `${
|
|
49937
|
-
this._markerDiv.style.marginTop = `${
|
|
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.
|
|
49943
|
-
this.pointerLens.
|
|
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.
|
|
49952
|
-
this.pointerLens.
|
|
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.
|
|
50035
|
-
this.pointerLens.
|
|
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`;
|
|
@@ -87441,6 +87491,8 @@ class PickController {
|
|
|
87441
87491
|
|
|
87442
87492
|
this._lastPickedEntityId = null;
|
|
87443
87493
|
|
|
87494
|
+
this._lastHash = null;
|
|
87495
|
+
|
|
87444
87496
|
this._needFireEvents = 0;
|
|
87445
87497
|
}
|
|
87446
87498
|
|
|
@@ -87448,6 +87500,7 @@ class PickController {
|
|
|
87448
87500
|
* Immediately attempts a pick, if scheduled.
|
|
87449
87501
|
*/
|
|
87450
87502
|
update() {
|
|
87503
|
+
|
|
87451
87504
|
if (!this._configs.pointerEnabled) {
|
|
87452
87505
|
return;
|
|
87453
87506
|
}
|
|
@@ -87456,6 +87509,11 @@ class PickController {
|
|
|
87456
87509
|
return;
|
|
87457
87510
|
}
|
|
87458
87511
|
|
|
87512
|
+
const hash = `${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;
|
|
87513
|
+
if (this._lastHash === hash) {
|
|
87514
|
+
return;
|
|
87515
|
+
}
|
|
87516
|
+
|
|
87459
87517
|
this.picked = false;
|
|
87460
87518
|
this.pickedSurface = false;
|
|
87461
87519
|
this.snappedOrPicked = false;
|
|
@@ -87464,13 +87522,13 @@ class PickController {
|
|
|
87464
87522
|
const hasHoverSurfaceSubs = this._cameraControl.hasSubs("hoverSurface");
|
|
87465
87523
|
|
|
87466
87524
|
if (this.scheduleSnapOrPick) {
|
|
87467
|
-
const snapPickResult = this._scene.
|
|
87525
|
+
const snapPickResult = this._scene.pick({
|
|
87468
87526
|
canvasPos: this.pickCursorPos,
|
|
87469
87527
|
snapRadius: this._configs.snapRadius,
|
|
87470
87528
|
snapToVertex: this._configs.snapToVertex,
|
|
87471
87529
|
snapToEdge: this._configs.snapToEdge,
|
|
87472
87530
|
});
|
|
87473
|
-
if (snapPickResult && snapPickResult.
|
|
87531
|
+
if (snapPickResult && (snapPickResult.snappedToEdge || snapPickResult.snappedToVertex)) {
|
|
87474
87532
|
this.snapPickResult = snapPickResult;
|
|
87475
87533
|
this.snappedOrPicked = true;
|
|
87476
87534
|
this._needFireEvents++;
|
|
@@ -87552,14 +87610,14 @@ class PickController {
|
|
|
87552
87610
|
|
|
87553
87611
|
fireEvents() {
|
|
87554
87612
|
|
|
87555
|
-
if (this._needFireEvents
|
|
87613
|
+
if (this._needFireEvents === 0) {
|
|
87556
87614
|
return;
|
|
87557
87615
|
}
|
|
87558
87616
|
|
|
87559
87617
|
if (this.hoveredSnappedOrSurfaceOff) {
|
|
87560
87618
|
this._cameraControl.fire("hoverSnapOrSurfaceOff", {
|
|
87561
87619
|
canvasPos: this.pickCursorPos,
|
|
87562
|
-
|
|
87620
|
+
pointerPos : this.pickCursorPos
|
|
87563
87621
|
}, true);
|
|
87564
87622
|
}
|
|
87565
87623
|
|
|
@@ -87568,9 +87626,9 @@ class PickController {
|
|
|
87568
87626
|
const pickResult = new PickResult();
|
|
87569
87627
|
pickResult.snappedToVertex = this.snapPickResult.snappedToVertex;
|
|
87570
87628
|
pickResult.snappedToEdge = this.snapPickResult.snappedToEdge;
|
|
87571
|
-
pickResult.worldPos = this.snapPickResult.
|
|
87572
|
-
pickResult.
|
|
87573
|
-
pickResult.
|
|
87629
|
+
pickResult.worldPos = this.snapPickResult.worldPos;
|
|
87630
|
+
pickResult.canvasPos = this.pickCursorPos;
|
|
87631
|
+
pickResult.snappedCanvasPos = this.snapPickResult.snappedCanvasPos;
|
|
87574
87632
|
this._cameraControl.fire("hoverSnapOrSurface", pickResult, true);
|
|
87575
87633
|
this.snapPickResult = null;
|
|
87576
87634
|
} else {
|