Merge branch 'main' into curl

This commit is contained in:
MihailRis 2024-11-23 17:46:57 +03:00
commit db5dada519
10 changed files with 231 additions and 24 deletions

86
doc/en/3d-text.md Normal file
View File

@ -0,0 +1,86 @@
# 3D Text
2D text displayed in 3D space.
The appearance of 3D text, is configured via a table, like [particles](particles.md). All fields are optional.
| Field | Description | Default |
| -------------- | ---------------------------- | ---------------- |
| display | Display format | static_billboard |
| color | Text color | {1, 1, 1, 1} |
| scale | Text scale | 1 |
| renderDistance | Text rendering distance | 32 |
| xray_opacity | Visibility through obstacles | 0 |
| perspective | Perspective coefficient | 1 |
Available display formats:
| Format | Description |
| ----------------- | ----------------------------------------------------------------- |
| static_billboard | Simple 3D text in the world with manual size and rotation control |
| y_free_billboard | Freely rotating text on the Y axis facing the camera |
| xy_free_billboard | Freely rotating text facing the camera |
| projected | Projected text (displayed in screen coordinates) |
## *gfx.text3d* library
```lua
gfx.text3d.show(
-- text position
position: vec3,
-- text to display
text: str,
-- text display settings table
preset: table,
-- additional text display settings table
[optional] extension: table
) -> int
```
Creates 3D text, returning its id.
```lua
gfx.text3d.hide(id: int)
```
Removes 3D text.
```lua
gfx.text3d.get_text(id: int) -> str
gfx.text3d.set_text(id: int, text: str)
```
Text getter and setter.
```lua
gfx.text3d.get_pos(id: int) -> vec3
gfx.text3d.set_pos(id: int, pos: vec3)
```
Text position getter and setter.
```lua
gfx.text3d.get_axis_x(id: int) -> vec3
gfx.text3d.set_axis_x(id: int, pos: vec3)
```
Getter and setter of vector X.
```lua
gfx.text3d.get_axis_y(id: int) -> vec3
gfx.text3d.set_axis_y(id: int, pos: vec3)
```
Getter and setter of vector Y.
```lua
gfx.text3d.set_rotation(id: int, rotation: mat4)
```
Sets the text rotation (Sets the rotated vectors X,Y).
```lua
gfx.text3d.update_settings(id: int, preset: table)
```
Updates text display settings.

View File

