-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathstage.html
More file actions
3157 lines (3061 loc) · 154 KB
/
Copy pathstage.html
File metadata and controls
3157 lines (3061 loc) · 154 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>
<!--
barehands: move things on your screen with your bare hands.
Copyright (C) 2026 Jared Rhodenizer
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL-3.0-or-later
-->
<html>
<head>
<meta charset="utf-8">
<title>barehands</title>
<style>
html, body { margin:0; padding:0; width:100%; height:100%; overflow:hidden;
background:#000; font-family:-apple-system,"SF Pro Display",sans-serif; }
body.overlay { background:transparent; }
body.keybg { /* background color set by JS from ?key= (default magenta) */ }
/* green-key fallback: the UI can't be green on a green key (learned live
2026-08-07 — the cursor got keyed out of existence). Cyan takes over. */
body.ui-cyan .cursor { border-color:rgba(0,229,255,0.9); background:rgba(0,229,255,0.12); }
body.ui-cyan .cursor.pinched { background:rgba(0,229,255,0.85); box-shadow:0 0 18px rgba(0,229,255,0.8); }
body.ui-cyan .cursor .dwell { background:conic-gradient(#00e5ff calc(var(--p)*360deg), transparent 0); }
body.ui-cyan .card, body.ui-cyan .panel { border-color:rgba(0,229,255,0.5); }
body.ui-cyan .card h3, body.ui-cyan .panel .bar h3, body.ui-cyan .panel .close
{ color:#00e5ff; border-color:rgba(0,229,255,0.6); }
body.ui-cyan .scroll .h { color:#00e5ff; }
#toast { position:absolute; top:14px; right:14px; z-index:998; display:none;
background:rgba(0,0,0,0.7); color:#8ff0e4; padding:8px 14px;
border-radius:8px; font:13px "SF Mono",Menlo,monospace; }
/* the squeeze-hold charge glow, visible on the TRACKER too (the render
page has its own on-air rule): pinch + hold still = charge = open/close */
.card, .panel { --ch:0; }
body:not(.on-air) .card.grabbed, body:not(.on-air) .panel.grabbed {
box-shadow:0 12px 60px rgba(0,0,0,0.7),
0 0 calc(44px + var(--ch)*70px) rgba(111,229,214,calc(0.35 + var(--ch)*0.55)); }
/* THE PRESENT spotlight: one item center stage, the rest step back */
.dimmed { opacity:0.22 !important; filter:saturate(0.35);
transition:opacity 0.35s, filter 0.35s; }
.presented { box-shadow:0 16px 70px rgba(0,0,0,0.65),
0 0 70px rgba(111,229,214,0.45); }
/* ON-AIR (the OBS render page): backdrop-blur has nothing to sample
in the compositor. GLASS ERA: the near-solid slabs died (Jared's
8/13 call — "frankly more transparent") — true translucent glass,
readability carried by the halo text-shadows below. */
body.on-air .panel { background:linear-gradient(160deg, rgba(58,116,108,0.42), rgba(16,44,40,0.34)); backdrop-filter:none; }
body.on-air .card { background:linear-gradient(160deg, rgba(60,120,112,0.38), rgba(18,48,44,0.30)); backdrop-filter:none; }
body.on-air .card p, body.on-air .panel .scroll {
text-shadow:0 1px 3px rgba(2,14,12,0.95), 0 0 10px rgba(2,14,12,0.85); }
body.on-air .card h3, body.on-air .panel .bar h3 {
text-shadow:0 1px 3px rgba(2,14,12,0.95), 0 0 14px rgba(111,229,214,0.55); }
/* the dwell CHARGE glow — the card announces it's about to open (the
audience's cue once the cursor rings are hidden) */
body.on-air .card, body.on-air .panel { --ch:0;
box-shadow:0 8px 40px rgba(0,0,0,0.55),
0 0 calc(24px + var(--ch)*70px) rgba(111,229,214,calc(0.10 + var(--ch)*0.75)),
inset 0 1px 0 rgba(191,255,245,0.35); }
#cam { position:absolute; inset:0; width:100%; height:100%; object-fit:cover;
transform:scaleX(-1); }
body.overlay #cam, body.keybg #cam {
width:2px; height:2px; opacity:0.01; pointer-events:none; }
/* THE GLASS ERA (2026-08-13, Jared's redesign): clean CLEAR glass —
low-alpha smoked fills you genuinely see through, one luminous
edge, a specular kiss on top. No wireframe chrome; restraint IS
the aesthetic. Readability rides halo text, not slab fills. */
.card { position:absolute; width:480px; padding:22px 24px; border-radius:16px;
background:linear-gradient(168deg, rgba(70,140,130,0.30), rgba(18,48,44,0.18));
border:1.5px solid rgba(140,240,225,0.55);
box-shadow:0 10px 44px rgba(0,0,0,0.40), 0 0 26px rgba(111,229,214,0.14),
inset 0 1px 0 rgba(210,255,248,0.55),
inset 0 -14px 30px rgba(111,229,214,0.05);
color:#ecfffa; user-select:none; will-change:transform;
transform-origin:center center; }
body.keybg .card, body.keybg .panel { backdrop-filter:none;
background:rgba(30,70,64,0.97); }
.card h3 { margin:0 0 8px; font-size:19px; letter-spacing:0.08em; color:#8ff0e4;
font-family:"SF Mono",Menlo,monospace; text-transform:uppercase; }
/* THE RING (naked canvas, the modelcard pattern) + THE ORBITAL
BLOOM orbs: the ring is the hub — tap it and your configured
folders bloom around it as glass orbs. */
.card.ringcard { width:440px; padding:0; background:transparent;
border:none; box-shadow:none; backdrop-filter:none; }
.card.ringcard canvas { display:block; width:440px; height:440px;
pointer-events:none; }
body:not(.on-air) .card.ringcard, .card.ringcard.grabbed,
body.on-air .card.ringcard {
box-shadow:none; border:none; background:transparent; }
.card.ringcard.grabbed canvas {
filter:brightness(calc(1.12 + var(--ch,0)*0.3)); }
body.on-air .card.ringcard.grabbed canvas { filter:none; }
.card.orb { width:150px; height:150px; border-radius:50%; padding:0;
display:flex; flex-direction:column; align-items:center;
justify-content:center; text-align:center; gap:2px; }
.card.orb h3 { margin:0; font-size:16px; }
.card.orb p { font-size:11.5px; color:#a8d8cf; margin:0; }
.card.imgcard { padding:6px; width:auto; overflow:hidden;
border-color:rgba(111,229,214,0.5);
box-shadow:0 8px 40px rgba(0,0,0,0.55), 0 0 30px rgba(111,229,214,0.20),
inset 0 1px 0 rgba(191,255,245,0.35); }
.card.imgcard img { display:block; max-width:32vw; max-height:44vh;
border-radius:10px; pointer-events:none; }
/* MATERIALIZE-AS-LIGHT (Jared's call 8/9): images ARRIVE as hologram
— teal monochrome light + one scan sweep — then resolve to their
TRUE colors. Theater at the edges, truth in the content (evidence
stays evidence; the folder law's spirit for pixels). */
.card.imgcard img, .card.imgcard video { transition:filter 0.5s ease-out; }
.card.imgcard.mat img, .card.imgcard.mat video {
filter:brightness(1.55) saturate(0.2) sepia(1) hue-rotate(115deg)
saturate(2.4) drop-shadow(0 0 22px rgba(111,229,214,0.85)); }
.card.imgcard.mat::after { content:""; position:absolute; left:0; right:0;
height:16%; top:-20%; background:linear-gradient(180deg, transparent,
rgba(191,255,245,0.75), transparent);
animation:matscan 0.6s linear; pointer-events:none; }
@keyframes matscan { from { top:-20%; } to { top:110%; } }
/* THE FX LAYER (2026-08-08, Jared's idea: "throw me a fireball") —
anything in media/fx/ (or any .webm) renders NAKED: no chip, no
border, no shadow — a floating OBJECT with full physics. Alpha
PNGs float; alpha WebMs loop silently. */
.card.fxcard { padding:0; background:transparent; border:none;
box-shadow:none; backdrop-filter:none; }
.card.fxcard img, .card.fxcard video { display:block; max-width:36vw;
max-height:52vh; border-radius:0; pointer-events:none; }
/* kill EVERY rectangular glow layer on fx, both pages — the tracker's
grab-glow and the render's always-on air-glow both paint box-shadows
at higher specificity than the base fx class (the fireball's green
halo+frame bug, Jared's catch 8/8). The object's own alpha
silhouette carries the grab cue via drop-shadow instead. */
body:not(.on-air) .card.fxcard, body:not(.on-air) .card.fxcard.grabbed,
body.on-air .card.fxcard, .card.fxcard.grabbed {
box-shadow:none; border:none; background:transparent; }
/* grab cue: the object FLARES in the hand (brightness+saturation) —
drop-shadow was the "green shadow behind it" bug: generated flames
carry a wide semi-alpha haze and the shadow glows through all of it.
On-air: no cue at all — bare-hands invisible magic. */
.card.fxcard.grabbed,
body:not(.on-air) .card.fxcard.grabbed {
filter:brightness(1.18) saturate(1.2); }
body.on-air .card.fxcard.grabbed { filter:none; }
/* BUILD 1 — 3D HOLOGRAMS (2026-08-09, gestures at 1.4): a model
renders NAKED like fx — transparent WebGL canvas, ZERO chrome (the
1.1 handle-bar zone died to the no-small-targets law; the base bar
killed at 1.3, Jared's call). Pinch = move; hold-still latches
spin — the charge cue is the MODEL brightening via --ch; two hands
= carry + twist-roll + scale (the 1.3 gimbal was rejected, one
round). Folder = render law: holo/ = blue wire, else solid. Fixed
480px both pages (the v20.4 law: identical geometry = 1:1). */
.card.modelcard { padding:0; background:transparent; border:none;
box-shadow:none; backdrop-filter:none; width:480px; }
.card.modelcard canvas { display:block; width:480px; height:480px;
pointer-events:none; }
/* (the v1 holo CSS drop-shadow retired at 2.0 — the ghost-glass
shader + its bloom rig carry the glow now) */
body:not(.on-air) .card.modelcard, body:not(.on-air) .card.modelcard.grabbed,
body.on-air .card.modelcard, .card.modelcard.grabbed {
box-shadow:none; border:none; background:transparent; }
.card.modelcard.grabbed canvas {
filter:brightness(calc(1.18 + var(--ch,0)*0.4)) saturate(1.15); }
/* ON-AIR: no grab/charge cue on models — the fx precedent (bare-hands
invisible magic; the tracker stays Jared's confidence monitor). */
body.on-air .card.modelcard.grabbed canvas { filter:none; }
/* THE BROWSER PANES: tap an orb = a tall glass pane with an
indented file tree; folders unfold IN PLACE; rows are fat tap
zones. */
.panel.browser { width:560px; height:720px; }
.brow { display:flex; align-items:center; gap:12px; min-height:68px;
border-bottom:1px solid rgba(111,229,214,0.12); font-size:18px; }
.brow .bico { color:#8ff0e4; width:28px; text-align:center; flex:none;
font-size:20px; }
.brow.dir .btxt { color:#8ff0e4; font-weight:600; letter-spacing:0.02em; }
.brow.note .btxt, .brow.prop .btxt, .brow.widget .btxt { color:#ecfffa; }
.brow .btxt { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
/* THE TAP FLASH (2026-08-13, the mirror-doctrine softener): the row
you tap pulses full-width on BOTH pages. Rows span the pane and
vertical never mirrors, so the pulse sits directly under the
on-air fingertip even though horizontal touch offsets flip
(the mirror doctrine). Also plain good feedback. */
.brow.flash { animation:rowflash 0.6s ease-out; }
@keyframes rowflash {
from { background:rgba(140,240,225,0.4); }
to { background:transparent; } }
.card p { margin:0; font-size:17px; line-height:1.45; color:#dcf5ee; text-shadow:0 1px 3px rgba(3,18,16,0.55); }
.card p:empty { display:none; }
.card.grabbed, .panel.grabbed { border-color:#8ff0e4;
box-shadow:0 12px 60px rgba(0,0,0,0.7), 0 0 44px rgba(111,229,214,0.35); }
/* v20.4: FIXED px (the 44vw×70vh of a 1920×1080 OBS canvas) so tracker
and render wrap text identically — same content height on both sides
makes the fractional scroll a true 1:1 (hand speed = on-air speed) */
.panel { position:absolute; width:845px; height:756px; border-radius:18px;
background:linear-gradient(172deg, rgba(52,108,100,0.36), rgba(14,40,36,0.24));
border:1.5px solid rgba(140,240,225,0.6); color:#ecfffa;
box-shadow:0 16px 70px rgba(0,0,0,0.5), 0 0 50px rgba(111,229,214,0.16),
inset 0 1px 0 rgba(210,255,248,0.55);
display:flex; flex-direction:column; will-change:transform; }
.panel .bar { padding:42px 16px; border-bottom:1px solid rgba(111,229,214,0.3); /* v3.8: THE GRIP BAR everywhere — notes + folders (grab = move, tap = close) */
display:flex; justify-content:space-between; align-items:center; }
.panel .bar h3 { margin:0; font-size:14px; color:#8ff0e4; letter-spacing:0.08em;
font-family:"SF Mono",Menlo,monospace; text-transform:uppercase; }
.panel .close { width:30px; height:30px; border-radius:50%; text-align:center;
line-height:28px; border:1.5px solid rgba(111,229,214,0.65);
color:#8ff0e4; font-size:15px; }
.panel .body { flex:1; overflow:hidden; padding:14px 20px; }
.panel .scroll { transition:none; font-size:14.5px; line-height:1.5; color:#dcf5ee; text-shadow:0 1px 3px rgba(3,18,16,0.55);
white-space:pre-wrap; font-family:-apple-system,sans-serif; }
.panel .scroll b { color:#fff; } .panel .scroll .h { color:#8ff0e4; font-weight:700; }
.cursor { position:absolute; width:28px; height:28px; margin:-14px 0 0 -14px;
border-radius:50%; border:2.5px solid rgba(111,229,214,0.9);
background:rgba(111,229,214,0.12); pointer-events:none; z-index:999; }
.cursor.pinched { background:rgba(111,229,214,0.85); transform:scale(0.62);
box-shadow:0 0 18px rgba(111,229,214,0.8); }
.cursor .dwell { position:absolute; inset:-7px; border-radius:50%;
background:conic-gradient(#8ff0e4 calc(var(--p)*360deg), transparent 0);
-webkit-mask:radial-gradient(circle, transparent 58%, black 60%);
opacity:0.95; }
#hint { position:absolute; bottom:14px; left:0; right:0; text-align:center;
color:rgba(230,255,240,0.7); font-size:13.5px; z-index:998;
text-shadow:0 1px 6px rgba(0,0,0,0.8); }
body.overlay #hint, body.greenkey #hint { display:none; }
#debug { position:absolute; top:12px; left:12px; z-index:998; display:none;
background:rgba(0,0,0,0.65); color:#8ff0e4; padding:10px 12px;
border-radius:8px; font:12px "SF Mono",Menlo,monospace; white-space:pre; }
/* GLASS ERA: the item layer is a real 3D SPACE — every card, panel,
and widget can rotate in Z (hold-latch); default pose is flat.
(The 8/11 depth-mask person-segmenter that masked this layer was
fully removed 2026-08-13 — the line was killed 8/11 but its
tracker half survived the baseline; Jared field-caught it.) */
#behind { position:fixed; inset:0; z-index:1; perspective:1200px; }
/* (an earlier whole-screen voice-pulse border was removed —
THE RING is the assistant's presence now.) */
#boot { position:absolute; inset:0; display:flex; align-items:center;
justify-content:center; color:#8ff0e4; text-align:center;
font:16px "SF Mono",Menlo,monospace; z-index:1000; background:#000;
flex-direction:column; gap:12px; }
</style>
<script type="importmap">
{ "imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/" } }
</script>
</head>
<body>
<!-- Opened by double-clicking the file instead of through the server? Everything
client-side still works (render, camera, gesture math), so the page LOOKS
alive, but every /orb /tree /note /state call dies silently: you can pinch
and rotate, and nothing will ever OPEN. Field-caught 2026-08-17 after a user
lost a day to it. Say so plainly instead of letting the next person chase
tap thresholds. -->
<script>
if (location.protocol === "file:") {
document.documentElement.innerHTML =
'<body style="margin:0;background:#04191c;color:#dff3ee;font:15px/1.65 ui-monospace,Menlo,monospace;' +
'display:flex;align-items:center;justify-content:center;height:100vh;padding:24px;text-align:left">' +
'<div style="max-width:620px">' +
'<div style="font-size:22px;letter-spacing:.18em;color:#6fe3c9;margin-bottom:18px">BAREHANDS NEEDS ITS SERVER</div>' +
'<p>You opened this file directly, so there is no server behind it. The camera and the gestures will still work, ' +
'but nothing will ever <b>open</b>: tapping a card asks the server for the file, and there is nothing to ask.</p>' +
'<p style="margin-top:16px">Start it from the barehands folder:</p>' +
'<pre style="background:#052227;border:1px solid #14484f;padding:12px 14px;border-radius:8px;color:#9ff0dd">' +
'python3 server.py <span style="color:#6b9c96"># Windows: python server.py</span></pre>' +
'<p style="margin-top:14px">Then open this in Chrome:</p>' +
'<pre style="background:#052227;border:1px solid #14484f;padding:12px 14px;border-radius:8px;color:#9ff0dd">' +
'http://127.0.0.1:8794/stage.html</pre>' +
'<p style="margin-top:18px;color:#7fb3ab">If you changed "port" in barehands.json, use that port instead.</p>' +
'</div></body>';
throw new Error("barehands: opened over file://, server required");
}
// First-run watchdog: the hand tracker and the 3D library arrive from CDNs,
// so with no internet the boot screen sits forever with no error. Say so.
setTimeout(function () {
var b = document.getElementById("boot");
if (b && b.isConnected) b.innerHTML +=
'<span style="color:#7fb3ab;font-size:12px">still loading? the first run downloads the hand tracker and needs internet once. TROUBLESHOOTING.md has more.</span>';
}, 12000);
</script>
<video id="cam" autoplay playsinline muted></video>
<div id="behind"></div>
<div id="boot">BAREHANDS<br><span style="color:#a8d8cf;font-size:12px;letter-spacing:0.22em">by jaredrhod</span><br><span style="color:#a8d8cf;font-size:13px">loading hand tracker… allow the camera when asked</span></div>
<div id="hint">tap the RING = orbs · tap an orb = its tree · TAP a card = open · pinch-drag = move · hold still ~1s = 3D rotate · two hands = scale · TAP an open item = close · CLAP (palms together, fingers up) = ring center-stage · CLAW: flash open, claw, aim, hold the strain 2s, SNAP = force pull · empty pinch dragged sideways = explode scrub · R respawn / C camera / D debug</div>
<div id="debug"></div>
<div id="toast"></div>
<script type="module">
import { HandLandmarker, FilesetResolver } from
"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.14/vision_bundle.mjs";
// modes: ?mode=mirror (default, self-view) | overlay (transparent — OBS
// browser sources can't open cameras reliably on macOS, kept for browsers
// that can) | key (solid key color for window-capture + chroma; ?key=
// magenta|green|blue|#hex, DEFAULT MAGENTA so the brand-green UI survives
// the key — keying green ate the cursor on the first OBS test, 2026-08-07).
// ?cam=<label substring> picks the tracking camera; C cycles cameras live.
const Q = new URLSearchParams(location.search);
// ?res=WxH — capture resolution (default 1920x1080, the tracking sweet
// spot: MediaPipe downscales every frame to its model input anyway, so
// higher res buys self-view sharpness, never accuracy — and costs fps
// on weak machines; 1280x720 is the low-end saver, 3840x2160 the 4K
// self-view). Capture res ≠ broadcast res: in an OBS rig the audience
// sees OBS's own camera source; this only shapes the tracker's sensor.
// ?portrait=1 — request the vertical capture instead of coercing the
// camera into landscape (a camera flipped to portrait negotiates its
// 9:16 mode). Composes with ?res=: portrait swaps the dimensions.
// Everything downstream is aspect-agnostic (fractions + cover-fit):
// shape the tracker WINDOW to match, 9:16 OBS canvas for the render.
const PORTRAIT = Q.get("portrait") === "1";
const RES = (() => {
const m = /^(\d{3,4})x(\d{3,4})$/i.exec(Q.get("res") || "");
return m ? [+m[1], +m[2]] : [1920, 1080];
})();
let MODE = Q.get("mode") || "mirror";
if (MODE === "greenkey") { MODE = "key"; Q.set("key", "green"); } // back-compat
if (MODE === "overlay") {
document.body.classList.add("overlay");
document.documentElement.style.background = "transparent";
document.body.style.background = "transparent";
}
if (MODE === "key") {
const KEYS = { magenta: "#ff00ff", green: "#00ff00", blue: "#0000ff" };
const want = (Q.get("key") || "magenta").toLowerCase();
const color = KEYS[want] || (want.startsWith("#") ? want : "#ff00ff");
document.body.classList.add("keybg");
document.body.style.background = color;
if (want === "green") document.body.classList.add("ui-cyan");
}
const cam = document.getElementById("cam");
const BEHIND = document.getElementById("behind");
const dbg = document.getElementById("debug");
let items = []; // cards + panels: {el,type,x,y,scale,vx,vy,grabbedBy:[],ox,oy,flying,file,stretch,scrollY,body}
let cursors = {};
let SAMPLER = null; // the pose sampler (dormant — claw/pinch tuning)
let CLAPSAMP = null; // the P clap recorder (v3.9.1)
let SAMPLED = ""; // its frozen last result (D overlay)
let landmarker = null, lastVideoTs = -1, frames = 0, fps = 0, lastFpsTs = performance.now();
let UID = 1;
function makeCard(def) {
const el = document.createElement("div");
el.className = "card";
el.innerHTML = `<h3>${escT(def.title)}</h3><p>${escT(def.body || "")}</p>`;
BEHIND.appendChild(el);
return { el, id: UID++, type: "card", def, x: 0, y: 0, scale: 1, vx: 0, vy: 0,
grabbedBy: [], ox: 0, oy: 0, flying: false, stretch: null };
}
// ---- FOLEY (2026-08-07): synthesized WebAudio — the objects make SOUND,
// which is what makes invisible cards feel physical. Plays from the
// TRACKER page through Mac audio, captured by the existing stream rig.
// Chrome arms audio on the first user gesture (any key/click).
// foley ships OFF by default (a field call: the sounds read as noise
// on camera). The engine stays; &sound=1 turns it on.
const SOUND = Q.get("sound") === "1";
let AC = null;
function _ac() {
if (!AC) { try { AC = new (window.AudioContext || webkitAudioContext)(); } catch (e) {} }
if (AC && AC.state === "suspended") AC.resume().catch(() => {});
return AC;
}
addEventListener("keydown", _ac); addEventListener("click", _ac);
function _noise(dur, fLo, fHi, gain, sweepTo) {
if (!SOUND) return;
const ac = _ac(); if (!ac || ac.state !== "running") return;
const n = ac.sampleRate * dur, buf = ac.createBuffer(1, n, ac.sampleRate);
const d = buf.getChannelData(0);
for (let i = 0; i < n; i++) d[i] = Math.random() * 2 - 1;
const src = ac.createBufferSource(); src.buffer = buf;
const bp = ac.createBiquadFilter(); bp.type = "bandpass";
bp.frequency.setValueAtTime((fLo + fHi) / 2, ac.currentTime);
if (sweepTo) bp.frequency.exponentialRampToValueAtTime(sweepTo, ac.currentTime + dur);
const g = ac.createGain();
g.gain.setValueAtTime(gain, ac.currentTime);
g.gain.exponentialRampToValueAtTime(0.001, ac.currentTime + dur);
src.connect(bp); bp.connect(g); g.connect(ac.destination);
src.start(); src.stop(ac.currentTime + dur);
}
function _tone(freq, dur, gain = 0.08, type = "sine", sweepTo = 0, delay = 0) {
if (!SOUND) return;
const ac = _ac(); if (!ac || ac.state !== "running") return;
const t0 = ac.currentTime + delay;
const o = ac.createOscillator(); o.type = type;
o.frequency.setValueAtTime(freq, t0);
if (sweepTo) o.frequency.exponentialRampToValueAtTime(sweepTo, t0 + dur);
const g = ac.createGain();
g.gain.setValueAtTime(gain, t0);
g.gain.exponentialRampToValueAtTime(0.001, t0 + dur);
o.connect(g); g.connect(ac.destination);
o.start(t0); o.stop(t0 + dur);
}
const foley = {
grab: () => { _noise(0.04, 900, 2200, 0.10); _tone(150, 0.06, 0.10); },
place: () => _tone(120, 0.06, 0.07),
throw_: () => _noise(0.22, 300, 900, 0.14, 1600),
void_: () => { _noise(0.25, 500, 1400, 0.12, 180); _tone(280, 0.28, 0.09, "square", 70); },
arrive: () => { _tone(523, 0.10, 0.06); _tone(659, 0.10, 0.06, "sine", 0, 0.07); _tone(784, 0.14, 0.07, "sine", 0, 0.14); },
yank: () => { _tone(220, 0.12, 0.10, "sawtooth", 900); _noise(0.06, 1200, 3000, 0.08); },
};
function makeImage(src, title) {
// THE FX LAYER: media/fx/ = naked render (no card chrome); .webm =
// silent looping alpha video. Both stay type "img" so every gesture —
// grab, stretch, fling, give-back, flash-close — works unchanged.
const fx = /\/fx\//i.test(src);
const vid = /\.webm(\?|$)/i.test(src);
const el = document.createElement("div");
el.className = "card imgcard" + (fx || vid ? " fxcard" : "");
el.innerHTML = vid
? `<video src="${escT(src)}" autoplay loop muted playsinline></video>`
: `<img src="${escT(src)}" alt="">`;
BEHIND.appendChild(el);
el.classList.add("mat"); // arrives as light...
setTimeout(() => el.classList.remove("mat"), 650); // ...resolves true
return { el, id: UID++, type: "img",
def: { title: title || "", file: "", src,
fx: fx || vid ? 1 : 0, vid: vid ? 1 : 0 },
x: innerWidth * 0.5, y: innerHeight * 0.42, scale: 1, vx: 0, vy: 0,
grabbedBy: [], ox: 0, oy: 0, flying: false, stretch: null };
}
function summonWidget(w) {
// the assistant ring is the only built-in widget
if (w && w !== "ring") return null;
const ex = items.find(i => i.type === "widget" && i.def.w === "ring");
if (ex) { ex.anim = { k: "hover", t: 0 }; return ex; }
return makeRing();
}
// ---- THE RING — the assistant's presence as a grabbable power-core
// ring: concentric glass rings, tick ring, wordmark core. BOTH pages
// animate it LOCALLY from /orb (the assistant's state files) on
// wall-clock phases — tracker and overlay pulse as one; only
// position/scale/rotation travel the bus. States: idle breath ·
// listening (deep blue, pulses draw INWARD — blue = the human
// talking) · thinking (radar sweep) · speaking (the live waveform
// drives glow/thickness/core through an auto-gain). Moods tint the
// whole ring red/amber.
const RING = {
data: { state: "idle", mood: "green", wave: null }, amp: 0, gmax: 1,
live: 0,
// palette eyedropped from the design reference (exact reference
// colors, SUBTLE state shifts — a deep-blue listening state was
// unreadable and died)
COLS: { idle: [140, 235, 240], listening: [120, 205, 250],
thinking: [170, 245, 250], speaking: [140, 235, 240] },
MOODT: { red: [255, 82, 82], amber: [255, 179, 71], green: null },
};
setInterval(async () => {
if (!RING.live) return; // poll only while a ring is up
try {
const r = await fetch("/orb", { cache: "no-store" });
if (r.ok) RING.data = await r.json();
} catch (e) {}
}, 120);
function ringAmp() {
// the preserved aura pulse math: RMS+peak blend, auto-gain against a
// rolling ceiling, contrast-expanded, fast attack / musical decay
const d = RING.data;
let target = 0;
if (d.state === "speaking" && d.wave && d.wave.length) {
let s = 0, pk = 0;
for (const v of d.wave) { s += v * v; pk = Math.max(pk, Math.abs(v)); }
const raw = 0.6 * Math.sqrt(s / d.wave.length) + 0.4 * pk;
RING.gmax = Math.max(raw, (RING.gmax || 1) * 0.995);
target = Math.pow(Math.min(1, raw / Math.max(3, RING.gmax)), 2.2);
}
RING.amp += (target - RING.amp) * (target > RING.amp ? 0.6 : 0.2);
return RING.amp;
}
const RINGS = new Map(); // this page's ring canvases: item id -> sc
function ringCanvas(el) {
const canvas = el.querySelector("canvas");
const RES = Math.min(devicePixelRatio || 1, 2);
canvas.width = 440 * RES; canvas.height = 440 * RES;
return { canvas, ctx: canvas.getContext("2d"), RES, tapT: 0 };
}
function makeRing() {
const el = document.createElement("div");
el.className = "card ringcard";
el.innerHTML = `<canvas></canvas>`;
BEHIND.appendChild(el);
const it = { el, id: UID++, type: "widget",
def: { title: (CFG.name || "Ring"), file: "", w: "ring" },
x: innerWidth * 0.30, y: innerHeight * 0.45, scale: 1,
vx: 0, vy: 0, grabbedBy: [], ox: 0, oy: 0, flying: false, stretch: null };
it.anim = { k: "in", t: 0 }; it.el.style.opacity = "0.05";
RINGS.set(it.id, ringCanvas(el));
items.push(it);
return it;
}
function ensureRingRes(sc) {
// the models' adaptive-resolution law, for the ring (round 4, Jared's
// pixelation catch on stretch): re-rez on settle only — never mid-
// grip — 25% hysteresis, 2048 cap, never below the 440 base
if (sc.held) return;
const want = Math.round(Math.min(2048, Math.max(440,
440 * (devicePixelRatio || 1) * SS * (sc.scale || 1))));
if (Math.abs(want - sc.canvas.width) / (sc.canvas.width || 1) < 0.25) return;
sc.canvas.width = want; sc.canvas.height = want;
sc.RES = want / 440;
}
function drawRing(sc) {
// NO spin — the ring is still; ONE solid thick band + solid hot
// rim; SPEAKING = the band pulses HOT WHITE on the live voice.
// Core is CLEAR glass, wordmark + status sized to fill it.
const d = RING.data, st = d.state || "idle";
const amp = st === "speaking" ? ringAmp() : (RING.amp *= 0.9);
const t = Date.now() / 1000; // wall clock: pages in sync
const base = RING.COLS[st] || RING.COLS.idle;
const tint = RING.MOODT[d.mood];
const c = tint ? base.map((v, i) => Math.round(v * 0.35 + tint[i] * 0.65))
: base;
// v4: SPEAKING = the band burns toward HOT WHITE on the live voice
const wp = st === "speaking" ? amp : 0;
const bc = c.map((v, i) => Math.round(v + ([235, 250, 252][i] - v) * wp));
const col = a => `rgba(${c[0]},${c[1]},${c[2]},${a})`;
const band = a => `rgba(${bc[0]},${bc[1]},${bc[2]},${a})`;
const hot = a => `rgba(228,250,252,${a})`; // the white-hot rim
const x = sc.ctx;
ensureRingRes(sc); // the pixelation fix (round 4)
const tap = Math.exp(-Math.max(0, t - sc.tapT) * 4);
const breath = 0.9 + 0.1 * Math.sin(t * 1.4);
const glow = (10 + wp * 34 + tap * 14) * breath;
x.setTransform(sc.RES, 0, 0, sc.RES, 0, 0);
x.clearRect(0, 0, 440, 440);
x.save();
x.translate(220, 220);
x.shadowColor = band(0.95);
// THE BAND — ONE solid piece, perfectly still — it PULSES HOT
// WHITE while the assistant speaks, riding the live waveform
x.shadowBlur = glow + 8;
x.strokeStyle = band(0.92);
x.lineWidth = 20 + wp * 3;
x.beginPath(); x.arc(0, 0, 178, 0, 7); x.stroke();
// solid hot rim + inner thin ring
x.shadowBlur = 6 + wp * 14;
x.strokeStyle = hot(0.85); x.lineWidth = 2.5;
x.beginPath(); x.arc(0, 0, 191, 0, 7); x.stroke();
x.shadowBlur = 6;
x.strokeStyle = col(0.5); x.lineWidth = 1.5;
x.beginPath(); x.arc(0, 0, 165, 0, 7); x.stroke();
// tick ring (static chrome)
x.shadowBlur = 0;
for (let i = 0; i < 48; i++) {
const a = i / 48 * Math.PI * 2;
const big = i % 4 === 0;
x.strokeStyle = col(big ? 0.6 : 0.3);
x.lineWidth = big ? 2 : 1.2;
x.beginPath();
x.moveTo(Math.cos(a) * (big ? 148 : 152), Math.sin(a) * (big ? 148 : 152));
x.lineTo(Math.cos(a) * 158, Math.sin(a) * 158);
x.stroke();
}
// state FX in the band between ticks and core
if (st === "listening") { // pulses draw INWARD: receiving
for (let k = 0; k < 3; k++) {
const p = (t * 0.7 + k / 3) % 1;
x.globalAlpha = (1 - p) * p * 1.8;
x.strokeStyle = col(0.9); x.lineWidth = 2;
x.beginPath(); x.arc(0, 0, 158 - p * 60, 0, 7); x.stroke();
}
x.globalAlpha = 1;
} else if (st === "thinking") { // radar sweep with a fading tail
const a0 = t * 2.8;
for (let i = 0; i < 7; i++) {
x.globalAlpha = 0.55 * (1 - i / 7);
x.strokeStyle = col(0.95); x.lineWidth = 10; x.shadowBlur = 12;
x.beginPath();
x.arc(0, 0, 148, a0 - (i + 1) * 0.11, a0 - i * 0.11); x.stroke();
}
x.globalAlpha = 1; x.shadowBlur = 0;
}
// THE CORE — CLEAR glass (round 4: the dark overlay died) — just the
// rims; the video breathes through the center
x.shadowBlur = glow;
x.strokeStyle = col(0.9); x.lineWidth = 2.5 + wp * 2;
x.beginPath(); x.arc(0, 0, 128, 0, 7); x.stroke();
x.shadowBlur = 0;
x.strokeStyle = col(0.3); x.lineWidth = 1;
x.beginPath(); x.arc(0, 0, 119, 0, 7); x.stroke();
// wordmark + status — sized UP (round 4: the clear core has room);
// dark halo shadow keeps them readable over live video
x.shadowColor = "rgba(2,10,10,0.9)"; x.shadowBlur = 7;
x.fillStyle = `rgba(235,250,250,${0.94 + wp * 0.06})`;
const nm = (CFG.name || "ASSISTANT").toUpperCase();
const fpx = nm.length <= 6 ? 27 : nm.length <= 9 ? 20 : 14;
x.font = `700 ${fpx}px 'SF Mono', Menlo, monospace`;
x.textAlign = "center"; x.textBaseline = "middle";
x.fillText(nm.split("").join(".") + ".", 0, -12);
x.globalAlpha = 0.85;
x.fillStyle = col(0.98);
x.font = "600 14px 'SF Mono', Menlo, monospace";
const status = { idle: "ACTIVE", listening: "LISTENING",
thinking: "THINKING", speaking: "SPEAKING" }[st];
x.fillText((status || "ACTIVE").split("").join(" "), 0, 28);
x.shadowBlur = 0; x.globalAlpha = 1;
x.restore();
}
function renderRings() {
RINGS.forEach((sc, id) => {
if (!sc.canvas.isConnected) { RINGS.delete(id); return; }
// feed scale + grip for the adaptive re-rez (tracker side; the
// render page feeds these from the bus in renderLoop)
const holder = items.find(k => k.id === id);
if (holder) { sc.scale = holder.scale;
sc.held = holder.grabbedBy.length > 0; }
drawRing(sc);
});
RING.live = RINGS.size;
}
// ---- 3D HOLOGRAMS —
// GLB/glTF models as first-class board objects. three.js arrives by
// dynamic import on the FIRST model staged (the import map in <head>
// resolves the bare specifiers), so the page still boots offline and
// the render page only pays the cost if a model actually appears.
// Modes: "holo" (hologram-blue emissive wireframe) and
// "solid" (real textures); a filename like ...-solid.glb forces solid,
// a {"mode":"solid"} param on the command overrides either way.
const MODEL_PX = 480;
const MSCENES = new Map(); // tracker: item id -> live three.js bundle
let _three = null;
function isModelSrc(s) { return /\.(glb|gltf)(\?|$)/i.test(s || ""); }
function modelModeFor(src, want) {
// Build 1.4 (Jared's design): the FOLDER is the render law, exactly
// like fx/ — anything in holo/ renders as the blue wire (reserved
// for 3D sketches/layouts); everything else renders REAL (solid).
// The command param still overrides for one-off forces.
if (want === "solid" || want === "holo") return want;
return /\/holo\//i.test(src || "") ? "holo" : "solid";
}
function liftTranslucentArt(obj, THREE, want) {
// THE GLOW LIFT: translucent-art models are authored as
// low-opacity veils for OPAQUE viewer backdrops (one veil-art
// test case: a single material at 16.5% alpha, 14 stacked
// shells); over live video a veil reads as
// nothing. Lift: opacity ~3x + the model's own color texture fed
// back as self-illumination so it carries its own light. Auto for
// any transparent material under 0.5 opacity; {"lift":0} disables,
// {"lift":1} forces every transparent material. Opaque models and
// deliberately-hidden helper materials (opacity ~0) are untouched.
if (want === 0) return 0;
// THE GLASS-WINDOW VERDICT (a real-car-model catch — the car
// rendered as a white ghost with an outer glow): veil-ART is
// MOSTLY translucent (veil art: every shell transparent); a REAL
// model with a few glass parts is not. One windshield used to drag
// the whole car through the art bloom. Now: unless lift is FORCED,
// auto-lift only fires when most of the model's materials are
// translucent candidates.
if (want !== 1) {
let cand = 0, total = 0;
const pre = new Set();
obj.traverse(n => {
if (!n.isMesh) return;
(Array.isArray(n.material) ? n.material : [n.material]).forEach(m => {
if (!m || pre.has(m)) return;
pre.add(m);
total++;
if (m.transparent && m.opacity > 0.02 && m.opacity < 0.5) cand++;
});
});
if (total === 0 || cand / total < 0.5) return 0;
}
let lifted = 0;
const seen = new Set();
obj.traverse(n => {
if (!n.isMesh) return;
(Array.isArray(n.material) ? n.material : [n.material]).forEach(m => {
if (!m || seen.has(m)) return;
seen.add(m);
if (!m.transparent || m.opacity <= 0.02) return;
if (want !== 1 && m.opacity >= 0.5) return;
m.opacity = Math.min(1, m.opacity * 3);
if (m.map) {
// THE MIP MURDER (proven in the headless harness, 8/9): thin-
// fiber art sampled at minification reads the deep mip levels,
// and every deep mip of a rainbow texture averages to GREY —
// the model erases its own colors at small sizes. No mips =
// the colors survive at any scale.
m.map.minFilter = THREE.LinearFilter;
m.map.needsUpdate = true;
}
if ('emissive' in m) {
if (m.map) { m.emissiveMap = m.map; m.emissive = new THREE.Color(0xffffff); }
else m.emissive.copy(m.color);
m.emissiveIntensity = 1.0;
}
if ('clearcoat' in m) m.clearcoat = 0; // white gloss stack
if ('specularIntensity' in m) m.specularIntensity = 0;
if ('envMapIntensity' in m) m.envMapIntensity = 0;
if ('metalness' in m) m.metalness = 0;
m.needsUpdate = true;
lifted++;
});
});
return lifted;
}
function _bloomQuad(THREE, frag, uniforms) {
const s = new THREE.Scene();
const g = new THREE.PlaneGeometry(2, 2);
const m = new THREE.ShaderMaterial({ uniforms, depthTest: false, depthWrite: false,
vertexShader: "varying vec2 vUv; void main(){ vUv=uv; gl_Position=vec4(position.xy,0.,1.); }",
fragmentShader: frag });
s.add(new THREE.Mesh(g, m));
return { s, g, m, cam: new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1) };
}
function buildBloomRig(THREE, renderer, o) {
o = o || { k: 2.2, sat: 2.6, spread: 2.6 };
// THE GLOW BLOOM (harness-verified against a reference render):
// hand-rolled alpha-correct bloom for lifted
// glow models — scene to texture, half-res two-round gaussian,
// composite base + SATURATED glow with accumulated alpha so the haze
// composites over live video like real light, ACES + gamma done in
// the composite shader (RT renders skip three's output transforms).
// The stock UnrealBloomPass was rejected: it stomps the alpha
// channel and blacks out transparent canvases.
const size = new THREE.Vector2();
renderer.getDrawingBufferSize(size);
const mk = (w, h, smp) => new THREE.WebGLRenderTarget(w, h,
{ samples: smp || 0, minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter });
return {
rtScene: mk(size.x, size.y, 4),
rtA: mk(size.x / 2, size.y / 2), rtB: mk(size.x / 2, size.y / 2),
o,
px: o.spread / (size.x / 2),
blurQ: _bloomQuad(THREE, `varying vec2 vUv; uniform sampler2D tex; uniform vec2 dir;
void main(){ vec4 s = texture2D(tex,vUv)*0.227027;
s+=texture2D(tex,vUv+dir*1.3846)*0.3162162; s+=texture2D(tex,vUv-dir*1.3846)*0.3162162;
s+=texture2D(tex,vUv+dir*3.2308)*0.0702703; s+=texture2D(tex,vUv-dir*3.2308)*0.0702703;
gl_FragColor = s; }`, { tex: { value: null }, dir: { value: new THREE.Vector2() } }),
compQ: _bloomQuad(THREE, `varying vec2 vUv; uniform sampler2D base;
uniform sampler2D glow; uniform float k; uniform float sat;
vec3 aces(vec3 c){ return clamp(c*(2.51*c+0.03)/(c*(2.43*c+0.59)+0.14), 0., 1.); }
void main(){ vec4 b = texture2D(base,vUv); vec4 g = texture2D(glow,vUv);
float l = dot(g.rgb, vec3(0.299,0.587,0.114));
vec3 gs = clamp(mix(vec3(l), g.rgb, sat), 0., 8.);
vec3 col = b.rgb + gs*k; float a = clamp(b.a + g.a*k*0.9, 0., 1.);
col = aces(col); col = pow(col, vec3(1./2.2));
gl_FragColor = vec4(col, a); }`,
{ base: { value: null }, glow: { value: null },
k: { value: o.k }, sat: { value: o.sat } }), // glow-lift hots = Jared's "turn them all up a LOT" (8/9)
};
}
function ensureModelRes(sc, scale, held) {
// ADAPTIVE RESOLUTION (Build 1.9, Jared's "low resolution" catch):
// the canvas re-renders at the size it's actually displayed — a
// stretched hologram renders AT screen resolution instead of blowing
// up a fixed 480px bitmap (and OBS's 1x-density browser stops being
// half the tracker's sharpness). Resizes only on SETTLE (never mid-
// grip — RT reallocation would hitch the stretch), 25% hysteresis,
// 2048 cap, never below the 480 base (minis stay supersampled).
if (held || !sc.bufSize) return;
const want = Math.round(Math.min(2048, Math.max(MODEL_PX,
MODEL_PX * (devicePixelRatio || 1) * SS * (scale || 1))));
if (Math.abs(want - sc.bufSize) / sc.bufSize < 0.25) return;
sc.bufSize = want;
sc.renderer.setPixelRatio(1);
sc.renderer.setSize(want, want, false); // CSS stays 480 (stylesheet)
if (sc.post) { // bloom rig rebuilt to match
[sc.post.rtScene, sc.post.rtA, sc.post.rtB].forEach(rt => rt.dispose());
[sc.post.blurQ, sc.post.compQ].forEach(q => { q.g.dispose(); q.m.dispose(); });
sc.post = buildBloomRig(sc.THREE, sc.renderer, sc.post.o);
}
}
function renderModelScene(sc) {
const r = sc.renderer, p = sc.post;
if (sc.ghostMat)
// THE SCAN BEAM loop: phase climbs the model's own height per
// ~6s cycle (the shader wraps it — no gap, ever). Wall-clock
// phase so the tracker and the OBS overlay pulse in sync.
sc.ghostMat.uniforms.uBeam.value =
((Date.now() % 6000) / 6000) * sc.ghostMat.beamSpan;
if (!p) { r.render(sc.scene, sc.camera); return; }
r.setRenderTarget(p.rtScene); r.render(sc.scene, sc.camera);
const bu = p.blurQ.m.uniforms;
bu.tex.value = p.rtScene.texture; bu.dir.value.set(p.px, 0);
r.setRenderTarget(p.rtA); r.render(p.blurQ.s, p.blurQ.cam);
bu.tex.value = p.rtA.texture; bu.dir.value.set(0, p.px);
r.setRenderTarget(p.rtB); r.render(p.blurQ.s, p.blurQ.cam);
bu.tex.value = p.rtB.texture; bu.dir.value.set(p.px * 2, 0);
r.setRenderTarget(p.rtA); r.render(p.blurQ.s, p.blurQ.cam);
bu.tex.value = p.rtA.texture; bu.dir.value.set(0, p.px * 2);
r.setRenderTarget(p.rtB); r.render(p.blurQ.s, p.blurQ.cam);
bu.tex.value = p.rtB.texture; bu.dir.value.set(p.px * 3, 0);
r.setRenderTarget(p.rtA); r.render(p.blurQ.s, p.blurQ.cam);
bu.tex.value = p.rtA.texture; bu.dir.value.set(0, p.px * 3);
r.setRenderTarget(p.rtB); r.render(p.blurQ.s, p.blurQ.cam);
p.compQ.m.uniforms.base.value = p.rtScene.texture;
p.compQ.m.uniforms.glow.value = p.rtB.texture;
r.setRenderTarget(null); r.render(p.compQ.s, p.compQ.cam);
}
function loadThree() {
if (!_three) _three = Promise.all([
import("three"),
import("three/addons/loaders/GLTFLoader.js"),
import("three/addons/environments/RoomEnvironment.js"),
]).then(([T, L, E]) => ({ THREE: T, GLTFLoader: L.GLTFLoader,
RoomEnvironment: E.RoomEnvironment }));
return _three;
}
async function buildModelScene(el, src, mm, lift) {
try {
const { THREE, GLTFLoader, RoomEnvironment } = await loadThree();
const canvas = el.querySelector("canvas");
const renderer = new THREE.WebGLRenderer({ canvas, alpha: true,
antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio || 1, 2));
renderer.setSize(MODEL_PX, MODEL_PX, false);
// ACES film curve on the plain path (a blown-out-highlights
// catch): highlights roll off instead of clipping. Canvas
// renders only — the bloom path renders to RTs (which skip tone
// mapping) and does its own ACES in the composite; no double-dip.
renderer.toneMapping = THREE.ACESFilmicToneMapping;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(35, 1, 0.01, 100);
camera.position.set(0, 0, 3.2);
const gltf = await new GLTFLoader().loadAsync(src);
const obj = gltf.scene;
let nLift = 0, ghostMat = null;
// SKELETON-AWARE LOAD (an AI-generated model's export-skeleton
// cut-off catch): skinned meshes store BIND-POSE geometry — the
// real shape only exists after the bones pose it. So: measure with
// the strings pulled, and NEVER let the culler eat a puppet (the
// old guard only ran when animation clips arrived — a skeleton
// with missing clips slipped through and vanished piecewise).
obj.updateMatrixWorld(true);
obj.traverse(n => { if (n.isSkinnedMesh) n.frustumCulled = false; });
const box = new THREE.Box3();
// THE ENVELOPE CACHE (round 4 — Jared: "slight delay... I guess
// that's the tradeoff"; refunded): the measured performance
// envelope is remembered per file, so the invisible rehearsal
// below runs ONCE per model per browser — every later load reads
// the box instantly.
const bkey = "barehands-box:" + src;
let cachedBox = null;
try { cachedBox = JSON.parse(localStorage.getItem(bkey) || "null"); }
catch (e) {}
if (cachedBox && cachedBox.min && cachedBox.max) {
box.min.fromArray(cachedBox.min);
box.max.fromArray(cachedBox.max);
} else {
try {
obj.traverse(n => {
if (!n.isMesh) return;
if (n.isSkinnedMesh) {
n.skeleton.update();
n.computeBoundingBox();
if (n.boundingBox)
box.union(n.boundingBox.clone().applyMatrix4(n.matrixWorld));
} else {
box.expandByObject(n);
}
});
} catch (e) {}
// belt + suspenders (round 2): union the skeleton-posed box with
// the plain measurement — whichever method sees more body wins
try { box.union(new THREE.Box3().setFromObject(obj)); } catch (e) {}
// round 3 ("it's still catching"): the ANIMATION escapes any
// load-pose snapshot — play every clip invisibly and union a
// dozen sampled frames each; the box becomes the true envelope
// of the whole performance
try {
if (gltf.animations && gltf.animations.length) {
const probe = new THREE.AnimationMixer(obj);
for (const clip of gltf.animations) {
const act = probe.clipAction(clip);
act.play();
const N = 12;
for (let i = 0; i <= N; i++) {
probe.setTime(clip.duration * i / N || 0);
obj.updateMatrixWorld(true);
obj.traverse(n => {
if (!n.isSkinnedMesh) return;
n.skeleton.update();
n.computeBoundingBox();
if (n.boundingBox)
box.union(n.boundingBox.clone().applyMatrix4(n.matrixWorld));
});
}
act.stop();
}
probe.stopAllAction();
}
} catch (e) {}
try {
if (!box.isEmpty())
localStorage.setItem(bkey, JSON.stringify(
{ min: box.min.toArray(), max: box.max.toArray() }));
} catch (e) {}
}
if (box.isEmpty()) box.setFromObject(obj);
obj.position.sub(box.getCenter(new THREE.Vector3()));
const bsz = box.getSize(new THREE.Vector3());
// THE EXPLODE RIG (inspired by a viral exploded-car web demo):
// the model is now centered at the origin, so
// every part's world center IS its outward flight direction. Parts
// sorted big-to-small for the stagger — panels leave first, small
// parts trail, which is what reads as engineered instead of
// detonated. Works on any parted GLB; a fused model just has one
// part and nothing visibly happens.
const exParts = [];
try {
obj.updateMatrixWorld(true);
const _pb = new THREE.Box3(), _pc = new THREE.Vector3();
obj.traverse(n => {
if (!n.isMesh || n.isSkinnedMesh) return;
try { _pb.setFromObject(n); } catch (e) { return; }
if (_pb.isEmpty()) return;
_pb.getCenter(_pc);
const dir = _pc.clone();
if (dir.length() < 1e-4) dir.set(0, 1, 0);
dir.normalize();
exParts.push({ n, home: n.position.clone(), dir,
size: _pb.getSize(new THREE.Vector3()).length() });
});
exParts.sort((a, b) => b.size - a.size);
exParts.forEach((p, i) => {
p.lag = exParts.length > 1 ? 0.35 * i / (exParts.length - 1) : 0;
});
} catch (e) {}
const exSpread = (bsz.length() || 1) * 0.55;
// 1.3 fit (was 1.7): real breathing room inside the square render
// window, so animation strides and pose swings don't overflow its
// edges — models rest smaller, and stretching covers the rest
const fit = 1.3 / (bsz.length() || 1);
const group = new THREE.Group();
group.scale.setScalar(fit);
group.add(obj);
scene.add(group);
let mixer = null;
if (gltf.animations && gltf.animations.length) {
// animated GLBs: play every clip — downloaded props often
// split one logical animation across clips. Skinned meshes lose frustum culling (the bind-pose
// bounding-box vanishing bug).
mixer = new THREE.AnimationMixer(obj);
gltf.animations.forEach(cl => mixer.clipAction(cl).play());
}
if (mm === "holo") {
// THE GHOST GLASS (modeled on a hologram-style AI-render
// reference, harness-matched): fresnel rim
// shader — translucent teal volume, X-ray interior, silhouettes
// burning bright for the bloom to catch. Skinning chunks included
// so animated models wear it too. (Replaces the v1 triangle
// wireframe — dense meshes rendered as blue soup.)
const ghost = new THREE.ShaderMaterial({
uniforms: {
cBase: { value: new THREE.Color(0.40, 0.75, 0.71) },
cRim: { value: new THREE.Color(0.75, 1.0, 0.96) },
rimPow: { value: 3.2 }, baseA: { value: 0.12 },
rimA: { value: 0.8 }, boost: { value: 1.4 },
uBeam: { value: 0.0 }, uBeamW: { value: 0.0375 },
uSpan: { value: Math.max(bsz.y * fit, 0.2) },
},
vertexShader: `
#include <common>
#include <skinning_pars_vertex>
varying vec3 vN; varying vec3 vV; varying float vWy;
void main() {
#include <skinbase_vertex>
#include <beginnormal_vertex>
#include <skinnormal_vertex>
#include <begin_vertex>
#include <skinning_vertex>
vec4 mv = modelViewMatrix * vec4(transformed, 1.0);
vN = normalize(normalMatrix * objectNormal);
vV = normalize(-mv.xyz);
vWy = mv.y;
gl_Position = projectionMatrix * mv;
}`,
fragmentShader: `
uniform vec3 cBase; uniform vec3 cRim;
uniform float rimPow; uniform float baseA;
uniform float rimA; uniform float boost;
uniform float uBeam; uniform float uBeamW; uniform float uSpan;
varying vec3 vN; varying vec3 vV; varying float vWy;