mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
feat: VEC3 automatic normals generation
This commit is contained in:
parent
016d91704b
commit
75805642b5
1 changed files with 7 additions and 0 deletions
|
|
@ -102,6 +102,13 @@ static model::Mesh build_mesh(
|
|||
}
|
||||
if (normals) {
|
||||
vertex.normal = normals[indices[i * attrsCount + normalsIndex]];
|
||||
} else if (coords) {
|
||||
// Flat normal calculation
|
||||
int idx = (i / 3) * 3;
|
||||
auto a = coords[indices[idx * attrsCount + coordsIndex]];
|
||||
auto b = coords[indices[(idx + 1) * attrsCount + coordsIndex]];
|
||||
auto c = coords[indices[(idx + 2) * attrsCount + coordsIndex]];
|
||||
vertex.normal = glm::normalize(glm::cross(b - a, c - a));
|
||||
}
|
||||
vertices.push_back(std::move(vertex));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue