载入中...
搜索中...
未找到
AnimationClipEditorScriptBindings.cpp
浏览该文件的文档.
2
5#if defined(EVE_ANIMATION_EDITOR_RUNTIME)
8#endif
10
11#include <simplesquirrel/simplesquirrel.hpp>
12
13#include <string>
15
16namespace eve::animation_editor {
17namespace {
18
19constexpr const char* kBindingSource = "editor.animation.clip.squirrel";
20
21class ScriptAnimationClipEditor {
22public:
23 explicit ScriptAnimationClipEditor(std::string targetId) : editor_(std::move(targetId)) {}
24
25 AnimationClipEditor& editor() noexcept { return editor_; }
26 const AnimationClipEditor& editor() const noexcept { return editor_; }
27
28private:
29 AnimationClipEditor editor_;
30};
31
32} // namespace
33
34void exposeAnimationClipEditorScriptBindings(ssq::Table& table, ssq::Class& moduleClass) {
35 const editor::ScriptBind bind{table.getHandle(), kBindingSource};
36 auto clipEditor = editor::addScriptClass<ScriptAnimationClipEditor>(table, "AnimationClipEditor");
37 editor::registerEditorWorkspace<ScriptAnimationClipEditor>(
38 clipEditor, bind, "animation clip editor and workspace must not be null");
39#if defined(EVE_ANIMATION_EDITOR_RUNTIME)
40 clipEditor.addFunc("loadRuntimeClip", [bind](ScriptAnimationClipEditor* self, animation::AnimSkeleton* skeleton,
42 return bind.checked(self && skeleton && clip, "animation clip editor, skeleton and clip must not be null",
43 [&] { return self->editor().loadRuntimeClip(*skeleton, *clip); });
44 });
45 clipEditor.addFunc("writeRuntimeClip", [bind](ScriptAnimationClipEditor* self, animation::AnimClip* clip,
46 animation::AnimSkeleton* skeleton) {
47 return bind.checked(self && skeleton && clip, "animation clip editor, clip and skeleton must not be null",
48 [&] { return self->editor().writeRuntimeClip(*clip, *skeleton); });
49 });
50#endif
51 clipEditor.addFunc(
52 "setViewport", [bind](ScriptAnimationClipEditor* self, float width, float rowHeight, float labelWidth) {
53 return bind.checked(self, "animation clip editor must not be null",
54 [&] { return self->editor().setViewport(width, rowHeight, labelWidth); });
55 });
56 clipEditor.addFunc("seekX", [bind](ScriptAnimationClipEditor* self, float x) {
57 return bind.checked(self, "animation clip editor must not be null", [&] { return self->editor().seekX(x); });
58 });
59 clipEditor.addFunc("seekSeconds", [bind](ScriptAnimationClipEditor* self, float seconds) {
60 return bind.checked(self, "animation clip editor must not be null",
61 [&] { return self->editor().seekSeconds(static_cast<double>(seconds)); });
62 });
63 clipEditor.addFunc("pointerDown", [bind](ScriptAnimationClipEditor* self, float x, float y) {
64 return bind.checked(self, "animation clip editor must not be null",
65 [&] { return self->editor().pointerDown(x, y); });
66 });
67 clipEditor.addFunc("selectBone", [bind](ScriptAnimationClipEditor* self, const std::string& bone) {
68 return bind.checked(self, "animation clip editor must not be null",
69 [&] { return self->editor().selectBone(bone); });
70 });
71 clipEditor.addFunc("setMaskWeight", [bind](ScriptAnimationClipEditor* self, float weight) {
72 return bind.checked(self, "animation clip editor must not be null",
73 [&] { return self->editor().setMaskWeight(static_cast<double>(weight)); });
74 });
75 clipEditor.addFunc("setDuration", [bind](ScriptAnimationClipEditor* self, float duration) {
76 return bind.checked(self, "animation clip editor must not be null",
77 [&] { return self->editor().setDuration(static_cast<double>(duration)); });
78 });
79 clipEditor.addFunc("setSampleRate", [bind](ScriptAnimationClipEditor* self, float sampleRate) {
80 return bind.checked(self, "animation clip editor must not be null",
81 [&] { return self->editor().setSampleRate(static_cast<double>(sampleRate)); });
82 });
83 clipEditor.addFunc("setLoop", [bind](ScriptAnimationClipEditor* self, bool loop) {
84 return bind.checked(self, "animation clip editor must not be null",
85 [&] { return self->editor().setLoop(loop); });
86 });
87 clipEditor.addFunc("moveSelectedKey", [bind](ScriptAnimationClipEditor* self, float time) {
88 return bind.checked(self, "animation clip editor must not be null",
89 [&] { return self->editor().moveSelectedKey(static_cast<double>(time)); });
90 });
91 clipEditor.addFunc("keySelectedBone", [bind](ScriptAnimationClipEditor* self) {
92 return bind.checked(self, "animation clip editor must not be null",
93 [&] { return self->editor().keySelectedBone(); });
94 });
95 clipEditor.addFunc("deleteSelectedKey", [bind](ScriptAnimationClipEditor* self) {
96 return bind.checked(self, "animation clip editor must not be null",
97 [&] { return self->editor().deleteSelectedKey(); });
98 });
99 clipEditor.addFunc("setSelectedPosition", [bind](ScriptAnimationClipEditor* self, float x, float y, float z) {
100 return bind.checked(self, "animation clip editor must not be null",
101 [&] { return self->editor().setSelectedPosition(x, y, z); });
102 });
103 clipEditor.addFunc("setSelectedRotation", [bind](ScriptAnimationClipEditor* self, float x, float y, float z) {
104 return bind.checked(self, "animation clip editor must not be null",
105 [&] { return self->editor().setSelectedRotation(x, y, z); });
106 });
107 clipEditor.addFunc("setSelectedScale", [bind](ScriptAnimationClipEditor* self, float x, float y, float z) {
108 return bind.checked(self, "animation clip editor must not be null",
109 [&] { return self->editor().setSelectedScale(x, y, z); });
110 });
111 editor::registerEditorHistory<ScriptAnimationClipEditor>(clipEditor, bind,
112 "animation clip editor must not be null");
113 clipEditor.addFunc("play", [](ScriptAnimationClipEditor* self) {
114 if (self) self->editor().play();
115 });
116 clipEditor.addFunc("pause", [](ScriptAnimationClipEditor* self) {
117 if (self) self->editor().pause();
118 });
119 clipEditor.addFunc("stop", [bind](ScriptAnimationClipEditor* self) {
120 return bind.checked(self, "animation clip editor must not be null", [&] {
121 self->editor().stop();
122 return self->editor().update(0.0);
123 });
124 });
125 clipEditor.addFunc("update", [bind](ScriptAnimationClipEditor* self, float deltaSeconds) {
126 if (!self) return bind.fail(DiagnosticCode::InvalidArgument, "animation clip editor must not be null");
127 auto result = self->editor().update(static_cast<double>(deltaSeconds));
128 return editor::project(bind.vm(), result, Value(self->editor().playhead()));
129 });
130 clipEditor.addFunc("isPlaying", [](ScriptAnimationClipEditor* self) { return self && self->editor().isPlaying(); });
131 clipEditor.addFunc("getDuration", [](ScriptAnimationClipEditor* self) {
132 return self ? static_cast<float>(self->editor().duration()) : 0.0f;
133 });
134 clipEditor.addFunc("getSampleRate", [](ScriptAnimationClipEditor* self) {
135 return self ? static_cast<float>(self->editor().sampleRate()) : 0.0f;
136 });
137 clipEditor.addFunc("getLoop", [](ScriptAnimationClipEditor* self) { return self && self->editor().isLooping(); });
138 clipEditor.addFunc("getPlayhead", [](ScriptAnimationClipEditor* self) {
139 return self ? static_cast<float>(self->editor().playhead()) : 0.0f;
140 });
141 clipEditor.addFunc("getLayoutWidth", [](ScriptAnimationClipEditor* self) {
142 return self ? self->editor().layoutWidth() : 0.0f;
143 });
144 clipEditor.addFunc("getLayoutHeight", [](ScriptAnimationClipEditor* self) {
145 return self ? self->editor().layoutHeight() : 0.0f;
146 });
147 clipEditor.addFunc("getPlayheadX", [](ScriptAnimationClipEditor* self) {
148 return self ? self->editor().playheadX() : 0.0f;
149 });
150 clipEditor.addFunc("getSelectedBone", [](ScriptAnimationClipEditor* self) {
151 return self ? self->editor().selectedBone() : std::string{};
152 });
153 clipEditor.addFunc("getSelectedMaskWeight", [](ScriptAnimationClipEditor* self) {
154 return self ? static_cast<float>(self->editor().selectedMaskWeight()) : 1.0f;
155 });
156 clipEditor.addFunc("hasSelectedKey", [](ScriptAnimationClipEditor* self) { return self && self->editor().hasSelectedKey(); });
157 clipEditor.addFunc("getSelectedKeyTime", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedKeyTime()) : 0.0f; });
158 clipEditor.addFunc("getSelectedPositionX", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedPositionX()) : 0.0f; });
159 clipEditor.addFunc("getSelectedPositionY", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedPositionY()) : 0.0f; });
160 clipEditor.addFunc("getSelectedPositionZ", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedPositionZ()) : 0.0f; });
161 clipEditor.addFunc("getSelectedRotationX", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedRotationX()) : 0.0f; });
162 clipEditor.addFunc("getSelectedRotationY", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedRotationY()) : 0.0f; });
163 clipEditor.addFunc("getSelectedRotationZ", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedRotationZ()) : 0.0f; });
164 clipEditor.addFunc("getSelectedScaleX", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedScaleX()) : 1.0f; });
165 clipEditor.addFunc("getSelectedScaleY", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedScaleY()) : 1.0f; });
166 clipEditor.addFunc("getSelectedScaleZ", [](ScriptAnimationClipEditor* self) { return self ? static_cast<float>(self->editor().selectedScaleZ()) : 1.0f; });
167 clipEditor.addFunc("getBoneCount", [](ScriptAnimationClipEditor* self) { return self ? self->editor().boneCount() : 0; });
168 clipEditor.addFunc("getBoneName", [](ScriptAnimationClipEditor* self, int index) { return self ? self->editor().boneName(index) : std::string{}; });
169 clipEditor.addFunc("getBoneParent", [](ScriptAnimationClipEditor* self, int index) { return self ? self->editor().boneParent(index) : std::string{}; });
170 clipEditor.addFunc("getTrackCount", [](ScriptAnimationClipEditor* self) {
171 return self ? self->editor().trackCount() : 0;
172 });
173 clipEditor.addFunc("getTrackBone", [](ScriptAnimationClipEditor* self, int index) {
174 return self ? self->editor().trackBone(index) : std::string{};
175 });
176 clipEditor.addFunc("getTrackId", [](ScriptAnimationClipEditor* self, int index) {
177 return self ? self->editor().trackId(index) : std::string{};
178 });
179 clipEditor.addFunc("getTrackSelected", [](ScriptAnimationClipEditor* self, int index) {
180 return self && self->editor().isTrackSelected(index);
181 });
182 clipEditor.addFunc("getKeyCount", [](ScriptAnimationClipEditor* self) {
183 return self ? self->editor().keyCount() : 0;
184 });
185 clipEditor.addFunc("getKeyX", [](ScriptAnimationClipEditor* self, int index) {
186 return self ? self->editor().keyX(index) : 0.0f;
187 });
188 clipEditor.addFunc("getKeyY", [](ScriptAnimationClipEditor* self, int index) {
189 return self ? self->editor().keyY(index) : 0.0f;
190 });
191 clipEditor.addFunc("getKeySelected", [](ScriptAnimationClipEditor* self, int index) {
192 return self && self->editor().isKeySelected(index);
193 });
194 clipEditor.addFunc("getEventCount", [](ScriptAnimationClipEditor* self) {
195 return self ? self->editor().eventCount() : 0;
196 });
197 clipEditor.addFunc("getEventX", [](ScriptAnimationClipEditor* self, int index) {
198 return self ? self->editor().eventX(index) : 0.0f;
199 });
200 clipEditor.addFunc("getEventName", [](ScriptAnimationClipEditor* self, int index) {
201 return self ? self->editor().eventName(index) : std::string{};
202 });
203 clipEditor.addFunc("getPrimitiveCount", [](ScriptAnimationClipEditor* self) {
204 return self ? self->editor().primitiveCount() : 0;
205 });
206 clipEditor.addFunc("getPrimitiveKind", [](ScriptAnimationClipEditor* self, int index) {
207 return self ? self->editor().primitiveKind(index) : std::string{};
208 });
209 clipEditor.addFunc("getPrimitiveX", [](ScriptAnimationClipEditor* self, int index) {
210 return self ? self->editor().primitiveX(index) : 0.0f;
211 });
212 clipEditor.addFunc("getPrimitiveY", [](ScriptAnimationClipEditor* self, int index) {
213 return self ? self->editor().primitiveY(index) : 0.0f;
214 });
215 clipEditor.addFunc("getPrimitiveDirX", [](ScriptAnimationClipEditor* self, int index) {
216 return self ? self->editor().primitiveDirX(index) : 0.0f;
217 });
218 clipEditor.addFunc("getPrimitiveDirY", [](ScriptAnimationClipEditor* self, int index) {
219 return self ? self->editor().primitiveDirY(index) : 0.0f;
220 });
221 clipEditor.addFunc("getPrimitiveLength", [](ScriptAnimationClipEditor* self, int index) {
222 return self ? self->editor().primitiveLength(index) : 0.0f;
223 });
224 clipEditor.addFunc("getPrimitiveRadius", [](ScriptAnimationClipEditor* self, int index) {
225 return self ? self->editor().primitiveRadius(index) : 0.0f;
226 });
227 clipEditor.addFunc("getPrimitiveR", [](ScriptAnimationClipEditor* self, int index) {
228 return self ? self->editor().primitiveR(index) : 0.0f;
229 });
230 clipEditor.addFunc("getPrimitiveG", [](ScriptAnimationClipEditor* self, int index) {
231 return self ? self->editor().primitiveG(index) : 0.0f;
232 });
233 clipEditor.addFunc("getPrimitiveB", [](ScriptAnimationClipEditor* self, int index) {
234 return self ? self->editor().primitiveB(index) : 0.0f;
235 });
236
237 editor::registerEditorOwnedCreate<ScriptAnimationClipEditor, AnimationEditorModule>(
238 moduleClass, bind, "animation clip target id must not be empty");
239}
240
241} // namespace eve::animation_editor
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
float duration
Squirrel adapter for the animation clip editor.
UI-neutral animation clip editor: workspace, pose scrub, dope sheet, undo.
glm::vec4 clip
std::uint32_t width
std::uint32_t bone
std::uint32_t targetId
uint32_t index
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
Keyframed skeletal animation clip (local TRS tracks per bone). Script type: AnimClip.
Definition AnimClip.h:145
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
Editor facade binder: common script::BindContext plus history/owned-create helpers.
void exposeAnimationClipEditorScriptBindings(ssq::Table &table, ssq::Class &moduleClass)
Expose the script-owned AnimationClipEditor factory on AnimationEditorModule.
ssq::Table project(HSQUIRRELVM vm, const eve::Result< void > &result)
Project a completed editing result that has no payload.