Merge pull request #37163 from madmiraal/fix-csg-normal

Fix CSG vertex normal calculation.
This commit is contained in:
Rémi Verschelde 2020-04-28 14:28:31 +02:00 committed by GitHub
commit 39f7a40925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 11 deletions

View File

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