add gfx.text3d.spawn(...)
This commit is contained in:
parent
c4170c07c5
commit
eb5715eba9
@ -24,4 +24,10 @@ function on_hud_open()
|
||||
local velocity = vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL))
|
||||
drop.rigidbody:set_vel(velocity)
|
||||
end)
|
||||
|
||||
gfx.text3d.spawn({0.5, 99.5, 0.0015}, "Segmentation fault", {
|
||||
scale = 0.005,
|
||||
color = {0, 0, 0, 1},
|
||||
displayMode = "static_billboard"
|
||||
})
|
||||
end
|
||||
|
||||
@ -78,25 +78,20 @@ void TextsRenderer::renderTexts(
|
||||
bool hudVisible,
|
||||
bool frontLayer
|
||||
) {
|
||||
std::vector<TextNote> notes;
|
||||
NotePreset preset;
|
||||
preset.displayMode = NoteDisplayMode::STATIC_BILLBOARD;
|
||||
preset.color = glm::vec4(0, 0, 0, 1);
|
||||
preset.scale = 0.005f;
|
||||
|
||||
notes.emplace_back(
|
||||
L"Segmentation fault",
|
||||
std::move(preset),
|
||||
glm::vec3(0.5f, 99.5f, 0.0015f)
|
||||
);
|
||||
auto& shader = assets.require<Shader>("ui3d");
|
||||
|
||||
shader.use();
|
||||
shader.uniformMatrix("u_projview", camera.getProjView());
|
||||
shader.uniformMatrix("u_apply", glm::mat4(1.0f));
|
||||
batch.begin();
|
||||
for (const auto& note : notes) {
|
||||
renderText(note, context, camera, settings, hudVisible);
|
||||
for (const auto& [id, note] : notes) {
|
||||
renderText(*note, context, camera, settings, hudVisible);
|
||||
}
|
||||
batch.flush();
|
||||
}
|
||||
|
||||
u64id_t TextsRenderer::add(std::unique_ptr<TextNote> note) {
|
||||
u64id_t uid = nextNote++;
|
||||
notes[uid] = std::move(note);
|
||||
return uid;
|
||||
}
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
|
||||
class DrawContext;
|
||||
class Camera;
|
||||
class Assets;
|
||||
@ -13,6 +18,9 @@ class TextsRenderer {
|
||||
const Assets& assets;
|
||||
const Frustum& frustum;
|
||||
|
||||
std::unordered_map<u64id_t, std::unique_ptr<TextNote>> notes;
|
||||
u64id_t nextNote = 1;
|
||||
|
||||
void renderText(
|
||||
const TextNote& note,
|
||||
const DrawContext& context,
|
||||
@ -30,4 +38,6 @@ public:
|
||||
bool hudVisible,
|
||||
bool frontLayer
|
||||
);
|
||||
|
||||
u64id_t add(std::unique_ptr<TextNote> note);
|
||||
};
|
||||
|
||||
@ -39,7 +39,6 @@ class WorldRenderer {
|
||||
std::unique_ptr<LineBatch> lineBatch;
|
||||
std::unique_ptr<Batch3D> batch3d;
|
||||
std::unique_ptr<ChunksRenderer> chunks;
|
||||
std::unique_ptr<TextsRenderer> texts;
|
||||
std::unique_ptr<GuidesRenderer> guides;
|
||||
std::unique_ptr<Skybox> skybox;
|
||||
std::unique_ptr<ModelBatch> modelBatch;
|
||||
@ -67,6 +66,7 @@ class WorldRenderer {
|
||||
float fogFactor
|
||||
);
|
||||
public:
|
||||
std::unique_ptr<TextsRenderer> texts;
|
||||
std::unique_ptr<ParticlesRenderer> particles;
|
||||
|
||||
static bool showChunkBorders;
|
||||
|
||||
@ -33,7 +33,8 @@ extern const luaL_Reg mat4lib[];
|
||||
extern const luaL_Reg packlib[];
|
||||
extern const luaL_Reg particleslib[];
|
||||
extern const luaL_Reg playerlib[];
|
||||
extern const luaL_Reg quatlib[]; // quat.cpp
|
||||
extern const luaL_Reg quatlib[];
|
||||
extern const luaL_Reg text3dlib[];
|
||||
extern const luaL_Reg timelib[];
|
||||
extern const luaL_Reg tomllib[];
|
||||
extern const luaL_Reg utf8lib[];
|
||||
|
||||
29
src/logic/scripting/lua/libs/libtext3d.cpp
Normal file
29
src/logic/scripting/lua/libs/libtext3d.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "api_lua.hpp"
|
||||
|
||||
#include "logic/scripting/scripting_hud.hpp"
|
||||
#include "graphics/render/WorldRenderer.hpp"
|
||||
#include "graphics/render/TextsRenderer.hpp"
|
||||
#include "graphics/render/TextNote.hpp"
|
||||
#include "engine.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
static int l_spawn(lua::State* L) {
|
||||
auto position = lua::tovec3(L, 1);
|
||||
auto text = lua::require_wstring(L, 2);
|
||||
auto preset = lua::tovalue(L, 3);
|
||||
auto extension = lua::tovalue(L, 4);
|
||||
|
||||
NotePreset notePreset {};
|
||||
notePreset.deserialize(preset);
|
||||
if (extension != nullptr) {
|
||||
notePreset.deserialize(extension);
|
||||
}
|
||||
auto note = std::make_unique<TextNote>(text, notePreset, position);
|
||||
return lua::pushinteger(L, renderer->texts->add(std::move(note)));
|
||||
}
|
||||
|
||||
const luaL_Reg text3dlib[] = {
|
||||
{"spawn", lua::wrap<l_spawn>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
@ -25,6 +25,7 @@ void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) {
|
||||
|
||||
lua::openlib(L, "hud", hudlib);
|
||||
lua::openlib(L, "gfx", "particles", particleslib);
|
||||
lua::openlib(L, "gfx", "text3d", text3dlib);
|
||||
|
||||
if (lua::getglobal(L, "__vc_create_hud_rules")) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user