Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Creates rigid bodies inheritting initial per particle position and velocity
- //Assign as creation expression to "nParticleShape1" system or use shelf button to automatically
- //Playback once to generate rigid bodies, then disable particle evaluation to avoid generating additional rigid bodies on playback
- //After making changes to the particle emitter, delete any objects generated by expression before playing back again
- //Use emmitter max and min distance attributes or volume emitter type to avoid rigid bodies interpenetrating upon generation,
- //To use expression with other particle systems change any instances of "nParticleShape1" in the expression
- // Paste expression into script editor and use 'CTRL + F' for search and replace feature
- //If maya crashes upon playback, lower emission rate
- // If crashes persist, create rigid body manually and set playbacks start time to frame 0 before creating expression
- //Check expression for additional instructions and settings
- // -Shelf Button Mel-
- //dynExpression -s "" -c nParticleShape1;
- //dynExpression -s "if (1==1) {\nstring $pTarget = \"pCube\";\n\nduplicate $pTarget;\nfloat $randRotateX = rand(-720,720);\nfloat $randRotateY = rand(-720,720);\nfloat $randRotateZ = rand(-720,720);\n\nvector $particlePosition = nParticleShape1.position;\nfloat $particlePositionX = $particlePosition.x;\nfloat $particlePositionY = $particlePosition.y;\nfloat $particlePositionZ = $particlePosition.z;\nsetAttr (($pTarget) + (nParticleShape1.particleId + 1) + \".translateX\") $particlePositionX;\nsetAttr (($pTarget) + (nParticleShape1.particleId + 1) + \".translateY\") $particlePositionY;\nsetAttr (($pTarget) + (nParticleShape1.particleId + 1) + \".translateZ\") $particlePositionZ;\nsetAttr (($pTarget) + (nParticleShape1.particleId + 1) + \".rotateX\") $randRotateX;\nsetAttr (($pTarget) + (nParticleShape1.particleId + 1) + \".rotateY\") $randRotateY;\nsetAttr (($pTarget) + (nParticleShape1.particleId + 1) + \".rotateZ\") $randRotateZ;\n\nrigidBody -n (\"ParticleToRigid\" + (nParticleShape1.particleId + 1)) -active ($pTarget + (nParticleShape1.particleId + 1));\n\nvector $particleVelocity = nParticleShape1.velocity;\nfloat $particleVelocityX = $particleVelocity.x;\nfloat $particleVelocityY = $particleVelocity.y;\nfloat $particleVelocityZ = $particleVelocity.z;\nsetAttr (\"ParticleToRigid\" + (nParticleShape1.particleId + 1) + \".initialVelocityX\") $particleVelocityX;\nsetAttr (\"ParticleToRigid\" + (nParticleShape1.particleId + 1) + \".initialVelocityY\") $particleVelocityY;\nsetAttr (\"ParticleToRigid\" + (nParticleShape1.particleId + 1) + \".initialVelocityZ\") $particleVelocityZ;\nsetAttr (\"ParticleToRigid\" + (nParticleShape1.particleId + 1) + \".initialSpinX\") $randRotateX;\nsetAttr (\"ParticleToRigid\" + (nParticleShape1.particleId + 1) + \".initialSpinY\") $randRotateY;\nsetAttr (\"ParticleToRigid\" + (nParticleShape1.particleId + 1) + \".initialSpinZ\") $randRotateZ;\n\nselect (($pTarget) + (nParticleShape1.particleId + 1));\nsetKeyframe -at ignore;\nsetKeyframe -at visibility;\nsetKeyframe -v 1 -t (frame - 1) -at ignore;\nsetKeyframe -v 0 -t (frame - 1) -at visibility;\n\nnParticleShape1.lifespanPP = 0;\n\n\t}" -c nParticleShape1;
- //Enable or disable script
- if (1==1) {
- //Change "pCube" to the name of the target object (can't end with number)
- string $pTarget = "pCube";
- //Initial rotation speed
- float $randRotateX = rand(-720,720);
- float $randRotateY = rand(-720,720);
- float $randRotateZ = rand(-720,720);
- duplicate $pTarget;
- vector $particlePosition = nParticleShape1.position;
- float $particlePositionX = $particlePosition.x;
- float $particlePositionY = $particlePosition.y;
- float $particlePositionZ = $particlePosition.z;
- setAttr (($pTarget) + (nParticleShape1.particleId + 1) + ".translateX") $particlePositionX;
- setAttr (($pTarget) + (nParticleShape1.particleId + 1) + ".translateY") $particlePositionY;
- setAttr (($pTarget) + (nParticleShape1.particleId + 1) + ".translateZ") $particlePositionZ;
- setAttr (($pTarget) + (nParticleShape1.particleId + 1) + ".rotateX") $randRotateX;
- setAttr (($pTarget) + (nParticleShape1.particleId + 1) + ".rotateY") $randRotateY;
- setAttr (($pTarget) + (nParticleShape1.particleId + 1) + ".rotateZ") $randRotateZ;
- rigidBody -n ("ParticleToRigid" + (nParticleShape1.particleId + 1)) -active ($pTarget + (nParticleShape1.particleId + 1));
- vector $particleVelocity = nParticleShape1.velocity;
- float $particleVelocityX = $particleVelocity.x;
- float $particleVelocityY = $particleVelocity.y;
- float $particleVelocityZ = $particleVelocity.z;
- setAttr ("ParticleToRigid" + (nParticleShape1.particleId + 1) + ".initialVelocityX") $particleVelocityX;
- setAttr ("ParticleToRigid" + (nParticleShape1.particleId + 1) + ".initialVelocityY") $particleVelocityY;
- setAttr ("ParticleToRigid" + (nParticleShape1.particleId + 1) + ".initialVelocityZ") $particleVelocityZ;
- setAttr ("ParticleToRigid" + (nParticleShape1.particleId + 1) + ".initialSpinX") $randRotateX;
- setAttr ("ParticleToRigid" + (nParticleShape1.particleId + 1) + ".initialSpinY") $randRotateY;
- setAttr ("ParticleToRigid" + (nParticleShape1.particleId + 1) + ".initialSpinZ") $randRotateZ;
- select (($pTarget) + (nParticleShape1.particleId + 1));
- setKeyframe -at ignore;
- setKeyframe -at visibility;
- setKeyframe -v 1 -t (frame - 1) -at ignore;
- setKeyframe -v 0 -t (frame - 1) -at visibility;
- //Kills particle after rigid body is created
- nParticleShape1.lifespanPP = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement