Notifications
Clear all

[Closed] Get local normal from face + barycentric coordinates?

I have a face number and the barycentric coordinates within that face and would like to get the local surface normal at that point (including effects from smoothing groups and explicit normals).

I can easily get all the vertices of the face, and all the normals to those vertices and then compute some average on them, but that will not deal with explicit normals or smoothing groups.

I have considered baking a normal map, but that a.) requires decent texture coordinates, b.) will compute many more normals than I need, c.) requires messing with render setup etc. which I would like to avoid.

Any suggestions?

Thanks!

6 Replies

bump

Any ideas anyone?

2 Replies
(@denist)
Joined: 10 months ago

Posts: 0

mxs or sdk?

(@martinb)
Joined: 10 months ago

Posts: 0

Some scripted solution would be needed, thank you.

bumping this once more, would really be interested in a MXS solution to query the normal at a given location on a mesh (ideally without baking normal maps).

the only way to get “true” normals (including specified normals) via mxs is to use Edit_Normals modifier… it’s not slow if you do it right, and of course much faster than bake to texture


fn getAllFaceNormals node = undo off, redraw off
(
   modi = Edit_Normals()
   addmodifier node modi
   
   _GetNumFaces = modi.GetNumFaces
   _GetFaceDegree = modi.GetFaceDegree
   _GetNormalID = modi.GetNormalID
   _GetNormal = modi.GetNormal
   
   data = for f=1 to _GetNumFaces() collect
   (
      norms = for i=1 to _GetFaceDegree f collect
      (
         id = _GetNormalID f i 
         _GetNormal id   
      )
      norms
   )   
   
   deletemodifier node modi
   data
)

delete objects
global data
sp = geosphere segments:16 isselected:on

(
   gc()
   max modify mode
   
   t = timestamp()
   h = heapfree

   getAllFaceNormals sp

   format "size:% time:% heap:%
" (getpolygoncount sp) (timestamp() - t) (h - heapfree)
   
   data
)


1 Reply
(@martinb)
Joined: 10 months ago

Posts: 0

Thank you! That will give me face/vertex normals. But what I really need are normals for a given barycentric coordinate. I.e. the surface normal within a triangle after all smoothing and explicit normals.
So a MAXScript function would accept a mesh, a triangle index, and a s/t barycentric coordinate within that triangle as arguments to precisely specify a point on the mesh (akin to the Attachment controller) – and for that point, the function would return the correct surface normal, taking smoothing groups and/or explicit normals into account.