Skip to content

Commit

Permalink
Add ValueNode::BoneWeightPair
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Lopez authored and Chris Moore committed Jan 4, 2009
1 parent 1a31d9d commit 06b102c
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 2 deletions.
4 changes: 2 additions & 2 deletions synfig-core/trunk/src/synfig/Makefile.am
Expand Up @@ -38,7 +38,7 @@ VALUENODEHEADERS = \
valuenode_sine.h valuenode_step.h valuenode_stripes.h valuenode_subtract.h valuenode_switch.h \
valuenode_timedswap.h valuenode_timeloop.h valuenode_timestring.h valuenode_twotone.h \
valuenode_vectorangle.h valuenode_vectorlength.h valuenode_vectorx.h valuenode_vectory.h \
valuenode_boneinfluence.h valuenode_staticlist.h valuenode_bone.h
valuenode_boneinfluence.h valuenode_staticlist.h valuenode_bone.h valuenode_boneweightpair.h

VALUENODESOURCES = \
valuenode_add.cpp valuenode_anglestring.cpp valuenode_animated.cpp valuenode_atan2.cpp valuenode_bline.cpp \
Expand All @@ -52,7 +52,7 @@ VALUENODESOURCES = \
valuenode_sine.cpp valuenode_step.cpp valuenode_stripes.cpp valuenode_subtract.cpp valuenode_switch.cpp \
valuenode_timedswap.cpp valuenode_timeloop.cpp valuenode_timestring.cpp valuenode_twotone.cpp \
valuenode_vectorangle.cpp valuenode_vectorlength.cpp valuenode_vectorx.cpp valuenode_vectory.cpp \
valuenode_boneinfluence.cpp valuenode_staticlist.cpp valuenode_bone.cpp
valuenode_boneinfluence.cpp valuenode_staticlist.cpp valuenode_bone.cpp valuenode_boneweightpair.cpp

VALUEHEADERS = \
blinepoint.h gradient.h value.h
Expand Down
2 changes: 2 additions & 0 deletions synfig-core/trunk/src/synfig/valuenode.cpp
Expand Up @@ -46,6 +46,7 @@
#include "valuenode_composite.h"
#include "valuenode_reference.h"
#include "valuenode_boneinfluence.h"
#include "valuenode_boneweightpair.h"
#include "valuenode_bone.h"
#include "valuenode_greyed.h"
#include "valuenode_scale.h"
Expand Down Expand Up @@ -183,6 +184,7 @@ ValueNode::subsys_init()
ADD_VALUENODE(ValueNode_BoneInfluence, "boneinfluence", _("Bone Influence"), RELEASE_VERSION_0_61_10); // SVN r2???
ADD_VALUENODE(ValueNode_Bone, "bone", _("Bone"), RELEASE_VERSION_0_61_10); // SVN r2???
ADD_VALUENODE2(ValueNode_StaticList, "static_list", _("Static List"), RELEASE_VERSION_0_61_10); // SVN r2???
ADD_VALUENODE(ValueNode_BoneWeightPair, "boneweightpair", _("BoneWeightPair"), RELEASE_VERSION_0_61_10); // SVN r2???

#undef ADD_VALUENODE
#undef ADD_VALUENODE2
Expand Down
189 changes: 189 additions & 0 deletions synfig-core/trunk/src/synfig/valuenode_boneweightpair.cpp
@@ -0,0 +1,189 @@
/* === S Y N F I G ========================================================= */
/*! \file valuenode_boneweightpair.cpp
** \brief Implementation of the "BoneWeightPair" valuenode conversion.
**
** $Id$
**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
** Copyright (c) 2007, 2008 Chris Moore
** Copyright (c) 2008 Carlos López
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License, or (at your option) any later version.
**
** This package is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
** \endlegal
*/
/* ========================================================================= */

/* === H E A D E R S ======================================================= */

#ifdef USING_PCH
# include "pch.h"
#else
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "valuenode_boneweightpair.h"
#include "valuenode_const.h"
#include "general.h"
#include "matrix.h"

#endif

/* === U S I N G =========================================================== */

using namespace std;
using namespace etl;
using namespace synfig;

/* === M A C R O S ========================================================= */

/* === G L O B A L S ======================================================= */

/* === P R O C E D U R E S ================================================= */

/* === M E T H O D S ======================================================= */

ValueNode_BoneWeightPair::ValueNode_BoneWeightPair(const ValueBase &value):
LinkableValueNode(value.get_type())
{
switch(value.get_type())
{
case ValueBase::TYPE_MATRIX:
set_link("bone",ValueNode_Const::create(Bone()));
set_link("weight",ValueNode_Const::create(Real(1.0)));
break;
default:
throw Exception::BadType(ValueBase::type_local_name(value.get_type()));
}

DCAST_HACK_ENABLE();
}

