import bpy, os TEXROOT = os.path.expanduser("~/game_assets/unitypacks_extracted/sci_fi_hands/Assets/Sci_Fi_Hands/Textures") _CACHE = {} def _load(path, maxs, noncolor=False): if path in _CACHE: return _CACHE[path] img = bpy.data.images.load(path) if noncolor: img.colorspace_settings.name = "Non-Color" w, h = img.size if max(w, h) > maxs: f = maxs / max(w, h) img.scale(int(w*f), int(h*f)) _CACHE[path] = img return img def bind(): print("MATERIALS:", [m.name for m in bpy.data.materials]) for mat in bpy.data.materials: n = mat.name.lower() pref = "FPS_Sci_Fi_Hands_Details" if "detail" in n else ("Sci_Fi_Shield" if "shield" in n else "FPS_Sci_Fi_Hands") sub = os.path.join(TEXROOT, pref) if not os.path.isdir(sub): continue alb = os.path.join(sub, pref + "_Albedo_01.tga") nrm = os.path.join(sub, pref + "_Normals.tga") if not os.path.exists(alb): continue mat.use_nodes = True nt = mat.node_tree bsdf = next((x for x in nt.nodes if x.type == "BSDF_PRINCIPLED"), None) if not bsdf: continue timg = nt.nodes.new("ShaderNodeTexImage") timg.image = _load(alb, 1024) nt.links.new(timg.outputs["Color"], bsdf.inputs["Base Color"]) if os.path.exists(nrm): nimg = nt.nodes.new("ShaderNodeTexImage") nimg.image = _load(nrm, 512, noncolor=True) nmap = nt.nodes.new("ShaderNodeNormalMap") nt.links.new(nimg.outputs["Color"], nmap.inputs["Color"]) nt.links.new(nmap.outputs["Normal"], bsdf.inputs["Normal"]) print("BOUND", mat.name, "->", pref)