Flip Normals Three.JS after flipping geometry

匆匆过客 提交于 2019-12-13 14:27:56

问题


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();


回答1:


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:


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;
}



回答3:


You could try:

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


来源:https://stackoverflow.com/questions/25795538/flip-normals-three-js-after-flipping-geometry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!