Skip to content

Commit e548c3e

Browse files
committed
export rotation offsets
1 parent d1c307a commit e548c3e

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,8 +1993,10 @@ public UnityToMayaConvertSceneHelper(string uniPropertyName)
19931993

19941994
bool partT = uniPropertyName.StartsWith ("m_LocalPosition.", cc) || uniPropertyName.StartsWith("m_TranslationOffset.", cc);
19951995
bool partTx = uniPropertyName.EndsWith ("Position.x", cc) || uniPropertyName.EndsWith ("T.x", cc) || uniPropertyName.EndsWith("TranslationOffset.x", cc);
1996+
bool partRyz = uniPropertyName.StartsWith("m_RotationOffset", cc) && (uniPropertyName.EndsWith(".y") || uniPropertyName.EndsWith(".z"));
19961997

19971998
convertLtoR |= partTx;
1999+
convertLtoR |= partRyz;
19982000

19992001
convertDistance |= partT;
20002002
convertDistance |= uniPropertyName.StartsWith ("m_Intensity", cc);
@@ -2029,12 +2031,19 @@ struct FbxPropertyChannelPair {
20292031
{ "S", "Lcl Scaling" },
20302032
{ "m_LocalPosition", "Lcl Translation" },
20312033
{ "T", "Lcl Translation" },
2034+
{ "m_TranslationOffset", "Translation" },
2035+
{ "m_ScaleOffset", "Scaling" },
2036+
{ "m_RotationOffset", "Rotation" }
2037+
};
2038+
2039+
private static Dictionary<string, string> AimConstraintProperties = new Dictionary<string, string>()
2040+
{
20322041
{ "m_AimVector", "AimVector" },
20332042
{ "m_UpVector", "UpVector" },
20342043
{ "m_WorldUpVector", "WorldUpVector" },
2035-
{ "m_TranslationOffset", "Translation" },
2036-
{ "m_ScaleOffset", "Scaling" }
2044+
{ "m_RotationOffset", "RotationOffset" }
20372045
};
2046+
20382047
private static Dictionary<string, string> TransformChannels = new Dictionary<string, string>()
20392048
{
20402049
{ "x", Globals.FBXSDK_CURVENODE_COMPONENT_X },
@@ -2059,7 +2068,9 @@ struct FbxPropertyChannelPair {
20592068
};
20602069
private static Dictionary<string, string> ConstraintSourceProperties = new Dictionary<string, string>()
20612070
{
2062-
{ "m_Sources\\.Array\\.data\\[(\\d+)\\]\\.weight", "{0}.Weight" }
2071+
{ "m_Sources\\.Array\\.data\\[(\\d+)\\]\\.weight", "{0}.Weight" },
2072+
{ "m_TranslationOffsets\\.Array\\.data\\[(\\d+)\\]", "{0}.Offset T" },
2073+
{ "m_RotationOffsets\\.Array\\.data\\[\\d+)\\]", "{0}.Offset R" }
20632074
};
20642075

20652076
public FbxPropertyChannelPair(string p, string c) : this() {
@@ -2150,9 +2161,21 @@ public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPai
21502161
return true;
21512162
}
21522163

2153-
if(constraint != null && TryGetConstraintSourceChannelPairs(uniPropertyName, constraint, ref prop))
2164+
if(constraint != null)
21542165
{
2155-
return true;
2166+
// Aim constraint shares the RotationOffset property with RotationConstraint, so make sure that the correct FBX property is returned
2167+
if (constraint.GetConstraintType() == FbxConstraint.EType.eAim)
2168+
{
2169+
if (TryGetChannelPairs(uniPropertyName, propFormat, AimConstraintProperties, TransformChannels, ref prop))
2170+
{
2171+
return true;
2172+
}
2173+
}
2174+
2175+
if (TryGetConstraintSourceChannelPairs(uniPropertyName, constraint, ref prop))
2176+
{
2177+
return true;
2178+
}
21562179
}
21572180

21582181
return false;

Assets/FbxExporters/Editor/UnitTests/FbxConstraintTest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ public static IEnumerable TestCases
1515
{
1616
/* Test Weight */
1717
yield return new TestCaseData(typeof(RotationConstraint), new float[] { 1f, 20f, 30f }, new float[] { 0f, 0.5f, 1f }, "m_Weight").Returns(1);
18-
yield return new TestCaseData(typeof(RotationConstraint), new float[] { 2, 9, 33 }, new float[] { 0.1f, 0.67f, 0.2f }, "m_Sources.Array.data[0].weight").Returns(1);
18+
yield return new TestCaseData(typeof(RotationConstraint), new float[] { 2, 9, 33 }, new float[] { 0.1f, 0.67f, 0.2f }, "m_Sources.Array.data[0].weight").Returns(1);
19+
20+
/* Test Rotation */
21+
yield return new TestCaseData(typeof(RotationConstraint), new float[] { 1, 0.3f, 10f }, new float[] { -4, 39, 45 }, "m_RotationOffset.x").Returns(1);
22+
yield return new TestCaseData(typeof(RotationConstraint), new float[] { 1, 4f, 3f }, new float[] { -4, -39, 145 }, "m_RotationOffset.y").Returns(1);
23+
yield return new TestCaseData(typeof(RotationConstraint), new float[] { 1.2f, 0.8f, 10.3f }, new float[] { 194, 9, 195 }, "m_RotationOffset.z").Returns(1);
1924

2025
/* Test Aim */
2126
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 30f, 10f }, new float[] { 10f, 180f, 10f }, "m_AimVector.x").Returns(1);
2227
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 30f, 10f }, new float[] { 90f, 45f, 60f }, "m_AimVector.y").Returns(1);
2328
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 30f, 10f }, new float[] { 10f, 180f, 10f }, "m_AimVector.z").Returns(1);
29+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1, 0.3f, 10f }, new float[] { -4, 39, 45 }, "m_RotationOffset.x").Returns(1);
30+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1, 4f, 3f }, new float[] { -4, -39, 145 }, "m_RotationOffset.y").Returns(1);
31+
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1.2f, 0.8f, 10.3f }, new float[] { 194, 9, 195 }, "m_RotationOffset.z").Returns(1);
2432

2533
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 2f, 4f }, new float[] { 100f, 80f, 19f }, "m_UpVector.x").Returns(1);
2634
yield return new TestCaseData(typeof(AimConstraint), new float[] { 1f, 2f, 4f }, new float[] { 4f, 154f, 454f }, "m_UpVector.y").Returns(1);

0 commit comments

Comments
 (0)