Skip to content

Commit

Permalink
new parse bones
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw committed Jan 9, 2024
1 parent 9cc6337 commit 881f238
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 123 deletions.
441 changes: 377 additions & 64 deletions private/Producers/FbxProducer/FbxProducerImpl.cpp

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions private/Producers/FbxProducer/FbxProducerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ class FbxProducerImpl final
bool IsOptionEnabled(FbxProducerOptions option) const { return m_options.IsEnabled(option); }

private:
void ParseSkeletonMesh(std::vector<fbxsdk::FbxNode*> skeletonMeshNodes);
void ParseSkeletonMesh(fbxsdk::FbxScene* pScene, std::vector<fbxsdk::FbxNode*> skeletonMeshNodes, cd::SceneDatabase* pSceneDatabase);

void TraverseBoneRecursively(fbxsdk::FbxNode* pSDKNode, cd::BoneID parentBoneID, cd::Skeleton& skeleton, cd::SceneDatabase* pSceneDatabase);
void TraverseNodeRecursively(fbxsdk::FbxNode* pSDKNode, cd::NodeID parentNodeID, cd::SceneDatabase* pSceneDatabase);

std::pair<cd::MaterialID, bool> AllocateMaterialID(const fbxsdk::FbxSurfaceMaterial* pSDKMaterial);
Expand All @@ -78,7 +77,6 @@ class FbxProducerImpl final

cd::SkinID ParseSkin(const fbxsdk::FbxSkin* pSkin, const cd::Mesh& sourceMesh, cd::SceneDatabase* pSceneDatabase);

cd::BoneID ParseBone(fbxsdk::FbxNode* pSDKNode, cd::BoneID parentBoneID, cd::Skeleton& skeleton, cd::SceneDatabase* pSceneDatabase);
void ParseAnimation(fbxsdk::FbxScene* scene, cd::SceneDatabase* pSceneDatabase);

private:
Expand Down
11 changes: 4 additions & 7 deletions private/Scene/Bone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ namespace cd

PIMPL_SCENE_CLASS(Bone);

Bone::Bone(BoneID id, std::string name)
bool Bone::IsRootBone() const
{
m_pBoneImpl = new BoneImpl(id, cd::MoveTemp(name));
}

void Bone::Init(BoneID id, std::string name)
{
m_pBoneImpl->Init(id, MoveTemp(name));
return m_pBoneImpl->IsRootBone();
}

PIMPL_SIMPLE_TYPE_APIS(Bone, ID);
PIMPL_SIMPLE_TYPE_APIS(Bone, ParentID);
PIMPL_SIMPLE_TYPE_APIS(Bone, SkeletonID);
PIMPL_SIMPLE_TYPE_APIS(Bone, LimbLength);
PIMPL_STRING_TYPE_APIS(Bone, Name);
PIMPL_COMPLEX_TYPE_APIS(Bone, LimbSize);
PIMPL_COMPLEX_TYPE_APIS(Bone, Offset);
PIMPL_COMPLEX_TYPE_APIS(Bone, Transform);
PIMPL_VECTOR_TYPE_APIS(Bone, ChildID);
Expand Down
11 changes: 0 additions & 11 deletions private/Scene/BoneImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,4 @@
namespace cd
{

BoneImpl::BoneImpl(BoneID id, std::string name)
{
Init(id, cd::MoveTemp(name));
}

void BoneImpl::Init(BoneID id, std::string name)
{
SetID(id);
SetName(cd::MoveTemp(name));
}

}
20 changes: 6 additions & 14 deletions private/Scene/BoneImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,26 @@ class BoneImpl final
public:
DECLARE_SCENE_IMPL_CLASS(Bone);

explicit BoneImpl(BoneID id, std::string name);
void Init(BoneID id, std::string name);
bool IsRootBone() const { return !GetParentID().IsValid(); }

IMPLEMENT_SIMPLE_TYPE_APIS(Bone, ID);
IMPLEMENT_SIMPLE_TYPE_APIS(Bone, ParentID);
IMPLEMENT_SIMPLE_TYPE_APIS(Bone, SkeletonID);
IMPLEMENT_SIMPLE_TYPE_APIS(Bone, LimbLength);
IMPLEMENT_STRING_TYPE_APIS(Bone, Name);
IMPLEMENT_COMPLEX_TYPE_APIS(Bone, LimbSize);
IMPLEMENT_COMPLEX_TYPE_APIS(Bone, Offset);
IMPLEMENT_COMPLEX_TYPE_APIS(Bone, Transform);
IMPLEMENT_VECTOR_TYPE_APIS(Bone, ChildID);

