Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Constructors

constructor

Properties

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

convexPolyhedronRepresentation

convexPolyhedronRepresentation: ConvexPolyhedron

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

halfExtents

halfExtents: Vec3

The half extents of the box.

id

id: number

Identifier of the Shape.

material

material: null | Material

Optional material of the shape that regulates contact properties.

type

type: 0 | ShapeType

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

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

forEachWorldCorner

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

    Parameters

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

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

          Returns void

    Returns void

getSideNormals

  • 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[]

updateBoundingSphereRadius

  • updateBoundingSphereRadius(): void

updateConvexPolyhedronRepresentation

  • updateConvexPolyhedronRepresentation(): void
  • Updates the local convex polyhedron representation used for some collisions.

    Returns void

volume

  • volume(): number