From 02abbef0732484d2987236d05d2ca2a910c15808 Mon Sep 17 00:00:00 2001 From: t-rvw <429601557@qq.com> Date: Thu, 21 Sep 2023 22:30:41 +0800 Subject: [PATCH] fix added cube/sphere --- Engine/Source/Editor/UILayers/EntityList.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Engine/Source/Editor/UILayers/EntityList.cpp b/Engine/Source/Editor/UILayers/EntityList.cpp index 98193dfc..6ac65833 100644 --- a/Engine/Source/Editor/UILayers/EntityList.cpp +++ b/Engine/Source/Editor/UILayers/EntityList.cpp @@ -42,21 +42,24 @@ void EntityList::AddEntity(engine::SceneWorld* pSceneWorld) auto CreateShapeComponents = [&pSceneWorld, &pWorld, &pSceneDatabase](engine::Entity entity, cd::Mesh&& mesh, engine::MaterialType* pMaterialType) { + mesh.SetName(pSceneWorld->GetNameComponent(entity)->GetName()); + mesh.SetID(cd::MeshID(pSceneDatabase->GetMeshCount())); + + uint32_t currentMeshCount = pSceneDatabase->GetMeshCount(); + pSceneDatabase->AddMesh(cd::MoveTemp(mesh)); + const cd::Mesh& newAddedShape = pSceneDatabase->GetMesh(currentMeshCount); + auto& collisionMeshComponent = pWorld->CreateComponent(entity); collisionMeshComponent.SetType(engine::CollisonMeshType::AABB); - collisionMeshComponent.SetAABB(mesh.GetAABB()); + collisionMeshComponent.SetAABB(newAddedShape.GetAABB()); collisionMeshComponent.Build(); auto& staticMeshComponent = pWorld->CreateComponent(entity); - staticMeshComponent.SetMeshData(&mesh); + staticMeshComponent.SetMeshData(&newAddedShape); staticMeshComponent.SetRequiredVertexFormat(&pMaterialType->GetRequiredVertexFormat()); staticMeshComponent.Build(); staticMeshComponent.Submit(); - mesh.SetName(pSceneWorld->GetNameComponent(entity)->GetName()); - mesh.SetID(cd::MeshID(pSceneDatabase->GetMeshCount())); - pSceneDatabase->AddMesh(cd::MoveTemp(mesh)); - auto& materialComponent = pWorld->CreateComponent(entity); materialComponent.Init(); materialComponent.SetMaterialType(pMaterialType);