@@ -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>
@@ -850,6 +857,125 @@ protected bool ExportCamera (GameObject unityGO, FbxScene fbxScene, FbxNode fbxN
850
857
return true ;
851
858
}
852
859
860
+ /// <summary>
861
+ /// Exports light component.
862
+ /// Supported types: point, spot and directional
863
+ /// Cookie => Gobo
864
+ /// </summary>
865
+ protected bool ExportLight ( GameObject unityGo , FbxScene fbxScene , FbxNode fbxNode )
866
+ {
867
+ Light unityLight = unityGo . GetComponent < Light > ( ) ;
868
+
869
+ if ( unityLight == null )
870
+ return false ;
871
+
872
+ FbxLight . EType fbxLightType ;
873
+
874
+ // Is light type supported?
875
+ if ( ! MapLightType . TryGetValue ( unityLight . type , out fbxLightType ) )
876
+ return false ;
877
+
878
+ FbxLight fbxLight = FbxLight . Create ( fbxScene . GetFbxManager ( ) , unityLight . name ) ;
879
+
880
+ // Set the type of the light.
881
+ fbxLight . LightType . Set ( fbxLightType ) ;
882
+
883
+ switch ( unityLight . type )
884
+ {
885
+ case LightType . Directional : {
886
+ break ;
887
+ }
888
+ case LightType . Spot : {
889
+ // Set the angle of the light's spotlight cone in degrees.
890
+ fbxLight . InnerAngle . Set ( unityLight . spotAngle ) ;
891
+ fbxLight . OuterAngle . Set ( unityLight . spotAngle ) ;
892
+ break ;
893
+ }
894
+ case LightType . Point : {
895
+ break ;
896
+ }
897
+ case LightType . Area : {
898
+ // TODO: areaSize: The size of the area light by scaling the node XY
899
+ break ;
900
+ }
901
+ }
902
+
903
+ // Export bounceIntensity as custom property
904
+ // NOTE: export on fbxNode so that it will show up in Maya
905
+ ExportFloatProperty ( fbxNode , unityLight . bounceIntensity ,
906
+ MakeName ( "bounceIntensity" ) ,
907
+ "The multiplier that defines the strength of the bounce lighting." ) ;
908
+
909
+ // The color of the light.
910
+ var unityLightColor = unityLight . color ;
911
+
912
+ fbxLight . Color . Set ( new FbxDouble3 ( unityLightColor . r , unityLightColor . g , unityLightColor . b ) ) ;
913
+
914
+ // Export colorTemperature as custom property
915
+ ExportFloatProperty ( fbxNode , unityLight . colorTemperature ,
916
+ MakeName ( "colorTemperature" ) ,
917
+ "The color temperature of the light. Correlated Color Temperature (abbreviated as CCT) is multiplied with the color filter when calculating the final color of a light source.The color temperature of the electromagnetic radiation emitted from an ideal black body is defined as its surface temperature in Kelvin.White is 6500K according to the D65 standard. Candle light is 1800K.If you want to use lightsUseCCT, lightsUseLinearIntensity has to be enabled to ensure physically correct output. See Also: GraphicsSettings.lightsUseLinearIntensity, GraphicsSettings.lightsUseCCT." ) ;
918
+
919
+ // TODO: commandBufferCount Number of command buffers set up on this light (Read Only).
920
+
921
+ // cookie The cookie texture projected by the light.
922
+ var unityCookieTexture = unityLight . cookie ;
923
+
924
+ if ( unityCookieTexture != null )
925
+ {
926
+ // Find its filename
927
+ var textureSourceFullPath = AssetDatabase . GetAssetPath ( unityCookieTexture ) ;
928
+ if ( textureSourceFullPath != "" ) {
929
+
930
+ // get absolute filepath to texture
931
+ textureSourceFullPath = Path . GetFullPath ( textureSourceFullPath ) ;
932
+
933
+ fbxLight . FileName . Set ( textureSourceFullPath ) ;
934
+ fbxLight . DrawGroundProjection . Set ( true ) ;
935
+ fbxLight . DrawVolumetricLight . Set ( true ) ;
936
+ fbxLight . DrawFrontFacingVolumetricLight . Set ( false ) ;
937
+ }
938
+ }
939
+
940
+ // Export cookieSize as custom property
941
+ ExportFloatProperty ( fbxNode , unityLight . cookieSize ,
942
+ MakeName ( "cookieSize" ) ,
943
+ "The size of a directional light's cookie." ) ;
944
+
945
+ // TODO: cullingMask This is used to light certain objects in the scene selectively.
946
+ // TODO: flare The flare asset to use for this light.
947
+
948
+ // Set the Intensity of a light is multiplied with the Light color.
949
+ fbxLight . Intensity . Set ( unityLight . intensity * 100.0f /*compensate for Maya scaling by system units*/ ) ;
950
+
951
+ // TODO: isBaked Is the light contribution already stored in lightmaps and/or lightprobes (Read Only).
952
+ // TODO: lightmapBakeType This property describes what part of a light's contribution can be baked.
953
+
954
+ // Set the range of the light.
955
+ // applies-to: Point & Spot
956
+ // => FarAttenuationStart, FarAttenuationEnd
957
+ fbxLight . FarAttenuationStart . Set ( 0.01f /* none zero start */ ) ;
958
+ fbxLight . FarAttenuationEnd . Set ( unityLight . range ) ;
959
+
960
+ // TODO: renderMode How to render the light.
961
+
962
+ // shadows Set how this light casts shadows
963
+ // applies-to: Point & Spot
964
+ bool unityLightCastShadows = unityLight . shadows != LightShadows . None ;
965
+ fbxLight . CastShadows . Set ( unityLightCastShadows ) ;
966
+
967
+ // TODO: shadowBias Shadow mapping constant bias.
968
+ // TODO: shadowCustomResolution The custom resolution of the shadow map.
969
+ // TODO: shadowNearPlane Near plane value to use for shadow frustums.
970
+ // TODO: shadowNormalBias Shadow mapping normal-based bias.
971
+ // TODO: shadowResolution The resolution of the shadow map.
972
+ // TODO: shadowStrength Strength of light's shadows.
973
+
974
+ fbxNode . SetNodeAttribute ( fbxLight ) ;
975
+
976
+ return true ;
977
+ }
978
+
853
979
/// <summary>
854
980
/// configures default camera for the scene
855
981
/// </summary>
@@ -883,6 +1009,26 @@ bool ExportColorProperty (FbxObject fbxObject, Color value, string name, string
883
1009
return true ;
884
1010
}
885
1011
1012
+ /// <summary>
1013
+ /// Export Unity Property as a Float Property
1014
+ /// </summary>
1015
+ FbxProperty ExportFloatProperty ( FbxObject fbxObject , float value , string name , string label )
1016
+ {
1017
+ // add (not particularly useful) custom data: how many Unity
1018
+ // components does the unity object have?
1019
+ var fbxProperty = FbxProperty . Create ( fbxObject , Globals . FbxDoubleDT , name , label ) ;
1020
+ if ( ! fbxProperty . IsValid ( ) ) {
1021
+ throw new System . NullReferenceException ( ) ;
1022
+ }
1023
+ fbxProperty . Set ( value ) ;
1024
+
1025
+ // Must be marked user-defined or it won't be shown in most DCCs
1026
+ fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eUserDefined , true ) ;
1027
+ fbxProperty . ModifyFlag ( FbxPropertyFlags . EFlags . eAnimatable , true ) ;
1028
+
1029
+ return fbxProperty ;
1030
+ }
1031
+
886
1032
/// <summary>
887
1033
/// Export Component's int property
888
1034
/// </summary>
@@ -964,8 +1110,14 @@ protected int ExportComponents (
964
1110
}
965
1111
966
1112
// export camera, but only if no mesh was exported
1113
+ bool exportedCamera = false ;
967
1114
if ( ! exportedMesh ) {
968
- ExportCamera ( unityGo , fbxScene , fbxNode ) ;
1115
+ exportedCamera = ExportCamera ( unityGo , fbxScene , fbxNode ) ;
1116
+ }
1117
+
1118
+ // export light, but only if no mesh or camera was exported
1119
+ if ( ! exportedMesh && ! exportedCamera ) {
1120
+ ExportLight ( unityGo , fbxScene , fbxNode ) ;
969
1121
}
970
1122
971
1123
if ( Verbose )
0 commit comments