add skeleton debug view

This commit is contained in:
MihailRis 2024-07-21 14:52:16 +03:00
parent c63e19e87b
commit cf12338a32
5 changed files with 51 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -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<Transform, Rigidbody>();
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<Transform, rigging::Skeleton>();
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(

View File

@ -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(

View File

@ -128,6 +128,10 @@ namespace rigging {
const std::string& getName() const {
return name;
}
Bone* getRoot() const {
return root.get();
}
};
};