载入中...
搜索中...
未找到
Animation.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
8#include "animation/Tween.h"
9#include "common/Module.h"
10#include "common/Time.h"
11
12#include <string>
13#include <memory>
14#include <unordered_map>
15#include <vector>
16
17namespace ssq {
18class Class;
19}
20
21namespace eve::model3d {
22class ModelData;
23}
24
25namespace eve::graphics {
26class Graphics;
27}
28
29namespace eve::animation {
30
31class AnimSkeleton;
32class AnimClip;
33class AnimPose;
34class AnimPlayer;
35class AnimGraph;
36class AnimBoneMask;
37class AnimLayerMixer;
38class AnimStateMachine;
39class MotionDatabase;
40class MotionMatcher;
41class ControlAnim;
42class ControlPose;
43class PhysicalBalancePose;
44class AnimSkin;
45class AnimLattice;
46class AnimTrail;
47class AnimBatch;
48class AnimConstraintStack;
49class AnimSyncGroup;
50class DynamicBoneSolver;
51class FootIKSolver;
52class SpriteSheet;
53class SpriteClip;
54class SpriteAnim;
55class SpineAtlas;
56class SpineSkeletonData;
57class SpineSkeleton;
58class SpineAnim;
59
81public:
83 // Declared, not `= default`: class-level dllexport forces MSVC to compute the
84 // defaulted constructor's exception specification, which needs the destructor of
85 // every member -- and `SpriteSheet` is only forward-declared here (line 47), so an
86 // in-class `= default` is C2027 "can't delete an incomplete type". Defined in
87 // Animation.cpp, which includes animation/SpriteSheet.h.
91 ~Animation() override;
92 // `spriteSequenceCache_` is a container of `unique_ptr`: dllexport instantiates
93 // every member, so the implicitly-defined copy operations would instantiate the
94 // container's copy (hard C2280). Copy is deleted; no move is declared because
95 // `MotionRuntime motions_` is itself neither copyable nor movable
96 // (MotionRuntime.h:130 deletes copy and declares no move), which would make a
97 // defaulted move operation ill-formed.
98 Animation(const Animation &) = delete;
99 Animation &operator=(const Animation &) = delete;
100
102 Tween *newTween(float duration = 1.f);
103
105 SpriteSheet *newSpriteSheet();
111 SpriteSheet *newSpriteSheetFromSequence(eve::graphics::Graphics *gfx,
112 const std::string &pattern, int first,
113 int last, int columns = 0);
122 SpriteSheet *newSpriteSheetFromAtlasJson(eve::graphics::Graphics *gfx,
123 const std::string &texturePath,
124 const std::string &jsonPath);
126 SpriteClip *newSpriteClip(const std::string &name = "");
128 SpriteAnim *newSpriteAnim();
130 int getSpriteSequenceCacheCount() const;
132 int getSpriteSequenceCacheBytes() const;
134 void clearSpriteSequenceCache();
135
137 SpineAtlas *newSpineAtlas();
139 SpineSkeletonData *newSpineSkeletonData();
141 SpineSkeleton *newSpineSkeleton(SpineSkeletonData *data);
143 SpineAnim *newSpineAnim(SpineSkeleton *skeleton);
144
146 SpineAtlas *newSpineAtlasFromFile(const std::string &path);
148 SpineAtlas *newSpineAtlasFromText(const std::string &text);
150 SpineSkeletonData *newSpineSkeletonDataFromFile(const std::string &path);
152 SpineSkeletonData *newSpineSkeletonDataFromJson(const std::string &json);
153
155 AnimSkeleton *newSkeleton();
157 AnimClip *newClip(const std::string &name = "");
159 AnimPose *newPose(int boneCount = 0);
161 AnimBatch *newBatch();
163 AnimConstraintStack *newConstraintStack(AnimSkeleton* skeleton);
169 DynamicBoneSolver *newDynamicBoneSolver(AnimSkeleton *skeleton);
170
175 int setupHairChain(DynamicBoneSolver *solver, const std::string &rootBone,
176 const std::string &tipBone, float stiffness = 0.12f,
177 float damping = 0.18f, float inertia = 0.8f, float endLength = 0.08f,
178 bool selfCollision = true);
179
184 int setupHairHeadCollider(DynamicBoneSolver *solver, const std::string &boneName,
185 float radius = 0.12f);
186
192 FootIKSolver *newFootIKSolver(AnimSkeleton *skeleton);
194 AnimSyncGroup* newSyncGroup();
196 AnimPlayer *newPlayer(AnimSkeleton *skeleton);
198 AnimGraph *newGraph(AnimSkeleton *skeleton);
200 AnimBoneMask* newBoneMask(AnimSkeleton* skeleton);
202 AnimLayerMixer* newLayerMixer(AnimSkeleton* skeleton);
204 AnimStateMachine *newStateMachine(AnimSkeleton *skeleton);
206 MotionDatabase *newMotionDatabase(AnimSkeleton *skeleton);
208 MotionMatcher *newMotionMatcher(AnimSkeleton *skeleton, MotionDatabase *database);
209
214 ControlAnim *newControlAnim(float frequencyHz = 3.f, float dampingZeta = 1.f,
215 float response = 1.f);
217 ControlPose *newControlPose(AnimSkeleton *skeleton);
227 PhysicalBalancePose* newPhysicalBalancePose(AnimSkeleton* skeleton);
228
235 AnimSkeleton *newSkeletonFromModel(eve::model3d::ModelData *model);
237 AnimClip *newClipFromModel(eve::model3d::ModelData *model, AnimSkeleton *skeleton,
238 int animIndex = 0);
249 AnimSkeleton *newSkeletonFromAnimationFixtureText(const std::string &path);
261 AnimClip *newClipFromAnimationFixtureText(const std::string &path);
262
267 AnimSkin *newSkinFromModel(eve::model3d::ModelData *model, int meshIndex,
268 AnimSkeleton *skeleton);
269
276 AnimLattice *newLattice(int divX = 2, int divY = 2, int divZ = 2);
277
279 AnimLattice *newLatticeFromModel(eve::model3d::ModelData *model, int meshIndex,
280 int divX = 2, int divY = 2, int divZ = 2);
281
286 AnimTrail *newTrail(int capacity = 64);
287
292 [[nodiscard]] MotionBuilder motion(float from, float to, float duration);
294 [[nodiscard]] MotionVec2Builder motionVec2(MotionVec2 from, MotionVec2 to, float duration);
296 [[nodiscard]] MotionVec3Builder motionVec3(MotionVec3 from, MotionVec3 to, float duration);
297
304 [[nodiscard]] MotionBuilder punch(float from, float strength, float duration);
306 [[nodiscard]] MotionBuilder shake(float from, float strength, float duration);
308 [[nodiscard]] MotionVec2Builder punchVec2(MotionVec2 from, MotionVec2 strength, float duration);
310 [[nodiscard]] MotionVec2Builder shakeVec2(MotionVec2 from, MotionVec2 strength, float duration);
312 [[nodiscard]] MotionVec3Builder punchVec3(MotionVec3 from, MotionVec3 strength, float duration);
314 [[nodiscard]] MotionVec3Builder shakeVec3(MotionVec3 from, MotionVec3 strength, float duration);
316 [[nodiscard]] MotionColorBuilder motionColor(MotionColor from, MotionColor to, float duration);
318 [[nodiscard]] MotionQuatBuilder motionQuat(MotionQuat from, MotionQuat to, float duration);
319
320 [[nodiscard]] MotionSequence sequence();
321
323 [[nodiscard]] MotionRuntime &motions() noexcept { return motions_; }
324 [[nodiscard]] const MotionRuntime &motions() const noexcept { return motions_; }
325
327 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep &step);
328
330 [[nodiscard]] eve::SimulationTick currentTick() const noexcept { return lastTick_; }
331
333 void update(float dt);
334
336 int getTweenCount() const { return static_cast<int>(tweens_.size()); }
338 int getMotionCount() const { return motions_.activeCount(); }
339
344 void ensureMotionCapacity(std::size_t floatCount) { motions_.ensureCapacity(floatCount); }
346 [[nodiscard]] std::size_t getMotionFloatCapacity() const noexcept {
347 return motions_.floatCapacity();
348 }
350 [[nodiscard]] std::size_t getMotionFloatFreeCount() const noexcept {
351 return motions_.floatFreeCount();
352 }
354 int getSpriteAnimCount() const { return static_cast<int>(spriteAnims_.size()); }
356 int getSpineAnimCount() const { return static_cast<int>(spineAnims_.size()); }
358 int getActiveCount() const;
359
361 void clearFinished();
363 void clearAll();
364
365private:
366 std::unordered_map<std::string, std::unique_ptr<SpriteSheet>> spriteSequenceCache_;
367 friend class Tween;
368 friend class SpriteAnim;
369 friend class SpineAnim;
370
371 void registerTween(Tween *t);
372 void unregisterTween(Tween *t);
373 void registerSpriteAnim(SpriteAnim *a);
374 void unregisterSpriteAnim(SpriteAnim *a);
375 void registerSpineAnim(SpineAnim *a);
376 void unregisterSpineAnim(SpineAnim *a);
377
378 std::vector<Tween *> tweens_;
379 std::vector<SpriteAnim *> spriteAnims_;
380 std::vector<SpineAnim *> spineAnims_;
381 MotionRuntime motions_;
383 bool hasLastTick_ = false;
384};
385
391
392} // namespace eve::animation
float duration
HSQOBJECT cls
Definition ECS.cpp:39
std::string name
Definition ECS.cpp:154
#define EVENGINE_API_WORLD
Definition Export.h:109
std::string pattern
float inertia
float strength
std::uint32_t capacity
std::int32_t first
std::string to
std::string from
std::string response
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
Fluent LitMotion-style builder that commits into MotionRuntime.
Dense motion storage advanced by Animation::advance(SimulationStep).
Lean LitMotion-style sequence: Append / Join / Insert / AppendInterval.
LitMotion-style typed motion handles, values, and sink interfaces.
double dt
std::unique_ptr< gpgpu::Sequence > sequence
Definition OnnxGpgpu.cpp:43
std::string path
Definition PlayHost.cpp:111
float t
glm::mat4 model
std::string text
int columns
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:451
EVENGINE_API_FOUNDATION public API.
Definition Module.h:48
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Parallel batch evaluator for independent character clip poses. Script type: AnimBatch.
Definition AnimBatch.h:13
Per-bone weights used by override and additive animation layers.
Keyframed skeletal animation clip (local TRS tracks per bone). Script type: AnimClip.
Definition AnimClip.h:145
Ordered main-thread post-process stack with aim, limb IK and foot planting.
Composable runtime pose graph supporting clips, blends, additive layers, per-bone masks,...
Definition AnimGraph.h:26
CPU 3D lattice scale-deformer (晶格缩放变形).
Definition AnimLattice.h:42
Combines a borrowed base pose source with ordered override/additive layers.
Single-clip (or cross-fading) 3D animation player. Script type: AnimPlayer.
Definition AnimPlayer.h:33
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
CPU linear-blend skinning binding for one mesh against an AnimSkeleton.
Definition AnimSkin.h:47
Clip-driven animation state machine with float/bool/trigger parameters and cross-fade transitions....
Marker-aware synchronization group for locomotion animation players.
Motion trail / afterimage recorder + 2D trajectory drawer.
Definition AnimTrail.h:34
Animation module — tween factory + 2D sprite-sheet / Spine + 3D skeletal playback (player / state mac...
Definition Animation.h:80
std::size_t getMotionFloatFreeCount() const noexcept
Returns the motion float free count.
Definition Animation.h:350
Animation & operator=(const Animation &)=delete
int getSpriteAnimCount() const
Returns the sprite anim count.
Definition Animation.h:354
Animation(const Animation &)=delete
std::size_t getMotionFloatCapacity() const noexcept
Returns the motion float capacity.
Definition Animation.h:346
int getTweenCount() const
Returns the tween count.
Definition Animation.h:336
void ensureMotionCapacity(std::size_t floatCount)
Pre-size motion float pool for churn-free spawn (Phase 4).
Definition Animation.h:344
const MotionRuntime & motions() const noexcept
Definition Animation.h:324
int getSpineAnimCount() const
Returns the spine anim count.
Definition Animation.h:356
int getMotionCount() const
Returns the motion count.
Definition Animation.h:338
eve::SimulationTick currentTick() const noexcept
Last scheduler tick consumed by the checked module pump.
Definition Animation.h:330
MotionRuntime & motions() noexcept
Shared motion storage for builders and handle queries.
Definition Animation.h:323
Control-theory procedural animation for named scalar properties.
Definition ControlAnim.h:25
Control-theory procedural pose driver: tracks a target AnimPose with per-channel second-order / sprin...
Definition ControlPose.h:23
World-space spring-chain solver that writes results as local bone rotations.
Paired-foot IK with contact smoothing and pelvis compensation.
Configure then bind/run a float motion into a MotionRuntime.
Color fluent builder (Tween / lerp only).
Baked motion-matching feature database from one or more AnimClips. Feature layout per frame: [0....
Runtime motion matching player: builds a query feature from current pose + desired trajectory,...
Quaternion fluent builder (Tween / slerp only).
Owns typed motion slots and applies SimulationStep updates.
Schedule unspawned builders onto a shared MotionRuntime timeline.
Authored-pose overlay that wobbles from world impulses and recovers balance.
Spine animation player + 2D draw collector (region attachments).
Definition SpineAnim.h:35
Esoteric Spine .atlas text parser (region rectangles + page metadata). Does not load image pixels — b...
Definition SpineAtlas.h:16
Spine skeleton JSON data (bones / slots / skins / animations).
Runtime Spine skeleton pose (local + world bone transforms, slot attachments). Script type: SpineSkel...
2D sprite-sheet clip player.
Definition SpriteAnim.h:26
Named 2D frame sequence referencing SpriteSheet frame indices. Script type: SpriteClip.
Definition SpriteClip.h:17
Sprite-sheet / texture-atlas frame table (pixel rects).
Definition SpriteSheet.h:23
Property tween — interpolates named float properties from → to over time.
Definition Tween.h:25
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
CPU-side decoded 3D model (Assimp scene owned via medialoader::ModelScene). Does not upload to GPU — ...
Definition ModelData.h:39
void exposeAnimationModelImportBindings(ssq::Class &cls)
Register ModelData/Assimp import factories when AnimationModelImport.cpp is linked (OPTIONAL_DEPS mod...
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
EVEngine ECS 集成层:底层实现使用 sunxfancy/ECS.hpp https://github.com/sunxfancy/ECS.hpp
Definition ECS.h:21
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Compact RGBA color used by motion adapters.
Definition MotionTypes.h:52
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