Defold Learn logo


Box2D b2Shape documentation

Constants for functional shape tables used with b2d.body.create_fixture and returned from b2d.fixture.get_shape.

Version: beta

FUNCTIONS
b2d.shape.are_contact_events_enabled() Check if contact events are enabled for a shape.
b2d.shape.are_hit_events_enabled() Check if hit events are enabled for a shape.
b2d.shape.are_pre_solve_events_enabled() Check if pre-solve events are enabled for a shape.
b2d.shape.are_sensor_events_enabled() Check if sensor events are enabled for a shape.
b2d.shape.enable_contact_events() Enable or disable contact events for a shape.
b2d.shape.enable_hit_events() Enable or disable hit events for a shape.
b2d.shape.enable_pre_solve_events() Enable or disable pre-solve events for a shape.
b2d.shape.enable_sensor_events() Enable or disable sensor events for a shape.
b2d.shape.get_body() Get the body owning a shape.
b2d.shape.get_closest_point() Get the closest point on a shape.
b2d.shape.get_contact_capacity() Get shape contact capacity.
b2d.shape.get_contact_data() Get touching contact data for a shape.
b2d.shape.get_mass_data() Get mass data for a shape.
b2d.shape.get_material() Get shape material id.
b2d.shape.get_sensor_capacity() Get sensor overlap capacity.
b2d.shape.get_sensor_overlaps() Get sensor overlaps.
b2d.shape.get_shape() Get a shape's geometry.
b2d.shape.get_world() Get the world owning a shape.
b2d.shape.is_valid() Validate a shape handle.
b2d.shape.ray_cast() Ray cast a shape directly.
b2d.shape.set_material() Set shape material id.
b2d.shape.set_shape() Set a shape's geometry.
CONSTANTS
b2d.shape.SHAPE_TYPE_BOX Box shape type alias.
b2d.shape.SHAPE_TYPE_BOX Box shape type alias.
b2d.shape.SHAPE_TYPE_CAPSULE Capsule shape type.
b2d.shape.SHAPE_TYPE_CHAIN Chain shape type.
b2d.shape.SHAPE_TYPE_CIRCLE Circle shape type.
b2d.shape.SHAPE_TYPE_CIRCLE Circle shape type.
b2d.shape.SHAPE_TYPE_EDGE Edge shape type.
b2d.shape.SHAPE_TYPE_EDGE Edge shape type alias.
b2d.shape.SHAPE_TYPE_GRID Grid shape type.
b2d.shape.SHAPE_TYPE_POLYGON Polygon shape type.
b2d.shape.SHAPE_TYPE_POLYGON Polygon shape type.
b2d.shape.SHAPE_TYPE_SEGMENT Segment shape type.

Functions

b2d.shape.are_contact_events_enabled()

b2d.shape.are_contact_events_enabled(shape_id)

Check if contact events are enabled for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

enabled boolean
true if contact events are enabled

b2d.shape.are_hit_events_enabled()

b2d.shape.are_hit_events_enabled(shape_id)

Check if hit events are enabled for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

enabled boolean
true if hit events are enabled

b2d.shape.are_pre_solve_events_enabled()

b2d.shape.are_pre_solve_events_enabled(shape_id)

Check if pre-solve events are enabled for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

enabled boolean
true if pre-solve events are enabled

b2d.shape.are_sensor_events_enabled()

b2d.shape.are_sensor_events_enabled(shape_id)

Check if sensor events are enabled for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

enabled boolean
true if sensor events are enabled

b2d.shape.enable_contact_events()

b2d.shape.enable_contact_events(shape_id,enable)

Enable or disable contact events for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index
enable boolean
true to enable contact events

b2d.shape.enable_hit_events()

b2d.shape.enable_hit_events(shape_id,enable)

Enable or disable hit events for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index
enable boolean
true to enable hit events

b2d.shape.enable_pre_solve_events()

b2d.shape.enable_pre_solve_events(shape_id,enable)

