@@ -124,6 +124,13 @@ public static Material DefaultMaterial {
124
124
}
125
125
static Material s_defaultMaterial = null ;
126
126
127
+ static Dictionary < UnityEngine . LightType , FbxLight . EType > MapLightType = new Dictionary < UnityEngine . LightType , FbxLight . EType > ( ) {
128
+ { UnityEngine . LightType . Directional , FbxLight . EType . eDirectional } ,
129
+ { UnityEngine . LightType . Spot , FbxLight . EType . eSpot } ,
130
+ { UnityEngine . LightType . Point , FbxLight . EType . ePoint } ,
131
+ { UnityEngine . LightType . Area , FbxLight . EType . eArea } ,
132
+ } ;
133
+
127
134
/// <summary>
128
135
/// Gets the version number of the FbxExporters plugin from the readme.
129
136
/// </summary>
@@ -825,18 +832,6 @@ protected bool ExportCamera (GameObject unityGO, FbxScene fbxScene, FbxNode fbxN
825
832
fbxCamera . SetFarPlane ( unityCamera . farClipPlane * UnitScaleFactor ) ;
826
833
#endregion
827
834
828
- // Export backgroundColor as a custom property
829
- // NOTE: export on fbxNode so that it will show up in Maya
830
- ExportColorProperty ( fbxNode , unityCamera . backgroundColor ,
831
- MakeName ( "backgroundColor" ) ,
832
- "The color with which the screen will be cleared." ) ;
833
-
834
- // Export clearFlags as a custom property
835
- // NOTE: export on fbxNode so that it will show up in Maya
836
- ExportIntProperty ( fbxNode , ( int ) unityCamera . clearFlags ,
837
- MakeName ( "clearFlags" ) ,
838
- "How the camera clears the background." ) ;
839
-
840
835
fbxNode . SetNodeAttribute ( fbxCamera ) ;
841
836
842
837
// set +90 post rotation to counteract for FBX camera's facing +X direction by default
@@ -851,55 +846,84 @@ protected bool ExportCamera (GameObject unityGO, FbxScene fbxScene, FbxNode fbxN
851
846
}
852
847
853
848
/// <summary>
854
- /// configures default camera for the scene
849
+ /// Exports light component.
850
+ /// Supported types: point, spot and directional
851
+ /// Cookie => Gobo
855
852
/// </summary>
856
- protected void SetDefaultCamera ( FbxScene fbxScene )
853
+ protected bool ExportLight ( GameObject unityGo , FbxScene fbxScene , FbxNode fbxNode )
857
854
{
858
- if ( DefaultCamera == "" )
859
- DefaultCamera = Globals . FBXSDK_CAMERA_PERSPECTIVE ;
855
+ Light unityLight = unityGo . GetComponent < Light > ( ) ;
860
856
861
- fbxScene . GetGlobalSettings ( ) . SetDefaultCamera ( DefaultCamera ) ;
862
- }
857
+ if ( unityLight == null )
858
+ return false ;
863
859
864
- /// <summary>
865
- /// Export Component's color property
866
- /// </summary>
867
- bool ExportColorProperty ( FbxObject fbxObject , Color value , string name , string label )
868
- {
869
- // create a custom property for component value
870
- var fbxProperty = FbxProperty . Create ( fbxObject , Globals . FbxColor4DT , name , label ) ;
871
- if ( ! fbxProperty . IsValid ( ) ) {
872
- throw new System . NullReferenceException ( ) ;
860
+ FbxLight . EType fbxLightType ;
861
+
862
+ // Is light type supported?
863
+ if ( ! MapLightType . TryGetValue ( unityLight . type , out fbxLightType ) )
864
+ return false ;
865
+
866
+ FbxLight fbxLight = FbxLight . Create ( fbxScene . GetFbxManager ( ) , unityLight . name ) ;
867
+
868
+ // Set the type of the light.
869
+ fbxLight . LightType . Set ( fbxLightType ) ;
870
+
871
+ switch ( unityLight . type )
872
+ {
873
+ case LightType . Directional : {
874
+ break ;
875
+ }
876
+ case LightType . Spot : {
877
+ // Set the angle of the light's spotlight cone in degrees.
878
+ fbxLight . InnerAngle . Set ( unityLight . spotAngle ) ;
879
+ fbxLight . OuterAngle . Set ( unityLight . spotAngle ) ;
880
+ break ;
881
+ }
882
+ case LightType . Point : {
883
+ break ;
884
+ }
885
+ case LightType . Area : {
886
+ // TODO: areaSize: The size of the area light by scaling the node XY
887
+ break ;
888
+ }
873
889
}
890
+ // The color of the light.
891
+ var unityLightColor = unityLight . color ;
892
+ fbxLight . Color . Set ( new FbxDouble3 ( unityLightColor . r , unityLightColor . g , unityLightColor . b ) ) ;
874
893
875
- FbxColor fbxColor = new FbxColor ( value . r , value . g , value . b , value . a ) ;
894
+ // Set the Intensity of a light is multiplied with the Light color.
895
+ fbxLight . Intensity . Set ( unityLight . intensity * UnitScaleFactor /*compensate for Maya scaling by system units*/ ) ;
876
896
877
- fbxProperty . Set ( fbxColor ) ;
897
+ // Set the range of the light.
898
+ // applies-to: Point & Spot
899
+ // => FarAttenuationStart, FarAttenuationEnd
900
+ fbxLight . FarAttenuationStart . Set ( 0.01f /* none zero start */ ) ;
901
+ fbxLight . FarAttenuationEnd . Set ( unityLight . range * UnitScaleFactor ) ;
878
902
879
- // Must be marked user-defined or it won't be shown in most DCCs
880
- fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eUserDefined , true ) ;
881
- fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eAnimatable , true ) ;
903
+ // shadows Set how this light casts shadows
904
+ // applies-to: Point & Spot
905
+ bool unityLightCastShadows = unityLight . shadows != LightShadows . None ;
906
+ fbxLight . CastShadows . Set ( unityLightCastShadows ) ;
907
+
908
+ fbxNode . SetNodeAttribute ( fbxLight ) ;
909
+
910
+ // set +90 post rotation on x to counteract for FBX light's facing -Y direction by default
911
+ fbxNode . SetPostRotation ( FbxNode . EPivotSet . eSourcePivot , new FbxVector4 ( 90 , 0 , 0 ) ) ;
912
+ // have to set rotation active to true in order for post rotation to be applied
913
+ fbxNode . SetRotationActive ( true ) ;
882
914
883
915
return true ;
884
916
}
885
917
886
918
/// <summary>
887
- /// Export Component's int property
919
+ /// configures default camera for the scene
888
920
/// </summary>
889
- bool ExportIntProperty ( FbxObject fbxObject , int value , string name , string label )
921
+ protected void SetDefaultCamera ( FbxScene fbxScene )
890
922
{
891
- // create a custom property for component value
892
- var fbxProperty = FbxProperty . Create ( fbxObject , Globals . FbxIntDT , name , label ) ;
893
- if ( ! fbxProperty . IsValid ( ) ) {
894
- throw new System . NullReferenceException ( ) ;
895
- }
896
- fbxProperty . Set ( value ) ;
897
-
898
- // Must be marked user-defined or it won't be shown in most DCCs
899
- fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eUserDefined , true ) ;
900
- fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eAnimatable , true ) ;
923
+ if ( DefaultCamera == "" )
924
+ DefaultCamera = Globals . FBXSDK_CAMERA_PERSPECTIVE ;
901
925
902
- return true ;
926
+ fbxScene . GetGlobalSettings ( ) . SetDefaultCamera ( DefaultCamera ) ;
903
927
}
904
928
905
929
/// <summary>
@@ -964,8 +988,14 @@ protected int ExportComponents (
964
988
}
965
989
966
990
// export camera, but only if no mesh was exported
991
+ bool exportedCamera = false ;
967
992
if ( ! exportedMesh ) {
968
- ExportCamera ( unityGo , fbxScene , fbxNode ) ;
993
+ exportedCamera = ExportCamera ( unityGo , fbxScene , fbxNode ) ;
994
+ }
995
+
996
+ // export light, but only if no mesh or camera was exported
997
+ if ( ! exportedMesh && ! exportedCamera ) {
998
+ ExportLight ( unityGo , fbxScene , fbxNode ) ;
969
999
}
970
1000
971
1001
if ( Verbose )
@@ -1318,6 +1348,9 @@ private void ReplaceFile ()
1318
1348
} catch ( IOException ) {
1319
1349
}
1320
1350
1351
+ // refresh the database so Unity knows the file's been deleted
1352
+ AssetDatabase . Refresh ( ) ;
1353
+
1321
1354
if ( File . Exists ( m_lastFilePath ) ) {
1322
1355
Debug . LogWarning ( "Failed to delete file: " + m_lastFilePath ) ;
1323
1356
}
0 commit comments