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