Skip to content

Commit ecb452c

Browse files
TMHSDigitalclaude
andcommitted
fix(examples): redesign turntable as a lathed display turntable with a frame-tick dial
The copper Suzanne sat on a plain two-disc plinth. The render-only staging is now a display turntable: a stepped, vented motor housing with a front status lamp, a steel platter with an inset rubber mat, one brass tick per keyed frame on the platter rim (FRAMES ticks, 10 degrees apart, a longer one every 90) so the keyed 0..360 span reads as a dial, and an amber arc arrow on the mat showing the direction of the keyed +Z turn. The steel is rougher than the old platter, which blew out to white under the key. The render path now runs the gallery_framing gate (exit 10, added to the README table). The rotation keys, the sampled frames and the check are unchanged. Evidence (live runs, local): - .scratch/blender-5.2.1-windows-x64/blender.exe (Blender 5.2.1 LTS): check-only exit 0, branch=5.0+ ensure-helper rot_z 0.0 / 3.0518 / 6.2832 drives=True. --no-keys exits 3 ("rotation keys do not drive playback"). - .scratch/blender-4.5.11-windows-x64/blender.exe (Blender 4.5.11 LTS): --output exits 0, branch=4.4/4.5 strip.channelbag with the same rot_z samples, framing_ok. - Framing: fill y=0.822; margins l=0.263 r=0.287 b=0.056 t=0.122. - Contact sheet: candidate luma 0.245 / stage 0.208 / warmth -0.029 / sat 0.208, against armature-bend 0.243/0.192/-0.144/0.237, damped-track-aim 0.237/0.218/+0.105/0.178 and bmesh-gear 0.237/0.252/+0.092/0.153. Warmth is slightly negative from the cool floor under the housing; the warm wedge reads on the wall. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 54ad091 commit ecb452c

7 files changed

Lines changed: 201 additions & 57 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ fails creating the 5.x RNA.
677677
<table>
678678
<tr>
679679
<td width="46%" valign="middle">
680-
<a href="examples/turntable/"><img src="examples/turntable/preview.webp" alt="Turntable: a copper Suzanne mid-rotation on a dark studio floor, rendered with EEVEE" /></a>
680+
<a href="examples/turntable/"><img src="examples/turntable/preview.webp" alt="Turntable: a copper Suzanne on a lathed display turntable with a vented motor base, a platter rim ticked once per keyed frame, and an amber arrow showing the keyed turn" /></a>
681681
</td>
682682
<td valign="middle">
683683

6.89 KB
Loading
4.99 KB
Loading

‎examples/gallery.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"name": "turntable",
2323
"dir": "examples/turntable",
2424
"teaches": "A slotted-actions Z-rotation turntable keyed through the cross-version channelbag path (get_channelbag_for_slot).",
25-
"alt": "A smooth copper monkey head (Suzanne) turned three-quarters on a black turntable with a brushed metal platter.",
25+
"alt": "A copper Suzanne turned three-quarters on a lathed display turntable: vented motor base with a status lamp, a steel platter ticked every keyed frame, and an amber arrow on the mat.",
2626
"witnessesFix": "Slotted-actions boundary: ensure-helper channelbag on 5.x, strip.channelbag on 4.4/4.5.",
2727
"hero": "docs/gallery/assets/turntable-hero.webp",
2828
"preview": "examples/turntable/preview.webp",

‎examples/turntable/README.md‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ a showcase extra, not part of the CI check.
3131

3232
The still's staging is render-only and runs after the check. The head gets a
3333
subdivision modifier (the 500-face monkey read as faceted plates) and is
34-
seated 10 mm into the platter of a turntable plinth, lifted from its own
35-
lowest evaluated vertex. It used to hover just above the floor with nothing
36-
under it. The rotation keys, the sampled frames and every exit code are
37-
unchanged. This render path does not call `gallery_framing.check_framing`,
38-
because adding it would add exit code 10. The framing was measured with the
39-
helper out of band instead: fill y 0.789, minimum margin 0.050, ok.
34+
seated 10 mm into the rubber mat of a display turntable, lifted from its own
35+
lowest evaluated vertex. The turntable is lathed: a stepped, vented motor
36+
housing with a front status lamp, and a steel platter whose rim carries one
37+
brass tick per keyed frame — `FRAMES` ticks, 10° apart, a longer one every
38+
90° — so the keyed 0→360° span over frames 1→`FRAMES` reads as a dial. An
39+
amber arc arrow on the mat sweeps the direction of the keyed +Z turn. The
40+
rotation keys and the sampled frames are unchanged. The render path gates
41+
framing through `examples/gallery_framing.py` before writing the still
42+
(exit 10 on violation; smoke never passes `--output`).
4043

4144
## Exit codes
4245

@@ -51,6 +54,7 @@ against it.
5154
| 3 | Rotation keys do not drive playback (`--no-keys` lands here) |
5255
| 4 | `--output` produced no file |
5356
| 5 | Wrong-era EEVEE engine id was accepted |
57+
| 10 | Framing gate violation on the `--output` path (`gallery_framing`) |
5458

5559
The `blender-smoke` workflow runs the check on Blender 5.2 LTS and 4.5 LTS
5660
(5.1 on the weekly cron, the `needs-5.1` PR label, or manual dispatch).

‎examples/turntable/preview.webp‎

5.46 KB
Loading

‎examples/turntable/turntable.py‎

