cntrl/tools/blender/build_thermo_door.py

104 lines
3.8 KiB
Python

# tools/blender/build_thermo_door.py
# FBC: NIGHT SHIFT — Control-style thermo door kit for room thresholds.
#
# Run headlessly:
# blender --background --factory-startup --python tools/blender/build_thermo_door.py
#
# Two GLBs: a fixed frame and one symmetric sliding panel (drawn twice, one
# per side, so retracted panels cost two draw calls). Both use the repo's
# one-mesh / painted-vertex path via actor_kit.
import math
import os
import sys
import bpy
from mathutils import Euler, 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)
P.update({"hazard": "#f5c518"})
def box(root, name, cx, cy, z0, dx, dy, dz, value, ao=0.06):
hw, hd = dx * 0.5, dy * 0.5
return K.plate(root, name,
[(-hw, -hd), (hw, -hd), (hw, hd), (-hw, hd)],
z0, z0 + dz, 1.0, value, shift=(cx, cy), ao=ao)
def place(obj, rot=(0.0, 0.0, 0.0), offset=(0.0, 0.0, 0.0)):
mat = Euler(rot).to_matrix()
shift = Vector(offset)
for v in obj.data.vertices:
v.co = shift + mat @ v.co
obj.data.update()
return obj
def build_frame():
r = K.new_actor("ThermoFrame")
for sx in (-1, 1):
box(r, "jamb_%d" % sx, sx * 3.85, 0.0, 0.0, 0.30, 1.20, 4.60,
P["steel_dk"], 0.10)
box(r, "track_%d" % sx, sx * 3.62, 0.0, 0.12, 0.10, 0.90, 4.20,
P["redaction"], 0.02)
box(r, "lintel", 0.0, 0.0, 4.05, 8.0, 1.20, 0.55, P["steel_dk"], 0.08)
box(r, "sill", 0.0, 0.0, 0.0, 8.0, 1.20, 0.16, P["steel"], 0.08)
for sx in (-1, 1):
for i in range(8):
box(r, "chev_%d_%d" % (sx, i), sx * 3.85, -0.61, 0.35 + i * 0.5,
0.22, 0.02, 0.18,
P["hazard"] if i % 2 == 0 else P["redaction"], 0.0)
box(r, "plate", 0.0, -0.61, 4.12, 2.2, 0.02, 0.32, P["hazard"], 0.0)
for i in range(5):
box(r, "plate_bar_%d" % i, -0.8 + i * 0.4, -0.63, 4.2,
0.18, 0.02, 0.10, P["redaction"], 0.0)
return r
def build_panel():
r = K.new_actor("ThermoPanel")
for sx in (-1, 1):
box(r, "edge_%d" % sx, sx * 1.76, 0.0, 0.0, 0.18, 0.34, 4.0,
P["steel_dk"], 0.10)
box(r, "top", 0.0, 0.0, 3.82, 3.7, 0.34, 0.18, P["steel_dk"], 0.08)
box(r, "bottom", 0.0, 0.0, 0.0, 3.7, 0.34, 0.18, P["steel_dk"], 0.08)
box(r, "face", 0.0, -0.18, 0.18, 3.34, 0.03, 3.64, P["hiss_dull"], 0.06)
box(r, "seam", 0.0, -0.205, 0.20, 0.05, 0.02, 3.55, P["redaction"], 0.0)
box(r, "band", 0.0, -0.21, 1.78, 3.20, 0.02, 0.50, P["hazard"], 0.0)
for i in range(7):
box(r, "band_bar_%d" % i, -1.32 + i * 0.44, -0.225, 1.76,
0.16, 0.02, 0.54, P["redaction"], 0.0)
ring = K.ring(r, "lock_ring", (0, 0, 0), 0.44, 0.055,
P["steel"], segments=16)
place(ring, rot=(math.pi / 2, 0, 0), offset=(0, -0.235, 2.65))
disc = K.plate(r, "lock_disc", K.octagon(0.34), -0.02, 0.02, 1.0,
P["hiss"], ao=0.0)
place(disc, rot=(math.pi / 2, 0, 0), offset=(0, -0.25, 2.65))
return r
for name, fn, builder in (("ThermoFrame", "thermo_frame.glb", build_frame),
("ThermoPanel", "thermo_panel.glb", build_panel)):
root = builder()
tris = K.triangle_count(root)
K.merge_actor(root, name)
path = os.path.join(MODEL_DIR, fn)
K.export_actor(root, name, path)
print("[%s] %d tris -> %s (%d bytes)" %
(name, tris, path, os.path.getsize(path)))
bpy.ops.wm.save_as_mainfile(
filepath=os.path.join(BLEND_DIR, "fbc_thermo_door.blend"))