From 79f56b60a001e5fe553aacb815a883959fe3e392 Mon Sep 17 00:00:00 2001 From: Atdunbg Date: Sun, 8 Mar 2026 00:22:12 +0800 Subject: [PATCH] replace mesh load texture from native create to AssetsManager::GetAsset; renderer.h add Submit::pFunc->~FuncT(); fix PhysicsWrappers::CreateTriamgleMesh() error collider collect; remove unused ChildrenComponent; AssetEditorPanel now will auto save(serialize) when the window closed --- Editor/Editor/EditorLayer.cpp | 2 +- Prism/src/Prism/Asset/Asset.h | 3 +- Prism/src/Prism/Asset/AssetSerializer.cpp | 20 +++- Prism/src/Prism/Asset/AssetsManager.cpp | 18 +++- Prism/src/Prism/Core/Core.cpp | 2 + Prism/src/Prism/Core/ImGui/ImGui.cpp | 2 +- Prism/src/Prism/Core/ImGui/ImGui.h | 2 + Prism/src/Prism/Core/Log.cpp | 34 +++++++ Prism/src/Prism/Core/Log.h | 1 + Prism/src/Prism/Core/Ref.h | 13 ++- Prism/src/Prism/Editor/AssetEditorPanel.cpp | 7 +- Prism/src/Prism/Editor/AssetEditorPanel.h | 2 + .../src/Prism/Editor/ContentBrowserPanel.cpp | 11 ++- .../src/Prism/Editor/DefaultAssetEditors.cpp | 7 +- Prism/src/Prism/Editor/DefaultAssetEditors.h | 2 + Prism/src/Prism/Editor/SceneHierachyPanel.cpp | 96 +++++++------------ Prism/src/Prism/Physics/PhysicsWrappers.cpp | 9 +- Prism/src/Prism/Renderer/Mesh.cpp | 12 ++- Prism/src/Prism/Renderer/Renderer.h | 2 +- Prism/src/Prism/Scene/Components.h | 8 -- Prism/src/Prism/Scene/Scene.cpp | 4 +- Prism/src/Prism/Scene/Scene.h | 2 +- Prism/src/Prism/Utilities/StringUtils.cpp | 15 +++ Prism/src/Prism/Utilities/StringUtils.h | 3 + 24 files changed, 180 insertions(+), 97 deletions(-) diff --git a/Editor/Editor/EditorLayer.cpp b/Editor/Editor/EditorLayer.cpp index d14a0ab..61ef8b1 100644 --- a/Editor/Editor/EditorLayer.cpp +++ b/Editor/Editor/EditorLayer.cpp @@ -483,7 +483,6 @@ namespace Prism } ImGui::End(); - m_SceneHierarchyPanel->OnImGuiRender(); PhysicsSettingsWindow::OnImGuiRender(m_ShowPhysicsSettings); SceneRenderer::OnImGuiRender(); AssetEditorPanel::OnImGuiRender(); @@ -492,6 +491,7 @@ namespace Prism m_ContentBrowserPanel->OnImGuiRender(); m_ObjectsPanel->OnImGuiRender(); + m_SceneHierarchyPanel->OnImGuiRender(); // Editor Panel ------------------------------------------------------------------------------ ImGui::Begin("Environment"); diff --git a/Prism/src/Prism/Asset/Asset.h b/Prism/src/Prism/Asset/Asset.h index 267c1ba..fe164a7 100644 --- a/Prism/src/Prism/Asset/Asset.h +++ b/Prism/src/Prism/Asset/Asset.h @@ -12,7 +12,7 @@ namespace Prism { enum class AssetType { - Scene = 0, Mesh, Texture, EnvMap, Audio, Script, PhysicsMat, Directory, Other, None + Scene = 0, Mesh, Texture, EnvMap, Audio, Script, PhysicsMaterial, Directory, Other, None }; using AssetHandle = UUID; @@ -47,6 +47,7 @@ namespace Prism PhysicsMaterial(float staticFriction, float dynamicFriction, float bounciness) : StaticFriction(staticFriction), DynamicFriction(dynamicFriction), Bounciness(bounciness) { + Type = AssetType::PhysicsMaterial; } }; diff --git a/Prism/src/Prism/Asset/AssetSerializer.cpp b/Prism/src/Prism/Asset/AssetSerializer.cpp index 4ef43c9..b2b51a3 100644 --- a/Prism/src/Prism/Asset/AssetSerializer.cpp +++ b/Prism/src/Prism/Asset/AssetSerializer.cpp @@ -4,6 +4,7 @@ #include "AssetSerializer.h" +#include "AssetsManager.h" #include "Prism/Utilities/StringUtils.h" #include "Prism/Utilities/FileSystem.h" #include "Prism/Renderer/Mesh.h" @@ -20,11 +21,24 @@ namespace Prism { YAML::Emitter out; + switch (type) + { + case AssetType::Texture: + case AssetType::EnvMap: + case AssetType::Audio: + case AssetType::Script: + case AssetType::Directory: + case AssetType::Other: + case AssetType::None: + return; + } + + out << YAML::BeginMap; switch (type) { - case Prism::AssetType::PhysicsMat: + case Prism::AssetType::PhysicsMaterial: { Ref material = Ref(asset); out << YAML::Key << "StaticFriction" << material->StaticFriction; @@ -47,7 +61,7 @@ namespace Prism YAML::Node data = YAML::Load(strStream.str()); - if (asset->Type == AssetType::PhysicsMat) + if (asset->Type == AssetType::PhysicsMaterial) { float staticFriction = data["StaticFriction"].as(); float dynamicFriction = data["DynamicFriction"].as(); @@ -136,7 +150,7 @@ namespace Prism loadYAMLData = false; break; } - case AssetType::PhysicsMat: + case AssetType::PhysicsMaterial: break; } diff --git a/Prism/src/Prism/Asset/AssetsManager.cpp b/Prism/src/Prism/Asset/AssetsManager.cpp index 9026c1b..d911096 100644 --- a/Prism/src/Prism/Asset/AssetsManager.cpp +++ b/Prism/src/Prism/Asset/AssetsManager.cpp @@ -25,9 +25,10 @@ namespace Prism s_Types["fbx"] = AssetType::Mesh; s_Types["obj"] = AssetType::Mesh; s_Types["png"] = AssetType::Texture; + s_Types["tga"] = AssetType::Texture; s_Types["hdr"] = AssetType::EnvMap; s_Types["blend"] = AssetType::Mesh; - s_Types["hpm"] = AssetType::PhysicsMat; + s_Types["hpm"] = AssetType::PhysicsMaterial; s_Types["wav"] = AssetType::Audio; s_Types["ogg"] = AssetType::Audio; s_Types["cs"] = AssetType::Script; @@ -39,7 +40,7 @@ namespace Prism } std::map AssetTypes::s_Types; - AssetsManager::AssetsChangeEventFn AssetsManager::s_AssetsChangeCallback; + AssetsManager::AssetsChangeEventFn AssetsManager::s_AssetsChangeCallback = nullptr; std::unordered_map> AssetsManager::s_LoadedAssets; void AssetsManager::Init() @@ -107,11 +108,18 @@ namespace Prism return false; } + AssetHandle AssetsManager::GetAssetHandleFromFilePath(const std::string& filepath) { + const std::string normalizedPath = Utils::NormalizePath(filepath); for (auto&[id, asset] : s_LoadedAssets) { - if (asset->FilePath == filepath) + if (asset->FilePath == normalizedPath) + return id; + + const std::string normalizedPathToLower = Utils::StringToLower(normalizedPath); + const std::string assetFilePath = Utils::StringToLower(asset->FilePath); + if (assetFilePath == normalizedPathToLower) return id; } @@ -149,7 +157,10 @@ namespace Prism Ref asset = s_LoadedAssets[assetHandle]; if (!asset->IsDataLoaded && loadData) + { asset = AssetSerializer::LoadAssetData(asset); + s_LoadedAssets[assetHandle] = asset; + } return asset.As(); } @@ -189,6 +200,7 @@ namespace Prism asset->Extension = Utils::GetFilename(filename); asset->ParentDirectory = directoryHandle; asset->Handle = std::hash()(asset->FilePath); + asset->IsDataLoaded = true; s_LoadedAssets[asset->Handle] = asset; AssetSerializer::SerializeAsset(asset); diff --git a/Prism/src/Prism/Core/Core.cpp b/Prism/src/Prism/Core/Core.cpp index 75265f6..f33f22d 100644 --- a/Prism/src/Prism/Core/Core.cpp +++ b/Prism/src/Prism/Core/Core.cpp @@ -20,6 +20,8 @@ namespace Prism { void ShutdownCore() { PM_CORE_TRACE("Shutting down..."); + + Log::Shutdown(); } } diff --git a/Prism/src/Prism/Core/ImGui/ImGui.cpp b/Prism/src/Prism/Core/ImGui/ImGui.cpp index 6dca9c9..aa20969 100644 --- a/Prism/src/Prism/Core/ImGui/ImGui.cpp +++ b/Prism/src/Prism/Core/ImGui/ImGui.cpp @@ -11,7 +11,7 @@ namespace Prism::UI void Image(const Ref& texture, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col) { - ImGui::PushID(texture->Handle); + ImGui::PushID(&texture->Handle); if (RendererAPI::Current() == RendererAPIType::OpenGL) { ImGui::Image((ImTextureID)texture->GetRendererID(), size, uv0, uv1, tint_col, border_col); diff --git a/Prism/src/Prism/Core/ImGui/ImGui.h b/Prism/src/Prism/Core/ImGui/ImGui.h index 4f3b289..6b6e462 100644 --- a/Prism/src/Prism/Core/ImGui/ImGui.h +++ b/Prism/src/Prism/Core/ImGui/ImGui.h @@ -440,6 +440,7 @@ namespace Prism::UI { static bool PropertyAssetReference(const char* label, Ref& object, const AssetType supportedType) { bool modified = false; + ImGui::PushID(label); ImGui::Text("%s", label); ImGui::NextColumn(); @@ -471,6 +472,7 @@ namespace Prism::UI { ImGui::PopItemWidth(); ImGui::NextColumn(); + ImGui::PopID(); return modified; } diff --git a/Prism/src/Prism/Core/Log.cpp b/Prism/src/Prism/Core/Log.cpp index d9495d2..91c507c 100644 --- a/Prism/src/Prism/Core/Log.cpp +++ b/Prism/src/Prism/Core/Log.cpp @@ -5,7 +5,11 @@ #include "pmpch.h" #include "Log.h" +#include + +#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/stdout_color_sinks-inl.h" +#include "spdlog/sinks/stdout_sinks.h" #ifdef _DEBUG #define LOG_LEVEL spdlog::level::trace @@ -20,12 +24,42 @@ namespace Prism void Log::Init() { + const std::string logsDirectory = "logs"; + if (!std::filesystem::exists(logsDirectory)) + std::filesystem::create_directories(logsDirectory); + + std::vector prismSinks = + { + std::make_shared(), + std::make_shared("logs/PRISM.log", true) + }; + + std::vector appSinks = + { + std::make_shared(), + std::make_shared("logs/APP.log", true) + }; + + s_CoreLogger = std::make_shared("PRISM", prismSinks.begin(), prismSinks.end()); + s_CoreLogger->set_level(LOG_LEVEL); + + s_ClientLogger = std::make_shared("APP", appSinks.begin(), appSinks.end()); + s_ClientLogger->set_level(LOG_LEVEL); + /* spdlog::set_pattern("%^[%T] [%n]%v%$"); s_CoreLogger = spdlog::stdout_color_mt("PRISM"); s_CoreLogger->set_level(LOG_LEVEL); s_ClientLogger = spdlog::stdout_color_mt("APP"); s_ClientLogger->set_level(LOG_LEVEL); + */ + } + + void Log::Shutdown() + { + s_ClientLogger.reset(); + s_ClientLogger.reset(); + spdlog::drop_all(); } const std::shared_ptr& Log::GetCoreLogger() diff --git a/Prism/src/Prism/Core/Log.h b/Prism/src/Prism/Core/Log.h index 41b970c..068a26e 100644 --- a/Prism/src/Prism/Core/Log.h +++ b/Prism/src/Prism/Core/Log.h @@ -14,6 +14,7 @@ namespace Prism { public: static void Init(); + static void Shutdown(); PRISM_API static const std::shared_ptr& GetCoreLogger(); PRISM_API static const std::shared_ptr& GetClientLogger(); diff --git a/Prism/src/Prism/Core/Ref.h b/Prism/src/Prism/Core/Ref.h index 3759d88..624083d 100644 --- a/Prism/src/Prism/Core/Ref.h +++ b/Prism/src/Prism/Core/Ref.h @@ -9,6 +9,8 @@ #include #include +#include "Log.h" + namespace Prism { class PRISM_API RefCounted @@ -138,7 +140,13 @@ namespace Prism private: void IncRef() const { - if (m_Instance) m_Instance->IncRefCount(); + if (m_Instance) + { + m_Instance->IncRefCount(); + // PM_CORE_DEBUG("{"); + // PM_CORE_DEBUG("{0}:{1}: +{2}",(uint64_t)(&m_Instance), typeid(*m_Instance).name(), m_Instance->GetRefCount()); + // if (m_Instance->GetRefCount() >= 1000) PM_CORE_ASSERT(false); + } } void DecRef() const @@ -146,8 +154,11 @@ namespace Prism if (m_Instance) { m_Instance->DecRefCount(); + // PM_CORE_DEBUG("{0}:{1}: -{2}",(uint64_t)(&m_Instance), typeid(*m_Instance).name(), m_Instance->GetRefCount()); + // PM_CORE_DEBUG("}"); if (m_Instance->GetRefCount() == 0) { + // PM_CORE_DEBUG("{0}:{1}: delete",(uint64_t)(&m_Instance), typeid(*m_Instance).name()); delete m_Instance; } } diff --git a/Prism/src/Prism/Editor/AssetEditorPanel.cpp b/Prism/src/Prism/Editor/AssetEditorPanel.cpp index e6f23d7..c6cd8bd 100644 --- a/Prism/src/Prism/Editor/AssetEditorPanel.cpp +++ b/Prism/src/Prism/Editor/AssetEditorPanel.cpp @@ -5,6 +5,7 @@ #include "AssetEditorPanel.h" #include "DefaultAssetEditors.h" +#include "Prism/Asset/AssetSerializer.h" #include "Prism/Core/Log.h" namespace Prism @@ -23,6 +24,10 @@ namespace Prism ImGui::Begin(m_Title, &m_IsOpen, m_Flags); Render(); ImGui::End(); + if (!m_IsOpen) + { + AssetSerializer::SerializeAsset(GetAsset()); + } } void AssetEditor::SetMinSize(uint32_t width, uint32_t height) @@ -46,7 +51,7 @@ namespace Prism void AssetEditorPanel::RegisterDefaultEditors() { RegisterEditor(AssetType::Texture); - RegisterEditor(AssetType::PhysicsMat); + RegisterEditor(AssetType::PhysicsMaterial); } void AssetEditorPanel::OnImGuiRender() diff --git a/Prism/src/Prism/Editor/AssetEditorPanel.h b/Prism/src/Prism/Editor/AssetEditorPanel.h index 01f15a4..d3ed884 100644 --- a/Prism/src/Prism/Editor/AssetEditorPanel.h +++ b/Prism/src/Prism/Editor/AssetEditorPanel.h @@ -17,6 +17,8 @@ namespace Prism void OnImGuiRender(); void SetOpen(const bool isOpen) { m_IsOpen = isOpen; } + + virtual Ref GetAsset() = 0; virtual void SetAsset(const Ref& asset) = 0; protected: diff --git a/Prism/src/Prism/Editor/ContentBrowserPanel.cpp b/Prism/src/Prism/Editor/ContentBrowserPanel.cpp index 764dd6c..3c37eee 100644 --- a/Prism/src/Prism/Editor/ContentBrowserPanel.cpp +++ b/Prism/src/Prism/Editor/ContentBrowserPanel.cpp @@ -144,7 +144,7 @@ namespace Prism if (ImGui::MenuItem("Physics Material")) { // TODO: use template - AssetsManager::CreateAssetPhysicsMaterial("New Physics Material.hpm", AssetType::PhysicsMat, m_CurrentDirHandle, 0.6f, 0.6f, 0.0f); + AssetsManager::CreateAssetPhysicsMaterial("New Physics Material.hpm", AssetType::PhysicsMaterial, m_CurrentDirHandle, 0.6f, 0.6f, 0.0f); UpdateCurrentDirectory(m_CurrentDirHandle); } @@ -248,7 +248,12 @@ namespace Prism ImGui::PushID(&asset->Handle); ImGui::BeginGroup(); - const RendererID iconRef = m_AssetIconMap.find(asset->Extension) != m_AssetIconMap.end() ? m_AssetIconMap[asset->Extension]->GetRendererID() : m_FileTex->GetRendererID(); + RendererID iconRef = m_AssetIconMap.find(asset->Extension) != m_AssetIconMap.end() ? m_AssetIconMap[asset->Extension]->GetRendererID() : m_FileTex->GetRendererID(); + + if (asset->Type == AssetType::Texture && asset->IsDataLoaded) + { + iconRef = asset.As()->GetRendererID(); + } if (m_SelectedAssets.IsSelected(assetHandle)) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.25f, 0.25f, 0.25f, 0.75f)); @@ -397,7 +402,7 @@ namespace Prism } - if (!m_SelectedAssets.IsSelected(asset->Handle) || m_IsDragging) + if (!m_SelectedAssets.IsSelected(asset->Handle)) return; if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlapped) && ImGui::IsItemClicked(ImGuiMouseButton_Left)) diff --git a/Prism/src/Prism/Editor/DefaultAssetEditors.cpp b/Prism/src/Prism/Editor/DefaultAssetEditors.cpp index 2b87f51..311066c 100644 --- a/Prism/src/Prism/Editor/DefaultAssetEditors.cpp +++ b/Prism/src/Prism/Editor/DefaultAssetEditors.cpp @@ -4,6 +4,8 @@ #include "DefaultAssetEditors.h" +#include "Prism/Asset/AssetSerializer.h" + namespace Prism { @@ -21,6 +23,9 @@ namespace Prism UI::Property("Dynamic Friction", m_Asset->DynamicFriction); UI::Property("Bounciness", m_Asset->Bounciness); UI::EndPropertyGrid(); + + if (ImGui::Button("Save")) + AssetSerializer::SerializeAsset(m_Asset); } @@ -53,4 +58,4 @@ namespace Prism UI::EndPropertyGrid(); } -} \ No newline at end of file +} diff --git a/Prism/src/Prism/Editor/DefaultAssetEditors.h b/Prism/src/Prism/Editor/DefaultAssetEditors.h index 112a32b..b367cd2 100644 --- a/Prism/src/Prism/Editor/DefaultAssetEditors.h +++ b/Prism/src/Prism/Editor/DefaultAssetEditors.h @@ -15,6 +15,7 @@ namespace Prism public: PhysicsMaterialEditor(); + virtual Ref GetAsset() override { return m_Asset; } virtual void SetAsset(const Ref& asset) override { m_Asset = (Ref)asset; } private: @@ -29,6 +30,7 @@ namespace Prism public: TextureViewer(); + virtual Ref GetAsset() override { return m_Asset; } virtual void SetAsset(const Ref& asset) override { m_Asset = static_cast>(asset); } private: diff --git a/Prism/src/Prism/Editor/SceneHierachyPanel.cpp b/Prism/src/Prism/Editor/SceneHierachyPanel.cpp index 0004e7a..51534da 100644 --- a/Prism/src/Prism/Editor/SceneHierachyPanel.cpp +++ b/Prism/src/Prism/Editor/SceneHierachyPanel.cpp @@ -172,7 +172,11 @@ namespace Prism void SceneHierarchyPanel::OnImGuiRender() { ImGui::Begin("Scene Hierarchy"); - const ImRect windowRect = { ImGui::GetWindowContentRegionMin(), ImGui::GetWindowContentRegionMax() }; + // const ImRect windowRect = { ImGui::GetWindowContentRegionMin(), ImGui::GetWindowContentRegionMax() }; + const ImVec2 windowPos = ImGui::GetWindowPos(); + const ImVec2 min = ImGui::GetWindowContentRegionMin(); + const ImVec2 max = ImGui::GetWindowContentRegionMax(); + const ImRect windowRect{ImVec2(windowPos.x + min.x, windowPos.y + min.y), ImVec2(windowPos.x + max.x, windowPos.y + max.y)}; if (m_Context) { @@ -186,7 +190,7 @@ namespace Prism if (ImGui::BeginDragDropTargetCustom(windowRect, ImGui::GetCurrentWindow()->ID)) { - const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("scene_entity_hierarchy", ImGuiDragDropFlags_AcceptNoDrawDefaultRect); + const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("scene_entity_hierarchy"); if (payload) { @@ -333,7 +337,7 @@ namespace Prism if (ImGui::BeginDragDropTarget()) { - const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("scene_entity_hierarchy", ImGuiDragDropFlags_AcceptNoDrawDefaultRect); + const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("scene_entity_hierarchy"); if (payload) { @@ -391,8 +395,6 @@ namespace Prism m_EntityDeletedCallback(entity); } - - } static std::tuple GetTransformDecomposition(const glm::mat4& transform) @@ -966,7 +968,7 @@ namespace Prism } UI::Property("IsTrigger", bcc.IsTrigger); - UI::PropertyAssetReference("Material", bcc.Material, AssetType::PhysicsMat); + UI::PropertyAssetReference("Material", bcc.Material, AssetType::PhysicsMaterial); UI::EndPropertyGrid(); }); @@ -981,7 +983,7 @@ namespace Prism } UI::Property("IsTrigger", scc.IsTrigger); - UI::PropertyAssetReference("Material", scc.Material, AssetType::PhysicsMat); + UI::PropertyAssetReference("Material", scc.Material, AssetType::PhysicsMaterial); UI::EndPropertyGrid(); }); @@ -996,7 +998,7 @@ namespace Prism if (UI::Property("Height", ccc.Height)) changed = true; UI::Property("Is Trigger", ccc.IsTrigger); - UI::PropertyAssetReference("Material", ccc.Material, AssetType::PhysicsMat); + UI::PropertyAssetReference("Material", ccc.Material, AssetType::PhysicsMaterial); if (changed) { @@ -1010,58 +1012,6 @@ namespace Prism { UI::BeginPropertyGrid(); - if (mcc.OverrideMesh) - { - if (UI::PropertyAssetReference("Mesh", mcc.CollisionMesh, AssetType::Mesh)) - { - if (mcc.IsConvex) - PhysicsWrappers::CreateConvexMesh(mcc, glm::vec3(1.0f)); - else - PhysicsWrappers::CreateTriangleMesh(mcc, glm::vec3(1.0f)); - } - /* - ImGui::Columns(3); - ImGui::SetColumnWidth(0, 100); - ImGui::SetColumnWidth(1, 250); - ImGui::SetColumnWidth(2, 40); - ImGui::Text("File Path"); - ImGui::NextColumn(); - ImGui::PushItemWidth(-1); - if (mcc.CollisionMesh) - ImGui::InputText("##meshfilepath", (char*)mcc.CollisionMesh->GetFilePath().c_str(), 256, ImGuiInputTextFlags_ReadOnly); - else - ImGui::InputText("##meshfilepath", (char*)"Null", 256, ImGuiInputTextFlags_ReadOnly); - ImGui::PopItemWidth(); - ImGui::NextColumn(); - if (ImGui::Button("...##openmesh")) - { - std::string file = Application::Get().OpenFile(); - if (!file.empty()) - { - mcc.CollisionMesh = Ref::Create(file); - if (mcc.IsConvex) - PhysicsWrappers::CreateConvexMesh(mcc, entity.Transform().Scale); - else - PhysicsWrappers::CreateTriangleMesh(mcc, entity.Transform().Scale); - } - } - ImGui::EndColumns(); - */ - } - - if (UI::Property("Is Convex", mcc.IsConvex)) - { - if (mcc.CollisionMesh) - { - if (mcc.IsConvex) - PhysicsWrappers::CreateConvexMesh(mcc); - else - PhysicsWrappers::CreateTriangleMesh(mcc); - } - } - - UI::Property("Is Trigger", mcc.IsTrigger); - UI::PropertyAssetReference("Material", mcc.Material, AssetType::PhysicsMat); if (UI::Property("Override Mesh", mcc.OverrideMesh)) { @@ -1076,6 +1026,32 @@ namespace Prism } } + if (mcc.OverrideMesh) + { + if (UI::PropertyAssetReference("Mesh", mcc.CollisionMesh, AssetType::Mesh)) + { + if (mcc.IsConvex) + PhysicsWrappers::CreateConvexMesh(mcc, glm::vec3(1.0f)); + else + PhysicsWrappers::CreateTriangleMesh(mcc, glm::vec3(1.0f)); + } + } + + if (UI::Property("Is Convex", mcc.IsConvex)) + { + if (mcc.CollisionMesh) + { + if (mcc.IsConvex) + PhysicsWrappers::CreateConvexMesh(mcc); + else + PhysicsWrappers::CreateTriangleMesh(mcc); + } + } + + UI::Property("Is Trigger", mcc.IsTrigger); + UI::PropertyAssetReference("Material", mcc.Material, AssetType::PhysicsMaterial); + + UI::EndPropertyGrid(); }); diff --git a/Prism/src/Prism/Physics/PhysicsWrappers.cpp b/Prism/src/Prism/Physics/PhysicsWrappers.cpp index d6bdd99..ab1f530 100644 --- a/Prism/src/Prism/Physics/PhysicsWrappers.cpp +++ b/Prism/src/Prism/Physics/PhysicsWrappers.cpp @@ -255,7 +255,7 @@ namespace Prism { auto& collider = actor.m_Entity.GetComponent(); if (!collider.Material) - collider.Material = Ref::Create(0.6F, 0.6F, 0.0f); + collider.Material = Ref::Create(0.6f, 0.6f, 0.0f); glm::vec3 scale = actor.m_Entity.Transform().Scale; physx::PxMaterial* material = s_Physics->createMaterial(collider.Material->StaticFriction, collider.Material->DynamicFriction, collider.Material->Bounciness); @@ -393,10 +393,9 @@ namespace Prism } } - glm::mat4 scale = glm::scale(glm::mat4(1.0f), *(glm::vec3*)&triangleGeometry.scale.scale); - glm::mat4 transform = FromPhysXTransform(shape->getLocalPose()) * scale; - collider.ProcessedMeshes.push_back(Ref::Create(vertices, indices, transform)); - // collider.ProcessedMeshes.push_back(Ref::Create(processedVertices, processedIndices, FromPhysXTransform(shape->getLocalPose()))); + glm::mat4 scale_mat = glm::scale(glm::mat4(1.0f), *(glm::vec3*)&triangleGeometry.scale.scale); + glm::mat4 transform = FromPhysXTransform(shape->getLocalPose()) * scale_mat; + collider.ProcessedMeshes.push_back(Ref::Create(processedVertices, processedIndices, transform)); } } diff --git a/Prism/src/Prism/Renderer/Mesh.cpp b/Prism/src/Prism/Renderer/Mesh.cpp index 8f727e5..fd5e047 100644 --- a/Prism/src/Prism/Renderer/Mesh.cpp +++ b/Prism/src/Prism/Renderer/Mesh.cpp @@ -294,7 +294,8 @@ namespace Prism std::string texturePath = parentPath.string(); PM_MESH_LOG(" Albedo map path = {0}", texturePath); - auto texture = Texture2D::Create(texturePath, true); + auto texture = AssetsManager::GetAsset(texturePath); + // auto texture = Texture2D::Create(texturePath, true); if (texture->Loaded()) { m_Textures[i] = texture; @@ -326,7 +327,8 @@ namespace Prism std::string texturePath = parentPath.string(); PM_MESH_LOG(" Normal map path = {0}", texturePath); - auto texture = Texture2D::Create(texturePath); + auto texture = AssetsManager::GetAsset(texturePath); + // auto texture = Texture2D::Create(texturePath); if (texture->Loaded()) { mi->Set("u_NormalTexture", texture); @@ -354,7 +356,8 @@ namespace Prism std::string texturePath = parentPath.string(); PM_MESH_LOG(" Roughness map path = {0}", texturePath); - auto texture = Texture2D::Create(texturePath); + auto texture = AssetsManager::GetAsset(texturePath); + // auto texture = Texture2D::Create(texturePath); if (texture->Loaded()) { PM_CORE_TRACE(" Roughness map path = {0}", texturePath); @@ -449,7 +452,8 @@ namespace Prism PM_MESH_LOG(" Metalness map path = {0}", texturePath); - auto texture = Texture2D::Create(texturePath); + auto texture = AssetsManager::GetAsset(texturePath); + // auto texture = Texture2D::Create(texturePath); if (texture->Loaded()) { mi->Set("u_MetalnessTexture", texture); diff --git a/Prism/src/Prism/Renderer/Renderer.h b/Prism/src/Prism/Renderer/Renderer.h index 5146c39..02ab038 100644 --- a/Prism/src/Prism/Renderer/Renderer.h +++ b/Prism/src/Prism/Renderer/Renderer.h @@ -39,7 +39,7 @@ namespace Prism // NOTE: Instead of destroying we could try and enforce all items to be trivally destructible // however some items like uniforms which contain std::strings still exist for now // static_assert(std::is_trivially_destructible_v, "FuncT must be trivially destructible"); - // pFunc->~FuncT(); + pFunc->~FuncT(); }; auto storageBuffer = GetRenderCommandQueue().Allocate(renderCmd, sizeof(func)); new (storageBuffer) FuncT(std::forward(func)); diff --git a/Prism/src/Prism/Scene/Components.h b/Prism/src/Prism/Scene/Components.h index 9bfd306..5818fa6 100644 --- a/Prism/src/Prism/Scene/Components.h +++ b/Prism/src/Prism/Scene/Components.h @@ -39,14 +39,6 @@ namespace Prism : ParentHandle(parent) {} }; - struct ChildrenComponent - { - std::vector Children; - - ChildrenComponent() = default; - ChildrenComponent(const ChildrenComponent& other) = default; - }; - struct TagComponent { std::string Tag; diff --git a/Prism/src/Prism/Scene/Scene.cpp b/Prism/src/Prism/Scene/Scene.cpp index 2ad88f6..b3bd442 100644 --- a/Prism/src/Prism/Scene/Scene.cpp +++ b/Prism/src/Prism/Scene/Scene.cpp @@ -620,7 +620,6 @@ namespace Prism entity.AddComponent(); entity.AddComponent(); - entity.AddComponent(); if (!name.empty()) entity.AddComponent(name); @@ -629,7 +628,7 @@ namespace Prism return entity; } - Entity Scene::CreateEntityWithID(UUID uuid, const std::string& name, bool runtimeMap) + Entity Scene::CreateEntityWithID(const UUID& uuid, const std::string& name, bool runtimeMap) { auto entity = Entity{ m_Registry.create(), this }; auto& idComponent = entity.AddComponent(); @@ -637,7 +636,6 @@ namespace Prism entity.AddComponent(); entity.AddComponent(); - entity.AddComponent(); if (!name.empty()) entity.AddComponent(name); diff --git a/Prism/src/Prism/Scene/Scene.h b/Prism/src/Prism/Scene/Scene.h index bd462d4..73051e4 100644 --- a/Prism/src/Prism/Scene/Scene.h +++ b/Prism/src/Prism/Scene/Scene.h @@ -77,7 +77,7 @@ namespace Prism void AddEntity(Entity* entity); Entity CreateEntity(const std::string& name = ""); - Entity CreateEntityWithID(UUID uuid, const std::string& name = "", bool runtimeMap = false); + Entity CreateEntityWithID(const UUID& uuid, const std::string& name = "", bool runtimeMap = false); void DestroyEntity(Entity entity); diff --git a/Prism/src/Prism/Utilities/StringUtils.cpp b/Prism/src/Prism/Utilities/StringUtils.cpp index a660245..7cd1426 100644 --- a/Prism/src/Prism/Utilities/StringUtils.cpp +++ b/Prism/src/Prism/Utilities/StringUtils.cpp @@ -65,5 +65,20 @@ namespace Prism::Utils return SplitString(string, std::string(1, delimiter)); } + std::string NormalizePath(std::string path) + { + std::replace(path.begin(), path.end(), '\\', '/'); + if (path.size() > 1 && path.back() == '/') + path.pop_back(); + return path; + } + std::string StringToLower(const std::string& str) + { + std::string result; + result.resize(str.size()); + std::transform(str.begin(), str.end(), result.begin(), + [](const unsigned char c) { return std::tolower(c); }); + return result; + } } diff --git a/Prism/src/Prism/Utilities/StringUtils.h b/Prism/src/Prism/Utilities/StringUtils.h index 4f99ec5..b4ccb1f 100644 --- a/Prism/src/Prism/Utilities/StringUtils.h +++ b/Prism/src/Prism/Utilities/StringUtils.h @@ -12,6 +12,9 @@ namespace Prism::Utils std::string GetFilename(const std::string& filepath); std::string GetExtension(const std::string& filename); std::string RemoveExtension(const std::string& filename); + std::string NormalizePath(std::string path); + std::string StringToLower(const std::string& str); + bool StartsWith(const std::string& string, const std::string& start); std::vector SplitString(const std::string& string, const std::string& delimiters); std::vector SplitString(const std::string& string, const char delimiter);