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

    r20 python Field

    Cinema 4D SDK
    r20 python
    2
    3
    611
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      Nenov
      last edited by Nenov

      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
      
      1 Reply Last reply Reply Quote 0
      • N
        Nenov
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by

          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.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 2
          • First post
            Last post