Skip to content

Commit 3a824e5

Browse files
committed
code review fixes
- add comments - use TryGetValue instead of Contains for dicts
1 parent 00e9325 commit 3a824e5

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,11 +1483,13 @@ protected List<ExpConstraintSource> GetConstraintSources(IConstraint unityConstr
14831483

14841484
protected void AddFbxNodeToConstraintsMapping<T>(FbxNode fbxNode, T fbxConstraint, System.Type uniConstraintType) where T : FbxConstraint
14851485
{
1486-
if (!MapConstrainedObjectToConstraints.ContainsKey(fbxNode))
1486+
Dictionary<FbxConstraint, System.Type> constraintMapping;
1487+
if (!MapConstrainedObjectToConstraints.TryGetValue(fbxNode, out constraintMapping))
14871488
{
1488-
MapConstrainedObjectToConstraints.Add(fbxNode, new Dictionary<FbxConstraint, System.Type>());
1489+
constraintMapping = new Dictionary<FbxConstraint, System.Type>();
1490+
MapConstrainedObjectToConstraints.Add(fbxNode, constraintMapping);
14891491
}
1490-
MapConstrainedObjectToConstraints[fbxNode].Add(fbxConstraint, uniConstraintType);
1492+
constraintMapping.Add(fbxConstraint, uniConstraintType);
14911493
}
14921494

14931495
protected bool ExportPositionConstraint(IConstraint uniConstraint, FbxScene fbxScene, FbxNode fbxNode)
@@ -1703,12 +1705,13 @@ protected bool ExportConstraints (GameObject unityGo, FbxScene fbxScene, FbxNode
17031705
foreach(var uniConstraint in uniConstraints)
17041706
{
17051707
var uniConstraintType = uniConstraint.GetType();
1706-
if (!mapConstraintTypeToExportFunction.ContainsKey(uniConstraintType))
1708+
ExportConstraintDelegate constraintDelegate;
1709+
if (!mapConstraintTypeToExportFunction.TryGetValue(uniConstraintType, out constraintDelegate))
17071710
{
17081711
Debug.LogWarningFormat("FbxExporter: Missing function to export constraint of type {0}", uniConstraintType.Name);
17091712
continue;
17101713
}
1711-
mapConstraintTypeToExportFunction[uniConstraintType](uniConstraint, fbxScene, fbxNode);
1714+
constraintDelegate(uniConstraint, fbxScene, fbxNode);
17121715
}
17131716

17141717
return true;
@@ -2004,6 +2007,10 @@ public float Convert(float value)
20042007
struct FbxPropertyChannelPair {
20052008
public string Property { get; private set; }
20062009
public string Channel { get; private set; }
2010+
2011+
/// <summary>
2012+
/// Map of Unity transform properties to their FBX equivalent.
2013+
/// </summary>
20072014
private static Dictionary<string, string> TransformProperties = new Dictionary<string, string>()
20082015
{
20092016
{ "m_LocalScale", "Lcl Scaling" },
@@ -2015,6 +2022,9 @@ struct FbxPropertyChannelPair {
20152022
{ "m_RotationOffset", "Rotation" }
20162023
};
20172024

2025+
/// <summary>
2026+
/// Map of Unity Aim constraint properties to their FBX equivalent.
2027+
/// </summary>
20182028
private static Dictionary<string, string> AimConstraintProperties = new Dictionary<string, string>()
20192029
{
20202030
{ "m_AimVector", "AimVector" },
@@ -2023,37 +2033,68 @@ struct FbxPropertyChannelPair {
20232033
{ "m_RotationOffset", "RotationOffset" }
20242034
};
20252035

2036+
/// <summary>
2037+
/// Map of Unity transform channels to their FBX equivalent.
2038+
/// </summary>
20262039
private static Dictionary<string, string> TransformChannels = new Dictionary<string, string>()
20272040
{
20282041
{ "x", Globals.FBXSDK_CURVENODE_COMPONENT_X },
20292042
{ "y", Globals.FBXSDK_CURVENODE_COMPONENT_Y },
20302043
{ "z", Globals.FBXSDK_CURVENODE_COMPONENT_Z }
20312044
};
2045+
2046+
/// <summary>
2047+
/// Map of Unity color properties to their FBX equivalent.
2048+
/// </summary>
20322049
private static Dictionary<string, string> ColorProperties = new Dictionary<string, string>()
20332050
{
20342051
{ "m_Color", "Color" }
20352052
};
2053+
2054+
/// <summary>
2055+
/// Map of Unity color channels to their FBX equivalent.
2056+
/// </summary>
20362057
private static Dictionary<string, string> ColorChannels = new Dictionary<string, string>()
20372058
{
20382059
{ "b", Globals.FBXSDK_CURVENODE_COLOR_BLUE },
20392060
{ "g", Globals.FBXSDK_CURVENODE_COLOR_GREEN },
20402061
{ "r", Globals.FBXSDK_CURVENODE_COLOR_RED }
20412062
};
2063+
2064+
/// <summary>
2065+
/// Map of Unity properties to their FBX equivalent.
2066+
/// </summary>
20422067
private static Dictionary<string, string> OtherProperties = new Dictionary<string, string>()
20432068
{
20442069
{ "m_Intensity", "Intensity" },
20452070
{ "field of view", "FieldOfView" },
20462071
{ "m_Weight", "Weight" }
20472072
};
2073+
2074+
/// <summary>
2075+
/// Map of empty string to null, used for properties that don't need a channel.
2076+
/// </summary>
20482077
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>
20492084
private static Dictionary<string, string> ConstraintSourceProperties = new Dictionary<string, string>()
20502085
{
2051-
{ "m_Sources\\.Array\\.data\\[(\\d+)\\]\\.weight", "{0}.Weight" }
2086+
{ @"m_Sources\.Array\.data\[(\d+)\]\.weight", "{0}.Weight" }
20522087
};
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>
20532094
private static Dictionary<string, string> ConstraintSourceTransformProperties = new Dictionary<string, string>()
20542095
{
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" }
20572098
};
20582099

20592100
public FbxPropertyChannelPair(string p, string c) : this() {

0 commit comments

Comments
 (0)