heightmap previews

This commit is contained in:
Till Wübbers
2025-06-13 13:10:31 +02:00
parent a936222711
commit 59b8eea3a7
4 changed files with 61 additions and 7 deletions

View File

@@ -400,7 +400,7 @@ namespace Game
auto& staticCard = isValid ? staticCards[card.RefCard.Idx] : staticCards[0]; auto& staticCard = isValid ? staticCards[card.RefCard.Idx] : staticCards[0];
// World Tile // World Tile
tile.EData.Visible = IsActive; tile.EData.Visible = true;
tile.EData.ModelH = staticCard.BaseModelHandle; tile.EData.ModelH = staticCard.BaseModelHandle;
tile.EData.TextureHandle = staticCard.ModelTextureHandle; tile.EData.TextureHandle = staticCard.ModelTextureHandle;
@@ -416,7 +416,7 @@ namespace Game
{ {
cardPos = {x * Puzzle::Config::CardScaleWorld, -5.0f, y * Puzzle::Config::CardScaleWorld}; cardPos = {x * Puzzle::Config::CardScaleWorld, -5.0f, y * Puzzle::Config::CardScaleWorld};
} }
tile.EData.Transform.Position = cardPos; tile.EData.Transform.Position = cardPos + WorldPosition;
bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f); bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f);
// Covers // Covers

View File

@@ -2,6 +2,7 @@
#include "Global.h" #include "Global.h"
#include "Log.h" #include "Log.h"
#include "Mesh.h" #include "Mesh.h"
#include "bgfx/bgfx.h"
#include "bx/bx.h" #include "bx/bx.h"
#include "bx/error.h" #include "bx/error.h"
#include "bx/file.h" #include "bx/file.h"
@@ -11,6 +12,7 @@
#include "rendering/Rendering.h" #include "rendering/Rendering.h"
#include "Instance.h" #include "Instance.h"
#include <cstdint>
#define TINYGLTF_IMPLEMENTATION #define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
@@ -21,6 +23,7 @@ namespace Game
{ {
bool LoadMesh(Model& mesh, const char* path, bool isBinary) bool LoadMesh(Model& mesh, const char* path, bool isBinary)
{ {
bx::strCopy(mesh.Name, sizeof(mesh.Name), path);
mesh.VertLayout.begin() mesh.VertLayout.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float) .add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::Normal, 3, bgfx::AttribType::Float) .add(bgfx::Attrib::Normal, 3, bgfx::AttribType::Float)
@@ -94,6 +97,17 @@ namespace Game
mesh.VertexBuffer = bgfx::createVertexBuffer(vbMem, mesh.VertLayout); mesh.VertexBuffer = bgfx::createVertexBuffer(vbMem, mesh.VertLayout);
} }
for (uint32_t y = 0; y < HeightMap::Height; ++y)
{
for (uint32_t x = 0; x < HeightMap::Width; ++x)
{
mesh.Height.Values[y * HeightMap::Width + x] = (uint8_t)(((float)x / HeightMap::Width) * UINT8_MAX);
}
}
const bgfx::Memory* mem = bgfx::makeRef(&mesh.Height.Values[0], sizeof(mesh.Height.Values));
mesh.HeightMapTexture =
bgfx::createTexture2D(HeightMap::Width, HeightMap::Height, false, 1, bgfx::TextureFormat::R8, 0, mem);
for (auto& node : model.nodes) for (auto& node : model.nodes)
{ {
if (bx::strFindI(node.name.c_str(), "_slot_").getLength() > 0) if (bx::strFindI(node.name.c_str(), "_slot_").getLength() > 0)

View File

@@ -7,9 +7,11 @@
#include "Puzzle.h" #include "Puzzle.h"
#include "Tools.h" #include "Tools.h"
#include "bgfx/bgfx.h"
#include "bx/filepath.h" #include "bx/filepath.h"
#include "bx/string.h" #include "bx/string.h"
#include "bx/timer.h" #include "bx/timer.h"
#include "rendering/Rendering.h"
#include <imgui.h> #include <imgui.h>
#include <tracy/Tracy.hpp> #include <tracy/Tracy.hpp>
@@ -269,10 +271,6 @@ namespace Tools
{ {
ImGui::TextColored({0.9f, 0.2f, 0.2f, 1.0f}, "Shader load Failiure!"); ImGui::TextColored({0.9f, 0.2f, 0.2f, 1.0f}, "Shader load Failiure!");
} }
if (ImGui::Button("Reload Meshes"))
{
LoadModels(rendering.Models, rendering.ModelCount);
}
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Reload Level")) if (ImGui::Button("Reload Level"))
{ {
@@ -395,6 +393,33 @@ namespace Tools
ImGui::End(); ImGui::End();
} }
void RenderModelsUI(Game::GameRendering& rendering)
{
if (ImGui::Begin("Models"))
{
if (ImGui::Button("Reload"))
{
LoadModels(rendering.Models, rendering.ModelCount);
}
for (int32_t i = 0; i < rendering.ModelCount; ++i)
{
auto& mdl = rendering.Models[i];
if (bgfx::isValid(mdl.HeightMapTexture))
{
ImGui::Text("%s", mdl.Name);
ImGui::Image(mdl.HeightMapTexture.idx,
ImVec2{(float)Game::HeightMap::Height, (float)Game::HeightMap::Width});
}
else
{
ImGui::Text("Invalid Handle!");
}
ImGui::Spacing();
}
}
ImGui::End();
}
void RenderPuzzlesUI() void RenderPuzzlesUI()
{ {
auto& debug = Game::GetInstance().DebugData; auto& debug = Game::GetInstance().DebugData;
@@ -405,6 +430,7 @@ namespace Tools
char nameBuf[64]{0}; char nameBuf[64]{0};
for (int32_t i = 0; i < BX_COUNTOF(level.Puzzles); ++i) for (int32_t i = 0; i < BX_COUNTOF(level.Puzzles); ++i)
{ {
ImGui::PushID(i);
auto& puzzleData = level.Puzzles[i].Data; auto& puzzleData = level.Puzzles[i].Data;
bool isSelected = debug.SelectedDebugLevel == i; bool isSelected = debug.SelectedDebugLevel == i;
@@ -414,6 +440,9 @@ namespace Tools
{ {
debug.SelectedDebugLevel = isSelected ? UINT16_MAX : i; debug.SelectedDebugLevel = isSelected ? UINT16_MAX : i;
} }
ImGui::DragFloat3("Pos", &level.Puzzles[i].WorldPosition.x);
ImGui::PopID();
ImGui::PopID(); ImGui::PopID();
} }
} }
@@ -593,7 +622,7 @@ namespace Tools
ImGui::Text("FPS: %.0f", 1.0 / time.Delta); ImGui::Text("FPS: %.0f", 1.0 / time.Delta);
constexpr ImVec2 FpsPlotSize{200, 60}; constexpr ImVec2 FpsPlotSize{200, 60};
if (ImGui::BeginChild("FpsPlot", FpsPlotSize)) if (ImGui::BeginChild("FpsPlot", FpsPlotSize, 0, ImGuiWindowFlags_NoInputs))
{ {
auto& drawList = *ImGui::GetWindowDrawList(); auto& drawList = *ImGui::GetWindowDrawList();
ImVec2 pos = ImGui::GetWindowPos(); ImVec2 pos = ImGui::GetWindowPos();
@@ -659,6 +688,7 @@ namespace Tools
RenderLogUI(); RenderLogUI();
RenderRenderSettingsUI(rendering); RenderRenderSettingsUI(rendering);
RenderTexturesUI(rendering); RenderTexturesUI(rendering);
RenderModelsUI(rendering);
RenderPuzzlesUI(); RenderPuzzlesUI();
RenderCardsUI(rendering); RenderCardsUI(rendering);
RenderEntitiesUI(); RenderEntitiesUI();

View File

@@ -40,6 +40,13 @@ namespace Game
char Name[MaxSocketNameLength]{}; char Name[MaxSocketNameLength]{};
}; };
struct HeightMap
{
static constexpr uint32_t Width = 64;
static constexpr uint32_t Height = 64;
uint8_t Values[Width * Height]{0};
};
struct Model struct Model
{ {
static constexpr uint16_t MaxSocketCount = 16; static constexpr uint16_t MaxSocketCount = 16;
@@ -49,6 +56,9 @@ namespace Game
Gen::ModelHandle Handle; Gen::ModelHandle Handle;
uint16_t SocketCount = 0; uint16_t SocketCount = 0;
ModelSocket Sockets[MaxSocketCount]; ModelSocket Sockets[MaxSocketCount];
HeightMap Height;
bgfx::TextureHandle HeightMapTexture = {bgfx::kInvalidHandle};
char Name[128]{0};
}; };
struct Material struct Material