载入中...
搜索中...
未找到
MotionTypes.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
12#include "common/Result.h"
13
14#include <cstddef>
15#include <cstdint>
16
17namespace eve::animation {
18
21 std::uint32_t index = 0;
22 std::uint32_t generation = 0;
23
25 [[nodiscard]] constexpr bool isNull() const noexcept { return generation == 0; }
26
28 [[nodiscard]] constexpr bool operator==(const MotionHandle &other) const noexcept {
29 return index == other.index && generation == other.generation;
30 }
31
33 [[nodiscard]] constexpr bool operator!=(const MotionHandle &other) const noexcept {
34 return !(*this == other);
35 }
36};
37
39struct MotionVec2 {
40 float x = 0.f;
41 float y = 0.f;
42};
43
45struct MotionVec3 {
46 float x = 0.f;
47 float y = 0.f;
48 float z = 0.f;
49};
50
53 float r = 0.f;
54 float g = 0.f;
55 float b = 0.f;
56 float a = 1.f;
57};
58
60struct MotionQuat {
61 float x = 0.f;
62 float y = 0.f;
63 float z = 0.f;
64 float w = 1.f;
65};
66
68enum class MotionLoopMode : std::uint8_t {
69 Restart = 0,
70 Yoyo = 1,
71};
72
77enum class MotionStyle : std::uint8_t {
78 Tween = 0,
79 Punch = 1,
80 Shake = 2,
81};
82
85public:
86 static constexpr const char *capabilityName = "IMotionFloatSink";
87
89 virtual ~IMotionFloatSink() = default;
90
92 [[nodiscard]] virtual eve::Result<void> write(float value) = 0;
93};
94
97public:
98 static constexpr const char *capabilityName = "IMotionVec2Sink";
99
101 virtual ~IMotionVec2Sink() = default;
102
104 [[nodiscard]] virtual eve::Result<void> write(MotionVec2 value) = 0;
105};
106
109public:
110 static constexpr const char *capabilityName = "IMotionVec3Sink";
111
113 virtual ~IMotionVec3Sink() = default;
114
116 [[nodiscard]] virtual eve::Result<void> write(MotionVec3 value) = 0;
117};
118
121public:
122 static constexpr const char *capabilityName = "IMotionColorSink";
123
125 virtual ~IMotionColorSink() = default;
126
128 [[nodiscard]] virtual eve::Result<void> write(MotionColor value) = 0;
129};
130
133public:
134 static constexpr const char *capabilityName = "IMotionQuatSink";
135
137 virtual ~IMotionQuatSink() = default;
138
140 [[nodiscard]] virtual eve::Result<void> write(MotionQuat value) = 0;
141};
142
148public:
150 explicit FloatPointerSink(float *target) : target_(target) {}
151
153 [[nodiscard]] eve::Result<void> write(float value) override;
154
155private:
156 float *target_ = nullptr;
157};
158
164public:
166 FloatBufferSink(float *buffer, std::size_t index) : buffer_(buffer), index_(index) {}
167
169 [[nodiscard]] eve::Result<void> write(float value) override;
170
171private:
172 float *buffer_ = nullptr;
173 std::size_t index_ = 0;
174};
175
176
182public:
184 Vec2PointerSink(float *x, float *y) : x_(x), y_(y) {}
185
187 [[nodiscard]] eve::Result<void> write(MotionVec2 value) override;
188
189private:
190 float *x_ = nullptr;
191 float *y_ = nullptr;
192};
193
198class Vec3PointerSink final : public IMotionVec3Sink {
199public:
201 Vec3PointerSink(float *x, float *y, float *z) : x_(x), y_(y), z_(z) {}
202
204 [[nodiscard]] eve::Result<void> write(MotionVec3 value) override;
205
206private:
207 float *x_ = nullptr;
208 float *y_ = nullptr;
209 float *z_ = nullptr;
210};
211
217public:
219 ColorPointerSink(float *r, float *g, float *b, float *a) : r_(r), g_(g), b_(b), a_(a) {}
220
222 [[nodiscard]] eve::Result<void> write(MotionColor value) override;
223
224private:
225 float *r_ = nullptr;
226 float *g_ = nullptr;
227 float *b_ = nullptr;
228 float *a_ = nullptr;
229};
230
236public:
238 QuatPointerSink(float *x, float *y, float *z, float *w) : x_(x), y_(y), z_(z), w_(w) {}
239
241 [[nodiscard]] eve::Result<void> write(MotionQuat value) override;
242
243private:
244 float *x_ = nullptr;
245 float *y_ = nullptr;
246 float *z_ = nullptr;
247 float *w_ = nullptr;
248};
249
251[[nodiscard]] EVENGINE_API_WORLD float evaluateMotionEase(float t, const char *kind);
252
259[[nodiscard]] EVENGINE_API_WORLD float evaluateMotionOscillation(float t, int frequency, float dampingRatio);
260
265[[nodiscard]] EVENGINE_API_WORLD float evaluateMotionShakeSign(std::uint32_t seed, int frequency, float t, int axis);
266
268[[nodiscard]] MotionColor lerpMotionColor(MotionColor a, MotionColor b, float t);
269
271[[nodiscard]] MotionQuat slerpMotionQuat(MotionQuat a, MotionQuat b, float t);
272
273} // namespace eve::animation
LogicalId target
double value
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
tensor::Graph g
Definition GpuGraph.cpp:7
double r
TokenKind kind
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::unique_ptr< gpgpu::GpuBuffer > buffer
Definition OnnxGpgpu.cpp:26
std::uint32_t seed
Definition PointSet.cpp:807
float t
Move-only, checked operation results for the common layer.
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Sink that writes into borrowed RGBA float pointers. @ownership Does not own the pointers; caller must...
ColorPointerSink(float *r, float *g, float *b, float *a)
Color pointer sink.
Sink that writes into buffer[index] (batch-friendly contiguous target). @ownership Does not own buffe...
FloatBufferSink(float *buffer, std::size_t index)
Float buffer sink.
Sink that writes into a borrowed float*. @ownership Does not own target; caller must keep it alive wh...
FloatPointerSink(float *target)
Float pointer sink.
Push target for a MotionColor motion.
virtual eve::Result< void > write(MotionColor value)=0
Writes .
static constexpr const char * capabilityName
virtual ~IMotionColorSink()=default
Releases IMotionColorSink resources.
Push target for a float motion. Lifetime is borrowed by MotionRuntime.
Definition MotionTypes.h:84
virtual ~IMotionFloatSink()=default
Releases IMotionFloatSink resources.
static constexpr const char * capabilityName
Definition MotionTypes.h:86
virtual eve::Result< void > write(float value)=0
Write the latest interpolated value.
Push target for a MotionQuat motion.
virtual eve::Result< void > write(MotionQuat value)=0
Writes .
virtual ~IMotionQuatSink()=default
Releases IMotionQuatSink resources.
static constexpr const char * capabilityName
Push target for a MotionVec2 motion.
Definition MotionTypes.h:96
virtual ~IMotionVec2Sink()=default
Releases IMotionVec2Sink resources.
virtual eve::Result< void > write(MotionVec2 value)=0
Writes .
static constexpr const char * capabilityName
Definition MotionTypes.h:98
Push target for a MotionVec3 motion.
virtual eve::Result< void > write(MotionVec3 value)=0
Writes .
virtual ~IMotionVec3Sink()=default
Releases IMotionVec3Sink resources.
static constexpr const char * capabilityName
Sink that writes into borrowed quaternion xyzw float pointers. @ownership Does not own the pointers; ...
QuatPointerSink(float *x, float *y, float *z, float *w)
Quat pointer sink.
Property tween — interpolates named float properties from → to over time.
Definition Tween.h:25
Sink that writes into borrowed float x/y pointers. @ownership Does not own the pointers; caller must ...
Vec2PointerSink(float *x, float *y)
Vec 2 pointer sink.
Sink that writes into borrowed float x/y/z pointers. @ownership Does not own the pointers; caller mus...
Vec3PointerSink(float *x, float *y, float *z)
Constructs a Vec3PointerSink.
eve::Result< void > write(MotionVec3 value) override
Writes .
MotionQuat slerpMotionQuat(MotionQuat a, MotionQuat b, float t)
Spherical linear interpolation for MotionQuat (shortest path).
float evaluateMotionOscillation(float t, int frequency, float dampingRatio)
LitMotion-style damped sine envelope in [0,1] progress.
MotionColor lerpMotionColor(MotionColor a, MotionColor b, float t)
Component-wise lerp for MotionColor.
float evaluateMotionShakeSign(std::uint32_t seed, int frequency, float t, int axis)
Deterministic shake sign in [-1,1] for axis (0..n).
MotionLoopMode
Loop behaviour after a cycle completes.
Definition MotionTypes.h:68
@ Restart
Jump back to start each cycle.
@ Yoyo
Alternate direction each cycle.
float evaluateMotionEase(float t, const char *kind)
Evaluate an ease curve; kinds match Math.ease / Tween.
MotionStyle
Evaluation style for a motion slot.
Definition MotionTypes.h:77
@ Punch
Finite damped sine punch about from.
@ Shake
Punch with per-axis deterministic random sign.
Compact RGBA color used by motion adapters.
Definition MotionTypes.h:52
Generation-checked slot identity for a live motion.
Definition MotionTypes.h:20
constexpr bool isNull() const noexcept
True when null.
Definition MotionTypes.h:25
constexpr bool operator==(const MotionHandle &other) const noexcept
Operator ==.
Definition MotionTypes.h:28
constexpr bool operator!=(const MotionHandle &other) const noexcept
Operator !=.
Definition MotionTypes.h:33
Compact quaternion used by motion adapters (xyzw).
Definition MotionTypes.h:60
Compact float2 used by motion adapters (avoids graphics math deps).
Definition MotionTypes.h:39
Compact float3 used by motion adapters.
Definition MotionTypes.h:45