23#include <utility/graphic/model.hpp>
24#include <utility/ressource_provider.hpp>
26#include "guillaume/systems/measure_mesh.hpp"
31 std::shared_ptr<utility::RessourceProvider> ressourceProvider,
32 utility::Engine &engine)
35 , _ressourceProvider(ressourceProvider)
55 <<
"Updating MeasureMesh system for entity " << entityIdentifier;
62 const auto &modelComponent =
64 auto &boundComponent =
66 auto &transformComponent =
71 getLogger().debug() <<
"Measuring model '" << cacheKey.
meshPath
72 <<
"' for entity " << entityIdentifier;
74 if (contains(cacheKey)) {
75 getLogger().debug() <<
"Mesh '" << cacheKey.
meshPath
76 <<
"' already measured, skipping.";
77 const auto &cacheValue = get(cacheKey);
78 if (cacheValue.has_value()) {
79 const float scale = modelComponent.scaleFor(
80 cacheValue->getWidth(), cacheValue->getHeight());
82 .setWidth(cacheValue->getWidth() * scale)
83 .setHeight(cacheValue->getHeight() * scale);
88 auto model = _ressourceProvider->loadModel(cacheKey.
meshPath);
89 if (model ==
nullptr) {
91 <<
"Failed to load model '" << cacheKey.
meshPath
92 <<
"' for entity " << entityIdentifier;
95 auto boundingBox = model->computeBoundingSize();
96 const float scale = modelComponent.scaleFor(boundingBox.getWidth(),
97 boundingBox.getHeight());
100 .setWidth(boundingBox.getWidth() * scale)
101 .setHeight(boundingBox.getHeight() * scale);
103 put(cacheKey, boundingBox);
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
SystemFiller(Phase phase)
ComponentType & getComponent(const ecs::Entity::Identifier &entityIdentifier)
Get a component of an entity from the bound registry, to read or modify it.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
virtual void update(const ecs::Entity::Identifier &entityIdentifier) override
Write the size of one model into its components::Bound, loading and measuring the file when it is not...
void prepare(void) override
Does nothing: the system needs no per-frame setup.
~MeasureMesh(void)
Destroy the system and its cache.
void cleanup(void) override
Does nothing: the cache is kept from one frame to the next.
MeasureMesh(std::shared_ptr< utility::RessourceProvider > ressourceProvider, utility::Engine &engine)
Create the system in the Measure phase, with an empty cache.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Rules. Every class here runs each frame on the entities that have the components it declares.
Key of the size cache of MeasureMesh: the path of the model file.
std::string meshPath
Path of the model file that was measured.