demoClassTypes.py

demoClassTypes.py
1 '''
2  Demonstrates creating many different types of scene objects that are visible in the viewport.
3  The scene objects are grouped by type.
4  The types created are Cameras, Lights, Geometric Objects, Shapes, Helpers, Modifiers and Materials.
5 '''
6 import MaxPlus
7 
8 
9 def GeneratePlugins(sid, cls):
10  Conform_cid = MaxPlus.Class_ID(0x1ab13757, 0x12365b98) # Known bug
11  for cd in MaxPlus.PluginManager.GetClassList().Classes:
12  if cd.SuperClassId == sid and cd.ClassId != Conform_cid:
13  o = MaxPlus.Factory.CreateAnimatable(sid, cd.ClassId, False)
14  if o:
15  r = cls._CastFrom(o)
16  if r:
17  yield r
18 
19 # =====================================================================
20 
21 
22 def CreateBox():
23  box = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Box)
24  box.ParameterBlock.Height.Value = 5.0
25  box.ParameterBlock.Width.Value = 5.0
26  box.ParameterBlock.Length.Value = 5.0
27  return box
28 
29 
30 def CreateText(pos, message):
31  tex = MaxPlus.Factory.CreateShapeObject(MaxPlus.ClassIds.text)
32  tex.ParameterBlock.size.Value = 20.0
33  tex.ParameterBlock.text.Value = message
34  node = MaxPlus.Factory.CreateNode(tex)
35  node.Position = MaxPlus.Point3(pos.X, pos.Y - 5, pos.Z)
36  node.WireColor = MaxPlus.Color(1.0, 0.5, 1.0)
37 
38 
39 def CreateTeapot():
40  box = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Teapot)
41  box.ParameterBlock.Radius.Value = 5.0
42  return box
43 
44 
45 def CreateBoxNode(x, y):
46  b = CreateBox()
48  node.Position = MaxPlus.Point3(x, y, 0)
49  return node
50 # =====================================================================
51 
52 
53 def CreateCameras(y_position):
54  CreateText(MaxPlus.Point3(-45, y_position, 0), "Cameras")
55  x_position = 0.0
56  for obj in GeneratePlugins(MaxPlus.SuperClassIds.Camera, MaxPlus.CameraObject):
57  node = MaxPlus.Factory.CreateNode(obj)
58  node.Position = MaxPlus.Point3(x_position, y_position, 0)
59 
60  x_position += 10.0
61  if ((x_position % 260.0) < 0.001):
62  x_position = 0.0
63  y_position += 20
64  return y_position
65 
66 
67 def CreateLights(y_position):
68  CreateText(MaxPlus.Point3(-45, y_position, 0), "Lights")
69  x_position = 0.0
70  for obj in GeneratePlugins(MaxPlus.SuperClassIds.Light, MaxPlus.LightObject):
71  node = MaxPlus.Factory.CreateNode(obj)
72  node.Position = MaxPlus.Point3(x_position, y_position, 0)
73 
74  x_position += 10.0
75  if ((x_position % 260.0) < 0.001):
76  x_position = 0.0
77  y_position += 20
78  return y_position
79 
80 
81 def CreateObjects(y_position):
82  CreateText(MaxPlus.Point3(-88, y_position, 0), "Geometric objects")
83  x_position = 0.0
84  for obj in GeneratePlugins(MaxPlus.SuperClassIds.GeomObject, MaxPlus.GeomObject):
85  node = MaxPlus.Factory.CreateNode(obj)
86  node.Position = MaxPlus.Point3(x_position, y_position, 0)
87 
88  x_position += 10.0
89  if ((x_position % 260.0) < 0.001):
90  x_position = 0.0
91  y_position += 20
92  return y_position
93 
94 
95 def CreateShapes(y_position):
96  CreateText(MaxPlus.Point3(-45, y_position, 0), "Shapes")
97  x_position = 0.0
98  for obj in GeneratePlugins(MaxPlus.SuperClassIds.Shape, MaxPlus.ShapeObject):
99  node = MaxPlus.Factory.CreateNode(obj)
100  node.Position = MaxPlus.Point3(x_position, y_position, 0)
101 
102  x_position += 10.0
103  if ((x_position % 260.0) < 0.001):
104  x_position = 0.0
105  y_position += 20
106  return y_position
107 
108 
109 def CreateHelpers(y_position):
110  CreateText(MaxPlus.Point3(-45, y_position, 0), "Helpers")
111  x_position = 0.0
112  for obj in GeneratePlugins(MaxPlus.SuperClassIds.Helper, MaxPlus.HelperObject):
113  node = MaxPlus.Factory.CreateNode(obj)
114  node.Position = MaxPlus.Point3(x_position, y_position, 0)
115  x_position += 10.0
116  if ((x_position % 260.0) < 0.001):
117  x_position = 0.0
118  y_position += 20
119  return y_position
120 
121 
122 def CreateModifiers(y_position):
123  CreateText(MaxPlus.Point3(-45, y_position, 0), "Modifiers")
124  x_position = 0.0
125  for m in GeneratePlugins(MaxPlus.SuperClassIds.Osm, MaxPlus.Modifier):
126  b = CreateBox()
128  node.Position = MaxPlus.Point3(x_position, y_position, 0)
129  print '\tAdding modifier: %s' % m
130  node.AddModifier(m)
131  x_position += 10.0
132  if ((x_position % 260.0) < 0.001):
133  x_position = 0.0
134  y_position += 20
135  return y_position
136 
137 
138 def CreateMaterials(y_position):
139  CreateText(MaxPlus.Point3(-45, y_position, 0), "Materials")
140  x_position = 0.0
141  b = CreateTeapot()
142  for m in GeneratePlugins(MaxPlus.SuperClassIds.Material, MaxPlus.Mtl):
143  print m
145  node.Position = MaxPlus.Point3(x_position, y_position, 0)
146  node.Material = m
147  x_position += 10.0
148 
149 
150 def CreateStuff():
152  y = 0.0
153  CreateMaterials(y)
154  y = 20.0
155  y = CreateModifiers(y)
156  y += 40.0
157  y = CreateHelpers(y)
158  y += 40.0
159  y = CreateShapes(y)
160  y += 40.0
161  y = CreateObjects(y)
162  y += 40.0
163  y = CreateLights(y)
164  y += 40.0
165  y = CreateCameras(y)
166 
167 CreateStuff()