Skip to content

Commit a156df0

Browse files
committed
backup, need to fix transform of root
1 parent 7f92050 commit a156df0

File tree

2 files changed

+77
-44
lines changed

2 files changed

+77
-44
lines changed

advancedfx_import_gameRecord.py

Lines changed: 73 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Copyright (c) advancedfx.org
22
#
33
# Last changes:
4-
# 2017-06-26 by dominik.matrixstorm.com
4+
# 2017-08-02 dominik.matrixstorm.com
55
#
66
# First changes:
7-
# 2016-07-13 by dominik.matrixstorm.com
7+
# 2016-07-13 dominik.matrixstorm.com
88

99

1010
# DEG2RAD = 0.0174532925199432957692369076849
@@ -270,6 +270,19 @@ def ReadAgrVersion(file):
270270

271271
return ReadInt(file)
272272

273+
class ModelHandle:
274+
def __init__(self,objNr,handle,modelName):
275+
self.objNr = objNr
276+
self.handle = handle
277+
self.modelName = modelName
278+
self.modelData = False
279+
280+
def __hash__(self):
281+
return hash((self.handle, self.modelName))
282+
283+
def __eq__(self, other):
284+
return (self.handle, self.modelName) == (other.handle, other.modelName)
285+
273286
class AgrDictionary:
274287
dict = {}
275288
peeked = None
@@ -316,24 +329,24 @@ def ReadFile(fileName):
316329
SetError('Invalid file format.')
317330
return False
318331

319-
if 1 != version:
332+
if 2 != version:
320333
SetError('Version '+str(version)+' is not supported!')
321334
return False
322335

323336
shot = sfm.GetCurrentShot()
324337

325338
firstTime = None
326339

327-
knownAnimSetNames = set()
328-
329340
dict = AgrDictionary()
341+
handleToLastModelHandle = {}
330342
channelCache = ChannelCache()
331-
knownHandleToDagName = {}
332343

333344
stupidCount = 0
334345

335346
afxCam = None
336347

348+
objNr = 0
349+
337350
while True:
338351
stupidCount = stupidCount +1
339352

@@ -350,24 +363,37 @@ def ReadFile(fileName):
350363
if node0 is None:
351364
break
352365

366+
elif 'afxHidden' == node0:
367+
handle = ReadInt(file)
368+
time = ReadFloat(file)
369+
370+
modelHandle = handleToLastModelHandle.get(handle, None)
371+
if modelHandle is not None:
372+
dagAnimSet = modelHandle.modelData
373+
if dagAnimSet:
374+
# Make ent invisible:
375+
channelsClip = sfmUtils.GetChannelsClipForAnimSet(dagAnimSet, shot)
376+
time = time -firstTime
377+
time = vs.DmeTime_t(time) -channelsClip.timeFrame.start.GetValue()
378+
MakeKeyFrameValue(channelCache, dagAnimSet, 'visible_channel', time, False)
379+
353380
elif 'deleted' == node0:
354381
handle = ReadInt(file)
355382
time = ReadFloat(file)
356383

357-
dagName = knownHandleToDagName.get(handle, None)
358-
if dagName is not None:
359-
# Make removed ent invisible:
360-
sfm.UsingAnimationSet(dagName)
361-
dagAnimSet = sfm.GetCurrentAnimationSet()
362-
channelsClip = sfmUtils.GetChannelsClipForAnimSet(dagAnimSet, shot)
363-
time = time -firstTime
364-
time = vs.DmeTime_t(time) -channelsClip.timeFrame.start.GetValue()
365-
MakeKeyFrameValue(channelCache, dagAnimSet, 'visible_channel', time, False)
384+
modelHandle = handleToLastModelHandle.pop(handle, None)
385+
if modelHandle is not None:
386+
dagAnimSet = modelHandle.modelData
387+
if dagAnimSet:
388+
# Make removed ent invisible:
389+
channelsClip = sfmUtils.GetChannelsClipForAnimSet(dagAnimSet, shot)
390+
time = time -firstTime
391+
time = vs.DmeTime_t(time) -channelsClip.timeFrame.start.GetValue()
392+
MakeKeyFrameValue(channelCache, dagAnimSet, 'visible_channel', time, False)
366393

367394
elif 'entity_state' == node0:
368395
visible = None
369396
time = None
370-
dagName = None
371397
dagAnimSet = None
372398
handle = ReadInt(file)
373399
if dict.Peekaboo(file,'baseentity'):
@@ -378,43 +404,46 @@ def ReadFile(fileName):
378404

379405
modelName = dict.Read(file)
380406

381-
dagName = knownHandleToDagName.get(handle, None)
382-
if dagName is not None:
383-
# Switched model, make old model invisible:
384-
sfm.UsingAnimationSet(dagName)
385-
dagAnimSet = sfm.GetCurrentAnimationSet()
386-
channelsClip = sfmUtils.GetChannelsClipForAnimSet(dagAnimSet, shot)
387-
rtime = time -channelsClip.timeFrame.start.GetValue()
388-
MakeKeyFrameValue(channelCache, dagAnimSet, 'visible_channel', rtime, False)
389-
390-
dagName = "afx." +str(handle) + " " + modelName
407+
modelHandle = handleToLastModelHandle.get(handle, None)
391408

392-
knownHandleToDagName[handle] = dagName
409+
if (modelHandle is not None) and (modelHandle.modelName != modelName):
410+
# Switched model, make old model invisible:
411+
dagAnimSet = modelHandle.modelData
412+
if dagAnimSet:
413+
channelsClip = sfmUtils.GetChannelsClipForAnimSet(dagAnimSet, shot)
414+
rtime = time -channelsClip.timeFrame.start.GetValue()
415+
MakeKeyFrameValue(channelCache, dagAnimSet, 'visible_channel', rtime, False)
416+
417+
modelHandle = None
418+
419+
if modelHandle is None:
420+
objNr = objNr + 1
421+
modelHandle = ModelHandle(objNr, handle, modelName)
422+
handleToLastModelHandle[handle] = modelHandle
393423

394-
sfm.ClearSelection()
395-
sfm.Select(dagName+':rootTransform')
396-
dagRootTransform = sfm.FirstSelectedDag()
397-
if(None == dagRootTransform):
424+
dagAnimSet = modelHandle.modelData
425+
if dagAnimSet is False:
426+
# We have not tried to import the model for this (new) handle yet, so try to import it:
427+
dagName = modelName.rsplit('/',1)
428+
dagName = dagName[len(dagName) -1]
429+
dagName = (dagName[:60] + '..') if len(dagName) > 60 else dagName
430+
dagName = "afx." +str(modelHandle.objNr)+"."+str(modelHandle.handle)+ " " + dagName
431+
398432
dagAnimSet = sfmUtils.CreateModelAnimationSet(dagName,modelName)
433+
399434
if(hasattr(dagAnimSet,'gameModel')):
400435
dagAnimSet.gameModel.evaluateProceduralBones = False # This will look awkwardly and crash SFM otherwise
401-
sfm.ClearSelection()
402-
sfm.Select(dagName+":rootTransform")
403-
dagRootTransform = sfm.FirstSelectedDag()
404-
else:
405-
sfm.UsingAnimationSet(dagName)
406-
dagAnimSet = sfm.GetCurrentAnimationSet()
407-
408-
if dagName not in knownAnimSetNames:
436+
409437
print "Initalizing animSet " + dagName
410438
InitalizeAnimSet(dagAnimSet)
411-
knownAnimSetNames.add(dagName)
439+
440+
modelHandle.modelData = dagAnimSet
412441

413442
channelsClip = sfmUtils.GetChannelsClipForAnimSet(dagAnimSet, shot)
414443

415444
time = time -channelsClip.timeFrame.start.GetValue()
416445

417-
visible = ReadBool(file)
446+
visible = True #visible = ReadBool(file)
418447

419448
MakeKeyFrameValue(channelCache, dagAnimSet, 'visible_channel', time, visible)
420449

@@ -426,9 +455,9 @@ def ReadFile(fileName):
426455
MakeKeyFrameTransform(channelCache, dagAnimSet, "rootTransform", time, renderOrigin, QuaternionFromQAngle(renderAngles), True)
427456

428457
if dict.Peekaboo(file,'baseanimating'):
429-
skin = ReadInt(file)
430-
body = ReadInt(file)
431-
sequence = ReadInt(file)
458+
#skin = ReadInt(file)
459+
#body = ReadInt(file)
460+
#sequence = ReadInt(file)
432461
hasBoneList = ReadBool(file)
433462
if hasBoneList:
434463
dagModel = None

readme.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ a custom (skin) model (modelName is '?' then).
7474

7575
Changelog:
7676

77+
1.4.0 (2017-08-02T18:32Z):
78+
- advancedfx_import_gameRecord:
79+
- Updated to agr version 2 (also bug fixes)
80+
7781
1.3.0 (2017-06-26T05:07Z):
7882
- advancedfx_import_gameRecord:
7983
- Updated to agr version 1

0 commit comments

Comments
 (0)