Skip to content

Commit

Permalink
Update editor build/load NavMesh, WalkingMap
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Dec 11, 2024
1 parent df1b310 commit ea4e315
Show file tree
Hide file tree
Showing 14 changed files with 824 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ jobs:
-DBUILD_SKYLICHT_NETWORK=OFF
-DBUILD_SKYLICHT_PHYSIC=OFF
-DBUILD_SPINE_RUNTIMES=OFF
-DBUILD_RECAST_GRAPH=OFF
-DBUILD_SKYLICHT_GRAPH=OFF
-DBUILD_EXAMPLES=OFF
-DBUILD_EDITOR_TOOL=OFF
- name: Build Project
Expand Down
28 changes: 28 additions & 0 deletions Projects/Editor/Source/Editor/CEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ This file is part of the "Skylicht Engine".
#include "Activator/CEditorActivator.h"
#include "ProjectSettings/CProjectSettings.h"

#ifdef BUILD_SKYLICHT_GRAPH
#include "Space/BuildWalkingMap/CSpaceBuildWalkingMap.h"
#endif

namespace Skylicht
{
namespace Editor
Expand Down Expand Up @@ -301,6 +305,24 @@ namespace Skylicht
spaceApplyTemplate->applyTemplate(path);
}

#ifdef BUILD_SKYLICHT_GRAPH
void CEditor::initBuildWalkMap(Graph::CGraphComponent* component)
{
m_waitingDialog = new GUI::CDialogWindow(m_canvas, 0.0f, 0.0f, 600.0f, 120.0f);
m_waitingDialog->setCaption(L"Build walking map");
m_waitingDialog->showCloseButton(false);
m_waitingDialog->setCenterPosition();
m_waitingDialog->bringToFront();

initWorkspace(m_waitingDialog, m_waitingDialog->getCaption());

CSpace* space = getWorkspace(m_waitingDialog);

CSpaceBuildWalkingMap* spaceBuild = dynamic_cast<CSpaceBuildWalkingMap*>(space);
spaceBuild->build(component);
}
#endif

