I’m trying to do boolean geometry that I have two meshes and would like to compute the intersection between them.
So I construct an octree from mesh A, and I check the vertices from mesh B against the octants, if there is an intersection, check the octant triangles for intersection, then I add the triangles, construct a mesh.
auto intersected_octant_faces = mn::buf_new<musa::Triangle>();
std::stack < cg::Octant *> stack;
stack.push(octree_sphere.root);
for (size_t i = 0; i < tri_mesh_cube.vertices.count; i++)
{
while (!stack.empty())
{
cg::Octant* node = stack.top();
if (!node)
break;
stack.pop();
musa::Ray ray;
ray.origin = { tri_mesh_cube.vertices[i] };
ray.dir = { 1,0,0 };
musa::Intersection_Points pts = {};
pts = musa::ray_box_intersection(ray, node->region);
if (pts.count >= 1)
{
musa::Intersection_Points t = {};
auto vertices = node->faces;
for (size_t j = 0; j < vertices.count; j += 3)
{
musa::Triangle tri{ vertices[j], vertices[j + 1], vertices[j + 2] };
t = musa::ray_triangle_intersection(ray, tri);
if (t.count == 1)
{
mn::buf_push(intersected_octant_faces, tri);
}
}
}
for (auto& n : node->octants)
{
stack.push(n);
}
}
}
Right now I get just two faces as shown in the figure and not sure where is the problem.
Source: Windows Questions C++