Flip Normals Three.JS after flipped geometry

I followed this stackoverflow example: Geometry 3DJS

I have successfully flipped my geometry. However, now my geometry is black. Can I flip my normals at the same time as the geometry to fix this? Or should I use a different approach to mirror the geometry from the start?

EDIT:

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

#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


source to share


3 answers


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

+2


source


This is an old question, but for those who are still lost: a normal face is calculated by looking at the opposite clockwise vertex order.

So, if you need to flip the normals, you need to reorder the vertices assigned to the 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;
}

      

+1


source


You may try:

mesh.geometry.reverse(computeFaceNormals());
mesh.geometry.reverse(computeVertexNormals());

      

-2


source







All Articles