パーティクルによる崩壊の制作手順を、 MEL スクリプトで自動化してみましょう。
proc string makeLambert(string $obj)
{
string $shname = `shadingNode -asShader lambert`;
string $sgname = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($shname + ".outColor") ($sgname + ".surfaceShader");
select $obj;
sets -e -forceElement $sgname;
return $shname;
}
proc string makeRamp()
{
string $ramp = `shadingNode -asTexture ramp`;
string $ptex = `shadingNode -asUtility place2dTexture`;
connectAttr ($ptex + ".outUV") ($ramp + ".uv");
connectAttr ($ptex + ".outUvFilterSize") ($ramp + ".uvFilterSize");
return $ramp;
}
proc makeKeyframe(int $keys[], float $vals[], string $obj, string $attr)
{
int $i = 0;
for($k in $keys)
{
currentTime $k;
setAttr ($obj + "." + $attr) $vals[$i];
setKeyframe -at $attr $obj;
$i++;
}
}
global proc makeDisintegrate1()
{
string $cname1[] = `cylinder`;
rotate 0 0 90;
string $dname[] = `duplicate`;
setAttr ($dname[0] + ".v") 0;
string $ename[] = `emitter -type surface -r 100 $dname[0]`;
setAttr ($ename[1] + ".enableTextureRate") 1;
string $pname[] = `particle`;
setAttr ($pname[1] + ".particleRenderType") 7;
addAttr -ln "radius" -at "float" -min 0 -max 10 $pname[1];
setAttr ($pname[1] + ".radius") 0.05;
connectDynamic -em $ename[1] $pname[0];
string $ramp1 = makeRamp();
connectAttr -force ($ramp1 + ".outColor") ($ename[1] + ".textureRate");
setAttr ($ramp1 + ".type") 1;
setAttr ($ramp1 + ".interpolation") 6;
setAttr ($ramp1 + ".colorEntryList[0].color") -type double3 0 0 0;
setAttr ($ramp1 + ".colorEntryList[1].color") -type double3 1 1 1;
setAttr ($ramp1 + ".colorEntryList[2].color") -type double3 1 1 1;
setAttr ($ramp1 + ".colorEntryList[3].color") -type double3 0 0 0;
int $keys1[] = {1, 90};
float $vals1[] = {1.0, 0.0};
makeKeyframe($keys1, $vals1, $ramp1, "colorEntryList[0].position");
int $keys2[] = {1, 10, 90};
float $vals2[] = {1.0, 1.0, 0.005};
makeKeyframe($keys2, $vals2, $ramp1, "colorEntryList[1].position");
int $keys3[] = {1, 20, 90};
float $vals3[] = {1.0, 1.0, 0.15};
makeKeyframe($keys3, $vals3, $ramp1, "colorEntryList[2].position");
int $keys4[] = {1, 30, 90};
float $vals4[] = {1.0, 1.0, 0.2};
makeKeyframe($keys4, $vals4, $ramp1, "colorEntryList[3].position");
string $shname = makeLambert($dname[0]);
connectAttr -f ($ramp1 + ".outColor") ($shname + ".color");
string $uname[] = `uniform -m 10 -dx 1 -dy 0 -dz 0 $dname[0]`;
connectDynamic -f $uname[0] $pname;
string $ramp2 = makeRamp();
setAttr ($ramp2 + ".type") 1;
setAttr ($ramp2 + ".interpolation") 6;
removeMultiInstance -break true ($ramp2 + ".colorEntryList[2]");
setAttr ($ramp2 + ".colorEntryList[0].color") -type double3 0 0 0;
setAttr ($ramp2 + ".colorEntryList[1].color") -type double3 1 1 1;
makeKeyframe($keys1, $vals1, $ramp2, "colorEntryList[0].position");
makeKeyframe($keys2, $vals2, $ramp2, "colorEntryList[1].position");
string $shname = makeLambert($cname1[0]);
connectAttr -f ($ramp2 + ".outColor") ($shname + ".transparency");
}