Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
1737 lines (1603 loc) · 115 KB
/
Copy pathindex.html
File metadata and controls
1737 lines (1603 loc) · 115 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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>cart — Showcase — Blender Developer Tools</title>
<meta name="description" content="A procedural two-wheel wooden cart through UVs, bake, LOD, collider, and Unity glTF, asserting recomputed budgets rather than an API contract." />
<link rel="canonical" href="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/cart/" />
<link rel="icon" href="../../assets/favicon.svg" type="image/svg+xml" />
<meta name="theme-color" content="#1a1b1e" />
<meta name="color-scheme" content="dark" />
<meta property="og:type" content="website" />
<meta property="og:title" content="cart — Showcase — Blender Developer Tools" />
<meta property="og:description" content="A procedural two-wheel wooden cart through UVs, bake, LOD, collider, and Unity glTF, asserting recomputed budgets rather than an API contract." />
<meta property="og:url" content="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/cart/" />
<meta property="og:image" content="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/assets/cart-hero.webp" />
<meta property="og:image:width" content="1280" />
<meta property="og:image:height" content="720" />
<meta property="og:image:alt" content="cart: the showcase piece's own headless render" />
<meta property="og:site_name" content="Blender Developer Tools" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="cart — Showcase — Blender Developer Tools" />
<meta name="twitter:description" content="A procedural two-wheel wooden cart through UVs, bake, LOD, collider, and Unity glTF, asserting recomputed budgets rather than an API contract." />
<meta name="twitter:image" content="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/assets/cart-hero.webp" />
<meta name="twitter:image:alt" content="cart: the showcase piece's own headless render" />
<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 {
color-scheme: dark;
--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: sticky controls (search, density toggle, tag chips) ---- */
.controls { position: sticky; top: 46px; z-index: 4;
background: color-mix(in srgb, var(--bg) 94%, transparent);
backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
border-bottom: 1px solid var(--border); }
.controls-inner { max-width: var(--maxw); margin: 0 auto; padding: 0.55rem 1.25rem 0.6rem;
display: flex; flex-direction: column; gap: 0.5rem; }
.controls-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.searchwrap { position: relative; flex: 1 1 240px; min-width: 150px; }
.searchwrap input { width: 100%; background: var(--surface-2); border: 1px solid var(--border);
color: var(--text); border-radius: var(--radius); padding: 0.34rem 1.9rem 0.34rem 0.7rem;
font-family: var(--font-sans); font-size: 0.85rem; line-height: 1.4; }
.searchwrap input:focus { border-color: var(--select); outline: none; }
.searchwrap input::placeholder { color: var(--text-dim); }
.searchwrap input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.q-clear { position: absolute; right: 0.2rem; top: 50%; transform: translateY(-50%);
background: none; border: none; color: var(--text-dim); font-size: 1.05rem; line-height: 1;
cursor: pointer; padding: 0.25rem 0.45rem; border-radius: 3px; }
.q-clear:hover { color: var(--select); }
.count { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.04em;
text-transform: uppercase; color: var(--text-dim); white-space: nowrap; }
.density { display: flex; border: 1px solid var(--border); border-radius: var(--radius);
overflow: hidden; }
.density-btn { background: var(--surface-2); border: none; color: var(--text-dim); cursor: pointer;
font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.04em;
text-transform: uppercase; padding: 0.36rem 0.7rem; transition: color 0.15s, background 0.15s; }
.density-btn + .density-btn { border-left: 1px solid var(--border); }
.density-btn:hover { color: var(--select); }
.density-btn.active { background: var(--select); color: #1a1b1e; }
.tags-toggle { display: none; background: var(--surface-2); border: 1px solid var(--border);
color: var(--text-dim); border-radius: 3px; padding: 0.3rem 0.7rem; cursor: pointer;
font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em; text-transform: uppercase; }
.tags-toggle:hover, .tags-toggle.has-active { color: var(--select); border-color: var(--select); }
/* Tag chips wrap by default (no-JS safe). With JS the row becomes a scroll
strip on wide viewports and collapses behind the Tags toggle on narrow
ones, so the sticky bar never eats the mobile viewport. */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
html.js .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.25rem;
scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
html.js .chips::-webkit-scrollbar { height: 5px; }
html.js .chips::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.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; white-space: nowrap; flex: 0 0 auto;
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); }
@media (max-width: 719px) {
html.js .tags-toggle { display: inline-block; }
html.js .chips { display: none; }
html.js .chips.open { display: flex; flex-wrap: wrap; overflow-y: auto; max-height: 40vh; }
}
/* Compact density: hero + name + one-line teaser. The description and
WITNESSES text stay in the DOM (searchable, screen-reader reachable,
present with JS disabled when the class is never applied) but are
visually collapsed. Applied only by JS via the density-compact class. */
html.density-compact .grid { gap: 1rem; }
html.density-compact .card-body { padding: 0.65rem 0.9rem 0.7rem; }
html.density-compact .card-body h2 { font-size: 0.88rem; margin-bottom: 0.15rem; }
html.density-compact .teaches { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 0;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.density-compact .witnesses { position: absolute; width: 1px; height: 1px; margin: -1px;
padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
html.density-compact .card-link { display: none; }
.noresults { color: var(--text-dim); text-align: center; padding: 3rem 1rem; font-size: 0.95rem; }
.noresults .chip { margin-left: 0.6rem; }
.to-top { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 6; cursor: pointer;
background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
border-radius: var(--radius); padding: 0.45rem 0.75rem;
font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em;
text-transform: uppercase; opacity: 0; visibility: hidden;
transition: opacity 0.2s, visibility 0.2s, color 0.15s, border-color 0.15s; }
.to-top.show { opacity: 1; visibility: visible; }
.to-top:hover { color: 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; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
white-space: nowrap; }
.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, .md ol { margin: 0.7rem 0 0.7rem 1.4rem; }
.md li { margin: 0.3rem 0; }
.md .table-wrap { overflow-x: auto; margin: 0.9rem 0; }
.md table { border-collapse: collapse; font-size: 0.86rem; min-width: 100%; }
.md th, .md td { text-align: left; vertical-align: top; padding: 0.4rem 0.75rem 0.4rem 0;
border-bottom: 1px solid var(--border); }
.md th { color: var(--text-dim); font-weight: 600; white-space: nowrap; }
.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 { border: 0; margin: 0; padding: 2rem; width: 100%; height: 100%; max-width: none;
max-height: none; background: rgba(0,0,0,0.85); cursor: zoom-out; }
.lightbox[open] { display: flex; align-items: center; justify-content: center; }
.lightbox::backdrop { background: transparent; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--radius); }
.lightbox-close { position: absolute; top: 0.9rem; right: 0.9rem; background: var(--surface-2);
color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
font: 500 0.8rem var(--font-sans); padding: 0.4rem 0.75rem; cursor: pointer; }
.lightbox-close:hover { border-color: var(--select); color: var(--select); }
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 (min-width: 560px) { html.density-compact .grid { grid-template-columns: 1fr 1fr; gap: 1rem; } }
@media (min-width: 900px) { html.density-compact .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1560px) {
html.density-compact .controls-inner,
html.density-compact main { max-width: 1400px; }
html.density-compact .grid { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
html { scroll-behavior: auto; }
.card { transition: none; }
.card:hover { transform: none; }
.to-top { transition: 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 and Showcase</a>
<div class="topbar-right">
<a class="ghlink" href="https://github.com/TMHSDigital/Blender-Developer-Tools">GitHub</a>
</div>
</div>
<header class="hero">
<h1>cart</h1>
<p>A procedural two-wheel wooden cart through UVs, bake, LOD, collider, and Unity glTF, asserting recomputed budgets rather than an API contract.</p>
</header>
<main id="main">
<button class="detail-hero" id="heroZoom" type="button" aria-label="Zoom cart render">
<img src="../assets/cart-hero.webp" alt="cart render" width="1280" height="720" />
</button>
<p class="zoom-hint">Rendered headless by the showcase piece itself — click to zoom.</p>
<div class="callout"><span class="tag">witnesses</span> Recomputed: 2856 tris, two materials with metal and wood face floors, UVs in 0..1 with zero AABB overlap, outer AABB 1.539×0.749×0.640 m, LOD ratios in band, convex collider 154 tris, hygiene zero (loose, non-manifold, doubles, n-gons), zero coplanar cross-shell face pairs, both tyres grounded, tyre seat depth in band over 48 angular stations, the two wheels mirrored within 5e-5 m, grounded zmin, non-empty glTF. --flush-tyre exits 15 on the z-fight budget; --sink-tyre exits 18 on the tyre seat band; --float-wheel exits 16 on the named-support budget; --skew-wheel exits 19 on the wheel mirror; --skip-decimate exits 9 on the LOD1 ratio budget; --lift-z exits 16 on the grounded budget.</div>
<div class="runline">
<pre id="runCmd">blender --background --python showcase/cart/cart.py --</pre>
<button class="copy-btn" id="copyRun" type="button">Copy</button>
</div>
<section class="detail-section md">
<p>A showcase piece, not an example. Procedural two-wheel wooden cart (slatted bed, side walls, shafts, spoked wheels, iron hubs and axle) then the shipped pipeline: unique-cell UVs, Cycles high-to-low normal bake, LOD chain, convex collider, Unity glTF export.</p>
<p>It asserts <strong>budget conformance</strong> of the generated result. It does not witness an API contract. "It rendered without error" is not a check.</p>
<p><strong>Composes</strong> skills <code>mesh-editing-and-bmesh</code>, <code>bake-high-to-low</code>, <code>depsgraph-and-evaluated-data</code>, <code>engine-export-presets</code>, and snippets <code>bake_normal_high_to_low.py</code>, <code>setup_bake_target_image.py</code>, <code>lod_chain.py</code> / <code>decimate_to_budget.py</code>, <code>convex_hull_collider.py</code>, <code>export_preset_unity.py</code> (helpers copied, not imported as a package).</p>
<h2>Budgets</h2>
<p>Declared as named constants; every gate <strong>recomputes</strong> from the mesh, materials, UVs, evaluated LOD, collider, or export file.</p>
<div class="table-wrap"><table><thead><tr><th scope="col">Axis</th><th scope="col">Declared</th><th scope="col">Measured (4.5.11 / 5.1.2 / 5.2.1)</th></tr></thead><tbody><tr><td>Base triangles</td><td>2760–2960</td><td>2856 / 2856 / 2856</td></tr><tr><td>LOD1 ratio</td><td>0.32–0.62 of base</td><td>0.5000 / 0.5000 / 0.5000</td></tr><tr><td>LOD2 ratio</td><td>0.10–0.35 of base</td><td>0.2199 / 0.2199 / 0.2157</td></tr><tr><td>Materials</td><td>exactly 2 distinct, metal ≥ 24, wood ≥ 800 faces</td><td>2 slots, floors met</td></tr><tr><td>UVs</td><td>in <code>0..1</code>, AABB overlap ≤ 1e-5</td><td>in range, overlap 0</td></tr><tr><td>Outer AABB</td><td>(1.539, 0.749, 0.640) m ± 0.01</td><td>(1.5393, 0.7486, 0.6400)</td></tr><tr><td>Grounded</td><td>bbox min Z within 1e-4 of 0</td><td>0.0000 / 0.0000 / 0.0000</td></tr><tr><td>Named supports</td><td>each tyre's own zmin within 1e-4 of the floor</td><td>+Y 0.000000, −Y 0.000000</td></tr><tr><td>Hygiene</td><td>loose V/E, non-manifold, zero-area, doubles @1e-5, n-gons: all 0</td><td>0 / 0 / 0 on every axis</td></tr><tr><td>Z-fighting</td><td>coplanar cross-shell face pairs = 0</td><td>0 / 0 / 0</td></tr><tr><td>Tyre seat</td><td>0.0030–0.0055 m interference, per angular station</td><td>[0.00400, 0.00400] over 48 stations</td></tr><tr><td>Wheel mirror</td><td>the two wheels match in X, Z and extent within 5e-5 m</td><td>0.00000 mm</td></tr><tr><td>Material-island gap</td><td>metal↔wood min distance ≤ 0.008 m</td><td>0.00000 / 0.00000 / 0.00000</td></tr><tr><td>Collider tris</td><td>≤ 360</td><td>154</td></tr><tr><td>Export</td><td>written, size > 0, removed after measuring</td><td>221960 bytes on 5.2.1</td></tr></tbody></table></div>
<p>DECIMATE COLLAPSE triangle counts are <strong>not</strong> identical across series — 5.2.1 is more aggressive on LOD2. The gate is a ratio band, not an exact count. Bake pixels are stochastic; the gate is <code>has_data</code> plus operator <code>FINISHED</code>, not byte-identity. Construction uses no RNG. Export byte counts differ by a few bytes across series (glTF serializer); the gate is "written and non-empty", not a byte count, and the file is removed once measured.</p>
<h2>Falsifiers</h2>
<p>Each flag breaks one stage so a <strong>named</strong> budget fails and the piece exits <em>that</em> code. Magnitudes are sized so no earlier gate can steal the failure: the two wheel moves stay inside <code>BBOX_TOL</code>, so the AABB gate (exit 8) still passes.</p>
<div class="table-wrap"><table><thead><tr><th scope="col">Flag</th><th scope="col">Target budget</th><th scope="col">Exit</th></tr></thead><tbody><tr><td><code>--skip-decimate</code></td><td>LOD1 ratio band (ratio becomes 1.0)</td><td>9</td></tr><tr><td><code>--lift-z</code></td><td>AABB grounded zmin (whole mesh up 0.05 m)</td><td>16</td></tr><tr><td><code>--flush-tyre</code></td><td>Coplanar cross-shell pairs — sets the tyre's inner radius equal to the felloe's outer radius, which is the construction bug this piece was rebuilt to remove (0 → 48 pairs)</td><td>15</td></tr><tr><td><code>--sink-tyre</code></td><td>Tyre seat band — buries the hoop 9 mm into the felloe so it reads as one body</td><td>18</td></tr><tr><td><code>--float-wheel</code></td><td>Named supports — lifts one wheel 3 mm while the other still grounds the AABB</td><td>16</td></tr><tr><td><code>--skew-wheel</code></td><td>Wheel mirror — pushes one wheel 6 mm out along the track</td><td>19</td></tr></tbody></table></div>
<p><code>--lift-z</code> and <code>--float-wheel</code> share exit 16 and fail different budgets: <code>--lift-z</code> fails the AABB gate, which fires first; <code>--float-wheel</code> leaves the AABB grounded, so only the per-tyre support check can catch it.</p>
<h2>Run</h2>
<pre><code>blender --background --python cart.py --
blender --background --python cart.py -- --skip-decimate
blender --background --python cart.py -- --lift-z
blender --background --python cart.py -- --flush-tyre
blender --background --python cart.py -- --sink-tyre
blender --background --python cart.py -- --float-wheel
blender --background --python cart.py -- --skew-wheel
blender --background --python cart.py -- --output cart.png</code></pre>
<p>Smoke passes none of the falsifier flags and no <code>--output</code>.</p>
<h2>Exit codes</h2>
<p>File-local. <code>9</code> is a valid check code. <code>10</code> is reserved for <code>gallery_framing.check_framing</code> on the <code>--output</code> path.</p>
<div class="table-wrap"><table><thead><tr><th scope="col">Code</th><th scope="col">Meaning</th></tr></thead><tbody><tr><td>0</td><td>Success</td></tr><tr><td>1</td><td>Uncaught exception (FATAL wrapper)</td></tr><tr><td>2</td><td>argparse / usage</td></tr><tr><td>3</td><td>Mesh did not build / no UV layer</td></tr><tr><td>4</td><td>Base triangle count outside range</td></tr><tr><td>5</td><td>Material count ≠ 2 distinct slots, or metal faces missing</td></tr><tr><td>6</td><td>UVs outside 0..1</td></tr><tr><td>7</td><td>UV AABB overlap above tolerance</td></tr><tr><td>8</td><td>World AABB off declared outer size</td></tr><tr><td>9</td><td>LOD ratio band (<code>--skip-decimate</code> lands here)</td></tr><tr><td>10</td><td>Framing gate (render path only)</td></tr><tr><td>11</td><td>Collider triangle count above ceiling</td></tr><tr><td>12</td><td>Bake did not finish or image has no data</td></tr><tr><td>13</td><td>Export file missing or empty</td></tr><tr><td>14</td><td><code>--output</code> produced no file</td></tr><tr><td>15</td><td>Hygiene: loose geometry, non-manifold, zero-area, doubles, n-gons, or coplanar cross-shell face pairs (<code>--flush-tyre</code> lands here)</td></tr><tr><td>16</td><td>Bbox min Z not grounded (<code>--lift-z</code>), or a named support off the floor (<code>--float-wheel</code>)</td></tr><tr><td>17</td><td>Material-island gap above tolerance (parts meant to touch)</td></tr><tr><td>18</td><td>Tyre seat depth outside its band (<code>--sink-tyre</code> lands here)</td></tr><tr><td>19</td><td>Wheel mirror deviation above epsilon (<code>--skew-wheel</code> lands here)</td></tr></tbody></table></div>
</section>
<section class="detail-section src">
<h2>Source</h2>
<div class="src-meta">
<code>showcase/cart/cart.py</code>
<a href="https://github.com/TMHSDigital/Blender-Developer-Tools/tree/main/showcase/cart/cart.py">View on GitHub →</a>
</div>
<pre><span class="s">"""Game-ready two-wheel wooden cart — a showcase piece, not an example.
Asserts budget conformance of a procedural cart (staved bed, side
walls, shafts, spoked wheels, iron hubs and axle) after composing
shipped pipeline pieces: bmesh construction, UVs, two materials,
high-to-low normal bake, LOD chain, convex collider, Unity glTF
export.
Budgets are declared below and recomputed from the generated result.
They are not API-contract witnesses. Each falsifier flag breaks one
stage so a named budget fails and the piece exits that budget's code:
``--skip-decimate`` (LOD ratio, 9), ``--lift-z`` (AABB grounded, 16),
``--float-wheel`` (named supports, 16), ``--flush-tyre`` (coplanar
cross-shell pairs, 15), ``--sink-tyre`` (tyre seat band, 18),
``--skew-wheel`` (wheel mirror, 19). The two wheel moves stay inside
``BBOX_TOL`` so the AABB gate cannot steal the failure.
No RNG. Construction is closed-form. DECIMATE COLLAPSE triangle counts
are not byte-identical across Blender versions — the LOD gate is a
ratio band, not an exact count.
blender --background --python cart.py --
blender --background --python cart.py -- --skip-decimate
blender --background --python cart.py -- --flush-tyre
blender --background --python cart.py -- --output cart.png
"""</span>
<span class="k">import</span> argparse
<span class="k">import</span> math
<span class="k">import</span> os
<span class="k">import</span> sys
<span class="k">import</span> tempfile
<span class="k">import</span> traceback
<span class="k">import</span> bmesh
<span class="k">import</span> bpy
<span class="k">from</span> mathutils <span class="k">import</span> Euler, Vector
<span class="k">from</span> mathutils.bvhtree <span class="k">import</span> BVHTree
_REPO = os.path.abspath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir)
)
sys.path.insert(<span class="n">0</span>, os.path.join(_REPO, <span class="s">"examples"</span>))
sys.dont_write_bytecode = <span class="k">True</span>
<span class="k">import</span> gallery_framing <span class="c"># noqa: E402</span>
RIM_MAJOR = <span class="n">0.30</span>
<span class="c"># Felloe ring: flat-tread box section, not a round tube — round torus rims</span>
<span class="c"># read as bicycle wheels. The iron tyre wraps the tread.</span>
RIM_RADIAL = <span class="n">0.012</span>
RIM_W = <span class="n">0.036</span>
TYRE_T = <span class="n">0.008</span>
TYRE_W = <span class="n">0.040</span>
<span class="c"># Felloe outer radius is the *host* surface the tyre is hooped onto. The</span>
<span class="c"># tyre's inner radius is derived from it minus a named interference, never</span>
<span class="c"># set equal to it: r_in == r_out puts the tyre's inner cylinder and the</span>
<span class="c"># felloe's tread on one plane for every segment, which is a guaranteed</span>
<span class="c"># z-fight (it measured 32 coplanar cross-shell pairs, 16 per wheel).</span>
RIM_OUTER = RIM_MAJOR + RIM_RADIAL
TYRE_SEAT = <span class="n">0.004</span>
TYRE_SEAT_MIN = <span class="n">0.0030</span>
TYRE_SEAT_MAX = <span class="n">0.0055</span>
WHEEL_SEGMENTS = <span class="n">24</span>
TRACK = <span class="n">0.68</span>
AXLE_X = -<span class="n">0.16</span>
AXLE_R = <span class="n">0.020</span>
HUB_R = <span class="n">0.052</span>
HUB_W = <span class="n">0.046</span>
N_SPOKES = <span class="n">8</span>
SPOKE_T = <span class="n">0.018</span>
BED_L = <span class="n">0.92</span>
BED_W = <span class="n">0.50</span>
BED_T = <span class="n">0.038</span>
WALL_H = <span class="n">0.16</span>
WALL_T = <span class="n">0.032</span>
TAILGATE_H = <span class="n">0.10</span>
SHAFT_L = <span class="n">0.58</span>
SHAFT_T = <span class="n">0.034</span>
SHAFT_PITCH = math.radians(<span class="n">7.0</span>)
N_SLATS = <span class="n">6</span>
IRON_T = <span class="n">0.014</span>
BOLSTER_H = <span class="n">0.044</span>
BBOX_TOL = <span class="n">0.01</span>
OUTER_SIZE = (<span class="n">1.539</span>, <span class="n">0.749</span>, <span class="n">0.640</span>)
<span class="c"># Re-fitted after the wheel went from 16 to 24 segments (2600 -> 2856).</span>
<span class="c"># Narrower than the band it replaces (200 wide, was 430) and centred on</span>
<span class="c"># the measured value, so this is a tightening, not a widening.</span>
BASE_TRIS_MIN = <span class="n">2760</span>
BASE_TRIS_MAX = <span class="n">2960</span>
ZMIN_EPS = <span class="n">1e-4</span>
DOUBLES_EPS = <span class="n">1e-5</span>
AREA_EPS = <span class="n">1e-10</span>
GAP_MAX = <span class="n">0.008</span>
LIFT_Z = <span class="n">0.05</span>
LOD1_RATIO_MIN = <span class="n">0.32</span>
LOD1_RATIO_MAX = <span class="n">0.62</span>
LOD2_RATIO_MIN = <span class="n">0.10</span>
LOD2_RATIO_MAX = <span class="n">0.35</span>
LOD1_TARGET = <span class="n">0.50</span>
LOD2_TARGET = <span class="n">0.22</span>
MATERIAL_COUNT = <span class="n">2</span>
UV_EPS = <span class="n">1e-4</span>
UV_OVERLAP_MAX = <span class="n">1e-5</span>
COLLIDER_TRIS_MAX = <span class="n">360</span>
BAKE_RES = <span class="n">256</span>
CAGE_EXTRUSION = <span class="n">0.08</span>
METAL_FACES_MIN = <span class="n">24</span>
WOOD_FACES_MIN = <span class="n">800</span>
<span class="c"># Z-fighting: two separate bodies landing on one plane. Cross-shell, with</span>
<span class="c"># hay-bale's constants (copied, not imported).</span>
COPLANAR_NORMAL_EPS = <span class="n">1e-4</span>
COPLANAR_PLANE_EPS = <span class="n">1e-4</span>
COPLANAR_CENTRE_MAX = <span class="n">0.05</span>
ZFIGHT_PAIRS_MAX = <span class="n">0</span>
<span class="c"># Named supports: a two-wheel cart's AABB zmin is grounded by whichever</span>
<span class="c"># tyre happens to be lowest. Each tyre carries its own floor contact.</span>
SUPPORT_ZMIN_EPS = <span class="n">1e-4</span>
<span class="c"># Mirrored members: the two wheels are the same part reflected in Y.</span>
WHEEL_MIRROR_EPS = <span class="n">5e-5</span>
<span class="c"># Falsifier magnitudes, each sized to trip its own budget and nothing</span>
<span class="c"># earlier: the wheel moves stay inside BBOX_TOL so the AABB gate cannot</span>
<span class="c"># steal the failure.</span>
SINK_TYRE_SEAT = <span class="n">0.009</span>
FLOAT_WHEEL_Z = <span class="n">0.003</span>
SKEW_WHEEL_Y = <span class="n">0.006</span>
WOOD_IDX = <span class="n">0</span>
METAL_IDX = <span class="n">1</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> fail(msg, code):
print(<span class="s">f"</span><span class="s">ERROR: </span>{msg}<span class="s">"</span>, file=sys.stderr)
<span class="k">return</span> code
<span class="k">def</span> triangle_count(mesh):
mesh.calc_loop_triangles()
<span class="k">return</span> len(mesh.loop_triangles)
<span class="k">def</span> evaluated_triangle_count(obj):
depsgraph = bpy.context.evaluated_depsgraph_get()
eval_obj = obj.evaluated_get(depsgraph)
eval_mesh = eval_obj.to_mesh()
<span class="k">try</span>:
eval_mesh.calc_loop_triangles()
<span class="k">return</span> len(eval_mesh.loop_triangles)
<span class="k">finally</span>:
eval_obj.to_mesh_clear()
<span class="k">def</span> deselect_all():
<span class="k">for</span> ob <span class="k">in</span> list(bpy.context.view_layer.objects):
<span class="k">if</span> ob <span class="k">is</span> <span class="k">None</span>:
<span class="k">continue</span>
ob.select_set(<span class="k">False</span>)
<span class="k">def</span> add_box(bm, loc, scale, mat_idx, euler=(<span class="n">0.0</span>, <span class="n">0.0</span>, <span class="n">0.0</span>)):
geo = bmesh.ops.create_cube(bm, size=<span class="n">1.0</span>)
verts = geo[<span class="s">"verts"</span>]
rot = Euler(euler).to_matrix()
origin = Vector(loc)
<span class="k">for</span> v <span class="k">in</span> verts:
p = Vector((v.co.x * scale[<span class="n">0</span>], v.co.y * scale[<span class="n">1</span>], v.co.z * scale[<span class="n">2</span>]))
v.co = rot @ p + origin
faces = {f <span class="k">for</span> v <span class="k">in</span> verts <span class="k">for</span> f <span class="k">in</span> v.link_faces}
<span class="k">for</span> f <span class="k">in</span> faces:
f.material_index = mat_idx
<span class="k">return</span> verts
<span class="k">def</span> add_cyl(bm, loc, radius, depth, segments, mat_idx, euler=(<span class="n">0.0</span>, <span class="n">0.0</span>, <span class="n">0.0</span>)):
geo = bmesh.ops.create_cone(
bm,
cap_ends=<span class="k">True</span>,
cap_tris=<span class="k">True</span>,
segments=segments,
radius1=radius,
radius2=radius,
depth=depth,
)
verts = geo[<span class="s">"verts"</span>]
rot = Euler(euler).to_matrix()
origin = Vector(loc)
<span class="k">for</span> v <span class="k">in</span> verts:
v.co = rot @ v.co + origin
faces = {f <span class="k">for</span> v <span class="k">in</span> verts <span class="k">for</span> f <span class="k">in</span> v.link_faces}
<span class="k">for</span> f <span class="k">in</span> faces:
f.material_index = mat_idx
<span class="k">return</span> verts
<span class="k">def</span> add_ring(bm, loc, r_mid, radial_t, width, segments, mat_idx, euler=(<span class="n">0.0</span>, <span class="n">0.0</span>, <span class="n">0.0</span>)):
<span class="s">"""Flat-sided ring with a box cross-section (felloe / tyre profile).
Manifold: outer tread, inner surface, and two side annuli, all quads.
Built in the XY plane, width along Z, then rotated/translated.
"""</span>
r_in = r_mid - radial_t
r_out = r_mid + radial_t
hw = width / <span class="n">2.0</span>
rings = []
<span class="k">for</span> i <span class="k">in</span> range(segments):
u = i * (<span class="n">2.0</span> * math.pi / segments)
cu = math.cos(u)
su = math.sin(u)
rings.append(
[
bm.verts.new((r_in * cu, r_in * su, -hw)),
bm.verts.new((r_out * cu, r_out * su, -hw)),
bm.verts.new((r_out * cu, r_out * su, hw)),
bm.verts.new((r_in * cu, r_in * su, hw)),
]
)
<span class="k">for</span> i <span class="k">in</span> range(segments):
i2 = (i + <span class="n">1</span>) % segments
a = rings[i]
b = rings[i2]
<span class="k">for</span> quad <span class="k">in</span> (
(a[<span class="n">1</span>], b[<span class="n">1</span>], b[<span class="n">2</span>], a[<span class="n">2</span>]),
(a[<span class="n">3</span>], b[<span class="n">3</span>], b[<span class="n">0</span>], a[<span class="n">0</span>]),
(a[<span class="n">2</span>], b[<span class="n">2</span>], b[<span class="n">3</span>], a[<span class="n">3</span>]),
(a[<span class="n">0</span>], b[<span class="n">0</span>], b[<span class="n">1</span>], a[<span class="n">1</span>]),
):
face = bm.faces.new(quad)
face.material_index = mat_idx
verts = [v <span class="k">for</span> ring <span class="k">in</span> rings <span class="k">for</span> v <span class="k">in</span> ring]
rot = Euler(euler).to_matrix()
origin = Vector(loc)
<span class="k">for</span> v <span class="k">in</span> verts:
v.co = rot @ v.co + origin
<span class="k">return</span> verts
<span class="k">def</span> pack_uvs(bm, margin=<span class="n">0.08</span>):
uv = bm.loops.layers.uv.new(<span class="s">"UVMap"</span>)
faces = list(bm.faces)
n = len(faces)
cols = max(<span class="n">1</span>, math.ceil(math.sqrt(n)))
rows = max(<span class="n">1</span>, math.ceil(n / cols))
cell_w = <span class="n">1.0</span> / cols
cell_h = <span class="n">1.0</span> / rows
pad_u = margin * cell_w * <span class="n">0.5</span>
pad_v = margin * cell_h * <span class="n">0.5</span>
usable_w = cell_w - <span class="n">2.0</span> * pad_u
usable_h = cell_h - <span class="n">2.0</span> * pad_v
<span class="k">for</span> i, face <span class="k">in</span> enumerate(faces):
col = i % cols
row = i // cols
nrm = face.normal
ax = abs(nrm.x)
ay = abs(nrm.y)
az = abs(nrm.z)
coords = []
<span class="k">for</span> loop <span class="k">in</span> face.loops:
co = loop.vert.co
<span class="k">if</span> az >= ax <span class="k">and</span> az >= ay:
coords.append((co.x, co.y))
<span class="k">elif</span> ax >= ay:
coords.append((co.y, co.z))
<span class="k">else</span>:
coords.append((co.x, co.z))
xs = [c[<span class="n">0</span>] <span class="k">for</span> c <span class="k">in</span> coords]
ys = [c[<span class="n">1</span>] <span class="k">for</span> c <span class="k">in</span> coords]
minx, maxx = min(xs), max(xs)
miny, maxy = min(ys), max(ys)
dx = max(maxx - minx, <span class="n">1e-8</span>)
dy = max(maxy - miny, <span class="n">1e-8</span>)
origin_u = col * cell_w + pad_u
origin_v = row * cell_h + pad_v
<span class="k">for</span> loop, (x, y) <span class="k">in</span> zip(face.loops, coords):
loop[uv].uv = (
origin_u + (x - minx) / dx * usable_w,
origin_v + (y - miny) / dy * usable_h,
)
<span class="k">def</span> add_wheel(bm, loc, wood, metal):
wood.extend(
add_ring(
bm, loc, RIM_MAJOR, RIM_RADIAL, RIM_W, WHEEL_SEGMENTS, WOOD_IDX,
euler=(math.pi / <span class="n">2.0</span>, <span class="n">0.0</span>, <span class="n">0.0</span>),
)
)
<span class="c"># Hooped, not pasted on: inner radius is RIM_OUTER - TYRE_SEAT so the</span>
<span class="c"># band bites into the felloe, and the tread still lands at</span>
<span class="c"># RIM_OUTER + TYRE_T so the tyre stays the ground contact.</span>
tyre_in = RIM_OUTER - TYRE_SEAT
tyre_out = RIM_OUTER + TYRE_T
metal.extend(
add_ring(
bm, loc, <span class="n">0.5</span> * (tyre_in + tyre_out), <span class="n">0.5</span> * (tyre_out - tyre_in),
TYRE_W, WHEEL_SEGMENTS, METAL_IDX,
euler=(math.pi / <span class="n">2.0</span>, <span class="n">0.0</span>, <span class="n">0.0</span>),
)
)
wood.extend(
add_cyl(
bm,
loc,
HUB_R,
HUB_W,
<span class="n">12</span>,
WOOD_IDX,
euler=(math.pi / <span class="n">2.0</span>, <span class="n">0.0</span>, <span class="n">0.0</span>),
)
)
<span class="c"># Spokes root inside the hub and embed into the felloe ring — no</span>
<span class="c"># floating ends hidden by the hub band.</span>
inner = HUB_R * <span class="n">0.4</span>
outer = RIM_MAJOR - RIM_RADIAL + <span class="n">0.008</span>
mid_r = <span class="n">0.5</span> * (inner + outer)
slen = outer - inner
<span class="k">for</span> i <span class="k">in</span> range(N_SPOKES):
a = i * (<span class="n">2.0</span> * math.pi / N_SPOKES)
dx = math.cos(a)
dz = math.sin(a)
cx = loc[<span class="n">0</span>] + dx * mid_r
cy = loc[<span class="n">1</span>]
cz = loc[<span class="n">2</span>] + dz * mid_r
wood.extend(
add_box(
bm,
(cx, cy, cz),
(slen, SPOKE_T * <span class="n">0.85</span>, SPOKE_T),
WOOD_IDX,
euler=(<span class="n">0.0</span>, -a, <span class="n">0.0</span>),
)
)
metal.extend(
add_cyl(
bm,
loc,
HUB_R + <span class="n">0.010</span>,
<span class="n">0.016</span>,
<span class="n">12</span>,
METAL_IDX,
euler=(math.pi / <span class="n">2.0</span>, <span class="n">0.0</span>, <span class="n">0.0</span>),
)
)
metal.extend(
add_cyl(
bm,
(loc[<span class="n">0</span>], loc[<span class="n">1</span>] + (HUB_W * <span class="n">0.55</span> <span class="k">if</span> loc[<span class="n">1</span>] > <span class="n">0</span> <span class="k">else</span> -HUB_W * <span class="n">0.55</span>), loc[<span class="n">2</span>]),
<span class="n">0.022</span>,
<span class="n">0.018</span>,
<span class="n">10</span>,
METAL_IDX,
euler=(math.pi / <span class="n">2.0</span>, <span class="n">0.0</span>, <span class="n">0.0</span>),
)
)
<span class="k">def</span> build_cart_mesh(name, bevel_offset, bevel_segments):
bm = bmesh.new()
<span class="k">try</span>:
body = []
wood_wheels = []
metal = []
axle_z = RIM_MAJOR
<span class="c"># The bed rides on the axle through a bolster: axle top -> bolster -></span>
<span class="c"># bed bottom. Never let the axle interpenetrate the slats.</span>
bed_z = axle_z + AXLE_R + BOLSTER_H + BED_T / <span class="n">2.0</span>
bed_bottom = bed_z - BED_T / <span class="n">2.0</span>
bed_cx = <span class="n">0.06</span>
add_wheel(bm, (AXLE_X, TRACK / <span class="n">2.0</span>, axle_z), wood_wheels, metal)
add_wheel(bm, (AXLE_X, -TRACK / <span class="n">2.0</span>, axle_z), wood_wheels, metal)
metal.extend(
add_cyl(
bm,
(AXLE_X, <span class="n">0.0</span>, axle_z),
AXLE_R,
TRACK + <span class="n">0.06</span>,
<span class="n">10</span>,
METAL_IDX,
euler=(math.pi / <span class="n">2.0</span>, <span class="n">0.0</span>, <span class="n">0.0</span>),
)
)
slat_w = BED_W / N_SLATS
y0 = -BED_W / <span class="n">2.0</span> + slat_w / <span class="n">2.0</span>
<span class="k">for</span> i <span class="k">in</span> range(N_SLATS):
y = y0 + i * slat_w
body.extend(
add_box(
bm,
(bed_cx, y, bed_z),
(BED_L, slat_w * <span class="n">0.88</span>, BED_T),
WOOD_IDX,
)
)
<span class="c"># Side walls and the front board finish flush at WALL_H; the back</span>
<span class="c"># board is a deliberately lower tailgate.</span>
<span class="k">for</span> ysign <span class="k">in</span> (-<span class="n">1.0</span>, <span class="n">1.0</span>):
body.extend(
add_box(
bm,
(bed_cx, ysign * (BED_W / <span class="n">2.0</span> + WALL_T / <span class="n">2.0</span>), bed_z + WALL_H / <span class="n">2.0</span>),
(BED_L * <span class="n">0.98</span>, WALL_T, WALL_H),
WOOD_IDX,
)
)
body.extend(
add_box(
bm,
(bed_cx + BED_L / <span class="n">2.0</span> - WALL_T / <span class="n">2.0</span>, <span class="n">0.0</span>, bed_z + WALL_H / <span class="n">2.0</span>),
(WALL_T, BED_W + WALL_T * <span class="n">2.0</span>, WALL_H),
WOOD_IDX,
)
)
body.extend(
add_box(
bm,
(bed_cx - BED_L / <span class="n">2.0</span> + WALL_T / <span class="n">2.0</span>, <span class="n">0.0</span>, bed_z + TAILGATE_H / <span class="n">2.0</span>),
(WALL_T, BED_W + WALL_T * <span class="n">2.0</span>, TAILGATE_H),
WOOD_IDX,
)
)
<span class="c"># Bolsters: one sits on the axle, one forward; both carry the bed.</span>
<span class="k">for</span> xj <span class="k">in</span> (AXLE_X, bed_cx + BED_L * <span class="n">0.28</span>):
body.extend(
add_box(
bm,
(xj, <span class="n">0.0</span>, axle_z + AXLE_R + BOLSTER_H / <span class="n">2.0</span>),
(<span class="n">0.055</span>, BED_W * <span class="n">0.92</span>, BOLSTER_H),
WOOD_IDX,
)
)
<span class="c"># Shafts hang under the bed front: the back end embeds 6 mm into the</span>
<span class="c"># slat bottom and never pokes through the bed floor.</span>
shaft_x = bed_cx + BED_L / <span class="n">2.0</span> + SHAFT_L / <span class="n">2.0</span> - <span class="n">0.04</span>
shaft_z = (
bed_bottom + <span class="n">0.006</span> - SHAFT_T / <span class="n">2.0</span>
- math.sin(SHAFT_PITCH) * (SHAFT_L / <span class="n">2.0</span>)
)
<span class="k">for</span> ysign <span class="k">in</span> (-<span class="n">1.0</span>, <span class="n">1.0</span>):
body.extend(
add_box(
bm,
(shaft_x, ysign * <span class="n">0.12</span>, shaft_z),
(SHAFT_L, SHAFT_T, SHAFT_T),
WOOD_IDX,
euler=(<span class="n">0.0</span>, SHAFT_PITCH, <span class="n">0.0</span>),
)
)
metal.extend(
add_box(
bm,
(bed_cx + BED_L / <span class="n">2.0</span> - <span class="n">0.02</span>, ysign * <span class="n">0.12</span>, bed_bottom - IRON_T / <span class="n">2.0</span>),
(<span class="n">0.05</span>, <span class="n">0.042</span>, IRON_T),
METAL_IDX,
)
)
<span class="c"># Tie-down plates sit on top of the bed floor, fully inboard of the</span>
<span class="c"># walls — visible, not buried inside the slats.</span>
<span class="k">for</span> sx, sy <span class="k">in</span> (
(bed_cx - BED_L / <span class="n">2.0</span> + <span class="n">0.055</span>, -BED_W / <span class="n">2.0</span> + <span class="n">0.055</span>),
(bed_cx - BED_L / <span class="n">2.0</span> + <span class="n">0.055</span>, BED_W / <span class="n">2.0</span> - <span class="n">0.055</span>),
(bed_cx + BED_L / <span class="n">2.0</span> - <span class="n">0.055</span>, -BED_W / <span class="n">2.0</span> + <span class="n">0.055</span>),
(bed_cx + BED_L / <span class="n">2.0</span> - <span class="n">0.055</span>, BED_W / <span class="n">2.0</span> - <span class="n">0.055</span>),
):
metal.extend(
add_box(
bm,
(sx, sy, bed_z + BED_T / <span class="n">2.0</span> + IRON_T / <span class="n">2.0</span>),
(<span class="n">0.055</span>, <span class="n">0.055</span>, IRON_T),
METAL_IDX,
)
)
<span class="k">if</span> bevel_offset > <span class="n">0.0</span>:
edges = list({e <span class="k">for</span> v <span class="k">in</span> body <span class="k">for</span> e <span class="k">in</span> v.link_edges})
ret = bmesh.ops.bevel(
bm,
geom=edges,
offset=bevel_offset,
segments=bevel_segments,
profile=<span class="n">0.5</span>,
affect=<span class="s">"EDGES"</span>,
clamp_overlap=<span class="k">True</span>,
)
<span class="k">for</span> f <span class="k">in</span> ret.get(<span class="s">"faces"</span>) <span class="k">or</span> []:
f.material_index = WOOD_IDX
xs = [v.co.x <span class="k">for</span> v <span class="k">in</span> bm.verts]
ys = [v.co.y <span class="k">for</span> v <span class="k">in</span> bm.verts]
zs = [v.co.z <span class="k">for</span> v <span class="k">in</span> bm.verts]
cx = <span class="n">0.5</span> * (min(xs) + max(xs))
cy = <span class="n">0.5</span> * (min(ys) + max(ys))
zmin = min(zs)
<span class="k">for</span> v <span class="k">in</span> bm.verts:
v.co.x -= cx
v.co.y -= cy
v.co.z -= zmin
<span class="k">if</span> v.co.z < <span class="n">0.0</span>:
v.co.z = <span class="n">0.0</span>
pack_uvs(bm)
bmesh.ops.recalc_face_normals(bm, faces=list(bm.faces))
<span class="k">for</span> face <span class="k">in</span> bm.faces:
face.smooth = <span class="k">False</span>
me = bpy.data.meshes.new(name)
bm.to_mesh(me)
me.update()
<span class="k">for</span> poly <span class="k">in</span> me.polygons:
poly.use_smooth = <span class="k">False</span>
<span class="k">finally</span>:
bm.free()
out = bpy.data.objects.new(name, me)
bpy.context.collection.objects.link(out)
<span class="k">return</span> out
<span class="k">def</span> principled(name, color, metallic, roughness, noise_scale=<span class="n">0.0</span>, wear=<span class="k">None</span>):
mat = bpy.data.materials.new(name)
mat.use_nodes = <span class="k">True</span>
nt = mat.node_tree
bsdf = nt.nodes[<span class="s">"Principled BSDF"</span>]
bsdf.inputs[<span class="s">"Base Color"</span>].default_value = color
bsdf.inputs[<span class="s">"Metallic"</span>].default_value = metallic
bsdf.inputs[<span class="s">"Roughness"</span>].default_value = roughness
<span class="k">if</span> noise_scale > <span class="n">0.0</span> <span class="k">and</span> wear <span class="k">is</span> <span class="k">not</span> <span class="k">None</span>:
tex = nt.nodes.new(<span class="s">"ShaderNodeTexNoise"</span>)
tex.inputs[<span class="s">"Scale"</span>].default_value = noise_scale
tex.inputs[<span class="s">"Detail"</span>].default_value = <span class="n">8.0</span>
tex.inputs[<span class="s">"Roughness"</span>].default_value = <span class="n">0.55</span>
mix = nt.nodes.new(<span class="s">"ShaderNodeMix"</span>)
mix.data_type = <span class="s">"RGBA"</span>
mix.inputs[<span class="s">"A"</span>].default_value = color
mix.inputs[<span class="s">"B"</span>].default_value = wear
fac = mix.inputs.get(<span class="s">"Factor"</span>) <span class="k">or</span> mix.inputs.get(<span class="s">"Fac"</span>)
nt.links.new(tex.outputs[<span class="s">"Fac"</span>], fac)
nt.links.new(mix.outputs[<span class="s">"Result"</span>], bsdf.inputs[<span class="s">"Base Color"</span>])
rmix = nt.nodes.new(<span class="s">"ShaderNodeMix"</span>)
rmix.data_type = <span class="s">"FLOAT"</span>
rmix.inputs[<span class="s">"A"</span>].default_value = roughness
rmix.inputs[<span class="s">"B"</span>].default_value = min(<span class="n">1.0</span>, roughness + <span class="n">0.18</span>)
rfac = rmix.inputs.get(<span class="s">"Factor"</span>) <span class="k">or</span> rmix.inputs.get(<span class="s">"Fac"</span>)
nt.links.new(tex.outputs[<span class="s">"Fac"</span>], rfac)
nt.links.new(rmix.outputs[<span class="s">"Result"</span>], bsdf.inputs[<span class="s">"Roughness"</span>])
<span class="k">return</span> mat
<span class="k">def</span> assign_slots(obj, wood, metal):
mats = obj.data.materials
wanted = (wood, metal)
<span class="k">for</span> i, mat <span class="k">in</span> enumerate(wanted):
<span class="k">if</span> i < len(mats):
mats[i] = mat
<span class="k">else</span>:
mats.append(mat)
<span class="k">def</span> world_bbox(obj):
corners = [obj.matrix_world @ Vector(c) <span class="k">for</span> c <span class="k">in</span> obj.bound_box]
xs = [c.x <span class="k">for</span> c <span class="k">in</span> corners]
ys = [c.y <span class="k">for</span> c <span class="k">in</span> corners]
zs = [c.z <span class="k">for</span> c <span class="k">in</span> corners]
<span class="k">return</span> (min(xs), min(ys), min(zs), max(xs), max(ys), max(zs))
<span class="k">def</span> uv_stats(mesh):
uv = mesh.uv_layers.active
<span class="k">if</span> uv <span class="k">is</span> <span class="k">None</span>:
<span class="k">return</span> <span class="n">0.0</span>, <span class="n">0.0</span>, <span class="n">1.0</span>, <span class="n">1.0</span>, <span class="n">0</span>, <span class="n">1.0</span>
data = uv.data
us = [loop.uv[<span class="n">0</span>] <span class="k">for</span> loop <span class="k">in</span> data]
vs = [loop.uv[<span class="n">1</span>] <span class="k">for</span> loop <span class="k">in</span> data]
aabbs = []
<span class="k">for</span> poly <span class="k">in</span> mesh.polygons:
pu = [data[i].uv[<span class="n">0</span>] <span class="k">for</span> i <span class="k">in</span> poly.loop_indices]
pv = [data[i].uv[<span class="n">1</span>] <span class="k">for</span> i <span class="k">in</span> poly.loop_indices]
aabbs.append((min(pu), min(pv), max(pu), max(pv)))
overlap = <span class="n">0.0</span>
<span class="k">for</span> i <span class="k">in</span> range(len(aabbs)):
a = aabbs[i]
<span class="k">for</span> j <span class="k">in</span> range(i + <span class="n">1</span>, len(aabbs)):
b = aabbs[j]
x0 = max(a[<span class="n">0</span>], b[<span class="n">0</span>])
y0 = max(a[<span class="n">1</span>], b[<span class="n">1</span>])
x1 = min(a[<span class="n">2</span>], b[<span class="n">2</span>])
y1 = min(a[<span class="n">3</span>], b[<span class="n">3</span>])
overlap += max(<span class="n">0.0</span>, x1 - x0) * max(<span class="n">0.0</span>, y1 - y0)
<span class="k">return</span> min(us), min(vs), max(us), max(vs), overlap, len(aabbs)
<span class="k">def</span> face_area(me, poly):
vs = [me.vertices[i].co <span class="k">for</span> i <span class="k">in</span> poly.vertices]
<span class="k">if</span> len(vs) < <span class="n">3</span>:
<span class="k">return</span> <span class="n">0.0</span>
v0 = vs[<span class="n">0</span>]
area = <span class="n">0.0</span>
<span class="k">for</span> i <span class="k">in</span> range(<span class="n">1</span>, len(vs) - <span class="n">1</span>):
area += (vs[i] - v0).cross(vs[i + <span class="n">1</span>] - v0).length * <span class="n">0.5</span>
<span class="k">return</span> area
<span class="k">def</span> hygiene_audit(me):
<span class="c"># Combinatorics match examples/mesh-hygiene-audit.audit (copied, not imported).</span>
nv, ne, nf = len(me.vertices), len(me.edges), len(me.polygons)
ngons = sum(<span class="n">1</span> <span class="k">for</span> p <span class="k">in</span> me.polygons <span class="k">if</span> len(p.vertices) > <span class="n">4</span>)
areas = [face_area(me, p) <span class="k">for</span> p <span class="k">in</span> me.polygons]
zero_area = sum(<span class="n">1</span> <span class="k">for</span> a <span class="k">in</span> areas <span class="k">if</span> a <= AREA_EPS)
bm = bmesh.new()
<span class="k">try</span>:
bm.from_mesh(me)
bm.verts.ensure_lookup_table()
bm.edges.ensure_lookup_table()
loose_v = sum(<span class="n">1</span> <span class="k">for</span> v <span class="k">in</span> bm.verts <span class="k">if</span> len(v.link_edges) == <span class="n">0</span>)
loose_e = sum(<span class="n">1</span> <span class="k">for</span> e <span class="k">in</span> bm.edges <span class="k">if</span> len(e.link_faces) == <span class="n">0</span>)
nonman = sum(<span class="n">1</span> <span class="k">for</span> e <span class="k">in</span> bm.edges <span class="k">if</span> <span class="k">not</span> e.is_manifold)
ret = bmesh.ops.find_doubles(bm, verts=list(bm.verts), dist=DOUBLES_EPS)
doubles = len(ret.get(<span class="s">"targetmap"</span>) <span class="k">or</span> {})
<span class="k">finally</span>:
bm.free()
<span class="k">return</span> {
<span class="s">"nv"</span>: nv,
<span class="s">"ne"</span>: ne,
<span class="s">"nf"</span>: nf,
<span class="s">"ngons"</span>: ngons,
<span class="s">"loose_v"</span>: loose_v,
<span class="s">"loose_e"</span>: loose_e,
<span class="s">"nonman"</span>: nonman,
<span class="s">"zero_area"</span>: zero_area,
<span class="s">"doubles"</span>: doubles,
<span class="s">"euler"</span>: nv - ne + nf,
}
<span class="k">def</span> shell_groups(me):
<span class="s">"""Vertex-index shells by edge connectivity (union-find), biggest first."""</span>
parent = list(range(len(me.vertices)))
<span class="k">def</span> find(a):
<span class="k">while</span> parent[a] != a:
parent[a] = parent[parent[a]]
a = parent[a]
<span class="k">return</span> a
<span class="k">for</span> e <span class="k">in</span> me.edges:
ra, rb = find(int(e.vertices[<span class="n">0</span>])), find(int(e.vertices[<span class="n">1</span>]))
<span class="k">if</span> ra != rb:
parent[rb] = ra
groups = {}
<span class="k">for</span> i <span class="k">in</span> range(len(me.vertices)):
groups.setdefault(find(i), []).append(i)
<span class="k">return</span> sorted(groups.values(), key=<span class="k">lambda</span> g: -len(g))
<span class="k">def</span> shell_box(me, idxs):
co = [me.vertices[i].co <span class="k">for</span> i <span class="k">in</span> idxs]
<span class="k">return</span> {
<span class="s">"xmin"</span>: min(c.x <span class="k">for</span> c <span class="k">in</span> co), <span class="s">"xmax"</span>: max(c.x <span class="k">for</span> c <span class="k">in</span> co),
<span class="s">"ymin"</span>: min(c.y <span class="k">for</span> c <span class="k">in</span> co), <span class="s">"ymax"</span>: max(c.y <span class="k">for</span> c <span class="k">in</span> co),
<span class="s">"zmin"</span>: min(c.z <span class="k">for</span> c <span class="k">in</span> co), <span class="s">"zmax"</span>: max(c.z <span class="k">for</span> c <span class="k">in</span> co),
}
<span class="k">def</span> coplanar_zfight_pairs(me, groups):
<span class="s">"""Coplanar face pairs from *different shells* — the z-fighting budget.
Cross-shell, not merely share-no-vertex: two quads two steps apart on
one flat cap share no vertex and are coplanar by construction, and
counting those makes the budget unsatisfiable rather than meaningful.
Z-fighting is two separate bodies landing on one plane, which is
exactly a cross-shell pair. Combinatorics and constants copied from
showcase/hay-bale (do not import across pieces).
"""</span>
owner = {}
<span class="k">for</span> si, comp <span class="k">in</span> enumerate(groups):
<span class="k">for</span> vi <span class="k">in</span> comp:
owner[vi] = si
faces = [(p.normal.copy(), p.center.copy(), owner.get(p.vertices[<span class="n">0</span>], -<span class="n">1</span>))
<span class="k">for</span> p <span class="k">in</span> me.polygons]
hits = <span class="n">0</span>
<span class="k">for</span> i <span class="k">in</span> range(len(faces)):
ni, ci, si = faces[i]
<span class="k">for</span> j <span class="k">in</span> range(i + <span class="n">1</span>, len(faces)):
nj, cj, sj = faces[j]