27#include <easy3d/viewer/viewer.h>
28#include <easy3d/renderer/camera.h>
29#include <easy3d/renderer/drawable_lines.h>
30#include <easy3d/renderer/drawable_points.h>
31#include <easy3d/renderer/drawable_triangles.h>
32#include <easy3d/core/types.h>
33#include <easy3d/util/resource.h>
34#include <easy3d/util/initializer.h>
57int main(
int argc,
char **argv) {
65 Viewer viewer(EXAMPLE_TITLE);
73 const std::vector<vec3> &points = resource::bunny_vertices;
76 const std::vector<unsigned int> &indices = resource::bunny_indices;
83 surface->update_vertex_buffer(points);
85 surface->update_element_buffer(indices);
94 vertices->update_vertex_buffer(points);
96 vertices->set_uniform_coloring(
vec4(1.0f, 0.0f, 0.0f, 1.0f));
102 vertices->set_impostor_type(PointsDrawable::SPHERE);
104 vertices->set_point_size(10);
113 const Box3 &box = geom::bounding_box<Box3, std::vector<vec3> >(points);
121 const std::vector<vec3> bbox_points = {
122 vec3(xmin, ymin, zmax),
vec3(xmax, ymin, zmax),
123 vec3(xmin, ymax, zmax),
vec3(xmax, ymax, zmax),
124 vec3(xmin, ymin, zmin),
vec3(xmax, ymin, zmin),
125 vec3(xmin, ymax, zmin),
vec3(xmax, ymax, zmin)
128 const std::vector<unsigned int> bbox_indices = {
129 0, 1, 2, 3, 4, 5, 6, 7,
130 0, 2, 4, 6, 1, 3, 5, 7,
131 0, 4, 2, 6, 1, 5, 3, 7
134 bbox_drawable->update_vertex_buffer(bbox_points);
136 bbox_drawable->update_element_buffer(bbox_indices);
138 bbox_drawable->set_uniform_coloring(
vec4(0.0f, 0.0f, 1.0f, 1.0f));
140 bbox_drawable->set_line_width(5.0f);
155int main(
int argc,
char **argv) {
163 Viewer viewer(EXAMPLE_TITLE);
164 viewer.set_usage(
"");
171 const std::vector<vec3> &points = resource::bunny_vertices;
174 const std::vector<unsigned int> &indices = resource::bunny_indices;
180 surface->set_update_func([&points, &indices](
Model* m,
Drawable* d) {
184 d->
update_element_buffer(indices);
188 viewer.add_drawable(surface);
200 vertices->set_uniform_coloring(
vec4(1.0f, 0.0f, 0.0f, 1.0f));
206 vertices->set_impostor_type(PointsDrawable::SPHERE);
208 vertices->set_point_size(10);
210 viewer.add_drawable(vertices);
217 bbox_drawable->set_update_func([&points](
Model* m,
Drawable* d) {
218 const Box3 &box = geom::bounding_box<Box3, std::vector<vec3> >(points);
226 const std::vector<vec3> bbox_points = {
227 vec3(xmin, ymin, zmax),
vec3(xmax, ymin, zmax),
228 vec3(xmin, ymax, zmax),
vec3(xmax, ymax, zmax),
229 vec3(xmin, ymin, zmin),
vec3(xmax, ymin, zmin),
230 vec3(xmin, ymax, zmin),
vec3(xmax, ymax, zmin)
233 const std::vector<unsigned int> bbox_indices = {
234 0, 1, 2, 3, 4, 5, 6, 7,
235 0, 2, 4, 6, 1, 3, 5, 7,
236 0, 4, 2, 6, 1, 5, 3, 7
242 d->update_element_buffer(bbox_indices);
246 bbox_drawable->set_uniform_coloring(
vec4(0.0f, 0.0f, 1.0f, 1.0f));
248 bbox_drawable->set_line_width(5.0f);
250 viewer.add_drawable(bbox_drawable);
268 void update_buffers_internal() {
278 update_element_buffer(indices);
285 MyLinesDrawable(
const std::string& name =
"") :
LinesDrawable(name) {}
288 void update_buffers_internal() {
291 const Box3 &box = geom::bounding_box<Box3, std::vector<vec3> >(points);
299 const std::vector<vec3> bbox_points = {
300 vec3(xmin, ymin, zmax),
vec3(xmax, ymin, zmax),
301 vec3(xmin, ymax, zmax),
vec3(xmax, ymax, zmax),
302 vec3(xmin, ymin, zmin),
vec3(xmax, ymin, zmin),
303 vec3(xmin, ymax, zmin),
vec3(xmax, ymax, zmin)
306 const std::vector<unsigned int> bbox_indices = {
307 0, 1, 2, 3, 4, 5, 6, 7,
308 0, 2, 4, 6, 1, 3, 5, 7,
309 0, 4, 2, 6, 1, 5, 3, 7
314 update_element_buffer(bbox_indices);
321 MyPointsDrawable(
const std::string& name =
"") :
PointsDrawable(name) {}
324 void update_buffers_internal() {
333int main(
int argc,
char **argv) {
341 Viewer viewer(EXAMPLE_TITLE);
342 viewer.set_usage(
"");
351 auto surface =
new MyTrianglesDrawable(
"faces");
353 viewer.add_drawable(surface);
358 auto vertices =
new MyPointsDrawable(
"vertices");
360 viewer.add_drawable(vertices);
362 vertices->set_uniform_coloring(
vec4(1.0f, 0.0f, 0.0f, 1.0f));
368 vertices->set_impostor_type(PointsDrawable::SPHERE);
370 vertices->set_point_size(10);
376 auto bbox_drawable =
new MyLinesDrawable(
"bbox");
378 viewer.add_drawable(bbox_drawable);
380 bbox_drawable->set_uniform_coloring(
vec4(0.0f, 0.0f, 1.0f, 1.0f));
382 bbox_drawable->set_line_width(5.0f);
The base class for drawable objects. A drawable represent a set of points, line segments,...
Definition: drawable.h:56
void update_vertex_buffer(const std::vector< vec3 > &vertices, bool dynamic=false)
Creates/Updates a single buffer.
Definition: drawable.cpp:142
FT max_coord(unsigned int axis) const
Definition: box.h:112
FT min_coord(unsigned int axis) const
Definition: box.h:103
The drawable for rendering a set of line segments, e.g., edges of a mesh, vector fields.
Definition: drawable_lines.h:40
The base class of renderable 3D models.
Definition: model.h:49
The drawable for rendering a set of points, e.g., point clouds, vertices of a mesh.
Definition: drawable_points.h:42
The drawable for rendering a set of triangles, e.g., the surface of a triangular mesh.
Definition: drawable_triangles.h:46
The built-in Easy3D viewer.
Definition: viewer.h:61
bool add_drawable(Drawable *drawable)
Add a drawable to the viewer to be visualized. After a drawable being added to the viewer,...
Definition: viewer.cpp:1302
void fit_screen(const easy3d::Model *model=nullptr)
Moves the camera so that the entire scene or the active model is centered on the screen at a proper s...
Definition: viewer.cpp:1337
int run(bool see_all=true)
Run the viewer.
Definition: viewer.cpp:1090
const std::vector< vec3 > bunny_vertices
Definition: resource.cpp:84
const std::vector< unsigned int > bunny_indices
Definition: resource.cpp:541
Definition: collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition: types.h:45
void initialize(bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition: initializer.cpp:35