diff --git a/Assets/Application.SHConfig b/Assets/Application.SHConfig index fb042acb..ace52f6d 100644 --- a/Assets/Application.SHConfig +++ b/Assets/Application.SHConfig @@ -1,4 +1,4 @@ Start in Fullscreen: false -Starting Scene ID: 85177200 +Starting Scene ID: 94511900 Window Size: {x: 1920, y: 1080} Window Title: SHADE Engine \ No newline at end of file diff --git a/Assets/Scenes/Scene01.shade b/Assets/Scenes/Scene01.shade new file mode 100644 index 00000000..78101be1 --- /dev/null +++ b/Assets/Scenes/Scene01.shade @@ -0,0 +1,46 @@ +- EID: 0 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 0} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + Camera Component: + Position: {x: 0, y: 0, z: 0} + Pitch: 0 + Yaw: 0 + Roll: 0 + Width: 1250 + Height: 1080 + Near: 0.00999999978 + Far: 10000 + Perspective: true + Scripts: ~ +- EID: 1 + Name: Ambient Light + IsActive: true + NumberOfChildren: 0 + Components: + Light Component: + Position: {x: 0, y: 0, z: 0} + Type: Ambient + Direction: {x: 0, y: 0, z: 1} + Color: {x: 1, y: 1, z: 1, w: 1} + Layer: 4294967295 + Strength: 1.39999998 + Scripts: ~ +- EID: 2 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: -2.9000001, z: -7} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 7, y: 7, z: 7} + Renderable Component: + Mesh: 80365422 + Material: 0 + Scripts: ~ \ No newline at end of file diff --git a/Assets/Scenes/Scene01.shade.shmeta b/Assets/Scenes/Scene01.shade.shmeta new file mode 100644 index 00000000..3474d21c --- /dev/null +++ b/Assets/Scenes/Scene01.shade.shmeta @@ -0,0 +1,3 @@ +Name: Scene01 +ID: 94511900 +Type: 5 diff --git a/Assets/Scenes/TestScene.shade b/Assets/Scenes/TestScene.shade deleted file mode 100644 index e7f86442..00000000 --- a/Assets/Scenes/TestScene.shade +++ /dev/null @@ -1,176 +0,0 @@ -- EID: 0 - Name: Default - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: 1, y: -2, z: -4.77791452} - Rotate: {x: 1.48352981, y: 326.085083, z: 1.48352981} - Scale: {x: 1, y: 1, z: 1} - Camera Component: - Position: {x: 1, y: -2, z: -4.77791452} - Pitch: 84.9999924 - Yaw: 323.298828 - Roll: 84.9999924 - Width: 1920 - Height: 1080 - Near: 0.00999999978 - Far: 10000 - Perspective: true - Renderable Component: - Mesh: 0 - Material: 0 - Light Component: - Position: {x: 0, y: 0, z: 0} - Type: Directional - Direction: {x: 0, y: 0, z: 1} - Color: {x: 1, y: 1, z: 1, w: 1} - Layer: 4294967295 - Strength: 0 - Scripts: ~ -- EID: 1 - Name: Default - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: 1, y: -1.89999998, z: -5.80951977} - Rotate: {x: 79.572258, y: 328.815308, z: 348.792389} - Scale: {x: 1, y: 1, z: 1} - Renderable Component: - Mesh: 0 - Material: 0 - RigidBody Component: - Type: Dynamic - Mass: 1 - Drag: 0.00999999978 - Angular Drag: 0.00999999978 - Use Gravity: true - Interpolate: true - Freeze Position X: false - Freeze Position Y: false - Freeze Position Z: false - Freeze Rotation X: false - Freeze Rotation Y: false - Freeze Rotation Z: false - Collider Component: - Colliders: - - Is Trigger: false - Type: Box - Half Extents: {x: 0.5, y: 0.5, z: 0.5} - Friction: 0.400000006 - Bounciness: 0 - Density: 1 - Position Offset: {x: 0, y: 0, z: 0} - Scripts: ~ -- EID: 2 - Name: Default - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: 1, y: -1.79999995, z: -5.05146122} - Rotate: {x: 196.999405, y: 35.1145439, z: 110.940132} - Scale: {x: 1, y: 1, z: 1} - Renderable Component: - Mesh: 0 - Material: 0 - RigidBody Component: - Type: Dynamic - Mass: 1 - Drag: 0.00999999978 - Angular Drag: 0.00999999978 - Use Gravity: true - Interpolate: true - Freeze Position X: false - Freeze Position Y: false - Freeze Position Z: false - Freeze Rotation X: false - Freeze Rotation Y: false - Freeze Rotation Z: false - Collider Component: - Colliders: - - Is Trigger: false - Type: Box - Half Extents: {x: 0.5, y: 0.5, z: 0.5} - Friction: 0.400000006 - Bounciness: 0 - Density: 1 - Position Offset: {x: 0, y: 0, z: 0} - Scripts: ~ -- EID: 3 - Name: Default - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: -3, y: -1, z: -1} - Rotate: {x: 0, y: 0, z: 0} - Scale: {x: 5, y: 5, z: 5} - Renderable Component: - Mesh: 0 - Material: 0 - Scripts: - - Type: RaccoonSpin - RotateSpeed: 1 -- EID: 4 - Name: Default - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: 0, y: -3, z: -5} - Rotate: {x: 0, y: 0, z: 0} - Scale: {x: 7.5, y: 0.5, z: 7.5} - Renderable Component: - Mesh: 0 - Material: 0 - RigidBody Component: - Type: Static - Mass: 1 - Drag: 0.00999999978 - Angular Drag: 0.00999999978 - Use Gravity: true - Interpolate: true - Freeze Position X: false - Freeze Position Y: false - Freeze Position Z: false - Freeze Rotation X: false - Freeze Rotation Y: false - Freeze Rotation Z: false - Collider Component: - Colliders: - - Is Trigger: false - Type: Box - Half Extents: {x: 3.75, y: 0.25, z: 3.75} - Friction: 0.400000006 - Bounciness: 0 - Density: 1 - Position Offset: {x: 0, y: 0, z: 0} - Scripts: ~ -- EID: 5 - Name: Default - IsActive: true - NumberOfChildren: 0 - Components: - Transform Component: - Translate: {x: 3, y: -1, z: -1} - Rotate: {x: 0, y: 0, z: 0} - Scale: {x: 5, y: 5, z: 5} - Renderable Component: - Mesh: 0 - Material: 0 - Scripts: ~ -- EID: 6 - Name: Default - IsActive: true - NumberOfChildren: 0 - Components: - Light Component: - Position: {x: 0, y: 0, z: 0} - Type: Ambient - Direction: {x: 0, y: 0, z: 1} - Color: {x: 1, y: 1, z: 1, w: 1} - Layer: 4294967295 - Strength: 0.25 - Scripts: ~ \ No newline at end of file diff --git a/Assets/Scenes/TestScene.shade.shmeta b/Assets/Scenes/TestScene.shade.shmeta deleted file mode 100644 index fceb114d..00000000 --- a/Assets/Scenes/TestScene.shade.shmeta +++ /dev/null @@ -1,3 +0,0 @@ -Name: TestScene -ID: 85177200 -Type: 5 diff --git a/SHADE_Application/src/Scenes/SBMainScene.cpp b/SHADE_Application/src/Scenes/SBMainScene.cpp index 4e49f3b0..34190915 100644 --- a/SHADE_Application/src/Scenes/SBMainScene.cpp +++ b/SHADE_Application/src/Scenes/SBMainScene.cpp @@ -36,41 +36,10 @@ namespace Sandbox void SBMainScene::Load() { - SHADE::SHGraphicsSystem* graphicsSystem = static_cast(SHADE::SHSystemManager::GetSystem()); - // Create temp meshes - const auto CUBE_MESH = SHADE::SHPrimitiveGenerator::Cube(*graphicsSystem); - - //Test Racoon mesh - std::vector> handles; - std::vector> texHandles; - for (const auto& asset : SHAssetManager::GetAllAssets()) - { - switch (asset.type) - { - case AssetType::MESH: - if (asset.name == "Cube.012") - handles.emplace_back(SHResourceManager::LoadOrGet(asset.id)); - break; - case AssetType::TEXTURE: - if (asset.name == "RaccoonPreTexturedVer1_Base9") - texHandles.emplace_back(SHResourceManager::LoadOrGet(asset.id)); - break; - } - } - SHResourceManager::FinaliseChanges(); } void SBMainScene::Init() { - SHADE::SHGraphicsSystem* graphicsSystem = static_cast(SHADE::SHSystemManager::GetSystem()); - - // Create Materials - auto matInst = graphicsSystem->AddOrGetBaseMaterialInstance(); - auto customMat = graphicsSystem->AddMaterialInstanceCopy(matInst); - customMat->SetProperty("data.color", SHVec4(0.0f, 1.0f, 1.0f, 1.0f)); - customMat->SetProperty("data.textureIndex", 0); - customMat->SetProperty("data.alpha", 0.1f); - sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID); } diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index cf58d520..32a3b961 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -373,6 +373,15 @@ namespace SHADE return false; } + AssetType SHAssetManager::GetType(AssetID id) noexcept + { + if (assetCollection.find(id) == assetCollection.end()) + { + return AssetType::INVALID; + } + return assetCollection[id].type; + } + SHAsset SHAssetManager::CreateAssetFromPath(AssetPath path) noexcept { SHAsset result; diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 64527e01..cfc77ee8 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -90,6 +90,8 @@ namespace SHADE static AssetID CompileAsset(AssetPath const& path) noexcept; static FolderPointer GetRootFolder() noexcept; + + static AssetType GetType(AssetID id) noexcept; private: diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index 85925784..2bbf6e34 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -13,12 +13,18 @@ //#==============================================================# //|| Library Includes || //#==============================================================# +#include "Editor/SHEditorWidgets.hpp" #include #include +#include + #include +#include "Assets/SHAssetManager.h" +#include "Assets/Asset Types/SHSceneAsset.h" #include "Scene/SHSceneManager.h" #include "Serialization/SHSerialization.h" +#include "Serialization/Configurations/SHConfigurationManager.h" namespace SHADE { @@ -40,7 +46,7 @@ namespace SHADE { SHEditorWindow::Init(); constexpr std::string_view path = "../../Assets/Editor/Layouts"; - for(auto const& entry : std::filesystem::directory_iterator(path)) + for (auto const& entry : std::filesystem::directory_iterator(path)) { layoutPaths.push_back(entry.path()); } @@ -76,32 +82,32 @@ namespace SHADE { if (ImGui::BeginMenu("File")) { - if(ImGui::Selectable("New")) + if (ImGui::Selectable("New")) { auto editor = SHSystemManager::GetSystem(); editor->NewScene(); } - if(ImGui::Selectable("Save")) + if (ImGui::Selectable("Save")) { auto editor = SHSystemManager::GetSystem(); editor->SaveScene(); } - if(ImGui::Selectable("Load")) + if (ImGui::Selectable("Load")) { SHSerialization::DeserializeSceneFromFile(SHSceneManager::GetCurrentSceneAssetID()); } ImGui::EndMenu(); } - if(ImGui::BeginMenu("Edit")) + if (ImGui::BeginMenu("Edit")) { ImGui::BeginDisabled(!SHCommandManager::GetUndoStackSize()); - if(ImGui::Button(std::format("{} Undo", ICON_MD_UNDO).data())) + if (ImGui::Button(std::format("{} Undo", ICON_MD_UNDO).data())) { SHCommandManager::UndoCommand(); } ImGui::EndDisabled(); ImGui::BeginDisabled(!SHCommandManager::GetRedoStackSize()); - if(ImGui::Button(std::format("{} Redo", ICON_MD_REDO).data())) + if (ImGui::Button(std::format("{} Redo", ICON_MD_REDO).data())) { SHCommandManager::RedoCommand(); } @@ -112,18 +118,18 @@ namespace SHADE { if (ImGui::Selectable("Generate Visual Studio Project")) { - auto* scriptEngine = static_cast(SHSystemManager::GetSystem()); - scriptEngine->GenerateScriptsCsProjFile(); + auto* scriptEngine = static_cast(SHSystemManager::GetSystem()); + scriptEngine->GenerateScriptsCsProjFile(); } if (ImGui::Selectable("Build Scripts - Debug")) { - auto* scriptEngine = static_cast(SHSystemManager::GetSystem()); - scriptEngine->BuildScriptAssembly(true, true); + auto* scriptEngine = static_cast(SHSystemManager::GetSystem()); + scriptEngine->BuildScriptAssembly(true, true); } if (ImGui::Selectable("Build Scripts - Release")) { - auto* scriptEngine = static_cast(SHSystemManager::GetSystem()); - scriptEngine->BuildScriptAssembly(false, true); + auto* scriptEngine = static_cast(SHSystemManager::GetSystem()); + scriptEngine->BuildScriptAssembly(false, true); } ImGui::EndMenu(); } @@ -151,17 +157,46 @@ namespace SHADE } ImGui::EndMenu(); } - if(ImGui::BeginMenu("Layout")) + if (ImGui::BeginMenu("Layout")) { - for(auto const& entry : layoutPaths) + for (auto const& entry : layoutPaths) { - if(ImGui::Selectable(entry.stem().string().c_str())) + if (ImGui::Selectable(entry.stem().string().c_str())) { ImGui::LoadIniSettingsFromDisk(entry.string().c_str()); } } ImGui::EndMenu(); } + + if (ImGui::BeginMenu("Application Config")) + { + auto& appConfig = SHConfigurationManager::applicationConfig; + ImGui::InputText("Window Title", &appConfig.windowTitle); + ImGui::Checkbox("Start in Fullscreen", &appConfig.startInFullScreen); + SHEditorWidgets::DragN("Window Size", { "Width", "Height" }, { &appConfig.windowSize.x, &appConfig.windowSize.y }); + //ImGui::InputScalar("Starting Scene", ImGuiDataType_U32, &appConfig.startingSceneID); + auto sceneAsset = SHAssetManager::GetData(appConfig.startingSceneID); + + if(ImGui::BeginCombo("Starting Scne", sceneAsset ? sceneAsset->name.data() : "")) + { + auto scenes = SHAssetManager::GetAllRecordOfType(AssetType::SCENE); + for(auto const& scene : scenes) + { + if(ImGui::Selectable(scene.name.data())) + { + appConfig.startingSceneID = scene.id; + } + } + ImGui::EndCombo(); + } + if (ImGui::Button("Save")) + { + SHConfigurationManager::SaveApplicationConfig(); + } + ImGui::EndMenu(); + } + ImGui::EndMainMenuBar(); } @@ -174,19 +209,19 @@ namespace SHADE void SHEditorMenuBar::DrawSecondaryBar() const noexcept { ImGuiViewport* viewport = ImGui::GetMainViewport(); - if(ImGui::BeginViewportSideBar("##SecondaryMenuBar", viewport, ImGuiDir_Up, ImGui::GetFrameHeight(), ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_MenuBar)) + if (ImGui::BeginViewportSideBar("##SecondaryMenuBar", viewport, ImGuiDir_Up, ImGui::GetFrameHeight(), ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_MenuBar)) { ImGui::BeginMenuBar(); ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x * 0.5f - 80.f); const auto editor = SHSystemManager::GetSystem(); ImGui::BeginDisabled(editor->editorState == SHEditor::State::PLAY); - if(ImGui::SmallButton(ICON_MD_PLAY_ARROW)) + if (ImGui::SmallButton(ICON_MD_PLAY_ARROW)) { - if(editor->SaveScene()) //Set play state and invoke event only if we managed to save successfully + if (editor->SaveScene()) //Set play state and invoke event only if we managed to save successfully { const SHEditorStateChangeEvent STATE_CHANGE_EVENT { - .previousState = editor->editorState + .previousState = editor->editorState }; editor->editorState = SHEditor::State::PLAY; @@ -195,11 +230,11 @@ namespace SHADE } ImGui::EndDisabled(); ImGui::BeginDisabled(editor->editorState == SHEditor::State::PAUSE); - if(ImGui::SmallButton(ICON_MD_PAUSE)) + if (ImGui::SmallButton(ICON_MD_PAUSE)) { const SHEditorStateChangeEvent STATE_CHANGE_EVENT { - .previousState = editor->editorState + .previousState = editor->editorState }; editor->editorState = SHEditor::State::PAUSE; @@ -207,11 +242,11 @@ namespace SHADE } ImGui::EndDisabled(); ImGui::BeginDisabled(editor->editorState == SHEditor::State::STOP); - if(ImGui::SmallButton(ICON_MD_STOP)) + if (ImGui::SmallButton(ICON_MD_STOP)) { const SHEditorStateChangeEvent STATE_CHANGE_EVENT { - .previousState = editor->editorState + .previousState = editor->editorState }; editor->editorState = SHEditor::State::STOP; SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_STOP_EVENT); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 007c8639..e6d02bac 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -198,7 +198,14 @@ namespace SHADE worldRenderer->SetCameraDirector(cameraSystem->CreateDirector()); + SHVec4 defaultTexture{1.0f, 1.0f, 1.0f, 1.0f}; + std::vector mipOffsets{}; + mipOffsets.push_back(0); + auto tex = AddTexture(1, reinterpret_cast(&defaultTexture), 1, 1, SHTexture::TextureFormat::eR32G32B32A32Sfloat, mipOffsets); + BuildTextures(); + defaultMaterial = AddMaterial(defaultVertShader, defaultFragShader, gBufferSubpass); + defaultMaterial->SetProperty("data.textureIndex", tex->TextureArrayIndex); } void SHGraphicsSystem::InitMiddleEnd(void) noexcept @@ -372,6 +379,9 @@ namespace SHADE // Bind all the buffers required for meshes for (auto& [buffer, bindingPoint] : MESH_DATA) { + if (!buffer) + continue; + if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer) currentCmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0); else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer) @@ -714,11 +724,6 @@ namespace SHADE { if (!renderable.HasChanged()) continue; - - if (!renderable.GetMesh()) - { - SHLOG_CRITICAL("NULL Mesh provided!"); - } // Remove from the SuperBatch it is previously in (prevMat if mat has changed) Handle prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial(); @@ -728,9 +733,9 @@ namespace SHADE oldSuperBatch->Remove(&renderable); } - // Add to new SuperBatch if there is a material + // Add to new SuperBatch if there is a material and a mesh to render Handle newMatInstance = renderable.GetMaterial(); - if (newMatInstance) + if (newMatInstance && renderable.GetMesh()) { Handle newSuperBatch = newMatInstance->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch(); newSuperBatch->Add(&renderable); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index 57762324..0c838449 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -22,13 +22,15 @@ namespace SHADE /* SHComponent Lifecycle Functions */ /*-----------------------------------------------------------------------------------*/ void SHRenderable::OnCreate() - { + { + SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem(); + matChanged = true; - sharedMaterial = {}; material = {}; oldMaterial = {}; - lightLayer = 1; + + sharedMaterial = gfxSystem ? gfxSystem->GetDefaultMaterialInstance() : Handle(); } void SHRenderable::OnDestroy() diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp index 8719458b..90c7e35f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp @@ -154,16 +154,16 @@ namespace SHADE addJobs.clear(); /* Build Descriptor Set with all the Textures only if there are textures */ + if (!texDescriptors) + { + texDescriptors = descPool->Allocate + ( + { SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS] }, + { static_cast(texOrder.size()) } + ); + } if (!texOrder.empty()) { - if (!texDescriptors) - { - texDescriptors = descPool->Allocate - ( - { SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS] }, - { static_cast(texOrder.size()) } - ); - } texDescriptors->ModifyWriteDescImage ( SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS,