337 lines
14 KiB
Python
337 lines
14 KiB
Python
# tools/blender/build_room_props.py
|
|
# FBC: NIGHT SHIFT — S16 open-plan room kit.
|
|
#
|
|
# Run inside Blender 5.x:
|
|
# exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_room_props.py").read())
|
|
#
|
|
# Eight sculpted set pieces for the expanded Oldest House floor: office desk,
|
|
# meeting table, swivel chair, workstation computer, potted plant, sofa, floor
|
|
# lamp and fabric partition. Each exports as one GLB with one merged mesh /
|
|
# material and painted COLOR_0 vertex colours, matching build_props.py.
|
|
|
|
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")
|
|
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", "screen_glow": "#2b8f9c",
|
|
"wood": "#4a3f33", "wood_lt": "#655643", "fabric": "#495463",
|
|
"fabric_lt": "#667386", "fabric_dk": "#313a46", "pot": "#7d6f5c",
|
|
"leaf": "#3f6b4f", "leaf_lt": "#6b9a68", "brass": "#b89348",
|
|
})
|
|
|
|
|
|
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."""
|
|
from mathutils import Euler
|
|
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 panel(root, name, w, h, t, x, y, z, value, ao=0.06):
|
|
"""A vertical panel centred at (x, y, z), facing -Y, from a flat plate."""
|
|
outline = [(-w / 2, -h / 2), (w / 2, -h / 2),
|
|
(w / 2, h / 2), (-w / 2, h / 2)]
|
|
obj = K.plate(root, name, outline, 0.0, t, 1.0, value, ao=ao)
|
|
return place(obj, rot=(math.pi / 2, 0, 0), offset=(x, y, z))
|
|
|
|
|
|
# ------------------------------------------------------------------ office desk
|
|
def build_desk():
|
|
r = K.new_actor("OfficeDesk")
|
|
# Oversized FBC-issue desk: 2.9 x 1.35 m footprint so it reads as furniture
|
|
# next to a 2 m guard at tactical camera distance.
|
|
K.plate(r, "top", K.octagon(1.45, 0.68), 0.71, 0.78, 1.0, P["wood"])
|
|
K.plate(r, "top_inlay", K.octagon(1.30, 0.56), 0.784, 0.786, 1.0,
|
|
P["wood_lt"], ao=0.0)
|
|
for sx in (-1, 1):
|
|
for sy in (-1, 1):
|
|
K.tube(r, "leg_%d_%d" % (sx, sy),
|
|
[(sx * 1.28, sy * 0.55, 0.03),
|
|
(sx * 1.28, sy * 0.55, 0.71)], [0.05, 0.045],
|
|
P["steel_dk"], sides=6)
|
|
panel(r, "modesty", 2.5, 0.34, 0.04, -0.14, 0.58, 0.50, P["plastic"])
|
|
K.loft(r, "drawers", [
|
|
{"z": 0.0, "r": (0.24, 0.50), "n": 12, "c": (1.08, 0.0)},
|
|
{"z": 0.66, "r": (0.25, 0.51), "n": 12, "c": (1.08, 0.0)},
|
|
{"z": 0.70, "r": (0.26, 0.52), "n": 12, "c": (1.08, 0.0)},
|
|
], P["plastic"])
|
|
for i in range(2):
|
|
z = 0.18 + i * 0.28
|
|
panel(r, "drawer_front_%d" % i, 0.44, 0.22, 0.02,
|
|
1.08, -0.535, z, P["redaction"])
|
|
K.tube(r, "pull_%d" % i, [(0.94, -0.565, z + 0.06),
|
|
(1.22, -0.565, z + 0.06)],
|
|
[0.018, 0.018], P["steel"], sides=6)
|
|
K.ring(r, "grommet", (-0.75, -0.20, 0.79), 0.07, 0.014,
|
|
P["steel_dk"], segments=10)
|
|
return r
|
|
|
|
|
|
# ---------------------------------------------------------------- meeting table
|
|
def build_meeting_table():
|
|
r = K.new_actor("MeetingTable")
|
|
K.plate(r, "top", K.octagon(3.20, 1.15), 0.74, 0.82, 1.0, P["wood"])
|
|
for i, sx in enumerate((-1, 1)):
|
|
K.loft(r, "pedestal_%d" % i, [
|
|
{"z": 0.0, "r": (0.30, 0.62), "n": 10, "c": (sx * 1.85, 0.0)},
|
|
{"z": 0.62, "r": (0.24, 0.54), "n": 10, "c": (sx * 1.85, 0.0)},
|
|
{"z": 0.74, "r": (0.30, 0.60), "n": 10, "c": (sx * 1.85, 0.0)},
|
|
], P["plastic"])
|
|
K.plate(r, "foot_%d" % i, K.octagon(0.42, 0.72), 0.0, 0.06, 1.0,
|
|
P["steel_dk"], shift=(sx * 1.85, 0.0))
|
|
for x in (-1.1, 0.0, 1.1):
|
|
K.plate(r, "seam_%g" % x, K.octagon(0.012, 1.10), 0.822, 0.825, 1.0,
|
|
P["wood_lt"], shift=(x, 0.0), ao=0.0)
|
|
return r
|
|
|
|
|
|
# --------------------------------------------------------------- swivel chair
|
|
def build_chair():
|
|
r = K.new_actor("OfficeChair")
|
|
K.loft(r, "seat", [
|
|
{"z": 0.44, "r": (0.27, 0.25), "n": 12},
|
|
{"z": 0.50, "r": (0.30, 0.27), "n": 12},
|
|
{"z": 0.54, "r": (0.27, 0.24), "n": 12},
|
|
], P["fabric"], ao=0.08)
|
|
panel(r, "back", 0.50, 0.52, 0.06, 0.0, 0.25, 0.82, P["fabric_lt"])
|
|
panel(r, "back_spine", 0.10, 0.46, 0.02, 0.0, 0.30, 0.82, P["fabric_dk"])
|
|
K.tube(r, "post", [(0.0, 0.0, 0.10), (0.0, 0.0, 0.45)],
|
|
[0.055, 0.045], P["steel_dk"], sides=8)
|
|
for i in range(5):
|
|
a = 2.0 * math.pi * i / 5
|
|
x, y = math.cos(a) * 0.32, math.sin(a) * 0.32
|
|
K.tube(r, "spoke_%d" % i,
|
|
[(0.0, 0.0, 0.09), (x, y, 0.07)],
|
|
[0.035, 0.025], P["steel_dk"], sides=6)
|
|
K.blob(r, "caster_%d" % i, (x, y, 0.045), (0.055, 0.055, 0.045),
|
|
P["redaction"], subdiv=1, ao=0.0)
|
|
return r
|
|
|
|
|
|
# ------------------------------------------------------------------- computer
|
|
def build_computer():
|
|
r = K.new_actor("Computer")
|
|
K.plate(r, "stand_base", K.octagon(0.18, 0.12), 0.0, 0.025, 1.0,
|
|
P["plastic"], shift=(0.0, 0.10))
|
|
K.tube(r, "neck", [(0.0, 0.10, 0.02), (0.0, 0.02, 0.22)],
|
|
[0.045, 0.035], P["steel_dk"], sides=8)
|
|
panel(r, "bezel", 0.68, 0.42, 0.04, 0.0, 0.0, 0.44, P["plastic"])
|
|
panel(r, "screen", 0.60, 0.34, 0.012, 0.0, -0.055, 0.44,
|
|
P["screen_glow"], ao=0.0)
|
|
panel(r, "scanline", 0.52, 0.018, 0.006, 0.0, -0.068, 0.51,
|
|
P["teal"], ao=0.0)
|
|
K.plate(r, "keyboard", K.octagon(0.31, 0.11), 0.005, 0.03, 1.0,
|
|
P["plastic"], shift=(0.0, -0.42))
|
|
for row in range(3):
|
|
K.plate(r, "keys_%d" % row, K.octagon(0.27, 0.012), 0.032, 0.034, 1.0,
|
|
P["steel_dk"], shift=(0.0, -0.47 + row * 0.045), ao=0.0)
|
|
K.blob(r, "mouse", (0.42, -0.38, 0.025), (0.055, 0.085, 0.025),
|
|
P["plastic"], subdiv=1, ao=0.0)
|
|
K.loft(r, "tower", [
|
|
{"z": 0.0, "r": (0.10, 0.20), "n": 10, "c": (0.54, 0.18)},
|
|
{"z": 0.36, "r": (0.10, 0.20), "n": 10, "c": (0.54, 0.18)},
|
|
{"z": 0.38, "r": (0.11, 0.21), "n": 10, "c": (0.54, 0.18)},
|
|
], P["plastic"])
|
|
panel(r, "tower_vent", 0.13, 0.22, 0.008, 0.54, -0.025, 0.20,
|
|
P["screen"], ao=0.0)
|
|
return r
|
|
|
|
|
|
# ----------------------------------------------------------------------- plant
|
|
def build_plant():
|
|
r = K.new_actor("Plant")
|
|
K.loft(r, "pot", [
|
|
{"z": 0.0, "r": (0.19, 0.19), "n": 12},
|
|
{"z": 0.06, "r": (0.23, 0.23), "n": 12},
|
|
{"z": 0.44, "r": (0.27, 0.27), "n": 12},
|
|
{"z": 0.49, "r": (0.29, 0.29), "n": 12},
|
|
], P["pot"])
|
|
K.ring(r, "rim", (0.0, 0.0, 0.49), 0.28, 0.022, P["wood_lt"], segments=12)
|
|
K.plate(r, "soil", K.octagon(0.25, 0.25), 0.47, 0.485, 1.0,
|
|
P["redaction"], ao=0.0)
|
|
K.tube(r, "trunk", [(0.0, 0.0, 0.48), (0.02, 0.0, 0.95),
|
|
(0.0, 0.02, 1.45)], [0.045, 0.032, 0.018],
|
|
P["wood"], sides=7)
|
|
for i in range(9):
|
|
a = 2.0 * math.pi * i / 9 + 0.3
|
|
z = 0.92 + (i % 3) * 0.22
|
|
rad = 0.30 + (i % 2) * 0.08
|
|
x, y = math.cos(a) * rad, math.sin(a) * rad
|
|
leaf = K.plate(r, "leaf_%d" % i,
|
|
[(0.0, -0.30), (0.14, 0.0), (0.0, 0.30), (-0.14, 0.0)],
|
|
0.0, 0.018, 1.0,
|
|
P["leaf_lt"] if i % 3 == 0 else P["leaf"], ao=0.04)
|
|
place(leaf, rot=(0.55, 0.0, a + math.pi / 2), offset=(x, y, z))
|
|
return r
|
|
|
|
|
|
# ------------------------------------------------------------------------ sofa
|
|
def build_sofa():
|
|
r = K.new_actor("Sofa")
|
|
K.loft(r, "base", [
|
|
{"z": 0.08, "r": (1.14, 0.40), "n": 14},
|
|
{"z": 0.44, "r": (1.18, 0.42), "n": 14},
|
|
{"z": 0.48, "r": (1.16, 0.42), "n": 14},
|
|
], P["fabric"], ao=0.10)
|
|
panel(r, "back", 2.36, 0.55, 0.12, 0.0, 0.38, 0.78, P["fabric_dk"])
|
|
for sx in (-1, 1):
|
|
K.loft(r, "arm_%d" % sx, [
|
|
{"z": 0.44, "r": (0.14, 0.38), "n": 10, "c": (sx * 1.06, 0.0)},
|
|
{"z": 0.72, "r": (0.15, 0.40), "n": 10, "c": (sx * 1.06, 0.0)},
|
|
], P["fabric"])
|
|
for i, x in enumerate((-0.70, 0.0, 0.70)):
|
|
K.blob(r, "cushion_%d" % i, (x, -0.05, 0.52), (0.36, 0.34, 0.10),
|
|
P["fabric_lt"], subdiv=2, seed=20 + i, ao=0.05)
|
|
K.blob(r, "back_cushion_%d" % i, (x, 0.30, 0.80), (0.34, 0.10, 0.22),
|
|
P["fabric"], subdiv=1, seed=30 + i, ao=0.04)
|
|
for sx in (-1, 1):
|
|
for sy in (-1, 1):
|
|
K.tube(r, "leg_%d_%d" % (sx, sy),
|
|
[(sx * 0.92, sy * 0.28, 0.02), (sx * 0.92, sy * 0.28, 0.12)],
|
|
[0.035, 0.035], P["steel_dk"], sides=6)
|
|
return r
|
|
|
|
|
|
# ------------------------------------------------------------------- floor lamp
|
|
def build_lamp():
|
|
r = K.new_actor("FloorLamp")
|
|
K.loft(r, "base", [
|
|
{"z": 0.0, "r": (0.28, 0.28), "n": 14},
|
|
{"z": 0.05, "r": (0.29, 0.29), "n": 14},
|
|
{"z": 0.09, "r": (0.22, 0.22), "n": 14},
|
|
], P["steel_dk"])
|
|
K.tube(r, "pole", [(0.0, 0.0, 0.08), (0.0, 0.0, 1.62)],
|
|
[0.028, 0.022], P["steel"], sides=8)
|
|
K.loft(r, "shade", [
|
|
{"z": 1.26, "r": (0.28, 0.28), "n": 14},
|
|
{"z": 1.62, "r": (0.11, 0.11), "n": 14},
|
|
], P["paper"], ao=0.0)
|
|
K.blob(r, "bulb", (0.0, 0.0, 1.30), (0.12, 0.12, 0.12),
|
|
"#fff3d0", subdiv=2, ao=0.0)
|
|
K.ring(r, "shade_rim", (0.0, 0.0, 1.26), 0.28, 0.014,
|
|
P["brass"], segments=14)
|
|
return r
|
|
|
|
|
|
# ------------------------------------------------------------------- partition
|
|
def build_partition():
|
|
r = K.new_actor("Partition")
|
|
panel(r, "fabric", 2.96, 1.28, 0.07, 0.0, 0.0, 0.86, P["fabric_dk"])
|
|
panel(r, "stripe", 2.80, 0.10, 0.01, 0.0, -0.05, 1.22, P["board"], ao=0.0)
|
|
K.tube(r, "top_rail",
|
|
[(-1.50, 0.0, 1.53), (1.50, 0.0, 1.53)],
|
|
[0.028, 0.028], P["steel"], sides=6)
|
|
for sx in (-1, 1):
|
|
K.tube(r, "edge_%d" % sx,
|
|
[(sx * 1.50, 0.0, 0.20), (sx * 1.50, 0.0, 1.53)],
|
|
[0.026, 0.026], P["steel"], sides=6)
|
|
K.tube(r, "foot_%d" % sx,
|
|
[(sx * 1.30, -0.38, 0.05), (sx * 1.30, 0.38, 0.05)],
|
|
[0.04, 0.04], P["steel_dk"], sides=6)
|
|
return r
|
|
|
|
|
|
# --------------------------------------------------------- lightswitch plate
|
|
def build_switch():
|
|
r = K.new_actor("Switch")
|
|
panel(r, "plate", 0.22, 0.52, 0.035, 0.0, 0.0, 0.45, P["paper"])
|
|
panel(r, "face", 0.17, 0.45, 0.014, 0.0, -0.045, 0.45, P["plastic"])
|
|
K.crystal(r, "toggle", (0.0, -0.09, 0.50), 0.055, P["board"], sides=6,
|
|
seed=1, tilt=(math.pi / 2, 0, 0), ao=0.0)
|
|
for i, z in enumerate((0.28, 0.62)):
|
|
K.crystal(r, "screw_%d" % i, (0.0, -0.07, z), 0.018, P["steel"],
|
|
sides=5, seed=10 + i, tilt=(math.pi / 2, 0, 0), ao=0.0)
|
|
return r
|
|
|
|
|
|
BUILDERS = [
|
|
("desk", build_desk, 1200),
|
|
("meeting_table", build_meeting_table, 1000),
|
|
("chair", build_chair, 1200),
|
|
("computer", build_computer, 1200),
|
|
("plant", build_plant, 1200),
|
|
("sofa", build_sofa, 1400),
|
|
("lamp", build_lamp, 1000),
|
|
("partition", build_partition, 1000),
|
|
("switch", build_switch, 300),
|
|
]
|
|
|
|
exported = []
|
|
for name, builder, cap in BUILDERS:
|
|
root = builder()
|
|
K.merge_actor(root, name)
|
|
tris = K.triangle_count(root)
|
|
print("[budget] %-13s %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 = [-16.0, -12.0, -8.0, -4.0, 0.0, 4.0, 8.0, 12.0, 16.0]
|
|
for obj, x in zip(K.ROOTS, SLOTS):
|
|
obj.location.x = x
|
|
|
|
world = bpy.data.worlds.new("RoomWorld")
|
|
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", (-4, -10, 9), 4200, "#eef2ff"),
|
|
("HissFill", (13, -1, 5), 1400, "#ff3b46"),
|
|
("Rim", (0, 8, 6), 1600, "#4ec9b0"),
|
|
):
|
|
data = bpy.data.lights.new(name, "AREA")
|
|
data.energy = power
|
|
data.shape = "DISK"
|
|
data.size = 9
|
|
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 = (Vector((0, 0, 1)) - Vector(loc)).to_track_quat("-Z", "Y").to_euler()
|
|
|
|
cam_data = bpy.data.cameras.new("RoomCam")
|
|
cam = bpy.data.objects.new("RoomCam", cam_data)
|
|
bpy.context.scene.collection.objects.link(cam)
|
|
cam.location = (0.0, -38.0, 13.0)
|
|
cam.rotation_euler = (Vector((0, 0, 1.0)) - cam.location).to_track_quat("-Z", "Y").to_euler()
|
|
cam_data.lens = 34
|
|
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 = 1800
|
|
scene.render.resolution_y = 650
|
|
scene.render.image_settings.file_format = "PNG"
|
|
scene.render.filepath = os.path.join(CONCEPT_DIR, "room_props_lineup.png")
|
|
bpy.ops.render.render(write_still=True)
|
|
|
|
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(BLEND_DIR, "fbc_room_props.blend"))
|
|
print("[done] room props:", ", ".join("%s(%d tris)" % (n, t)
|
|
for n, t, _ in exported))
|