actor: minor style fixes

This commit is contained in:
rdb 2020-01-21 15:00:13 +01:00
parent 4819e2ce3a
commit 2960b67c7a

View File

@ -212,7 +212,7 @@ class Actor(DirectObject, NodePath):
self.__LODCenter = Point3(0, 0, 0)
self.switches = None
if (other == None):
if other is None:
# act like a normal constructor
# create base hierarchy
@ -352,7 +352,7 @@ class Actor(DirectObject, NodePath):
self.gotName = other.gotName
# copy the scene graph elements of other
if (overwrite):
if overwrite:
otherCopy = other.copyTo(NodePath())
otherCopy.detachNode()
# assign these elements to ourselve (overwrite)
@ -372,7 +372,7 @@ class Actor(DirectObject, NodePath):
self.switches = other.switches
self.__LODNode = self.find('**/+LODNode')
self.__hasLOD = 0
if (not self.__LODNode.isEmpty()):
if not self.__LODNode.isEmpty():
self.__hasLOD = 1
@ -418,7 +418,7 @@ class Actor(DirectObject, NodePath):
subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName))
partDef = partBundleDict.get(subpartDef.truePartName)
if partDef == None:
if partDef is None:
Actor.notify.error("no part named: %s" % (partName))
self.__doListJoints(0, partDef.getBundle(),
@ -491,7 +491,7 @@ class Actor(DirectObject, NodePath):
for animName, file, animControl in animInfo:
print(' Anim: %s' % animName)
print(' File: %s' % file)
if animControl == None:
if animControl is None:
print(' (not loaded)')
else:
print(' NumFrames: %d PlayRate: %0.2f' %
@ -557,14 +557,14 @@ class Actor(DirectObject, NodePath):
bundles = []
for lodName, partBundleDict in self.__partBundleDict.items():
if partName == None:
if partName is None:
for partDef in partBundleDict.values():
bundles.append(partDef.getBundle())
else:
subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName))
partDef = partBundleDict.get(subpartDef.truePartName)
if partDef != None:
if partDef is not None:
bundles.append(partDef.getBundle())
else:
Actor.notify.warning("Couldn't find part: %s" % (partName))
@ -635,7 +635,7 @@ class Actor(DirectObject, NodePath):
Set the node that switches actor geometry in and out.
If one is not supplied as an argument, make one
"""
if (node == None):
if node is None:
node = LODNode.makeDefaultLod("lod")
if self.__LODNode:
@ -685,7 +685,7 @@ class Actor(DirectObject, NodePath):
self.switches[lodName] = [inDist, outDist]
# add the switch distance info
self.__LODNode.node().addSwitch(inDist, outDist)
if center != None:
if center is not None:
self.setCenter(center)
def setLOD(self, lodName, inDist=0, outDist=0):
@ -724,7 +724,7 @@ class Actor(DirectObject, NodePath):
return self.__hasLOD
def setCenter(self, center):
if center == None:
if center is None:
center = Point3(0, 0, 0)
self.__LODCenter = center
if self.__LODNode:
@ -782,7 +782,7 @@ class Actor(DirectObject, NodePath):
Returns True if any joint has changed as a result of this,
False otherwise. """
if lodName == None:
if lodName is None:
lodNames = self.getLODNames()
else:
lodNames = [lodName]
@ -790,7 +790,7 @@ class Actor(DirectObject, NodePath):
anyChanged = False
if lod < len(lodNames):
lodName = lodNames[lod]
if partName == None:
if partName is None:
partBundleDict = self.__partBundleDict[lodName]
partNames = list(partBundleDict.keys())
else:
@ -906,11 +906,11 @@ class Actor(DirectObject, NodePath):
return
lodName, animControlDict = next(iter(self.__animControlDict.items()))
if partName == None:
if partName is None:
partName, animDict = next(iter(animControlDict.items()))
else:
animDict = animControlDict.get(partName)
if animDict == None:
if animDict is None:
# part was not present
Actor.notify.warning("couldn't find part: %s" % (partName))
return None
@ -931,11 +931,11 @@ class Actor(DirectObject, NodePath):
in dictionary. NOTE: only returns info for an arbitrary LOD
"""
lodName, animControlDict = next(iter(self.__animControlDict.items()))
if partName == None:
if partName is None:
partName, animDict = next(iter(animControlDict.items()))
else:
animDict = animControlDict.get(partName)
if animDict == None:
if animDict is None:
# part was not present
Actor.notify.warning("couldn't find part: %s" % (partName))
return None
@ -969,7 +969,7 @@ class Actor(DirectObject, NodePath):
return None
subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName))
partDef = partBundleDict.get(subpartDef.truePartName)
if partDef != None:
if partDef is not None:
return partDef.partBundleNP
return None
@ -984,7 +984,7 @@ class Actor(DirectObject, NodePath):
return None
subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName))
partDef = partBundleDict.get(subpartDef.truePartName)
if partDef != None:
if partDef is not None:
return partDef.getBundle()
return None
@ -1001,9 +1001,9 @@ class Actor(DirectObject, NodePath):
return
# remove the part
if (partName in partBundleDict):
if partName in partBundleDict:
partBundleDict[partName].partBundleNP.removeNode()
del(partBundleDict[partName])
del partBundleDict[partName]
# find the corresponding anim control dict
if self.mergeLODBundles:
@ -1014,8 +1014,8 @@ class Actor(DirectObject, NodePath):
return
# remove the animations
if (partName in partDict):
del(partDict[partName])
if partName in partDict:
del partDict[partName]
def hidePart(self, partName, lodName="lodRoot"):
"""
@ -1093,7 +1093,7 @@ class Actor(DirectObject, NodePath):
if node is None:
node = partDef.partBundleNP.attachNewNode(jointName)
if (joint):
if joint:
if localTransform:
joint.addLocalTransform(node.node())
else:
@ -1125,7 +1125,7 @@ class Actor(DirectObject, NodePath):
# Get a handle to the joint.
joint = bundle.findChild(jointName)
if (joint):
if joint:
joint.clearNetTransforms()
joint.clearLocalTransforms()
else:
@ -1139,11 +1139,11 @@ class Actor(DirectObject, NodePath):
joints=[]
pattern = GlobPattern(jointName)
if lodName == None and self.mergeLODBundles:
if lodName is None and self.mergeLODBundles:
# Get the common bundle.
partBundleDicts = [self.__commonBundleHandles]
elif lodName == None:
elif lodName is None:
# Get all LOD's.
partBundleDicts = self.__partBundleDict.values()
else:
@ -1232,7 +1232,7 @@ class Actor(DirectObject, NodePath):
return None
joint = bundle.findChild(jointName)
if joint == None:
if joint is None:
Actor.notify.warning("no joint named %s!" % (jointName))
return None
return joint.getDefaultValue()
@ -1252,7 +1252,7 @@ class Actor(DirectObject, NodePath):
return None
joint = bundle.findChild(jointName)
if joint == None:
if joint is None:
Actor.notify.warning("no joint named %s!" % (jointName))
return None
return joint.getTransformState()
@ -1277,7 +1277,7 @@ class Actor(DirectObject, NodePath):
anyGood = False
for bundleDict in self.__partBundleDict.values():
bundle = bundleDict[trueName].getBundle()
if node == None:
if node is None:
node = self.attachNewNode(ModelNode(jointName))
joint = bundle.findChild(jointName)
if joint and isinstance(joint, MovingPartMatrix):
@ -1299,7 +1299,7 @@ class Actor(DirectObject, NodePath):
optimal than controlJoint() for cases in which the transform
is not intended to be animated during the lifetime of the
Actor. """
if transform == None:
if transform is None:
transform = TransformState.makePosHprScale(pos, hpr, scale)
subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName))
@ -1330,7 +1330,7 @@ class Actor(DirectObject, NodePath):
partDef = partBundleDict.get(subpartDef.truePartName)
if partDef:
joint = partDef.partBundleNP.find("**/" + jointName)
if (joint.isEmpty()):
if joint.isEmpty():
Actor.notify.warning("%s not found!" % (jointName))
else:
return path.instanceTo(joint)
@ -1350,7 +1350,7 @@ class Actor(DirectObject, NodePath):
anotherPartDef = partBundleDict.get(anotherPartName)
if anotherPartDef:
joint = anotherPartDef.partBundleNP.find("**/" + jointName)
if (joint.isEmpty()):
if joint.isEmpty():
Actor.notify.warning("%s not found!" % (jointName))
else:
partDef.partBundleNP.reparentTo(joint)
@ -1395,10 +1395,10 @@ class Actor(DirectObject, NodePath):
root under the given lod.
"""
# check to see if we are working within an lod
if lodName != None:
if lodName is not None:
# find the named lod node
lodRoot = self.__LODNode.find(str(lodName))
if root == None:
if root is None:
# no need to look further
root = lodRoot
else:
@ -1406,7 +1406,7 @@ class Actor(DirectObject, NodePath):
root = lodRoot.find("**/" + root)
else:
# start search from self if no root and no lod given
if root == None:
if root is None:
root = self
frontParts = root.findAllMatches("**/" + frontPartName)
@ -1426,7 +1426,7 @@ class Actor(DirectObject, NodePath):
# Find the back part.
backPart = root.find("**/" + backPartName)
if (backPart.isEmpty()):
if backPart.isEmpty():
Actor.notify.warning("no part named %s!" % (backPartName))
return
@ -1442,7 +1442,7 @@ class Actor(DirectObject, NodePath):
def fixBounds(self, partName = None):
if(partName == None):
if partName is None:
#iterate through everything
for lodData in self.__partBundleDict.values():
for partData in lodData.values():
@ -1473,7 +1473,7 @@ class Actor(DirectObject, NodePath):
in this actor
"""
# if no part name specified fix all parts
if (part==None):
if part is None:
part = self
# update all characters first
@ -1531,12 +1531,12 @@ class Actor(DirectObject, NodePath):
Play the given animation on the given part of the actor.
If no part is specified, try to play on all parts. NOTE:
plays over ALL LODs"""
if fromFrame == None:
if fromFrame is None:
for control in self.getAnimControls(animName, partName):
control.play()
else:
for control in self.getAnimControls(animName, partName):
if toFrame == None:
if toFrame is None:
control.play(fromFrame, control.getNumFrames() - 1)
else:
control.play(fromFrame, toFrame)
@ -1550,12 +1550,12 @@ class Actor(DirectObject, NodePath):
all LOD's
"""
if fromFrame == None:
if fromFrame is None:
for control in self.getAnimControls(animName, partName):
control.loop(restart)
else:
for control in self.getAnimControls(animName, partName):
if toFrame == None:
if toFrame is None:
control.loop(restart, fromFrame, control.getNumFrames() - 1)
else:
control.loop(restart, fromFrame, toFrame)
@ -1567,11 +1567,11 @@ class Actor(DirectObject, NodePath):
restarting at zero frame if requested. If no part name
is given then try to loop on all parts. NOTE: loops on
all LOD's"""
if fromFrame == None:
if fromFrame is None:
fromFrame = 0
for control in self.getAnimControls(animName, partName):
if toFrame == None:
if toFrame is None:
control.pingpong(restart, fromFrame, control.getNumFrames() - 1)
else:
control.pingpong(restart, fromFrame, toFrame)
@ -1623,11 +1623,11 @@ class Actor(DirectObject, NodePath):
Config.prc variable.
"""
for bundle in self.getPartBundles(partName = partName):
if blendType != None:
if blendType is not None:
bundle.setBlendType(blendType)
if animBlend != None:
if animBlend is not None:
bundle.setAnimBlendFlag(animBlend)
if frameBlend != None:
if frameBlend is not None:
bundle.setFrameBlendFlag(frameBlend)
def enableBlend(self, blendType = PartBundle.BTNormalizedLinear, partName = None):
@ -1706,15 +1706,15 @@ class Actor(DirectObject, NodePath):
partDict = self.__animControlDict.get(lodName)
# if this assertion fails, named lod was not present
assert partDict != None
assert partDict is not None
animDict = partDict.get(partName)
if animDict == None:
if animDict is None:
# part was not present
Actor.notify.warning("couldn't find part: %s" % (partName))
else:
anim = animDict.get(animName)
if anim == None:
if anim is None:
# anim was not present
assert Actor.notify.debug("couldn't find anim: %s" % (animName))
pass
@ -1750,7 +1750,7 @@ class Actor(DirectObject, NodePath):
If lodName is None or omitted, all LOD's are returned.
"""
if partName == None and self.__subpartsComplete:
if partName is None and self.__subpartsComplete:
# If we have the __subpartsComplete flag, and no partName
# is specified, it really means to play the animation on
# all subparts, not on the overall Actor.
@ -1759,12 +1759,12 @@ class Actor(DirectObject, NodePath):
controls = []
# build list of lodNames and corresponding animControlDicts
# requested.
if lodName == None or self.mergeLODBundles:
if lodName is None or self.mergeLODBundles:
# Get all LOD's
animControlDictItems = self.__animControlDict.items()
else:
partDict = self.__animControlDict.get(lodName)
if partDict == None:
if partDict is None:
Actor.notify.warning("couldn't find lod: %s" % (lodName))
animControlDictItems = []
else:
@ -1773,7 +1773,7 @@ class Actor(DirectObject, NodePath):
for lodName, partDict in animControlDictItems:
# Now, build the list of partNames and the corresponding
# animDicts.
if partName == None:
if partName is None:
# Get all main parts, but not sub-parts.
animDictItems = []
for thisPart, animDict in partDict.items():
@ -1791,14 +1791,14 @@ class Actor(DirectObject, NodePath):
for pName in partNameList:
animDict = partDict.get(pName)
if animDict == None:
if animDict is None:
# Maybe it's a subpart that hasn't been bound yet.
subpartDef = self.__subpartDict.get(pName)
if subpartDef:
animDict = {}
partDict[pName] = animDict
if animDict == None:
if animDict is None:
# part was not present
Actor.notify.warning("couldn't find part: %s" % (pName))
else:
@ -1824,7 +1824,7 @@ class Actor(DirectObject, NodePath):
names = animDict.keys()
for animName in names:
anim = animDict.get(animName)
if anim == None and partName != None:
if anim is None and partName is not None:
for pName in partNameList:
# Maybe it's a subpart that hasn't been bound yet.
subpartDef = self.__subpartDict.get(pName)
@ -1835,14 +1835,14 @@ class Actor(DirectObject, NodePath):
anim = anim.makeCopy()
animDict[animName] = anim
if anim == None:
if anim is None:
# anim was not present
assert Actor.notify.debug("couldn't find anim: %s" % (animName))
pass
else:
# bind the animation first if we need to
animControl = anim.animControl
if animControl == None:
if animControl is None:
animControl = self.__bindAnimToPart(
animName, thisPart, lodName,
allowAsyncBind = allowAsyncBind)
@ -1869,7 +1869,7 @@ class Actor(DirectObject, NodePath):
if isinstance(modelPath, NodePath):
# If we got a NodePath instead of a string, use *that* as
# the model directly.
if (copy):
if copy:
model = modelPath.copyTo(NodePath())
else:
model = modelPath
@ -1898,15 +1898,15 @@ class Actor(DirectObject, NodePath):
if model is not None:
model = NodePath(model)
if (model == None):
if model is None:
raise IOError("Could not load Actor model %s" % (modelPath))
if (model.node().isOfType(Character.getClassType())):
if model.node().isOfType(Character.getClassType()):
bundleNP = model
else:
bundleNP = model.find("**/+Character")
if (bundleNP.isEmpty()):
if bundleNP.isEmpty():
Actor.notify.warning("%s is not a character!" % (modelPath))
model.reparentTo(self.__geomNode)
else:
@ -1923,7 +1923,7 @@ class Actor(DirectObject, NodePath):
# Now extract out the Character and integrate it with
# the Actor.
if (lodName!="lodRoot"):
if lodName != "lodRoot":
# parent to appropriate node under LOD switch
bundleNP.reparentTo(self.__LODNode.find(str(lodName)))
else:
@ -1965,7 +1965,7 @@ class Actor(DirectObject, NodePath):
self.gotName = 1
bundleDict = self.__partBundleDict.get(lodName, None)
if bundleDict == None:
if bundleDict is None:
# make a dictionary to store these parts in
bundleDict = {}
self.__partBundleDict[lodName] = bundleDict
@ -2254,7 +2254,7 @@ class Actor(DirectObject, NodePath):
for lodName in lodNames:
for partName in partNames:
for animDef in self.__animControlDict[lodName][partName].values():
if animDef.animControl != None:
if animDef.animControl is not None:
# Try to clear any control effects before we let
# our handle on them go. This is especially
# important if the anim control was blending
@ -2266,7 +2266,7 @@ class Actor(DirectObject, NodePath):
for partName in partNames:
for anim in anims:
animDef = self.__animControlDict[lodName][partName].get(anim)
if animDef and animDef.animControl != None:
if animDef and animDef.animControl is not None:
# Try to clear any control effects before we let
# our handle on them go. This is especially
# important if the anim control was blending
@ -2329,19 +2329,19 @@ class Actor(DirectObject, NodePath):
partDict = self.__animControlDict[lodName]
animDict = partDict.get(partName)
if animDict == None:
if animDict is None:
# It must be a subpart that hasn't been bound yet.
animDict = {}
partDict[partName] = animDict
anim = animDict.get(animName)
if anim == None:
if anim is None:
# It must be a subpart that hasn't been bound yet.
anim = partDict[subpartDef.truePartName].get(animName)
anim = anim.makeCopy()
animDict[animName] = anim
if anim == None:
if anim is None:
Actor.notify.error("actor has no animation %s", animName)
# only bind if not already bound!
@ -2396,7 +2396,7 @@ class Actor(DirectObject, NodePath):
# find the part in our tree
bundleNP = partLod.find("**/%s%s"%(Actor.partPrefix,partName))
if (bundleNP != None):
if bundleNP is not None:
# store the part bundle
self.__prepareBundle(bundleNP, partDef.partModel,
partName, lodName)
@ -2468,7 +2468,7 @@ class Actor(DirectObject, NodePath):
else:
lodNames = [lodName]
if partName == None and self.__subpartsComplete:
if partName is None and self.__subpartsComplete:
partNames = self.__subpartDict.keys()
else:
partNames = [partName]