Skip to content

Commit 315d298

Browse files
committed
export both inner and outer angle attribute animation
to animate cone angle in Maya, have to export animation on both attributes, otherwise penumbra angle will be animated. Allow a single Unity property to map to multiple fbx property channels for animation export.
1 parent 6474c10 commit 315d298

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,8 +1530,8 @@ protected void ExportAnimationCurve (UnityEngine.Object uniObj,
15301530
Debug.Log ("Exporting animation for " + uniObj.ToString() + " (" + uniPropertyName + ")");
15311531
}
15321532

1533-
FbxPropertyChannelPair fbxPropertyChannelPair;
1534-
if (!FbxPropertyChannelPair.TryGetValue (uniPropertyName, out fbxPropertyChannelPair)) {
1533+
FbxPropertyChannelPair[] fbxPropertyChannelPairs;
1534+
if (!FbxPropertyChannelPair.TryGetValue (uniPropertyName, out fbxPropertyChannelPairs)) {
15351535
Debug.LogWarning (string.Format ("no mapping from Unity '{0}' to fbx property", uniPropertyName));
15361536
return;
15371537
}
@@ -1549,39 +1549,35 @@ protected void ExportAnimationCurve (UnityEngine.Object uniObj,
15491549
return;
15501550
}
15511551

1552-
// map unity property name to fbx property
1553-
var fbxProperty = fbxNode.FindProperty(fbxPropertyChannelPair.Property, false);
1554-
if (!fbxProperty.IsValid())
1555-
{
1556-
var fbxNodeAttribute = fbxNode.GetNodeAttribute();
1557-
if (fbxNodeAttribute != null)
1558-
{
1559-
fbxProperty = fbxNodeAttribute.FindProperty(fbxPropertyChannelPair.Property, false);
1552+
foreach (var fbxPropertyChannelPair in fbxPropertyChannelPairs) {
1553+
// map unity property name to fbx property
1554+
var fbxProperty = fbxNode.FindProperty (fbxPropertyChannelPair.Property, false);
1555+
if (!fbxProperty.IsValid ()) {
1556+
var fbxNodeAttribute = fbxNode.GetNodeAttribute ();
1557+
if (fbxNodeAttribute != null) {
1558+
fbxProperty = fbxNodeAttribute.FindProperty (fbxPropertyChannelPair.Property, false);
1559+
}
1560+
}
1561+
if (!fbxProperty.IsValid ()) {
1562+
Debug.LogError (string.Format ("no fbx property {0} found on {1} node or nodeAttribute ", fbxPropertyChannelPair.Property, fbxNode.GetName ()));
1563+
return;
15601564
}
1561-
}
1562-
if (!fbxProperty.IsValid())
1563-
{
1564-
Debug.LogError(string.Format("no fbx property {0} found on {1} node or nodeAttribute ", fbxPropertyChannelPair.Property, fbxNode.GetName()));
1565-
return;
1566-
}
15671565

1568-
// Create the AnimCurve on the channel
1569-
FbxAnimCurve fbxAnimCurve = fbxProperty.GetCurve (fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
1566+
// Create the AnimCurve on the channel
1567+
FbxAnimCurve fbxAnimCurve = fbxProperty.GetCurve (fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
15701568

1571-
// create a convert scene helper so that we can convert from Unity to Maya
1572-
// AxisSystem (LeftHanded to RightHanded) and FBX's default units
1573-
// (Meters to Centimetres)
1574-
var convertSceneHelper = new UnityToMayaConvertSceneHelper (uniPropertyName);
1569+
// create a convert scene helper so that we can convert from Unity to Maya
1570+
// AxisSystem (LeftHanded to RightHanded) and FBX's default units
1571+
// (Meters to Centimetres)
1572+
var convertSceneHelper = new UnityToMayaConvertSceneHelper (uniPropertyName);
15751573

1576-
// TODO: we'll resample the curve so we don't have to
1577-
// configure tangents
1578-
if (ModelExporter.ExportSettings.BakeAnimation)
1579-
{
1580-
ExportAnimationSamples(uniAnimCurve, fbxAnimCurve, frameRate, convertSceneHelper);
1581-
}
1582-
else
1583-
{
1584-
ExportAnimationKeys(uniAnimCurve, fbxAnimCurve, convertSceneHelper);
1574+
// TODO: we'll resample the curve so we don't have to
1575+
// configure tangents
1576+
if (ModelExporter.ExportSettings.BakeAnimation) {
1577+
ExportAnimationSamples (uniAnimCurve, fbxAnimCurve, frameRate, convertSceneHelper);
1578+
} else {
1579+
ExportAnimationKeys (uniAnimCurve, fbxAnimCurve, convertSceneHelper);
1580+
}
15851581
}
15861582
}
15871583

@@ -1636,75 +1632,78 @@ public FbxPropertyChannelPair(string p, string c):this() {
16361632
/// Map a Unity property name to the corresponding FBX property and
16371633
/// channel names.
16381634
/// </summary>
1639-
public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPair prop)
1635+
public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPair[] prop)
16401636
{
16411637
System.StringComparison ct = System.StringComparison.CurrentCulture;
16421638

16431639
// Transform Scaling
16441640
if (uniPropertyName.StartsWith ("m_LocalScale.x", ct) || uniPropertyName.EndsWith ("S.x", ct)) {
1645-
prop = new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_X);
1641+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_X) };
16461642
return true;
16471643
}
16481644
if (uniPropertyName.StartsWith ("m_LocalScale.y", ct) || uniPropertyName.EndsWith ("S.y", ct)) {
1649-
prop = new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_Y);
1645+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_Y) };
16501646
return true;
16511647
}
16521648
if (uniPropertyName.StartsWith ("m_LocalScale.z", ct) || uniPropertyName.EndsWith ("S.z", ct)) {
1653-
prop = new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_Z);
1649+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair ("Lcl Scaling", Globals.FBXSDK_CURVENODE_COMPONENT_Z) };
16541650
return true;
16551651
}
16561652

