Skip to content

Commit 6867f84

Browse files
authored
do not preserve FBX Pivots (#2141)
1 parent 1d55ae5 commit 6867f84

File tree

1 file changed

+12
-86
lines changed

1 file changed

+12
-86
lines changed

src/Xna.Framework.Content.Pipeline.Graphics/OpenAssetImporter.cs

+12-86
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,9 @@ public override NodeContent Import(string filename, ContentImporterContext conte
152152

153153
using (AssimpContext importer = new AssimpContext())
154154
{
155-
// TODO: check if we can set FBXPreservePivotsConfig(false) and clean up the code.
156-
157155
// FBXPreservePivotsConfig(false) can be set to remove transformation
158-
// pivots. However, Assimp does not automatically correct animations!
159-
// --> Leave default settings, handle transformation pivots explicitly.
160-
//importer.SetConfig(new Assimp.Configs.FBXPreservePivotsConfig(false));
156+
// pivots.
157+
importer.SetConfig(new Assimp.Configs.FBXPreservePivotsConfig(false));
161158

162159
// Set flag to remove degenerate faces (points and lines).
163160
// This flag is very important when PostProcessSteps.FindDegenerates is used
@@ -429,15 +426,6 @@ private NodeContent ImportNodes(ContentImporterContext context, Scene aiScene, N
429426

430427
node = mesh;
431428
}
432-
else if (aiNode.Name.Contains("_$AssimpFbx$"))
433-
{
434-
// This is a transformation pivot.
435-
// <OriginalName>_$AssimpFbx$_<TransformName>
436-
// where <TransformName> is one of
437-
// Translation, RotationOffset, RotationPivot, PreRotation, Rotation,
438-
// PostRotation, RotationPivotInverse, ScalingOffset, ScalingPivot,
439-
// Scaling, ScalingPivotInverse
440-
}
441429
else if (!_bones.Contains(aiNode)) // Ignore bones.
442430
{
443431
node = new NodeContent();
@@ -608,10 +596,7 @@ private static Node FindRootBone(Scene aiScene, string boneName)
608596
Node rootBone = node;
609597
while (node != aiScene.RootNode && !node.HasMeshes)
610598
{
611-
// Only when FBXPreservePivotsConfig(true):
612-
// The FBX path likes to put these extra preserve pivot nodes in here.
613-
if (!node.Name.Contains("$AssimpFbx$"))
614-
rootBone = node;
599+
rootBone = node;
615600

616601
node = node.Parent;
617602
}
@@ -655,19 +640,8 @@ private NodeContent ImportBones(Node aiNode, Node aiParent, NodeContent parent)
655640
Debug.Assert(aiParent != null);
656641

657642
NodeContent node = null;
658-
if (!aiNode.Name.Contains("_$AssimpFbx$")) // Ignore pivot nodes
659643
{
660-
const string mangling = "_$AssimpFbxNull$"; // Null leaf nodes are helpers
661-
662-
if (aiNode.Name.Contains(mangling))
663-
{
664-
// Null leaf node
665-
node = new NodeContent();
666-
node.Name = aiNode.Name.Replace(mangling, string.Empty);
667-
node.Identity = _identity;
668-
node.Transform = ToXna(GetRelativeTransform(aiNode, aiParent));
669-
}
670-
else if (_bones.Contains(aiNode))
644+
if (_bones.Contains(aiNode))
671645
{
672646
// Bone
673647
node = new BoneContent();
@@ -752,26 +726,23 @@ private NodeContent ImportBones(Node aiNode, Node aiParent, NodeContent parent)
752726
private AnimationContent ImportAnimation(Animation aiAnimation, string nodeName = null)
753727
{
754728
AnimationContent animation = new AnimationContent();
755-
animation.Name = GetAnimationName(aiAnimation.Name);
729+
animation.Name = aiAnimation.Name.Replace("AnimStack::", string.Empty);
756730
animation.Identity = _identity;
757731
animation.Duration = TimeSpan.FromSeconds(aiAnimation.DurationInTicks / aiAnimation.TicksPerSecond);
758732

759733
// In Assimp animation channels may be split into separate channels.
760-
// "nodeXyz" --> "nodeXyz_$AssimpFbx$_Translation",
761-
// "nodeXyz_$AssimpFbx$_Rotation",
762-
// "nodeXyz_$AssimpFbx$_Scaling"
763-
// Group animation channels by name (strip the "_$AssimpFbx$" part).
734+
// Group animation channels by name.
764735
IEnumerable<IGrouping<string,NodeAnimationChannel>> channelGroups;
765736
if (nodeName != null)
766737
{
767738
channelGroups = aiAnimation.NodeAnimationChannels
768-
.Where(channel => nodeName == GetNodeName(channel.NodeName))
769-
.GroupBy(channel => GetNodeName(channel.NodeName));
739+
.Where(channel => nodeName == channel.NodeName)
740+
.GroupBy(channel => channel.NodeName);
770741
}
771742
else
772743
{
773744
channelGroups = aiAnimation.NodeAnimationChannels
774-
.GroupBy(channel => GetNodeName(channel.NodeName));
745+
.GroupBy(channel => channel.NodeName);
775746
}
776747

777748
foreach (IGrouping<string,NodeAnimationChannel> channelGroup in channelGroups)
@@ -785,33 +756,9 @@ private AnimationContent ImportAnimation(Animation aiAnimation, string nodeName
785756

786757
foreach (NodeAnimationChannel aiChannel in channelGroup)
787758
{
788-
if (aiChannel.NodeName.EndsWith("_$AssimpFbx$_Scaling"))
789-
{
790-
scaleKeys = aiChannel.ScalingKeys;
791-
792-
Debug.Assert(!aiChannel.HasRotationKeys || (aiChannel.RotationKeyCount == 1 && (aiChannel.RotationKeys[0].Value == new Assimp.Quaternion(1, 0, 0, 0) || aiChannel.RotationKeys[0].Value == new Assimp.Quaternion(0, 0, 0, 0))));
793-
Debug.Assert(!aiChannel.HasPositionKeys || (aiChannel.PositionKeyCount == 1 && aiChannel.PositionKeys[0].Value == new Vector3D(0, 0, 0)));
794-
}
795-
else if (aiChannel.NodeName.EndsWith("_$AssimpFbx$_Rotation"))
796-
{
797-
rotationKeys = aiChannel.RotationKeys;
798-
799-
Debug.Assert(!aiChannel.HasScalingKeys || (aiChannel.ScalingKeyCount == 1 && aiChannel.ScalingKeys[0].Value == new Vector3D(1, 1, 1)));
800-
Debug.Assert(!aiChannel.HasPositionKeys || (aiChannel.PositionKeyCount == 1 && aiChannel.PositionKeys[0].Value == new Vector3D(0, 0, 0)));
801-
}
802-
else if (aiChannel.NodeName.EndsWith("_$AssimpFbx$_Translation"))
803-
{
804-
translationKeys = aiChannel.PositionKeys;
805-
806-
Debug.Assert(!aiChannel.HasScalingKeys || (aiChannel.ScalingKeyCount == 1 && aiChannel.ScalingKeys[0].Value == new Vector3D(1, 1, 1)));
807-
Debug.Assert(!aiChannel.HasRotationKeys || (aiChannel.RotationKeyCount == 1 && (aiChannel.RotationKeys[0].Value == new Assimp.Quaternion(1, 0, 0, 0) || aiChannel.RotationKeys[0].Value == new Assimp.Quaternion(0, 0, 0, 0))));
808-
}
809-
else
810-
{
811-
scaleKeys = aiChannel.ScalingKeys;
812-
rotationKeys = aiChannel.RotationKeys;
813-
translationKeys = aiChannel.PositionKeys;
814-
}
759+
scaleKeys = aiChannel.ScalingKeys;
760+
rotationKeys = aiChannel.RotationKeys;
761+
translationKeys = aiChannel.PositionKeys;
815762
}
816763

817764
int scaleIndex = -1;
@@ -980,27 +927,6 @@ private static Matrix4x4 GetRelativeTransform(Node node, Node ancestorNode)
980927
return transform;
981928
}
982929

983-
/// <summary>
984-
/// Gets the animation name without the "AnimStack::" part.
985-
/// </summary>
986-
/// <param name="name">The mangled animation name.</param>
987-
/// <returns>The original animation name.</returns>
988-
private static string GetAnimationName(string name)
989-
{
990-
return name.Replace("AnimStack::", string.Empty);
991-
}
992-
993-
/// <summary>
994-
/// Gets the node name without the "_$AssimpFbx$" part.
995-
/// </summary>
996-
/// <param name="name">The mangled node name.</param>
997-
/// <returns>The original node name.</returns>
998-
private static string GetNodeName(string name)
999-
{
1000-
int index = name.IndexOf("_$AssimpFbx$", StringComparison.Ordinal);
1001-
return (index >= 0) ? name.Remove(index) : name;
1002-
}
1003-
1004930
private static void ImportMetadata(Scene _scene, NodeContent rootNode)
1005931
{
1006932
foreach (var metaDataPair in _scene.Metadata)

0 commit comments

Comments
 (0)