mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-03 14:09:46 +03:00
Now only drawing navmesh if selected + properly serialized
This commit is contained in:
@@ -367,11 +367,11 @@ public:
|
||||
Nuake::NavManager::Get().PushMesh(mesh, transformComponent.GetGlobalTransform());
|
||||
}
|
||||
}
|
||||
|
||||
auto recastConfig = RecastConfig(component);
|
||||
recastConfig.Position = volumeTransformComponent.GetGlobalPosition();
|
||||
NavManager::Get().BuildNavMesh(std::move(recastConfig));
|
||||
}
|
||||
|
||||
auto recastConfig = RecastConfig(component);
|
||||
recastConfig.Position = volumeTransformComponent.GetGlobalPosition();
|
||||
component.NavMeshData = NavManager::Get().BuildNavMesh(std::move(recastConfig));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,24 +54,8 @@ void EditorLayer::OnUpdate()
|
||||
|
||||
if (m_EditorInterface->ShouldDrawNavMesh())
|
||||
{
|
||||
auto cam = Engine::GetCurrentScene()->m_EditorCamera;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(glm::value_ptr(cam->GetPerspective()));
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(glm::value_ptr(cam->GetTransform()));
|
||||
|
||||
|
||||
glDepthFunc(GL_LESS);
|
||||
RenderCommand::Disable(RendererEnum::DEPTH_TEST);
|
||||
Nuake::NavManager::Get().DrawNavMesh();
|
||||
RenderCommand::Enable(RendererEnum::DEPTH_TEST);
|
||||
|
||||
Nuake::NavManager::Get().DrawNavMesh();
|
||||
glDepthFunc(GL_GREATER);
|
||||
Nuake::NavManager::Get().DrawNavMesh();
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
m_GizmoDrawer->DrawNavMesh(currentScene, true);
|
||||
}
|
||||
|
||||
if (m_EditorInterface->ShouldDrawCollision())
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <src/Scene/Components/ParticleEmitterComponent.h>
|
||||
#include <src/Scene/Components/BoneComponent.h>
|
||||
#include <src/Scene/Components/AudioEmitterComponent.h>
|
||||
#include <DetourDebugDraw.h>
|
||||
|
||||
|
||||
GizmoDrawer::GizmoDrawer(EditorInterface* editor)
|
||||
@@ -175,6 +176,23 @@ void GizmoDrawer::DrawAxis(Ref<Scene> scene, bool occluded)
|
||||
}
|
||||
}
|
||||
|
||||
void GizmoDrawer::DrawNavMesh(Ref<Scene> scene, bool occluded)
|
||||
{
|
||||
auto cam = Engine::GetCurrentScene()->m_EditorCamera;
|
||||
|
||||
auto navVolumesView = scene->m_Registry.view<TransformComponent, NavMeshVolumeComponent>();
|
||||
for (auto e : navVolumesView)
|
||||
{
|
||||
if (!IsEntityInSelection(Nuake::Entity{ (entt::entity)e, scene.get() }))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto [transform, navmesh] = scene->m_Registry.get<TransformComponent, NavMeshVolumeComponent>(e);
|
||||
duDebugDrawNavMesh(&m_DebugDrawer, *navmesh.NavMeshData->GetNavMesh(), DU_DRAWNAVMESH_OFFMESHCONS);
|
||||
}
|
||||
}
|
||||
|
||||
void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "Gizmos/CapsuleGizmo.h"
|
||||
#include "Gizmos/CylinderGizmo.h"
|
||||
#include "../Windows/EditorInterface.h"
|
||||
|
||||
#include "src/AI/NavMeshDebugDrawer.h"
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
@@ -20,7 +20,7 @@ class GizmoDrawer
|
||||
private:
|
||||
EditorInterface* m_Editor;
|
||||
Shader* m_LineShader;
|
||||
|
||||
NavMeshDebugDrawer m_DebugDrawer;
|
||||
std::map<std::string, Ref<Model>> m_Gizmos;
|
||||
std::map<uint32_t, Scope<CapsuleGizmo>> m_CapsuleGizmo;
|
||||
std::map<uint32_t, Scope<CylinderGizmo>> m_CylinderGizmo;
|
||||
@@ -54,8 +54,8 @@ public:
|
||||
~GizmoDrawer() = default;
|
||||
|
||||
void DrawGizmos(Ref<Scene> scene, bool occluded);
|
||||
void DrawAxis(Ref<Scene> scene, bool occlude);
|
||||
|
||||
void DrawAxis(Ref<Scene> scene, bool occluded);
|
||||
void DrawNavMesh(Ref<Scene> scene, bool occluded);
|
||||
private:
|
||||
void GenerateSphereGizmo();
|
||||
bool IsEntityInSelection(Nuake::Entity entity);
|
||||
|
||||
@@ -278,15 +278,9 @@ namespace Nuake {
|
||||
Logger::Log("Could not init Detour navmesh query", "NavManager", CRITICAL);
|
||||
}
|
||||
|
||||
Ref<NavMesh> navMesh = CreateRef<NavMesh>(m_DetourNavMesh, m_DetourNavQuery);
|
||||
|
||||
const std::string& deserializedNavMesh = navMesh->Serialize().dump(4);
|
||||
Logger::Log(deserializedNavMesh, "debug", VERBOSE);
|
||||
|
||||
Ref<NavMesh> navMesh2 = CreateRef<NavMesh>();
|
||||
navMesh->Deserialize(json::parse(deserializedNavMesh));
|
||||
m_Meshes.clear();
|
||||
|
||||
Ref<NavMesh> navMesh = CreateRef<NavMesh>(m_DetourNavMesh, m_DetourNavQuery);
|
||||
return navMesh;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,13 @@ namespace Nuake {
|
||||
json Serialize() override;
|
||||
bool Deserialize(const json& j) override;
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
return m_DetourNavMesh != nullptr && m_DetourNavQuery != nullptr;
|
||||
}
|
||||
|
||||
dtNavMesh* GetNavMesh() const { return m_DetourNavMesh; }
|
||||
|
||||
private:
|
||||
const dtMeshTile* GetTile(int i) const;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "../Entities/Entity.h"
|
||||
#include "Engine.h"
|
||||
#include <src/AI/NavMesh.h>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
@@ -25,12 +26,14 @@ namespace Nuake
|
||||
float DetailSampleDistance = 2.0f;
|
||||
float DetailsampleMaxError = 1.0f;
|
||||
|
||||
Ref<NavMesh> NavMeshData;
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VEC3(VolumeSize);
|
||||
SERIALIZE_VAL(OnlyIncludeMapGeometry);
|
||||
|
||||
SERIALIZE_OBJECT(NavMeshData);
|
||||
// Generation config
|
||||
END_SERIALIZE();
|
||||
}
|
||||
@@ -47,6 +50,12 @@ namespace Nuake
|
||||
DESERIALIZE_VAL(OnlyIncludeMapGeometry);
|
||||
}
|
||||
|
||||
if (j.contains("NavMeshData"))
|
||||
{
|
||||
NavMeshData = CreateRef<NavMesh>();
|
||||
NavMeshData->Deserialize(j["NavMeshData"]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
1
Resources/resources.rc
Normal file
1
Resources/resources.rc
Normal file
@@ -0,0 +1 @@
|
||||
appIcon ICON "nuake-logo.ico"
|
||||
Reference in New Issue
Block a user