summaryrefslogtreecommitdiffhomepage
path: root/src/models.c
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2021-02-05 19:49:05 +0100
committerraysan5 <[email protected]>2021-02-05 19:49:05 +0100
commit0f309b9b16c7986c5bda65ff002b7a5b432642d4 (patch)
tree38cc02d69e93811475266273b60e5adc60473532 /src/models.c
parentedb54c6cb15800ed9876df962c5fa7153108cb4a (diff)
downloadraylib-0f309b9b16c7986c5bda65ff002b7a5b432642d4.tar.gz
raylib-0f309b9b16c7986c5bda65ff002b7a5b432642d4.zip
REMOVED: MeshNormalsSmooth() #1421
Current implementation is probably wrong and it should be reimplemented from scratch, in the meantime, I prefer to remove the function.
Diffstat (limited to 'src/models.c')
-rw-r--r--src/models.c67
1 files changed, 0 insertions, 67 deletions
diff --git a/src/models.c b/src/models.c
index 2683cc89..d52dc83f 100644
--- a/src/models.c
+++ b/src/models.c
@@ -2352,73 +2352,6 @@ void MeshBinormals(Mesh *mesh)
}
}
-// Smooth (average) vertex normals
-void MeshNormalsSmooth(Mesh *mesh)
-{
- #define EPSILON 0.000001 // A small number
-
- int uvCounter = 0;
- Vector3 *uniqueVertices = (Vector3 *)RL_CALLOC(mesh->vertexCount, sizeof(Vector3));
- Vector3 *summedNormals = (Vector3 *)RL_CALLOC(mesh->vertexCount, sizeof(Vector3));
-
- int *uniqueIndices = (int *)RL_CALLOC(mesh->vertexCount, sizeof(int));
-
- // Sum normals grouped by vertex
- for (int i = 0; i < mesh->vertexCount; i++)
- {
- Vector3 v = { mesh->vertices[(i + 0)*3 + 0], mesh->vertices[(i + 0)*3 + 1], mesh->vertices[(i + 0)*3 + 2] };
- Vector3 n = { mesh->normals[(i + 0)*3 + 0], mesh->normals[(i + 0)*3 + 1], mesh->normals[(i + 0)*3 + 2] };
-
- bool matched = false;
-
- // TODO: Matching vertices is brute force O(N^2). Do it more efficiently?
- for (int j = 0; j < uvCounter; j++)
- {
- Vector3 uv = uniqueVertices[j];
-
- bool match = true;
- match = match && fabs(uv.x - v.x) < EPSILON;
- match = match && fabs(uv.y - v.y) < EPSILON;
- match = match && fabs(uv.z - v.z) < EPSILON;
-
- if (match)
- {
- matched = true;
- summedNormals[j] = Vector3Add(summedNormals[j], n);
- uniqueIndices[i] = j;
- break;
- }
- }
-
- if (!matched)
- {
- int j = uvCounter++;
- uniqueVertices[j] = v;
- summedNormals[j] = n;
- uniqueIndices[i] = j;
- }
- }
-
- // Average and update normals
- for (int i = 0; i < mesh->vertexCount; i++)
- {
- int j = uniqueIndices[i];
- Vector3 n = Vector3Normalize(summedNormals[j]);
- mesh->normals[(i + 0)*3 + 0] = n.x;
- mesh->normals[(i + 0)*3 + 1] = n.y;
- mesh->normals[(i + 0)*3 + 2] = n.z;
- }
-
- // 2=normals, see rlUpdateMeshAt()
- rlUpdateMesh(*mesh, 2, mesh->vertexCount);
-
- RL_FREE(uniqueVertices);
- RL_FREE(summedNormals);
- RL_FREE(uniqueIndices);
-
- TRACELOG(LOG_INFO, "MESH: Normals smoothed (%d vertices, %d unique)", mesh->vertexCount, uvCounter);
-}
-
// Draw a model (with texture if set)
void DrawModel(Model model, Vector3 position, float scale, Color tint)
{