From 1ed89592fc40c93d04c5da87bbc5dcfd5ac4157f Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 27 Feb 2011 14:41:02 -0500 Subject: [PATCH] ms3d importing now also looks for a separate animation definition text file, which will be included in the export data (if present) --- MeshConverter/src/ms3d/ms3d.cpp | 77 +++++++++++++++++++++++++++++++++ MeshConverter/src/ms3d/ms3d.h | 9 ++++ 2 files changed, 86 insertions(+) diff --git a/MeshConverter/src/ms3d/ms3d.cpp b/MeshConverter/src/ms3d/ms3d.cpp index 66a5021..d863e5c 100644 --- a/MeshConverter/src/ms3d/ms3d.cpp +++ b/MeshConverter/src/ms3d/ms3d.cpp @@ -188,6 +188,56 @@ bool Ms3d::Load(const std::string &file) fclose(fp); + // check for an animation definition file + std::string animationFile = file; + animationFile.erase(animationFile.find_last_of('.', std::string::npos)); + animationFile.append(".animations"); + + fp = fopen(animationFile.c_str(), "r"); + if (fp != NULL) + { + char *buffer = new char[80]; + std::string line; + std::string name; + std::string temp; + int start; + int end; + + while (!feof(fp)) + { + fgets(buffer, 80, fp); + line = buffer; + + if (strlen(buffer) > 5) // minimum length for a viable frame definition + { + // get animation name + int nameEnd = line.find_first_of(','); + if (nameEnd == std::string::npos) + continue; + name = line.substr(0, nameEnd); + + // get start frame index + int startEnd = line.find_first_of(',', nameEnd + 1); + if (startEnd == std::string::npos) + continue; + temp = line.substr(nameEnd + 1, startEnd); + start = atoi(temp.c_str()); + + // get end frame index + temp = line.substr(startEnd + 1, std::string::npos); + end = atoi(temp.c_str()); + + Ms3dAnimation *animation = new Ms3dAnimation(); + animation->name = name; + animation->startFrame = start; + animation->endFrame = end; + m_animations.push_back(*animation); + } + } + delete[] buffer; + + fclose(fp); + } return true; } @@ -316,6 +366,33 @@ bool Ms3d::ConvertToMesh(const std::string &file) } } + if (m_animations.size() > 0) + { + // figure out the size of all the animation name strings + long sizeofNames = 0; + for (int i = 0; i < m_animations.size(); ++i) + sizeofNames += m_animations[i].name.length() + 1; + + // animations chunk + fputs("ANI", fp); + long numAnimations = m_animations.size(); + long sizeofAnimations = (sizeof(long) * 2) * numAnimations + sizeofNames + sizeof(long); + fwrite(&sizeofAnimations, sizeof(long), 1, fp); + fwrite(&numAnimations, sizeof(long), 1, fp); + for (long i = 0; i < numAnimations; ++i) + { + long data; + const Ms3dAnimation *animation = &m_animations[i]; + //fputs(animation->name.c_str(), fp); + fputs(animation->name.c_str(), fp); + fwrite("\0", 1, 1, fp); + data = animation->startFrame; + fwrite(&data, sizeof(long), 1, fp); + data = animation->endFrame; + fwrite(&data, sizeof(long), 1, fp); + } + } + fclose(fp); return true; diff --git a/MeshConverter/src/ms3d/ms3d.h b/MeshConverter/src/ms3d/ms3d.h index 0ddeec5..c52b5e1 100644 --- a/MeshConverter/src/ms3d/ms3d.h +++ b/MeshConverter/src/ms3d/ms3d.h @@ -4,6 +4,7 @@ #include #include "../geometry/vector3.h" #include "../geometry/vector2.h" +#include struct Ms3dHeader { @@ -93,6 +94,13 @@ struct Ms3dJoint } }; +struct Ms3dAnimation +{ + std::string name; + unsigned int startFrame; + unsigned int endFrame; +}; + class Ms3d { public: @@ -132,6 +140,7 @@ private: Ms3dMesh *m_meshes; Ms3dMaterial *m_materials; Ms3dJoint *m_joints; + std::vector m_animations; }; #endif