@kerf-js/keel 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +306 -2
  3. package/package.json +59 -3
  4. package/src/blend-inset.ts +79 -0
  5. package/src/blend.ts +120 -0
  6. package/src/client.d.ts +9 -0
  7. package/src/generate/bust.ts +24 -0
  8. package/src/generate/bust.worker.ts +4 -0
  9. package/src/generate/pack.ts +69 -0
  10. package/src/generate/plate.ts +51 -0
  11. package/src/generate/plate.worker.ts +4 -0
  12. package/src/generate/serve.ts +56 -0
  13. package/src/generate/surface.ts +16 -0
  14. package/src/generate/surface.worker.ts +4 -0
  15. package/src/generate.ts +133 -0
  16. package/src/governor.ts +87 -0
  17. package/src/index.d.ts +15 -0
  18. package/src/index.mjs +63 -0
  19. package/src/lit.d.ts +384 -0
  20. package/src/paint-live.ts +60 -0
  21. package/src/paint-recipe.d.mts +29 -0
  22. package/src/paint-recipe.mjs +29 -0
  23. package/src/paint-worker.mjs +20 -0
  24. package/src/paint.d.mts +37 -0
  25. package/src/paint.mjs +180 -0
  26. package/src/runtime.ts +35 -0
  27. package/src/scene.ts +289 -0
  28. package/src/stage.ts +192 -0
  29. package/vendor/LICENSE +21 -0
  30. package/vendor/LICENSE-modules +21 -0
  31. package/vendor/NOTICE +24 -0
  32. package/vendor/README.md +13 -0
  33. package/vendor/lit.d.mts +1 -0
  34. package/vendor/lit.mjs +2 -0
  35. package/vendor/lock.json +177 -0
  36. package/vendor/modules/band/events.d.ts +20 -0
  37. package/vendor/modules/band/index.d.ts +29 -0
  38. package/vendor/modules/band/player.d.ts +43 -0
  39. package/vendor/modules/band/roll.d.ts +14 -0
  40. package/vendor/modules/band/score.d.ts +45 -0
  41. package/vendor/modules/band/styles.data.d.ts +37 -0
  42. package/vendor/modules/band/voices.d.ts +33 -0
  43. package/vendor/modules/band.d.mts +1 -0
  44. package/vendor/modules/band.mjs +2 -0
  45. package/vendor/modules/butterflies/butterflies.glsl.d.ts +2 -0
  46. package/vendor/modules/butterflies/flight.d.ts +68 -0
  47. package/vendor/modules/butterflies/index.d.ts +79 -0
  48. package/vendor/modules/butterflies/wing.d.ts +38 -0
  49. package/vendor/modules/butterflies.d.mts +1 -0
  50. package/vendor/modules/butterflies.inputs.json +73 -0
  51. package/vendor/modules/butterflies.mjs +39 -0
  52. package/vendor/modules/camera-rail/index.d.ts +113 -0
  53. package/vendor/modules/camera-rail.d.mts +1 -0
  54. package/vendor/modules/camera-rail.mjs +2 -0
  55. package/vendor/modules/device-profile/index.d.ts +47 -0
  56. package/vendor/modules/device-profile.d.mts +1 -0
  57. package/vendor/modules/device-profile.mjs +2 -0
  58. package/vendor/modules/lit-finish/dress.d.ts +34 -0
  59. package/vendor/modules/lit-finish/finish.glsl.d.ts +15 -0
  60. package/vendor/modules/lit-finish/index.d.ts +33 -0
  61. package/vendor/modules/lit-finish/lit.d.ts +52 -0
  62. package/vendor/modules/lit-finish/pass.d.ts +35 -0
  63. package/vendor/modules/lit-finish/settings.d.ts +88 -0
  64. package/vendor/modules/lit-finish.d.mts +1 -0
  65. package/vendor/modules/lit-finish.inputs.json +200 -0
  66. package/vendor/modules/lit-finish.mjs +267 -0
  67. package/vendor/modules/look/index.d.ts +159 -0
  68. package/vendor/modules/look.d.mts +1 -0
  69. package/vendor/modules/look.inputs.json +23 -0
  70. package/vendor/modules/look.mjs +2 -0
  71. package/vendor/modules/motes/index.d.ts +83 -0
  72. package/vendor/modules/motes/motes.glsl.d.ts +9 -0
  73. package/vendor/modules/motes/place.d.ts +59 -0
  74. package/vendor/modules/motes.d.mts +1 -0
  75. package/vendor/modules/motes.inputs.json +116 -0
  76. package/vendor/modules/motes.mjs +68 -0
  77. package/vendor/modules/plate-painter/dab.d.ts +44 -0
  78. package/vendor/modules/plate-painter/exact.d.ts +19 -0
  79. package/vendor/modules/plate-painter/foliage.d.ts +4 -0
  80. package/vendor/modules/plate-painter/gpu.d.ts +65 -0
  81. package/vendor/modules/plate-painter/index.d.ts +14 -0
  82. package/vendor/modules/plate-painter/paint.glsl.d.ts +14 -0
  83. package/vendor/modules/plate-painter/plan.d.ts +42 -0
  84. package/vendor/modules/plate-painter/recipe.d.ts +136 -0
  85. package/vendor/modules/plate-painter/scene.d.ts +4 -0
  86. package/vendor/modules/plate-painter.d.mts +1 -0
  87. package/vendor/modules/plate-painter.inputs.json +50 -0
  88. package/vendor/modules/plate-painter.mjs +384 -0
  89. package/vendor/modules/portrait/body.d.ts +25 -0
  90. package/vendor/modules/portrait/bust.d.ts +67 -0
  91. package/vendor/modules/portrait/cap.d.ts +12 -0
  92. package/vendor/modules/portrait/compile.d.ts +8 -0
  93. package/vendor/modules/portrait/exact.d.ts +17 -0
  94. package/vendor/modules/portrait/hair.d.ts +26 -0
  95. package/vendor/modules/portrait/hand.d.ts +30 -0
  96. package/vendor/modules/portrait/head.d.ts +18 -0
  97. package/vendor/modules/portrait/index.d.ts +12 -0
  98. package/vendor/modules/portrait/mesh.d.ts +24 -0
  99. package/vendor/modules/portrait/parts.d.ts +33 -0
  100. package/vendor/modules/portrait/portrait.glsl.d.ts +4 -0
  101. package/vendor/modules/portrait/render.d.ts +125 -0
  102. package/vendor/modules/portrait/sdf.d.ts +75 -0
  103. package/vendor/modules/portrait/settings.d.ts +27 -0
  104. package/vendor/modules/portrait.d.mts +1 -0
  105. package/vendor/modules/portrait.inputs.json +111 -0
  106. package/vendor/modules/portrait.mjs +2 -0
  107. package/vendor/modules/quality/index.d.ts +130 -0
  108. package/vendor/modules/quality.d.mts +1 -0
  109. package/vendor/modules/quality.inputs.json +34 -0
  110. package/vendor/modules/quality.mjs +2 -0
  111. package/vendor/modules/scene-blend/blend.d.ts +54 -0
  112. package/vendor/modules/scene-blend/blend.glsl.d.ts +8 -0
  113. package/vendor/modules/scene-blend/index.d.ts +25 -0
  114. package/vendor/modules/scene-blend/lit.d.ts +61 -0
  115. package/vendor/modules/scene-blend/noise.d.ts +13 -0
  116. package/vendor/modules/scene-blend/settings.d.ts +63 -0
  117. package/vendor/modules/scene-blend.d.mts +1 -0
  118. package/vendor/modules/scene-blend.inputs.json +133 -0
  119. package/vendor/modules/scene-blend.mjs +2 -0
  120. package/vendor/modules/section-post/index.d.ts +23 -0
  121. package/vendor/modules/section-post/lit.d.ts +47 -0
  122. package/vendor/modules/section-post/noise.d.ts +14 -0
  123. package/vendor/modules/section-post/post.d.ts +31 -0
  124. package/vendor/modules/section-post/post.glsl.d.ts +8 -0
  125. package/vendor/modules/section-post/settings.d.ts +84 -0
  126. package/vendor/modules/section-post.d.mts +1 -0
  127. package/vendor/modules/section-post.inputs.json +107 -0
  128. package/vendor/modules/section-post.mjs +53 -0
  129. package/vendor/modules/surfaces/exact.d.ts +8 -0
  130. package/vendor/modules/surfaces/field.d.ts +7 -0
  131. package/vendor/modules/surfaces/gpu.d.ts +19 -0
  132. package/vendor/modules/surfaces/index.d.ts +17 -0
  133. package/vendor/modules/surfaces/paint.d.ts +28 -0
  134. package/vendor/modules/surfaces/plan.d.ts +39 -0
  135. package/vendor/modules/surfaces/print.d.ts +55 -0
  136. package/vendor/modules/surfaces/recipe.d.ts +143 -0
  137. package/vendor/modules/surfaces/surface.glsl.d.ts +4 -0
  138. package/vendor/modules/surfaces.d.mts +1 -0
  139. package/vendor/modules/surfaces.inputs.json +54 -0
  140. package/vendor/modules/surfaces.mjs +172 -0
  141. package/vendor/modules/tracks/index.d.ts +66 -0
  142. package/vendor/modules/tracks.d.mts +1 -0
  143. package/vendor/modules/tracks.mjs +2 -0
  144. package/vendor/modules/tree-growth/bend.d.ts +28 -0
  145. package/vendor/modules/tree-growth/frame.d.ts +60 -0
  146. package/vendor/modules/tree-growth/index.d.ts +23 -0
  147. package/vendor/modules/tree-growth/light.d.ts +13 -0
  148. package/vendor/modules/tree-growth/math.d.ts +19 -0
  149. package/vendor/modules/tree-growth/model.d.ts +100 -0
  150. package/vendor/modules/tree-growth/sectors.d.ts +10 -0
  151. package/vendor/modules/tree-growth/simulation.d.ts +58 -0
  152. package/vendor/modules/tree-growth/species.d.ts +117 -0
  153. package/vendor/modules/tree-growth/species.data.d.ts +2 -0
  154. package/vendor/modules/tree-growth/year.d.ts +38 -0
  155. package/vendor/modules/tree-growth.d.mts +1 -0
  156. package/vendor/modules/tree-growth.inputs.json +75 -0
  157. package/vendor/modules/tree-growth.mjs +2 -0
  158. package/vendor/modules/tree-render/features.d.ts +9 -0
  159. package/vendor/modules/tree-render/forest/bake.d.ts +41 -0
  160. package/vendor/modules/tree-render/forest/cards.d.ts +28 -0
  161. package/vendor/modules/tree-render/forest/forest.d.ts +156 -0
  162. package/vendor/modules/tree-render/index.d.ts +52 -0
  163. package/vendor/modules/tree-render/inputs.d.ts +260 -0
  164. package/vendor/modules/tree-render/instances.d.ts +66 -0
  165. package/vendor/modules/tree-render/math.d.ts +8 -0
  166. package/vendor/modules/tree-render/tree/bark.d.ts +20 -0
  167. package/vendor/modules/tree-render/tree/leaves.d.ts +29 -0
  168. package/vendor/modules/tree-render/tree/litter.d.ts +21 -0
  169. package/vendor/modules/tree-render/tree/ornaments.d.ts +36 -0
  170. package/vendor/modules/tree-render/tree/roots.d.ts +75 -0
  171. package/vendor/modules/tree-render/tree/shapes.d.ts +49 -0
  172. package/vendor/modules/tree-render/tree/tree.d.ts +239 -0
  173. package/vendor/modules/tree-render/tree/wood.d.ts +27 -0
  174. package/vendor/modules/tree-render/wind.d.ts +51 -0
  175. package/vendor/modules/tree-render.d.mts +1 -0
  176. package/vendor/modules/tree-render.inputs.json +45 -0
  177. package/vendor/modules/tree-render.mjs +2 -0
  178. package/vendor/modules/voxel-dither/dither.glsl.d.ts +9 -0
  179. package/vendor/modules/voxel-dither/index.d.ts +35 -0
  180. package/vendor/modules/voxel-dither/light.d.ts +33 -0
  181. package/vendor/modules/voxel-dither/lit.d.ts +86 -0
  182. package/vendor/modules/voxel-dither/pass.d.ts +46 -0
  183. package/vendor/modules/voxel-dither/screens.d.ts +21 -0
  184. package/vendor/modules/voxel-dither/settings.d.ts +307 -0
  185. package/vendor/modules/voxel-dither/signals.d.ts +35 -0
  186. package/vendor/modules/voxel-dither.d.mts +1 -0
  187. package/vendor/modules/voxel-dither.inputs.json +295 -0
  188. package/vendor/modules/voxel-dither.mjs +452 -0
  189. package/vendor/modules/world-light/index.d.ts +133 -0
  190. package/vendor/modules/world-light.d.mts +1 -0
  191. package/vendor/modules/world-light.inputs.json +68 -0
  192. package/vendor/modules/world-light.mjs +2 -0
