@@ -1483,11 +1483,13 @@ protected List<ExpConstraintSource> GetConstraintSources(IConstraint unityConstr
1483
1483
1484
1484
protected void AddFbxNodeToConstraintsMapping < T > ( FbxNode fbxNode , T fbxConstraint , System . Type uniConstraintType ) where T : FbxConstraint
1485
1485
{
1486
- if ( ! MapConstrainedObjectToConstraints . ContainsKey ( fbxNode ) )
1486
+ Dictionary < FbxConstraint , System . Type > constraintMapping ;
1487
+ if ( ! MapConstrainedObjectToConstraints . TryGetValue ( fbxNode , out constraintMapping ) )
1487
1488
{
1488
- MapConstrainedObjectToConstraints . Add ( fbxNode , new Dictionary < FbxConstraint , System . Type > ( ) ) ;
1489
+ constraintMapping = new Dictionary < FbxConstraint , System . Type > ( ) ;
1490
+ MapConstrainedObjectToConstraints . Add ( fbxNode , constraintMapping ) ;
1489
1491
}
1490
- MapConstrainedObjectToConstraints [ fbxNode ] . Add ( fbxConstraint , uniConstraintType ) ;
1492
+ constraintMapping . Add ( fbxConstraint , uniConstraintType ) ;
1491
1493
}
1492
1494
1493
1495
protected bool ExportPositionConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
@@ -1703,12 +1705,13 @@ protected bool ExportConstraints (GameObject unityGo, FbxScene fbxScene, FbxNode
1703
1705
foreach ( var uniConstraint in uniConstraints )
1704
1706
{
1705
1707
var uniConstraintType = uniConstraint . GetType ( ) ;
1706
- if ( ! mapConstraintTypeToExportFunction . ContainsKey ( uniConstraintType ) )
1708
+ ExportConstraintDelegate constraintDelegate ;
1709
+ if ( ! mapConstraintTypeToExportFunction . TryGetValue ( uniConstraintType , out constraintDelegate ) )
1707
1710
{
1708
1711
Debug . LogWarningFormat ( "FbxExporter: Missing function to export constraint of type {0}" , uniConstraintType . Name ) ;
1709
1712
continue ;
1710
1713
}
1711
- mapConstraintTypeToExportFunction [ uniConstraintType ] ( uniConstraint , fbxScene , fbxNode ) ;
1714
+ constraintDelegate ( uniConstraint , fbxScene , fbxNode ) ;
1712
1715
}
1713
1716
1714
1717
return true ;
@@ -2004,6 +2007,10 @@ public float Convert(float value)
2004
2007
struct FbxPropertyChannelPair {
2005
2008
public string Property { get ; private set ; }
2006
2009
public string Channel { get ; private set ; }
2010
+
2011
+ /// <summary>
2012
+ /// Map of Unity transform properties to their FBX equivalent.
2013
+ /// </summary>
2007
2014
private static Dictionary < string , string > TransformProperties = new Dictionary < string , string > ( )
2008
2015
{
2009
2016
{ "m_LocalScale" , "Lcl Scaling" } ,
@@ -2015,6 +2022,9 @@ struct FbxPropertyChannelPair {
2015
2022
{ "m_RotationOffset" , "Rotation" }
2016
2023
} ;
2017
2024
2025
+ /// <summary>
2026
+ /// Map of Unity Aim constraint properties to their FBX equivalent.
2027
+ /// </summary>
2018
2028
private static Dictionary < string , string > AimConstraintProperties = new Dictionary < string , string > ( )
2019
2029
{
2020
2030
{ "m_AimVector" , "AimVector" } ,
@@ -2023,37 +2033,68 @@ struct FbxPropertyChannelPair {
2023
2033
{ "m_RotationOffset" , "RotationOffset" }
2024
2034
} ;
2025
2035
2036
+ /// <summary>
2037
+ /// Map of Unity transform channels to their FBX equivalent.
2038
+ /// </summary>
2026
2039
private static Dictionary < string , string > TransformChannels = new Dictionary < string , string > ( )
2027
2040
{
2028
2041
{ "x" , Globals . FBXSDK_CURVENODE_COMPONENT_X } ,
2029
2042
{ "y" , Globals . FBXSDK_CURVENODE_COMPONENT_Y } ,
2030
2043
{ "z" , Globals . FBXSDK_CURVENODE_COMPONENT_Z }
2031
2044
} ;
2045
+
2046
+ /// <summary>
2047
+ /// Map of Unity color properties to their FBX equivalent.
2048
+ /// </summary>
2032
2049
private static Dictionary < string , string > ColorProperties = new Dictionary < string , string > ( )
2033
2050
{
2034
2051
{ "m_Color" , "Color" }
2035
2052
} ;
2053
+
2054
+ /// <summary>
2055
+ /// Map of Unity color channels to their FBX equivalent.
2056
+ /// </summary>
2036
2057
private static Dictionary < string , string > ColorChannels = new Dictionary < string , string > ( )
2037
2058
{
2038
2059
{ "b" , Globals . FBXSDK_CURVENODE_COLOR_BLUE } ,
2039
2060
{ "g" , Globals . FBXSDK_CURVENODE_COLOR_GREEN } ,
2040
2061
{ "r" , Globals . FBXSDK_CURVENODE_COLOR_RED }
2041
2062
} ;
2063
+
2064
+ /// <summary>
2065
+ /// Map of Unity properties to their FBX equivalent.
2066
+ /// </summary>
2042
2067
private static Dictionary < string , string > OtherProperties = new Dictionary < string , string > ( )
2043
2068
{
2044
2069
{ "m_Intensity" , "Intensity" } ,
2045
2070
{ "field of view" , "FieldOfView" } ,
2046
2071
{ "m_Weight" , "Weight" }
2047
2072
} ;
2073
+
2074
+ /// <summary>
2075
+ /// Map of empty string to null, used for properties that don't need a channel.
2076
+ /// </summary>
2048
2077
private static Dictionary < string , string > NullChannel = new Dictionary < string , string > ( ) { { "" , null } } ;
2078
+
2079
+ /// <summary>
2080
+ /// Map of Unity constraint source property name as a regular expression to the FBX property as a string format.
2081
+ /// This is necessary because the Unity property contains an index in to an array, and the FBX property contains
2082
+ /// the name of the source object.
2083
+ /// </summary>
2049
2084
private static Dictionary < string , string > ConstraintSourceProperties = new Dictionary < string , string > ( )
2050
2085
{
2051
- { "m_Sources\\ .Array\\ .data\\ [(\\ d+)\\ ] \ \ .weight" , "{0}.Weight" }
2086
+ { @ "m_Sources\.Array\.data\[(\d+)\] \.weight", "{0}.Weight" }
2052
2087
} ;
2088
+
2089
+ /// <summary>
2090
+ /// Map of Unity constraint source transform property name as a regular expression to the FBX property as a string format.
2091
+ /// This is necessary because the Unity property contains an index in to an array, and the FBX property contains
2092
+ /// the name of the source object.
2093
+ /// </summary>
2053
2094
private static Dictionary < string , string > ConstraintSourceTransformProperties = new Dictionary < string , string > ( )
2054
2095
{
2055
- { "m_TranslationOffsets\\ .Array\\ .data\\ [(\\ d+)\ \ ]" , "{0}.Offset T" } ,
2056
- { "m_RotationOffsets\\ .Array\\ .data\\ [(\\ d+)\ \ ]" , "{0}.Offset R" }
2096
+ { @ "m_TranslationOffsets\.Array\.data\[(\d+)\]", "{0}.Offset T" } ,
2097
+ { @ "m_RotationOffsets\.Array\.data\[(\d+)\]", "{0}.Offset R" }
2057
2098
} ;
2058
2099
2059
2100
public FbxPropertyChannelPair ( string p , string c ) : this ( ) {
0 commit comments