guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
mesh.cpp
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#include <memory>
24
25#include "guillaume/entities/mesh.hpp"
26#include "guillaume/entities/builder_base.hpp"
27
28namespace guillaume::entities
29{
30
31 Mesh::Mesh::Builder::Builder(ecs::ComponentRegistry &componentRegistry,
32 ecs::EntityRegistry &entityRegistry)
33 : EntityBuilderBase<Mesh>(componentRegistry, entityRegistry)
34 {
35 reset();
36 }
37
38 std::shared_ptr<Mesh> Mesh::Builder::buildEntity(void)
39 {
40 auto entity = Mesh::create(this->getComponentRegistry(), _meshPath);
41 entity->setMeshPath(_meshPath);
42 entity->setTexturePath(_texturePath);
43 return entity;
44 }
45
47 {
48 _meshPath.clear();
49 _texturePath.clear();
50 }
51
52 Mesh::Builder &Mesh::Builder::withMeshPath(const std::string &meshPath)
53 {
54 _meshPath = meshPath;
55 return *this;
56 }
57
59 Mesh::Builder::withTexturePath(const std::string &texturePath)
60 {
61 _texturePath = texturePath;
62 return *this;
63 }
64
65 std::shared_ptr<Mesh>
66 Mesh::Builder::makeMesh(std::shared_ptr<Entity> parent,
67 const std::string &meshPath,
68 const std::string &texturePath)
69 {
70 return withMeshPath(meshPath)
71 .withTexturePath(texturePath)
72 .registerEntity(parent);
73 }
74
75 Mesh::Mesh(ecs::ComponentRegistry &registry, const std::string &meshPath)
76 : ecs::EntityFiller<components::Transform, components::Bound,
77 components::Mesh>(registry)
78 {
79 setMeshPath(meshPath);
80 }
81
83 {
84 }
85
86 Mesh &Mesh::setMeshPath(const std::string &meshPath)
87 {
90 .setMeshPath(meshPath);
91
92 return *this;
93 }
94
95 Mesh &Mesh::setTexturePath(const std::string &texturePath)
96 {
99 .setTexturePath(texturePath);
100
101 return *this;
102 }
103
104 Mesh &Mesh::setFitSize(std::optional<float> size)
105 {
108 .setFitSize(size);
109 return *this;
110 }
111
112} // namespace guillaume::entities
A 3D model shown at the entity's pose: the model file and an optional texture.
Definition mesh.hpp:57
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
Definition entity.cpp:94
Base of every widget Builder: turns a configuration into a widget that is attached to a parent and ow...
Configures Mesh widgets and registers them in the scene's entity registry.
Definition mesh.hpp:75
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
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
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Definition component.hpp:28
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46