cntrl/tools/blender/build_props.py
dandovlatov 336c1249e9 FBC: NIGHT SHIFT - added active skills with autoplay
Added CONCRETE CALL (J) and WARP (K) as player-triggered skills that also autoplay when no skill keys are pressed. Includes cooldown HUD stamps, target telegraphs, warp pull/collapse VFX, a generic SkillSystem, Blender-enhanced concrete rubble, and regression tests.
2026-11-24 22:53:07 +04:00

348 lines
14 KiB
Python

# tools/blender/build_props.py
# FBC: NIGHT SHIFT — props / Objects of Power kit (S11).
#
# Run inside Blender 5.x:
# exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_props.py").read())
#
# Sculpted, ~1k-triangle set pieces for the Oldest House arena: the Hotline,
# Benicoff TV, Service Weapon pedestal, Rubber Duck, filing cabinet, supply
# crate and a Hiss-corrupted floating slab. Each exports as one GLB with one
# merged mesh / material, using the same painted-vertex path as the actors.
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")
CONCEPT_DIR = os.path.join(REPO, "docs", "concept")
for d in (MODEL_DIR, BLEND_DIR, CONCEPT_DIR):
os.makedirs(d, 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 = K.PALETTE
P.update({"plastic": "#2a2d33", "screen": "#10151c", "duck": "#f2c230",
"brass": "#b89348", "glass": "#9fc4cf",
"concrete_lt": "#9d9c96", "concrete_mid": "#6f7072"})
def place(obj, rot=(0.0, 0.0, 0.0), offset=(0.0, 0.0, 0.0)):
"""Rotate/translate a finished painted part about the prop origin."""
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
# ------------------------------------------------------------------- hotline
def build_hotline():
r = K.new_actor("Hotline")
K.loft(r, "table_top", [
{"z": 0.84, "r": (0.78, 0.55), "n": 14},
{"z": 0.89, "r": (0.79, 0.56), "n": 14, "fold": (0.015, 6)},
{"z": 0.94, "r": (0.80, 0.57), "n": 14},
], P["plastic"])
for sx in (-1, 1):
for sy in (-1, 1):
K.tube(r, "leg_%d_%d" % (sx, sy),
[(sx * 0.55, sy * 0.36, 0.02),
(sx * 0.58, sy * 0.38, 0.84)], [0.055, 0.045],
P["steel_dk"], sides=6)
K.plate(r, "drawer", K.octagon(0.40, 0.18), 0.70, 0.83, 0.94,
P["redaction"], shift=(0, -0.42))
K.tube(r, "drawer_pull", [(-0.14, -0.52, 0.76), (0.14, -0.52, 0.76)],
[0.02, 0.02], P["brass"], sides=6)
K.blob(r, "phone_base", (0, 0, 1.04), (0.30, 0.22, 0.09),
P["hiss"], subdiv=3, seed=1, ao=0.05)
K.tube(r, "handset",
[(-0.30, -0.02, 1.19), (-0.16, -0.14, 1.22),
(0.16, -0.14, 1.22), (0.30, -0.02, 1.19)],
[0.055, 0.05, 0.05, 0.055], P["hiss"], sides=10)
K.ring(r, "dial", (0, -0.10, 1.135), 0.11, 0.018, P["redaction"],
segments=10)
for i in range(10):
a = 2.0 * math.pi * i / 10
K.crystal(r, "dial_hole_%d" % i,
(math.cos(a) * 0.10, -0.10 + math.sin(a) * 0.10, 1.14),
0.022, P["redaction"], sides=4, seed=10 + i)
K.crystal(r, "indicator", (0.20, -0.16, 1.13), 0.045,
P["hiss_hot"], sides=5, seed=3)
K.tube(r, "cord",
[(0.30, -0.02, 1.19), (0.40, -0.22, 1.06),
(0.24, -0.40, 0.98), (0.05, -0.32, 1.04)],
[0.014, 0.012, 0.012, 0.012], P["redaction"], sides=5)
return r
# ------------------------------------------------------------------------ tv
def build_tv():
r = K.new_actor("BenicoffTV")
K.loft(r, "stand", [
{"z": 0.02, "r": (0.72, 0.50), "n": 10},
{"z": 0.52, "r": (0.68, 0.47), "n": 10},
{"z": 0.58, "r": (0.74, 0.52), "n": 10},
], P["plastic"], ao=0.10)
K.loft(r, "body", [
{"z": 0.58, "r": (0.62, 0.40), "n": 14},
{"z": 0.85, "r": (0.65, 0.42), "n": 14},
{"z": 1.05, "r": (0.66, 0.43), "n": 14},
{"z": 1.36, "r": (0.66, 0.43), "n": 14},
{"z": 1.70, "r": (0.66, 0.43), "n": 14},
{"z": 1.84, "r": (0.58, 0.38), "n": 14},
], P["plastic"], ao=0.06)
screen = K.plate(r, "screen", K.octagon(0.50, 0.36), 0.0, 0.015, 1.0,
P["screen"], ao=0.0)
place(screen, rot=(math.pi / 2, 0, 0), offset=(0, -0.445, 1.34))
bezel = K.ring(r, "bezel", (0, 0, 0), 0.50, 0.025,
P["steel_dk"], segments=16)
place(bezel, rot=(math.pi / 2, 0, 0), offset=(0, -0.45, 1.34))
K.tube(r, "antenna_l",
[(0.20, 0.10, 1.84), (0.42, 0.12, 2.30)],
[0.016, 0.009], P["steel"], sides=5)
K.tube(r, "antenna_r",
[(-0.20, 0.10, 1.84), (-0.44, 0.14, 2.24)],
[0.016, 0.009], P["steel"], sides=5)
for i, sx in enumerate((-1, 1)):
K.crystal(r, "knob_%d" % i, (sx * 0.46, -0.44, 0.78), 0.055,
P["steel"], sides=6, seed=20 + i,
tilt=(math.pi / 2, 0, 0))
K.plate(r, "vent", K.octagon(0.30, 0.10), 0.0, 0.012, 1.0,
P["redaction"], shift=(0, 0, 1.845))
return r
# ------------------------------------------------------------------ pedestal
def build_pedestal():
r = K.new_actor("Pedestal")
K.loft(r, "plinth", [
{"z": 0.0, "r": (0.62, 0.62), "n": 14},
{"z": 0.10, "r": (0.66, 0.66), "n": 14},
{"z": 0.48, "r": (0.58, 0.58), "n": 14, "fold": (0.015, 5)},
{"z": 0.92, "r": (0.54, 0.54), "n": 14, "fold": (0.02, 5)},
{"z": 1.02, "r": (0.60, 0.60), "n": 14},
], P["concrete"], ao=0.14)
K.plate(r, "top", K.octagon(0.52, 0.52), 1.02, 1.08, 1.0, P["redaction"])
K.tube(r, "weapon_body",
[(0.0, -0.10, 1.26), (0.0, -0.36, 1.30), (0.0, -0.62, 1.34)],
[0.09, 0.075, 0.06], P["plastic"], sides=8)
grip = K.plate(r, "grip", K.octagon(0.07, 0.11), 0.0, 0.20, 0.88,
P["steel_dk"])
place(grip, rot=(math.pi / 2, 0, 0), offset=(0, -0.06, 1.06))
K.crystal(r, "muzzle", (0, -0.64, 1.34), 0.10, P["steel"], sides=6,
seed=5, tilt=(math.pi / 2, 0, 0))
K.crystal(r, "inlay", (0, -0.34, 1.40), 0.07, P["paper"], sides=5,
seed=6)
K.ring(r, "base_glow", (0, 0, 0.12), 0.60, 0.022, P["paper"],
segments=16)
return r
# ---------------------------------------------------------------------- duck
def build_duck():
r = K.new_actor("Duck")
K.loft(r, "plinth", [
{"z": 0.0, "r": (0.42, 0.42), "n": 10},
{"z": 0.08, "r": (0.46, 0.46), "n": 10},
{"z": 0.76, "r": (0.40, 0.40), "n": 10},
{"z": 0.82, "r": (0.44, 0.44), "n": 10},
], P["concrete"], ao=0.14)
K.blob(r, "body", (0, 0, 1.00), (0.26, 0.22, 0.19), P["duck"],
subdiv=3, seed=2, ao=0.04)
K.blob(r, "head", (0, -0.14, 1.22), (0.15, 0.15, 0.15), P["duck"],
subdiv=3, seed=3, ao=0.04)
K.crystal(r, "beak", (0, -0.29, 1.19), 0.12, P["hiss"], sides=6,
seed=4, tilt=(math.pi / 2, 0, 0))
for side in (-1, 1):
K.blob(r, "eye_%d" % side, (side * 0.075, -0.25, 1.26),
(0.018, 0.018, 0.018), P["redaction"], subdiv=1,
seed=10 + side)
K.tube(r, "tail", [(0, 0.20, 1.04), (0, 0.32, 1.14)],
[0.08, 0.025], P["duck"], sides=6)
# Glass case as a slim brass frame (alpha isn't part of the vertex palette).
for sx in (-1, 1):
for sy in (-1, 1):
K.tube(r, "frame_%d_%d" % (sx, sy),
[(sx * 0.33, sy * 0.33, 0.84),
(sx * 0.33, sy * 0.33, 1.48)], [0.014, 0.014],
P["brass"], sides=5)
K.tube(r, "frame_top",
[(-0.33, -0.33, 1.48), (0.33, -0.33, 1.48),
(0.33, 0.33, 1.48), (-0.33, 0.33, 1.48), (-0.33, -0.33, 1.48)],
[0.014] * 5, P["brass"], sides=5)
return r
# ------------------------------------------------------------------- cabinet
def build_cabinet():
r = K.new_actor("Cabinet")
K.loft(r, "body", [
{"z": 0.0, "r": (0.48, 0.36), "n": 14},
{"z": 0.84, "r": (0.48, 0.36), "n": 14},
{"z": 1.68, "r": (0.48, 0.36), "n": 14},
{"z": 1.76, "r": (0.52, 0.40), "n": 14},
], P["redaction"], ao=0.10)
for i in range(4):
z = 0.28 + i * 0.40
K.plate(r, "drawer_%d" % i, K.octagon(0.40, 0.30), 0.0, 0.018,
1.0, P["plastic"], shift=(0, 0, z))
K.tube(r, "handle_%d" % i,
[(-0.18, -0.375, z + 0.10), (0.18, -0.375, z + 0.10)],
[0.022, 0.022], P["steel"], sides=6)
K.plate(r, "label_%d" % i, K.octagon(0.11, 0.025), 0.0, 0.006,
1.0, P["paper"], shift=(0, 0, z + 0.02))
for side in (-1, 1):
K.tube(r, "edge_%d" % side,
[(side * 0.46, -0.34, 0.04), (side * 0.46, -0.34, 1.72)],
[0.018, 0.018], P["steel_dk"], sides=5)
return r
# --------------------------------------------------------------------- crate
def build_crate():
r = K.new_actor("Crate")
K.loft(r, "body", [
{"z": 0.0, "r": (0.52, 0.42), "n": 14, "fold": (0.02, 5)},
{"z": 0.36, "r": (0.53, 0.43), "n": 14, "fold": (0.025, 5)},
{"z": 0.72, "r": (0.54, 0.44), "n": 14, "fold": (0.025, 5)},
{"z": 0.78, "r": (0.56, 0.46), "n": 14},
], P["tan"], ao=0.14)
K.plate(r, "lid", K.octagon(0.56, 0.46), 0.78, 0.86, 0.98,
P["navy_dk"])
for sx in (-1, 1):
for sy in (-1, 1):
K.tube(r, "brace_%d_%d" % (sx, sy),
[(sx * 0.46, sy * 0.36, 0.02),
(sx * 0.46, sy * 0.36, 0.76)], [0.03, 0.03],
P["steel_dk"], sides=5)
K.plate(r, "stencil", K.octagon(0.20, 0.10), 0.0, 0.008, 1.0,
P["redaction"], shift=(0, -0.46, 0.42))
K.ring(r, "seal", (0, 0, 0.87), 0.24, 0.018, P["hiss_dull"],
segments=10)
return r
# -------------------------------------------------------------------- debris
def build_debris():
# A heap of broken concrete, not a single floating slab: the active skill
# CONCRETE CALL reuses this model as its flying pile, so the silhouette has
# to read as rubble at tactical distance. Feet stay at the origin.
r = K.new_actor("Debris")
K.blob(r, "slab", (0, 0, 0.42), (0.92, 0.70, 0.30), P["concrete_lt"],
subdiv=3, warp=0.34, seed=7, smooth=False, ao=0.12)
chunks = [
((-0.55, 0.08, 0.22), (0.40, 0.32, 0.22), 11, "concrete_lt"),
((0.50, 0.18, 0.24), (0.38, 0.30, 0.24), 12, "concrete_mid"),
((0.18, -0.48, 0.20), (0.36, 0.28, 0.20), 13, "concrete_lt"),
((-0.34, -0.38, 0.26), (0.30, 0.26, 0.28), 14, "concrete"),
((0.52, -0.36, 0.32), (0.28, 0.26, 0.32), 15, "concrete_lt"),
((0.00, 0.52, 0.24), (0.34, 0.26, 0.24), 16, "concrete_mid"),
]
for i, (center, scale, seed, tone) in enumerate(chunks):
K.blob(r, "chunk_%d" % i, center, scale, P[tone],
subdiv=2, warp=0.30, seed=seed, smooth=False, ao=0.10)
K.plate(r, "rebar_plate", K.octagon(0.34, 0.22), 0.68, 0.72, 0.9,
P["steel_dk"], shift=(0.14, 0.0))
for i, (x, y, z, tilt) in enumerate([
(-0.40, -0.14, 0.66, (0.3, -0.2, 0.4)),
(0.30, 0.22, 0.70, (-0.4, 0.3, -0.2)),
(0.46, -0.26, 0.60, (0.2, 0.4, 0.3)),
]):
K.crystal(r, "growth_%d" % i, (x, y, z), 0.26, P["hiss"],
sides=5, seed=30 + i, tilt=tilt)
for i in range(3):
K.tube(r, "crack_%d" % i,
[(-0.5 + i * 0.45, -0.4, 0.58),
(-0.3 + i * 0.45, -0.1, 0.68),
(-0.1 + i * 0.45, 0.2, 0.62)],
[0.018, 0.02, 0.014], P["hiss_hot"], sides=5)
# One chunk dips 3 cm under the origin; lift the whole heap so its feet
# sit exactly on the floor after export.
for part in r.children:
for v in part.data.vertices:
v.co.z += 0.03
part.data.update()
return r
BUILDERS = [
("hotline", build_hotline, 1200),
("tv", build_tv, 1200),
("pedestal", build_pedestal, 1000),
("duck", build_duck, 1000),
("cabinet", build_cabinet, 1200),
("crate", build_crate, 1000),
("debris", build_debris, 3000),
]
exported = []
for name, builder, cap in BUILDERS:
root = builder()
K.merge_actor(root, name)
tris = K.triangle_count(root)
print("[budget] %-10s %5d tris (cap %d) %s"
% (name, tris, cap, "OK" if tris <= cap else "OVER"))
out = os.path.join(MODEL_DIR, name + ".glb")
K.export_actor(root, name, out)
exported.append((name, tris, os.path.getsize(out)))
SLOTS = {"Hotline": -7.5, "BenicoffTV": -4.5, "Pedestal": -1.5,
"Duck": 1.5, "Cabinet": 4.5, "Crate": 7.5, "Debris": 10.5}
for obj in bpy.data.objects:
if obj.name in SLOTS:
obj.location.x = SLOTS[obj.name]
world = bpy.data.worlds.new("PropWorld")
bpy.context.scene.world = world
world.use_nodes = True
bg = next(n for n in world.node_tree.nodes if n.type == "BACKGROUND")
bg.inputs["Color"].default_value = (*K.rgb("#0d0f12"), 1.0)
bg.inputs["Strength"].default_value = 0.9
import mathutils
for name, loc, power, col in (
("Key", (-2, -8, 9), 2200, "#eef2ff"),
("HissFill", (8, -1, 5), 1100, "#ff3b46"),
("Rim", (0, 7, 6), 900, "#4ec9b0"),
):
data = bpy.data.lights.new(name, "AREA")
data.energy = power
data.shape = "DISK"
data.size = 8
data.color = K.rgb(col)
obj = bpy.data.objects.new(name, data)
bpy.context.scene.collection.objects.link(obj)
obj.location = loc
obj.rotation_euler = (mathutils.Vector((0, 0, 1)) -
mathutils.Vector(loc)).to_track_quat("-Z", "Y").to_euler()
cam_data = bpy.data.cameras.new("PropCam")
cam = bpy.data.objects.new("PropCam", cam_data)
bpy.context.scene.collection.objects.link(cam)
cam.location = (1.0, -20.0, 9.0)
cam.rotation_euler = (mathutils.Vector((0, 0, 0.95)) -
cam.location).to_track_quat("-Z", "Y").to_euler()
cam_data.lens = 42
scene = bpy.context.scene
scene.camera = cam
engines = [i.identifier for i in bpy.types.RenderSettings.bl_rna.properties["engine"].enum_items]
scene.render.engine = "BLENDER_EEVEE_NEXT" if "BLENDER_EEVEE_NEXT" in engines else engines[0]
scene.render.resolution_x = 1200
scene.render.resolution_y = 520
scene.render.image_settings.file_format = "PNG"
scene.render.filepath = os.path.join(CONCEPT_DIR, "props_lineup.png")
bpy.ops.render.render(write_still=True)
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(BLEND_DIR, "fbc_props.blend"))
print("[done] props:", ", ".join("%s(%d tris)" % (n, t)
for n, t, _ in exported))