Bug fixes and scene changes #267

Merged
glencelow merged 15 commits from PlayerController into main 2022-11-23 20:53:44 +08:00
68 changed files with 1935 additions and 363 deletions
Showing only changes of commit 332d0a846d - Show all commits

View File

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

View File

@ -4,7 +4,7 @@
NumberOfChildren: 0
Components:
Camera Component:
Position: {x: 0, y: 0, z: 8}
Position: {x: 0, y: 3, z: 8}
Pitch: 0
Yaw: 0
Roll: 0
@ -13,6 +13,7 @@
Near: 0.00999999978
Far: 10000
Perspective: true
IsActive: true
Light Component:
Position: {x: 0, y: 0, z: 0}
Type: Directional
@ -20,6 +21,7 @@
Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1}
Layer: 4294967295
Strength: 0
IsActive: true
Scripts: ~
- EID: 7
Name: BigBoi
@ -30,9 +32,11 @@
Translate: {x: 0, y: -16.8647861, z: -14.039052}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975}
IsActive: true
Renderable Component:
Mesh: 149697411
Material: 126974645
IsActive: true
Scripts: ~
- EID: 8
Name: AmbientLight
@ -46,4 +50,335 @@
Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295
Strength: 0.25
IsActive: true
Scripts: ~
- EID: 65542
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 2.5, y: 0.5, z: -2.5}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 5, y: 0.5, z: 5}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 65538
Name: Movable
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 4.28833103, z: 0}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
RigidBody Component:
Type: Dynamic
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Sleeping Enabled: 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
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
- Is Trigger: false
Type: Box
Half Extents: {x: 2, y: 2, z: 2}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 65537
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 5.25, y: 2.75, z: 2.5}
Rotate: {x: 0, y: 0, z: 1.57079637}
Scale: {x: 5, y: 0.5, z: 5}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 9
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 5.25, y: 2.75, z: -2.5}
Rotate: {x: 0, y: 0, z: 1.57079637}
Scale: {x: 5, y: 0.5, z: 5}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 10
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -5.25, y: 2.75, z: 2.5}
Rotate: {x: 0, y: 0, z: 1.57079637}
Scale: {x: 5, y: 0.5, z: 5}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 11
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -5.25, y: 2.75, z: -2.5}
Rotate: {x: 0, y: 0, z: 1.57079637}
Scale: {x: 5, y: 0.5, z: 5}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 12
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 2.5, y: 2.75, z: 5.25}
Rotate: {x: 7.15255737e-07, y: 1.57079566, z: 1.57079589}
Scale: {x: 4.99999809, y: 0.499999762, z: 4.99999809}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 65551
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -2.5, y: 2.75, z: 5.25}
Rotate: {x: 7.15255737e-07, y: 1.57079566, z: 1.57079589}
Scale: {x: 4.99999809, y: 0.499999762, z: 4.99999809}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 65550
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -2.5, y: 2.75, z: -5.25}
Rotate: {x: 7.15255737e-07, y: 1.57079566, z: 1.57079589}
Scale: {x: 4.99999809, y: 0.499999762, z: 4.99999809}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 65549
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 2.5, y: 2.75, z: -5.25}
Rotate: {x: 7.15255737e-07, y: 1.57079566, z: 1.57079589}
Scale: {x: 4.99999809, y: 0.499999762, z: 4.99999809}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 16
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 2.5, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 2.5, y: 0.5, z: 2.5}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 5
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 2.5, y: 0.5, z: 2.5}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 5, y: 0.5, z: 5}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 4
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -2.5, y: 0.5, z: -2.5}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 5, y: 0.5, z: 5}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~
- EID: 3
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -2.5, y: 0.5, z: 2.5}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 5, y: 0.5, z: 5}
IsActive: true
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Rotation Offset: {x: 0, y: 0, z: 0}
IsActive: true
Scripts: ~

View File

@ -0,0 +1,84 @@
- EID: 0
Name: Canvas
IsActive: true
NumberOfChildren: 1
Components:
Canvas Component:
Canvas Width: 10
Canvas Height: 10
IsActive: true
Scripts: ~
- EID: 6
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}
IsActive: true
Renderable Component:
Mesh: 141771688
Material: 129340704
IsActive: true
Button Component:
Default Texture: 0
Hovered Texture: 0
Clicked Texture: 0
IsActive: true
Scripts: ~
- EID: 1
Name: Camera
IsActive: true
NumberOfChildren: 0
Components:
Camera Component:
Position: {x: 0, y: 3, z: 8}
Pitch: 0
Yaw: 0
Roll: 0
Width: 1920
Height: 1080
Near: 0.00999999978
Far: 10000
Perspective: true
IsActive: true
Light Component:
Position: {x: 0, y: 0, z: 0}
Type: Directional
Direction: {x: 1.79999995, y: 0, z: 1}
Color: {x: 0.951541841, y: 0.921719015, z: 0.553319454, w: 1}
Layer: 4294967295
Strength: 0
IsActive: true
Scripts: ~
- EID: 7
Name: BigBoi
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -16.8647861, z: -14.039052}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 28.1434975, y: 28.1434975, z: 28.1434975}
IsActive: true
Renderable Component:
Mesh: 149697411
Material: 126974645
IsActive: true
Scripts: ~
- EID: 8
Name: AmbientLight
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
IsActive: true
Scripts: ~

View File

@ -0,0 +1,3 @@
Name: UI Test
ID: 87707373
Type: 5

View File

@ -23,7 +23,9 @@ public class RaccoonShowcase : Script
[Range(-5, 5)]
public List<int> intList = new List<int>(new int[] { 2, 8, 2, 6, 8, 0, 1 });
public List<Light.Type> enumList = new List<Light.Type>(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient });
public FontAsset fontAsset;
public MeshAsset mesh;
public MaterialAsset matAsset;
protected override void awake()
{
Transform = GetComponent<Transform>();

View File

@ -126,7 +126,9 @@ namespace Sandbox
//SHSystemManager::RegisterRoutine<SHCameraSystem, SHCameraSystem::EditorCameraUpdate>();
SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::AddUIComponentRoutine>();
SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::UpdateCanvasMatrixRoutine>();
SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::UpdateUIMatrixRoutine>();
SHSystemManager::RegisterRoutine<SHUISystem, SHUISystem::UpdateButtonsRoutine>();
SHSystemManager::RegisterRoutine<SHCameraSystem, SHCameraSystem::CameraSystemUpdate>();
#ifdef SHEDITOR

View File

@ -44,6 +44,8 @@ namespace Sandbox
{
sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID);
#ifndef SHEDITOR
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
if (!physicsSystem)
{
@ -53,6 +55,8 @@ namespace Sandbox
physicsSystem->BuildScene(SHSceneManager::GetCurrentSceneGraph());
#endif
/*-----------------------------------------------------------------------*/
/* TESTING CODE */
/*-----------------------------------------------------------------------*/

View File

@ -53,15 +53,16 @@ project "SHADE_CSharp"
function configElementCS(cfg)
_p(2,'<Configurations>Debug;Release;Publish</Configurations>')
end
function docsElementCS(cfg)
_p(2,'<GenerateDocumentationFile>true</GenerateDocumentationFile>')
end
function docsLocationElementCS(cfg)
_p(2,'<DocumentationFile>$(OutDir)</DocumentationFile>')
end
-- function docsElementCS(cfg)
-- _p(2,'<GenerateDocumentationFile>true</GenerateDocumentationFile>')
-- end
-- function docsLocationElementCS(cfg)
-- _p(2,'<DocumentationFile>$(OutDir)</DocumentationFile>')
-- end
premake.override(premake.vstudio.cs2005.elements, "projectProperties", function (oldfn, cfg)
return table.join(oldfn(cfg), {
platformsElementCS, configElementCS, docsElementCS, docsLocationElementCS,
-- platformsElementCS, configElementCS, docsElementCS, docsLocationElementCS,
platformsElementCS, configElementCS,
})
end)

View File

@ -52,7 +52,7 @@ namespace SHADE
std::ifstream file{ path.string(), std::ios::in | std::ios::binary };
if (!file.is_open())
{
SHLOG_ERROR("Unable to open SHMesh File: {}", path.string());
SHLOG_ERROR("[Model Loader] Unable to open SHModel File: {}", path.string());
return;
}

View File

@ -26,7 +26,7 @@ namespace SHADE
if (!file.is_open())
{
SHLOG_ERROR("Unable to open text File: {}", path.string());
SHLOG_ERROR("[Text Loader] Unable to open text File: {}", path.string());
return nullptr;
}
std::stringstream stream;
@ -70,7 +70,7 @@ namespace SHADE
if (!file.is_open())
{
SHLOG_ERROR("Unable to open text File: {}", path.string());
SHLOG_ERROR("[Text Loader] Unable to open text File: {}", path.string());
return;
}

View File

@ -22,7 +22,7 @@ namespace SHADE
std::ifstream file{ path.string(), std::ios::in | std::ios::binary };
if (!file.is_open())
{
SHLOG_ERROR("Error opening SHTexture file: {}", path.string());
SHLOG_ERROR("[Texture Loader] Error opening SHTexture file: {}", path.string());
}
auto const intBytes{ sizeof(uint32_t) };
@ -61,7 +61,7 @@ namespace SHADE
std::ofstream file{ path, std::ios::out | std::ios::binary };
if (!file.is_open())
{
SHLOG_ERROR("Unable to open file for writing texture file: {}", path.string());
SHLOG_ERROR("[Texture Loader] Unable to open file for writing texture file: {}", path.string());
}
auto asset = *dynamic_cast<SHTextureAsset const*>(data);

View File

@ -220,7 +220,7 @@ namespace SHADE
break;
default:
SHLOG_ERROR("Asset type of {} not an internal asset type, cannot be created", name);
SHLOG_ERROR("[Asset Manager] Asset type of {} not an internal asset type, cannot be created", name);
return 0;
}
@ -272,14 +272,14 @@ namespace SHADE
return true;
}
SHLOG_ERROR("Asset data has not been written into, cannot be saved: {}",
SHLOG_ERROR("[Asset Manager] Asset data has not been written into, cannot be saved: {}",
asset.path.filename().string());
return false;
}
}
SHLOG_WARNING("Asset id: {} not an internal asset type, save cannot be triggered", id);
SHLOG_WARNING("[Asset Manager] Asset id: {} not an internal asset type, save cannot be triggered", id);
return false;
}
@ -297,10 +297,10 @@ namespace SHADE
{
return (DeleteLocalFile(asset.path) && DeleteLocalFile(asset.path.string() + META_EXTENSION.data()));
}
SHLOG_WARNING("Asset id: {} not an internal asset type, file deletion not allowed", id);
SHLOG_WARNING("[Asset Manager] Asset id: {} not an internal asset type, file deletion not allowed", id);
}
SHLOG_WARNING("Asset id does not exist, nothing was deleted: {}", id);
SHLOG_WARNING("[Asset Manager] Asset id does not exist, nothing was deleted: {}", id);
return false;
}
@ -334,7 +334,7 @@ namespace SHADE
std::filesystem::path const newPath{ GenerateLocalPath(path) };
if (newPath.empty())
{
SHLOG_WARNING("Unsupported file format for asset: {}", path.string());
SHLOG_WARNING("[Asset Manager] Unsupported file format for asset: {}", path.string());
return 0;
}
@ -386,7 +386,7 @@ namespace SHADE
{
if (!std::filesystem::exists(path))
{
SHLOG_ERROR("Path provided does not point to a file: {}", path.string());
SHLOG_ERROR("[Asset Manager] Path provided does not point to a file: {}", path.string());
return;
}
AssetPath newPath;
@ -416,7 +416,7 @@ namespace SHADE
auto pathGen = SHTextureCompiler::CompileTextureAsset(path);
if (!pathGen.has_value())
{
SHLOG_ERROR("Texture Compilation Failed for: {}", path.string());
SHLOG_ERROR("[Asset Manager] Texture Compilation Failed for: {}", path.string());
return;
}
newPath = pathGen.value();
@ -433,7 +433,7 @@ namespace SHADE
}
else
{
SHLOG_WARNING("File Type compilation not yet Implemented: {}", path.string());
SHLOG_WARNING("[Asset Manager] File Type compilation not yet Implemented: {}", path.string());
return;
}
@ -520,7 +520,7 @@ namespace SHADE
SHAssetData* data = loaders[static_cast<size_t>(asset.type)]->Load(asset.path);
if (data == nullptr)
{
SHLOG_ERROR("Unable to load asset into memory: {}\n", asset.path.string());
SHLOG_ERROR("[Asset Manager] Unable to load asset into memory: {}\n", asset.path.string());
}
else
{
@ -537,7 +537,7 @@ namespace SHADE
if (parentData == nullptr)
{
SHLOG_ERROR("Unable to load asset into memory: {}\n", parent.path.string());
SHLOG_ERROR("[Asset Manager] Unable to load asset into memory: {}\n", parent.path.string());
}
else
{
@ -653,6 +653,34 @@ namespace SHADE
return newAsset.id;
}
else if(ext == MATERIAL_EXTENSION)
{
SHAsset newAsset{
path.stem().string(),
GenerateAssetID(AssetType::MATERIAL),
AssetType::MATERIAL,
path,
false
};
assetCollection.emplace(newAsset.id, newAsset);
SHAssetMetaHandler::WriteMetaData(newAsset);
return newAsset.id;
}
else if (ext == PREFAB_EXTENSION)
{
SHAsset newAsset{
path.stem().string(),
GenerateAssetID(AssetType::PREFAB),
AssetType::PREFAB,
path,
false
};
assetCollection.emplace(newAsset.id, newAsset);
SHAssetMetaHandler::WriteMetaData(newAsset);
return newAsset.id;
}
else if (ext == FONT_EXTENSION)
{
SHAsset newAsset{

View File

@ -90,5 +90,22 @@ namespace SHADE
return SHMatrix::Identity;
}
float SHCameraDirector::GetWidth() noexcept
{
SHCameraComponent* camComponent = GetMainCameraComponent();
if (camComponent)
return camComponent->GetWidth();
else
return 0.0f;
}
float SHCameraDirector::GetHeight() noexcept
{
SHCameraComponent* camComponent = GetMainCameraComponent();
if (camComponent)
return camComponent->GetHeight();
else
return 0.0f;
}
}

View File

@ -30,6 +30,8 @@ namespace SHADE
void SetMainCamera(SHCameraComponent& cam) noexcept;
SHMatrix const& GetOrthoMatrix() noexcept;
SHMatrix const& GetPerspectiveMatrix() noexcept;
float GetWidth() noexcept;
float GetHeight() noexcept;
private:
SHMatrix viewMatrix;

View File

@ -8,6 +8,8 @@
#include "Math/Transform/SHTransformComponent.h"
#include <math.h>
#include "Scene/SHSceneManager.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Editor/SHEditor.h"
namespace SHADE
{
@ -57,6 +59,8 @@ namespace SHADE
//std::cout << camera.yaw << std::endl;
camera.pitch -= mouseY * dt * camera.turnSpeed.x;
camera.yaw -= mouseX * dt * camera.turnSpeed.y;
camera.dirtyView = true;
@ -150,6 +154,8 @@ namespace SHADE
void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept
{
if (camera.isActive == false)
return;
@ -436,4 +442,22 @@ namespace SHADE
SetCameraViewMatrix(camera, viewMtx);
}
SHVec2 SHCameraSystem::GetCameraWidthHeight(size_t index) noexcept
{
#ifdef SHEDITOR
auto editor = SHSystemManager::GetSystem<SHEditor>();
if (editor->editorState != SHEditor::State::PLAY)
{
return SHVec2{ GetEditorCamera()->GetWidth(), GetEditorCamera()->GetHeight() };
}
else
{
return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() };
}
#else
return SHVec2{ GetDirector(index)->GetWidth(),GetDirector(index)->GetHeight() };
#endif
}
}

View File

@ -29,6 +29,7 @@ namespace SHADE
void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept;
public:
SHCameraSystem(void) = default;
virtual ~SHCameraSystem(void) = default;
@ -57,6 +58,8 @@ namespace SHADE
void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept;
void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept;
void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept;
SHVec2 GetCameraWidthHeight(size_t index) noexcept;
};

View File

@ -333,10 +333,10 @@ namespace SHADE
auto cursorPos = ImGui::GetCursorPos();
//collider->IsTrigger
if (collider->GetType() == SHCollisionShape::Type::BOX)
{
SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
const auto* BOX = reinterpret_cast<const SHBox*>(collider->GetShape());
SHEditorWidgets::DragVec3
(
@ -360,6 +360,15 @@ namespace SHADE
}
{
SHEditorWidgets::CheckBox("Is Trigger", [collider] { return collider->IsTrigger(); }, [collider](bool value) { collider->SetIsTrigger(value); });
if(ImGui::CollapsingHeader("Physics Material"))
{
SHEditorWidgets::DragFloat("Friction", [collider] { return collider->GetFriction(); }, [collider](float value) { collider->SetFriction(value); }, "Friction", 0.05f, 0.0f, 1.0f);
SHEditorWidgets::DragFloat("Bounciness", [collider] { return collider->GetBounciness(); }, [collider](float value) { collider->SetBounciness(value); }, "Bounciness", 0.05f, 0.0f, 1.0f);
SHEditorWidgets::DragFloat("Mass Density", [collider] { return collider->GetDensity(); }, [collider](float value) { collider->SetDensity(value); }, "Mass Density", 0.1f, 0.0f);
}
SHEditorWidgets::BeginPanel("Offsets",{ ImGui::GetContentRegionAvail().x, 30.0f });
SHEditorWidgets::DragVec3("Position", { "X", "Y", "Z" }, [&collider] {return collider->GetPositionOffset(); }, [&collider](SHVec3 const& vec) {collider->SetPositionOffset(vec); });
SHEditorWidgets::DragVec3("Rotation", { "X", "Y", "Z" },
@ -375,8 +384,6 @@ namespace SHADE
SHEditorWidgets::EndPanel();
}
SHEditorWidgets::CheckBox("Is Trigger", [collider] { return collider->IsTrigger(); }, [collider](bool value) { collider->SetIsTrigger(value); });
if (ImGui::Button(std::format("{} Remove Collider #{}", ICON_MD_REMOVE, i).data()))
{
colliderToDelete = i;

View File

@ -20,6 +20,7 @@
#include "Camera/SHCameraArmComponent.h"
#include "UI/SHUIComponent.h"
#include "UI/SHCanvasComponent.h"
#include "UI/SHButtonComponent.h"
#include "SHEditorComponentView.h"
#include "AudioSystem/SHAudioListenerComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
@ -149,6 +150,10 @@ namespace SHADE
{
DrawComponent(textRendererComponent);
}
if (auto buttonComponent = SHComponentManager::GetComponent_s<SHButtonComponent>(eid))
{
DrawComponent(buttonComponent);
}
ImGui::Separator();
// Render Scripts
SHScriptEngine* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
@ -161,6 +166,7 @@ namespace SHADE
DrawAddComponentButton<SHCameraArmComponent>(eid);
DrawAddComponentButton<SHLightComponent>(eid);
DrawAddComponentButton<SHCanvasComponent>(eid);
DrawAddComponentButton<SHButtonComponent>(eid);
// Components that require Transforms

View File

@ -20,6 +20,7 @@
#include "Assets/SHAssetManager.h"
#include "Assets/Asset Types/SHSceneAsset.h"
#include "ECS_Base/Managers/SHEntityManager.h"
#include "Scene/SHSceneManager.h"
#include "Serialization/SHSerialization.h"
#include "Serialization/Configurations/SHConfigurationManager.h"
@ -256,11 +257,13 @@ namespace SHADE
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { ImVec2(0.0f, 0.0f) });
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]);
if (ImGui::BeginViewportSideBar("MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, menuBarHeight, editorMenuBarFlags))
{
ImGui::Text("Entity count: ");
ImGui::Text("Entity count: %zu", SHEntityManager::GetEntityCount());
}
ImGui::End();
ImGui::PopStyleColor();
ImGui::PopStyleVar(3);
}

View File

@ -15,8 +15,10 @@ of DigiPen Institute of Technology is prohibited.
#include "SHEditorUI.h"
// External Dependencies
#include <imgui.h>
// Project Includes
#include "SHEditorWidgets.hpp"
#include "ECS_Base/Managers/SHEntityManager.h"
#include "Assets/SHAssetManager.h"
namespace SHADE
{
@ -351,6 +353,53 @@ namespace SHADE
return changed;
}
bool SHEditorUI::InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered)
{
// Label
if (!label.empty())
{
ImGui::Text(label.c_str());
ImGui::SameLine();
}
// Hover tracking
if (isHovered)
*isHovered = ImGui::IsItemHovered();
ImGui::SameLine();
// Attempt to get the asset's data for rendering editor
auto asset = SHAssetManager::GetAsset(value);
std::string assetName;
if (asset.has_value())
{
assetName = asset.value().name;
}
// Editor
bool changed = ImGui::InputText("##", &assetName, ImGuiInputTextFlags_ReadOnly);
if (SHDragDrop::BeginTarget())
{
if (AssetID* payload = SHDragDrop::AcceptPayload<AssetID>(SHDragDrop::DRAG_RESOURCE))
{
// Check if type matches
auto draggedAsset = SHAssetManager::GetAsset(*payload);
if (draggedAsset.has_value() && draggedAsset.value().type == type)
{
value = draggedAsset.value().id;
changed = true;
}
SHDragDrop::EndTarget();
}
}
ImGui::SameLine();
if (ImGui::Button("Clear"))
{
value = INVALID_ASSET_ID;
changed = true;
}
return changed;
}
bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector<std::string>& enumNames, bool* isHovered)
{
// Clamp input value

View File

@ -19,6 +19,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Math/Vector/SHVec3.h"
#include "Math/Vector/SHVec4.h"
#include "Math/SHMatrix.h"
#include "Assets/SHAssetMacros.h"
namespace SHADE
{
@ -298,7 +299,7 @@ namespace SHADE
/// <returns>True if the value was changed.</returns>
static bool InputTextField(const std::string& label, std::string& value, bool* isHovered = nullptr);
/// <summary>
/// Creates a drag field widget for int input.
/// Creates a drag field widget for GameObject input.
/// </summary>
/// <param name="label">Label used to identify this widget.</param>
/// <param name="value">Reference to the variable to store the result.</param>
@ -310,6 +311,13 @@ namespace SHADE
/// <returns>True if the value was changed.</returns>
static bool InputGameObjectField(const std::string& label, uint32_t& value, bool* isHovered = nullptr, bool alwaysNull = false);
/// <summary>
/// Creates a drag field widget for Asset input.
/// </summary>
/// <param name="label">Label used to identify this widget.</param>
/// <param name="value">Reference to the variable to store the result.</param>
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
static bool InputAssetField(const std::string& label, AssetID& value, AssetType type, bool* isHovered = nullptr);
/// <summary>
/// Creates a combo box for enumeration input.
/// </summary>
/// <typeparam name="Enum">The type of enum to input.</typeparam>

View File

@ -454,12 +454,12 @@ namespace SHADE
ImGui::BeginGroup();
ImGui::PushID(label.data());
TextLabel(label);
const bool hasChange = ImGui::DragScalar("##dragScalar", data_type, &value, speed, &p_min, &p_max, displayFormat, flags);
const bool hasChange = ImGui::InputScalar("##dragScalar", data_type, &value);
static bool startRecording = false;
if (hasChange)
{
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), startRecording);
if (!startRecording)
if (!startRecording && ImGui::IsMouseDown(ImGuiMouseButton_Left))
startRecording = true;
}
if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
@ -477,7 +477,7 @@ namespace SHADE
ImGui::EndTooltip();
}
}
return hasChange;
return false;
}
static bool DragFloat(const std::string_view& label, std::function<float(void)> get, std::function<void(float const&)> set, std::string_view const& tooltip = {},

View File

@ -313,6 +313,7 @@ namespace SHADE
auto uiComp = SHComponentManager::GetComponent_s<SHUIComponent>(rendId);
if (uiComp)
{
if(uiComp->isActive)
transformData.emplace_back(uiComp->GetMatrix());
}
else

View File

@ -55,7 +55,11 @@ namespace SHADE
void SHSuperBatch::Remove(const SHRenderable* renderable) noexcept
{
Handle<SHMaterial> baseMat = (renderable->HasMaterialChanged() ? renderable->GetPrevMaterial() : renderable->GetMaterial())->GetBaseMaterial();
Handle<SHMaterialInstance> matInst = renderable->HasMaterialChanged() ? renderable->GetPrevMaterial() : renderable->GetMaterial();
if (!matInst)
return;
Handle<SHMaterial> baseMat = matInst->GetBaseMaterial();
const Handle<SHVkPipeline> PIPELINE = baseMat->HasPipelineChanged() ? baseMat->GetPrevPipeline() : baseMat->GetPipeline();
// Check if we have a Batch with the same pipeline yet

View File

@ -34,9 +34,10 @@ namespace SHADE
void SHRenderable::OnDestroy()
{
// Remove from SuperBatch
if (sharedMaterial)
auto currMat = GetMaterial();
if (currMat)
{
Handle<SHSuperBatch> superBatch = sharedMaterial->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch();
Handle<SHSuperBatch> superBatch = currMat->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch();
superBatch->Remove(this);
}
@ -64,7 +65,6 @@ namespace SHADE
if (material)
{
oldMaterial = material;
material.Free();
material = {};
}
else if (sharedMaterial)
@ -76,6 +76,12 @@ namespace SHADE
sharedMaterial = materialInstance;
}
void SHRenderable::SetMaterial(Handle<SHMaterial> material)
{
SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(material));
}
Handle<SHMaterialInstance> SHRenderable::GetMaterial() const
{
if (material)
@ -144,6 +150,8 @@ namespace SHADE
{
matChanged = false;
meshChanged = false;
if (oldMaterial)
oldMaterial.Free();
oldMaterial = {};
oldMesh = {};
}

View File

@ -48,6 +48,7 @@ namespace SHADE
/*-------------------------------------------------------------------------------*/
/* Material Functions */
/*-------------------------------------------------------------------------------*/
void SetMaterial(Handle<SHMaterial> material);
void SetMaterial(Handle<SHMaterialInstance> materialInstance);
Handle<SHMaterialInstance> GetMaterial() const;
Handle<SHMaterialInstance> GetModifiableMaterial();

View File

@ -47,14 +47,14 @@ namespace SHADE
{
// Get the current scene graph to traverse and update
const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph();
UpdateEntity(SCENE_GRAPH.GetRoot(), !IsRunInEditorPause);
UpdateEntity(SCENE_GRAPH.GetRoot(), false);
}
void SHTransformSystem::TransformPostPhysicsUpdate::Execute(double) noexcept
{
// Get the current scene graph to traverse and update
const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph();
UpdateEntity(SCENE_GRAPH.GetRoot(), IsRunInEditorPause);
UpdateEntity(SCENE_GRAPH.GetRoot(), true);
}
void SHTransformSystem::Init()

View File

@ -359,6 +359,10 @@ RTTR_REGISTRATION
);
registration::class_<SHCollisionShape>("Collider")
.property("IsTrigger" , &SHCollisionShape::IsTrigger , &SHCollisionShape::SetIsTrigger )
.property("Friction" , &SHCollisionShape::GetFriction , &SHCollisionShape::SetFriction )
.property("Bounciness" , &SHCollisionShape::GetBounciness , &SHCollisionShape::SetBounciness )
.property("Density" , &SHCollisionShape::GetDensity , &SHCollisionShape::SetDensity )
.property("Position Offset" , &SHCollisionShape::GetPositionOffset, &SHCollisionShape::SetPositionOffset)
.property("Rotation Offset" , &SHCollisionShape::GetRotationOffset, &SHCollisionShape::SetRotationOffset) (metadata(META::angleInRad, true));
}

