Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
549 lines (493 loc) · 39.1 KB
/
Copy pathindex.html
File metadata and controls
549 lines (493 loc) · 39.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>light-link-studio — Examples — Blender Developer Tools</title>
<meta name="description" content="One key, one hero: a light linked to a receiver collection lights only the hero, proven by two pixel renders in one pass. Linked: 4.0x luminance ratio; unlinked in the same check: the decoy rises 244% while the hero holds at 0.0% drift." />
<link rel="canonical" href="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/light-link-studio/" />
<link rel="icon" href="../../assets/favicon.svg" type="image/svg+xml" />
<meta name="theme-color" content="#1a1b1e" />
<meta property="og:type" content="website" />
<meta property="og:title" content="light-link-studio — Examples — Blender Developer Tools" />
<meta property="og:description" content="One key, one hero: a light linked to a receiver collection lights only the hero, proven by two pixel renders in one pass. Linked: 4.0x luminance ratio; unlinked in the same check: the decoy rises 244% while the hero holds at 0.0% drift." />
<meta property="og:url" content="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/light-link-studio/" />
<meta property="og:image" content="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/assets/light-link-studio-hero.webp" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="light-link-studio — Examples — Blender Developer Tools" />
<meta name="twitter:description" content="One key, one hero: a light linked to a receiver collection lights only the hero, proven by two pixel renders in one pass. Linked: 4.0x luminance ratio; unlinked in the same check: the decoy rises 244% while the hero holds at 0.0% drift." />
<meta name="twitter:image" content="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/assets/light-link-studio-hero.webp" />
<style>
/* fonts are deployed by the landing build (docs/fonts/) */
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap;
src: url('../../fonts/barlow-condensed-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 400; font-display: swap;
src: url('../../fonts/inter-regular.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 500; font-display: swap;
src: url('../../fonts/inter-medium.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-weight: 400; font-display: swap;
src: url('../../fonts/jetbrains-mono-regular.woff2') format('woff2'); }
/* Blender-viewport system, shared with the landing page. Dark only. */
:root {
--bg: #1a1b1e; --surface: #222327; --surface-2: #2a2b30; --bg2: #131417;
--border: #3a3b40; --text: #e8e9eb; --text-dim: #9698a0;
--select: #ff8c19; --ok: #6dc96d;
--radius: 4px; --radius-lg: 6px; --maxw: 1080px;
--font-display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
--font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
--code-k: #ff7b72; --code-s: #a5d6ff; --code-c: #9698a0; --code-n: #79c0ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: var(--font-sans); background: var(--bg); color: var(--text);
line-height: 1.6; min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--select); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--select); outline-offset: 2px; border-radius: 3px; }
::selection { background: color-mix(in srgb, var(--select) 40%, transparent); }
.skip { position: absolute; left: -999px; top: 0; background: var(--select); color: #1a1b1e;
padding: 0.5rem 1rem; border-radius: var(--radius); z-index: 10; font-weight: 500; }
.skip:focus { left: 0.5rem; top: 0.5rem; }
.hud { font-family: var(--font-mono); font-size: 0.6875rem; letter-spacing: 0.04em;
color: var(--text-dim); text-transform: uppercase; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center;
justify-content: space-between; gap: 1rem; padding: 0 1.25rem; height: 46px;
background: color-mix(in srgb, var(--surface) 92%, transparent);
backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar .back { color: var(--text-dim); font-size: 0.8125rem; font-weight: 500; }
.topbar .back:hover { color: var(--select); text-decoration: none; }
.topbar-right { display: flex; align-items: center; gap: 0.85rem; }
.topbar-right .ghlink { color: var(--text-dim); font-size: 0.8125rem; font-weight: 500; }
.topbar-right .ghlink:hover { color: var(--select); text-decoration: none; }
header.hero { max-width: var(--maxw); margin: 0 auto; padding: 2.75rem 1.25rem 1.25rem; }
header.hero h1 { font-family: var(--font-display); font-weight: 600; text-transform: uppercase;
font-size: clamp(2.2rem, 5vw, 3.4rem); letter-spacing: 0.005em; line-height: 0.98; }
header.hero p { color: var(--text-dim); max-width: 62ch; margin-top: 0.7rem; font-size: 1rem; }
/* ---- index: filter chips ---- */
.chips { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem 0.25rem;
display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
border-radius: 3px; padding: 0.22rem 0.7rem; font-size: 0.72rem; font-weight: 400;
font-family: var(--font-mono); cursor: pointer; transition: color 0.15s, border-color 0.15s; }
.chip:hover { color: var(--select); border-color: var(--select); }
.chip.active { color: #1a1b1e; background: var(--select); border-color: var(--select); }
main { max-width: var(--maxw); margin: 0 auto; padding: 1rem 1.25rem 2rem; }
.grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; align-items: stretch; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
overflow: hidden; display: flex; flex-direction: column;
outline: 2px solid transparent; outline-offset: -1px;
transition: outline-color 0.12s ease, border-color 0.12s ease; }
.card:hover { border-color: var(--select); outline-color: var(--select); }
.card.hidden { display: none; }
.card-media { display: block; background: var(--bg2); line-height: 0; }
.card-media img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.card-body { padding: 1.15rem 1.4rem 1.45rem; display: flex; flex-direction: column; flex: 1 1 auto; }
.card-body h2 { font-family: var(--font-mono); font-size: 1rem; font-weight: 400; margin-bottom: 0.5rem; }
.card-body h2 a { color: var(--text); }
.card-body h2 a:hover { color: var(--select); text-decoration: none; }
.teaches { color: var(--text); margin-bottom: 0.7rem; font-size: 0.92rem; }
.witnesses { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1rem; }
.tag { display: inline-block; font-family: var(--font-mono); font-size: 0.62rem; text-transform: uppercase;
letter-spacing: 0.06em; color: var(--select); border: 1px solid color-mix(in srgb, var(--select) 55%, transparent);
border-radius: 3px; padding: 0.08rem 0.5rem; margin-right: 0.4rem; vertical-align: 1px; }
.card-link { font-weight: 600; font-size: 0.95rem; margin-top: auto; }
/* ---- detail page ---- */
.detail-hero { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden;
background: var(--bg2); padding: 0; display: block; width: 100%; cursor: zoom-in; line-height: 0; }
.detail-hero img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.zoom-hint { color: var(--text-dim); font-size: 0.78rem; margin-top: 0.4rem; }
.callout { border: 1px solid color-mix(in srgb, var(--select) 45%, var(--border));
border-left: 3px solid var(--select); border-radius: var(--radius);
background: color-mix(in srgb, var(--select) 7%, var(--surface));
padding: 0.85rem 1.1rem; margin: 1.5rem 0; font-size: 0.95rem; }
.runline { display: flex; align-items: stretch; gap: 0.5rem; margin: 1.5rem 0; }
.runline pre { flex: 1 1 auto; background: var(--surface-2); border: 1px solid var(--border);
border-radius: var(--radius); padding: 0.7rem 0.9rem; overflow-x: auto;
font-family: var(--font-mono); font-size: 0.83rem; line-height: 1.5; }
.copy-btn { flex: 0 0 auto; background: var(--surface-2); border: 1px solid var(--border);
color: var(--text-dim); border-radius: var(--radius); padding: 0 0.85rem; cursor: pointer;
font-family: var(--font-sans); font-size: 0.82rem; font-weight: 500; transition: color 0.15s, border-color 0.15s; }
.copy-btn:hover { color: var(--select); border-color: var(--select); }
.detail-section { margin-top: 2.25rem; }
.detail-section > h2 { font-family: var(--font-display); font-weight: 600; text-transform: uppercase;
font-size: 1.45rem; letter-spacing: 0.005em; padding-bottom: 0.5rem;
border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.md h1, .md h2, .md h3 { letter-spacing: -0.01em; margin: 1.4rem 0 0.6rem; line-height: 1.25; }
.md h1 { font-size: 1.35rem; } .md h2 { font-size: 1.15rem; } .md h3 { font-size: 1rem; }
.md p { margin: 0.7rem 0; }
.md ul { margin: 0.7rem 0 0.7rem 1.4rem; }
.md li { margin: 0.3rem 0; }
.md code { background: var(--surface-2); border: 1px solid var(--border); padding: 0.08rem 0.35rem;
border-radius: 4px; font-family: var(--font-mono); font-size: 0.84em; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
padding: 0.85rem 1rem; overflow-x: auto; margin: 0.9rem 0; }
.md pre code { background: none; border: none; padding: 0; font-size: 0.83rem; line-height: 1.55; }
.src pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
padding: 1rem 1.1rem; overflow-x: auto; font-family: var(--font-mono);
font-size: 0.82rem; line-height: 1.55; }
.src .k { color: var(--code-k); } .src .s { color: var(--code-s); }
.src .c { color: var(--code-c); font-style: italic; } .src .n { color: var(--code-n); }
.src-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
flex-wrap: wrap; margin-bottom: 0.6rem; color: var(--text-dim); font-size: 0.85rem; }
.src-meta code { font-family: var(--font-mono); font-size: 0.82rem; }
.lightbox { position: fixed; inset: 0; z-index: 50; display: none; align-items: center;
justify-content: center; background: rgba(0,0,0,0.85); padding: 2rem; cursor: zoom-out; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--radius); }
footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 2rem; }
footer .statusbar { max-width: var(--maxw); margin: 0 auto; padding: 0.55rem 1.25rem;
display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
font-family: var(--font-mono); font-size: 0.6875rem; letter-spacing: 0.04em;
text-transform: uppercase; color: var(--text-dim); }
footer .statusbar code { font-family: inherit; text-transform: none; }
@media (min-width: 720px) { .grid { grid-template-columns: 1fr 1fr; gap: 1.75rem; } }
@media (prefers-reduced-motion: reduce) {
html { scroll-behavior: auto; }
.card { transition: none; }
.card:hover { transform: none; }
}
</style>
</head>
<body>
<a class="skip" href="#main">Skip to content</a>
<div class="topbar">
<a class="back" href="../"><span aria-hidden="true">←</span> Examples Gallery</a>
<div class="topbar-right">
<a class="ghlink" href="https://github.com/TMHSDigital/Blender-Developer-Tools">GitHub</a>
</div>
</div>
<header class="hero">
<h1>light-link-studio</h1>
<p>One key, one hero: a light linked to a receiver collection lights only the hero, proven by two pixel renders in one pass. Linked: 4.0x luminance ratio; unlinked in the same check: the decoy rises 244% while the hero holds at 0.0% drift.</p>
</header>
<main id="main">
<button class="detail-hero" id="heroZoom" type="button" aria-label="Zoom light-link-studio render">
<img src="../assets/light-link-studio-hero.webp" alt="light-link-studio render" width="1280" height="720" />
</button>
<p class="zoom-hint">Rendered headless by the example itself — click to zoom.</p>
<div class="callout"><span class="tag">witnesses</span> The API is obj.light_linking on the light OBJECT (ld.light_linking is an AttributeError). Luminance is sampled at each sphere's projected center; EEVEE Next honors linking too (5.5x on 4.5, 5.9x on 5.1), Cycles pinned for deterministic samples.</div>
<div class="runline">
<pre id="runCmd">blender --background --python examples/light-link-studio/light_link_studio.py --</pre>
<button class="copy-btn" id="copyRun" type="button">Copy</button>
</div>
<section class="detail-section md">
<p>A runnable example that stages one key light linked to a hero sphere beside an identical decoy, renders the studio twice in one pass, and proves the whole light-linking contract <strong>in pixels</strong> — the feature AI-generated staging code most often misses or misaddresses.</p>
<p><strong>What it witnesses:</strong> the light-linking contract and the traps around it.</p>
<p>1. <strong>The API is on the light OBJECT, not the Light datablock.</strong> <code>ld.light_linking</code> is an AttributeError on both versions (verified); the path is <code>obj.light_linking.receiver_collection</code> (ObjectLightLinking, with <code>blocker_collection</code> alongside). Assignment reads back through the API. 2. <strong>Linked, the key lights only the receiver collection.</strong> Render one: hero well-lit, decoy at the fill floor — hero/decoy luminance ratio <strong>4.0x</strong> (gate ≥ 3x), measured at each sphere's *projected* center so framing can't move the sample off the subject. 3. <strong>Unlinked (same check), the restriction vanishes surgically.</strong> Render two: the decoy rises <strong>244–251%</strong> while the hero drifts <strong>0.0%</strong> — the link restricts without dimming anything else. The shipped check therefore demonstrates both states, not just one. 4. <strong>The engine note, verified rather than assumed.</strong> Light linking also works on EEVEE Next — measured 5.5x linked ratio on 4.5.11 EEVEE Next and 5.9x on 5.1.2 EEVEE, matching Cycles within sampling noise. The check still pins Cycles for deterministic tiny-sample CPU renders; luminance gates need <code>view_transform = 'Standard'</code> (AgX compresses the ratios).</p>
<p><strong>What each check catches on failure:</strong> inverting the link to the decoy collection (exit 6 — hero drops to 0.179, ratio collapses to 0.22x), an RNA move of the API onto the Light datablock (exit 3, guarded), a lost assignment read-back (exit 5), a link that doesn't restrict (exit 7, rise below 50%), and a non-surgical restriction (exit 8, hero drift above 5%).</p>
<p><strong>Version witness:</strong> ObjectLightLinking API and the measured ratios match on Blender 4.5 LTS and 5.1 (4.0x linked both; rise 244% vs 251% within sampling noise).</p>
<p>The render is the contract at a glance: the blazing orange hero over the LINKED plaque, the cold steel decoy over UNLINKED — one key, one hero.</p>
<h2>Run</h2>
<pre><code># Two-render correctness check (tiny Cycles CPU renders) — the CI check:
blender --background --python light_link_studio.py --
# Also render the gallery still (Cycles, deterministic samples):
blender --background --python light_link_studio.py -- --output linked.png</code></pre>
<p>It exits non-zero on failure (API moved, assignment lost, ratio below gate, insufficient unlink rise, or hero drift). The <code>blender-smoke</code> workflow runs the check on Blender 4.5 LTS and 5.1.</p>
</section>
<section class="detail-section src">
<h2>Source</h2>
<div class="src-meta">
<code>examples/light-link-studio/light_link_studio.py</code>
<a href="https://github.com/TMHSDigital/Blender-Developer-Tools/tree/main/examples/light-link-studio/light_link_studio.py">View on GitHub →</a>
</div>
<pre><span class="s">"""One key, one hero: light linking, proven by pixels — a runnable example.
Witnesses the light-linking contract AI-generated staging code most often
misses: a light's contribution can be restricted to a receiver collection,
and the API is on the light OBJECT (``obj.light_linking``), not the Light
datablock — `ld.light_linking` is an AttributeError. The check renders the
studio twice in one pass and asserts the whole story in pixels:
1. Linked: the key lights ONLY the hero — the hero reads bright while the
identical decoy beside it sits at the fill floor.
2. Unlinked (same check): the decoy's brightness rises materially while the
hero's is unchanged within tolerance — the link is surgical, not a dimmer.
The engine note, verified rather than assumed: light linking also works on
EEVEE Next — measured 5.5x linked ratio on 4.5.11 EEVEE Next and 5.9x on
5.1.2 EEVEE, matching Cycles within sampling noise. The check still pins
Cycles for deterministic tiny-sample CPU renders. The API is stable between
Blender 4.5 LTS and 5.1 (ObjectLightLinking with
receiver_collection/blocker_collection on both).
By default it runs the two-render correctness check (no gallery still) — the
CI smoke check. Pass --output to also render a still:
blender --background --python light_link_studio.py -- # check only
blender --background --python light_link_studio.py -- --output l.png # + render
"""</span>
<span class="k">import</span> bpy, bmesh, sys, os, math, argparse, tempfile, shutil
IS_5X = bpy.app.version >= (<span class="n">5</span>, <span class="n">0</span>, <span class="n">0</span>)
HERO_RGB = (<span class="n">0.85</span>, <span class="n">0.30</span>, <span class="n">0.08</span>) <span class="c"># hazard orange</span>
DECOY_RGB = (<span class="n">0.30</span>, <span class="n">0.34</span>, <span class="n">0.40</span>) <span class="c"># cold steel</span>
KEY_ENERGY = <span class="n">450.0</span>
FILL_ENERGY = <span class="n">18.0</span>
PXW, PXH = <span class="n">64</span>, <span class="n">36</span>
RATIO_MIN = <span class="n">3.0</span> <span class="c"># hero/decoy luminance ratio, linked</span>
HERO_LUMA_MIN = <span class="n">0.25</span> <span class="c"># hero must be well-lit, linked</span>
RISE_MIN = <span class="n">0.5</span> <span class="c"># decoy luminance rise when unlinked (relative)</span>
HERO_DRIFT_MAX = <span class="n">0.05</span> <span class="c"># hero brightness change across the two renders</span>
<span class="k">def</span> sphere(name, rgb, x, coll):
me = bpy.data.meshes.new(name)
bm = bmesh.new()
<span class="k">try</span>:
bmesh.ops.create_uvsphere(bm, u_segments=<span class="n">32</span>, v_segments=<span class="n">16</span>, radius=<span class="n">0.5</span>)
bm.to_mesh(me)
<span class="k">finally</span>:
bm.free()
<span class="k">for</span> p <span class="k">in</span> me.polygons:
p.use_smooth = <span class="k">True</span>
mat = bpy.data.materials.new(name + <span class="s">"M"</span>)
mat.use_nodes = <span class="k">True</span>
b = mat.node_tree.nodes[<span class="s">"Principled BSDF"</span>]
b.inputs[<span class="s">"Base Color"</span>].default_value = (*rgb, <span class="n">1.0</span>)
b.inputs[<span class="s">"Roughness"</span>].default_value = <span class="n">0.45</span>
me.materials.append(mat)
ob = bpy.data.objects.new(name, me)
ob.location = (x, <span class="n">0.0</span>, <span class="n">0.55</span>)
coll.objects.link(ob)
<span class="k">return</span> ob
<span class="k">def</span> add_light(sc, name, energy, loc, rot, color, size=<span class="n">1.2</span>):
ld = bpy.data.lights.new(name, <span class="s">'AREA'</span>)
ld.energy = energy
ld.size = size
ld.color = color
ob = bpy.data.objects.new(name, ld)
ob.location = loc
ob.rotation_euler = tuple(math.radians(a) <span class="k">for</span> a <span class="k">in</span> rot)
sc.collection.objects.link(ob)
<span class="k">return</span> ob
<span class="k">def</span> build_studio(sc):
<span class="s">"""Hero and decoy on one stage, plus a low fill that lights both."""</span>
hero_c = bpy.data.collections.new(<span class="s">"HeroColl"</span>)
decoy_c = bpy.data.collections.new(<span class="s">"DecoyColl"</span>)
hero = sphere(<span class="s">"Hero"</span>, HERO_RGB, -<span class="n">1.2</span>, hero_c)
decoy = sphere(<span class="s">"Decoy"</span>, DECOY_RGB, <span class="n">1.2</span>, decoy_c)
sc.collection.children.link(hero_c)
sc.collection.children.link(decoy_c)
floor_me = bpy.data.meshes.new(<span class="s">"Floor"</span>)
bm = bmesh.new()
<span class="k">try</span>:
bmesh.ops.create_grid(bm, x_segments=<span class="n">1</span>, y_segments=<span class="n">1</span>, size=<span class="n">30.0</span>)
bm.to_mesh(floor_me)
<span class="k">finally</span>:
bm.free()
fmat = bpy.data.materials.new(<span class="s">"Studio"</span>)
fmat.use_nodes = <span class="k">True</span>
fb = fmat.node_tree.nodes[<span class="s">"Principled BSDF"</span>]
fb.inputs[<span class="s">"Base Color"</span>].default_value = (<span class="n">0.03</span>, <span class="n">0.032</span>, <span class="n">0.037</span>, <span class="n">1.0</span>)
fb.inputs[<span class="s">"Roughness"</span>].default_value = <span class="n">0.7</span>
floor_me.materials.append(fmat)
floor = bpy.data.objects.new(<span class="s">"Floor"</span>, floor_me)
sc.collection.objects.link(floor)
wall = bpy.data.objects.new(<span class="s">"Wall"</span>, floor_me.copy())
wall.location = (<span class="n">0.0</span>, <span class="n">9.0</span>, <span class="n">0.0</span>)
wall.rotation_euler = (math.radians(<span class="n">90</span>), <span class="n">0.0</span>, <span class="n">0.0</span>)
sc.collection.objects.link(wall)
world = bpy.data.worlds.new(<span class="s">"World"</span>)
world.use_nodes = <span class="k">True</span>
world.node_tree.nodes[<span class="s">"Background"</span>].inputs[<span class="s">"Color"</span>].default_value = (<span class="n">0.02</span>, <span class="n">0.021</span>, <span class="n">0.025</span>, <span class="n">1.0</span>)
sc.world = world
key = add_light(sc, <span class="s">"Key"</span>, KEY_ENERGY, (-<span class="n">2.2</span>, -<span class="n">2.5</span>, <span class="n">3.5</span>), (<span class="n">40</span>, <span class="n">0</span>, -<span class="n">25</span>),
(<span class="n">1.0</span>, <span class="n">0.92</span>, <span class="n">0.82</span>), size=<span class="n">1.4</span>)
add_light(sc, <span class="s">"Fill"</span>, FILL_ENERGY, (<span class="n">3.0</span>, -<span class="n">2.0</span>, <span class="n">2.2</span>), (<span class="n">60</span>, <span class="n">0</span>, <span class="n">35</span>),
(<span class="n">0.75</span>, <span class="n">0.85</span>, <span class="n">1.0</span>), size=<span class="n">4.0</span>)
add_light(sc, <span class="s">"Rim"</span>, <span class="n">120.0</span>, (<span class="n">0.5</span>, <span class="n">4.5</span>, <span class="n">4.0</span>), (-<span class="n">55</span>, <span class="n">0</span>, <span class="n">175</span>),
(<span class="n">0.6</span>, <span class="n">0.78</span>, <span class="n">1.0</span>), size=<span class="n">3.0</span>)
<span class="c"># the signature warm wedge raking the back wall (docs/VISUAL-STYLE.md)</span>
add_light(sc, <span class="s">"Wedge"</span>, <span class="n">250.0</span>, (-<span class="n">2.5</span>, <span class="n">3.5</span>, <span class="n">4.2</span>), (-<span class="n">72</span>, <span class="n">0</span>, <span class="n">165</span>),
(<span class="n">1.0</span>, <span class="n">0.76</span>, <span class="n">0.5</span>), size=<span class="n">5.0</span>)
cam = bpy.data.cameras.new(<span class="s">"Cam"</span>)
cam.lens = <span class="n">55.0</span>
cam_ob = bpy.data.objects.new(<span class="s">"Cam"</span>, cam)
cam_ob.location = (<span class="n">0.0</span>, -<span class="n">5.9</span>, <span class="n">1.32</span>)
cam_ob.rotation_euler = (math.radians(<span class="n">86</span>), <span class="n">0.0</span>, <span class="n">0.0</span>)
sc.collection.objects.link(cam_ob)
sc.camera = cam_ob
<span class="k">return</span> hero, decoy, hero_c, key
<span class="k">def</span> setup_render(sc, w, h, samples):
<span class="c"># Cycles for deterministic tiny CPU samples; EEVEE Next honors linking</span>
<span class="c"># too (measured on both supported versions), but its sampling is not</span>
<span class="c"># deterministic enough for a luminance gate</span>
sc.render.engine = <span class="s">'CYCLES'</span>
sc.cycles.samples = samples
sc.cycles.use_denoising = <span class="k">False</span>
sc.render.resolution_x = w
sc.render.resolution_y = h
sc.render.resolution_percentage = <span class="n">100</span>
sc.render.image_settings.file_format = <span class="s">'PNG'</span>
<span class="c"># Standard keeps luminance ratios meaningful (AgX would compress them)</span>
sc.view_settings.view_transform = <span class="s">'Standard'</span>
<span class="k">def</span> luma_at(img, fx, fy):
w, h = img.size
x, y = int(fx * w), int(fy * h)
i = (y * w + x) * <span class="n">4</span>
px = img.pixels
<span class="k">return</span> <span class="n">0.299</span> * px[i] + <span class="n">0.587</span> * px[i + <span class="n">1</span>] + <span class="n">0.114</span> * px[i + <span class="n">2</span>]
<span class="k">def</span> render_lumas(sc, tmp, name, hero, decoy):
<span class="k">from</span> bpy_extras.object_utils <span class="k">import</span> world_to_camera_view
path = os.path.join(tmp, name)
sc.render.filepath = path
bpy.ops.render.render(write_still=<span class="k">True</span>)
img = bpy.data.images.load(path)
<span class="c"># sample AT each sphere's projected center (framing-independent), taking</span>
<span class="c"># the max over a small disc to stay off edges</span>
out = []
<span class="k">for</span> ob <span class="k">in</span> (hero, decoy):
ndc = world_to_camera_view(sc, sc.camera, ob.matrix_world.translation)
best = <span class="n">0.0</span>
<span class="k">for</span> dy <span class="k">in</span> (-<span class="n">2</span>, <span class="n">0</span>, <span class="n">2</span>):
<span class="k">for</span> dx <span class="k">in</span> (-<span class="n">2</span>, <span class="n">0</span>, <span class="n">2</span>):
best = max(best, luma_at(img, ndc.x + dx / PXW,
ndc.y + dy / PXH))
out.append(best)
bpy.data.images.remove(img)
<span class="k">return</span> out[<span class="n">0</span>], out[<span class="n">1</span>]
<span class="k">def</span> check(sc, key, hero_c, hero, decoy):
<span class="c"># contract 0 (RNA guard): the API is on the light OBJECT</span>
ld = key.data
<span class="k">if</span> hasattr(ld, <span class="s">"light_linking"</span>):
print(<span class="s">"ERROR: Light datablock gained light_linking — the API moved; "</span>
<span class="s">"this example pins the Object-level path"</span>, file=sys.stderr)
<span class="k">return</span> <span class="n">3</span>
<span class="k">if</span> <span class="k">not</span> hasattr(key, <span class="s">"light_linking"</span>):
print(<span class="s">"ERROR: light objects lost light_linking"</span>, file=sys.stderr)
<span class="k">return</span> <span class="n">4</span>
<span class="c"># contract 1 (assignment round-trip through the API itself)</span>
key.light_linking.receiver_collection = hero_c
<span class="k">if</span> key.light_linking.receiver_collection != hero_c:
print(<span class="s">"ERROR: receiver_collection assignment did not read back"</span>,
file=sys.stderr)
<span class="k">return</span> <span class="n">5</span>
setup_render(sc, PXW, PXH, <span class="n">8</span>)
tmp = tempfile.mkdtemp(prefix=<span class="s">"light_link_"</span>)
<span class="k">try</span>:
hero_a, decoy_a = render_lumas(sc, tmp, <span class="s">"linked.png"</span>, hero, decoy)
key.light_linking.receiver_collection = <span class="k">None</span>
hero_b, decoy_b = render_lumas(sc, tmp, <span class="s">"unlinked.png"</span>, hero, decoy)
key.light_linking.receiver_collection = hero_c <span class="c"># restore for the still</span>
<span class="k">finally</span>:
shutil.rmtree(tmp, ignore_errors=<span class="k">True</span>)
<span class="c"># contract 2 (linked): the hero is lit, the decoy is not</span>
ratio_a = hero_a / max(decoy_a, <span class="n">1e-6</span>)
<span class="k">if</span> hero_a < HERO_LUMA_MIN <span class="k">or</span> ratio_a < RATIO_MIN:
print(<span class="s">f"</span><span class="s">ERROR: linked state wrong — hero </span>{hero_a:<span class="s">.3f</span>}<span class="s"> (min </span><span class="s">"</span>
<span class="s">f"</span>{HERO_LUMA_MIN}<span class="s">), hero/decoy </span>{ratio_a:<span class="s">.2f</span>}<span class="s">x (min </span>{RATIO_MIN}<span class="s">x)</span><span class="s">"</span>,
file=sys.stderr)
<span class="k">return</span> <span class="n">6</span>
<span class="c"># contract 3 (unlinked): the decoy rises materially, the hero holds</span>
rise = (decoy_b - decoy_a) / max(decoy_a, <span class="n">1e-6</span>)
hero_drift = abs(hero_b - hero_a) / max(hero_a, <span class="n">1e-6</span>)
<span class="k">if</span> rise < RISE_MIN:
print(<span class="s">f"</span><span class="s">ERROR: decoy rose only </span>{rise:<span class="s">.1%</span>}<span class="s"> when unlinked (min </span><span class="s">"</span>
<span class="s">f"</span>{RISE_MIN:<span class="s">.0%</span>}<span class="s">) — the key was never restricted</span><span class="s">"</span>,
file=sys.stderr)
<span class="k">return</span> <span class="n">7</span>
<span class="k">if</span> hero_drift > HERO_DRIFT_MAX:
print(<span class="s">f"</span><span class="s">ERROR: hero drifted </span>{hero_drift:<span class="s">.1%</span>}<span class="s"> across the unlink </span><span class="s">"</span>
<span class="s">f"</span><span class="s">(max </span>{HERO_DRIFT_MAX:<span class="s">.0%</span>}<span class="s">) — the link is not surgical</span><span class="s">"</span>,
file=sys.stderr)
<span class="k">return</span> <span class="n">8</span>
print(<span class="s">f"</span><span class="s">linked: hero=</span>{hero_a:<span class="s">.3f</span>}<span class="s"> decoy=</span>{decoy_a:<span class="s">.3f</span>}<span class="s"> </span><span class="s">"</span>
<span class="s">f"</span><span class="s">ratio=</span>{ratio_a:<span class="s">.1f</span>}<span class="s">x (min </span>{RATIO_MIN}<span class="s">x)</span><span class="s">"</span>)
print(<span class="s">f"</span><span class="s">unlinked: hero=</span>{hero_b:<span class="s">.3f</span>}<span class="s"> decoy=</span>{decoy_b:<span class="s">.3f</span>}<span class="s"> </span><span class="s">"</span>
<span class="s">f"</span><span class="s">rise=</span>{rise:<span class="s">.0%</span>}<span class="s"> (min </span>{RISE_MIN:<span class="s">.0%</span>}<span class="s">) </span><span class="s">"</span>
<span class="s">f"</span><span class="s">hero_drift=</span>{hero_drift:<span class="s">.1%</span>}<span class="s"> (max </span>{HERO_DRIFT_MAX:<span class="s">.0%</span>}<span class="s">)</span><span class="s">"</span>)
<span class="k">return</span> <span class="n">0</span>
<span class="k">def</span> eevee_engine_id():
<span class="k">return</span> <span class="s">'BLENDER_EEVEE'</span> <span class="k">if</span> bpy.app.version >= (<span class="n">5</span>, <span class="n">0</span>, <span class="n">0</span>) <span class="k">else</span> <span class="s">'BLENDER_EEVEE_NEXT'</span>
<span class="k">def</span> plaque(sc, text, x):
pm = bpy.data.materials.new(<span class="s">"PlaqueMetal"</span>)
pm.use_nodes = <span class="k">True</span>
pb = pm.node_tree.nodes[<span class="s">"Principled BSDF"</span>]
pb.inputs[<span class="s">"Base Color"</span>].default_value = (<span class="n">0.42</span>, <span class="n">0.44</span>, <span class="n">0.48</span>, <span class="n">1.0</span>)
pb.inputs[<span class="s">"Metallic"</span>].default_value = <span class="n">0.2</span>
pb.inputs[<span class="s">"Roughness"</span>].default_value = <span class="n">0.6</span>
<span class="c"># faint self-glow: the LINKED plaque must read even in the decoy's dark</span>
sock = pb.inputs.get(<span class="s">"Emission Color"</span>) <span class="k">or</span> pb.inputs[<span class="s">"Emission"</span>]
sock.default_value = (<span class="n">0.35</span>, <span class="n">0.37</span>, <span class="n">0.42</span>, <span class="n">1.0</span>)
pb.inputs[<span class="s">"Emission Strength"</span>].default_value = <span class="n">0.6</span>
cu = bpy.data.curves.new(<span class="s">"Plaque"</span>, <span class="s">'FONT'</span>)
cu.body = text
cu.align_x = <span class="s">'CENTER'</span>
cu.size = <span class="n">0.20</span>
cu.extrude = <span class="n">0.006</span>
ob = bpy.data.objects.new(<span class="s">"Plaque"</span>, cu)
ob.location = (x, -<span class="n">0.68</span>, <span class="n">0.01</span>)
ob.data.materials.append(pm)
sc.collection.objects.link(ob)
<span class="k">def</span> render_still(sc, path, engine):
plaque(sc, <span class="s">"LINKED"</span>, -<span class="n">1.2</span>)
plaque(sc, <span class="s">"UNLINKED"</span>, <span class="n">1.2</span>)
<span class="c"># the gallery still is the linked state, on Cycles for the same</span>
<span class="c"># deterministic sampling as the check</span>
sc.render.engine = <span class="s">'CYCLES'</span>
sc.cycles.samples = <span class="n">48</span>
sc.cycles.use_denoising = <span class="k">False</span>
sc.render.resolution_x = <span class="n">1280</span>
sc.render.resolution_y = <span class="n">720</span>
sc.render.resolution_percentage = <span class="n">100</span>
sc.render.image_settings.file_format = <span class="s">'PNG'</span>
sc.render.filepath = path
sc.view_settings.view_transform = <span class="s">'Standard'</span>
bpy.ops.render.render(write_still=<span class="k">True</span>)
<span class="k">return</span> os.path.exists(path) <span class="k">and</span> os.path.getsize(path) > <span class="n">0</span>
<span class="k">def</span> main():
argv = sys.argv[sys.argv.index(<span class="s">"--"</span>) + <span class="n">1</span>:] <span class="k">if</span> <span class="s">"--"</span> <span class="k">in</span> sys.argv <span class="k">else</span> []
p = argparse.ArgumentParser()
p.add_argument(<span class="s">"--output"</span>, default=<span class="k">None</span>, help=<span class="s">"optional: render a still PNG here"</span>)
p.add_argument(<span class="s">"--engine"</span>, default=<span class="s">"cycles"</span>, choices=(<span class="s">"cycles"</span>,),
help=<span class="s">"render engine — pinned to cycles for deterministic samples"</span>)
args = p.parse_args(argv)
bpy.ops.wm.read_factory_settings(use_empty=<span class="k">True</span>)
sc = bpy.context.scene
hero, decoy, hero_c, key = build_studio(sc)
code = check(sc, key, hero_c, hero, decoy)
<span class="k">if</span> code:
<span class="k">return</span> code
<span class="k">if</span> args.output:
<span class="k">if</span> <span class="k">not</span> render_still(sc, os.path.abspath(args.output), args.engine):
print(<span class="s">"ERROR: render produced no file"</span>, file=sys.stderr)
<span class="k">return</span> <span class="n">9</span>
print(<span class="s">f"</span><span class="s">rendered still </span>{args.output}<span class="s">"</span>)
print(<span class="s">"light-link-studio OK"</span>)
<span class="k">return</span> <span class="n">0</span>
<span class="k">if</span> __name__ == <span class="s">"__main__"</span>:
<span class="k">try</span>:
sys.exit(main())
<span class="k">except</span> Exception <span class="k">as</span> e:
<span class="k">import</span> traceback; traceback.print_exc(); print(<span class="s">f"</span><span class="s">FATAL: </span>{e}<span class="s">"</span>, file=sys.stderr); sys.exit(<span class="n">1</span>)
</pre>
</section>
</main>
<div class="lightbox" id="lightbox" role="dialog" aria-label="Full-size render">
<img src="../assets/light-link-studio-hero.webp" alt="light-link-studio render, full size" />
</div>
<footer>
<div class="statusbar">
<span>generated from <code>examples/gallery.json</code></span>
<span>CC-BY-NC-ND-4.0</span>
<span style="color: var(--ok);">exit 0</span>
</div>
</footer>
<script>
(function () {
var hero = document.getElementById('heroZoom');
var box = document.getElementById('lightbox');
if (hero && box) {
hero.addEventListener('click', function () { box.classList.add('open'); });
box.addEventListener('click', function () { box.classList.remove('open'); });
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') box.classList.remove('open');
});
}
var copy = document.getElementById('copyRun');
if (copy) {
copy.addEventListener('click', function () {
var cmd = document.getElementById('runCmd').textContent;
navigator.clipboard.writeText(cmd).then(function () {
copy.textContent = 'Copied!';
setTimeout(function () { copy.textContent = 'Copy'; }, 1500);
});
});
}
})();
</script>
</body>
</html>