diff --git a/doc/en/scripting/ecs.md b/doc/en/scripting/ecs.md index 8ff0d5fa..2b339864 100644 --- a/doc/en/scripting/ecs.md +++ b/doc/en/scripting/ecs.md @@ -141,6 +141,20 @@ rig:set_texture(key: str, value: str) -- Returns the bone index by name or nil rig:index(name: str) -> int + +-- Checks the visibility status of a bone by index +-- or the skeleton if no index is specified +rig:is_visible([optional] index: int) -> bool + +-- Sets the visibility status of a bone by index +-- or the skeleton if no index is specified +rig:set_visible([optional] index: int, status: bool) + +-- Returns the color of the entity +rig:get_color() -> vec3 + +-- Sets the color of the entity +rig:set_color(color: vec3) ``` ## Component events diff --git a/doc/ru/scripting/ecs.md b/doc/ru/scripting/ecs.md index 3c8c6cb8..5090c264 100644 --- a/doc/ru/scripting/ecs.md +++ b/doc/ru/scripting/ecs.md @@ -150,6 +150,12 @@ rig:is_visible([optional] index: int) -> bool -- Устанавливает статус видимости кости по индексу -- или всего скелета, если индекс не указан rig:set_visible([optional] index: int, status: bool) + +-- Возвращает цвет сущности +rig:get_color() -> vec3 + +-- Устанавливает цвет сущности +rig:set_color(color: vec3) ``` ## События компонента diff --git a/src/logic/scripting/lua/lib__skeleton.cpp b/src/logic/scripting/lua/lib__skeleton.cpp index 42c25dcd..00508176 100644 --- a/src/logic/scripting/lua/lib__skeleton.cpp +++ b/src/logic/scripting/lua/lib__skeleton.cpp @@ -112,6 +112,22 @@ static int l_set_visible(lua::State* L) { return 0; } +static int l_get_color(lua::State* L) { + if (auto entity = get_entity(L, 1)) { + auto& skeleton = entity->getSkeleton(); + return lua::pushvec(L, skeleton.tint); + } + return 0; +} + +static int l_set_color(lua::State* L) { + if (auto entity = get_entity(L, 1)) { + auto& skeleton = entity->getSkeleton(); + skeleton.tint = lua::tovec3(L, 2); + } + return 0; +} + const luaL_Reg skeletonlib [] = { {"get_model", lua::wrap}, {"set_model", lua::wrap}, @@ -122,5 +138,7 @@ const luaL_Reg skeletonlib [] = { {"index", lua::wrap}, {"is_visible", lua::wrap}, {"set_visible", lua::wrap}, + {"get_color", lua::wrap}, + {"set_color", lua::wrap}, {NULL, NULL} }; diff --git a/src/objects/rigging.cpp b/src/objects/rigging.cpp index 6deaf449..ee5299bb 100644 --- a/src/objects/rigging.cpp +++ b/src/objects/rigging.cpp @@ -99,7 +99,7 @@ void SkeletonConfig::render( } model = modelOverride.model ? modelOverride.model : model; if (model) { - batch.draw(skeleton.calculated.matrices[i], glm::vec3(1.0f), model, + batch.draw(skeleton.calculated.matrices[i], skeleton.tint, model, &skeleton.textures); } } diff --git a/src/objects/rigging.hpp b/src/objects/rigging.hpp index 8866dd88..b6ca3e04 100644 --- a/src/objects/rigging.hpp +++ b/src/objects/rigging.hpp @@ -75,6 +75,7 @@ namespace rigging { std::unordered_map textures; std::vector modelOverrides; bool visible; + glm::vec3 tint {1.0f, 1.0f, 1.0f}; Skeleton(const SkeletonConfig* config); };