/*********************************************************** Esporta i file di Maya in Visual Basic, creando direttamente i comandi MakeVertex. Include normali e coordinate di mappatura. Funziona solo su Maya Unlimited o Complete (NON sulla Personal Learning Edition). ************************************************************/ global proc VBDXexport() { window -title "Export to Visual Basic" -w 400 -h 500; columnLayout -adjustableColumn true; button -l "Convert" -command "exportVertexToVBinField()"; scrollField -editable true -w 400 -h 300 outputExport; showWindow; } global proc exportVertexToVBinField() { float $x, $y, $z, $fidelity, $coords[], $normal[]; int $triNum[], $i, $totalNumF, $totalNumV, $j, $k, $l, $totalObjects, $oldNum, $newNum, $nextIdx; int $vertexNum[], $mode, $RealVertexPerFace[], $NextRealVertex; int $found, $nDiffN, $totDiffV; float $nX[], $nY[], $nZ[], $nUvU[], $nUvV[], $PUV[]; int $nV[]; string $object, $strs[], $selection[], $str, $loc, $selToDel, $fIdx[]; vector $n0, $n1, $n2; $fidelity = 0.001; $selection = `ls -sl -fl`; $totalObjects = size($selection); textField -e -tx "" outputExport; for($j = 0; $j < $totalObjects; $j ++) { // process edges $object = $selection[$j]; polyTriangulate $object; select $object; $vertexNum = `polyEvaluate -v`; $totalNumV = $vertexNum[0]; $triNum = `polyEvaluate -f`; $totalNumF = $triNum[0]; $totDiffV = 0; for($i = 0; $i < $totalNumV; $i++) { $str = $object+".vtx["+$i+"]"; select $str; $coords = `pointPosition`; $strs =`polyInfo -vf`; tokenize($strs[0], $fIdx); $nDiffN = 0; for($k = 2; $k < size($fIdx); $k++) { $str = $object+".vtxFace["+$i+"]["+$fIdx[$k]+"]"; select $str; $normal = `polyNormalPerVertex -q -xyz`; ConvertSelectionToUVs; $PUV = `polyEditUV -q`; $found = false; for($l = 0; $l < $nDiffN; $l++) { if(($normal[0]==$nX[$l]) && ($normal[1]==$nY[$l]) && ($normal[2]==$nZ[$l]) && ($PUV[0]==$nUvU[$l]) && ($PUV[1]==$nUvV[$l])) { $found = true; break; } } if($found) { $RealVertexPerFace[int($fIdx[$k]) * $totalNumV + $i] = $nV[$l]; } else { $nX[$nDiffN] = $normal[0]; $nY[$nDiffN] = $normal[1]; $nZ[$nDiffN] = $normal[2]; $nV[$nDiffN] = $totDiffV; $nUvU[$nDiffN] = $PUV[0]; $nUvV[$nDiffN] = $PUV[1]; $RealVertexPerFace[int($fIdx[$k]) * $totalNumV + $i] = $totDiffV; $nDiffN++; $totDiffV++; //print("[f"+$fIdx[$k]+"v"+$i+"]<"+string(int($fIdx[$k]) * $totalNumV + $i)+" "+$RealVertexPerFace[int($fIdx[$k]) * $totalNumV + $i] +">"); } } for($k = 0; $k < $nDiffN; $k++) { textField -e -ip 0 -it ("V("+$nV[$k]+")=MakeVertex("+$coords[0]+","+ $coords[1]+","+$coords[2]+ "," + $nX[$k] + "," + $nY[$k] + "," + $nZ[$k] + "," + $nUvU[$k] + "," + $nUvV[$k] + ")\n") outputExport; // print("V("+$nV[$k]+")=MakeVertex("+$coords[0]+","+$coords[1]+","+$coords[2]+ "," + // $nX[$k] + "," + $nY[$k] + "," + $nZ[$k] + ")\n"); } } $nextIdx = 0; for($i = 0; $i < $totalNumF; $i++) { $str = $object+".f["+$i+"]"; select $str; $strs =`polyInfo -fv`; tokenize($strs[0], $fIdx); textField -e -ip 0 -it ("I("+$nextIdx+")="+$RealVertexPerFace[$i * $totalNumV + int($fIdx[2])]+ ": I("+string($nextIdx+1)+")="+$RealVertexPerFace[$i * $totalNumV + int($fIdx[3])]+ ": I("+string($nextIdx+2)+")="+$RealVertexPerFace[$i * $totalNumV + int($fIdx[4])]+"\n") outputExport; // print("I("+$nextIdx+")="+$RealVertexPerFace[$i * $totalNumV + int($fIdx[2])]+ // ": I("+string($nextIdx+1)+")="+$RealVertexPerFace[$i * $totalNumV + int($fIdx[3])]+ // ": I("+string($nextIdx+2)+")="+$RealVertexPerFace[$i * $totalNumV + int($fIdx[4])]+"\n"); $nextIdx+=3; //print("[f"+$i+"v"+$fIdx[2]+"]<"+string($i * $totalNumV + int($fIdx[2]))+"["+$RealVertexPerFace[$i * $totalNumV + int($fIdx[2])]+"]~"); //print("[f"+$i+"v"+$fIdx[3]+"]"+string($i * $totalNumV + int($fIdx[3]))+"["+$RealVertexPerFace[$i * $totalNumV + int($fIdx[3])]+"]~"); //print("[f"+$i+"v"+$fIdx[4]+"]"+string($i * $totalNumV + int($fIdx[4]))+"["+$RealVertexPerFace[$i * $totalNumV + int($fIdx[4])]+"]>"); } select $object; textField -e -ip 1 -it ("ReDim V("+$totDiffV+"), I("+$nextIdx+")\n") outputExport; // print("ReDim V("+$totDiffV+"), I("+$nextIdx+")\n"); } } // ConvertSelectionToUVs -> Trasforma la selezione in UV // PolyEditUV -q -> restituisce le coordinate UV del vertice selezionato.