def GM_generate_previews(metals): previews = GM_preview_collections["tmp_material_all"] image_location = previews.images_location GM_enum_items = [] #path DB filepathdb = os.path.join(os.path.dirname(__file__), "materials" + os.sep) + "materials.ga" gaDB = open(filepathdb, "r") lines = gaDB.readlines() for i, line in enumerate(lines): q_name = line[0:4] if q_name == "NAME": q_name = line[5:-1] filepathIMG = os.path.join(image_location, q_name) thumb = previews.load(filepathIMG, filepathIMG, 'IMAGE') GM_enum_items.append((q_name, q_name, "", thumb.icon_id, i)) GM_enum_items.sort() return GM_enum_items
def generate_previews_tex(): previews = preview_collections_tex["pbr_textures"] image_location = previews.images_location enum_items = [] # Generate the thumbnails for i, image in enumerate(os.listdir(image_location)): filepath = os.path.join(image_location, image) thumb = previews.load(filepath, filepath, 'IMAGE') enum_items.append((image, image, "", thumb.icon_id, i)) enum_items.sort() return enum_items
def generate_previews(): previews = preview_collections["pbr_textures"] image_location = previews.images_location enum_items = [] # Generate the thumbnails for i, image in enumerate(os.listdir(image_location)): filepath = os.path.join(image_location, image) thumb = previews.load(filepath, filepath, 'IMAGE') enum_items.append((image, image, "", thumb.icon_id, i)) return enum_items
def generate_previews_nodes(metals): if metals: previews = preview_collections_nodes["pbr_materials_metals_node"] else: previews = preview_collections_nodes["pbr_materials_dielectrics_node"] image_location = previews.images_location enum_items = [] # Generate the thumbnails for i, image in enumerate(os.listdir(image_location)): filepath = os.path.join(image_location, image) thumb = previews.load(filepath, filepath, 'IMAGE') enum_items.append((image, image, "", thumb.icon_id, i)) enum_items.sort() return enum_items
def generate_previews(metals): if metals: previews = preview_collections["pbr_materials_metals_node"] else: previews = preview_collections["pbr_materials_dielectrics_node"] image_location = previews.images_location enum_items = [] # Generate the thumbnails for i, image in enumerate(os.listdir(image_location)): filepath = os.path.join(image_location, image) thumb = previews.load(filepath, filepath, "IMAGE") enum_items.append((image, image, "", thumb.icon_id, i)) return enum_items
def draw(self, context): settings = context.scene.pbr_material_settings layout = self.layout layout.enabled = settings.enabled col = layout.column(align=True) row = col.row() row.prop(settings, "category": "Learnbgame", # Preview row = col.row() if settings.category == 'm': row.template_icon_view(context.scene, "thumbs_mats_metals", show_labels=True) elif settings.category == 'd': row.template_icon_view(context.scene, "thumbs_mats_dielectrics", show_labels=True) row = col.row() row.operator('material.use_current_material') def generate_previews(metals): if metals: previews = preview_collections["pbr_materials_metals"] else: previews = preview_collections["pbr_materials_dielectrics"] image_location = previews.images_location enum_items = [] # Generate the thumbnails for i, image in enumerate(os.listdir(image_location)): filepath = os.path.join(image_location, image) thumb = previews.load(filepath, filepath, 'IMAGE') enum_items.append((image, image, "", thumb.icon_id, i)) return enum_items def add_nodes(node_name): o = bpy.context.active_object # If materials exist if o.data.materials: active_mat = o.active_material else: active_mat = bpy.data.materials.new(name="Material") o.data.materials.append(active_mat) active_mat.use_nodes = True active_mat.node_tree.nodes.clear() preview_type = active_mat.preview_render_type # Create nodes output = active_mat.node_tree.nodes.new("ShaderNodeOutputMaterial") group = active_mat.node_tree.nodes.new("ShaderNodeGroup") group.node_tree = bpy.data.node_groups[node_name] group.location = (-200, 0) # Link nodes active_mat.node_tree.links.new(group.outputs[0], output.inputs[0]) # Hack to refresh the preview active_mat.preview_render_type = preview_type def append_material(self, context): settings = context.scene.pbr_material_settings if settings.category == 'm': path = os.path.join(os.path.dirname(__file__), "blends" + os.sep + "metals.blend") elif settings.category == 'd': path = os.path.join(os.path.dirname(__file__), "blends" + os.sep + "dielectrics.blend") with bpy.data.libraries.load(path, False) as (data_from, data_to): if settings.category == 'm': node_name = context.scene.thumbs_mats_metals elif settings.category == 'd': node_name = context.scene.thumbs_mats_dielectrics if not node_name in bpy.data.node_groups: data_to.node_groups = [node_name] add_nodes(node_name) def register(): previews_mat_metals = bpy.utils.previews.new() previews_mat_metals.images_location = os.path.join(os.path.dirname(__file__), "thumbs" + os.sep + 'm') previews_mat_dielectrics = bpy.utils.previews.new() previews_mat_dielectrics.images_location = os.path.join(os.path.dirname(__file__), "thumbs" + os.sep + 'd') preview_collections['pbr_materials_metals'] = previews_mat_metals preview_collections['pbr_materials_dielectrics'] = previews_mat_dielectrics bpy.types.Scene.thumbs_mats_metals = bpy.props.EnumProperty( items=generate_previews(True), description="Choose the material you want to use", update=append_material, default='Gold' ) bpy.types.Scene.thumbs_mats_dielectrics = bpy.props.EnumProperty( items=generate_previews(False), description="Choose the material you want to use", update=append_material, default='Plastic' ) def unregister(): for preview in preview_collections.values(): bpy.utils.previews.remove(preview) preview_collections.clear() del bpy.types.Scene.thumbs_mats_metals del bpy.types.Scene.thumbs_mats_dielectrics