"""Spearfish: what each seat sees (exec'd in Blender after a build, or headless on Tender_Spearfish.blend). The user, 2026-10-20: "two seater next to each other when two player can seat each should can see the sea from the window front". From each seat's eye (SOCKET_Seat_L_Eye, SOCKET_Seat_R_Eye) rays go out over the forward view: yaw -40..+40 deg (+ = outboard, toward the seat's own side), pitch -25..+15 deg, 5 deg steps. A ray that first meets glass leaves the cabin: that seat sees the sea that way. Writes checks/view.json and returns the summary.""" import bpy, math, os, json from mathutils import Vector, Matrix HERE = r"D:\HADAL - The Descent\models\tender-spearfish\build" sc = bpy.context.scene dg = bpy.context.evaluated_depsgraph_get() GLASS = {"SM_Spearfish_Glass"} def first_hit(o, d): ok, loc, nrm, idx, ob, mx = sc.ray_cast(dg, o, d) return (ob.name if ok else None), ((loc - o).length if ok else None) out = {} for nm, s in (("SOCKET_Seat_L_Eye", 1), ("SOCKET_Seat_R_Eye", -1)): eye = bpy.data.objects[nm].matrix_world.translation.copy() grid, hits = [], {} through = total = 0 for pitch in range(-25, 16, 5): row = "" for yaw in range(-40, 41, 5): # forward is -Y; positive yaw turns outboard (toward this seat's own side) d = Matrix.Rotation(math.radians(yaw * s), 3, 'Z') @ Vector((0, -1, 0)) d = Matrix.Rotation(math.radians(pitch), 3, d.cross(Vector((0, 0, 1))).normalized()) @ d ob, dist = first_hit(eye, d.normalized()) total += 1 if ob in GLASS: through += 1 row += "o" else: row += "." hits[ob] = hits.get(ob, 0) + 1 grid.append("%+03d %s" % (pitch, row)) ahead, _ = first_hit(eye, Vector((0, -1, 0))) ahead_down, _ = first_hit(eye, (Matrix.Rotation(math.radians(-10), 3, Vector((1, 0, 0))) @ Vector((0, -1, 0)))) out[nm] = {"eye": [round(c, 3) for c in eye], "straight_ahead": ahead, "ahead_10deg_down": ahead_down, "through_glass_pct": round(100.0 * through / total, 1), "first_hits": hits, "map (rows pitch -25..+15, columns yaw -40..+40, o = glass)": grid} json.dump(out, open(os.path.join(HERE, "checks", "view.json"), "w"), indent=1) result = {k: {kk: v[kk] for kk in ("eye", "straight_ahead", "ahead_10deg_down", "through_glass_pct")} for k, v in out.items()} print("VIEW", json.dumps(result))