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
    The forum rollback caused push notifications and recent user data to malfunction. The problem will fix itself naturally within the next days. See the topic Broken Push Notifications for a more in detail explanation. You can fix this yourself by forcibly clearing your browser cache (for most browsers: CTRL + F5).

    lhit from BaseVolumeData

    Cinema 4D SDK
    r21 python windows
    2
    3
    426
    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.
    • JH23J
      JH23
      last edited by

      Hi,
      I've been trying to understand what type of structure I would need to be able to access what lhit offers, although I know what a PyCobject is, I still don't understand what structure I should use, or what data it affords me, I reviewed the C++ documentation but ended up with more questions than answers, I work in python in a simple sahder, I really don't plan anything elaborate and at this point I'm just testing what information I can get to identify what will be useful to me, I would appreciate it if someone could help me with this problem

      import ctypes
      import c4d
      
      PyCObject_AsVoidPtr = ctypes.pythonapi.PyCObject_AsVoidPtr 
      PyCObject_AsVoidPtr.restype = ctypes.c_void_p
      PyCObject_AsVoidPtr.argtypes = [ctypes.py_object]
      
      def Message(sh, msg, data):
          return True
       
      def InitRender(sh, irs, customdata): 
          return c4d.INITRENDERRESULT_OK
       
      def FreeRender(sh, customdata): 
          pass 
      once = True
      def Output(sh, cd, customdata):
          global once
          if not cd.vd: 
              return c4d.Vector(0) 
      
          pyco = cd.vd.lhit
          if not pyco:
              return c4d.Vector(0)
      
          if once:
              ptr = PyCObject_AsVoidPtr(pyco)
              
              print (ptr)
              
              once = False
              
                      
          return c4d.Vector(0) 
      

      I experimented with the PyCObjects of the PolygonObjects and managed to obtain information from the indices. It is not useful to me, but I wanted to know first if it was possible, but I require prior knowledge of the information I hope to obtain. In this case, I feel blind, I would appreciate it if someone would light my way.
      thanks in advance
      JH

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

        Hi sadly there is not much you can do with it in Python. The only use case is if your want to create a kind of hashmap on the pointer, but I do not see a big use case of that to be honest. I will see if I can improve thing a bit here, because in C++ via the lhit you can retrieve the polygon and the underlying object being hit, which is important information but this is very low on my priority list. So in general regarding shader I would say you better at look at C++ since in any case doing a Shader in Python will most likely be a performance killer.

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        JH23J 1 Reply Last reply Reply Quote 0
        • JH23J
          JH23 @m_adam
          last edited by

          Hey @m_adam,
          Thanks for the reply! What you’re saying makes a lot of sense C++ is clearly the better option for this kind of stuff, especially when you need more control and better performance. I haven’t had much chance to dive into C++ yet, but I’m well aware it’s way more powerful than Python when it comes to working with the engine.
          It’s a bit of a shame that there’s no way to directly access polygon info from Python, since that’s exactly what I needed. But still, I really appreciate you taking the time to explain it.
          Cheers,
          James H.

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