demoTransformNodes.py

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