From 78bbb7320df1320dcf5b384317f6313755769182 Mon Sep 17 00:00:00 2001 From: Mkr Date: Thu, 16 Aug 2018 21:32:25 -0700 Subject: [PATCH 1/5] Make getVertexAt and getHeightAt public to allow for inspecting the height field (e.g. for debug draw the height field) --- src/collision/shapes/HeightFieldShape.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/collision/shapes/HeightFieldShape.h b/src/collision/shapes/HeightFieldShape.h index d8149a9e..e278dbba 100644 --- a/src/collision/shapes/HeightFieldShape.h +++ b/src/collision/shapes/HeightFieldShape.h @@ -161,12 +161,6 @@ class HeightFieldShape : public ConcaveShape { void getTriangleVerticesWithIndexPointer(int32 subPart, int32 triangleIndex, Vector3* outTriangleVertices) const; - /// Return the vertex (local-coordinates) of the height field at a given (x,y) position - Vector3 getVertexAt(int x, int y) const; - - /// Return the height of a given (x,y) point in the height field - decimal getHeightAt(int x, int y) const; - /// Return the closest inside integer grid value of a given floating grid value int computeIntegerGridValue(decimal value) const; @@ -201,6 +195,12 @@ class HeightFieldShape : public ConcaveShape { /// Return the number of columns in the height field int getNbColumns() const; + + /// Return the vertex (local-coordinates) of the height field at a given (x,y) position + Vector3 getVertexAt(int x, int y) const; + + /// Return the height of a given (x,y) point in the height field + decimal getHeightAt(int x, int y) const; /// Return the type of height value in the height field HeightDataType getHeightDataType() const; From 54f17ac0aa7a7c14b2d6c757991fd770730709f3 Mon Sep 17 00:00:00 2001 From: Mkr Date: Sun, 9 Sep 2018 16:26:29 -0700 Subject: [PATCH 2/5] Make input to PolygonVertexArray constant --- src/collision/PolygonVertexArray.cpp | 10 +++++----- src/collision/PolygonVertexArray.h | 16 ++++++++-------- src/collision/PolyhedronMesh.cpp | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/collision/PolygonVertexArray.cpp b/src/collision/PolygonVertexArray.cpp index e52590c0..260e8ffc 100644 --- a/src/collision/PolygonVertexArray.cpp +++ b/src/collision/PolygonVertexArray.cpp @@ -43,14 +43,14 @@ using namespace reactphysics3d; * @param vertexDataType Data type of the vertices data * @param indexDataType Data type of the face indices data */ -PolygonVertexArray::PolygonVertexArray(uint nbVertices, void* verticesStart, int verticesStride, - void* indexesStart, int indexesStride, +PolygonVertexArray::PolygonVertexArray(uint nbVertices, const void* verticesStart, int verticesStride, + const void* indexesStart, int indexesStride, uint nbFaces, PolygonFace* facesStart, VertexDataType vertexDataType, IndexDataType indexDataType) { mNbVertices = nbVertices; - mVerticesStart = reinterpret_cast(verticesStart); + mVerticesStart = reinterpret_cast(verticesStart); mVerticesStride = verticesStride; - mIndicesStart = reinterpret_cast(indexesStart); + mIndicesStart = reinterpret_cast(indexesStart); mIndicesStride = indexesStride; mNbFaces = nbFaces; mPolygonFacesStart = facesStart; @@ -71,7 +71,7 @@ uint PolygonVertexArray::getVertexIndexInFace(uint faceIndex, uint noVertexInFac assert(noVertexInFace < face->nbVertices); - void* vertexIndexPointer = mIndicesStart + (face->indexBase + noVertexInFace) * mIndicesStride; + const void* vertexIndexPointer = mIndicesStart + (face->indexBase + noVertexInFace) * mIndicesStride; if (mIndexDataType == PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE) { return *((uint*)vertexIndexPointer); diff --git a/src/collision/PolygonVertexArray.h b/src/collision/PolygonVertexArray.h index 09d04574..e00aa5b5 100644 --- a/src/collision/PolygonVertexArray.h +++ b/src/collision/PolygonVertexArray.h @@ -69,14 +69,14 @@ class PolygonVertexArray { uint mNbVertices; /// Pointer to the first vertex value in the array - unsigned char* mVerticesStart; + const unsigned char* mVerticesStart; /// Stride (number of bytes) between the beginning of two vertices /// values in the array int mVerticesStride; /// Pointer to the first vertex index of the array - unsigned char* mIndicesStart; + const unsigned char* mIndicesStart; /// Stride (number of bytes) between the beginning of two indices in /// the array @@ -97,8 +97,8 @@ class PolygonVertexArray { public: /// Constructor - PolygonVertexArray(uint nbVertices, void* verticesStart, int verticesStride, - void* indexesStart, int indexesStride, + PolygonVertexArray(uint nbVertices, const void* verticesStart, int verticesStride, + const void* indexesStart, int indexesStride, uint nbFaces, PolygonFace* facesStart, VertexDataType vertexDataType, IndexDataType indexDataType); @@ -130,10 +130,10 @@ class PolygonVertexArray { PolygonFace* getPolygonFace(uint faceIndex) const; /// Return the pointer to the start of the vertices array - unsigned char* getVerticesStart() const; + const unsigned char* getVerticesStart() const; /// Return the pointer to the start of the indices array - unsigned char* getIndicesStart() const; + const unsigned char* getIndicesStart() const; }; // Return the vertex data type @@ -198,7 +198,7 @@ inline PolygonVertexArray::PolygonFace* PolygonVertexArray::getPolygonFace(uint /** * @return A pointer to the start of the vertex array of the polyhedron */ -inline unsigned char* PolygonVertexArray::getVerticesStart() const { +inline const unsigned char* PolygonVertexArray::getVerticesStart() const { return mVerticesStart; } @@ -206,7 +206,7 @@ inline unsigned char* PolygonVertexArray::getVerticesStart() const { /** * @return A pointer to the start of the face indices array of the polyhedron */ -inline unsigned char* PolygonVertexArray::getIndicesStart() const { +inline const unsigned char* PolygonVertexArray::getIndicesStart() const { return mIndicesStart; } diff --git a/src/collision/PolyhedronMesh.cpp b/src/collision/PolyhedronMesh.cpp index c8ca9e77..850991a6 100644 --- a/src/collision/PolyhedronMesh.cpp +++ b/src/collision/PolyhedronMesh.cpp @@ -105,7 +105,7 @@ Vector3 PolyhedronMesh::getVertex(uint index) const { uint vertexIndex = mHalfEdgeStructure.getVertex(index).vertexPointIndex; PolygonVertexArray::VertexDataType vertexType = mPolygonVertexArray->getVertexDataType(); - unsigned char* verticesStart = mPolygonVertexArray->getVerticesStart(); + const unsigned char* verticesStart = mPolygonVertexArray->getVerticesStart(); int vertexStride = mPolygonVertexArray->getVerticesStride(); Vector3 vertex; From 5f4d14d3033b8bf8ec0cff9c161ef869ddff418a Mon Sep 17 00:00:00 2001 From: Mkr Date: Sun, 9 Sep 2018 16:28:34 -0700 Subject: [PATCH 3/5] Add accessor methods to ConcaveMeshShape to allow reading back vertices and normals for inspection from the user code. --- src/collision/shapes/ConcaveMeshShape.cpp | 44 +++++++++++++++++++++++ src/collision/shapes/ConcaveMeshShape.h | 15 ++++++++ 2 files changed, 59 insertions(+) diff --git a/src/collision/shapes/ConcaveMeshShape.cpp b/src/collision/shapes/ConcaveMeshShape.cpp index 42d7ddd1..631d2415 100644 --- a/src/collision/shapes/ConcaveMeshShape.cpp +++ b/src/collision/shapes/ConcaveMeshShape.cpp @@ -115,6 +115,50 @@ void ConcaveMeshShape::getTriangleVerticesNormals(uint subPart, uint triangleInd triangleVertexArray->getTriangleVerticesNormals(triangleIndex, outVerticesNormals); } +// Return the indices of the three vertices of a given triangle in the array +void ConcaveMeshShape::getTriangleVerticesIndices(uint subPart, uint triangleIndex, uint* outVerticesIndices) const { + + // Get the triangle vertex array of the current sub-part + TriangleVertexArray* triangleVertexArray = mTriangleMesh->getSubpart(subPart); + + // Get the vertices normals of the triangle + triangleVertexArray->getTriangleVerticesIndices(triangleIndex, outVerticesIndices); +} + +// Return the number of sub parts contained in this mesh +uint ConcaveMeshShape::getNbSubparts() const +{ + return mTriangleMesh->getNbSubparts(); +} + +// Return the number of triangles in a sub part +uint ConcaveMeshShape::getNbTriangles(uint subPart) const +{ + assert(mTriangleMesh->getSubpart(subPart)); + return mTriangleMesh->getSubpart(subPart)->getNbTriangles(); +} + +// Return the triangle positions for a specific subpart and triangle index +void ConcaveMeshShape::getTriangleVertices(uint subPart, uint triangleIndex, Vector3* v1, Vector3* v2, Vector3* v3) const +{ + assert(mTriangleMesh->getSubpart(subPart)); + Vector3 outTriangleVertices[3]; + getTriangleVertices(subPart, triangleIndex, &outTriangleVertices[0]); + *v1 = outTriangleVertices[0]; + *v2 = outTriangleVertices[1]; + *v3 = outTriangleVertices[2]; +} + +// Return the triangle normals for a specific subpart and triangle index +void ConcaveMeshShape::getTriangleVerticesNormals(uint subPart, uint triangleIndex, Vector3* n1, Vector3* n2, Vector3* n3) const +{ + assert(mTriangleMesh->getSubpart(subPart)); + Vector3 outTriangleVerticesNormals[3]; + getTriangleVerticesNormals(subPart, triangleIndex, &outTriangleVerticesNormals[0]); + *n1 = outTriangleVerticesNormals[0]; + *n2 = outTriangleVerticesNormals[1]; + *n3 = outTriangleVerticesNormals[2]; +} // Use a callback method on all triangles of the concave shape inside a given AABB void ConcaveMeshShape::testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const { diff --git a/src/collision/shapes/ConcaveMeshShape.h b/src/collision/shapes/ConcaveMeshShape.h index d5353d6f..36f6607c 100644 --- a/src/collision/shapes/ConcaveMeshShape.h +++ b/src/collision/shapes/ConcaveMeshShape.h @@ -160,6 +160,9 @@ class ConcaveMeshShape : public ConcaveShape { /// Return the three vertex normals (in the array outVerticesNormals) of a triangle void getTriangleVerticesNormals(uint subPart, uint triangleIndex, Vector3* outVerticesNormals) const; + + /// Return the indices of the three vertices of a given triangle in the array + void getTriangleVerticesIndices(uint subPart, uint triangleIndex, uint* outVerticesIndices) const; /// Compute the shape Id for a given triangle of the mesh uint computeTriangleShapeId(uint subPart, uint triangleIndex) const; @@ -180,6 +183,18 @@ class ConcaveMeshShape : public ConcaveShape { /// Return the scaling vector const Vector3& getScaling() const; + + /// Return the number of sub parts contained in this mesh + uint getNbSubparts() const; + + /// Return the number of triangles in a sub part + uint getNbTriangles(uint subPart) const; + + /// Return the triangle positions for a specific subpart and triangle index + void getTriangleVertices(uint subPart, uint triangleIndex, Vector3* v1, Vector3* v2, Vector3* v3) const; + + /// Return the triangle normals for a specific subpart and triangle index + void getTriangleVerticesNormals(uint subPart, uint triangleIndex, Vector3* n1, Vector3* n2, Vector3* n3) const; /// Return the local bounds of the shape in x, y and z directions. virtual void getLocalBounds(Vector3& min, Vector3& max) const override; From 5b0227c5c508a1eb64a7be5aafe34aeb04e7f7a9 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Wed, 12 Sep 2018 09:39:00 +0200 Subject: [PATCH 4/5] Modifications of pull request (move private methods to public) --- src/collision/shapes/ConcaveMeshShape.cpp | 24 +-------------------- src/collision/shapes/ConcaveMeshShape.h | 26 +++++++++-------------- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/src/collision/shapes/ConcaveMeshShape.cpp b/src/collision/shapes/ConcaveMeshShape.cpp index 631d2415..23a4bf4d 100644 --- a/src/collision/shapes/ConcaveMeshShape.cpp +++ b/src/collision/shapes/ConcaveMeshShape.cpp @@ -131,35 +131,13 @@ uint ConcaveMeshShape::getNbSubparts() const return mTriangleMesh->getNbSubparts(); } -// Return the number of triangles in a sub part +// Return the number of triangles in a sub part of the mesh uint ConcaveMeshShape::getNbTriangles(uint subPart) const { assert(mTriangleMesh->getSubpart(subPart)); return mTriangleMesh->getSubpart(subPart)->getNbTriangles(); } -// Return the triangle positions for a specific subpart and triangle index -void ConcaveMeshShape::getTriangleVertices(uint subPart, uint triangleIndex, Vector3* v1, Vector3* v2, Vector3* v3) const -{ - assert(mTriangleMesh->getSubpart(subPart)); - Vector3 outTriangleVertices[3]; - getTriangleVertices(subPart, triangleIndex, &outTriangleVertices[0]); - *v1 = outTriangleVertices[0]; - *v2 = outTriangleVertices[1]; - *v3 = outTriangleVertices[2]; -} - -// Return the triangle normals for a specific subpart and triangle index -void ConcaveMeshShape::getTriangleVerticesNormals(uint subPart, uint triangleIndex, Vector3* n1, Vector3* n2, Vector3* n3) const -{ - assert(mTriangleMesh->getSubpart(subPart)); - Vector3 outTriangleVerticesNormals[3]; - getTriangleVerticesNormals(subPart, triangleIndex, &outTriangleVerticesNormals[0]); - *n1 = outTriangleVerticesNormals[0]; - *n2 = outTriangleVerticesNormals[1]; - *n3 = outTriangleVerticesNormals[2]; -} - // Use a callback method on all triangles of the concave shape inside a given AABB void ConcaveMeshShape::testAllTriangles(TriangleCallback& callback, const AABB& localAABB) const { diff --git a/src/collision/shapes/ConcaveMeshShape.h b/src/collision/shapes/ConcaveMeshShape.h index 36f6607c..b23fd057 100644 --- a/src/collision/shapes/ConcaveMeshShape.h +++ b/src/collision/shapes/ConcaveMeshShape.h @@ -155,15 +155,6 @@ class ConcaveMeshShape : public ConcaveShape { /// Insert all the triangles into the dynamic AABB tree void initBVHTree(); - /// Return the three vertices coordinates (in the array outTriangleVertices) of a triangle - void getTriangleVertices(uint subPart, uint triangleIndex, Vector3* outTriangleVertices) const; - - /// Return the three vertex normals (in the array outVerticesNormals) of a triangle - void getTriangleVerticesNormals(uint subPart, uint triangleIndex, Vector3* outVerticesNormals) const; - - /// Return the indices of the three vertices of a given triangle in the array - void getTriangleVerticesIndices(uint subPart, uint triangleIndex, uint* outVerticesIndices) const; - /// Compute the shape Id for a given triangle of the mesh uint computeTriangleShapeId(uint subPart, uint triangleIndex) const; @@ -173,7 +164,7 @@ class ConcaveMeshShape : public ConcaveShape { ConcaveMeshShape(TriangleMesh* triangleMesh, const Vector3& scaling = Vector3(1, 1, 1)); /// Destructor - virtual ~ConcaveMeshShape() = default; + virtual ~ConcaveMeshShape() override = default; /// Deleted copy-constructor ConcaveMeshShape(const ConcaveMeshShape& shape) = delete; @@ -187,14 +178,17 @@ class ConcaveMeshShape : public ConcaveShape { /// Return the number of sub parts contained in this mesh uint getNbSubparts() const; - /// Return the number of triangles in a sub part + /// Return the number of triangles in a sub part of the mesh uint getNbTriangles(uint subPart) const; - - /// Return the triangle positions for a specific subpart and triangle index - void getTriangleVertices(uint subPart, uint triangleIndex, Vector3* v1, Vector3* v2, Vector3* v3) const; - /// Return the triangle normals for a specific subpart and triangle index - void getTriangleVerticesNormals(uint subPart, uint triangleIndex, Vector3* n1, Vector3* n2, Vector3* n3) const; + /// Return the indices of the three vertices of a given triangle in the array + void getTriangleVerticesIndices(uint subPart, uint triangleIndex, uint* outVerticesIndices) const; + + /// Return the three vertices coordinates (in the array outTriangleVertices) of a triangle + void getTriangleVertices(uint subPart, uint triangleIndex, Vector3* outTriangleVertices) const; + + /// Return the three vertex normals (in the array outVerticesNormals) of a triangle + void getTriangleVerticesNormals(uint subPart, uint triangleIndex, Vector3* outVerticesNormals) const; /// Return the local bounds of the shape in x, y and z directions. virtual void getLocalBounds(Vector3& min, Vector3& max) const override; From 451722898f81336b4fd818869584c0329144d10a Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Wed, 12 Sep 2018 10:01:47 +0200 Subject: [PATCH 5/5] Edit changelog file --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c667fb2..f5c7bcd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Release Candidate +### Added + + - Make possible for the user to get vertices, normals and triangle indices of a ConcaveMeshShape + - Make possible for the user to get vertices and height values of the HeightFieldShape + ### Fixed - Bug [#45](https://github.com/DanielChappuis/reactphysics3d/issues/45) has been fixed.