Notifications
Clear all

[Closed] Get vertex normal from Editable Poly

 xcx

How I can get vertex normal from Editable Poly object? Mesh object I can use ex. getNormal $ 1, but I can’t find anything like that for Editable Poly objects.

27 Replies

Hi xcx, you will need to get the facenormals of the surrounding faces and average them by adding them all together, then dividing by the number of faces and then normalize the result. As far as I know there is no direct way to get it, but you can easialy make this into a function. Beware though that some vertices might not have any faces. In that case I believe the normal will be aligned to the objects transform.

CML

 xcx

Tryed that one, but normals seems to be wrong. Anyway your idea sounds working so problem is propably in my code. So here goes.


      vertnormal = 0.0 
      
      -- Get vertex selection from first object at selection array
      verts = getVertSelection selection[1]
      -- Get all faces where first vertex in selection array is accosied with.
      faces = polyop.getFacesUsingVert selection[1] (verts as array)[1]
      -- Convert bit array to array
      faces = faces as array
       
      -- Loop all faces what are accosied with vertex
      for i in 1 to (faces.count) do
      (
      	-- Add face normals to vertex normal
      	vertnormal = vertnormal + (polyop.getFaceNormal selection[1] faces[i])
 ) 		 
      
      -- Divied vertex normal with count of faces  
      vertnormal = vertnormal / (faces.count)	
      -- Normalize
     vertnormal = normalize vertnormal		     	   
        
        
  Any bugs or did I make something wrong?

Antti,

Try this:

(
	local sel = selection[1]
	local vertFaces = polyOp.getFacesUsingVert sel (polyOp.getVertSelection sel as array)[1]
	local tNormal = [0,0,0]; for i in vertFaces do tNormal += polyOp.getFaceNormal sel i
	tNormal / vertFaces.numberSet
)

Light

 xcx

Thanks! That worked like a dream! bow

If it works like a dream and you know it is a dream, then it must be a lucid dream;)

Light

A few things I’d like to add to lights example:
When you use polyOp.getFaceNormal sel i you will get the normal in the objects local coordinate system wich is at least not what I usually want. To get it in world coordinates instead write polyOp.getFaceNormal sel i node:sel .
Also the normal you get from the example is pointing in the right direction but it’s not normalized(length=1) so I suggest you normalize it afterwards too to make it a “true” normal. This is important if you as an example want to move the vert 10 units along the normal you can say newpos = vertpos + (thenormal *10) , but only if the the normal is normalized.

cheers,
CML

Rivendale,

I think there is no point in telling that the returned normal is in local coordinates since it solves his problem obviously.

FYI polyOp.getFaceNormal ALWAYS returns a normalized vector.

Light

Light – I’m sure he has no problem with getting more info, maybe he wants to compare the normal to the view or something. That would seem to work…until he rotates his object. Things like this is good to know imho.

FYI polyOp.getFaceNormal ALWAYS returns a normalized vector.

yes it does, but after you add them up and divide you will NOT get a normalized normal. If he tried to move with a unnormalized normal it would seem to work but the results would not be accurate.

I always used the returned vector without normalizing and never encountered a problem regarding accuracy.

It is OK if you want to give more info, but please don’t post after every message I post regarding my message as if you have to. I feel like being chased

Light

Page 1 / 3