Spaces:
Running
Running
Add the Pixel renderer: pixel art of the 3DGS scenes and of the modelled ones
Browse files- README.md +5 -2
- dist/assets/{__vite-browser-external-COjOOfZK.js → __vite-browser-external-C_NOlca-.js} +1 -1
- dist/assets/{index-CPsrtEdT.css → index-B0OqpDBS.css} +1 -1
- dist/assets/{index-B6g15d6P.js → index-BGZ4TK1u.js} +0 -0
- dist/assets/{ort.wasm.bundle.min-B_kL_bec.js → ort.wasm.bundle.min-U3rC08vl.js} +0 -0
- dist/assets/{spark.module-BKn6je4z.js → spark.module-DyJfYrxI.js} +1 -1
- dist/index.html +3 -2
- index.html +1 -0
- src/main.js +643 -637
- src/render/palette.js +261 -0
- src/render/pixel.js +408 -0
- src/render/view.js +40 -8
- src/style.css +531 -531
README.md
CHANGED
|
@@ -38,7 +38,9 @@ The robot model, its inverse kinematics and keyboard map, and the 3D Gaussian sp
|
|
| 38 |
- **Drag objects** with the mouse.
|
| 39 |
- **Switch renderers**: Toon (cel shading with ink outlines); Lit (image-based lighting, shadows, PBR
|
| 40 |
materials and procedural textures); 3DGS (the scene's splat; the robot is lit by light captured from
|
| 41 |
-
the splat, and its shadows fall on the splat's floor, counters and walls)
|
|
|
|
|
|
|
| 42 |
- **Watch the robot's cameras**: head and both wrists.
|
| 43 |
- **Run skills**: go to an object, pick it (scripted grasp), place it in or on another object. A held
|
| 44 |
object stays put: while a gripper squeezes something, MuJoCo's noslip solver keeps it from creeping out
|
|
@@ -79,7 +81,8 @@ assets/policies/ exported policies
|
|
| 79 |
src/core/ loading, scene composition (as MuJoCo-GS-Web's SceneManager), the simulation loop
|
| 80 |
src/robots/ xlerobot.js (MuJoCo-GS-Web's IK and keys), skills.js, g1.js (the G1's walking
|
| 81 |
policy and keys), generic.js (uploaded robots)
|
| 82 |
-
src/render/ three.js views: toon (outlines in toon.js), lit
|
|
|
|
| 83 |
src/policy/, src/tasks/ ONNX Runtime policy runner and the pick task's observation
|
| 84 |
src/agent/ the agent's tools, the chat loop, Hugging Face sign-in
|
| 85 |
tools/, train/ Node checks, demonstrations, dataset, training, ONNX export, publishing
|
|
|
|
| 38 |
- **Drag objects** with the mouse.
|
| 39 |
- **Switch renderers**: Toon (cel shading with ink outlines); Lit (image-based lighting, shadows, PBR
|
| 40 |
materials and procedural textures); 3DGS (the scene's splat; the robot is lit by light captured from
|
| 41 |
+
the splat, and its shadows fall on the splat's floor, counters and walls); Pixel (pixel art of the
|
| 42 |
+
splat, or of the Toon scene where there is none: about 240 rows of whole pixels, 32 colours chosen
|
| 43 |
+
from what the view shows, ordered dithering, and an ink line around the robot and the objects).
|
| 44 |
- **Watch the robot's cameras**: head and both wrists.
|
| 45 |
- **Run skills**: go to an object, pick it (scripted grasp), place it in or on another object. A held
|
| 46 |
object stays put: while a gripper squeezes something, MuJoCo's noslip solver keeps it from creeping out
|
|
|
|
| 81 |
src/core/ loading, scene composition (as MuJoCo-GS-Web's SceneManager), the simulation loop
|
| 82 |
src/robots/ xlerobot.js (MuJoCo-GS-Web's IK and keys), skills.js, g1.js (the G1's walking
|
| 83 |
policy and keys), generic.js (uploaded robots)
|
| 84 |
+
src/render/ three.js views: toon (outlines in toon.js), lit, 3DGS (Spark) and pixel (pixel.js;
|
| 85 |
+
its colours in palette.js)
|
| 86 |
src/policy/, src/tasks/ ONNX Runtime policy runner and the pick task's observation
|
| 87 |
src/agent/ the agent's tools, the chat loop, Hugging Face sign-in
|
| 88 |
tools/, train/ Node checks, demonstrations, dataset, training, ONNX export, publishing
|
dist/assets/{__vite-browser-external-COjOOfZK.js → __vite-browser-external-C_NOlca-.js}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
import{Y as e}from"./index-
|
|
|
|
| 1 |
+
import{Y as e}from"./index-BGZ4TK1u.js";var t=e(((e,t)=>{t.exports={}}));export default t();
|
dist/assets/{index-CPsrtEdT.css → index-B0OqpDBS.css}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
:root{--bg:#f5f5f7;--panel:#fff;--text:#1d1d1f;--muted:#6e6e73;--line:#0000001a;--accent:#0071e3;--ok:#1a7f37;--error:#b42318;--radius:12px;color-scheme:light;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,PingFang SC,Microsoft YaHei,sans-serif}@media (prefers-color-scheme:dark){:root{--bg:#111113;--panel:#1c1c1e;--text:#f5f5f7;--muted:#a1a1a6;--line:#ffffff1f;--accent:#2997ff;--ok:#3fb950;--error:#ff7b72;color-scheme:dark}}*{box-sizing:border-box}html,body{background:var(--bg);height:100%;color:var(--text);margin:0}.app{grid-template-columns:1fr 320px;height:100vh;display:grid}.stage{min-height:0;position:relative}#view{outline:none;width:100%;height:100%;display:block}.brand{background:color-mix(in srgb, var(--panel) 72%, transparent);backdrop-filter:blur(8px);pointer-events:none;border-radius:12px;padding:6px 12px 7px;position:absolute;top:12px;left:12px}.brand h1{letter-spacing:-.01em;margin:0;font-size:22px}.brand p{color:var(--muted);margin:2px 0 0;font-size:13px}.view-labels span{color:#fff;pointer-events:none;background:#0000008c;border-radius:6px;padding:2px 8px;font-size:12px;position:absolute}.loading{background:var(--bg);place-items:center;display:grid;position:absolute;inset:0}.loading[hidden]{display:none}.loading-card{text-align:center;width:min(360px,80vw);color:var(--muted)}.loading.failed .loading-card{color:var(--error)}.progress{background:var(--line);border-radius:3px;height:6px;overflow:hidden}.progress div{background:var(--accent);width:0;height:100%;transition:width .2s}.panel{background:var(--panel);border-left:1px solid var(--line);padding:16px 18px 24px;font-size:14px;overflow-y:auto}.panel section,.panel details{border-bottom:1px solid var(--line);padding:12px 0}.panel h2{letter-spacing:.04em;text-transform:uppercase;color:var(--muted);justify-content:space-between;align-items:center;margin:0 0 10px;font-size:12px;font-weight:600;display:flex}.segmented{background:var(--bg);border-radius:9px;grid-template-columns:repeat(
|
|
|
|
| 1 |
+
:root{--bg:#f5f5f7;--panel:#fff;--text:#1d1d1f;--muted:#6e6e73;--line:#0000001a;--accent:#0071e3;--ok:#1a7f37;--error:#b42318;--radius:12px;color-scheme:light;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,PingFang SC,Microsoft YaHei,sans-serif}@media (prefers-color-scheme:dark){:root{--bg:#111113;--panel:#1c1c1e;--text:#f5f5f7;--muted:#a1a1a6;--line:#ffffff1f;--accent:#2997ff;--ok:#3fb950;--error:#ff7b72;color-scheme:dark}}*{box-sizing:border-box}html,body{background:var(--bg);height:100%;color:var(--text);margin:0}.app{grid-template-columns:1fr 320px;height:100vh;display:grid}.stage{min-height:0;position:relative}#view{outline:none;width:100%;height:100%;display:block}.brand{background:color-mix(in srgb, var(--panel) 72%, transparent);backdrop-filter:blur(8px);pointer-events:none;border-radius:12px;padding:6px 12px 7px;position:absolute;top:12px;left:12px}.brand h1{letter-spacing:-.01em;margin:0;font-size:22px}.brand p{color:var(--muted);margin:2px 0 0;font-size:13px}.view-labels span{color:#fff;pointer-events:none;background:#0000008c;border-radius:6px;padding:2px 8px;font-size:12px;position:absolute}.loading{background:var(--bg);place-items:center;display:grid;position:absolute;inset:0}.loading[hidden]{display:none}.loading-card{text-align:center;width:min(360px,80vw);color:var(--muted)}.loading.failed .loading-card{color:var(--error)}.progress{background:var(--line);border-radius:3px;height:6px;overflow:hidden}.progress div{background:var(--accent);width:0;height:100%;transition:width .2s}.panel{background:var(--panel);border-left:1px solid var(--line);padding:16px 18px 24px;font-size:14px;overflow-y:auto}.panel section,.panel details{border-bottom:1px solid var(--line);padding:12px 0}.panel h2{letter-spacing:.04em;text-transform:uppercase;color:var(--muted);justify-content:space-between;align-items:center;margin:0 0 10px;font-size:12px;font-weight:600;display:flex}.segmented{background:var(--bg);border-radius:9px;grid-template-columns:repeat(4,1fr);gap:2px;padding:2px;display:grid}.segmented button{color:var(--text);font:inherit;cursor:pointer;background:0 0;border:0;border-radius:7px;padding:6px 0}.segmented button[aria-pressed=true]{background:var(--panel);font-weight:600;box-shadow:0 1px 3px #00000026}.segmented button:disabled{color:var(--muted);cursor:default}.chips{flex-wrap:wrap;gap:8px;display:flex}.chips label{border:1px solid var(--line);cursor:pointer;border-radius:999px;align-items:center;gap:6px;padding:4px 10px;display:inline-flex}.task p{margin:0 0 8px}.meter{background:var(--bg);border-radius:4px;height:8px;overflow:hidden}.meter div{background:var(--accent);width:0;height:100%}.task.done .meter div{background:var(--ok)}.lift{color:var(--muted);margin-top:8px!important}.badge{background:var(--ok);color:#fff;border-radius:999px;margin-left:6px;padding:1px 8px;font-size:12px;display:none}.task.done .badge{display:inline-block}.buttons{gap:8px;display:flex}.buttons button{border:1px solid var(--line);background:var(--panel);color:var(--text);font:inherit;cursor:pointer;border-radius:999px;flex:1;padding:8px 0}.buttons .primary{border-color:var(--accent);background:var(--accent);color:#fff}.buttons button:disabled{opacity:.5;cursor:default}.active-arm{background:var(--bg);color:var(--text);text-transform:none;letter-spacing:0;border-radius:999px;padding:1px 8px}.keys{grid-template-columns:auto 1fr;gap:4px 12px;margin:0;display:grid}.keys dt{white-space:nowrap}.keys dd{color:var(--muted);margin:0}kbd{border:1px solid var(--line);border-bottom-width:2px;border-radius:5px;padding:1px 6px;font:12px ui-monospace,SFMono-Regular,Consolas,monospace}summary{cursor:pointer;font-weight:600}.note{color:var(--muted);font-size:12px}.note.error{color:var(--error)}.state{border-collapse:collapse;width:100%;font:12px ui-monospace,SFMono-Regular,Consolas,monospace}.state th{text-align:left;color:var(--muted);padding:2px 0;font-weight:400}.state td{text-align:right}footer p{color:var(--muted);margin:14px 0 0;font-size:12px}a{color:var(--accent)}@media (width<=760px){.app{grid-template-rows:60vh auto;grid-template-columns:1fr;height:auto}.stage{height:60vh}.panel{border-left:0;border-top:1px solid var(--line)}}.tabs{z-index:2;background:var(--panel);border-bottom:1px solid var(--line);grid-template-columns:repeat(3,1fr);gap:2px;margin:-16px -18px 4px;padding:10px 12px;display:grid;position:sticky;top:-16px}.tabs button{color:var(--muted);font:inherit;cursor:pointer;background:0 0;border:0;border-radius:8px;padding:7px 0;font-weight:600}.tabs button[aria-selected=true]{background:var(--bg);color:var(--text)}.tab[hidden]{display:none}select,input[type=text],input:not([type]),input[type=password],textarea{border:1px solid var(--line);background:var(--bg);width:100%;color:var(--text);font:inherit;border-radius:8px;padding:7px 9px}textarea{resize:vertical}.row{align-items:center;gap:8px;display:flex}.row select{flex:1}.row button,.connect button,.link{border:1px solid var(--line);background:var(--panel);color:var(--text);font:inherit;cursor:pointer;white-space:nowrap;border-radius:999px;padding:7px 12px}.buttons.wrap{flex-wrap:wrap;margin-top:10px}.buttons.wrap button{flex:30%}.status{min-height:1.4em;color:var(--muted);margin:10px 0 0;font-size:13px}.activity{color:#fff;pointer-events:none;background:#0009;border-radius:999px;padding:6px 12px;font-size:13px;position:absolute;top:18px;right:18px}.activity[hidden]{display:none}.hint{color:var(--muted);pointer-events:none;margin:0;font-size:12px;position:absolute;bottom:12px;right:18px}.sliders label{color:var(--muted);gap:2px;margin-bottom:8px;font-size:12px;display:grid}.sliders input{width:100%}.connect .hf{color:#1d1d1f;background:#ffd21e;border:0;width:100%;padding:9px 12px;font-weight:600}.connect label{color:var(--muted);gap:4px;margin-top:10px;font-size:12px;display:grid}.connect label.check{align-items:center;gap:8px;display:flex}.connect label.check input{width:auto}.connect details{border:0;margin-top:10px;padding:0}.link{color:var(--accent);background:0 0;border:0;padding:0}.chat-log{flex-direction:column;gap:8px;min-height:120px;max-height:46vh;margin-bottom:10px;display:flex;overflow-y:auto}.msg{overflow-wrap:anywhere;border-radius:10px;padding:8px 10px;line-height:1.4}.msg.user{background:var(--accent);color:#fff;align-self:flex-end;max-width:85%}.msg.assistant{background:var(--bg)}.msg.tool{border:1px solid var(--line);color:var(--muted);padding:4px 8px;font:12px ui-monospace,SFMono-Regular,Consolas,monospace}.msg.tool .tool-name{color:var(--text);font-weight:600}.msg.tool.failed .tool-result{color:#c0392b}.msg.tool img{border-radius:6px;width:100%;display:block}.msg.error{color:#c0392b;font-size:13px}.examples{flex-wrap:wrap;gap:6px;margin-bottom:10px;display:flex}.examples[hidden]{display:none}.examples button{border:1px solid var(--line);background:var(--panel);color:var(--text);font:inherit;cursor:pointer;border-radius:999px;padding:5px 10px;font-size:12px}.chat-form .buttons{margin-top:8px}code{font:12px ui-monospace,SFMono-Regular,Consolas,monospace}@media (width<=760px){.tabs{margin-top:-16px;top:0}.hint{display:none}}
|
dist/assets/{index-B6g15d6P.js → index-BGZ4TK1u.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/assets/{ort.wasm.bundle.min-B_kL_bec.js → ort.wasm.bundle.min-U3rC08vl.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/assets/{spark.module-BKn6je4z.js → spark.module-DyJfYrxI.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import{A as e,B as t,C as n,D as r,E as i,F as a,G as o,H as s,I as c,J as l,K as u,L as d,M as f,N as p,O as m,P as h,R as g,S as _,T as v,U as y,V as b,W as x,_ as ee,a as te,b as ne,c as S,d as C,f as w,g as re,h as ie,i as ae,j as oe,k as se,l as ce,m as le,n as T,o as ue,p as de,q as fe,r as pe,s as me,t as he,u as ge,v as _e,w as ve,x as ye,y as be,z as xe}from"./index-B6g15d6P.js";var Se=new e(-1,1,1,-1,0,1),Ce=new class extends ue{constructor(){super(),this.setAttribute(`position`,new ie([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute(`uv`,new ie([0,2,0,0,2,0],2))}},we=class{constructor(e){this._mesh=new i(Ce,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,Se)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}},E=Uint8Array,Te=Uint16Array,Ee=Int32Array,De=new E([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Oe=new E([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ke=new E([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ae=function(e,t){for(var n=new Te(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new Ee(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},je=Ae(De,2),Me=je.b,Ne=je.r;Me[28]=258,Ne[258]=28;var Pe=Ae(Oe,0),Fe=Pe.b;Pe.r;for(var Ie=new Te(32768),D=0;D<32768;++D){var Le=(D&43690)>>1|(D&21845)<<1;Le=(Le&52428)>>2|(Le&13107)<<2,Le=(Le&61680)>>4|(Le&3855)<<4,Ie[D]=((Le&65280)>>8|(Le&255)<<8)>>1}for(var Re=(function(e,t,n){for(var r=e.length,i=0,a=new Te(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new Te(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new Te(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=o[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[Ie[d]>>c]=l}else for(s=new Te(r),i=0;i<r;++i)e[i]&&(s[i]=Ie[o[e[i]-1]++]>>15-e[i]);return s}),ze=new E(288),D=0;D<144;++D)ze[D]=8;for(var D=144;D<256;++D)ze[D]=9;for(var D=256;D<280;++D)ze[D]=7;for(var D=280;D<288;++D)ze[D]=8;for(var Be=new E(32),D=0;D<32;++D)Be[D]=5;var Ve=Re(ze,9,1),He=Re(Be,5,1),Ue=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},O=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},We=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Ge=function(e){return(e+7)/8|0},Ke=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new E(e.subarray(t,n))},qe=[`unexpected EOF`,`invalid block type`,`invalid length/literal`,`invalid distance`,`stream finished`,`no stream handler`,,`no callback`,`invalid UTF-8 data`,`extra field too long`,`date not in range 1980-2099`,`filename too long`,`stream finishing`,`invalid zip data`],k=function(e,t,n){var r=Error(t||qe[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,k),!n)throw r;return r},Je=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new E(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new E(i*3));var l=function(e){var t=n.length;if(e>t){var r=new E(Math.max(t*2,e));r.set(n),n=r}},u=t.f||0,d=t.p||0,f=t.b||0,p=t.l,m=t.d,h=t.m,g=t.n,_=i*8;do{if(!p){u=O(e,d,1);var v=O(e,d+1,3);if(d+=3,!v){var y=Ge(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&k(0);break}s&&l(f+b),n.set(e.subarray(y,x),f),t.b=f+=b,t.p=d=x*8,t.f=u;continue}if(v==1)p=Ve,m=He,h=9,g=5;else if(v==2){var ee=O(e,d,31)+257,te=O(e,d+10,15)+4,ne=ee+O(e,d+5,31)+1;d+=14;for(var S=new E(ne),C=new E(19),w=0;w<te;++w)C[ke[w]]=O(e,d+w*3,7);d+=te*3;for(var re=Ue(C),ie=(1<<re)-1,ae=Re(C,re,1),w=0;w<ne;){var oe=ae[O(e,d,ie)];d+=oe&15;var y=oe>>4;if(y<16)S[w++]=y;else{var se=0,ce=0;for(y==16?(ce=3+O(e,d,3),d+=2,se=S[w-1]):y==17?(ce=3+O(e,d,7),d+=3):y==18&&(ce=11+O(e,d,127),d+=7);ce--;)S[w++]=se}}var le=S.subarray(0,ee),T=S.subarray(ee);h=Ue(le),g=Ue(T),p=Re(le,h,1),m=Re(T,g,1)}else k(1);if(d>_){c&&k(0);break}}s&&l(f+131072);for(var ue=(1<<h)-1,de=(1<<g)-1,fe=d;;fe=d){var se=p[We(e,d)&ue],pe=se>>4;if(d+=se&15,d>_){c&&k(0);break}if(se||k(2),pe<256)n[f++]=pe;else if(pe==256){fe=d,p=null;break}else{var me=pe-254;if(pe>264){var w=pe-257,he=De[w];me=O(e,d,(1<<he)-1)+Me[w],d+=he}var ge=m[We(e,d)&de],_e=ge>>4;ge||k(3),d+=ge&15;var T=Fe[_e];if(_e>3){var he=Oe[_e];T+=We(e,d)&(1<<he)-1,d+=he}if(d>_){c&&k(0);break}s&&l(f+131072);var ve=f+me;if(f<T){var ye=a-T,be=Math.min(T,ve);for(ye+f<0&&k(3);f<be;++f)n[f]=r[ye+f]}for(;f<ve;++f)n[f]=n[f-T]}}t.l=p,t.p=fe,t.b=f,t.f=u,p&&(u=1,t.m=h,t.d=m,t.n=g)}while(!u);return f!=n.length&&o?Ke(n,0,f):n.subarray(0,f)},Ye=new E(0),A=function(e,t){return e[t]|e[t+1]<<8},j=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Xe=function(e,t){return j(e,t)+j(e,t+4)*4294967296},Ze=function(e){(e[0]!=31||e[1]!=139||e[2]!=8)&&k(6,`invalid gzip data`);var t=e[3],n=10;t&4&&(n+=(e[10]|e[11]<<8)+2);for(var r=(t>>3&1)+(t>>4&1);r>0;r-=!e[n++]);return n+(t&2)},Qe=function(){function e(e,t){typeof e==`function`&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new E(32768),this.p=new E(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||k(5),this.d&&k(4),!this.p.length)this.p=e;else if(e.length){var t=new E(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}},e.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=Je(this.p,this.s,this.o);this.ondata(Ke(n,t,this.s.b),this.d),this.o=Ke(n,this.s.b-32768),this.s.b=this.o.length,this.p=Ke(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}();function $e(e,t){return Je(e,{i:2},t&&t.out,t&&t.dictionary)}var et=function(){function e(e,t){this.v=1,this.r=0,Qe.call(this,e,t)}return e.prototype.push=function(e,t){if(Qe.prototype.e.call(this,e),this.r+=e.length,this.v){var n=this.p.subarray(this.v-1),r=n.length>3?Ze(n):4;if(r>n.length){if(!t)return}else this.v>1&&this.onmember&&this.onmember(this.r-n.length);this.p=n.subarray(r),this.v=0}Qe.prototype.c.call(this,t),this.s.f&&!this.s.l&&!t&&(this.v=Ge(this.s.p)+9,this.s={i:0},this.o=new E(0),this.push(new E(0),t))},e}(),tt=typeof TextDecoder<`u`&&new TextDecoder;try{tt.decode(Ye,{stream:!0})}catch{}var nt=function(e){for(var t=``,n=0;;){var r=e[n++],i=(r>127)+(r>223)+(r>239);if(n+i>e.length)return{s:t,r:Ke(e,n-1)};i?i==3?(r=((r&15)<<18|(e[n++]&63)<<12|(e[n++]&63)<<6|e[n++]&63)-65536,t+=String.fromCharCode(55296|r>>10,56320|r&1023)):i&1?t+=String.fromCharCode((r&31)<<6|e[n++]&63):t+=String.fromCharCode((r&15)<<12|(e[n++]&63)<<6|e[n++]&63):t+=String.fromCharCode(r)}};function rt(e,t){if(t){for(var n=``,r=0;r<e.length;r+=16384)n+=String.fromCharCode.apply(null,e.subarray(r,r+16384));return n}if(tt)return tt.decode(e);var i=nt(e),a=i.s,n=i.r;return n.length&&k(8),a}var it=function(e,t){return t+30+A(e,t+26)+A(e,t+28)},at=function(e,t,n){var r=A(e,t+28),i=rt(e.subarray(t+46,t+46+r),!(A(e,t+8)&2048)),a=t+46+r,o=j(e,t+20),s=n&&o==4294967295?ot(e,a):[o,j(e,t+24),j(e,t+42)],c=s[0],l=s[1],u=s[2];return[A(e,t+10),c,l,i,a+A(e,t+30)+A(e,t+32),u]},ot=function(e,t){for(;A(e,t)!=1;t+=4+A(e,t+2));return[Xe(e,t+12),Xe(e,t+4),Xe(e,t+20)]};function st(e,t){for(var n={},r=e.length-22;j(e,r)!=101010256;--r)(!r||e.length-r>65558)&&k(13);var i=A(e,r+8);if(!i)return{};var a=j(e,r+16),o=a==4294967295||i==65535;if(o){var s=j(e,r-12);o=j(e,s)==101075792,o&&(i=j(e,s+32),a=j(e,s+48))}for(var c=t&&t.filter,l=0;l<i;++l){var u=at(e,a,o),d=u[0],f=u[1],p=u[2],m=u[3],h=u[4],g=u[5],_=it(e,g);a=h,(!c||c({name:m,size:f,originalSize:p,compression:d}))&&(d?d==8?n[m]=$e(e.subarray(_,_+f),{out:new E(p)}):k(14,`unknown compression type `+d):n[m]=Ke(e,_,_+f))}return n}var ct=Math.exp(-30),M=2048,N=2048,P=function(e){return e.PLY=`ply`,e.SPZ=`spz`,e.SPLAT=`splat`,e.KSPLAT=`ksplat`,e.PCSOGS=`pcsogs`,e.PCSOGSZIP=`pcsogszip`,e.RAD=`rad`,e}({}),lt={rgbMin:0,rgbMax:1,lnScaleMin:-12,lnScaleMax:9,sh1Max:1,sh2Max:1,sh3Max:1,lodOpacity:!1};function ut(e){return e===`int`||e===`ivec2`||e===`ivec3`||e===`ivec4`}function dt(e){return e===`uint`||e===`uvec2`||e===`uvec3`||e===`uvec4`}function ft(e){return e===`float`||e===`vec2`||e===`vec3`||e===`vec4`}function pt(e){return e===`mat2`||e===`mat2x2`||e===`mat2x3`||e===`mat2x4`||e===`mat3`||e===`mat3x2`||e===`mat3x3`||e===`mat3x4`||e===`mat4`||e===`mat4x2`||e===`mat4x3`||e===`mat4x4`}function mt(e){return ft(e)||pt(e)}function ht(e){return e===`mat2`||e===`mat2x2`}function gt(e){return e===`mat3`||e===`mat3x3`}function _t(e){return e===`mat4`||e===`mat4x4`}function F(e){return Math.trunc(e).toString()}function I(e){return`${Math.max(0,Math.trunc(e)).toString()}u`}function L(e){return e===1/0?`INFINITY`:e===-1/0?`-INFINITY`:Number.isInteger(e)?e.toFixed(1):e.toString()}function vt(e){return e instanceof yt?e.type:e.dynoOut().type}var yt=class{constructor(e){this.__isDynoValue=!0,this.type=e}},R=class extends yt{constructor(e,t){super(e.outTypes[t]),this.dyno=e,this.key=t}},bt=class extends yt{constructor(e,t){super(e),this.literal=t}getLiteral(){return this.literal}},xt=class extends bt{constructor(e,t){super(e,``),this.value=t}getLiteral(){let{type:e,value:t}=this;switch(e){case`bool`:return t?`true`:`false`;case`uint`:return I(t);case`int`:return F(t);case`float`:return L(t);case`bvec2`:{let e=t;return`bvec2(${e[0]}, ${e[1]})`}case`uvec2`:{if(t instanceof x)return`uvec2(${I(t.x)}, ${I(t.y)})`;let e=t;return`uvec2(${I(e[0])}, ${I(e[1])})`}case`ivec2`:{if(t instanceof x)return`ivec2(${F(t.x)}, ${F(t.y)})`;let e=t;return`ivec2(${F(e[0])}, ${F(e[1])})`}case`vec2`:{if(t instanceof x)return`vec2(${L(t.x)}, ${L(t.y)})`;let e=t;return`vec2(${L(e[0])}, ${L(e[1])})`}case`bvec3`:{let e=t;return`bvec3(${e[0]}, ${e[1]}, ${e[2]})`}case`uvec3`:{if(t instanceof o)return`uvec3(${I(t.x)}, ${I(t.y)}, ${I(t.z)})`;let e=t;return`uvec3(${I(e[0])}, ${I(e[1])}, ${I(e[2])})`}case`ivec3`:{if(t instanceof o)return`ivec3(${F(t.x)}, ${F(t.y)}, ${F(t.z)})`;let e=t;return`ivec3(${F(e[0])}, ${F(e[1])}, ${F(e[2])})`}case`vec3`:{if(t instanceof o)return`vec3(${L(t.x)}, ${L(t.y)}, ${L(t.z)})`;let e=t;return`vec3(${L(e[0])}, ${L(e[1])}, ${L(e[2])})`}case`bvec4`:{let e=t;return`bvec4(${e[0]}, ${e[1]}, ${e[2]}, ${e[3]})`}case`uvec4`:{if(t instanceof u)return`uvec4(${I(t.x)}, ${I(t.y)}, ${I(t.z)}, ${I(t.w)})`;let e=t;return`uvec4(${I(e[0])}, ${I(e[1])}, ${I(e[2])}, ${I(e[3])})`}case`ivec4`:{if(t instanceof u)return`ivec4(${F(t.x)}, ${F(t.y)}, ${F(t.z)}, ${F(t.w)})`;let e=t;return`ivec4(${F(e[0])}, ${F(e[1])}, ${F(e[2])}, ${F(e[3])})`}case`vec4`:{if(t instanceof u||t instanceof f)return`vec4(${L(t.x)}, ${L(t.y)}, ${L(t.z)}, ${L(t.w)})`;let e=t;return`vec4(${L(e[0])}, ${L(e[1])}, ${L(e[2])}, ${L(e[3])})`}case`mat2`:case`mat2x2`:{let r=t,i=r instanceof n?r.elements:t;return`${e}(${[,,,,].fill(0).map((e,t)=>L(i[t])).join(`, `)})`}case`mat2x3`:{let n=t;return`${e}(${[,,,,,,].fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat2x4`:{let n=t;return`${e}(${Array(8).fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat3`:case`mat3x3`:{let n=t,r=n instanceof ve?n.elements:t;return`${e}(${Array(9).fill(0).map((e,t)=>L(r[t])).join(`, `)})`}case`mat3x2`:{let n=t;return`${e}(${[,,,,,,].fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat3x4`:{let n=t;return`${e}(${Array(12).fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat4`:case`mat4x4`:{let n=t,r=n instanceof v?n.elements:t;return`${e}(${Array(16).fill(0).map((e,t)=>L(r[t])).join(`, `)})`}case`mat4x2`:{let n=t;return`${e}(${Array(8).fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat4x3`:{let n=t;return`${e}(${Array(12).fill(0).map((e,t)=>L(n[t])).join(`, `)})`}default:throw Error(`Type not implemented: ${String(e)}`)}}};function St(e,t){return new xt(e,t)}var Ct=` `,wt=class{constructor({indent:e}={}){this.globals=new Set,this.statements=[],this.uniforms={},this.declares=new Set,this.updaters=[],this.sequence=0,this.indent=Ct,this.indent=e??Ct}nextSequence(){return this.sequence++}},z=class{constructor({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,statements:a,generate:o}){this.inTypes=e??{},this.outTypes=t??{},this.inputs=n??{},this.update=r,this.globals=i,this.statements=a,this.generate=o??(({inputs:e,outputs:t,compile:n})=>({globals:this.globals?.({inputs:e,outputs:t,compile:n}),statements:this.statements?.({inputs:e,outputs:t,compile:n})}))}get outputs(){let e={};for(let t in this.outTypes)e[t]=new R(this,t);return e}apply(e){return Object.assign(this.inputs,e),this.outputs}compile({inputs:e,outputs:t,compile:n}){let r=[`// ${this.constructor.name}(${Object.values(e).join(`, `)}) => (${Object.values(t).join(`, `)})`],i=[];for(let e in t){let r=t[e];r&&!n.declares.has(r)&&(n.declares.add(r),i.push(e))}let{globals:a,statements:o,uniforms:s}=this.generate({inputs:e,outputs:t,compile:n});for(let e of a??[])n.globals.add(e);for(let e in s)n.uniforms[e]=s[e];this.update&&n.updaters.push(this.update);for(let e of i){let i=t[e];i&&(n.uniforms[i]||r.push(`${Dt(i,this.outTypes[e])};`))}return o?.length&&(r.push(`{`),r.push(...o.map(e=>n.indent+e)),r.push(`}`)),r}},Tt=class extends z{constructor({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,construct:a}){super({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,generate:e=>this.generateBlock(e)}),this.construct=a}generateBlock({inputs:e,outputs:t,compile:n}){let r={},i={};for(let t in e)e[t]!=null&&(r[t]=new bt(this.inTypes[t],e[t]));for(let e in t)t[e]!=null&&(i[e]=new yt(this.outTypes[e]));let a={roots:[]},o=this.construct(r,i,a);for(let r of this.globals?.({inputs:e,outputs:t,compile:n})??[])n.globals.add(r);let s=[],c=new Map;function l(e,t,r){let i=c.get(e);if(!i){i={sequence:n.nextSequence(),outNames:new Map,newOuts:new Set},c.set(e,i);for(let t in e.inputs){let n=e.inputs[t];for(;n;){if(n instanceof yt){n instanceof R&&l(n.dyno,n.key);break}if(typeof n.dynoOut!=`function`)throw Error(`dynoOut is not a function for ${n.constructor.name}`);n=n.dynoOut()}}s.push(e)}t&&(r||i.newOuts.add(t),i.outNames.set(t,r??`${t}_${i.sequence}`))}for(let e of a.roots)l(e);for(let e in i){let n=o?.[e]??i[e];for(;n;){if(n instanceof yt){n instanceof R&&l(n.dyno,n.key,t[e]);break}n=n.dynoOut()}i[e]=n}let u=[];for(let e of s){let t={},r={};for(let n in e.inputs){let r=e.inputs[n];for(;r;){if(r instanceof yt){if(r instanceof bt)t[n]=r.getLiteral();else if(r instanceof R){let e=c.get(r.dyno)?.outNames.get(r.key);if(!e)throw Error(`Source not found for ${r.dyno.constructor.name}.${r.key}`);t[n]=e}break}r=r.dynoOut()}}let i=c.get(e)??{outNames:new Map};for(let[e,t]of i.outNames.entries())r[e]=t;let a=e.compile({inputs:t,outputs:r,compile:n});u.push(a)}let d=[];for(let e in t)i[e]instanceof bt&&d.push(`${t[e]} = ${i[e].getLiteral()};`);return d.length>0&&u.push(d),{statements:u.flatMap((e,t)=>t===0?e:[``,...e])}}};function B(e,t,n,{update:r,globals:i}={}){return new Tt({inTypes:e,outTypes:t,construct:n,update:r,globals:i})}function Et({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,statements:a,generate:o}){return new z({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,statements:a,generate:o})}function Dt(e,t,n){let r=typeof t==`string`?t:t.type;if(!r)throw Error(`Invalid DynoType: ${String(t)}`);return`${r} ${e}${n==null?``:`[${n}]`}`}function V(e){let t=!1,n=e.split(`
|
| 2 |
`).map(e=>{let n=e.trimEnd();return t?n:n.length>0?(t=!0,n):null}).filter(e=>e!=null);for(;n.length>0&&n[n.length-1].length===0;)n.pop();if(n.length===0)return[];let r=n[0].match(/^\s*/)?.[0];if(!r)return n;let i=RegExp(`^${r}`);return n.map(e=>e.replace(i,``))}function H(e){return V(e).join(`
|
| 3 |
`)}var Ot=class extends z{constructor({a:e,outKey:t,outTypeFunc:n}){let r={a:vt(e)},i=n(vt(e));super({inTypes:r,outTypes:{[t]:i},inputs:{a:e}}),this.outKey=t}dynoOut(){return new R(this,this.outKey)}},kt=class extends z{constructor({a:e,b:t,outKey:n,outTypeFunc:r}){let i={a:vt(e),b:vt(t)},a=r(vt(e),vt(t));super({inTypes:i,outTypes:{[n]:a},inputs:{a:e,b:t}}),this.outKey=n}dynoOut(){return new R(this,this.outKey)}},At=Number.parseInt(`187`)>=179,jt=new Float32Array(1),Mt=new Uint32Array(jt.buffer),Nt=`Float16Array`in globalThis,Pt=Nt?new globalThis.Float16Array(1):null,Ft=new Uint16Array(Pt?.buffer);function It(e){return jt[0]=e,Mt[0]}function Lt(e){return Mt[0]=e,jt[0]}var U=Nt?Rt:zt,W=Nt?Bt:Vt;function Rt(e){return Pt[0]=e,Ft[0]}function zt(e){jt[0]=e;let t=Mt[0],n=t>>31&1,r=t>>23&255,i=t&8388607,a=n<<15;if(r===255)return i===0?a|31744:a|32767;let o=r-127+15;if(o>=31)return a|31744;if(o<=0)return o<-10?a:a|(i|8388608)>>1-o+13;let s=i>>13;return a|o<<10|s}function Bt(e){return Ft[0]=e,Pt[0]}function Vt(e){let t=e>>15&1,n=e>>10&31,r=e&1023,i;if(n===0){if(r===0)i=t<<31;else{let e=r,n=-14;for(;!(e&1024);)e<<=1,n--;e&=1023;let a=n+127,o=e<<13;i=t<<31|a<<23|o}}else if(n===31)i=r===0?t<<31|2139095040:t<<31|2143289344;else{let e=n-15+127,a=r<<13;i=t<<31|e<<23|a}return Mt[0]=i,jt[0]}function Ht(e){return Math.max(0,Math.min(255,Math.round(e*255)))}function Ut(e){let t=[],n=new Set;function r(e){e&&typeof e==`object`&&!n.has(e)&&(n.add(e),e instanceof ArrayBuffer?t.push(e):ArrayBuffer.isView(e)?t.push(e.buffer):Array.isArray(e)?e.forEach(r):Object.values(e).forEach(r))}return r(e),t}function Wt(e,t){return Array(e).fill(null).map((e,n)=>t(n))}function Gt(e,t){let n=0;for(let r of e)t(r)||(e[n++]=r);e.length=n}function Kt(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=t*4,[_,v]=e;_[g]=It(n),_[g+1]=It(r),_[g+2]=It(i),_[g+3]=U(f),v[g]=U(p)|U(m)<<16,v[g+1]=U(h)|U(Math.log(a))<<16,v[g+2]=U(Math.log(o))|U(Math.log(s))<<16,v[g+3]=ln(c,l,u,d)}function qt(e,t){let n=Xt,r=t*4,[i,a]=e;return n.center.x=Lt(i[r]),n.center.y=Lt(i[r+1]),n.center.z=Lt(i[r+2]),n.opacity=W(i[r+3]&65535),n.color.r=W(a[r]&65535),n.color.g=W(a[r]>>>16),n.color.b=W(a[r+1]&65535),n.scales.x=Math.exp(W(a[r+1]>>>16)),n.scales.y=Math.exp(W(a[r+2]&65535)),n.scales.z=Math.exp(W(a[r+2]>>>16)),un(a[r+3],n.quaternion),n}function Jt(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g){let _=g?.rgbMin??0,v=(g?.rgbMax??1)-_,y=Ht((p-_)/v),b=Ht((m-_)/v),x=Ht((h-_)/v),ee=Ht(g?.lodOpacity?.5*f:f),te=sn(Yt.set(c,l,u,d)),ne=te&255,S=te>>>8&255,C=te>>>16&255,w=g?.lnScaleMin??-12,re=254/((g?.lnScaleMax??9)-w),ie=a<ct?0:Math.min(255,Math.max(1,Math.round((Math.log(a)-w)*re)+1)),ae=o<ct?0:Math.min(255,Math.max(1,Math.round((Math.log(o)-w)*re)+1)),oe=s<ct?0:Math.min(255,Math.max(1,Math.round((Math.log(s)-w)*re)+1)),se=U(n),ce=U(r),le=U(i),T=t*4;e[T]=y|b<<8|x<<16|ee<<24,e[T+1]=se|ce<<16,e[T+2]=le|ne<<16|S<<24,e[T+3]=ie|ae<<8|oe<<16|C<<24}var Yt=new f,Xt={center:new o,scales:new o,quaternion:new f,color:new S,opacity:0};function Zt(e,t,n){let r=Xt,i=t*4,a=e[i],o=e[i+1],s=e[i+2],c=e[i+3],l=n?.rgbMin??0,u=(n?.rgbMax??1)-l;r.color.set(l+(a&255)/255*u,l+(a>>>8&255)/255*u,l+(a>>>16&255)/255*u),r.opacity=(a>>>24&255)/255,n?.lodOpacity&&(r.opacity=2*r.opacity),r.center.set(W(o&65535),W(o>>>16&65535),W(s&65535));let d=n?.lnScaleMin??-12,f=((n?.lnScaleMax??9)-d)/254,p=c&255;r.scales.x=p===0?0:Math.exp(d+(p-1)*f);let m=c>>>8&255;r.scales.y=m===0?0:Math.exp(d+(m-1)*f);let h=c>>>16&255;return r.scales.z=h===0?0:Math.exp(d+(h-1)*f),cn(s>>>16&65535|c>>>8&16711680,r.quaternion),r}function G(e){let t=M,n=Math.max(1,Math.min(N,Math.ceil(e/t))),r=Math.ceil(e/(t*n));return{width:t,height:n,depth:r,maxSplats:t*n*r}}function Qt(){return navigator.platform.toLowerCase().startsWith(`win`)?!1:navigator.maxTouchPoints>0||/Mobi|Android|iPhone|iPad|iPod|Opera Mini|IEMobile/.test(navigator.userAgent)}function $t(){return/Android/.test(navigator.userAgent)||/Tizen/.test(navigator.userAgent)}function en(){return!!navigator.xr&&/Oculus/.test(navigator.userAgent)}function tn(){return/iPhone|iPad/.test(navigator.userAgent)}function nn(){return!!navigator.xr&&tn()&&/Safari/.test(navigator.userAgent)&&Qt()}var rn=H(`
|
| 4 |
precision highp float;
|
|
|
|
| 1 |
+
import{A as e,B as t,C as n,D as r,E as i,F as a,G as o,H as s,I as c,J as l,K as u,L as d,M as f,N as p,O as m,P as h,R as g,S as _,T as v,U as y,V as b,W as x,_ as ee,a as te,b as ne,c as S,d as C,f as w,g as re,h as ie,i as ae,j as oe,k as se,l as ce,m as le,n as T,o as ue,p as de,q as fe,r as pe,s as me,t as he,u as ge,v as _e,w as ve,x as ye,y as be,z as xe}from"./index-BGZ4TK1u.js";var Se=new e(-1,1,1,-1,0,1),Ce=new class extends ue{constructor(){super(),this.setAttribute(`position`,new ie([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute(`uv`,new ie([0,2,0,0,2,0],2))}},we=class{constructor(e){this._mesh=new i(Ce,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,Se)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}},E=Uint8Array,Te=Uint16Array,Ee=Int32Array,De=new E([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Oe=new E([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),ke=new E([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ae=function(e,t){for(var n=new Te(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var i=new Ee(n[30]),r=1;r<30;++r)for(var a=n[r];a<n[r+1];++a)i[a]=a-n[r]<<5|r;return{b:n,r:i}},je=Ae(De,2),Me=je.b,Ne=je.r;Me[28]=258,Ne[258]=28;var Pe=Ae(Oe,0),Fe=Pe.b;Pe.r;for(var Ie=new Te(32768),D=0;D<32768;++D){var Le=(D&43690)>>1|(D&21845)<<1;Le=(Le&52428)>>2|(Le&13107)<<2,Le=(Le&61680)>>4|(Le&3855)<<4,Ie[D]=((Le&65280)>>8|(Le&255)<<8)>>1}for(var Re=(function(e,t,n){for(var r=e.length,i=0,a=new Te(t);i<r;++i)e[i]&&++a[e[i]-1];var o=new Te(t);for(i=1;i<t;++i)o[i]=o[i-1]+a[i-1]<<1;var s;if(n){s=new Te(1<<t);var c=15-t;for(i=0;i<r;++i)if(e[i])for(var l=i<<4|e[i],u=t-e[i],d=o[e[i]-1]++<<u,f=d|(1<<u)-1;d<=f;++d)s[Ie[d]>>c]=l}else for(s=new Te(r),i=0;i<r;++i)e[i]&&(s[i]=Ie[o[e[i]-1]++]>>15-e[i]);return s}),ze=new E(288),D=0;D<144;++D)ze[D]=8;for(var D=144;D<256;++D)ze[D]=9;for(var D=256;D<280;++D)ze[D]=7;for(var D=280;D<288;++D)ze[D]=8;for(var Be=new E(32),D=0;D<32;++D)Be[D]=5;var Ve=Re(ze,9,1),He=Re(Be,5,1),Ue=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},O=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},We=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},Ge=function(e){return(e+7)/8|0},Ke=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new E(e.subarray(t,n))},qe=[`unexpected EOF`,`invalid block type`,`invalid length/literal`,`invalid distance`,`stream finished`,`no stream handler`,,`no callback`,`invalid UTF-8 data`,`extra field too long`,`date not in range 1980-2099`,`filename too long`,`stream finishing`,`invalid zip data`],k=function(e,t,n){var r=Error(t||qe[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,k),!n)throw r;return r},Je=function(e,t,n,r){var i=e.length,a=r?r.length:0;if(!i||t.f&&!t.l)return n||new E(0);var o=!n,s=o||t.i!=2,c=t.i;o&&(n=new E(i*3));var l=function(e){var t=n.length;if(e>t){var r=new E(Math.max(t*2,e));r.set(n),n=r}},u=t.f||0,d=t.p||0,f=t.b||0,p=t.l,m=t.d,h=t.m,g=t.n,_=i*8;do{if(!p){u=O(e,d,1);var v=O(e,d+1,3);if(d+=3,!v){var y=Ge(d)+4,b=e[y-4]|e[y-3]<<8,x=y+b;if(x>i){c&&k(0);break}s&&l(f+b),n.set(e.subarray(y,x),f),t.b=f+=b,t.p=d=x*8,t.f=u;continue}if(v==1)p=Ve,m=He,h=9,g=5;else if(v==2){var ee=O(e,d,31)+257,te=O(e,d+10,15)+4,ne=ee+O(e,d+5,31)+1;d+=14;for(var S=new E(ne),C=new E(19),w=0;w<te;++w)C[ke[w]]=O(e,d+w*3,7);d+=te*3;for(var re=Ue(C),ie=(1<<re)-1,ae=Re(C,re,1),w=0;w<ne;){var oe=ae[O(e,d,ie)];d+=oe&15;var y=oe>>4;if(y<16)S[w++]=y;else{var se=0,ce=0;for(y==16?(ce=3+O(e,d,3),d+=2,se=S[w-1]):y==17?(ce=3+O(e,d,7),d+=3):y==18&&(ce=11+O(e,d,127),d+=7);ce--;)S[w++]=se}}var le=S.subarray(0,ee),T=S.subarray(ee);h=Ue(le),g=Ue(T),p=Re(le,h,1),m=Re(T,g,1)}else k(1);if(d>_){c&&k(0);break}}s&&l(f+131072);for(var ue=(1<<h)-1,de=(1<<g)-1,fe=d;;fe=d){var se=p[We(e,d)&ue],pe=se>>4;if(d+=se&15,d>_){c&&k(0);break}if(se||k(2),pe<256)n[f++]=pe;else if(pe==256){fe=d,p=null;break}else{var me=pe-254;if(pe>264){var w=pe-257,he=De[w];me=O(e,d,(1<<he)-1)+Me[w],d+=he}var ge=m[We(e,d)&de],_e=ge>>4;ge||k(3),d+=ge&15;var T=Fe[_e];if(_e>3){var he=Oe[_e];T+=We(e,d)&(1<<he)-1,d+=he}if(d>_){c&&k(0);break}s&&l(f+131072);var ve=f+me;if(f<T){var ye=a-T,be=Math.min(T,ve);for(ye+f<0&&k(3);f<be;++f)n[f]=r[ye+f]}for(;f<ve;++f)n[f]=n[f-T]}}t.l=p,t.p=fe,t.b=f,t.f=u,p&&(u=1,t.m=h,t.d=m,t.n=g)}while(!u);return f!=n.length&&o?Ke(n,0,f):n.subarray(0,f)},Ye=new E(0),A=function(e,t){return e[t]|e[t+1]<<8},j=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Xe=function(e,t){return j(e,t)+j(e,t+4)*4294967296},Ze=function(e){(e[0]!=31||e[1]!=139||e[2]!=8)&&k(6,`invalid gzip data`);var t=e[3],n=10;t&4&&(n+=(e[10]|e[11]<<8)+2);for(var r=(t>>3&1)+(t>>4&1);r>0;r-=!e[n++]);return n+(t&2)},Qe=function(){function e(e,t){typeof e==`function`&&(t=e,e={}),this.ondata=t;var n=e&&e.dictionary&&e.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new E(32768),this.p=new E(0),n&&this.o.set(n)}return e.prototype.e=function(e){if(this.ondata||k(5),this.d&&k(4),!this.p.length)this.p=e;else if(e.length){var t=new E(this.p.length+e.length);t.set(this.p),t.set(e,this.p.length),this.p=t}},e.prototype.c=function(e){this.s.i=+(this.d=e||!1);var t=this.s.b,n=Je(this.p,this.s,this.o);this.ondata(Ke(n,t,this.s.b),this.d),this.o=Ke(n,this.s.b-32768),this.s.b=this.o.length,this.p=Ke(this.p,this.s.p/8|0),this.s.p&=7},e.prototype.push=function(e,t){this.e(e),this.c(t)},e}();function $e(e,t){return Je(e,{i:2},t&&t.out,t&&t.dictionary)}var et=function(){function e(e,t){this.v=1,this.r=0,Qe.call(this,e,t)}return e.prototype.push=function(e,t){if(Qe.prototype.e.call(this,e),this.r+=e.length,this.v){var n=this.p.subarray(this.v-1),r=n.length>3?Ze(n):4;if(r>n.length){if(!t)return}else this.v>1&&this.onmember&&this.onmember(this.r-n.length);this.p=n.subarray(r),this.v=0}Qe.prototype.c.call(this,t),this.s.f&&!this.s.l&&!t&&(this.v=Ge(this.s.p)+9,this.s={i:0},this.o=new E(0),this.push(new E(0),t))},e}(),tt=typeof TextDecoder<`u`&&new TextDecoder;try{tt.decode(Ye,{stream:!0})}catch{}var nt=function(e){for(var t=``,n=0;;){var r=e[n++],i=(r>127)+(r>223)+(r>239);if(n+i>e.length)return{s:t,r:Ke(e,n-1)};i?i==3?(r=((r&15)<<18|(e[n++]&63)<<12|(e[n++]&63)<<6|e[n++]&63)-65536,t+=String.fromCharCode(55296|r>>10,56320|r&1023)):i&1?t+=String.fromCharCode((r&31)<<6|e[n++]&63):t+=String.fromCharCode((r&15)<<12|(e[n++]&63)<<6|e[n++]&63):t+=String.fromCharCode(r)}};function rt(e,t){if(t){for(var n=``,r=0;r<e.length;r+=16384)n+=String.fromCharCode.apply(null,e.subarray(r,r+16384));return n}if(tt)return tt.decode(e);var i=nt(e),a=i.s,n=i.r;return n.length&&k(8),a}var it=function(e,t){return t+30+A(e,t+26)+A(e,t+28)},at=function(e,t,n){var r=A(e,t+28),i=rt(e.subarray(t+46,t+46+r),!(A(e,t+8)&2048)),a=t+46+r,o=j(e,t+20),s=n&&o==4294967295?ot(e,a):[o,j(e,t+24),j(e,t+42)],c=s[0],l=s[1],u=s[2];return[A(e,t+10),c,l,i,a+A(e,t+30)+A(e,t+32),u]},ot=function(e,t){for(;A(e,t)!=1;t+=4+A(e,t+2));return[Xe(e,t+12),Xe(e,t+4),Xe(e,t+20)]};function st(e,t){for(var n={},r=e.length-22;j(e,r)!=101010256;--r)(!r||e.length-r>65558)&&k(13);var i=A(e,r+8);if(!i)return{};var a=j(e,r+16),o=a==4294967295||i==65535;if(o){var s=j(e,r-12);o=j(e,s)==101075792,o&&(i=j(e,s+32),a=j(e,s+48))}for(var c=t&&t.filter,l=0;l<i;++l){var u=at(e,a,o),d=u[0],f=u[1],p=u[2],m=u[3],h=u[4],g=u[5],_=it(e,g);a=h,(!c||c({name:m,size:f,originalSize:p,compression:d}))&&(d?d==8?n[m]=$e(e.subarray(_,_+f),{out:new E(p)}):k(14,`unknown compression type `+d):n[m]=Ke(e,_,_+f))}return n}var ct=Math.exp(-30),M=2048,N=2048,P=function(e){return e.PLY=`ply`,e.SPZ=`spz`,e.SPLAT=`splat`,e.KSPLAT=`ksplat`,e.PCSOGS=`pcsogs`,e.PCSOGSZIP=`pcsogszip`,e.RAD=`rad`,e}({}),lt={rgbMin:0,rgbMax:1,lnScaleMin:-12,lnScaleMax:9,sh1Max:1,sh2Max:1,sh3Max:1,lodOpacity:!1};function ut(e){return e===`int`||e===`ivec2`||e===`ivec3`||e===`ivec4`}function dt(e){return e===`uint`||e===`uvec2`||e===`uvec3`||e===`uvec4`}function ft(e){return e===`float`||e===`vec2`||e===`vec3`||e===`vec4`}function pt(e){return e===`mat2`||e===`mat2x2`||e===`mat2x3`||e===`mat2x4`||e===`mat3`||e===`mat3x2`||e===`mat3x3`||e===`mat3x4`||e===`mat4`||e===`mat4x2`||e===`mat4x3`||e===`mat4x4`}function mt(e){return ft(e)||pt(e)}function ht(e){return e===`mat2`||e===`mat2x2`}function gt(e){return e===`mat3`||e===`mat3x3`}function _t(e){return e===`mat4`||e===`mat4x4`}function F(e){return Math.trunc(e).toString()}function I(e){return`${Math.max(0,Math.trunc(e)).toString()}u`}function L(e){return e===1/0?`INFINITY`:e===-1/0?`-INFINITY`:Number.isInteger(e)?e.toFixed(1):e.toString()}function vt(e){return e instanceof yt?e.type:e.dynoOut().type}var yt=class{constructor(e){this.__isDynoValue=!0,this.type=e}},R=class extends yt{constructor(e,t){super(e.outTypes[t]),this.dyno=e,this.key=t}},bt=class extends yt{constructor(e,t){super(e),this.literal=t}getLiteral(){return this.literal}},xt=class extends bt{constructor(e,t){super(e,``),this.value=t}getLiteral(){let{type:e,value:t}=this;switch(e){case`bool`:return t?`true`:`false`;case`uint`:return I(t);case`int`:return F(t);case`float`:return L(t);case`bvec2`:{let e=t;return`bvec2(${e[0]}, ${e[1]})`}case`uvec2`:{if(t instanceof x)return`uvec2(${I(t.x)}, ${I(t.y)})`;let e=t;return`uvec2(${I(e[0])}, ${I(e[1])})`}case`ivec2`:{if(t instanceof x)return`ivec2(${F(t.x)}, ${F(t.y)})`;let e=t;return`ivec2(${F(e[0])}, ${F(e[1])})`}case`vec2`:{if(t instanceof x)return`vec2(${L(t.x)}, ${L(t.y)})`;let e=t;return`vec2(${L(e[0])}, ${L(e[1])})`}case`bvec3`:{let e=t;return`bvec3(${e[0]}, ${e[1]}, ${e[2]})`}case`uvec3`:{if(t instanceof o)return`uvec3(${I(t.x)}, ${I(t.y)}, ${I(t.z)})`;let e=t;return`uvec3(${I(e[0])}, ${I(e[1])}, ${I(e[2])})`}case`ivec3`:{if(t instanceof o)return`ivec3(${F(t.x)}, ${F(t.y)}, ${F(t.z)})`;let e=t;return`ivec3(${F(e[0])}, ${F(e[1])}, ${F(e[2])})`}case`vec3`:{if(t instanceof o)return`vec3(${L(t.x)}, ${L(t.y)}, ${L(t.z)})`;let e=t;return`vec3(${L(e[0])}, ${L(e[1])}, ${L(e[2])})`}case`bvec4`:{let e=t;return`bvec4(${e[0]}, ${e[1]}, ${e[2]}, ${e[3]})`}case`uvec4`:{if(t instanceof u)return`uvec4(${I(t.x)}, ${I(t.y)}, ${I(t.z)}, ${I(t.w)})`;let e=t;return`uvec4(${I(e[0])}, ${I(e[1])}, ${I(e[2])}, ${I(e[3])})`}case`ivec4`:{if(t instanceof u)return`ivec4(${F(t.x)}, ${F(t.y)}, ${F(t.z)}, ${F(t.w)})`;let e=t;return`ivec4(${F(e[0])}, ${F(e[1])}, ${F(e[2])}, ${F(e[3])})`}case`vec4`:{if(t instanceof u||t instanceof f)return`vec4(${L(t.x)}, ${L(t.y)}, ${L(t.z)}, ${L(t.w)})`;let e=t;return`vec4(${L(e[0])}, ${L(e[1])}, ${L(e[2])}, ${L(e[3])})`}case`mat2`:case`mat2x2`:{let r=t,i=r instanceof n?r.elements:t;return`${e}(${[,,,,].fill(0).map((e,t)=>L(i[t])).join(`, `)})`}case`mat2x3`:{let n=t;return`${e}(${[,,,,,,].fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat2x4`:{let n=t;return`${e}(${Array(8).fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat3`:case`mat3x3`:{let n=t,r=n instanceof ve?n.elements:t;return`${e}(${Array(9).fill(0).map((e,t)=>L(r[t])).join(`, `)})`}case`mat3x2`:{let n=t;return`${e}(${[,,,,,,].fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat3x4`:{let n=t;return`${e}(${Array(12).fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat4`:case`mat4x4`:{let n=t,r=n instanceof v?n.elements:t;return`${e}(${Array(16).fill(0).map((e,t)=>L(r[t])).join(`, `)})`}case`mat4x2`:{let n=t;return`${e}(${Array(8).fill(0).map((e,t)=>L(n[t])).join(`, `)})`}case`mat4x3`:{let n=t;return`${e}(${Array(12).fill(0).map((e,t)=>L(n[t])).join(`, `)})`}default:throw Error(`Type not implemented: ${String(e)}`)}}};function St(e,t){return new xt(e,t)}var Ct=` `,wt=class{constructor({indent:e}={}){this.globals=new Set,this.statements=[],this.uniforms={},this.declares=new Set,this.updaters=[],this.sequence=0,this.indent=Ct,this.indent=e??Ct}nextSequence(){return this.sequence++}},z=class{constructor({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,statements:a,generate:o}){this.inTypes=e??{},this.outTypes=t??{},this.inputs=n??{},this.update=r,this.globals=i,this.statements=a,this.generate=o??(({inputs:e,outputs:t,compile:n})=>({globals:this.globals?.({inputs:e,outputs:t,compile:n}),statements:this.statements?.({inputs:e,outputs:t,compile:n})}))}get outputs(){let e={};for(let t in this.outTypes)e[t]=new R(this,t);return e}apply(e){return Object.assign(this.inputs,e),this.outputs}compile({inputs:e,outputs:t,compile:n}){let r=[`// ${this.constructor.name}(${Object.values(e).join(`, `)}) => (${Object.values(t).join(`, `)})`],i=[];for(let e in t){let r=t[e];r&&!n.declares.has(r)&&(n.declares.add(r),i.push(e))}let{globals:a,statements:o,uniforms:s}=this.generate({inputs:e,outputs:t,compile:n});for(let e of a??[])n.globals.add(e);for(let e in s)n.uniforms[e]=s[e];this.update&&n.updaters.push(this.update);for(let e of i){let i=t[e];i&&(n.uniforms[i]||r.push(`${Dt(i,this.outTypes[e])};`))}return o?.length&&(r.push(`{`),r.push(...o.map(e=>n.indent+e)),r.push(`}`)),r}},Tt=class extends z{constructor({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,construct:a}){super({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,generate:e=>this.generateBlock(e)}),this.construct=a}generateBlock({inputs:e,outputs:t,compile:n}){let r={},i={};for(let t in e)e[t]!=null&&(r[t]=new bt(this.inTypes[t],e[t]));for(let e in t)t[e]!=null&&(i[e]=new yt(this.outTypes[e]));let a={roots:[]},o=this.construct(r,i,a);for(let r of this.globals?.({inputs:e,outputs:t,compile:n})??[])n.globals.add(r);let s=[],c=new Map;function l(e,t,r){let i=c.get(e);if(!i){i={sequence:n.nextSequence(),outNames:new Map,newOuts:new Set},c.set(e,i);for(let t in e.inputs){let n=e.inputs[t];for(;n;){if(n instanceof yt){n instanceof R&&l(n.dyno,n.key);break}if(typeof n.dynoOut!=`function`)throw Error(`dynoOut is not a function for ${n.constructor.name}`);n=n.dynoOut()}}s.push(e)}t&&(r||i.newOuts.add(t),i.outNames.set(t,r??`${t}_${i.sequence}`))}for(let e of a.roots)l(e);for(let e in i){let n=o?.[e]??i[e];for(;n;){if(n instanceof yt){n instanceof R&&l(n.dyno,n.key,t[e]);break}n=n.dynoOut()}i[e]=n}let u=[];for(let e of s){let t={},r={};for(let n in e.inputs){let r=e.inputs[n];for(;r;){if(r instanceof yt){if(r instanceof bt)t[n]=r.getLiteral();else if(r instanceof R){let e=c.get(r.dyno)?.outNames.get(r.key);if(!e)throw Error(`Source not found for ${r.dyno.constructor.name}.${r.key}`);t[n]=e}break}r=r.dynoOut()}}let i=c.get(e)??{outNames:new Map};for(let[e,t]of i.outNames.entries())r[e]=t;let a=e.compile({inputs:t,outputs:r,compile:n});u.push(a)}let d=[];for(let e in t)i[e]instanceof bt&&d.push(`${t[e]} = ${i[e].getLiteral()};`);return d.length>0&&u.push(d),{statements:u.flatMap((e,t)=>t===0?e:[``,...e])}}};function B(e,t,n,{update:r,globals:i}={}){return new Tt({inTypes:e,outTypes:t,construct:n,update:r,globals:i})}function Et({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,statements:a,generate:o}){return new z({inTypes:e,outTypes:t,inputs:n,update:r,globals:i,statements:a,generate:o})}function Dt(e,t,n){let r=typeof t==`string`?t:t.type;if(!r)throw Error(`Invalid DynoType: ${String(t)}`);return`${r} ${e}${n==null?``:`[${n}]`}`}function V(e){let t=!1,n=e.split(`
|
| 2 |
`).map(e=>{let n=e.trimEnd();return t?n:n.length>0?(t=!0,n):null}).filter(e=>e!=null);for(;n.length>0&&n[n.length-1].length===0;)n.pop();if(n.length===0)return[];let r=n[0].match(/^\s*/)?.[0];if(!r)return n;let i=RegExp(`^${r}`);return n.map(e=>e.replace(i,``))}function H(e){return V(e).join(`
|
| 3 |
`)}var Ot=class extends z{constructor({a:e,outKey:t,outTypeFunc:n}){let r={a:vt(e)},i=n(vt(e));super({inTypes:r,outTypes:{[t]:i},inputs:{a:e}}),this.outKey=t}dynoOut(){return new R(this,this.outKey)}},kt=class extends z{constructor({a:e,b:t,outKey:n,outTypeFunc:r}){let i={a:vt(e),b:vt(t)},a=r(vt(e),vt(t));super({inTypes:i,outTypes:{[n]:a},inputs:{a:e,b:t}}),this.outKey=n}dynoOut(){return new R(this,this.outKey)}},At=Number.parseInt(`187`)>=179,jt=new Float32Array(1),Mt=new Uint32Array(jt.buffer),Nt=`Float16Array`in globalThis,Pt=Nt?new globalThis.Float16Array(1):null,Ft=new Uint16Array(Pt?.buffer);function It(e){return jt[0]=e,Mt[0]}function Lt(e){return Mt[0]=e,jt[0]}var U=Nt?Rt:zt,W=Nt?Bt:Vt;function Rt(e){return Pt[0]=e,Ft[0]}function zt(e){jt[0]=e;let t=Mt[0],n=t>>31&1,r=t>>23&255,i=t&8388607,a=n<<15;if(r===255)return i===0?a|31744:a|32767;let o=r-127+15;if(o>=31)return a|31744;if(o<=0)return o<-10?a:a|(i|8388608)>>1-o+13;let s=i>>13;return a|o<<10|s}function Bt(e){return Ft[0]=e,Pt[0]}function Vt(e){let t=e>>15&1,n=e>>10&31,r=e&1023,i;if(n===0){if(r===0)i=t<<31;else{let e=r,n=-14;for(;!(e&1024);)e<<=1,n--;e&=1023;let a=n+127,o=e<<13;i=t<<31|a<<23|o}}else if(n===31)i=r===0?t<<31|2139095040:t<<31|2143289344;else{let e=n-15+127,a=r<<13;i=t<<31|e<<23|a}return Mt[0]=i,jt[0]}function Ht(e){return Math.max(0,Math.min(255,Math.round(e*255)))}function Ut(e){let t=[],n=new Set;function r(e){e&&typeof e==`object`&&!n.has(e)&&(n.add(e),e instanceof ArrayBuffer?t.push(e):ArrayBuffer.isView(e)?t.push(e.buffer):Array.isArray(e)?e.forEach(r):Object.values(e).forEach(r))}return r(e),t}function Wt(e,t){return Array(e).fill(null).map((e,n)=>t(n))}function Gt(e,t){let n=0;for(let r of e)t(r)||(e[n++]=r);e.length=n}function Kt(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=t*4,[_,v]=e;_[g]=It(n),_[g+1]=It(r),_[g+2]=It(i),_[g+3]=U(f),v[g]=U(p)|U(m)<<16,v[g+1]=U(h)|U(Math.log(a))<<16,v[g+2]=U(Math.log(o))|U(Math.log(s))<<16,v[g+3]=ln(c,l,u,d)}function qt(e,t){let n=Xt,r=t*4,[i,a]=e;return n.center.x=Lt(i[r]),n.center.y=Lt(i[r+1]),n.center.z=Lt(i[r+2]),n.opacity=W(i[r+3]&65535),n.color.r=W(a[r]&65535),n.color.g=W(a[r]>>>16),n.color.b=W(a[r+1]&65535),n.scales.x=Math.exp(W(a[r+1]>>>16)),n.scales.y=Math.exp(W(a[r+2]&65535)),n.scales.z=Math.exp(W(a[r+2]>>>16)),un(a[r+3],n.quaternion),n}function Jt(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g){let _=g?.rgbMin??0,v=(g?.rgbMax??1)-_,y=Ht((p-_)/v),b=Ht((m-_)/v),x=Ht((h-_)/v),ee=Ht(g?.lodOpacity?.5*f:f),te=sn(Yt.set(c,l,u,d)),ne=te&255,S=te>>>8&255,C=te>>>16&255,w=g?.lnScaleMin??-12,re=254/((g?.lnScaleMax??9)-w),ie=a<ct?0:Math.min(255,Math.max(1,Math.round((Math.log(a)-w)*re)+1)),ae=o<ct?0:Math.min(255,Math.max(1,Math.round((Math.log(o)-w)*re)+1)),oe=s<ct?0:Math.min(255,Math.max(1,Math.round((Math.log(s)-w)*re)+1)),se=U(n),ce=U(r),le=U(i),T=t*4;e[T]=y|b<<8|x<<16|ee<<24,e[T+1]=se|ce<<16,e[T+2]=le|ne<<16|S<<24,e[T+3]=ie|ae<<8|oe<<16|C<<24}var Yt=new f,Xt={center:new o,scales:new o,quaternion:new f,color:new S,opacity:0};function Zt(e,t,n){let r=Xt,i=t*4,a=e[i],o=e[i+1],s=e[i+2],c=e[i+3],l=n?.rgbMin??0,u=(n?.rgbMax??1)-l;r.color.set(l+(a&255)/255*u,l+(a>>>8&255)/255*u,l+(a>>>16&255)/255*u),r.opacity=(a>>>24&255)/255,n?.lodOpacity&&(r.opacity=2*r.opacity),r.center.set(W(o&65535),W(o>>>16&65535),W(s&65535));let d=n?.lnScaleMin??-12,f=((n?.lnScaleMax??9)-d)/254,p=c&255;r.scales.x=p===0?0:Math.exp(d+(p-1)*f);let m=c>>>8&255;r.scales.y=m===0?0:Math.exp(d+(m-1)*f);let h=c>>>16&255;return r.scales.z=h===0?0:Math.exp(d+(h-1)*f),cn(s>>>16&65535|c>>>8&16711680,r.quaternion),r}function G(e){let t=M,n=Math.max(1,Math.min(N,Math.ceil(e/t))),r=Math.ceil(e/(t*n));return{width:t,height:n,depth:r,maxSplats:t*n*r}}function Qt(){return navigator.platform.toLowerCase().startsWith(`win`)?!1:navigator.maxTouchPoints>0||/Mobi|Android|iPhone|iPad|iPod|Opera Mini|IEMobile/.test(navigator.userAgent)}function $t(){return/Android/.test(navigator.userAgent)||/Tizen/.test(navigator.userAgent)}function en(){return!!navigator.xr&&/Oculus/.test(navigator.userAgent)}function tn(){return/iPhone|iPad/.test(navigator.userAgent)}function nn(){return!!navigator.xr&&tn()&&/Safari/.test(navigator.userAgent)&&Qt()}var rn=H(`
|
| 4 |
precision highp float;
|
dist/index.html
CHANGED
|
@@ -6,8 +6,8 @@
|
|
| 6 |
<title>XLeRobot Sim</title>
|
| 7 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='14' fill='%230071e3'/%3E%3Ctext x='32' y='42' font-size='28' font-weight='700' text-anchor='middle' fill='white' font-family='Arial'%3EXL%3C/text%3E%3C/svg%3E" />
|
| 8 |
<meta name="description" content="XLeRobot in your browser: MuJoCo 4.0 physics, MuJoCo-GS-Web's robot and 3D Gaussian splat scenes, a kitchen, a learned policy and an LLM agent." />
|
| 9 |
-
<script type="module" crossorigin src="./assets/index-
|
| 10 |
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
| 11 |
</head>
|
| 12 |
<body>
|
| 13 |
<main class="app">
|
|
@@ -55,6 +55,7 @@
|
|
| 55 |
<button type="button" data-style="toon" aria-pressed="false">Toon</button>
|
| 56 |
<button type="button" data-style="lit" aria-pressed="true">Lit</button>
|
| 57 |
<button type="button" data-style="splat" aria-pressed="false">3DGS</button>
|
|
|
|
| 58 |
</div>
|
| 59 |
<p id="style-note" class="note error" role="status" hidden></p>
|
| 60 |
</section>
|
|
|
|
| 6 |
<title>XLeRobot Sim</title>
|
| 7 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='14' fill='%230071e3'/%3E%3Ctext x='32' y='42' font-size='28' font-weight='700' text-anchor='middle' fill='white' font-family='Arial'%3EXL%3C/text%3E%3C/svg%3E" />
|
| 8 |
<meta name="description" content="XLeRobot in your browser: MuJoCo 4.0 physics, MuJoCo-GS-Web's robot and 3D Gaussian splat scenes, a kitchen, a learned policy and an LLM agent." />
|
| 9 |
+
<script type="module" crossorigin src="./assets/index-BGZ4TK1u.js"></script>
|
| 10 |
+
<link rel="stylesheet" crossorigin href="./assets/index-B0OqpDBS.css">
|
| 11 |
</head>
|
| 12 |
<body>
|
| 13 |
<main class="app">
|
|
|
|
| 55 |
<button type="button" data-style="toon" aria-pressed="false">Toon</button>
|
| 56 |
<button type="button" data-style="lit" aria-pressed="true">Lit</button>
|
| 57 |
<button type="button" data-style="splat" aria-pressed="false">3DGS</button>
|
| 58 |
+
<button type="button" data-style="pixel" aria-pressed="false" title="Pixel art of the 3DGS scene, or of the modelled one where there is none">Pixel</button>
|
| 59 |
</div>
|
| 60 |
<p id="style-note" class="note error" role="status" hidden></p>
|
| 61 |
</section>
|
index.html
CHANGED
|
@@ -53,6 +53,7 @@
|
|
| 53 |
<button type="button" data-style="toon" aria-pressed="false">Toon</button>
|
| 54 |
<button type="button" data-style="lit" aria-pressed="true">Lit</button>
|
| 55 |
<button type="button" data-style="splat" aria-pressed="false">3DGS</button>
|
|
|
|
| 56 |
</div>
|
| 57 |
<p id="style-note" class="note error" role="status" hidden></p>
|
| 58 |
</section>
|
|
|
|
| 53 |
<button type="button" data-style="toon" aria-pressed="false">Toon</button>
|
| 54 |
<button type="button" data-style="lit" aria-pressed="true">Lit</button>
|
| 55 |
<button type="button" data-style="splat" aria-pressed="false">3DGS</button>
|
| 56 |
+
<button type="button" data-style="pixel" aria-pressed="false" title="Pixel art of the 3DGS scene, or of the modelled one where there is none">Pixel</button>
|
| 57 |
</div>
|
| 58 |
<p id="style-note" class="note error" role="status" hidden></p>
|
| 59 |
</section>
|
src/main.js
CHANGED
|
@@ -1,637 +1,643 @@
|
|
| 1 |
-
// XLeRobot Sim: MuJoCo-GS-Web's XLeRobot (and any uploaded robot) in its scenes or the kitchen, with
|
| 2 |
-
// keyboard teleop, skills, a learned policy and an LLM agent; and a Unitree G1 that walks with a learned
|
| 3 |
-
// policy. window.xlerobotSim exposes it all.
|
| 4 |
-
import "./style.css";
|
| 5 |
-
import { SceneView } from "./render/view.js";
|
| 6 |
-
import { fetchRobot, json, mujocoModule, onnxRuntime, progress, readRobotFolder, download, text } from "./core/assets.js";
|
| 7 |
-
import { writeScene } from "./core/compose.js";
|
| 8 |
-
import { Sim } from "./core/sim.js";
|
| 9 |
-
import { TELEOP_KEYS, XLeRobot, XLeRobotTeleop } from "./robots/xlerobot.js";
|
| 10 |
-
import { G1_KEYS, G1Robot, G1Teleop } from "./robots/g1.js";
|
| 11 |
-
import { GenericRobot } from "./robots/generic.js";
|
| 12 |
-
import { SkillRunner, comfortable, homeArm, objectInfo, holding } from "./robots/skills.js";
|
| 13 |
-
import { PolicyRunner } from "./policy/runner.js";
|
| 14 |
-
import { createTools } from "./agent/tools.js";
|
| 15 |
-
import { Agent } from "./agent/agent.js";
|
| 16 |
-
import { DEFAULT_MODEL, HF_ROUTER, routerModels } from "./agent/llm.js";
|
| 17 |
-
import { currentLogin, signIn, signInRequested, signOut } from "./agent/oauth.js";
|
| 18 |
-
|
| 19 |
-
const BASE = import.meta.env.BASE_URL;
|
| 20 |
-
const $ = (id) => document.getElementById(id);
|
| 21 |
-
const store = {
|
| 22 |
-
get: (k, d = null) => {
|
| 23 |
-
try {
|
| 24 |
-
return localStorage.getItem(`xlerobot-sim.${k}`) ?? d;
|
| 25 |
-
} catch {
|
| 26 |
-
return d;
|
| 27 |
-
}
|
| 28 |
-
},
|
| 29 |
-
set: (k, v) => {
|
| 30 |
-
try {
|
| 31 |
-
localStorage.setItem(`xlerobot-sim.${k}`, v);
|
| 32 |
-
} catch {
|
| 33 |
-
// storage blocked: settings last for this visit
|
| 34 |
-
}
|
| 35 |
-
},
|
| 36 |
-
};
|
| 37 |
-
|
| 38 |
-
const app = {
|
| 39 |
-
mujoco: null,
|
| 40 |
-
envs: [],
|
| 41 |
-
robots: [],
|
| 42 |
-
robotData: {}, // id -> fetched robot (xml, meshes, meta)
|
| 43 |
-
envId: null,
|
| 44 |
-
robotId: null,
|
| 45 |
-
sim: null,
|
| 46 |
-
robot: null,
|
| 47 |
-
teleop: null,
|
| 48 |
-
skills: new SkillRunner(),
|
| 49 |
-
settled: null,
|
| 50 |
-
view: null,
|
| 51 |
-
policy: null,
|
| 52 |
-
policyLoading: null,
|
| 53 |
-
walking: {}, // robot id -> promise of its locomotion policy session (ONNX Runtime)
|
| 54 |
-
activity: null, // what is loading, shown on the view when no skill runs
|
| 55 |
-
};
|
| 56 |
-
|
| 57 |
-
function setLoading(message, fraction) {
|
| 58 |
-
$("loading").hidden = false;
|
| 59 |
-
$("loading").classList.remove("failed");
|
| 60 |
-
if (message) $("loading-text").textContent = message;
|
| 61 |
-
if (fraction !== undefined) $("loading-bar").style.width = `${Math.round(fraction * 100)}%`;
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
function showError(error) {
|
| 65 |
-
console.error(error);
|
| 66 |
-
$("loading").hidden = false;
|
| 67 |
-
$("loading-text").textContent = `Could not load: ${error.message}`;
|
| 68 |
-
$("loading").classList.add("failed");
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
// ---------------------------------------------------------------------------------------------
|
| 72 |
-
// Scenes
|
| 73 |
-
|
| 74 |
-
/** The environment's XML, and its decor (a modelled stand-in for its splat) to include, if it has one. */
|
| 75 |
-
async function envSource(env) {
|
| 76 |
-
const dir = env.xml.slice(0, env.xml.lastIndexOf("/") + 1);
|
| 77 |
-
const [xml, decor] = await Promise.all([text(`${BASE}environments/${env.xml}`), env.decor ? download(`${BASE}environments/${dir}${env.decor}`) : null]);
|
| 78 |
-
return decor ? { xml, files: [[env.decor, decor]], includes: [env.decor] } : { xml };
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
/** Compose `envId` with the robot `robotId`, compile, settle and show it. */
|
| 82 |
-
async function loadScene(envId, robotId) {
|
| 83 |
-
const env = app.envs.find((e) => e.id === envId) ?? app.envs[0];
|
| 84 |
-
const robotData = app.robotData[robotId];
|
| 85 |
-
app.skills.cancel("scene changed");
|
| 86 |
-
setLoading(`Building ${env.name} with ${robotData.meta.name}…`);
|
| 87 |
-
await new Promise((r) => requestAnimationFrame(r));
|
| 88 |
-
const withObjects = env.objects === "robot" && robotData.objectsXml;
|
| 89 |
-
const path = writeScene(app.mujoco, "/scene", await envSource(env), { ...robotData, objectsXml: withObjects ? robotData.objectsXml : null }, { modelName: `${env.id}_${robotId}` });
|
| 90 |
-
let model;
|
| 91 |
-
try {
|
| 92 |
-
model = app.mujoco.MjModel.from_xml_path(path);
|
| 93 |
-
} catch (error) {
|
| 94 |
-
throw new Error(`MuJoCo could not compile the scene: ${error.message ?? error}`);
|
| 95 |
-
}
|
| 96 |
-
// A walking robot's policy loads with the scene (once): it has to run from the first step.
|
| 97 |
-
const walking = robotData.meta.controller === "g1" ? await walkingPolicy(robotData) : null;
|
| 98 |
-
app.sim?.dispose();
|
| 99 |
-
const sim = new Sim(app.mujoco, model, { controlHz: 50 });
|
| 100 |
-
const { controller } = robotData.meta;
|
| 101 |
-
const robot = controller === "xlerobot" ? new XLeRobot(sim, robotData.meta) : controller === "g1" ? new G1Robot(sim, robotData.meta, robotData.policyConfig) : new GenericRobot(sim, robotData.meta);
|
| 102 |
-
app.sim = sim;
|
| 103 |
-
app.robot = robot;
|
| 104 |
-
app.envId = env.id;
|
| 105 |
-
app.robotId = robotId;
|
| 106 |
-
app.teleop = robot instanceof XLeRobot ? new XLeRobotTeleop(robot) : robot instanceof G1Robot ? new G1Teleop(robot) : null;
|
| 107 |
-
sim.reset(() => robot.home());
|
| 108 |
-
// Objects settle where the scene drops them; a walking robot stands on its joint servos meanwhile.
|
| 109 |
-
sim.run(robot instanceof G1Robot ? 0.3 : 1.0, () => robot.update());
|
| 110 |
-
if (walking) robot.setPolicy(walking.ort, walking.session);
|
| 111 |
-
sim.steps = 0;
|
| 112 |
-
app.settled = sim.snapshot();
|
| 113 |
-
app.view.splatBase = `${BASE}environments/`;
|
| 114 |
-
// How the robot's rgba values are meant (robot.json "colorSpace"), for its objects too when it brought them.
|
| 115 |
-
const colorSpace = robotData.meta.colorSpace ?? "srgb";
|
| 116 |
-
app.view.setScene(sim, {
|
| 117 |
-
robotRoots: robot.roots ?? (robot.root >= 0 ? [robot.root] : []),
|
| 118 |
-
env,
|
| 119 |
-
cameras: robotData.meta.cameras ?? {},
|
| 120 |
-
robot,
|
| 121 |
-
colorSpaces: { robot: colorSpace, object: withObjects ? colorSpace : "srgb" },
|
| 122 |
-
});
|
| 123 |
-
app.view.frameRobot(robot.pose(), robot instanceof G1Robot ? { distance: 3.0, height: 1.9 } : env.id === "kitchen" ? { distance: 2.4, height: 1.8 } : {});
|
| 124 |
-
if (app.view.style === "splat" && !env.splat) await setStyle("lit");
|
| 125 |
-
else if (app.view.style === "splat") await setStyle(
|
| 126 |
-
refreshSceneUi();
|
| 127 |
-
$("loading").hidden = true;
|
| 128 |
-
const url = new URL(location.href);
|
| 129 |
-
url.searchParams.set("env", env.id);
|
| 130 |
-
history.replaceState(null, "", url);
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
function resetScene() {
|
| 134 |
-
app.skills.cancel("reset");
|
| 135 |
-
app.sim.restore(app.settled);
|
| 136 |
-
app.robot.home();
|
| 137 |
-
app.sim.forward();
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
/** Movable objects: free bodies that are not the robot. */
|
| 141 |
-
function objects() {
|
| 142 |
-
if (!app.sim) return [];
|
| 143 |
-
return app.sim.freeBodies(app.robot?.roots ?? (app.robot?.root >= 0 ? [app.robot.root] : []));
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
/** Height of the highest static box top under a world point, below `below` (for placing things). */
|
| 147 |
-
function surfaceBelow(point, below = Infinity) {
|
| 148 |
-
const { model, data } = app.sim;
|
| 149 |
-
let best = 0;
|
| 150 |
-
for (let g = 0; g < model.ngeom; g++) {
|
| 151 |
-
if (model.geom_type[g] !== 6 || model.body_weldid[model.geom_bodyid[g]] !== 0 || !model.geom_contype[g]) continue;
|
| 152 |
-
const c = data.geom_xpos.subarray(3 * g, 3 * g + 3);
|
| 153 |
-
const R = data.geom_xmat.subarray(9 * g, 9 * g + 9);
|
| 154 |
-
const s = model.geom_size.subarray(3 * g, 3 * g + 3);
|
| 155 |
-
const d = [point[0] - c[0], point[1] - c[1], 0];
|
| 156 |
-
const lx = R[0] * d[0] + R[3] * d[1];
|
| 157 |
-
const ly = R[1] * d[0] + R[4] * d[1];
|
| 158 |
-
if (Math.abs(lx) > s[0] || Math.abs(ly) > s[1]) continue;
|
| 159 |
-
const top = c[2] + Math.abs(R[6]) * s[0] + Math.abs(R[7]) * s[1] + Math.abs(R[8]) * s[2];
|
| 160 |
-
if (top < below && top > best) best = top;
|
| 161 |
-
}
|
| 162 |
-
return best;
|
| 163 |
-
}
|
| 164 |
-
|
| 165 |
-
// ---------------------------------------------------------------------------------------------
|
| 166 |
-
// Renderer, cameras, keys, sliders
|
| 167 |
-
|
| 168 |
-
const styleButtons = [...document.querySelectorAll("[data-style]")];
|
| 169 |
-
const pressStyle = (style) => {
|
| 170 |
-
for (const b of styleButtons) b.setAttribute("aria-pressed", String(b.dataset.style === style));
|
| 171 |
-
};
|
| 172 |
-
|
| 173 |
-
/**
|
| 174 |
-
* Switch renderer: "toon", "lit"
|
| 175 |
-
*
|
| 176 |
-
*
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
if (style === "
|
| 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 |
-
const
|
| 216 |
-
|
| 217 |
-
const
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
setViews(
|
| 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 |
-
const
|
| 276 |
-
const
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
app.walking[id]
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
get
|
| 314 |
-
return app.
|
| 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 |
-
const
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
const
|
| 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 |
-
else if (e.type === "
|
| 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 |
-
app.
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
$("env").
|
| 582 |
-
$("robot").
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
$("
|
| 588 |
-
$("robot
|
| 589 |
-
const
|
| 590 |
-
if (!
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// XLeRobot Sim: MuJoCo-GS-Web's XLeRobot (and any uploaded robot) in its scenes or the kitchen, with
|
| 2 |
+
// keyboard teleop, skills, a learned policy and an LLM agent; and a Unitree G1 that walks with a learned
|
| 3 |
+
// policy. window.xlerobotSim exposes it all.
|
| 4 |
+
import "./style.css";
|
| 5 |
+
import { SceneView } from "./render/view.js";
|
| 6 |
+
import { fetchRobot, json, mujocoModule, onnxRuntime, progress, readRobotFolder, download, text } from "./core/assets.js";
|
| 7 |
+
import { writeScene } from "./core/compose.js";
|
| 8 |
+
import { Sim } from "./core/sim.js";
|
| 9 |
+
import { TELEOP_KEYS, XLeRobot, XLeRobotTeleop } from "./robots/xlerobot.js";
|
| 10 |
+
import { G1_KEYS, G1Robot, G1Teleop } from "./robots/g1.js";
|
| 11 |
+
import { GenericRobot } from "./robots/generic.js";
|
| 12 |
+
import { SkillRunner, comfortable, homeArm, objectInfo, holding } from "./robots/skills.js";
|
| 13 |
+
import { PolicyRunner } from "./policy/runner.js";
|
| 14 |
+
import { createTools } from "./agent/tools.js";
|
| 15 |
+
import { Agent } from "./agent/agent.js";
|
| 16 |
+
import { DEFAULT_MODEL, HF_ROUTER, routerModels } from "./agent/llm.js";
|
| 17 |
+
import { currentLogin, signIn, signInRequested, signOut } from "./agent/oauth.js";
|
| 18 |
+
|
| 19 |
+
const BASE = import.meta.env.BASE_URL;
|
| 20 |
+
const $ = (id) => document.getElementById(id);
|
| 21 |
+
const store = {
|
| 22 |
+
get: (k, d = null) => {
|
| 23 |
+
try {
|
| 24 |
+
return localStorage.getItem(`xlerobot-sim.${k}`) ?? d;
|
| 25 |
+
} catch {
|
| 26 |
+
return d;
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
set: (k, v) => {
|
| 30 |
+
try {
|
| 31 |
+
localStorage.setItem(`xlerobot-sim.${k}`, v);
|
| 32 |
+
} catch {
|
| 33 |
+
// storage blocked: settings last for this visit
|
| 34 |
+
}
|
| 35 |
+
},
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
const app = {
|
| 39 |
+
mujoco: null,
|
| 40 |
+
envs: [],
|
| 41 |
+
robots: [],
|
| 42 |
+
robotData: {}, // id -> fetched robot (xml, meshes, meta)
|
| 43 |
+
envId: null,
|
| 44 |
+
robotId: null,
|
| 45 |
+
sim: null,
|
| 46 |
+
robot: null,
|
| 47 |
+
teleop: null,
|
| 48 |
+
skills: new SkillRunner(),
|
| 49 |
+
settled: null,
|
| 50 |
+
view: null,
|
| 51 |
+
policy: null,
|
| 52 |
+
policyLoading: null,
|
| 53 |
+
walking: {}, // robot id -> promise of its locomotion policy session (ONNX Runtime)
|
| 54 |
+
activity: null, // what is loading, shown on the view when no skill runs
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
function setLoading(message, fraction) {
|
| 58 |
+
$("loading").hidden = false;
|
| 59 |
+
$("loading").classList.remove("failed");
|
| 60 |
+
if (message) $("loading-text").textContent = message;
|
| 61 |
+
if (fraction !== undefined) $("loading-bar").style.width = `${Math.round(fraction * 100)}%`;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function showError(error) {
|
| 65 |
+
console.error(error);
|
| 66 |
+
$("loading").hidden = false;
|
| 67 |
+
$("loading-text").textContent = `Could not load: ${error.message}`;
|
| 68 |
+
$("loading").classList.add("failed");
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ---------------------------------------------------------------------------------------------
|
| 72 |
+
// Scenes
|
| 73 |
+
|
| 74 |
+
/** The environment's XML, and its decor (a modelled stand-in for its splat) to include, if it has one. */
|
| 75 |
+
async function envSource(env) {
|
| 76 |
+
const dir = env.xml.slice(0, env.xml.lastIndexOf("/") + 1);
|
| 77 |
+
const [xml, decor] = await Promise.all([text(`${BASE}environments/${env.xml}`), env.decor ? download(`${BASE}environments/${dir}${env.decor}`) : null]);
|
| 78 |
+
return decor ? { xml, files: [[env.decor, decor]], includes: [env.decor] } : { xml };
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/** Compose `envId` with the robot `robotId`, compile, settle and show it. */
|
| 82 |
+
async function loadScene(envId, robotId) {
|
| 83 |
+
const env = app.envs.find((e) => e.id === envId) ?? app.envs[0];
|
| 84 |
+
const robotData = app.robotData[robotId];
|
| 85 |
+
app.skills.cancel("scene changed");
|
| 86 |
+
setLoading(`Building ${env.name} with ${robotData.meta.name}…`);
|
| 87 |
+
await new Promise((r) => requestAnimationFrame(r));
|
| 88 |
+
const withObjects = env.objects === "robot" && robotData.objectsXml;
|
| 89 |
+
const path = writeScene(app.mujoco, "/scene", await envSource(env), { ...robotData, objectsXml: withObjects ? robotData.objectsXml : null }, { modelName: `${env.id}_${robotId}` });
|
| 90 |
+
let model;
|
| 91 |
+
try {
|
| 92 |
+
model = app.mujoco.MjModel.from_xml_path(path);
|
| 93 |
+
} catch (error) {
|
| 94 |
+
throw new Error(`MuJoCo could not compile the scene: ${error.message ?? error}`);
|
| 95 |
+
}
|
| 96 |
+
// A walking robot's policy loads with the scene (once): it has to run from the first step.
|
| 97 |
+
const walking = robotData.meta.controller === "g1" ? await walkingPolicy(robotData) : null;
|
| 98 |
+
app.sim?.dispose();
|
| 99 |
+
const sim = new Sim(app.mujoco, model, { controlHz: 50 });
|
| 100 |
+
const { controller } = robotData.meta;
|
| 101 |
+
const robot = controller === "xlerobot" ? new XLeRobot(sim, robotData.meta) : controller === "g1" ? new G1Robot(sim, robotData.meta, robotData.policyConfig) : new GenericRobot(sim, robotData.meta);
|
| 102 |
+
app.sim = sim;
|
| 103 |
+
app.robot = robot;
|
| 104 |
+
app.envId = env.id;
|
| 105 |
+
app.robotId = robotId;
|
| 106 |
+
app.teleop = robot instanceof XLeRobot ? new XLeRobotTeleop(robot) : robot instanceof G1Robot ? new G1Teleop(robot) : null;
|
| 107 |
+
sim.reset(() => robot.home());
|
| 108 |
+
// Objects settle where the scene drops them; a walking robot stands on its joint servos meanwhile.
|
| 109 |
+
sim.run(robot instanceof G1Robot ? 0.3 : 1.0, () => robot.update());
|
| 110 |
+
if (walking) robot.setPolicy(walking.ort, walking.session);
|
| 111 |
+
sim.steps = 0;
|
| 112 |
+
app.settled = sim.snapshot();
|
| 113 |
+
app.view.splatBase = `${BASE}environments/`;
|
| 114 |
+
// How the robot's rgba values are meant (robot.json "colorSpace"), for its objects too when it brought them.
|
| 115 |
+
const colorSpace = robotData.meta.colorSpace ?? "srgb";
|
| 116 |
+
app.view.setScene(sim, {
|
| 117 |
+
robotRoots: robot.roots ?? (robot.root >= 0 ? [robot.root] : []),
|
| 118 |
+
env,
|
| 119 |
+
cameras: robotData.meta.cameras ?? {},
|
| 120 |
+
robot,
|
| 121 |
+
colorSpaces: { robot: colorSpace, object: withObjects ? colorSpace : "srgb" },
|
| 122 |
+
});
|
| 123 |
+
app.view.frameRobot(robot.pose(), robot instanceof G1Robot ? { distance: 3.0, height: 1.9 } : env.id === "kitchen" ? { distance: 2.4, height: 1.8 } : {});
|
| 124 |
+
if (app.view.style === "splat" && !env.splat) await setStyle("lit");
|
| 125 |
+
else if (app.view.style === "splat" || app.view.style === "pixel") await setStyle(app.view.style); // this environment's splat
|
| 126 |
+
refreshSceneUi();
|
| 127 |
+
$("loading").hidden = true;
|
| 128 |
+
const url = new URL(location.href);
|
| 129 |
+
url.searchParams.set("env", env.id);
|
| 130 |
+
history.replaceState(null, "", url);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
function resetScene() {
|
| 134 |
+
app.skills.cancel("reset");
|
| 135 |
+
app.sim.restore(app.settled);
|
| 136 |
+
app.robot.home();
|
| 137 |
+
app.sim.forward();
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/** Movable objects: free bodies that are not the robot. */
|
| 141 |
+
function objects() {
|
| 142 |
+
if (!app.sim) return [];
|
| 143 |
+
return app.sim.freeBodies(app.robot?.roots ?? (app.robot?.root >= 0 ? [app.robot.root] : []));
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
/** Height of the highest static box top under a world point, below `below` (for placing things). */
|
| 147 |
+
function surfaceBelow(point, below = Infinity) {
|
| 148 |
+
const { model, data } = app.sim;
|
| 149 |
+
let best = 0;
|
| 150 |
+
for (let g = 0; g < model.ngeom; g++) {
|
| 151 |
+
if (model.geom_type[g] !== 6 || model.body_weldid[model.geom_bodyid[g]] !== 0 || !model.geom_contype[g]) continue;
|
| 152 |
+
const c = data.geom_xpos.subarray(3 * g, 3 * g + 3);
|
| 153 |
+
const R = data.geom_xmat.subarray(9 * g, 9 * g + 9);
|
| 154 |
+
const s = model.geom_size.subarray(3 * g, 3 * g + 3);
|
| 155 |
+
const d = [point[0] - c[0], point[1] - c[1], 0];
|
| 156 |
+
const lx = R[0] * d[0] + R[3] * d[1];
|
| 157 |
+
const ly = R[1] * d[0] + R[4] * d[1];
|
| 158 |
+
if (Math.abs(lx) > s[0] || Math.abs(ly) > s[1]) continue;
|
| 159 |
+
const top = c[2] + Math.abs(R[6]) * s[0] + Math.abs(R[7]) * s[1] + Math.abs(R[8]) * s[2];
|
| 160 |
+
if (top < below && top > best) best = top;
|
| 161 |
+
}
|
| 162 |
+
return best;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
// ---------------------------------------------------------------------------------------------
|
| 166 |
+
// Renderer, cameras, keys, sliders
|
| 167 |
+
|
| 168 |
+
const styleButtons = [...document.querySelectorAll("[data-style]")];
|
| 169 |
+
const pressStyle = (style) => {
|
| 170 |
+
for (const b of styleButtons) b.setAttribute("aria-pressed", String(b.dataset.style === style));
|
| 171 |
+
};
|
| 172 |
+
|
| 173 |
+
/**
|
| 174 |
+
* Switch renderer: "toon", "lit", "splat" or "pixel" (pixel art of the splat, or of the Toon scene where
|
| 175 |
+
* the environment has none). If the 3DGS renderer cannot load, the scene keeps running, in Lit or in
|
| 176 |
+
* Pixel's modelled scene, and the panel says why.
|
| 177 |
+
*/
|
| 178 |
+
async function setStyle(style) {
|
| 179 |
+
const env = app.envs.find((e) => e.id === app.envId);
|
| 180 |
+
if (style === "simple") style = "toon"; // its earlier name, maybe saved in this browser
|
| 181 |
+
if (style === "splat" && !env?.splat) style = "lit";
|
| 182 |
+
pressStyle(style);
|
| 183 |
+
$("style-note").hidden = true;
|
| 184 |
+
let loading = (style === "splat" || style === "pixel") && Boolean(env?.splat);
|
| 185 |
+
if (loading) app.activity = "Loading the 3D Gaussian splat";
|
| 186 |
+
const onBytes = (got, total) => {
|
| 187 |
+
if (loading && total) app.activity = `Loading the 3D Gaussian splat, ${Math.round((100 * got) / total)}%`;
|
| 188 |
+
};
|
| 189 |
+
try {
|
| 190 |
+
await app.view.setStyle(style, { onBytes });
|
| 191 |
+
store.set("style", style);
|
| 192 |
+
} catch (error) {
|
| 193 |
+
console.error(error);
|
| 194 |
+
if (style === "pixel") {
|
| 195 |
+
store.set("style", style);
|
| 196 |
+
$("style-note").textContent = `Could not load the 3DGS scene (${error.message}). Pixel shows the modelled scene instead.`;
|
| 197 |
+
} else {
|
| 198 |
+
await app.view.setStyle("lit");
|
| 199 |
+
pressStyle("lit");
|
| 200 |
+
$("style-note").textContent = `Could not load the 3DGS renderer (${error.message}). Showing Lit instead.`;
|
| 201 |
+
}
|
| 202 |
+
$("style-note").hidden = false;
|
| 203 |
+
} finally {
|
| 204 |
+
if (loading) app.activity = null;
|
| 205 |
+
loading = false; // a download that outlives a failure reports nothing
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
function refreshSceneUi() {
|
| 210 |
+
const env = app.envs.find((e) => e.id === app.envId);
|
| 211 |
+
$("env").value = app.envId;
|
| 212 |
+
$("env-note").textContent = env.description ?? "";
|
| 213 |
+
for (const b of styleButtons) if (b.dataset.style === "splat") b.disabled = !env.splat;
|
| 214 |
+
// Robot cameras
|
| 215 |
+
const cams = app.view.robotCameras;
|
| 216 |
+
$("cameras-section").hidden = Object.keys(cams).length === 0;
|
| 217 |
+
const saved = (store.get("views") ?? "head,right_wrist").split(",");
|
| 218 |
+
$("cameras").innerHTML = Object.entries(cams)
|
| 219 |
+
.map(([name, c]) => `<label><input type="checkbox" data-view="${name}" ${saved.includes(name) ? "checked" : ""}/> ${c.label}</label>`)
|
| 220 |
+
.join("");
|
| 221 |
+
const boxes = [...document.querySelectorAll("[data-view]")];
|
| 222 |
+
// Saved when the visitor ticks a box, not here: a robot without some cameras keeps the choice for others.
|
| 223 |
+
const setViews = (save) => {
|
| 224 |
+
const names = boxes.filter((b) => b.checked).map((b) => b.dataset.view);
|
| 225 |
+
app.view.setViews(names);
|
| 226 |
+
if (save) store.set("views", names.join(","));
|
| 227 |
+
};
|
| 228 |
+
for (const b of boxes) b.addEventListener("change", () => setViews(true));
|
| 229 |
+
setViews(false);
|
| 230 |
+
// Keys or sliders
|
| 231 |
+
const xl = app.robot instanceof XLeRobot;
|
| 232 |
+
const g1 = app.robot instanceof G1Robot;
|
| 233 |
+
$("keys-section").hidden = !xl && !g1;
|
| 234 |
+
$("keys").innerHTML = (g1 ? G1_KEYS : TELEOP_KEYS).map(([k, what]) => `<dt><kbd>${k}</kbd></dt><dd>${what}</dd>`).join("");
|
| 235 |
+
$("sliders-section").hidden = xl || g1;
|
| 236 |
+
if (!xl && !g1) {
|
| 237 |
+
$("sliders").innerHTML = app.robot.actuators
|
| 238 |
+
.map((a) => `<label>${a.name}<input type="range" min="${a.range[0]}" max="${a.range[1]}" step="${(a.range[1] - a.range[0]) / 200}" value="${app.robot.targets[a.id]}" data-act="${a.name}"/></label>`)
|
| 239 |
+
.join("");
|
| 240 |
+
for (const input of $("sliders").querySelectorAll("input")) input.addEventListener("input", () => app.robot.set(input.dataset.act, Number(input.value)));
|
| 241 |
+
}
|
| 242 |
+
for (const b of document.querySelectorAll("[data-skill]")) b.disabled = !xl;
|
| 243 |
+
$("skill-status").textContent = xl ? "" : "Skills, the pick policy and the agent drive XLeRobot; choose it under Scene → Robot.";
|
| 244 |
+
refreshObjects();
|
| 245 |
+
// State table
|
| 246 |
+
$("state").innerHTML = "";
|
| 247 |
+
stateCells = [];
|
| 248 |
+
if (xl) {
|
| 249 |
+
for (const name of Object.keys(app.robot.qpos)) {
|
| 250 |
+
const row = document.createElement("tr");
|
| 251 |
+
row.innerHTML = `<th>${name}</th><td>0</td>`;
|
| 252 |
+
$("state").append(row);
|
| 253 |
+
stateCells.push([name, row.lastChild]);
|
| 254 |
+
}
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
let stateCells = [];
|
| 258 |
+
|
| 259 |
+
function refreshObjects() {
|
| 260 |
+
const list = objects();
|
| 261 |
+
const keep = $("object").value;
|
| 262 |
+
$("object").innerHTML = list.map((o) => `<option value="${o.name}">${o.name}</option>`).join("");
|
| 263 |
+
if (list.some((o) => o.name === keep)) $("object").value = keep;
|
| 264 |
+
const keepTarget = $("place-target").value;
|
| 265 |
+
$("place-target").innerHTML = `<option value="">in front of the robot</option>` + list.map((o) => `<option value="${o.name}">on / in the ${o.name}</option>`).join("");
|
| 266 |
+
if ([...$("place-target").options].some((o) => o.value === keepTarget)) $("place-target").value = keepTarget;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
// ---------------------------------------------------------------------------------------------
|
| 270 |
+
// Policy
|
| 271 |
+
|
| 272 |
+
async function loadPolicy() {
|
| 273 |
+
if (app.policy) return app.policy;
|
| 274 |
+
app.policyLoading ??= (async () => {
|
| 275 |
+
const list = await json(`${BASE}policies/index.json`);
|
| 276 |
+
const entry = list.find((p) => p.robot === "xlerobot");
|
| 277 |
+
if (!entry) throw new Error("no policy for this robot in policies/index.json");
|
| 278 |
+
const dir = `${BASE}policies/${entry.dir}/`;
|
| 279 |
+
const meta = await json(`${dir}policy.json`);
|
| 280 |
+
const status = $("policy-status");
|
| 281 |
+
const track = progress({ ort: 3.8e6, onnx: 17e6 }, (f) => (status.textContent = `Loading the policy… ${Math.round(f * 100)}%`));
|
| 282 |
+
const [ort, bytes] = await Promise.all([onnxRuntime(track("ort")), download(`${dir}${meta.onnx}`, track("onnx"))]);
|
| 283 |
+
app.policy = await PolicyRunner.load(ort, bytes, meta);
|
| 284 |
+
status.textContent = `${meta.name}: ${(meta.parameters / 1e6).toFixed(1)} M parameters, chunks of ${meta.chunk_size} actions at ${meta.fps} Hz, ${meta.n_action_steps} executed per inference.`;
|
| 285 |
+
return app.policy;
|
| 286 |
+
})();
|
| 287 |
+
try {
|
| 288 |
+
return await app.policyLoading;
|
| 289 |
+
} catch (error) {
|
| 290 |
+
app.policyLoading = null;
|
| 291 |
+
$("policy-status").textContent = `Could not load the policy: ${error.message}`;
|
| 292 |
+
throw error;
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
/** A walking robot's locomotion policy: ONNX Runtime and a session on its ONNX file, loaded once. */
|
| 297 |
+
function walkingPolicy(robotData) {
|
| 298 |
+
const id = robotData.name;
|
| 299 |
+
app.walking[id] ??= (async () => {
|
| 300 |
+
const track = progress({ ort: 3.8e6, onnx: 0.9e6 }, (f) => setLoading(`Loading ${robotData.meta.name}'s walking policy…`, f));
|
| 301 |
+
const [ort, bytes] = await Promise.all([onnxRuntime(track("ort")), download(robotData.policyUrl, track("onnx"))]);
|
| 302 |
+
const session = await ort.InferenceSession.create(bytes, { executionProviders: ["wasm"], graphOptimizationLevel: "all" });
|
| 303 |
+
return { ort, session };
|
| 304 |
+
})();
|
| 305 |
+
app.walking[id].catch(() => delete app.walking[id]); // try again next time
|
| 306 |
+
return app.walking[id];
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// ---------------------------------------------------------------------------------------------
|
| 310 |
+
// Skills tab and agent tools
|
| 311 |
+
|
| 312 |
+
const tools = createTools({
|
| 313 |
+
get sim() {
|
| 314 |
+
return app.sim;
|
| 315 |
+
},
|
| 316 |
+
get robot() {
|
| 317 |
+
return app.robot;
|
| 318 |
+
},
|
| 319 |
+
get skills() {
|
| 320 |
+
return app.skills;
|
| 321 |
+
},
|
| 322 |
+
objects,
|
| 323 |
+
loadPolicy,
|
| 324 |
+
surfaceBelow: (p) => surfaceBelow(p),
|
| 325 |
+
snapshot: (name) => app.view.snapshot(name),
|
| 326 |
+
envInfo: () => {
|
| 327 |
+
const env = app.envs.find((e) => e.id === app.envId);
|
| 328 |
+
return `${env.name}: ${env.description}`;
|
| 329 |
+
},
|
| 330 |
+
});
|
| 331 |
+
|
| 332 |
+
async function runSkill(label, promise) {
|
| 333 |
+
$("skill-status").textContent = `${label}…`;
|
| 334 |
+
const result = await promise;
|
| 335 |
+
$("skill-status").textContent = `${label}: ${result.message ?? (result.ok ? "done" : "failed")}`;
|
| 336 |
+
return result;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
for (const button of document.querySelectorAll("[data-skill]")) {
|
| 340 |
+
button.addEventListener("click", async () => {
|
| 341 |
+
const object = $("object").value;
|
| 342 |
+
const kind = button.dataset.skill;
|
| 343 |
+
if (kind === "stop") return app.skills.cancel("stopped");
|
| 344 |
+
if (kind === "go_to") return runSkill(`Go to the ${object}`, tools.call("go_to", { object }));
|
| 345 |
+
if (kind === "pick") return runSkill(`Pick the ${object}`, tools.call("pick", { object }));
|
| 346 |
+
if (kind === "pick_policy") return runSkill(`Policy picks the ${object}`, tools.call("pick", { object, method: "policy" }));
|
| 347 |
+
if (kind === "home") return runSkill("Rest the arms", tools.call("home_arms"));
|
| 348 |
+
if (kind === "place") {
|
| 349 |
+
const side = ["left", "right"].find((s) => objects().some((o) => holding(app.robot, s, o.id)));
|
| 350 |
+
if (!side) return ($("skill-status").textContent = "Neither gripper holds anything.");
|
| 351 |
+
const on = $("place-target").value;
|
| 352 |
+
return runSkill("Place", tools.call("place", on ? { arm: side, on } : { arm: side, forward_m: 0.3, left_m: side === "left" ? 0.05 : -0.05 }));
|
| 353 |
+
}
|
| 354 |
+
});
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
// ---------------------------------------------------------------------------------------------
|
| 358 |
+
// Agent tab
|
| 359 |
+
|
| 360 |
+
const agentSettings = () => {
|
| 361 |
+
const login = app.login;
|
| 362 |
+
const endpoint = $("endpoint").value.trim() || HF_ROUTER;
|
| 363 |
+
const key = $("api-key").value.trim() || (endpoint === HF_ROUTER ? login?.accessToken : "") || "";
|
| 364 |
+
return { baseUrl: endpoint, apiKey: key, model: $("model").value.trim() || DEFAULT_MODEL, vision: $("vision").checked };
|
| 365 |
+
};
|
| 366 |
+
const agent = new Agent(tools, agentSettings);
|
| 367 |
+
|
| 368 |
+
function chatLine(kind, html) {
|
| 369 |
+
const div = document.createElement("div");
|
| 370 |
+
div.className = `msg ${kind}`;
|
| 371 |
+
div.innerHTML = html;
|
| 372 |
+
$("chat").append(div);
|
| 373 |
+
$("chat").scrollTop = $("chat").scrollHeight;
|
| 374 |
+
return div;
|
| 375 |
+
}
|
| 376 |
+
const escapeHtml = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
| 377 |
+
|
| 378 |
+
async function sendToAgent(textIn) {
|
| 379 |
+
const settings = agentSettings();
|
| 380 |
+
if (!settings.apiKey && settings.baseUrl === HF_ROUTER) {
|
| 381 |
+
chatLine("error", "Sign in with Hugging Face, or paste a token under “Model and endpoint”.");
|
| 382 |
+
return;
|
| 383 |
+
}
|
| 384 |
+
chatLine("user", escapeHtml(textIn));
|
| 385 |
+
$("send").disabled = true;
|
| 386 |
+
$("stop-agent").hidden = false;
|
| 387 |
+
$("examples").hidden = true;
|
| 388 |
+
let pending = null;
|
| 389 |
+
await agent.send(textIn, (e) => {
|
| 390 |
+
if (e.type === "assistant") chatLine("assistant", escapeHtml(e.text).replace(/\n/g, "<br>"));
|
| 391 |
+
else if (e.type === "tool") pending = chatLine("tool", `<span class="tool-name">${escapeHtml(e.name)}</span> <span class="tool-args">${escapeHtml(JSON.stringify(e.args))}</span> <span class="tool-result">…</span>`);
|
| 392 |
+
else if (e.type === "result" && pending) {
|
| 393 |
+
const r = e.result;
|
| 394 |
+
const summary = e.name === "observe" ? `${r.objects?.length ?? 0} objects` : r.message ?? (r.ok ? "ok" : "failed");
|
| 395 |
+
pending.querySelector(".tool-result").textContent = `→ ${summary}`;
|
| 396 |
+
pending.classList.toggle("failed", r.ok === false);
|
| 397 |
+
} else if (e.type === "image") chatLine("tool", `<img src="${e.url}" alt="Head camera">`);
|
| 398 |
+
else if (e.type === "error") chatLine("error", escapeHtml(e.message));
|
| 399 |
+
});
|
| 400 |
+
$("send").disabled = false;
|
| 401 |
+
$("stop-agent").hidden = true;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
$("chat-form").addEventListener("submit", (e) => {
|
| 405 |
+
e.preventDefault();
|
| 406 |
+
const t = $("chat-input").value.trim();
|
| 407 |
+
if (!t || agent.busy) return;
|
| 408 |
+
$("chat-input").value = "";
|
| 409 |
+
sendToAgent(t);
|
| 410 |
+
});
|
| 411 |
+
$("chat-input").addEventListener("keydown", (e) => {
|
| 412 |
+
if (e.key === "Enter" && !e.shiftKey) {
|
| 413 |
+
e.preventDefault();
|
| 414 |
+
$("chat-form").requestSubmit();
|
| 415 |
+
}
|
| 416 |
+
});
|
| 417 |
+
$("stop-agent").addEventListener("click", () => {
|
| 418 |
+
agent.stop();
|
| 419 |
+
app.skills.cancel("stopped");
|
| 420 |
+
});
|
| 421 |
+
for (const b of $("examples").querySelectorAll("button")) b.addEventListener("click", () => sendToAgent(b.textContent));
|
| 422 |
+
for (const id of ["model", "endpoint", "api-key"]) {
|
| 423 |
+
$(id).value = store.get(id) ?? "";
|
| 424 |
+
$(id).addEventListener("change", () => store.set(id, $(id).value.trim()));
|
| 425 |
+
}
|
| 426 |
+
$("vision").checked = store.get("vision") === "1";
|
| 427 |
+
$("vision").addEventListener("change", () => store.set("vision", $("vision").checked ? "1" : "0"));
|
| 428 |
+
$("model").placeholder = DEFAULT_MODEL;
|
| 429 |
+
routerModels()
|
| 430 |
+
.then((models) => {
|
| 431 |
+
$("models").innerHTML = models.map((m) => `<option value="${m.id}">${m.vision ? "text + images" : "text"}, $${m.price}/M input</option>`).join("");
|
| 432 |
+
app.models = models;
|
| 433 |
+
const pick = () => {
|
| 434 |
+
const m = models.find((x) => x.id === ($("model").value.trim() || DEFAULT_MODEL));
|
| 435 |
+
if (m && store.get("vision") === null) $("vision").checked = m.vision;
|
| 436 |
+
};
|
| 437 |
+
$("model").addEventListener("change", pick);
|
| 438 |
+
pick();
|
| 439 |
+
})
|
| 440 |
+
.catch(() => {});
|
| 441 |
+
|
| 442 |
+
async function refreshLogin() {
|
| 443 |
+
app.login = await currentLogin();
|
| 444 |
+
$("signed-out").hidden = Boolean(app.login);
|
| 445 |
+
$("signed-in").hidden = !app.login;
|
| 446 |
+
if (app.login) $("hf-user").textContent = app.login.name || "Hugging Face user";
|
| 447 |
+
}
|
| 448 |
+
$("hf-signin").addEventListener("click", () => signIn());
|
| 449 |
+
$("hf-signout").addEventListener("click", () => {
|
| 450 |
+
signOut();
|
| 451 |
+
refreshLogin();
|
| 452 |
+
});
|
| 453 |
+
|
| 454 |
+
// ---------------------------------------------------------------------------------------------
|
| 455 |
+
// Tabs
|
| 456 |
+
|
| 457 |
+
for (const tab of document.querySelectorAll("[data-tab]")) {
|
| 458 |
+
tab.addEventListener("click", () => {
|
| 459 |
+
for (const t of document.querySelectorAll("[data-tab]")) t.setAttribute("aria-selected", String(t === tab));
|
| 460 |
+
for (const p of document.querySelectorAll("[data-panel]")) p.hidden = p.dataset.panel !== tab.dataset.tab;
|
| 461 |
+
store.set("tab", tab.dataset.tab);
|
| 462 |
+
});
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
// ---------------------------------------------------------------------------------------------
|
| 466 |
+
// Keyboard: teleop keys go to the robot unless the focus is in a text field.
|
| 467 |
+
|
| 468 |
+
const teleopCodes = new Map([
|
| 469 |
+
[XLeRobotTeleop, XLeRobotTeleop.codes()],
|
| 470 |
+
[G1Teleop, G1Teleop.codes()],
|
| 471 |
+
]);
|
| 472 |
+
window.addEventListener("keydown", (e) => {
|
| 473 |
+
const t = e.target;
|
| 474 |
+
if (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement) return;
|
| 475 |
+
if (!app.teleop || !teleopCodes.get(app.teleop.constructor)?.has(e.code)) return;
|
| 476 |
+
app.teleop.down.add(e.code);
|
| 477 |
+
e.preventDefault();
|
| 478 |
+
});
|
| 479 |
+
window.addEventListener("keyup", (e) => app.teleop?.down.delete(e.code));
|
| 480 |
+
window.addEventListener("blur", () => app.teleop?.down.clear());
|
| 481 |
+
|
| 482 |
+
// ---------------------------------------------------------------------------------------------
|
| 483 |
+
// Main loop: physics follows the wall clock; control runs every 1/50 s inside it.
|
| 484 |
+
|
| 485 |
+
function control(dt) {
|
| 486 |
+
const { robot, teleop, skills } = app;
|
| 487 |
+
app.view.applyDrag();
|
| 488 |
+
if (skills.running) {
|
| 489 |
+
if (teleop?.engaged) {
|
| 490 |
+
skills.cancel("the keyboard took over");
|
| 491 |
+
} else {
|
| 492 |
+
skills.tick();
|
| 493 |
+
if (skills.waiting) return false; // the policy is still thinking: hold the physics
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
// A walking robot's policy answers asynchronously: the period's keys count once, when it is asked.
|
| 497 |
+
if (!skills.running && teleop && !robot.pending && !robot.ready) teleop.tick(dt);
|
| 498 |
+
return robot.update(dt) !== false; // false: the walking policy is still thinking, hold the physics
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
let last = performance.now();
|
| 502 |
+
let carry = 0;
|
| 503 |
+
|
| 504 |
+
/**
|
| 505 |
+
* Physics for the wall-clock time since the last frame. A policy (the G1's walking, the pick policy)
|
| 506 |
+
* answers asynchronously and the physics waits for it; it answers within microseconds to milliseconds,
|
| 507 |
+
* so a frame waits a few times rather than covering only one control period.
|
| 508 |
+
*/
|
| 509 |
+
async function advance(now) {
|
| 510 |
+
const sim = app.sim;
|
| 511 |
+
const dt = Math.min(0.1, (now - last) / 1000);
|
| 512 |
+
last = now;
|
| 513 |
+
carry += dt;
|
| 514 |
+
const want = Math.floor(carry / sim.timestep);
|
| 515 |
+
let done = 0;
|
| 516 |
+
for (let waits = 0; done < want; waits++) {
|
| 517 |
+
done += sim.runSteps(want - done, control);
|
| 518 |
+
const pending = app.robot?.pending ?? app.skills.pending;
|
| 519 |
+
if (done >= want || !pending || waits >= 12) break;
|
| 520 |
+
await pending;
|
| 521 |
+
if (app.sim !== sim) return; // the scene changed meanwhile
|
| 522 |
+
}
|
| 523 |
+
carry -= done * sim.timestep;
|
| 524 |
+
if (done < want) carry = Math.min(carry, 0.05); // still held: do not race to catch up
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
let frames = 0;
|
| 528 |
+
let fpsTime = last;
|
| 529 |
+
let uiTime = 0;
|
| 530 |
+
let stepping = false;
|
| 531 |
+
async function frame(now) {
|
| 532 |
+
requestAnimationFrame(frame);
|
| 533 |
+
if (!app.sim || stepping) return;
|
| 534 |
+
stepping = true;
|
| 535 |
+
try {
|
| 536 |
+
await advance(now);
|
| 537 |
+
} finally {
|
| 538 |
+
stepping = false;
|
| 539 |
+
}
|
| 540 |
+
if (!app.sim) return;
|
| 541 |
+
app.view.update();
|
| 542 |
+
app.view.render();
|
| 543 |
+
frames++;
|
| 544 |
+
if (now - fpsTime > 1000) {
|
| 545 |
+
$("fps").textContent = `${Math.round((frames * 1000) / (now - fpsTime))} fps`;
|
| 546 |
+
frames = 0;
|
| 547 |
+
fpsTime = now;
|
| 548 |
+
}
|
| 549 |
+
if (now - uiTime > 200) {
|
| 550 |
+
uiTime = now;
|
| 551 |
+
const label = app.skills.label ?? app.activity;
|
| 552 |
+
$("activity").hidden = !label;
|
| 553 |
+
if (label) $("activity").textContent = `${label}…`;
|
| 554 |
+
$("view-labels").innerHTML = app.view
|
| 555 |
+
.viewRects()
|
| 556 |
+
.map((r) => `<span style="left:${r.x + 8}px;top:${r.y + 6}px">${r.label}</span>`)
|
| 557 |
+
.join("");
|
| 558 |
+
if (app.robot instanceof XLeRobot) {
|
| 559 |
+
const q = app.robot.joints();
|
| 560 |
+
for (const [name, cell] of stateCells) cell.textContent = q[name].toFixed(3);
|
| 561 |
+
const sel = objects().find((o) => o.name === $("object").value);
|
| 562 |
+
if (sel) {
|
| 563 |
+
const c = comfortable(app.robot, sel.id);
|
| 564 |
+
$("object-note").textContent = c.plan.reason ? `Out of reach: ${c.plan.reason}.` : `In reach of the ${c.plan.side} arm.`;
|
| 565 |
+
}
|
| 566 |
+
}
|
| 567 |
+
}
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
// ---------------------------------------------------------------------------------------------
|
| 571 |
+
// Boot
|
| 572 |
+
|
| 573 |
+
async function main() {
|
| 574 |
+
app.view = new SceneView($("view"));
|
| 575 |
+
const track = progress({ mujoco: 2.8e6, robot: 1.7e6 }, (f) => setLoading(null, f));
|
| 576 |
+
const [mujoco, envs, robots] = await Promise.all([mujocoModule(track("mujoco")), json(`${BASE}environments/index.json`), json(`${BASE}robots/index.json`)]);
|
| 577 |
+
app.mujoco = mujoco;
|
| 578 |
+
app.envs = envs;
|
| 579 |
+
app.robots = robots;
|
| 580 |
+
app.robotData.xlerobot = await fetchRobot(BASE, "xlerobot", track("robot"));
|
| 581 |
+
$("env").innerHTML = envs.map((e) => `<option value="${e.id}">${e.name}</option>`).join("");
|
| 582 |
+
$("robot").innerHTML = robots.map((r) => `<option value="${r.id}">${r.name}</option>`).join("");
|
| 583 |
+
const wanted = new URL(location.href).searchParams.get("env");
|
| 584 |
+
await loadScene(envs.some((e) => e.id === wanted) ? wanted : envs[0].id, "xlerobot");
|
| 585 |
+
requestAnimationFrame(frame);
|
| 586 |
+
|
| 587 |
+
$("env").addEventListener("change", () => loadScene($("env").value, app.robotId).catch(showError));
|
| 588 |
+
$("robot").addEventListener("change", async () => {
|
| 589 |
+
const id = $("robot").value;
|
| 590 |
+
if (!app.robotData[id]) app.robotData[id] = await fetchRobot(BASE, id);
|
| 591 |
+
loadScene(app.envId, id).catch(showError);
|
| 592 |
+
});
|
| 593 |
+
$("upload-robot").addEventListener("click", () => $("robot-folder").click());
|
| 594 |
+
$("robot-folder").addEventListener("change", async (e) => {
|
| 595 |
+
const files = [...e.target.files];
|
| 596 |
+
if (!files.length) return;
|
| 597 |
+
try {
|
| 598 |
+
const robot = await readRobotFolder(files);
|
| 599 |
+
app.robotData[robot.name] = robot;
|
| 600 |
+
if (![...$("robot").options].some((o) => o.value === robot.name)) $("robot").append(new Option(`${robot.meta.name} (uploaded)`, robot.name));
|
| 601 |
+
$("robot").value = robot.name;
|
| 602 |
+
await loadScene(app.envId, robot.name);
|
| 603 |
+
} catch (error) {
|
| 604 |
+
showError(error);
|
| 605 |
+
setTimeout(() => ($("loading").hidden = true), 4000);
|
| 606 |
+
}
|
| 607 |
+
});
|
| 608 |
+
for (const b of styleButtons) b.addEventListener("click", () => setStyle(b.dataset.style).catch(showError));
|
| 609 |
+
$("reset").addEventListener("click", resetScene);
|
| 610 |
+
const tab = store.get("tab");
|
| 611 |
+
if (tab) document.querySelector(`[data-tab="${tab}"]`)?.click();
|
| 612 |
+
|
| 613 |
+
await refreshLogin();
|
| 614 |
+
if (signInRequested() && !app.login) signIn();
|
| 615 |
+
else if (signInRequested()) document.querySelector('[data-tab="agent"]').click();
|
| 616 |
+
|
| 617 |
+
window.xlerobotSim = {
|
| 618 |
+
ready: true,
|
| 619 |
+
get sim() {
|
| 620 |
+
return app.sim;
|
| 621 |
+
},
|
| 622 |
+
get robot() {
|
| 623 |
+
return app.robot;
|
| 624 |
+
},
|
| 625 |
+
view: app.view,
|
| 626 |
+
skills: app.skills,
|
| 627 |
+
tools,
|
| 628 |
+
agent,
|
| 629 |
+
objects: () => objects().map((o) => o.name),
|
| 630 |
+
observe: () => tools.call("observe"),
|
| 631 |
+
call: (name, args) => tools.call(name, args),
|
| 632 |
+
setEnvironment: (id) => loadScene(id, app.robotId),
|
| 633 |
+
setStyle,
|
| 634 |
+
reset: resetScene,
|
| 635 |
+
loadPolicy,
|
| 636 |
+
objectInfo: (name) => objectInfo(app.sim, app.sim.id("body", name)),
|
| 637 |
+
homeArms: () => app.skills.start("home", homeArm(app.robot, "left")),
|
| 638 |
+
};
|
| 639 |
+
// The saved renderer last: a 3DGS splat downloads while the scene already runs.
|
| 640 |
+
await setStyle(store.get("style") ?? "lit");
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
main().catch(showError);
|
src/render/palette.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// The Pixel renderer's colours: a small palette fitted to what the view shows, as a pixel artist picks
|
| 2 |
+
// colours for a scene. The frame's colours are binned, weighted so that a small bright object counts next
|
| 3 |
+
// to a large wall, and clustered in OKLab (k-means). Between frames the palette follows the view: the
|
| 4 |
+
// clusters move with it, and a colour that is shown badly takes the place of one of two near-identical ones.
|
| 5 |
+
//
|
| 6 |
+
// Colours are kept in a stretched OKLab, chroma times CHROMA, where plain distances pick the nearest
|
| 7 |
+
// colour: hues stay apart in a small palette, at the cost of a little lightness accuracy.
|
| 8 |
+
|
| 9 |
+
export const MAX_COLOURS = 48;
|
| 10 |
+
export const CHROMA = 1.5;
|
| 11 |
+
|
| 12 |
+
const CELLS = 1 << 15; // 5 bits per sRGB channel
|
| 13 |
+
const WEIGHT = 0.5; // a cell counts as its pixel count to this power
|
| 14 |
+
// How the palette is shown: a little more saturated and contrasted, lights warmer and shadows cooler.
|
| 15 |
+
const SATURATION = 1.15;
|
| 16 |
+
const CONTRAST = 0.2;
|
| 17 |
+
const WARMTH = 0.012;
|
| 18 |
+
|
| 19 |
+
const toLinear = (v) => (v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4);
|
| 20 |
+
|
| 21 |
+
function toOklab(r, g, b, out, o) {
|
| 22 |
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
| 23 |
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
| 24 |
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
| 25 |
+
out[o] = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
|
| 26 |
+
out[o + 1] = CHROMA * (1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s);
|
| 27 |
+
out[o + 2] = CHROMA * (0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
function toLinearRgb(L, a, b, out, o) {
|
| 31 |
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
| 32 |
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
| 33 |
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
| 34 |
+
out[o] = Math.min(1, Math.max(0, 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s));
|
| 35 |
+
out[o + 1] = Math.min(1, Math.max(0, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s));
|
| 36 |
+
out[o + 2] = Math.min(1, Math.max(0, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s));
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
export class Palette {
|
| 40 |
+
constructor(size = 32) {
|
| 41 |
+
this.size = Math.min(size, MAX_COLOURS);
|
| 42 |
+
this.count = 0; // colours fitted so far; 0 until the first frame
|
| 43 |
+
this.generation = 0;
|
| 44 |
+
this.matched = new Float32Array(3 * MAX_COLOURS); // what the shader matches against: stretched OKLab
|
| 45 |
+
this.colours = new Float32Array(3 * MAX_COLOURS); // what it draws for each: linear RGB
|
| 46 |
+
this.centres = new Float32Array(3 * MAX_COLOURS); // where the fit says each colour should be
|
| 47 |
+
this.weights = new Float32Array(MAX_COLOURS);
|
| 48 |
+
this.jumped = new Uint8Array(MAX_COLOURS); // colours that changed place, shown at once
|
| 49 |
+
this.counts = new Uint32Array(CELLS);
|
| 50 |
+
this.sums = new Uint32Array(3 * CELLS);
|
| 51 |
+
this.used = new Uint16Array(CELLS);
|
| 52 |
+
this.points = new Float32Array(3 * 4096);
|
| 53 |
+
this.pointWeights = new Float32Array(4096);
|
| 54 |
+
this.errors = new Float32Array(4096);
|
| 55 |
+
this.sumsByColour = new Float64Array(4 * MAX_COLOURS);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/** Forget the colours: the next frame picks them afresh (a new scene or renderer). */
|
| 59 |
+
reset() {
|
| 60 |
+
this.count = 0;
|
| 61 |
+
this.generation++;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Fit the palette to a frame: `pixels` are sRGB bytes, four per pixel. The first fit of a scene starts
|
| 66 |
+
* from the frame's most different colours; later ones adjust the palette they find.
|
| 67 |
+
*/
|
| 68 |
+
fit(pixels) {
|
| 69 |
+
const n = this.#histogram(pixels);
|
| 70 |
+
if (!n) return;
|
| 71 |
+
const cold = this.count === 0;
|
| 72 |
+
if (cold) this.#start(n);
|
| 73 |
+
else if (this.count < this.size && n > this.count) this.#grow(n);
|
| 74 |
+
this.#cluster(n, cold ? 8 : 2);
|
| 75 |
+
for (let round = 0; round < (cold ? 12 : 1); round++) {
|
| 76 |
+
if (!this.#swap(n)) break;
|
| 77 |
+
this.#cluster(n, cold ? 2 : 1);
|
| 78 |
+
}
|
| 79 |
+
if (cold) this.settle();
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/** The frame as weighted points: one per occupied cell of a 32x32x32 sRGB grid. Returns their number. */
|
| 83 |
+
#histogram(pixels) {
|
| 84 |
+
const { counts, sums, used } = this;
|
| 85 |
+
let n = 0;
|
| 86 |
+
for (let i = 0; i + 3 < pixels.length; i += 4) {
|
| 87 |
+
const r = pixels[i];
|
| 88 |
+
const g = pixels[i + 1];
|
| 89 |
+
const b = pixels[i + 2];
|
| 90 |
+
const cell = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);
|
| 91 |
+
if (counts[cell]++ === 0) used[n++] = cell;
|
| 92 |
+
sums[3 * cell] += r;
|
| 93 |
+
sums[3 * cell + 1] += g;
|
| 94 |
+
sums[3 * cell + 2] += b;
|
| 95 |
+
}
|
| 96 |
+
if (n > this.pointWeights.length) {
|
| 97 |
+
this.points = new Float32Array(3 * n);
|
| 98 |
+
this.pointWeights = new Float32Array(n);
|
| 99 |
+
this.errors = new Float32Array(n);
|
| 100 |
+
}
|
| 101 |
+
for (let k = 0; k < n; k++) {
|
| 102 |
+
const cell = used[k];
|
| 103 |
+
const count = counts[cell];
|
| 104 |
+
const scale = 1 / (255 * count);
|
| 105 |
+
toOklab(toLinear(sums[3 * cell] * scale), toLinear(sums[3 * cell + 1] * scale), toLinear(sums[3 * cell + 2] * scale), this.points, 3 * k);
|
| 106 |
+
this.pointWeights[k] = count ** WEIGHT;
|
| 107 |
+
counts[cell] = 0;
|
| 108 |
+
sums[3 * cell] = sums[3 * cell + 1] = sums[3 * cell + 2] = 0;
|
| 109 |
+
}
|
| 110 |
+
return n;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/** The first colours: the commonest, then each time the one the colours so far show worst. */
|
| 114 |
+
#start(n) {
|
| 115 |
+
const { points, pointWeights, centres, errors } = this;
|
| 116 |
+
this.count = Math.min(this.size, n);
|
| 117 |
+
let next = 0;
|
| 118 |
+
for (let k = 1; k < n; k++) if (pointWeights[k] > pointWeights[next]) next = k;
|
| 119 |
+
errors.fill(Infinity, 0, n);
|
| 120 |
+
for (let j = 0; j < this.count; j++) {
|
| 121 |
+
centres.set(points.subarray(3 * next, 3 * next + 3), 3 * j);
|
| 122 |
+
this.jumped[j] = 1;
|
| 123 |
+
let worst = -1;
|
| 124 |
+
let worstError = -1;
|
| 125 |
+
for (let k = 0; k < n; k++) {
|
| 126 |
+
const d = distance2(points, 3 * k, centres, 3 * j);
|
| 127 |
+
if (d < errors[k]) errors[k] = d;
|
| 128 |
+
const e = pointWeights[k] * errors[k];
|
| 129 |
+
if (e > worstError) {
|
| 130 |
+
worstError = e;
|
| 131 |
+
worst = k;
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
next = worst;
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/** A frame with few colours left the palette short: add the colours shown worst. */
|
| 139 |
+
#grow(n) {
|
| 140 |
+
this.#cluster(n, 1);
|
| 141 |
+
while (this.count < Math.min(this.size, n)) {
|
| 142 |
+
const k = this.#worst(n);
|
| 143 |
+
this.centres.set(this.points.subarray(3 * k, 3 * k + 3), 3 * this.count);
|
| 144 |
+
this.jumped[this.count++] = 1;
|
| 145 |
+
this.errors[k] = 0;
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
#worst(n) {
|
| 150 |
+
let worst = 0;
|
| 151 |
+
for (let k = 1; k < n; k++) if (this.errors[k] > this.errors[worst]) worst = k;
|
| 152 |
+
return worst;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/** k-means steps: every point to its nearest colour, every colour to the weighted mean of its points. */
|
| 156 |
+
#cluster(n, steps) {
|
| 157 |
+
const { points, pointWeights, centres, errors, weights, sumsByColour: sums } = this;
|
| 158 |
+
const K = this.count;
|
| 159 |
+
for (let step = 0; step < steps; step++) {
|
| 160 |
+
sums.fill(0);
|
| 161 |
+
for (let k = 0; k < n; k++) {
|
| 162 |
+
const x = points[3 * k];
|
| 163 |
+
const y = points[3 * k + 1];
|
| 164 |
+
const z = points[3 * k + 2];
|
| 165 |
+
let best = 0;
|
| 166 |
+
let bestD = Infinity;
|
| 167 |
+
for (let j = 0; j < K; j++) {
|
| 168 |
+
const dx = x - centres[3 * j];
|
| 169 |
+
const dy = y - centres[3 * j + 1];
|
| 170 |
+
const dz = z - centres[3 * j + 2];
|
| 171 |
+
const d = dx * dx + dy * dy + dz * dz;
|
| 172 |
+
if (d < bestD) {
|
| 173 |
+
bestD = d;
|
| 174 |
+
best = j;
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
const w = pointWeights[k];
|
| 178 |
+
errors[k] = w * bestD;
|
| 179 |
+
sums[4 * best] += w * x;
|
| 180 |
+
sums[4 * best + 1] += w * y;
|
| 181 |
+
sums[4 * best + 2] += w * z;
|
| 182 |
+
sums[4 * best + 3] += w;
|
| 183 |
+
}
|
| 184 |
+
for (let j = 0; j < K; j++) {
|
| 185 |
+
const w = sums[4 * j + 3];
|
| 186 |
+
weights[j] = w;
|
| 187 |
+
if (w > 0) {
|
| 188 |
+
centres[3 * j] = sums[4 * j] / w;
|
| 189 |
+
centres[3 * j + 1] = sums[4 * j + 1] / w;
|
| 190 |
+
centres[3 * j + 2] = sums[4 * j + 2] / w;
|
| 191 |
+
} else {
|
| 192 |
+
// Nothing on screen has this colour any more: it goes to the colour shown worst.
|
| 193 |
+
const k = this.#worst(n);
|
| 194 |
+
centres.set(points.subarray(3 * k, 3 * k + 3), 3 * j);
|
| 195 |
+
errors[k] = 0;
|
| 196 |
+
this.jumped[j] = 1;
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
/**
|
| 203 |
+
* Give the colour shown worst a place of its own, taken from the two colours most alike (merged into
|
| 204 |
+
* one), when the frame is shown better that way. This is how a small object of a new colour gets it.
|
| 205 |
+
*/
|
| 206 |
+
#swap(n) {
|
| 207 |
+
const { centres, weights } = this;
|
| 208 |
+
const K = this.count;
|
| 209 |
+
if (K < 3) return false;
|
| 210 |
+
const k = this.#worst(n);
|
| 211 |
+
let cost = Infinity;
|
| 212 |
+
let a = -1;
|
| 213 |
+
let b = -1;
|
| 214 |
+
for (let i = 0; i < K; i++) {
|
| 215 |
+
for (let j = i + 1; j < K; j++) {
|
| 216 |
+
const total = weights[i] + weights[j];
|
| 217 |
+
const c = total > 0 ? ((weights[i] * weights[j]) / total) * distance2(centres, 3 * i, centres, 3 * j) : 0;
|
| 218 |
+
if (c < cost) {
|
| 219 |
+
cost = c;
|
| 220 |
+
a = i;
|
| 221 |
+
b = j;
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
if (this.errors[k] <= 2 * cost) return false;
|
| 226 |
+
const total = weights[a] + weights[b];
|
| 227 |
+
const [keep, drop] = weights[a] >= weights[b] ? [a, b] : [b, a];
|
| 228 |
+
if (total > 0) for (let c = 0; c < 3; c++) centres[3 * keep + c] = (weights[a] * centres[3 * a + c] + weights[b] * centres[3 * b + c]) / total;
|
| 229 |
+
centres.set(this.points.subarray(3 * k, 3 * k + 3), 3 * drop);
|
| 230 |
+
this.jumped[drop] = 1;
|
| 231 |
+
return true;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
/** Show the fitted colours at once. */
|
| 235 |
+
settle() {
|
| 236 |
+
this.jumped.fill(1);
|
| 237 |
+
this.ease(0);
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/** Move the shown colours toward the fitted ones: `dt` seconds have passed. Colours that changed place jump. */
|
| 241 |
+
ease(dt) {
|
| 242 |
+
const k = 1 - Math.exp(-dt / 0.15);
|
| 243 |
+
for (let j = 0; j < this.count; j++) {
|
| 244 |
+
const f = this.jumped[j] ? 1 : k;
|
| 245 |
+
this.jumped[j] = 0;
|
| 246 |
+
for (let c = 0; c < 3; c++) this.matched[3 * j + c] += f * (this.centres[3 * j + c] - this.matched[3 * j + c]);
|
| 247 |
+
const L = this.matched[3 * j];
|
| 248 |
+
const light = 2 * L - 1;
|
| 249 |
+
const a = (this.matched[3 * j + 1] / CHROMA) * SATURATION - 0.4 * WARMTH * light;
|
| 250 |
+
const b = (this.matched[3 * j + 2] / CHROMA) * SATURATION + WARMTH * light;
|
| 251 |
+
toLinearRgb(L + CONTRAST * (L - 0.5) * (1 - Math.abs(light)), a, b, this.colours, 3 * j);
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
function distance2(p, i, q, j) {
|
| 257 |
+
const dx = p[i] - q[j];
|
| 258 |
+
const dy = p[i + 1] - q[j + 1];
|
| 259 |
+
const dz = p[i + 2] - q[j + 2];
|
| 260 |
+
return dx * dx + dy * dy + dz * dz;
|
| 261 |
+
}
|
src/render/pixel.js
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// The Pixel renderer: pixel art of whatever the scene shows, a 3D Gaussian splat included. Each view is
|
| 2 |
+
// drawn small (about 240 pixels high), every pixel takes one of a few colours fitted to what that view
|
| 3 |
+
// shows (palette.js), in-between colours become an ordered dither of the two nearest ones, and the result
|
| 4 |
+
// is scaled up by a whole number of screen pixels. Robots and objects get an ink line around them: meshes
|
| 5 |
+
// drawn this small need one to read against the splat.
|
| 6 |
+
//
|
| 7 |
+
// A view is first drawn with 2x2 samples per pixel, and each pixel then takes one of its four samples, never
|
| 8 |
+
// a blend: the colours stay those of the scene, while a line thinner than a pixel is drawn whole or not at
|
| 9 |
+
// all (sampled once per pixel it would come out dotted, and crawl when the camera moves).
|
| 10 |
+
import * as THREE from "three";
|
| 11 |
+
import { CHROMA, MAX_COLOURS, Palette } from "./palette.js";
|
| 12 |
+
|
| 13 |
+
/** Layers of the meshes that get an ink line, and of those that only hide it (the splat's stand-in). */
|
| 14 |
+
export const OUTLINED = 1;
|
| 15 |
+
export const OCCLUDER = 2;
|
| 16 |
+
|
| 17 |
+
const REFIT_MS = 250; // between updates of a view's palette
|
| 18 |
+
|
| 19 |
+
const VERTEX = /* glsl */ `
|
| 20 |
+
varying vec2 vUv;
|
| 21 |
+
void main() {
|
| 22 |
+
vUv = uv;
|
| 23 |
+
gl_Position = vec4(position.xy, 0.0, 1.0);
|
| 24 |
+
}`;
|
| 25 |
+
|
| 26 |
+
// One pixel from its 2x2 samples. The nearest surface among them takes the pixel, so a thin part of the
|
| 27 |
+
// robot is not lost; of that surface's samples, the one closest to their mean colour is kept. The alpha
|
| 28 |
+
// channel says whether that surface is an outlined mesh, and the depth is that of its nearest sample.
|
| 29 |
+
const RESOLVE = /* glsl */ `
|
| 30 |
+
uniform sampler2D tScene;
|
| 31 |
+
uniform sampler2D tMask;
|
| 32 |
+
uniform sampler2D tDepth;
|
| 33 |
+
uniform vec2 texel;
|
| 34 |
+
uniform float near;
|
| 35 |
+
uniform float far;
|
| 36 |
+
uniform bool edges;
|
| 37 |
+
varying vec2 vUv;
|
| 38 |
+
|
| 39 |
+
void main() {
|
| 40 |
+
vec2 o = 0.5 * texel;
|
| 41 |
+
vec2 at[4] = vec2[4](vUv - o, vUv + vec2(o.x, -o.y), vUv + vec2(-o.x, o.y), vUv + o);
|
| 42 |
+
float depth[4];
|
| 43 |
+
int nearest = 0;
|
| 44 |
+
for (int i = 0; i < 4; i++) {
|
| 45 |
+
depth[i] = edges ? texture2D(tDepth, at[i]).x : 1.0;
|
| 46 |
+
if (depth[i] < depth[nearest]) nearest = i;
|
| 47 |
+
}
|
| 48 |
+
// One over the distance is linear in the depth value; the same surface: within 3% of the nearest.
|
| 49 |
+
float scale = 1.0 / near - 1.0 / far;
|
| 50 |
+
float limit = (1.0 / near - depth[nearest] * scale) * 0.97;
|
| 51 |
+
vec3 colour[4];
|
| 52 |
+
vec3 mean = vec3(0.0);
|
| 53 |
+
float n = 0.0;
|
| 54 |
+
for (int i = 0; i < 4; i++) {
|
| 55 |
+
colour[i] = sqrt(texture2D(tScene, at[i]).rgb);
|
| 56 |
+
if (1.0 / near - depth[i] * scale < limit) continue;
|
| 57 |
+
mean += colour[i];
|
| 58 |
+
n += 1.0;
|
| 59 |
+
}
|
| 60 |
+
mean /= n;
|
| 61 |
+
int pick = nearest;
|
| 62 |
+
float best = 1e9;
|
| 63 |
+
for (int i = 0; i < 4; i++) {
|
| 64 |
+
if (1.0 / near - depth[i] * scale < limit) continue;
|
| 65 |
+
vec3 d = colour[i] - mean;
|
| 66 |
+
float dd = dot(d, d);
|
| 67 |
+
if (dd < best) {
|
| 68 |
+
best = dd;
|
| 69 |
+
pick = i;
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
gl_FragColor = vec4(colour[pick] * colour[pick], edges ? texture2D(tMask, at[nearest]).r : 0.0);
|
| 73 |
+
gl_FragDepth = depth[nearest];
|
| 74 |
+
}`;
|
| 75 |
+
|
| 76 |
+
const QUANTISE = /* glsl */ `
|
| 77 |
+
#include <packing>
|
| 78 |
+
uniform sampler2D tPicked;
|
| 79 |
+
uniform sampler2D tDepth;
|
| 80 |
+
uniform vec2 texel;
|
| 81 |
+
uniform float near;
|
| 82 |
+
uniform float far;
|
| 83 |
+
uniform vec3 matched[MAX_COLOURS];
|
| 84 |
+
uniform vec3 colours[MAX_COLOURS];
|
| 85 |
+
uniform int count;
|
| 86 |
+
uniform float sharpness;
|
| 87 |
+
uniform bool edges;
|
| 88 |
+
uniform vec3 ink;
|
| 89 |
+
varying vec2 vUv;
|
| 90 |
+
|
| 91 |
+
const float BAYER[16] = float[16](0.0, 8.0, 2.0, 10.0, 12.0, 4.0, 14.0, 6.0, 3.0, 11.0, 1.0, 9.0, 15.0, 7.0, 13.0, 5.0);
|
| 92 |
+
|
| 93 |
+
vec3 oklab(vec3 c) {
|
| 94 |
+
vec3 lms = mat3(0.4122214708, 0.2119034982, 0.0883024619, 0.5363325363, 0.6806995451, 0.2817188376, 0.0514459929, 0.1073969566, 0.6299787005) * c;
|
| 95 |
+
lms = pow(max(lms, 0.0), vec3(1.0 / 3.0));
|
| 96 |
+
vec3 lab = mat3(0.2104542553, 1.9779984951, 0.0259040371, 0.7936177850, -2.4285922050, 0.7827717662, -0.0040720468, 0.4505937099, -0.8086757660) * lms;
|
| 97 |
+
return vec3(lab.x, lab.yz * CHROMA);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// One over the distance: it changes evenly across a flat surface, however steeply the surface is seen.
|
| 101 |
+
float nearness(vec2 uv) { return -1.0 / perspectiveDepthToViewZ(texture2D(tDepth, uv).x, near, far); }
|
| 102 |
+
|
| 103 |
+
// Whether an outlined surface next to this pixel, toward d, stands in front of it. Both surfaces are
|
| 104 |
+
// carried on, each with its own slope, to the point half way between the two pixels: a step leaves a gap
|
| 105 |
+
// there, while two faces meeting in a crease (a worktop against a wall) leave at most half the difference
|
| 106 |
+
// of their slopes. The line is drawn on the far side, around the shape.
|
| 107 |
+
float inFront(vec2 d, float here) {
|
| 108 |
+
float front = nearness(vUv + d);
|
| 109 |
+
float slopeFront = nearness(vUv + 2.0 * d) - front;
|
| 110 |
+
float slopeHere = here - nearness(vUv - d);
|
| 111 |
+
float gap = (front - 0.5 * slopeFront) - (here + 0.5 * slopeHere);
|
| 112 |
+
return texture2D(tPicked, vUv + d).a * step(0.6 * (abs(slopeFront) + abs(slopeHere)) + 0.02 * front, gap);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
void main() {
|
| 116 |
+
vec3 colour = texture2D(tPicked, vUv).rgb;
|
| 117 |
+
float line = 0.0;
|
| 118 |
+
if (edges) {
|
| 119 |
+
float here = nearness(vUv);
|
| 120 |
+
vec2 dx = vec2(texel.x, 0.0);
|
| 121 |
+
vec2 dy = vec2(0.0, texel.y);
|
| 122 |
+
line = min(1.0, inFront(dx, here) + inFront(-dx, here) + inFront(dy, here) + inFront(-dy, here));
|
| 123 |
+
}
|
| 124 |
+
if (count > 1) {
|
| 125 |
+
// The two nearest palette colours, and how far the colour lies from the first toward the second
|
| 126 |
+
// (never past half way). Past a point the pixel takes the second colour on part of a 4x4 pattern.
|
| 127 |
+
vec3 lab = oklab(colour);
|
| 128 |
+
float d1 = 1e9;
|
| 129 |
+
float d2 = 1e9;
|
| 130 |
+
int i1 = 0;
|
| 131 |
+
int i2 = 0;
|
| 132 |
+
for (int i = 0; i < MAX_COLOURS; i++) {
|
| 133 |
+
if (i >= count) break;
|
| 134 |
+
vec3 d = lab - matched[i];
|
| 135 |
+
float dd = dot(d, d);
|
| 136 |
+
if (dd < d1) {
|
| 137 |
+
d2 = d1;
|
| 138 |
+
i2 = i1;
|
| 139 |
+
d1 = dd;
|
| 140 |
+
i1 = i;
|
| 141 |
+
} else if (dd < d2) {
|
| 142 |
+
d2 = dd;
|
| 143 |
+
i2 = i;
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
vec3 span = matched[i2] - matched[i1];
|
| 147 |
+
float t = dot(lab - matched[i1], span) / max(dot(span, span), 1e-6);
|
| 148 |
+
ivec2 cell = ivec2(gl_FragCoord.xy) & 3;
|
| 149 |
+
float threshold = (BAYER[cell.x + 4 * cell.y] + 0.5) / 16.0;
|
| 150 |
+
colour = (t - 0.5) * sharpness + 0.5 > threshold ? colours[i2] : colours[i1];
|
| 151 |
+
}
|
| 152 |
+
gl_FragColor = vec4(mix(colour, ink, line), 1.0);
|
| 153 |
+
#include <colorspace_fragment>
|
| 154 |
+
}`;
|
| 155 |
+
|
| 156 |
+
const COPY = /* glsl */ `
|
| 157 |
+
uniform sampler2D tPixels;
|
| 158 |
+
varying vec2 vUv;
|
| 159 |
+
void main() {
|
| 160 |
+
gl_FragColor = texture2D(tPixels, vUv);
|
| 161 |
+
#include <colorspace_fragment>
|
| 162 |
+
}`;
|
| 163 |
+
|
| 164 |
+
export class PixelPass {
|
| 165 |
+
/**
|
| 166 |
+
* `rows`: about how many pixels high the main view is drawn; `colours`: the palette's size (48 at most);
|
| 167 |
+
* `sharpness`: 1 dithers all the way between two colours, more keeps the dither to where they meet.
|
| 168 |
+
*/
|
| 169 |
+
constructor({ rows = 240, colours = 32, sharpness = 2, ink = 0x16141f } = {}) {
|
| 170 |
+
this.rows = rows;
|
| 171 |
+
this.size = colours;
|
| 172 |
+
this.views = new Map(); // per view: its render targets and its palette
|
| 173 |
+
this.solid = new THREE.MeshBasicMaterial({ color: 0xffffff });
|
| 174 |
+
this.hidden = new THREE.MeshBasicMaterial({ colorWrite: false });
|
| 175 |
+
const options = { vertexShader: VERTEX, depthTest: false, depthWrite: false };
|
| 176 |
+
this.resolve = new THREE.ShaderMaterial({
|
| 177 |
+
vertexShader: VERTEX,
|
| 178 |
+
depthFunc: THREE.AlwaysDepth, // the pass writes each pixel's depth
|
| 179 |
+
uniforms: {
|
| 180 |
+
tScene: { value: null },
|
| 181 |
+
tMask: { value: null },
|
| 182 |
+
tDepth: { value: null },
|
| 183 |
+
texel: { value: new THREE.Vector2() },
|
| 184 |
+
near: { value: 0.1 },
|
| 185 |
+
far: { value: 100 },
|
| 186 |
+
edges: { value: false },
|
| 187 |
+
},
|
| 188 |
+
fragmentShader: RESOLVE,
|
| 189 |
+
});
|
| 190 |
+
this.quantise = new THREE.ShaderMaterial({
|
| 191 |
+
...options,
|
| 192 |
+
defines: { MAX_COLOURS, CHROMA: CHROMA.toFixed(3) },
|
| 193 |
+
uniforms: {
|
| 194 |
+
tPicked: { value: null },
|
| 195 |
+
tDepth: { value: null },
|
| 196 |
+
texel: { value: new THREE.Vector2() },
|
| 197 |
+
near: { value: 0.1 },
|
| 198 |
+
far: { value: 100 },
|
| 199 |
+
matched: { value: null },
|
| 200 |
+
colours: { value: null },
|
| 201 |
+
count: { value: 0 },
|
| 202 |
+
sharpness: { value: sharpness },
|
| 203 |
+
edges: { value: false },
|
| 204 |
+
ink: { value: new THREE.Color(ink) },
|
| 205 |
+
},
|
| 206 |
+
fragmentShader: QUANTISE,
|
| 207 |
+
});
|
| 208 |
+
this.copy = new THREE.ShaderMaterial({ ...options, uniforms: { tPixels: { value: null } }, fragmentShader: COPY });
|
| 209 |
+
this.quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), this.quantise);
|
| 210 |
+
this.quad.frustumCulled = false;
|
| 211 |
+
this.screen = new THREE.Scene();
|
| 212 |
+
this.screen.add(this.quad);
|
| 213 |
+
this.screenCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
| 214 |
+
this.clear = new THREE.Color();
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
/** The size of each view's palette. */
|
| 218 |
+
get colours() {
|
| 219 |
+
return this.size;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
set colours(n) {
|
| 223 |
+
this.size = Math.max(2, Math.min(MAX_COLOURS, Math.round(n)));
|
| 224 |
+
for (const view of this.views.values()) {
|
| 225 |
+
view.palette.size = this.size;
|
| 226 |
+
view.palette.reset();
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
get sharpness() {
|
| 231 |
+
return this.quantise.uniforms.sharpness.value;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
set sharpness(v) {
|
| 235 |
+
this.quantise.uniforms.sharpness.value = v;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/** Pick the colours afresh on the next frame (a new scene or look). */
|
| 239 |
+
reset() {
|
| 240 |
+
for (const view of this.views.values()) view.palette.reset();
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
/** Screen pixels to one drawn pixel, for a view filling the canvas. */
|
| 244 |
+
scale(renderer) {
|
| 245 |
+
return Math.max(2, Math.round(renderer.domElement.height / this.rows));
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
#viewFor(key, w, h) {
|
| 249 |
+
let view = this.views.get(key);
|
| 250 |
+
if (!view) {
|
| 251 |
+
const nearest = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, generateMipmaps: false };
|
| 252 |
+
const srgb = { ...nearest, colorSpace: THREE.SRGBColorSpace };
|
| 253 |
+
view = {
|
| 254 |
+
// The scene with 2x2 samples per pixel, and which of them show an outlined mesh, with their depth.
|
| 255 |
+
scene: new THREE.WebGLRenderTarget(2 * w, 2 * h, srgb),
|
| 256 |
+
mask: new THREE.WebGLRenderTarget(2 * w, 2 * h, { ...nearest, depthTexture: new THREE.DepthTexture(2 * w, 2 * h) }),
|
| 257 |
+
// One sample per pixel, then the pixels in the palette's colours.
|
| 258 |
+
picked: new THREE.WebGLRenderTarget(w, h, { ...srgb, depthTexture: new THREE.DepthTexture(w, h) }),
|
| 259 |
+
pixels: new THREE.WebGLRenderTarget(w, h, { ...srgb, depthBuffer: false }),
|
| 260 |
+
palette: new Palette(this.size),
|
| 261 |
+
fitted: performance.now() + 90 * this.views.size, // the views take turns at refitting
|
| 262 |
+
reading: false,
|
| 263 |
+
last: 0,
|
| 264 |
+
};
|
| 265 |
+
this.views.set(key, view);
|
| 266 |
+
}
|
| 267 |
+
if (view.picked.width !== w || view.picked.height !== h) {
|
| 268 |
+
view.scene.setSize(2 * w, 2 * h);
|
| 269 |
+
view.mask.setSize(2 * w, 2 * h);
|
| 270 |
+
view.picked.setSize(w, h);
|
| 271 |
+
view.pixels.setSize(w, h);
|
| 272 |
+
}
|
| 273 |
+
return view;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
/**
|
| 277 |
+
* Draw `scene` from `camera` as pixel art into the canvas rectangle `rect` (CSS pixels from the top left;
|
| 278 |
+
* null for the whole canvas), `scale` screen pixels to a pixel. `key` names the view, which keeps its
|
| 279 |
+
* own render targets and palette. `draw` draws the scene in place of renderer.render (a view with its
|
| 280 |
+
* own Spark state); `edges` asks for ink lines, {occluders} saying whether OCCLUDER meshes exist.
|
| 281 |
+
*/
|
| 282 |
+
render(renderer, scene, camera, key, rect = null, { scale = this.scale(renderer), draw = null, edges = null } = {}) {
|
| 283 |
+
const pr = renderer.getPixelRatio();
|
| 284 |
+
const canvas = renderer.domElement;
|
| 285 |
+
const x = rect ? Math.round(rect.x * pr) : 0;
|
| 286 |
+
const y = rect ? Math.round(rect.y * pr) : 0;
|
| 287 |
+
const w = rect ? Math.round(rect.w * pr) : canvas.width;
|
| 288 |
+
const h = rect ? Math.round(rect.h * pr) : canvas.height;
|
| 289 |
+
const cols = Math.ceil(w / scale);
|
| 290 |
+
const rows = Math.ceil(h / scale);
|
| 291 |
+
const t = this.#viewFor(key, cols, rows);
|
| 292 |
+
|
| 293 |
+
// Whole pixels cover the view, so the last column and row may hang over its right and bottom edges:
|
| 294 |
+
// the frustum widens by as much, and the picture stays where the other renderers draw it.
|
| 295 |
+
camera.setViewOffset(w, h, 0, 0, cols * scale, rows * scale);
|
| 296 |
+
renderer.setRenderTarget(t.scene);
|
| 297 |
+
if (draw) draw();
|
| 298 |
+
else renderer.render(scene, camera);
|
| 299 |
+
if (edges) this.#drawMask(renderer, scene, camera, t.mask, edges.occluders);
|
| 300 |
+
camera.clearViewOffset();
|
| 301 |
+
|
| 302 |
+
const r = this.resolve.uniforms;
|
| 303 |
+
r.tScene.value = t.scene.texture;
|
| 304 |
+
r.tMask.value = t.mask.texture;
|
| 305 |
+
r.tDepth.value = t.mask.depthTexture;
|
| 306 |
+
r.texel.value.set(0.5 / cols, 0.5 / rows);
|
| 307 |
+
r.near.value = camera.near;
|
| 308 |
+
r.far.value = camera.far;
|
| 309 |
+
r.edges.value = Boolean(edges);
|
| 310 |
+
this.quad.material = this.resolve;
|
| 311 |
+
renderer.setRenderTarget(t.picked);
|
| 312 |
+
renderer.render(this.screen, this.screenCamera);
|
| 313 |
+
this.#follow(renderer, t);
|
| 314 |
+
|
| 315 |
+
const u = this.quantise.uniforms;
|
| 316 |
+
u.tPicked.value = t.picked.texture;
|
| 317 |
+
u.tDepth.value = t.picked.depthTexture;
|
| 318 |
+
u.texel.value.set(1 / cols, 1 / rows);
|
| 319 |
+
u.near.value = camera.near;
|
| 320 |
+
u.far.value = camera.far;
|
| 321 |
+
u.matched.value = t.palette.matched;
|
| 322 |
+
u.colours.value = t.palette.colours;
|
| 323 |
+
u.count.value = t.palette.count;
|
| 324 |
+
u.edges.value = Boolean(edges);
|
| 325 |
+
this.quad.material = this.quantise;
|
| 326 |
+
renderer.setRenderTarget(t.pixels);
|
| 327 |
+
renderer.render(this.screen, this.screenCamera);
|
| 328 |
+
|
| 329 |
+
this.copy.uniforms.tPixels.value = t.pixels.texture;
|
| 330 |
+
this.quad.material = this.copy;
|
| 331 |
+
renderer.setRenderTarget(null);
|
| 332 |
+
renderer.setViewport(x / pr, (canvas.height - y - rows * scale) / pr, (cols * scale) / pr, (rows * scale) / pr);
|
| 333 |
+
renderer.setScissor(x / pr, (canvas.height - y - h) / pr, w / pr, h / pr);
|
| 334 |
+
renderer.setScissorTest(true);
|
| 335 |
+
renderer.render(this.screen, this.screenCamera);
|
| 336 |
+
renderer.setScissorTest(false);
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
/** Which samples show an outlined mesh, and the depth of those and of what hides them. */
|
| 340 |
+
#drawMask(renderer, scene, camera, target, occluders) {
|
| 341 |
+
const background = scene.background;
|
| 342 |
+
const layers = camera.layers.mask;
|
| 343 |
+
const autoClear = renderer.autoClear;
|
| 344 |
+
const clearAlpha = renderer.getClearAlpha();
|
| 345 |
+
renderer.getClearColor(this.clear);
|
| 346 |
+
scene.background = null;
|
| 347 |
+
renderer.setClearColor(0x000000, 0);
|
| 348 |
+
renderer.setRenderTarget(target);
|
| 349 |
+
renderer.clear();
|
| 350 |
+
renderer.autoClear = false;
|
| 351 |
+
if (occluders) {
|
| 352 |
+
camera.layers.set(OCCLUDER);
|
| 353 |
+
scene.overrideMaterial = this.hidden;
|
| 354 |
+
renderer.render(scene, camera);
|
| 355 |
+
}
|
| 356 |
+
camera.layers.set(OUTLINED);
|
| 357 |
+
scene.overrideMaterial = this.solid;
|
| 358 |
+
renderer.render(scene, camera);
|
| 359 |
+
scene.overrideMaterial = null;
|
| 360 |
+
scene.background = background;
|
| 361 |
+
camera.layers.mask = layers;
|
| 362 |
+
renderer.autoClear = autoClear;
|
| 363 |
+
renderer.setClearColor(this.clear, clearAlpha);
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
/** Keep a view's palette on what it shows: at once for a first frame, a few times a second after. */
|
| 367 |
+
#follow(renderer, view) {
|
| 368 |
+
const { palette, picked: target } = view;
|
| 369 |
+
const now = performance.now();
|
| 370 |
+
const { width, height } = target;
|
| 371 |
+
if (palette.count === 0) {
|
| 372 |
+
const pixels = new Uint8Array(4 * width * height);
|
| 373 |
+
renderer.readRenderTargetPixels(target, 0, 0, width, height, pixels);
|
| 374 |
+
palette.fit(pixels);
|
| 375 |
+
} else {
|
| 376 |
+
palette.ease(Math.min(0.1, (now - view.last) / 1000));
|
| 377 |
+
if (!view.reading && now - view.fitted >= REFIT_MS) {
|
| 378 |
+
// Read without stalling the frame; a palette reset meanwhile makes the answer stale.
|
| 379 |
+
view.reading = true;
|
| 380 |
+
view.fitted = now;
|
| 381 |
+
const generation = palette.generation;
|
| 382 |
+
const pixels = new Uint8Array(4 * width * height);
|
| 383 |
+
renderer
|
| 384 |
+
.readRenderTargetPixelsAsync(target, 0, 0, width, height, pixels)
|
| 385 |
+
.then(() => {
|
| 386 |
+
if (generation === palette.generation) palette.fit(pixels);
|
| 387 |
+
})
|
| 388 |
+
.catch(() => {})
|
| 389 |
+
.finally(() => {
|
| 390 |
+
view.reading = false;
|
| 391 |
+
});
|
| 392 |
+
}
|
| 393 |
+
}
|
| 394 |
+
view.last = now;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
dispose() {
|
| 398 |
+
for (const view of this.views.values()) {
|
| 399 |
+
view.scene.dispose();
|
| 400 |
+
view.mask.depthTexture.dispose();
|
| 401 |
+
view.mask.dispose();
|
| 402 |
+
view.picked.depthTexture.dispose();
|
| 403 |
+
view.picked.dispose();
|
| 404 |
+
view.pixels.dispose();
|
| 405 |
+
}
|
| 406 |
+
this.views.clear();
|
| 407 |
+
}
|
| 408 |
+
}
|
src/render/view.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
| 7 |
// - "lit": image-based lighting, soft shadows and PBR materials (after the Microduck simulator), with
|
| 8 |
// procedural textures for the kitchens;
|
| 9 |
// - "splat": the environment's 3D Gaussian splat from MuJoCo-GS-Web (Spark), with the robot and objects
|
| 10 |
-
// lit by the splat itself (an environment map rendered from it) and their shadows caught on its floor
|
|
|
|
| 11 |
//
|
| 12 |
// Environments with a splat also have a decor (tools/make_decor.py): a modelled stand-in for the splat that
|
| 13 |
// Toon and Lit show in place of MuJoCo-GS-Web's invisible collision boxes. Static geoms never move, so they
|
|
@@ -17,13 +18,14 @@ import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
|
| 17 |
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
|
| 18 |
import { mergeGeometries, toCreasedNormals } from "three/addons/utils/BufferGeometryUtils.js";
|
| 19 |
import { floorMaterial, lookFor, makeMaterial, surfaceColour, worldUVs } from "./materials.js";
|
|
|
|
| 20 |
import { OutlinePass } from "./toon.js";
|
| 21 |
import { download } from "../core/assets.js";
|
| 22 |
|
| 23 |
const GEOM = { PLANE: 0, SPHERE: 2, CAPSULE: 3, ELLIPSOID: 4, CYLINDER: 5, BOX: 6, MESH: 7 };
|
| 24 |
const CREASE_ANGLE = Math.PI / 6;
|
| 25 |
const STATIC = new Set(["floor", "proxy", "env", "decor"]);
|
| 26 |
-
const BACKGROUND = { toon: 0xf1eee8, lit: 0xe3dfd8, splat: 0x202124 };
|
| 27 |
// Where the key light sits relative to the camera target, unless the environment says (its "lighting").
|
| 28 |
const KEY_OFFSET = [1.4, -1.1, 3.2];
|
| 29 |
|
|
@@ -45,6 +47,7 @@ export class SceneView {
|
|
| 45 |
this.scene.add(this.root);
|
| 46 |
this.#buildLights();
|
| 47 |
this.outline = new OutlinePass();
|
|
|
|
| 48 |
// 3DGS shadows on the decor: a depth-only pass, then shadows on the nearest surface only.
|
| 49 |
this.catchers = {
|
| 50 |
depth: new THREE.MeshBasicMaterial({ colorWrite: false, transparent: true }),
|
|
@@ -356,10 +359,15 @@ export class SceneView {
|
|
| 356 |
}
|
| 357 |
}
|
| 358 |
|
| 359 |
-
/**
|
|
|
|
|
|
|
|
|
|
| 360 |
async setStyle(style, { onBytes } = {}) {
|
| 361 |
this.style = style === "simple" ? "toon" : style;
|
| 362 |
-
|
|
|
|
|
|
|
| 363 |
this.#applyStyle();
|
| 364 |
}
|
| 365 |
|
|
@@ -451,13 +459,16 @@ export class SceneView {
|
|
| 451 |
}
|
| 452 |
|
| 453 |
#applyStyle() {
|
| 454 |
-
const
|
| 455 |
-
const
|
|
|
|
|
|
|
| 456 |
// The splat replaces the floor, the collision boxes and the decor; elsewhere the decor replaces the
|
| 457 |
// floor and the boxes.
|
| 458 |
const decor = this.meshes.some((m) => m.userData.role === "decor");
|
| 459 |
for (const mesh of this.meshes) {
|
| 460 |
const { role } = mesh.userData;
|
|
|
|
| 461 |
if (role === "catcher") {
|
| 462 |
mesh.visible = splat;
|
| 463 |
continue;
|
|
@@ -468,8 +479,11 @@ export class SceneView {
|
|
| 468 |
mesh.renderOrder = splat ? 1 : 0;
|
| 469 |
mesh.castShadow = splat ? false : mesh.userData.casts;
|
| 470 |
mesh.visible = true;
|
|
|
|
|
|
|
| 471 |
continue;
|
| 472 |
}
|
|
|
|
| 473 |
mesh.material = look === "toon" ? mesh.userData.toon : mesh.userData.lit;
|
| 474 |
const ground = role === "floor" || role === "proxy";
|
| 475 |
mesh.visible = splat ? !ground : !(decor && ground);
|
|
@@ -478,7 +492,12 @@ export class SceneView {
|
|
| 478 |
if (this.shadowCatcher) this.shadowCatcher.visible = splat && !decor;
|
| 479 |
// Splats cost per pixel, so 3DGS draws one pixel per CSS pixel, as MuJoCo-GS-Web does; on a
|
| 480 |
// high-DPI screen the device ratio would multiply the work by up to four.
|
| 481 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
this.lights.lit.visible = look === "lit";
|
| 483 |
this.lights.toon.visible = look === "toon";
|
| 484 |
this.renderer.shadowMap.enabled = true;
|
|
@@ -495,7 +514,7 @@ export class SceneView {
|
|
| 495 |
this.scene.environment = look === "toon" ? null : (splatLight ?? this.environment);
|
| 496 |
this.scene.environmentIntensity = splatLight ? (lighting.ambient ?? 1) : 1;
|
| 497 |
this.scene.environmentRotation.set(splatLight ? 0 : Math.PI / 2, 0, 0);
|
| 498 |
-
this.scene.background = new THREE.Color(BACKGROUND[look]);
|
| 499 |
}
|
| 500 |
|
| 501 |
/** Point the camera at the robot from behind its right shoulder. */
|
|
@@ -566,6 +585,19 @@ export class SceneView {
|
|
| 566 |
for (const rect of this.viewRects()) this.outline.render(renderer, this.scene, this.robotCameras[rect.name].camera, rect.name, rect);
|
| 567 |
return;
|
| 568 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 569 |
renderer.setScissorTest(false);
|
| 570 |
renderer.setViewport(0, 0, w, h);
|
| 571 |
renderer.render(this.scene, this.camera);
|
|
|
|
| 7 |
// - "lit": image-based lighting, soft shadows and PBR materials (after the Microduck simulator), with
|
| 8 |
// procedural textures for the kitchens;
|
| 9 |
// - "splat": the environment's 3D Gaussian splat from MuJoCo-GS-Web (Spark), with the robot and objects
|
| 10 |
+
// lit by the splat itself (an environment map rendered from it) and their shadows caught on its floor;
|
| 11 |
+
// - "pixel": pixel art (pixel.js) of the splat where the environment has one, of the Toon scene elsewhere.
|
| 12 |
//
|
| 13 |
// Environments with a splat also have a decor (tools/make_decor.py): a modelled stand-in for the splat that
|
| 14 |
// Toon and Lit show in place of MuJoCo-GS-Web's invisible collision boxes. Static geoms never move, so they
|
|
|
|
| 18 |
import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js";
|
| 19 |
import { mergeGeometries, toCreasedNormals } from "three/addons/utils/BufferGeometryUtils.js";
|
| 20 |
import { floorMaterial, lookFor, makeMaterial, surfaceColour, worldUVs } from "./materials.js";
|
| 21 |
+
import { OCCLUDER, OUTLINED, PixelPass } from "./pixel.js";
|
| 22 |
import { OutlinePass } from "./toon.js";
|
| 23 |
import { download } from "../core/assets.js";
|
| 24 |
|
| 25 |
const GEOM = { PLANE: 0, SPHERE: 2, CAPSULE: 3, ELLIPSOID: 4, CYLINDER: 5, BOX: 6, MESH: 7 };
|
| 26 |
const CREASE_ANGLE = Math.PI / 6;
|
| 27 |
const STATIC = new Set(["floor", "proxy", "env", "decor"]);
|
| 28 |
+
const BACKGROUND = { toon: 0xf1eee8, lit: 0xe3dfd8, splat: 0x202124, pixel: 0x0d1226 };
|
| 29 |
// Where the key light sits relative to the camera target, unless the environment says (its "lighting").
|
| 30 |
const KEY_OFFSET = [1.4, -1.1, 3.2];
|
| 31 |
|
|
|
|
| 47 |
this.scene.add(this.root);
|
| 48 |
this.#buildLights();
|
| 49 |
this.outline = new OutlinePass();
|
| 50 |
+
this.pixel = new PixelPass();
|
| 51 |
// 3DGS shadows on the decor: a depth-only pass, then shadows on the nearest surface only.
|
| 52 |
this.catchers = {
|
| 53 |
depth: new THREE.MeshBasicMaterial({ colorWrite: false, transparent: true }),
|
|
|
|
| 359 |
}
|
| 360 |
}
|
| 361 |
|
| 362 |
+
/**
|
| 363 |
+
* "toon", "lit", "splat" (falls back to lit without a splat) or "pixel" (of the splat, or of the Toon
|
| 364 |
+
* scene without one); onBytes reports the splat download.
|
| 365 |
+
*/
|
| 366 |
async setStyle(style, { onBytes } = {}) {
|
| 367 |
this.style = style === "simple" ? "toon" : style;
|
| 368 |
+
const splat = (this.style === "splat" || this.style === "pixel") && Boolean(this.env?.splat);
|
| 369 |
+
if (splat && this.style === "pixel") this.#applyStyle(); // the modelled scene in pixels while the splat downloads
|
| 370 |
+
if (splat) await this.#loadSplat(onBytes);
|
| 371 |
this.#applyStyle();
|
| 372 |
}
|
| 373 |
|
|
|
|
| 459 |
}
|
| 460 |
|
| 461 |
#applyStyle() {
|
| 462 |
+
const pixel = this.style === "pixel";
|
| 463 |
+
const loaded = Boolean(this.env?.splat) && this.splat?.userData.url === this.splatBase + this.env.splat;
|
| 464 |
+
const splat = (this.style === "splat" || pixel) && loaded;
|
| 465 |
+
const look = splat ? "splat" : this.style === "toon" || pixel ? "toon" : "lit";
|
| 466 |
// The splat replaces the floor, the collision boxes and the decor; elsewhere the decor replaces the
|
| 467 |
// floor and the boxes.
|
| 468 |
const decor = this.meshes.some((m) => m.userData.role === "decor");
|
| 469 |
for (const mesh of this.meshes) {
|
| 470 |
const { role } = mesh.userData;
|
| 471 |
+
mesh.layers.set(0);
|
| 472 |
if (role === "catcher") {
|
| 473 |
mesh.visible = splat;
|
| 474 |
continue;
|
|
|
|
| 479 |
mesh.renderOrder = splat ? 1 : 0;
|
| 480 |
mesh.castShadow = splat ? false : mesh.userData.casts;
|
| 481 |
mesh.visible = true;
|
| 482 |
+
// Pixel's ink lines go around what is drawn as a mesh; over a splat the decor only hides them.
|
| 483 |
+
mesh.layers.enable(splat ? OCCLUDER : OUTLINED);
|
| 484 |
continue;
|
| 485 |
}
|
| 486 |
+
mesh.layers.enable(OUTLINED);
|
| 487 |
mesh.material = look === "toon" ? mesh.userData.toon : mesh.userData.lit;
|
| 488 |
const ground = role === "floor" || role === "proxy";
|
| 489 |
mesh.visible = splat ? !ground : !(decor && ground);
|
|
|
|
| 492 |
if (this.shadowCatcher) this.shadowCatcher.visible = splat && !decor;
|
| 493 |
// Splats cost per pixel, so 3DGS draws one pixel per CSS pixel, as MuJoCo-GS-Web does; on a
|
| 494 |
// high-DPI screen the device ratio would multiply the work by up to four.
|
| 495 |
+
// Pixel draws its few pixels whatever the screen, and scales them up on all of it.
|
| 496 |
+
this.renderer.setPixelRatio(splat && !pixel ? 1 : Math.min(window.devicePixelRatio, 2));
|
| 497 |
+
this.pixelEdges = { occluders: splat && decor };
|
| 498 |
+
if (pixel) this.pixel.reset(); // new colours for the new look
|
| 499 |
+
// Where the canvas is not a whole number of screen pixels (a 150% display), the browser stretches it.
|
| 500 |
+
this.canvas.style.imageRendering = pixel ? "pixelated" : "";
|
| 501 |
this.lights.lit.visible = look === "lit";
|
| 502 |
this.lights.toon.visible = look === "toon";
|
| 503 |
this.renderer.shadowMap.enabled = true;
|
|
|
|
| 514 |
this.scene.environment = look === "toon" ? null : (splatLight ?? this.environment);
|
| 515 |
this.scene.environmentIntensity = splatLight ? (lighting.ambient ?? 1) : 1;
|
| 516 |
this.scene.environmentRotation.set(splatLight ? 0 : Math.PI / 2, 0, 0);
|
| 517 |
+
this.scene.background = new THREE.Color(BACKGROUND[pixel ? "pixel" : look]);
|
| 518 |
}
|
| 519 |
|
| 520 |
/** Point the camera at the robot from behind its right shoulder. */
|
|
|
|
| 585 |
for (const rect of this.viewRects()) this.outline.render(renderer, this.scene, this.robotCameras[rect.name].camera, rect.name, rect);
|
| 586 |
return;
|
| 587 |
}
|
| 588 |
+
if (this.style === "pixel") {
|
| 589 |
+
const edges = this.pixelEdges;
|
| 590 |
+
const scale = this.pixel.scale(renderer);
|
| 591 |
+
this.pixel.render(renderer, this.scene, this.camera, "main", null, { scale, edges });
|
| 592 |
+
// The robot cameras are small: half-size pixels keep them readable.
|
| 593 |
+
for (const rect of this.viewRects()) {
|
| 594 |
+
const cam = this.robotCameras[rect.name];
|
| 595 |
+
const spark = this.#sparkFor(cam);
|
| 596 |
+
const draw = spark ? () => spark.render(this.scene, cam.camera) : null;
|
| 597 |
+
this.pixel.render(renderer, this.scene, cam.camera, rect.name, rect, { scale: Math.max(1, Math.round(scale / 2)), edges, draw });
|
| 598 |
+
}
|
| 599 |
+
return;
|
| 600 |
+
}
|
| 601 |
renderer.setScissorTest(false);
|
| 602 |
renderer.setViewport(0, 0, w, h);
|
| 603 |
renderer.render(this.scene, this.camera);
|
src/style.css
CHANGED
|
@@ -1,531 +1,531 @@
|
|
| 1 |
-
:root {
|
| 2 |
-
--bg: #f5f5f7;
|
| 3 |
-
--panel: #ffffff;
|
| 4 |
-
--text: #1d1d1f;
|
| 5 |
-
--muted: #6e6e73;
|
| 6 |
-
--line: rgba(0, 0, 0, 0.1);
|
| 7 |
-
--accent: #0071e3;
|
| 8 |
-
--ok: #1a7f37;
|
| 9 |
-
--error: #b42318;
|
| 10 |
-
--radius: 12px;
|
| 11 |
-
color-scheme: light;
|
| 12 |
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
| 13 |
-
}
|
| 14 |
-
@media (prefers-color-scheme: dark) {
|
| 15 |
-
:root {
|
| 16 |
-
--bg: #111113;
|
| 17 |
-
--panel: #1c1c1e;
|
| 18 |
-
--text: #f5f5f7;
|
| 19 |
-
--muted: #a1a1a6;
|
| 20 |
-
--line: rgba(255, 255, 255, 0.12);
|
| 21 |
-
--accent: #2997ff;
|
| 22 |
-
--ok: #3fb950;
|
| 23 |
-
--error: #ff7b72;
|
| 24 |
-
color-scheme: dark;
|
| 25 |
-
}
|
| 26 |
-
}
|
| 27 |
-
* {
|
| 28 |
-
box-sizing: border-box;
|
| 29 |
-
}
|
| 30 |
-
html,
|
| 31 |
-
body {
|
| 32 |
-
margin: 0;
|
| 33 |
-
height: 100%;
|
| 34 |
-
background: var(--bg);
|
| 35 |
-
color: var(--text);
|
| 36 |
-
}
|
| 37 |
-
.app {
|
| 38 |
-
display: grid;
|
| 39 |
-
grid-template-columns: 1fr 320px;
|
| 40 |
-
height: 100vh;
|
| 41 |
-
}
|
| 42 |
-
.stage {
|
| 43 |
-
position: relative;
|
| 44 |
-
min-height: 0;
|
| 45 |
-
}
|
| 46 |
-
#view {
|
| 47 |
-
display: block;
|
| 48 |
-
width: 100%;
|
| 49 |
-
height: 100%;
|
| 50 |
-
outline: none;
|
| 51 |
-
}
|
| 52 |
-
.brand {
|
| 53 |
-
position: absolute;
|
| 54 |
-
top: 12px;
|
| 55 |
-
left: 12px;
|
| 56 |
-
padding: 6px 12px 7px;
|
| 57 |
-
border-radius: 12px;
|
| 58 |
-
background: color-mix(in srgb, var(--panel) 72%, transparent);
|
| 59 |
-
backdrop-filter: blur(8px);
|
| 60 |
-
pointer-events: none;
|
| 61 |
-
}
|
| 62 |
-
.brand h1 {
|
| 63 |
-
margin: 0;
|
| 64 |
-
font-size: 22px;
|
| 65 |
-
letter-spacing: -0.01em;
|
| 66 |
-
}
|
| 67 |
-
.brand p {
|
| 68 |
-
margin: 2px 0 0;
|
| 69 |
-
font-size: 13px;
|
| 70 |
-
color: var(--muted);
|
| 71 |
-
}
|
| 72 |
-
.view-labels span {
|
| 73 |
-
position: absolute;
|
| 74 |
-
padding: 2px 8px;
|
| 75 |
-
border-radius: 6px;
|
| 76 |
-
background: rgba(0, 0, 0, 0.55);
|
| 77 |
-
color: #fff;
|
| 78 |
-
font-size: 12px;
|
| 79 |
-
pointer-events: none;
|
| 80 |
-
}
|
| 81 |
-
.loading {
|
| 82 |
-
position: absolute;
|
| 83 |
-
inset: 0;
|
| 84 |
-
display: grid;
|
| 85 |
-
place-items: center;
|
| 86 |
-
background: var(--bg);
|
| 87 |
-
}
|
| 88 |
-
.loading[hidden] {
|
| 89 |
-
display: none;
|
| 90 |
-
}
|
| 91 |
-
.loading-card {
|
| 92 |
-
width: min(360px, 80vw);
|
| 93 |
-
text-align: center;
|
| 94 |
-
color: var(--muted);
|
| 95 |
-
}
|
| 96 |
-
.loading.failed .loading-card {
|
| 97 |
-
color: var(--error);
|
| 98 |
-
}
|
| 99 |
-
.progress {
|
| 100 |
-
height: 6px;
|
| 101 |
-
border-radius: 3px;
|
| 102 |
-
background: var(--line);
|
| 103 |
-
overflow: hidden;
|
| 104 |
-
}
|
| 105 |
-
.progress div {
|
| 106 |
-
width: 0;
|
| 107 |
-
height: 100%;
|
| 108 |
-
background: var(--accent);
|
| 109 |
-
transition: width 0.2s;
|
| 110 |
-
}
|
| 111 |
-
.panel {
|
| 112 |
-
overflow-y: auto;
|
| 113 |
-
padding: 16px 18px 24px;
|
| 114 |
-
background: var(--panel);
|
| 115 |
-
border-left: 1px solid var(--line);
|
| 116 |
-
font-size: 14px;
|
| 117 |
-
}
|
| 118 |
-
.panel section,
|
| 119 |
-
.panel details {
|
| 120 |
-
padding: 12px 0;
|
| 121 |
-
border-bottom: 1px solid var(--line);
|
| 122 |
-
}
|
| 123 |
-
.panel h2 {
|
| 124 |
-
display: flex;
|
| 125 |
-
align-items: center;
|
| 126 |
-
justify-content: space-between;
|
| 127 |
-
margin: 0 0 10px;
|
| 128 |
-
font-size: 12px;
|
| 129 |
-
font-weight: 600;
|
| 130 |
-
letter-spacing: 0.04em;
|
| 131 |
-
text-transform: uppercase;
|
| 132 |
-
color: var(--muted);
|
| 133 |
-
}
|
| 134 |
-
.segmented {
|
| 135 |
-
display: grid;
|
| 136 |
-
grid-template-columns: repeat(
|
| 137 |
-
gap: 2px;
|
| 138 |
-
padding: 2px;
|
| 139 |
-
border-radius: 9px;
|
| 140 |
-
background: var(--bg);
|
| 141 |
-
}
|
| 142 |
-
.segmented button {
|
| 143 |
-
padding: 6px 0;
|
| 144 |
-
border: 0;
|
| 145 |
-
border-radius: 7px;
|
| 146 |
-
background: transparent;
|
| 147 |
-
color: var(--text);
|
| 148 |
-
font: inherit;
|
| 149 |
-
cursor: pointer;
|
| 150 |
-
}
|
| 151 |
-
.segmented button[aria-pressed="true"] {
|
| 152 |
-
background: var(--panel);
|
| 153 |
-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
|
| 154 |
-
font-weight: 600;
|
| 155 |
-
}
|
| 156 |
-
.segmented button:disabled {
|
| 157 |
-
color: var(--muted);
|
| 158 |
-
cursor: default;
|
| 159 |
-
}
|
| 160 |
-
.chips {
|
| 161 |
-
display: flex;
|
| 162 |
-
flex-wrap: wrap;
|
| 163 |
-
gap: 8px;
|
| 164 |
-
}
|
| 165 |
-
.chips label {
|
| 166 |
-
display: inline-flex;
|
| 167 |
-
align-items: center;
|
| 168 |
-
gap: 6px;
|
| 169 |
-
padding: 4px 10px;
|
| 170 |
-
border: 1px solid var(--line);
|
| 171 |
-
border-radius: 999px;
|
| 172 |
-
cursor: pointer;
|
| 173 |
-
}
|
| 174 |
-
.task p {
|
| 175 |
-
margin: 0 0 8px;
|
| 176 |
-
}
|
| 177 |
-
.meter {
|
| 178 |
-
height: 8px;
|
| 179 |
-
border-radius: 4px;
|
| 180 |
-
background: var(--bg);
|
| 181 |
-
overflow: hidden;
|
| 182 |
-
}
|
| 183 |
-
.meter div {
|
| 184 |
-
width: 0;
|
| 185 |
-
height: 100%;
|
| 186 |
-
background: var(--accent);
|
| 187 |
-
}
|
| 188 |
-
.task.done .meter div {
|
| 189 |
-
background: var(--ok);
|
| 190 |
-
}
|
| 191 |
-
.lift {
|
| 192 |
-
margin-top: 8px !important;
|
| 193 |
-
color: var(--muted);
|
| 194 |
-
}
|
| 195 |
-
.badge {
|
| 196 |
-
display: none;
|
| 197 |
-
margin-left: 6px;
|
| 198 |
-
padding: 1px 8px;
|
| 199 |
-
border-radius: 999px;
|
| 200 |
-
background: var(--ok);
|
| 201 |
-
color: #fff;
|
| 202 |
-
font-size: 12px;
|
| 203 |
-
}
|
| 204 |
-
.task.done .badge {
|
| 205 |
-
display: inline-block;
|
| 206 |
-
}
|
| 207 |
-
.buttons {
|
| 208 |
-
display: flex;
|
| 209 |
-
gap: 8px;
|
| 210 |
-
}
|
| 211 |
-
.buttons button {
|
| 212 |
-
flex: 1;
|
| 213 |
-
padding: 8px 0;
|
| 214 |
-
border: 1px solid var(--line);
|
| 215 |
-
border-radius: 999px;
|
| 216 |
-
background: var(--panel);
|
| 217 |
-
color: var(--text);
|
| 218 |
-
font: inherit;
|
| 219 |
-
cursor: pointer;
|
| 220 |
-
}
|
| 221 |
-
.buttons .primary {
|
| 222 |
-
border-color: var(--accent);
|
| 223 |
-
background: var(--accent);
|
| 224 |
-
color: #fff;
|
| 225 |
-
}
|
| 226 |
-
.buttons button:disabled {
|
| 227 |
-
opacity: 0.5;
|
| 228 |
-
cursor: default;
|
| 229 |
-
}
|
| 230 |
-
.active-arm {
|
| 231 |
-
padding: 1px 8px;
|
| 232 |
-
border-radius: 999px;
|
| 233 |
-
background: var(--bg);
|
| 234 |
-
color: var(--text);
|
| 235 |
-
text-transform: none;
|
| 236 |
-
letter-spacing: 0;
|
| 237 |
-
}
|
| 238 |
-
.keys {
|
| 239 |
-
display: grid;
|
| 240 |
-
grid-template-columns: auto 1fr;
|
| 241 |
-
gap: 4px 12px;
|
| 242 |
-
margin: 0;
|
| 243 |
-
}
|
| 244 |
-
.keys dt {
|
| 245 |
-
white-space: nowrap;
|
| 246 |
-
}
|
| 247 |
-
.keys dd {
|
| 248 |
-
margin: 0;
|
| 249 |
-
color: var(--muted);
|
| 250 |
-
}
|
| 251 |
-
kbd {
|
| 252 |
-
padding: 1px 6px;
|
| 253 |
-
border: 1px solid var(--line);
|
| 254 |
-
border-bottom-width: 2px;
|
| 255 |
-
border-radius: 5px;
|
| 256 |
-
font: 12px ui-monospace, SFMono-Regular, Consolas, monospace;
|
| 257 |
-
}
|
| 258 |
-
summary {
|
| 259 |
-
cursor: pointer;
|
| 260 |
-
font-weight: 600;
|
| 261 |
-
}
|
| 262 |
-
.note {
|
| 263 |
-
color: var(--muted);
|
| 264 |
-
font-size: 12px;
|
| 265 |
-
}
|
| 266 |
-
.note.error {
|
| 267 |
-
color: var(--error);
|
| 268 |
-
}
|
| 269 |
-
.state {
|
| 270 |
-
width: 100%;
|
| 271 |
-
border-collapse: collapse;
|
| 272 |
-
font: 12px ui-monospace, SFMono-Regular, Consolas, monospace;
|
| 273 |
-
}
|
| 274 |
-
.state th {
|
| 275 |
-
padding: 2px 0;
|
| 276 |
-
font-weight: normal;
|
| 277 |
-
text-align: left;
|
| 278 |
-
color: var(--muted);
|
| 279 |
-
}
|
| 280 |
-
.state td {
|
| 281 |
-
text-align: right;
|
| 282 |
-
}
|
| 283 |
-
footer p {
|
| 284 |
-
margin: 14px 0 0;
|
| 285 |
-
color: var(--muted);
|
| 286 |
-
font-size: 12px;
|
| 287 |
-
}
|
| 288 |
-
a {
|
| 289 |
-
color: var(--accent);
|
| 290 |
-
}
|
| 291 |
-
@media (max-width: 760px) {
|
| 292 |
-
.app {
|
| 293 |
-
grid-template-columns: 1fr;
|
| 294 |
-
grid-template-rows: 60vh auto;
|
| 295 |
-
height: auto;
|
| 296 |
-
}
|
| 297 |
-
.stage {
|
| 298 |
-
height: 60vh;
|
| 299 |
-
}
|
| 300 |
-
.panel {
|
| 301 |
-
border-left: 0;
|
| 302 |
-
border-top: 1px solid var(--line);
|
| 303 |
-
}
|
| 304 |
-
}
|
| 305 |
-
|
| 306 |
-
/* v0.2: tabs, selects, skills, agent chat */
|
| 307 |
-
.tabs {
|
| 308 |
-
position: sticky;
|
| 309 |
-
top: -16px;
|
| 310 |
-
z-index: 2;
|
| 311 |
-
display: grid;
|
| 312 |
-
grid-template-columns: repeat(3, 1fr);
|
| 313 |
-
gap: 2px;
|
| 314 |
-
margin: -16px -18px 4px;
|
| 315 |
-
padding: 10px 12px;
|
| 316 |
-
background: var(--panel);
|
| 317 |
-
border-bottom: 1px solid var(--line);
|
| 318 |
-
}
|
| 319 |
-
.tabs button {
|
| 320 |
-
padding: 7px 0;
|
| 321 |
-
border: 0;
|
| 322 |
-
border-radius: 8px;
|
| 323 |
-
background: transparent;
|
| 324 |
-
color: var(--muted);
|
| 325 |
-
font: inherit;
|
| 326 |
-
font-weight: 600;
|
| 327 |
-
cursor: pointer;
|
| 328 |
-
}
|
| 329 |
-
.tabs button[aria-selected="true"] {
|
| 330 |
-
background: var(--bg);
|
| 331 |
-
color: var(--text);
|
| 332 |
-
}
|
| 333 |
-
.tab[hidden] {
|
| 334 |
-
display: none;
|
| 335 |
-
}
|
| 336 |
-
select,
|
| 337 |
-
input[type="text"],
|
| 338 |
-
input:not([type]),
|
| 339 |
-
input[type="password"],
|
| 340 |
-
textarea {
|
| 341 |
-
width: 100%;
|
| 342 |
-
padding: 7px 9px;
|
| 343 |
-
border: 1px solid var(--line);
|
| 344 |
-
border-radius: 8px;
|
| 345 |
-
background: var(--bg);
|
| 346 |
-
color: var(--text);
|
| 347 |
-
font: inherit;
|
| 348 |
-
}
|
| 349 |
-
textarea {
|
| 350 |
-
resize: vertical;
|
| 351 |
-
}
|
| 352 |
-
.row {
|
| 353 |
-
display: flex;
|
| 354 |
-
gap: 8px;
|
| 355 |
-
align-items: center;
|
| 356 |
-
}
|
| 357 |
-
.row select {
|
| 358 |
-
flex: 1;
|
| 359 |
-
}
|
| 360 |
-
.row button,
|
| 361 |
-
.connect button,
|
| 362 |
-
.link {
|
| 363 |
-
padding: 7px 12px;
|
| 364 |
-
border: 1px solid var(--line);
|
| 365 |
-
border-radius: 999px;
|
| 366 |
-
background: var(--panel);
|
| 367 |
-
color: var(--text);
|
| 368 |
-
font: inherit;
|
| 369 |
-
cursor: pointer;
|
| 370 |
-
white-space: nowrap;
|
| 371 |
-
}
|
| 372 |
-
.buttons.wrap {
|
| 373 |
-
flex-wrap: wrap;
|
| 374 |
-
margin-top: 10px;
|
| 375 |
-
}
|
| 376 |
-
.buttons.wrap button {
|
| 377 |
-
flex: 1 1 30%;
|
| 378 |
-
}
|
| 379 |
-
.status {
|
| 380 |
-
margin: 10px 0 0;
|
| 381 |
-
min-height: 1.4em;
|
| 382 |
-
color: var(--muted);
|
| 383 |
-
font-size: 13px;
|
| 384 |
-
}
|
| 385 |
-
.activity {
|
| 386 |
-
position: absolute;
|
| 387 |
-
top: 18px;
|
| 388 |
-
right: 18px;
|
| 389 |
-
padding: 6px 12px;
|
| 390 |
-
border-radius: 999px;
|
| 391 |
-
background: rgba(0, 0, 0, 0.6);
|
| 392 |
-
color: #fff;
|
| 393 |
-
font-size: 13px;
|
| 394 |
-
pointer-events: none;
|
| 395 |
-
}
|
| 396 |
-
.activity[hidden] {
|
| 397 |
-
display: none;
|
| 398 |
-
}
|
| 399 |
-
.hint {
|
| 400 |
-
position: absolute;
|
| 401 |
-
right: 18px;
|
| 402 |
-
bottom: 12px;
|
| 403 |
-
margin: 0;
|
| 404 |
-
color: var(--muted);
|
| 405 |
-
font-size: 12px;
|
| 406 |
-
pointer-events: none;
|
| 407 |
-
}
|
| 408 |
-
.sliders label {
|
| 409 |
-
display: grid;
|
| 410 |
-
gap: 2px;
|
| 411 |
-
margin-bottom: 8px;
|
| 412 |
-
font-size: 12px;
|
| 413 |
-
color: var(--muted);
|
| 414 |
-
}
|
| 415 |
-
.sliders input {
|
| 416 |
-
width: 100%;
|
| 417 |
-
}
|
| 418 |
-
.connect .hf {
|
| 419 |
-
width: 100%;
|
| 420 |
-
padding: 9px 12px;
|
| 421 |
-
border: 0;
|
| 422 |
-
background: #ffd21e;
|
| 423 |
-
color: #1d1d1f;
|
| 424 |
-
font-weight: 600;
|
| 425 |
-
}
|
| 426 |
-
.connect label {
|
| 427 |
-
display: grid;
|
| 428 |
-
gap: 4px;
|
| 429 |
-
margin-top: 10px;
|
| 430 |
-
font-size: 12px;
|
| 431 |
-
color: var(--muted);
|
| 432 |
-
}
|
| 433 |
-
.connect label.check {
|
| 434 |
-
display: flex;
|
| 435 |
-
align-items: center;
|
| 436 |
-
gap: 8px;
|
| 437 |
-
}
|
| 438 |
-
.connect label.check input {
|
| 439 |
-
width: auto;
|
| 440 |
-
}
|
| 441 |
-
.connect details {
|
| 442 |
-
margin-top: 10px;
|
| 443 |
-
padding: 0;
|
| 444 |
-
border: 0;
|
| 445 |
-
}
|
| 446 |
-
.link {
|
| 447 |
-
padding: 0;
|
| 448 |
-
border: 0;
|
| 449 |
-
color: var(--accent);
|
| 450 |
-
background: none;
|
| 451 |
-
}
|
| 452 |
-
.chat-log {
|
| 453 |
-
display: flex;
|
| 454 |
-
flex-direction: column;
|
| 455 |
-
gap: 8px;
|
| 456 |
-
max-height: 46vh;
|
| 457 |
-
min-height: 120px;
|
| 458 |
-
overflow-y: auto;
|
| 459 |
-
margin-bottom: 10px;
|
| 460 |
-
}
|
| 461 |
-
.msg {
|
| 462 |
-
padding: 8px 10px;
|
| 463 |
-
border-radius: 10px;
|
| 464 |
-
line-height: 1.4;
|
| 465 |
-
overflow-wrap: anywhere;
|
| 466 |
-
}
|
| 467 |
-
.msg.user {
|
| 468 |
-
align-self: flex-end;
|
| 469 |
-
max-width: 85%;
|
| 470 |
-
background: var(--accent);
|
| 471 |
-
color: #fff;
|
| 472 |
-
}
|
| 473 |
-
.msg.assistant {
|
| 474 |
-
background: var(--bg);
|
| 475 |
-
}
|
| 476 |
-
.msg.tool {
|
| 477 |
-
padding: 4px 8px;
|
| 478 |
-
border: 1px solid var(--line);
|
| 479 |
-
font: 12px ui-monospace, SFMono-Regular, Consolas, monospace;
|
| 480 |
-
color: var(--muted);
|
| 481 |
-
}
|
| 482 |
-
.msg.tool .tool-name {
|
| 483 |
-
color: var(--text);
|
| 484 |
-
font-weight: 600;
|
| 485 |
-
}
|
| 486 |
-
.msg.tool.failed .tool-result {
|
| 487 |
-
color: #c0392b;
|
| 488 |
-
}
|
| 489 |
-
.msg.tool img {
|
| 490 |
-
display: block;
|
| 491 |
-
width: 100%;
|
| 492 |
-
border-radius: 6px;
|
| 493 |
-
}
|
| 494 |
-
.msg.error {
|
| 495 |
-
color: #c0392b;
|
| 496 |
-
font-size: 13px;
|
| 497 |
-
}
|
| 498 |
-
.examples {
|
| 499 |
-
display: flex;
|
| 500 |
-
flex-wrap: wrap;
|
| 501 |
-
gap: 6px;
|
| 502 |
-
margin-bottom: 10px;
|
| 503 |
-
}
|
| 504 |
-
.examples[hidden] {
|
| 505 |
-
display: none;
|
| 506 |
-
}
|
| 507 |
-
.examples button {
|
| 508 |
-
padding: 5px 10px;
|
| 509 |
-
border: 1px solid var(--line);
|
| 510 |
-
border-radius: 999px;
|
| 511 |
-
background: var(--panel);
|
| 512 |
-
color: var(--text);
|
| 513 |
-
font: inherit;
|
| 514 |
-
font-size: 12px;
|
| 515 |
-
cursor: pointer;
|
| 516 |
-
}
|
| 517 |
-
.chat-form .buttons {
|
| 518 |
-
margin-top: 8px;
|
| 519 |
-
}
|
| 520 |
-
code {
|
| 521 |
-
font: 12px ui-monospace, SFMono-Regular, Consolas, monospace;
|
| 522 |
-
}
|
| 523 |
-
@media (max-width: 760px) {
|
| 524 |
-
.tabs {
|
| 525 |
-
top: 0;
|
| 526 |
-
margin-top: -16px;
|
| 527 |
-
}
|
| 528 |
-
.hint {
|
| 529 |
-
display: none;
|
| 530 |
-
}
|
| 531 |
-
}
|
|
|
|
| 1 |
+
:root {
|
| 2 |
+
--bg: #f5f5f7;
|
| 3 |
+
--panel: #ffffff;
|
| 4 |
+
--text: #1d1d1f;
|
| 5 |
+
--muted: #6e6e73;
|
| 6 |
+
--line: rgba(0, 0, 0, 0.1);
|
| 7 |
+
--accent: #0071e3;
|
| 8 |
+
--ok: #1a7f37;
|
| 9 |
+
--error: #b42318;
|
| 10 |
+
--radius: 12px;
|
| 11 |
+
color-scheme: light;
|
| 12 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
| 13 |
+
}
|
| 14 |
+
@media (prefers-color-scheme: dark) {
|
| 15 |
+
:root {
|
| 16 |
+
--bg: #111113;
|
| 17 |
+
--panel: #1c1c1e;
|
| 18 |
+
--text: #f5f5f7;
|
| 19 |
+
--muted: #a1a1a6;
|
| 20 |
+
--line: rgba(255, 255, 255, 0.12);
|
| 21 |
+
--accent: #2997ff;
|
| 22 |
+
--ok: #3fb950;
|
| 23 |
+
--error: #ff7b72;
|
| 24 |
+
color-scheme: dark;
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
* {
|
| 28 |
+
box-sizing: border-box;
|
| 29 |
+
}
|
| 30 |
+
html,
|
| 31 |
+
body {
|
| 32 |
+
margin: 0;
|
| 33 |
+
height: 100%;
|
| 34 |
+
background: var(--bg);
|
| 35 |
+
color: var(--text);
|
| 36 |
+
}
|
| 37 |
+
.app {
|
| 38 |
+
display: grid;
|
| 39 |
+
grid-template-columns: 1fr 320px;
|
| 40 |
+
height: 100vh;
|
| 41 |
+
}
|
| 42 |
+
.stage {
|
| 43 |
+
position: relative;
|
| 44 |
+
min-height: 0;
|
| 45 |
+
}
|
| 46 |
+
#view {
|
| 47 |
+
display: block;
|
| 48 |
+
width: 100%;
|
| 49 |
+
height: 100%;
|
| 50 |
+
outline: none;
|
| 51 |
+
}
|
| 52 |
+
.brand {
|
| 53 |
+
position: absolute;
|
| 54 |
+
top: 12px;
|
| 55 |
+
left: 12px;
|
| 56 |
+
padding: 6px 12px 7px;
|
| 57 |
+
border-radius: 12px;
|
| 58 |
+
background: color-mix(in srgb, var(--panel) 72%, transparent);
|
| 59 |
+
backdrop-filter: blur(8px);
|
| 60 |
+
pointer-events: none;
|
| 61 |
+
}
|
| 62 |
+
.brand h1 {
|
| 63 |
+
margin: 0;
|
| 64 |
+
font-size: 22px;
|
| 65 |
+
letter-spacing: -0.01em;
|
| 66 |
+
}
|
| 67 |
+
.brand p {
|
| 68 |
+
margin: 2px 0 0;
|
| 69 |
+
font-size: 13px;
|
| 70 |
+
color: var(--muted);
|
| 71 |
+
}
|
| 72 |
+
.view-labels span {
|
| 73 |
+
position: absolute;
|
| 74 |
+
padding: 2px 8px;
|
| 75 |
+
border-radius: 6px;
|
| 76 |
+
background: rgba(0, 0, 0, 0.55);
|
| 77 |
+
color: #fff;
|
| 78 |
+
font-size: 12px;
|
| 79 |
+
pointer-events: none;
|
| 80 |
+
}
|
| 81 |
+
.loading {
|
| 82 |
+
position: absolute;
|
| 83 |
+
inset: 0;
|
| 84 |
+
display: grid;
|
| 85 |
+
place-items: center;
|
| 86 |
+
background: var(--bg);
|
| 87 |
+
}
|
| 88 |
+
.loading[hidden] {
|
| 89 |
+
display: none;
|
| 90 |
+
}
|
| 91 |
+
.loading-card {
|
| 92 |
+
width: min(360px, 80vw);
|
| 93 |
+
text-align: center;
|
| 94 |
+
color: var(--muted);
|
| 95 |
+
}
|
| 96 |
+
.loading.failed .loading-card {
|
| 97 |
+
color: var(--error);
|
| 98 |
+
}
|
| 99 |
+
.progress {
|
| 100 |
+
height: 6px;
|
| 101 |
+
border-radius: 3px;
|
| 102 |
+
background: var(--line);
|
| 103 |
+
overflow: hidden;
|
| 104 |
+
}
|
| 105 |
+
.progress div {
|
| 106 |
+
width: 0;
|
| 107 |
+
height: 100%;
|
| 108 |
+
background: var(--accent);
|
| 109 |
+
transition: width 0.2s;
|
| 110 |
+
}
|
| 111 |
+
.panel {
|
| 112 |
+
overflow-y: auto;
|
| 113 |
+
padding: 16px 18px 24px;
|
| 114 |
+
background: var(--panel);
|
| 115 |
+
border-left: 1px solid var(--line);
|
| 116 |
+
font-size: 14px;
|
| 117 |
+
}
|
| 118 |
+
.panel section,
|
| 119 |
+
.panel details {
|
| 120 |
+
padding: 12px 0;
|
| 121 |
+
border-bottom: 1px solid var(--line);
|
| 122 |
+
}
|
| 123 |
+
.panel h2 {
|
| 124 |
+
display: flex;
|
| 125 |
+
align-items: center;
|
| 126 |
+
justify-content: space-between;
|
| 127 |
+
margin: 0 0 10px;
|
| 128 |
+
font-size: 12px;
|
| 129 |
+
font-weight: 600;
|
| 130 |
+
letter-spacing: 0.04em;
|
| 131 |
+
text-transform: uppercase;
|
| 132 |
+
color: var(--muted);
|
| 133 |
+
}
|
| 134 |
+
.segmented {
|
| 135 |
+
display: grid;
|
| 136 |
+
grid-template-columns: repeat(4, 1fr);
|
| 137 |
+
gap: 2px;
|
| 138 |
+
padding: 2px;
|
| 139 |
+
border-radius: 9px;
|
| 140 |
+
background: var(--bg);
|
| 141 |
+
}
|
| 142 |
+
.segmented button {
|
| 143 |
+
padding: 6px 0;
|
| 144 |
+
border: 0;
|
| 145 |
+
border-radius: 7px;
|
| 146 |
+
background: transparent;
|
| 147 |
+
color: var(--text);
|
| 148 |
+
font: inherit;
|
| 149 |
+
cursor: pointer;
|
| 150 |
+
}
|
| 151 |
+
.segmented button[aria-pressed="true"] {
|
| 152 |
+
background: var(--panel);
|
| 153 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
|
| 154 |
+
font-weight: 600;
|
| 155 |
+
}
|
| 156 |
+
.segmented button:disabled {
|
| 157 |
+
color: var(--muted);
|
| 158 |
+
cursor: default;
|
| 159 |
+
}
|
| 160 |
+
.chips {
|
| 161 |
+
display: flex;
|
| 162 |
+
flex-wrap: wrap;
|
| 163 |
+
gap: 8px;
|
| 164 |
+
}
|
| 165 |
+
.chips label {
|
| 166 |
+
display: inline-flex;
|
| 167 |
+
align-items: center;
|
| 168 |
+
gap: 6px;
|
| 169 |
+
padding: 4px 10px;
|
| 170 |
+
border: 1px solid var(--line);
|
| 171 |
+
border-radius: 999px;
|
| 172 |
+
cursor: pointer;
|
| 173 |
+
}
|
| 174 |
+
.task p {
|
| 175 |
+
margin: 0 0 8px;
|
| 176 |
+
}
|
| 177 |
+
.meter {
|
| 178 |
+
height: 8px;
|
| 179 |
+
border-radius: 4px;
|
| 180 |
+
background: var(--bg);
|
| 181 |
+
overflow: hidden;
|
| 182 |
+
}
|
| 183 |
+
.meter div {
|
| 184 |
+
width: 0;
|
| 185 |
+
height: 100%;
|
| 186 |
+
background: var(--accent);
|
| 187 |
+
}
|
| 188 |
+
.task.done .meter div {
|
| 189 |
+
background: var(--ok);
|
| 190 |
+
}
|
| 191 |
+
.lift {
|
| 192 |
+
margin-top: 8px !important;
|
| 193 |
+
color: var(--muted);
|
| 194 |
+
}
|
| 195 |
+
.badge {
|
| 196 |
+
display: none;
|
| 197 |
+
margin-left: 6px;
|
| 198 |
+
padding: 1px 8px;
|
| 199 |
+
border-radius: 999px;
|
| 200 |
+
background: var(--ok);
|
| 201 |
+
color: #fff;
|
| 202 |
+
font-size: 12px;
|
| 203 |
+
}
|
| 204 |
+
.task.done .badge {
|
| 205 |
+
display: inline-block;
|
| 206 |
+
}
|
| 207 |
+
.buttons {
|
| 208 |
+
display: flex;
|
| 209 |
+
gap: 8px;
|
| 210 |
+
}
|
| 211 |
+
.buttons button {
|
| 212 |
+
flex: 1;
|
| 213 |
+
padding: 8px 0;
|
| 214 |
+
border: 1px solid var(--line);
|
| 215 |
+
border-radius: 999px;
|
| 216 |
+
background: var(--panel);
|
| 217 |
+
color: var(--text);
|
| 218 |
+
font: inherit;
|
| 219 |
+
cursor: pointer;
|
| 220 |
+
}
|
| 221 |
+
.buttons .primary {
|
| 222 |
+
border-color: var(--accent);
|
| 223 |
+
background: var(--accent);
|
| 224 |
+
color: #fff;
|
| 225 |
+
}
|
| 226 |
+
.buttons button:disabled {
|
| 227 |
+
opacity: 0.5;
|
| 228 |
+
cursor: default;
|
| 229 |
+
}
|
| 230 |
+
.active-arm {
|
| 231 |
+
padding: 1px 8px;
|
| 232 |
+
border-radius: 999px;
|
| 233 |
+
background: var(--bg);
|
| 234 |
+
color: var(--text);
|
| 235 |
+
text-transform: none;
|
| 236 |
+
letter-spacing: 0;
|
| 237 |
+
}
|
| 238 |
+
.keys {
|
| 239 |
+
display: grid;
|
| 240 |
+
grid-template-columns: auto 1fr;
|
| 241 |
+
gap: 4px 12px;
|
| 242 |
+
margin: 0;
|
| 243 |
+
}
|
| 244 |
+
.keys dt {
|
| 245 |
+
white-space: nowrap;
|
| 246 |
+
}
|
| 247 |
+
.keys dd {
|
| 248 |
+
margin: 0;
|
| 249 |
+
color: var(--muted);
|
| 250 |
+
}
|
| 251 |
+
kbd {
|
| 252 |
+
padding: 1px 6px;
|
| 253 |
+
border: 1px solid var(--line);
|
| 254 |
+
border-bottom-width: 2px;
|
| 255 |
+
border-radius: 5px;
|
| 256 |
+
font: 12px ui-monospace, SFMono-Regular, Consolas, monospace;
|
| 257 |
+
}
|
| 258 |
+
summary {
|
| 259 |
+
cursor: pointer;
|
| 260 |
+
font-weight: 600;
|
| 261 |
+
}
|
| 262 |
+
.note {
|
| 263 |
+
color: var(--muted);
|
| 264 |
+
font-size: 12px;
|
| 265 |
+
}
|
| 266 |
+
.note.error {
|
| 267 |
+
color: var(--error);
|
| 268 |
+
}
|
| 269 |
+
.state {
|
| 270 |
+
width: 100%;
|
| 271 |
+
border-collapse: collapse;
|
| 272 |
+
font: 12px ui-monospace, SFMono-Regular, Consolas, monospace;
|
| 273 |
+
}
|
| 274 |
+
.state th {
|
| 275 |
+
padding: 2px 0;
|
| 276 |
+
font-weight: normal;
|
| 277 |
+
text-align: left;
|
| 278 |
+
color: var(--muted);
|
| 279 |
+
}
|
| 280 |
+
.state td {
|
| 281 |
+
text-align: right;
|
| 282 |
+
}
|
| 283 |
+
footer p {
|
| 284 |
+
margin: 14px 0 0;
|
| 285 |
+
color: var(--muted);
|
| 286 |
+
font-size: 12px;
|
| 287 |
+
}
|
| 288 |
+
a {
|
| 289 |
+
color: var(--accent);
|
| 290 |
+
}
|
| 291 |
+
@media (max-width: 760px) {
|
| 292 |
+
.app {
|
| 293 |
+
grid-template-columns: 1fr;
|
| 294 |
+
grid-template-rows: 60vh auto;
|
| 295 |
+
height: auto;
|
| 296 |
+
}
|
| 297 |
+
.stage {
|
| 298 |
+
height: 60vh;
|
| 299 |
+
}
|
| 300 |
+
.panel {
|
| 301 |
+
border-left: 0;
|
| 302 |
+
border-top: 1px solid var(--line);
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
/* v0.2: tabs, selects, skills, agent chat */
|
| 307 |
+
.tabs {
|
| 308 |
+
position: sticky;
|
| 309 |
+
top: -16px;
|
| 310 |
+
z-index: 2;
|
| 311 |
+
display: grid;
|
| 312 |
+
grid-template-columns: repeat(3, 1fr);
|
| 313 |
+
gap: 2px;
|
| 314 |
+
margin: -16px -18px 4px;
|
| 315 |
+
padding: 10px 12px;
|
| 316 |
+
background: var(--panel);
|
| 317 |
+
border-bottom: 1px solid var(--line);
|
| 318 |
+
}
|
| 319 |
+
.tabs button {
|
| 320 |
+
padding: 7px 0;
|
| 321 |
+
border: 0;
|
| 322 |
+
border-radius: 8px;
|
| 323 |
+
background: transparent;
|
| 324 |
+
color: var(--muted);
|
| 325 |
+
font: inherit;
|
| 326 |
+
font-weight: 600;
|
| 327 |
+
cursor: pointer;
|
| 328 |
+
}
|
| 329 |
+
.tabs button[aria-selected="true"] {
|
| 330 |
+
background: var(--bg);
|
| 331 |
+
color: var(--text);
|
| 332 |
+
}
|
| 333 |
+
.tab[hidden] {
|
| 334 |
+
display: none;
|
| 335 |
+
}
|
| 336 |
+
select,
|
| 337 |
+
input[type="text"],
|
| 338 |
+
input:not([type]),
|
| 339 |
+
input[type="password"],
|
| 340 |
+
textarea {
|
| 341 |
+
width: 100%;
|
| 342 |
+
padding: 7px 9px;
|
| 343 |
+
border: 1px solid var(--line);
|
| 344 |
+
border-radius: 8px;
|
| 345 |
+
background: var(--bg);
|
| 346 |
+
color: var(--text);
|
| 347 |
+
font: inherit;
|
| 348 |
+
}
|
| 349 |
+
textarea {
|
| 350 |
+
resize: vertical;
|
| 351 |
+
}
|
| 352 |
+
.row {
|
| 353 |
+
display: flex;
|
| 354 |
+
gap: 8px;
|
| 355 |
+
align-items: center;
|
| 356 |
+
}
|
| 357 |
+
.row select {
|
| 358 |
+
flex: 1;
|
| 359 |
+
}
|
| 360 |
+
.row button,
|
| 361 |
+
.connect button,
|
| 362 |
+
.link {
|
| 363 |
+
padding: 7px 12px;
|
| 364 |
+
border: 1px solid var(--line);
|
| 365 |
+
border-radius: 999px;
|
| 366 |
+
background: var(--panel);
|
| 367 |
+
color: var(--text);
|
| 368 |
+
font: inherit;
|
| 369 |
+
cursor: pointer;
|
| 370 |
+
white-space: nowrap;
|
| 371 |
+
}
|
| 372 |
+
.buttons.wrap {
|
| 373 |
+
flex-wrap: wrap;
|
| 374 |
+
margin-top: 10px;
|
| 375 |
+
}
|
| 376 |
+
.buttons.wrap button {
|
| 377 |
+
flex: 1 1 30%;
|
| 378 |
+
}
|
| 379 |
+
.status {
|
| 380 |
+
margin: 10px 0 0;
|
| 381 |
+
min-height: 1.4em;
|
| 382 |
+
color: var(--muted);
|
| 383 |
+
font-size: 13px;
|
| 384 |
+
}
|
| 385 |
+
.activity {
|
| 386 |
+
position: absolute;
|
| 387 |
+
top: 18px;
|
| 388 |
+
right: 18px;
|
| 389 |
+
padding: 6px 12px;
|
| 390 |
+
border-radius: 999px;
|
| 391 |
+
background: rgba(0, 0, 0, 0.6);
|
| 392 |
+
color: #fff;
|
| 393 |
+
font-size: 13px;
|
| 394 |
+
pointer-events: none;
|
| 395 |
+
}
|
| 396 |
+
.activity[hidden] {
|
| 397 |
+
display: none;
|
| 398 |
+
}
|
| 399 |
+
.hint {
|
| 400 |
+
position: absolute;
|
| 401 |
+
right: 18px;
|
| 402 |
+
bottom: 12px;
|
| 403 |
+
margin: 0;
|
| 404 |
+
color: var(--muted);
|
| 405 |
+
font-size: 12px;
|
| 406 |
+
pointer-events: none;
|
| 407 |
+
}
|
| 408 |
+
.sliders label {
|
| 409 |
+
display: grid;
|
| 410 |
+
gap: 2px;
|
| 411 |
+
margin-bottom: 8px;
|
| 412 |
+
font-size: 12px;
|
| 413 |
+
color: var(--muted);
|
| 414 |
+
}
|
| 415 |
+
.sliders input {
|
| 416 |
+
width: 100%;
|
| 417 |
+
}
|
| 418 |
+
.connect .hf {
|
| 419 |
+
width: 100%;
|
| 420 |
+
padding: 9px 12px;
|
| 421 |
+
border: 0;
|
| 422 |
+
background: #ffd21e;
|
| 423 |
+
color: #1d1d1f;
|
| 424 |
+
font-weight: 600;
|
| 425 |
+
}
|
| 426 |
+
.connect label {
|
| 427 |
+
display: grid;
|
| 428 |
+
gap: 4px;
|
| 429 |
+
margin-top: 10px;
|
| 430 |
+
font-size: 12px;
|
| 431 |
+
color: var(--muted);
|
| 432 |
+
}
|
| 433 |
+
.connect label.check {
|
| 434 |
+
display: flex;
|
| 435 |
+
align-items: center;
|
| 436 |
+
gap: 8px;
|
| 437 |
+
}
|
| 438 |
+
.connect label.check input {
|
| 439 |
+
width: auto;
|
| 440 |
+
}
|
| 441 |
+
.connect details {
|
| 442 |
+
margin-top: 10px;
|
| 443 |
+
padding: 0;
|
| 444 |
+
border: 0;
|
| 445 |
+
}
|
| 446 |
+
.link {
|
| 447 |
+
padding: 0;
|
| 448 |
+
border: 0;
|
| 449 |
+
color: var(--accent);
|
| 450 |
+
background: none;
|
| 451 |
+
}
|
| 452 |
+
.chat-log {
|
| 453 |
+
display: flex;
|
| 454 |
+
flex-direction: column;
|
| 455 |
+
gap: 8px;
|
| 456 |
+
max-height: 46vh;
|
| 457 |
+
min-height: 120px;
|
| 458 |
+
overflow-y: auto;
|
| 459 |
+
margin-bottom: 10px;
|
| 460 |
+
}
|
| 461 |
+
.msg {
|
| 462 |
+
padding: 8px 10px;
|
| 463 |
+
border-radius: 10px;
|
| 464 |
+
line-height: 1.4;
|
| 465 |
+
overflow-wrap: anywhere;
|
| 466 |
+
}
|
| 467 |
+
.msg.user {
|
| 468 |
+
align-self: flex-end;
|
| 469 |
+
max-width: 85%;
|
| 470 |
+
background: var(--accent);
|
| 471 |
+
color: #fff;
|
| 472 |
+
}
|
| 473 |
+
.msg.assistant {
|
| 474 |
+
background: var(--bg);
|
| 475 |
+
}
|
| 476 |
+
.msg.tool {
|
| 477 |
+
padding: 4px 8px;
|
| 478 |
+
border: 1px solid var(--line);
|
| 479 |
+
font: 12px ui-monospace, SFMono-Regular, Consolas, monospace;
|
| 480 |
+
color: var(--muted);
|
| 481 |
+
}
|
| 482 |
+
.msg.tool .tool-name {
|
| 483 |
+
color: var(--text);
|
| 484 |
+
font-weight: 600;
|
| 485 |
+
}
|
| 486 |
+
.msg.tool.failed .tool-result {
|
| 487 |
+
color: #c0392b;
|
| 488 |
+
}
|
| 489 |
+
.msg.tool img {
|
| 490 |
+
display: block;
|
| 491 |
+
width: 100%;
|
| 492 |
+
border-radius: 6px;
|
| 493 |
+
}
|
| 494 |
+
.msg.error {
|
| 495 |
+
color: #c0392b;
|
| 496 |
+
font-size: 13px;
|
| 497 |
+
}
|
| 498 |
+
.examples {
|
| 499 |
+
display: flex;
|
| 500 |
+
flex-wrap: wrap;
|
| 501 |
+
gap: 6px;
|
| 502 |
+
margin-bottom: 10px;
|
| 503 |
+
}
|
| 504 |
+
.examples[hidden] {
|
| 505 |
+
display: none;
|
| 506 |
+
}
|
| 507 |
+
.examples button {
|
| 508 |
+
padding: 5px 10px;
|
| 509 |
+
border: 1px solid var(--line);
|
| 510 |
+
border-radius: 999px;
|
| 511 |
+
background: var(--panel);
|
| 512 |
+
color: var(--text);
|
| 513 |
+
font: inherit;
|
| 514 |
+
font-size: 12px;
|
| 515 |
+
cursor: pointer;
|
| 516 |
+
}
|
| 517 |
+
.chat-form .buttons {
|
| 518 |
+
margin-top: 8px;
|
| 519 |
+
}
|
| 520 |
+
code {
|
| 521 |
+
font: 12px ui-monospace, SFMono-Regular, Consolas, monospace;
|
| 522 |
+
}
|
| 523 |
+
@media (max-width: 760px) {
|
| 524 |
+
.tabs {
|
| 525 |
+
top: 0;
|
| 526 |
+
margin-top: -16px;
|
| 527 |
+
}
|
| 528 |
+
.hint {
|
| 529 |
+
display: none;
|
| 530 |
+
}
|
| 531 |
+
}
|