Compare commits
No commits in common. "main" and "tinygltf" have entirely different histories.
24
premake5.lua
24
premake5.lua
|
@ -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,8 +43,7 @@ project "ModelCompiler"
|
|||
"TINYGLTF_NO_INCLUDE_STB_IMAGE",
|
||||
"TINYGLTF_NO_INCLUDE_STB_IMAGE_WRITE",
|
||||
"TINYGLTF_NO_STB_IMAGE_WRITE",
|
||||
"TINYGLTF_NO_STB_IMAGE",
|
||||
"TINYGLTF_USE_CPP14"
|
||||
"TINYGLTF_NO_STB_IMAGE"
|
||||
}
|
||||
|
||||
filter "configurations:Debug"
|
||||
|
@ -56,4 +55,5 @@ project "ModelCompiler"
|
|||
defines{"_RELEASE"}
|
||||
|
||||
filter "configurations:Publish"
|
||||
flags {"ExcludeFromBuild"}
|
||||
optimize "On"
|
||||
defines{"_RELEASE, _PUBLISH"}
|
|
@ -6058,7 +6058,6 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
|||
}
|
||||
|
||||
// 11. Parse Image
|
||||
/*
|
||||
void *load_image_user_data{nullptr};
|
||||
|
||||
LoadImageDataOption load_image_option;
|
||||
|
@ -6137,7 +6136,6 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
|||
return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// 12. Parse Texture
|
||||
{
|
||||
|
|
|
@ -39,13 +39,14 @@ namespace SH_COMP
|
|||
|
||||
class MeshCompiler
|
||||
{
|
||||
|
||||
static AccessorReference accessors;
|
||||
static BufferViewReference bufferViews;
|
||||
static BufferData buffer;
|
||||
|
||||
static inline bool LoadFromFile(AssetPath path, ModelRef asset) noexcept;
|
||||
static inline void LoadFromFile(AssetPath path, ModelRef asset) noexcept;
|
||||
|
||||
static inline bool ProcessMesh(ModelData const& data, ModelRef asset) noexcept;
|
||||
static inline void 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;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace SH_COMP
|
|||
BufferViewReference MeshCompiler::bufferViews{ nullptr };
|
||||
BufferData MeshCompiler::buffer{ nullptr };
|
||||
|
||||
inline bool MeshCompiler::LoadFromFile(AssetPath path, ModelRef asset) noexcept
|
||||
inline void MeshCompiler::LoadFromFile(AssetPath path, ModelRef asset) noexcept
|
||||
{
|
||||
ModelData model;
|
||||
tinygltf::TinyGLTF loader;
|
||||
|
@ -38,37 +38,27 @@ namespace SH_COMP
|
|||
bool result = loader.LoadASCIIFromFile(&model, &error, &warn, path.string());
|
||||
|
||||
if (!warn.empty())
|
||||
std::cout << "[TinyGLTF Warning] " << warn;
|
||||
std::cout << "[TinyGLTF Warning]: " << warn << std::endl;
|
||||
|
||||
if (!error.empty())
|
||||
std::cout << "[TinyGLTF Error] " << error;
|
||||
std::cout << "[TinyGLTF Error]: " << error << std::endl;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
std::cout << "[TinyGLTF] Failed to parse\n";
|
||||
return false;
|
||||
std::cout << "TinyGLTF failed to parse.\n";
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
if (ProcessMesh(model, asset))
|
||||
{
|
||||
auto const hasAnims {!model.animations.empty()};
|
||||
if (hasAnims)
|
||||
{
|
||||
ProcessRigNodes(model, asset);
|
||||
ProcessAnimationChannels(model, asset);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
ProcessMesh(model, asset);
|
||||
ProcessRigNodes(model, asset);
|
||||
ProcessAnimationChannels(model, asset);
|
||||
}
|
||||
|
||||
inline bool MeshCompiler::ProcessMesh(ModelData const& data, ModelRef asset) noexcept
|
||||
inline void 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)
|
||||
{
|
||||
|
@ -98,24 +88,18 @@ namespace SH_COMP
|
|||
catch (std::out_of_range e)
|
||||
{
|
||||
std::cout << "[Model Compiler] Failed to load critical data from gltf\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasAnims)
|
||||
try
|
||||
{
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -228,16 +212,9 @@ namespace SH_COMP
|
|||
{
|
||||
auto const asset = new ModelAsset();
|
||||
|
||||
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";
|
||||
}
|
||||
LoadFromFile(path, *asset);
|
||||
BuildHeaders(*asset);
|
||||
MeshWriter::CompileMeshBinary(path, *asset);
|
||||
|
||||
delete asset;
|
||||
}
|
||||
|
@ -290,7 +267,7 @@ namespace SH_COMP
|
|||
{
|
||||
if (data.skins.empty())
|
||||
{
|
||||
std::cout << "[Model Compiler] Skins not found for asset\n";
|
||||
std::cout << "[Model Compiler] Unable to load rigs without skin, aborting";
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::vector<std::string> paths;
|
||||
|
||||
#if 1
|
||||
|
||||
#if 0
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue