1
1
using UnityEngine ;
2
2
using Autodesk . Fbx ;
3
3
using UnityEditor . Formats . Fbx . Exporter . CustomExtensions ;
4
+ using System . Collections . Generic ;
4
5
5
6
namespace UnityEditor . Formats . Fbx . Exporter
6
7
{
7
8
namespace Visitors
8
9
{
9
10
internal static class CameraVisitor
10
11
{
12
+ private static Dictionary < Camera . GateFitMode , FbxCamera . EGateFit > s_mapGateFit = new Dictionary < Camera . GateFitMode , FbxCamera . EGateFit > ( )
13
+ {
14
+ { Camera . GateFitMode . Fill , FbxCamera . EGateFit . eFitFill } ,
15
+ { Camera . GateFitMode . Horizontal , FbxCamera . EGateFit . eFitHorizontal } ,
16
+ { Camera . GateFitMode . None , FbxCamera . EGateFit . eFitNone } ,
17
+ { Camera . GateFitMode . Overscan , FbxCamera . EGateFit . eFitOverscan } ,
18
+ { Camera . GateFitMode . Vertical , FbxCamera . EGateFit . eFitVertical }
19
+ } ;
20
+
11
21
/// <summary>
12
22
/// Visit Object and configure FbxCamera
13
23
/// </summary>
@@ -56,6 +66,14 @@ private static void ConfigureGameCamera (FbxCamera fbxCamera, Camera unityCamera
56
66
return ;
57
67
}
58
68
69
+ public static Vector2 GetSizeOfMainGameView ( )
70
+ {
71
+ System . Type T = System . Type . GetType ( "UnityEditor.GameView,UnityEditor" ) ;
72
+ System . Reflection . MethodInfo GetSizeOfMainGameView = T . GetMethod ( "GetSizeOfMainGameView" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Static ) ;
73
+ System . Object Res = GetSizeOfMainGameView . Invoke ( null , null ) ;
74
+ return ( Vector2 ) Res ;
75
+ }
76
+
59
77
/// <summary>
60
78
/// Configure FbxCameras from a Physical Camera
61
79
/// </summary>
@@ -80,11 +98,14 @@ private static void ConfigurePhysicalCamera (FbxCamera fbxCamera, Camera unityCa
80
98
81
99
fbxCamera . ProjectionType . Set ( projectionType ) ;
82
100
fbxCamera . FilmAspectRatio . Set ( aspectRatio ) ;
101
+
102
+ Vector2 gameViewSize = GetSizeOfMainGameView ( ) ;
103
+ fbxCamera . SetAspect ( FbxCamera . EAspectRatioMode . eFixedRatio , gameViewSize . x / gameViewSize . y , 1.0 ) ;
83
104
fbxCamera . SetApertureWidth ( apertureWidthInInches ) ;
84
105
fbxCamera . SetApertureHeight ( apertureHeightInInches ) ;
85
106
86
107
// Fit the resolution gate horizontally within the film gate.
87
- fbxCamera . GateFit . Set ( FbxCamera . EGateFit . eFitHorizontal ) ;
108
+ fbxCamera . GateFit . Set ( s_mapGateFit [ unityCamera . gateFit ] ) ;
88
109
89
110
// Lens Shift ( Film Offset ) as a percentage 0..1
90
111
// FBX FilmOffset is in inches
0 commit comments