@threenative/physics 0.3.11 → 0.3.13

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.
@@ -359,6 +359,8 @@ declare class CollisionShape3D {
359
359
  y: number;
360
360
  z: number;
361
361
  }): CollisionShape3D;
362
+ /** Godot's ConcavePolygonShape3D: x, y, z vertex triples in body-local metres and triangle indices. */
363
+ static trimesh(vertices: Float32Array, indices: Uint32Array): CollisionShape3D;
362
364
  static fromMesh(mesh: Mesh, kind?: CollisionShapeKind): CollisionShape3D;
363
365
  setCollisionGroups(groups: number): this;
364
366
  setSensor(sensor: boolean): this;
@@ -556,7 +558,45 @@ interface ICharacterBody3DOptions {
556
558
  * which reads as a physics bug rather than a default.
557
559
  */
558
560
  readonly pushesDynamicBodies?: boolean;
559
- }
561
+ /**
562
+ * The water surface height in metres at world (x, z), or `undefined` where there is none. With
563
+ * it the body swims the way Unreal's CharacterMovementComponent does: once its centre is under
564
+ * the surface it is `swimming`, buoyancy and fluid friction replace gravity, and its horizontal
565
+ * speed is held to `maxSwimSpeed`; shallower water only slows it. Without it nothing changes.
566
+ */
567
+ readonly water?: CharacterWaterQuery;
568
+ /**
569
+ * The water's own velocity at world (x, z) in m/s, or `undefined` where there is none. While any
570
+ * part of the body is under water it is carried downstream, added to its horizontal motion before
571
+ * its own move input: a swimmer floats at the river's full speed, and a wader, whose feet hold the
572
+ * bed, takes a share that grows with depth until its centre goes under. Unreal pushes a body in a
573
+ * river towards the spline's own velocity while it moves slower than the water, so a floating body
574
+ * settles at the water's speed (UE 5.8.3:
575
+ * Engine/Plugins/Experimental/Water/Source/Runtime/Private/BuoyancyComponent.cpp:724-753).
576
+ * Without it nothing changes.
577
+ */
578
+ readonly waterCurrent?: CharacterWaterCurrentQuery;
579
+ /**
580
+ * Unreal's `Buoyancy`: the body floats where `buoyancy * immersionDepth = 1`. Default 1.6, which
581
+ * floats it with its centre just under the surface. Unreal ships 1.0, which is neutral: the body
582
+ * drifts to the bottom.
583
+ */
584
+ readonly buoyancy?: number;
585
+ /** Unreal's `MaxSwimSpeed` in m/s: half its walk speed. Default 3. */
586
+ readonly maxSwimSpeed?: number;
587
+ /**
588
+ * Unreal's water-volume `FluidFriction`, applied to vertical speed while swimming. Default 12,
589
+ * which settles a swimmer in about a second; Unreal's 0.3 bobs it for many seconds.
590
+ */
591
+ readonly fluidFriction?: number;
592
+ }
593
+ /** Water surface height at world (x, z), or `undefined` where there is no water. */
594
+ type CharacterWaterQuery = (x: number, z: number) => number | undefined;
595
+ /** The water's own velocity in m/s at world (x, z), or `undefined` where there is no water. */
596
+ type CharacterWaterCurrentQuery = (x: number, z: number) => {
597
+ x: number;
598
+ z: number;
599
+ } | undefined;
560
600
  declare class CharacterBody3D {
561
601
  #private;
562
602
  readonly body: IPhysicsBodyHandle;
@@ -575,6 +615,28 @@ declare class CharacterBody3D {
575
615
  groundBody: IPhysicsBodyHandle | undefined;
576
616
  /** Radians between `groundNormal` and world up (+Y). */
577
617
  slopeAngle: number;
618
+ /** See `ICharacterBody3DOptions.water`; assign it once the water exists. */
619
+ water: CharacterWaterQuery | undefined;
620
+ /** See `ICharacterBody3DOptions.waterCurrent`; assign it once the water exists. */
621
+ waterCurrent: CharacterWaterCurrentQuery | undefined;
622
+ /**
623
+ * The water's own velocity the last `moveAndSlide` applied, in m/s: the full current while
624
+ * swimming, a depth-weighted share of it while wading, `(0, 0)` out of water. Read it to tell a
625
+ * drift from a step.
626
+ */
627
+ readonly currentVelocity: {
628
+ x: number;
629
+ z: number;
630
+ };
631
+ buoyancy: number;
632
+ maxSwimSpeed: number;
633
+ fluidFriction: number;
634
+ /** True while the body's centre is under the water surface (Unreal's MOVE_Swimming). */
635
+ swimming: boolean;
636
+ /** Unreal's `ImmersionDepth`: the share of the collider's height under water, 0 to 1. */
637
+ immersionDepth: number;
638
+ /** The water surface height the last `moveAndSlide` read, or `undefined` out of water. */
639
+ waterSurface: number | undefined;
578
640
  /** Draw between solved ticks; false presents this body at its true tick pose. */
579
641
  get interpolate(): boolean;
580
642
  set interpolate(enabled: boolean);
@@ -784,6 +846,11 @@ interface IPhysicsContext {
784
846
  readonly y: number;
785
847
  readonly z: number;
786
848
  } | undefined;
849
+ /**
850
+ * False for ground that can move with no notice: a dynamic `RigidBody3D` or another character.
851
+ * A `CharacterBody3D` standing on such ground keeps taking its gravity step, so it follows it.
852
+ */
853
+ groundHolds?(bodyId: number): boolean;
787
854
  remove(body: PhysicsBody3D): void;
788
855
  addArea(area: Area3D): void;
789
856
  removeArea(area: Area3D): void;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { I as IPhysicsContext, a as IPhysicsWorldHandle, b as IPhysicsBodyHandle, c as IPhysicsVector3, d as IPhysicsRotation, e as IPhysicsJointLimit, R as RigidBody3D, f as IPhysicsColliderHandle, P as PhysicsBody3D, C as CollisionShape3D, g as IPhysicsVehicleWheelOptions } from './Area3D-AgKEDg0q.js';
2
- export { A as Area3D, B as Buoyancy3D, h as BuoyancyPointPosition, i as CharacterBody3D, j as IBuoyancy3DOptions, k as IBuoyancyHullPoint, l as IBuoyancySurface, m as IBuoyancySurfaceSample, n as ICollisionShapeHandle, o as IIntersectPointOptions, p as IIntersectRayOptions, q as IIntersectShapeOptions, r as IPhysicsBodyCreateOptions, s as IPhysicsCharacterOptions, t as IPhysicsHandle, u as IPhysicsInputSnapshot, v as IPhysicsJointCreateOptions, w as IPhysicsPointQuery, x as IPhysicsQueryHit, y as IPhysicsRayHit, z as IPhysicsRayQuery, D as IPhysicsRuntimeSimulation, E as IPhysicsShapeDescriptor, F as IPhysicsShapeQuery, G as IPhysicsSimulation, H as IPhysicsVehicleCreateOptions, J as IPhysicsVehicleInput, K as IPhysicsVehicleState, L as IPointHit, M as IRayHit, N as IRigidBody3DOptions, O as IShapeHit, Q as MAX_PHYSICS_QUERY_RESULTS, S as PHYSICS_COLLISION_EVENT_STRIDE, T as PHYSICS_TRANSFORM_STRIDE, U as PHYSICS_VEHICLE_WHEEL_STRIDE, V as PhysicsDirectSpaceState3D, W as PhysicsJointKind, X as PhysicsQueryVector3, Y as PhysicsShapeKind, Z as RigidBodyType, _ as rapier } from './Area3D-AgKEDg0q.js';
3
- import { Object3D } from 'three';
1
+ import { I as IPhysicsContext, a as IPhysicsWorldHandle, b as IPhysicsBodyHandle, c as IPhysicsVector3, d as IPhysicsRotation, e as IPhysicsJointLimit, R as RigidBody3D, f as IPhysicsColliderHandle, P as PhysicsBody3D, C as CollisionShape3D, g as IPhysicsVehicleWheelOptions } from './Area3D-CyRWumWF.js';
2
+ export { A as Area3D, B as Buoyancy3D, h as BuoyancyPointPosition, i as CharacterBody3D, j as IBuoyancy3DOptions, k as IBuoyancyHullPoint, l as IBuoyancySurface, m as IBuoyancySurfaceSample, n as ICollisionShapeHandle, o as IIntersectPointOptions, p as IIntersectRayOptions, q as IIntersectShapeOptions, r as IPhysicsBodyCreateOptions, s as IPhysicsCharacterOptions, t as IPhysicsHandle, u as IPhysicsInputSnapshot, v as IPhysicsJointCreateOptions, w as IPhysicsPointQuery, x as IPhysicsQueryHit, y as IPhysicsRayHit, z as IPhysicsRayQuery, D as IPhysicsRuntimeSimulation, E as IPhysicsShapeDescriptor, F as IPhysicsShapeQuery, G as IPhysicsSimulation, H as IPhysicsVehicleCreateOptions, J as IPhysicsVehicleInput, K as IPhysicsVehicleState, L as IPointHit, M as IRayHit, N as IRigidBody3DOptions, O as IShapeHit, Q as MAX_PHYSICS_QUERY_RESULTS, S as PHYSICS_COLLISION_EVENT_STRIDE, T as PHYSICS_TRANSFORM_STRIDE, U as PHYSICS_VEHICLE_WHEEL_STRIDE, V as PhysicsDirectSpaceState3D, W as PhysicsJointKind, X as PhysicsQueryVector3, Y as PhysicsShapeKind, Z as RigidBodyType, _ as rapier } from './Area3D-CyRWumWF.js';
3
+ import { Object3D, BufferGeometry, Matrix4 } from 'three';
4
4
  import { ISoftBodyCollision } from '@threenative/core';
5
5
  import { ISnowFootprint, SnowField } from '@threenative/core/world';
6
6
  import 'recast-navigation';
@@ -70,6 +70,59 @@ type StaticColliderFilter = StaticColliderPredicate | IBuildStaticCollidersOptio
70
70
  */
71
71
  declare function buildStaticColliders(context: IStaticColliderContext, root: Object3D, filter?: StaticColliderFilter): readonly RigidBody3D[];
72
72
 
73
+ /** How one scattered instance collides. "auto" measures its geometry; the rest force a shape. */
74
+ type ScatterCollision = "auto" | "hull" | "trunk" | "none";
75
+ interface IScatterColliderInstance {
76
+ /** The solid part (stone, bark; not leaves or grass), local to the instance, base at the bottom. */
77
+ readonly geometry: BufferGeometry;
78
+ /** The instance's world transform. */
79
+ readonly matrix: Matrix4;
80
+ /** Named override of the measured shape. Default "auto". */
81
+ readonly collision?: ScatterCollision;
82
+ }
83
+ interface IScatterCollidersOptions {
84
+ readonly physics: IPhysicsContext;
85
+ readonly instances: Iterable<IScatterColliderInstance>;
86
+ /** The point bodies stream around, read on every update: usually the player. */
87
+ readonly follow: {
88
+ readonly position: {
89
+ readonly x: number;
90
+ readonly z: number;
91
+ };
92
+ };
93
+ /** Horizontal metres around `follow` that hold bodies. Default 40. */
94
+ readonly radius?: number;
95
+ readonly collisionLayer?: number;
96
+ readonly collisionMask?: number;
97
+ }
98
+ interface IScatterCollidersStats {
99
+ readonly instances: number;
100
+ readonly hulls: number;
101
+ readonly trunks: number;
102
+ readonly skipped: number;
103
+ readonly resident: number;
104
+ }
105
+ /**
106
+ * Fixed bodies for scattered props (rocks, trunks), created near a followed point and released
107
+ * past it, so 100k placements cost one cheap scan per few metres walked and only the nearby
108
+ * bodies live in the physics world. Unreal gives each foliage instance a body from its mesh's
109
+ * simple collision (UE 5.8.3: Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:2847,
110
+ * :2875) and World Partition streams them with the cell; here the follow radius is the cell.
111
+ *
112
+ * Shapes are measured, never authored: a slender base becomes a capsule around the trunk (the
113
+ * crown and branch wood stay passable), anything else becomes the 18-DOP hull Unreal generates on
114
+ * import, and pieces under knee height or thinner than a stem get no body. `collision` on an
115
+ * instance overrides the measurement by name.
116
+ */
117
+ declare class ScatterColliders {
118
+ #private;
119
+ constructor(options: IScatterCollidersOptions);
120
+ /** Create the bodies the follow point nears and release the ones it left. Cheap to call per frame. */
121
+ update(): void;
122
+ stats(): IScatterCollidersStats;
123
+ dispose(): void;
124
+ }
125
+
73
126
  /** Adapt existing physics bodies into `SoftBody3D` collision input without a second shape API. */
74
127
  declare function softBodyCollision(...bodies: readonly RigidBody3D[]): ISoftBodyCollision;
75
128
 
@@ -270,4 +323,4 @@ declare class VehicleBody3D extends RigidBody3D {
270
323
  dispose(): void;
271
324
  }
272
325
 
273
- export { CollisionShape3D, type IBuildStaticCollidersOptions, type IFixedJoint3DOptions, type IHingeJoint3DOptions, type IJoint3DOptions, IPhysicsBodyHandle, IPhysicsColliderHandle, IPhysicsContext, IPhysicsJointLimit, IPhysicsRotation, IPhysicsVector3, IPhysicsWorldHandle, type IPinJoint3DOptions, type ISnowPhysicsBinding, type ISnowPhysicsObservation, type ISnowPhysicsOptions, type IStaticColliderContext, type IVehicleBody3DOptions, type IVehicleWheel3D, Joint3D, PhysicsBody3D, type PhysicsJointBody, RigidBody3D, type StaticColliderPredicate, VehicleBody3D, type VehicleForwardAxis, attachSnowPhysics, boxFootprint, buildStaticColliders, capsuleFootprint, interactionGroups, softBodyCollision };
326
+ export { CollisionShape3D, type IBuildStaticCollidersOptions, type IFixedJoint3DOptions, type IHingeJoint3DOptions, type IJoint3DOptions, IPhysicsBodyHandle, IPhysicsColliderHandle, IPhysicsContext, IPhysicsJointLimit, IPhysicsRotation, IPhysicsVector3, IPhysicsWorldHandle, type IPinJoint3DOptions, type IScatterColliderInstance, type IScatterCollidersOptions, type IScatterCollidersStats, type ISnowPhysicsBinding, type ISnowPhysicsObservation, type ISnowPhysicsOptions, type IStaticColliderContext, type IVehicleBody3DOptions, type IVehicleWheel3D, Joint3D, PhysicsBody3D, type PhysicsJointBody, RigidBody3D, ScatterColliders, type ScatterCollision, type StaticColliderPredicate, VehicleBody3D, type VehicleForwardAxis, attachSnowPhysics, boxFootprint, buildStaticColliders, capsuleFootprint, interactionGroups, softBodyCollision };