ConvexPolyhedron class

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 = CANNON.ConvexPolyhedron({ vertices, faces }) const convexBody = CANNON.Body({ mass: 1, shape: convexShape }) world.addBody(convexBody)

Inheritance
Implementers

Constructors

ConvexPolyhedron({List<Vec3>? vertices, List<List<int>>? faces, List<Vec3>? normals, List<Vec3>? axes, double? boundingSphereRadius, ShapeType type = ShapeType.convex})
@param vertices An array of Vec3's @param faces Array of integer arrays, describing which vertices that is included in each face.

Properties

aabbmax Vec3
final
aabbmin Vec3
final
body Body?
The body to which the shape is added to.
getter/setter pairinherited
boundingSphereRadius double
The local bounding sphere radius of this shape.
getter/setter pairinherited
collisionFilterGroup int
getter/setter pairinherited
collisionFilterMask int
getter/setter pairinherited
collisionResponse bool
Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.
getter/setter pairinherited
faceNormals List<Vec3?>
getter/setter pair
faces List<List<int>>
Array of integer arrays, indicating which vertices each face consists of
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
id int
Identifier of the Shape.
getter/setter pairinherited
material Material?
Optional material of the shape that regulates contact properties.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type ShapeType
The type of this shape. Must be set to an int > 0 by subclasses.
getter/setter pairinherited
uniqueAxes List<Vec3>?
If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check.
getter/setter pair
uniqueEdges List<Vec3>
getter/setter pair
vertices List<Vec3>
getter/setter pair
worldFaceNormals List<Vec3>
getter/setter pair
worldFaceNormalsNeedsUpdate bool
getter/setter pair
worldVertices List<Vec3>
getter/setter pair
worldVerticesNeedsUpdate bool
getter/setter pair

Methods

calculateLocalInertia(double mass, Vec3 target) Vec3
Calculates the inertia in the local frame for this shape. @see http://en.wikipedia.org/wiki/List_of_moments_of_inertia
override
calculateWorldAABB(Vec3 pos, Quaternion quat, Vec3 min, Vec3 max) → void
@todo use abstract for these kind of methods
override
clipAgainstHull(Vec3 posA, Quaternion quatA, ConvexPolyhedron hullB, Vec3 posB, Quaternion quatB, Vec3 separatingNormal, double minDist, double maxDist, List<ConvexPolyhedronContactPoint> result) → void
@param minDist Clamp distance @param result The an array of contact point objects, see clipFaceAgainstHull
clipFaceAgainstHull(Vec3 separatingNormal, Vec3 posA, Quaternion quatA, List<Vec3> worldVertsB1, double minDist, double maxDist, List<ConvexPolyhedronContactPoint> result) → void
Clip a face against a hull. @param worldVertsB1 An array of Vec3 with vertices in the world frame. @param minDist Distance clamping @param Array result Array to store resulting contact points in. Will be objects with properties: point, depth, normal. These are represented in world coordinates.
clipFaceAgainstPlane(List<Vec3> inVertices, List<Vec3> outVertices, Vec3 planeNormal, double planeConstant) List<Vec3>
Clip a face in a hull against the back of a plane. @param planeConstant The constant in the mathematical plane equation
computeEdges() → void
Computes uniqueEdges
computeLocalAABB(Vec3 aabbmin, Vec3 aabbmax) → void
computeNormals() → void
Compute the normals of the faces. Will reuse existing Vec3 objects in the faceNormals array if they exist.
computeWorldFaceNormals(Quaternion quat) → void
Updates worldVertices and sets worldFaceNormalsNeedsUpdate to false.
computeWorldVertices(Vec3 position, Quaternion quat) → void
Updates .worldVertices and sets .worldVerticesNeedsUpdate to false.
findSeparatingAxis(ConvexPolyhedron hullB, Vec3 posA, Quaternion quatA, Vec3 posB, Quaternion quatB, Vec3 target, [List<int>? faceListA, List<int>? faceListB]) bool
Find the separating axis between this hull and another @param target The target vector to save the axis in @return Returns false if a separation is found, else true
getAveragePointLocal([Vec3? target]) Vec3
Get an average of all the vertices position
getFaceNormal(int i, Vec3 target) Vec3
Compute the normal of a face from its vertices
getPlaneConstantOfFace(int faceI) double
@param face_i Index of the face
init(List<Vec3>? vertices, List<List<int>>? faces, List<Vec3?>? normals, List<Vec3>? axes, double? boundingSphereRadius) → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pointIsInside(Vec3 p) bool
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. @param p A point given in local coordinates
testSepAxis(Vec3 axis, ConvexPolyhedron hullB, Vec3 posA, Quaternion quatA, Vec3 posB, Quaternion quatB) double?
Test separating axis against two hulls. Both hulls are projected onto the axis and the overlap size is returned if there is one. @return The overlap depth, or FALSE if no penetration.
toString() String
A string representation of this object.
inherited
transformAllPoints([Vec3? offset, Quaternion? quat]) → void
Transform all local points. Will change the .vertices
updateBoundingSphereRadius() → void
Computes the bounding sphere radius. The result is stored in the property .boundingSphereRadius
override
volume() double
Get approximate convex volume
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

computeNormal(Vec3 va, Vec3 vb, Vec3 vc, Vec3 target) Vec3
Get face normal given 3 vertices
project(ConvexPolyhedron shape, Vec3 axis, Vec3 pos, Quaternion quat, List<double> result) → void
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. @param result result0 and result1 will be set to maximum and minimum, respectively.