main
John Lauer Add README, license and 3D model provenance 22bfcfd
#!/usr/bin/env python3
"""Colour and pose the step2glb output of the vendor STEP (which carries no colours).
usage: build_glb.py raw.glb out.glb
Only the glTF JSON is changed: materials, node names, tooltips, one root translation. Geometry bytes are untouched."""
import sys,os
sys.path.insert(0,os.path.dirname(os.path.abspath(__file__)))
import glbio
src,dst=sys.argv[1:3]
js,bn=glbio.load(src)
def lin(c): return ((c+0.055)/1.055)**2.4 if c>0.04045 else c/12.92
def mat(name,hexc,metal,rough):
    r,g,b=[lin(int(hexc[i:i+2],16)/255) for i in (1,3,5)]
    return {"name":name,"pbrMetallicRoughness":{"baseColorFactor":[r,g,b,1],"metallicFactor":metal,"roughnessFactor":rough}}
MATS={
 "rubber":      mat("Tyre rubber (black)","#2b2c2f",0.0,0.82),
 "rim":         mat("Rim (dark painted steel)","#4b5058",0.45,0.42),
 "cover":       mat("Motor cover (metal)","#7b828c",0.55,0.38),
 "shell":       mat("Motor shell (dark metal)","#3a3d43",0.5,0.5),
 "steel":       mat("Steel (axle)","#a9afb7",0.7,0.3),
 "zinc":        mat("Zinc plated steel (nut, washer)","#cfd3d8",0.7,0.27),
 "bearing":     mat("Bearing steel","#8d939b",0.7,0.33),
 "brass":       mat("Brass (valve)","#b9923a",0.7,0.35),
 "cable":       mat("Cable jacket (black)","#18191b",0.0,0.65),
 "connector":   mat("Connector housing (white nylon)","#e9e7df",0.0,0.6),
 "cap":         mat("Centre cap (dark)","#2a2d32",0.3,0.5),
}
# vendor solid (node name out of step2glb) -> (new node name, material, tooltip)
PARTS={
 "NAUO23":("tyre","rubber","Tyre\nrubber, 65 +/-5 Shore A, 398 mm diameter, 98 mm wide"),
 "NAUO21":("rim","rim","Wheel rim"),
 "NAUO22":("tyre_valve","brass","Tyre valve"),
 "NAUO12":("motor_shell","shell","Motor shell (outer rotor)"),
 "NAUO19":("motor_cover_axle_side","cover","Motor cover, axle side"),
 "NAUO20":("motor_cover_outer_side","cover","Motor cover, outer side"),
 "NAUO17":("centre_cap","cover","Centre cap"),
 "NAUO15":("cover_plate","cap","Cover plate"),
 "NAUO13":("bearing_outer_side","bearing","Bearing, outer side"),
 "NAUO14":("bearing_axle_side","bearing","Bearing, axle side"),
 "NAUO18":("bearing_retainer","bearing","Bearing retainer"),
 "NAUO16":("axle","steel","Axle\nM24 x 2 thread, 16 mm across the flats, cables exit through the bore"),
 "NAUO6": ("axle_nut_m24x2","zinc","Axle nut, M24 x 2"),
 "NAUO7": ("axle_washer","zinc","Axle washer"),
 "NAUO8": ("cable_sheath","cable","Cable sheath\n600 +/-50 mm long on the real motor; the model stops short"),
 "NAUO9": ("signal_cable","cable","Signal cable (Halls, encoder, thermistor)"),
 "NAUO10":("power_cable","cable","Power cable (U yellow, V green, W blue)"),
 "NAUO11":("signal_connector","connector","Signal cable connector, 12 positions"),
}
names=list(MATS); js["materials"]=[MATS[k] for k in names]
seen=set()
for n in js["nodes"]:
    nm=n.get("name")
    if nm in PARTS and "mesh" in n:
        new,mk,tip=PARTS[nm]; seen.add(nm)
        n["name"]=new; n.setdefault("extras",{})["tooltip"]=tip; n["extras"]["vendorSolid"]=nm
        m=js["meshes"][n["mesh"]]; m["name"]=new
        for p in m["primitives"]: p["material"]=names.index(mk)
assert seen==set(PARTS), set(PARTS)-seen
gen={"NAUO1":"wheel_assembly","NAUO2":"wheel","NAUO3":"cable_assembly","NAUO4":"power_cable_group","NAUO5":"signal_cable_group"}
for n in js["nodes"]:
    if n.get("name") in gen: n["name"]=gen[n["name"]]
# pose: vendor frame already has the axle along Y and the wheel in the XZ plane (Z up = standing).
# Move the tyre mid-plane to y = 0 and the tyre bottom to z = 0. Metres.
T=[0.0,-0.03425,0.199]
root=js["nodes"][js["scenes"][0]["nodes"][0]]
root["name"]="ZLLG16ASM800_V2.0"; root["translation"]=T
js["asset"]["extras"]={"adomModel":{"mpn":"ZLLG16ASM800 V2.0","manufacturer":"ZLTECH (Shenzhen Zhongling Technology Co., Ltd.)",
 "source":"vendor STEP ZLLG16ASM800-V2.0.step, sha256 90799f3d77f5ed5d0653941bfa2a352e87d84e68a04986555ade4eb68f5349cc",
 "frame":"Z up, axle along Y (cable exit at +Y), tyre mid-plane at y = 0, tyre bottom at z = 0, metres",
 "sourceToDisplay":{"rotation":"none","translation_m":T},
 "colours":"added by Adom: the vendor STEP has no colour data. Black tyre, metal hub: chosen by hand, not measured. In the vendor's product photos the rim and motor covers are black; they are shown lighter here so the parts can be told apart.",
 "notInModel":"tread pattern, hub label, full 600 mm cable"}}
glbio.save(dst,js,bn); print("wrote",dst,len(js["materials"]),"materials")