42#include "FileSkeleton.hh"
46#include <OpenMesh/Core/IO/IOManager.hh>
54 return QString(
"Skeleton files ( *.skl )" );
58 return QString(
"Skeleton files ( *.skl )" );
66template<
typename Skeleton>
67bool FileSKLPlugin::LoadSkeleton(
Skeleton *_pSkeleton, QString _filename)
73 unsigned int nJoints = 0;
75 std::ifstream in(_filename.toStdString().c_str(), std::ofstream::in);
82 std::map<unsigned int, Joint*> parents;
84 std::map<unsigned int, unsigned int> jointMap;
86 for(
unsigned int i = 0; i < nJoints; ++i)
97 for(
int y = 0; y < 3; ++y)
98 for(
int x = 0; x < 3; ++x)
100 for(
int y = 0; y < 3; ++y)
105 if(parents.find(
id) != parents.end())
106 pParent = parents[id];
109 Joint *pJoint =
new Joint(pParent);
110 _pSkeleton->
addJoint(pParent, pJoint);
112 jointMap[ id ] = pJoint->id();
115 ref->setGlobalMatrix(jointMap[
id ], mat);
118 unsigned int nChildren;
121 for(
unsigned int j = 0; j < nChildren; ++j)
124 unsigned int idChild;
127 parents[idChild] = pJoint;
131 unsigned int num_anim = 0;
137 std::string identifier;
139 std::string animationName = (QString(
"Animation") + QString::number(num_anim)).toStdString();
142 unsigned int frameCount = 0;
145 if(identifier ==
"animation") {
146 std::getline(in, animationName);
148 animationName = QString(animationName.c_str()).trimmed().toStdString();
153 std::istringstream tmp(identifier);
158 if ( frameCount > 0 ){
163 for (
unsigned int k = 0; k < frameCount; k++){
168 for(
unsigned int i = 0; i < nJoints; ++i)
178 for(
int y = 0; y < 3; ++y)
179 for(
int x = 0; x < 3; ++x)
181 for(
int y = 0; y < 3; ++y)
196int FileSKLPlugin::loadObject(QString _filename)
206 LoadSkeleton(skel->
skeleton(), _filename);
210 obj->setFromFileName(_filename);
211 obj->setName(obj->filename());
213 emit openedFile( obj->id() );
215 emit log(
LOGERR,tr(
"Unable to add empty skeleton"));
222template<
typename Skeleton>
223bool FileSKLPlugin::SaveSkeleton(
Skeleton *_pSkeleton, QString _filename)
229 std::ofstream out(_filename.toStdString().c_str(), std::ofstream::out);
238 unsigned int i = (*it)->id();
242 out << pJoint->id() <<
" ";
246 for(
int y = 0; y < 3; ++y)
247 for(
int x = 0; x < 3; ++x)
248 out << mat(y, x) <<
" ";
249 for(
int y = 0; y < 3; ++y)
250 out << mat(y, 3) <<
" ";
253 out << pJoint->size() <<
" ";
256 for(
unsigned int j = 0; j < pJoint->size(); ++j)
257 out << pJoint->child(j)->id() <<
" ";
269 if (animation != 0) {
271 std::string
name = animation->name();
273 out <<
"animation " <<
name << std::endl;
275 out << animation->frameCount() << std::endl;
280 for (
unsigned int k = 0; k < animation->frameCount(); ++k) {
287 unsigned int i = (*it)->id();
291 out << pJoint->id() <<
" ";
295 for (
int y = 0; y < 3; ++y)
296 for (
int x = 0; x < 3; ++x)
297 out << mat(y, x) <<
" ";
298 for (
int y = 0; y < 3; ++y)
299 out << mat(y, 3) <<
" ";
305 out <<
"0" << std::endl;
313bool FileSKLPlugin::saveObject(
int _id, QString _filename)
321 obj->setFromFileName(_filename);
322 obj->setName(obj->filename());
323 SaveSkeleton(skel->
skeleton(), _filename);
326 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
336 emit log(
LOGERR,
"Cannot find object for id " + QString::number(_id) +
" in saveFile" );
352 emit log(
LOGERR,
"Cannot find object for id " + QString::number(_id) +
" in saveFile" );
const Vec4f & base_color() const
get the base color ( same as emission() )
void set_base_color(const Vec4f &_c)
set the base color ( Same as set_emission(const Vec4f& _c) )
A handle used to refer to an animation or to a specific frame in an animation.
void setFrame(size_t _iFrame)
Sets the current animation frame (not failsafe)
MaterialNode * materialNode()
get a pointer to the materialnode
QString name() const
return the name of the object. The name defaults to NONAME if unset.
void initializePlugin()
Initialize Plugin.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
void loadIniFile(INIFile &_ini, int _id)
Load per object settings.
void saveIniFile(INIFile &_ini, int _id)
Save per object settings.
QString name()
Return a name for the plugin.
Class for the handling of simple configuration files.
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)
void add_entryVec(const QString &_section, const QString &_key, const VectorT &_value)
Addition of a Vec_n_something.
Represents a single joint in the skeleton.
A general pose, used to store the frames of the animation.
const Matrix & globalMatrix(unsigned int _joint) const
Returns the global matrix for the given joint.
void setGlobalMatrix(unsigned int _joint, const Matrix &_global, bool _keepGlobalChildPositions=true)
Sets the global coordinate system.
Skeleton * skeleton()
Returns a pointer to the skeleton.
Iterator class for the skeleton.
Pose * referencePose()
Returns a pointer to the reference pose.
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
size_t jointCount()
Returns the number of joints.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
size_t animationCount()
Returns the number of animations stored in this skeleton.
AnimationHandle addAnimation(std::string _name, Animation *_animation)
Adds a new animation to the list.
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
int objectCount()
Get the number of available objects.