void CEditor::initEditorGUI()
{
// bind save layout function
Expand Down Expand Up @@ -641,6 +663,12 @@ namespace Skylicht
{
ret = new CSpaceLoadScene(window, this);
}
#ifdef BUILD_SKYLICHT_GRAPH
else if (workspace == L"Build walking map")
{
ret = new CSpaceBuildWalkingMap(window, this);
}
#endif

if (ret)
m_workspaces.push_back(ret);
Expand Down
8 changes: 8 additions & 0 deletions Projects/Editor/Source/Editor/CEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ This file is part of the "Skylicht Engine".
#include "Graphics2D/SpriteFrame/CSpriteAtlas.h"
#include "Utils/CSingleton.h"

#ifdef BUILD_SKYLICHT_GRAPH
#include "Graph/CGraphComponent.h"
#endif

namespace Skylicht
{
namespace Editor
Expand Down Expand Up @@ -77,6 +81,10 @@ namespace Skylicht

void initApplyTemplateGUI(const char* path);

#ifdef BUILD_SKYLICHT_GRAPH
void initBuildWalkMap(Graph::CGraphComponent* component);
#endif

void initEditorGUI();

bool isUIInitiate()
Expand Down
26 changes: 24 additions & 2 deletions Projects/Editor/Source/Editor/Components/Graph/CGraphEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace Skylicht
CGraphComponent* graph = (CGraphComponent*)m_component;
graph->buildRecastMesh();
};

ui->addButton(layout, L"Save RecastMesh")->OnPress = [&](GUI::CBase* button)
{
CSceneController* controller = CSceneController::getInstance();
Expand Down Expand Up @@ -92,12 +91,35 @@ namespace Skylicht
};
layout->addSpace(5.0f);
}
else if (data->Name == "inputObstacle")
else if (data->Name == "recastMesh")
{
layout->addSpace(5.0f);
ui->addButton(layout, L"Load RecastMesh")->OnPress = [&](GUI::CBase* button)
{
CGraphComponent* graph = (CGraphComponent*)m_component;
graph->loadRecastMesh();
};
ui->addButton(layout, L"Build WalkingTilemap")->OnPress = [&](GUI::CBase* button)
{
CGraphComponent* graph = (CGraphComponent*)m_component;
CEditor::getInstance()->initBuildWalkMap(graph);
};
layout->addSpace(5.0f);
ui->addButton(layout, L"Save WalkingTilemap")->OnPress = [&](GUI::CBase* button)
{
CGraphComponent* graph = (CGraphComponent*)m_component;

};
ui->addButton(layout, L"Load WalkingTilemap")->OnPress = [&](GUI::CBase* button)
{
CGraphComponent* graph = (CGraphComponent*)m_component;

};
layout->addSpace(5.0f);
ui->addButton(layout, L"Release")->OnPress = [&](GUI::CBase* button)
{
CGraphComponent* graph = (CGraphComponent*)m_component;
graph->release();
};
layout->addSpace(5.0f);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
!@
MIT License
Copyright (c) 2024 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "GUI/GUIContext.h"
#include "CSpaceBuildWalkingMap.h"
#include "Scene/CSceneImporter.h"
#include "Editor/SpaceController/CSceneController.h"

#ifdef BUILD_SKYLICHT_GRAPH

namespace Skylicht
{
namespace Editor
{
CSpaceBuildWalkingMap::CSpaceBuildWalkingMap(GUI::CWindow* window, CEditor* editor) :
CSpaceLoading(window, editor),
m_startLoading(false),
m_progressBar(NULL),
m_statusText(NULL),
m_component(NULL)
{
m_progressBar = new GUI::CProgressBar(window);
m_progressBar->dock(GUI::EPosition::Top);
m_progressBar->setMargin(GUI::SMargin(14.0f, 14.0, 14.0, 0.0f));

m_statusText = new GUI::CLabel(window);
m_statusText->dock(GUI::EPosition::Fill);
m_statusText->setMargin(GUI::SMargin(14.0f, 5.0, 14.0, 0.0f));
m_statusText->setWrapMultiline(true);
m_statusText->setString(L"Build Walking map...");
}

CSpaceBuildWalkingMap::~CSpaceBuildWalkingMap()
{

}

void CSpaceBuildWalkingMap::update()
{
CSpace::update();

if (m_startLoading)
{
m_startLoading = false;
if (!m_component->beginBuildWalkingMap())
{
m_finished = true;
}
}

if (m_finished == false)
{
m_finished = m_component->updateBuildWalkingMap();
}

m_progressBar->setPercent(m_component->getBuildPercent());

if (m_finished == true)
{

}
}

void CSpaceBuildWalkingMap::onDestroy(GUI::CBase* base)
{
CSpace::onDestroy(base);
}

void CSpaceBuildWalkingMap::build(Graph::CGraphComponent* component)
{
m_startLoading = true;
m_component = component;
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
!@
MIT License
Copyright (c) 2024 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#pragma once

#include "SkylichtEngine.h"
#include "Editor/Space/CSpaceLoading.h"

#ifdef BUILD_SKYLICHT_GRAPH
#include "Graph/CGraphComponent.h"

namespace Skylicht
{
namespace Editor
{
class CSpaceBuildWalkingMap : public CSpaceLoading
{
protected:

bool m_startLoading;

protected:
GUI::CProgressBar* m_progressBar;

GUI::CLabel* m_statusText;

Graph::CGraphComponent* m_component;

public:
CSpaceBuildWalkingMap(GUI::CWindow* window, CEditor* editor);

virtual ~CSpaceBuildWalkingMap();

virtual void update();

virtual void onDestroy(GUI::CBase* base);

void build(Graph::CGraphComponent* component);
};
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ namespace Skylicht
node->setTagData(newObject, CHierachyNode::GameObject);

setNodeEvent(node);
CHierarchyController::updateObjectToUI(newObject, node);

if (m_spaceHierarchy != NULL)
m_spaceHierarchy->addToTreeNode(node);
Expand Down Expand Up @@ -928,6 +929,7 @@ namespace Skylicht
node->setTagData(newObject, CHierachyNode::Container);

setNodeEvent(node);
CHierarchyController::updateObjectToUI(newObject, node);

if (m_spaceHierarchy != NULL)
m_spaceHierarchy->addToTreeNode(node);
Expand Down Expand Up @@ -966,6 +968,7 @@ namespace Skylicht
node->setTagData(newObject, CHierachyNode::GameObject);

setNodeEvent(node);
CHierarchyController::updateObjectToUI(newObject, node);

rebuildHierarchyEntityData(newObject, node);

Expand Down
23 changes: 23 additions & 0 deletions Projects/Editor/Source/GizmosComponents/Graph/CGGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ namespace Skylicht
CMesh* mesh = m_graph->getNavMesh();

SColor white(255, 255, 255, 255);
SColor red(255, 255, 0, 0);
SColor yellow(255, 255, 255, 0);

CHandles* handles = CHandles::getInstance();

for (u32 i = 0, n = mesh->getMeshBufferCount(); i < n; i++)
Expand All @@ -91,6 +94,26 @@ namespace Skylicht
handles->drawLine(p3->Pos, p1->Pos, white);
}
}

Graph::CObstacleAvoidance* obstacle = m_graph->getObstacle();
core::array<core::line3df>& segments = obstacle->getSegments();
for (u32 i = 0, n = segments.size(); i < n; i++)
{
handles->drawLine(segments[i].start, segments[i].end, red);
}

core::vector3df halfHeight(0.0f, 0.2f, 0.0f);
Graph::CWalkingTileMap* walkMap = m_graph->getWalkingMap();

walkMap->resetVisit();
core::array<Graph::STile*>& tiles = walkMap->getTiles();
for (u32 i = 0, n = tiles.size(); i < n; i++)
{
Graph::STile* tile = tiles[i];
handles->drawLine(tile->Position, tile->Position + halfHeight, yellow);
tile->Visit = true;
}
walkMap->resetVisit();
}
}
}
Expand Down
Loading

0 comments on commit ea4e315

Please sign in to comment.