From 71dd7c72b268f6ba95f89b98fe468af58cfbad35 Mon Sep 17 00:00:00 2001 From: qw_fuku Date: Sun, 8 Feb 2015 14:02:19 +0900 Subject: [PATCH] =?utf8?q?=E3=82=B9=E3=82=AD=E3=83=8B=E3=83=B3=E3=82=B0?= =?utf8?q?=E5=AE=9F=E8=A3=85=E4=BF=AE=E6=AD=A3=20=E5=A4=A7=E4=BD=93?= =?utf8?q?=E3=81=AE=E3=83=87=E3=83=BC=E3=82=BF=E3=82=92=E3=82=A8=E3=83=A9?= =?utf8?q?=E3=83=BC=E3=81=AA=E3=81=97=E3=81=A7=E8=AA=AD=E3=81=BF=E8=BE=BC?= =?utf8?q?=E3=82=81=E3=81=A6=E4=B8=80=E5=BF=9C=E5=8B=95=E3=81=8F=E3=81=A8?= =?utf8?q?=E3=81=93=E3=82=8D=E3=81=BE=E3=81=A7=E3=81=AF=E3=81=A7=E3=81=8D?= =?utf8?q?=E3=81=A6=E3=81=84=E3=82=8B=E3=81=8C=E3=80=81=E3=83=88=E3=83=A9?= =?utf8?q?=E3=83=B3=E3=82=B9=E3=83=95=E3=82=A9=E3=83=BC=E3=83=A0=E3=81=AE?= =?utf8?q?=E5=88=B6=E5=BE=A1=E3=81=8C=E6=AD=A3=E3=81=97=E3=81=8F=E3=81=AA?= =?utf8?q?=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Src/LibQtGeoViewerCore/Bone.cpp | 8 +++--- Src/LibQtGeoViewerCore/Format/AssimpReader.cpp | 33 ++++++++++++++++++------- Src/LibQtGeoViewerCore/GeomObject.cpp | 2 +- Src/LibQtGeoViewerCore/SkinWeight.cpp | 34 +++++++++++++++++--------- 4 files changed, 50 insertions(+), 27 deletions(-) diff --git a/Src/LibQtGeoViewerCore/Bone.cpp b/Src/LibQtGeoViewerCore/Bone.cpp index a78d2ce..ce5a989 100644 --- a/Src/LibQtGeoViewerCore/Bone.cpp +++ b/Src/LibQtGeoViewerCore/Bone.cpp @@ -25,25 +25,23 @@ lm::matrix4f BoneNode::GetFrameTransform(int frame) const lm::matrix4f mt = lm::matrix4f::get_identity(); - int a_frame = frame; - if (!m_Rotate.empty()) { float vel; lm::vec3f ax; - m_Rotate[a_frame].get_rotate_params(ax, vel); + m_Rotate[frame].get_rotate_params(ax, vel); mt *= lm::matrix4f::get_rotate(ax, vel); } if (!m_Scale.empty()) { - const lm::vec3f& s = m_Scale[a_frame]; + const lm::vec3f& s = m_Scale[frame]; mt *= lm::matrix4f::get_scale(s.x, s.y, s.z); } if (!m_Translate.empty()) { - lm::vec3f d = m_Translate[a_frame]; + lm::vec3f d = m_Translate[frame]; mt *= lm::matrix4f::get_translate(d); } diff --git a/Src/LibQtGeoViewerCore/Format/AssimpReader.cpp b/Src/LibQtGeoViewerCore/Format/AssimpReader.cpp index 63a5621..54fbcd6 100644 --- a/Src/LibQtGeoViewerCore/Format/AssimpReader.cpp +++ b/Src/LibQtGeoViewerCore/Format/AssimpReader.cpp @@ -42,6 +42,7 @@ bool AssimpReader::Load(SceneMain& scene, const std::string& filename) MeshBuf* mbuf = geom->CreateNewMeshBuf(); lib_geo::BaseMesh& mesh_dst = mbuf->m_Mesh; + mbuf->m_Name = mesh->mName.C_Str(); geom->m_Name = mesh->mName.C_Str(); if (geom->m_Name.empty()) @@ -186,34 +187,48 @@ void AssimpReader::LoadAnimation(const aiScene* ai_scene, geom::GeomObject* geom for (unsigned int j = 0; j < anim->mNumChannels; ++j) { aiNodeAnim* ch = anim->mChannels[j]; - BoneNode* bone = bone_map.Bones[ch->mNodeName.C_Str()]; - if (bone == NULL) + BoneNode* bn = bone_map.Bones[ch->mNodeName.C_Str()]; + if (bn == NULL) continue; + for (size_t k = 0; k < geom->m_MeshAry.size(); ++k) + { + MeshBuf& m = geom->m_MeshAry[k]; + for (Bone& b : m.m_Bones.m_Bones) + { + if (b.m_Name == bn->m_Name) + { + bn->m_MeshIDs.push_back((int)k); + bn->m_Bone = &b; + break; + } + } + } + int num_key = AssimpUtil::GetNumKeyOfFrame(ch); // ƒtƒ@ƒCƒ‹ƒtƒH[ƒ}ƒbƒg‚ÌŽd—l‚Æ‚µ‚Ä‚Í, ‘®«‚²‚ƂɃL[—v‘f”‚ªˆÙ‚È‚é‰Â”\«‚ª‚ ‚邪, // §Œä‚ª–Ê“|‚Ȃ̂ňê’v‚µ‚Ä‚¢‚é‚Æ‚¢‚¤‘O’ñ‚ŏˆ—‚ðì‚Á‚Ä‚¢‚é. - bone->m_Translate.resize(num_key); - bone->m_Scale.resize(num_key); - bone->m_Rotate.resize(num_key); + bn->m_Translate.resize(num_key); + bn->m_Scale.resize(num_key); + bn->m_Rotate.resize(num_key); for (unsigned int k = 0; k < ch->mNumPositionKeys; ++k) { - ae::ConvertVec(bone->m_Translate[k], ch->mPositionKeys[k].mValue); + ae::ConvertVec(bn->m_Translate[k], ch->mPositionKeys[k].mValue); } for (unsigned int k = 0; k < ch->mNumScalingKeys; ++k) { - ae::ConvertVec(bone->m_Scale[k], ch->mScalingKeys[k].mValue); + ae::ConvertVec(bn->m_Scale[k], ch->mScalingKeys[k].mValue); } for (unsigned int k = 0; k < ch->mNumRotationKeys; ++k) { - ae::AiQuatToLmQuat(bone->m_Rotate[k], ch->mRotationKeys[k].mValue); + ae::AiQuatToLmQuat(bn->m_Rotate[k], ch->mRotationKeys[k].mValue); } - bone->m_KeyIdxOffset = GetNumMinusKeyFrames(ch); + bn->m_KeyIdxOffset = GetNumMinusKeyFrames(ch); } } diff --git a/Src/LibQtGeoViewerCore/GeomObject.cpp b/Src/LibQtGeoViewerCore/GeomObject.cpp index c5d1762..04fbb8d 100644 --- a/Src/LibQtGeoViewerCore/GeomObject.cpp +++ b/Src/LibQtGeoViewerCore/GeomObject.cpp @@ -123,7 +123,7 @@ void GeomObject::SetFrame(int frame) ApplyTrans(n, n.m_Transform); } - int a_frame = frame; + int a_frame = frame - 1; ObjectSkinWeight vw; vw.Reset(*this, a_frame); diff --git a/Src/LibQtGeoViewerCore/SkinWeight.cpp b/Src/LibQtGeoViewerCore/SkinWeight.cpp index efb2aed..9f2b2db 100644 --- a/Src/LibQtGeoViewerCore/SkinWeight.cpp +++ b/Src/LibQtGeoViewerCore/SkinWeight.cpp @@ -33,28 +33,38 @@ void ObjectSkinWeight::CreateBuf(GeomObject& obj) void ObjectSkinWeight::AppendWeight(GeomObject& obj, lm::matrix4f& mat_parent, BoneNode* bn, int frame) { Bone* b = bn->m_Bone; - if (b == NULL) - return; + lm::matrix4f tb; + if (b != NULL) + tb = bn->GetFrameTransform(frame); + else + tb = bn->m_Transform; - lm::matrix4f mb = bn->GetFrameTransform(frame); + lm::matrix4f tc = tb * mat_parent; - lm::matrix4f mc = mb * mat_parent; - - for (size_t j = 0; j < b->m_Weights.size(); ++j) + if (b != NULL) { - int vid = b->m_Weights[j].m_Vid; - float weight = b->m_Weights[j].m_Weight; + for (size_t j = 0; j < b->m_Weights.size(); ++j) + { + if (bn->m_MeshIDs.size() != 1) + break; + + int mid = bn->m_MeshIDs.front(); + + int vid = b->m_Weights[j].m_Vid; + float weight = b->m_Weights[j].m_Weight; - lm::vec3f v;// = obj.m_BoneAnimation.m_SrcVertPos[vid]; + MeshBuf& mb = obj.m_MeshAry[mid]; + lm::vec3f v = mb.m_Bones.m_SrcVertPos[vid]; - v = b->VertGolbalToLocal(v) * mc; + v = b->VertGolbalToLocal(v) * tc; - Meshes[0].Weights[vid].Add(weight, v); + Meshes[mid].Weights[vid].Add(weight, v); + } } for (size_t i = 0; i < bn->m_Children.size(); ++i) { - AppendWeight(obj, mc, &bn->m_Children[i], frame); + AppendWeight(obj, tc, &bn->m_Children[i], frame); } } -- 2.11.0