示例#1
0
    def chooseExpression(self, filename):
        log.debug("Loading expression from %s", filename)
        self.selectedFile = filename

        if not filename:
            # Unload current expression
            self.selectedPose = None
            # Remove the expression from existing pose by restoring the original
            org_pose = self._get_current_unmodified_pose()
            if org_pose is None:
                self.human.setActiveAnimation(None)
            elif self.human.hasAnimation(org_pose.name):
                self.human.setActiveAnimation(org_pose.name)
            else:
                self.human.addAnimation(org_pose)
                self.human.setActiveAnimation(org_pose.name)

            # Remove pose reserved for expression library from human
            if self.human.hasAnimation('expr-lib-pose'):
                self.human.removeAnimation('expr-lib-pose')
            self.filechooser.selectItem(None)
            self.human.refreshPose(updateIfInRest=True)
            return

        # Assign to human
        self.selectedPose = animation.poseFromUnitPose('expr-lib-pose',
                                                       filename,
                                                       self.base_anim)
        self.applyToPose(self.selectedPose)
        self.human.refreshPose()

        self.filechooser.selectItem(filename)
    def chooseExpression(self, filename):
        log.debug("Loading expression from %s", filename)
        self.selectedFile = filename

        if not filename:
            # Unload current expression
            self.selectedPose = None
            # Remove the expression from existing pose by restoring the original
            org_pose = self._get_current_unmodified_pose()
            if org_pose is None:
                self.human.setActiveAnimation(None)
            elif self.human.hasAnimation(org_pose.name):
                self.human.setActiveAnimation(org_pose.name)
            else:
                self.human.addAnimation(org_pose)
                self.human.setActiveAnimation(org_pose.name)

            # Remove pose reserved for expression library from human
            if self.human.hasAnimation('expr-lib-pose'):
                self.human.removeAnimation('expr-lib-pose')
            self.filechooser.selectItem(None)
            self.human.refreshPose(updateIfInRest=True)
            return

        # Assign to human
        self.selectedPose = animation.poseFromUnitPose('expr-lib-pose', filename, self.base_anim)
        self.applyToPose(self.selectedPose)
        self.human.refreshPose()

        self.filechooser.selectItem(filename)
示例#3
0
    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()