OSDN Git Service

データ構造の改良
authorqw_fuku <fkhideaki@gmail.com>
Sun, 25 Jan 2015 11:34:13 +0000 (20:34 +0900)
committerqw_fuku <fkhideaki@gmail.com>
Sun, 25 Jan 2015 11:34:13 +0000 (20:34 +0900)
Src/LibQtGeoViewerCore/Bone.h
Src/LibQtGeoViewerCore/Format/AssimpReader.cpp
Src/LibQtGeoViewerCore/Format/AssimpUtil.cpp
Src/LibQtGeoViewerCore/Format/AssimpUtil.h
Src/LibQtGeoViewerCore/SkinWeight.cpp
Src/LibQtGeoViewerCore/SkinWeight.h
Src/QtGeoViewer/View3D.cpp
Src/QtGeoViewer/View3D.h

index 8fcaff6..85b72fb 100644 (file)
@@ -26,6 +26,7 @@ class Bone
 public:
        Bone(void)
        {
+               m_Index = -1;
                m_KeyIdxOffset = 0;
        }
 
@@ -48,7 +49,6 @@ public:
 public:
        int m_Index;
        std::string m_Name;
-       Bone* m_Parent;
 
        lm::matrix4f m_NodeTrans;
 
@@ -58,19 +58,28 @@ public:
        std::vector<lm::quat4f> m_Rotate;
        std::vector<lm::vec3f>  m_Scale;
 
-       std::vector<Bone*> m_Children;
-
        lm::matrix4f m_Offset;
 
        int m_KeyIdxOffset;
 };
 
 
-class BoneRoot
+class BoneNode
 {
 public:
+       BoneNode(void)
+       {
+               m_Bone = NULL;
+               m_Parent = NULL;
+       }
+
+public:
        lm::matrix4f m_Transform;
        Bone* m_Bone;
+
+       BoneNode* m_Parent;
+
+       boost::ptr_vector<BoneNode> m_Children;
 };
 
 
@@ -91,7 +100,7 @@ public:
 
        std::vector<lm::vec3f> m_SrcVertPos;
 
-       std::vector<BoneRoot> m_RootNodes;
+       boost::ptr_vector<BoneNode> m_RootNodes;
 };
 
 
index f85b1dc..943d360 100644 (file)
@@ -166,13 +166,13 @@ void AssimpReader::SetBoneToGeom(const aiScene* ai_scene, geom::BoneMap& bone_ma
                        aiNode* nc = n->mChildren[k];
                        Bone* b_root = bone_map.Bones[nc->mName.C_Str()];
 
-                       BoneRoot br;
-                       br.m_Bone = b_root;
-                       ae::ConvertMat(br.m_Transform, n->mTransformation);
-
+                       BoneNode* br = new BoneNode();
                        geom->m_BoneAnimation.m_RootNodes.push_back(br);
 
-                       AssimpUtil::CreateBoneTree(bone_map, b_root, nc);
+                       br->m_Bone = b_root;
+                       ae::ConvertMat(br->m_Transform, n->mTransformation);
+
+                       AssimpUtil::CreateBoneTree(bone_map, br, nc);
                }
        }
 }
index 4054f50..a751232 100644 (file)
@@ -179,19 +179,22 @@ void AssimpUtil::ApplyTransform(aiNode* n, aiMatrix4x4 t, std::map<int, MeshBuf*
        }
 }
 
-void AssimpUtil::CreateBoneTree(BoneMap& bone_map, Bone* b, aiNode* n)
+void AssimpUtil::CreateBoneTree(BoneMap& bone_map, BoneNode* bn, aiNode* n)
 {
-       if (b == NULL)
+       if (bn == NULL)
                return;
 
-       ae::ConvertMat(b->m_NodeTrans, n->mTransformation);
+       Bone* b = bn->m_Bone;
+       if (b != NULL)
+               ae::ConvertMat(b->m_NodeTrans, n->mTransformation);
 
        for (int i = 0; i < n->mNumChildren; ++i)
        {
                aiNode* nc = n->mChildren[i];
-               Bone* bc = bone_map.Bones[nc->mName.C_Str()];
-               b->m_Children.push_back(bc);
-               CreateBoneTree(bone_map, bc, nc);
+               BoneNode* bnc = new BoneNode();
+               bnc->m_Bone = bone_map.Bones[nc->mName.C_Str()];
+               bn->m_Children.push_back(bnc);
+               CreateBoneTree(bone_map, bnc, nc);
        }
 }
 
index 548e396..dbbf51e 100644 (file)
@@ -18,7 +18,7 @@ public:
 
        static void ApplyTransform(aiNode* n, aiMatrix4x4 t, std::map<int, MeshBuf*>& AiToLGMesh);
 
