Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
667 khor 1
//
2
//  MeshEditor.h
3
//  GEL
4
//
5
//  Created by J. Andreas Bærentzen on 09/10/13.
6
//
7
//
8
 
9
#ifndef __GEL__MeshEditor__
10
#define __GEL__MeshEditor__
11
 
12
#include <string>
13
#include "../GLGraphics/Console.h"
14
#include "../GLGraphics/VisObj.h"
15
#include "../GLGraphics/GLViewController.h"
16
 
17
namespace GLGraphics {
18
 
19
    class MeshEditor
20
    {
21
        bool console_visible;
22
 
23
        bool dragging;
24
        int mouse_x, mouse_y;
25
        float depth;
26
        HMesh::VertexAttributeVector<float> weight_vector;
27
        HMesh::VertexAttributeVector<CGLA::Vec3d> orig_pos;
28
 
29
        static const int NO_MESHES = 9;
30
        std::array<VisObj,NO_MESHES> vo;
31
        VisObj& active_visobj() { return vo[active]; }
32
        const VisObj& active_visobj() const { return vo[active]; }
33
        GLViewController& active_view_control() {
34
            return active_visobj().view_control();
35
        }
36
 
37
        Console theConsole;
38
        Console::variable<int> active;
39
        Console::variable<std::string> display_render_mode;
40
        Console::variable<float> brush_size;
41
        Console::variable<int> display_smooth_shading;
42
        Console::variable<float> display_gamma;
43
 
44
    public:
45
        MeshEditor():active(0), console_visible(false), dragging(false),  display_render_mode("normal"), brush_size(0.01), display_smooth_shading(true),
46
        display_gamma(2.2) {}
47
 
48
        /// Initialize the mesh editor. Do this only when OpenGL state is available.
49
        void init();
50
 
51
        bool select_vertex(const CGLA::Vec2i& pos) {
52
            return active_visobj().select_vertex(pos);
53
        }
54
 
55
         HMesh::VertexAttributeVector<int>& get_vertex_selection()  {
56
            return active_visobj().get_vertex_selection();
57
        }
58
 
59
 
60
 
61
        /** Tests whether the position passed as argument is on the mesh (return true) 
62
         or background (false). This function also retains the 3D unprojection of the 
63
         grabbed position. */
64
        bool grab_mesh(const CGLA::Vec2i& pos);
65
 
66
        /** Provided grab_mesh has been called and returned true, drag_mesh computes a 
67
         vector to the new position given as argument and moves a small subset of the mesh
68
         according to the vector from grabbed to dragged position. */
69
        bool drag_mesh(const CGLA::Vec2i& pos);
70
 
71
        /** Releases the mesh. We are no longer dragging. */
72
        void release_mesh();
73
 
74
        // GLViewController stuff
75
        void reshape(int w, int h);
76
        void grab_ball(TrackBallAction action, const CGLA::Vec2i& pos);
77
        void roll_ball(const CGLA::Vec2i& pos);
78
        void release_ball();
79
        bool try_spinning_ball();
80
 
81
        /// Align means that we sync view controllers.
82
        void align(int src, int dst)
83
        {
84
            vo[dst].view_control() =
85
            vo[src].view_control();
86
        }
87
 
88
        /// Make sure the object fits in the window.
89
        void refit() {
90
            active_visobj().refit();
91
        }
92
 
93
        /// Returns the name of the file whence the active mesh was loaded.
94
        const std::string& file_name() const {return active_visobj().file_name();}
95
 
96
        // Get mesh and mesh state.
97
        void save_active_mesh() {active_visobj().save_old();}
98
        void restore_active_mesh() {active_visobj().restore_old();}
99
 
100
        // Display functions ------------
101
 
102
        /// Notify the visualization object that we need to regenerate the display list.
103
        void post_create_display_list() {active_visobj().post_create_display_list();}
104
 
105
        /// Render the active mesh.
106
        void display(int scale = 1);
107
 
108
 
109
        // Console functions --------------
110
 
111
        void register_console_function(const std::string& name,
112
                                       const std::function<void(MeshEditor*, const std::vector<std::string>&)>& con_fun,
113
                                       const std::string& help_txt);
114
 
115
        void printf(const char* format, ...);
116
        void keyparse(unsigned short c);
117
        void key_up();
118
        void key_down();
119
        void key_left();
120
        void key_right();
121
        void key_home();
122
        void key_end();
123
 
124
        /// Returns a reference to active mesh.
125
        HMesh::Manifold& active_mesh() { return active_visobj().mesh(); }
126
 
127
       /// Add a file to the next empty slot.
128
        bool add_file(const std::string& str);
129
 
130
        /// Load the mesh given as argument to the current slot.
131
        bool reload_active_from_file(const std::string& str);
132
 
133
        /// Load the mesh but without clearing, effectively combining it with existing mesh.
134
        bool add_to_active_from_file(const std::string& str);
135
 
136
        void harmonics_analyze_mesh() {active_visobj().harmonics_analyze();}
137
 
138
    };
139
}
140
 
141
#endif /* defined(__GEL__MeshEditor__) */