Difference between revisions of "Maya tmp"
Jump to navigation
Jump to search
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Maya tmp Scripts= | =Maya tmp Scripts= | ||
− | === Maya Python - | + | === Maya Python - Create object & Randomize Translate === |
<pre> | <pre> | ||
from maya import cmds | from maya import cmds | ||
Line 15: | Line 15: | ||
</pre> | </pre> | ||
− | === Maya Python - Randomize selection === | + | === Maya Python - Randomize translate of selection #1=== |
<pre> | <pre> | ||
from maya import cmds | from maya import cmds | ||
Line 29: | Line 29: | ||
cmds.setAttr(obj+'.translateZ', random.randint(0, 5)) | cmds.setAttr(obj+'.translateZ', random.randint(0, 5)) | ||
+ | </pre> | ||
+ | |||
+ | === Maya Python - Randomize translate of selection #2=== | ||
+ | <pre> | ||
+ | #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) | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | === Maya Mel - Replace path - getAttr/setAttr=== | ||
+ | <pre> | ||
+ | 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"); | ||
+ | } | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | === Maya Mel - Auto Uvs and Layout=== | ||
+ | <pre> | ||
+ | polyMultiLayoutUV -scale 1 -rotateForBestFit 0 -layout 2; | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | === Instance and Snap === | ||
+ | <pre> | ||
+ | |||
+ | //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; | ||
+ | //////////////// | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | === Maya Mel - Primary visibility off=== | ||
+ | <pre> | ||
+ | for ( $object in `ls -sl -l` ) { | ||
+ | print($object+"\n"); | ||
+ | setAttr ($object + ".primaryVisibility") 0; | ||
+ | } | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | === V-ray - Create and connect VRayMtls, files and place2dTextures for a set of objects === | ||
+ | <pre> | ||
+ | // 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 ; | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | === Maya Mel - Shift Translate for each objects of a group === | ||
+ | <pre> | ||
+ | // 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; | ||
</pre> | </pre> |
Latest revision as of 14:09, 29 September 2023
Contents
- 1 Maya tmp Scripts
- 1.1 Maya Python - Create object & Randomize Translate
- 1.2 Maya Python - Randomize translate of selection #1
- 1.3 Maya Python - Randomize translate of selection #2
- 1.4 Maya Mel - Replace path - getAttr/setAttr
- 1.5 Maya Mel - Auto Uvs and Layout
- 1.6 Instance and Snap
- 1.7 Maya Mel - Primary visibility off
- 1.8 V-ray - Create and connect VRayMtls, files and place2dTextures for a set of objects
- 1.9 Maya Mel - Shift Translate for each objects of a group
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;