@@ -19,16 +19,13 @@ def ReadLineWords(file):
1919 return words
2020
2121def AlienSwarm_FovScaling (width , height , fov ):
22-
2322 if 0 == height :
2423 return fov
25-
26- engineAspectRatio = width / height ;
27- defaultAscpectRatio = 4.0 / 3.0 ;
28- ratio = engineAspectRatio / defaultAscpectRatio ;
29- halfAngle = 0.5 * fov * (2.0 * math .pi / 360.0 );
30- t = ratio * math .tan (halfAngle );
31- return 2.0 * math .atan (t ) / (2.0 * math .pi / 360.0 );
24+ engineAspectRatio = width / height
25+ defaultAscpectRatio = 4.0 / 3.0
26+ ratio = engineAspectRatio / defaultAscpectRatio
27+ t = ratio * math .tan (math .radians (0.5 * fov ))
28+ return 2.0 * math .degrees (math .atan (t ))
3229
3330class CameraData :
3431 def __init__ (self ,o ,c ):
@@ -76,9 +73,8 @@ def invoke(self, context, event):
7673
7774 def createCamera (self , context , camName ):
7875
79- camBData = bpy .data .cameras .new (camName )
80- o = bpy .data .objects .new (camName , camBData )
81- c = bpy .data .cameras [o .name ]
76+ c = bpy .data .cameras .new (camName )
77+ o = bpy .data .objects .new (camName , c )
8278
8379 context .scene .collection .objects .link (o )
8480
@@ -91,7 +87,7 @@ def createCamera(self, context, camName):
9187 o .rotation_mode = 'QUATERNION'
9288
9389
94- # Create actions and their curves (boobs) :
90+ # Create actions and their curves:
9591
9692 o .animation_data_create ()
9793 action = bpy .data .actions .new (name = "game_data" )
@@ -108,28 +104,17 @@ def createCamera(self, context, camName):
108104 c .animation_data .action = action
109105
110106 camData .curves .append (action .fcurves .new ("lens" ))
111-
112- return camData
113-
114- # <returns> Camera FOV in radians </returns>
115- def calcCameraFov (self ):
116- fov = math .radians (self .cameraFov )
117-
118- if self .scaleFov :
119- defaultAspectRatio = 4.0 / 3.0
120- engineAspectRatio = (self .screenWidth / self .screenHeight ) if 0 != self .screenHeight else defaultAspectRatio
121- ratio = engineAspectRatio / defaultAspectRatio
122- halfAngle = fov * 0.5
123- fov = math .atan (math .tan (halfAngle ) * ratio ) * 2.0
124107
125- return fov
108+ return camData
126109
127110 def readCam (self , context ):
128111 fps = context .scene .render .fps
129112
130113 width = context .scene .render .pixel_aspect_x * context .scene .render .resolution_x
131114 height = context .scene .render .pixel_aspect_y * context .scene .render .resolution_y
132115
116+ frame_end = None
117+
133118 camData = self .createCamera (context ,"afxCam" )
134119
135120 if camData is None :
@@ -144,7 +129,7 @@ def readCam(self, context):
144129 file = open (self .filepath , 'rU' )
145130
146131 version = 0
147- scaleFov = 'none '
132+ scaleFov = ''
148133
149134 words = ReadLineWords (file )
150135
@@ -163,11 +148,11 @@ def readCam(self, context):
163148 if 'scaleFov' == words [0 ] and 2 <= len (words ):
164149 scaleFov = words [1 ]
165150
166- if (1 != version ):
167- self .error ("Invalid version, only 1 is supported." )
151+ if (version < 1 or version > 2 ):
152+ self .error ("Invalid version, only 1 - 2 are supported." )
168153 return False
169154
170- if not (scaleFov in ['none' , 'alienSwarm' ]):
155+ if not (scaleFov in ['' , ' none' , 'alienSwarm' ]):
171156 self .error ("Unsupported scaleFov value." )
172157 return False
173158
@@ -191,6 +176,8 @@ def readCam(self, context):
191176
192177 time = 1.0 + time * fps
193178
179+ frame_end = int (math .ceil (time ))
180+
194181 renderOrigin = mathutils .Vector ((- float (words [2 ]),float (words [1 ]),float (words [3 ]))) * self .global_scale
195182 qAngle = afx_utils .QAngle (float (words [5 ]),float (words [6 ]),float (words [4 ]))
196183
@@ -206,7 +193,8 @@ def readCam(self, context):
206193
207194 fov = float (words [7 ])
208195
209- if 'alienSwarm' == scaleFov :
196+ # none and alienSwarm was confused in version 1, version 2 always outputs real fov and doesn't have scaleFov.
197+ if 'none' == scaleFov :
210198 fov = AlienSwarm_FovScaling (width , height , fov )
211199
212200 lens = camData .c .sensor_width / (2.0 * math .tan (math .radians (fov ) / 2.0 ))
@@ -218,6 +206,10 @@ def readCam(self, context):
218206 afx_utils .AddKey_Rotation (self .interKey , curves [0 + 3 ].keyframe_points , curves [0 + 4 ].keyframe_points , curves [0 + 5 ].keyframe_points , curves [0 + 6 ].keyframe_points , time , quat )
219207
220208 afx_utils .AddKey_Value (self .interKey , curves [0 + 7 ].keyframe_points , time , lens )
209+
210+ if frame_end is not None :
211+ bpy .context .scene .frame_start = 1
212+ bpy .context .scene .frame_end = frame_end
221213
222214 finally :
223215 if file is not None :
0 commit comments