Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ConvexPolyhedron

A set of polygons describing a convex shape.

The shape MUST be convex for the code to work properly. No polygons may be coplanar (contained in the same 3D plane), instead these should be merged into one polygon.

author

qiao / https://github.com/qiao (original author, see https://github.com/qiao/three.js/commit/85026f0c769e4000148a67d45a9e9b9c5108836f)

author

schteppe / https://github.com/schteppe

see

https://www.altdevblogaday.com/2011/05/13/contact-generation-between-3d-convex-meshes/

todo

Move the clipping functions to ContactGenerator?

todo

Automatically merge coplanar polygons in constructor.

example
const convexShape = new CANNON.ConvexPolyhedron({ vertices, faces })
const convexBody = new CANNON.Body({ mass: 1, shape: convexShape })
world.addBody(convexBody)

Hierarchy

Index

Constructors

constructor

  • new ConvexPolyhedron(props?: { axes?: Vec3[]; boundingSphereRadius?: number; faces?: number[][]; normals?: Vec3[]; vertices?: Vec3[] }): ConvexPolyhedron
  • Parameters

    • props: { axes?: Vec3[]; boundingSphereRadius?: number; faces?: number[][]; normals?: Vec3[]; vertices?: Vec3[] } = {}
      • Optional axes?: Vec3[]

        axes

      • Optional boundingSphereRadius?: number

        boundingSphereRadius

      • Optional faces?: number[][]

        Array of integer arrays, describing which vertices that is included in each face.

      • Optional normals?: Vec3[]

        normals

      • Optional vertices?: Vec3[]

        An array of Vec3's

    Returns ConvexPolyhedron

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

faceNormals

faceNormals: Vec3[]

faceNormals

faces

faces: number[][]

Array of integer arrays, indicating which vertices each face consists of

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.

uniqueAxes

uniqueAxes: null | Vec3[]

If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check.

uniqueEdges

uniqueEdges: Vec3[]

uniqueEdges

vertices

vertices: Vec3[]

vertices

worldFaceNormals

worldFaceNormals: Vec3[]

worldFaceNormals

worldFaceNormalsNeedsUpdate

worldFaceNormalsNeedsUpdate: boolean

worldFaceNormalsNeedsUpdate

worldVertices

worldVertices: Vec3[]

worldVertices

worldVerticesNeedsUpdate

worldVerticesNeedsUpdate: boolean

worldVerticesNeedsUpdate

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): void

calculateWorldAABB

clipFaceAgainstHull

clipFaceAgainstPlane

  • clipFaceAgainstPlane(inVertices: Vec3[], outVertices: Vec3[], planeNormal: Vec3, planeConstant: number): Vec3[]
  • Clip a face in a hull against the back of a plane.

    Parameters

    • inVertices: Vec3[]
    • outVertices: Vec3[]
    • planeNormal: Vec3
    • planeConstant: number

      The constant in the mathematical plane equation

    Returns Vec3[]

computeEdges

  • computeEdges(): void

computeNormals

  • computeNormals(): void
  • Compute the normals of the faces. Will reuse existing Vec3 objects in the faceNormals array if they exist.

    Returns void

computeWorldFaceNormals

computeWorldVertices

findSeparatingAxis

getAveragePointLocal

  • getAveragePointLocal(target?: Vec3): Vec3

getFaceNormal

  • getFaceNormal(i: number, target: Vec3): void

pointIsInside

  • pointIsInside(p: Vec3): false | 1 | -1
  • Checks whether p is inside the polyhedra. Must be in local coords. The point lies outside of the convex hull of the other points if and only if the direction of all the vectors from it to those other points are on less than one half of a sphere around it.

    Parameters

    • p: Vec3

      A point given in local coordinates

    Returns false | 1 | -1

testSepAxis

transformAllPoints

updateBoundingSphereRadius

  • updateBoundingSphereRadius(): void

volume

  • volume(): number

Static computeNormal

Static project

  • Get max and min dot product of a convex hull at position (pos,quat) projected onto an axis. Results are saved in the array maxmin.

    Parameters

    Returns void