def _load_pose_units(self): from collections import OrderedDict self.base_bvh = bvh.load( getpath.getSysDataPath('poseunits/face-poseunits.bvh'), allowTranslation="none") self.base_anim = self.base_bvh.createAnimationTrack( self.human.getBaseSkeleton(), name="Expression-Face-PoseUnits") poseunit_json = json.load(io.open( getpath.getSysDataPath('poseunits/face-poseunits.json'), 'r', encoding='utf-8'), object_pairs_hook=OrderedDict) self.poseunit_names = poseunit_json['framemapping'] if len(self.poseunit_names) != self.base_bvh.frameCount: self.base_anim = None raise RuntimeError( "Face units BVH has wrong number of frames (%s) while face-poseunits.json defines %s poses, they should be equal." % (self.base_bvh.frameCount, len(self.poseunit_names))) self.base_anim = animation.PoseUnit(self.base_anim.name, self.base_anim._data, self.poseunit_names) log.message('unit pose frame count:%s', len(self.poseunit_names)) # Store indexes of all bones affected by face unit poses, should be all face bones self.face_bone_idxs = sorted( list( set([ bIdx for l in self.base_anim.getAffectedBones() for bIdx in l ])))
def _load_pose_units(self): from collections import OrderedDict self.base_bvh = bvh.load( getpath.getSysDataPath('poseunits/face-poseunits.bvh'), allowTranslation="none") self.base_anim = self.base_bvh.createAnimationTrack( self.human.getBaseSkeleton(), name="Expression-Face-PoseUnits") poseunit_json = json.load(open( getpath.getSysDataPath('poseunits/face-poseunits.json'), 'r', encoding='utf-8'), object_pairs_hook=OrderedDict) self.poseunit_names = poseunit_json['framemapping'] log.message('unit pose frame count:%s', len(self.poseunit_names)) self.modifiers = dict( list(zip(self.poseunit_names, len(self.poseunit_names) * [0.0]))) self.base_poseunit = animation.PoseUnit( self.base_anim.name, self.base_anim.data[:self.base_anim.nBones * len(self.poseunit_names)], self.poseunit_names) self._load_gui()
def get_blank_pose(): human = gui3d.app.selectedHuman base_bvh = bvh.load(getpath.getSysDataPath('poseunits/face-poseunits.bvh'), allowTranslation="none") base_anim = base_bvh.createAnimationTrack(human.getBaseSkeleton(), name="Expression-Face-PoseUnits") poseunit_json = json.load(open(getpath.getSysDataPath('poseunits/face-poseunits.json'),'rb'), object_pairs_hook=OrderedDict) # the names of the changeable facial expression features poseunit_names = poseunit_json['framemapping'] modifiers = dict(zip(poseunit_names, len(poseunit_names)*[0.0])) base_poseunit = animation.PoseUnit(base_anim.name, base_anim.data[:base_anim.nBones*len(poseunit_names)], poseunit_names) return modifiers, base_poseunit
def setExpressionFromFile(self, mhposeFile): """Set the expression from a mhpose file""" if mhposeFile is None: # clear expression original_pose = self.getPoseAsAnimation() if original_pose and hasattr(original_pose, 'pose_backref'): original_pose = original_pose.pose_backref if original_pose is None: self.human.setActiveAnimation(None) else: if self.human.hasAnimation(original_pose.name): self.human.setActiveAnimation(original_pose.name) else: self.human.addAnimation(original_pose) self.human.setActiveAnimation(orgiginal_pose.name) if self.human.hasAnimation('expr-lib-pose'): self.human.removeAnimation('expr-lib-pose') else: # Assign expression base_bvh = bvh.load(getpath.getSysDataPath('poseunits/face-poseunits.bvh'), allowTranslation="none") base_anim = base_bvh.createAnimationTrack(self.human.getBaseSkeleton(), name="Expression-Face-PoseUnits") poseunit_json = json.load(open(getpath.getSysDataPath('poseunits/face-poseunits.json'), 'r', encoding='utf-8'), object_pairs_hook=OrderedDict) poseunit_names = poseunit_json['framemapping'] base_anim = animation.PoseUnit(base_anim.name, base_anim._data, poseunit_names) face_bone_idxs = sorted(list(set([bIdx for l in base_anim.getAffectedBones() for bIdx in l]))) new_pose = animation.poseFromUnitPose('expr-lib-pose', mhposeFile, base_anim) current_pose = self.getPoseAsAnimation() if current_pose is None: current_pose = new_pose current_pose.pose_backref = None else: if hasattr(current_pose,'pose_backref') and not current_pose.pose_backref is None: current_pose = current_pose.pose_backref org_pose = current_pose current_pose = animation.mixPoses(org_pose, new_pose, face_bone_idxs) current_pose.name = 'expr-lib-pose' self.human.addAnimation(current_pose) self.human.setActiveAnimation(current_pose.name) self.human.setPosed(True) self.human.refreshPose()
def onShow(self, event): gui3d.TaskView.onShow(self, event) anim = self.base_bvh.createAnimationTrack( self.human.getBaseSkeleton(), name="Expression-Face-PoseUnits") log.message('unit pose frame count:%s', len(self.poseunit_names)) self.base_poseunit = animation.PoseUnit( anim.name, anim.data[:anim.nBones * len(self.poseunit_names)], self.poseunit_names) self.updateGui() if gui3d.app.getSetting('cameraAutoZoom'): gui3d.app.setFaceCamera()
def setExpression(expression): if expression == "None": modifiers, _ = get_blank_pose() return modifiers with open(expression, 'r') as f: human = G.app.objects[0] base_bvh = bvh.load( getpath.getSysDataPath('poseunits/face-poseunits.bvh'), allowTranslation="none") base_anim = base_bvh.createAnimationTrack( human.getBaseSkeleton(), name="Expression-Face-PoseUnits") poseunit_json = json.load(open( getpath.getSysDataPath('poseunits/face-poseunits.json'), 'rb'), object_pairs_hook=OrderedDict) # the names of the changeable facial expression features poseunit_names = poseunit_json['framemapping'] modifiers = dict(zip(poseunit_names, len(poseunit_names) * [0.0])) base_poseunit = animation.PoseUnit( base_anim.name, base_anim.data[:base_anim.nBones * len(poseunit_names)], poseunit_names) pose_modifiers = json.load(f, object_pairs_hook=OrderedDict)['unit_poses'] for key in modifiers: if key in pose_modifiers: modifiers[key] = pose_modifiers[key] # see which values are different so only those are updated posenames = [] posevalues = [] for pname, pval in modifiers.items(): #if pval != 0: posenames.append(pname) posevalues.append(pval) if len(posenames) > 0: panim = base_poseunit.getBlendedPose(posenames, posevalues) panim.disableBaking = False human.addAnimation(panim) human.setActiveAnimation(panim.name) human.refreshPose() return modifiers