3

I'm having difficulties with vertex normals in THREE.js. (For reference I'm using revision 58.) For various reasons I'd like to first calculate the face vertex normals when I setup my geometry, then be free to transform it, merge and whatnot.

While I realize the normals depend on the vertices which are transformed when you apply a matrix, I thought geometry.applyMatrix was able to transform them as well. However, while the following works fine:

geometry.applyMatrix(new THREE.Matrix4().makeScale(1, -1, 1));
geometry.computeFaceNormals();
geometry.computeVertexNormals();

...the following order of operations yields reversed vertex normals:

geometry.computeFaceNormals();
geometry.computeVertexNormals();
geometry.applyMatrix(new THREE.Matrix4().makeScale(1, -1, 1));

So I'm simply wondering, is this working as intended? Do I need to first do all the transformations on the geometry before I calculate the vertex normals?

user1421750
  • 1,200
  • 2
  • 9
  • 16

1 Answers1

4

three.js does not support reflections in the object matrix. By setting a negative scale factor, you are reflecting the geometry of the object.

You are free to apply such a matrix to your geometry directly, however, which of course, is what you are doing.

However, this will result in a number of undesirable consequences, one of which is the geometry faces will no longer have counterclockwise winding order, but clockwise. It will also result in reversed face normals as calculated by geometry.computeFaceNormals().

I would advise against doing this unless you are familiar with the inner-workings of the library.

three.js r.58

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • Thank you so much for the explanation, this was driving me mad! Unfortunately I have to work with the models I'm given, but I haven't noticed any other "undesirable consequences". Does any more come to mind quickly? – user1421750 May 09 '13 at 23:06
  • 2
    Vertex normal calculations are affected, as are tangent calculations, material sidedness, lighting calculations, to name a few. Face culling and ray-casting will be effected by the winding order. – WestLangley May 10 '13 at 01:48