贴图设置工具

脚本语言:Mel

脚本界面:

使用说明:

这个工具是因为连贴图的时候使用。设置各种贴图的颜色空间,什么Raw,什么勾选忽略颜色空间,Alpha为亮度等,一两个贴图还可以。贴图一多一遍一遍的设置无疑是浪费时间的,Maya也有颜色空间规则可以自动识别贴图的后缀设置色彩空间。但是后缀没有设别的话就不会应用正确的色彩空间。所以写了这个小工具,能精准控制每一张贴图的色彩空间。

各按钮功能:

忽略所有贴图色彩空间规则:

无需选中任何贴图,直接执行可忽略当前场景的所有贴图的色彩空间规则。原理也很简单,就是识别场景中所有的贴图节点,全部勾选忽略色彩空间规则。

2dTexture:

使用方法就是先选中一个place2dTexture节点,再加选需要链接这个place2dTexture的贴图执行。

就可以自动连接好,不限于渐变节点,其他节点均可。

sRGB:

这个按键就是选中需要设置色彩空间为sRGB的贴图,执行这个功能,可以设置色彩空间为sRGB,勾选忽略颜色空间规则,检查是否勾选Alpha为亮度。如果勾选Alpha为亮度,则执行取消勾选。如果未勾选则忽略;

Rwa:

这个按键就是选中需要设置色彩空间为Raw的贴图,执行这个功能,可以设置色彩空间为Raw,勾选忽略颜色空间规则,检查是否勾选Alpha为亮度。如果勾选则忽略,如果未勾选则执行勾选;

Utility - sRGB:

这个和sRGB功能一样,唯一区别就是将色彩空间设置为Utility - sRGB;

Utility - RAW:

和Raw功能相同,区别是色彩空间设置为Utility - RAW

功能讲解完毕,上源码!

脚本源码:

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
//贴图设置工具//
// 作者:三岁豆 , 创建日期 2023.06.07 //
// 2024年1月24日 添加保留边和角功能 //


////////////忽略所有贴图色彩空间规则///////////////
proc Ignoreall(){
string $FileJD[]=`ls -type file`;
for ($one in $FileJD){
setAttr ($one+".ignoreColorSpaceFileRules") 1;
print ("所有贴图忽略颜色空间规则成功"+"\n");
}
}


////////////OpenSubdiv 保留边和角///////////////
proc OpenSubdivT(){
string $Subdiv[0] = `ls -sl -dag -type shape`;
for ($one in $Subdiv)
if(`objExists ($one+".osdFvarBoundary")`)
{setAttr ($one+".osdFvarBoundary") 1;}
print ("已将UV平滑模式设置为保留边和角"+"\n");
}
////////////设置格式为 sRGB 忽略规则///////////////
proc BsRGB(){
string $sRGBsel[] = `ls -sl`;
for($i=0; $i<`size($sRGBsel)`; $i++)
{
setAttr -type "string" ($sRGBsel[$i] + ".colorSpace")"sRGB";
setAttr ($sRGBsel[$i]+ ".ignoreColorSpaceFileRules") 1;
print (" Utility - sRGB - Texture设置成功"+"\n");
}
}

////////////设置格式为Raw 忽略规则 Alpha为亮度///////////////
proc BRaw(){
string $Rawsel[] = `ls -sl`;
for($i=0; $i<`size($Rawsel)`; $i++){
setAttr -type "string" ($Rawsel[$i] + ".colorSpace")"Raw";
setAttr ($Rawsel[$i]+ ".ignoreColorSpaceFileRules") 1;
setAttr ($Rawsel[$i]+ ".alphaIsLuminance") 1;
print (" Utility - Raw 设置成功"+"\n");
}
}

////////////设置格式为 Utility - sRGB - Texture 忽略规则///////////////
proc BUsRGB(){
string $Usrgbsel[] = `ls -sl`;
for($i=0; $i<`size($Usrgbsel)`; $i++)
{
setAttr -type "string" ($Usrgbsel[$i] + ".colorSpace")"Utility - sRGB - Texture";
setAttr ($Usrgbsel[$i]+ ".ignoreColorSpaceFileRules") 1;
print (" Utility - sRGB - Texture设置成功"+"\n");
}
}

