def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root morph_type = mmd_root.active_morph_type morphs = getattr(mmd_root, morph_type) morph = ItemOp.get_by_index(morphs, mmd_root.active_morph) if morph is None: return {'CANCELLED'} name_orig, name_tmp = morph.name, '_tmp%s' % str(morph.as_pointer()) if morph_type.startswith('vertex'): for obj in mmd_model.Model(root).meshes(): FnMorph.copy_shape_key(obj, name_orig, name_tmp) elif morph_type.startswith('uv'): if morph.data_type == 'VERTEX_GROUP': for obj in mmd_model.Model(root).meshes(): FnMorph.copy_uv_morph_vertex_groups( obj, name_orig, name_tmp) morph_new, mmd_root.active_morph = ItemOp.add_after( morphs, mmd_root.active_morph) for k, v in morph.items(): morph_new[k] = v if k != 'name' else name_tmp morph_new.name = name_orig + '_copy' # trigger name check return {'FINISHED'}
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root morph_type = mmd_root.active_morph_type morph = ItemOp.get_by_index(getattr(mmd_root, morph_type), mmd_root.active_morph) if morph is None: return {'CANCELLED'} item, morph.active_data = ItemOp.add_after(morph.data, morph.active_data) if morph_type.startswith('material'): if obj.type == 'MESH' and obj.mmd_type == 'NONE': item.related_mesh = obj.data.name active_material = obj.active_material if active_material and '_temp' not in active_material.name: item.material = active_material.name elif morph_type.startswith('bone'): pose_bone = context.active_pose_bone if pose_bone: item.bone = pose_bone.name item.location = pose_bone.location item.rotation = pose_bone.rotation_quaternion return {'FINISHED'}
def load_facial_items(mmd_root): item_list = [] item_list.extend( ('vertex_morphs', i.name) for i in mmd_root.vertex_morphs) item_list.extend(('bone_morphs', i.name) for i in mmd_root.bone_morphs) item_list.extend( ('material_morphs', i.name) for i in mmd_root.material_morphs) item_list.extend(('uv_morphs', i.name) for i in mmd_root.uv_morphs) item_list.extend( ('group_morphs', i.name) for i in mmd_root.group_morphs) frames = mmd_root.display_item_frames frame = frames[u'表情'] facial_items = frame.data mmd_root.active_display_item_frame = frames.find(frame.name) # keep original item order old = tuple((i.morph_type, i.name) for i in facial_items) item_list.sort(key=lambda x: old.index(x) if x in old else len(old)) ItemOp.resize(facial_items, len(item_list)) for item, data in zip(facial_items, item_list): item.type = 'MORPH' item.morph_type, item.name = data frame.active_item = 0
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root morph_type = mmd_root.active_morph_type morph = ItemOp.get_by_index(getattr(mmd_root, morph_type), mmd_root.active_morph) if morph is None: return {'CANCELLED'} if morph_type.startswith('material'): bpy.ops.mmd_tools.clear_temp_materials() if self.all: if morph_type.startswith('vertex'): for obj in mmd_model.Model(root).meshes(): FnMorph.remove_shape_key(obj, morph.name) return {'FINISHED'} elif morph_type.startswith('uv'): if morph.data_type == 'VERTEX_GROUP': for obj in mmd_model.Model(root).meshes(): FnMorph.store_uv_morph_data(obj, morph) return {'FINISHED'} morph.data.clear() morph.active_data = 0 else: morph.data.remove(morph.active_data) morph.active_data = max(0, morph.active_data - 1) return {'FINISHED'}
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root if self.type == 'MORPH': morph_type = mmd_root.active_morph_type morph = ItemOp.get_by_index(getattr(mmd_root, morph_type), mmd_root.active_morph) if morph is None: return {'CANCELLED'} morph_name = morph.name def __check(item): return item.type == 'MORPH' and item.name == morph_name and item.morph_type == morph_type self._find_display_item(mmd_root, __check) else: if context.active_bone is None: return {'CANCELLED'} bone_name = context.active_bone.name def __check(item): return item.type == 'BONE' and item.name == bone_name self._find_display_item(mmd_root, __check) return {'FINISHED'}
def _add_item(self, frame, item_type, item_name, morph_type=None): items = frame.data item, index = ItemOp.add_after(items, frame.active_item) item.type = item_type item.name = item_name if morph_type: item.morph_type = morph_type frame.active_item = index
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root frame = ItemOp.get_by_index(mmd_root.display_item_frames, mmd_root.active_display_item_frame) if frame is None: return {'CANCELLED'} frame.active_item = self.move(frame.data, frame.active_item, self.type) return {'FINISHED'}
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root frame = ItemOp.get_by_index(mmd_root.display_item_frames, mmd_root.active_display_item_frame) if frame is None: return {'CANCELLED'} if frame.name == u'表情': morph = ItemOp.get_by_index( getattr(mmd_root, mmd_root.active_morph_type), mmd_root.active_morph) morph_name = morph.name if morph else 'Morph Item' self._add_item(frame, 'MORPH', morph_name, mmd_root.active_morph_type) else: bone_name = context.active_bone.name if context.active_bone else 'Bone Item' self._add_item(frame, 'BONE', bone_name) return {'FINISHED'}
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root frames = mmd_root.display_item_frames item, index = ItemOp.add_after( frames, max(1, mmd_root.active_display_item_frame)) item.name = 'Display Frame' mmd_root.active_display_item_frame = index return {'FINISHED'}
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root morph_type = mmd_root.active_morph_type morphs = getattr(mmd_root, morph_type) morph, mmd_root.active_morph = ItemOp.add_after( morphs, mmd_root.active_morph) morph.name = 'New Morph' if morph_type.startswith('uv'): morph.data_type = 'VERTEX_GROUP' return {'FINISHED'}
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root frame = ItemOp.get_by_index(mmd_root.display_item_frames, mmd_root.active_display_item_frame) if frame is None: return {'CANCELLED'} item = ItemOp.get_by_index(frame.data, frame.active_item) if item is None: return {'CANCELLED'} if item.type == 'MORPH': morphs = getattr(mmd_root, item.morph_type) index = morphs.find(item.name) if index >= 0: mmd_root.active_morph_type = item.morph_type mmd_root.active_morph = index else: utils.selectSingleBone(context, mmd_model.Model(root).armature(), item.name) return {'FINISHED'}
def load_bone_groups(mmd_root, armature): bone_groups = OrderedDict( (i.name, []) for i in armature.pose.bone_groups) for b in armature.pose.bones: if b.bone_group: bone_groups[b.bone_group.name].append(b.name) frames = mmd_root.display_item_frames used_index = set() for group_name, bone_names in bone_groups.items(): if len(bone_names) < 1: # skip empty group continue frame = frames.get(group_name) if frame is None: frame = frames.add() frame.name = group_name frame.name_e = group_name used_index.add(frames.find(group_name)) items = frame.data ItemOp.resize(items, len(bone_names)) for item, name in zip(items, bone_names): item.type = 'BONE' item.name = name frame.active_item = 0 # remove unused frames for i in reversed(range(len(frames))): if i not in used_index: frame = frames[i] if frame.is_special: if frame.name != u'表情': frame.data.clear() else: frames.remove(i) mmd_root.active_display_item_frame = 0
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root frame = ItemOp.get_by_index(mmd_root.display_item_frames, mmd_root.active_display_item_frame) if frame is None: return {'CANCELLED'} if self.all: frame.data.clear() frame.active_item = 0 else: frame.data.remove(frame.active_item) frame.active_item = max(0, frame.active_item - 1) return {'FINISHED'}
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root index = mmd_root.active_display_item_frame frames = mmd_root.display_item_frames frame = ItemOp.get_by_index(frames, index) if frame and frame.is_special: frame.data.clear() frame.active_item = 0 else: frames.remove(index) mmd_root.active_display_item_frame = min( len(frames) - 1, max(2, index - 1)) return {'FINISHED'}
def execute(self, context): obj = context.active_object root = mmd_model.Model.findRoot(obj) mmd_root = root.mmd_root index = mmd_root.active_display_item_frame frames = mmd_root.display_item_frames frame = ItemOp.get_by_index(frames, index) if frame and frame.is_special: pass else: mmd_root.active_display_item_frame = self.move(frames, index, self.type, index_min=2) return {'FINISHED'}
def _template_morph_offset_list(self, layout, morph, list_type_name): row = layout.row() row.template_list( list_type_name, '', morph, 'data', morph, 'active_data', ) tb = row.column() tb1 = tb.column(align=True) tb1.operator('mmd_tools.morph_offset_add', text='', icon=ICON_ADD) tb1.operator('mmd_tools.morph_offset_remove', text='', icon=ICON_REMOVE) tb.operator('mmd_tools.morph_offset_remove', text='', icon='X').all = True return ItemOp.get_by_index(morph.data, morph.active_data)
def draw(self, context): active_obj = context.active_object root = mmd_model.Model.findRoot(active_obj) if root is None: self.layout.label(text='Select a MMD Model') return rig = mmd_model.Model(root) mmd_root = root.mmd_root col = self.layout.column() row = col.row() row.prop(mmd_root, 'active_morph_type', expand=True) morph_type = mmd_root.active_morph_type c = col.column(align=True) row = c.row() row.template_list("UL_Morphs", "", mmd_root, morph_type, mmd_root, "active_morph") tb = row.column() tb1 = tb.column(align=True) tb1.operator('mmd_tools.morph_add', text='', icon=ICON_ADD) tb1.operator('mmd_tools.morph_remove', text='', icon=ICON_REMOVE) tb1.menu('OBJECT_MT_mmd_tools_morph_menu', text='', icon='DOWNARROW_HLT') tb.separator() tb1 = tb.column(align=True) tb1.operator('mmd_tools.morph_move', text='', icon='TRIA_UP').type = 'UP' tb1.operator('mmd_tools.morph_move', text='', icon='TRIA_DOWN').type = 'DOWN' morph = ItemOp.get_by_index(getattr(mmd_root, morph_type), mmd_root.active_morph) if morph: slider = rig.morph_slider.get(morph.name) if slider: col.row().prop(slider, 'value') draw_func = getattr(self, '_draw_%s_data' % morph_type[:-7], None) if draw_func: draw_func(context, rig, col, morph)
def draw(self, context): active_obj = context.active_object root = mmd_model.Model.findRoot(active_obj) if root is None: self.layout.label(text='Select a MMD Model') return mmd_root = root.mmd_root col = self.layout.column() row = col.row() row.template_list( "MMD_ROOT_UL_display_item_frames", "", mmd_root, "display_item_frames", mmd_root, "active_display_item_frame", ) tb = row.column() tb1 = tb.column(align=True) tb1.operator('mmd_tools.display_item_frame_add', text='', icon=ICON_ADD) tb1.operator('mmd_tools.display_item_frame_remove', text='', icon=ICON_REMOVE) tb1.menu('OBJECT_MT_mmd_tools_display_item_frame_menu', text='', icon='DOWNARROW_HLT') tb.separator() tb1 = tb.column(align=True) tb1.operator('mmd_tools.display_item_frame_move', text='', icon='TRIA_UP').type = 'UP' tb1.operator('mmd_tools.display_item_frame_move', text='', icon='TRIA_DOWN').type = 'DOWN' frame = ItemOp.get_by_index(mmd_root.display_item_frames, mmd_root.active_display_item_frame) if frame is None: return c = col.column(align=True) row = c.row() row.template_list( "MMD_ROOT_UL_display_items", "", frame, "data", frame, "active_item", ) tb = row.column() tb1 = tb.column(align=True) tb1.operator('mmd_tools.display_item_add', text='', icon=ICON_ADD) tb1.operator('mmd_tools.display_item_remove', text='', icon=ICON_REMOVE) tb1.menu('OBJECT_MT_mmd_tools_display_item_menu', text='', icon='DOWNARROW_HLT') tb.separator() tb1 = tb.column(align=True) tb1.operator('mmd_tools.display_item_move', text='', icon='TRIA_UP').type = 'UP' tb1.operator('mmd_tools.display_item_move', text='', icon='TRIA_DOWN').type = 'DOWN' row = col.row() r = row.row(align=True) r.operator('mmd_tools.display_item_find', text='Bone', icon='VIEWZOOM').type = 'BONE' r.operator('mmd_tools.display_item_find', text='Morph', icon='VIEWZOOM').type = 'MORPH' row.operator('mmd_tools.display_item_select_current', text='Select')