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;
417 virtual agx::Vec3 getCenter()
const override;
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)
568 size_t triangleIndex,
569 uint_fast8_t localVertexIndex )
const;
577 size_t triangleIndex )
const;
607 bool hasHalfEdge()
const;
610 const AabbTree* getBvhTree()
const;
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;
851 if (newMargin >= 0) {
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();
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGXPHYSICS_EXPORT
Axis aligned bounding box implementation.
Class for data sharing only to be used by Mesh, its internal classes and children.
Class in order to circulate over the edges connected to a Triangle's face.
FaceEdgeCirculator()
A newly created and unassigned FaceEdgeCirculator will be invalid.
const Triangle getTriangle() const
uint_fast8_t m_localEdgeIndex
agx::Vec3 getEdgeStartVertex() const
const Mesh * getMesh() const
agx::Vec3 getEdgeEndVertex() const
FaceEdgeCirculator & operator++()
Move circulator one step counter clockwise around the face.
FaceEdgeCirculator(const Mesh *mesh, size_t triangleIndex)
This hidden constructor can only be called from the Mesh class.
uint_fast8_t getLocalEdgeIndex() const
Class for more intuitive access to the Mesh's mesh data.
agx::Vec3 getVertex(uint_fast8_t localVertexIndex) const
agx::Vec3 getEdgeEndVertex(uint_fast8_t localEdgeIndex) const
Triangle()
This constructor is hidden and should only be called from the Mesh class and its children.
agx::Vec3 getEdgeStartVertex(uint_fast8_t localEdgeIndex) const
size_t getHalfEdgePartnerGlobalEdgeIndex(uint_fast8_t localEdgeIndex) const
const Mesh * getMesh() const
size_t getGlobalVertexIndex(uint_fast8_t localVertexIndex) const
Returns the global index of the vertex.
agx::Real getMaximumEdgeLength() const
agx::Vec3 getNormal() const
This function returns the triangle normal (as stored in the collision mesh data).
bool hasHalfEdgePartner(uint_fast8_t localEdgeIndex) const
size_t getTriangleIndex() const
Implementations.
Triangle(const Mesh *mesh, size_t triangleIndex)
This constructor is hidden and should only be called from the Mesh class.
size_t getHalfEdgePartnerLocalEdgeIndex(uint_fast8_t localEdgeIndex) const
const Triangle getHalfEdgePartner(uint_fast8_t localEdgeIndex) const
Class in order to circulate over the edges connected to a Triangle's vertex.
size_t getTriangleIndex() const
bool m_hasJustJumpedOverHole
uint_fast8_t m_localEdgeStartIndex
const Mesh * getMesh() const
const Triangle getTriangle() const
agx::Vec3 getEdgeStartVertex() const
agx::Vec3 getEdgeEndVertex() const
uint_fast8_t getLocalEdgeIndex() const
size_t m_triangleStartIndex
VertexEdgeCirculator(const Mesh *mesh, size_t triangleIndex, uint_fast8_t localVertexIndex)
This hidden constructor can only be called from the Mesh class.
uint_fast8_t m_localEdgeIndex
VertexEdgeCirculator()
A newly created and unassigned VertexEdgeCirculator will be invalid.
VertexEdgeCirculator & operator++()
Move circulator one step clockwise.
bool hasJustJumpedOverHole() const
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
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...
virtual void calculatePossibleTriangleOverlapsAlongLineSegment(const agx::Vec3 &segmentStartLocal, const agx::Vec3 &segmentEndLocal, agx::UInt32Vector &triangleIndices) const =0
Calculates an array of triangle indices of the triangles whose bounding volumes get intersected by a ...
virtual void updateBvhTree()=0
virtual agx::Real getVolume() const override
void restore(class agxStream::InputArchive &in) override
bool isValidAndClosed() const
virtual void calculatePossibleTriangleOverlapsAlongLineSegment(const agx::Vec3 &segmentStartLocal, const agx::Vec3 &segmentEndLocal, agxData::LocalVector< agx::UInt32 > &triangleIndices) const =0
Calculates an array of triangle indices of the triangles whose bounding volumes get intersected by a ...
bool isConvexEdge(size_t globalEdgeIndex) const
Is an edge convex? Returns always true if half edge information is missing on this edge/the whole mes...
size_t getNumTriangles() const
static size_t getGlobalTriangleIndex(size_t globalEdgeIndex)
bool isConvexVertex(size_t triangleIndex, size_t localVertexIndex) const
Is an vertex convex? Returns always true if half edge information is missing on this vertex/the whole...
virtual agx::Vec3 getCenter() const override
virtual ~Mesh()
Hide destructor.
agx::Vec3 getTriangleNormal(size_t triangleIndex) const
bool isValidEdgeIndex(size_t globalEdgeIndex) const
BoundingAABB m_localBound
const BoundingAABB & getLocalBound() const
void store(class agxStream::OutputArchive &out) const override
agx::Vec3 getVertex(size_t globalVertexIndex) const
size_t getNumVertices() const
CollisionMeshDataRef m_collisionMeshData
bool hasInternalCenterPoint() const
virtual const BoundingAABB & updateBoundingVolume() override
Calculate the bounding volume based on the current Shape parameters including transformation.
uint32_t getHalfEdgePartnerEdge(size_t globalEdgeIndex) const
VertexEdgeCirculator createVertexEdgeCirculator(size_t triangleIndex, uint_fast8_t localVertexIndex) const
Creates an VertexEdgeCirculator pointing to this Triangle and a Voronoi region.
const Triangle getTriangle(size_t triangleIndex) const
const CollisionMeshData * getMeshData() const
bool isValidTriangleIndex(size_t globalTriangleIndex) 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.
agx::Real getTotalMaximumEdgeLength() const
FaceEdgeCirculator createFaceEdgeCirculator(size_t triangleIndex) const
Creates an FaceEdgeCirculator pointing to this Triangle and a Voronoi region.
void setBottomMargin(agx::Real newMargin)
Sets a bottom safety margin that is added below the lowest point of the height field in local z direc...
void calculateTriangleOverlapsAlongLineSegment(const agx::Vec3 &segmentStartLocal, const agx::Vec3 &segmentEndLocal, TriangleLineSegmentResultVector &triangleResults) const
Calculates all triangle overlaps of a line segment with the mesh.
Mesh(Shape::Type type, agx::Physics::Geometry::ShapePtr entity)
Hidden, should only be called by child classes.
agx::Real getBottomMargin() const
const AabbTree * getBvhTree() const
agx::Vec3 getTriangleVertex(size_t triangleIndex, uint_fast8_t localVertexIndex) const
Returns one of the three vertices in a triangle.
static size_t getLocalEdgeIndex(size_t globalEdgeIndex)
agx::Real getTriangleMaximumEdgeLength(size_t triangleIndex) const
virtual BoundingAABB calculateLocalBound() const override
Calculate the bounding volume in the local coordinate system.
agx::Vector< TriangleLineSegmentResult > TriangleLineSegmentResultVector
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.
virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override
Returns the inertia of the shape, scaled with the mass. Inherited from class Shape.
Type
Define the type of a Shape.
agx::UInt32 incrementModifiedCount()
Increment the number of times the shape have been modified.
Class for writing serialized data in binary format to a stream.
Pointer to a entity instance of type Physics.Geometry.Shape.
Specialized type of matrices for holding symmetric positive definite matrices.
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Struct used in calculateTriangleOverlapsAlongLineSegment.
TriangleLineSegmentResult(agx::UInt32 newTriangleIndex, agx::Real newLineParameter, bool newIsFrontFace)
agx::UInt32 triangleIndex