Added C# Assets System and Serialization of Script Enabled State #247
|
@ -76,6 +76,12 @@ namespace SHADE
|
||||||
sharedMaterial = materialInstance;
|
sharedMaterial = materialInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHRenderable::SetMaterial(Handle<SHMaterial> material)
|
||||||
|
{
|
||||||
|
SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
|
||||||
|
SetMaterial(gfxSystem->AddOrGetBaseMaterialInstance(material));
|
||||||
|
}
|
||||||
|
|
||||||
Handle<SHMaterialInstance> SHRenderable::GetMaterial() const
|
Handle<SHMaterialInstance> SHRenderable::GetMaterial() const
|
||||||
{
|
{
|
||||||
if (material)
|
if (material)
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace SHADE
|
||||||
/*-------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------*/
|
||||||
/* Material Functions */
|
/* Material Functions */
|
||||||
/*-------------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------------*/
|
||||||
|
void SetMaterial(Handle<SHMaterial> material);
|
||||||
void SetMaterial(Handle<SHMaterialInstance> materialInstance);
|
void SetMaterial(Handle<SHMaterialInstance> materialInstance);
|
||||||
Handle<SHMaterialInstance> GetMaterial() const;
|
Handle<SHMaterialInstance> GetMaterial() const;
|
||||||
Handle<SHMaterialInstance> GetModifiableMaterial();
|
Handle<SHMaterialInstance> GetModifiableMaterial();
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Conversion Operators */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
MaterialAsset::operator Asset(MaterialAsset nativeAsset)
|
||||||
|
{
|
||||||
|
return nativeAsset.asset;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialAsset::operator MaterialAsset(Asset asset)
|
||||||
|
{
|
||||||
|
return MaterialAsset(asset.NativeAssetID);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetNativeComponent()->SetMesh(Handle<SHMesh>(Convert::ToNative(value->NativeObjectHandle)));
|
GetNativeComponent()->SetMesh(value->NativeObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SHADE::Material^ Renderable::Material::get()
|
SHADE::Material^ Renderable::Material::get()
|
||||||
|
@ -64,4 +64,12 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
return GetNativeComponent()->GetLightLayer();
|
return GetNativeComponent()->GetLightLayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void Renderable::SetMaterial(MaterialAsset materialAsset)
|
||||||
|
{
|
||||||
|
GetNativeComponent()->SetMaterial(materialAsset.NativeObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// External Dependencies
|
// External Dependencies
|
||||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||||
#include "Assets/MeshAsset.hxx"
|
#include "Assets/MeshAsset.hxx"
|
||||||
#include "Assets/Material.hxx"
|
#include "Graphics/Material.hxx"
|
||||||
|
#include "Assets/MaterialAsset.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -68,6 +69,16 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
System::Byte get();
|
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetNativeComponent()->SetFont(Handle<SHFont>(Convert::ToNative(value->NativeObjectHandle)));
|
GetNativeComponent()->SetFont(value->NativeObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Utility/Convert.hxx"
|
#include "Utility/Convert.hxx"
|
||||||
|
#include "Resource/SHResourceManagerInterface.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -58,7 +59,7 @@ namespace SHADE
|
||||||
Handle<SHMaterialInstance> Material::NativeObject::get()
|
Handle<SHMaterialInstance> Material::NativeObject::get()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Handle<SHMaterialInstance>(Convert::ToNative(asset.NativeObjectHandle));
|
return Handle<SHMaterialInstance>(Convert::ToNative(matInstHandle));
|
||||||
}
|
}
|
||||||
catch (const BadHandleCastException&)
|
catch (const BadHandleCastException&)
|
||||||
{
|
{
|
||||||
|
@ -66,18 +67,18 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
GenericHandle Material::NativeObjectHandle::get()
|
GenericHandle Material::NativeObjectHandle::get()
|
||||||
{
|
{
|
||||||
return asset.NativeObjectHandle;
|
return matInstHandle;
|
||||||
}
|
}
|
||||||
AssetID Material::NativeAssetID::get()
|
AssetID Material::NativeAssetID::get()
|
||||||
{
|
{
|
||||||
return asset.NativeAssetID;
|
return SHResourceManagerInterface::GetAssetID(Convert::ToNative(matInstHandle)).value_or(INVALID_ASSET_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Constructors/Destructor */
|
/* Constructors/Destructor */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
Material::Material(Handle<SHMaterialInstance> material)
|
Material::Material(Handle<SHMaterialInstance> material)
|
||||||
: asset { Handle<void>(material) }
|
: matInstHandle{ Handle<void>(material) }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -136,21 +137,8 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Operator Overloads */
|
/* Operator Overloads */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
Material::operator bool(Material asset)
|
Material::operator bool(Material materialInstance)
|
||||||
{
|
{
|
||||||
return asset;
|
return materialInstance;
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* Conversion Operators */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
Material::operator Asset(Material nativeAsset)
|
|
||||||
{
|
|
||||||
return nativeAsset.asset;
|
|
||||||
}
|
|
||||||
|
|
||||||
Material::operator Material(Asset asset)
|
|
||||||
{
|
|
||||||
return Material(Handle<SHMaterialInstance>(Convert::ToNative(asset.NativeObjectHandle)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,8 +16,8 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// External Dependencies
|
// External Dependencies
|
||||||
#include "Resource/SHHandle.h"
|
#include "Resource/SHHandle.h"
|
||||||
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
||||||
|
#include "Assets/SHAssetMacros.h"
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "NativeAsset.hxx"
|
|
||||||
#include "Engine/GenericHandle.hxx"
|
#include "Engine/GenericHandle.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -113,24 +113,10 @@ namespace SHADE
|
||||||
/// <returns>True if the Asset is valid.</returns>
|
/// <returns>True if the Asset is valid.</returns>
|
||||||
static operator bool(Material asset);
|
static operator bool(Material 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(Material nativeAsset);
|
|
||||||
/// <summary>
|
|
||||||
/// Conversion operator to enable casting from a Asset to a Material.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="vec">Vector2 to convert from.</param>
|
|
||||||
static explicit operator Material(Asset vec);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
Asset asset;
|
GenericHandle matInstHandle;
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue