cntrl/tools/blender/build_beacon.py
dandovlatov 27bf6e511f Replace Threshold exit flow with walk-to-activate Beacons
- Remove Threshold Key/hazard door/stairwell exit, anchors, events and HUD text
- Add aged 40%-larger Beacon GLB and reproducible Blender generator
- Add BeaconSystem: three walk-over beacons, grey->bright-red Hiss-wave activation
- Add cheap plinth collision and a placeholder completion event/banner
- Add beacon QA flag, validation, tests and design notes
2026-11-25 02:46:19 +04:00

254 lines
10 KiB
Python

# tools/blender/build_beacon.py
# FBC: NIGHT SHIFT — walk-to-activate Beacon prop.
#
# Run headlessly:
# blender --background --factory-startup --python tools/blender/build_beacon.py
#
# A tall, tapered triangular prism: two pale mirrored faces meeting at a
# vertical spine, a dark back face, curled metal veins, and a low steel
# plinth. Grey until the player walks near it; the game tints the whole one-
# mesh / painted-vertex GLB bright red, adds emissive glow, and runs the
# actor shader's dark-red Hiss wave over it. Scaled 40% for presence.
import math
import os
import sys
import bpy
from mathutils import Vector
REPO = "/home/dandovlatov/Documents/cntrl"
MODEL_DIR = os.path.join(REPO, "assets", "models", "props")
BLEND_DIR = os.path.join(REPO, "assets", "blender")
os.makedirs(MODEL_DIR, exist_ok=True)
os.makedirs(BLEND_DIR, exist_ok=True)
sys.path.insert(0, os.path.join(REPO, "tools", "blender"))
import importlib
import actor_kit as K
importlib.reload(K)
K.clear_scene()
P = dict(K.PALETTE)
# Dull pewter and oxidised green-grey: an old, otherworldly relic rather than
# a clean gallery sculpture. The game still reads it as grey until activated.
P.update({"mirror": "#7d8985", "glass_dark": "#2f3738",
"patina": "#5c6d63", "soot": "#202324", "rust": "#6b5648"})
# Footprint of the prism (Blender XY; +Z is up). A is the sharp front ridge.
A = Vector((0.0, -0.92))
B = Vector((-0.98, 0.58))
C = Vector((0.98, 0.58))
CENTROID = (A + B + C) / 3.0
Z0, Z1, TAPER = 0.54, 4.55, 0.12
SCALE = 1.4 # 40% larger than first pass, so it reads at tactical distance
def outward(p, q):
"""Unit normal of edge p->q pointing away from the prism's centre."""
d = q - p
n = Vector((-d.y, d.x)).normalized()
if n.dot((p + q) * 0.5 - CENTROID) < 0.0:
n = -n
return n
def on_face(p, q, u, t, lift=0.0):
"""Point on a face: u across the edge, t up the taper, lift along normal."""
bottom = p * (1.0 - u) + q * u
top = p * TAPER * (1.0 - u) + q * TAPER * u
xy = bottom * (1.0 - t) + top * t
n = outward(p, q)
return (xy.x + n.x * lift, xy.y + n.y * lift,
Z0 + (Z1 - Z0) * t)
def box(root, name, cx, cy, z0, dx, dy, dz, value, ao=0.06, taper=1.0):
hw, hd = dx * 0.5, dy * 0.5
return K.plate(root, name,
[(-hw, -hd), (hw, -hd), (hw, hd), (-hw, hd)],
z0, z0 + dz, taper, value, shift=(cx, cy), ao=ao)
def face(root, name, p, q, value, thickness=0.035):
"""A thin double-sided slab following one tapered face of the prism."""
n = outward(p, q)
outer = [on_face(p, q, u, t)
for u, t in ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))]
inner = [(v[0] - n.x * thickness, v[1] - n.y * thickness, v[2])
for v in outer]
verts = outer + inner
faces = [(0, 1, 2, 3), (7, 6, 5, 4),
(0, 4, 5, 1), (1, 5, 6, 2), (2, 6, 7, 3), (3, 7, 4, 0)]
return K.paint(K._mesh(root, name, verts, faces), value, ao=0.10)
def veins(root, name, p, q, seed=0.0):
"""Old, irregular root-like tracery laid just proud of a mirrored face."""
for k, phase in ((0.22, 0.4), (0.50, 2.3), (0.78, 4.1)):
pts = []
for i in range(13):
t = 0.03 + i * 0.077
u = (k + 0.11 * math.sin(t * 7.3 + phase)
+ 0.045 * math.sin(t * 19.0 + seed))
pts.append(on_face(p, q, u, t, 0.035 + 0.01 * math.sin(t * 9.0)))
K.tube(root, "%s_rib_%d" % (name, int(k * 100)), pts,
[0.030] * len(pts), P["soot"], sides=5, ao=0.0)
# A short crooked branch makes the growth look grown, not drawn.
base = pts[5]
b = on_face(p, q, k + 0.19 * math.cos(phase), 0.44 + 0.08 * seed, 0.036)
K.tube(root, "%s_branch_%d" % (name, int(k * 100)),
[base, on_face(p, q, k + 0.13, 0.40 + 0.06 * seed, 0.036), b],
[0.022, 0.017, 0.008], P["soot"], sides=5, ao=0.0)
for idx, (cu, ct, ru, rt) in enumerate(((0.50, 0.56, 0.30, 0.21),
(0.47, 0.24, 0.17, 0.13))):
pts = []
for i in range(16):
a = 2.0 * math.pi * i / 16.0
wobble = 1.0 + 0.17 * math.sin(3.0 * a + seed + idx)
pts.append(on_face(p, q, cu + ru * wobble * math.cos(a),
ct + rt * wobble * math.sin(a), 0.04))
pts.append(pts[0])
K.tube(root, "%s_loop_%d" % (name, idx), pts,
[0.027] * len(pts), P["soot"], sides=5, ao=0.0)
# Hairline fractures: old glass that survived longer than it should have.
for idx, (u0, t0, step) in enumerate(((0.16, 0.80, 0.085),
(0.83, 0.69, -0.075))):
pts = []
for i in range(7):
u = u0 + step * i + 0.035 * math.sin(i * 2.7 + seed)
t = t0 - i * 0.095 + 0.02 * math.cos(i * 1.9 + idx)
pts.append(on_face(p, q, u, t, 0.042))
K.tube(root, "%s_crack_%d" % (name, idx), pts,
[0.012] * len(pts), P["soot"], sides=4, ao=0.0)
def noise(x, y, z):
v = math.sin(x * 12.9898 + y * 78.233 + z * 37.719) * 43758.5453
return v - math.floor(v)
def weather(obj, seed=0.0, strength=0.48):
"""Bake mottled tarnish, verdigris blooms and pitted soot into COLOR_0."""
attr = obj.data.color_attributes.get("Color")
if attr is None:
return obj
patina, rust = K.color(P["patina"]), K.color(P["rust"])
for i, v in enumerate(obj.data.vertices):
x, y, z = v.co
n = noise(x + seed, y + seed * 0.7, z + seed * 1.3)
n2 = noise(x * 2.7 + seed, y * 2.3, z * 3.1 + seed * 0.4)
c = list(attr.data[i].color)
dirt = 1.0 - strength * (0.35 + 0.65 * n) * (0.4 + 0.6 * n2)
c = [channel * dirt for channel in c[:3]]
if n2 > 0.62:
f = min(0.62, (n2 - 0.62) * 1.9)
c = [c[k] * (1.0 - f) + patina[k] * f for k in range(3)]
elif n < 0.28:
f = min(0.50, (0.28 - n) * 1.9)
c = [c[k] * (1.0 - f) + rust[k] * f for k in range(3)]
attr.data[i].color = (c[0], c[1], c[2], 1.0)
return obj
def lean(root, dx=0.07, dy=0.02):
"""A slight, unsettling list — an old monument that has settled."""
for obj in root.children:
for v in obj.data.vertices:
if v.co.z > Z0:
t = (v.co.z - Z0) / (Z1 - Z0)
v.co.x += dx * t * t
v.co.y += dy * t * t
obj.data.update()
def build_beacon():
root = K.new_actor("Beacon")
# Plinth: two stacked steel plates with a dark recess for the prism.
box(root, "plinth", 0.0, 0.0, 0.0, 1.95, 1.95, 0.46,
P["steel_dk"], 0.10, taper=0.88)
box(root, "plinth_cap", 0.0, 0.0, 0.46, 1.85, 1.85, 0.08,
P["steel"], 0.06)
box(root, "plinth_recess", 0.0, 0.0, 0.54, 1.65, 1.65, 0.02,
P["redaction"], 0.02)
# Mirrored front faces and the dark back face.
face(root, "mirror_left", A, B, P["mirror"])
face(root, "mirror_right", A, C, P["mirror"])
face(root, "back", B, C, P["glass_dark"])
veins(root, "veins_left", A, B, seed=0.7)
veins(root, "veins_right", A, C, seed=2.1)
# Mineral inclusions pushing through the old metal, like the sculpture is
# growing something it should not.
for name, p, q, spots in (("left", A, B, ((0.31, 0.63), (0.72, 0.34))),
("right", A, C, ((0.64, 0.58), (0.28, 0.30)))):
for i, (u, t) in enumerate(spots):
x, y, z = on_face(p, q, u, t, 0.055)
K.crystal(root, "inclusion_%s_%d" % (name, i), (x, y, z), 0.17,
P["patina"], sides=5, seed=i + (0 if name == "left" else 9),
tilt=(0.35, -0.2, 0.4 + i))
# Three vertical corner rails, the top triangle, and the front spine with
# its small finial (the reference sculpture's most readable silhouette).
for name, p, radius in (("rail_front", A, 0.075),
("rail_left", B, 0.055),
("rail_right", C, 0.055)):
K.tube(root, name,
[(p.x, p.y, Z0), (p.x * TAPER, p.y * TAPER, Z1)],
[radius, radius * 0.75], P["steel_dk"], sides=7, ao=0.08)
for name, p, q in (("crown_left", A, B), ("crown_right", A, C),
("crown_back", B, C)):
K.tube(root, name,
[(p.x * TAPER, p.y * TAPER, Z1),
(q.x * TAPER, q.y * TAPER, Z1)],
[0.04, 0.04], P["steel_dk"], sides=6, ao=0.04)
tip = Vector((A.x * TAPER, A.y * TAPER))
K.tube(root, "finial_stem",
[(tip.x, tip.y, Z1), (tip.x, tip.y, Z1 + 0.26)],
[0.032, 0.022], P["steel"], sides=6, ao=0.0)
K.crystal(root, "finial", (tip.x, tip.y, Z1 + 0.29), 0.26,
P["steel"], sides=5, seed=7, tilt=(0.12, -0.2, 0.5))
K.crystal(root, "finial_shard", (tip.x + 0.06, tip.y - 0.04, Z1 + 0.20),
0.14, P["patina"], sides=5, seed=11, tilt=(-0.5, 0.3, 1.1))
# Age every part before merging: mottled oxidation and a slight settled
# lean make it read as a found relic rather than a fresh prop.
for i, obj in enumerate(o for o in root.children if o.type == "MESH"):
weather(obj, seed=0.37 + i * 0.61)
lean(root)
for obj in root.children:
for v in obj.data.vertices:
v.co = v.co * SCALE
obj.data.update()
return root
root = build_beacon()
tris = K.triangle_count(root)
K.merge_actor(root, "Beacon")
path = os.path.join(MODEL_DIR, "beacon.glb")
K.export_actor(root, "Beacon", path)
print("[Beacon] %d tris -> %s (%d bytes)" %
(tris, path, os.path.getsize(path)))
# Preview-only camera and lights; excluded from the GLB (root selection only).
cam_data = bpy.data.cameras.new("PreviewCam")
cam = bpy.data.objects.new("PreviewCam", cam_data)
bpy.context.scene.collection.objects.link(cam)
cam.location = (6.5, -8.0, 4.4)
target = Vector((0.0, 0.0, 2.3))
cam.rotation_euler = (target - cam.location).to_track_quat("-Z", "Y").to_euler()
bpy.context.scene.camera = cam
for name, loc, power, size in (
("Key", (4.0, -5.0, 7.0), 1400.0, 5.0),
("Fill", (-5.0, 2.0, 5.0), 700.0, 6.0)):
data = bpy.data.lights.new(name, "AREA")
data.energy, data.shape, data.size = power, "DISK", size
obj = bpy.data.objects.new(name, data)
bpy.context.scene.collection.objects.link(obj)
obj.location = loc
obj.rotation_euler = (target - obj.location).to_track_quat("-Z", "Y").to_euler()
bpy.ops.wm.save_as_mainfile(
filepath=os.path.join(BLEND_DIR, "fbc_beacon.blend"))