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.new({List<
Vector3> ? vertices, List<List< ? faces, List<int> >Vector3> ? normals, List<Vector3> ? axes, double? boundingSphereRadius, ShapeType type = ShapeType.convex}) - @param vertices An array of Vector3's @param faces Array of integer arrays, describing which vertices that is included in each face.
Properties
- aabbmax → Vector3
-
final
- aabbmin → Vector3
-
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<
Vector3?> -
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<
Vector3> ? -
If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check.
getter/setter pair
-
uniqueEdges
↔ List<
Vector3> -
getter/setter pair
-
vertices
↔ List<
Vector3> -
getter/setter pair
-
worldFaceNormals
↔ List<
Vector3> -
getter/setter pair
- worldFaceNormalsNeedsUpdate ↔ bool
-
getter/setter pair
-
worldVertices
↔ List<
Vector3> -
getter/setter pair
- worldVerticesNeedsUpdate ↔ bool
-
getter/setter pair
Methods
-
calculateLocalInertia(
double mass, Vector3 target) → Vector3 -
Calculates the inertia in the local frame for this shape.
@see http://en.wikipedia.org/wiki/List_of_moments_of_inertia
override
-
calculateWorldAABB(
Vector3 pos, Quaternion quat, Vector3 min, Vector3 max) → void -
@todo use abstract for these kind of methods
override
-
clipAgainstHull(
Vector3 posA, Quaternion quatA, ConvexPolyhedron hullB, Vector3 posB, Quaternion quatB, Vector3 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(
Vector3 separatingNormal, Vector3 posA, Quaternion quatA, List< Vector3> worldVertsB1, double minDist, double maxDist, List<ConvexPolyhedronContactPoint> result) → void - Clip a face against a hull. @param worldVertsB1 An array of Vector3 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< Vector3> inVertices, List<Vector3> outVertices, Vector3 planeNormal, double planeConstant) → List<Vector3> - 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(
Vector3 aabbmin, Vector3 aabbmax) → void -
computeNormals(
) → void -
Compute the normals of the faces.
Will reuse existing Vector3 objects in the
faceNormals
array if they exist. -
computeWorldFaceNormals(
Quaternion quat) → void -
Updates
worldVertices
and setsworldFaceNormalsNeedsUpdate
to false. -
computeWorldVertices(
Vector3 position, Quaternion quat) → void -
Updates
.worldVertices
and sets.worldVerticesNeedsUpdate
to false. -
findSeparatingAxis(
ConvexPolyhedron hullB, Vector3 posA, Quaternion quatA, Vector3 posB, Quaternion quatB, Vector3 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(
[Vector3? target]) → Vector3 - Get an average of all the vertices position
-
getFaceNormal(
int i, Vector3 target) → Vector3 - Compute the normal of a face from its vertices
-
getPlaneConstantOfFace(
int faceI) → double - @param face_i Index of the face
-
init(
[List< Vector3> ? vertices, List<List< ? faces, List<int> >Vector3?> ? normals, List<Vector3> ? axes, double? boundingSphereRadius]) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pointIsInside(
Vector3 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(
Vector3 axis, ConvexPolyhedron hullB, Vector3 posA, Quaternion quatA, Vector3 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(
[Vector3? 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(
Vector3 va, Vector3 vb, Vector3 vc, Vector3 target) → Vector3 - Get face normal given 3 vertices
-
project(
ConvexPolyhedron shape, Vector3 axis, Vector3 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 result
0
and result1
will be set to maximum and minimum, respectively. -
trimeshToPolyhedron(
Trimesh trimesh, Body body, [Vector3? upvector]) → Body