PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
animation_evaluation.h
1#pragma once
2
3#include "pixelbullet/scene/components/morph_weights_animation_component.h"
4#include "pixelbullet/scene/components/skeleton_animation_component.h"
5#include "pixelbullet/scene/components/transform_animation_component.h"
6#include "pixelbullet/scene/entity_id.h"
7
8#include <optional>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13namespace pixelbullet
14{
15class Filesystem;
16class Scene;
17
19{
20 std::unordered_map<EntityId::ValueType, Transform> values;
21
22 [[nodiscard]] bool Empty() const noexcept
23 {
24 return values.empty();
25 }
26
27 [[nodiscard]] const Transform* Find(EntityId entity) const noexcept
28 {
29 if (!entity)
30 {
31 return nullptr;
32 }
33
34 const auto it = values.find(entity.Raw());
35 return it != values.end() ? &it->second : nullptr;
36 }
37};
38
40{
41public:
42 [[nodiscard]] static SceneTransformOverrides Evaluate(const Scene& scene, float time_seconds);
43 [[nodiscard]] static std::optional<Transform> Evaluate(const TransformAnimationComponent& component, float time_seconds);
44 [[nodiscard]] static std::optional<Transform> Evaluate(const TransformAnimationComponent& component,
45 const AnimationStateComponent* state, float time_seconds);
46};
47
49{
50public:
51 [[nodiscard]] static SceneTransformOverrides Evaluate(const Scene& scene, const Filesystem& filesystem, float time_seconds);
52 [[nodiscard]] static std::optional<SceneTransformOverrides> Evaluate(const SkeletonAnimationComponent& component,
53 const Filesystem& filesystem, float time_seconds);
54 [[nodiscard]] static std::optional<SceneTransformOverrides> Evaluate(const SkeletonAnimationComponent& component,
55 const Filesystem& filesystem, const AnimationStateComponent* state,
56 float time_seconds);
57 [[nodiscard]] static std::optional<SceneTransformOverrides>
58 Evaluate(const SkeletonAnimationComponent& component, const Filesystem& filesystem, std::string_view clip_name, float time_seconds);
59 [[nodiscard]] static std::optional<std::vector<Transform>> SampleLocalTransforms(const SkeletonAnimationComponent& component,
60 const Filesystem& filesystem, float time_seconds);
61 [[nodiscard]] static std::optional<std::vector<Transform>> SampleLocalTransforms(const SkeletonAnimationComponent& component,
62 const Filesystem& filesystem,
63 const AnimationStateComponent* state,
64 float time_seconds);
65 [[nodiscard]] static std::optional<std::vector<Transform>> SampleLocalTransforms(const SkeletonAnimationComponent& component,
66 const Filesystem& filesystem,
67 std::string_view clip_name, float time_seconds);
68 [[nodiscard]] static std::optional<std::vector<Transform>> SampleRestPoseLocalTransforms(const SkeletonAnimationComponent& component,
69 const Filesystem& filesystem);
70 [[nodiscard]] static float ResolveClipLength(const SkeletonAnimationComponent& component, const Filesystem& filesystem,
71 const AnimationStateComponent* state);
72 [[nodiscard]] static float ResolveClipLength(const SkeletonAnimationComponent& component, const Filesystem& filesystem,
73 std::string_view clip_name);
74};
75
76enum class LayeredSkeletonPoseBlendMode
77{
78 Override,
79 Additive,
80};
81
83{
84 std::string layer_id;
85 LayeredSkeletonPoseBlendMode blend_mode = LayeredSkeletonPoseBlendMode::Override;
86 std::vector<std::string> mask_joint_names;
87 float layer_weight = 1.0f;
88 bool reference_pose = false;
89 std::string primary_clip;
90 std::optional<std::string> secondary_clip;
91 float blend_factor = 0.0f;
92 float time_seconds = 0.0f;
93};
94
96{
97public:
98 [[nodiscard]] static std::optional<std::vector<Transform>> EvaluateLocalTransforms(const SkeletonAnimationComponent& component,
99 const Filesystem& filesystem,
100 const Scene& joint_name_scene,
101 const std::vector<LayeredSkeletonPoseLayer>& layers);
102};
103
105{
106 std::unordered_map<EntityId::ValueType, std::vector<float>> values;
107
108 [[nodiscard]] bool Empty() const noexcept
109 {
110 return values.empty();
111 }
112
113 [[nodiscard]] const std::vector<float>* Find(EntityId entity) const noexcept
114 {
115 if (!entity)
116 {
117 return nullptr;
118 }
119
120 const auto it = values.find(entity.Raw());
121 return it != values.end() ? &it->second : nullptr;
122 }
123};
124
126{
127public:
128 [[nodiscard]] static SceneMorphWeightOverrides Evaluate(const Scene& scene, float time_seconds);
129 [[nodiscard]] static std::optional<std::vector<float>> Evaluate(const MorphWeightsAnimationComponent& component, float time_seconds);
130 [[nodiscard]] static std::optional<std::vector<float>> Evaluate(const MorphWeightsAnimationComponent& component,
131 const AnimationStateComponent* state, float time_seconds);
132};
133} // namespace pixelbullet
Definition entity_id.h:11
Definition filesystem.h:19
Definition animation_evaluation.h:96
Definition animation_evaluation.h:126
Definition scene.h:30
Definition animation_evaluation.h:49
Definition animation_evaluation.h:40
Definition animation_state_component.h:10
Definition animation_evaluation.h:83
Definition morph_weights_animation_component.h:100
Definition animation_evaluation.h:105
Definition animation_evaluation.h:19
Definition skeleton_animation_component.h:33
Definition transform_animation_component.h:91
Definition transform.h:14