Navigation

    • Register
    • Login
    • Search
    1. Home
    2. Nenov
    N

    Nenov

    @Nenov

    0
    Reputation
    2
    Posts
    49
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    Nenov Follow

    Best posts made by Nenov

    This user does not have any upvoted posts yet.

    Latest posts made by Nenov

    RE: r20 python Field

    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.

    posted in Cinema 4D SDK •
    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
    
    posted in Cinema 4D SDK •