PhysicsGenerator Class

Module: Physics

Physics generator is used to create Cannon.js shapes from three.js geometries.

Can be used with any object that contains a geometry.

It is based on the original Mesh2Shape converted by @donmccurdy.

Methods

createBoundingBoxShape

(
  • geometry
)
Box

Bounding box needs to be computed with the entire mesh, not just geometry.

Parameters:

  • geometry Geometry

Returns:

Box:

shape

createBoundingCylinderShape

(
  • object
)
Cylinder

Create cylinder shape from bounding cylinder calculated from bounding box and bouding sphere.

Parameters:

Returns:

Cylinder:

shape

createBoundingSphereShape

(
  • geometry
)
Sphere

Sphere shape from bouding sphere.

Parameters:

  • geometry Geometry

Returns:

Sphere:

shape

createBoxShape

(
  • geometry
)
Box

Create box shape from geometry.

Parameters:

  • geometry Geometry

Returns:

Box:

shape

createConvexPolyhedron

(
  • geometry
)
Shape

Computes 3D convex hull as a ConvexPolyhedron.

Parameters:

  • geometry ConvexPolyhedron

Returns:

Shape:

shape

createCylinderShape

(
  • geometry
)
Cylinder

Create cylinder shape from geometry.

Parameters:

  • geometry Geometry

Returns:

Cylinder:

shape

createPlaneShape

(
  • geometry
)
Box

Plane shape from geometry.

Parameters:

  • geometry Geometry

Returns:

Box:

shape

createShape

(
  • object
  • type
)
Shape

Given a Object3D instance, creates a corresponding CANNON shape.

Parameters:

  • object Object3D
  • type String

    PhysicsGenerator.Type

Returns:

Shape:

shape

createSphereShape

(
  • geometry
)
Sphere

Sphere shape from geometry.

Parameters:

  • geometry Geometry

Returns:

Sphere:

shape

createTrimeshShape

(
  • geometry
)
Trimesh

Trimesh shape from geometry.

Parameters:

  • geometry Geometry

Returns:

Trimesh:

shape

createTubeShape

(
  • geometry
)
Trimesh

Sphere shape from bouding sphere.

Parameters:

  • geometry Geometry

Returns:

Trimesh:

shape

getGeometry

(
  • object
)
Geometry

Returns a single geometry for the given object.

If the object is compound, its geometries are automatically merged.

Parameters:

Returns:

Geometry:

Geometry that contains all merger geometry

getMeshes

(
  • object
)
Array

Returns a array of Mesh instances from the given object.

If nested transformations are found, they are applied to child meshes as mesh.userData.matrix, so that each mesh has its position/rotation/scale independently of all of its parents except the top-level object.

Parameters:

Returns:

Array:

meshes found inside the Object3D

getVertices

(
  • geometry
)
Array

Get geometry vertices.

Parameters:

  • geometry Geometry

Returns:

Array:

array

Attributes

Type

Object

Type is used to indentify the type of cannonjs:

  • BOX
  • CYLINDER
  • SPHERE
  • HULL