载入中...
搜索中...
未找到
ProcgenAnimation.cpp
浏览该文件的文档.
2
6
7#include <functional>
8#include <simplesquirrel/simplesquirrel.hpp>
9
10namespace eve::procgen_animation {
12
13void ProcgenAnimation::expose(ssq::Table& table) {
14 auto module = table.addClass(name, ProcgenAnimation::create, false);
15 expose(module);
16 auto plan = table.addClass("PcgSkinnedMeshPlan", ssq::Class::Ctor<PcgSkinnedMeshPlan()>());
17 plan.addFunc("appendSource", [vm = table.getHandle()](PcgSkinnedMeshPlan* self,
19 const animation::AnimSkin* skin,
20 const procgen::PcgMeshTransform* transform,
21 const std::string& material) {
22 if (!self || !mesh || !skin || !transform)
23 return eve::script::projectResult(vm, Result<void>::failure(Diagnostic::error(
24 DiagnosticCode::InvalidArgument, "Pcg skinned plan arguments are required",
25 "procgen.animation.pcgSkinnedMesh")));
26 return eve::script::projectResult(vm, self->appendSource(*mesh, *skin, *transform, material));
27 });
28 plan.addFunc("clear", [](PcgSkinnedMeshPlan* self) { if (self) self->clear(); });
29 plan.addFunc("getSourceCount", [](const PcgSkinnedMeshPlan* self) {
30 return self ? self->getSourceCount() : 0;
31 });
32 auto result = table.addClass("PcgSkinnedMeshResult", ssq::Class::Ctor<PcgSkinnedMeshResult()>());
33 result.addFunc("isValid", [](const PcgSkinnedMeshResult* self) { return self && self->valid(); });
34 result.addFunc("getSkin", [](PcgSkinnedMeshResult* self) { return self ? self->skin() : nullptr; });
35 result.addFunc("copyMesh", [vm = table.getHandle()](const PcgSkinnedMeshResult* self) -> ssq::Object {
36 const auto* mesh = self ? self->mesh() : nullptr;
37 if (!mesh) return ssq::Object(vm);
38 auto object = eve::script::makeOwnedSquirrelInstance<procgen::MeshBuild>(
39 vm, std::make_unique<procgen::MeshBuild>(*mesh));
40 if (!object) {
41 object.ignore("failed to create Pcg combined skinned mesh Squirrel instance");
42 return ssq::Object(vm);
43 }
44 return std::move(object).takeValue();
45 });
46}
47
48void ProcgenAnimation::expose(ssq::Class& cls) {
49 cls.addFunc("combinePcgSkinnedMeshes", [vm = cls.getHandle()](ProcgenAnimation*,
50 PcgSkinnedMeshResult* output,
51 const PcgSkinnedMeshPlan* plan) {
52 if (!output || !plan)
53 return eve::script::projectResult(vm, Result<void>::failure(Diagnostic::error(
54 DiagnosticCode::InvalidArgument, "Pcg skinned output and plan are required",
55 "procgen.animation.pcgSkinnedMesh")));
56 return eve::script::projectResult(vm, combinePcgSkinnedMeshesInto(*output, *plan));
57 });
58}
59
60} // namespace eve::procgen_animation
std::string output
HSQUIRRELVM vm
Definition ECS.cpp:20
HSQOBJECT cls
Definition ECS.cpp:21
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
Mesh * mesh
Material * material
The single Squirrel projection for common Result, Status and Value.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
CPU linear-blend skinning binding for one mesh against an AnimSkeleton.
Definition AnimSkin.h:47
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Definition MeshBuild.h:19
Row-major affine matrix used by Pcg's root-relative static mesh combination.
Definition PcgMeshLod.h:43
Owned ordered inputs for Pcg's skinned MeshCombiner path.
void clear() noexcept
Remove all sources.
Optional script composition for procedural meshes and skeletal animation.
std::unordered_map< std::string, SkillDefinition > & table()
Definition Skill.cpp:65