Scripting changes for item and added level 1 scene #330
|
@ -1 +1,96 @@
|
|||
7
|
||||
Controller Look Horizontal
|
||||
0
|
||||
0
|
||||
5
|
||||
0.2
|
||||
5
|
||||
0
|
||||
0
|
||||
0
|
||||
1
|
||||
18
|
||||
0
|
||||
Controller Look Vertical
|
||||
0
|
||||
0
|
||||
5
|
||||
0.2
|
||||
5
|
||||
0
|
||||
0
|
||||
0
|
||||
1
|
||||
19
|
||||
0
|
||||
Horizontal
|
||||
0
|
||||
0
|
||||
5
|
||||
0.2
|
||||
5
|
||||
1
|
||||
2
|
||||
39
|
||||
68
|
||||
2
|
||||
37
|
||||
65
|
||||
2
|
||||
3
|
||||
16
|
||||
1
|
||||
2
|
||||
Jump
|
||||
0
|
||||
0
|
||||
1000
|
||||
0.2
|
||||
1000
|
||||
0
|
||||
1
|
||||
32
|
||||
0
|
||||
1
|
||||
10
|
||||
0
|
||||
Mouse Look Horizontal
|
||||
1
|
||||
0
|
||||
1
|
||||
0.2
|
||||
1
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
Mouse Look Vertical
|
||||
2
|
||||
0
|
||||
1
|
||||
0.2
|
||||
1
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
Vertical
|
||||
0
|
||||
0
|
||||
5
|
||||
0.2
|
||||
5
|
||||
1
|
||||
2
|
||||
38
|
||||
87
|
||||
2
|
||||
40
|
||||
83
|
||||
2
|
||||
0
|
||||
17
|
||||
1
|
||||
1
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
Start Maximized: true
|
||||
Working Scene ID: 97161771
|
||||
Window Size: {x: 1920, y: 1080}
|
||||
Style: 0
|
|
@ -0,0 +1,8 @@
|
|||
- VertexShader: 47911992
|
||||
FragmentShader: 46377769
|
||||
SubPass: G-Buffer Write
|
||||
Properties:
|
||||
data.color: {x: 1, y: 1, z: 1, w: 1}
|
||||
data.textureIndex: 58303057
|
||||
data.alpha: 0
|
||||
data.beta: {x: 1, y: 1, z: 1}
|
|
@ -0,0 +1,3 @@
|
|||
Name: AnimatedBag
|
||||
ID: 117923942
|
||||
Type: 7
|
|
@ -0,0 +1,8 @@
|
|||
- VertexShader: 47911992
|
||||
FragmentShader: 46377769
|
||||
SubPass: G-Buffer Write
|
||||
Properties:
|
||||
data.color: {x: 1, y: 1, z: 1, w: 1}
|
||||
data.textureIndex: 64651793
|
||||
data.alpha: 0
|
||||
data.beta: {x: 1, y: 1, z: 1}
|
|
@ -0,0 +1,3 @@
|
|||
Name: AnimatedRaccoon
|
||||
ID: 128805346
|
||||
Type: 7
|
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -0,0 +1,7 @@
|
|||
Name: BoneIKTest4
|
||||
ID: 81814706
|
||||
Type: 4
|
||||
Sub Assets:
|
||||
Name: Cube
|
||||
ID: 137599708
|
||||
Type: 8
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -4,6 +4,7 @@ using System;
|
|||
|
||||
public class SoundsBoard : Script
|
||||
{
|
||||
AudioClipHandler test;
|
||||
protected override void awake()
|
||||
{
|
||||
/*
|
||||
|
@ -31,13 +32,21 @@ event:/Homeowner/homeowner_humming
|
|||
event:/Homeowner/homeowner_footsteps
|
||||
event:/Homeowner/homeowner_detect_raccoon
|
||||
*/
|
||||
test = Audio.CreateAudioClip("event:/Music/player_undetected");
|
||||
Audio.AddAudioClipToSFXChannelGroup(test);
|
||||
}
|
||||
|
||||
protected override void start()
|
||||
{
|
||||
test.Play();
|
||||
}
|
||||
protected override void update()
|
||||
{
|
||||
|
||||
if (Input.GetKeyDown(Input.KeyCode.Q))
|
||||
Audio.PlayBGMOnce2D("event:/UI/mouse_down_element");
|
||||
test.Play();
|
||||
if (Input.GetKeyDown(Input.KeyCode.W))
|
||||
Audio.PlayBGMOnce2D("event:/UI/mouse_down_empty");
|
||||
test.Stop(true);
|
||||
if (Input.GetKeyDown(Input.KeyCode.E))
|
||||
Audio.PlayBGMOnce2D("event:/UI/mouse_enter_element");
|
||||
if (Input.GetKeyDown(Input.KeyCode.R))
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
#version 450
|
||||
#extension GL_KHR_vulkan_glsl : enable
|
||||
|
||||
//#include "ShaderDescriptorDefinitions.glsl"
|
||||
|
||||
|
||||
layout(location = 0) in vec3 aVertexPos;
|
||||
layout(location = 1) in vec2 aUV;
|
||||
layout(location = 2) in vec3 aNormal;
|
||||
layout(location = 3) in vec3 aTangent;
|
||||
layout(location = 4) in mat4 worldTransform;
|
||||
layout(location = 8) in uvec2 integerData;
|
||||
layout(location = 9) in uvec4 aBoneIndices;
|
||||
layout(location = 10) in vec4 aBoneWeights;
|
||||
layout(location = 11) in uint firstBoneIndex;
|
||||
|
||||
layout(location = 0) out struct
|
||||
{
|
||||
vec4 vertPos; // location 0
|
||||
vec2 uv; // location = 1
|
||||
vec4 normal; // location = 2
|
||||
vec4 worldPos; // location = 3
|
||||
} Out;
|
||||
|
||||
// material stuff
|
||||
layout(location = 4) out struct
|
||||
{
|
||||
int materialIndex;
|
||||
uint eid;
|
||||
uint lightLayerIndex;
|
||||
|
||||
} Out2;
|
||||
|
||||
layout(set = 1, binding = 0) uniform CameraData
|
||||
{
|
||||
vec4 position;
|
||||
mat4 vpMat;
|
||||
mat4 viewMat;
|
||||
mat4 projMat;
|
||||
} cameraData;
|
||||
|
||||
layout (std430, set = 2, binding = 1) buffer AnimBoneMatrices
|
||||
{
|
||||
mat4 data[];
|
||||
} BoneMatrices;
|
||||
|
||||
void main()
|
||||
{
|
||||
Out2.materialIndex = gl_InstanceIndex;
|
||||
Out2.eid = integerData[0];
|
||||
Out2.lightLayerIndex = integerData[1];
|
||||
|
||||
// for transforming gBuffer position and normal data
|
||||
mat4 modelViewMat = cameraData.viewMat * worldTransform;
|
||||
|
||||
// gBuffer position will be in view space
|
||||
Out.vertPos = modelViewMat * vec4(aVertexPos, 1.0f);
|
||||
|
||||
Out.worldPos = worldTransform * vec4 (aVertexPos, 1.0f);
|
||||
|
||||
// uvs for texturing in fragment shader
|
||||
Out.uv = aUV;
|
||||
|
||||
mat3 transposeInv = mat3 (transpose(inverse(modelViewMat)));
|
||||
|
||||
// normals are also in view space
|
||||
Out.normal.rgb = transposeInv * aNormal.rgb;
|
||||
Out.normal.rgb = normalize (Out.normal.rgb);
|
||||
|
||||
// Compute bone matrix
|
||||
mat4 boneMatrix = BoneMatrices.data[firstBoneIndex + aBoneIndices[0]] * aBoneWeights[0];
|
||||
boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[1]] * aBoneWeights[1];
|
||||
boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[2]] * aBoneWeights[2];
|
||||
boneMatrix += BoneMatrices.data[firstBoneIndex + aBoneIndices[3]] * aBoneWeights[3];
|
||||
|
||||
// clip space for rendering
|
||||
gl_Position = cameraData.vpMat * worldTransform * boneMatrix * vec4 (aVertexPos, 1.0f);
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
Name: Anim_VS
|
||||
ID: 47911992
|
||||
Type: 2
|
|
@ -17,7 +17,6 @@ layout(location = 0) in struct
|
|||
vec2 uv; // location = 1
|
||||
vec4 normal; // location = 2
|
||||
vec4 worldPos; // location = 3
|
||||
|
||||
} In;
|
||||
|
||||
// material stuff
|
||||
|
|
|
@ -10,7 +10,9 @@ layout(location = 2) in vec3 aNormal;
|
|||
layout(location = 3) in vec3 aTangent;
|
||||
layout(location = 4) in mat4 worldTransform;
|
||||
layout(location = 8) in uvec2 integerData;
|
||||
|
||||
layout(location = 9) in uvec4 aBoneIndices;
|
||||
layout(location = 10) in vec4 aBoneWeights;
|
||||
layout(location = 11) in uint firstBoneIndex;
|
||||
|
||||
layout(location = 0) out struct
|
||||
{
|
||||
|
|
Binary file not shown.
|
@ -34,6 +34,7 @@
|
|||
#include "Physics/System/SHPhysicsDebugDrawSystem.h"
|
||||
#include "Scripting/SHScriptEngine.h"
|
||||
#include "UI/SHUISystem.h"
|
||||
#include "Animation/SHAnimationSystem.h"
|
||||
|
||||
// Components
|
||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||
|
@ -47,6 +48,7 @@
|
|||
|
||||
#include "Tools/Logger/SHLogger.h"
|
||||
#include "Tools/SHDebugDraw.h"
|
||||
#include "Resource/SHResourceManager.h"
|
||||
|
||||
using namespace SHADE;
|
||||
|
||||
|
@ -95,6 +97,7 @@ namespace Sandbox
|
|||
// Link up SHDebugDraw
|
||||
SHSystemManager::CreateSystem<SHDebugDrawSystem>();
|
||||
SHDebugDraw::Init(SHSystemManager::GetSystem<SHDebugDrawSystem>());
|
||||
SHSystemManager::CreateSystem<SHAnimationSystem>();
|
||||
|
||||
#ifdef SHEDITOR
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
@ -141,7 +144,7 @@ namespace Sandbox
|
|||
#ifdef SHEDITOR
|
||||
SHSystemManager::RegisterRoutine<SHEditor, SHEditor::EditorRoutine>();
|
||||
#endif
|
||||
|
||||
SHSystemManager::RegisterRoutine<SHAnimationSystem, SHAnimationSystem::UpdateRoutine>();
|
||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::RenderRoutine>();
|
||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::EndRoutine>();
|
||||
|
||||
|
@ -149,6 +152,7 @@ namespace Sandbox
|
|||
SHComponentManager::CreateComponentSparseSet<SHColliderComponent>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHTransformComponent>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHRenderable>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHAnimatorComponent>();
|
||||
//SHComponentManager::CreateComponentSparseSet<SHCameraComponent>();
|
||||
|
||||
SHAssetManager::Load();
|
||||
|
@ -170,6 +174,10 @@ namespace Sandbox
|
|||
|
||||
// Link up SHDebugDraw
|
||||
SHDebugDraw::Init(SHSystemManager::GetSystem<SHDebugDrawSystem>());
|
||||
|
||||
auto clip = SHResourceManager::LoadOrGet<SHAnimationClip>(77816045);
|
||||
auto rig = SHResourceManager::LoadOrGet<SHRig>(77816045);
|
||||
int i = 0;
|
||||
}
|
||||
|
||||
void SBApplication::Update(void)
|
||||
|
@ -232,7 +240,13 @@ namespace Sandbox
|
|||
SDL_Quit();
|
||||
#endif
|
||||
|
||||
// Unload scenes
|
||||
SHSceneManager::Exit();
|
||||
|
||||
// Free all remaining resources
|
||||
SHResourceManager::UnloadAll();
|
||||
|
||||
// Shut down engine
|
||||
SHSystemManager::Exit();
|
||||
SHAssetManager::Exit();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHAnimationClip.cpp
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 20, 2022
|
||||
\brief Contains the function definitions of the SHAnimationClip 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.
|
||||
*//*************************************************************************************/
|
||||
// Pre-compiled Header
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "SHAnimationClip.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHAnimationClip::SHAnimationClip(const SHAnimAsset& asset)
|
||||
: ticksPerSecond { static_cast<int>(asset.ticksPerSecond) }
|
||||
, totalTime { static_cast<float>(asset.duration) / static_cast<int>(asset.ticksPerSecond) }
|
||||
{
|
||||
// Populate keyframes
|
||||
for (const auto& channel : asset.nodeChannels)
|
||||
{
|
||||
// Create a channel
|
||||
Channel newChannel;
|
||||
newChannel.Name = std::string(channel.name);
|
||||
newChannel.PositionKeyFrames.reserve(channel.positionKeys.size());
|
||||
newChannel.RotationKeyFrames.reserve(channel.rotationKeys.size());
|
||||
newChannel.ScaleKeyFrames.reserve(channel.scaleKeys.size());
|
||||
|
||||
// Populate Keyframes
|
||||
for (const auto& posKey : channel.positionKeys)
|
||||
{
|
||||
newChannel.PositionKeyFrames.emplace_back(SHAnimationKeyFrame<SHVec3>{ static_cast<int>(posKey.time), posKey.value});
|
||||
}
|
||||
for (const auto& rotKey : channel.rotationKeys)
|
||||
{
|
||||
newChannel.RotationKeyFrames.emplace_back(SHAnimationKeyFrame<SHQuaternion>{ static_cast<int>(rotKey.time), rotKey.value});
|
||||
}
|
||||
for (const auto& scaleKey : channel.scaleKeys)
|
||||
{
|
||||
newChannel.ScaleKeyFrames.emplace_back(SHAnimationKeyFrame<SHVec3>{ static_cast<int>(scaleKey.time), scaleKey.value});
|
||||
}
|
||||
|
||||
newChannel.MaxFrames = std::max({ newChannel.PositionKeyFrames.size(), newChannel.RotationKeyFrames.size(), newChannel.ScaleKeyFrames.size() });
|
||||
|
||||
// Insert the channel
|
||||
channels.emplace_back(std::move(newChannel));
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHAnimationClip.h
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Dec 12, 2022
|
||||
\brief Contains the definition of the SHAnimationClip struct and related types.
|
||||
|
||||
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 "SH_API.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "Assets/Asset Types/Models/SHAnimationAsset.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Defines a single key frame in an animation for a specific type of data.
|
||||
/// </summary>
|
||||
template<typename T>
|
||||
struct SHAnimationKeyFrame
|
||||
{
|
||||
int FrameIndex;
|
||||
T Data;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Represents a animation clip of a 3D animation that is made for a specific model
|
||||
/// rig.
|
||||
/// </summary>
|
||||
class SH_API SHAnimationClip
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Defines the animations of a single bone in a rig.
|
||||
/// </summary>
|
||||
struct Channel
|
||||
{
|
||||
std::string Name;
|
||||
std::vector<SHAnimationKeyFrame<SHVec3>> PositionKeyFrames;
|
||||
std::vector<SHAnimationKeyFrame<SHQuaternion>> RotationKeyFrames;
|
||||
std::vector<SHAnimationKeyFrame<SHVec3>> ScaleKeyFrames;
|
||||
int MaxFrames;
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructs an SHAnimation Clip from a specified SHAnimAsset.
|
||||
/// </summary>
|
||||
/// <param name="asset">Animation asset to load.</param>
|
||||
explicit SHAnimationClip(const SHAnimAsset& asset);
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
const std::vector<Channel>& GetChannels() const noexcept { return channels; }
|
||||
int GetTicksPerSecond() const noexcept { return ticksPerSecond; }
|
||||
float GetTotalTime() const noexcept { return totalTime; }
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
std::vector<Channel> channels;
|
||||
int ticksPerSecond;
|
||||
float totalTime;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
};
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHAnimationSystem.cpp
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 20, 2022
|
||||
\brief Contains the function definitions of the SHAnimationSystem 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 "SHAnimationSystem.h"
|
||||
// Project Includes
|
||||
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||
#include "SHAnimatorComponent.h"
|
||||
#include "ECS_Base/General/SHFamily.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* System Routine Functions - UpdateRoutine */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHAnimationSystem::UpdateRoutine::UpdateRoutine()
|
||||
: SHSystemRoutine("Animation System Update", true)
|
||||
{
|
||||
SHFamilyID<SHSystem>::GetID<SHAnimationSystem>();
|
||||
}
|
||||
|
||||
void SHAnimationSystem::UpdateRoutine::Execute(double dt) noexcept
|
||||
{
|
||||
auto& animators = SHComponentManager::GetDense<SHAnimatorComponent>();
|
||||
for (auto& animator : animators)
|
||||
{
|
||||
animator.Update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* SHSystem Overrides */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void SHAnimationSystem::Init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SHAnimationSystem::Exit(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHAnimationSystem.h
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 20, 2022
|
||||
\brief Contains the definition of the SHAnimationSystem class and related types.
|
||||
|
||||
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 "SH_API.h"
|
||||
#include "ECS_Base/System/SHSystem.h"
|
||||
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// System that is responsible for updating all animations.
|
||||
/// </summary>
|
||||
class SH_API SHAnimationSystem : public SHSystem
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Responsible for updating the playback of all animator components and computing
|
||||
/// the required bone matrices.
|
||||
/// </summary>
|
||||
class SH_API UpdateRoutine final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
UpdateRoutine();
|
||||
void Execute(double dt) noexcept override final;
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
SHAnimationSystem() = default;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* SHSystem Overrides */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
virtual void Init(void) override final;
|
||||
virtual void Exit(void) override final;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHAnimatorComponent.cpp
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 20, 2022
|
||||
\brief Contains the definition of functions of the SHAnimatorComponent Component
|
||||
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 "SHAnimatorComponent.h"
|
||||
// STL Includes
|
||||
#include <queue>
|
||||
// Project Includes
|
||||
#include "SHRig.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "SHAnimationClip.h"
|
||||
#include "Graphics/SHVkUtil.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Tools/SHDebugDraw.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void SHAnimatorComponent::Play()
|
||||
{
|
||||
isPlaying = false;
|
||||
}
|
||||
|
||||
void SHAnimatorComponent::Play(Handle<SHAnimationClip> clip)
|
||||
{
|
||||
currClip = clip;
|
||||
currPlaybackTime = 0.0f;
|
||||
Play();
|
||||
}
|
||||
|
||||
void SHAnimatorComponent::PlayFromStart()
|
||||
{
|
||||
isPlaying = true;
|
||||
currPlaybackTime = 0.0f;
|
||||
}
|
||||
|
||||
void SHAnimatorComponent::Pause()
|
||||
{
|
||||
isPlaying = false;
|
||||
}
|
||||
|
||||
void SHAnimatorComponent::Stop()
|
||||
{
|
||||
isPlaying = false;
|
||||
currPlaybackTime = 0.0f;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Setter Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void SHAnimatorComponent::SetRig(Handle<SHRig> newRig)
|
||||
{
|
||||
// Same rig, don't bother
|
||||
if (rig == newRig)
|
||||
return;
|
||||
|
||||
rig = newRig;
|
||||
|
||||
// Populate bone matrices based on new rig's default pose
|
||||
boneMatrices.clear();
|
||||
if (rig)
|
||||
{
|
||||
std::fill_n(std::back_inserter(boneMatrices), rig->GetNodeCount(), SHMatrix::Identity);
|
||||
}
|
||||
}
|
||||
|
||||
void SHAnimatorComponent::SetClip(Handle<SHAnimationClip> newClip)
|
||||
{
|
||||
// No change
|
||||
if (currClip == newClip)
|
||||
return;
|
||||
|
||||
// Set parameters
|
||||
currClip = newClip;
|
||||
secsPerTick = 1.0f / currClip->GetTicksPerSecond();
|
||||
|
||||
// Build channel map
|
||||
channelMap.clear();
|
||||
if (currClip)
|
||||
{
|
||||
for (const auto& channel : currClip->GetChannels())
|
||||
{
|
||||
channelMap.emplace(channel.Name, &channel);
|
||||
}
|
||||
}
|
||||
|
||||
if (rig && currClip)
|
||||
{
|
||||
updatePoseWithClip(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Update Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void SHAnimatorComponent::Update(float dt)
|
||||
{
|
||||
// Nothing to animate
|
||||
if (!currClip || !isPlaying || !rig)
|
||||
return;
|
||||
|
||||
// Update time on the playback
|
||||
currPlaybackTime += dt;
|
||||
if (currPlaybackTime > currClip->GetTotalTime())
|
||||
{
|
||||
currPlaybackTime = currPlaybackTime - currClip->GetTotalTime();
|
||||
}
|
||||
|
||||
// Reset all matrices
|
||||
for (auto& mat : boneMatrices)
|
||||
{
|
||||
mat = SHMatrix::Identity;
|
||||
}
|
||||
|
||||
// Play the clip
|
||||
updatePoseWithClip(currPlaybackTime);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void SHAnimatorComponent::updatePoseWithClip(float poseTime)
|
||||
{
|
||||
// Get closest frame index
|
||||
const int CLOSEST_FRAME_IDX = static_cast<int>(std::floorf(poseTime * currClip->GetTicksPerSecond()));
|
||||
updatePoseWithClip(CLOSEST_FRAME_IDX, poseTime, rig->GetRootNode(), SHMatrix::Identity);
|
||||
}
|
||||
|
||||
void SHAnimatorComponent::updatePoseWithClip(int closestFrameIndex, float poseTime, Handle<SHRigNode> node, const SHMatrix& parentMatrix)
|
||||
{
|
||||
// Check if there is a channel for this node
|
||||
const std::string& BONE_NAME = rig->GetName(node);
|
||||
SHMatrix transformMatrix = node->TransformMatrix;
|
||||
if (channelMap.contains(BONE_NAME))
|
||||
{
|
||||
const auto CHANNEL = channelMap[BONE_NAME];
|
||||
transformMatrix = SHMatrix::Transform
|
||||
(
|
||||
getInterpolatedValue(CHANNEL->PositionKeyFrames, closestFrameIndex, poseTime),
|
||||
getInterpolatedValue(CHANNEL->RotationKeyFrames, closestFrameIndex, poseTime),
|
||||
getInterpolatedValue(CHANNEL->ScaleKeyFrames, closestFrameIndex, poseTime)
|
||||
);
|
||||
}
|
||||
|
||||
// Apply parent's transformation
|
||||
transformMatrix = transformMatrix * parentMatrix;
|
||||
|
||||
// Apply transformations to this node
|
||||
const int BONE_MTX_IDX = rig->GetNodeIndex(node);
|
||||
std::optional<SHVec3> position;
|
||||
if (BONE_MTX_IDX >= 0)
|
||||
{
|
||||
boneMatrices[BONE_MTX_IDX] = node->OffsetMatrix * transformMatrix;
|
||||
}
|
||||
|
||||
// Apply pose to children
|
||||
for (auto& child : node->Children)
|
||||
{
|
||||
updatePoseWithClip(closestFrameIndex, poseTime, child, transformMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
/* RTTR Registration */
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
RTTR_REGISTRATION
|
||||
{
|
||||
using namespace SHADE;
|
||||
using namespace rttr;
|
||||
|
||||
registration::class_<SHAnimatorComponent>("Animator Component");
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHAnimatorComponent.h
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 20, 2022
|
||||
\brief Contains the definition of the SHAnimatorComponent class and related
|
||||
types.
|
||||
|
||||
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 <vector>
|
||||
// External Dependencies
|
||||
#include <rttr/registration>
|
||||
// Project Includes
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "Math/Vector/SHVec3.h"
|
||||
#include "Math/SHQuaternion.h"
|
||||
#include "SHAnimationClip.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
class SHRig;
|
||||
struct SHRigNode;
|
||||
class SHAnimationClip;
|
||||
class SHVkBuffer;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Component that holds and controls the animation related properties of a skinned
|
||||
/// mesh.
|
||||
/// </summary>
|
||||
class SH_API SHAnimatorComponent final : public SHComponent
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Plays the currently loaded animation from the last time.
|
||||
/// </summary>
|
||||
void Play();
|
||||
/// <summary>
|
||||
/// Plays the specified animation clip from the start.
|
||||
/// </summary>
|
||||
/// <param name="clip"></param>
|
||||
void Play(Handle<SHAnimationClip> clip);
|
||||
/// <summary>
|
||||
/// Plays the currently loaded animation clip from the start.
|
||||
/// </summary>
|
||||
void PlayFromStart();
|
||||
/// <summary>
|
||||
/// Pauses the animation at the current time.
|
||||
/// </summary>
|
||||
void Pause();
|
||||
/// <summary>
|
||||
/// Stops the animation and resets the play time back to 0.
|
||||
/// </summary>
|
||||
void Stop();
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Setter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Sets the animation rig for this animator.
|
||||
/// </summary>
|
||||
/// <param name="newRig">Rig to use.</param>
|
||||
void SetRig(Handle<SHRig> newRig);
|
||||
/// <summary>
|
||||
/// Sets the animation clip of this animator without playing it.
|
||||
/// This will set the pose of the model to it's initial pose.
|
||||
/// If the clip is the same as the current clip, nothing happens.
|
||||
/// </summary>
|
||||
/// <param name="newClip">Clip to use.</param>
|
||||
void SetClip(Handle<SHAnimationClip> newClip);
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Retrieves all the bone matrices of this animator.
|
||||
/// </summary>
|
||||
/// <returns>Reference to a vector of the bone matrices.</returns>
|
||||
const std::vector<SHMatrix>& GetBoneMatrices() const noexcept { return boneMatrices; }
|
||||
/// <summary>
|
||||
/// Retrieve the currently set model rig.
|
||||
/// </summary>
|
||||
/// <returns>Handle to the currently set rig.</returns>
|
||||
Handle<SHRig> GetRig() const noexcept { return rig; }
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Retrieve the currently set animation clip.
|
||||
/// </summary>
|
||||
/// <returns>Handle to the currently set animation clip.</returns>
|
||||
Handle<SHAnimationClip> GetCurrentClip() const noexcept { return currClip; }
|
||||
/// <summary>
|
||||
/// Checks if an animation is currently playing.
|
||||
/// </summary>
|
||||
/// <returns>True if an animation clip is currently playing.</returns>
|
||||
bool IsPlaying() const { return isPlaying; }
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Update Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Updates the current state of the animation if one is specified based on the
|
||||
/// current animation clip and frames. This will update the bone matrices.
|
||||
/// </summary>
|
||||
/// <param name="dt">Time passed since the last frame.</param>
|
||||
void Update(float dt);
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
// Resources
|
||||
Handle<SHRig> rig;
|
||||
Handle<SHAnimationClip> currClip;
|
||||
// Playback Tracking
|
||||
float currPlaybackTime = 0.0f;
|
||||
bool isPlaying = true;
|
||||
// Useful Cached Data
|
||||
float secsPerTick = 0.0f;
|
||||
// Buffer
|
||||
std::vector<SHMatrix> boneMatrices;
|
||||
// Caches
|
||||
std::unordered_map<std::string, const SHAnimationClip::Channel*> channelMap;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void updatePoseWithClip(float poseTime);
|
||||
void updatePoseWithClip(int closestFrameIndex, float poseTime, Handle<SHRigNode> node, const SHMatrix& parentMatrix);
|
||||
template<typename T>
|
||||
T getInterpolatedValue(const std::vector<SHAnimationKeyFrame<T>>& keyframes, int closestFrameIndex, float poseTime);
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* RTTR */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
RTTR_ENABLE()
|
||||
};
|
||||
}
|
||||
|
||||
#include "SHAnimatorComponent.hpp"
|
|
@ -0,0 +1,82 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHAnimatorComponent.hpp
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Jan 10, 2023
|
||||
\brief Contains the definition of function templates of the SHAnimatorComponent
|
||||
Component class.
|
||||
|
||||
Copyright (C) 2023 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.
|
||||
*//*************************************************************************************/
|
||||
// Primary Include
|
||||
#include "SHAnimatorComponent.h"
|
||||
// Project Includes
|
||||
#include "SHRig.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "SHAnimationClip.h"
|
||||
#include "Graphics/SHVkUtil.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
template<typename T>
|
||||
T SHAnimatorComponent::getInterpolatedValue(const std::vector<SHAnimationKeyFrame<T>>& keyframes, int closestFrameIndex, float poseTime)
|
||||
{
|
||||
// Only allow SHVec3 and SHQuaternion
|
||||
static_assert(std::is_same_v<T, SHVec3> || std::is_same_v<T, SHQuaternion>, "Only interpolation for SHVec3 and SHQuaternion is allowed.");
|
||||
|
||||
// Find the key frames that surround the current frame index
|
||||
auto firstKeyFrame = keyframes.end();
|
||||
auto nextKeyFrame = keyframes.end();
|
||||
for (auto iter = keyframes.begin(); iter != keyframes.end(); ++iter)
|
||||
{
|
||||
const auto& KEYFRAME = *iter;
|
||||
|
||||
if (KEYFRAME.FrameIndex <= closestFrameIndex)
|
||||
{
|
||||
firstKeyFrame = iter;
|
||||
}
|
||||
else // KEYFRAME.FrameIndex > closestFrameIndex
|
||||
{
|
||||
nextKeyFrame = iter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Edge Cases
|
||||
if (firstKeyFrame == keyframes.end())
|
||||
{
|
||||
// No keyframes at all, means no changes
|
||||
if (nextKeyFrame == keyframes.end())
|
||||
return T();
|
||||
// Out of range, clamp to the back
|
||||
else
|
||||
return nextKeyFrame->Data;
|
||||
}
|
||||
// At the back, so no keyframes will follow
|
||||
else if (nextKeyFrame == keyframes.end())
|
||||
{
|
||||
return firstKeyFrame->Data;
|
||||
}
|
||||
|
||||
// Get interpolated vector
|
||||
const float PREV_FRAME_TIME = firstKeyFrame->FrameIndex * secsPerTick;
|
||||
const float NEXT_FRAME_TIME = nextKeyFrame->FrameIndex * secsPerTick;
|
||||
const float NORMALISED_TIME = (poseTime - PREV_FRAME_TIME) / (NEXT_FRAME_TIME - PREV_FRAME_TIME);
|
||||
|
||||
if constexpr (std::is_same_v<T, SHQuaternion>)
|
||||
{
|
||||
return SHQuaternion::Slerp(firstKeyFrame->Data, nextKeyFrame->Data, NORMALISED_TIME);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, SHVec3>)
|
||||
{
|
||||
return SHVec3::Lerp(firstKeyFrame->Data, nextKeyFrame->Data, NORMALISED_TIME);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHRig.cpp
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 20, 2022
|
||||
\brief Contains the function definitions of the SHRig 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.
|
||||
*//*************************************************************************************/
|
||||
// Pre-compiled Header
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "SHRig.h"
|
||||
// STL Includes
|
||||
#include <stack>
|
||||
// Project Headers
|
||||
#include "Assets/Asset Types/Models/SHRigAsset.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHRig::SHRig(const SHRigAsset& asset, SHResourceLibrary<SHRigNode>& nodeStore)
|
||||
{
|
||||
// Don't bother if empty
|
||||
if (asset.root == nullptr)
|
||||
{
|
||||
SHLOG_ERROR("[SHRig] Attempted to load an invalid rig with no root.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Do a recursive depth first traversal to populate the rig
|
||||
rootNode = recurseCreateNode(asset, asset.root, nodeStore);
|
||||
if (rootNode)
|
||||
{
|
||||
globalInverseMatrix = SHMatrix::Inverse(rootNode->TransformMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
SHRig::SHRig(SHRig&& rhs)
|
||||
: rootNode { rhs.rootNode }
|
||||
, nodeNames { std::move(rhs.nodeNames) }
|
||||
, nodesByName { std::move(rhs.nodesByName) }
|
||||
, nodes { std::move(rhs.nodes) }
|
||||
, nodeIndexMap { std::move(rhs.nodeIndexMap) }
|
||||
, globalInverseMatrix { std::move(rhs.globalInverseMatrix) }
|
||||
{
|
||||
rhs.rootNode = {};
|
||||
}
|
||||
SHRig::~SHRig()
|
||||
{
|
||||
// Unload all nodes
|
||||
for (auto node : nodes)
|
||||
{
|
||||
if (node)
|
||||
node.Free();
|
||||
}
|
||||
nodes.clear();
|
||||
}
|
||||
|
||||
SHRig& SHRig::operator=(SHRig&& rhs)
|
||||
{
|
||||
rootNode = rhs.rootNode;
|
||||
nodeNames = std::move(rhs.nodeNames);
|
||||
nodesByName = std::move(rhs.nodesByName);
|
||||
nodes = std::move(rhs.nodes);
|
||||
nodeIndexMap = std::move(rhs.nodeIndexMap);
|
||||
globalInverseMatrix = std::move(rhs.globalInverseMatrix);
|
||||
|
||||
rhs.rootNode = {};
|
||||
|
||||
return *this;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
const std::string& SHRig::GetName(Handle<SHRigNode> node) const noexcept
|
||||
{
|
||||
static const std::string EMPTY_STRING = "";
|
||||
|
||||
if (nodeNames.contains(node))
|
||||
return nodeNames.at(node);
|
||||
|
||||
return EMPTY_STRING;
|
||||
}
|
||||
|
||||
Handle<SHRigNode> SHRig::GetNode(const std::string& name) const noexcept
|
||||
{
|
||||
if (nodesByName.contains(name))
|
||||
return nodesByName.at(name);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
int SHRig::GetNodeCount() const noexcept
|
||||
{
|
||||
return static_cast<int>(nodes.size());
|
||||
}
|
||||
|
||||
int SHRig::GetNodeIndex(Handle<SHRigNode> node) const noexcept
|
||||
{
|
||||
if (nodeIndexMap.contains(node))
|
||||
{
|
||||
return nodeIndexMap.at(node);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
Handle<SHRigNode> SHRig::recurseCreateNode(const SHRigAsset& asset, const SHRigNodeAsset* sourceNode, SHResourceLibrary<SHRigNode>& nodeStore)
|
||||
{
|
||||
// Construct the node
|
||||
auto newNode = nodeStore.Create();
|
||||
|
||||
// Fill the node with data
|
||||
const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef);
|
||||
newNode->OffsetMatrix = SHMatrix::Transpose(NODE_DATA.offset);
|
||||
newNode->TransformMatrix = SHMatrix::Transpose(NODE_DATA.transform);
|
||||
|
||||
// Populate maps
|
||||
if (!NODE_DATA.name.empty())
|
||||
{
|
||||
nodeNames.emplace(newNode, NODE_DATA.name);
|
||||
nodesByName.emplace(NODE_DATA.name, newNode);
|
||||
}
|
||||
nodeIndexMap.emplace(newNode, sourceNode->idRef);
|
||||
nodes.emplace_back(newNode);
|
||||
|
||||
// Fill child nodes
|
||||
for (const auto& child : sourceNode->children)
|
||||
{
|
||||
// Ignore nulls
|
||||
if (child == nullptr)
|
||||
continue;
|
||||
|
||||
// Recursively create children
|
||||
auto childNode = recurseCreateNode(asset, child, nodeStore); // Not sure why this works but it is required for
|
||||
newNode->Children.emplace_back(childNode); // the emplace_back operation to not crash
|
||||
}
|
||||
|
||||
return newNode;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHRig.h
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 20, 2022
|
||||
\brief Contains the definition of the SHRig struct and related types.
|
||||
|
||||
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 <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
// Project Includes
|
||||
#include "SH_API.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "Resource/SHResourceLibrary.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
struct SHRigAsset;
|
||||
struct SHRigNodeAsset;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
struct SHRigNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Matrix that performs a transformation from local space to bone (node) space.
|
||||
/// </summary>
|
||||
SHMatrix OffsetMatrix;
|
||||
/// <summary>
|
||||
/// Matrix that performs a transformation from bone (node) space to local space.
|
||||
/// </summary>
|
||||
SHMatrix TransformMatrix;
|
||||
/// <summary>
|
||||
/// Child nodes of this node.
|
||||
/// </summary>
|
||||
std::vector<Handle<SHRigNode>> Children;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Represents an animation skeletal rig for a model.
|
||||
/// </summary>
|
||||
class SH_API SHRig
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructs a rig from a SHRigAsset.
|
||||
/// </summary>
|
||||
/// <param name="asset">
|
||||
/// SHRigAsset to load.
|
||||
/// </param>
|
||||
/// <param name="nodeStore">
|
||||
/// Reference to a ResourceLibrary to use to create the rig's nodes.
|
||||
/// </param>
|
||||
explicit SHRig(const SHRigAsset& asset, SHResourceLibrary<SHRigNode>& nodeStore);
|
||||
/// <summary>
|
||||
/// Move Constructor
|
||||
/// </summary>
|
||||
/// <param name="rhs>SHRig to move from.</param>
|
||||
SHRig(SHRig&& rhs);
|
||||
/// <summary>
|
||||
/// Default destructor.
|
||||
/// </summary>
|
||||
~SHRig();
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Operator Overloads */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Move assignment operator.
|
||||
/// </summary>
|
||||
/// <param name="rhs>SHRig to move from.</param>
|
||||
/// <returns>Reference to this object.</returns>
|
||||
SHRig& operator=(SHRig&& rhs);
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Retrieves the name of a node.
|
||||
/// </summary>
|
||||
/// <param name="node">Node to get the name of.</param>
|
||||
/// <returns>
|
||||
/// Name of the node. If it does not have a name or is invalid, an empty string will
|
||||
/// be provided.
|
||||
/// </returns>
|
||||
const std::string& GetName(Handle<SHRigNode> node) const noexcept;
|
||||
/// <summary>
|
||||
/// Retrieves the root node of the rig.
|
||||
/// </summary>
|
||||
/// <returns>Handle to the root node of the rig.</returns>
|
||||
Handle<SHRigNode> GetRootNode() const noexcept { return rootNode; }
|
||||
const SHMatrix& GetGlobalInverseMatrix() const noexcept { return globalInverseMatrix; }
|
||||
/// <summary>
|
||||
/// Retrieves a node via name.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the node to retrieve.</param>
|
||||
/// <returns>
|
||||
/// Node with the specified name. If it does not have a name or is invalid, an empty
|
||||
/// handle will be provided.
|
||||
/// </returns>
|
||||
Handle<SHRigNode> GetNode(const std::string& name) const noexcept;
|
||||
/// <summary>
|
||||
/// Returns the number of nodes in the rig. This matches the number of bone matrices
|
||||
/// needed.
|
||||
/// </summary>
|
||||
int GetNodeCount() const noexcept;
|
||||
/// <summary>
|
||||
/// Retrieves the index in the node storage.
|
||||
/// </summary>
|
||||
int GetNodeIndex(Handle<SHRigNode> node) const noexcept;
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<SHRigNode> rootNode;
|
||||
std::unordered_map<Handle<SHRigNode>, std::string> nodeNames;
|
||||
std::unordered_map<std::string, Handle<SHRigNode>> nodesByName;
|
||||
std::vector<Handle<SHRigNode>> nodes;
|
||||
std::unordered_map<Handle<SHRigNode>, int> nodeIndexMap;
|
||||
SHMatrix globalInverseMatrix;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<SHRigNode> recurseCreateNode(const SHRigAsset& asset, const SHRigNodeAsset* sourceNode, SHResourceLibrary<SHRigNode>& nodeStore);
|
||||
};
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHAnimationAsset.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date October 2022
|
||||
* \brief
|
||||
*
|
||||
* 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 "Math/SHMath.h"
|
||||
#include "Assets/Asset Types/SHAssetData.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
enum class SHAnimationBehaviour : uint8_t
|
||||
{
|
||||
DEFAULT = 0x0,
|
||||
CONSTANT = 0x1,
|
||||
LINEAR = 0x2,
|
||||
REPEAT = 0x3
|
||||
};
|
||||
|
||||
// Smallest data containers
|
||||
struct PositionKey
|
||||
{
|
||||
float time;
|
||||
SHVec3 value;
|
||||
};
|
||||
|
||||
struct RotationKey
|
||||
{
|
||||
float time;
|
||||
SHVec4 value;
|
||||
};
|
||||
|
||||
struct ScaleKey
|
||||
{
|
||||
float time;
|
||||
SHVec3 value;
|
||||
};
|
||||
|
||||
// Headers for read/write
|
||||
struct SHAnimNodeInfo
|
||||
{
|
||||
uint32_t charCount;
|
||||
uint32_t posKeyCount;
|
||||
uint32_t rotKeyCount;
|
||||
uint32_t scaKeyCount;
|
||||
};
|
||||
|
||||
struct SHAnimDataHeader
|
||||
{
|
||||
uint32_t charCount;
|
||||
uint32_t animNodeCount;
|
||||
std::vector<SHAnimNodeInfo> nodeHeaders;
|
||||
};
|
||||
|
||||
// Main data containers
|
||||
struct SHAnimData
|
||||
{
|
||||
std::string name;
|
||||
SHAnimationBehaviour pre;
|
||||
SHAnimationBehaviour post;
|
||||
|
||||
std::vector<PositionKey> positionKeys;
|
||||
std::vector<RotationKey> rotationKeys;
|
||||
std::vector<ScaleKey> scaleKeys;
|
||||
|
||||
};
|
||||
|
||||
struct SH_API SHAnimAsset : SHAssetData
|
||||
{
|
||||
std::string name;
|
||||
|
||||
double duration;
|
||||
double ticksPerSecond;
|
||||
|
||||
std::vector<SHAnimData> nodeChannels;
|
||||
//std::vector<aiMeshAnim*> meshChannels;
|
||||
//std::vector<aiMeshMorphAnim*> morphMeshChannels;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/******************************************************************************
|
||||
* \file SHMeshAsset.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 19 November 2022
|
||||
* \brief
|
||||
*
|
||||
* \copyright Copyright (c) 2021 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 "Math/SHMath.h"
|
||||
#include "Assets/Asset Types/SHAssetData.h"
|
||||
#include "Math/Vector/SHVec4U.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
constexpr int BONE_INDEX_ALIGHTMENT = 4;
|
||||
|
||||
struct SHMeshDataHeader
|
||||
{
|
||||
uint32_t vertexCount;
|
||||
uint32_t indexCount;
|
||||
uint32_t charCount;
|
||||
uint32_t boneCount;
|
||||
};
|
||||
|
||||
struct MeshBoneInfo
|
||||
{
|
||||
uint32_t charCount;
|
||||
uint32_t weightCount; // Size should be same as boneCount
|
||||
};
|
||||
|
||||
struct BoneWeight
|
||||
{
|
||||
uint32_t index;
|
||||
float weight;
|
||||
};
|
||||
|
||||
struct MeshBone
|
||||
{
|
||||
std::string name;
|
||||
SHMatrix offset;
|
||||
std::vector<BoneWeight> weights;
|
||||
};
|
||||
|
||||
struct SH_API SHMeshAsset : SHAssetData
|
||||
{
|
||||
std::string name;
|
||||
std::vector<SHVec3> VertexPositions;
|
||||
std::vector<SHVec3> VertexTangents;
|
||||
std::vector<SHVec3> VertexNormals;
|
||||
std::vector<SHVec2> VertexTexCoords;
|
||||
std::vector<uint32_t> Indices;
|
||||
std::vector<SHVec4U> VertexBoneIndices;
|
||||
std::vector<SHVec4> VertexBoneWeights;
|
||||
uint32_t BoneCount;
|
||||
};
|
||||
}
|
|
@ -13,36 +13,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "Math/SHMath.h"
|
||||
#include "SHAssetData.h"
|
||||
|
||||
#include "Assets/Asset Types/Models/SHAnimationAsset.h"
|
||||
#include "Assets/Asset Types/Models/SHMeshAsset.h"
|
||||
#include "Assets/Asset Types/Models/SHRigAsset.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHMeshAssetHeader
|
||||
{
|
||||
uint32_t vertexCount;
|
||||
uint32_t indexCount;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct SHModelAssetHeader
|
||||
{
|
||||
size_t meshCount;
|
||||
};
|
||||
|
||||
struct SH_API SHMeshData : SHAssetData
|
||||
{
|
||||
SHMeshAssetHeader header;
|
||||
std::vector<SHVec3> VertexPositions;
|
||||
std::vector<SHVec3> VertexTangents;
|
||||
std::vector<SHVec3> VertexNormals;
|
||||
std::vector<SHVec2> VertexTexCoords;
|
||||
std::vector<uint32_t> Indices;
|
||||
size_t animCount;
|
||||
};
|
||||
|
||||
struct SH_API SHModelAsset : SHAssetData
|
||||
{
|
||||
SHModelAssetHeader header;
|
||||
std::vector<SHMeshData*> subMeshes;
|
||||
SHRigAsset rig;
|
||||
|
||||
std::vector<SHMeshDataHeader> meshHeaders;
|
||||
std::vector<SHAnimDataHeader> animHeaders;
|
||||
|
||||
std::vector<SHMeshAsset*> meshes;
|
||||
std::vector<SHAnimAsset*> anims;
|
||||
};
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHRigAsset.h"
|
||||
|
||||
#include <queue>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
SHRigAsset::~SHRigAsset()
|
||||
{
|
||||
if (root != nullptr)
|
||||
delete[] root;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/******************************************************************************
|
||||
* \file SHRigAsset.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date 19 November 2022
|
||||
* \brief
|
||||
*
|
||||
* \copyright Copyright (c) 2021 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 "Math/SHMath.h"
|
||||
#include "Assets/Asset Types/SHAssetData.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SHRigDataHeader
|
||||
{
|
||||
uint32_t nodeCount;
|
||||
std::vector<uint32_t> charCounts;
|
||||
};
|
||||
|
||||
struct SHRigNodeData
|
||||
{
|
||||
std::string name;
|
||||
SHMatrix transform;
|
||||
SHMatrix offset;
|
||||
};
|
||||
|
||||
struct SHRigNodeAsset
|
||||
{
|
||||
uint32_t idRef;
|
||||
std::vector<SHRigNodeAsset*> children;
|
||||
};
|
||||
|
||||
struct SH_API SHRigAsset : SHAssetData
|
||||
{
|
||||
~SHRigAsset();
|
||||
|
||||
SHRigDataHeader header;
|
||||
std::vector<SHRigNodeData> nodeDataCollection;
|
||||
SHRigNodeAsset* root;
|
||||
};
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*************************************************************************//**
|
||||
* \file SHAnimationAsset.h
|
||||
* \author Loh Xiao Qi
|
||||
* \date October 2022
|
||||
* \brief
|
||||
*
|
||||
* 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 <vector>
|
||||
#include <assimp/anim.h>
|
||||
#include "SHAssetData.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
struct SH_API SHAnimationAsset : SHAssetData
|
||||
{
|
||||
std::string name;
|
||||
|
||||
std::vector<aiNodeAnim*> nodeChannels;
|
||||
std::vector<aiMeshAnim*> meshChannels;
|
||||
std::vector<aiMeshMorphAnim*> morphMeshChannels;
|
||||
|
||||
double duration;
|
||||
double ticksPerSecond;
|
||||
};
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
#include "SHModelAsset.h"
|
||||
#include "Models/SHModelAsset.h"
|
||||
#include "SHTextureAsset.h"
|
|
@ -13,73 +13,321 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHModelLoader.h"
|
||||
#include <fstream>
|
||||
#include <queue>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
void SHModelLoader::ReadHeader(std::ifstream& file, SHMeshLoaderHeader& header) noexcept
|
||||
void SHModelLoader::ReadHeaders(FileReference file, SHModelAsset& asset)
|
||||
{
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&header),
|
||||
sizeof(SHMeshLoaderHeader)
|
||||
reinterpret_cast<char*>(&asset.header),
|
||||
sizeof(asset.header)
|
||||
);
|
||||
|
||||
if (asset.header.meshCount > 0)
|
||||
{
|
||||
asset.meshHeaders.resize(asset.header.meshCount);
|
||||
file.read(
|
||||
reinterpret_cast<char*>(asset.meshHeaders.data()),
|
||||
asset.header.meshCount * sizeof(SHMeshDataHeader)
|
||||
);
|
||||
}
|
||||
|
||||
void SHModelLoader::ReadData(std::ifstream& file, SHMeshLoaderHeader const& header, SHMeshData& data) noexcept
|
||||
if (asset.header.animCount > 0)
|
||||
{
|
||||
asset.animHeaders.resize(asset.header.animCount);
|
||||
for (auto i {0}; i < asset.header.animCount; ++i)
|
||||
{
|
||||
auto& animHeader = asset.animHeaders[i];
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&animHeader.charCount),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&animHeader.animNodeCount),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
animHeader.nodeHeaders.resize(animHeader.animNodeCount);
|
||||
for (auto j {0}; j < animHeader.animNodeCount; ++j)
|
||||
{
|
||||
auto& nodeHeader = animHeader.nodeHeaders[j];
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&nodeHeader),
|
||||
sizeof(SHAnimNodeInfo)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SHModelLoader::ReadData(FileReference file, SHModelAsset& asset)
|
||||
{
|
||||
ReadMeshData(file, asset.meshHeaders, asset.meshes);
|
||||
ReadAnimData(file, asset.animHeaders, asset.anims);
|
||||
|
||||
// Not eof yet, animation exists
|
||||
if (file.peek() != EOF)
|
||||
{
|
||||
ReadRigHeader(file, asset.rig.header);
|
||||
ReadRigData(file, asset.rig.header, asset.rig.nodeDataCollection);
|
||||
ReadRigTree(file, asset.rig.header, asset.rig.root);
|
||||
}
|
||||
}
|
||||
|
||||
void SHModelLoader::ReadAnimNode(FileReference file, SHAnimNodeInfo const& info, SHAnimData& data)
|
||||
{
|
||||
data.name.resize(info.charCount);
|
||||
file.read(
|
||||
data.name.data(),
|
||||
info.charCount
|
||||
);
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&data.pre),
|
||||
sizeof(SHAnimationBehaviour)
|
||||
);
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&data.post),
|
||||
sizeof(SHAnimationBehaviour)
|
||||
);
|
||||
|
||||
uint32_t keySize {0};
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&keySize),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
data.positionKeys.resize(keySize);
|
||||
data.rotationKeys.resize(keySize);
|
||||
data.scaleKeys.resize(keySize);
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(data.positionKeys.data()),
|
||||
sizeof(PositionKey) * keySize
|
||||
);
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(data.rotationKeys.data()),
|
||||
sizeof(RotationKey) * keySize
|
||||
);
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(data.scaleKeys.data()),
|
||||
sizeof(ScaleKey) * keySize
|
||||
);
|
||||
}
|
||||
|
||||
void SHModelLoader::ReadRigHeader(FileReference file, SHRigDataHeader& header)
|
||||
{
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&header.nodeCount),
|
||||
sizeof(uint32_t)
|
||||
);
|
||||
|
||||
header.charCounts.resize(header.nodeCount);
|
||||
file.read(
|
||||
reinterpret_cast<char*>(header.charCounts.data()),
|
||||
sizeof(uint32_t) * header.nodeCount
|
||||
);
|
||||
}
|
||||
|
||||
void SHModelLoader::ReadRigData(FileReference file, SHRigDataHeader const& header, std::vector<SHRigNodeData>& data)
|
||||
{
|
||||
data.resize(header.nodeCount);
|
||||
|
||||
for (auto i {0}; i < header.nodeCount; ++i)
|
||||
{
|
||||
data[i].name.resize(header.charCounts[i]);
|
||||
file.read(
|
||||
data[i].name.data(),
|
||||
header.charCounts[i]
|
||||
);
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&data[i].transform),
|
||||
sizeof(SHMatrix)
|
||||
);
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&data[i].offset),
|
||||
sizeof(SHMatrix)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void SHModelLoader::ReadRigTree(FileReference file, SHRigDataHeader const& header, SHRigNodeAsset*& root)
|
||||
{
|
||||
// Read All nodes into one contiguous data block
|
||||
struct NodeTemp
|
||||
{
|
||||
uint32_t id, numChild;
|
||||
};
|
||||
|
||||
NodeTemp* dst = new NodeTemp[header.nodeCount];
|
||||
|
||||
file.read(
|
||||
reinterpret_cast<char*>(dst),
|
||||
sizeof(NodeTemp) * header.nodeCount
|
||||
);
|
||||
|
||||
// Build and populate tree
|
||||
SHRigNodeAsset* nodePool = new SHRigNodeAsset[header.nodeCount];
|
||||
root = nodePool;
|
||||
|
||||
std::queue<std::pair<SHRigNodeAsset*, NodeTemp*>> nodeQueue;
|
||||
nodeQueue.emplace(std::make_pair(nodePool, dst));
|
||||
|
||||
SHRigNodeAsset* depthPtr = nodePool + 1;
|
||||
NodeTemp* depthTempPtr = dst + 1;
|
||||
|
||||
while(!nodeQueue.empty())
|
||||
{
|
||||
auto currPair = nodeQueue.front();
|
||||
nodeQueue.pop();
|
||||
auto currNode = currPair.first;
|
||||
auto currTemp = currPair.second;
|
||||
|
||||
currNode->idRef = currTemp->id;
|
||||
|
||||
for (auto i{0}; i < currTemp->numChild; ++i)
|
||||
{
|
||||
currNode->children.push_back(depthPtr);
|
||||
nodeQueue.emplace(depthPtr++, depthTempPtr++);
|
||||
}
|
||||
}
|
||||
|
||||
delete[] dst;
|
||||
}
|
||||
|
||||
void SHModelLoader::ReadMeshData(FileReference file, std::vector<SHMeshDataHeader> const& headers,
|
||||
std::vector<SHMeshAsset*>& meshes)
|
||||
{
|
||||
meshes.resize(headers.size());
|
||||
for (auto i {0}; i < headers.size(); ++i)
|
||||
{
|
||||
auto const& header = headers[i];
|
||||
auto& data = *new SHMeshAsset;
|
||||
|
||||
auto const vertexVec3Byte{ sizeof(SHVec3) * header.vertexCount };
|
||||
auto const vertexVec2Byte{ sizeof(SHVec2) * header.vertexCount };
|
||||
|
||||
data.name.resize(header.charCount);
|
||||
data.VertexPositions.resize(header.vertexCount);
|
||||
data.VertexTangents.resize(header.vertexCount);
|
||||
data.VertexNormals.resize(header.vertexCount);
|
||||
data.VertexTexCoords.resize(header.vertexCount);
|
||||
data.Indices.resize(header.indexCount);
|
||||
data.header.name.resize(header.charCount);
|
||||
data.BoneCount = header.boneCount;
|
||||
|
||||
file.read(data.header.name.data(), header.charCount);
|
||||
file.read(data.name.data(), header.charCount);
|
||||
file.read(reinterpret_cast<char*>(data.VertexPositions.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char*>(data.VertexTangents.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char*>(data.VertexNormals.data()), vertexVec3Byte);
|
||||
file.read(reinterpret_cast<char*>(data.VertexTexCoords.data()), vertexVec2Byte);
|
||||
file.read(reinterpret_cast<char*>(data.Indices.data()), sizeof(uint32_t) * header.indexCount);
|
||||
|
||||
data.header.vertexCount = header.vertexCount;
|
||||
data.header.indexCount = header.indexCount;
|
||||
if (header.boneCount)
|
||||
{
|
||||
std::vector<MeshBoneInfo> boneInfos(header.boneCount);
|
||||
std::vector<MeshBone> bones(header.boneCount);
|
||||
|
||||
file.read(reinterpret_cast<char*>(boneInfos.data()), sizeof(MeshBoneInfo) * header.boneCount);
|
||||
|
||||
for (auto i{ 0 }; i < header.boneCount; ++i)
|
||||
{
|
||||
auto& bone = bones[i];
|
||||
auto const& info = boneInfos[i];
|
||||
|
||||
bone.name.resize(info.charCount);
|
||||
file.read(bone.name.data(), info.charCount);
|
||||
file.read(reinterpret_cast<char*>(&bone.offset), sizeof(SHMatrix));
|
||||
|
||||
bone.weights.resize(info.weightCount);
|
||||
file.read(reinterpret_cast<char*>(bone.weights.data()), sizeof(BoneWeight) * info.weightCount);
|
||||
}
|
||||
|
||||
void SHModelLoader::LoadSHMesh(AssetPath path, SHModelAsset& model) noexcept
|
||||
data.VertexBoneIndices.resize(header.vertexCount);
|
||||
data.VertexBoneWeights.resize(header.vertexCount);
|
||||
|
||||
for (uint32_t boneIndex{0}; boneIndex < bones.size(); ++boneIndex)
|
||||
{
|
||||
std::ifstream file{ path.string(), std::ios::in | std::ios::binary };
|
||||
if (!file.is_open())
|
||||
auto const& bone = bones[boneIndex];
|
||||
for (auto const& weight : bone.weights)
|
||||
{
|
||||
SHLOG_ERROR("[Model Loader] Unable to open SHModel File: {}", path.string());
|
||||
return;
|
||||
auto& boneIndices = data.VertexBoneIndices[weight.index];
|
||||
auto& boneWeight = data.VertexBoneWeights[weight.index];
|
||||
|
||||
for (auto j{0}; j < BONE_INDEX_ALIGHTMENT; ++j)
|
||||
{
|
||||
if (boneWeight[j] == 0.f)
|
||||
{
|
||||
boneIndices[j] = boneIndex;
|
||||
boneWeight[j] = weight.weight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file.seekg(0);
|
||||
meshes[i] = &data;
|
||||
}
|
||||
}
|
||||
|
||||
void SHModelLoader::ReadAnimData(FileReference file, std::vector<SHAnimDataHeader> const& headers,
|
||||
std::vector<SHAnimAsset*>& anims)
|
||||
{
|
||||
anims.resize(headers.size());
|
||||
for (auto i {0}; i < headers.size(); ++i)
|
||||
{
|
||||
auto const& header = headers[i];
|
||||
auto& animAsset = *new SHAnimAsset;
|
||||
|
||||
animAsset.name.resize(header.charCount);
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&model.header),
|
||||
sizeof(SHModelAssetHeader)
|
||||
animAsset.name.data(),
|
||||
header.charCount
|
||||
);
|
||||
|
||||
std::vector<SHMeshLoaderHeader> headers(model.header.meshCount);
|
||||
model.subMeshes.resize(model.header.meshCount);
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&animAsset.duration),
|
||||
sizeof(double)
|
||||
);
|
||||
|
||||
for (auto i{ 0 }; i < model.header.meshCount; ++i)
|
||||
file.read(
|
||||
reinterpret_cast<char*>(&animAsset.ticksPerSecond),
|
||||
sizeof(double)
|
||||
);
|
||||
|
||||
animAsset.nodeChannels.resize(header.animNodeCount);
|
||||
for (auto i {0}; i < header.animNodeCount; ++i)
|
||||
{
|
||||
model.subMeshes[i] = new SHMeshData();
|
||||
ReadHeader(file, headers[i]);
|
||||
ReadData(file, headers[i], *model.subMeshes[i]);
|
||||
ReadAnimNode(file, header.nodeHeaders[i], animAsset.nodeChannels[i]);
|
||||
}
|
||||
|
||||
anims[i] = &animAsset;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
SHAssetData* SHModelLoader::Load(AssetPath path)
|
||||
{
|
||||
auto result = new SHModelAsset();
|
||||
|
||||
LoadSHMesh(path, *result);
|
||||
std::ifstream file{ path.string(), std::ios::in | std::ios::binary };
|
||||
if (!file.is_open())
|
||||
{
|
||||
SHLOG_ERROR("[Model Loader] Unable to open SHModel File: {}", path.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ReadHeaders(file, *result);
|
||||
ReadData(file, *result);
|
||||
|
||||
file.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* of DigiPen Institute of Technology is prohibited.
|
||||
*****************************************************************************/
|
||||
#pragma once
|
||||
#include "Assets/Asset Types/SHModelAsset.h"
|
||||
#include "Assets/Asset Types/Models/SHModelAsset.h"
|
||||
#include "SHAssetLoader.h"
|
||||
#include <fstream>
|
||||
|
||||
|
@ -18,19 +18,20 @@ namespace SHADE
|
|||
{
|
||||
class SHModelLoader : public SHAssetLoader
|
||||
{
|
||||
struct SHMeshLoaderHeader
|
||||
{
|
||||
uint32_t vertexCount;
|
||||
uint32_t indexCount;
|
||||
uint32_t charCount;
|
||||
};
|
||||
using FileReference = std::ifstream&;
|
||||
|
||||
void ReadAnimNode(FileReference file, SHAnimNodeInfo const& info, SHAnimData& data);
|
||||
|
||||
void ReadHeader(std::ifstream& file, SHMeshLoaderHeader& header) noexcept;
|
||||
void ReadData(std::ifstream& file, SHMeshLoaderHeader const& header, SHMeshData& data) noexcept;
|
||||
void ReadRigHeader(FileReference file, SHRigDataHeader& header);
|
||||
void ReadRigData(FileReference file, SHRigDataHeader const& header, std::vector<SHRigNodeData>& data);
|
||||
void ReadRigTree(FileReference file, SHRigDataHeader const& header, SHRigNodeAsset*& root);
|
||||
|
||||
void ReadMeshData(FileReference file, std::vector<SHMeshDataHeader> const& headers, std::vector<SHMeshAsset*>& meshes);
|
||||
void ReadAnimData(FileReference file, std::vector<SHAnimDataHeader> const& headers, std::vector<SHAnimAsset*>& anims);
|
||||
|
||||
void ReadHeaders(FileReference file, SHModelAsset& asset);
|
||||
void ReadData(FileReference file, SHModelAsset& asset);
|
||||
public:
|
||||
void LoadSHMesh(AssetPath path, SHModelAsset& model) noexcept;
|
||||
SHAssetData* Load(AssetPath path) override;
|
||||
void Write(SHAssetData const* data, AssetPath path) override;
|
||||
};
|
||||
|
|
|
@ -492,8 +492,8 @@ namespace SHADE
|
|||
****************************************************************************/
|
||||
void SHAssetManager::Load() noexcept
|
||||
{
|
||||
BuildAssetCollection();
|
||||
InitLoaders();
|
||||
BuildAssetCollection();
|
||||
//CompileAll();
|
||||
//LoadAllData();
|
||||
}
|
||||
|
@ -549,7 +549,7 @@ namespace SHADE
|
|||
{
|
||||
assetData.emplace(
|
||||
parent.subAssets[i]->id,
|
||||
parentModel->subMeshes[i]
|
||||
parentModel->meshes[i]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -607,10 +607,10 @@ namespace SHADE
|
|||
|
||||
SHModelAsset* const data = reinterpret_cast<SHModelAsset*>(LoadData(newAsset));
|
||||
assetData.emplace(newAsset.id, data);
|
||||
for(auto const& subMesh : data->subMeshes)
|
||||
for(auto const& subMesh : data->meshes)
|
||||
{
|
||||
SHAsset subAsset{
|
||||
.name = subMesh->header.name,
|
||||
.name = subMesh->name,
|
||||
.id = GenerateAssetID(AssetType::MESH),
|
||||
.type = AssetType::MESH,
|
||||
.isSubAsset = true,
|
||||
|
|
|
@ -6,6 +6,11 @@ namespace SHADE
|
|||
template<typename T>
|
||||
std::enable_if_t<std::is_base_of_v<SHAssetData, T>, T* const> SHAssetManager::GetData(AssetID id) noexcept
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!assetData.contains(id))
|
||||
{
|
||||
for (auto const& asset : std::ranges::views::values(assetCollection))
|
||||
|
|
|
@ -125,14 +125,29 @@ namespace SHADE
|
|||
SHTransformComponent* listenerTransform = SHComponentManager::GetComponent_s<SHTransformComponent>(listener.GetEID());
|
||||
if (listenerTransform)
|
||||
{
|
||||
listener.SetPos(listenerTransform->GetLocalPosition());
|
||||
listener.SetForward({ (listenerTransform->GetLocalScale()[0] > 0.f) ? 1.f : -1.f, 0.f, 0.f });
|
||||
listener.SetPos(listenerTransform->GetWorldPosition()); // TODO: Clean up listener
|
||||
listener.SetForward({ (listenerTransform->GetLocalScale()[0] > 0.f) ? 1.f : -1.f, 0.f, 0.f }); //TODO: USE CORRECT FORWARD
|
||||
FMOD_VECTOR pos = { listener.pos[0] ,listener.pos[1] ,0.f };
|
||||
FMOD_VECTOR forward = { listener.forward[0] ,listener.forward[1] ,listener.forward[2] };
|
||||
FMOD_VECTOR up = { listener.up[0] ,listener.up[1] ,listener.up[2] };
|
||||
fmodSystem->set3DListenerAttributes(0, &pos, nullptr, &forward, &up);
|
||||
}
|
||||
}
|
||||
|
||||
auto [begin, end] = audioClipLibrary.GetDenseAccess();
|
||||
for(auto it = begin; it != end; ++it)
|
||||
{
|
||||
if(it->instance && (it->transformRef != MAX_EID))
|
||||
{
|
||||
if(SHTransformComponent* transformComponent = SHComponentManager::GetComponent_s<SHTransformComponent>(it->transformRef))
|
||||
{
|
||||
FMOD_3D_ATTRIBUTES attribs{}; //TODO: Set other attribs
|
||||
auto pos = transformComponent->GetWorldPosition();
|
||||
attribs.position = {pos.x, pos.y, pos.z};
|
||||
it->instance->set3DAttributes(&attribs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SHAudioSystem::AudioRoutine::AudioRoutine()
|
||||
|
@ -325,27 +340,83 @@ namespace SHADE
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
AudioClip* SHAudioSystem::CreateAudioClip(const char* path)
|
||||
Handle<AudioClip> SHAudioSystem::CreateAudioClip(const char* path)
|
||||
{
|
||||
AudioClipID newID{};
|
||||
AudioClip* clip = nullptr;
|
||||
auto it = eventMap.find(path);
|
||||
if (it != eventMap.end())
|
||||
Handle<AudioClip> audioClipHandle{};
|
||||
|
||||
if(auto it = eventMap.find(path); it != eventMap.end())
|
||||
{
|
||||
FMOD::Studio::EventInstance* event = nullptr;
|
||||
it->second->createInstance(&event);
|
||||
if (event)
|
||||
audioClipHandle = audioClipLibrary.Create();
|
||||
it->second->createInstance(&audioClipHandle->instance);
|
||||
}
|
||||
|
||||
return audioClipHandle;
|
||||
}
|
||||
|
||||
void SHAudioSystem::AddAudioClipToBGMChannelGroup(Handle<AudioClip> handle)
|
||||
{
|
||||
//event->start();
|
||||
newID = clipID;
|
||||
clipID++;
|
||||
eventInstances.emplace(newID, AudioClip(newID, event));
|
||||
clip = &eventInstances[newID];
|
||||
if(!handle->instance)
|
||||
return;
|
||||
FMOD::ChannelGroup* channelGroup;
|
||||
handle->instance->getChannelGroup(&channelGroup);
|
||||
|
||||
if(!channelGroup)
|
||||
{
|
||||
SHLOG_ERROR("Event instance has no channel group")
|
||||
return;
|
||||
}
|
||||
bgmChannelGroup->addGroup(channelGroup);
|
||||
}
|
||||
|
||||
void SHAudioSystem::AddAudioClipToSFXChannelGroup(Handle<AudioClip> handle)
|
||||
{
|
||||
if (!handle->instance)
|
||||
return;
|
||||
FMOD::ChannelGroup* channelGroup;
|
||||
handle->instance->getChannelGroup(&channelGroup);
|
||||
|
||||
if (!channelGroup)
|
||||
{
|
||||
SHLOG_ERROR("Event instance has no channel group")
|
||||
return;
|
||||
}
|
||||
sfxChannelGroup->addGroup(channelGroup);
|
||||
}
|
||||
|
||||
void SHAudioSystem::AttachAudioClipToObject(Handle<AudioClip> handle, EntityID eid)
|
||||
{
|
||||
if (auto transform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
|
||||
{
|
||||
handle->transformRef = eid;
|
||||
}
|
||||
}
|
||||
return clip;
|
||||
|
||||
void SHAudioSystem::DetachAudioClipFromObject(Handle<AudioClip> handle)
|
||||
{
|
||||
handle->transformRef = MAX_EID;
|
||||
}
|
||||
|
||||
//AudioClip* SHAudioSystem::CreateAudioClip(const char* path)
|
||||
//{
|
||||
// AudioClipID newID{};
|
||||
// AudioClip* clip = nullptr;
|
||||
// auto it = eventMap.find(path);
|
||||
// if (it != eventMap.end())
|
||||
// {
|
||||
// FMOD::Studio::EventInstance* event = nullptr;
|
||||
// it->second->createInstance(&event);
|
||||
// if (event)
|
||||
// {
|
||||
// //event->start();
|
||||
// newID = clipID;
|
||||
// clipID++;
|
||||
// eventInstances.emplace(newID, AudioClip(newID, event));
|
||||
// clip = &eventInstances[newID];
|
||||
// }
|
||||
// }
|
||||
// return clip;
|
||||
//}
|
||||
|
||||
//std::vector<const char*> SHAudioSystem::GetAllEvents()
|
||||
//{
|
||||
// int count{};
|
||||
|
@ -489,41 +560,39 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
AudioClip::AudioClip(AudioClipID clipID, FMOD::Studio::EventInstance* inst)
|
||||
:instance(inst), id(clipID)
|
||||
{
|
||||
}
|
||||
|
||||
AudioClip::~AudioClip()
|
||||
{
|
||||
}
|
||||
|
||||
void AudioClip::Play(bool isSfx)
|
||||
void AudioClip::Play()
|
||||
{
|
||||
if(!instance)
|
||||
return;
|
||||
instance->start();
|
||||
auto audioSystem = SHSystemManager::GetSystem<SHADE::SHAudioSystem>();
|
||||
instance->setVolume(audioSystem->GetMasterVolume() * (isSfx ? audioSystem->GetSfxVolume() : audioSystem->GetBgmVolume()));
|
||||
}
|
||||
|
||||
void AudioClip::Play(SHVec3 position, bool isSfx)
|
||||
{
|
||||
if (!instance)
|
||||
return;
|
||||
instance->start();
|
||||
FMOD_3D_ATTRIBUTES attributes{ {} };
|
||||
attributes.forward.z = 1.0f;
|
||||
attributes.up.y = 1.0f;
|
||||
//void AudioClip::Play(bool isSfx)
|
||||
//{
|
||||
// if (!instance)
|
||||
// return;
|
||||
// instance->start();
|
||||
// auto audioSystem = SHSystemManager::GetSystem<SHADE::SHAudioSystem>();
|
||||
// instance->setVolume(audioSystem->GetMasterVolume() * (isSfx ? audioSystem->GetSfxVolume() : audioSystem->GetBgmVolume()));
|
||||
//}
|
||||
|
||||
auto audioSystem = SHSystemManager::GetSystem<SHADE::SHAudioSystem>();
|
||||
SHVec3 listenerPos = audioSystem->GetListenerPosition();
|
||||
attributes.position.x = position[0];
|
||||
attributes.position.y = position[1];
|
||||
attributes.position.z = listenerPos[2];
|
||||
instance->set3DAttributes(&attributes);
|
||||
instance->setVolume(audioSystem->GetMasterVolume() * (isSfx ? audioSystem->GetSfxVolume() : audioSystem->GetBgmVolume()));
|
||||
}
|
||||
//void AudioClip::Play(SHVec3 position, bool isSfx)
|
||||
//{
|
||||
// if (!instance)
|
||||
// return;
|
||||
// instance->start();
|
||||
// FMOD_3D_ATTRIBUTES attributes{ {} };
|
||||
// attributes.forward.z = 1.0f;
|
||||
// attributes.up.y = 1.0f;
|
||||
|
||||
// auto audioSystem = SHSystemManager::GetSystem<SHADE::SHAudioSystem>();
|
||||
// SHVec3 listenerPos = audioSystem->GetListenerPosition();
|
||||
// attributes.position.x = position[0];
|
||||
// attributes.position.y = position[1];
|
||||
// attributes.position.z = listenerPos[2];
|
||||
// instance->set3DAttributes(&attributes);
|
||||
// instance->setVolume(audioSystem->GetMasterVolume() * (isSfx ? audioSystem->GetSfxVolume() : audioSystem->GetBgmVolume()));
|
||||
//}
|
||||
|
||||
void AudioClip::Stop(bool fadeOut)
|
||||
{
|
||||
|
@ -557,12 +626,12 @@ namespace SHADE
|
|||
instance->setParameterByName(paramName, value);
|
||||
}
|
||||
|
||||
void AudioClip::SetParameterLabel(const char* paramName, const char* label)
|
||||
{
|
||||
if (!instance)
|
||||
return;
|
||||
instance->setParameterByNameWithLabel(paramName, label);
|
||||
}
|
||||
//void AudioClip::SetParameterLabel(const char* paramName, const char* label)
|
||||
//{
|
||||
// if (!instance)
|
||||
// return;
|
||||
// instance->setParameterByNameWithLabel(paramName, label);
|
||||
//}
|
||||
|
||||
float AudioClip::GetParameterValue(const char* paramName)
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "Events/SHEvent.h"
|
||||
|
||||
#include "SH_API.h"
|
||||
#include <Resource/SHResourceLibrary.h>
|
||||
#define AUDIO_SYS_MAX_CHANNELS 1024
|
||||
|
||||
namespace SHADE
|
||||
|
@ -22,27 +23,22 @@ namespace SHADE
|
|||
|
||||
class SHAudioListenerComponent;
|
||||
|
||||
typedef uint64_t AudioClipID;
|
||||
|
||||
class AudioClip
|
||||
class SH_API AudioClip
|
||||
{
|
||||
public:
|
||||
AudioClip() = default;
|
||||
AudioClip(AudioClipID clipID, FMOD::Studio::EventInstance* inst);
|
||||
~AudioClip();
|
||||
void Play(bool isSfx = true);
|
||||
void Play(SHVec3 position, bool isSfx = true);
|
||||
void Play();
|
||||
//void Play(SHVec3 position);
|
||||
void Stop(bool fadeOut = true);
|
||||
|
||||
void SetPause(bool pause);
|
||||
bool IsPaused();
|
||||
void SetParameter(const char* paramName, float value);
|
||||
void SetParameterLabel(const char* paramName, const char* label);
|
||||
//void SetParameterLabel(const char* paramName, const char* label);
|
||||
float GetParameterValue(const char* paramName);
|
||||
friend class SHAudioSystem;
|
||||
private:
|
||||
FMOD::Studio::EventInstance* instance;
|
||||
AudioClipID id;
|
||||
FMOD::Studio::EventInstance* instance = nullptr;
|
||||
EntityID transformRef = MAX_EID;
|
||||
};
|
||||
|
||||
class SH_API SHAudioSystem : public SHSystem
|
||||
|
@ -62,7 +58,7 @@ namespace SHADE
|
|||
void Exit();
|
||||
|
||||
int GetAvailableChannelIndex();
|
||||
/*std::vector<SHSound>::size_type CreateSound(const char* filepath, bool loop = false);*/
|
||||
|
||||
void PlaySFX(EntityID id, EntityID eid, const bool& loop, const bool& spatial, float min = 5.0f, float max = 1000.0f);
|
||||
void PlayBGM(EntityID id, EntityID eid, const bool& loop, const bool& spatial, float min = 5.0f, float max = 1000.0f);
|
||||
void PlayEventOnce(const char* path, bool isSFX = true, EntityID eid = MAX_EID, bool spatial = false);
|
||||
|
@ -71,9 +67,15 @@ namespace SHADE
|
|||
void StopAllSounds();
|
||||
|
||||
std::optional<FMOD_GUID> GetEventGUID(const char* path);
|
||||
AudioClip* CreateAudioClip(const char* path);
|
||||
//std::vector<const char*> GetAllEvents();
|
||||
//AudioClip* CreateAudioClip(const char* path);
|
||||
//AUDIO CLIP
|
||||
Handle<AudioClip> CreateAudioClip(const char* path);
|
||||
void AddAudioClipToBGMChannelGroup(Handle<AudioClip> handle);
|
||||
void AddAudioClipToSFXChannelGroup(Handle<AudioClip> handle);
|
||||
|
||||
void AttachAudioClipToObject(Handle<AudioClip> handle, EntityID eid);
|
||||
void DetachAudioClipFromObject(Handle<AudioClip> handle);
|
||||
///
|
||||
float GetBgmVolume();
|
||||
float GetSfxVolume();
|
||||
float GetMasterVolume();
|
||||
|
@ -84,6 +86,7 @@ namespace SHADE
|
|||
bool GetPaused() const;
|
||||
SHVec3 GetListenerPosition();
|
||||
void LoadBank(const char* path);
|
||||
|
||||
private:
|
||||
FMOD::Studio::System* fmodStudioSystem;
|
||||
FMOD::System* fmodSystem;
|
||||
|
@ -95,7 +98,9 @@ namespace SHADE
|
|||
//std::unordered_map<ResourceID, SHBank> bankMap;
|
||||
std::unordered_map<std::string, SHBank> bankMap;
|
||||
std::unordered_map<std::string, FMOD::Studio::EventDescription*> eventMap;
|
||||
std::unordered_map<AudioClipID, AudioClip> eventInstances;
|
||||
//std::unordered_map<AudioClipID, AudioClip> eventInstances;
|
||||
SHResourceLibrary<AudioClip> audioClipLibrary{};
|
||||
|
||||
FMOD::ChannelGroup* bgmChannelGroup, * sfxChannelGroup, * masterGroup;
|
||||
FMOD::Channel* audioChannels[AUDIO_SYS_MAX_CHANNELS];
|
||||
FMOD_RESULT result;
|
||||
|
@ -105,7 +110,6 @@ namespace SHADE
|
|||
SHBank masterBank, stringsBank, musicBank, sfxBank; //To do: change to map of banks loaded by resource manager
|
||||
|
||||
std::vector<SHAudioListenerComponent>* denseListener;
|
||||
AudioClipID clipID = 0;
|
||||
|
||||
SHEventHandle onPlay(SHEventPtr onStopEvent);
|
||||
SHEventHandle onStop(SHEventPtr onStopEvent);
|
||||
|
|
|
@ -57,9 +57,13 @@ namespace SHADE
|
|||
skipFrame = false;
|
||||
return;
|
||||
}
|
||||
DrawMenuBar();
|
||||
auto const& sceneGraph = SHSceneManager::GetCurrentSceneGraph();
|
||||
|
||||
DrawMenuBar();
|
||||
if(wasFilterChanged && !filter.empty())
|
||||
{
|
||||
filterHighlightedEntities.clear();
|
||||
filterOpenEntities.clear();
|
||||
}
|
||||
if (const auto root = sceneGraph.GetRoot())
|
||||
{
|
||||
auto const& children = root->GetChildren();
|
||||
|
@ -67,7 +71,13 @@ namespace SHADE
|
|||
for (const auto child : children)
|
||||
{
|
||||
if (child)
|
||||
{
|
||||
if(wasFilterChanged && !filter.empty())
|
||||
{
|
||||
EntityFilterCheck(child);
|
||||
}
|
||||
RecursivelyDrawEntityNode(child);
|
||||
}
|
||||
if (skipFrame)
|
||||
{
|
||||
ImGui::End();
|
||||
|
@ -177,9 +187,10 @@ namespace SHADE
|
|||
|
||||
void SHHierarchyPanel::DrawHierarchyPanelFilter() noexcept
|
||||
{
|
||||
wasFilterChanged = false;
|
||||
if(ImGui::InputTextWithHint("##hierarchyPanelFilter", "Filter", &filter))
|
||||
{
|
||||
|
||||
wasFilterChanged = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("x"))
|
||||
|
@ -204,24 +215,65 @@ namespace SHADE
|
|||
{
|
||||
result |= SHComponentManager::HasComponent<SHTransformComponent>(eid);
|
||||
}
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHColliderComponent>().get_name().data(), filter) != std::string::npos;
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHRigidBodyComponent>().get_name().data(), filter) != std::string::npos;
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHCameraComponent>().get_name().data(), filter) != std::string::npos;
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHCameraArmComponent>().get_name().data(), filter) != std::string::npos;
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHRenderable>().get_name().data(), filter) != std::string::npos;
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHLightComponent>().get_name().data(), filter) != std::string::npos;
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHTextRenderableComponent>().get_name().data(), filter) != std::string::npos;
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHUIComponent>().get_name().data(), filter) != std::string::npos;
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHButtonComponent>().get_name().data(), filter) != std::string::npos;
|
||||
//result |= SHStringUtilities::StringFindInsensitive(rttr::type::get<SHCanvasComponent>().get_name().data(), filter) != std::string::npos;
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHColliderComponent>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHColliderComponent>(eid);
|
||||
}
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHRigidBodyComponent>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHRigidBodyComponent>(eid);
|
||||
}
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHCameraComponent>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHCameraComponent>(eid);
|
||||
}
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHCameraArmComponent>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHCameraArmComponent>(eid);
|
||||
}
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHRenderable>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHRenderable>(eid);
|
||||
}
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHLightComponent>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHLightComponent>(eid);
|
||||
}
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHTextRenderableComponent>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHTextRenderableComponent>(eid);
|
||||
}
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHUIComponent>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHUIComponent>(eid);
|
||||
}
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHButtonComponent>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHButtonComponent>(eid);
|
||||
}
|
||||
if(SHStringUtilities::StringFindInsensitive(rttr::type::get<SHCanvasComponent>().get_name().data(), filter) != std::string::npos)
|
||||
{
|
||||
result |= SHComponentManager::HasComponent<SHCanvasComponent>(eid);
|
||||
}
|
||||
|
||||
//std::vector<SHSceneNode*> const& children = entityNode->GetChildren();
|
||||
if(result)
|
||||
{
|
||||
filterHighlightedEntities.push_back(eid);
|
||||
}
|
||||
|
||||
//for (auto const& child : children)
|
||||
//{
|
||||
// result |= EntityFilterCheck(child);
|
||||
//}
|
||||
std::vector<SHSceneNode*> const& children = entityNode->GetChildren();
|
||||
|
||||
bool open = false;
|
||||
for (auto const& child : children)
|
||||
{
|
||||
open |= EntityFilterCheck(child);
|
||||
}
|
||||
result |= open;
|
||||
|
||||
if(open)
|
||||
{
|
||||
filterOpenEntities.push_back(eid);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -245,31 +297,27 @@ namespace SHADE
|
|||
|
||||
const bool isSelected = (std::ranges::find(editor->selectedEntities, eid) != editor->selectedEntities.end());
|
||||
|
||||
bool highlighted = false;
|
||||
//if(!filter.empty())
|
||||
//{
|
||||
// highlighted = EntityFilterCheck(currentNode);
|
||||
// if (highlighted)
|
||||
// {
|
||||
// ImGui::PushStyleColor(ImGuiCol_Text, highlightedColor);
|
||||
//
|
||||
// ImGui::SetNextItemOpen(true);
|
||||
//
|
||||
//
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//}
|
||||
bool highlighted = false, open = false;
|
||||
if(!filter.empty())
|
||||
{
|
||||
highlighted = (std::ranges::find(filterHighlightedEntities, eid) != filterHighlightedEntities.end());
|
||||
if(open = std::ranges::find(filterOpenEntities, eid) != filterOpenEntities.end())
|
||||
{
|
||||
ImGui::SetNextItemOpen(true);
|
||||
}
|
||||
|
||||
if(!open && !highlighted)
|
||||
{
|
||||
return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
|
||||
}
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, highlighted ? highlightedColor : ImVec4(0.5f, 0.5f, 0.5f, 1.f ));
|
||||
}
|
||||
|
||||
const ImGuiTreeNodeFlags nodeFlags = ((isSelected) ? ImGuiTreeNodeFlags_Selected : 0) | ((children.empty()) ? ImGuiTreeNodeFlags_Leaf : ImGuiTreeNodeFlags_OpenOnArrow);
|
||||
|
||||
|
||||
//Draw Node
|
||||
bool isNodeOpen = ImGui::TreeNodeEx(reinterpret_cast<void*>(eid), nodeFlags, "%u: %s", SHEntityManager::GetEntityIndex(eid), entity->name.c_str());
|
||||
|
||||
if (highlighted)
|
||||
if(!filter.empty())
|
||||
{
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
|
|
@ -44,7 +44,8 @@ namespace SHADE
|
|||
std::string filter;
|
||||
bool isAnyNodeSelected = false;
|
||||
EntityID scrollTo = MAX_EID;
|
||||
std::vector<EntityID> draggingEntities;
|
||||
std::vector<EntityID> draggingEntities, filterOpenEntities, filterHighlightedEntities;
|
||||
bool wasFilterChanged = false;
|
||||
|
||||
};//class SHHierarchyPanel
|
||||
|
||||
|
|
|
@ -0,0 +1,546 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHInputBindingsPanel.h"
|
||||
#include "Input/SHInputManager.h"
|
||||
#include "Editor/SHEditorWidgets.hpp"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
//Vectors containing data for elements for different bindings
|
||||
static std::vector<std::string> bindingRenames;
|
||||
|
||||
//Flags to prevent unwanted editing of bindings
|
||||
static size_t positiveKeyListeningFor;
|
||||
static bool positiveKeyListening;
|
||||
|
||||
static size_t negativeKeyListeningFor;
|
||||
static bool negativeKeyListening;
|
||||
|
||||
static size_t positiveControllerListeningFor;
|
||||
static bool positiveControllerListening;
|
||||
|
||||
static size_t negativeControllerListeningFor;
|
||||
static bool negativeControllerListening;
|
||||
|
||||
//Internal Helper function
|
||||
void resizeVectors(size_t newSize)
|
||||
{
|
||||
bindingRenames.resize(newSize);
|
||||
for (auto& s : bindingRenames)
|
||||
s.clear();
|
||||
}
|
||||
|
||||
//Internal Helper function
|
||||
std::string labelConcat(char const* label, size_t entryNumber)
|
||||
{
|
||||
std::string concat = label;
|
||||
concat += std::to_string(entryNumber);
|
||||
return concat;
|
||||
}
|
||||
|
||||
void SHInputBindingsPanel::Init()
|
||||
{
|
||||
SHEditorWindow::Init();
|
||||
}
|
||||
|
||||
void SHInputBindingsPanel::Update()
|
||||
{
|
||||
if (SHEditorWindow::Begin())
|
||||
{
|
||||
//ImGui::ShowDemoWindow();
|
||||
|
||||
//Binding count
|
||||
ImGui::Text("Binding Count: %d", SHInputManager::CountBindings());
|
||||
|
||||
//Binding file name
|
||||
static std::string bindingFileName;
|
||||
ImGui::InputText("Binding File Path", &bindingFileName);
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text(".SHConfig will be appeneded to file name");
|
||||
ImGui::Text("If no name is provided, saves to or loads from \"Assets/Bindings.SHConfig\"");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
//Save bindings to...
|
||||
if (ImGui::Button("Save Bindings"))
|
||||
{
|
||||
if (bindingFileName.empty())
|
||||
{
|
||||
SHInputManager::SaveBindings();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string filePath = std::string(ASSET_ROOT);
|
||||
filePath += "/";
|
||||
filePath += bindingFileName;
|
||||
filePath += ".SHConfig";
|
||||
SHInputManager::SaveBindings(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
//Load bindings from...
|
||||
if (ImGui::Button("Load Bindings"))
|
||||
{
|
||||
if (bindingFileName.empty())
|
||||
{
|
||||
SHInputManager::LoadBindings();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string filePath = std::string(ASSET_ROOT);
|
||||
filePath += "/";
|
||||
filePath += bindingFileName;
|
||||
filePath += ".SHConfig";
|
||||
SHInputManager::LoadBindings(filePath);
|
||||
}
|
||||
resizeVectors(SHInputManager::CountBindings());
|
||||
}
|
||||
|
||||
//Button to add new binding
|
||||
if (ImGui::Button("Add New Binding"))
|
||||
{
|
||||
std::string newBindingName = "Binding" + std::to_string(SHInputManager::CountBindings());
|
||||
SHInputManager::AddBinding(newBindingName);
|
||||
resizeVectors(SHInputManager::CountBindings());
|
||||
}
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("Add a new binding to the list");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
//Ensure unique label for entries
|
||||
size_t entryNumber = 0;
|
||||
|
||||
//Listing for each binding
|
||||
for (auto& binding : SHInputManager::GetBindings())
|
||||
{
|
||||
if (ImGui::CollapsingHeader(binding.first.c_str()))
|
||||
{
|
||||
//Modifiable binding name
|
||||
ImGui::Text("Binding Name: %s", binding.first.c_str());
|
||||
ImGui::InputText(labelConcat("##bindingModifyName", entryNumber).c_str(), &bindingRenames[entryNumber]);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(labelConcat("Rename##bindingRename", entryNumber).c_str()))
|
||||
{
|
||||
SHInputManager::RenameBinding(binding.first, bindingRenames[entryNumber]);
|
||||
bindingRenames[entryNumber].clear();
|
||||
}
|
||||
|
||||
if (ImGui::Button(labelConcat("Delete Binding##", entryNumber).c_str()))
|
||||
{
|
||||
SHInputManager::RemoveBinding(binding.first);
|
||||
resizeVectors(SHInputManager::CountBindings());
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("Delete this binding from the list");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
//Binding value test
|
||||
ImGui::BeginDisabled();
|
||||
float val = SHInputManager::GetBindingAxis(binding.first);
|
||||
ImGui::SliderFloat(labelConcat("Value##", entryNumber).c_str(), &val, -1.0f, 1.0f);
|
||||
ImGui::EndDisabled();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("Test the current value of the binding");
|
||||
ImGui::Text("For mouse movement/wheel inputs, will be multiplied by Sensitivity, with 0 being neutral (no input detected)");
|
||||
ImGui::Text("Between -1 and 1 for other inputs, with 0 still being neutral (no input detected)");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
ImGui::BeginDisabled();
|
||||
float rawVal = SHInputManager::GetBindingAxisRaw(binding.first);
|
||||
ImGui::SliderFloat(labelConcat("Raw Value##", entryNumber).c_str(), &rawVal, -1.0f, 1.0f);
|
||||
ImGui::EndDisabled();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("Test the current value of the binding");
|
||||
ImGui::Text("Raw value means it will be fixed among -1, 0 and 1 for non-mouse movement/wheel inputs");
|
||||
ImGui::Text("No difference between this and Value for mouse movement/wheel inputs");
|
||||
ImGui::Text("But for other inputs, does not consider smoothing options such as gravity and sensitivity");
|
||||
ImGui::Text("If both positive and negative input is detected, returns neutral 0");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
//Binding Type Combo Box
|
||||
int bindingType = static_cast<int>(SHInputManager::GetBindingType(binding.first));
|
||||
if (ImGui::Combo(labelConcat("Input Type##", entryNumber).c_str(), &bindingType, "Keyboard / Mouse Buttons / Controller\0Mouse Horizontal\0Mouse Vertical\0Mouse Scroll Wheel"))
|
||||
SHInputManager::SetBindingType(binding.first, static_cast<SHInputManager::SH_BINDINGTYPE>(bindingType));
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("Which of the four types the binding uses");
|
||||
ImGui::Text("Keyboard / Mouse Buttons / Controller = Keys, mouse buttons and ALL controller inputs");
|
||||
ImGui::Text("Mouse Horizontal = Horizontal movement of the mouse");
|
||||
ImGui::Text("Mouse Vertical = Vertical movement of the mouse");
|
||||
ImGui::Text("Mouse Scroll Wheel = The scroll wheel found at the middle of most mouses");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
//Inversion
|
||||
bool bindingInvert = SHInputManager::GetBindingInverted(binding.first);
|
||||
if (ImGui::Checkbox(labelConcat("Inverted##", entryNumber).c_str(), &bindingInvert))
|
||||
SHInputManager::SetBindingInverted(binding.first, bindingInvert);
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("If inverted:");
|
||||
ImGui::Text("Positive inputs mean negative value of the binding");
|
||||
ImGui::Text("Negative inputs mean positive value of the binding");
|
||||
ImGui::Text("Mouse moving up / right means negative value of the binding");
|
||||
ImGui::Text("Scrolling the mouse wheel up means negative value of the binding");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
//Sensitivity
|
||||
double bindingSensitivity = SHInputManager::GetBindingSensitivity(binding.first);
|
||||
if (ImGui::InputDouble(labelConcat("Sensitivity##", entryNumber).c_str(), &bindingSensitivity))
|
||||
SHInputManager::SetBindingSensitivity(binding.first, bindingSensitivity);
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("Value multiplier for mouse movement and scrolling");
|
||||
ImGui::Text("For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative");
|
||||
//ImGui::Text("For other analog inputs, serves as a multiplier, but axis value magnitude will still be capped at 1");
|
||||
ImGui::Text("Irrelevant for other analog inputs");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
//Below this section is only for KB/M type bindings
|
||||
//Not relevant for mouse movement and scrolling
|
||||
if (SHInputManager::GetBindingType(binding.first) == SHInputManager::SH_BINDINGTYPE::KB_MB_CONTROLLER)
|
||||
{
|
||||
//Dead
|
||||
float bindingDead = static_cast<float>(SHInputManager::GetBindingDead(binding.first));
|
||||
if (ImGui::SliderFloat(labelConcat("Deadzone##", entryNumber).c_str(), &bindingDead, 0.0f, 1.0f))
|
||||
SHInputManager::SetBindingDead(binding.first, static_cast<double>(bindingDead));
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("Any positive or negative analog input with magnitude less than this will be registered as neutral");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
//Gravity
|
||||
double bindingGravity = SHInputManager::GetBindingGravity(binding.first);
|
||||
if (ImGui::InputDouble(labelConcat("Gravity##", entryNumber).c_str(), &bindingGravity))
|
||||
SHInputManager::SetBindingGravity(binding.first, static_cast<double>(bindingGravity));
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("The rate at which the value moves to neutral if no input in the direction is read");
|
||||
ImGui::TextColored(ImVec4{ 1.0f, 0.5f, 0.5f, 1.0f }, "Should be non-negative");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
//Snap
|
||||
bool bindingSnap = SHInputManager::GetBindingSnap(binding.first);
|
||||
if (ImGui::Checkbox(labelConcat("Snap##", entryNumber).c_str(), &bindingSnap))
|
||||
SHInputManager::SetBindingSnap(binding.first, bindingSnap);
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("If no other input on the axis is present and a input is made in the opposite direction of the current value,");
|
||||
ImGui::Text("the binding's value will jump to neutral 0 before resuming in the input direction");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
size_t keycodeIndex = 0;
|
||||
//Positive key codes
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Positive Key Codes:");
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("When this keyboard or mouse button is held, causes the value to go positive, or negative when inverted");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
//Button to ask for inputs
|
||||
if (!positiveKeyListening)
|
||||
{
|
||||
if (ImGui::Button(labelConcat("New##positiveKeyCode", entryNumber).c_str()))
|
||||
{
|
||||
positiveKeyListening = true;
|
||||
positiveKeyListeningFor = entryNumber;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (positiveKeyListeningFor == entryNumber)
|
||||
{
|
||||
//Listening for inputs
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.4f, 0.4f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0.5f, 0.5f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.6f, 0.3f, 0.3f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
ImGui::Button(labelConcat("PRESS##positiveKeyCode", entryNumber).c_str());
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
SHInputManager::SH_KEYCODE k;
|
||||
if (SHInputManager::AnyKey(&k))
|
||||
{
|
||||
positiveKeyListening = false;
|
||||
SHInputManager::AddBindingPositiveKeyCode(binding.first, k);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Not listening
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button(labelConcat("New##positiveKeyCode", entryNumber).c_str());
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
//List and remove bindings
|
||||
ImGui::Indent();
|
||||
keycodeIndex = 0;
|
||||
for (auto& k : binding.second.positiveKeyCodes)
|
||||
{
|
||||
//ImGui::Text("%d", static_cast<int>(k));
|
||||
ImGui::Text(SHInputManager::GetKeyCodeName(k).c_str());
|
||||
ImGui::SameLine();
|
||||
std::string labelString = "X##KeyPositive";
|
||||
labelString += binding.first;
|
||||
|
||||
//Delete button
|
||||
if (ImGui::SmallButton(labelConcat(labelString.c_str(), keycodeIndex).c_str()))
|
||||
{
|
||||
SHInputManager::RemoveBindingPositiveKeyCode(binding.first, k);
|
||||
break;
|
||||
}
|
||||
++keycodeIndex;
|
||||
}
|
||||
ImGui::Unindent();
|
||||
|
||||
|
||||
//Negative key codes
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Negative Key Codes:");
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("When this keyboard or mouse button is held, causes the value to go negative, or positive when inverted");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
//Button to ask for inputs
|
||||
if (!negativeKeyListening)
|
||||
{
|
||||
if (ImGui::Button(labelConcat("New##negativeKeyCode", entryNumber).c_str()))
|
||||
{
|
||||
negativeKeyListening = true;
|
||||
negativeKeyListeningFor = entryNumber;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (negativeKeyListeningFor == entryNumber)
|
||||
{
|
||||
//Listening for inputs
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.4f, 0.4f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0.5f, 0.5f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.6f, 0.3f, 0.3f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
ImGui::Button(labelConcat("PRESS##negativeKeyCode", entryNumber).c_str());
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
SHInputManager::SH_KEYCODE k;
|
||||
if (SHInputManager::AnyKey(&k))
|
||||
{
|
||||
negativeKeyListening = false;
|
||||
SHInputManager::AddBindingNegativeKeyCode(binding.first, k);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Not listening
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button(labelConcat("New##negativeKeyCode", entryNumber).c_str());
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
//List and remove bindings
|
||||
ImGui::Indent();
|
||||
keycodeIndex = 0;
|
||||
for (auto& k : binding.second.negativeKeyCodes)
|
||||
{
|
||||
//ImGui::Text("%d", static_cast<int>(k));
|
||||
ImGui::Text(SHInputManager::GetKeyCodeName(k).c_str());
|
||||
ImGui::SameLine();
|
||||
std::string labelString = "X##KeyNegative";
|
||||
labelString += binding.first;
|
||||
|
||||
//Delete button
|
||||
if (ImGui::SmallButton(labelConcat(labelString.c_str(), keycodeIndex).c_str()))
|
||||
{
|
||||
SHInputManager::RemoveBindingNegativeKeyCode(binding.first, k);
|
||||
break;
|
||||
}
|
||||
++keycodeIndex;
|
||||
}
|
||||
ImGui::Unindent();
|
||||
|
||||
//Positive controller codes
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Positive Controller Codes:");
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("When this controller button is held, causes the value to go positive, or negative when inverted");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
//Button to ask for inputs
|
||||
if (!positiveControllerListening)
|
||||
{
|
||||
if (ImGui::Button(labelConcat("New##positiveControllerCode", entryNumber).c_str()))
|
||||
{
|
||||
positiveControllerListening = true;
|
||||
positiveControllerListeningFor = entryNumber;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (positiveControllerListeningFor == entryNumber)
|
||||
{
|
||||
//Listening for inputs
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.4f, 0.4f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0.5f, 0.5f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.6f, 0.3f, 0.3f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
ImGui::Button(labelConcat("PRESS##positiveControllerCode", entryNumber).c_str());
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
SHInputManager::SH_CONTROLLERCODE c;
|
||||
if (SHInputManager::AnyControllerInput(&c))
|
||||
{
|
||||
positiveControllerListening = false;
|
||||
SHInputManager::AddBindingPositiveControllerCode(binding.first, c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Not listening
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button(labelConcat("New##positiveControllerCode", entryNumber).c_str());
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
//List and remove bindings
|
||||
ImGui::Indent();
|
||||
keycodeIndex = 0;
|
||||
for (auto& c : binding.second.positiveControllerCodes)
|
||||
{
|
||||
//ImGui::Text("%d", static_cast<int>(k));
|
||||
ImGui::Text(SHInputManager::GetControllerCodeName(c).c_str());
|
||||
ImGui::SameLine();
|
||||
std::string labelString = "X##ControllerPositive";
|
||||
labelString += binding.first;
|
||||
|
||||
//Delete button
|
||||
if (ImGui::SmallButton(labelConcat(labelString.c_str(), keycodeIndex).c_str()))
|
||||
{
|
||||
SHInputManager::RemoveBindingPositiveControllerCode(binding.first, c);
|
||||
break;
|
||||
}
|
||||
++keycodeIndex;
|
||||
}
|
||||
ImGui::Unindent();
|
||||
|
||||
//Negative controller codes
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Negative Controller Codes:");
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("When this controller button is pressed, causes the value to go negative, or positive when inverted");
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
//Button to ask for inputs
|
||||
if (!negativeControllerListening)
|
||||
{
|
||||
if (ImGui::Button(labelConcat("New##negativeControllerCode", entryNumber).c_str()))
|
||||
{
|
||||
negativeControllerListening = true;
|
||||
negativeControllerListeningFor = entryNumber;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (negativeControllerListeningFor == entryNumber)
|
||||
{
|
||||
//Listening for inputs
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.4f, 0.4f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 0.5f, 0.5f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.6f, 0.3f, 0.3f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
ImGui::Button(labelConcat("PRESS##negativeControllerCode", entryNumber).c_str());
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
SHInputManager::SH_CONTROLLERCODE c;
|
||||
if (SHInputManager::AnyControllerInput(&c))
|
||||
{
|
||||
negativeControllerListening = false;
|
||||
SHInputManager::AddBindingNegativeControllerCode(binding.first, c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Not listening
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button(labelConcat("New##negativeControllerCode", entryNumber).c_str());
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
//List and remove bindings
|
||||
ImGui::Indent();
|
||||
keycodeIndex = 0;
|
||||
for (auto& c : binding.second.negativeControllerCodes)
|
||||
{
|
||||
//ImGui::Text("%d", static_cast<int>(k));
|
||||
ImGui::Text(SHInputManager::GetControllerCodeName(c).c_str());
|
||||
ImGui::SameLine();
|
||||
std::string labelString = "X##ControllerNegative";
|
||||
labelString += binding.first;
|
||||
|
||||
//Delete button
|
||||
if (ImGui::SmallButton(labelConcat(labelString.c_str(), keycodeIndex).c_str()))
|
||||
{
|
||||
SHInputManager::RemoveBindingNegativeControllerCode(binding.first, c);
|
||||
break;
|
||||
}
|
||||
++keycodeIndex;
|
||||
}
|
||||
ImGui::Unindent();
|
||||
}
|
||||
}
|
||||
++entryNumber; //Next entry
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void SHInputBindingsPanel::Exit()
|
||||
{
|
||||
SHEditorWindow::Exit();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "Editor/EditorWindow/SHEditorWindow.h"
|
||||
#include <imgui.h>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SH_API SHInputBindingsPanel final : public SHEditorWindow
|
||||
{
|
||||
public:
|
||||
SHInputBindingsPanel() : SHEditorWindow("Input Bindings Panel", ImGuiWindowFlags_MenuBar) {}
|
||||
|
||||
void Init() override;
|
||||
void Update() override;
|
||||
void Exit() override;
|
||||
};
|
||||
}
|
|
@ -22,6 +22,8 @@
|
|||
#include "Serialization/SHSerializationHelper.hpp"
|
||||
#include "Tools/Utilities/SHClipboardUtilities.h"
|
||||
#include "SHInspectorCommands.h"
|
||||
#include "Physics/Collision/SHCollisionTagMatrix.h"
|
||||
#include "Animation/SHAnimatorComponent.h"
|
||||
namespace SHADE
|
||||
{
|
||||
template<typename T>
|
||||
|
@ -574,4 +576,60 @@ namespace SHADE
|
|||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
template<>
|
||||
static void DrawComponent(SHAnimatorComponent* component)
|
||||
{
|
||||
if (!component)
|
||||
return;
|
||||
ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHAnimatorComponent>());
|
||||
const auto componentType = rttr::type::get(*component);
|
||||
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);
|
||||
Handle<SHRig> const& rig = component->GetRig();
|
||||
const auto RIG_NAME = rig ? SHResourceManager::GetAssetName<SHRig>(rig).value_or("") : "";
|
||||
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Rig", RIG_NAME, [component]()
|
||||
{
|
||||
Handle<SHRig> const& rig = component->GetRig();
|
||||
return SHResourceManager::GetAssetID<SHRig>(rig).value_or(0);
|
||||
},
|
||||
[component](AssetID const& id)
|
||||
{
|
||||
if (SHAssetManager::GetType(id) != AssetType::MODEL)
|
||||
{
|
||||
SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!")
|
||||
return;
|
||||
}
|
||||
component->SetRig(SHResourceManager::LoadOrGet<SHRig>(id));
|
||||
SHResourceManager::FinaliseChanges();
|
||||
}, SHDragDrop::DRAG_RESOURCE);
|
||||
|
||||
Handle<SHAnimationClip> const& clip = component->GetCurrentClip();
|
||||
const auto CLIP_NAME = clip ? SHResourceManager::GetAssetName<SHAnimationClip>(clip).value_or("") : "";
|
||||
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Clip", CLIP_NAME,
|
||||
[component]()
|
||||
{
|
||||
Handle<SHAnimationClip> const& clip = component->GetCurrentClip();
|
||||
return SHResourceManager::GetAssetID<SHAnimationClip>(clip).value_or(0);
|
||||
},
|
||||
[component](AssetID const& id)
|
||||
{
|
||||
if (SHAssetManager::GetType(id) != AssetType::MODEL)
|
||||
{
|
||||
SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!")
|
||||
return;
|
||||
}
|
||||
component->SetClip(SHResourceManager::LoadOrGet<SHAnimationClip>(id));
|
||||
}, SHDragDrop::DRAG_RESOURCE);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawContextMenu(component);
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,13 @@
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
template<typename Component>
|
||||
void EnsureComponent(EntityID eid)
|
||||
{
|
||||
if(SHComponentManager::GetComponent_s<Component>(eid) == nullptr)
|
||||
SHComponentManager::AddComponent<Component>(eid);
|
||||
}
|
||||
|
||||
template<typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
||||
bool DrawAddComponentButton(EntityID const& eid)
|
||||
{
|
||||
|
@ -49,9 +56,13 @@ namespace SHADE
|
|||
return selected;
|
||||
}
|
||||
|
||||
template <typename ComponentType, typename EnforcedComponent, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true, std::enable_if_t<std::is_base_of_v<SHComponent, EnforcedComponent>, bool> = true>
|
||||
template <typename ComponentType, typename ... EnforcedComponents>
|
||||
bool DrawAddComponentWithEnforcedComponentButton(EntityID const& eid)
|
||||
{
|
||||
// Only make sure components are passed here
|
||||
static_assert(std::is_base_of_v<SHComponent, ComponentType>, "");
|
||||
//(static_assert(std::is_base_of_v<SHComponent, EnforcedComponents>, ""), ...);
|
||||
|
||||
bool selected = false;
|
||||
if (!SHComponentManager::HasComponent<ComponentType>(eid))
|
||||
{
|
||||
|
@ -59,9 +70,8 @@ namespace SHADE
|
|||
|
||||
if(selected = ImGui::Selectable(std::format("Add {}", componentName).data()); selected)
|
||||
{
|
||||
if(SHComponentManager::GetComponent_s<EnforcedComponent>(eid) == nullptr)
|
||||
SHComponentManager::AddComponent<EnforcedComponent>(eid);
|
||||
|
||||
// Ensure that all required components are present
|
||||
(EnsureComponent<EnforcedComponents>(eid), ...);
|
||||
SHComponentManager::AddComponent<ComponentType>(eid);
|
||||
}
|
||||
if(ImGui::IsItemHovered())
|
||||
|
@ -70,9 +80,8 @@ namespace SHADE
|
|||
ImGui::Text("Adds", componentName); ImGui::SameLine();
|
||||
ImGui::TextColored(ImGuiColors::green, "%s", componentName); ImGui::SameLine();
|
||||
ImGui::Text("to this entity", componentName);
|
||||
ImGui::Text("Adds"); ImGui::SameLine();
|
||||
ImGui::TextColored(ImGuiColors::red, "%s", rttr::type::get<EnforcedComponent>().get_name().data()); ImGui::SameLine();
|
||||
ImGui::Text("if the entity does not already have it");
|
||||
ImGui::Text("Adds the following components if the entity does not already have it: ");
|
||||
(ImGui::TextColored(ImGuiColors::red, "%s", rttr::type::get<EnforcedComponents>().get_name().data()), ...);
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +127,10 @@ namespace SHADE
|
|||
{
|
||||
DrawComponent(renderableComponent);
|
||||
}
|
||||
if (auto animatorComponent = SHComponentManager::GetComponent_s<SHAnimatorComponent>(eid))
|
||||
{
|
||||
DrawComponent(animatorComponent);
|
||||
}
|
||||
if(auto colliderComponent = SHComponentManager::GetComponent_s<SHColliderComponent>(eid))
|
||||
{
|
||||
DrawComponent(colliderComponent);
|
||||
|
@ -179,6 +192,7 @@ namespace SHADE
|
|||
DrawAddComponentWithEnforcedComponentButton<SHRigidBodyComponent, SHTransformComponent>(eid);
|
||||
DrawAddComponentWithEnforcedComponentButton<SHColliderComponent, SHTransformComponent>(eid);
|
||||
DrawAddComponentWithEnforcedComponentButton<SHTextRenderableComponent, SHTransformComponent>(eid);
|
||||
DrawAddComponentWithEnforcedComponentButton<SHAnimatorComponent, SHTransformComponent, SHRenderable>(eid);
|
||||
|
||||
|
||||
ImGui::EndMenu();
|
||||
|
|
|
@ -201,8 +201,8 @@ namespace SHADE
|
|||
// Get interface for the shader combination
|
||||
auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface
|
||||
(
|
||||
mappings.at(SHPredefinedDescriptorTypes::MATERIALS),
|
||||
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA
|
||||
mappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH),
|
||||
SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA
|
||||
);
|
||||
if (!interface)
|
||||
return;
|
||||
|
|
|
@ -7,3 +7,4 @@
|
|||
#include "AssetBrowser/SHAssetBrowser.h" //Asset Browser
|
||||
#include "MaterialInspector/SHMaterialInspector.h" //Material Inspector
|
||||
#include "ColliderTagPanel/SHColliderTagPanel.h" //Collider Tag Panel
|
||||
#include "InputBindings/SHInputBindingsPanel.h" //Input Bindings
|
|
@ -106,6 +106,7 @@ namespace SHADE
|
|||
SHEditorWindowManager::CreateEditorWindow<SHMaterialInspector>();
|
||||
SHEditorWindowManager::CreateEditorWindow<SHColliderTagPanel>();
|
||||
SHEditorWindowManager::CreateEditorWindow<SHHierarchyPanel>();
|
||||
SHEditorWindowManager::CreateEditorWindow<SHInputBindingsPanel>();
|
||||
SHEditorWindowManager::CreateEditorWindow<SHEditorInspector>();
|
||||
|
||||
SHEditorWindowManager::CreateEditorWindow<SHEditorViewport>();
|
||||
|
|
|
@ -105,6 +105,12 @@ namespace SHADE
|
|||
std::vector<SHAsset> assets;
|
||||
|
||||
// Get all subfolders/files in this current folder
|
||||
if (!std::filesystem::exists(std::filesystem::path(folder->path)))
|
||||
{
|
||||
SHLOG_WARNING("[Asset Manager] Path to build directory does not exist!: {}", folder->path);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto& dirEntry : std::filesystem::directory_iterator(folder->path))
|
||||
{
|
||||
auto path = dirEntry.path();
|
||||
|
|
|
@ -29,24 +29,29 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Graphics/Descriptors/SHVkDescriptorPool.h"
|
||||
#include "Scene/SHSceneManager.h"
|
||||
#include "UI/SHUIComponent.h"
|
||||
#include "Animation/SHAnimatorComponent.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* SHBatch - Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* SHBatch - Constructors/Destructors */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHBatch::SHBatch(Handle<SHVkPipeline> pipeline)
|
||||
: pipeline{ pipeline }
|
||||
{
|
||||
if (!pipeline)
|
||||
throw std::invalid_argument("Attempted to create a SHBatch with an invalid SHPipeline!");
|
||||
|
||||
// Check the pipeline and flag it depending on whether or not it is animated
|
||||
isAnimated = checkIfIsAnimatedPipeline(pipeline);
|
||||
|
||||
// Mark all as dirty
|
||||
setAllDirtyFlags();
|
||||
}
|
||||
|
||||
SHBatch::SHBatch(SHBatch&& rhs)
|
||||
: device { rhs.device }
|
||||
, isAnimated { rhs.isAnimated }
|
||||
, pipeline { rhs.pipeline }
|
||||
, referencedMatInstances { std::move(rhs.referencedMatInstances) }
|
||||
, matBufferDirty { std::move(rhs.matBufferDirty) }
|
||||
|
@ -59,18 +64,24 @@ namespace SHADE
|
|||
, matPropsDataSize { rhs.matPropsDataSize }
|
||||
, singleMatPropAlignedSize { rhs.singleMatPropAlignedSize }
|
||||
, singleMatPropSize { rhs.singleMatPropSize }
|
||||
, boneMatrixData { std::move(rhs.boneMatrixData) }
|
||||
, boneMatrixIndices { std::move(rhs.boneMatrixIndices) }
|
||||
, isCPUBuffersDirty { rhs.isCPUBuffersDirty }
|
||||
, drawDataBuffer { rhs.drawDataBuffer }
|
||||
, transformDataBuffer { rhs.transformDataBuffer }
|
||||
, instancedIntegerBuffer { rhs.instancedIntegerBuffer }
|
||||
, matPropsBuffer { rhs.matPropsBuffer }
|
||||
, matPropsDescSet { rhs.matPropsDescSet }
|
||||
, boneMatrixBuffer { rhs.boneMatrixBuffer }
|
||||
, boneMatrixFirstIndexBuffer { rhs.boneMatrixFirstIndexBuffer }
|
||||
, instanceDataDescSet { rhs.instanceDataDescSet }
|
||||
{
|
||||
rhs.drawDataBuffer = {};
|
||||
rhs.transformDataBuffer = {};
|
||||
rhs.instancedIntegerBuffer = {};
|
||||
rhs.matPropsBuffer = {};
|
||||
rhs.matPropsDescSet = {};
|
||||
rhs.boneMatrixBuffer = {};
|
||||
rhs.boneMatrixFirstIndexBuffer = {};
|
||||
rhs.instanceDataDescSet = {};
|
||||
}
|
||||
|
||||
SHBatch& SHBatch::operator=(SHBatch&& rhs)
|
||||
|
@ -79,6 +90,7 @@ namespace SHADE
|
|||
return *this;
|
||||
|
||||
device = rhs.device ;
|
||||
isAnimated = rhs.isAnimated ;
|
||||
pipeline = rhs.pipeline ;
|
||||
referencedMatInstances = std::move(rhs.referencedMatInstances);
|
||||
matBufferDirty = std::move(rhs.matBufferDirty) ;
|
||||
|
@ -91,19 +103,25 @@ namespace SHADE
|
|||
matPropsDataSize = rhs.matPropsDataSize ;
|
||||
singleMatPropAlignedSize = rhs.singleMatPropAlignedSize ;
|
||||
singleMatPropSize = rhs.singleMatPropSize ;
|
||||
boneMatrixData = std::move(rhs.boneMatrixData) ;
|
||||
boneMatrixIndices = std::move(rhs.boneMatrixIndices) ;
|
||||
isCPUBuffersDirty = rhs.isCPUBuffersDirty ;
|
||||
drawDataBuffer = rhs.drawDataBuffer ;
|
||||
transformDataBuffer = rhs.transformDataBuffer ;
|
||||
instancedIntegerBuffer = rhs.instancedIntegerBuffer ;
|
||||
matPropsBuffer = rhs.matPropsBuffer ;
|
||||
matPropsDescSet = rhs.matPropsDescSet ;
|
||||
boneMatrixBuffer = rhs.boneMatrixBuffer ;
|
||||
boneMatrixFirstIndexBuffer = rhs.boneMatrixFirstIndexBuffer ;
|
||||
instanceDataDescSet = rhs.instanceDataDescSet ;
|
||||
|
||||
// Unset values
|
||||
rhs.drawDataBuffer = {};
|
||||
rhs.transformDataBuffer = {};
|
||||
rhs.instancedIntegerBuffer = {};
|
||||
rhs.matPropsBuffer = {};
|
||||
rhs.matPropsDescSet = {};
|
||||
rhs.boneMatrixBuffer = {};
|
||||
rhs.boneMatrixFirstIndexBuffer = {};
|
||||
rhs.instanceDataDescSet = {};
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -121,11 +139,14 @@ namespace SHADE
|
|||
instancedIntegerBuffer[i].Free();
|
||||
if (matPropsBuffer[i])
|
||||
matPropsBuffer[i].Free();
|
||||
if (matPropsDescSet[i])
|
||||
matPropsDescSet[i].Free();
|
||||
if (instanceDataDescSet[i])
|
||||
instanceDataDescSet[i].Free();
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* SHBatch - Usage Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void SHBatch::Add(const SHRenderable* renderable)
|
||||
{
|
||||
// Ignore if null
|
||||
|
@ -285,7 +306,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
// Transfer to GPU
|
||||
rebuildMaterialBuffers(frameIndex, descPool);
|
||||
rebuildDescriptorSetBuffers(frameIndex, descPool);
|
||||
|
||||
// This frame is updated
|
||||
matBufferDirty[frameIndex] = false;
|
||||
|
@ -366,14 +387,79 @@ namespace SHADE
|
|||
{
|
||||
rendId,
|
||||
renderable->GetLightLayer()
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Transfer to GPU
|
||||
if (instancedIntegerBuffer[frameIndex] && !drawData.empty())
|
||||
instancedIntegerBuffer[frameIndex]->WriteToMemory(instancedIntegerData.data(), static_cast<uint32_t>(instancedIntegerData.size() * sizeof(SHInstancedIntegerData)), 0, 0);
|
||||
}
|
||||
|
||||
void SHBatch::UpdateAnimationBuffer(uint32_t frameIndex)
|
||||
{
|
||||
// Ignore if not animated batch
|
||||
if (!isAnimated)
|
||||
return;
|
||||
|
||||
// Frame Index check
|
||||
if (frameIndex >= SHGraphicsConstants::NUM_FRAME_BUFFERS)
|
||||
{
|
||||
SHLOG_WARNING("[SHBatch] Attempted to update animation buffers with an invalid frame index.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset Animation Matrix Data
|
||||
boneMatrixData.clear();
|
||||
boneMatrixIndices.clear();
|
||||
|
||||
// Add the first identity matrix into the bone matrix data
|
||||
boneMatrixData.emplace_back(SHMatrix::Identity); // This kills the GPU
|
||||
|
||||
// Populate on the CPU
|
||||
for (auto& subBatch : subBatches)
|
||||
for (auto rendId : subBatch.Renderables)
|
||||
{
|
||||
// Get resources
|
||||
auto animator = SHComponentManager::GetComponent_s<SHAnimatorComponent>(rendId);
|
||||
auto renderable = SHComponentManager::GetComponent<SHRenderable>(rendId);
|
||||
auto mesh = renderable->GetMesh();
|
||||
|
||||
// Mark start
|
||||
boneMatrixIndices.emplace_back(static_cast<uint32_t>(boneMatrixData.size()));
|
||||
|
||||
// Add matrices
|
||||
const int BONE_COUNT = static_cast<int>(mesh->BoneCount);
|
||||
int extraMatricesToAdd = BONE_COUNT;
|
||||
if (animator)
|
||||
{
|
||||
// Add matrices
|
||||
const auto& MATRICES = animator->GetBoneMatrices();
|
||||
if (MATRICES.size() <= BONE_COUNT)
|
||||
{
|
||||
boneMatrixData.insert(boneMatrixData.end(), MATRICES.cbegin(), MATRICES.cend());
|
||||
extraMatricesToAdd = std::max({0, BONE_COUNT - static_cast<int>(MATRICES.size())});
|
||||
}
|
||||
}
|
||||
|
||||
// If we need to patch up with more matrices, add it
|
||||
if (extraMatricesToAdd > 0)
|
||||
{
|
||||
boneMatrixData.insert(boneMatrixData.end(), extraMatricesToAdd, SHMatrix::Identity);
|
||||
}
|
||||
}
|
||||
|
||||
// Update GPU Buffers
|
||||
if (!boneMatrixIndices.empty())
|
||||
{
|
||||
const uint32_t BMI_DATA_BYTES = static_cast<uint32_t>(boneMatrixIndices.size() * sizeof(uint32_t));
|
||||
SHVkUtil::EnsureBufferAndCopyHostVisibleData
|
||||
(
|
||||
device, boneMatrixFirstIndexBuffer[frameIndex], boneMatrixIndices.data(), BMI_DATA_BYTES,
|
||||
vk::BufferUsageFlagBits::eVertexBuffer,
|
||||
"Batch Instance Bone Matrix First Index Buffer"
|
||||
);
|
||||
}
|
||||
rebuildBoneMatrixDescSetBuffer(frameIndex);
|
||||
}
|
||||
|
||||
void SHBatch::Build(Handle<SHVkLogicalDevice> _device, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex)
|
||||
|
@ -410,14 +496,23 @@ namespace SHADE
|
|||
// - EID data
|
||||
instancedIntegerData.reserve(numTotalElements);
|
||||
instancedIntegerData.clear();
|
||||
// - Bone Data
|
||||
if (isAnimated)
|
||||
{
|
||||
boneMatrixData.clear();
|
||||
boneMatrixIndices.clear();
|
||||
boneMatrixIndices.reserve(numTotalElements);
|
||||
|
||||
auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
|
||||
// Add the first identity matrix into the bone matrix data
|
||||
boneMatrixData.emplace_back(SHMatrix::Identity);
|
||||
}
|
||||
|
||||
// - Material Properties Data
|
||||
auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
|
||||
const Handle<SHShaderBlockInterface> SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface
|
||||
(
|
||||
descMappings.at(SHPredefinedDescriptorTypes::MATERIALS),
|
||||
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
||||
descMappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH),
|
||||
SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
|
||||
vk::ShaderStageFlagBits::eFragment
|
||||
);
|
||||
const bool EMPTY_MAT_PROPS = !SHADER_INFO;
|
||||
|
@ -503,9 +598,36 @@ namespace SHADE
|
|||
{
|
||||
SHLOG_WARNING("[SHBatch] Entity with a missing SHRenderable found!");
|
||||
}
|
||||
//propsCurrPtr += singleMatPropAlignedSize;
|
||||
propsCurrPtr += singleMatPropSize;
|
||||
}
|
||||
|
||||
// Bone Data
|
||||
if (isAnimated)
|
||||
{
|
||||
// Mark start
|
||||
boneMatrixIndices.emplace_back(static_cast<uint32_t>(boneMatrixData.size()));
|
||||
|
||||
auto animator = SHComponentManager::GetComponent_s<SHAnimatorComponent>(rendId);
|
||||
auto mesh = renderable->GetMesh();
|
||||
const int BONE_COUNT = static_cast<int>(mesh->BoneCount);
|
||||
int extraMatricesToAdd = BONE_COUNT;
|
||||
if (animator)
|
||||
{
|
||||
// Add matrices
|
||||
const auto& MATRICES = animator->GetBoneMatrices();
|
||||
if (MATRICES.size() <= BONE_COUNT)
|
||||
{
|
||||
boneMatrixData.insert(boneMatrixData.end(), MATRICES.cbegin(), MATRICES.cend());
|
||||
extraMatricesToAdd = std::max({0, BONE_COUNT - static_cast<int>(MATRICES.size())});
|
||||
}
|
||||
}
|
||||
|
||||
// If we need to patch up with more matrices, add it
|
||||
if (extraMatricesToAdd > 0)
|
||||
{
|
||||
boneMatrixData.insert(boneMatrixData.end(), extraMatricesToAdd, SHMatrix::Identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -540,8 +662,19 @@ namespace SHADE
|
|||
BuffUsage::eVertexBuffer,
|
||||
"Batch Instance Data Buffer"
|
||||
);
|
||||
// - Material Properties Buffer
|
||||
rebuildMaterialBuffers(frameIndex, descPool);
|
||||
// - Bone Matrix Indices
|
||||
if (isAnimated && !boneMatrixIndices.empty())
|
||||
{
|
||||
const uint32_t BMI_DATA_BYTES = static_cast<uint32_t>(boneMatrixIndices.size() * sizeof(uint32_t));
|
||||
SHVkUtil::EnsureBufferAndCopyHostVisibleData
|
||||
(
|
||||
device, boneMatrixFirstIndexBuffer[frameIndex], boneMatrixIndices.data(), BMI_DATA_BYTES,
|
||||
BuffUsage::eVertexBuffer,
|
||||
"Batch Instance Bone Matrix First Index Buffer"
|
||||
);
|
||||
}
|
||||
// - Material and bone buffers/descriptor sets
|
||||
rebuildDescriptorSetBuffers(frameIndex, descPool);
|
||||
}
|
||||
|
||||
// Mark this frame as no longer dirty
|
||||
|
@ -551,7 +684,7 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* SHBatch - Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void SHBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline/* = true*/)
|
||||
void SHBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline)
|
||||
{
|
||||
if (frameIndex >= SHGraphicsConstants::NUM_FRAME_BUFFERS)
|
||||
{
|
||||
|
@ -564,7 +697,11 @@ namespace SHADE
|
|||
return;
|
||||
|
||||
// Bind all required objects before drawing
|
||||
static std::array<uint32_t, 1> dynamicOffset{ 0 };
|
||||
std::vector<uint32_t> dynamicOffset{ 0 };
|
||||
if (isAnimated && !boneMatrixData.empty())
|
||||
{
|
||||
dynamicOffset.emplace_back(0);
|
||||
}
|
||||
cmdBuffer->BeginLabeledSegment("SHBatch for Pipeline #" + std::to_string(pipeline.GetId().Data.Index));
|
||||
|
||||
if (bindBatchPipeline)
|
||||
|
@ -572,16 +709,24 @@ namespace SHADE
|
|||
|
||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0);
|
||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);
|
||||
if (matPropsDescSet[frameIndex])
|
||||
if (isAnimated && boneMatrixFirstIndexBuffer[frameIndex])
|
||||
{
|
||||
auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
|
||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::BONE_MATRIX_FIRST_INDEX, boneMatrixFirstIndexBuffer[frameIndex], 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// HACK: Bind the transform buffer instead since we won't use it anyways, but we must bind something
|
||||
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::BONE_MATRIX_FIRST_INDEX, transformDataBuffer[frameIndex], 0);
|
||||
}
|
||||
|
||||
auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
|
||||
if (instanceDataDescSet[frameIndex])
|
||||
{
|
||||
cmdBuffer->BindDescriptorSet
|
||||
(
|
||||
matPropsDescSet[frameIndex],
|
||||
instanceDataDescSet[frameIndex],
|
||||
SH_PIPELINE_TYPE::GRAPHICS,
|
||||
//SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
||||
descMappings.at(SHPredefinedDescriptorTypes::MATERIALS),
|
||||
descMappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH),
|
||||
dynamicOffset
|
||||
);
|
||||
}
|
||||
|
@ -624,49 +769,128 @@ namespace SHADE
|
|||
isCPUBuffersDirty = true;
|
||||
}
|
||||
|
||||
void SHBatch::rebuildMaterialBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool)
|
||||
void SHBatch::rebuildDescriptorSetBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool)
|
||||
{
|
||||
if (matPropsData && !drawData.empty())
|
||||
{
|
||||
SHVkUtil::EnsureBufferAndCopyHostVisibleData
|
||||
(
|
||||
device, matPropsBuffer[frameIndex], matPropsData.get(), static_cast<uint32_t>(matPropsDataSize),
|
||||
vk::BufferUsageFlagBits::eStorageBuffer,
|
||||
"Batch Material Data"
|
||||
);
|
||||
// Using Declarations and constants
|
||||
using BuffUsage = vk::BufferUsageFlagBits;
|
||||
using PreDefDescLayoutType = SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes;
|
||||
|
||||
if (!matPropsDescSet[frameIndex])
|
||||
|
||||
/* Create Descriptor Sets if Needed */
|
||||
PreDefDescLayoutType layoutTypes = {};
|
||||
if (matPropsData)
|
||||
{
|
||||
matPropsDescSet[frameIndex] = descPool->Allocate
|
||||
layoutTypes = PreDefDescLayoutType::MATERIALS;
|
||||
}
|
||||
if (!boneMatrixData.empty())
|
||||
{
|
||||
layoutTypes = PreDefDescLayoutType::MATERIAL_AND_BONES;
|
||||
}
|
||||
|
||||
const bool MUST_BUILD_BONE_DESC = isAnimated && !boneMatrixData.empty();
|
||||
|
||||
if (matPropsData || MUST_BUILD_BONE_DESC)
|
||||
{
|
||||
// Make sure that we have a descriptor set if we don't already have one
|
||||
if (!instanceDataDescSet[frameIndex])
|
||||
{
|
||||
instanceDataDescSet[frameIndex] = descPool->Allocate
|
||||
(
|
||||
SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS),
|
||||
SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(layoutTypes),
|
||||
{ 0 }
|
||||
);
|
||||
#ifdef _DEBUG
|
||||
const auto& DESC_SETS = matPropsDescSet[frameIndex]->GetVkHandle();
|
||||
const auto& DESC_SETS = instanceDataDescSet[frameIndex]->GetVkHandle();
|
||||
for (auto descSet : DESC_SETS)
|
||||
{
|
||||
SET_VK_OBJ_NAME(device, vk::ObjectType::eDescriptorSet, descSet, "[Descriptor Set] Batch Material Data");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0;
|
||||
/* Material Data */
|
||||
if (matPropsData && !drawData.empty())
|
||||
{
|
||||
// Update GPU buffer
|
||||
SHVkUtil::EnsureBufferAndCopyHostVisibleData
|
||||
(
|
||||
device, matPropsBuffer[frameIndex], matPropsData.get(), static_cast<uint32_t>(matPropsDataSize),
|
||||
BuffUsage::eStorageBuffer,
|
||||
"Batch Material Data"
|
||||
);
|
||||
|
||||
// Update descriptor set buffer
|
||||
std::array<Handle<SHVkBuffer>, 1> bufferList = { matPropsBuffer[frameIndex] };
|
||||
matPropsDescSet[frameIndex]->ModifyWriteDescBuffer
|
||||
instanceDataDescSet[frameIndex]->ModifyWriteDescBuffer
|
||||
(
|
||||
MATERIAL_DESC_SET_INDEX,
|
||||
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
||||
SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
|
||||
bufferList,
|
||||
0, static_cast<uint32_t>(matPropsDataSize)
|
||||
);
|
||||
matPropsDescSet[frameIndex]->UpdateDescriptorSetBuffer
|
||||
|
||||
// Update the descriptor set buffer
|
||||
instanceDataDescSet[frameIndex]->UpdateDescriptorSetBuffer
|
||||
(
|
||||
MATERIAL_DESC_SET_INDEX,
|
||||
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA
|
||||
SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA
|
||||
);
|
||||
}
|
||||
|
||||
/* Animation Bone Data */
|
||||
if (MUST_BUILD_BONE_DESC)
|
||||
{
|
||||
rebuildBoneMatrixDescSetBuffer(frameIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void SHBatch::rebuildBoneMatrixDescSetBuffer(uint32_t frameIndex)
|
||||
{
|
||||
using BuffUsage = vk::BufferUsageFlagBits;
|
||||
// Update GPU Buffers
|
||||
const uint32_t BONE_MTX_DATA_BYTES = static_cast<uint32_t>(boneMatrixData.size() * sizeof(SHMatrix));
|
||||
SHVkUtil::EnsureBufferAndCopyHostVisibleData
|
||||
(
|
||||
device, boneMatrixBuffer[frameIndex], boneMatrixData.data(), BONE_MTX_DATA_BYTES,
|
||||
BuffUsage::eStorageBuffer,
|
||||
"Batch Bone Matrix Buffer"
|
||||
);
|
||||
|
||||
// Update descriptor set buffer
|
||||
std::array<Handle<SHVkBuffer>, 1> bufferList = { boneMatrixBuffer[frameIndex] };
|
||||
instanceDataDescSet[frameIndex]->ModifyWriteDescBuffer
|
||||
(
|
||||
MATERIAL_DESC_SET_INDEX,
|
||||
SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA,
|
||||
bufferList,
|
||||
0,
|
||||
static_cast<uint32_t>(boneMatrixData.size() * sizeof(SHMatrix))
|
||||
);
|
||||
|
||||
// Update the descriptor set buffer
|
||||
instanceDataDescSet[frameIndex]->UpdateDescriptorSetBuffer
|
||||
(
|
||||
MATERIAL_DESC_SET_INDEX,
|
||||
SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA
|
||||
);
|
||||
}
|
||||
|
||||
bool SHBatch::checkIfIsAnimatedPipeline(Handle<SHVkPipeline> pipeline)
|
||||
{
|
||||
if (!pipeline || !pipeline->GetPipelineLayout())
|
||||
return false;
|
||||
|
||||
// Grab the pipeline descriptor set layouts
|
||||
auto pipelineDescLayouts = pipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline();
|
||||
|
||||
// Check if they contain the material and bones layout, that indicates it is
|
||||
using GfxPreDef = SHGraphicsPredefinedData;
|
||||
using GfxPreDefType = GfxPreDef::PredefinedDescSetLayoutTypes;
|
||||
const Handle<SHVkDescriptorSetLayout> BONE_DESC_SET_LAYOUT = GfxPreDef::GetPredefinedDescSetLayouts(GfxPreDefType::MATERIAL_AND_BONES)[0];
|
||||
return std::find_if(pipelineDescLayouts.begin(), pipelineDescLayouts.end(), [BONE_DESC_SET_LAYOUT](Handle<SHVkDescriptorSetLayout> layout)
|
||||
{
|
||||
return BONE_DESC_SET_LAYOUT == layout;
|
||||
}) != pipelineDescLayouts.end();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
class SHVkBuffer;
|
||||
class SHVkCommandBuffer;
|
||||
class SHVkPipeline;
|
||||
|
@ -40,36 +40,36 @@ namespace SHADE
|
|||
class SHVkDescriptorSetGroup;
|
||||
class SHVkDescriptorPool;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/***********************************************************************************/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*************************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Describes a segment of the sub batch operation.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
/*************************************************************************************/
|
||||
struct SHSubBatch
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<SHMesh> Mesh;
|
||||
std::unordered_set<EntityID> Renderables;
|
||||
};
|
||||
/***********************************************************************************/
|
||||
/*************************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Describes a segment of the sub batch operation.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
/*************************************************************************************/
|
||||
class SHBatch
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructor/Destructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
SHBatch(Handle<SHVkPipeline> pipeline);
|
||||
SHBatch(const SHBatch&) = delete;
|
||||
SHBatch(SHBatch&& rhs);
|
||||
|
@ -77,39 +77,48 @@ namespace SHADE
|
|||
SHBatch& operator=(SHBatch&& rhs);
|
||||
~SHBatch();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void Add(const SHRenderable* renderable);
|
||||
void Remove(const SHRenderable* renderable);
|
||||
void Clear();
|
||||
void UpdateMaterialBuffer(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
||||
void UpdateTransformBuffer(uint32_t frameIndex);
|
||||
void UpdateInstancedIntegerBuffer(uint32_t frameIndex);
|
||||
void UpdateAnimationBuffer(uint32_t frameIndex);
|
||||
void Build(Handle<SHVkLogicalDevice> device, Handle<SHVkDescriptorPool> descPool, uint32_t frameIndex);
|
||||
void Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline = true);
|
||||
void Draw(Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex, bool bindBatchPipeline);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<SHVkPipeline> GetPipeline() const noexcept { return pipeline; };
|
||||
bool IsEmpty() const noexcept { return subBatches.empty(); }
|
||||
Handle<SHVkBuffer> GetTransformBuffer(uint32_t frameIndex) const noexcept;
|
||||
Handle<SHVkBuffer> GetMDIBuffer(uint32_t frameIndex) const noexcept;
|
||||
bool IsAnimated() const noexcept { return isAnimated; }
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definition */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
using TripleBool = std::array<bool, SHGraphicsConstants::NUM_FRAME_BUFFERS>;
|
||||
using TripleBuffer = std::array<Handle<SHVkBuffer>, SHGraphicsConstants::NUM_FRAME_BUFFERS>;
|
||||
using TripleDescSet = std::array<Handle<SHVkDescriptorSetGroup>, SHGraphicsConstants::NUM_FRAME_BUFFERS>;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constants */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
// Resources
|
||||
Handle<SHVkLogicalDevice> device;
|
||||
// Config
|
||||
bool isAnimated; // Whether the material supports animation
|
||||
// Batch Properties
|
||||
Handle<SHVkPipeline> pipeline;
|
||||
std::unordered_set<Handle<SHMaterialInstance>> referencedMatInstances;
|
||||
|
@ -125,18 +134,25 @@ namespace SHADE
|
|||
Byte matPropsDataSize = 0;
|
||||
Byte singleMatPropAlignedSize = 0;
|
||||
Byte singleMatPropSize = 0;
|
||||
std::vector<SHMatrix> boneMatrixData; // 0th element is always an identity matrix
|
||||
std::vector<uint32_t> boneMatrixIndices;
|
||||
bool isCPUBuffersDirty = true;
|
||||
// GPU Buffers
|
||||
TripleBuffer drawDataBuffer;
|
||||
TripleBuffer transformDataBuffer;
|
||||
TripleBuffer instancedIntegerBuffer;
|
||||
TripleBuffer matPropsBuffer;
|
||||
TripleDescSet matPropsDescSet;
|
||||
TripleBuffer boneMatrixBuffer;
|
||||
TripleBuffer boneMatrixFirstIndexBuffer; // Instanced buffer, indicates where the first bone matrix is
|
||||
TripleDescSet instanceDataDescSet;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void setAllDirtyFlags();
|
||||
void rebuildMaterialBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
||||
void rebuildDescriptorSetBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
||||
void rebuildBoneMatrixDescSetBuffer(uint32_t frameIndex);
|
||||
static bool checkIfIsAnimatedPipeline(Handle<SHVkPipeline> pipeline);
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -94,6 +94,7 @@ namespace SHADE
|
|||
{
|
||||
batch.UpdateMaterialBuffer(frameIndex, descPool);
|
||||
batch.UpdateTransformBuffer(frameIndex);
|
||||
batch.UpdateAnimationBuffer(frameIndex);
|
||||
batch.UpdateInstancedIntegerBuffer(frameIndex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,18 @@ namespace SHADE
|
|||
|
||||
void SHGraphicsPredefinedData::InitDescMappings(void) noexcept
|
||||
{
|
||||
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descMappings.AddMappings
|
||||
({
|
||||
{SHPredefinedDescriptorTypes::STATIC_DATA, 0},
|
||||
{SHPredefinedDescriptorTypes::CAMERA, 1},
|
||||
{SHPredefinedDescriptorTypes::MATERIALS, 2},
|
||||
{SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH, 2},
|
||||
});
|
||||
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING_ANIM)].descMappings.AddMappings
|
||||
({
|
||||
{SHPredefinedDescriptorTypes::STATIC_DATA, 0},
|
||||
{SHPredefinedDescriptorTypes::CAMERA, 1},
|
||||
{SHPredefinedDescriptorTypes::PER_INSTANCE_ANIM_BATCH, 2},
|
||||
});
|
||||
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descMappings.AddMappings
|
||||
|
@ -50,9 +56,13 @@ namespace SHADE
|
|||
|
||||
void SHGraphicsPredefinedData::InitDummyPipelineLayouts(Handle<SHVkLogicalDevice> logicalDevice) noexcept
|
||||
{
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts });
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts });
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].descSetLayouts });
|
||||
for (int i = 0; i < SYSTEM_TYPE_COUNT; ++i)
|
||||
{
|
||||
perSystemData[i].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy
|
||||
(
|
||||
SHPipelineLayoutParamsDummy { perSystemData[i].descSetLayouts }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -124,8 +134,8 @@ namespace SHADE
|
|||
SHVkDescriptorSetLayout::Binding materialDataBinding
|
||||
{
|
||||
.Type = vk::DescriptorType::eStorageBufferDynamic,
|
||||
.Stage = vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eVertex,
|
||||
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
||||
.Stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
|
||||
.DescriptorCount = 1,
|
||||
};
|
||||
Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding });
|
||||
|
@ -166,12 +176,24 @@ namespace SHADE
|
|||
Handle<SHVkDescriptorSetLayout> shadowMapDescLayout = logicalDevice->CreateDescriptorSetLayout({ shadowMapBinding });
|
||||
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, shadowMapDescLayout->GetVkHandle(), "[Descriptor Set Layout] Shadow Maps");
|
||||
|
||||
// For per instance data (transforms, materials, etc.)
|
||||
SHVkDescriptorSetLayout::Binding boneDataBinding
|
||||
{
|
||||
.Type = vk::DescriptorType::eStorageBufferDynamic,
|
||||
.Stage = vk::ShaderStageFlagBits::eVertex,
|
||||
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA,
|
||||
.DescriptorCount = 1,
|
||||
};
|
||||
Handle<SHVkDescriptorSetLayout> materialBoneDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding, boneDataBinding });
|
||||
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialBoneDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material and Bone Globals");
|
||||
|
||||
predefinedLayouts.push_back(staticGlobalLayout);
|
||||
predefinedLayouts.push_back(lightDataDescSetLayout);
|
||||
predefinedLayouts.push_back(cameraDataGlobalLayout);
|
||||
predefinedLayouts.push_back(materialDataPerInstanceLayout);
|
||||
predefinedLayouts.push_back(fontDataDescSetLayout);
|
||||
predefinedLayouts.push_back(shadowMapDescLayout);
|
||||
predefinedLayouts.push_back(materialBoneDataPerInstanceLayout);
|
||||
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts = GetPredefinedDescSetLayouts
|
||||
(
|
||||
|
@ -180,6 +202,13 @@ namespace SHADE
|
|||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS
|
||||
);
|
||||
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING_ANIM)].descSetLayouts = GetPredefinedDescSetLayouts
|
||||
(
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA |
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::CAMERA |
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIAL_AND_BONES
|
||||
);
|
||||
|
||||
perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts = GetPredefinedDescSetLayouts
|
||||
(
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA |
|
||||
|
@ -197,12 +226,15 @@ namespace SHADE
|
|||
|
||||
void SHGraphicsPredefinedData::InitPredefinedVertexInputState(void) noexcept
|
||||
{
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Normals at binding 2
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Tangents at binding 3
|
||||
defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }); // Transform at binding 4 - 7 (4 slots)
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Attribute positions at binding 0
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // Attribute UVs at binding 1
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Attribute Normals at binding 2
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Attribute Tangents at binding 3
|
||||
defaultVertexInputState.AddBinding(true , true , { SHVertexAttribute(SHAttribFormat::MAT_4D) }); // Instanced Transform at binding 4 - 7 (4 slots)
|
||||
defaultVertexInputState.AddBinding(true , true , { SHVertexAttribute(SHAttribFormat::UINT32_2D) }); // Instanced integer data at index 8
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::UINT32_4D) }); // Attribute bone indices at index 9
|
||||
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); // Attribute bone weights at index 10
|
||||
defaultVertexInputState.AddBinding(true , true , { SHVertexAttribute(SHAttribFormat::UINT32_1D) }); // Instance bone matrix first index at index 11
|
||||
|
||||
shadowMapVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D)});
|
||||
shadowMapVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }, 4, 4); // Transform at binding 4 - 7 (4 slots)
|
||||
|
@ -256,12 +288,24 @@ namespace SHADE
|
|||
return static_cast<SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes>(static_cast<uint64_t>(lhs) | static_cast<uint64_t>(rhs));
|
||||
}
|
||||
|
||||
SHADE::SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& operator|=(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept
|
||||
{
|
||||
lhs = lhs | rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator&(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept
|
||||
{
|
||||
return static_cast<SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes>(static_cast<uint64_t>(lhs) & static_cast<uint64_t>(rhs));
|
||||
|
||||
}
|
||||
|
||||
SHADE::SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& operator&=(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept
|
||||
{
|
||||
lhs = lhs & rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
//SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetBatchingSystemData(void) noexcept
|
||||
//{
|
||||
// return batchingSystemData;
|
||||
|
|
|
@ -23,21 +23,24 @@ namespace SHADE
|
|||
// This enum is mainly to initialize a bit field to retrieve bit fields from SHPRedefinedData
|
||||
enum class PredefinedDescSetLayoutTypes : uint64_t
|
||||
{
|
||||
STATIC_DATA = 0x01,
|
||||
LIGHTS = 0x02,
|
||||
CAMERA = 0x04,
|
||||
MATERIALS = 0x08,
|
||||
FONT = 0x10,
|
||||
SHADOW = 0x20,
|
||||
STATIC_DATA = 0b00000001,
|
||||
LIGHTS = 0b00000010,
|
||||
CAMERA = 0b00000100,
|
||||
MATERIALS = 0b00001000,
|
||||
FONT = 0b00010000,
|
||||
SHADOW = 0b00100000,
|
||||
MATERIAL_AND_BONES = 0b01000000
|
||||
};
|
||||
|
||||
enum class SystemType
|
||||
{
|
||||
BATCHING = 0,
|
||||
BATCHING_ANIM,
|
||||
TEXT_RENDERING,
|
||||
RENDER_GRAPH_NODE_COMPUTE,
|
||||
NUM_TYPES
|
||||
};
|
||||
static constexpr int SYSTEM_TYPE_COUNT = static_cast<int>(SystemType::NUM_TYPES);
|
||||
|
||||
struct PerSystem
|
||||
{
|
||||
|
@ -103,5 +106,7 @@ namespace SHADE
|
|||
|
||||
};
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator| (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept;
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& operator|=(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept;
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator& (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept;
|
||||
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& operator&=(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ namespace SHADE
|
|||
STATIC_DATA,
|
||||
LIGHTS,
|
||||
CAMERA,
|
||||
MATERIALS,
|
||||
PER_INSTANCE_BATCH,
|
||||
PER_INSTANCE_ANIM_BATCH,
|
||||
FONT,
|
||||
RENDER_GRAPH_NODE_COMPUTE_RESOURCE,
|
||||
RENDER_GRAPH_RESOURCE,
|
||||
|
|
|
@ -14,7 +14,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
// STL Includes
|
||||
#include <algorithm>
|
||||
// Project Includes
|
||||
#include "Assets/Asset Types/SHModelAsset.h"
|
||||
#include "Assets/Asset Types/Models/SHModelAsset.h"
|
||||
#include "../Meshes/SHPrimitiveGenerator.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "SHGraphicsSystem.h"
|
||||
|
|
|
@ -161,7 +161,15 @@ namespace SHADE
|
|||
DescriptorSet binding for per instance material values.
|
||||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t BATCHED_PER_INST_DATA = 0;
|
||||
static constexpr uint32_t PER_INST_MATERIAL_DATA = 0;
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
DescriptorSet binding for per instance bone values.
|
||||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t PER_INST_BONE_DATA = 1;
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
@ -191,6 +199,14 @@ namespace SHADE
|
|||
static constexpr uint32_t SHADOW_MAP_IMAGE_SAMPLER_DATA = 0;
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Descriptor set binding for bone matrix data.
|
||||
|
||||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t BONE_MATRIX_DATA = 1;
|
||||
};
|
||||
|
||||
struct VertexBufferBindings
|
||||
|
@ -237,6 +253,27 @@ namespace SHADE
|
|||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t INTEGER_DATA = 5;
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Vertex buffer bindings for the bone indices buffer.
|
||||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t BONE_INDICES = 6;
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Vertex buffer bindings for the bone weights buffer.
|
||||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t BONE_WEIGHTS = 7;
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Vertex buffer bindings for the bone matrix first index buffer.
|
||||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t BONE_MATRIX_FIRST_INDEX = 8;
|
||||
|
||||
static constexpr uint32_t CALCULATED_GLYPH_POSITION = 0;
|
||||
static constexpr uint32_t GLYPH_INDEX = 1;
|
||||
|
|
|
@ -127,15 +127,16 @@ namespace SHADE
|
|||
|
||||
SHFreetypeInstance::Init();
|
||||
|
||||
SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false);
|
||||
SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false);
|
||||
SHAssetManager::CompileAsset("../../Assets/Shaders/SSAOBlur_CS.glsl", false);
|
||||
SHAssetManager::CompileAsset("../../Assets/Shaders/PureCopy_CS.glsl", false);
|
||||
SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false);
|
||||
SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_FS.glsl", false);
|
||||
//SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false);
|
||||
//SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false);
|
||||
//SHAssetManager::CompileAsset("../../Assets/Shaders/SSAOBlur_CS.glsl", false);
|
||||
//SHAssetManager::CompileAsset("../../Assets/Shaders/PureCopy_CS.glsl", false);
|
||||
//SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_VS.glsl", false);
|
||||
//SHAssetManager::CompileAsset("../../Assets/Shaders/TestCube_FS.glsl", false);
|
||||
|
||||
// Load Built In Shaders
|
||||
static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEFAULT);
|
||||
static constexpr AssetID VS_ANIM = 47911992; animtVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_ANIM);
|
||||
static constexpr AssetID FS_DEFAULT = 46377769; defaultFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEFAULT);
|
||||
static constexpr AssetID VS_DEBUG = 48002439; debugVertShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(VS_DEBUG);
|
||||
static constexpr AssetID FS_DEBUG = 36671027; debugFragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(FS_DEBUG);
|
||||
|
@ -450,6 +451,12 @@ namespace SHADE
|
|||
renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass("G-Buffer Write")
|
||||
);
|
||||
defaultMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex);
|
||||
defaultAnimMaterial = AddMaterial
|
||||
(
|
||||
animtVertShader, defaultFragShader,
|
||||
renderGraph->GetNode("G-Buffer")->GetSubpass("G-Buffer Write")
|
||||
);
|
||||
defaultAnimMaterial->SetProperty("data.textureIndex", defaultTexture->TextureArrayIndex);
|
||||
}
|
||||
|
||||
|
||||
|
@ -525,6 +532,8 @@ namespace SHADE
|
|||
std::make_pair(meshLibrary.GetVertexTexCoordsBuffer(), SHGraphicsConstants::VertexBufferBindings::TEX_COORD),
|
||||
std::make_pair(meshLibrary.GetVertexNormalsBuffer(), SHGraphicsConstants::VertexBufferBindings::NORMAL),
|
||||
std::make_pair(meshLibrary.GetVertexTangentsBuffer(), SHGraphicsConstants::VertexBufferBindings::TANGENT),
|
||||
std::make_pair(meshLibrary.GetVertexBoneIndicesBuffer(), SHGraphicsConstants::VertexBufferBindings::BONE_INDICES),
|
||||
std::make_pair(meshLibrary.GetVertexBoneWeightsBuffer(), SHGraphicsConstants::VertexBufferBindings::BONE_WEIGHTS),
|
||||
std::make_pair(meshLibrary.GetIndexBuffer(), 0),
|
||||
};
|
||||
|
||||
|
@ -568,14 +577,14 @@ namespace SHADE
|
|||
#endif
|
||||
}
|
||||
|
||||
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::B))
|
||||
{
|
||||
auto& lightComps = SHComponentManager::GetDense<SHLightComponent>();
|
||||
for (auto& comp : lightComps)
|
||||
{
|
||||
comp.SetEnableShadow(true);
|
||||
}
|
||||
}
|
||||
//if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::B))
|
||||
//{
|
||||
// auto& lightComps = SHComponentManager::GetDense<SHLightComponent>();
|
||||
// for (auto& comp : lightComps)
|
||||
// {
|
||||
// comp.SetEnableShadow(true);
|
||||
// }
|
||||
//}
|
||||
|
||||
renderGraph->Begin(frameIndex);
|
||||
auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex);
|
||||
|
@ -800,7 +809,12 @@ namespace SHADE
|
|||
rasterState.cull_mode = vk::CullModeFlagBits::eBack;
|
||||
|
||||
tempLibrary.Init(device);
|
||||
tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass, SHGraphicsPredefinedData::GetShadowMapViState(), rasterState);
|
||||
tempLibrary.CreateGraphicsPipelines
|
||||
(
|
||||
{ shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass,
|
||||
SHGraphicsPredefinedData::SystemType::BATCHING,
|
||||
SHGraphicsPredefinedData::GetShadowMapViState(), rasterState
|
||||
);
|
||||
shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, {} });
|
||||
}
|
||||
newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline
|
||||
|
@ -865,9 +879,9 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* Mesh Registration Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
SHADE::Handle<SHADE::SHMesh> SHGraphicsSystem::AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices)
|
||||
SHADE::Handle<SHADE::SHMesh> SHGraphicsSystem::AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices, const SHMesh::VertexBoneIndices* const boneIndices, const SHMesh::VertexWeights* const boneWeights, uint32_t boneCount)
|
||||
{
|
||||
return meshLibrary.AddMesh(vertexCount, positions, texCoords, tangents, normals, indexCount, indices);
|
||||
return meshLibrary.AddMesh(vertexCount, positions, texCoords, tangents, normals, boneIndices, boneWeights, indexCount, indices, boneCount);
|
||||
}
|
||||
|
||||
void SHGraphicsSystem::RemoveMesh(Handle<SHMesh> mesh)
|
||||
|
|
|
@ -230,7 +230,7 @@ namespace SHADE
|
|||
|
||||
*/
|
||||
/*******************************************************************************/
|
||||
Handle<SHMesh> AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices);
|
||||
Handle<SHMesh> AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices, const SHMesh::VertexBoneIndices* const boneIndices = nullptr, const SHMesh::VertexWeights* const boneWeights = nullptr, uint32_t boneCount = 0);
|
||||
/*******************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -455,6 +455,7 @@ namespace SHADE
|
|||
|
||||
// Built-In Shaders
|
||||
Handle<SHVkShaderModule> defaultVertShader;
|
||||
Handle<SHVkShaderModule> animtVertShader;
|
||||
Handle<SHVkShaderModule> defaultFragShader;
|
||||
Handle<SHVkShaderModule> debugVertShader;
|
||||
Handle<SHVkShaderModule> debugFragShader;
|
||||
|
@ -473,6 +474,7 @@ namespace SHADE
|
|||
|
||||
// Built-In Materials
|
||||
Handle<SHMaterial> defaultMaterial;
|
||||
Handle<SHMaterial> defaultAnimMaterial;
|
||||
Handle<SHVkPipeline> debugDrawPipeline;
|
||||
Handle<SHVkPipeline> debugDrawDepthPipeline;
|
||||
Handle<SHVkPipeline> debugDrawLineMeshPipeline;
|
||||
|
|
|
@ -100,9 +100,9 @@ namespace SHADE
|
|||
auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
|
||||
return pipeline->GetPipelineLayout()->GetShaderBlockInterface
|
||||
(
|
||||
mappings.at (SHPredefinedDescriptorTypes::MATERIALS),
|
||||
mappings.at (SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH),
|
||||
//SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
||||
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
||||
SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
|
||||
vk::ShaderStageFlagBits::eFragment
|
||||
);
|
||||
}
|
||||
|
|
|
@ -81,9 +81,9 @@ namespace SHADE
|
|||
{
|
||||
return baseMaterial->GetPipeline()->GetPipelineLayout()->GetShaderBlockInterface
|
||||
(
|
||||
SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING).at(SHPredefinedDescriptorTypes::MATERIALS),
|
||||
SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING).at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH),
|
||||
//SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
||||
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
||||
SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
|
||||
vk::ShaderStageFlagBits::eFragment
|
||||
);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,16 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
SHADE::Handle<SHADE::SHMesh> SHMeshLibrary::AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices)
|
||||
SHADE::Handle<SHADE::SHMesh> SHMeshLibrary::AddMesh
|
||||
(
|
||||
uint32_t vertexCount, const SHMesh::VertexPosition* const positions,
|
||||
const SHMesh::VertexTexCoord* const texCoords,
|
||||
const SHMesh::VertexTangent* const tangents,
|
||||
const SHMesh::VertexNormal* const normals,
|
||||
const SHMesh::VertexBoneIndices* const boneIndices,
|
||||
const SHMesh::VertexWeights* const boneWeights,
|
||||
uint32_t indexCount, const SHMesh::Index* const indices,
|
||||
uint32_t boneCount)
|
||||
{
|
||||
isDirty = true;
|
||||
|
||||
|
@ -32,8 +41,11 @@ namespace SHADE
|
|||
texCoords,
|
||||
tangents,
|
||||
normals,
|
||||
boneIndices,
|
||||
boneWeights,
|
||||
indexCount,
|
||||
indices,
|
||||
boneCount,
|
||||
handle
|
||||
});
|
||||
return handle;
|
||||
|
@ -83,6 +95,8 @@ namespace SHADE
|
|||
vertTexCoordStorage.erase(vertTexCoordStorage.begin() + nextVertInsertPoint, vertTexCoordStorage.begin() + mesh->FirstVertex);
|
||||
vertTangentStorage.erase(vertTangentStorage.begin() + nextVertInsertPoint, vertTangentStorage.begin() + mesh->FirstVertex);
|
||||
vertNormalStorage.erase(vertNormalStorage.begin() + nextVertInsertPoint, vertNormalStorage.begin() + mesh->FirstVertex);
|
||||
vertBoneIdxStorage.erase(vertBoneIdxStorage.begin() + nextVertInsertPoint, vertBoneIdxStorage.begin() + mesh->FirstVertex);
|
||||
vertBoneWeightStorage.erase(vertBoneWeightStorage.begin() + nextVertInsertPoint, vertBoneWeightStorage.begin() + mesh->FirstVertex);
|
||||
// - Update mesh data
|
||||
mesh->FirstVertex = nextVertInsertPoint;
|
||||
|
||||
|
@ -114,6 +128,8 @@ namespace SHADE
|
|||
vertTexCoordStorage.reserve(newVertElems);
|
||||
vertTangentStorage.reserve(newVertElems);
|
||||
vertNormalStorage.reserve(newVertElems);
|
||||
vertBoneIdxStorage.reserve(newVertElems);
|
||||
vertBoneWeightStorage.reserve(newVertElems);
|
||||
indexStorage.reserve(newIdxElems);
|
||||
// - Append new data
|
||||
for (auto& addJob : meshAddJobs)
|
||||
|
@ -126,6 +142,7 @@ namespace SHADE
|
|||
.VertexCount = static_cast<uint32_t>(addJob.VertexCount),
|
||||
.FirstIndex = static_cast<uint32_t>(indexStorage.size()),
|
||||
.IndexCount = static_cast<uint32_t>(addJob.IndexCount),
|
||||
.BoneCount = addJob.BoneCount
|
||||
};
|
||||
|
||||
// Copy into storage
|
||||
|
@ -149,6 +166,32 @@ namespace SHADE
|
|||
vertNormalStorage.end(),
|
||||
addJob.VertexNormals, addJob.VertexNormals + addJob.VertexCount
|
||||
);
|
||||
if (addJob.VertexBoneIndices)
|
||||
{
|
||||
vertBoneIdxStorage.insert
|
||||
(
|
||||
vertBoneIdxStorage.end(),
|
||||
addJob.VertexBoneIndices, addJob.VertexBoneIndices + addJob.VertexCount
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
vertBoneIdxStorage.resize(vertBoneIdxStorage.size() + addJob.VertexCount);
|
||||
}
|
||||
if (addJob.VertexBoneWeights)
|
||||
{
|
||||
vertBoneWeightStorage.insert
|
||||
(
|
||||
vertBoneWeightStorage.end(),
|
||||
addJob.VertexBoneWeights, addJob.VertexBoneWeights + addJob.VertexCount
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto OG_SIZE = vertBoneWeightStorage.size();
|
||||
vertBoneWeightStorage.resize(vertBoneWeightStorage.size() + addJob.VertexCount);
|
||||
std::fill_n(vertBoneWeightStorage.begin() + OG_SIZE, addJob.VertexCount, SHVec4(1.0f, 0.0f, 0.0f, 0.0f));
|
||||
}
|
||||
indexStorage.insert
|
||||
(
|
||||
indexStorage.end(),
|
||||
|
@ -192,6 +235,28 @@ namespace SHADE
|
|||
BuffUsage::eVertexBuffer,
|
||||
"Mesh Library Vertex Normals"
|
||||
);
|
||||
if (!vertBoneIdxStorage.empty())
|
||||
{
|
||||
SHVkUtil::EnsureBufferAndCopyData
|
||||
(
|
||||
device, cmdBuffer, vertBoneIdxBuffer,
|
||||
vertBoneIdxStorage.data(),
|
||||
static_cast<uint32_t>(vertBoneIdxStorage.size()) * sizeof(SHMesh::VertexBoneIndices),
|
||||
BuffUsage::eVertexBuffer,
|
||||
"Mesh Library Vertex Bone Indices"
|
||||
);
|
||||
}
|
||||
if (!vertBoneWeightStorage.empty())
|
||||
{
|
||||
SHVkUtil::EnsureBufferAndCopyData
|
||||
(
|
||||
device, cmdBuffer, vertBoneWeightBuffer,
|
||||
vertBoneWeightStorage.data(),
|
||||
static_cast<uint32_t>(vertBoneWeightStorage.size()) * sizeof(SHMesh::VertexWeights),
|
||||
BuffUsage::eVertexBuffer,
|
||||
"Mesh Library Vertex Bone Weights"
|
||||
);
|
||||
}
|
||||
SHVkUtil::EnsureBufferAndCopyData
|
||||
(
|
||||
device, cmdBuffer, indexBuffer,
|
||||
|
|
|
@ -19,6 +19,8 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Resource/SHResourceLibrary.h"
|
||||
#include "Math/Vector/SHVec2.h"
|
||||
#include "Math/Vector/SHVec3.h"
|
||||
#include "Math/Vector/SHVec4.h"
|
||||
#include "Math/Vector/SHVec4U.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -49,6 +51,8 @@ namespace SHADE
|
|||
using VertexTexCoord = SHVec2;
|
||||
using VertexTangent = SHVec3;
|
||||
using VertexNormal = SHVec3;
|
||||
using VertexBoneIndices = SHVec4U;
|
||||
using VertexWeights = SHVec4;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
|
@ -57,6 +61,7 @@ namespace SHADE
|
|||
uint32_t VertexCount;
|
||||
uint32_t FirstIndex;
|
||||
uint32_t IndexCount;
|
||||
uint32_t BoneCount;
|
||||
};
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
|
@ -105,7 +110,14 @@ namespace SHADE
|
|||
|
||||
*/
|
||||
/*******************************************************************************/
|
||||
Handle<SHMesh> AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices);
|
||||
Handle<SHMesh> AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions,
|
||||
const SHMesh::VertexTexCoord* const texCoords,
|
||||
const SHMesh::VertexTangent* const tangents,
|
||||
const SHMesh::VertexNormal* const normals,
|
||||
const SHMesh::VertexBoneIndices* const boneIndices,
|
||||
const SHMesh::VertexWeights* const boneWeights,
|
||||
uint32_t indexCount, const SHMesh::Index* const indices,
|
||||
uint32_t boneCount);
|
||||
/*******************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -144,7 +156,9 @@ namespace SHADE
|
|||
Handle<SHVkBuffer> GetVertexTexCoordsBuffer() const noexcept { return vertTexCoordBuffer; }
|
||||
Handle<SHVkBuffer> GetVertexTangentsBuffer() const noexcept { return vertTangentBuffer; }
|
||||
Handle<SHVkBuffer> GetVertexNormalsBuffer() const noexcept { return vertNormalBuffer; }
|
||||
Handle<SHVkBuffer> GetIndexBuffer() const { return indexBuffer; }
|
||||
Handle<SHVkBuffer> GetVertexBoneIndicesBuffer() const noexcept { return vertBoneIdxBuffer; }
|
||||
Handle<SHVkBuffer> GetVertexBoneWeightsBuffer() const noexcept { return vertBoneWeightBuffer; }
|
||||
Handle<SHVkBuffer> GetIndexBuffer() const noexcept { return indexBuffer; }
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -157,8 +171,11 @@ namespace SHADE
|
|||
const SHMesh::VertexTexCoord* VertexTexCoords = nullptr;
|
||||
const SHMesh::VertexTangent* VertexTangents = nullptr;
|
||||
const SHMesh::VertexNormal* VertexNormals = nullptr;
|
||||
const SHMesh::VertexBoneIndices* VertexBoneIndices = nullptr;
|
||||
const SHMesh::VertexWeights* VertexBoneWeights = nullptr;
|
||||
uint32_t IndexCount = 0;
|
||||
const SHMesh::Index* Indices = nullptr;
|
||||
uint32_t BoneCount = 0;
|
||||
Handle<SHMesh> Handle;
|
||||
};
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -168,19 +185,23 @@ namespace SHADE
|
|||
std::vector<MeshAddJob> meshAddJobs;
|
||||
std::vector<Handle<SHMesh>> meshRemoveJobs;
|
||||
// Tracking
|
||||
SHResourceLibrary<SHMesh> meshes{};
|
||||
SHResourceLibrary<SHMesh> meshes;
|
||||
std::vector<Handle<SHMesh>> meshOrder;
|
||||
// CPU Storage
|
||||
std::vector<SHMesh::VertexPosition> vertPosStorage;
|
||||
std::vector<SHMesh::VertexTexCoord> vertTexCoordStorage;
|
||||
std::vector<SHMesh::VertexTangent> vertTangentStorage;
|
||||
std::vector<SHMesh::VertexNormal> vertNormalStorage;
|
||||
std::vector<SHMesh::VertexBoneIndices> vertBoneIdxStorage; // Must be in multiples of 4
|
||||
std::vector<SHMesh::VertexWeights> vertBoneWeightStorage;
|
||||
std::vector<SHMesh::Index> indexStorage;
|
||||
// GPU Storage
|
||||
Handle<SHVkBuffer> vertPosBuffer{};
|
||||
Handle<SHVkBuffer> vertTexCoordBuffer{};
|
||||
Handle<SHVkBuffer> vertTangentBuffer{};
|
||||
Handle<SHVkBuffer> vertNormalBuffer{};
|
||||
Handle<SHVkBuffer> vertBoneIdxBuffer{};
|
||||
Handle<SHVkBuffer> vertBoneWeightBuffer{};
|
||||
Handle<SHVkBuffer> indexBuffer{};
|
||||
// Flags
|
||||
bool isDirty = true;
|
||||
|
|
|
@ -25,18 +25,18 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Static Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHMeshData SHPrimitiveGenerator::cubeMesh;
|
||||
SHMeshData SHPrimitiveGenerator::sphereMesh;
|
||||
SHMeshData SHPrimitiveGenerator::lineCubeMesh;
|
||||
SHMeshData SHPrimitiveGenerator::lineCircleMesh;
|
||||
SHMeshData SHPrimitiveGenerator::lineCapsuleCapMesh;
|
||||
SHMeshAsset SHPrimitiveGenerator::cubeMesh;
|
||||
SHMeshAsset SHPrimitiveGenerator::sphereMesh;
|
||||
SHMeshAsset SHPrimitiveGenerator::lineCubeMesh;
|
||||
SHMeshAsset SHPrimitiveGenerator::lineCircleMesh;
|
||||
SHMeshAsset SHPrimitiveGenerator::lineCapsuleCapMesh;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Primitive Generation Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHMeshData SHPrimitiveGenerator::Cube() noexcept
|
||||
SHMeshAsset SHPrimitiveGenerator::Cube() noexcept
|
||||
{
|
||||
SHMeshData mesh;
|
||||
SHMeshAsset mesh;
|
||||
|
||||
mesh.VertexPositions =
|
||||
{
|
||||
|
@ -221,9 +221,9 @@ namespace SHADE
|
|||
return addMeshDataTo(cubeMesh, gfxSystem);
|
||||
}
|
||||
|
||||
SHMeshData SHPrimitiveGenerator::Sphere() noexcept
|
||||
SHMeshAsset SHPrimitiveGenerator::Sphere() noexcept
|
||||
{
|
||||
SHMeshData meshData;
|
||||
SHMeshAsset meshData;
|
||||
|
||||
const int LAT_SLICES = 12;
|
||||
const int LONG_SLICES = 12;
|
||||
|
@ -288,9 +288,9 @@ namespace SHADE
|
|||
return addMeshDataTo(sphereMesh, gfxSystem);
|
||||
}
|
||||
|
||||
SHMeshData SHPrimitiveGenerator::LineCube() noexcept
|
||||
SHMeshAsset SHPrimitiveGenerator::LineCube() noexcept
|
||||
{
|
||||
SHMeshData mesh;
|
||||
SHMeshAsset mesh;
|
||||
|
||||
mesh.VertexPositions =
|
||||
{
|
||||
|
@ -347,9 +347,9 @@ namespace SHADE
|
|||
return addMeshDataTo(lineCubeMesh, gfxSystem);
|
||||
}
|
||||
|
||||
SHMeshData SHPrimitiveGenerator::LineCircle() noexcept
|
||||
SHMeshAsset SHPrimitiveGenerator::LineCircle() noexcept
|
||||
{
|
||||
SHMeshData mesh;
|
||||
SHMeshAsset mesh;
|
||||
|
||||
// Generate points of the circle
|
||||
static constexpr int SPLITS = 36;
|
||||
|
@ -393,9 +393,9 @@ namespace SHADE
|
|||
return addMeshDataTo(lineCircleMesh, gfxSystem);
|
||||
}
|
||||
|
||||
SHADE::SHMeshData SHPrimitiveGenerator::LineCapsuleCap() noexcept
|
||||
SHMeshAsset SHPrimitiveGenerator::LineCapsuleCap() noexcept
|
||||
{
|
||||
SHMeshData mesh;
|
||||
SHMeshAsset mesh;
|
||||
|
||||
// Have multiple semi-circles for the cap
|
||||
static constexpr int SPLITS = 36;
|
||||
|
@ -454,7 +454,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHADE::Handle<SHADE::SHMesh> SHPrimitiveGenerator::addMeshDataTo(const SHMeshData& meshData, SHMeshLibrary& meshLibrary) noexcept
|
||||
SHADE::Handle<SHADE::SHMesh> SHPrimitiveGenerator::addMeshDataTo(const SHMeshAsset& meshData, SHMeshLibrary& meshLibrary) noexcept
|
||||
{
|
||||
return meshLibrary.AddMesh
|
||||
(
|
||||
|
@ -463,12 +463,15 @@ namespace SHADE
|
|||
meshData.VertexTexCoords.data(),
|
||||
meshData.VertexTangents.data(),
|
||||
meshData.VertexNormals.data(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
static_cast<uint32_t>(meshData.Indices.size()),
|
||||
meshData.Indices.data()
|
||||
meshData.Indices.data(),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
SHADE::Handle<SHADE::SHMesh> SHPrimitiveGenerator::addMeshDataTo(const SHMeshData& meshData, SHGraphicsSystem& gfxSystem) noexcept
|
||||
SHADE::Handle<SHADE::SHMesh> SHPrimitiveGenerator::addMeshDataTo(const SHMeshAsset& meshData, SHGraphicsSystem& gfxSystem) noexcept
|
||||
{
|
||||
return gfxSystem.AddMesh
|
||||
(
|
||||
|
|
|
@ -12,10 +12,11 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#pragma once
|
||||
|
||||
// Project Includes
|
||||
#include "Math/SHMath.h"
|
||||
#include "Assets/Asset Types/SHModelAsset.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
|
||||
#include "SH_API.h"
|
||||
#include "Math/SHMath.h"
|
||||
#include "Assets/Asset Types/Models/SHModelAsset.h"
|
||||
#include "Assets/Asset Types/Models/SHMeshAsset.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -47,13 +48,13 @@ namespace SHADE
|
|||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Produces a cube and stores the data in a SHMeshData object.
|
||||
Produces a cube and stores the data in a SHMeshAsset object.
|
||||
|
||||
\return
|
||||
SHMeshData object containing vertex data for the cube.
|
||||
SHMeshAsset object containing vertex data for the cube.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
[[nodiscard]] static SHMeshData Cube() noexcept;
|
||||
[[nodiscard]] static SHMeshAsset Cube() noexcept;
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
|
@ -83,13 +84,13 @@ namespace SHADE
|
|||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Produces a sphere and stores the data in a SHMeshData object.
|
||||
Produces a sphere and stores the data in a SHMeshAsset object.
|
||||
|
||||
\return
|
||||
SHMeshData object containing vertex data for the sphere.
|
||||
SHMeshAsset object containing vertex data for the sphere.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
[[nodiscard]] static SHMeshData Sphere() noexcept;
|
||||
[[nodiscard]] static SHMeshAsset Sphere() noexcept;
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
|
@ -120,13 +121,13 @@ namespace SHADE
|
|||
/*!
|
||||
\brief
|
||||
Produces a cube that is comprised only of lines with no diagonal lines and store
|
||||
the data in a SHMeshData object.
|
||||
the data in a SHMeshAsset object.
|
||||
|
||||
\return
|
||||
SHMeshData object containing vertex data for the line cube.
|
||||
SHMeshAsset object containing vertex data for the line cube.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
[[nodiscard]] static SHMeshData LineCube() noexcept;
|
||||
[[nodiscard]] static SHMeshAsset LineCube() noexcept;
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
|
@ -158,13 +159,13 @@ namespace SHADE
|
|||
/*!
|
||||
\brief
|
||||
Produces a circle that is comprised only of lines with no diagonal lines and
|
||||
store the data in a SHMeshData object.
|
||||
store the data in a SHMeshAsset object.
|
||||
|
||||
\return
|
||||
SHMeshData object containing vertex data for the line circle.
|
||||
SHMeshAsset object containing vertex data for the line circle.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
[[nodiscard]] static SHMeshData LineCircle() noexcept;
|
||||
[[nodiscard]] static SHMeshAsset LineCircle() noexcept;
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
|
@ -204,7 +205,7 @@ namespace SHADE
|
|||
SHMeshData object containing vertex data for the line circle.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
[[nodiscard]] static SHMeshData LineCapsuleCap() noexcept;
|
||||
[[nodiscard]] static SHMeshAsset LineCapsuleCap() noexcept;
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
|
@ -239,16 +240,16 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
static Handle<SHMesh> addMeshDataTo(const SHMeshData& meshData, SHMeshLibrary& meshLibrary) noexcept;
|
||||
static Handle<SHMesh> addMeshDataTo(const SHMeshData& meshData, SHGraphicsSystem& gfxSystem) noexcept;
|
||||
static Handle<SHMesh> addMeshDataTo(const SHMeshAsset& meshData, SHMeshLibrary& meshLibrary) noexcept;
|
||||
static Handle<SHMesh> addMeshDataTo(const SHMeshAsset& meshData, SHGraphicsSystem& gfxSystem) noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
static SHMeshData cubeMesh;
|
||||
static SHMeshData sphereMesh;
|
||||
static SHMeshData lineCubeMesh;
|
||||
static SHMeshData lineCircleMesh;
|
||||
static SHMeshData lineCapsuleCapMesh;
|
||||
static SHMeshAsset cubeMesh;
|
||||
static SHMeshAsset sphereMesh;
|
||||
static SHMeshAsset lineCubeMesh;
|
||||
static SHMeshAsset lineCircleMesh;
|
||||
static SHMeshAsset lineCapsuleCapMesh;
|
||||
};
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
namespace SHADE
|
||||
{
|
||||
|
||||
Handle<SHVkPipeline> SHPipelineLibrary::CreateGraphicsPipelines(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, Handle<SHSubpass> subpass, SHVertexInputState const& viState/* = SHGraphicsPredefinedData::GetDefaultViState()*/, SHRasterizationState const& rasterState) noexcept
|
||||
Handle<SHVkPipeline> SHPipelineLibrary::CreateGraphicsPipelines(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, Handle<SHSubpass> subpass, SHGraphicsPredefinedData::SystemType systemType, SHVertexInputState const& viState, SHRasterizationState const& rasterState) noexcept
|
||||
{
|
||||
std::vector<Handle<SHVkShaderModule>> modules{};
|
||||
if (vsFsPair.first)
|
||||
|
@ -17,8 +17,8 @@ namespace SHADE
|
|||
|
||||
SHPipelineLayoutParams params
|
||||
{
|
||||
.shaderModules = std::move(modules),
|
||||
.predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts
|
||||
.shaderModules = {vsFsPair.first, vsFsPair.second},
|
||||
.predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(systemType).descSetLayouts
|
||||
};
|
||||
|
||||
// Create the pipeline layout
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace SHADE
|
|||
std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair,
|
||||
Handle<SHVkRenderpass> renderpass,
|
||||
Handle<SHSubpass> subpass,
|
||||
SHGraphicsPredefinedData::SystemType systemType,
|
||||
SHVertexInputState const& viState = SHGraphicsPredefinedData::GetDefaultViState(),
|
||||
SHRasterizationState const& rasterState = SHRasterizationState{}
|
||||
) noexcept;
|
||||
|
|
|
@ -689,11 +689,37 @@ namespace SHADE
|
|||
Handle<SHVkPipeline> pipeline = pipelineLibrary.GetGraphicsPipeline(vsFsPair);
|
||||
if (!pipeline)
|
||||
{
|
||||
// default to batching system type
|
||||
SHGraphicsPredefinedData::SystemType systemType{ SHGraphicsPredefinedData::SystemType::BATCHING };
|
||||
auto const& REFLECTED_SETS = vsFsPair.first->GetReflectedData().GetDescriptorBindingInfo().GetReflectedSets();
|
||||
|
||||
// look for animation set binding in the shader (set 2 binding 1)
|
||||
for (auto const& set : REFLECTED_SETS)
|
||||
{
|
||||
auto const mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING_ANIM);
|
||||
|
||||
// Look for set 2
|
||||
if (set->set == mappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_ANIM_BATCH))
|
||||
{
|
||||
for (int i = 0; i < set->binding_count; i++)
|
||||
{
|
||||
// look for binding 1. if found use BATCHING_ANIM system type
|
||||
if (set->bindings[i]->binding == SHGraphicsConstants::DescriptorSetBindings::BONE_MATRIX_DATA)
|
||||
{
|
||||
systemType = SHGraphicsPredefinedData::SystemType::BATCHING_ANIM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pipeline = pipelineLibrary.CreateGraphicsPipelines
|
||||
(
|
||||
vsFsPair,
|
||||
renderpass,
|
||||
subpass
|
||||
subpass,
|
||||
systemType
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,475 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
std::string SHInputManager::GetKeyCodeName(SH_KEYCODE k) noexcept
|
||||
{
|
||||
int kInt = static_cast<int>(k);
|
||||
//Numbers
|
||||
if (kInt >= static_cast<int>(SH_KEYCODE::NUMBER_0) && kInt <= static_cast<int>(SH_KEYCODE::NUMBER_9))
|
||||
{
|
||||
return std::to_string(kInt - 48);
|
||||
}
|
||||
//Letters
|
||||
if (kInt >= static_cast<int>(SH_KEYCODE::A) && kInt <= static_cast<int>(SH_KEYCODE::Z))
|
||||
{
|
||||
return std::string(1, static_cast<char>(kInt));
|
||||
}
|
||||
//Numpads
|
||||
if (kInt >= static_cast<int>(SH_KEYCODE::NUMPAD_0) && kInt <= static_cast<int>(SH_KEYCODE::NUMPAD_9))
|
||||
{
|
||||
return "Numpad " + std::to_string(kInt - 96);
|
||||
}
|
||||
//Function keys
|
||||
if (kInt >= static_cast<int>(SH_KEYCODE::F1) && kInt <= static_cast<int>(SH_KEYCODE::F24))
|
||||
{
|
||||
return "F" + std::to_string(kInt - 111);
|
||||
}
|
||||
|
||||
//Other keys
|
||||
switch (k)
|
||||
{
|
||||
case SH_KEYCODE::LMB:
|
||||
return "Left Mouse Button";
|
||||
break;
|
||||
case SH_KEYCODE::RMB:
|
||||
return "Right Mouse Button";
|
||||
break;
|
||||
case SH_KEYCODE::CANCEL:
|
||||
return "Cancel";
|
||||
break;
|
||||
case SH_KEYCODE::MMB:
|
||||
return "Middle Mouse Button";
|
||||
break;
|
||||
case SH_KEYCODE::XMB1:
|
||||
return "X1 Mouse Button";
|
||||
break;
|
||||
case SH_KEYCODE::XMB2:
|
||||
return "X2 Mouse Button";
|
||||
break;
|
||||
case SH_KEYCODE::BACKSPACE:
|
||||
return "Backspace";
|
||||
break;
|
||||
case SH_KEYCODE::TAB:
|
||||
return "Tab";
|
||||
break;
|
||||
case SH_KEYCODE::CLEAR:
|
||||
return "Clear";
|
||||
break;
|
||||
case SH_KEYCODE::ENTER:
|
||||
return "Enter";
|
||||
break;
|
||||
case SH_KEYCODE::SHIFT:
|
||||
return "Shift";
|
||||
break;
|
||||
case SH_KEYCODE::CTRL:
|
||||
return "Ctrl";
|
||||
break;
|
||||
case SH_KEYCODE::ALT:
|
||||
return "Alt";
|
||||
break;
|
||||
case SH_KEYCODE::PAUSE:
|
||||
return "Pause";
|
||||
break;
|
||||
case SH_KEYCODE::CAPS_LOCK:
|
||||
return "Caps Lock";
|
||||
break;
|
||||
case SH_KEYCODE::IME_KANA:
|
||||
return "IME Kana / Hangul Mode";
|
||||
break;
|
||||
case SH_KEYCODE::IME_ON:
|
||||
return "IME On";
|
||||
break;
|
||||
case SH_KEYCODE::IME_JUNJA:
|
||||
return "IME Junja Mode";
|
||||
break;
|
||||
case SH_KEYCODE::IME_FINAL:
|
||||
return "IME Final Mode";
|
||||
break;
|
||||
case SH_KEYCODE::IME_HANJA:
|
||||
return "IME Kanji / Hanja Mode";
|
||||
break;
|
||||
case SH_KEYCODE::IME_OFF:
|
||||
return "IME Off";
|
||||
break;
|
||||
case SH_KEYCODE::ESCAPE:
|
||||
return "Esc";
|
||||
break;
|
||||
case SH_KEYCODE::IME_CONVERT:
|
||||
return "IME Convert";
|
||||
break;
|
||||
case SH_KEYCODE::IME_NONCONVERT:
|
||||
return "IME Nonconvert";
|
||||
break;
|
||||
case SH_KEYCODE::IME_ACCEPT:
|
||||
return "IME Accept";
|
||||
break;
|
||||
case SH_KEYCODE::IME_MODECHANGE:
|
||||
return "IME Mode Change Request";
|
||||
break;
|
||||
case SH_KEYCODE::SPACE:
|
||||
return "Spacebar";
|
||||
break;
|
||||
case SH_KEYCODE::PAGE_UP:
|
||||
return "Page Up";
|
||||
break;
|
||||
case SH_KEYCODE::PAGE_DOWN:
|
||||
return "Page Down";
|
||||
break;
|
||||
case SH_KEYCODE::END:
|
||||
return "End";
|
||||
break;
|
||||
case SH_KEYCODE::HOME:
|
||||
return "Home";
|
||||
break;
|
||||
case SH_KEYCODE::LEFT_ARROW:
|
||||
return "Left Arrow";
|
||||
break;
|
||||
case SH_KEYCODE::UP_ARROW:
|
||||
return "Up Arrow";
|
||||
break;
|
||||
case SH_KEYCODE::RIGHT_ARROW:
|
||||
return "Right Arrow";
|
||||
break;
|
||||
case SH_KEYCODE::DOWN_ARROW:
|
||||
return "Down Arrow";
|
||||
break;
|
||||
case SH_KEYCODE::SELECT:
|
||||
return "Select";
|
||||
break;
|
||||
case SH_KEYCODE::PRINT:
|
||||
return "Print";
|
||||
break;
|
||||
case SH_KEYCODE::EXECUTE:
|
||||
return "Execute";
|
||||
break;
|
||||
case SH_KEYCODE::PRINT_SCREEN:
|
||||
return "Print Screen";
|
||||
break;
|
||||
case SH_KEYCODE::INSERT:
|
||||
return "Insert";
|
||||
break;
|
||||
case SH_KEYCODE::DEL:
|
||||
return "Delete";
|
||||
break;
|
||||
case SH_KEYCODE::HELP:
|
||||
return "Help";
|
||||
break;
|
||||
case SH_KEYCODE::LEFT_WINDOWS:
|
||||
return "Left Windows";
|
||||
break;
|
||||
case SH_KEYCODE::RIGHT_WINDOWS:
|
||||
return "Right Windows";
|
||||
break;
|
||||
case SH_KEYCODE::APPS:
|
||||
return "Applications";
|
||||
break;
|
||||
case SH_KEYCODE::SLEEP:
|
||||
return "Sleep";
|
||||
break;
|
||||
case SH_KEYCODE::MULTIPLY:
|
||||
return "Numpad *";
|
||||
break;
|
||||
case SH_KEYCODE::ADD:
|
||||
return "Numpad +";
|
||||
break;
|
||||
case SH_KEYCODE::SEPARATOR:
|
||||
return "Separator";
|
||||
break;
|
||||
case SH_KEYCODE::SUBTRACT:
|
||||
return "Numpad -";
|
||||
break;
|
||||
case SH_KEYCODE::DECIMAL:
|
||||
return "Numpad .";
|
||||
break;
|
||||
case SH_KEYCODE::DIVIDE:
|
||||
return "Numpad /";
|
||||
break;
|
||||
case SH_KEYCODE::NUM_LOCK:
|
||||
return "Num Lock";
|
||||
break;
|
||||
case SH_KEYCODE::SCROLL_LOCK:
|
||||
return "Scroll Lock";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_PC98_NUMPAD_EQUAL:
|
||||
return "OEM PC98 Numpad Equal / Fujitsu Dictionary";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_FUJITSU_UNREGISTER:
|
||||
return "OEM Fujitsu Unregister";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_FUJITSU_REGISTER:
|
||||
return "OEM Fujitsu Register";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_FUJITSU_LEFT_THUMB:
|
||||
return "OEM Fujitsu Left Thumb";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_FUJITSU_RIGHT_THUMB:
|
||||
return "OEM Fujitsu Right Thumb";
|
||||
break;
|
||||
case SH_KEYCODE::LEFT_SHIFT:
|
||||
return "Left Shift";
|
||||
break;
|
||||
case SH_KEYCODE::RIGHT_SHIFT:
|
||||
return "Right Shift";
|
||||
break;
|
||||
case SH_KEYCODE::LEFT_CTRL:
|
||||
return "Left Ctrl";
|
||||
break;
|
||||
case SH_KEYCODE::RIGHT_CTRL:
|
||||
return "Right Ctrl";
|
||||
break;
|
||||
case SH_KEYCODE::LEFT_ALT:
|
||||
return "Left Alt";
|
||||
break;
|
||||
case SH_KEYCODE::RIGHT_ALT:
|
||||
return "Right Alt";
|
||||
break;
|
||||
case SH_KEYCODE::BROWSER_BACK:
|
||||
return "Browser Back";
|
||||
break;
|
||||
case SH_KEYCODE::BROWSER_FORWARD:
|
||||
return "Browser Forward";
|
||||
break;
|
||||
case SH_KEYCODE::BROWSER_REFRESH:
|
||||
return "Browser Refresh";
|
||||
break;
|
||||
case SH_KEYCODE::BROWSER_STOP:
|
||||
return "Browser Stop";
|
||||
break;
|
||||
case SH_KEYCODE::BROWSER_SEARCH:
|
||||
return "Browser Search";
|
||||
break;
|
||||
case SH_KEYCODE::BROWSER_FAVOURITES:
|
||||
return "Browser Favourites";
|
||||
break;
|
||||
case SH_KEYCODE::BROWSER_HOME:
|
||||
return "Browser Start and Home";
|
||||
break;
|
||||
case SH_KEYCODE::VOLUME_MUTE:
|
||||
return "Volume Mute";
|
||||
break;
|
||||
case SH_KEYCODE::VOLUME_DOWN:
|
||||
return "Volume Down";
|
||||
break;
|
||||
case SH_KEYCODE::VOLUME_UP:
|
||||
return "Volume Up";
|
||||
break;
|
||||
case SH_KEYCODE::MEDIA_NEXT_TRACK:
|
||||
return "Media Next Track";
|
||||
break;
|
||||
case SH_KEYCODE::MEDIA_PREVIOUS_TRACK:
|
||||
return "Media Previous Track";
|
||||
break;
|
||||
case SH_KEYCODE::MEDIA_STOP:
|
||||
return "Media Stop";
|
||||
break;
|
||||
case SH_KEYCODE::MEDIA_PLAY_PAUSE:
|
||||
return "Media Play/Pause";
|
||||
break;
|
||||
case SH_KEYCODE::LAUNCH_MAIL:
|
||||
return "Launch Mail";
|
||||
break;
|
||||
case SH_KEYCODE::LAUNCH_MEDIA_SELECT:
|
||||
return "Select Media";
|
||||
break;
|
||||
case SH_KEYCODE::LAUNCH_APP_1:
|
||||
return "Launch App 1";
|
||||
break;
|
||||
case SH_KEYCODE::LAUNCH_APP_2:
|
||||
return "Launch App 2";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_1:
|
||||
return "; or :";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_PLUS:
|
||||
return "= or +";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_COMMA:
|
||||
return ", or <";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_MINUS:
|
||||
return "- or _";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_PERIOD:
|
||||
return ". or >";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_2:
|
||||
return "/ or ?";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_3:
|
||||
return "` or ~";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_4:
|
||||
return "[ or {";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_5:
|
||||
return "\\ or |";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_6:
|
||||
return "] or }";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_7:
|
||||
return "\' or \"";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_8:
|
||||
return "OEM 8";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_AX:
|
||||
return "OEM AX";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_102:
|
||||
return "< or > or \\ or |";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_ICO_HELP:
|
||||
return "ICO Help";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_ICO_00:
|
||||
return "ICO 00";
|
||||
break;
|
||||
case SH_KEYCODE::IME_PROCESS:
|
||||
return "IME Process";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_ICO_CLEAR:
|
||||
return "ICO Clear";
|
||||
break;
|
||||
case SH_KEYCODE::PACKET:
|
||||
return "Packet";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_RESET:
|
||||
return "OEM Reset";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_JUMP:
|
||||
return "OEM Jump";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_PA1:
|
||||
return "OEM PA1";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_PA2:
|
||||
return "OEM PA2";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_PA3:
|
||||
return "OEM PA3";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_WSCTRL:
|
||||
return "OEM WSCTRL";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_CUSEL:
|
||||
return "OEM CuSel";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_ATTN:
|
||||
return "OEM Attn";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_FINISH:
|
||||
return "OEM Finish";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_COPY:
|
||||
return "OEM Copy";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_AUTO:
|
||||
return "OEM Auto";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_ENLW:
|
||||
return "OEM ENLW";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_BACKTAB:
|
||||
return "OEM Backtab";
|
||||
break;
|
||||
case SH_KEYCODE::ATTN:
|
||||
return "Attn";
|
||||
break;
|
||||
case SH_KEYCODE::CRSEL:
|
||||
return "CrSel";
|
||||
break;
|
||||
case SH_KEYCODE::EXSEL:
|
||||
return "ExSel";
|
||||
break;
|
||||
case SH_KEYCODE::EREOF:
|
||||
return "Erase EOF";
|
||||
break;
|
||||
case SH_KEYCODE::PLAY:
|
||||
return "Play";
|
||||
break;
|
||||
case SH_KEYCODE::ZOOM:
|
||||
return "Zoom";
|
||||
break;
|
||||
case SH_KEYCODE::NONAME:
|
||||
return "No Name Key";
|
||||
break;
|
||||
case SH_KEYCODE::PA_1:
|
||||
return "PA1";
|
||||
break;
|
||||
case SH_KEYCODE::OEM_CLEAR:
|
||||
return "OEM Clear";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string SHInputManager::GetControllerCodeName(SH_CONTROLLERCODE c) noexcept
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case SH_CONTROLLERCODE::DPAD_UP:
|
||||
return "D-Pad Up";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::DPAD_DOWN:
|
||||
return "D-Pad Down";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::DPAD_LEFT:
|
||||
return "D-Pad Left";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::DPAD_RIGHT:
|
||||
return "D-Pad Right";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::START:
|
||||
return "Start Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::BACK:
|
||||
return "Back Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::LEFT_THUMBSTICK:
|
||||
return "Left Thumbstick Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::RIGHT_THUMBSTICK:
|
||||
return "Right Thumbstick Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::LEFT_SHOULDER:
|
||||
return "Left Shoulder Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::RIGHT_SHOULDER:
|
||||
return "Right Shoulder Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::A:
|
||||
return "A Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::B:
|
||||
return "B Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::X:
|
||||
return "X Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::Y:
|
||||
return "Y Button";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::LEFT_TRIGGER:
|
||||
return "Left Trigger";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::RIGHT_TRIGGER:
|
||||
return "Right Trigger";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::LEFT_THUMBSTICK_X:
|
||||
return "Left Thumbstick Horizontal";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::LEFT_THUMBSTICK_Y:
|
||||
return "Left Thumbstick Vertical";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::RIGHT_THUMBSTICK_X:
|
||||
return "Right Thumbstick Horizontal";
|
||||
break;
|
||||
case SH_CONTROLLERCODE::RIGHT_THUMBSTICK_Y:
|
||||
return "Right Thumbstick Vertical";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//The Binding File format presently goes as such:
|
||||
/*
|
||||
* Binding count
|
||||
|
@ -680,7 +1149,7 @@ namespace SHADE
|
|||
digitalInput = true;
|
||||
}
|
||||
if (std::abs(newValue) > std::abs(largestMagnitude))
|
||||
largestMagnitude = newValue * data.sensitivity * (data.inverted ? -1.0 : 1.0);
|
||||
largestMagnitude = newValue * (data.inverted ? -1.0 : 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -696,7 +1165,7 @@ namespace SHADE
|
|||
digitalInput = true;
|
||||
}
|
||||
if (std::abs(newValue) > std::abs(largestMagnitude))
|
||||
largestMagnitude = -newValue * data.sensitivity * (data.inverted ? -1.0 : 1.0);
|
||||
largestMagnitude = -newValue * (data.inverted ? -1.0 : 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -740,16 +1209,17 @@ namespace SHADE
|
|||
if (data.value > 1.0) data.value = 1.0;
|
||||
else if (data.value < -1.0) data.value = -1.0;
|
||||
}
|
||||
//If analog input was in,
|
||||
//sensitivity is instead used as a multiplier
|
||||
//If analog input was in, raw value taken
|
||||
else
|
||||
{
|
||||
data.value = largestMagnitude * data.sensitivity;
|
||||
data.value = largestMagnitude;
|
||||
if (data.value > 1.0) data.value = 1.0;
|
||||
else if (data.value < -1.0) data.value = -1.0;
|
||||
}
|
||||
|
||||
if (data.snap) //Snapping
|
||||
{
|
||||
if (digitalInput) //Only for digital inputs
|
||||
{
|
||||
if (data.value > 0.0 && data.negativeInputHeld)
|
||||
data.value = 0.0;
|
||||
|
@ -759,6 +1229,7 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Binding timings
|
||||
|
||||
|
@ -936,11 +1407,11 @@ namespace SHADE
|
|||
{
|
||||
return 0.0;
|
||||
}
|
||||
else if (bindings[bindingName].positiveInputHeld)
|
||||
else if (GetBindingAxis(bindingName, cNum) > 0.0)
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
else if (bindings[bindingName].negativeInputHeld)
|
||||
else if (GetBindingAxis(bindingName, cNum) < 0.0)
|
||||
{
|
||||
return -1.0;
|
||||
}
|
||||
|
|
|
@ -363,6 +363,7 @@ namespace SHADE
|
|||
|
||||
//Speed in units per second that the axis will move toward target value for digital
|
||||
//For mouse movement / scrolling, serves as multiplier
|
||||
//Irrelevant for other analog inputs
|
||||
double sensitivity = 1.0;
|
||||
|
||||
//If enabled, axis value will reset to zero when pressing a button
|
||||
|
@ -415,6 +416,12 @@ namespace SHADE
|
|||
return controllerInUse;
|
||||
}
|
||||
|
||||
//Get the name of key code
|
||||
static std::string GetKeyCodeName(SH_KEYCODE const keyCode) noexcept;
|
||||
|
||||
//Get the name of controller code
|
||||
static std::string GetControllerCodeName(SH_CONTROLLERCODE const controllerCode) noexcept;
|
||||
|
||||
//For testing purposes
|
||||
//static void PrintCurrentState() noexcept;
|
||||
|
||||
|
@ -738,6 +745,16 @@ namespace SHADE
|
|||
return bindings.erase(bindingName);
|
||||
}
|
||||
|
||||
//Rename a binding
|
||||
static inline void RenameBinding(std::string const& oldBindingName, std::string const& newBindingName) noexcept
|
||||
{
|
||||
//https://stackoverflow.com/a/44883472
|
||||
//https://en.cppreference.com/w/cpp/container/map/extract
|
||||
auto nodeHandler = bindings.extract(oldBindingName);
|
||||
nodeHandler.key() = newBindingName;
|
||||
bindings.insert(std::move(nodeHandler));
|
||||
}
|
||||
|
||||
//Clears all bindings from the list
|
||||
static inline void ClearBindings() noexcept
|
||||
{
|
||||
|
@ -809,7 +826,7 @@ namespace SHADE
|
|||
//Get the sensitivity of the binding
|
||||
//Serves as a multiplier for mouse movement/scrolling
|
||||
//For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative
|
||||
//For other analog inputs, serves as a multiplier, but axis value magnitude will still be capped at 1
|
||||
//Irrelevant for other analog inputs
|
||||
static inline double GetBindingSensitivity(std::string const& bindingName)
|
||||
{
|
||||
return bindings[bindingName].sensitivity;
|
||||
|
@ -818,7 +835,7 @@ namespace SHADE
|
|||
//Set the sensitivity of the binding
|
||||
//Serves as a multiplier for mouse movement/scrolling
|
||||
//For other digital inputs, serves as a rate of how fast axis value goes to maximum positive/negative
|
||||
//For other analog inputs, serves as a multiplier, but axis value magnitude will still be capped at 1
|
||||
//Irrelevant for other analog inputs
|
||||
static inline void SetBindingSensitivity(std::string const& bindingName, double const newValue)
|
||||
{
|
||||
bindings[bindingName].sensitivity = newValue;
|
||||
|
@ -984,8 +1001,6 @@ namespace SHADE
|
|||
|
||||
//Get the axis value of binding, between -1 and 1 for non-mouse movement/wheel
|
||||
//For mouse movement/wheel, it won't be between -1 and 1. It will also be multiplied by sensitivity
|
||||
//To avoid interference between mouse movement/wheel and keyboard/mouse/controller input,
|
||||
//Set mouseXBound, mouseYBound and mouseScrollBound to false
|
||||
//controllerNumber is not used
|
||||
static double GetBindingAxis(std::string const& bindingName, size_t controllerNumber = 0) noexcept;
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHVec4U.h
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Jan 16, 2023
|
||||
\brief Contains type alias for SHVec4U.
|
||||
|
||||
Copyright (C) 2023 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
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Simple type alias for a array of uint32_t of 4 uint32_ts.
|
||||
/// </summary>
|
||||
using SHVec4U = std::array<uint32_t, 4>;
|
||||
}
|
|
@ -176,12 +176,14 @@ namespace SHADE
|
|||
/* Type Definition */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
using LibraryDeleter = std::function<void()>;
|
||||
using LibraryClearer = std::function<void()>;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
std::unordered_map<std::type_index, void*> resourceLibs; // TODO: Replace with compile time map
|
||||
std::vector<LibraryDeleter> deleters;
|
||||
std::unordered_map<std::type_index, LibraryClearer> clearers;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
|
|
|
@ -20,9 +20,11 @@ namespace SHADE
|
|||
/* Static Data Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHResourceHub SHResourceManager::resourceHub;
|
||||
SHResourceLibrary<SHRigNode> SHResourceManager::rigNodeStore;
|
||||
std::unordered_map<std::type_index, std::unordered_map<AssetID, Handle<void>>> SHResourceManager::handlesMap;
|
||||
std::unordered_map<std::type_index, SHResourceManager::HandleAssetMap> SHResourceManager::assetIdMap;
|
||||
std::unordered_map<std::type_index, std::function<void(AssetID)>> SHResourceManager::typedFreeFuncMap;
|
||||
std::unordered_map<std::type_index, SHResourceManager::AssetFreeFunc> SHResourceManager::typedFreeFuncMap;
|
||||
std::unordered_map<std::type_index, SHResourceManager::LibraryClearer> SHResourceManager::typedFreeAllFuncMap;
|
||||
std::vector<AssetID> SHResourceManager::loadedAssetData;
|
||||
bool SHResourceManager::textureChanged = false;
|
||||
bool SHResourceManager::meshChanged = false;
|
||||
|
@ -91,6 +93,14 @@ namespace SHADE
|
|||
loadedAssetData.clear();
|
||||
}
|
||||
|
||||
void SHResourceManager::UnloadAll()
|
||||
{
|
||||
for (auto func : typedFreeAllFuncMap)
|
||||
{
|
||||
func.second();
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Query Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -13,11 +13,12 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
// STL Includes
|
||||
#include <unordered_map>
|
||||
|
||||
// Project Includes
|
||||
#include "SH_API.h"
|
||||
#include "SHResourceLibrary.h"
|
||||
#include "Assets/SHAssetMacros.h"
|
||||
#include "Assets/Asset Types/SHModelAsset.h"
|
||||
#include "Assets/Asset Types/Models/SHModelAsset.h"
|
||||
#include "Assets/Asset Types/SHTextureAsset.h"
|
||||
#include "Assets/Asset Types/SHShaderAsset.h"
|
||||
#include "Graphics/Shaders/SHVkShaderModule.h"
|
||||
|
@ -27,6 +28,8 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h"
|
||||
#include "Assets/Asset Types/SHMaterialAsset.h"
|
||||
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
|
||||
#include "Animation/SHAnimationClip.h"
|
||||
#include "Animation/SHRig.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -34,6 +37,7 @@ namespace SHADE
|
|||
/* Forward Declarations */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
class SHMaterial;
|
||||
struct SHRigNode;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
|
@ -43,12 +47,14 @@ namespace SHADE
|
|||
/// </summary>
|
||||
template<typename T = void>
|
||||
struct SHResourceLoader { using AssetType = void; };
|
||||
template<> struct SHResourceLoader<SHMesh> { using AssetType = SHMeshData; };
|
||||
template<> struct SHResourceLoader<SHMesh> { using AssetType = SHMeshAsset; };
|
||||
template<> struct SHResourceLoader<SHTexture> { using AssetType = SHTextureAsset; };
|
||||
template<> struct SHResourceLoader<SHVkShaderModule> { using AssetType = SHShaderAsset; };
|
||||
template<> struct SHResourceLoader<SHMaterialSpec> { using AssetType = SHMaterialAsset; };
|
||||
template<> struct SHResourceLoader<SHMaterial> { using AssetType = SHMaterialSpec; };
|
||||
template<> struct SHResourceLoader<SHFont> { using AssetType = SHFontAsset; };
|
||||
template<> struct SHResourceLoader<SHAnimationClip> { using AssetType = SHModelAsset; };
|
||||
template<> struct SHResourceLoader<SHRig> { using AssetType = SHModelAsset; };
|
||||
|
||||
/// <summary>
|
||||
/// Static class responsible for loading and caching runtime resources from their
|
||||
|
@ -105,6 +111,10 @@ namespace SHADE
|
|||
/// Needs to be called to finalise all changes to loads, unless at runtime.
|
||||
/// </summary>
|
||||
static void FinaliseChanges();
|
||||
/// <summary>
|
||||
/// Unloads all loaded resources.
|
||||
/// </summary>
|
||||
static void UnloadAll();
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Query Functions */
|
||||
|
@ -166,15 +176,19 @@ namespace SHADE
|
|||
using HandleAssetMap = std::unordered_map<Handle<void>, AssetID>;
|
||||
using AssetHandleMapRef = std::reference_wrapper<AssetHandleMap>;
|
||||
using HandleAssetMapRef = std::reference_wrapper<HandleAssetMap>;
|
||||
using AssetFreeFunc = std::function<void(AssetID)>;
|
||||
using LibraryClearer = std::function<void()>;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
// Handles
|
||||
static SHResourceHub resourceHub;
|
||||
static SHResourceLibrary<SHRigNode> rigNodeStore;
|
||||
static std::unordered_map<std::type_index, AssetHandleMap> handlesMap;
|
||||
static std::unordered_map<std::type_index, HandleAssetMap> assetIdMap;
|
||||
static std::unordered_map<std::type_index, std::function<void(AssetID)>> typedFreeFuncMap;
|
||||
static std::unordered_map<std::type_index, AssetFreeFunc> typedFreeFuncMap;
|
||||
static std::unordered_map<std::type_index, LibraryClearer> typedFreeAllFuncMap;
|
||||
// Pointers to temp CPU resources
|
||||
static std::vector<AssetID> loadedAssetData;
|
||||
// Dirty Flags
|
||||
|
|
|
@ -40,7 +40,9 @@ namespace SHADE
|
|||
!std::is_same_v<ResourceType, SHVkShaderModule> &&
|
||||
!std::is_same_v<ResourceType, SHMaterialSpec> &&
|
||||
!std::is_same_v<ResourceType, SHFont> &&
|
||||
!std::is_same_v<ResourceType, SHMaterial>
|
||||
!std::is_same_v<ResourceType, SHMaterial> &&
|
||||
!std::is_same_v<ResourceType, SHAnimationClip> &&
|
||||
!std::is_same_v<ResourceType, SHRig>
|
||||
)
|
||||
{
|
||||
static_assert(true, "Unsupported Resource Type specified for SHResourceManager.");
|
||||
|
@ -175,14 +177,19 @@ namespace SHADE
|
|||
{
|
||||
handlesMap.emplace(TYPE, AssetHandleMap{});
|
||||
assetIdMap.emplace(TYPE, HandleAssetMap{});
|
||||
typedFreeFuncMap.emplace
|
||||
(
|
||||
TYPE,
|
||||
[TYPE](AssetID assetId)
|
||||
typedFreeFuncMap[TYPE] = [TYPE](AssetID assetId)
|
||||
{
|
||||
static_cast<Handle<ResourceType>>(SHResourceManager::handlesMap[TYPE][assetId]).Free();
|
||||
};
|
||||
typedFreeAllFuncMap[TYPE] = [TYPE]()
|
||||
{
|
||||
auto& handlesMap = SHResourceManager::handlesMap[TYPE];
|
||||
for (auto handle : handlesMap)
|
||||
{
|
||||
static_cast<Handle<ResourceType>>(handle.second).Free();
|
||||
}
|
||||
);
|
||||
handlesMap.clear();
|
||||
};
|
||||
}
|
||||
return std::make_pair(std::ref(handlesMap[TYPE]), std::ref(assetIdMap[TYPE]));
|
||||
}
|
||||
|
@ -209,7 +216,10 @@ namespace SHADE
|
|||
assetData.VertexTangents.data(),
|
||||
assetData.VertexNormals.data(),
|
||||
assetData.Indices.size(),
|
||||
assetData.Indices.data()
|
||||
assetData.Indices.data(),
|
||||
assetData.VertexBoneIndices.empty() ? nullptr : assetData.VertexBoneIndices.data(),
|
||||
assetData.VertexBoneWeights.empty() ? nullptr : assetData.VertexBoneWeights.data(),
|
||||
assetData.BoneCount
|
||||
);
|
||||
}
|
||||
// Textures
|
||||
|
@ -345,5 +355,16 @@ namespace SHADE
|
|||
|
||||
return gfxSystem->AddFont(assetData);
|
||||
}
|
||||
// Animation Clip and Rig
|
||||
else if constexpr (std::is_same_v<ResourceType, SHRig>)
|
||||
{
|
||||
loadedAssetData.emplace_back(assetId);
|
||||
return resourceHub.Create<ResourceType>(assetData.rig, rigNodeStore);
|
||||
}
|
||||
else if constexpr (std::is_same_v<ResourceType, SHAnimationClip>)
|
||||
{
|
||||
loadedAssetData.emplace_back(assetId);
|
||||
return resourceHub.Create<ResourceType>(*assetData.anims[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,6 +204,7 @@ namespace SHADE
|
|||
AddComponentToComponentNode<SHToggleButtonComponent>(components, eid);
|
||||
|
||||
AddComponentToComponentNode<SHTextRenderableComponent>(components, eid);
|
||||
AddComponentToComponentNode<SHAnimatorComponent>(components, eid);
|
||||
|
||||
node[ComponentsNode] = components;
|
||||
|
||||
|
@ -261,6 +262,7 @@ namespace SHADE
|
|||
AddComponentID<SHButtonComponent>(componentIDList, componentsNode);
|
||||
AddComponentID<SHToggleButtonComponent>(componentIDList, componentsNode);
|
||||
AddComponentID<SHTextRenderableComponent>(componentIDList, componentsNode);
|
||||
AddComponentID<SHAnimatorComponent>(componentIDList, componentsNode);
|
||||
|
||||
return componentIDList;
|
||||
}
|
||||
|
@ -344,5 +346,6 @@ namespace SHADE
|
|||
SHSerializationHelper::InitializeComponentFromNode<SHToggleButtonComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHTextRenderableComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHLightComponent>(componentsNode, eid);
|
||||
SHSerializationHelper::InitializeComponentFromNode<SHAnimatorComponent>(componentsNode, eid);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -325,7 +325,7 @@ namespace SHADE
|
|||
{
|
||||
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(spec.fragShader);
|
||||
auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
|
||||
auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(mappings.at(SHPredefinedDescriptorTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA);
|
||||
auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(mappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH), SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA);
|
||||
int const varCount = static_cast<int>(interface->GetVariableCount());
|
||||
|
||||
for (int i = 0; i < varCount; ++i)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
||||
#include "SHSerializationTools.h"
|
||||
#include "Graphics/MiddleEnd/TextRendering/SHFont.h"
|
||||
#include "Animation/SHAnimatorComponent.h"
|
||||
#include "Physics/Collision/SHCollisionTagMatrix.h"
|
||||
|
||||
namespace YAML
|
||||
|
@ -29,6 +30,8 @@ namespace YAML
|
|||
struct HasYAMLConv<SHRenderable> : std::true_type {};
|
||||
template<>
|
||||
struct HasYAMLConv<SHTextRenderableComponent> : std::true_type {};
|
||||
template<>
|
||||
struct HasYAMLConv<SHAnimatorComponent> : std::true_type {};
|
||||
|
||||
template<>
|
||||
struct convert<SHVec4>
|
||||
|
@ -386,4 +389,33 @@ namespace YAML
|
|||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<>
|
||||
struct convert<SHAnimatorComponent>
|
||||
{
|
||||
static constexpr std::string_view RIG_YAML_TAG = "Rig";
|
||||
static constexpr std::string_view CLIP_YAML_TAG = "Clip";
|
||||
|
||||
static YAML::Node encode(SHAnimatorComponent const& rhs)
|
||||
{
|
||||
YAML::Node node;
|
||||
node[RIG_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHRig>(rhs.GetRig()).value_or(0);
|
||||
node[CLIP_YAML_TAG.data()] = SHResourceManager::GetAssetID<SHAnimationClip>(rhs.GetCurrentClip()).value_or(0);
|
||||
return node;
|
||||
}
|
||||
static bool decode(YAML::Node const& node, SHAnimatorComponent& rhs)
|
||||
{
|
||||
if (node[RIG_YAML_TAG.data()].IsDefined())
|
||||
{
|
||||
rhs.SetRig(SHResourceManager::LoadOrGet<SHRig>(node[RIG_YAML_TAG.data()].as<AssetID>()));
|
||||
}
|
||||
if (node[CLIP_YAML_TAG.data()].IsDefined())
|
||||
{
|
||||
rhs.SetClip(SHResourceManager::LoadOrGet<SHAnimationClip>(node[CLIP_YAML_TAG.data()].as<AssetID>()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -98,4 +98,35 @@ namespace SHADE
|
|||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->StopAllSounds();
|
||||
}
|
||||
|
||||
AudioClipHandler Audio::CreateAudioClip(System::String^ path)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
return AudioClipHandler(audioSys->CreateAudioClip(Convert::ToNative(path).data()));
|
||||
}
|
||||
|
||||
void Audio::AddAudioClipToBGMChannelGroup(AudioClipHandler handle)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->AddAudioClipToBGMChannelGroup(handle.NativeObject);
|
||||
}
|
||||
|
||||
void Audio::AddAudioClipToSFXChannelGroup(AudioClipHandler handle)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->AddAudioClipToSFXChannelGroup(handle.NativeObject);
|
||||
}
|
||||
|
||||
void Audio::AttachAudioClipToObject(AudioClipHandler handle, EntityID eid)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->AttachAudioClipToObject(handle.NativeObject, eid);
|
||||
}
|
||||
|
||||
void Audio::DetachAudioClipFromObject(AudioClipHandler handle)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->DetachAudioClipFromObject(handle.NativeObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
#include "Engine/GameObject.hxx"
|
||||
#include "Audio/AudioClip.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -99,5 +100,13 @@ namespace SHADE
|
|||
/// Stops playback of all sound effects and music.
|
||||
/// </summary>
|
||||
static void StopAllSounds();
|
||||
|
||||
|
||||
//to comment ltr
|
||||
static AudioClipHandler CreateAudioClip(System::String^ path);
|
||||
static void AddAudioClipToBGMChannelGroup(AudioClipHandler handle);
|
||||
static void AddAudioClipToSFXChannelGroup(AudioClipHandler handle);
|
||||
static void AttachAudioClipToObject(AudioClipHandler handle, EntityID eid);
|
||||
static void DetachAudioClipFromObject(AudioClipHandler handle);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/************************************************************************************//*!
|
||||
\file AudioClip.cxx
|
||||
\author Glence Low
|
||||
\par email: glence.low\@digipen.edu
|
||||
\date Jan 16, 2023
|
||||
\brief Contains the implementation of the functions in managed AudioClip
|
||||
|
||||
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 "AudioClip.hxx"
|
||||
// Standard Library
|
||||
#include <stdexcept>
|
||||
// Project Includes
|
||||
#include "Utility/Convert.hxx"
|
||||
#include "Resource/SHResourceManagerInterface.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<AudioClip> AudioClipHandler::NativeObject::get()
|
||||
try
|
||||
{
|
||||
return Handle<AudioClip>(Convert::ToNative(audioClipInstHandle));
|
||||
}
|
||||
catch (const BadHandleCastException&)
|
||||
{
|
||||
return Handle<AudioClip>();
|
||||
}
|
||||
GenericHandle AudioClipHandler::NativeObjectHandle::get()
|
||||
{
|
||||
return audioClipInstHandle;
|
||||
}
|
||||
AssetID AudioClipHandler::NativeAssetID::get()
|
||||
{
|
||||
return SHResourceManagerInterface::GetAssetID(Convert::ToNative(audioClipInstHandle)).value_or(INVALID_ASSET_ID);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AudioClipHandler::AudioClipHandler(Handle<AudioClip> audioClip)
|
||||
: audioClipInstHandle{ Handle<void>(audioClip) }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* AudioClip Properties Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void AudioClipHandler::Play()
|
||||
{
|
||||
NativeObject->Play();
|
||||
}
|
||||
|
||||
void AudioClipHandler::Stop(bool fadeOut)
|
||||
{
|
||||
NativeObject->Stop(fadeOut);
|
||||
}
|
||||
|
||||
void AudioClipHandler::SetPause(bool pause)
|
||||
{
|
||||
NativeObject->SetPause(pause);
|
||||
}
|
||||
|
||||
bool AudioClipHandler::IsPaused()
|
||||
{
|
||||
return NativeObject->IsPaused();
|
||||
}
|
||||
|
||||
void AudioClipHandler::SetParameter(System::String^ paramName, float value)
|
||||
{
|
||||
NativeObject->SetParameter(Convert::ToNative(paramName).data(), value);
|
||||
}
|
||||
|
||||
float AudioClipHandler::GetParameterValue(System::String^ paramName)
|
||||
{
|
||||
return NativeObject->GetParameterValue(Convert::ToNative(paramName).data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/************************************************************************************//*!
|
||||
\file AudioClip.hxx
|
||||
\author Glence Low
|
||||
\par email: glence.low\@digipen.edu
|
||||
\date Jan 16, 2023
|
||||
\brief Contains the definition of the managed Audio Clip 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 "AudioSystem/SHAudioSystem.h"
|
||||
#include "Assets/SHAssetMacros.h"
|
||||
// Project Includes
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed counterpart of the AudioSystem containing Audioclip
|
||||
/// that can be fed to Audioscripting for creating clips.
|
||||
/// </summary>
|
||||
public value struct AudioClipHandler
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Copy of the Handle to the native object.
|
||||
/// </summary>
|
||||
property Handle<AudioClip> NativeObject
|
||||
{
|
||||
Handle<AudioClip> 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 */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the AudioClip
|
||||
/// </summary>
|
||||
/// <param name="AudioClip">Handle to the native material object.</param>
|
||||
AudioClipHandler(Handle<AudioClip> audioclip);
|
||||
|
||||
public:
|
||||
|
||||
//to comment ltr
|
||||
void Play();
|
||||
void Stop(bool fadeOut);
|
||||
void SetPause(bool pause);
|
||||
bool IsPaused();
|
||||
void SetParameter(System::String^ paramName, float value);
|
||||
float GetParameterValue(System::String^ paramName);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
GenericHandle audioClipInstHandle;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue