From fe5404f6e7931b7f8182e81634da290c7437401a Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Tue, 6 May 2025 12:39:11 +0200 Subject: [PATCH] update --- Crafter.Graphics-Mesh.cppm | 45 ++++++++++++++++++++++++++++ Crafter.Graphics-VulkanPipeline.cppm | 2 +- project.json | 16 +++++----- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Crafter.Graphics-Mesh.cppm b/Crafter.Graphics-Mesh.cppm index f2c9ddb..9bcd996 100644 --- a/Crafter.Graphics-Mesh.cppm +++ b/Crafter.Graphics-Mesh.cppm @@ -7,6 +7,7 @@ module; export module Crafter.Graphics:Mesh; import Crafter.Component; +import Crafter.Math; import :VulkanBuffer; namespace Crafter { @@ -62,5 +63,49 @@ namespace Crafter { } return mesh; } + + static Mesh* FromHeightMapUV(float* heights, uint32_t sizeX, uint32_t sizeZ, float spacing) { + Mesh* mesh = new Mesh(sizeX*sizeZ, ((sizeX-1)*(sizeZ-1))*6); + for (float x = 0; x < sizeX; x++) + { + for (float z = 0; z < sizeZ; z++) + { + uint32_t xInt = static_cast(x); + uint32_t zInt = static_cast(z); + Vector pos((x * spacing) - ((sizeX*spacing) / 2.0f), heights[xInt * sizeX + zInt], (z * spacing) - ((sizeZ*spacing) / 2.0f)); + Vector uv(x / sizeX, z / sizeZ); + VertexType vertex; + vertex.x = pos.x; + vertex.y = pos.y; + vertex.z = pos.z; + vertex.w = 1.0f; + vertex.u = uv.x; + vertex.v = uv.y; + mesh->verticies.value[xInt * sizeX + zInt] = vertex; + } + } + + for (uint32_t x = 0; x < sizeX - 1; x++) + { + for (uint32_t z = 0; z < sizeZ - 1; z++) + { + uint32_t topLeftIndex = x * sizeZ + z; + uint32_t topRightIndex = topLeftIndex + 1; + uint32_t bottomLeftIndex = topLeftIndex + sizeZ; + uint32_t bottomRightIndex = bottomLeftIndex + 1; + + uint32_t index = (x * sizeX + z)*6; + + mesh->indicies.value[index] = topRightIndex; + mesh->indicies.value[index + 1] = bottomLeftIndex; + mesh->indicies.value[index + 2] = topLeftIndex; + + mesh->indicies.value[index + 3] = bottomRightIndex; + mesh->indicies.value[index + 4] = bottomLeftIndex; + mesh->indicies.value[index + 5] = topRightIndex; + } + } + return mesh; + } }; } diff --git a/Crafter.Graphics-VulkanPipeline.cppm b/Crafter.Graphics-VulkanPipeline.cppm index 1808287..4aa792c 100644 --- a/Crafter.Graphics-VulkanPipeline.cppm +++ b/Crafter.Graphics-VulkanPipeline.cppm @@ -33,7 +33,7 @@ namespace Crafter { } }; - export template + export template class VulkanPipeline { private: consteval static std::uint32_t GetUniqueDiscriptorCount() { diff --git a/project.json b/project.json index 00578f2..b9c83d0 100644 --- a/project.json +++ b/project.json @@ -42,20 +42,20 @@ "debug": true, "dependencies": [ { - "path":"/home/jorijn/repos/Crafter/Crafter.Event/project.json", + "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Event.git", "configuration":"debug" }, { - "path":"/home/jorijn/repos/Crafter/Crafter.Asset/project.json", - "configuration":"lib-debug" - }, - { - "path":"/home/jorijn/repos/Crafter/Crafter.Component/project.json", + "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Asset.git", "configuration":"debug" }, { - "path":"/home/jorijn/repos/Crafter/Crafter.Math/project.json", - "configuration":"debug-lib" + "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Component.git", + "configuration":"debug" + }, + { + "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.Math.git", + "configuration":"debug" } ] },