Body
new Body()Body - Three.js-like Transform Interface
Provides a familiar Three.js-style interface for setting physics body
position and quaternion via SharedArrayBuffer. The Body class is
automatically attached to API objects returned by physics.addBody()
and physics.addBodies().
Features
- THREE.Vector3-like
positionproperty (set, copy, add, x/y/z) - THREE.Quaternion-like
quaternionproperty (set, copy, setFromEuler, setFromAxisAngle) - Automatic sync to both SharedArrayBuffer and entity mesh
- Works with single bodies and batch operations
Usage
Batch Bodies
Works identically with addBodies() for batch operations:
const apis = await physics.addBodies(BodyType.KINEMATIC, bodiesConfig);
for (const api of apis) {
api.body.position.y += 10;
}
Example
const api = await physics.addBody(BodyType.KINEMATIC, mesh, { friction: 0.5 });
// Set position like THREE.Object3D
api.body.position.set(10, 5, 20);
api.body.position.x = 5;
// Set quaternion
api.body.quaternion.set(0, 0, 0, 1);
api.body.quaternion.setFromEuler({ x: 0, y: Math.PI, z: 0 });
// Copy from existing objects
api.body.position.copy(someMesh.position);
api.body.quaternion.copy(someMesh.quaternion);
Properties
# .position : Object
Position interface with THREE.Vector3-like methods. Changes are written to SharedArrayBuffer and optionally synced to entity mesh.
# .quaternion : Object
Quaternion interface with THREE.Quaternion-like methods. Changes are written to SharedArrayBuffer and optionally synced to entity mesh.
# .index : number
The body index in the physics system.
# .type : string
The body type ('dynamic', 'kinematic', 'static', 'zone').
# .entity : THREE.Object3D|null
The associated Three.js entity (mesh/group).
# .view : Object|null
Direct access to the raw BBO view for advanced usage.