Browse Source

fix obj exporter bugs

MonkeyFirst 10 years ago
parent
commit
4a9fb69f62
1 changed files with 5 additions and 2 deletions
  1. 5 2
      Source/Urho3D/Graphics/Drawable.cpp

+ 5 - 2
Source/Urho3D/Graphics/Drawable.cpp

@@ -467,6 +467,9 @@ bool WriteDrawablesToOBJ(PODVector<Drawable*> drawables, File* outputFile, bool
 
 
         Node* node = drawable->GetNode();
         Node* node = drawable->GetNode();
         Matrix3x4 transMat = drawable->GetNode()->GetWorldTransform();
         Matrix3x4 transMat = drawable->GetNode()->GetWorldTransform();
+        Matrix3x4 n = transMat.Inverse();
+        Matrix3 normalMat = Matrix3(n.m00_, n.m01_, n.m02_, n.m10_, n.m11_, n.m12_, n.m20_, n.m21_, n.m22_);
+        normalMat = normalMat.Transpose();
 
 
         const Vector<SourceBatch>& batches = drawable->GetBatches();
         const Vector<SourceBatch>& batches = drawable->GetBatches();
         for (unsigned geoIndex = 0; geoIndex < batches.Size(); ++geoIndex)
         for (unsigned geoIndex = 0; geoIndex < batches.Size(); ++geoIndex)
@@ -527,8 +530,8 @@ bool WriteDrawablesToOBJ(PODVector<Drawable*> drawables, File* outputFile, bool
                     const unsigned normalOffset = VertexBuffer::GetElementOffset(elementMask, ELEMENT_NORMAL);
                     const unsigned normalOffset = VertexBuffer::GetElementOffset(elementMask, ELEMENT_NORMAL);
                     for (unsigned j = 0; j < vertexCount; ++j)
                     for (unsigned j = 0; j < vertexCount; ++j)
                     {
                     {
-                        Vector3 vertexNormal = *((const Vector3*)(&vertexData[(vertexStart + j) * elementSize + positionOffset]));
-                        vertexNormal = transMat * vertexNormal;
+                        Vector3 vertexNormal = *((const Vector3*)(&vertexData[(vertexStart + j) * elementSize + normalOffset]));
+                        vertexNormal = normalMat * vertexNormal;
                         vertexNormal.Normalize();
                         vertexNormal.Normalize();
 
 
                         if (asRightHanded)
                         if (asRightHanded)