View File

@ -123,12 +123,14 @@ namespace SHADE
default: break;
}
auto* rp3dCollider = rp3dBody->getCollider(rp3dBody->getNbColliders() - 1);
syncColliderProperties(collisionShape, rp3dCollider);
if (rp3dBody->getType() == rp3d::BodyType::DYNAMIC)
{
rp3dBody->updateMassPropertiesFromColliders();
auto* rigidBodyComponent = SHComponentManager::GetComponent_s<SHRigidBodyComponent>(entityID);
if (rigidBodyComponent)
if (auto* rigidBodyComponent = SHComponentManager::GetComponent_s<SHRigidBodyComponent>(entityID); rigidBodyComponent)
rigidBodyComponent->mass = rp3dBody->getMass();
}
@ -326,28 +328,42 @@ namespace SHADE
default: break;
}
// Sync material
auto* rp3dCollider = rp3dBody->getCollider(i);
auto& rp3dMaterial = rp3dCollider->getMaterial();
rp3dMaterial.setFrictionCoefficient(collisionShape.GetFriction());
rp3dMaterial.setBounciness(collisionShape.GetBounciness());
rp3dMaterial.setMassDensity(collisionShape.GetDensity());
// Sync tags
const unsigned short MASK_BITS = collisionShape.GetCollisionTag();
rp3dCollider->setCollisionCategoryBits(MASK_BITS);
rp3dCollider->setCollideWithMaskBits(MASK_BITS);
syncColliderProperties(collisionShape, rp3dCollider);
collisionShape.dirty = false;
}
// Set rigidbody mass if dynamic
auto* rigidBodyComponent = SHComponentManager::GetComponent_s<SHRigidBodyComponent>(entityID);
if (rigidBodyComponent)
{
// This is generally expensive, will be optimised in the future with my own engine.
rp3dBody->updateMassPropertiesFromColliders();
rigidBodyComponent->mass = rp3dBody->getMass();
}
}
/*-----------------------------------------------------------------------------------*/
/* Private Function Member Definitions */
/*-----------------------------------------------------------------------------------*/
void SHPhysicsObject::addBoxShape(SHCollisionShape& boxShape) const noexcept
void SHPhysicsObject::syncColliderProperties(const SHCollisionShape& collisionShape, rp3d::Collider* rp3dCollider) const noexcept
{
rp3dCollider->setIsTrigger(collisionShape.IsTrigger());
auto& rp3dMaterial = rp3dCollider->getMaterial();
rp3dMaterial.setFrictionCoefficient(collisionShape.GetFriction());
rp3dMaterial.setBounciness(collisionShape.GetBounciness());
rp3dMaterial.setMassDensity(collisionShape.GetDensity());
const unsigned short MASK_BITS = collisionShape.GetCollisionTag();
rp3dCollider->setCollisionCategoryBits(MASK_BITS);
rp3dCollider->setCollideWithMaskBits(MASK_BITS);
}
void SHPhysicsObject::addBoxShape(const SHCollisionShape& boxShape) const noexcept
{
const rp3d::Transform OFFSETS
{
@ -361,7 +377,7 @@ namespace SHADE
rp3dBody->addCollider(newBox, OFFSETS);
}
void SHPhysicsObject::syncBoxShape(int index, SHCollisionShape& boxShape) const noexcept
void SHPhysicsObject::syncBoxShape(int index, const SHCollisionShape& boxShape) const noexcept
{
const auto* BOX = reinterpret_cast<const SHBox*>(boxShape.GetShape());
@ -380,7 +396,7 @@ namespace SHADE
rp3dBox->setHalfExtents(BOX->GetWorldExtents());
}
void SHPhysicsObject::addSphereShape(SHCollisionShape& sphereShape) const noexcept
void SHPhysicsObject::addSphereShape(const SHCollisionShape& sphereShape) const noexcept
{
const rp3d::Transform OFFSETS
{
@ -394,7 +410,7 @@ namespace SHADE
rp3dBody->addCollider(newSphere, OFFSETS);
}
void SHPhysicsObject::syncSphereShape(int index, SHCollisionShape& sphereShape) const noexcept
void SHPhysicsObject::syncSphereShape(int index, const SHCollisionShape& sphereShape) const noexcept
{
const auto* SPHERE = reinterpret_cast<const SHSphere*>(sphereShape.GetShape());

View File

@ -96,14 +96,16 @@ namespace SHADE
/* Function Members */
/*---------------------------------------------------------------------------------*/
void syncColliderProperties (const SHCollisionShape& collisionShape, rp3d::Collider* rp3dCollider) const noexcept;
// Box Shapes
void addBoxShape (SHCollisionShape& boxShape) const noexcept;
void syncBoxShape (int index, SHCollisionShape& boxShape) const noexcept;
void addBoxShape (const SHCollisionShape& boxShape) const noexcept;
void syncBoxShape (int index, const SHCollisionShape& boxShape) const noexcept;
// Sphere Shapes
void addSphereShape (SHCollisionShape& sphereShape) const noexcept;
void syncSphereShape (int index, SHCollisionShape& sphereShape) const noexcept;
void addSphereShape (const SHCollisionShape& sphereShape) const noexcept;
void syncSphereShape (int index, const SHCollisionShape& sphereShape) const noexcept;
};
} // namespace SHADE

View File

@ -21,6 +21,14 @@
#include "Input/SHInputManager.h"
/*-------------------------------------------------------------------------------------*/
/* Local Functions */
/*-------------------------------------------------------------------------------------*/
void testFunction();
/////////////////////////////////////////////////////////////////////////////////////////
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
@ -134,6 +142,8 @@ namespace SHADE
const double FIXED_DT = physicsSystem->fixedDT;
accumulatedTime += dt;
//testFunction();
int count = 0;
while (accumulatedTime > FIXED_DT)
{
@ -292,11 +302,14 @@ namespace SHADE
{
colliderComponent->position = WORLD_POS;
colliderComponent->orientation = WORLD_ROT;
colliderComponent->scale = WORLD_SCL;
if (colliderComponent->scale != WORLD_SCL)
{
colliderComponent->scale = WORLD_SCL;
colliderComponent->RecomputeCollisionShapes();
}
}
}
void SHPhysicsSystem::PhysicsPostUpdate::postUpdateSyncTransforms
(
@ -315,6 +328,10 @@ namespace SHADE
if (physicsObject.GetRigidBody()->isActive())
physicsObject.prevTransform = CURRENT_TF;
// Skip sleeping objects
if (physicsObject.GetRigidBody()->isSleeping())
return;
// Sync with rigid bodies
if (rigidBodyComponent && SHSceneManager::CheckNodeAndComponentsActive<SHRigidBodyComponent>(physicsObject.entityID))
{
@ -336,11 +353,12 @@ namespace SHADE
rigidBodyComponent->position = CURRENT_TF.getPosition();
rigidBodyComponent->orientation = CURRENT_TF.getOrientation();
}
// Sync with colliders
if (colliderComponent && SHSceneManager::CheckNodeAndComponentsActive<SHColliderComponent>(physicsObject.entityID))
{
// Skip colliders without rigidbody components. If any transform was updated, it was done in pre-update.
colliderComponent->position = CURRENT_TF.getPosition();
colliderComponent->orientation = CURRENT_TF.getOrientation();
}
@ -352,4 +370,35 @@ namespace SHADE
transformComponent->SetWorldOrientation(renderRot);
}
}
}
} // namespace SHADE
/////////////////////////////////////////////////////////////////////////////////////////
void testFunction()
{
using namespace SHADE;
// Test movement
const float forceModifier = 25.0f;
EntityID eid = 65538;
if (SHEntityManager::IsValidEID(eid))
{
auto* rb = SHComponentManager::GetComponent_s<SHRigidBodyComponent>(eid);
if (rb)
{
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::W))
rb->AddForce(-SHVec3::UnitZ * forceModifier);
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A))
rb->AddForce(-SHVec3::UnitX * forceModifier);
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::S))
rb->AddForce(SHVec3::UnitZ * forceModifier);
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::D))
rb->AddForce(SHVec3::UnitX * forceModifier);
}
}
}

