载入中...
搜索中...
未找到
AvatarInstance.h
浏览该文件的文档.
1#pragma once
2
3#include <string>
4#include <unordered_map>
5#include <vector>
6
7namespace eve::graphics {
8struct DrawItem2D;
9class Mesh;
10class Renderable2D;
11class Renderable3D;
12class Texture;
13} // namespace eve::graphics
14
15namespace eve::image {
16class ImageData;
17}
18
19namespace eve::model3d {
20class ModelData;
21}
22
23namespace eve::animation {
24class Tween;
25}
26
27namespace eve::avatar {
28
31public:
32 virtual ~ILive2DBackend() = default;
33 virtual std::string getName() const = 0;
34 virtual bool loadModel(const std::string &path) = 0;
35 virtual void update(float dt) = 0;
36 virtual void setParameter(const std::string &name, float value) = 0;
37 virtual float getParameter(const std::string &name) const = 0;
38 virtual bool setExpression(const std::string &name) = 0;
39 virtual bool setMotion(const std::string &name) = 0;
41 virtual void collectDrawItems(std::vector<graphics::DrawItem2D> & /*out*/) {}
42};
43
45
52public:
53 explicit AvatarInstance(std::string kind);
55
56 AvatarInstance(const AvatarInstance &) = delete;
58
59 std::string getKind() const { return kind_; }
60
61 void setPosition(float x, float y);
62 float getX() const { return x_; }
63 float getY() const { return y_; }
64
65 void setScale(float sx, float sy);
66 float getScaleX() const { return sx_; }
67 float getScaleY() const { return sy_; }
68
69 void setVisible(bool visible);
70 bool isVisible() const { return visible_; }
71
72 void setLayer(int layer);
73 int getLayer() const { return layer_; }
74
75 void setExpression(const std::string &name);
76 std::string getExpression() const { return expression_; }
77
78 void setMotion(const std::string &name);
79 std::string getMotion() const { return motion_; }
80
81 void setParameter(const std::string &name, float value);
82 float getParameter(const std::string &name) const;
83 bool hasParameter(const std::string &name) const;
84 int getParameterCount() const;
85 std::string getParameterName(int index) const;
86
87 void update(float dt);
89 void sync();
90
91 void release();
92
93 // ---- image kind ----
94 bool addLayer(const std::string &name, graphics::Texture *texture, int zIndex);
95 bool setLayerTexture(const std::string &name, graphics::Texture *texture);
96 bool setLayerVisible(const std::string &name, bool visible);
97 bool setLayerOffset(const std::string &name, float ox, float oy);
98 bool setLayerColor(const std::string &name, float r, float g, float b, float a);
99 bool setLayerZ(const std::string &name, int zIndex);
100 bool setLayerSize(const std::string &name, float w, float h);
101 int getLayerCount() const;
102 std::string getLayerName(int index) const;
103 bool hasLayer(const std::string &name) const;
105 bool defineExpression(const std::string &name, const std::string &spec);
106 bool applyExpression(const std::string &name);
107
108 // ---- live2d kind ----
109 bool loadLive2DModel(const std::string &path);
110 std::string getLive2DBackendName() const;
111 bool hasLive2DBackend() const;
112
113 // ---- vroid kind ----
114 bool loadVroidModelPath(const std::string &path);
117 int loadMorphNamesFromModel(int meshIndex = 0);
119 void setTexture(graphics::Texture *texture);
120 void setPosition3D(float x, float y, float z);
121 void setRotation3D(float yaw, float pitch, float roll);
122 void setScale3D(float sx, float sy, float sz);
123 graphics::Renderable3D *getRenderable3D() const { return renderable3d_; }
125 std::string getVroidModelPath() const { return vroidPath_; }
127 bool bakeMorphs();
128
129 // ---- animation tween binding ----
131 void bindTween(animation::Tween *tween);
132 void unbindTween();
133 animation::Tween *getBoundTween() const { return tween_; }
134
135private:
136 struct Layer {
137 std::string name;
138 graphics::Texture *texture = nullptr;
139 graphics::Renderable2D *entity = nullptr;
140 int zIndex = 0;
141 bool visible = true;
142 float ox = 0.f, oy = 0.f;
143 float w = 0.f, h = 0.f; // 0 → use texture size
144 float r = 1.f, g = 1.f, b = 1.f, a = 1.f;
145 };
146
147 Layer *findLayer(const std::string &name);
148 const Layer *findLayer(const std::string &name) const;
149 void syncImageLayers();
150 void syncVroid();
151 void destroyLayers();
152 void destroyVroid();
153 bool applyExpressionSpec(const std::string &spec);
154
155 std::string kind_;
156 float x_ = 0.f, y_ = 0.f;
157 float sx_ = 1.f, sy_ = 1.f;
158 bool visible_ = true;
159 int layer_ = 100;
160 std::string expression_;
161 std::string motion_;
162 std::unordered_map<std::string, float> parameters_;
163 std::vector<std::string> parameterOrder_;
164
165 // image
166 std::vector<Layer> layers_;
167 std::unordered_map<std::string, std::string> expressionDefs_;
168
169 // live2d
170 ILive2DBackend *live2d_ = nullptr;
171
172 // vroid
173 std::string vroidPath_;
174 model3d::ModelData *vroidData_ = nullptr;
175 graphics::Renderable3D *renderable3d_ = nullptr;
176 graphics::Mesh *boundMesh_ = nullptr;
177 float x3_ = 0.f, y3_ = 0.f, z3_ = 0.f;
178 float yaw_ = 0.f, pitch_ = 0.f, roll_ = 0.f;
179 float sx3_ = 1.f, sy3_ = 1.f, sz3_ = 1.f;
180
181 animation::Tween *tween_ = nullptr;
182
183 void ensureParameter(const std::string &name, float value = 0.f);
184 void applyTweenTracks();
185 void syncMorphWeightsToMesh();
186
187 bool released_ = false;
188};
189
190} // namespace eve::avatar
Tok kind
std::string value
int y
Definition Grass.cpp:135
int z
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
int h
int w
uint32_t a
uint32_t b
TileLayer * layer
Mesh * mesh
const char * name
Definition RockMesh.cpp:21
Property tween — interpolates named float properties from → to over time.
Definition Tween.h:21
Unified avatar instance. Kind is a string: "image" | "live2d" | "vroid". Script-facing API avoids ove...
void setScale(float sx, float sy)
void setExpression(const std::string &name)
bool setLayerColor(const std::string &name, float r, float g, float b, float a)
bool setLayerOffset(const std::string &name, float ox, float oy)
void sync()
Push image / live2d layers into ECS or draw queues.
float getParameter(const std::string &name) const
std::string getMotion() const
AvatarInstance & operator=(const AvatarInstance &)=delete
std::string getVroidModelPath() const
std::string getExpression() const
void bindTween(animation::Tween *tween)
Drive x/y/sx/sy and matching parameters from a Tween each update().
bool hasLayer(const std::string &name) const
bool applyExpression(const std::string &name)
std::string getParameterName(int index) const
std::string getKind() const
graphics::Mesh * getBoundMesh() const
void setVisible(bool visible)
bool loadVroidModelPath(const std::string &path)
bool bindVroidModelData(model3d::ModelData *data)
void setMesh(graphics::Mesh *mesh)
int loadMorphNamesFromModel(int meshIndex=0)
Register morph target names from ModelData as parameters (weights default 0).
void setParameter(const std::string &name, float value)
AvatarInstance(const AvatarInstance &)=delete
std::string getLayerName(int index) const
bool bakeMorphs()
Push parameter weights onto Mesh morphs and bake GPU verts when possible.
void setTexture(graphics::Texture *texture)
void setPosition(float x, float y)
void setMotion(const std::string &name)
void setRotation3D(float yaw, float pitch, float roll)
animation::Tween * getBoundTween() const
bool loadLive2DModel(const std::string &path)
bool setLayerZ(const std::string &name, int zIndex)
bool setLayerTexture(const std::string &name, graphics::Texture *texture)
bool addLayer(const std::string &name, graphics::Texture *texture, int zIndex)
std::string getLive2DBackendName() const
bool setLayerSize(const std::string &name, float w, float h)
void setScale3D(float sx, float sy, float sz)
bool setLayerVisible(const std::string &name, bool visible)
bool hasParameter(const std::string &name) const
bool defineExpression(const std::string &name, const std::string &spec)
Spec: "eyes=1;mouth=smile;blush=0" (semicolon-separated name=value).
graphics::Renderable3D * getRenderable3D() const
void setPosition3D(float x, float y, float z)
Optional Live2D runtime backend (Cubism etc.). Registered from C++ / plugins.
virtual void setParameter(const std::string &name, float value)=0
virtual void update(float dt)=0
virtual void collectDrawItems(std::vector< graphics::DrawItem2D > &)
Optional: push drawables into the 2D queue. Default no-op.
virtual std::string getName() const =0
virtual ~ILive2DBackend()=default
virtual bool setMotion(const std::string &name)=0
virtual float getParameter(const std::string &name) const =0
virtual bool loadModel(const std::string &path)=0
virtual bool setExpression(const std::string &name)=0
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:18
Default renderable entity for declarative 2D sprites / solid quads.
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
Represents raw pixel data.
Definition ImageData.h:26
CPU-side decoded 3D model (Assimp scene owned via medialoader::ModelScene). Does not upload to GPU — ...
Definition ModelData.h:23
ILive2DBackend *(*)() Live2DBackendFactory
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6