Fixed material property setting at runtime #214

Merged
Pycorax merged 4 commits from SP3-1-MaterialUpdate into main 2022-11-16 17:01:57 +08:00
6 changed files with 299 additions and 18 deletions
Showing only changes of commit db7c4a6d38 - Show all commits

View File

@ -7,7 +7,7 @@
#include "ECS_Base/System/SHSystem.h" #include "ECS_Base/System/SHSystem.h"
#include "ECS_Base/System/SHSystemRoutine.h" #include "ECS_Base/System/SHSystemRoutine.h"
#include "ECS_Base/SHECSMacros.h" #include "ECS_Base/SHECSMacros.h"
#include "Math/SHMath.h" #include "Math/Vector/SHVec3.h"
#include <optional> #include <optional>
#include <FMOD/fmod_studio.hpp> #include <FMOD/fmod_studio.hpp>
#include "SH_API.h" #include "SH_API.h"

View File

@ -220,6 +220,87 @@ namespace SHADE
} }
template<>
static void DrawComponent(SHRigidBodyComponent* component)
{
if(!component)
return;
ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHRigidBodyComponent>());
const auto componentType = rttr::type::get<SHRigidBodyComponent>();
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active");
ImGui::SameLine();
if (ImGui::CollapsingHeader(componentType.get_name().data()))
{
DrawContextMenu(component);
SHRigidBodyComponent::Type rbType = component->GetType();
auto enumAlign = rttr::type::get<SHRigidBodyComponent::Type>().get_enumeration();
auto names = enumAlign.get_names();
std::vector<const char*> list;
for (auto const& name : names)
list.push_back(name.data());
SHEditorWidgets::ComboBox("Type", list, [component] {return static_cast<int>(component->GetType()); }, [component, enumAlign](int const& idx)
{
auto values = enumAlign.get_values();
auto it = std::next(values.begin(), idx);
component->SetType((*it).convert<SHRigidBodyComponent::Type>());
}, "RigidBody Type");
if(rbType == SHRigidBodyComponent::Type::DYNAMIC) //Dynamic only fields
{
SHEditorWidgets::CheckBox("Use Gravity", [component]{return component->IsGravityEnabled();}, [component](bool const& value){component->SetGravityEnabled(value);}, "Gravity");
SHEditorWidgets::DragFloat("Mass", [component] {return component->GetMass(); }, [component](float const& value) {component->SetMass(value); }, "Mass");
}
if (rbType == SHRigidBodyComponent::Type::DYNAMIC || rbType == SHRigidBodyComponent::Type::KINEMATIC) //Dynamic or Kinematic only fields
{
SHEditorWidgets::DragFloat("Drag", [component] {return component->GetDrag(); }, [component](float const& value) {component->SetDrag(value); }, "Drag");
SHEditorWidgets::DragFloat("Angular Drag", [component] {return component->GetAngularDrag(); }, [component](float const& value) {component->SetAngularDrag(value); }, "Angular Drag");
SHEditorWidgets::CheckBox("Interpolate", [component] {return component->IsInterpolating(); }, [component](bool const& value) {component->SetInterpolate(value); }, "Interpolate");
SHEditorWidgets::BeginPanel(std::format("{} Constraints", ICON_FA_LOCK).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
SHEditorWidgets::TextLabel("Freeze Position");
SHEditorWidgets::CheckBox("X", [component] {return component->GetFreezePositionX(); }, [component](bool const& value) {component->SetFreezePositionX(value); }, "Freeze Position - X"); ImGui::SameLine();
SHEditorWidgets::CheckBox("Y", [component] {return component->GetFreezePositionY(); }, [component](bool const& value) {component->SetFreezePositionY(value); }, "Freeze Position - Y"); ImGui::SameLine();
SHEditorWidgets::CheckBox("Z", [component] {return component->GetFreezePositionZ(); }, [component](bool const& value) {component->SetFreezePositionZ(value); }, "Freeze Position - Z");
SHEditorWidgets::TextLabel("Freeze Rotation");
SHEditorWidgets::CheckBox("X", [component] {return component->GetFreezeRotationX(); }, [component](bool const& value) {component->SetFreezeRotationX(value); }, "Freeze Rotation - X"); ImGui::SameLine();
SHEditorWidgets::CheckBox("Y", [component] {return component->GetFreezeRotationY(); }, [component](bool const& value) {component->SetFreezeRotationY(value); }, "Freeze Rotation - Y"); ImGui::SameLine();
SHEditorWidgets::CheckBox("Z", [component] {return component->GetFreezeRotationZ(); }, [component](bool const& value) {component->SetFreezeRotationZ(value); }, "Freeze Rotation - Z");
SHEditorWidgets::EndPanel();
}
//Debug Info (Read-Only)
if(ImGui::CollapsingHeader("Debug Information", ImGuiTreeNodeFlags_DefaultOpen))//Dynamic or Kinematic only fields
{
SHEditorWidgets::DragVec3("Position", { "X", "Y", "Z" }, [component] {return component->GetPosition(); }, [](SHVec3 const& value) {}, false, "Position", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly);
SHEditorWidgets::DragVec3("Rotation", { "X", "Y", "Z" }, [component] {return component->GetRotation(); }, [](SHVec3 const& value) {}, false, "Rotation", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly);
if (rbType == SHRigidBodyComponent::Type::DYNAMIC || rbType == SHRigidBodyComponent::Type::KINEMATIC) //Dynamic or Kinematic only fields
{
SHEditorWidgets::DragVec3("Velocity", { "X", "Y", "Z" }, [component] {return component->GetLinearVelocity(); }, [](SHVec3 const& value) {}, false, "Linear Velocity", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly);
SHEditorWidgets::DragVec3("Angular\nVelocity", { "X", "Y", "Z" }, [component] {return component->GetAngularVelocity(); }, [](SHVec3 const& value) {}, false, "Angular Velocity", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly);
}
if (rbType == SHRigidBodyComponent::Type::DYNAMIC) //Dynamic only fields
{
SHEditorWidgets::DragVec3("Force", { "X", "Y", "Z" }, [component] {return component->GetForce(); }, [](SHVec3 const& value) {}, false, "Force", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly);
SHEditorWidgets::DragVec3("Torque", { "X", "Y", "Z" }, [component] {return component->GetTorque(); }, [](SHVec3 const& value) {}, false, "Torque", 0.1f, "%.3f", 0.0f, 0.0f, ImGuiSliderFlags_ReadOnly);
}
}
}
else
{
DrawContextMenu(component);
}
ImGui::PopID();
}
template<> template<>
static void DrawComponent(SHColliderComponent* component) static void DrawComponent(SHColliderComponent* component)
{ {
@ -278,21 +359,12 @@ namespace SHADE
[&collider] [&collider]
{ {
auto offset = collider->GetRotationOffset(); auto offset = collider->GetRotationOffset();
offset.x = SHMath::RadiansToDegrees(offset.x);
offset.y = SHMath::RadiansToDegrees(offset.y);
offset.z = SHMath::RadiansToDegrees(offset.z);
return offset; return offset;
}, },
[&collider](SHVec3 const& vec) [&collider](SHVec3 const& vec)
{ {
const SHVec3 vecInRad collider->SetRotationOffset(vec);
{ }, true);
SHMath::DegreesToRadians(vec.x)
, SHMath::DegreesToRadians(vec.y)
, SHMath::DegreesToRadians(vec.z)
};
collider->SetRotationOffset(vecInRad);
});
SHEditorWidgets::EndPanel(); SHEditorWidgets::EndPanel();
} }

