@@ -87,9 +87,24 @@ private static Object LoadModel (string fbxFileName)
87
87
}
88
88
}
89
89
90
+ FrameCameraOnModel ( modelGO ) ;
91
+
90
92
return modelGO as Object ;
91
93
}
92
94
95
+ private static void FrameCameraOnModel ( GameObject modelGO )
96
+ {
97
+ // Set so camera frames model
98
+ // Note: this code assumes the model is at 0,0,0
99
+ Vector3 boundsSize = modelGO . GetComponent < Renderer > ( ) . bounds . size ;
100
+ float distance = Mathf . Max ( boundsSize . x , boundsSize . y , boundsSize . z ) ;
101
+ distance /= ( 2.0f * Mathf . Tan ( 0.5f * Camera . main . fieldOfView * Mathf . Deg2Rad ) ) ;
102
+ Camera . main . transform . position = new Vector3 ( Camera . main . transform . position . x , Camera . main . transform . position . y , - distance * 2.0f ) ;
103
+
104
+ // rotate camera towards model
105
+ Camera . main . transform . LookAt ( modelGO . transform . position ) ;
106
+ }
107
+
93
108
private static void LoadLastSavedModel ( )
94
109
{
95
110
string fbxFileName = GetLastSavedFilePath ( ) ;
@@ -179,6 +194,20 @@ public static void LastSavedModel ()
179
194
// make turntable the active scene
180
195
UnityEngine . SceneManagement . SceneManager . SetActiveScene ( scene ) ;
181
196
197
+ // create camera and light if none
198
+ if ( Camera . main == null ) {
199
+ GameObject camera = new GameObject ( "MainCamera" ) ;
200
+ camera . AddComponent < Camera > ( ) ;
201
+ camera . tag = "MainCamera" ;
202
+
203
+ GameObject light = new GameObject ( "Light" ) ;
204
+ light . transform . localEulerAngles = new Vector3 ( 50 , - 30 , 0 ) ;
205
+ Light lightComp = light . AddComponent < Light > ( ) ;
206
+ lightComp . type = LightType . Directional ;
207
+ lightComp . intensity = 1 ;
208
+ lightComp . shadows = LightShadows . Soft ;
209
+ }
210
+
182
211
if ( AutoUpdateEnabled ( ) ) {
183
212
LoadLastSavedModel ( ) ;
184
213
0 commit comments