17 #ifndef AGXCOLLIDE_MESH_H 18 #define AGXCOLLIDE_MESH_H 25 #include <GIMPACT/AabbTree.h> 86 agx::Vec3 getVertex( uint_fast8_t localVertexIndex )
const;
101 bool isValid()
const;
108 size_t getGlobalVertexIndex( uint_fast8_t localVertexIndex )
const;
114 agx::Vec3 getEdgeStartVertex( uint_fast8_t localEdgeIndex )
const;
120 agx::Vec3 getEdgeEndVertex( uint_fast8_t localEdgeIndex )
const;
129 bool hasHalfEdgePartner( uint_fast8_t localEdgeIndex )
const;
139 const Triangle getHalfEdgePartner( uint_fast8_t localEdgeIndex )
const;
151 size_t getHalfEdgePartnerGlobalEdgeIndex( uint_fast8_t localEdgeIndex )
const;
162 size_t getHalfEdgePartnerLocalEdgeIndex( uint_fast8_t localEdgeIndex )
const;
168 size_t getTriangleIndex()
const;
171 const Mesh* getMesh()
const;
214 void operator++(
int);
229 bool isValid()
const;
244 inline const Triangle getTriangle()
const;
247 uint_fast8_t getLocalEdgeIndex()
const;
250 bool hasJustJumpedOverHole()
const;
253 size_t getTriangleIndex()
const;
256 const Mesh* getMesh()
const;
271 size_t triangleIndex, uint_fast8_t localVertexIndex );
298 void operator++(
int);
310 bool isValid()
const;
328 uint_fast8_t getLocalEdgeIndex()
const;
331 const Mesh* getMesh()
const;
358 size_t getNumVertices()
const;
364 agx::Vec3 getVertex(
size_t globalVertexIndex )
const;
367 size_t getNumTriangles()
const;
375 agx::Vec3 getTriangleVertex(
size_t triangleIndex, uint_fast8_t localVertexIndex )
const;
381 agx::Vec3 getTriangleNormal(
size_t triangleIndex )
const;
389 size_t getGlobalVertexIndex(
size_t triangleIndex, uint_fast8_t localVertexIndex )
const;
395 agx::Real getTriangleMaximumEdgeLength(
size_t triangleIndex )
const;
398 agx::Real getTotalMaximumEdgeLength()
const;
401 uint32_t getHalfEdgePartnerEdge(
size_t globalEdgeIndex )
const;
407 bool isValid()
const;
414 bool isValidAndClosed()
const;
420 virtual agx::Real getVolume()
const override;
426 bool isTerrain()
const;
429 bool hasInternalCenterPoint()
const;
445 void setBottomMargin(
agx::Real newMargin);
451 bool isValidEdgeIndex(
size_t globalEdgeIndex )
const;
457 bool isValidTriangleIndex(
size_t globalTriangleIndex )
const;
463 inline const Triangle getTriangle(
size_t triangleIndex )
const;
469 static size_t getLocalEdgeIndex(
size_t globalEdgeIndex );
475 static size_t getGlobalTriangleIndex(
size_t globalEdgeIndex );
484 static size_t getGlobalEdgeIndex (
size_t triangleIndex, uint_fast8_t localEdgeIndex );
495 void calculateTrianglesInVolume(
499 void calculateTrianglesInVolume(
508 agx::Real newLineParameter,
bool newIsFrontFace) :
509 lineParameter(newLineParameter), triangleIndex(newTriangleIndex),
510 isFrontFace(newIsFrontFace)
529 void calculateTriangleOverlapsAlongLineSegment(
532 TriangleLineSegmentResultVector& triangleResults)
const;
541 virtual void calculatePossibleTriangleOverlapsAlongLineSegment(
554 virtual void calculatePossibleTriangleOverlapsAlongLineSegment(
568 size_t triangleIndex,
569 uint_fast8_t localVertexIndex )
const;
577 size_t triangleIndex )
const;
587 bool isConvexEdge(
size_t globalEdgeIndex)
const;
601 bool isConvexVertex(
size_t triangleIndex,
size_t localVertexIndex)
const;
607 bool hasHalfEdge()
const;
610 const AabbTree* getBvhTree()
const;
612 virtual const BoundingAABB& updateBoundingVolume()
override;
613 virtual BoundingAABB calculateLocalBound()
const override;
629 virtual void updateBvhTree() = 0;
644 return m_triangleIndex;
650 return m_mesh->getGlobalVertexIndex( m_triangleIndex, localVertexIndex );
656 return m_mesh->isValid() && m_mesh->isValidTriangleIndex( m_triangleIndex );
662 return m_mesh->getTriangleNormal( m_triangleIndex );
668 return m_mesh->getTriangleVertex( m_triangleIndex, localVertexIndex );
674 return m_mesh->getTriangleVertex( m_triangleIndex, localEdgeIndex );
680 return m_mesh->getTriangleVertex( m_triangleIndex, (uint_fast8_t)((localEdgeIndex + (uint_fast8_t)1) % (uint_fast8_t)3) );
686 return m_mesh->getTriangleMaximumEdgeLength( m_triangleIndex );
699 return Triangle( m_mesh, this->getHalfEdgePartnerGlobalEdgeIndex( localEdgeIndex ) / 3 ) ;
706 return this->getHalfEdgePartnerGlobalEdgeIndex( localEdgeIndex ) % 3;
714 return m_mesh->isValidEdgeIndex( this->getHalfEdgePartnerGlobalEdgeIndex( localEdgeIndex ) );
727 return 3 * triangleIndex + localEdgeIndex;
739 return globalEdgeIndex % 3;
745 return globalEdgeIndex / 3;
751 return m_collisionMeshData->m_vertices.size();
757 return m_collisionMeshData->m_vertices[ globalVertexIndex ];
763 return m_collisionMeshData->m_numTriangles;
769 return m_collisionMeshData->m_vertices[m_collisionMeshData->m_indices[3 * triangleIndex + localVertexIndex]];
775 return m_collisionMeshData->m_normals[triangleIndex];
781 return m_collisionMeshData->m_indices[3 * triangleIndex + localVertexIndex];
787 return m_collisionMeshData->m_triangleMaximumEdgeLengths[triangleIndex];
793 return m_collisionMeshData->m_totalMaximumEdgeLength;
799 return m_collisionMeshData->m_halfEdges[globalEdgeIndex];
805 return m_collisionMeshData->m_valid;
811 return (m_collisionMeshData->m_valid && m_collisionMeshData->m_closed);
816 return m_collisionMeshData->m_center;
822 return m_collisionMeshData->m_volume;
828 return mass * m_collisionMeshData->m_inertia;
834 return m_collisionMeshData->m_isTerrain;
839 return m_collisionMeshData->m_hasInternalCenterPoint;
845 return m_collisionMeshData->m_bottomMargin;
851 if (newMargin >= 0) {
852 m_collisionMeshData->m_bottomMargin = newMargin;
853 incrementModifiedCount();
854 updateBoundingVolume();
861 return globalEdgeIndex < m_collisionMeshData->m_indices.size();
867 return globalTriangleIndex < m_collisionMeshData->m_numTriangles;
873 return m_collisionMeshData.get();
879 return m_collisionMeshData->m_hasHalfEdge;
895 if (m_hasJustJumpedOverHole) {
898 m_localEdgeIndex = (uint_fast8_t)((m_localEdgeIndex + (uint_fast8_t)1) % (uint_fast8_t)3);
899 m_hasJustJumpedOverHole =
false;
902 size_t he = m_mesh->getHalfEdgePartnerEdge(3 * m_triangleIndex + m_localEdgeIndex);
903 if (!m_mesh->isValidEdgeIndex(he)) {
906 m_triangleIndex = m_triangleStartIndex;
907 m_localEdgeIndex = (uint_fast8_t)((m_localEdgeStartIndex + (uint_fast8_t)2) % (uint_fast8_t)3);
908 m_hasJustJumpedOverHole =
true;
909 size_t he2 = m_mesh->getHalfEdgePartnerEdge(3 * m_triangleIndex + m_localEdgeIndex);
910 while (m_mesh->isValidEdgeIndex( he2 )) {
911 m_triangleIndex = he2 / 3;
912 m_localEdgeIndex = (uint_fast8_t)((he2 + 2) % 3);
913 he2 = m_mesh->getHalfEdgePartnerEdge(3 * m_triangleIndex + m_localEdgeIndex);
917 m_triangleIndex = he / 3;
918 m_localEdgeIndex = (uint_fast8_t)((he + 1) % 3);
942 return (m_valid && m_hasMoved && m_localEdgeIndex == m_localEdgeStartIndex &&
943 m_triangleIndex == m_triangleStartIndex);
951 return m_mesh->getMeshData()->m_vertices[
952 m_mesh->getMeshData()->m_indices[3 * m_triangleIndex + m_localEdgeIndex]];
960 return m_mesh->getMeshData()->m_vertices[
961 m_mesh->getMeshData()->m_indices[3 * m_triangleIndex + (m_localEdgeIndex + 1) % 3]];
967 return m_hasJustJumpedOverHole;
974 return Triangle( m_mesh->getTriangle( m_triangleIndex ));
980 return m_localEdgeIndex;
986 return m_triangleIndex;
1000 m_aabbTree->findCollision(&volume, std::back_inserter(triangleIndices), meshToWorld, volumeToWorld );
1009 m_aabbTree->findCollision(&volume, std::back_inserter(triangleIndices), meshToWorld, volumeToWorld );
1014 size_t triangleIndex,
1015 uint_fast8_t localVertexIndex )
const 1028 m_localEdgeIndex = (uint_fast8_t)((m_localEdgeIndex + (uint_fast8_t)1) % (uint_fast8_t)3);
1049 return (m_valid && m_hasMoved && m_localEdgeIndex == 0);
1057 return m_mesh->getMeshData()->m_vertices[
1058 m_mesh->getMeshData()->m_indices[3 * m_triangleIndex + m_localEdgeIndex]];
1066 return m_mesh->getMeshData()->m_vertices[
1067 m_mesh->getMeshData()->m_indices[3 * m_triangleIndex + (m_localEdgeIndex + 1) % 3]];
1074 return m_mesh->getTriangle( m_triangleIndex );
1080 return m_localEdgeIndex;
1086 size_t triangleIndex )
const 1094 return m_mesh.get();
1099 return m_localBound;
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 getEdgeEndVertex(uint_fast8_t localEdgeIndex) const
VertexEdgeCirculator createVertexEdgeCirculator(size_t triangleIndex, uint_fast8_t localVertexIndex) const
Creates an VertexEdgeCirculator pointing to this Triangle and a Voronoi region.
const BoundingAABB & getLocalBound() const
const Triangle getTriangle() const
size_t getGlobalVertexIndex(uint_fast8_t localVertexIndex) const
Returns the global index of the vertex.
const Triangle getTriangle() const
bool m_hasJustJumpedOverHole
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
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.
const Triangle getHalfEdgePartner(uint_fast8_t localEdgeIndex) const
bool hasJustJumpedOverHole() const
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...
This namespace consists of a set of classes for handling geometric intersection tests including boole...
agx::Vec3 getEdgeStartVertex() const
FaceEdgeCirculator createFaceEdgeCirculator(size_t triangleIndex) const
Creates an FaceEdgeCirculator pointing to this Triangle and a Voronoi region.
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.
uint_fast8_t getLocalEdgeIndex() const
agx::Real getBottomMargin() const
BoundingAABB m_localBound
agx::Real getTotalMaximumEdgeLength() const
uint_fast8_t m_localEdgeIndex
agx::Vector< TriangleLineSegmentResult > TriangleLineSegmentResultVector
static size_t getGlobalTriangleIndex(size_t globalEdgeIndex)
const AabbTree * getBvhTree() const
agx::Real getMaximumEdgeLength() const
bool hasHalfEdgePartner(uint_fast8_t localEdgeIndex) const
size_t getHalfEdgePartnerGlobalEdgeIndex(uint_fast8_t localEdgeIndex) const
AGXMODEL_EXPORT agx::Vec3 getCenter(const agxCollide::Mesh::Triangle &triangle)
Class in order to circulate over the edges connected to a Triangle's vertex.
static size_t getLocalEdgeIndex(size_t globalEdgeIndex)
agx::Vec3 getTriangleNormal(size_t triangleIndex) const
agx::Vec3 getEdgeEndVertex() const
const Mesh * getMesh() const
Class for more intuitive access to the Mesh's mesh data.
uint_fast8_t m_localEdgeIndex
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...
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 getVertex(uint_fast8_t localVertexIndex) const
const CollisionMeshData * getMeshData() 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.
uint_fast8_t m_localEdgeStartIndex
Struct used in calculateTriangleOverlapsAlongLineSegment.
Class in order to circulate over the edges connected to a Triangle's face.
bool isValidEdgeIndex(size_t globalEdgeIndex) const
agx::UInt32 triangleIndex
size_t getNumVertices() const
agx::Vec3 getEdgeStartVertex(uint_fast8_t localEdgeIndex) const
const Triangle getTriangle(size_t triangleIndex) const
virtual agx::Real getVolume() const override
uint_fast8_t getLocalEdgeIndex() const
bool isValidAndClosed() const
bool hasInternalCenterPoint() const
Type
Define the type of a Shape.
Class for writing serialized data in binary format to a stream.
VertexEdgeCirculator & operator++()
Move circulator one step clockwise.
size_t getTriangleIndex() const
virtual agx::Vec3 getCenter() const override
const Mesh * getMesh() const
agx::Vec3 getVertex(size_t globalVertexIndex) const
agx::Vec3 getEdgeStartVertex() const
Axis aligned bounding box implementation.
agx::Real getTriangleMaximumEdgeLength(size_t triangleIndex) const
agx::Vec3 getEdgeEndVertex() const
uint32_t getHalfEdgePartnerEdge(size_t globalEdgeIndex) const
virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override
Returns the inertia of the shape, scaled with the mass. Inherited from class Shape.
size_t getNumTriangles() const
const Mesh * getMesh() const
size_t getGlobalVertexIndex(size_t triangleIndex, uint_fast8_t localVertexIndex) const
Returns the global index of one of the three vertices in a triangle.
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
size_t getHalfEdgePartnerLocalEdgeIndex(uint_fast8_t localEdgeIndex) const
bool isValidTriangleIndex(size_t globalTriangleIndex) const