demoApplyMaterial.py
Main Page
Modules
Classes
Examples
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
9
def
createSphere():
10
obj =
MaxPlus.Factory.CreateGeomObject
(MaxPlus.ClassIds.Sphere)
11
obj.ParameterBlock.Radius.Value = 5.0
12
return
MaxPlus.Factory.CreateNode
(obj)
13
14
15
def
solidMaterial(color):
16
m =
MaxPlus.Factory.CreateDefaultStdMat
()
17
m.Ambient = color
18
m.Diffuse = color
19
m.Specular =
MaxPlus.Color
(1, 1, 1)
20
m.Shininess = 0.5
21
m.ShinyStrength = 0.7
22
return
m
23
24
25
def
descendants(node):
26
for
c
in
node.Children:
27
yield
c
28
for
d
in
descendants(c):
29
yield
d
30
31
32
def
allNodes():
33
return
descendants(
MaxPlus.Core.GetRootNode
())
34
35
36
def
applyMaterialToNodes(m, nodes=allNodes()):
37
for
n
in
nodes:
38
n.Material = m
39
40
if
__name__ ==
'__main__'
:
41
createSphere()
42
m = solidMaterial(
MaxPlus.Color
(0, 0, 1))
43
applyMaterialToNodes(m)