mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
Add LoaderDFF normal calculation for models without
This commit is contained in:
parent
33e9920b48
commit
8b1f539b12
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user