58 <<
"Updating ImageRender system for entity " << entityIdentifier;
66 const auto &transformComponent =
68 auto &imageComponent =
71 std::string texturePath = imageComponent.getTexturePath();
73 getLogger().debug() <<
"Rendering image '" << texturePath
74 <<
"' for entity " << entityIdentifier;
76 bool usingFallback =
false;
77 if (!_ressourceProvider->loadImageMaterial(texturePath)) {
79 <<
"Failed to load image material for texture: " << texturePath;
80 const std::string &fallback = imageComponent.getFallbackPath();
82 || !_ressourceProvider->loadImageMaterial(fallback)) {
83 imageComponent.setLoadState(
87 texturePath = fallback;
97 if (bound.getWidth() <= 0.0f || bound.getHeight() <= 0.0f) {
98 const auto texture = _ressourceProvider->loadTexture(texturePath);
99 if (texture !=
nullptr && texture->width() > 0
100 && texture->height() > 0) {
101 const float textureWidth =
static_cast<float>(texture->width());
102 const float textureHeight =
103 static_cast<float>(texture->height());
104 if (bound.getWidth() > 0.0f) {
105 bound.setHeight(bound.getWidth() * textureHeight
107 }
else if (bound.getHeight() > 0.0f) {
108 bound.setWidth(bound.getHeight() * textureWidth
111 bound.setWidth(textureWidth).setHeight(textureHeight);
116 const auto &boundComponent = bound;
117 const float halfWidth = boundComponent.getWidth() / 2.0f;
118 const float halfHeight = boundComponent.getHeight() / 2.0f;
120 const utility::graphic::PositionF center(
121 transformComponent.getPose().getPosition().x + halfWidth,
122 transformComponent.getPose().getPosition().y - halfHeight,
123 transformComponent.getPose().getPosition().z);
125 const utility::graphic::Color32Bit white(255, 255, 255, 255);
127 utility::graphic::Mesh mesh(std::vector<utility::graphic::VertexF> {},
128 std::vector<uint32_t> {});
130 const auto addVertex = [&](
float x,
float y,
float u,
float v) {
131 utility::graphic::VertexF vertex;
132 vertex.setPosition(utility::graphic::PositionF(
133 center[0] + x, center[1] + y, center[2]));
134 vertex.setColor(white);
135 vertex.setTextureCoordinates(utility::math::Vector2F({ u, v }));
136 mesh.addVertex(vertex);
139 addVertex(-halfWidth, -halfHeight, 0.0f, 0.0f);
140 addVertex(halfWidth, -halfHeight, 1.0f, 0.0f);
141 addVertex(halfWidth, halfHeight, 1.0f, 1.0f);
142 addVertex(-halfWidth, halfHeight, 0.0f, 1.0f);
151 auto renderable = std::make_shared<MeshRenderable>(
152 std::vector<utility::graphic::Mesh> { mesh },
153 "image_" + texturePath);
156 if (handle ==
nullptr) {
157 size_t objectId = _engine.createObject(renderable);
161 if (!_engine.updateObject(renderable, handle->objectId)) {
162 handle->objectId = _engine.createObject(renderable);
164 handle->renderable = renderable;