Enable or disable pre-solve events for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index
enable boolean
true to enable pre-solve events

b2d.shape.enable_sensor_events()

b2d.shape.enable_sensor_events(shape_id,enable)

Enable or disable sensor events for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index
enable boolean
true to enable sensor events

b2d.shape.get_body()

b2d.shape.get_body(shape_id)

Get the body owning a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

body b2Body
owning body

b2d.shape.get_closest_point()

b2d.shape.get_closest_point(shape_id,target)

Get the closest point on a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index
target vector3
world target point

RETURNS

point vector3
closest world point on the shape

b2d.shape.get_contact_capacity()

b2d.shape.get_contact_capacity(shape_id)

Get shape contact capacity.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

capacity number
maximum contact data count

b2d.shape.get_contact_data()

b2d.shape.get_contact_data(shape_id)

Get touching contact data for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

contacts table
array of contact tables

b2d.shape.get_mass_data()

b2d.shape.get_mass_data(shape_id)

Get mass data for a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

data table
table with mass, center, and inertia

b2d.shape.get_material()

b2d.shape.get_material(shape_id)

Get shape material id.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

material number
shape material id

b2d.shape.get_sensor_capacity()

b2d.shape.get_sensor_capacity(shape_id)

Get sensor overlap capacity.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

capacity number
maximum sensor overlap count

b2d.shape.get_sensor_overlaps()

b2d.shape.get_sensor_overlaps(shape_id)

Get sensor overlaps.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

overlaps table
array of shape info tables

b2d.shape.get_shape()

b2d.shape.get_shape(shape_id)

Get a shape's geometry.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

shape table
shape table with numeric type from b2d.shape.SHAPE_TYPE_*

b2d.shape.get_world()

b2d.shape.get_world(shape_id)

Get the world owning a shape.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

world b2World
owning world

b2d.shape.is_valid()

b2d.shape.is_valid(shape_id)

Validate a shape handle.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index

RETURNS

valid boolean
true if the shape handle still refers to a live Box2D shape

b2d.shape.ray_cast()

b2d.shape.ray_cast(shape_id,origin,translation,max_fraction)

Ray cast a shape directly.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index
origin vector3
world ray origin
translation vector3
world ray translation
max_fraction number
optional maximum translation fraction, defaults to 1

RETURNS

hit table
hit table with point, normal, fraction, and iterations, or nil

b2d.shape.set_material()

b2d.shape.set_material(shape_id,material)

Set shape material id.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index
material number
shape material id

b2d.shape.set_shape()

b2d.shape.set_shape(shape_id,definition,update_mass)

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.

PARAMETERS

shape_id b2Shape
shape handle from a shape info table, or pass body, shape_index
definition table
shape table with numeric type from b2d.shape.SHAPE_TYPE_*
update_mass boolean
true to reset body mass from shapes

EXAMPLES

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

Uses the polygon enum value, but indicates the hx/hy box convenience format.


b2d.shape.SHAPE_TYPE_BOX

Uses the polygon enum value, but indicates the hx/hy box convenience format.


b2d.shape.SHAPE_TYPE_CAPSULE

Capsule shape type.


b2d.shape.SHAPE_TYPE_CHAIN

Chain shape type.


b2d.shape.SHAPE_TYPE_CIRCLE

Circle shape type.


b2d.shape.SHAPE_TYPE_CIRCLE

Circle shape type.


b2d.shape.SHAPE_TYPE_EDGE

Edge shape type.


b2d.shape.SHAPE_TYPE_EDGE

Compatibility alias for b2d.shape.SHAPE_TYPE_SEGMENT.


b2d.shape.SHAPE_TYPE_GRID

Grid shape type.


b2d.shape.SHAPE_TYPE_POLYGON

Polygon shape type.


b2d.shape.SHAPE_TYPE_POLYGON

Polygon shape type.


b2d.shape.SHAPE_TYPE_SEGMENT

Segment shape type.