Skip to main content

SceneNodeConfig.ixx File

Configuration for scene graph integration. More...

Included Headers

#include <cassert> #include <memory> #include <helios.math> #include <helios.engine.ecs.components> #include <helios.engine.modules.rendering> #include <helios.scene> #include <helios.engine.modules.scene> #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

classSceneNodeConfig

Fluent configuration for scene graph integration. More...

Description

Configuration for scene graph integration.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file SceneNodeConfig.ixx
3 * @brief Configuration for scene graph integration.
4 */
5module;
6
7#include <cassert>
8#include <memory>
9
10export module helios.engine.builder.gameObject.builders.configs.SceneNodeConfig;
11
12import helios.engine.ecs.GameObject;
13import helios.scene;
14import helios.engine.modules.rendering;
15import helios.engine.ecs.components;
16import helios.engine.modules.scene;
17
18import helios.math;
19
21
22 /**
23 * @brief Fluent configuration for scene graph integration.
24 *
25 * @details Allows attaching a GameObject's renderable to the scene graph
26 * by creating a SceneNode and setting its parent and inheritance mode.
27 * The config automatically manages HierarchyComponent relationships when
28 * parenting to another GameObject.
29 *
30 * ## Usage
31 *
32 * ```cpp
33 * sceneConfig.parent(rootNode)
34 * .inherit(TransformType::Translation | TransformType::Rotation);
35 * ```
36 *
37 * @see SceneNodeComponent
38 * @see HierarchyComponent
39 * @see TransformType
40 */
42
43 /**
44 * @brief Non-owning pointer to the target GameObject.
45 */
47
48
49 /**
50 * @brief Validates that a RenderableComponent exists.
51 */
52 void ensureRenderableComponent() {
54 assert(renderableComponent && "Unexpected nullptr for RenderableComponent.");
55 }
56
57 /**
58 * @brief Validates SceneNodeComponent presence.
59 *
60 * @param shouldBeAvailable Whether the component should exist.
61 */
62 void ensureSceneNode(const bool shouldBeAvailable) {
64
65 if (shouldBeAvailable) {
66 assert(snc && "Unexpected nullptr for SceneNodeComponent.");
67 } else {
68 assert(!snc && "Unexpected SceneNodeComponent.");
69 }
70
71 }
72
73 public:
74
75 /**
76 * @brief Constructs a SceneNodeConfig for the given GameObject.
77 *
78 * @param gameObject Target GameObject to configure.
79 */
81
82 /**
83 * @brief Creates a SceneNode and parents it to the given node.
84 *
85 * @param parent Parent SceneNode in the scene graph.
86 *
87 * @return Reference to this config for chaining.
88 */
90 ensureSceneNode(false);
91 ensureRenderableComponent();
92
93 const auto* renderableComponent = gameObject_.get<helios::engine::modules::rendering::renderable::components::RenderableComponent>();
94
95 auto renderable = renderableComponent->shareRenderable();
96
97 auto node = std::make_unique<helios::scene::SceneNode>(renderable);
98 auto node_ptr = parent->addNode(std::move(node));
99
101
102 return *this;
103 }
104
105
106 /**
107 * @brief Creates a SceneNode and parents it to another GameObject's node.
108 *
109 * @details Establishes both scene graph and ECS hierarchy relationships:
110 * - Adds HierarchyComponent to both entities if not present
111 * - Sets parent-child relationship in HierarchyComponent
112 * - Parents the SceneNode to the parent GameObject's SceneNode
113 *
114 * @param parent Parent GameObject whose SceneNode will be the parent.
115 *
116 * @return Reference to this config for chaining.
117 */
119 ensureSceneNode(false);
120 ensureRenderableComponent();
121
122 parent.getOrAdd<helios::engine::ecs::components::HierarchyComponent>().addChild(gameObject_.entityHandle());
123 gameObject_.getOrAdd<helios::engine::ecs::components::HierarchyComponent>().setParent(parent.entityHandle());
124
125 const auto* renderableComponent = gameObject_.get<helios::engine::modules::rendering::renderable::components::RenderableComponent>();
126
127 auto renderable = renderableComponent->shareRenderable();
128
129 auto node = std::make_unique<helios::scene::SceneNode>(renderable);
130
132 assert(psn && "Unexpected missing SceneNodeComponent for parent GameObject");
133 assert(psn->sceneNode() && "Unexpected missing SceneNode for parent GameObject");
134
135 auto node_ptr = psn->sceneNode()->addNode(std::move(node));
136
138
139 return *this;
140 }
141
142 /**
143 * @brief Sets the transform inheritance mode.
144 *
145 * @param transformType Which transforms to inherit from parent.
146 *
147 * @return Reference to this config for chaining.
148 */
150 ensureSceneNode(true);
151
153 ->sceneNode()
154 ->setInheritance(transformType) ;
155
156 return *this;
157 }
158
159
160
161 };
162
163}
164

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.