Sampling the falloff of a mograph effector? (python/R19)
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.
• the Effector (BaseObject)
• point coordinate (Vector)
• 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.
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.
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).
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.
If you have any questions, please let me know!
jenandesign 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.
P.S. if only the py4d documentation had examples like this, we would all be better programmers