diff --git a/MeshConverter/src/ms3d/ms3d.cpp b/MeshConverter/src/ms3d/ms3d.cpp index 2c3b24d..2889cce 100644 --- a/MeshConverter/src/ms3d/ms3d.cpp +++ b/MeshConverter/src/ms3d/ms3d.cpp @@ -8,10 +8,12 @@ Ms3d::Ms3d() m_numTriangles = 0; m_numMeshes = 0; m_numMaterials = 0; + m_numJoints = 0; m_vertices = NULL; m_triangles = NULL; m_meshes = NULL; m_materials = NULL; + m_joints = NULL; } void Ms3d::Release() @@ -20,10 +22,12 @@ void Ms3d::Release() delete[] m_triangles; delete[] m_meshes; delete[] m_materials; + delete[] m_joints; m_numVertices = 0; m_numTriangles = 0; m_numMeshes = 0; m_numMaterials = 0; + m_numJoints = 0; } bool Ms3d::Load(const std::string &file) @@ -132,6 +136,48 @@ bool Ms3d::Load(const std::string &file) fread(&material->alpha, 128, 1, fp); } + // read joints + fread(&m_animationFps, 4, 1, fp); + fread(&m_editorAnimationTime, 4, 1, fp); + fread(&m_numFrames, 4, 1, fp); + fread(&m_numJoints, 2, 1, fp); + m_joints = new Ms3dJoint[m_numJoints]; + + for (int i = 0; i < m_numJoints; ++i) + { + Ms3dJoint *joint = &m_joints[i]; + + fread(&joint->editorFlags, 1, 1, fp); + fread(&joint->name, 32, 1, fp); + fread(&joint->parentName, 32, 1, fp); + fread(&joint->rotation.x, 4, 1, fp); + fread(&joint->rotation.y, 4, 1, fp); + fread(&joint->rotation.z, 4, 1, fp); + fread(&joint->position.x, 4, 1, fp); + fread(&joint->position.y, 4, 1, fp); + fread(&joint->position.z, 4, 1, fp); + fread(&joint->numRotationFrames, 2, 1, fp); + fread(&joint->numTranslationFrames, 2, 1, fp); + joint->rotationFrames = new Ms3dKeyFrame[joint->numRotationFrames]; + for (int j = 0; j < joint->numRotationFrames; ++j) + { + Ms3dKeyFrame *frame = &joint->rotationFrames[j]; + fread(&frame->time, 4, 1, fp); + fread(&frame->param.x, 4, 1, fp); + fread(&frame->param.y, 4, 1, fp); + fread(&frame->param.z, 4, 1, fp); + } + joint->translationFrames = new Ms3dKeyFrame[joint->numTranslationFrames]; + for (int j = 0; j < joint->numTranslationFrames; ++j) + { + Ms3dKeyFrame *frame = &joint->translationFrames[j]; + fread(&frame->time, 4, 1, fp); + fread(&frame->param.x, 4, 1, fp); + fread(&frame->param.y, 4, 1, fp); + fread(&frame->param.z, 4, 1, fp); + } + } + fclose(fp); return true; diff --git a/MeshConverter/src/ms3d/ms3d.h b/MeshConverter/src/ms3d/ms3d.h index c0ae3e4..a3a27c6 100644 --- a/MeshConverter/src/ms3d/ms3d.h +++ b/MeshConverter/src/ms3d/ms3d.h @@ -62,6 +62,37 @@ struct Ms3dMaterial char alpha[128]; }; +struct Ms3dKeyFrame +{ + float time; + Vector3 param; +}; + +struct Ms3dJoint +{ + unsigned char editorFlags; + char name[32]; + char parentName[32]; + Vector3 rotation; + Vector3 position; + unsigned short numRotationFrames; + unsigned short numTranslationFrames; + Ms3dKeyFrame *rotationFrames; + Ms3dKeyFrame *translationFrames; + + Ms3dJoint() + { + rotationFrames = NULL; + translationFrames = NULL; + } + + ~Ms3dJoint() + { + delete[] rotationFrames; + delete[] translationFrames; + } +}; + class Ms3d { public: @@ -76,20 +107,27 @@ public: unsigned short GetNumTriangles() { return m_numTriangles; } unsigned short GetNumMeshes() { return m_numMeshes; } unsigned short GetNumMaterials() { return m_numMaterials; } + unsigned short GetNumJoints() { return m_numJoints; } Ms3dVertex* GetVertices() { return m_vertices; } Ms3dTriangle* GetTriangles() { return m_triangles; } Ms3dMesh* GetMeshes() { return m_meshes; } Ms3dMaterial* GetMaterials() { return m_materials; } + Ms3dJoint* GetJoints() { return m_joints; } private: unsigned short m_numVertices; unsigned short m_numTriangles; unsigned short m_numMeshes; unsigned short m_numMaterials; + unsigned short m_numJoints; + float m_animationFps; + float m_editorAnimationTime; + int m_numFrames; Ms3dVertex *m_vertices; Ms3dTriangle *m_triangles; Ms3dMesh *m_meshes; Ms3dMaterial *m_materials; + Ms3dJoint *m_joints; }; #endif