Can finally deserialize starting scene, play and stop which saves and reloads the scene.

This commit is contained in:
Sri Sham Haran 2022-11-01 21:07:56 +08:00
parent 8b4ebc557c
commit 6524639409
12 changed files with 145 additions and 253 deletions

View File

@ -1,4 +1,4 @@
Start in Fullscreen: false Start in Fullscreen: false
Starting Scene ID: 85177200 Starting Scene ID: 94511900
Window Size: {x: 1920, y: 1080} Window Size: {x: 1920, y: 1080}
Window Title: SHADE Engine Window Title: SHADE Engine

View File

@ -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: ~

View File

@ -0,0 +1,3 @@
Name: Scene01
ID: 94511900
Type: 5

View File

@ -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: ~

View File

@ -1,3 +0,0 @@
Name: TestScene
ID: 85177200
Type: 5

View File

@ -36,41 +36,10 @@ namespace Sandbox
void SBMainScene::Load() void SBMainScene::Load()
{ {
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
// Create temp meshes
const auto CUBE_MESH = SHADE::SHPrimitiveGenerator::Cube(*graphicsSystem);
//Test Racoon mesh
std::vector<Handle<SHMesh>> handles;
std::vector<Handle<SHTexture>> texHandles;
for (const auto& asset : SHAssetManager::GetAllAssets())
{
switch (asset.type)
{
case AssetType::MESH:
if (asset.name == "Cube.012")
handles.emplace_back(SHResourceManager::LoadOrGet<SHMesh>(asset.id));
break;
case AssetType::TEXTURE:
if (asset.name == "RaccoonPreTexturedVer1_Base9")
texHandles.emplace_back(SHResourceManager::LoadOrGet<SHTexture>(asset.id));
break;
}
}
SHResourceManager::FinaliseChanges();
} }
void SBMainScene::Init() void SBMainScene::Init()
{ {
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
// 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); sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID);
} }

View File

@ -373,6 +373,15 @@ namespace SHADE
return false; 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 SHAssetManager::CreateAssetFromPath(AssetPath path) noexcept
{ {
SHAsset result; SHAsset result;

View File

@ -91,6 +91,8 @@ namespace SHADE
static FolderPointer GetRootFolder() noexcept; static FolderPointer GetRootFolder() noexcept;
static AssetType GetType(AssetID id) noexcept;
private: private:
static void InitLoaders() noexcept; static void InitLoaders() noexcept;

View File

@ -13,12 +13,18 @@
//#==============================================================# //#==============================================================#
//|| Library Includes || //|| Library Includes ||
//#==============================================================# //#==============================================================#
#include "Editor/SHEditorWidgets.hpp"
#include <imgui.h> #include <imgui.h>
#include <imgui_internal.h> #include <imgui_internal.h>
#include <misc/cpp/imgui_stdlib.h>
#include <rttr/type> #include <rttr/type>
#include "Assets/SHAssetManager.h"
#include "Assets/Asset Types/SHSceneAsset.h"
#include "Scene/SHSceneManager.h" #include "Scene/SHSceneManager.h"
#include "Serialization/SHSerialization.h" #include "Serialization/SHSerialization.h"
#include "Serialization/Configurations/SHConfigurationManager.h"
namespace SHADE namespace SHADE
{ {
@ -162,6 +168,35 @@ namespace SHADE
} }
ImGui::EndMenu(); 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<float, 2>("Window Size", { "Width", "Height" }, { &appConfig.windowSize.x, &appConfig.windowSize.y });
//ImGui::InputScalar("Starting Scene", ImGuiDataType_U32, &appConfig.startingSceneID);
auto sceneAsset = SHAssetManager::GetData<SHSceneAsset>(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(); ImGui::EndMainMenuBar();
} }

View File

@ -198,7 +198,14 @@ namespace SHADE
worldRenderer->SetCameraDirector(cameraSystem->CreateDirector()); worldRenderer->SetCameraDirector(cameraSystem->CreateDirector());
SHVec4 defaultTexture{1.0f, 1.0f, 1.0f, 1.0f};
std::vector<uint32_t> mipOffsets{};
mipOffsets.push_back(0);
auto tex = AddTexture(1, reinterpret_cast<unsigned char*>(&defaultTexture), 1, 1, SHTexture::TextureFormat::eR32G32B32A32Sfloat, mipOffsets);
BuildTextures();
defaultMaterial = AddMaterial(defaultVertShader, defaultFragShader, gBufferSubpass); defaultMaterial = AddMaterial(defaultVertShader, defaultFragShader, gBufferSubpass);
defaultMaterial->SetProperty("data.textureIndex", tex->TextureArrayIndex);
} }
void SHGraphicsSystem::InitMiddleEnd(void) noexcept void SHGraphicsSystem::InitMiddleEnd(void) noexcept
@ -372,6 +379,9 @@ namespace SHADE
// Bind all the buffers required for meshes // Bind all the buffers required for meshes
for (auto& [buffer, bindingPoint] : MESH_DATA) for (auto& [buffer, bindingPoint] : MESH_DATA)
{ {
if (!buffer)
continue;
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer) if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
currentCmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0); currentCmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer) else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
@ -715,11 +725,6 @@ namespace SHADE
if (!renderable.HasChanged()) if (!renderable.HasChanged())
continue; continue;
if (!renderable.GetMesh())
{
SHLOG_CRITICAL("NULL Mesh provided!");
}
// Remove from the SuperBatch it is previously in (prevMat if mat has changed) // Remove from the SuperBatch it is previously in (prevMat if mat has changed)
Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial(); Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial();
if (prevMaterial) if (prevMaterial)
@ -728,9 +733,9 @@ namespace SHADE
oldSuperBatch->Remove(&renderable); 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<SHMaterialInstance> newMatInstance = renderable.GetMaterial(); Handle<SHMaterialInstance> newMatInstance = renderable.GetMaterial();
if (newMatInstance) if (newMatInstance && renderable.GetMesh())
{ {
Handle<SHSuperBatch> newSuperBatch = newMatInstance->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch(); Handle<SHSuperBatch> newSuperBatch = newMatInstance->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch();
newSuperBatch->Add(&renderable); newSuperBatch->Add(&renderable);

View File

@ -23,12 +23,14 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SHRenderable::OnCreate() void SHRenderable::OnCreate()
{ {
SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
matChanged = true; matChanged = true;
sharedMaterial = {};
material = {}; material = {};
oldMaterial = {}; oldMaterial = {};
lightLayer = 1; lightLayer = 1;
sharedMaterial = gfxSystem ? gfxSystem->GetDefaultMaterialInstance() : Handle<SHMaterialInstance>();
} }
void SHRenderable::OnDestroy() void SHRenderable::OnDestroy()

View File

@ -154,8 +154,6 @@ namespace SHADE
addJobs.clear(); addJobs.clear();
/* Build Descriptor Set with all the Textures only if there are textures */ /* Build Descriptor Set with all the Textures only if there are textures */
if (!texOrder.empty())
{
if (!texDescriptors) if (!texDescriptors)
{ {
texDescriptors = descPool->Allocate texDescriptors = descPool->Allocate
@ -164,6 +162,8 @@ namespace SHADE
{ static_cast<uint32_t>(texOrder.size()) } { static_cast<uint32_t>(texOrder.size()) }
); );
} }
if (!texOrder.empty())
{
texDescriptors->ModifyWriteDescImage texDescriptors->ModifyWriteDescImage
( (
SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS, SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS,