Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    How do I find the z-depth with Python ViewportSelect.PickObject()?

    Cinema 4D SDK
    r19 python windows classic api
    2
    3
    708
    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.
    • CairynC
      Cairyn
      last edited by

      Hello; I am wondering whether the Python version of c4d.utils.ViewportSelect.PickObject() may be missing a return value.

      Within C++, I can extract the depth of the picked point with GetZ() on the returned C4DObjectList. (I didn't try this but it has been discussed before on this forum.)
      In Python, all I get is a Python list with no such method, and the list contains only objects, not object/zdepth pairs. The help text for the flags indicates that VIEWPORT_PICK_FLAGS_OGL_ONLY_TOPMOST_WITH_OBJ at least should give me a z value ("Picks only topmost object but returns the topmost object with its Z position.") but that may be just copied from the C++ help.

      So, while I can identify the object under a mouse click, I cannot find the depth of the hit point.
      Trying to get around by using other ViewportSelect methods shows that these apparently only work for polygon objects.

      What is the preferred method to find an object under the mouse cursor including the z-depth of the found hit?

      Thanks.

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

        Hi @Cairyn this is currently not possible (I've added it to our list of parity list).

        Regarding possible workarounds:

        • Use GeRayCollider from the camera to the object.
        • Use ViewportSelect such as GetPixelInfoPolygon, but as you figured you need the actual PolygonObject drawn into the ViewPort (can be the cache).

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        CairynC 1 Reply Last reply Reply Quote 1
        • CairynC
          Cairyn @m_adam
          last edited by

          @m_adam Oops. Okay, GeRayCollider works only for polygon objects, as does GetPixelInfoPolygon.

          The idea was to provide a new selection method for arbitrary objects by just checking all hits of a scattered PickObject within a radius, and then select the nearest hit. For that, I need to be able to hit splines and parametric objects as well.

          Okay, I guess I can still do that in C++ then, thanks.

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