cgv
Loading...
Searching...
No Matches
mesh_drawable.cxx
1#include <cgv/base/base.h>
2#include "mesh_drawable.h"
3#include <cgv/base/import.h>
4
5namespace cgv {
6 namespace render {
7 namespace gl {
8
11{
12 rebuild_mesh_info = false;
13}
14
17{
18 if (!rebuild_mesh_info)
19 return;
20
21 mesh_info.destruct(ctx);
22 mesh_info.construct(ctx, mesh);
23 mesh_info.bind(ctx, ctx.ref_surface_shader_program(true), true);
24}
25
28{
29 mesh_info.destruct(ctx);
30}
31
32void mesh_drawable::draw_mesh_primitive(context &ctx, unsigned pi, bool opaque, bool use_materials)
33{
34 mesh_info.draw_primitive(ctx, pi, !opaque, opaque, use_materials);
35}
36
37void mesh_drawable::draw_mesh(context &ctx, bool opaque, bool use_materials)
38{
39 mesh_info.draw_all(ctx, !opaque, opaque);
40}
41
43{
44 draw_mesh(ctx, true);
45}
46
48{
49 draw_mesh(ctx, false);
50}
51
52bool mesh_drawable::read_mesh(const std::string& _file_name)
53{
54 std::string fn = cgv::base::find_data_file(_file_name, "cpMD", "", model_path);
55 if (fn.empty()) {
56 std::cerr << "mesh file " << file_name << " not found" << std::endl;
57 return false;
58 }
59 file_name = _file_name;
60 mesh.clear();
61 if (mesh.read(file_name)) {
62 box = mesh.compute_box();
63 rebuild_mesh_info = true;
64 return true;
65 }
66 std::cerr << "could not read mesh " << file_name << std::endl;
67 return false;
68}
69
71{
73 if (!view_ptr)
74 return;
75 view_ptr->set_focus(box.get_center());
76 view_ptr->set_y_extent_at_focus(1.3*box.get_extent()(box.get_max_extent_coord_index()));
78}
79
81{
82 return box;
83}
84
85
86 }
87 }
88}
89
base class for all drawables, which is independent of the used rendering API.
Definition context.h:670
view * find_view_as_node(size_t view_idx=0) const
convenience function to find the view control in the current hierarchy
Definition drawable.cxx:49
void post_redraw()
posts a redraw event to the current context if one is available
Definition drawable.cxx:43
const box3 & get_box() const
return the axis aligned bounding box
void center_view()
call this to center the view after loading the mesh.
void draw_mesh_primitive(cgv::render::context &ctx, unsigned pi, bool opaque, bool use_materials=true)
draw all faces belonging to the given primitive, optionally turn off the specification of materials
void init_frame(cgv::render::context &ctx)
init textures if the mesh has been newly loaded
void clear(context &ctx)
clear all objects living in the context like textures or display lists
virtual bool read_mesh(const std::string &file_name)
read mesh from the given file_name which is extended by model path if it does not exist
void finish_draw(context &ctx)
default finish drawing implementation calls draw_mesh(ctx, false) to render transparent part
mesh_drawable()
construct from name which is necessary construction argument to node
std::string file_name
currently loaded file name
void draw_mesh(cgv::render::context &ctx, bool opaque, bool use_materials=true)
draw the complete mesh, optionally turn off the specification of materials
void draw(cgv::render::context &ctx)
default drawing implementation calls draw_mesh(ctx, true) to render opaque part
std::string model_path
default path to file names
box3 box
the bounding box of the mesh is computed in the read_mesh method
defines a symmetric view with the following quantities:
Definition view.h:22
std::string find_data_file(const std::string &file_name, const std::string &strategy, const std::string &sub_directory, const std::string &master_path)
Find a file with the given strategy and return the file name extended by the necessary path.
Definition import.cxx:59
namespace for opengl specific GPU programming
Definition gl.cxx:6
namespace for api independent GPU programming
this header is dependency free
Definition print.h:11
cgv::media::axis_aligned_box< float, 3 > box3
declare type of 3d single precision floating point axis-aligned boxes