/*********************************************************** 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 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[]; int $tFound; $fidelity = 0.001; // Conta gli oggetti selezionati $selection = `ls -sl -fl`; $totalObjects = size($selection); textField -e -tx "" outputExport; // 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]; // 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 -l`; $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++; } } // 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] + "\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 ($totalObjects + "\n") outputExport; for($j = 0; $j < $totalObjects; $j ++) { // process edges $object = $selection[$j]; // Ricava la shape select $object; pickWalk -d down; $strs = `ls -sl -fl`; tokenize($strs[0], "|", $strs2); $curShapeName = $strs2[size($strs2)-1]; // Scrive le trasformazioni textField -e -it ($object + "\n" + $curShapeName + "\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; } // Aggiunge il conto delle shape diverse. Va messo qui, altrimenti dopo i nodi // di trasformazione vengono messi all'inizio. textField -e -ip 1 -it (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