@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/package.json
CHANGED
|
@@ -93,8 +93,8 @@ export class PointerLens {
|
|
|
93
93
|
this._lensCanvasContext = this._lensCanvas.getContext('2d');
|
|
94
94
|
this._canvasElement = this.viewer.scene.canvas.canvas;
|
|
95
95
|
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
96
|
+
this._canvasPos = null;
|
|
97
|
+
this._snappedCanvasPos = null;
|
|
98
98
|
this._lensPosToggle = true;
|
|
99
99
|
|
|
100
100
|
this._zoomLevel = cfg.zoomLevel || 2;
|
|
@@ -117,14 +117,14 @@ export class PointerLens {
|
|
|
117
117
|
if (!this._active || !this._visible) {
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
-
if (!this.
|
|
120
|
+
if (!this._canvasPos) {
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
123
|
const lensRect = this._lensContainer.getBoundingClientRect();
|
|
124
124
|
const canvasRect = this._canvasElement.getBoundingClientRect();
|
|
125
125
|
const pointerOnLens =
|
|
126
|
-
this.
|
|
127
|
-
this.
|
|
126
|
+
this._canvasPos[0] < lensRect.right && this._canvasPos[0] > lensRect.left &&
|
|
127
|
+
this._canvasPos[1] < lensRect.bottom && this._canvasPos[1] > lensRect.top;
|
|
128
128
|
this._lensContainer.style.marginLeft = `25px`;
|
|
129
129
|
if (pointerOnLens) {
|
|
130
130
|
if (this._lensPosToggle) {
|
|
@@ -138,8 +138,8 @@ export class PointerLens {
|
|
|
138
138
|
const size = Math.max(this._lensCanvas.width, this._lensCanvas.height) / this._zoomLevel;
|
|
139
139
|
this._lensCanvasContext.drawImage(
|
|
140
140
|
this._canvasElement, // source canvas
|
|
141
|
-
this.
|
|
142
|
-
this.
|
|
141
|
+
this._canvasPos[0] - size / 2, // source x (zoom center)
|
|
142
|
+
this._canvasPos[1] - size / 2, // source y (zoom center)
|
|
143
143
|
size, // source width
|
|
144
144
|
size, // source height
|
|
145
145
|
0, // destination x
|
|
@@ -153,9 +153,9 @@ export class PointerLens {
|
|
|
153
153
|
(lensRect.top + lensRect.bottom) / 2
|
|
154
154
|
];
|
|
155
155
|
|
|
156
|
-
if (this.
|
|
157
|
-
const deltaX = this.
|
|
158
|
-
const deltaY = this.
|
|
156
|
+
if (this._snappedCanvasPos) {
|
|
157
|
+
const deltaX = this._snappedCanvasPos[0] - this._canvasPos[0];
|
|
158
|
+
const deltaY = this._snappedCanvasPos[1] - this._canvasPos[1];
|
|
159
159
|
|
|
160
160
|
this._lensCursorDiv.style.marginLeft = `${centerLensCanvas[0] + deltaX * this._zoomLevel - 10}px`;
|
|
161
161
|
this._lensCursorDiv.style.marginTop = `${centerLensCanvas[1] + deltaY * this._zoomLevel - 10}px`;
|
|
@@ -191,10 +191,10 @@ export class PointerLens {
|
|
|
191
191
|
|
|
192
192
|
/**
|
|
193
193
|
* Sets the canvas central position of the lens.
|
|
194
|
-
* @param
|
|
194
|
+
* @param canvasPos
|
|
195
195
|
*/
|
|
196
|
-
set
|
|
197
|
-
this.
|
|
196
|
+
set canvasPos(canvasPos) {
|
|
197
|
+
this._canvasPos = canvasPos;
|
|
198
198
|
this.update();
|
|
199
199
|
}
|
|
200
200
|
|
|
@@ -202,25 +202,25 @@ export class PointerLens {
|
|
|
202
202
|
* Gets the canvas central position of the lens.
|
|
203
203
|
* @returns {Number[]}
|
|
204
204
|
*/
|
|
205
|
-
get
|
|
206
|
-
return this.
|
|
205
|
+
get canvasPos() {
|
|
206
|
+
return this._canvasPos;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
210
|
* Sets the canvas coordinates of the pointer.
|
|
211
|
-
* @param
|
|
211
|
+
* @param snappedCanvasPos
|
|
212
212
|
*/
|
|
213
|
-
set
|
|
214
|
-
this.
|
|
213
|
+
set snappedCanvasPos(snappedCanvasPos) {
|
|
214
|
+
this._snappedCanvasPos = snappedCanvasPos;
|
|
215
215
|
this.update();
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
|
-
* Gets the canvas coordinates of the pointer.
|
|
219
|
+
* Gets the canvas coordinates of the snapped pointer.
|
|
220
220
|
* @returns {Number[]}
|
|
221
221
|
*/
|
|
222
|
-
get
|
|
223
|
-
return this.
|
|
222
|
+
get snappedCanvasPos() {
|
|
223
|
+
return this._snappedCanvasPos;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
/**
|
|
@@ -177,8 +177,8 @@ export class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
|
|
|
177
177
|
if (event.snappedToVertex || event.snappedToEdge) {
|
|
178
178
|
if (pointerLens) {
|
|
179
179
|
pointerLens.visible = true;
|
|
180
|
-
pointerLens.
|
|
181
|
-
pointerLens.
|
|
180
|
+
pointerLens.canvasPos = event.canvasPos;
|
|
181
|
+
pointerLens.snappedCanvasPos = event.snappedCanvasPos || event.canvasPos;
|
|
182
182
|
pointerLens.snapped = true;
|
|
183
183
|
}
|
|
184
184
|
this.markerDiv.style.background = "greenyellow";
|
|
@@ -186,21 +186,22 @@ export class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
|
|
|
186
186
|
} else {
|
|
187
187
|
if (pointerLens) {
|
|
188
188
|
pointerLens.visible = true;
|
|
189
|
-
pointerLens.
|
|
190
|
-
pointerLens.
|
|
189
|
+
pointerLens.canvasPos = event.canvasPos;
|
|
190
|
+
pointerLens.snappedCanvasPos = event.canvasPos;
|
|
191
191
|
pointerLens.snapped = false;
|
|
192
192
|
}
|
|
193
193
|
this.markerDiv.style.background = "pink";
|
|
194
194
|
this.markerDiv.style.border = "2px solid red";
|
|
195
195
|
}
|
|
196
|
+
const canvasPos = event.snappedCanvasPos || event.canvasPos;
|
|
196
197
|
mouseHovering = true;
|
|
197
198
|
mouseHoverEntity = event.entity;
|
|
198
199
|
mouseWorldPos.set(event.worldPos);
|
|
199
|
-
mouseHoverCanvasPos.set(
|
|
200
|
+
mouseHoverCanvasPos.set(canvasPos);
|
|
200
201
|
switch (this._mouseState) {
|
|
201
202
|
case MOUSE_FINDING_ORIGIN:
|
|
202
|
-
this.markerDiv.style.marginLeft = `${
|
|
203
|
-
this.markerDiv.style.marginTop = `${
|
|
203
|
+
this.markerDiv.style.marginLeft = `${canvasPos[0] - 5}px`;
|
|
204
|
+
this.markerDiv.style.marginTop = `${canvasPos[1] - 5}px`;
|
|
204
205
|
break;
|
|
205
206
|
case MOUSE_FINDING_CORNER:
|
|
206
207
|
if (this._currentAngleMeasurement) {
|
|
@@ -316,8 +317,8 @@ export class AngleMeasurementsMouseControl extends AngleMeasurementsControl {
|
|
|
316
317
|
mouseHovering = false;
|
|
317
318
|
if (pointerLens) {
|
|
318
319
|
pointerLens.visible = true;
|
|
319
|
-
pointerLens.
|
|
320
|
-
pointerLens.
|
|
320
|
+
pointerLens.pointerPos = event.canvasPos;
|
|
321
|
+
pointerLens.snappedCanvasPos = event.snappedCanvasPos || event.canvasPos;
|
|
321
322
|
pointerLens.snapped = false;
|
|
322
323
|
}
|
|
323
324
|
this.markerDiv.style.marginLeft = `-100px`;
|
|
@@ -181,18 +181,19 @@ export class DistanceMeasurementsMouseControl extends DistanceMeasurementsContro
|
|
|
181
181
|
this._snapping
|
|
182
182
|
? "hoverSnapOrSurface"
|
|
183
183
|
: "hoverSurface", event => {
|
|
184
|
+
const canvasPos = event.snappedCanvasPos || event.canvasPos;
|
|
184
185
|
mouseHovering = true;
|
|
185
186
|
pointerWorldPos.set(event.worldPos);
|
|
186
187
|
pointerCanvasPos.set(event.canvasPos);
|
|
187
188
|
if (this._mouseState === MOUSE_FIRST_CLICK_EXPECTED) {
|
|
188
|
-
this._markerDiv.style.marginLeft = `${
|
|
189
|
-
this._markerDiv.style.marginTop = `${
|
|
189
|
+
this._markerDiv.style.marginLeft = `${canvasPos[0] - 5}px`;
|
|
190
|
+
this._markerDiv.style.marginTop = `${canvasPos[1] - 5}px`;
|
|
190
191
|
this._markerDiv.style.background = "pink";
|
|
191
192
|
if (event.snappedToVertex || event.snappedToEdge) {
|
|
192
193
|
if (this.pointerLens) {
|
|
193
194
|
this.pointerLens.visible = true;
|
|
194
|
-
this.pointerLens.
|
|
195
|
-
this.pointerLens.
|
|
195
|
+
this.pointerLens.canvasPos = event.canvasPos;
|
|
196
|
+
this.pointerLens.snappedCanvasPos = event.snappedCanvasPos || event.canvasPos;
|
|
196
197
|
this.pointerLens.snapped = true;
|
|
197
198
|
}
|
|
198
199
|
this._markerDiv.style.background = "greenyellow";
|
|
@@ -200,8 +201,8 @@ export class DistanceMeasurementsMouseControl extends DistanceMeasurementsContro
|
|
|
200
201
|
} else {
|
|
201
202
|
if (this.pointerLens) {
|
|
202
203
|
this.pointerLens.visible = true;
|
|
203
|
-
this.pointerLens.
|
|
204
|
-
this.pointerLens.
|
|
204
|
+
this.pointerLens.canvasPos = event.canvasPos;
|
|
205
|
+
this.pointerLens.snappedCanvasPos = event.canvasPos;
|
|
205
206
|
this.pointerLens.snapped = false;
|
|
206
207
|
}
|
|
207
208
|
this._markerDiv.style.background = "pink";
|
|
@@ -283,8 +284,8 @@ export class DistanceMeasurementsMouseControl extends DistanceMeasurementsContro
|
|
|
283
284
|
: "hoverOff", event => {
|
|
284
285
|
if (this.pointerLens) {
|
|
285
286
|
this.pointerLens.visible = true;
|
|
286
|
-
this.pointerLens.
|
|
287
|
-
this.pointerLens.
|
|
287
|
+
this.pointerLens.canvasPos = event.canvasPos;
|
|
288
|
+
this.pointerLens.snappedCanvasPos = event.snappedCanvasPos || event.canvasPos;
|
|
288
289
|
}
|
|
289
290
|
mouseHovering = false;
|
|
290
291
|
this._markerDiv.style.marginLeft = `-100px`;
|
|
@@ -69,6 +69,8 @@ class PickController {
|
|
|
69
69
|
|
|
70
70
|
this._lastPickedEntityId = null;
|
|
71
71
|
|
|
72
|
+
this._lastHash = null;
|
|
73
|
+
|
|
72
74
|
this._needFireEvents = 0;
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -76,6 +78,7 @@ class PickController {
|
|
|
76
78
|
* Immediately attempts a pick, if scheduled.
|
|
77
79
|
*/
|
|
78
80
|
update() {
|
|
81
|
+
|
|
79
82
|
if (!this._configs.pointerEnabled) {
|
|
80
83
|
return;
|
|
81
84
|
}
|
|
@@ -84,6 +87,11 @@ class PickController {
|
|
|
84
87
|
return;
|
|
85
88
|
}
|
|
86
89
|
|
|
90
|
+
const hash = `${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;
|
|
91
|
+
if (this._lastHash === hash) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
87
95
|
this.picked = false;
|
|
88
96
|
this.pickedSurface = false;
|
|
89
97
|
this.snappedOrPicked = false;
|
|
@@ -92,13 +100,13 @@ class PickController {
|
|
|
92
100
|
const hasHoverSurfaceSubs = this._cameraControl.hasSubs("hoverSurface");
|
|
93
101
|
|
|
94
102
|
if (this.scheduleSnapOrPick) {
|
|
95
|
-
const snapPickResult = this._scene.
|
|
103
|
+
const snapPickResult = this._scene.pick({
|
|
96
104
|
canvasPos: this.pickCursorPos,
|
|
97
105
|
snapRadius: this._configs.snapRadius,
|
|
98
106
|
snapToVertex: this._configs.snapToVertex,
|
|
99
107
|
snapToEdge: this._configs.snapToEdge,
|
|
100
108
|
});
|
|
101
|
-
if (snapPickResult && snapPickResult.
|
|
109
|
+
if (snapPickResult && (snapPickResult.snappedToEdge || snapPickResult.snappedToVertex)) {
|
|
102
110
|
this.snapPickResult = snapPickResult;
|
|
103
111
|
this.snappedOrPicked = true;
|
|
104
112
|
this._needFireEvents++;
|
|
@@ -180,14 +188,14 @@ class PickController {
|
|
|
180
188
|
|
|
181
189
|
fireEvents() {
|
|
182
190
|
|
|
183
|
-
if (this._needFireEvents
|
|
191
|
+
if (this._needFireEvents === 0) {
|
|
184
192
|
return;
|
|
185
193
|
}
|
|
186
194
|
|
|
187
195
|
if (this.hoveredSnappedOrSurfaceOff) {
|
|
188
196
|
this._cameraControl.fire("hoverSnapOrSurfaceOff", {
|
|
189
197
|
canvasPos: this.pickCursorPos,
|
|
190
|
-
|
|
198
|
+
pointerPos : this.pickCursorPos
|
|
191
199
|
}, true);
|
|
192
200
|
}
|
|
193
201
|
|
|
@@ -196,9 +204,9 @@ class PickController {
|
|
|
196
204
|
const pickResult = new PickResult();
|
|
197
205
|
pickResult.snappedToVertex = this.snapPickResult.snappedToVertex;
|
|
198
206
|
pickResult.snappedToEdge = this.snapPickResult.snappedToEdge;
|
|
199
|
-
pickResult.worldPos = this.snapPickResult.
|
|
200
|
-
pickResult.
|
|
201
|
-
pickResult.
|
|
207
|
+
pickResult.worldPos = this.snapPickResult.worldPos;
|
|
208
|
+
pickResult.canvasPos = this.pickCursorPos
|
|
209
|
+
pickResult.snappedCanvasPos = this.snapPickResult.snappedCanvasPos;
|
|
202
210
|
this._cameraControl.fire("hoverSnapOrSurface", pickResult, true);
|
|
203
211
|
this.snapPickResult = null;
|
|
204
212
|
} else {
|
|
@@ -2154,6 +2154,9 @@ class Scene extends Component {
|
|
|
2154
2154
|
* @param {Number[]} [params.matrix] 4x4 transformation matrix to define the World-space ray origin and direction, as an alternative to ````origin```` and ````direction````.
|
|
2155
2155
|
* @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.
|
|
2156
2156
|
* @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.
|
|
2157
|
+
* @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels
|
|
2158
|
+
* @param {boolean} [params.snapToVertex=true] Whether to snap to vertex.
|
|
2159
|
+
* @param {boolean} [params.snapToEdge=true] Whether to snap to edge.
|
|
2157
2160
|
* @param {PickResult} [pickResult] Holds the results of the pick attempt. Will use the Scene's singleton PickResult if you don't supply your own.
|
|
2158
2161
|
* @returns {PickResult} Holds results of the pick attempt, returned when an {@link Entity} is picked, else null. See method comments for description.
|
|
2159
2162
|
*/
|
|
@@ -2188,14 +2191,25 @@ class Scene extends Component {
|
|
|
2188
2191
|
this._needRecompile = false;
|
|
2189
2192
|
}
|
|
2190
2193
|
|
|
2191
|
-
|
|
2194
|
+
if (params.snapToEdge || params.snapToVertex) {
|
|
2195
|
+
pickResult = this._renderer.snapPick(
|
|
2196
|
+
params.canvasPos,
|
|
2197
|
+
params.snapRadius || 30,
|
|
2198
|
+
params.snapToVertex,
|
|
2199
|
+
params.snapToEdge,
|
|
2200
|
+
pickResult
|
|
2201
|
+
);
|
|
2202
|
+
} else {
|
|
2203
|
+
pickResult = this._renderer.pick(params, pickResult);
|
|
2204
|
+
}
|
|
2192
2205
|
|
|
2193
2206
|
if (pickResult) {
|
|
2194
2207
|
if (pickResult.entity && pickResult.entity.fire) {
|
|
2195
|
-
pickResult.entity.fire("picked", pickResult); // TODO:
|
|
2208
|
+
pickResult.entity.fire("picked", pickResult); // TODO: SceneModelEntity doesn't fire events
|
|
2196
2209
|
}
|
|
2197
|
-
return pickResult;
|
|
2198
2210
|
}
|
|
2211
|
+
|
|
2212
|
+
return pickResult;
|
|
2199
2213
|
}
|
|
2200
2214
|
|
|
2201
2215
|
/**
|
|
@@ -2204,8 +2218,13 @@ class Scene extends Component {
|
|
|
2204
2218
|
* @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels
|
|
2205
2219
|
* @param {boolean} [params.snapToVertex=true] Whether to snap to vertex.
|
|
2206
2220
|
* @param {boolean} [params.snapToEdge=true] Whether to snap to edge.
|
|
2221
|
+
* @deprecated
|
|
2207
2222
|
*/
|
|
2208
2223
|
snapPick(params) {
|
|
2224
|
+
if (undefined === this._warnSnapPickDeprecated) {
|
|
2225
|
+
this._warnSnapPickDeprecated = true;
|
|
2226
|
+
this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead")
|
|
2227
|
+
}
|
|
2209
2228
|
return this._renderer.snapPick(
|
|
2210
2229
|
params.canvasPos,
|
|
2211
2230
|
params.snapRadius || 30,
|
|
@@ -60,13 +60,14 @@ class PickResult {
|
|
|
60
60
|
*/
|
|
61
61
|
this.snappedToVertex = false;
|
|
62
62
|
|
|
63
|
-
this._canvasPos = new Int16Array([0, 0]);
|
|
64
63
|
this._origin = new Float64Array([0, 0, 0]);
|
|
65
64
|
this._direction = new Float64Array([0, 0, 0]);
|
|
66
65
|
this._indices = new Int32Array(3);
|
|
67
66
|
this._localPos = new Float64Array([0, 0, 0]);
|
|
68
67
|
this._worldPos = new Float64Array([0, 0, 0]);
|
|
69
68
|
this._viewPos = new Float64Array([0, 0, 0]);
|
|
69
|
+
this._canvasPos = new Int16Array([0, 0]);
|
|
70
|
+
this._snappedCanvasPos = new Int16Array([0, 0]);
|
|
70
71
|
this._bary = new Float64Array([0, 0, 0]);
|
|
71
72
|
this._worldNormal = new Float64Array([0, 0, 0]);
|
|
72
73
|
this._uv = new Float64Array([0, 0]);
|
|
@@ -75,7 +76,7 @@ class PickResult {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
|
-
* Canvas coordinates
|
|
79
|
+
* Canvas pick coordinates.
|
|
79
80
|
* @property canvasPos
|
|
80
81
|
* @type {Number[]}
|
|
81
82
|
*/
|
|
@@ -193,6 +194,29 @@ class PickResult {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Canvas cursor coordinates, snapped when snap picking, otherwise same as {@link PickResult#pointerPos}.
|
|
199
|
+
* @property snappedCanvasPos
|
|
200
|
+
* @type {Number[]}
|
|
201
|
+
*/
|
|
202
|
+
get snappedCanvasPos() {
|
|
203
|
+
return this._gotSnappedCanvasPos ? this._snappedCanvasPos : null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @private
|
|
208
|
+
* @param value
|
|
209
|
+
*/
|
|
210
|
+
set snappedCanvasPos(value) {
|
|
211
|
+
if (value) {
|
|
212
|
+
this._snappedCanvasPos[0] = value[0];
|
|
213
|
+
this._snappedCanvasPos[1] = value[1];
|
|
214
|
+
this._gotSnappedCanvasPos = true;
|
|
215
|
+
} else {
|
|
216
|
+
this._gotSnappedCanvasPos = false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
196
220
|
/**
|
|
197
221
|
* Picked World-space point.
|
|
198
222
|
* @property worldPos
|
|
@@ -321,6 +345,7 @@ class PickResult {
|
|
|
321
345
|
this.primitive = null;
|
|
322
346
|
this.pickSurfacePrecision = false;
|
|
323
347
|
this._gotCanvasPos = false;
|
|
348
|
+
this._gotSnappedCanvasPos = false;
|
|
324
349
|
this._gotOrigin = false;
|
|
325
350
|
this._gotDirection = false;
|
|
326
351
|
this._gotIndices = false;
|