载入中...
搜索中...
未找到
AnimationInertiaBindings.cpp
浏览该文件的文档.
1#include <functional>
2#include <simplesquirrel/simplesquirrel.hpp>
3#include <stdexcept>
4#include <string>
5#include <vector>
6
12
13namespace eve::animation {
14namespace {
15
16constexpr const char* kSource = "animation.bindings";
17
18} // namespace
19
20void exposeAnimInertializerBindings(ssq::Table& table) {
21 const script::BindContext bind{table.getHandle(), kSource};
22 auto cls = table.addClass<AnimInertializer>(
23 "AnimInertializer", std::function<AnimInertializer*()>([] { return new AnimInertializer(); }), true);
25 cls, "begin",
26 [bind](AnimInertializer* self, AnimPose* source, AnimPose* previousSource, AnimPose* target,
27 AnimPose* previousTarget, float history, float duration, ssq::Array factors) {
28 try {
29 if (!source || !previousSource || !target || !previousTarget)
30 throw std::runtime_error("transition requires four poses");
31 if (factors.size() != 0 && factors.size() != static_cast<std::size_t>(source->getBoneCount()))
32 throw std::runtime_error("time factors must match bone count");
33 std::vector<float> values;
34 values.reserve(factors.size());
35 for (std::size_t i = 0; i < factors.size(); ++i) values.push_back(factors.get<float>(i));
36 return script::projectResult(bind.vm(), self->begin(*source, *previousSource, *target, *previousTarget,
37 history, duration, values));
38 } catch (const std::exception& error) {
39 return bind.failInvalid(error.what());
40 }
41 });
42 script::bindMethod(cls, "evaluate", [bind](AnimInertializer* self, AnimPose* target, float elapsed) {
43 if (!target) return bind.failInvalid("target pose is required");
44 return script::projectResult(bind.vm(), self->evaluate(*target, elapsed));
45 });
46 script::bindMethod(cls, "copyPose", [](AnimInertializer* self, AnimPose* destination) {
47 if (!destination) throw std::runtime_error("output pose is required");
48 destination->copyFrom(&self->pose());
49 });
50}
51} // namespace eve::animation
LogicalId target
float duration
HSQOBJECT cls
Definition ECS.cpp:39
std::string error
Definition Package.cpp:174
std::set< std::string > values
std::string_view source
Per-translation-unit VM + diagnostic-source helper for Squirrel bindings.
The single Squirrel projection for common Result, Status and Value.
Finite-duration pose transition relative to a continuously sampled target.
const AnimPose & pose() const noexcept
Borrow read-only output, valid until destruction; contents change after successful begin/evaluate....
eve::Result< void > begin(const AnimPose &source, const AnimPose &previousSource, const AnimPose &target, const AnimPose &previousTarget, float historySeconds, float durationSeconds, std::span< const float > boneTimeFactors={})
Atomically begin or interrupt a transition using actual outgoing pose history.
eve::Result< void > evaluate(const AnimPose &target, float elapsedSeconds)
Evaluate the moving target at an absolute elapsed simulation time since begin.
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
void copyFrom(const AnimPose *other)
Copies from.
Definition AnimPose.cpp:95
Pins the active VM and a stable diagnostic source for one expose() TU.
void exposeAnimInertializerBindings(ssq::Table &table)
Register the owning AnimInertializer Squirrel surface.
void bindMethod(ssq::Class &cls, const char *name, F &&fn)
Register one script method while keeping a literal name for Binding Contracts.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.