SP3-103 SP3-104 Separated mesh and texture loading

Added in lines in SBApplication to load racoon fbx and dds textures

Racoon shows up in renderdoc hehe
This commit is contained in:
Xiao Qi 2022-09-26 14:38:12 +08:00
parent a0a57e7c29
commit 99534c1613
12 changed files with 107 additions and 5081 deletions

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -74,7 +74,11 @@ namespace Sandbox
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHRenderable>(); SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHRenderable>();
SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHTransformComponent>(); SHADE::SHComponentManager::CreateComponentSparseSet<SHADE::SHTransformComponent>();
//TODO: REMOVE AFTER PRESENTATION
SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.fbx"); SHADE::SHAssetManager::LoadDataTemp("../../Assets/racoon.fbx");
SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds");
SHADE::SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds");
//TODO: REMOVE AFTER PRESENTATION
// Set up graphics system and windows // Set up graphics system and windows
graphicsSystem->SetWindow(&window); graphicsSystem->SetWindow(&window);

View File

@ -10,6 +10,8 @@
#include "Scripting/SHScriptEngine.h" #include "Scripting/SHScriptEngine.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include "Assets/SHAssetManager.h"
using namespace SHADE; using namespace SHADE;
namespace Sandbox namespace Sandbox
@ -33,6 +35,23 @@ namespace Sandbox
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>()); SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
// Create temp meshes // Create temp meshes
const auto CUBE_MESH = SHADE::SHPrimitiveGenerator::Cube(*graphicsSystem); const auto CUBE_MESH = SHADE::SHPrimitiveGenerator::Cube(*graphicsSystem);
//graphicsSystem->BuildMeshBuffers();
//Test Racoon mesh
auto meshes = SHADE::SHAssetManager::GetAllMeshes();
std::vector<Handle<SHMesh>> handles;
for (auto const& mesh : meshes)
{
handles.push_back(graphicsSystem->AddMesh(
mesh.header.vertexCount,
mesh.vertexPosition.data(),
mesh.texCoords.data(),
mesh.vertexTangent.data(),
mesh.vertexNormal.data(),
mesh.header.indexCount,
mesh.indices.data()
));
}
graphicsSystem->BuildMeshBuffers(); graphicsSystem->BuildMeshBuffers();
// Create Materials // Create Materials
@ -44,22 +63,33 @@ namespace Sandbox
constexpr int NUM_COLS = 100; constexpr int NUM_COLS = 100;
static const SHVec3 TEST_OBJ_SPACING = { 1.0f, 1.0f, 1.0f }; static const SHVec3 TEST_OBJ_SPACING = { 1.0f, 1.0f, 1.0f };
static const SHVec3 TEST_OBJ_START_POS = { - (NUM_COLS / 2 * TEST_OBJ_SPACING.x ), 0.0f, 0.0f }; static const SHVec3 TEST_OBJ_START_POS = { - (NUM_COLS / 2 * TEST_OBJ_SPACING.x ), 0.0f, 0.0f };
for (int z = 0; z < NUM_ROWS; ++z) //for (int z = 0; z < NUM_ROWS; ++z)
for (int x = 0; x < NUM_COLS; ++x) //for (int x = 0; x < NUM_COLS; ++x)
{ //{
// auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
// auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
// auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
// renderable.Mesh = handles.front();
// renderable.SetMaterial(matInst);
// // Set initial positions
// transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, 0.0f, z * TEST_OBJ_SPACING.z });
// //transform.SetLocalScale(TEST_OBJ_SCALE);
// stressTestObjects.emplace_back(entity);
//}
auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>(); auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity); auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity); auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
renderable.Mesh = CUBE_MESH; renderable.Mesh = handles.front();
renderable.SetMaterial(matInst); renderable.SetMaterial(matInst);
// Set initial positions
transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, 0.0f, z * TEST_OBJ_SPACING.z });
//transform.SetLocalScale(TEST_OBJ_SCALE); //transform.SetLocalScale(TEST_OBJ_SCALE);
stressTestObjects.emplace_back(entity); stressTestObjects.emplace_back(entity);
}
// Create blank entity with a script // Create blank entity with a script
testObj = SHADE::SHEntityManager::CreateEntity(); testObj = SHADE::SHEntityManager::CreateEntity();

