载入中...
搜索中...
未找到
AvatarDocumentEditor.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4#include <cstdint>
5#include <simplesquirrel/simplesquirrel.hpp>
6#include <string>
7#include <utility>
13
14// AvatarDocumentEditor.cpp
15namespace eve::avatar_editor {
16namespace {
17
18template <class T = void>
19avatar_editing::Result<T> editorError(avatar_editing::EditorStatus status, std::string rule, std::string message) {
20 return eve::editing::failed<T>(status, avatar_editing::RuleId(std::move(rule)), std::move(message));
21}
22
24avatar_editing::EditorValue color(float r, float g, float b, float a) {
26}
27
28avatar_editing::EditorValue layerValue(const char* id, const char* name, const char* texture, int z, bool visible,
29 float ox, float oy, float w, float h, float r, float g, float bl, float a) {
31 {"id", std::string(id)}, {"name", std::string(name)}, {"texture", std::string(texture)},
32 {"z", std::int64_t{z}}, {"visible", visible}, {"offset", floats(ox, oy)},
33 {"size", floats(w, h)}, {"color", color(r, g, bl, a)}};
34}
35
36} // namespace
37
39 : target_(std::move(targetId)), authority_(&target_), transactions_(&authority_) {
40 seedPreviewDocument();
41 auto previewed = refreshPreview();
42 if (!previewed.ok()) previewed.ignore("avatar editor keeps an empty composite when the seeded preview is rejected");
43}
44
45void AvatarDocumentEditor::seedPreviewDocument() {
47 layers.push_back(layerValue("body", "body", "asset://preview/body.png", 0, true, 40.0f, 20.0f, 96.0f, 128.0f, 0.35f,
48 0.55f, 0.72f, 1.0f));
49 layers.push_back(layerValue("eyes", "eyes", "asset://preview/eyes.png", 1, true, 62.0f, 78.0f, 52.0f, 22.0f, 0.95f,
50 0.92f, 0.88f, 1.0f));
52 parameters.emplace_back(avatar_editing::EditorValue::Object{{"id", std::string("smile")},
53 {"name", std::string("smile")},
54 {"default", 0.35},
55 {"minimum", 0.0},
56 {"maximum", 1.0},
57 {"value", 0.35}});
59 channels["smile"] = 1.0;
61 expressions.emplace_back(avatar_editing::EditorValue::Object{
62 {"id", std::string("happy")}, {"name", std::string("happy")}, {"channels", std::move(channels)}});
64 content["kind"] = std::string("image");
65 content["source"] = std::string{};
66 content["layers"] = std::move(layers);
67 content["parameters"] = std::move(parameters);
68 content["expressions"] = std::move(expressions);
70 root["schemaVersion"] = std::int64_t{1};
71 root["content"] = avatar_editing::EditorValue(std::move(content));
72 auto loaded = target_.loadSnapshot(avatar_editing::EditorValue(std::move(root)));
73 if (!loaded.ok()) loaded.ignore("avatar editor keeps defaults when the preview snapshot is rejected");
74}
75
77 editor::EditorWorkspace candidate = workspace;
78 struct Panel {
79 const char* id;
80 const char* title;
81 const char* region;
82 const char* context;
83 int order;
84 };
85 constexpr Panel panels[] = {
86 {"avatar.layers", "Layers", "left", "list", 100},
87 {"avatar.preview", "Avatar Preview", "center", "preview", 100},
88 {"avatar.inspector", "Avatar Inspector", "right", "inspector", 100},
89 {"avatar.parameters", "Parameters", "bottom", "parameters", 100},
90 {"avatar.expressions", "Expressions", "right", "expressions", 200},
91 };
92 for (const auto& panel : panels) {
93 if (!candidate.registerPanel(panel.id, panel.title, panel.region, panel.order) ||
94 !candidate.setPanelCapability(panel.id, "avatar.document") ||
95 !candidate.setPanelContext(panel.id, panel.context))
96 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.workspace-conflict",
97 "Could not install the avatar workspace composition");
98 }
99 if (!candidate.activatePanel("avatar.preview"))
100 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.workspace-activate",
101 "Could not activate the avatar preview panel");
102 workspace = std::move(candidate);
103 return eve::editing::applied<void>();
104}
105
106editor::SelectionSnapshot AvatarDocumentEditor::selection() const {
108 snapshot.channel = "avatar";
110 item.domain = editor::SelectionDomain::Asset;
111 item.target = editor::TargetId(target_.targetId());
112 item.item = editor::StableId(selectedId_);
113 item.type = selectedType_;
114 snapshot.items.push_back(item);
115 snapshot.primary = item;
116 return snapshot;
117}
118
119avatar_editing::Result<void> AvatarDocumentEditor::commit(
123 spec.id = editor::TransactionId("avatar.document.tx." + std::to_string(++txSequence_));
124 spec.label = std::move(label);
125 spec.target = editor::TargetId(target_.targetId());
126 spec.baseRevision = target_.revision();
127 auto begun = transactions_.begin(std::move(spec));
128 if (!begun.ok()) return editorError(begun.code(), "editor.avatar.begin", "Could not begin the avatar transaction");
129 auto appended = transactions_.append(std::move(operation).takeValue());
130 if (!appended.ok()) {
131 auto discarded = transactions_.discard();
132 if (!discarded.ok()) discarded.ignore("pending avatar transaction already inactive");
133 return avatar_editing::Result<void>::failure(appended.status());
134 }
135 auto committed = transactions_.commit();
137 return refreshPreview();
138}
139
140avatar_editing::Result<void> AvatarDocumentEditor::refreshPreview() {
141 std::vector<PreviewRect> next;
142 auto layers = target_.layers();
143 std::sort(layers.begin(), layers.end(), [](const auto& a, const auto& b) {
144 return a.zIndex == b.zIndex ? a.id.value() < b.id.value() : a.zIndex < b.zIndex;
145 });
146 const float smile = smileAmount();
147 for (const auto& layer : layers) {
148 if (!layer.visible) continue;
149 PreviewRect rect;
150 rect.id = layer.id.value();
151 rect.name = layer.name;
152 rect.x = layer.offset[0];
153 rect.y = layer.offset[1] + (layer.name == "eyes" ? smile * 10.0f : 0.0f);
154 rect.w = layer.size[0];
155 rect.h = layer.size[1];
156 rect.r = layer.color[0];
157 rect.g = layer.color[1];
158 rect.b = layer.color[2];
159 rect.a = layer.color[3];
160 rect.selected = layer.id.value() == selectedId_;
161 next.push_back(std::move(rect));
162 }
163 preview_ = std::move(next);
164 previewRevision_ = target_.revision();
165 return eve::editing::applied<void>();
166}
167
168float AvatarDocumentEditor::smileAmount() const {
169 for (const auto& parameter : target_.parameters())
170 if (parameter.name == "smile") return parameter.value;
171 return 0.0f;
172}
173
175 if (id.empty())
176 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.select-layer",
177 "Layer id must not be empty");
178 bool found = false;
179 for (const auto& layer : target_.layers())
180 if (layer.id.value() == id) found = true;
181 if (!found)
182 return editorError(avatar_editing::EditorStatus::NotFound, "editor.avatar.layer", "Avatar layer was not found");
183 selectedId_ = std::move(id);
184 selectedType_ = "avatar.layer";
185 return refreshPreview();
186}
187
189 if (id.empty())
190 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.select-parameter",
191 "Parameter id must not be empty");
192 bool found = false;
193 for (const auto& parameter : target_.parameters())
194 if (parameter.id.value() == id) found = true;
195 if (!found)
196 return editorError(avatar_editing::EditorStatus::NotFound, "editor.avatar.parameter",
197 "Avatar parameter was not found");
198 selectedId_ = std::move(id);
199 selectedType_ = "avatar.parameter";
200 return refreshPreview();
201}
202
204 if (id.empty())
205 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.select-expression",
206 "Expression id must not be empty");
207 bool found = false;
208 for (const auto& expression : target_.expressions())
209 if (expression.id.value() == id) found = true;
210 if (!found)
211 return editorError(avatar_editing::EditorStatus::NotFound, "editor.avatar.expression",
212 "Avatar expression was not found");
213 selectedId_ = std::move(id);
214 selectedType_ = "avatar.expression";
215 return refreshPreview();
216}
217
219 if (!std::isfinite(x) || !std::isfinite(y))
220 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.pointer",
221 "Pointer coordinates must be finite");
222 for (int i = static_cast<int>(preview_.size()) - 1; i >= 0; --i) {
223 const auto& rect = preview_[static_cast<std::size_t>(i)];
224 if (x >= rect.x && y >= rect.y && x <= rect.x + rect.w && y <= rect.y + rect.h) return selectLayer(rect.id);
225 }
226 return eve::editing::applied<void>();
227}
228
230 if (selectedType_ != "avatar.layer")
231 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.selection",
232 "A layer must be selected to change visibility");
233 return commit(target_.makeSet(selection(), avatar_editing::PropertyPath("layer.visible"),
234 avatar_editing::EditorValue(visible), avatar_editing::PropertySetMode::Absolute),
235 "Set layer visibility");
236}
237
239 if (selectedType_ != "avatar.layer")
240 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.selection",
241 "A layer must be selected to change z-order");
242 return commit(
243 target_.makeSet(selection(), avatar_editing::PropertyPath("layer.z"),
244 avatar_editing::EditorValue(std::int64_t{zIndex}), avatar_editing::PropertySetMode::Absolute),
245 "Set layer z");
246}
247
249 if (selectedType_ != "avatar.parameter")
250 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.selection",
251 "A parameter must be selected to change its value");
252 return commit(target_.makeSet(selection(), avatar_editing::PropertyPath("parameter.value"),
253 avatar_editing::EditorValue(value), avatar_editing::PropertySetMode::Absolute),
254 "Set parameter value");
255}
256
259 layer.id = avatar_editing::ObjectId(std::move(id));
260 layer.name = std::move(name);
261 layer.textureAsset = "asset://preview/" + layer.name + ".png";
262 layer.zIndex = static_cast<int>(target_.layers().size());
263 layer.offset = {16.0f, 16.0f};
264 layer.size = {48.0f, 48.0f};
265 auto created = commit(target_.makeCreateLayer(layer), "Create layer");
266 if (!created.ok()) return created;
267 return selectLayer(layer.id.value());
268}
269
271 if (selectedType_ != "avatar.layer")
272 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.selection",
273 "A layer must be selected to delete it");
274 const auto previous = preview_;
275 const auto revision = previewRevision_;
276 auto deleted = commit(target_.makeDeleteLayer(avatar_editing::ObjectId(selectedId_)), "Delete layer");
277 if (!deleted.ok()) {
278 preview_ = previous;
279 previewRevision_ = revision;
280 return deleted;
281 }
282 if (!target_.layers().empty()) return selectLayer(target_.layers().front().id.value());
283 selectedId_.clear();
284 return eve::editing::applied<void>();
285}
286
289 parameter.id = avatar_editing::ObjectId(std::move(id));
290 parameter.name = std::move(name);
291 auto created = commit(target_.makeCreateParameter(parameter), "Create parameter");
292 if (!created.ok()) return created;
293 return selectParameter(parameter.id.value());
294}
295
297 if (selectedType_ != "avatar.parameter")
298 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.selection",
299 "A parameter must be selected to delete it");
300 const auto previous = preview_;
301 const auto revision = previewRevision_;
302 auto deleted = commit(target_.makeDeleteParameter(avatar_editing::ObjectId(selectedId_)), "Delete parameter");
303 if (!deleted.ok()) {
304 preview_ = previous;
305 previewRevision_ = revision;
306 return deleted;
307 }
308 if (!target_.parameters().empty()) return selectParameter(target_.parameters().front().id.value());
309 selectedId_.clear();
310 return eve::editing::applied<void>();
311}
312
315 expression.id = avatar_editing::ObjectId(std::move(id));
316 expression.name = std::move(name);
317 auto created = commit(target_.makeCreateExpression(expression), "Create expression");
318 if (!created.ok()) return created;
319 return selectExpression(expression.id.value());
320}
321
323 if (selectedType_ != "avatar.expression")
324 return editorError(avatar_editing::EditorStatus::Rejected, "editor.avatar.selection",
325 "An expression must be selected to delete it");
326 auto deleted = commit(target_.makeDeleteExpression(avatar_editing::ObjectId(selectedId_)), "Delete expression");
327 if (!deleted.ok()) return deleted;
328 if (!target_.expressions().empty()) return selectExpression(target_.expressions().front().id.value());
329 selectedId_.clear();
330 return eve::editing::applied<void>();
331}
332
334 auto result = transactions_.undo();
335 if (!result.ok()) return result;
336 auto previewed = refreshPreview();
337 if (!previewed.ok()) return avatar_editing::Result<editor::TransactionReceipt>::failure(previewed.status());
338 return result;
339}
340
342 auto result = transactions_.redo();
343 if (!result.ok()) return result;
344 auto previewed = refreshPreview();
345 if (!previewed.ok()) return avatar_editing::Result<editor::TransactionReceipt>::failure(previewed.status());
346 return result;
347}
348
349std::string AvatarDocumentEditor::layerId(int index) const {
350 const auto* layer = layerAt(index);
351 return layer ? layer->id.value() : std::string{};
352}
354 const auto* layer = layerAt(index);
355 return layer ? layer->name : std::string{};
356}
358 const auto* layer = layerAt(index);
359 return layer && layer->visible;
360}
362 const auto* layer = layerAt(index);
363 return layer ? layer->zIndex : 0;
364}
366 const auto* layer = layerAt(index);
367 return layer && selectedType_ == "avatar.layer" && layer->id.value() == selectedId_;
368}
369
371 const auto* rect = previewAt(index);
372 return rect ? rect->x : 0.0f;
373}
375 const auto* rect = previewAt(index);
376 return rect ? rect->y : 0.0f;
377}
379 const auto* rect = previewAt(index);
380 return rect ? rect->w : 0.0f;
381}
383 const auto* rect = previewAt(index);
384 return rect ? rect->h : 0.0f;
385}
387 const auto* rect = previewAt(index);
388 return rect ? rect->r : 0.0f;
389}
391 const auto* rect = previewAt(index);
392 return rect ? rect->g : 0.0f;
393}
395 const auto* rect = previewAt(index);
396 return rect ? rect->b : 0.0f;
397}
399 const auto* rect = previewAt(index);
400 return rect ? rect->a : 0.0f;
401}
403 const auto* rect = previewAt(index);
404 return rect && rect->selected;
405}
407 const auto* rect = previewAt(index);
408 return rect ? rect->name : std::string{};
409}
410
412 const auto* parameter = parameterAt(index);
413 return parameter ? parameter->id.value() : std::string{};
414}
416 const auto* parameter = parameterAt(index);
417 return parameter ? parameter->name : std::string{};
418}
420 const auto* parameter = parameterAt(index);
421 return parameter ? parameter->value : 0.0f;
422}
424 const auto* parameter = parameterAt(index);
425 return parameter ? parameter->minimum : 0.0f;
426}
428 const auto* parameter = parameterAt(index);
429 return parameter ? parameter->maximum : 1.0f;
430}
432 const auto* parameter = parameterAt(index);
433 return parameter && selectedType_ == "avatar.parameter" && parameter->id.value() == selectedId_;
434}
435
437 const auto* expression = expressionAt(index);
438 return expression ? expression->id.value() : std::string{};
439}
441 const auto* expression = expressionAt(index);
442 return expression ? expression->name : std::string{};
443}
445 const auto* expression = expressionAt(index);
446 return expression && selectedType_ == "avatar.expression" && expression->id.value() == selectedId_;
447}
449 const auto* expression = expressionAt(index);
450 return expression ? static_cast<int>(expression->channels.size()) : 0;
451}
452std::string AvatarDocumentEditor::expressionChannelName(int expression, int channel) const {
453 const auto* value = expressionAt(expression);
454 if (!value || channel < 0 || static_cast<std::size_t>(channel) >= value->channels.size()) return {};
455 auto it = value->channels.begin();
456 for (int i = 0; i < channel; ++i) ++it;
457 return it->first;
458}
459
460const AvatarDocumentEditor::PreviewRect* AvatarDocumentEditor::previewAt(int index) const {
461 if (index < 0 || static_cast<std::size_t>(index) >= preview_.size()) return nullptr;
462 return &preview_[static_cast<std::size_t>(index)];
463}
464const avatar_editing::AvatarLayerValue* AvatarDocumentEditor::layerAt(int index) const {
465 if (index < 0 || static_cast<std::size_t>(index) >= target_.layers().size()) return nullptr;
466 return &target_.layers()[static_cast<std::size_t>(index)];
467}
468const avatar_editing::AvatarParameterValue* AvatarDocumentEditor::parameterAt(int index) const {
469 if (index < 0 || static_cast<std::size_t>(index) >= target_.parameters().size()) return nullptr;
470 return &target_.parameters()[static_cast<std::size_t>(index)];
471}
472const avatar_editing::AvatarExpressionValue* AvatarDocumentEditor::expressionAt(int index) const {
473 if (index < 0 || static_cast<std::size_t>(index) >= target_.expressions().size()) return nullptr;
474 return &target_.expressions()[static_cast<std::size_t>(index)];
475}
476
477} // namespace eve::avatar_editor
478
479// AvatarDocumentEditorScriptBindings.cpp
480namespace eve::avatar_editor {
481namespace {
482
483constexpr const char* kBindingSource = "editor.avatar.document.squirrel";
484
485class ScriptAvatarDocumentEditor {
486public:
487 explicit ScriptAvatarDocumentEditor(std::string targetId) : editor_(std::move(targetId)) {}
488
489 AvatarDocumentEditor& editor() noexcept { return editor_; }
490 const AvatarDocumentEditor& editor() const noexcept { return editor_; }
491
492private:
493 AvatarDocumentEditor editor_;
494};
495
496} // namespace
497
498void exposeAvatarDocumentEditorScriptBindings(ssq::Table& table, ssq::Class& moduleClass) {
499 const editor::ScriptBind bind{table.getHandle(), kBindingSource};
500 auto avatarEditor = editor::addScriptClass<ScriptAvatarDocumentEditor>(table, "AvatarDocumentEditor");
501 editor::registerEditorWorkspace<ScriptAvatarDocumentEditor>(avatarEditor, bind,
502 "avatar editor and workspace must not be null");
503 avatarEditor.addFunc("selectLayer", [bind](ScriptAvatarDocumentEditor* self, const std::string& id) {
504 return bind.checked(self, "avatar editor must not be null", [&] { return self->editor().selectLayer(id); });
505 });
506 avatarEditor.addFunc("selectParameter", [bind](ScriptAvatarDocumentEditor* self, const std::string& id) {
507 return bind.checked(self, "avatar editor must not be null", [&] { return self->editor().selectParameter(id); });
508 });
509 avatarEditor.addFunc("selectExpression", [bind](ScriptAvatarDocumentEditor* self, const std::string& id) {
510 return bind.checked(self, "avatar editor must not be null",
511 [&] { return self->editor().selectExpression(id); });
512 });
513 avatarEditor.addFunc("pointerDown", [bind](ScriptAvatarDocumentEditor* self, float x, float y) {
514 return bind.checked(self, "avatar editor must not be null", [&] { return self->editor().pointerDown(x, y); });
515 });
516 avatarEditor.addFunc("setLayerVisible", [bind](ScriptAvatarDocumentEditor* self, bool visible) {
517 return bind.checked(self, "avatar editor must not be null",
518 [&] { return self->editor().setLayerVisible(visible); });
519 });
520 avatarEditor.addFunc("setLayerZ", [bind](ScriptAvatarDocumentEditor* self, int zIndex) {
521 return bind.checked(self, "avatar editor must not be null", [&] { return self->editor().setLayerZ(zIndex); });
522 });
523 avatarEditor.addFunc("setParameterValue", [bind](ScriptAvatarDocumentEditor* self, float value) {
524 return bind.checked(self, "avatar editor must not be null",
525 [&] { return self->editor().setParameterValue(static_cast<double>(value)); });
526 });
527 avatarEditor.addFunc("createLayer",
528 [bind](ScriptAvatarDocumentEditor* self, const std::string& id, const std::string& name) {
529 return bind.checked(self, "avatar editor must not be null",
530 [&] { return self->editor().createLayer(id, name); });
531 });
532 avatarEditor.addFunc("deleteSelectedLayer", [bind](ScriptAvatarDocumentEditor* self) {
533 return bind.checked(self, "avatar editor must not be null",
534 [&] { return self->editor().deleteSelectedLayer(); });
535 });
536 avatarEditor.addFunc("createParameter",
537 [bind](ScriptAvatarDocumentEditor* self, const std::string& id, const std::string& name) {
538 return bind.checked(self, "avatar editor must not be null",
539 [&] { return self->editor().createParameter(id, name); });
540 });
541 avatarEditor.addFunc("deleteSelectedParameter", [bind](ScriptAvatarDocumentEditor* self) {
542 return bind.checked(self, "avatar editor must not be null",
543 [&] { return self->editor().deleteSelectedParameter(); });
544 });
545 avatarEditor.addFunc("createExpression",
546 [bind](ScriptAvatarDocumentEditor* self, const std::string& id, const std::string& name) {
547 return bind.checked(self, "avatar editor must not be null",
548 [&] { return self->editor().createExpression(id, name); });
549 });
550 avatarEditor.addFunc("deleteSelectedExpression", [bind](ScriptAvatarDocumentEditor* self) {
551 return bind.checked(self, "avatar editor must not be null",
552 [&] { return self->editor().deleteSelectedExpression(); });
553 });
554 editor::registerEditorHistory<ScriptAvatarDocumentEditor>(avatarEditor, bind, "avatar editor must not be null");
555 avatarEditor.addFunc("getPreviewRevision", [](ScriptAvatarDocumentEditor* self) {
556 return self ? static_cast<int>(self->editor().previewRevision()) : 0;
557 });
558 avatarEditor.addFunc("getKind",
559 [](ScriptAvatarDocumentEditor* self) { return self ? self->editor().kind() : std::string{}; });
560 avatarEditor.addFunc("getSelectedId", [](ScriptAvatarDocumentEditor* self) {
561 return self ? self->editor().selectedId() : std::string{};
562 });
563 avatarEditor.addFunc("getSelectedType", [](ScriptAvatarDocumentEditor* self) {
564 return self ? self->editor().selectedType() : std::string{};
565 });
566 avatarEditor.addFunc("getLayerCount",
567 [](ScriptAvatarDocumentEditor* self) { return self ? self->editor().layerCount() : 0; });
568 avatarEditor.addFunc("getLayerId", [](ScriptAvatarDocumentEditor* self, int index) {
569 return self ? self->editor().layerId(index) : std::string{};
570 });
571 avatarEditor.addFunc("getLayerName", [](ScriptAvatarDocumentEditor* self, int index) {
572 return self ? self->editor().layerName(index) : std::string{};
573 });
574 avatarEditor.addFunc("getLayerVisible", [](ScriptAvatarDocumentEditor* self, int index) {
575 return self && self->editor().layerVisible(index);
576 });
577 avatarEditor.addFunc("getLayerZ", [](ScriptAvatarDocumentEditor* self, int index) {
578 return self ? self->editor().layerZ(index) : 0;
579 });
580 avatarEditor.addFunc("getLayerSelected", [](ScriptAvatarDocumentEditor* self, int index) {
581 return self && self->editor().isLayerSelected(index);
582 });
583 avatarEditor.addFunc("getPreviewLayerCount", [](ScriptAvatarDocumentEditor* self) {
584 return self ? self->editor().previewLayerCount() : 0;
585 });
586 avatarEditor.addFunc("getPreviewX", [](ScriptAvatarDocumentEditor* self, int index) {
587 return self ? self->editor().previewX(index) : 0.0f;
588 });
589 avatarEditor.addFunc("getPreviewY", [](ScriptAvatarDocumentEditor* self, int index) {
590 return self ? self->editor().previewY(index) : 0.0f;
591 });
592 avatarEditor.addFunc("getPreviewW", [](ScriptAvatarDocumentEditor* self, int index) {
593 return self ? self->editor().previewW(index) : 0.0f;
594 });
595 avatarEditor.addFunc("getPreviewH", [](ScriptAvatarDocumentEditor* self, int index) {
596 return self ? self->editor().previewH(index) : 0.0f;
597 });
598 avatarEditor.addFunc("getPreviewR", [](ScriptAvatarDocumentEditor* self, int index) {
599 return self ? self->editor().previewR(index) : 0.0f;
600 });
601 avatarEditor.addFunc("getPreviewG", [](ScriptAvatarDocumentEditor* self, int index) {
602 return self ? self->editor().previewG(index) : 0.0f;
603 });
604 avatarEditor.addFunc("getPreviewB", [](ScriptAvatarDocumentEditor* self, int index) {
605 return self ? self->editor().previewB(index) : 0.0f;
606 });
607 avatarEditor.addFunc("getPreviewA", [](ScriptAvatarDocumentEditor* self, int index) {
608 return self ? self->editor().previewA(index) : 0.0f;
609 });
610 avatarEditor.addFunc("getPreviewSelected", [](ScriptAvatarDocumentEditor* self, int index) {
611 return self && self->editor().isPreviewSelected(index);
612 });
613 avatarEditor.addFunc("getPreviewName", [](ScriptAvatarDocumentEditor* self, int index) {
614 return self ? self->editor().previewName(index) : std::string{};
615 });
616 avatarEditor.addFunc("getParameterCount",
617 [](ScriptAvatarDocumentEditor* self) { return self ? self->editor().parameterCount() : 0; });
618 avatarEditor.addFunc("getParameterId", [](ScriptAvatarDocumentEditor* self, int index) {
619 return self ? self->editor().parameterId(index) : std::string{};
620 });
621 avatarEditor.addFunc("getParameterName", [](ScriptAvatarDocumentEditor* self, int index) {
622 return self ? self->editor().parameterName(index) : std::string{};
623 });
624 avatarEditor.addFunc("getParameterValue", [](ScriptAvatarDocumentEditor* self, int index) {
625 return self ? self->editor().parameterValue(index) : 0.0f;
626 });
627 avatarEditor.addFunc("getParameterMinimum", [](ScriptAvatarDocumentEditor* self, int index) {
628 return self ? self->editor().parameterMinimum(index) : 0.0f;
629 });
630 avatarEditor.addFunc("getParameterMaximum", [](ScriptAvatarDocumentEditor* self, int index) {
631 return self ? self->editor().parameterMaximum(index) : 1.0f;
632 });
633 avatarEditor.addFunc("getParameterSelected", [](ScriptAvatarDocumentEditor* self, int index) {
634 return self && self->editor().isParameterSelected(index);
635 });
636 avatarEditor.addFunc("getExpressionCount",
637 [](ScriptAvatarDocumentEditor* self) { return self ? self->editor().expressionCount() : 0; });
638 avatarEditor.addFunc("getExpressionId", [](ScriptAvatarDocumentEditor* self, int index) {
639 return self ? self->editor().expressionId(index) : std::string{};
640 });
641 avatarEditor.addFunc("getExpressionName", [](ScriptAvatarDocumentEditor* self, int index) {
642 return self ? self->editor().expressionName(index) : std::string{};
643 });
644 avatarEditor.addFunc("getExpressionSelected", [](ScriptAvatarDocumentEditor* self, int index) {
645 return self && self->editor().isExpressionSelected(index);
646 });
647 avatarEditor.addFunc("getExpressionChannelCount", [](ScriptAvatarDocumentEditor* self, int index) {
648 return self ? self->editor().expressionChannelCount(index) : 0;
649 });
650 avatarEditor.addFunc("getExpressionChannelName", [](ScriptAvatarDocumentEditor* self, int expression, int channel) {
651 return self ? self->editor().expressionChannelName(expression, channel) : std::string{};
652 });
653
654 editor::registerEditorOwnedCreate<ScriptAvatarDocumentEditor, AvatarEditorModule>(
655 moduleClass, bind, "avatar target id must not be empty");
656}
657
658} // namespace eve::avatar_editor
double z
double y
double x
ActionParameterOperation operation
float w
Definition AnimClip.cpp:738
std::map< std::string, std::vector< Key >, std::less<> > channels
int root
Definition AnimSmr.cpp:119
Squirrel adapter for the avatar document editor.
UI-neutral avatar editor: workspace, layer composite preview, undo.
std::string title
bool committed
std::string name
Definition ECS.cpp:154
ScriptFieldRegion region
std::string message
tensor::Graph g
Definition GpuGraph.cpp:7
wgpu::PopErrorScopeStatus status
double r
int h
std::string label
std::string id
Poco::JSON::Object::Ptr result
Snapshot snapshot
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::vector< std::int32_t > order
ScriptMotionSinkStore< ScriptMotionFloatSink > floats
std::shared_ptr< const OceanSprayFrame > previous
std::array< uint32_t, 9 > parameters
Texture * texture
TileLayer * layer
std::unordered_set< std::string > loaded
Definition Plugins.cpp:24
std::uint32_t targetId
Object::Ptr value
std::string parameter
bool found
int created
bool visible
uint32_t index
double oy
double ox
const VegetationPresetContext & context
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:313
const std::string & value() const noexcept
Returns the exact legacy or canonical compatibility spelling.
Definition Identity.h:365
Result< DomainOperation > makeSet(const SelectionSnapshot &, const PropertyPath &, const EditorValue &, PropertySetMode) const override
Make set.
const std::vector< AvatarExpressionValue > & expressions() const
Expressions.
Result< void > loadSnapshot(const EditorValue &)
Loads snapshot.
Result< DomainOperation > makeDeleteParameter(const ObjectId &) const
Make delete parameter.
Result< DomainOperation > makeCreateExpression(const AvatarExpressionValue &) const
Make create expression.
Result< DomainOperation > makeCreateLayer(const AvatarLayerValue &) const
Make create layer.
Result< DomainOperation > makeCreateParameter(const AvatarParameterValue &) const
Make create parameter.
Result< DomainOperation > makeDeleteExpression(const ObjectId &) const
Make delete expression.
Result< DomainOperation > makeDeleteLayer(const ObjectId &) const
Make delete layer.
const std::vector< AvatarLayerValue > & layers() const
Layers.
TargetId targetId() const override
Target id.
const std::vector< AvatarParameterValue > & parameters() const
Parameters.
std::string expressionChannelName(int expression, int channel) const
Expression channel name.
avatar_editing::Result< void > setParameterValue(double value)
avatar_editing::Result< void > deleteSelectedExpression()
float parameterValue(int index) const
Parameter value.
std::string layerId(int index) const
Layer id.
std::string previewName(int index) const
Preview name.
float parameterMinimum(int index) const
Parameter minimum.
std::string expressionId(int index) const
Expression id.
avatar_editing::Result< editor::TransactionReceipt > redo()
avatar_editing::Result< void > selectParameter(std::string id)
float previewX(int index) const
Preview x.
avatar_editing::Result< void > deleteSelectedParameter()
avatar_editing::Result< void > selectExpression(std::string id)
std::string expressionName(int index) const
Expression name.
float previewA(int index) const
Preview a.
float previewB(int index) const
Preview b.
avatar_editing::Result< void > pointerDown(float x, float y)
avatar_editing::Result< void > createParameter(std::string id, std::string name)
bool isParameterSelected(int index) const
True when parameter selected.
avatar_editing::Result< void > deleteSelectedLayer()
float parameterMaximum(int index) const
Parameter maximum.
int expressionChannelCount(int index) const
Expression channel count.
bool isExpressionSelected(int index) const
True when expression selected.
avatar_editing::Result< void > createLayer(std::string id, std::string name)
AvatarDocumentEditor(std::string targetId)
Construct a seeded two-layer face with a referenced parameter.
float previewW(int index) const
Preview w.
std::uint64_t revision() const noexcept
Revision.
float previewG(int index) const
Preview g.
std::string parameterName(int index) const
Parameter name.
avatar_editing::Result< void > createExpression(std::string id, std::string name)
avatar_editing::Result< void > selectLayer(std::string id)
avatar_editing::Result< void > setLayerZ(int zIndex)
std::string parameterId(int index) const
Parameter id.
avatar_editing::Result< editor::TransactionReceipt > undo()
std::string layerName(int index) const
Layer name.
avatar_editing::Result< void > setLayerVisible(bool visible)
float previewR(int index) const
Preview r.
bool isPreviewSelected(int index) const
True when preview selected.
avatar_editing::Result< void > configureWorkspace(editor::EditorWorkspace &workspace) const
Install Layers / Preview / Inspector / Parameters / Expressions panels.
float previewH(int index) const
Preview h.
bool layerVisible(int index) const
Layer visible.
bool isLayerSelected(int index) const
True when layer selected.
float previewY(int index) const
Preview y.
std::uint64_t revision() const override
Return the current revision.
Dotted property path (layout.size) compared and persisted as text.
Definition EditingIds.h:78
Deterministic owning value tree shared by authoring hosts.
std::vector< Value > Array
std::map< std::string, Value > Object
Composition model shared by project-specific developer and runtime editors.
bool setPanelContext(const std::string &id, const std::string &context)
Attach a semantic input context such as scene, graph, or timeline.
Result< WorkspacePanelDescriptor > registerPanel(WorkspacePanelDescriptor descriptor)
Register a checked owning panel descriptor.
Result< WorkspacePanelDescriptor > activatePanel(const StableId &id)
Activate a visible panel with structured not-found/rejected results.
bool setPanelCapability(const std::string &id, const std::string &capability)
Attach a capability requirement used by the host when filtering panels.
Result< TransactionReceipt > commit() override
Preflight and commit all active operations through the authority.
Result< TransactionId > begin(TransactionSpec specification) override
Begin a transaction with a stable id and base revision.
Result< TransactionReceipt > undo() override
Compensate the most recent committed transaction.
Result< void > discard() override
Discard the active, not-yet-committed operation list.
Result< TransactionReceipt > redo() override
Reapply the most recently compensated transaction.
Result< void > append(DomainOperation operation) override
Append an operation to the active transaction without applying it.
Editor facade binder: common script::BindContext plus history/owned-create helpers.
editing::Status EditorStatus
editing::ObjectId ObjectId
editing::Value EditorValue
editing::RuleId RuleId
void exposeAvatarDocumentEditorScriptBindings(ssq::Table &table, ssq::Class &moduleClass)
Expose the script-owned AvatarDocumentEditor factory on AvatarEditorModule.
eve::editing::StableId StableId
Definition EditorIds.h:36
eve::editing::TargetId TargetId
Definition EditorIds.h:29
eve::editing::TransactionId TransactionId
Definition EditorIds.h:34
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
Named expression containing layer/parameter channel targets.
Stable image layer in an Avatar asset.
Reflected Avatar parameter and its initial value.
SelectionItem public API.
SelectionSnapshot public API.
TransactionSpec public API.
glm::vec4 color