From 01a0215903056c3f325cbca64aba43c3710a03fb Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 18 Oct 2026 14:45:42 +0300 Subject: [PATCH 1/3] add skeleton:get_bone_offset --- res/modules/internal/stdcomp.lua | 1 + res/scripts/hud_classes.lua | 1 + src/logic/scripting/lua/libs/lib__skeleton.cpp | 12 ++++++++++++ 3 files changed, 14 insertions(+) diff --git a/res/modules/internal/stdcomp.lua b/res/modules/internal/stdcomp.lua index 65048629f..50af846b4 100644 --- a/res/modules/internal/stdcomp.lua +++ b/res/modules/internal/stdcomp.lua @@ -53,6 +53,7 @@ local Skeleton = {__index={ set_model=function(self, i, s) return __skeleton.set_model(self.eid, i, s) end, get_matrix=function(self, i, ...) return __skeleton.get_matrix(self.eid, i, ...) end, set_matrix=function(self, i, m) return __skeleton.set_matrix(self.eid, i, m) end, + get_bone_offset=function(self, i) return __skeleton.get_bone_offset(self.eid, i) end, reset_pose=function(self) return __skeleton.reset_pose(self.eid) end, get_texture=function(self, s) return __skeleton.get_texture(self.eid, s) end, set_texture=function(self, s, s2) return __skeleton.set_texture(self.eid, s, s2) end, diff --git a/res/scripts/hud_classes.lua b/res/scripts/hud_classes.lua index e6259e22e..e7253f44e 100644 --- a/res/scripts/hud_classes.lua +++ b/res/scripts/hud_classes.lua @@ -18,6 +18,7 @@ local Skeleton = {__index={ set_model=function(self, i, s) return gfx.skeletons.set_model(self.name, i, s) end, get_matrix=function(self, i) return gfx.skeletons.get_matrix(self.name, i) end, set_matrix=function(self, i, m) return gfx.skeletons.set_matrix(self.name, i, m) end, + get_bone_offset=function(self, i) return gfx.skeletons.get_bone_offset(self.name, i) end, get_texture=function(self, i) return gfx.skeletons.get_texture(self.name, i) end, set_texture=function(self, i, s) return gfx.skeletons.set_texture(self.name, i, s) end, is_visible=function(self, i) return gfx.skeletons.is_visible(self.name, i) end, diff --git a/src/logic/scripting/lua/libs/lib__skeleton.cpp b/src/logic/scripting/lua/libs/lib__skeleton.cpp index b39b3287b..b3edc32e7 100644 --- a/src/logic/scripting/lua/libs/lib__skeleton.cpp +++ b/src/logic/scripting/lua/libs/lib__skeleton.cpp @@ -89,6 +89,17 @@ static int l_set_matrix(lua::State* L) { return 0; } +static int l_get_bone_offset(lua::State* L) { + if (auto skeleton = get_skeleton(L)) { + if (skeleton->config == nullptr) { + return 0; + } + auto index = index_range_check(*skeleton, lua::tointeger(L, 2)); + return lua::pushvec(L, skeleton->config->getBones()[index]->getOffset()); + } + return 0; +} + static int l_reset_pose(lua::State* L) { if (auto skeleton = get_skeleton(L)) { auto& pose = skeleton->pose; @@ -372,6 +383,7 @@ const luaL_Reg skeletonlib[] = { {"set_model", lua::wrap}, {"get_matrix", lua::wrap}, {"set_matrix", lua::wrap}, + {"get_bone_offset", lua::wrap}, {"reset_pose", lua::wrap}, {"get_texture", lua::wrap}, {"set_texture", lua::wrap}, From ddf8395d85ed8c725a2057542935af83fc8131a3 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 18 Oct 2026 14:46:31 +0300 Subject: [PATCH 2/3] update doc/*/scripting/ecs.md, doc/*/scripting/builtins/libgfx-skeletons.md --- doc/en/scripting/builtins/libgfx-skeletons.md | 4 ++++ doc/en/scripting/ecs.md | 3 +++ doc/ru/scripting/builtins/libgfx-skeletons.md | 4 ++++ doc/ru/scripting/ecs.md | 3 +++ 4 files changed, 14 insertions(+) diff --git a/doc/en/scripting/builtins/libgfx-skeletons.md b/doc/en/scripting/builtins/libgfx-skeletons.md index 5518cb349..0dfcd7e27 100644 --- a/doc/en/scripting/builtins/libgfx-skeletons.md +++ b/doc/en/scripting/builtins/libgfx-skeletons.md @@ -26,6 +26,10 @@ skeleton:get_matrix(index: int) -> mat4 -- Sets the transformation matrix of the bone with the specified index skeleton:set_matrix(index: int, matrix: mat4) +-- Returns the offset of the bone with the specified index relative to its parent +-- (as defined in the skeleton config) +skeleton:get_bone_offset(index: int) -> vec3 + -- Returns the texture by key (dynamically assigned textures - '$name') skeleton:get_texture(key: str) -> str diff --git a/doc/en/scripting/ecs.md b/doc/en/scripting/ecs.md index 73add6bda..18f815c6c 100644 --- a/doc/en/scripting/ecs.md +++ b/doc/en/scripting/ecs.md @@ -172,6 +172,9 @@ rig:get_matrix(index: int) -> mat4 -- Sets the bone transformation matrix at the specified index rig:set_matrix(index: int, matrix: mat4) +-- Returns the bone offset relative to its parent (from the skeleton config) +rig:get_bone_offset(index: int) -> vec3 + -- Returns the texture by key (dynamically assigned textures - '$name') rig:get_texture(key: str) -> str diff --git a/doc/ru/scripting/builtins/libgfx-skeletons.md b/doc/ru/scripting/builtins/libgfx-skeletons.md index 9465c0df1..0dd8c8462 100644 --- a/doc/ru/scripting/builtins/libgfx-skeletons.md +++ b/doc/ru/scripting/builtins/libgfx-skeletons.md @@ -27,6 +27,10 @@ skeleton:get_matrix(index: int) -> mat4 -- Устанавливает матрицу трансформации кости с указанным индексом skeleton:set_matrix(index: int, matrix: mat4) +-- Возвращает смещение кости с указанным индексом относительно родительской +-- (как задано в конфиге скелета) +skeleton:get_bone_offset(index: int) -> vec3 + -- Возвращает текстуру по ключу (динамически назначаемые текстуры - '$имя') skeleton:get_texture(key: string) -> string diff --git a/doc/ru/scripting/ecs.md b/doc/ru/scripting/ecs.md index 647a4ee3b..fe963e86b 100644 --- a/doc/ru/scripting/ecs.md +++ b/doc/ru/scripting/ecs.md @@ -161,6 +161,9 @@ rig:get_matrix(index: int) -> mat4 -- Устанавливает матрицу трансформации кости с указанным индексом rig:set_matrix(index: int, matrix: mat4) +-- Возвращает смещение кости относительно родительской (из конфига скелета) +rig:get_bone_offset(index: int) -> vec3 + -- Возвращает текстуру по ключу (динамически назначаемые текстуры - '$имя') rig:get_texture(key: str) -> str From 716977aed7a55b166d0dc2071af8c36e54bc5723 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 18 Oct 2026 17:10:44 +0300 Subject: [PATCH 3/3] update Skeleton class --- res/scripts/hud_classes.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/res/scripts/hud_classes.lua b/res/scripts/hud_classes.lua index e7253f44e..0d1804847 100644 --- a/res/scripts/hud_classes.lua +++ b/res/scripts/hud_classes.lua @@ -16,15 +16,16 @@ local Skeleton = {__index={ index=function(self, s) return gfx.skeletons.index(self.name, s) end, get_model=function(self, i) return gfx.skeletons.get_model(self.name, i) end, set_model=function(self, i, s) return gfx.skeletons.set_model(self.name, i, s) end, - get_matrix=function(self, i) return gfx.skeletons.get_matrix(self.name, i) end, + get_matrix=function(self, i, ...) return gfx.skeletons.get_matrix(self.name, i, ...) end, + reset_pose=function(self, ...) return gfx.skeletons.reset_pose(self.name, ...) end, set_matrix=function(self, i, m) return gfx.skeletons.set_matrix(self.name, i, m) end, get_bone_offset=function(self, i) return gfx.skeletons.get_bone_offset(self.name, i) end, get_texture=function(self, i) return gfx.skeletons.get_texture(self.name, i) end, set_texture=function(self, i, s) return gfx.skeletons.set_texture(self.name, i, s) end, - is_visible=function(self, i) return gfx.skeletons.is_visible(self.name, i) end, - set_visible=function(self, i, b) return gfx.skeletons.set_visible(self.name, i, b) end, - get_color=function(self, i) return gfx.skeletons.get_color(self.name, i) end, - set_color=function(self, i, c) return gfx.skeletons.set_color(self.name, i, c) end, + is_visible=function(self, ...) return gfx.skeletons.is_visible(self.name, ...) end, + set_visible=function(self, ...) return gfx.skeletons.set_visible(self.name, ...) end, + get_color=function(self, ...) return gfx.skeletons.get_color(self.name, ...) end, + set_color=function(self, ...) return gfx.skeletons.set_color(self.name, ...) end, }} gfx.text3d.new = function(pos, text, preset, extension)