demoApplyMaterial.py

demoApplyMaterial.py
1 '''
2  Applies a standard material to all nodes in the scene.
3  Also shows the use of generator functions in Python.
4 '''
5 
6 import MaxPlus
7 
8 def createSphere():
9  obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Sphere)
10  obj.ParameterBlock.Radius.Value = 5.0
11  return MaxPlus.Factory.CreateNode(obj)
12 
13 def solidMaterial(color):
15  m.Ambient = color
16  m.Diffuse = color
17  m.Specular = MaxPlus.Color(1, 1, 1)
18  m.Shininess = 0.5
19  m.ShinyStrength = 0.7
20  return m
21 
22 def descendants(node):
23  for c in node.Children:
24  yield c
25  for d in descendants(c):
26  yield d
27 
28 def allNodes():
29  return descendants(MaxPlus.Core.GetRootNode())
30 
31 def applyMaterialToNodes(m, nodes = allNodes()):
32  for n in nodes:
33  n.Material = m
34 
35 if __name__ == '__main__':
36  createSphere()
37  m = solidMaterial(MaxPlus.Color(0, 0, 1))
38  applyMaterialToNodes(m)
39