add new skeleton:get_color, skeleton:set_color overloads

This commit is contained in:
MihailRis 2026-09-16 23:40:41 +03:00
parent f5f17b7746
commit ad22763a1f
2 changed files with 19 additions and 5 deletions

View file

@ -58,8 +58,8 @@ local Skeleton = {__index={
index=function(self, s) return __skeleton.index(self.eid, s) end,
is_visible=function(self, i) return __skeleton.is_visible(self.eid, i) end,
set_visible=function(self, i, b) return __skeleton.set_visible(self.eid, i, b) end,
get_color=function(self) return __skeleton.get_color(self.eid) end,
set_color=function(self, color) return __skeleton.set_color(self.eid, color) end,
get_color=function(self, ...) return __skeleton.get_color(self.eid, ...) end,
set_color=function(self, color, ...) return __skeleton.set_color(self.eid, color, ...) end,
set_interpolated=function(self, b) return __skeleton.set_interpolated(self.eid, b) end,
}}

View file

@ -147,8 +147,19 @@ static int l_set_visible(lua::State* L) {
return 0;
}
static glm::vec4 to_color(lua::State* L, int idx) {
if (lua::objlen(L, idx) > 3) {
return lua::tovec4(L, idx);
}
return glm::vec4(lua::tovec3(L, idx), 1.0f);
}
static int l_get_color(lua::State* L) {
if (auto skeleton = get_skeleton(L)) {
if (lua::isnumber(L, 2)) {
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
return lua::pushvec(L, skeleton->boneTints[index]);
}
return lua::pushvec(L, skeleton->tint);
}
return 0;
@ -156,9 +167,12 @@ static int l_get_color(lua::State* L) {
static int l_set_color(lua::State* L) {
if (auto skeleton = get_skeleton(L)) {
skeleton->tint = lua::objlen(L, 2) > 3
? lua::tovec4(L, 2)
: glm::vec4(lua::tovec3(L, 2), 1.0f);
if (lua::isnumber(L, 2)) {
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
skeleton->boneTints[index] = to_color(L, 3);
} else {
skeleton->tint = to_color(L, 2);
}
}
return 0;
}