View File

@ -49,6 +49,7 @@ namespace SHADE
template<> struct SHResourceLoader<SHMaterialSpec> { using AssetType = SHMaterialAsset; };
template<> struct SHResourceLoader<SHMaterial> { using AssetType = SHMaterialSpec; };
template<> struct SHResourceLoader<SHFont> { using AssetType = SHFontAsset; };
/// <summary>
/// Static class responsible for loading and caching runtime resources from their
/// serialised Asset IDs.

View File

@ -0,0 +1,59 @@
/************************************************************************************//*!
\file SHResourceManagerInterface.cpp
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 22, 2022
\brief Contains the definition of the functions of the
SHResourceManagerInterface static class.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Precompiled Header
#include "SHpch.h"
// Primary Include
#include "SHResourceManagerInterface.h"
// Project Includes
#include "SHResourceManager.h"
namespace SHADE
{
Handle<SHMesh> SHResourceManagerInterface::LoadOrGetMesh(AssetID assetId)
{
return SHResourceManager::LoadOrGet<SHMesh>(assetId);
}
Handle<SHTexture> SHResourceManagerInterface::LoadOrGetTexture(AssetID assetId)
{
return SHResourceManager::LoadOrGet<SHTexture>(assetId);
}
Handle<SHVkShaderModule> SHResourceManagerInterface::LoadOrGetShaderModule(AssetID assetId)
{
return SHResourceManager::LoadOrGet<SHVkShaderModule>(assetId);
}
Handle<SHMaterialSpec> SHResourceManagerInterface::LoadOrGetMaterialSpec(AssetID assetId)
{
return SHResourceManager::LoadOrGet<SHMaterialSpec>(assetId);
}
Handle<SHMaterial> SHResourceManagerInterface::LoadOrGetMaterial(AssetID assetId)
{
return SHResourceManager::LoadOrGet<SHMaterial>(assetId);
}
Handle<SHFont> SHResourceManagerInterface::LoadOrGetFont(AssetID assetId)
{
return SHResourceManager::LoadOrGet<SHFont>(assetId);
}
/*-----------------------------------------------------------------------------------*/
/* Query Functions */
/*-----------------------------------------------------------------------------------*/
std::optional<AssetID> SHResourceManagerInterface::GetAssetID(Handle<void> handle)
{
return SHResourceManager::GetAssetID(handle);
}
std::optional<std::string> SHResourceManagerInterface::GetAssetName(Handle<void> handle)
{
return SHResourceManager::GetAssetName(handle);
}
}

View File

@ -0,0 +1,111 @@
/************************************************************************************//*!
\file SHResourceManagerInterface.h
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 22, 2022
\brief Contains the definition of the SHResourceManagerInterface static class.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// STL Includes
#include <optional>
// Project Includes
#include "SH_API.h"
#include "Resource/SHHandle.h"
#include "Assets/SHAssetMacros.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Forward Declarations */
/*-----------------------------------------------------------------------------------*/
class SHMesh;
class SHTexture;
class SHVkShaderModule;
struct SHMaterialSpec;
class SHMaterial;
class SHFont;
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
/// <summary>
/// Static class providing access to non-templated functions of SHResourceManager for
/// SHADE_Managed.
/// </summary>
class SH_API SHResourceManagerInterface
{
public:
/*---------------------------------------------------------------------------------*/
/* Loading Functions */
/*---------------------------------------------------------------------------------*/
/// <summary>
/// Wrapper for SHResourceManager::LoadOrGet<SHMesh>().
/// </summary>
/// <param name="assetId">Asset ID of the resource to load.</param>
/// <returns>Handle to the resource to retrieve.</returns>
static Handle<SHMesh> LoadOrGetMesh(AssetID assetId);
/// <summary>
/// Wrapper for SHResourceManager::LoadOrGet<SHTexture>().
/// </summary>
/// <param name="assetId"></param>
/// <returns>Handle to the resource to retrieve.</returns>
static Handle<SHTexture> LoadOrGetTexture(AssetID assetId);
/// <summary>
/// Wrapper for SHResourceManager::LoadOrGet<SHVkShaderModule>().
/// </summary>
/// <param name="assetId">Asset ID of the resource to load.</param>
/// <returns>Handle to the resource to retrieve.</returns>
static Handle<SHVkShaderModule> LoadOrGetShaderModule(AssetID assetId);
/// <summary>
/// Wrapper for SHResourceManager::LoadOrGet<SHMaterialSpec>().
/// </summary>
/// <param name="assetId">Asset ID of the resource to load.</param>
/// <returns>Handle to the resource to retrieve.</returns>
static Handle<SHMaterialSpec> LoadOrGetMaterialSpec (AssetID assetId);
/// <summary>
/// Wrapper for SHResourceManager::LoadOrGet<SHMaterial>().
/// </summary>
/// <param name="assetId">Asset ID of the resource to load.</param>
/// <returns>Handle to the resource to retrieve.</returns>
static Handle<SHMaterial> LoadOrGetMaterial(AssetID assetId);
/// <summary>
/// Wrapper for SHResourceManager::LoadOrGet<SHFont>().
/// </summary>
/// <param name="assetId">Asset ID of the resource to load.</param>
/// <returns>Handle to the resource to retrieve.</returns>
static Handle<SHFont> LoadOrGetFont(AssetID assetId);
/*---------------------------------------------------------------------------------*/
/* Query Functions */
/*---------------------------------------------------------------------------------*/
/// <summary>
/// Retrieves the AssetID associated with a specified Handle.
/// Compared to the templated version, this function is slower as it requires
/// searching through the storage of all resource types.
/// </summary>
/// <param name="handle">Handle to get the AssetID of.</param>
/// <return>
/// AssetID for the specified Handle. If the Handle is invalid, there will be no
/// value.
/// </return>
static std::optional<AssetID> GetAssetID(Handle<void> handle);
/// <summary>
/// Retrieves the name associated with the AssetID that is associated with the
/// specified Handle.
/// Compared to the templated version, this function is slower as it requires
/// searching through the storage of all resource types.
/// </summary>
/// <param name="handle">Handle to get the name of.</param>
/// <return>
/// Name for the specified Handle. If the Handle is invalid, there will be no
/// value.
/// </return>
static std::optional<std::string> GetAssetName(Handle<void> handle);
};
}

View File

@ -12,9 +12,12 @@
#include "Assets/Asset Types/SHSceneAsset.h"
#include "Camera/SHCameraComponent.h"
#include "Camera/SHCameraArmComponent.h"
#include "Math/Transform/SHTransformComponent.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Physics/Interface/SHRigidBodyComponent.h"
#include "UI/SHCanvasComponent.h"
#include "UI/SHButtonComponent.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
#include "Scripting/SHScriptEngine.h"
@ -207,10 +210,15 @@ namespace SHADE
AddComponentToComponentNode<SHTransformComponent>(components, eid);
AddComponentToComponentNode<SHCameraComponent>(components, eid);
AddComponentToComponentNode<SHCameraArmComponent>(components, eid);
AddConvComponentToComponentNode<SHRenderable>(components, eid);
AddComponentToComponentNode<SHLightComponent>(components, eid);
AddComponentToComponentNode<SHRigidBodyComponent>(components, eid);
AddConvComponentToComponentNode<SHColliderComponent>(components, eid);
AddComponentToComponentNode<SHCanvasComponent>(components, eid);
AddComponentToComponentNode<SHButtonComponent>(components, eid);
AddConvComponentToComponentNode<SHTextRenderableComponent>(components, eid);
node[ComponentsNode] = components;
@ -259,10 +267,14 @@ namespace SHADE
AddComponentID<SHTransformComponent>(componentIDList, componentsNode);
AddComponentID<SHCameraComponent>(componentIDList, componentsNode);
AddComponentID<SHCameraArmComponent>(componentIDList, componentsNode);
AddComponentID<SHRenderable>(componentIDList, componentsNode);
AddComponentID<SHRigidBodyComponent>(componentIDList, componentsNode);
AddComponentID<SHLightComponent>(componentIDList, componentsNode);
AddComponentID<SHColliderComponent>(componentIDList, componentsNode);
AddComponentID<SHCanvasComponent>(componentIDList, componentsNode);
AddComponentID<SHButtonComponent>(componentIDList, componentsNode);
AddComponentID<SHTextRenderableComponent>(componentIDList, componentsNode);
return componentIDList;
@ -337,9 +349,13 @@ namespace SHADE
return;
SHSerializationHelper::InitializeComponentFromNode<SHTransformComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHCameraComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHCameraArmComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHRigidBodyComponent>(componentsNode, eid);
SHSerializationHelper::ConvertNodeToComponent<SHRenderable>(componentsNode, eid);
SHSerializationHelper::ConvertNodeToComponent<SHColliderComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHCanvasComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHButtonComponent>(componentsNode, eid);
SHSerializationHelper::ConvertNodeToComponent<SHTextRenderableComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
}

