Fix CSG vertex normal calculation.

(cherry picked from commit 9bd305bfe2)
This commit is contained in:
Marcel Admiraal 2020-03-19 11:13:25 +00:00 committed by Rémi Verschelde
parent 1a4530e84c
commit 966139ca4c
1 changed files with 9 additions and 11 deletions

View File

@ -296,20 +296,18 @@ void CSGShape::_update_shape() {
int mat = n->faces[i].material;
ERR_CONTINUE(mat < -1 || mat >= face_count.size());
int idx = mat == -1 ? face_count.size() - 1 : mat;
if (n->faces[i].smooth) {
Plane p(n->faces[i].vertices[0], n->faces[i].vertices[1], n->faces[i].vertices[2]);
Plane p(n->faces[i].vertices[0], n->faces[i].vertices[1], n->faces[i].vertices[2]);
for (int j = 0; j < 3; j++) {
Vector3 v = n->faces[i].vertices[j];
Vector3 add;
if (vec_map.lookup(v, add)) {
add += p.normal;
} else {
add = p.normal;
}
vec_map.set(v, add);
for (int j = 0; j < 3; j++) {
Vector3 v = n->faces[i].vertices[j];
Vector3 add;
if (vec_map.lookup(v, add)) {
add += p.normal;
} else {
add = p.normal;
}
vec_map.set(v, add);
}
face_count.write[idx]++;