mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 13:01:49 +00:00
Merge pull request #830 from MihailRis/update-3d-text
feat: binding 3d text to entity
This commit is contained in:
commit
82e8cc991f
8 changed files with 71 additions and 5 deletions
|
|
@ -79,6 +79,14 @@ gfx.text3d.set_rotation(id: int, rotation: mat4)
|
||||||
|
|
||||||
Sets the text rotation (Sets the rotated vectors X,Y).
|
Sets the text rotation (Sets the rotated vectors X,Y).
|
||||||
|
|
||||||
|
```lua
|
||||||
|
gfx.text3d.get_entity(id: int) -> int
|
||||||
|
gfx.text3d.set_entity(id: int, entity: int)
|
||||||
|
```
|
||||||
|
|
||||||
|
Getter and setter for the entity to which the 3D text position is bound.
|
||||||
|
The position set via `gfx.text3d.set_pos` is then relative to the entity's position.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
gfx.text3d.update_settings(id: int, preset: table)
|
gfx.text3d.update_settings(id: int, preset: table)
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,14 @@ gfx.text3d.set_rotation(id: int, rotation: mat4)
|
||||||
|
|
||||||
Устанавливает вращение текста (Устанавливает повернутые вектора X,Y).
|
Устанавливает вращение текста (Устанавливает повернутые вектора X,Y).
|
||||||
|
|
||||||
|
```lua
|
||||||
|
gfx.text3d.get_entity(id: int) -> int
|
||||||
|
gfx.text3d.set_entity(id: int, entity: int)
|
||||||
|
```
|
||||||
|
|
||||||
|
Геттер и сеттер сущности, к позиции которой привязан 3D текст.
|
||||||
|
Позиция, устанавливаемая через `gfx.text3d.set_pos`, в таком случае, относительна позиции сущности.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
gfx.text3d.update_settings(id: int, preset: table)
|
gfx.text3d.update_settings(id: int, preset: table)
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,14 @@ void TextNote::setText(std::wstring_view text) {
|
||||||
this->text = text;
|
this->text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextNote::setEntity(entityid_t eid) {
|
||||||
|
this->entity = eid;
|
||||||
|
}
|
||||||
|
|
||||||
|
entityid_t TextNote::getEntity() const {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
const std::wstring& TextNote::getText() const {
|
const std::wstring& TextNote::getText() const {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "constants.hpp"
|
||||||
#include "presets/NotePreset.hpp"
|
#include "presets/NotePreset.hpp"
|
||||||
|
|
||||||
/// @brief 3D text instance
|
/// @brief 3D text instance
|
||||||
|
|
@ -7,6 +8,7 @@ class TextNote {
|
||||||
std::wstring text;
|
std::wstring text;
|
||||||
NotePreset preset;
|
NotePreset preset;
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
|
entityid_t entity = ENTITY_NONE;
|
||||||
|
|
||||||
glm::vec3 xAxis {1, 0, 0};
|
glm::vec3 xAxis {1, 0, 0};
|
||||||
glm::vec3 yAxis {0, 1, 0};
|
glm::vec3 yAxis {0, 1, 0};
|
||||||
|
|
@ -14,6 +16,8 @@ public:
|
||||||
TextNote(std::wstring text, NotePreset preset, glm::vec3 position);
|
TextNote(std::wstring text, NotePreset preset, glm::vec3 position);
|
||||||
|
|
||||||
void setText(std::wstring_view text);
|
void setText(std::wstring_view text);
|
||||||
|
void setEntity(entityid_t eid);
|
||||||
|
entityid_t getEntity() const;
|
||||||
|
|
||||||
const std::wstring& getText() const;
|
const std::wstring& getText() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,18 @@
|
||||||
#include "graphics/core/Shader.hpp"
|
#include "graphics/core/Shader.hpp"
|
||||||
#include "graphics/core/DrawContext.hpp"
|
#include "graphics/core/DrawContext.hpp"
|
||||||
#include "presets/NotePreset.hpp"
|
#include "presets/NotePreset.hpp"
|
||||||
|
#include "world/Level.hpp"
|
||||||
|
#include "objects/Entities.hpp"
|
||||||
|
#include "objects/Entity.hpp"
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
|
|
||||||
TextsRenderer::TextsRenderer(
|
TextsRenderer::TextsRenderer(
|
||||||
Batch3D& batch, const Assets& assets, const Frustum& frustum
|
const Level& level,
|
||||||
|
Batch3D& batch,
|
||||||
|
const Assets& assets,
|
||||||
|
const Frustum& frustum
|
||||||
)
|
)
|
||||||
: batch(batch), assets(assets), frustum(frustum) {
|
: level(level), batch(batch), assets(assets), frustum(frustum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextsRenderer::renderNote(
|
void TextsRenderer::renderNote(
|
||||||
|
|
@ -31,6 +37,13 @@ void TextsRenderer::renderNote(
|
||||||
const auto& preset = note.getPreset();
|
const auto& preset = note.getPreset();
|
||||||
auto pos = note.getPosition();
|
auto pos = note.getPosition();
|
||||||
|
|
||||||
|
entityid_t eid = note.getEntity();
|
||||||
|
if (eid != ENTITY_NONE) {
|
||||||
|
if (auto entity = level.entities->get(eid)) {
|
||||||
|
pos += entity->getTransform().displayPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (util::distance2(pos, camera.position) >
|
if (util::distance2(pos, camera.position) >
|
||||||
util::sqr(preset.renderDistance / camera.zoom)) {
|
util::sqr(preset.renderDistance / camera.zoom)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,10 @@ class Batch3D;
|
||||||
class Frustum;
|
class Frustum;
|
||||||
class TextNote;
|
class TextNote;
|
||||||
struct EngineSettings;
|
struct EngineSettings;
|
||||||
|
class Level;
|
||||||
|
|
||||||
class TextsRenderer {
|
class TextsRenderer {
|
||||||
|
const Level& level;
|
||||||
Batch3D& batch;
|
Batch3D& batch;
|
||||||
const Assets& assets;
|
const Assets& assets;
|
||||||
const Frustum& frustum;
|
const Frustum& frustum;
|
||||||
|
|
@ -31,7 +33,12 @@ class TextsRenderer {
|
||||||
bool projected
|
bool projected
|
||||||
);
|
);
|
||||||
public:
|
public:
|
||||||
TextsRenderer(Batch3D& batch, const Assets& assets, const Frustum& frustum);
|
TextsRenderer(
|
||||||
|
const Level& level,
|
||||||
|
Batch3D& batch,
|
||||||
|
const Assets& assets,
|
||||||
|
const Frustum& frustum
|
||||||
|
);
|
||||||
|
|
||||||
void render(
|
void render(
|
||||||
const DrawContext& context,
|
const DrawContext& context,
|
||||||
|
|
|
||||||
|
|
@ -91,9 +91,11 @@ WorldRenderer::WorldRenderer(
|
||||||
assets, level, *player.chunks, &engine.getSettings().graphics
|
assets, level, *player.chunks, &engine.getSettings().graphics
|
||||||
)),
|
)),
|
||||||
particles(std::make_unique<ParticlesRenderer>(
|
particles(std::make_unique<ParticlesRenderer>(
|
||||||
assets, level, *player.chunks, engine.getSettings().graphics
|
assets, level, *player.chunks, engine.getSettings().graphics
|
||||||
|
)),
|
||||||
|
texts(std::make_unique<TextsRenderer>(
|
||||||
|
level, *batch3d, assets, *frustumCulling
|
||||||
)),
|
)),
|
||||||
texts(std::make_unique<TextsRenderer>(*batch3d, assets, *frustumCulling)),
|
|
||||||
blockWraps(std::make_unique<BlockWrapsRenderer>(
|
blockWraps(std::make_unique<BlockWrapsRenderer>(
|
||||||
assets, level.content, *player.chunks
|
assets, level.content, *player.chunks
|
||||||
)) {
|
)) {
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,20 @@ static int l_set_rotation(lua::State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_get_entity(lua::State* L) {
|
||||||
|
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
|
||||||
|
return lua::pushinteger(L, note->getEntity());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_set_entity(lua::State* L) {
|
||||||
|
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
|
||||||
|
note->setEntity(lua::touinteger(L, 2));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg text3dlib[] = {
|
const luaL_Reg text3dlib[] = {
|
||||||
{"show", wrap_hud<l_show>},
|
{"show", wrap_hud<l_show>},
|
||||||
{"hide", wrap_hud<l_hide>},
|
{"hide", wrap_hud<l_hide>},
|
||||||
|
|
@ -108,5 +122,7 @@ const luaL_Reg text3dlib[] = {
|
||||||
{"set_axis_y", wrap_hud<l_set_axis_y>},
|
{"set_axis_y", wrap_hud<l_set_axis_y>},
|
||||||
{"set_rotation", wrap_hud<l_set_rotation>},
|
{"set_rotation", wrap_hud<l_set_rotation>},
|
||||||
{"update_settings", wrap_hud<l_update_settings>},
|
{"update_settings", wrap_hud<l_update_settings>},
|
||||||
|
{"get_entity", wrap_hud<l_get_entity>},
|
||||||
|
{"set_entity", wrap_hud<l_set_entity>},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue