Skip to main content

MeshRenderableConfig.ixx File

Configuration for renderable components (mesh, material, shader). More...

Included Headers

#include <memory> #include <unordered_map> #include <cassert> #include <helios.engine.builder.gameObject.builders.configs.SceneNodeConfig> #include <helios.scene.SceneNode> #include <helios.rendering.mesh> #include <helios.math.types> #include <helios.engine.modules.rendering> #include <helios.ext.opengl> #include <helios.rendering> #include <helios.engine.ecs.GameObject>

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacebuilder

Fluent builder pattern for constructing GameObjects. More...

namespacegameObject

Factory and prototype classes for GameObject construction. More...

namespacebuilders

Domain-specific builders for configuring different aspects of GameObjects. More...

namespaceconfigs

Fine-grained configuration classes for component setup. More...

Classes Index

classMeshRenderableConfig

Fluent configuration for setting up a Renderable on a GameObject. More...

Description

Configuration for renderable components (mesh, material, shader).

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file MeshRenderableConfig.ixx
3 * @brief Configuration for renderable components (mesh, material, shader).
4 */
5module;
6
7#include <memory>
8#include <unordered_map>
9#include <cassert>
10
11export module helios.engine.builder.gameObject.builders.configs.MeshRenderableConfig;
12
13import helios.engine.ecs.GameObject;
14import helios.rendering;
15import helios.ext.opengl;
16import helios.engine.modules.rendering;
17import helios.math.types;
18import helios.rendering.mesh;
19import helios.scene.SceneNode;
20
21import helios.engine.builder.gameObject.builders.configs.SceneNodeConfig;
22
23
25
26 /**
27 * @brief Fluent configuration for setting up a Renderable on a GameObject.
28 *
29 * Allows specification of shape, shader, primitive type, and color.
30 * Builds and attaches a RenderableComponent.
31 */
33
34 /**
35 * @brief Non-owning pointer to the target GameObject.
36 */
38
39 /**
40 * @brief The shape geometry to render.
41 */
42 std::shared_ptr<helios::rendering::asset::shape::Shape> shape_;
43
44 /**
45 * @brief The shader for rendering.
46 */
47 std::shared_ptr<helios::ext::opengl::rendering::shader::LegacyOpenGLShader> shader_;
48
49 /**
50 * @brief The primitive type for mesh rendering.
51 */
53
54 /**
55 * @brief The base color for the material.
56 */
58
59 static inline std::unordered_map<
61 std::shared_ptr<helios::rendering::mesh::MeshConfig>
62 > meshConfigs_;
63
64 static std::shared_ptr<helios::rendering::mesh::MeshConfig> meshConfig(helios::rendering::mesh::PrimitiveType primitiveType) {
65
66 auto [it, inserted] = meshConfigs_.try_emplace(
68 std::make_shared<helios::rendering::mesh::MeshConfig>(primitiveType)
69 );
70
71 return it->second;
72 }
73
74 public:
75
76 /**
77 * @brief Constructs a MeshRenderableConfig for the given GameObject.
78 *
79 * @param gameObject Target GameObject to configure.
80 */
83 ) : gameObject_(gameObject) {}
84
85 /**
86 * @brief Sets the shape geometry.
87 *
88 * @param shape Shared pointer to the shape.
89 *
90 * @return Reference to this config for chaining.
91 */
92 MeshRenderableConfig& shape(std::shared_ptr<helios::rendering::asset::shape::Shape> shape) {
93 shape_ = shape;
94
95 return *this;
96 }
97
98 /**
99 * @brief Sets the shader program.
100 *
101 * @param shader Shared pointer to the OpenGL shader.
102 *
103 * @return Reference to this config for chaining.
104 */
105 MeshRenderableConfig& shader(std::shared_ptr<helios::ext::opengl::rendering::shader::LegacyOpenGLShader> shader) {
106 shader_ = shader;
107
108 return *this;
109 }
110
111 /**
112 * @brief Sets the primitive type for rendering.
113 *
114 * @param primitiveType The OpenGL primitive type.
115 *
116 * @return Reference to this config for chaining.
117 */
119 primitiveType_ = primitiveType;
120
121 return *this;
122 }
123
124 /**
125 * @brief Sets the base color for the material.
126 *
127 * @param color RGBA color vector.
128 *
129 * @return Reference to this config for chaining.
130 */
132 color_ = color;
133
134 return *this;
135 }
136
137 /**
138 * @brief Builds the renderable and attaches it to a scene node.
139 *
140 * @param parent Parent SceneNode for the new node.
141 */
143
144 build();
145
146 SceneNodeConfig scn{gameObject_};
147
148 scn.parent(parent);
149 }
150
151 /**
152 * @brief Builds and attaches the RenderableComponent.
153 *
154 * @return Reference to this config for chaining.
155 */
157
158 assert(shape_ && shader_ && "Unexpected missing shape and/or shader");
159
160 auto mesh = std::make_shared<helios::ext::opengl::rendering::model::OpenGLMesh>(
161 *shape_,
162 std::move(MeshRenderableConfig::meshConfig(primitiveType_))
163 );
164
165 auto materialProperties = std::make_shared<helios::rendering::material::MaterialShaderProperties>(color_);
166 auto material = std::make_shared<helios::rendering::material::Material>(shader_, materialProperties);
167
168 const auto renderPrototype = std::make_shared<helios::rendering::RenderPrototype>(material, mesh);
169
171 std::make_shared<helios::rendering::mesh::MeshRenderable>(renderPrototype)
172 );
173
175 msc.setAabb(rc.renderable().localAABB());
176
177 return *this;
178 }
179
180 };
181
182}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.