public:
Bone(void)
{
+ m_Index = -1;
m_KeyIdxOffset = 0;
}
public:
int m_Index;
std::string m_Name;
- Bone* m_Parent;
lm::matrix4f m_NodeTrans;
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;
};
std::vector<lm::vec3f> m_SrcVertPos;
- std::vector<BoneRoot> m_RootNodes;
+ boost::ptr_vector<BoneNode> m_RootNodes;
};
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);
}
}
}
}
}
-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);
}
}
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);
};
{
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);
}
}
}
}
-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;
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);
}
}
class GeomObject;
class Bone;
+class BoneNode;
class BoneAnimation;
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;
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;
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);
}
}
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);