Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login
    1. Maxon Developers Forum
    2. Nenov
    N
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 2
    • Best 0
    • Controversial 0
    • Groups 0

    Nenov

    @Nenov

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

    Nenov Unfollow Follow

    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
      N
      Nenov
    • 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 r20 python
      N
      Nenov