Skip to content

Commit c7b5f79

Browse files
committed
code review fix
- make MapConstrainedObjectToConstraints have a dict of FbxConstraint to Type as its value
1 parent ae1c067 commit c7b5f79

File tree

1 file changed

+9
-30
lines changed

1 file changed

+9
-30
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public enum FbxNodeRelationType
156156
/// keep a map between the constrained FbxNode (in Unity this is the GameObject with constraint component)
157157
/// and its FbxConstraints for quick lookup when exporting constraint animations.
158158
/// </summary>
159-
Dictionary<FbxNode, List<FbxConstraint>> MapConstrainedObjectToConstraints = new Dictionary<FbxNode, List<FbxConstraint>>();
159+
Dictionary<FbxNode, Dictionary<FbxConstraint, System.Type>> MapConstrainedObjectToConstraints = new Dictionary<FbxNode, Dictionary<FbxConstraint, System.Type>>();
160160

161161
/// <summary>
162162
/// Map Unity material name to FBX material object
@@ -1425,7 +1425,7 @@ protected bool ExportCommonConstraintProperties<T,U>(T uniConstraint, U fbxConst
14251425
fbxConstraint.Lock.Set(uniConstraint.locked);
14261426
fbxConstraint.Weight.Set(uniConstraint.weight * UnitScaleFactor);
14271427

1428-
AddFbxNodeToConstraintsMapping(fbxNode, fbxConstraint);
1428+
AddFbxNodeToConstraintsMapping(fbxNode, fbxConstraint, typeof(T));
14291429
return true;
14301430
}
14311431

@@ -1459,13 +1459,13 @@ protected List<FbxConstraintSource> GetConstraintSources(IConstraint unityConstr
14591459
return fbxSources;
14601460
}
14611461

1462-
protected void AddFbxNodeToConstraintsMapping<T>(FbxNode fbxNode, T fbxConstraint) where T : FbxConstraint
1462+
protected void AddFbxNodeToConstraintsMapping<T>(FbxNode fbxNode, T fbxConstraint, System.Type uniConstraintType) where T : FbxConstraint
14631463
{
14641464
if (!MapConstrainedObjectToConstraints.ContainsKey(fbxNode))
14651465
{
1466-
MapConstrainedObjectToConstraints.Add(fbxNode, new List<FbxConstraint>());
1466+
MapConstrainedObjectToConstraints.Add(fbxNode, new Dictionary<FbxConstraint, System.Type>());
14671467
}
1468-
MapConstrainedObjectToConstraints[fbxNode].Add(fbxConstraint);
1468+
MapConstrainedObjectToConstraints[fbxNode].Add(fbxConstraint, uniConstraintType);
14691469
}
14701470

14711471
protected bool ExportPositionConstraint(PositionConstraint uniPosConstraint, FbxScene fbxScene, FbxNode fbxNode)
@@ -1846,26 +1846,6 @@ protected void ExportAnimationSamples (AnimationCurve uniAnimCurve, FbxAnimCurve
18461846
}
18471847
}
18481848

1849-
1850-
protected System.Type FbxToUnityConstraintType(FbxConstraint.EType fbxConstraintType)
1851-
{
1852-
switch (fbxConstraintType)
1853-
{
1854-
case FbxConstraint.EType.eAim:
1855-
return typeof(AimConstraint);
1856-
case FbxConstraint.EType.eParent:
1857-
return typeof(ParentConstraint);
1858-
case FbxConstraint.EType.ePosition:
1859-
return typeof(PositionConstraint);
1860-
case FbxConstraint.EType.eRotation:
1861-
return typeof(RotationConstraint);
1862-
case FbxConstraint.EType.eScale:
1863-
return typeof(ScaleConstraint);
1864-
default:
1865-
throw new System.NotImplementedException(fbxConstraintType.ToString());
1866-
}
1867-
}
1868-
18691849
/// <summary>
18701850
/// Get the FbxConstraint associated with the constrained node.
18711851
/// </summary>
@@ -1880,21 +1860,20 @@ protected FbxConstraint GetFbxConstraint(FbxNode constrainedNode, System.Type un
18801860
return null;
18811861
}
18821862

1883-
List<FbxConstraint> constraints;
1863+
Dictionary<FbxConstraint, System.Type> constraints;
18841864
if (!MapConstrainedObjectToConstraints.TryGetValue(constrainedNode, out constraints))
18851865
{
18861866
return null;
18871867
}
1888-
1889-
1868+
18901869
foreach (var constraint in constraints)
18911870
{
1892-
if (uniConstraintType != FbxToUnityConstraintType(constraint.GetConstraintType()))
1871+
if (uniConstraintType != constraint.Value)
18931872
{
18941873
continue;
18951874
}
18961875

1897-
return constraint;
1876+
return constraint.Key;
18981877
}
18991878

19001879
return null;

0 commit comments

Comments
 (0)