16571653
// Transform Translation
16581654
if (uniPropertyName.StartsWith ("m_LocalPosition.x", ct) || uniPropertyName.EndsWith ("T.x", ct)) {
1659-
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_X);
1655+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_X) };
16601656
return true;
16611657
}
16621658
if (uniPropertyName.StartsWith ("m_LocalPosition.y", ct) || uniPropertyName.EndsWith ("T.y", ct)) {
1663-
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Y);
1659+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Y) };
16641660
return true;
16651661
}
16661662
if (uniPropertyName.StartsWith ("m_LocalPosition.z", ct) || uniPropertyName.EndsWith ("T.z", ct)) {
1667-
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Z);
1663+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Z) };
16681664
return true;
16691665
}
16701666

16711667
if (uniPropertyName.StartsWith("m_Intensity", ct))
16721668
{
1673-
prop = new FbxPropertyChannelPair ("Intensity", null);
1669+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair ("Intensity", null) };
16741670
return true;
16751671
}
16761672

16771673
if (uniPropertyName.StartsWith("m_SpotAngle", ct))
16781674
{
1679-
prop = new FbxPropertyChannelPair ("OuterAngle", null);
1675+
prop = new FbxPropertyChannelPair[]{
1676+
new FbxPropertyChannelPair ("OuterAngle", null),
1677+
new FbxPropertyChannelPair ("InnerAngle", null)
1678+
};
16801679
return true;
16811680
}
16821681

16831682
if (uniPropertyName.StartsWith("m_Color.r", ct))
16841683
{
1685-
prop = new FbxPropertyChannelPair ("Color", Globals.FBXSDK_CURVENODE_COLOR_RED);
1684+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair ("Color", Globals.FBXSDK_CURVENODE_COLOR_RED) };
16861685
return true;
16871686
}
16881687

16891688
if (uniPropertyName.StartsWith("m_Color.g", ct))
16901689
{
1691-
prop = new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR_GREEN);
1690+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR_GREEN) };
16921691
return true;
16931692
}
16941693

16951694
if (uniPropertyName.StartsWith("m_Color.b", ct))
16961695
{
1697-
prop = new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR_BLUE);
1696+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR_BLUE) };
16981697
return true;
16991698
}
17001699

17011700
if (uniPropertyName.StartsWith("field of view", ct))
17021701
{
1703-
prop = new FbxPropertyChannelPair("FieldOfView", null);
1702+
prop = new FbxPropertyChannelPair[]{ new FbxPropertyChannelPair("FieldOfView", null) };
17041703
return true;
17051704
}
17061705

1707-
prop = new FbxPropertyChannelPair ();
1706+
prop = new FbxPropertyChannelPair[]{};
17081707
return false;
17091708
}
17101709
}

0 commit comments

Comments
 (0)