// ========================================================================== // http://www.tjgalda.com // // Copyright (C) 2007 TJ Galda. All rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files contain unpublished // information proprietary to TJ Galda which is protected by U.S. and // Canadian federal copyright law and by international treaties. // // The Data is provided for use exclusively by You. You have the right // to use, modify, and incorporate this Data into other products for // purposes authorized by TJ Galda, without fee. // // The copyright notices in the Software and this entire statement, // including the above license grant, this restriction and the // following disclaimer, must be included in all copies of the // Software, in whole or in part, and all derivative works of // the Software, unless such copies or derivative works are solely // in the form of machine-executable object code generated by a // source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. // TJ GALDA DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED // WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF // NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR // PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR // TRADE PRACTICE. IN NO EVENT WILL TJ GALDA AND/OR ITS LICENSORS // BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, // DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF TJ GALDA // AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY // OR PROBABILITY OF SUCH DAMAGES. // // http://www.tjgalda.com // ========================================================================== // // TJ Galda Script File // MODIFY THIS AT YOUR OWN RISK // // Creation Date: tj, october 14, 2008 // // Procedure Name: // tj_matchVertPos.mel // // Description: // Tool that takes the world space position of selected vertices // on a good mesh and moves the same vertices on the "bad" mesh // to the same spot. Works well for fixing blendshapes, etc. // Works on world space, brute force level. // // Usage: matchVertPos // -use UI to select "good" & "bad" meshes // -select vertices to match and run // // Input Arguments: // None // // Return Value: // None. // // http://www.tjgalda.com // ========================================================================== global proc tj_matchVertPos() { //create a window to harvest mesh information // ////////////////// // start window ////////////////// string $tj_mvp_winName = "mvp_meshNamesWin"; if ( `window -exists $tj_mvp_winName` ) { deleteUI -window $tj_mvp_winName; } // string $tj_mvp_temp = `window -widthHeight 512 149 -title ("Enter The Mesh Names "+ " tj galda") -in "Enter The Mesh Names" -rtf true -mxb false -s true $tj_mvp_winName`; $tj_mvp_winName = $tj_mvp_temp; //build initial window columnLayout -adjustableColumn true; string $tj_mvp_goodMeshButton = `button -l "Select Good Mesh" -ann "Select the mesh you want to match the vert positions to" -h 40 -bgc 0 0.7 0.9 -c "tj_mvp_updateWin" goodMeshButton`; string $tj_mvp_fixMeshButton = `button -l "Waiting to Select Mesh to Fix" -ann "Select the mesh you want to fix" -en 0 fixMeshButton`; //spacer text -l ""; text -l ""; string $tj_mvp_vertSelButton = `button -l "Waiting to Select Vertices On the GOOD Mesh to Match" -en 0 -h 60 vertSelButton`; setParent ..; showWindow $tj_mvp_winName; //update button commands with names button -e -c ("tj_mvp_updateWin 0 "+$tj_mvp_goodMeshButton+" "+$tj_mvp_fixMeshButton+" "+$tj_mvp_vertSelButton+" "+$tj_mvp_winName) $tj_mvp_goodMeshButton; button -e -c ("tj_mvp_updateWin 1 "+$tj_mvp_goodMeshButton+" "+$tj_mvp_fixMeshButton+" "+$tj_mvp_vertSelButton+" "+$tj_mvp_winName) $tj_mvp_fixMeshButton; button -e -c ("tj_mvp_selectVertsWin "+$tj_mvp_goodMeshButton+" "+$tj_mvp_fixMeshButton+" "+$tj_mvp_vertSelButton+" "+$tj_mvp_winName) $tj_mvp_vertSelButton; } global proc tj_mvp_updateWin (int $tj_mvp_meshFlag, string $tj_mvp_goodMeshButton, string $tj_mvp_fixMeshButton, string $tj_mvp_vertSelButton, string $tj_mvp_winName) { //update window according to info provided // flag 0 = good mesh, 1 = mesh to fix if ($tj_mvp_meshFlag == 0) { //gather good mesh info and update window string $tj_mvp_meshes[] = `ls -sl`; if (`size $tj_mvp_meshes` != 1 ) { warning "Please select one mesh to use as the GOOD mesh"; } else { //have one mesh, update window button -e -l ("Good Mesh = "+$tj_mvp_meshes[0]) -bgc 0.2 0.6 0 -h 25 -c $tj_mvp_meshes[0] -en 0 $tj_mvp_goodMeshButton; button -e -en 1 -bgc 0 0.7 0.9 -h 40 $tj_mvp_fixMeshButton; } } else if ($tj_mvp_meshFlag == 1) { //gather fix mesh info and update window string $tj_mvp_meshes[] = `ls -sl`; string $tj_mvp_goodMeshName = `button -q -c $tj_mvp_goodMeshButton`; if (`size $tj_mvp_meshes` != 1 ) { warning "Please select one mesh to use as the one to FIX mesh"; } else if ($tj_mvp_meshes[0] == $tj_mvp_goodMeshName) { warning "You've selected the same mesh! Try again..."; } else { //have both meshes, update window button -e -l ("Fix Mesh = "+$tj_mvp_meshes[0]) -bgc 0.2 0.6 0 -h 25 -c $tj_mvp_meshes[0] -en 0 $tj_mvp_fixMeshButton; button -e -en 1 -bgc 0 0.7 0.9 -h 50 -l "Select Vertices On the GOOD Mesh to Match" $tj_mvp_vertSelButton; //change to component mode to prompt vert selection select -r $tj_mvp_goodMeshName; changeSelectMode -component; setComponentPickMask "Point" true; updateObjectSelectionMasks; updateComponentSelectionMasks; hilite -r $tj_mvp_goodMeshName; } } } //now have names, ensure vertices are selected and run matching.... global proc tj_mvp_selectVertsWin (string $tj_mvp_goodMeshButton, string $tj_mvp_fixMeshButton, string $tj_mvp_vertSelButton, string $tj_mvp_winName) { //harvest data first string $tj_mvp_goodMesh = `button -q -c $tj_mvp_goodMeshButton`; string $tj_mvp_fixMesh = `button -q -c $tj_mvp_fixMeshButton`; //ensure vertices on good mesh are selected string $tj_mvp_selectedVerts[] = `ls -sl -fl`; //check something is selected... if (`size $tj_mvp_selectedVerts` <= 1) { warning "Please select the vertices on the GOOD mesh to match"; } else { string $tj_mvp_buffer[]; int $tj_mvp_numTokens = `tokenize $tj_mvp_selectedVerts[0] "." $tj_mvp_buffer`; //check vertex is on good mesh if ($tj_mvp_buffer[0] != $tj_mvp_goodMesh) { warning "Please select the vertices on the GOOD mesh to match"; } else { //verified good mesh verts are selected, so do the work finally. int $tj_mvp_vertCount = 0; for ($tj_mvp_v in $tj_mvp_selectedVerts) { //get point position float $tj_mvp_pointPosB[] = `pointPosition -w ($tj_mvp_v)`; //get name clear $tj_mvp_buffer; int $tj_mvp_numTokens = `tokenize $tj_mvp_v "." $tj_mvp_buffer`; //replace name to build new string string $tj_mvp_newV = ($tj_mvp_fixMesh+"."+$tj_mvp_buffer[1]); //feedback print ("\nFound good position of vert: "+$tj_mvp_v+" and moving there the vert "+$tj_mvp_newV); xform -ws -t $tj_mvp_pointPosB[0] $tj_mvp_pointPosB[1] $tj_mvp_pointPosB[2] $tj_mvp_newV ; $tj_mvp_vertCount ++; } //done, clean up print ("\n Successfully completed moving "+$tj_mvp_vertCount+" vertices..."); if ( `window -exists $tj_mvp_winName` ) { deleteUI -window $tj_mvp_winName; } changeSelectMode -object; select -r $tj_mvp_fixMesh; } } }