// Modified by Soren 'kurgan' Jacobsen // September 20, 2000 // kurgan@kurgan.dk // Copyright (C) 1997-2000 Alias|Wavefront, // a division of Silicon Graphics Limited. // // The information in this file is provided for the exclusive use of the // licensees of Alias|Wavefront. Such users have the right to use, modify, // and incorporate this code into other products for purposes authorized // by the Alias|Wavefront license agreement, without fee. // // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. // // // Alias|Wavefront Script File // // Creation Date: Nov 4, 1999 // // Procedure: // subdIntoPolyMode // // Description: // Given a subdivision surface (with no construction history), // create a polygon. For more details see the description // with "subdiIntoPolyMode" function below. // proc subdGivenIntoPolyModeSimple( string $subd, string $poly, int $ap, int $aut ) // // Description: // See subdGivenIntoPolyMode description. { string $conv[] = `polyToSubdiv -ch 1 -ap $ap -aut $aut -mpc 100000 -o 0 $poly`; if( size($conv) > 0 ) { // Connect: connectAttr ($conv[0] + ".o") ($subd + ".cr"); } } proc subdGivenIntoPolyModeInvolved( string $subd, string $poly, int $ap, int $aut ) // // Description: // See subdGivenIntoPolyMode description. { string $conv[] = `polyToSubdiv -ch 1 -aut $aut -ap $ap -mpc 100000 -o 0 $poly`; if( size($conv) > 0 ) { string $gpsFirst = ""; string $gpsLast = ""; string $newOrig = ""; // Now produce the group parts nodes this object may have. // After that, disconnect and delete the newly created subd // but reconnect the group parts in there... string $lattice[] = `lattice -dv 2 2 2 -oc 0 -ldv 2 2 2 $subd`; string $subdHist[] = `listHistory $subd`; int $nLat = size($lattice); int $nSubdHist = size($subdHist); int $hadTweak = false; int $ii; if( $nLat < 3 ) { // Something weird happened... subdGivenIntoPolyModeSimple( $subd, $poly, $ap, $aut ); return; } // Start at 1, as [0] is the shape itself. for( $ii=1; $ii<$nSubdHist; $ii+=1 ) { string $ntype = `nodeType $subdHist[$ii]`; if( "tweak" == $ntype ) { $hadTweak = true; } else if( $hadTweak ) { if( "groupParts" == $ntype ) { if( "" == $gpsLast ) { $gpsLast = $subdHist[$ii]; $gpsFirst = $gpsLast; } else { $gpsFirst = $subdHist[$ii]; } } else if( "subdiv" == $ntype ) { $newOrig = $subdHist[$ii]; break; } } } string $tweak[]; if( "" != $gpsLast ) { $tweak = `listConnections -plugs on ($gpsLast + ".outputGeometry")`; } // Something weird happened... if( (0 == size($tweak)) || ("" == $gpsFirst) || ("" == $newOrig) ) { if( "" != $newOrig ) delete $newOrig; if( (size($tweak) > 0) && ("" != $tweak[0])) delete $tweak[0]; delete $lattice[0] $lattice[1] $lattice[2]; subdGivenIntoPolyModeSimple( $subd, $poly, $ap, $aut ); return; } disconnectAttr ($gpsLast + ".outputGeometry") $tweak; disconnectAttr ($newOrig + ".worldSubdiv[0]") ($gpsFirst + ".inputGeometry"); disconnectAttr ($lattice[0] + ".outputGeometry[0]") ($subd + ".create"); connectAttr ($conv[0] + ".o") ($gpsFirst + ".inputGeometry"); connectAttr ($gpsLast + ".outputGeometry") ($subd + ".cr"); delete $lattice[0] $lattice[1] $lattice[2] $tweak[0] $newOrig; } } global proc string subdGivenIntoPolyMode( string $subd, int $hookAsHist, int $allowHist, int $templateSubd, int $ap ) // Description: // If $allowHistory is set, we will try and find a polygon in the // history of this object, delete that polygon's blind data of // the "hierarchical edits" type and put the new blind data on // the polygon shape. If $allowHistory is not set, we will fail // if the subd has history in the first place. If there is no // history on the subd, $allowHistory is ignored. In that case, // we will make a new polygon (using "point position" option and // the base mesh on the subd -> poly conversion) and give it the blind // data that represents the hierarchical edits. If $hookAsHistory is // set, we will then plug everything through polyToSubdiv node into // the subd we started with. Otherwise, we just leave it be. Note // that subd -> poly must be done without history, or we can end up // with a loop. // // Ordinarilly, this would be called with a subdivision surface as $subd. // However, dagMenuProc.mel may call it with a transform above it instead, // so we do a filterExpand, just in case. { global int $gSelectSubdivSurface; string $list[] = `filterExpand -ex 1 -fp 1 -sm $gSelectSubdivSurface $subd`; int $len = size($list); if( $len > 0 ) { $subd = $list[0]; } int $whichMode = `subdiv -q -proxyMode $subd`; if( 2 == $whichMode ) { error( "Cannot go into polygon proxy mode on the " + "object with construction history and/or deformers." ); return ""; } else if( 1 == $whichMode ) { warning("Already in polygon proxy mode."); return ""; } int $disconnectShaders = ! $templateSubd; string $conn[] = `listConnections ($subd + ".cr")`; int $nConn = size($conn); string $hist[] = `listHistory $subd`; int $nHist = size($hist); string $poly = ""; int $i; // If there is no history, we will just see the shape; if( ($nConn > 0) && $allowHist ) { // Find the polygon to give the blind data for( $i=0; $i<$nHist; $i+=1 ) { if( "mesh" == `nodeType $hist[$i]` ) { $poly = $hist[$i]; break; } } } else if( 0 == $nConn ) { int $aut = !$ap; // we need to go and create the polygon string $res[] = `subdToPoly -ch 0 -aut $aut -f 1 -d 0 -epp 1 -mp 100000 $subd`; if( size($res) > 0 ) { // Rename it to something nicer: if( $nHist > 0 ) { $poly = `rename $res[0] ($hist[0] + "HistPoly")`; } if( $disconnectShaders ) { // disconnect the shader: // kurgans edits start here::: eval("setAttr " + $poly + ".castsShadows 0"); eval("setAttr " + $poly + ".motionBlur 0"); eval("setAttr " + $poly + ".primaryVisibility 0"); eval("setAttr " + $poly + ".smoothShading 0"); eval("setAttr " + $poly + ".visibleInReflections 0"); eval("setAttr " + $poly + ".visibleInRefractions 0"); eval("setAttr " + $poly + ".doubleSided 0"); eval("setAttr " + $poly + ".overrideEnabled 1"); eval("setAttr " + $poly + ".overrideShading 0"); eval("setAttr " + $poly + ".overrideTexturing 0"); // string $shade[] = `listConnections -p 1 ($poly + ".iog")`; // int $nShade = size($shade); // for( $i=0; $i<$nShade; $i+=1 ) { // disconnectAttr ($poly + ".iog") $shade[$i]; // } // kurgans edits end here } } } else { // This is not allowed: warning( "Subdivision surface " + $subd + " cannot switch into the polygon mode " + "if it has history and history is not allowed." ); return ""; } // At this point, we should have a $poly; if we don't we quit. if( "" == $poly ) { warning( "Subdivision surface " + $subd + " cannot switch into the polygon mode " + "if it has history but no polygon in its history." ); return ""; } // OK, we have the polygon. Go ahead and make the blind stuff: if(catch(eval( "subdToBlind -ap " + $ap + " -ic true -izo false " + $subd + " " + $poly))){ warning("subdToBlind command failure?"); } // In some cases, we need the extra poly node; this is when we have // more than 127 edits on some faces and thus multiple blind data nodes // of the same type. If we don't do this, we will screw up when doing // poly component delete... if( `getAttr -size ($poly + ".blindDataNodes")` > 7 ) { string $parent[] = `listRelatives -p $poly`; string $newPoly = `createNode mesh -p $parent[0]`; string $origPoly = `rename $poly ($poly + "Orig")`; $newPoly = `rename $newPoly $poly`; connectAttr ($origPoly + ".o") ($newPoly + ".i"); setAttr ($origPoly + ".io") 1; $poly = $newPoly; } // Now, produce the conversion node: note that that we list the // connections on .iog parent attribute. listHistory seems to // screw up after one round of conversion, though it does get cleaned // up after a file I/O cycle. It is always safe to go the involved // route, trouble is going "simple" route when you shouldn't. // We'll see how it goes... if( $hookAsHist ) { // Which one? string $iogConn[] = `listConnections ($subd + ".iog")`; if( ($nHist > 1) || (0 == size($iogConn)) ) { subdGivenIntoPolyModeInvolved( $subd, $poly, $ap, !$ap ); } else { subdGivenIntoPolyModeSimple( $subd, $poly, $ap, !$ap ); } } // Done. Template the subd if necessary: if( $templateSubd ) { toggle -template -state on $subd; } return $poly; }