Skip to main content

ScaleSystem.ixx File

System for applying scale transformations based on ScaleStateComponent. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemodules

Domain-specific components and systems. More...

namespacespatial
namespacetransform

Transform components and systems for spatial state management. More...

namespacesystems

Transform composition systems. More...

Classes Index

classScaleSystem

System that applies scaling to entities based on their ScaleStateComponent. More...

Description

System for applying scale transformations based on ScaleStateComponent.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ScaleSystem.ixx
3 * @brief System for applying scale transformations based on ScaleStateComponent.
4 */
5module;
6
7
8
9export module helios.engine.modules.spatial.transform.systems.ScaleSystem;
10
11
12import helios.math;
13
14import helios.core.units.Unit;
15
16import helios.engine.ecs.GameObject;
17import helios.engine.runtime.world.GameWorld;
18import helios.engine.runtime.world.UpdateContext;
19
20import helios.engine.modules.spatial.transform.components.ScaleStateComponent;
21import helios.engine.modules.spatial.transform.components.ComposeTransformComponent;
22
23import helios.engine.modules.rendering.model.components.ModelAabbComponent;
24
25import helios.engine.mechanics.lifecycle.components.Active;
26
27import helios.engine.common.tags.SystemRole;
28
30
31 /**
32 * @brief System that applies scaling to entities based on their ScaleStateComponent.
33 *
34 * @details
35 * This system converts the desired world-space dimensions from ScaleStateComponent
36 * into scale factors relative to the model's original AABB. It handles unit
37 * conversion (e.g., centimeters to meters) based on the ScaleStateComponent's unit.
38 *
39 * Required components:
40 * - ScaleStateComponent (desired dimensions and unit)
41 * - ModelAabbComponent (original model bounds)
42 * - ComposeTransformComponent (receives scale updates)
43 */
44 class ScaleSystem {
45
46
47 public:
48
50 /**
51 * @brief Updates scale for all entities with dirty ScaleComponents.
52 *
53 * @details For each entity with the required components, calculates the scale factor
54 * needed to resize the model from its original dimensions to the desired
55 * world-space dimensions.
56 *
57 * @param updateContext Context containing deltaTime and other frame data.
58 */
60
61 for (auto [entity, mab, sc, tc, active] : updateContext.view<
66 >().whereEnabled()) {
67
68 if (!sc->isDirty()) {
69 continue;
70 }
71
72 // Get current model size and desired size
73 auto cscale = mab->aabb().size();
74 auto wscale = sc->scaling();
75
76 auto currentScale = tc->localScaling();
77
78 auto unit = sc->unit();
79
80 // Calculate scale factors: desired_size / current_size
81 // Convert desired size to engine units (meters)
82 auto scale = helios::math::vec3f{
83 wscale[0] != 0 && cscale[0] != 0 ? helios::core::units::from(wscale[0], unit) / cscale[0] : currentScale[0],
84 wscale[1] != 0 && cscale[1] != 0 ? helios::core::units::from(wscale[1], unit) / cscale[1] : currentScale[1],
85 wscale[2] != 0 && cscale[2] != 0 ? helios::core::units::from(wscale[2], unit) / cscale[2] : currentScale[2]
86 };
87
88 tc->setLocalScale(scale);
89 }
90 }
91
92 };
93
94}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.