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);
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)
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 Iterator class for the skeleton.
Pose * pose(unsigned int _iFrame)
Returns a pointer to the pose stored in the given frame.
Represents a single joint in the skeleton.
QString filename() const
return the filename of the object
bool getObject(int _identifier, BSplineCurveObject *&_object)
unsigned int jointCount()
Returns the number of joints.
void add_entryVec(const QString &_section, const QString &_key, const VectorT &_value)
Addition of a Vec_n_something.
void loadIniFile(INIFile &_ini, int _id)
Load per object settings.
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)
const Matrix & globalMatrix(unsigned int _joint) const
Returns the global matrix for the given joint.
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
void setFrame(unsigned int _iFrame)
Sets the current animation frame (not failsafe)
void setFromFileName(const QString &_filename)
MaterialNode * materialNode()
get a pointer to the materialnode
A general pose, used to store the frames of the animation.
Skeleton * skeleton()
Returns a pointer to the skeleton.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
A handle used to refer to an animation or to a specific frame in an animation.
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
int objectCount()
Get the number of available objects.
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void initializePlugin()
Initialize Plugin.
Class for the handling of simple configuration files.
void saveIniFile(INIFile &_ini, int _id)
Save per object settings.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
unsigned int animationCount()
Returns the number of animations stored in this skeleton.
const Vec4f & base_color() const
get the base color
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
QString name()
Return a name for the plugin.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void set_base_color(const Vec4f &_c)
set the base color
void setGlobalMatrix(unsigned int _joint, const Matrix &_global, bool _keepGlobalChildPositions=true)
Sets the global coordinate system.
Pose * referencePose()
Returns a pointer to the reference pose.