Skip to content

Commit

Permalink
add skeleton class(#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw authored Dec 16, 2023
1 parent 6f027df commit ba6fb01
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 18 deletions.
2 changes: 1 addition & 1 deletion auto/premake-findfbx
Submodule premake-findfbx updated 0 files
11 changes: 3 additions & 8 deletions private/Scene/AnimationImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,11 @@ class AnimationImpl final
{
uint32_t animationID;
std::string animationName;
float duration;
float ticksPerSecond;
uint32_t boneTrackCount;

inputArchive >> animationID >> animationName >> duration >> ticksPerSecond >> boneTrackCount;

inputArchive >> animationID >> animationName;
Init(AnimationID(animationID), cd::MoveTemp(animationName));
SetDuration(duration);
SetTicksPerSecond(ticksPerSecond);

uint32_t boneTrackCount;
inputArchive >> GetDuration() >> GetTicksPerSecond() >> boneTrackCount;
GetBoneTrackIDs().resize(boneTrackCount);
inputArchive.ImportBuffer(GetBoneTrackIDs().data());

Expand Down
4 changes: 1 addition & 3 deletions private/Scene/ParticleEmitterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ class ParticleEmitterImpl final
uint32_t emitterID;
std::string emitterName;
uint32_t emitterType;
uint32_t meshID;
inputArchive >> emitterID >> emitterName >> emitterType >> meshID;
inputArchive >> emitterID >> emitterName >> emitterType >> GetMeshID().Data();
Init(ParticleEmitterID(emitterID), cd::MoveTemp(emitterName));
SetType(static_cast<ParticleEmitterType>(emitterType));
SetMeshID(meshID);
inputArchive >> GetPosition() >> GetVelocity() >> GetAccelerate()
>> GetColor() >> GetFixedRotation() >> GetFixedScale();
return *this;
Expand Down
1 change: 1 addition & 0 deletions private/Scene/SceneDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ PIMPL_VECTOR_TYPE_APIS_WITH_PLURAL(SceneDatabase, Mesh, es);
PIMPL_VECTOR_TYPE_APIS(SceneDatabase, Morph);
PIMPL_VECTOR_TYPE_APIS(SceneDatabase, Node);
PIMPL_VECTOR_TYPE_APIS(SceneDatabase, ParticleEmitter);
PIMPL_VECTOR_TYPE_APIS(SceneDatabase, Skeleton);
PIMPL_VECTOR_TYPE_APIS(SceneDatabase, Texture);
PIMPL_VECTOR_TYPE_APIS(SceneDatabase, Track);
PIMPL_STRING_TYPE_APIS(SceneDatabase, Name);
Expand Down
10 changes: 10 additions & 0 deletions private/Scene/SceneDatabaseImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ void SceneDatabaseImpl::Dump() const
printf("\tTexture count : %d\n", GetTextureCount());
printf("\tCamera count : %d\n", GetCameraCount());
printf("\tLight count : %d\n", GetLightCount());
printf("\tSkeleton count : %d\n", GetSkeletonCount());
printf("\tBone count : %d\n", GetBoneCount());
printf("\tAnimation count : %d\n", GetAnimationCount());
printf("\tTrack count : %d\n", GetTrackCount());
Expand Down Expand Up @@ -333,6 +334,15 @@ void SceneDatabaseImpl::Dump() const
}
}

if (GetSkeletonCount() > 0U)
{
printf("\n");
for (const auto& skeleton : GetSkeletons())
{
printf("[Skeleton %u] Name : %s\n", skeleton.GetID().Data(), skeleton.GetName());
}
}

