// // toggle subdivision surfaces // // Created by Hamish McKenzie www.emissionpossible.com // Created : 4 July 2001 // Amended : 9 April 2003** // // Description: // a simple little script that will hopefully make lightwave users // a little more comfortable with their modelling. it will toggle // an object between subdiv and poly. it will also convert a nurbs // surface to subdiv. // // 13/12/01:Fixed it, so hopefully it now works. The original version // of this script was one of my first. And it showed. So I've // re-written it, so its a lot cleaner, and it should work properly // now. Plus it now works with multiple selections, as well as when // you've got components selected instead of objects. // // 26/03/03simple change. it now works on hilite selections if either // an object or component isn't selected. // // **it now checks to see if there are any "intermediate" objects // that share the same transform, and deletes them. It also // automatically deletes history on the object. It seems to be very // reliable now. It also no longer relies on external scripts. // // Hamish McKenzie ©2001... global proc zzToggleSubDee() { string $selObjs[] = `ls -sl -o`; if ( `size $selObjs` == 0 ) $selObjs = `ls -hl`; for ( $obj in $selObjs ) { int $isShape = `zzIsType shape $obj`; int $isTransform = `zzIsType transform $obj`; //delete history on the object delete -ch $obj; //now check to see if there are any "intermediate" objects in the transform string $shapes[] = `listRelatives`; //SHAPES if ( $isShape ) { string $objTransform[] = `listRelatives -p $obj`; string $children[] = `listRelatives -c $objTransform`; for ( $child in $children ) { //discover any intermediate objects that are children of the transform in question if ( `getAttr ( $child + ".intermediateObject" )` ) { delete $child; } } string $objType = `nodeType $obj`; if ( $objType == "subdiv" ) { string $newObject[] = `subdToPoly -ch 0 -aut 1 -format 0 -depth 0 -sampleCount 1 -maxPolys 15000 -epp 1 -suv 1 -subdNormals 0 $obj`; delete $obj; rename $newObject[0] $obj; } if ( $objType == "mesh" ) { string $newObject[] = `polyToSubdiv -ch 0 -aut 1 -ap 0 -mpc 100000 -me 255 $obj`; delete $obj; rename $newObject[0] $obj; } if ( $objType == "nurbsSurface" ) { string $newObject[] = `nurbsToSubdiv -ch 0 -aut 1 -rn 0 -mpc 100000 -mp 1 $obj`; delete $obj; rename $newObject[0] $obj; } } //TRANSFORMS if ( $isTransform ) { string $children[] = `listRelatives -c $obj`; for ( $child in $children ) { //discover any intermediate objects that are children of the transform in question if ( `getAttr ( $child + ".intermediateObject" )` ) { delete $child; } } string $objShape[] = `listRelatives -s $obj`; string $objType = `nodeType $objShape`; if ( $objType == "subdiv" ) { string $newObject[] = `subdToPoly -ch 0 -aut 1 -format 0 -depth 0 -sampleCount 1 -maxPolys 15000 -epp 1 -suv 1 -subdNormals 0 $objShape[0]`; delete $objShape[0]; rename $newObject[0] $objShape[0]; } if ( $objType == "mesh" ) { string $newObject[] = `polyToSubdiv -ch 0 -aut 1 -ap 0 -mpc 100000 -me 255 $objShape[0]`; delete $objShape[0]; rename $newObject[0] $objShape[0]; } if ( $objType == "nurbsSurface" ) { string $newObject[] = `nurbsToSubdiv -ch 0 -aut 1 -rn 0 -mpc 100000 -mp 1 $objShape[0]`; delete $objShape[0]; rename $newObject[0] $objShape[0]; } } } //RESTORE SELECTION select $selObjs; } global proc int zzIsType ( string $type, string $obj ) { $selType = `nodeType $obj`; $isType = 0; if ( $type == "transform" ) { if ( $selType == "transform" ) { $isType = 1; } } if ( $type == "shape" ) { if ( $selType == "mesh" || $selType == "subdiv" || $selType == "nurbsSurface" ) { $isType = 1; } } return $isType; }