Added feature to support model based anim list

This commit is contained in:
Gyedo Jeon 2010-04-24 00:46:27 +00:00
parent e58d747f6a
commit 3849b1221f
3 changed files with 33 additions and 12 deletions

View File

@ -384,11 +384,17 @@ class ObjectMgrBase:
objRGBA = obj[OG.OBJ_RGBA] objRGBA = obj[OG.OBJ_RGBA]
# load new model # load new model
newobjModel = loader.loadModel(model, okMissing=True) if obj[OG.OBJ_DEF].actor:
if newobjModel is None: try:
print "Can't load model %s"%model newobj = Actor(model)
return except:
newobj = PythonNodePath(newobjModel) newobj = Actor(Filename.fromOsSpecific(model).getFullpath())
else:
newobjModel = loader.loadModel(model, okMissing=True)
if newobjModel is None:
print "Can't load model %s"%model
return
newobj = PythonNodePath(newobjModel)
newobj.setTag('OBJRoot','1') newobj.setTag('OBJRoot','1')
# reparent children # reparent children
@ -414,10 +420,14 @@ class ObjectMgrBase:
obj[OG.OBJ_MODEL] = model obj[OG.OBJ_MODEL] = model
self.npIndex[NodePath(newobj)] = obj[OG.OBJ_UID] self.npIndex[NodePath(newobj)] = obj[OG.OBJ_UID]
if fSelectObject:
base.direct.select(newobj, fUndo=0)
self.editor.fNeedToSave = True self.editor.fNeedToSave = True
# update anim if necessary
animList = obj[OG.OBJ_DEF].animDict.get(model)
if animList:
self.updateObjectAnim(animList[0], obj, fSelectObject=fSelectObject)
else:
if fSelectObject:
base.direct.select(newobj, fUndo=0)
def updateObjectAnim(self, anim, obj, fSelectObject=True): def updateObjectAnim(self, anim, obj, fSelectObject=True):
""" replace object's anim """ """ replace object's anim """

View File

@ -8,7 +8,7 @@ class ObjectGen:
class ObjectBase(ObjectGen): class ObjectBase(ObjectGen):
""" Base class for obj definitions """ """ Base class for obj definitions """
def __init__(self, name='', createFunction = None, model = None, models= [], anims = [], animNames = [], properties={}, def __init__(self, name='', createFunction = None, model = None, models= [], anims = [], animNames = [], animDict = {}, properties={},
movable = True, actor = False, named=False, orderedProperties=[], propertiesMask={}): movable = True, actor = False, named=False, orderedProperties=[], propertiesMask={}):
ObjectGen.__init__(self, name) ObjectGen.__init__(self, name)
self.createFunction = createFunction self.createFunction = createFunction
@ -16,6 +16,7 @@ class ObjectBase(ObjectGen):
self.models = models[:] self.models = models[:]
self.anims = anims[:] self.anims = anims[:]
self.animNames = animNames[:] self.animNames = animNames[:]
self.animDict = copy.deepcopy(animDict)
self.properties = copy.deepcopy(properties) self.properties = copy.deepcopy(properties)
self.movable = movable self.movable = movable
self.actor = actor self.actor = actor

View File

@ -323,8 +323,18 @@ class ObjectPropertyUI(ScrolledPanel):
self.editor.objectMgr.onLeaveObjectPropUI, self.editor.objectMgr.onLeaveObjectPropUI,
lambda p0=None, p1=obj: self.editor.objectMgr.updateObjectModelFromUI(p0, p1)) lambda p0=None, p1=obj: self.editor.objectMgr.updateObjectModelFromUI(p0, p1))
if len(objDef.anims) > 0: animList = objDef.animDict.get(obj[OG.OBJ_MODEL])
propUI = ObjectPropUICombo(self.lookPane, 'anim', obj[OG.OBJ_ANIM], objDef.anims) if len(objDef.anims) > 0 or animList:
if animList is None:
animist = objDef.anims
if '' not in animList:
animList.append('')
defaultAnim = obj[OG.OBJ_ANIM]
if defaultAnim is None:
defaultAnim = ''
propUI = ObjectPropUICombo(self.lookPane, 'anim', defaultAnim, animList)
sizer.Add(propUI) sizer.Add(propUI)
propUI.bindFunc(self.editor.objectMgr.onEnterObjectPropUI, propUI.bindFunc(self.editor.objectMgr.onEnterObjectPropUI,