@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,39 @@
|
|
|
1
|
+
import { vec3 } from "math";
|
|
2
|
+
//#region src/three/camera.ts
|
|
3
|
+
/** Read a perspective camera's transform and lens into `out`. */
|
|
4
|
+
function copyCameraStateFromCamera(out, camera) {
|
|
5
|
+
camera.position.toArray(out.position);
|
|
6
|
+
camera.quaternion.toArray(out.quaternion);
|
|
7
|
+
out.fov = camera.fov;
|
|
8
|
+
out.near = camera.near;
|
|
9
|
+
out.far = camera.far;
|
|
10
|
+
out.viewOffset[0] = camera.view?.enabled ? -camera.view.offsetX / (camera.view.fullWidth / 2) : 0;
|
|
11
|
+
out.viewOffset[1] = camera.view?.enabled ? camera.view.offsetY / (camera.view.fullHeight / 2) : 0;
|
|
12
|
+
out.hasTarget = false;
|
|
13
|
+
out.hasLookAtTarget = false;
|
|
14
|
+
vec3.set(out.referenceUp, 0, 1, 0);
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
/** Write a camera state's position and rotation to a camera. */
|
|
18
|
+
function writeCameraTransform(camera, state) {
|
|
19
|
+
camera.position.fromArray(state.position);
|
|
20
|
+
camera.quaternion.fromArray(state.quaternion);
|
|
21
|
+
}
|
|
22
|
+
/** Write a camera state's lens and view offset to a perspective camera. */
|
|
23
|
+
function writeCameraLens(camera, state, viewportWidth, viewportHeight) {
|
|
24
|
+
camera.fov = state.fov;
|
|
25
|
+
camera.near = state.near;
|
|
26
|
+
camera.far = state.far;
|
|
27
|
+
if (state.viewOffset[0] !== 0 || state.viewOffset[1] !== 0) {
|
|
28
|
+
const offsetX = -state.viewOffset[0] * (viewportWidth / 2);
|
|
29
|
+
const offsetY = state.viewOffset[1] * (viewportHeight / 2);
|
|
30
|
+
camera.setViewOffset(viewportWidth, viewportHeight, offsetX, offsetY, viewportWidth, viewportHeight);
|
|
31
|
+
} else camera.clearViewOffset();
|
|
32
|
+
}
|
|
33
|
+
/** Apply a camera state to a perspective camera. */
|
|
34
|
+
function applyCameraState(camera, state, viewportWidth, viewportHeight) {
|
|
35
|
+
writeCameraTransform(camera, state);
|
|
36
|
+
writeCameraLens(camera, state, viewportWidth, viewportHeight);
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { applyCameraState, copyCameraStateFromCamera, writeCameraLens, writeCameraTransform };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Vector3 } from 'three';
|
|
2
|
+
import * as predictor from '../../core/damping/predictor.js';
|
|
3
|
+
/** Stateful wrapper over the predictor functions for three.js vectors. */
|
|
4
|
+
export declare class Predictor {
|
|
5
|
+
readonly state: predictor.PredictorState;
|
|
6
|
+
/** Add a position sample and update the tracked velocity. */
|
|
7
|
+
addPosition(position: Vector3, dt: number, smoothing: number): void;
|
|
8
|
+
/** Write the predicted offset `time` seconds ahead into `out`. */
|
|
9
|
+
predictPositionDelta(out: Vector3, time: number): Vector3;
|
|
10
|
+
/** Clear the tracked velocity and position history. */
|
|
11
|
+
reset(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { addPosition, create, predictDelta, reset } from "../../core/damping/predictor.js";
|
|
2
|
+
//#region src/three/damping/Predictor.ts
|
|
3
|
+
var scratchPosition = [
|
|
4
|
+
0,
|
|
5
|
+
0,
|
|
6
|
+
0
|
|
7
|
+
];
|
|
8
|
+
var scratchDelta = [
|
|
9
|
+
0,
|
|
10
|
+
0,
|
|
11
|
+
0
|
|
12
|
+
];
|
|
13
|
+
/** Stateful wrapper over the predictor functions for three.js vectors. */
|
|
14
|
+
var Predictor = class {
|
|
15
|
+
state = create();
|
|
16
|
+
/** Add a position sample and update the tracked velocity. */
|
|
17
|
+
addPosition(position, dt, smoothing) {
|
|
18
|
+
addPosition(this.state, position.toArray(scratchPosition), dt, smoothing);
|
|
19
|
+
}
|
|
20
|
+
/** Write the predicted offset `time` seconds ahead into `out`. */
|
|
21
|
+
predictPositionDelta(out, time) {
|
|
22
|
+
return out.fromArray(predictDelta(scratchDelta, this.state, time));
|
|
23
|
+
}
|
|
24
|
+
/** Clear the tracked velocity and position history. */
|
|
25
|
+
reset() {
|
|
26
|
+
reset(this.state);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { Predictor };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Quaternion } from 'three';
|
|
2
|
+
import * as damping from '../../core/damping/damping.js';
|
|
3
|
+
import type { DampingConstant } from '../../core/damping/damping.js';
|
|
4
|
+
/** Stateful wrapper over `dampQuaternion` for three.js quaternions. */
|
|
5
|
+
export declare class QuaternionDamper {
|
|
6
|
+
readonly state: damping.DamperState;
|
|
7
|
+
update(out: Quaternion, target: Quaternion, dampingTime: DampingConstant, dt: number, maxSpeed?: number): Quaternion;
|
|
8
|
+
/** Reset the underlying angle spring. */
|
|
9
|
+
reset(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createState, dampQuaternion, reset } from "../../core/damping/damping.js";
|
|
2
|
+
//#region src/three/damping/QuaternionDamper.ts
|
|
3
|
+
var scratchOut = [
|
|
4
|
+
0,
|
|
5
|
+
0,
|
|
6
|
+
0,
|
|
7
|
+
1
|
|
8
|
+
];
|
|
9
|
+
var scratchTarget = [
|
|
10
|
+
0,
|
|
11
|
+
0,
|
|
12
|
+
0,
|
|
13
|
+
1
|
|
14
|
+
];
|
|
15
|
+
/** Stateful wrapper over `dampQuaternion` for three.js quaternions. */
|
|
16
|
+
var QuaternionDamper = class {
|
|
17
|
+
state = createState();
|
|
18
|
+
update(out, target, dampingTime, dt, maxSpeed = Infinity) {
|
|
19
|
+
dampQuaternion(this.state, out.toArray(scratchOut), target.toArray(scratchTarget), dampingTime, dt, maxSpeed);
|
|
20
|
+
return out.fromArray(scratchOut);
|
|
21
|
+
}
|
|
22
|
+
/** Reset the underlying angle spring. */
|
|
23
|
+
reset() {
|
|
24
|
+
reset(this.state);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { QuaternionDamper };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Vector3 } from 'three';
|
|
2
|
+
import * as damping from '../../core/damping/damping.js';
|
|
3
|
+
import type { DampingConstant } from '../../core/damping/damping.js';
|
|
4
|
+
/** Stateful wrapper over `dampVector3` for three.js vectors. */
|
|
5
|
+
export declare class Vector3Damper {
|
|
6
|
+
readonly state: damping.Vector3DamperState;
|
|
7
|
+
update(out: Vector3, target: Vector3, dampingTime: DampingConstant, dt: number, maxSpeed?: number): Vector3;
|
|
8
|
+
/** Reset all three component dampers. */
|
|
9
|
+
reset(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createVector3State, dampVector3, resetVector3 } from "../../core/damping/damping.js";
|
|
2
|
+
//#region src/three/damping/Vector3Damper.ts
|
|
3
|
+
var scratchOut = [
|
|
4
|
+
0,
|
|
5
|
+
0,
|
|
6
|
+
0
|
|
7
|
+
];
|
|
8
|
+
var scratchTarget = [
|
|
9
|
+
0,
|
|
10
|
+
0,
|
|
11
|
+
0
|
|
12
|
+
];
|
|
13
|
+
/** Stateful wrapper over `dampVector3` for three.js vectors. */
|
|
14
|
+
var Vector3Damper = class {
|
|
15
|
+
state = createVector3State();
|
|
16
|
+
update(out, target, dampingTime, dt, maxSpeed = Infinity) {
|
|
17
|
+
dampVector3(this.state, out.toArray(scratchOut), target.toArray(scratchTarget), dampingTime, dt, maxSpeed);
|
|
18
|
+
return out.fromArray(scratchOut);
|
|
19
|
+
}
|
|
20
|
+
/** Reset all three component dampers. */
|
|
21
|
+
reset() {
|
|
22
|
+
resetVector3(this.state);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Vector3Damper };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GroupFramingFitMode, GroupFramingMode, GroupMember } from '../../core/extension/groupFraming.js';
|
|
2
|
+
import { GroupFramingExtension, type GroupFramingOptions } from '../../core/extension/GroupFramingExtension.js';
|
|
3
|
+
import type { TargetGroup } from './TargetGroup.js';
|
|
4
|
+
export type { GroupFramingFitMode, GroupFramingMode, GroupFramingOptions };
|
|
5
|
+
/** Keeps a `TargetGroup` of `Object3D`s, refs and points inside the camera frame. */
|
|
6
|
+
export declare class GroupFramingExtensionThree extends GroupFramingExtension {
|
|
7
|
+
group: TargetGroup;
|
|
8
|
+
private forceSizeRecalculation;
|
|
9
|
+
constructor(group: TargetGroup, options?: GroupFramingOptions);
|
|
10
|
+
/** Re-measure member sizes on the next update. */
|
|
11
|
+
recalculateSize(): void;
|
|
12
|
+
protected readMembers(): readonly GroupMember[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GroupFramingExtension } from "../../core/extension/GroupFramingExtension.js";
|
|
2
|
+
//#region src/three/extension/GroupFramingExtensionThree.ts
|
|
3
|
+
/** Keeps a `TargetGroup` of `Object3D`s, refs and points inside the camera frame. */
|
|
4
|
+
var GroupFramingExtensionThree = class extends GroupFramingExtension {
|
|
5
|
+
group;
|
|
6
|
+
forceSizeRecalculation = false;
|
|
7
|
+
constructor(group, options) {
|
|
8
|
+
super([], group.positionMode, options);
|
|
9
|
+
this.group = group;
|
|
10
|
+
}
|
|
11
|
+
/** Re-measure member sizes on the next update. */
|
|
12
|
+
recalculateSize() {
|
|
13
|
+
this.forceSizeRecalculation = true;
|
|
14
|
+
}
|
|
15
|
+
readMembers() {
|
|
16
|
+
this.positionMode = this.group.positionMode;
|
|
17
|
+
const members = this.group.resolveMembers(this.forceSizeRecalculation);
|
|
18
|
+
this.forceSizeRecalculation = false;
|
|
19
|
+
return members;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { GroupFramingExtensionThree };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
|
+
import type { GroupMember, GroupPositionMode } from '../../core/extension/groupFraming.js';
|
|
3
|
+
import type { Vector3Like } from '../resolve/resolveVector3.js';
|
|
4
|
+
import { type Target } from '../resolve/Target.js';
|
|
5
|
+
import type { TargetSlot } from '../resolve/TargetRegistry.js';
|
|
6
|
+
export type TargetGroupMember = {
|
|
7
|
+
target: Target;
|
|
8
|
+
/** Position weight used by `groupAverage`. */
|
|
9
|
+
weight?: number;
|
|
10
|
+
/** Bounding-sphere radius. Ignored when `size` is set. */
|
|
11
|
+
radius?: number;
|
|
12
|
+
/** Bounding-box dimensions. Takes priority over `radius`. */
|
|
13
|
+
size?: Vector3Like;
|
|
14
|
+
};
|
|
15
|
+
/** Strategy used to compute the group's position. */
|
|
16
|
+
export type TargetGroupPositionMode = GroupPositionMode;
|
|
17
|
+
/** Combines multiple targets into one position and bound. */
|
|
18
|
+
export declare class TargetGroup {
|
|
19
|
+
members: TargetGroupMember[];
|
|
20
|
+
positionMode: TargetGroupPositionMode;
|
|
21
|
+
/** Registry slots by member target; members without one are resolved directly. */
|
|
22
|
+
memberSlots: ReadonlyMap<Target, TargetSlot>;
|
|
23
|
+
private readonly resolved;
|
|
24
|
+
constructor(members?: TargetGroupMember[], positionMode?: TargetGroupPositionMode);
|
|
25
|
+
slotOf: (member: TargetGroupMember) => TargetSlot | null;
|
|
26
|
+
/** Resolve a member's dimensions. */
|
|
27
|
+
resolveMemberSize: (outSize: Vector3, member: TargetGroupMember, dynamicSize?: boolean) => boolean;
|
|
28
|
+
/** Resolve every member's position and extent for this frame, as plain data for the core. */
|
|
29
|
+
resolveMembers: (dynamicSize?: boolean) => readonly GroupMember[];
|
|
30
|
+
/** Write the group position and return a conservative enclosing radius. */
|
|
31
|
+
computeBounds: (outPosition: Vector3, dynamicSize?: boolean) => number;
|
|
32
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { computeBounds, createMember } from "../../core/extension/groupFraming.js";
|
|
2
|
+
import { resolveTargetPosition, resolveTargetSize } from "../resolve/Target.js";
|
|
3
|
+
import { readTargetExtent } from "../readTargetExtent.js";
|
|
4
|
+
import { Vector3 } from "three";
|
|
5
|
+
//#region src/three/extension/TargetGroup.ts
|
|
6
|
+
var scratchPosition = new Vector3();
|
|
7
|
+
var scratchCenter = [
|
|
8
|
+
0,
|
|
9
|
+
0,
|
|
10
|
+
0
|
|
11
|
+
];
|
|
12
|
+
var noSlots = /* @__PURE__ */ new Map();
|
|
13
|
+
/** Combines multiple targets into one position and bound. */
|
|
14
|
+
var TargetGroup = class {
|
|
15
|
+
members;
|
|
16
|
+
positionMode;
|
|
17
|
+
/** Registry slots by member target; members without one are resolved directly. */
|
|
18
|
+
memberSlots = noSlots;
|
|
19
|
+
resolved = [];
|
|
20
|
+
constructor(members = [], positionMode = "groupCenter") {
|
|
21
|
+
this.members = members;
|
|
22
|
+
this.positionMode = positionMode;
|
|
23
|
+
}
|
|
24
|
+
slotOf = (member) => this.memberSlots.get(member.target) ?? null;
|
|
25
|
+
/** Resolve a member's dimensions. */
|
|
26
|
+
resolveMemberSize = (outSize, member, dynamicSize = false) => resolveTargetSize(outSize, member.target, member.size, member.radius, dynamicSize, this.slotOf(member));
|
|
27
|
+
/** Resolve every member's position and extent for this frame, as plain data for the core. */
|
|
28
|
+
resolveMembers = (dynamicSize = false) => {
|
|
29
|
+
const count = this.members.length;
|
|
30
|
+
while (this.resolved.length < count) this.resolved.push(createMember());
|
|
31
|
+
this.resolved.length = count;
|
|
32
|
+
for (let i = 0; i < count; i++) {
|
|
33
|
+
const member = this.members[i];
|
|
34
|
+
const out = this.resolved[i];
|
|
35
|
+
const slot = this.slotOf(member);
|
|
36
|
+
out.weight = member.weight ?? 1;
|
|
37
|
+
out.resolved = resolveTargetPosition(scratchPosition, member.target, slot);
|
|
38
|
+
if (!out.resolved) continue;
|
|
39
|
+
scratchPosition.toArray(out.position);
|
|
40
|
+
readTargetExtent(out.extent, member.target, member.size, member.radius, dynamicSize, slot);
|
|
41
|
+
}
|
|
42
|
+
return this.resolved;
|
|
43
|
+
};
|
|
44
|
+
/** Write the group position and return a conservative enclosing radius. */
|
|
45
|
+
computeBounds = (outPosition, dynamicSize = false) => {
|
|
46
|
+
const radius = computeBounds(scratchCenter, this.resolveMembers(dynamicSize), this.positionMode);
|
|
47
|
+
if (radius < 0) return 0;
|
|
48
|
+
outPosition.fromArray(scratchCenter);
|
|
49
|
+
return radius;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { TargetGroup };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { applyCameraState, copyCameraStateFromCamera, writeCameraLens, writeCameraTransform } from './camera.js';
|
|
2
|
+
export { CameraFrustumHelperThree } from './CameraFrustumHelperThree.js';
|
|
3
|
+
export { KlippThree, type FrameUpdate, type KlippMode, type KlippThreeOptions } from './KlippThree.js';
|
|
4
|
+
export { readTargetExtent } from './readTargetExtent.js';
|
|
5
|
+
export { readTargetPose, readTargetRotation } from './readTargetPose.js';
|
|
6
|
+
export { isVector3Like, resolveVec3, resolveVector3, type Vector3Like } from './resolve/resolveVector3.js';
|
|
7
|
+
export { resolveTargetPosition, resolveTargetRotation, resolveTargetSize, type RefLike, type Target, } from './resolve/Target.js';
|
|
8
|
+
export { TargetRegistry, type RegisteredTarget, type TargetSlot } from './resolve/TargetRegistry.js';
|
|
9
|
+
export { VirtualCameraThree, type CameraPiece, type InitialCameraState, type VirtualCameraThreeOptions, } from './VirtualCameraThree.js';
|
|
10
|
+
export { Predictor } from './damping/Predictor.js';
|
|
11
|
+
export { QuaternionDamper } from './damping/QuaternionDamper.js';
|
|
12
|
+
export { Vector3Damper } from './damping/Vector3Damper.js';
|
|
13
|
+
export { FollowBodyThree, type FollowThreeOptions } from './body/FollowBodyThree.js';
|
|
14
|
+
export { HardLockToTargetBodyThree, type HardLockToTargetOptions } from './body/HardLockToTargetBodyThree.js';
|
|
15
|
+
export { OrbitFollowBodyThree, type OrbitFollowThreeOptions } from './body/OrbitFollowBodyThree.js';
|
|
16
|
+
export { OrbitFollowHelperThree } from './body/OrbitFollowHelperThree.js';
|
|
17
|
+
export { PositionComposerBodyThree, type PositionComposerThreeOptions } from './body/PositionComposerBodyThree.js';
|
|
18
|
+
export { HardLookAtAimThree } from './aim/HardLookAtAimThree.js';
|
|
19
|
+
export { PanTiltAimThree } from './aim/PanTiltAimThree.js';
|
|
20
|
+
export { RotateWithFollowTargetAimThree, type RotateWithFollowTargetOptions, } from './aim/RotateWithFollowTargetAimThree.js';
|
|
21
|
+
export { RotationComposerAimThree, type RotationComposerThreeOptions } from './aim/RotationComposerAimThree.js';
|
|
22
|
+
export { GroupFramingExtensionThree, type GroupFramingFitMode, type GroupFramingMode, type GroupFramingOptions, } from './extension/GroupFramingExtensionThree.js';
|
|
23
|
+
export { TargetGroup, type TargetGroupMember, type TargetGroupPositionMode } from './extension/TargetGroup.js';
|
|
24
|
+
export { BasicMultiChannelPerlinNoiseThree, type PerlinNoiseThreeOptions, } from './noise/BasicMultiChannelPerlinNoiseThree.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { applyCameraState, copyCameraStateFromCamera, writeCameraLens, writeCameraTransform } from "./camera.js";
|
|
2
|
+
import { CameraFrustumHelperThree } from "./CameraFrustumHelperThree.js";
|
|
3
|
+
import { isVector3Like, resolveVec3, resolveVector3 } from "./resolve/resolveVector3.js";
|
|
4
|
+
import { resolveTargetPosition, resolveTargetRotation, resolveTargetSize } from "./resolve/Target.js";
|
|
5
|
+
import { readTargetExtent } from "./readTargetExtent.js";
|
|
6
|
+
import { TargetGroup } from "./extension/TargetGroup.js";
|
|
7
|
+
import { VirtualCameraThree } from "./VirtualCameraThree.js";
|
|
8
|
+
import { TargetRegistry } from "./resolve/TargetRegistry.js";
|
|
9
|
+
import { KlippThree } from "./KlippThree.js";
|
|
10
|
+
import { readTargetPose, readTargetRotation } from "./readTargetPose.js";
|
|
11
|
+
import { Predictor } from "./damping/Predictor.js";
|
|
12
|
+
import { QuaternionDamper } from "./damping/QuaternionDamper.js";
|
|
13
|
+
import { Vector3Damper } from "./damping/Vector3Damper.js";
|
|
14
|
+
import { FollowBodyThree } from "./body/FollowBodyThree.js";
|
|
15
|
+
import { HardLockToTargetBodyThree } from "./body/HardLockToTargetBodyThree.js";
|
|
16
|
+
import { OrbitFollowBodyThree } from "./body/OrbitFollowBodyThree.js";
|
|
17
|
+
import { OrbitFollowHelperThree } from "./body/OrbitFollowHelperThree.js";
|
|
18
|
+
import { PositionComposerBodyThree } from "./body/PositionComposerBodyThree.js";
|
|
19
|
+
import { HardLookAtAimThree } from "./aim/HardLookAtAimThree.js";
|
|
20
|
+
import { PanTiltAimThree } from "./aim/PanTiltAimThree.js";
|
|
21
|
+
import { RotateWithFollowTargetAimThree } from "./aim/RotateWithFollowTargetAimThree.js";
|
|
22
|
+
import { RotationComposerAimThree } from "./aim/RotationComposerAimThree.js";
|
|
23
|
+
import { GroupFramingExtensionThree } from "./extension/GroupFramingExtensionThree.js";
|
|
24
|
+
import { BasicMultiChannelPerlinNoiseThree } from "./noise/BasicMultiChannelPerlinNoiseThree.js";
|
|
25
|
+
export { BasicMultiChannelPerlinNoiseThree, CameraFrustumHelperThree, FollowBodyThree, GroupFramingExtensionThree, HardLockToTargetBodyThree, HardLookAtAimThree, KlippThree, OrbitFollowBodyThree, OrbitFollowHelperThree, PanTiltAimThree, PositionComposerBodyThree, Predictor, QuaternionDamper, RotateWithFollowTargetAimThree, RotationComposerAimThree, TargetGroup, TargetRegistry, Vector3Damper, VirtualCameraThree, applyCameraState, copyCameraStateFromCamera, isVector3Like, readTargetExtent, readTargetPose, readTargetRotation, resolveTargetPosition, resolveTargetRotation, resolveTargetSize, resolveVec3, resolveVector3, writeCameraLens, writeCameraTransform };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BasicMultiChannelPerlinNoise, type PerlinNoiseOptions as PerlinNoiseCoreOptions } from '../../core/noise/BasicMultiChannelPerlinNoise.js';
|
|
2
|
+
import { type Vector3Like } from '../resolve/resolveVector3.js';
|
|
3
|
+
export type PerlinNoiseThreeOptions = Omit<PerlinNoiseCoreOptions, 'positionAmplitude' | 'positionFrequency' | 'rotationAmplitude' | 'rotationFrequency'> & {
|
|
4
|
+
/** Per-axis positional shake amplitude in camera-local space. */
|
|
5
|
+
positionAmplitude?: Vector3Like;
|
|
6
|
+
/** Per-axis oscillation speed for position noise. */
|
|
7
|
+
positionFrequency?: Vector3Like;
|
|
8
|
+
/** Per-axis rotational shake amplitude in degrees. */
|
|
9
|
+
rotationAmplitude?: Vector3Like;
|
|
10
|
+
/** Per-axis oscillation speed for rotation noise. */
|
|
11
|
+
rotationFrequency?: Vector3Like;
|
|
12
|
+
};
|
|
13
|
+
/** `BasicMultiChannelPerlinNoise` taking three.js vectors in its options. */
|
|
14
|
+
export declare class BasicMultiChannelPerlinNoiseThree extends BasicMultiChannelPerlinNoise {
|
|
15
|
+
constructor({ positionAmplitude, positionFrequency, rotationAmplitude, rotationFrequency, ...options }?: PerlinNoiseThreeOptions);
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BasicMultiChannelPerlinNoise } from "../../core/noise/BasicMultiChannelPerlinNoise.js";
|
|
2
|
+
import { optionalVec3 } from "../resolve/resolveVector3.js";
|
|
3
|
+
//#region src/three/noise/BasicMultiChannelPerlinNoiseThree.ts
|
|
4
|
+
/** `BasicMultiChannelPerlinNoise` taking three.js vectors in its options. */
|
|
5
|
+
var BasicMultiChannelPerlinNoiseThree = class extends BasicMultiChannelPerlinNoise {
|
|
6
|
+
constructor({ positionAmplitude, positionFrequency, rotationAmplitude, rotationFrequency, ...options } = {}) {
|
|
7
|
+
super({
|
|
8
|
+
...options,
|
|
9
|
+
positionAmplitude: optionalVec3(positionAmplitude),
|
|
10
|
+
positionFrequency: optionalVec3(positionFrequency),
|
|
11
|
+
rotationAmplitude: optionalVec3(rotationAmplitude),
|
|
12
|
+
rotationFrequency: optionalVec3(rotationFrequency)
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { BasicMultiChannelPerlinNoiseThree };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TargetExtent } from '../core/TargetExtent.js';
|
|
2
|
+
import type { Vector3Like } from './resolve/resolveVector3.js';
|
|
3
|
+
import { type Target } from './resolve/Target.js';
|
|
4
|
+
import type { TargetSlot } from './resolve/TargetRegistry.js';
|
|
5
|
+
/**
|
|
6
|
+
* Resolve how far a target reaches: an explicit `size`, else `radius`, else its geometry's bounds.
|
|
7
|
+
* `dynamicSize` re-measures geometry instead of using the cached bounding box.
|
|
8
|
+
*/
|
|
9
|
+
export declare function readTargetExtent(out: TargetExtent, target: Target, size: Vector3Like | undefined, radius: number | undefined, dynamicSize: boolean, slot: TargetSlot | null): TargetExtent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { resolveTargetRotation, resolveTargetSize } from "./resolve/Target.js";
|
|
2
|
+
import { Quaternion, Vector3 } from "three";
|
|
3
|
+
//#region src/three/readTargetExtent.ts
|
|
4
|
+
var scratchSize = new Vector3();
|
|
5
|
+
var scratchRotation = new Quaternion();
|
|
6
|
+
/**
|
|
7
|
+
* Resolve how far a target reaches: an explicit `size`, else `radius`, else its geometry's bounds.
|
|
8
|
+
* `dynamicSize` re-measures geometry instead of using the cached bounding box.
|
|
9
|
+
*/
|
|
10
|
+
function readTargetExtent(out, target, size, radius, dynamicSize, slot) {
|
|
11
|
+
out.hasSize = false;
|
|
12
|
+
if (radius !== void 0 && !size) {
|
|
13
|
+
out.radius = radius;
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
out.radius = 0;
|
|
17
|
+
if (!resolveTargetSize(scratchSize, target, size, radius, dynamicSize, slot)) return out;
|
|
18
|
+
out.hasSize = true;
|
|
19
|
+
scratchSize.toArray(out.size);
|
|
20
|
+
if (resolveTargetRotation(scratchRotation, target, slot)) scratchRotation.toArray(out.rotation);
|
|
21
|
+
else scratchRotation.identity().toArray(out.rotation);
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { readTargetExtent };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Quat } from 'math';
|
|
2
|
+
import type { TargetPose } from '../core/TargetPose.js';
|
|
3
|
+
import { type Target } from './resolve/Target.js';
|
|
4
|
+
import type { TargetSlot } from './resolve/TargetRegistry.js';
|
|
5
|
+
/** Read a target's world pose into `out`, from `slot` when it is fresh. Returns false when unresolved. */
|
|
6
|
+
export declare function readTargetPose(out: TargetPose, target: Target, slot: TargetSlot | null, withRotation: boolean): boolean;
|
|
7
|
+
/** Read only a target's world rotation into `out`. Returns false for fixed points and unresolved targets. */
|
|
8
|
+
export declare function readTargetRotation(out: Quat, target: Target, slot: TargetSlot | null): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { resolveTargetPosition, resolveTargetRotation } from "./resolve/Target.js";
|
|
2
|
+
import { Quaternion, Vector3 } from "three";
|
|
3
|
+
//#region src/three/readTargetPose.ts
|
|
4
|
+
var scratchPosition = new Vector3();
|
|
5
|
+
var scratchRotation = new Quaternion();
|
|
6
|
+
/** Read a target's world pose into `out`, from `slot` when it is fresh. Returns false when unresolved. */
|
|
7
|
+
function readTargetPose(out, target, slot, withRotation) {
|
|
8
|
+
if (!resolveTargetPosition(scratchPosition, target, slot)) return false;
|
|
9
|
+
scratchPosition.toArray(out.position);
|
|
10
|
+
out.hasRotation = withRotation && resolveTargetRotation(scratchRotation, target, slot);
|
|
11
|
+
if (out.hasRotation) scratchRotation.toArray(out.rotation);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
/** Read only a target's world rotation into `out`. Returns false for fixed points and unresolved targets. */
|
|
15
|
+
function readTargetRotation(out, target, slot) {
|
|
16
|
+
if (!resolveTargetRotation(scratchRotation, target, slot)) return false;
|
|
17
|
+
scratchRotation.toArray(out);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { readTargetPose, readTargetRotation };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Quaternion, Vector3, type Object3D } from 'three';
|
|
2
|
+
import { type Vector3Like } from './resolveVector3.js';
|
|
3
|
+
import type { TargetSlot } from './TargetRegistry.js';
|
|
4
|
+
/** A React-style ref, without depending on React. */
|
|
5
|
+
export type RefLike<T> = {
|
|
6
|
+
current: T;
|
|
7
|
+
};
|
|
8
|
+
/** A fixed point, live object, or ref to a target object. */
|
|
9
|
+
export type Target = Object3D | RefLike<Object3D | null> | Vector3Like | null | undefined;
|
|
10
|
+
/** Resolve a target to its live object, if it has one. */
|
|
11
|
+
export declare function resolveTargetObject3D(target: Target): Object3D | null;
|
|
12
|
+
/** Resolve target dimensions, using explicit size, radius, or geometry bounds. */
|
|
13
|
+
export declare function resolveTargetSize(outSize: Vector3, target: Target, size?: Vector3Like, radius?: number, dynamicSize?: boolean, slot?: TargetSlot | null): boolean;
|
|
14
|
+
/** Resolve a target to a world position, from `slot` when it holds this frame's value. */
|
|
15
|
+
export declare function resolveTargetPosition(out: Vector3, target: Target, slot?: TargetSlot | null): boolean;
|
|
16
|
+
/** Resolve a target to a world rotation. Fixed points return `false`. */
|
|
17
|
+
export declare function resolveTargetRotation(out: Quaternion, target: Target, slot?: TargetSlot | null): boolean;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isVector3Like, resolveVector3 } from "./resolveVector3.js";
|
|
2
|
+
import { Vector3 } from "three";
|
|
3
|
+
//#region src/three/resolve/Target.ts
|
|
4
|
+
/** Resolve a target to its live object, if it has one. */
|
|
5
|
+
function resolveTargetObject3D(target) {
|
|
6
|
+
if (target == null || isVector3Like(target)) return null;
|
|
7
|
+
return ("current" in target ? target.current : target) ?? null;
|
|
8
|
+
}
|
|
9
|
+
var scratchWorldScale = new Vector3();
|
|
10
|
+
/** Identify geometry-bearing three.js objects. */
|
|
11
|
+
function isGeometryObject(object) {
|
|
12
|
+
const o = object;
|
|
13
|
+
return o.isMesh === true || o.isLine === true || o.isPoints === true;
|
|
14
|
+
}
|
|
15
|
+
/** Resolve target dimensions, using explicit size, radius, or geometry bounds. */
|
|
16
|
+
function resolveTargetSize(outSize, target, size, radius, dynamicSize = false, slot) {
|
|
17
|
+
if (size) {
|
|
18
|
+
resolveVector3(outSize, size);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (radius !== void 0) return false;
|
|
22
|
+
const object = resolveTargetObject3D(target);
|
|
23
|
+
if (!object || !isGeometryObject(object)) return false;
|
|
24
|
+
if (dynamicSize || !object.geometry.boundingBox) object.geometry.computeBoundingBox();
|
|
25
|
+
if (!object.geometry.boundingBox) return false;
|
|
26
|
+
object.geometry.boundingBox.getSize(outSize);
|
|
27
|
+
if (slot?.valid) scratchWorldScale.fromArray(slot.scale);
|
|
28
|
+
else object.getWorldScale(scratchWorldScale);
|
|
29
|
+
outSize.multiply(scratchWorldScale);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
/** Resolve a target to a world position, from `slot` when it holds this frame's value. */
|
|
33
|
+
function resolveTargetPosition(out, target, slot) {
|
|
34
|
+
if (slot?.valid) {
|
|
35
|
+
out.fromArray(slot.position);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (target == null) return false;
|
|
39
|
+
if (isVector3Like(target)) {
|
|
40
|
+
resolveVector3(out, target);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
const object = "current" in target ? target.current : target;
|
|
44
|
+
if (!object) return false;
|
|
45
|
+
object.getWorldPosition(out);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
/** Resolve a target to a world rotation. Fixed points return `false`. */
|
|
49
|
+
function resolveTargetRotation(out, target, slot) {
|
|
50
|
+
if (slot?.valid) {
|
|
51
|
+
out.fromArray(slot.rotation);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (target == null) return false;
|
|
55
|
+
if (isVector3Like(target)) return false;
|
|
56
|
+
const object = "current" in target ? target.current : target;
|
|
57
|
+
if (!object) return false;
|
|
58
|
+
object.getWorldQuaternion(out);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { resolveTargetObject3D, resolveTargetPosition, resolveTargetRotation, resolveTargetSize };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Quat, Vec3 } from 'math';
|
|
2
|
+
import { type Object3D } from 'three';
|
|
3
|
+
import type { RefLike } from './Target.js';
|
|
4
|
+
/** A target whose world transform comes from the scene graph. */
|
|
5
|
+
export type RegisteredTarget = Object3D | RefLike<Object3D | null>;
|
|
6
|
+
/** A target's world transform for the current frame. `valid` is false while a ref is empty. */
|
|
7
|
+
export type TargetSlot = {
|
|
8
|
+
position: Vec3;
|
|
9
|
+
rotation: Quat;
|
|
10
|
+
scale: Vec3;
|
|
11
|
+
valid: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Resolves each registered target once per frame, however many stages and cameras read it.
|
|
15
|
+
* Two different refs to the same object get two slots.
|
|
16
|
+
*/
|
|
17
|
+
export declare class TargetRegistry {
|
|
18
|
+
private readonly entries;
|
|
19
|
+
private readonly byTarget;
|
|
20
|
+
/** Register a reader of `target` and return its slot. The same target shares one slot. */
|
|
21
|
+
acquire(target: RegisteredTarget): TargetSlot;
|
|
22
|
+
/** Unregister a reader. Unused entries are dropped on the next `refresh()`, so a re-`acquire` keeps the slot. */
|
|
23
|
+
release(target: RegisteredTarget): void;
|
|
24
|
+
has(target: RegisteredTarget): boolean;
|
|
25
|
+
/** Read every registered target's world transform. Call once per frame, before any stage runs. */
|
|
26
|
+
refresh(): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Quaternion, Vector3 } from "three";
|
|
2
|
+
//#region src/three/resolve/TargetRegistry.ts
|
|
3
|
+
var scratchPosition = new Vector3();
|
|
4
|
+
var scratchRotation = new Quaternion();
|
|
5
|
+
var scratchScale = new Vector3();
|
|
6
|
+
/**
|
|
7
|
+
* Resolves each registered target once per frame, however many stages and cameras read it.
|
|
8
|
+
* Two different refs to the same object get two slots.
|
|
9
|
+
*/
|
|
10
|
+
var TargetRegistry = class {
|
|
11
|
+
entries = [];
|
|
12
|
+
byTarget = /* @__PURE__ */ new Map();
|
|
13
|
+
/** Register a reader of `target` and return its slot. The same target shares one slot. */
|
|
14
|
+
acquire(target) {
|
|
15
|
+
let entry = this.byTarget.get(target);
|
|
16
|
+
if (!entry) {
|
|
17
|
+
entry = {
|
|
18
|
+
target,
|
|
19
|
+
count: 0,
|
|
20
|
+
slot: {
|
|
21
|
+
position: [
|
|
22
|
+
0,
|
|
23
|
+
0,
|
|
24
|
+
0
|
|
25
|
+
],
|
|
26
|
+
rotation: [
|
|
27
|
+
0,
|
|
28
|
+
0,
|
|
29
|
+
0,
|
|
30
|
+
1
|
|
31
|
+
],
|
|
32
|
+
scale: [
|
|
33
|
+
1,
|
|
34
|
+
1,
|
|
35
|
+
1
|
|
36
|
+
],
|
|
37
|
+
valid: false
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
this.byTarget.set(target, entry);
|
|
41
|
+
this.entries.push(entry);
|
|
42
|
+
}
|
|
43
|
+
entry.count++;
|
|
44
|
+
return entry.slot;
|
|
45
|
+
}
|
|
46
|
+
/** Unregister a reader. Unused entries are dropped on the next `refresh()`, so a re-`acquire` keeps the slot. */
|
|
47
|
+
release(target) {
|
|
48
|
+
const entry = this.byTarget.get(target);
|
|
49
|
+
if (entry && entry.count > 0) entry.count--;
|
|
50
|
+
}
|
|
51
|
+
has(target) {
|
|
52
|
+
return this.byTarget.has(target);
|
|
53
|
+
}
|
|
54
|
+
/** Read every registered target's world transform. Call once per frame, before any stage runs. */
|
|
55
|
+
refresh() {
|
|
56
|
+
let kept = 0;
|
|
57
|
+
for (let i = 0; i < this.entries.length; i++) {
|
|
58
|
+
const entry = this.entries[i];
|
|
59
|
+
if (entry.count === 0) {
|
|
60
|
+
this.byTarget.delete(entry.target);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
this.entries[kept++] = entry;
|
|
64
|
+
const object = "current" in entry.target ? entry.target.current : entry.target;
|
|
65
|
+
const slot = entry.slot;
|
|
66
|
+
slot.valid = object != null;
|
|
67
|
+
if (!object) continue;
|
|
68
|
+
object.updateWorldMatrix(true, false);
|
|
69
|
+
object.matrixWorld.decompose(scratchPosition, scratchRotation, scratchScale);
|
|
70
|
+
scratchPosition.toArray(slot.position);
|
|
71
|
+
scratchRotation.toArray(slot.rotation);
|
|
72
|
+
scratchScale.toArray(slot.scale);
|
|
73
|
+
}
|
|
74
|
+
this.entries.length = kept;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { TargetRegistry };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Vec3 } from 'math';
|
|
2
|
+
import { Vector3 } from 'three';
|
|
3
|
+
/** A vector as a `Vector3`, an `[x, y, z?]` tuple or one number for all axes (same shape as r3f's `Vector3` prop). */
|
|
4
|
+
export type Vector3Like = Vector3 | readonly [x: number, y: number, z?: number] | number;
|
|
5
|
+
/** Whether a value matches r3f's `Vector3` prop shorthand. */
|
|
6
|
+
export declare function isVector3Like(value: unknown): value is Vector3Like;
|
|
7
|
+
/** Resolve a r3f vector shorthand into `out`. */
|
|
8
|
+
export declare function resolveVector3(out: Vector3, value: Vector3Like): Vector3;
|
|
9
|
+
/** A new tuple from a vector shorthand, or `undefined` to keep a setting's default. */
|
|
10
|
+
export declare function optionalVec3(value: Vector3Like | undefined): Vec3 | undefined;
|
|
11
|
+
/** Resolve a r3f vector shorthand into the tuple `out`. */
|
|
12
|
+
export declare function resolveVec3(out: Vec3, value: Vector3Like): Vec3;
|