42 #include "FileSkeleton.hh" 46 #include <OpenMesh/Core/IO/IOManager.hh> 54 return QString(
"Skeleton files ( *.skl )" );
58 return QString(
"Skeleton files ( *.skl )" );
66 template<
typename Skeleton>
67 bool 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 ){
161 AnimationHandle animHandle = _pSkeleton->addAnimation(animationName, animation);
163 for (
unsigned int k = 0; k < frameCount; k++){
165 animHandle.setFrame(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)
196 int FileSKLPlugin::loadObject(QString _filename)
206 LoadSkeleton(skel->
skeleton(), _filename);
213 emit openedFile( obj->
id() );
215 emit log(
LOGERR,tr(
"Unable to add empty skeleton"));
222 template<
typename Skeleton>
223 bool 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;
313 bool FileSKLPlugin::saveObject(
int _id, QString _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" );
Pose * pose(unsigned int _iFrame)
Returns a pointer to the pose stored in the given frame.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const Matrix & globalMatrix(unsigned int _joint) const
Returns the global matrix for the given joint.
MaterialNode * materialNode()
get a pointer to the materialnode
void setGlobalMatrix(unsigned int _joint, const Matrix &_global, bool _keepGlobalChildPositions=true)
Sets the global coordinate system.
void setFromFileName(const QString &_filename)
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
A general pose, used to store the frames of the animation.
QString name()
Return a name for the plugin.
size_t animationCount()
Returns the number of animations stored in this skeleton.
Iterator class for the skeleton.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
bool get_entryVecf(VectorT &_val, const QString &_section, const QString &_key) const
Get a Vec_n_i (int)
A handle used to refer to an animation or to a specific frame in an animation.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
void loadIniFile(INIFile &_ini, int _id)
Load per object settings.
Pose * referencePose()
Returns a pointer to the reference pose.
QString filename() const
return the filename of the object
Skeleton * skeleton()
Returns a pointer to the skeleton.
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
Pose * pose(const AnimationHandle &_hAni)
Returns a pointer to the pose with the given animation handle.
Represents a single joint in the skeleton.
const Vec4f & base_color() const
get the base color ( same as emission() )
AnimationHandle animationHandle(std::string _name)
Get an AnimationHandle to the animation with the given name.
size_t jointCount()
Returns the number of joints.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
void setFrame(size_t _iFrame)
Sets the current animation frame (not failsafe)
int objectCount()
Get the number of available objects.
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 ( Same as set_emission(const Vec4f& _c) )
void saveIniFile(INIFile &_ini, int _id)
Save per object settings.
void addJoint(typename SkeletonT< PointT >::Joint *_pParent, typename SkeletonT< PointT >::Joint *_pJoint)
Adds a joint as child of a given parent joint.
void initializePlugin()
Initialize Plugin.
Class for the handling of simple configuration files.