Skip to content

Instantly share code, notes, and snippets.

@fereria
Created January 30, 2014 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fereria/7979f89d0e1c18ade636 to your computer and use it in GitHub Desktop.
Save fereria/7979f89d0e1c18ade636 to your computer and use it in GitHub Desktop.
## -*- coding: utf-8 -*-
import pymel.core as pm
def addOffset2DTexAttr():
texName = pm.ls(sl=True,type="place2dTexture")
splitAttr = "Split"
numAttr = "Num"
for tex in texName:
if tex.hasAttr(splitAttr) != True:
tex.addAttr(splitAttr,k=True,at="long",dv=7)
if tex.hasAttr(numAttr) != True:
tex.addAttr(numAttr,k=True,at="long",dv=1)
#OffsetCommand生成
expCmd = "int $texSplit = (int) " + tex.name() + "." + splitAttr + ";\n"
expCmd += "float $offset = 1.0 / $texSplit;\n"
expCmd += tex.name() + ".offsetU = (((" + tex.name() + "." + numAttr + "- 1) % $texSplit) * $offset);\n"
expCmd += tex.name() + ".offsetV = ((((int)(" + tex.name() + "." + numAttr + " - 1) / $texSplit)) * $offset ) * -1;\n"
print expCmd
pm.expression(s=expCmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment