Import of SessionSource: the merging of sources in session now applies

transformations of the sessionsource; so visually nothing (almost)
should change on the output.
This commit is contained in:
brunoherbelin
2021-01-30 12:26:49 +01:00
parent 843fa86c00
commit 62bc779dee
5 changed files with 94 additions and 22 deletions

View File

@@ -220,17 +220,26 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection)
handle_->shader()->color = color; handle_->shader()->color = color;
handle_active->shader()->color = color; handle_active->shader()->color = color;
// extract rotation from modelview
glm::mat4 ctm; glm::mat4 ctm;
glm::vec3 rot(0.f); glm::vec4 vec;
glm::vec4 vec = modelview * glm::vec4(1.f, 0.f, 0.f, 0.f); glm::vec3 tra, rot, sca;
rot.z = glm::orientedAngle( glm::vec3(1.f, 0.f, 0.f), glm::normalize(glm::vec3(vec)), glm::vec3(0.f, 0.f, 1.f) );
// get rotation and mirroring from the modelview
GlmToolkit::inverse_transform(modelview, tra, rot, sca);
glm::vec3 mirror = glm::sign(sca);
// // extract rotation from modelview
// glm::mat4 ctm;
// glm::vec3 rot(0.f);
// glm::vec4 vec = modelview * glm::vec4(1.f, 0.f, 0.f, 0.f);
// rot.z = glm::orientedAngle( glm::vec3(1.f, 0.f, 0.f), glm::normalize(glm::vec3(vec)), glm::vec3(0.f, 0.f, 1.f) );
// // extract scaling and mirroring
// ctm = glm::rotate(glm::identity<glm::mat4>(), -rot.z, glm::vec3(0.f, 0.f, 1.f)) * modelview ;
// vec = ctm * glm::vec4(1.f, 1.f, 0.f, 0.f);
// glm::vec4 mirror = glm::sign(vec);
// mirror.z = 1.f;
// extract scaling and mirroring
ctm = glm::rotate(glm::identity<glm::mat4>(), -rot.z, glm::vec3(0.f, 0.f, 1.f)) * modelview ;
vec = ctm * glm::vec4(1.f, 1.f, 0.f, 0.f);
glm::vec4 mirror = glm::sign(vec);
mirror.z = 1.f;
if ( type_ == Handles::RESIZE ) { if ( type_ == Handles::RESIZE ) {

View File

@@ -4,6 +4,7 @@
#include <glm/gtc/matrix_access.hpp> #include <glm/gtc/matrix_access.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/vector_angle.hpp>
#include <glm/gtc/random.hpp> #include <glm/gtc/random.hpp>
#include <chrono> #include <chrono>
@@ -27,6 +28,25 @@ glm::mat4 GlmToolkit::transform(glm::vec3 translation, glm::vec3 rotation, glm::
return View * Model; return View * Model;
} }
void GlmToolkit::inverse_transform(glm::mat4 M, glm::vec3 &translation, glm::vec3 &rotation, glm::vec3 &scale)
{
// extract rotation from modelview
glm::mat4 ctm;
glm::vec3 rot(0.f);
glm::vec4 vec = M * glm::vec4(1.f, 0.f, 0.f, 0.f);
rot.z = glm::orientedAngle( glm::vec3(1.f, 0.f, 0.f), glm::normalize(glm::vec3(vec)), glm::vec3(0.f, 0.f, 1.f) );
rotation = rot;
// extract scaling
ctm = glm::rotate(glm::identity<glm::mat4>(), -rot.z, glm::vec3(0.f, 0.f, 1.f)) * M ;
vec = ctm * glm::vec4(1.f, 1.f, 0.f, 0.f);
scale = glm::vec3(vec.x, vec.y, 1.f);
// extract translation
vec = M * glm::vec4(0.f, 0.f, 0.f, 1.f);
translation = glm::vec3(vec);
}
GlmToolkit::AxisAlignedBoundingBox::AxisAlignedBoundingBox() { GlmToolkit::AxisAlignedBoundingBox::AxisAlignedBoundingBox() {
mMin = glm::vec3(1.f); mMin = glm::vec3(1.f);

View File

@@ -13,6 +13,7 @@ uint64_t uniqueId();
// get Matrix for these transformation components // get Matrix for these transformation components
glm::mat4 transform(glm::vec3 translation, glm::vec3 rotation, glm::vec3 scale); glm::mat4 transform(glm::vec3 translation, glm::vec3 rotation, glm::vec3 scale);
void inverse_transform(glm::mat4 M, glm::vec3 &translation, glm::vec3 &rotation, glm::vec3 &scale);
class AxisAlignedBoundingBox class AxisAlignedBoundingBox
{ {

View File

@@ -17,6 +17,7 @@ using namespace tinyxml2;
#include "Settings.h" #include "Settings.h"
#include "Log.h" #include "Log.h"
#include "View.h" #include "View.h"
#include "ImageShader.h"
#include "SystemToolkit.h" #include "SystemToolkit.h"
#include "SessionCreator.h" #include "SessionCreator.h"
#include "SessionVisitor.h" #include "SessionVisitor.h"
@@ -168,8 +169,8 @@ void Mixer::update()
if (!sessionSourceToImport_.empty()) { if (!sessionSourceToImport_.empty()) {
// get the session source to be imported // get the session source to be imported
SessionSource *source = sessionSourceToImport_.back(); SessionSource *source = sessionSourceToImport_.back();
// merge the session inside this session source, and adjust alpha and depth // merge the session inside this session source
merge( source->detach(), source->alpha(), source->depth() ); merge( source );
// important: delete the sessionsource itself // important: delete the sessionsource itself
deleteSource(source); deleteSource(source);
// done with this session source // done with this session source
@@ -852,13 +853,13 @@ void Mixer::import(const std::string& filename)
#endif #endif
} }
void Mixer::import(SessionSource *s) void Mixer::import(SessionSource *source)
{ {
sessionSourceToImport_.push_back( s ); sessionSourceToImport_.push_back( source );
} }
void Mixer::merge(Session *session, float alpha, float depth) void Mixer::merge(Session *session)
{ {
if ( session == nullptr ) { if ( session == nullptr ) {
Log::Warning("Failed to import Session."); Log::Warning("Failed to import Session.");
@@ -873,13 +874,54 @@ void Mixer::merge(Session *session, float alpha, float depth)
// avoid name duplicates // avoid name duplicates
renameSource(s, s->name()); renameSource(s, s->name());
// Add source to Session
session_->addSource(s);
// Attach source to Mixer
attach(s);
}
// needs to update !
View::need_deep_update_++;
// avoid display issues
current_view_->update(0.f);
}
void Mixer::merge(SessionSource *source)
{
if ( source == nullptr ) {
Log::Warning("Failed to import Session Source.");
return;
}
// new state in history manager
Action::manager().store( source->name().c_str() + std::string(" imported."));
Session *session = source->detach();
// import every sources
for ( Source *s = session->popSource(); s != nullptr; s = session->popSource()) {
// avoid name duplicates
renameSource(s, s->name());
// scale alpha // scale alpha
if ( alpha > 0.f ) s->setAlpha( s->alpha() * source->alpha() );
s->setAlpha( s->alpha() * alpha );
// set depth at given location // set depth at given location
if ( depth > 0.f ) s->group(View::LAYER)->translation_.z = source->depth() + (s->depth() / MAX_DEPTH);
s->setDepth( depth + (s->depth() / MAX_DEPTH));
// set location
// a. transform of node to import
Group *sNode = s->group(View::GEOMETRY);
glm::mat4 sTransform = GlmToolkit::transform(sNode->translation_, sNode->rotation_, sNode->scale_);
// b. transform of session source
Group *sourceNode = source->group(View::GEOMETRY);
glm::mat4 sourceTransform = GlmToolkit::transform(sourceNode->translation_, sourceNode->rotation_, sourceNode->scale_);
// c. combined transform of source and session source
sourceTransform *= sTransform;
GlmToolkit::inverse_transform(sourceTransform, sNode->translation_, sNode->rotation_, sNode->scale_);
// Add source to Session // Add source to Session
session_->addSource(s); session_->addSource(s);
@@ -896,7 +938,6 @@ void Mixer::merge(Session *session, float alpha, float depth)
} }
void Mixer::swap() void Mixer::swap()
{ {
if (!back_session_) if (!back_session_)

View File

@@ -86,9 +86,10 @@ public:
void saveas (const std::string& filename); void saveas (const std::string& filename);
void load (const std::string& filename); void load (const std::string& filename);
void import (const std::string& filename); void import (const std::string& filename);
void import (SessionSource *s); void import (SessionSource *source);
void merge (Session *s, float alpha = -1.f, float depth = -1.f); void merge (Session *session);
void set (Session *s); void merge (SessionSource *source);
void set (Session *session);
// operations depending on transition mode // operations depending on transition mode
void close (); void close ();