tweaks to actor

This commit is contained in:
Zachary Pavlov 2007-06-13 21:11:19 +00:00
parent 9bec17d962
commit 0109caeeed

View File

@ -38,7 +38,7 @@ class Actor(DirectObject, NodePath):
self.partBundleNP = partBundleNP self.partBundleNP = partBundleNP
self.partBundle = partBundle self.partBundle = partBundle
self.partModel = partModel self.partModel = partModel
def __repr__(self): def __repr__(self):
return 'Actor.PartDef(%s, %s)' % (repr(self.partBundleNP), repr(self.partModel)) return 'Actor.PartDef(%s, %s)' % (repr(self.partBundleNP), repr(self.partModel))
@ -301,7 +301,7 @@ class Actor(DirectObject, NodePath):
def copyActor(self, other, overwrite=False): def copyActor(self, other, overwrite=False):
# act like a copy constructor # act like a copy constructor
self.gotName = other.gotName self.gotName = other.gotName
# copy the scene graph elements of other # copy the scene graph elements of other
if (overwrite): if (overwrite):
otherCopy = other.copyTo(NodePath()) otherCopy = other.copyTo(NodePath())
@ -325,7 +325,7 @@ class Actor(DirectObject, NodePath):
self.__copyPartBundles(other) self.__copyPartBundles(other)
self.__copySubpartDict(other) self.__copySubpartDict(other)
self.__subpartsComplete = other.__subpartsComplete self.__subpartsComplete = other.__subpartsComplete
# copy the anim dictionary from other # copy the anim dictionary from other
self.__copyAnimControls(other) self.__copyAnimControls(other)
@ -446,8 +446,9 @@ class Actor(DirectObject, NodePath):
self.stop(None) self.stop(None)
self.__frozenJoints = {} self.__frozenJoints = {}
self.flush() self.flush()
self.__geomNode.removeNode() if(self.__geomNode):
self.__geomNode = None self.__geomNode.removeNode()
self.__geomNode = None
if not self.isEmpty(): if not self.isEmpty():
self.removeNode() self.removeNode()
@ -474,7 +475,8 @@ class Actor(DirectObject, NodePath):
self.__LODNode = None self.__LODNode = None
# remove all its children # remove all its children
self.__geomNode.removeChildren() if(self.__geomNode):
self.__geomNode.removeChildren()
self.__hasLOD = 0 self.__hasLOD = 0
@ -1002,6 +1004,17 @@ class Actor(DirectObject, NodePath):
else: else:
Actor.notify.warning("no joint named %s!" % (jointName)) Actor.notify.warning("no joint named %s!" % (jointName))
def getJoints(self, jointName):
joints=[]
for lod in self.__partBundleDict.values():
for part in lod.values():
partBundle=part.partBundle
joint=partBundle.findChild(jointName)
if(joint):
joints.append(joint)
return joints
def getJointTransform(self,partName, jointName, lodName='lodRoot'): def getJointTransform(self,partName, jointName, lodName='lodRoot'):
partBundleDict=self.__partBundleDict.get(lodName) partBundleDict=self.__partBundleDict.get(lodName)
if not partBundleDict: if not partBundleDict:
@ -1076,20 +1089,9 @@ class Actor(DirectObject, NodePath):
#trueName = self.__subpartDict[partName].truePartName #trueName = self.__subpartDict[partName].truePartName
subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName)) subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName))
trueName = subpartDef.truePartName trueName = subpartDef.truePartName
for bundleDict in self.__partBundleDict.values(): for bundleDict in self.__partBundleDict.values():
bundleDict[trueName].partBundle.findChild(jointName).freezeJoint(transform) bundleDict[trueName].partBundle.findChild(jointName).freezeJoint(transform)
# self.__frozenJoints[bundle.this][jointName] = transform
#This is an alternate method to control joints, which can be copied
#This function is optimal in a non control jointed actor
def freezeJointMat(self, partName, jointName, mat):
subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName))
trueName = subpartDef.truePartName
for bundleDict in self.__partBundleDict.values():
bundleDict[trueName].partBundle.findChild(jointName).freezeJoint(Mat4(mat))
def instance(self, path, partName, jointName, lodName="lodRoot"): def instance(self, path, partName, jointName, lodName="lodRoot"):
"""instance(self, NodePath, string, string, key="lodRoot") """instance(self, NodePath, string, string, key="lodRoot")
@ -1301,6 +1303,7 @@ class Actor(DirectObject, NodePath):
is given then try to loop on all parts. NOTE: loops on is given then try to loop on all parts. NOTE: loops on
all LOD's all LOD's
""" """
if fromFrame == None: if fromFrame == None:
for control in self.getAnimControls(animName, partName): for control in self.getAnimControls(animName, partName):
control.loop(restart) control.loop(restart)
@ -1455,6 +1458,7 @@ class Actor(DirectObject, NodePath):
a given anim and part. If none specified, try the first part and lod. a given anim and part. If none specified, try the first part and lod.
Return the animControl if present, or None otherwise Return the animControl if present, or None otherwise
""" """
if not partName: if not partName:
partName = 'modelRoot' partName = 'modelRoot'
@ -1962,7 +1966,7 @@ class Actor(DirectObject, NodePath):
# Before we apply any control joints, we have to make a # Before we apply any control joints, we have to make a
# copy of the bundle hierarchy, so we don't modify other # copy of the bundle hierarchy, so we don't modify other
# Actors that share the same bundle. # Actors that share the same bundle.
animBundle = animBundle.copyBundle()
# Are there any controls requested for joints in this bundle? # Are there any controls requested for joints in this bundle?
@ -1970,6 +1974,8 @@ class Actor(DirectObject, NodePath):
assert Actor.notify.debug('actor bundle %s, %s'% (bundle,bundle.this)) assert Actor.notify.debug('actor bundle %s, %s'% (bundle,bundle.this))
controlDict = self.__controlJoints.get(bundle.this, None) controlDict = self.__controlJoints.get(bundle.this, None)
animBundle = animBundle.copyBundle()
if controlDict: if controlDict:
for jointName, node in controlDict.items(): for jointName, node in controlDict.items():
if node: if node: