A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date. Images, audio, models and binaries go through Git LFS (.gitattributes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
196 lines
10 KiB
Python
196 lines
10 KiB
Python
"""Re-import the FBX files of gc_up_production.py and check what the game relies on: named parts, their pivots, the axis each
|
|
moving part works on, footprints, tri budgets, belt UVs and materials. Blender space: Z up, front -Y.
|
|
|
|
The axis tests read the raw FBX as well as the re-imported scene, because the importer undoes the file's axis conversion:
|
|
Gauge raw Lcl Rotation must be (0, 0, 0): that is what makes Unity's local Y point straight up. Then its local Y is scaled to
|
|
0.25 in the re-imported scene, and the strip must keep its bottom, lose 3/4 of its height and not change in width or depth.
|
|
Spin its local Z must lie along the axle the mesh is built around, with the origin on that axle, and must run front to
|
|
back: Machine.cs turns it about BaseRot.LocalAxisFor(spin, transform.forward), the local axis nearest the machine's front.
|
|
|
|
Run: blender -b --factory-startup --python gc_up_production_verify.py -- [names]"""
|
|
import bpy, json, os, struct, sys
|
|
from mathutils import Vector, Matrix
|
|
|
|
ROOT = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", ".."))
|
|
d = os.path.join(ROOT, "Assets", "Art", "Models")
|
|
J = dict(hx=0.5, hy=0.5, budget=2500)
|
|
REQ = {
|
|
"SM_Vaporizer": (["Body", "Lamp", "Spin", "Out", "Vent"], 1.0, 1.0, 8000),
|
|
"SM_CryoPress": (["Body", "Lamp", "Spin", "Press", "Out"], 1.0, 1.0, 8000),
|
|
"SM_Binder": (["Body", "Lamp"], 1.0, 1.0, 8000),
|
|
"SM_BundleCatcher": (["Body"], 1.5, 1.5, 8000),
|
|
"SM_SolarPost": (["Stand", "Head"], None, None, 2500),
|
|
"SM_SolarPair": (["Stand", "Head"], None, None, 2500),
|
|
"SM_SolarTracker": (["Stand", "Head"], None, None, 2500),
|
|
"SM_BatteryRack": (["Body", "Gauge", "Lamp"], 0.75, 0.75, 8000),
|
|
"SM_BatteryBank": (["Body", "Gauge", "Lamp"], 1.5, 1.0, 8000),
|
|
"SM_BeltSplitter": (["Frame", "Belt", "Paddle", "Sign"], 0.5, 0.5, 2500),
|
|
"SM_BeltMerger": (["Frame", "Belt", "Sign"], 0.5, 0.5, 2500),
|
|
}
|
|
PIVOTS = {"Press": (0, 0, 1.24), "Head": None, "Paddle": (0, 0.44, 0.35), "Out": (0, -0.98, 0.4)}
|
|
HEAD = {"SM_SolarPost": 1.6, "SM_SolarPair": 1.9, "SM_SolarTracker": 2.6}
|
|
EMISSIVE = {"Lamp", "Gauge"}
|
|
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)}
|
|
|
|
|
|
def raw_rotations(path):
|
|
"""Every (name, Lcl Rotation) in a binary FBX, by walking Model nodes the simple way: the property follows the name."""
|
|
b = open(path, "rb").read()
|
|
out = {}
|
|
i = 0
|
|
while True:
|
|
i = b.find(b"\x00\x01Model", i)
|
|
if i < 0:
|
|
break
|
|
name = b[max(0, i - 40):i].split(b"\x00")[-1].decode("latin1", "ignore")
|
|
name = "".join(c for c in name if c.isalnum() or c == "_")
|
|
j = b.find(b"Lcl Rotation", i, i + 1400)
|
|
rot = (0.0, 0.0, 0.0)
|
|
if j > 0:
|
|
seg = b[j:j + 90]
|
|
vals = []
|
|
k = 0
|
|
while k < len(seg) - 8 and len(vals) < 3:
|
|
if seg[k:k + 1] == b"D":
|
|
vals.append(struct.unpack("<d", seg[k + 1:k + 9])[0])
|
|
k += 9
|
|
else:
|
|
k += 1
|
|
rot = tuple(round(v, 3) for v in vals)
|
|
out[name] = rot
|
|
i += 6
|
|
return out
|
|
|
|
|
|
names = (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []) or list(REQ)
|
|
bad = 0
|
|
for n in names:
|
|
need, hx, hy, budget = REQ[n]
|
|
issues = []
|
|
path = os.path.join(d, n + ".fbx")
|
|
if not os.path.exists(path):
|
|
print("UP|%s|missing FBX" % n)
|
|
bad += 1
|
|
continue
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
bpy.ops.import_scene.fbx(filepath=path)
|
|
bpy.context.view_layer.update()
|
|
objs = {o.name: o for o in bpy.context.scene.objects}
|
|
for k in need:
|
|
if k not in objs:
|
|
issues.append("missing " + k)
|
|
for k, want in PIVOTS.items():
|
|
if want and k in objs and k in need:
|
|
got = objs[k].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))
|
|
if "Head" in objs and n in HEAD:
|
|
if abs(objs["Head"].matrix_world.translation.z - HEAD[n]) > 0.011:
|
|
issues.append("Head pivot z %.3f" % objs["Head"].matrix_world.translation.z)
|
|
total, mats = 0, set()
|
|
mn, mx = [1e9] * 3, [-1e9] * 3
|
|
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]
|
|
mn = [min(a, min(p[i] for p in pts)) for i, a in enumerate(mn)]
|
|
mx = [max(a, max(p[i] for p in pts)) for i, a in enumerate(mx)]
|
|
mats |= {m.name.split(".")[0] for m in o.data.materials if m}
|
|
if not o.data.uv_layers:
|
|
issues.append("no uv on " + o.name)
|
|
if hx and (max(abs(mn[0]), mx[0]) > hx + 0.011 or max(abs(mn[1]), mx[1]) > hy + 0.011):
|
|
issues.append("footprint x[%.3f,%.3f] y[%.3f,%.3f] limit %.2f x %.2f" % (mn[0], mx[0], mn[1], mx[1], hx, hy))
|
|
if total > budget:
|
|
issues.append("tris %d > %d" % (total, budget))
|
|
unknown = sorted(m for m in mats if m not in defs)
|
|
if unknown:
|
|
issues.append("unknown materials %s" % unknown)
|
|
raw = raw_rotations(path)
|
|
for k in EMISSIVE:
|
|
if k in objs:
|
|
ms = [m.name.split(".")[0] for m in objs[k].data.materials]
|
|
if ms != ["M_Emissive"]:
|
|
issues.append("%s materials %s" % (k, ms))
|
|
if "Lamp" in objs:
|
|
o = objs["Lamp"]
|
|
pts = [o.matrix_world @ v.co for v in o.data.vertices]
|
|
w = max(max(p[i] for p in pts) - min(p[i] for p in pts) for i in range(3))
|
|
if not 0.07 <= w <= 0.095:
|
|
issues.append("Lamp size %.3f" % w)
|
|
if "Gauge" in objs:
|
|
o = objs["Gauge"]
|
|
r = raw.get("Gauge")
|
|
if r is None or max(abs(a) for a in r) > 0.01:
|
|
issues.append("Gauge raw Lcl Rotation %s, Unity local Y would not be up" % (r,))
|
|
pts = [o.matrix_world @ v.co for v in o.data.vertices]
|
|
z0, z1 = min(p.z for p in pts), max(p.z for p in pts)
|
|
x0, x1 = min(p.x for p in pts), max(p.x for p in pts)
|
|
y0, y1 = min(p.y for p in pts), max(p.y for p in pts)
|
|
if abs(o.matrix_world.translation.z - z0) > 0.002:
|
|
issues.append("Gauge origin %.3f is not at its bottom %.3f" % (o.matrix_world.translation.z, z0))
|
|
if abs(z1 - z0 - 0.5) > 0.011:
|
|
issues.append("Gauge height %.3f" % (z1 - z0))
|
|
o.scale = (o.scale.x, o.scale.y * 0.25, o.scale.z)
|
|
bpy.context.view_layer.update()
|
|
p2 = [o.matrix_world @ v.co for v in o.data.vertices]
|
|
z0b, z1b = min(p.z for p in p2), max(p.z for p in p2)
|
|
w_same = abs((max(p.x for p in p2) - min(p.x for p in p2)) - (x1 - x0)) < 1e-4 and abs((max(p.y for p in p2) - min(p.y for p in p2)) - (y1 - y0)) < 1e-4
|
|
if abs(z0b - z0) > 1e-3 or abs((z1b - z0b) - 0.25 * (z1 - z0)) > 1e-3 or not w_same:
|
|
issues.append("Gauge local Y scale test failed: z %.3f..%.3f became %.3f..%.3f" % (z0, z1, z0b, z1b))
|
|
print(" Gauge raw rot %s z %.3f..%.3f at scale 1, %.3f..%.3f at local Y 0.25, width and depth kept: %s" % (r, z0, z1, z0b, z1b, w_same))
|
|
o.scale = (o.scale.x, o.scale.y / 0.25, o.scale.z)
|
|
if "Spin" in objs:
|
|
o = objs["Spin"]
|
|
ax = (o.matrix_world.to_3x3() @ Vector((0, 0, 1))).normalized()
|
|
lp = [v.co for v in o.data.vertices]
|
|
spread = [max(p[i] for p in lp) - min(p[i] for p in lp) for i in range(3)]
|
|
c = [(max(p[i] for p in lp) + min(p[i] for p in lp)) / 2 for i in range(2)]
|
|
print(" Spin local Z in world (%.2f,%.2f,%.2f), mesh spread %.3f %.3f %.3f, centre offset %.3f %.3f" % (*ax, *spread, *c))
|
|
if spread[2] > min(spread[0], spread[1]) * 0.8:
|
|
issues.append("Spin's axle is not its local Z")
|
|
pick = max(range(3), key=lambda i: abs((o.matrix_world.to_3x3().inverted() @ Vector((0, -1, 0))).normalized()[i]))
|
|
print(" Spin: local axis nearest the machine's front is %s" % "XYZ"[pick])
|
|
if pick != 2:
|
|
issues.append("Machine.cs would turn Spin about local %s, not its axle" % "XYZ"[pick])
|
|
if max(abs(a) for a in c) > 0.05:
|
|
issues.append("Spin's origin is off its axle")
|
|
if "Sign" in objs:
|
|
ms = [m.name.split(".")[0] for m in objs["Sign"].data.materials]
|
|
if ms != ["M_PaintWhite"]:
|
|
issues.append("Sign materials %s" % ms)
|
|
if n in ("SM_BeltSplitter", "SM_BeltMerger"):
|
|
# nothing fixed may stand where a bundle rides: the cross of corridors through the middle, 0.4 m wide, to just over the hay at 0.86
|
|
hits = []
|
|
for k in ("Frame", "Sign"):
|
|
for v in objs[k].data.vertices:
|
|
q = objs[k].matrix_world @ v.co
|
|
if 0.37 < q.z < 0.88 and (abs(q.x) < 0.2 or abs(q.y) < 0.2):
|
|
hits.append((round(q.x, 2), round(q.y, 2), round(q.z, 2)))
|
|
print(" bundle corridors: %d fixed vertices in the way %s" % (len(hits), hits[:4]))
|
|
if hits:
|
|
issues.append("something stands in a bundle's way")
|
|
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]
|
|
zs = [(b.matrix_world @ v.co).z for v in b.data.vertices]
|
|
ms = [m.name.split(".")[0] for m in b.data.materials]
|
|
print(" Belt U %.3f..%.3f V %.3f..%.3f z %.3f..%.3f mats %s" % (min(us), max(us), min(vs), max(vs), min(zs), max(zs), ms))
|
|
if abs(min(us)) > 0.01 or abs(max(us) - 1) > 0.01:
|
|
issues.append("belt U")
|
|
if abs(max(zs) - 0.35) > 0.002 or abs(min(zs) - 0.35) > 0.002:
|
|
issues.append("belt height")
|
|
if ms != ["M_ConveyorBelt"]:
|
|
issues.append("belt material %s" % ms)
|
|
if any(p.normal.z < 0.99 for p in b.data.polygons):
|
|
pass
|
|
bad += len(issues)
|
|
print("UP|%s|tris %d|x[%.2f,%.2f] y[%.2f,%.2f] z[%.2f,%.2f]|%s" % (n, total, mn[0], mx[0], mn[1], mx[1], mn[2], mx[2], "; ".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("UP|RESULT|%s" % ("OK" if bad == 0 else "ISSUES %d" % bad))
|