How to get vertex normal using python

How to get vertex normal using python

Anonymous
Not applicable
4,351 Views
20 Replies
Message 1 of 21

How to get vertex normal using python

Anonymous
Not applicable

I drag a box into an empty scene, then using the following python script to get vertex normal. However, the result is not what i expected.

 

From the output, we can see there are just two kind of normals, which is obviously wrong.

 

I know the face normal can be retrieved with Mesh.GetFaceNormal, but what I really want to get is the vertex normal taking smooth group into account(That means every vertex has three normals). I searched the python API docs, but can't find the right way to do that.

 

Can somebody help me?

 

  python script:

 

n=list(MaxPlus.Core.GetRootNode().Children)[0]
obj=n.EvalWorldState(0).Getobj()
tri_obj = MaxPlus.TriObject._CastFrom(obj.ConvertToType(MaxPlus.ClassIds.TriMeshGeometry, 0))
mesh=tri_obj.GetMesh()
for i in xrange(mesh.GetNumVertices()): print mesh.GetRenderedVertexNormal(i)

  output:

Point3(0, 0, -1.5708)
Point3(0, 0, -1.5708)
Point3(0, 0, -1.5708)
Point3(0, 0, -1.5708)
Point3(0, 0, 1.5708)
Point3(0, 0, 1.5708)
Point3(0, 0, 1.5708)
Point3(0, 0, 1.5708)

max_normalpng.png

0 Likes
4,352 Views
20 Replies
Replies (20)
Message 21 of 21

Anonymous
Not applicable

sorry for the confusion

0 Likes