View File

@ -26,25 +26,13 @@ namespace SHADE
} }
} }
void SHDDSLoader::LoadImageAsset(std::vector<AssetPath> const& paths, std::vector<SHDDSAsset>& images) void SHDDSLoader::LoadImageAsset(AssetPath path, SHDDSAsset& asset)
{ {
std::vector<SHDDSAsset> result;
tinyddsloader::Result loadResult = tinyddsloader::Result::Success; tinyddsloader::Result loadResult = tinyddsloader::Result::Success;
AssetPath lastPath; loadResult = asset.image.Load(path.string().c_str());
for (auto const& path : paths) if (loadResult != tinyddsloader::Result::Success)
{ {
if (loadResult == tinyddsloader::Result::Success) SHLOG_ERROR("Unable to load DDS file: {} at {}", TinyDDSResultToString(loadResult), path.string());
{
result.emplace_back();
} }
else
{
SHLOG_ERROR("Unable to load DDS file: {} at {}", TinyDDSResultToString(loadResult), lastPath.string());
}
loadResult = result.back().image.Load(path.string().c_str());
lastPath = path;
}
std::swap(images, result);
} }
} }

View File

@ -13,6 +13,6 @@ namespace SHADE
private: private:
static std::string TinyDDSResultToString(tinyddsloader::Result value); static std::string TinyDDSResultToString(tinyddsloader::Result value);
public: public:
static void LoadImageAsset(std::vector<AssetPath> const& paths, std::vector<SHDDSAsset>& images); static void LoadImageAsset(AssetPath paths, SHDDSAsset& image);
}; };
} }

View File

@ -14,7 +14,7 @@ namespace SHADE
meshes.push_back(ProcessMesh(*mesh, scene)); meshes.push_back(ProcessMesh(*mesh, scene));
} }
for (size_t i{ 0 }; i < node.mNumMeshes; ++i) for (size_t i{ 0 }; i < node.mNumChildren; ++i)
{ {
ProcessNode(*node.mChildren[i], scene, meshes); ProcessNode(*node.mChildren[i], scene, meshes);
} }
@ -85,7 +85,7 @@ namespace SHADE
return result; return result;
} }
bool SHMeshLoader::LoadMesh(std::vector<SHMeshAsset>& meshes, std::vector<AssetPath>& images, AssetPath path) bool SHMeshLoader::LoadMesh(std::vector<SHMeshAsset>& meshes, AssetPath path)
{ {
const aiScene* scene = aiImporter.ReadFile(path.string().c_str(), const aiScene* scene = aiImporter.ReadFile(path.string().c_str(),
aiProcess_Triangulate aiProcess_Triangulate
@ -111,11 +111,18 @@ namespace SHADE
SHLOG_ERROR("ERROR in GLTF::ASSIMP: {}\nFile: {}", aiImporter.GetErrorString(), path.string()); SHLOG_ERROR("ERROR in GLTF::ASSIMP: {}\nFile: {}", aiImporter.GetErrorString(), path.string());
return false; return false;
} }
//TODO MATERIALS FROM MESHES
for (size_t i {0}; i < scene->mNumTextures; ++i) //if (scene->HasMaterials())
{ //{
images.push_back(AssetPath(scene->mTextures[i]->mFilename.C_Str())); // for (int i{0}; i < scene->mNumMaterials; ++i)
} // {
// if (scene->mMaterials[i]->mNumProperties > 0)
// {
// for (int j{0}; j < scene->mMaterials[i]->mProperties[j].)
// }
//std::cout << scene->mMaterials[i]->;
// }
//}
ProcessNode(*scene->mRootNode, *scene, meshes); ProcessNode(*scene->mRootNode, *scene, meshes);

View File

@ -16,6 +16,6 @@ namespace SHADE
static SHMeshAsset ProcessMesh(aiMesh const& mesh, aiScene const& scene); static SHMeshAsset ProcessMesh(aiMesh const& mesh, aiScene const& scene);
public: public:
static bool LoadMesh(std::vector<SHMeshAsset>& meshes, std::vector<AssetPath>& images, AssetPath path); static bool LoadMesh(std::vector<SHMeshAsset>& meshes, AssetPath path);
}; };
} }

