Dynamics Body Tag & GetVirtualObjects
-
Hello,
Is it possible that a Dynamics Body Tag added to GVO object can be assigned to all the child virtual objects. like on Fracture Object with Explode Segments mode.
a code example and screenshot below:
import c4d, os from c4d import bitmaps, plugins class Object(plugins.ObjectData): def GetVirtualObjects(self, op, hh): dirty = op.CheckCache(hh) or op.IsDirty(c4d.DIRTY_MATRIX | c4d.DIRTY_DATA) if not dirty: return op.GetCache(hh) cloner = c4d.BaseObject(1018544) if cloner is None: return c4d.BaseObject(c4d.Onull) cube = c4d.BaseObject(c4d.Ocube) if cube is None: return c4d.BaseObject(c4d.Onull) cube[c4d.PRIM_CUBE_LEN] = c4d.Vector(20.0, 20.0, 20.0) cube.InsertUnder(cloner) return cloner if __name__ == "__main__": icon = bitmaps.BaseBitmap() icon.InitWith(os.path.join("res", "icons", "icon.tif")) plugins.RegisterObjectPlugin(1078197, 'Object', Object, 'Object', c4d.OBJECT_GENERATOR, icon)
Thanks.
-
Hello @mfersaoui,
thank you for reaching out to us. Please remember adding the required tags to your postings as lined out in the Forum Guidelines. Your posting is missing information on the used OS and version of Cinema 4D. You should also formally say with a tag that this is about Python.
About your question: To answer your question formally, yes, it is possible to mirror tags hosted on the classic scene node that represents your ObjectData plugin. In GVO you get passed in that node as
node
, so you could clone its tags onto nodes you build in the cache. This is however a very unusual thing to do, since caches are caches, i.e., expressions inside a cache will not be evaluated.It is also not necessary in the case of rigid body simulations since the engine will reach into caches on its own. Your example is not very illustrative for this example, since it does only contain a single cube. So, one could not distinguish if Cinema would treat it as one object or multiple objects, but my little Python generator example at the end of the posting contains twelve cubes and works fine.
So, there are not extra steps for you to do, just return a cache with multiple objects in it and then assign a rigid body tag to the plugin node and it should work. If this does not solve your question, I would have to ask to clarify what you want to do.
Cheers,
FerdinandThe result:
The code:
"""Example for simple Python generator object that returns a cache containing multiple cube objects. This example is meant to be host a rigid body simulation tag which will drive the cube inside the cache. As discussed in: plugincafe.maxon.net/topic/13641 """ import c4d OBJ_COUNT = 12 def main(): """Simple generator that returns a cache containing multiple cube objects. """ null = c4d.BaseList2D(c4d.Onull) if null is None: raise MemoryError("Could not allocate object.") for i in range(OBJ_COUNT): cube = c4d.BaseList2D(c4d.Ocube) if cube is None: raise MemoryError("Could not allocate object.") cube.SetMl(c4d.Matrix(off=c4d.Vector(i * 250., 0, 0))) cube.InsertUnder(null) return null
-
Hello @mfersaoui,
Without any further questions, we will regard this topic as solved and flag it accordingly by Monday, September, the 8th.
Thank you for your understanding,
Ferdinand