Showing several models (or several drawables of one model) side by side in a grid of views.
Overview
MultiViewer splits a single window into a rows-by-columns grid of independent viewports, each with its own camera and its own list of models/drawables. This tutorial builds a 2 x 2 layout that displays a graph, a shaded sphere surface, the sphere's wireframe, and the sphere's vertices — a convenient way to compare representations of the same data at once.
The technique
A multi-view layout is just a set of scissored viewports rendered one after another into the same framebuffer. Each cell owns a camera, so the user can navigate the views independently; mouse events are remapped to the cell under the cursor. The key idea in Easy3D is the separation between ownership and visibility: add_model()/add_drawable() give the viewer ownership of the data (and create its renderer), while assign(row, col, ...) chooses which cell actually displays it. Because a drawable can be assigned to several cells, the four views here can share one underlying sphere model while showing different drawables of it (faces, edges, vertices). Impostor rendering (cylinders for lines, spheres for points) draws thick, smoothly shaded primitives from simple vertex data, which is why the wireframe and point views look like solid tubes and balls.
Easy3D API
- MultiViewer: the grid viewer; construct it with (rows, cols) and use assign() per cell.
- Renderer: each model's renderer exposes named drawables via get_triangles_drawable(), get_lines_drawable(), and get_points_drawable().
- TrianglesDrawable / LinesDrawable / PointsDrawable: the surface, wireframe, and vertex representations; set_impostor_type(), set_line_width()/set_point_size(), and set_uniform_coloring() control their appearance.
Running it
A window opens divided into four cells. Click a cell to make it active, then drag to rotate its camera independently of the others. The top-left shows the graph, top-right the shaded sphere, bottom-left its wireframe, and bottom-right its vertices.
27#include <easy3d/viewer/viewer.h>
28#include <easy3d/core/model.h>
29#include <easy3d/renderer/renderer.h>
30#include <easy3d/renderer/drawable_points.h>
31#include <easy3d/renderer/drawable_lines.h>
32#include <easy3d/renderer/drawable_triangles.h>
33#include <easy3d/util/resource.h>
34#include <easy3d/util/initializer.h>
83int main(
int argc,
char **argv) {
92 const std::string file_graph = resource::directory() +
"/data/graph.ply";
94 auto graph = viewer.add_model(file_graph);
96 viewer.assign(0, 0, graph);
98 std::cerr <<
"failed to load model from file: " << file_graph << std::endl;
102 const std::string file_sphere = resource::directory() +
"/data/sphere.obj";
103 auto sphere = viewer.add_model(file_sphere);
106 auto sphere_faces = sphere->renderer()->get_triangles_drawable(
"faces");
107 viewer.assign(0, 1, sphere_faces);
109 std::cerr <<
"failed to load model from file: " << file_sphere << std::endl;
114 auto sphere_wireframe = sphere->renderer()->get_lines_drawable(
"edges");
116 sphere_wireframe->set_impostor_type(LinesDrawable::CYLINDER);
117 sphere_wireframe->set_line_width(6);
118 sphere_wireframe->set_uniform_coloring(
vec4(0.7f, 0.7f, 1.0f, 1.0f));
119 viewer.assign(1, 0, sphere_wireframe);
123 auto sphere_vertices = sphere->renderer()->get_points_drawable(
"vertices");
125 sphere_vertices->set_impostor_type(PointsDrawable::SPHERE);
126 sphere_vertices->set_point_size(16);
127 viewer.assign(1, 1, sphere_vertices);
A viewer that displays assigned scene content in a grid of views.
Definition multi_viewer.h:55
Definition collider.cpp:182
- See also
- MultiViewer, Renderer, LinesDrawable, PointsDrawable, Tutorial_201_Viewer_default