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

    Dynamics Body Tag & GetVirtualObjects

    Cinema 4D SDK
    python
    2
    3
    659
    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.
    • mfersaouiM
      mfersaoui
      last edited by

      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:

      DynamicsBodyTag-GetVirtualObjects.jpg

      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.

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @mfersaoui
        last edited by ferdinand

        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,
        Ferdinand

        The 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
        

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand
          last edited by

          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

          MAXON SDK Specialist
          developers.maxon.net

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