addBody

@three-blocks/pro
addBody(physicsApi : Object, type : string, meshOrCollideBox : THREE.Mesh|THREE.Group|THREE.InstancedMesh|THREE.BatchedMesh, properties : Object, bodyProps : Object, options : Object) : Promise<(Object|Array<Object>)>

Add a physics body from a mesh or pre-created collideBox. For BatchedMesh/InstancedMesh without instanceMatrixIndex, automatically batches ALL instances.

Parameters
physicsApiObject
The physics worker API (physics.api).
typestring
Body type: 'static', 'dynamic', 'kinematic', 'zone'.
meshOrCollideBoxTHREE.Mesh | THREE.Group | THREE.InstancedMesh | THREE.BatchedMesh
Mesh, group, InstancedMesh, or BatchedMesh to create physics for, or a pre-created collideBox.
propertiesoptionalObject
Physics properties (friction, mass, pFrom, pTo, etc.).
Default is {}.
bodyPropsoptionalObject
Body properties (capsuleRadius, capsuleLength, initialPosition, etc.).
Default is {}.
optionsoptionalObject
Optional settings.
Default is {}.
  • hitboxoptionalTHREE.Mesh
    Custom hitbox mesh (overrides auto-generated collision).
  • debugMaterialoptionalTHREE.Material
    Material for debug visualization.
  • sideoptionalnumber
    BVH side (e.g., THREE.DoubleSide).
  • instanceMatrixIndexoptionalnumber
    For InstancedMesh/BatchedMesh: which instance to use. If omitted, ALL instances are batched automatically.
  • sourceGeometryoptionalTHREE.BufferGeometry
    For BatchedMesh single instance: optional original geometry (skips extraction from internal buffers).
  • sourceGeometriesoptionalObject
    For BatchedMesh batch mode: optional map of geometryId -> BufferGeometry (skips extraction, slightly faster).
  • customGeometryToBVHScriptoptionalfunction
    Custom geometry processing function.
Returns
Promise<(Object|Array<Object>)> — The body API object(s). Returns array for batched BatchedMesh/InstancedMesh.