diff --git a/Editor/Editor/EditorLayer.cpp b/Editor/Editor/EditorLayer.cpp index 04a4992..679c44f 100644 --- a/Editor/Editor/EditorLayer.cpp +++ b/Editor/Editor/EditorLayer.cpp @@ -177,6 +177,7 @@ namespace Prism // OpenScene("assets/scenes/FPSDemo.scene"); NewScene(); + m_CurrentScene = m_RuntimeScene; AssetEditorPanel::RegisterDefaultEditors(); FileSystem::StartWatching(); @@ -804,11 +805,12 @@ namespace Prism bool snap = Input::IsKeyPressed(Key::LEFT_CONTROL); TransformComponent& entityTransform = selection.Entity.Transform(); + // glm::mat4 transform = entityTransform.GetTransform(); + glm::mat4 transform = m_CurrentScene->GetTransformRelativeToParent(selection.Entity); float snapValue = GetSnapValue(); float snapValues[3] = { snapValue, snapValue, snapValue }; if (m_SelectionMode == SelectionMode::Entity) { - glm::mat4 transform = entityTransform.GetTransform(); ImGuizmo::Manipulate(glm::value_ptr(m_EditorCamera.GetViewMatrix()), glm::value_ptr(m_EditorCamera.GetProjectionMatrix()), (ImGuizmo::OPERATION)m_GizmoType, @@ -822,16 +824,27 @@ namespace Prism glm::vec3 translation, rotation, scale; Math::DecomposeTransform(transform, translation,rotation,scale); - entityTransform.Translation = translation; + if (Entity parent = m_CurrentScene->FindEntityByUUID(selection.Entity.GetParentUUID())) + { + glm::vec3 parentTranslation, parentRotation, parentScale; + Math::DecomposeTransform(m_CurrentScene->GetTransformRelativeToParent(parent), parentTranslation, parentRotation, parentScale); - glm::vec3 deltaRotation = rotation - entityTransform.Rotation; - entityTransform.Rotation += deltaRotation; - - entityTransform.Scale = scale; + glm::vec3 deltaRotation = (rotation - parentRotation) - entityTransform.Rotation; + entityTransform.Translation = translation - parentTranslation; + entityTransform.Rotation += deltaRotation; + entityTransform.Scale = scale; + } + else + { + glm::vec3 deltaRotation = rotation - entityTransform.Rotation; + entityTransform.Translation = translation; + entityTransform.Rotation += deltaRotation; + entityTransform.Scale = scale; + } } }else { - glm::mat4 transformBase = entityTransform.GetTransform() * selection.Mesh->Transform; + glm::mat4 transformBase = transform * selection.Mesh->Transform; ImGuizmo::Manipulate(glm::value_ptr(m_EditorCamera.GetViewMatrix()), glm::value_ptr(m_EditorCamera.GetProjectionMatrix()), (ImGuizmo::OPERATION)m_GizmoType, @@ -918,6 +931,15 @@ namespace Prism case KeyCode::R: m_GizmoType = ImGuizmo::OPERATION::SCALE; break; + case KeyCode::F: + { + if (m_SelectionContext.size() == 0) + break; + + Entity selectedEntity = m_SelectionContext[0].Entity; + m_EditorCamera.Focus(selectedEntity.Transform().Translation); + break; + } } } @@ -1068,6 +1090,7 @@ namespace Prism m_SelectionContext.push_back(selection); m_EditorScene->SetSelectedEntity(entity); + m_CurrentScene = m_EditorScene; } void EditorLayer::UpdateWindowTitle(const std::string &sceneName) @@ -1108,9 +1131,9 @@ namespace Prism m_EditorScene->SetSelectedEntity(selectionContext.Entity); } - void EditorLayer::OnEntityDeleted(Entity e) + void EditorLayer::OnEntityDeleted(const Entity e) { - if (m_SelectionContext[0].Entity == e) + if (m_SelectionContext.size() > 0 && m_SelectionContext[0].Entity == e) { m_SelectionContext.clear(); m_EditorScene->SetSelectedEntity({}); @@ -1164,6 +1187,7 @@ namespace Prism m_EditorScene->SetSelectedEntity({}); m_SelectionContext.clear(); + m_CurrentScene = m_EditorScene; } void EditorLayer::SaveScene() @@ -1213,6 +1237,7 @@ namespace Prism m_RuntimeScene->OnRuntimeStart(); m_SceneHierarchyPanel->SetContext(m_RuntimeScene); + m_CurrentScene = m_RuntimeScene; } void EditorLayer::OnSceneStop() @@ -1226,6 +1251,7 @@ namespace Prism m_SelectionContext.clear(); ScriptEngine::SetSceneContext(m_EditorScene); m_SceneHierarchyPanel->SetContext(m_EditorScene); + m_CurrentScene = m_EditorScene; } float EditorLayer::GetSnapValue() const diff --git a/Editor/Editor/EditorLayer.h b/Editor/Editor/EditorLayer.h index c63ba11..9bd5ab4 100644 --- a/Editor/Editor/EditorLayer.h +++ b/Editor/Editor/EditorLayer.h @@ -61,7 +61,7 @@ namespace Prism Scope m_AssetManagerPanel; Scope m_ObjectsPanel; - Ref m_ActiveScene; + Ref m_CurrentScene; Ref m_RuntimeScene, m_EditorScene; std::string m_SceneFilePath; diff --git a/Editor/assets/shaders/BloomBlend.glsl b/Editor/assets/shaders/BloomBlend.glsl index 6b838b7..1437d66 100644 --- a/Editor/assets/shaders/BloomBlend.glsl +++ b/Editor/assets/shaders/BloomBlend.glsl @@ -48,7 +48,7 @@ void main() vec3 mappedColor = (mappedLuminance / luminance) * color* u_Exposure; // Gamma correction. - o_Color = vec4(color, 1.0); + o_Color = vec4(mappedColor, 1.0); #else const float gamma = 2.2; vec3 hdrColor = texture(u_SceneTexture, v_TexCoord).rgb; diff --git a/Prism-ScriptCore/Src/Prism/Physics/Colliders.cs b/Prism-ScriptCore/Src/Prism/Physics/Colliders.cs index eb70f1e..6cfe9d1 100644 --- a/Prism-ScriptCore/Src/Prism/Physics/Colliders.cs +++ b/Prism-ScriptCore/Src/Prism/Physics/Colliders.cs @@ -50,7 +50,7 @@ namespace Prism public Vec3 Size { get; protected set; } public Vec3 Offset { get; protected set; } - private BoxCollider(ulong entityID, bool isTrigger, Vec3 size, Vec3 offset) + internal BoxCollider(ulong entityID, bool isTrigger, Vec3 size, Vec3 offset) { EntityID = entityID; Size = size; @@ -63,7 +63,7 @@ namespace Prism { public float Radius { get; protected set; } - private SphereCollider(ulong entityID, bool isTrigger, float radius) + internal SphereCollider(ulong entityID, bool isTrigger, float radius) { EntityID = entityID; Radius = radius; @@ -76,7 +76,7 @@ namespace Prism public float Radius { get; protected set; } public float Height { get; protected set; } - private CapsuleCollider(ulong entityID, bool isTrigger, float radius, float height) + internal CapsuleCollider(ulong entityID, bool isTrigger, float radius, float height) { EntityID = entityID; Radius = radius; @@ -89,7 +89,7 @@ namespace Prism { public Mesh Mesh { get; protected set; } - private MeshCollider(ulong entityID, bool isTrigger, IntPtr filepath) + internal MeshCollider(ulong entityID, bool isTrigger, IntPtr filepath) { EntityID = entityID; Mesh = new Mesh(filepath); diff --git a/Prism/src/Prism/Asset/Asset.h b/Prism/src/Prism/Asset/Asset.h index 509b65e..267c1ba 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, Mesh, Texture, EnvMap, Audio, Script, PhysicsMat, Directory, Other + Scene = 0, Mesh, Texture, EnvMap, Audio, Script, PhysicsMat, Directory, Other, None }; using AssetHandle = UUID; @@ -21,7 +21,7 @@ namespace Prism { public: AssetHandle Handle; - AssetType Type; + AssetType Type = AssetType::None; std::string FilePath; std::string FileName; @@ -56,7 +56,10 @@ namespace Prism public: std::vector ChildDirectories; - Directory() = default; + Directory() + { + Type = AssetType::Directory; + } }; } diff --git a/Prism/src/Prism/Asset/AssetSerializer.cpp b/Prism/src/Prism/Asset/AssetSerializer.cpp index 903302e..4ef43c9 100644 --- a/Prism/src/Prism/Asset/AssetSerializer.cpp +++ b/Prism/src/Prism/Asset/AssetSerializer.cpp @@ -71,8 +71,9 @@ namespace Prism const std::string extension = Utils::GetExtension(filepath); - asset->FilePath = filepath; + asset->Type = type; + std::replace(asset->FilePath.begin(), asset->FilePath.end(), '\\', '/'); const bool hasMeta = FileSystem::Exists(asset->FilePath + ".meta"); @@ -82,16 +83,12 @@ namespace Prism } else { - if (filepath == "assets") - asset->Handle = 0; - else - asset->Handle = AssetHandle(); - - asset->FileName = Utils::RemoveExtension(Utils::GetFilename(filepath)); - asset->Extension = Utils::GetExtension(filepath); - asset->Type = type; + asset->Handle = AssetHandle(); } + // TODO: file or directory Type to fix + asset->Extension = extension; + asset->FileName = Utils::RemoveExtension(Utils::GetFilename(filepath)); asset->ParentDirectory = parentHandle; asset->IsDataLoaded = false; @@ -174,10 +171,15 @@ namespace Prism } asset->Handle = data["Asset"].as(); - asset->FileName = data["FileName"].as(); asset->FilePath = data["FilePath"].as(); - asset->Extension = data["Extension"].as(); asset->Type = (AssetType)data["Type"].as(); + + if (asset->FileName == "assets" && asset->Handle == 0) + { + asset->Handle = AssetHandle(); + CreateMetaFile(asset); + } + } void AssetSerializer::CreateMetaFile(const Ref& asset) @@ -185,10 +187,7 @@ namespace Prism YAML::Emitter out; out << YAML::BeginMap; out << YAML::Key << "Asset" << YAML::Value << asset->Handle; - out << YAML::Key << "FileName" << YAML::Value << asset->FileName; out << YAML::Key << "FilePath" << YAML::Value << asset->FilePath; - out << YAML::Key << "Extension" << YAML::Value << asset->Extension; - out << YAML::Key << "Directory" << YAML::Value << asset->ParentDirectory; out << YAML::Key << "Type" << YAML::Value << (int)asset->Type; out << YAML::EndMap; diff --git a/Prism/src/Prism/Asset/AssetsManager.cpp b/Prism/src/Prism/Asset/AssetsManager.cpp index bb63144..9026c1b 100644 --- a/Prism/src/Prism/Asset/AssetsManager.cpp +++ b/Prism/src/Prism/Asset/AssetsManager.cpp @@ -33,20 +33,6 @@ namespace Prism s_Types["cs"] = AssetType::Script; } - size_t AssetTypes::GetAssetTypeID(const std::string& extension) - { - if (extension.empty()) - return 0; - - for (const auto& kv : s_Types) - { - if (kv.first == extension) - return std::hash()(extension); - } - - return -1; - } - AssetType AssetTypes::GetAssetTypeFromExtension(const std::string& extension) { return s_Types.find(extension) != s_Types.end() ? s_Types[extension] : AssetType::Other; @@ -121,7 +107,7 @@ namespace Prism return false; } - AssetHandle AssetsManager::GetAssetIDForFile(const std::string& filepath) + AssetHandle AssetsManager::GetAssetHandleFromFilePath(const std::string& filepath) { for (auto&[id, asset] : s_LoadedAssets) { @@ -134,7 +120,7 @@ namespace Prism bool AssetsManager::IsAssetHandleValid(const AssetHandle& assetHandle) { - return s_LoadedAssets.find(assetHandle) != s_LoadedAssets.end(); + return assetHandle != 0 && s_LoadedAssets.find(assetHandle) != s_LoadedAssets.end(); } void AssetsManager::Rename(Ref& asset, const std::string& newName) @@ -157,22 +143,38 @@ namespace Prism } template - Ref AssetsManager::GetAsset(const AssetHandle assetHandle) + Ref AssetsManager::GetAsset(AssetHandle assetHandle, bool loadData) { PM_CORE_ASSERT(s_LoadedAssets.find(assetHandle) != s_LoadedAssets.end()); Ref asset = s_LoadedAssets[assetHandle]; - if (!asset->IsDataLoaded) + if (!asset->IsDataLoaded && loadData) asset = AssetSerializer::LoadAssetData(asset); return asset.As(); } - template PRISM_API Ref AssetsManager::GetAsset(AssetHandle); - template PRISM_API Ref AssetsManager::GetAsset(AssetHandle); - template PRISM_API Ref AssetsManager::GetAsset(AssetHandle); - template PRISM_API Ref AssetsManager::GetAsset(AssetHandle); - template PRISM_API Ref AssetsManager::GetAsset(AssetHandle); + + template PRISM_API Ref AssetsManager::GetAsset(AssetHandle, bool); + template PRISM_API Ref AssetsManager::GetAsset(AssetHandle, bool); + template PRISM_API Ref AssetsManager::GetAsset(AssetHandle, bool); + template PRISM_API Ref AssetsManager::GetAsset(AssetHandle, bool); + template PRISM_API Ref AssetsManager::GetAsset(AssetHandle, bool); + template PRISM_API Ref AssetsManager::GetAsset(AssetHandle, bool); + + template + Ref AssetsManager::GetAsset(const std::string& filepath, const bool loadData) + { + return GetAsset(GetAssetHandleFromFilePath(filepath), loadData); + } + + template PRISM_API Ref AssetsManager::GetAsset(const std::string&, bool); + template PRISM_API Ref AssetsManager::GetAsset(const std::string&, bool); + template PRISM_API Ref AssetsManager::GetAsset(const std::string&, bool); + template PRISM_API Ref AssetsManager::GetAsset(const std::string&, bool); + template PRISM_API Ref AssetsManager::GetAsset(const std::string&, bool); + template PRISM_API Ref AssetsManager::GetAsset(const std::string&, bool); + // temp Ref AssetsManager::CreateAssetPhysicsMaterial(const std::string& filename, const AssetType type, const AssetHandle& directoryHandle, float v1, float v2, float v3) @@ -205,7 +207,7 @@ namespace Prism childList.erase(std::remove(childList.begin(), childList.end(), assetHandle), childList.end()); } - for (auto child : asset.As()->ChildDirectories) + for (const auto child : asset.As()->ChildDirectories) RemoveAsset(child); for (auto it = s_LoadedAssets.begin(); it != s_LoadedAssets.end(); ) @@ -306,51 +308,13 @@ namespace Prism s_LoadedAssets[asset->Handle] = asset; } - void AssetsManager::ConvertAsset(const std::string& assetPath, const std::string& conversionType) - { - // Create a filestream to write a blender python script for conversion of the asset - // The 'bpy.ops.export_scene.(asset-type-to-convert) function runs blender in background and exports the file' - std::string path = std::filesystem::temp_directory_path().string(); - std::ofstream fileStream(path + "export.py"); - - // Importing the python modules required for the export to work out - fileStream << "import bpy\n"; - fileStream << "import sys\n"; - - if (conversionType == "fbx") - fileStream << "bpy.ops.export_scene.fbx(filepath=r'" + path + "asset.fbx" + "', axis_forward='-Z', axis_up='Y')\n"; - - if (conversionType == "obj") - fileStream << "bpy.ops.export_scene.obj(filepath=r'" + path + "asset.obj" + "', axis_forward='-Z', axis_up='Y')\n"; - - fileStream.close(); - - // This section involves creating the command to export the .blend file to the required asset type - // The command goes something like this - // blender.exe path\to\files\cube.blend --background --python path\to\file\export.py - - std::string blender_base_path = R"(D:\Application\Blender5.0.1\blender.exe)"; - std::string p_asset_path = '"' + assetPath + '"'; - std::string p_blender_path = '"' + blender_base_path + '"'; - std::string p_script_path = '"' + path + "export.py" + '"'; - - // Creating the actual command that will execute - std::string convCommand = '"' + p_blender_path + " " + p_asset_path + " --background --python " + p_script_path + "" + '"'; - - // Just for debugging(it took me 1hr for this string literals n stuff! It better work!) - PM_CORE_INFO("{0}", convCommand); - - // Fire the above created command - - system(convCommand.c_str()); - } AssetHandle AssetsManager::ProcessDirectory(const std::string& directoryPath, AssetHandle parentHandle) { Ref dirInfo = AssetSerializer::LoadAssetInfo(directoryPath, parentHandle, AssetType::Directory).As(); s_LoadedAssets[dirInfo->Handle] = dirInfo; - if (parentHandle != dirInfo->Handle && IsAssetHandleValid(parentHandle)) + if (IsAssetHandleValid(parentHandle)) s_LoadedAssets[parentHandle].As()->ChildDirectories.push_back(dirInfo->Handle); for (const auto& entry : std::filesystem::directory_iterator(directoryPath)) @@ -444,7 +408,7 @@ namespace Prism { const std::vector parts = Utils::SplitString(filepath, "/\\"); const std::string& parentFolder = parts[parts.size() - 2]; - Ref assetsDirectory = GetAsset(0); + Ref assetsDirectory = GetAsset(GetAssetHandleFromFilePath("assets")); return FindParentHandleInChildren(assetsDirectory, parentFolder); } } diff --git a/Prism/src/Prism/Asset/AssetsManager.h b/Prism/src/Prism/Asset/AssetsManager.h index 55af083..b0f10df 100644 --- a/Prism/src/Prism/Asset/AssetsManager.h +++ b/Prism/src/Prism/Asset/AssetsManager.h @@ -18,7 +18,6 @@ namespace Prism { public: static void Init(); - static size_t GetAssetTypeID(const std::string& extension); static AssetType GetAssetTypeFromExtension(const std::string& extension); private: @@ -43,7 +42,7 @@ namespace Prism static bool IsDirectory(const std::string& filepath); - static AssetHandle GetAssetIDForFile(const std::string& filepath); + static AssetHandle GetAssetHandleFromFilePath(const std::string& filepath); static bool IsAssetHandleValid(const AssetHandle& assetHandle); static void Rename(Ref& asset, const std::string& newName); @@ -56,16 +55,18 @@ namespace Prism static Ref CreateAsset(const std::string& filename, AssetType type, AssetHandle directoryHandle, Args&&... args); template - static Ref GetAsset(AssetHandle assetHandle); + static Ref GetAsset(AssetHandle assetHandle, bool loadData = true); - static bool IsAssetType(AssetHandle assetHandle, AssetType type); + template + static Ref GetAsset(const std::string& filepath, bool loadData = true); + + static bool IsAssetType(AssetHandle assetHandle, AssetType type); static std::string StripExtras(const std::string& filename); private: static void ImportAsset(const std::string& filepath, AssetHandle parentHandle); - static void ConvertAsset(const std::string& assetPath, const std::string& conversionType); static AssetHandle ProcessDirectory(const std::string& directoryPath, AssetHandle parentHandle); static void ReloadAssets(); diff --git a/Prism/src/Prism/Core/ImGui/ImGui.h b/Prism/src/Prism/Core/ImGui/ImGui.h index 01c078f..91860aa 100644 --- a/Prism/src/Prism/Core/ImGui/ImGui.h +++ b/Prism/src/Prism/Core/ImGui/ImGui.h @@ -260,7 +260,7 @@ namespace Prism::UI { } template - static bool PropertyAssetReference(const char* label, Ref& object, AssetType supportedType) + static bool PropertyAssetReference(const char* label, Ref& object, const AssetType supportedType) { bool modified = false; @@ -281,11 +281,9 @@ namespace Prism::UI { if (ImGui::BeginDragDropTarget()) { - auto data = ImGui::AcceptDragDropPayload("asset_payload"); - - if (data) + if (const auto data = ImGui::AcceptDragDropPayload("asset_payload")) { - AssetHandle assetHandle = *(AssetHandle*)data->Data; + const AssetHandle assetHandle = *(AssetHandle*)data->Data; if (AssetsManager::IsAssetType(assetHandle, supportedType)) { object = AssetsManager::GetAsset(assetHandle); diff --git a/Prism/src/Prism/Editor/AssetEditorPanel.cpp b/Prism/src/Prism/Editor/AssetEditorPanel.cpp index 16b6606..e6f23d7 100644 --- a/Prism/src/Prism/Editor/AssetEditorPanel.cpp +++ b/Prism/src/Prism/Editor/AssetEditorPanel.cpp @@ -19,7 +19,6 @@ namespace Prism if (!m_IsOpen) return; - // NOTE(Peter): SetNextWindowSizeConstraints requires a max constraint that's above 0. For now we're just setting it to a large value ImGui::SetNextWindowSizeConstraints(m_MinSize, m_MaxSize); ImGui::Begin(m_Title, &m_IsOpen, m_Flags); Render(); @@ -46,7 +45,7 @@ namespace Prism void AssetEditorPanel::RegisterDefaultEditors() { - RegisterEditor(AssetType::Texture); + RegisterEditor(AssetType::Texture); RegisterEditor(AssetType::PhysicsMat); } @@ -65,7 +64,7 @@ namespace Prism } s_Editors[asset->Type]->SetOpen(true); - s_Editors[asset->Type]->SetAsset(asset); + s_Editors[asset->Type]->SetAsset(AssetsManager::GetAsset(asset->Handle)); } template @@ -76,7 +75,7 @@ namespace Prism s_Editors[type] = CreateScope(); } - template PRISM_API void AssetEditorPanel::RegisterEditor(AssetType); + template PRISM_API void AssetEditorPanel::RegisterEditor(AssetType); template PRISM_API void AssetEditorPanel::RegisterEditor(AssetType); std::unordered_map> AssetEditorPanel::s_Editors; diff --git a/Prism/src/Prism/Editor/AssetsManagerPanel.cpp b/Prism/src/Prism/Editor/AssetsManagerPanel.cpp index 1e8201f..447f7ca 100644 --- a/Prism/src/Prism/Editor/AssetsManagerPanel.cpp +++ b/Prism/src/Prism/Editor/AssetsManagerPanel.cpp @@ -20,27 +20,25 @@ namespace Prism UpdateCurrentDirectory(m_CurrentDirHandle); }); - m_FolderTex = Texture2D::Create("assets/editor/folder.png"); - - m_AssetIconMap[-1] = Texture2D::Create("assets/editor/file.png"); - m_AssetIconMap[0] = m_FolderTex; - m_AssetIconMap[AssetTypes::GetAssetTypeID("hdr")] = Texture2D::Create("assets/editor/file.png"); - m_AssetIconMap[AssetTypes::GetAssetTypeID("fbx")] = Texture2D::Create("assets/editor/fbx.png"); - m_AssetIconMap[AssetTypes::GetAssetTypeID("obj")] = Texture2D::Create("assets/editor/obj.png"); - m_AssetIconMap[AssetTypes::GetAssetTypeID("wav")] = Texture2D::Create("assets/editor/wav.png"); - m_AssetIconMap[AssetTypes::GetAssetTypeID("cs")] = Texture2D::Create("assets/editor/csc.png"); - m_AssetIconMap[AssetTypes::GetAssetTypeID("png")] = Texture2D::Create("assets/editor/png.png"); - m_AssetIconMap[AssetTypes::GetAssetTypeID("blend")] = Texture2D::Create("assets/editor/blend.png"); + m_FileTex = AssetsManager::GetAsset("assets/editor/file.png"); + m_AssetIconMap[""] = AssetsManager::GetAsset("assets/editor/folder.png"); + m_AssetIconMap["hdr"] = AssetsManager::GetAsset("assets/editor/file.png"); + m_AssetIconMap["fbx"] = AssetsManager::GetAsset("assets/editor/fbx.png"); + m_AssetIconMap["obj"] = AssetsManager::GetAsset("assets/editor/obj.png"); + m_AssetIconMap["wav"] = AssetsManager::GetAsset("assets/editor/wav.png"); + m_AssetIconMap["cs"] = AssetsManager::GetAsset("assets/editor/csc.png"); + m_AssetIconMap["png"] = AssetsManager::GetAsset("assets/editor/png.png"); + m_AssetIconMap["blend"] = AssetsManager::GetAsset("assets/editor/blend.png"); // TODO: get a logo for this project - m_AssetIconMap[AssetTypes::GetAssetTypeID("scene")] = Texture2D::Create("assets/editor/asset.png"); + m_AssetIconMap["scene"] = Texture2D::Create("assets/editor/asset.png"); - m_BackbtnTex = Texture2D::Create("assets/editor/btn_back.png"); - m_FwrdbtnTex = Texture2D::Create("assets/editor/btn_fwrd.png"); - m_FolderRightTex = Texture2D::Create("assets/editor/folder_hierarchy.png"); - m_SearchTex = Texture2D::Create("assets/editor/search.png"); + m_BackbtnTex = AssetsManager::GetAsset("assets/editor/btn_back.png"); + m_FwrdbtnTex = AssetsManager::GetAsset("assets/editor/btn_fwrd.png"); + m_FolderRightTex = AssetsManager::GetAsset("assets/editor/folder_hierarchy.png"); + m_SearchTex = AssetsManager::GetAsset("assets/editor/search.png"); - m_BaseDirectoryHandle = 0; + m_BaseDirectoryHandle = AssetsManager::GetAssetHandleFromFilePath("assets"); m_BaseDirectory = AssetsManager::GetAsset(m_BaseDirectoryHandle); UpdateCurrentDirectory(m_BaseDirectoryHandle); @@ -89,6 +87,7 @@ namespace Prism { m_SelectedAssets.Clear(); m_RenamingSelected = false; + memset(m_InputBuffer, 0, MAX_INPUT_BUFFER_LENGTH); } m_IsAnyItemHovered = false; @@ -106,7 +105,7 @@ namespace Prism if (created) { UpdateCurrentDirectory(m_CurrentDirHandle); - const auto& createdDirectory = AssetsManager::GetAsset(AssetsManager::GetAssetIDForFile(m_CurrentDirectory->FilePath + "/New Folder")); + const auto& createdDirectory = AssetsManager::GetAsset(AssetsManager::GetAssetHandleFromFilePath(m_CurrentDirectory->FilePath + "/New Folder")); m_SelectedAssets.Select(createdDirectory->Handle); memset(m_InputBuffer, 0, MAX_INPUT_BUFFER_LENGTH); memcpy(m_InputBuffer, createdDirectory->FileName.c_str(), createdDirectory->FileName.size()); @@ -158,16 +157,17 @@ namespace Prism { for (Ref& asset : m_CurrentDirAssets) { - if (m_SkipRenderingThisFrame) - { - m_SkipRenderingThisFrame = false; - break; - } RenderAsset(asset); ImGui::NextColumn(); } } + if (m_UpdateDirectoryNextFrame) + { + UpdateCurrentDirectory(m_CurrentDirHandle); + m_UpdateDirectoryNextFrame = false; + } + if (m_IsDragging && !ImGui::IsMouseDragging(ImGuiMouseButton_Left, 0.1f)) { m_IsDragging = false; @@ -217,15 +217,13 @@ namespace Prism void AssetsManagerPanel::RenderAsset(Ref& asset) { // These caches are currently required for when we change directories - AssetHandle assetHandle = asset->Handle; - std::string filename = asset->FileName; + const AssetHandle assetHandle = asset->Handle; + const std::string filename = asset->FileName; ImGui::PushID(&asset->Handle); ImGui::BeginGroup(); - size_t fileID = AssetTypes::GetAssetTypeID(asset->Extension); - fileID = m_AssetIconMap.find(fileID) != m_AssetIconMap.end() ? fileID : -1; - const RendererID iconRef = m_AssetIconMap[fileID]->GetRendererID(); + const RendererID iconRef = m_AssetIconMap.find(asset->Extension) != m_AssetIconMap.end() ? m_AssetIconMap[asset->Extension]->GetRendererID() : m_FileTex->GetRendererID(); if (m_SelectedAssets.IsSelected(assetHandle)) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.25f, 0.25f, 0.25f, 0.75f)); @@ -247,8 +245,8 @@ namespace Prism if (asset->Type == AssetType::Directory) { m_PrevDirHandle = m_CurrentDirHandle; - UpdateCurrentDirectory(assetHandle); - m_SkipRenderingThisFrame = true; + m_CurrentDirHandle = assetHandle; + m_UpdateDirectoryNextFrame = true; } else { @@ -317,8 +315,7 @@ namespace Prism { FileSystem::PrismDeleteFile(filepath + ".meta"); AssetsManager::RemoveAsset(assetHandle); - m_SkipRenderingThisFrame = true; - UpdateCurrentDirectory(m_CurrentDirHandle); + m_UpdateDirectoryNextFrame = true; } ImGui::CloseCurrentPopup(); @@ -350,6 +347,31 @@ namespace Prism void AssetsManagerPanel::HandleDragDrop(const RendererID icon, const Ref& asset) { + if (asset->Type == AssetType::Directory && m_IsDragging) + { + if (ImGui::BeginDragDropTarget()) + { + auto payload = ImGui::AcceptDragDropPayload("asset_payload"); + if (payload) + { + int count = payload->DataSize / sizeof(AssetHandle); + + for (int i = 0; i < count; i++) + { + AssetHandle handle = *(((AssetHandle*)payload->Data) + i); + Ref droppedAsset = AssetsManager::GetAsset(handle, false); + + bool result = FileSystem::PrismMoveFile(droppedAsset->FilePath, asset->FilePath); + if (result) + droppedAsset->ParentDirectory = asset->Handle; + } + + m_UpdateDirectoryNextFrame = true; + } + } + } + + if (!m_SelectedAssets.IsSelected(asset->Handle) || m_IsDragging) return; @@ -393,7 +415,7 @@ namespace Prism ImGui::PushItemWidth(200); char* buf = m_InputBuffer; if (m_RenamingSelected) - buf = '\0'; + *buf = '\0'; if (ImGui::InputTextWithHint("##asset_panel_search", "Search...", buf, MAX_INPUT_BUFFER_LENGTH)) { @@ -424,7 +446,6 @@ namespace Prism currentHandle = dirInfo->ParentDirectory; } - m_BreadCrumbData.push_back(m_BaseDirectory); std::reverse(m_BreadCrumbData.begin(), m_BreadCrumbData.end()); m_UpdateBreadCrumbs = false; @@ -475,8 +496,7 @@ namespace Prism AssetsManager::Rename(asset, m_InputBuffer); m_RenamingSelected = false; m_SelectedAssets.Clear(); - m_SkipRenderingThisFrame = true; - UpdateCurrentDirectory(m_CurrentDirHandle); + m_UpdateDirectoryNextFrame = true; } } } @@ -484,8 +504,7 @@ namespace Prism void AssetsManagerPanel::UpdateCurrentDirectory(AssetHandle directoryHandle) { - if (m_CurrentDirHandle != directoryHandle) - m_UpdateBreadCrumbs = true; + m_UpdateBreadCrumbs = true; m_CurrentDirAssets.clear(); m_CurrentDirHandle = directoryHandle; diff --git a/Prism/src/Prism/Editor/AssetsManagerPanel.h b/Prism/src/Prism/Editor/AssetsManagerPanel.h index 81438d8..46c64c9 100644 --- a/Prism/src/Prism/Editor/AssetsManagerPanel.h +++ b/Prism/src/Prism/Editor/AssetsManagerPanel.h @@ -82,7 +82,7 @@ namespace Prism void UpdateCurrentDirectory(AssetHandle directoryHandle); private: - Ref m_FolderTex; + Ref m_FileTex; Ref m_BackbtnTex; Ref m_FwrdbtnTex; Ref m_FolderRightTex; @@ -93,7 +93,7 @@ namespace Prism bool m_IsDragging = false; bool m_UpdateBreadCrumbs = true; bool m_IsAnyItemHovered = false; - bool m_SkipRenderingThisFrame = false; + bool m_UpdateDirectoryNextFrame = false; char m_InputBuffer[MAX_INPUT_BUFFER_LENGTH]; @@ -112,7 +112,7 @@ namespace Prism bool m_RenamingSelected = false; - std::map> m_AssetIconMap; + std::map> m_AssetIconMap; }; } diff --git a/Prism/src/Prism/Editor/DefaultAssetEditors.cpp b/Prism/src/Prism/Editor/DefaultAssetEditors.cpp index 309d4b6..2b87f51 100644 --- a/Prism/src/Prism/Editor/DefaultAssetEditors.cpp +++ b/Prism/src/Prism/Editor/DefaultAssetEditors.cpp @@ -25,14 +25,14 @@ namespace Prism // MaterialEditor - TextureEditor::TextureEditor() + TextureViewer::TextureViewer() : AssetEditor("Edit Texture") { SetMinSize(200, 600); SetMaxSize(500, 1000); } - void TextureEditor::Render() + void TextureViewer::Render() { if (!m_Asset) SetOpen(false); diff --git a/Prism/src/Prism/Editor/DefaultAssetEditors.h b/Prism/src/Prism/Editor/DefaultAssetEditors.h index a8cd02b..112a32b 100644 --- a/Prism/src/Prism/Editor/DefaultAssetEditors.h +++ b/Prism/src/Prism/Editor/DefaultAssetEditors.h @@ -24,10 +24,10 @@ namespace Prism Ref m_Asset; }; - class TextureEditor : public AssetEditor + class TextureViewer : public AssetEditor { public: - TextureEditor(); + TextureViewer(); virtual void SetAsset(const Ref& asset) override { m_Asset = static_cast>(asset); } diff --git a/Prism/src/Prism/Editor/EditorCamera.cpp b/Prism/src/Prism/Editor/EditorCamera.cpp index e78f69a..192b5ba 100644 --- a/Prism/src/Prism/Editor/EditorCamera.cpp +++ b/Prism/src/Prism/Editor/EditorCamera.cpp @@ -33,8 +33,15 @@ namespace Prism UpdateCameraView(); } - void EditorCamera::Focus() + void EditorCamera::Focus(const glm::vec3& focusPoint) { + m_FocalPoint = focusPoint; + if (m_Distance > m_MinFocusDistance) + { + const float distance = m_Distance - m_MinFocusDistance; + MouseZoom(distance / ZoomSpeed()); + UpdateCameraView(); + } } void EditorCamera::OnUpdate(TimeStep deltaTime) diff --git a/Prism/src/Prism/Editor/EditorCamera.h b/Prism/src/Prism/Editor/EditorCamera.h index d75109a..46f183a 100644 --- a/Prism/src/Prism/Editor/EditorCamera.h +++ b/Prism/src/Prism/Editor/EditorCamera.h @@ -21,7 +21,7 @@ namespace Prism EditorCamera() = default; EditorCamera(const glm::mat4& projectionMatrix); - void Focus(); + void Focus(const glm::vec3& focusPoint); void OnUpdate(TimeStep deltaTime); void OnEvent(Event& e); @@ -72,6 +72,9 @@ namespace Prism float m_Distance; + // focus + float m_MinFocusDistance = 100.0f; + float m_Pitch, m_Yaw; }; diff --git a/Prism/src/Prism/Editor/ObjectsPanel.cpp b/Prism/src/Prism/Editor/ObjectsPanel.cpp index 39c9bcb..9b22fa5 100644 --- a/Prism/src/Prism/Editor/ObjectsPanel.cpp +++ b/Prism/src/Prism/Editor/ObjectsPanel.cpp @@ -17,13 +17,13 @@ namespace Prism void ObjectsPanel::OnImGuiRender() { - static const AssetHandle CubeHandle = AssetsManager::GetAssetIDForFile("assets/meshes/Default/Cube.fbx"); - static const AssetHandle CapsuleHandle = AssetsManager::GetAssetIDForFile("assets/meshes/Default/Capsule.fbx"); - static const AssetHandle SphereHandle = AssetsManager::GetAssetIDForFile("assets/meshes/Default/Sphere.fbx"); - static const AssetHandle CylinderHandle = AssetsManager::GetAssetIDForFile("assets/meshes/Default/Cylinder.fbx"); - static const AssetHandle TorusHandle = AssetsManager::GetAssetIDForFile("assets/meshes/Default/Torus.fbx"); - static const AssetHandle PlaneHandle = AssetsManager::GetAssetIDForFile("assets/meshes/Default/Plane.fbx"); - static const AssetHandle ConeHandle = AssetsManager::GetAssetIDForFile("assets/meshes/Default/Cone.fbx"); + static const AssetHandle CubeHandle = AssetsManager::GetAssetHandleFromFilePath("assets/meshes/Default/Cube.fbx"); + static const AssetHandle CapsuleHandle = AssetsManager::GetAssetHandleFromFilePath("assets/meshes/Default/Capsule.fbx"); + static const AssetHandle SphereHandle = AssetsManager::GetAssetHandleFromFilePath("assets/meshes/Default/Sphere.fbx"); + static const AssetHandle CylinderHandle = AssetsManager::GetAssetHandleFromFilePath("assets/meshes/Default/Cylinder.fbx"); + static const AssetHandle TorusHandle = AssetsManager::GetAssetHandleFromFilePath("assets/meshes/Default/Torus.fbx"); + static const AssetHandle PlaneHandle = AssetsManager::GetAssetHandleFromFilePath("assets/meshes/Default/Plane.fbx"); + static const AssetHandle ConeHandle = AssetsManager::GetAssetHandleFromFilePath("assets/meshes/Default/Cone.fbx"); ImGui::Begin("Objects"); { diff --git a/Prism/src/Prism/Editor/SceneHierachyPanel.cpp b/Prism/src/Prism/Editor/SceneHierachyPanel.cpp index a7b5a64..ee66904 100644 --- a/Prism/src/Prism/Editor/SceneHierachyPanel.cpp +++ b/Prism/src/Prism/Editor/SceneHierachyPanel.cpp @@ -15,6 +15,7 @@ #include #include "Prism/Core/Application.h" +#include "Prism/Core/Math/Math.h" #include "Prism/Physics/PhysicsLayer.h" #include "Prism/Physics/PhysicsWrappers.h" #include "Prism/Renderer/Meshfactory.h" @@ -194,11 +195,17 @@ namespace Prism { auto& children = previousParent.Children(); children.erase(std::remove(children.begin(), children.end(), droppedHandle), children.end()); + + const glm::mat4 parentTransform = m_Context->GetTransformRelativeToParent(previousParent); + glm::vec3 parentTranslation, parentRotation, parentScale; + Math::DecomposeTransform(parentTransform, parentTranslation, parentRotation, parentScale); + + e.Transform().Translation = e.Transform().Translation + parentTranslation; } e.SetParentUUID(0); - PM_CORE_INFO("Unparented Entity!"); + PM_CORE_DEBUG("Unparented Entity!"); } ImGui::EndDragDropTarget(); @@ -247,7 +254,6 @@ namespace Prism if (m_SelectionContext) { DrawComponents(m_SelectionContext); - } } ImGui::End(); @@ -329,12 +335,18 @@ namespace Prism parentChildren.erase(std::remove(parentChildren.begin(), parentChildren.end(), droppedHandle), parentChildren.end()); } + const glm::mat4 parentTransform = m_Context->GetTransformRelativeToParent(entity); + glm::vec3 parentTranslation, parentRotation, parentScale; + Math::DecomposeTransform(parentTransform, parentTranslation, parentRotation, parentScale); + + e.Transform().Translation = e.Transform().Translation - parentTranslation; + e.SetParentUUID(entity.GetUUID()); entity.Children().push_back(droppedHandle); - PM_CORE_INFO("Dropping Entity {0} on {1}", (uint64_t)droppedHandle, (uint64_t)entity.GetUUID()); + PM_CORE_DEBUG("Dropping Entity {0} on {1}", (uint64_t)droppedHandle, (uint64_t)entity.GetUUID()); } - PM_CORE_INFO("Dropping Entity {0} on {1}", (uint64_t)droppedHandle, (uint64_t)entity.GetUUID()); + PM_CORE_DEBUG("Dropping Entity {0} on {1}", (uint64_t)droppedHandle, (uint64_t)entity.GetUUID()); } ImGui::EndDragDropTarget(); @@ -701,65 +713,80 @@ namespace Prism switch (field.Type) { case FieldType::Int: - { - int value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); - if (UI::Property(field.Name.c_str(), value)) { - if (isRuntime) - field.SetRuntimeValue(value); - else - field.SetStoredValue(value); + int value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); + if (UI::Property(field.Name.c_str(), value)) + { + if (isRuntime) + field.SetRuntimeValue(value); + else + field.SetStoredValue(value); + } + break; } - break; - } case FieldType::Float: - { - float value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); - if (UI::Property(field.Name.c_str(), value, 0.2f)) { - if (isRuntime) - field.SetRuntimeValue(value); - else - field.SetStoredValue(value); + float value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); + if (UI::Property(field.Name.c_str(), value, 0.2f)) + { + if (isRuntime) + field.SetRuntimeValue(value); + else + field.SetStoredValue(value); + } + break; } - break; - } case FieldType::Vec2: - { - glm::vec2 value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); - if (UI::Property(field.Name.c_str(), value, 0.2f)) { - if (isRuntime) - field.SetRuntimeValue(value); - else - field.SetStoredValue(value); + glm::vec2 value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); + if (UI::Property(field.Name.c_str(), value, 0.2f)) + { + if (isRuntime) + field.SetRuntimeValue(value); + else + field.SetStoredValue(value); + } + break; } - break; - } case FieldType::Vec3: - { - glm::vec3 value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); - if (UI::Property(field.Name.c_str(), value, 0.2f)) { - if (isRuntime) - field.SetRuntimeValue(value); - else - field.SetStoredValue(value); + glm::vec3 value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); + if (UI::Property(field.Name.c_str(), value, 0.2f)) + { + if (isRuntime) + field.SetRuntimeValue(value); + else + field.SetStoredValue(value); + } + break; } - break; - } case FieldType::Vec4: - { - glm::vec4 value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); - if (UI::Property(field.Name.c_str(), value, 0.2f)) { - if (isRuntime) - field.SetRuntimeValue(value); - else - field.SetStoredValue(value); + glm::vec4 value = isRuntime ? field.GetRuntimeValue() : field.GetStoredValue(); + if (UI::Property(field.Name.c_str(), value, 0.2f)) + { + if (isRuntime) + field.SetRuntimeValue(value); + else + field.SetStoredValue(value); + } + break; } - break; - } + /* + case FieldType::ClassReference: + { + Ref* asset = (Ref*)(isRuntime ? field.GetRuntimeValueRaw() : field.GetStoredValueRaw()); + std::string label = field.Name + "(" + field.TypeName + ")"; + if (UI::PropertyAssetReference(label.c_str(), *asset)) + { + if (isRuntime) + field.SetRuntimeValueRaw(asset); + else + field.SetStoredValueRaw(asset); + } + break; + } + */ } } } diff --git a/Prism/src/Prism/Platform/Windows/WindowsFileSystemWatcher.cpp b/Prism/src/Prism/Platform/Windows/WindowsFileSystemWatcher.cpp index 40c1784..2adbad1 100644 --- a/Prism/src/Prism/Platform/Windows/WindowsFileSystemWatcher.cpp +++ b/Prism/src/Prism/Platform/Windows/WindowsFileSystemWatcher.cpp @@ -107,6 +107,16 @@ namespace Prism return result == 0; } + bool FileSystem::PrismMoveFile(const std::string& filepath, const std::string& dest) + { + s_IgnoreNextChange = true; + std::filesystem::path p = filepath; + const std::string destFilePath = dest + "/" + p.filename().string(); + const BOOL result = MoveFileA(filepath.c_str(), destFilePath.c_str()); + s_IgnoreNextChange = false; + return result != 0; + } + void FileSystem::StartWatching() { diff --git a/Prism/src/Prism/Renderer/Mesh.h b/Prism/src/Prism/Renderer/Mesh.h index f726d59..fa1ac73 100644 --- a/Prism/src/Prism/Renderer/Mesh.h +++ b/Prism/src/Prism/Renderer/Mesh.h @@ -179,10 +179,10 @@ namespace Prism // Animation bool m_IsAnimated = false; + bool m_AnimationPlaying = false; float m_AnimationTime = 0.0f; float m_WorldTime = 0.0f; float m_TimeMultiplier = 1.0f; - bool m_AnimationPlaying = false; std::string m_FilePath; private: diff --git a/Prism/src/Prism/Renderer/Renderer.h b/Prism/src/Prism/Renderer/Renderer.h index 02ab038..5146c39 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/Renderer/SceneRenderer.cpp b/Prism/src/Prism/Renderer/SceneRenderer.cpp index 204bf3f..d0f670e 100644 --- a/Prism/src/Prism/Renderer/SceneRenderer.cpp +++ b/Prism/src/Prism/Renderer/SceneRenderer.cpp @@ -110,7 +110,7 @@ namespace Prism s_Data.GeoPass = RenderPass::Create(geoRenderPassSpec); FramebufferSpecification compFramebufferSpec; - compFramebufferSpec.Attachments = { FramebufferTextureFormat::RGBA8 }; + compFramebufferSpec.Attachments = { FramebufferTextureFormat::RGBA8 , FramebufferTextureFormat::RGBA8}; compFramebufferSpec.ClearColor = { 0.1f, 0.1f, 0.1f, 1.0f }; RenderPassSpecification compRenderPassSpec; @@ -118,7 +118,7 @@ namespace Prism s_Data.CompositePass = RenderPass::Create(compRenderPassSpec); FramebufferSpecification bloomBlurFramebufferSpec; - bloomBlurFramebufferSpec.Attachments = { FramebufferTextureFormat::RGBA16F }; + bloomBlurFramebufferSpec.Attachments = { FramebufferTextureFormat::RGBA16F , FramebufferTextureFormat::RGBA8}; bloomBlurFramebufferSpec.ClearColor = { 0.1f, 0.1f, 0.1f, 1.0f }; RenderPassSpecification bloomBlurRenderPassSpec; @@ -394,7 +394,7 @@ namespace Prism s_Stats.CompositePass = s_Stats.CompositePassTimer.ElapsedMillis(); }); - // BloomBlurPass(); + BloomBlurPass(); } s_Data.DrawList.clear(); @@ -409,7 +409,7 @@ namespace Prism const bool outline = !s_Data.SelectedMeshDrawList.empty(); const bool collider = !s_Data.ColliderDrawList.empty(); - if (outline || collider) + if (outline) { Renderer::Submit([]() { @@ -419,7 +419,7 @@ namespace Prism Renderer::BeginRenderPass(s_Data.GeoPass); - if (outline || collider) + if (outline) { Renderer::Submit([]() { @@ -506,7 +506,7 @@ namespace Prism Renderer::SubmitMesh(dc.mesh, dc.Transform, overrideMaterial); } - if (collider || outline) + if (outline) { Renderer::Submit([]() { @@ -621,8 +621,8 @@ namespace Prism { Renderer::Submit([]() { - glStencilFunc(GL_NOTEQUAL, 1, 0xff); - glStencilMask(0); + // glStencilFunc(GL_NOTEQUAL, 1, 0xff); + // glStencilMask(0); glLineWidth(1); glEnable(GL_LINE_SMOOTH); @@ -652,8 +652,8 @@ namespace Prism Renderer::Submit([]() { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glStencilMask(0xff); - glStencilFunc(GL_ALWAYS, 1, 0xff); + // glStencilMask(0xff); + // glStencilFunc(GL_ALWAYS, 1, 0xff); glEnable(GL_DEPTH_TEST); }); } @@ -690,6 +690,7 @@ namespace Prism // s_Data.CompositeShader->SetFloat2("u_FocusPoint", s_Data.FocusPoint); s_Data.CompositeShader->SetInt("u_TextureSamples", s_Data.GeoPass->GetSpecification().TargetFramebuffer->GetSpecification().Samples); // s_Data.CompositeShader->SetFloat("u_BloomThreshold", s_Data.BloomThreshold); + s_Data.CompositeShader->SetFloat("u_EnableBloom", s_Data.EnableBloom); s_Data.GeoPass->GetSpecification().TargetFramebuffer->BindTexture(); Renderer::Submit([]() @@ -739,6 +740,7 @@ namespace Prism { Renderer::BeginRenderPass(s_Data.BloomBlendPass); s_Data.BloomBlendShader->Bind(); + auto & adad =s_Data; s_Data.BloomBlendShader->SetFloat("u_Exposure", s_Data.SceneData.SceneCamera.Camera.GetExposure()); s_Data.BloomBlendShader->SetBool("u_EnableBloom", s_Data.EnableBloom); diff --git a/Prism/src/Prism/Scene/Entity.cpp b/Prism/src/Prism/Scene/Entity.cpp index dc006bb..d5de3ca 100644 --- a/Prism/src/Prism/Scene/Entity.cpp +++ b/Prism/src/Prism/Scene/Entity.cpp @@ -32,4 +32,9 @@ namespace Prism { return entity.IsAncesterOf(*this); } + + bool Entity::HasParent() + { + return m_Scene->FindEntityByUUID(GetParentUUID()); + } } diff --git a/Prism/src/Prism/Scene/Entity.h b/Prism/src/Prism/Scene/Entity.h index 377e884..5735529 100644 --- a/Prism/src/Prism/Scene/Entity.h +++ b/Prism/src/Prism/Scene/Entity.h @@ -73,6 +73,7 @@ namespace Prism bool IsAncesterOf(Entity entity); bool IsDescendantOf(Entity entity) const; + bool HasParent(); UUID GetUUID() { return GetComponent().ID; } diff --git a/Prism/src/Prism/Scene/Scene.cpp b/Prism/src/Prism/Scene/Scene.cpp index f8a1492..2ad88f6 100644 --- a/Prism/src/Prism/Scene/Scene.cpp +++ b/Prism/src/Prism/Scene/Scene.cpp @@ -267,7 +267,8 @@ namespace Prism auto [transformComponent, skyLightComponent] = lights.get(entity); m_Environment = skyLightComponent.SceneEnvironment; m_EnvironmentIntensity = skyLightComponent.Intensity; - SetSkybox(m_Environment->RadianceMap); + if (m_Environment) + SetSkybox(m_Environment->RadianceMap); } } diff --git a/Prism/src/Prism/Scene/SceneSerializer.cpp b/Prism/src/Prism/Scene/SceneSerializer.cpp index ec144c1..bbc240c 100644 --- a/Prism/src/Prism/Scene/SceneSerializer.cpp +++ b/Prism/src/Prism/Scene/SceneSerializer.cpp @@ -572,6 +572,7 @@ namespace Prism std::string sceneName = data["Scene"].as(); PM_CORE_INFO("Deserializing scene '{0}'", sceneName); + /* auto environment = data["Environment"]; if (environment) { @@ -587,6 +588,7 @@ namespace Prism light.Multiplier = lightNode["Multiplier"].as(); } } + */ auto entities = data["Entities"]; if (entities) @@ -664,14 +666,16 @@ namespace Prism for (auto field : storedFields) { auto name = field["Name"].as(); + std::string typeName = field["TypeName"] ? field["TypeName"].as() : ""; auto type = static_cast(field["Type"].as()); EntityInstanceData& data = ScriptEngine::GetEntityInstanceData(m_Scene->GetUUID(), uuid); auto& moduleFieldMap = data.ModuleFieldMap; auto& publicFields = moduleFieldMap[moduleName]; if (publicFields.find(name) == publicFields.end()) { - // PublicField pf = { name, type }; - // publicFields.emplace(name, std::move(pf)); + + PublicField pf = { name, typeName, type }; + publicFields.emplace(name, std::move(pf)); PM_CORE_WARN("Script field '{0}' not found in current Script file! ignore this.", name); continue; } @@ -726,7 +730,7 @@ namespace Prism if (meshComponent["AssetPath"]) { const std::string assetFilePath = meshComponent["AssetPath"].as(); - assetID = AssetsManager::GetAssetIDForFile(assetFilePath); + assetID = AssetsManager::GetAssetHandleFromFilePath(filepath); } else { @@ -756,7 +760,7 @@ namespace Prism if (skyLightComponent["EnvironmentAssetPath"]) { const std::string filePath = skyLightComponent["EnvironmentAssetPath"].as(); - assetHandle = AssetsManager::GetAssetIDForFile(filePath); + assetHandle = AssetsManager::GetAssetHandleFromFilePath(filepath); } else { @@ -906,7 +910,7 @@ namespace Prism if (meshComponent["AssetPath"]) { const auto assetFilePath = meshComponent["AssetPath"].as(); - assetID = AssetsManager::GetAssetIDForFile(assetFilePath); + assetID = AssetsManager::GetAssetHandleFromFilePath(filepath); } else { diff --git a/Prism/src/Prism/Script/ScriptEngine.cpp b/Prism/src/Prism/Script/ScriptEngine.cpp index 15bc4fd..0e8f0ba 100644 --- a/Prism/src/Prism/Script/ScriptEngine.cpp +++ b/Prism/src/Prism/Script/ScriptEngine.cpp @@ -300,13 +300,13 @@ namespace Prism { switch (type) { - case FieldType::Float: return 4; - case FieldType::Int: return 4; - case FieldType::UnsignedInt: return 4; - // case FieldType::String: return 8; // TODO - case FieldType::Vec2: return 4 * 2; - case FieldType::Vec3: return 4 * 3; - case FieldType::Vec4: return 4 * 4; + case FieldType::Float: return 4; + case FieldType::Int: return 4; + case FieldType::UnsignedInt: return 4; + case FieldType::Vec2: return 4 * 2; + case FieldType::Vec3: return 4 * 3; + case FieldType::Vec4: return 4 * 4; + case FieldType::ClassReference: return 4; } PM_CORE_ASSERT(false, "Unknown field type!"); return 0; @@ -317,10 +317,11 @@ namespace Prism int type = mono_type_get_type(monoType); switch (type) { - case MONO_TYPE_R4: return FieldType::Float; - case MONO_TYPE_I4: return FieldType::Int; - case MONO_TYPE_U4: return FieldType::UnsignedInt; - case MONO_TYPE_STRING: return FieldType::String; + case MONO_TYPE_R4: return FieldType::Float; + case MONO_TYPE_I4: return FieldType::Int; + case MONO_TYPE_U4: return FieldType::UnsignedInt; + case MONO_TYPE_STRING: return FieldType::String; + case MONO_TYPE_CLASS: return FieldType::ClassReference; case MONO_TYPE_VALUETYPE: { const char* name = mono_type_get_name(monoType); @@ -355,10 +356,18 @@ namespace Prism return buffer; } - void PublicField::SetStoredValue_Internal(void* value) const + void PublicField::SetStoredValue_Internal(const void* value) const { - const uint32_t size = GetFieldSize(Type); - memcpy(m_StoredValueBuffer, value, size); + if (Type == FieldType::ClassReference) + { + //m_StoredValueBuffer = (uint8_t*)value; + } + else + { + const uint32_t size = GetFieldSize(Type); + memcpy(m_StoredValueBuffer, value, size); + } + } void PublicField::GetStoredValue_Internal(void* outValue) const @@ -750,18 +759,32 @@ namespace Prism MonoType* fieldType = mono_field_get_type(iter); const FieldType prismFieldType = GetPrismFieldType(fieldType); + if (prismFieldType == FieldType::ClassReference) + continue; + // TODO: Attributes MonoCustomAttrInfo* attr = mono_custom_attrs_from_field(scriptClass.Class, iter); + char* typeName = mono_type_get_name(fieldType); + if (oldFields.find(name) != oldFields.end()) { fieldMap.emplace(name, std::move(oldFields.at(name))); } else { - PublicField field = { name, prismFieldType }; + PublicField field = { name, typeName, prismFieldType }; field.m_EntityInstance = &entityInstance; field.m_MonoClassField = iter; + + /* + if (field.Type == FieldType::ClassReference) + { + const auto asset = new Ref(); + field.SetStoredValueRaw(asset); + } + */ + fieldMap.emplace(name, std::move(field)); } } @@ -874,8 +897,8 @@ namespace Prism return mono_gchandle_get_target(Handle); } - PublicField::PublicField(const std::string& name, FieldType type) - : Name(name), Type(type) + PublicField::PublicField(const std::string& name, const std::string& typeName, const FieldType type) + : Name(name), TypeName(typeName), Type(type) { m_StoredValueBuffer = AllocateBuffer(type); } @@ -883,6 +906,7 @@ namespace Prism PublicField::PublicField(PublicField&& other) { Name = std::move(other.Name); + TypeName = std::move(other.TypeName); Type = other.Type; m_EntityInstance = other.m_EntityInstance; m_MonoClassField = other.m_MonoClassField; @@ -901,7 +925,21 @@ namespace Prism void PublicField::CopyStoredValueToRuntime() { PM_CORE_ASSERT(m_EntityInstance->GetInstance()); - mono_field_set_value(m_EntityInstance->GetInstance(), m_MonoClassField, m_StoredValueBuffer); + + if (Type == FieldType::ClassReference) + { + // Create Managed Object + void* params[] = { + &m_StoredValueBuffer + }; + MonoObject* obj = ScriptEngine::Construct(TypeName + ":.ctor(intptr)", true, params); + mono_field_set_value(m_EntityInstance->GetInstance(), m_MonoClassField, obj); + } + else + { + mono_field_set_value(m_EntityInstance->GetInstance(), m_MonoClassField, m_StoredValueBuffer); + } + } bool PublicField::IsRuntimeAvailable() const @@ -911,7 +949,53 @@ namespace Prism void PublicField::SetStoredValueRaw(void* src) { - uint32_t size = GetFieldSize(Type); - memcpy(m_StoredValueBuffer, src, size); + if (Type == FieldType::ClassReference) + { + m_StoredValueBuffer = (uint8_t*)src; + } + else + { + uint32_t size = GetFieldSize(Type); + memcpy(m_StoredValueBuffer, src, size); + } + } + + void PublicField::SetRuntimeValueRaw(void* src) + { + if (Type == FieldType::ClassReference) + { + m_StoredValueBuffer = (uint8_t*)src; + } + else + { + uint32_t size = GetFieldSize(Type); + memcpy(m_StoredValueBuffer, src, size); + } + } + + void* PublicField::GetRuntimeValueRaw() + { + PM_CORE_ASSERT(m_EntityInstance->GetInstance()); + + if (Type == FieldType::ClassReference) + { + MonoObject* instance; + mono_field_get_value(m_EntityInstance->GetInstance(), m_MonoClassField, &instance); + + if (!instance) + return nullptr; + + MonoClassField* field = mono_class_get_field_from_name(mono_object_get_class(instance), "m_UnmanagedInstance"); + int* value; + mono_field_get_value(instance, field, &value); + return value; + } + else + { + uint8_t* outValue = nullptr; + mono_field_get_value(m_EntityInstance->GetInstance(), m_MonoClassField, outValue); + return outValue; + } + } } diff --git a/Prism/src/Prism/Script/ScriptEngine.h b/Prism/src/Prism/Script/ScriptEngine.h index e98df85..1ba7232 100644 --- a/Prism/src/Prism/Script/ScriptEngine.h +++ b/Prism/src/Prism/Script/ScriptEngine.h @@ -17,7 +17,7 @@ namespace Prism { enum class FieldType { - None = 0, Float, Int, UnsignedInt, String, Vec2, Vec3, Vec4 + None = 0, Float, Int, UnsignedInt, String, Vec2, Vec3, Vec4, ClassReference }; const char* FieldTypeToString(FieldType type); @@ -36,9 +36,10 @@ namespace Prism struct PublicField { std::string Name; + std::string TypeName; FieldType Type; - PublicField(const std::string& name, FieldType type); + PublicField(const std::string& name, const std::string& typeName, FieldType type); PublicField(const PublicField&) = delete; PublicField(PublicField&& other); ~PublicField(); @@ -75,13 +76,18 @@ namespace Prism } void SetStoredValueRaw(void* src); + void* GetStoredValueRaw() { return m_StoredValueBuffer; } + + void SetRuntimeValueRaw(void* src); + void* GetRuntimeValueRaw(); + private: EntityInstance* m_EntityInstance; MonoClassField* m_MonoClassField; uint8_t* m_StoredValueBuffer = nullptr; uint8_t* AllocateBuffer(FieldType type); - void SetStoredValue_Internal(void* value) const; + void SetStoredValue_Internal(const void* value) const; void GetStoredValue_Internal(void* outValue) const; void SetRuntimeValue_Internal(void* value) const; void GetRuntimeValue_Internal(void* outValue) const; diff --git a/Prism/src/Prism/Utilities/FileSystem.h b/Prism/src/Prism/Utilities/FileSystem.h index 62a807c..444c1e9 100644 --- a/Prism/src/Prism/Utilities/FileSystem.h +++ b/Prism/src/Prism/Utilities/FileSystem.h @@ -33,6 +33,7 @@ namespace Prism static bool Exists(const std::string& filepath); static std::string Rename(const std::string& filepath, const std::string& newName); static bool PrismDeleteFile(const std::string& filepath); + static bool PrismMoveFile(const std::string& filepath, const std::string& dest); static void SetChangeCallback(const FileSystemChangedCallbackFn& callback); static void StartWatching();