forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
writelooks.py
executable file
·150 lines (132 loc) · 4.75 KB
/
writelooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python
'''
Generate the "Looks.mtlx" example file programmatically.
'''
import MaterialX as mx
def main():
doc = mx.createDocument()
# Add document CMS/colorspace
doc.setColorManagementSystem("ocio")
doc.setColorSpace("lin_rec709")
# Prepend an XInclude reference for "SimpleSrf.mtlx".
mx.prependXInclude(doc, "SimpleSrf.mtlx")
#
# Materials
#
shader = doc.addNode("simple_srf", "sr_mp1")
shader.setInputValue("diffColor", mx.Color3(0.134, 0.130, 0.125))
shader.setInputValue("specColor", mx.Color3(0.114))
shader.setInputValue("specRoughness", 0.38)
mplastic1 = doc.addMaterialNode("Mplastic1", shader)
shader = doc.addNode("simple_srf", "sr_mp2")
shader.setInputValue("diffColor", mx.Color3(0.17, 0.26, 0.23))
shader.setInputValue("specRoughness", 0.24)
mplastic2 = doc.addMaterialNode("Mplastic2", shader)
shader = doc.addNode("simple_srf", "sr_mm1")
shader.setInputValue("diffColor", mx.Color3(0.001))
shader.setInputValue("specColor", mx.Color3(0.671, 0.676, 0.667))
shader.setInputValue("specRoughness", 0.005)
mmetal1 = doc.addMaterialNode("Mmetal1", shader)
shader = doc.addNode("simple_srf", "sr_mm2")
shader.setInputValue("diffColor", mx.Color3(0.049, 0.043, 0.033))
shader.setInputValue("specColor", mx.Color3(0.115, 0.091, 0.064))
shader.setInputValue("specRoughness", 0.35)
mmetal2 = doc.addMaterialNode("Mmetal2", shader)
#
# VariantSet
#
vset = doc.addVariantSet("varset")
vardry = vset.addVariant("dry")
vardry.setInputValue("wetgain", 0.0)
varwet = vset.addVariant("wet")
varwet.setInputValue("wetgain", 1.0)
vardamp = vset.addVariant("damp")
vardamp.setInputValue("wetgain", 0.2)
#
# Collections
#
cplastic = doc.addCollection("c_plastic")
cplastic.setIncludeGeom("/a/g1,/a/g2,/a/g5")
cmetal = doc.addCollection("c_metal")
cmetal.setIncludeGeom("/a/g3,/a/g4")
clamphouse = doc.addCollection("c_lamphouse")
clamphouse.setIncludeGeom("/a/lamp1/housing*Mesh")
csetgeom = doc.addCollection("c_setgeom")
csetgeom.setIncludeGeom("/b")
#
# Nodedef and lightshader material
#
nd_disklgt = doc.addNodeDef("ND_disk_lgt_light", "lightshader", "disk_lgt")
nd_disklgt.setInputValue("emissionmap", "", "filename")
nd_disklgt.setInputValue("gain", 2000.0)
shader = doc.addNode("disk_lgt", "lgtsr1")
shader.setInputValue("gain", 500.0)
mheadlight = doc.addMaterialNode("mheadlight", shader)
#
# PropertySet
#
propset = doc.addPropertySet("standard")
p = propset.addProperty("displacementbound_sphere")
p.setTarget("rmanris")
p.setValue(0.05)
p = propset.addProperty("trace_maxdiffusedepth")
p.setTarget("rmanris")
p.setValue(3.0)
#
# Looks
#
lookA = doc.addLook("lookA")
ma = lookA.addMaterialAssign("ma1", mplastic1.getName())
ma.setCollection(cplastic)
ma = lookA.addMaterialAssign("ma2", mmetal1.getName())
ma.setCollection(cmetal)
ma = lookA.addMaterialAssign("ma3", mheadlight.getName())
ma.setGeom("/a/b/headlight")
va = lookA.addVisibility("v1")
va.setVisibilityType("shadow")
va.setViewerGeom("/a/b/headlight")
va.setGeom("/")
va.setVisible(0)
va = lookA.addVisibility("v2")
va.setVisibilityType("shadow")
va.setViewerGeom("/a/b/headlight")
va.setCollection(clamphouse)
psa = lookA.addPropertySetAssign("psa1")
psa.setAttribute("propertyset", propset.getName())
psa.setGeom("/")
lookB = doc.addLook("lookB")
ma = lookB.addMaterialAssign("ma4", mplastic2.getName())
ma.setCollection(cplastic)
ma = lookB.addMaterialAssign("ma5", mmetal2.getName())
ma.setCollection(cmetal)
pa = lookB.addPropertyAssign("pa1")
pa.setAttribute("property", "matte")
pa.setValue("true", "boolean")
pa.setGeom("/g/holdout,/g/holdout2")
psa = lookB.addPropertySetAssign("psa2")
psa.setAttribute("propertyset", propset.getName())
psa.setGeom("/")
vara = lookB.addVariantAssign("va1")
vara.setVariantSetString(vset.getName())
vara.setVariantString(vardamp.getName())
va = lookB.addVisibility("v3")
va.setVisibilityType("camera")
va.setCollection(csetgeom)
va.setVisible(0)
#
# LookGroups
#
lookgrp = doc.addLookGroup("testlooks")
looks = "%s,%s" % (lookA.getName(), lookB.getName())
lookgrp.setLooks(looks)
# Validate the doc just to be sure
rc = doc.validate()
if (len(rc) >= 1 and rc[0]):
print("Mtlx document is valid.")
else:
print("Mtlx document is NOT valid: %s" % str(rc[1]))
outfile = "myLooks.mtlx"
mx.writeToXmlFile(doc, outfile)
print("Wrote materials and looks and such to %s" % outfile)
if __name__ == '__main__':
main()