SLC_Game/01_3D-Druck/blender/raci-board.py
2026-06-09 08:13:12 +02:00

189 lines
7.8 KiB
Python

# RACI-Konsolen-Board (rund) — Blender-Generator (bpy) · v2
# SLC-Workshop Tabletop · 1 Blender-Unit = 1 mm
# Runde Puck-Flaeche, zentrale Acryl-Chip-Mulde (Ø40), 10 Sockel in 4 RACI-Sektoren
# (R3 A1 C4 I2), gleich grosse Sektor-Woerter tangential um die Sockel, Kartenhalter
# oben (Aussparung), Phasenname (DESIGN) unten im Innenkreis, Design-Blau.
# Lauf: Scripting -> Open -> Run | blender -b -P raci-board.py
import bpy, math, os
# ----------------------------- Parameter (mm) -----------------------------
R_BOARD, BASE_H = 90.0, 12.0
EDGE_BEVEL, EDGE_SEG = 1.6, 4
CHIP_D, CHIP_DEP = 40.6, 1.8 # Acryl-Chip Ø40 x 2 mm
NOTCH_D = 12.0
SOCK_D, SOCK_DEP = 25.3, 1.5 # Figuren-Sockel Ø24,5
SOCK_LEAD = 0.6
RING_R = 64.0
PHASE_NAME = "DESIGN"
PHASE_COLOR = (0.184, 0.502, 0.788, 1) # #2f80c9 Design-Blau
# Sektoren: Name, Wort-Mittenwinkel, Sockel-Winkel (Grad, 90=oben). Top frei fuer Karte.
SECTORS = [
("RESPONSIBLE", 165, [135, 165, 195]),
("ACCOUNTABLE", 50, [50]),
("CONSULTED", -20, [25, -5, -35, -65]),
("INFORMED", -110, [-95, -125]),
]
DIVIDERS = [37.5, -80, -145] # Grenzen zwischen Sektoren (nicht im Karten-Spalt)
RIDGE_H, RIDGE_W = 2.6, 3.4
WORD_SIZE, WORD_DEP = 5.0, 0.8
WORD_R = RING_R + SOCK_D/2 + 9 # ausserhalb der Sockel
DESIGN_SIZE, DESIGN_DEP = 9.0, 1.0
DESIGN_POS = (0, -38) # unten im Innenkreis, gegenueber Kartenhalter
CARD_CY, CARD_BW, CARD_BD, CARD_BH = 70.0, 76.0, 20.0, 16.0
SLOT_W, SLOT_T, SLOT_TILT = 63.0, 4.0, 12.0
TOP = BASE_H
def _outdir():
d = os.path.dirname(bpy.data.filepath)
if d: return d
try: return os.path.dirname(os.path.abspath(__file__))
except NameError: return os.path.expanduser("~")
HERE = _outdir()
STL_OUT = os.path.join(HERE, "raci-board.stl")
PNG_OUT = os.path.join(HERE, "raci_preview.png")
print("Ausgabe-Ordner:", HERE)
# ----------------------------- Helfer -----------------------------
def clear_scene():
bpy.ops.object.select_all(action='SELECT'); bpy.ops.object.delete(use_global=False)
for blk in (bpy.data.meshes, bpy.data.materials, bpy.data.curves):
for d in list(blk):
if d.users == 0: blk.remove(d)
def cube(sx, sy, sz, loc):
bpy.ops.mesh.primitive_cube_add(size=1, location=loc)
o = bpy.context.object; o.scale = (sx, sy, sz)
bpy.ops.object.transform_apply(scale=True); return o
def cyl(d, h, loc, verts=96):
bpy.ops.mesh.primitive_cylinder_add(radius=d/2.0, depth=h, location=loc, vertices=verts)
return bpy.context.object
def boolean(obj, tool, op='DIFFERENCE'):
m = obj.modifiers.new("bool", 'BOOLEAN'); m.operation = op; m.object = tool
try: m.solver = 'EXACT'
except Exception: pass
bpy.context.view_layer.objects.active = obj
bpy.ops.object.modifier_apply(modifier=m.name)
bpy.data.objects.remove(tool, do_unlink=True)
def apply_bevel(obj, width=EDGE_BEVEL, seg=EDGE_SEG, ang=30):
m = obj.modifiers.new("bevel", 'BEVEL'); m.width = width; m.segments = seg
m.limit_method = 'ANGLE'; m.angle_limit = math.radians(ang)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.modifier_apply(modifier=m.name)
def engrave(board, body, x, y, rotz=0, size=WORD_SIZE, dep=WORD_DEP):
try:
bpy.ops.object.text_add(location=(x, y, TOP - dep))
t = bpy.context.object; t.data.body = body; t.data.size = size
t.data.extrude = dep + 1.5; t.data.align_x='CENTER'; t.data.align_y='CENTER'
t.rotation_euler = (0, 0, math.radians(rotz))
bpy.ops.object.convert(target='MESH'); boolean(board, t, 'DIFFERENCE')
except Exception as e:
print("Label uebersprungen (%s): %s" % (body, e))
# ----------------------------- Aufbau -----------------------------
clear_scene()
# Runde Platte + Kartenblock (oben), beide gefast, vereinen
base = cyl(R_BOARD*2, BASE_H, (0, 0, BASE_H/2), verts=160)
apply_bevel(base)
block = cube(CARD_BW, CARD_BD, BASE_H + CARD_BH, (0, CARD_CY, (BASE_H + CARD_BH)/2))
apply_bevel(block, width=1.0)
boolean(base, block, 'UNION')
# Chip-Mulde + Greifkerbe
boolean(base, cyl(CHIP_D, 6, (0, 0, TOP - CHIP_DEP + 3)), 'DIFFERENCE')
boolean(base, cyl(NOTCH_D, 6, (0, -CHIP_D/2, TOP - CHIP_DEP + 3)), 'DIFFERENCE')
# Sockelmulden (mit Einfuehr-Fase)
for _, _, angles in SECTORS:
for a in angles:
x = RING_R*math.cos(math.radians(a)); y = RING_R*math.sin(math.radians(a))
boolean(base, cyl(SOCK_D, 6, (x, y, TOP - SOCK_DEP + 3)), 'DIFFERENCE')
# Sektor-Trennstege (erhaben)
ri, ro = CHIP_D/2 + 3, RING_R + SOCK_D/2 + 4
for a in DIVIDERS:
rmid = (ri+ro)/2
r = cube(ro-ri, RIDGE_W, RIDGE_H, (rmid*math.cos(math.radians(a)),
rmid*math.sin(math.radians(a)), TOP + RIDGE_H/2))
r.rotation_euler = (0, 0, math.radians(a)); bpy.ops.object.transform_apply(rotation=False)
boolean(base, r, 'UNION')
# Action-Card-Schlitz (oben offen, nach hinten geneigt)
slot = cube(SLOT_W, SLOT_T, 40, (0, CARD_CY, 22))
slot.rotation_euler = (math.radians(-SLOT_TILT), 0, 0); bpy.ops.object.transform_apply(rotation=True)
boolean(base, slot, 'DIFFERENCE')
# Gravierte Rand-Linie (rund)
rim = cyl((R_BOARD-7)*2, 1.4, (0, 0, TOP-0.7))
boolean(rim, cyl((R_BOARD-8.6)*2, 2.0, (0, 0, TOP-0.7)), 'DIFFERENCE')
boolean(base, rim, 'DIFFERENCE')
# Sektor-Woerter: gleich gross, tangential um die Sockel
for name, wc, _ in SECTORS:
rot = (wc - 90) if math.sin(math.radians(wc)) >= 0 else (wc + 90) # lesbar tangential
engrave(base, name, WORD_R*math.cos(math.radians(wc)), WORD_R*math.sin(math.radians(wc)), rot)
# Phasenname unten im Innenkreis
engrave(base, PHASE_NAME, DESIGN_POS[0], DESIGN_POS[1], 0, DESIGN_SIZE, DESIGN_DEP)
base.name = "RACI-Board"
try: bpy.ops.object.shade_auto_smooth(angle=math.radians(30))
except Exception:
try: bpy.ops.object.shade_flat()
except Exception: pass
# ----------------------------- Material (Design-Blau) -----------------------------
mat = bpy.data.materials.new("Phase"); mat.use_nodes = True
bsdf = next((n for n in mat.node_tree.nodes if n.type == 'BSDF_PRINCIPLED'), None)
if bsdf:
bsdf.inputs["Base Color"].default_value = PHASE_COLOR
try: bsdf.inputs["Roughness"].default_value = 0.5
except Exception: pass
base.data.materials.clear(); base.data.materials.append(mat)
# ----------------------------- Vorschau-Render -----------------------------
try:
sc = bpy.context.scene
try:
bg = next((n for n in sc.world.node_tree.nodes if n.type == 'BACKGROUND'), None)
if bg: bg.inputs[1].default_value = 1.2
except Exception: pass
bpy.ops.object.light_add(type='SUN', location=(140, -180, 260)); bpy.context.object.data.energy = 3.5
bpy.ops.object.light_add(type='AREA', location=(-140, -60, 180))
bpy.context.object.data.energy = 5000; bpy.context.object.data.size = 260
bpy.ops.object.empty_add(location=(0, 0, 5)); tgt = bpy.context.object
bpy.ops.object.camera_add(location=(215, -270, 250)); cam = bpy.context.object
cam.data.lens = 50
con = cam.constraints.new('TRACK_TO'); con.target = tgt
con.track_axis = 'TRACK_NEGATIVE_Z'; con.up_axis = 'UP_Y'
sc.camera = cam
sc.render.resolution_x, sc.render.resolution_y = 1500, 1100
sc.render.filepath = PNG_OUT
try: sc.render.engine = 'BLENDER_EEVEE_NEXT'
except Exception:
try: sc.render.engine = 'BLENDER_EEVEE'
except Exception: pass
bpy.ops.render.render(write_still=True); print("Vorschau:", PNG_OUT)
except Exception as e:
print("Render uebersprungen:", e)
# ----------------------------- STL-Export -----------------------------
bpy.ops.object.select_all(action='DESELECT'); base.select_set(True)
bpy.context.view_layer.objects.active = base
try:
bpy.ops.wm.stl_export(filepath=STL_OUT, export_selected_objects=True)
except Exception:
try: bpy.ops.export_mesh.stl(filepath=STL_OUT, use_selection=True)
except Exception as e: print("STL-Export manuell noetig:", e)
print("STL:", STL_OUT)