Material Folder Importer

As i just got myself a massive library of materials/textures, i finally got around to code a little addon for easing the whole importing of these. May i introduce

import_material_folder.py

image

This little addon looks through all subfolders of the given folder and generates material assets. It searches for commonly used key words in texture file names like for example “diffuse”, “basemap” or “albedo” for albedo maps.

Demo Video

If it doesn’t recognize your files, you can easily extend the existing keywords yourself in the addon settings:

Image

Some features:

  • Marks materials directly as assets so they can be browsed in blenders asset browser.
  • Optionally adds up to 3 user defined tags to all imported material assets.
  • Optionally can add converter nodes for DirectX style normal maps (doesn’t recognize those itself though!)
  • Adds a custom thumbnail image if it finds one, otherwise lets blender generate one.
  • Keywords can be defined by the user, saved and loaded.
  • Can be set to ignore upper/lowercase. If activated, “_AmbientOcclusion” and “_ambientocclusion” are treated as the same.

Download Version 0.41

Warning: Folders with several dozens of files will take quite a while to import, up to several minutes.

8 Likes

Woaaaw very good idea! Thks a lot Guy, Congrats.

Agreed – very nice script!

I’ve been going through my textures folder and adding all the name variations to the arrays.

It’s motivated me to finally make asset libraries out of all these loose PBRs! :+1:

1 Like

Yea, exactly that was my motivation for the script. We have this nice asset browser now right in blender, we should really use it. But putting those in by hand is at best a horrible chore that the computer should do for us.

Care to share your variations? Maybe they are worth including as default.

Sure! I’ve still got 2/3 of the folders to go through, but when I’ve completed the list, I’ll post the updated .py here.

More File Names

I won’t have time to play with the code for a while, but rather than leave this thread hanging, I went through my folders and these are the additional names I’ve found.

First, an expanded list of file types:

file_types = [".jpg", ".jpeg", ".png", ".tga", ".tif", ".tiff"]

Maybe include “.exr” as well, since that format seems to be gaining popularity for 16 bit roughness and displacement maps.

And I found a TON of suffixes. Some redundancies, but I’ve included them all in lowercase, title case, and uppercase:

  "ao": [
    "_ao", "_AO", "ambientocclusion", "AmbientOcclusion", "ambientOcclusion", "Ambient_Occlusion"
    "ambient_occlusion",
    "Ambient_Occlusion",
    "ambientocclusion",
    "ambientOcclusion",
    "Ambientocclusion",
    "AmbientOcclusion",
    "ao",
    "AO",
    "occ",
    "Occ",
    "OCC",
  ],

  "diffuse": [
    "_diffuse", "basemap", "albedo", "Albedo", "_alb", "Base_Color", "basecolor"
    "alb",
    "Alb",
    "ALB",
    "albedo",
    "Albedo",
    "ALBEDO",
    "base_color",
    "Base_Color",
    "BASE_COLOR",
    "basecolor",
    "baseColor",
    "Basecolor",
    "BaseColor",
    "BASECOLOR",
    "col",
    "Col",
    "COL",
    "color",
    "Color",
    "COLOR",
    "dif",
    "Dif",
    "DIF",
    "DIF",
    "diff",
    "Diff",
    "DIFF",
  ],

  "roughness": [
    "_roughness", "_rgh", "Roughness"
    "rgh",
    "Rgh",
    "RGH",
    "rou",
    "Rou",
    "ROU",
    "rough",
    "Rough",
    "ROUGH",
    "roughness",
    "Roughness",
    "ROUGHNESS",
    "gloss",
    "Gloss",
    "GLOSS",
    "glossiness",
    "Glossiness",
  ],

  "normal": [
    "_nrm", "_normal", "_Normal", "NormalMap", "normalmap"
    "nor",
    "Nor",
    "NOR",
    "norm",
    "Norm",
    "NORM",
    "normal",
    "Normal",
    "NORMAL",
    "nrm",
    "Nrm",
    "NRM",
  ],

  "height": [
    "_height", "_Height", "HeightMap", "heightmap"
    "dis",
    "Dis",
    "DIS",
    "disp",
    "Disp",
    "DISP",
    "displacement",
    "Displacement",
    "dsp",
    "Dsp",
    "DSP",
    "height",
    "Height",
    "HEIGHT",
  ],

  "thumbnail": [
    "_render", "thumbnail", "Thumbnail"
  ],

  "reflection": [
    "_reflection", "_ref", "Reflection"
    "ref",
    "Ref",
    "REF",
    "refl",
    "Refl",
    "REFL",
    "reflection",
    "Reflection",
    "REFLECTION",
  ],

  "metal": [
    "_met", "metalness", "Metalness"
    "metallic",
    "Metallic",
    "METALLIC",
    "mtl",
    "Mtl",
    "MTL",
  ],

  "emission": [
    "_emi", "Emission", "emissive"
    "emissive",
    "Emissive",
    "EMISSIVE",
  ],