@ -9,10 +9,14 @@ Subsections:
- [UI properties and methods](scripting/ui.md)
- [Entities and components](scripting/ecs.md)
- [Libraries](#)
- [base64](scripting/builtins/libbase64.md)
- [bjson, json, toml](scripting/filesystem.md)
- [block](scripting/builtins/libblock.md)
- [cameras](scripting/builtins/libcameras.md)
- [entities](scripting/builtins/libentities.md)
- [file](scripting/builtins/libfile.md)
- [gfx.particles](particles.md#gfxparticles-library)
- [gfx.text3d](3d-text.md#gfxtext3d-library)
- [gui](scripting/builtins/libgui.md)
- [hud](scripting/builtins/libhud.md)
- [inventory](scripting/builtins/libinventory.md)

View File

@ -0,0 +1,11 @@
# *base64* library
Library for base64 encoding/decoding.
```lua
-- Encode bytes to base64 string
base64.encode(bytes: table|ByteArray) -> str
-- Decode base64 string to ByteArray or lua table if second argument is set to true
base64.decode(base64string: str, [optional]usetable: bool=false) -> table|ByteArray
```

86
doc/ru/3d-text.md Normal file
View File

@ -0,0 +1,86 @@
# 3D Текст
2D текст отображаемый в 3D пространстве.
Вид 3D текста, как и [частицы](particles.md), настраивается через таблицу, все поля которой опциональны.
| Поле | Описание | По-умолчанию |
| --------------- | ------------------------------------------------------- | ----------------- |
| display | Формат отображения | static_billboard |
| color | Цвет текста | {1, 1, 1, 1} |
| scale | Масштаб | 1 |
| renderDistance | Дистанция отрисовки текста | 32 |
| xray_opacity | Коэффициент видимости через препятствия (просвечивание) | 0 |
| perspective | Коэффициент перспективы | 1 |
Доступные форматы отображения:
| Формат | Описание |
| ----------------- | ----------------------------------------------------------------- |
| static_billboard | Простой 3D текст в мире с ручным управлением размером и вращением |
| y_free_billboard | Свободно вращающийся по оси Y текст, направляющийся на камеру |
| xy_free_billboard | Свободно вращающийся текст, направляющийся на камеру |
| projected | Проецируемый текст (отображается в экранной системе координат) |
## Библиотека *gfx.text3d*
```lua
gfx.text3d.show(
-- позиция текста
position: vec3,
-- отображаемый текст
text: str,
-- таблица настроек отображение текста
preset: table,
-- дополнительная таблица настроек отображения текста
[опционально] extension: table
) -> int
```
Создаёт 3D текст, возвращая его id.
```lua
gfx.text3d.hide(id: int)
```
Удаляет 3D текст.
```lua
gfx.text3d.get_text(id: int) -> str
gfx.text3d.set_text(id: int, text: str)
```
Геттер и сеттер текста.
```lua
gfx.text3d.get_pos(id: int) -> vec3
gfx.text3d.set_pos(id: int, pos: vec3)
```
Геттер и сеттер позиции текста.
```lua
gfx.text3d.get_axis_x(id: int) -> vec3
gfx.text3d.set_axis_x(id: int, pos: vec3)
```
Геттер и сеттер вектора X.
```lua
gfx.text3d.get_axis_y(id: int) -> vec3
gfx.text3d.set_axis_y(id: int, pos: vec3)
```
Геттер и сеттер вектора Y.
```lua
gfx.text3d.set_rotation(id: int, rotation: mat4)
```
Устанавливает вращение текста (Устанавливает повернутые вектора X,Y).
```lua
gfx.text3d.update_settings(id: int, preset: table)
```
Обновляет настройки отображения текста.

View File

@ -9,10 +9,14 @@
- [Свойства и методы UI элементов](scripting/ui.md)
- [Сущности и компоненты](scripting/ecs.md)
- [Библиотеки](#)
- [base64](scripting/builtins/libbase64.md)
- [bjson, json, toml](scripting/filesystem.md)
- [block](scripting/builtins/libblock.md)
- [cameras](scripting/builtins/libcameras.md)
- [entities](scripting/builtins/libentities.md)
- [file](scripting/builtins/libfile.md)
- [gfx.particles](particles.md#библиотека-gfxparticles)
- [gfx.text3d](3d-text.md#библиотека-gfxtext3d)
- [gui](scripting/builtins/libgui.md)
- [hud](scripting/builtins/libhud.md)
- [inventory](scripting/builtins/libinventory.md)

View File

@ -0,0 +1,11 @@
# Библиотека *base64*
Библиотека для base64 кодирования/декодирования.
```lua
-- Кодирует массив байт в base64 строку
base64.encode(bytes: table|ByteArray) -> str
-- Декодирует base64 строку в ByteArray или таблицу чисел, если второй аргумент установлен на true
base64.decode(base64string: str, [опционально]usetable: bool=false) -> table|ByteArray
```

View File

@ -1,3 +1,4 @@
display = "projected"
xray_opacity = 0.3
render_distance = 128
perspective = 0.0

View File

@ -248,7 +248,7 @@ function _rules.create(name, value, handler)
end
if _rules.get(name) == nil then
_rules.set(name, value)
else
elseif handler then
handler(_rules.get(name))
end
return handlerid
@ -265,11 +265,11 @@ end
function _rules.clear()
_rules.rules = {}
_rules.nextid = 1
_rules.create("allow-cheats", true)
end
function __vc_on_hud_open()
_rules.create("allow-cheats", true)
_rules.create("allow-content-access", hud._is_content_access(), function(value)
hud._set_content_access(value)
input.set_enabled("player.pick", value)

View File

@ -34,12 +34,11 @@ void TextsRenderer::renderNote(
util::sqr(preset.renderDistance / camera.zoom)) {
return;
}
// Projected notes are displayed on the front layer only
if ((preset.displayMode == NoteDisplayMode::PROJECTED) != projected) {
return;
}
float opacity = 1.0f;
if (frontLayer && preset.displayMode != NoteDisplayMode::PROJECTED) {
if (frontLayer) {
if (preset.xrayOpacity <= 0.0001f) {
return;
}
@ -81,15 +80,25 @@ void TextsRenderer::renderNote(
scale = scale2 * preset.perspective +
scale * (1.0f - preset.perspective);
}
auto projpos = camera.getProjView() * glm::vec4(pos, 1.0f);
pos = projpos;
if (pos.z < 0.0f) {
return;
if (frontLayer) {
auto projpos = camera.getProjView() * glm::vec4(pos, 1.0f);
pos = projpos;
if (pos.z < 0.0f) {
return;
}
pos /= projpos.w;
pos.z = 0;
xvec = {2.0f/Window::width*scale, 0, 0};
yvec = {0, 2.0f/Window::height*scale, 0};
} else {
auto matrix = camera.getProjView();
auto screenPos = matrix * glm::vec4(pos, 1.0f);
xvec = glm::vec3(2.0f/Window::width*scale, 0, 0);
yvec = glm::vec3(0, 2.0f/Window::height*scale, 0);
pos = screenPos / screenPos.w;
}
pos /= pos.z;
pos.z = 0;
xvec = {2.0f/Window::width*scale, 0, 0};
yvec = {0, 2.0f/Window::height*scale, 0};
}
auto color = preset.color;
batch.setColor(glm::vec4(color.r, color.g, color.b, color.a * opacity));
@ -119,16 +128,11 @@ void TextsRenderer::render(
renderNote(*note, context, camera, settings, hudVisible, frontLayer, false);
}
batch.flush();
if (frontLayer) {
shader.uniformMatrix(
"u_projview",
glm::mat4(1.0f)
);
for (const auto& [_, note] : notes) {
renderNote(*note, context, camera, settings, hudVisible, true, true);
}
batch.flush();
shader.uniformMatrix("u_projview", glm::mat4(1.0f));
for (const auto& [_, note] : notes) {
renderNote(*note, context, camera, settings, hudVisible, frontLayer, true);
}
batch.flush();
}
u64id_t TextsRenderer::add(std::unique_ptr<TextNote> note) {

View File

@ -20,9 +20,9 @@ struct NotePreset : public Serializable {
NoteDisplayMode displayMode = NoteDisplayMode::STATIC_BILLBOARD;
glm::vec4 color {1.0f};
float scale = 1.0f;
float renderDistance = 10.0f;
float renderDistance = 32.0f;
float xrayOpacity = 0.0f;
float perspective = 0.0f;
float perspective = 1.0f;
dv::value serialize() const override;
void deserialize(const dv::value& src) override;