50 #include "FileSkeleton.hh"
54 #include <OpenMesh/Core/IO/IOManager.hh>
56 #if QT_VERSION >= 0x050000
66 return QString(
"Skeleton files ( *.skl )" );
70 return QString(
"Skeleton files ( *.skl )" );
78 template<
typename Skeleton>
79 bool FileSKLPlugin::LoadSkeleton(
Skeleton *_pSkeleton, QString _filename)
85 unsigned int nJoints = 0;
87 std::ifstream in(_filename.toStdString().c_str(), std::ofstream::in);
94 std::map<unsigned int, Joint*> parents;
96 std::map<unsigned int, unsigned int> jointMap;
98 for(
unsigned int i = 0; i < nJoints; ++i)
109 for(
int y = 0; y < 3; ++y)
110 for(
int x = 0; x < 3; ++x)
112 for(
int y = 0; y < 3; ++y)
117 if(parents.find(
id) != parents.end())
118 pParent = parents[
id];
121 Joint *pJoint =
new Joint(pParent);
122 _pSkeleton->
addJoint(pParent, pJoint);
124 jointMap[ id ] = pJoint->id();
127 ref->setGlobalMatrix(jointMap[
id ], mat);
130 unsigned int nChildren;
133 for(
unsigned int j = 0; j < nChildren; ++j)
136 unsigned int idChild;
139 parents[idChild] = pJoint;
143 unsigned int num_anim = 0;
149 std::string identifier;
151 std::string animationName = (QString(
"Animation") + QString::number(num_anim)).toStdString();
154 unsigned int frameCount = 0;
157 if(identifier ==
"animation") {
158 std::getline(in, animationName);
160 animationName = QString(animationName.c_str()).trimmed().toStdString();
165 std::istringstream tmp(identifier);
170 if ( frameCount > 0 ){
173 AnimationHandle animHandle = _pSkeleton->addAnimation(animationName, animation);
175 for (
unsigned int k = 0; k < frameCount; k++){
177 animHandle.setFrame(k);
180 for(
unsigned int i = 0; i < nJoints; ++i)
190 for(
int y = 0; y < 3; ++y)
191 for(
int x = 0; x < 3; ++x)
193 for(
int y = 0; y < 3; ++y)
208 int FileSKLPlugin::loadObject(QString _filename)
218 LoadSkeleton(skel->
skeleton(), _filename);
222 obj->setFromFileName(_filename);
223 obj->setName(obj->filename());
225 emit openedFile( obj->id() );
227 emit log(
LOGERR,tr(
"Unable to add empty skeleton"));
234 template<
typename Skeleton>
235 bool FileSKLPlugin::SaveSkeleton(
Skeleton *_pSkeleton, QString _filename)
241 std::ofstream out(_filename.toStdString().c_str(), std::ofstream::out);
250 unsigned int i = (*it)->id();
254 out << pJoint->id() <<
" ";
258 for(
int y = 0; y < 3; ++y)
259 for(
int x = 0; x < 3; ++x)
260 out << mat(y, x) <<
" ";
261 for(
int y = 0; y < 3; ++y)
262 out << mat(y, 3) <<
" ";
265 out << pJoint->size() <<
" ";
268 for(
unsigned int j = 0; j < pJoint->size(); ++j)
269 out << pJoint->child(j)->id() <<
" ";
281 if (animation != 0) {
283 std::string
name = animation->name();
285 out <<
"animation " << name << std::endl;
287 out << animation->frameCount() << std::endl;
292 for (
unsigned int k = 0; k < animation->frameCount(); ++k) {
299 unsigned int i = (*it)->id();
303 out << pJoint->id() <<
" ";
307 for (
int y = 0; y < 3; ++y)
308 for (
int x = 0; x < 3; ++x)
309 out << mat(y, x) <<
" ";
310 for (
int y = 0; y < 3; ++y)
311 out << mat(y, 3) <<
" ";
317 out <<
"0" << std::endl;
325 bool FileSKLPlugin::saveObject(
int _id, QString _filename)
333 obj->setFromFileName(_filename);
334 obj->setName(obj->filename());
335 SaveSkeleton(skel->
skeleton(), _filename);
338 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
348 emit log(
LOGERR,
"Cannot find object for id " + QString::number(_id) +
" in saveFile" );
364 emit log(
LOGERR,
"Cannot find object for id " + QString::number(_id) +
" in saveFile" );
376 #if QT_VERSION < 0x050000
void setGlobalMatrix(unsigned int _joint, const Matrix &_global, bool _keepGlobalChildPositions=true)
Sets the global coordinate system.
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
void loadIniFile(INIFile &_ini, int _id)
Load per object settings.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Pose * referencePose()
Returns a pointer to the reference pose.
const Vec4f & base_color() const
get the base color
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
MaterialNode * materialNode()
get a pointer to the materialnode
A general pose, used to store the frames of the animation.
unsigned int jointCount()
Returns the number of joints.
void initializePlugin()
Initialize Plugin.
QString name()
Return a name for the plugin.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
Iterator class for the skeleton.
void add_entryVec(const QString &_section, const QString &_key, const VectorT &_value)
Addition of a Vec_n_something.
void set_base_color(const Vec4f &_c)
set the base color
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
Class for the handling of simple configuration files.
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
Pose * pose(unsigned int _iFrame)
Returns a pointer to the pose stored in the given frame.
unsigned int animationCount()
Returns the number of animations stored in this skeleton.
Skeleton * skeleton()
Returns a pointer to the skeleton.
void saveIniFile(INIFile &_ini, int _id)
Save per object settings.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
A handle used to refer to an animation or to a specific frame in an animation.
int objectCount()
Get the number of available objects.
void setFrame(unsigned int _iFrame)
Sets the current animation frame (not failsafe)
const Matrix & globalMatrix(unsigned int _joint) const
Returns the global matrix for the given joint.
Represents a single joint in the skeleton.
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)