From 5ae8e7a94465de84af03e7d5e0112a546e02f385 Mon Sep 17 00:00:00 2001 From: Thomas Tissot Date: Thu, 26 Sep 2019 17:10:51 +0200 Subject: [PATCH 1/2] Fix tipo in TriangleVertexArray --- src/collision/TriangleVertexArray.cpp | 12 ++++++------ src/collision/TriangleVertexArray.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/collision/TriangleVertexArray.cpp b/src/collision/TriangleVertexArray.cpp index 65591bf00..7390e3265 100644 --- a/src/collision/TriangleVertexArray.cpp +++ b/src/collision/TriangleVertexArray.cpp @@ -60,7 +60,7 @@ TriangleVertexArray::TriangleVertexArray(uint nbVertices, const void* verticesSt mIndicesStart = static_cast(indexesStart); mIndicesStride = indexesStride; mVertexDataType = vertexDataType; - mVertexNormaldDataType = NormalDataType::NORMAL_FLOAT_TYPE; + mVertexNormalsDataType = NormalDataType::NORMAL_FLOAT_TYPE; mIndexDataType = indexDataType; mAreVerticesNormalsProvidedByUser = false; @@ -100,7 +100,7 @@ TriangleVertexArray::TriangleVertexArray(uint nbVertices, const void* verticesSt mIndicesStart = static_cast(indexesStart); mIndicesStride = indexesStride; mVertexDataType = vertexDataType; - mVertexNormaldDataType = normalDataType; + mVertexNormalsDataType = normalDataType; mIndexDataType = indexDataType; mAreVerticesNormalsProvidedByUser = true; @@ -275,13 +275,13 @@ void TriangleVertexArray::getTriangleVerticesNormals(uint triangleIndex, Vector3 const void* vertexNormalPointer = static_cast(vertexNormalPointerChar); // Get the normals from the array - if (mVertexNormaldDataType == TriangleVertexArray::NormalDataType::NORMAL_FLOAT_TYPE) { + if (mVertexNormalsDataType == TriangleVertexArray::NormalDataType::NORMAL_FLOAT_TYPE) { const float* normal = static_cast(vertexNormalPointer); outTriangleVerticesNormals[k][0] = decimal(normal[0]); outTriangleVerticesNormals[k][1] = decimal(normal[1]); outTriangleVerticesNormals[k][2] = decimal(normal[2]); } - else if (mVertexNormaldDataType == TriangleVertexArray::NormalDataType::NORMAL_DOUBLE_TYPE) { + else if (mVertexNormalsDataType == TriangleVertexArray::NormalDataType::NORMAL_DOUBLE_TYPE) { const double* normal = static_cast(vertexNormalPointer); outTriangleVerticesNormals[k][0] = decimal(normal[0]); outTriangleVerticesNormals[k][1] = decimal(normal[1]); @@ -336,13 +336,13 @@ void TriangleVertexArray::getNormal(uint vertexIndex, Vector3* outNormal) { const void* vertexNormalPointer = static_cast(vertexNormalPointerChar); // Get the normals from the array - if (mVertexNormaldDataType == TriangleVertexArray::NormalDataType::NORMAL_FLOAT_TYPE) { + if (mVertexNormalsDataType == TriangleVertexArray::NormalDataType::NORMAL_FLOAT_TYPE) { const float* normal = static_cast(vertexNormalPointer); (*outNormal)[0] = decimal(normal[0]); (*outNormal)[1] = decimal(normal[1]); (*outNormal)[2] = decimal(normal[2]); } - else if (mVertexNormaldDataType == TriangleVertexArray::NormalDataType::NORMAL_DOUBLE_TYPE) { + else if (mVertexNormalsDataType == TriangleVertexArray::NormalDataType::NORMAL_DOUBLE_TYPE) { const double* normal = static_cast(vertexNormalPointer); (*outNormal)[0] = decimal(normal[0]); (*outNormal)[1] = decimal(normal[1]); diff --git a/src/collision/TriangleVertexArray.h b/src/collision/TriangleVertexArray.h index 9902af32f..13e61e872 100644 --- a/src/collision/TriangleVertexArray.h +++ b/src/collision/TriangleVertexArray.h @@ -91,7 +91,7 @@ class TriangleVertexArray { VertexDataType mVertexDataType; /// Data type of the vertex normals in the array - NormalDataType mVertexNormaldDataType; + NormalDataType mVertexNormalsDataType; /// Data type of the indices in the array IndexDataType mIndexDataType; @@ -191,7 +191,7 @@ inline TriangleVertexArray::VertexDataType TriangleVertexArray::getVertexDataTyp * @return The data type of the normals in the array */ inline TriangleVertexArray::NormalDataType TriangleVertexArray::getVertexNormalDataType() const { - return mVertexNormaldDataType; + return mVertexNormalsDataType; } // Return the index data type From a0b70fc4b8e6cbb0554da1b53daed59fa2b8cc50 Mon Sep 17 00:00:00 2001 From: Thomas Tissot Date: Thu, 26 Sep 2019 17:15:49 +0200 Subject: [PATCH 2/2] Make TriangleVertexArray normals generation optional --- src/collision/TriangleVertexArray.cpp | 15 +++++++++++++-- src/collision/TriangleVertexArray.h | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/collision/TriangleVertexArray.cpp b/src/collision/TriangleVertexArray.cpp index 7390e3265..6a7dca5eb 100644 --- a/src/collision/TriangleVertexArray.cpp +++ b/src/collision/TriangleVertexArray.cpp @@ -50,7 +50,8 @@ using namespace reactphysics3d; */ TriangleVertexArray::TriangleVertexArray(uint nbVertices, const void* verticesStart, uint verticesStride, uint nbTriangles, const void* indexesStart, uint indexesStride, - VertexDataType vertexDataType, IndexDataType indexDataType) { + VertexDataType vertexDataType, IndexDataType indexDataType, + bool generateNormals) { mNbVertices = nbVertices; mVerticesStart = static_cast(verticesStart); mVerticesStride = verticesStride; @@ -65,7 +66,9 @@ TriangleVertexArray::TriangleVertexArray(uint nbVertices, const void* verticesSt mAreVerticesNormalsProvidedByUser = false; // Compute the vertices normals because they are not provided by the user - computeVerticesNormals(); + if (generateNormals) { + computeVerticesNormals(); + } } // Constructor with vertices normals @@ -264,6 +267,10 @@ void TriangleVertexArray::getTriangleVerticesNormals(uint triangleIndex, Vector3 assert(triangleIndex >= 0 && triangleIndex < mNbTriangles); + if (!mVerticesNormalsStart) { + return; + } + // Get the three vertex index of the three vertices of the triangle uint verticesIndices[3]; getTriangleVerticesIndices(triangleIndex, verticesIndices); @@ -332,6 +339,10 @@ void TriangleVertexArray::getNormal(uint vertexIndex, Vector3* outNormal) { assert(vertexIndex < mNbVertices); + if (!mVerticesNormalsStart) { + return; + } + const uchar* vertexNormalPointerChar = mVerticesNormalsStart + vertexIndex * mVerticesNormalsStride; const void* vertexNormalPointer = static_cast(vertexNormalPointerChar); diff --git a/src/collision/TriangleVertexArray.h b/src/collision/TriangleVertexArray.h index 13e61e872..c0160c065 100644 --- a/src/collision/TriangleVertexArray.h +++ b/src/collision/TriangleVertexArray.h @@ -111,7 +111,8 @@ class TriangleVertexArray { /// Constructor without vertices normals TriangleVertexArray(uint nbVertices, const void* verticesStart, uint verticesStride, uint nbTriangles, const void* indexesStart, uint indexesStride, - VertexDataType vertexDataType, IndexDataType indexDataType); + VertexDataType vertexDataType, IndexDataType indexDataType, + bool generateNormals = true); /// Constructor with vertices normals TriangleVertexArray(uint nbVertices, const void* verticesStart, uint verticesStride,