add gfx.skeletons library docs

This commit is contained in:
MihailRis 2025-07-27 22:18:28 +03:00
parent b991ca3c9a
commit b5a2f2ae71
5 changed files with 122 additions and 2 deletions

View File

@ -0,0 +1,48 @@
# gfx.skeletons library
A library for working with named skeletons, such as 'hand',
used to control the hand and the carried item displayed in first-person view.
The set of functions is similar to the skeleton component of entities.
The first argument to the function is the name of the skeleton.
```lua
-- Returns an object wrapper over the skeleton
local skeleton = gfx.skeletons.get(name: str)
-- Returns the index of the bone by name or nil
skeleton:index(name: str) -> int
-- Returns the name of the model assigned to the bone with the specified index
skeleton:get_model(index: int) -> str
-- Reassigns the model of the bone with the specified index
-- Resets to the original if you do not specify a name
skeleton:set_model(index: int, name: str)
-- Returns the transformation matrix of the bone with the specified index
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 texture by key (dynamically assigned textures - '$name')
skeleton:get_texture(key: str) -> str
-- Assigns a texture by key
skeleton:set_texture(key: str, value: str)
-- Checks the visibility status of a bone by index
-- or the entire skeleton if index is not specified
skeleton:is_visible([optional] index: int) -> bool
-- Sets the visibility status of a bone by index
-- or the entire skeleton if index is not specified
skeleton:set_visible([optional] index: int, status: bool)
-- Returns the color of the entity
skeleton:get_color() -> vec3
-- Sets the color of the entity
skeleton:set_color(color: vec3)
```

View File

@ -0,0 +1,49 @@
# Библиотека gfx.skeletons
Библиотека для работы с именованными скелетами, такими как 'hand',
использующийся для управления, отображаемыми при виде от первого лица,
рукой и переносимым предметом. Набор функций аналогичен компоненту skeleton
у сущностей.
Первым аргументом в функции передаётся имя скелета.
```lua
-- Возвращает объектную обёртку над скелетом
local skeleton = gfx.skeletons.get(name: str)
-- Возвращает индекс кости по имени или nil
skeleton:index(name: str) -> int
-- Возвращает имя модели, назначенной на кость с указанным индексом
skeleton:get_model(index: int) -> str
-- Переназначает модель кости с указанным индексом
-- Сбрасывает до изначальной, если не указывать имя
skeleton:set_model(index: int, name: str)
-- Возвращает матрицу трансформации кости с указанным индексом
skeleton:get_matrix(index: int) -> mat4
-- Устанавливает матрицу трансформации кости с указанным индексом
skeleton:set_matrix(index: int, matrix: mat4)
-- Возвращает текстуру по ключу (динамически назначаемые текстуры - '$имя')
skeleton:get_texture(key: str) -> str
-- Назначает текстуру по ключу
skeleton:set_texture(key: str, value: str)
-- Проверяет статус видимости кости по индесу
-- или всего скелета, если индекс не указан
skeleton:is_visible([опционально] index: int) -> bool
-- Устанавливает статус видимости кости по индексу
-- или всего скелета, если индекс не указан
skeleton:set_visible([опционально] index: int, status: bool)
-- Возвращает цвет сущности
skeleton:get_color() -> vec3
-- Устанавливает цвет сущности
skeleton:set_color(color: vec3)
```

View File

@ -83,8 +83,6 @@ function on_hud_open()
configure_SSAO()
end
local prev_rotation = mat4.idt()
function update_hand()
local skeleton = gfx.skeletons
local pid = hud.get_player()

View File

@ -12,7 +12,27 @@ local Text3D = {__index={
update_settings=function(self, t) return gfx.text3d.update_settings(self.id, t) end,
}}
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,
set_matrix=function(self, i, m) return gfx.skeletons.set_matrix(self.name, i, m) 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,
}}
gfx.text3d.new = function(pos, text, preset, extension)
local id = gfx.text3d.show(pos, text, preset, extension)
return setmetatable({id=id}, Text3D)
end
gfx.skeletons.get = function(name)
if gfx.skeletons.exists(name) then
return setmetatable({name=name}, Skeleton)
end
end

View File

@ -150,6 +150,10 @@ static int l_set_interpolated(lua::State* L) {
return 0;
}
static int l_exists(lua::State* L) {
return lua::pushboolean(L, get_skeleton(L));
}
const luaL_Reg skeletonlib[] = {
{"get_model", lua::wrap<l_get_model>},
{"set_model", lua::wrap<l_set_model>},
@ -164,5 +168,6 @@ const luaL_Reg skeletonlib[] = {
{"set_color", lua::wrap<l_set_color>},
{"is_interpolated", lua::wrap<l_is_interpolated>},
{"set_interpolated", lua::wrap<l_set_interpolated>},
{"exists", lua::wrap<l_exists>},
{NULL, NULL}
};