Merge master

pull/1007/head
Kim Kulling 2016-09-04 20:41:20 +02:00
parent 1f22e33b96
commit a54835c91d
1 changed files with 11 additions and 9 deletions

View File

@ -105,6 +105,8 @@ BlenderImporter::~BlenderImporter()
delete modifier_cache; delete modifier_cache;
} }
static const char* Tokens[] = { "BLENDER" };
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file. // Returns whether the class can handle the format of the given file.
bool BlenderImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const bool BlenderImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
@ -116,8 +118,7 @@ bool BlenderImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, b
else if ((!extension.length() || checkSig) && pIOHandler) { else if ((!extension.length() || checkSig) && pIOHandler) {
// note: this won't catch compressed files // note: this won't catch compressed files
const char* tokens[] = {"BLENDER"}; return SearchFileHeaderForToken(pIOHandler,pFile, Tokens,1);
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
} }
return false; return false;
} }
@ -171,7 +172,7 @@ void BlenderImporter::InternReadFile( const std::string& pFile,
char magic[8] = {0}; char magic[8] = {0};
stream->Read(magic,7,1); stream->Read(magic,7,1);
if (strcmp(magic,"BLENDER")) { if (strcmp(magic, Tokens[0] )) {
// Check for presence of the gzip header. If yes, assume it is a // Check for presence of the gzip header. If yes, assume it is a
// compressed blend file and try uncompressing it, else fail. This is to // compressed blend file and try uncompressing it, else fail. This is to
// avoid uncompressing random files which our loader might end up with. // avoid uncompressing random files which our loader might end up with.
@ -346,8 +347,9 @@ void BlenderImporter::ConvertBlendFile(aiScene* out, const Scene& in,const FileD
if (cur->object) { if (cur->object) {
if(!cur->object->parent) { if(!cur->object->parent) {
no_parents.push_back(cur->object.get()); no_parents.push_back(cur->object.get());
} else {
conv.objects.insert( cur->object.get() );
} }
else conv.objects.insert(cur->object.get());
} }
} }
for (std::shared_ptr<Base> cur = in.basact; cur; cur = cur->next) { for (std::shared_ptr<Base> cur = in.basact; cur; cur = cur->next) {
@ -404,7 +406,7 @@ void BlenderImporter::ConvertBlendFile(aiScene* out, const Scene& in,const FileD
} }
// acknowledge that the scene might come out incomplete // acknowledge that the scene might come out incomplete
// by Assimps definition of `complete`: blender scenes // by Assimp's definition of `complete`: blender scenes
// can consist of thousands of cameras or lights with // can consist of thousands of cameras or lights with
// not a single mesh between them. // not a single mesh between them.
if (!out->mNumMeshes) { if (!out->mNumMeshes) {
@ -430,8 +432,9 @@ void BlenderImporter::ResolveImage(aiMaterial* out, const Material* mat, const M
// so we can extract the file extension from it. // so we can extract the file extension from it.
const size_t nlen = strlen( img->name ); const size_t nlen = strlen( img->name );
const char* s = img->name+nlen, *e = s; const char* s = img->name+nlen, *e = s;
while ( s >= img->name && *s != '.' ) {
while (s >= img->name && *s != '.')--s; --s;
}
tex->achFormatHint[0] = s+1>e ? '\0' : ::tolower( s[1] ); tex->achFormatHint[0] = s+1>e ? '\0' : ::tolower( s[1] );
tex->achFormatHint[1] = s+2>e ? '\0' : ::tolower( s[2] ); tex->achFormatHint[1] = s+2>e ? '\0' : ::tolower( s[2] );
@ -448,8 +451,7 @@ void BlenderImporter::ResolveImage(aiMaterial* out, const Material* mat, const M
tex->pcData = reinterpret_cast<aiTexel*>(ch); tex->pcData = reinterpret_cast<aiTexel*>(ch);
LogInfo("Reading embedded texture, original file was "+std::string(img->name)); LogInfo("Reading embedded texture, original file was "+std::string(img->name));
} } else {
else {
name = aiString( img->name ); name = aiString( img->name );
} }