Skip to content

Commit 6d4ea1e

Browse files
Fixes OpenAssetImporter.GetRelativeTransform to return a row-major matrix (MonoGame#8671)
Fixes MonoGame#8661 ### Description of Change Fixes `OpenAssetImporter.GetRelativeTransform` to now correctly return a row-major matrix. Appears to have been broken when MonoGame#8607 removed the `ToXna(Matrix4x4 matrix)` method, resulting in the return of an incorrect column-major matrix. While this fixes the rendering of ShipGame models, I just realised other changes from that PR might have broken other things. I'll try some other 3d models and import options next I guess. --------- Co-authored-by: Simon (Darkside) Jackson <[email protected]>
1 parent 1b9c760 commit 6d4ea1e

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

MonoGame.Framework.Content.Pipeline/MonoGame.Framework.Content.Pipeline.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171

7272
<ItemGroup>
73-
<PackageReference Include="AssimpNetter" Version="5.4.3" />
73+
<PackageReference Include="AssimpNetter" Version="5.4.3.3" />
7474
<PackageReference Include="BCnEncoder.Net" Version="2.1.0" />
7575
<PackageReference Include="Microsoft.NETCore.App" Version="2.1.30" />
7676
<PackageReference Include="MonoGame.Library.FreeImage" Version="3.18.0.3" />

MonoGame.Framework.Content.Pipeline/OpenAssetImporter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ private NodeContent ImportNodes(Node aiNode, Node aiParent, NodeContent parent)
548548
_pivots.Add(originalName, pivot);
549549
}
550550

551-
Matrix transform = aiNode.Transform;
551+
Matrix transform = Matrix.Transpose(aiNode.Transform);
552552
if (aiNode.Name.EndsWith("_Translation"))
553553
pivot.Translation = transform;
554554
else if (aiNode.Name.EndsWith("_RotationOffset"))
@@ -730,7 +730,7 @@ private static Dictionary<string, Matrix> FindDeformationBones(Scene scene)
730730
if (mesh.HasBones)
731731
foreach (var bone in mesh.Bones)
732732
if (!offsetMatrices.ContainsKey(bone.Name))
733-
offsetMatrices[bone.Name] = bone.OffsetMatrix;
733+
offsetMatrices[bone.Name] = Matrix.Transpose(bone.OffsetMatrix);
734734

735735
return offsetMatrices;
736736
}
@@ -1147,7 +1147,7 @@ private static Matrix4x4 GetRelativeTransform(Node node, Node ancestor)
11471147
if (parent == null && ancestor != null)
11481148
throw new ArgumentException(string.Format("Node \"{0}\" is not an ancestor of \"{1}\".", ancestor.Name, node.Name));
11491149

1150-
return transform;
1150+
return Matrix4x4.Transpose(transform);
11511151
}
11521152

11531153
/// <summary>

Tools/MonoGame.Tools.Tests/FbxImporterTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public void Arguments()
4848
}
4949

5050
[Test]
51-
[Ignore("Disabled until latest assimp is merged on Mac and Linux or windows!")]
5251
public void Dude()
5352
{
5453
var context = new TestImporterContext("TestObj", "TestBin");
@@ -227,7 +226,7 @@ public void Dude()
227226
// returned a bigger animation duration that is correct. Looking
228227
// at the content of the FBX ascii i can see the math is:
229228
//
230-
// (57732697500 - 1924423250) / 46186158000 = 1.208 seconds
229+
// (57732697500 - 1924423250) / 46186158000 = 1.2083333 seconds
231230
//
232231
// Which is the correct result and what our FBX importer returns.
233232
// I highly suspect that XNA was wrong.
@@ -237,7 +236,7 @@ public void Dude()
237236
#if XNA
238237
Assert.AreEqual(12670000, animationContent.Duration.Ticks);
239238
#else
240-
Assert.AreEqual(12080000, animationContent.Duration.Ticks);
239+
Assert.AreEqual(12083333, animationContent.Duration.Ticks);
241240
#endif
242241

243242
// TODO: XNA assigns the identity to null on all NodeContent

0 commit comments

Comments
 (0)