Point/Vertex.is_visible? how?
-
I need to determine from a tool, if a given vertex/point3d is visible to the camera.
I tried translating the point to screen-coords, getting a pickray for that point and then shooting a raytest - comparing the points. But it's no good - inaccurate.
Any ideas?
-
The vertex will have edges and possibly faces.
Make anarray
of these.
Get thevertex.position
andcamera.eye.position
.
Shoot araytest
from the eye_position to the vertex_position along that vector.
If there is nothing in the way it will return one of thearray
items [as it will get to the vertex and I think that only edges/faces get returned ?].
Test ifarray.include?(raytext[1][-1])
If there is something in the way it will not be in thearray
so you know the vertex is hidden ?
-
Ah, I was overthinking this. I tried to obtain the X, Y screen coords of where the point was and raytest that.
sp = view.screen_coords(point) ray = view.pickray(sp.x, sp.y) item = view.model.raytest(ray)
Using the camera eye was of course easier, and more logical.
c = view.camera item = view.model.raytest([c.eye, c.eye.vector_to(point)]) visible = (point == item.first)
that's all I needed.
thanks TIG
-
hmm... this is a slow method... are there alternatives?
-
If you place a temporary cpoint [or something else suitable if that is notraytest-able ?] at the eye-point and then test each vertex-position vector towards the eye-position, then if the first raytest result isn't the thing at the 'eye', the vertex can't see the eye and so the eye can't see the the vertex ? This way there are fewer things to test for hitting
?
-
I'm not sure if it's the number of items in between - I think that the raytest might be iterating the whole model to test. And I think it uses the whole model scope and not just the active - but in my tests everything is "loose" in the model scope.
-
One additional problem with raytest: if you have a group/component open and you want to get a list of visible verties/3d points, then raytest won't be any good if there is geometry outside that scope between the camera and the vertices. Even if Hide Rest of Model is enabled.
Alternative to that is to manually iterate all faces and intersect eye-point. Horrendously slow!
Advertisement