|
@@ -23,7 +23,7 @@ following conditions are met:
|
|
|
derived from this software without specific prior
|
|
|
written permission of the assimp team.
|
|
|
|
|
|
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
@@ -767,6 +767,7 @@ private:
|
|
|
|
|
|
// find user defined properties (3ds Max)
|
|
|
data->Set(index++, "UserProperties", aiString(PropertyGet<std::string>(props, "UDP3DSMAX", "")));
|
|
|
+ unparsedProperties.erase("UDP3DSMAX");
|
|
|
// preserve the info that a node was marked as Null node in the original file.
|
|
|
data->Set(index++, "IsNull", model.IsNull() ? true : false);
|
|
|
|
|
@@ -1440,6 +1441,7 @@ private:
|
|
|
|
|
|
// texture assignments
|
|
|
SetTextureProperties(out_mat,material.Textures());
|
|
|
+ SetTextureProperties(out_mat,material.LayeredTextures());
|
|
|
|
|
|
return static_cast<unsigned int>(materials.size() - 1);
|
|
|
}
|
|
@@ -1456,7 +1458,103 @@ private:
|
|
|
}
|
|
|
|
|
|
const Texture* const tex = (*it).second;
|
|
|
-
|
|
|
+ if(tex !=0 )
|
|
|
+ {
|
|
|
+ aiString path;
|
|
|
+ path.Set(tex->RelativeFilename());
|
|
|
+
|
|
|
+ out_mat->AddProperty(&path,_AI_MATKEY_TEXTURE_BASE,target,0);
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ const PropertyTable& props = tex->Props();
|
|
|
+
|
|
|
+ int uvIndex = 0;
|
|
|
+
|
|
|
+ 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;
|
|
|
+ BOOST_FOREACH(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");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ------------------------------------------------------------------------------------------------
|
|
|
+ void TrySetTextureProperties(aiMaterial* out_mat, const LayeredTextureMap& layeredTextures,
|
|
|
+ const std::string& propName,
|
|
|
+ aiTextureType target)
|
|
|
+ {
|
|
|
+ LayeredTextureMap::const_iterator it = layeredTextures.find(propName);
|
|
|
+ if(it == layeredTextures.end()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const Texture* const tex = (*it).second->getTexture();
|
|
|
+
|
|
|
aiString path;
|
|
|
path.Set(tex->RelativeFilename());
|
|
|
|
|
@@ -1490,7 +1588,7 @@ private:
|
|
|
|
|
|
const unsigned int matIndex = static_cast<unsigned int>(std::distance(materials.begin(),
|
|
|
std::find(materials.begin(),materials.end(),out_mat)
|
|
|
- ));
|
|
|
+ ));
|
|
|
|
|
|
uvIndex = -1;
|
|
|
BOOST_FOREACH(const MeshMap::value_type& v,meshes_converted) {
|
|
@@ -1539,7 +1637,6 @@ private:
|
|
|
out_mat->AddProperty(&uvIndex,1,_AI_MATKEY_UVWSRC_BASE,target,0);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
void SetTextureProperties(aiMaterial* out_mat, const TextureMap& textures)
|
|
|
{
|
|
@@ -1555,6 +1652,20 @@ private:
|
|
|
TrySetTextureProperties(out_mat, textures, "ShininessExponent", aiTextureType_SHININESS);
|
|
|
}
|
|
|
|
|
|
+ // ------------------------------------------------------------------------------------------------
|
|
|
+ void SetTextureProperties(aiMaterial* out_mat, const LayeredTextureMap& layeredTextures)
|
|
|
+ {
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "DiffuseColor", aiTextureType_DIFFUSE);
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "AmbientColor", aiTextureType_AMBIENT);
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "EmissiveColor", aiTextureType_EMISSIVE);
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "SpecularColor", aiTextureType_SPECULAR);
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "TransparentColor", aiTextureType_OPACITY);
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "ReflectionColor", aiTextureType_REFLECTION);
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "DisplacementColor", aiTextureType_DISPLACEMENT);
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "NormalMap", aiTextureType_NORMALS);
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "Bump", aiTextureType_HEIGHT);
|
|
|
+ TrySetTextureProperties(out_mat, layeredTextures, "ShininessExponent", aiTextureType_SHININESS);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|