if (GetBoneCount() > 0U)
{
printf("\n");
Expand Down
27 changes: 22 additions & 5 deletions private/Scene/SceneDatabaseImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Scene/Mesh.h"
#include "Scene/Morph.h"
#include "Scene/Node.h"
#include "Scene/Skeleton.h"
#include "Scene/Texture.h"
#include "Scene/Track.h"
#include "Scene/ParticleEmitter.h"
Expand Down Expand Up @@ -47,6 +48,7 @@ class SceneDatabaseImpl
IMPLEMENT_VECTOR_TYPE_APIS(SceneDatabase, Morph);
IMPLEMENT_VECTOR_TYPE_APIS(SceneDatabase, Node);
IMPLEMENT_VECTOR_TYPE_APIS(SceneDatabase, ParticleEmitter);
IMPLEMENT_VECTOR_TYPE_APIS(SceneDatabase, Skeleton);
IMPLEMENT_VECTOR_TYPE_APIS(SceneDatabase, Texture);
IMPLEMENT_VECTOR_TYPE_APIS(SceneDatabase, Track);
IMPLEMENT_STRING_TYPE_APIS(SceneDatabase, Name);
Expand Down Expand Up @@ -93,16 +95,18 @@ class SceneDatabaseImpl
uint32_t materialCount;
uint32_t cameraCount;
uint32_t lightCount;
uint32_t skeletonCount;
uint32_t boneCount;
uint32_t animationCount;
uint32_t trackCount;
uint32_t morphCount;
uint32_t particleCount;
uint32_t particleEmitterCount;

inputArchive >> nodeCount >> meshCount >> morphCount
>> materialCount >> textureCount
>> cameraCount >> lightCount
>> boneCount >> animationCount >> trackCount >> particleCount;
>> skeletonCount >> boneCount >> animationCount >> trackCount
>> particleEmitterCount;

SetNodeCount(nodeCount);
SetMeshCount(meshCount);
Expand All @@ -111,10 +115,11 @@ class SceneDatabaseImpl
SetTextureCount(textureCount);
SetCameraCount(cameraCount);
SetLightCount(lightCount);
SetSkeletonCount(boneCount);
SetBoneCount(boneCount);
SetAnimationCount(animationCount);
SetTrackCount(trackCount);
SetParticleEmitterCount(particleCount);
SetParticleEmitterCount(particleEmitterCount);

for (uint32_t nodeIndex = 0U; nodeIndex < nodeCount; ++nodeIndex)
{
Expand Down Expand Up @@ -151,6 +156,11 @@ class SceneDatabaseImpl
AddLight(Light(inputArchive));
}

for (uint32_t skeletonIndex = 0U; skeletonIndex < skeletonCount; ++skeletonIndex)
{
AddSkeleton(Skeleton(inputArchive));
}

for (uint32_t boneIndex = 0U; boneIndex < boneCount; ++boneIndex)
{
AddBone(Bone(inputArchive));
Expand All @@ -166,7 +176,7 @@ class SceneDatabaseImpl
AddTrack(Track(inputArchive));
}

for (uint32_t particleIndex = 0U; particleIndex < particleCount; ++particleIndex)
for (uint32_t particleIndex = 0U; particleIndex < particleEmitterCount; ++particleIndex)
{
AddParticleEmitter(ParticleEmitter(inputArchive));
}
Expand All @@ -181,7 +191,8 @@ class SceneDatabaseImpl
<< GetNodeCount() << GetMeshCount() << GetMorphCount()
<< GetMaterialCount() << GetTextureCount()
<< GetCameraCount() << GetLightCount()
<< GetBoneCount() << GetAnimationCount() << GetTrackCount()<<GetParticleEmitterCount();
<< GetSkeletonCount() << GetBoneCount() << GetAnimationCount() << GetTrackCount()
<< GetParticleEmitterCount();

for (uint32_t nodeIndex = 0U; nodeIndex < GetNodeCount(); ++nodeIndex)
{
Expand Down Expand Up @@ -225,6 +236,12 @@ class SceneDatabaseImpl
light >> outputArchive;
}

for (uint32_t skeletonIndex = 0U; skeletonIndex < GetSkeletonCount(); ++skeletonIndex)
{
const Skeleton& skeleton = GetSkeleton(skeletonIndex);
skeleton >> outputArchive;
}

for (uint32_t boneIndex = 0U; boneIndex < GetBoneCount(); ++boneIndex)
{
const Bone& bone = GetBone(boneIndex);
Expand Down
12 changes: 12 additions & 0 deletions private/Scene/Skeleton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "Scene/Skeleton.h"
#include "SkeletonImpl.h"

namespace cd
{

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

}
6 changes: 6 additions & 0 deletions private/Scene/SkeletonImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "SkeletonImpl.h"

namespace cd
{

}
35 changes: 35 additions & 0 deletions private/Scene/SkeletonImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include "Base/Template.h"
#include "IO/InputArchive.hpp"
#include "IO/OutputArchive.hpp"
#include "Scene/Types.h"

namespace cd
{

class SkeletonImpl final
{
public:
DECLARE_SCENE_IMPL_CLASS(Skeleton);

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

template<bool SwapBytesOrder>
SkeletonImpl& operator<<(TInputArchive<SwapBytesOrder>& inputArchive)
{
inputArchive >> GetID().Data() >> GetRootBoneID().Data() >> GetName();
return *this;
}

template<bool SwapBytesOrder>
const SkeletonImpl& operator>>(TOutputArchive<SwapBytesOrder>& outputArchive) const
{
outputArchive << GetID().Data() << GetRootBoneID().Data() << GetName();
return *this;
}
};

}
13 changes: 13 additions & 0 deletions public/Scene/APITypeTraits.inl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Mesh;
class Morph;
class Node;
class ParticleEmitter;
class Skeleton;
class Texture;
class Track;

Expand All @@ -35,6 +36,7 @@ struct SceneDatabaseTypeTraits
using Morph = cd::Morph;
using Node = cd::Node;
using ParticleEmitter = cd::ParticleEmitter;
using Skeleton = cd::Skeleton;
using Texture = cd::Texture;
using Track = cd::Track;

Expand Down Expand Up @@ -210,6 +212,17 @@ struct ParticleEmitterTypeTraits
using Name = std::string;
};

// Skeleton
struct SkeletonTypeTraits
{
// Simple
using ID = cd::SkeletonID;
using RootBoneID = cd::BoneID;

// String
using Name = std::string;
};

// Texture
struct TextureTypeTraits
{
Expand Down
1 change: 1 addition & 0 deletions public/Scene/ObjectID.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ObjectID final
ObjectID& operator=(ObjectID&&) = default;
~ObjectID() = default;
T Data() const { return m_id; }
T& Data() { return m_id; }
void Set(T id) { m_id = id; }

ObjectID& operator=(T id) { m_id = id; return *this; }
Expand Down
3 changes: 2 additions & 1 deletion public/Scene/ObjectType.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ enum class ObjectType
Animation,
Track,
Morph,
ParticleEmitter
ParticleEmitter,
Skeleton
};

}
2 changes: 2 additions & 0 deletions public/Scene/SceneDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Scene/Morph.h"
#include "Scene/Node.h"
#include "Scene/ParticleEmitter.h"
#include "Scene/Skeleton.h"
#include "Scene/Texture.h"
#include "Scene/Track.h"

