"""Re-import the farm machine FBX files and check what the game relies on: required parts and their pivots, footprint, tri budget, belt UV layout and materials. Blender space: Z up, front -Y. OLD holds the values measured from the models these replaced (bounds min/max, total tris), printed next to the new ones. Run: blender -b --factory-startup --python verify_gc_farm_machines.py -- [names]""" import bpy, json, os, sys ROOT = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..")) d = os.path.join(ROOT, "Assets", "Art", "Models") # name: (required part -> pivot, footprint half-extents (x, y) [third value: may overhang at the front / below the deck], old bounds, old tris) REQ = { "SM_Hopper": ({"Body": (0, 0, 0), "Mouth": (0, 0, 1.1)}, (1, 1), ((-0.72, -0.72, 0), (0.72, 0.72, 1.12)), 9667), "SM_WaterTank": ({"Body": (0, 0, 0), "Fill": (0, 0, 0.45)}, (1, 1), ((-0.9, -0.9, 0), (0.97, 0.99, 3.15)), 7730), "SM_Filler": ({"Body": (0, 0, 0), "Lamp": (-0.66, 0.2, 1.84), "Out": (-0.5, -0.98, 0.5)}, (1, 1), ((-0.95, -1, 0), (0.95, 1, 2.22)), 9788), "SM_Vaporizer": ({"Body": (0, 0, 0), "Lamp": (-0.71, -0.31, 1.13), "Out": (0.5, -0.98, 0.5), "Vent": (-0.2, 0.55, 2.86)}, (1, 1), ((-0.95, -1, 0), (0.95, 0.97, 3.03)), 9907), "SM_CryoPress": ({"Body": (0, 0, 0), "Lamp": (-0.7, 0.05, 2.55), "Out": (0.5, -0.98, 0.46), "Press": (0, 0, 1.24)}, (1, 1), ((-1, -1, 0), (1, 0.98, 2.67)), 10872), "SM_Pump": ({"Body": (0, 0, 0), "Rotor": (0, -1.62, -0.96)}, (0.5, 1, "edge"), ((-0.56, -2.18, -1.01), (0.56, 0.95, 1.33)), 8921), "SM_Belt": ({"Belt": (0, 0, 0), "Frame": (0, 0, 0), "EndIn": (0, 0, 0), "EndOut": (0, 0, 0)}, (0.515, 0.515), ((-0.5, -0.51, 0), (0.5, 0.51, 0.48)), 2328), "SM_BeltTurn": ({"Belt": (0, 0, 0), "Frame": (0, 0, 0), "EndIn": (0, 0, 0), "EndOut": (0, 0, 0)}, (0.515, 0.515), ((-0.51, -0.49, 0), (0.49, 0.51, 0.48)), 3744), "SM_BeltSorter": ({"Belt": (0, 0, 0), "Frame": (0, 0, 0), "EndIn": (0, 0, 0), "EndOut": (0, 0, 0), "Pusher": (-0.47, 0, 0.42), "Scanner": (0, 0, 0)}, (0.515, 0.515), ((-0.5, -0.51, 0), (0.5, 0.51, 1.15)), 4428), "SM_BeltSplitter": ({"Frame": (0, 0, 0), "EndIn": (0, 0, 0), "Lamp": (0, 0, 0), "Paddle": (0, -0.32, 0.35)}, (0.515, 0.515), ((-0.5, -0.51, 0), (0.5, 0.51, 0.77)), 3906), "SM_Launcher": ({"Body": (0, 0, 0), "Plate": (0, 0.46, 0.3)}, (0.515, 0.515), ((-0.51, -0.51, 0), (0.51, 0.51, 0.37)), 5560), "SM_DronePad": ({"Body": (0, 0, 0), "Lamp": (0.42, 0.42, 1.15)}, (0.515, 0.515), ((-0.48, -0.48, 0), (0.5, 0.5, 1.23)), 2630), "SM_DroneHub": ({"Body": (0, 0, 0), "Land": (0, 0, 0.22)}, (1, 1), ((-0.95, -0.95, 0), (0.95, 0.95, 1.26)), 5684), "SM_Drone": ({"Body": (0, 0, 0), "Claw": (0, 0, -0.13), "Lamp": (0, 0.06, 0.175), "Rotor0": (-0.3, -0.3, 0.125), "Rotor1": (0.3, -0.3, 0.125), "Rotor2": (0.3, 0.3, 0.125), "Rotor3": (-0.3, 0.3, 0.125)}, None, ((-0.47, -0.43, -0.36), (0.43, 0.47, 0.25)), 6314), "SM_RainDrone": ({"Body": (0, 0, 0), "Tank": (0, 0, 0.06), "Rotor_1": (-0.4, -0.4, 0.54), "Rotor_2": (0.4, -0.4, 0.54), "Rotor_3": (0.4, 0.4, 0.54), "Rotor_4": (-0.4, 0.4, 0.54)}, None, ((-0.62, -0.62, 0), (0.62, 0.62, 0.79)), 5946), } SCI_FI = {"M_Hazard", "M_PaintOrange", "M_Screen", "M_GaugeFace", "M_Frost", "M_Ice", "M_LightBlue", "M_WaterFill", "M_Glass"} ALLOWED_SCI_FI = {("SM_RainDrone", "M_LightBlue"), ("SM_WaterTank", "M_Glass")} # warm iris of the eye, inspection slot defs = set() for fn in sorted(os.listdir(os.path.join(ROOT, "ArtSource"))): if fn.startswith("materials") and fn.endswith(".json"): with open(os.path.join(ROOT, "ArtSource", fn), encoding="utf-8") as f: defs |= {m["name"] for m in json.load(f)} names = (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []) or list(REQ) bad = 0 for n in names: req, fp, old_b, old_t = REQ[n] bpy.ops.wm.read_factory_settings(use_empty=True) bpy.ops.import_scene.fbx(filepath=os.path.join(d, n + ".fbx")) bpy.context.view_layer.update() objs = {o.name: o for o in bpy.context.scene.objects} total, deck, mats, issues = 0, [], set(), [] gmn, gmx = [1e9] * 3, [-1e9] * 3 for k, want in req.items(): o = objs.get(k) if o is None: issues.append("missing %s" % k) continue got = o.matrix_world.translation if max(abs(a - b) for a, b in zip(got, want)) > 0.011: issues.append("pivot %s (%.3f,%.3f,%.3f) want %s" % (k, *got, want)) for o in objs.values(): if o.type != "MESH": continue total += sum(len(f.vertices) - 2 for f in o.data.polygons) pts = [o.matrix_world @ v.co for v in o.data.vertices] gmn = [min(a, min(p[i] for p in pts)) for i, a in enumerate(gmn)] gmx = [max(a, max(p[i] for p in pts)) for i, a in enumerate(gmx)] deck += [p for p in pts if p.z > -0.05] mats |= {m.name.split(".")[0] for m in o.data.materials if m} if not o.data.uv_layers: issues.append("no uv on %s" % o.name) if fp and deck: ex = max(abs(p.x) for p in deck) ey = max((p.y if len(fp) > 2 else abs(p.y)) for p in deck) if ex > fp[0] + (0.06 if len(fp) > 2 else 0.011) or ey > fp[1] + 0.011: issues.append("footprint |x|=%.3f |y|=%.3f limit %s" % (ex, ey, fp[:2])) if total > old_t * 1.25: issues.append("tris %d > 1.25 x old" % total) if "Belt" in objs: b = objs["Belt"] uv = b.data.uv_layers[0].data us, vs = [u.uv.x for u in uv], [u.uv.y for u in uv] if abs(min(us)) > 0.01 or abs(max(us) - 1) > 0.01: issues.append("belt U %.3f..%.3f" % (min(us), max(us))) print(" Belt %s U %.3f..%.3f V %.3f..%.3f mats %s z %.3f..%.3f" % (b.name, min(us), max(us), min(vs), max(vs), [m.name for m in b.data.materials], min((b.matrix_world @ v.co).z for v in b.data.vertices), max((b.matrix_world @ v.co).z for v in b.data.vertices))) unknown = sorted(m for m in mats if m not in defs) if unknown: issues.append("unknown materials %s" % unknown) sci = sorted(m for m in mats if m in SCI_FI and (n, m) not in ALLOWED_SCI_FI) if sci: issues.append("old-theme materials %s" % sci) bad += len(issues) fmt = lambda a, b: "x[%.2f,%.2f] y[%.2f,%.2f] z[%.2f,%.2f]" % (a[0], b[0], a[1], b[1], a[2], b[2]) print("FARM|%s|tris %d (old %d)|new %s|old %s|%s" % (n, total, old_t, fmt(gmn, gmx), fmt(*old_b), "; ".join(issues) or "OK")) print(" parts: %s" % ", ".join("%s(%.3f,%.3f,%.3f)" % (k, *o.matrix_world.translation) for k, o in sorted(objs.items()))) print(" mats: %s" % ", ".join(sorted(mats))) print("FARM|RESULT|%s" % ("OK" if bad == 0 else "ISSUES %d" % bad))