3

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

Community
  • 1
  • 1
Laura
  • 469
  • 1
  • 6
  • 12

3 Answers3

4

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;
}
Thomas Huijzer
  • 354
  • 1
  • 7
3
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

IceCreamYou
  • 1,852
  • 14
  • 25
  • After adding that code, I still could not get the geometry to return to its normal state (the model on the left). – Laura Sep 15 '14 at 14:00
  • Try applying the matrix on the geometry before adding it to a mesh – IceCreamYou Sep 18 '14 at 02:54
  • This won't solve the problem : the direction of the normal is computed using the cross product of vectors. one has to invert the order of the three integers indexes in each face of the geometry. Maybe it is already implemented in recent Threejs. – Arnaud Aug 07 '17 at 18:11
-3

You could try:

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