def save_relationship(obj_a=None, obj_b=None, bones=False):
    if bones is False:
        obj_a, obj_b = get_selection_order(obj_a, obj_b, bones)
        obj_a_mat = obj_a.matrix
        obj_b_mat = obj_b.matrix

    else:
        obj_a, obj_b = get_selection_order(obj_a, obj_b, bones)
        obj_a_mat = obj_a.matrix
        obj_b_mat = obj_b.matrix
        obj_a_mat_world = obj_a.matrix
        obj_b_mat_world = obj_b.matrix
        difference_local = obj_b_mat_world.inverted() @ obj_a_mat_world

    difference = obj_b_mat.inverted() @ obj_a_mat

    if bones:
        print('difference world')
        print(obj_a_mat_world)
        print(obj_b_mat_world)
        difference = obj_a_mat_world.inverted() @ obj_b_mat_world
        difference_inv = obj_b_mat_world.inverted() @ obj_a_mat_world

    print('difference')
    print(difference)

    data = {}
    data.update({'{} {}'.format(obj_a.name, obj_b.name): flatten(difference)})
    data.update(
        {'{} {}'.format(obj_b.name, obj_a.name): flatten(difference_inv)})

    save_json(filepath, data)
Пример #2
0
 def edit_globals_paths(self):
     globals = read_write.load_json(self.globals_path)
     # change the stuff
     globals["paths"]["code_root"] = self.default_code_root
     globals["paths"]["root"] = self.default_root
     globals["paths"]["cgl_tools"] = os.path.join(self.default_root,
                                                  '_config', 'cgl_tools')
     # TODO this shouldn't be used
     globals["paths"]["globals"] = os.path.join(self.default_root,
                                                '_config', 'globals.json')
     # TODO this should be a env_variable
     globals["paths"]["user_globals"] = self.default_user_globals
     globals["sync"]["syncthing"]["sheets_config_path"] = os.path.join(
         self.default_root, '_config', 'client.json')
     # TODO this should exist
     globals["account_info"]["globals_path"] = os.path.join(
         self.default_root, '_config', 'globals.json')
     # TODO - This shouldn't exist
     globals["cg_lumberjack_dir"] = os.path.join(self.default_root,
                                                 '_config')
     # TODO - it'd be nice to double check all the sofwtare paths and see if there are newer versions on disk, this will help a ton.
     globals_dir = os.path.dirname(globals["paths"]["globals"])
     if not os.path.exists(globals_dir):
         os.makedirs(globals_dir)
     print 'Saving Globals To: %s' % globals["paths"]["globals"]
     read_write.save_json(globals["paths"]["globals"], globals)
Пример #3
0
def write_mesh_list(outFile=None):
    """

    :param outFile:
    :return:
    """
    from cgl.plugins.blender.alchemy import scene_object
    from cgl.core.utils.read_write import save_json
    import bpy

    scene = alc.scene_object()

    if outFile == None:
        outFile = scene_object().copy(ext='json', context='render').path_root
    data = {}

    for obj in bpy.data.collections[scene.asset].objects:
        name = obj.name
        print(obj.name)
        #            blender_transform = np.array(obj.matrix_world).tolist()
        blender_transform = set_matrix(obj)
        data[name] = {'name': obj.name, 'blender_transform': blender_transform}

    create_render_folder(scene)
    save_json(outFile, data)

    return (outFile)
Пример #4
0
def write_layout(outFile=None):
    """

    :param outFile:
    :return:
    """
    from cgl.plugins.blender.alchemy import scene_object, PathObject
    from cgl.core.utils.read_write import save_json
    import bpy
    from pathlib import Path

    if outFile == None:
        outFile = scene_object().copy(ext='json', task='lay',
                                      user='******').path_root
    data = {}

    for obj in bpy.context.view_layer.objects:
        if obj.is_instancer:
            print(5 * '_' + obj.name + 5 * '_')
            name = obj.name
            #            blender_transform = np.array(obj.matrix_world).tolist()
            blender_transform = [
                obj.matrix_world.to_translation().x,
                obj.matrix_world.to_translation().y,
                obj.matrix_world.to_translation().z,
                obj.matrix_world.to_euler().x,
                obj.matrix_world.to_euler().y,
                obj.matrix_world.to_euler().z,
                obj.matrix_world.to_scale().x,
                obj.matrix_world.to_scale().y,
                obj.matrix_world.to_scale().z
            ]

            instanced_collection = obj.instance_collection
            if instanced_collection:
                collection_library = return_linked_library(
                    instanced_collection.name)

                if collection_library:

                    libraryPath = bpy.path.abspath(collection_library.filepath)
                    filename = Path(bpy.path.abspath(libraryPath)).__str__()
                    libObject = PathObject(filename)

                    data[name] = {
                        'name': libObject.asset,
                        'source_path': libObject.path,
                        'blender_transform': blender_transform
                    }
                else:
                    print('{} has no instanced collection'.format(obj.name))

            else:
                print('{} has no instanced collection'.format(obj.name))

    save_json(outFile, data)

    return (outFile)
def write_anim(outFile=None):
    from cgl.plugins.blender.alchemy import scene_object, PathObject, import_file
    from cgl.core.utils.read_write import load_json, save_json
    import bpy
    from pathlib import Path

    if outFile == None:
        outFile = scene_object().copy(ext='json').path_root
    data = {}

    data = load_json(outFile)

    valid_rigs = []

    for obj in bpy.data.objects:

        if 'proxy' in obj.name:
            animation_data = obj.animation_data
            if animation_data:
                action = animation_data.action
                if action:
                    valid_rigs.append(obj)

    for obj in valid_rigs:
        name = obj.name.split('_proxy')[0]
        print('___________' + name)
        #            blender_transform = np.array(obj.matrix_world).tolist()
        blender_transform = [
            obj.matrix_world.to_translation().x,
            obj.matrix_world.to_translation().y,
            obj.matrix_world.to_translation().z,
            obj.matrix_world.to_euler().x,
            obj.matrix_world.to_euler().y,
            obj.matrix_world.to_euler().z,
            obj.matrix_world.to_scale().x,
            obj.matrix_world.to_scale().y,
            obj.matrix_world.to_scale().z
        ]
        libraryPath = bpy.path.abspath(
            obj.proxy_collection.instance_collection.library.filepath)
        filename = Path(bpy.path.abspath(libraryPath)).__str__()
        libObject = PathObject(filename)

    sourcePath = alc.scene_object()

    data[name] = {
        'name': libObject.asset,
        'source_path': libObject.path,
        'blender_transform': blender_transform,
        'blender_action': obj.animation_data.action.name,
        'blender_action_path': sourcePath.path
    }

    save_json(outFile, data)

    print(data)
    return (outFile)
Пример #6
0
 def create_global_config(self):
     if self.global_config:
         pm_dict = self.global_config['project_management'][
             self.proj_management_combo.currentText()]
         self.global_config['paths']['root'] = self.widget_dict['root'][
             'line_edit'].text()
         self.global_config['paths']['cgl_tools'] = self.widget_dict[
             'cgl_tools']['line_edit'].text()
         self.global_config['paths']['code_root'] = self.widget_dict[
             'code_root']['line_edit'].text()
         self.global_config['account_info'][
             'project_management'] = self.project_management
         self.global_config['account_info'][
             'globals_path'] = self.widget_dict['globals'][
                 'line_edit'].text()
         self.global_config['paths']['user_globals'] = self.widget_dict[
             'user_globals']['line_edit'].text()
         pm_dict['users'] = {
             self.user_name_line_edit.text(): {
                 'email': self.user_email_line_edit.text(),
                 'first': '',
                 'last': '',
                 'login': self.user_name_line_edit.text()
             }
         }
         api = self.global_config['project_management'][
             self.project_management]['api']
         if self.project_management == 'ftrack':
             api['api_key'] = self.api_key_line_edit.text()
             api['server_url'] = self.server_line_edit.text()
             api['api_user'] = self.api_user_line_edit.text()
             api['default_schema'] = 'VFX'
         elif self.project_management == 'shotgun':
             api['api_key'] = self.api_key_line_edit.text()
             api['server_url'] = self.server_line_edit.text()
             api['api_user'] = self.api_user_line_edit.text()
             api['api_script'] = self.api_script_line_edit.text()
         if not os.path.exists(
                 os.path.dirname(
                     self.widget_dict['root']['line_edit'].text())):
             os.makedirs(
                 os.path.dirname(
                     self.widget_dict['root']['line_edit'].text()))
         if not os.path.exists(
                 os.path.dirname(
                     self.widget_dict['globals']['line_edit'].text())):
             os.makedirs(
                 os.path.dirname(
                     self.widget_dict['globals']['line_edit'].text()))
         read_write.save_json(
             self.widget_dict['globals']['line_edit'].text(),
             self.global_config)
     else:
         print 'No Dictionary Loaded for Global Config'
