Skip to content

Commit 2e9daf8

Browse files
committed
generic tests
2 parents 3ab9e76 + 79c55f9 commit 2e9daf8

File tree

5 files changed

+414
-148
lines changed

5 files changed

+414
-148
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 68 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -146,35 +146,6 @@ public enum FbxNodeRelationType
146146
{ typeof(Material), new KeyValuePair<System.Type, FbxNodeRelationType>(typeof(FbxSurfaceMaterial), FbxNodeRelationType.Material) },
147147
};
148148

149-
/// <summary>
150-
/// Return True is Unity component is animatable
151-
///
152-
public static bool IsAnimatable (System.Type componentType) { return GetAnimatableProperties (componentType).Any (); }
153-
154-
private static HashSet<System.Type> m_animatableTypes = new HashSet<System.Type> () { typeof (System.Single) };
155-
156-
public static IEnumerable<System.Reflection.PropertyInfo> GetAnimatableProperties (System.Type componentType)
157-
{
158-
return from p in componentType.GetProperties ()
159-
where IsAnimatableProperty (p)
160-
select p;
161-
}
162-
163-
private static bool IsAnimatableProperty (System.Reflection.PropertyInfo p)
164-
{
165-
// assume any custom attribute is System.ObsoleteAttribute
166-
return m_animatableTypes.Contains (p.PropertyType) &&
167-
!p.GetCustomAttributes (true).Any ();
168-
}
169-
170-
/// <summary>
171-
/// Which components map to FbxProperty
172-
/// </summary>
173-
public static HashSet<System.Type> MapsToFbxProperty = new HashSet<System.Type> ()
174-
{
175-
typeof(Transform),
176-
};
177-
178149
/// <summary>
179150
/// Map Unity material name to FBX material object
180151
/// </summary>
@@ -1037,55 +1008,66 @@ protected void ExportAnimationCurve (UnityEngine.Object uniObj,
10371008
}
10381009