template<bool SwapBytesOrder>
BoneImpl& operator<<(TInputArchive<SwapBytesOrder>& inputArchive)
{
uint32_t boneID;
std::string boneName;
uint32_t boneParentID;
uint32_t boneChildIDCount;

inputArchive >> boneID >> boneName
>> boneParentID >> boneChildIDCount;

Init(BoneID(boneID), cd::MoveTemp(boneName));
SetParentID(BoneID(boneParentID));

GetChildIDs().resize(boneChildIDCount);
inputArchive >> GetID().Data() >> GetParentID().Data() >> GetName() >> boneChildIDCount;
SetChildIDCount(boneChildIDCount);
inputArchive.ImportBuffer(GetChildIDs().data());

inputArchive >> GetOffset() >> GetTransform();

return *this;
Expand All @@ -52,7 +44,7 @@ class BoneImpl final
template<bool SwapBytesOrder>
const BoneImpl& operator>>(TOutputArchive<SwapBytesOrder>& outputArchive) const
{
outputArchive << GetID().Data() << GetName() << GetParentID().Data() << GetChildIDCount();
outputArchive << GetID().Data() << GetParentID().Data() << GetName() << GetChildIDCount();
outputArchive.ExportBuffer(GetChildIDs().data(), GetChildIDs().size());
outputArchive << GetOffset() << GetTransform();

Expand Down
12 changes: 3 additions & 9 deletions private/Scene/SceneDatabaseImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,7 @@ void SceneDatabaseImpl::Dump() const
{
printf("[Skeleton %u] Name : %s\n", skeleton.GetID().Data(), skeleton.GetName());

for (auto rootBoneID : skeleton.GetRootBoneIDs())
{
printf("\t[Associated RootBone %u]\n", rootBoneID.Data());
}
printf("\t[Associated RootBone %u]\n", skeleton.GetRootBoneID().Data());

for (auto boneID : skeleton.GetBoneIDs())
{
Expand Down Expand Up @@ -672,11 +669,7 @@ void SceneDatabaseImpl::Merge(cd::SceneDatabaseImpl&& sceneDatabaseImpl)
for (auto& skeleton : sceneDatabaseImpl.GetSkeletons())
{
skeleton.SetID(GetSkeletonCount());

for (auto& rootBoneID : skeleton.GetRootBoneIDs())
{
rootBoneID.Set(rootBoneID.Data() + originBoneCount);
}
skeleton.SetRootBoneID(skeleton.GetRootBoneID().Data() + originBoneCount);

for (auto& boneID : skeleton.GetBoneIDs())
{
Expand All @@ -694,6 +687,7 @@ void SceneDatabaseImpl::Merge(cd::SceneDatabaseImpl&& sceneDatabaseImpl)
{
childID.Set(childID.Data() + originBoneCount);
}
bone.SetSkeletonID(bone.GetSkeletonID().Data() + originSkeletonCount);
AddBone(cd::MoveTemp(bone));
}

Expand Down
2 changes: 1 addition & 1 deletion private/Scene/Skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace cd

PIMPL_SCENE_CLASS(Skeleton);
PIMPL_SIMPLE_TYPE_APIS(Skeleton, ID);
PIMPL_SIMPLE_TYPE_APIS(Skeleton, RootBoneID);
PIMPL_STRING_TYPE_APIS(Skeleton, Name);
PIMPL_VECTOR_TYPE_APIS(Skeleton, RootBoneID);
PIMPL_VECTOR_TYPE_APIS(Skeleton, BoneID);

}
13 changes: 4 additions & 9 deletions private/Scene/SkeletonImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@ class SkeletonImpl final
DECLARE_SCENE_IMPL_CLASS(Skeleton);

IMPLEMENT_SIMPLE_TYPE_APIS(Skeleton, ID);
IMPLEMENT_SIMPLE_TYPE_APIS(Skeleton, RootBoneID);
IMPLEMENT_STRING_TYPE_APIS(Skeleton, Name);
IMPLEMENT_VECTOR_TYPE_APIS(Skeleton, RootBoneID);
IMPLEMENT_VECTOR_TYPE_APIS(Skeleton, BoneID);

template<bool SwapBytesOrder>
SkeletonImpl& operator<<(TInputArchive<SwapBytesOrder>& inputArchive)
{
uint32_t rootBoneIDCount;
uint32_t boneIDCount;
inputArchive >> GetID().Data() >> GetName() >> rootBoneIDCount >> boneIDCount;

SetRootBoneIDCount(rootBoneIDCount);
inputArchive >> GetID().Data() >> GetRootBoneID().Data() >> GetName() >> boneIDCount;
SetBoneIDCount(boneIDCount);
inputArchive.ImportBuffer(GetRootBoneIDs().data());
inputArchive.ImportBuffer(GetBoneIDs().data());

return *this;
Expand All @@ -36,9 +32,8 @@ class SkeletonImpl final
template<bool SwapBytesOrder>
const SkeletonImpl& operator>>(TOutputArchive<SwapBytesOrder>& outputArchive) const
{
outputArchive << GetID().Data() << GetName() << GetRootBoneIDCount() << GetBoneIDCount();
outputArchive.ExportBuffer(GetRootBoneIDs().data(), GetRootBoneIDs().size());
outputArchive.ExportBuffer(GetBoneIDs().data(), GetRootBoneIDs().size());
outputArchive << GetID().Data() << GetRootBoneID().Data() << GetName() << GetBoneIDCount();
outputArchive.ExportBuffer(GetBoneIDs().data(), GetBoneIDs().size());

return *this;
}
Expand Down
6 changes: 4 additions & 2 deletions public/Scene/APITypeTraits.inl
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ struct BoneTypeTraits
using ID = cd::BoneID;
using ParentID = cd::BoneID;
using SkeletonID = cd::SkeletonID;
using LimbLength = float;

// String
using Name = std::string;

// Complex
using Offset = cd::Matrix4x4;
using Transform = cd::Transform;
using LimbSize = cd::Vec3f;

// Vector
using ChildID = cd::BoneID;
Expand Down Expand Up @@ -224,12 +226,12 @@ struct SkeletonTypeTraits
{
// Simple
using ID = cd::SkeletonID;

using RootBoneID = cd::BoneID;

// String
using Name = std::string;

// Vector
using RootBoneID = cd::BoneID;
using BoneID = cd::BoneID;
};

Expand Down
6 changes: 4 additions & 2 deletions public/Scene/Bone.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ class CORE_API Bone final
{
public:
DECLARE_SCENE_CLASS(Bone);
explicit Bone(BoneID id, std::string name);
void Init(BoneID id, std::string name);

EXPORT_SIMPLE_TYPE_APIS(Bone, ID);
EXPORT_SIMPLE_TYPE_APIS(Bone, ParentID);
EXPORT_SIMPLE_TYPE_APIS(Bone, SkeletonID);
EXPORT_SIMPLE_TYPE_APIS(Bone, LimbLength);
EXPORT_STRING_TYPE_APIS(Bone, Name);
EXPORT_COMPLEX_TYPE_APIS(Bone, LimbSize);
EXPORT_COMPLEX_TYPE_APIS(Bone, Offset);
EXPORT_COMPLEX_TYPE_APIS(Bone, Transform);
EXPORT_VECTOR_TYPE_APIS(Bone, ChildID);

bool IsRootBone() const;
};

}
2 changes: 1 addition & 1 deletion public/Scene/Skeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class CORE_API Skeleton final
public:
DECLARE_SCENE_CLASS(Skeleton);
EXPORT_SIMPLE_TYPE_APIS(Skeleton, ID);
EXPORT_SIMPLE_TYPE_APIS(Skeleton, RootBoneID);
EXPORT_STRING_TYPE_APIS(Skeleton, Name);
EXPORT_VECTOR_TYPE_APIS(Skeleton, RootBoneID);
EXPORT_VECTOR_TYPE_APIS(Skeleton, BoneID);
};

Expand Down

0 comments on commit 881f238

Please sign in to comment.