5

I have several objects in Three.js's JSON Model Format. It specifies vertex positions, and faces -- sometimes triangles, sometimes quads, sometimes with material indices and sometimes not.

However none of these files have vertex normals specified.

I want an algorithm that can calculate such normals over a set of mesh faces. I'd like to specify an angular limit beyond which a crease is shown (normals are not shared by adjacent faces at a vertex.)

Before coding this myself I wondered, does this exist either in Three.js already or somewhere else that's usable?

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
  • Did you eventually code the crease angle algorithm? I it something you would share? – gaitat Apr 17 '13 at 09:40
  • @gaitat, yes I did and I do intend to submit it to Three.js as a pull-request. However I want to put together a nice demo to show how it might be used and why it's useful. If you'd like to test it out, I can share it with you. There's no email address on your profile. – Drew Noakes Apr 17 '13 at 10:48
  • gaitat at yahoo dot com. Thank you very much. – gaitat Apr 17 '13 at 19:49
  • Citizens demand a demo! – meetar Jul 08 '13 at 16:45

1 Answers1

5

The only thing available is

geometry.computeFaceNormals();
geometry.computeVertexNormals();

See the source for the algorithm.

three.js r.55

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • Thanks for this. It looks like a good start. The resulting objects lose some edges in the mesh though. I'll see if I can modify the implementation of `computeVertexNormals()` to do what I'm after. – Drew Noakes Feb 07 '13 at 23:33
  • Also passing `true` as an argument to `computeVertexNormals` (signifying to consider the area of faces as weights on the normals) made it look a bit less weird, but still the sharp edges are missing which is a problem for this mesh at least. – Drew Noakes Feb 07 '13 at 23:37
  • Yes, this algorithm does lose sharp edges. – WestLangley Feb 08 '13 at 00:20
  • 2
    I was really looking for an approach that allowed control over crease angles to maintain sharp edges. I've coded such a solution myself and, after a little tidying, will provide it in an answer here. I'll also see whether it might fit neatly in the Three.js library itself and submit a pull request. – Drew Noakes Feb 16 '13 at 21:02
  • hey, same problem here and came to the same conclusion :) I'm stuck on the VertexNormals computation ; the weighted computation doesn't work for me neither exactly for the reasons Drew exposed : it's a low poly mesh with smoothing groups so sharp edges are crucial. Drew, is there a way you'd share your solution? or just point me in the right direction. thanks – nicoptere Mar 26 '14 at 18:31
  • after some rest I realized the problem came from the import / export in 3DSMax ; both were flipping the ZY coords... this being said I'm very curious how you managed to perform a "topology aware" smoothing :) – nicoptere Mar 27 '14 at 08:39