// Creation Date: Jan-27-2002 // // Author: // // ------------------------- // --------------------------- // Klaus Stangl // Student@TU Graz // Demoartist/Developer // Educator@Siliconstudio Graz // www.worldofmaya.com // office@worldofmaya.com // ----------------------------- // // Script Name: // particleDisplacement (version 0.9) // // Syntax: // particleDisplacement() // // Tested with: // Maya 4.5 for NT // // Example: // source particleDisplacement.mel; particleDisplacement; // // Description: // // The script creates an particle grid with the resolution you enter. // Afterwards press play and change the values in the ramps named: // displaceXRampX, displaceYRampX displaceZRampX // where ...X means a number // // // For more infos read the documentation on www.worldofmaya.com or mail! //---------------------------------------------------------------- proc string confirm_Dialog(string $title) { global int $q_confirm; if ($q_confirm==0) { string $button_re=`confirmDialog -message $title -button "Yes" -button "No" -defaultButton "No" -ma "center" -t "particleDisplacement()" -cancelButton "No" -dismissString "No"`; return($button_re); } else { return("Yes"); } } //---------------------------------------------------------------- proc createGridwithUV(int $maxX, int $maxY, int $createParticle) { //Initialize! global string $particleName[]; int $runX = 0; int $runY = 0; int $currentTimeVar; int $runXExpr = 0; int $runYExpr = 0; $currentTimeVar = `currentTime -q`; int $temporaryInt = 0; string $expressionStrg; //Initialize End! cycleCheck -e off; if ($createParticle) { $particleName = `particle -ll 0.1 0 0.1 -ur ($maxY/10.0) 0 ($maxX/10.0) -grs 0.1 -c 1 `; CenterPivot; move -rpr 0 0 0 ; } addAttr -ln displacementPP -dt vectorArray $particleName[1]; setAttr -e -keyable true ($particleName[1]+".displacementPP"); addAttr -ln displacementX -dt vectorArray $particleName[1]; setAttr -e -keyable true ($particleName[1]+".displacementX"); addAttr -ln displacementY -dt vectorArray $particleName[1]; setAttr -e -keyable true ($particleName[1]+".displacementY"); addAttr -ln displacementZ -dt vectorArray $particleName[1]; setAttr -e -keyable true ($particleName[1]+".displacementZ"); addAttr -ln positionSave0 -dt vectorArray $particleName[1]; addAttr -ln positionSave -dt vectorArray $particleName[1]; setAttr -e -keyable true ($particleName[1]+".positionSave"); addAttr -ln "rgbPP" -dt vectorArray $particleName[1]; addAttr -ln "rgbPP0" -dt vectorArray $particleName[1]; addAttr -ln "opacityPP" -dt doubleArray $particleName[1]; addAttr -ln "opacityPP0" -dt doubleArray $particleName[1]; addAttr -ln xCoord0 -dt doubleArray $particleName[1]; addAttr -ln xCoord -dt doubleArray $particleName[1]; setAttr -e -keyable true ($particleName[1]+".xCoord"); addAttr -ln yCoord0 -dt doubleArray $particleName[1]; addAttr -ln yCoord -dt doubleArray $particleName[1]; setAttr -e -keyable true ($particleName[1]+".yCoord"); $runXExpr = 0; $runYExpr = 0; $expressionStrg = "int $maxX = "+$maxX+";\r\nint $maxY = "+$maxY+";\r\nglobal int $runXExpr;\r\nglobal int $runYExpr;\r\nif (id==0) {$runXExpr =0;$runYExpr=0;}\r\nif ($runYExpr<$maxY)\r\n{\r\n\r\n if ($runXExpr == $maxX)\r\n {\r\n\t$runXExpr = 0;\r\n\t$runYExpr++;\r\n\r\n }\r\n\r\n if ($runXExpr > 0) xCoord0 = $runXExpr/($maxX-1.0);\r\n\telse $runXExpr =0;\r\n if ($runYExpr > 0) yCoord0 = $runYExpr/($maxY-1.0);\r\n\telse $runYExpr =0;\r\n $runXExpr++;\r\n}\r\npositionSave0 = position;"; dynExpression -s $expressionStrg -r $particleName[1]; // Change time to take Effect $currentTimeVar = `currentTime -q`; currentTime -e ($currentTimeVar+1); //currentTime -e ($currentTimeVar+2); currentTime -e ($currentTimeVar); $runXExpr = 0; $runYExpr = 0; // Delete expression! dynExpression -s "" -r $particleName[1]; } //---------------------------------------------------------------- proc createDisplacementShadingNode(int $fileORramp) { global string $particleName[]; string $rampName = ""; string $shadingNodeName = ""; string $arrayMapperName = ""; string $tempAryStrg[]; $shadingNodeName = `shadingNode -asTexture layeredTexture`; $shadingNodeName = `rename $shadingNodeName "particleDisplaceLayer#"`; setAttr ($shadingNodeName+".inputs[0].color") -type "double3" 0 0 0; setAttr ($shadingNodeName+".inputs[0].alpha") 1; setAttr ($shadingNodeName+".inputs[0].blendMode") 1; setAttr ($shadingNodeName+".inputs[1].color") -type "double3" 0 1 0; setAttr ($shadingNodeName+".inputs[1].alpha") 1; setAttr ($shadingNodeName+".inputs[1].blendMode") 1; dynExpression -s "float $tempFloatX = displacementX;\r\nfloat $tempFloatY = displacementY;\r\nfloat $tempFloatZ = displacementZ;\r\nposition = positionSave + <<$tempFloatX,$tempFloatY,$tempFloatZ>>;\r" -r $particleName[1]; $rampName = `shadingNode -asTexture ramp -n "displaceXRamp#"`; removeMultiInstance -break true ($rampName+".colorEntryList[1]"); removeMultiInstance -break true ($rampName+".colorEntryList[2]"); setAttr ($rampName+".colorEntryList[0].color") -type double3 0 0 0 ; $tempAryStrg = `arrayMapper -target $particleName[1] -destAttr displacementX -inputU xCoord -inputV yCoord -mapTo $rampName`; $arrayMapperName = $tempAryStrg[0]; if ($fileORramp) { $shadingNodeName = `shadingNode -asTexture file -n "displaceXFile#"`; connectAttr -f ($shadingNodeName+".message") ($arrayMapperName+".computeNode"); connectAttr -f ($shadingNodeName+".outColor") ($arrayMapperName+".computeNodeColor"); } $rampName = `shadingNode -asTexture ramp -n "displaceYRamp#"`; removeMultiInstance -break true ($rampName+".colorEntryList[1]"); removeMultiInstance -break true ($rampName+".colorEntryList[2]"); setAttr ($rampName+".type") 5; setAttr ($rampName+".colorEntryList[0].color") -type double3 1 1 1 ; setAttr ($rampName+".colorEntryList[1].color") -type double3 0 0 0 ; setAttr ($rampName+".colorEntryList[1].position") 0.5; $tempAryStrg = `arrayMapper -target $particleName[1] -destAttr displacementY -inputU xCoord -inputV yCoord -mapTo $rampName`; $arrayMapperName = $tempAryStrg[0]; if ($fileORramp) { $shadingNodeName = `shadingNode -asTexture file -n "displaceYFile#"`; connectAttr -f ($shadingNodeName+".message") ($arrayMapperName+".computeNode"); connectAttr -f ($shadingNodeName+".outColor") ($arrayMapperName+".computeNodeColor"); } $rampName = `shadingNode -asTexture ramp -n "displaceZRamp#"`; removeMultiInstance -break true ($rampName+".colorEntryList[1]"); removeMultiInstance -break true ($rampName+".colorEntryList[2]"); setAttr ($rampName+".colorEntryList[0].color") -type double3 0 0 0 ; $tempAryStrg = `arrayMapper -target $particleName[1] -destAttr displacementZ -inputU xCoord -inputV yCoord -mapTo $rampName`; $arrayMapperName = $tempAryStrg[0]; if ($fileORramp) { $shadingNodeName = `shadingNode -asTexture file -n "displaceZFile#"`; connectAttr -f ($shadingNodeName+".message") ($arrayMapperName+".computeNode"); connectAttr -f ($shadingNodeName+".outColor") ($arrayMapperName+".computeNodeColor"); } } //---------------------------------------------------------------- proc createRGBFileNode() { global string $particleName[]; string $rampName = ""; string $shadingNodeName = ""; string $arrayMapperName = ""; string $tempAryStrg[]; $tempAryStrg = `arrayMapper -target $particleName[1] -destAttr rgbPP -inputU xCoord -inputV yCoord -type ramp`; $arrayMapperName = $tempAryStrg[0]; $shadingNodeName = `shadingNode -asTexture file -n "hardwareColorFile#"`; connectAttr -f ($shadingNodeName+".message") ($arrayMapperName+".computeNode"); connectAttr -f ($shadingNodeName+".outColor") ($arrayMapperName+".computeNodeColor"); } //---------------------------------------------------------------- global proc particleDisplacement( ) { //Initialize! int $maxX = 0; int $maxY = 0; int $currentTimeVar; int $useSoftbody = 0; global string $particleName[]; global string $softbodyParticleShapeName[]; //Initialize End! $softbodyParticleShapeName = `ls -sl -s`; if ((`size $softbodyParticleShapeName`) == 1) if(confirm_Dialog("Use Softbody?")=="Yes") { $useSoftbody = 1; $particleName[1] = $softbodyParticleShapeName[0]; } currentTime -e 1; promptDialog -message "Enter X-Resolution:" -button "Ok" -button "Cancel" -defaultButton "Ok" -cancelButton "Cancel" -dismissString "Cancel"; $maxX = `promptDialog -q`; if($maxX > 0) { promptDialog -message "Enter Y-Resolution:" -button "Ok" -button "Cancel" -defaultButton "Ok" -cancelButton "Cancel" -dismissString "Cancel"; $maxY = `promptDialog -q`; } if(($maxX>0)&&($maxY>0)) { if($useSoftbody) createGridwithUV($maxX, $maxY, 0); if(!$useSoftbody) createGridwithUV($maxX, $maxY, 1); if (confirm_Dialog("Create Ramp-Nodes?")=="Yes") createDisplacementShadingNode(0); else createDisplacementShadingNode(1); if (confirm_Dialog("Create RGB-File-Node?")=="Yes") createRGBFileNode(); setAttr ($particleName[1]+".startFrame") `playbackOptions -q -min`; $currentTimeVar = `currentTime -q`; currentTime -e ($currentTimeVar+1); } select -cl; } // End of particleDisplacement()