add skeleton debug view
This commit is contained in:
@@ -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->use();
|
||||||
linesShader->uniformMatrix("u_projview", camera->getProjView());
|
linesShader->uniformMatrix("u_projview", camera->getProjView());
|
||||||
if (player->selection.vox.id != BLOCK_VOID) {
|
if (player->selection.vox.id != BLOCK_VOID) {
|
||||||
renderBlockSelection();
|
renderBlockSelection();
|
||||||
}
|
}
|
||||||
if (player->debug && showEntitiesDebug) {
|
if (player->debug && showEntitiesDebug) {
|
||||||
level->entities->renderDebug(*lineBatch, *frustumCulling);
|
level->entities->renderDebug(*lineBatch, *frustumCulling, pctx);
|
||||||
}
|
}
|
||||||
lineBatch->render();
|
lineBatch->render();
|
||||||
}
|
}
|
||||||
@@ -341,7 +343,7 @@ void WorldRenderer::draw(
|
|||||||
renderLevel(ctx, camera, settings, pause);
|
renderLevel(ctx, camera, settings, pause);
|
||||||
// Debug lines
|
// Debug lines
|
||||||
if (hudVisible){
|
if (hudVisible){
|
||||||
renderLines(camera, linesShader);
|
renderLines(camera, linesShader, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class WorldRenderer {
|
|||||||
/// @brief Render lines (selection and debug)
|
/// @brief Render lines (selection and debug)
|
||||||
/// @param camera active camera
|
/// @param camera active camera
|
||||||
/// @param linesShader shader used
|
/// @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)
|
/// @brief Render all debug lines (chunks borders, coord system guides)
|
||||||
/// @param context graphics context
|
/// @param context graphics context
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "../graphics/render/ModelBatch.hpp"
|
#include "../graphics/render/ModelBatch.hpp"
|
||||||
#include "../graphics/core/LineBatch.hpp"
|
#include "../graphics/core/LineBatch.hpp"
|
||||||
#include "../graphics/core/Model.hpp"
|
#include "../graphics/core/Model.hpp"
|
||||||
|
#include "../graphics/core/DrawContext.hpp"
|
||||||
#include "../maths/FrustumCulling.hpp"
|
#include "../maths/FrustumCulling.hpp"
|
||||||
#include "../objects/EntityDef.hpp"
|
#include "../objects/EntityDef.hpp"
|
||||||
#include "../objects/rigging.hpp"
|
#include "../objects/rigging.hpp"
|
||||||
@@ -443,7 +444,24 @@ void Entities::update() {
|
|||||||
scripting::on_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);
|
batch.lineWidth(1.0f);
|
||||||
auto view = registry.view<Transform, Rigidbody>();
|
auto view = registry.view<Transform, Rigidbody>();
|
||||||
for (auto [entity, transform, rigidbody] : view.each()) {
|
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));
|
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(
|
void Entities::render(
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ class LineBatch;
|
|||||||
class ModelBatch;
|
class ModelBatch;
|
||||||
class Frustum;
|
class Frustum;
|
||||||
class Entities;
|
class Entities;
|
||||||
|
class DrawContext;
|
||||||
|
|
||||||
namespace rigging {
|
namespace rigging {
|
||||||
struct Skeleton;
|
struct Skeleton;
|
||||||
@@ -184,7 +185,7 @@ public:
|
|||||||
void updatePhysics(float delta);
|
void updatePhysics(float delta);
|
||||||
void update();
|
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);
|
void render(Assets* assets, ModelBatch& batch, const Frustum& frustum, bool pause);
|
||||||
|
|
||||||
entityid_t spawn(
|
entityid_t spawn(
|
||||||
|
|||||||
@@ -128,6 +128,10 @@ namespace rigging {
|
|||||||
const std::string& getName() const {
|
const std::string& getName() const {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bone* getRoot() const {
|
||||||
|
return root.get();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user