@luma.gl/engine 9.4.0-beta.2 → 9.4.0-beta.3
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/controls/orbit-controls.d.ts +5 -2
- package/dist/controls/orbit-controls.d.ts.map +1 -1
- package/dist/controls/orbit-controls.js +70 -20
- package/dist/controls/orbit-controls.js.map +1 -1
- package/dist/dist.dev.js +68 -19
- package/dist/dist.min.js +4 -4
- package/dist/index.cjs +64 -19
- package/dist/index.cjs.map +1 -1
- package/package.json +2 -2
- package/src/controls/orbit-controls.ts +81 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/engine",
|
|
3
|
-
"version": "9.4.0-beta.
|
|
3
|
+
"version": "9.4.0-beta.3",
|
|
4
4
|
"description": "3D Engine Components for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"@probe.gl/log": "^4.1.1",
|
|
50
50
|
"@probe.gl/stats": "^4.1.1"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "9331acb0bcad4ce818a8e509076e5c40d22c8424"
|
|
53
53
|
}
|
|
@@ -50,7 +50,7 @@ const DEFAULT_PROPS: ResolvedOrbitControlsProps = {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Pointer orbit, wheel zoom, and optional automatic rotation controls for
|
|
53
|
+
* Pointer orbit, wheel and pinch zoom, and optional automatic rotation controls for a canvas.
|
|
54
54
|
*
|
|
55
55
|
* Call {@link update} once per frame with an animation-loop timestamp in milliseconds before
|
|
56
56
|
* reading {@link getEyePosition}. Manual dragging temporarily pauses automatic rotation and
|
|
@@ -64,8 +64,9 @@ export class OrbitControls {
|
|
|
64
64
|
distance: number;
|
|
65
65
|
|
|
66
66
|
private dragging = false;
|
|
67
|
-
private
|
|
67
|
+
private readonly activePointers = new Map<number, [number, number]>();
|
|
68
68
|
private lastPointer: [number, number] = [0, 0];
|
|
69
|
+
private previousPinchDistance: number | null = null;
|
|
69
70
|
private previousTimeMilliseconds: number | null = null;
|
|
70
71
|
private readonly previousCursor: string;
|
|
71
72
|
private readonly previousTouchAction: string;
|
|
@@ -169,39 +170,65 @@ export class OrbitControls {
|
|
|
169
170
|
this.canvas.removeEventListener('pointerup', this.handlePointerUp);
|
|
170
171
|
this.canvas.removeEventListener('pointercancel', this.handlePointerUp);
|
|
171
172
|
this.canvas.removeEventListener('wheel', this.handleWheel);
|
|
172
|
-
|
|
173
|
-
this.canvas.releasePointerCapture(this.pointerId);
|
|
174
|
-
}
|
|
173
|
+
this.endPointerInteraction();
|
|
175
174
|
this.canvas.style.cursor = this.previousCursor;
|
|
176
175
|
this.canvas.style.touchAction = this.previousTouchAction;
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
private readonly handlePointerDown = (event: PointerEvent): void => {
|
|
180
|
-
if (
|
|
179
|
+
if (
|
|
180
|
+
!this.props.enabled ||
|
|
181
|
+
event.button !== 0 ||
|
|
182
|
+
this.activePointers.has(event.pointerId) ||
|
|
183
|
+
this.activePointers.size >= 2 ||
|
|
184
|
+
(this.activePointers.size > 0 && event.pointerType !== 'touch')
|
|
185
|
+
) {
|
|
181
186
|
return;
|
|
182
187
|
}
|
|
183
|
-
this.
|
|
188
|
+
if (this.activePointers.size === 0) {
|
|
189
|
+
this.props.onInteractionStart?.();
|
|
190
|
+
}
|
|
184
191
|
this.dragging = true;
|
|
185
|
-
this.pointerId
|
|
186
|
-
this.
|
|
192
|
+
this.activePointers.set(event.pointerId, [event.clientX, event.clientY]);
|
|
193
|
+
if (this.activePointers.size === 1) {
|
|
194
|
+
this.lastPointer = [event.clientX, event.clientY];
|
|
195
|
+
} else {
|
|
196
|
+
const {center, distance} = this.getMultiPointerState();
|
|
197
|
+
this.lastPointer = center;
|
|
198
|
+
this.previousPinchDistance = distance;
|
|
199
|
+
}
|
|
187
200
|
this.canvas.setPointerCapture(event.pointerId);
|
|
188
201
|
this.canvas.style.cursor = 'grabbing';
|
|
189
202
|
};
|
|
190
203
|
|
|
191
204
|
private readonly handlePointerMove = (event: PointerEvent): void => {
|
|
192
|
-
if (!this.props.enabled || !this.dragging || event.pointerId
|
|
205
|
+
if (!this.props.enabled || !this.dragging || !this.activePointers.has(event.pointerId)) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
this.activePointers.set(event.pointerId, [event.clientX, event.clientY]);
|
|
210
|
+
if (this.activePointers.size > 1) {
|
|
211
|
+
const {center, distance} = this.getMultiPointerState();
|
|
212
|
+
if (this.props.enablePan) {
|
|
213
|
+
this.panTarget(center[0] - this.lastPointer[0], center[1] - this.lastPointer[1]);
|
|
214
|
+
}
|
|
215
|
+
if (this.props.enableZoom && this.previousPinchDistance && distance > 0) {
|
|
216
|
+
this.distance = clampNumber(
|
|
217
|
+
(this.distance * this.previousPinchDistance) / distance,
|
|
218
|
+
this.props.minDistance,
|
|
219
|
+
this.props.maxDistance
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
this.lastPointer = center;
|
|
223
|
+
this.previousPinchDistance = distance;
|
|
193
224
|
return;
|
|
194
225
|
}
|
|
226
|
+
|
|
195
227
|
const deltaX = event.clientX - this.lastPointer[0];
|
|
196
228
|
const deltaY = event.clientY - this.lastPointer[1];
|
|
197
229
|
this.lastPointer = [event.clientX, event.clientY];
|
|
198
230
|
if (this.props.enablePan && event.shiftKey) {
|
|
199
|
-
|
|
200
|
-
this.props.target = [
|
|
201
|
-
this.props.target[0] - Math.cos(this.yaw) * deltaX * panScale,
|
|
202
|
-
this.props.target[1] + deltaY * panScale,
|
|
203
|
-
this.props.target[2] + Math.sin(this.yaw) * deltaX * panScale
|
|
204
|
-
];
|
|
231
|
+
this.panTarget(deltaX, deltaY);
|
|
205
232
|
} else {
|
|
206
233
|
this.yaw -= deltaX * this.props.rotateSpeed;
|
|
207
234
|
this.pitch = clampNumber(
|
|
@@ -213,7 +240,19 @@ export class OrbitControls {
|
|
|
213
240
|
};
|
|
214
241
|
|
|
215
242
|
private readonly handlePointerUp = (event: PointerEvent): void => {
|
|
216
|
-
if (event.pointerId
|
|
243
|
+
if (!this.activePointers.has(event.pointerId)) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (this.canvas.hasPointerCapture(event.pointerId)) {
|
|
248
|
+
this.canvas.releasePointerCapture(event.pointerId);
|
|
249
|
+
}
|
|
250
|
+
this.activePointers.delete(event.pointerId);
|
|
251
|
+
this.previousPinchDistance = null;
|
|
252
|
+
|
|
253
|
+
const remainingPointer = this.activePointers.entries().next().value;
|
|
254
|
+
if (remainingPointer) {
|
|
255
|
+
this.lastPointer = remainingPointer[1];
|
|
217
256
|
return;
|
|
218
257
|
}
|
|
219
258
|
this.endPointerInteraction();
|
|
@@ -221,13 +260,35 @@ export class OrbitControls {
|
|
|
221
260
|
|
|
222
261
|
private endPointerInteraction(): void {
|
|
223
262
|
this.dragging = false;
|
|
224
|
-
|
|
225
|
-
this.canvas.
|
|
263
|
+
for (const pointerId of this.activePointers.keys()) {
|
|
264
|
+
if (this.canvas.hasPointerCapture(pointerId)) {
|
|
265
|
+
this.canvas.releasePointerCapture(pointerId);
|
|
266
|
+
}
|
|
226
267
|
}
|
|
227
|
-
this.
|
|
268
|
+
this.activePointers.clear();
|
|
269
|
+
this.previousPinchDistance = null;
|
|
228
270
|
this.canvas.style.cursor = 'grab';
|
|
229
271
|
}
|
|
230
272
|
|
|
273
|
+
private getMultiPointerState(): {center: [number, number]; distance: number} {
|
|
274
|
+
const [firstPointer, secondPointer] = this.activePointers.values();
|
|
275
|
+
const deltaX = secondPointer[0] - firstPointer[0];
|
|
276
|
+
const deltaY = secondPointer[1] - firstPointer[1];
|
|
277
|
+
return {
|
|
278
|
+
center: [(firstPointer[0] + secondPointer[0]) / 2, (firstPointer[1] + secondPointer[1]) / 2],
|
|
279
|
+
distance: Math.hypot(deltaX, deltaY)
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private panTarget(deltaX: number, deltaY: number): void {
|
|
284
|
+
const panScale = this.distance * this.props.panSpeed;
|
|
285
|
+
this.props.target = [
|
|
286
|
+
this.props.target[0] - Math.cos(this.yaw) * deltaX * panScale,
|
|
287
|
+
this.props.target[1] + deltaY * panScale,
|
|
288
|
+
this.props.target[2] + Math.sin(this.yaw) * deltaX * panScale
|
|
289
|
+
];
|
|
290
|
+
}
|
|
291
|
+
|
|
231
292
|
private readonly handleWheel = (event: WheelEvent): void => {
|
|
232
293
|
if (!this.props.enabled || !this.props.enableZoom) {
|
|
233
294
|
return;
|