Jump to content
bn-top

Script di copia UV


70MadMax
 Share

Recommended Posts

Ciao di nuovo,

come al solito mi servono cose che sono sempre leggermente diverse da quelle che trovo...e mi tocca rifarmele...

Modello, texturizzo, riggo, animo...poi mi accorgo che le uv andavano meglio in un'altra maniera, ma se le copio con i mezzi (che conosco...quindi non è detto che non si possa) di Maya, mi si crea una history e sono costretto a tenere il collegamento con la mesh da cui ho copiato le nuove UV.

Allora ho fatto uno script che mi copia le UV tra due mesh identiche...

Il codice è stato scritto molto velocemente, e è sicuramente da migliorare per evitare doppi controlli ecc...ecc...però pare che funziona, e per ora mi accontento...se vi interessa e se non trovate come me di meglio...

max_CopyUV

Ciao a tutti...

Link to comment
Share on other sites

bn-top
  • 4 years later...

Ciao...lieto che ancora qualcosa di mio sia di interesse :) oltretutto neanche ricordavo più di averlo scritto, tanto che tempo fa avevo trovato questa più che valida alternativa:

 

https://gabnation.wordpress.com/2010/02/09/how-to-transfer-uvs-after-rigging/

 

comunque, visto che il sito è down, copio lo script qui, ti basta fare un copia e incolla:


global string $gMainProgressBar;  // This is defined on maya startup
string $saObject[] = `ls -sl`;
max_CopyUV($gMainProgressBar, $saObject[0], $saObject[1]);
proc max_CopyUV(string $gMainProgressBar, string $sMainObject, string $sSecondObject) {
    int $iEdges = getMeshEdges($sSecondObject);
    polyMapCut ($sSecondObject + ".e[0:" + $iEdges + "]");
    int $iFaces = getMeshFaces($sMainObject);
    progressBar -edit
        -beginProgress
        -isInterruptable false
        -status "Copying UVs ..."
        -maxValue $iFaces
        $gMainProgressBar;
    int $iCounter = 0;
    int $i;
    for($i = 0; $i < $iFaces; $i++) {
        copyUV_proc($sMainObject, $sSecondObject, $i);
        $iCounter++;
        if($iCounter < 10) continue;
        $iCounter = 0;
        progressBar -edit
            -step 10 $gMainProgressBar;
    }
    progressBar -edit
        -endProgress
        $gMainProgressBar;
    
    progressBar -edit
        -beginProgress
        -isInterruptable false
        -status "Sewing Edges..."
        -maxValue $iFaces
        $gMainProgressBar;
    
    $iCounter = 0;
    for($i = 0; $i < $iFaces; $i++) {
        copyUV_mainFace_proc($sMainObject, $sSecondObject, $i);
        $iCounter++;
        if($iCounter < 10) continue;
        $iCounter = 0;
        progressBar -edit
            -step 10 $gMainProgressBar;
    }
    progressBar -edit
        -endProgress
        $gMainProgressBar;
    
}
proc copyUV_proc(string $sMainObject, string $sSecondObject, int $iFace) {
    int $iaVertices[] = getVerticesFromFace(($sMainObject + ".f[" + $iFace + "]"));
    int $iVertices = size($iaVertices);
    int $i;
    for($i = 0; $i < $iVertices; $i++) {
        int $iUV = getUVFromVertexFace($sMainObject, $iFace, $iaVertices[$i]);
        float $faUVPos[] = getUVPosFromUV(($sMainObject + ".map[" + $iUV + "]"), 4);
        $iUV = getUVFromVertexFace($sSecondObject, $iFace, $iaVertices[$i]);
        polyEditUV -r false -u $faUVPos[0] -v $faUVPos[1] ($sSecondObject + ".map[" + $iUV + "]");
    }
}
proc copyUV_mainFace_proc(string $sMainObject, string $sSecondObject, int $iFace) {
    int $iaFaceEdges[] = getEdgesFromFace(($sMainObject + ".f[" + $iFace + "]"));
    int $iFaceEdges = size($iaFaceEdges);
    
    int $i;
    for($i = 0; $i < $iFaceEdges; $i++) {
        copyUV_mainFaceEdge_proc($sMainObject, $sSecondObject, $iaFaceEdges[$i]);
    }
    
}
proc copyUV_mainFaceEdge_proc(string $sMainObject, string $sSecondObject, int $iaFaceEdges) {
    int $iaFaces[] = getFacesFromEdge(($sMainObject + ".e[" + $iaFaceEdges + "]"));
    if(1 == size($iaFaces)) return;
    int $iaVertices[] = getVerticesFromEdge(($sMainObject + ".e[" + $iaFaceEdges + "]"));
    
    int $iUV0 = getUVFromVertexFace($sMainObject, $iaFaces[0], $iaVertices[0]);
    int $iUV1 = getUVFromVertexFace($sMainObject, $iaFaces[0], $iaVertices[1]);
    int $iUV2 = getUVFromVertexFace($sMainObject, $iaFaces[1], $iaVertices[0]);
    int $iUV3 = getUVFromVertexFace($sMainObject, $iaFaces[1], $iaVertices[1]);
    
    if(($iUV0 != $iUV2) || ($iUV1 != $iUV3)) return;
    
    polyMapSew ($sSecondObject + ".e[" + $iaFaceEdges + "]");
}