View File

@ -188,7 +188,7 @@ namespace YAML
if (node[Friction].IsDefined())
rhs.SetFriction(node[Friction].as<float>());
if (node[Bounciness].IsDefined())
rhs.SetBounciness(rhs.GetBounciness());
rhs.SetBounciness(node[Bounciness].as<float>());
if (node[Density].IsDefined())
rhs.SetDensity(node[Density].as<float>());
if (node[PositionOffset].IsDefined())

View File

@ -0,0 +1,58 @@
#include "SHpch.h"
#include "SHButtonComponent.h"
namespace SHADE
{
SHButtonComponent::SHButtonComponent()
:size(1.0f), offset(0.0f), isHovered(false), isClicked(false),
defaultTexture(0), hoveredTexture(0), clickedTexture(0)
{
}
AssetID SHButtonComponent::GetDefaultTexture() const noexcept
{
return defaultTexture;
}
AssetID SHButtonComponent::GetHoveredTexture() const noexcept
{
return hoveredTexture;
}
AssetID SHButtonComponent::GetClickedTexture() const noexcept
{
return clickedTexture;
}
void SHButtonComponent::SetDefaultTexture(AssetID texture) noexcept
{
defaultTexture = texture;
}
void SHButtonComponent::SetHoveredTexture(AssetID texture) noexcept
{
hoveredTexture = texture;
}
void SHButtonComponent::SetClickedTexture(AssetID texture) noexcept
{
clickedTexture = texture;
}
}
RTTR_REGISTRATION
{
using namespace SHADE;
using namespace rttr;
registration::class_<SHButtonComponent>("Button Component")
.property("Default Texture", &SHButtonComponent::GetDefaultTexture, &SHButtonComponent::SetDefaultTexture)
.property("Hovered Texture", &SHButtonComponent::GetHoveredTexture, &SHButtonComponent::SetHoveredTexture)
.property("Clicked Texture", &SHButtonComponent::GetClickedTexture, &SHButtonComponent::SetClickedTexture)
;
}

View File

@ -0,0 +1,48 @@
#pragma once
#include <rttr/registration>
#include "SH_API.h"
#include "ECS_Base/Components/SHComponent.h"
#include "Math/Vector/SHVec3.h"
#include "Math/Vector/SHVec2.h"
#include "Assets/SHAssetMacros.h"
namespace SHADE
{
class SH_API SHButtonComponent final: public SHComponent
{
public:
SHButtonComponent();
virtual ~SHButtonComponent() = default;
SHVec2 size;
SHVec2 offset;
AssetID GetClickedTexture() const noexcept;
AssetID GetDefaultTexture() const noexcept;
AssetID GetHoveredTexture() const noexcept;
void SetDefaultTexture(AssetID texture) noexcept;
void SetHoveredTexture(AssetID texture) noexcept;
void SetClickedTexture(AssetID texture) noexcept;
friend class SHUISystem;
private:
bool isHovered;
bool isClicked;
AssetID defaultTexture;
AssetID hoveredTexture;
AssetID clickedTexture;
RTTR_ENABLE()
};
}

View File

@ -3,6 +3,13 @@
#include "ECS_Base/Managers/SHComponentManager.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Math/Transform/SHTransformComponent.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Camera/SHCameraSystem.h"
#include "Editor/EditorWindow/SHEditorWindowManager.h"
#include "Editor/EditorWindow/ViewportWindow/SHEditorViewport.h"
#include "Editor/SHEditor.h"
#include "Resource/SHResourceManager.h"
#include "Input/SHInputManager.h"
namespace SHADE
{
@ -12,6 +19,7 @@ namespace SHADE
SystemFamily::GetID<SHUISystem>();
SHComponentManager::CreateComponentSparseSet<SHCanvasComponent>();
SHComponentManager::CreateComponentSparseSet<SHUIComponent>();
SHComponentManager::CreateComponentSparseSet<SHButtonComponent>();
}
void SHUISystem::Exit()
@ -108,6 +116,109 @@ namespace SHADE
}
}
void SHUISystem::UpdateCanvasComponent(SHCanvasComponent& comp) noexcept
{
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
SHVec2 camSize = cameraSystem->GetCameraWidthHeight(0);
comp.canvasMatrix = SHMatrix::Identity;
comp.canvasMatrix(0, 0) = camSize.x * 0.5f / (comp.GetCanvasWidth() * 0.5f);
comp.canvasMatrix(1, 1) = camSize.y * 0.5f / (comp.GetCanvasHeight() * 0.5f);
}
void SHUISystem::UpdateCanvasMatrixRoutine::Execute(double dt) noexcept
{
SHUISystem* system = (SHUISystem*)GetSystem();
auto& dense = SHComponentManager::GetDense<SHCanvasComponent>();
for (auto& comp : dense)
{
if(SHSceneManager::CheckNodeAndComponentsActive<SHCanvasComponent>(comp.GetEID()))
system->UpdateCanvasComponent(comp);
}
}
void SHUISystem::UpdateButtonComponent(SHButtonComponent& comp) noexcept
{
if (!SHComponentManager::HasComponent<SHTransformComponent>(comp.GetEID()) || !SHComponentManager::HasComponent<SHUIComponent>(comp.GetEID()))
{
return;
}
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
auto uiComp = SHComponentManager::GetComponent<SHUIComponent>(comp.GetEID());
SHVec4 topExtent4 = uiComp->GetMatrix() * SHVec4(-comp.size.x * 0.5f, comp.size.y * 0.5f , 0.0f,1.0f);
SHVec4 btmExtent4 = uiComp->GetMatrix() * SHVec4(comp.size.x * 0.5f , -comp.size.y * 0.5f , 0.0f, 1.0f);
SHVec2 topExtent{ topExtent4.x,-topExtent4.y };
SHVec2 btmExtent{ btmExtent4.x,-btmExtent4.y };
SHVec2 windowSize;
SHVec2 mousePos;
#ifdef SHEDITOR
windowSize = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->windowSize;
mousePos = SHEditorWindowManager::GetEditorWindow<SHEditorViewport>()->viewportMousePos;
#endif
SHVec2 camSize{ cameraSystem->GetCameraWidthHeight(0).x , cameraSystem->GetCameraWidthHeight(0).y };
topExtent += camSize * 0.5f;
btmExtent += camSize * 0.5f;
//Convert everything to using ratios
topExtent /= camSize;
btmExtent /= camSize;
mousePos /= windowSize;
//SHLOG_INFO("mousePos: {} , {}", mousePos.x, mousePos.y);
comp.isClicked = false;
if (mousePos.x >= topExtent.x && mousePos.x <= btmExtent.x
&& mousePos.y >= topExtent.y && mousePos.y <= btmExtent.y)
{
comp.isHovered = true;
if (SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB))
{
comp.isClicked = true;
}
//SHLOG_INFO("BUTTON HOVERED");
}
else
{
comp.isHovered = false;
//SHLOG_INFO("BUTTON NOT HOVERED")
}
if (SHComponentManager::HasComponent<SHRenderable>(comp.GetEID()))
{
//auto renderable = SHComponentManager::GetComponent_s<SHRenderable>(comp.GetEID());
//auto texture = SHResourceManager::Get<SHTexture>(comp.GetDefaultTexture());
//auto material = renderable->GetModifiableMaterial();
//material->SetProperty("texture", comp.GetDefaultTexture());
}
}
void SHUISystem::UpdateButtonsRoutine::Execute(double dt) noexcept
{
SHUISystem* system = (SHUISystem*)GetSystem();
auto& dense = SHComponentManager::GetDense<SHButtonComponent>();
for (auto& comp : dense)
{
if (SHSceneManager::CheckNodeAndComponentsActive<SHButtonComponent>(comp.GetEID()))
system->UpdateButtonComponent(comp);
}
}
}//end namespace

View File

@ -4,6 +4,7 @@
#include "ECS_Base/System/SHSystem.h"
#include "ECS_Base/System/SHSystemRoutine.h"
#include "SHUIComponent.h"
#include "SHButtonComponent.h"
#include "SHCanvasComponent.h"
#include "Scene/SHSceneGraph.h"
#include "Scene/SHSceneManager.h"
@ -38,6 +39,23 @@ namespace SHADE
};
friend class UpdateUIMatrixRoutine;
class SH_API UpdateCanvasMatrixRoutine final: public SHSystemRoutine
{
public:
UpdateCanvasMatrixRoutine() :SHSystemRoutine("Update Canvas Matrix Routine", true) {};
virtual void Execute(double dt) noexcept override final;
};
friend class UpdateCanvasMatrixRoutine;
class SH_API UpdateButtonsRoutine final: public SHSystemRoutine
{
public:
UpdateButtonsRoutine() : SHSystemRoutine("Update Buttons Routine", true) {};
virtual void Execute(double dt) noexcept override final;
};
friend class UpdateButtonsRoutine;
void Init();
void Exit();
@ -45,8 +63,8 @@ namespace SHADE
private:
void UpdateUIComponent(SHUIComponent& comp) noexcept;
void UpdateButtonComponent(SHButtonComponent& comp) noexcept;
void UpdateCanvasComponent(SHCanvasComponent& comp) noexcept;
};

View File

@ -119,14 +119,14 @@ project "SHADE_Managed"
links{"librttr_core.lib"}
links{"fmodstudio_vc.lib", "fmod_vc.lib"}
require "vstudio"
-- require "vstudio"
function docsElementCPP(cfg)
_p(3,'<GenerateXMLDocumentationFiles>true</GenerateXMLDocumentationFiles>')
end
-- function docsElementCPP(cfg)
-- _p(3,'<GenerateXMLDocumentationFiles>true</GenerateXMLDocumentationFiles>')
-- end
premake.override(premake.vstudio.vc2010.elements, "clCompile", function (oldfn, cfg)
return table.join(oldfn(cfg), {
docsElementCPP,
})
end)
-- premake.override(premake.vstudio.vc2010.elements, "clCompile", function (oldfn, cfg)
-- return table.join(oldfn(cfg), {
-- docsElementCPP,
-- })
-- end)

