@@ -146,35 +146,6 @@ public enum FbxNodeRelationType
146
146
{ typeof ( Material ) , new KeyValuePair < System . Type , FbxNodeRelationType > ( typeof ( FbxSurfaceMaterial ) , FbxNodeRelationType . Material ) } ,
147
147
} ;
148
148
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
-
178
149
/// <summary>
179
150
/// Map Unity material name to FBX material object
180
151
/// </summary>
@@ -1037,55 +1008,66 @@ protected void ExportAnimationCurve (UnityEngine.Object uniObj,
1037
1008
}
1038
1009
1039
1010
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 ( ) ) ) ;
1042
1014
return ;
1043
1015
}
1044
-
1045
1016
// 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 ( ) ) ) ;
1049
1029
return ;
1050
1030
}
1051
1031
1052
1032
// Create the AnimCurve on the channel
1053
1033
FbxAnimCurve fbxAnimCurve = fbxProperty . GetCurve ( fbxAnimLayer , fbxPropertyChannelPair . Channel , true ) ;
1054
1034
1055
- var transformBindings = new TransformBindings ( uniPropertyName ) ;
1035
+ var transformBindings = new UnityToMayaConvertSceneHelper ( uniPropertyName ) ;
1056
1036
1057
1037
// copy Unity AnimCurve to FBX AnimCurve.
1058
1038
fbxAnimCurve . KeyModifyBegin ( ) ;
1059
1039
1060
1040
for ( int keyIndex = 0 , n = uniAnimCurve . length ; keyIndex < n ; ++ keyIndex ) {
1061
1041
var uniKeyFrame = uniAnimCurve [ keyIndex ] ;
1062
1042
var fbxTime = FbxTime . FromSecondDouble ( uniKeyFrame . time ) ;
1063
- fbxAnimCurve . KeyAdd ( fbxTime ) ;
1043
+
1044
+ keyIndex = fbxAnimCurve . KeyAdd ( fbxTime ) ;
1064
1045
fbxAnimCurve . KeySet ( keyIndex , fbxTime , transformBindings . Convert ( uniKeyFrame . value ) ) ;
1065
1046
}
1066
1047
1067
- fbxAnimCurve . KeyModifyEnd ( ) ;
1048
+ fbxAnimCurve . KeyModifyEnd ( ) ;
1068
1049
}
1069
1050
1070
- class TransformBindings
1051
+ class UnityToMayaConvertSceneHelper
1071
1052
{
1072
- bool requiresConversion = false ;
1053
+ bool convertDistance = false ;
1073
1054
float unitScaleFactor = 1f ;
1074
1055
1075
- public TransformBindings ( string uniPropertyName )
1056
+ public UnityToMayaConvertSceneHelper ( string uniPropertyName )
1076
1057
{
1077
1058
System . StringComparison cc = System . StringComparison . CurrentCulture ;
1078
1059
1079
- requiresConversion |= uniPropertyName . StartsWith ( "m_LocalPosition." , cc ) ;
1060
+ convertDistance |= uniPropertyName . StartsWith ( "m_LocalPosition." , cc ) ;
1061
+ convertDistance |= uniPropertyName . StartsWith ( "m_Intensity" , cc ) ;
1080
1062
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 ) ;
1085
1067
1086
- if ( requiresConversion ) {
1068
+ if ( convertDistance ) {
1087
1069
unitScaleFactor = ModelExporter . UnitScaleFactor ;
1088
- if ( isTx )
1070
+ if ( convertLHRH )
1089
1071
unitScaleFactor = - unitScaleFactor ;
1090
1072
}
1091
1073
}
@@ -1094,7 +1076,7 @@ public float Convert(float value)
1094
1076
{
1095
1077
// left handed to right handed conversion
1096
1078
// meters to centimetres conversion
1097
- return ( requiresConversion ) ? unitScaleFactor * value : value ;
1079
+ return ( convertDistance ) ? unitScaleFactor * value : value ;
1098
1080
}
1099
1081
}
1100
1082
@@ -1143,7 +1125,37 @@ public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPai
1143
1125
return true ;
1144
1126
}
1145
1127
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 ) ;
1147
1159
return true ;
1148
1160
}
1149
1161
@@ -1313,7 +1325,7 @@ protected void ExportAnimationClip (AnimationClip uniAnimClip, GameObject uniRoo
1313
1325
// Custom frame rate isn't really supported in FBX SDK (there's
1314
1326
// a bug), so try hard to find the nearest time mode.
1315
1327
FbxTime . EMode timeMode = FbxTime . EMode . eCustom ;
1316
- double precision = Mathf . Epsilon ;
1328
+ double precision = 1e-6 ;
1317
1329
while ( timeMode == FbxTime . EMode . eCustom && precision < 1000 ) {
1318
1330
timeMode = FbxTime . ConvertFrameRateToTimeMode ( uniAnimClip . frameRate , precision ) ;
1319
1331
precision *= 10 ;
@@ -1516,7 +1528,7 @@ protected int ExportComponents (
1516
1528
}
1517
1529
1518
1530
if ( Verbose )
1519
- Debug . Log ( string . Format ( "Exporting node {0}" , fbxNode . GetName ( ) ) ) ;
1531
+ Debug . Log ( string . Format ( "exporting {0}" , fbxNode . GetName ( ) ) ) ;
1520
1532
1521
1533
fbxNodeParent . AddChild ( fbxNode ) ;
1522
1534
@@ -2094,9 +2106,9 @@ private static GameObject GetGameObject (Object obj)
2094
2106
return xform . gameObject ;
2095
2107
} else if ( obj is UnityEngine . GameObject ) {
2096
2108
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 ;
2100
2112
}
2101
2113
2102
2114
return null ;
@@ -2323,7 +2335,7 @@ public void Dispose ()
2323
2335
{
2324
2336
}
2325
2337
2326
- public bool Verbose { private set { ; } get { return true ; } }
2338
+ public bool Verbose { private set { ; } get { return false ; } }
2327
2339
2328
2340
/// <summary>
2329
2341
/// manage the selection of a filename
0 commit comments