mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Improved implementation of crop in AppearanceView. Not yet fully
satisfying though...
This commit is contained in:
@@ -28,7 +28,7 @@ FrameBuffer::FrameBuffer(glm::vec3 resolution, bool useAlpha, bool multiSampling
|
||||
{
|
||||
attrib_.viewport = glm::ivec2(resolution);
|
||||
attrib_.clear_color = glm::vec4(0.f, 0.f, 0.f, use_alpha_ ? 0.f : 1.f);
|
||||
crop(glm::vec2(1.f, 1.f));
|
||||
setProjectionArea(glm::vec2(1.f, 1.f));
|
||||
}
|
||||
|
||||
FrameBuffer::FrameBuffer(uint width, uint height, bool useAlpha, bool multiSampling):
|
||||
@@ -37,7 +37,7 @@ FrameBuffer::FrameBuffer(uint width, uint height, bool useAlpha, bool multiSampl
|
||||
{
|
||||
attrib_.viewport = glm::ivec2(width, height);
|
||||
attrib_.clear_color = glm::vec4(0.f, 0.f, 0.f, use_alpha_ ? 0.f : 1.f);
|
||||
crop(glm::vec2(1.f, 1.f));
|
||||
setProjectionArea(glm::vec2(1.f, 1.f));
|
||||
}
|
||||
|
||||
void FrameBuffer::init()
|
||||
@@ -258,7 +258,7 @@ glm::vec2 FrameBuffer::projectionArea() const
|
||||
return projection_crop_;
|
||||
}
|
||||
|
||||
void FrameBuffer::crop(glm::vec2 c)
|
||||
void FrameBuffer::setProjectionArea(glm::vec2 c)
|
||||
{
|
||||
projection_crop_.x = CLAMP(c.x, 0.1f, 1.f);
|
||||
projection_crop_.y = CLAMP(c.y, 0.1f, 1.f);
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
// projection and crop
|
||||
glm::mat4 projection() const;
|
||||
glm::vec2 projectionArea() const;
|
||||
void crop(glm::vec2 c);
|
||||
void setProjectionArea(glm::vec2 c);
|
||||
|
||||
// internal pixel format
|
||||
inline bool use_alpha() const { return use_alpha_; }
|
||||
|
||||
20
Source.cpp
20
Source.cpp
@@ -186,6 +186,7 @@ Source::Source() : initialized_(false), active_(true), need_update_(true), symbo
|
||||
// - crop & repeat UV can be managed here
|
||||
// - additional custom shader can be associated
|
||||
texturesurface_ = new Surface(renderingshader_);
|
||||
crop_ = glm::vec2(1.f, 1.f);
|
||||
|
||||
// will be created at init
|
||||
renderbuffer_ = nullptr;
|
||||
@@ -444,14 +445,15 @@ void Source::update(float dt)
|
||||
// Aspect Ratio correction transform : coordinates of Appearance Frame are scaled by render buffer width
|
||||
glm::mat4 Ar = glm::identity<glm::mat4>();
|
||||
if (renderbuffer_)
|
||||
Ar = glm::scale(glm::identity<glm::mat4>(), glm::vec3(renderbuffer_->aspectRatio(), 1.f, 1.f) );
|
||||
Ar = glm::scale(glm::identity<glm::mat4>(), glm::vec3(renderbuffer_->aspectRatio() * crop_.x, crop_.y, 1.f) );
|
||||
// Translation : same as Appearance Frame (modified by Ar)
|
||||
glm::mat4 Tra = glm::translate(glm::identity<glm::mat4>(), groups_[View::APPEARANCE]->translation_);
|
||||
// Scaling : inverse scaling (larger UV when smaller Appearance Frame)
|
||||
glm::mat4 Sca = glm::scale(glm::identity<glm::mat4>(), glm::vec3( 1.f / groups_[View::APPEARANCE]->scale_.x,
|
||||
1.f / groups_[View::APPEARANCE]->scale_.y, 1.f));
|
||||
glm::mat4 Sca = glm::scale(glm::identity<glm::mat4>(), glm::vec3( crop_.x / groups_[View::APPEARANCE]->scale_.x,
|
||||
crop_.y / groups_[View::APPEARANCE]->scale_.y, 1.f));
|
||||
// Rotation : same angle than Appearance Frame, inverted axis
|
||||
glm::mat4 Rot = glm::rotate(glm::identity<glm::mat4>(), groups_[View::APPEARANCE]->rotation_.z, glm::vec3(0.f, 0.f, -1.f) );
|
||||
|
||||
// Combine transformations (non transitive) in this order:
|
||||
// 1. switch to Scene coordinate system
|
||||
// 2. Apply the aspect ratio correction
|
||||
@@ -462,12 +464,12 @@ void Source::update(float dt)
|
||||
// 7. switch back to UV coordinate system
|
||||
texturesurface_->shader()->iTransform = glm::inverse(UVtoScene) * Sca * glm::inverse(Ar) * Rot * Tra * Ar * UVtoScene;
|
||||
|
||||
// MODIFY CROP
|
||||
if (renderbuffer_) {
|
||||
glm::vec2 crop = renderbuffer_->projectionArea();
|
||||
groups_[View::MIXING]->scale_.x *= crop.x / crop.y;
|
||||
groups_[View::LAYER]->scale_.x = crop.x / crop.y;
|
||||
}
|
||||
// // MODIFY CROP
|
||||
// if (renderbuffer_) {
|
||||
// glm::vec2 crop = renderbuffer_->projectionArea();
|
||||
// groups_[View::MIXING]->scale_.x *= crop.x / crop.y;
|
||||
// groups_[View::LAYER]->scale_.x = crop.x / crop.y;
|
||||
// }
|
||||
|
||||
need_update_ = false;
|
||||
}
|
||||
|
||||
1
Source.h
1
Source.h
@@ -171,6 +171,7 @@ protected:
|
||||
|
||||
// surface to draw on
|
||||
Surface *texturesurface_;
|
||||
glm::vec2 crop_;
|
||||
|
||||
// mode for display
|
||||
Mode mode_;
|
||||
|
||||
72
View.cpp
72
View.cpp
@@ -1243,6 +1243,7 @@ View::Cursor GeometryView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::p
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GeometryView::terminate()
|
||||
{
|
||||
View::terminate();
|
||||
@@ -1804,9 +1805,8 @@ AppearanceView::AppearanceView() : View(APPEARANCE), edit_source_(nullptr), need
|
||||
|
||||
// surface showing the source transparency background
|
||||
backgroundpreview = new ImageSurface("images/checker.dds");
|
||||
glm::mat4 Tra = glm::translate(glm::identity<glm::mat4>(), glm::vec3( -32.f, -32.f, 0.f));
|
||||
glm::mat4 Sca = glm::scale(glm::identity<glm::mat4>(), glm::vec3( 64.f, 64.f, 1.f));
|
||||
backgroundpreview->shader()->iTransform = Tra * Sca;
|
||||
static glm::mat4 Tra = glm::scale(glm::translate(glm::identity<glm::mat4>(), glm::vec3( -32.f, -32.f, 0.f)), glm::vec3( 64.f, 64.f, 1.f));
|
||||
backgroundpreview->shader()->iTransform = Tra;
|
||||
backgroundpreview->translation_.z = 0.001f;
|
||||
scene.bg()->attach(backgroundpreview);
|
||||
// surface to show the texture of the source
|
||||
@@ -2033,7 +2033,12 @@ void AppearanceView::adjustBackground()
|
||||
// update rendering frame to match edit source AR
|
||||
image_original_width = edit_source_->frame()->aspectRatio();
|
||||
surfacepreview->setTextureIndex( edit_source_->frame()->texture() );
|
||||
image_crop_area = edit_source_->frame()->projectionArea();
|
||||
|
||||
// image_crop_area = edit_source_->frame()->projectionArea();
|
||||
image_crop_area = edit_source_->crop_;
|
||||
|
||||
surfacepreview->scale_.x = image_original_width;
|
||||
|
||||
image_crop_area.x *= image_original_width;
|
||||
}
|
||||
|
||||
@@ -2045,19 +2050,19 @@ void AppearanceView::adjustBackground()
|
||||
backgroundframe_->scale_.x = image_original_width;
|
||||
|
||||
// background of preview
|
||||
surfacepreview->scale_ = glm::vec3(image_crop_area, 1.f);
|
||||
// surfacepreview->scale_ = glm::vec3(image_crop_area, 1.f);
|
||||
backgroundpreview->scale_ = glm::vec3(image_crop_area, 1.f);
|
||||
backgroundpreview->update(0);
|
||||
glm::mat4 Ar = glm::scale(glm::identity<glm::mat4>(), glm::vec3(image_crop_area, 1.f) );
|
||||
glm::mat4 Tra = glm::translate(glm::identity<glm::mat4>(), glm::vec3( -32.f, -32.f, 0.f));
|
||||
glm::mat4 Sca = glm::scale(glm::identity<glm::mat4>(), glm::vec3( 64.f, 64.f, 1.f));
|
||||
backgroundpreview->shader()->iTransform = Ar * Tra * Sca ;
|
||||
static glm::mat4 Tra = glm::scale(glm::translate(glm::identity<glm::mat4>(), glm::vec3( -32.f, -32.f, 0.f)), glm::vec3( 64.f, 64.f, 1.f));
|
||||
backgroundpreview->shader()->iTransform = Ar * Tra;
|
||||
|
||||
// foreground
|
||||
crop_horizontal_->translation_.x = image_crop_area.x;
|
||||
crop_vertical_->translation_.y = -image_crop_area.y;
|
||||
crop_vertical_->translation_.x = -image_original_width - 0.1f;
|
||||
foregroundframe_->scale_ = glm::vec3(image_crop_area, 1.f);
|
||||
|
||||
}
|
||||
|
||||
Source *AppearanceView::getEditOrCurrentSource()
|
||||
@@ -2126,36 +2131,54 @@ View::Cursor AppearanceView::grab (Source *s, glm::vec2 from, glm::vec2 to, std:
|
||||
glm::vec3 scene_to = Rendering::manager().unProject(to, scene.root()->transform_);
|
||||
glm::vec3 scene_translation = scene_to - scene_from;
|
||||
|
||||
// work on the given source
|
||||
// Not grabbing a source
|
||||
if (!s) {
|
||||
|
||||
// work on the edited source
|
||||
if ( edit_source_ != nullptr ) {
|
||||
|
||||
// make sure matrix transform of stored status is updated
|
||||
edit_source_->stored_status_->update(0);
|
||||
// Group *sourceNode = edit_source_->group(View::GEOMETRY); // groups_[View::GEOMETRY]
|
||||
// edit_source_status_.update(0);
|
||||
|
||||
// picking on the resizing handles in the corners
|
||||
if ( pick.first == crop_horizontal_ ) {
|
||||
|
||||
// crop horizontally
|
||||
glm::vec2 cropped = edit_source_->frame()->projectionArea();
|
||||
// glm::vec2 cropped = edit_source_->frame()->projectionArea();
|
||||
// float max_width = edit_source_->frame()->aspectRatio();
|
||||
// cropped.x = CLAMP(scene_to.x, 0.2f, max_width) / max_width;
|
||||
// edit_source_->frame()->setProjectionArea(cropped);
|
||||
|
||||
float max_width = edit_source_->frame()->aspectRatio();
|
||||
cropped.x = CLAMP(scene_to.x, 0.2f, max_width) / max_width;
|
||||
edit_source_->frame()->crop(cropped);
|
||||
edit_source_->crop_.x = CLAMP(scene_to.x, 0.2f, max_width) / max_width;
|
||||
|
||||
// TODO scale GEOMETRY and RENDER groups
|
||||
edit_source_->texturesurface_->scale_.x = edit_source_->crop_.x;
|
||||
edit_source_->texturesurface_->update(0);
|
||||
|
||||
// edit_source_->group(View::GEOMETRY)->scale_ = edit_source_status_.scale_ * glm::vec3(cropped, 1.f);
|
||||
edit_source_->touch();
|
||||
|
||||
// update background and frame
|
||||
adjustBackground();
|
||||
// cursor indication
|
||||
ret.type = Cursor_ResizeEW;
|
||||
}
|
||||
if ( pick.first == crop_vertical_ ) {
|
||||
// crop vertically
|
||||
glm::vec2 cropped = edit_source_->frame()->projectionArea();
|
||||
cropped.y = -1.f * CLAMP(scene_to.y, -1.f, -0.2f);
|
||||
edit_source_->frame()->crop(cropped);
|
||||
|
||||
// // crop vertically
|
||||
// glm::vec2 cropped = edit_source_->frame()->projectionArea();
|
||||
// cropped.y = -1.f * CLAMP(scene_to.y, -1.f, -0.2f);
|
||||
// edit_source_->frame()->setProjectionArea(cropped);
|
||||
|
||||
edit_source_->crop_.y = -1.f * CLAMP(scene_to.y, -1.f, -0.2f);
|
||||
|
||||
// TODO scale GEOMETRY and RENDER groups
|
||||
edit_source_->texturesurface_->scale_.y = edit_source_->crop_.y;
|
||||
edit_source_->texturesurface_->update(0);
|
||||
|
||||
edit_source_->touch();
|
||||
|
||||
// update background and frame
|
||||
adjustBackground();
|
||||
// cursor indication
|
||||
@@ -2166,7 +2189,7 @@ View::Cursor AppearanceView::grab (Source *s, glm::vec2 from, glm::vec2 to, std:
|
||||
return ret;
|
||||
}
|
||||
|
||||
Group *sourceNode = s->group(mode_); // groups_[View::GEOMETRY]
|
||||
Group *sourceNode = s->group(mode_); // groups_[View::APPEARANCE]
|
||||
|
||||
// make sure matrix transform of stored status is updated
|
||||
s->stored_status_->update(0);
|
||||
@@ -2454,6 +2477,17 @@ View::Cursor AppearanceView::grab (Source *s, glm::vec2 from, glm::vec2 to, std:
|
||||
}
|
||||
|
||||
|
||||
//void AppearanceView::initiate()
|
||||
//{
|
||||
// View::initiate();
|
||||
|
||||
//Log::Info("AppearanceView::initiate") ;
|
||||
// if ( edit_source_ != nullptr ) {
|
||||
// Log::Info("store edit_source_status_") ;
|
||||
// edit_source_status_.copyTransform(edit_source_->group(View::GEOMETRY));
|
||||
// }
|
||||
//}
|
||||
|
||||
void AppearanceView::terminate()
|
||||
{
|
||||
View::terminate();
|
||||
|
||||
2
View.h
2
View.h
@@ -239,11 +239,13 @@ public:
|
||||
std::pair<Node *, glm::vec2> pick(glm::vec2 P) override;
|
||||
Cursor grab (Source *s, glm::vec2 from, glm::vec2 to, std::pair<Node *, glm::vec2> pick) override;
|
||||
Cursor drag (glm::vec2, glm::vec2) override;
|
||||
// void initiate() override;
|
||||
void terminate() override;
|
||||
|
||||
private:
|
||||
|
||||
Source *edit_source_;
|
||||
Group edit_source_status_;
|
||||
bool need_edit_update_;
|
||||
Source *getEditOrCurrentSource();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user