From 372e0f2aa06b705fda893103a9febed4574ddb7e Mon Sep 17 00:00:00 2001 From: ducphamhong Date: Wed, 8 Jun 2022 12:50:48 +0700 Subject: [PATCH] #149 Update duplicate (multi entities), move, rot, scale on many entities --- .../Transform/CWorldTransformDataGizmos.cpp | 28 +++++++++++++++++-- .../SpaceController/CSceneController.cpp | 26 +++++++++++------ .../Source/Primitive/CPrimitiveRenderer.cpp | 2 ++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp b/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp index 17ac8e807..8ce3f21a7 100644 --- a/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp +++ b/Projects/Editor/Source/Editor/Gizmos/Transform/CWorldTransformDataGizmos.cpp @@ -84,12 +84,26 @@ namespace Skylicht CSceneController* sceneController = CSceneController::getInstance(); CScene* scene = sceneController->getScene(); + CEntityHandleData* selectEntityHander = (CEntityHandleData*)m_selectEntity->getDataByIndex(CEntityHandleData::DataTypeIndex); + std::vector& selectObjects = CSelection::getInstance()->getAllSelected(); for (CSelectObject* obj : selectObjects) { if (obj->getType() == CSelectObject::Entity) { + CEntity* entity = scene->getEntityManager()->getEntityByID(obj->getID().c_str()); + if (entity != NULL) + { + if (entity == m_selectEntity) + continue; + CEntityHandleData* h = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex); + if (h->Handler != selectEntityHander->Handler) + continue; + + CWorldTransformData* t = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex); + transforms.push_back(t); + } } } } @@ -103,7 +117,10 @@ namespace Skylicht { if (t != m_transform) { - + core::vector3df pos = t->Relative.getTranslation(); + pos += delta; + t->Relative.setTranslation(pos); + t->HasChanged = true; } } } @@ -117,7 +134,10 @@ namespace Skylicht { if (t != m_transform) { - + core::vector3df scale = t->Relative.getScale(); + scale *= delta; + t->Relative.setScale(scale); + t->HasChanged = true; } } } @@ -150,7 +170,9 @@ namespace Skylicht { if (t != m_transform) { - + core::matrix4 m = delta.getMatrix(); + t->Relative *= m; + t->HasChanged = true; } } } diff --git a/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp b/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp index 0a6c40c0b..554e3d249 100644 --- a/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp +++ b/Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp @@ -1125,9 +1125,11 @@ namespace Skylicht // Check duplicate entity CSelection* selection = CSelection::getInstance(); std::vector& selected = selection->getAllSelected(); - if (selected.size() == 1) + std::vector newEntities; + + // Duplicate entities + for (CSelectObject* selectObject : selected) { - CSelectObject* selectObject = selected[0]; CSelectObject::ESelectType type = selectObject->getType(); if (type == CSelectObject::Entity) { @@ -1148,23 +1150,29 @@ namespace Skylicht CWorldTransformData* spawnTransform = (CWorldTransformData*)spawnNewEntity->getDataByIndex(CWorldTransformData::DataTypeIndex); spawnTransform->Relative = transform->Relative; - // change selection - selection->clear(); - selection->addSelect(spawnNewEntity); + newEntities.push_back(spawnNewEntity); // remove gui hierachy if (m_spaceHierarchy != NULL) m_spaceHierarchy->getController()->updateTreeNode(handler->getGameObject()); - - // select on GUI - selectOnHierachy(spawnNewEntity); } } } - return; } } + if (newEntities.size() > 0) + { + // change selection + selection->clear(); + for (CEntity* e : newEntities) + { + selection->addSelect(e); + selectOnHierachy(e); + } + return; + } + // Duplicate game object onCopy(); onPaste(); diff --git a/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRenderer.cpp b/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRenderer.cpp index 926432b02..4418e4db1 100644 --- a/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRenderer.cpp +++ b/Projects/Skylicht/Components/Source/Primitive/CPrimitiveRenderer.cpp @@ -170,6 +170,7 @@ namespace Skylicht meshBuffer->recalculateBoundingBox(); mesh->recalculateBoundingBox(); + mesh->setHardwareMappingHint(EHM_STATIC); m_mesh[CPrimiviteData::Cube] = mesh; m_materials[CPrimiviteData::Cube] = mat; @@ -191,6 +192,7 @@ namespace Skylicht mb->recalculateBoundingBox(); mesh->recalculateBoundingBox(); + mesh->setHardwareMappingHint(EHM_STATIC); m_mesh[primitive] = mesh; m_materials[primitive] = mat;