-       static void CreateBoneTree(BoneMap& bone_map, Bone* b, aiNode* n);
+       static void CreateBoneTree(BoneMap& bone_map, BoneNode* bn, aiNode* n);
        static void CreateBoneMap(const aiScene* scene, BoneMap& bone_map);
        static int GetNumKeyOfFrame(const aiNodeAnim* ch);
 };
index 2767dab..6c6e62b 100644 (file)
@@ -12,12 +12,10 @@ void ObjectSkinWeight::Reset(GeomObject& obj, BoneAnimation& bones, int a_frame)
 {
        CreateBuf(obj);
 
-       for (BoneRoot& br : bones.m_RootNodes)
+       for (BoneNode& br : bones.m_RootNodes)
        {
                lm::matrix4f mi = br.m_Transform;
-
-               Bone* b = br.m_Bone;
-               AppendWeight(obj, mi, b, a_frame);
+               AppendWeight(obj, mi, &br, a_frame);
        }
 }
 
@@ -32,8 +30,10 @@ void ObjectSkinWeight::CreateBuf(GeomObject& obj)
        }
 }
 
-void ObjectSkinWeight::AppendWeight(GeomObject& obj, lm::matrix4f& mat_parent, Bone* b, int frame)
+void ObjectSkinWeight::AppendWeight(GeomObject& obj, lm::matrix4f& mat_parent, BoneNode* bn, int frame)
 {
+       Bone* b = bn->m_Bone;
+
        lm::matrix4f mb = b->GetFrameTransform(frame);
 
        lm::matrix4f mc = mb * mat_parent;
@@ -50,9 +50,9 @@ void ObjectSkinWeight::AppendWeight(GeomObject& obj, lm::matrix4f& mat_parent, B
                Meshes[0].Weights[vid].Add(weight, v);
        }
 
-       for (size_t i = 0; i < b->m_Children.size(); ++i)
+       for (size_t i = 0; i < bn->m_Children.size(); ++i)
        {
-               AppendWeight(obj, mc, b->m_Children[i], frame);
+               AppendWeight(obj, mc, &bn->m_Children[i], frame);
        }
 }
 
index a18de0c..b1117ae 100644 (file)
@@ -13,6 +13,7 @@ namespace geom
 
 class GeomObject;
 class Bone;
+class BoneNode;
 class BoneAnimation;
 
 
@@ -55,7 +56,7 @@ public:
 
 private:
        void CreateBuf(GeomObject& obj);
-       void AppendWeight(GeomObject& obj, lm::matrix4f& mat_parent, Bone* b, int frame);
+       void AppendWeight(GeomObject& obj, lm::matrix4f& mat_parent, BoneNode* bn, int frame);
 
 public:
        std::vector<MeshSkinWeight> Meshes;
index 175908a..ba8b127 100644 (file)
@@ -966,18 +966,19 @@ void View3D::DrawAllGeomBone(void)
 
        for (GeomObject& g : m_Scene->m_Objects)
        {
-               for (BoneRoot& b : g.m_BoneAnimation.m_RootNodes)
+               for (BoneNode& b : g.m_BoneAnimation.m_RootNodes)
                {
                        lm::matrix4f m = b.m_Transform;
-                       DrawBone(NULL, b.m_Bone, af, m);
+                       DrawBone(NULL, &b, af, m);
                }
        }
 
        glPopAttrib();
 }
 
-void View3D::DrawBone(Bone* parent, Bone* b, int frame, lm::matrix4f m)
+void View3D::DrawBone(Bone* parent, BoneNode* bn, int frame, lm::matrix4f m)
 {
+       Bone* b = bn->m_Bone;
        if (b == NULL)
                return;
 
@@ -1011,9 +1012,9 @@ void View3D::DrawBone(Bone* parent, Bone* b, int frame, lm::matrix4f m)
 
        glPopMatrix();
 
-       for (size_t i = 0; i < b->m_Children.size(); ++i)
+       for (size_t i = 0; i < bn->m_Children.size(); ++i)
        {
-               DrawBone(b, b->m_Children[i], frame, nf);
+               DrawBone(b, &bn->m_Children[i], frame, nf);
        }
 }
 
index fc43a19..fb33c65 100644 (file)
@@ -137,7 +137,7 @@ protected:
        void DrawAllGeomMeshStd(bool UseShader, std::vector<MeshBuf*>& meshes);
        void DrawAllGeomVLinks(std::vector<MeshBuf*>& meshes);
        void DrawAllGeomBone(void);
-       void DrawBone(Bone* parent, Bone* b, int frame, lm::matrix4f m);
+       void DrawBone(Bone* parent, BoneNode* b, int frame, lm::matrix4f m);
 
        void DrawAllGeomPolyline(std::vector<MeshBuf*>& meshes);
        void DrawPolyline(MeshBuf& mbuf);