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

    Sampling the falloff of a mograph effector? (python/R19)

    Cinema 4D SDK
    3
    4
    1.7k
    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.
    • jenandesignJ
      jenandesign
      last edited by m_adam

      I know of the C4D_Falloff and FalloffData classes, but it is a bit over my head how to utilize them within this particular application... and unfortunately there are no examples of what I'm trying to do in the documentation or anywhere online. I am writing a python modifier for sketch & toon (which means it cannot be a plugin).

      More simply, I am trying to sample a MoGraph Effector's Falloff as the title states.

      2 inputs:
      • the Effector (BaseObject)
      • point coordinate (Vector)

      1 output:
      • falloff reading (Float between 0.0 - 1.0)

      This is something I've been wanting to be able to do for a long time in c4d python and have researched it multiple times at no avail, usually I end up resorting to roundabout setups to get things to work while in the midst of production. Thanks in advance for any leads.

      1 Reply Last reply Reply Quote 0
      • eZioPanE
        eZioPan
        last edited by

        Hi, here is a thread from the old forum: Sample Node With Python.
        I don't know if there will be any solution for now.

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

          Hi @jenandesign, first of all, welcome in the plugincafe community.

          No worry at all, since it's your first post, but I would like to point you about few rules in order to properly ask questions in this forum for future ones (I've set up this one).

          • How to Post Questions (Especially the tagging system).
          • Q&A New Functionality.

          With that's said. Regarding your question. I get it to work (a bit hacky) but it's working.
          When C4D render a scene, actually the whole scene is cloned in memory and then it renders this one. (It allow a user to still work on C4D while the other scene is rendering).
          So this render scene is read-only, you shouldn't modify at anytime anything in this scene, or you can screw up the render.
          Moreover in a shaderData, in order to optimize memory, only relevant information (aka polygon, UV) are copied. So you are losing your UserData.
          This means you have to find another way to find your effector.
          So the way I find to achieve what you want is to get the document from the object passed to the shader(the rendered document).
          Then in this document, I search for an effector called "Plain" (Not the most robust way but it's working).

          Then here the final code I put on the python color channel of a sketch and toon

          import c4d
          
          def main():
              doc = op.GetDocument()
              effector = doc.SearchObject("Plain")
              if not effector: return c4d.Vector()
              
              eff =  c4d.modules.mograph.C4D_Falloff()
              if not eff: return c4d.Vector()
              eff.InitFalloff(bc=effector.GetData())
          
              eff.SetMg(effector.GetMg())
              eff.SetMode(effector[c4d.FALLOFF_MODE])
          
               # World position currently sampled
              value = eff.Sample(wPnt, False)
              return c4d.Vector(value)
          
          

          And the attached scene where a plain effector drives a mograph effector and the sketch and toon shader.
          0_1542626486830_SketchAndToon.c4d
          0_1542626902040_sketchtoon.jpg

          If you have any questions, please let me know!
          Cheers,
          Maxime!

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          jenandesignJ 1 Reply Last reply Reply Quote 4
          • jenandesignJ
            jenandesign @m_adam
            last edited by

            @m_adam Wow, this is truly great. What a fantastically written response, I really appreciate it! Learning a bunch from this example, way more than I asked for. šŸ˜„

            Thanks again

            Jenny

            P.S. if only the py4d documentation had examples like this, we would all be better programmers šŸ˜‹

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