From 8b1f539b12fecc9c868b5d20b86a405f2e5bd383 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Mon, 30 Mar 2015 22:15:55 +0100 Subject: [PATCH] Add LoaderDFF normal calculation for models without --- rwengine/src/loaders/LoaderDFF.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rwengine/src/loaders/LoaderDFF.cpp b/rwengine/src/loaders/LoaderDFF.cpp index 5a02cacd..cdbcd102 100644 --- a/rwengine/src/loaders/LoaderDFF.cpp +++ b/rwengine/src/loaders/LoaderDFF.cpp @@ -191,7 +191,8 @@ void LoaderDFF::readGeometry(Model *model, const RWBStream &stream) } } - // Skip indicies data for now. + // Grab indicies data to generate normals (if applicable). + RW::BSGeometryTriangle* triangles = (RW::BSGeometryTriangle*)headerPtr; headerPtr += sizeof(RW::BSGeometryTriangle) * numTris; geom->geometryBounds = *(RW::BSGeometryBounds*)headerPtr; @@ -209,6 +210,19 @@ void LoaderDFF::readGeometry(Model *model, const RWBStream &stream) headerPtr += sizeof(glm::vec3); } } + else { + // Use triangle data to calculate normals for each vert. + for( int t = 0; t < numTris; ++t ) { + auto& triangle = triangles[t]; + auto& A = verts[triangle.first]; + auto& B = verts[triangle.second]; + auto& C = verts[triangle.third]; + auto normal = glm::normalize(glm::cross(C.position-A.position, B.position-A.position)); + A.normal = normal; + B.normal = normal; + C.normal = normal; + } + } // Add the geometry to the model now so that it can be accessed. model->geometries.push_back(geom);