Native-style access to the Bullet 3D world and collision objects owned by Defold. World creation, destruction and stepping remain controlled by Defold. The backend name refers to three-dimensional physics.
World, collision-object and rigid-body userdata are borrowed handles to Defold-owned objects. Shape userdata are borrowed logical child-slot handles attached to a collision object. Constraint userdata identify auxiliary native objects owned by this Lua API; destroy them explicitly when no longer needed. They are also destroyed automatically when a required body or world is destroyed.
A collision-object, rigid-body or shape handle becomes invalid when its
collision object is deleted or reloaded. A world handle remains valid across
collision-object reloads, but becomes invalid when its collection and physics
world are destroyed. The corresponding is_valid() function is safe for
checking a retained handle; every other operation rejects an invalid handle.
Version: beta
| TYPES | |
|---|---|
| btCollisionObject | Bullet collision object |
| btDiscreteDynamicsWorld | Bullet dynamics world |
| btRigidBody | Bullet rigid body |
| RECORDS | |
|---|---|
| bullet3d.version_info | Bullet version information |
| FUNCTIONS | |
|---|---|
| bullet3d.get_collision_object() | Get a Bullet collision object |
| bullet3d.get_rigid_body() | Get a Bullet rigid body |
| bullet3d.get_version() | Get the Bullet version |
| bullet3d.get_world() | Get the Bullet world for the current collection |
btRigidBody = userdata
Rigid bodies use the same Lua userdata representation as collision objects, but rigid-body functions validate the native type before upcasting it.
Bullet version information
FIELDS
version |
string |
full Bullet version string |
number |
integer |
compact numeric Bullet version |
major |
integer |
major version number |
minor |
integer |
minor version number |
bullet3d.get_collision_object(url:string|hash|url)→object:btCollisionObject|nil
This returns both rigid bodies and ghost trigger objects. This function raises an error unless the collection uses 3D physics.
PARAMETERS
url |
stringhashurl |
collision object component URL |
RETURNS
object |
btCollisionObjectnil |
the collision object, or nil
|
bullet3d.get_rigid_body(url:string|hash|url)→body:btRigidBody|nil
Trigger components are ghost objects, so this function returns nil for them.
This function raises an error unless the collection uses 3D physics.
PARAMETERS
url |
stringhashurl |
collision object component URL |
RETURNS
body |
btRigidBodynil |
the rigid body handle, or nil
|
EXAMPLES
local world = bullet3d.get_world()
local body = bullet3d.get_rigid_body("#collisionobject")
if world and body and bullet3d.rigid_body.is_valid(body) then
bullet3d.rigid_body.apply_central_impulse(body, vmath.vector3(0, 10, 0))
end
-- A trigger is a collision object, not a rigid body.
local trigger = bullet3d.get_collision_object("#trigger")
assert(trigger and bullet3d.get_rigid_body("#trigger") == nil)
bullet3d.get_version()→info:bullet3d.version_info
Get the Bullet version
PARAMETERS
None
RETURNS
info |
bullet3d.version_info |
version information |
bullet3d.get_world()→world:btDiscreteDynamicsWorld|nil
This function raises an error unless the collection uses 3D physics.
PARAMETERS
None
RETURNS
world |
btDiscreteDynamicsWorldnil |
the world, or nil if the collection has no physics world
|