@threenative/physics 0.3.4 → 0.3.6
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/dist/{Area3D-DI_kCf7I.d.ts → Area3D-vbmjpxsN.d.ts} +34 -1
- package/dist/index.d.ts +129 -3
- package/dist/index.js +514 -8
- package/dist/native/index.d.ts +3 -2
- package/dist/native/index.js +489 -4
- package/dist/navigation/index.d.ts +1 -1
- package/package.json +5 -4
|
@@ -270,6 +270,26 @@ interface IPhysicsSimulation {
|
|
|
270
270
|
* the same tick, or copy the fields out before the step advances.
|
|
271
271
|
*/
|
|
272
272
|
areaIntersections?(id: number): ReadonlySet<number>;
|
|
273
|
+
/**
|
|
274
|
+
* Persistent solved contacts between one target collider and a set of candidate colliders.
|
|
275
|
+
*
|
|
276
|
+
* Collision start/stop events say a pair began touching; they carry no point, normal or load,
|
|
277
|
+
* so a contact that persists cannot be observed through them. This reads the narrow phase's
|
|
278
|
+
* solved manifolds directly, which is what a deformation or support consumer needs.
|
|
279
|
+
*
|
|
280
|
+
* One `PHYSICS_CONTACT_STRIDE` record per solved manifold, written from index 0. Returns the
|
|
281
|
+
* total record count; when that exceeds the buffer's capacity only the first records were
|
|
282
|
+
* written, and the caller must grow the buffer and read again before the next step. A sleeping
|
|
283
|
+
* body was not solved and reports nothing. Optional: a backend with no narrow-phase access
|
|
284
|
+
* omits it, and a caller that needs contacts must fail closed instead of assuming support.
|
|
285
|
+
*/
|
|
286
|
+
readContacts?(target: IPhysicsColliderHandle, colliders: Uint32Array, buffer: Float32Array): number;
|
|
287
|
+
/**
|
|
288
|
+
* Replace a collider's shape in place, keeping its handle, owning body, filters and scene
|
|
289
|
+
* cleanup. Recreating a collider instead leaves every recorded identity stale. Bodies sleeping
|
|
290
|
+
* on the old shape must wake, since the new one may no longer support them.
|
|
291
|
+
*/
|
|
292
|
+
setColliderShape?(collider: IPhysicsColliderHandle, shape: IPhysicsShapeDescriptor): void;
|
|
273
293
|
/**
|
|
274
294
|
* Attach ray-cast wheels to a dynamic chassis. A vehicle lives and dies with its body, so
|
|
275
295
|
* `removeBody()` releases its controller; there is no separate vehicle removal call.
|
|
@@ -366,6 +386,9 @@ declare class RigidBody3D {
|
|
|
366
386
|
/** The effective continuous-collision setting; dynamic defaults true, fixed and kinematic are always false. */
|
|
367
387
|
readonly continuousCollision: boolean;
|
|
368
388
|
buoyancy: Buoyancy3D | undefined;
|
|
389
|
+
/** Draw between solved ticks; false presents this body at its true tick pose. */
|
|
390
|
+
get interpolate(): boolean;
|
|
391
|
+
set interpolate(enabled: boolean);
|
|
369
392
|
constructor(options: IRigidBody3DOptions);
|
|
370
393
|
get physics(): IPhysicsContext | undefined;
|
|
371
394
|
/** Called by the shared plugin before a bulk step. */
|
|
@@ -376,6 +399,9 @@ declare class RigidBody3D {
|
|
|
376
399
|
readonly y: number;
|
|
377
400
|
readonly z: number;
|
|
378
401
|
};
|
|
402
|
+
/** Assign a world position to teleport; mutate object.position for ordinary kinematic motion. */
|
|
403
|
+
get position(): Pick<Vector3, "x" | "y" | "z">;
|
|
404
|
+
set position(position: Pick<Vector3, "x" | "y" | "z">);
|
|
379
405
|
syncToPhysics(): void;
|
|
380
406
|
/**
|
|
381
407
|
* Godot's `apply_impulse`. The one-shot shove: a thrown crate, a jump pad, a hit reaction.
|
|
@@ -539,6 +565,9 @@ declare class CharacterBody3D {
|
|
|
539
565
|
groundBody: IPhysicsBodyHandle | undefined;
|
|
540
566
|
/** Radians between `groundNormal` and world up (+Y). */
|
|
541
567
|
slopeAngle: number;
|
|
568
|
+
/** Draw between solved ticks; false presents this body at its true tick pose. */
|
|
569
|
+
get interpolate(): boolean;
|
|
570
|
+
set interpolate(enabled: boolean);
|
|
542
571
|
constructor(options: ICharacterBody3DOptions);
|
|
543
572
|
move(desiredTranslation: Pick<Vector3, "x" | "y" | "z">): void;
|
|
544
573
|
/**
|
|
@@ -695,6 +724,7 @@ type NavigationPlugin = IGamePluginHooks<Record<string, unknown>, IPhysicsContex
|
|
|
695
724
|
* @situation NPC patrols a level and chases a player
|
|
696
725
|
* @constraint requires rapier() earlier in the plugins array
|
|
697
726
|
* @example const game = defineGame({ plugins: [rapier(), recast()] });
|
|
727
|
+
* @requires npm i @threenative/physics
|
|
698
728
|
*/
|
|
699
729
|
declare function recast(): NavigationPlugin;
|
|
700
730
|
|
|
@@ -729,6 +759,9 @@ interface IPhysicsContext {
|
|
|
729
759
|
readonly simulation: IPhysicsSimulation;
|
|
730
760
|
readonly directSpaceState: PhysicsDirectSpaceState3D;
|
|
731
761
|
navigation?: INavigationContext;
|
|
762
|
+
/** Engine-owned draw history; optional for standalone physics contexts. */
|
|
763
|
+
resetInterpolation?(object: Object3D): void;
|
|
764
|
+
updateInterpolation?(body: PhysicsBody3D): void;
|
|
732
765
|
add(body: PhysicsBody3D): void;
|
|
733
766
|
numBodies(): number;
|
|
734
767
|
kinematicMotion?(colliderHandle: number): {
|
|
@@ -785,4 +818,4 @@ declare class Area3D {
|
|
|
785
818
|
dispose(): void;
|
|
786
819
|
}
|
|
787
820
|
|
|
788
|
-
export { type AreaEvent as $, Area3D as A, Buoyancy3D as B, CollisionShape3D as C, type IPhysicsRuntimeSimulation as D, type IPhysicsShapeDescriptor as E, type IPhysicsShapeQuery as F, type IPhysicsSimulation as G, type IPhysicsVehicleCreateOptions as H, type IPhysicsContext as I, type IPhysicsVehicleInput as J, type IPhysicsVehicleState as K, type IPointHit as L, type IRayHit as M, type IRigidBody3DOptions as N, type IShapeHit as O,
|
|
821
|
+
export { type AreaEvent as $, Area3D as A, Buoyancy3D as B, CollisionShape3D as C, type IPhysicsRuntimeSimulation as D, type IPhysicsShapeDescriptor as E, type IPhysicsShapeQuery as F, type IPhysicsSimulation as G, type IPhysicsVehicleCreateOptions as H, type IPhysicsContext as I, type IPhysicsVehicleInput as J, type IPhysicsVehicleState as K, type IPointHit as L, type IRayHit as M, type IRigidBody3DOptions as N, type IShapeHit as O, type PhysicsBody3D as P, MAX_PHYSICS_QUERY_RESULTS as Q, RigidBody3D as R, PHYSICS_COLLISION_EVENT_STRIDE as S, PHYSICS_TRANSFORM_STRIDE as T, PHYSICS_VEHICLE_WHEEL_STRIDE as U, PhysicsDirectSpaceState3D as V, type PhysicsJointKind as W, type PhysicsQueryVector3 as X, type PhysicsShapeKind as Y, type RigidBodyType as Z, rapier as _, type IPhysicsWorldHandle as a, type AreaHandler as a0, type CollisionShapeKind as a1, type IArea3DOptions as a2, type IAreaContact as a3, type ICharacterBody3DOptions as a4, type IPhysicsOptions as a5, type PhysicsPlugin as a6, type INavigationAgent3DOptions as a7, type INavigationContext as a8, type INavigationObstacle3DOptions as a9, type INavigationRegion3DOptions as aa, NavigationAgent3D as ab, type NavigationAgentEvent as ac, type NavigationAgentHandler as ad, NavigationObstacle3D as ae, type NavigationPlugin as af, NavigationRegion3D as ag, recast as ah, type IPhysicsBodyHandle as b, type IPhysicsVector3 as c, type IPhysicsRotation as d, type IPhysicsJointLimit as e, type IPhysicsColliderHandle as f, type IPhysicsVehicleWheelOptions as g, type BuoyancyPointPosition as h, CharacterBody3D as i, type IBuoyancy3DOptions as j, type IBuoyancyHullPoint as k, type IBuoyancySurface as l, type IBuoyancySurfaceSample as m, type ICollisionShapeHandle as n, type IIntersectPointOptions as o, type IIntersectRayOptions as p, type IIntersectShapeOptions as q, type IPhysicsBodyCreateOptions as r, type IPhysicsCharacterOptions as s, type IPhysicsHandle as t, type IPhysicsInputSnapshot as u, type IPhysicsJointCreateOptions as v, type IPhysicsPointQuery as w, type IPhysicsQueryHit as x, type IPhysicsRayHit as y, type IPhysicsRayQuery as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { I as IPhysicsContext, a as IPhysicsWorldHandle, b as IPhysicsBodyHandle, c as IPhysicsVector3, d as IPhysicsRotation, e as IPhysicsJointLimit, R as RigidBody3D, C as CollisionShape3D,
|
|
2
|
-
export { A as Area3D, B as Buoyancy3D,
|
|
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-vbmjpxsN.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-vbmjpxsN.js';
|
|
3
3
|
import { Object3D } from 'three';
|
|
4
4
|
import { ISoftBodyCollision } from '@threenative/core';
|
|
5
|
+
import { ISnowFootprint, SnowField } from '@threenative/core/world';
|
|
5
6
|
import 'recast-navigation';
|
|
6
7
|
|
|
7
8
|
/** A body handle or a shared physics node exposing one. */
|
|
@@ -72,6 +73,131 @@ declare function buildStaticColliders(context: IStaticColliderContext, root: Obj
|
|
|
72
73
|
/** Adapt existing physics bodies into `SoftBody3D` collision input without a second shape API. */
|
|
73
74
|
declare function softBodyCollision(...bodies: readonly RigidBody3D[]): ISoftBodyCollision;
|
|
74
75
|
|
|
76
|
+
/**
|
|
77
|
+
* A stadium contact: a rectangle of half-length `halfHeight` and half-width `radius`, capped by
|
|
78
|
+
* two half-discs of `radius`. The shape a capsule lies on, so a knocked-over body sinks along a
|
|
79
|
+
* line instead of at a point. Coverage is full across the body's own width and fades just
|
|
80
|
+
* outside it, so the body's edge never rests on a half-pressed rim; the bank rises beyond that.
|
|
81
|
+
* @situation let a fallen capsule, limb or barrel leave a linear imprint in snow
|
|
82
|
+
* @situation give a capsule a shape-appropriate snow contact instead of a sphere's dot
|
|
83
|
+
* @constraint radius and halfHeight are metres and never grow with load
|
|
84
|
+
* @example const footprint = capsuleFootprint(0.5, 0.2);
|
|
85
|
+
* @requires npm i @threenative/physics
|
|
86
|
+
*/
|
|
87
|
+
declare function capsuleFootprint(halfHeight: number, radius: number): ISnowFootprint;
|
|
88
|
+
/**
|
|
89
|
+
* A rectangular contact: the face a box rests on, in the contact's own frame. Coverage is full
|
|
90
|
+
* across the face and fades just outside it; the bank rises beyond that.
|
|
91
|
+
* @situation let a crate, platform or plank press a rectangular pit into snow
|
|
92
|
+
* @situation imprint a box's own footprint rather than a circle around it
|
|
93
|
+
* @constraint halfWidth and halfDepth are metres; rotation comes from the contact, not the footprint
|
|
94
|
+
* @example const footprint = boxFootprint(0.4, 0.25);
|
|
95
|
+
* @requires npm i @threenative/physics
|
|
96
|
+
*/
|
|
97
|
+
declare function boxFootprint(halfWidth: number, halfDepth: number): ISnowFootprint;
|
|
98
|
+
interface ISnowPhysicsOptions {
|
|
99
|
+
/** The physics context whose solved steps drive the deformation. */
|
|
100
|
+
readonly physics: IPhysicsContext;
|
|
101
|
+
/** The snow surface these bodies deform. */
|
|
102
|
+
readonly snow: SnowField;
|
|
103
|
+
/** Bodies to watch from the start. Register more later with `add`. */
|
|
104
|
+
readonly bodies?: readonly PhysicsBody3D[];
|
|
105
|
+
/** Collision layer of the generated snow surface collider. Default 1. */
|
|
106
|
+
readonly collisionLayer?: number;
|
|
107
|
+
/** Collision mask of the generated snow surface collider. Default 0xffff. */
|
|
108
|
+
readonly collisionMask?: number;
|
|
109
|
+
/** Multiplier turning a solved contact impulse into load. Default 1. */
|
|
110
|
+
readonly loadScale?: number;
|
|
111
|
+
/** Smallest contact-normal height that counts as support. Default 0.35. */
|
|
112
|
+
readonly supportNormal?: number;
|
|
113
|
+
/**
|
|
114
|
+
* Largest gap, in metres, the live collider may keep from the canonical surface before it is
|
|
115
|
+
* rebuilt. Default 0.0005. A resting body's print converges geometrically, so rebuilding on
|
|
116
|
+
* every sub-millimetre change would wake it every step and it would never sleep.
|
|
117
|
+
*/
|
|
118
|
+
readonly colliderTolerance?: number;
|
|
119
|
+
/** Snowfall deposition in metres per second, forwarded to `SnowField.recover`. Default 0. */
|
|
120
|
+
readonly deposition?: number;
|
|
121
|
+
/** Wind erosion rate, forwarded to `SnowField.recover`. Default 0. */
|
|
122
|
+
readonly wind?: number;
|
|
123
|
+
}
|
|
124
|
+
/** What the last consumed step observed, for a registry snapshot or a playtest probe. */
|
|
125
|
+
interface ISnowPhysicsObservation {
|
|
126
|
+
/** Solved snow-contact manifolds read in the most recent step. */
|
|
127
|
+
readonly contacts: number;
|
|
128
|
+
/** Bodies whose supported, downward-loaded contacts pressed the snow in that step. */
|
|
129
|
+
readonly supported: number;
|
|
130
|
+
/** Summed load those bodies pressed with, in newtons. */
|
|
131
|
+
readonly load: number;
|
|
132
|
+
/** How `load` was obtained. It is estimated from solver impulses, never measured. */
|
|
133
|
+
readonly loadProvenance: "solver-impulse-per-step";
|
|
134
|
+
/** Canonical snow surface version. */
|
|
135
|
+
readonly version: number;
|
|
136
|
+
/** Canonical version the live collider was last reconciled with. */
|
|
137
|
+
readonly colliderVersion: number;
|
|
138
|
+
/** Largest gap between the collider's source samples and the canonical surface, in metres. */
|
|
139
|
+
readonly colliderError: number;
|
|
140
|
+
}
|
|
141
|
+
interface ISnowPhysicsBinding {
|
|
142
|
+
/** The generated snow surface collider. Its identity survives every deformation. */
|
|
143
|
+
readonly surface: IPhysicsColliderHandle;
|
|
144
|
+
/** Canonical surface version the live collider was last reconciled with. */
|
|
145
|
+
readonly surfaceVersion: number;
|
|
146
|
+
/** Solved contact manifolds read in the most recent step. */
|
|
147
|
+
readonly contacts: number;
|
|
148
|
+
/** Bodies that pressed the snow in the most recent step. */
|
|
149
|
+
readonly supported: number;
|
|
150
|
+
/** Snow surface version at the last step this binding ran. */
|
|
151
|
+
readonly version: number;
|
|
152
|
+
/** Live snowfall deposition in metres per second; checked at the next step. */
|
|
153
|
+
deposition: number;
|
|
154
|
+
/** Live wind erosion rate; checked at the next step. */
|
|
155
|
+
wind: number;
|
|
156
|
+
add(body: PhysicsBody3D, footprint?: ISnowFootprint): void;
|
|
157
|
+
remove(body: PhysicsBody3D): void;
|
|
158
|
+
/** Load one watched body pressed into the snow in the last step, newtons; 0 when airborne. */
|
|
159
|
+
loadOf(body: PhysicsBody3D): number;
|
|
160
|
+
/**
|
|
161
|
+
* Consume one solved step: read contacts, deform the snow, let it recover, then publish the
|
|
162
|
+
* changed surface to collision. Call it once per fixed step, after the physics step and before
|
|
163
|
+
* the next one.
|
|
164
|
+
*/
|
|
165
|
+
step(deltaTime: number): void;
|
|
166
|
+
/** The last step's observation, with the collider measured against the canonical surface. */
|
|
167
|
+
observe(): ISnowPhysicsObservation;
|
|
168
|
+
/** Idempotent cleanup: removes the surface body and forgets every watched body. */
|
|
169
|
+
dispose(): void;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Drive a `SnowField` from real solved contacts.
|
|
173
|
+
*
|
|
174
|
+
* The binding creates the snow surface collider from the field's own canonical samples and keeps
|
|
175
|
+
* it in step with them, so a body lands on the surface a query would report. Each fixed step it
|
|
176
|
+
* reads the solver's persistent contacts — not collision start/stop events, which carry no point
|
|
177
|
+
* or load — deforms the snow only where a contact is supported and loaded downward, then
|
|
178
|
+
* republishes the surface before the next step. Airborne bodies, side contacts and unrelated
|
|
179
|
+
* colliders never deform anything.
|
|
180
|
+
*
|
|
181
|
+
* A dropped sphere settles on the surface it made; a pushed one rotates and carves a connected
|
|
182
|
+
* track without its transform being copied anywhere. Footprints come from the body's own
|
|
183
|
+
* collision shape and orientation unless the game supplies one.
|
|
184
|
+
*
|
|
185
|
+
* Contact load is `impulse / deltaTime * loadScale`: a solver impulse over a step, which
|
|
186
|
+
* estimates a contact force and is not measured. `observe().loadProvenance` says so.
|
|
187
|
+
* @situation leave footprints and tracks where physical bodies actually touch snow
|
|
188
|
+
* @situation let a dropped or pushed sphere carve and settle into deformable snow
|
|
189
|
+
* @situation make a crate, capsule or ball compress the surface it rests on
|
|
190
|
+
* @constraint register `rapier()` before attaching, and call `step` once per fixed step after the physics step
|
|
191
|
+
* @constraint the backend must expose persistent solved contacts and in-place shape refresh; one that does not fails at attach
|
|
192
|
+
* @constraint verified on browser WebGPU and the native Linux desktop host; Android and iOS share the native seam but have not run it
|
|
193
|
+
* @constraint automatic profiles cover sphere, box and capsule; any other shape needs an explicit footprint
|
|
194
|
+
* @override loadScale, supportNormal, colliderTolerance, deposition, wind, collisionLayer and collisionMask name the binding's own behaviour
|
|
195
|
+
* @requires @threenative/core/world SnowField as the surface it deforms
|
|
196
|
+
* @example const snowPhysics = attachSnowPhysics({ physics: ctx.physics, snow, bodies: [ball] });
|
|
197
|
+
* afterPhysics(ctx, (dt) => snowPhysics.step(dt));
|
|
198
|
+
*/
|
|
199
|
+
declare function attachSnowPhysics(options: ISnowPhysicsOptions): ISnowPhysicsBinding;
|
|
200
|
+
|
|
75
201
|
/** Rapier packs membership in the high 16 bits and the filter in the low 16. */
|
|
76
202
|
declare function interactionGroups(layer: number, mask: number): number;
|
|
77
203
|
|
|
@@ -144,4 +270,4 @@ declare class VehicleBody3D extends RigidBody3D {
|
|
|
144
270
|
dispose(): void;
|
|
145
271
|
}
|
|
146
272
|
|
|
147
|
-
export { CollisionShape3D, type IBuildStaticCollidersOptions, type IFixedJoint3DOptions, type IHingeJoint3DOptions, type IJoint3DOptions, IPhysicsBodyHandle, IPhysicsContext, IPhysicsJointLimit, IPhysicsRotation, IPhysicsVector3, IPhysicsWorldHandle, type IPinJoint3DOptions, type IStaticColliderContext, type IVehicleBody3DOptions, type IVehicleWheel3D, Joint3D, type PhysicsJointBody, RigidBody3D, type StaticColliderPredicate, VehicleBody3D, type VehicleForwardAxis, buildStaticColliders, interactionGroups, softBodyCollision };
|
|
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 };
|