////////////设置格式为 Utility - RAW 忽略规则 Alpha为亮度///////////////
proc BUraw(){
string $URAWsel[] = `ls -sl`;
for($i=0; $i<`size($URAWsel)`; $i++){
setAttr -type "string" ($URAWsel[$i] + ".colorSpace")"Utility - Raw";
setAttr ($URAWsel[$i]+ ".ignoreColorSpaceFileRules") 1;
setAttr ($URAWsel[$i]+ ".alphaIsLuminance") 1;
print (" Utility - Raw 设置成功"+"\n");
}
}

//批量连接2dTexture到贴图File节点,先选择2dTexture,后选择贴图节点(可支持rs法线贴图连接)//
proc B2dtex(){
string $Nsel[] = `ls -sl`;
string $NTile = ($Nsel[0]+".repeatUV");
select -d $Nsel[0];
string $sel[] = `ls -sl`;
for($i=0;$i<`size($sel)`;$i++)
{
if(`objectType $sel[$i]`=="file")
{
connectAttr -force ($Nsel[0]+".coverage") ($sel[$i]+".coverage");
connectAttr -force ($Nsel[0]+".mirrorU") ($sel[$i]+".mirrorU");
connectAttr -force ($Nsel[0]+".mirrorV") ($sel[$i]+".mirrorV");
connectAttr -force ($Nsel[0]+".noiseUV") ($sel[$i]+".noiseUV");
connectAttr -force ($Nsel[0]+".offset") ($sel[$i]+".offset");
connectAttr -force ($Nsel[0]+".uvFilterSize") ($sel[$i]+".uvFilterSize");
connectAttr -force ($Nsel[0]+".repeatUV") ($sel[$i]+".repeatUV");
connectAttr -force ($Nsel[0]+".rotateFrame") ($sel[$i]+".rotateFrame");
connectAttr -force ($Nsel[0]+".rotateUV") ($sel[$i]+".rotateUV");
connectAttr -force ($Nsel[0]+".stagger") ($sel[$i]+".stagger");
connectAttr -force ($Nsel[0]+".translateFrame") ($sel[$i]+".translateFrame");
connectAttr -force ($Nsel[0]+".vertexCameraOne") ($sel[$i]+".vertexCameraOne");
connectAttr -force ($Nsel[0]+".vertexUvOne") ($sel[$i]+".vertexUvOne");
connectAttr -force ($Nsel[0]+".vertexUvThree") ($sel[$i]+".vertexUvThree");
connectAttr -force ($Nsel[0]+".vertexUvTwo") ($sel[$i]+".vertexUvTwo");
connectAttr -force ($Nsel[0]+".wrapU") ($sel[$i]+".wrapU");
connectAttr -force ($Nsel[0]+".wrapV") ($sel[$i]+".wrapV");
connectAttr -force ($Nsel[0]+".outUV") ($sel[$i]+".uvCoord");
}
else if(`objectType $sel[$i]`=="RedshiftNormalMap")
{
connectAttr -f $NTile ($sel[$i]+".repeats");
}
}
}

///////////////////主要窗口//////////////////
string $WindowMapColor = "WindowMapColor";

if (`window -ex $WindowMapColor`)
{
deleteUI -window $WindowMapColor;
}

string $windowtex = `window -title "三岁豆Er"
-sizeable 0
$WindowMapColor`;
columnLayout -columnAttach "both" 10 -rowSpacing 5 -columnWidth 230;
text -h 50 -label"贴图设置工具";
button -label "忽略所有贴图色彩空间规则" -bgc 0.2 0.8 0.9 -c "Ignoreall()";
button -label "2dTexture" -c "B2dtex()";
button -label "保留边和角" -c "OpenSubdivT()";
button -label "sRGB" -c "BsRGB()";
button -label "Raw" -c "BRaw()";
button -label "Utility - sRGB" -c "BUsRGB()";
button -label "Utility - Raw" -c "BUraw()";
text -h 5 -label"";
setParent ..;
showWindow $WindowMapColor;

2024年6月14日22:33:46更新:

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
// 贴图设置工具 //
// 作者:三岁豆 , 创建日期 2023.06.07 //
// 更新日期 2023.06.07 22:28:18 //
// 1. 自动选中颜色空间为Raw和Utility-Raw的纹理贴图,忽略颜色空间规则并勾选Alpha为亮度 //
// 2. 选中指定色彩空间的贴图节点 //

////////////忽略所有贴图色彩空间规则///////////////
proc Ignoreall(){
string $FileJD[]=`ls -type file`;
for ($one in $FileJD){
setAttr ($one+".ignoreColorSpaceFileRules") 1;
print ("所有贴图忽略颜色空间规则成功"+"\n");
}
}


////////////OpenSubdiv 保留边和角///////////////
proc OpenSubdivT(){
string $Subdiv[0] = `ls -sl -dag -type shape`;
for ($one in $Subdiv)
if(`objExists ($one+".osdFvarBoundary")`)
{setAttr ($one+".osdFvarBoundary") 1;}
print ("已将UV平滑模式设置为保留边和角"+"\n");
}
////////////设置格式为 sRGB 忽略规则///////////////
proc BsRGB(){
string $sRGBsel[] = `ls -sl`;
for($i=0; $i<`size($sRGBsel)`; $i++)
{
setAttr -type "string" ($sRGBsel[$i] + ".colorSpace")"sRGB";
setAttr ($sRGBsel[$i]+ ".ignoreColorSpaceFileRules") 1;
print (" Utility - sRGB - Texture设置成功"+"\n");
}
}

////////////设置格式为Raw 忽略规则 Alpha为亮度///////////////
proc BRaw(){
string $Rawsel[] = `ls -sl`;
for($i=0; $i<`size($Rawsel)`; $i++){
setAttr -type "string" ($Rawsel[$i] + ".colorSpace")"Raw";
setAttr ($Rawsel[$i]+ ".ignoreColorSpaceFileRules") 1;
setAttr ($Rawsel[$i]+ ".alphaIsLuminance") 1;
print (" Utility - Raw 设置成功"+"\n");
}
}

////////////设置格式为 Utility - sRGB - Texture 忽略规则///////////////
proc BUsRGB(){
string $Usrgbsel[] = `ls -sl`;
for($i=0; $i<`size($Usrgbsel)`; $i++)
{
setAttr -type "string" ($Usrgbsel[$i] + ".colorSpace")"Utility - sRGB - Texture";
setAttr ($Usrgbsel[$i]+ ".ignoreColorSpaceFileRules") 1;
print (" Utility - sRGB - Texture设置成功"+"\n");
}
}

////////////设置格式为 Utility - RAW 忽略规则 Alpha为亮度///////////////
proc BUraw(){
string $URAWsel[] = `ls -sl`;
for($i=0; $i<`size($URAWsel)`; $i++){
setAttr -type "string" ($URAWsel[$i] + ".colorSpace")"Utility - Raw";
setAttr ($URAWsel[$i]+ ".ignoreColorSpaceFileRules") 1;
setAttr ($URAWsel[$i]+ ".alphaIsLuminance") 1;
print (" Utility - Raw 设置成功"+"\n");
}
}

//批量连接2dTexture到贴图File节点,先选择2dTexture,后选择贴图节点(可支持rs法线贴图连接)//
proc B2dtex(){
string $Nsel[] = `ls -sl`;
string $NTile = ($Nsel[0]+".repeatUV");
select -d $Nsel[0];
string $sel[] = `ls -sl`;
for($i=0;$i<`size($sel)`;$i++)
{
if(`objectType $sel[$i]`=="file")
{
connectAttr -force ($Nsel[0]+".coverage") ($sel[$i]+".coverage");
connectAttr -force ($Nsel[0]+".mirrorU") ($sel[$i]+".mirrorU");
connectAttr -force ($Nsel[0]+".mirrorV") ($sel[$i]+".mirrorV");
connectAttr -force ($Nsel[0]+".noiseUV") ($sel[$i]+".noiseUV");
connectAttr -force ($Nsel[0]+".offset") ($sel[$i]+".offset");
connectAttr -force ($Nsel[0]+".uvFilterSize") ($sel[$i]+".uvFilterSize");
connectAttr -force ($Nsel[0]+".repeatUV") ($sel[$i]+".repeatUV");
connectAttr -force ($Nsel[0]+".rotateFrame") ($sel[$i]+".rotateFrame");
connectAttr -force ($Nsel[0]+".rotateUV") ($sel[$i]+".rotateUV");
connectAttr -force ($Nsel[0]+".stagger") ($sel[$i]+".stagger");
connectAttr -force ($Nsel[0]+".translateFrame") ($sel[$i]+".translateFrame");
connectAttr -force ($Nsel[0]+".vertexCameraOne") ($sel[$i]+".vertexCameraOne");
connectAttr -force ($Nsel[0]+".vertexUvOne") ($sel[$i]+".vertexUvOne");
connectAttr -force ($Nsel[0]+".vertexUvThree") ($sel[$i]+".vertexUvThree");
connectAttr -force ($Nsel[0]+".vertexUvTwo") ($sel[$i]+".vertexUvTwo");
connectAttr -force ($Nsel[0]+".wrapU") ($sel[$i]+".wrapU");
connectAttr -force ($Nsel[0]+".wrapV") ($sel[$i]+".wrapV");
connectAttr -force ($Nsel[0]+".outUV") ($sel[$i]+".uvCoord");
}
else if(`objectType $sel[$i]`=="RedshiftNormalMap")
{
connectAttr -f $NTile ($sel[$i]+".repeats");
}
}
}

global proc SetColorSpaceAndAlphaIsLuminance() {
// 获取所有的 file 节点
string $FileJD[] = `ls -type file`;

// 设置颜色空间为 "Raw" 或 "Utility - Raw",并勾选 "Alpha is Luminance"
for ($one in $FileJD) {
string $colorSpace = `getAttr ($one + ".colorSpace")`;

// 判断颜色空间是否为 "Raw" 或 "Utility - Raw"
if ($colorSpace == "Raw" || $colorSpace == "Utility - Raw") {
setAttr ($one + ".alphaIsLuminance") 1;
print ("设置 " + $one + " 的 Alpha is Luminance 成功\n");
}
}
}

global proc MainTool() {
Ignoreall();
SetColorSpaceAndAlphaIsLuminance();
}

global proc selectTexturesByColorSpace(string $colorSpace) {
// 获取所有的 file 类型节点
string $fileNodes[] = `ls -type "file"`;

// 初始化一个空数组来存储符合条件的节点
string $matchingNodes[];

for ($node in $fileNodes) {
// 获取颜色空间属性
string $nodeColorSpace = `getAttr ($node + ".colorSpace")`;

// 检查颜色空间是否为指定的颜色空间
if ($nodeColorSpace == $colorSpace) {
// 添加符合条件的节点到数组中
$matchingNodes[size($matchingNodes)] = $node;
}
}

// 打印符合条件的节点并选中它们
if (size($matchingNodes) > 0) {
print ("颜色空间为 " + $colorSpace + " 的节点:\n");
for ($node in $matchingNodes) {
print ($node + " 的颜色空间: " + $colorSpace + "\n");
}

// 选中符合条件的节点
select -r $matchingNodes;
} else {
print ("未找到颜色空间为 " + $colorSpace + " 的节点.\n");
select -cl; //如果没有则清空
}
}

///////////////////主要窗口//////////////////
string $WindowMapColor = "WindowMapColor";

if (`window -ex $WindowMapColor`)
{
deleteUI -window $WindowMapColor;
}

string $windowtex = `window -title "三岁豆Er"
-sizeable 0
$WindowMapColor`;
columnLayout -columnAttach "both" 10 -rowSpacing 5 -columnWidth 230;
text -h 50 -label"贴图设置工具";
button -label "忽略所有贴图色彩空间规则" -bgc 0.2 0.8 0.9 -c "Ignoreall()";
button -label "2dTexture" -c "B2dtex()";
button -label "保留边和角" -c "OpenSubdivT()";
button -label "sRGB" -c "BsRGB()";
button -label "Raw" -c "BRaw()";
button -label "Utility - sRGB" -c "BUsRGB()";
button -label "Utility - Raw" -c "BUraw()";
button -label "Alpha为亮度" -c "MainTool()";
button -label " 选中 sRGB " -command "selectTexturesByColorSpace(\"sRGB\")";
button -label " 选中 Raw " -command "selectTexturesByColorSpace(\"Raw\")";
button -label " 选中 Utility - sRGB " -command "selectTexturesByColorSpace(\"Utility - sRGB - Texture\")";
button -label " 选中 Utility - Raw " -command "selectTexturesByColorSpace(\"Utility - Raw\")";
button -label " 选中 ACES-ACES2065-1 " -command "selectTexturesByColorSpace(\"ACES - ACES2065-1\")";
text -h 5 -label"";
setParent ..;
showWindow $WindowMapColor;