manifold:physics 0.2.0
Contract reference · Payloads · contract.json (crates/manifold-wasm-abi/wit/contract.json)
Contract 0.2.0, track 0.2: open, unreleased. Nothing on track 0.2 is released yet, so any item may still change in place (spec §7.2).
| Interface | Kind | Consent | Sides | Owner |
|---|---|---|---|---|
physics | import | listed | server | daedalus |
physics-types | types-only | silent | both | daedalus |
Interface physics
import · consent listed · sides server · owner daedalus · since 0.2.0
Rigid bodies, assemblies and joints for game modules (Daedalus G §5).
Server-only: on a client instance every query returns wrong-side,
submit returns other("wrong-side") and take-results returns an empty
list.
Queries are synchronous and see this tick’s post-step state; they need
physics(read) on the calling system. Mutations are deferred ops: a
batch of [u32 length][postcard PhysicsOp] records, applied before the
next physics step by the actor named once per batch; they need
physics(write). Results arrive through take-results. Positions cross
as f64. Every list<u8> is classified in PAYLOADS.toml.
Published whole: every type is complete, including the events’. The
functions whose producers have not landed arrive in place with them while
this track is open: contacts (A’s contact view), mechanism-of (C’s
mechanisms), support-query (F’s support values), and subscribe,
unsubscribe and take-events (G2b).
Functions
body-mass-properties
body-mass-properties: func(body: u64) -> result<option<mass-properties>, query-error>
A live body’s mass properties. (Spec G §5.2 names it
mass-properties, which WIT cannot: the record of that name shares
the interface’s namespace.)
- Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent.
body-state
body-state: func(body: u64) -> result<option<list<u8>>, query-error>
A live body’s state: a BodyStateView envelope payload.
- Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent. result: schema payloadphysics-body-state.
cast-rays
cast-rays: func(space: world-space-id, rays: list<u8>, filter: query-filter) -> result<list<u8>, query-error>
Packed rays in (physics-rays, 40 B each), one packed record per
ray out (physics-ray-hits, 48 B each): its hit, a miss, or the
unloaded chunk it reached first.
- Reports
other("chunk-unloaded"): the ray or sweep reached a chunk that is not loaded before any hit; terrain is the voxel world wherever it is loaded. - Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent. rays: packed layoutphysics-rays.result: packed layoutphysics-ray-hits.
joint-state
joint-state: func(joint: u64) -> result<option<list<u8>>, query-error>
A joint’s status and last-step state: a JointView envelope payload.
- Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent. result: schema payloadphysics-joint-view.
overlap
overlap: func(space: world-space-id, shape: shape, at: pose, filter: query-filter, max-results: u32) -> result<list<entity-ref>, query-error>
The bodies whose colliders shape at at touches, at most
max-results.
- Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent.
raycast
raycast: func(space: world-space-id, origin: dvec3, dir: vec3, max: f32, filter: query-filter) -> result<option<ray-hit>, query-error>
––––– queries: synchronous, post-step state of this tick –––––
Terrain is the voxel world wherever it is loaded, not only near
bodies. A ray or sweep that reaches an unloaded chunk before any hit
returns other("chunk-unloaded") (in cast-rays, kind 5 for that
ray), never a miss. At equal distance a body hit wins over terrain.
The nearest hit along a ray, up to max metres.
- Reports
other("chunk-unloaded"): the ray or sweep reached a chunk that is not loaded before any hit; terrain is the voxel world wherever it is loaded. - Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent.
read-bodies
read-bodies: func(bodies: list<u8>, fields: body-fields) -> result<list<u8>, query-error>
Packed entity handles in (physics-body-handles, 8 B each), one
packed row per handle out (physics-body-rows: an 8-byte header and
the requested field groups).
- Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent. bodies: packed layoutphysics-body-handles.result: packed layoutphysics-body-rows.
resolve-id
resolve-id: func(id: u64) -> result<option<u64>, query-error>
A durable id’s live entity handle. (Spec G §5.2 names it resolve,
which jco’s generated JavaScript cannot import: it declares its own
top-level resolve; bytecodealliance/jco#2134, fixed by jco#2135.
The published name stays resolve-id.)
- Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent.
shape-cast
shape-cast: func(space: world-space-id, shape: shape, start: pose, dir: vec3, max: f32, filter: query-filter) -> result<option<shape-hit>, query-error>
Sweep shape from start along dir for up to max metres. The
terrain cells of the swept box are limited (too-large past it).
- Reports
other("chunk-unloaded"): the ray or sweep reached a chunk that is not loaded before any hit; terrain is the voxel world wherever it is loaded. - Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent.
submit
submit: func(actor: actor, mode: batch-mode, ops: list<u8>) -> result<batch-id, submit-error>
––––– mutations: deferred –––––
ops: [u32 length][postcard PhysicsOp] records. Static checks
only; everything else is decided at apply and reported as the batch’s
result.
- Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent. - Reports
other("wrong-side"): called on a client instance; physics is server-only. ops: schema payloadphysics-op.
supports-op
supports-op: func(kind: op-kind) -> bool
Whether this host applies op kind.
take-results
take-results: func() -> list<u8>
This mod’s finished batches since the last call: a postcard
Vec<PhysicsBatchResult>.
result: schema payloadphysics-batch-results.
usage
usage: func(owner: owner) -> result<owner-usage, query-error>
- Reports
other("not-installed"): this host installs no physics. - Reports
other("outside-system"): called outside a system, where no world is lent.
Types
actor (alias)
= core/types.actor
batch-id (alias)
= core/ops.batch-id
batch-mode (alias)
= core/ops.batch-mode
block-box (alias)
= core/types.block-box
body-fields (alias)
= physics/physics-types.body-fields
dvec3 (alias)
= core/types.dvec3
entity-ref (alias)
= core/types.entity-ref
event-filter (record)
| Field | Type | About |
|---|---|---|
kinds | event-kinds | |
scope | event-scope | |
min-force | f32 | N, for contact events; 0 reports every contact. |
min-impact-energy | f32 | J, for F’s body-impact. |
include-terrain | bool | |
max-per-tick | u32 | Excess is counted, not delivered. |
event-kinds (flags)
––––– events (functions arrive with G2b) –––––
| Bit | Flag | About |
|---|---|---|
| 0 | contact-started | |
| 1 | contact-ended | |
| 2 | contact-force | |
| 3 | created | |
| 4 | split | |
| 5 | merged | |
| 6 | joint-status | |
| 7 | joint-broken | |
| 8 | joint-removed | |
| 9 | cells-removed | |
| 10 | collapsed | |
| 11 | debris-expired | |
| 12 | cell-damaged | |
| 13 | body-impact | |
| 14 | fluid-entered | |
| 15 | fluid-exited | |
| 16 | character-impact | |
| 17 | sleep | |
| 18 | wake | |
| 19 | removed | |
| 20 | dormant | |
| 21 | restored | |
| 22 | budget |
event-scope (variant)
| Index | Case | Payload | About |
|---|---|---|---|
| 0 | bodies | list<u64> | Durable ids, at most 1,024. |
| 1 | owner | owner | |
| 2 | region | tuple<world-space-id, block-box> | |
| 3 | own | none | Everything this mod owns. |
mass-properties (alias)
= physics/physics-types.mass-properties
op-kind (alias)
= core/ops.op-kind
owner (alias)
= core/types.owner
owner-usage (record)
What an owner’s bodies use.
| Field | Type | About |
|---|---|---|
bodies | u32 | |
assemblies | u32 | |
voxels | u64 | |
joints | u32 | |
cost-us | u32 | |
rung | u8 |
pose (alias)
= core/types.pose
query-error (alias)
= physics/physics-types.query-error
query-filter (alias)
= physics/physics-types.query-filter
ray-hit (alias)
= physics/physics-types.ray-hit
shape (alias)
= physics/physics-types.shape
shape-hit (alias)
= physics/physics-types.shape-hit
submit-error (alias)
= core/ops.submit-error
vec3 (alias)
= core/types.vec3
world-space-id (alias)
= core/types.world-space-id
Interface physics-types
types-only · consent silent · sides both · owner daedalus · since 0.2.0
Records the server interface physics and the later client interface
physics-view share (Daedalus G §5.2). Types only: importing it links
nothing and needs no consent.
Published whole: every flag, variant and record is complete at its first
release, including what later milestones fill. A class with no members
matches nothing; a body-fields group a host cannot fill reads as absent
in the row’s present byte.
Types
block-pos (alias)
= core/types.block-pos
body-classes (flags)
Which colliders a query sees.
| Bit | Flag | About |
|---|---|---|
| 0 | dynamic | |
| 1 | kinematic | |
| 2 | fixed | |
| 3 | sensors | |
| 4 | terrain | |
| 5 | props |
body-fields (flags)
The field groups a read-bodies row carries, in bit order.
| Bit | Flag | About |
|---|---|---|
| 0 | pose | |
| 1 | velocity | |
| 2 | mass | |
| 3 | state | |
| 4 | fluid |
dvec3 (alias)
= core/types.dvec3
entity-ref (alias)
= core/types.entity-ref
hit-target (variant)
What a cast hit.
| Index | Case | Payload | About |
|---|---|---|---|
| 0 | body | entity-ref | |
| 1 | assembly-cell | tuple<entity-ref, block-pos> | An assembly and the grid-local cell hit (Daedalus B): a block address in contract form. |
| 2 | terrain | block-pos | |
| 3 | prop | u64 | An Enki D prop, by its durable PropId. |
localized-text (alias)
= core/text.localized-text
mass-properties (record)
| Field | Type | About |
|---|---|---|
mass | f32 | |
local-com | vec3 | |
world-com | dvec3 | |
principal-inertia | vec3 | |
inertia-frame | quat |
owner (alias)
= core/types.owner
quat (alias)
= core/types.quat
query-error (variant)
| Index | Case | Payload | About |
|---|---|---|---|
| 0 | wrong-side | none | The interface is server-only; this is a client instance. |
| 1 | space-not-found | none | |
| 2 | too-large | u32 | Over a per-call or per-tick query limit, which it carries. |
| 3 | invalid | localized-text | |
| 4 | not-declared | none | The calling system did not declare physics(read). |
| 5 | other | string | A condition added after this track opened (foundation §5.7). |
query-filter (record)
| Field | Type | About |
|---|---|---|
classes | body-classes | |
groups | option<tuple<u32, u32>> | Collision groups as (memberships, filter). |
exclude | list<u64> | Entity handles never reported, at most 16. |
owner | option<owner> | Only bodies this owner owns. |
ray-hit (record)
| Field | Type | About |
|---|---|---|
target | hit-target | |
point | dvec3 | |
normal | vec3 | |
distance | f32 |
shape (variant)
A query shape in metres: a cuboid by its half extents, a capsule
along +Y by (radius, half-height).
| Index | Case | Payload | About |
|---|---|---|---|
| 0 | cuboid | vec3 | |
| 1 | sphere | f32 | |
| 2 | capsule-y | tuple<f32, f32> |
shape-hit (record)
| Field | Type | About |
|---|---|---|
target | hit-target | |
toi | f32 | |
point | dvec3 | |
normal | vec3 |
vec3 (alias)
= core/types.vec3