"""Surfaces of the nutrition vat, headless, in place: blender.exe -b ../NutritionVat.blend --python nv_surfaces.py [-- --nobake] The nutrition feeder's recipe (models/nutrition-feeder/build/nf_surfaces.py), for the user's rule "realistic with good textures" from the first version: * tiling sets from the user's own Season 2 pack (already in the Unreal project), read in place by relative path from models/vessel-interior/textures/ModSci_Engineer/Textures: ScratchedMetal under the paints, BrushedMetal for the chrome handles and the brass lever, Glass_DirtRough as a smudge mask, T_Scratch_Norm for fine scratches on metal; * one map baked from the model in Cycles into a shared atlas, textures/T_NV_Masks.png (R occlusion, G edges, B crevices): shade in the grooves, almost no wear (the ship is clean); * drawn textures (nv_textures.py): T_NV_Decals (side label, warning sticker, keypad digits), T_NV_CanLabel (the canister's wrap), T_NV_Bubbles (the liquid), T_NV_Perforation (the grille). Colours after the picture: a pale sage paint, cyan light, a dark teal liquid with bright bubbles, black rubber ports, bright metal handles. UV layers (order matters for Unreal): UVMap (UV0) unique unwrap inside the mesh's square of the atlas; decals take their atlas, the canister's glass its wrap, the liquid a cylinder (round, up) UV_Tile (UV1) metres, box-projected, for the tiling sets """ import bpy, bmesh, math, os, sys, time, json import numpy as np from mathutils import Vector HERE = os.path.dirname(os.path.abspath(__file__)) FOLDER = os.path.dirname(HERE) exec(open(os.path.join(HERE, "nv_lib.py")).read()) TEX = os.path.join(FOLDER, "textures") PACK = os.path.normpath(os.path.join(FOLDER, "..", "vessel-interior", "textures", "ModSci_Engineer", "Textures")) SCR = ("Base/ScratchedMetal/T_ScratchedMetal_Diff.png", "Base/ScratchedMetal/T_ScratchedMetal_Rough.png", "Base/ScratchedMetal/T_ScratchedMetal_Normal.png") BRU = ("Base/BrushedMetal/T_BrushedMetal_Diff.png", "Base/BrushedMetal/T_BrushedMetal_Rough.png", "Base/BrushedMetal/T_BrushedMetal_Normal.png") DIRT = "Base/Glass/T_Glass_DirtRough.png" SCRATCH_N = "Base/Glass/T_Scratch_Norm.png" ATLAS_SIZE = 4096 ATLAS_RECT = {"SM_NutritionVat_Body": (0.0, 0.0, 0.875), "SM_NutritionVat_Canister": (0.875, 0.0, 0.125), "SM_NutritionVat_Hoses": (0.875, 0.125, 0.125)} EDGE_R = 0.003 OWN_UV = {"M_NV_Decal", "M_NV_CanGlass", "M_NV_Fluid"} # faces with their own UVs, not in the atlas unwrap NOBAKE = {"M_NV_Decal", "M_NV_CanGlass", "M_NV_Fluid", "M_NV_Glass", "M_NV_Glow"} PAINT = dict(set=SCR, metal=0.0, tile=0.60, shade=(0.97, 1.02), rough=(0.40, 0.30), normal=0.10, dirt=0.03, dirt_tile=1.4, grime=0.18) SURF = { "M_NV_Shell": dict(PAINT, tint=(0.34, 0.48, 0.42)), "M_NV_ShellDark": dict(PAINT, tint=(0.11, 0.145, 0.13), rough=(0.50, 0.40)), "M_NV_Gap": dict(set=(None, SCR[1], None), tint=(0.010, 0.012, 0.012), metal=0.0, tile=0.40, shade=(1.0, 1.0), rough=(0.70, 0.55), normal=0.0, dirt=0.0, dirt_tile=1.0, grime=0.0), "M_NV_Rubber": dict(PAINT, tint=(0.012, 0.014, 0.014), rough=(0.34, 0.24), grime=0.10, normal=0.05), "M_NV_Hose": dict(PAINT, tint=(0.010, 0.011, 0.012), rough=(0.38, 0.26), grime=0.0, normal=0.04), "M_NV_Keypad": dict(PAINT, tint=(0.018, 0.020, 0.022), rough=(0.62, 0.50), grime=0.10), "M_NV_Chrome": dict(set=BRU, tint=(0.82, 0.84, 0.86), metal=1.0, tile=0.15, shade=(0.96, 1.03), rough=(0.14, 0.22), normal=0.25, normal_map=SCRATCH_N, dirt=0.03, dirt_tile=0.6, grime=0.10), "M_NV_Brass": dict(set=BRU, tint=(0.78, 0.56, 0.22), metal=1.0, tile=0.10, shade=(0.95, 1.04), rough=(0.26, 0.36), normal=0.2, normal_map=SCRATCH_N, dirt=0.03, dirt_tile=0.6, grime=0.10), } GLOW = {"M_NV_Glow": ((0.0, 0.85, 1.0), 6.0)} OBJECTS = ["SM_NutritionVat_Body", "SM_NutritionVat_Canister", "SM_NutritionVat_Hoses"] def mesh_of(name): ob = bpy.data.objects.get(name) if ob is not None: return ob for o in bpy.data.objects: # objects named otherwise (the canister's two) if o.data is not None and o.data.name == name: return o raise KeyError(name) # ------------------------------------------------------------------ UV layers def uv_tile_layer(me): uv = me.uv_layers.get("UV_Tile") or me.uv_layers.new(name="UV_Tile") co = np.zeros(len(me.vertices) * 3, np.float32) me.vertices.foreach_get("co", co) co = co.reshape(-1, 3) out = np.zeros((len(me.loops), 2), np.float32) for p in me.polygons: n = p.normal ax = 0 if abs(n.x) >= abs(n.y) and abs(n.x) >= abs(n.z) else (1 if abs(n.y) >= abs(n.z) else 2) for li in range(p.loop_start, p.loop_start + p.loop_total): c = co[me.loops[li].vertex_index] out[li] = (c[1], c[2]) if ax == 0 else ((c[0], c[2]) if ax == 1 else (c[0], c[1])) uv.data.foreach_set("uv", out.ravel()) def ensure_layers(me): keep = {} for l in me.uv_layers: a = np.zeros(len(me.loops) * 2, np.float32) l.data.foreach_get("uv", a) keep[l.name] = a while len(me.uv_layers): me.uv_layers.remove(me.uv_layers[0]) for nm in ("UVMap", "UV_Tile"): me.uv_layers.new(name=nm).data.foreach_set("uv", keep.get(nm, np.zeros(len(me.loops) * 2, np.float32))) me.uv_layers.active = me.uv_layers["UVMap"] me.uv_layers["UVMap"].active_render = True def cyl_uv(me, poly_ids, axis_xy, z0, z1, u_shift=0.0): """round-the-axis UVs for these faces (local coords): u = angle / 2 pi (0 at +x, the seam at -x), v up""" a = np.zeros(len(me.loops) * 2, np.float32) me.uv_layers["UVMap"].data.foreach_get("uv", a) a = a.reshape(-1, 2) cx, cy = axis_xy for pi in poly_ids: p = me.polygons[pi] lis = list(range(p.loop_start, p.loop_start + p.loop_total)) us = [] for li in lis: c = me.vertices[me.loops[li].vertex_index].co us.append(math.atan2(c.y - cy, c.x - cx) / (2 * math.pi) + u_shift) if max(us) - min(us) > 0.5: us = [u + 1.0 if u < 0 else u for u in us] for li, u in zip(lis, us): c = me.vertices[me.loops[li].vertex_index].co a[li] = (u, (c.z - z0) / (z1 - z0)) me.uv_layers["UVMap"].data.foreach_set("uv", a.ravel()) def uv_atlas_layer(ob, rect): me = ob.data ensure_layers(me) names = [m.name for m in me.materials] own = {i for i, n in enumerate(names) if n in OWN_UV} vl = bpy.context.view_layer for o in vl.objects: o.select_set(False) ob.hide_set(False) ob.select_set(True) vl.objects.active = ob for p in me.polygons: p.select = p.material_index not in own bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_mode(type='FACE') x0, y0, s = rect margin = 6.0 / (s * ATLAS_SIZE) bpy.ops.uv.smart_project(angle_limit=math.radians(55), island_margin=margin, area_weight=0.0, correct_aspect=True, scale_to_bounds=False) bpy.ops.uv.select_all(action='SELECT') try: bpy.ops.uv.pack_islands(rotate=True, scale=True, margin_method='FRACTION', margin=margin, shape_method='CONCAVE') except Exception as ex: print("pack skipped", ob.name, ex) bpy.ops.object.mode_set(mode='OBJECT') a = np.zeros(len(me.loops) * 2, np.float32) me.uv_layers["UVMap"].data.foreach_get("uv", a) a = a.reshape(-1, 2) pad = 4.0 / (s * ATLAS_SIZE) sel = np.zeros(len(me.loops), bool) for p in me.polygons: if p.material_index not in own: sel[p.loop_start:p.loop_start + p.loop_total] = True a[sel] = np.array([x0, y0], np.float32) + (pad + np.clip(a[sel], 0, 1) * (1 - 2 * pad)) * s me.uv_layers["UVMap"].data.foreach_set("uv", a.ravel()) # decals: their atlas; the canister's glass: its wrap mw = ob.matrix_world if "M_NV_Decal" in names: di = names.index("M_NV_Decal") a = a.reshape(-1, 2) for p in me.polygons: if p.material_index != di: continue d = which_decal(mw @ p.center) for li in range(p.loop_start, p.loop_start + p.loop_total): a[li] = decal_uv(d, mw @ me.vertices[me.loops[li].vertex_index].co) me.uv_layers["UVMap"].data.foreach_set("uv", a.ravel()) if "M_NV_CanGlass" in names: ci = names.index("M_NV_CanGlass") ids = [p.index for p in me.polygons if p.material_index == ci] if ids: zs = [me.vertices[v].co.z for pi in ids for v in me.polygons[pi].vertices] cyl_uv(me, ids, (0.0, 0.0), min(zs), max(zs)) def uv_fluid(ob): me = ob.data ensure_layers(me) zs = [v.co.z for v in me.vertices] cyl_uv(me, [p.index for p in me.polygons], (0.0, 0.0), min(zs), max(zs)) uv_tile_layer(me) # ------------------------------------------------------------------ bake def use_gpu(): sc = bpy.context.scene sc.render.engine = 'CYCLES' try: prefs = bpy.context.preferences.addons['cycles'].preferences prefs.compute_device_type = 'HIP' prefs.get_devices() for d in prefs.devices: d.use = d.type == 'HIP' sc.cycles.device = 'GPU' return 'HIP' except Exception as ex: print("GPU not set:", ex) sc.cycles.device = 'CPU' return 'CPU' def bake_masks(parts): """parts: [(name, mesh)]. One emit bake of each mesh alone (occlusion counts only the mesh itself).""" t0 = time.time() kind = use_gpu() sc = bpy.context.scene N = ATLAS_SIZE for im in [i for i in bpy.data.images if i.name.startswith("T_NV_Masks")]: bpy.data.images.remove(im) masks = bpy.data.images.new("T_NV_Masks", N, N, alpha=False) masks.colorspace_settings.name = 'Non-Color' masks.pixels.foreach_set(np.tile(np.array((1.0, 0.0, 1.0, 1.0), np.float32), N * N)) mm = bpy.data.materials.new("_bake_masks") mm.use_nodes = True nt = mm.node_tree nt.nodes.clear() ao = nt.nodes.new('ShaderNodeAmbientOcclusion'); ao.samples = 24; ao.only_local = True; ao.inputs["Distance"].default_value = 0.15 cv = nt.nodes.new('ShaderNodeAmbientOcclusion'); cv.samples = 16; cv.only_local = True; cv.inputs["Distance"].default_value = 0.015 bv = nt.nodes.new('ShaderNodeBevel'); bv.samples = 8; bv.inputs["Radius"].default_value = EDGE_R geo = nt.nodes.new('ShaderNodeNewGeometry') dot = nt.nodes.new('ShaderNodeVectorMath'); dot.operation = 'DOT_PRODUCT' nt.links.new(bv.outputs["Normal"], dot.inputs[0]); nt.links.new(geo.outputs["Normal"], dot.inputs[1]) inv = nt.nodes.new('ShaderNodeMath'); inv.operation = 'SUBTRACT'; inv.inputs[0].default_value = 1.0 nt.links.new(dot.outputs["Value"], inv.inputs[1]) edg = nt.nodes.new('ShaderNodeMath'); edg.operation = 'MULTIPLY'; edg.inputs[1].default_value = 3.5; edg.use_clamp = True nt.links.new(inv.outputs[0], edg.inputs[0]) cc = nt.nodes.new('ShaderNodeCombineColor') nt.links.new(ao.outputs["AO"], cc.inputs[0]); nt.links.new(edg.outputs[0], cc.inputs[1]); nt.links.new(cv.outputs["AO"], cc.inputs[2]) em = nt.nodes.new('ShaderNodeEmission') nt.links.new(cc.outputs[0], em.inputs["Color"]) om = nt.nodes.new('ShaderNodeOutputMaterial') nt.links.new(em.outputs[0], om.inputs["Surface"]) ti = nt.nodes.new('ShaderNodeTexImage'); ti.image = masks nt.nodes.active = ti sc.cycles.samples = 24 sc.cycles.use_denoising = False sc.render.bake.margin = 6 sc.render.bake.use_clear = False for name, src in parts: me = src.copy() bm = bmesh.new() bm.from_mesh(me) names = [m.name for m in me.materials] bmesh.ops.delete(bm, geom=[f for f in bm.faces if names[f.material_index] in NOBAKE], context='FACES') for f in bm.faces: f.material_index = 0 bm.to_mesh(me) bm.free() me.materials.clear() me.materials.append(mm) me.uv_layers.active = me.uv_layers["UVMap"] me.uv_layers["UVMap"].active_render = True tmp = bpy.data.objects.new("_bake_" + name, me) sc.collection.objects.link(tmp) for o2 in bpy.context.view_layer.objects: o2.select_set(False) tmp.select_set(True) bpy.context.view_layer.objects.active = tmp try: bpy.ops.object.bake(type='EMIT', margin=6, use_clear=False) finally: bpy.data.objects.remove(tmp) bpy.data.meshes.remove(me) os.makedirs(TEX, exist_ok=True) masks.filepath_raw = os.path.join(TEX, "T_NV_Masks.png") masks.file_format = 'PNG' masks.save() masks.filepath = bpy.path.relpath(masks.filepath_raw) bpy.data.materials.remove(mm) return masks, dict(device=kind, seconds=round(time.time() - t0, 1), size=N) # ------------------------------------------------------------------ materials (node recipe from the feeder) def tex_image(path, colorspace="sRGB"): path = os.path.normpath(path) for im in bpy.data.images: if im.filepath and os.path.normpath(bpy.path.abspath(im.filepath)) == path: return im im = bpy.data.images.load(path) im.colorspace_settings.name = colorspace try: im.filepath = bpy.path.relpath(path) except Exception: pass return im _RANGE = {} def tex_range(im, lo=3, hi=97): if im.name not in _RANGE: n, ch = im.size[0] * im.size[1], im.channels px = np.empty(n * ch, np.float32) im.pixels.foreach_get(px) px = px.reshape(n, ch) if ch >= 3: c = px[:, :3] if im.colorspace_settings.name == 'sRGB': c = np.where(c <= 0.04045, c / 12.92, ((c + 0.055) / 1.055) ** 2.4) v = c @ np.array([0.2126, 0.7152, 0.0722], np.float32) else: v = px[:, 0] _RANGE[im.name] = (round(float(np.percentile(v, lo)), 4), round(float(np.percentile(v, hi)), 4)) return _RANGE[im.name] class Tree: def __init__(self, mat): mat.use_nodes = True self.nt = mat.node_tree self.nt.nodes.clear() def node(self, kind, label=None, **props): n = self.nt.nodes.new(kind) if label: n.label = label for k, v in props.items(): setattr(n, k, v) i = len(self.nt.nodes) - 1 n.location = (-2000 + 240 * (i // 4), 500 - 320 * (i % 4)) return n def link(self, a, b): self.nt.links.new(a, b) def put(self, sock, v): if isinstance(v, bpy.types.NodeSocket): self.nt.links.new(v, sock) else: sock.default_value = v def math(self, op, a, b=None, clamp=False, label=None): n = self.node('ShaderNodeMath', label, operation=op, use_clamp=clamp) self.put(n.inputs[0], a) if b is not None: self.put(n.inputs[1], b) return n.outputs[0] def ranged(self, v, lo, hi, label=None, f0=0.0, f1=1.0): n = self.node('ShaderNodeMapRange', label) self.put(n.inputs["Value"], v) n.inputs["From Min"].default_value = f0; n.inputs["From Max"].default_value = f1 n.inputs["To Min"].default_value = lo; n.inputs["To Max"].default_value = hi return n.outputs["Result"] def mixc(self, fac, a, b, label=None): n = self.node('ShaderNodeMix', label, data_type='RGBA') self.put(n.inputs[0], fac) self.put(n.inputs[6], a if isinstance(a, bpy.types.NodeSocket) else tuple(a) + (1.0,)) self.put(n.inputs[7], b if isinstance(b, bpy.types.NodeSocket) else tuple(b) + (1.0,)) return n.outputs[2] def uv(self, name): return self.node('ShaderNodeUVMap', uv_map=name).outputs["UV"] def mapped(self, src, scale, label=None): n = self.node('ShaderNodeMapping', label) self.nt.links.new(src, n.inputs["Vector"]) n.inputs["Scale"].default_value = scale if isinstance(scale, tuple) else (scale, scale, scale) return n.outputs["Vector"] def tex(self, im, vec, label=None): n = self.node('ShaderNodeTexImage', label, image=im) self.nt.links.new(vec, n.inputs["Vector"]) return n def bsdf(self): b = self.node('ShaderNodeBsdfPrincipled') out = self.node('ShaderNodeOutputMaterial') self.link(b.outputs[0], out.inputs["Surface"]) return b def dress(mat, r, masks=None): """a painted or bare metal surface: a tiling set + smudges; with the baked masks also shade in the grooves""" t = Tree(mat) b = t.bsdf() u0 = t.uv("UV_Tile") mp = t.mapped(u0, 1.0 / r["tile"], "one repeat = %.2f m" % r["tile"]) diff, rough, normal = r["set"] dirt = t.tex(tex_image(os.path.join(PACK, DIRT), "Non-Color"), t.mapped(u0, 1.0 / r["dirt_tile"]), "smudges and dust").outputs["Color"] ao = crev = None if masks is not None: sep = t.node('ShaderNodeSeparateColor') t.link(t.tex(masks, t.uv("UVMap"), "baked: R occlusion, G edges, B crevices").outputs["Color"], sep.inputs[0]) ao, crev = sep.outputs[0], sep.outputs[2] tint = tuple(r["tint"]) col = tint if diff: im = tex_image(os.path.join(PACK, diff)) lo, hi = tex_range(im) bw = t.node('ShaderNodeRGBToBW') t.link(t.tex(im, mp, "surface, diffuse").outputs["Color"], bw.inputs[0]) sh = t.ranged(bw.outputs[0], r["shade"][0], r["shade"][1], "shade the tint", lo, hi) vm = t.node('ShaderNodeVectorMath', "tint x shade", operation='SCALE') vm.inputs[0].default_value = tint t.link(sh, vm.inputs["Scale"]) col = vm.outputs["Vector"] grime = None if crev is not None and r["grime"] > 0: grime = t.math('MULTIPLY', t.math('POWER', t.math('SUBTRACT', 1.0, crev), 1.4), r["grime"], clamp=True, label="shade in crevices") col = t.mixc(grime, col, (0.02, 0.022, 0.021), "darken crevices") if ao is not None: col = t.mixc(t.ranged(ao, 0.25, 0.0, "occlusion", 0.0, 1.0), col, (0.004, 0.005, 0.005), "occlusion") rim = tex_image(os.path.join(PACK, rough), "Non-Color") rlo, rhi = tex_range(rim) ro = t.tex(rim, mp, "surface, roughness").outputs["Color"] rr = t.ranged(ro, r["rough"][0], r["rough"][1], "roughness range", rlo, rhi) rr = t.math('ADD', rr, t.math('MULTIPLY', dirt, r["dirt"]), clamp=True, label="smudges dull the sheen") if grime is not None: rr = t.math('ADD', rr, t.math('MULTIPLY', grime, 0.30), clamp=True, label="crevices are matte") t.put(b.inputs["Base Color"], col) t.put(b.inputs["Roughness"], rr) t.put(b.inputs["Metallic"], r["metal"]) nm_file = r.get("normal_map") or normal if nm_file and r["normal"] > 0: nd = t.node('ShaderNodeNormalMap', "fine relief", uv_map="UV_Tile") nd.inputs["Strength"].default_value = r["normal"] t.link(t.tex(tex_image(os.path.join(PACK, nm_file), "Non-Color"), mp, "surface, normal").outputs["Color"], nd.inputs["Color"]) t.link(nd.outputs["Normal"], b.inputs["Normal"]) mat.diffuse_color = tuple(r["tint"]) + (1.0,) mat.metallic = r["metal"] def dress_glow(mat, color, strength): t = Tree(mat) b = t.bsdf() b.inputs["Base Color"].default_value = (0.5, 0.9, 0.95, 1) b.inputs["Roughness"].default_value = 0.15 b.inputs["Emission Color"].default_value = tuple(color) + (1,) b.inputs["Emission Strength"].default_value = strength mat.diffuse_color = tuple(color) + (1.0,) def dress_glass(mat): t = Tree(mat) b = t.bsdf() b.inputs["Base Color"].default_value = (0.86, 0.97, 0.96, 1) b.inputs["Roughness"].default_value = 0.03 b.inputs["IOR"].default_value = 1.47 b.inputs["Transmission Weight"].default_value = 1.0 dirt = t.tex(tex_image(os.path.join(PACK, DIRT), "Non-Color"), t.mapped(t.uv("UV_Tile"), 1.6), "smudges").outputs["Color"] t.link(t.ranged(dirt, 0.02, 0.12, "smudges dull the glass"), b.inputs["Roughness"]) mat.diffuse_color = (0.6, 0.85, 0.9, 0.3) mat.blend_method = 'BLEND' if hasattr(mat, "blend_method") else None def dress_fluid(mat): """dark teal liquid, faintly lit from inside, bubbles bright (T_NV_Bubbles round the tank, two scales)""" t = Tree(mat) b = t.bsdf() b.inputs["Base Color"].default_value = (0.003, 0.035, 0.04, 1) b.inputs["Roughness"].default_value = 0.08 b.inputs["Transmission Weight"].default_value = 0.15 b.inputs["IOR"].default_value = 1.33 bub = tex_image(os.path.join(TEX, "T_NV_Bubbles.png"), "Non-Color") uv = t.uv("UVMap") b1 = t.tex(bub, t.mapped(uv, (1.0, 1.0, 1.0)), "bubbles").outputs["Color"] b2 = t.tex(bub, t.mapped(uv, (2.0, 1.7, 1.0)), "smaller bubbles").outputs["Color"] bb = t.math('MAXIMUM', b1, t.math('MULTIPLY', b2, 0.5)) sep = t.node('ShaderNodeSeparateXYZ') t.link(uv, sep.inputs[0]) height = t.ranged(sep.outputs["Y"], 0.6, 1.4, "lighter toward the lamp at the top") glow = t.math('ADD', t.math('MULTIPLY', bb, 1.6), t.math('MULTIPLY', height, 0.05)) t.link(glow, b.inputs["Emission Strength"]) b.inputs["Emission Color"].default_value = (0.02, 0.75, 0.8, 1) mat.diffuse_color = (0.02, 0.25, 0.24, 1) def dress_decal(mat): t = Tree(mat) b = t.bsdf() tx = t.tex(tex_image(os.path.join(TEX, "T_NV_Decals.png")), t.uv("UVMap"), "decals (nv_textures.py)") t.link(tx.outputs["Color"], b.inputs["Base Color"]) t.link(tx.outputs["Alpha"], b.inputs["Alpha"]) b.inputs["Roughness"].default_value = 0.45 mat.diffuse_color = (0.9, 0.9, 0.9, 1) def dress_canglass(mat): t = Tree(mat) b = t.bsdf() tx = t.tex(tex_image(os.path.join(TEX, "T_NV_CanLabel.png")), t.uv("UVMap"), "label wrap (nv_textures.py)") t.link(tx.outputs["Color"], b.inputs["Base Color"]) b.inputs["Roughness"].default_value = 0.35 b.inputs["Coat Weight"].default_value = 1.0 b.inputs["Coat Roughness"].default_value = 0.03 mat.diffuse_color = (0.5, 0.55, 0.52, 1) def dress_grille(mat): t = Tree(mat) b = t.bsdf() pf = t.tex(tex_image(os.path.join(TEX, "T_NV_Perforation.png"), "Non-Color"), t.mapped(t.uv("UV_Tile"), 1.0 / 0.004), "holes every 4 mm").outputs["Color"] t.link(t.mixc(pf, (0.0, 0.0, 0.0), (0.05, 0.06, 0.06)), b.inputs["Base Color"]) b.inputs["Roughness"].default_value = 0.5 mat.diffuse_color = (0.04, 0.05, 0.05, 1) def main(bake=True): rep = {} for n in OBJECTS: ob = mesh_of(n) uv_tile_layer(ob.data) uv_atlas_layer(ob, ATLAS_RECT[n]) uv_fluid(bpy.data.objects["SM_NutritionVat_Fluid"]) if bake: masks, info = bake_masks([(n, mesh_of(n).data) for n in OBJECTS]) rep["bake"] = info else: masks = bpy.data.images.get("T_NV_Masks") for name, r in SURF.items(): dress(bpy.data.materials[name], r, masks) for name, (c, s) in GLOW.items(): dress_glow(bpy.data.materials[name], c, s) dress_glass(bpy.data.materials["M_NV_Glass"]) dress_fluid(bpy.data.materials["M_NV_Fluid"]) dress_decal(bpy.data.materials["M_NV_Decal"]) dress_canglass(bpy.data.materials["M_NV_CanGlass"]) dress_grille(bpy.data.materials["M_NV_Grille"]) for im in bpy.data.images: if im.filepath and not im.filepath.startswith("//"): try: im.filepath = bpy.path.relpath(bpy.path.abspath(im.filepath)) except Exception: pass bpy.ops.wm.save_mainfile() print("SURFACES OK", json.dumps(rep)) if __name__ == "__main__": main(bake="--nobake" not in sys.argv)