Subversion Repositories gelsvn

Rev

Rev 650 | Rev 657 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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