@@ -920,55 +920,74 @@ protected bool ExportLight (GameObject unityGo, FbxScene fbxScene, FbxNode fbxNo
920
920
/// NOTE: This is not used for rotations, because we need to convert from
921
921
/// quaternion to euler and various other stuff.
922
922
/// </summary>
923
- protected void ExportAnimCurve ( UnityEngine . Object unityObj ,
923
+ protected void ExportAnimCurve ( UnityEngine . Object unityObj ,
924
924
AnimationCurve unityAnimCurve ,
925
925
string unityPropertyName ,
926
926
FbxScene fbxScene ,
927
927
FbxAnimLayer fbxAnimLayer )
928
928
{
929
929
FbxPropertyChannelPair fbxPropertyChannelPair ;
930
- if ( ! FbxPropertyChannelPair . TryGetValue ( unityPropertyName , out fbxPropertyChannelPair ) ) {
931
- Debug . LogWarning ( string . Format ( "no mapping from Unity '{0}' to fbx property" , unityPropertyName ) ) ;
930
+ if ( ! FbxPropertyChannelPair . TryGetValue ( unityPropertyName , out fbxPropertyChannelPair ) )
931
+ {
932
+ Debug . LogWarning ( string . Format ( "no mapping from Unity '{0}' to fbx property" , unityPropertyName ) ) ;
932
933
return ;
933
934
}
934
935
935
- GameObject unityGo = GetGameObject ( unityObj ) ;
936
- if ( unityGo == null ) {
937
- Debug . LogError ( string . Format ( "cannot find gameobject for {0}" , unityObj . ToString ( ) ) ) ;
936
+ GameObject unityGo = GetGameObject ( unityObj ) ;
937
+ if ( unityGo == null && ! unityObj )
938
+ {
939
+ Debug . LogError ( string . Format ( "cannot find gameobject for {0}" , unityObj . ToString ( ) ) ) ;
938
940
return ;
939
941
}
940
942
941
943
FbxNode fbxNode ;
942
- if ( ! MapUnityObjectToFbxNode . TryGetValue ( unityGo , out fbxNode ) ) {
943
- Debug . LogError ( string . Format ( "no fbx node for {0}" , unityGo . ToString ( ) ) ) ;
944
+ if ( ! MapUnityObjectToFbxNode . TryGetValue ( unityGo , out fbxNode ) )
945
+ {
946
+ Debug . LogError ( string . Format ( "no fbx node for {0}" , unityGo . ToString ( ) ) ) ;
944
947
return ;
945
948
}
946
-
947
949
// map unity property name to fbx property
948
- var fbxProperty = fbxNode . FindProperty ( fbxPropertyChannelPair . Property , false ) ;
949
- if ( ! fbxProperty . IsValid ( ) ) {
950
- Debug . LogError ( string . Format ( "no fbx property {0} found on {1} " , fbxPropertyChannelPair . Property , fbxNode . GetName ( ) ) ) ;
950
+ var fbxProperty = fbxNode . FindProperty ( fbxPropertyChannelPair . Property , false ) ;
951
+ if ( ! fbxProperty . IsValid ( ) )
952
+ {
953
+ var fbxNodeAttribute = fbxNode . GetNodeAttribute ( ) ;
954
+ if ( fbxNodeAttribute != null )
955
+ {
956
+ fbxProperty = fbxNodeAttribute . FindProperty ( fbxPropertyChannelPair . Property , false ) ;
957
+ }
958
+ }
959
+ if ( ! fbxProperty . IsValid ( ) )
960
+ {
961
+ Debug . LogError ( string . Format ( "no fbx property {0} found on {1} node or nodeAttribute " , fbxPropertyChannelPair . Property , fbxNode . GetName ( ) ) ) ;
951
962
return ;
952
963
}
953
964
954
- if ( Verbose ) {
955
- Debug . Log ( "Exporting animation for " + unityObj . ToString ( ) + " (" + unityPropertyName + ")" ) ;
965
+ if ( Verbose )
966
+ {
967
+ Debug . Log ( "Exporting animation for " + unityObj . ToString ( ) + " (" + unityPropertyName + ")" ) ;
956
968
}
957
969
970
+ FbxAnimCurve fbxAnimCurve ;
958
971
// Create the AnimCurve on the channel
959
- FbxAnimCurve fbxAnimCurve = fbxProperty . GetCurve ( fbxAnimLayer , fbxPropertyChannelPair . Channel , true ) ;
972
+ if ( fbxPropertyChannelPair . Channel != null )
973
+ fbxAnimCurve = fbxProperty . GetCurve ( fbxAnimLayer , fbxPropertyChannelPair . Channel , true ) ;
974
+ else
975
+ {
976
+ fbxAnimCurve = fbxProperty . GetCurve ( fbxAnimLayer , true ) ;
977
+ }
960
978
961
979
// copy Unity AnimCurve to FBX AnimCurve.
962
- fbxAnimCurve . KeyModifyBegin ( ) ;
980
+ fbxAnimCurve . KeyModifyBegin ( ) ;
963
981
964
- for ( int keyIndex = 0 , n = unityAnimCurve . length ; keyIndex < n ; ++ keyIndex ) {
965
- var key = unityAnimCurve [ keyIndex ] ;
966
- var fbxTime = FbxTime . FromSecondDouble ( key . time ) ;
967
- fbxAnimCurve . KeyAdd ( fbxTime ) ;
968
- fbxAnimCurve . KeySet ( keyIndex , fbxTime , key . value ) ;
982
+ for ( int keyIndex = 0 , n = unityAnimCurve . length ; keyIndex < n ; ++ keyIndex )
983
+ {
984
+ var key = unityAnimCurve [ keyIndex ] ;
985
+ var fbxTime = FbxTime . FromSecondDouble ( key . time ) ;
986
+ fbxAnimCurve . KeyAdd ( fbxTime ) ;
987
+ fbxAnimCurve . KeySet ( keyIndex , fbxTime , key . value ) ;
969
988
}
970
989
971
- fbxAnimCurve . KeyModifyEnd ( ) ;
990
+ fbxAnimCurve . KeyModifyEnd ( ) ;
972
991
}
973
992
974
993
/// <summary>
@@ -994,6 +1013,7 @@ public static bool TryGetValue(string unityPropertyName, out FbxPropertyChannelP
994
1013
prop = new FbxPropertyChannelPair ( "Lcl Translation" , Globals . FBXSDK_CURVENODE_COMPONENT_X ) ;
995
1014
return true ;
996
1015
}
1016
+
997
1017
if ( unityPropertyName . StartsWith ( "m_LocalPosition.y" , ct ) || unityPropertyName . EndsWith ( "T.y" , ct ) ) {
998
1018
prop = new FbxPropertyChannelPair ( "Lcl Translation" , Globals . FBXSDK_CURVENODE_COMPONENT_Y ) ;
999
1019
return true ;
@@ -1004,6 +1024,12 @@ public static bool TryGetValue(string unityPropertyName, out FbxPropertyChannelP
1004
1024
return true ;
1005
1025
}
1006
1026
1027
+ if ( unityPropertyName . StartsWith ( "m_Intensity" , ct ) || unityPropertyName . EndsWith ( "T.z" , ct ) )
1028
+ {
1029
+ prop = new FbxPropertyChannelPair ( "Intensity" , null ) ;
1030
+ return true ;
1031
+ }
1032
+
1007
1033
prop = new FbxPropertyChannelPair ( ) ;
1008
1034
return false ;
1009
1035
}
@@ -1945,9 +1971,9 @@ private static GameObject GetGameObject (Object obj)
1945
1971
return xform . gameObject ;
1946
1972
} else if ( obj is UnityEngine . GameObject ) {
1947
1973
return obj as UnityEngine . GameObject ;
1948
- } else if ( obj is MonoBehaviour ) {
1949
- var mono = obj as MonoBehaviour ;
1950
- return mono . gameObject ;
1974
+ } else if ( obj is Behaviour ) {
1975
+ var behaviour = obj as Behaviour ;
1976
+ return behaviour . gameObject ;
1951
1977
}
1952
1978
1953
1979
return null ;
0 commit comments