def __cleanup(self, names_in_use=None): names_in_use = names_in_use or {} rig = self.__rig for mesh in rig.meshes(): for kb in getattr(mesh.data.shape_keys, 'key_blocks', ()): if kb.name.startswith('mmd_bind') and kb.name not in names_in_use: kb.driver_remove('value') kb.relative_key.mute = False ObjectOp(mesh).shape_key_remove(kb) for m in mesh.modifiers: # uv morph if m.name.startswith('mmd_bind') and m.name not in names_in_use: mesh.modifiers.remove(m) from mmd_tools_local.core.shader import _MaterialMorph for m in rig.materials(): if m and m.node_tree: for n in sorted((x for x in m.node_tree.nodes if x.name.startswith('mmd_bind')), key=lambda x: -x.location[0]): _MaterialMorph.reset_morph_links(n) m.node_tree.nodes.remove(n) attributes = set(TransformConstraintOp.min_max_attributes('LOCATION', 'to')) attributes |= set(TransformConstraintOp.min_max_attributes('ROTATION', 'to')) for b in rig.armature().pose.bones: for c in b.constraints: if c.name.startswith('mmd_bind') and c.name[:-4] not in names_in_use: for attr in attributes: c.driver_remove(attr) b.constraints.remove(c)
def __cleanup(self, names_in_use=None): names_in_use = names_in_use or {} rig = self.__rig for mesh in rig.meshes(): for kb in getattr(mesh.data.shape_keys, 'key_blocks', ()): if kb.name.startswith( 'mmd_bind') and kb.name not in names_in_use: kb.driver_remove('value') kb.relative_key.mute = False ObjectOp(mesh).shape_key_remove(kb) for m in mesh.modifiers: # uv morph if m.name.startswith( 'mmd_bind') and m.name not in names_in_use: mesh.modifiers.remove(m) attributes = set( TransformConstraintOp.min_max_attributes('LOCATION', 'to')) attributes |= set( TransformConstraintOp.min_max_attributes('ROTATION', 'to')) for b in rig.armature().pose.bones: for c in b.constraints: if c.name.startswith( 'mmd_bind') and c.name[:-4] not in names_in_use: for attr in attributes: c.driver_remove(attr) b.constraints.remove(c)
def execute(self, context): for ob in context.selected_objects: if ob.type != 'MESH' or ob.data.shape_keys is None: continue if not ob.data.shape_keys.use_relative: continue # not be considered yet self.__shape_key_clean(ObjectOp(ob), ob.data.shape_keys.key_blocks) return {'FINISHED'}
def copy_shape_key(obj, src_name, dest_name): key_blocks = getattr(obj.data.shape_keys, 'key_blocks', None) if key_blocks and src_name in key_blocks: if dest_name in key_blocks: ObjectOp(obj).shape_key_remove(key_blocks[dest_name]) obj.active_shape_key_index = key_blocks.find(src_name) obj.show_only_shape_key, last = True, obj.show_only_shape_key obj.shape_key_add(name=dest_name, from_mix=True) obj.show_only_shape_key = last obj.active_shape_key_index = key_blocks.find(dest_name)
def unbind(cls, obj): from mmd_tools_local.bpyutils import ObjectOp if obj.data.shape_keys: if cls.SHAPEKEY_NAME in obj.data.shape_keys.key_blocks: ObjectOp(obj).shape_key_remove(obj.data.shape_keys.key_blocks[cls.SHAPEKEY_NAME]) for mod in obj.modifiers: if mod.type == 'ARMATURE' and mod.vertex_group == cls.MASK_NAME: mod.vertex_group = '' mod.invert_vertex_group = False break if cls.MASK_NAME in obj.vertex_groups: obj.vertex_groups.remove(obj.vertex_groups[cls.MASK_NAME]) cls.clear_cache(obj)
def remove_shape_key(obj, key_name): key_blocks = getattr(obj.data.shape_keys, 'key_blocks', None) if key_blocks and key_name in key_blocks: ObjectOp(obj).shape_key_remove(key_blocks[key_name])