Namespace: bullet3d.shape
Language: Lua
Type: Defold Lua
File: script_bullet3d_shape.cpp
Source: engine/gamesys/src/gamesys/scripts/bullet3d/script_bullet3d_shape.cpp
Borrowed shape handles identify a one-based child slot on a Defold-owned collision object. They remain attached to that logical slot when its native shape is replaced and become invalid with their owning collision object. Shape mutation is copy-on-write, so instances sharing a collision resource are not modified together. Lengths use Defold world units.
Type: TYPEDEF Shape handles identify logical child slots and resolve the current native shape on every call.
Parameters
value (userdata)Type: FUNCTION Get one attached shape by one-based index.
Parameters
object (btCollisionObject) - collision objectshape_index (integer) - one-based shape indexReturns
shape (btCollisionShape) - borrowed logical shape handleType: FUNCTION Get the number of shapes attached to a collision object.
Parameters
object (btCollisionObject) - collision objectReturns
count (integer) - shape countType: FUNCTION Get all attached shapes.
Parameters
object (btCollisionObject) - collision objectReturns
shapes (btCollisionShape[]) - array of borrowed shape handlesExamples
Enumerate the logical shapes attached to a collision object:
function init(self)
local object = bullet3d.get_collision_object("#collisionobject")
for _, shape in ipairs(bullet3d.collision_object.get_shapes(object)) do
local index = bullet3d.shape.get_index(shape)
local data = bullet3d.shape.get_shape(shape)
print("shape", index, "type", data.type)
end
end
Type: TYPEDEF A sphere has diameter; a box has dimensions; a capsule has diameter and cylindrical-section height; and a convex hull has vertices. Query functions also accept optional position, rotation, and target_rotation fields. Lengths use Defold units.
Parameters
value ({ type:bullet3d.shape.SHAPE_TYPE, diameter:number, position?:vector3, rotation?:quaternion, target_rotation?:quaternion } |
{ type:bullet3d.shape.SHAPE_TYPE, dimensions:vector3, position?:vector3, rotation?:quaternion, target_rotation?:quaternion } | { type:bullet3d.shape.SHAPE_TYPE, diameter:number, height:number, position?:vector3, rotation?:quaternion, target_rotation?:quaternion } | { type:bullet3d.shape.SHAPE_TYPE, vertices:vector3[], position?:vector3, rotation?:quaternion, target_rotation?:quaternion }) - collision shape definition |
Type: FUNCTION Get the owning collision object.
Parameters
shape (btCollisionShape) - shape handleReturns
object (btCollisionObject) - owning collision objectType: FUNCTION Get the one-based child index.
Parameters
shape (btCollisionShape) - shape handleReturns
shape_index (integer) - one-based shape indexType: FUNCTION A non-compound collision object’s only shape has no child transform, so this function returns the identity transform for it.
Parameters
shape (btCollisionShape) - shape handleReturns
position (vector3) - local positionrotation (quaternion) - local rotationType: FUNCTION The returned table always contains type, one of bullet3d.shape.SHAPE_TYPE_*. A sphere also contains numeric diameter; a box contains vector3 dimensions; a capsule contains numeric diameter and cylindrical-section height; a hull contains a vertices array of vector3 values; and a triangle mesh contains only type. Primitive and hull tables use Defold units and can be passed to a bullet3d.world shape query after adding the desired position and optional rotation fields.
Parameters
shape (btCollisionShape) - shape handleReturns
data (bullet3d.shape.definition) - typed shape geometry in Defold unitsType: FUNCTION Get the normalized Defold shape type.
Parameters
shape (btCollisionShape) - shape handleReturns
type (bullet3d.shape.SHAPE_TYPE) - collision shape typeType: FUNCTION Test whether a shape handle and its owner still exist.
Parameters
shape (btCollisionShape) - shape handleReturns
valid (boolean) - validityType: FUNCTION A non-compound collision object’s only shape has no child transform and is rejected. The binding normalizes the supplied rotation.
Parameters
shape (btCollisionShape) - shape handleposition (vector3) - finite local positionrotation (quaternion) - finite non-zero local rotationType: FUNCTION The table uses the same format as get_shape. Its type must match the existing shape because changing native shape type is not supported. Primitive dimensions must be finite and greater than zero. Hulls require at least four finite vertices. Triangle mesh geometry cannot be changed with this function.
Parameters
shape (btCollisionShape) - shape handledata (bullet3d.shape.definition) - typed shape geometry in Defold unitsExamples
Increase the dimensions of the first box shape by 50 percent for this instance:
function init(self)
local object = bullet3d.get_collision_object("#collisionobject")
local shape = bullet3d.collision_object.get_shape(object, 1)
local data = bullet3d.shape.get_shape(shape)
if data.type == bullet3d.shape.SHAPE_TYPE_BOX then
data.dimensions = data.dimensions * 1.5
bullet3d.shape.set_shape(shape, data)
end
end
Type: ENUM Collision shape types
Members
bullet3d.shape.SHAPE_TYPE_BOX - Box shape type Value 1. Shape data contains positive vector3 dimensions in Defold units.bullet3d.shape.SHAPE_TYPE_CAPSULE - Capsule shape type Value 2. Shape data contains a positive numeric diameter and positive numeric cylindrical-section height in Defold units.bullet3d.shape.SHAPE_TYPE_HULL - Convex hull shape type Value 3. Shape data contains a vertices array with at least four finite vector3 values in Defold units.bullet3d.shape.SHAPE_TYPE_MESH - Triangle mesh shape type Value 4. Shape data contains only the type; triangle geometry is read-only.bullet3d.shape.SHAPE_TYPE_SPHERE - Sphere shape type Value 0. Shape data contains a positive numeric diameter in Defold units.