Collision Shape

self:set_shape_mesh

Shared

Builds the collision shape from the meshes of a model

Syntax

local status = self:set_shape_mesh(
    model,
    config = {}
)

Parameters

TypeNameDescription
modelmodelModel instance whose meshes are used to generate the shape
tableconfigOptional generation settings
Refer Config section

Returns

TypeNameDescription
boolstatustrue on successful generation, false if the model has no usable mesh

Config

TypeKeyDefaultDescription
stringshape_type"convex"• When "convex" - builds a convex hull
• When "concave" - builds an exact triangle mesh
boolinclude_childrenfalseWhether every matching mesh becomes its own child shape instead of one shape for the whole model
tablefiltersnilList of {match, shape_type} rules, the first rule matching a component name overrides shape_type for it

Examples

Generate a convex shape from a model
core.model.load("crate", "models/crate.glb")

local model = core.model.create("crate")
local body = physics.static.create()
local entity = physics.collision_shape.create(body)

entity:set_shape_mesh(model)
Generate a concave shape for a specific component
core.model.load("crate", "models/crate.glb")

local model = core.model.create("crate")
local body = physics.static.create()
local entity = physics.collision_shape.create(body)

entity:set_shape_mesh(model, {
    shape_type = "convex",
    include_children = true,
    filters = {
        {match = "Floor*", shape_type = "concave"}
    }
})

On this page