demoGetRenderedNormals.py

demoGetRenderedNormals.py
1 '''
2 An example of how to populate RNormals and get them with GetRenderedVertexNormals()
3 '''
4 import MaxPlus
5 
6 obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Box)
7 n = MaxPlus.Factory.CreateNode(obj, "myBox")
8 
9 print "node name: %s" % n.Name
10 n.Convert(MaxPlus.ClassIds.TriMeshGeometry)
11 object_state = n.EvalWorldState()
12 obj_original = object_state.Getobj()
13 tri_obj = MaxPlus.TriObject._CastFrom(obj_original)
14 tri_mesh = tri_obj.GetMesh()
15 print "normals built? ", tri_mesh.GetNormalsBuilt() # will return 0 if normals are not yet built
16 tri_mesh.CheckNormals(True) # less expensive than BuildNormals(), because it will only build if normals
17 # do not yet exist
18 print "normals built? ", tri_mesh.GetNormalsBuilt() # will now return non-0 because CheckNormals() ensures
19 # we've built them
20 normal_count = tri_mesh.GetNormalCount()
21 vertex_count = tri_mesh.GetNumVertices()
22 print " normals: ", normal_count
23 print " verts: ", vertex_count
24 
25 for i in range(0, vertex_count):
26  print "vertex: " , tri_mesh.GetVertex(i)
27  print "RNormal: ", tri_mesh.GetRenderedVertexNormal(i)