def __importMaterials(self): self.__importTextures() pmxModel = self.__model self.__materialFaceCountTable = [] for i in pmxModel.materials: mat = bpy.data.materials.new(name=self.__safe_name(i.name, max_length=50)) self.__materialTable.append(mat) mmd_mat = mat.mmd_material 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
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[0:3] mat.specular_alpha = i.specular[3] mat.use_shadows = i.enabled_self_shadow mat.use_transparent_shadows = i.enabled_self_shadow mat.use_cast_buffer_shadows = i.enabled_self_shadow_map # only buffer shadows if hasattr(mat, 'use_cast_shadows'): # "use_cast_shadows" is not supported in older Blender (< 2.71), # so we still use "use_cast_buffer_shadows". mat.use_cast_shadows = i.enabled_self_shadow_map 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.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 if(len(i.edge_color)==4):# If it cames from PMD it will not # have edge color and assigning an empty array # will raise an error(ValueError) 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 if i.sphere_texture_mode == 2: amount = self.__spa_blend_factor blend = 'ADD' else: amount = self.__sph_blend_factor blend = 'MULTIPLY' if i.sphere_texture != -1 and amount != 0.0: texture_slot = fnMat.create_sphere_texture(self.__textureTable[i.sphere_texture]) if isinstance(texture_slot.texture.image, bpy.types.Image): texture_slot.texture.image.use_alpha = False texture_slot.diffuse_color_factor = amount texture_slot.blend_type = blend
def execute(self, context): mat = context.active_object.active_material fnMat = FnMaterial(mat) fnMat.create_texture(self.filepath) return {'FINISHED'}
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[0:3] mat.specular_alpha = i.specular[3] mat.use_shadows = i.enabled_self_shadow mat.use_transparent_shadows = i.enabled_self_shadow mat.use_cast_buffer_shadows = i.enabled_self_shadow_map # only buffer shadows if hasattr(mat, 'use_cast_shadows'): # "use_cast_shadows" is not supported in older Blender (< 2.71), # so we still use "use_cast_buffer_shadows". mat.use_cast_shadows = i.enabled_self_shadow_map 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.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 if (len(i.edge_color) == 4): # If it cames from PMD it will not # have edge color and assigning an empty array # will raise an error(ValueError) 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 if i.sphere_texture_mode == 2: amount = self.__spa_blend_factor blend = 'ADD' else: amount = self.__sph_blend_factor blend = 'MULTIPLY' if i.sphere_texture != -1 and amount != 0.0: texture_slot = fnMat.create_sphere_texture( self.__textureTable[i.sphere_texture]) if isinstance(texture_slot.texture.image, bpy.types.Image): texture_slot.texture.image.use_alpha = False texture_slot.diffuse_color_factor = amount texture_slot.blend_type = blend
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.use_nodes = True mat.diffuse_color = i.diffuse[0:4] mat.specular_color = i.specular[0:3] mat.specular_intensity = i.specular[3] mat.shadow_method = 'HASHED' mat.blend_method = 'HASHED' mat.use_screen_refraction = True #mat.use_shadows = i.enabled_self_shadow #mat.use_transparent_shadows = i.enabled_self_shadow #mat.use_cast_buffer_shadows = i.enabled_self_shadow_map # only buffer shadows #if hasattr(mat, 'use_cast_shadows'): # "use_cast_shadows" is not supported in older Blender (< 2.71), # so we still use "use_cast_buffer_shadows". #mat.use_cast_shadows = i.enabled_self_shadow_map #if mat.alpha < 1.0 or mat.specular_alpha < 1.0 or i.texture != -1: #mat.use_transparency = True #mat.transparency_method = 'Z_TRANSPARENCY' #fit for cycles mat.node_tree.links.clear() shader = mat.node_tree.nodes['Principled BSDF'] #texture = None outplug = shader.outputs[0] mat.node_tree.links.new(mat.node_tree.nodes['Material Output'].inputs['Surface'], outplug) mat.node_tree.nodes['Material Output'].location.x = shader.location.x + 500 mat.node_tree.nodes['Material Output'].location.y = shader.location.y - 150 mmd_mat.name_j = i.name mmd_mat.name_e = i.name_e mmd_mat.ambient_color = i.ambient 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 if(len(i.edge_color)==4):# If it cames from PMD it will not # have edge color and assigning an empty array # will raise an error(ValueError) 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: texnode = fnMat.create_texture(self.__textureTable[i.texture],shader) #texture_slot = fnMat.create_texture(self.__textureTable[i.texture]) #texture_slot.texture.use_mipmap = self.__use_mipmap mat.node_tree.links.new(shader.inputs['Base Color'], texnode.outputs['Color']) mat.node_tree.links.new(shader.inputs['Alpha'], texnode.outputs['Alpha']) '''