View File

@ -166,14 +166,14 @@ namespace SHADE
const ImGuiWindow* const window = ImGui::GetCurrentWindow(); const ImGuiWindow* const window = ImGui::GetCurrentWindow();
if (window->SkipItems) if (window->SkipItems)
return false; return false;
static constexpr float defaultLabelColWidth = 80.0f;
const ImGuiContext& g = *GImGui; const ImGuiContext& g = *GImGui;
bool valueChanged = false; bool valueChanged = false;
ImGui::BeginGroup(); ImGui::BeginGroup();
ImGui::PushID(label.c_str()); ImGui::PushID(label.c_str());
PushMultiItemsWidthsAndLabels(componentLabels, 0.0f); PushMultiItemsWidthsAndLabels(componentLabels, 0.0f);
ImGui::BeginColumns("DragVecCol", 2, ImGuiOldColumnFlags_NoBorder | ImGuiOldColumnFlags_NoResize); ImGui::BeginColumns("DragVecCol", 2, ImGuiOldColumnFlags_NoBorder | ImGuiOldColumnFlags_NoResize);
ImGui::SetColumnWidth(-1, 80.0f); ImGui::SetColumnWidth(-1, defaultLabelColWidth);
ImGui::Text(label.c_str()); ImGui::Text(label.c_str());
if (isHovered) if (isHovered)
*isHovered |= ImGui::IsItemHovered(); *isHovered |= ImGui::IsItemHovered();
@ -219,7 +219,7 @@ namespace SHADE
} }
bool const changed = DragN<float, 2>(label, componentLabels, { &values.x, &values.y }, speed, displayFormat, valueMin, valueMax, flags); bool const changed = DragN<float, 2>(label, componentLabels, { &values.x, &values.y }, speed, displayFormat, valueMin, valueMax, flags);
static bool startRecording = false; static bool startRecording = false;
if (changed) if (!(flags & ImGuiSliderFlags_ReadOnly) && changed)
{ {
if(isAnAngleInRad) if(isAnAngleInRad)
{ {
@ -255,7 +255,7 @@ namespace SHADE
bool isHovered = false; bool isHovered = false;
bool const changed = DragN<float, 3>(label, componentLabels, { &values.x, &values.y, &values.z }, speed, displayFormat, valueMin, valueMax, flags, &isHovered); bool const changed = DragN<float, 3>(label, componentLabels, { &values.x, &values.y, &values.z }, speed, displayFormat, valueMin, valueMax, flags, &isHovered);
static bool startRecording = false; static bool startRecording = false;
if (changed) if (!(flags & ImGuiSliderFlags_ReadOnly) && changed)
{ {
SHVec3 old = get(); SHVec3 old = get();
if(isAnAngleInRad) if(isAnAngleInRad)
@ -293,7 +293,7 @@ namespace SHADE
} }
bool const changed = DragN<float, 4>(label, componentLabels, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags); bool const changed = DragN<float, 4>(label, componentLabels, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags);
static bool startRecording = false; static bool startRecording = false;
if (changed) if (!(flags & ImGuiSliderFlags_ReadOnly) && changed)
{ {
if(isAnAngleInRad) if(isAnAngleInRad)
{ {

View File

@ -39,13 +39,15 @@ project "SHADE_Managed"
"%{IncludeDir.dotnet}\\include", "%{IncludeDir.dotnet}\\include",
"%{IncludeDir.reactphysics3d}\\include", "%{IncludeDir.reactphysics3d}\\include",
"%{IncludeDir.VULKAN}\\include", "%{IncludeDir.VULKAN}\\include",
"%{IncludeDir.fmod}\\include",
"%{wks.location}/SHADE_Engine/src" "%{wks.location}/SHADE_Engine/src"
} }
libdirs libdirs
{ {
"%{IncludeDir.RTTR}/lib", "%{IncludeDir.RTTR}/lib",
"%{IncludeDir.SDL}/lib" "%{IncludeDir.SDL}/lib",
"%{IncludeDir.fmod}/lib"
} }
links links
@ -93,16 +95,19 @@ project "SHADE_Managed"
symbols "On" symbols "On"
defines {"_DEBUG"} defines {"_DEBUG"}
links{"librttr_core_d.lib"} links{"librttr_core_d.lib"}
links{"fmodstudioL_vc.lib", "fmodL_vc.lib"}
filter "configurations:Release" filter "configurations:Release"
optimize "On" optimize "On"
defines{"_RELEASE"} defines{"_RELEASE"}
links{"librttr_core.lib"} links{"librttr_core.lib"}
links{"fmodstudio_vc.lib", "fmod_vc.lib"}
filter "configurations:Publish" filter "configurations:Publish"
optimize "On" optimize "On"
defines{"_RELEASE"} defines{"_RELEASE"}
links{"librttr_core.lib"} links{"librttr_core.lib"}
links{"fmodstudio_vc.lib", "fmod_vc.lib"}
require "vstudio" require "vstudio"

View File

@ -0,0 +1,101 @@
/************************************************************************************//*!
\file Audio.cxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 16, 2022
\brief Contains the function definitions of the managed Audio static 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 Header
#include "SHpch.h"
// Primary Header
#include "Audio.hxx"
// External Dependencies
#include "AudioSystem/SHAudioSystem.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Utility/Convert.hxx"
namespace SHADE
{
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
float Audio::BGMVolume::get()
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
return audioSys->GetBgmVolume();
}
void Audio::BGMVolume::set(float value)
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
audioSys->SetBgmVolume(System::Math::Clamp(value, 0.0f, 1.0f));
}
float Audio::SFXVolume::get()
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
return audioSys->GetSfxVolume();
}
void Audio::SFXVolume::set(float value)
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
audioSys->SetSfxVolume(System::Math::Clamp(value, 0.0f, 1.0f));
}
float Audio::MasterVolume::get()
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
return audioSys->GetMasterVolume();
}
void Audio::MasterVolume::set(float value)
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
audioSys->SetMasterVolume(System::Math::Clamp(value, 0.0f, 1.0f));
}
bool Audio::IsPaused::get()
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
return audioSys->GetPaused();
}
void Audio::IsPaused::set(bool value)
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
audioSys->SetPaused(value);
}
/*-----------------------------------------------------------------------------*/
/* Playback Control Functions */
/*-----------------------------------------------------------------------------*/
void Audio::PlaySFXOnce2D(System::String^ path)
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
audioSys->PlayEventOnce(Convert::ToNative(path).data());
}
void Audio::PlaySFXOnce3D(System::String^ path, GameObject gameObject)
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
audioSys->PlayEventOnce(Convert::ToNative(path).data(), true, gameObject.GetEntity(), true);
}
void Audio::PlayBGMOnce2D(System::String^ path)
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
audioSys->PlayEventOnce(Convert::ToNative(path).data(), false);
}
void Audio::PlayBGMOnce3D(System::String^ path, GameObject gameObject)
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
audioSys->PlayEventOnce(Convert::ToNative(path).data(), false, gameObject.GetEntity(), true);
}
void Audio::StopAllSounds()
{
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
audioSys->StopAllSounds();
}
}

View File

@ -0,0 +1,103 @@
/************************************************************************************//*!
\file Audio.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Nov 16, 2022
\brief Contains the definitions of the managed Audio static 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
#include "Engine/GameObject.hxx"
namespace SHADE
{
/// <summary>
/// Static class that contains the functions for interfacing with the Audio system.
/// </summary>
public ref class Audio abstract sealed
{
public:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Volume of background music playback. Clamped between 0.0 and 1.0.
/// </summary>
static property float BGMVolume
{
float get();
void set(float value);
}
/// <summary>
/// Volume of sound effects playback. Clamped between 0.0 and 1.0.
/// </summary>
static property float SFXVolume
{
float get();
void set(float value);
}
/// <summary>
/// Overall volume for all audio playback. Clamped between 0.0 and 1.0.
/// </summary>
static property float MasterVolume
{
float get();
void set(float value);
}
/// <summary>
/// Whether or not all audio playback is paused.
/// </summary>
static property bool IsPaused
{
bool get();
void set(bool value);
}
/*-----------------------------------------------------------------------------*/
/* Playback Control Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Plays a sound effect without looping without spatial attenuation.
/// </summary>
/// <param name="path">
/// Path to the audio file relative to the working directory.
/// </param>
static void PlaySFXOnce2D(System::String^ path);
/// <summary>
/// Plays a sound effect without looping with spatial attenuation.
/// </summary>
/// <param name="path">
/// Path to the audio file relative to the working directory.
/// </param>
/// <param name="gameObject">
/// Object whose position is used to play the sound effect.
/// </param>
static void PlaySFXOnce3D(System::String^ path, GameObject gameObject);
/// <summary>
/// Plays background music without looping without spatial attenuation.
/// </summary>
/// <param name="path">
/// Path to the audio file relative to the working directory.
/// </param>
static void PlayBGMOnce2D(System::String^ path);
/// <summary>
/// Plays background music without looping with spatial attenuation.
/// </summary>
/// <param name="path">
/// Path to the audio file relative to the working directory.
/// </param>
/// <param name="gameObject">
/// Object whose position is used to play the background music.
/// </param>
static void PlayBGMOnce3D(System::String^ path, GameObject gameObject);
/// <summary>
/// Stops playback of all sound effects and music.
/// </summary>
static void StopAllSounds();
};
}