Compare commits

...

6 Commits

Author SHA1 Message Date
Xiao Qi 24080969a6 Added flag to exclude from build in publish 2023-03-25 16:38:57 +08:00
Xiao Qi c4cea569e1 Implemented proper error output when compiling files 2023-03-07 22:59:50 +08:00
Xiao Qi 0f88c23604 Added cpp14 define for tinygltf
Commented out block in tinygltf that loads images from gltf file
2023-03-07 22:59:23 +08:00
Xiao Qi 92105f1f31 Updated program to output name of gltf asset when printing errors 2023-03-07 17:17:05 +08:00
Xiao Qi d98fb3ceb8 Commented out solution build in premake 2023-03-07 17:12:53 +08:00
XiaoQiDigipen 8efa4ab395
Merge pull request #1 from SHADE-DP/tinygltf
TinyGltf Integration
2023-03-07 16:25:44 +08:00
5 changed files with 61 additions and 37 deletions

View File

@ -1,12 +1,12 @@
outputdir = "%{wks.location}/bin/%{cfg.buildcfg}"
interdir = "%{wks.location}/bin_int"
workspace "ModelCompile"
architecture "x64"
configurations
{
"Release",
"Debug"
}
-- outputdir = "%{wks.location}/bin/%{cfg.buildcfg}"
-- interdir = "%{wks.location}/bin_int"
-- workspace "ModelCompile"
-- architecture "x64"
-- configurations
-- {
-- "Release",
-- "Debug"
-- }
project "ModelCompiler"
kind "ConsoleApp"
@ -43,7 +43,8 @@ project "ModelCompiler"
"TINYGLTF_NO_INCLUDE_STB_IMAGE",
"TINYGLTF_NO_INCLUDE_STB_IMAGE_WRITE",
"TINYGLTF_NO_STB_IMAGE_WRITE",
"TINYGLTF_NO_STB_IMAGE"
"TINYGLTF_NO_STB_IMAGE",
"TINYGLTF_USE_CPP14"
}
filter "configurations:Debug"
@ -55,5 +56,4 @@ project "ModelCompiler"
defines{"_RELEASE"}
filter "configurations:Publish"
optimize "On"
defines{"_RELEASE, _PUBLISH"}
flags {"ExcludeFromBuild"}

View File

@ -6058,6 +6058,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
}
// 11. Parse Image
/*
void *load_image_user_data{nullptr};
LoadImageDataOption load_image_option;
@ -6136,6 +6137,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
return false;
}
}
*/
// 12. Parse Texture
{

View File

@ -39,14 +39,13 @@ namespace SH_COMP
class MeshCompiler
{
static AccessorReference accessors;
static BufferViewReference bufferViews;
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 ProcessRigNodes(ModelData const& data, ModelRef asset) noexcept;

View File

@ -29,7 +29,7 @@ namespace SH_COMP
BufferViewReference MeshCompiler::bufferViews{ 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;
tinygltf::TinyGLTF loader;
@ -38,27 +38,37 @@ namespace SH_COMP
bool result = loader.LoadASCIIFromFile(&model, &error, &warn, path.string());
if (!warn.empty())
std::cout << "[TinyGLTF Warning]: " << warn << std::endl;
std::cout << "[TinyGLTF Warning] " << warn;
if (!error.empty())
std::cout << "[TinyGLTF Error]: " << error << std::endl;
std::cout << "[TinyGLTF Error] " << error;
if (!result)
{
std::cout << "TinyGLTF failed to parse.\n";
std::exit(1);
std::cout << "[TinyGLTF] Failed to parse\n";
return false;
}
ProcessMesh(model, asset);
ProcessRigNodes(model, asset);
ProcessAnimationChannels(model, asset);
if (ProcessMesh(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;
bufferViews = &data.bufferViews;
buffer = data.buffers[0].data.data();
auto const hasAnims {!data.animations.empty()};
for (auto const& mesh : data.meshes)
{
@ -88,18 +98,24 @@ namespace SH_COMP
catch (std::out_of_range e)
{
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);
FetchData(primitive.attributes.at(ATT_JOINT.data()), meshIn.joints);
}
catch(std::out_of_range e)
{
std::cout << "No weights and joints found for mesh: " << mesh.name << std::endl;
try
{
FetchData(primitive.attributes.at(ATT_WEIGHTS.data()), meshIn.weights);
FetchData(primitive.attributes.at(ATT_JOINT.data()), meshIn.joints);
}
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>
@ -212,9 +228,16 @@ namespace SH_COMP
{
auto const asset = new ModelAsset();
LoadFromFile(path, *asset);
BuildHeaders(*asset);
MeshWriter::CompileMeshBinary(path, *asset);
if (LoadFromFile(path, *asset))
{
BuildHeaders(*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;
}
@ -267,7 +290,7 @@ namespace SH_COMP
{
if (data.skins.empty())
{
std::cout << "[Model Compiler] Unable to load rigs without skin, aborting";
std::cout << "[Model Compiler] Skins not found for asset\n";
return;
}

View File

@ -17,8 +17,8 @@
int main(int argc, char* argv[])
{
std::vector<std::string> paths;
#if 0
#if 1
if (argc == 1)
{