@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
|
@@ -6,6 +6,7 @@ import Quaternion from "../../../core/geom/Quaternion.js";
|
|
|
6
6
|
import Vector3 from "../../../core/geom/Vector3.js";
|
|
7
7
|
import { clamp } from "../../../core/math/clamp.js";
|
|
8
8
|
import { DEG_TO_RAD } from "../../../core/math/DEG_TO_RAD.js";
|
|
9
|
+
import { exponential_approach } from "../../../core/math/exponential_approach.js";
|
|
9
10
|
import { lerp } from "../../../core/math/lerp.js";
|
|
10
11
|
import { ResourceAccessKind } from "../../../core/model/ResourceAccessKind.js";
|
|
11
12
|
import { ResourceAccessSpecification } from "../../../core/model/ResourceAccessSpecification.js";
|
|
@@ -13,6 +14,13 @@ import { SerializationMetadata } from "../../ecs/components/SerializationMetadat
|
|
|
13
14
|
import Entity from "../../ecs/Entity.js";
|
|
14
15
|
import { System, SystemState } from "../../ecs/System.js";
|
|
15
16
|
import { Transform64 } from "../../ecs/transform/Transform64.js";
|
|
17
|
+
import { camera_rig_cut } from "../../graphics/camera/rig/camera_rig_update.js";
|
|
18
|
+
import { CameraRig } from "../../graphics/camera/rig/CameraRig.js";
|
|
19
|
+
import { CameraFovDriver } from "../../graphics/camera/rig/drivers/CameraFovDriver.js";
|
|
20
|
+
import { CameraOffsetDriver } from "../../graphics/camera/rig/drivers/CameraOffsetDriver.js";
|
|
21
|
+
import { CameraOffsetFrame } from "../../graphics/camera/rig/drivers/CameraOffsetFrame.js";
|
|
22
|
+
import { CameraPositionDriver } from "../../graphics/camera/rig/drivers/CameraPositionDriver.js";
|
|
23
|
+
import { CameraYawPitchRollDriver } from "../../graphics/camera/rig/drivers/CameraYawPitchRollDriver.js";
|
|
16
24
|
import { Camera } from "../../graphics/ecs/camera/Camera.js";
|
|
17
25
|
import { BodyKind } from "../../physics/ecs/BodyKind.js";
|
|
18
26
|
import { Collider } from "../../physics/ecs/Collider.js";
|
|
@@ -21,14 +29,13 @@ import { PhysicsSystem } from "../../physics/ecs/PhysicsSystem.js";
|
|
|
21
29
|
import { RigidBody } from "../../physics/ecs/RigidBody.js";
|
|
22
30
|
import { PhysicsSurfacePoint } from "../../physics/queries/PhysicsSurfacePoint.js";
|
|
23
31
|
import { KinematicMover } from "./collision/KinematicMover.js";
|
|
24
|
-
import { EyeOffsetStack } from "./composer/EyeOffsetStack.js";
|
|
25
32
|
import { FirstPersonPlayerController } from "./FirstPersonPlayerController.js";
|
|
26
33
|
import { DecisionPoint } from "./mastery/DecisionPoint.js";
|
|
27
34
|
import { computeJumpFromApex } from "./math/computeJumpFromApex.js";
|
|
28
35
|
import { computeLRCBreathRate } from "./math/computeLRCBreathRate.js";
|
|
29
36
|
import { computeMassRatios } from "./math/computeMassRatios.js";
|
|
30
37
|
import { jumpForceForHeight, launchVelocityForForce } from "./math/jumpDynamics.js";
|
|
31
|
-
import { Spring } from "
|
|
38
|
+
import { Spring } from "../../../core/math/physics/spring/Spring.js";
|
|
32
39
|
import { stepTowards } from "./math/stepTowards.js";
|
|
33
40
|
import { FirstPersonActionState, FirstPersonLocomotionMode } from "./pose/FirstPersonPose.js";
|
|
34
41
|
import { FirstPersonPosture } from "./pose/FirstPersonPosture.js";
|
|
@@ -40,11 +47,7 @@ import { t64_announce_change } from "../../ecs/transform/t64_announce_change.js"
|
|
|
40
47
|
// Scratch allocations — reused per frame to avoid GC pressure
|
|
41
48
|
// ---------------------------------------------------------------------------
|
|
42
49
|
const SCRATCH_V3_A = new Vector3();
|
|
43
|
-
const SCRATCH_V3_B = new Vector3();
|
|
44
|
-
const SCRATCH_V3_C = new Vector3();
|
|
45
50
|
const SCRATCH_Q_A = new Quaternion();
|
|
46
|
-
const SCRATCH_Q_B = new Quaternion();
|
|
47
|
-
const SCRATCH_Q_C = new Quaternion();
|
|
48
51
|
/** the transform holds its rotation as four numbers, so euler and axis-angle work goes through here */
|
|
49
52
|
const SCRATCH_Q_EULER = new Quaternion();
|
|
50
53
|
|
|
@@ -52,7 +55,6 @@ const SCRATCH_Q_EULER = new Quaternion();
|
|
|
52
55
|
const ZERO_VELOCITY = new Float64Array(3);
|
|
53
56
|
|
|
54
57
|
const TWO_PI = Math.PI * 2;
|
|
55
|
-
const LN2 = Math.log(2);
|
|
56
58
|
|
|
57
59
|
/**
|
|
58
60
|
* Build a posture-sized player capsule: a {@link CapsuleShape3D} of
|
|
@@ -320,9 +322,6 @@ class PerEntityRuntime {
|
|
|
320
322
|
/** Spring for landing dip (under-damped → rings after impact). */
|
|
321
323
|
landSpring = new Spring();
|
|
322
324
|
|
|
323
|
-
/** Spring for FOV (critically damped). */
|
|
324
|
-
fovSpring = new Spring(70);
|
|
325
|
-
|
|
326
325
|
/** Spring for eye height (crouch transition). */
|
|
327
326
|
eyeHeightSpring = new Spring(1.80);
|
|
328
327
|
|
|
@@ -443,14 +442,49 @@ class PerEntityRuntime {
|
|
|
443
442
|
strideFreqHz = 0;
|
|
444
443
|
|
|
445
444
|
/**
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
445
|
+
* The eye's source: the body's render-rate position, written each render frame.
|
|
446
|
+
* @type {CameraPositionDriver}
|
|
447
|
+
*/
|
|
448
|
+
eyePosition = new CameraPositionDriver();
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* The head's yaw, pitch and roll, every contribution summed, written each render frame.
|
|
452
|
+
* @type {CameraYawPitchRollDriver}
|
|
453
|
+
*/
|
|
454
|
+
eyeLook = new CameraYawPitchRollDriver();
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Body-local eye offset (eye height, bob, breath, landing, anticipation, sprint shift), in the
|
|
458
|
+
* head's heading frame, written each render frame.
|
|
459
|
+
* @type {CameraOffsetDriver}
|
|
460
|
+
*/
|
|
461
|
+
eyeOffset = new CameraOffsetDriver();
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Impulses others add to the eye: {@link FirstPersonPlayerController#eyeImpulse}.
|
|
465
|
+
* @type {CameraImpulseDriver|null}
|
|
466
|
+
*/
|
|
467
|
+
eyeImpulse = null;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* The field of view the head wants, sprung by the driver.
|
|
471
|
+
* @type {CameraFovDriver}
|
|
472
|
+
*/
|
|
473
|
+
eyeFov = new CameraFovDriver();
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* The rig on {@link eyeEntity} the drivers above sit in, or null before link places them.
|
|
477
|
+
* @type {CameraRig|null}
|
|
452
478
|
*/
|
|
453
|
-
|
|
479
|
+
eyeRig = null;
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* True iff link added {@link eyeRig} to a caller-supplied eye, so unlink takes it off again;
|
|
483
|
+
* otherwise the drivers were placed at the front of the eye's own rig and unlink takes out only
|
|
484
|
+
* them.
|
|
485
|
+
* @type {boolean}
|
|
486
|
+
*/
|
|
487
|
+
ownsEyeRig = false;
|
|
454
488
|
|
|
455
489
|
/**
|
|
456
490
|
* Spatial-query results populated by {@link FirstPersonSensorsSystem}
|
|
@@ -496,7 +530,9 @@ class PerEntityRuntime {
|
|
|
496
530
|
* - fixedUpdate runs L1 (locomotion), L2 (pose state), and L4 (events) so
|
|
497
531
|
* the simulation remains deterministic.
|
|
498
532
|
* - update runs L3 (camera composition) at render rate so the eye is never
|
|
499
|
-
* smoother than the screen.
|
|
533
|
+
* smoother than the screen. It writes the drivers of the eye's
|
|
534
|
+
* {@link CameraRig}; {@link CameraRigSystem} composes the eye from them, so
|
|
535
|
+
* a world with this system needs that one too.
|
|
500
536
|
*
|
|
501
537
|
* The body is moved by the physics step, onto the pose each fixedUpdate
|
|
502
538
|
* resolves ({@link PhysicsSystem#setTargetPose}). The order the EntityManager
|
|
@@ -524,6 +560,8 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
524
560
|
components_used = [
|
|
525
561
|
ResourceAccessSpecification.from(Transform64, ResourceAccessKind.Write),
|
|
526
562
|
ResourceAccessSpecification.from(Camera, ResourceAccessKind.Write),
|
|
563
|
+
// the eye's driver fields; CameraRigSystem reads them after this writes them
|
|
564
|
+
ResourceAccessSpecification.from(CameraRig, ResourceAccessKind.Write | ResourceAccessKind.Create),
|
|
527
565
|
ResourceAccessSpecification.from(RigidBody, ResourceAccessKind.Write),
|
|
528
566
|
ResourceAccessSpecification.from(Collider, ResourceAccessKind.Write),
|
|
529
567
|
];
|
|
@@ -716,7 +754,7 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
716
754
|
const runtime = new PerEntityRuntime();
|
|
717
755
|
runtime.rigidBody = rigidBody;
|
|
718
756
|
runtime.collider = collider;
|
|
719
|
-
runtime.
|
|
757
|
+
runtime.eyeImpulse = controller.eyeImpulse;
|
|
720
758
|
runtime.notSelf = (other_entity) => other_entity !== entity;
|
|
721
759
|
runtime.solidNotSelf = (other_entity, other_collider, body_id) => {
|
|
722
760
|
if (other_entity === entity) return false;
|
|
@@ -811,9 +849,16 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
811
849
|
|
|
812
850
|
// Initialize springs to standing-eye-height baseline
|
|
813
851
|
runtime.eyeHeightSpring.settle(controller.config.body.height);
|
|
814
|
-
runtime.fovSpring.settle(controller.config.fov.base);
|
|
815
852
|
controller.state.eyeHeight = controller.config.body.height;
|
|
816
853
|
|
|
854
|
+
runtime.eyeOffset.frame = CameraOffsetFrame.Heading;
|
|
855
|
+
runtime.eyeImpulse.frame = CameraOffsetFrame.Heading;
|
|
856
|
+
runtime.eyePosition.set(bodyTransform.translation_x, bodyTransform.translation_y, bodyTransform.translation_z);
|
|
857
|
+
runtime.eyeLook.yaw = runtime.bodyYaw;
|
|
858
|
+
runtime.eyeOffset.set(0, controller.config.body.height, 0);
|
|
859
|
+
runtime.eyeFov.target = controller.config.fov.base;
|
|
860
|
+
runtime.eyeFov.half_life = controller.config.fov.smoothHalfLife;
|
|
861
|
+
|
|
817
862
|
assert.notEqual(
|
|
818
863
|
controller.eyeEntity,
|
|
819
864
|
entity,
|
|
@@ -871,8 +916,14 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
871
916
|
camera.clip_far = 1000;
|
|
872
917
|
camera.autoClip = true;
|
|
873
918
|
|
|
919
|
+
const rig = new CameraRig();
|
|
920
|
+
this._placeEyeDrivers(rig, runtime);
|
|
921
|
+
// link seeds the eye and announces its placement itself, below
|
|
922
|
+
rig.cut_pending = false;
|
|
923
|
+
|
|
874
924
|
eye.add(eyeTransform);
|
|
875
925
|
eye.add(camera);
|
|
926
|
+
eye.add(rig);
|
|
876
927
|
eye.add(SerializationMetadata.Transient);
|
|
877
928
|
|
|
878
929
|
eye.build(ecd);
|
|
@@ -887,11 +938,36 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
887
938
|
controller.eyeEntity = eye.id;
|
|
888
939
|
runtime.eyeEntity = eye.id;
|
|
889
940
|
runtime.ownsEyeEntity = true;
|
|
941
|
+
runtime.eyeRig = rig;
|
|
942
|
+
runtime.ownsEyeRig = false;
|
|
890
943
|
} else {
|
|
891
944
|
const suppliedEye = controller.eyeEntity;
|
|
892
945
|
runtime.eyeEntity = suppliedEye;
|
|
893
946
|
runtime.ownsEyeEntity = false;
|
|
894
947
|
|
|
948
|
+
let rig = ecd.getComponent(suppliedEye, CameraRig);
|
|
949
|
+
|
|
950
|
+
if (rig === undefined) {
|
|
951
|
+
rig = new CameraRig();
|
|
952
|
+
this._placeEyeDrivers(rig, runtime);
|
|
953
|
+
// link seeds the eye and announces its placement itself, below
|
|
954
|
+
rig.cut_pending = false;
|
|
955
|
+
|
|
956
|
+
if (!ecd.isComponentTypeRegistered(CameraRig)) {
|
|
957
|
+
ecd.registerComponentType(CameraRig);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
ecd.addComponentToEntity(suppliedEye, rig);
|
|
961
|
+
|
|
962
|
+
runtime.ownsEyeRig = true;
|
|
963
|
+
} else {
|
|
964
|
+
this._placeEyeDrivers(rig, runtime);
|
|
965
|
+
|
|
966
|
+
runtime.ownsEyeRig = false;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
runtime.eyeRig = rig;
|
|
970
|
+
|
|
895
971
|
const eyeTransform = ecd.getComponent(suppliedEye, Transform64);
|
|
896
972
|
if (eyeTransform !== undefined) {
|
|
897
973
|
eyeTransform.setTranslation(baseEyeX, baseEyeY, baseEyeZ);
|
|
@@ -947,15 +1023,66 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
947
1023
|
if (controller.eyeEntity === runtime.eyeEntity) {
|
|
948
1024
|
controller.eyeEntity = -1;
|
|
949
1025
|
}
|
|
1026
|
+
} else if (runtime.eyeRig !== null) {
|
|
1027
|
+
this._removeEyeDrivers(ecd, runtime);
|
|
950
1028
|
}
|
|
1029
|
+
runtime.eyeRig = null;
|
|
951
1030
|
this._releaseBody(ecd, entity, runtime, bodyTransform);
|
|
952
1031
|
}
|
|
953
1032
|
|
|
954
|
-
controller.
|
|
1033
|
+
controller.eyeImpulse.clear();
|
|
955
1034
|
|
|
956
1035
|
this.runtime.delete(entity);
|
|
957
1036
|
}
|
|
958
1037
|
|
|
1038
|
+
/**
|
|
1039
|
+
* Put the eye's drivers at the front of `rig`, in the order they compose: position, look, offset,
|
|
1040
|
+
* impulse, field of view. Drivers already in the rig apply after them.
|
|
1041
|
+
*
|
|
1042
|
+
* @private
|
|
1043
|
+
* @param {CameraRig} rig
|
|
1044
|
+
* @param {PerEntityRuntime} runtime
|
|
1045
|
+
*/
|
|
1046
|
+
_placeEyeDrivers(rig, runtime) {
|
|
1047
|
+
rig.drivers.unshift(
|
|
1048
|
+
runtime.eyePosition,
|
|
1049
|
+
runtime.eyeLook,
|
|
1050
|
+
runtime.eyeOffset,
|
|
1051
|
+
runtime.eyeImpulse,
|
|
1052
|
+
runtime.eyeFov
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Take the eye's drivers back out of a caller-supplied eye: the whole rig when link added it, only
|
|
1058
|
+
* the drivers when the rig was the eye's own.
|
|
1059
|
+
*
|
|
1060
|
+
* @private
|
|
1061
|
+
* @param {import("../../ecs/EntityComponentDataset.js").EntityComponentDataset} ecd
|
|
1062
|
+
* @param {PerEntityRuntime} runtime
|
|
1063
|
+
*/
|
|
1064
|
+
_removeEyeDrivers(ecd, runtime) {
|
|
1065
|
+
const rig = runtime.eyeRig;
|
|
1066
|
+
const eye = runtime.eyeEntity;
|
|
1067
|
+
|
|
1068
|
+
if (runtime.ownsEyeRig) {
|
|
1069
|
+
if (eye !== -1 && ecd.entityExists(eye) && ecd.getComponent(eye, CameraRig) === rig) {
|
|
1070
|
+
ecd.removeComponentFromEntity(eye, CameraRig);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
const mine = [runtime.eyePosition, runtime.eyeLook, runtime.eyeOffset, runtime.eyeImpulse, runtime.eyeFov];
|
|
1077
|
+
const drivers = rig.drivers;
|
|
1078
|
+
|
|
1079
|
+
for (let i = drivers.length - 1; i >= 0; i--) {
|
|
1080
|
+
if (mine.includes(drivers[i])) {
|
|
1081
|
+
drivers.splice(i, 1);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
|
|
959
1086
|
/**
|
|
960
1087
|
* Leave the body standing where the controller last put it. The velocities a target pose
|
|
961
1088
|
* derives stay on the body after its step, so a body the controller stops driving would walk
|
|
@@ -1263,8 +1390,8 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
1263
1390
|
cfg.breath.locomotorCouplingMax,
|
|
1264
1391
|
cfg.breath.couplingMinStrideFreqHz,
|
|
1265
1392
|
);
|
|
1266
|
-
state.breathRateHz =
|
|
1267
|
-
state.breathAmplitudeM =
|
|
1393
|
+
state.breathRateHz = exponential_approach(state.breathRateHz, targetRate, cfg.exertion.rateDecayHalfLife, dt);
|
|
1394
|
+
state.breathAmplitudeM = exponential_approach(state.breathAmplitudeM, targetAmp, cfg.exertion.ampDecayHalfLife, dt);
|
|
1268
1395
|
|
|
1269
1396
|
runtime.prevBreathPhase = state.breathPhase;
|
|
1270
1397
|
state.breathPhase += state.breathRateHz * dt;
|
|
@@ -2089,8 +2216,8 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
2089
2216
|
/ runtime.massRatios.groundAccelScale
|
|
2090
2217
|
/ controller.mastery.evaluate(DecisionPoint.GroundAccel, controller, runtime);
|
|
2091
2218
|
if (isBackwardIntent) halfLife /= cfg.motion.backwardAccelFactor;
|
|
2092
|
-
runtime.velocityX =
|
|
2093
|
-
runtime.velocityZ =
|
|
2219
|
+
runtime.velocityX = exponential_approach(runtime.velocityX, desiredHorizontalVx, halfLife, dt);
|
|
2220
|
+
runtime.velocityZ = exponential_approach(runtime.velocityZ, desiredHorizontalVz, halfLife, dt);
|
|
2094
2221
|
}
|
|
2095
2222
|
|
|
2096
2223
|
// -- L1.e/f/g/h: jump FSM + vertical integration --------------
|
|
@@ -2389,7 +2516,10 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
2389
2516
|
}
|
|
2390
2517
|
|
|
2391
2518
|
/**
|
|
2392
|
-
*
|
|
2519
|
+
* Write the eye's drivers for this render frame: the body's render-rate position, the head's yaw,
|
|
2520
|
+
* pitch and roll, the body-local offset of eye height, bob, breath, landing, jump anticipation and
|
|
2521
|
+
* sprint posture, and the field of view the head wants. The eye's {@link CameraRig} composes them,
|
|
2522
|
+
* with the impulses others add, when {@link CameraRigSystem} runs.
|
|
2393
2523
|
* @private
|
|
2394
2524
|
* @param {FirstPersonPlayerController} controller
|
|
2395
2525
|
* @param {number} entity
|
|
@@ -2400,7 +2530,6 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
2400
2530
|
if (runtime === undefined) return;
|
|
2401
2531
|
|
|
2402
2532
|
const dt = this._currentRenderDt;
|
|
2403
|
-
const stack = runtime.eyeOffsetStack;
|
|
2404
2533
|
|
|
2405
2534
|
// Consume mouse-look at RENDER rate so the camera direction tracks the
|
|
2406
2535
|
// mouse smoothly, decoupled from the aliased 60Hz sim sampling. `dt` goes
|
|
@@ -2409,34 +2538,14 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
2409
2538
|
const cfg = controller.config;
|
|
2410
2539
|
const state = controller.state;
|
|
2411
2540
|
|
|
2412
|
-
|
|
2413
|
-
if (bodyTransform === undefined) {
|
|
2414
|
-
stack.step(dt);
|
|
2415
|
-
stack.clear();
|
|
2541
|
+
if (ecd.getComponent(entity, Transform64) === undefined) {
|
|
2416
2542
|
return;
|
|
2417
2543
|
}
|
|
2418
2544
|
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
return;
|
|
2424
|
-
}
|
|
2425
|
-
const eyeTransform = ecd.getComponent(eyeEntity, Transform64);
|
|
2426
|
-
if (eyeTransform === undefined) {
|
|
2427
|
-
stack.step(dt);
|
|
2428
|
-
stack.clear();
|
|
2429
|
-
return;
|
|
2430
|
-
}
|
|
2431
|
-
const camera = ecd.getComponent(eyeEntity, Camera);
|
|
2432
|
-
|
|
2433
|
-
// -- Body-local eye offset, composed via the additive stack ----
|
|
2434
|
-
// External single-frame pushes queued since the previous compose are
|
|
2435
|
-
// already in `stack.offset`. Built-in offsets and decaying 3D spring
|
|
2436
|
-
// impulses add onto the same body-local sum first so `onCompose`
|
|
2437
|
-
// listeners can inspect or clamp the full offset before it is written
|
|
2438
|
-
// to the eye transform and cleared.
|
|
2439
|
-
stack.push("eyeHeight", 0, state.eyeHeight, 0);
|
|
2545
|
+
// -- Body-local eye offset ------------------------------------
|
|
2546
|
+
let offsetX = 0;
|
|
2547
|
+
let offsetY = state.eyeHeight;
|
|
2548
|
+
let offsetZ = 0;
|
|
2440
2549
|
|
|
2441
2550
|
// Bob — gated on grounded only (the impact spring decays naturally
|
|
2442
2551
|
// even at rest, so the bob fade-out is smooth; lateral amp uses the
|
|
@@ -2455,34 +2564,33 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
2455
2564
|
|
|
2456
2565
|
// Vertical: read directly from the impact spring (footfall kicks,
|
|
2457
2566
|
// under-damped recovery → trough + leg-push overshoot).
|
|
2458
|
-
|
|
2567
|
+
offsetY += runtime.verticalImpactSpring.value;
|
|
2459
2568
|
|
|
2460
2569
|
// Lateral: head shifts toward the foot bearing weight. Polarity
|
|
2461
2570
|
// sourced from runtime.standingFoot — the same signal the
|
|
2462
2571
|
// footstep emits — so bob direction and footstep side agree.
|
|
2463
2572
|
// |sin(phase)| is the non-negative "midstance envelope".
|
|
2464
2573
|
const lateralPolarity = runtime.standingFoot === "R" ? -1 : 1;
|
|
2465
|
-
|
|
2574
|
+
offsetX += ampL * lateralPolarity * Math.abs(Math.sin(phase));
|
|
2466
2575
|
}
|
|
2467
2576
|
|
|
2468
2577
|
// Breath — sine + tiny noise riding the rate spring.
|
|
2469
|
-
|
|
2578
|
+
offsetY += -state.breathAmplitudeM
|
|
2470
2579
|
* Math.sin(state.breathPhase * TWO_PI)
|
|
2471
2580
|
* (1 + cfg.breath.noiseAmount * (Math.sin(state.breathPhase * 13.7) * 0.5));
|
|
2472
|
-
stack.push("breath", 0, breathOffset, 0);
|
|
2473
2581
|
|
|
2474
2582
|
// Landing spring dip (under-damped — overshoots once on recovery).
|
|
2475
|
-
|
|
2583
|
+
offsetY += runtime.landSpring.value;
|
|
2476
2584
|
|
|
2477
2585
|
// Jump anticipation dip (eased ramp during the squash window).
|
|
2478
2586
|
if (state.inJumpAnticipation) {
|
|
2479
2587
|
const t = 1 - clamp(runtime.anticipationRemaining / Math.max(cfg.jump.anticipation.duration, 1e-3), 0, 1);
|
|
2480
2588
|
const eased = t * (2 - t); // ease-out quad
|
|
2481
|
-
|
|
2589
|
+
offsetY += -cfg.jump.anticipation.dipAmount * eased;
|
|
2482
2590
|
}
|
|
2483
2591
|
|
|
2484
2592
|
// Sprint posture: head leans slightly forward as commitment builds.
|
|
2485
|
-
// Pitch part is in the rotation
|
|
2593
|
+
// Pitch part is in the rotation below; the +Z position shift
|
|
2486
2594
|
// sells "head leading the hips" (Mirror's Edge), tied to the same
|
|
2487
2595
|
// spring envelope so they move together.
|
|
2488
2596
|
const sprintPitch = runtime.sprintPostureSpring.value;
|
|
@@ -2490,78 +2598,30 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
2490
2598
|
cfg.posture.sprintForwardPitchDeg > 0
|
|
2491
2599
|
? sprintPitch / (cfg.posture.sprintForwardPitchDeg * DEG_TO_RAD)
|
|
2492
2600
|
: 0;
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
stack.step(dt);
|
|
2496
|
-
|
|
2497
|
-
if (stack.onCompose.hasHandlers()) {
|
|
2498
|
-
stack.dispatchCompose(dt);
|
|
2499
|
-
if (this.runtime.get(entity) !== runtime) {
|
|
2500
|
-
let relinked = false;
|
|
2501
|
-
for (const activeRuntime of this.runtime.values()) {
|
|
2502
|
-
if (activeRuntime.eyeOffsetStack === stack) {
|
|
2503
|
-
relinked = true;
|
|
2504
|
-
break;
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
if (!relinked) {
|
|
2508
|
-
stack.reset();
|
|
2509
|
-
}
|
|
2510
|
-
return;
|
|
2511
|
-
}
|
|
2512
|
-
eyeEntity = controller.eyeEntity;
|
|
2513
|
-
if (eyeEntity === -1
|
|
2514
|
-
|| eyeEntity === entity
|
|
2515
|
-
|| ecd.getComponent(eyeEntity, Transform64) !== eyeTransform) {
|
|
2516
|
-
stack.clear();
|
|
2517
|
-
return;
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2601
|
+
offsetZ += cfg.posture.sprintForwardShiftM * sprintShiftFraction;
|
|
2520
2602
|
|
|
2521
2603
|
// Body POSITION advances only at the fixed step → blend the last two
|
|
2522
2604
|
// steps by the engine's sub-step alpha (the same fraction the
|
|
2523
2605
|
// InterpolationSystem uses for physics bodies) so it's smooth on a high-
|
|
2524
2606
|
// refresh display. Yaw + pitch are already render-rate (consumed in
|
|
2525
2607
|
// _consumeLook), so they're used directly — no blend, no aliasing.
|
|
2526
|
-
const placed = runtime.eyePlacementPending;
|
|
2527
|
-
runtime.eyePlacementPending = false;
|
|
2528
2608
|
const alpha = this.entityManager.getFixedStepAlpha();
|
|
2529
2609
|
const iPosX = lerp(runtime.renderPrevPos.x, runtime.renderCurPos.x, alpha);
|
|
2530
2610
|
const iPosY = lerp(runtime.renderPrevPos.y, runtime.renderCurPos.y, alpha);
|
|
2531
2611
|
const iPosZ = lerp(runtime.renderPrevPos.z, runtime.renderCurPos.z, alpha);
|
|
2532
|
-
const qYaw0 = SCRATCH_Q_A.fromAxisAngle(Vector3.up, runtime.bodyYaw);
|
|
2533
|
-
|
|
2534
|
-
// Transform body-local accumulated offset into world space (about the
|
|
2535
|
-
// render-rate yaw, to match the interpolated base position), then
|
|
2536
|
-
// clear the per-frame sum for the next render pass.
|
|
2537
|
-
const worldOffset = SCRATCH_V3_B.copy(stack.offset);
|
|
2538
|
-
stack.clear();
|
|
2539
|
-
worldOffset.applyQuaternion(qYaw0);
|
|
2540
|
-
|
|
2541
|
-
const prevTx = eyeTransform.translation_x;
|
|
2542
|
-
const prevTy = eyeTransform.translation_y;
|
|
2543
|
-
const prevTz = eyeTransform.translation_z;
|
|
2544
|
-
const prevRx = eyeTransform.rotation_x;
|
|
2545
|
-
const prevRy = eyeTransform.rotation_y;
|
|
2546
|
-
const prevRz = eyeTransform.rotation_z;
|
|
2547
|
-
const prevRw = eyeTransform.rotation_w;
|
|
2548
|
-
|
|
2549
|
-
const nextTx = iPosX + worldOffset.x;
|
|
2550
|
-
const nextTy = iPosY + worldOffset.y;
|
|
2551
|
-
const nextTz = iPosZ + worldOffset.z;
|
|
2552
2612
|
|
|
2553
2613
|
// -- Eye rotation: body yaw × eye pitch × roll -------------------
|
|
2554
2614
|
// Bob roll mixes in for a subtle head sway (in phase with lateral bob).
|
|
2555
2615
|
// Breath pitch is a small extra nod 90° out of phase with vertical
|
|
2556
|
-
// breath; merged into the main pitch so
|
|
2557
|
-
//
|
|
2616
|
+
// breath; merged into the main pitch so the composition stays a
|
|
2617
|
+
// single yaw × pitch × roll.
|
|
2558
2618
|
let rollTotal = state.leanRollRad;
|
|
2559
2619
|
if (state.grounded) {
|
|
2560
2620
|
// Roll: head tilts toward the standing foot, in phase with the
|
|
2561
2621
|
// lateral sway. Polarity sourced from runtime.standingFoot for
|
|
2562
|
-
// consistency with the lateral bob. Positive
|
|
2563
|
-
//
|
|
2564
|
-
//
|
|
2622
|
+
// consistency with the lateral bob. Positive roll = head tilts
|
|
2623
|
+
// RIGHT, so R-foot midstance = positive roll, L-foot midstance =
|
|
2624
|
+
// negative roll.
|
|
2565
2625
|
const phase = state.stridePhase * TWO_PI;
|
|
2566
2626
|
const rollBackMult = 1 + (cfg.bob.backwardRollFactor - 1) * runtime.backwardness;
|
|
2567
2627
|
const ampRoll = cfg.bob.rollAtWalkDeg * DEG_TO_RAD * runtime.bobIntensitySpring.value * rollBackMult;
|
|
@@ -2593,50 +2653,27 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
2593
2653
|
+ runtime.sprintPostureSpring.value
|
|
2594
2654
|
+ runtime.headDroopSpring.value;
|
|
2595
2655
|
|
|
2596
|
-
// composition: yaw * pitch * roll
|
|
2597
|
-
// pitch around world X — yaw applied after, so effective axis is camera-local right
|
|
2598
|
-
// roll around world Z — yaw and pitch applied after, so effective axis is camera-local forward
|
|
2599
|
-
const qYaw = qYaw0; // SCRATCH_Q_A, already the render-rate yaw
|
|
2600
|
-
const qPitch = SCRATCH_Q_B.fromAxisAngle(Vector3.right, pitchTotal);
|
|
2601
|
-
const qRoll = SCRATCH_Q_C.fromAxisAngle(Vector3.forward, rollTotal);
|
|
2602
|
-
|
|
2603
|
-
// composed in a scratch: a transform keeps its rotation as four numbers and has no
|
|
2604
|
-
// quaternion product of its own
|
|
2605
|
-
SCRATCH_Q_EULER.multiplyQuaternions(qYaw, qPitch);
|
|
2606
|
-
SCRATCH_Q_EULER.multiply(qRoll);
|
|
2607
|
-
|
|
2608
|
-
const nextRx = SCRATCH_Q_EULER.x;
|
|
2609
|
-
const nextRy = SCRATCH_Q_EULER.y;
|
|
2610
|
-
const nextRz = SCRATCH_Q_EULER.z;
|
|
2611
|
-
const nextRw = SCRATCH_Q_EULER.w;
|
|
2612
|
-
|
|
2613
2656
|
// Dev-only camera-output guard (compiled out of prod). The composed eye
|
|
2614
|
-
//
|
|
2615
|
-
//
|
|
2616
|
-
//
|
|
2657
|
+
// is exactly what the player sees; if a spring (head-droop, breath nod)
|
|
2658
|
+
// or lean ever drove pitch/roll to NaN, the camera would snap to
|
|
2659
|
+
// garbage. Assert it here, at the source of the visible jump.
|
|
2617
2660
|
assert.ok(
|
|
2618
|
-
Number.isFinite(
|
|
2661
|
+
Number.isFinite(iPosX + offsetX) && Number.isFinite(iPosY + offsetY) && Number.isFinite(iPosZ + offsetZ),
|
|
2619
2662
|
"FP invariant: composed eye translation is non-finite (camera position corrupted)",
|
|
2620
2663
|
);
|
|
2621
2664
|
assert.ok(
|
|
2622
|
-
Number.isFinite(
|
|
2665
|
+
Number.isFinite(runtime.bodyYaw) && Number.isFinite(pitchTotal) && Number.isFinite(rollTotal),
|
|
2623
2666
|
"FP invariant: composed eye rotation is non-finite (camera direction corrupted)",
|
|
2624
2667
|
);
|
|
2625
2668
|
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
if (poseChanged) {
|
|
2636
|
-
eyeTransform.setTranslation(nextTx, nextTy, nextTz);
|
|
2637
|
-
eyeTransform.setRotation(nextRx, nextRy, nextRz, nextRw);
|
|
2638
|
-
eyeTransform.updateMatrix();
|
|
2639
|
-
}
|
|
2669
|
+
runtime.eyePosition.set(iPosX, iPosY, iPosZ);
|
|
2670
|
+
|
|
2671
|
+
const look = runtime.eyeLook;
|
|
2672
|
+
look.yaw = runtime.bodyYaw;
|
|
2673
|
+
look.pitch = pitchTotal;
|
|
2674
|
+
look.roll = rollTotal;
|
|
2675
|
+
|
|
2676
|
+
runtime.eyeOffset.set(offsetX, offsetY, offsetZ);
|
|
2640
2677
|
|
|
2641
2678
|
// -- FOV ---------------------------------------------------------
|
|
2642
2679
|
let fovTarget = cfg.fov.base;
|
|
@@ -2645,28 +2682,17 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
2645
2682
|
}
|
|
2646
2683
|
if (state.crouchActive) fovTarget += cfg.fov.crouchAdd;
|
|
2647
2684
|
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
: ecd.getComponent(eyeEntity, Camera);
|
|
2652
|
-
if (liveCamera !== undefined) {
|
|
2653
|
-
liveCamera.fov.set(runtime.fovSpring.value);
|
|
2654
|
-
}
|
|
2685
|
+
const fov = runtime.eyeFov;
|
|
2686
|
+
fov.target = fovTarget;
|
|
2687
|
+
fov.half_life = cfg.fov.smoothHalfLife;
|
|
2655
2688
|
|
|
2656
|
-
//
|
|
2657
|
-
//
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
&& ecd.getComponent(eyeEntity, Transform64) === eyeTransform) {
|
|
2664
|
-
t64_announce_change(ecd, eyeEntity);
|
|
2665
|
-
if (placed
|
|
2666
|
-
&& this.runtime.get(entity) === runtime
|
|
2667
|
-
&& ecd.entityExists(eyeEntity)
|
|
2668
|
-
&& ecd.getComponent(eyeEntity, Transform64) === eyeTransform) {
|
|
2669
|
-
ecd.sendEvent(eyeEntity, TRANSFORM64_EVENT_PLACED);
|
|
2689
|
+
// A warp of the body is a cut of the eye: no glide across the jump, and the eye announces
|
|
2690
|
+
// the placement, which TransformAttachment children, GPUSceneRows and fluid wakes follow.
|
|
2691
|
+
if (runtime.eyePlacementPending) {
|
|
2692
|
+
runtime.eyePlacementPending = false;
|
|
2693
|
+
|
|
2694
|
+
if (runtime.eyeRig !== null) {
|
|
2695
|
+
camera_rig_cut(runtime.eyeRig);
|
|
2670
2696
|
}
|
|
2671
2697
|
}
|
|
2672
2698
|
}
|
|
@@ -2676,20 +2702,6 @@ export class FirstPersonPlayerControllerSystem extends System {
|
|
|
2676
2702
|
// helpers
|
|
2677
2703
|
// ---------------------------------------------------------------------------
|
|
2678
2704
|
|
|
2679
|
-
/**
|
|
2680
|
-
* Exponential approach with half-life parameterization.
|
|
2681
|
-
* @param {number} current
|
|
2682
|
-
* @param {number} target
|
|
2683
|
-
* @param {number} halfLife
|
|
2684
|
-
* @param {number} dt
|
|
2685
|
-
* @returns {number}
|
|
2686
|
-
*/
|
|
2687
|
-
function exponentialApproach(current, target, halfLife, dt) {
|
|
2688
|
-
if (halfLife <= 0) return target;
|
|
2689
|
-
const alpha = 1 - Math.exp(-LN2 * dt / halfLife);
|
|
2690
|
-
return current + (target - current) * alpha;
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
2705
|
/**
|
|
2694
2706
|
* Detect that phase value crossed a boundary in [0,1) between two ticks.
|
|
2695
2707
|
* Handles the wraparound case where phase jumps from e.g. 0.95 to 0.05.
|
|
@@ -10,7 +10,9 @@ import HeadsUpDisplay from "./HeadsUpDisplay.js";
|
|
|
10
10
|
import HeadsUpDisplaySystem from "./HeadsUpDisplaySystem.js";
|
|
11
11
|
import { EngineConfiguration } from "../../../EngineConfiguration.js";
|
|
12
12
|
import { camera_find_active } from "../../../graphics/ecs/camera/camera_find_active.js";
|
|
13
|
-
import
|
|
13
|
+
import { camera_rig_find_driver } from "../../../graphics/camera/rig/camera_rig_update.js";
|
|
14
|
+
import { CameraRig } from "../../../graphics/camera/rig/CameraRig.js";
|
|
15
|
+
import { CameraOrbitDriver } from "../../../graphics/camera/rig/drivers/CameraOrbitDriver.js";
|
|
14
16
|
|
|
15
17
|
const eh = new EngineHarness();
|
|
16
18
|
|
|
@@ -104,7 +106,7 @@ async function main(engine) {
|
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
const active_camera = camera_find_active(ecd);
|
|
107
|
-
const controller = ecd.getComponent(active_camera.entity,
|
|
109
|
+
const controller = camera_rig_find_driver(ecd.getComponent(active_camera.entity, CameraRig), CameraOrbitDriver);
|
|
108
110
|
|
|
109
111
|
window.__hud_edge_stick_test = {
|
|
110
112
|
engine,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The entity at the top of `entity`'s lifetime chain: follow {@link ParentEntity} until an entity has
|
|
3
|
+
* none. Two entities with the same root belong to the same thing, which is how a cast tells a
|
|
4
|
+
* character's own colliders from the world's.
|
|
5
|
+
*
|
|
6
|
+
* @param {EntityComponentDataset} dataset
|
|
7
|
+
* @param {number} entity
|
|
8
|
+
* @returns {number} `entity` itself when it has no parent
|
|
9
|
+
*/
|
|
10
|
+
export function parent_entity_root_of(dataset: EntityComponentDataset, entity: number): number;
|
|
11
|
+
//# sourceMappingURL=parent_entity_root_of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parent_entity_root_of.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/parent/parent_entity_root_of.js"],"names":[],"mappings":"AAQA;;;;;;;;GAQG;AACH,+EAHW,MAAM,GACJ,MAAM,CAgBlB"}
|