Keyboard shortcuts

Press ← or → to navigate between chapters

Press ? to show this help

Press Esc to hide this help

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).

InterfaceKindConsentSidesOwner
physicsimportlistedserverdaedalus
physics-typestypes-onlysilentbothdaedalus

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 payload physics-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 layout physics-rays.
  • result: packed layout physics-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 payload physics-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 layout physics-body-handles.
  • result: packed layout physics-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 payload physics-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>.

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)

FieldTypeAbout
kindsevent-kinds
scopeevent-scope
min-forcef32N, for contact events; 0 reports every contact.
min-impact-energyf32J, for F’s body-impact.
include-terrainbool
max-per-ticku32Excess is counted, not delivered.

event-kinds (flags)

––––– events (functions arrive with G2b) –––––

BitFlagAbout
0contact-started
1contact-ended
2contact-force
3created
4split
5merged
6joint-status
7joint-broken
8joint-removed
9cells-removed
10collapsed
11debris-expired
12cell-damaged
13body-impact
14fluid-entered
15fluid-exited
16character-impact
17sleep
18wake
19removed
20dormant
21restored
22budget

event-scope (variant)

IndexCasePayloadAbout
0bodieslist<u64>Durable ids, at most 1,024.
1ownerowner
2regiontuple<world-space-id, block-box>
3ownnoneEverything 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.

FieldTypeAbout
bodiesu32
assembliesu32
voxelsu64
jointsu32
cost-usu32
rungu8

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.

BitFlagAbout
0dynamic
1kinematic
2fixed
3sensors
4terrain
5props

body-fields (flags)

The field groups a read-bodies row carries, in bit order.

BitFlagAbout
0pose
1velocity
2mass
3state
4fluid

dvec3 (alias)

= core/types.dvec3

entity-ref (alias)

= core/types.entity-ref

hit-target (variant)

What a cast hit.

IndexCasePayloadAbout
0bodyentity-ref
1assembly-celltuple<entity-ref, block-pos>An assembly and the grid-local cell hit (Daedalus B): a block address in contract form.
2terrainblock-pos
3propu64An Enki D prop, by its durable PropId.

localized-text (alias)

= core/text.localized-text

mass-properties (record)

FieldTypeAbout
massf32
local-comvec3
world-comdvec3
principal-inertiavec3
inertia-framequat

owner (alias)

= core/types.owner

quat (alias)

= core/types.quat

query-error (variant)

IndexCasePayloadAbout
0wrong-sidenoneThe interface is server-only; this is a client instance.
1space-not-foundnone
2too-largeu32Over a per-call or per-tick query limit, which it carries.
3invalidlocalized-text
4not-declarednoneThe calling system did not declare physics(read).
5otherstringA condition added after this track opened (foundation §5.7).

query-filter (record)

FieldTypeAbout
classesbody-classes
groupsoption<tuple<u32, u32>>Collision groups as (memberships, filter).
excludelist<u64>Entity handles never reported, at most 16.
owneroption<owner>Only bodies this owner owns.

ray-hit (record)

FieldTypeAbout
targethit-target
pointdvec3
normalvec3
distancef32

shape (variant)

A query shape in metres: a cuboid by its half extents, a capsule along +Y by (radius, half-height).

IndexCasePayloadAbout
0cuboidvec3
1spheref32
2capsule-ytuple<f32, f32>

shape-hit (record)

FieldTypeAbout
targethit-target
toif32
pointdvec3
normalvec3

vec3 (alias)

= core/types.vec3