diff --git a/src/graphics/render/WorldRenderer.cpp b/src/graphics/render/WorldRenderer.cpp index ef1516ea..42d5f354 100644 --- a/src/graphics/render/WorldRenderer.cpp +++ b/src/graphics/render/WorldRenderer.cpp @@ -240,14 +240,16 @@ void WorldRenderer::renderBlockSelection() { } } -void WorldRenderer::renderLines(Camera* camera, Shader* linesShader) { +void WorldRenderer::renderLines( + Camera* camera, Shader* linesShader, const DrawContext& pctx +) { linesShader->use(); linesShader->uniformMatrix("u_projview", camera->getProjView()); if (player->selection.vox.id != BLOCK_VOID) { renderBlockSelection(); } if (player->debug && showEntitiesDebug) { - level->entities->renderDebug(*lineBatch, *frustumCulling); + level->entities->renderDebug(*lineBatch, *frustumCulling, pctx); } lineBatch->render(); } @@ -341,7 +343,7 @@ void WorldRenderer::draw( renderLevel(ctx, camera, settings, pause); // Debug lines if (hudVisible){ - renderLines(camera, linesShader); + renderLines(camera, linesShader, ctx); } } diff --git a/src/graphics/render/WorldRenderer.hpp b/src/graphics/render/WorldRenderer.hpp index 013f37df..29d4bfe4 100644 --- a/src/graphics/render/WorldRenderer.hpp +++ b/src/graphics/render/WorldRenderer.hpp @@ -51,7 +51,7 @@ class WorldRenderer { /// @brief Render lines (selection and debug) /// @param camera active camera /// @param linesShader shader used - void renderLines(Camera* camera, Shader* linesShader); + void renderLines(Camera* camera, Shader* linesShader, const DrawContext& pctx); /// @brief Render all debug lines (chunks borders, coord system guides) /// @param context graphics context diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index 59905c3c..adc979df 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -11,6 +11,7 @@ #include "../graphics/render/ModelBatch.hpp" #include "../graphics/core/LineBatch.hpp" #include "../graphics/core/Model.hpp" +#include "../graphics/core/DrawContext.hpp" #include "../maths/FrustumCulling.hpp" #include "../objects/EntityDef.hpp" #include "../objects/rigging.hpp" @@ -443,7 +444,24 @@ void Entities::update() { scripting::on_entities_update(); } -void Entities::renderDebug(LineBatch& batch, const Frustum& frustum) { +static void debug_render_skeleton( + LineBatch& batch, + const rigging::Bone* bone, + const rigging::Skeleton& skeleton +) { + size_t pindex = bone->getIndex(); + for (auto& sub : bone->getSubnodes()) { + size_t sindex = sub->getIndex(); + batch.line(glm::vec3(skeleton.calculated.matrices[pindex] * glm::vec4(0,0,0,1)), + glm::vec3(skeleton.calculated.matrices[sindex] * glm::vec4(0,0,0,1)), + glm::vec4(0,0.5f,0,1)); + debug_render_skeleton(batch, sub.get(), skeleton); + } +} + +void Entities::renderDebug( + LineBatch& batch, const Frustum& frustum, const DrawContext& pctx +) { batch.lineWidth(1.0f); auto view = registry.view(); for (auto [entity, transform, rigidbody] : view.each()) { @@ -464,6 +482,26 @@ void Entities::renderDebug(LineBatch& batch, const Frustum& frustum) { glm::vec4(1.0f, 1.0f, 0.0f, 1.0f)); } } + batch.render(); + { + auto view = registry.view(); + auto ctx = pctx.sub(); + ctx.setDepthTest(false); + ctx.setDepthMask(false); + batch.lineWidth(2); + for (auto [entity, transform, skeleton] : view.each()) { + auto config = skeleton.config; + const auto& pos = transform.pos; + const auto& size = transform.size; + if (!frustum.isBoxVisible(pos-size, pos+size)) { + continue; + } + auto bone = config->getRoot(); + debug_render_skeleton(batch, bone, skeleton); + } + batch.render(); + batch.lineWidth(1); + } } void Entities::render( diff --git a/src/objects/Entities.hpp b/src/objects/Entities.hpp index 9adf6358..6892a7f5 100644 --- a/src/objects/Entities.hpp +++ b/src/objects/Entities.hpp @@ -100,6 +100,7 @@ class LineBatch; class ModelBatch; class Frustum; class Entities; +class DrawContext; namespace rigging { struct Skeleton; @@ -184,7 +185,7 @@ public: void updatePhysics(float delta); void update(); - void renderDebug(LineBatch& batch, const Frustum& frustum); + void renderDebug(LineBatch& batch, const Frustum& frustum, const DrawContext& ctx); void render(Assets* assets, ModelBatch& batch, const Frustum& frustum, bool pause); entityid_t spawn( diff --git a/src/objects/rigging.hpp b/src/objects/rigging.hpp index b6ca3e04..b816bdc9 100644 --- a/src/objects/rigging.hpp +++ b/src/objects/rigging.hpp @@ -128,6 +128,10 @@ namespace rigging { const std::string& getName() const { return name; } + + Bone* getRoot() const { + return root.get(); + } }; };