From ffb6756d2a2dc690e173b89679335ac99d885f29 Mon Sep 17 00:00:00 2001 From: Tammo Hinrichs Date: Wed, 30 May 2018 14:56:53 +0200 Subject: [PATCH 1/2] FBX: LayeredTextures now work with embedded texture data --- code/FBXConverter.cpp | 80 +++++++++++++++++++++++-------------------- code/FBXConverter.h | 4 +++ 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index c50e88390..9c07e9c58 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -1526,6 +1526,46 @@ unsigned int Converter::ConvertVideo( const Video& video ) return static_cast( textures.size() - 1 ); } +aiString Converter::GetTexturePath(const Texture* tex) +{ + aiString path; + path.Set(tex->RelativeFilename()); + + const Video* media = tex->Media(); + if (media != 0) { + bool textureReady = false; //tells if our texture is ready (if it was loaded or if it was found) + unsigned int index; + + VideoMap::const_iterator it = textures_converted.find(media); + if (it != textures_converted.end()) { + index = (*it).second; + textureReady = true; + } + else { + if (media->ContentLength() > 0) { + index = ConvertVideo(*media); + textures_converted[media] = index; + textureReady = true; + } + } + + // setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture), if the texture is ready + if (doc.Settings().useLegacyEmbeddedTextureNaming) { + if (textureReady) { + // TODO: check the possibility of using the flag "AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING" + // In FBX files textures are now stored internally by Assimp with their filename included + // Now Assimp can lookup through the loaded textures after all data is processed + // We need to load all textures before referencing them, as FBX file format order may reference a texture before loading it + // This may occur on this case too, it has to be studied + path.data[0] = '*'; + path.length = 1 + ASSIMP_itoa10(path.data + 1, MAXLEN - 1, index); + } + } + } + + return path; +} + void Converter::TrySetTextureProperties( aiMaterial* out_mat, const TextureMap& textures, const std::string& propName, aiTextureType target, const MeshGeometry* const mesh ) @@ -1538,41 +1578,7 @@ void Converter::TrySetTextureProperties( aiMaterial* out_mat, const TextureMap& const Texture* const tex = ( *it ).second; if ( tex != 0 ) { - aiString path; - path.Set( tex->RelativeFilename() ); - - const Video* media = tex->Media(); - if (media != 0) { - bool textureReady = false; //tells if our texture is ready (if it was loaded or if it was found) - unsigned int index; - - VideoMap::const_iterator it = textures_converted.find(media); - if (it != textures_converted.end()) { - index = (*it).second; - textureReady = true; - } - else { - if (media->ContentLength() > 0) { - index = ConvertVideo(*media); - textures_converted[media] = index; - textureReady = true; - } - } - - // setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture), if the texture is ready - if (doc.Settings().useLegacyEmbeddedTextureNaming) { - if (textureReady) { - // TODO: check the possibility of using the flag "AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING" - // In FBX files textures are now stored internally by Assimp with their filename included - // Now Assimp can lookup through the loaded textures after all data is processed - // We need to load all textures before referencing them, as FBX file format order may reference a texture before loading it - // This may occur on this case too, it has to be studied - path.data[0] = '*'; - path.length = 1 + ASSIMP_itoa10(path.data + 1, MAXLEN - 1, index); - } - } - } - + aiString path = GetTexturePath(tex); out_mat->AddProperty( &path, _AI_MATKEY_TEXTURE_BASE, target, 0 ); aiUVTransform uvTrafo; @@ -1696,9 +1702,7 @@ void Converter::TrySetTextureProperties( aiMaterial* out_mat, const LayeredTextu const Texture* const tex = ( *it ).second->getTexture(texIndex); - aiString path; - path.Set( tex->RelativeFilename() ); - + aiString path = GetTexturePath(tex); out_mat->AddProperty( &path, _AI_MATKEY_TEXTURE_BASE, target, texIndex ); aiUVTransform uvTrafo; diff --git a/code/FBXConverter.h b/code/FBXConverter.h index 71d93d339..fca42e8d7 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -228,6 +228,10 @@ private: // Video -> aiTexture unsigned int ConvertVideo(const Video& video); + // ------------------------------------------------------------------------------------------------ + // convert embedded texture if necessary and return actual texture path + aiString GetTexturePath(const Texture* tex); + // ------------------------------------------------------------------------------------------------ void TrySetTextureProperties(aiMaterial* out_mat, const TextureMap& textures, const std::string& propName, From 31e75b9d5438ea4de3204555a8741119e41041d2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 31 May 2018 20:18:17 +0200 Subject: [PATCH 2/2] Update FBXConverter.cpp Replaces a 0 by nullptr. --- code/FBXConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 9c07e9c58..981203abb 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -1532,7 +1532,7 @@ aiString Converter::GetTexturePath(const Texture* tex) path.Set(tex->RelativeFilename()); const Video* media = tex->Media(); - if (media != 0) { + if (media != nullptr) { bool textureReady = false; //tells if our texture is ready (if it was loaded or if it was found) unsigned int index;