贴图设置工具
脚本语言: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
功能讲解完毕,上源码!
2024.06.23脚本源码:
脚本更新没做介绍
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
global proc Ignoreall(){ string $FileJD[]=`ls -type file`; for ($one in $FileJD){ setAttr ($one+".ignoreColorSpaceFileRules") 1; print ("所有贴图忽略颜色空间规则成功"+"\n"); } }
global 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"); }
global 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; setAttr ($sRGBsel[$i]+ ".alphaIsLuminance") 0; print (" Utility - sRGB - Texture设置成功"+"\n"); } }
global 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"); } }
global 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; setAttr ($Usrgbsel[$i]+ ".alphaIsLuminance") 0; print (" Utility - sRGB - Texture设置成功"+"\n"); } }
global 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"); } }
global proc B2dtex(){ string $selectedNodes[] = `ls -sl -type "place2dTexture"`;
if (size($selectedNodes) < 2) { warning("请至少选择两个place2dTexture节点进行合并。"); return; }
string $baseNode = $selectedNodes[0]; for ($i = 1; $i < `size($selectedNodes)`; $i++) { string $currentNode = $selectedNodes[$i];
string $fileNodes[] = `listConnections -type "file" $currentNode`; for ($fileNode in $fileNodes) { if (`isConnected ($currentNode + ".outUV") ($fileNode + ".uvCoord")`) { disconnectAttr ($currentNode + ".outUV") ($fileNode + ".uvCoord"); } if (`isConnected ($currentNode + ".outUvFilterSize") ($fileNode + ".uvFilterSize")`) { disconnectAttr ($currentNode + ".outUvFilterSize") ($fileNode + ".uvFilterSize"); }
if (!`isConnected ($baseNode + ".outUV") ($fileNode + ".uvCoord")`) { connectAttr -force ($baseNode + ".outUV") ($fileNode + ".uvCoord"); } if (!`isConnected ($baseNode + ".outUvFilterSize") ($fileNode + ".uvFilterSize")`) { connectAttr -force ($baseNode + ".outUvFilterSize") ($fileNode + ".uvFilterSize"); } if (!`isConnected ($baseNode + ".coverage") ($fileNode + ".coverage")`) { connectAttr -force ($baseNode + ".coverage") ($fileNode + ".coverage"); } if (!`isConnected ($baseNode + ".translateFrame") ($fileNode + ".translateFrame")`) { connectAttr -force ($baseNode + ".translateFrame") ($fileNode + ".translateFrame"); } if (!`isConnected ($baseNode + ".rotateFrame") ($fileNode + ".rotateFrame")`) { connectAttr -force ($baseNode + ".rotateFrame") ($fileNode + ".rotateFrame"); } if (!`isConnected ($baseNode + ".mirrorU") ($fileNode + ".mirrorU")`) { connectAttr -force ($baseNode + ".mirrorU") ($fileNode + ".mirrorU"); } if (!`isConnected ($baseNode + ".mirrorV") ($fileNode + ".mirrorV")`) { connectAttr -force ($baseNode + ".mirrorV") ($fileNode + ".mirrorV"); } if (!`isConnected ($baseNode + ".stagger") ($fileNode + ".stagger")`) { connectAttr -force ($baseNode + ".stagger") ($fileNode + ".stagger"); } if (!`isConnected ($baseNode + ".wrapU") ($fileNode + ".wrapU")`) { connectAttr -force ($baseNode + ".wrapU") ($fileNode + ".wrapU"); } if (!`isConnected ($baseNode + ".wrapV") ($fileNode + ".wrapV")`) { connectAttr -force ($baseNode + ".wrapV") ($fileNode + ".wrapV"); } if (!`isConnected ($baseNode + ".repeatUV") ($fileNode + ".repeatUV")`) { connectAttr -force ($baseNode + ".repeatUV") ($fileNode + ".repeatUV"); } if (!`isConnected ($baseNode + ".vertexUvOne") ($fileNode + ".vertexUvOne")`) { connectAttr -force ($baseNode + ".vertexUvOne") ($fileNode + ".vertexUvOne"); } if (!`isConnected ($baseNode + ".vertexUvTwo") ($fileNode + ".vertexUvTwo")`) { connectAttr -force ($baseNode + ".vertexUvTwo") ($fileNode + ".vertexUvTwo"); } if (!`isConnected ($baseNode + ".vertexUvThree") ($fileNode + ".vertexUvThree")`) { connectAttr -force ($baseNode + ".vertexUvThree") ($fileNode + ".vertexUvThree"); } if (!`isConnected ($baseNode + ".vertexCameraOne") ($fileNode + ".vertexCameraOne")`) { connectAttr -force ($baseNode + ".vertexCameraOne") ($fileNode + ".vertexCameraOne"); } if (!`isConnected ($baseNode + ".noiseUV") ($fileNode + ".noiseUV")`) { connectAttr -force ($baseNode + ".noiseUV") ($fileNode + ".noiseUV"); } if (!`isConnected ($baseNode + ".offset") ($fileNode + ".offset")`) { connectAttr -force ($baseNode + ".offset") ($fileNode + ".offset"); } if (!`isConnected ($baseNode + ".rotateUV") ($fileNode + ".rotateUV")`) { connectAttr -force ($baseNode + ".rotateUV") ($fileNode + ".rotateUV"); } } delete $currentNode; }
print("合并完成。\n"); }
global proc MainTool() { string $FileJD[] = `ls -type file`; for ($one in $FileJD) { string $colorSpace = `getAttr ($one + ".colorSpace")`; if ($colorSpace == "Raw" || $colorSpace == "Utility - Raw") { setAttr ($one + ".alphaIsLuminance") 1; setAttr ($one+".ignoreColorSpaceFileRules") 1; print ("设置 " + $one + " 的 Alpha is Luminance 成功\n"); } } }
global proc selectTexturesByColorSpace(string $colorSpace) { 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 240; 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 "Alpha为亮度" -c "MainTool()"; frameLayout -label " 将选中的贴图设置为对应的色彩空间"; rowLayout -numberOfColumns 4 -columnAttach4 "both" "both" "both" "both" -columnWidth4 53 53 53 53; button -label "sRGB" -c "BsRGB()"; button -label "Raw" -c "BRaw()"; button -label "U-sRGB" -c "BUsRGB()"; button -label "U-Raw" -c "BUraw()"; setParent ..;
frameLayout -label " 选中对应色彩空间的file节点"; rowLayout -numberOfColumns 4 -columnAttach4 "both" "both" "both" "both" -columnWidth4 53 53 53 53; button -label "sRGB" -c "selectTexturesByColorSpace(\"sRGB\")"; button -label "Raw" -c "selectTexturesByColorSpace(\"Raw\")"; button -label "U-sRGB" -c "selectTexturesByColorSpace(\"Utility - sRGB - Texture\")"; button -label "U-Raw" -c "selectTexturesByColorSpace(\"Utility - Raw\")"; setParent ..;
button -label "ACES-ACES2065-1" -c "selectTexturesByColorSpace(\"ACES - ACES2065-1\")"; text -h 5 -label ""; setParent ..; showWindow $WindowMapColor;
|