载入中...
搜索中...
未找到
Avatar.cpp
浏览该文件的文档.
1#include "avatar/Avatar.h"
2#include "avatar/Appearance.h"
4#include "avatar/VrmRuntime.h"
6#include "graphics/Graphics.h"
9
10#include <algorithm>
11#include <simplesquirrel/simplesquirrel.hpp>
12
13namespace eve::avatar {
14namespace {
15
16template <class Map>
17std::vector<std::string> sortedKeys(const Map& values) {
18 std::vector<std::string> names;
19 names.reserve(values.size());
20 for (const auto& [name, value] : values) {
21 (void)value;
22 names.push_back(name);
23 }
24 std::sort(names.begin(), names.end());
25 return names;
26}
27
28} // namespace
29
30void AvatarInstance::ensureParameter(const std::string& name, float value) {
31 if (name.empty()) return;
32 if (parameters_.find(name) == parameters_.end()) {
33 parameterOrder_.push_back(name);
34 parameterMetadata_.emplace(name, ParameterMetadata{value, 0.f, 1.f});
35 }
36 parameters_[name] = value;
37}
38
39bool AvatarInstance::defineParameter(const std::string& name, float defaultValue, float minimum,
40 float maximum) {
41 if (name.empty() || minimum > maximum) return false;
42 ensureParameter(name, defaultValue);
43 parameterMetadata_[name] = {defaultValue, minimum, maximum};
44 return true;
45}
46
47float AvatarInstance::getParameterDefault(const std::string& name) const {
48 const auto found = parameterMetadata_.find(name);
49 return found == parameterMetadata_.end() ? 0.f : found->second.defaultValue;
50}
51
52float AvatarInstance::getParameterMinimum(const std::string& name) const {
53 const auto found = parameterMetadata_.find(name);
54 return found == parameterMetadata_.end() ? 0.f : found->second.minimum;
55}
56
57float AvatarInstance::getParameterMaximum(const std::string& name) const {
58 const auto found = parameterMetadata_.find(name);
59 return found == parameterMetadata_.end() ? 1.f : found->second.maximum;
60}
61
62bool AvatarInstance::removeExpression(const std::string& name) {
63 return expressionDefs_.erase(name) > 0;
64}
65
67 int count = static_cast<int>(expressionDefs_.size());
68 if (vrm_)
69 for (const auto& e : vrm_->document.expressions)
70 if (!expressionDefs_.contains(e.name)) ++count;
71 return count;
72}
73
75 std::vector<std::string> names = sortedKeys(expressionDefs_);
76 if (vrm_)
77 for (const auto& e : vrm_->document.expressions) names.push_back(e.name);
78 std::sort(names.begin(), names.end());
79 names.erase(std::unique(names.begin(), names.end()), names.end());
80 return index < 0 || index >= static_cast<int>(names.size()) ? std::string{}
81 : names[static_cast<size_t>(index)];
82}
83
84bool AvatarInstance::unregisterMotion(const std::string& name) {
85 return motions_.erase(name) > 0;
86}
87
89 return static_cast<int>(motions_.size());
90}
91
92std::string AvatarInstance::getMotionName(int index) const {
93 const std::vector<std::string> names = sortedKeys(motions_);
94 return index < 0 || index >= static_cast<int>(names.size()) ? std::string{}
95 : names[static_cast<size_t>(index)];
96}
97
99 const auto found = motions_.find(name);
100 return found == motions_.end() ? nullptr : found->second;
101}
102
103Live2DBackendFactory Avatar::live2dFactory_ = &createNullLive2DBackend;
104
106
108 // Instances may outlive the module if script GC still holds them; detach.
109 for (AvatarInstance *a : avatars_) {
110 (void)a;
111 }
112 avatars_.clear();
113}
114
115void Avatar::registerInstance(AvatarInstance *a) {
116 if (!a) return;
117 if (std::find(avatars_.begin(), avatars_.end(), a) == avatars_.end())
118 avatars_.push_back(a);
119}
120
121void Avatar::unregisterInstance(AvatarInstance *a) {
122 if (!a) return;
123 auto it = std::find(avatars_.begin(), avatars_.end(), a);
124 if (it != avatars_.end()) avatars_.erase(it);
125}
126
128
130
132
133void Avatar::update(float dt) {
134 std::vector<AvatarInstance *> snapshot = avatars_;
135 for (AvatarInstance *a : snapshot) {
136 if (a) a->update(dt);
137 }
138}
139
141 std::vector<AvatarInstance *> snapshot = avatars_;
142 for (AvatarInstance *a : snapshot) {
143 if (a) a->sync();
144 }
145}
146
148 sync();
149 if (!gfx) return;
150 std::vector<graphics::DrawItem2D> items;
152 for (AvatarInstance* a : avatars_) {
153 if (a) a->collectLive2DDrawItems(items);
154 }
155 graphics::RenderSystem::drawItems(*gfx, items, false);
156}
157
158int Avatar::getAvatarCount() const { return int(avatars_.size()); }
159
161 live2dFactory_ = factory ? factory : &createNullLive2DBackend;
162}
163
165
167 Live2DBackendFactory f = live2dFactory_ ? live2dFactory_ : &createNullLive2DBackend;
168 return f();
169}
170
173 if (!tmp) return "none";
174 std::string n = tmp->getName();
175 delete tmp;
176 return n;
177}
178
181 if (!tmp) return false;
182 const bool available = tmp->isRuntimeAvailable();
183 delete tmp;
184 return available;
185}
186
187void Avatar::expose(ssq::Table &table) {
188 exposeAppearance(table);
189 auto cls = table.addClass(name, Avatar::create, false);
190 expose(cls);
191
192 auto av = table.addClass<AvatarInstance>(
193 "AvatarInstance",
194 std::function<AvatarInstance *()>([]() -> AvatarInstance * { return nullptr; }), true);
195
196 av.addFunc("getKind", &AvatarInstance::getKind);
197 av.addFunc("setPosition", &AvatarInstance::setPosition);
198 av.addFunc("getX", &AvatarInstance::getX);
199 av.addFunc("getY", &AvatarInstance::getY);
200 av.addFunc("setScale", &AvatarInstance::setScale);
201 av.addFunc("getScaleX", &AvatarInstance::getScaleX);
202 av.addFunc("getScaleY", &AvatarInstance::getScaleY);
203 av.addFunc("setVisible", &AvatarInstance::setVisible);
204 av.addFunc("isVisible", &AvatarInstance::isVisible);
205 av.addFunc("setLayer", &AvatarInstance::setLayer);
206 av.addFunc("getLayer", &AvatarInstance::getLayer);
207 av.addFunc("setExpression", &AvatarInstance::setExpression);
208 av.addFunc("getExpression", &AvatarInstance::getExpression);
209 av.addFunc("setMotion", &AvatarInstance::setMotion);
210 av.addFunc("getMotion", &AvatarInstance::getMotion);
211 av.addFunc("setParameter", &AvatarInstance::setParameter);
212 av.addFunc("getParameter", &AvatarInstance::getParameter);
213 av.addFunc("hasParameter", &AvatarInstance::hasParameter);
214 av.addFunc("getParameterCount", &AvatarInstance::getParameterCount);
215 av.addFunc("getParameterName", &AvatarInstance::getParameterName);
216 av.addFunc("defineParameter", &AvatarInstance::defineParameter);
217 av.addFunc("getParameterDefault", &AvatarInstance::getParameterDefault);
218 av.addFunc("getParameterMinimum", &AvatarInstance::getParameterMinimum);
219 av.addFunc("getParameterMaximum", &AvatarInstance::getParameterMaximum);
220 av.addFunc("update", &AvatarInstance::update);
221 av.addFunc("sync", &AvatarInstance::sync);
222 av.addFunc("release", &AvatarInstance::release);
223
224 // addLayer / setLayerTexture accept a nullable texture (colored placeholder
225 // layers). ssq's default pointer binding rejects Squirrel `null`, so accept
226 // ssq::Object and translate null -> nullptr.
227 av.addFunc("addLayer", [](AvatarInstance *a, const std::string &name, ssq::Object textureObj,
228 int zIndex) -> bool {
229 graphics::Texture *tex =
230 textureObj.isNull() ? nullptr : textureObj.toPtrUnsafe<graphics::Texture *>();
231 return a->addLayer(name, tex, zIndex);
232 });
233 av.addFunc("setLayerTexture", [](AvatarInstance *a, const std::string &name,
234 ssq::Object textureObj) -> bool {
235 graphics::Texture *tex =
236 textureObj.isNull() ? nullptr : textureObj.toPtrUnsafe<graphics::Texture *>();
237 return a->setLayerTexture(name, tex);
238 });
239 av.addFunc("setLayerVisible", &AvatarInstance::setLayerVisible);
240 av.addFunc("setLayerOffset", &AvatarInstance::setLayerOffset);
241 av.addFunc("setLayerColor", &AvatarInstance::setLayerColor);
242 av.addFunc("setLayerZ", &AvatarInstance::setLayerZ);
243 av.addFunc("setLayerSize", &AvatarInstance::setLayerSize);
244 av.addFunc("getLayerCount", &AvatarInstance::getLayerCount);
245 av.addFunc("getLayerName", &AvatarInstance::getLayerName);
246 av.addFunc("hasLayer", &AvatarInstance::hasLayer);
247 av.addFunc("getLayerRenderable", &AvatarInstance::getLayerRenderable);
248 av.addFunc("defineExpression", &AvatarInstance::defineExpression);
249 av.addFunc("removeExpression", &AvatarInstance::removeExpression);
250 av.addFunc("getExpressionCount", &AvatarInstance::getExpressionCount);
251 av.addFunc("getExpressionName", &AvatarInstance::getExpressionName);
252 av.addFunc("applyExpression", &AvatarInstance::applyExpression);
253 av.addFunc("transitionExpression", &AvatarInstance::transitionExpression);
254
255 av.addFunc("loadLive2DModel", &AvatarInstance::loadLive2DModel);
256 av.addFunc("getLive2DBackendName", &AvatarInstance::getLive2DBackendName);
257 av.addFunc("hasLive2DBackend", &AvatarInstance::hasLive2DBackend);
258
259 av.addFunc("loadVroidModel", [vm = table.getHandle()](AvatarInstance* avatar, const std::string& path) {
260 return eve::script::projectResult(vm, avatar->loadVroidModel(path));
261 });
262 av.addFunc("setHumanoidBoneRotation", [vm = table.getHandle()](AvatarInstance* avatar, const std::string& semantic,
263 float yaw, float pitch, float roll) {
264 return eve::script::projectResult(vm, avatar->setHumanoidBoneRotation(semantic, yaw, pitch, roll));
265 });
266 av.addFunc("getVroidMeshCount", &AvatarInstance::getVroidMeshCount);
267 av.addFunc("getVroidSpringCount", &AvatarInstance::getVroidSpringCount);
268 av.addFunc("getVroidVersion", &AvatarInstance::getVroidVersion);
269 av.addFunc("loadVroidModelPath", &AvatarInstance::loadVroidModelPath);
270 av.addFunc("bindVroidModelData", &AvatarInstance::bindVroidModelData);
271 av.addFunc("loadMorphNamesFromModel", &AvatarInstance::loadMorphNamesFromModel);
272 av.addFunc("setMesh", &AvatarInstance::setMesh);
273 av.addFunc("setTexture", &AvatarInstance::setTexture);
274 av.addFunc("setPosition3D", &AvatarInstance::setPosition3D);
275 av.addFunc("setRotation3D", &AvatarInstance::setRotation3D);
276 av.addFunc("setScale3D", &AvatarInstance::setScale3D);
277 av.addFunc("getRenderable3D", &AvatarInstance::getRenderable3D);
278 av.addFunc("getBoundMesh", &AvatarInstance::getBoundMesh);
279 av.addFunc("getVroidModelPath", &AvatarInstance::getVroidModelPath);
280 av.addFunc("bakeMorphs", &AvatarInstance::bakeMorphs);
281 av.addFunc("bindAnimPlayer", &AvatarInstance::bindAnimPlayer);
282 av.addFunc("bindAnimStateMachine", &AvatarInstance::bindAnimStateMachine);
283 av.addFunc("bindAnimLayerMixer", &AvatarInstance::bindAnimLayerMixer);
284 av.addFunc("setAnimConstraintStack", [](AvatarInstance* a, animation::AnimConstraintStack* stack) -> void {
285 a->setAnimConstraintStack(stack);
286 });
287 av.addFunc("getAnimConstraintStack", &AvatarInstance::getAnimConstraintStack);
288 av.addFunc("setFootIKSolver", [](AvatarInstance* a, animation::FootIKSolver* solver) -> void {
289 a->setFootIKSolver(solver);
290 });
291 av.addFunc("getFootIKSolver", &AvatarInstance::getFootIKSolver);
292 av.addFunc("setDynamicBoneSolver", [](AvatarInstance* a, animation::DynamicBoneSolver* solver) -> void {
293 a->setDynamicBoneSolver(solver);
294 });
295 av.addFunc("getDynamicBoneSolver", &AvatarInstance::getDynamicBoneSolver);
296 av.addFunc("bindAnimSkin", &AvatarInstance::bindAnimSkin);
297 av.addFunc("bindSkinnedPart",
298 [](AvatarInstance* a, int partIndex, const std::string& partName,
299 graphics::Mesh* mesh, graphics::Material* material,
300 animation::AnimSkin* skin) -> int {
301 return static_cast<int>(
302 a->bindSkinnedPart(partIndex, partName, mesh, material, skin));
303 });
304 av.addFunc("unbindSkinnedPart", [](AvatarInstance* a, int partIndex) -> int {
305 return static_cast<int>(a->unbindSkinnedPart(partIndex));
306 });
307 av.addFunc("getSkinnedPartUpdateMode", [](AvatarInstance* a, int partIndex) -> int {
308 return static_cast<int>(a->getSkinnedPartUpdateMode(partIndex));
309 });
310 av.addFunc("registerMotion", &AvatarInstance::registerMotion);
311 av.addFunc("unregisterMotion", &AvatarInstance::unregisterMotion);
312 av.addFunc("getMotionCount", &AvatarInstance::getMotionCount);
313 av.addFunc("getMotionName", &AvatarInstance::getMotionName);
314 av.addFunc("getMotionClip", &AvatarInstance::getMotionClip);
315 av.addFunc("setMotionBlendTime", &AvatarInstance::setMotionBlendTime);
316 av.addFunc("setApplyRootMotion", &AvatarInstance::setApplyRootMotion);
317 av.addFunc("getApplyRootMotion", &AvatarInstance::getApplyRootMotion);
318 av.addFunc("getRootMotionDeltaX", &AvatarInstance::getRootMotionDeltaX);
319 av.addFunc("getRootMotionDeltaZ", &AvatarInstance::getRootMotionDeltaZ);
320 av.addFunc("getAnimationEventCount", &AvatarInstance::getAnimationEventCount);
321 av.addFunc("getAnimationEventLayer", &AvatarInstance::getAnimationEventLayer);
322 av.addFunc("getAnimationEventName", &AvatarInstance::getAnimationEventName);
323 av.addFunc("getAnimationEventPayload", &AvatarInstance::getAnimationEventPayload);
324 av.addFunc("mapHumanoidBone", &AvatarInstance::mapHumanoidBone);
325 av.addFunc("autoMapHumanoidBones", &AvatarInstance::autoMapHumanoidBones);
326 av.addFunc("getHumanoidBoneName", &AvatarInstance::getHumanoidBoneName);
327 av.addFunc("mapViseme", &AvatarInstance::mapViseme);
328 av.addFunc("setViseme", &AvatarInstance::setViseme);
329 av.addFunc("setLookAtTarget", &AvatarInstance::setLookAtTarget);
330 av.addFunc("setLookAtWeight", &AvatarInstance::setLookAtWeight);
331 av.addFunc("clearLookAtTarget", &AvatarInstance::clearLookAtTarget);
332 av.addFunc("attachToBone", &AvatarInstance::attachToBone);
333 av.addFunc("detachAttachment", &AvatarInstance::detachAttachment);
334 av.addFunc("getAttachmentCount", &AvatarInstance::getAttachmentCount);
335 av.addFunc("linkSceneNode", &AvatarInstance::linkSceneNode);
336 av.addFunc("isSceneLinked", &AvatarInstance::isSceneLinked);
337 av.addFunc("bindEquipment", [](AvatarInstance* a, inventory::EquipmentSet* equipment) -> int {
338 return static_cast<int>(a->bindEquipment(equipment));
339 });
340 av.addFunc("unbindEquipment", [](AvatarInstance* a) -> int {
341 return static_cast<int>(a->unbindEquipment());
342 });
343 av.addFunc("syncEquipmentAppearance", [](AvatarInstance* a) -> int {
344 return static_cast<int>(a->syncEquipmentAppearance());
345 });
346 av.addFunc("getEquipmentVisualItem", &AvatarInstance::getEquipmentVisualItem);
347 av.addFunc("defineEquipmentLayer",
348 [](AvatarInstance* a, const std::string& name, int order,
349 const std::string& parent) -> int {
350 return static_cast<int>(a->defineEquipmentLayer(name, order, parent));
351 });
352 av.addFunc("addEquipmentLayerOcclusion",
353 [](AvatarInstance* a, const std::string& outerLayer,
354 const std::string& innerLayer) -> int {
355 return static_cast<int>(
356 a->addEquipmentLayerOcclusion(outerLayer, innerLayer));
357 });
358 av.addFunc("setEquipmentVisualLayer",
359 [](AvatarInstance* a, const std::string& itemId,
360 const std::string& equipmentSlot, const std::string& wearLayer,
361 int withinLayerOrder) -> int {
362 return static_cast<int>(a->setEquipmentVisualLayer(
363 itemId, equipmentSlot, wearLayer, withinLayerOrder));
364 });
365 av.addFunc("getEquipmentRenderStackCount", &AvatarInstance::getEquipmentRenderStackCount);
366 av.addFunc("getEquipmentRenderStackItem", &AvatarInstance::getEquipmentRenderStackItem);
367 av.addFunc("getEquipmentRenderStackLayer", &AvatarInstance::getEquipmentRenderStackLayer);
368 av.addFunc("defineEquipmentVisual2D",
369 [](AvatarInstance* a, const std::string& itemId, const std::string& equipmentSlot,
370 const std::string& layerName, ssq::Object textureObj, int zIndex) -> int {
371 graphics::Texture* texture = textureObj.isNull()
372 ? nullptr
373 : textureObj.toPtrUnsafe<graphics::Texture*>();
374 return static_cast<int>(a->defineEquipmentVisual2D(
375 itemId, equipmentSlot, layerName, texture, zIndex));
376 });
377 av.addFunc("defineEquipmentVisual3D",
378 [](AvatarInstance* a, const std::string& itemId, const std::string& equipmentSlot,
379 graphics::Renderable3D* renderable, const std::string& bone, float ox, float oy,
380 float oz) -> int {
381 return static_cast<int>(a->defineEquipmentVisual3D(
382 itemId, equipmentSlot, renderable, bone, ox, oy, oz));
383 });
384 av.addFunc("defineEquipmentSkinnedVisual3D",
385 [](AvatarInstance* a, const std::string& itemId,
386 const std::string& equipmentSlot, int partIndex,
387 const std::string& partName, graphics::Mesh* mesh,
388 graphics::Material* material, animation::AnimSkin* skin) -> int {
389 return static_cast<int>(a->defineEquipmentSkinnedVisual3D(
390 itemId, equipmentSlot, partIndex, partName, mesh, material, skin));
391 });
392 av.addFunc("bindTween", &AvatarInstance::bindTween);
393 av.addFunc("unbindTween", &AvatarInstance::unbindTween);
394 av.addFunc("getBoundTween", &AvatarInstance::getBoundTween);
395}
396
397void Avatar::expose(ssq::Class &cls) {
398 cls.addFunc("getName", &Avatar::getName);
399 cls.addFunc("newImageAvatar", &Avatar::newImageAvatar);
400 cls.addFunc("newLive2DAvatar", &Avatar::newLive2DAvatar);
401 cls.addFunc("newVroidAvatar", &Avatar::newVroidAvatar);
402 cls.addFunc("update", &Avatar::update);
403 cls.addFunc("sync", &Avatar::sync);
404 cls.addFunc("render", &Avatar::render);
405 cls.addFunc("getAvatarCount", &Avatar::getAvatarCount);
406 // Static method: wrap so SSQ gets an instance-method signature (raw static
407 // function pointers make Class::addFunc recurse until stack overflow).
408 cls.addFunc("getLive2DBackendName",
409 [](Avatar *) -> std::string { return Avatar::getLive2DBackendName(); });
410 cls.addFunc("hasLive2DBackend", [](Avatar*) -> bool { return Avatar::hasLive2DBackend(); });
411}
412
413} // namespace eve::avatar
LogicalId itemId
float yaw
Definition BushMesh.cpp:37
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
std::string name
Definition ECS.cpp:154
float maximum[3]
float minimum[3]
glm::vec3 n
Definition Grass.cpp:63
const ColourScope * parent
std::uint32_t bone
Snapshot snapshot
double defaultValue
MeleePoint3 a
Definition MeleeHit.cpp:40
std::vector< std::int32_t > order
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:27
OceanMeshSettings mesh
double dt
std::array< uint32_t, 16 > material
Texture * texture
float f
std::string path
Definition PlayHost.cpp:111
std::set< std::string > values
Object::Ptr value
uint32_t semantic
bool found
Graphics * graphics
int count
The single Squirrel projection for common Result, Status and Value.
uint32_t index
double oy
double ox
virtual std::string getName() const =0
Returns the name.
Keyframed skeletal animation clip (local TRS tracks per bone). Script type: AnimClip.
Definition AnimClip.h:145
Unified avatar instance. Kind is a string: "image" | "live2d" | "vroid". Script-facing API avoids ove...
void setScale(float sx, float sy)
Sets the scale.
void setExpression(const std::string &name)
Sets the expression.
bool bindAnimStateMachine(animation::AnimStateMachine *machine)
Bind an animation state machine that the avatar advances each update.
bool setLayerColor(const std::string &name, float r, float g, float b, float a)
Sets the layer color.
void setApplyRootMotion(bool enabled)
Apply root-bone X/Z deltas to the Avatar transform while animating.
bool setLayerOffset(const std::string &name, float ox, float oy)
Sets the layer offset.
float getParameterDefault(const std::string &name) const
Return a reflected parameter default, or zero for an unknown parameter.
Definition Avatar.cpp:47
float getScaleX() const
Returns the scale x.
std::string getAnimationEventLayer(int index) const
Source layer for an animation event ("base" for the base player).
int getMotionCount() const
Return the number of registered skeletal motions.
Definition Avatar.cpp:88
void setLayer(int layer)
Sets the layer.
std::string getHumanoidBoneName(const std::string &semantic) const
Return the mapped skeleton bone name, or an empty string.
void clearLookAtTarget()
Disable procedural head look-at.
bool isVisible() const
True when visible.
int getVroidSpringCount() const
Number of imported VRM spring chains.
void sync()
Push image / live2d layers into ECS or draw queues.
float getParameter(const std::string &name) const
Returns the parameter.
std::string getMotion() const
Returns the motion.
float getX() const
Returns the x.
bool registerMotion(const std::string &name, animation::AnimClip *clip)
Register a motion name for setMotion(); the clip is not owned.
int autoMapHumanoidBones()
Auto-map common VRM humanoid semantics from the currently bound skeleton.
bool bindAnimPlayer(animation::AnimPlayer *player)
Bind a clip player that the avatar advances and skins each update.
std::string getVroidModelPath() const
Returns the vroid model path.
std::string getExpression() const
Returns the expression.
bool mapViseme(const std::string &viseme, const std::string &morphName)
Map a VRM viseme/expression semantic to an existing mesh morph.
bool detachAttachment(const std::string &name)
Remove an attachment without destroying its Renderable3D.
std::string getAnimationEventPayload(int index) const
Animation event payload, or empty for an invalid index.
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
True when layer.
animation::DynamicBoneSolver * getDynamicBoneSolver() const
Return the Avatar-owned solver, or null. @ownership Borrowed from this Avatar. @lifetime Valid until ...
bool attachToBone(const std::string &name, const std::string &boneSemanticOrName, graphics::Renderable3D *renderable, float ox=0.f, float oy=0.f, float oz=0.f)
Attach a non-owned Renderable3D to a mapped humanoid semantic or bone name.
animation::AnimConstraintStack * getAnimConstraintStack() const
Return the Avatar-owned constraint stack, or null. @ownership Borrowed from this Avatar....
bool applyExpression(const std::string &name)
Applies expression.
std::string getParameterName(int index) const
Returns the parameter name.
float getRootMotionDeltaZ() const
Last evaluated root-motion Z delta.
graphics::Renderable2D * getLayerRenderable(const std::string &name)
Return the native Renderable2D owned by a named image layer.
std::string getEquipmentRenderStackItem(int index) const
Active item id at a render-stack index, or empty text.
std::string getKind() const
Returns the kind.
bool bindAnimLayerMixer(animation::AnimLayerMixer *mixer)
Bind an override/additive layer mixer that the avatar advances each update.
graphics::Mesh * getBoundMesh() const
Borrow the first imported mesh, or the manually bound mesh.
bool getApplyRootMotion() const
Return whether root motion is applied to the Avatar transform.
bool linkSceneNode(scene::Scene *scene, const std::string &nodeId)
Link this avatar to a node in Scene's current host.
void setVisible(bool visible)
Sets the visible.
void update(float dt)
Updates .
float getY() const
Returns the y.
int getEquipmentRenderStackCount() const
Number of active visuals in canonical back-to-front render order.
bool loadVroidModelPath(const std::string &path)
Compatibility-only bool projection of loadVroidModel; performs the real import.
int getLayerCount() const
Returns the layer count.
std::string getVroidVersion() const
Imported VRM specification version, or empty before import.
bool bindVroidModelData(model3d::ModelData *data)
Binds vroid model data.
int getExpressionCount() const
Return the number of imported and project-defined expressions.
Definition Avatar.cpp:66
void setMesh(graphics::Mesh *mesh)
Sets the mesh.
bool defineParameter(const std::string &name, float defaultValue, float minimum, float maximum)
Define reflected Avatar parameter metadata for project-built inspectors.
Definition Avatar.cpp:39
bool bindAnimSkin(animation::AnimSkin *skin)
Bind CPU skin data used to deform the avatar mesh from the active pose.
void unbindTween()
Unbinds tween.
std::string getExpressionName(int index) const
Return a stable sorted expression name, or empty text.
Definition Avatar.cpp:74
float getScaleY() const
Returns the scale y.
animation::AnimClip * getMotionClip(const std::string &name) const
Return a registered non-owned motion clip, or nullptr.
Definition Avatar.cpp:98
int loadMorphNamesFromModel(int meshIndex=0)
Register morph target names from ModelData as parameters (weights default 0).
void setParameter(const std::string &name, float value)
Sets the parameter.
float getRootMotionDeltaX() const
Last evaluated root-motion X delta.
bool transitionExpression(const std::string &name, float duration)
Blend numeric/bool expression channels over duration seconds.
std::string getAnimationEventName(int index) const
Animation event name, or empty for an invalid index.
std::string getLayerName(int index) const
Returns the layer name.
bool bakeMorphs()
Push parameter weights onto Mesh morphs and bake GPU verts when possible.
void setTexture(graphics::Texture *texture)
Sets the texture.
bool setLookAtTarget(float x, float y, float z)
Set a world-space target tracked by the mapped humanoid head bone.
bool setViseme(const std::string &viseme, float weight)
Set a mapped viseme weight and clear the previously active viseme.
std::string getEquipmentVisualItem(const std::string &equipmentSlot) const
Return the currently projected item for a slot, or empty text when none is shown.
bool hasLive2DBackend() const
True when live 2 d backend.
std::string getEquipmentRenderStackLayer(int index) const
Wear-layer name at a render-stack index, or empty text.
void setPosition(float x, float y)
Sets the position.
bool mapHumanoidBone(const std::string &semantic, const std::string &boneName)
Map a VRM humanoid semantic (for example "head") to a skeleton bone.
void setMotion(const std::string &name)
Sets the motion.
void setRotation3D(float yaw, float pitch, float roll)
Sets the rotation 3 d.
animation::Tween * getBoundTween() const
Returns the bound tween.
bool loadLive2DModel(const std::string &path)
Loads live 2 d model.
bool setLayerZ(const std::string &name, int zIndex)
Sets the layer z.
int getParameterCount() const
Returns the parameter count.
void setMotionBlendTime(float seconds)
Set the cross-fade duration used when switching registered motions.
bool isSceneLinked() const
Return whether this avatar is currently scene-driven.
bool removeExpression(const std::string &name)
Remove a project-defined expression.
Definition Avatar.cpp:62
bool unregisterMotion(const std::string &name)
Remove a registered motion without destroying its clip.
Definition Avatar.cpp:84
animation::FootIKSolver * getFootIKSolver() const
Return the Avatar-owned paired-foot IK solver, or null. @ownership Borrowed from this Avatar....
std::string getMotionName(int index) const
Return a stable sorted motion name, or empty text.
Definition Avatar.cpp:92
std::string getLive2DBackendName() const
Returns the live 2 d backend name.
bool setLayerSize(const std::string &name, float w, float h)
Sets the layer size.
int getAttachmentCount() const
Return the number of active bone attachments.
void setScale3D(float sx, float sy, float sz)
Sets the scale 3 d.
int getVroidMeshCount() const
Number of imported mesh primitives; zero before successful import.
float getParameterMinimum(const std::string &name) const
Return a reflected parameter minimum, or zero for an unknown parameter.
Definition Avatar.cpp:52
bool setLayerVisible(const std::string &name, bool visible)
Sets the layer visible.
void setLookAtWeight(float weight)
Set VRM-style head look-at influence in the range 0..1.
float getParameterMaximum(const std::string &name) const
Return a reflected parameter maximum, or one for an unknown parameter.
Definition Avatar.cpp:57
bool hasParameter(const std::string &name) const
True when parameter.
int getLayer() const
Returns the layer.
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
Borrow the first imported render projection, or the manual projection.
void setPosition3D(float x, float y, float z)
Sets the position 3 d.
int getAnimationEventCount() const
Number of animation events emitted by the latest update.
Avatar module — layered character rendering for VN / portrait use. Script: avatar <- eve....
Definition Avatar.h:25
static void registerLive2DBackend(Live2DBackendFactory factory)
C++ / plugin: replace Live2D backend factory. Pass nullptr to restore the built-in NullLive2DBackend ...
Definition Avatar.cpp:160
static Live2DBackendFactory live2DBackendFactory()
Live 2 d backend factory.
Definition Avatar.cpp:164
Avatar()=default
Avatar.
void render(graphics::Graphics *gfx)
Sync then draw Image/Live2D avatars via the shared 2D sprite queue (does not present)....
Definition Avatar.cpp:147
void update(float dt)
Updates .
Definition Avatar.cpp:133
AvatarInstance * newLive2DAvatar()
Creates a live 2 d avatar. @ownership Caller deletes unless documented otherwise.
Definition Avatar.cpp:129
~Avatar() override
Avatar.
Definition Avatar.cpp:107
static bool hasLive2DBackend()
True when the active backend is a real rendering runtime, not the null stub.
Definition Avatar.cpp:179
AvatarInstance * newImageAvatar()
Creates a image avatar. @ownership Caller deletes unless documented otherwise.
Definition Avatar.cpp:127
int getAvatarCount() const
Returns the avatar count.
Definition Avatar.cpp:158
static std::string getLive2DBackendName()
Backend name currently in effect ("null" when using the built-in stub).
Definition Avatar.cpp:171
friend class AvatarInstance
Definition Avatar.h:67
AvatarInstance * newVroidAvatar()
Creates a vroid avatar. @ownership Caller deletes unless documented otherwise.
Definition Avatar.cpp:131
static ILive2DBackend * createLive2DBackend()
Always returns a backend: custom factory, else NullLive2DBackend.
Definition Avatar.cpp:166
void sync()
Sync all live avatars into renderables.
Definition Avatar.cpp:140
Optional Live2D runtime backend (Cubism etc.). Registered from C++ / plugins.
virtual std::string getName() const =0
Returns the name.
virtual bool isRuntimeAvailable() const
True only for a backend that can render a real Live2D model.
static void collectSprites(std::vector< DrawItem2D > &out)
Append visible Renderable2D sprites into a shared queue.
static void drawItems(Graphics &gfx, std::vector< DrawItem2D > &items, bool present)
Sort and draw items. If present=true, calls gfx.present() at the end. Map::render uses present=false ...
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
ILive2DBackend *(*)() Live2DBackendFactory
ILive2DBackend * createNullLive2DBackend()
Creates null live 2 d backend.
void exposeAppearance(ssq::Table &table)
Register VM-owned Appearance objects. Table is borrowed only during registration. @thread VM owner th...
std::unordered_map< std::string, SkillDefinition > & table()
Definition Skill.cpp:73
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.