@pmndrs/klipp 0.0.0-stage → 0.14.0
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/LICENSE +21 -0
- package/README.md +72 -2
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/core/CameraState.d.ts +32 -0
- package/dist/core/CameraState.js +97 -0
- package/dist/core/EventDispatcher.d.ts +18 -0
- package/dist/core/EventDispatcher.js +28 -0
- package/dist/core/Klipp.d.ts +109 -0
- package/dist/core/Klipp.js +253 -0
- package/dist/core/TargetExtent.d.ts +11 -0
- package/dist/core/TargetExtent.js +54 -0
- package/dist/core/TargetPose.d.ts +13 -0
- package/dist/core/TargetPose.js +21 -0
- package/dist/core/VirtualCamera.d.ts +102 -0
- package/dist/core/VirtualCamera.js +290 -0
- package/dist/core/aim/HardLookAtAim.d.ts +10 -0
- package/dist/core/aim/HardLookAtAim.js +19 -0
- package/dist/core/aim/PanTiltAim.d.ts +26 -0
- package/dist/core/aim/PanTiltAim.js +38 -0
- package/dist/core/aim/RotateWithFollowTargetAim.d.ts +19 -0
- package/dist/core/aim/RotateWithFollowTargetAim.js +23 -0
- package/dist/core/aim/RotationComposerAim.d.ts +27 -0
- package/dist/core/aim/RotationComposerAim.js +27 -0
- package/dist/core/aim/hardLookAt.d.ts +4 -0
- package/dist/core/aim/hardLookAt.js +13 -0
- package/dist/core/aim/index.d.ts +11 -0
- package/dist/core/aim/lookRotation.d.ts +6 -0
- package/dist/core/aim/lookRotation.js +46 -0
- package/dist/core/aim/panTilt.d.ts +16 -0
- package/dist/core/aim/panTilt.js +121 -0
- package/dist/core/aim/rotateWithFollowTarget.d.ts +20 -0
- package/dist/core/aim/rotateWithFollowTarget.js +35 -0
- package/dist/core/aim/rotationComposer.d.ts +58 -0
- package/dist/core/aim/rotationComposer.js +284 -0
- package/dist/core/blend/BlendCurves.d.ts +19 -0
- package/dist/core/blend/BlendCurves.js +22 -0
- package/dist/core/blend/BlendDefinition.d.ts +21 -0
- package/dist/core/blend/BlendDefinition.js +9 -0
- package/dist/core/blend/BlendDriver.d.ts +23 -0
- package/dist/core/blend/BlendDriver.js +42 -0
- package/dist/core/blend/BlendHints.d.ts +9 -0
- package/dist/core/blend/BlendHints.js +13 -0
- package/dist/core/blend/blend.d.ts +41 -0
- package/dist/core/blend/blend.js +110 -0
- package/dist/core/blend/index.d.ts +6 -0
- package/dist/core/blend/lerpCameraState.d.ts +4 -0
- package/dist/core/blend/lerpCameraState.js +143 -0
- package/dist/core/body/BindingModes.d.ts +9 -0
- package/dist/core/body/BindingModes.js +11 -0
- package/dist/core/body/FollowBody.d.ts +24 -0
- package/dist/core/body/FollowBody.js +26 -0
- package/dist/core/body/HardLockToTargetBody.d.ts +17 -0
- package/dist/core/body/HardLockToTargetBody.js +20 -0
- package/dist/core/body/OrbitFollowBody.d.ts +47 -0
- package/dist/core/body/OrbitFollowBody.js +48 -0
- package/dist/core/body/PositionComposerBody.d.ts +28 -0
- package/dist/core/body/PositionComposerBody.js +27 -0
- package/dist/core/body/follow.d.ts +33 -0
- package/dist/core/body/follow.js +83 -0
- package/dist/core/body/hardLockToTarget.d.ts +17 -0
- package/dist/core/body/hardLockToTarget.js +26 -0
- package/dist/core/body/index.d.ts +17 -0
- package/dist/core/body/orbitFollow.d.ts +76 -0
- package/dist/core/body/orbitFollow.js +336 -0
- package/dist/core/body/positionComposer.d.ts +56 -0
- package/dist/core/body/positionComposer.js +207 -0
- package/dist/core/body/safeFromToRotation.d.ts +3 -0
- package/dist/core/body/safeFromToRotation.js +39 -0
- package/dist/core/body/threeRing.d.ts +28 -0
- package/dist/core/body/threeRing.js +100 -0
- package/dist/core/body/tracker.d.ts +42 -0
- package/dist/core/body/tracker.js +193 -0
- package/dist/core/damping/Damper.d.ts +11 -0
- package/dist/core/damping/Damper.js +22 -0
- package/dist/core/damping/damping.d.ts +30 -0
- package/dist/core/damping/damping.js +119 -0
- package/dist/core/damping/index.d.ts +5 -0
- package/dist/core/damping/predictor.d.ts +16 -0
- package/dist/core/damping/predictor.js +56 -0
- package/dist/core/debug/debugZones.d.ts +16 -0
- package/dist/core/debug/debugZones.js +38 -0
- package/dist/core/debug/index.d.ts +2 -0
- package/dist/core/extension/GroupFramingExtension.d.ts +26 -0
- package/dist/core/extension/GroupFramingExtension.js +24 -0
- package/dist/core/extension/LensExtension.d.ts +20 -0
- package/dist/core/extension/LensExtension.js +12 -0
- package/dist/core/extension/groupFraming.d.ts +62 -0
- package/dist/core/extension/groupFraming.js +271 -0
- package/dist/core/extension/index.d.ts +6 -0
- package/dist/core/extension/lens.d.ts +35 -0
- package/dist/core/extension/lens.js +57 -0
- package/dist/core/groups/ClearShot.d.ts +32 -0
- package/dist/core/groups/MixingCamera.d.ts +20 -0
- package/dist/core/groups/Sequencer.d.ts +24 -0
- package/dist/core/groups/StateDrivenCamera.d.ts +26 -0
- package/dist/core/groups/clearShotState.d.ts +32 -0
- package/dist/core/groups/index.d.ts +11 -0
- package/dist/core/groups/mixCameraStates.d.ts +13 -0
- package/dist/core/groups/sequencerState.d.ts +26 -0
- package/dist/core/groups/stateDrivenState.d.ts +28 -0
- package/dist/core/impulse/ImpulseField.d.ts +15 -0
- package/dist/core/impulse/ImpulseField.js +22 -0
- package/dist/core/impulse/ImpulseListenerNoise.d.ts +19 -0
- package/dist/core/impulse/ImpulseListenerNoise.js +29 -0
- package/dist/core/impulse/impulseListener.d.ts +13 -0
- package/dist/core/impulse/impulseListener.js +14 -0
- package/dist/core/impulse/impulses.d.ts +54 -0
- package/dist/core/impulse/impulses.js +84 -0
- package/dist/core/impulse/index.d.ts +6 -0
- package/dist/core/index.d.ts +20 -0
- package/dist/core/index.js +52 -0
- package/dist/core/input/InputAxis.d.ts +29 -0
- package/dist/core/input/InputAxis.js +28 -0
- package/dist/core/input/InputAxisOwner.d.ts +6 -0
- package/dist/core/input/InputAxisOwner.js +4 -0
- package/dist/core/input/InputController.d.ts +15 -0
- package/dist/core/input/InputController.js +24 -0
- package/dist/core/input/axis.d.ts +52 -0
- package/dist/core/input/axis.js +89 -0
- package/dist/core/input/consumedInput.d.ts +37 -0
- package/dist/core/input/consumedInput.js +34 -0
- package/dist/core/input/index.d.ts +9 -0
- package/dist/core/input/inputMapping.d.ts +46 -0
- package/dist/core/input/inputMapping.js +55 -0
- package/dist/core/input/shortestWrappedDelta.d.ts +2 -0
- package/dist/core/input/shortestWrappedDelta.js +11 -0
- package/dist/core/internal.d.ts +16 -0
- package/dist/core/internal.js +19 -0
- package/dist/core/klippState.d.ts +78 -0
- package/dist/core/klippState.js +124 -0
- package/dist/core/noise/BasicMultiChannelPerlinNoise.d.ts +21 -0
- package/dist/core/noise/BasicMultiChannelPerlinNoise.js +13 -0
- package/dist/core/noise/index.d.ts +3 -0
- package/dist/core/noise/perlinNoise.d.ts +36 -0
- package/dist/core/noise/perlinNoise.js +110 -0
- package/dist/core/params.d.ts +2 -0
- package/dist/core/params.js +12 -0
- package/dist/dom/DebugOverlay.d.ts +11 -0
- package/dist/dom/DebugOverlay.js +96 -0
- package/dist/dom/InputControllerDom.d.ts +15 -0
- package/dist/dom/InputControllerDom.js +31 -0
- package/dist/dom/InputSystem.d.ts +40 -0
- package/dist/dom/InputSystem.js +113 -0
- package/dist/dom/index.d.ts +3 -0
- package/dist/dom/index.js +5 -0
- package/dist/input-sources/buttonInput.d.ts +15 -0
- package/dist/input-sources/buttonInput.js +23 -0
- package/dist/input-sources/isInsideInteractiveArea.d.ts +9 -0
- package/dist/input-sources/isInsideInteractiveArea.js +11 -0
- package/dist/input-sources/mouse.d.ts +47 -0
- package/dist/input-sources/mouse.js +171 -0
- package/dist/input-sources/safariGesture.d.ts +32 -0
- package/dist/input-sources/safariGesture.js +107 -0
- package/dist/input-sources/suppressNativeGestures.d.ts +5 -0
- package/dist/input-sources/suppressNativeGestures.js +32 -0
- package/dist/input-sources/touch.d.ts +47 -0
- package/dist/input-sources/touch.js +173 -0
- package/dist/input-sources/wheel.d.ts +28 -0
- package/dist/input-sources/wheel.js +44 -0
- package/dist/react/CameraFrustumHelper.d.ts +13 -0
- package/dist/react/CameraFrustumHelper.js +32 -0
- package/dist/react/DebugZoneOverlay.d.ts +7 -0
- package/dist/react/DebugZoneOverlay.js +23 -0
- package/dist/react/Klipp.d.ts +20 -0
- package/dist/react/Klipp.js +47 -0
- package/dist/react/KlippContext.d.ts +5 -0
- package/dist/react/KlippContext.js +11 -0
- package/dist/react/VirtualCamera.d.ts +28 -0
- package/dist/react/VirtualCamera.js +81 -0
- package/dist/react/VirtualCameraContext.d.ts +11 -0
- package/dist/react/VirtualCameraContext.js +21 -0
- package/dist/react/aim/Aim.d.ts +11 -0
- package/dist/react/aim/Aim.js +14 -0
- package/dist/react/aim/HardLookAt.d.ts +10 -0
- package/dist/react/aim/HardLookAt.js +15 -0
- package/dist/react/aim/PanTilt.d.ts +31 -0
- package/dist/react/aim/PanTilt.js +38 -0
- package/dist/react/aim/RotateWithFollowTarget.d.ts +10 -0
- package/dist/react/aim/RotateWithFollowTarget.js +18 -0
- package/dist/react/aim/RotationComposer.d.ts +12 -0
- package/dist/react/aim/RotationComposer.js +34 -0
- package/dist/react/body/Body.d.ts +11 -0
- package/dist/react/body/Body.js +14 -0
- package/dist/react/body/CameraControls.d.ts +50 -0
- package/dist/react/body/CameraControls.js +106 -0
- package/dist/react/body/Follow.d.ts +10 -0
- package/dist/react/body/Follow.js +20 -0
- package/dist/react/body/HardLockToTarget.d.ts +10 -0
- package/dist/react/body/HardLockToTarget.js +18 -0
- package/dist/react/body/OrbitFollow.d.ts +25 -0
- package/dist/react/body/OrbitFollow.js +67 -0
- package/dist/react/body/PositionComposer.d.ts +12 -0
- package/dist/react/body/PositionComposer.js +32 -0
- package/dist/react/body/camera-controls.d.ts +2 -0
- package/dist/react/body/camera-controls.js +3 -0
- package/dist/react/extension/Extension.d.ts +7 -0
- package/dist/react/extension/Extension.js +10 -0
- package/dist/react/extension/GroupFraming.d.ts +14 -0
- package/dist/react/extension/GroupFraming.js +52 -0
- package/dist/react/extension/Lens.d.ts +7 -0
- package/dist/react/extension/Lens.js +31 -0
- package/dist/react/impulse/ImpulseListener.d.ts +12 -0
- package/dist/react/impulse/ImpulseListener.js +33 -0
- package/dist/react/index.d.ts +24 -0
- package/dist/react/index.js +24 -0
- package/dist/react/input/InputAxisOwnerContext.d.ts +3 -0
- package/dist/react/input/InputAxisOwnerContext.js +6 -0
- package/dist/react/input/InputController.d.ts +53 -0
- package/dist/react/input/InputController.js +115 -0
- package/dist/react/noise/BasicMultiChannelPerlin.d.ts +7 -0
- package/dist/react/noise/BasicMultiChannelPerlin.js +14 -0
- package/dist/react/noise/Noise.d.ts +5 -0
- package/dist/react/noise/Noise.js +6 -0
- package/dist/react/noise/useBasicMultiChannelPerlinNoise.d.ts +4 -0
- package/dist/react/noise/useBasicMultiChannelPerlinNoise.js +21 -0
- package/dist/react/useCameraTransitionEvent.d.ts +12 -0
- package/dist/react/useCameraTransitionEvent.js +14 -0
- package/dist/three/CameraFrustumHelperThree.d.ts +11 -0
- package/dist/three/CameraFrustumHelperThree.js +44 -0
- package/dist/three/KlippThree.d.ts +18 -0
- package/dist/three/KlippThree.js +50 -0
- package/dist/three/VirtualCameraThree.d.ts +35 -0
- package/dist/three/VirtualCameraThree.js +108 -0
- package/dist/three/aim/HardLookAtAimThree.d.ts +10 -0
- package/dist/three/aim/HardLookAtAimThree.js +14 -0
- package/dist/three/aim/PanTiltAimThree.d.ts +10 -0
- package/dist/three/aim/PanTiltAimThree.js +15 -0
- package/dist/three/aim/RotateWithFollowTargetAimThree.d.ts +11 -0
- package/dist/three/aim/RotateWithFollowTargetAimThree.js +15 -0
- package/dist/three/aim/RotationComposerAimThree.d.ts +26 -0
- package/dist/three/aim/RotationComposerAimThree.js +35 -0
- package/dist/three/body/CameraControlsBodyThree.d.ts +30 -0
- package/dist/three/body/CameraControlsBodyThree.js +54 -0
- package/dist/three/body/FollowBodyThree.d.ts +16 -0
- package/dist/three/body/FollowBodyThree.js +23 -0
- package/dist/three/body/HardLockToTargetBodyThree.d.ts +11 -0
- package/dist/three/body/HardLockToTargetBodyThree.js +14 -0
- package/dist/three/body/OrbitFollowBodyThree.d.ts +16 -0
- package/dist/three/body/OrbitFollowBodyThree.js +23 -0
- package/dist/three/body/OrbitFollowHelperThree.d.ts +23 -0
- package/dist/three/body/OrbitFollowHelperThree.js +85 -0
- package/dist/three/body/PositionComposerBodyThree.d.ts +24 -0
- package/dist/three/body/PositionComposerBodyThree.js +31 -0
- package/dist/three/camera.d.ts +10 -0
- package/dist/three/camera.js +39 -0
- package/dist/three/damping/Predictor.d.ts +12 -0
- package/dist/three/damping/Predictor.js +30 -0
- package/dist/three/damping/QuaternionDamper.d.ts +10 -0
- package/dist/three/damping/QuaternionDamper.js +28 -0
- package/dist/three/damping/Vector3Damper.d.ts +10 -0
- package/dist/three/damping/Vector3Damper.js +26 -0
- package/dist/three/extension/GroupFramingExtensionThree.d.ts +13 -0
- package/dist/three/extension/GroupFramingExtensionThree.js +23 -0
- package/dist/three/extension/TargetGroup.d.ts +32 -0
- package/dist/three/extension/TargetGroup.js +53 -0
- package/dist/three/index.d.ts +24 -0
- package/dist/three/index.js +25 -0
- package/dist/three/noise/BasicMultiChannelPerlinNoiseThree.d.ts +16 -0
- package/dist/three/noise/BasicMultiChannelPerlinNoiseThree.js +17 -0
- package/dist/three/readTargetExtent.d.ts +9 -0
- package/dist/three/readTargetExtent.js +25 -0
- package/dist/three/readTargetPose.d.ts +8 -0
- package/dist/three/readTargetPose.js +21 -0
- package/dist/three/resolve/Target.d.ts +17 -0
- package/dist/three/resolve/Target.js +62 -0
- package/dist/three/resolve/TargetRegistry.d.ts +27 -0
- package/dist/three/resolve/TargetRegistry.js +78 -0
- package/dist/three/resolve/resolveVector3.d.ts +12 -0
- package/dist/three/resolve/resolveVector3.js +29 -0
- package/package.json +120 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Vec3 } from 'math';
|
|
2
|
+
import type { CameraState } from '../CameraState.js';
|
|
3
|
+
import type { TargetPose } from '../TargetPose.js';
|
|
4
|
+
import type { DampingConstant } from '../damping/damping.js';
|
|
5
|
+
import * as positionComposer from './positionComposer.js';
|
|
6
|
+
import type { PositionComposerParams } from './positionComposer.js';
|
|
7
|
+
/** Positions the camera using depth and screen-space composition. Layers override `readTarget`. */
|
|
8
|
+
export declare class PositionComposerBody<T = TargetPose | null> implements PositionComposerParams {
|
|
9
|
+
target: T;
|
|
10
|
+
cameraDistance: number;
|
|
11
|
+
screenPosition: [number, number];
|
|
12
|
+
aspect: number;
|
|
13
|
+
deadZone: [number, number];
|
|
14
|
+
damping: DampingConstant;
|
|
15
|
+
hardLimit: [number, number];
|
|
16
|
+
depthDeadZone: number;
|
|
17
|
+
maxSpeed: number;
|
|
18
|
+
lookaheadTime: number;
|
|
19
|
+
lookaheadSmoothing: number;
|
|
20
|
+
lookaheadIgnoreY: boolean;
|
|
21
|
+
readonly state: positionComposer.PositionComposerState;
|
|
22
|
+
private lastTarget;
|
|
23
|
+
constructor(target: T, options?: Partial<PositionComposerParams>);
|
|
24
|
+
primeFrom: (position: Vec3) => void;
|
|
25
|
+
update: (out: CameraState, dt: number, justActivated: boolean) => void;
|
|
26
|
+
/** This frame's target pose with its extent, or `null` when there is none. */
|
|
27
|
+
protected readTarget(): TargetPose | null;
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createParams, createState, prime, retarget, update } from "./positionComposer.js";
|
|
2
|
+
//#region src/core/body/PositionComposerBody.ts
|
|
3
|
+
/** Positions the camera using depth and screen-space composition. Layers override `readTarget`. */
|
|
4
|
+
var PositionComposerBody = class {
|
|
5
|
+
target;
|
|
6
|
+
state = createState();
|
|
7
|
+
lastTarget = void 0;
|
|
8
|
+
constructor(target, options) {
|
|
9
|
+
this.target = target;
|
|
10
|
+
Object.assign(this, createParams(options));
|
|
11
|
+
}
|
|
12
|
+
primeFrom = (position) => prime(this.state, this, position);
|
|
13
|
+
update = (out, dt, justActivated) => {
|
|
14
|
+
const pose = this.readTarget();
|
|
15
|
+
if (pose) {
|
|
16
|
+
if (this.target !== this.lastTarget) retarget(this.state);
|
|
17
|
+
this.lastTarget = this.target;
|
|
18
|
+
}
|
|
19
|
+
update(out, this.state, this, pose, dt, justActivated);
|
|
20
|
+
};
|
|
21
|
+
/** This frame's target pose with its extent, or `null` when there is none. */
|
|
22
|
+
readTarget() {
|
|
23
|
+
return this.target;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { PositionComposerBody };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Vec3 } from 'math';
|
|
2
|
+
import type { CameraState } from '../CameraState.js';
|
|
3
|
+
import type { TargetPose } from '../TargetPose.js';
|
|
4
|
+
import type { DampingConstant } from '../damping/damping.js';
|
|
5
|
+
import { type BindingMode } from './BindingModes.js';
|
|
6
|
+
import type { TrackerState } from './tracker.js';
|
|
7
|
+
export type FollowParams = {
|
|
8
|
+
/** Offset from the target, rotated according to `bindingMode`. */
|
|
9
|
+
offset: Vec3;
|
|
10
|
+
/** Response time for following the target position. */
|
|
11
|
+
damping: DampingConstant;
|
|
12
|
+
/** Response time for turning with the target, for every `bindingMode` but `worldSpace`. */
|
|
13
|
+
rotationDamping: DampingConstant;
|
|
14
|
+
/** Rotation frame used to interpret `offset`. */
|
|
15
|
+
bindingMode: BindingMode;
|
|
16
|
+
/** Maximum damping speed, in world units/sec. */
|
|
17
|
+
maxSpeed: number;
|
|
18
|
+
};
|
|
19
|
+
/** Every setting from `settings`, or its default. */
|
|
20
|
+
export declare const createParams: (settings?: Partial<FollowParams>) => FollowParams;
|
|
21
|
+
export type FollowState = {
|
|
22
|
+
tracker: TrackerState;
|
|
23
|
+
/** Position set by `prime`, applied once a target is available. */
|
|
24
|
+
primePosition: Vec3;
|
|
25
|
+
primed: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare const createState: () => FollowState;
|
|
28
|
+
/** Whether `update` will read `target.rotation` this frame. */
|
|
29
|
+
export declare const needsTargetRotation: (state: FollowState, params: FollowParams) => boolean;
|
|
30
|
+
/** Moves `out` to the target position plus `offset`, rotated according to `bindingMode`. A `null` target leaves `out` as is. */
|
|
31
|
+
export declare function update(out: CameraState, state: FollowState, params: FollowParams, target: TargetPose | null, dt: number, justActivated: boolean): void;
|
|
32
|
+
/** Start the next activation from `position` instead of snapping to the target. */
|
|
33
|
+
export declare function prime(state: FollowState, position: Vec3): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { withDefaults } from "../params.js";
|
|
3
|
+
import { BindingModes } from "./BindingModes.js";
|
|
4
|
+
import { createState as createState$1, needsTargetRotation as needsTargetRotation$1, prime as prime$1, referenceOrientation, reset, trackTarget } from "./tracker.js";
|
|
5
|
+
import { vec3 } from "math";
|
|
6
|
+
//#region src/core/body/follow.ts
|
|
7
|
+
var follow_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
createParams: () => createParams,
|
|
9
|
+
createState: () => createState,
|
|
10
|
+
needsTargetRotation: () => needsTargetRotation,
|
|
11
|
+
prime: () => prime,
|
|
12
|
+
update: () => update
|
|
13
|
+
});
|
|
14
|
+
/** Every setting from `settings`, or its default. */
|
|
15
|
+
var createParams = (settings) => withDefaults({
|
|
16
|
+
offset: [
|
|
17
|
+
0,
|
|
18
|
+
0,
|
|
19
|
+
10
|
|
20
|
+
],
|
|
21
|
+
damping: 0,
|
|
22
|
+
rotationDamping: 0,
|
|
23
|
+
bindingMode: BindingModes.lockToTarget,
|
|
24
|
+
maxSpeed: Infinity
|
|
25
|
+
}, settings);
|
|
26
|
+
var createState = () => ({
|
|
27
|
+
tracker: createState$1(),
|
|
28
|
+
primePosition: [
|
|
29
|
+
0,
|
|
30
|
+
0,
|
|
31
|
+
0
|
|
32
|
+
],
|
|
33
|
+
primed: false
|
|
34
|
+
});
|
|
35
|
+
/** Whether `update` will read `target.rotation` this frame. */
|
|
36
|
+
var needsTargetRotation = (state, params) => needsTargetRotation$1(state.tracker, params.bindingMode);
|
|
37
|
+
var worldUp = [
|
|
38
|
+
0,
|
|
39
|
+
1,
|
|
40
|
+
0
|
|
41
|
+
];
|
|
42
|
+
var noOffset = [
|
|
43
|
+
0,
|
|
44
|
+
0,
|
|
45
|
+
0
|
|
46
|
+
];
|
|
47
|
+
var scratchRotation = [
|
|
48
|
+
0,
|
|
49
|
+
0,
|
|
50
|
+
0,
|
|
51
|
+
1
|
|
52
|
+
];
|
|
53
|
+
var scratchRotatedOffset = [
|
|
54
|
+
0,
|
|
55
|
+
0,
|
|
56
|
+
0
|
|
57
|
+
];
|
|
58
|
+
function startFromPrime(state, params, target) {
|
|
59
|
+
referenceOrientation(scratchRotation, state.tracker, params.bindingMode, target);
|
|
60
|
+
vec3.transformQuat(scratchRotatedOffset, params.offset, scratchRotation);
|
|
61
|
+
vec3.subtract(scratchRotatedOffset, state.primePosition, scratchRotatedOffset);
|
|
62
|
+
prime$1(state.tracker, scratchRotatedOffset, params.offset, scratchRotation);
|
|
63
|
+
}
|
|
64
|
+
/** Moves `out` to the target position plus `offset`, rotated according to `bindingMode`. A `null` target leaves `out` as is. */
|
|
65
|
+
function update(out, state, params, target, dt, justActivated) {
|
|
66
|
+
if (justActivated && !state.primed) reset(state.tracker);
|
|
67
|
+
if (!target) return;
|
|
68
|
+
if (state.primed) {
|
|
69
|
+
state.primed = false;
|
|
70
|
+
startFromPrime(state, params, target);
|
|
71
|
+
}
|
|
72
|
+
trackTarget(out.target, scratchRotation, state.tracker, params, target, params.offset, noOffset, dt);
|
|
73
|
+
vec3.add(out.position, out.target, vec3.transformQuat(scratchRotatedOffset, params.offset, scratchRotation));
|
|
74
|
+
out.hasTarget = true;
|
|
75
|
+
vec3.transformQuat(out.referenceUp, worldUp, scratchRotation);
|
|
76
|
+
}
|
|
77
|
+
/** Start the next activation from `position` instead of snapping to the target. */
|
|
78
|
+
function prime(state, position) {
|
|
79
|
+
vec3.copy(state.primePosition, position);
|
|
80
|
+
state.primed = true;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { createParams, createState, follow_exports, needsTargetRotation, prime, update };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Vec3 } from 'math';
|
|
2
|
+
import type { CameraState } from '../CameraState.js';
|
|
3
|
+
import type { DampingConstant, Vector3DamperState } from '../damping/damping.js';
|
|
4
|
+
export type HardLockToTargetParams = {
|
|
5
|
+
/** Response time for following the target position. */
|
|
6
|
+
damping: DampingConstant;
|
|
7
|
+
/** Maximum damping speed, in world units/sec. */
|
|
8
|
+
maxSpeed: number;
|
|
9
|
+
};
|
|
10
|
+
/** Every setting from `settings`, or its default. */
|
|
11
|
+
export declare const createParams: (settings?: Partial<HardLockToTargetParams>) => HardLockToTargetParams;
|
|
12
|
+
export type HardLockToTargetState = {
|
|
13
|
+
damper: Vector3DamperState;
|
|
14
|
+
};
|
|
15
|
+
export declare const createState: () => HardLockToTargetState;
|
|
16
|
+
/** Moves `out` onto `targetPosition`, optionally damped. A `null` target leaves `out` as is. */
|
|
17
|
+
export declare function update(out: CameraState, state: HardLockToTargetState, params: HardLockToTargetParams, targetPosition: Vec3 | null, dt: number, justActivated: boolean): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { createVector3State, dampVector3, resetVector3 } from "../damping/damping.js";
|
|
3
|
+
import { withDefaults } from "../params.js";
|
|
4
|
+
import { vec3 } from "math";
|
|
5
|
+
//#region src/core/body/hardLockToTarget.ts
|
|
6
|
+
var hardLockToTarget_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
createParams: () => createParams,
|
|
8
|
+
createState: () => createState,
|
|
9
|
+
update: () => update
|
|
10
|
+
});
|
|
11
|
+
/** Every setting from `settings`, or its default. */
|
|
12
|
+
var createParams = (settings) => withDefaults({
|
|
13
|
+
damping: 0,
|
|
14
|
+
maxSpeed: Infinity
|
|
15
|
+
}, settings);
|
|
16
|
+
var createState = () => ({ damper: createVector3State() });
|
|
17
|
+
/** Moves `out` onto `targetPosition`, optionally damped. A `null` target leaves `out` as is. */
|
|
18
|
+
function update(out, state, params, targetPosition, dt, justActivated) {
|
|
19
|
+
if (justActivated) resetVector3(state.damper);
|
|
20
|
+
if (!targetPosition) return;
|
|
21
|
+
dampVector3(state.damper, out.position, targetPosition, params.damping, dt, params.maxSpeed);
|
|
22
|
+
vec3.copy(out.target, out.position);
|
|
23
|
+
out.hasTarget = true;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { createParams, createState, hardLockToTarget_exports, update };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { BindingModes, type BindingMode } from './BindingModes.js';
|
|
2
|
+
export { HardLockToTargetBody, type HardLockToTargetOptions } from './HardLockToTargetBody.js';
|
|
3
|
+
export * as hardLockToTarget from './hardLockToTarget.js';
|
|
4
|
+
export type { HardLockToTargetParams, HardLockToTargetState } from './hardLockToTarget.js';
|
|
5
|
+
export { FollowBody, type FollowOptions } from './FollowBody.js';
|
|
6
|
+
export * as follow from './follow.js';
|
|
7
|
+
export type { FollowParams, FollowState } from './follow.js';
|
|
8
|
+
export { OrbitFollowBody, type OrbitFollowOptions } from './OrbitFollowBody.js';
|
|
9
|
+
export * as orbitFollow from './orbitFollow.js';
|
|
10
|
+
export type { OrbitFollowParams, OrbitFollowState, OrbitStyle, RecenteringTarget } from './orbitFollow.js';
|
|
11
|
+
export * as threeRing from './threeRing.js';
|
|
12
|
+
export type { Orbit, Orbits, ThreeRingState } from './threeRing.js';
|
|
13
|
+
export * as tracker from './tracker.js';
|
|
14
|
+
export type { TrackerParams, TrackerState } from './tracker.js';
|
|
15
|
+
export { PositionComposerBody } from './PositionComposerBody.js';
|
|
16
|
+
export * as positionComposer from './positionComposer.js';
|
|
17
|
+
export type { PositionComposerParams, PositionComposerState } from './positionComposer.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type Quat, type Vec3 } from 'math';
|
|
2
|
+
import type { CameraState } from '../CameraState.js';
|
|
3
|
+
import type { TargetPose } from '../TargetPose.js';
|
|
4
|
+
import type { DamperState, DampingConstant } from '../damping/damping.js';
|
|
5
|
+
import type { InputAxisParams } from '../input/axis.js';
|
|
6
|
+
import { InputAxis } from '../input/InputAxis.js';
|
|
7
|
+
import { type BindingMode } from './BindingModes.js';
|
|
8
|
+
import type { Orbits, ThreeRingState } from './threeRing.js';
|
|
9
|
+
import type { TrackerState } from './tracker.js';
|
|
10
|
+
export type OrbitFollowParams = {
|
|
11
|
+
/** Shape the camera moves on: a sphere of `radius`, or a surface through three `orbits`. */
|
|
12
|
+
orbitStyle: OrbitStyle;
|
|
13
|
+
/** Distance from the target while `radial` is `0`, for `sphere`. Changes ease in with `radial.damping`. */
|
|
14
|
+
radius: number;
|
|
15
|
+
/** Rings the `threeRing` surface passes through, from `vertical`'s minimum to its maximum. */
|
|
16
|
+
orbits: Orbits;
|
|
17
|
+
/** How strongly the `threeRing` surface curves between the rings, from `0` to `1`. */
|
|
18
|
+
splineCurvature: number;
|
|
19
|
+
/** Center of the orbit relative to the target, rotated according to `bindingMode`. */
|
|
20
|
+
targetOffset: Vec3;
|
|
21
|
+
/** Rotation frame the orbit is measured in. */
|
|
22
|
+
bindingMode: BindingMode;
|
|
23
|
+
/** Response time for following the target position. */
|
|
24
|
+
damping: DampingConstant;
|
|
25
|
+
/** Response time for turning with the target, for every `bindingMode` but `worldSpace`. */
|
|
26
|
+
rotationDamping: DampingConstant;
|
|
27
|
+
/** Maximum damping speed, in world units/sec. */
|
|
28
|
+
maxSpeed: number;
|
|
29
|
+
/** What `horizontal` recenters to: its `center`, or the side behind the target's forward. */
|
|
30
|
+
recenteringTarget: RecenteringTarget;
|
|
31
|
+
};
|
|
32
|
+
export type OrbitStyle = 'sphere' | 'threeRing';
|
|
33
|
+
export type RecenteringTarget = 'axisCenter' | 'trackingTarget';
|
|
34
|
+
/** Every setting from `settings`, or its default. */
|
|
35
|
+
export declare const createParams: (settings?: Partial<OrbitFollowParams>) => OrbitFollowParams;
|
|
36
|
+
/**
|
|
37
|
+
* `horizontal` (around the target, wraps ±180°) and `vertical` (elevation, or from the bottom to the top ring) in
|
|
38
|
+
* degrees, and `radial` as the natural log of the radius scale.
|
|
39
|
+
*/
|
|
40
|
+
export type OrbitFollowState = {
|
|
41
|
+
horizontal: InputAxis;
|
|
42
|
+
vertical: InputAxis;
|
|
43
|
+
radial: InputAxis;
|
|
44
|
+
radius: DamperState;
|
|
45
|
+
threeRing: ThreeRingState;
|
|
46
|
+
tracker: TrackerState;
|
|
47
|
+
/** Binding frame of the last `update`. */
|
|
48
|
+
orientation: Quat;
|
|
49
|
+
/** Position set by `prime`, applied once a target is available. */
|
|
50
|
+
primePosition: Vec3;
|
|
51
|
+
primed: boolean;
|
|
52
|
+
};
|
|
53
|
+
type AxisSettings = Partial<InputAxisParams>;
|
|
54
|
+
/** Default settings of each axis. Every axis starts at its `center`. */
|
|
55
|
+
export declare const createAxisSettings: () => {
|
|
56
|
+
horizontal: AxisSettings;
|
|
57
|
+
vertical: AxisSettings;
|
|
58
|
+
radial: AxisSettings;
|
|
59
|
+
};
|
|
60
|
+
export declare function createState(): OrbitFollowState;
|
|
61
|
+
/** Whether `update` will read `target.rotation` this frame. */
|
|
62
|
+
export declare const needsTargetRotation: (state: OrbitFollowState, params: OrbitFollowParams) => boolean;
|
|
63
|
+
/** Start the next update from `position`'s direction around the target. `radial` keeps its value. */
|
|
64
|
+
export declare function prime(state: OrbitFollowState, position: Vec3): void;
|
|
65
|
+
/** Where the camera would be at these axis values, around the tracked point and in the frame of the last `update`. */
|
|
66
|
+
export declare function point(out: Vec3, state: OrbitFollowState, params: OrbitFollowParams, horizontal: number, vertical: number): Vec3;
|
|
67
|
+
/** Eases `horizontal` and `vertical` toward `position`'s direction around the target. `radial` keeps its value. */
|
|
68
|
+
export declare function setFromPosition(state: OrbitFollowState, params: OrbitFollowParams, target: TargetPose, position: Vec3): void;
|
|
69
|
+
/** Eases `horizontal` and `vertical` so the camera looks along `rotation`'s forward at the target. */
|
|
70
|
+
export declare function setFromRotation(state: OrbitFollowState, params: OrbitFollowParams, target: TargetPose, rotation: Quat): void;
|
|
71
|
+
/**
|
|
72
|
+
* Advances the axes and places `out` on the orbit around the target. A `null` target leaves `out` as is.
|
|
73
|
+
* Returns `true` while an axis still has to move.
|
|
74
|
+
*/
|
|
75
|
+
export declare function update(out: CameraState, state: OrbitFollowState, params: OrbitFollowParams, target: TargetPose | null, dt: number, justActivated: boolean): boolean;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { createState as createState$1, damp, reset } from "../damping/damping.js";
|
|
3
|
+
import { withDefaults } from "../params.js";
|
|
4
|
+
import { shortestWrappedDelta } from "../input/shortestWrappedDelta.js";
|
|
5
|
+
import { InputAxis } from "../input/InputAxis.js";
|
|
6
|
+
import { BindingModes } from "./BindingModes.js";
|
|
7
|
+
import { safeFromToRotation } from "./safeFromToRotation.js";
|
|
8
|
+
import { createState as createState$2, needsTargetRotation as needsTargetRotation$1, referenceOrientation, reset as reset$1, trackTarget } from "./tracker.js";
|
|
9
|
+
import { createState as createState$3, point as point$1 } from "./threeRing.js";
|
|
10
|
+
import { clamp, degreesToRadians, quat, radiansToDegrees, vec3 } from "math";
|
|
11
|
+
//#region src/core/body/orbitFollow.ts
|
|
12
|
+
var orbitFollow_exports = /* @__PURE__ */ __exportAll({
|
|
13
|
+
createAxisSettings: () => createAxisSettings,
|
|
14
|
+
createParams: () => createParams,
|
|
15
|
+
createState: () => createState,
|
|
16
|
+
needsTargetRotation: () => needsTargetRotation,
|
|
17
|
+
point: () => point,
|
|
18
|
+
prime: () => prime,
|
|
19
|
+
setFromPosition: () => setFromPosition,
|
|
20
|
+
setFromRotation: () => setFromRotation,
|
|
21
|
+
update: () => update
|
|
22
|
+
});
|
|
23
|
+
/** Every setting from `settings`, or its default. */
|
|
24
|
+
var createParams = (settings) => withDefaults({
|
|
25
|
+
orbitStyle: "sphere",
|
|
26
|
+
radius: 10,
|
|
27
|
+
orbits: {
|
|
28
|
+
top: {
|
|
29
|
+
height: 10,
|
|
30
|
+
radius: 10
|
|
31
|
+
},
|
|
32
|
+
center: {
|
|
33
|
+
height: 0,
|
|
34
|
+
radius: 10
|
|
35
|
+
},
|
|
36
|
+
bottom: {
|
|
37
|
+
height: -10,
|
|
38
|
+
radius: 10
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
splineCurvature: 0,
|
|
42
|
+
targetOffset: [
|
|
43
|
+
0,
|
|
44
|
+
0,
|
|
45
|
+
0
|
|
46
|
+
],
|
|
47
|
+
bindingMode: BindingModes.worldSpace,
|
|
48
|
+
damping: 0,
|
|
49
|
+
rotationDamping: 0,
|
|
50
|
+
maxSpeed: Infinity,
|
|
51
|
+
recenteringTarget: "trackingTarget"
|
|
52
|
+
}, settings);
|
|
53
|
+
/** Default settings of each axis. Every axis starts at its `center`. */
|
|
54
|
+
var createAxisSettings = () => ({
|
|
55
|
+
horizontal: {
|
|
56
|
+
center: 0,
|
|
57
|
+
range: [-180, 180],
|
|
58
|
+
wrap: true
|
|
59
|
+
},
|
|
60
|
+
vertical: {
|
|
61
|
+
center: 0,
|
|
62
|
+
range: [-90, 90]
|
|
63
|
+
},
|
|
64
|
+
radial: {
|
|
65
|
+
center: 0,
|
|
66
|
+
range: [Math.log(.5), Math.log(2)]
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
function createState() {
|
|
70
|
+
const { horizontal, vertical, radial } = createAxisSettings();
|
|
71
|
+
return {
|
|
72
|
+
horizontal: new InputAxis({
|
|
73
|
+
...horizontal,
|
|
74
|
+
value: horizontal.center
|
|
75
|
+
}),
|
|
76
|
+
vertical: new InputAxis({
|
|
77
|
+
...vertical,
|
|
78
|
+
value: vertical.center
|
|
79
|
+
}),
|
|
80
|
+
radial: new InputAxis({
|
|
81
|
+
...radial,
|
|
82
|
+
value: radial.center
|
|
83
|
+
}),
|
|
84
|
+
radius: createState$1(),
|
|
85
|
+
threeRing: createState$3(),
|
|
86
|
+
tracker: createState$2(),
|
|
87
|
+
orientation: [
|
|
88
|
+
0,
|
|
89
|
+
0,
|
|
90
|
+
0,
|
|
91
|
+
1
|
|
92
|
+
],
|
|
93
|
+
primePosition: [
|
|
94
|
+
0,
|
|
95
|
+
0,
|
|
96
|
+
0
|
|
97
|
+
],
|
|
98
|
+
primed: false
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
var recentersBehindTarget = (state, params) => params.recenteringTarget === "trackingTarget" && state.horizontal.recentering.enabled;
|
|
102
|
+
/** Whether `update` will read `target.rotation` this frame. */
|
|
103
|
+
var needsTargetRotation = (state, params) => needsTargetRotation$1(state.tracker, params.bindingMode) || recentersBehindTarget(state, params);
|
|
104
|
+
/** Start the next update from `position`'s direction around the target. `radial` keeps its value. */
|
|
105
|
+
function prime(state, position) {
|
|
106
|
+
vec3.copy(state.primePosition, position);
|
|
107
|
+
state.primed = true;
|
|
108
|
+
}
|
|
109
|
+
var poleLimit = 89.999;
|
|
110
|
+
var worldUp = [
|
|
111
|
+
0,
|
|
112
|
+
1,
|
|
113
|
+
0
|
|
114
|
+
];
|
|
115
|
+
var forwardAxis = [
|
|
116
|
+
0,
|
|
117
|
+
0,
|
|
118
|
+
-1
|
|
119
|
+
];
|
|
120
|
+
var scratchEuler = [
|
|
121
|
+
0,
|
|
122
|
+
0,
|
|
123
|
+
0,
|
|
124
|
+
"yxz"
|
|
125
|
+
];
|
|
126
|
+
var scratchRotation = [
|
|
127
|
+
0,
|
|
128
|
+
0,
|
|
129
|
+
0,
|
|
130
|
+
1
|
|
131
|
+
];
|
|
132
|
+
var scratchOffset = [
|
|
133
|
+
0,
|
|
134
|
+
0,
|
|
135
|
+
0
|
|
136
|
+
];
|
|
137
|
+
var scratchOrientation = [
|
|
138
|
+
0,
|
|
139
|
+
0,
|
|
140
|
+
0,
|
|
141
|
+
1
|
|
142
|
+
];
|
|
143
|
+
var scratchInverse = [
|
|
144
|
+
0,
|
|
145
|
+
0,
|
|
146
|
+
0,
|
|
147
|
+
1
|
|
148
|
+
];
|
|
149
|
+
var backAxis = [
|
|
150
|
+
0,
|
|
151
|
+
0,
|
|
152
|
+
1
|
|
153
|
+
];
|
|
154
|
+
var scratchDirection = [
|
|
155
|
+
0,
|
|
156
|
+
0,
|
|
157
|
+
0
|
|
158
|
+
];
|
|
159
|
+
var scratchWorld = [
|
|
160
|
+
0,
|
|
161
|
+
0,
|
|
162
|
+
0
|
|
163
|
+
];
|
|
164
|
+
var scratchAxes = [0, 0];
|
|
165
|
+
var scratchPreviousOffset = [
|
|
166
|
+
0,
|
|
167
|
+
0,
|
|
168
|
+
0
|
|
169
|
+
];
|
|
170
|
+
/** Where `value` is within `axis`' range, from `0` to `1`. */
|
|
171
|
+
function normalize(axis, value) {
|
|
172
|
+
const range = axis.range;
|
|
173
|
+
if (!range || range[1] <= range[0]) return .5;
|
|
174
|
+
return clamp((value - range[0]) / (range[1] - range[0]), 0, 1);
|
|
175
|
+
}
|
|
176
|
+
/** The camera's offset from the tracked point at these axis values, in the binding frame. */
|
|
177
|
+
function orbitOffset(out, state, params, horizontal, vertical) {
|
|
178
|
+
const scale = Math.exp(state.radial.value);
|
|
179
|
+
if (params.orbitStyle === "threeRing") {
|
|
180
|
+
const t = normalize(state.vertical, vertical);
|
|
181
|
+
point$1(out, state.threeRing, params.orbits, params.splineCurvature, t);
|
|
182
|
+
vec3.scale(out, out, scale);
|
|
183
|
+
quat.setAxisAngle(scratchRotation, worldUp, -degreesToRadians(horizontal));
|
|
184
|
+
} else {
|
|
185
|
+
scratchEuler[0] = -degreesToRadians(clamp(vertical, -89.999, poleLimit));
|
|
186
|
+
scratchEuler[1] = -degreesToRadians(horizontal);
|
|
187
|
+
quat.fromEuler(scratchRotation, scratchEuler);
|
|
188
|
+
vec3.set(out, 0, 0, state.radius.value * scale);
|
|
189
|
+
}
|
|
190
|
+
return vec3.transformQuat(out, out, scratchRotation);
|
|
191
|
+
}
|
|
192
|
+
/** Where the camera would be at these axis values, around the tracked point and in the frame of the last `update`. */
|
|
193
|
+
function point(out, state, params, horizontal, vertical) {
|
|
194
|
+
orbitOffset(out, state, params, horizontal, vertical);
|
|
195
|
+
vec3.transformQuat(out, out, state.orientation);
|
|
196
|
+
return vec3.add(out, out, state.tracker.trackedPoint);
|
|
197
|
+
}
|
|
198
|
+
function directionFrom(out, state, params, target, position) {
|
|
199
|
+
referenceOrientation(scratchOrientation, state.tracker, params.bindingMode, target);
|
|
200
|
+
vec3.add(out, target.position, vec3.transformQuat(out, params.targetOffset, scratchOrientation));
|
|
201
|
+
return vec3.subtract(out, position, out);
|
|
202
|
+
}
|
|
203
|
+
/** The `horizontal` and `vertical` values that put the camera along world `direction` from the orbit's center. */
|
|
204
|
+
function axesAlong(state, params, target, direction) {
|
|
205
|
+
referenceOrientation(scratchOrientation, state.tracker, params.bindingMode, target);
|
|
206
|
+
vec3.transformQuat(scratchDirection, direction, quat.conjugate(scratchInverse, scratchOrientation));
|
|
207
|
+
const x = scratchDirection[0];
|
|
208
|
+
const y = scratchDirection[1];
|
|
209
|
+
const z = scratchDirection[2];
|
|
210
|
+
if (x * x + y * y + z * z < 1e-12) return null;
|
|
211
|
+
scratchAxes[0] = radiansToDegrees(Math.atan2(-x, z));
|
|
212
|
+
const elevation = Math.atan2(y, Math.hypot(x, z));
|
|
213
|
+
const range = state.vertical.range;
|
|
214
|
+
if (params.orbitStyle !== "threeRing") scratchAxes[1] = radiansToDegrees(elevation);
|
|
215
|
+
else if (range) scratchAxes[1] = range[0] + closestOrbitPoint(state, params, elevation) * (range[1] - range[0]);
|
|
216
|
+
else scratchAxes[1] = state.vertical.value;
|
|
217
|
+
return scratchAxes;
|
|
218
|
+
}
|
|
219
|
+
function easeAxesTo(state, axes) {
|
|
220
|
+
if (!axes) return;
|
|
221
|
+
const { horizontal, vertical } = state;
|
|
222
|
+
const wrapped = horizontal.wrap && horizontal.range;
|
|
223
|
+
horizontal.applyDelta(wrapped ? shortestWrappedDelta(horizontal.rawValue, axes[0], wrapped) : axes[0] - horizontal.rawValue);
|
|
224
|
+
vertical.applyDelta(axes[1] - vertical.rawValue);
|
|
225
|
+
}
|
|
226
|
+
/** Eases `horizontal` and `vertical` toward `position`'s direction around the target. `radial` keeps its value. */
|
|
227
|
+
function setFromPosition(state, params, target, position) {
|
|
228
|
+
easeAxesTo(state, axesAlong(state, params, target, directionFrom(scratchWorld, state, params, target, position)));
|
|
229
|
+
}
|
|
230
|
+
/** Eases `horizontal` and `vertical` so the camera looks along `rotation`'s forward at the target. */
|
|
231
|
+
function setFromRotation(state, params, target, rotation) {
|
|
232
|
+
easeAxesTo(state, axesAlong(state, params, target, vec3.transformQuat(scratchWorld, backAxis, rotation)));
|
|
233
|
+
}
|
|
234
|
+
function primeAxes(state, params, target, position) {
|
|
235
|
+
const axes = axesAlong(state, params, target, directionFrom(scratchWorld, state, params, target, position));
|
|
236
|
+
if (!axes) return;
|
|
237
|
+
state.horizontal.setValue(axes[0]);
|
|
238
|
+
state.vertical.setValue(axes[1]);
|
|
239
|
+
}
|
|
240
|
+
function elevationError(state, params, t, elevation) {
|
|
241
|
+
point$1(scratchDirection, state.threeRing, params.orbits, params.splineCurvature, t);
|
|
242
|
+
return Math.abs(Math.atan2(scratchDirection[1], scratchDirection[2]) - elevation);
|
|
243
|
+
}
|
|
244
|
+
/** Where between the bottom (`0`) and top (`1`) ring the direction from the target is closest to `elevation`. */
|
|
245
|
+
function closestOrbitPoint(state, params, elevation) {
|
|
246
|
+
const samples = 32;
|
|
247
|
+
let best = 0;
|
|
248
|
+
let bestError = Infinity;
|
|
249
|
+
for (let i = 0; i <= samples; i++) {
|
|
250
|
+
const error = elevationError(state, params, i / samples, elevation);
|
|
251
|
+
if (error < bestError) {
|
|
252
|
+
bestError = error;
|
|
253
|
+
best = i / samples;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
for (let step = .5 / samples; step > 1e-7; step /= 2) {
|
|
257
|
+
const below = clamp(best - step, 0, 1);
|
|
258
|
+
const above = clamp(best + step, 0, 1);
|
|
259
|
+
const belowError = elevationError(state, params, below, elevation);
|
|
260
|
+
const aboveError = elevationError(state, params, above, elevation);
|
|
261
|
+
if (belowError < bestError && belowError <= aboveError) {
|
|
262
|
+
best = below;
|
|
263
|
+
bestError = belowError;
|
|
264
|
+
} else if (aboveError < bestError) {
|
|
265
|
+
best = above;
|
|
266
|
+
bestError = aboveError;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return best;
|
|
270
|
+
}
|
|
271
|
+
function centerBehindTarget(state, params, target) {
|
|
272
|
+
if (!target.hasRotation) return;
|
|
273
|
+
referenceOrientation(scratchOrientation, state.tracker, params.bindingMode, target);
|
|
274
|
+
vec3.transformQuat(scratchDirection, forwardAxis, target.rotation);
|
|
275
|
+
vec3.transformQuat(scratchDirection, scratchDirection, quat.conjugate(scratchInverse, scratchOrientation));
|
|
276
|
+
const x = scratchDirection[0];
|
|
277
|
+
const z = scratchDirection[2];
|
|
278
|
+
if (x * x + z * z < 1e-12) return;
|
|
279
|
+
state.horizontal.center = radiansToDegrees(Math.atan2(x, -z));
|
|
280
|
+
}
|
|
281
|
+
var isActive = (axis) => axis.held || axis.hadDelta;
|
|
282
|
+
function shareInput(axis, other, otherActive) {
|
|
283
|
+
if (otherActive && other.recentering.time === axis.recentering.time) axis.hadDelta = true;
|
|
284
|
+
}
|
|
285
|
+
/** Input on one axis restarts the recentering wait of every axis with the same `recentering.time`. */
|
|
286
|
+
function syncRecentering({ horizontal, vertical, radial }) {
|
|
287
|
+
const h = isActive(horizontal);
|
|
288
|
+
const v = isActive(vertical);
|
|
289
|
+
const r = isActive(radial);
|
|
290
|
+
shareInput(horizontal, vertical, v);
|
|
291
|
+
shareInput(horizontal, radial, r);
|
|
292
|
+
shareInput(vertical, horizontal, h);
|
|
293
|
+
shareInput(vertical, radial, r);
|
|
294
|
+
shareInput(radial, horizontal, h);
|
|
295
|
+
shareInput(radial, vertical, v);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Advances the axes and places `out` on the orbit around the target. A `null` target leaves `out` as is.
|
|
299
|
+
* Returns `true` while an axis still has to move.
|
|
300
|
+
*/
|
|
301
|
+
function update(out, state, params, target, dt, justActivated) {
|
|
302
|
+
quat.identity(out.rotationDampingBypass);
|
|
303
|
+
if (justActivated) {
|
|
304
|
+
reset$1(state.tracker);
|
|
305
|
+
reset(state.radius);
|
|
306
|
+
state.horizontal.idleTime = 0;
|
|
307
|
+
state.vertical.idleTime = 0;
|
|
308
|
+
state.radial.idleTime = 0;
|
|
309
|
+
}
|
|
310
|
+
if (target && recentersBehindTarget(state, params)) centerBehindTarget(state, params, target);
|
|
311
|
+
syncRecentering(state);
|
|
312
|
+
const horizontalMoving = state.horizontal.update(dt);
|
|
313
|
+
const verticalMoving = state.vertical.update(dt);
|
|
314
|
+
const radialMoving = state.radial.update(dt);
|
|
315
|
+
const radius = damp(state.radius, params.radius, state.radial.damping, dt).value;
|
|
316
|
+
const moving = horizontalMoving || verticalMoving || radialMoving || radius !== params.radius;
|
|
317
|
+
if (!target) return moving;
|
|
318
|
+
if (state.primed) {
|
|
319
|
+
state.primed = false;
|
|
320
|
+
primeAxes(state, params, target, state.primePosition);
|
|
321
|
+
}
|
|
322
|
+
orbitOffset(scratchOffset, state, params, state.horizontal.value, state.vertical.value);
|
|
323
|
+
const hadPrevious = state.tracker.hasPrevious;
|
|
324
|
+
vec3.copy(scratchPreviousOffset, state.tracker.previousOffset);
|
|
325
|
+
trackTarget(out.target, state.orientation, state.tracker, params, target, scratchOffset, params.targetOffset, dt);
|
|
326
|
+
vec3.add(out.position, out.target, vec3.transformQuat(scratchOffset, scratchOffset, state.orientation));
|
|
327
|
+
out.hasTarget = true;
|
|
328
|
+
vec3.transformQuat(out.referenceUp, worldUp, state.orientation);
|
|
329
|
+
if (hadPrevious) {
|
|
330
|
+
vec3.transformQuat(scratchPreviousOffset, scratchPreviousOffset, state.orientation);
|
|
331
|
+
safeFromToRotation(out.rotationDampingBypass, scratchPreviousOffset, scratchOffset, out.referenceUp);
|
|
332
|
+
}
|
|
333
|
+
return moving;
|
|
334
|
+
}
|
|
335
|
+
//#endregion
|
|
336
|
+
export { createAxisSettings, createParams, createState, needsTargetRotation, orbitFollow_exports, point, prime, setFromPosition, setFromRotation, update };
|