View File

@ -70,7 +70,7 @@ enum class AssetType : uint8_t
#define PREFAB_EXTENSION ".SHPrefab" #define PREFAB_EXTENSION ".SHPrefab"
#define MATERIAL_EXTENSION ".SHMat" #define MATERIAL_EXTENSION ".SHMat"
#define TEXTURE_EXTENSION ".dds" #define TEXTURE_EXTENSION ".dds"
#define MESH_EXTENSION ".gltf" #define MESH_EXTENSION ".fbx"
std::string const EXTENSIONS[] = { std::string const EXTENSIONS[] = {
AUDIO_EXTENSION, AUDIO_EXTENSION,

View File

@ -199,6 +199,8 @@ namespace SHADE
{ {
AssetPath path{ p }; AssetPath path{ p };
if (path.extension().string() == MESH_EXTENSION)
{
LoadGLTF( LoadGLTF(
{ {
.name {path.filename().string()}, .name {path.filename().string()},
@ -208,8 +210,30 @@ namespace SHADE
.location {0} .location {0}
} }
); );
}
else if (path.extension().string() == TEXTURE_EXTENSION)
{
LoadDDS(
{
.name {path.filename().string()},
.id {0},
.type {AssetType::DDS},
.path {path},
.location {0}
}
);
}
}
SHLOG_INFO("Loaded meshes\n"); std::vector<SHMeshAsset> SHAssetManager::GetAllMeshes() noexcept
{
std::vector<SHMeshAsset> result;
for (auto const& mesh : meshCollection)
{
result.push_back(mesh.second);
}
return result;
} }
/**************************************************************************** /****************************************************************************
@ -259,24 +283,22 @@ namespace SHADE
void SHAssetManager::LoadGLTF(SHAsset asset) noexcept void SHAssetManager::LoadGLTF(SHAsset asset) noexcept
{ {
std::vector<SHMeshAsset> meshes; std::vector<SHMeshAsset> meshes;
std::vector<AssetPath> imagePaths;
std::vector<SHDDSAsset> images;
SHMeshLoader::LoadMesh(meshes, imagePaths, asset.path); SHMeshLoader::LoadMesh(meshes, asset.path);
SHDDSLoader::LoadImageAsset(imagePaths, images);
//TODO Recognise new meshes as asset as well and write mesh into binary
//TODO
for (auto const& mesh : meshes) for (auto const& mesh : meshes)
{ {
meshCollection.emplace(GenerateAssetID(AssetType::MESH), mesh); meshCollection.emplace(GenerateAssetID(AssetType::MESH), mesh);
} }
for (auto const& image : images)
{
ddsCollection.emplace(GenerateAssetID(AssetType::DDS), image);
} }
void SHAssetManager::LoadDDS(SHAsset asset) noexcept
{
SHDDSAsset image;
SHDDSLoader::LoadImageAsset(asset.path, image);
ddsCollection.emplace(GenerateAssetID(AssetType::DDS), image);
} }
/**************************************************************************** /****************************************************************************

View File

@ -72,6 +72,7 @@ namespace SHADE
//TODO: TEMPORARY FOR TESTING GLTF & DDS //TODO: TEMPORARY FOR TESTING GLTF & DDS
static void LoadDataTemp(std::string path) noexcept; static void LoadDataTemp(std::string path) noexcept;
static std::vector<SHMeshAsset> GetAllMeshes() noexcept;
private: private:
/**************************************************************************** /****************************************************************************
@ -116,6 +117,7 @@ namespace SHADE
// Specialised load calls // Specialised load calls
static void LoadGLTF(SHAsset asset) noexcept; static void LoadGLTF(SHAsset asset) noexcept;
static void LoadDDS(SHAsset asset) noexcept;
static FMOD::System* audioSystem; static FMOD::System* audioSystem;
static std::unordered_map<AssetID,SHSound>* audioSoundList; static std::unordered_map<AssetID,SHSound>* audioSoundList;