@woosh/meep-engine 3.80.2 → 3.81.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/CHANGELOG.md +52 -0
- package/build/bundle-worker-terrain.js +1 -1
- package/editor/Editor.d.ts +10 -2
- package/editor/Editor.d.ts.map +1 -1
- package/editor/Editor.js +33 -23
- package/editor/EditorCameraNavigation.d.ts +3 -4
- package/editor/EditorCameraNavigation.d.ts.map +1 -1
- package/editor/EditorCameraNavigation.js +29 -8
- package/editor/prototypeEditorShell.d.ts.map +1 -1
- package/editor/prototypeEditorShell.js +10 -2
- package/editor/tools/GridPaintTool.d.ts.map +1 -1
- package/editor/tools/GridPaintTool.js +12 -7
- package/package.json +1 -1
- package/src/core/geom/3d/quaternion/quat3_slerp.d.ts +25 -0
- package/src/core/geom/3d/quaternion/quat3_slerp.d.ts.map +1 -0
- package/src/core/geom/3d/quaternion/quat3_slerp.js +66 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_face_cluster_compute_normal_bounding_cone.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/query/bt_face_cluster_compute_normal_bounding_cone.js +9 -5
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_compute_bounding_sphere.d.ts +3 -3
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_compute_bounding_sphere.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_compute_bounding_sphere.js +5 -14
- package/src/core/geom/packing/miniball/Miniball.d.ts +8 -181
- package/src/core/geom/packing/miniball/Miniball.d.ts.map +1 -1
- package/src/core/geom/packing/miniball/Miniball.js +10 -452
- package/src/core/geom/packing/miniball/PointSet.d.ts +13 -39
- package/src/core/geom/packing/miniball/PointSet.d.ts.map +1 -1
- package/src/core/geom/packing/miniball/PointSet.js +14 -54
- package/src/core/geom/packing/sphere_compute_bounding_of_points.d.ts +20 -0
- package/src/core/geom/packing/sphere_compute_bounding_of_points.d.ts.map +1 -0
- package/src/core/geom/packing/sphere_compute_bounding_of_points.js +66 -0
- package/src/core/geom/packing/sphere_compute_bounding_of_spheres.d.ts.map +1 -1
- package/src/core/geom/packing/sphere_compute_bounding_of_spheres.js +0 -1
- package/src/core/math/exponential_approach.d.ts +23 -0
- package/src/core/math/exponential_approach.d.ts.map +1 -0
- package/src/core/math/exponential_approach.js +31 -0
- package/src/core/math/physics/spring/Spring.d.ts.map +1 -0
- package/src/core/math/physics/spring/criticallyDampedSpring.d.ts.map +1 -0
- package/src/core/math/physics/spring/dampedSpringStep.d.ts.map +1 -0
- package/src/engine/EngineHarness.d.ts +1 -3
- package/src/engine/EngineHarness.d.ts.map +1 -1
- package/src/engine/EngineHarness.js +13 -10
- package/src/engine/control/first-person/FirstPersonPlayerController.d.ts +9 -15
- package/src/engine/control/first-person/FirstPersonPlayerController.d.ts.map +1 -1
- package/src/engine/control/first-person/FirstPersonPlayerController.js +9 -10
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts +68 -14
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +196 -184
- package/src/engine/ecs/gui/hud/testHudEdgeStick.js +4 -2
- package/src/engine/ecs/parent/parent_entity_root_of.d.ts +11 -0
- package/src/engine/ecs/parent/parent_entity_root_of.d.ts.map +1 -0
- package/src/engine/ecs/parent/parent_entity_root_of.js +32 -0
- package/src/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +130 -130
- package/src/engine/graphics/camera/makeOrbitalCameraController.d.ts +3 -2
- package/src/engine/graphics/camera/makeOrbitalCameraController.d.ts.map +1 -1
- package/src/engine/graphics/camera/makeOrbitalCameraController.js +18 -11
- package/src/engine/graphics/camera/orbital/OrbitalCameraRig.d.ts +4 -5
- package/src/engine/graphics/camera/orbital/OrbitalCameraRig.d.ts.map +1 -1
- package/src/engine/graphics/camera/orbital/OrbitalCameraRig.js +6 -6
- package/src/engine/graphics/camera/rig/CameraRig.d.ts +55 -0
- package/src/engine/graphics/camera/rig/CameraRig.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/CameraRig.js +65 -0
- package/src/engine/graphics/camera/rig/CameraRigContext.d.ts +58 -0
- package/src/engine/graphics/camera/rig/CameraRigContext.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/CameraRigContext.js +51 -0
- package/src/engine/graphics/camera/rig/CameraRigDriver.d.ts +36 -0
- package/src/engine/graphics/camera/rig/CameraRigDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/CameraRigDriver.js +39 -0
- package/src/engine/graphics/camera/rig/CameraRigSystem.d.ts +30 -0
- package/src/engine/graphics/camera/rig/CameraRigSystem.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/CameraRigSystem.js +81 -0
- package/src/engine/graphics/camera/rig/CameraState.d.ts +59 -0
- package/src/engine/graphics/camera/rig/CameraState.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/CameraState.js +76 -0
- package/src/engine/graphics/camera/rig/camera_rig_output.d.ts +17 -0
- package/src/engine/graphics/camera/rig/camera_rig_output.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/camera_rig_output.js +80 -0
- package/src/engine/graphics/camera/rig/camera_rig_update.d.ts +38 -0
- package/src/engine/graphics/camera/rig/camera_rig_update.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/camera_rig_update.js +102 -0
- package/src/engine/graphics/camera/rig/camera_state_read_entity.d.ts +17 -0
- package/src/engine/graphics/camera/rig/camera_state_read_entity.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/camera_state_read_entity.js +71 -0
- package/src/engine/graphics/camera/rig/drivers/CameraBlendDriver.d.ts +95 -0
- package/src/engine/graphics/camera/rig/drivers/CameraBlendDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraBlendDriver.js +290 -0
- package/src/engine/graphics/camera/rig/drivers/CameraCollideDriver.d.ts +37 -0
- package/src/engine/graphics/camera/rig/drivers/CameraCollideDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraCollideDriver.js +158 -0
- package/src/engine/graphics/camera/rig/drivers/CameraFollowDriver.d.ts +28 -0
- package/src/engine/graphics/camera/rig/drivers/CameraFollowDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraFollowDriver.js +66 -0
- package/src/engine/graphics/camera/rig/drivers/CameraFovDriver.d.ts +29 -0
- package/src/engine/graphics/camera/rig/drivers/CameraFovDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraFovDriver.js +65 -0
- package/src/engine/graphics/camera/rig/drivers/CameraImpulseDriver.d.ts +113 -0
- package/src/engine/graphics/camera/rig/drivers/CameraImpulseDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraImpulseDriver.js +442 -0
- package/src/engine/graphics/camera/rig/drivers/CameraLookAtDriver.d.ts +32 -0
- package/src/engine/graphics/camera/rig/drivers/CameraLookAtDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraLookAtDriver.js +78 -0
- package/src/engine/graphics/camera/rig/drivers/CameraOffsetDriver.d.ts +36 -0
- package/src/engine/graphics/camera/rig/drivers/CameraOffsetDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraOffsetDriver.js +54 -0
- package/src/engine/graphics/camera/rig/drivers/CameraOffsetFrame.d.ts +10 -0
- package/src/engine/graphics/camera/rig/drivers/CameraOffsetFrame.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraOffsetFrame.js +22 -0
- package/src/engine/graphics/camera/rig/drivers/CameraOrbitDriver.d.ts +182 -0
- package/src/engine/graphics/camera/rig/drivers/CameraOrbitDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraOrbitDriver.js +455 -0
- package/src/engine/graphics/camera/rig/drivers/CameraPositionDriver.d.ts +31 -0
- package/src/engine/graphics/camera/rig/drivers/CameraPositionDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraPositionDriver.js +57 -0
- package/src/engine/graphics/camera/rig/drivers/CameraShakeDriver.d.ts +62 -0
- package/src/engine/graphics/camera/rig/drivers/CameraShakeDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraShakeDriver.js +174 -0
- package/src/engine/graphics/camera/rig/drivers/CameraSmoothDriver.d.ts +29 -0
- package/src/engine/graphics/camera/rig/drivers/CameraSmoothDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraSmoothDriver.js +82 -0
- package/src/engine/graphics/camera/rig/drivers/CameraYawPitchRollDriver.d.ts +40 -0
- package/src/engine/graphics/camera/rig/drivers/CameraYawPitchRollDriver.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/CameraYawPitchRollDriver.js +66 -0
- package/src/engine/graphics/camera/rig/drivers/camera_state_add_offset.d.ts +22 -0
- package/src/engine/graphics/camera/rig/drivers/camera_state_add_offset.d.ts.map +1 -0
- package/src/engine/graphics/camera/rig/drivers/camera_state_add_offset.js +81 -0
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts +6 -131
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +4 -378
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSerializationAdapter.d.ts +4 -2
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSerializationAdapter.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSerializationAdapter.js +16 -27
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLander.d.ts +4 -0
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLander.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLander.js +4 -0
- package/src/engine/graphics/ecs/light/Light.d.ts +10 -5
- package/src/engine/graphics/ecs/light/Light.d.ts.map +1 -1
- package/src/engine/graphics/ecs/light/Light.js +15 -24
- package/src/engine/graphics/geometry/computeBoundingSphereFromVertexData.d.ts +0 -4
- package/src/engine/graphics/geometry/computeBoundingSphereFromVertexData.d.ts.map +1 -1
- package/src/engine/graphics/geometry/computeBoundingSphereFromVertexData.js +12 -11
- package/src/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.d.ts.map +1 -1
- package/src/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.js +5 -5
- package/src/engine/graphics3/LightSystem.js +0 -3
- package/src/engine/input/ecs/controllers/KeyboardCameraController.d.ts +2 -2
- package/src/engine/input/ecs/controllers/KeyboardCameraController.d.ts.map +1 -1
- package/src/engine/input/ecs/controllers/KeyboardCameraController.js +3 -3
- package/src/engine/physics/ecs/ContactProbeSystem.d.ts.map +1 -1
- package/src/engine/physics/ecs/ContactProbeSystem.js +3 -25
- package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
- package/src/shade/playground/foliage_wind/foliage_world.d.ts.map +1 -1
- package/src/shade/playground/foliage_wind/foliage_world.js +0 -1
- package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
- package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +1 -1
- package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
- package/src/shade/renderer/camera/orbital/OrbitalCameraController.d.ts +4 -4
- package/src/shade/renderer/camera/orbital/OrbitalCameraController.d.ts.map +1 -1
- package/src/shade/renderer/camera/orbital/OrbitalCameraController.js +26 -11
- package/src/shade/renderer/geometry/Geometry.d.ts.map +1 -1
- package/src/shade/renderer/geometry/Geometry.js +2 -11
- package/src/shade/renderer/geometry/virtual/build/sphere/vgeo_bounding_sphere.d.ts.map +1 -1
- package/src/shade/renderer/geometry/virtual/build/sphere/vgeo_bounding_sphere.js +3 -6
- package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
- package/src/core/geom/packing/miniball/Quality.d.ts +0 -92
- package/src/core/geom/packing/miniball/Quality.d.ts.map +0 -1
- package/src/core/geom/packing/miniball/Quality.js +0 -114
- package/src/core/geom/packing/miniball/Subspan.d.ts +0 -191
- package/src/core/geom/packing/miniball/Subspan.d.ts.map +0 -1
- package/src/core/geom/packing/miniball/Subspan.js +0 -529
- package/src/core/geom/packing/miniball/miniball_compute_quality.d.ts +0 -10
- package/src/core/geom/packing/miniball/miniball_compute_quality.d.ts.map +0 -1
- package/src/core/geom/packing/miniball/miniball_compute_quality.js +0 -60
- package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts +0 -146
- package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts.map +0 -1
- package/src/engine/control/first-person/composer/EyeOffsetStack.js +0 -395
- package/src/engine/control/first-person/math/Spring.d.ts.map +0 -1
- package/src/engine/control/first-person/math/criticallyDampedSpring.d.ts.map +0 -1
- package/src/engine/control/first-person/math/dampedSpringStep.d.ts.map +0 -1
- package/src/engine/graphics/camera/CameraShake.d.ts +0 -32
- package/src/engine/graphics/camera/CameraShake.d.ts.map +0 -1
- package/src/engine/graphics/camera/CameraShake.js +0 -68
- package/src/engine/graphics/camera/CameraShakeBehavior.d.ts +0 -41
- package/src/engine/graphics/camera/CameraShakeBehavior.d.ts.map +0 -1
- package/src/engine/graphics/camera/CameraShakeBehavior.js +0 -91
- package/src/engine/graphics/camera/CameraShakeTraumaBehavior.d.ts +0 -19
- package/src/engine/graphics/camera/CameraShakeTraumaBehavior.d.ts.map +0 -1
- package/src/engine/graphics/camera/CameraShakeTraumaBehavior.js +0 -37
- package/src/engine/graphics/ecs/camera/filter/setup_filtered_camera_controller.d.ts +0 -21
- package/src/engine/graphics/ecs/camera/filter/setup_filtered_camera_controller.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/filter/setup_filtered_camera_controller.js +0 -79
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.d.ts +0 -28
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js +0 -100
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.d.ts +0 -36
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.js +0 -160
- /package/src/{engine/control/first-person/math → core/math/physics/spring}/Spring.d.ts +0 -0
- /package/src/{engine/control/first-person/math → core/math/physics/spring}/Spring.js +0 -0
- /package/src/{engine/control/first-person/math → core/math/physics/spring}/criticallyDampedSpring.d.ts +0 -0
- /package/src/{engine/control/first-person/math → core/math/physics/spring}/criticallyDampedSpring.js +0 -0
- /package/src/{engine/control/first-person/math → core/math/physics/spring}/dampedSpringStep.d.ts +0 -0
- /package/src/{engine/control/first-person/math → core/math/physics/spring}/dampedSpringStep.js +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CameraRigDriver } from "../CameraRigDriver.js";
|
|
2
|
+
import { CAMERA_STATE_PIVOT, CAMERA_STATE_POSITION } from "../CameraState.js";
|
|
3
|
+
|
|
4
|
+
/** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Puts the camera, and the pivot with it, at a world position that code writes: for a source that is
|
|
8
|
+
* not an entity, such as a controller's own render-rate position.
|
|
9
|
+
*
|
|
10
|
+
* @author Alex Goldring
|
|
11
|
+
* @copyright Company Named Limited (c) 2026
|
|
12
|
+
*/
|
|
13
|
+
export class CameraPositionDriver extends CameraRigDriver {
|
|
14
|
+
/**
|
|
15
|
+
* @type {number}
|
|
16
|
+
*/
|
|
17
|
+
x = 0;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @type {number}
|
|
21
|
+
*/
|
|
22
|
+
y = 0;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @type {number}
|
|
26
|
+
*/
|
|
27
|
+
z = 0;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {number} x
|
|
31
|
+
* @param {number} y
|
|
32
|
+
* @param {number} z
|
|
33
|
+
*/
|
|
34
|
+
set(x, y, z) {
|
|
35
|
+
this.x = x;
|
|
36
|
+
this.y = y;
|
|
37
|
+
this.z = z;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {Float64Array} state
|
|
42
|
+
* @param {CameraRigContext} context
|
|
43
|
+
*/
|
|
44
|
+
update(state, context) {
|
|
45
|
+
const x = this.x;
|
|
46
|
+
const y = this.y;
|
|
47
|
+
const z = this.z;
|
|
48
|
+
|
|
49
|
+
state[CAMERA_STATE_POSITION] = x;
|
|
50
|
+
state[CAMERA_STATE_POSITION + 1] = y;
|
|
51
|
+
state[CAMERA_STATE_POSITION + 2] = z;
|
|
52
|
+
|
|
53
|
+
state[CAMERA_STATE_PIVOT] = x;
|
|
54
|
+
state[CAMERA_STATE_PIVOT + 1] = y;
|
|
55
|
+
state[CAMERA_STATE_PIVOT + 2] = z;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shakes the camera by trauma, after Squirrel Eiserloh, "Math for Game Programmers: Juicing Your
|
|
3
|
+
* Cameras With Math" (GDC 2016): gameplay adds {@link trauma}, which falls linearly over time; the shake
|
|
4
|
+
* is {@link response} of the trauma, so small hits barely register and big ones land hard; offset and
|
|
5
|
+
* rotation are smooth noise scaled by the shake and the limits, in the camera's own axes.
|
|
6
|
+
*
|
|
7
|
+
* Smooth noise rather than random values per frame, so the shake slows down with time and stops with a
|
|
8
|
+
* pause. Every channel has its own noise from {@link seed}, so two cameras with different seeds shake
|
|
9
|
+
* differently.
|
|
10
|
+
*
|
|
11
|
+
* Place it after anything that smooths, or the smoothing eats the shake.
|
|
12
|
+
*
|
|
13
|
+
* @author Alex Goldring
|
|
14
|
+
* @copyright Company Named Limited (c) 2026
|
|
15
|
+
*/
|
|
16
|
+
export class CameraShakeDriver extends CameraRigDriver {
|
|
17
|
+
/**
|
|
18
|
+
* 0 to 1. Add with {@link addTrauma}.
|
|
19
|
+
* @type {number}
|
|
20
|
+
*/
|
|
21
|
+
trauma: number;
|
|
22
|
+
/**
|
|
23
|
+
* Trauma lost per second.
|
|
24
|
+
* @type {number}
|
|
25
|
+
*/
|
|
26
|
+
trauma_decay: number;
|
|
27
|
+
/**
|
|
28
|
+
* Shake as a function of trauma, both 0 to 1. Trauma squared by default.
|
|
29
|
+
* @type {AnimationCurve}
|
|
30
|
+
*/
|
|
31
|
+
response: AnimationCurve;
|
|
32
|
+
/**
|
|
33
|
+
* Largest pitch, yaw and roll, radians.
|
|
34
|
+
* @type {Vector3}
|
|
35
|
+
*/
|
|
36
|
+
max_rotation: Vector3;
|
|
37
|
+
/**
|
|
38
|
+
* Largest offset along the camera's x, y and z, world units.
|
|
39
|
+
* @type {Vector3}
|
|
40
|
+
*/
|
|
41
|
+
max_offset: Vector3;
|
|
42
|
+
/**
|
|
43
|
+
* How fast the noise runs; a higher frequency shakes faster.
|
|
44
|
+
* @type {number}
|
|
45
|
+
*/
|
|
46
|
+
frequency: number;
|
|
47
|
+
/**
|
|
48
|
+
* Picks the noise. Two drivers with the same seed shake the same way.
|
|
49
|
+
* @type {number}
|
|
50
|
+
*/
|
|
51
|
+
seed: number;
|
|
52
|
+
/**
|
|
53
|
+
* @param {number} amount added to {@link trauma}, which stays within 0 to 1
|
|
54
|
+
*/
|
|
55
|
+
addTrauma(amount: number): void;
|
|
56
|
+
#private;
|
|
57
|
+
}
|
|
58
|
+
export type CameraRigContext = import("../CameraRigContext.js").CameraRigContext;
|
|
59
|
+
import { CameraRigDriver } from "../CameraRigDriver.js";
|
|
60
|
+
import { AnimationCurve } from "../../../../animation/curve/AnimationCurve.js";
|
|
61
|
+
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
62
|
+
//# sourceMappingURL=CameraShakeDriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CameraShakeDriver.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/camera/rig/drivers/CameraShakeDriver.js"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;GAcG;AACH;IACI;;;OAGG;IACH,QAFU,MAAM,CAEL;IAEX;;;OAGG;IACH,cAFU,MAAM,CAEC;IAEjB;;;OAGG;IACH,UAFU,cAAc,CAKrB;IAEH;;;OAGG;IACH,cAFU,OAAO,CAEY;IAE7B;;;OAGG;IACH,YAFU,OAAO,CAEU;IAE3B;;;OAGG;IACH,WAFU,MAAM,CAED;IAEf;;;OAGG;IACH,MAFU,MAAM,CAEP;IAmBT;;OAEG;IACH,kBAFW,MAAM,QAIhB;;CAmEJ;+BAhKa,OAAO,wBAAwB,EAAE,gBAAgB;gCAN/B,uBAAuB;+BAFxB,+CAA+C;oBAJ1D,qCAAqC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { quat3_multiply } from "../../../../../core/geom/3d/quaternion/quat3_multiply.js";
|
|
2
|
+
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
3
|
+
import { clamp01 } from "../../../../../core/math/clamp01.js";
|
|
4
|
+
import { create_simplex_noise_2d } from "../../../../../core/math/noise/create_simplex_noise_2d.js";
|
|
5
|
+
import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
|
|
6
|
+
import { AnimationCurve } from "../../../../animation/curve/AnimationCurve.js";
|
|
7
|
+
import { Keyframe } from "../../../../animation/curve/Keyframe.js";
|
|
8
|
+
import { CameraRigDriver } from "../CameraRigDriver.js";
|
|
9
|
+
import { CAMERA_STATE_ROTATION } from "../CameraState.js";
|
|
10
|
+
import { camera_state_add_offset } from "./camera_state_add_offset.js";
|
|
11
|
+
import { CameraOffsetFrame } from "./CameraOffsetFrame.js";
|
|
12
|
+
import { camera_yaw_pitch_roll_rotation } from "./CameraYawPitchRollDriver.js";
|
|
13
|
+
|
|
14
|
+
/** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
|
|
15
|
+
|
|
16
|
+
const scratch_q = new Float64Array(4);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Noise channels: rotation pitch, yaw, roll, then offset x, y, z.
|
|
20
|
+
* @type {number}
|
|
21
|
+
*/
|
|
22
|
+
const CHANNEL_COUNT = 6;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Shakes the camera by trauma, after Squirrel Eiserloh, "Math for Game Programmers: Juicing Your
|
|
26
|
+
* Cameras With Math" (GDC 2016): gameplay adds {@link trauma}, which falls linearly over time; the shake
|
|
27
|
+
* is {@link response} of the trauma, so small hits barely register and big ones land hard; offset and
|
|
28
|
+
* rotation are smooth noise scaled by the shake and the limits, in the camera's own axes.
|
|
29
|
+
*
|
|
30
|
+
* Smooth noise rather than random values per frame, so the shake slows down with time and stops with a
|
|
31
|
+
* pause. Every channel has its own noise from {@link seed}, so two cameras with different seeds shake
|
|
32
|
+
* differently.
|
|
33
|
+
*
|
|
34
|
+
* Place it after anything that smooths, or the smoothing eats the shake.
|
|
35
|
+
*
|
|
36
|
+
* @author Alex Goldring
|
|
37
|
+
* @copyright Company Named Limited (c) 2026
|
|
38
|
+
*/
|
|
39
|
+
export class CameraShakeDriver extends CameraRigDriver {
|
|
40
|
+
/**
|
|
41
|
+
* 0 to 1. Add with {@link addTrauma}.
|
|
42
|
+
* @type {number}
|
|
43
|
+
*/
|
|
44
|
+
trauma = 0;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Trauma lost per second.
|
|
48
|
+
* @type {number}
|
|
49
|
+
*/
|
|
50
|
+
trauma_decay = 1;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Shake as a function of trauma, both 0 to 1. Trauma squared by default.
|
|
54
|
+
* @type {AnimationCurve}
|
|
55
|
+
*/
|
|
56
|
+
response = AnimationCurve.from([
|
|
57
|
+
Keyframe.from(0, 0, 0, 0),
|
|
58
|
+
Keyframe.from(1, 1, 2, 0),
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Largest pitch, yaw and roll, radians.
|
|
63
|
+
* @type {Vector3}
|
|
64
|
+
*/
|
|
65
|
+
max_rotation = new Vector3();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Largest offset along the camera's x, y and z, world units.
|
|
69
|
+
* @type {Vector3}
|
|
70
|
+
*/
|
|
71
|
+
max_offset = new Vector3();
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* How fast the noise runs; a higher frequency shakes faster.
|
|
75
|
+
* @type {number}
|
|
76
|
+
*/
|
|
77
|
+
frequency = 10;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Picks the noise. Two drivers with the same seed shake the same way.
|
|
81
|
+
* @type {number}
|
|
82
|
+
*/
|
|
83
|
+
seed = 0;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Seconds of noise run so far.
|
|
87
|
+
* @type {number}
|
|
88
|
+
*/
|
|
89
|
+
#time = 0;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The seed {@link #noise} was made from.
|
|
93
|
+
* @type {number}
|
|
94
|
+
*/
|
|
95
|
+
#noise_seed = NaN;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @type {function(number, number):number[]}
|
|
99
|
+
*/
|
|
100
|
+
#noise = [];
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {number} amount added to {@link trauma}, which stays within 0 to 1
|
|
104
|
+
*/
|
|
105
|
+
addTrauma(amount) {
|
|
106
|
+
this.trauma = clamp01(this.trauma + amount);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {Float64Array} state
|
|
111
|
+
* @param {CameraRigContext} context
|
|
112
|
+
*/
|
|
113
|
+
update(state, context) {
|
|
114
|
+
const dt = context.dt;
|
|
115
|
+
|
|
116
|
+
const trauma = clamp01(this.trauma);
|
|
117
|
+
|
|
118
|
+
this.trauma = clamp01(trauma - this.trauma_decay * dt);
|
|
119
|
+
|
|
120
|
+
this.#time += dt;
|
|
121
|
+
|
|
122
|
+
if (trauma <= 0) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const shake = this.response.evaluate(trauma);
|
|
127
|
+
|
|
128
|
+
if (shake === 0) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this.#noise_seed !== this.seed) {
|
|
133
|
+
this.#make_noise();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const noise = this.#noise;
|
|
137
|
+
const t = this.#time * this.frequency;
|
|
138
|
+
|
|
139
|
+
const rotation = this.max_rotation;
|
|
140
|
+
const offset = this.max_offset;
|
|
141
|
+
|
|
142
|
+
const pitch = rotation.x * shake * noise[0](t, 1);
|
|
143
|
+
const yaw = rotation.y * shake * noise[1](t, 2);
|
|
144
|
+
const roll = rotation.z * shake * noise[2](t, 3);
|
|
145
|
+
|
|
146
|
+
const ox = offset.x * shake * noise[3](t, 4);
|
|
147
|
+
const oy = offset.y * shake * noise[4](t, 5);
|
|
148
|
+
const oz = offset.z * shake * noise[5](t, 6);
|
|
149
|
+
|
|
150
|
+
camera_state_add_offset(state, ox, oy, oz, CameraOffsetFrame.Local);
|
|
151
|
+
|
|
152
|
+
camera_yaw_pitch_roll_rotation(scratch_q, 0, yaw, pitch, roll);
|
|
153
|
+
|
|
154
|
+
quat3_multiply(
|
|
155
|
+
state, CAMERA_STATE_ROTATION,
|
|
156
|
+
state[CAMERA_STATE_ROTATION], state[CAMERA_STATE_ROTATION + 1],
|
|
157
|
+
state[CAMERA_STATE_ROTATION + 2], state[CAMERA_STATE_ROTATION + 3],
|
|
158
|
+
scratch_q[0], scratch_q[1], scratch_q[2], scratch_q[3]
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#make_noise() {
|
|
163
|
+
const random = seededRandom(this.seed);
|
|
164
|
+
const noise = this.#noise;
|
|
165
|
+
|
|
166
|
+
noise.length = 0;
|
|
167
|
+
|
|
168
|
+
for (let i = 0; i < CHANNEL_COUNT; i++) {
|
|
169
|
+
noise.push(create_simplex_noise_2d(random));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this.#noise_seed = this.seed;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
|
|
2
|
+
/**
|
|
3
|
+
* Lags the camera behind the pose it is handed: the gap to it halves every half life, for position and
|
|
4
|
+
* rotation separately. Position moves in a straight line, rotation along the shortest arc, both by the
|
|
5
|
+
* same exact fraction per frame, so the camera ends up in the same place however a second is cut into
|
|
6
|
+
* frames.
|
|
7
|
+
*
|
|
8
|
+
* Where it sits decides what lags: before an orbit it lags the pivot, after it the eye. The pivot itself
|
|
9
|
+
* is not smoothed.
|
|
10
|
+
*
|
|
11
|
+
* @author Alex Goldring
|
|
12
|
+
* @copyright Company Named Limited (c) 2026
|
|
13
|
+
*/
|
|
14
|
+
export class CameraSmoothDriver extends CameraRigDriver {
|
|
15
|
+
/**
|
|
16
|
+
* Seconds for the position gap to halve; 0 follows exactly.
|
|
17
|
+
* @type {number}
|
|
18
|
+
*/
|
|
19
|
+
position_half_life: number;
|
|
20
|
+
/**
|
|
21
|
+
* Seconds for the rotation gap to halve; 0 follows exactly.
|
|
22
|
+
* @type {number}
|
|
23
|
+
*/
|
|
24
|
+
rotation_half_life: number;
|
|
25
|
+
#private;
|
|
26
|
+
}
|
|
27
|
+
export type CameraRigContext = import("../CameraRigContext.js").CameraRigContext;
|
|
28
|
+
import { CameraRigDriver } from "../CameraRigDriver.js";
|
|
29
|
+
//# sourceMappingURL=CameraSmoothDriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CameraSmoothDriver.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/camera/rig/drivers/CameraSmoothDriver.js"],"names":[],"mappings":"AAKA,oFAAoF;AAEpF;;;;;;;;;;;GAWG;AACH;IACI;;;OAGG;IACH,oBAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,oBAFU,MAAM,CAEO;;CAmD1B;+BA5Ea,OAAO,wBAAwB,EAAE,gBAAgB;gCAH/B,uBAAuB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { quat3_slerp } from "../../../../../core/geom/3d/quaternion/quat3_slerp.js";
|
|
2
|
+
import { exponential_approach_fraction } from "../../../../../core/math/exponential_approach.js";
|
|
3
|
+
import { CameraRigDriver } from "../CameraRigDriver.js";
|
|
4
|
+
import { CAMERA_STATE_POSITION, CAMERA_STATE_ROTATION } from "../CameraState.js";
|
|
5
|
+
|
|
6
|
+
/** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Lags the camera behind the pose it is handed: the gap to it halves every half life, for position and
|
|
10
|
+
* rotation separately. Position moves in a straight line, rotation along the shortest arc, both by the
|
|
11
|
+
* same exact fraction per frame, so the camera ends up in the same place however a second is cut into
|
|
12
|
+
* frames.
|
|
13
|
+
*
|
|
14
|
+
* Where it sits decides what lags: before an orbit it lags the pivot, after it the eye. The pivot itself
|
|
15
|
+
* is not smoothed.
|
|
16
|
+
*
|
|
17
|
+
* @author Alex Goldring
|
|
18
|
+
* @copyright Company Named Limited (c) 2026
|
|
19
|
+
*/
|
|
20
|
+
export class CameraSmoothDriver extends CameraRigDriver {
|
|
21
|
+
/**
|
|
22
|
+
* Seconds for the position gap to halve; 0 follows exactly.
|
|
23
|
+
* @type {number}
|
|
24
|
+
*/
|
|
25
|
+
position_half_life = 0;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Seconds for the rotation gap to halve; 0 follows exactly.
|
|
29
|
+
* @type {number}
|
|
30
|
+
*/
|
|
31
|
+
rotation_half_life = 0;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The pose this driver produced last frame.
|
|
35
|
+
* @type {Float64Array}
|
|
36
|
+
*/
|
|
37
|
+
#pose = new Float64Array(7);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @type {boolean}
|
|
41
|
+
*/
|
|
42
|
+
#has_pose = false;
|
|
43
|
+
|
|
44
|
+
reset() {
|
|
45
|
+
this.#has_pose = false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {Float64Array} state
|
|
50
|
+
* @param {CameraRigContext} context
|
|
51
|
+
*/
|
|
52
|
+
update(state, context) {
|
|
53
|
+
const pose = this.#pose;
|
|
54
|
+
|
|
55
|
+
if (this.#has_pose) {
|
|
56
|
+
const dt = context.dt;
|
|
57
|
+
|
|
58
|
+
const p = exponential_approach_fraction(this.position_half_life, dt);
|
|
59
|
+
|
|
60
|
+
for (let i = 0; i < 3; i++) {
|
|
61
|
+
const current = pose[i];
|
|
62
|
+
state[CAMERA_STATE_POSITION + i] = current + (state[CAMERA_STATE_POSITION + i] - current) * p;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const r = exponential_approach_fraction(this.rotation_half_life, dt);
|
|
66
|
+
|
|
67
|
+
quat3_slerp(
|
|
68
|
+
state, CAMERA_STATE_ROTATION,
|
|
69
|
+
pose[3], pose[4], pose[5], pose[6],
|
|
70
|
+
state[CAMERA_STATE_ROTATION], state[CAMERA_STATE_ROTATION + 1],
|
|
71
|
+
state[CAMERA_STATE_ROTATION + 2], state[CAMERA_STATE_ROTATION + 3],
|
|
72
|
+
r
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (let i = 0; i < 7; i++) {
|
|
77
|
+
pose[i] = state[CAMERA_STATE_POSITION + i];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.#has_pose = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `yaw` about +Y, then `pitch` about the turned +X, then `roll` about the turned +Z.
|
|
3
|
+
*
|
|
4
|
+
* @param {Float64Array|number[]} out
|
|
5
|
+
* @param {number} out_offset receives 4 floats, x y z w
|
|
6
|
+
* @param {number} yaw radians
|
|
7
|
+
* @param {number} pitch radians
|
|
8
|
+
* @param {number} roll radians
|
|
9
|
+
*/
|
|
10
|
+
export function camera_yaw_pitch_roll_rotation(out: Float64Array | number[], out_offset: number, yaw: number, pitch: number, roll: number): void;
|
|
11
|
+
/**
|
|
12
|
+
* Turns the camera to yaw, then pitch, then roll: yaw about world up, pitch about the turned right, roll
|
|
13
|
+
* about the turned view direction, `R = yaw × pitch × roll`. A first-person head.
|
|
14
|
+
*
|
|
15
|
+
* Signs follow the axes: positive pitch turns +Z towards −Y, so it looks down; positive roll turns +Y
|
|
16
|
+
* towards −X, the viewer's right, so the head tilts right.
|
|
17
|
+
*
|
|
18
|
+
* @author Alex Goldring
|
|
19
|
+
* @copyright Company Named Limited (c) 2026
|
|
20
|
+
*/
|
|
21
|
+
export class CameraYawPitchRollDriver extends CameraRigDriver {
|
|
22
|
+
/**
|
|
23
|
+
* Radians, about world up.
|
|
24
|
+
* @type {number}
|
|
25
|
+
*/
|
|
26
|
+
yaw: number;
|
|
27
|
+
/**
|
|
28
|
+
* Radians, about the camera's right.
|
|
29
|
+
* @type {number}
|
|
30
|
+
*/
|
|
31
|
+
pitch: number;
|
|
32
|
+
/**
|
|
33
|
+
* Radians, about the camera's view direction.
|
|
34
|
+
* @type {number}
|
|
35
|
+
*/
|
|
36
|
+
roll: number;
|
|
37
|
+
}
|
|
38
|
+
export type CameraRigContext = import("../CameraRigContext.js").CameraRigContext;
|
|
39
|
+
import { CameraRigDriver } from "../CameraRigDriver.js";
|
|
40
|
+
//# sourceMappingURL=CameraYawPitchRollDriver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CameraYawPitchRollDriver.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/camera/rig/drivers/CameraYawPitchRollDriver.js"],"names":[],"mappings":"AA8CA;;;;;;;;GAQG;AACH,oDANW,YAAY,GAAC,MAAM,EAAE,cACrB,MAAM,OACN,MAAM,SACN,MAAM,QACN,MAAM,QAYhB;AAzDD;;;;;;;;;GASG;AACH;IACI;;;OAGG;IACH,KAFU,MAAM,CAER;IAER;;;OAGG;IACH,OAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,MAFU,MAAM,CAEP;CASZ;+BAxCa,OAAO,wBAAwB,EAAE,gBAAgB;gCAH/B,uBAAuB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { quat3_multiply } from "../../../../../core/geom/3d/quaternion/quat3_multiply.js";
|
|
2
|
+
import { CameraRigDriver } from "../CameraRigDriver.js";
|
|
3
|
+
import { CAMERA_STATE_ROTATION } from "../CameraState.js";
|
|
4
|
+
|
|
5
|
+
/** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
|
|
6
|
+
|
|
7
|
+
const scratch_q = new Float64Array(4);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Turns the camera to yaw, then pitch, then roll: yaw about world up, pitch about the turned right, roll
|
|
11
|
+
* about the turned view direction, `R = yaw × pitch × roll`. A first-person head.
|
|
12
|
+
*
|
|
13
|
+
* Signs follow the axes: positive pitch turns +Z towards −Y, so it looks down; positive roll turns +Y
|
|
14
|
+
* towards −X, the viewer's right, so the head tilts right.
|
|
15
|
+
*
|
|
16
|
+
* @author Alex Goldring
|
|
17
|
+
* @copyright Company Named Limited (c) 2026
|
|
18
|
+
*/
|
|
19
|
+
export class CameraYawPitchRollDriver extends CameraRigDriver {
|
|
20
|
+
/**
|
|
21
|
+
* Radians, about world up.
|
|
22
|
+
* @type {number}
|
|
23
|
+
*/
|
|
24
|
+
yaw = 0;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Radians, about the camera's right.
|
|
28
|
+
* @type {number}
|
|
29
|
+
*/
|
|
30
|
+
pitch = 0;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Radians, about the camera's view direction.
|
|
34
|
+
* @type {number}
|
|
35
|
+
*/
|
|
36
|
+
roll = 0;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {Float64Array} state
|
|
40
|
+
* @param {CameraRigContext} context
|
|
41
|
+
*/
|
|
42
|
+
update(state, context) {
|
|
43
|
+
camera_yaw_pitch_roll_rotation(state, CAMERA_STATE_ROTATION, this.yaw, this.pitch, this.roll);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* `yaw` about +Y, then `pitch` about the turned +X, then `roll` about the turned +Z.
|
|
49
|
+
*
|
|
50
|
+
* @param {Float64Array|number[]} out
|
|
51
|
+
* @param {number} out_offset receives 4 floats, x y z w
|
|
52
|
+
* @param {number} yaw radians
|
|
53
|
+
* @param {number} pitch radians
|
|
54
|
+
* @param {number} roll radians
|
|
55
|
+
*/
|
|
56
|
+
export function camera_yaw_pitch_roll_rotation(out, out_offset, yaw, pitch, roll) {
|
|
57
|
+
const sy = Math.sin(yaw * 0.5), cy = Math.cos(yaw * 0.5);
|
|
58
|
+
const sp = Math.sin(pitch * 0.5), cp = Math.cos(pitch * 0.5);
|
|
59
|
+
const sr = Math.sin(roll * 0.5), cr = Math.cos(roll * 0.5);
|
|
60
|
+
|
|
61
|
+
// yaw × pitch
|
|
62
|
+
quat3_multiply(scratch_q, 0, 0, sy, 0, cy, sp, 0, 0, cp);
|
|
63
|
+
|
|
64
|
+
// × roll
|
|
65
|
+
quat3_multiply(out, out_offset, scratch_q[0], scratch_q[1], scratch_q[2], scratch_q[3], 0, 0, sr, cr);
|
|
66
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write the heading of a rotation into `out`: the turn about world up that faces the same horizontal
|
|
3
|
+
* direction the rotation does.
|
|
4
|
+
*
|
|
5
|
+
* @param {Float64Array} out receives 4 floats, x y z w
|
|
6
|
+
* @param {number} qx
|
|
7
|
+
* @param {number} qy
|
|
8
|
+
* @param {number} qz
|
|
9
|
+
* @param {number} qw
|
|
10
|
+
*/
|
|
11
|
+
export function camera_heading_of(out: Float64Array, qx: number, qy: number, qz: number, qw: number): void;
|
|
12
|
+
/**
|
|
13
|
+
* Add an offset to a state's position, given in one of the {@link CameraOffsetFrame}s.
|
|
14
|
+
*
|
|
15
|
+
* @param {Float64Array} state {@link CameraState}
|
|
16
|
+
* @param {number} x
|
|
17
|
+
* @param {number} y
|
|
18
|
+
* @param {number} z
|
|
19
|
+
* @param {number} frame {@link CameraOffsetFrame}
|
|
20
|
+
*/
|
|
21
|
+
export function camera_state_add_offset(state: Float64Array, x: number, y: number, z: number, frame: number): void;
|
|
22
|
+
//# sourceMappingURL=camera_state_add_offset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera_state_add_offset.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/camera/rig/drivers/camera_state_add_offset.js"],"names":[],"mappings":"AAaA;;;;;;;;;GASG;AACH,uCANW,YAAY,MACZ,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAwBhB;AAED;;;;;;;;GAQG;AACH,+CANW,YAAY,KACZ,MAAM,KACN,MAAM,KACN,MAAM,SACN,MAAM,QA0BhB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { v3_quaternion_apply } from "../../../../../core/geom/vec3/v3_quaternion_apply.js";
|
|
2
|
+
import { CAMERA_STATE_POSITION, CAMERA_STATE_ROTATION } from "../CameraState.js";
|
|
3
|
+
import { CameraOffsetFrame } from "./CameraOffsetFrame.js";
|
|
4
|
+
|
|
5
|
+
const scratch = new Float64Array(4);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Below this horizontal length the camera looks straight up or down, and the heading is read from its
|
|
9
|
+
* up instead of its view direction.
|
|
10
|
+
* @type {number}
|
|
11
|
+
*/
|
|
12
|
+
const VERTICAL_EPSILON = 1e-9;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Write the heading of a rotation into `out`: the turn about world up that faces the same horizontal
|
|
16
|
+
* direction the rotation does.
|
|
17
|
+
*
|
|
18
|
+
* @param {Float64Array} out receives 4 floats, x y z w
|
|
19
|
+
* @param {number} qx
|
|
20
|
+
* @param {number} qy
|
|
21
|
+
* @param {number} qz
|
|
22
|
+
* @param {number} qw
|
|
23
|
+
*/
|
|
24
|
+
export function camera_heading_of(out, qx, qy, qz, qw) {
|
|
25
|
+
v3_quaternion_apply(out, 0, 0, 0, 1, qx, qy, qz, qw);
|
|
26
|
+
|
|
27
|
+
let hx = out[0];
|
|
28
|
+
let hz = out[2];
|
|
29
|
+
|
|
30
|
+
if (hx * hx + hz * hz < VERTICAL_EPSILON * VERTICAL_EPSILON) {
|
|
31
|
+
// looking straight down, up points the way the camera faces; straight up, the other way
|
|
32
|
+
const looking_down = out[1] < 0;
|
|
33
|
+
|
|
34
|
+
v3_quaternion_apply(out, 0, 0, 1, 0, qx, qy, qz, qw);
|
|
35
|
+
|
|
36
|
+
hx = looking_down ? out[0] : -out[0];
|
|
37
|
+
hz = looking_down ? out[2] : -out[2];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const half = Math.atan2(hx, hz) * 0.5;
|
|
41
|
+
|
|
42
|
+
out[0] = 0;
|
|
43
|
+
out[1] = Math.sin(half);
|
|
44
|
+
out[2] = 0;
|
|
45
|
+
out[3] = Math.cos(half);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Add an offset to a state's position, given in one of the {@link CameraOffsetFrame}s.
|
|
50
|
+
*
|
|
51
|
+
* @param {Float64Array} state {@link CameraState}
|
|
52
|
+
* @param {number} x
|
|
53
|
+
* @param {number} y
|
|
54
|
+
* @param {number} z
|
|
55
|
+
* @param {number} frame {@link CameraOffsetFrame}
|
|
56
|
+
*/
|
|
57
|
+
export function camera_state_add_offset(state, x, y, z, frame) {
|
|
58
|
+
let wx = x, wy = y, wz = z;
|
|
59
|
+
|
|
60
|
+
if (frame !== CameraOffsetFrame.World) {
|
|
61
|
+
const qx = state[CAMERA_STATE_ROTATION];
|
|
62
|
+
const qy = state[CAMERA_STATE_ROTATION + 1];
|
|
63
|
+
const qz = state[CAMERA_STATE_ROTATION + 2];
|
|
64
|
+
const qw = state[CAMERA_STATE_ROTATION + 3];
|
|
65
|
+
|
|
66
|
+
if (frame === CameraOffsetFrame.Heading) {
|
|
67
|
+
camera_heading_of(scratch, qx, qy, qz, qw);
|
|
68
|
+
v3_quaternion_apply(scratch, 0, x, y, z, scratch[0], scratch[1], scratch[2], scratch[3]);
|
|
69
|
+
} else {
|
|
70
|
+
v3_quaternion_apply(scratch, 0, x, y, z, qx, qy, qz, qw);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
wx = scratch[0];
|
|
74
|
+
wy = scratch[1];
|
|
75
|
+
wz = scratch[2];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
state[CAMERA_STATE_POSITION] += wx;
|
|
79
|
+
state[CAMERA_STATE_POSITION + 1] += wy;
|
|
80
|
+
state[CAMERA_STATE_POSITION + 2] += wz;
|
|
81
|
+
}
|