MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / copyData

Method copyData

src/collision/TriangleMesh.cpp:91–213  ·  view source on GitHub ↗

Copy the triangles faces

Source from the content-addressed store, hash-verified

89
90// Copy the triangles faces
91bool TriangleMesh::copyData(const TriangleVertexArray& triangleVertexArray, std::vector<Message>& messages) {
92
93 bool isValid = true;
94
95 assert(mEpsilon > 0);
96
97 const decimal epsilonSquare = mEpsilon * mEpsilon;
98
99 Array<bool> areUserVerticesUsed(mAllocator);
100 for (uint32 i=0 ; i < triangleVertexArray.getNbVertices(); i++) {
101 areUserVerticesUsed.add(false);
102 mVertices.add(Vector3::zero());
103 mVerticesNormals.add(Vector3::zero());
104 }
105
106 // For each face
107 for (uint32 i=0 ; i < triangleVertexArray.getNbTriangles(); i++) {
108
109 bool isValidFace = true;
110 uint32 vertexIndices[3];
111 Vector3 vertexNormal[3] = {Vector3::zero(), Vector3::zero(), Vector3::zero()};
112
113 // Get the vertex indices from the user
114 triangleVertexArray.getTriangleVerticesIndices(i, vertexIndices[0], vertexIndices[1], vertexIndices[2]);
115
116 for (int v=0; v < 3; v++) {
117
118 if (vertexIndices[v] >= triangleVertexArray.getNbVertices()) {
119
120 // Add an error message for the user
121 messages.push_back(Message("The face with index " + std::to_string(i) +
122 " has a vertex with index " + std::to_string(vertexIndices[v]) +
123 " but the TriangleVertexArray only has " +
124 std::to_string(triangleVertexArray.getNbVertices()) + " vertices"));
125
126 isValid = false;
127 isValidFace = false;
128 }
129 }
130
131 if (isValidFace) {
132
133 // Check if the triangle area is not almost zero
134 const Vector3 v1 = triangleVertexArray.getVertex(vertexIndices[0]);
135 const Vector3 v2 = triangleVertexArray.getVertex(vertexIndices[1]);
136 const Vector3 v3 = triangleVertexArray.getVertex(vertexIndices[2]);
137 const Vector3 faceNormal = (v3 - v1).cross(v2 - v1);
138 const bool isFaceZeroArea = faceNormal.lengthSquare() < epsilonSquare;
139 if (isFaceZeroArea) {
140
141 // Add a warning message for the user
142 messages.push_back(Message("The face with index " + std::to_string(i) + " has almost zero area. This triangle will not be part of the final collision shape.",
143 Message::Type::Warning));
144 }
145
146 // Check that edges lengths are not almost zero
147 decimal edgesLengthsSquare[3];
148 edgesLengthsSquare[0] = (v2 - v1).lengthSquare();

Callers

nothing calls this directly

Calls 11

getHasNormalsMethod · 0.80
getVertexNormalMethod · 0.80
MessageClass · 0.50
getNbVerticesMethod · 0.45
addMethod · 0.45
getNbTrianglesMethod · 0.45
getVertexMethod · 0.45
crossMethod · 0.45
lengthSquareMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected