PDA

View Full Version : polygon duplicate/writing/output/rebuilder something script... here ya go... :)


strarup
11-08-2007, 08:41 AM
hi,

a long time ago when I went to the 3d animation course on the Animation Workshop in Viborg Denmark...
I was trying out the ragdoll tutorial which I wanted to throw onto a character...
however when I mirrored and duplicated the polygon objects to the other side... e.g. an arm object...
I got some strange behaviour on the dynamics from the tutorial...
after remodelling the arm object... I got pretty tired of that.. and thought there most be a much better way to do this...
sometimes lazyness rules... :D

so here you go... a kind of rebuild polygon object script... you can rebuild your polygon object... save it as
a melscript file... which produces a script with which you can recreate your polygon object...
it does has some problems if a face has a hole or 2 in it... to rebuild it correctly...

regards

Strarup


/* ////////////////////////////////////////////////////////////////////////////////////////////
''
'' Script Name: get Poly Build Info version 0.5 beta
'' Author: Alex V. U. Strarup
'' E-mail: 3d@strarup.net (http://forums.cgsociety.org/3d@strarup.net)
'' Web-site: http://www.strarup.net
'' Created: 21. sep. 2003
'' Last Updated: 6. nov. 2007
''
*/ ////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////
//
// DESCRIPTION : this script prints out the "build info" of an Polygon object into
// the scripteditor...
// it also has the posibility to either rebuild it, or save the data as
// a melfile to the Maya Mel Script folder...
// as long the polygon object doesn't have any "holes" in a face...
//
//////////////////////////////////////////////////////////////////////////////////////////////
//
// Installation: put the script in the Maya script folder...
// to activate the script, type daPolyBuildInfoUI;
//
//////////////////////////////////////////////////////////////////////////////////////////////
//
// Conditions : Use at your own risk, No Banana throwing or whatever if it doesn't work...
// copy... steal... modify it... do whatever you want...
// as long you don't call me up early in the morning... :-)
//
//////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////// Start of Script /////////////////////////////////////

global proc daPolyBuildInfoUI()
{

if (`window -exists daPolyBuildInfoWindowUI`)
deleteUI daPolyBuildInfoWindowUI;

//create the get Poly Build Info GUI...
window -wh 280 120 -rtf true -t "Da Poly Build Info UI" daPolyBuildInfoWindowUI;
columnLayout -co "both" 10 -rs 10 -adj false daPBICoL;
frameLayout -cll false -l " get the Poly Build Info..." -w 260 -mh 10 -mw 10 gPolyInfoFl;
button -l "Print Poly Build Info" -c "getPolyBuildInfo(0);" gPolyInfoB;
setParent ..;
frameLayout -collapsable true -label "rebuild polyobject..." -width 260 -mh 10 -mw 10 rPolyInfoFl;
rowLayout -columnWidth2 60 200 -numberOfColumns 2;
button -en false -l "rebuild" -c "getPolyBuildInfo(1);" rPolyInfoB;
textField -w 200 -ed false rbPObjName;
setParent ..;
setParent ..;
frameLayout -cll true -l " save the Poly Build Info..." -w 260 -mh 10 -mw 10 sPolyInfoFl;
button -en false -l "save Poly Build Info" -c "getPolyBuildInfo(2);" sPolyInfoB;
setParent ..;
showWindow daPolyBuildInfoWindowUI;
}
//daPolyBuildInfoUI;

