FA所用的sum exporter for maya。以前写的,贴出来

proc WriteComponentDataToFile(string $obj,int $hFile)
{
print(“exporting " + $obj + “\n”);
fprint $hFile (”[“+$obj+”]\n");
string $tempstrlist[] = listRelatives -p $obj;
string $parentobj=$tempstrlist[0];

///输出Parent名字
fprint $hFile (“Parent=”+$parentobj+“\n”);

///输出参照系偏移
float $pivotoffset[]=pointPosition -w ($obj+".rotatePivot");
float $parentpivotoffset[3];

if($parentobj==“”)
{
$parentpivotoffset[0]=0;
$parentpivotoffset[1]=0;
$parentpivotoffset[2]=0;
}
else
{
$parentpivotoffset =pointPosition -w ($parentobj+".rotatePivot");
}

float $ObjPivotOffset[3];
$ObjPivotOffset[0]=$pivotoffset[0]-$parentpivotoffset[0];
$ObjPivotOffset[1]=$pivotoffset[1]-$parentpivotoffset[1];
$ObjPivotOffset[2]=$pivotoffset[2]-$parentpivotoffset[2];

fprint $hFile (“Offset=”+string($ObjPivotOffset[0])+“,” +string($ObjPivotOffset[1])+“,”+string($ObjPivotOffset[2]) +“\n”);

float $Rotation[3];
string $strrotatesel;
$strrotatesel=$obj+“.rotateX”;
$Rotation[0]=getAttr $strrotatesel;

$strrotatesel=$obj+“.rotateY”;
$Rotation[1]=getAttr $strrotatesel;

$strrotatesel=$obj+“.rotateZ”;
$Rotation[2]=getAttr $strrotatesel;

///// Set Rotation to 0
$strrotatesel=$obj+“.rotateX”;
setAttr $strrotatesel 0;

$strrotatesel=$obj+“.rotateY”;
setAttr $strrotatesel 0;

$strrotatesel=$obj+“.rotateZ”;
setAttr $strrotatesel 0;
//// Set Rotation to 0

fprint $hFile (“rotation=”+string($Rotation[0])+“,” +string($Rotation[1])+“,”+string($Rotation[2]) +“\n”);

select -r $obj;
///
int $tempret[] = polyEvaluate -uv ;
int $UVCount=$tempret[0];
print(“UVCount=”+$UVCount+“\n”);
fprint $hFile ($UVCount+“\n”);

string $UVQuiry;

int $UVIndex;
for($UVIndex=0;$UVIndex<$UVCount;$UVIndex++)
{
$UVQuiry = $obj + “.map[” + $UVIndex + “]”;

///取UV
float $uv[]=polyEditUV -q $UVQuiry;
$uv[1]=1-$uv[1];

select -r $UVQuiry;

string $retstrlist[];
$retstrlist = polyListComponentConversion -fuv -tv;
///根据UV求对应Vtx

///取vtx坐标
string $VtxQuiry;
$VtxQuiry=$retstrlist[0];

float $vertex_temp[];
$vertex_temp = pointPosition -world $VtxQuiry;
$vertex_temp[0]=$vertex_temp[0]-$pivotoffset[0];
$vertex_temp[1]=$vertex_temp[1]-$pivotoffset[1];
$vertex_temp[2]=$vertex_temp[2]-$pivotoffset[2];

///取法向
select -r $VtxQuiry;
float $Normals[] = polyNormalPerVertex -q -xyz;

string $output=$vertex_temp[0] + “,” + $vertex_temp[1] + “,”+ $vertex_temp[2]+ “;” + $uv[0]+“,” + $uv[1]+“;”+ $Normals[0] + “,” +$Normals[1] + “,” +$Normals[2] + “\n”;
fprint $hFile ($output);
}

////从面开始
select -r $obj;
string $f2v[]=polyInfo -faceToVertex;
////f2v每一行都存有每个面的顶点
int $faceCount = size $f2v ;

int $faceIndex;
// int $FaceVtxIndex[3];

print(“faceCount = “+$faceCount+”\n”);
fprint $hFile ($faceCount+“\n”);

for ( $faceIndex = 0; $faceIndex < $faceCount; $faceIndex++ )
{
select -r $obj;

string $FaceQuiry = $obj+“.f[” + $faceIndex + “]”;
// print($FaceQuiry+“\n”);
select -r $FaceQuiry;

select -r polyListComponentConversion -ff -tvf;
string $FaceVtxList[];

$FaceVtxList = filterExpand -ex true -sm 70;
int $FaceVtxUVIndex[3];
string $UVQuiry[];
string $tempstr;

select -r $FaceVtxList[0];
$UVQuiry = polyListComponentConversion -fvf -tuv;
// print($UVQuiry[0]+“\n”);
$tempstr = match "\[[0-9]+\]" $UVQuiry[0];
$FaceVtxUVIndex[0] = match "[0-9]+" $tempstr;

select -r $FaceVtxList[1];
$UVQuiry = polyListComponentConversion -fvf -tuv;
// print($UVQuiry[0]+“\n”);
$tempstr = match "\[[0-9]+\]" $UVQuiry[0];
$FaceVtxUVIndex[1] = match "[0-9]+" $tempstr;

select -r $FaceVtxList[2];
$UVQuiry = polyListComponentConversion -fvf -tuv;
$tempstr = match "\[[0-9]+\]" $UVQuiry[0];
$FaceVtxUVIndex[2] = match "[0-9]+" $tempstr;

fprint $hFile ($FaceVtxUVIndex[0] + “,” + $FaceVtxUVIndex[1]+ “,” +$FaceVtxUVIndex[2]+“\n”);
}

///// Restore Rotation
$strrotatesel=$obj+“.rotateX”;
setAttr $strrotatesel $Rotation[0];

$strrotatesel=$obj+“.rotateY”;
setAttr $strrotatesel $Rotation[1];

$strrotatesel=$obj+“.rotateZ”;
setAttr $strrotatesel $Rotation[2];
//// Set Rotation
// polyQuad -a 30 -kgb 1 -ktb 1 -khe 1 -ws 1 -ch 1 $obj;

}
proc int CheckObjValid(string $obj)
{
string $tempstr = match "Shape" $obj;
if($tempstr==“”)
return 1;
else
return 0;
}
////文件打开
string $FileName = fileDialog -m 1 -dm "*.sum";
string $tempstr = match "\.sum" $FileName;
if($tempstr == “”)
{
$FileName = $FileName + “.sum”;
}
print($FileName + " is the dest file\n");
int $hFile = fopen $FileName "w";
frewind $hFile;
////文件打开
string $objs[] = ls -sl ;
string $baseobj = $objs[0];
WriteComponentDataToFile($baseobj,$hFile);
fflush $hFile;
$objs = listRelatives -ad $baseobj;

$objindex=0;
int $objCount = size $objs;
string $obj;
print(“objcount = “+$objCount +”\n”);
for($obj in $objs)
{
print($obj + “\n”);
}
for($objindex = $objCount-1; $objindex>=0 ; $objindex–)
{
if( CheckObjValid($objs[$objindex]) ==0 )
{
print($objs[$objindex] + " is not a valid export obj, skipped\n");
continue;
}

WriteComponentDataToFile($objs[$objindex] , $hFile);
fflush $hFile;
}

东西先放在这里。以后有时间再来写说明和注意事项。

我一窍不通:P

:L 这就是传说中的SUlbon Model文件。。。
:Q 为啥不用诸如obj的格式?