Added plane
This commit is contained in:
@@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
MeshComponent.cpp
|
||||
CubeMeshComponent.cpp
|
||||
QuadMeshComponent.cpp
|
||||
PlaneMeshComponent.cpp
|
||||
)
|
68
src/dawn/component/display/mesh/PlaneMeshComponent.cpp
Normal file
68
src/dawn/component/display/mesh/PlaneMeshComponent.cpp
Normal 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
|
||||
);
|
||||
}
|
23
src/dawn/component/display/mesh/PlaneMeshComponent.hpp
Normal file
23
src/dawn/component/display/mesh/PlaneMeshComponent.hpp
Normal 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:
|
||||
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user