New vsg::PolytopeIntersector class #1288
Replies: 4 comments 10 replies
-
Hi Robert, |
Beta Was this translation helpful? Give feedback.
-
I finally got around to testing the PolytopeIntersector and it's not working as I expected. I used the Builder to create a scene composed of a ground floor and a grid of cubes, and I then used my new rectangular interactive selector to interactively draw a rectangle. I intersected the rectangle with my scene through the Here are two screenshots from this interaction:
Now, what surprised me was that once I intersect a second cube, I no longer got the intersections with the first cube. My code is very similar to your code @robertosfield: void intersectionRect(const MouseRectSelector::Rectangle& Rect)
{
double xMin = Rect.pos.x;
double xMax = Rect.pos.x + Rect.size.x;
double yMin = Rect.pos.y;
double yMax = Rect.pos.y + Rect.size.y;
auto intersector = vsg::PolytopeIntersector::create(*_camera, xMin, yMin, xMax, yMax);
_scene->accept(*intersector);
if (intersector->intersections.empty())
return;
selectNode(); // Reset all colors
for (auto& intersection : intersector->intersections)
{
{
string name;
vector<string> names;
for (auto& node : intersection->nodePath)
{
if (node->getValue("name", name))
{
names.push_back(name);
selectNode(node);
}
}
if (names.size())
print("Names: {}\n", fmt::join(names,","));
}
}
} So why don't I get any intersections from the first cube? I'm also worried about the efficiency of this method for meshes that contain >100k primitives. In my use case, I don't care which primitives are intersected. All I want to know is whether the mesh intersects the selection rectangle. I think that in my case it would be a more efficient to draw to a "label image" texture, but I'll ask about that in a separate discussion. |
Beta Was this translation helpful? Give feedback.
-
Oh, forgot to mention, w.r.t performance, PolytopeIntersector has to tests of every triangle, line segment or point against each face of the polytope to know that it's inside, and in the case of triangles and line segments has to successively trim the primitive to find whether it's partially within the polytope. This will be expensive for scenes with large meshes. One can help lower the cost by decorating the mesh with vsg::CullGroup/CullGroup with their bounding spheres set to be a tight bound around the meshes geometry. The PolytopeIntersector/LineSegmentIntersector can then test against the bounding sphere and not traverse the subgraph if it's not intersected. Longer term I'd like to see some support built into the scene graph for acceleration structures that can be used for intersection testing, such a KdTree. The OSG has this so I've implemented this type of functionality before, it's not a trivial task though so I haven't yet tackled it for the VSG. The are alternative approaches for picking as well, each approach has it's own advantages and disadvantages. |
Beta Was this translation helpful? Give feedback.
-
Hi Robert, I found adding
What's missing is TextLayout support (for billboarding, position etc.) but we are not using this in our case, so this seems a good rudimentary solution for now. What are your thoughts? |
Beta Was this translation helpful? Give feedback.
-
Hi All,
I have completed my work on vsg::PolytopeIntersector and checked it into VSG master and vsgExamples master. vsg::PolytopeIntersector provides support for finding point, line or triangle intersections of a scene graph with a polytope. Changes are:
The usage is similar to the vsg::LineSegmentIntersector - you construct the intersector and traverse the scene graph to collect the intersections, then utilize the intersections. A common usage case is to use the intersector for picking, to create a PolytopeIntersector for this purpose you create it using the vsg::Camera and dimensions in screen space:
auto intersector = vsg::PolytopeIntersector::create(*camera, xMin, yMin, xMax, yMax);
Traverse the scene graph to find the intersections:
scenegraph->accept(*intersector);
And to process the intersections:
As part of the work I wrote a vsg::PrimitiveFunctor template class for helping map Vulkan primitive types to point, line and triangle primitives. I haven't refactored vsg::LineSegmentIntersector to use this class but that's on my TODO list as it'll make it easy to support triangle strips etc. that aren't support be the LineSegmentInteresector right now.
Beta Was this translation helpful? Give feedback.
All reactions