update
This commit is contained in:
parent
cb848e7109
commit
fe5404f6e7
3 changed files with 54 additions and 9 deletions
|
|
@ -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<uint32_t>(x);
|
||||
uint32_t zInt = static_cast<uint32_t>(z);
|
||||
Vector<float, 3> pos((x * spacing) - ((sizeX*spacing) / 2.0f), heights[xInt * sizeX + zInt], (z * spacing) - ((sizeZ*spacing) / 2.0f));
|
||||
Vector<float, 2> 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue