载入中...
搜索中...
未找到
AppearanceBindings.cpp
浏览该文件的文档.
1#include "avatar/Appearance.h"
3#include "graphics/Mesh.h"
4
5#include <simplesquirrel/simplesquirrel.hpp>
6
7namespace eve::avatar {
8void exposeAppearance(ssq::Table& table) {
9 const auto vm = table.getHandle();
10 auto cls = table.addClass<Appearance>("AvatarAppearance",
11 std::function<Appearance*()>([] { return new Appearance(); }), true);
12 cls.addFunc("configure", [vm](Appearance* self, ssq::Object object) {
13 auto value = script::valueFromSquirrel(object);
14 if (!value.ok()) return script::projectStatusResult(vm, value.status());
15 return script::projectResult(vm, self->configure(value.value()));
16 });
17 cls.addFunc("apply", [vm](Appearance* self, ssq::Object object) {
18 auto value = script::valueFromSquirrel(object);
19 if (!value.ok()) return script::projectStatusResult(vm, value.status());
20 return script::projectResult(vm, self->apply(value.value()));
21 });
22 cls.addFunc("restore", [vm](Appearance* self, ssq::Object object) {
23 auto value = script::valueFromSquirrel(object);
24 if (!value.ok()) return script::projectStatusResult(vm, value.status());
25 return script::projectResult(vm, self->restore(value.value()));
26 });
27 cls.addFunc("snapshot", [vm](Appearance* self) {
29 });
30 cls.addFunc("evaluate", [vm](Appearance* self) {
32 });
33 cls.addFunc("undo", [vm](Appearance* self) { return script::projectResult(vm, self->undo()); });
34 cls.addFunc("redo", [vm](Appearance* self) { return script::projectResult(vm, self->redo()); });
35 cls.addFunc("canUndo", &Appearance::canUndo);
36 cls.addFunc("canRedo", &Appearance::canRedo);
37 cls.addFunc("applyMorphWeights", [vm](Appearance* self, graphics::Mesh* mesh, const std::string& prefix) {
38 if (!mesh)
41 return script::projectResult(vm, self->applyMorphWeights(*mesh, prefix));
42 });
43 cls.addFunc("snapshotJson", [vm](Appearance* self) {
44 return script::projectResult(vm, self->snapshot().toJson(),
45 [](std::string value) { return Value(std::move(value)); });
46 });
47 cls.addFunc("restoreJson", [vm](Appearance* self, const std::string& json) {
48 auto value = Value::fromJson(json);
49 if (!value.ok()) return script::projectStatusResult(vm, value.status());
50 return script::projectResult(vm, self->restore(value.value()));
51 });
52}
53} // namespace eve::avatar
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
OceanMeshSettings mesh
Object::Ptr value
The single Squirrel projection for common Result, Status and Value.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
Definition Status.cpp:28
Result< std::string > toJson() const
Serialize this value as deterministic compact JSON.
Definition Value.cpp:187
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
Renderer-independent character appearance authoring and runtime state. Owns its validated definition,...
Definition Appearance.h:27
Result< void > configure(const Value &definition)
Validate and replace a complete eve.appearance.definition v1 document. @cost Linear in document size ...
Result< void > applyMorphWeights(graphics::Mesh &mesh, std::string_view prefix) const
Validate all driven morph names before writing weights to a borrowed mesh. Only outputs beginning wit...
bool canRedo() const
Query whether a redo state exists, without evaluating anything.
Definition Appearance.h:51
bool canUndo() const
Query whether an undo state exists, without evaluating anything.
Definition Appearance.h:49
Value evaluate() const
Evaluate additive channels and multi-input corrective drivers, and derive wardrobe visibility....
Result< void > redo()
Redo the last undone edit; NotFound when history is empty.
Result< void > undo()
Undo the last applied edit; NotFound when history is empty.
Result< void > apply(const Value &patch)
Atomically patch parameters and selections; reject unknown ids, conflicts and out-of-range values....
Value snapshot() const
Return an owning versioned snapshot of authoritative parameter and selection state....
Result< void > restore(const Value &snapshot)
Restore an exact eve.appearance.state v1 snapshot for the currently loaded profile....
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:26
void exposeAppearance(ssq::Table &table)
Register VM-owned Appearance objects. Table is borrowed only during registration. @thread VM owner th...
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
Result< Value > valueFromSquirrel(HSQUIRRELVM vm, SQInteger index, const SquirrelValueOptions &options)
Convert one Squirrel value into the canonical owning Value tree.