Difference between revisions of "Maya tmp"

From Antoine Vienne | Wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 138: Line 138:
 
</pre>
 
</pre>
  
=== Maya Mel - Multi Snap===
+
=== V-ray - Create and connect VRayMtls, files and place2dTextures for a set of objects ===
///////////////////////////////////////////////////////////////////////////////////////////
+
<pre>
///////////////////////////////////////////////////////////////////////////////////////////
+
// Replace assetBaked_Set by the name of your set
/*
 
type the command MS()
 
*/
 
///////////////////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////////////////
 
source "generateChannelMenu.mel";
 
  
global proc MS ()
+
select -cl  ;
{
+
select -r assetBaked_Set ;
    global string $sourceObjects;
+
string $selection[] = `ls -sl`;
    global string $destinationObjects;
+
string $polyGons[] = `filterExpand -sm 12 $selection`;
 
+
select $polyGons;
 
+
for($object in `ls -sl`){
    // If the window exists already, delete it.
 
    if (`window -exists multiSnapWindow`)
 
    {
 
        deleteUI multiSnapWindow;
 
    }
 
 
 
    // Build the window.
 
    global string $man_window;
 
    string $man_window = `window -title " MULTI SNAP" -sizeable 0 -w 300 multiSnapWindow`;
 
    frameLayout -label "Snap source objects on destination objects.";
 
    rowLayout -width 540 -nc 2 -cw4 10 20 20 100;
 
    // Source objects section
 
    frameLayout -label "Source objects";
 
    $sourceObjects = `textScrollList -width 600 -height 300`;
 
    rowLayout -width 240 -nc 2 -cw2 120 120;
 
    button -label "Add selected" -command "MS_addObjects ();" -width 120;
 
    button -label "Remove selected" -command "MS_removeObjects ();" -width 120;
 
    setParent ..;
 
    rowLayout -width 240 -nc 2 -cw2 120 120;
 
    button -label "Remove All" -command "MS_clearObjects ();" -width 240;
 
    setParent ..;
 
    setParent ..;
 
    rowLayout -nc 3;
 
    button -label "Create" -command "VRAYCONNECDO() " -width 140 -align center;
 
    button -label "Close" -command "DAC_CloseUI() " -width 140 -align center;
 
    setParent ..;
 
    setParent ..;
 
    // Destination objects section
 
    frameLayout -label "Destination objects";
 
    $destinationObjects = `textScrollList -width 600 -height 300`;
 
    rowLayout -width 240 -nc 2 -cw2 120 120;
 
    button -label "Add selected" -command "MS_addMM ();" -width 120;
 
    button -label "Remove selected" -command "MS_removeMM ();" -width 120;
 
    setParent ..;
 
    setParent ..;
 
    rowLayout -nc 3;
 
    button -label "SNAP IT" -command "VRAYCONNECDO() " -width 140 -align center;
 
    button -label "Close" -command "DAC_CloseUI() " -width 140 -align center;
 
    setParent ..;
 
    setParent ..;
 
 
 
// Show the window.
 
showWindow multiSnapWindow;
 
}
 
 
 
global proc string[] getShaders(string $from)
 
{
 
// get the shapes from the input
 
string $shapes[] = ls("-o", "-dag", "-s", $from);
 
// give me the connected "shadingEngines"
 
string $shadingEngines[] = listConnections("-type","shadingEngine", $shapes);
 
// list the connected materials (shaders) from that
 
string $materials[] = ls("-mat", listConnections($shadingEngines));
 
// remove duplicate occurrences.
 
return (stringArrayRemoveDuplicates($materials));
 
}
 
  
//Add selected objects to list.
+
    string $shaderName = ($object + "_BAKE_" + `toupper $lightRigName` + "_SHD");
global proc MS_addObjects ()
+
    string $shadingGroupName = ($object + "_BAKE_" + `toupper $lightRigName` + "_SG");
{
+
    shadingNode -asShader VRayMtl -n $shaderName;
      global string $sourceObjects;
+
    sets -renderable true -noSurfaceShader true -empty -name $shadingGroupName;
      string $selectedshapes[] = `ls -sl -l`;
+
   
      //print $selectedshapes;
+
    string $shaderNameC = substituteAllString($shaderName, "|", "");
      int $count = 0;
+
    string $shadingGroupNameC = substituteAllString($shadingGroupName, "|", "");
 +
    connectAttr -f ($shaderNameC + ".outColor") ($shadingGroupNameC + ".surfaceShader");
  
if ($selectedshapes[0] != "")
+
    setAttr ($shaderNameC + ".color") -type double3 0 0 0 ;
{
 
    for ($i in $selectedshapes)
 
    {
 
      $count ++;
 
      textScrollList -edit -append $i $sourceObjects;
 
    }
 
}
 
}
 
  
//Add selected objects to list.
+
    string $fileName = ("file_" + $object);
global proc MS_addMM ()
+
    string $place2dTextureName = ("place2dTexture_" + $object);
{
+
    shadingNode -asTexture -isColorManaged file -n $fileName;
      global string $destinationObjects;
+
    shadingNode -asUtility place2dTexture -n $place2dTextureName;
      string $selectedshapes[] = `ls -sl -l`;
 
      //print $selectedshapes;
 
      int $count = 0;
 
  
if ($selectedshapes[0] != "")
+
    string $objectC = substituteAllString($object, "|", "");
{
+
    string $fileNameC = ("file_" + $objectC);
    for ($i in $selectedshapes)
+
    string $place2dTextureNameC = ("place2dTexture_" + $objectC);
    {
+
   
      $count ++;
+
    setAttr ($fileNameC + ".filterType") 0;
      textScrollList -edit -append $i $destinationObjects;
+
    setAttr ($fileNameC + ".uvTilingMode") 3;
    }
+
    setAttr ($fileNameC + ".cs") -type "string" "ACES - ACEScg";
}
+
   
}
+
    connectAttr -f ($place2dTextureNameC + ".coverage") ($fileNameC + ".coverage");
 +
    connectAttr -f ($place2dTextureNameC + ".translateFrame") ($fileNameC + ".translateFrame");
 +
    connectAttr -f ($place2dTextureNameC + ".rotateFrame") ($fileNameC + ".rotateFrame");
 +
    connectAttr -f ($place2dTextureNameC + ".mirrorU") ($fileNameC + ".mirrorU");
 +
    connectAttr -f ($place2dTextureNameC + ".mirrorV") ($fileNameC + ".mirrorV");
 +
    connectAttr -f ($place2dTextureNameC + ".stagger") ($fileNameC + ".stagger");
 +
    connectAttr -f ($place2dTextureNameC + ".wrapU") ($fileNameC + ".wrapU");
 +
    connectAttr -f ($place2dTextureNameC + ".wrapV") ($fileNameC + ".wrapV");
 +
    connectAttr -f ($place2dTextureNameC + ".repeatUV") ($fileNameC + ".repeatUV");
 +
    connectAttr -f ($place2dTextureNameC + ".offset") ($fileNameC + ".offset");
 +
    connectAttr -f ($place2dTextureNameC + ".rotateUV") ($fileNameC + ".rotateUV");
 +
    connectAttr -f ($place2dTextureNameC + ".noiseUV") ($fileNameC + ".noiseUV");
 +
    connectAttr -f ($place2dTextureNameC + ".vertexUvOne") ($fileNameC + ".vertexUvOne");
 +
    connectAttr -f ($place2dTextureNameC + ".vertexUvTwo") ($fileNameC + ".vertexUvTwo");
 +
    connectAttr -f ($place2dTextureNameC + ".vertexUvThree") ($fileNameC + ".vertexUvThree");
 +
    connectAttr -f ($place2dTextureNameC + ".vertexCameraOne") ($fileNameC + ".vertexCameraOne");
 +
    connectAttr ($place2dTextureNameC + ".outUV") ($fileNameC + ".uv");
 +
    connectAttr ($place2dTextureNameC + ".outUvFilterSize") ($fileNameC + ".uvFilterSize");
  
// Clear objects from list.
+
    connectAttr -f ($fileNameC + ".outColor") ($shaderNameC + ".illumColor");
global proc MS_clearObjects ()
+
   
{
+
     sets -e -forceElement $shadingGroupNameC $object;
     global string $sourceObjects;
 
textScrollList -e -ra $sourceObjects;
 
 
}
 
}
 +
select -cl  ;
  
// Remove selected object from list.
+
</pre>
global proc MS_removeObjects ()
 
{
 
  global string $sourceObjects;
 
  
    int $index [] = `textScrollList -query -selectIndexedItem $sourceObjects`;
+
=== Maya Mel - Shift Translate for each objects of a group ===
    if ($index [0] != 0)
+
<pre>
    {
+
// Select top group first
        textScrollList -edit -removeIndexedItem $index [0] $sourceObjects;
 
    }
 
  global string $sourceObjects;
 
}
 
  
 +
string $selection[] = `ls -sl`;
 +
string $polyGons[] = `filterExpand -sm 12 $selection`;
  
global proc VRAYCONNECDO()
+
for ($i = 0; $i < size($polyGons); $i ++)
 
{
 
{
  // UI Elements
+
    setAttr ($polyGons[$i] + ".translateX") ($i*2);
global string $sourceObjects;
 
global string $destinationObjects;
 
// Define user selected objects
 
string $selected_objects[] = `textScrollList -query -allItems $sourceObjects`;
 
string $meshMaterial[] = `textScrollList -query -allItems $destinationObjects`;
 
int $i = 0;
 
//Progress bar
 
global string $gMainProgressBar;
 
 
// Start the progress bar and adjust its max value for this operation.
 
    int $steps = size($selected_objects);
 
    progressBar -edit -beginProgress -isInterruptable true -status "Connecting shaders to mesh material ..." -maxValue $steps $gMainProgressBar;
 
 
 
for ($i = 0; $i < size($selected_objects); $i ++)
 
{
 
        select -r $selected_objects[$i];
 
        select -add $meshMaterial[$i];
 
        pointConstraint -offset 0 0 0 -weight 1;
 
        orientConstraint -offset 0 0 0 -weight 1;
 
        scaleConstraint -offset 1 1 1 -weight 1;
 
        select -r "*Constraint*";
 
        doDelete;
 
// Update the progress bar.
 
progressBar -edit -step 1 $gMainProgressBar;
 
}
 
// End the progress.
 
progressBar -edit -endProgress $gMainProgressBar;
 
 
}
 
}
  
 +
