Rendering a snapshot of a Dynamica Rigid Body Array in Maya

Physics APIs, Physics file formats, Maya, Max, XSI, Cinema 4D, Lightwave, Blender, thinkingParticles™ and other simulation tools, exporters and importers
Post Reply
metaldev
Posts: 1
Joined: Mon Feb 17, 2014 6:04 pm

Rendering a snapshot of a Dynamica Rigid Body Array in Maya

Post by metaldev »

I was beating my face against my desk trying to get a Dynamica Rigid Body Array to render in Maya. Beautiful simulation! But useless if I couldn't render or bake them.

So I wrote the following MEL script that instances and places a set of objects at the positions of the bodies in the rigid body array so you can render or export or do whatever with them.

It does not handle any animation.
It's simply for using a rigid body array to place objects in a scene.

Hopefully it will be useful to someone else too,
enjoy:

Code: Select all

//This tool instances and places a set of ordered object(s) at the positions of the bodies in a Dynamica rigid body array
//first select the rigid body array SHAPE,  then select objects that you want instanced at the positions of the bodies 
//in the rigid body array
global proc string[] bakeRigidBodyArraySnapshot()
{ 
    
    string $sel[] = `ls -sl`;
    
    if (`objectType $sel[0]` != "dRigidBodyArray")
        error "The Dynamica rigid body array SHAPE must be selected first.";
    
    int $bodyCount = `getAttr ( $sel[0] + ".numBodies")`;
    int $variantCount = `size $sel`;
    
    
    if ($variantCount < 2)
        error "Select the rigid body SHAPE first,  then select geometry variants that you want instanced at the positions of the rigid bodies.";
    
    int $i = 1; //skip the rigid body itself
    for (; $i < $variantCount; $i++)
    {
        if (`objectType $sel[$i]` != "transform")
        {
            	string $shapeList[] = `listRelatives -path -s $sel[$i]`;
            	for($shape in $shapeList)
            	{
            		if ( `nodeType $shape` != "mesh" && `nodeType $shape` != "surface")
                        error "Select the rigid body SHAPE first,  then select geometry variants. The objects that followed were not detected to be geometry.";
                        
                }
        }
    }
    
    string $newObjects[];
    
    int $currentVariant = 1;    
    for ($i = 0; $i < $bodyCount; $i++)
    {
        
        string $newObj[] = `instance $sel[$currentVariant]`;
        float $t[] = `getAttr ($sel[0] + ".position[" + $i + "]")`;
        float $r[] = `getAttr ($sel[0] + ".rotation[" + $i + "]")`;
        move -absolute $t[0] $t[1] $t[2] $newObj[0];
        rotate -absolute  $r[0] $r[1] $r[2] $newObj[0];      
        
        $newObjects[`size $newObjects`] = $newObj[0];
        
        $currentVariant ++;
        if ($currentVariant >= $variantCount)
            $currentVariant = 1; // 0 is the rigidBodyArray

    } 
    
    return $newObjects;   
}

select `bakeRigidBodyArraySnapshot`;

macina11
Posts: 1
Joined: Tue Aug 25, 2015 2:05 am

Re: Rendering a snapshot of a Dynamica Rigid Body Array in M

Post by macina11 »

Enter your message here, it may contain no more than 60000 characters.
backscatter x-ray scanners
Post Reply