Added plane

This commit is contained in:
2024-12-06 10:48:00 -06:00
parent e6672945ae
commit 9d91fa6435
10 changed files with 196 additions and 35 deletions

View File

@@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
MeshComponent.cpp
CubeMeshComponent.cpp
QuadMeshComponent.cpp
PlaneMeshComponent.cpp
)

View File

@@ -0,0 +1,68 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PlaneMeshComponent.hpp"
#include "display/mesh/PlaneMesh.hpp"
#include "util/JSON.hpp"
using namespace Dawn;
void PlaneMeshComponent::meshLoad(std::shared_ptr<SceneLoadContext> ctx) {
if(ctx->data.contains("columns")) {
columns = ctx->data["columns"];
assertTrue(columns > 0, "Columns must be greater than 0.");
} else {
columns = 10;
}
if(ctx->data.contains("rows")) {
rows = ctx->data["rows"];
assertTrue(rows > 0, "Rows must be greater than 0.");
} else {
rows = columns;
}
if(ctx->data.contains("cells")) {
assertTrue(
ctx->data["cells"].type() == json::value_t::array,
"Cells must be an array."
);
assertTrue(
ctx->data["cells"].size() == 2,
"Cells must be an array of 2 integers."
);
columns = ctx->data["cells"][0];
rows = ctx->data["cells"][1];
assertTrue(columns > 0, "Columns must be greater than 0.");
assertTrue(rows > 0, "Rows must be greater than 0.");
}
if(ctx->data.contains("planeSize")) {
planeSize = JSON::vec2(ctx->data["planeSize"]);
assertTrue(planeSize.x > 0.0f, "Plane size x must be greater than 0.");
assertTrue(planeSize.y > 0.0f, "Plane size y must be greater than 0.");
} else if(ctx->data.contains("size")) {
planeSize = JSON::vec2(ctx->data["size"]);
assertTrue(planeSize.x > 0.0f, "Size x must be greater than 0.");
assertTrue(planeSize.y > 0.0f, "Size y must be greater than 0.");
} else {
planeSize = glm::vec2(10.0f, 10.0f);
}
if(ctx->data.contains("uv")) {
uv = JSON::vec4(ctx->data["uv"]);
} else {
uv = glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);
}
}
void PlaneMeshComponent::meshBuffer(std::shared_ptr<Mesh> mesh) {
PlaneMesh::buffer(
mesh,
planeSize,
columns, rows,
uv
);
}

View File

@@ -0,0 +1,23 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "MeshComponent.hpp"
namespace Dawn {
class PlaneMeshComponent final : public MeshComponent {
protected:
int32_t columns;
int32_t rows;
glm::vec2 planeSize;
glm::vec4 uv;
void meshLoad(std::shared_ptr<SceneLoadContext> ctx) override;
void meshBuffer(std::shared_ptr<Mesh> mesh) override;
public:
};
}