LinkableValueNode*
ValueNode_BoneWeightPair::create_new()const
{
return new ValueNode_BoneWeightPair(get_type());
}

ValueNode_BoneWeightPair*
ValueNode_BoneWeightPair::create(const ValueBase &x)
{
return new ValueNode_BoneWeightPair(x);
}

ValueNode_BoneWeightPair::~ValueNode_BoneWeightPair()
{
unlink_all();
}

ValueBase
ValueNode_BoneWeightPair::operator()(Time t)const
{
if (getenv("SYNFIG_DEBUG_VALUENODE_OPERATORS"))
printf("%s:%d operator()\n", __FILE__, __LINE__);
Bone b(((*bone_)(t).get(Bone())));
return
Matrix(
b.get_setup_matrix()
*
b.get_animated_matrix()
*
(*weight_)(t).get(Real())
)
;
}


String
ValueNode_BoneWeightPair::get_name()const
{
return "boneweightpair";
}

String
ValueNode_BoneWeightPair::get_local_name()const
{
return _("BoneWeightPair");
}

bool
ValueNode_BoneWeightPair::check_type(ValueBase::Type type)
{
return type==ValueBase::TYPE_MATRIX;
}

bool
ValueNode_BoneWeightPair::set_link_vfunc(int i,ValueNode::Handle value)
{
assert(i>=0 && i<link_count());

switch(i)
{
case 0: CHECK_TYPE_AND_SET_VALUE(bone_, ValueBase::TYPE_BONE);
case 1: CHECK_TYPE_AND_SET_VALUE(weight_, ValueBase::TYPE_REAL);
}
return false;
}

ValueNode::LooseHandle
ValueNode_BoneWeightPair::get_link_vfunc(int i)const
{
assert(i>=0 && i<link_count());

if(i==0)
return bone_;
if(i==1)
return weight_;

return 0;
}

int
ValueNode_BoneWeightPair::link_count()const
{
return 2;
}

String
ValueNode_BoneWeightPair::link_name(int i)const
{
assert(i>=0 && i<link_count());

if(i==0)
return "bone";
if(i==1)
return "weight";
return String();
}

String
ValueNode_BoneWeightPair::link_local_name(int i)const
{
assert(i>=0 && i<link_count());

if(i==0)
return _("Bone");
if(i==1)
return _("Weight");
return String();
}

int
ValueNode_BoneWeightPair::get_link_index_from_name(const String &name)const
{
if(name=="bone")
return 0;
if(name=="weight")
return 1;

throw Exception::BadLinkName(name);
}
83 changes: 83 additions & 0 deletions synfig-core/trunk/src/synfig/valuenode_boneweightpair.h
@@ -0,0 +1,83 @@
/* === S Y N F I G ========================================================= */
/*! \file valuenode_boneweightpair.h
** \brief Header file for implementation of the "BoneWeightPair" valuenode conversion.
**
** $Id$
**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
** Copyright (c) 2007 Chris Moore
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version 2 of
** the License, or (at your option) any later version.
**
** This package is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
** \endlegal
*/
/* ========================================================================= */

/* === S T A R T =========================================================== */

#ifndef __SYNFIG_VALUENODE_BONEWEIGHTPAIR_H
#define __SYNFIG_VALUENODE_BONEWEIGHTPAIR_H

/* === H E A D E R S ======================================================= */

#include "valuenode.h"

/* === M A C R O S ========================================================= */

/* === C L A S S E S & S T R U C T S ======================================= */

namespace synfig {

class ValueNode_BoneWeightPair : public LinkableValueNode
{
ValueNode::RHandle bone_;
ValueNode::RHandle weight_;

ValueNode_BoneWeightPair(const ValueBase &value);

public:

typedef etl::handle<ValueNode_BoneWeightPair> Handle;
typedef etl::handle<const ValueNode_BoneWeightPair> ConstHandle;


virtual ValueBase operator()(Time t)const;

virtual ~ValueNode_BoneWeightPair();

virtual String get_name()const;
virtual String get_local_name()const;


virtual ValueNode::LooseHandle get_link_vfunc(int i)const;
virtual int link_count()const;
virtual String link_name(int i)const;

virtual String link_local_name(int i)const;
virtual int get_link_index_from_name(const String &name)const;

protected:
LinkableValueNode* create_new()const;
virtual bool set_link_vfunc(int i,ValueNode::Handle x);

public:
using synfig::LinkableValueNode::get_link_vfunc;

using synfig::LinkableValueNode::set_link_vfunc;
static bool check_type(ValueBase::Type type);
static ValueNode_BoneWeightPair* create(const ValueBase &x);
}; // END of class ValueNode_BoneWeightPair

}; // END of namespace synfig

/* === E N D =============================================================== */

#endif

0 comments on commit 06b102c

Please sign in to comment.