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

This commit is contained in:
2026-03-08 00:22:12 +08:00
parent 57e14bc3d2
commit 79f56b60a0
24 changed files with 180 additions and 97 deletions

View File

@ -483,7 +483,6 @@ namespace Prism
} }
ImGui::End(); ImGui::End();
m_SceneHierarchyPanel->OnImGuiRender();
PhysicsSettingsWindow::OnImGuiRender(m_ShowPhysicsSettings); PhysicsSettingsWindow::OnImGuiRender(m_ShowPhysicsSettings);
SceneRenderer::OnImGuiRender(); SceneRenderer::OnImGuiRender();
AssetEditorPanel::OnImGuiRender(); AssetEditorPanel::OnImGuiRender();
@ -492,6 +491,7 @@ namespace Prism
m_ContentBrowserPanel->OnImGuiRender(); m_ContentBrowserPanel->OnImGuiRender();
m_ObjectsPanel->OnImGuiRender(); m_ObjectsPanel->OnImGuiRender();
m_SceneHierarchyPanel->OnImGuiRender();
// Editor Panel ------------------------------------------------------------------------------ // Editor Panel ------------------------------------------------------------------------------
ImGui::Begin("Environment"); ImGui::Begin("Environment");

View File

@ -12,7 +12,7 @@ namespace Prism
{ {
enum class AssetType 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; using AssetHandle = UUID;
@ -47,6 +47,7 @@ namespace Prism
PhysicsMaterial(float staticFriction, float dynamicFriction, float bounciness) PhysicsMaterial(float staticFriction, float dynamicFriction, float bounciness)
: StaticFriction(staticFriction), DynamicFriction(dynamicFriction), Bounciness(bounciness) : StaticFriction(staticFriction), DynamicFriction(dynamicFriction), Bounciness(bounciness)
{ {
Type = AssetType::PhysicsMaterial;
} }
}; };

View File

@ -4,6 +4,7 @@
#include "AssetSerializer.h" #include "AssetSerializer.h"
#include "AssetsManager.h"
#include "Prism/Utilities/StringUtils.h" #include "Prism/Utilities/StringUtils.h"
#include "Prism/Utilities/FileSystem.h" #include "Prism/Utilities/FileSystem.h"
#include "Prism/Renderer/Mesh.h" #include "Prism/Renderer/Mesh.h"
@ -20,11 +21,24 @@ namespace Prism
{ {
YAML::Emitter out; 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; out << YAML::BeginMap;
switch (type) switch (type)
{ {
case Prism::AssetType::PhysicsMat: case Prism::AssetType::PhysicsMaterial:
{ {
Ref<PhysicsMaterial> material = Ref<PhysicsMaterial>(asset); Ref<PhysicsMaterial> material = Ref<PhysicsMaterial>(asset);
out << YAML::Key << "StaticFriction" << material->StaticFriction; out << YAML::Key << "StaticFriction" << material->StaticFriction;
@ -47,7 +61,7 @@ namespace Prism
YAML::Node data = YAML::Load(strStream.str()); YAML::Node data = YAML::Load(strStream.str());
if (asset->Type == AssetType::PhysicsMat) if (asset->Type == AssetType::PhysicsMaterial)
{ {
float staticFriction = data["StaticFriction"].as<float>(); float staticFriction = data["StaticFriction"].as<float>();
float dynamicFriction = data["DynamicFriction"].as<float>(); float dynamicFriction = data["DynamicFriction"].as<float>();
@ -136,7 +150,7 @@ namespace Prism
loadYAMLData = false; loadYAMLData = false;
break; break;
} }
case AssetType::PhysicsMat: case AssetType::PhysicsMaterial:
break; break;
} }

View File

@ -25,9 +25,10 @@ namespace Prism
s_Types["fbx"] = AssetType::Mesh; s_Types["fbx"] = AssetType::Mesh;
s_Types["obj"] = AssetType::Mesh; s_Types["obj"] = AssetType::Mesh;
s_Types["png"] = AssetType::Texture; s_Types["png"] = AssetType::Texture;
s_Types["tga"] = AssetType::Texture;
s_Types["hdr"] = AssetType::EnvMap; s_Types["hdr"] = AssetType::EnvMap;
s_Types["blend"] = AssetType::Mesh; s_Types["blend"] = AssetType::Mesh;
s_Types["hpm"] = AssetType::PhysicsMat; s_Types["hpm"] = AssetType::PhysicsMaterial;
s_Types["wav"] = AssetType::Audio; s_Types["wav"] = AssetType::Audio;
s_Types["ogg"] = AssetType::Audio; s_Types["ogg"] = AssetType::Audio;
s_Types["cs"] = AssetType::Script; s_Types["cs"] = AssetType::Script;
@ -39,7 +40,7 @@ namespace Prism
} }
std::map<std::string, AssetType> AssetTypes::s_Types; std::map<std::string, AssetType> AssetTypes::s_Types;
AssetsManager::AssetsChangeEventFn AssetsManager::s_AssetsChangeCallback; AssetsManager::AssetsChangeEventFn AssetsManager::s_AssetsChangeCallback = nullptr;
std::unordered_map<AssetHandle, Ref<Asset>> AssetsManager::s_LoadedAssets; std::unordered_map<AssetHandle, Ref<Asset>> AssetsManager::s_LoadedAssets;
void AssetsManager::Init() void AssetsManager::Init()
@ -107,11 +108,18 @@ namespace Prism
return false; return false;
} }
AssetHandle AssetsManager::GetAssetHandleFromFilePath(const std::string& filepath) AssetHandle AssetsManager::GetAssetHandleFromFilePath(const std::string& filepath)
{ {
const std::string normalizedPath = Utils::NormalizePath(filepath);
for (auto&[id, asset] : s_LoadedAssets) 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; return id;
} }
@ -149,7 +157,10 @@ namespace Prism
Ref<Asset> asset = s_LoadedAssets[assetHandle]; Ref<Asset> asset = s_LoadedAssets[assetHandle];
if (!asset->IsDataLoaded && loadData) if (!asset->IsDataLoaded && loadData)
{
asset = AssetSerializer::LoadAssetData(asset); asset = AssetSerializer::LoadAssetData(asset);
s_LoadedAssets[assetHandle] = asset;
}
return asset.As<T>(); return asset.As<T>();
} }
@ -189,6 +200,7 @@ namespace Prism
asset->Extension = Utils::GetFilename(filename); asset->Extension = Utils::GetFilename(filename);
asset->ParentDirectory = directoryHandle; asset->ParentDirectory = directoryHandle;
asset->Handle = std::hash<std::string>()(asset->FilePath); asset->Handle = std::hash<std::string>()(asset->FilePath);
asset->IsDataLoaded = true;
s_LoadedAssets[asset->Handle] = asset; s_LoadedAssets[asset->Handle] = asset;
AssetSerializer::SerializeAsset(asset); AssetSerializer::SerializeAsset(asset);

View File

@ -20,6 +20,8 @@ namespace Prism {
void ShutdownCore() void ShutdownCore()
{ {
PM_CORE_TRACE("Shutting down..."); PM_CORE_TRACE("Shutting down...");
Log::Shutdown();
} }
} }

View File

@ -11,7 +11,7 @@ namespace Prism::UI
void Image(const Ref<Texture2D>& texture, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col) void Image(const Ref<Texture2D>& 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) if (RendererAPI::Current() == RendererAPIType::OpenGL)
{ {
ImGui::Image((ImTextureID)texture->GetRendererID(), size, uv0, uv1, tint_col, border_col); ImGui::Image((ImTextureID)texture->GetRendererID(), size, uv0, uv1, tint_col, border_col);

View File

@ -440,6 +440,7 @@ namespace Prism::UI {
static bool PropertyAssetReference(const char* label, Ref<T>& object, const AssetType supportedType) static bool PropertyAssetReference(const char* label, Ref<T>& object, const AssetType supportedType)
{ {
bool modified = false; bool modified = false;
ImGui::PushID(label);
ImGui::Text("%s", label); ImGui::Text("%s", label);
ImGui::NextColumn(); ImGui::NextColumn();
@ -471,6 +472,7 @@ namespace Prism::UI {
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::PopID();
return modified; return modified;
} }

View File

@ -5,7 +5,11 @@
#include "pmpch.h" #include "pmpch.h"
#include "Log.h" #include "Log.h"
#include <filesystem>
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks-inl.h" #include "spdlog/sinks/stdout_color_sinks-inl.h"
#include "spdlog/sinks/stdout_sinks.h"
#ifdef _DEBUG #ifdef _DEBUG
#define LOG_LEVEL spdlog::level::trace #define LOG_LEVEL spdlog::level::trace
@ -20,12 +24,42 @@ namespace Prism
void Log::Init() void Log::Init()
{ {
const std::string logsDirectory = "logs";
if (!std::filesystem::exists(logsDirectory))
std::filesystem::create_directories(logsDirectory);
std::vector<spdlog::sink_ptr> prismSinks =
{
std::make_shared<spdlog::sinks::stdout_sink_mt>(),
std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/PRISM.log", true)
};
std::vector<spdlog::sink_ptr> appSinks =
{
std::make_shared<spdlog::sinks::stdout_sink_mt>(),
std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/APP.log", true)
};
s_CoreLogger = std::make_shared<spdlog::logger>("PRISM", prismSinks.begin(), prismSinks.end());
s_CoreLogger->set_level(LOG_LEVEL);
s_ClientLogger = std::make_shared<spdlog::logger>("APP", appSinks.begin(), appSinks.end());
s_ClientLogger->set_level(LOG_LEVEL);
/*
spdlog::set_pattern("%^[%T] [%n]%v%$"); spdlog::set_pattern("%^[%T] [%n]%v%$");
s_CoreLogger = spdlog::stdout_color_mt("PRISM"); s_CoreLogger = spdlog::stdout_color_mt("PRISM");
s_CoreLogger->set_level(LOG_LEVEL); s_CoreLogger->set_level(LOG_LEVEL);
s_ClientLogger = spdlog::stdout_color_mt("APP"); s_ClientLogger = spdlog::stdout_color_mt("APP");
s_ClientLogger->set_level(LOG_LEVEL); s_ClientLogger->set_level(LOG_LEVEL);
*/
}
void Log::Shutdown()
{
s_ClientLogger.reset();
s_ClientLogger.reset();
spdlog::drop_all();
} }
const std::shared_ptr<spdlog::logger>& Log::GetCoreLogger() const std::shared_ptr<spdlog::logger>& Log::GetCoreLogger()

View File

@ -14,6 +14,7 @@ namespace Prism
{ {
public: public:
static void Init(); static void Init();
static void Shutdown();
PRISM_API static const std::shared_ptr<spdlog::logger>& GetCoreLogger(); PRISM_API static const std::shared_ptr<spdlog::logger>& GetCoreLogger();
PRISM_API static const std::shared_ptr<spdlog::logger>& GetClientLogger(); PRISM_API static const std::shared_ptr<spdlog::logger>& GetClientLogger();

View File

@ -9,6 +9,8 @@
#include <cstdint> #include <cstdint>
#include <type_traits> #include <type_traits>
#include "Log.h"
namespace Prism namespace Prism
{ {
class PRISM_API RefCounted class PRISM_API RefCounted
@ -138,7 +140,13 @@ namespace Prism
private: private:
void IncRef() const 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 void DecRef() const
@ -146,8 +154,11 @@ namespace Prism
if (m_Instance) if (m_Instance)
{ {
m_Instance->DecRefCount(); 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) if (m_Instance->GetRefCount() == 0)
{ {
// PM_CORE_DEBUG("{0}:{1}: delete",(uint64_t)(&m_Instance), typeid(*m_Instance).name());
delete m_Instance; delete m_Instance;
} }
} }

View File

@ -5,6 +5,7 @@
#include "AssetEditorPanel.h" #include "AssetEditorPanel.h"
#include "DefaultAssetEditors.h" #include "DefaultAssetEditors.h"
#include "Prism/Asset/AssetSerializer.h"
#include "Prism/Core/Log.h" #include "Prism/Core/Log.h"
namespace Prism namespace Prism
@ -23,6 +24,10 @@ namespace Prism
ImGui::Begin(m_Title, &m_IsOpen, m_Flags); ImGui::Begin(m_Title, &m_IsOpen, m_Flags);
Render(); Render();
ImGui::End(); ImGui::End();
if (!m_IsOpen)
{
AssetSerializer::SerializeAsset(GetAsset());
}
} }
void AssetEditor::SetMinSize(uint32_t width, uint32_t height) void AssetEditor::SetMinSize(uint32_t width, uint32_t height)
@ -46,7 +51,7 @@ namespace Prism
void AssetEditorPanel::RegisterDefaultEditors() void AssetEditorPanel::RegisterDefaultEditors()
{ {
RegisterEditor<TextureViewer>(AssetType::Texture); RegisterEditor<TextureViewer>(AssetType::Texture);
RegisterEditor<PhysicsMaterialEditor>(AssetType::PhysicsMat); RegisterEditor<PhysicsMaterialEditor>(AssetType::PhysicsMaterial);
} }
void AssetEditorPanel::OnImGuiRender() void AssetEditorPanel::OnImGuiRender()

View File

@ -17,6 +17,8 @@ namespace Prism
void OnImGuiRender(); void OnImGuiRender();
void SetOpen(const bool isOpen) { m_IsOpen = isOpen; } void SetOpen(const bool isOpen) { m_IsOpen = isOpen; }
virtual Ref<Asset> GetAsset() = 0;
virtual void SetAsset(const Ref<Asset>& asset) = 0; virtual void SetAsset(const Ref<Asset>& asset) = 0;
protected: protected:

View File

@ -144,7 +144,7 @@ namespace Prism
if (ImGui::MenuItem("Physics Material")) if (ImGui::MenuItem("Physics Material"))
{ {
// TODO: use template // 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); UpdateCurrentDirectory(m_CurrentDirHandle);
} }
@ -248,7 +248,12 @@ namespace Prism
ImGui::PushID(&asset->Handle); ImGui::PushID(&asset->Handle);
ImGui::BeginGroup(); 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<Texture>()->GetRendererID();
}
if (m_SelectedAssets.IsSelected(assetHandle)) if (m_SelectedAssets.IsSelected(assetHandle))
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.25f, 0.25f, 0.25f, 0.75f)); 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; return;
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlapped) && ImGui::IsItemClicked(ImGuiMouseButton_Left)) if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlapped) && ImGui::IsItemClicked(ImGuiMouseButton_Left))

