瀏覽代碼

Fixed:

1. FBX import is unable to read the texture UV rotation angle.
2. FBX export is unable to write the texture UV rotation angle.
Pankaj Tyagi 4 年之前
父節點
當前提交
6170c49155

+ 3 - 0
code/AssetLib/FBX/FBXConverter.cpp

@@ -1766,6 +1766,7 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const TextureMap
         // XXX handle all kinds of UV transformations
         // XXX handle all kinds of UV transformations
         uvTrafo.mScaling = tex->UVScaling();
         uvTrafo.mScaling = tex->UVScaling();
         uvTrafo.mTranslation = tex->UVTranslation();
         uvTrafo.mTranslation = tex->UVTranslation();
+        uvTrafo.mRotation = tex->UVRotation();
         out_mat->AddProperty(&uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, 0);
         out_mat->AddProperty(&uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, 0);
 
 
         const PropertyTable &props = tex->Props();
         const PropertyTable &props = tex->Props();
@@ -1885,6 +1886,7 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const LayeredTex
         // XXX handle all kinds of UV transformations
         // XXX handle all kinds of UV transformations
         uvTrafo.mScaling = tex->UVScaling();
         uvTrafo.mScaling = tex->UVScaling();
         uvTrafo.mTranslation = tex->UVTranslation();
         uvTrafo.mTranslation = tex->UVTranslation();
+        uvTrafo.mRotation = tex->UVRotation();
         out_mat->AddProperty(&uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, texIndex);
         out_mat->AddProperty(&uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, texIndex);
 
 
         const PropertyTable &props = tex->Props();
         const PropertyTable &props = tex->Props();
@@ -2324,6 +2326,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial *out_mat, const PropertyTa
             // XXX handle all kinds of UV transformations
             // XXX handle all kinds of UV transformations
             uvTrafo.mScaling = tex->UVScaling();
             uvTrafo.mScaling = tex->UVScaling();
             uvTrafo.mTranslation = tex->UVTranslation();
             uvTrafo.mTranslation = tex->UVTranslation();
+            uvTrafo.mRotation = tex->UVRotation();
             out_mat->AddProperty(&uvTrafo, 1, (name + "|uvtrafo").c_str(), aiTextureType_UNKNOWN, 0);
             out_mat->AddProperty(&uvTrafo, 1, (name + "|uvtrafo").c_str(), aiTextureType_UNKNOWN, 0);
 
 
             int uvIndex = 0;
             int uvIndex = 0;

+ 5 - 0
code/AssetLib/FBX/FBXDocument.h

@@ -500,6 +500,10 @@ public:
         return uvScaling;
         return uvScaling;
     }
     }
 
 
+    const ai_real &UVRotation() const {
+        return uvRotation;
+    }
+
     const PropertyTable& Props() const {
     const PropertyTable& Props() const {
         ai_assert(props.get());
         ai_assert(props.get());
         return *props.get();
         return *props.get();
@@ -517,6 +521,7 @@ public:
 private:
 private:
     aiVector2D uvTrans;
     aiVector2D uvTrans;
     aiVector2D uvScaling;
     aiVector2D uvScaling;
+    ai_real    uvRotation;
 
 
     std::string type;
     std::string type;
     std::string relativeFileName;
     std::string relativeFileName;

+ 7 - 0
code/AssetLib/FBX/FBXExporter.cpp

@@ -1688,6 +1688,10 @@ void FBXExporter::WriteObjects ()
             // link the image data to the texture
             // link the image data to the texture
             connections.emplace_back("C", "OO", image_uid, texture_uid);
             connections.emplace_back("C", "OO", image_uid, texture_uid);
 
 
+            aiUVTransform trafo;
+            unsigned int max = sizeof(aiUVTransform);
+            aiGetMaterialFloatArray(mat, AI_MATKEY_UVTRANSFORM(aiTextureType_DIFFUSE, 0), (float *)&trafo, &max);
+
             // now write the actual texture node
             // now write the actual texture node
             FBX::Node tnode("Texture");
             FBX::Node tnode("Texture");
             // TODO: some way to determine texture name?
             // TODO: some way to determine texture name?
@@ -1698,6 +1702,9 @@ void FBXExporter::WriteObjects ()
             tnode.AddChild("Version", int32_t(202));
             tnode.AddChild("Version", int32_t(202));
             tnode.AddChild("TextureName", texture_name);
             tnode.AddChild("TextureName", texture_name);
             FBX::Node p("Properties70");
             FBX::Node p("Properties70");
+            p.AddP70vectorA("Translation", trafo.mTranslation[0], trafo.mTranslation[1], 0.0);
+            p.AddP70vectorA("Rotation", 0, 0, trafo.mRotation);
+            p.AddP70vectorA("Scaling", trafo.mScaling[0], trafo.mScaling[1], 0.0);
             p.AddP70enum("CurrentTextureBlendMode", 0); // TODO: verify
             p.AddP70enum("CurrentTextureBlendMode", 0); // TODO: verify
             //p.AddP70string("UVSet", ""); // TODO: how should this work?
             //p.AddP70string("UVSet", ""); // TODO: how should this work?
             p.AddP70bool("UseMaterial", 1);
             p.AddP70bool("UseMaterial", 1);

+ 5 - 0
code/AssetLib/FBX/FBXMaterial.cpp

@@ -210,6 +210,11 @@ Texture::Texture(uint64_t id, const Element& element, const Document& doc, const
         uvTrans.y = trans.y;
         uvTrans.y = trans.y;
     }
     }
 
 
+    const aiVector3D &rotation = PropertyGet<aiVector3D>(*props, "Rotation", ok);
+    if (ok) {
+        uvRotation = rotation.z;
+    }
+
     // resolve video links
     // resolve video links
     if(doc.Settings().readTextures) {
     if(doc.Settings().readTextures) {
         const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID());
         const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID());