demoMakeInstances.py

demoMakeInstances.py
1 '''
2  Demonstrates creating instances of a node hierarchy.
3 '''
4 import MaxPlus
5 
6 def createNodes(o, cnt):
7  return [MaxPlus.Factory.CreateNode(o) for i in xrange(cnt)]
8 
9 def linkNodes(nodes):
10  for i in xrange(len(nodes) - 1):
11  nodes[i + 1].Parent = nodes[i]
12 
13 def alignNodesInLine(nodes, pt):
14  for i in xrange(len(nodes)):
15  nodes[i].Move(MaxPlus.Point3(pt.X * i, pt.Y * i, pt.Z * i))
16 
17 def main():
18  obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Sphere)
19  obj.ParameterBlock.Radius.Value = 3.0
20  nodes = createNodes(obj, 10)
21  alignNodesInLine(nodes, MaxPlus.Point3(5, 0, 0))
22  linkNodes(nodes)
23  copy = nodes[0].CreateTreeInstance()
24  copy.Move(MaxPlus.Point3(0, 25, 0))
25 
26 if __name__ == "__main__":
27  main()