demoTransformNodes.py

demoTransformNodes.py
1 '''
2  Creates a number of boxes with random scale, position, and rotation.
3 '''
4 import random, math, MaxPlus
5 
6 def rnd():
7  return random.random()
8 
9 def rndAngle():
10  return -math.pi + (rnd() * 2 * math.pi)
11 
12 def rndQuat():
13  return MaxPlus.Quat(rnd(), rnd(), rnd(), rndAngle())
14 
15 def rndDist():
16  return rnd() * 100.0 - 50.0
17 
18 def rndPosition():
19  return MaxPlus.Point3(rndDist(), rndDist(), 0)
20 
21 def rndScaleAmount():
22  return rnd() * 2.0 + 0.1
23 
24 def rndScale():
25  return MaxPlus.Point3(rndScaleAmount(), rndScaleAmount(), rndScaleAmount())
26 
27 def randomTransformNodes(nodes):
28  for n in nodes:
29  n.Scaling = rndScale()
30  n.Rotation = rndQuat()
31  n.Position = rndPosition()
32 
33 def createNodes(obj, cnt):
34  return [MaxPlus.Factory.CreateNode(obj) for i in range(cnt)]
35 
36 def main():
37  box = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Box)
38  box.ParameterBlock.Length.Value = 10.0
39  box.ParameterBlock.Height.Value = 10.0
40  box.ParameterBlock.Width.Value = 10.0
41  nodes = createNodes(box, 25)
42  randomTransformNodes(nodes)
43 
44 if __name__ == "__main__":
45  main()