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

(
  • object
)
Box

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

Parameters:

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

(
  • object
)
ConvexPolyhedron

Computes 3D convex hull as a ConvexPolyhedron.

A convex hull is a convex geometry that contain all the geometry points inside.

Parameters:

  • object Object3D

    Object to calculate the convex hull.

Returns:

ConvexPolyhedron:

Convex polyhedron calculated from thr object meshes.

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. Trimesh objects represent the object exactly with all the triangles that compose the original geometry

This type of physics shape should be avoided as much as possible since it is a lot slower that other available types.

Parameters:

  • geometry Geometry

Returns:

Trimesh:

shape

createTubeShape

(
  • geometry
)
Trimesh

Cylinder shape from bounding 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 identify the type of physics shapes:

  • BOX
  • CYLINDER
  • SPHERE
  • HULL