Class Trimesh

Trimesh.

Example

// How to make a mesh with a single triangle
const vertices = [
0, 0, 0, // vertex 0
1, 0, 0, // vertex 1
0, 1, 0 // vertex 2
]
const indices = [
0, 1, 2 // triangle 0
]
const trimeshShape = new CANNON.Trimesh(vertices, indices)

Hierarchy (view full)

Constructors

Properties

aabb: AABB

The local AABB of the mesh.

body: Body

The body to which the shape is added to.

boundingSphereRadius: number

The local bounding sphere radius of this shape.

collisionFilterGroup: number

Default

1
collisionFilterMask: number

Default

-1
collisionResponse: boolean

Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

Default

true
edges: Int16Array

References to vertex pairs, making up all unique edges in the trimesh.

id: number

Identifier of the Shape.

indices: Int16Array

Array of integers, indicating which vertices each triangle consists of. The length of this array is thus 3 times the number of triangles.

material: Material

Optional material of the shape that regulates contact properties.

normals: Float32Array

The normals data.

scale: Vec3

Local scaling of the mesh. Use .setScale() to set it.

tree: Octree

The indexed triangles. Use .updateTree() to update it.

type: 0 | ShapeType

The type of this shape. Must be set to an int > 0 by subclasses.

vertices: Float32Array

vertices

idCounter: number
types: {
    BOX: 4;
    COMPOUND: 8;
    CONVEXPOLYHEDRON: 16;
    CYLINDER: 128;
    HEIGHTFIELD: 32;
    PARTICLE: 64;
    PLANE: 2;
    SPHERE: 1;
    TRIMESH: 256;
}

All the Shape types.

Type declaration

  • Readonly BOX: 4

    BOX

  • Readonly COMPOUND: 8

    COMPOUND

  • Readonly CONVEXPOLYHEDRON: 16

    CONVEXPOLYHEDRON

  • Readonly CYLINDER: 128

    CYLINDER

  • Readonly HEIGHTFIELD: 32

    HEIGHTFIELD

  • Readonly PARTICLE: 64

    PARTICLE

  • Readonly PLANE: 2

    PLANE

  • Readonly SPHERE: 1

    SPHERE

  • Readonly TRIMESH: 256

    TRIMESH

Methods

  • Compute the local AABB for the trimesh

    Parameters

    Returns void

  • Get a vector along an edge.

    Parameters

    • edgeIndex: number
    • vectorStore: Vec3

    Returns void

  • Get an edge vertex

    Parameters

    • edgeIndex: number
    • firstOrSecond: number

      0 or 1, depending on which one of the vertices you need.

    • vertexStore: Vec3

      Where to store the result

    Returns void

  • Compute the normal of triangle i.

    Parameters

    • i: number
    • target: Vec3

    Returns Vec3

    The "target" vector object

  • Get the three vertices for triangle i.

    Parameters

    Returns void

  • Get triangles in a local AABB from the trimesh.

    Parameters

    • aabb: AABB
    • result: number[]

      An array of integers, referencing the queried triangles.

    Returns number[]

  • Get vertex i.

    Parameters

    Returns Vec3

    The "out" vector object

  • Get a vertex from the trimesh,transformed by the given position and quaternion.

    Parameters

    Returns Vec3

    The "out" vector object

  • setScale

    Parameters

    Returns void

  • Update the .aabb property

    Returns void

  • Update the .edges property

    Returns void

  • Compute the normals of the faces. Will save in the .normals array.

    Returns void

  • updateTree

    Returns void

  • Get approximate volume

    Returns number

  • Get face normal given 3 vertices

    Parameters

    Returns void

  • Create a Trimesh instance, shaped as a torus.

    Parameters

    • Optional radius: number
    • Optional tube: number
    • Optional radialSegments: number
    • Optional tubularSegments: number
    • Optional arc: number

    Returns Trimesh