@@ -163,6 +163,19 @@ def ReadQuaternion(file, quakeFormat = False):
163163 z = 0
164164
165165 return mathutils .Quaternion ((w ,- y ,x ,z )) if quakeFormat else mathutils .Quaternion ((w ,x ,y ,z ))
166+
167+ def ReadMatrix3x4 (file ):
168+ mat = mathutils .Matrix ()
169+ for i in range (3 ):
170+ for j in range (4 ):
171+ val = ReadFloat (file )
172+ if val is None :
173+ return None
174+ if math .isinf (val ):
175+ val = 0
176+ mat [i ][j ] = val
177+
178+ return mat
166179
167180def ReadAgrVersion (file ):
168181 buf = file .read (14 )
@@ -230,6 +243,7 @@ def __init__(self,objNr,modelName):
230243 self .visible = None
231244 self .location = None
232245 self .rotation = None
246+ self .scale = None
233247 self .bones = None
234248
235249 # We are lazy, so we use frame 0 to set as not visible (initially) / hide_render 1:
@@ -241,13 +255,19 @@ def __init__(self,objNr,modelName):
241255 self .rotationXFrames = []
242256 self .rotationYFrames = []
243257 self .rotationZFrames = []
258+ self .scaleXFrames = []
259+ self .scaleYFrames = []
260+ self .scaleZFrames = []
244261 self .boneLocationXFrames = defaultdict (list )
245262 self .boneLocationYFrames = defaultdict (list )
246263 self .boneLocationZFrames = defaultdict (list )
247264 self .boneRotationWFrames = defaultdict (list )
248265 self .boneRotationXFrames = defaultdict (list )
249266 self .boneRotationYFrames = defaultdict (list )
250267 self .boneRotationZFrames = defaultdict (list )
268+ self .boneScaleXFrames = defaultdict (list )
269+ self .boneScaleYFrames = defaultdict (list )
270+ self .boneScaleZFrames = defaultdict (list )
251271
252272 def UpdateVisible (self ,curTime ,visible ,interKey ):
253273 self .Update (curTime ,interKey )
@@ -261,6 +281,10 @@ def UpdateRotation(self,curTime,rotation,interKey):
261281 self .Update (curTime ,interKey )
262282 self .rotation = rotation
263283
284+ def UpdateScale (self ,curTime ,scale ,interKey ):
285+ self .Update (curTime ,interKey )
286+ self .scale = scale
287+
264288 def UpdateBones (self ,curTime ,bones ,interKey ):
265289 self .Update (curTime ,interKey )
266290 self .bones = bones
@@ -299,6 +323,13 @@ def Update(self,curTime,interKey):
299323 self .rotationYFrames .extend ((self .lastTime , self .rotation .y ))
300324 self .rotationZFrames .extend ((self .lastTime , self .rotation .z ))
301325
326+ if self .scale is not None :
327+ if interKey :
328+ afx_utils .AppendInterKeys_Location (self .lastTime , self .scale , self .scaleXFrames , self .scaleYFrames , self .scaleZFrames )
329+ self .scaleXFrames .extend ((self .lastTime , self .scale .x ))
330+ self .scaleYFrames .extend ((self .lastTime , self .scale .y ))
331+ self .scaleZFrames .extend ((self .lastTime , self .scale .z ))
332+
302333 if self .bones is not None :
303334 for idx ,i in enumerate (self .bones ):
304335
@@ -316,6 +347,7 @@ def Update(self,curTime,interKey):
316347 if interKey :
317348 afx_utils .AppendInterKeys_Location (self .lastTime , bone .location , self .boneLocationXFrames [i ], self .boneLocationYFrames [i ], self .boneLocationZFrames [i ])
318349 afx_utils .AppendInterKeys_Rotation (self .lastTime , renderRotQuat , self .boneRotationWFrames [i ], self .boneRotationXFrames [i ], self .boneRotationYFrames [i ], self .boneRotationZFrames [i ])
350+ afx_utils .AppendInterKeys_Location (self .lastTime , bone .scale , self .boneScaleXFrames [i ], self .boneScaleYFrames [i ], self .boneScaleZFrames [i ])
319351
320352 self .boneLocationXFrames [i ].extend ((self .lastTime , bone .location .x ))
321353 self .boneLocationYFrames [i ].extend ((self .lastTime , bone .location .y ))
@@ -325,6 +357,10 @@ def Update(self,curTime,interKey):
325357 self .boneRotationXFrames [i ].extend ((self .lastTime , renderRotQuat .x ))
326358 self .boneRotationYFrames [i ].extend ((self .lastTime , renderRotQuat .y ))
327359 self .boneRotationZFrames [i ].extend ((self .lastTime , renderRotQuat .z ))
360+
361+ self .boneScaleXFrames [i ].extend ((self .lastTime , bone .scale .x ))
362+ self .boneScaleYFrames [i ].extend ((self .lastTime , bone .scale .y ))
363+ self .boneScaleZFrames [i ].extend ((self .lastTime , bone .scale .z ))
328364
329365 self .visible = None
330366 self .location = None
@@ -568,6 +604,9 @@ def addCurvesToModel(self, context, modelData):
568604
569605 for i in range (4 ):
570606 modelData .curves .append (action .fcurves .new ("rotation_quaternion" ,index = i ))
607+
608+ for i in range (3 ):
609+ modelData .curves .append (action .fcurves .new ("scale" ,index = i ))
571610
572611 num_bones = len (a .pose .bones )
573612
@@ -582,6 +621,9 @@ def addCurvesToModel(self, context, modelData):
582621 for j in range (4 ):
583622 modelData .curves .append (action .fcurves .new (bone_string + "rotation_quaternion" ,index = j ))
584623
624+ for j in range (3 ):
625+ modelData .curves .append (action .fcurves .new (bone_string + "scale" ,index = j ))
626+
585627 # Create visibility driver:
586628
587629 for child in a .children :
@@ -598,17 +640,14 @@ def addCurvesToModel(self, context, modelData):
598640
599641 for df in ds :
600642 d = df .driver
601- d .type = 'AVERAGE'
602- v = d .variables .new ()
603- v .name = 'hide_render'
604- v .targets [0 ].id = a
605- v .targets [0 ].data_path = 'hide_render'
606- m = df .modifiers .new ('GENERATOR' )
607- m .coefficients [0 ] = self .global_scale
608- m .coefficients [1 ] = - self .global_scale
609- m .poly_order = 1
610- m .mode = 'POLYNOMIAL'
611- m .use_additive = False
643+ d .type = 'SCRIPTED'
644+ d .use_self = True
645+ h = d .variables .new ()
646+ h .name = 'hide'
647+ h .targets [0 ].id = a
648+ h .targets [0 ].data_path = 'hide_render'
649+ d .expression = "(1-hide)*self"
650+
612651
613652 return modelData
614653
@@ -777,7 +816,7 @@ def readAgr(self,context):
777816 self .error ('Invalid file format.' )
778817 return result
779818
780- if 5 != version :
819+ if ( 5 != version and version != 6 ) :
781820 self .error ('Version ' + str (version )+ ' is not supported!' )
782821 return result
783822
@@ -873,11 +912,18 @@ def readAgr(self,context):
873912
874913 visible = ReadBool (file )
875914
876- renderOrigin = ReadVector (file , quakeFormat = True )
877- renderAngles = ReadQAngle (file )
915+ if 5 == version :
916+ renderOrigin = ReadVector (file , quakeFormat = True )
917+ renderAngles = ReadQAngle (file )
918+ renderRotQuat = renderAngles .to_quaternion ()
919+ renderScale = mathutils .Vector ((1 ,1 ,1 ))
920+ else :
921+ matrix = ReadMatrix3x4 (file )
922+ matrix = self .valveMatrixToBlender @ matrix
923+ renderOrigin , renderRotQuat , renderScale = matrix .decompose ()
878924
879925 renderOrigin = renderOrigin * self .global_scale
880- renderRotQuat = renderAngles . to_quaternion ()
926+ renderScale = renderScale * self . global_scale
881927
882928 modelHandle = handleToLastModelHandle .get (handle , None )
883929
@@ -925,6 +971,7 @@ def readAgr(self,context):
925971 modelHandle .UpdateVisible (currentTime , visible , self .interKey )
926972 modelHandle .UpdateLocation (currentTime , renderOrigin , self .interKey )
927973 modelHandle .UpdateRotation (currentTime , renderRotQuat , self .interKey )
974+ modelHandle .UpdateScale (currentTime , renderScale , self .interKey )
928975
929976 if dictionary .Peekaboo (file ,'baseanimating' ):
930977 #skin = ReadInt(file)
@@ -938,8 +985,12 @@ def readAgr(self,context):
938985
939986 for i in range (numBones ):
940987 #pos = file.tell()
941- vec = ReadVector (file , quakeFormat = False )
942- quat = ReadQuaternion (file , quakeFormat = False )
988+ if 5 == version :
989+ vec = ReadVector (file , quakeFormat = False )
990+ quat = ReadQuaternion (file , quakeFormat = False )
991+ matrix = mathutils .Matrix .Translation (vec ) @ quat .to_matrix ().to_4x4 ()
992+ else :
993+ matrix = ReadMatrix3x4 (file )
943994
944995 if (modelData is None ):
945996 continue
@@ -953,12 +1004,11 @@ def readAgr(self,context):
9531004
9541005 #self.warning(str(pos)+": "+str(i)+"("+bone.name+"): "+str(vec)+" "+str(quat))
9551006
956- matrix = mathutils .Matrix .Translation (vec ) @ quat .to_matrix ().to_4x4 ()
957-
9581007 if bone .parent :
9591008 matrix = bone .parent .matrix @ matrix
9601009 else :
961- matrix = self .valveMatrixToBlender @ matrix
1010+ if 5 == version :
1011+ matrix = self .valveMatrixToBlender @ matrix
9621012
9631013 bone .matrix = matrix
9641014
@@ -1034,9 +1084,11 @@ def readAgr(self,context):
10341084 totalFrames += len (modelHandle .visibilityFrames )
10351085 totalFrames += len (modelHandle .locationXFrames ) * 3
10361086 totalFrames += len (modelHandle .rotationWFrames ) * 4
1087+ totalFrames += len (modelHandle .scaleXFrames ) * 3
10371088 for i in modelHandle .boneLocationXFrames :
10381089 totalFrames += len (modelHandle .boneLocationXFrames [i ]) * 3
10391090 totalFrames += len (modelHandle .boneRotationWFrames [i ]) * 4
1091+ totalFrames += len (modelHandle .boneScaleXFrames [i ]) * 3
10401092 if camData is not None :
10411093 camData .Update (None ,self .interKey ) #finish lingering updates
10421094 totalFrames += len (camData .locationXFrames ) * 3
@@ -1068,17 +1120,23 @@ def updateImportProgress(newFrames):
10681120 afx_utils .AddKeysList_Visible (curves [0 ].keyframe_points , modelHandle .visibilityFrames )
10691121 afx_utils .AddKeysList_Location (self .keyframeInterpolation , curves [1 ].keyframe_points , curves [2 ].keyframe_points , curves [3 ].keyframe_points , modelHandle .locationXFrames , modelHandle .locationYFrames , modelHandle .locationZFrames )
10701122 afx_utils .AddKeysList_Rotation (self .keyframeInterpolation , curves [4 ].keyframe_points , curves [5 ].keyframe_points , curves [6 ].keyframe_points , curves [7 ].keyframe_points , modelHandle .rotationWFrames , modelHandle .rotationXFrames , modelHandle .rotationYFrames , modelHandle .rotationZFrames )
1071- updateImportProgress (len (modelHandle .visibilityFrames ) + len (modelHandle .locationXFrames ) * 3 + len (modelHandle .rotationWFrames ) * 4 )
1123+ afx_utils .AddKeysList_Location (self .keyframeInterpolation , curves [8 ].keyframe_points , curves [9 ].keyframe_points , curves [10 ].keyframe_points , modelHandle .scaleXFrames , modelHandle .scaleYFrames , modelHandle .scaleZFrames )
1124+ updateImportProgress (len (modelHandle .visibilityFrames ) + len (modelHandle .locationXFrames ) * 3 + len (modelHandle .rotationWFrames ) * 4 + len (modelHandle .scaleXFrames ) * 3 )
10721125 currentFrames = 0
10731126 for i in modelHandle .boneLocationXFrames :
1074- afx_utils .AddKeysList_Location (self .keyframeInterpolation , curves [7 * i + 8 ].keyframe_points , curves [7 * i + 9 ].keyframe_points , curves [7 * i + 10 ].keyframe_points , modelHandle .boneLocationXFrames [i ], modelHandle .boneLocationYFrames [i ], modelHandle .boneLocationZFrames [i ])
1127+ afx_utils .AddKeysList_Location (self .keyframeInterpolation , curves [10 * i + 11 ].keyframe_points , curves [10 * i + 12 ].keyframe_points , curves [10 * i + 13 ].keyframe_points , modelHandle .boneLocationXFrames [i ], modelHandle .boneLocationYFrames [i ], modelHandle .boneLocationZFrames [i ])
10751128 currentFrames += len (modelHandle .boneLocationXFrames [i ]) * 3
10761129 updateImportProgress (currentFrames )
10771130 currentFrames = 0
10781131 for i in modelHandle .boneRotationWFrames :
1079- afx_utils .AddKeysList_Rotation (self .keyframeInterpolation , curves [7 * i + 11 ].keyframe_points , curves [7 * i + 12 ].keyframe_points , curves [7 * i + 13 ].keyframe_points , curves [7 * i + 14 ].keyframe_points , modelHandle .boneRotationWFrames [i ], modelHandle .boneRotationXFrames [i ], modelHandle .boneRotationYFrames [i ], modelHandle .boneRotationZFrames [i ])
1132+ afx_utils .AddKeysList_Rotation (self .keyframeInterpolation , curves [10 * i + 14 ].keyframe_points , curves [10 * i + 15 ].keyframe_points , curves [10 * i + 16 ].keyframe_points , curves [10 * i + 17 ].keyframe_points , modelHandle .boneRotationWFrames [i ], modelHandle .boneRotationXFrames [i ], modelHandle .boneRotationYFrames [i ], modelHandle .boneRotationZFrames [i ])
10801133 currentFrames += len (modelHandle .boneRotationWFrames [i ]) * 4
10811134 updateImportProgress (currentFrames )
1135+ currentFrames = 0
1136+ for i in modelHandle .boneScaleXFrames :
1137+ afx_utils .AddKeysList_Location (self .keyframeInterpolation , curves [10 * i + 18 ].keyframe_points , curves [10 * i + 19 ].keyframe_points , curves [10 * i + 20 ].keyframe_points , modelHandle .boneScaleXFrames [i ], modelHandle .boneScaleYFrames [i ], modelHandle .boneScaleZFrames [i ])
1138+ currentFrames += len (modelHandle .boneScaleXFrames [i ]) * 3
1139+ updateImportProgress (currentFrames )
10821140 for curve in curves :
10831141 curve .update ()
10841142 if camData is not None :
0 commit comments