@@ -0,0 +1,2 @@
1
+ // portrait@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
2
+ var e=1.5707963267948966;function n(e,n,t){let o=e,a=e;for(let e=t;e<t+16;e+=2)o*=-n/(e*(e+1)),a+=o;return a}function t(t){let o=t%e,a=Math.abs(o)>e/2?o-Math.sign(t)*e:o,r=Math.round((t-a)/e),l=a-6123233995736766e-32*r,i=(r%4+4)%4,s=i%2==1?n(1,l*l,1):n(l,l*l,2);return i<2?s:-s}function o(n){return t(n+e)}var a=n=>n*e/90;function r(e,n,a){let[r,l]=[t(e),o(e)],[i,s]=[t(n),o(n)],[u,c]=[t(a),o(a)];return[s*c+i*r*u,l*u,-i*c+s*r*u,-s*u+i*r*c,l*c,i*u+s*r*c,i*l,-r,s*l]}function l(...e){let n=2166136261;for(let t of e)n=Math.imul(n^(0|t),16777619),n^=n>>>15,n=Math.imul(n,739982445),n^=n>>>12;return n>>>0}function i(...e){return l(...e)/4294967296}function s(e,n,t,o){return t+(o-t)*i(e,n)}var u=[1,0,0,0,1,0,0,0,1];function c(e,n,t){if(t<=0)return e<n?e:n;let o=t-(e>n?e-n:n-e);return o<=0?e<n?e:n:(e<n?e:n)-o*o/(4*t)}function h(e,n,t){return-c(-e,-n,t)}var d=(e,n,t)=>Math.sqrt(e*e+n*n+t*t);function f(e,n,t,o){return[e[0]*n+e[1]*t+e[2]*o,e[3]*n+e[4]*t+e[5]*o,e[6]*n+e[7]*t+e[8]*o]}function p(e,n,t,o){return[e[0]*n+e[3]*t+e[6]*o,e[1]*n+e[4]*t+e[7]*o,e[2]*n+e[5]*t+e[8]*o]}function v(e,n){let t=(e,n)=>e[n]??0,o=(o,a)=>t(e,3*o)*t(n,a)+t(e,3*o+1)*t(n,3+a)+t(e,3*o+2)*t(n,6+a);return[o(0,0),o(0,1),o(0,2),o(1,0),o(1,1),o(1,2),o(2,0),o(2,1),o(2,2)]}var m=(e,n,t)=>({kind:"prim",bound:[e[0],e[1],e[2],n],f:t});function w(e,n){let[t,o,a]=e;return m(e,n,(e,r,l)=>d(e-t,r-o,l-a)-n)}function b(e,n,t=u){let[o,a,r]=e,[l,i,s]=n.map(e=>1/e),[c,h,d]=[l*l,i*i,s*s],f=-Math.min(...n),p=(e,n,t)=>{let o=Math.sqrt(e*e*c+n*n*h+t*t*d),a=Math.sqrt(e*e*c*c+n*n*h*h+t*t*d*d);return a>1e-12?o*(o-1)/a:f},[v,w,b,y,g,x,k,M,A]=t,C=t!==u;return m(e,Math.max(...n),(e,n,t)=>{let l=e-o,i=n-a,s=t-r;return C?p(v*l+w*i+b*s,y*l+g*i+x*s,k*l+M*i+A*s):p(l,i,s)})}function y(e,n,t,o){let[a,r,l]=e,i=n[0]-a,s=n[1]-r,u=n[2]-l,c=i*i+s*s+u*u,h=t-o,d=c-h*h,f=1/c;return m([a+i/2,r+s/2,l+u/2],Math.sqrt(c)/2+Math.max(t,o),(e,n,p)=>{let v=e-a,m=n-r,w=p-l,b=v*i+m*s+w*u,y=b-c,g=v*c-i*b,x=m*c-s*b,k=w*c-u*b,M=g*g+x*x+k*k,A=b*b*c,C=y*y*c,S=(h>0?1:-1)*h*h*M;return(y>0?1:-1)*d*C>S?Math.sqrt(M+C)*f-o:(b>0?1:-1)*d*A<S?Math.sqrt(M+A)*f-t:(Math.sqrt(M*d*f)+b*h)*f-t})}function g(e,n,t){return y(e,n,t,t)}function x(e,n,t,o=u){let[a,r,l]=e;return m(e,d(n[0],n[1],n[2])+t,(e,i,s)=>{let u=e-a,c=i-r,h=s-l,f=o[0]*u+o[1]*c+o[2]*h,p=o[3]*u+o[4]*c+o[5]*h,v=o[6]*u+o[7]*c+o[8]*h,m=Math.abs(f)-n[0],w=Math.abs(p)-n[1],b=Math.abs(v)-n[2];return d(Math.max(m,0),Math.max(w,0),Math.max(b,0))+Math.min(Math.max(m,w,b),0)-t})}function k(e,n){let[t,o,a]=e;return{kind:"prim",bound:[0,0,0,1/0],f:(e,r,l)=>t*e+o*r+a*l-n}}function M(e){let n=e.filter(e=>e.bound[3]<1/0);if(0===n.length)return[0,0,0,1/0];let t=[1/0,1/0,1/0],o=[-1/0,-1/0,-1/0];for(let{bound:e}of n)t=t.map((n,t)=>Math.min(n,(e[t]??0)-e[3])),o=o.map((n,t)=>Math.max(n,(e[t]??0)+e[3]));let a=t.map((e,n)=>(e+(o[n]??0))/2),r=d((o[0]??0)-(t[0]??0),(o[1]??0)-(t[1]??0),(o[2]??0)-(t[2]??0))/2;return[a[0]??0,a[1]??0,a[2]??0,r]}function A(e,...n){return{kind:"blend",k:e,kids:n,bound:M(n)}}function C(e,n,t){return{kind:"fan",k:Math.max(0,...t),ks:t,kids:[e,...n],bound:M([e,...n])}}function S(e,n,...t){return{kind:"carve",k:e,kids:[n,...t],bound:n.bound}}function T(e,...n){let t=n.filter(e=>e.bound[3]<1/0).reduce((e,n)=>e&&e.bound[3]<=n.bound[3]?e:n,void 0);return{kind:"cut",k:e,kids:n,bound:t?t.bound:[0,0,0,1/0]}}function F(e,n,t){let[o,a,r,l]=t.bound,[i,s,u]=p(e,o,a,r);return{kind:"frame",rot:e,at:n,kid:t,bound:[i+n[0],s+n[1],u+n[2],l]}}function q(e,n,t){let[o,a,r,l]=e.bound;return{kind:"bump",kid:e,f:n,bound:[o,a,r,l+t]}}var R={shoulder:[-.165,-.045,-.055],elbow:[-.235,-.31,.03],wrist:[-.25,-.12,.2],hanging:[.215,-.33,-.05]};function z(){return A(.02,y([0,-.02,-.05],[0,.085,-.053],.046,.041),...[1,-1].map(e=>g([.05*e,.125,-.07],[.012*e,0,-.012],.011)),...[1,-1].map(e=>g([.018*e,-.004,-.014],[.15*e,.014,-.05],.0085)),...[1,-1].map(e=>y([.03*e,.055,-.072],[.16*e,-.005,-.06],.027,.028)))}function L(e,n){let t=n;return A(.025,b([0,-.13,-.065],[.14+t,.15+t,.085+t]),b([0,-.38,-.06],[.125+t,.17+t,.085+t]),...[1,-1].map(e=>b([.068*e,-.14,-.005],[.058+t,.055+t,.05+t])),...[1,-1].map(e=>b([.165*e,-.05,-.058],[.05+t,.06+t,.055+t])),y(e.shoulder,e.elbow,.044+t,.036+t),y([-e.shoulder[0],e.shoulder[1],e.shoulder[2]],e.hanging,.044+t,.036+t))}function O(e){let n=e-Math.floor(e);return 8*n*(1-n)-1}function K(e,n){return(t,o,a)=>{let r=t*n+a*n*.4+2*o,l=.6*O(r)+.25*O(2.3*r+.27),i=Math.min(1,Math.max(0,6*(-o-.12)));return l*e*(.35+.65*i)}}function E(e){return T(.003,q(L(e,.003),(e,n)=>{let t=Math.max(0,1-40*Math.abs(n+.085));return.0012*O(41*e)*t},.0013),k([0,1,.25],-.072))}function P(e){let n=q(L(e,.008),K(.0022,7),.0025),t=x([0,.06,.06],[.105,.155,.12],.012),[o,a]=[e.elbow,e.wrist],r=[a[0]-o[0],a[1]-o[1],a[2]-o[2]],l=Math.sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]),i=[r[0]/l,r[1]/l,r[2]/l],s=[a[0]-.028*i[0],a[1]-.028*i[1],a[2]-.028*i[2]],u=q(y(o,a,.05,.036),K(.0025,9),.0027),c=k(i,i[0]*s[0]+i[1]*s[1]+i[2]*s[2]);return A(.006,S(.004,n,t),T(.003,u,c))}function D(e){let n=q(L(e,.02),K(.004,4.5),.0045),t=A(.02,x([0,-.25,.1],[.128,.24,.18],.01),b([0,.08,.02],[.13,.13,.14])),o=[e.elbow,e.hanging].map((n,t)=>{let o=0===t?e.shoulder:[-e.shoulder[0],e.shoulder[1],e.shoulder[2]];return q(y(o,[n[0]+.25*(n[0]-o[0]),n[1]-.06,n[2]],.06,.1),K(.005,3.5),.0055)});return A(.02,S(.012,n,t),...o)}function B(e){let n=[];for(let a=0;a<=e;a+=1){let r=2.6*(a/e*2-1),l=o(r);n.push([.075*t(r),-.048*l*l-.012*l+.03,.09*l-.05])}return n}function V(e){let n=Math.sqrt(1.1296);return{normal:[0,1/n,-.36/n],edge:(.043-("B"===e?.01:0)-.36*.03)/n,cuff:.046,centre:[0,.06,-.06]}}function W(e){return A(.03,b([0,.026,-.064],[.083+e,.104+e,.1+e]),b([0,.03,-.02],[.064+e,.052+e,.05+e]),b([.025,.105,-.115],[.072+e,.058+e,.07+e]),b([0,.03,-.07],[.097+e,.085+e,.095+e]))}function j(e,n){let[t,o,a]=e;return t?o?a?(o,a,r)=>{let l=t(o,a,r);for(let t=1;t<e.length;t+=1){let i=e[t];i&&(l=c(l,i(o,a,r),n))}return l}:(e,a,r)=>c(t(e,a,r),o(e,a,r),n):t:null}function N(e,n,t){if(((e,n,t)=>{let[o,a,r,l]=e.bound;if(l===1/0)return!1;let i=o-n[0],s=a-n[1],u=r-n[2];return Math.sqrt(i*i+s*s+u*u)-l-n[3]>t})(e,n,t))return null;switch(e.kind){case"prim":return e.f;case"frame":return function(e,n,t){let{rot:o,at:a}=e,[r,l,i]=a,s=n[0]-r,u=n[1]-l,c=n[2]-i,h=[o[0]*s+o[1]*u+o[2]*c,o[3]*s+o[4]*u+o[5]*c,o[6]*s+o[7]*u+o[8]*c,n[3]],d=N(e.kid,h,t);return d?(e,n,t)=>{let a=e-r,s=n-l,u=t-i;return d(o[0]*a+o[1]*s+o[2]*u,o[3]*a+o[4]*s+o[5]*u,o[6]*a+o[7]*s+o[8]*u)}:null}(e,n,t);case"bump":{let o=N(e.kid,n,t+e.bound[3]-e.kid.bound[3]),a=e.f;return o?(e,n,t)=>o(e,n,t)+a(e,n,t):null}default:return function(e,n,t){let o=Math.max(t,2*e.k);if("fan"===e.kind)return function(e,n,t){let o=Math.max(t,2*e.k),[a,...r]=e.kids,l=a?N(a,n,o):null,i=[],s=[];return r.forEach((t,a)=>{let r=N(t,n,o);r&&i.push(r),r&&s.push(e.ks?.[a]??0)}),l?(e,n,t)=>{let o=l(e,n,t),a=o;for(let r=0;r<i.length;r+=1){let l=i[r];l&&(a=Math.min(a,c(o,l(e,n,t),s[r]??0)))}return a}:j(i,0)}(e,n,t);if("blend"===e.kind)return j(e.kids.map(e=>N(e,n,o)).filter(e=>null!==e),e.k);let[a,...r]=e.kids,l=a?N(a,n,t):null;if(!l)return null;if("carve"===e.kind)return function(e,n,t){let[o,a]=n;return o?a?(o,a,r)=>{let l=e(o,a,r);for(let e of n)l=h(l,-e(o,a,r),t);return l}:(n,a,r)=>h(e(n,a,r),-o(n,a,r),t):e}(l,r.map(e=>N(e,n,o)).filter(e=>null!==e),e.k);let i=r.map(e=>N(e,n,t));return i.some(e=>null===e)?null:function(e,n){return(t,o,a)=>{let r=-1/0;for(let l of e)r=h(r,l(t,o,a),n);return r}}([l,...i],e.k)}(e,n,t)}}var I=1.7320508075688772;function _(e,n){let t=2*(3&n),o=2*(n>>2&3),a=2*(n>>4);for(let n=0;n<27;n+=1){let r=t+n%3,l=o+Math.floor(n/3)%3,i=a+Math.floor(n/9),s=9*(9*i+l)+r;Number.isNaN(e.values[s]??0)&&(e.values[s]=e.field(e.o[0]+r*e.h,e.o[1]+l*e.h,e.o[2]+i*e.h))}}function G(e,n){let{cell:t,lo:o}=e.grid,a=[o[0]+8*n[0]*t,o[1]+8*n[1]*t,o[2]+8*n[2]*t],r=[a[0]+8*t/2,a[1]+8*t/2,a[2]+8*t/2,8*t*I/2],l=N(e.node,r,2*t);if(!l||Math.abs(l(r[0],r[1],r[2]))>r[3]+t)return;let i=function(e,n,t){let o={field:e,o:n,h:t,values:new Float64Array(729).fill(Number.NaN)},a=new Float64Array(64),r=I*t*1.15+.25*t;for(let l=0;l<64;l+=1){let i=e(n[0]+(2*(3&l)+1)*t,n[1]+(2*(l>>2&3)+1)*t,n[2]+(2*(l>>4)+1)*t);a[l]=i,Math.abs(i)<=r&&_(o,l)}for(let e=0;e<729;e+=1){if(!Number.isNaN(o.values[e]??0))continue;let[n,t,r]=[e%9,Math.floor(e/9)%9,Math.floor(e/81)];o.values[e]=a[4*(4*Math.min(3,r>>1)+Math.min(3,t>>1))+Math.min(3,n>>1)]??0}return o.values}(l,a,t),s=0;for(let e of i)e<0&&(s+=1);return 0!==s&&729!==s?{field:l,ball:r,o:a,at:n,values:i,verts:new Int32Array(512).fill(-1)}:void 0}var H=[0,2,4,6,0,1,4,5,0,1,2,3],U=[1,3,5,7,2,3,6,7,4,5,6,7],$=[0,1,9,10,81,82,90,91];function J(e,n,t){for(let o=0;o<8;o+=1)t[o]=e[n+($[o]??0)]??0}function Q(e,n){let[t,o,a,r]=[0,0,0,0];for(let n=0;n<12;n+=1){let l=H[n]??0,i=U[n]??0,s=e[l]??0,u=e[i]??0;if(s<0==u<0)continue;let c=s/(s-u);t+=(1&l)+((1&i)-(1&l))*c,o+=(l>>1&1)+((i>>1&1)-(l>>1&1))*c,a+=(l>>2&1)+((i>>2&1)-(l>>2&1))*c,r+=1}return 0!==r&&(n[0]=t/r,n[1]=o/r,n[2]=a/r,!0)}function X(e,n){let t=n[0]??0,o=n[1]??0,a=n[2]??0,r=n=>e[n]??0,l=r(0)+(r(1)-r(0))*t,i=r(2)+(r(3)-r(2))*t,s=r(4)+(r(5)-r(4))*t,u=l+(i-l)*o;return u+(s+(r(6)+(r(7)-r(6))*t-s)*o-u)*a}function Y(e,n,t){let[o,a,r]=n,l=e(o+t,a-t,r-t),i=e(o-t,a-t,r+t),s=e(o-t,a+t,r-t),u=e(o+t,a+t,r+t),c=l-i-s+u,h=-l-i+s+u,d=-l+i-s+u,f=Math.sqrt(c*c+h*h+d*d);return f>0?[c/f,h/f,d/f]:[0,1,0]}var Z=new Float64Array(8),ee=new Float64Array(3);function ne(e,n){let[t,o]=e.nb,[a=-1,r=-1,l=-1]=n;if(a<0||r<0||l<0)return-1;let i=e.blocks[((l>>3)*o+(r>>3))*t+(a>>3)];return i?i.verts[8*(8*(7&l)+(7&r))+(7&a)]??-1:-1}function te(e,n,t){let[o=-1,a=-1,r=-1,l=-1]=t?[n[3],n[2],n[1],n[0]]:n;if(o<0||a<0||r<0||l<0)return;let i=e.pos,s=(e,n)=>{let t=(i[3*e]??0)-(i[3*n]??0),o=(i[3*e+1]??0)-(i[3*n+1]??0),a=(i[3*e+2]??0)-(i[3*n+2]??0);return t*t+o*o+a*a};s(o,r)<=s(a,l)?e.tri.push(o,a,r,o,r,l):e.tri.push(o,a,l,a,r,l)}var oe=[[[0,0,0],[0,-1,0],[0,-1,-1],[0,0,-1]],[[0,0,0],[0,0,-1],[-1,0,-1],[-1,0,0]],[[0,0,0],[-1,0,0],[-1,-1,0],[0,-1,0]]],ae=[1,9,81];function re(e,n){for(let t=0;t<512;t+=1){if(-1===n.verts[t])continue;let[o,a,r]=[7&t,t>>3&7,t>>6],l=9*(9*r+a)+o,i=(n.values[l]??0)<0,s=[8*n.at[0]+o,8*n.at[1]+a,8*n.at[2]+r];oe.forEach((t,o)=>{i!==(n.values[l+(ae[o]??0)]??0)<0&&te(e,t.map(n=>ne(e,[s[0]+n[0],s[1]+n[1],s[2]+n[2]])),!i)})}}function le(e,n,t,o){let{pos:a,nor:r}=n,[l,i,s]=[0,1,0];for(let n=1;n<=2;n+=1){let u=o*n/2,c=e=>(a[3*t+e]??0)+(r[3*t+e]??0)*u;l+=i*Math.max(0,u-e(c(0),c(1),c(2)))/u,s+=i,i*=.7}return Math.max(0,1-l/s)}function ie(e,n){let{lo:t,hi:o,cell:a}=n,r=[0,1,2].map(e=>Math.ceil(((o[e]??0)-(t[e]??0))/a/8)),l={node:e,grid:n,nb:r,blocks:[],pos:[],owner:[],nor:[],tri:[]},i=r[0]*r[1]*r[2];for(let e=0;e<i;e+=1)l.blocks[e]=G(l,[e%r[0],Math.floor(e/r[0])%r[1],Math.floor(e/(r[0]*r[1]))]);l.blocks.forEach((e,n)=>{e&&function(e,n,t){let{cell:o}=e.grid;for(let a=0;a<512;a+=1){let r=7&a,l=a>>3&7,i=a>>6;if(J(n.values,9*(9*i+l)+r,Z),!Q(Z,ee))continue;let s=[n.o[0]+(r+(ee[0]??0))*o,n.o[1]+(l+(ee[1]??0))*o,n.o[2]+(i+(ee[2]??0))*o],u=Y(n.field,s,o/4),c=Math.max(-o/2,Math.min(o/2,X(Z,ee)));n.verts[a]=e.owner.length,e.owner.push(t),e.pos.push(s[0]-u[0]*c,s[1]-u[1]*c,s[2]-u[2]*c),e.nor.push(u[0],u[1],u[2])}}(l,e,n)});for(let e of l.blocks)e&&re(l,e);return function(e){let{cell:n,reach:t,shade:o}=e.grid,a=e.owner.length,r=new Float32Array(a).fill(1),l=o?A(0,e.node,o):e.node;for(let o=0;t>0&&o<a;o+=1){let a=e.blocks[e.owner[o]??0];if(!a)continue;let i=[a.ball[0],a.ball[1],a.ball[2],a.ball[3]+t];a.wide??=N(l,i,2*n)??a.field,r[o]=le(a.wide,e,o,t)}let i=Float32Array.from(e.nor);return{position:Float32Array.from(e.pos),normal:i,open:r,index:Uint32Array.from(e.tri)}}(l)}var se=6.283185307179586;function ue(e,n,a){let r=.076*t(n),l=.086*o(n)-.062,i=Math.sqrt(1.1296),s=p(a.turn,r,e.edge*i+.36*l+.008,l);return[s[0]+a.at[0],s[1]+a.at[1],s[2]+a.at[2]]}function ce(e){let n=Math.sqrt((e[0]??0)**2+(e[1]??0)**2+(e[2]??0)**2)||1;return[(e[0]??0)/n,(e[1]??0)/n,(e[2]??0)/n]}function he(e,n,t){let{body:o,gap:a,centre:r}=e,l=t/24,i=[[...n]],s=[...n],u=ce([.3*(n[0]-r[0]),-1,.5*(n[2]-r[2])]);for(let e=1;e<=24;e+=1){let e=ce([s[0]-r[0],0,s[2]-r[2]]);u=ce([.8*u[0]+.07*e[0],.8*u[1]-.2,.8*u[2]+.07*e[2]]),s=[s[0]+u[0]*l,s[1]+u[1]*l,s[2]+u[2]*l];for(let e=0;e<3;e+=1){let e=o(s[0],s[1],s[2])-a;if(e>=0)break;let n=Y(o,s,.002);s=[s[0]-n[0]*e,s[1]-n[1]*e,s[2]-n[2]*e]}i.push(s)}return i}function de(e,n){let a=e.guide,r=n*(a.length-1),l=Math.min(a.length-2,Math.floor(r)),i=r-l,s=a[l]??[0,0,0],u=a[l+1]??s,c=[s[0]+(u[0]-s[0])*i,s[1]+(u[1]-s[1])*i,s[2]+(u[2]-s[2])*i],h=ce([u[0]-s[0],u[1]-s[1],u[2]-s[2]]),d=ce([c[0]-e.centre[0],0,c[2]-e.centre[2]]),f=ce([h[1]*d[2]-h[2]*d[1],h[2]*d[0]-h[0]*d[2],h[0]*d[1]-h[1]*d[0]]),p=ce([f[1]*h[2]-f[2]*h[1],f[2]*h[0]-f[0]*h[2],f[0]*h[1]-f[1]*h[0]]),v=se*n*e.length/e.wave+e.phase,m=Math.min(1,3*n)*e.curl,[w,b]=[o(v)*m,t(v)*m];return{at:[c[0]+f[0]*w+p[0]*b,c[1]+f[1]*w+p[1]*b,c[2]+f[2]*w+p[2]*b],tangent:h,side:f,out:p}}var fe={bend:[[4,6,4],[62,88,55],[74,92,55],[82,92,50]],spread:[4,0,-4,-9],thumbTo:[1,.85]},pe={bend:[[38,46,18],[52,70,40],[64,80,45],[74,86,45]],spread:[2,0,-5,-10],thumbTo:[0,.7]},ve=[[.027,.093,.001],[.008,.097,0],[-.011,.093,-.001],[-.027,.084,-.002]],me=[[.045,.027,.022],[.049,.03,.023],[.046,.029,.022],[.036,.021,.02]],we=[.0077,.0079,.0074,.0065],be=(e,n,t)=>[e[0]+n[0]*t,e[1]+n[1]*t,e[2]+n[2]*t];function ye(e,n){let[t,o,a,r]=e.joints,l=e.radius,i=n?[1.15,1,.9,.78]:[1,.92,.86,.78],[s,u,c,h]=i.map(e=>e*l),d=be([(a[0]+r[0])/2,(a[1]+r[1])/2,(a[2]+r[2])/2],e.back,.35*-h);return A(.003,y(t,o,s,u),y(o,a,.97*u,c),y(a,r,.97*c,h),w(d,.9*h),w(o,.97*u),w(a,.94*c))}var ge=.0118,xe=.005,ke=e=>[e(1),e(-1)];function Me(e,n){let t=[e*n.eyes,0,xe],o=r(0,0,-e*a(4)),l=T(.0012,w([0,0,0],.0129),k([0,-.9,.436],.0018)),i=T(.0012,w([0,0,0],ge+7e-4),k([0,.93,.37],0));return[F(o,t,l),F(o,t,i)]}function Ae(e,n){let t=new Float32Array(e.position.length),o=new Float32Array(e.normal.length);for(let a=0;a<t.length;a+=3){let r=p(n.turn,e.position[a]??0,e.position[a+1]??0,e.position[a+2]??0);t.set([r[0]+n.at[0],r[1]+n.at[1],r[2]+n.at[2]],a),o.set(p(n.turn,e.normal[a]??0,e.normal[a+1]??0,e.normal[a+2]??0),a)}return{...e,position:t,normal:o}}var Ce=6.283185307179586,Se=[.12,.12/1.586,9e-4];function Te(e,n,t){let o=e.position.length/3,a=t>0?1:-1;e.position.push(0,0,t),e.normal.push(0,0,a);for(let[o=0,r=0]of n)e.position.push(o,r,t),e.normal.push(0,0,a);n.forEach((a,r)=>{let l=o+1+r,i=o+1+(r+1)%n.length;e.index.push(...t>0?[o,l,i]:[o,i,l])})}function Fe(e,n){let a=Se[2],r=function(){let[e,n]=Se,a=.037*e,r=[];for(let l=0;l<28;l+=1){let[i,s]=[Math.floor(l/7),l%7],u=(0===i||3===i?1:-1)*(e/2-a),c=(i<2?1:-1)*(n/2-a),h=(i+s/6)*(Ce/4);r.push([u+o(h)*a,c+t(h)*a,o(h),t(h)])}return r}(),l={position:[],normal:[],index:[]};Te(l,r,a/2),Te(l,r,-a/2);let i=l.position.length/3;for(let[e,n,t,o]of r)l.position.push(e,n,a/2,e,n,-a/2),l.normal.push(t,o,0,t,o,0);r.forEach((e,n)=>{let t=i+2*n,o=i+(n+1)%r.length*2;l.index.push(t,t+1,o,o,t+1,o+1)});let s=Float32Array.from(l.position);return Ae({name:"card",kind:e,position:s,normal:Float32Array.from(l.normal),open:new Float32Array(s.length/3).fill(1),rest:s.slice(),index:Uint32Array.from(l.index)},n)}function qe(e,n,a){let r=N(a,[0,0,0,1],1)??(()=>1),l=n.map(e=>{let n=[e[0],e[1],e[2]];for(let e=0;e<6;e+=1){let e=r(n[0],n[1],n[2])-.0016,t=Y(r,n,.001);n=[n[0]-t[0]*e,n[1]-t[1]*e,n[2]-t[2]*e]}return n}),i=[],s=[],u=[],c=[];return l.forEach((e,n)=>{let a=l[Math.max(0,n-1)]??e,h=l[Math.min(l.length-1,n+1)]??e,d=[h[0]-a[0],h[1]-a[1],h[2]-a[2]],f=Math.sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2])||1,p=Y(r,e,.001),v=[p[1]*d[2]-p[2]*d[1],p[2]*d[0]-p[0]*d[2],p[0]*d[1]-p[1]*d[0]].map(e=>e/f);for(let a=0;a<6;a+=1){let r=a/6*Ce,h=[0,1,2].map(e=>(p[e]??0)*o(r)+(v[e]??0)*t(r));if(i.push(...[0,1,2].map(n=>(e[n]??0)+.0011*(h[n]??0))),s.push(...h),u.push(n/l.length,a/6,0),n<l.length-1){let e=6*n+a,t=6*n+(a+1)%6;c.push(e,t,e+6,t,t+6,e+6)}}}),{name:"chain",kind:e,position:Float32Array.from(i),normal:Float32Array.from(s),open:new Float32Array(i.length/3).fill(.8),rest:Float32Array.from(u),index:Uint32Array.from(c)}}var Re={skin:0,hand:1,eye:2,cap:3,hair:4,dress:5,chemise:6,gown:7,gold:8,card:9},ze={hero:{face:.0018,body:.004,hand:.0022,cloth:.0065,eye:40,locks:220,segments:44,sides:8},mid:{face:.0026,body:.005,hand:.002,cloth:.006,eye:24,locks:160,segments:22,sides:6},far:{face:.005,body:.009,hand:.004,cloth:.011,eye:12,locks:80,segments:12,sides:5}},Le=[0,.168,.035];function Oe(e){let n="A"===e?[0,-.07,-.05]:[0,0,-.05],t="A"===e?r(a(3),a(1),a(-3)):r(a(20),a(-24),a(-3)),[o,l,i]=p(t,-n[0],-n[1],-n[2]);return{turn:t,at:[o+n[0]+Le[0],l+n[1]+Le[1],i+n[2]+Le[2]]}}function Ke(e,n){let t=new Float32Array(e.length);for(let o=0;o<e.length;o+=3)t.set(f(n.turn,(e[o]??0)-n.at[0],(e[o+1]??0)-n.at[1],(e[o+2]??0)-n.at[2]),o);return t}function Ee(e,n,t){let o=A(.012,F(n.turn,n.at,function(e){let n=ke(n=>b([n*e.eyes,.002,.011],[.017,.0125,.0105])),t=A(.006,function(e){return A(.02,function(e){let[n,t,o,a]=[-.005,.108,.101,-.045],[r,l,i]=[.067*e.cheeks,.058,.033*e.jaw],[s,u,c]=[.07,.0025,-.0125];return{kind:"prim",bound:[0,n,a,.125],f:(e,h,d)=>{let f=h>n?t:o,p=Math.max(-1,Math.min(1,(h-n)/f)),v=p>0?r+(l-r)*p*p:r+(r-i)*p*p*p,m=s+u*p+c*p*p,w=e/v,b=(h-n)/f,y=(d-a)/m,g=b<0?.6:0,x=b*b*(1-g+g*b*b),k=b*(1-g+2*g*b*b),M=Math.sqrt(w*w+x+y*y),A=Math.sqrt(w*w/(v*v)+k*k/(f*f)+y*y/(m*m));return A>1e-12?M*(M-1)/A:-.03}}}(e),b([0,.026,-.068],[.071,.094,.092]),b([0,-.064*e.chin,-.004],[.028,.024,.026]),b([0,-.092*e.chin,-.001],[.02,.014,.016]),...ke(n=>b([.03*n*e.cheeks,-.036,.004],[.022,.024,.017])),...ke(e=>b([.04*e,-.016,-.004],[.02,.013,.02])))}(e),...ke(e=>b([.026*e,.017,.01],[.022,.0075,.012],r(0,e*a(20),0))));return t=A(.006,t,function(e){let n=[0,-.038*e.nose,.036];return A(.007,y([0,.006,.019],[0,n[1]+.006,n[2]-.001],.0062,.0056),w(n,.0078),...ke(e=>b([.0105*e,n[1]-.005,.025],[.0056,.005,.0075],r(0,e*a(20),0))),b([0,n[1]-.007,.03],[.0036,.0035,.0065]),b([0,n[1]-.002,.02],[.014,.009,.011]))}(e)),t=S(.006,t,...n),t=A(.0022,t,...Me(1,e),...Me(-1,e)),t=A(.006,t,...function(e){let n=e.lips;return[...ke(e=>b([.009*e,-.0645,.0195],[.0132,.003*n,.0048],r(0,e*a(14),-e*a(7)))),b([0,-.066,.0225],[.0045,.003*n,.0035]),b([0,-.0722,.018],[.0165,.0042*n,.0052])]}(e)),t=S(.0012,t,b([0,-.068,.025],[.0225*e.lips,7e-4,.006]),...ke(n=>b([.006*n,-.047*e.nose,.025],[.0028,.0017,.0042],r(0,n*a(20),0)))),t=S(.004,t,b([0,-.056,.0262],[.003,.006,.0014]),b([0,-.081,.021],[.013,.0035,.005])),A(.004,t,...ke(e=>S(.003,b([.071*e,-.012,-.072],[.0095,.029,.018],r(a(-12),e*a(-18),0)),b([.078*e,-.016,-.069],[.006,.012,.008]))))}(e)),z(),L(R,-6e-4)),l=ie(o,{lo:[-.105,.055,-.045],hi:[.105,.225,.13],cell:t.face,reach:.014}),i=ie(o,{lo:[-.18,-.105,-.075],hi:[.18,.075,.1],cell:t.body,reach:.02});return[{name:"skin",kind:Re.skin,...l,rest:Ke(l.position,n)},{name:"chest",kind:Re.skin,...i,rest:Ke(i.position,n)}]}var Pe={chemise:[[-.16,-.16,-.06],[.16,0,.1]],dress:[[-.32,-.3,-.035],[.16,.06,.32]],gown:[[-.36,-.3,-.2],[.36,.1,.32]]};function De(e,n,t,o){let[a,r]=Pe[e]??[[-.36,-.46,-.2],[.36,.1,.32]],l=ie(t,{lo:a,hi:r,cell:"chemise"===e?.75*o.cloth:o.cloth,reach:.03});return{name:e,kind:n,...l,rest:l.position.slice()}}function Be(e,n,a){let r=Oe("A"),l=V(n),s=F(r.turn,r.at,function(e){let[n,t,o]=e.normal,a=k([-n,-t,-o],-e.edge),r=e.edge+e.cuff;return A(.0015,T(.004,W(0),a),T(.004,W(.0055),a,k([n,t,o],r)))}(l)),u=ie(s,{lo:[-.13,.13,-.19],hi:[.15,.36,.1],cell:.7*a.cloth,reach:.02}),c=ie(F(r.turn,r.at,A(.03,b([0,-.01,-.075],[.078,.1,.068]),...[1,-1].map(e=>b([.062*e,-.075,-.105],[.026,.085,.036])),b([0,-.09,-.11],[.07,.11,.03]))),{lo:[-.14,-.08,-.2],hi:[.14,.26,.06],cell:1.5*a.cloth,reach:0}),h=N(A(.01,F(r.turn,r.at,b([0,-.01,-.035],[.078,.122,.1])),z(),L(R,.03)),[0,0,0,1],1),d=function(e,n,a,r){let l=function(e,n,t,o){let a=p(o.turn,0,0,-.06).map((e,n)=>e+(o.at[n]??0)),r=[],{seed:l,locks:s}=e;for(let u=0;u<s;u+=1){let s=u%2==0?1:-1,c=i(l,u,1),h=s*(.95+2.2*i(l,u,2)),d=e.length*(.75+.35*i(l,u,3))*(1-.25*c),f=he({body:t,gap:.003+.016*c,centre:a},ue(n,h,o),d);r.push({guide:f,length:d,centre:a,width:.011+.01*i(l,u,4),thick:.004+.002*i(l,u,5),curl:.004+.005*i(l,u,6),wave:.045+.03*i(l,u,7),phase:se*i(l,u,8),tone:.6*i(l,u,9)+.4*c})}return r}(e,n,a,r),{segments:s,sides:u}=e,c=(s+1)*u,h=l.length*c,d=new Float32Array(3*h),f=new Float32Array(3*h),v=new Float32Array(3*h),m=new Float32Array(4*h),w=new Float32Array(h),b=[];return l.forEach((e,n)=>{for(let a=0;a<=s;a+=1){let r=a/s,{at:l,tangent:i,side:h,out:p}=de(e,r),y=(1-r*r*r*.85)*Math.min(1,.4+8*r);for(let g=0;g<u;g+=1){let x=se*g/u,[k,M]=[o(x),t(x)],A=n*c+a*u+g,C=ce([h[0]*k+p[0]*M,h[1]*k+p[1]*M,h[2]*k+p[2]*M]),S=e.width*y*k,T=e.thick*y*M,F=[0,1,2].map(e=>(l[e]??0)+(h[e]??0)*S+(p[e]??0)*T);if(d.set(F,3*A),f.set(C,3*A),v.set([g/u,r,e.tone],3*A),m.set([...i,e.tone],4*A),w[A]=.35+.65*(.5+.5*M)*(.55+.45*e.tone),a<s){let e=(g+1)%u,t=n*c+a*u;b.push(t+g,t+e,t+u+g,t+e,t+u+e,t+u+g)}}}}),{position:d,normal:f,rest:v,flow:m,open:w,index:Uint32Array.from(b)}}({seed:e,locks:a.locks,segments:a.segments,sides:a.sides,length:.28},l,h??(()=>1),r);return[{name:"cap",kind:Re.cap,...u,rest:Ke(u.position,r)},{name:"under",kind:Re.hair,...c,rest:new Float32Array(c.position.length).fill(.5),flow:void 0},{name:"hair",kind:Re.hair,...d}]}function Ve(e){return{eyes:s(e,1,.0285,.03),nose:s(e,2,.9,.96),lips:s(e,3,.94,1.06),jaw:s(e,4,.95,1.03),chin:s(e,5,.97,1.03),cheeks:s(e,6,.96,1.04)}}var We=r(a(-12),a(28),a(-14)),je=new Map;function Ne(e){let n=e.detail;return l(e.seed,"A"===e.face?1:2,"point"===e.hand?1:2,Math.round(1e6*n.face),Math.round(1e6*n.body),Math.round(1e6*n.hand),Math.round(1e6*n.cloth),n.eye,n.locks,n.segments,n.sides).toString(16).padStart(8,"0")}function Ie(e){let n=Ne(e),l=je.get(n);if(l)return l;let i=Oe(e.face),s=Ve(e.seed),u=[[s.eyes,0,xe],[-s.eyes,0,xe]],c=e.detail,h=function(e,n){let l=function(e){let n=[0,1,2,3].map(n=>function(e,n){let r=me[e]??[.04,.025,.02],l=n.bend[e]??[0,0,0],i=a(n.spread[e]??0),[s,u]=[t(i),o(i)],c=ve[e]??[0,.09,0],h=[c],d=0,f=[0,1,0];for(let e=0;e<3;e+=1){d+=a(l[e]??0);let[n,i]=[t(d),o(d)];f=[s*i,u*i,n],c=be(c,f,r[e]??.02),h.push(c)}let[p,v]=[t(d),o(d)];return{joints:h,radius:we[e]??.008,back:[s*p,u*p,-v]}}(n,e)),r=function(e,n){let t=[.022,.024,.006],o=be(t,[.62,.6,.5],.042/Math.sqrt(.9944)),[a,r]=[.031,.027],l=be(o,[.2,.75,.62],.05);if(e.thumbTo){let t=n[e.thumbTo[0]],a=t?.joints[2]??o,r=t?.joints[3]??o,i=e.thumbTo[1],s=[a[0]+(r[0]-a[0])*i,a[1]+(r[1]-a[1])*i,a[2]+(r[2]-a[2])*i];l=be(s,t?.back??[0,0,-1],-((t?.radius??.008)+.0088))}let i=[l[0]-o[0],l[1]-o[1],l[2]-o[2]],s=Math.min(a+r-1e-4,Math.sqrt(i[0]*i[0]+i[1]*i[1]+i[2]*i[2])),u=[i[0]/s,i[1]/s,i[2]/s],c=[.8,-.2,-.55],h=c[0]*u[0]+c[1]*u[1]+c[2]*u[2],d=[c[0]-u[0]*h,c[1]-u[1]*h,c[2]-u[2]*h],f=Math.sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2])||1,p=(a*a-r*r+s*s)/(2*s),v=Math.sqrt(Math.max(0,a*a-p*p));return{joints:[t,o,be(be(o,u,p),d,v/f),be(o,u,s)],radius:.0102,back:[d[0]/f,d[1]/f,d[2]/f]}}(e,n);return{node:C(A(.008,x([0,.052,-.001],[.03,.04,.0075],.0085),b([.019,.034,.01],[.017,.027,.012]),b([-.021,.042,.007],[.011,.03,.01]),b([0,-.012,-.002],[.026,.035,.018])),[...n.map(e=>ye(e,!1)),ye(r,!0)],[.005,.005,.005,.005,.011]),fingers:n,thumb:r}}("point"===e?fe:pe),i=ie(l.node,{lo:[-.05,-.06,-.05],hi:[.075,.2,.08],cell:n.hand,reach:.012}),s={turn:We,at:R.wrist},u=Ae({name:"hand",kind:Re.hand,...i,rest:i.position.slice()},s),c=l.fingers[0]?.joints[3]??[0,.18,0],h=l.fingers[0]?.joints[2]??c,d="point"===e?{turn:r(a(-10),a(15),a(36)),at:[c[0]+.014,c[1]+.05,c[2]+.004]}:{turn:r(a(-8),a(-30),a(-10)),at:[h[0]-.012,h[1]+.045,h[2]+.004]},f={turn:v(d.turn,We),at:p(We,...d.at).map((e,n)=>e+(R.wrist[n]??0))},m=[...l.fingers,l.thumb].map(e=>({from:e.joints[2]??[0,0,0],to:e.joints[3]??[0,0,0],radius:e.radius,back:e.back}));return{parts:[u,Fe(Re.card,f)],card:f,nails:m}}(e.hand,c),d={parts:[...Ee(s,i,c),...u.map(e=>function(e,n,a,r){let{centre:l,radius:i}=n,s=[],u=[],c=[];for(let e=0;e<(a+1)*(a+1);e+=1){let[n,r]=[Math.floor(e/(a+1)),e%(a+1)],h=n/a*2-1,d=Math.sqrt(1-h*h),f=r/a*Ce;s.push(l[0]+d*o(f)*i,l[1]+d*t(f)*i,l[2]+h*i),u.push(d*o(f),d*t(f),h),n<a&&r<a&&c.push(e,e+1,e+a+1,e+1,e+a+2,e+a+1)}return Ae({name:"eye",kind:e,position:Float32Array.from(s),normal:Float32Array.from(u),open:new Float32Array(s.length/3).fill(1),rest:Float32Array.from(s),index:Uint32Array.from(c)},r)}(Re.eye,{centre:e,radius:ge},c.eye,i)),...Be(e.seed,e.face,c),De("chemise",Re.chemise,E(R),c),De("dress",Re.dress,P(R),c),De("gown",Re.gown,D(R),c),qe(Re.gold,B(160),A(.012,z(),L(R,0))),...h.parts],pose:i,eyes:u,cap:V(e.face),card:h.card,nails:h.nails};return je.set(n,d),d}var _e={skin:"#dbb294",lip:"#c4766e",blush:"#e3a491",brow:"#8a5638",iris:"#7b8c87",sclera:"#efe9e0",cap:"#ff2f78",hair:"#b0562a",dress:"#626658",chemise:"#e8e4d8",gown:"#171b19",gold:"#c9a24a",card:"#ff2a62"},Ge={key:[-t(a(40))*o(a(35)),t(a(35)),o(a(40))*o(a(35))],keyColor:"#fff1dc",keyStrength:1.8,sky:"#c9d6d9",ground:"#8d8a7c",fillStrength:.42},He=(e,n)=>{let t=new e.Color(n);return new e.Vector3(t.r,t.g,t.b)};function Ue(e,n,r){let[l,i]=n.eyes,s=n.pose.turn,u=new e.Matrix3;u.set(s[0],s[3],s[6],s[1],s[4],s[7],s[2],s[5],s[8]);let c=n=>({value:He(e,n)});return{uKey:{value:new e.Vector3},uKeyColor:{value:new e.Vector3},uSky:{value:new e.Vector3},uGround:{value:new e.Vector3},uFillDir:{value:new e.Vector3(.3,.9,.3)},uShadowMap:{value:null},uShadow:{value:new e.Vector4(0,0,0,0)},uShadowMatrix:{value:new e.Matrix4},uShadowBox:{value:new e.Vector2(1,1)},uShadowFar:{value:1},uTime:{value:0},uEyeL:{value:new e.Vector4(l[0],l[1],l[2],ge)},uEyeR:{value:new e.Vector4(i[0],i[1],i[2],ge)},uLid:{value:new e.Vector4(0,t(a(4)),o(a(4)),0)},uLookL:{value:new e.Vector3(0,0,1)},uLookR:{value:new e.Vector3(0,0,1)},uHeadTurn:{value:u},uSkinTone:c(r.skin),uLipTone:c(r.lip),uBlushTone:c(r.blush),uBrowTone:c(r.brow),uIris:c(r.iris),uSclera:c(r.sclera),...$e(e,n,r)}}function $e(e,n,t){let{normal:o,edge:a,cuff:r,centre:l}=n.cap,i=(n,t)=>{let o=new e.Color(n);return new e.Vector3(o.r*t,o.g*t,o.b*t)},s=(n,t)=>new e.Vector4(n[0],n[1],n[2],t);return{uCapAxis:{value:s(o,a)},uCapCentre:{value:s(l,r)},uCapTones:{value:[i(t.cap,1),i(t.cap,.62),i("#ff9bbd",1)]},uHairTones:{value:[i(t.hair,.4),i(t.hair,.95),i("#c8783c",1)]},uWrist:{value:new e.Vector3(...R.wrist)},uElbow:{value:new e.Vector3(...R.elbow)},uTips:{value:n.nails.map(e=>s(e.from,e.radius))},uTipEnds:{value:n.nails.map(e=>s(e.to,0))},uBacks:{value:n.nails.map(n=>new e.Vector3(...n.back))}}}var Je=["skin","skin","sclera","cap","hair","dress","chemise","gown","gold","card"];function Qe(e,n,t){let{lit:o}=e,a=function(e,n){let t=new e.Geometry;return t.setAttribute("position",new e.Attribute(n.position,3)),t.setAttribute("normal",new e.Attribute(n.normal,3)),t.setAttribute("aOpen",new e.Attribute(n.open,1)),t.setAttribute("aRest",new e.Attribute(n.rest,3)),t.setAttribute("aFlow",new e.Attribute(n.flow??new Float32Array(n.position.length/3*4),4)),t.setIndex(new e.Attribute(n.index,1)),t}(o,n),r=new o.CustomMaterial({defines:{PART:n.kind},uniforms:{...e.uniforms,uColor:{value:He(o,t[Je[n.kind]??"skin"])}},vertexShader:"\nattribute float aOpen;\nattribute vec3 aRest;\nattribute vec4 aFlow;\nvarying vec3 vWorld;\nvarying vec3 vNormal;\nvarying vec3 vRest;\nvarying vec4 vFlow;\nvarying float vOpen;\nvarying vec4 vShadowAt;\nuniform mat4 uShadowMatrix; // the world into the key light's view\nvoid main() {\n vec4 world = modelMatrix * vec4(position, 1.0);\n vWorld = world.xyz;\n vNormal = normalize(mat3(modelMatrix) * normal);\n vRest = aRest;\n vFlow = vec4(normalize(mat3(modelMatrix) * (aFlow.xyz + vec3(0.0, 1e-6, 0.0))), aFlow.w);\n vOpen = aOpen;\n vShadowAt = uShadowMatrix * world;\n gl_Position = projectionMatrix * viewMatrix * world;\n}\n",fragmentShader:"\n\nuniform vec3 uKey; // toward the key light\nuniform vec3 uKeyColor;\nuniform vec3 uSky; // the fill's sky and ground colours\nuniform vec3 uGround;\nuniform vec3 uFillDir;\nuniform sampler2D uShadowMap;\nuniform vec4 uShadow; // texel, softness in texels, bias, on\nuniform vec2 uShadowBox; // the light view's half width and far plane\nuniform float uTime;\nvarying vec3 vWorld;\nvarying vec3 vNormal;\nvarying vec3 vRest;\nvarying vec4 vFlow;\nvarying float vOpen;\nvarying vec4 vShadowAt;\n\nfloat hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }\nfloat noise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n f = f * f * (3.0 - 2.0 * f);\n return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);\n}\nfloat fbm(vec2 p) { return 0.5 * noise(p) + 0.3 * noise(p * 2.03 + 7.1) + 0.2 * noise(p * 4.1 + 3.3); }\n\n// The key's soft shadow: a ring of samples in the light's depth map.\nfloat keyShadow(vec3 n) {\n if (uShadow.w < 0.5) return 1.0;\n vec2 uv = vShadowAt.xy / uShadowBox.x * 0.5 + 0.5;\n if (uv.x < 0.0 || uv.y < 0.0 || uv.x > 1.0 || uv.y > 1.0) return 1.0;\n float depth = -vShadowAt.z / uShadowBox.y;\n float bias = uShadow.z * (1.0 + 3.0 * (1.0 - clamp(dot(n, uKey), 0.0, 1.0)));\n float lit = 0.0;\n float spin = hash(gl_FragCoord.xy) * 6.2832;\n for (int i = 0; i < 12; i++) {\n float a = spin + float(i) * 2.39996;\n float r = sqrt((float(i) + 0.5) / 12.0) * uShadow.y;\n vec2 o = vec2(cos(a), sin(a)) * r * uShadow.x;\n lit += texture2D(uShadowMap, uv + o).r + bias < depth ? 0.0 : 1.0;\n }\n return lit / 12.0;\n}\n\nvec3 fill(vec3 n) { return mix(uGround, uSky, dot(n, uFillDir) * 0.5 + 0.5); }\n\n\nuniform vec4 uEyeL; // the eyes' centres in the head's frame, and the eye's radius\nuniform vec4 uEyeR;\nuniform vec4 uLid; // how far the lids are down (0 open, 1 shut), tilt's sine and cosine\nuniform vec3 uSkinTone;\nuniform vec3 uLipTone;\nuniform vec3 uBlushTone;\nuniform vec3 uBrowTone;\n\n// How far below the eye's centre the open upper lid's edge sits (head.ts, LID_DROP).\nconst float LID_DROP = 0.0018;\n\nfloat ellipse(vec2 p, vec2 c, vec2 r) { vec2 q = (p - c) / r; return dot(q, q); }\n\n// Where the upper lid's edge is, as a distance past it (+ on the lid), in the eye's own frame.\nvec3 eyeFrame(vec3 p, vec4 eye, float side) {\n vec3 q = p - eye.xyz;\n float s = uLid.y * side;\n return vec3(uLid.z * q.x + s * q.y, -s * q.x + uLid.z * q.y, q.z);\n}\n\n// Lips, blush, brows, the line of the lashes: painted from where the skin lies on the head at rest.\nvec3 skinAlbedo(vec3 r, out float gloss) {\n vec3 base = uSkinTone;\n gloss = 0.25;\n float front = smoothstep(0.005, 0.02, r.z);\n float ax = abs(r.x);\n // Blush on the cheeks, the nose's tip, the ears and the chin.\n float blush = exp(-ellipse(vec2(ax, r.y), vec2(0.036, -0.026), vec2(0.022, 0.018)));\n blush += 0.45 * exp(-ellipse(r.xy, vec2(0.0, -0.041), vec2(0.009, 0.008)));\n blush += 0.25 * exp(-ellipse(r.xy, vec2(0.0, -0.098), vec2(0.012, 0.01)));\n blush += 0.6 * smoothstep(0.06, 0.075, ax) * (1.0 - smoothstep(-0.045, -0.06, r.z));\n base = mix(base, uBlushTone, clamp(blush * 0.5, 0.0, 0.6));\n // Lips.\n float upper = min(ellipse(vec2(ax, r.y), vec2(0.009, -0.0643), vec2(0.0138, 0.0033)),\n ellipse(r.xy, vec2(0.0, -0.0655), vec2(0.005, 0.0032)));\n float lower = ellipse(r.xy, vec2(0.0, -0.0718), vec2(0.0172, 0.0056));\n float lip = (1.0 - smoothstep(0.55, 1.15, min(upper, lower))) * front;\n base = mix(base, uLipTone, lip);\n gloss = mix(gloss, 0.55, lip);\n // Brows: a soft arch of fine hairs above each eye, thinning to the tail.\n float bx = (ax - 0.029) / 0.021;\n float arch = 0.0195 + 0.0032 * (1.0 - bx * bx) - 0.0015 * max(bx, 0.0);\n float thick = 0.0024 * (1.0 - 0.55 * smoothstep(-0.6, 1.0, bx));\n float slant = mix(1.2, 0.25, smoothstep(-1.0, 0.0, bx));\n vec2 hp = vec2(ax * 2600.0 + (r.y - arch) * 2600.0 * slant, (r.y - arch) * 700.0);\n float hairs = 0.45 + 0.55 * noise(hp);\n float brow = (1.0 - smoothstep(0.0, thick, abs(r.y - arch))) * (1.0 - smoothstep(0.8, 1.15, abs(bx)));\n base = mix(base, uBrowTone, brow * hairs * 0.55 * front);\n return base;\n}\n\n// The line of the lashes along each upper lid, a lighter one along the lower.\nfloat lashes(vec3 r) {\n float side = r.x > 0.0 ? 1.0 : -1.0;\n vec4 eye = side > 0.0 ? uEyeL : uEyeR;\n vec3 q = eyeFrame(r, eye, side);\n float len2 = length(q);\n if (len2 > eye.w * 1.25 || q.z < -0.002) return 0.0;\n float up = 0.9 * q.y - 0.436 * q.z + LID_DROP;\n float low = -(0.93 * q.y + 0.37 * q.z);\n float outer = smoothstep(-0.2, 0.9, side * q.x / eye.w);\n float top = (1.0 - smoothstep(0.0, 0.0011 + 0.0007 * outer, up)) * step(0.0, up + 0.0004);\n float bottom = (1.0 - smoothstep(0.0, 0.0006, low)) * step(0.0, low + 0.0003) * 0.45;\n return max(top, bottom) * smoothstep(eye.w * 1.25, eye.w * 1.05, len2);\n}\n\nvec3 shadeSkin(vec3 albedo, float gloss, vec3 n, vec3 v, float shadow, float open) {\n float nl = dot(n, uKey);\n float wrap = clamp((nl + 0.38) / 1.38, 0.0, 1.0);\n float lit = wrap * mix(0.35, 1.0, shadow);\n // Light crossing under the skin reddens the terminator and the shadow's edge.\n float under = smoothstep(-0.35, 0.15, nl) * (1.0 - smoothstep(0.15, 0.6, nl * shadow));\n vec3 scatter = vec3(0.9, 0.28, 0.16) * under * 0.22;\n // Half-tones run cool, lights warm.\n float halftone = smoothstep(0.0, 0.35, nl) * (1.0 - smoothstep(0.35, 0.8, nl * shadow));\n vec3 tone = mix(vec3(1.0), vec3(0.9, 0.97, 1.02), halftone * 0.6);\n vec3 key = uKeyColor * (lit * tone + scatter);\n vec3 sky = fill(n) * open * (0.55 + 0.45 * open);\n vec3 h = normalize(uKey + v);\n float spec = pow(max(dot(n, h), 0.0), mix(18.0, 60.0, gloss)) * (0.03 + 0.12 * gloss) * shadow;\n return albedo * (key + sky) + uKeyColor * spec;\n}\n\n\nuniform vec3 uLookL; // where each iris faces, in the head's frame\nuniform vec3 uLookR;\nuniform vec3 uIris;\nuniform vec3 uSclera;\n\nvec3 shadeEye(vec3 n, vec3 v, float shadow) {\n float side = vRest.x > 0.0 ? 1.0 : -1.0;\n vec4 eye = side > 0.0 ? uEyeL : uEyeR;\n vec3 q = vRest - eye.xyz;\n vec3 d = normalize(q);\n vec3 look = side > 0.0 ? uLookL : uLookR;\n float c = dot(d, look);\n float r = sqrt(max(0.0, 1.0 - c * c)); // the sine off the look\n vec3 across = normalize(d - look * c + 1e-6);\n float ang = atan(dot(across, normalize(cross(look, vec3(0.0, 1.0, 0.0)))), dot(across, vec3(0.0, 1.0, 0.0)));\n float iris = 1.0 - smoothstep(0.47, 0.5, r);\n float pupil = 1.0 - smoothstep(0.15, 0.175, r);\n float fibres = 0.75 + 0.25 * noise(vec2(ang * 18.0, r * 9.0)) + 0.15 * sin(ang * 60.0);\n vec3 irisCol = uIris * fibres;\n irisCol = mix(irisCol * 1.35 + vec3(0.06, 0.03, 0.0), irisCol, smoothstep(0.17, 0.3, r));\n irisCol = mix(irisCol, irisCol * 0.35, smoothstep(0.36, 0.5, r));\n vec3 sclera = uSclera * mix(1.0, 0.82, smoothstep(0.55, 0.95, r));\n vec3 col = mix(sclera, irisCol, iris);\n col = mix(col, vec3(0.012), pupil);\n // The upper lid and its lashes shade the top of the eye.\n vec3 f = eyeFrame(vRest, eye, side);\n float up = 0.9 * f.y - 0.436 * f.z + LID_DROP;\n float lidShade = smoothstep(-0.0045, -0.0003, up);\n // Open, the lid's edge is its geometry's (a plane LID_DROP below the eye's centre); shut, it closes to the\n // lower lid.\n float covered = step(0.0, mix(up, f.y + 0.4 * f.z, uLid.x));\n vec3 wn = n;\n float nl = clamp(dot(wn, uKey), 0.0, 1.0);\n vec3 lit = uKeyColor * (0.25 + 0.75 * nl) * shadow * (1.0 - 0.75 * lidShade) + fill(wn) * 0.55 * (1.0 - 0.5 * lidShade);\n vec3 h = normalize(uKey + v);\n float glint = pow(max(dot(wn, h), 0.0), 900.0) * 9.0 * shadow * (1.0 - lidShade);\n vec3 eyeOut = col * lit + uKeyColor * glint;\n float g;\n vec3 lidOut = shadeSkin(skinAlbedo(vRest, g), 0.3, n, v, shadow, 0.8);\n return mix(eyeOut, lidOut, covered);\n}\n\nuniform vec3 uColor;\n\n// A height painted on a surface, turned into a tilt of its normal from how it changes across the screen.\nvec3 bumped(vec3 n, float height) {\n vec3 dx = dFdx(vWorld);\n vec3 dy = dFdy(vWorld);\n float hx = dFdx(height);\n float hy = dFdy(height);\n vec3 r1 = cross(dy, n);\n vec3 r2 = cross(n, dx);\n float det = dot(dx, r1);\n vec3 grad = sign(det) * (hx * r1 + hy * r2);\n return normalize(abs(det) * n - grad);\n}\n\n// Light from a soft sky and warm ground for shiny things, with the key as a soft box.\nvec3 reflected(vec3 n, vec3 v, float sharp) {\n vec3 r = reflect(-v, n);\n vec3 env = mix(uGround * 0.8, uSky * 1.3, smoothstep(-0.4, 0.6, r.y));\n float box = pow(max(dot(r, uKey), 0.0), sharp);\n return env + uKeyColor * box * 1.2;\n}\n\nvec3 diffuse(vec3 albedo, vec3 n, float shadow, float open, float wrap) {\n float nl = clamp((dot(n, uKey) + wrap) / (1.0 + wrap), 0.0, 1.0);\n return albedo * (uKeyColor * nl * shadow + fill(n) * open);\n}\n\n\nuniform vec4 uCapAxis; // the cap's axis (its cuff plane's normal) and the cuff edge's height along it\nuniform vec4 uCapCentre; // a point on the axis, and the cuff's height\nuniform vec3 uCapTones[3];\nuniform vec3 uHairTones[3];\nuniform vec3 uWrist;\nuniform vec3 uElbow;\n\nvec3 shadeCap(vec3 n, vec3 v, float shadow) {\n vec3 r = vRest;\n vec3 axis = uCapAxis.xyz;\n float h = dot(r, axis) - uCapAxis.w;\n vec3 q = r - uCapCentre.xyz;\n q -= axis * dot(q, axis);\n float around = atan(q.x, q.z);\n float cols = around * 56.0 / 6.2832;\n float rib = pow(abs(sin(cols * 3.14159)), 0.55);\n float row = h / 0.0026 + abs(fract(cols) - 0.5) * 1.4;\n float loop = smoothstep(0.15, 0.5, abs(fract(row) - 0.5));\n float height = rib * 0.0011 + loop * rib * 0.00025 + noise(vec2(cols * 4.0, h * 900.0)) * 0.00012;\n // Two woven labels on the cuff: an oblong one front left, a small square on the right.\n float onCuff = step(0.0, h) * step(h, uCapCentre.w);\n float oblong = step(-0.62, around) * step(around, -0.18) * step(0.013, h) * step(h, 0.034);\n float square = step(0.72, around) * step(around, 0.9) * step(0.016, h) * step(h, 0.031);\n float label = max(oblong, square) * onCuff;\n vec3 nn = label > 0.5 ? n : bumped(n, height);\n vec3 base = mix(uCapTones[1], uCapTones[0], rib) * (0.92 + 0.08 * loop);\n float print = oblong * step(0.5, fract((around + 0.62) * 70.0)) *\n (step(0.018, h) * step(h, 0.021) + step(0.025, h) * step(h, 0.0275) * step(around, -0.3));\n print += square * smoothstep(0.004, 0.003, length(vec2((around - 0.81) * 0.09, h - 0.0235)));\n base = mix(base, vec3(0.012), label);\n base = mix(base, vec3(0.8), clamp(print, 0.0, 1.0) * label);\n vec3 col = diffuse(base, nn, shadow, vOpen, 0.45);\n float rim = pow(1.0 - clamp(dot(nn, v), 0.0, 1.0), 3.0);\n col += uCapTones[2] * rim * 0.18 * (0.4 + 0.6 * shadow) * (1.0 - label);\n return col;\n}\n\nvec3 shadeHair(vec3 n, vec3 v, float shadow) {\n if (dot(vFlow.xyz, vFlow.xyz) < 0.5) return diffuse(uHairTones[0] * 0.55, n, shadow, vOpen * 0.7, 0.3);\n vec3 t = normalize(vFlow.xyz);\n float tone = vRest.z;\n float strands = 0.72 + 0.4 * noise(vec2(vRest.x * 24.0 + tone * 97.0, vRest.y * 6.0 + tone * 13.0));\n vec3 base = mix(uHairTones[0], uHairTones[1], tone) * strands;\n base = mix(base, uHairTones[2], smoothstep(0.6, 1.0, vRest.y) * 0.2);\n float tl = dot(t, uKey);\n float diff = mix(0.25, 1.0, sqrt(max(0.0, 1.0 - tl * tl))) * clamp(dot(n, uKey) * 0.6 + 0.4, 0.0, 1.0);\n vec3 h = normalize(uKey + v);\n float th = dot(t + n * 0.12, h);\n float spec = pow(sqrt(max(0.0, 1.0 - th * th)), 80.0) * 0.12;\n float th2 = dot(t - n * 0.1, h);\n float spec2 = pow(sqrt(max(0.0, 1.0 - th2 * th2)), 24.0) * 0.18;\n vec3 col = base * (uKeyColor * diff * shadow + fill(n) * vOpen * 0.9);\n col += (uKeyColor * spec + base * uKeyColor * spec2 * 1.5) * shadow * vOpen;\n return col;\n}\n\nvec3 shadeDress(vec3 n, vec3 v, float shadow) {\n vec3 r = vRest;\n vec3 base = uColor;\n // The embroidered band under the neckline: olive and black diamonds between fine light lines.\n float band = step(-0.142, r.y) * step(r.y, -0.106) * step(0.0, r.z) * step(abs(r.x), 0.15);\n vec2 d = vec2(r.x / 0.0105, (r.y + 0.124) / 0.0105);\n float diamond = abs(fract(d.x) - 0.5) + abs(d.y) ;\n float edge = step(abs(r.y + 0.108), 0.0012) + step(abs(r.y + 0.14), 0.0012);\n vec3 stitch = mix(vec3(0.02, 0.025, 0.018), vec3(0.17, 0.18, 0.09), step(diamond, 0.42));\n stitch = mix(stitch, vec3(0.55, 0.5, 0.36), clamp(edge, 0.0, 1.0));\n base = mix(base, stitch, band);\n // The sleeve's cuff at the wrist, with a pale lace edge.\n vec3 arm = uWrist - uElbow;\n float along = dot(r - uElbow, arm) / dot(arm, arm);\n float cuff = smoothstep(0.78, 0.8, along);\n base = mix(base, vec3(0.16, 0.19, 0.13), cuff);\n float lace = smoothstep(0.93, 0.95, along) * (0.6 + 0.4 * sin(atan(r.x - uWrist.x, r.z - uWrist.z) * 18.0));\n base = mix(base, vec3(0.78, 0.76, 0.68), clamp(lace, 0.0, 1.0));\n vec3 nn = bumped(n, noise(r.xy * 2600.0) * 0.00004);\n vec3 col = diffuse(base, nn, shadow, vOpen, 0.35);\n vec3 h = normalize(uKey + v);\n col += uKeyColor * pow(max(dot(nn, h), 0.0), 26.0) * 0.12 * shadow * (1.0 - band);\n return col;\n}\n\nvec3 shadeVelvet(vec3 n, vec3 v, float shadow) {\n float facing = clamp(dot(n, v), 0.0, 1.0);\n float sheen = pow(1.0 - facing, 2.2);\n vec3 base = uColor;\n vec3 col = diffuse(base, n, shadow, vOpen, 0.2);\n col += vec3(0.11, 0.13, 0.135) * sheen * (uKeyColor * 0.35 * (0.3 + 0.7 * shadow) + fill(n) * 0.6) * vOpen;\n return col;\n}\n\nvec3 shadeGold(vec3 n, vec3 v, float shadow) {\n float link = 0.65 + 0.35 * step(0.5, fract(vRest.x * 420.0));\n return uColor * reflected(n, v, 60.0) * link * mix(0.55, 1.0, shadow) * vOpen;\n}\n\nvec3 shadeCard(vec3 n, vec3 v, float shadow) {\n vec3 r = vRest;\n vec2 c = r.xy;\n // The chip, a bevelled gold plate with contact grooves.\n vec2 chipAt = vec2(0.03, 0.006);\n vec2 cq = abs(c - chipAt) - vec2(0.0084, 0.0072);\n float chip = step(max(cq.x, cq.y), 0.0) * step(0.0, r.z);\n float groove = chip * (step(abs(c.y - chipAt.y), 0.0004) + step(abs(abs(c.x - chipAt.x) - 0.003), 0.0003));\n float grain = noise(c * 2400.0) * 0.6 + noise(c * 5200.0) * 0.4;\n float digits = step(0.0, r.z) * step(abs(c.y + 0.016), 0.0026) * step(abs(c.x + 0.004), 0.046) *\n step(0.35, fract(c.x / 0.0058)) * step(fract(c.x / 0.026), 0.82);\n float mark = step(0.0, r.z) * step(abs(c.y + 0.03), 0.0022) * step(abs(c.x + 0.038), 0.014);\n float height = (1.0 - chip) * (grain * 0.00006 + digits * 0.00012);\n vec3 nn = bumped(n, height);\n vec3 base = mix(uColor, vec3(1.0, 0.27, 0.42), mark * 0.6);\n vec3 col = diffuse(base, nn, shadow, vOpen, 0.25);\n vec3 h = normalize(uKey + v);\n col += uKeyColor * pow(max(dot(nn, h), 0.0), 40.0) * 0.35 * shadow;\n vec3 gold = vec3(0.6, 0.38, 0.06) * reflected(nn, v, 40.0) * mix(0.5, 1.0, shadow);\n gold = mix(gold, vec3(0.1, 0.06, 0.01), clamp(groove, 0.0, 1.0));\n return mix(col, gold, chip);\n}\n\n\nuniform vec4 uTips[5]; // each finger's last joint and tip, in the hand's frame; the radius in w\nuniform vec4 uTipEnds[5];\nuniform vec3 uBacks[5]; // the back of each last bone\n\nfloat nails(vec3 r) {\n float best = 0.0;\n for (int i = 0; i < 5; i++) {\n vec3 a = uTips[i].xyz;\n vec3 b = uTipEnds[i].xyz;\n vec3 ab = b - a;\n float t = clamp(dot(r - a, ab) / dot(ab, ab), 0.0, 1.0);\n vec3 off = r - (a + ab * t);\n float back = dot(normalize(off), uBacks[i]);\n float on = smoothstep(0.38, 0.5, t) * smoothstep(0.55, 0.75, back) * step(length(off), uTips[i].w * 1.6);\n best = max(best, on);\n }\n return best;\n}\n\nvoid main() {\n vec3 n = normalize(vNormal);\n vec3 v = normalize(cameraPosition - vWorld);\n if (!gl_FrontFacing) n = -n;\n float shadow = keyShadow(n);\n vec3 col;\n#if PART == 0\n float gloss;\n vec3 albedo = skinAlbedo(vRest, gloss);\n albedo = mix(albedo, uBrowTone * 0.35, lashes(vRest));\n col = shadeSkin(albedo, gloss, n, v, shadow, vOpen);\n#elif PART == 1\n float nail = nails(vRest);\n vec3 albedo = mix(uSkinTone * vec3(1.0, 0.97, 0.95), vec3(0.85, 0.62, 0.56), nail);\n col = shadeSkin(albedo, 0.25 + nail * 0.6, n, v, shadow, vOpen);\n#elif PART == 2\n col = shadeEye(n, v, shadow);\n#elif PART == 3\n col = shadeCap(n, v, shadow);\n#elif PART == 4\n col = shadeHair(n, v, shadow);\n#elif PART == 5\n col = shadeDress(n, v, shadow);\n#elif PART == 6\n col = diffuse(uColor, bumped(n, noise(vRest.xy * 1800.0) * 0.00003), shadow, vOpen, 0.5);\n#elif PART == 7\n col = shadeVelvet(n, v, shadow);\n#elif PART == 8\n col = shadeGold(n, v, shadow);\n#else\n col = shadeCard(n, v, shadow);\n#endif\n gl_FragColor = vec4(col, 1.0);\n}\n",side:"both"}),l=new o.Mesh(a,r);l.frustumCulled=!1,e.group.add(l);let i=new o.CustomMaterial({uniforms:{uShadowFar:e.uniforms.uShadowFar},vertexShader:"\nvarying float vDepth;\nuniform float uShadowFar;\nvoid main() {\n vec4 view = viewMatrix * modelMatrix * vec4(position, 1.0);\n vDepth = -view.z / uShadowFar;\n gl_Position = projectionMatrix * view;\n}\n",fragmentShader:"\nvarying float vDepth;\nvoid main() { gl_FragColor = vec4(vDepth, 0.0, 0.0, 1.0); }\n",side:"both"}),s=new o.Mesh(a,i);s.frustumCulled=!1,e.casters.add(s),e.owned.push(a,r,i)}function Xe(e,n){let{lit:t,uniforms:o}=e,a=(e,n)=>{(o[e]?.value).set(n[0],n[1],n[2])},r=(e,n)=>{let o=new t.Color(e);return[o.r*n,o.g*n,o.b*n]};a("uKey",n.key),a("uKeyColor",r(n.keyColor,n.keyStrength)),a("uSky",r(n.sky,n.fillStrength)),a("uGround",r(n.ground,.6*n.fillStrength))}function Ye(e,n,t=_e){let o={lit:e,bust:n,uniforms:Ue(e,n,t),group:new e.Group,shadowStage:new e.Stage,casters:new e.Group,owned:[]};o.shadowStage.add(o.casters),o.casters.matrixAutoUpdate=!1;for(let e of n.parts)Qe(o,e,t);return Xe(o,Ge),{group:o.group,light:e=>{Xe(o,e)},face:e=>{!function(e,n){let{uniforms:t,bust:o,group:a}=e;a.updateMatrixWorld(!0);let r=a.matrixWorld.elements,l=t.uLid?.value;l.x=n.lid;let{turn:i,at:s}=o.pose;o.eyes.forEach((e,o)=>{let a=Ze([0,1,2].map(n=>(i[n]??0)*e[0]+(i[3+n]??0)*e[1]+(i[6+n]??0)*e[2]+(s[n]??0))),l=en(r,a,1),u=function(e,n){return Ze([0,1,2].map(t=>(e[4*t]??0)*n[0]+(e[4*t+1]??0)*n[1]+(e[4*t+2]??0)*n[2]))}(r,[n.at[0]-l[0],n.at[1]-l[1],n.at[2]-l[2]]),c=Ze([0,1,2].map(e=>(i[3*e]??0)*u[0]+(i[3*e+1]??0)*u[1]+(i[3*e+2]??0)*u[2])),h=Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2])||1;(t[0===o?"uLookL":"uLookR"]?.value).set(c[0]/h,c[1]/h,c[2]/h)})}(o,e)},shadows:e=>{!function(e,n){let{lit:t,uniforms:o}=e;e.target??=new t.RenderTarget(tn,tn,{type:"float",format:"red",minFilter:"nearest",magFilter:"nearest",depthBuffer:!0}),e.camera??=new t.OrthoCamera(-1,1,1,-1,.01,10);let{target:a,camera:r}=e,l=function(e,n){let{uniforms:t,group:o}=e;o.updateMatrixWorld(!0);let a=o.matrixWorld.elements;e.casters.matrix.copy(o.matrixWorld),e.casters.matrixWorldNeedsUpdate=!0;let r=nn[3]*Math.sqrt((a[0]??0)**2+(a[1]??0)**2+(a[2]??0)**2),l=en(a,[nn[0],nn[1],nn[2]],1),i=t.uKey?.value??{x:0,y:1,z:0},s=2*r;n.position.set(l[0]+i.x*s,l[1]+i.y*s,l[2]+i.z*s),n.lookAt(...l);let u=3.5*r;return Object.assign(n,{left:-r,right:r,top:r,bottom:-r,near:.5*r,far:u}),n.updateProjectionMatrix(),n.updateMatrixWorld(!0),(t.uShadowMatrix?.value).copy(n.matrixWorldInverse),(t.uShadowBox?.value).set(r,u),r}(e,r);o.uShadowFar&&(o.uShadowFar.value=3.5*l),o.uShadowMap&&(o.uShadowMap.value=a.texture),(o.uShadow?.value).set(1/tn,2.5,.004/3.5,1);let i=n.getRenderTarget(),s=new t.Color;n.getClearColor(s);let u=n.getClearAlpha();n.setRenderTarget(a),n.setClearColor(16777215,1),n.clear(!0,!0,!1),n.render(e.shadowStage,r),n.setRenderTarget(i),n.setClearColor(s,u)}(o,e)},dispose:()=>{for(let e of o.owned)e.dispose()}}}var Ze=e=>[e[0]??0,e[1]??0,e[2]??0];function en(e,n,t){return Ze([0,1,2].map(o=>(e[o]??0)*n[0]+(e[4+o]??0)*n[1]+(e[8+o]??0)*n[2]+(e[12+o]??0)*t))}var nn=[0,-.05,0,.62],tn=2048,on={seed:7,face:"A",detail:"hero",hand:"pinch",cap:_e.cap,hair:_e.hair,card:_e.card},an=/^#[0-9a-f]{6}$/iu;function rn(e,n){return"string"==typeof e&&an.test(e)?e.toLowerCase():n}function ln(e){return"number"==typeof e&&Number.isFinite(e)?Math.min(2**31-1,Math.max(0,Math.round(e))):on.seed}function sn(e){if(null===e||"object"!=typeof e)return on;let n=e,t=on;return{seed:ln(n.seed),face:"B"===n.face?"B":"A",detail:"mid"===n.detail||"far"===n.detail?n.detail:"hero",hand:"point"===n.hand?"point":"pinch",cap:rn(n.cap,t.cap),hair:rn(n.hair,t.hair),card:rn(n.card,t.card)}}function un(e){let{seed:n,face:t,hand:o,cap:a,hair:r,card:l}=e;return{recipe:{seed:n,face:t,hand:o,detail:ze[e.detail]},palette:{..._e,cap:a,hair:r,card:l}}}export{on as DEFAULT_PORTRAIT_SETTINGS,ze as DETAIL,Ge as LIGHT,_e as PALETTE,Re as PARTS,Ie as buildBust,o as cosine,Ye as createPortrait,a as deg,Ne as digestOf,Ve as featuresOf,l as hash32,Oe as headPose,sn as portraitSettings,t as sine,un as sitterOf,r as turn};
@@ -0,0 +1,130 @@
1
+ /**
2
+ * One setting for how good a scene looks. A level says what to spend; where the
3
+ * camera is says what is worth spending it on, so a view from the shore traces
4
+ * the sand's shadows and a dive spends the same rays on light shafts. MIT.
5
+ *
6
+ * const quality = createQuality({ level: "auto", tier: device.tier });
7
+ * quality.at({ under, depth, height, clearance }) -> what to draw this frame
8
+ * quality.frame(milliseconds) -> tell it how the last one went
9
+ * quality.levers -> what a scrolled page's scenes may spend
10
+ *
11
+ * Pure: nothing here reads a clock or a GPU, so the caller hands it frame times
12
+ * and any run can be replayed from them.
13
+ */
14
+ export type Level = "low" | "medium" | "high" | "ultra";
15
+ export type Tier = "low" | "mid" | "high";
16
+ /** What a renderer may spend on one frame. */
17
+ export interface Settings {
18
+ readonly level: Level;
19
+ /** Pixels drawn, as a share of the screen's width and height. */
20
+ readonly renderScale: number;
21
+ /** Rebuild the full image from past frames. */
22
+ readonly upscale: boolean;
23
+ /** Steps a reflected ray takes through the ground; 0 reflects only the sky. */
24
+ readonly reflectSteps: number;
25
+ /** Steps a ray toward the sun takes; 0 casts no traced shadows. */
26
+ readonly shadowSteps: number;
27
+ /** How far a reflected ray runs, metres. */
28
+ readonly traceFar: number;
29
+ /** How far from the eye water is traced at all, metres. */
30
+ readonly traceNear: number;
31
+ /** How many simple shapes stand in for animals in the rays. */
32
+ readonly casters: number;
33
+ /** Steps through the water for light shafts. */
34
+ readonly shafts: number;
35
+ /** Shells of marine snow. */
36
+ readonly snow: number;
37
+ /** The share of the surf's spray drawn, from 0 to 1. */
38
+ readonly spray: number;
39
+ }
40
+ /** What a scrolled page's scenes may spend: the levers a scene's `setQuality` takes, beside the settings above. */
41
+ export interface Levers {
42
+ /** Pixels drawn, as a share of the screen's width and height: the governed scale. */
43
+ readonly renderScale: number;
44
+ /** Bloom, as a share of a scene's own: 0 turns it off. */
45
+ readonly bloom: number;
46
+ /** The share of a scene's motes and other particles drawn, 0 to 1. */
47
+ readonly motes: number;
48
+ /** The outgoing scene's scale during a hand-over between two scenes, as a share of `renderScale`. */
49
+ readonly blendScale: number;
50
+ /** Temporal antialiasing. */
51
+ readonly taa: boolean;
52
+ /** The share of a scene's detail (crowds, foliage, level of detail) drawn, 0 to 1. */
53
+ readonly density: number;
54
+ }
55
+ /**
56
+ * A level's page levers at a render scale.
57
+ *
58
+ * @param level The level in use.
59
+ * @param scale The render scale, as the governor holds it.
60
+ */
61
+ export declare function leversFor(level: Level, scale: number): Levers;
62
+ /** Where the camera is. */
63
+ export interface Place {
64
+ readonly under: boolean;
65
+ /** Metres under the water; 0 above it. */
66
+ readonly depth: number;
67
+ /** Metres above the water; 0 under it. */
68
+ readonly height: number;
69
+ /** Metres from the camera down to the ground, or to the sea floor. */
70
+ readonly clearance: number;
71
+ }
72
+ /**
73
+ * Spends a level by where the camera is.
74
+ *
75
+ * @param settings What the level allows.
76
+ * @param place Where the camera is.
77
+ * @returns What is worth drawing there.
78
+ */
79
+ export declare function settingsAt(settings: Settings, place: Place): Settings;
80
+ export interface QualityInput {
81
+ /** A level, or "auto" to take it from the device. */
82
+ readonly level?: Level | "auto";
83
+ /** `device-profile`'s tier, for "auto". */
84
+ readonly tier?: Tier;
85
+ /** The frame time to hold, milliseconds. 1000 / 60 by default. */
86
+ readonly target?: number;
87
+ /** The lowest render scale the governor may reach. */
88
+ readonly floor?: number;
89
+ /** Ray traced reflections and shadows, on by default where the level has them. */
90
+ readonly tracing?: boolean;
91
+ /** Rebuilding the image from past frames, on by default where the level has it. */
92
+ readonly upscale?: boolean;
93
+ /** Whether the surf throws spray. */
94
+ readonly spray?: boolean;
95
+ }
96
+ /** What can be switched while running. */
97
+ export interface Switches {
98
+ readonly tracing?: boolean;
99
+ readonly upscale?: boolean;
100
+ readonly spray?: boolean;
101
+ readonly level?: Level;
102
+ }
103
+ export interface Quality {
104
+ /** The level in use. */
105
+ readonly level: Level;
106
+ /** What to draw from this place, at the governed render scale. */
107
+ at(place: Place): Settings;
108
+ /** Reports how long the last frame took. */
109
+ frame(milliseconds: number): void;
110
+ /** The render scale the governor has settled on. */
111
+ readonly scale: number;
112
+ /** Whether rays are on. */
113
+ readonly tracing: boolean;
114
+ /** Whether upscaling is on. */
115
+ readonly upscale: boolean;
116
+ /** Whether the surf throws spray. */
117
+ readonly spray: boolean;
118
+ /** Turns tracing, upscaling or spray on or off, or changes level, at once. */
119
+ set(switches: Switches): void;
120
+ /** The page levers for the level in use, at the governed render scale. */
121
+ readonly levers: Levers;
122
+ }
123
+ /**
124
+ * Picks a level, and keeps it to the frame rate by lowering the render scale.
125
+ * With upscaling on, scale is the cheapest thing to give up.
126
+ *
127
+ * @param input The level, the device's tier, and the frame time to hold.
128
+ * @returns A quality to ask each frame.
129
+ */
130
+ export declare function createQuality(input?: QualityInput): Quality;
@@ -0,0 +1 @@
1
+ export * from './quality/index.js'
@@ -0,0 +1,34 @@
1
+ {
2
+ "protocol": "keel-module-inputs@1",
3
+ "fields": [
4
+ {
5
+ "key": "level",
6
+ "label": "Quality",
7
+ "required": false,
8
+ "type": "select",
9
+ "options": [
10
+ {
11
+ "value": "auto",
12
+ "label": "Automatic"
13
+ },
14
+ {
15
+ "value": "low",
16
+ "label": "Low"
17
+ },
18
+ {
19
+ "value": "medium",
20
+ "label": "Medium"
21
+ },
22
+ {
23
+ "value": "high",
24
+ "label": "High"
25
+ },
26
+ {
27
+ "value": "ultra",
28
+ "label": "Ultra"
29
+ }
30
+ ],
31
+ "default": "auto"
32
+ }
33
+ ]
34
+ }
@@ -0,0 +1,2 @@
1
+ // quality@0.2.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
2
+ var e={low:{level:"low",renderScale:.7,upscale:!1,reflectSteps:0,shadowSteps:0,traceFar:0,traceNear:0,casters:0,shafts:4,snow:2,spray:.25},medium:{level:"medium",renderScale:.75,upscale:!0,reflectSteps:14,shadowSteps:10,traceFar:70,traceNear:60,casters:8,shafts:8,snow:4,spray:.5},high:{level:"high",renderScale:.8,upscale:!0,reflectSteps:28,shadowSteps:20,traceFar:140,traceNear:140,casters:16,shafts:16,snow:6,spray:.8},ultra:{level:"ultra",renderScale:1,upscale:!0,reflectSteps:48,shadowSteps:32,traceFar:260,traceNear:260,casters:32,shafts:24,snow:6,spray:1}},a={low:"low",mid:"medium",high:"high"},r={low:{bloom:0,motes:.25,blendScale:.5,taa:!1,density:.5},medium:{bloom:1,motes:.5,blendScale:.5,taa:!0,density:.75},high:{bloom:1,motes:.8,blendScale:.75,taa:!0,density:1},ultra:{bloom:1,motes:1,blendScale:1,taa:!0,density:1}};function t(e,a){return{renderScale:a,...r[e]}}function s(e,a){let r=a.clearance>40;if(a.under)return{...e,shadowSteps:r?0:e.shadowSteps,spray:0};let t=l(a.height/120);return{...e,shafts:0,snow:0,spray:e.spray*(1-t),reflectSteps:Math.round(e.reflectSteps*(1-.6*t)),casters:r?0:e.casters}}var l=e=>Math.min(1,Math.max(0,e)),c=e=>({...e,reflectSteps:0,shadowSteps:0,traceFar:0,traceNear:0,casters:0});function n(r={}){let l=r.level??"auto",n="auto"===l?a[r.tier??"mid"]:l,o=e[n],p=r.tracing??!0,u=r.upscale??!0,d=r.spray??!0,h=r.target??1e3/60,i=o.renderScale,S=h,m=30;return{get level(){return n},get scale(){return i},get tracing(){return p},get upscale(){return u},get spray(){return d},get levers(){return t(n,i)},set(a){p=a.tracing??p,u=a.upscale??u,d=a.spray??d,void 0!==a.level&&a.level!==n&&(n=a.level,o=e[n],i=o.renderScale,m=30)},at(e){let a=s(o,e);return{...p?a:c(a),spray:d?a.spray:0,upscale:u&&o.upscale,renderScale:u&&o.upscale?i:Math.max(i,1-(1-i)/2)}},frame(e){if(S+=.1*(e-S),m-=1,m>0)return;let a=S>1.15*h;!a&&!(S<.8*h)||(i=Math.max(Math.min(r.floor??.5,o.renderScale),Math.min(o.renderScale,i+(a?-.05:.05))),m=30)}}}export{n as createQuality,t as leversFor,s as settingsAt};
@@ -0,0 +1,54 @@
1
+ import type { FinishLike, LitLike, RendererLike } from "./lit.js";
2
+ import type { BlendSettings, Point } from "./settings.js";
3
+ /** A scene to draw: a stage and its camera (through the finish when there is one), or a function that draws it. */
4
+ export type Shot = {
5
+ readonly scene: unknown;
6
+ readonly camera: unknown;
7
+ } | (() => void);
8
+ /** How one frame of a hand-over looks. Every value is a plain number or point a host can feed from tracks. */
9
+ export interface DrawOptions {
10
+ /** "noise" (default): a seeded noise threshold. "radial": out from `centre`. "fade": a plain dissolve. */
11
+ readonly mode?: "noise" | "radial" | "fade";
12
+ /** A radial reveal's centre, -1..1 each way with y up (a projected 3D point, say). The frame's centre by default. */
13
+ readonly centre?: Point;
14
+ /** The pointer, -1..1 each way with y up, or null when it is away. Pulls a radial centre toward it. */
15
+ readonly pointer?: Point | null;
16
+ /** Darkens the blended picture, 0..1. */
17
+ readonly darken?: number;
18
+ /** Overrides the line work from `blendLines(t)`: the incoming's and the outgoing's, each 0..1. */
19
+ readonly lines?: {
20
+ readonly in?: number;
21
+ readonly out?: number;
22
+ };
23
+ }
24
+ /**
25
+ * The finishes a blend draws through: the main one, shared with the page, and optionally a second the blend sizes
26
+ * itself at `scale`, for the less visible scene. A scaled finish may be set lighter (no bloom, say).
27
+ */
28
+ export interface Finishes {
29
+ readonly main: FinishLike;
30
+ readonly scaled?: FinishLike;
31
+ }
32
+ export interface SceneBlend {
33
+ readonly settings: BlendSettings;
34
+ setSettings(input?: unknown): BlendSettings;
35
+ /** The canvas's CSS size and pixel ratio (the renderer's, and the main finish's). Sizes the scaled finish too. */
36
+ setSize(cssWidth: number, cssHeight: number, devicePixelRatio: number): void;
37
+ /**
38
+ * Draws the hand-over from `a` (outgoing) to `b` (incoming) at `t` onto the renderer's current target.
39
+ *
40
+ * @returns The current scene: "a" before the switch at 0.5, "b" from it. Moving the active section is the host's.
41
+ */
42
+ draw(a: Shot, b: Shot, t: number, options?: DrawOptions): "a" | "b";
43
+ dispose(): void;
44
+ }
45
+ /**
46
+ * Binds a scene hand-over to a renderer: two scenes, each finished into its own half-float target, blended by a
47
+ * seeded noise threshold or a radial reveal, the incoming arriving as line work and the outgoing leaving as it.
48
+ *
49
+ * @param lit The keel/lit namespace (WebGL2).
50
+ * @param renderer The renderer that owns the canvas.
51
+ * @param finish The finish each scene is drawn through (lit-finish's), a main and a scaled one, or null to draw plain.
52
+ * @param input Settings, normalized through `blendSettings`.
53
+ */
54
+ export declare function createSceneBlend(lit: LitLike, renderer: RendererLike, finish?: FinishLike | Finishes | null, input?: unknown): SceneBlend;
@@ -0,0 +1,8 @@
1
+ export declare const BLEND_VERTEX_GLSL = "\nvoid main() { gl_Position = vec4(position.xy, 0.0, 1.0); }\n";
2
+ /**
3
+ * Two finished pictures, A outgoing and B incoming, into one; either may be smaller than the frame. Lines are luma
4
+ * edges by a Roberts cross, one texel of that picture apart, so they stay thin. The fill follows a field that rises
5
+ * from 0 to 1: the noise (mode 0), or the distance from a centre roughened by the noise (mode 1); a pixel shows B
6
+ * once the reveal level passes its field, through a soft boundary that glows faintly. Mode 2 is a plain dissolve.
7
+ */
8
+ export declare const BLEND_GLSL = "\nprecision highp float;\nuniform sampler2D tA;\nuniform sampler2D tB;\nuniform sampler2D tNoise;\nuniform vec2 uSize;\nuniform vec2 uTexelA;\nuniform vec2 uTexelB;\nuniform float uMode;\nuniform float uFill;\nuniform float uLinesIn;\nuniform float uLinesOut;\nuniform float uDarken;\nuniform vec3 uLine;\nuniform float uLineStrength;\nuniform float uEdge;\nuniform float uSoft;\nuniform vec3 uSeam;\nuniform float uGlow;\nuniform float uSeamWidth;\nuniform float uNoiseScale;\nuniform vec2 uCentre;\nuniform float uReach;\nfloat luma(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }\nfloat lines(sampler2D t, float here, vec2 uv, vec2 px) {\n float right = luma(texture2D(t, uv + vec2(px.x, 0.0)).rgb);\n float up = luma(texture2D(t, uv + vec2(0.0, px.y)).rgb);\n float across = luma(texture2D(t, uv + px).rgb);\n return smoothstep(uEdge, uEdge * 3.0, length(vec2(here - across, right - up)));\n}\nvoid main() {\n vec2 uv = gl_FragCoord.xy / uSize;\n vec3 a = texture2D(tA, uv).rgb;\n vec3 b = texture2D(tB, uv).rgb;\n if (uMode > 1.5) { gl_FragColor = vec4(mix(a, b, uFill) * (1.0 - uDarken), 1.0); return; }\n float aspect = uSize.x / uSize.y;\n float n = texture2D(tNoise, vec2(uv.x * aspect, uv.y) * uNoiseScale).r;\n float field = n;\n if (uMode > 0.5) field = mix(length((uv - uCentre) * vec2(aspect, 1.0)) / uReach, n, 0.18);\n float level = uFill * (1.0 + 2.0 * uSoft) - uSoft;\n float fill = 1.0 - smoothstep(level - uSoft, level + uSoft, field);\n float seam = (1.0 - smoothstep(0.0, uSeamWidth, abs(field - level))) * step(0.0001, uFill) * step(uFill, 0.9999);\n float la = uLinesOut > 0.0 ? lines(tA, luma(a), uv, uTexelA) : 0.0;\n float lb = uLinesIn > 0.0 ? lines(tB, luma(b), uv, uTexelB) : 0.0;\n vec3 outgoing = mix(a, vec3(0.0), uLinesOut * 0.6) + uLine * la * uLinesOut * uLineStrength;\n vec3 c = mix(outgoing, b, fill);\n c += uLine * lb * uLinesIn * uLineStrength * (1.0 - 0.6 * fill);\n c += uSeam * seam * seam * uGlow * 0.25;\n gl_FragColor = vec4(clamp(c * (1.0 - uDarken), 0.0, 1.0), 1.0);\n}\n";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * A hand-over between two keel/lit scenes on one renderer. MIT.
3
+ *
4
+ * const finish = createLitFinish(lit, renderer); // lit-finish, shared by both scenes
5
+ * const blend = createSceneBlend(lit, renderer, finish, { seed: 7 });
6
+ * blend.setSize(cssWidth, cssHeight, renderer.getPixelRatio());
7
+ * // each frame of the pair's life, t from the page:
8
+ * const current = blend.draw({ scene: a, camera: camA }, { scene: b, camera: camB }, t, { mode: "noise" });
9
+ *
10
+ * While 0 < t < 1 each scene is drawn through the one finish into its own half-float target, and one pass blends
11
+ * them onto the host's target. The incoming arrives as white luma-edge line work over the outgoing and fills in
12
+ * through a seeded noise threshold (or out from a point, radially) with a glowing seam at the boundary; the outgoing
13
+ * takes on line work of its own as it goes. `draw` returns which scene is current (the switch is at 0.5); moving the
14
+ * active section is the host's. The noise is a texture worked out from the seed with exact arithmetic, never
15
+ * Math.random, so a capture repeats.
16
+ *
17
+ * keel/lit and the finish are injected: the module never imports them and never touches globals.
18
+ */
19
+ export { DEFAULT_BLEND_SETTINGS, blendSettings, blendLines, blendFill, currentAt, minorAt, radialCentre, farthestCorner, displayColour, } from "./settings.js";
20
+ export type { BlendSettings, Point } from "./settings.js";
21
+ export { NOISE_SIZE, latticeHash, noiseTexels } from "./noise.js";
22
+ export { BLEND_GLSL, BLEND_VERTEX_GLSL } from "./blend.glsl.js";
23
+ export type { FinishLike, LitLike } from "./lit.js";
24
+ export { createSceneBlend } from "./blend.js";
25
+ export type { DrawOptions, Finishes, SceneBlend, Shot } from "./blend.js";
@@ -0,0 +1,61 @@
1
+ export interface TextureLike {
2
+ dispose(): void;
3
+ }
4
+ export interface DataTextureLike extends TextureLike {
5
+ wrapS: string;
6
+ wrapT: string;
7
+ minFilter: string;
8
+ magFilter: string;
9
+ needsUpdate: boolean;
10
+ }
11
+ export interface RenderTargetLike {
12
+ readonly texture: TextureLike;
13
+ setSize(width: number, height: number): void;
14
+ dispose(): void;
15
+ }
16
+ export interface Uniform {
17
+ value: unknown;
18
+ }
19
+ export interface ShaderMaterialLike {
20
+ readonly uniforms: Record<string, Uniform>;
21
+ dispose(): void;
22
+ }
23
+ export interface RendererLike {
24
+ getRenderTarget(): RenderTargetLike | null;
25
+ setRenderTarget(target: RenderTargetLike | null): void;
26
+ render(scene: unknown, camera: unknown): void;
27
+ }
28
+ export interface DisposableLike {
29
+ dispose(): void;
30
+ }
31
+ interface MeshLike {
32
+ frustumCulled: boolean;
33
+ }
34
+ export interface SceneLike {
35
+ add(object: unknown): void;
36
+ }
37
+ /** The parts of keel/lit this module calls. Pass the keel/lit namespace itself. */
38
+ export interface LitLike {
39
+ readonly RenderTarget: new (width: number, height: number, options: Readonly<Record<string, unknown>>) => RenderTargetLike;
40
+ readonly DataTexture: new (data: Uint8Array, width: number, height: number, format: string) => DataTextureLike;
41
+ readonly CustomMaterial: new (parameters: Readonly<Record<string, unknown>>) => ShaderMaterialLike;
42
+ plane(width: number, height: number): DisposableLike;
43
+ readonly Mesh: new (geometry: unknown, material: unknown) => MeshLike;
44
+ readonly Stage: new () => SceneLike;
45
+ readonly OrthoCamera: new (left: number, right: number, top: number, bottom: number, near: number, far: number) => unknown;
46
+ }
47
+ /**
48
+ * A finish that draws a scene onto the renderer's current target: lit-finish's `createLitFinish` result, or anything
49
+ * of its shape. `settings`, `setSettings` and `dress` are optional; with them the blend pauses TAA for the overlap
50
+ * and dresses both scenes.
51
+ */
52
+ export interface FinishLike {
53
+ render(scene: unknown, camera: unknown): void;
54
+ setSize?(cssWidth: number, cssHeight: number, devicePixelRatio: number): void;
55
+ readonly settings?: {
56
+ readonly taa?: boolean;
57
+ };
58
+ setSettings?(input: unknown): unknown;
59
+ dress?(root: unknown): void;
60
+ }
61
+ export {};
@@ -0,0 +1,13 @@
1
+ /** Texels along a side of the noise texture. */
2
+ export declare const NOISE_SIZE = 256;
3
+ /** A lattice point and a seed to a share in [0, 1), by 32-bit integer mixing. */
4
+ export declare function latticeHash(x: number, y: number, seed: number): number;
5
+ /**
6
+ * The noise texture's texels, RGBA, `size` a side (a power of two). R: fine fractal noise (16 cells a side and up),
7
+ * the threshold a reveal follows. G: broad fractal noise (4 cells and up), for a torn edge's shape. B: white noise
8
+ * for grain. A: 255. R and G are stretched to the full range. The same seed gives the same bytes everywhere.
9
+ *
10
+ * @param seed An integer seed.
11
+ * @param size Texels a side, a power of two from 32; 256 by default.
12
+ */
13
+ export declare function noiseTexels(seed?: number, size?: number): Uint8Array;
@@ -0,0 +1,63 @@
1
+ /** How a hand-over looks. Colours are display (sRGB) values: the blend works on finished pictures. */
2
+ export interface BlendSettings {
3
+ /** The noise texture's seed. */
4
+ readonly seed: number;
5
+ /** The line work's colour, "#rrggbb". */
6
+ readonly lineColour: string;
7
+ /** How strong the line work is, 0 to 1. */
8
+ readonly lines: number;
9
+ /** The luma step that makes a line, 0.01 to 1: lower draws more lines. */
10
+ readonly edge: number;
11
+ /** How soft the reveal's boundary is, as a share of the noise's range, 0 to 0.3. */
12
+ readonly soft: number;
13
+ /** The seam's glow colour, "#rrggbb". */
14
+ readonly seamColour: string;
15
+ /** How bright the seam glows along the boundary, 0 (none) to 4. */
16
+ readonly glow: number;
17
+ /** The seam's width, as a share of the noise's range, 0 to 0.3. */
18
+ readonly seam: number;
19
+ /** How many times the noise repeats down the frame's height, 0.25 to 8. */
20
+ readonly noiseScale: number;
21
+ /** How far the pointer pulls a radial reveal's centre, 0 to 1. */
22
+ readonly pull: number;
23
+ /**
24
+ * The scale the less visible scene is drawn at, 0.25 to 1 (quality's `blendScale`). It takes a scaled finish, or no
25
+ * finish; with only the main finish both scenes are drawn whole.
26
+ */
27
+ readonly scale: number;
28
+ }
29
+ export declare const DEFAULT_BLEND_SETTINGS: BlendSettings;
30
+ /**
31
+ * Settings from anything: each one checked and bounded, a missing or broken one falling back to its default.
32
+ *
33
+ * @param input A partial settings object, or nothing for the defaults.
34
+ */
35
+ export declare function blendSettings(input?: unknown): BlendSettings;
36
+ /** "#rrggbb" to [r, g, b] in 0..1, unconverted: the blend mixes display values. */
37
+ export declare function displayColour(value: string): [number, number, number];
38
+ /**
39
+ * The line work each scene carries at `t`. The incoming's lines are full at 0, half at the switch and gone by 0.9;
40
+ * the outgoing's start at the switch and are full at 1.
41
+ *
42
+ * @returns `[incoming, outgoing]`, each 0..1.
43
+ */
44
+ export declare function blendLines(t: number): [number, number];
45
+ /** How far the incoming's fill has come at `t`, 0..1: it starts at 0.25 and covers everything at 1. */
46
+ export declare function blendFill(t: number): number;
47
+ /** The less visible scene at `t`, where a lower scale shows least: the incoming ("b") before 0.5, then the outgoing. */
48
+ export declare function minorAt(t: number): "a" | "b";
49
+ /** The current scene at `t`: the outgoing ("a") before the switch at 0.5, the incoming ("b") from it. */
50
+ export declare function currentAt(t: number): "a" | "b";
51
+ /** A point in -1..1 each way with y up, as both a centre and a pointer are given. */
52
+ export interface Point {
53
+ readonly x: number;
54
+ readonly y: number;
55
+ }
56
+ /**
57
+ * A radial reveal's centre: the host's point (a projected 3D point, say) pulled toward the pointer by `pull`.
58
+ *
59
+ * @returns The centre in 0..1 texture space, y up.
60
+ */
61
+ export declare function radialCentre(centre: Point, pointer: Point | null, pull: number): [number, number];
62
+ /** The distance from a centre (0..1 texture space) to the farthest corner, measured in frame heights. */
63
+ export declare function farthestCorner(centre: readonly [number, number], aspect: number): number;
@@ -0,0 +1 @@
1
+ export * from './scene-blend/index.js'