From 715d4879fdd096ac82367984fdb22117d48737a4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Feb 2023 02:26:06 +0000 Subject: First cut of the model factory and the hardcoded Brush 47 model Requires temporary change to the fragment shader to hardcode some visible colour to the model --- assetFactory/cylinder.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 assetFactory/cylinder.cpp (limited to 'assetFactory/cylinder.cpp') diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp new file mode 100644 index 0000000..66d456d --- /dev/null +++ b/assetFactory/cylinder.cpp @@ -0,0 +1,43 @@ +#include "cylinder.h" +#include "assetFactoryConfig.h" +#include "maths.h" + +Cylinder::CreatedFaces +Cylinder::createMesh(ModelFactoryMesh & mesh, const Mutation::Matrix & mutation) const +{ + const glm::vec2 scale {std::accumulate(&mutation[0][0], &mutation[0][3], 0.f), + std::accumulate(&mutation[1][0], &mutation[1][3], 0.f)}; + const unsigned int P = static_cast(std::round(15.F * std::sqrt(glm::length(scale)))); + std::vector bottom(P), top(P); + std::generate_n(bottom.begin(), P, [a = 0.f, step = two_pi / static_cast(P), &mesh, &mutation]() mutable { + const auto xy = sincosf(a += step) * .5F; + const auto xyz = (xy ^ 0) % mutation; + return mesh.add_vertex({xyz.x, xyz.y, xyz.z}); + }); + std::generate_n(top.begin(), P, [a = 0.f, step = two_pi / static_cast(P), &mesh, &mutation]() mutable { + const auto xy = sincosf(a -= step) * .5F; + const auto xyz = (xy ^ 1) % mutation; + return mesh.add_vertex({xyz.x, xyz.y, xyz.z}); + }); + CreatedFaces surface; + std::generate_n(std::inserter(surface, surface.end()), P, + [a = 0.f, step = two_pi / static_cast(P), &mesh, &mutation]() mutable { + const auto xy1 = sincosf(a) * .5F; + const auto xy2 = sincosf(a -= step) * .5F; + const auto xyz1b = (xy1 ^ 0) % mutation; + const auto xyz2b = (xy2 ^ 0) % mutation; + const auto xyz1t = (xy1 ^ 1) % mutation; + const auto xyz2t = (xy2 ^ 1) % mutation; + return std::make_pair(std::string {"edge"}, + mesh.add_face({ + mesh.add_vertex({xyz1b.x, xyz1b.y, xyz1b.z}), + mesh.add_vertex({xyz2b.x, xyz2b.y, xyz2b.z}), + mesh.add_vertex({xyz2t.x, xyz2t.y, xyz2t.z}), + mesh.add_vertex({xyz1t.x, xyz1t.y, xyz1t.z}), + })); + }); + surface.emplace("bottom", mesh.add_face(bottom)); + surface.emplace("top", mesh.add_face(top)); + + return surface; +} -- cgit v1.2.3 From c22c676dfee583bd48e1f962378f580f8310838b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 16 Feb 2023 23:54:22 +0000 Subject: Refactor so ModelFactoryMesh can define the smooth property on faces --- assetFactory/cylinder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'assetFactory/cylinder.cpp') diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp index 66d456d..83cf035 100644 --- a/assetFactory/cylinder.cpp +++ b/assetFactory/cylinder.cpp @@ -1,6 +1,6 @@ #include "cylinder.h" -#include "assetFactoryConfig.h" #include "maths.h" +#include "modelFactoryMesh.h" Cylinder::CreatedFaces Cylinder::createMesh(ModelFactoryMesh & mesh, const Mutation::Matrix & mutation) const -- cgit v1.2.3 From 88d5b474f3ab1c021612b0730f1b8d327a7a32db Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 16 Feb 2023 23:56:10 +0000 Subject: Add support for smooth faces --- assetFactory/cylinder.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'assetFactory/cylinder.cpp') diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp index 83cf035..d51dc37 100644 --- a/assetFactory/cylinder.cpp +++ b/assetFactory/cylinder.cpp @@ -36,6 +36,9 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, const Mutation::Matrix & mutation) mesh.add_vertex({xyz1t.x, xyz1t.y, xyz1t.z}), })); }); + for (const auto & [name, face] : surface) { + mesh.property(mesh.smoothFaceProperty, face) = true; + } surface.emplace("bottom", mesh.add_face(bottom)); surface.emplace("top", mesh.add_face(top)); -- cgit v1.2.3 From f6f085d3744990a6e80927aa17f4c5d77456d4f9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Feb 2023 03:10:25 +0000 Subject: Primitives add named faces --- assetFactory/cylinder.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'assetFactory/cylinder.cpp') diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp index d51dc37..cf0dbfb 100644 --- a/assetFactory/cylinder.cpp +++ b/assetFactory/cylinder.cpp @@ -28,19 +28,19 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, const Mutation::Matrix & mutation) const auto xyz2b = (xy2 ^ 0) % mutation; const auto xyz1t = (xy1 ^ 1) % mutation; const auto xyz2t = (xy2 ^ 1) % mutation; - return std::make_pair(std::string {"edge"}, - mesh.add_face({ + return mesh.add_namedFace("edge", + { mesh.add_vertex({xyz1b.x, xyz1b.y, xyz1b.z}), mesh.add_vertex({xyz2b.x, xyz2b.y, xyz2b.z}), mesh.add_vertex({xyz2t.x, xyz2t.y, xyz2t.z}), mesh.add_vertex({xyz1t.x, xyz1t.y, xyz1t.z}), - })); + }); }); for (const auto & [name, face] : surface) { mesh.property(mesh.smoothFaceProperty, face) = true; } - surface.emplace("bottom", mesh.add_face(bottom)); - surface.emplace("top", mesh.add_face(top)); + surface.insert(mesh.add_namedFace("bottom", bottom)); + surface.insert(mesh.add_namedFace("top", top)); return surface; } -- cgit v1.2.3