How to use the algorithms.load_json_data 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 / skeletonengine.py View on Github external
if rigging_type == "muscle":
                self.skeleton_template_name = "MBLab_skeleton_muscle_fk"
                self.groups_filename = character_config["vertexgroup_muscle_file"]
            if rigging_type == "muscle_ik":
                self.skeleton_template_name = "MBLab_skeleton_muscle_ik"
                self.groups_filename = character_config["vertexgroup_muscle_file"]


            self.skeleton_name = character_config["name"]+"_skeleton"
            self.lib_filepath = algorithms.get_blendlibrary_path()
            self.joints_data_path = os.path.join(self.data_path,"joints",self.joints_filename)
            self.joints_offset_data_path = os.path.join(self.data_path,"joints",self.joints_offset_filename)
            self.vgroup_data_path = os.path.join(self.data_path,"vgroups",self.groups_filename)
            self.joints_database = algorithms.load_json_data(self.joints_data_path,"Joints data")
            self.joints_offset_database = algorithms.load_json_data(self.joints_offset_data_path,"Joints offset data")

            if self.check_skeleton(obj_body):
                obj_armat = algorithms.get_object_parent(obj_body)
            else:
                obj_armat = algorithms.import_object_from_lib(self.lib_filepath, self.skeleton_template_name, self.skeleton_name)


            if obj_armat != None:
                self.store_z_axis()
                self.armature_visibility = [x for x in obj_armat.layers]
                self.armature_name = obj_armat.name                
                self.align_bones_z_axis()
                obj_body.parent = obj_armat
                self.has_data = True
            self.load_groups(self.vgroup_data_path)
            self.add_armature_modifier()
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)
github calben / EasyBastioniLAB / skeletonengine.py View on Github external
self.groups_filename = character_config["vertexgroup_base_file"]

            if rigging_type == "muscle":
                self.skeleton_template_name = "MBLab_skeleton_muscle_fk"
                self.groups_filename = character_config["vertexgroup_muscle_file"]
            if rigging_type == "muscle_ik":
                self.skeleton_template_name = "MBLab_skeleton_muscle_ik"
                self.groups_filename = character_config["vertexgroup_muscle_file"]


            self.skeleton_name = character_config["name"]+"_skeleton"
            self.lib_filepath = algorithms.get_blendlibrary_path()
            self.joints_data_path = os.path.join(self.data_path,"joints",self.joints_filename)
            self.joints_offset_data_path = os.path.join(self.data_path,"joints",self.joints_offset_filename)
            self.vgroup_data_path = os.path.join(self.data_path,"vgroups",self.groups_filename)
            self.joints_database = algorithms.load_json_data(self.joints_data_path,"Joints data")
            self.joints_offset_database = algorithms.load_json_data(self.joints_offset_data_path,"Joints offset data")

            if self.check_skeleton(obj_body):
                obj_armat = algorithms.get_object_parent(obj_body)
            else:
                obj_armat = algorithms.import_object_from_lib(self.lib_filepath, self.skeleton_template_name, self.skeleton_name)


            if obj_armat != None:
                self.store_z_axis()
                self.armature_visibility = [x for x in obj_armat.layers]
                self.armature_name = obj_armat.name                
                self.align_bones_z_axis()
                obj_body.parent = obj_armat
                self.has_data = True
            self.load_groups(self.vgroup_data_path)
github calben / EasyBastioniLAB / proxyengine.py View on Github external
def fit_distant_vertices(self, basis_proxy,basis_body,proxy_shapekey,current_body):


        #basis_proxy = proxy in basis shape, without shapekey applied
        #proxy_shapekey = shapekey to modify as final result
        #basis_body = body in basis shape, without morphings and armature
        #current_body = current body shape, with morphing (but not armature) applied

        polygons_file = algorithms.get_template_polygons(current_body)
        polygons_path = os.path.join(self.data_path,"pgroups",polygons_file)
        valid_polygons_indxs = algorithms.load_json_data(polygons_path, "Subset of polygons for proxy fitting")

        basis_proxy_vertices = basis_proxy.data.vertices #In Blender obj.data = basis data
        basis_body_polygons = basis_body.data.polygons
        current_body_polygons = current_body.data.polygons

        involved_body_polygons_idx = []
        involved_basis_body_polygons_coords = []
        involved_current_body_polygons_coords = []

        if len(basis_body_polygons) == len(current_body_polygons):
            basis_body_tree = algorithms.kdtree_from_obj_polygons(basis_body, valid_polygons_indxs)

            for i,basis_proxy_vert in enumerate(basis_proxy_vertices):

                nearest_body_polygons_data = basis_body_tree.find(basis_proxy_vert.co)
                body_polygon_index = nearest_body_polygons_data[1]
github calben / EasyBastioniLAB / humanoid.py View on Github external
def load_character(self, data_source, reset_string = "nothing", reset_unassigned=True, mix=False, update_mode = "update_all"):

        obj = self.get_object()
        log_msg_type = "character data"

        if type(data_source) == str:  #TODO: better check of types
            log_msg_type = algorithms.simple_path(data_source)
            charac_data = algorithms.load_json_data(data_source,"Character data")
        else:
            charac_data = data_source

        algorithms.print_log_report("INFO","Loading character from {0}".format(log_msg_type))

        if "manuellab_vers" in charac_data:
            if not algorithms.check_version(charac_data["manuellab_vers"]):
                algorithms.print_log_report("WARNING","{0} created with vers. {1}. Current vers is {2}".format(log_msg_type,charac_data["manuellab_vers"],self.lab_vers))
        else:
            algorithms.print_log_report("INFO","No lab version specified in {0}".format(log_msg_type))

        if "structural" in charac_data:
            char_data = charac_data["structural"]
        else:
            algorithms.print_log_report("WARNING","No structural data in  {0}".format(log_msg_type))
            char_data = {}
github calben / EasyBastioniLAB / morphengine.py View on Github external
def load_measures_database(self, measures_path):
        m_database = algorithms.load_json_data(measures_path,"Measures data")
        if m_database:
            self.measures_data = m_database["measures"]
            self.measures_relat_data = m_database["relations"]
            self.measures_score_weights = m_database["score_weights"]
            self.body_height_Z_parts = m_database["body_height_Z_parts"]
github calben / EasyBastioniLAB / morphengine.py View on Github external
def load_bboxes_database(self, bounding_box_path):
        self.bbox_data = algorithms.load_json_data(bounding_box_path,"Bounding box data")
github calben / EasyBastioniLAB / animationengine.py View on Github external
def load_expression(self, filepath):

            charac_data = algorithms.load_json_data(filepath,"Character data")
            expressions_ID = algorithms.simple_path(filepath)
            if "manuellab_vers" in charac_data:
                if not algorithms.check_version(charac_data["manuellab_vers"]):
                    algorithms.print_log_report("INFO","{0} created with vers. {1}.".format(expressions_ID,charac_data["manuellab_vers"]))
            else:
                algorithms.print_log_report("INFO","No lab version specified in {0}".format(expressions_ID))

            if "structural" in charac_data:
                char_data = charac_data["structural"]
            else:
                algorithms.print_log_report("WARNING","No structural data in  {0}".format(expressions_ID))
                char_data = None

            return char_data
github calben / EasyBastioniLAB / proxyengine.py View on Github external
def proxy_offset(self, basis_proxy,basis_body,proxy_shapekey,current_body,offset_factor):

        #basis_proxy = proxy in basis shape, without shapekey applied
        #proxy_shapekey = shapekey of actual, "real" proxy shape to modify as final result
        #basis_body = body in basis shape, without morphings and armature
        #current_body = raw copy of current body shape, with morphing and armature applied

        basis_proxy_vertices = basis_proxy.data.vertices
        basis_body_polygons = basis_body.data.polygons
        current_body_polygons = current_body.data.polygons

        polygons_file = algorithms.get_template_polygons(current_body)
        polygons_path = os.path.join(self.data_path,"pgroups",polygons_file)
        valid_polygons_indxs = algorithms.load_json_data(polygons_path, "Subset of polygons for proxy fitting")

        if len(basis_body_polygons) == len(current_body_polygons):

            #current_body_tree = algorithms.kdtree_from_mesh_polygons(current_body)
            current_body_tree = algorithms.kdtree_from_obj_polygons(current_body, valid_polygons_indxs)

            for i in range(len(basis_proxy_vertices)):
                proxy_shapekey_vert = proxy_shapekey.data[i]
                nearest_body_polygons_data = current_body_tree.find_n(proxy_shapekey_vert.co, 10)
                body_normals = []

                #raw body vs proxy shapekey
                for body_polygons_data in nearest_body_polygons_data:
                    body_polygon_index = body_polygons_data[1]
                    body_polygon_dist = body_polygons_data[2] #distance body-proxy
                    body_polygon = current_body_polygons[body_polygon_index]