Vray阴影层添加移除工具
脚本语言:Mel
脚本界面:
使用说明:
此工具是在项目中需要渲染Vray材质的物体阴影产生的,由于拖拽的方式在较大场景中很不方便,加上卡顿可能会误拖拽。有了这个工具会方便许多。
添加:选中一个或多个模型,点击添加可将选中模型添加到 Vrayobjectproperties。
移除:选中一个或多个模型,点击移除可将选中模型移出 Vrayobjectproperties。
创建阴影层:创建阴影层按钮不需要选中物体,会直接创建好 Vrayobjectproperties,并设置好参数
2023年11月1日21:38:32 更新
增加了采样器类型选项,方便快速设置切换
解决了重新声明变量的报错问题
采样器类型快速切换,前提是渲染设置的渲染器为 V-Ray
脚本源码:
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
|
proc YY() { createNode "VRayObjectProperties" -n "vrayobjectproperties"; setAttr "vrayobjectproperties.alphaContribution" -1; setAttr "vrayobjectproperties.affectAlpha" 1; setAttr "vrayobjectproperties.shadows" 1; setAttr "vrayobjectproperties.matteSurface" 1; setAttr "vrayobjectproperties.matteForSecondaryRays" 1; print ("阴影层创建成功!"+"\n"); }
proc Buckets() { setAttr "vraySettings.samplerType" 4; print (" Buckets 设置成功"+"\n"); } proc Progressives() { setAttr "vraySettings.samplerType" 3; print (" Progressive 设置成功"+"\n"); }
string $WindowSDWS = "WindowSDWS"; if (`window -ex $WindowSDWS`) { deleteUI -window $WindowSDWS; }
string $windowsdw = `window -title "三岁豆Er" -sizeable 0 $WindowSDWS`; columnLayout -columnAttach "both" 10 -rowSpacing 5 -columnWidth 230; text -h 50 -label"Vray 阴影层添加移除工具"; button -label "添加" -command "sets -edit -forceElement vrayobjectproperties"; button -label "移除" -command "sets -edit -rm vrayobjectproperties;"; button -label "创建阴影层" -command "YY"; separator -h 2; button -label "Bucket" -bgc 0.9 0.7 0.2 -command "Buckets"; button -label "Progressive" -bgc 0.6 0.7 0.2 -command "Progressives"; text -h 5 -label""; setParent ..; showWindow $WindowSDWS;
|
2024年1月21日更新:(大更新)
请根据自己的需求选择是否更新这个版本
如果场景很乱有很多重名的模型节点会出错,因为这个版本增加了较为复杂的运算,不允许同名节点的存在。
如果上面的个版本能满足需求不要使用现有的这个版本,因为我个人使用这个版本感觉比较方便。
功能说明:
- 创建阴影层:增加判断语句,不会多次点击创建多个,保证场景只有一个阴影层,名称为vrayobjectproperties
- 添加:添加选定的对象加入阴影层,选择的对象高光属性会被关闭,请不要选中组添加,虽然也会被添加进去,但是组里面的对象的材质不会被关闭高光属性
- 移除:将选中的对象移除阴影层,还会自动还原高光属性,选中组除外。
- 清空:清空阴影层内所有的对象和组,功能和移除一样,只不过不用手动选中对象和组
- 检查:检检查功能是因为害怕场景中有被关闭高光属性的材质出现,点击检查会找到这些被赋予有材质的对象。从而避免不必要的错误。
- Bucket:功能未改变
- Progressive:功能未改变。
脚本源码:
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
|
proc SDWlayD() { if (objExists("vrayobjectproperties")) { print "VRayObjectProperties已存在。\n"; return; }
createNode "VRayObjectProperties" -n "vrayobjectproperties"; setAttr "vrayobjectproperties.alphaContribution" -1; setAttr "vrayobjectproperties.affectAlpha" 1; setAttr "vrayobjectproperties.shadows" 1; setAttr "vrayobjectproperties.matteSurface" 1; setAttr "vrayobjectproperties.matteForSecondaryRays" 1;
print ("阴影层创建成功!\n"); }
proc Buckets() { setAttr "vraySettings.samplerType" 4; print (" Buckets 切换成功"+"\n"); }
proc Progressives() { setAttr "vraySettings.samplerType" 3; print (" Progressive 切换成功"+"\n"); }
proc addToShadowLayer() { string $selectedObjects[] = `ls -sl`; sets -edit -add "vrayobjectproperties" $selectedObjects; }
proc removeToShadowLayer() { string $selectedObjects[] = `ls -sl`; sets -edit -remove "vrayobjectproperties" $selectedObjects; }
proc clearsets() { string $setName = "vrayobjectproperties"; string $allObjectsInSet[] = `sets -q $setName`; for ($obj in $allObjectsInSet) { select -r $obj; setVrayReflAmount(1); } select -cl; for ($obj in $allObjectsInSet) { sets -remove $setName $obj; } }
global proc setVrayReflAmount(float $value) { string $selectedObjects[] = `ls -sl`; for ($object in $selectedObjects) { string $shapes[] = `listRelatives -shapes $object`; for ($shape in $shapes) { string $shadingEngines[] = `listConnections -type "shadingEngine" $shape`; for ($shadingEngine in $shadingEngines) { string $materials[] = `listConnections ($shadingEngine + ".surfaceShader")`; for ($material in $materials) { if (`objectType -isType "VRayMtl" $material` && `attributeExists "reflectionColorAmount" $material`) { setAttr ($material + ".reflectionColorAmount") $value; } } } } } }
global proc checkVrayReflAmount() { string $allMaterials[] = `ls -mat`; string $transformsToSelect[] = {}; int $notResetCount = 0; int $setToZeroCount = 0;
for ($material in $allMaterials) { if (`objectType -isType "VRayMtl" $material` && `attributeExists "reflectionColorAmount" $material`) { float $amount = `getAttr ($material + ".reflectionColorAmount")`; if ($amount != 1.0) { string $sgs[] = `listConnections -type "shadingEngine" $material`; for ($sg in $sgs) { string $connections[] = `listConnections ($sg + ".dagSetMembers")`; string $meshes[] = `ls -dag -type "mesh" $connections`; for ($mesh in $meshes) { string $parent[] = `listRelatives -parent $mesh`; if (size($parent) > 0 && !stringArrayContains($parent[0], $transformsToSelect)) { $transformsToSelect[size($transformsToSelect)] = $parent[0]; } } } $notResetCount++; } if ($amount == 0.0) { $setToZeroCount++; } } }
if ($notResetCount > 0) { select -r $transformsToSelect; print ("以下模型包含 reflectionColorAmount 不为 1 的 VrayMtl 材质的 mesh 节点: " + stringArrayToString($transformsToSelect, ", ") + "\n"); } else { print ("所有 VRayMtl 材质的 reflectionColorAmount 已设置为 1。\n"); }
if ($setToZeroCount == 0) { confirmDialog -title "检查结果" -message "场景中没有反射权重为0的材质" -button "确定" -defaultButton "确定"; } }
proc addlayD() { addToShadowLayer(); setVrayReflAmount(0); }
proc removelayD() { removeToShadowLayer(); setVrayReflAmount(1); }
global proc createUI() { if (`window -exists myWindow`) { deleteUI myWindow; }
window -title "三岁豆Er" -sizeable 0 -widthHeight 220 288 myWindow ; columnLayout -adjustableColumn true -columnAttach "both" 10 -rowSpacing 5 -columnWidth 230; text -h 50 -label"Vray阴影层辅助工具 v1.0"; button -label "创建阴影层" -bgc 0.9 0.6 0.6 -command "SDWlayD"; button -label "添加" -command "addlayD"; button -label "移除" -command "removelayD"; button -label "清空" -command "clearsets"; button -label "检查" -command "checkVrayReflAmount"; button -label "Bucket" -bgc 0.9 0.7 0.2 -command "Buckets"; button -label "Progressive" -bgc 0.6 0.7 0.2 -command "Progressives"; showWindow myWindow; }
createUI();
|