View File

@ -1,32 +0,0 @@
/************************************************************************************//*!
\file Font.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the implementation of the functions of the managed Font class.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "Font.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Explicit Template Instantiation */
/*---------------------------------------------------------------------------------*/
template ref class NativeAsset<SHFont>;
/*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/
Font::Font(Handle<SHFont> font)
: NativeAsset<SHFont> { font }
{}
}

View File

@ -1,41 +0,0 @@
/************************************************************************************//*!
\file Font.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of the managed Font class.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// External Dependencies
#include "Resource/SHHandle.h"
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
// Project Includes
#include "NativeAsset.hxx"
#include "Engine/GenericHandle.hxx"
namespace SHADE
{
/// <summary>
/// Managed counterpart of the native Font object that can be fed to TextRenderables
/// for rendering.
/// </summary>
public ref class Font : public NativeAsset<SHFont>
{
internal:
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor for the Font.
/// </summary>
/// <param name="font">Handle to the font object.</param>
Font(Handle<SHFont> font);
};
}

View File

@ -0,0 +1,69 @@
/************************************************************************************//*!
\file Font.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the implementation of the functions of the managed Font class.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "FontAsset.hxx"
// External Dependencies
#include "Resource/SHResourceManagerInterface.h"
// Project Headers
#include "Utility/Convert.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
Handle<SHFont> FontAsset::NativeObject::get()
try
{
return SHResourceManagerInterface::LoadOrGetFont(asset.NativeAssetID);
}
catch (const BadHandleCastException&)
{
return Handle<SHFont>();
}
AssetID FontAsset::NativeAssetID::get()
{
return asset.NativeAssetID;
}
/*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/
FontAsset::FontAsset(AssetID fontId)
: asset { fontId }
{}
/*---------------------------------------------------------------------------------*/
/* Operator Overloads */
/*---------------------------------------------------------------------------------*/
FontAsset::operator bool(FontAsset asset)
{
return asset.asset;
}
/*---------------------------------------------------------------------------------*/
/* Conversion Operators */
/*---------------------------------------------------------------------------------*/
FontAsset::operator Asset(FontAsset nativeAsset)
{
return nativeAsset.asset;
}
FontAsset::operator FontAsset(Asset asset)
{
return FontAsset(asset.NativeAssetID);
}
}

View File

@ -0,0 +1,89 @@
/************************************************************************************//*!
\file Font.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of the managed Font class.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// External Dependencies
#include "Resource/SHHandle.h"
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
// Project Includes
#include "NativeAsset.hxx"
#include "Engine/GenericHandle.hxx"
namespace SHADE
{
/// <summary>
/// Managed counterpart of the native Font object that can be fed to TextRenderables
/// for rendering.
/// </summary>
public value struct FontAsset
{
internal:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Copy of the Handle to the native object.
/// </summary>
property Handle<SHFont> NativeObject
{
Handle<SHFont> get();
}
/// <summary>
/// The raw asset ID of the asset.
/// </summary>
property AssetID NativeAssetID
{
AssetID get();
}
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor for the Font.
/// </summary>
/// <param name="fontId">AssetID to the font asset.</param>
FontAsset(AssetID fontId);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Font is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(FontAsset asset);
/*-----------------------------------------------------------------------------*/
/* Conversion Operators */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Conversion operator to enable casting from a Font to an Asset.
/// </summary>
/// <param name="vec">Vector3 to convert from.</param>
static explicit operator Asset(FontAsset nativeAsset);
/// <summary>
/// Conversion operator to enable casting from a Asset to a Font.
/// </summary>
/// <param name="asset"></param>
static explicit operator FontAsset(Asset asset);
protected:
/*-----------------------------------------------------------------------------*/
/* Data Members */
/*-----------------------------------------------------------------------------*/
Asset asset;
};
}

View File

@ -0,0 +1,70 @@
/************************************************************************************//*!
\file MaterialAsset.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 22, 2022
\brief Contains the implementation of the functions of the managed Material
struct.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "MaterialAsset.hxx"
// External Dependencies
#include "Resource/SHResourceManagerInterface.h"
// Project Headers
#include "Utility/Convert.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
Handle<SHMaterial> MaterialAsset::NativeObject::get()
try
{
return SHResourceManagerInterface::LoadOrGetMaterial(asset.NativeAssetID);
}
catch (const BadHandleCastException&)
{
return Handle<SHMaterial>();
}
AssetID MaterialAsset::NativeAssetID::get()
{
return asset.NativeAssetID;
}
/*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/
MaterialAsset::MaterialAsset(AssetID MaterialId)
: asset { MaterialId }
{}
/*---------------------------------------------------------------------------------*/
/* Operator Overloads */
/*---------------------------------------------------------------------------------*/
MaterialAsset::operator bool(MaterialAsset asset)
{
return asset.asset;
}
/*---------------------------------------------------------------------------------*/
/* Conversion Operators */
/*---------------------------------------------------------------------------------*/
MaterialAsset::operator Asset(MaterialAsset nativeAsset)
{
return nativeAsset.asset;
}
MaterialAsset::operator MaterialAsset(Asset asset)
{
return MaterialAsset(asset.NativeAssetID);
}
}

View File

@ -0,0 +1,89 @@
/************************************************************************************//*!
\file MaterialAsset.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 22, 2022
\brief Contains the definition of the managed MaterialAsset struct.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// External Dependencies
#include "Resource/SHHandle.h"
#include "Graphics/MiddleEnd/Interface/SHMaterial.h"
// Project Includes
#include "NativeAsset.hxx"
#include "Engine/GenericHandle.hxx"
namespace SHADE
{
/// <summary>
/// Managed counterpart of the native Material object that can be fed to TextRenderables
/// for rendering.
/// </summary>
public value struct MaterialAsset
{
internal:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Copy of the Handle to the native object.
/// </summary>
property Handle<SHMaterial> NativeObject
{
Handle<SHMaterial> get();
}
/// <summary>
/// The raw asset ID of the asset.
/// </summary>
property AssetID NativeAssetID
{
AssetID get();
}
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor for the Material.
/// </summary>
/// <param name="MaterialId">AssetID to the Material asset.</param>
MaterialAsset(AssetID MaterialId);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Material is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(MaterialAsset asset);
/*-----------------------------------------------------------------------------*/
/* Conversion Operators */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Conversion operator to enable casting from a Material to an Asset.
/// </summary>
/// <param name="vec">Vector3 to convert from.</param>
static explicit operator Asset(MaterialAsset nativeAsset);
/// <summary>
/// Conversion operator to enable casting from a Asset to a Material.
/// </summary>
/// <param name="asset"></param>
static explicit operator MaterialAsset(Asset asset);
protected:
/*-----------------------------------------------------------------------------*/
/* Data Members */
/*-----------------------------------------------------------------------------*/
Asset asset;
};
}

View File

@ -1,34 +0,0 @@
/************************************************************************************//*!
\file Mesh.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the implementation of the functions of the managed Mesh class.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "Mesh.hxx"
// Project Headers
#include "Utility/Convert.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Explicit Template Instantiation */
/*---------------------------------------------------------------------------------*/
template ref class NativeAsset<SHMesh>;
/*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/
Mesh::Mesh(Handle<SHMesh> mesh)
: NativeAsset<SHMesh> { mesh }
{}
}

View File

@ -1,41 +0,0 @@
/************************************************************************************//*!
\file Mesh.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of the managed Mesh class.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// External Dependencies
#include "Resource/SHHandle.h"
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
// Project Includes
#include "NativeAsset.hxx"
#include "Engine/GenericHandle.hxx"
namespace SHADE
{
/// <summary>
/// Managed counterpart of the native Mesh object containing vertex data that can
/// be fed to Renderables for rendering.
/// </summary>
public ref class Mesh : public NativeAsset<SHMesh>
{
internal:
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor for the Mesh
/// </summary>
/// <param name="mesh">Handle to the mesh object.</param>
Mesh(Handle<SHMesh> mesh);
};
}

View File

@ -0,0 +1,69 @@
/************************************************************************************//*!
\file Mesh.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the implementation of the functions of the managed Mesh class.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
#include "MeshAsset.hxx"
// External Dependencies
#include "Resource/SHResourceManagerInterface.h"
// Project Headers
#include "Utility/Convert.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
Handle<SHMesh> MeshAsset::NativeObject::get()
try
{
return SHResourceManagerInterface::LoadOrGetMesh(asset.NativeAssetID);
}
catch (const BadHandleCastException&)
{
return Handle<SHMesh>();
}
AssetID MeshAsset::NativeAssetID::get()
{
return asset.NativeAssetID;
}
/*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/
MeshAsset::MeshAsset(AssetID meshId)
: asset{ meshId }
{}
/*---------------------------------------------------------------------------------*/
/* Operator Overloads */
/*---------------------------------------------------------------------------------*/
MeshAsset::operator bool(MeshAsset asset)
{
return asset.asset;
}
/*---------------------------------------------------------------------------------*/
/* Conversion Operators */
/*---------------------------------------------------------------------------------*/
MeshAsset::operator Asset(MeshAsset nativeAsset)
{
return nativeAsset.asset;
}
MeshAsset::operator MeshAsset(Asset asset)
{
return MeshAsset(asset.NativeAssetID);
}
}

View File

@ -0,0 +1,89 @@
/************************************************************************************//*!
\file Mesh.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of the managed Mesh class.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// External Dependencies
#include "Resource/SHHandle.h"
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
// Project Includes
#include "NativeAsset.hxx"
#include "Engine/GenericHandle.hxx"
namespace SHADE
{
/// <summary>
/// Managed counterpart of the native Mesh object containing vertex data that can
/// be fed to Renderables for rendering.
/// </summary>
public value struct MeshAsset
{
internal:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Copy of the Handle to the native object.
/// </summary>
property Handle<SHMesh> NativeObject
{
Handle<SHMesh> get();
}
/// <summary>
/// The raw asset ID of the asset.
/// </summary>
property AssetID NativeAssetID
{
AssetID get();
}
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor for the Mesh.
/// </summary>
/// <param name="meshId">AssetID to the Mesh asset.</param>
MeshAsset(AssetID meshId);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Mesh is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(MeshAsset asset);
/*-----------------------------------------------------------------------------*/
/* Conversion Operators */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Conversion operator to enable casting from a Mesh to an Asset.
/// </summary>
/// <param name="vec">Vector3 to convert from.</param>
static explicit operator Asset(MeshAsset nativeAsset);
/// <summary>
/// Conversion operator to enable casting from a Asset to a Mesh.
/// </summary>
/// <param name="asset"></param>
static explicit operator MeshAsset(Asset asset);
protected:
/*-----------------------------------------------------------------------------*/
/* Data Members */
/*-----------------------------------------------------------------------------*/
Asset asset;
};
}

