/*********************************************************** Esporta i file di Maya in Visual Basic. Esporta solo le coordinate: e' fatto per creare file da caricare da Visual Basic. Include normali e coordinate di mappatura. Funziona solo su Maya Unlimited o Complete (NON sulla Personal Learning Edition). ************************************************************/ global proc VBDXexport() { window -title "Export a Character 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[], $trA[]; int $nV[]; string $object, $strs[], $selection[], $str, $loc, $selToDel, $fIdx[], $oneObj, $strs2[]; string $shapeNames[], $curShapeName, $nodes[]; vector $n0, $n1, $n2; float $M_color[], $M_diS, $M_diffuse[], $M_emissive[], $M_specular[], $M_cos, $M_ambient[]; string $aName, $textureName, $M_Def, $tConnAttr[], $strs3[]; string $trObjs[], $firstSon, $firstBrother, $elderBrother; string $skinCluster[], $skV1; string $affectingTn[], $skeleton, $sSkinW, $jOAttr; float $SkinW[], $TempW; int $SkinTN[], $TempTN; float $JOr[], $bindPose[]; int $totalTrObjs; int $tFound; int $maxTN; $fidelity = 0.001; $maxTN = 4; // Conta gli oggetti selezionati $selection = `ls -sl -fl -s -dag -ni`; $totalObjects = size($selection); $trObjs = `ls -sl -fl -tr -dag -ni`; $totalTrObjs = size($trObjs); textField -e -tx "" outputExport; // Cerca di capire la pelle associata if($totalObjects < 1) return; $skinCluster = `ls -typ skinCluster`; if(size($skinCluster) != 1) { textField -e -tx ("Error: there are " + size($skinCluster) + " skinClusters") outputExport; return; } $skV1 = $selection[0] + ".vtx[0]"; $affectingTn = `skinPercent -q -t $skinCluster[0] $skV1`; $skeleton = size($affectingTn) + "\n"; for($i = 0; $i < size($affectingTn) ; $i++) { $jOAttr = $affectingTn[$i] + ".jo"; $JOr = `getAttr $jOAttr`; $jOAttr = $affectingTn[$i] + ".bps"; $bindPose = `getAttr $jOAttr`; $skeleton = $skeleton + "\"" + $affectingTn[$i] + "\"" + "\n" + $JOr[0] + "," + $JOr[1] + "," + $JOr[2] + "\n" + $bindPose[0] + "," + $bindPose[1] + "," + $bindPose[2] + "," + $bindPose[3] + "\n" + $bindPose[4] + "," + $bindPose[5] + "," + $bindPose[6] + "," + $bindPose[7] + "\n" + $bindPose[8] + "," + $bindPose[9] + "," + $bindPose[10] + "," + $bindPose[11] + "\n" + $bindPose[12] + "," + $bindPose[13] + "," + $bindPose[14] + "," + $bindPose[15] + "\n"; } // Per ogni oggetto selezionato for($j = 0; $j < $totalObjects; $j ++) { $object = $selection[$j]; polyTriangulate $object; // Trova la sua shape select $object; /* pickWalk -d down; * $strs = `ls -sl -fl`; * tokenize($strs[0], "|", $strs2); * $curShapeName = $strs2[size($strs2)-1]; */ tokenize($object, "|", $strs2); $curShapeName = $strs2[size($strs2)-1]; // Controlla che non sia gia' stata salvata $found = false; for($l = 0; $l < size($shapeNames); $l++) { if($shapeNames[$l] == $curShapeName) { $found = true; break; } } if($found) continue; // Se non e' stata salvata, la aggiunge $shapeNames[size($shapeNames)] = $curShapeName; // Conta vertici e facce diverse $vertexNum = `polyEvaluate -v`; $totalNumV = $vertexNum[0]; $triNum = `polyEvaluate -f`; $totalNumF = $triNum[0]; $totDiffV = 0; $oneObj = ""; // Esamina i materiali // Prende tutti i nodi collegati $nodes = `listConnections -s false $curShapeName`; // Cerca lo ShadingGroup $found = false; for($i = 0; $i < size($nodes); $i++) { $strs = `ls -st $nodes[$i]`; if($strs[1] == "shadingEngine") { $found = true; break; } } // Se lo trova cerca un matriale lambert o phong if($found) { $found = false; $nodes = `listConnections -d false $strs[0]`; for($i = 0; $i < size($nodes); $i++) { $strs = `ls -st $nodes[$i]`; if(($strs[1] == "lambert" ) || ($strs[1]=="phong")) { $found = true; break; } } // Se trota il materiale, allora lo scrive tale e quale if($found) { // Cerca se c'e' la texture. $aName = $strs[0]+".color"; $tConnAttr = `listConnections -c true $aName`; if(size($tConnAttr) == 0) { // No texture $aName = $strs[0]+".color"; $M_color = `getAttr $aName`; $aName = $strs[0]+".diffuse"; $M_diS = `getAttr $aName`; $M_diffuse[0] = $M_color[0] * $M_diS; $M_diffuse[1] = $M_color[1] * $M_diS; $M_diffuse[2] = $M_color[2] * $M_diS; $textureName = ""; } else { $M_diffuse[0] = 1; $M_diffuse[1] = 1; $M_diffuse[2] = 1; $strs3 = `ls -st $tConnAttr[1]`; if($strs3[1] == "file") { $aName = $strs3[0]+".fileTextureName"; $textureName = `getAttr $aName`; $textureName = basename($textureName, ""); } else $textureName = ""; } $aName = $strs[0]+".ambientColor"; $M_ambient = `getAttr $aName`; $aName = $strs[0]+".incandescence "; $M_emissive = `getAttr $aName`; // se e' un phong, allora ha anche la componente speculare if($strs[1]=="phong") { $aName = $strs[0]+".specularColor"; $M_specular = `getAttr $aName`; $aName = $strs[0]+".cosinePower"; $M_cos = `getAttr $aName`; } else { $M_specular[0] = 0; $M_specular[1] = 0; $M_specular[2] = 0; $M_cos = 20; } } } // Se non trova il materiale, lo imposta di default if(!$found) { $M_emissive[0] = 1; $M_emissive[1] = 1; $M_emissive[2] = 1; $M_ambient[0] = 1; $M_ambient[1] = 1; $M_ambient[2] = 1; $M_diffuse[0] = 1; $M_diffuse[1] = 1; $M_diffuse[2] = 1; $M_specular[0] = 0; $M_specular[1] = 0; $M_specular[2] = 0; $M_cos = 20; } // Stampa il materiale $M_Def = "\"" + $textureName + "\"\n" + $M_emissive[0] + "," + $M_emissive[1] + "," + $M_emissive[2] + "\n" + $M_ambient[0] + "," + $M_ambient[1] + "," + $M_ambient[2] + "\n" + $M_diffuse[0] + "," + $M_diffuse[1] + "," + $M_diffuse[2] + "\n" + $M_specular[0] + "," + $M_specular[1] + "," + $M_specular[2] + "," + $M_cos + "\n"; // Stampa i vertici for($i = 0; $i < $totalNumV; $i++) { $str = $object+".vtx["+$i+"]"; select $str; $coords = `pointPosition -w`; $strs =`polyInfo -vf`; tokenize($strs[0], $fIdx); $nDiffN = 0; // Conrolla quante normali-UV diverse ha questo verice for($k = 2; $k < size($fIdx); $k++) { //Ricava le normali $str = $object+".vtxFace["+$i+"]["+$fIdx[$k]+"]"; select $str; $normal = `polyNormalPerVertex -q -xyz`; //Ricava le coordinate UV ConvertSelectionToUVs; $PUV = `polyEditUV -q`; // Controlla se sono nuove $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; } } // Se sono nuove, aggiunge un vertice, altrimenti riusa il vecchio 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++; } } $str = $object+".vtx["+$i+"]"; $SkinW = `skinPercent -q -v $skinCluster[0] $str`; $sSkinW = ""; for($k = 0; $k < size($SkinW); $k++) $SkinTN[$k] = $k; for($k = 0; $k < $maxTN; $k++) { for($l = $k+1; $l < size($SkinW); $l++) { if($SkinW[$l] > $SkinW[$k]) { $TempW = $SkinW[$k]; $SkinW[$k] = $SkinW[$l]; $SkinW[$l] = $TempW; $TempTN = $SkinTN[$k]; $SkinTN[$k] = $SkinTN[$l]; $SkinTN[$l] = $TempTN; } } $sSkinW = $sSkinW + "," + $SkinTN[$k] + "," + $SkinW[$k]; } //print($SkinW); // Stampa un vertice diverso per ogni normale-UV differente for($k = 0; $k < $nDiffN; $k++) { $oneObj = $oneObj + $coords[0]+","+ $coords[1]+","+$coords[2]+ "," + $nX[$k] + "," + $nY[$k] + "," + $nZ[$k] + "," + $nUvU[$k] + "," + $nUvV[$k] + $sSkinW + "\n"; } } // Stampa i triangoli $nextIdx = 0; for($i = 0; $i < $totalNumF; $i++) { $str = $object+".f["+$i+"]"; select $str; $strs =`polyInfo -fv`; tokenize($strs[0], $fIdx); $oneObj = $oneObj + $RealVertexPerFace[$i * $totalNumV + int($fIdx[2])]+ ","+$RealVertexPerFace[$i * $totalNumV + int($fIdx[3])]+ ","+$RealVertexPerFace[$i * $totalNumV + int($fIdx[4])]+"\n"; $nextIdx+=3; } // Aggiunge il numero di vertici-spigoli di questo oggetto textField -e -it ($curShapeName+"\n"+$M_Def+$totDiffV+","+$nextIdx+"\n"+$oneObj) outputExport; } // Considera adesso i nodi di trasformazione textField -e -it ($totalTrObjs + "\n") outputExport; for($j = 0; $j < $totalTrObjs; $j ++) { // process edges $object = $trObjs[$j]; // Ricava la shape select $object; pickWalk -d down; $strs = `ls -sl -fl -s -ni`; if(size($strs) > 0) { tokenize($strs[0], "|", $strs2); $curShapeName = $strs2[size($strs2)-1]; } else $curShapeName = ""; // Ricava il primo figlio if($curShapeName != "") // Ci si sposta a destra solo se il primo nodo figlio era una shape pickWalk -d right; $strs = `ls -sl -fl -tr -ni`; if(size($strs) > 0) { tokenize($strs[0], "|", $strs2); $firstSon = $strs2[size($strs2)-1]; // Controlla che sia tra gli oggetti che si vogliono esportare for($k = 0; $k < $totalTrObjs; $k++) if($trObjs[$k] == $firstSon) break; if($k >= $totalTrObjs) $firstSon = ""; } else $firstSon = ""; // Ricava il primo fratello select $object; pickWalk -d right; $strs = `ls -sl -fl -tr -ni`; if(size($strs) > 0) { tokenize($strs[0], "|", $strs2); $firstBrother = $strs2[size($strs2)-1]; // Controlla che sia tra gli oggetti che si vogliono esportare for(;;) { for($k = 0; $k < $totalTrObjs; $k++) if($trObjs[$k] == $firstBrother) break; if($k < $totalTrObjs) break; pickWalk -d right; $strs = `ls -sl -fl -tr -ni`; tokenize($strs[0], "|", $strs2); $firstBrother = $strs2[size($strs2)-1]; } // Controlla che non si sia ritornati al primo figlio pickWalk -d up; pickWalk -d down; $strs = `ls -sl -fl -tr -ni`; tokenize($strs[0], "|", $strs2); $elderBrother = $strs2[size($strs2)-1]; if($firstBrother == $elderBrother) $firstBrother = ""; // Controlla che non si sia tornati al primo transform node if($firstBrother == $trObjs[0]) $firstBrother = ""; } else $firstBrother = ""; // Scrive le trasformazioni textField -e -it ($object + "\n\"" + $curShapeName + "\"\n\"") outputExport; textField -e -it ($firstSon + "\"\n\"" + $firstBrother + "\"\n") outputExport; select $object; $trA = `getAttr .t`; textField -e -it ($trA[0] + "," + $trA[1] + "," + $trA[2] + "\n") outputExport; $trA = `getAttr .r`; textField -e -it ($trA[0] + "," + $trA[1] + "," + $trA[2] + "\n") outputExport; $trA = `getAttr .s`; textField -e -it ($trA[0] + "," + $trA[1] + "," + $trA[2] + "\n") outputExport; $trA = `getAttr .rp`; textField -e -it ($trA[0] + "," + $trA[1] + "," + $trA[2] + "\n") outputExport; } // Aggiunge il conto delle shape diverse. Va messo qui, altrimenti dopo i nodi // di trasformazione vengono messi all'inizio. textField -e -ip 1 -it ($skeleton + size($shapeNames) + "\n") outputExport; } // listConnections >> elenca le connessioni // listConnections -s false ->sullo shape >> identifica i nodi a cui questo e' collegato // ls -st $obj >> Scrive il tipo dell'oggetto selezionato - [shadingEngine] per quelli che contengono // i dati per il rendering