Skip to content

Commit

Permalink
#149 Update duplicate (multi entities), move, rot, scale on many enti…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
ducphamhong committed Jun 8, 2022
1 parent 6fe82fd commit 372e0f2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,26 @@ namespace Skylicht
CSceneController* sceneController = CSceneController::getInstance();
CScene* scene = sceneController->getScene();

CEntityHandleData* selectEntityHander = (CEntityHandleData*)m_selectEntity->getDataByIndex(CEntityHandleData::DataTypeIndex);

std::vector<CSelectObject*>& 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);
}
}
}
}
Expand All @@ -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;
}
}
}
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -150,7 +170,9 @@ namespace Skylicht
{
if (t != m_transform)
{

core::matrix4 m = delta.getMatrix();
t->Relative *= m;
t->HasChanged = true;
}
}
}
Expand Down
26 changes: 17 additions & 9 deletions Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,9 +1125,11 @@ namespace Skylicht
// Check duplicate entity
CSelection* selection = CSelection::getInstance();
std::vector<CSelectObject*>& selected = selection->getAllSelected();
if (selected.size() == 1)
std::vector<CEntity*> newEntities;

// Duplicate entities
for (CSelectObject* selectObject : selected)
{
CSelectObject* selectObject = selected[0];
CSelectObject::ESelectType type = selectObject->getType();
if (type == CSelectObject::Entity)
{
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ namespace Skylicht

meshBuffer->recalculateBoundingBox();
mesh->recalculateBoundingBox();
mesh->setHardwareMappingHint(EHM_STATIC);

m_mesh[CPrimiviteData::Cube] = mesh;
m_materials[CPrimiviteData::Cube] = mat;
Expand All @@ -191,6 +192,7 @@ namespace Skylicht

mb->recalculateBoundingBox();
mesh->recalculateBoundingBox();
mesh->setHardwareMappingHint(EHM_STATIC);

m_mesh[primitive] = mesh;
m_materials[primitive] = mat;
Expand Down

0 comments on commit 372e0f2

Please sign in to comment.