Added scripting interface and serialization for Trajectory comp
This commit is contained in:
parent
4b37be6075
commit
87c04436b3
|
@ -180,6 +180,10 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
DrawComponent(listenerComponent);
|
DrawComponent(listenerComponent);
|
||||||
}
|
}
|
||||||
|
if (auto trajectoryComponent = SHComponentManager::GetComponent_s<SHTrajectoryRenderableComponent>(eid))
|
||||||
|
{
|
||||||
|
DrawComponent(trajectoryComponent);
|
||||||
|
}
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
// Render Scripts
|
// Render Scripts
|
||||||
SHScriptEngine* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
|
SHScriptEngine* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
|
||||||
|
@ -195,6 +199,7 @@ namespace SHADE
|
||||||
DrawAddComponentButton<SHButtonComponent>(eid);
|
DrawAddComponentButton<SHButtonComponent>(eid);
|
||||||
DrawAddComponentButton<SHToggleButtonComponent>(eid);
|
DrawAddComponentButton<SHToggleButtonComponent>(eid);
|
||||||
DrawAddComponentButton<SHSliderComponent>(eid);
|
DrawAddComponentButton<SHSliderComponent>(eid);
|
||||||
|
DrawAddComponentButton<SHTrajectoryRenderableComponent>(eid);
|
||||||
|
|
||||||
// Components that require Transforms
|
// Components that require Transforms
|
||||||
|
|
||||||
|
|
|
@ -42,16 +42,26 @@ namespace SHADE
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHVec4 const& SHTrajectoryRenderableComponent::GetStartColor(void) const noexcept
|
SHVec3 const& SHTrajectoryRenderableComponent::GetStartColor(void) const noexcept
|
||||||
{
|
{
|
||||||
return startColor;
|
return startColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHVec4 const& SHTrajectoryRenderableComponent::GetEndColor(void) const noexcept
|
SHVec3 const& SHTrajectoryRenderableComponent::GetEndColor(void) const noexcept
|
||||||
{
|
{
|
||||||
return endColor;
|
return endColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float SHTrajectoryRenderableComponent::GetStartAlpha(void) const noexcept
|
||||||
|
{
|
||||||
|
return startAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
float SHTrajectoryRenderableComponent::GetEndAlpha(void) const noexcept
|
||||||
|
{
|
||||||
|
return endAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
float SHTrajectoryRenderableComponent::GetColorEvolveRate(void) const noexcept
|
float SHTrajectoryRenderableComponent::GetColorEvolveRate(void) const noexcept
|
||||||
{
|
{
|
||||||
return colorEvolveRate;
|
return colorEvolveRate;
|
||||||
|
@ -67,17 +77,27 @@ namespace SHADE
|
||||||
positions = inPositions;
|
positions = inPositions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHTrajectoryRenderableComponent::SetStartColor(SHVec4 color) noexcept
|
void SHTrajectoryRenderableComponent::SetStartColor(SHVec3 color) noexcept
|
||||||
{
|
{
|
||||||
startColor = color;
|
startColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHTrajectoryRenderableComponent::SetEndColor(SHVec4 color) noexcept
|
void SHTrajectoryRenderableComponent::SetEndColor(SHVec3 color) noexcept
|
||||||
{
|
{
|
||||||
endColor = color;
|
endColor = color;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHTrajectoryRenderableComponent::SetStartAlpha(float a) noexcept
|
||||||
|
{
|
||||||
|
startAlpha = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHTrajectoryRenderableComponent::SetEndAlpha(float a) noexcept
|
||||||
|
{
|
||||||
|
endAlpha = a;
|
||||||
|
}
|
||||||
|
|
||||||
void SHTrajectoryRenderableComponent::SetColorEvolveRate(float rate) noexcept
|
void SHTrajectoryRenderableComponent::SetColorEvolveRate(float rate) noexcept
|
||||||
{
|
{
|
||||||
colorEvolveRate = rate;
|
colorEvolveRate = rate;
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
class SHMesh;
|
class SHMesh;
|
||||||
|
|
||||||
class SHTrajectoryRenderableComponent : public SHComponent
|
class SH_API SHTrajectoryRenderableComponent : public SHComponent
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -21,10 +21,16 @@ namespace SHADE
|
||||||
std::vector<SHVec3> positions;
|
std::vector<SHVec3> positions;
|
||||||
|
|
||||||
//! Starting color of the trajectory
|
//! Starting color of the trajectory
|
||||||
SHVec4 startColor;
|
SHVec3 startColor;
|
||||||
|
|
||||||
//! Color the trajectory should evolve to the longer it is
|
//! Color the trajectory should evolve to the longer it is
|
||||||
SHVec4 endColor;
|
SHVec3 endColor;
|
||||||
|
|
||||||
|
//! Starting alpha of the trajectory
|
||||||
|
float startAlpha;
|
||||||
|
|
||||||
|
//! end alpha of the trajectory
|
||||||
|
float endAlpha;
|
||||||
|
|
||||||
//! evolving rate of the color
|
//! evolving rate of the color
|
||||||
float colorEvolveRate;
|
float colorEvolveRate;
|
||||||
|
@ -35,14 +41,18 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
void SetMesh(Handle<SHMesh> newMesh) noexcept;
|
void SetMesh(Handle<SHMesh> newMesh) noexcept;
|
||||||
void SetPositions (std::vector<SHVec3> const& inPositions) noexcept;
|
void SetPositions (std::vector<SHVec3> const& inPositions) noexcept;
|
||||||
void SetStartColor(SHVec4 startColor) noexcept;
|
void SetStartColor(SHVec3 startColor) noexcept;
|
||||||
void SetEndColor (SHVec4 endColor) noexcept;
|
void SetEndColor (SHVec3 endColor) noexcept;
|
||||||
void SetColorEvolveRate (float rate) noexcept;
|
void SetStartAlpha(float a) noexcept;
|
||||||
|
void SetEndAlpha (float a) noexcept;
|
||||||
|
void SetColorEvolveRate(float rate) noexcept;
|
||||||
|
|
||||||
std::vector<SHVec3> GetPositions (void) const noexcept;
|
std::vector<SHVec3> GetPositions (void) const noexcept;
|
||||||
Handle<SHMesh> GetMesh (void) const noexcept;
|
Handle<SHMesh> GetMesh (void) const noexcept;
|
||||||
SHVec4 const& GetStartColor (void) const noexcept;
|
SHVec3 const& GetStartColor (void) const noexcept;
|
||||||
SHVec4 const& GetEndColor (void) const noexcept;
|
SHVec3 const& GetEndColor (void) const noexcept;
|
||||||
|
float GetStartAlpha (void) const noexcept;
|
||||||
|
float GetEndAlpha (void) const noexcept;
|
||||||
float GetColorEvolveRate (void) const noexcept;
|
float GetColorEvolveRate (void) const noexcept;
|
||||||
|
|
||||||
void OnCreate(void) override final;
|
void OnCreate(void) override final;
|
||||||
|
|
|
@ -59,8 +59,8 @@ namespace SHADE
|
||||||
.srcColorBlendFactor = vk::BlendFactor::eSrcAlpha,
|
.srcColorBlendFactor = vk::BlendFactor::eSrcAlpha,
|
||||||
.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
|
.dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
|
||||||
.colorBlendOp = vk::BlendOp::eAdd,
|
.colorBlendOp = vk::BlendOp::eAdd,
|
||||||
.srcAlphaBlendFactor = vk::BlendFactor::eOne,
|
.srcAlphaBlendFactor = vk::BlendFactor::eSrcAlpha,
|
||||||
.dstAlphaBlendFactor = vk::BlendFactor::eZero,
|
.dstAlphaBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha,
|
||||||
.alphaBlendOp = vk::BlendOp::eAdd,
|
.alphaBlendOp = vk::BlendOp::eAdd,
|
||||||
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
|
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,8 @@ namespace SHADE
|
||||||
if (transform)
|
if (transform)
|
||||||
{
|
{
|
||||||
// convenient variable
|
// convenient variable
|
||||||
SHVec4 const& startColor = comp.GetStartColor();
|
SHVec3 const& startColor = comp.GetStartColor();
|
||||||
SHVec4 const& endColor = comp.GetEndColor();
|
SHVec3 const& endColor = comp.GetEndColor();
|
||||||
float colorEvolveRate = comp.GetColorEvolveRate();
|
float colorEvolveRate = comp.GetColorEvolveRate();
|
||||||
|
|
||||||
// trs to be reused
|
// trs to be reused
|
||||||
|
@ -118,7 +118,8 @@ namespace SHADE
|
||||||
colorData.push_back(currentColor);
|
colorData.push_back(currentColor);
|
||||||
|
|
||||||
// evolve color
|
// evolve color
|
||||||
currentColor = SHVec4::Lerp(startColor, endColor, lerpValue);
|
currentColor = SHVec3::Lerp(startColor, endColor, lerpValue);
|
||||||
|
currentColor.w = SHMath::Lerp (comp.GetStartAlpha(), comp.GetEndAlpha(), lerpValue);
|
||||||
|
|
||||||
// evolve lerp value and clamp to 1
|
// evolve lerp value and clamp to 1
|
||||||
lerpValue = std::max (1.0f, lerpValue + colorEvolveRate);
|
lerpValue = std::max (1.0f, lerpValue + colorEvolveRate);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
|
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
|
||||||
#include "Animation/SHAnimatorComponent.h"
|
#include "Animation/SHAnimatorComponent.h"
|
||||||
#include "Physics/Collision/CollisionTags/SHCollisionTagMatrix.h"
|
#include "Physics/Collision/CollisionTags/SHCollisionTagMatrix.h"
|
||||||
|
#include "Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderableComponent.h"
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
{
|
{
|
||||||
|
@ -424,4 +425,37 @@ namespace YAML
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct convert<SHTrajectoryRenderableComponent>
|
||||||
|
{
|
||||||
|
static constexpr std::string_view MESH_YAML_TAG = "Mesh";
|
||||||
|
static constexpr std::string_view START_COLOR_YAML_TAG = "Start Color";
|
||||||
|
static constexpr std::string_view END_COLOR_YAML_TAG = "End Color";
|
||||||
|
static constexpr std::string_view COLOR_EVAL_RATE_YAML_TAG = "Color Eval Rate ";
|
||||||
|
|
||||||
|
static YAML::Node encode(SHTrajectoryRenderableComponent const& rhs)
|
||||||
|
{
|
||||||
|
YAML::Node node;
|
||||||
|
node[MESH_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHMesh>(rhs.GetMesh()).value_or(0);
|
||||||
|
node[START_COLOR_YAML_TAG.data()] = SHVec3(rhs.GetStartColor());
|
||||||
|
node[END_COLOR_YAML_TAG.data()] = SHVec3(rhs.GetEndColor());
|
||||||
|
node[COLOR_EVAL_RATE_YAML_TAG.data()] = rhs.GetColorEvolveRate();
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
static bool decode(YAML::Node const& node, SHTrajectoryRenderableComponent& rhs)
|
||||||
|
{
|
||||||
|
if (node[MESH_YAML_TAG.data()].IsDefined())
|
||||||
|
rhs.SetMesh(SHResourceManager::LoadOrGet<SHMesh>(node[MESH_YAML_TAG.data()].as<AssetID>()));
|
||||||
|
if (node[START_COLOR_YAML_TAG.data()].IsDefined())
|
||||||
|
rhs.SetStartColor(node[START_COLOR_YAML_TAG.data()].as<SHVec3>());
|
||||||
|
if (node[END_COLOR_YAML_TAG.data()].IsDefined())
|
||||||
|
rhs.SetEndColor(node[END_COLOR_YAML_TAG.data()].as<SHVec3>());
|
||||||
|
if (node[COLOR_EVAL_RATE_YAML_TAG.data()].IsDefined())
|
||||||
|
rhs.SetColorEvolveRate(node[COLOR_EVAL_RATE_YAML_TAG.data()].as<float>());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
#include "SHpch.h"
|
||||||
|
|
||||||
|
#include "TrajectoryRenderable.hxx"
|
||||||
|
#include "Assets/NativeAsset.hxx"
|
||||||
|
#include "Utility/Convert.hxx"
|
||||||
|
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
TrajectoryRenderable::TrajectoryRenderable(Entity entity)
|
||||||
|
:Component(entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MeshAsset TrajectoryRenderable::Mesh::get()
|
||||||
|
{
|
||||||
|
auto mesh = GetNativeComponent()->GetMesh();
|
||||||
|
return mesh ? MeshAsset(mesh) : MeshAsset();
|
||||||
|
}
|
||||||
|
void TrajectoryRenderable::Mesh::set(MeshAsset value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
GetNativeComponent()->SetMesh(Handle<SHMesh>());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GetNativeComponent()->SetMesh(value.NativeObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TrajectoryRenderable::StartColor::set(Vector3 val)
|
||||||
|
{
|
||||||
|
GetNativeComponent()->SetStartColor(Convert::ToNative(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 TrajectoryRenderable::StartColor::get()
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(GetNativeComponent()->GetStartColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrajectoryRenderable::EndColor::set(Vector3 val)
|
||||||
|
{
|
||||||
|
GetNativeComponent()->SetEndColor(Convert::ToNative(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 TrajectoryRenderable::EndColor::get()
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(GetNativeComponent()->GetEndColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrajectoryRenderable::StartAlpha::set(float val)
|
||||||
|
{
|
||||||
|
GetNativeComponent()->SetStartAlpha(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
float TrajectoryRenderable::StartAlpha::get()
|
||||||
|
{
|
||||||
|
return GetNativeComponent()->GetStartAlpha();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrajectoryRenderable::EndAlpha::set(float val)
|
||||||
|
{
|
||||||
|
GetNativeComponent()->SetEndAlpha(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
float TrajectoryRenderable::EndAlpha::get()
|
||||||
|
{
|
||||||
|
return GetNativeComponent()->GetEndAlpha();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrajectoryRenderable::ColorEvolveRate::set(float val)
|
||||||
|
{
|
||||||
|
GetNativeComponent()->SetColorEvolveRate(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
float TrajectoryRenderable::ColorEvolveRate::get()
|
||||||
|
{
|
||||||
|
return GetNativeComponent()->GetColorEvolveRate();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file TrajectoryRenderable.hxx
|
||||||
|
\author Brandon Mak, brandon.hao,
|
||||||
|
\par email: brandon.hao\@digipen.edu
|
||||||
|
\date 1st March, 2023
|
||||||
|
\brief Contains the definition of the managed Renderable class with the
|
||||||
|
declaration of functions for working with it.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
// Project Includes
|
||||||
|
#include "Components/Component.hxx"
|
||||||
|
#include "Math/Quaternion.hxx"
|
||||||
|
// External Dependencies
|
||||||
|
#include "Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderableComponent.h"
|
||||||
|
#include "Graphics/Color.hxx"
|
||||||
|
#include "Assets/MeshAsset.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// CLR version of the SHADE Engine's SHRenderableComponent.
|
||||||
|
/// </summary>
|
||||||
|
public ref class TrajectoryRenderable : public Component<SHTrajectoryRenderableComponent>
|
||||||
|
{
|
||||||
|
internal:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Constructors */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs a Trajectory Renderable Component that represents a native Trajectory Renderable
|
||||||
|
/// component tied to the specified Entity.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">Entity that this Component will be tied to.</param>
|
||||||
|
TrajectoryRenderable(Entity entity);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Mesh used to render this Renderable.
|
||||||
|
/// </summary>
|
||||||
|
property MeshAsset Mesh
|
||||||
|
{
|
||||||
|
MeshAsset get();
|
||||||
|
void set(MeshAsset value);
|
||||||
|
}
|
||||||
|
|
||||||
|
property Vector3 StartColor
|
||||||
|
{
|
||||||
|
Vector3 get();
|
||||||
|
void set (Vector3 val);
|
||||||
|
}
|
||||||
|
|
||||||
|
property Vector3 EndColor
|
||||||
|
{
|
||||||
|
Vector3 get();
|
||||||
|
void set(Vector3 val);
|
||||||
|
}
|
||||||
|
|
||||||
|
property float StartAlpha
|
||||||
|
{
|
||||||
|
float get();
|
||||||
|
void set (float val);
|
||||||
|
}
|
||||||
|
|
||||||
|
property float EndAlpha
|
||||||
|
{
|
||||||
|
float get();
|
||||||
|
void set(float val);
|
||||||
|
}
|
||||||
|
|
||||||
|
property float ColorEvolveRate
|
||||||
|
{
|
||||||
|
float get();
|
||||||
|
void set(float val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -46,6 +46,8 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Components\UIElement.hxx"
|
#include "Components\UIElement.hxx"
|
||||||
#include "Components\Canvas.hxx"
|
#include "Components\Canvas.hxx"
|
||||||
#include "Components\Slider.hxx"
|
#include "Components\Slider.hxx"
|
||||||
|
#include "Components\TrajectoryRenderable.hxx"
|
||||||
|
#include "Graphics\MiddleEnd\TrajectoryRendering\SHTrajectoryRenderableComponent.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -335,6 +337,7 @@ namespace SHADE
|
||||||
componentMap.Add(createComponentSet<SHUIComponent, UIElement>());
|
componentMap.Add(createComponentSet<SHUIComponent, UIElement>());
|
||||||
componentMap.Add(createComponentSet<SHCanvasComponent, Canvas>());
|
componentMap.Add(createComponentSet<SHCanvasComponent, Canvas>());
|
||||||
componentMap.Add(createComponentSet<SHSliderComponent, Slider>());
|
componentMap.Add(createComponentSet<SHSliderComponent, Slider>());
|
||||||
|
componentMap.Add(createComponentSet<SHTrajectoryRenderableComponent, TrajectoryRenderable>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in New Issue