View File

@ -17,21 +17,30 @@ of DigiPen Institute of Technology is prohibited.
#include "NativeAsset.hxx"
// Project Includes
#include "Engine/GenericHandle.hxx"
#include "Utility/Convert.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
GenericHandle Asset::NativeObjectHandle::get()
AssetID Asset::NativeAssetID::get()
{
return nativeObjHandle;
return assetId;
}
/*---------------------------------------------------------------------------------*/
/* Constructors */
/*---------------------------------------------------------------------------------*/
Asset::Asset(Handle<void> nativeHandle)
: nativeObjHandle { Convert::ToCLI(Handle<void>(nativeHandle)) }
Asset::Asset(AssetID id)
: assetId { id }
{}
/*---------------------------------------------------------------------------------*/
/* Operator Overloads */
/*---------------------------------------------------------------------------------*/
Asset::operator bool(Asset asset)
{
return asset.NativeAssetID != INVALID_ASSET_ID;
}
}

View File

@ -1,44 +0,0 @@
/************************************************************************************//*!
\file NativeAsset.h++
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2022
\brief Contains the definition of templated functions for the managed
NativeAsset classes.
Note: This file is written in C++17/CLI.
Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// Primary Include
#include "NativeAsset.hxx"
#include "Utility/Convert.hxx"
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
template <typename NativeAssetType>
Handle<NativeAssetType> NativeAsset<NativeAssetType>::NativeObject::get()
try
{
return Handle<NativeAssetType>(Convert::ToNative(nativeObjHandle));
}
catch (const BadHandleCastException&)
{
return Handle<NativeAssetType>(); // Null handle
}
/*---------------------------------------------------------------------------------*/
/* Constructors */
/*---------------------------------------------------------------------------------*/
template <typename NativeAssetType>
NativeAsset<NativeAssetType>::NativeAsset(Handle<NativeAssetType> nativeObj)
: Asset { Handle<void>(nativeObj) }
{}
}

View File

@ -14,25 +14,28 @@ of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// External Dependencies
#include "Assets/SHAssetMacros.h"
// Project Includes
#include "Engine/GenericHandle.hxx"
namespace SHADE
{
/// <summary>
/// Abstract base class that all Native Assets will inherit from.
/// Struct that contains native asset information.
/// </summary>
public ref class Asset abstract
public value struct Asset
{
internal:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Generic handle for the native object
/// The raw asset ID of the asset.
/// </summary>
property GenericHandle NativeObjectHandle
property AssetID NativeAssetID
{
GenericHandle get();
AssetID get();
}
/*-----------------------------------------------------------------------------*/
@ -41,46 +44,23 @@ namespace SHADE
/// <summary>
/// Constructor for the asset.
/// </summary>
/// <param name="ptr">Native asset object handle.</param>
Asset(Handle<void> nativeHandle);
/// <param name="id">Native asset ID to construct this asset from.</param>
explicit Asset(AssetID id);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Asset is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(Asset asset);
protected:
/*-----------------------------------------------------------------------------*/
/* Data Members */
/*-----------------------------------------------------------------------------*/
GenericHandle nativeObjHandle;
};
/// <summary>
/// Generalised template class for a managed representation of a native asset
/// </summary>
/// <typeparam name="NativeAssetType">
/// The type of the asset's native representation.
/// </typeparam>
template<typename NativeAssetType>
public ref class NativeAsset abstract : Asset
{
internal:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Copy of the Handle to the native object.
/// </summary>
property Handle<NativeAssetType> NativeObject
{
Handle<NativeAssetType> get();
}
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor for the native asset
/// </summary>
/// <param name="ptr">Native asset object handle.</param>
NativeAsset(Handle<NativeAssetType> ptr);
AssetID assetId;
};
}
#include "NativeAsset.h++"

View File

@ -30,11 +30,11 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
SHADE::Mesh^ Renderable::Mesh::get()
SHADE::MeshAsset^ Renderable::Mesh::get()
{
return gcnew SHADE::Mesh(GetNativeComponent()->GetMesh());
return gcnew SHADE::MeshAsset(GetNativeComponent()->GetMesh());
}
void Renderable::Mesh::set(SHADE::Mesh^ value)
void Renderable::Mesh::set(SHADE::MeshAsset^ value)
{
if (value == nullptr)
{
@ -42,7 +42,7 @@ namespace SHADE
}
else
{
GetNativeComponent()->SetMesh(Handle<SHMesh>(Convert::ToNative(value->NativeObjectHandle)));
GetNativeComponent()->SetMesh(value->NativeObject);
}
}
SHADE::Material^ Renderable::Material::get()
@ -64,4 +64,12 @@ namespace SHADE
{
return GetNativeComponent()->GetLightLayer();
}
/*---------------------------------------------------------------------------------*/
/* Properties */
/*---------------------------------------------------------------------------------*/
void Renderable::SetMaterial(MaterialAsset materialAsset)
{
GetNativeComponent()->SetMaterial(materialAsset.NativeObject);
}
}

View File

@ -20,8 +20,9 @@ of DigiPen Institute of Technology is prohibited.
#include "Math/Quaternion.hxx"
// External Dependencies
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Assets/Mesh.hxx"
#include "Assets/Material.hxx"
#include "Assets/MeshAsset.hxx"
#include "Graphics/Material.hxx"
#include "Assets/MaterialAsset.hxx"
namespace SHADE
{
@ -48,10 +49,10 @@ namespace SHADE
/// <summary>
/// Mesh used to render this Renderable.
/// </summary>
property SHADE::Mesh^ Mesh
property SHADE::MeshAsset^ Mesh
{
SHADE::Mesh^ get();
void set(SHADE::Mesh^ value);
SHADE::MeshAsset^ get();
void set(SHADE::MeshAsset^ value);
}
/// <summary>
/// Material used to render this Renderable.
@ -68,6 +69,16 @@ namespace SHADE
{
System::Byte get();
}
/*-----------------------------------------------------------------------------*/
/* Usage functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Sets the Material used by this Renderable to be an instance of the specified
/// base MaterialAsset.
/// </summary>
/// <param name="asset">Material to set.</param>
void SetMaterial(MaterialAsset materialAsset);
};
}

View File

@ -39,11 +39,11 @@ namespace SHADE
{
GetNativeComponent()->SetText(Convert::ToNative(value));
}
SHADE::Font^ TextRenderable::Font::get()
SHADE::FontAsset^ TextRenderable::Font::get()
{
return gcnew SHADE::Font(GetNativeComponent()->GetFont());
return gcnew SHADE::FontAsset(GetNativeComponent()->GetFont());
}
void TextRenderable::Font::set(SHADE::Font^ value)
void TextRenderable::Font::set(SHADE::FontAsset^ value)
{
if (value == nullptr)
{
@ -51,7 +51,7 @@ namespace SHADE
}
else
{
GetNativeComponent()->SetFont(Handle<SHFont>(Convert::ToNative(value->NativeObjectHandle)));
GetNativeComponent()->SetFont(value->NativeObject);
}
}
}

View File

@ -20,7 +20,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Components/Component.hxx"
#include "Math/Vector3.hxx"
#include "Math/Quaternion.hxx"
#include "Assets/Font.hxx"
#include "Assets/FontAsset.hxx"
namespace SHADE
{
@ -55,10 +55,10 @@ namespace SHADE
/// <summary>
/// Font to use to render using this TextRenderable.
/// </summary>
property SHADE::Font^ Font
property SHADE::FontAsset^ Font
{
SHADE::Font^ get();
void set(SHADE::Font^ value);
SHADE::FontAsset^ get();
void set(SHADE::FontAsset^ value);
}
};
}

View File

@ -176,7 +176,10 @@ namespace SHADE
renderSpecificField<SHVec3 , Vector3 >(field, object, SHEditorUI::InputVec3 , &isHovered) ||
renderSpecificField<uint32_t , GameObject >(field, object, nullptr , &isHovered) ||
renderSpecificField<std::string, System::String^>(field, object, nullptr , &isHovered) ||
renderSpecificField<int , System::Enum >(field, object, nullptr , &isHovered);
renderSpecificField<int , System::Enum >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , FontAsset >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , MeshAsset >(field, object, nullptr , &isHovered) ||
renderSpecificField<AssetID , MaterialAsset >(field, object, nullptr , &isHovered);
if (!MODIFIED_PRIMITIVE)
{
@ -319,7 +322,10 @@ namespace SHADE
renderFieldEditor<SHVec3 , Vector3 >(fieldName, object, SHEditorUI::InputVec3 , nullptr, rangeAttrib, modified) ||
renderFieldEditor<uint32_t , GameObject >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<std::string, System::String^>(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<int , System::Enum >(fieldName, object, nullptr , nullptr, rangeAttrib, modified);
renderFieldEditor<int , System::Enum >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , FontAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , MeshAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified) ||
renderFieldEditor<AssetID , MaterialAsset >(fieldName, object, nullptr , nullptr, rangeAttrib, modified);
return modified;
}

View File

@ -20,6 +20,9 @@ of DigiPen Institute of Technology is prohibited.
#include "Editor/SHEditorUI.h"
// Project Includes
#include "Utility/Convert.hxx"
#include "Assets/FontAsset.hxx"
#include "Assets/MeshAsset.hxx"
#include "Assets/MaterialAsset.hxx"
namespace SHADE
{
@ -198,6 +201,42 @@ namespace SHADE
return true;
}
return false;
}
template<>
bool Editor::renderFieldEditorInternal<AssetID, FontAsset>(const std::string& fieldName, interior_ptr<FontAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
{
uint32_t assetId = managedValPtr->NativeAssetID;
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::FONT, isHovered))
{
*managedValPtr = FontAsset(assetId);
return true;
}
return false;
}
template<>
bool Editor::renderFieldEditorInternal<AssetID, MeshAsset>(const std::string& fieldName, interior_ptr<MeshAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
{
uint32_t assetId = managedValPtr->NativeAssetID;
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MESH, isHovered))
{
*managedValPtr = MeshAsset(assetId);
return true;
}
return false;
}
template<>
bool Editor::renderFieldEditorInternal<AssetID, MaterialAsset>(const std::string& fieldName, interior_ptr<MaterialAsset> managedValPtr, EditorFieldFunc<uint32_t>, bool* isHovered, RangeAttribute^)
{
uint32_t assetId = managedValPtr->NativeAssetID;
if (SHEditorUI::InputAssetField(fieldName, assetId, AssetType::MATERIAL, isHovered))
{
*managedValPtr = MaterialAsset(assetId);
return true;
}
return false;
}
}

View File

@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited.
#include <stdexcept>
// Project Includes
#include "Utility/Convert.hxx"
#include "Resource/SHResourceManagerInterface.h"
namespace SHADE
{
@ -53,15 +54,31 @@ namespace SHADE
}
/*---------------------------------------------------------------------------------*/
/* Explicit Template Instantiation */
/* Properties */
/*---------------------------------------------------------------------------------*/
template ref class NativeAsset<SHMaterialInstance>;
Handle<SHMaterialInstance> Material::NativeObject::get()
try
{
return Handle<SHMaterialInstance>(Convert::ToNative(matInstHandle));
}
catch (const BadHandleCastException&)
{
return Handle<SHMaterialInstance>();
}
GenericHandle Material::NativeObjectHandle::get()
{
return matInstHandle;
}
AssetID Material::NativeAssetID::get()
{
return SHResourceManagerInterface::GetAssetID(Convert::ToNative(matInstHandle)).value_or(INVALID_ASSET_ID);
}
/*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/
Material::Material(Handle<SHMaterialInstance> material)
: NativeAsset<SHMaterialInstance>{ material }
: matInstHandle{ Handle<void>(material) }
{}
/*---------------------------------------------------------------------------------*/
@ -116,4 +133,12 @@ namespace SHADE
throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material.");
}
/*---------------------------------------------------------------------------------*/
/* Operator Overloads */
/*---------------------------------------------------------------------------------*/
Material::operator bool(Material materialInstance)
{
return materialInstance;
}
}

View File

@ -16,8 +16,8 @@ of DigiPen Institute of Technology is prohibited.
// External Dependencies
#include "Resource/SHHandle.h"
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
#include "Assets/SHAssetMacros.h"
// Project Includes
#include "NativeAsset.hxx"
#include "Engine/GenericHandle.hxx"
namespace SHADE
@ -26,9 +26,34 @@ namespace SHADE
/// Managed counterpart of the native MaterialInstance object containing material
/// data that can be fed to Renderables for rendering.
/// </summary>
public ref class Material : public NativeAsset<SHMaterialInstance>
public value struct Material
{
internal:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Copy of the Handle to the native object.
/// </summary>
property Handle<SHMaterialInstance> NativeObject
{
Handle<SHMaterialInstance> get();
}
/// <summary>
/// Generic handle for the native object
/// </summary>
property GenericHandle NativeObjectHandle
{
GenericHandle get();
}
/// <summary>
/// The raw asset ID of the asset.
/// </summary>
property AssetID NativeAssetID
{
AssetID get();
}
/*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/
@ -77,5 +102,21 @@ namespace SHADE
/// </exception>
generic<typename T>
T GetProperty(System::String^ name);
/*-----------------------------------------------------------------------------*/
/* Operator Overloads */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Implicit conversion operator to enable checking if a Material is valid.
/// </summary>
/// <param name="gameObj">Asset to check.</param>
/// <returns>True if the Asset is valid.</returns>
static operator bool(Material asset);
protected:
/*-----------------------------------------------------------------------------*/
/* Data Members */
/*-----------------------------------------------------------------------------*/
GenericHandle matInstHandle;
};
}

View File

@ -259,6 +259,14 @@ namespace SHADE
: OnGizmosDrawOverriden { false }
{}
/*---------------------------------------------------------------------------------*/
/* Manipulation Functions */
/*---------------------------------------------------------------------------------*/
void Script::SetEnabledWithoutEvents(bool enable)
{
enabled = enable;
}
/*---------------------------------------------------------------------------------*/
/* Virtual "All-Time" Lifecycle Functions */
/*---------------------------------------------------------------------------------*/

View File

@ -326,6 +326,15 @@ namespace SHADE
/// <param name="collision">Information on the collision event.</param>
void OnTriggerExit(CollisionInfo collision);
/*-----------------------------------------------------------------------------*/
/* Manipulation Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Function to set the enabled state of this script without triggering events.
/// </summary>
/// <param name="enable">Whether to enable or disable the script.</param>
void SetEnabledWithoutEvents(bool enable);
protected:
/*-----------------------------------------------------------------------------*/
/* Constructors */

View File

@ -744,7 +744,7 @@ namespace SHADE
for (YAML::Node& node : *yamlNode)
{
// Get the name of the script
if (!node["Type"])
if (!node["Type"].IsDefined())
{
Debug::LogWarning("[ScriptStore] Script with no type detected, skipping.");
continue;

View File

@ -18,11 +18,16 @@ of DigiPen Institute of Technology is prohibited.
#include "Serialisation/SerialisationUtilities.hxx"
// Project Includes
#include "ReflectionUtilities.hxx"
#include "Assets/FontAsset.hxx"
#include "Assets/MaterialAsset.hxx"
#include "Assets/MeshAsset.hxx"
#include "Scripts/Script.hxx"
/*-------------------------------------------------------------------------------------*/
/* File-Level Constants */
/*-------------------------------------------------------------------------------------*/
static const std::string_view SCRIPT_TYPE_YAMLTAG = "Type";
static const std::string_view SCRIPT_ENABLED_YAMLTAG = "Enabled";
/*-------------------------------------------------------------------------------------*/
/* Function Definitions */
@ -36,10 +41,19 @@ namespace SHADE
{
using namespace System::Reflection;
// Obtain script
Script^ script = safe_cast<Script^>(object);
if (script == nullptr)
{
Debug::LogWarning("[SerialisationUtilities] Attempted to serialise an object that is not a script!");
return;
}
// Create YAML object
YAML::Node scriptNode;
scriptNode.SetStyle(YAML::EmitterStyle::Block);
scriptNode[SCRIPT_TYPE_YAMLTAG.data()] = Convert::ToNative(object->GetType()->FullName);
scriptNode[SCRIPT_ENABLED_YAMLTAG.data()] = script->Enabled;
// Get all fields
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
@ -69,7 +83,7 @@ namespace SHADE
{
using namespace System::Reflection;
// Load the YAML
// Error Checking
if (!yamlNode.IsMap())
{
// Invalid
@ -80,6 +94,21 @@ namespace SHADE
);
return;
}
// Get the script
Script^ script = safe_cast<Script^>(object);
if (script == nullptr)
{
Debug::LogWarning("[SerialisationUtilities] Attempted to deserialise an object that is not a script!");
return;
}
// Set enabled state
if (yamlNode[SCRIPT_ENABLED_YAMLTAG.data()].IsDefined())
{
script->SetEnabledWithoutEvents(yamlNode[SCRIPT_ENABLED_YAMLTAG.data()].as<bool>());
}
// Get all fields
System::Collections::Generic::IEnumerable<FieldInfo^>^ fields = ReflectionUtilities::GetInstanceFields(object);
for each (FieldInfo^ field in fields)
@ -92,7 +121,7 @@ namespace SHADE
// Deserialise
const std::string FIELD_NAME = Convert::ToNative(field->Name);
if (yamlNode[FIELD_NAME])
if (yamlNode[FIELD_NAME].IsDefined())
{
writeYamlIntoField(field, object, yamlNode[FIELD_NAME]);
}
@ -129,7 +158,10 @@ namespace SHADE
fieldInsertYaml<System::String>(fieldInfo, object, fieldNode) ||
fieldInsertYaml<Vector2 >(fieldInfo, object, fieldNode) ||
fieldInsertYaml<Vector3 >(fieldInfo, object, fieldNode) ||
fieldInsertYaml<GameObject >(fieldInfo, object, fieldNode);
fieldInsertYaml<GameObject >(fieldInfo, object, fieldNode) ||
fieldInsertYaml<FontAsset >(fieldInfo, object, fieldNode) ||
fieldInsertYaml<MaterialAsset >(fieldInfo, object, fieldNode) ||
fieldInsertYaml<MeshAsset >(fieldInfo, object, fieldNode);
// Serialization of more complex types
if (!PRIMITIVE_SERIALIZED)
@ -190,7 +222,10 @@ namespace SHADE
varInsertYamlInternal<System::String>(object, fieldNode) ||
varInsertYamlInternal<Vector2 >(object, fieldNode) ||
varInsertYamlInternal<Vector3 >(object, fieldNode) ||
varInsertYamlInternal<GameObject >(object, fieldNode);
varInsertYamlInternal<GameObject >(object, fieldNode) ||
varInsertYamlInternal<FontAsset >(object, fieldNode) ||
varInsertYamlInternal<MaterialAsset >(object, fieldNode) ||
varInsertYamlInternal<MeshAsset >(object, fieldNode);
return INSERTED;
}
@ -214,7 +249,10 @@ namespace SHADE
fieldAssignYaml<System::String>(fieldInfo, object, node) ||
fieldAssignYaml<Vector2> (fieldInfo, object, node) ||
fieldAssignYaml<Vector3> (fieldInfo, object, node) ||
fieldAssignYaml<GameObject> (fieldInfo, object, node);
fieldAssignYaml<GameObject> (fieldInfo, object, node) ||
fieldAssignYaml<FontAsset> (fieldInfo, object, node) ||
fieldAssignYaml<MaterialAsset> (fieldInfo, object, node) ||
fieldAssignYaml<MeshAsset> (fieldInfo, object, node);
if (!ASSIGNED)
{
if (ReflectionUtilities::FieldIsList(fieldInfo))
@ -277,7 +315,10 @@ namespace SHADE
varAssignYamlInternal<System::String>(object, node) ||
varAssignYamlInternal<Vector2> (object, node) ||
varAssignYamlInternal<Vector3> (object, node) ||
varAssignYamlInternal<GameObject> (object, node);
varAssignYamlInternal<GameObject> (object, node) ||
varAssignYamlInternal<FontAsset> (object, node) ||
varAssignYamlInternal<MaterialAsset> (object, node) ||
varAssignYamlInternal<MeshAsset> (object, node);
return DESERIALISED;
}
}

View File

@ -60,6 +60,12 @@ namespace SHADE
{
fieldNode = MAX_EID;
}
else if constexpr (std::is_same_v<FieldType, FontAsset> ||
std::is_same_v<FieldType, MaterialAsset> ||
std::is_same_v<FieldType, MeshAsset>)
{
fieldNode = INVALID_ASSET_ID;
}
else
{
fieldNode = FieldType();
@ -122,6 +128,17 @@ namespace SHADE
return true;
}
}
else if constexpr (std::is_same_v<FieldType, FontAsset> ||
std::is_same_v<FieldType, MaterialAsset> ||
std::is_same_v<FieldType, MeshAsset>)
{
if (object->GetType() == FieldType::typeid)
{
FieldType asset = safe_cast<FieldType>(object);
fieldNode = asset.NativeAssetID;
return true;
}
}
else
{
if (object->GetType() == FieldType::typeid)
@ -229,6 +246,16 @@ namespace SHADE
const uint32_t EID = node.as<uint32_t>();
object = (EID == MAX_EID ? GameObject() : GameObject(EID));
}
else if constexpr (std::is_same_v<FieldType, FontAsset> ||
std::is_same_v<FieldType, MaterialAsset> ||
std::is_same_v<FieldType, MeshAsset>)
{
if (object->GetType() == FieldType::typeid)
{
object = FieldType(node.as<AssetID>());
return true;
}
}
else
{
object = node.as<CastType>();