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>
99 lines
4.3 KiB
Python
99 lines
4.3 KiB
Python
"""Load the os_vehicles FBX files (vehicles + cargo) and print per-object origin / bounds (Unity space) / tris /
|
|
materials / UV layers, check the required named children (meshes + empties), the tri budgets and inside-out islands.
|
|
Run: blender -b --factory-startup --python verify_os_vehicles.py -- [names]"""
|
|
import bpy, bmesh, os, sys
|
|
|
|
d = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..", "Assets", "Art", "Models"))
|
|
REQ = {
|
|
"SM_SlurpSki": (["Body", "Bars"], ["Seat", "Intake", "Wake"], 12000),
|
|
"SM_TugPump": (["Body", "Fill", "Arm"], ["Seat", "Intake", "Wake"], 20000),
|
|
"SM_HoverTanker": (["Body", "Fill", "Fan_L", "Fan_R"], ["Seat", "Intake"], 20000),
|
|
"SM_Barrel": (["SM_Barrel"], [], 3000),
|
|
"SM_Canister": (["SM_Canister"], [], 3000),
|
|
"SM_IceBlock": (["SM_IceBlock"], [], 3000),
|
|
}
|
|
names = (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []) or list(REQ)
|
|
|
|
|
|
def U(v): # blender -> unity
|
|
return (-v.x, v.z, -v.y)
|
|
|
|
|
|
def inside_out(me, mw):
|
|
"""Count closed islands with negative signed volume."""
|
|
bm = bmesh.new()
|
|
bm.from_mesh(me)
|
|
bm.transform(mw)
|
|
bm.verts.ensure_lookup_table()
|
|
bm.faces.ensure_lookup_table()
|
|
seen, bad = set(), 0
|
|
for f0 in bm.faces:
|
|
if f0.index in seen:
|
|
continue
|
|
isl, st = [], [f0]
|
|
seen.add(f0.index)
|
|
while st:
|
|
f = st.pop()
|
|
isl.append(f)
|
|
for e in f.edges:
|
|
for g in e.link_faces:
|
|
if g.index not in seen:
|
|
seen.add(g.index)
|
|
st.append(g)
|
|
if any(len(e.link_faces) != 2 for f in isl for e in f.edges):
|
|
continue
|
|
vv = [v.co for f in isl for v in f.verts]
|
|
c = sum(vv, vv[0] * 0) / len(vv)
|
|
vol = 0.0
|
|
for f in isl:
|
|
vs = [v.co - c for v in f.verts]
|
|
for i in range(1, len(vs) - 1):
|
|
vol += vs[0].dot(vs[i].cross(vs[i + 1]))
|
|
bad += vol < 0
|
|
bm.free()
|
|
return bad
|
|
|
|
|
|
bad = 0
|
|
for n in names:
|
|
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()
|
|
meshes_req, empties_req, budget = REQ.get(n, ([], [], 1e9))
|
|
total = 0
|
|
gmn = [1e9] * 3; gmx = [-1e9] * 3
|
|
rows, found_m, found_e = [], set(), set()
|
|
flips = 0
|
|
for o in sorted(bpy.context.scene.objects, key=lambda o: (o.type, o.name)):
|
|
org = U(o.matrix_world.translation)
|
|
if o.type == "EMPTY":
|
|
found_e.add(o.name)
|
|
par = o.parent.name if o.parent else "-"
|
|
rows.append(f" EMPTY {o.name:<12} at({org[0]:.3f},{org[1]:.3f},{org[2]:.3f}) parent={par}")
|
|
continue
|
|
if o.type != "MESH":
|
|
continue
|
|
found_m.add(o.name)
|
|
tris = sum(len(f.vertices) - 2 for f in o.data.polygons)
|
|
total += tris
|
|
pts = [U(o.matrix_world @ v.co) for v in o.data.vertices]
|
|
mn = [min(p[i] for p in pts) for i in range(3)]
|
|
mx = [max(p[i] for p in pts) for i in range(3)]
|
|
gmn = [min(a, b) for a, b in zip(gmn, mn)]; gmx = [max(a, b) for a, b in zip(gmx, mx)]
|
|
mats = ",".join(sorted({m.name for m in o.data.materials if m}))
|
|
uvs = [l.name for l in o.data.uv_layers]
|
|
io = inside_out(o.data, o.matrix_world)
|
|
flips += io
|
|
par = o.parent.name if o.parent else "-"
|
|
rows.append(f" MESH {o.name:<12} origin({org[0]:.3f},{org[1]:.3f},{org[2]:.3f}) size({mx[0]-mn[0]:.2f} x {mx[1]-mn[1]:.2f} x {mx[2]-mn[2]:.2f}) "
|
|
f"x[{mn[0]:.2f},{mx[0]:.2f}] y[{mn[1]:.2f},{mx[1]:.2f}] z[{mn[2]:.2f},{mx[2]:.2f}] tris={tris} uv={uvs} insideout={io} parent={par}\n"
|
|
f" [{mats}]")
|
|
missing = [r for r in meshes_req if r not in found_m] + [r for r in empties_req if r not in found_e]
|
|
over = total > budget
|
|
bad += len(missing) + int(over) + flips
|
|
print(f"OSV|{n}|tris={total} (budget {budget}{' OVER' if over else ''})|size x={gmx[0]-gmn[0]:.2f} y={gmx[1]-gmn[1]:.2f} z={gmx[2]-gmn[2]:.2f}"
|
|
f" | x[{gmn[0]:.2f},{gmx[0]:.2f}] y[{gmn[1]:.2f},{gmx[1]:.2f}] z[{gmn[2]:.2f},{gmx[2]:.2f}]|missing={missing or 'none'}|insideout={flips}")
|
|
for r in rows:
|
|
print(r)
|
|
print(f"OSV|RESULT|{'OK' if bad == 0 else 'PROBLEMS %d' % bad}")
|