Flip Normals Three.JS after flipping geometry

2019-07-01 13:09发布

I followed this stackoverflow example: ThreeJS geometry flipping

I successfully mirrored my geometry. However now my geometry is black. Can I flip my normals at the same time as the geometry to correct this? Or should I have used a different approach to mirror the geometry from the beginning?

EDIT:

Tried adding the updates to this code and still have inverted geometry.

#transformation
mS.elements[5] = -1;
mesh.applyMatrix(mS);

#updates
mesh.geometry.verticesNeedUpdate = true;
mesh.geometry.normalsNeedUpdate = true;
mesh.geometry.computeBoundingSphere();
mesh.geometry.computeFaceNormals();
mesh.geometry.computeVertexNormals();

geometry

3条回答
【Aperson】
2楼-- · 2019-07-01 13:17

You could try:

mesh.geometry.reverse(computeFaceNormals());
mesh.geometry.reverse(computeVertexNormals());
查看更多
做自己的国王
3楼-- · 2019-07-01 13:18
mesh.geometry.verticesNeedUpdate = true;
mesh.geometry.normalsNeedUpdate = true;
mesh.geometry.computeBoundingSphere();
mesh.geometry.computeFaceNormals();
mesh.geometry.computeVertexNormals();

https://github.com/mrdoob/three.js/wiki/Updates

查看更多
甜甜的少女心
4楼-- · 2019-07-01 13:43

This is an old question, but for those still lost: the face normal is calculated by looking at the counter clockwise order of the vertices.

So if you need to flip the normals you have to reorder the vertices that are assigned to a face. For example:

var tmp;
for(var f = 0; f < geometry.faces.length; f++) {
    tmp = geometry.faces[f].clone();
    geometry.faces[f].a = tmp.c;
    geometry.faces[f].c = tmp.a;
}
查看更多
登录 后发表回答