EigenPuff
03-21-2006, 11:14 PM
I'm porting a max utility for my artists which swaps out the mesh of one object for another. I originally started to implement this technique with replaceNode (http://www.ewertb.com/maya/mel/mel.php?howto=69) but that is not working exactly the way I want.
What I would like to do is to take a transform node, and replace it's shape node inplace, maintaining the original orientation & position of the transform's shape node. I figured that all of the orientation information would automatically be inherited from the transform parent node, but it seems I'm missing a concept here.
Here's a simplified version of what I have:
//---------------------------------------------------------
//ripped from ewertb.com MEL How To #8 - Thanks, Brian!
//---------------------------------------------------------
proc string[] GetShapes( string $xform )
{
string $shapes[];
$shapes[0] = $xform;
if ( "transform" == `nodeType $xform` )
// If given node is not a transform, assume it is a shape
// and pass it through
{
$shapes = `listRelatives -fullPath -shapes $xform`;
}
return $shapes;
}
//---------------------------------------------------------
// Replaces the child-shape node of the destination with a
// copy of the one found under source
//---------------------------------------------------------
global proc ReplaceXFormShape(string $destxform, string $sourcexform)
{
//get shapes from transform parents
string $oldshapes[] = GetShapes($destxform);
string $newshapes[] = GetShapes($sourcexform);
if(size($newshapes) != 1)
print("WARNING: This script only handles transforms with a single child shape\n");
//copy the source shape so that we leave it intact for future operations
string $dupshapes[] = `duplicate $newshapes[0]`;
//replace the old shape with the duplicate of the new one
replaceNode $oldshapes[0] $dupshapes[0];
parent -shape $dupshapes[0] $destxform;
delete $oldshapes;
rename $dupshapes[0] $oldshapes[0];
}
Anybody see what I'm missing? Thanks!
What I would like to do is to take a transform node, and replace it's shape node inplace, maintaining the original orientation & position of the transform's shape node. I figured that all of the orientation information would automatically be inherited from the transform parent node, but it seems I'm missing a concept here.
Here's a simplified version of what I have:
//---------------------------------------------------------
//ripped from ewertb.com MEL How To #8 - Thanks, Brian!
//---------------------------------------------------------
proc string[] GetShapes( string $xform )
{
string $shapes[];
$shapes[0] = $xform;
if ( "transform" == `nodeType $xform` )
// If given node is not a transform, assume it is a shape
// and pass it through
{
$shapes = `listRelatives -fullPath -shapes $xform`;
}
return $shapes;
}
//---------------------------------------------------------
// Replaces the child-shape node of the destination with a
// copy of the one found under source
//---------------------------------------------------------
global proc ReplaceXFormShape(string $destxform, string $sourcexform)
{
//get shapes from transform parents
string $oldshapes[] = GetShapes($destxform);
string $newshapes[] = GetShapes($sourcexform);
if(size($newshapes) != 1)
print("WARNING: This script only handles transforms with a single child shape\n");
//copy the source shape so that we leave it intact for future operations
string $dupshapes[] = `duplicate $newshapes[0]`;
//replace the old shape with the duplicate of the new one
replaceNode $oldshapes[0] $dupshapes[0];
parent -shape $dupshapes[0] $destxform;
delete $oldshapes;
rename $dupshapes[0] $oldshapes[0];
}
Anybody see what I'm missing? Thanks!
