TriangleMesh Class Reference
This ContactGeometry subclass represents an arbitrary shape described by a mesh of triangular faces.
More...
#include <ContactGeometry.h>
List of all members.
Classes |
class | OBBTreeNode |
| This class represents a node in the Oriented Bounding Box Tree for a TriangleMesh. More...
|
Public Member Functions |
| TriangleMesh (const std::vector< Vec3 > &vertices, const std::vector< int > &faceIndices, bool smooth=false) |
| Create a TriangleMesh.
|
| TriangleMesh (const PolygonalMesh &mesh, bool smooth=false) |
| Create a TriangleMesh based on a PolygonalMesh object.
|
int | getNumEdges () const |
| Get the number of edges in the mesh.
|
int | getNumFaces () const |
| Get the number of faces in the mesh.
|
int | getNumVertices () const |
| Get the number of vertices in the mesh.
|
const Vec3 & | getVertexPosition (int index) const |
| Get the position of a vertex in the mesh.
|
int | getFaceEdge (int face, int edge) const |
| Get the index of one of the edges of a face.
|
int | getFaceVertex (int face, int vertex) const |
| Get the index of one of the vertices of a face.
|
int | getEdgeFace (int edge, int face) const |
| Get the index of one of the faces shared by an edge.
|
int | getEdgeVertex (int edge, int vertex) const |
| Get the index of one of the vertices shared by an edge.
|
void | findVertexEdges (int vertex, std::vector< int > &edges) const |
| Find all edges that intersect a vertex.
|
const UnitVec3 & | getFaceNormal (int face) const |
| Get the normal vector for a face.
|
Real | getFaceArea (int face) const |
| Get the area of a face.
|
UnitVec3 | findNormalAtPoint (int face, const Vec2 &uv) const |
| Calculate the normal vector at a point on the surface.
|
Vec3 | findNearestPoint (const Vec3 &position, bool &inside, UnitVec3 &normal) const |
| Given a point, find the nearest point on the surface of this object.
|
Vec3 | findNearestPoint (const Vec3 &position, bool &inside, int &face, Vec2 &uv) const |
| Given a point, find the nearest point on the surface of this object.
|
bool | intersectsRay (const Vec3 &origin, const UnitVec3 &direction, Real &distance, UnitVec3 &normal) const |
| Determine whether this mesh intersects a ray, and if so, find the intersection point.
|
bool | intersectsRay (const Vec3 &origin, const UnitVec3 &direction, Real &distance, int &face, Vec2 &uv) const |
| Determine whether this mesh intersects a ray, and if so, find what face it hit.
|
OBBTreeNode | getOBBTreeNode () const |
| Get the OBBTreeNode which forms the root of this mesh's Oriented Bounding Box Tree.
|
const TriangleMeshImpl & | getImpl () const |
TriangleMeshImpl & | updImpl () |
Detailed Description
This ContactGeometry subclass represents an arbitrary shape described by a mesh of triangular faces.
The mesh surface must satisfy the following requirements:
-
It must be closed, so that any point can unambiguously be classified as either inside or outside.
-
It may not intersect itself anywhere, even at a single point.
-
It must be an oriented manifold.
-
The vertices for each face must be ordered counter-clockwise when viewed from the outside. That is, if v0, v1, and v2 are the locations of the three vertices for a face, the cross product (v1-v0)%(v2-v0) must point outward.
-
The length of every edge must be non-zero.
It is your responsibility to ensure that any mesh you create meets these requirements. The constructor will detect many incorrect meshes and signal them by throwing an exception, but it is not guaranteed to detect all possible problems. If a mesh fails to satisfy any of these requirements, the results of calculations performed with it are undefined. For example, collisions involving it might fail to be detected, or contact forces on it might be calculated incorrectly.
Constructor & Destructor Documentation
TriangleMesh |
( |
const std::vector< Vec3 > & |
vertices, |
|
|
const std::vector< int > & |
faceIndices, |
|
|
bool |
smooth = false | |
|
) |
| | |
Create a TriangleMesh.
- Parameters:
-
| vertices | the positions of all vertices in the mesh |
| faceIndices | the indices of the vertices that make up each face. The first three elements are the vertices in the first face, the next three elements are the vertices in the second face, etc. |
| smooth | if true, the mesh will be treated as a smooth surface, and normal vectors will be smoothly interpolated between vertices. If false, it will be treated as a faceted mesh with a constant normal vector over each face. |
Create a TriangleMesh based on a PolygonalMesh object.
If any faces of the PolygonalMesh have more than three vertices, they are automatically triangulated.
- Parameters:
-
| mesh | the PolygonalMesh from which to construct a triangle mesh |
| smooth | if true, the mesh will be treated as a smooth surface, and normal vectors will be smoothly interpolated between vertices. If false, it will be treated as a faceted mesh with a constant normal vector over each face. |
Member Function Documentation
Vec3 findNearestPoint |
( |
const Vec3 & |
position, |
|
|
bool & |
inside, |
|
|
int & |
face, |
|
|
Vec2 & |
uv | |
|
) |
| | const |
Given a point, find the nearest point on the surface of this object.
If multiple points on the surface are equally close to the specified point, this may return any of them.
- Parameters:
-
| position | the point in question |
| inside | on exit, this is set to true if the specified point is inside this object, false otherwise |
| face | on exit, this contains the index of the face containing the returned point |
| uv | on exit, this contains the barycentric coordinates (u and v) of the returned point within its face |
- Returns:
- the point on the surface of the object which is closest to the specified point
Vec3 findNearestPoint |
( |
const Vec3 & |
position, |
|
|
bool & |
inside, |
|
|
UnitVec3 & |
normal | |
|
) |
| | const |
Given a point, find the nearest point on the surface of this object.
If multiple points on the surface are equally close to the specified point, this may return any of them.
- Parameters:
-
| position | the point in question |
| inside | on exit, this is set to true if the specified point is inside this object, false otherwise |
| normal | on exit, this contains the surface normal at the returned point |
- Returns:
- the point on the surface of the object which is closest to the specified point
Reimplemented from ContactGeometry.
UnitVec3 findNormalAtPoint |
( |
int |
face, |
|
|
const Vec2 & |
uv | |
|
) |
| | const |
Calculate the normal vector at a point on the surface.
- Parameters:
-
| face | the index of the face containing the point |
| uv | the point within the face, specified by its barycentric uv coordinates |
void findVertexEdges |
( |
int |
vertex, |
|
|
std::vector< int > & |
edges | |
|
) |
| | const |
Find all edges that intersect a vertex.
- Parameters:
-
| vertex | the index of the vertex |
| edges | the indices of all edges intersecting the vertex will be added to this |
int getEdgeFace |
( |
int |
edge, |
|
|
int |
face | |
|
) |
| | const |
Get the index of one of the faces shared by an edge.
- Parameters:
-
| edge | the index of the edge |
| face | the index of the face within the edge (0 or 1) |
- Returns:
- the index of the specified face
int getEdgeVertex |
( |
int |
edge, |
|
|
int |
vertex | |
|
) |
| | const |
Get the index of one of the vertices shared by an edge.
- Parameters:
-
| edge | the index of the edge |
| vertex | the index of the vertex within the edge (0 or 1) |
- Returns:
- the index of the specified vertex
Real getFaceArea |
( |
int |
face |
) |
const |
Get the area of a face.
- Parameters:
-
| face | the index of the face |
int getFaceEdge |
( |
int |
face, |
|
|
int |
edge | |
|
) |
| | const |
Get the index of one of the edges of a face.
Edge 0 connects vertices 0 and 1. Edge 1 connects vertices 1 and 2. Edge 2 connects vertices 0 and 2.
- Parameters:
-
| face | the index of the face |
| edge | the index of the edge within the face (0, 1, or 2) |
- Returns:
- the index of the specified edge
const UnitVec3& getFaceNormal |
( |
int |
face |
) |
const |
Get the normal vector for a face.
This points outward from the mesh.
- Parameters:
-
| face | the index of the face |
int getFaceVertex |
( |
int |
face, |
|
|
int |
vertex | |
|
) |
| | const |
Get the index of one of the vertices of a face.
- Parameters:
-
| face | the index of the face |
| vertex | the index of the vertex within the face (0, 1, or 2) |
- Returns:
- the index of the specified vertex
int getNumEdges |
( |
|
) |
const |
Get the number of edges in the mesh.
int getNumFaces |
( |
|
) |
const |
Get the number of faces in the mesh.
int getNumVertices |
( |
|
) |
const |
Get the number of vertices in the mesh.
Get the OBBTreeNode which forms the root of this mesh's Oriented Bounding Box Tree.
const Vec3& getVertexPosition |
( |
int |
index |
) |
const |
Get the position of a vertex in the mesh.
- Parameters:
-
| index | the index of the vertex to get |
- Returns:
- the position of the specified vertex
bool intersectsRay |
( |
const Vec3 & |
origin, |
|
|
const UnitVec3 & |
direction, |
|
|
Real & |
distance, |
|
|
int & |
face, |
|
|
Vec2 & |
uv | |
|
) |
| | const |
Determine whether this mesh intersects a ray, and if so, find what face it hit.
- Parameters:
-
| origin | the position at which the ray begins |
| direction | the ray direction |
| distance | if an intersection is found, the distance from the ray origin to the intersection point is stored in this. Otherwise, it is left unchanged. |
| face | if an intersection is found, the index of the face hit by the ray is stored in this. Otherwise, it is left unchanged. |
| uv | if an intersection is found, the barycentric coordinates (u and v) of the intersection point within the hit face are stored in this. Otherwise, it is left unchanged. |
- Returns:
- true if an intersection is found, false otherwise
bool intersectsRay |
( |
const Vec3 & |
origin, |
|
|
const UnitVec3 & |
direction, |
|
|
Real & |
distance, |
|
|
UnitVec3 & |
normal | |
|
) |
| | const |
Determine whether this mesh intersects a ray, and if so, find the intersection point.
- Parameters:
-
| origin | the position at which the ray begins |
| direction | the ray direction |
| distance | if an intersection is found, the distance from the ray origin to the intersection point is stored in this. Otherwise, it is left unchanged. |
| normal | if an intersection is found, the surface normal of the intersection point is stored in this. Otherwise, it is left unchanged. |
- Returns:
- true if an intersection is found, false otherwise
Reimplemented from ContactGeometry.
The documentation for this class was generated from the following file: