three-gamepad-controls 0.25.7 → 0.25.8
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.
|
@@ -76,6 +76,9 @@ export type GamepadArcballControlsOptions = GamepadControlsOptions & {
|
|
|
76
76
|
* needed after manual camera or target changes, matching Arcball's native API.
|
|
77
77
|
* Gamepad `start`, `change`, and `end` events are dispatched on the native controls.
|
|
78
78
|
* The balanced session belongs to this wrapper, including isolated focus commands.
|
|
79
|
+
* Zoom and focus preserve native `adjustNearFar` clipping and projection behavior,
|
|
80
|
+
* including restoration of the native initial planes on the next scale operation
|
|
81
|
+
* after adjustment is disabled. Focus without zoom leaves clipping unchanged.
|
|
79
82
|
*/
|
|
80
83
|
export declare class GamepadArcballControls extends GamepadControls {
|
|
81
84
|
#private;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GAMEPAD_AXIS, GAMEPAD_BUTTON } from "./core.js";
|
|
2
2
|
import { DEFAULT_GAMEPAD_STICK_PIPELINE, resolveGamepadStickBinding } from "./gamepad-stick-processing.js";
|
|
3
3
|
import { GamepadControls } from "./gamepad-controls.js";
|
|
4
|
-
import { Vector2, Vector3 } from "three";
|
|
4
|
+
import { Box3, Matrix4, Sphere, Vector2, Vector3 } from "three";
|
|
5
5
|
// src/gamepad-arcball-controls.ts
|
|
6
6
|
const DEFAULT_ARCBALL_OPTIONS = {
|
|
7
7
|
rotateSpeed: 1,
|
|
@@ -34,6 +34,9 @@ const ZOOM_NOTCHES_PER_SECOND = 8;
|
|
|
34
34
|
* needed after manual camera or target changes, matching Arcball's native API.
|
|
35
35
|
* Gamepad `start`, `change`, and `end` events are dispatched on the native controls.
|
|
36
36
|
* The balanced session belongs to this wrapper, including isolated focus commands.
|
|
37
|
+
* Zoom and focus preserve native `adjustNearFar` clipping and projection behavior,
|
|
38
|
+
* including restoration of the native initial planes on the next scale operation
|
|
39
|
+
* after adjustment is disabled. Focus without zoom leaves clipping unchanged.
|
|
37
40
|
*/
|
|
38
41
|
var GamepadArcballControls = class extends GamepadControls {
|
|
39
42
|
#controls;
|
|
@@ -45,6 +48,9 @@ var GamepadArcballControls = class extends GamepadControls {
|
|
|
45
48
|
#cameraForward;
|
|
46
49
|
#cameraRight;
|
|
47
50
|
#previousUp;
|
|
51
|
+
#scaleMatrix = new Matrix4();
|
|
52
|
+
#gizmoBounds = new Box3();
|
|
53
|
+
#gizmoSphere = new Sphere();
|
|
48
54
|
/** Whether this wrapper owns an active gamepad interaction. */
|
|
49
55
|
#wasInteracting = false;
|
|
50
56
|
/** Blocks recursive updates while a frame is being processed. */
|
|
@@ -274,7 +280,8 @@ var GamepadArcballControls = class extends GamepadControls {
|
|
|
274
280
|
controls.updateMatrixState();
|
|
275
281
|
const transformation = controls.scale(size, controls._gizmos.position);
|
|
276
282
|
if (transformation === void 0) return false;
|
|
277
|
-
this.#
|
|
283
|
+
this.#applyScaleTransform(transformation);
|
|
284
|
+
controls.updateMatrixState();
|
|
278
285
|
return true;
|
|
279
286
|
}
|
|
280
287
|
/**
|
|
@@ -303,7 +310,19 @@ var GamepadArcballControls = class extends GamepadControls {
|
|
|
303
310
|
if (point === null) return false;
|
|
304
311
|
const controls = this.#controls;
|
|
305
312
|
controls.updateMatrixState();
|
|
306
|
-
|
|
313
|
+
const descriptor = Object.getOwnPropertyDescriptor(controls, "applyTransformMatrix");
|
|
314
|
+
const applyScale = (transformation) => {
|
|
315
|
+
this.#applyScaleTransform(transformation);
|
|
316
|
+
};
|
|
317
|
+
controls.applyTransformMatrix = applyScale;
|
|
318
|
+
try {
|
|
319
|
+
controls.focus(point, controls.scaleFactor);
|
|
320
|
+
} finally {
|
|
321
|
+
if (controls.applyTransformMatrix === applyScale) {
|
|
322
|
+
if (descriptor) Object.defineProperty(controls, "applyTransformMatrix", descriptor);
|
|
323
|
+
else Reflect.deleteProperty(controls, "applyTransformMatrix");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
307
326
|
controls.updateMatrixState();
|
|
308
327
|
return true;
|
|
309
328
|
}
|
|
@@ -317,6 +336,43 @@ var GamepadArcballControls = class extends GamepadControls {
|
|
|
317
336
|
this.#controls.updateMatrixState();
|
|
318
337
|
}
|
|
319
338
|
/**
|
|
339
|
+
* Applies native scale matrices and geometric side effects exactly once.
|
|
340
|
+
* Arcball's own applicator gates these effects on inaccessible state Symbols.
|
|
341
|
+
* Reproduce its scale/focus branch without entering or borrowing pointer state;
|
|
342
|
+
* native scale() and focus() still own the transformation and limit calculations.
|
|
343
|
+
* Cached baselines must stay intact until focus() restores its temporary ones.
|
|
344
|
+
*
|
|
345
|
+
* @param transformation - Native camera and gizmo scale transformations.
|
|
346
|
+
*/
|
|
347
|
+
#applyScaleTransform(transformation) {
|
|
348
|
+
const controls = this.#controls;
|
|
349
|
+
const camera = controls.object;
|
|
350
|
+
const gizmos = controls._gizmos;
|
|
351
|
+
if (transformation.camera !== null) {
|
|
352
|
+
this.#scaleMatrix.copy(controls._cameraMatrixState).premultiply(transformation.camera).decompose(camera.position, camera.quaternion, camera.scale);
|
|
353
|
+
camera.updateMatrix();
|
|
354
|
+
}
|
|
355
|
+
if (transformation.gizmos !== null) {
|
|
356
|
+
this.#scaleMatrix.copy(controls._gizmoMatrixState).premultiply(transformation.gizmos).decompose(gizmos.position, gizmos.quaternion, gizmos.scale);
|
|
357
|
+
gizmos.updateMatrix();
|
|
358
|
+
}
|
|
359
|
+
controls._tbRadius = controls.calculateTbRadius(camera);
|
|
360
|
+
if (controls.adjustNearFar) {
|
|
361
|
+
const distance = camera.position.distanceTo(gizmos.position);
|
|
362
|
+
this.#gizmoBounds.setFromObject(gizmos).getBoundingSphere(this.#gizmoSphere);
|
|
363
|
+
const { radius, center } = this.#gizmoSphere;
|
|
364
|
+
const adjustedNear = Math.max(controls._nearPos0, radius + center.length());
|
|
365
|
+
const adjustedFar = Math.min(controls._farPos0, -radius + center.length());
|
|
366
|
+
camera.near = distance - Math.min(adjustedNear, distance - controls._initialNear);
|
|
367
|
+
camera.far = distance - Math.min(adjustedFar, distance - controls._initialFar);
|
|
368
|
+
camera.updateProjectionMatrix();
|
|
369
|
+
} else if (camera.near !== controls._initialNear || camera.far !== controls._initialFar) {
|
|
370
|
+
camera.near = controls._initialNear;
|
|
371
|
+
camera.far = controls._initialFar;
|
|
372
|
+
camera.updateProjectionMatrix();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
320
376
|
* Consumes a focus-button press and resolves the viewport center hit point.
|
|
321
377
|
*
|
|
322
378
|
* @param buttonFocus - Button index configured for focus.
|
package/package.json
CHANGED