Skip to content

Commit

Permalink
Merge branch 'master' into imeshbuilder-usemorphtarget
Browse files Browse the repository at this point in the history
  • Loading branch information
ptasev committed Apr 11, 2020
2 parents 81ab609 + 1e9caa3 commit b21c8d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/SharpGLTF.Toolkit/Scenes/NodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,12 @@ private bool RenameIfAvailable(string newName, ISet<string> usedNames)
private void _DecomposeMatrix()
{
if (!_Matrix.HasValue) return;
if (_Matrix.Value == Matrix4x4.Identity) return;
_DecomposeMatrix(_Matrix.Value);

var m = _Matrix.Value;
_Matrix = null;

// we do the decomposition AFTER setting _Matrix to null to prevent an infinite recursive loop. Fixes #37
if (m != Matrix4x4.Identity) _DecomposeMatrix(m);
}

private void _DecomposeMatrix(Matrix4x4 matrix)
Expand Down
12 changes: 12 additions & 0 deletions tests/SharpGLTF.Toolkit.Tests/Scenes/SceneBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,5 +613,17 @@ public void CreateSceneWithEmptyMeshes()
scene.AttachToCurrentTest("scene.glb");
}


[Test(Description ="Regression test for #37")]
public void CreateNodeBuilderWithWorldMatrix()
{
var nbr = new NodeBuilder("Dummy1");
var nb = nbr.CreateNode("Dummy2");
nb.WorldMatrix = new Matrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1);
nb.UseTranslation().UseTrackBuilder("Default");
nb.UseRotation().UseTrackBuilder("Default");
nb.UseScale().UseTrackBuilder("Default");
}

}
}

0 comments on commit b21c8d7

Please sign in to comment.