fix components order & add skeleton:get_matrix overload & add skeleton:reset_pose

This commit is contained in:
MihailRis 2026-07-26 15:08:55 +03:00
parent 8a9b4a9e9c
commit 8242d299ed
3 changed files with 29 additions and 8 deletions

View file

@ -66,7 +66,11 @@ static int l_set_model(lua::State* L) {
static int l_get_matrix(lua::State* L) {
if (auto skeleton = get_skeleton(L)) {
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
return lua::pushmat4(L, skeleton->pose.matrices[index]);
if (lua::istable(L, 3)) {
lua::setmat4(L, 3, skeleton->pose.matrices[index]);
} else {
return lua::pushmat4(L, skeleton->pose.matrices[index]);
}
}
return 0;
}
@ -79,6 +83,14 @@ static int l_set_matrix(lua::State* L) {
return 0;
}
static int l_reset_pose(lua::State* L) {
if (auto skeleton = get_skeleton(L)) {
auto& pose = skeleton->pose;
std::fill(pose.matrices.begin(), pose.matrices.end(), glm::mat4(1.0f));
}
return 0;
}
static int l_get_texture(lua::State* L) {
if (auto skeleton = get_skeleton(L)) {
const auto& found = skeleton->textures.find(lua::require_string(L, 2));
@ -169,6 +181,7 @@ const luaL_Reg skeletonlib[] = {
{"set_model", lua::wrap<l_set_model>},
{"get_matrix", lua::wrap<l_get_matrix>},
{"set_matrix", lua::wrap<l_set_matrix>},
{"reset_pose", lua::wrap<l_reset_pose>},
{"get_texture", lua::wrap<l_get_texture>},
{"set_texture", lua::wrap<l_set_texture>},
{"index", lua::wrap<l_index>},

View file

@ -37,6 +37,11 @@ static inline const std::string STDCOMP = "stdcomp";
lua::setfield(L, name);
lua::pop(L);
}
if (lua::getfield(L, "ordered_components")) {
lua::pushenv(L, id);
lua::rawseti(L, lua::objlen(L, -2) + 1);
lua::pop(L);
}
lua::pop(L);
return std::shared_ptr<int>(new int(id), [=](int* id) { //-V508