/* This file downloaded from Highend3d.com '' '' Highend3d.com File Information: '' '' Script Name: pointsAverage v1.0 '' Author: Jin Kwon '' Last Updated: October 18, 2001 '' Update/Change this file at: '' http://www.highend3d.com/maya/mel/?section=modeling#957 '' '' Please do not alter any information above this line '' it is generated dynamically by Highend3d.com and will '' be changed automatically on any updates. */ // (C) 2001 Young Jin Kwon // // SCRIPT NAME: pointsAverage v1.0 // DATE CREATED: 10/2/2001. // WRITTEN AND TESTED ON: Maya 3.0/3.0a // DESCRIPTION: // It calculates an average point of the selected points, and moves the points // you also selected to the average point--which is similar to "TangentCVWin" // The difference is TangentCVWin only works with nurbs mesh cvs, but this mel // script works with any points from any number of objects in many different // types of nodes: // nurbs mesh cvs, curve cvs, poly vertices, lattice points, subDiv points. // HOW TO INSTALL : Open this script from the Script Editor, drag and drop into a Shelf. // HOW TO USE: (The same way you would do in TangentCVWin.mel.) // 1. Select points components to be reference points. // Press "Reference Points" button. // 2. Select points that you want to move to the average position of // the previously selected points. // Press "Points to move" button. // 3. Press "Make Points Tangent" button. //EXTRA COMMENT: This mel script also works with poly UVs. If the points you selected // to move are poly UVs, it will move the points to the average UV point // in UV coordinates, but not in world space. // For example, // If the "Points to move" are poly UVs and "Reference Points" are poly UVs, // then the points move to the average UV coordinates. // If the "Points to move" are other than poly UVs and "Reference Points" are poly UVs, // then the points move to the average xyz world space coordinates. proc string[] pointsSel () { string $result[] = `filterExpand -sm 28 -sm 31 -sm 35 -sm 36 -sm 46`; return ($result); clear ($result); } proc makeTangent (string $movePnts[], string $tangentPnts[]) { // double3 : curve/nurbs cvs, lattice points // float3 : poly vertices // float2 : poly uvs float $xAverage = 0.0; float $yAverage = 0.0; float $zAverage = 0.0; float $uAverage = 0.0; float $vAverage = 0.0; string $type[] = `ls -st $movePnts[0]`; if ($type[1] == "float2") // if it's a poly uv point { for ($pnt in $tangentPnts) { $currentUV = `polyEditUV -q $pnt`; $uAverage = $uAverage + $currentUV[0]; $vAverage = $vAverage + $currentUV[1]; }//for $uAverage = $uAverage/size ($tangentPnts); $vAverage = $vAverage/size ($tangentPnts); for ($pnt in $movePnts) polyEditUV -r false -u $uAverage -v $vAverage $pnt; }//if else // other than poly uvs { for ($pnt in $tangentPnts) { $currentPos = `pointPosition -w $pnt`; $xAverage = $xAverage + $currentPos[0]; $yAverage = $yAverage + $currentPos[1]; $zAverage = $zAverage + $currentPos[2]; } $xAverage = $xAverage/size ($tangentPnts); $yAverage = $yAverage/size ($tangentPnts); $zAverage = $zAverage/size ($tangentPnts); for ($pnt in $movePnts) move $xAverage $yAverage $zAverage $pnt; } clear($movePnts); clear($tangentPnts); } proc makePointsTangent () { $movePoints = `textScrollList -q -ai pointsMoveTextScrollList`; $tangentPoints = `textScrollList -q -ai pointsTangentTextScrollList`; makeTangent $movePoints $tangentPoints; } proc buildPointsTangent ( string $win ) { window -title "pointsAverage v1.0 by Jin 10/2/01" $win; columnLayout topCVWindowLayout; rowColumnLayout -nc 2 -cw 1 140 -cw 2 140 cvRowColumnLayout; button -w 140 -l "Points to move" pointsReloadLeftButton; button -w 140 -l "Reference Points" pointsReloadRightButton; textScrollList -w 140 -h 120 -nr 6 pointsMoveTextScrollList; textScrollList -w 140 -h 120 -nr 6 pointsTangentTextScrollList; setParent topCVWindowLayout; button -w 280 -l "Move Points To The Average Point" makeTangentButton; } proc loadPoints ( string $scrollList) { $selectedPoints = `pointsSel`; textScrollList -e -ra $scrollList; for ($item in $selectedPoints) { textScrollList -e -a $item -w 120 -h 120 $scrollList; } textScrollList -e -w 140 -h 120 $scrollList; } proc createCallBacksPointsWindow () { button -e -c "loadPoints \"pointsMoveTextScrollList\"" pointsReloadLeftButton; button -e -c "loadPoints \"pointsTangentTextScrollList\"" pointsReloadRightButton; button -e -c makePointsTangent makeTangentButton; } global proc pointsAverage () { $win = "pointsAverage"; if (!`window -exists $win`) { buildPointsTangent $win; createCallBacksPointsWindow; } showWindow $win; }; pointsAverage;