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)
def parent_mesh_to_collection(collection_name='', low=False, objects=None): if collection_name == '': collection_name = alc.scene_object().shot if low: collection_name = '{}_low'.format(alc.scene_object().shot) meshes = [] if not objects: objects = bpy.context.selected_objects for obj in objects: if obj.type == "MESH": print(obj.name) meshes.append(obj) try: for collection in bpy.data.collections: if collection.name == collection_name: collection.objects.link(obj) except (RuntimeError, TypeError, NameError, AttributeError): pass for collection in obj.users_collection: if collection.name != collection_name: collection.objects.unlink(obj) return meshes
def execute(self, context): self.report({'INFO'}, "Selected: %s" % self.selected_task) new_task = alc.scene_object() task_version = new_task.copy(task=self.selected_task) task_version_dir = task_version.copy(filename='') new_version = task_version_dir.new_minor_version_object() if os.path.isdir(new_version.path_root): new_version = new_version.new_minor_version_object() else: new_version = new_version.copy(major='000', minor='000') os.makedirs(new_version.path_root) alc.save_file_as(new_version.copy(set_proper_filename=True).path_root) alc.open_file(new_version.copy(set_proper_filename=True).path_root) if os.path.isfile(alc.scene_object().copy(extension='json').path_root): print("______________Json File Saved____________") copyfile( alc.scene_object().copy(extension='json').path_root, new_version.copy(set_proper_filename=True, ext='json').path_root) else: print("______________No Json File on: ____________") print(alc.scene_object().copy(extension='json').path_root) return {'FINISHED'}
def execute(self, context): self.report({'INFO'}, "Selected: %s" % self.selected_task) if self.selected_task == 'Base Mesh': new_task = alc.scene_object().copy( context='render', task='mdl', type='lib', asset='baseMesh', user='******', set_proper_filename=True).latest_version().path_root else: new_task = alc.scene_object().copy( context='render', task=self.selected_task, user='******', set_proper_filename=True).latest_version().path_root if os.path.isfile(new_task): print(new_task) alc.import_file(new_task, linked=True, append=False) else: alc.confirm_prompt( message= 'publish not found, please check if the task has been published or import manually ' ) return {'FINISHED'}
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ scene = alc.scene_object() if scene.context == 'source': if scene.resolution == 'high': alc.version_up() bpy.ops.file.make_paths_relative() low_res = alc.scene_object().copy(resolution='low') for res in low_res.glob_project_element('filename'): create_file_dirs(res) cgl_copy(res.path_root, low_res.path_root) alc.confirm_prompt(message="Version up to {}".format(alc.scene_object().version)) else: alc.confirm_prompt(message="This is a low resolution version , please edit source file") else: alc.confirm_prompt(message="files in the render context shouldn't be versioned up, please edit source file")
def cleanup_scene(assetName): ''' :param assetname: collection that will be kepth ''' if not assetName: assetName = alc.scene_object().shot rig_collection = bpy.data.collections[assetName] sceneName = alc.scene_object().filename_base scenes = [] for scene in bpy.data.scenes: scenes.append(scene.name) if sceneName not in scenes: newScene = bpy.data.scenes.new(sceneName) else: newScene = bpy.data.scenes[sceneName] for scene in bpy.data.scenes: list_of_collections = [] for collection in newScene.collection.children: list_of_collections.append(collection) if rig_collection not in list_of_collections: newScene.collection.children.link(rig_collection) if scene.name != sceneName: bpy.data.scenes.remove(scene) data = [ bpy.data.objects, bpy.data.collections, bpy.data.materials, bpy.data.meshes, bpy.data.lights ] for type in data: for obj in type: if obj.users < 1: type.remove(obj) for action in bpy.data.actions: bpy.data.actions.remove(action) scene_collections = bpy.context.scene.collection scene = alc.scene_object() if scene.type == 'prop': for lib in bpy.data.libraries: print(lib.name) for collection in scene_collections.children: if collection.name != assetName: print(collection.name) scene_collections.children.unlink(collection)
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)
def get_selection(selection=None): if selection == None: try: selection = bpy.context.selected_objects except: currentScene = alc.scene_object() assetName = alc.scene_object().shot obj_in_collection = bpy.data.collections[assetName].all_objects if not selection: selection = bpy.data.objects return selection
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ if alc.scene_object().type == 'env': read_layout(outFile=alc.scene_object().copy(ext='json').path_root, append=True) elif alc.scene_object().type == 'light': read_layout(append=False) else: read_layout(append=True)
def get_asset_from_name(keys=''): name = keys.split(' ')[0] type = keys.split(' ')[1] user = keys.split(' ')[2] task = 'mdl' current_scene = alc.scene_object() dict_ = { 'company': current_scene.company, 'context': 'source', 'project': current_scene.project, 'scope': 'assets', 'seq': type, 'shot': name, 'task': task, 'user': user, 'branch': current_scene.branch, 'variant': 'default', 'resolution': 'high' } path_object = alc.PathObject(dict_) path_object.set_attr(filename='%s_%s_%s.%s' % (path_object.seq, path_object.shot, path_object.task, current_scene.ext)) default_asset = path_object.latest_version() return (default_asset)
def get_shot_from_name(keys=''): seq = keys.split(' ')[0] shot = keys.split(' ')[1] task = keys.split(' ')[3] current_scene = alc.scene_object() dict_ = {'company': current_scene.company, 'context': 'source', 'project': current_scene.project, 'scope': 'assets', 'seq': seq, 'shot': shot, 'task': task, 'user': '******', 'resolution': 'high' } path_object = alc.PathObject(dict_) path_object.set_attr(filename='%s_%s_%s.%s' % (path_object.seq, path_object.shot, path_object.task, current_scene.ext )) default_asset = path_object.latest_version() return (default_asset)
def get_asset_from_name(keys=''): name = keys.split(' ')[0] type = keys.split(' ')[1] if type in ['char', 'veh']: task = 'rig' else: task = 'mdl' current_scene = alc.scene_object() dict_ = {'company': current_scene.company, 'context': 'source', 'project': current_scene.project, 'scope': 'assets', 'seq': type, 'shot': name, 'task': task, 'user': '******', 'resolution': 'high' } path_object = alc.PathObject(dict_) path_object.set_attr(filename='%s_%s_%s.%s' % (path_object.seq, path_object.shot, path_object.task, current_scene.ext )) default_asset = path_object.latest_version() return (default_asset)
def reset_bones(armature=''): import bpy from mathutils import Vector, Quaternion from mathutils import Matrix ik_switches = ["c_foot_ik.l", "c_foot_ik.r", "c_hand_ik.r", "c_hand_ik.l"] if armature == '': assetName = alc.scene_object().shot rigname = '{}_rig'.format(assetName) rig = bpy.data.objects[rigname] armature = rig.pose.bones else: armature_name = '{}_rig'.format(armature) armature = bpy.data.objects[armature_name].pose.bones for pb in armature: try: pb.matrix_basis = Matrix() # == Matrix.Identity(4) except (AttributeError): pass if pb.name in ik_switches: if 'hand' in pb.name: pb["ik_fk_switch"] = 1 elif 'foot' in pb.name: pb["ik_fk_switch"] = 0
def run(selection=''): """ simple renamer.. really basic . :return: """ current_scene = alc.scene_object() if selection == '': selection = bpy.context.selected_objects else: selection = [bpy.data.objects[selection]] for i in selection: asset = current_scene.shot if '_' in i.name: i.name = '{}_{}'.format(asset, i.name.split('_')[1]) if '.' in i.name: i.name = i.name.split('.')[0] else: i.name = asset
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ from cgl.plugins.blender import alchemy as alc import bpy import os scene = alc.scene_object() texture_task = scene.copy(task='tex').latest_version() texture_task = texture_task.copy( version=texture_task.next_minor_version_number(), filename='') # print(texture_task_next.path_root) os.makedirs(texture_task.path_root) os.makedirs(texture_task.copy(context='render').path_root) for image in bpy.data.images: out_path = texture_task.copy(filename=image.name, context='render').path_root image.save_render(out_path) alc.save_file_as( texture_task.copy(context='source', set_proper_filename=True).path_root) alc.confirm_prompt(message='textures exported!!! ')
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ from cgl.plugins.blender import alchemy as alc import bpy import os scene = alc.scene_object() texture_task = scene.copy(task='tex').latest_version() texture_task = texture_task.copy(version=texture_task.next_minor_version_number(), filename='') # print(texture_task_next.path_root) os.makedirs(texture_task.path_root) os.makedirs(texture_task.copy(context='render').path_root) ignore_list = ['b_painter_brush_img', 'Render Result'] for image in bpy.data.images: filename = image.name.split(':') if len(filename) > 1: filename = filename[1] if image.name not in ignore_list: out_path = texture_task.copy(filename=filename, context='render', ext='exr').path_root image.save_render(out_path) image.filepath = out_path alc.save_file_as(texture_task.copy(context='source', set_proper_filename=True).path_root) alc.confirm_prompt(message='textures exported!!! ')
def execute(self, context): self.report({'INFO'}, "Selected: %s" % self.selected_task) new_user = alc.scene_object().copy( task=self.selected_task, user='******', set_proper_filename=True).latest_version().path_root alc.open_file(new_user) return {'FINISHED'}
def get_items(self, context): from cgl.plugins.blender import alchemy as alc import os scene = alc.scene_object() project = alc.PathObject(scene.split_after('project')) char = project.copy(scope='assets', seq='char') assets = ['char', 'prop', 'lib', 'veh', 'env'] asset_dic = {} for asset in assets: asset_dic.update({asset: project.copy(scope='assets', seq=asset,branch = scene.branch,)}) list_base = [] list = [] for type in assets: if os.path.isdir(asset_dic[type].path_root): for i in os.listdir(asset_dic[type].path_root): list_base.append('{} {}'.format(i, type)) dictionary = {} for i in list_base: list.append(i.split(' ')[0]) dictionary = dict(map(str, x.split(' ')) for x in list_base) value = [('{} {}'.format(list[i], dictionary[list[i]]), '{} {}'.format(dictionary[list[i]], '{}'.format(list[i])), '') for i in range(len(list))] return (value)
def burn_in_image(): current = bpy.context.scene mSettings = current.render sceneObject = alc.scene_object() current.name = sceneObject.filename_base scene_info = bpy.context.scene.statistics(bpy.context.view_layer) try: mSettings.metadata_input = 'SCENE' except AttributeError: mSettings.use_stamp_strip_meta = 0 mSettings.stamp_font_size = 26 mSettings.use_stamp = 1 mSettings.use_stamp_camera = 1 mSettings.use_stamp_date = 0 mSettings.use_stamp_frame = True mSettings.use_stamp_frame_range = 0 mSettings.use_stamp_hostname = 0 mSettings.use_stamp_labels = 0 mSettings.use_stamp_lens = 1 mSettings.use_stamp_marker = 0 mSettings.use_stamp_memory = 0 mSettings.use_stamp_note = 0 mSettings.use_stamp_render_time = 0 mSettings.use_stamp_scene = 1 mSettings.use_stamp_sequencer_strip = 0 mSettings.use_stamp_time = 1 mSettings.use_stamp_note = True mSettings.stamp_note_text = scene_info print('sucess')
def cleanup_scene(): "deletes all unecesary info " assetName = alc.scene_object().shot rig_collection = bpy.data.collections[assetName] sceneName = alc.scene_object().filename_base scenes = [] for scene in bpy.data.scenes: scenes.append(scene.name) if sceneName not in scenes: newScene = bpy.data.scenes.new(sceneName) else: newScene = bpy.data.scenes[sceneName] for scene in bpy.data.scenes: #override = bpy.context.copy() #override["area.type"] = ['OUTLINER'] #override["display_mode"] = ['ORPHAN_DATA'] #bpy.ops.outliner.orphans_purge(override) list_of_collections = [] for collection in newScene.collection.children: list_of_collections.append(collection) if rig_collection not in list_of_collections: newScene.collection.children.link(rig_collection) if scene.name != sceneName: bpy.data.scenes.remove(scene) data = [ bpy.data.objects, bpy.data.collections, bpy.data.materials, bpy.data.meshes, bpy.data.lights ] for type in data: for obj in type: if obj.users < 1: type.remove(obj) for action in bpy.data.actions: bpy.data.actions.remove(action)
def create_low_collection(collection_name=''): if collection_name == '': scene = alc.scene_object().shot collection_name = '{}_low'.format(scene) if collection_name not in bpy.data.collections: collection = bpy.data.collections.new(collection_name) bpy.context.scene.collection.children.link(collection)
def move_to_project(project): context = ['source', 'render'] scene = alc.scene_object() for item in context: fromDir = scene.copy(context=item, filename=None).path_root toDir = scene.copy(context=item, filename=None, project=project).path_root cgl_copy(fromDir, toDir)
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ print('Hello World!: button_template') scene = alc.scene_object() scene.show_in_folder()
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ scene = alc.scene_object() copy_latest_low() copy_latest_high()
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 export_to_task(assetName, task): task_to_export = alc.scene_object().copy( task=task, set_proper_filename=True, type='prop', shot=assetName).next_major_version() if not os.path.isdir(task_to_export.copy(filename='').path_root): os.makedirs(task_to_export.copy(filename='').path_root) alc.save_file_as(task_to_export.path_root)
def run(): """ This run statement is what's executed when your button is pressed in blender. :return: """ path_object = alc.scene_object() alc.save_file_as(path_object.copy(set_proper_filename=True).path_root) print('filename fixed')
def split_scene(): division_list = get_division_list() for i in division_list: print(i) bpy.ops.scene.new(type='LINK_COPY') bpy.context.scene.name = get_scene_name(i) bpy.context.window.scene = bpy.data.scenes[ alc.scene_object().filename_base]
def export_obj(selected): scene = alc.scene_object() obj_path = scene.copy(context='render', set_proper_filename=True, ext='obj') create_render_folder(scene) bpy.ops.export_scene.obj(filepath=obj_path.path_root, use_selection=selected)
def rename_cameras(): selected_cam = bpy.context.selected_objects currentScene = alc.scene_object() shotIncrement = 10 for camera in selected_cam: if camera.type == 'CAMERA': camName = '%04d:cam' % (shotIncrement) camera.name = camName camera.data.name = camName shotIncrement += 10