Exemple #1
0
    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
Exemple #2
0
    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