// ********************************************************************************
// ************************************
//DATO UN UV, RITORNA LA SUA POSIZIONE*
// ************************************
proc float[] getUVPosFromUV(string $sUV,int $iPrecision) {
    float $faUVPos[] = `polyEditUV -q $sUV`;
    $faUVPos[0] = RoundOff($faUVPos[0],$iPrecision);
    $faUVPos[1] = RoundOff($faUVPos[1],$iPrecision);
    return $faUVPos;
}
// ****************************************************
//DATA UNA FACCIA E UN VERTICE, RITORNA L'UV ASSOCIATO*
// ****************************************************
proc int getUVFromVertexFace(string $sObject, int $iFace, int $iVertex){
    string $saUV[] = `polyListComponentConversion -fvf -tuv ($sObject + ".vtxFace[" + $iVertex + "][" + $iFace + "]")`;
    int $iaUVs[] = componentRange($saUV[0]);
    return $iaUVs[0];
}
// **********************************
// DATA UNA FACCIA RITORNA I VERTICI*
// **********************************
proc int[] getVerticesFromFace(string $sFace) {
    string $saVertices[] = `polyListComponentConversion -ff -tv $sFace`;
    int $iaVertices[] = componentRangeExpanded($saVertices);
    return $iaVertices;
}
// *****************************************
//DATA UNA MESH, RITORNA IL NUMERO DI EDGES*
// *****************************************
proc int getMeshEdges(string $sObject) {
    int $iaEdges[] = `polyEvaluate -e $sObject`;
    return $iaEdges[0];
}
// *****************************************
//DATA UNA MESH, RITORNA IL NUMERO DI FACCE*
// *****************************************
proc int getMeshFaces(string $sObject) {
    int $iafcs[] = `polyEvaluate -f $sObject`;
    return $iafcs[0];
}
// **********************************
// DATA UNA FACCIA RITORNA GLI EDGES*
// **********************************
proc int[] getEdgesFromFace(string $sFace) {
    string $sEdges[] = `polyListComponentConversion -ff -te $sFace`;
    int $iaEdges[] = componentRangeExpanded($sEdges);
    return $iaEdges;
}
// ******************************
//DATO UN EDGE RITORNA I VERTICI*
// ******************************
proc int[] getVerticesFromEdge(string $sEdge) {
    string $saVertices[] = `polyListComponentConversion -fe -tv $sEdge`;
    int $iaVertices[] = componentRangeExpanded($saVertices);
    return $iaVertices;
}
// ****************************************
// DATO UN EDGE RITORNA LE FACCE ASSOCIATE*
// ****************************************
proc int[] getFacesFromEdge(string $sEdge) {
    string $saFaces[] = `polyListComponentConversion -fe -tf $sEdge`;
    int $iaFaces[] = componentRangeExpanded($saFaces);
    return $iaFaces;
}
// **********************************************************************
// ***************************
//ARROTONDA UN NUMERO 'FLOAT'*
// ***************************
proc float RoundOff(float $Number, int $Precision) {
    if($Precision > 0) {
        float $roundscale = pow(10,$Precision);
        if($Number > 0)
            return (((float)(int)($Number*$roundscale + 0.5)) /$roundscale);
        else
            return (((float)(int)($Number*$roundscale - 0.5)) /$roundscale);
    } else {
        float $roundscale = pow(10,-$Precision);
        if($Number > 0)
            return (((float)(int)($Number/$roundscale + 0.5)) *$roundscale);
        else
            return (((float)(int)($Number/$roundscale - 0.5)) *$roundscale);
    }
}
// **************************************************
//dato ad esempio pSphere1.vtx[0:25] ritorna { 0, 25}*
//dato ad esempio pSphere1.vtx[0] ritorna { 0, 0}    *
// **************************************************
proc int[] componentRange(string $select) {
    string $buffer[];
    int $i, $tokens;
    int $elements[2] = { 0, 0 };
    $tokens = `tokenize $select "[:]" $buffer`;
    $elements[0] = $elements[1] = int($buffer[1]);
    if($tokens > 2) $elements[1] = int($buffer[2]);
    
    return $elements;
}
// **************************************************************************
//dato ad esempio pSphere1.vtx[0:5] ritorna { 0, 1, 2, 3, 4, 5}                *
//dato ad esempio pSphere1.vtx[0] ritorna { 0 }                                *
//dato ad esempio pSphere1.vtx[0] E pSphere1.vtx[3:5] ritorna { 0, 3, 4, 5}    *
// **************************************************************************
proc int[] componentRangeExpanded(string $saSelection[]) {
    int $iSelection = size($saSelection);
    int $iaRes[];
    clear $iaRes;
    int $iCounter = 0;
    int $i;
    
    for($i = 0; $i < $iSelection; $i++) {
        int $iaTemp[] = componentRange($saSelection[$i]);
        if($iaTemp[0] == $iaTemp[1]) {
            $iaRes[$iCounter] = $iaTemp[0];
            $iCounter++;
            continue;
        }
        
        int $i2;
        for($i2 = $iaTemp[0]; $i2 < $iaTemp[1]; $i2++) {
            $iaRes[$iCounter] = $i2;
            $iCounter++;
        }
        $iaRes[$iCounter] = $i2;
        $iCounter++;
        
    }
    return $iaRes;
    
}

 

 

Edited by Michele71
inserito lo script in code format
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...