Пример #7
0
def create_user_globals(user_globals, globals_path):
    if user_globals:
        if not os.path.exists(os.path.dirname(user_globals)):
            os.makedirs(os.path.dirname(user_globals))
        d = {
            "globals": globals_path,
            "previous_path": "",
            "previous_paths": {},
            "methodology": "local",
            "my_tasks": {}
        }
        print "saving user_globals to %s" % user_globals
        read_write.save_json(user_globals, d)
    else:
        print 'No Root Defined, cannot save user globals'
Пример #8
0
def run():

    """
    This run statement is what's executed when your button is pressed in blender.
    :return:
    """

    path_object = utils.create_task_on_asset('shd')
    jsonFile = path_object.copy(ext='json')
    outFile = path_object.copy(ext='json').path_root
    print(path_object.path_root)
    save_json(outFile, data=utils.get_materials_dictionary())
    alc.save_file_as(path_object.copy(set_proper_filename=True).path_root)
    bpy.ops.object.build()
    alc.save_file()
    alc.confirm_prompt(message='Shaders Exported !!')
def save_relationship(filepath, obj_a=None, obj_b=None, bones=False):
    if bones is False:
        obj_a, obj_b = get_selection_order(obj_a, obj_b, bones)
        obj_a_mat = obj_a.matrix
        obj_b_mat = obj_b.matrix

    else:
        obj_a, obj_b = get_selection_order(obj_a, obj_b, bones)
        obj_a_mat = obj_a.matrix
        obj_b_mat = obj_b.matrix
        obj_a_mat_world = obj_a.matrix
        obj_b_mat_world = obj_b.matrix
        difference_local = obj_b_mat_world.inverted() @ obj_a_mat_world

    difference = obj_b_mat.inverted() @ obj_a_mat

    if bones:
        print('difference world')
        print(obj_a_mat_world)
        print(obj_b_mat_world)
        difference = obj_a_mat_world.inverted() @ obj_b_mat_world

    print('difference')
    print(difference)

    data = {}
    data.update({'{} {}'.format(obj_a.name, obj_b.name): flatten(difference)})
    data.update({
        '{} {}'.format(obj_b.name, obj_a.name):
        flatten(difference.inverted())
    })

    updated_json = data
    if isfile(filepath):
        print('file_ existis')
        current_json = load_json(filepath)
        print(current_json)
    else:
        current_json = {}

    if current_json:
        updated_json = {**data, **current_json}
        print('file updated')
        print(updated_json)

    save_json(filepath, updated_json)
Пример #10
0
 def create_user_globals(self):
     user_globals = self.widget_dict['user_globals']['line_edit'].text()
     if user_globals:
         if not os.path.exists(os.path.dirname(user_globals)):
             os.makedirs(os.path.dirname(user_globals))
         d = {
             "globals": self.widget_dict['globals']['line_edit'].text(),
             "previous_path": "",
             "previous_paths": {},
             "user_email": self.user_email_line_edit.text(),
             "user_name": self.user_name_line_edit.text(),
             "proj_man_user_email": self.api_user_line_edit.text(),
             "proj_man_user_name": "",
             "methodology": "local",
             "my_tasks": {}
         }
         read_write.save_json(user_globals, d)
     else:
         print 'No Root Defined, cannot save user globals'