refactor: transform world 矩阵改由帧循环统一重算,删除手动 Compose

- Scene::UpdateTransforms():渲染前全量 Compose(UE transform-update
  阶段模式),Application::Run 在 FlushDestroyQueue 后调用
- 用户代码永远不需要手动 Compose——Set*/直接写字段均安全;
  Compose 降级为引擎内部调用
- 选择全量而非 dirty 标记:字段直接写(t.rotation.y = x)无法可靠
  追踪脏,无条件重算零脚枪;万级实体内成本可忽略,更大规模再引入
  dirty+封装
- main.cpp/Camera 所有手动 Compose 调用点删除
This commit is contained in:
2026-09-23 15:26:58 +08:00
parent 1bc44e261b
commit 57ab8901a9
6 changed files with 35 additions and 25 deletions
+5 -9
View File
@@ -58,9 +58,8 @@ protected:
const auto ground = GetAssets().CreatePlane(15.0f, 140, 140, 145);
m_Ground = scene.CreateEntity("Ground");
m_Ground.GetComponent<TransformComponent>() // 出生即有,直接取
.SetPosition(glm::vec3(0.0f, -0.5f, 0.0f))
.Compose();
m_Ground.GetComponent<TransformComponent>()
.SetPosition(glm::vec3(0.0f, -0.5f, 0.0f)); // dirty → 帧循环统一 Compose
m_Ground.AddComponent<MeshRendererComponent>(MeshRendererComponent{ground});
// 相机实体(primary = 当前渲染视角;位姿存实体 Transform)
@@ -68,15 +67,13 @@ protected:
auto& camera = m_Camera.AddComponent<CameraComponent>();
camera.primary = true;
m_Camera.GetComponent<TransformComponent>()
.SetPosition(glm::vec3(0.0f, 0.0f, 7.0f))
.Compose();
.SetPosition(glm::vec3(0.0f, 0.0f, 7.0f));
// 神庙实体 × 1( FBX 单位较大,缩放到场景尺度)
{
auto e = scene.CreateEntity("SunTemple");
e.GetComponent<TransformComponent>()
.SetScale(glm::vec3(0.05f))
.Compose();
.SetScale(glm::vec3(0.05f));
e.AddComponent<MeshRendererComponent>(MeshRendererComponent{temple});
}
@@ -116,8 +113,7 @@ protected:
{
auto& t = m_Spinners[i].GetComponent<TransformComponent>();
t.rotation.y = m_Time * 60.0f + static_cast<f32>(i) * 40.0f;
t.scale = glm::vec3(0.5f);
t.Compose();
t.scale = glm::vec3(0.5f); // dirty → 帧循环统一 Compose
}
}