Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Skeleton Tool] Automatic change Bone Width parameter in Tool Options Panel (for Skeleton Deformation) #1698

Merged
merged 1 commit into from Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 25 additions & 2 deletions synfig-studio/src/gui/states/state_bone.cpp
Expand Up @@ -168,9 +168,9 @@ class studio::StateBone_Context : public sigc::trackable
void set_skel_deform_bone_width(Distance x){return skel_deform_bone_width_dist.set_value(x);}

Real get_bone_width() const{
if(skel_bone_width_dist.is_sensitive()){
if(skel_bone_width_dist.is_visible()){
return get_skel_bone_width();
}else if(skel_deform_bone_width_dist.is_sensitive()){
}else if(skel_deform_bone_width_dist.is_visible()){
return get_skel_deform_bone_width();
}else{
return DEFAULT_WIDTH;
Expand All @@ -181,11 +181,13 @@ class studio::StateBone_Context : public sigc::trackable
if(c_layer==0) {
save_settings();
c_layer=1;
update_tool_options(1);
load_settings();
}
else{
save_settings();
c_layer=0;
update_tool_options(0);
load_settings();
}
}
Expand All @@ -212,6 +214,7 @@ class studio::StateBone_Context : public sigc::trackable
WorkArea * get_work_area() const {return canvas_view_->get_work_area();}
int find_bone(Point point,Layer::Handle layer,int lay=0)const;
void _on_signal_change_active_bone(ValueNode::Handle node);
void _on_signal_value_desc_set(ValueDesc value_desc,ValueBase value);
int change_active_bone(ValueNode::Handle node);

void load_settings();
Expand Down Expand Up @@ -367,6 +370,8 @@ StateBone_Context::StateBone_Context(CanvasView *canvas_view) :
{
egress_on_selection_change=true;

get_canvas_interface()->set_state("bone");

/*setting up the tool options menu*/

// 0, title
Expand Down Expand Up @@ -463,6 +468,7 @@ StateBone_Context::StateBone_Context(CanvasView *canvas_view) :

//signals
get_canvas_interface()->signal_active_bone_changed().connect(sigc::mem_fun(*this,&studio::StateBone_Context::_on_signal_change_active_bone));
get_canvas_interface()->signal_value_desc_set().connect(sigc::mem_fun(*this,&studio::StateBone_Context::_on_signal_value_desc_set));

// Refresh the work area
get_work_area()->queue_draw();
Expand Down Expand Up @@ -525,6 +531,8 @@ StateBone_Context::event_refresh_tool_options(const Smach::event& /*x*/)

StateBone_Context::~StateBone_Context()
{
get_canvas_interface()->set_state("");

save_settings();
App::dialog_tool_options->clear();

Expand Down Expand Up @@ -1245,3 +1253,18 @@ StateBone_Context::change_active_bone(ValueNode::Handle node){
}
return -1;
}

void
StateBone_Context::_on_signal_value_desc_set(ValueDesc value_desc,ValueBase value) {
cout<<value_desc.get_description()<<endl;
ValueNode_Composite::Handle comp = ValueNode_Composite::Handle::cast_dynamic(value_desc.get_parent_desc().get_parent_desc().get_value_node());
if(comp){
int index = value_desc.get_index();
cout<<"cc "<<index<<endl;
if(index==7 || index==6){
if(skel_bone_width_dist.is_visible())set_skel_bone_width(Distance(value.get(Real()),synfig::Distance::SYSTEM_UNITS));
if(skel_deform_bone_width_dist.is_visible())set_skel_deform_bone_width(Distance(value.get(Real()),synfig::Distance::SYSTEM_UNITS));

}
}
}
58 changes: 58 additions & 0 deletions synfig-studio/src/synfigapp/actions/valuedescset.cpp
Expand Up @@ -199,6 +199,64 @@ Action::ValueDescSet::prepare()
{
clear();

get_canvas_interface()->signal_value_desc_set()(value_desc,value);

// If the tool is state_bone
// then both bones in a ValueNode_Composite
// should follow each other
ValueNode_Composite::Handle comp = ValueNode_Composite::Handle::cast_dynamic(value_desc.get_parent_desc().get_parent_desc().get_value_node());
if(comp && get_canvas_interface()->get_state()=="bone"){

if(value_desc.get_parent_value_node() == comp->get_link("first")){
ValueNode_Bone::Handle bone = ValueNode_Bone::Handle::cast_dynamic(comp->get_link("second"));
ValueNode_Bone::Handle bone1 = ValueNode_Bone::Handle::cast_dynamic(comp->get_link("first"));
if(bone){
Action::Handle action(Action::create("ValueDescSet"));
ValueBase svalue(0);
if(!action)
throw Error(_("Unable to find action ValueDescSet (bug)"));
int index = value_desc.get_index();
if(index==2 || index==3 || index==4){

if(index==2) {
Point p = value.get(Point());

Bone parentBone = (*bone->get_link("parent"))(time).get(Bone());
Bone parentBone1 = (*bone1->get_link("parent"))(time).get(Bone());

Matrix parentAnimMatrix = parentBone.get_animated_matrix();
Matrix parentAnimMatrix1 = parentBone1.get_animated_matrix();

p += parentAnimMatrix.get_transformed(bone->get_link(value_desc.get_index())->operator()(time).get(Point()));
p -= parentAnimMatrix1.get_transformed(-bone1->get_link(value_desc.get_index())->operator()(time).get(Point()));
svalue = ValueBase(parentAnimMatrix.get_inverted().get_transformed(p));
}else if(index==3){
Angle a = value.get(Angle());
a+=bone->get_link(value_desc.get_index())->operator()(time).get(Angle());
a-=bone1->get_link(value_desc.get_index())->operator()(time).get(Angle());
svalue = ValueBase(a);
}else if(index==4){
Real r = value.get(Real());
r+= bone->get_link(value_desc.get_index())->operator()(time).get(Real());
r-=bone1->get_link(value_desc.get_index())->operator()(time).get(Real());
svalue = ValueBase(r);
}
action->set_param("canvas",get_canvas());
action->set_param("canvas_interface",get_canvas_interface());
action->set_param("time",time);
action->set_param("new_value",svalue);
action->set_param("value_desc",ValueDesc(bone,value_desc.get_index()));

if(!action->is_ready())
throw Error(Error::TYPE_NOTREADY);

add_action(action);
}
}
}
}


Comment on lines +204 to +259
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morevnaproject @Aa20475

Does this stuff do anything? Could you please show me how/what I can make on Synfig to reach this code?
I deleted it , and the (closed) issue doesn't seem to be affected.

Copy link
Contributor Author

@Aa20475 Aa20475 Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the comment on the top says, when we are using the skeleton tool to edit a ValueNode_Composite, the offset between the bones should be maintained.

Atleast that's what I intended it to do 😅😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa! Thank you for quick answer!!

By what do you mean? With or without this code, I move/rotate a bone with Bone Tool and its children moves together with it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its children moves together with it.

@rodolforg This is not for children, it's for second bone from pair (in Skeleton Deformation layer). This code is fixing this issue - #1627
Without this code we will have wrong behavior, which is demonstrated in this video - https://www.youtube.com/watch?v=dzTPdNbqS3U&feature=youtu.be

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to work this new fixed way only with Bone Tool?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is supposed to work only when BoneTool is active. On the other hand... your question made me think... Maybe it worth to apply the same behavior for any other tool? How about to try this in separate PR? ^__^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are a synfig user and animator waaaaay more than me XD It's up to you.

// If we are a reference value node, then
// we need to distribute the changes to the
// referenced value node
Expand Down
14 changes: 13 additions & 1 deletion synfig-studio/src/synfigapp/canvasinterface.cpp
Expand Up @@ -100,7 +100,8 @@ CanvasInterface::CanvasInterface(etl::loose_handle<Instance> instance,etl::handl
instance_(instance),
canvas_(canvas),
cur_time_(canvas->rend_desc().get_frame_start()),
mode_(MODE_NORMAL|MODE_ANIMATE_PAST|MODE_ANIMATE_FUTURE)
mode_(MODE_NORMAL|MODE_ANIMATE_PAST|MODE_ANIMATE_FUTURE),
state_("")
{
set_selection_manager(get_instance()->get_selection_manager());
set_ui_interface(get_instance()->get_ui_interface());
Expand Down Expand Up @@ -190,6 +191,17 @@ CanvasInterface::get_mode()const
return mode_;
}

void
CanvasInterface::set_state(synfig::String x) {
state_=x;
}

synfig::String
CanvasInterface::get_state()const
{
return state_;
}

synfig::Layer::Handle
CanvasInterface::layer_create(
const synfig::String &id,
Expand Down
14 changes: 13 additions & 1 deletion synfig-studio/src/synfigapp/canvasinterface.h
Expand Up @@ -76,6 +76,7 @@ class CanvasInterface : public etl::shared_object, public sigc::trackable
etl::handle<UIInterface> ui_interface_;
synfig::Time cur_time_;
Mode mode_;
synfig::String state_;

sigc::signal<void,synfig::Layer::Handle> signal_layer_raised_;
sigc::signal<void,synfig::Layer::Handle> signal_layer_lowered_;
Expand All @@ -90,6 +91,7 @@ class CanvasInterface : public etl::shared_object, public sigc::trackable
sigc::signal<void,synfig::Canvas::Handle> signal_canvas_removed_;

sigc::signal<void,synfig::ValueNode::Handle> signal_value_node_added_;
sigc::signal<void,synfigapp::ValueDesc,synfig::ValueBase> signal_value_desc_set_;
sigc::signal<void,synfig::ValueNode::Handle> signal_value_node_deleted_;
sigc::signal<void,synfig::ValueNode::Handle,synfig::ValueNode::Handle> signal_value_node_replaced_;

Expand Down Expand Up @@ -167,6 +169,9 @@ class CanvasInterface : public etl::shared_object, public sigc::trackable
//! Signal called when a ValueNode has been changed
sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_changed() { return get_canvas()->signal_value_node_changed(); }

//! Signal called when a ValueDesc has been set
sigc::signal<void,synfigapp::ValueDesc,synfig::ValueBase>& signal_value_desc_set() { return signal_value_desc_set_; }

//! Signal called when a ValueNode has been renamed
sigc::signal<void,etl::handle<synfig::ValueNode> >& signal_value_node_renamed() { return get_canvas()->signal_value_node_renamed(); }

Expand Down Expand Up @@ -281,6 +286,14 @@ class CanvasInterface : public etl::shared_object, public sigc::trackable
/*! \see Mode */
Mode get_mode()const;

//! Sets the current smach
/*! \see Smach*/
void set_state(synfig::String x);

//! Retrieves the current editing mode
/*! \see Smach */
synfig::String get_state()const;



//! Creates a new layer, of type \c id at the top of the layer stack
Expand All @@ -300,7 +313,6 @@ class CanvasInterface : public etl::shared_object, public sigc::trackable
//! Adds the given ValueNode to the canvas.
bool add_value_node(synfig::ValueNode::Handle value_node, synfig::String name);


Action::ParamList generate_param_list(const synfigapp::ValueDesc &);

Action::ParamList generate_param_list(const std::list<synfigapp::ValueDesc> &);
Expand Down