select -r $selection;
 
</pre>
 
</pre>

Latest revision as of 14:09, 29 September 2023

Maya tmp Scripts

Maya Python - Create object & Randomize Translate

from maya import cmds
import random

numObjects = 4

for n in range(numObjects):
    obj = cmds.polyCube()
    cmds.setAttr(obj[0]+'.translateX', random.randint(0, 5))
    cmds.setAttr(obj[0]+'.translateY', random.randint(0, 5))
    cmds.setAttr(obj[0]+'.translateZ', random.randint(0, 5))

Maya Python - Randomize translate of selection #1

from maya import cmds
import random

objList = cmds.ls(selection=True)

print objList

for obj in objList:
    cmds.setAttr(obj+'.translateX', random.randint(0, 5))
    cmds.setAttr(obj+'.translateY', random.randint(0, 5))
    cmds.setAttr(obj+'.translateZ', random.randint(0, 5))

Maya Python - Randomize translate of selection #2

#La meme chose en utilisant une fonction
from maya import cmds
import random

objList = cmds.ls(selection=True)

print objList

#On definit la fonction
def randomize(minValue=0, maxValue=5):
    for obj in objList:
        cmds.setAttr(obj+'.translateX', random.randint(minValue, maxValue))
        cmds.setAttr(obj+'.translateY', random.randint(minValue, maxValue))
        cmds.setAttr(obj+'.translateZ', random.randint(minValue, maxValue))

#On change si besoin les valeurs par defaut avant d'executer la fonction
randomize(minValue=4, maxValue=20)

Maya Mel - Replace path - getAttr/setAttr

for ( $object in `ls -sl -l` ) {
    $path = getAttr ($object+".filePrefix");   
    setAttr -type "string" ($object+".filePrefix") ($path+"yo");
}

for ( $object in `ls -sl -l` ) {    
    setAttr -type "string" ($object+".filePrefix") ("//blabla/bla.abc");
}

Maya Mel - Auto Uvs and Layout

polyMultiLayoutUV -scale 1 -rotateForBestFit 0 -layout 2;

Instance and Snap


//DE-PARENT meshs
string $VRMeshs = "*VR";
select -r $VRMeshs;
parent -w;
select -cl;


////Basket Grass
//replace_locator_by_object
string $objectCible = "Basket_Grass_VR";
string $locatorPlacement = "Basket_Grass_AR*";

select -cl;
select -r $locatorPlacement;
//pickWalk -d up;
string $selLocatorPlacement[] = `ls -sl`;
int $nbreLocatorPlacement = size ($selLocatorPlacement);

select -r $objectCible;
for ($i=1; $i<$nbreLocatorPlacement; ++$i)
{
    instance -st;
}
select -cl;

////////////////
string $objectCibleI = "Basket_Grass_VR*";
select -r $objectCibleI;
pickWalk -d up;
string $selObjectCible[] = `ls -sl`;
int $nbreObjectCible = size ($selObjectCible);

select -cl;

for ($i=0; $i<$nbreObjectCible; ++$i)
{
    select -r $selLocatorPlacement[$i];
    select -add $selObjectCible[$i];
    pointConstraint -offset 0 0 0 -weight 1;
    orientConstraint -offset 0 0 0 -weight 1;
    scaleConstraint -offset 1 1 1 -weight 1;
    select -r "*Constraint*";
    doDelete;
}

