Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/tutorials/Tutorial_303_Viewer_Qt/main_window.cpp b/tutorials/Tutorial_303_Viewer_Qt/main_window.cpp
- index d262149..d6c010f 100644
- --- a/tutorials/Tutorial_303_Viewer_Qt/main_window.cpp
- +++ b/tutorials/Tutorial_303_Viewer_Qt/main_window.cpp
- @@ -198,6 +198,38 @@ Model* MainWindow::open(const std::string& file_name) {
- std::cout << "mesh loaded. num faces: " << mesh->n_faces() << "; "
- << "num vertices: " << mesh->n_vertices() << "; "
- << "num edges: " << mesh->n_edges() << std::endl;
- +#if 1
- + // Now let's create the drawable for the bounding box of the model.
- + // We also attached it to the model.
- + auto vertices = mesh->get_vertex_property<vec3>("v:point");
- + const auto& points = vertices.vector();
- + LinesDrawable* bbox_drawable = mesh->add_lines_drawable("bbox");
- + Box3 box;
- + // Compute the bounding box.
- + for (const auto& p : points)
- + box.add_point(p);
- + float xmin = box.min(0); float xmax = box.max(0);
- + float ymin = box.min(1); float ymax = box.max(1);
- + float zmin = box.min(2); float zmax = box.max(2);
- + // The eight vertices of the bounding box.
- + const std::vector<vec3> bbox_points = {
- + vec3(xmin, ymin, zmax), vec3(xmax, ymin, zmax),
- + vec3(xmin, ymax, zmax), vec3(xmax, ymax, zmax),
- + vec3(xmin, ymin, zmin), vec3(xmax, ymin, zmin),
- + vec3(xmin, ymax, zmin), vec3(xmax, ymax, zmin)
- + };
- + const std::vector<unsigned int> bbox_indices = {
- + 0, 1, 2, 3, 4, 5, 6, 7,
- + 0, 2, 4, 6, 1, 3, 5, 7,
- + 0, 4, 2, 6, 1, 5, 3, 7
- + };
- +
- + // Upload the vertex positions of the bounding box to the GPU.
- + bbox_drawable->update_vertex_buffer(bbox_points);
- + // Upload the vertex indices of the bounding box to the GPU.
- + bbox_drawable->update_index_buffer(bbox_indices);
- + bbox_drawable->set_default_color(vec3(1.0f, 0.0f, 0.0f)); // red color
- +#endif
- }
- }
- else { // point cloud
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement