def load(folder_path: str = "resources/cctextures", used_assets: list = None, preload: bool = False, fill_used_empty_materials: bool = False, add_custom_properties: dict = None, use_all_materials: bool = False) -> List[Material]: """ This method loads all textures obtained from https://cc0textures.com, use the script (scripts/download_cc_textures.py) to download all the textures to your pc. All textures here support Physically based rendering (PBR), which makes the textures more realistic. All materials will have the custom property "is_cc_texture": True, which will make the selection later on easier. :param folder_path: The path to the downloaded cc0textures. :param used_assets: A list of all asset names, you want to use. The asset-name must not be typed in completely, only the beginning the name starts with. By default all assets will be loaded, specified by an empty list. :param preload: If set true, only the material names are loaded and not the complete material. :param fill_used_empty_materials: If set true, the preloaded materials, which are used are now loaded completely. :param add_custom_properties: A dictionary of materials and the respective properties. :param use_all_materials: If this is false only a selection of probably useful textures is used. This excludes \ some see through texture and non tileable texture. :return a list of all loaded materials, if preload is active these materials do not contain any textures yet and have to be filled before rendering (by calling this function again, no need to save the prior returned list) """ folder_path = Utility.resolve_path(folder_path) # this selected textures are probably useful for random selection probably_useful_texture = ["paving stones", "tiles", "wood", "fabric", "bricks", "metal", "wood floor", "ground", "rock", "concrete", "leather", "planks", "rocks", "gravel", "asphalt", "painted metal", "painted plaster", "marble", "carpet", "plastic", "roofing tiles", "bark", "metal plates", "wood siding", "terrazzo", "plaster", "paint", "corrugated steel", "painted wood", "lava" "cardboard", "clay", "diamond plate", "ice", "moss", "pipe", "candy", "chipboard", "rope", "sponge", "tactile paving", "paper", "cork", "wood chips"] if not use_all_materials and used_assets is None: used_assets = probably_useful_texture else: used_assets = [asset.lower() for asset in used_assets] if add_custom_properties is None: add_custom_properties = dict() if preload and fill_used_empty_materials: raise Exception("Preload and fill used empty materials can not be done at the same time, check config!") if os.path.exists(folder_path) and os.path.isdir(folder_path): materials = [] for asset in os.listdir(folder_path): if used_assets: skip_this_one = True for used_asset in used_assets: # lower is necessary here, as all used assets are made that that way if asset.lower().startswith(used_asset.replace(" ", "")): skip_this_one = False break if skip_this_one: continue current_path = os.path.join(folder_path, asset) if os.path.isdir(current_path): base_image_path = os.path.join(current_path, "{}_2K_Color.jpg".format(asset)) if not os.path.exists(base_image_path): continue # construct all image paths ambient_occlusion_image_path = base_image_path.replace("Color", "AmbientOcclusion") metallic_image_path = base_image_path.replace("Color", "Metalness") roughness_image_path = base_image_path.replace("Color", "Roughness") alpha_image_path = base_image_path.replace("Color", "Opacity") normal_image_path = base_image_path.replace("Color", "Normal") displacement_image_path = base_image_path.replace("Color", "Displacement") # if the material was already created it only has to be searched if fill_used_empty_materials: new_mat = MaterialLoaderUtility.find_cc_material_by_name(asset, add_custom_properties) else: new_mat = MaterialLoaderUtility.create_new_cc_material(asset, add_custom_properties) # if preload then the material is only created but not filled if preload: # Set alpha to 0 if the material has an alpha texture, so it can be detected e.q. in the material getter. nodes = new_mat.node_tree.nodes principled_bsdf = Utility.get_the_one_node_with_type(nodes, "BsdfPrincipled") principled_bsdf.inputs["Alpha"].default_value = 0 if os.path.exists(alpha_image_path) else 1 # add it here for the preload case materials.append(Material(new_mat)) continue elif fill_used_empty_materials and not MaterialLoaderUtility.is_material_used(new_mat): # now only the materials, which have been used should be filled continue # create material based on these image paths CCMaterialLoader.create_material(new_mat, base_image_path, ambient_occlusion_image_path, metallic_image_path, roughness_image_path, alpha_image_path, normal_image_path, displacement_image_path) materials.append(Material(new_mat)) return materials else: raise Exception("The folder path does not exist: {}".format(folder_path))
def load(folder_path: str = "resources/haven", used_assets: list = [], preload: bool = False, fill_used_empty_materials: bool = False, add_cp: dict = {}): """ Loads all specified haven textures from the given directory. :param folder_path: The path to the downloaded haven. :param used_assets: A list of all asset names, you want to use. The asset-name must not be typed in completely, only the beginning the name starts with. By default all assets will be loaded, specified by an empty list. :param preload: If set true, only the material names are loaded and not the complete material. :param fill_used_empty_materials: If set true, the preloaded materials, which are used are now loaded completely. :param add_cp: A dictionary of materials and the respective properties. """ # makes the integration of complex materials easier addon_utils.enable("node_wrangler") folder_path = Utility.resolve_path(folder_path) if preload and fill_used_empty_materials: raise Exception( "Preload and fill used empty materials can not be done at the same time, check config!" ) if os.path.exists(folder_path) and os.path.isdir(folder_path): for asset in os.listdir(folder_path): if used_assets: skip_this_one = True for used_asset in used_assets: if asset.startswith(used_asset): skip_this_one = False break if skip_this_one: continue current_path = os.path.join(folder_path, asset) if os.path.isdir(current_path): # find the current base_image_path by search for _diff_, this make it independent of the used res all_paths = glob.glob(os.path.join(current_path, "*.jpg")) base_image_path = "" for path in all_paths: if "_diff_" in path: base_image_path = path break if not os.path.exists(base_image_path): continue # if the material was already created it only has to be searched if fill_used_empty_materials: new_mat = MaterialLoaderUtility.find_cc_material_by_name( asset, add_cp) else: new_mat = MaterialLoaderUtility.create_new_cc_material( asset, add_cp) if preload: # if preload then the material is only created but not filled continue elif fill_used_empty_materials and not MaterialLoaderUtility.is_material_used( new_mat): # now only the materials, which have been used should be filled continue # construct all image paths # the images path contain the words named in this list, but some of them are differently # capitalized, e.g. Nor, NOR, NoR, ... used_elements = [ "ao", "spec", "rough", "nor", "disp", "bump", "alpha" ] final_paths = {} for ele in used_elements: new_path = base_image_path.replace("diff", ele).lower() found_path = "" for path in all_paths: if path.lower() == new_path: found_path = path break final_paths[ele] = found_path # create material based on these image paths HavenMaterialLoader.create_material( new_mat, base_image_path, final_paths["ao"], final_paths["spec"], final_paths["rough"], final_paths["alpha"], final_paths["nor"], final_paths["disp"], final_paths["bump"]) else: raise Exception( "The folder path does not exist: {}".format(folder_path))
def run(self): self._folder_path = Utility.resolve_path( self.config.get_string("folder_path", "resources/cctextures")) self._used_assets = self.config.get_list("used_assets", []) self._add_cp = self.config.get_raw_dict("add_custom_properties", {}) self._preload = self.config.get_bool("preload", False) self._fill_used_empty_materials = self.config.get_bool( "fill_used_empty_materials", False) if self._preload and self._fill_used_empty_materials: raise Exception( "Preload and fill used empty materials can not be done at the same time, check config!" ) if os.path.exists(self._folder_path) and os.path.isdir( self._folder_path): for asset in os.listdir(self._folder_path): if self._used_assets: skip_this_one = True for used_asset in self._used_assets: if asset.startswith(used_asset): skip_this_one = False break if skip_this_one: continue current_path = os.path.join(self._folder_path, asset) if os.path.isdir(current_path): base_image_path = os.path.join( current_path, "{}_2K_Color.jpg".format(asset)) if not os.path.exists(base_image_path): continue # if the material was already created it only has to be searched if self._fill_used_empty_materials: new_mat = MaterialLoaderUtility.find_cc_material_by_name( asset, self._add_cp) else: new_mat = MaterialLoaderUtility.create_new_cc_material( asset, self._add_cp) if self._preload: # if preload then the material is only created but not filled continue elif self._fill_used_empty_materials and not MaterialLoaderUtility.is_material_used( new_mat): # now only the materials, which have been used should be filled continue # construct all image paths ambient_occlusion_image_path = base_image_path.replace( "Color", "AmbientOcclusion") metallic_image_path = base_image_path.replace( "Color", "Metalness") roughness_image_path = base_image_path.replace( "Color", "Roughness") alpha_image_path = base_image_path.replace( "Color", "Opacity") normal_image_path = base_image_path.replace( "Color", "Normal") displacement_image_path = base_image_path.replace( "Color", "Displacement") # create material based on these image paths CCMaterialLoader.create_material( new_mat, base_image_path, ambient_occlusion_image_path, metallic_image_path, roughness_image_path, alpha_image_path, normal_image_path, displacement_image_path) else: raise Exception("The folder path does not exist: {}".format( self._folder_path))
def run(self): """ Load the materials """ self._folder_path = Utility.resolve_path( self.config.get_string("folder_path", "resources/haven")) self._used_assets = self.config.get_list("used_assets", []) self._add_cp = self.config.get_raw_dict("add_custom_properties", {}) self._preload = self.config.get_bool("preload", False) self._fill_used_empty_materials = self.config.get_bool( "fill_used_empty_materials", False) if self._preload and self._fill_used_empty_materials: raise Exception( "Preload and fill used empty materials can not be done at the same time, check config!" ) if os.path.exists(self._folder_path) and os.path.isdir( self._folder_path): for asset in os.listdir(self._folder_path): if self._used_assets: skip_this_one = True for used_asset in self._used_assets: if asset.startswith(used_asset): skip_this_one = False break if skip_this_one: continue current_path = os.path.join(self._folder_path, asset) if os.path.isdir(current_path): # find the current base_image_path by search for _diff_, this make it independent of the used res all_paths = glob.glob(os.path.join(current_path, "*.jpg")) base_image_path = "" for path in all_paths: if "_diff_" in path: base_image_path = path break if not os.path.exists(base_image_path): continue # if the material was already created it only has to be searched if self._fill_used_empty_materials: new_mat = MaterialLoaderUtility.find_cc_material_by_name( asset, self._add_cp) else: new_mat = MaterialLoaderUtility.create_new_cc_material( asset, self._add_cp) if self._preload: # if preload then the material is only created but not filled continue elif self._fill_used_empty_materials and not MaterialLoaderUtility.is_material_used( new_mat): # now only the materials, which have been used should be filled continue # construct all image paths # the images path contain the words named in this list, but some of them are differently # capitalized, e.g. Nor, NOR, NoR, ... used_elements = [ "ao", "spec", "rough", "nor", "disp", "bump", "alpha" ] final_paths = {} for ele in used_elements: new_path = base_image_path.replace("diff", ele).lower() found_path = "" for path in all_paths: if path.lower() == new_path: found_path = path break final_paths[ele] = found_path # create material based on these image paths HavenMaterialLoader.create_material( new_mat, base_image_path, final_paths["ao"], final_paths["spec"], final_paths["rough"], final_paths["alpha"], final_paths["nor"], final_paths["disp"], final_paths["bump"]) else: raise Exception("The folder path does not exist: {}".format( self._folder_path))