10391010
FbxNode fbxNode;
1040-
if (!MapUnityObjectToFbxNode.TryGetValue (unityGo, out fbxNode)) {
1041-
Debug.LogError ( string.Format("no fbx node for {0}", unityGo.ToString()));
1011+
if (!MapUnityObjectToFbxNode.TryGetValue(unityGo, out fbxNode))
1012+
{
1013+
Debug.LogError(string.Format("no fbx node for {0}", unityGo.ToString()));
10421014
return;
10431015
}
1044-
10451016
// map unity property name to fbx property
1046-
var fbxProperty = fbxNode.FindProperty (fbxPropertyChannelPair.Property, false);
1047-
if (!fbxProperty.IsValid ()) {
1048-
Debug.LogError (string.Format ("no fbx property {0} found on {1} ", fbxPropertyChannelPair.Property, fbxNode.GetName ()));
1017+
var fbxProperty = fbxNode.FindProperty(fbxPropertyChannelPair.Property, false);
1018+
if (!fbxProperty.IsValid())
1019+
{
1020+
var fbxNodeAttribute = fbxNode.GetNodeAttribute();
1021+
if (fbxNodeAttribute != null)
1022+
{
1023+
fbxProperty = fbxNodeAttribute.FindProperty(fbxPropertyChannelPair.Property, false);
1024+
}
1025+
}
1026+
if (!fbxProperty.IsValid())
1027+
{
1028+
Debug.LogError(string.Format("no fbx property {0} found on {1} node or nodeAttribute ", fbxPropertyChannelPair.Property, fbxNode.GetName()));
10491029
return;
10501030
}
10511031

10521032
// Create the AnimCurve on the channel
10531033
FbxAnimCurve fbxAnimCurve = fbxProperty.GetCurve (fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
10541034

1055-
var transformBindings = new TransformBindings (uniPropertyName);
1035+
var transformBindings = new UnityToMayaConvertSceneHelper (uniPropertyName);
10561036

10571037
// copy Unity AnimCurve to FBX AnimCurve.
10581038
fbxAnimCurve.KeyModifyBegin ();
10591039

10601040
for (int keyIndex = 0, n = uniAnimCurve.length; keyIndex < n; ++keyIndex) {
10611041
var uniKeyFrame = uniAnimCurve [keyIndex];
10621042
var fbxTime = FbxTime.FromSecondDouble (uniKeyFrame.time);
1063-
fbxAnimCurve.KeyAdd (fbxTime);
1043+
1044+
keyIndex = fbxAnimCurve.KeyAdd (fbxTime);
10641045
fbxAnimCurve.KeySet (keyIndex, fbxTime, transformBindings.Convert(uniKeyFrame.value));
10651046
}
10661047

1067-
fbxAnimCurve.KeyModifyEnd ();
1048+
fbxAnimCurve.KeyModifyEnd();
10681049
}
10691050

1070-
class TransformBindings
1051+
class UnityToMayaConvertSceneHelper
10711052
{
1072-
bool requiresConversion = false;
1053+
bool convertDistance = false;
10731054
float unitScaleFactor = 1f;
10741055

1075-
public TransformBindings(string uniPropertyName)
1056+
public UnityToMayaConvertSceneHelper(string uniPropertyName)
10761057
{
10771058
System.StringComparison cc = System.StringComparison.CurrentCulture;
10781059

1079-
requiresConversion |= uniPropertyName.StartsWith ("m_LocalPosition.", cc);
1060+
convertDistance |= uniPropertyName.StartsWith ("m_LocalPosition.", cc);
1061+
convertDistance |= uniPropertyName.StartsWith ("m_Intensity", cc);
10801062

1081-
bool isTx = requiresConversion && uniPropertyName.EndsWith (".x", cc) || uniPropertyName.EndsWith ("T.x", cc);
1082-
requiresConversion |= isTx;
1083-
requiresConversion |= uniPropertyName.EndsWith ("T.y", cc);
1084-
requiresConversion |= uniPropertyName.EndsWith ("T.z", cc);
1063+
bool convertLHRH = convertDistance && uniPropertyName.EndsWith (".x", cc) || uniPropertyName.EndsWith ("T.x", cc);
1064+
convertDistance |= convertLHRH;
1065+
convertDistance |= uniPropertyName.EndsWith ("T.y", cc);
1066+
convertDistance |= uniPropertyName.EndsWith ("T.z", cc);
10851067

1086-
if (requiresConversion) {
1068+
if (convertDistance) {
10871069
unitScaleFactor = ModelExporter.UnitScaleFactor;
1088-
if (isTx)
1070+
if (convertLHRH)
10891071
unitScaleFactor = -unitScaleFactor;
10901072
}
10911073
}
@@ -1094,7 +1076,7 @@ public float Convert(float value)
10941076
{
10951077
// left handed to right handed conversion
10961078
// meters to centimetres conversion
1097-
return (requiresConversion) ? unitScaleFactor * value : value;
1079+
return (convertDistance) ? unitScaleFactor * value : value;
10981080
}
10991081
}
11001082

@@ -1143,7 +1125,37 @@ public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPai
11431125
return true;
11441126
}
11451127
if (uniPropertyName.StartsWith ("m_LocalPosition.z", ct) || uniPropertyName.EndsWith ("T.z", ct)) {
1146-
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Z);
1128+
prop = new FbxPropertyChannelPair ("Lcl Translation", Globals.FBXSDK_CURVENODE_COMPONENT_Z);
1129+
return true;
1130+
}
1131+
1132+
if (uniPropertyName.StartsWith("m_Intensity", ct))
1133+
{
1134+
prop = new FbxPropertyChannelPair ("Intensity", null);
1135+
return true;
1136+
}
1137+
1138+
if (uniPropertyName.StartsWith("m_SpotAngle", ct))
1139+
{
1140+
prop = new FbxPropertyChannelPair ("OuterAngle", null);
1141+
return true;
1142+
}
1143+
1144+
if (uniPropertyName.StartsWith("m_Color.r", ct))
1145+
{
1146+
prop = new FbxPropertyChannelPair ("Color", Globals.FBXSDK_CURVENODE_COLOR_RED);
1147+
return true;
1148+
}
1149+
1150+
if (uniPropertyName.StartsWith("m_Color.g", ct))
1151+
{
1152+
prop = new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR_GREEN);
1153+
return true;
1154+
}
1155+
1156+
if (uniPropertyName.StartsWith("m_Color.b", ct))
1157+
{
1158+
prop = new FbxPropertyChannelPair("Color", Globals.FBXSDK_CURVENODE_COLOR_BLUE);
11471159
return true;
11481160
}
11491161