select -cl;

select -r $locatorPlacement;
doDelete;
select -cl;
////////////////

Maya Mel - Primary visibility off

for ( $object in `ls -sl -l` ) {
    print($object+"\n");
    setAttr ($object + ".primaryVisibility") 0;
}

V-ray - Create and connect VRayMtls, files and place2dTextures for a set of objects

// Replace assetBaked_Set by the name of your set

select -cl  ;
select -r assetBaked_Set ;
string $selection[] = `ls -sl`;
string $polyGons[] = `filterExpand -sm 12 $selection`;
select $polyGons;
for($object in `ls -sl`){

    string $shaderName = ($object + "_BAKE_" + `toupper $lightRigName` + "_SHD");
    string $shadingGroupName = ($object + "_BAKE_" + `toupper $lightRigName` + "_SG");
    shadingNode -asShader VRayMtl -n $shaderName;
    sets -renderable true -noSurfaceShader true -empty -name $shadingGroupName;
    
    string $shaderNameC = substituteAllString($shaderName, "|", "");
    string $shadingGroupNameC = substituteAllString($shadingGroupName, "|", "");
    connectAttr -f ($shaderNameC + ".outColor") ($shadingGroupNameC + ".surfaceShader");

    setAttr ($shaderNameC + ".color") -type double3 0 0 0 ;

    string $fileName = ("file_" + $object);
    string $place2dTextureName = ("place2dTexture_" + $object);
    shadingNode -asTexture -isColorManaged file -n $fileName;
    shadingNode -asUtility place2dTexture -n $place2dTextureName;

    string $objectC = substituteAllString($object, "|", "");
    string $fileNameC = ("file_" + $objectC);
    string $place2dTextureNameC = ("place2dTexture_" + $objectC);
    
    setAttr ($fileNameC + ".filterType") 0;
    setAttr ($fileNameC + ".uvTilingMode") 3;
    setAttr ($fileNameC + ".cs") -type "string" "ACES - ACEScg";
    
    connectAttr -f ($place2dTextureNameC + ".coverage") ($fileNameC + ".coverage");
    connectAttr -f ($place2dTextureNameC + ".translateFrame") ($fileNameC + ".translateFrame");
    connectAttr -f ($place2dTextureNameC + ".rotateFrame") ($fileNameC + ".rotateFrame");
    connectAttr -f ($place2dTextureNameC + ".mirrorU") ($fileNameC + ".mirrorU");
    connectAttr -f ($place2dTextureNameC + ".mirrorV") ($fileNameC + ".mirrorV");
    connectAttr -f ($place2dTextureNameC + ".stagger") ($fileNameC + ".stagger");
    connectAttr -f ($place2dTextureNameC + ".wrapU") ($fileNameC + ".wrapU");
    connectAttr -f ($place2dTextureNameC + ".wrapV") ($fileNameC + ".wrapV");
    connectAttr -f ($place2dTextureNameC + ".repeatUV") ($fileNameC + ".repeatUV");
    connectAttr -f ($place2dTextureNameC + ".offset") ($fileNameC + ".offset");
    connectAttr -f ($place2dTextureNameC + ".rotateUV") ($fileNameC + ".rotateUV");
    connectAttr -f ($place2dTextureNameC + ".noiseUV") ($fileNameC + ".noiseUV");
    connectAttr -f ($place2dTextureNameC + ".vertexUvOne") ($fileNameC + ".vertexUvOne");
    connectAttr -f ($place2dTextureNameC + ".vertexUvTwo") ($fileNameC + ".vertexUvTwo");
    connectAttr -f ($place2dTextureNameC + ".vertexUvThree") ($fileNameC + ".vertexUvThree");
    connectAttr -f ($place2dTextureNameC + ".vertexCameraOne") ($fileNameC + ".vertexCameraOne");
    connectAttr ($place2dTextureNameC + ".outUV") ($fileNameC + ".uv");
    connectAttr ($place2dTextureNameC + ".outUvFilterSize") ($fileNameC + ".uvFilterSize");

    connectAttr -f ($fileNameC + ".outColor") ($shaderNameC + ".illumColor");
    
    sets -e -forceElement $shadingGroupNameC $object;
}
select -cl  ;

Maya Mel - Shift Translate for each objects of a group

// Select top group first

string $selection[] = `ls -sl`;
string $polyGons[] = `filterExpand -sm 12 $selection`;

for ($i = 0; $i < size($polyGons); $i ++)
{
    setAttr ($polyGons[$i] + ".translateX") ($i*2);
}

select -r $selection;