Lines changed: 189 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
blender --background --python turntable.py -- --output t.png --engine cycles # GPU-less
2121
"""
2222
import bpy, sys, os, math, argparse
23+
from mathutils import Vector
24+
25+
# Shared Layer 1 framing measurement (render path only) — see
26+
# gallery_framing.py for the __file__-relative import shim this relies on.
27+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir))
28+
import gallery_framing # noqa: E402
2329

2430
FRAMES = 36
2531

@@ -72,21 +78,92 @@ def rz(f):
7278
print(f"branch={branch} rot_z f1={r1} fmid={rmid} fend={rend} drives={drives}")
7379
return drives
7480

75-
PLINTH_R = 1.15
76-
PLINTH_H = 0.28
77-
PLATTER_R = 1.05
78-
PLATTER_H = 0.05
81+
# Render-only display turntable, sized around the head (Suzanne spans ~2.7 x 1.7).
82+
BASE_R = 1.32 # motor housing radius at its widest
83+
BASE_H = 0.34 # housing top (platter bearing seat)
84+
PLATTER_R = 1.18
85+
PLATTER_Z0 = BASE_H + 0.02
86+
PLATTER_H = 0.07
87+
MAT_R = 1.06 # rubber mat inset into the platter
7988
SEAT = 0.01
89+
TICK_STEP_DEG = 360.0 / FRAMES # one rim tick per keyed frame: the key span, made visible
90+
91+
92+
def _lathe(bm, profile, segs=96):
93+
"""Revolve an (r, z) profile about Z; r == 0 points become poles."""
94+
rings = []
95+
for r, z in profile:
96+
if r < 1e-9:
97+
rings.append([bm.verts.new((0.0, 0.0, z))])
98+
else:
99+
rings.append([bm.verts.new((r * math.cos(2 * math.pi * i / segs),
100+
r * math.sin(2 * math.pi * i / segs), z))
101+
for i in range(segs)])
102+
for a, b in zip(rings, rings[1:]):
103+
for i in range(segs):
104+
j = (i + 1) % segs
105+
if len(a) == 1:
106+
bm.faces.new((a[0], b[j], b[i]))
107+
elif len(b) == 1:
108+
bm.faces.new((a[i], a[j], b[0]))
109+
else:
110+
bm.faces.new((a[i], a[j], b[j], b[i]))
111+
112+
113+
def _material(name, base, rough, metal=0.0, emit=None, strength=0.0, noise=None):
114+
mat = bpy.data.materials.new(name); mat.use_nodes = True
115+
nt = mat.node_tree
116+
pb = nt.nodes['Principled BSDF']
117+
pb.inputs['Base Color'].default_value = (*base, 1.0)
118+
pb.inputs['Metallic'].default_value = metal
119+
pb.inputs['Roughness'].default_value = rough
120+
if emit is not None:
121+
pb.inputs['Emission Color'].default_value = (*emit, 1.0)
122+
pb.inputs['Emission Strength'].default_value = strength
123+
if noise:
124+
# brushed / worn: noise-modulated roughness, never a flat slot
125+
tex = nt.nodes.new('ShaderNodeTexNoise')
126+
tex.inputs['Scale'].default_value = noise
127+
tex.inputs['Detail'].default_value = 8.0
128+
mr = nt.nodes.new('ShaderNodeMapRange')
129+
mr.inputs['To Min'].default_value = rough - 0.08
130+
mr.inputs['To Max'].default_value = rough + 0.12
131+
nt.links.new(tex.outputs['Fac'], mr.inputs['Value'])
132+
nt.links.new(mr.outputs['Result'], pb.inputs['Roughness'])
133+
return mat
134+
135+
136+
def _mesh_object(name, build, mats, smooth_angle=35.0):
137+
import bmesh
138+
me = bpy.data.meshes.new(name)
139+
bm = bmesh.new()
140+
try:
141+
build(bm)
142+
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
143+
bm.to_mesh(me)
144+
finally:
145+
bm.free()
146+
for p in me.polygons:
147+
p.use_smooth = True
148+
me.set_sharp_from_angle(angle=math.radians(smooth_angle))
149+
for m in mats:
150+
me.materials.append(m)
151+
ob = bpy.data.objects.new(name, me)
152+
bpy.context.collection.objects.link(ob)
153+
return ob
80154

81155

82156
def stage_turntable(obj):
83-
"""Render-only staging, after the check has run: a turntable to turn on.
157+
"""Render-only staging, after the check has run: a display turntable.
84158
85-
The head is smoothed by a subdivision modifier (the 500-face monkey read
86-
as faceted plates), seated SEAT into a platter on a plinth, and lifted so
87-
its lowest evaluated vertex lands there. It used to hover just above the
88-
floor with nothing under it. Rotation keys and the correctness samples
89-
are untouched; only location and a modifier change here.
159+
A lathed motor housing (stepped foot, vented drum, front status lamp)
160+
carries a steel platter with an inset rubber mat. Its rim carries one tick
161+
per keyed frame (FRAMES ticks, 10 degrees apart, a longer tick every 90),
162+
so the keyed 0..360 span over frames 1..FRAMES reads as a dial, and an
163+
amber arc arrow on the mat sweeps the direction of the keyed turn. The
164+
head is smoothed by a subdivision modifier and seated SEAT into the mat.
165+
Rotation keys and the correctness samples are untouched; only location
166+
and a modifier change on the checked object.
90167
"""
91168
import bmesh
92169
sub = obj.modifiers.new("Smooth", 'SUBSURF')
@@ -99,45 +176,99 @@ def stage_turntable(obj):
99176
zmin = min((ev.matrix_world @ v.co).z for v in me.vertices)
100177
finally:
101178
ev.to_mesh_clear()
102-
obj.location.z += (PLINTH_H + PLATTER_H - SEAT) - zmin
179+
top = PLATTER_Z0 + PLATTER_H
180+
obj.location.z += (top - SEAT) - zmin
103181
b = obj.active_material.node_tree.nodes['Principled BSDF']
104182
# 0.25 blew every brow and ear edge out to white under the key
105-
b.inputs['Roughness'].default_value = 0.38
106-
parts = []
107-
for nm, r, z0, h, col, metal, rough in (
108-
("Plinth", PLINTH_R, 0.0, PLINTH_H, (0.035, 0.032, 0.03), 0.0, 0.55),
109-
("Platter", PLATTER_R, PLINTH_H - 0.004, PLATTER_H + 0.004,
110-
(0.42, 0.42, 0.44), 1.0, 0.45),
111-
):
112-
mesh = bpy.data.meshes.new(nm)
113-
bm = bmesh.new()
114-
try:
115-
bmesh.ops.create_cone(bm, cap_ends=True, segments=64, radius1=r,
116-
radius2=r, depth=h)
117-
bmesh.ops.translate(bm, vec=(0.0, 0.0, z0 + h / 2.0), verts=bm.verts)
118-
bmesh.ops.bevel(bm, geom=[e for e in bm.edges if len(e.link_faces) == 2
119-
and e.calc_face_angle(0.0) > 1.0],
120-
offset=0.012, segments=2, affect='EDGES')
121-
bm.to_mesh(mesh)
122-
finally:
123-
bm.free()
124-
mesh.shade_smooth()
125-
mat = bpy.data.materials.new(nm); mat.use_nodes = True
126-
pb = mat.node_tree.nodes['Principled BSDF']
127-
pb.inputs['Base Color'].default_value = (*col, 1.0)
128-
pb.inputs['Metallic'].default_value = metal
129-
pb.inputs['Roughness'].default_value = rough
130-
mesh.materials.append(mat)
131-
ob = bpy.data.objects.new(nm, mesh)
132-
bpy.context.collection.objects.link(ob)
133-
parts.append(ob)
134-
return parts
183+
b.inputs['Roughness'].default_value = 0.34
184+
b.inputs['Base Color'].default_value = (0.80, 0.33, 0.12, 1.0)
185+
186+
housing = _material("Housing", (0.028, 0.030, 0.034), 0.42, metal=0.6, noise=40.0)
187+
steel = _material("Steel", (0.34, 0.34, 0.36), 0.40, metal=1.0, noise=90.0)
188+
rubber = _material("Rubber", (0.012, 0.012, 0.013), 0.78)
189+
brass = _material("Brass", (0.80, 0.56, 0.24), 0.26, metal=1.0, noise=60.0)
190+
lamp = _material("Lamp", (0.1, 0.03, 0.0), 0.3, emit=(1.0, 0.45, 0.10), strength=6.0)
191+
arrow = _material("Arrow", (0.9, 0.45, 0.1), 0.4, emit=(1.0, 0.50, 0.14), strength=2.2)
192+
193+
def build_housing(bm):
194+
_lathe(bm, [(0.0, 0.0), (BASE_R, 0.0), (BASE_R, 0.05), (BASE_R - 0.03, 0.07),
195+
(BASE_R - 0.08, 0.08), (BASE_R - 0.08, 0.10),
196+
# vented drum: shallow grooves around the waist
197+
*[(BASE_R - 0.10 - (0.012 if k % 2 else 0.0), 0.12 + 0.02 * k)
198+
for k in range(9)],
199+
(BASE_R - 0.10, 0.30), (BASE_R - 0.13, 0.33), (0.62, BASE_H),
200+
(0.60, BASE_H + 0.02), (0.0, BASE_H + 0.02)])
201+
housing_ob = _mesh_object("Housing", build_housing, [housing])
202+
203+
def build_platter(bm):
204+
z0, z1 = PLATTER_Z0, PLATTER_Z0 + PLATTER_H
205+
_lathe(bm, [(0.0, z0), (PLATTER_R - 0.02, z0), (PLATTER_R, z0 + 0.015),
206+
(PLATTER_R, z1 - 0.015), (PLATTER_R - 0.015, z1),
207+
(MAT_R + 0.01, z1), (MAT_R, z1 - 0.006), (0.0, z1 - 0.006)])
208+
platter_ob = _mesh_object("Platter", build_platter, [steel])
209+
210+
def build_mat(bm):
211+
_lathe(bm, [(0.0, top - 0.006), (MAT_R - 0.004, top - 0.006),
212+
(MAT_R - 0.004, top), (0.0, top)], segs=96)
213+
mat_ob = _mesh_object("Mat", build_mat, [rubber])
214+
215+
def build_ticks(bm):
216+
for k in range(FRAMES):
217+
a = math.radians(k * TICK_STEP_DEG)
218+
major = k % (FRAMES // 4) == 0
219+
h = 0.058 if major else 0.036
220+
res = bmesh.ops.create_cube(bm, size=1.0)
221+
for v in res['verts']:
222+
v.co.x *= 0.016
223+
v.co.y *= 0.026 if major else 0.013
224+
v.co.z *= h
225+
v.co.x += PLATTER_R + 0.006
226+
v.co.z += PLATTER_Z0 + PLATTER_H / 2.0
227+
x, y = v.co.x, v.co.y
228+
v.co.x = x * math.cos(a) - y * math.sin(a)
229+
v.co.y = x * math.sin(a) + y * math.cos(a)
230+
ticks_ob = _mesh_object("Ticks", build_ticks, [brass], smooth_angle=10.0)
231+
232+
def build_arrow(bm):
233+
# a quarter-turn arc on the mat edge, counter-clockwise (+Z rotation),
234+
# ending in a flat arrowhead: the keyed direction of travel
235+
r, w, z = MAT_R - 0.07, 0.022, top + 0.002
236+
a0, a1, n = math.radians(-150), math.radians(-75), 24
237+
prev = None
238+
for i in range(n + 1):
239+
a = a0 + (a1 - a0) * i / n
240+
ring = [bm.verts.new(((r + s * w) * math.cos(a), (r + s * w) * math.sin(a), z + dz))
241+
for s, dz in ((-1, 0.0), (1, 0.0), (1, 0.008), (-1, 0.008))]
242+
if prev:
243+
for k in range(4):
244+
bm.faces.new((prev[k], prev[(k + 1) % 4], ring[(k + 1) % 4], ring[k]))
245+
prev = ring
246+
tip = a1 + math.radians(9)
247+
head = [bm.verts.new(((r + s) * math.cos(a1), (r + s) * math.sin(a1), z + dz))
248+
for s, dz in ((-0.06, 0.0), (0.06, 0.0), (0.06, 0.008), (-0.06, 0.008))]
249+
pt = [bm.verts.new((r * math.cos(tip), r * math.sin(tip), z)),
250+
bm.verts.new((r * math.cos(tip), r * math.sin(tip), z + 0.008))]
251+
bm.faces.new((head[0], head[1], pt[0]))
252+
bm.faces.new((head[3], pt[1], head[2]))
253+
bm.faces.new((head[1], head[2], pt[1], pt[0]))
254+
bm.faces.new((head[0], pt[0], pt[1], head[3]))
255+
bm.faces.new((head[0], head[3], head[2], head[1]))
256+
arrow_ob = _mesh_object("Arrow", build_arrow, [arrow], smooth_angle=10.0)
257+
258+
def build_lamp(bm):
259+
# a status lamp on the housing front, facing the camera (-Y)
260+
res = bmesh.ops.create_uvsphere(bm, u_segments=16, v_segments=10, radius=0.035)
261+
for v in res['verts']:
262+
v.co.y *= 0.6
263+
v.co += Vector((0.0, -(BASE_R - 0.105), 0.21))
264+
lamp_ob = _mesh_object("Lamp", build_lamp, [lamp])
265+
return [housing_ob, platter_ob, mat_ob, ticks_ob, arrow_ob, lamp_ob]
135266

136267

137268
def render_still(obj, path, engine):
138269
import bmesh
139270
sc = bpy.context.scene
140-
stage_turntable(obj)
271+
parts = stage_turntable(obj)
141272
fme = bpy.data.meshes.new("Floor"); bm = bmesh.new()
142273
try:
143274
bmesh.ops.create_grid(bm, x_segments=1, y_segments=1, size=30.0); bm.to_mesh(fme)
@@ -155,8 +286,8 @@ def render_still(obj, path, engine):
155286
wall.rotation_euler = (math.radians(90), 0, 0); bpy.context.collection.objects.link(wall)
156287
w = bpy.data.worlds.new("W"); w.use_nodes = True
157288
w.node_tree.nodes["Background"].inputs[0].default_value = (0.02, 0.021, 0.025, 1); sc.world = w
158-
aim = bpy.data.objects.new("Aim", None); aim.location = (0, 0, 1.1); bpy.context.collection.objects.link(aim)
159-
cam = bpy.data.objects.new("cam", bpy.data.cameras.new("cam")); cam.location = (0, -8.0, 3.4)
289+
aim = bpy.data.objects.new("Aim", None); aim.location = (0, 0, 1.05); bpy.context.collection.objects.link(aim)
290+
cam = bpy.data.objects.new("cam", bpy.data.cameras.new("cam")); cam.location = (0.6, -8.2, 3.2)
160291
bpy.context.collection.objects.link(cam); sc.camera = cam
161292
c = cam.constraints.new('TRACK_TO'); c.target = aim; c.track_axis = 'TRACK_NEGATIVE_Z'; c.up_axis = 'UP_Y'
162293
for nm, loc, en, size, col in [("K", (-4, -5, 7), 620, 5.0, (1.0, 0.96, 0.9)),
@@ -170,10 +301,10 @@ def render_still(obj, path, engine):
170301
wo.rotation_euler = (math.radians(-68), 0, math.radians(190)); bpy.context.collection.objects.link(wo)
171302
sc.render.engine = 'CYCLES' if engine == 'cycles' else get_eevee_engine_id()
172303
if sc.render.engine == 'CYCLES':
173-
try: sc.cycles.samples = 16
304+
try: sc.cycles.samples = 48
174305
except Exception: pass
175306
else:
176-
try: sc.eevee.taa_render_samples = 16
307+
try: sc.eevee.taa_render_samples = 64
177308
except Exception: pass
178309
# pin the still to a deliberate pose: frame 4 is ~31 degrees of turn, a
179310
# three-quarter view where ears and brow read instantly as Suzanne. An
@@ -186,8 +317,14 @@ def render_still(obj, path, engine):
186317
sc.render.image_settings.file_format = 'PNG'; sc.render.filepath = path
187318
# AgX would wash the copper toward beige (docs/VISUAL-STYLE.md)
188319
sc.view_settings.view_transform = 'Standard'
320+
bpy.context.view_layer.update()
321+
# Layer 1 framing gate before the beauty render (exit 10 on violation)
322+
fcode = gallery_framing.check_framing(sc, cam, hero=[obj] + parts,
323+
elements=[obj] + parts, stage=[floor, wall])
324+
if fcode:
325+
return fcode
189326
bpy.ops.render.render(write_still=True)
190-
return os.path.exists(path) and os.path.getsize(path) > 0
327+
return 0 if os.path.exists(path) and os.path.getsize(path) > 0 else 4
191328

192329
def main():
193330
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
@@ -214,8 +351,11 @@ def main():
214351
print("ERROR: rotation keys do not drive playback", file=sys.stderr); return 3
215352

216353
if args.output:
217-
if not render_still(obj, args.output, args.engine):
218-
print("ERROR: still render produced no file", file=sys.stderr); return 4
354+
rcode = render_still(obj, args.output, args.engine)
355+
if rcode:
356+
if rcode == 4:
357+
print("ERROR: still render produced no file", file=sys.stderr)
358+
return rcode
219359
print(f"rendered still {args.output} ({os.path.getsize(args.output)} bytes)")
220360
print("turntable OK")
221361
return 0

0 commit comments

Comments
 (0)