载入中...
搜索中...
未找到
VoxelCatalogEditorScriptBindings.cpp
浏览该文件的文档.
2
6
7#include <simplesquirrel/simplesquirrel.hpp>
8
9#include <string>
11
12namespace eve::voxel_editor {
13namespace {
14
15constexpr const char* kBindingSource = "editor.voxel.sculpt.squirrel";
16
17class ScriptVoxelCatalogEditor {
18public:
19 explicit ScriptVoxelCatalogEditor(std::string targetId) : editor_(std::move(targetId)) {}
20
21 VoxelCatalogEditor& editor() noexcept { return editor_; }
22 const VoxelCatalogEditor& editor() const noexcept { return editor_; }
23
24private:
25 VoxelCatalogEditor editor_;
26};
27
28} // namespace
29
30void exposeVoxelCatalogEditorScriptBindings(ssq::Table& table, ssq::Class& moduleClass) {
31 const editor::ScriptBind bind{table.getHandle(), kBindingSource};
32 auto voxelEditor = editor::addScriptClass<ScriptVoxelCatalogEditor>(table, "VoxelCatalogEditor");
33
34 editor::registerEditorWorkspace<ScriptVoxelCatalogEditor>(voxelEditor, bind,
35 "voxel editor and workspace must not be null");
36 voxelEditor.addFunc("selectModel", [bind](ScriptVoxelCatalogEditor* self, const std::string& id) {
37 return bind.checked(self, "voxel editor must not be null", [&] { return self->editor().selectModel(id); });
38 });
39 voxelEditor.addFunc("setTool", [bind](ScriptVoxelCatalogEditor* self, const std::string& tool) {
40 return bind.checked(self, "voxel editor must not be null", [&] { return self->editor().setTool(tool); });
41 });
42 voxelEditor.addFunc("setViewport", [bind](ScriptVoxelCatalogEditor* self, float width, float height) {
43 return bind.checked(self, "voxel editor must not be null",
44 [&] { return self->editor().setViewport(width, height); });
45 });
46 voxelEditor.addFunc("orbit", [bind](ScriptVoxelCatalogEditor* self, float yaw, float pitch) {
47 return bind.checked(self, "voxel editor must not be null", [&] { return self->editor().orbit(yaw, pitch); });
48 });
49 voxelEditor.addFunc("pointerDown", [bind](ScriptVoxelCatalogEditor* self, float x, float y) {
50 return bind.checked(self, "voxel editor must not be null", [&] { return self->editor().pointerDown(x, y); });
51 });
52 voxelEditor.addFunc("pointerWorldRay", [bind](ScriptVoxelCatalogEditor* self, float ox, float oy, float oz,
53 float dx, float dy, float dz) {
54 return bind.checked(self, "voxel editor must not be null",
55 [&] { return self->editor().pointerWorldRay(ox, oy, oz, dx, dy, dz); });
56 });
57 voxelEditor.addFunc("setVoxel", [bind](ScriptVoxelCatalogEditor* self, int x, int y, int z, bool occupied) {
58 return bind.checked(self, "voxel editor must not be null",
59 [&] { return self->editor().setVoxel(x, y, z, occupied); });
60 });
61 voxelEditor.addFunc("setSelectedSocket",
62 [bind](ScriptVoxelCatalogEditor* self, const std::string& tag, const std::string& kind) {
63 return bind.checked(self, "voxel editor must not be null",
64 [&] { return self->editor().setSelectedSocket(tag, kind); });
65 });
66 voxelEditor.addFunc("selectFace", [bind](ScriptVoxelCatalogEditor* self, int face) {
67 return bind.checked(self, "voxel editor must not be null", [&] { return self->editor().selectFace(face); });
68 });
69 voxelEditor.addFunc("createModel", [bind](ScriptVoxelCatalogEditor* self, const std::string& id,
70 const std::string& name, int sx, int sy, int sz) {
71 return bind.checked(self, "voxel editor must not be null",
72 [&] { return self->editor().createModel(id, name, sx, sy, sz); });
73 });
74 voxelEditor.addFunc("deleteSelectedModel", [bind](ScriptVoxelCatalogEditor* self) {
75 return bind.checked(self, "voxel editor must not be null",
76 [&] { return self->editor().deleteSelectedModel(); });
77 });
78 editor::registerEditorHistory<ScriptVoxelCatalogEditor>(voxelEditor, bind, "voxel editor must not be null");
79 voxelEditor.addFunc("getSelectedId", [](ScriptVoxelCatalogEditor* self) {
80 return self ? self->editor().selectedId() : std::string{};
81 });
82 voxelEditor.addFunc("getTool", [](ScriptVoxelCatalogEditor* self) {
83 return self ? self->editor().toolName() : std::string{};
84 });
85 voxelEditor.addFunc("getSelectedFace", [](ScriptVoxelCatalogEditor* self) {
86 return self ? self->editor().selectedFace() : 0;
87 });
88 voxelEditor.addFunc("getModelCount", [](ScriptVoxelCatalogEditor* self) {
89 return self ? self->editor().modelCount() : 0;
90 });
91 voxelEditor.addFunc("getModelId", [](ScriptVoxelCatalogEditor* self, int index) {
92 return self ? self->editor().modelId(index) : std::string{};
93 });
94 voxelEditor.addFunc("getModelName", [](ScriptVoxelCatalogEditor* self, int index) {
95 return self ? self->editor().modelName(index) : std::string{};
96 });
97 voxelEditor.addFunc("getModelFill", [](ScriptVoxelCatalogEditor* self, int index) {
98 return self ? self->editor().modelFill(index) : std::string{};
99 });
100 voxelEditor.addFunc("getModelSelected", [](ScriptVoxelCatalogEditor* self, int index) {
101 return self && self->editor().isModelSelected(index);
102 });
103 voxelEditor.addFunc("getVoxelCount", [](ScriptVoxelCatalogEditor* self) {
104 return self ? self->editor().voxelCount() : 0;
105 });
106 voxelEditor.addFunc("getVoxelX", [](ScriptVoxelCatalogEditor* self, int index) {
107 return self ? self->editor().voxelX(index) : 0;
108 });
109 voxelEditor.addFunc("getVoxelY", [](ScriptVoxelCatalogEditor* self, int index) {
110 return self ? self->editor().voxelY(index) : 0;
111 });
112 voxelEditor.addFunc("getVoxelZ", [](ScriptVoxelCatalogEditor* self, int index) {
113 return self ? self->editor().voxelZ(index) : 0;
114 });
115 voxelEditor.addFunc("getModelSizeX", [](ScriptVoxelCatalogEditor* self) {
116 return self ? self->editor().modelSizeX() : 0;
117 });
118 voxelEditor.addFunc("getModelSizeY", [](ScriptVoxelCatalogEditor* self) {
119 return self ? self->editor().modelSizeY() : 0;
120 });
121 voxelEditor.addFunc("getModelSizeZ", [](ScriptVoxelCatalogEditor* self) {
122 return self ? self->editor().modelSizeZ() : 0;
123 });
124 voxelEditor.addFunc("getScreenVoxelCount", [](ScriptVoxelCatalogEditor* self) {
125 return self ? self->editor().screenVoxelCount() : 0;
126 });
127 voxelEditor.addFunc("getScreenVoxelX", [](ScriptVoxelCatalogEditor* self, int index) {
128 return self ? self->editor().screenVoxelX(index) : 0.0f;
129 });
130 voxelEditor.addFunc("getScreenVoxelY", [](ScriptVoxelCatalogEditor* self, int index) {
131 return self ? self->editor().screenVoxelY(index) : 0.0f;
132 });
133 voxelEditor.addFunc("getScreenVoxelW", [](ScriptVoxelCatalogEditor* self, int index) {
134 return self ? self->editor().screenVoxelW(index) : 0.0f;
135 });
136 voxelEditor.addFunc("getScreenVoxelH", [](ScriptVoxelCatalogEditor* self, int index) {
137 return self ? self->editor().screenVoxelH(index) : 0.0f;
138 });
139 voxelEditor.addFunc("getSelectedSocketTag", [](ScriptVoxelCatalogEditor* self) {
140 return self ? self->editor().selectedSocketTag() : std::string{};
141 });
142 voxelEditor.addFunc("getSelectedSocketKind", [](ScriptVoxelCatalogEditor* self) {
143 return self ? self->editor().selectedSocketKind() : std::string{};
144 });
145 voxelEditor.addFunc("getJoinPartnerCount", [](ScriptVoxelCatalogEditor* self) {
146 return self ? self->editor().joinPartnerCount() : 0;
147 });
148 voxelEditor.addFunc("getJoinPartnerId", [](ScriptVoxelCatalogEditor* self, int index) {
149 return self ? self->editor().joinPartnerId(index) : std::string{};
150 });
151
152 editor::registerEditorOwnedCreate<ScriptVoxelCatalogEditor, VoxelEditorModule>(moduleClass, bind, "voxel target id must not be empty");
153}
154
155} // namespace eve::voxel_editor
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
std::uint32_t height
std::uint32_t width
TokenKind kind
std::string name
const std::string * tag
std::uint32_t targetId
float dz
float dy
float dx
bool occupied
uint32_t index
double oy
double ox
Squirrel adapter for the MagicaVoxel-style sculpt editor.
MagicaVoxel-style miniature sculpt editor: orbit view, attach/erase, undo.
Editor facade binder: common script::BindContext plus history/owned-create helpers.
void exposeVoxelCatalogEditorScriptBindings(ssq::Table &table, ssq::Class &moduleClass)
Expose the script-owned VoxelCatalogEditor factory on VoxelEditorModule.