Skip to content

Commit

Permalink
#123 Display tree nodes of RenderMesh Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed May 13, 2022
1 parent 6b9bfe0 commit d23fe77
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,10 @@ namespace Skylicht

GUI::CListRowItem* rowItem = (GUI::CListRowItem*)data->UserData;
std::string path = rowItem->getTagString();
CSceneController::getInstance()->createResourceComponent(path, targetObject);

CSceneController* sceneController = CSceneController::getInstance();
sceneController->createResourceComponent(path, targetObject);
sceneController->updateTreeNode(targetObject);
}
}

Expand Down
14 changes: 9 additions & 5 deletions Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ namespace Skylicht
sceneController->createResourceComponent(path, targetObject);
CHierachyNode* node = sceneController->selectOnHierachy(targetObject);
sceneController->onSelectNode(node, true);
sceneController->updateTreeNode(targetObject);
}
}
}
Expand Down Expand Up @@ -579,8 +580,11 @@ namespace Skylicht

// end toolbar

void CSpaceScene::initRenderPipeline(float w, float h)
void CSpaceScene::initRenderPipeline(float fw, float fh)
{
int w = (int)fw;
int h = (int)fh;

if (w >= 32.0f && h >= 32.0f)
{
if (m_renderRP == NULL)
Expand Down Expand Up @@ -620,7 +624,7 @@ namespace Skylicht
{
// resize
if (m_shadowMapRendering != NULL)
m_shadowMapRendering->resize(w, h);
m_shadowMapRendering->resize((int)w, h);

if (m_rendering != NULL)
m_rendering->resize(w, h);
Expand All @@ -635,15 +639,15 @@ namespace Skylicht
if (m_viewpointRP == NULL)
{
m_viewpointRP = new CForwardRP(false);
m_viewpointRP->initRender((int)w, (int)h);
m_viewpointRP->initRender(w, h);
}
else
{
m_viewpointRP->resize((int)w, (int)h);
m_viewpointRP->resize(w, h);
}

// update camera aspect
m_editorCamera->setAspect(w / h);
m_editorCamera->setAspect(fw / fh);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ namespace Skylicht
{
// Name and icon
spaceProperty->setIcon(GUI::ESystemIcon::Poly);
spaceProperty->setLabel(L"Entity");

// Label on Propety
std::wstring label = L"Entity: ";

// Clear old ui
spaceProperty->clearAllGroup();
Expand All @@ -141,6 +143,9 @@ namespace Skylicht
CEntity* entity = scene->getEntityManager()->getEntityByID(object->getID().c_str());
if (entity != NULL)
{
CWorldTransformData* worldTransform = entity->getData<CWorldTransformData>();
label += CStringImp::convertUTF8ToUnicode(worldTransform->Name.c_str());

// Activator
CEditorActivator* activator = CEditorActivator::getInstance();

Expand All @@ -157,6 +162,8 @@ namespace Skylicht
}
}
}

spaceProperty->setLabel(label.c_str());
}
}
else
Expand Down
15 changes: 12 additions & 3 deletions Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,24 +360,33 @@ namespace Skylicht
}
}

void CSceneController::rebuildHierarchyEntityData(CGameObject* object, CHierachyNode* parentNode)
void CSceneController::rebuildHierarchyEntityData(CGameObject* object, CHierachyNode* rootNode)
{
parentNode->removeAll(CHierachyNode::Entity);
rootNode->removeAll(CHierachyNode::Entity);

CEntityHandler* entityHandler = object->getComponent<CEntityHandler>();
if (entityHandler == NULL)
return;

CEntity* root = object->getEntity();

std::map<int, CHierachyNode*> treeNodes;
treeNodes[root->getIndex()] = rootNode;

std::vector<CEntity*>& entities = entityHandler->getEntities();
for (CEntity* entity : entities)
{
CHierachyNode* node = parentNode->addChild();
CWorldTransformData* worldData = entity->getData<CWorldTransformData>();

CHierachyNode* parentNode = treeNodes[worldData->ParentIndex];

CHierachyNode* node = parentNode->addChild();
node->setName(CStringImp::convertUTF8ToUnicode(worldData->Name.c_str()).c_str());
node->setIcon(GUI::ESystemIcon::Poly);
node->setTagData(entity, CHierachyNode::Entity);

treeNodes[entity->getIndex()] = node;

setNodeEvent(node);
}
}
Expand Down
25 changes: 25 additions & 0 deletions Projects/Skylicht/Engine/Source/Entity/CEntityHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,29 @@ namespace Skylicht
}
}
}

void CEntityHandler::setEntities(CEntity** entities, int count)
{
m_entities.clear();
for (int i = 0; i < count; i++)
{
CEntity* entity = entities[i];
CWorldTransformData* transformData = entity->addData<CWorldTransformData>();

// assign name
if (transformData != NULL && transformData->Name.empty())
{
char name[512];
sprintf(name, "#%d", entity->getIndex());
transformData->Name = name;
}

// generate id for entity
std::string id = m_gameObject->getZone()->generateRandomID();
entity->setID(id.c_str());

// add to handler
m_entities.push_back(entity);
}
}
}
5 changes: 5 additions & 0 deletions Projects/Skylicht/Engine/Source/Entity/CEntityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ namespace Skylicht
{
return m_entities;
}

protected:

void setEntities(CEntity** entities, int count);

};
}
12 changes: 8 additions & 4 deletions Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ namespace Skylicht
if (m_gameObject != NULL)
{
CEntityManager* entityManager = m_gameObject->getEntityManager();
for (u32 i = 0, n = m_entities.size(); i < n; i++)
entityManager->removeEntity(m_entities[i]);
for (u32 i = 0, n = m_allEntities.size(); i < n; i++)
entityManager->removeEntity(m_allEntities[i]);
}

m_entities.clear();
m_allEntities.clear();
m_renderers.clear();
m_entities.clear();
}

void CRenderMesh::initComponent()
Expand Down Expand Up @@ -189,7 +190,7 @@ namespace Skylicht

// spawn childs entity
int numEntities = prefab->getNumEntities();
CEntity** entities = entityManager->createEntity(numEntities, m_entities);
CEntity** entities = entityManager->createEntity(numEntities, m_allEntities);

// map new entity index from src prefab
std::map<int, int> entityIndex;
Expand Down Expand Up @@ -270,6 +271,9 @@ namespace Skylicht

bool addInvData = false;

// for handler on Editor UI
setEntities(entities, numEntities);

// re-map joint with new entity in CEntityManager
for (CRenderMeshData*& r : m_renderers)
{
Expand Down
8 changes: 4 additions & 4 deletions Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ This file is part of the "Skylicht Engine".
#pragma once

#include "Entity/CEntityPrefab.h"
#include "Components/CComponentSystem.h"
#include "Entity/CEntityHandler.h"
#include "Material/CMaterial.h"
#include "Material/CMaterialManager.h"
#include "RenderMesh/CRenderMeshData.h"
#include "Transform/CWorldTransformData.h"

namespace Skylicht
{
class CRenderMesh : public CComponentSystem
class CRenderMesh : public CEntityHandler
{
protected:
CEntity* m_root;
core::array<CEntity*> m_entities;
core::array<CEntity*> m_allEntities;

std::vector<CWorldTransformData*> m_renderTransforms;
std::vector<CWorldTransformData*> m_transforms;
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace Skylicht

core::array<CEntity*>& getEntities()
{
return m_entities;
return m_allEntities;
}

std::vector<CRenderMeshData*>& getRenderers()
Expand Down

0 comments on commit d23fe77

Please sign in to comment.