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; this Defold version
bundles Bullet 2.77, reported by bullet3d.get_version().
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: alpha
| FUNCTIONS | |
|---|---|
| bullet3d.get_collision_object() | Get a Bullet collision object |
| bullet3d.get_rigid_body() | Get a Bullet rigid body |
| bullet3d.get_version() | Get the bundled Bullet version |
| bullet3d.get_world() | Get the Bullet world for the current collection |
bullet3d.get_collision_object(url)
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)
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()
Get the bundled Bullet version
PARAMETERS
None
RETURNS
info |
table |
version fields: version is the string "2.77", number is the integer 277, major is 2, and minor is 77 |
bullet3d.get_world()
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 |