fix depth export, improve VR UI interaction

This commit is contained in:
2019-06-02 14:10:01 +02:00
parent e5c7a35fd2
commit d8a1a99d04
6 changed files with 93 additions and 97 deletions

View File

@@ -24,7 +24,8 @@ struct QuestController : public VRController
vrapi_GetInputTrackingState(ovr_context, id, predictedDisplayTime, &tracking); vrapi_GetInputTrackingState(ovr_context, id, predictedDisplayTime, &tracking);
glm::vec3 c_pos = glm::make_vec3((float*)&tracking.HeadPose.Pose.Position) - head_pos; glm::vec3 c_pos = glm::make_vec3((float*)&tracking.HeadPose.Pose.Position) - head_pos;
auto c_rot_ovr = ovrMatrix4f_CreateFromQuaternion(&tracking.HeadPose.Pose.Orientation); auto c_rot_ovr = ovrMatrix4f_CreateFromQuaternion(&tracking.HeadPose.Pose.Orientation);
glm::mat4 c_rot = glm::make_mat4((float*)&c_rot_ovr); auto c_rot_ovr_tp = ovrMatrix4f_Transpose(&c_rot_ovr);
glm::mat4 c_rot = glm::make_mat4((float*)&c_rot_ovr_tp);
m_mat = glm::translate(c_pos) * c_rot; m_mat = glm::translate(c_pos) * c_rot;
// update controllers // update controllers

View File

@@ -1747,29 +1747,30 @@ Here's a list of what's available in this release.
<scroll id="drop-left" color="0 0 0 .6" min-width="10" mouse-capture="true" rtl="ltr"/> <scroll id="drop-left" color="0 0 0 .6" min-width="10" mouse-capture="true" rtl="ltr"/>
<!--quick bar--> <node dir="col" width="1" grow="1">
<node justify="center" align="center" dir="col" rtl="ltr"> <!-- timeline -->
<panel-quick id="panel-quick"/> <node width="100%" shrink="1" dir="col" rtl="ltr">
<node height="0" grow="1" max-height="50"/> <border color=".3 .3 .3 .4" height="50" width="100%" pad="10" dir="row" mouse-capture="true">
<text text="Timeline: " margin="8 10 0 0"/>
<slider-h id="frames-slider" width="1" grow="1" margin="0 10 0 0"></slider-h>
<node width="30" margin="5 10 0 10">
<text id="timeline-frame" text="00" font-size="30"/>
</node>
</border>
</node>
<node dir="row" height="200" grow="1">
<!--quick bar-->
<node justify="center" align="center" dir="col" rtl="ltr">
<panel-quick id="panel-quick"/>
<node height="0" grow="1" max-height="50"/>
</node>
<!--floating area-->
<node id="floatings" color="0 0 0 1" width="1" grow="1" height="100%" rtl="ltr"/>
</node>
</node> </node>
<node id="floatings" color="0 0 0 1" width="1" grow="1" height="100%" rtl="ltr"/>
<scroll id="drop-right" color="0 0 0 .6" min-width="10" mouse-capture="true" rtl="ltr"/> <scroll id="drop-right" color="0 0 0 .6" min-width="10" mouse-capture="true" rtl="ltr"/>
<!-- timeline -->
<!--
<node height="100%" width="1" grow="1" dir="col" justify="flex-start" rtl="ltr">
<border color=".3 .3 .3 .4" height="50" width="100%" pad="10" dir="row">
<text text="Timeline: " margin="8 10 0 0"/>
<slider-h id="frames-slider" width="1" grow="1" margin="0 10 0 0"></slider-h>
<node width="30" margin="5 10 0 10">
<text id="timeline-frame" text="00" font-size="30"/>
</node>
</border>
</node>
-->
<!--<node height="100%" width="1" grow="1" dir="col" align="center" justify="flex-start" rtl="ltr"> <!--<node height="100%" width="1" grow="1" dir="col" align="center" justify="flex-start" rtl="ltr">
<border border-color="0 0 0 0" thickness="2" color=".2 .2 .2 .6" pad="10" dir="row" margin="2 0 0 0"> <border border-color="0 0 0 0" thickness="2" color=".2 .2 .2 .6" pad="10" dir="row" margin="2 0 0 0">
<node dir="col"> <node dir="col">

View File

@@ -210,34 +210,29 @@ void App::init_sidebar()
layers->on_layer_opacity_changed = [this](Node*, int idx, float value) { layers->on_layer_opacity_changed = [this](Node*, int idx, float value) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_opacity = value; canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_opacity = value;
canvas->m_canvas->m_unsaved = true; canvas->m_canvas->m_unsaved = true;
canvas->m_canvas->draw_merge();
title_update(); title_update();
}; };
layers->on_layer_visibility_changed = [this](Node*, int idx, bool visible) { layers->on_layer_visibility_changed = [this](Node*, int idx, bool visible) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_visible = visible; canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_visible = visible;
canvas->m_canvas->m_unsaved = true; canvas->m_canvas->m_unsaved = true;
canvas->m_canvas->draw_merge();
title_update(); title_update();
}; };
layers->on_layer_alpha_lock_changed = [this](Node*, int idx, bool locked) { layers->on_layer_alpha_lock_changed = [this](Node*, int idx, bool locked) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_alpha_locked = locked; canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_alpha_locked = locked;
canvas->m_canvas->m_unsaved = true; canvas->m_canvas->m_unsaved = true;
canvas->m_canvas->draw_merge();
title_update(); title_update();
}; };
layers->on_layer_blend_mode_changed = [this](Node*, int idx, int mode) { layers->on_layer_blend_mode_changed = [this](Node*, int idx, int mode) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_blend_mode = mode; canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_blend_mode = mode;
canvas->m_canvas->m_unsaved = true; canvas->m_canvas->m_unsaved = true;
canvas->m_canvas->draw_merge();
title_update(); title_update();
}; };
layers->on_layer_highlight_changed = [this](Node*, int idx, bool highlight) { layers->on_layer_highlight_changed = [this](Node*, int idx, bool highlight) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_hightlight = highlight; canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]]->m_hightlight = highlight;
canvas->m_canvas->draw_merge();
}; };
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-stroke")) if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-stroke"))
{ {

View File

@@ -1,12 +1,21 @@
#include "pch.h" #include "pch.h"
#include "app.h" #include "app.h"
#include "util.h" #include "util.h"
#include "shape.h"
#ifdef _WIN32 #ifdef _WIN32
bool win32_vr_start(); bool win32_vr_start();
void win32_vr_stop(); void win32_vr_stop();
#endif #endif
bool trigger_down = false;
cbuffer<glm::vec3> controller_points(10);
glm::vec3 controller_last_point;
const VRController* down_controller = nullptr;
glm::vec2 controller_cursor;
bool ui_inside = false;
bool ui_capture = false;
Sphere controller_ray;
bool App::vr_start() bool App::vr_start()
{ {
@@ -41,12 +50,6 @@ void App::vr_draw_ui()
uirtt.unbindFramebuffer(); uirtt.unbindFramebuffer();
} }
bool trigger_down = false;
cbuffer<glm::vec3> controller_points(10);
glm::vec3 controller_last_point;
const VRController* down_controller = nullptr;
glm::vec2 controller_cursor;
bool ui_inside = false;
void App::vr_update(float dt) void App::vr_update(float dt)
{ {
glm::vec3 hit; glm::vec3 hit;
@@ -56,27 +59,25 @@ void App::vr_update(float dt)
auto r = m * glm::vec3(1, 0, 0); auto r = m * glm::vec3(1, 0, 0);
auto n = m * glm::vec3(0, 0, 1); auto n = m * glm::vec3(0, 0, 1);
auto u = m * glm::vec3(0, 1, 0); auto u = m * glm::vec3(0, 1, 0);
if (ray_intersect({ 0, 0, 0 }, vr_controllers[0].get_pos_n(), o, n, r, hit, t)) auto co = vr_controllers[0].get_pos();
auto cd = co + glm::mat3(vr_controllers[0].m_mat) * glm::vec3(0, 0, -1);
ui_inside = false;
if (ray_intersect(co, cd, o, n, r, hit, t))
{ {
glm::mat4 plane_camera = glm::lookAt(o, n, u); glm::mat4 plane_camera = glm::lookAt(o, n, u);
glm::vec4 plane_local = plane_camera * glm::vec4(hit, 1); glm::vec4 plane_local = (plane_camera * glm::vec4(hit, 1)) * 2.f;
if (glm::all(glm::lessThanEqual(glm::abs(xy(plane_local)), glm::vec2(1.5f)))) if (glm::all(glm::lessThanEqual(glm::abs(xy(plane_local)), glm::vec2(1.0f))))
{ {
controller_cursor.x = -(plane_local.x * 0.5f - 0.5f) * width; controller_cursor.x = -(plane_local.x * 0.5f - 0.5f) * width;
controller_cursor.y = height - (plane_local.y * 0.5f + 0.5f) * height - 1; controller_cursor.y = height - (plane_local.y * 0.5f + 0.5f) * height - 1;
async_start(); if (!down_controller && ui_visible)
mouse_move(controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false); {
async_end(); async_start();
ui_inside = true; mouse_move(controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false);
async_end();
ui_inside = true;
}
} }
else
{
ui_inside = false;
}
}
else
{
ui_inside = false;
} }
if (down_controller) if (down_controller)
@@ -98,22 +99,40 @@ void App::vr_analog(const VRController& c, VRController::kButton b, VRController
{ {
if (b == VRController::kButton::Trigger) if (b == VRController::kButton::Trigger)
{ {
if (a == VRController::kAction::Press) if (!down_controller && (ui_inside || ui_capture) && ui_visible)
{ {
glm::vec3 pos = c.get_pos_n() * 800.f;
async_start(); async_start();
Canvas::I->stroke_start(pos, force.x); if (a == VRController::kAction::Press)
{
mouse_down(0, controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false);
ui_capture = true;
}
else
{
mouse_up(0, controller_cursor.x, controller_cursor.y, kEventSource::Mouse, false);
ui_capture = false;
}
async_end(); async_end();
controller_last_point = pos;
controller_points.clear();
down_controller = &c;
} }
if (a == VRController::kAction::Release) else
{ {
down_controller = nullptr; if (a == VRController::kAction::Press)
async_start(); {
Canvas::I->stroke_end(); glm::vec3 pos = c.get_pos_n() * 800.f;
async_end(); async_start();
Canvas::I->stroke_start(pos, force.x);
async_end();
controller_last_point = pos;
controller_points.clear();
down_controller = &c;
}
if (a == VRController::kAction::Release)
{
down_controller = nullptr;
async_start();
Canvas::I->stroke_end();
async_end();
}
} }
} }
} }
@@ -129,15 +148,6 @@ void App::vr_digital(const VRController& c, VRController::kButton b, VRControlle
toggle_ui(); toggle_ui();
} }
} }
if (b == VRController::kButton::A)
{
async_start();
if (a == VRController::kAction::Press)
mouse_down(0, controller_cursor.x, controller_cursor.y, 1.f, kEventSource::Mouse, false);
else
mouse_up(0, controller_cursor.x, controller_cursor.y, kEventSource::Mouse, false);
async_end();
}
} }
void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat4& pose) void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat4& pose)
@@ -299,7 +309,7 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
} }
} }
float tan_fov = glm::tan(glm::radians(canvas->m_canvas->m_cam_fov / 2.f)); float tan_fov = glm::tan(glm::radians(canvas->m_canvas->m_cam_fov / 2.f)) * 0.5f;
glm::vec3 aspect = { (float)uirtt.getWidth() / (float)uirtt.getHeight(), 1.f, 1.f }; glm::vec3 aspect = { (float)uirtt.getWidth() / (float)uirtt.getHeight(), 1.f, 1.f };
// draw the frame // draw the frame
@@ -419,22 +429,22 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
tex.unbind(); tex.unbind();
} }
/* glm::mat4 ortho_proj(1);
for (auto& mode : *m_canvas->m_mode)
for (auto& mode : *canvas->m_canvas->m_mode)
mode->on_Draw(ortho_proj, proj, camera); mode->on_Draw(ortho_proj, proj, camera);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
if (m_canvas->m_smask_active) if (canvas->m_canvas->m_smask_active)
{ {
m_canvas->modes[(int)kCanvasMode::MaskFree][0]->on_Draw(ortho_proj, proj, camera); canvas->m_canvas->modes[(int)kCanvasMode::MaskFree][0]->on_Draw(ortho_proj, proj, camera);
m_canvas->modes[(int)kCanvasMode::MaskLine][0]->on_Draw(ortho_proj, proj, camera); canvas->m_canvas->modes[(int)kCanvasMode::MaskLine][0]->on_Draw(ortho_proj, proj, camera);
} }
// keep drawing the grids // keep drawing the grids
if (m_canvas->m_state != kCanvasMode::Grid) if (canvas->m_canvas->m_current_mode != kCanvasMode::Grid)
for (auto& mode : Canvas::modes[(int)kCanvasMode::Grid]) for (auto& mode : Canvas::modes[(int)kCanvasMode::Grid])
mode->on_Draw(ortho_proj, proj, camera); mode->on_Draw(ortho_proj, proj, camera);
*/
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND); blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
depth ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST); depth ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);

