Solved 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,
Nick

import 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

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.

Hi @Nenov, first of all, welcome in the plugincafe community.
No worry since it's your first post, but I would like to point you to the Q&A Functionality and How to Post Questions especially about categories.
I've setup your topic correctly and moved to the correct category.

Regarding your issue, this actually the purpose of the example to do a different operation on even and odd clones.
With that's said you can find more example in our Github repository especially theses following files:

  • field_python_color_direction.c4d
  • field_pythonmodifier_readcolor.c4d
  • field_pythonmodifier_vertexmap.c4d

If you have any question please let me know,
Cheers,
Maxime.