b2d.shape30 new
Constants for functional shape tables used with b2d.body.create_fixture
and returned from b2d.fixture.get_shape.
Functions
b2d.shape.are_contact_events_enabled(2 overloads): booleanNb2d.shape.are_hit_events_enabled(2 overloads): booleanNb2d.shape.are_pre_solve_events_enabled(2 overloads): booleanNb2d.shape.are_sensor_events_enabled(2 overloads): booleanNb2d.shape.enable_contact_events(2 overloads): voidNb2d.shape.enable_hit_events(2 overloads): voidNb2d.shape.enable_pre_solve_events(2 overloads): voidNb2d.shape.enable_sensor_events(2 overloads): voidNb2d.shape.get_body(2 overloads):Opaque<"b2Body">Nb2d.shape.get_closest_point(2 overloads): Vector3Nb2d.shape.get_contact_capacity(2 overloads): numberNb2d.shape.get_contact_data(2 overloads):b2d.ContactData[]Nb2d.shape.get_mass_data(2 overloads):b2d.MassDataNb2d.shape.get_material(2 overloads): numberNb2d.shape.get_sensor_capacity(2 overloads): numberNb2d.shape.get_sensor_overlaps(2 overloads):b2d.ShapeInfo[]Nb2d.shape.get_shape(2 overloads):b2d.shape.DefinitionNb2d.shape.get_world(2 overloads):Opaque<"b2World">Nb2d.shape.is_valid(2 overloads): booleanNb2d.shape.ray_cast(2 overloads):b2d.ShapeCastOutput| undefinedNb2d.shape.set_material(2 overloads): voidNb2d.shape.set_shape(2 overloads): voidN(shape_id:Opaque<"b2Shape">, definition: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 }, update_mass?: boolean)(body:Opaque<"b2Body">, shape_index: number, definition: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 }, update_mass?: boolean)
b2d.shape.are_contact_events_enabled(2 overloads): booleanN
- Since Defold 1.13.0
Check if contact events are enabled for a shape.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
enabled:boolean— true if contact events are enabled
b2d.shape.are_hit_events_enabled(2 overloads): booleanN
- Since Defold 1.13.0
Check if hit events are enabled for a shape.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
enabled:boolean— true if hit events are enabled
b2d.shape.are_pre_solve_events_enabled(2 overloads): booleanN
- Since Defold 1.13.0
Check if pre-solve events are enabled for a shape.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
enabled:boolean— true if pre-solve events are enabled
b2d.shape.are_sensor_events_enabled(2 overloads): booleanN
- Since Defold 1.13.0
Check if sensor events are enabled for a shape.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
enabled:boolean— true if sensor events are enabled
b2d.shape.enable_contact_events(2 overloads): voidN
- Since Defold 1.13.0
Enable or disable contact events for a shape.
(shape_id: Opaque<"b2Shape">, enable: boolean)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_indexenable:boolean— true to enable contact events
(body: Opaque<"b2Body">, shape_index: number, enable: boolean)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.enable:boolean— true to enable contact events
b2d.shape.enable_hit_events(2 overloads): voidN
- Since Defold 1.13.0
Enable or disable hit events for a shape.
(shape_id: Opaque<"b2Shape">, enable: boolean)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_indexenable:boolean— true to enable hit events
(body: Opaque<"b2Body">, shape_index: number, enable: boolean)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.enable:boolean— true to enable hit events
b2d.shape.enable_pre_solve_events(2 overloads): voidN
- Since Defold 1.13.0
Enable or disable pre-solve events for a shape.
(shape_id: Opaque<"b2Shape">, enable: boolean)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_indexenable:boolean— true to enable pre-solve events
(body: Opaque<"b2Body">, shape_index: number, enable: boolean)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.enable:boolean— true to enable pre-solve events
b2d.shape.enable_sensor_events(2 overloads): voidN
- Since Defold 1.13.0
Enable or disable sensor events for a shape.
(shape_id: Opaque<"b2Shape">, enable: boolean)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_indexenable:boolean— true to enable sensor events
(body: Opaque<"b2Body">, shape_index: number, enable: boolean)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.enable:boolean— true to enable sensor events
b2d.shape.get_body(2 overloads): Opaque<"b2Body">N
- Since Defold 1.13.0
Get the body owning a shape.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
body:Opaque<"b2Body">— owning body
b2d.shape.get_closest_point(2 overloads): Vector3N
- Since Defold 1.13.0
Get the closest point on a shape.
(shape_id: Opaque<"b2Shape">, target: Vector3)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_indextarget:Vector3— world target point
(body: Opaque<"b2Body">, shape_index: number, target: Vector3)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.target:Vector3— world target point
Returns
point:Vector3— closest world point on the shape
b2d.shape.get_contact_capacity(2 overloads): numberN
- Since Defold 1.13.0
Get shape contact capacity.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
capacity:number— maximum contact data count
b2d.shape.get_contact_data(2 overloads): b2d.ContactData[]N
- Since Defold 1.13.0
Get touching contact data for a shape.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
contacts:b2d.ContactData[]— touching contacts
b2d.shape.get_mass_data(2 overloads): b2d.MassDataN
- Since Defold 1.13.0
Get mass data for a shape.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
data:b2d.MassData— shape mass data
b2d.shape.get_material(2 overloads): numberN
- Since Defold 1.13.0
Get shape material id.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
material:number— shape material id
b2d.shape.get_sensor_capacity(2 overloads): numberN
- Since Defold 1.13.0
Get sensor overlap capacity.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
capacity:number— maximum sensor overlap count
b2d.shape.get_sensor_overlaps(2 overloads): b2d.ShapeInfo[]N
- Since Defold 1.13.0
Get sensor overlaps.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
overlaps:b2d.ShapeInfo[]— overlapping shapes
b2d.shape.get_shape(2 overloads): b2d.shape.DefinitionN
- Since Defold 1.13.0
Get a shape's geometry.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
shape:b2d.shape.Definition— shape table with numerictypefromb2d.shape.SHAPE_TYPE_*
b2d.shape.get_world(2 overloads): Opaque<"b2World">N
- Since Defold 1.13.0
Get the world owning a shape.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
world:Opaque<"b2World">— owning world
b2d.shape.is_valid(2 overloads): booleanN
- Since Defold 1.13.0
Validate a shape handle.
(shape_id: Opaque<"b2Shape">)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_index
(body: Opaque<"b2Body">, shape_index: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.
Returns
valid:boolean— true if the shape handle still refers to a live Box2D shape
b2d.shape.ray_cast(2 overloads): b2d.ShapeCastOutput | undefinedN
- Since Defold 1.13.0
Ray cast a shape directly.
(shape_id: Opaque<"b2Shape">, origin: Vector3, translation: Vector3, max_fraction?: number)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_indexorigin:Vector3— world ray origintranslation:Vector3— world ray translationmax_fraction?:number— optional maximum translation fraction, defaults to 1
(body: Opaque<"b2Body">, shape_index: number, origin: Vector3, translation: Vector3, max_fraction?: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.origin:Vector3— world ray origintranslation:Vector3— world ray translationmax_fraction?:number— optional maximum translation fraction, defaults to 1
Returns
hit:b2d.ShapeCastOutput | undefined— cast result, ornil
b2d.shape.set_material(2 overloads): voidN
- Since Defold 1.13.0
Set shape material id.
(shape_id: Opaque<"b2Shape">, material: number)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_indexmaterial:number— shape material id
(body: Opaque<"b2Body">, shape_index: number, material: number)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.material:number— shape material id
b2d.shape.set_shape(2 overloads): voidN
- Since Defold 1.13.0
This updates the shape geometry using the same table format as
b2d.body.create_shape and b2d.shape.get_shape. The body mass is not
updated unless update_mass is true.
(shape_id: Opaque<"b2Shape">, definition: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 }, update_mass?: boolean)Parameters
shape_id:Opaque<"b2Shape">— shape handle from a shape info table, or passbody, shape_indexdefinition:{ type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 }— shape table with numerictypefromb2d.shape.SHAPE_TYPE_*update_mass?:boolean— true to reset body mass from shapes
(body: Opaque<"b2Body">, shape_index: number, definition: { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 }, update_mass?: boolean)Parameters
body:Opaque<"b2Body">— The body that owns the shape.shape_index:number— The shape's position on that body, in the orderb2d.body.get_shapeslists them. ⚠️ 1-based; passed to Defold unchanged.definition:{ type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; hx: number; hy: number; center?: Vector3; angle?: number } | { type: typeof b2d.shape.SHAPE_TYPE_POLYGON | typeof b2d.shape.SHAPE_TYPE_BOX; vertices: Vector3[] } | { type: typeof b2d.shape.SHAPE_TYPE_CIRCLE; radius: number; center?: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_CAPSULE; radius: number; center1: Vector3; center2: Vector3 } | { type: typeof b2d.shape.SHAPE_TYPE_EDGE | typeof b2d.shape.SHAPE_TYPE_SEGMENT; v1: Vector3; v2: Vector3 }— shape table with numerictypefromb2d.shape.SHAPE_TYPE_*update_mass?:boolean— true to reset body mass from shapes
const body = b2d.get_body("#collisionobject");
if (body !== undefined) {
// Move a circle shape relative to the body origin.
const circle = b2d.shape.get_shape(body, 1);
const radius = "radius" in circle ? circle.radius : undefined;
b2d.shape.set_shape(body, 1, { type: b2d.shape.SHAPE_TYPE_CIRCLE, radius: radius ?? 16, center: vmath.vector3(24, 0, 0) }, true);
// Replace a segment shape's local endpoints.
b2d.shape.set_shape(body, 2, {
type: b2d.shape.SHAPE_TYPE_SEGMENT,
v1: vmath.vector3(-32, 0, 0),
v2: vmath.vector3(32, 0, 0),
});
// Update a box shape using the polygon box convenience format.
b2d.shape.set_shape(
body,
3,
{
type: b2d.shape.SHAPE_TYPE_BOX,
hx: 16,
hy: 8,
center: vmath.vector3(0, 20, 0),
angle: math.rad(30),
},
true,
);
}local body = b2d.get_body("#collisionobject")
-- Move a circle shape relative to the body origin.
local circle = b2d.shape.get_shape(body, 1)
circle.center = vmath.vector3(24, 0, 0)
b2d.shape.set_shape(body, 1, circle, true)
-- Replace a segment shape's local endpoints.
b2d.shape.set_shape(body, 2, {
type = b2d.shape.SHAPE_TYPE_SEGMENT,
v1 = vmath.vector3(-32, 0, 0),
v2 = vmath.vector3( 32, 0, 0),
})
-- Update a box shape using the polygon box convenience format.
b2d.shape.set_shape(body, 3, {
type = b2d.shape.SHAPE_TYPE_BOX,
hx = 16,
hy = 8,
center = vmath.vector3(0, 20, 0),
angle = math.rad(30),
}, true)Constants
b2d.shape.SHAPE_TYPE_BOX: number & { readonly __brand: "b2d.shape.SHAPE_TYPE_BOX" }N
- Since Defold 1.13.0
Box shape type alias. Uses the polygon enum value, but indicates the hx/hy box convenience format.
b2d.shape.SHAPE_TYPE_CAPSULE: number & { readonly __brand: "b2d.shape.SHAPE_TYPE_CAPSULE" }N
- Since Defold 1.13.0
Capsule shape type.
b2d.shape.SHAPE_TYPE_CHAIN: number & { readonly __brand: "b2d.shape.SHAPE_TYPE_CHAIN" }N
- Since Defold 1.13.0
Chain shape type.
b2d.shape.SHAPE_TYPE_CIRCLE: number & { readonly __brand: "b2d.shape.SHAPE_TYPE_CIRCLE" }N
- Since Defold 1.13.0
Circle shape type.
b2d.shape.SHAPE_TYPE_EDGE: number & { readonly __brand: "b2d.shape.SHAPE_TYPE_EDGE" }N
- Since Defold 1.13.0
Edge shape type alias. Compatibility alias for b2d.shape.SHAPE_TYPE_SEGMENT.
b2d.shape.SHAPE_TYPE_GRID: number & { readonly __brand: "b2d.shape.SHAPE_TYPE_GRID" }N
- Since Defold 1.13.0
Grid shape type.
b2d.shape.SHAPE_TYPE_POLYGON: number & { readonly __brand: "b2d.shape.SHAPE_TYPE_POLYGON" }N
- Since Defold 1.13.0
Polygon shape type.
b2d.shape.SHAPE_TYPE_SEGMENT: number & { readonly __brand: "b2d.shape.SHAPE_TYPE_SEGMENT" }N
- Since Defold 1.13.0
Segment shape type.