Add support for importing both glTF and glTF2 files
This commit is contained in:
committed by
Daniel Hritzkiv
parent
2ee7991558
commit
19876e9822
@@ -100,24 +100,18 @@ const aiImporterDesc* glTFImporter::GetInfo() const
|
||||
|
||||
bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
||||
{
|
||||
const std::string& extension = GetExtension(pFile);
|
||||
const std::string &extension = GetExtension(pFile);
|
||||
|
||||
if (extension == "gltf" || extension == "glb")
|
||||
return true;
|
||||
if (extension != "gltf" && extension != "glb")
|
||||
return false;
|
||||
|
||||
if ((checkSig || !extension.length()) && pIOHandler) {
|
||||
char buffer[4];
|
||||
|
||||
std::unique_ptr<IOStream> pStream(pIOHandler->Open(pFile));
|
||||
if (pStream && pStream->Read(buffer, sizeof(buffer), 1) == 1) {
|
||||
if (memcmp(buffer, AI_GLB_MAGIC_NUMBER, sizeof(buffer)) == 0) {
|
||||
return true; // Has GLB header
|
||||
}
|
||||
else if (memcmp(buffer, "{\r\n ", sizeof(buffer)) == 0
|
||||
|| memcmp(buffer, "{\n ", sizeof(buffer)) == 0) {
|
||||
// seems a JSON file, and we're the only format that can read them
|
||||
return true;
|
||||
}
|
||||
if (checkSig && pIOHandler) {
|
||||
glTF::Asset asset(pIOHandler);
|
||||
try {
|
||||
asset.Load(pFile, extension == "glb");
|
||||
return asset.asset.version < 2;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user