def announceGenerate(self): DistributedAvatarAI.announceGenerate(self) if not self.eyeLensNP: lens = PerspectiveLens() lens.setMinFov(180.0 / (4. / 3.)) node = LensNode('toonEyes', lens) node.activateLens(0) self.eyeLensNP = self.attachNewNode(node) self.eyeLensNP.setZ(self.getHeight() - 0.5) self.eyeLensNP.setY(-1) self.setEyesOpenDuration() taskMgr.add(self.__eyesLookTask, self.taskName("eyesLookTask"))
def generateHead(self, gender, head, headType, forGui=0): def stashMuzzles(length, stashNeutral=0): if stashNeutral: if length == "short": self.findAllMatches('**/muzzle-long-neutral;+s').stash() elif length == "long": self.findAllMatches('**/muzzle-short-neutral;+s').stash() else: if length == "short": if self.find('**/muzzle-long-neutral;+s').isStashed(): self.find('**/muzzle-long-neutral;+s').unstash() elif length == "long": if self.find('**/muzzle-short-neutral;+s').isStashed(): self.find('**/muzzle-short-neutral;+s').unstash() self.findAllMatches('**/muzzle-' + length + '-s*;+s').stash() self.findAllMatches('**/muzzle-' + length + '-laugh;+s').stash() self.findAllMatches('**/muzzle-' + length + '-angry;+s').stash() def stashParts(length): for part in self.findAllMatches('**/*' + length + '*;+s'): part.stash() self.gender = gender self.animal = head self.head = headType _modelDetail = "1000" if head != "dog": self.loadModel( "phase_3/models/char/%s-heads-%s.bam" % (head, _modelDetail), 'head') else: self.loadModel( "phase_3/models/char/tt_a_chr_%s_head_%s.bam" % (headType, _modelDetail), 'head') partAnimations = {} # Load the body part animations. for animName in ToonGlobals.ANIMATIONS: animationData = list(ToonGlobals.ANIMATIONS[animName]) animPath = None if len(animationData) == 2: animPhase = animationData[0] animFile = animationData[1] # Let's create the path for the animation. animPath = ToonGlobals.BASE_MODEL % (animPhase, headType, '', 'head', animFile) if '_-' in animPath: animPath = animPath.replace('_-', '-') if '__' in animPath: animPath = animPath.replace('__', '_') partAnimations[animName] = animPath self.loadAnims(partAnimations, 'head') _pupilL = self.findAllMatches('**/def_left_pupil') _pupilR = self.findAllMatches('**/def_right_pupil') if headType == "1": stashParts("long") stashMuzzles("long", stashNeutral=0) stashMuzzles("short", stashNeutral=1) _pupilL = self.findAllMatches('**/joint_pupilL_short') _pupilR = self.findAllMatches('**/joint_pupilR_short') elif headType == "2": if head == "mouse": stashParts("short") stashMuzzles("short", stashNeutral=1) stashMuzzles("long", stashNeutral=0) _pupilL = self.findAllMatches('**/joint_pupilL_long') _pupilR = self.findAllMatches('**/joint_pupilR_long') else: stashParts("long") stashMuzzles("short", stashNeutral=0) stashMuzzles("long", stashNeutral=1) _pupilL = self.findAllMatches('**/joint_pupilL_short') _pupilR = self.findAllMatches('**/joint_pupilR_short') if head == "rabbit": self.findAllMatches('**/head-long').unstash() self.findAllMatches('**/head-front-long').unstash() #self.findAllMatches('**/head-front-short').stash() #self.findAllMatches('**/head-short').stash() elif headType == "3": stashParts("short") stashMuzzles("long", stashNeutral=0) stashMuzzles("short", stashNeutral=1) _pupilL = self.findAllMatches('**/joint_pupilL_long') _pupilR = self.findAllMatches('**/joint_pupilR_long') if head == "rabbit": self.findAllMatches('**/head-long').stash() self.findAllMatches('**/head-front-long').stash() self.findAllMatches('**/head-front-short').unstash() self.findAllMatches('**/head-short').unstash() elif headType == "4": stashParts("short") stashMuzzles("short", stashNeutral=0) stashMuzzles("long", stashNeutral=1) _pupilL = self.findAllMatches('**/joint_pupilL_long') _pupilR = self.findAllMatches('**/joint_pupilR_long') self.pupils.append(_pupilL) self.pupils.append(_pupilR) self.fixEyes() if self.gender == "girl": self.setupEyelashes() if not forGui: if not self.eyeLensNP: lens = PerspectiveLens() lens.setMinFov(180.0 / (4. / 3.)) node = LensNode('toonEyes', lens) node.activateLens(0) #node.showFrustum() self.eyeLensNP = self.attachNewNode(node) self.eyeLensNP.setZ(self.getHeight() - 0.5) self.eyeLensNP.setY(-1) self.setEyesOpenDuration() taskMgr.add(self.__eyesLookTask, "toonHeadEyesLook-" + str(id(self))) return