View File

@ -4,6 +4,8 @@
#include "DefaultAssetEditors.h" #include "DefaultAssetEditors.h"
#include "Prism/Asset/AssetSerializer.h"
namespace Prism namespace Prism
{ {
@ -21,6 +23,9 @@ namespace Prism
UI::Property("Dynamic Friction", m_Asset->DynamicFriction); UI::Property("Dynamic Friction", m_Asset->DynamicFriction);
UI::Property("Bounciness", m_Asset->Bounciness); UI::Property("Bounciness", m_Asset->Bounciness);
UI::EndPropertyGrid(); UI::EndPropertyGrid();
if (ImGui::Button("Save"))
AssetSerializer::SerializeAsset(m_Asset);
} }

View File

@ -15,6 +15,7 @@ namespace Prism
public: public:
PhysicsMaterialEditor(); PhysicsMaterialEditor();
virtual Ref<Asset> GetAsset() override { return m_Asset; }
virtual void SetAsset(const Ref<Asset>& asset) override { m_Asset = (Ref<PhysicsMaterial>)asset; } virtual void SetAsset(const Ref<Asset>& asset) override { m_Asset = (Ref<PhysicsMaterial>)asset; }
private: private:
@ -29,6 +30,7 @@ namespace Prism
public: public:
TextureViewer(); TextureViewer();
virtual Ref<Asset> GetAsset() override { return m_Asset; }
virtual void SetAsset(const Ref<Asset>& asset) override { m_Asset = static_cast<Ref<Texture>>(asset); } virtual void SetAsset(const Ref<Asset>& asset) override { m_Asset = static_cast<Ref<Texture>>(asset); }
private: private:

View File

@ -172,7 +172,11 @@ namespace Prism
void SceneHierarchyPanel::OnImGuiRender() void SceneHierarchyPanel::OnImGuiRender()
{ {
ImGui::Begin("Scene Hierarchy"); 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) if (m_Context)
{ {
@ -186,7 +190,7 @@ namespace Prism
if (ImGui::BeginDragDropTargetCustom(windowRect, ImGui::GetCurrentWindow()->ID)) 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) if (payload)
{ {
@ -333,7 +337,7 @@ namespace Prism
if (ImGui::BeginDragDropTarget()) if (ImGui::BeginDragDropTarget())
{ {
const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("scene_entity_hierarchy", ImGuiDragDropFlags_AcceptNoDrawDefaultRect); const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("scene_entity_hierarchy");
if (payload) if (payload)
{ {
@ -391,8 +395,6 @@ namespace Prism
m_EntityDeletedCallback(entity); m_EntityDeletedCallback(entity);
} }
} }
static std::tuple<glm::vec3, glm::quat, glm::vec3> GetTransformDecomposition(const glm::mat4& transform) static std::tuple<glm::vec3, glm::quat, glm::vec3> GetTransformDecomposition(const glm::mat4& transform)
@ -966,7 +968,7 @@ namespace Prism
} }
UI::Property("IsTrigger", bcc.IsTrigger); UI::Property("IsTrigger", bcc.IsTrigger);
UI::PropertyAssetReference("Material", bcc.Material, AssetType::PhysicsMat); UI::PropertyAssetReference("Material", bcc.Material, AssetType::PhysicsMaterial);
UI::EndPropertyGrid(); UI::EndPropertyGrid();
}); });
@ -981,7 +983,7 @@ namespace Prism
} }
UI::Property("IsTrigger", scc.IsTrigger); UI::Property("IsTrigger", scc.IsTrigger);
UI::PropertyAssetReference("Material", scc.Material, AssetType::PhysicsMat); UI::PropertyAssetReference("Material", scc.Material, AssetType::PhysicsMaterial);
UI::EndPropertyGrid(); UI::EndPropertyGrid();
}); });
@ -996,7 +998,7 @@ namespace Prism
if (UI::Property("Height", ccc.Height)) changed = true; if (UI::Property("Height", ccc.Height)) changed = true;
UI::Property("Is Trigger", ccc.IsTrigger); UI::Property("Is Trigger", ccc.IsTrigger);
UI::PropertyAssetReference("Material", ccc.Material, AssetType::PhysicsMat); UI::PropertyAssetReference("Material", ccc.Material, AssetType::PhysicsMaterial);
if (changed) if (changed)
{ {
@ -1010,58 +1012,6 @@ namespace Prism
{ {
UI::BeginPropertyGrid(); 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<Mesh>::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)) 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(); UI::EndPropertyGrid();
}); });

