Improve binary check for gltf and gltf2.
By checking the magic token we don't depend on the extension any more and follow the official way to detect a gltf file as binary, see also https://github.com/KhronosGroup/glTF/blob/main/extensions/1.0/Khronos/KHR_binary_glTF/README.md#header and https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#binary-header.pull/5154/head
parent
03934128fc
commit
a2bdfdd05a
|
@ -93,7 +93,7 @@ const aiImporterDesc *glTFImporter::GetInfo() const {
|
||||||
bool glTFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /* checkSig */) const {
|
bool glTFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /* checkSig */) const {
|
||||||
glTF::Asset asset(pIOHandler);
|
glTF::Asset asset(pIOHandler);
|
||||||
try {
|
try {
|
||||||
asset.Load(pFile, GetExtension(pFile) == "glb");
|
asset.Load(pFile, CheckMagicToken(pIOHandler, pFile, AI_GLB_MAGIC_NUMBER, AI_COUNT_OF(AI_GLB_MAGIC_NUMBER)));
|
||||||
return asset.asset;
|
return asset.asset;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -697,7 +697,7 @@ void glTFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOS
|
||||||
|
|
||||||
// read the asset file
|
// read the asset file
|
||||||
glTF::Asset asset(pIOHandler);
|
glTF::Asset asset(pIOHandler);
|
||||||
asset.Load(pFile, GetExtension(pFile) == "glb");
|
asset.Load(pFile, CheckMagicToken(pIOHandler, pFile, AI_GLB_MAGIC_NUMBER, AI_COUNT_OF(AI_GLB_MAGIC_NUMBER)));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Copy the data out
|
// Copy the data out
|
||||||
|
|
|
@ -112,7 +112,8 @@ bool glTF2Importer::CanRead(const std::string &filename, IOSystem *pIOHandler, b
|
||||||
|
|
||||||
if (pIOHandler) {
|
if (pIOHandler) {
|
||||||
glTF2::Asset asset(pIOHandler);
|
glTF2::Asset asset(pIOHandler);
|
||||||
return asset.CanRead(filename, extension == "glb");
|
return asset.CanRead(filename, CheckMagicToken(pIOHandler, filename, AI_GLB_MAGIC_NUMBER,
|
||||||
|
AI_COUNT_OF(AI_GLB_MAGIC_NUMBER)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -1678,7 +1679,7 @@ void glTF2Importer::InternReadFile(const std::string &pFile, aiScene *pScene, IO
|
||||||
|
|
||||||
// read the asset file
|
// read the asset file
|
||||||
glTF2::Asset asset(pIOHandler, static_cast<rapidjson::IRemoteSchemaDocumentProvider *>(mSchemaDocumentProvider));
|
glTF2::Asset asset(pIOHandler, static_cast<rapidjson::IRemoteSchemaDocumentProvider *>(mSchemaDocumentProvider));
|
||||||
asset.Load(pFile, GetExtension(pFile) == "glb");
|
asset.Load(pFile, CheckMagicToken(pIOHandler, pFile, AI_GLB_MAGIC_NUMBER, AI_COUNT_OF(AI_GLB_MAGIC_NUMBER)));
|
||||||
if (asset.scene) {
|
if (asset.scene) {
|
||||||
pScene->mName = asset.scene->name;
|
pScene->mName = asset.scene->name;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue