Implemented proper error output when compiling files
This commit is contained in:
parent
0f88c23604
commit
c4cea569e1
|
@ -39,14 +39,13 @@ namespace SH_COMP
|
||||||
|
|
||||||
class MeshCompiler
|
class MeshCompiler
|
||||||
{
|
{
|
||||||
static std::string filename;
|
|
||||||
static AccessorReference accessors;
|
static AccessorReference accessors;
|
||||||
static BufferViewReference bufferViews;
|
static BufferViewReference bufferViews;
|
||||||
static BufferData buffer;
|
static BufferData buffer;
|
||||||
|
|
||||||
static inline void LoadFromFile(AssetPath path, ModelRef asset) noexcept;
|
static inline bool LoadFromFile(AssetPath path, ModelRef asset) noexcept;
|
||||||
|
|
||||||
static inline void ProcessMesh(ModelData const& data, ModelRef asset) noexcept;
|
static inline bool ProcessMesh(ModelData const& data, ModelRef asset) noexcept;
|
||||||
static inline void ProcessAnimationChannels(ModelData const& data, ModelRef asset) noexcept;
|
static inline void ProcessAnimationChannels(ModelData const& data, ModelRef asset) noexcept;
|
||||||
static inline void ProcessRigNodes(ModelData const& data, ModelRef asset) noexcept;
|
static inline void ProcessRigNodes(ModelData const& data, ModelRef asset) noexcept;
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,11 @@
|
||||||
|
|
||||||
namespace SH_COMP
|
namespace SH_COMP
|
||||||
{
|
{
|
||||||
std::string MeshCompiler::filename{""};
|
|
||||||
AccessorReference MeshCompiler::accessors{ nullptr };
|
AccessorReference MeshCompiler::accessors{ nullptr };
|
||||||
BufferViewReference MeshCompiler::bufferViews{ nullptr };
|
BufferViewReference MeshCompiler::bufferViews{ nullptr };
|
||||||
BufferData MeshCompiler::buffer{ nullptr };
|
BufferData MeshCompiler::buffer{ nullptr };
|
||||||
|
|
||||||
inline void MeshCompiler::LoadFromFile(AssetPath path, ModelRef asset) noexcept
|
inline bool MeshCompiler::LoadFromFile(AssetPath path, ModelRef asset) noexcept
|
||||||
{
|
{
|
||||||
ModelData model;
|
ModelData model;
|
||||||
tinygltf::TinyGLTF loader;
|
tinygltf::TinyGLTF loader;
|
||||||
|
@ -39,27 +38,37 @@ namespace SH_COMP
|
||||||
bool result = loader.LoadASCIIFromFile(&model, &error, &warn, path.string());
|
bool result = loader.LoadASCIIFromFile(&model, &error, &warn, path.string());
|
||||||
|
|
||||||
if (!warn.empty())
|
if (!warn.empty())
|
||||||
std::cout << "[TinyGLTF Warning] " << filename << " : " << warn << std::endl;
|
std::cout << "[TinyGLTF Warning] " << warn;
|
||||||
|
|
||||||
if (!error.empty())
|
if (!error.empty())
|
||||||
std::cout << "[TinyGLTF Error] " << filename << " : " << error << std::endl;
|
std::cout << "[TinyGLTF Error] " << error;
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
std::cout << "TinyGLTF failed to parse: " << filename << "\n";
|
std::cout << "[TinyGLTF] Failed to parse\n";
|
||||||
std::exit(1);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessMesh(model, asset);
|
if (ProcessMesh(model, asset))
|
||||||
ProcessRigNodes(model, asset);
|
{
|
||||||
ProcessAnimationChannels(model, asset);
|
auto const hasAnims {!model.animations.empty()};
|
||||||
|
if (hasAnims)
|
||||||
|
{
|
||||||
|
ProcessRigNodes(model, asset);
|
||||||
|
ProcessAnimationChannels(model, asset);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void MeshCompiler::ProcessMesh(ModelData const& data, ModelRef asset) noexcept
|
inline bool MeshCompiler::ProcessMesh(ModelData const& data, ModelRef asset) noexcept
|
||||||
{
|
{
|
||||||
accessors = &data.accessors;
|
accessors = &data.accessors;
|
||||||
bufferViews = &data.bufferViews;
|
bufferViews = &data.bufferViews;
|
||||||
buffer = data.buffers[0].data.data();
|
buffer = data.buffers[0].data.data();
|
||||||
|
auto const hasAnims {!data.animations.empty()};
|
||||||
|
|
||||||
for (auto const& mesh : data.meshes)
|
for (auto const& mesh : data.meshes)
|
||||||
{
|
{
|
||||||
|
@ -88,19 +97,25 @@ namespace SH_COMP
|
||||||
}
|
}
|
||||||
catch (std::out_of_range e)
|
catch (std::out_of_range e)
|
||||||
{
|
{
|
||||||
std::cout << "[Model Compiler] Failed to load critical data from gltf: " << filename << "\n";
|
std::cout << "[Model Compiler] Failed to load critical data from gltf\n";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
if (hasAnims)
|
||||||
{
|
{
|
||||||
FetchData(primitive.attributes.at(ATT_WEIGHTS.data()), meshIn.weights);
|
try
|
||||||
FetchData(primitive.attributes.at(ATT_JOINT.data()), meshIn.joints);
|
{
|
||||||
}
|
FetchData(primitive.attributes.at(ATT_WEIGHTS.data()), meshIn.weights);
|
||||||
catch(std::out_of_range e)
|
FetchData(primitive.attributes.at(ATT_JOINT.data()), meshIn.joints);
|
||||||
{
|
}
|
||||||
std::cout << "[Model Compiler] " << filename << ": No weights and joints found for mesh: " << mesh.name << std::endl;
|
catch(std::out_of_range e)
|
||||||
|
{
|
||||||
|
std::cout << "[Model Compiler] No weights and joints found for mesh: " << mesh.name << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -213,11 +228,16 @@ namespace SH_COMP
|
||||||
{
|
{
|
||||||
auto const asset = new ModelAsset();
|
auto const asset = new ModelAsset();
|
||||||
|
|
||||||
filename = path.filename().string();
|
if (LoadFromFile(path, *asset))
|
||||||
|
{
|
||||||
LoadFromFile(path, *asset);
|
BuildHeaders(*asset);
|
||||||
BuildHeaders(*asset);
|
MeshWriter::CompileMeshBinary(path, *asset);
|
||||||
MeshWriter::CompileMeshBinary(path, *asset);
|
std::cout << "[Model Compiler] Compiled file: " << path << "\n\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "[Model Compiler] Failed to compile file: " << path << "\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
delete asset;
|
delete asset;
|
||||||
}
|
}
|
||||||
|
@ -226,7 +246,7 @@ namespace SH_COMP
|
||||||
{
|
{
|
||||||
if (data.animations.empty())
|
if (data.animations.empty())
|
||||||
{
|
{
|
||||||
std::cout << "[Model Compiler] " << filename << ": Animations do not exist\n";
|
std::cout << "[Model Compiler] Animations do not exist\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +290,7 @@ namespace SH_COMP
|
||||||
{
|
{
|
||||||
if (data.skins.empty())
|
if (data.skins.empty())
|
||||||
{
|
{
|
||||||
std::cout << "[Model Compiler] " << filename << ": Unable to load rigs without skin, aborting";
|
std::cout << "[Model Compiler] Skins not found for asset\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue