Matter.Bodies
The Matter.Bodies
module contains factory methods for creating rigid body models
with commonly used body configurations (such as rectangles, circles and other polygons).
See the included usage examples.
Methods
Matter.Bodies.circle
Creates a new rigid body model with a circle hull.
The options parameter is an object that specifies any properties you wish to override the defaults.
See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Returns
A new circle body
Matter.Bodies.fromVertices
Utility to create a compound body based on set(s) of vertices.
Note: To optionally enable automatic concave vertices decomposition the poly-decomp
package must be first installed and provided see Common.setDecomp
, otherwise the convex hull of each vertex set will be used.
The resulting vertices are reorientated about their centre of mass,
and offset such that body.position
corresponds to this point.
The resulting offset may be found if needed by subtracting body.bounds
from the original input bounds.
To later move the centre of mass see Body.setCentre
.
Note that automatic conconcave decomposition results are not always optimal. For best results, simplify the input vertices as much as possible first. By default this function applies some addtional simplification to help.
Some outputs may also require further manual processing afterwards to be robust. In particular some parts may need to be overlapped to avoid collision gaps. Thin parts and sharp points should be avoided or removed where possible.
The options parameter object specifies any Matter.Body
properties you wish to override the defaults.
See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Parameters
-
x
Number -
y
Number -
vertexSets
ArrayOne or more arrays of vertex points e.g.
[[{ x: 0, y: 0 }...], ...]
. -
[options]
Object optionalThe body options.
-
[flagInternal=false]
Bool optionalOptionally marks internal edges with
isInternal
. -
[removeCollinear=0.01]
Number optionalThreshold when simplifying vertices along the same edge.
-
[minimumArea=10]
Number optionalThreshold when removing small parts.
-
[removeDuplicatePoints=0.01]
Number optionalThreshold when simplifying nearby vertices.
Returns
Matter.Bodies.polygon
Creates a new rigid body model with a regular polygon hull with the given number of sides.
The options parameter is an object that specifies any properties you wish to override the defaults.
See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Returns
A new regular polygon body
Matter.Bodies.rectangle
Creates a new rigid body model with a rectangle hull.
The options parameter is an object that specifies any properties you wish to override the defaults.
See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Returns
A new rectangle body
Matter.Bodies.trapezoid
Creates a new rigid body model with a trapezoid hull.
The slope
is parameterised as a fraction of width
and must be < 1 to form a valid trapezoid.
The options parameter is an object that specifies any properties you wish to override the defaults.
See the properties section of the Matter.Body
module for detailed information on what you can pass via the options
object.
Parameters
Returns
A new trapezoid body