Skip to content

Commit

Permalink
Assimp: apply some fixes to IO to make glTF importer work
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Jan 23, 2022
1 parent 5f01f3c commit 778df3c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions PlugIns/Assimp/src/AssimpLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ struct OgreIOStream : public Assimp::IOStream

size_t Read(void* pvBuffer, size_t pSize, size_t pCount)
{
return stream->read(pvBuffer, pSize * pCount);
size_t bytes = stream->read(pvBuffer, pSize * pCount);
return bytes / pSize;
}
size_t Tell() const { return stream->tell(); }
size_t FileSize() const { return stream->size(); }
Expand Down Expand Up @@ -111,8 +112,12 @@ struct OgreIOSystem : public Assimp::IOSystem
String file = StringUtil::normalizeFilePath(pFile, false);
DataStreamPtr res;
if (file == source->getName())
{
res = source;

// glTF2 importer wants to open files multiple times
// while this is not fully correct, this makes it happy
source->seek(0);
}
if (!res)
res = ResourceGroupManager::getSingleton().openResource(file, _group, NULL, false);

Expand Down Expand Up @@ -353,6 +358,10 @@ bool AssimpLoader::_load(const char* name, Assimp::Importer& importer, Mesh* mes
{
uint32 flags = aiProcessPreset_TargetRealtime_Fast | aiProcess_TransformUVCoords | aiProcess_FlipUVs;
flags &= ~(aiProcess_JoinIdenticalVertices | aiProcess_CalcTangentSpace); // optimize for fast loading

if(StringUtil::endsWith(name, ".gltf") || StringUtil::endsWith(name, ".glb"))
flags |= aiProcess_JoinIdenticalVertices;

flags |= options.postProcessSteps;
importer.SetPropertyFloat("PP_GSN_MAX_SMOOTHING_ANGLE", options.maxEdgeAngle);
const aiScene* scene = importer.ReadFile(name, flags);
Expand Down

0 comments on commit 778df3c

Please sign in to comment.