On 16/09/2013 at 23:07, xxxxxxxx wrote:
Hi,
We need to set keys for a shader effector's gradient.
We can successfully change the gradient with the following code, but don't know how to key it.
import c4d
from c4d import gui
from c4d.modules import mograph as mo
def main() :
shader = op[c4d.ID_MG_SHADER_SHADER]
shader[c4d.SLA_GRADIENT_CYCLE] = True
shader[c4d.SLA_GRADIENT_TURBULENCE]=.30
gradient = shader[c4d.SLA_GRADIENT_GRADIENT]
#knot = gradient.GetKnot(1)
gradient.FlushKnots()
knot_1 = gradient.InsertKnot(col=c4d.Vector(20/256.0 , 40/256.0, 200/256.0), pos=0.0,index=0)
knot_2 = gradient.InsertKnot(col=c4d.Vector(55/256.0 , 200/256.0, 127/256.0), pos=0.5,index=1)
knot_3 = gradient.InsertKnot(col=c4d.Vector(75/256.0 , 230/256.0, 150/256.0), pos=1.0,index=2)
gradient.SetData(c4d.GRADIENT_INTERPOLATION, c4d.GRADIENT_INTERPOLATION_SMOOTHKNOT)
shader[c4d.SLA_GRADIENT_GRADIENT] = gradient
c4d.EventAdd()
if __name__=='__main__':
main()
I have to also key colors on lights, which we can successfully accomplish with something like the following code, and I've been trying to model the DescIDs on the lights for the gradients. When I key the gradient by hand, I see that the gradient includes r,g.b tracks for each knot, so I think I need to create r,g,b tracks for each knot, but I am not sure how to construct the DescID and DescLevels for this by code, nor can't seem to find this information anywhere. The code below shows one of the many attempts to start that process. I am clearly tripping up on the DescID and DescLevels.
Any help or direction would be greatly appreciated.
Thanks.
import c4d
from c4d.modules import mograph as mo
def CreateKey(obj,id,value,frame) :
if not obj.GetDocument() : raise Exception, "object must be in a document"
track=obj.FindCTrack(id)
if not track:
track = c4d.CTrack(obj,id)
obj.InsertTrackSorted(track)
curve=track.GetCurve()
key=curve.AddKey(c4d.BaseTime(frame,doc.GetFps()))
if type(value)==int or type(value)==float:
key["key"].SetValue(curve,value)
else:
key["key"].SetGeData(curve,value)
def main() :
r = float(64) / 255.0 #values to be read from database
g = float(12) / 255.0
b = float(123) / 255.0
#if op is the light
#CreateKey(op, c4d.DescID(c4d.DescLevel(c4d.LIGHT_COLOR,c4d.DTYPE_COLOR,0), c4d.DescLevel(c4d.VECTOR_X,c4d.DTYPE_REAL,0)), r, 0)
#CreateKey(op, c4d.DescID(c4d.DescLevel(c4d.LIGHT_COLOR,c4d.DTYPE_COLOR,0), c4d.DescLevel(c4d.VECTOR_Y,c4d.DTYPE_REAL,0)), g, 0)
#CreateKey(op, c4d.DescID(c4d.DescLevel(c4d.LIGHT_COLOR,c4d.DTYPE_COLOR,0), c4d.DescLevel(c4d.VECTOR_Z,c4d.DTYPE_REAL,0)), b, 0)
#if op is the shader effector
CreateKey(op, c4d.DescID(c4d.DescLevel(c4d.SLA_GRADIENT_GRADIENT,c4d.CUSTOMDATATYPE_GRADIENT,0), c4d.DescLevel(1), c4d.DescLevel(c4d.VECTOR_X,c4d.DTYPE_REAL,0)), r, 50)
CreateKey(op, c4d.DescID(c4d.DescLevel(c4d.SLA_GRADIENT_GRADIENT,c4d.CUSTOMDATATYPE_GRADIENT,0), c4d.DescLevel(1), c4d.DescLevel(c4d.VECTOR_Y,c4d.DTYPE_REAL,0)), g, 50)
CreateKey(op, c4d.DescID(c4d.DescLevel(c4d.SLA_GRADIENT_GRADIENT,c4d.CUSTOMDATATYPE_GRADIENT,0), c4d.DescLevel(1), c4d.DescLevel(c4d.VECTOR_Z,c4d.DTYPE_REAL,0)), b, 50)
c4d.EventAdd()
if __name__=='__main__':
main()