View File

@ -255,7 +255,7 @@ namespace Prism
{ {
auto& collider = actor.m_Entity.GetComponent<MeshColliderComponent>(); auto& collider = actor.m_Entity.GetComponent<MeshColliderComponent>();
if (!collider.Material) if (!collider.Material)
collider.Material = Ref<PhysicsMaterial>::Create(0.6F, 0.6F, 0.0f); collider.Material = Ref<PhysicsMaterial>::Create(0.6f, 0.6f, 0.0f);
glm::vec3 scale = actor.m_Entity.Transform().Scale; glm::vec3 scale = actor.m_Entity.Transform().Scale;
physx::PxMaterial* material = s_Physics->createMaterial(collider.Material->StaticFriction, collider.Material->DynamicFriction, collider.Material->Bounciness); 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 scale_mat = glm::scale(glm::mat4(1.0f), *(glm::vec3*)&triangleGeometry.scale.scale);
glm::mat4 transform = FromPhysXTransform(shape->getLocalPose()) * scale; glm::mat4 transform = FromPhysXTransform(shape->getLocalPose()) * scale_mat;
collider.ProcessedMeshes.push_back(Ref<Mesh>::Create(vertices, indices, transform)); collider.ProcessedMeshes.push_back(Ref<Mesh>::Create(processedVertices, processedIndices, transform));
// collider.ProcessedMeshes.push_back(Ref<Mesh>::Create(processedVertices, processedIndices, FromPhysXTransform(shape->getLocalPose())));
} }
} }

View File

