Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Constructors

constructor

  • new Trimesh(vertices: number[], indices: number[]): Trimesh

Properties

aabb

aabb: AABB

The local AABB of the mesh.

body

body: null | Body

The body to which the shape is added to.

boundingSphereRadius

boundingSphereRadius: number

The local bounding sphere radius of this shape.

collisionResponse

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

edges: null | Int16Array

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

id

id: number

Identifier of the Shape.

indices

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: null | Material

Optional material of the shape that regulates contact properties.

normals

normals: Float32Array

The normals data.

scale

scale: Vec3

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

tree

tree: Octree

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

type

type: 0 | ShapeType

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

vertices

vertices: Float32Array

vertices

Static types

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

All the Shape types.

Type declaration

  • BOX: 4
  • COMPOUND: 8
  • CONVEXPOLYHEDRON: 16
  • CYLINDER: 128
  • HEIGHTFIELD: 32
  • PARTICLE: 64
  • PLANE: 2
  • SPHERE: 1
  • TRIMESH: 256

Methods

calculateLocalInertia

  • calculateLocalInertia(mass: number, target: Vec3): Vec3

calculateWorldAABB

computeLocalAABB

  • computeLocalAABB(aabb: AABB): void

getEdgeVector

  • getEdgeVector(edgeIndex: number, vectorStore: Vec3): void

getEdgeVertex

  • getEdgeVertex(edgeIndex: number, firstOrSecond: number, vertexStore: Vec3): 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

getNormal

  • getNormal(i: number, target: Vec3): Vec3

getTriangleVertices

  • getTriangleVertices(i: number, a: Vec3, b: Vec3, c: Vec3): void

getTrianglesInAABB

  • getTrianglesInAABB(aabb: AABB, result: number[]): number[]
  • Get triangles in a local AABB from the trimesh.

    Parameters

    • aabb: AABB
    • result: number[]

      An array of integers, referencing the queried triangles.

    Returns number[]

getVertex

getWorldVertex

setScale

  • setScale(scale: Vec3): void

updateAABB

  • updateAABB(): void

updateBoundingSphereRadius

  • updateBoundingSphereRadius(): void

updateEdges

  • updateEdges(): void

updateNormals

  • updateNormals(): void
  • Compute the normals of the faces. Will save in the .normals array.

    Returns void

updateTree

  • updateTree(): void

volume

  • volume(): number

Static computeNormal

Static createTorus

  • createTorus(radius?: number, tube?: number, radialSegments?: number, tubularSegments?: number, arc?: number): Trimesh
  • Create a Trimesh instance, shaped as a torus.

    Parameters

    • radius: number = 1
    • tube: number = 0.5
    • radialSegments: number = 8
    • tubularSegments: number = 6
    • arc: number = ...

    Returns Trimesh