cleanup __skeleton library
This commit is contained in:
@@ -13,25 +13,30 @@ static int index_range_check(
|
|||||||
return static_cast<int>(index);
|
return static_cast<int>(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_get_model(lua::State* L) {
|
static rigging::Skeleton* get_skeleton(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
return &entity->getSkeleton();
|
||||||
auto* rigConfig = skeleton.config;
|
}
|
||||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
return nullptr;
|
||||||
const auto& modelOverride = skeleton.modelOverrides[index];
|
}
|
||||||
|
|
||||||
|
static int l_get_model(lua::State* L) {
|
||||||
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
|
auto& rigConfig = *skeleton->config;
|
||||||
|
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
||||||
|
const auto& modelOverride = skeleton->modelOverrides[index];
|
||||||
if (!modelOverride.model) {
|
if (!modelOverride.model) {
|
||||||
return lua::pushstring(L, modelOverride.name);
|
return lua::pushstring(L, modelOverride.name);
|
||||||
}
|
}
|
||||||
return lua::pushstring(L, rigConfig->getBones()[index]->model.name);
|
return lua::pushstring(L, rigConfig.getBones()[index]->model.name);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_set_model(lua::State* L) {
|
static int l_set_model(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
||||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
auto& modelOverride = skeleton->modelOverrides[index];
|
||||||
auto& modelOverride = skeleton.modelOverrides[index];
|
|
||||||
if (lua::isnoneornil(L, 3)) {
|
if (lua::isnoneornil(L, 3)) {
|
||||||
modelOverride = {"", nullptr, true};
|
modelOverride = {"", nullptr, true};
|
||||||
} else {
|
} else {
|
||||||
@@ -42,28 +47,25 @@ static int l_set_model(lua::State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int l_get_matrix(lua::State* L) {
|
static int l_get_matrix(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
||||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
return lua::pushmat4(L, skeleton->pose.matrices[index]);
|
||||||
return lua::pushmat4(L, skeleton.pose.matrices[index]);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_set_matrix(lua::State* L) {
|
static int l_set_matrix(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
||||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
skeleton->pose.matrices[index] = lua::tomat4(L, 3);
|
||||||
skeleton.pose.matrices[index] = lua::tomat4(L, 3);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_get_texture(lua::State* L) {
|
static int l_get_texture(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
const auto& found = skeleton->textures.find(lua::require_string(L, 2));
|
||||||
const auto& found = skeleton.textures.find(lua::require_string(L, 2));
|
if (found != skeleton->textures.end()) {
|
||||||
if (found != skeleton.textures.end()) {
|
|
||||||
return lua::pushstring(L, found->second);
|
return lua::pushstring(L, found->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,18 +73,16 @@ static int l_get_texture(lua::State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int l_set_texture(lua::State* L) {
|
static int l_set_texture(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
skeleton->textures[lua::require_string(L, 2)] =
|
||||||
skeleton.textures[lua::require_string(L, 2)] =
|
|
||||||
lua::require_string(L, 3);
|
lua::require_string(L, 3);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_index(lua::State* L) {
|
static int l_index(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton= get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
if (auto bone = skeleton->config->find(lua::require_string(L, 2))) {
|
||||||
if (auto bone = skeleton.config->find(lua::require_string(L, 2))) {
|
|
||||||
return lua::pushinteger(L, bone->getIndex());
|
return lua::pushinteger(L, bone->getIndex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,58 +90,52 @@ static int l_index(lua::State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int l_is_visible(lua::State* L) {
|
static int l_is_visible(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
|
||||||
if (!lua::isnoneornil(L, 2)) {
|
if (!lua::isnoneornil(L, 2)) {
|
||||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
||||||
return lua::pushboolean(L, skeleton.flags.at(index).visible);
|
return lua::pushboolean(L, skeleton->flags.at(index).visible);
|
||||||
}
|
}
|
||||||
return lua::pushboolean(L, skeleton.visible);
|
return lua::pushboolean(L, skeleton->visible);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_set_visible(lua::State* L) {
|
static int l_set_visible(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
|
||||||
if (!lua::isnoneornil(L, 3)) {
|
if (!lua::isnoneornil(L, 3)) {
|
||||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
||||||
skeleton.flags.at(index).visible = lua::toboolean(L, 3);
|
skeleton->flags.at(index).visible = lua::toboolean(L, 3);
|
||||||
} else {
|
} else {
|
||||||
skeleton.visible = lua::toboolean(L, 2);
|
skeleton->visible = lua::toboolean(L, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_get_color(lua::State* L) {
|
static int l_get_color(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
return lua::pushvec(L, skeleton->tint);
|
||||||
return lua::pushvec(L, skeleton.tint);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_set_color(lua::State* L) {
|
static int l_set_color(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
skeleton->tint = lua::tovec3(L, 2);
|
||||||
skeleton.tint = lua::tovec3(L, 2);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_is_interpolated(lua::State* L) {
|
static int l_is_interpolated(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
return lua::pushboolean(L, skeleton->interpolation.isEnabled());
|
||||||
return lua::pushboolean(L, skeleton.interpolation.isEnabled());
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_set_interpolated(lua::State* L) {
|
static int l_set_interpolated(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& skeleton = entity->getSkeleton();
|
skeleton->interpolation.setEnabled(lua::toboolean(L, 2));
|
||||||
skeleton.interpolation.setEnabled(lua::toboolean(L, 2));
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -160,4 +154,5 @@ const luaL_Reg skeletonlib[] = {
|
|||||||
{"set_color", lua::wrap<l_set_color>},
|
{"set_color", lua::wrap<l_set_color>},
|
||||||
{"is_interpolated", lua::wrap<l_is_interpolated>},
|
{"is_interpolated", lua::wrap<l_is_interpolated>},
|
||||||
{"set_interpolated", lua::wrap<l_set_interpolated>},
|
{"set_interpolated", lua::wrap<l_set_interpolated>},
|
||||||
{NULL, NULL}};
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user