Beispiel #1
0
    def __configure_rig(self, rig):
        root = rig.rootObject()
        armature = rig.armature()
        meshes = tuple(rig.meshes())

        rig.loadMorphs()

        vertex_groups = {g.name for mesh in meshes for g in mesh.vertex_groups}
        for pose_bone in armature.pose.bones:
            if not pose_bone.parent:
                continue
            if not pose_bone.bone.use_connect and pose_bone.name not in vertex_groups:
                continue
            pose_bone.lock_location = (True, True, True)

        for m in {x for mesh in meshes for x in mesh.data.materials if x}:
            mmd_material = m.mmd_material

            map_diffuse = next(
                (s.blend_type
                 for s in m.texture_slots if s and s.use_map_color_diffuse),
                None)
            use_diffuse = map_diffuse in {None, 'MULTIPLY'}
            diffuse = m.diffuse_color * min(1.0, m.diffuse_intensity /
                                            0.8) if use_diffuse else (1.0, 1.0,
                                                                      1.0)
            mmd_material.diffuse_color = diffuse
            if self.ambient_color_source == 'MIRROR':
                mmd_material.ambient_color = m.mirror_color
            else:
                mmd_material.ambient_color = [0.5 * c for c in diffuse]

            map_alpha = next(
                (s.blend_type
                 for s in m.texture_slots if s and s.use_map_alpha), None)
            if m.use_transparency and map_alpha in {None, 'MULTIPLY'}:
                mmd_material.alpha = m.alpha

            mmd_material.specular_color = m.specular_color * min(
                1.0, m.specular_intensity / 0.8)
            mmd_material.shininess = m.specular_hardness
            mmd_material.is_double_sided = m.game_settings.use_backface_culling
            mmd_material.enabled_self_shadow_map = m.use_cast_buffer_shadows and m.alpha > 1e-3
            mmd_material.enabled_self_shadow = m.use_shadows
            if hasattr(m, 'line_color'):  # freestyle line color
                line_color = list(m.line_color)
                mmd_material.enabled_toon_edge = line_color[
                    3] >= self.edge_threshold
                mmd_material.edge_color = line_color[:3] + [
                    max(line_color[3], self.edge_alpha_min)
                ]

        from mmd_tools_local.operators.display_item import DisplayItemQuickSetup
        DisplayItemQuickSetup.load_bone_groups(root.mmd_root, armature)
        rig.initialDisplayFrames(reset=False)  # ensure default frames
        DisplayItemQuickSetup.load_facial_items(root.mmd_root)
Beispiel #2
0
    def __configure_rig(self, rig):
        root = rig.rootObject()
        armature = rig.armature()
        meshes = tuple(rig.meshes())

        rig.loadMorphs()

        vertex_groups = {g.name for mesh in meshes for g in mesh.vertex_groups}
        for pose_bone in armature.pose.bones:
            if not pose_bone.parent:
                continue
            if not pose_bone.bone.use_connect and pose_bone.name not in vertex_groups:
                continue
            pose_bone.lock_location = (True, True, True)

        for m in {x for mesh in meshes for x in mesh.data.materials if x}:
            mmd_material = m.mmd_material

            diffuse = m.diffuse_color[:]
            mmd_material.diffuse_color = diffuse
            if self.ambient_color_source == 'MIRROR':
                mmd_material.ambient_color = m.mirror_color
            else:
                mmd_material.ambient_color = [0.5 * c for c in diffuse]
            mmd_material.alpha = m.alpha
            mmd_material.specular_color = m.specular_color
            mmd_material.shininess = m.specular_hardness
            mmd_material.is_double_sided = m.game_settings.use_backface_culling
            mmd_material.enabled_self_shadow_map = m.use_cast_buffer_shadows and m.alpha > 1e-3
            mmd_material.enabled_self_shadow = m.use_shadows
            if hasattr(m, 'line_color'):  # freestyle line color
                line_color = list(m.line_color)
                if line_color[3] < self.edge_threshold:
                    mmd_material.enabled_toon_edge = False
                    mmd_material.edge_color[:3] = line_color[:3]  # skip alpha
                else:
                    mmd_material.enabled_toon_edge = True
                    mmd_material.edge_color = line_color

        from mmd_tools_local.operators.display_item import DisplayItemQuickSetup
        DisplayItemQuickSetup.load_bone_groups(root.mmd_root, armature)
        rig.initialDisplayFrames(reset=False)  # ensure default frames
        DisplayItemQuickSetup.load_facial_items(root.mmd_root)
Beispiel #3
0
    def __configure_rig(self, rig):
        root = rig.rootObject()
        armature = rig.armature()
        meshes = tuple(rig.meshes())

        rig.loadMorphs()

        vertex_groups = {g.name for mesh in meshes for g in mesh.vertex_groups}
        for pose_bone in armature.pose.bones:
            if not pose_bone.parent:
                continue
            if not pose_bone.bone.use_connect and pose_bone.name not in vertex_groups:
                continue
            pose_bone.lock_location = (True, True, True)

        from mmd_tools_local.core.material import FnMaterial
        for m in {x for mesh in meshes for x in mesh.data.materials if x}:
            FnMaterial.convert_to_mmd_material(m)
            mmd_material = m.mmd_material
            if self.ambient_color_source == 'MIRROR' and hasattr(
                    m, 'mirror_color'):
                mmd_material.ambient_color = m.mirror_color
            else:
                mmd_material.ambient_color = [
                    0.5 * c for c in mmd_material.diffuse_color
                ]

            if hasattr(m, 'line_color'):  # freestyle line color
                line_color = list(m.line_color)
                mmd_material.enabled_toon_edge = line_color[
                    3] >= self.edge_threshold
                mmd_material.edge_color = line_color[:3] + [
                    max(line_color[3], self.edge_alpha_min)
                ]

        from mmd_tools_local.operators.display_item import DisplayItemQuickSetup
        DisplayItemQuickSetup.load_bone_groups(root.mmd_root, armature)
        rig.initialDisplayFrames(reset=False)  # ensure default frames
        DisplayItemQuickSetup.load_facial_items(root.mmd_root)
        root.mmd_root.active_display_item_frame = 0
    def __importDisplayFrames(self):
        pmxModel = self.__model
        root = self.__root
        morph_types = self.MORPH_TYPES

        for i in pmxModel.display:
            frame = root.mmd_root.display_item_frames.add()
            frame.name = i.name
            frame.name_e = i.name_e
            frame.is_special = i.isSpecial
            for disp_type, index in i.data:
                item = frame.data.add()
                if disp_type == 0:
                    item.type = 'BONE'
                    item.name = self.__boneTable[index].name
                elif disp_type == 1:
                    item.type = 'MORPH'
                    morph = pmxModel.morphs[index]
                    item.name = morph.name
                    item.morph_type = morph_types[morph.type_index()]
                else:
                    raise Exception('Unknown display item type.')

        DisplayItemQuickSetup.apply_bone_groups(root.mmd_root, self.__armObj)