@@ -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>
@@ -838,6 +845,76 @@ protected bool ExportCamera (GameObject unityGO, FbxScene fbxScene, FbxNode fbxN
838
845
return true ;
839
846
}
840
847
848
+ /// <summary>
849
+ /// Exports light component.
850
+ /// Supported types: point, spot and directional
851
+ /// Cookie => Gobo
852
+ /// </summary>
853
+ protected bool ExportLight ( GameObject unityGo , FbxScene fbxScene , FbxNode fbxNode )
854
+ {
855
+ Light unityLight = unityGo . GetComponent < Light > ( ) ;
856
+
857
+ if ( unityLight == null )
858
+ return false ;
859
+
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
+ }
889
+ }
890
+ // The color of the light.
891
+ var unityLightColor = unityLight . color ;
892
+ fbxLight . Color . Set ( new FbxDouble3 ( unityLightColor . r , unityLightColor . g , unityLightColor . b ) ) ;
893
+
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*/ ) ;
896
+
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 ) ;
902
+
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 ) ;
914
+
915
+ return true ;
916
+ }
917
+
841
918
/// <summary>
842
919
/// configures default camera for the scene
843
920
/// </summary>
@@ -911,8 +988,14 @@ protected int ExportComponents (
911
988
}
912
989
913
990
// export camera, but only if no mesh was exported
991
+ bool exportedCamera = false ;
914
992
if ( ! exportedMesh ) {
915
- 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 ) ;
916
999
}
917
1000
918
1001
if ( Verbose )
0 commit comments