Created
January 24, 2013 00:18
-
-
Save KelSolaar/4616184 to your computer and use it in GitHub Desktop.
Craig's Planator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as cmds | |
import os | |
MAPPING = {64 : "/path/to/chair.png", | |
128 : "/path/to/mop.png", | |
256 : "/path/to/safe.png", | |
512 : "/path/to/book.png"} | |
def getSplitextBasename(path): | |
basename = os.path.splitext(os.path.basename(os.path.normpath(path)))[0] | |
return basename | |
def getShaderBranch(texture): | |
lambert = cmds.shadingNode("lambert", asShader=True) | |
shadingEngine = cmds.sets(renderable=True, noSurfaceShader=True, empty=True) | |
cmds.connectAttr("%s.outColor" % lambert, "%s.surfaceShader" % shadingEngine, f=True) | |
file = cmds.shadingNode("file", asTexture=True) | |
cmds.setAttr("%s.fileTextureName" % file, texture, type="string") | |
cmds.connectAttr("%s.outColor" % file, "%s.color" % lambert, f=True) | |
place2dTexture = cmds.shadingNode("place2dTexture", asUtility=True) | |
cmds.connectAttr("%s.outUV" % place2dTexture, "%s.uvCoord" % file, f=True) | |
cmds.connectAttr("%s.outUvFilterSize" % place2dTexture, "%s.uvFilterSize" % file, f=True) | |
attributes = ("coverage", "translateFrame", "rotateFrame", "mirrorU", "mirrorV", "stagger", "wrapU", "wrapV" , "repeatUV" , "vertexUvOne" , "vertexUvTwo" , "vertexUvThree" , "vertexCameraOne", "noiseUV", "offset", "rotateUV") | |
for attribute in attributes: | |
cmds.connectAttr("%s.%s" % (place2dTexture, attribute), "%s.%s" % (file, attribute), f=True) | |
prefix = getSplitextBasename(texture) | |
for node in (lambert, file, place2dTexture): | |
cmds.rename(node, "%s_%s" % (prefix, cmds.nodeType(node))) | |
return cmds.rename(shadingEngine, "%s_%s" % (prefix, cmds.nodeType(shadingEngine))) | |
def getTexturedPlane(size, mapping=MAPPING): | |
file = mapping.get(size) | |
if not file: | |
return False | |
plane = cmds.polyPlane(w=size, h=size, sx=10, sy=10, ch=0) | |
cmds.sets(plane, e=True, forceElement=getShaderBranch(file)) | |
cmds.rename(plane, getSplitextBasename(file)) | |
return True | |
getTexturedPlane(64) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment