def __importMaterials(self):
        self.__importTextures()

        pmxModel = self.__model

        self.__materialFaceCountTable = []
        for i in pmxModel.materials:
            mat = bpy.data.materials.new(name=i.name)
            self.__materialTable.append(mat)
            mmd_mat = mat.mmd_material
            mat.diffuse_color = i.diffuse[0:3]
            mat.alpha = i.diffuse[3]
            mat.specular_color = i.specular
            if mat.alpha < 1.0 or mat.specular_alpha < 1.0 or i.texture != -1:
                mat.use_transparency = True
                mat.transparency_method = 'Z_TRANSPARENCY'

            mmd_mat.name_j = i.name
            mmd_mat.name_e = i.name_e
            mmd_mat.ambient_color = i.ambient
            mmd_mat.diffuse_color = i.diffuse[0:3]
            mmd_mat.alpha = i.diffuse[3]
            mmd_mat.specular_color = i.specular
            mmd_mat.shininess = i.shininess
            mmd_mat.is_double_sided = i.is_double_sided
            mmd_mat.enabled_drop_shadow = i.enabled_drop_shadow
            mmd_mat.enabled_self_shadow_map = i.enabled_self_shadow_map
            mmd_mat.enabled_self_shadow = i.enabled_self_shadow
            mmd_mat.enabled_toon_edge = i.enabled_toon_edge
            mmd_mat.edge_color = i.edge_color
            mmd_mat.edge_weight = i.edge_size
            mmd_mat.sphere_texture_type = str(i.sphere_texture_mode)
            if i.is_shared_toon_texture:
                mmd_mat.is_shared_toon_texture = True
                mmd_mat.shared_toon_texture = i.toon_texture
            else:
                mmd_mat.is_shared_toon_texture = False
                if i.toon_texture >= 0:
                    mmd_mat.toon_texture = self.__textureTable[i.toon_texture]
                else:
                    mmd_mat.toon_texture = ''
            mmd_mat.comment = i.comment

            self.__materialFaceCountTable.append(int(i.vertex_count/3))
            self.__meshObj.data.materials.append(mat)
            fnMat = FnMaterial(mat)
            if i.texture != -1:
                texture_slot = fnMat.create_texture(self.__textureTable[i.texture])
                texture_slot.texture.use_mipmap = self.__use_mipmap
                self.__imageTable[len(self.__materialTable)-1] = texture_slot.texture.image
            if i.sphere_texture_mode == 2:
                amount = self.__spa_blend_factor
            else:
                amount = self.__sph_blend_factor
            if i.sphere_texture != -1 and amount != 0.0:
                texture_slot = fnMat.create_sphere_texture(self.__textureTable[i.sphere_texture])
                texture_slot.diffuse_color_factor = amount
                if i.sphere_texture_mode == 3 and getattr(pmxModel.header, 'additional_uvs', 0):
                    texture_slot.uv_layer = 'UV1' # for SubTexture
                    mmd_mat.sphere_texture_type = mmd_mat.sphere_texture_type # re-update
Beispiel #2
0
    def draw(self, context):
        material = context.active_object.active_material
        mmd_material = material.mmd_material

        layout = self.layout

        fnMat = FnMaterial(material)

        col = layout.column()
        col.label(text='Texture:')
        r = col.row(align=True)
        tex = fnMat.get_texture()
        if tex:
            if tex.type == 'IMAGE' and tex.image:
                r.prop(tex.image, 'filepath', text='')
                r.operator('mmd_tools.material_remove_texture',
                           text='',
                           icon='PANEL_CLOSE')
            else:
                r.operator('mmd_tools.material_remove_texture',
                           text='Remove',
                           icon='PANEL_CLOSE')
                r.label(icon='ERROR')
        else:
            r.operator('mmd_tools.material_open_texture',
                       text='Add',
                       icon=ICON_FILE_FOLDER)

        col = layout.column()
        col.label(text='Sphere Texture:')
        r = col.row(align=True)
        tex = fnMat.get_sphere_texture()
        if tex:
            if tex.type == 'IMAGE' and tex.image:
                r.prop(tex.image, 'filepath', text='')
                r.operator('mmd_tools.material_remove_sphere_texture',
                           text='',
                           icon='PANEL_CLOSE')
            else:
                r.operator('mmd_tools.material_remove_sphere_texture',
                           text='Remove',
                           icon='PANEL_CLOSE')
                r.label(icon='ERROR')
        else:
            r.operator('mmd_tools.material_open_sphere_texture',
                       text='Add',
                       icon=ICON_FILE_FOLDER)
        col.row(align=True).prop(mmd_material,
                                 'sphere_texture_type',
                                 expand=True)

        col = layout.column()
        row = col.row()
        row.prop(mmd_material, 'is_shared_toon_texture')
        r = row.row()
        r.active = mmd_material.is_shared_toon_texture
        r.prop(mmd_material, 'shared_toon_texture')
        r = col.row()
        r.active = not mmd_material.is_shared_toon_texture
        r.prop(mmd_material, 'toon_texture')
Beispiel #3
0
def _set_material(prop, value):
    if value not in bpy.data.materials.keys():
        prop['material_id'] = -1
        return
    mat = bpy.data.materials[value]
    fnMat = FnMaterial(mat)
    prop['material_id'] = fnMat.material_id
Beispiel #4
0
def _toggleUseSphereTexture(self, context):
    root = self.id_data
    rig = mmd_model.Model(root)
    use_sphere = self.use_sphere_texture
    for i in rig.meshes():
        for m in i.data.materials:
            if m is None:
                continue
            FnMaterial(m).use_sphere_texture(use_sphere, i)
    def draw(self, context):
        material = context.active_object.active_material
        mmd_material = material.mmd_material

        layout = self.layout

        fnMat = FnMaterial(material)

        col = layout.column(align=True)
        row = col.row(align=True)
        row.label('Texture:')
        r = row.column(align=True)
        tex = fnMat.get_texture()
        if tex:
            if tex.type == 'IMAGE' and tex.image:
                r2 = r.row(align=True)
                r2.prop(tex.image, 'filepath', text='')
                r2.operator('mmd_tools.material_remove_texture', text='', icon='PANEL_CLOSE')
            else:
                r.operator('mmd_tools.material_remove_texture', text='Remove', icon='PANEL_CLOSE')
                col.label('Texture is invalid.', icon='ERROR')
        else:
            r.operator('mmd_tools.material_open_texture', text='Add', icon='FILESEL')

        col = layout.column(align=True)
        row = col.row(align=True)
        row.label('Sphere Texture:')
        r = row.column(align=True)
        tex = fnMat.get_sphere_texture()
        if tex:
            if tex.type == 'IMAGE' and tex.image:
                r2 = r.row(align=True)
                r2.prop(tex.image, 'filepath', text='')
                r2.operator('mmd_tools.material_remove_sphere_texture', text='', icon='PANEL_CLOSE')
            else:
                r.operator('mmd_tools.material_remove_sphere_texture', text='Remove', icon='PANEL_CLOSE')
                col.label('Sphere Texture is invalid.', icon='ERROR')
        else:
            r.operator('mmd_tools.material_open_sphere_texture', text='Add', icon='FILESEL')
        r = col.row(align=True)
        r.prop(mmd_material, 'sphere_texture_type')

        col = layout.column(align=True)
        c = col.column()
        r = c.row()
        r.prop(mmd_material, 'is_shared_toon_texture')
        if mmd_material.is_shared_toon_texture:
            r.prop(mmd_material, 'shared_toon_texture')
        else:
            r = c.row()
            r.prop(mmd_material, 'toon_texture')
Beispiel #6
0
def _updateShininess(prop, context):
    FnMaterial(prop.id_data).update_shininess()
Beispiel #7
0
def _updateEdgeColor(prop, context):
    FnMaterial(prop.id_data).update_edge_color()
Beispiel #8
0
def _updateEdgeWeight(prop, context):
    FnMaterial(prop.id_data).update_edge_weight()
Beispiel #9
0
def _updateSelfShadow(prop, context):
    FnMaterial(prop.id_data).update_self_shadow()
Beispiel #10
0
def _updateEnabledToonEdge(prop, context):
    FnMaterial(prop.id_data).update_enabled_toon_edge()
Beispiel #11
0
def _updateToonTexture(prop, context):
    FnMaterial(prop.id_data).update_toon_texture()
Beispiel #12
0
def _updateDropShadow(prop, context):
    FnMaterial(prop.id_data).update_drop_shadow()
Beispiel #13
0
def _updateSphereMapType(prop, context):
    FnMaterial(prop.id_data).update_sphere_texture_type(context.active_object)
Beispiel #14
0
def _updateSphereMapType(prop, context):
    FnMaterial(prop.id_data).update_sphere_texture_type()
 def execute(self, context):
     mat = context.active_object.active_material
     fnMat = FnMaterial(mat)
     fnMat.create_sphere_texture(self.filepath)
     return {'FINISHED'}
Beispiel #16
0
def _updateSpecularColor(prop, context):
    FnMaterial(prop.id_data).update_specular_color()
Beispiel #17
0
def _updateAlpha(prop, context):
    FnMaterial(prop.id_data).update_alpha()
Beispiel #18
0
def _updateDiffuseColor(prop, context):
    FnMaterial(prop.id_data).update_diffuse_color()
Beispiel #19
0
def _updateAmbientColor(prop, context):
    FnMaterial(prop.id_data).update_ambient_color()
 def execute(self, context):
     mat = context.active_object.active_material
     fnMat = FnMaterial(mat)
     fnMat.remove_sphere_texture()
     return {'FINISHED'}
Beispiel #21
0
def _updateIsDoubleSided(prop, context):
    FnMaterial(prop.id_data).update_is_double_sided()