Expand Down Expand Up @@ -49,6 +50,7 @@ class CORE_API SceneDatabase final
EXPORT_VECTOR_TYPE_APIS(SceneDatabase, Morph);
EXPORT_VECTOR_TYPE_APIS(SceneDatabase, Node);
EXPORT_VECTOR_TYPE_APIS(SceneDatabase, ParticleEmitter);
EXPORT_VECTOR_TYPE_APIS(SceneDatabase, Skeleton);
EXPORT_VECTOR_TYPE_APIS(SceneDatabase, Texture);
EXPORT_VECTOR_TYPE_APIS(SceneDatabase, Track);
EXPORT_STRING_TYPE_APIS(SceneDatabase, Name);
Expand Down
22 changes: 22 additions & 0 deletions public/Scene/Skeleton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "Base/Export.h"
#include "IO/InputArchive.hpp"
#include "IO/OutputArchive.hpp"
#include "Scene/Types.h"

namespace cd
{

class SkeletonImpl;

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);
};

}
1 change: 1 addition & 0 deletions public/Scene/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using AnimationID = ObjectID<uint32_t, ObjectType::Animation>;
using TrackID = ObjectID<uint32_t, ObjectType::Track>;
using MorphID = ObjectID<uint32_t, ObjectType::Morph>;
using ParticleEmitterID = ObjectID<uint32_t, ObjectType::ParticleEmitter>;
using SkeletonID = ObjectID<uint32_t, ObjectType::Skeleton>;
static_assert(sizeof(VertexID) == sizeof(uint32_t));

// ID Array
Expand Down

0 comments on commit ba6fb01

Please sign in to comment.