physicsObstacles2D
Import from @pibbl/core/physics/2d. Call physicsObstacles2D(world) during
component evaluation to obtain a stable source accepted by
useFlowField2D({ ..., obstacles: source }) or
embers({ ..., physics: { obstacles: source } }). The world retains the source and
its reusable numerical buffers until disposal. Worlds that never request it
perform no obstacle packing.
source.read() returns { revision, boxes, ellipses, polygons } from the last successful physics
commit. The borrowed Float64Array uses ten entries per box: center x/y,
half-width/height, rotation in radians, center-of-mass linear velocity x/y,
angular velocity in radians per second, and world center-of-mass x/y.
Coordinates use the physics world’s simulation space. The field must use the
same origin and scale.
The obstacle revision changes only when packed geometry or motion changes; unchanged physics commits retain the revision so a flow field can reuse its grid. Do not mutate or retain borrowed values across commits; copy them if needed. The buffer contains copies, never Rapier or another WASM module’s memory. Ellipses (including circles) use the same ten-entry layout with radii instead of half extents. Each polygon record contains vertex count, linear velocity x/y, angular velocity, center of mass x/y, then world-space vertex x/y pairs.
Rounded boxes with equal corner radii are exported as an exact union of central boxes and corner circles. Their immutable local geometry is cached.
Disabled bodies and sensors are excluded. Unsupported solid collider kinds (such as capsules or rounded boxes with unequal corner radii) produce an explicit error on read. Reading after world disposal throws.
Geometry and motion publish together after physics adoption, so flow advancement reads the previous committed physics state regardless of registration order. The flow applies no forces back to the world, and smoke particles need no bodies.
API details from source
Section titled “API details from source”
A borrowed committed solid batch, structurally compatible with a flow obstacle source.
physicsObstacles2D: (world: PibblPhysicsWorldHandle2D) => Readonly<{ read(): Readonly<{ revision: number; boxes: Float64Array; ellipses: Float64Array; polygons: Float64Array; }>; }>Related API: physicsObstacles2D, PibblPhysicsWorldHandle2D.
Parameters
Section titled “Parameters”world— World supplying collider geometry. See PibblPhysicsWorldHandle2D.
Returns
Section titled “Returns”An obstacle source whose read method returns the current revision and packed geometry.
See also
Section titled “See also”View source — packages/core/src/features/physics/2d.ts:439
Implementation guidance for agents
Section titled “Implementation guidance for agents”Read the Physics and geometry companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.
Complete minimal examples
Section titled “Complete minimal examples”- World queries: Query a static collider by ray, moving shape, overlap, point, and bounds. Plain source
Interactive examples
Section titled “Interactive examples”Documentation version
Section titled “Documentation version”Documentation built with @pibbl/core 0.0.2, revision 272a94a. ALPHA — NOT FOR PRODUCTION USE.