#!/usr/bin/env python3 """debug_view.py -- numeric check of vrview transforms against a capture replay.""" import os, sys, struct import numpy as np sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) os.environ.setdefault('SDL_VIDEODRIVER', 'dummy') from vrboard import VirtualBoard, Assembler from decode_anim import find_framed_start from vrview import Renderer, _mat_from_dcs path = sys.argv[1] if len(sys.argv) > 1 else 'cap5.raw.bin' data = open(path, 'rb').read() board = VirtualBoard() asm = Assembler(); asm.feed(data[find_framed_start(data):]) for m in asm: try: board.handle(m) except Exception: pass if board.frames >= 600: break r = Renderer(); r.cache.maybe_rebuild(board) c = r.cache print('cam chain', [hex(h) for h in c.cam_chain]) for h in (0x1, 0x2, 0x3): b = board.nodes.get(h, {}).get('body') or b'' if len(b) >= 76: M = _mat_from_dcs(b) print(f'dcs {h:#x} diag={np.diag(M)[:3]} row3={M[3,:3]} anim={h in board.anim}') V = np.linalg.inv(r.chain_matrix(board, c.cam_chain)) print('V row3 (eye offset):', V[3, :3]) for inst in c.instances: M = r.chain_matrix(board, inst['chain']) for gh in inst['geoms']: mesh = c.meshes[gh] pw = mesh['pos'] @ M[:3, :3] + M[3, :3] pe = pw @ V[:3, :3] + V[3, :3] z = -pe[:, 2] vis = z > 8 if vis.any(): xp = pe[vis, 0] * 1.3 / z[vis]; yp = pe[vis, 1] * 1.3 / z[vis] scr = f"proj x[{xp.min():7.2f},{xp.max():7.2f}] y[{yp.min():7.2f},{yp.max():7.2f}]" else: scr = "behind camera" print(f"dcs={inst['chain'][0]:#04x} geom={gh:#04x} v={len(pw):4d} " f"world y[{pw[:,1].min():8.1f},{pw[:,1].max():8.1f}] " f"size={np.ptp(pw,0).round(0)} {scr}")