View File

@@ -143,13 +143,11 @@ void Canvas::clear(const glm::vec4& c/*={0,0,0,1}*/)
snap_history({ 0, 1, 2, 3, 4, 5 }); snap_history({ 0, 1, 2, 3, 4, 5 });
m_layers[m_current_layer_idx]->clear(c); m_layers[m_current_layer_idx]->clear(c);
m_unsaved = true; m_unsaved = true;
draw_merge();
} }
void Canvas::clear_all() void Canvas::clear_all()
{ {
for (auto& l : m_layers) for (auto& l : m_layers)
l->clear({0, 0, 0, 0}); l->clear({0, 0, 0, 0});
draw_merge();
} }
void Canvas::snap_history(const std::vector<int>& planes) void Canvas::snap_history(const std::vector<int>& planes)
{ {
@@ -630,8 +628,6 @@ void Canvas::stroke_draw()
stroke_commit(); stroke_commit();
m_current_stroke = nullptr; m_current_stroke = nullptr;
} }
draw_merge(merge_faces);
} }
bool Canvas::point_trace(glm::vec2 loc, glm::vec3& ray_origin, glm::vec3& ray_dir, bool Canvas::point_trace(glm::vec2 loc, glm::vec3& ray_origin, glm::vec3& ray_dir,
glm::vec3& hit_pos, glm::vec2& fb_pos, glm::vec3& hit_normal, int& out_plane_id) glm::vec3& hit_pos, glm::vec2& fb_pos, glm::vec3& hit_normal, int& out_plane_id)
@@ -897,13 +893,10 @@ void Canvas::stroke_commit()
action->m_canvas = this; action->m_canvas = this;
//action->m_stroke = std::move(m_current_stroke); //action->m_stroke = std::move(m_current_stroke);
ActionManager::add(action); ActionManager::add(action);
draw_merge();
} }
void Canvas::draw_merge(std::array<bool, 6> faces /*= SIXPLETTE(false)*/) void Canvas::draw_merge(std::array<bool, 6> faces /*= SIXPLETTE(false)*/)
{ {
return;
gl_state gl; gl_state gl;
gl.save(); gl.save();
glViewport(0, 0, m_width, m_height); glViewport(0, 0, m_width, m_height);
@@ -1237,7 +1230,6 @@ void Canvas::layer_add(std::string name)
m_layers.back()->create(m_width, m_height, name); m_layers.back()->create(m_width, m_height, name);
m_order.push_back(idx); m_order.push_back(idx);
m_current_layer_idx = idx; m_current_layer_idx = idx;
draw_merge();
} }
void Canvas::layer_remove(int idx) // m_order index void Canvas::layer_remove(int idx) // m_order index
{ {
@@ -1249,12 +1241,10 @@ void Canvas::layer_remove(int idx) // m_order index
m_layers.erase(m_layers.begin() + n); m_layers.erase(m_layers.begin() + n);
m_order.erase(m_order.begin() + idx); m_order.erase(m_order.begin() + idx);
m_current_layer_idx = m_order[std::min<int>((int)m_layers.size() - 1, idx)]; m_current_layer_idx = m_order[std::min<int>((int)m_layers.size() - 1, idx)];
draw_merge();
} }
void Canvas::layer_order(int idx, int pos) // m_order index void Canvas::layer_order(int idx, int pos) // m_order index
{ {
std::swap(m_order[idx], m_order[pos]); std::swap(m_order[idx], m_order[pos]);
draw_merge();
} }
void Canvas::layer_merge(int source_idx, int dest_idx) // m_layer index void Canvas::layer_merge(int source_idx, int dest_idx) // m_layer index
{ {
@@ -1347,7 +1337,6 @@ void Canvas::layer_merge(int source_idx, int dest_idx) // m_layer index
action->m_stroke = std::move(m_current_stroke); action->m_stroke = std::move(m_current_stroke);
ActionManager::add(action); ActionManager::add(action);
*/ */
draw_merge();
} }
void Canvas::resize(int width, int height) void Canvas::resize(int width, int height)
{ {
@@ -1367,12 +1356,12 @@ void Canvas::resize(int width, int height)
//#endif //#endif
m_tex2[i].create(width, height, GL_RGBA8); m_tex2[i].create(width, height, GL_RGBA8);
} }
m_layers_merge.resize(width, height);
for (auto& l : m_layers) for (auto& l : m_layers)
l->resize(width, height); l->resize(width, height);
m_smask.create(width, height, "mask"); m_smask.create(width, height, "mask");
//m_merge_rtt.create(width, height); m_layers_merge.resize(width, height);
//m_merge_tex.create(width, height); m_merge_rtt.create(width, height);
m_merge_tex.create(width, height);
m_unsaved = true; m_unsaved = true;
} }
@@ -1385,13 +1374,13 @@ void Canvas::destroy()
m_tex[i].destroy(); m_tex[i].destroy();
m_tex2[i].destroy(); m_tex2[i].destroy();
} }
m_layers_merge.destroy();
for (auto& l : m_layers) for (auto& l : m_layers)
l->destroy(); l->destroy();
m_smask.destroy(); m_smask.destroy();
m_mixer.destroy(); m_mixer.destroy();
//m_merge_rtt.destroy(); m_layers_merge.destroy();
//m_merge_tex.destroy(); m_merge_rtt.destroy();
m_merge_tex.destroy();
} }
bool Canvas::create(int width, int height) bool Canvas::create(int width, int height)
@@ -1432,15 +1421,14 @@ bool Canvas::create(int width, int height)
m_brush_shape.create(); m_brush_shape.create();
m_mesh.create(); m_mesh.create();
m_brush_mix.create(8, 8); m_brush_mix.create(8, 8);
m_layers_merge.create(width, height, "merge");
for (auto& l : m_layers) for (auto& l : m_layers)
l->create(width, height, ""); l->create(width, height, "");
m_smask.create(width, height, "mask"); m_smask.create(width, height, "mask");
//m_smask.clear({1, 1, 1, 1}); //m_smask.clear({1, 1, 1, 1});
//m_merge_rtt.create(width, height); m_layers_merge.create(width, height, "merge");
//m_merge_tex.create(width, height); m_merge_rtt.create(width, height);
m_merge_tex.create(width, height);
m_unsaved = true; m_unsaved = true;
draw_merge();
return true; return true;
} }
@@ -1871,6 +1859,8 @@ void Canvas::export_depth_thread(std::string file_name)
gl_state gl; gl_state gl;
gl.save(); gl.save();
draw_merge();
glEnable(GL_BLEND); glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);

View File

@@ -1339,7 +1339,6 @@ void CanvasModeTransform::leave(kCanvasMode next)
layer->optimize(); layer->optimize();
//auto m = static_cast<CanvasModeMaskFree*>(Canvas::I->modes[(int)kCanvasMode::MaskFree][0]); //auto m = static_cast<CanvasModeMaskFree*>(Canvas::I->modes[(int)kCanvasMode::MaskFree][0]);
//m->clear(); //m->clear();
Canvas::I->draw_merge();
} }
void CanvasModeTransform::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const glm::mat4& camera) void CanvasModeTransform::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const glm::mat4& camera)