"""Render the cap7 test-scene from cap7_wide30.pkl's REAL captured IGC packets. Packets = {SETENABS, 3x TREEgeZERO_L3 edges, MEMltTREE_L3 z-test, TREEintoMEM_L0 z-write, 3x color-plane instrs, scalar}. Executed vectorized (numpy) on a full 832x512 surface with a persistent 1/w z-buffer (MEMltTREE: keep where old < new => greater 1/w wins = closer wins).""" import sys, pickle, struct import numpy as np S = r'C:\Users\cyd\AppData\Local\Temp\claude\c--VWE-TeslaRel410\4e848c76-6e89-4034-8047-d8d491cb32d8\scratchpad' W, H = 832, 512 d = pickle.load(open(S + r'\cap7_wide30.pkl', 'rb')) mem = d['mem'] def f32(w): return struct.unpack('= 0 en_neg &= v < 0 en = en_pos | en_neg # winding-agnostic if not en.any(): continue # z instr: scan forward from a+48 for the MEMltTREE header (preambles vary) za = None for off in range(48, 48 + 44, 4): if (rd(a + off) & 0xffffff00) == 0x44ea2100: za = a + off break if za is None: continue A, B, C = rdf(za + 4), rdf(za + 8), rdf(za + 12) z = A * xx + B * yy + C en &= z > zbuf if not en.any(): continue zbuf[en] = z[en] # z-write at a+64 (1 word), colors from a+68: three 5-word groups # {clmp-hdr, pword, w2, w3, w4} -- empirical: value plane = {B?, A?, C?} cols = [] ca = za + 20 for c in range(3): g = ca + 20 * c hdr = rd(g) w1, w2, w3, w4 = rd(g + 4), rd(g + 8), rd(g + 12), rd(g + 16) # try: the plane floats are the last three words {A?, B?, C?} fA, fB, fC = f32(w2), f32(w3), f32(w4) cols.append((fA, fB, fC)) for c, (fA, fB, fC) in enumerate(cols): plane = fA * xx + fB * yy + fC rgb[..., c][en] = np.clip(plane[en], 0, 255) drawn += 1 print("drawn: %d packets" % drawn) print("rgb range:", rgb.min(), rgb.max()) # normalize for viewing if the scale is off mx = rgb.max() or 1.0 img = (np.clip(rgb / (mx if mx > 255 else 255), 0, 1) * 255).astype(np.uint8) from PIL import Image Image.fromarray(img, 'RGB').save(S + r'\wide30_render.png') # also a z-buffer visualization (structure check independent of colors) zv = zbuf.copy() m = zv > -1e29 if m.any(): zn = (zv - zv[m].min()) / max(1e-9, (zv[m].max() - zv[m].min())) zi = np.zeros((H, W), np.uint8) zi[m] = (40 + 215 * zn[m]).astype(np.uint8) Image.fromarray(zi, 'L').save(S + r'\wide30_depth.png') print("wrote wide30_render.png + wide30_depth.png")