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 "guillaume/components/mesh.hpp"
24
25#include <algorithm>
26
28{
29 Mesh &Mesh::setMeshPath(const std::string &path)
30 {
31 if (_meshPath == path) {
32 return *this;
33 }
34 _meshPath = path;
35 setHasChanged(true);
36 return *this;
37 }
38
39 std::string Mesh::getMeshPath(void) const
40 {
41 return _meshPath;
42 }
43
44 Mesh &Mesh::setTexturePath(const std::string &path)
45 {
46 if (_texturePath == path) {
47 return *this;
48 }
49 _texturePath = path;
50 setHasChanged(true);
51 return *this;
52 }
53
54 std::string Mesh::getTexturePath(void) const
55 {
56 return _texturePath;
57 }
58
59 const std::optional<float> &Mesh::getFitSize(void) const noexcept
60 {
61 return _fitSize;
62 }
63
64 Mesh &Mesh::setFitSize(std::optional<float> size)
65 {
66 if (_fitSize != size) {
67 _fitSize = size;
68 setHasChanged(true);
69 }
70 return *this;
71 }
72
73 float Mesh::scaleFor(float modelWidth, float modelHeight) const noexcept
74 {
75 const float longest = std::max(modelWidth, modelHeight);
76
77 if (!_fitSize.has_value() || longest <= 0.0f) {
78 return 1.0f;
79 }
80 return *_fitSize / longest;
81 }
82} // namespace guillaume::components
const std::optional< float > & getFitSize(void) const noexcept
Get the size the model is scaled to.
Definition mesh.cpp:59
Mesh(void)=default
Default constructor for the Mesh component.
std::string getMeshPath(void) const
Get the path of the model file.
Definition mesh.cpp:39
Mesh & setTexturePath(const std::string &path)
Choose the texture applied to the model.
Definition mesh.cpp:44
float scaleFor(float modelWidth, float modelHeight) const noexcept
Get the factor that turns model units into dp.
Definition mesh.cpp:73
Mesh & setMeshPath(const std::string &path)
Choose the model to show.
Definition mesh.cpp:29
std::string getTexturePath(void) const
Get the path of the texture file.
Definition mesh.cpp:54
Mesh & setFitSize(std::optional< float > size)
Scale the model so its longest side has this length.
Definition mesh.cpp:64
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
State. Every class here is plain data attached to an entity.