How to use the algorithms.select_and_change_mode function in algorithms

To help you get started, we’ve selected a few algorithms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github calben / EasyBastioniLAB / animationengine.py View on Github external
for x_bone in target_armature.data.bones:
                    b_name = x_bone.name
                    source_bone_name = self.get_mapped_name(b_name)
                    if source_bone_name != None:
                        armature_z_axis[b_name] = source_armature.data.edit_bones[source_bone_name].z_axis.copy()
                    else:
                        algorithms.print_log_report("DEBUG","Bone {0} non mapped".format(b_name))
                algorithms.select_and_change_mode(source_armature,'POSE')

            algorithms.select_and_change_mode(target_armature,'EDIT')
            for armat_bone in target_armature.data.edit_bones:
                if armat_bone.name in armature_z_axis:
                    z_axis = armature_z_axis[armat_bone.name]
                    armat_bone.align_roll(z_axis)
            algorithms.select_and_change_mode(target_armature,'POSE')
github calben / EasyBastioniLAB / animationengine.py View on Github external
def clear_chain_by_dot_product(self, chain, armature):
        algorithms.select_and_change_mode(armature,'EDIT')
        if len(chain) > 2:
            edit_bones = algorithms.get_edit_bones(armature)
            bone_name = chain[0]
            if bone_name in edit_bones:
                e_bone = edit_bones[bone_name]
                if e_bone.parent:
                    v1 = e_bone.vector.normalized()
                    v2 = e_bone.parent.vector.normalized()
                    if v1.dot(v2) < 0.5:
                        algorithms.print_log_report("INFO","Retarget: Bone {0} removed BY DOT".format(bone_name))
                        chain.remove(bone_name)
        algorithms.select_and_change_mode(armature,'POSE')#TODO: store the status and restore it
        return chain
github calben / EasyBastioniLAB / skeletonengine.py View on Github external
def align_bones_z_axis(self):
        target_armature = self.get_armature()
        if target_armature:
            algorithms.select_and_change_mode(target_armature,'EDIT')
            edit_bones = algorithms.get_edit_bones(target_armature)
            for e_bone in edit_bones:                
                if e_bone.name in self.armature_z_axis:
                    z_axis = self.armature_z_axis[e_bone.name]
                    e_bone.align_roll(z_axis)
            algorithms.select_and_change_mode(target_armature,'POSE')
github calben / EasyBastioniLAB / animationengine.py View on Github external
def calculate_skeleton_vectors(self,armat,armat_type,rot_type):

        algorithms.select_and_change_mode(armat,"EDIT")
        if armat_type == 'SOURCE':

            head_bone = self.get_source_editbone(armat,"head")
            pelvis_bone = self.get_source_editbone(armat,"pelvis")
            hand_bone1 = self.get_source_editbone(armat,"hand_R")
            hand_bone2 = self.get_source_editbone(armat,"hand_L")

            if head_bone == None:
                head_bone = self.get_source_editbone(armat,"neck")
            if hand_bone1 == None:
                hand_bone1 = self.get_source_editbone(armat,"lowerarm_R")
            if hand_bone2 == None:
                hand_bone2 = self.get_source_editbone(armat,"lowerarm_L")

        if armat_type == 'TARGET':
github calben / EasyBastioniLAB / animationengine.py View on Github external
def use_animation_pelvis(self,target_armat,source_armat):

        if target_armat != None:
            if source_armat != None:
                v1 = None
                v2 = None

                armat_prop = self.get_armature_proportion(target_armat,source_armat)
                algorithms.select_and_change_mode(source_armat,'EDIT')
                source_pelvis = self.get_source_editbone(source_armat,"pelvis")
                r_thigh_bone = self.get_source_editbone(source_armat,"thigh_R")
                l_thigh_bone = self.get_source_editbone(source_armat,"thigh_L")

                if source_pelvis != None:
                    if r_thigh_bone != None:
                        if l_thigh_bone != None:

                            p1 =  (r_thigh_bone.head + l_thigh_bone.head)*0.5
                            p2 =  source_pelvis.head
                            p3 =  source_pelvis.tail
                            v1 = armat_prop*(p2-p1)
                            v2 = armat_prop*(p3-p2)

                algorithms.select_and_change_mode(source_armat,'POSE')
github calben / EasyBastioniLAB / humanoid.py View on Github external
wished_measures = use_measures_from_dict

            self.morph_engine.calculate_proportions(wished_measures)
            similar_characters_data  = self.morph_engine.compare_data_proportions()

            best_character = similar_characters_data[0]
            filepath = best_character[1]
            self.load_character(filepath)
            if mix:
                for char_data in similar_characters_data[1:n_samples]:
                    filepath = char_data[1]
                    self.load_character(filepath, mix = True)

            self.measure_fitting(wished_measures, mix)
            self.update_character(mode = "update_directly_verts")
            algorithms.select_and_change_mode(obj,'OBJECT')

            algorithms.print_log_report("INFO","Human fitting in {0} secs".format(time.time()-time2))
github calben / EasyBastioniLAB / skeletonengine.py View on Github external
def align_bones_z_axis(self):
        target_armature = self.get_armature()
        if target_armature:
            algorithms.select_and_change_mode(target_armature,'EDIT')
            edit_bones = algorithms.get_edit_bones(target_armature)
            for e_bone in edit_bones:                
                if e_bone.name in self.armature_z_axis:
                    z_axis = self.armature_z_axis[e_bone.name]
                    e_bone.align_roll(z_axis)
            algorithms.select_and_change_mode(target_armature,'POSE')
github calben / EasyBastioniLAB / animationengine.py View on Github external
def load_bones_quaternions(self, armat, data_path):
        self.reset_pose(armat)

        if armat:
            matrix_data = algorithms.load_json_data(data_path,"Pose data")
            algorithms.set_object_visible(armat)
            algorithms.select_and_change_mode(armat,"POSE")

            pose_bones = algorithms.get_pose_bones(armat)
            for p_bone in pose_bones:
                if p_bone.name in matrix_data:
                    algorithms.set_bone_rotation(p_bone, mathutils.Quaternion(matrix_data[p_bone.name]))
                else:
                    algorithms.reset_bone_rot(p_bone)