Files
grass-cutters/ArtSource/Blender/scripts/gc_up_windmill_verify.py
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
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>
2026-11-06 18:44:40 +06:00

100 lines
4.6 KiB
Python

"""Check the exported SM_Windmill.fbx: names, hub, sail clearance, footprint, ports, budget. Run:
blender -b --factory-startup --python D:/PROJECTS/LOCAL/GrassCutter/ArtSource/Blender/scripts/gc_up_windmill_verify.py
Exits non-zero if a check fails.
"""
import bpy, math, os, sys
from mathutils import Vector
FBX = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..", "Assets", "Art", "Models", "SM_Windmill.fbx"))
HUB = Vector((0, -1.30, 5.0))
fails = []
def check(ok, text):
print((" ok " if ok else " FAIL ") + text)
if not ok:
fails.append(text)
def verts(o):
return [o.matrix_world @ v.co for v in o.data.vertices]
bpy.ops.wm.read_factory_settings(use_empty=True)
bpy.ops.import_scene.fbx(filepath=FBX)
bpy.context.view_layer.update()
obs = {o.name: o for o in bpy.context.scene.objects}
print("objects:", sorted(obs))
print("names")
for n in ("Body", "Spin", "Lamp", "Sail_1", "Sail_2", "Sail_3", "Sail_4"):
check(n in obs and obs[n].type == "MESH", n + " is a mesh in the FBX")
for n in range(1, 5):
check(obs["Sail_%d" % n].parent == obs["Spin"], "Sail_%d is parented to Spin" % n)
print("hub")
sp = obs["Spin"]
loc = sp.matrix_world.translation
check((loc - HUB).length < 1e-3, "Spin origin %s on the hub %s" % (tuple(round(c, 4) for c in loc), tuple(HUB)))
m3 = sp.matrix_world.to_3x3().normalized()
axes = {a: (m3 @ Vector(v)).normalized() for a, v in (("X", (1, 0, 0)), ("Y", (0, 1, 0)), ("Z", (0, 0, 1)))}
check(abs(axes["Y"].dot(Vector((0, 1, 0)))) > .99999, "Spin local Y runs along world Y, front to back")
sw = [p for n in ("Spin", "Sail_1", "Sail_2", "Sail_3", "Sail_4") for p in verts(obs[n])]
nose = [p for p in verts(obs["Spin"]) if p.y < HUB.y - .2]
cx_, cz_ = (min(p.x for p in nose) + max(p.x for p in nose)) / 2, (min(p.z for p in nose) + max(p.z for p in nose)) / 2
check(math.hypot(cx_ - HUB.x, cz_ - HUB.z) < .01, "the hub nose is centred on the axis (off by %.4f)" % math.hypot(cx_ - HUB.x, cz_ - HUB.z))
print("sails")
R = max(math.hypot(p.x, p.z - HUB.z) for p in sw)
check(HUB.z - R >= 1.9, "lowest possible tip %.3f m >= 1.9 (R %.3f, hub %.3f)" % (HUB.z - R, R, HUB.z))
print(" rest pose top %.2f, tip straight up %.2f" % (max(p.z for p in sw), HUB.z + R))
# swept: nothing of the body may lie inside the disc the sails sweep
bins = {}
for p in sw:
k = int(math.hypot(p.x, p.z - HUB.z) / .1)
bins[k] = max(bins.get(k, -9e9), p.y)
clear = 9e9
for p in verts(obs["Body"]) + verts(obs["Lamp"]):
r = math.hypot(p.x, p.z - HUB.z)
k = int(r / .1)
ys = [bins[j] for j in (k - 1, k, k + 1) if j in bins]
if ys and r > .35:
clear = min(clear, p.y - max(ys))
check(clear > .03, "sails clear the body by %.3f m as they sweep" % clear)
print("footprint")
body = verts(obs["Body"])
low = [p for p in body if p.z < 1.55] # the gallery and its brackets overhang above this
xs, ys = [p.x for p in low], [p.y for p in low]
check(max(map(abs, xs)) <= 1.0005 and max(map(abs, ys)) <= 1.0005, "everything under the gallery brackets fits 2 x 2 m: x %.3f..%.3f, y %.3f..%.3f" % (min(xs), max(xs), min(ys), max(ys)))
check(abs(min(p.z for p in body)) < 1e-3, "stands on z = 0 (min %.4f)" % min(p.z for p in body))
print(" body top %.2f" % max(p.z for p in body))
print("ports")
front = [p for p in body if p.y < -.995 and abs(p.x) < .06 and p.z < .7]
back = [p for p in body if p.y > .96 and abs(p.x) < .34 and p.z < 1.0]
check(abs(max(p.z for p in front) - .4) < .03, "chute floor at the lip %.3f, y %.3f" % (max(p.z for p in front), min(p.y for p in front)))
check(abs(max(p.z for p in back) - .4) < .03, "hopper rim %.3f, y %.3f" % (max(p.z for p in back), max(p.y for p in back)))
print(" gallery half width %.3f" % max(max(abs(p.x), abs(p.y)) for p in body if 1.7 < p.z < 2.7 and p.y < 1.1))
print("lamp")
lamp = obs["Lamp"]
names = [m.name for m in lamp.data.materials]
check(any(n.startswith("M_Light") for n in names), "Lamp uses a light material: %s" % names)
print(" Lamp at", tuple(round(c, 3) for c in lamp.matrix_world.translation))
print("budget")
tris = 0
for o in bpy.context.scene.objects:
if o.type == "MESH":
t = sum(len(p.vertices) - 2 for p in o.data.polygons)
tris += t
print(" %-8s %5d tris %s uv:%s" % (o.name, t, sorted({m.name for m in o.data.materials}), [l.name for l in o.data.uv_layers]))
check(tris < 8000, "%d tris < 8000" % tris)
for o in bpy.context.scene.objects:
if o.type == "MESH":
check(not any(m.name.startswith("P_") for m in o.data.materials), o.name + " has no stand-in paint left")
print("RESULT:", "FAIL " + str(len(fails)) if fails else "all ok")
sys.exit(1 if fails else 0)