# Assets so the zone name signs match the fence: one baked board face of Fence_Warm_Cedar_Subtle # (vertical + horizontal grain) and two of the fence's snow pieces (post cap, rail snow). # Run: blender -b map_refined_benches.blend --python export_sign_assets.py import bpy, bmesh, os from mathutils import Vector, Matrix OUT = os.path.join(os.path.dirname(bpy.data.filepath), "roblox", "sign") os.makedirs(OUT, exist_ok=True) sc = bpy.context.scene sc.render.engine = "CYCLES"; sc.cycles.samples = 4; sc.cycles.device = "CPU" sc.render.bake.use_pass_direct = False; sc.render.bake.use_pass_indirect = False sc.render.bake.use_pass_color = True; sc.render.bake.margin = 4 wood = bpy.data.materials["Fence_Warm_Cedar_Subtle"] def bake_face(name, w, h, rotate): """Plane whose UVMap is 0..1 (like each fence face). rotate=True turns the grain 90 degrees.""" bm = bmesh.new() vs = [bm.verts.new(v) for v in ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0))] f = bm.faces.new(vs) uvl = bm.loops.layers.uv.new("UVMap") bake = bm.loops.layers.uv.new("BakeUV") for lp, (x, y) in zip(f.loops, ((0, 0), (1, 0), (1, 1), (0, 1))): lp[uvl].uv = (y, x) if rotate else (x, y) lp[bake].uv = (x, y) me = bpy.data.meshes.new(name); bm.to_mesh(me); bm.free() me.uv_layers["UVMap"].active_render = True me.uv_layers.active = me.uv_layers["BakeUV"] ob = bpy.data.objects.new(name, me); sc.collection.objects.link(ob) img = bpy.data.images.new(name, w, h, alpha=False) mat = wood.copy(); me.materials.append(mat) tex = mat.node_tree.nodes.new("ShaderNodeTexImage"); tex.image = img; mat.node_tree.nodes.active = tex bpy.ops.object.select_all(action="DESELECT"); ob.select_set(True); bpy.context.view_layer.objects.active = ob bpy.ops.object.bake(type="DIFFUSE", pass_filter={"COLOR"}, use_clear=True) img.filepath_raw = os.path.join(OUT, name + ".png"); img.file_format = "PNG"; img.save() bake_face("SignWood_Vertical", 256, 1024, rotate=False) # grain runs along image height (posts) bake_face("SignWood_Horizontal", 1024, 256, rotate=True) # grain runs along image width (rails) def export_piece(src_name, out_name): src = bpy.data.objects[src_name] dg = bpy.context.evaluated_depsgraph_get() me = bpy.data.meshes.new_from_object(src.evaluated_get(dg)) me.transform(src.matrix_world) cs = [v.co for v in me.vertices] lo = Vector((min(c.x for c in cs), min(c.y for c in cs), min(c.z for c in cs))) hi = Vector((max(c.x for c in cs), max(c.y for c in cs), max(c.z for c in cs))) me.transform(Matrix.Translation(-(lo + hi) / 2)) for p in me.polygons: p.use_smooth = True ob = bpy.data.objects.new(out_name, me); sc.collection.objects.link(ob) bpy.ops.object.select_all(action="DESELECT"); ob.select_set(True); bpy.context.view_layer.objects.active = ob bpy.ops.export_scene.gltf(filepath=os.path.join(OUT, out_name + ".glb"), export_format="GLB", use_selection=True, export_yup=True) print("PIECE", out_name, [round(v, 3) for v in (hi - lo)], len(me.polygons)) export_piece("Snow_Drape_000", "SignSnow_PostCap") export_piece("Snow_Soft_0036", "SignSnow_Rail") print("DONE")