And some additional map types:

  "bump": [
    "bmp",
    "Bmp",
    "BMP",
    "bump",
    "Bump",
    "BUMP",
  ],

  "opacity": [
    "opacity",
    "Opacity",
    "OPACITY",
  ],

  "specular": [
    "spec",
    "Spec",
    "SPEC",
    "specular",
    "Specular",
    "SPECULAR",
  ],

? - Optimizing the List

Some of the suffixes went long with particulars like “normal0gx”, but I presume the test recognizes fragments, and that “normal” is enough for a positive match, so I went with the viable minimum.

If I’m correct about fragment matches returning a positive, then it suggests the lists can be much shorter. For instance, Ambient Occlusion would only need “ao” and “occ”.

Or maybe “_ao” and “_occ”, to make sure file names like “maori_tattoo.png” aren’t misinterpreted as AO files. Although not all my files use underscores; some use a dash, some use a space.

? - Test Using .lower()

Including all the possible capitalization variations makes the list extra long, so it might be cool to do what Node Wrangler does and limit the list to lowercase names, and apply .lower to the file name before testing.

To wit:

if self.hotkey_list_filter.lower() in hotkey_name.lower():
1 Like

Small update, now you can set the keywords in the addon’s preferences:

Image

I’m not sure i got it all totally correctly, so pls let me know if you run into issues!

And I found a TON of suffixes

Wow, that’s imprevssive… and taunting :slight_smile: I guess it’s like impossible to check every possible case, hence i’m tending more towards providing roughly adequate defaults and additionally giving the user the ability to customize those accordingly.

First, an expanded list of file types:

I probably will add those as another addon pref setting

Test Using .lower()

Might make this into another setting.

I have some other Todos anways, like checking for existing materials and so on. But for the time being i need some beer, cheers! :slight_smile:

1 Like

Lol! Yeah, it’s a lot of names. I don’t include all these when I modify Node Wrangler, but I figured I’d give you the full menu and you can pick and choose your tapas.

I’m looking forward to seeing what you do with opening prefs to user tweaking. I haven’t dug into that myself, but I’ve had one or two folks asking me to incorporate it, so it’s on my list.

I pulled v0.3.0 – nice bit of refactoring!

I see you added a BOOL for search using lowercase names. That will be useful once it’s hooked up.

The LOAD KEYWORDS button in prefs didn’t do anything for me (3.31 on OSX). Should it do something, or is it still in-progress?

Why I added keywords but still can’t add thumbnails and basic colors??Maybe a blend node should be added after the AO!!By the way, I have to say that this is a very useful plugin!


When I restart blender after changing the keywords, the basecolu can be connected correctly, but the thumbnail still cannot be created correctly, it seems that it can only create the thumbnail of the last asset.

It’s wip. Had some personal problems last week, so couldn’t get anything done.

Made a little update that lets you define file types:

1 Like

Interesting. I’ll take a look what’s happening over there. Thanks!

Ni-i-ice! :mechanical_arm:

Ver. 0.41 released. Now with ignore upper/lowercase option!

@chen-pan Your problem arose from the trailing comma in the diffuse line:

image

I fixed this for the new version, shouldn’t be an issue now.

1 Like

Oh yea, the “Load Keywords” button only restores keywords saved using “Save Keywords”. The issue is that custom keywords are disposed when you update the script. I don’t really know how to fix that for now, so this is a workaround. Simply save your keywords everytime you change them, so you can load them in case they are set to the defaults.

very nice , you are going to add opacity or alpha?

Could do, i’ll check what i can do. Alpha is usually the alpha channel in the albedo tex, no? This might be tricky… Maybe i’ll add various options to import.

If you have any ideas about that, let me know.

1 Like

must of the time i found it in a separated file namedas _opacity, same for displacement or high for bump