in GLTFSDK.Samples/Deserialize/Source/main.cpp [188:258]
void PrintInfo(const std::experimental::filesystem::path& path)
{
// Pass the absolute path, without the filename, to the stream reader
auto streamReader = std::make_unique<StreamReader>(path.parent_path());
std::experimental::filesystem::path pathFile = path.filename();
std::experimental::filesystem::path pathFileExt = pathFile.extension();
std::string manifest;
auto MakePathExt = [](const std::string& ext)
{
return "." + ext;
};
std::unique_ptr<GLTFResourceReader> resourceReader;
// If the file has a '.gltf' extension then create a GLTFResourceReader
if (pathFileExt == MakePathExt(GLTF_EXTENSION))
{
auto gltfStream = streamReader->GetInputStream(pathFile.u8string()); // Pass a UTF-8 encoded filename to GetInputString
auto gltfResourceReader = std::make_unique<GLTFResourceReader>(std::move(streamReader));
std::stringstream manifestStream;
// Read the contents of the glTF file into a string using a std::stringstream
manifestStream << gltfStream->rdbuf();
manifest = manifestStream.str();
resourceReader = std::move(gltfResourceReader);
}
// If the file has a '.glb' extension then create a GLBResourceReader. This class derives
// from GLTFResourceReader and adds support for reading manifests from a GLB container's
// JSON chunk and resource data from the binary chunk.
if (pathFileExt == MakePathExt(GLB_EXTENSION))
{
auto glbStream = streamReader->GetInputStream(pathFile.u8string()); // Pass a UTF-8 encoded filename to GetInputString
auto glbResourceReader = std::make_unique<GLBResourceReader>(std::move(streamReader), std::move(glbStream));
manifest = glbResourceReader->GetJson(); // Get the manifest from the JSON chunk
resourceReader = std::move(glbResourceReader);
}
if (!resourceReader)
{
throw std::runtime_error("Command line argument path filename extension must be .gltf or .glb");
}
Document document;
try
{
document = Deserialize(manifest);
}
catch (const GLTFException& ex)
{
std::stringstream ss;
ss << "Microsoft::glTF::Deserialize failed: ";
ss << ex.what();
throw std::runtime_error(ss.str());
}
std::cout << "### glTF Info - " << pathFile << " ###\n\n";
PrintDocumentInfo(document);
PrintResourceInfo(document, *resourceReader);
}