Check if the point is visible

Hi, everyone, i’m creating a region selection for CAD application. I need to check if the point at mesh is visible (noone triangle at mesh block ray from cam to this point). I was going to make collision rays and calculate distance between collision surface point and vertex at mesh, but I’m looking for faster and easier solution. I think panda creates height map or smth like this for render translucent triangles, but i don’t know how to get it.

1 Like

The way you described using collision rays is probably the best way to do it and based on my understanding it is the most common way.

I don’t think that I’ve heard of such a feature, offhand.

What Panda does produce is a depth map, which is used for the majority of rendering (i.e. for both opaque and transparent geometry). This map is used to prevent elements from rendering “on top of” objects that are in front of them.

And… you could, I daresay, use the depth-map for your purposes: you might use the “project” method to find the location of your vertex on the screen, calculate the depth of the vertex, then access the corresponding position on the depth-buffer and compare the two.

But I’m not sure that it would actually be easier than just using rays.

Another approach might be to place a small quad at the location of your vertex (or just in front of it), then aim a dedicated camera at the quad and render the scene into a 1x1 buffer, with the quad being rendered in white and everything else in black. If the single-pixel rendering is white, then the vertex is presumably visible; if it’s black, then the vertex presumably isn’t visible.

(Would either of these be faster? That I do not know. You could perhaps try them and find out!)

@Serzho

I’m not sure I understand you, but you can consider this approach.

from panda3d.core import CallbackNode, OccluderNode, NodePath, BoundingBox
from direct.showbase.ShowBase import ShowBase

class Test(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        base.trackball.node().set_pos(0, 20, 0)
        base.trackball.node().set_p(45)

        point_command = CallbackNode("point 1")
        point_command.set_bounds(BoundingBox())
        point_command.set_cull_callback(self.command)
        point = NodePath(point_command)
        point.reparent_to(render)
        #point.show_bounds()

        model_point = loader.load_model("misc/rgbCube")
        model_point.set_scale(0.2)
        model_point.set_pos(0, 0, -0.5)
        model_point.reparent_to(point)

        frame = OccluderNode("frame")
        frame.set_vertices((-5, -5, 0), (5, -5, 0), (5, 5, 0), (-5, 5, 0))
        point = NodePath(frame)
        point.reparent_to(render)
        point.show()

        render.set_occluder(point)

    def command(self, cbdata):
        print (cbdata.get_data().node().name)
        cbdata.upcall()

test = Test()
test.run()

Try to look around while holding down the wheel button on the mouse.

Since you want to do a selection, maybe this snippet could help you. It uses a simple glsl shader for picking objects and could probably easily be enhanced to work for a region rather than only the mouses position. It’s also faster than using collision rays. It does require a property on each pickable object but I guess that needs to be done in most any cases anyways to make things selectable.

1 Like

By the way, there is an example of a choice in the code examples.