@ -294,7 +294,8 @@ namespace Prism
std::string texturePath = parentPath.string(); std::string texturePath = parentPath.string();
PM_MESH_LOG(" Albedo map path = {0}", texturePath); PM_MESH_LOG(" Albedo map path = {0}", texturePath);
auto texture = Texture2D::Create(texturePath, true); auto texture = AssetsManager::GetAsset<Texture2D>(texturePath);
// auto texture = Texture2D::Create(texturePath, true);
if (texture->Loaded()) if (texture->Loaded())
{ {
m_Textures[i] = texture; m_Textures[i] = texture;
@ -326,7 +327,8 @@ namespace Prism
std::string texturePath = parentPath.string(); std::string texturePath = parentPath.string();
PM_MESH_LOG(" Normal map path = {0}", texturePath); PM_MESH_LOG(" Normal map path = {0}", texturePath);
auto texture = Texture2D::Create(texturePath); auto texture = AssetsManager::GetAsset<Texture2D>(texturePath);
// auto texture = Texture2D::Create(texturePath);
if (texture->Loaded()) if (texture->Loaded())
{ {
mi->Set("u_NormalTexture", texture); mi->Set("u_NormalTexture", texture);
@ -354,7 +356,8 @@ namespace Prism
std::string texturePath = parentPath.string(); std::string texturePath = parentPath.string();
PM_MESH_LOG(" Roughness map path = {0}", texturePath); PM_MESH_LOG(" Roughness map path = {0}", texturePath);
auto texture = Texture2D::Create(texturePath); auto texture = AssetsManager::GetAsset<Texture2D>(texturePath);
// auto texture = Texture2D::Create(texturePath);
if (texture->Loaded()) if (texture->Loaded())
{ {
PM_CORE_TRACE(" Roughness map path = {0}", texturePath); PM_CORE_TRACE(" Roughness map path = {0}", texturePath);
@ -449,7 +452,8 @@ namespace Prism
PM_MESH_LOG(" Metalness map path = {0}", texturePath); PM_MESH_LOG(" Metalness map path = {0}", texturePath);
auto texture = Texture2D::Create(texturePath); auto texture = AssetsManager::GetAsset<Texture2D>(texturePath);
// auto texture = Texture2D::Create(texturePath);
if (texture->Loaded()) if (texture->Loaded())
{ {
mi->Set("u_MetalnessTexture", texture); mi->Set("u_MetalnessTexture", texture);

View File

@ -39,7 +39,7 @@ namespace Prism
// NOTE: Instead of destroying we could try and enforce all items to be trivally destructible // 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 // however some items like uniforms which contain std::strings still exist for now
// static_assert(std::is_trivially_destructible_v<FuncT>, "FuncT must be trivially destructible"); // static_assert(std::is_trivially_destructible_v<FuncT>, "FuncT must be trivially destructible");
// pFunc->~FuncT(); pFunc->~FuncT();
}; };
auto storageBuffer = GetRenderCommandQueue().Allocate(renderCmd, sizeof(func)); auto storageBuffer = GetRenderCommandQueue().Allocate(renderCmd, sizeof(func));
new (storageBuffer) FuncT(std::forward<FuncT>(func)); new (storageBuffer) FuncT(std::forward<FuncT>(func));

View File

@ -39,14 +39,6 @@ namespace Prism
: ParentHandle(parent) {} : ParentHandle(parent) {}
}; };
struct ChildrenComponent
{
std::vector<UUID> Children;
ChildrenComponent() = default;
ChildrenComponent(const ChildrenComponent& other) = default;
};
struct TagComponent struct TagComponent
{ {
std::string Tag; std::string Tag;

View File

@ -620,7 +620,6 @@ namespace Prism
entity.AddComponent<TransformComponent>(); entity.AddComponent<TransformComponent>();
entity.AddComponent<RelationshipComponent>(); entity.AddComponent<RelationshipComponent>();
entity.AddComponent<ChildrenComponent>();
if (!name.empty()) if (!name.empty())
entity.AddComponent<TagComponent>(name); entity.AddComponent<TagComponent>(name);
@ -629,7 +628,7 @@ namespace Prism
return entity; 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 entity = Entity{ m_Registry.create(), this };
auto& idComponent = entity.AddComponent<IDComponent>(); auto& idComponent = entity.AddComponent<IDComponent>();
@ -637,7 +636,6 @@ namespace Prism
entity.AddComponent<TransformComponent>(); entity.AddComponent<TransformComponent>();
entity.AddComponent<RelationshipComponent>(); entity.AddComponent<RelationshipComponent>();
entity.AddComponent<ChildrenComponent>();
if (!name.empty()) if (!name.empty())
entity.AddComponent<TagComponent>(name); entity.AddComponent<TagComponent>(name);

View File

@ -77,7 +77,7 @@ namespace Prism
void AddEntity(Entity* entity); void AddEntity(Entity* entity);
Entity CreateEntity(const std::string& name = ""); 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); void DestroyEntity(Entity entity);

View File

@ -65,5 +65,20 @@ namespace Prism::Utils
return SplitString(string, std::string(1, delimiter)); 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;
}
} }

View File

@ -12,6 +12,9 @@ namespace Prism::Utils
std::string GetFilename(const std::string& filepath); std::string GetFilename(const std::string& filepath);
std::string GetExtension(const std::string& filename); std::string GetExtension(const std::string& filename);
std::string RemoveExtension(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); bool StartsWith(const std::string& string, const std::string& start);
std::vector<std::string> SplitString(const std::string& string, const std::string& delimiters); std::vector<std::string> SplitString(const std::string& string, const std::string& delimiters);
std::vector<std::string> SplitString(const std::string& string, const char delimiter); std::vector<std::string> SplitString(const std::string& string, const char delimiter);