global proc getPolyBuildInfo(int $action)
{
string $daPolyList[], $daPoly[], $daPolyName[];

$daPolyList = `ls -dag -sl -type mesh`;
$daPoly = doDaFlattenPolyArray($daPolyList);
$daPolyName = doDaGetDaTypeFromSelection("transform");
if(size( $daPolyList ) < 1 )
{
error( "no polygon objects selected for this test." );
}

string $daCurPoly; //current selected poly object
int $i, $j;
string $daCurFace; //current selected face...
string $daFertexx[]; //selected face vertex...
int $daFacesNum[], $daNumVerts;
string $daVtxFace[], $daFertexxOrder[];

for( $j = 0; $j < size ($daPoly); $j++ ) //run this for every selected polyobject...
{
string $reCreatePoly[];
$daCurPoly = $daPoly[$j];
$daFacesNum = `polyEvaluate -f $daCurPoly`; //get the number of faces for the selected object...
for($i = 0;$i < $daFacesNum[0];$i++ )
{
$daCurFace = ($daCurPoly +".f["+$i+"]");
$daFertexxOrder = doDaVtxOrderFromDaVtxFaceFromDaFace($daCurFace);
$daFertexx = `listAttr $daFertexxOrder`;
$daNumVerts = size($daFertexx)/4;
string $reCreatePolyStr;
$reCreatePolyStr = daReCreatePolyStr($daCurPoly, $daFertexx, $daNumVerts, $i);
clear ($daFertexxOrder);
$reCreatePoly[$i] = $reCreatePolyStr;
}
clear ($daFertexxOrder);
if($action == 0)//print out data...
{
print($reCreatePoly);
print("//-------------------------------------------------------------//\n"); //seperation line
textField -e -tx ($daPolyName[0]+"_Copy") rbPObjName;
button -e -en true rPolyInfoB;
button -e -en true sPolyInfoB;
textField -e -ed true rbPObjName;
}
else if($action == 1)//rebuild data
{
int $daRBSize = `size($reCreatePoly)`;
int $rb=0;
for($rb=0; $rb< $daRBSize; $rb++ )
{
eval($reCreatePoly[$rb]);
}
if($rb=$daRBSize)
{
select "daFP_Obj*";
string $daRB_PolyFaces[] = doDaGetDaTypeFromSelection("transform");
select -cl;
//get the name for the new recreated/rebuilded polyobject...
string $daReBuildObj = `textField -q -tx rbPObjName`;
polyUnite -ch off -n $daReBuildObj $daRB_PolyFaces;
polySewEdge -t 0.0 -tx 1 -ws 1 -ch 0 $daReBuildObj;
polyMergeVertex -d 0.0001 -ch 1 $daReBuildObj;
xform -cp $daReBuildObj;
DeleteHistory $daReBuildObj;
select -cl;
}
}
else if($action == 2)//save data
{
string $daReBuildObj = `textField -q -tx rbPObjName`;
int $daWBISize = `size($reCreatePoly)`;
int $wbi=0;

string $daWBIpf = "";

for($wbi=0; $wbi< $daWBISize; $wbi++ )
{
string $currWBI_obj = $reCreatePoly[$wbi];
$daWBIpf = $daWBIpf+$currWBI_obj;
}
string $rbCMDstr="\n\tselect \"daFP_Obj*\"; \n"+"\tstring $daRB_PolyFaces[] = `ls -sl -type transform`; \n"+"\tselect -cl; \n\n"+"\t//get the name for the new recreated/rebuilded polyobject... \n"+"\tpolyUnite -ch off -n "+$daReBuildObj+" $daRB_PolyFaces; \n"+"\tpolySewEdge -t 0.0 -tx 1 -ws 1 -ch 0 "+$daReBuildObj+"; \n"+"\tpolyMergeVertex -d 0.0001 -ch 1 "+$daReBuildObj+"; \n"+"\txform -cp "+$daReBuildObj+"; \n"+"\tDeleteHistory "+$daReBuildObj+"; \n"+"\tselect -cl; \n ";
string $daRB_mel_Str="global proc "+$daReBuildObj+"() \n{ \n"+$daWBIpf+$rbCMDstr+"\n} \n";
string $rbDir = `internalVar -usd`;
string $rbFileName = ( `internalVar -usd` +""+$daReBuildObj+".mel" );
int $rbId=`fopen $rbFileName "w"`;
fwrite $rbId $daRB_mel_Str;
fclose $rbId;
button -e -en false sPolyInfoB;
//print("File: "+$rbFileName+" Saved in: "+$rbDir+"\n");
}
}
}

global proc string daReCreatePolyStr(string $daCurPoly, string $daFertexx[], int $daNumVerts, int $daPolyNr)
{
string $reCreatePolyStr = ("\tpolyCreateFacet -n daFP_Obj"+$daPolyNr);
string $daTmpStr = "";
int $daIndex = 0;
float $daVpos[];
for($i=0; $i< $daNumVerts; $i++)
{
$daVpos = `pointPosition ($daCurPoly + "." + $daFertexx[$daIndex])`;
$reCreatePolyStr += " -p "+$daVpos[0]+" "+$daVpos[1]+" "+$daVpos[2]+"";
$daIndex = ($daIndex+4);
}
return ($reCreatePolyStr+" ; \n");
}

global proc string[] doDaVtxOrderFromDaVtxFaceFromDaFace(string $daFace)
{
string $daVtxFace[] = doDaGetVtxFaceFromDaFace($daFace);
string $daVertexOrderList[];
for($daVF in $daVtxFace)
{
string $daVertex[] = doDaGetVtxFromDaVtxFace($daVF);
$daVertexOrderList[size($daVertexOrderList)] = $daVertex[0];
}
return $daVertexOrderList;
}

global proc string[] doDaGetVtxFaceFromDaFace(string $daFace)
{
return doDaFlattenVtxFaceArray(`polyListComponentConversion -ff -tvf $daFace`);
}

global proc string[] doDaGetVtxFromDaVtxFace(string $daVtxFace)
{
return doDaFlattenVertexArray(`polyListComponentConversion -fvf -tv $daVtxFace`);
}

global proc string[] doDaFlattenPolyArray(string $daArray[])
{
return (`filterExpand -sm 12 -ex true $daArray`);
}

global proc string[] doDaFlattenVertexArray(string $daArray[])
{
return (`filterExpand -sm 31 -ex true $daArray`);
}

global proc string[] doDaFlattenVtxFaceArray(string $daArray[])
{
return (`filterExpand -sm 70 -ex true $daArray`);
}

global proc string[] doDaGetDaTypeFromSelection(string $daType)
{
return `ls -sl -type $daType`;
}
///////////////////////////////////// End of Script /////////////////////////////////////

kojala
11-20-2007, 07:26 AM
hm so the main problem was that when you duplicated and mirrored a hand object to the other side you had strange behaviour on dynamics...

did you tried reversing the normals?

did you actually duplicate and scaled to -1 ?
if you did, why didnt you used the mirror geometry tool ?

sabathyus
11-21-2007, 06:10 AM
What Kajala said:

polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -tx 1 -ch 1;
move -r -os -wd 0 3 0 ;
move -r -os -wd 2 0 0 ;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 pCube1;
ResetTransformations;
duplicate pCube1;
setAttr "pCube2.scaleX" -1;
polyNormal -normalMode 4 -ch 1 pCube2;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 pCube2;
select -cl;

strarup
03-05-2008, 06:41 AM
hi,


hmm... well good question... can't remember was back in 2003 and with maya 5... :D

did use the mirror tool whereafter I then used the script to rebuild it... after trying a lot of different stuff that didn't make it work... but regarding the normals I can't remember... :)

however that was back then... and now I just wanted to share the script from back then that has been updated... :)

kind regards

Strarup

CGTalk Moderation
03-05-2008, 06:41 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.