-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_rsTexBin.py
209 lines (191 loc) · 11.1 KB
/
convert_rsTexBin.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# -*- coding: utf-8 -*-
# by rongjie
def convertTexturesToRedshift(forced):
import maya.cmds as cmds
import os
redshitTextureProcessor = os.getenv("REDSHIFT_COREDATAPATH") + "/bin/redshiftTextureProcessor"
# find the files
all_material_list = cmds.ls(materials=True)
textures_list = cmds.ls(type="file")
domeLights_list = cmds.ls(type="RedshiftDomeLight")
normalMaps_list = cmds.ls(type="RedshiftNormalMap")
environments_list = cmds.ls(type="RedshiftEnvironment")
lensDistortions_list = cmds.ls(type="RedshiftLensDistortion")
sprites_list = cmds.ls(type="RedshiftSprite")
numberOfNodes = len(textures_list) + len(domeLights_list) + len(normalMaps_list) + len(environments_list) # + len(sprites_list) + len(lensDistortions_list)
if forced == 1:
print "Forced Conversion of " + str(numberOfNodes) + " nodes\n"
else:
print "Skipped Conversion of " + str(numberOfNodes) + " nodes\n"
# file textures
for each in textures_list:
if not each:
continue
fileName = cmds.getAttr(each + ".ftn")
colorSpace = cmds.getAttr(each + ".colorProfile")
if cmds.listConnections(each + '.repeatUV', s=True, d=False):
place2d = cmds.listConnections(each + '.repeatUV', s=True, d=False)[0]
repeatU = cmds.getAttr(place2d + '.repeatU')
repeatV = cmds.getAttr(place2d + '.repeatV')
else:
repeatU = 1
repeatV = 1
if repeatU != 1:
repeatU_str = " -wx"
else:
repeatU_str = ""
if repeatV != 1:
repeatV_str = " -wy"
else:
repeatV_str = ""
# about color and weight
if cmds.listConnections(each, s=False, d=True, c=True):
des_node_list = zip(cmds.listConnections(each, s=False, d=True, c=True)[::2],
cmds.listConnections(each, s=False, d=True, c=True)[1::2])
for des_node in des_node_list:
if des_node[1] in all_material_list or (cmds.nodeType(des_node[1]) == 'multiplyDivide'):
if des_node[0].rsplit('.', 1)[1] == 'outColor':
# force_str = " -s"
if colorSpace not in [2, 4]:
if forced == 1:
print "Converting " + fileName + " to sRGB space\n"
os.system(
redshitTextureProcessor + " " + fileName + " -s -noskip" + repeatU_str + repeatV_str + "\n")
else:
print "Converting " + fileName + " to sRGB space\n"
os.system(
redshitTextureProcessor + " " + fileName + " -s" + repeatU_str + repeatV_str + " \n")
else:
if forced == 1:
print "Converting " + fileName + " to linear space\n"
os.system(
redshitTextureProcessor + " " + fileName + " -l -noskip" + repeatU_str + repeatV_str + "\n")
else:
print "Converting " + fileName + " to linear space\n"
os.system(
redshitTextureProcessor + " " + fileName + " -l" + repeatU_str + repeatV_str + " \n")
else:
if colorSpace not in [3]:
# force_str = " -l"
if forced == 1:
print "Converting " + fileName + " to linear space\n"
os.system(
redshitTextureProcessor + " " + fileName + " -l -noskip" + repeatU_str + repeatV_str + "\n")
else:
print "Converting " + fileName + " to linear space\n"
os.system(
redshitTextureProcessor + " " + fileName + " -l" + repeatU_str + repeatV_str + " \n")
else:
# force_str = " -l"
if forced == 1:
print "Converting " + fileName + " to sRGB space\n"
os.system(
redshitTextureProcessor + " " + fileName + " -s -noskip" + repeatU_str + repeatV_str + "\n")
else:
print "Converting " + fileName + " to sRGB space\n"
os.system(
redshitTextureProcessor + " " + fileName + " -s" + repeatU_str + repeatV_str + " \n")
# domelight maps are always linear
for domeLight in domeLights_list:
domeLightName = cmds.getAttr(domeLight + ".tex0")
backPlateName = cmds.getAttr(domeLight + ".tex1")
if os.path.exists(domeLightName):
domeLight_srgb = cmds.getAttr(domeLight + ".srgbToLinear0")
if domeLight_srgb == 0:
if forced == 1:
print ("Converting " + domeLightName + " to original space\n")
os.system(redshitTextureProcessor + " " + domeLightName + " -isphere -l -noskip\n")
else:
print ("Converting " + domeLightName + " to original space\n")
os.system(redshitTextureProcessor + " " + domeLightName + " -isphere -l\n")
else:
if forced == 1:
print ("Converting " + domeLightName + " to original space\n")
os.system(redshitTextureProcessor + " " + domeLightName + " -isphere -s -noskip\n")
else:
print ("Converting " + domeLightName + " to original space\n")
os.system(redshitTextureProcessor + " " + domeLightName + " -isphere -s\n")
if backPlateName and os.path.exists(backPlateName):
backPlate_srgb = cmds.getAttr(domeLight + ".srgbToLinear1")
if backPlate_srgb == 0:
if forced == 1:
print ("Converting " + backPlateName + " to original space\n")
os.system(redshitTextureProcessor + " " + backPlateName + " -isphere -l -noskip\n")
else:
print ("Converting " + backPlateName + " to original space\n")
os.system(redshitTextureProcessor + " " + backPlateName + " -isphere -l\n")
else:
if forced == 1:
print ("Converting " + backPlateName + " to original space\n")
os.system(redshitTextureProcessor + " " + backPlateName + " -isphere -s -noskip\n")
else:
print ("Converting " + backPlateName + " to original space\n")
os.system(redshitTextureProcessor + " " + backPlateName + " -isphere -s\n")
# environments are usually linear
for environment in environments_list:
environmentMapName = cmds.getAttr(environment + ".tex0")
environmentBackPlateName = cmds.getAttr(environment + ".tex1")
if os.path.exists(environmentMapName):
env_srgb = cmds.getAttr(environment + ".srgbToLinear0")
if env_srgb == 0:
if forced == 1:
print ("Converting " + environmentMapName + " to original space\n")
os.system(redshitTextureProcessor + " " + environmentMapName + " -l -noskip\n")
else:
print ("Converting " + environmentMapName + " to original space\n")
os.system(redshitTextureProcessor + " " + environmentMapName + " -l\n")
else:
if forced == 1:
print ("Converting " + environmentMapName + " to original space\n")
os.system(redshitTextureProcessor + " " + environmentMapName + " -s -noskip\n")
else:
print ("Converting " + environmentMapName + " to original space\n")
os.system(redshitTextureProcessor + " " + environmentMapName + " -s\n")
if environmentBackPlateName and os.path.exists(environmentBackPlateName):
env_srgb = cmds.getAttr(environment + ".srgbToLinear1")
if env_srgb == 0:
if forced == 1:
print ("Converting " + environmentBackPlateName + " to original space\n")
os.system(redshitTextureProcessor + " " + environmentBackPlateName + " -l -noskip\n")
else:
print ("Converting " + environmentBackPlateName + " to original space\n")
os.system(redshitTextureProcessor + " " + environmentBackPlateName + " -l\n")
else:
if forced == 1:
print ("Converting " + environmentBackPlateName + " to original space\n")
os.system(redshitTextureProcessor + " " + environmentBackPlateName + " -s -noskip\n")
else:
print ("Converting " + environmentBackPlateName + " to original space\n")
os.system(redshitTextureProcessor + " " + environmentBackPlateName + " -s\n")
# normal maps are always linear
for normalMap in normalMaps_list:
normalMapName = cmds.getAttr(normalMap + ".tex0")
if os.path.exists(normalMapName):
if forced == 1:
print ("Converting " + normalMapName + " to linear space\n")
os.system(redshitTextureProcessor + " " + normalMapName + " -l -noskip\n")
else:
print ("Converting " + normalMapName + " to linear space\n")
os.system(redshitTextureProcessor + " " + normalMapName + " -l\n")
# # sprite textures as original color space otherwise it interferes with the sprite color settings
# for sprite in sprites_list:
# spriteName = cmds.getAttr(sprite + ".tex0")
# if os.path.exists(spriteName):
# if forced == 1:
# print ("Converting " + spriteName + " using its original space\n")
# os.system(redshitTextureProcessor + " " + spriteName + " -ocolor -l -noskip\n")
# else:
# print ("Converting " + spriteName + " using it's original space\n")
# os.system(redshitTextureProcessor + " " + spriteName + " -ocolor -l\n")
# # lens distortion images as original color space otherwise it interferes with the distortion image color settings
# for lensDistortion in lensDistortions_list:
# lensDistortionName = cmds.getAttr(lensDistortion + ".LDimage")
# if os.path.exists(lensDistortionName):
# if forced == 1:
# print ("Converting " + lensDistortionName + " using it's original space\n")
# os.system(redshitTextureProcessor + " " + lensDistortionName + " -ocolor -l -noskip\n")
# else:
# print ("Converting " + lensDistortionName + " using it's original space\n")
# os.system(redshitTextureProcessor + " " + lensDistortionName + " -ocolor -l\n")
print 'final!'
convertTexturesToRedshift(1)