Skip to content

Instantly share code, notes, and snippets.

@giangm9
Last active April 10, 2021 08:39
Show Gist options
  • Save giangm9/5b2bdbf9ab07b3e5b538e948dd845390 to your computer and use it in GitHub Desktop.
Save giangm9/5b2bdbf9ab07b3e5b538e948dd845390 to your computer and use it in GitHub Desktop.

Append data from other blender files (example material)

with bpy.data.libraries.load(MATERIAL_LIBRARY_FILE) as (data_from, data_to):
    data_to.materials = data_from.materials

for mat in templateMat:
    materialList.append(mat.name)

remove all materials

import bpy
for material in bpy.data.materials:
    material.user_clear()
    bpy.data.materials.remove(material)
@giangm9
Copy link
Author

giangm9 commented Mar 15, 2021

generate meshes from MeshCacheSequence

import bpy
SKIP_RATE = 5

    
def generate_frame(name):
    
    for i in range(1, 30):
        if i % SKIP_RATE != 0:
            continue
        
        bpy.context.scene.frame_set(i)
        obj = bpy.data.objects[name]
        frame = obj.copy()
        frame.data  = obj.data.copy()
        
        bpy.data.collections['Collection'].objects.link(frame)
        bpy.context.view_layer.objects.active = frame

        bpy.ops.object.modifier_apply(modifier="MeshSequenceCache")
        frame.hide_viewport = True
        frame.parent = obj

generate_frame('Vay')

@giangm9
Copy link
Author

giangm9 commented Mar 29, 2021

clear morph frames

def clear_frames():
    for obj in bpy.data.objects:
        if obj.get('is_frame'):
            bpy.data.objects.remove(obj)    

@giangm9
Copy link
Author

giangm9 commented Apr 10, 2021

Assign mesh sequence cache

def assign_abc(obj):
    for child in obj.children:
        child.modifiers.clear()
        mod = child.modifiers.new("MeshSequenceCache", "MESH_SEQUENCE_CACHE")
        mod.cache_file = bpy.data.cache_files['Girl.abc']
        
        for path in mod.cache_file.object_paths:
            if child.name in path.path:
                mod.object_path = path.path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment