Apologies, for some reason I was thinking in the context of VDB in which case the example didn't make sense, I see it was just demonstrating a way to affect odd/even clones, but the concept applies in vdb too.
N
Latest posts made by Nenov
-
RE: r20 python Field
-
r20 python Field
Hello, Quick question,what is the reason for processing the points first even then odd in the python field example code?
Also, is there somewhere I can find any other example code for use in a python Field?
Thank you,
Nickimport c4d import math from c4d.modules import mograph as mo #Welcome to the world of Python Fields def Sample(op, inputs, outputs, info): """Calculate the output values for the specified set of input points. Allocations should be avoided in Sample to maximize performance. Return false on error to cancel sampling. NOTE: Sample function is mandatory, PythonField cannot function without it. Keyword arguments: BaseObject -- the python field. FieldInput -- the points to sample. FieldOutput -- the sampling output arrays (pre-allocated). FieldInfo -- the sampling informations. """ # First pass on even points to calculate values for i in xrange(0, inputs._blockCount, 2): value = math.sin(math.pi * doc.GetTime().Get()) offsetValue = (value + 1.0) / 2.0 outputs.SetValue(i, offsetValue) # Second pass on odd points to calculate values for i in xrange(1, inputs._blockCount, 2): value = math.cos(math.pi * doc.GetTime().Get()) offsetValue = (value + 1.0) / 2.0 outputs.SetValue(i, offsetValue) # Depending on the color parameters of the Effector and FieldObject, # color arrays could be empty. if info._flags & c4d.FIELDSAMPLE_FLAG_COLOR: # First pass on even points to calculate colors for i in xrange(0, inputs._blockCount, 2): # Just use the sin-cos wave to generate a color. value = outputs.GetValue(i) outputs.SetColor(i, c4d.Vector(value, 0.0, 0.0)) outputs.SetAlpha(i, value) # Second pass on odd points to calculate colors for i in xrange(1, inputs._blockCount, 2): # Just use the sin-cos wave to generate a color. value = outputs.GetValue(i) outputs.SetColor(i, c4d.Vector(0.0, value, 0.0)) outputs.SetAlpha(i, value) # Return false to cancel further sampling. return True