Skip to content

Instantly share code, notes, and snippets.

@tokejepsen
Last active July 11, 2016 08:25
Show Gist options
  • Save tokejepsen/264bf6618baa5d0c8034 to your computer and use it in GitHub Desktop.
Save tokejepsen/264bf6618baa5d0c8034 to your computer and use it in GitHub Desktop.
Maya: Highlight Tool
import pymel
import traceback
def place_highlight(cam, obj):
""" Creates a highlight rig for placing highlights on an object
"""
parent_loc = pymel.core.spaceLocator()
up_vector = pymel.core.spaceLocator()
aim_loc = pymel.core.spaceLocator()
vector01 = pymel.core.spaceLocator()
vector02 = pymel.core.spaceLocator()
highlight_loc = pymel.core.spaceLocator()
highlight = pymel.core.polyPlane()[0]
pymel.core.parent(up_vector, parent_loc)
pymel.core.parent(aim_loc, parent_loc)
pymel.core.parent(vector01, parent_loc)
pymel.core.parent(vector02, parent_loc)
pymel.core.parent(highlight_loc, parent_loc)
pymel.core.parent(highlight, highlight_loc)
for node in [up_vector, aim_loc, vector01, vector02, highlight_loc]:
node.getShape().localScaleX.set(0)
node.getShape().localScaleY.set(0)
node.getShape().localScaleZ.set(0)
up_vector.ty.set(1)
vector01.tx.set(1)
vector02.tx.set(1)
highlight.tx.set(10)
highlight.rz.set(90)
highlight.primaryVisibility.set(0)
pymel.core.normalConstraint(obj, parent_loc)
pymel.core.geometryConstraint(obj, parent_loc)
pymel.core.parentConstraint(aim_loc, vector02, maintainOffset=True)
pymel.core.aimConstraint(cam, aim_loc, worldUpObject=up_vector)
angle_between = pymel.core.createNode('angleBetween')
uc01 = pymel.core.createNode('unitConversion')
uc02 = pymel.core.createNode('unitConversion')
md = pymel.core.createNode('multiplyDivide')
uc01.conversionFactor.set(57.296)
uc02.conversionFactor.set(0.017)
md.operation.set(1)
md.input2X.set(-1)
md.input2Y.set(-1)
md.input2Z.set(-1)
vector01.translate >> angle_between.vector1
vector02.translate >> angle_between.vector2
angle_between.euler >> uc01.input
uc01.output >> md.input1
md.output >> uc02.input
uc02.output >> highlight_loc.rotate
mat = pymel.core.shadingNode("surfaceShader", asShader=True)
shader = pymel.core.sets( renderable=True, noSurfaceShader=True, empty=True)
mat.outColor.set([1, 1, 1])
mat.outColor >> shader.surfaceShader
pymel.core.sets(shader, edit=True, forceElement=[highlight])
cam = None
obj = None
for node in pymel.core.ls(selection=True):
if node.getShape().nodeType() == 'camera':
cam = node
if node.getShape().nodeType() == 'mesh':
obj = node
if not cam:
pymel.core.error('No camera found in selection!')
if not obj:
pymel.core.error('No meshes found in selection!')
try:
place_highlight(cam, obj)
except:
print traceback.format_exc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment