From 355d7ebdf3285dda5b33c226d079926f571b5a78 Mon Sep 17 00:00:00 2001 From: "Asad M. Zaman" Date: Wed, 2 May 2007 22:50:25 +0000 Subject: [PATCH] added a new interface called getAnimFilename in Actor and made the getAnimControl more robust --- direct/src/actor/Actor.py | 81 +++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 17 deletions(-) diff --git a/direct/src/actor/Actor.py b/direct/src/actor/Actor.py index fe44e1f6fb..dd7730a8e2 100644 --- a/direct/src/actor/Actor.py +++ b/direct/src/actor/Actor.py @@ -626,11 +626,14 @@ class Actor(DirectObject, NodePath): Get the named node under the LOD to which we parent all LOD specific geometry to. Returns 'None' if not found """ - lod = self.__LODNode.find("**/" + str(lodName)) - if lod.isEmpty(): - return None + if self.__LODNode: + lod = self.__LODNode.find("**/" + str(lodName)) + if lod.isEmpty(): + return None + else: + return lod else: - return lod + return None def hasLOD(self): """ @@ -1377,12 +1380,40 @@ class Actor(DirectObject, NodePath): for control in self.getAnimControls(animName, partName, lodName): control.getPart().setControlEffect(control, effect) - def getAnimControl(self, animName, partName="modelRoot", lodName="lodRoot"): - """getAnimControl(self, string, string, string="lodRoot") - Search the animControl dictionary indicated by lodName for - a given anim and part. Return the animControl if present, - or None otherwise + def getAnimFilename(self, animName, partName='modelRoot'): """ + getAnimFilename(self, animName) + return the animFilename given the animName + """ + if self.switches: + lodName = str(self.switches.keys()[0]) + else: + lodName = 'lodRoot' + + try: + return self.__animControlDict[lodName][partName][animName].filename + except: + return None + + def getAnimControl(self, animName, partName=None, lodName=None): + """ + getAnimControl(self, string, string, string="lodRoot") + Search the animControl dictionary indicated by lodName for + a given anim and part. If none specified, try the first part and lod. + Return the animControl if present, or None otherwise + """ + if not partName: + if self.__subpartDict.keys(): + partName = self.__subpartDict.keys()[0] + else: + partName = 'modelRoot' + + if not lodName: + if self.switches: + lodName = str(self.switches.keys()[0]) + else: + lodName = 'lodRoot' + partDict = self.__animControlDict.get(lodName) # if this assertion fails, named lod was not present assert partDict != None @@ -1697,18 +1728,34 @@ class Actor(DirectObject, NodePath): to 'lodRoot' for non-LOD actors) and dict of corresponding anims in the form animName:animPath{} """ + if (lodName == 'all'): + lodNames = self.switches.keys() + lodNames.sort() + for i in range(0,len(lodNames)): + lodNames[i] = str(lodNames[i]) + else: + lodNames = [lodName] + assert Actor.notify.debug("in loadAnims: %s, part: %s, lod: %s" % - (anims, partName, lodName)) + (anims, partName, lodNames[0])) + firstLoad = True + for lName in lodNames: + try: + self.__animControlDict[lName][partName] + firstLoad = False + except: + self.__animControlDict.setdefault(lName, {}) + self.__animControlDict[lName].setdefault(partName, {}) for animName, filename in anims.items(): # make sure this lod is in anim control dict - self.__animControlDict.setdefault(lodName, {}) - self.__animControlDict[lodName].setdefault(partName, {}) - - # store the file path only; we will bind it (and produce - # an AnimControl) when it is played - self.__animControlDict[lodName][partName][animName] = Actor.AnimDef(filename) - + for lName in lodNames: + # store the file path only; we will bind it (and produce + # an AnimControl) when it is played + if not firstLoad: + self.__animControlDict[lName][partName][animName].filename = filename + else: + self.__animControlDict[lName][partName][animName] = Actor.AnimDef(filename) def unloadAnims(self, anims, partName="modelRoot", lodName="lodRoot"): """unloadAnims(self, string:string{}, string='modelRoot',