17 #ifndef AGXCOLLIDE_MESH_H
18 #define AGXCOLLIDE_MESH_H
26 #include <agxCollide/GIMPACT/AabbTree.h>
85 agx::Vec3 getVertex( uint_fast8_t localVertexIndex )
const;
100 bool isValid()
const;
107 size_t getGlobalVertexIndex( uint_fast8_t localVertexIndex )
const;
113 agx::Vec3 getEdgeStartVertex( uint_fast8_t localEdgeIndex )
const;
119 agx::Vec3 getEdgeEndVertex( uint_fast8_t localEdgeIndex )
const;
128 bool hasHalfEdgePartner( uint_fast8_t localEdgeIndex )
const;
138 const Triangle getHalfEdgePartner( uint_fast8_t localEdgeIndex )
const;
150 size_t getHalfEdgePartnerGlobalEdgeIndex( uint_fast8_t localEdgeIndex )
const;
161 size_t getHalfEdgePartnerLocalEdgeIndex( uint_fast8_t localEdgeIndex )
const;
167 size_t getTriangleIndex()
const;
170 const Mesh* getMesh()
const;
213 void operator++(
int);
228 bool isValid()
const;
243 inline const Triangle getTriangle()
const;
246 uint_fast8_t getLocalEdgeIndex()
const;
249 bool hasJustJumpedOverHole()
const;
252 size_t getTriangleIndex()
const;
255 const Mesh* getMesh()
const;
270 size_t triangleIndex, uint_fast8_t localVertexIndex );
297 void operator++(
int);
309 bool isValid()
const;
327 uint_fast8_t getLocalEdgeIndex()
const;
330 const Mesh* getMesh()
const;
357 size_t getNumVertices()
const;
363 agx::Vec3 getVertex(
size_t globalVertexIndex )
const;
366 size_t getNumTriangles()
const;
374 agx::Vec3 getTriangleVertex(
size_t triangleIndex, uint_fast8_t localVertexIndex )
const;
380 agx::Vec3 getTriangleNormal(
size_t triangleIndex )
const;
388 size_t getGlobalVertexIndex(
size_t triangleIndex, uint_fast8_t localVertexIndex )
const;
394 agx::Real getTriangleMaximumEdgeLength(
size_t triangleIndex )
const;
397 agx::Real getTotalMaximumEdgeLength()
const;
400 uint32_t getHalfEdgePartnerEdge(
size_t globalEdgeIndex )
const;
406 bool isValid()
const;
413 bool isValidAndClosed()
const;
419 virtual agx::Real getVolume()
const override;
425 bool isTerrain()
const;
428 bool hasInternalCenterPoint()
const;
444 void setBottomMargin(
agx::Real newMargin);
450 bool isValidEdgeIndex(
size_t globalEdgeIndex )
const;
456 bool isValidTriangleIndex(
size_t globalTriangleIndex )
const;
462 inline const Triangle getTriangle(
size_t triangleIndex )
const;
468 static size_t getLocalEdgeIndex(
size_t globalEdgeIndex );
474 static size_t getGlobalTriangleIndex(
size_t globalEdgeIndex );
483 static size_t getGlobalEdgeIndex (
size_t triangleIndex, uint_fast8_t localEdgeIndex );
494 void calculateTrianglesInVolume(
498 void calculateTrianglesInVolume(
507 agx::Real newLineParameter,
bool newIsFrontFace) :
508 lineParameter(newLineParameter), triangleIndex(newTriangleIndex),
509 isFrontFace(newIsFrontFace)
528 void calculateTriangleOverlapsAlongLineSegment(
540 virtual void calculatePossibleTriangleOverlapsAlongLineSegment(
553 virtual void calculatePossibleTriangleOverlapsAlongLineSegment(
567 size_t triangleIndex,
568 uint_fast8_t localVertexIndex )
const;
576 size_t triangleIndex )
const;
586 bool isConvexEdge(
size_t globalEdgeIndex)
const;
600 bool isConvexVertex(
size_t triangleIndex,
size_t localVertexIndex)
const;
606 bool hasHalfEdge()
const;
609 const AabbTree* getBvhTree()
const;
611 virtual const BoundingAABB& updateBoundingVolume()
override;
612 virtual BoundingAABB calculateLocalBound()
const override;
628 virtual void updateBvhTree() = 0;
649 return m_mesh->getGlobalVertexIndex( m_triangleIndex, localVertexIndex );
655 return m_mesh->isValid() && m_mesh->isValidTriangleIndex( m_triangleIndex );
661 return m_mesh->getTriangleNormal( m_triangleIndex );
667 return m_mesh->getTriangleVertex( m_triangleIndex, localVertexIndex );
673 return m_mesh->getTriangleVertex( m_triangleIndex, localEdgeIndex );
679 return m_mesh->getTriangleVertex( m_triangleIndex, (uint_fast8_t)((localEdgeIndex + (uint_fast8_t)1) % (uint_fast8_t)3) );
685 return m_mesh->getTriangleMaximumEdgeLength( m_triangleIndex );
698 return Triangle( m_mesh, this->getHalfEdgePartnerGlobalEdgeIndex( localEdgeIndex ) / 3 ) ;
705 return this->getHalfEdgePartnerGlobalEdgeIndex( localEdgeIndex ) % 3;
713 return m_mesh->isValidEdgeIndex( this->getHalfEdgePartnerGlobalEdgeIndex( localEdgeIndex ) );
726 return 3 * triangleIndex + localEdgeIndex;
738 return globalEdgeIndex % 3;
744 return globalEdgeIndex / 3;
850 if (newMargin >= 0) {
894 if (m_hasJustJumpedOverHole) {
897 m_localEdgeIndex = (uint_fast8_t)((m_localEdgeIndex + (uint_fast8_t)1) % (uint_fast8_t)3);
898 m_hasJustJumpedOverHole =
false;
901 size_t he = m_mesh->getHalfEdgePartnerEdge(3 * m_triangleIndex + m_localEdgeIndex);
902 if (!m_mesh->isValidEdgeIndex(he)) {
905 m_triangleIndex = m_triangleStartIndex;
906 m_localEdgeIndex = (uint_fast8_t)((m_localEdgeStartIndex + (uint_fast8_t)2) % (uint_fast8_t)3);
907 m_hasJustJumpedOverHole =
true;
908 size_t he2 = m_mesh->getHalfEdgePartnerEdge(3 * m_triangleIndex + m_localEdgeIndex);
909 while (m_mesh->isValidEdgeIndex( he2 )) {
910 m_triangleIndex = he2 / 3;
911 m_localEdgeIndex = (uint_fast8_t)((he2 + 2) % 3);
912 he2 = m_mesh->getHalfEdgePartnerEdge(3 * m_triangleIndex + m_localEdgeIndex);
916 m_triangleIndex = he / 3;
917 m_localEdgeIndex = (uint_fast8_t)((he + 1) % 3);
941 return (m_valid && m_hasMoved && m_localEdgeIndex == m_localEdgeStartIndex &&
942 m_triangleIndex == m_triangleStartIndex);
950 return m_mesh->getMeshData()->m_vertices[
951 m_mesh->getMeshData()->m_indices[3 * m_triangleIndex + m_localEdgeIndex]];
959 return m_mesh->getMeshData()->m_vertices[
960 m_mesh->getMeshData()->m_indices[3 * m_triangleIndex + (m_localEdgeIndex + 1) % 3]];
966 return m_hasJustJumpedOverHole;
973 return Triangle( m_mesh->getTriangle( m_triangleIndex ));
979 return m_localEdgeIndex;
985 return m_triangleIndex;
999 m_aabbTree->findCollision(&volume, std::back_inserter(triangleIndices), meshToWorld, volumeToWorld );
1008 m_aabbTree->findCollision(&volume, std::back_inserter(triangleIndices), meshToWorld, volumeToWorld );
1013 size_t triangleIndex,
1014 uint_fast8_t localVertexIndex )
const
1027 m_localEdgeIndex = (uint_fast8_t)((m_localEdgeIndex + (uint_fast8_t)1) % (uint_fast8_t)3);
1048 return (m_valid && m_hasMoved && m_localEdgeIndex == 0);
1056 return m_mesh->getMeshData()->m_vertices[
1057 m_mesh->getMeshData()->m_indices[3 * m_triangleIndex + m_localEdgeIndex]];
1065 return m_mesh->getMeshData()->m_vertices[
1066 m_mesh->getMeshData()->m_indices[3 * m_triangleIndex + (m_localEdgeIndex + 1) % 3]];
1073 return m_mesh->getTriangle( m_triangleIndex );
1079 return m_localEdgeIndex;
1085 size_t triangleIndex )
const
1093 return m_mesh.get();
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
size_t getTriangleIndex() const
Implementations.
agx::Vec3 getEdgeStartVertex() const
bool m_hasJustJumpedOverHole
agx::Real getTriangleMaximumEdgeLength(size_t triangleIndex) const
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
FaceEdgeCirculator createFaceEdgeCirculator(size_t triangleIndex) const
Creates an FaceEdgeCirculator pointing to this Triangle and a Voronoi region.
agx::Vec3 getEdgeEndVertex() const
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
Class for data sharing only to be used by Mesh, its internal classes and children.
VertexEdgeCirculator createVertexEdgeCirculator(size_t triangleIndex, uint_fast8_t localVertexIndex) const
Creates an VertexEdgeCirculator pointing to this Triangle and a Voronoi region.
static size_t getGlobalEdgeIndex(size_t triangleIndex, uint_fast8_t localEdgeIndex)
Computes the global edge index from a given triangle index and the local edge index within this trian...
const Mesh * getMesh() const
agx::UInt32 incrementModifiedCount()
Increment the number of times the shape have been modified.
size_t getHalfEdgePartnerGlobalEdgeIndex(uint_fast8_t localEdgeIndex) const
agx::Vec3 getTriangleVertex(size_t triangleIndex, uint_fast8_t localVertexIndex) const
Returns one of the three vertices in a triangle.
agx::Vec3 getNormal() const
This function returns the triangle normal (as stored in the collision mesh data). ...
#define AGXPHYSICS_EXPORT
Pointer to a entity instance of type Physics.Geometry.Shape.
BoundingAABB m_localBound
bool isValidTriangleIndex(size_t globalTriangleIndex) const
const Triangle getTriangle(size_t triangleIndex) const
const Triangle getHalfEdgePartner(uint_fast8_t localEdgeIndex) const
agx::Real getMaximumEdgeLength() const
uint_fast8_t m_localEdgeIndex
agx::Vec3 getVertex(uint_fast8_t localVertexIndex) const
agx::Vector< TriangleLineSegmentResult > TriangleLineSegmentResultVector
agx::Real getTotalMaximumEdgeLength() const
size_t getHalfEdgePartnerLocalEdgeIndex(uint_fast8_t localEdgeIndex) const
static size_t getGlobalTriangleIndex(size_t globalEdgeIndex)
const CollisionMeshData * getMeshData() const
AGXMODEL_EXPORT agx::Vec3 getCenter(const agxCollide::Mesh::Triangle &triangle)
bool isValidAndClosed() const
Class in order to circulate over the edges connected to a Triangle's vertex.
bool isValidEdgeIndex(size_t globalEdgeIndex) const
const BoundingAABB & getLocalBound() const
static size_t getLocalEdgeIndex(size_t globalEdgeIndex)
Class for more intuitive access to the Mesh's mesh data.
const AabbTree * getBvhTree() const
uint_fast8_t m_localEdgeIndex
size_t getGlobalVertexIndex(uint_fast8_t localVertexIndex) const
Returns the global index of the vertex.
void setBottomMargin(agx::Real newMargin)
Sets the depth that is added below the lowest point in the terrain in local z direction, to prevent tunneling in this direction.
agx::Vec3 getEdgeStartVertex() const
agx::Vec3 getEdgeEndVertex(uint_fast8_t localEdgeIndex) const
AGXPHYSICS_EXPORT size_t getMeshData(const agxCollide::Mesh *mesh, agx::Vec3Vector &vertices, agx::UInt32Vector &indices)
Extract vertices and indices from mesh.
Specialized type of matrices for holding symmetric positive definite matrices.
virtual const BoundingAABB & updateBoundingVolume() override
Calculate the bounding volume based on the current Shape parameters including transformation.
uint32_t getHalfEdgePartnerEdge(size_t globalEdgeIndex) const
uint_fast8_t m_localEdgeStartIndex
const Mesh * getMesh() const
const Triangle getTriangle() const
size_t getNumVertices() const
Struct used in calculateTriangleOverlapsAlongLineSegment.
Class in order to circulate over the edges connected to a Triangle's face.
agx::Vec3 getTriangleNormal(size_t triangleIndex) const
const Triangle getTriangle() const
agx::UInt32 triangleIndex
agx::Vec3 getEdgeStartVertex(uint_fast8_t localEdgeIndex) const
void calculateTrianglesInVolume(const BoundingAABB &volume, const agx::AffineMatrix4x4 &meshToWorld, const agx::AffineMatrix4x4 &volumeToWorld, agx::UInt32Vector &triangleIndices) const
Calculates an array of triangle indices of the triangles that are within a bounding volume...
uint_fast8_t getLocalEdgeIndex() const
bool hasHalfEdgePartner(uint_fast8_t localEdgeIndex) const
virtual agx::Real getVolume() const override
size_t getGlobalVertexIndex(size_t triangleIndex, uint_fast8_t localVertexIndex) const
Returns the global index of one of the three vertices in a triangle.
uint_fast8_t getLocalEdgeIndex() const
size_t getTriangleIndex() const
bool hasInternalCenterPoint() const
Type
Define the type of a Shape.
agx::Real getBottomMargin() const
Class for writing serialized data in binary format to a stream.
VertexEdgeCirculator & operator++()
Move circulator one step clockwise.
virtual agx::Vec3 getCenter() const override
agx::Vec3 getVertex(size_t globalVertexIndex) const
bool hasJustJumpedOverHole() const
Axis aligned bounding box implementation.
agx::Vec3 getEdgeEndVertex() const
size_t getNumTriangles() const
virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override
Returns the inertia of the shape, scaled with the mass. Inherited from class Shape.
const Mesh * getMesh() const
TriangleLineSegmentResult(agx::UInt32 newTriangleIndex, agx::Real newLineParameter, bool newIsFrontFace)
AGX_DECLARE_POINTER_TYPES(SpaceListener)
CollisionMeshDataRef m_collisionMeshData
FaceEdgeCirculator & operator++()
Move circulator one step counter clockwise around the face.
size_t m_triangleStartIndex