diff --git a/.gitmodules b/.gitmodules
index e26413f..712ff4f 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -19,3 +19,6 @@
[submodule "libs/jpeg"]
path = libs/jpeg
url = https://github.com/richgel999/jpeg-compressor.git
+[submodule "libs/poly2tri"]
+ path = libs/poly2tri
+ url = https://github.com/greenm01/poly2tri
diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt
index 4a5e92b..d29613b 100644
--- a/android/CMakeLists.txt
+++ b/android/CMakeLists.txt
@@ -26,6 +26,11 @@ add_library(
../libs/tinyxml2/tinyxml2.cpp
../libs/jpeg/jpgd.cpp
../libs/jpeg/jpge.cpp
+ ../libs/poly2tri/poly2tri/common/shapes.cc
+ ../libs/poly2tri/poly2tri/sweep/advancing_front.cc
+ ../libs/poly2tri/poly2tri/sweep/cdt.cc
+ ../libs/poly2tri/poly2tri/sweep/sweep_context.cc
+ ../libs/poly2tri/poly2tri/sweep/sweep.cc
src/main/cpp/main.cpp
../engine/pch.cpp
../engine/util.cpp
@@ -84,6 +89,7 @@ target_include_directories(native-lib PRIVATE
../libs/stb
../libs/jpeg
../libs/curl-android-ios/prebuilt-with-ssl/android/include
+ ../libs/poly2tri/poly2tri
)
# add lib dependencies
diff --git a/data/layout.xml b/data/layout.xml
index 5b7e1cf..d1c72e5 100644
--- a/data/layout.xml
+++ b/data/layout.xml
@@ -521,7 +521,7 @@
-
+
diff --git a/engine.xcodeproj/project.pbxproj b/engine.xcodeproj/project.pbxproj
index 25f1edd..e30bf9b 100644
--- a/engine.xcodeproj/project.pbxproj
+++ b/engine.xcodeproj/project.pbxproj
@@ -196,6 +196,16 @@
ADD7D2AF1EBFA35F00D5A897 /* libcurl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2AE1EBFA35F00D5A897 /* libcurl.a */; };
ADD7D2B11EBFA42600D5A897 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2B01EBFA42600D5A897 /* libz.tbd */; };
ADD7D2B31EBFA42C00D5A897 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD7D2B21EBFA42C00D5A897 /* Security.framework */; };
+ ADE491161F86E65D00FB8E92 /* advancing_front.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491121F86D09100FB8E92 /* advancing_front.cc */; };
+ ADE491171F86E65D00FB8E92 /* cdt.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491151F86D09100FB8E92 /* cdt.cc */; };
+ ADE491181F86E65D00FB8E92 /* shapes.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491111F86D09100FB8E92 /* shapes.cc */; };
+ ADE491191F86E65D00FB8E92 /* sweep_context.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491141F86D09100FB8E92 /* sweep_context.cc */; };
+ ADE4911A1F86E65D00FB8E92 /* sweep.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491131F86D09100FB8E92 /* sweep.cc */; };
+ ADE4911B1F86E65E00FB8E92 /* advancing_front.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491121F86D09100FB8E92 /* advancing_front.cc */; };
+ ADE4911C1F86E65E00FB8E92 /* cdt.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491151F86D09100FB8E92 /* cdt.cc */; };
+ ADE4911D1F86E65E00FB8E92 /* shapes.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491111F86D09100FB8E92 /* shapes.cc */; };
+ ADE4911E1F86E65E00FB8E92 /* sweep_context.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491141F86D09100FB8E92 /* sweep_context.cc */; };
+ ADE4911F1F86E65E00FB8E92 /* sweep.cc in Sources */ = {isa = PBXBuildFile; fileRef = ADE491131F86D09100FB8E92 /* sweep.cc */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -353,6 +363,11 @@
ADD7D2AE1EBFA35F00D5A897 /* libcurl.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcurl.a; path = "../../Downloads/curl-android-ios-master/prebuilt-with-ssl/iOS/arm64/libcurl.a"; sourceTree = ""; };
ADD7D2B01EBFA42600D5A897 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; };
ADD7D2B21EBFA42C00D5A897 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; };
+ ADE491111F86D09100FB8E92 /* shapes.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = shapes.cc; path = libs/poly2tri/poly2tri/common/shapes.cc; sourceTree = ""; };
+ ADE491121F86D09100FB8E92 /* advancing_front.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = advancing_front.cc; path = libs/poly2tri/poly2tri/sweep/advancing_front.cc; sourceTree = ""; };
+ ADE491131F86D09100FB8E92 /* sweep.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = sweep.cc; path = libs/poly2tri/poly2tri/sweep/sweep.cc; sourceTree = ""; };
+ ADE491141F86D09100FB8E92 /* sweep_context.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = sweep_context.cc; path = libs/poly2tri/poly2tri/sweep/sweep_context.cc; sourceTree = ""; };
+ ADE491151F86D09100FB8E92 /* cdt.cc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = cdt.cc; path = libs/poly2tri/poly2tri/sweep/cdt.cc; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -564,6 +579,7 @@
AD58E0731E3421CB006ACC15 /* libs */ = {
isa = PBXGroup;
children = (
+ ADE491101F86D07900FB8E92 /* p2t */,
AD0E11A21ECA61B500CDA6BB /* jpge.cpp */,
AD0E119F1ECA619F00CDA6BB /* jpgd.cpp */,
AD58E0781E342205006ACC15 /* tinyxml2.cpp */,
@@ -608,6 +624,18 @@
name = "Supporting Files";
sourceTree = "";
};
+ ADE491101F86D07900FB8E92 /* p2t */ = {
+ isa = PBXGroup;
+ children = (
+ ADE491121F86D09100FB8E92 /* advancing_front.cc */,
+ ADE491151F86D09100FB8E92 /* cdt.cc */,
+ ADE491111F86D09100FB8E92 /* shapes.cc */,
+ ADE491141F86D09100FB8E92 /* sweep_context.cc */,
+ ADE491131F86D09100FB8E92 /* sweep.cc */,
+ );
+ name = p2t;
+ sourceTree = "";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -737,6 +765,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ ADE4911F1F86E65E00FB8E92 /* sweep.cc in Sources */,
AD0E5CB91ECC72AD00C35669 /* node_border.cpp in Sources */,
AD0E5CC81ECC72AD00C35669 /* node_popup_menu.cpp in Sources */,
AD0E5CB71ECC72AD00C35669 /* layout.cpp in Sources */,
@@ -752,6 +781,7 @@
AD0E5CDA1ECC72AD00C35669 /* event.cpp in Sources */,
AD0E5CCB1ECC72AD00C35669 /* node_scroll.cpp in Sources */,
AD0E5CBF1ECC72AD00C35669 /* node_dialog_open.cpp in Sources */,
+ ADE4911B1F86E65E00FB8E92 /* advancing_front.cc in Sources */,
AD0E5CE31ECC72AD00C35669 /* util.cpp in Sources */,
AD0E5CD51ECC72AD00C35669 /* asset.cpp in Sources */,
AD0E5CCA1ECC72AD00C35669 /* node_slider.cpp in Sources */,
@@ -761,6 +791,7 @@
AD0E5CDD1ECC72AD00C35669 /* log.cpp in Sources */,
AD0E5CD61ECC72AD00C35669 /* bezier.cpp in Sources */,
AD0E5CB61ECC72AD00C35669 /* Yoga.c in Sources */,
+ ADE4911D1F86E65E00FB8E92 /* shapes.cc in Sources */,
AD0E5CC51ECC72AD00C35669 /* node_panel_color.cpp in Sources */,
AD0E5CD71ECC72AD00C35669 /* brush.cpp in Sources */,
AD0E5CBE1ECC72AD00C35669 /* node_color_quad.cpp in Sources */,
@@ -781,6 +812,7 @@
AD0E5CC31ECC72AD00C35669 /* node_message_box.cpp in Sources */,
ADC6F4631F3AFF2D004177FA /* node_dialog_layer_rename.cpp in Sources */,
AD0E5CC41ECC72AD00C35669 /* node_panel_brush.cpp in Sources */,
+ ADE4911C1F86E65E00FB8E92 /* cdt.cc in Sources */,
AD0E5CBC1ECC72AD00C35669 /* node_canvas.cpp in Sources */,
AD0E5CD01ECC72AD00C35669 /* action.cpp in Sources */,
AD0E5CC01ECC72AD00C35669 /* node_icon.cpp in Sources */,
@@ -790,6 +822,7 @@
AD0E5CBB1ECC72AD00C35669 /* node_button.cpp in Sources */,
AD0E5CD41ECC72AD00C35669 /* app_shaders.cpp in Sources */,
AD0E5CD91ECC72AD00C35669 /* canvas.cpp in Sources */,
+ ADE4911E1F86E65E00FB8E92 /* sweep_context.cc in Sources */,
AD0E5CB81ECC72AD00C35669 /* node.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -861,6 +894,7 @@
ADD7D2951EBF9E1C00D5A897 /* bezier.cpp in Sources */,
AD1063A21EC7AE92002A525F /* node_panel_brush.cpp in Sources */,
AD0E11A51ECA61B900CDA6BB /* jpgd.cpp in Sources */,
+ ADE491181F86E65D00FB8E92 /* shapes.cc in Sources */,
ADD7D29E1EBF9E1C00D5A897 /* shape.cpp in Sources */,
ADD7D2901EBF9E1C00D5A897 /* canvas_modes.cpp in Sources */,
ADC6F4621F3AFF2C004177FA /* node_dialog_layer_rename.cpp in Sources */,
@@ -875,11 +909,13 @@
AD10639E1EC7AE92002A525F /* node_icon.cpp in Sources */,
AD1063A71EC7AE92002A525F /* node_settings.cpp in Sources */,
AD0E119E1ECA215600CDA6BB /* app_shaders.cpp in Sources */,
+ ADE491171F86E65D00FB8E92 /* cdt.cc in Sources */,
ADD7D29F1EBF9E1C00D5A897 /* app.cpp in Sources */,
AD1063A41EC7AE92002A525F /* node_panel_layer.cpp in Sources */,
AD1063AA1EC7AE92002A525F /* node_text_input.cpp in Sources */,
AD0E119B1ECA215600CDA6BB /* node_scroll.cpp in Sources */,
ADD7D2941EBF9E1C00D5A897 /* asset.cpp in Sources */,
+ ADE491191F86E65D00FB8E92 /* sweep_context.cc in Sources */,
ADD7D29B1EBF9E1C00D5A897 /* layout.cpp in Sources */,
AD0E119D1ECA215600CDA6BB /* app_layout.cpp in Sources */,
AD1063991EC7AE92002A525F /* node_button.cpp in Sources */,
@@ -890,6 +926,7 @@
AD0E11A41ECA61B900CDA6BB /* jpge.cpp in Sources */,
AD10639C1EC7AE92002A525F /* node_color_quad.cpp in Sources */,
AD1063961EC7AE92002A525F /* node.cpp in Sources */,
+ ADE491161F86E65D00FB8E92 /* advancing_front.cc in Sources */,
AD10639D1EC7AE92002A525F /* node_dialog_open.cpp in Sources */,
AD1063A91EC7AE92002A525F /* node_stroke_preview.cpp in Sources */,
ADD7D2981EBF9E1C00D5A897 /* rtt.cpp in Sources */,
@@ -906,6 +943,7 @@
ADD7D2A11EBF9E1C00D5A897 /* texture.cpp in Sources */,
AD0E119C1ECA215600CDA6BB /* app_events.cpp in Sources */,
ADD7D2961EBF9E1C00D5A897 /* brush.cpp in Sources */,
+ ADE4911A1F86E65D00FB8E92 /* sweep.cc in Sources */,
AD02F0C31EDC457C00B2E692 /* sequencer.cpp in Sources */,
AD1063A51EC7AE92002A525F /* node_panel_stroke.cpp in Sources */,
ADD7D2911EBF9E1C00D5A897 /* event.cpp in Sources */,
@@ -1031,6 +1069,7 @@
libs/tinyxml2,
/opt/local/include,
libs/jpeg,
+ libs/poly2tri/poly2tri,
);
LIBRARY_SEARCH_PATHS = /opt/local/lib;
MACOSX_DEPLOYMENT_TARGET = 10.11;
@@ -1080,6 +1119,7 @@
libs/tinyxml2,
/opt/local/include,
libs/jpeg,
+ libs/poly2tri/poly2tri,
);
LIBRARY_SEARCH_PATHS = /opt/local/lib;
MACOSX_DEPLOYMENT_TARGET = 10.11;
@@ -1129,6 +1169,7 @@
libs/tinyxml2,
/opt/local/include,
libs/jpeg,
+ libs/poly2tri/poly2tri,
);
INFOPLIST_FILE = PanoPainter/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
@@ -1157,6 +1198,7 @@
libs/tinyxml2,
/opt/local/include,
libs/jpeg,
+ libs/poly2tri/poly2tri,
);
INFOPLIST_FILE = PanoPainter/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
diff --git a/engine/app_shaders.cpp b/engine/app_shaders.cpp
index 73b2b04..81b1161 100644
--- a/engine/app_shaders.cpp
+++ b/engine/app_shaders.cpp
@@ -52,6 +52,7 @@ void App::initShaders()
SHADER_VERSION
"uniform sampler2D tex;\n"
"uniform sampler2D tex_stroke;\n"
+ "uniform sampler2D tex_mask;\n"
"uniform mediump float alpha;\n"
"uniform bool lock;\n"
"in mediump vec3 uv;\n"
@@ -67,19 +68,34 @@ void App::initShaders()
SHADER_VERSION
"uniform sampler2D tex;\n"
"uniform sampler2D tex_stroke;\n"
+ "uniform sampler2D tex_mask;\n"
"uniform mediump float alpha;\n"
"uniform bool lock;\n"
+ "uniform bool mask;\n"
"in mediump vec3 uv;\n"
"out mediump vec4 frag;\n"
+ "mediump vec4 blur(sampler2D t, mediump vec2 uv){\n"
+ " mediump vec4 sum = texture(t, uv);\n"
+ " sum += textureOffset(t, uv, ivec2(-1, -1));\n"
+ " sum += textureOffset(t, uv, ivec2(-1, 0));\n"
+ " sum += textureOffset(t, uv, ivec2(-1, 1));\n"
+ " sum += textureOffset(t, uv, ivec2( 0, -1));\n"
+
+ " sum += textureOffset(t, uv, ivec2( 0, 1));\n"
+ " sum += textureOffset(t, uv, ivec2( 1, -1));\n"
+ " sum += textureOffset(t, uv, ivec2( 1, 0));\n"
+ " sum += textureOffset(t, uv, ivec2( 1, 1));\n"
+ " return sum / vec4(9.0);\n"
+ "}\n"
"void main(){\n"
" mediump vec4 base = texture(tex, uv.xy);\n"
" mediump vec4 stroke = texture(tex_stroke, uv.xy);\n"
- " stroke.a = stroke.a * alpha;\n"
+ " stroke.a = mask ? stroke.a * alpha * blur(tex_mask, uv.xy).r : stroke.a * alpha;\n"
" mediump float contribution = (1.0 - base.a) * stroke.a;\n"
" mediump float alpha_tot = base.a + contribution;"
- " mediump vec3 rgb = mix(base.rgb, stroke.rgb, stroke.a / alpha_tot);\n"
- " frag = vec4(rgb, lock ? base.a : alpha_tot);\n"
+ " mediump vec3 rgb = mix(base.rgb, stroke.rgb, (stroke.a / alpha_tot));\n"
+ " frag = vec4(rgb, (lock ? base.a : alpha_tot));\n"
"}\n";
// TEXTURE ATLAS
diff --git a/engine/canvas.cpp b/engine/canvas.cpp
index 875e0dc..de6b175 100644
--- a/engine/canvas.cpp
+++ b/engine/canvas.cpp
@@ -457,11 +457,13 @@ void ui::Canvas::stroke_commit()
m_tex2[i].bind();
m_sampler.bind(0);
m_sampler_bg.bind(1);
+ m_sampler_mask.bind(2);
if (m_state == kCanvasMode::Erase)
{
ui::ShaderManager::use(kShader::CompErase);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_int(kShaderUniform::TexStroke, 1);
+ ui::ShaderManager::u_int(kShaderUniform::TexMask, 2);
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_current_stroke->m_brush.m_tip_opacity);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
@@ -469,7 +471,11 @@ void ui::Canvas::stroke_commit()
m_tex2[i].bind();
glActiveTexture(GL_TEXTURE1);
m_tmp[i].bindTexture();
+ glActiveTexture(GL_TEXTURE2);
+ m_smask.m_rtt[i].bindTexture();
m_plane.draw_fill();
+ m_smask.m_rtt[i].unbindTexture();
+ glActiveTexture(GL_TEXTURE1);
m_tmp[i].unbindTexture();
glActiveTexture(GL_TEXTURE0);
m_tex2[i].unbind();
@@ -479,14 +485,20 @@ void ui::Canvas::stroke_commit()
ui::ShaderManager::use(kShader::CompDraw);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_int(kShaderUniform::TexStroke, 1);
+ ui::ShaderManager::u_int(kShaderUniform::TexMask, 2);
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_current_stroke->m_brush.m_tip_opacity);
+ ui::ShaderManager::u_int(kShaderUniform::Mask, m_smask_active);
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
glActiveTexture(GL_TEXTURE0);
m_tex2[i].bind();
glActiveTexture(GL_TEXTURE1);
m_tmp[i].bindTexture();
+ glActiveTexture(GL_TEXTURE2);
+ m_smask.m_rtt[i].bindTexture();
m_plane.draw_fill();
+ m_smask.m_rtt[i].unbindTexture();
+ glActiveTexture(GL_TEXTURE1);
m_tmp[i].unbindTexture();
glActiveTexture(GL_TEXTURE0);
m_tex2[i].unbind();
@@ -699,7 +711,7 @@ bool ui::Canvas::create(int width, int height)
m_sampler_brush.create();
m_sampler_brush.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
m_sampler_bg.create(GL_NEAREST);
- m_sampler_mask.create(GL_NEAREST);
+ m_sampler_mask.create(GL_LINEAR);
m_plane.create<1>(1, 1);
m_plane_brush.create<1>(1, 1);
m_mesh.create();
@@ -707,6 +719,8 @@ bool ui::Canvas::create(int width, int height)
{
l.create(width, height, "");
}
+ m_smask.create(width*2, height*2, "mask");
+ m_smask.clear({1, 1, 1, 1});
return true;
}
@@ -1246,7 +1260,7 @@ ui::Image ui::Canvas::thumbnail_read(std::string data_path)
return std::move(thumb);
}
-void ui::Canvas::draw_objects(std::function observer)
+void ui::Canvas::draw_objects(std::function observer, Layer& layer)
{
// save viewport and clear color states
GLint vp[4];
@@ -1256,18 +1270,18 @@ void ui::Canvas::draw_objects(std::function observer)
+{
+ draw_objects(observer, m_layers[m_current_layer_idx]);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////
void ui::Layer::destroy()
diff --git a/engine/canvas.h b/engine/canvas.h
index 82f4e4e..d0881e0 100644
--- a/engine/canvas.h
+++ b/engine/canvas.h
@@ -64,6 +64,8 @@ public:
std::vector m_order;
glm::vec4 m_dirty_box[6];
bool m_dirty_face[6];
+ Layer m_smask; // selection mask
+ bool m_smask_active = false;
RTT m_tmp[6];
Texture2D m_tex[6];
Texture2D m_tex2[6];
@@ -131,6 +133,7 @@ public:
ui::Image thumbnail_read(std::string data_path);
void preview_generate();
void draw_objects(std::function);
+ void draw_objects(std::function, Layer& layer);
bool ray_intersect(glm::vec3 ray_origin, glm::vec3 ray_dir, glm::vec3 plane_origin,
glm::vec3 plane_normal, glm::vec3 plane_tangent, glm::vec3 &out_hit);
void point_unproject(glm::vec2 loc, glm::vec4 vp, glm::mat4 camera, glm::mat4 proj,
diff --git a/engine/canvas_modes.cpp b/engine/canvas_modes.cpp
index 50d360a..3f9a877 100644
--- a/engine/canvas_modes.cpp
+++ b/engine/canvas_modes.cpp
@@ -6,6 +6,7 @@
#include "shader.h"
#include "node_canvas.h"
#include "app.h"
+#include
NodeCanvas* CanvasMode::node;
ui::Canvas* CanvasMode::canvas;
@@ -376,10 +377,14 @@ char get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y,
void CanvasModeFill::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
{
+ static glm::vec2 oldpos;
+ static glm::vec2 oldvec;
+ static float acc = 0.f;
switch (me->m_type)
{
case kEventType::MouseDownR:
{
+ /*
if (!m_points.empty())
{
auto drawer = [this](const glm::mat4& camera, const glm::mat4& proj) {
@@ -400,59 +405,147 @@ void CanvasModeFill::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
m_points.clear();
m_dirty_planes.clear();
}
+ */
break;
}
case kEventType::MouseDownL:
{
node->mouse_capture();
m_dragging = true;
- glm::vec3 ro, rd, hit_o, hit_d;
- glm::vec2 hit_fb;
- int plane_id;
- if (canvas->point_trace_plane(loc, ro, rd, hit_o, hit_d, hit_fb, 0))
- {
- m_dirty_planes[plane_id]++;
- ui::Shape::vertex_t v;
- v.pos = glm::vec4(hit_o, 1);
- v.uvs = glm::vec2(0);
- if (m_points.size() < 3)
- {
- m_points.push_back(v);
- }
- else
- {
- auto last = m_points.back();
- m_points.push_back(m_points[0]);
- m_points.push_back(last);
- m_points.push_back(v);
- float isx, isy;
- if (get_line_intersection(m_points[0].pos.x, m_points[0].pos.y, v.pos.x, v.pos.y, 1, -1, 1, 1, &isx, &isy))
- {
- LOG("intersection in %f %f", isx, isy);
- }
- }
- m_shape.update_vertices(m_points.data(), m_points.size());
- }
+ m_points2d.clear();
+ m_points.clear();
+ oldpos = loc;
+ oldvec = {1.f, 0.f};
+ acc = 0;
+ ui::Shape::vertex_t vert;
+ vert.pos = glm::vec4(loc, 0, 1);
+ m_points2d.push_back(loc);
+ m_points2d.push_back(loc);
+ m_points.push_back(vert);
+ m_points.push_back(vert);
+ canvas->m_smask.clear({0, 0, 0, 0});
+ canvas->m_smask_active = true;
break;
}
case kEventType::MouseUpL:
node->mouse_release();
m_dragging = false;
+ if (m_points2d.size() > 3)
+ {
+ std::vector points;
+ for (int i = 0; i < (int)m_points2d.size() - 1; i++)
+ points.push_back(new p2t::Point(m_points2d[i].x, m_points2d[i].y));
+ p2t::CDT cdt(points);
+ cdt.Triangulate();
+ auto triangles = cdt.GetTriangles();
+ std::vector v;
+ for (auto t : triangles)
+ {
+ ui::Shape::vertex_t vertex;
+ for (int i = 0; i < 3; i++)
+ {
+ auto p = t->GetPoint(i);
+
+ glm::vec3 ro, rd, hit_o, hit_d;
+ glm::vec2 hit_fb;
+ int plane_id;
+ if (canvas->point_trace({p->x, p->y}, ro, rd, hit_o, hit_fb, hit_d, plane_id))
+ {
+ m_dirty_planes[plane_id]++;
+ vertex.pos = glm::vec4(hit_o, 1);
+ v.push_back(vertex);
+ }
+ }
+ }
+ m_shape.update_vertices(v.data(), v.size());
+
+ if (!m_points.empty())
+ {
+ auto drawer = [this](const glm::mat4& camera, const glm::mat4& proj) {
+ //glEnable(GL_BLEND);
+ ui::ShaderManager::use(ui::kShader::Color);
+ ui::ShaderManager::u_mat4(ui::kShaderUniform::MVP, proj * camera);
+ ui::ShaderManager::u_vec4(ui::kShaderUniform::Col, {1, 1, 1, 1});
+ m_shape.draw_fill();
+ };
+ std::vector planes;
+ for (auto p : m_dirty_planes)
+ {
+ planes.push_back(p.first);
+ canvas->m_dirty_face[p.first] = true;
+ canvas->m_dirty_box[p.first] = { 0, 0, canvas->m_width, canvas->m_height };
+ }
+ canvas->snap_history(planes);
+ canvas->draw_objects(std::bind(drawer, std::placeholders::_1, std::placeholders::_2), canvas->m_smask);
+ m_points.clear();
+ m_dirty_planes.clear();
+ }
+ }
+ else
+ {
+ canvas->m_smask_active = false;
+ }
break;
case kEventType::MouseMove:
{
- glm::vec3 ro, rd, hit_o, hit_d;
- glm::vec2 fb_pos;
- int plane_id;
- if (m_dragging && canvas->point_trace(loc, ro, rd, hit_o, fb_pos, hit_d, plane_id))
+ if (m_dragging)
{
- ui::Shape::vertex_t v;
- v.pos = glm::vec4(hit_o, 1);
- v.uvs = glm::vec2(0);
- m_points.back() = v;
- m_shape.update_vertices(m_points.data(), m_points.size());
+ auto v = loc-oldpos;
+ float len = glm::length(v);
+ if (len > 5)
+ {
+ m_points.back().pos = glm::vec4(loc, 0, 1);
+ m_points2d.back() = loc;
+
+ v = glm::normalize(v);
+ float d = 1-glm::dot(v, oldvec);
+ acc += d;
+ oldpos = loc;
+ oldvec = v;
+ if (acc > 0.001) // angle change tollerance
+ {
+ LOG("d=%f acc=%f", d, acc);
+ acc = 0;
+
+ m_points2d.push_back(loc);
+ ui::Shape::vertex_t vert;
+ vert.pos = glm::vec4(loc, 0, 1);
+ m_points.push_back(vert);
+ m_points.push_back(vert);
+ }
+ m_shape.update_vertices(m_points.data(), m_points.size());
+ }
}
break;
+/*
+glm::vec3 ro, rd, hit_o, hit_d;
+glm::vec2 hit_fb;
+int plane_id;
+if (canvas->point_trace_plane(loc, ro, rd, hit_o, hit_d, hit_fb, 0))
+{
+ m_dirty_planes[plane_id]++;
+ ui::Shape::vertex_t v;
+ v.pos = glm::vec4(hit_o, 1);
+ v.uvs = glm::vec2(0);
+ if (m_points.size() < 3)
+ {
+ m_points.push_back(v);
+ }
+ else
+ {
+ auto last = m_points.back();
+ m_points.push_back(m_points[0]);
+ m_points.push_back(last);
+ m_points.push_back(v);
+ float isx, isy;
+ if (get_line_intersection(m_points[0].pos.x, m_points[0].pos.y, v.pos.x, v.pos.y, 1, -1, 1, 1, &isx, &isy))
+ {
+ LOG("intersection in %f %f", isx, isy);
+ }
+ }
+ m_shape.update_vertices(m_points.data(), m_points.size());
+}
+*/
}
case kEventType::MouseCancel:
if (m_dragging)
@@ -478,8 +571,8 @@ void CanvasModeFill::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, cons
if (!m_points.empty())
{
ui::ShaderManager::use(ui::kShader::Color);
- ui::ShaderManager::u_mat4(ui::kShaderUniform::MVP, proj * camera);
+ ui::ShaderManager::u_mat4(ui::kShaderUniform::MVP, glm::scale(glm::vec3(1,-1,1)) * ortho);
ui::ShaderManager::u_vec4(ui::kShaderUniform::Col, { node->m_brush.m_tip_color.rgb(), node->m_brush.m_tip_opacity });
- m_shape.draw_fill();
+ m_dragging ? m_shape.draw_stroke() : m_shape.draw_fill();
}
}
diff --git a/engine/canvas_modes.h b/engine/canvas_modes.h
index 8d0aaae..4f70430 100644
--- a/engine/canvas_modes.h
+++ b/engine/canvas_modes.h
@@ -93,6 +93,7 @@ class CanvasModeFill : public CanvasMode
ui::DynamicShape m_shape;
bool m_dragging = false;
std::vector m_points;
+ std::vector m_points2d;
std::map m_dirty_planes;
public:
virtual void on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const glm::mat4& camera) override;
diff --git a/engine/node_canvas.cpp b/engine/node_canvas.cpp
index 23fe711..ff85513 100644
--- a/engine/node_canvas.cpp
+++ b/engine/node_canvas.cpp
@@ -78,6 +78,7 @@ void NodeCanvas::draw()
m_sampler.bind(0);
m_sampler.bind(1);
+ m_sampler.bind(2);
auto blend = glIsEnabled(GL_BLEND);
auto depth = glIsEnabled(GL_DEPTH_TEST);
@@ -120,14 +121,20 @@ void NodeCanvas::draw()
ui::ShaderManager::use(kShader::CompErase);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_int(kShaderUniform::TexStroke, 1);
+ ui::ShaderManager::u_int(kShaderUniform::TexMask, 2);
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_current_stroke->m_brush.m_tip_opacity);
ui::ShaderManager::u_int(kShaderUniform::Lock, m_canvas->m_layers[m_canvas->m_current_layer_idx].m_alpha_locked);
+ ui::ShaderManager::u_int(kShaderUniform::Mask, m_canvas->m_smask_active);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
glActiveTexture(GL_TEXTURE0);
m_canvas->m_layers[layer_index].m_rtt[plane_index].bindTexture();
glActiveTexture(GL_TEXTURE1);
m_canvas->m_tmp[plane_index].bindTexture();
+ glActiveTexture(GL_TEXTURE2);
+ m_canvas->m_smask.m_rtt[plane_index].bindTexture();
m_face_plane.draw_fill();
+ m_canvas->m_smask.m_rtt[plane_index].unbindTexture();
+ glActiveTexture(GL_TEXTURE1);
m_canvas->m_tmp[plane_index].unbindTexture();
glActiveTexture(GL_TEXTURE0);
m_canvas->m_layers[layer_index].m_rtt[plane_index].unbindTexture();
@@ -137,14 +144,20 @@ void NodeCanvas::draw()
ui::ShaderManager::use(kShader::CompDraw);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_int(kShaderUniform::TexStroke, 1);
+ ui::ShaderManager::u_int(kShaderUniform::TexMask, 2);
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_current_stroke->m_brush.m_tip_opacity);
ui::ShaderManager::u_int(kShaderUniform::Lock, m_canvas->m_layers[m_canvas->m_current_layer_idx].m_alpha_locked);
+ ui::ShaderManager::u_int(kShaderUniform::Mask, m_canvas->m_smask_active);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
glActiveTexture(GL_TEXTURE0);
m_canvas->m_layers[layer_index].m_rtt[plane_index].bindTexture();
glActiveTexture(GL_TEXTURE1);
m_canvas->m_tmp[plane_index].bindTexture();
+ glActiveTexture(GL_TEXTURE2);
+ m_canvas->m_smask.m_rtt[plane_index].bindTexture();
m_face_plane.draw_fill();
+ m_canvas->m_smask.m_rtt[plane_index].unbindTexture();
+ glActiveTexture(GL_TEXTURE1);
m_canvas->m_tmp[plane_index].unbindTexture();
glActiveTexture(GL_TEXTURE0);
m_canvas->m_layers[layer_index].m_rtt[plane_index].unbindTexture();
diff --git a/engine/node_image.cpp b/engine/node_image.cpp
index d599691..fd19d0e 100644
--- a/engine/node_image.cpp
+++ b/engine/node_image.cpp
@@ -31,7 +31,7 @@ void NodeImage::clone_copy(Node* dest) const
void NodeImage::create()
{
- if (!m_path.empty() && TextureManager::load(m_path.c_str()))
+ if (!m_path.empty() && TextureManager::load(m_path.c_str(), m_use_mipmaps))
{
//LOG("load image node %s", m_path.c_str());
auto tex_sz = TextureManager::get(m_tex_id).size();
diff --git a/engine/node_image.h b/engine/node_image.h
index 76ef180..8229031 100644
--- a/engine/node_image.h
+++ b/engine/node_image.h
@@ -9,6 +9,7 @@ public:
static ui::Plane m_plane;
static Sampler m_sampler;
bool m_use_atlas = false;
+ bool m_use_mipmaps = false;
glm::vec4 m_region;
glm::vec2 m_off;
glm::vec2 m_sz;
diff --git a/engine/node_panel_brush.cpp b/engine/node_panel_brush.cpp
index 03ecf8e..9b581d7 100644
--- a/engine/node_panel_brush.cpp
+++ b/engine/node_panel_brush.cpp
@@ -26,6 +26,7 @@ void NodeButtonBrush::set_icon(const char* path)
{
img->m_path = path;
img->m_tex_id = const_hash(img->m_path.c_str());
+ img->m_use_mipmaps = true;
img->create();
}
diff --git a/engine/node_stroke_preview.cpp b/engine/node_stroke_preview.cpp
index ee19145..5fbd4ad 100644
--- a/engine/node_stroke_preview.cpp
+++ b/engine/node_stroke_preview.cpp
@@ -31,7 +31,7 @@ void NodeStrokePreview::init_controls()
m_mesh.create();
m_sampler.create();
m_sampler_brush.create();
- m_sampler_brush.set_filter(GL_LINEAR, GL_LINEAR);
+ m_sampler_brush.set_filter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
TextureManager::load("data/thumbs/Round-Hard.png");
m_brush.m_tex_id = const_hash("data/thumbs/Round-Hard.png");
}
diff --git a/engine/shader.h b/engine/shader.h
index a1becef..232c7a2 100644
--- a/engine/shader.h
+++ b/engine/shader.h
@@ -16,6 +16,7 @@ enum class kShaderUniform : uint16_t
Tof = const_hash("tof"),
Tsz = const_hash("tsz"),
Alpha = const_hash("alpha"),
+ Mask = const_hash("mask"),
Resolution = const_hash("resolution"),
Highlight = const_hash("highlight"),
};
diff --git a/libs/poly2tri b/libs/poly2tri
new file mode 160000
index 0000000..88de490
--- /dev/null
+++ b/libs/poly2tri
@@ -0,0 +1 @@
+Subproject commit 88de49021b6d9bef6faa1bc94ceb3fbd85c3c204