save camera settings on selection to avoid different result when re-projecting the selection 2d screen points transformation (does not compile because of canvas.h cyclic dependency)
This commit is contained in:
@@ -1087,11 +1087,11 @@ Here's a list of what's available in this release.
|
||||
<button-custom id="btn-layer" width="50" height="50" margin="0 0 5 0" thickness="1" border-color=".1" pad="2">
|
||||
<image path="data/ui/layers.png" width="100%" height="100%" align="center" justify="flex-end"/>
|
||||
</button-custom>
|
||||
<!--
|
||||
|
||||
<button-custom id="btn-grids-panel" width="50" height="50" margin="0 0 5 0" thickness="1" border-color=".1" pad="2">
|
||||
<image path="data/ui/grid.png" width="100%" height="100%" align="center" justify="flex-end" mips="true"/>
|
||||
</button-custom>
|
||||
-->
|
||||
|
||||
</border>
|
||||
<!-- side bar -->
|
||||
<node height="100%" dir="row" shrink="1">
|
||||
|
||||
@@ -2143,6 +2143,48 @@ std::vector<glm::vec2> ui::Canvas::face_to_shape2D(int plane_index)
|
||||
return points;
|
||||
}
|
||||
|
||||
void ui::Canvas::push_camera()
|
||||
{
|
||||
m_camera_stack.push(get_camera());
|
||||
}
|
||||
|
||||
void ui::Canvas::pop_camera()
|
||||
{
|
||||
if (!m_camera_stack.empty())
|
||||
{
|
||||
set_camera(m_camera_stack.top());
|
||||
m_camera_stack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
ui::Canvas::CameraData ui::Canvas::get_camera()
|
||||
{
|
||||
CameraData c;
|
||||
c.m_box = m_box;
|
||||
c.m_mv = m_mv;
|
||||
c.m_pan = m_pan;
|
||||
std::copy_n(m_plane_dir, 6, c.m_plane_dir);
|
||||
std::copy_n(m_plane_unproject, 6, c.m_plane_unproject);
|
||||
c.m_proj = m_proj;
|
||||
c.m_vp = m_vp;
|
||||
return c;
|
||||
}
|
||||
|
||||
void ui::Canvas::set_camera(const ui::Canvas::CameraData& c)
|
||||
{
|
||||
m_box = c.m_box;
|
||||
m_mv = c.m_mv;
|
||||
m_pan = c.m_pan;
|
||||
std::copy_n(c.m_plane_dir, 6, m_plane_dir);
|
||||
std::copy_n(c.m_plane_unproject, 6, m_plane_unproject);
|
||||
m_proj = c.m_proj;
|
||||
m_vp = c.m_vp;
|
||||
}
|
||||
|
||||
void ui::Canvas::reset_camera()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<vertex_t> ui::Canvas::triangulate_simple(const std::vector<vertex_t>& vertices)
|
||||
{
|
||||
std::vector<vertex_t> ret;
|
||||
|
||||
18
src/canvas.h
18
src/canvas.h
@@ -6,6 +6,7 @@
|
||||
#include "brush.h"
|
||||
#include "action.h"
|
||||
#include "canvas_modes.h"
|
||||
#include <stack>
|
||||
|
||||
NS_START
|
||||
|
||||
@@ -100,6 +101,17 @@ struct PPIHeader
|
||||
}
|
||||
};
|
||||
|
||||
struct CameraData
|
||||
{
|
||||
glm::mat4 m_mv{ 1 };
|
||||
glm::mat4 m_proj{ 1 };
|
||||
glm::vec4 m_box{ 0 };
|
||||
glm::vec4 m_vp{ 0 };
|
||||
glm::vec2 m_pan{ 0 };
|
||||
glm::mat4 m_plane_unproject[6] = SIXPLETTE(glm::mat4(1));
|
||||
glm::vec3 m_plane_dir[6] = SIXPLETTE(glm::vec3(0));
|
||||
};
|
||||
|
||||
class Canvas
|
||||
{
|
||||
public:
|
||||
@@ -112,6 +124,7 @@ public:
|
||||
bool m_dirty = false;
|
||||
bool m_commit_delayed = false;
|
||||
bool m_dirty_stroke = false;
|
||||
std::stack<CameraData> m_camera_stack;
|
||||
|
||||
static Canvas* I;
|
||||
NodeCanvas* m_node = nullptr;
|
||||
@@ -241,6 +254,11 @@ public:
|
||||
void project2Dpoints(std::vector<vertex_t>& vertices);
|
||||
glm::vec3 project2Dpoint(glm::vec2 pt);
|
||||
std::vector<glm::vec2> face_to_shape2D(int plane_index);
|
||||
void push_camera();
|
||||
void pop_camera();
|
||||
CameraData get_camera();
|
||||
void set_camera(const CameraData& c);
|
||||
void reset_camera();
|
||||
};
|
||||
|
||||
class ActionStroke : public Action
|
||||
|
||||
@@ -493,7 +493,7 @@ void CanvasModeMaskFree::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
{
|
||||
if (!m_points.empty())
|
||||
{
|
||||
|
||||
m_selection_cam = canvas->get_camera();
|
||||
//m_points2d = poly_intersect(poly_remove_duplicate(m_points2d), canvas->face_to_shape2D(0));
|
||||
auto drawer = [this](const glm::mat4& camera, const glm::mat4& proj) {
|
||||
//glEnable(GL_BLEND);
|
||||
@@ -910,6 +910,9 @@ void CanvasModeTransform::enter()
|
||||
canvas->m_smask_active = false;
|
||||
auto points = m->m_points2d;
|
||||
|
||||
canvas->push_camera();
|
||||
canvas->set_camera(m->m_selection_cam);
|
||||
|
||||
glm::vec2 bb_min(FLT_MAX);
|
||||
glm::vec2 bb_max(-FLT_MAX);
|
||||
for (auto p2d : points)
|
||||
@@ -1079,6 +1082,8 @@ void CanvasModeTransform::enter()
|
||||
|
||||
m_source_image.destroy();
|
||||
}
|
||||
|
||||
canvas->pop_camera();
|
||||
}
|
||||
|
||||
void CanvasModeTransform::leave()
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
#include "shape.h"
|
||||
#include "brush.h"
|
||||
#include "texture.h"
|
||||
#include "canvas.h"
|
||||
#include <poly2tri.h>
|
||||
|
||||
NS_START
|
||||
class Canvas;
|
||||
NS_END
|
||||
// NS_START
|
||||
// class Canvas;
|
||||
// NS_END
|
||||
|
||||
class CanvasMode
|
||||
{
|
||||
@@ -122,6 +123,7 @@ class CanvasModeMaskFree : public CanvasMode
|
||||
bool m_dragging = false;
|
||||
std::vector<vertex_t> m_points;
|
||||
std::vector<glm::vec2> m_points2d;
|
||||
struct ui::CameraData m_selection_cam;
|
||||
public:
|
||||
virtual void on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const glm::mat4& camera) override;
|
||||
virtual void on_MouseEvent(MouseEvent* me, glm::vec2& loc) override;
|
||||
|
||||
Reference in New Issue
Block a user