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



  • 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.



  • 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.



  • @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.