载入中...
搜索中...
未找到
ControlPose.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
6#include "common/Time.h"
7
8#include <string>
9#include <vector>
10
11namespace eve::animation {
12
13class AnimSkeleton;
14
24public:
26 explicit ControlPose(AnimSkeleton *skeleton);
28 ~ControlPose() = default;
29
30 ControlPose(const ControlPose &) = delete;
31 ControlPose &operator=(const ControlPose &) = delete;
32
34 AnimSkeleton *getSkeleton() const { return skeleton_; }
35
37 void setFrequency(float frequencyHz);
39 float getFrequency() const { return frequencyHz_; }
41 void setDamping(float dampingZeta);
43 float getDamping() const { return dampingZeta_; }
45 void setResponse(float response);
47 float getResponse() const { return response_; }
48
50 void setIntegrator(const std::string &kind);
52 std::string getIntegrator() const;
53
55 void setBoneWeight(int boneIndex, float weight);
57 float getBoneWeight(int boneIndex) const;
58
60 void setTargetPose(const AnimPose *target);
62 void snapToTarget();
63
65 AnimPose *getPose();
67 AnimPose *getTargetPose();
68
70 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep &step);
72 void update(float dt);
73
74private:
75 enum class Integrator { SecondOrder, Spring, Pd };
76
77 struct ScalarState {
78 float y = 0.f;
79 float yd = 0.f;
80 float x = 0.f;
81 float xp = 0.f;
82 bool hasPrev = false;
83 };
84
85 struct BoneState {
86 ScalarState px, py, pz;
87 ScalarState qx, qy, qz, qw;
88 ScalarState sx, sy, sz;
89 float weight = 1.f;
90 };
91
92 void refreshCoeffs();
93 void ensureBones(int count);
94 void stepScalar(float dt, float xd, ScalarState &s);
95 void writePoseFromState();
96 void readTargetIntoState(const AnimPose *target, bool snap);
97
98 AnimSkeleton *skeleton_ = nullptr;
99 AnimPose pose_;
100 AnimPose target_;
101
102 float frequencyHz_ = 3.f;
103 float dampingZeta_ = 1.f;
104 float response_ = 1.f;
105 Integrator integrator_ = Integrator::SecondOrder;
106 SecondOrderCoeffs coeffs_{};
107 float kp_ = 0.f;
108 float kd_ = 0.f;
109
110 std::vector<BoneState> bones_;
111 bool hasTarget_ = false;
113 bool hasLastTick_ = false;
114
115 void updateUnchecked(float dt);
116};
117
118} // namespace eve::animation
LogicalId target
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
const std::string & s
float py
float pz
#define EVENGINE_API_WORLD
Definition Export.h:109
std::vector< Colorf > px
TokenKind kind
std::uint32_t count
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
float qy
float qx
float qw
float qz
Move-only operation result carrying either a value or Status.
Definition Result.h:155
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...
Control-theory procedural pose driver: tracks a target AnimPose with per-channel second-order / sprin...
Definition ControlPose.h:23
ControlPose(const ControlPose &)=delete
AnimSkeleton * getSkeleton() const
Returns the skeleton.
Definition ControlPose.h:34
float getFrequency() const
Returns the frequency.
Definition ControlPose.h:39
ControlPose & operator=(const ControlPose &)=delete
float getDamping() const
Returns the damping.
Definition ControlPose.h:43
~ControlPose()=default
Control pose.
float getResponse() const
Returns the response.
Definition ControlPose.h:47
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158