guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
mesh.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <utility>
26#include <memory>
27#include <optional>
28#include "guillaume/ecs/component_registry.hpp"
29#include "guillaume/entities/builder_base.hpp"
30#include "guillaume/ecs/entity_builder.hpp"
31#include "guillaume/ecs/entity_filler.hpp"
32
33#include "guillaume/components/mesh.hpp"
34#include "guillaume/components/bound.hpp"
35#include "guillaume/components/transform.hpp"
36
37namespace guillaume::entities
38{
39
65 class Mesh:
66 public ecs::EntityFiller<components::Transform, components::Bound,
67 components::Mesh>
68 {
69 public:
74 class Builder: public EntityBuilderBase<Mesh>
75 {
76 private:
77 std::string _meshPath;
78 std::string _texturePath;
80
81 public:
89 Builder(ecs::ComponentRegistry &componentRegistry,
90 ecs::EntityRegistry &entityRegistry);
91
97 std::shared_ptr<Mesh> buildEntity(void) override;
98
103 void reset(void) override;
104
112 Builder &withMeshPath(const std::string &meshPath);
113
120 Builder &withTexturePath(const std::string &texturePath);
121
132 std::shared_ptr<Mesh> makeMesh(std::shared_ptr<Entity> parent,
133 const std::string &meshPath,
134 const std::string &texturePath = "");
135 };
136
137 public:
147 template<typename... Arguments>
148 static std::shared_ptr<Mesh> create(Arguments &&...arguments)
149 {
150 std::shared_ptr<Mesh> entity(
151 new Mesh(std::forward<Arguments>(arguments)...));
152 return entity;
153 }
154
158 ~Mesh(void);
159
168 Mesh &setMeshPath(const std::string &meshPath);
169
176 Mesh &setTexturePath(const std::string &texturePath);
177
185 Mesh &setFitSize(std::optional<float> size);
186
187 private:
194 Mesh(ecs::ComponentRegistry &registry, const std::string &meshPath);
195 };
196
197} // namespace guillaume::entities
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
The base class of a widget without children: an Entity that creates its components when it is constru...
Owns entities and gives the systems the list of entities to visit.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
std::shared_ptr< Mesh > makeMesh(std::shared_ptr< Entity > parent, const std::string &meshPath, const std::string &texturePath="")
Build a mesh, register it under parent and reset the builder.
Definition mesh.cpp:66
void reset(void) override
Restore the defaults: empty model path and empty texture path.
Definition mesh.cpp:46
Builder & withMeshPath(const std::string &meshPath)
Choose the model to draw.
Definition mesh.cpp:52
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
std::shared_ptr< Mesh > buildEntity(void) override
Build a mesh from the current configuration, without registering it or giving it a parent.
Definition mesh.cpp:38
Builder & withTexturePath(const std::string &texturePath)
Choose the texture applied to the model.
Definition mesh.cpp:59
A 3D model loaded from a file, with an optional texture.
Definition mesh.hpp:68
Mesh & setMeshPath(const std::string &meshPath)
Change the model to draw.
Definition mesh.cpp:86
Mesh & setTexturePath(const std::string &texturePath)
Change the texture applied to the model.
Definition mesh.cpp:95
~Mesh(void)
Destructor.
Definition mesh.cpp:82
static std::shared_ptr< Mesh > create(Arguments &&...arguments)
Build a mesh without registering it in an entity registry.
Definition mesh.hpp:148
Mesh & setFitSize(std::optional< float > size)
Scale the model so its longest side has this length.
Definition mesh.cpp:104
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46