Cogs.Core
LoftedCrossSectionsComponent.h
1#pragma once
2
3#include "Resources/VertexFormats.h"
4
5#include "Foundation/ComponentModel/Component.h"
6#include "Foundation/Geometry/BoundingBox.hpp"
7#include "Foundation/Geometry/Glm.hpp"
8#include "Foundation/Logging/Logger.h"
9
10#include <vector>
11
12namespace Cogs
13{
14 namespace Core
15 {
17 {
18 enum struct Shape : int
19 {
20 Hollow,
21 Solid,
22 Shell
23 };
24
25 bool open = false;
26 bool screenAligned = false;
27 LoftedCrossSectionsComponent::Shape shape = Shape::Hollow;
28 int samples = 0;
29 int crossSections = 0;
30 bool hollow = false;
31 bool doubleSeamVertices = false;
32 bool hasData = false;
33 std::vector<PositionNormalVertex> vertices_vn;
34 std::vector<PositionNormalTexVertex> vertices_vnt;
35 std::vector<glm::vec3> spine;
36 Geometry::BoundingBox boundingBox;
37 bool boundingBoxSet = false;
38 bool visibility = false;
39
40 template<typename Arg0, typename Arg1>
41 bool set(Arg0&& vertices,
42 Arg1&& spine,
43 LoftedCrossSectionsComponent::Shape shape,
44 int samples,
45 int crossSections,
46 bool doubleSeamVertices)
47 {
48
49 if ((samples < 3) || (crossSections < 2) || (spine.size() != static_cast<size_t>(crossSections))) {
50 Cogs::Logging::Log log = Cogs::Logging::getLogger("Cogs.Core.LoftedCrossSectionsData.set");
51 LOG_ERROR(log, "Parameter sanity tests failed.");
52 this->visibility = false;
53 this->hasData = false;
54 return false;
55 }
56
57 this->shape = shape;
58 this->samples = samples;
59 this->crossSections = crossSections;
60 this->doubleSeamVertices = doubleSeamVertices;
61 switch (this->shape) {
62 case LoftedCrossSectionsComponent::Shape::Hollow:
63 this->hollow = true;
64 break;
65 case LoftedCrossSectionsComponent::Shape::Solid:
66 this->hollow = false;
67 break;
68 case LoftedCrossSectionsComponent::Shape::Shell:
69 break;
70 }
71 setVertices<Arg0>(std::forward<Arg0>(vertices));
72 this->spine = std::forward<Arg1>(spine);
73 this->hasData = true;
74 setChanged();
75 return true;
76 }
77
78 static void registerType();
79
80 template<typename Arg0> void setVertices(Arg0&& arg);
81 };
82
83 template<>
84 inline void LoftedCrossSectionsComponent::setVertices<std::vector<PositionNormalVertex>&>(std::vector<PositionNormalVertex>& arg)
85 {
86 vertices_vn = arg;
87 }
88
89 template<>
90 inline void LoftedCrossSectionsComponent::setVertices<std::vector<PositionNormalVertex>>(std::vector<PositionNormalVertex>&& arg)
91 {
92 vertices_vn = std::move(arg);
93 }
94
95 template<>
96 inline void LoftedCrossSectionsComponent::setVertices<std::vector<PositionNormalTexVertex>&>(std::vector<PositionNormalTexVertex>& arg)
97 {
98 vertices_vnt = arg;
99 }
100
101 template<>
102 inline void LoftedCrossSectionsComponent::setVertices<std::vector<PositionNormalTexVertex>>(std::vector<PositionNormalTexVertex>&& arg)
103 {
104 vertices_vnt = std::move(arg);
105 }
106
107
108 } // namespace Core
109} // namespace Cogs
110
111template<> inline
112Cogs::StringView getName<Cogs::Core::LoftedCrossSectionsComponent>()
113{
114 return "LoftedCrossSectionsComponent";
115}
116
117template<> inline
118Cogs::StringView getName<Cogs::Core::LoftedCrossSectionsComponent::Shape>()
119{
120 return "LoftShape";
121}
Base class for Component instances.
Definition: Component.h:143
void setChanged()
Sets the component to the ComponentFlags::Changed state with carry.
Definition: Component.h:202
Log implementation class.
Definition: LogManager.h:139
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
@ Solid
Opaque geometry in arbitrary order.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
bool boundingBoxSet
True when bounding box info is set but not yet forwarded to mesh.
int crossSections
Number of cross sections (inner & outer cross sections count as one).
bool screenAligned
Let open geometry be screen-aligned.
bool hollow
True if shape has inner and outer cross sections, otherwise shape is solid with only outer cross sect...
int samples
Number of sample points in each of the cross sections.
bool open
If true, cull the front of the shape such that the inside is visible.