"""[SSOT 측정 유일 스크립트] 그려지는 메시의 실제 노즐끝/와이어끝을 measureTCP()로 잰다.
자기충족·프레임혼합 금지. 노즐끝↔NOZZLE_TCP(525) / 와이어끝↔WIRE_TCP(540). (방향은 _verify_orient.py 별도)"""
import asyncio, json
from playwright.async_api import async_playwright
URL='http://localhost:8090/DOZIKWORKS_OS_v5_locked.dc.html'
CEO_HOME={"S":-0.7,"L":-59.4,"U":-44.4,"R":-1.0,"B":-92.9,"T":-1.1}
async def main():
    async with async_playwright() as p:
        br=await p.chromium.launch(channel='msedge',headless=True)
        pg=await br.new_page(viewport={'width':1200,'height':800})
        errs=[]; pg.on('pageerror',lambda e: errs.append(str(e)))
        await pg.goto(URL); await pg.wait_for_function("window.__dzw && window.__dzw._torchMesh",timeout=15000)
        res=await pg.evaluate("""(HOME)=>{ const d=window.__dzw;
          if(d.setJoints) d.setJoints(HOME);
          return { measure:d.measureTCP(), meshName:d._torchMesh&&d._torchMesh.name,
                   NOZZLE_TCP:d.NOZZLE_TCP, WIRE_TCP:d.WIRE_TCP }; }""", CEO_HOME)
        print("=== SSOT 측정 (자 1벌, 실제 메시 정점) ===")
        print(" 메시:", res['meshName'])
        print(" NOZZLE_TCP:", res['NOZZLE_TCP'], "  WIRE_TCP:", res['WIRE_TCP'])
        m=res['measure']
        print(" 노즐끝 ↔ NOZZLE_TCP(525):", m['nozzle_to_NOZZLE_TCP'], "mm")
        print(" 와이어끝 ↔ WIRE_TCP(540):", m['wire_to_WIRE_TCP'], "mm  (와이어 모델링:", m['wireModeled'],")")
        print(" pageerrors:", errs if errs else "없음")
        await br.close()
asyncio.run(main())
