Class Box

A 3d box shape.

Example

const size = 1
const halfExtents = new CANNON.Vec3(size, size, size)
const boxShape = new CANNON.Box(halfExtents)
const boxBody = new CANNON.Body({ mass: 1, shape: boxShape })
world.addBody(boxBody)

Hierarchy (view full)

Constructors

Properties

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
convexPolyhedronRepresentation: ConvexPolyhedron

Used by the contact generator to make contacts with other convex polyhedra for example.

halfExtents: Vec3

The half extents of the box.

id: number

Identifier of the Shape.

material: Material

Optional material of the shape that regulates contact properties.

type: 0 | ShapeType

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

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

  • forEachWorldCorner

    Parameters

    • pos: Vec3
    • quat: Quaternion
    • callback: ((x, y, z) => void)
        • (x, y, z): void
        • Parameters

          • x: number
          • y: number
          • z: number

          Returns void

    Returns void

  • Get the box 6 side normals

    Parameters

    • sixTargetVectors: Vec3[]

      An array of 6 vectors, to store the resulting side normals in.

    • quat: Quaternion

      Orientation to apply to the normal vectors. If not provided, the vectors will be in respect to the local frame.

    Returns Vec3[]

  • Updates the local convex polyhedron representation used for some collisions.

    Returns void

  • Returns the volume of the box.

    Returns number

  • Parameters

    • halfExtents: Vec3
    • mass: number
    • target: Vec3

    Returns void