@@ -1313,7 +1325,7 @@ protected void ExportAnimationClip (AnimationClip uniAnimClip, GameObject uniRoo
13131325
// Custom frame rate isn't really supported in FBX SDK (there's
13141326
// a bug), so try hard to find the nearest time mode.
13151327
FbxTime.EMode timeMode = FbxTime.EMode.eCustom;
1316-
double precision = Mathf.Epsilon;
1328+
double precision = 1e-6;
13171329
while (timeMode == FbxTime.EMode.eCustom && precision < 1000) {
13181330
timeMode = FbxTime.ConvertFrameRateToTimeMode (uniAnimClip.frameRate, precision);
13191331
precision *= 10;
@@ -1516,7 +1528,7 @@ protected int ExportComponents (
15161528
}
15171529

15181530
if (Verbose)
1519-
Debug.Log (string.Format ("Exporting node {0}", fbxNode.GetName ()));
1531+
Debug.Log (string.Format ("exporting {0}", fbxNode.GetName ()));
15201532

15211533
fbxNodeParent.AddChild (fbxNode);
15221534

@@ -2094,9 +2106,9 @@ private static GameObject GetGameObject (Object obj)
20942106
return xform.gameObject;
20952107
} else if (obj is UnityEngine.GameObject) {
20962108
return obj as UnityEngine.GameObject;
2097-
} else if (obj is MonoBehaviour) {
2098-
var mono = obj as MonoBehaviour;
2099-
return mono.gameObject;
2109+
} else if (obj is Behaviour) {
2110+
var behaviour = obj as Behaviour;
2111+
return behaviour.gameObject;
21002112
}
21012113

21022114
return null;
@@ -2323,7 +2335,7 @@ public void Dispose ()
23232335
{
23242336
}
23252337

2326-
public bool Verbose { private set {;} get { return true; } }
2338+
public bool Verbose { private set {;} get { return false; } }
23272339

23282340
/// <summary>
23292341
/// manage the selection of a filename

Assets/FbxExporters/Editor/FbxPrefabInspector.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ namespace FbxExporters.EditorTools {
66
[CustomEditor(typeof(FbxPrefab))]
77
public class FbxPrefabInspector : UnityEditor.Editor {
88
public override void OnInspectorGUI() {
9+
10+
SerializedProperty m_GameObjectProp = serializedObject.FindProperty("m_nameMapping");
11+
912
FbxPrefab fbxPrefab = (FbxPrefab)target;
1013

1114
// We can only change these settings when applied to a prefab.
@@ -28,17 +31,18 @@ public override void OnInspectorGUI() {
2831

2932
EditorGUI.EndDisabledGroup();
3033

34+
EditorGUILayout.PropertyField(m_GameObjectProp, true);
35+
3136
#if FBXEXPORTER_DEBUG
32-
GUILayout.BeginHorizontal();
33-
GUILayout.Label ("Debug info:");
37+
EditorGUILayout.LabelField ("Debug info:");
3438
try {
35-
fbxPrefab.GetFbxHistory().ToJson();
39+
fbxPrefabUtility.GetFbxHistory().ToJson();
3640
} catch(System.Exception xcp) {
3741
Debug.LogException(xcp);
3842
}
39-
EditorGUILayout.SelectableLabel(fbxPrefab.GetFbxHistoryString());
40-
GUILayout.EndHorizontal();
43+
EditorGUILayout.SelectableLabel(fbxPrefabUtility.GetFbxHistoryString());
4144
#endif
45+
serializedObject.ApplyModifiedProperties();
4246
}
4347
}
44-
}
48+
}

0 commit comments

Comments
 (0)