From 14dbd31886922e8a658b29625190a9e4b58044b6 Mon Sep 17 00:00:00 2001 From: brige Date: Sat, 21 Mar 2026 21:13:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=B0=BE=E8=BF=B9=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/EntitiesManager.cpp | 23 ++++++++++++++++++++++- src/entities/EntityFactory.cpp | 24 +++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/entities/EntitiesManager.cpp b/src/entities/EntitiesManager.cpp index 70ad395b..6ce85959 100644 --- a/src/entities/EntitiesManager.cpp +++ b/src/entities/EntitiesManager.cpp @@ -114,7 +114,8 @@ Entity* EntitiesManager::CreateMesh(const QString& mesh) { SceneComponent* conponent = ComponentFactory::Create("MeshComponent", nullptr); conponent->SetAttribute("mesh", mesh.toStdString().c_str()); conponent->AttachEntity(entity); - // Also add PathComponent so the entity has a path attribute by default + + // Also add PathComponent so the entity has a path attribute by default. SceneComponent* rootComponent = entity->GetRootComponent(); if (rootComponent) { SceneComponent* pathComponent = ComponentFactory::Create("PathComponent", rootComponent); @@ -133,6 +134,26 @@ Entity* EntitiesManager::CreateMesh(const QString& mesh) { LOG_WARN("EntitiesManager::CreateMesh - Failed to create PathComponent with no root"); } } + + // Add TrajectoryTraceComponent by default for all newly created mesh entities. + rootComponent = entity->GetRootComponent(); + if (rootComponent) { + SceneComponent* traceComponent = ComponentFactory::Create("TrajectoryTraceComponent", rootComponent); + if (traceComponent) { + traceComponent->AttachTo(rootComponent); + LOG_INFO("EntitiesManager::CreateMesh - Added TrajectoryTraceComponent"); + } else { + LOG_WARN("EntitiesManager::CreateMesh - Failed to create TrajectoryTraceComponent"); + } + } else { + SceneComponent* traceComponent = ComponentFactory::Create("TrajectoryTraceComponent", nullptr); + if (traceComponent) { + traceComponent->AttachEntity(entity); + LOG_INFO("EntitiesManager::CreateMesh - Added TrajectoryTraceComponent with no root"); + } else { + LOG_WARN("EntitiesManager::CreateMesh - Failed to create TrajectoryTraceComponent with no root"); + } + } return entity; } diff --git a/src/entities/EntityFactory.cpp b/src/entities/EntityFactory.cpp index 7da7a48e..91080f7b 100644 --- a/src/entities/EntityFactory.cpp +++ b/src/entities/EntityFactory.cpp @@ -88,6 +88,28 @@ Entity* EntityFactory::CreateEntityWithComponents(const QString& type, const QSt } } + // Always add TrajectoryTraceComponent so newly created entities can edit/show traces immediately. + { + SceneComponent* rootComponent = entity->GetRootComponent(); + if (nullptr == rootComponent) { + SceneComponent* traceComponent = ComponentFactory::Create("TrajectoryTraceComponent", nullptr); + if (traceComponent) { + traceComponent->AttachEntity(entity); + LOG_INFO("EntityFactory::CreateEntityWithComponents - Added TrajectoryTraceComponent"); + } else { + LOG_WARN("EntityFactory::CreateEntityWithComponents - Failed to create TrajectoryTraceComponent"); + } + } else { + SceneComponent* traceComponent = ComponentFactory::Create("TrajectoryTraceComponent", rootComponent); + if (traceComponent) { + traceComponent->AttachTo(rootComponent); + LOG_INFO("EntityFactory::CreateEntityWithComponents - Added TrajectoryTraceComponent"); + } else { + LOG_WARN("EntityFactory::CreateEntityWithComponents - Failed to create TrajectoryTraceComponent"); + } + } + } + // Add required components QStringList requiredComponents = it->second->GetRequiredComponents(); SceneComponent* rootComponent = entity->GetRootComponent(); @@ -148,4 +170,4 @@ QStringList EntityFactory::GetRequiredComponents(const QString& type) const { bool EntityFactory::IsTypeSupported(const QString& type) const { return creators_.find(type) != creators_.end(); -} \ No newline at end of file +}