I’ve had some questions about the placement of bitmaps on surfaces in Maya, and it was about time I make this process more portable.
So, I packaged a new subroutine called “PlaceImageAndMaterialOnObject” and it automatically generates a new shader and file container for a specific surface in 3D. Why do this? First, it takes a lot of connected attributes to make file connections to material characteristics and the bitmap. When MEL scripting this, it can clutter your code with dozens of connectAttr lines. This new function outsources your process so whenever the bitmap is applied, you just have one line of code instead of many. Second, applying bitmap textures in Maya via MEL is very counter intuitive, even for advance melscripters. This function simplifies the process.
Some features….Well, I get sick of codes from HighEnd3D that don’t do name verification or concatenation, so this code will still create a unique id even if the input name already exists. The returned string array gives the user the new name and file container. Also, it will replace the material if a bitmap is already designated to the object. This is good if the map already appears on more than one surface. We don’t want to replace the image string on all of the other geometric elements.
I’ve thrown this on the 0001d Blast wiki, and the link is above. Otherwise here it is on the sherpa blog:
global proc string[] PlaceImageAndMaterialOnObject(string $ObjName, string $MatType, string $ImagePath, string $MatPrefixName, string $ContainerFileName) {
//Author Nick Pisca 0001d 2009 SURFACE PHONG,BLINN,LAMB PATH YOUR NAME YOUR NAME
string $TempArr[1];
string $SNA = `shadingNode -asShader $MatType -n $MatPrefixName`;
string $SNASG = `sets -renderable true -noSurfaceShader true -empty -name ($MatPrefixName+"SG")`;
connectAttr -f ($SNA+".outColor") ($SNASG+".surfaceShader");
sets -e -forceElement $SNASG $ObjName;
string $SNF = `shadingNode -asTexture file -n $ContainerFileName`;
string $P2D = `shadingNode -asUtility place2dTexture -n "p2dT#"`;
connectAttr -f ($P2D+".coverage") ($SNF+".coverage");
connectAttr -f ($P2D+".translateFrame") ($SNF+".translateFrame");
connectAttr -f ($P2D+".rotateFrame") ($SNF+".rotateFrame");
connectAttr -f ($P2D+".mirrorU") ($SNF+".mirrorU");
connectAttr -f ($P2D+".mirrorV") ($SNF+".mirrorV");
connectAttr -f ($P2D+".stagger") ($SNF+".stagger");
connectAttr -f ($P2D+".wrapU") ($SNF+".wrapU");
connectAttr -f ($P2D+".wrapV") ($SNF+".wrapV");
connectAttr -f ($P2D+".repeatUV") ($SNF+".repeatUV");
connectAttr -f ($P2D+".offset") ($SNF+".offset");
connectAttr -f ($P2D+".rotateUV") ($SNF+".rotateUV");
connectAttr -f ($P2D+".noiseUV") ($SNF+".noiseUV");
connectAttr -f ($P2D+".vertexUvOne") ($SNF+".vertexUvOne");
connectAttr -f ($P2D+".vertexUvTwo") ($SNF+".vertexUvTwo");
connectAttr -f ($P2D+".vertexUvThree") ($SNF+".vertexUvThree");
connectAttr -f ($P2D+".vertexCameraOne") ($SNF+".vertexCameraOne");
connectAttr ($P2D+".outUV") ($SNF+".uv");
connectAttr ($P2D+".outUvFilterSize") ($SNF+".uvFilterSize");
connectAttr -force ($SNF+".outColor") ($SNA+".color");
setAttr ($SNF+".fileTextureName") -type "string" $ImagePath;
$TempArr[0] = $SNA; $TempArr[1] = $SNF;
return $TempArr;
}
Wonderful. And, nice timing: I need this now and you just posted it this week! I want something slightly different, putting the *same* image at various brightnesses/colors on a bunch of objects — specifically, stars!
But this should be a good base to build on. Thanks!
Stuart,
Cool. It’s something that needed to be portable anyway. As for the brightness of the map, there is an attribute for that…I don’t recall the name. Go into the File Container node sidebar and it’s something about color values. You can increase or decrease the contrast and brightness.
Stuart,
Quick question… are you at NCSA using Maya a lot? Are you using it just for visualizations, or are you doing some processing on it?