Animation node Channels copy complete
This commit is contained in:
parent
6615f0c2b8
commit
69d3cc7619
|
@ -95,6 +95,11 @@ enum class PRIMITIVE_MODE : int
|
|||
TRIANLE_FAN = 6
|
||||
};
|
||||
|
||||
constexpr std::string_view TRANSLATION_PATH{ "translation" };
|
||||
constexpr std::string_view SCALE_PATH{ "scale" };
|
||||
constexpr std::string_view ROTATION_PATH{ "rotation" };
|
||||
constexpr std::string_view WEIGHTS_PATH{ "weights" };
|
||||
|
||||
//Directory
|
||||
#ifdef _PUBLISH
|
||||
constexpr std::string_view ASSET_ROOT{ "Assets" };
|
||||
|
|
|
@ -53,6 +53,9 @@ namespace SH_COMP
|
|||
|
||||
template<typename T>
|
||||
static void FetchData(int accessorID, std::vector<T>& dst);
|
||||
|
||||
template<typename T>
|
||||
static void FetchChannelKeyFrame(int targetNode, int inputAcc, int outputAcc, int nodeTarget, std::vector<T>& dst);
|
||||
public:
|
||||
static void LoadAndCompile(AssetPath path) noexcept;
|
||||
};
|
||||
|
|
|
@ -162,6 +162,30 @@ namespace SH_COMP
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void MeshCompiler::FetchChannelKeyFrame(int targetNode, int inputAcc, int outputAcc, int nodeTarget, std::vector<T>& dst)
|
||||
{
|
||||
// ONLY ALLOW THIS FUNCTION TO BE USED ON KEY DATA STRUCT
|
||||
static_assert(std::derived_from<T, KeyBase> == true);
|
||||
|
||||
std::vector<float> inputVec;
|
||||
std::vector<SHVec3> outputVec;
|
||||
FetchData(inputAcc, inputVec);
|
||||
FetchData(outputAcc, outputVec);
|
||||
|
||||
dst.resize(inputVec.size());
|
||||
|
||||
std::ranges::transform(
|
||||
inputVec,
|
||||
outputVec,
|
||||
dst.begin(),
|
||||
[](float const& time, SHVec3 const& value)->T
|
||||
{
|
||||
return { time, value };
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
inline void MeshCompiler::BuildHeaders(ModelRef asset) noexcept
|
||||
{
|
||||
// Mesh Headers
|
||||
|
@ -195,12 +219,34 @@ namespace SH_COMP
|
|||
asset.anims.resize(model.animations.size());
|
||||
for (auto i {0}; i < model.animations.size(); ++i)
|
||||
{
|
||||
auto& animData{ model.animations[i] };
|
||||
auto const& animData{ model.animations[i] };
|
||||
auto& anim{ asset.anims[i] };
|
||||
|
||||
anim.name = animData.name;
|
||||
|
||||
for (auto const& channel : animData.channels)
|
||||
{
|
||||
auto const& sampler{ animData.samplers[channel.sampler] };
|
||||
|
||||
// Resize nodes vector to latest largest index called
|
||||
if (anim.nodes.size() <= channel.target_node)
|
||||
anim.nodes.resize(channel.target_node + 1);
|
||||
|
||||
if (channel.target_path == TRANSLATION_PATH.data())
|
||||
FetchChannelKeyFrame(channel.target_node, sampler.input, sampler.output, channel.target_node, anim.nodes[channel.target_node].positionKeys);
|
||||
else if (channel.target_path == SCALE_PATH.data())
|
||||
FetchChannelKeyFrame(channel.target_node, sampler.input, sampler.output, channel.target_node, anim.nodes[channel.target_node].scaleKeys);
|
||||
else if (channel.target_path == ROTATION_PATH.data())
|
||||
FetchChannelKeyFrame(channel.target_node, sampler.input, sampler.output, channel.target_node, anim.nodes[channel.target_node].rotationKeys);
|
||||
|
||||
anim.nodes[channel.target_node].interpolation =
|
||||
sampler.interpolation == "LINEAR" ? AnimationInterpolation::LINEAR :
|
||||
sampler.interpolation == "STEP" ? AnimationInterpolation::STEP :
|
||||
sampler.interpolation == "CUBICSPLINE" ? AnimationInterpolation::CUBICSPLINE :
|
||||
AnimationInterpolation::DEFAULT;
|
||||
}
|
||||
|
||||
std::cout << "all anim channels copied\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace SH_COMP
|
|||
|
||||
for (auto i{0}; i < header.animNodeCount; ++i)
|
||||
{
|
||||
WriteAnimNode(file, header.nodeHeaders[i], data.nodeChannels[i]);
|
||||
WriteAnimNode(file, header.nodeHeaders[i], data.nodes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,13 +124,8 @@ namespace SH_COMP
|
|||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&node.pre),
|
||||
sizeof(AnimationBehaviour)
|
||||
);
|
||||
|
||||
file.write(
|
||||
reinterpret_cast<char const*>(&node.post),
|
||||
sizeof(AnimationBehaviour)
|
||||
reinterpret_cast<char const*>(&node.interpolation),
|
||||
sizeof(AnimationInterpolation)
|
||||
);
|
||||
|
||||
uint32_t const keySize = node.positionKeys.size();
|
||||
|
|
|
@ -16,32 +16,27 @@
|
|||
|
||||
namespace SH_COMP
|
||||
{
|
||||
enum class AnimationBehaviour : uint8_t
|
||||
enum class AnimationInterpolation : uint8_t
|
||||
{
|
||||
DEFAULT = 0x0,
|
||||
CONSTANT = 0x1,
|
||||
LINEAR = 0x2,
|
||||
REPEAT = 0x3
|
||||
DEFAULT = 0x1,
|
||||
LINEAR = 0x1,
|
||||
STEP = 0x2,
|
||||
CUBICSPLINE = 0x3
|
||||
};
|
||||
|
||||
// Base
|
||||
struct KeyBase
|
||||
{
|
||||
float time;
|
||||
SHVec3 value;
|
||||
};
|
||||
|
||||
// Smallest data containers
|
||||
struct PositionKey
|
||||
{
|
||||
float time;
|
||||
SHVec3 value;
|
||||
};
|
||||
struct PositionKey :KeyBase {};
|
||||
|
||||
struct RotationKey
|
||||
{
|
||||
float time;
|
||||
SHVec4 value;
|
||||
};
|
||||
struct RotationKey : KeyBase {};
|
||||
|
||||
struct ScaleKey
|
||||
{
|
||||
float time;
|
||||
SHVec3 value;
|
||||
};
|
||||
struct ScaleKey :KeyBase {};
|
||||
|
||||
// Headers for read/write
|
||||
struct AnimNodeInfo
|
||||
|
@ -63,13 +58,11 @@ namespace SH_COMP
|
|||
struct AnimNode
|
||||
{
|
||||
std::string name;
|
||||
AnimationBehaviour pre;
|
||||
AnimationBehaviour post;
|
||||
AnimationInterpolation interpolation;
|
||||
|
||||
std::vector<PositionKey> positionKeys;
|
||||
std::vector<RotationKey> rotationKeys;
|
||||
std::vector<ScaleKey> scaleKeys;
|
||||
|
||||
};
|
||||
|
||||
struct AnimData
|
||||
|
@ -79,7 +72,7 @@ namespace SH_COMP
|
|||
double duration;
|
||||
double ticksPerSecond;
|
||||
|
||||
std::vector<AnimNode> nodeChannels;
|
||||
std::vector<AnimNode> nodes;
|
||||
//std::vector<aiMeshAnim*> meshChannels;
|
||||
//std::vector<aiMeshMorphAnim*> morphMeshChannels;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue