Skip to content

Instantly share code, notes, and snippets.

@blockinhead
Created June 8, 2021 07:49
Show Gist options
  • Select an option

  • Save blockinhead/7cc01bd60c117adb821f69ee308ca6c7 to your computer and use it in GitHub Desktop.

Select an option

Save blockinhead/7cc01bd60c117adb821f69ee308ca6c7 to your computer and use it in GitHub Desktop.
a function to create an animated ramp to color a curve for arnold in maya
import pymel.core as pm
import random
def ramp_to_curve(curve, anim_length=20, color1=(0.01, 0.01, 0.01), color2=(1, 1, 1)):
ramp = pm.shadingNode('ramp', asTexture=True)
place2d = pm.shadingNode('place2dTexture', asUtility=True)
place2d.outUV >> ramp.uvCoord
place2d.outUvFilterSize >> ramp.uvFilterSize
ramp.cel[2].ep.set(1)
ramp.cel[0].color.set(color1)
ramp.cel[1].color.set(color2)
ramp.cel[2].color.set(color1)
anim_curve = pm.createNode('animCurveTU')
anim_curve.addKeys((1, anim_length), (0, 1))
anim_curve.setPostInfinityType('cycle')
anim_curve.output >> ramp.cel[0].ep
add1 = pm.createNode('addDoubleLinear')
anim_curve.output >> add1.input1
add1.input2.set(0.05)
add1.output >> ramp.cel[1].ep
add2 = pm.createNode('addDoubleLinear')
anim_curve.output >> add2.input1
add2.input2.set(0.1)
add2.output >> ramp.cel[2].ep
ramp.outColor >> curve.aiCurveShader
curve.aiMode.set(1)
curve.aiCurveWidth.set(0.01)
curve.aiRenderCurve.set(1)
pts=[]
for i in range(10):
pts.append([0, i, 0])
curve = pm.curve(editPoint=pts)
ramp_to_curve(curve=curve,
anim_length=15 + random.randrange(8),
color2=(random.uniform(0.5, 1), random.uniform(0.2, 1), 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment