@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeokit/xeokit-sdk",
3
- "version": "2.4.2-beta-15",
3
+ "version": "2.4.2-beta-19",
4
4
  "description": "Web Programming Toolkit for 3D/2D BIM and AEC Graphics",
5
5
  "module": "./dist/xeokit-sdk.es.js",
6
6
  "main": "./dist/xeokit-sdk.cjs.js",
@@ -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._centerPos = null;
97
- this._cursorPos = null;
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._centerPos) {
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._centerPos[0] < lensRect.right && this._centerPos[0] > lensRect.left &&
127
- this._centerPos[1] < lensRect.bottom && this._centerPos[1] > lensRect.top;
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._centerPos[0] - size / 2, // source x (zoom center)
142
- this._centerPos[1] - size / 2, // source y (zoom center)
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._cursorPos) {
157
- const deltaX = this._cursorPos[0] - this._centerPos[0];
158
- const deltaY = this._cursorPos[1] - this._centerPos[1];
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 centerPos
194
+ * @param canvasPos
195
195
  */
196
- set centerPos(centerPos) {
197
- this._centerPos = centerPos;
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 centerPos() {
206
- return this._centerPos;
205
+ get canvasPos() {
206
+ return this._canvasPos;
207
207
  }
208
208
 
209
209
  /**
210
210
  * Sets the canvas coordinates of the pointer.
211
- * @param cursorPos
211
+ * @param snappedCanvasPos
212
212
  */
213
- set cursorPos(cursorPos) {
214
- this._cursorPos = cursorPos;
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 cursorPos() {
223
- return this._cursorPos;
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.centerPos = event.cursorPos || event.canvasPos;
181
- pointerLens.cursorPos = event.canvasPos;
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.centerPos = event.cursorPos || event.canvasPos;
190
- pointerLens.cursorPos = event.canvasPos;
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(event.canvasPos);
200
+ mouseHoverCanvasPos.set(canvasPos);
200
201
  switch (this._mouseState) {
201
202
  case MOUSE_FINDING_ORIGIN:
202
- this.markerDiv.style.marginLeft = `${event.canvasPos[0] - 5}px`;
203
- this.markerDiv.style.marginTop = `${event.canvasPos[1] - 5}px`;
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.centerPos = event.cursorPos;
320
- pointerLens.cursorPos = event.cursorPos;
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 = `${event.canvasPos[0] - 5}px`;
189
- this._markerDiv.style.marginTop = `${event.canvasPos[1] - 5}px`;
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.centerPos = event.cursorPos || event.canvasPos;
195
- this.pointerLens.cursorPos = event.canvasPos;
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.centerPos = event.cursorPos || event.canvasPos;
204
- this.pointerLens.cursorPos = event.canvasPos;
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.centerPos = event.cursorPos || event.canvasPos;
287
- this.pointerLens.cursorPos = event.canvasPos;
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`;
@@ -92,13 +92,13 @@ class PickController {
92
92
  const hasHoverSurfaceSubs = this._cameraControl.hasSubs("hoverSurface");
93
93
 
94
94
  if (this.scheduleSnapOrPick) {
95
- const snapPickResult = this._scene.snapPick({
95
+ const snapPickResult = this._scene.pick({
96
96
  canvasPos: this.pickCursorPos,
97
97
  snapRadius: this._configs.snapRadius,
98
98
  snapToVertex: this._configs.snapToVertex,
99
99
  snapToEdge: this._configs.snapToEdge,
100
100
  });
101
- if (snapPickResult && snapPickResult.snappedWorldPos) {
101
+ if (snapPickResult && (snapPickResult.snappedToEdge || snapPickResult.snappedToVertex)) {
102
102
  this.snapPickResult = snapPickResult;
103
103
  this.snappedOrPicked = true;
104
104
  this._needFireEvents++;
@@ -180,14 +180,14 @@ class PickController {
180
180
 
181
181
  fireEvents() {
182
182
 
183
- if (this._needFireEvents == 0) {
183
+ if (this._needFireEvents === 0) {
184
184
  return;
185
185
  }
186
186
 
187
187
  if (this.hoveredSnappedOrSurfaceOff) {
188
188
  this._cameraControl.fire("hoverSnapOrSurfaceOff", {
189
189
  canvasPos: this.pickCursorPos,
190
- cursorPos : this.pickCursorPos
190
+ pointerPos : this.pickCursorPos
191
191
  }, true);
192
192
  }
193
193
 
@@ -196,9 +196,9 @@ class PickController {
196
196
  const pickResult = new PickResult();
197
197
  pickResult.snappedToVertex = this.snapPickResult.snappedToVertex;
198
198
  pickResult.snappedToEdge = this.snapPickResult.snappedToEdge;
199
- pickResult.worldPos = this.snapPickResult.snappedWorldPos;
200
- pickResult.cursorPos = this.pickCursorPos;
201
- pickResult.canvasPos = this.snapPickResult.snappedCanvasPos;
199
+ pickResult.worldPos = this.snapPickResult.worldPos;
200
+ pickResult.canvasPos = this.pickCursorPos
201
+ pickResult.snappedCanvasPos = this.snapPickResult.snappedCanvasPos;
202
202
  this._cameraControl.fire("hoverSnapOrSurface", pickResult, true);
203
203
  this.snapPickResult = null;
204
204
  } 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
- pickResult = this._renderer.pick(params, pickResult);
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: PerformanceModelNode doesn't fire events
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 when picking with a 2D pointer.
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;