|
@@ -1916,57 +1916,92 @@ void Converter::TrySetTextureProperties( aiMaterial* out_mat, const LayeredTextu
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const Texture* const tex = ( *it ).second->getTexture();
|
|
|
+ int texCount = (*it).second->textureCount();
|
|
|
+
|
|
|
+ // Set the blend mode for layered textures
|
|
|
+ int blendmode= (*it).second->GetBlendMode();
|
|
|
+ out_mat->AddProperty(&blendmode,1,_AI_MATKEY_TEXOP_BASE,target,0);
|
|
|
|
|
|
- aiString path;
|
|
|
- path.Set( tex->RelativeFilename() );
|
|
|
+ for(int texIndex = 0; texIndex < texCount; texIndex++){
|
|
|
+
|
|
|
+ const Texture* const tex = ( *it ).second->getTexture(texIndex);
|
|
|
|
|
|
- out_mat->AddProperty( &path, _AI_MATKEY_TEXTURE_BASE, target, 0 );
|
|
|
+ aiString path;
|
|
|
+ path.Set( tex->RelativeFilename() );
|
|
|
|
|
|
- aiUVTransform uvTrafo;
|
|
|
- // XXX handle all kinds of UV transformations
|
|
|
- uvTrafo.mScaling = tex->UVScaling();
|
|
|
- uvTrafo.mTranslation = tex->UVTranslation();
|
|
|
- out_mat->AddProperty( &uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, 0 );
|
|
|
+ out_mat->AddProperty( &path, _AI_MATKEY_TEXTURE_BASE, target, texIndex );
|
|
|
|
|
|
- const PropertyTable& props = tex->Props();
|
|
|
+ aiUVTransform uvTrafo;
|
|
|
+ // XXX handle all kinds of UV transformations
|
|
|
+ uvTrafo.mScaling = tex->UVScaling();
|
|
|
+ uvTrafo.mTranslation = tex->UVTranslation();
|
|
|
+ out_mat->AddProperty( &uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, texIndex );
|
|
|
|
|
|
- int uvIndex = 0;
|
|
|
+ const PropertyTable& props = tex->Props();
|
|
|
|
|
|
- bool ok;
|
|
|
- const std::string& uvSet = PropertyGet<std::string>( props, "UVSet", ok );
|
|
|
- if ( ok ) {
|
|
|
- // "default" is the name which usually appears in the FbxFileTexture template
|
|
|
- if ( uvSet != "default" && uvSet.length() ) {
|
|
|
- // this is a bit awkward - we need to find a mesh that uses this
|
|
|
- // material and scan its UV channels for the given UV name because
|
|
|
- // assimp references UV channels by index, not by name.
|
|
|
-
|
|
|
- // XXX: the case that UV channels may appear in different orders
|
|
|
- // in meshes is unhandled. A possible solution would be to sort
|
|
|
- // the UV channels alphabetically, but this would have the side
|
|
|
- // effect that the primary (first) UV channel would sometimes
|
|
|
- // be moved, causing trouble when users read only the first
|
|
|
- // UV channel and ignore UV channel assignments altogether.
|
|
|
-
|
|
|
- const unsigned int matIndex = static_cast<unsigned int>( std::distance( materials.begin(),
|
|
|
- std::find( materials.begin(), materials.end(), out_mat )
|
|
|
- ) );
|
|
|
-
|
|
|
- uvIndex = -1;
|
|
|
- if ( !mesh )
|
|
|
- {
|
|
|
- for( const MeshMap::value_type& v : meshes_converted ) {
|
|
|
- const MeshGeometry* const mesh = dynamic_cast<const MeshGeometry*> ( v.first );
|
|
|
- if ( !mesh ) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ int uvIndex = 0;
|
|
|
|
|
|
- const MatIndexArray& mats = mesh->GetMaterialIndices();
|
|
|
- if ( std::find( mats.begin(), mats.end(), matIndex ) == mats.end() ) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ bool ok;
|
|
|
+ const std::string& uvSet = PropertyGet<std::string>( props, "UVSet", ok );
|
|
|
+ if ( ok ) {
|
|
|
+ // "default" is the name which usually appears in the FbxFileTexture template
|
|
|
+ if ( uvSet != "default" && uvSet.length() ) {
|
|
|
+ // this is a bit awkward - we need to find a mesh that uses this
|
|
|
+ // material and scan its UV channels for the given UV name because
|
|
|
+ // assimp references UV channels by index, not by name.
|
|
|
|
|
|
+ // XXX: the case that UV channels may appear in different orders
|
|
|
+ // in meshes is unhandled. A possible solution would be to sort
|
|
|
+ // the UV channels alphabetically, but this would have the side
|
|
|
+ // effect that the primary (first) UV channel would sometimes
|
|
|
+ // be moved, causing trouble when users read only the first
|
|
|
+ // UV channel and ignore UV channel assignments altogether.
|
|
|
+
|
|
|
+ const unsigned int matIndex = static_cast<unsigned int>( std::distance( materials.begin(),
|
|
|
+ std::find( materials.begin(), materials.end(), out_mat )
|
|
|
+ ) );
|
|
|
+
|
|
|
+ uvIndex = -1;
|
|
|
+ if ( !mesh )
|
|
|
+ {
|
|
|
+ for( const MeshMap::value_type& v : meshes_converted ) {
|
|
|
+ const MeshGeometry* const mesh = dynamic_cast<const MeshGeometry*> ( v.first );
|
|
|
+ if ( !mesh ) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ const MatIndexArray& mats = mesh->GetMaterialIndices();
|
|
|
+ if ( std::find( mats.begin(), mats.end(), matIndex ) == mats.end() ) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ int index = -1;
|
|
|
+ for ( unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i ) {
|
|
|
+ if ( mesh->GetTextureCoords( i ).empty() ) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ const std::string& name = mesh->GetTextureCoordChannelName( i );
|
|
|
+ if ( name == uvSet ) {
|
|
|
+ index = static_cast<int>( i );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( index == -1 ) {
|
|
|
+ FBXImporter::LogWarn( "did not find UV channel named " + uvSet + " in a mesh using this material" );
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( uvIndex == -1 ) {
|
|
|
+ uvIndex = index;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ FBXImporter::LogWarn( "the UV channel named " + uvSet +
|
|
|
+ " appears at different positions in meshes, results will be wrong" );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
int index = -1;
|
|
|
for ( unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i ) {
|
|
|
if ( mesh->GetTextureCoords( i ).empty() ) {
|
|
@@ -1980,48 +2015,22 @@ void Converter::TrySetTextureProperties( aiMaterial* out_mat, const LayeredTextu
|
|
|
}
|
|
|
if ( index == -1 ) {
|
|
|
FBXImporter::LogWarn( "did not find UV channel named " + uvSet + " in a mesh using this material" );
|
|
|
- continue;
|
|
|
}
|
|
|
|
|
|
if ( uvIndex == -1 ) {
|
|
|
uvIndex = index;
|
|
|
}
|
|
|
- else {
|
|
|
- FBXImporter::LogWarn( "the UV channel named " + uvSet +
|
|
|
- " appears at different positions in meshes, results will be wrong" );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- int index = -1;
|
|
|
- for ( unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i ) {
|
|
|
- if ( mesh->GetTextureCoords( i ).empty() ) {
|
|
|
- break;
|
|
|
- }
|
|
|
- const std::string& name = mesh->GetTextureCoordChannelName( i );
|
|
|
- if ( name == uvSet ) {
|
|
|
- index = static_cast<int>( i );
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if ( index == -1 ) {
|
|
|
- FBXImporter::LogWarn( "did not find UV channel named " + uvSet + " in a mesh using this material" );
|
|
|
}
|
|
|
|
|
|
if ( uvIndex == -1 ) {
|
|
|
- uvIndex = index;
|
|
|
+ FBXImporter::LogWarn( "failed to resolve UV channel " + uvSet + ", using first UV channel" );
|
|
|
+ uvIndex = 0;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if ( uvIndex == -1 ) {
|
|
|
- FBXImporter::LogWarn( "failed to resolve UV channel " + uvSet + ", using first UV channel" );
|
|
|
- uvIndex = 0;
|
|
|
- }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- out_mat->AddProperty( &uvIndex, 1, _AI_MATKEY_UVWSRC_BASE, target, 0 );
|
|
|
+ out_mat->AddProperty( &uvIndex, 1, _AI_MATKEY_UVWSRC_BASE, target, texIndex );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void Converter::SetTextureProperties( aiMaterial* out_mat, const TextureMap& textures, const MeshGeometry* const mesh )
|
|
@@ -2030,6 +2039,7 @@ void Converter::SetTextureProperties( aiMaterial* out_mat, const TextureMap& tex
|
|
|
TrySetTextureProperties( out_mat, textures, "AmbientColor", aiTextureType_AMBIENT, mesh );
|
|
|
TrySetTextureProperties( out_mat, textures, "EmissiveColor", aiTextureType_EMISSIVE, mesh );
|
|
|
TrySetTextureProperties( out_mat, textures, "SpecularColor", aiTextureType_SPECULAR, mesh );
|
|
|
+ TrySetTextureProperties( out_mat, textures, "SpecularFactor", aiTextureType_SPECULAR, mesh);
|
|
|
TrySetTextureProperties( out_mat, textures, "TransparentColor", aiTextureType_OPACITY, mesh );
|
|
|
TrySetTextureProperties( out_mat, textures, "ReflectionColor", aiTextureType_REFLECTION, mesh );
|
|
|
TrySetTextureProperties( out_mat, textures, "DisplacementColor", aiTextureType_DISPLACEMENT, mesh );
|
|
@@ -2044,6 +2054,7 @@ void Converter::SetTextureProperties( aiMaterial* out_mat, const LayeredTextureM
|
|
|
TrySetTextureProperties( out_mat, layeredTextures, "AmbientColor", aiTextureType_AMBIENT, mesh );
|
|
|
TrySetTextureProperties( out_mat, layeredTextures, "EmissiveColor", aiTextureType_EMISSIVE, mesh );
|
|
|
TrySetTextureProperties( out_mat, layeredTextures, "SpecularColor", aiTextureType_SPECULAR, mesh );
|
|
|
+ TrySetTextureProperties( out_mat, layeredTextures, "SpecularFactor", aiTextureType_SPECULAR, mesh);
|
|
|
TrySetTextureProperties( out_mat, layeredTextures, "TransparentColor", aiTextureType_OPACITY, mesh );
|
|
|
TrySetTextureProperties( out_mat, layeredTextures, "ReflectionColor", aiTextureType_REFLECTION, mesh );
|
|
|
TrySetTextureProperties( out_mat, layeredTextures, "DisplacementColor", aiTextureType_DISPLACEMENT, mesh );
|