depthview-mcp 0.1.0 → 0.5.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.
- package/README.md +64 -19
- package/dist/cli.js +1009 -1194
- package/dist/probe.js +782 -0
- package/package.json +5 -1
- package/skill/SKILL.md +583 -54
- package/skill/references/award-sites.md +175 -0
- package/skill/references/extension-ui.md +190 -0
- package/skill/references/modeling.md +198 -0
- package/skill/references/particles.md +137 -0
- package/skill/references/performance.md +114 -0
- package/skill/references/r3f.md +151 -0
- package/skill/references/rendering.md +150 -0
- package/skill/references/shaders.md +200 -0
- package/skill/references/site-build.md +288 -0
- package/skill/references/threejs.md +387 -0
- package/skill/references/visual-qa.md +152 -0
- package/skill/references/volumetrics.md +165 -0
package/dist/probe.js
ADDED
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
"use strict";(()=>{var Ku=Object.create;var gs=Object.defineProperty;var Xu=Object.getOwnPropertyDescriptor;var Ju=Object.getOwnPropertyNames;var Yu=Object.getPrototypeOf,Qu=Object.prototype.hasOwnProperty;var bs=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Zu=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ju(t))!Qu.call(e,o)&&o!==n&&gs(e,o,{get:()=>t[o],enumerable:!(r=Xu(t,o))||r.enumerable});return e};var ef=(e,t,n)=>(n=e!=null?Ku(Yu(e)):{},Zu(t||!e||!e.__esModule?gs(n,"default",{value:e,enumerable:!0}):n,e));var vu=bs(D=>{"use strict";var Gn=Symbol.for("react.element"),Sm=Symbol.for("react.portal"),Mm=Symbol.for("react.fragment"),km=Symbol.for("react.strict_mode"),Em=Symbol.for("react.profiler"),Tm=Symbol.for("react.provider"),Rm=Symbol.for("react.context"),Am=Symbol.for("react.forward_ref"),Pm=Symbol.for("react.suspense"),Cm=Symbol.for("react.memo"),Lm=Symbol.for("react.lazy"),lu=Symbol.iterator;function $m(e){return e===null||typeof e!="object"?null:(e=lu&&e[lu]||e["@@iterator"],typeof e=="function"?e:null)}var fu={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},hu=Object.assign,du={};function on(e,t,n){this.props=e,this.context=t,this.refs=du,this.updater=n||fu}on.prototype.isReactComponent={};on.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};on.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function mu(){}mu.prototype=on.prototype;function qi(e,t,n){this.props=e,this.context=t,this.refs=du,this.updater=n||fu}var Gi=qi.prototype=new mu;Gi.constructor=qi;hu(Gi,on.prototype);Gi.isPureReactComponent=!0;var cu=Array.isArray,pu=Object.prototype.hasOwnProperty,Ki={current:null},gu={key:!0,ref:!0,__self:!0,__source:!0};function bu(e,t,n){var r,o={},i=null,s=null;if(t!=null)for(r in t.ref!==void 0&&(s=t.ref),t.key!==void 0&&(i=""+t.key),t)pu.call(t,r)&&!gu.hasOwnProperty(r)&&(o[r]=t[r]);var a=arguments.length-2;if(a===1)o.children=n;else if(1<a){for(var l=Array(a),c=0;c<a;c++)l[c]=arguments[c+2];o.children=l}if(e&&e.defaultProps)for(r in a=e.defaultProps,a)o[r]===void 0&&(o[r]=a[r]);return{$$typeof:Gn,type:e,key:i,ref:s,props:o,_owner:Ki.current}}function jm(e,t){return{$$typeof:Gn,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function Xi(e){return typeof e=="object"&&e!==null&&e.$$typeof===Gn}function Om(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(n){return t[n]})}var uu=/\/+/g;function Ui(e,t){return typeof e=="object"&&e!==null&&e.key!=null?Om(""+e.key):t.toString(36)}function oo(e,t,n,r,o){var i=typeof e;(i==="undefined"||i==="boolean")&&(e=null);var s=!1;if(e===null)s=!0;else switch(i){case"string":case"number":s=!0;break;case"object":switch(e.$$typeof){case Gn:case Sm:s=!0}}if(s)return s=e,o=o(s),e=r===""?"."+Ui(s,0):r,cu(o)?(n="",e!=null&&(n=e.replace(uu,"$&/")+"/"),oo(o,t,n,"",function(c){return c})):o!=null&&(Xi(o)&&(o=jm(o,n+(!o.key||s&&s.key===o.key?"":(""+o.key).replace(uu,"$&/")+"/")+e)),t.push(o)),1;if(s=0,r=r===""?".":r+":",cu(e))for(var a=0;a<e.length;a++){i=e[a];var l=r+Ui(i,a);s+=oo(i,t,n,l,o)}else if(l=$m(e),typeof l=="function")for(e=l.call(e),a=0;!(i=e.next()).done;)i=i.value,l=r+Ui(i,a++),s+=oo(i,t,n,l,o);else if(i==="object")throw t=String(e),Error("Objects are not valid as a React child (found: "+(t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.");return s}function ro(e,t,n){if(e==null)return e;var r=[],o=0;return oo(e,r,"","",function(i){return t.call(n,i,o++)}),r}function _m(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(n){(e._status===0||e._status===-1)&&(e._status=1,e._result=n)},function(n){(e._status===0||e._status===-1)&&(e._status=2,e._result=n)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var he={current:null},io={transition:null},Im={ReactCurrentDispatcher:he,ReactCurrentBatchConfig:io,ReactCurrentOwner:Ki};function yu(){throw Error("act(...) is not supported in production builds of React.")}D.Children={map:ro,forEach:function(e,t,n){ro(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return ro(e,function(){t++}),t},toArray:function(e){return ro(e,function(t){return t})||[]},only:function(e){if(!Xi(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};D.Component=on;D.Fragment=Mm;D.Profiler=Em;D.PureComponent=qi;D.StrictMode=km;D.Suspense=Pm;D.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Im;D.act=yu;D.cloneElement=function(e,t,n){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=hu({},e.props),o=e.key,i=e.ref,s=e._owner;if(t!=null){if(t.ref!==void 0&&(i=t.ref,s=Ki.current),t.key!==void 0&&(o=""+t.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(l in t)pu.call(t,l)&&!gu.hasOwnProperty(l)&&(r[l]=t[l]===void 0&&a!==void 0?a[l]:t[l])}var l=arguments.length-2;if(l===1)r.children=n;else if(1<l){a=Array(l);for(var c=0;c<l;c++)a[c]=arguments[c+2];r.children=a}return{$$typeof:Gn,type:e.type,key:o,ref:i,props:r,_owner:s}};D.createContext=function(e){return e={$$typeof:Rm,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:Tm,_context:e},e.Consumer=e};D.createElement=bu;D.createFactory=function(e){var t=bu.bind(null,e);return t.type=e,t};D.createRef=function(){return{current:null}};D.forwardRef=function(e){return{$$typeof:Am,render:e}};D.isValidElement=Xi;D.lazy=function(e){return{$$typeof:Lm,_payload:{_status:-1,_result:e},_init:_m}};D.memo=function(e,t){return{$$typeof:Cm,type:e,compare:t===void 0?null:t}};D.startTransition=function(e){var t=io.transition;io.transition={};try{e()}finally{io.transition=t}};D.unstable_act=yu;D.useCallback=function(e,t){return he.current.useCallback(e,t)};D.useContext=function(e){return he.current.useContext(e)};D.useDebugValue=function(){};D.useDeferredValue=function(e){return he.current.useDeferredValue(e)};D.useEffect=function(e,t){return he.current.useEffect(e,t)};D.useId=function(){return he.current.useId()};D.useImperativeHandle=function(e,t,n){return he.current.useImperativeHandle(e,t,n)};D.useInsertionEffect=function(e,t){return he.current.useInsertionEffect(e,t)};D.useLayoutEffect=function(e,t){return he.current.useLayoutEffect(e,t)};D.useMemo=function(e,t){return he.current.useMemo(e,t)};D.useReducer=function(e,t,n){return he.current.useReducer(e,t,n)};D.useRef=function(e){return he.current.useRef(e)};D.useState=function(e){return he.current.useState(e)};D.useSyncExternalStore=function(e,t,n){return he.current.useSyncExternalStore(e,t,n)};D.useTransition=function(){return he.current.useTransition()};D.version="18.3.1"});var xu=bs((Ag,wu)=>{"use strict";wu.exports=vu()});var tf="Depthview",Pt=tf.toLowerCase();var yo=Pt,vo=1,Ye=`${Pt}-root`,ys="dv-scene-view",vs="dv-grab",ws=1600;var Km=`data-${Pt}-mode`,Xm=`data-${Pt}-bg`,Ct=`data-${Pt}-webgl`,xs=`data-${Pt}-fixed`,Ss="__DEPTHVIEW_BRIDGE__",Ms="__depthview";function er(e){if(typeof e!="object"||e===null)return!1;let t=e;return t.source===yo&&t.v===vo&&typeof t.id=="string"&&t.id.length>0&&t.id.length<=64&&typeof t.type=="string"&&t.type.length>0&&t.type.length<=64&&"payload"in t}function dn(e,t,n){return{source:yo,v:vo,id:n,type:e,payload:t}}var wo=0;function xo(e="m"){return wo=(wo+1)%1e9,`${e}${Date.now().toString(36)}-${wo.toString(36)}`}function ks(e){return typeof e=="object"&&e!==null&&typeof e.ok=="boolean"}var K={now:null,raf:null,caf:null},de=()=>K.now?K.now.call(performance):performance.now(),tr=e=>K.raf?K.raf.call(window,e):requestAnimationFrame(e),Es=e=>K.caf?K.caf.call(window,e):cancelAnimationFrame(e);var nf=96,Ts=1e4,T={paused:!1,inspectorRendering:!1,renderers:[],scenes:[],originals:new WeakMap,pairs:[],canvases:[],canvasSet:new WeakSet,wheelListeners:0,pinned:null,manual:null,visible:{scene:null,at:-1/0},visibleDebug:"",live:!1,onRender:null,cameraOverride:null,effects:null,liveRender:null};function nr(e){!(e instanceof HTMLCanvasElement)||T.canvasSet.has(e)||(T.canvasSet.add(e),T.canvases.push(new WeakRef(e)))}function Mo(e){let t=[];for(let n=e.length-1;n>=0;n--){let r=e[n].deref();r?t.push(r):e.splice(n,1)}return t.reverse()}var mn=()=>Mo(T.renderers),_e=()=>Mo(T.scenes),ko=()=>Mo(T.canvases).filter(e=>e.isConnected);function rf(e,t,n){if(T.inspectorRendering||T.paused&&!T.live||!t||!n||t.isScene!==!0)return null;let r=e.getRenderTarget?e.getRenderTarget():null,o=r===null,i=de();for(let a of T.pairs)if(a.toScreen===o&&a.scene.deref()===t&&a.camera.deref()===n&&a.renderer.deref()===e)return a.t=i,a.target?.deref()!==r&&(a.target=r?new WeakRef(r):null),a;if(T.pairs.length>=nf){let a=0;for(let l=1;l<T.pairs.length;l++)T.pairs[l].t<T.pairs[a].t&&(a=l);T.pairs.splice(a,1)}let s={renderer:new WeakRef(e),scene:new WeakRef(t),camera:new WeakRef(n),toScreen:o,t:i,done:0,target:r?new WeakRef(r):null};return T.pairs.push(s),s}var of=0,So=!1;function rr(e){if(e.isWebGLRenderer!==!0||T.originals.has(e)||typeof e.render!="function")return;let t=e.render,n=Object.prototype.hasOwnProperty.call(e,"render");T.originals.set(e,{render:t,hadOwn:n}),T.renderers.push(new WeakRef(e)),e.render=function(r,o){if(So)return t.call(this,r,o);let i=null,s=null;try{i=rf(e,r,o)}catch{}try{T.cameraOverride&&!T.inspectorRendering&&o&&(s=T.cameraOverride(o))}catch{}let a=t;try{let l=T.effects&&!T.inspectorRendering?T.effects(e,r,o):null;l&&(a=function(c,u){So=!0;try{return l(c,u)}finally{So=!1}})}catch{}try{if(T.paused&&!T.inspectorRendering){if(!T.live)return;if(T.liveRender)return T.liveRender(e,a,this,r,o)}return a.call(this,r,o)}finally{i&&(i.done=++of);try{s?.()}catch{}try{T.onRender?.(e,r,o)}catch{}}};try{nr(e.domElement)}catch{}}function Rs(e){return T.originals.has(e)||rr(e),T.originals.get(e)?.render??e.render}function Lt(){try{let e=window[Ss];return e&&typeof e.getState=="function"?e:null}catch{return null}}var As=e=>e.parent?.type==="CubeCamera";function Eo(e,t,n){let r=0;e.isScene&&(r+=1e3),t.isPerspectiveCamera&&(r+=400),n&&(r+=250),As(t)&&(r-=500);let o=e.children?.length??0;return r+=Math.min(o,100),o<=1&&(r-=300),(!e.isScene||t.isOrthographicCamera&&(e.children?.length??0)<=1)&&(r-=2e3),r}function _(){let e=Lt();if(e)try{let t=e.getState();if(t?.scene&&t.camera&&t.gl?.isWebGLRenderer===!0)return{renderer:t.gl,scene:t.scene,camera:t.camera,toScreen:!0}}catch{}return T.pinned??To()}function Ps(e,t){let n=e.target?.deref();return n?(n.width??0)*(n.height??0):(t.domElement?.width??0)*(t.domElement?.height??0)}function To(e){let t=-1/0;for(let l of T.pairs)l.t>t&&(t=l.t);let n=T.manual?.deref(),r=de()-T.visible.at<3e3?T.visible.scene?.deref():void 0,o=null,i=-1/0,s=-1,a=-1;for(let l=T.pairs.length-1;l>=0;l--){let c=T.pairs[l],u=c.renderer.deref(),f=c.scene.deref(),d=c.camera.deref();if(!u||!f||!d){T.pairs.splice(l,1);continue}let p=t-c.t;if(p>Ts)continue;let m=Eo(f,d,c.toScreen)-p/1e3*30+(f===e&&p<250?60:0)+(f===r&&p<250?400:0)+(f===n?5e3:0),g=o!==null&&o.scene===f&&Math.abs(m-i)<=1,h=Ps(c,u);(g?h>a||h===a&&c.done>s:m>i)&&(i=m,s=c.done,a=h,o={renderer:u,scene:f,camera:d,toScreen:c.toScreen})}return o}function or(){let e=-1/0;for(let n of T.pairs)n.t>e&&(e=n.t);let t=new Map;for(let n of T.pairs){let r=n.renderer.deref(),o=n.scene.deref(),i=n.camera.deref();if(!r||!o||!i||e-n.t>250)continue;let s=Eo(o,i,n.toScreen);if(s<1200||(o.children?.length??0)<=1)continue;let a=t.get(o),l=Ps(n,r);(!a||l>a.area||l===a.area&&n.done>a.done)&&t.set(o,{scene:o,camera:i,renderer:r,target:n.target?.deref()??null,score:s,done:n.done,area:l})}return[...t.values()].sort((n,r)=>r.score-n.score)}function Ro(){let e=-1/0;for(let n of T.pairs)n.t>e&&(e=n.t);return[{visible:T.visibleDebug,pinned:T.pinned?.scene.name||T.pinned?.scene.children?.[0]?.name,pinnedCamera:T.pinned?.camera.name,parent:T.pinned?.camera.parent?.type,auto:T.pinned?.camera.matrixAutoUpdate},...T.pairs.map(n=>{let r=n.scene.deref(),o=n.camera.deref();return{alive:!!r&&!!o&&!!n.renderer.deref(),kids:r?.children?.length,first:r?.children?.[0]?.name,names:r?.children?.slice(0,30).map(i=>`${i.name||"-"}:${i.type}${i.visible?"":":hidden"}`),camera:o?.type,cameraName:o?.name,cameraId:o?.uuid.slice(0,4),cameraAt:o?.matrixWorld.elements.slice(12,15).map(i=>Math.round(i)),target:(()=>{let i=n.target?.deref();return i?`${i.width}x${i.height}`:"screen"})(),done:n.done,toScreen:n.toScreen,age:Math.round(e-n.t),score:r&&o?Math.round(Eo(r,o,n.toScreen)):null}})]}function Pe(){let e=-1/0;for(let t of T.pairs)t.t>e&&(e=t.t);return T.pairs.some(t=>{if(t.toScreen||t.t<e-Ts)return!1;let n=t.scene.deref(),r=t.camera.deref();return!!n?.isScene&&!!r&&!As(r)})}var Y=e=>e!==null&&typeof e=="object"?e:null;function $t(e,t,n=2e4){let r=[e],o=0;for(;r.length&&o<n;){let i=r.pop();o++,t(i);let s=i.children;if(Array.isArray(s))for(let a=s.length-1;a>=0;a--)r.push(s[a])}return o}var jt=e=>Array.isArray(e.material)?e.material:e.material?[e.material]:[],sr=e=>!!Y(e)?.isTexture;function me(e){let t=Y(e.image),n=Number(t?.width??t?.videoWidth??e.mipmaps?.[0]?.width??0)||0,r=Number(t?.height??t?.videoHeight??e.mipmaps?.[0]?.height??0)||0;return{width:n,height:r}}function js(e){if(e.isCompressedTexture&&e.mipmaps?.length)return e.mipmaps.reduce((r,o)=>r+(o.data?.byteLength??0),0);let{width:t,height:n}=me(e);return Math.round(t*n*4*(e.generateMipmaps===!1?1:4/3))}function Ot(e){let t=[],n=e;for(let o of Object.keys(n)){let i=n[o];sr(i)&&t.push({slot:o,texture:i})}let r=e.uniforms;if(r&&typeof r=="object")for(let o of Object.keys(r)){let i=r[o]?.value;sr(i)&&t.push({slot:o,texture:i})}return t}function Os(e){try{let t=Ot(e).slice(0,24).map(({slot:n,texture:r})=>({slot:n,uuid:r.uuid,name:r.name??"",...me(r),bytes:js(r)}));return t.length?t:void 0}catch{return}}var Ie=new Map;function sf(e){let t=_()?.renderer,n=Y(t),r=Y(e);if(!t||!n||!r||r.isCubeTexture||r.isData3DTexture||r.isDataArrayTexture||r.isDepthTexture)return null;let o=t.getContext?.(),i=Y(n.properties),a=(typeof i?.get=="function"?Y(i.get.call(i,e)):null)?.__webglTexture,{width:l,height:c}=me(e);if(!o||!(a instanceof WebGLTexture)||!l||!c)return null;let u=Math.min(1,128/Math.max(l,c)),f=Math.max(1,Math.round(l*u)),d=Math.max(1,Math.round(c*u)),p=null,m=null,g=null,h=null,b=[];try{let y=(E,L)=>{let A=o.createShader(E);return o.shaderSource(A,L),o.compileShader(A),b.push(A),A};if(g=o.createProgram(),o.attachShader(g,y(o.VERTEX_SHADER,"attribute vec2 p;varying vec2 v;void main(){v=p*0.5+0.5;gl_Position=vec4(p,0.0,1.0);}")),o.attachShader(g,y(o.FRAGMENT_SHADER,"precision mediump float;uniform sampler2D t;varying vec2 v;void main(){gl_FragColor=vec4(texture2D(t,v).rgb,1.0);}")),o.linkProgram(g),!o.getProgramParameter(g,o.LINK_STATUS)||(m=o.createTexture(),o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,m),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,f,d,0,o.RGBA,o.UNSIGNED_BYTE,null),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),p=o.createFramebuffer(),o.bindFramebuffer(o.FRAMEBUFFER,p),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,m,0),o.checkFramebufferStatus(o.FRAMEBUFFER)!==o.FRAMEBUFFER_COMPLETE))return null;typeof WebGL2RenderingContext<"u"&&o instanceof WebGL2RenderingContext&&o.bindVertexArray(null),h=o.createBuffer(),o.bindBuffer(o.ARRAY_BUFFER,h),o.bufferData(o.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),o.STATIC_DRAW),o.useProgram(g);let v=o.getAttribLocation(g,"p");o.enableVertexAttribArray(v),o.vertexAttribPointer(v,2,o.FLOAT,!1,0,0);for(let E of[o.DEPTH_TEST,o.BLEND,o.SCISSOR_TEST,o.CULL_FACE,o.STENCIL_TEST])o.disable(E);o.colorMask(!0,!0,!0,!0),o.viewport(0,0,f,d),o.bindTexture(o.TEXTURE_2D,a),o.uniform1i(o.getUniformLocation(g,"t"),0),o.drawArrays(o.TRIANGLES,0,3);let x=new Uint8Array(f*d*4);o.readPixels(0,0,f,d,o.RGBA,o.UNSIGNED_BYTE,x),o.disableVertexAttribArray(v);let M=new ImageData(f,d);for(let E=0;E<d;E++)M.data.set(x.subarray((d-1-E)*f*4,(d-E)*f*4),E*f*4);let S=document.createElement("canvas");S.width=f,S.height=d,S.getContext("2d").putImageData(M,0,0);let k=S.toDataURL("image/png");return S.width=S.height=0,k}catch{return null}finally{try{o.bindFramebuffer(o.FRAMEBUFFER,null),o.bindTexture(o.TEXTURE_2D,null),o.bindBuffer(o.ARRAY_BUFFER,null),o.useProgram(null),p&&o.deleteFramebuffer(p),m&&o.deleteTexture(m),h&&o.deleteBuffer(h);for(let y of b)o.deleteShader(y);g&&o.deleteProgram(g),typeof n.resetState=="function"&&n.resetState.call(t)}catch{}}}function _s(e){let t=Ie.get(e)?.deref();if(t)return t;let n=_();return n?($t(n.scene,r=>{for(let o of jt(r))for(let{texture:i}of Ot(o))Ie.set(i.uuid,new WeakRef(i))}),Ie.get(e)?.deref()??null):null}function Is(e){let t=Ie.get(e)?.deref();if(!t){let o=_();if(!o)return null;$t(o.scene,i=>{for(let s of jt(i))for(let{texture:a}of Ot(s))Ie.set(a.uuid,new WeakRef(a))}),t=Ie.get(e)?.deref()}let n=t?.image,r=n instanceof HTMLImageElement||n instanceof HTMLCanvasElement||n instanceof HTMLVideoElement||typeof ImageBitmap<"u"&&n instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&n instanceof OffscreenCanvas;if(!t)return null;if(!r)return sf(t);try{let{width:o,height:i}=me(t);if(!o||!i)return null;let s=Math.min(1,128/Math.max(o,i)),a=document.createElement("canvas");a.width=Math.max(1,Math.round(o*s)),a.height=Math.max(1,Math.round(i*s)),a.getContext("2d").drawImage(n,0,0,a.width,a.height);let l=a.toDataURL("image/png");return a.width=a.height=0,l}catch{return null}}function Fs(e){let t=Y(e.info),n=Y(t?.memory),r=t?.programs;return{geometries:Number(n?.geometries??0)||0,textures:Number(n?.textures??0)||0,programs:Array.isArray(r)?r.length:0}}function af(e){let t=e.geometry;if(!t)return 0;let n=t.index?.array?.byteLength??0,r=t.attributes??{};for(let o of Object.keys(r))n+=r[o]?.array?.byteLength??0;return n}var lf=e=>e.toLocaleString("en-US");function Vs(){let e=_();if(!e)return null;let t=new Map,n=new Map,r=new Map,o=(l,c,u)=>{let f=l.get(c);f?f.users++:l.set(c,u())},i=$t(e.scene,l=>{let c=l.geometry;c?.uuid&&o(n,c.uuid,()=>{let u=c.attributes?.position?.count??0;return{uuid:c.uuid,name:c.name||c.type||"BufferGeometry",detail:`${lf(u)} verts`,bytes:af(l),users:1,owner:l.uuid}});for(let u of jt(l))if(u.uuid){o(r,u.uuid,()=>({uuid:u.uuid,name:u.name||u.type||"Material",detail:u.type??"Material",bytes:0,users:1,owner:l.uuid}));for(let{slot:f,texture:d}of Ot(u))Ie.set(d.uuid,new WeakRef(d)),o(t,d.uuid,()=>{let{width:p,height:m}=me(d);return{uuid:d.uuid,name:d.name||f,detail:p?`${p} \xD7 ${m}`:"no image",bytes:js(d),users:1,owner:l.uuid}})}}),s=l=>[...l.values()].sort((c,u)=>u.bytes-c.bytes||u.users-c.users).slice(0,400),a=l=>[...l.values()].reduce((c,u)=>c+u.bytes,0);return{textures:s(t),geometries:s(n),materials:s(r),textureBytes:a(t),geometryBytes:a(n),loaded:Fs(e.renderer),objects:i}}function Ds(){let e=_();return e?$t(e.scene,()=>{}):0}var ir=2e5;function Ns(e){let t=_(),n=e?jt(e)[0]:void 0;if(!t||!n)return null;try{let r=Y(Y(t.renderer)?.properties),o=r?.get,i=Y(Y(o?.call(r,n))?.currentProgram),s=t.renderer.getContext?.();if(i&&s){let a=s.getShaderSource(i.vertexShader),l=s.getShaderSource(i.fragmentShader);if(a&&l)return{kind:"compiled",vertex:a.slice(0,ir),fragment:l.slice(0,ir)}}}catch{}return typeof n.vertexShader=="string"&&typeof n.fragmentShader=="string"?{kind:"authored",vertex:n.vertexShader.slice(0,ir),fragment:n.fragmentShader.slice(0,ir)}:null}var cf=[["Base colour",["color","map","vertexColors"]],["Opacity",["opacity","alphaMap","alphaTest","transparent"]],["Normal",["normalMap","normalScale","bumpMap","bumpScale"]],["Roughness",["roughness","roughnessMap"]],["Metalness",["metalness","metalnessMap"]],["Emissive",["emissive","emissiveIntensity","emissiveMap"]],["Ambient occlusion",["aoMap","aoMapIntensity"]],["Environment",["envMap","envMapIntensity","reflectivity"]],["Light map",["lightMap","lightMapIntensity"]],["Displacement",["displacementMap","displacementScale","displacementBias"]],["Specular",["specular","shininess","specularMap","specularIntensity","specularColor"]],["Clearcoat",["clearcoat","clearcoatRoughness","clearcoatMap","clearcoatNormalMap"]],["Transmission",["transmission","thickness","ior","transmissionMap","thicknessMap"]],["Sheen",["sheen","sheenColor","sheenRoughness"]],["Matcap / toon",["matcap","gradientMap"]],["Points",["size","sizeAttenuation"]]],uf=/(Scale|Intensity|Bias|Roughness|Color)$|^(reflectivity|ior|thickness|sizeAttenuation|shininess|transparent)$/,ff=new Set(["clearcoat","transmission","sheen"]),hf=new Set(["color","roughness","metalness","opacity","transparent","emissive","emissiveIntensity","size"]),Po=160,Cs=e=>String(Math.round(e*1e3)/1e3);function $o(e,t,n){let r=Y(n);if(sr(n)){let{width:o,height:i}=me(n);return Ie.set(n.uuid,new WeakRef(n)),{id:e,label:t,detail:o?`Texture \xB7 ${o} \xD7 ${i}`:"Texture",kind:"texture",col:0,ref:n.uuid}}if(typeof n=="number"&&Number.isFinite(n))return{id:e,label:t,detail:Cs(n),kind:"number",col:0,value:n};if(typeof n=="boolean")return{id:e,label:t,detail:n?"on":"off",kind:"flag",col:0,value:n};if(r?.isColor&&typeof r.getHexString=="function"){let o=`#${r.getHexString.call(r)}`;return{id:e,label:t,detail:o,kind:"color",col:0,ref:o,value:o}}if(r&&(r.isVector2||r.isVector3||r.isVector4)){let o=["x","y","z","w"].filter(i=>typeof r[i]=="number").map(i=>Cs(r[i]));return{id:e,label:t,detail:`(${o.join(", ")})`,kind:"vector",col:0,value:r.isVector3?[Number(r.x)||0,Number(r.y)||0,Number(r.z)||0]:void 0}}return r&&(r.isMatrix3||r.isMatrix4)?{id:e,label:t,detail:r.isMatrix4?"mat4":"mat3",kind:"vector",col:0}:Array.isArray(n)&&n.length?{id:e,label:t,detail:`array \xB7 ${n.length}`,kind:"vector",col:0}:null}var Ls=(e,t)=>new RegExp(`(^|[^A-Za-z0-9_])${t.replace(/[^A-Za-z0-9_]/g,"")}([^A-Za-z0-9_]|$)`).test(e);function df(e,t){let n=[{id:"vertex",label:"Vertex shader",detail:`${(e.vertexShader??"").split(`
|
|
2
|
+
`).length} lines`,kind:"stage",col:1},{id:"fragment",label:"Fragment shader",detail:`${(e.fragmentShader??"").split(`
|
|
3
|
+
`).length} lines`,kind:"stage",col:1},{id:"out",label:"Surface",detail:e.type??"ShaderMaterial",kind:"output",col:2}],r=[{from:"vertex",to:"fragment"},{from:"fragment",to:"out"}],o=e.vertexShader??"",i=e.fragmentShader??"",s=!1;for(let l of o.matchAll(/(?:^|\n)\s*(?:attribute|in)\s+\w+\s+(\w+)\s*;/g)){if(n.length>=Po)break;let c=`a:${l[1]}`;n.some(u=>u.id===c)||(n.push({id:c,label:l[1],detail:"geometry attribute",kind:"attribute",col:0}),r.push({from:c,to:"vertex"}))}let a=e.uniforms??{};for(let l of Object.keys(a)){if(n.length>=Po){s=!0;break}let c=Ls(o,l),u=Ls(i,l),f=$o(`u:${l}`,l,a[l]?.value)??{id:`u:${l}`,label:l,detail:"not set",kind:"flag",col:0};!c&&!u&&(f.detail+=" \xB7 unused"),(f.value!==void 0||f.kind==="texture")&&(f.path=`uniform.${l}`),f.kind==="texture"&&(f.replaced=ht.has(`${e.uuid}|uniform.${l}`)),n.push(f),c&&r.push({from:f.id,to:"vertex"}),u&&r.push({from:f.id,to:"fragment"})}return{uuid:"",title:t,flavour:"shader",nodes:n,edges:r,truncated:s}}function mf(e,t){let n=e,r=[{id:"out",label:"Surface",detail:e.type??"NodeMaterial",kind:"output",col:0}],o=[],i=new Map,s=new Map([["out",0]]),a=!1,l=(u,f,d,p)=>{let m=i.get(u);if(m)(s.get(m)??0)<d&&s.set(m,d);else{if(r.length>=Po){a=!0;return}m=`n${i.size}`,i.set(u,m);let g=u.value,h=g!==void 0?$o(m,"",g):null;if(r.push({id:m,label:String(u.name||u.type||u.nodeType||"Node").replace(/Node$/,"")||"Node",detail:h?h.detail:p,kind:h&&h.kind!=="flag"?h.kind:"node",col:0,ref:h?.ref}),s.set(m,d),d<24)for(let b of Object.keys(u)){if(b==="parents"||b.startsWith("_"))continue;let y=u[b],v=Array.isArray(y)?y:[y];for(let x of v){let M=Y(x);M?.isNode&&l(M,m,d+1,b)}}}o.push({from:m,to:f})};for(let u of Object.keys(n)){let f=Y(n[u]);if(!u.endsWith("Node")||!f?.isNode)continue;let d=`c:${u}`;r.push({id:d,label:u.replace(/Node$/,""),detail:"slot",kind:"channel",col:0}),s.set(d,1),o.push({from:d,to:"out"}),l(f,d,2,u)}let c=Math.max(...s.values());for(let u of r)u.col=c-(s.get(u.id)??0);return{uuid:"",title:t,flavour:"nodes",nodes:r,edges:o,truncated:a}}function pf(e,t){let n=e;if(n.isNodeMaterial){let i=mf(e,t);if(i.nodes.length>1)return i}if(typeof e.vertexShader=="string"&&typeof e.fragmentShader=="string"&&e.uniforms)return df(e,t);let r=[{id:"out",label:"Surface",detail:e.type??"Material",kind:"output",col:2}],o=[];for(let[i,s]of cf){let a=[],l=!1;for(let u of s){let f=n[u];if(f===!1||f===null||f===void 0||u==="alphaTest"&&f===0||u==="opacity"&&f===1&&!n.transparent||ff.has(u)&&f===0||u==="emissive"&&!n.emissiveMap&&Y(f)?.getHexString&&f.getHexString()==="000000")continue;let d=$o(`p:${u}`,u,f);d&&(d.value!==void 0&&hf.has(u)&&(d.path=`material.${u}`),d.kind==="texture"&&(d.path=`material.${u}`,d.replaced=ht.has(`${e.uuid}|material.${u}`)),a.push(d),uf.test(u)||(l=!0))}if(!l||a.length===0)continue;let c=`c:${i}`;r.push({id:c,label:i,detail:"channel",kind:"channel",col:1},...a),o.push({from:c,to:"out"},...a.map(u=>({from:u.id,to:c})))}return{uuid:"",title:t,flavour:"standard",nodes:r,edges:o,truncated:!1}}var ht=new Map;function zs(e,t){if(t.startsWith("uniform.")){let n=e.uniforms?.[t.slice(8)];return n?{get:()=>n.value,set:r=>n.value=r}:null}if(t.startsWith("material.")){let n=e,r=t.slice(9);return r in n?{get:()=>n[r],set:o=>n[r]=o}:null}return null}function gf(e){let t=Object.getPrototypeOf(e);for(let n=0;t&&n<6;n++){let r=Object.getPrototypeOf(t);if(r&&Object.prototype.hasOwnProperty.call(r,"dispatchEvent"))return t.constructor;t=r}return null}function Co(e){let t=ht.get(e);if(t){ht.delete(e);try{zs(t.material,t.path)?.set(t.original),t.material.needsUpdate=!0,typeof t.mine.dispose=="function"&&t.mine.dispose.call(t.mine),t.mine.image?.close?.()}catch{}}}async function Ws(e,t,n){let r=e?jt(e)[0]:void 0;if(!r?.uuid)return!1;let o=`${r.uuid}|${t}`;if(n===null)return Co(o),!0;let i=zs(r,t),s=ht.get(o)?.original??i?.get();if(!i||!sr(s)||!n.startsWith("data:image/"))return!1;let a=gf(s);if(!a)return!1;try{let l=atob(n.slice(n.indexOf(",")+1)),c=new Uint8Array(l.length);for(let m=0;m<l.length;m++)c[m]=l.charCodeAt(m);let u=n.slice(5,n.indexOf(";")),f=s,d=await createImageBitmap(new Blob([c],{type:u}),{imageOrientation:f.flipY===!1?"none":"flipY"}),p=new a(d);for(let m of["wrapS","wrapT","colorSpace","encoding","channel","anisotropy","name"])m in f&&m in p&&(p[m]=f[m]);for(let m of["repeat","offset","center"])p[m]?.copy?.(f[m]);return p.rotation=f.rotation??0,p.flipY=!1,p.needsUpdate=!0,Co(o),ht.set(o,{material:r,path:t,original:s,mine:p}),i.set(p),r.needsUpdate=!0,!0}catch{return!1}}function Bs(e){let t=e?jt(e)[0]:void 0;if(!e||!t)return null;try{return{...pf(t,`${e.name||e.type} \xB7 ${t.name||t.type||"Material"}`),uuid:e.uuid}}catch{return null}}var Ao=[];function jo(e){for(let r of Ao){let o=r.deref();o&&(o.visible=!0)}Ao=[];let t=_();if(!e||!t)return!1;let n=new Set;return $t(e,r=>n.add(r)),$t(t.scene,r=>{(r.isMesh||r.isPoints||r.isLine||r.isSprite)&&r.visible&&!n.has(r)&&(r.visible=!1,Ao.push(new WeakRef(r)))}),!0}var bf=600,ut=[],Lo=0,ar=!1,Qe=0,pn=0,gn={calls:0,triangles:0,passes:0},$s=new WeakMap,ge=null,ft=null,bn=[];function Hs(e=700){return new Promise(t=>{let n=o=>{clearTimeout(r),bn=bn.filter(i=>i!==n),t(o)},r=setTimeout(()=>n(!1),e);bn.push(n)})}function Us(e,t,n){if(bn.length&&(e.getRenderTarget?.()??null)===null)for(let l of bn.slice())l(!0);if(!ar&&!ge)return;let r=Y(e.info),o=Y(r?.render),i={calls:Number(o?.calls??0)||0,triangles:Number(o?.triangles??0)||0},s=i.calls,a=i.triangles;if(r?.autoReset===!1){let l=$s.get(e);l&&i.calls>=l.calls&&(s=i.calls-l.calls,a=Math.max(0,i.triangles-l.triangles)),$s.set(e,i)}if(gn.calls+=s,gn.triangles+=a,gn.passes++,ge&&ge.length<200){let l=Y(e.getRenderTarget?.());ge.push({scene:t.name||t.type||"Scene",objects:Array.isArray(t.children)?t.children.length:0,camera:n.name||n.type||"Camera",target:l?`${Number(l.width)||0} \xD7 ${Number(l.height)||0}`:"screen",targetWidth:l?Number(l.width)||0:void 0,samples:l?Number(l.samples)||0:void 0,calls:s,triangles:a})}}function Oo(e){if(pn>0&&(ut.push({dt:e-pn,...gn}),ut.length>bf&&ut.shift(),Lo++),pn=e,gn={calls:0,triangles:0,passes:0},ge&&ft&&ge.length>0){let t=ft,n=ge;ge=null,ft=null,t(n)}Qe=ar||ge?tr(Oo):0}function qs(e){ar=e,e&&!Qe&&(pn=0,Qe=tr(Oo))}function Gs(e){let t=Math.min(ut.length,Math.max(0,Lo-e)),n=Y(Y(performance)?.memory),r=_();return{seq:Lo,samples:t?ut.slice(ut.length-t):[],heap:n&&Number(n.usedJSHeapSize)||null,loaded:r?Fs(r.renderer):{geometries:0,textures:0,programs:0}}}function lr(){return new Promise(e=>{ge=[],ft=e,Qe||(pn=0,Qe=tr(Oo)),setTimeout(()=>{if(ft!==e)return;let t=ge??[];ge=null,ft=null,e(t)},1500)})}function Ks(){for(let e of[...ht.keys()])Co(e);jo(null),ar=!1,ge=null,ft=null,Qe&&Es(Qe),Qe=0,ut.length=0,Ie.clear()}var yn=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]];var cr=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Xs=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Ze=e=>Math.hypot(e[0],e[1],e[2]),Js=(e,t)=>Ze(yn(e,t)),ur=e=>{let t=Ze(e);return t>1e-12?[e[0]/t,e[1]/t,e[2]/t]:[0,0,0]};var Ys=()=>[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function ae(e,t){let n=new Array(16);for(let r=0;r<4;r++)for(let o=0;o<4;o++)n[r*4+o]=e[o]*t[r*4]+e[4+o]*t[r*4+1]+e[8+o]*t[r*4+2]+e[12+o]*t[r*4+3];return n}function be(e){let[t,n,r,o,i,s,a,l,c,u,f,d,p,m,g,h]=e,b=u*g*l-m*f*l+m*a*d-s*g*d-u*a*h+s*f*h,y=p*f*l-c*g*l-p*a*d+i*g*d+c*a*h-i*f*h,v=c*m*l-p*u*l+p*s*d-i*m*d-c*s*h+i*u*h,x=p*u*a-c*m*a-p*s*f+i*m*f+c*s*g-i*u*g,M=t*b+n*y+r*v+o*x;if(Math.abs(M)<1e-20)return null;let S=1/M;return[b*S,(m*f*o-u*g*o-m*r*d+n*g*d+u*r*h-n*f*h)*S,(s*g*o-m*a*o+m*r*l-n*g*l-s*r*h+n*a*h)*S,(u*a*o-s*f*o-u*r*l+n*f*l+s*r*d-n*a*d)*S,y*S,(c*g*o-p*f*o+p*r*d-t*g*d-c*r*h+t*f*h)*S,(p*a*o-i*g*o-p*r*l+t*g*l+i*r*h-t*a*h)*S,(i*f*o-c*a*o+c*r*l-t*f*l-i*r*d+t*a*d)*S,v*S,(p*u*o-c*m*o-p*n*d+t*m*d+c*n*h-t*u*h)*S,(i*m*o-p*s*o+p*n*l-t*m*l-i*n*h+t*s*h)*S,(c*s*o-i*u*o-c*n*l+t*u*l+i*n*d-t*s*d)*S,x*S,(c*m*r-p*u*r+p*n*f-t*m*f-c*n*g+t*u*g)*S,(p*s*r-i*m*r-p*n*a+t*m*a+i*n*g-t*s*g)*S,(i*u*r-c*s*r+c*n*a-t*u*a-i*n*f+t*s*f)*S]}function oe(e,t){let n=t[0],r=t[1],o=t[2],i=e[3]*n+e[7]*r+e[11]*o+e[15],s=Math.abs(i)>1e-20?1/i:1;return[(e[0]*n+e[4]*r+e[8]*o+e[12])*s,(e[1]*n+e[5]*r+e[9]*o+e[13])*s,(e[2]*n+e[6]*r+e[10]*o+e[14])*s]}function fr(e,t){return[e[0]*t[0]+e[4]*t[1]+e[8]*t[2],e[1]*t[0]+e[5]*t[1]+e[9]*t[2],e[2]*t[0]+e[6]*t[1]+e[10]*t[2]]}var le=e=>[e[12],e[13],e[14]];function et(e,t,n){let[r,o,i,s]=t,a=r+r,l=o+o,c=i+i,u=r*a,f=r*l,d=r*c,p=o*l,m=o*c,g=i*c,h=s*a,b=s*l,y=s*c;return[(1-(p+g))*n[0],(f+y)*n[0],(d-b)*n[0],0,(f-y)*n[1],(1-(u+g))*n[1],(m+h)*n[1],0,(d+b)*n[2],(m-h)*n[2],(1-(u+p))*n[2],0,e[0],e[1],e[2],1]}function Fe(e){let t=Math.hypot(e[0],e[1],e[2])||1,n=Math.hypot(e[4],e[5],e[6])||1,r=Math.hypot(e[8],e[9],e[10])||1;return vf([e[0]/t,e[1]/t,e[2]/t],[e[4]/n,e[5]/n,e[6]/n],[e[8]/r,e[9]/r,e[10]/r])}function vf(e,t,n){let r=e[0],o=e[1],i=e[2],s=t[0],a=t[1],l=t[2],c=n[0],u=n[1],f=n[2],d=r+a+f;if(d>0){let m=.5/Math.sqrt(d+1);return[(l-u)*m,(c-i)*m,(o-s)*m,.25/m]}if(r>a&&r>f){let m=2*Math.sqrt(1+r-a-f);return[.25*m,(s+o)/m,(c+i)/m,(l-u)/m]}if(a>f){let m=2*Math.sqrt(1+a-r-f);return[(s+o)/m,.25*m,(u+l)/m,(c-i)/m]}let p=2*Math.sqrt(1+f-r-a);return[(c+i)/p,(u+l)/p,.25*p,(o-s)/p]}function Qs(e,t,n,r){let o=1/Math.tan(e*Math.PI/360),i=1/(n-r);return[o/t,0,0,0,0,o,0,0,0,0,(r+n)*i,-1,0,0,2*r*n*i,0]}function Zs(e,t,n,r,o,i){let s=1/(t-e),a=1/(n-r),l=1/(i-o);return[2*s,0,0,0,0,2*a,0,0,0,0,-2*l,0,-(t+e)*s,-(n+r)*a,-(i+o)*l,1]}function _o(e,t,n,r){let o=ae(e,t),i=oe(o,[n,r,-1]),s=oe(o,[n,r,1]);return{origin:i,direction:ur(yn(s,i))}}function Io(e,t,n){let r=-1/0,o=1/0;for(let i=0;i<3;i++){let s=e.origin[i],a=e.direction[i];if(Math.abs(a)<1e-12){if(s<t[i]||s>n[i])return null;continue}let l=(t[i]-s)/a,c=(n[i]-s)/a;if(l>c&&([l,c]=[c,l]),l>r&&(r=l),c<o&&(o=c),r>o)return null}return o<0?null:Math.max(r,0)}function ea(e,t,n,r){let o=yn(n,t),i=yn(r,t),s=Xs(e.direction,i),a=cr(o,s);if(Math.abs(a)<1e-12)return null;let l=1/a,c=yn(e.origin,t),u=cr(c,s)*l;if(u<0||u>1)return null;let f=Xs(c,o),d=cr(e.direction,f)*l;if(d<0||u+d>1)return null;let p=cr(i,f)*l;return p>=0?p:null}function _t(e,t){return[[e[0],e[1],e[2]],[t[0],e[1],e[2]],[t[0],t[1],e[2]],[e[0],t[1],e[2]],[e[0],e[1],t[2]],[t[0],e[1],t[2]],[t[0],t[1],t[2]],[e[0],t[1],t[2]]]}function tt(e){let t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0];for(let r of e)for(let o=0;o<3;o++)r[o]<t[o]&&(t[o]=r[o]),r[o]>n[o]&&(n[o]=r[o]);return{min:t,max:n}}var Ee=(e,t=3)=>{let n=10**t,r=Math.round(e*n)/n;return Object.is(r,-0)?0:r};var hr=class{items=[];add(t,n){let r={label:t,fn:n};return this.items.push(r),()=>{let o=this.items.indexOf(r);if(o>=0){this.items.splice(o,1);try{n()}catch{}}}}addListener(t,n,r,o){return t.addEventListener(n,r,o),this.add(`listener:${n}`,()=>t.removeEventListener(n,r,o))}addStyle(t,n,r="style"){let o=document.createElement("style");return o.textContent=t,n.appendChild(o),this.add(r,()=>o.remove()),o}get size(){return this.items.length}labels(){return this.items.map(t=>t.label)}flush(){let t=this.items;this.items=[];for(let n=t.length-1;n>=0;n--)try{t[n].fn()}catch{}}};var wf=5e3,xf=4e5,Fo=new hr,It=null,gt=null,Vt=null,Mn=null,kn=null,fa=-1/0,ta=0,Vo=!1,En=[],ha=null,Tn=null,mr=0,mt=new Map,xn=[],An=-1e3,vn=null,wn=null,Do=()=>{let e=window.__THREE__;return e==null?null:String(e)},pt=e=>[e.x,e.y,e.z],Sn=e=>e&&typeof e.getHexString=="function"?`#${e.getHexString()}`:void 0,N=e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,Ve=e=>Array.isArray(e.material)?e.material[0]:e.material;function da(e){return e.isMesh?"mesh":e.isPoints||e.isLine||e.isSprite?"points":e.isLight?"light":e.isCamera?"camera":"object"}function nt(e,t,n=2e4){let r=[e],o=0;for(;r.length&&o<n;){let i=r.pop();if(o++,t(i)===!1)continue;let s=i.children;if(Array.isArray(s))for(let a=s.length-1;a>=0;a--)r.push(s[a])}}function Bo(){let e=_();return{three:mn().length>0||Do()!==null,revision:Do(),renderers:mn().length,scenes:_e().length,webglCanvases:ko().length,hasActive:e!==null,bridge:Lt()!==null,postProcessing:Pe(),wheelDriven:T.wheelListeners>0}}function Ft(e,t){let{renderer:n,scene:r}=e,o=Rs(n),i=n.getRenderTarget?.()??null,s=n.autoClear,a=n.getScissorTest?.()??!1;T.inspectorRendering=!0;try{i!==null&&n.setRenderTarget?.(null),s===!1&&(n.autoClear=!0),a&&n.setScissorTest?.(!1),o.call(n,r,t)}finally{T.inspectorRendering=!1;try{i!==null&&n.setRenderTarget?.(i),s===!1&&(n.autoClear=!1),a&&n.setScissorTest?.(!0)}catch{}}}function Dt(e){e.parent||e.updateMatrixWorld()}function ma(){if(!T.paused){T.pinned=_(),T.paused=!0,Fo.add("unpause",()=>{T.paused=!1});for(let e of mn()){let t=e.clear;if(typeof t!="function")continue;let n=Object.prototype.hasOwnProperty.call(e,"clear");e.clear=function(...r){if(!(T.paused&&!T.inspectorRendering&&!T.live))return t.apply(this,r)},Fo.add("unwrap-clear",()=>{n?e.clear=t:delete e.clear})}}return Bo()}function pa(){let e=_();T.cameraOverride=null,Ho(!1);for(let t of document.querySelectorAll(`[${Ct}]`))t.removeAttribute(Ct);if(Fo.flush(),T.paused=!1,T.pinned=null,It=null,gt=null,Vt=null,Mn=null,kn=null,Rn=new Map,pr=null,W.hide=null,W.queue=[],W.base=null,W.changes.clear(),W.wait=20,T.live=!1,T.manual=null,T.visible={scene:null,at:-1/0},En=[],Tn=null,wn=null,mt=new Map,xn=[],An=-1e3,e)try{Dt(e.camera),e.toScreen&&Ft(e,e.camera)}catch{}}function Sf(e){let t=e;for(let n=0;n<8;n++){let r=t.getRootNode();if(!(r instanceof ShadowRoot))break;t=r.host}return t}function ga(){let e=new Set(ko());for(let n of mn())n.domElement instanceof HTMLCanvasElement&&n.domElement.isConnected&&e.add(n.domElement);for(let n of document.querySelectorAll(`[${Ct}]`))n.removeAttribute(Ct);let t=0;for(let n of e){let r=n.getBoundingClientRect(),o=getComputedStyle(n);r.width<2||r.height<2||o.visibility==="hidden"||o.display==="none"||(Sf(n).setAttribute(Ct,""),t++)}return t}async function ba(){let e=_();return e?await qo(3,500)?!0:Pe()?!1:(Dt(e.camera),Ft(e,e.camera),!0):!1}var gr={count:0,sum:0};function ya(e){let t=_()?.renderer.domElement;if(!(t instanceof HTMLCanvasElement)||!t.isConnected||!Number.isFinite(e))return!1;gr.count++,gr.sum+=e;let n=t.getBoundingClientRect();return t.dispatchEvent(new WheelEvent("wheel",{deltaY:e,deltaMode:0,bubbles:!0,cancelable:!0,composed:!0,clientX:n.left+n.width/2,clientY:n.top+n.height/2})),!0}async function va(){let e={ok:!1,width:0,height:0},t=_(),n=document.getElementById(Ye)?.shadowRoot?.getElementById(vs);if(!t||!(n instanceof HTMLCanvasElement))return e;if(!await qo(3,500)){if(Pe())return e;Dt(t.camera),Ft(t,t.camera)}let r=t.renderer.domElement;if(!r.width||!r.height)return e;let o=Math.min(1,ws/r.width);n.width=Math.round(r.width*o),n.height=Math.round(r.height*o);let i=n.getContext("2d");return i?(i.clearRect(0,0,n.width,n.height),i.drawImage(r,0,0,n.width,n.height),{ok:!0,width:n.width,height:n.height}):e}async function br(e=1920,t=1200){let n=_();if(!n)return null;if(T.paused){if(!await qo(3,500)){if(Pe())return null;Dt(n.camera),Ft(n,n.camera)}}else if(!await Hs()){if(Pe())return null;Ft(n,n.camera)}let r=n.renderer.domElement;if(!r.width||!r.height)return null;let o=Math.min(r.width,e),i=Math.min(r.height,t),s=document.createElement("canvas");s.width=o,s.height=i;let a=s.getContext("2d",{willReadFrequently:!0});if(!a)return null;a.drawImage(r,Math.floor((r.width-o)/2),Math.floor((r.height-i)/2),o,i,0,0,o,i);try{return{data:a.getImageData(0,0,o,i).data,width:o,height:i}}catch{return null}finally{s.width=s.height=0}}function wa(e){let t=e.renderer,n=t.domElement;return{revision:Do(),width:n?.width??0,height:n?.height??0,pixelRatio:N(t.getPixelRatio?.())??1,calls:N(t.info?.render?.calls)??0,triangles:N(t.info?.render?.triangles)??0,textures:N(t.info?.memory?.textures)??0,geometries:N(t.info?.memory?.geometries)??0,scenes:Math.max(_e().length,1),postProcessing:Pe()}}function xa(){let e=_();return e?wa(e):null}function Mf(e){let t=e.geometry;if(!t)return null;!t.boundingBox&&typeof t.computeBoundingBox=="function"&&t.computeBoundingBox();let n=t.boundingBox;return!n||!Number.isFinite(n.min.x)||!Number.isFinite(n.max.x)?null:{min:pt(n.min),max:pt(n.max)}}function bt(e){let t=Mf(e);if(!t)return null;let n=e.matrixWorld.elements;return _t(t.min,t.max).map(r=>oe(n,r))}function Sa(){let e=_();if(!e)return null;let{scene:t,camera:n}=e;Dt(n),t.updateMatrixWorld(),mt=new Map;let r=0,o=!1,i=!1,s=[],a=[],l=g=>{if(r++,mt.set(g.uuid,new WeakRef(g)),g===n&&(i=!0),g.isMesh&&g.visible&&s.length<4e4){let b=bt(g);b&&(s.push(...b),Ea(g)&&a.push(tt(b)))}let h=[];for(let b of Array.isArray(g.children)?g.children:[]){if(r>=wf){o=!0;break}h.push(l(b))}return{uuid:String(g.uuid),name:typeof g.name=="string"?g.name:"",type:typeof g.type=="string"?g.type:"Object3D",visible:g.visible!==!1,kind:da(g),children:h}},c=l(t);mt.set(n.uuid,new WeakRef(n)),An=-1e3;let u=[0,0,0],f=5;if(s.length){let{min:g,max:h}=tt(s);u=[(g[0]+h[0])/2,(g[1]+h[1])/2,(g[2]+h[2])/2],f=Math.max(Ze([h[0]-g[0],h[1]-g[1],h[2]-g[2]])/2,.001)}let d=(T.live?Ln.get(t)?.matrixWorld:void 0)??n.matrixWorld.elements,p=e.renderer.domElement,m=No(a,le(d),ur(fr(d,[0,0,-1])),{center:u,radius:f});return{tree:c,nodeCount:r,truncated:o,bounds:{center:u,radius:f},focus:m,siteCamera:{uuid:n.uuid,type:n.type,perspective:!!n.isPerspectiveCamera,position:le(d),quaternion:Fe(d),fov:N(n.fov)??50,near:N(n.near)??.1,far:N(n.far)??2e3,aspect:N(n.aspect)??(p.height?p.width/p.height:1),inScene:i},canvas:{width:p.width,height:p.height},info:wa(e)}}function No(e,t,n,r,o=0,i=.25){let s=[];for(let{min:l,max:c}of e){if([0,1,2].every(m=>t[m]>l[m]&&t[m]<c[m]))continue;let f=[(l[0]+c[0])/2-t[0],(l[1]+c[1])/2-t[1],(l[2]+c[2])/2-t[2]],d=f[0]*n[0]+f[1]*n[1]+f[2]*n[2],p=Ze(f);d>0&&d>=p*o&&s.push(p)}if(s.length===0)return r;s.sort((l,c)=>l-c);let a=Math.max(s[Math.floor((s.length-1)*i)],.001);return{center:[t[0]+n[0]*a,t[1]+n[1]*a,t[2]+n[2]*a],radius:Math.min(a*.75,r.radius)}}function re(e){let t=_();if(!t)return null;if(t.camera.uuid===e)return t.camera;let n=mt.get(e)?.deref();if(n)return n;let r=null;return nt(t.scene,o=>(o.uuid===e&&(r=o),r===null)),r&&mt.set(e,new WeakRef(r)),r}function na(e){let t=e?.[Ms];if(t&&typeof t.file=="string"&&typeof t.line=="number"&&typeof t.column=="number")return{file:t.file,line:t.line,column:t.column,component:typeof t.component=="string"?t.component:""}}function Pn(e){let t=re(e);if(!t)return null;let n=[];if(nt(t,s=>{if(n.length>=16e3)return!1;let a=bt(s);a&&n.push(...a)},4e3),!n.length)return null;let{min:r,max:o}=tt(n),i=s=>Math.round(s*1e3)/1e3;return{min:[i(r[0]),i(r[1]),i(r[2])],max:[i(o[0]),i(o[1]),i(o[2])],size:[i(o[0]-r[0]),i(o[1]-r[1]),i(o[2]-r[2])],center:[i((r[0]+o[0])/2),i((r[1]+o[1])/2),i((r[2]+o[2])/2)]}}function yr(e){let t=re(e);if(!t)return null;let n=_(),r={uuid:t.uuid,name:typeof t.name=="string"?t.name:"",type:t.type,kind:da(t),position:pt(t.position),rotation:pt(t.rotation),scale:pt(t.scale),visible:t.visible!==!1,castShadow:!!t.castShadow,receiveShadow:!!t.receiveShadow,source:na(t.userData)},o=Ve(t);if(t.isMesh||t.isPoints||t.isLine||t.isSprite){let i=t.geometry,s=i?.attributes?.position?.count??0;r.mesh={geometryType:i?.type??(t.isSprite?"Sprite":"BufferGeometry"),vertices:s,triangles:t.isMesh?Math.floor((i?.index?i.index.count:s)/3):0,materialType:o?.type??"Material",color:o?.color?.isColor?Sn(o.color):void 0,roughness:N(o?.roughness),metalness:N(o?.metalness),opacity:N(o?.opacity),transparent:typeof o?.transparent=="boolean"?o.transparent:void 0,hasMap:!!o?.map,materialSource:na(o?.userData),size:N(o?.size),uniforms:kf(o),emissive:o?.emissive?.isColor?Sn(o.emissive):void 0,emissiveIntensity:N(o?.emissiveIntensity),side:N(o?.side),depthTest:typeof o?.depthTest=="boolean"?o.depthTest:void 0,depthWrite:typeof o?.depthWrite=="boolean"?o.depthWrite:void 0,wireframe:typeof o?.wireframe=="boolean"?o.wireframe:void 0,flatShading:typeof o?.flatShading=="boolean"?o.flatShading:void 0,textures:o?Os(o):void 0,hasShader:!!o}}if(t.isLight&&(r.light={color:Sn(t.color)??"#ffffff",intensity:N(t.intensity)??1,distance:N(t.distance),decay:N(t.decay),angle:N(t.angle),penumbra:N(t.penumbra)}),t.isCamera){let i=t;r.camera={fov:i.isPerspectiveCamera?N(i.fov):void 0,near:N(i.near)??.1,far:N(i.far)??2e3,zoom:N(i.zoom)??1,isSiteCamera:i===n?.camera}}return r}function kf(e){let t=e?.uniforms;if(!t||typeof t!="object")return;let n=[];for(let r of Object.keys(t)){if(n.length>=48)break;let o=t[r]?.value;typeof o=="number"&&Number.isFinite(o)?n.push({name:r,kind:"number",value:o}):typeof o=="boolean"?n.push({name:r,kind:"boolean",value:o}):o&&typeof o=="object"&&o.isColor&&o.getHexString?n.push({name:r,kind:"color",value:`#${o.getHexString()}`}):o&&typeof o=="object"&&o.isVector3&&n.push({name:r,kind:"vec3",value:[o.x??0,o.y??0,o.z??0]})}return n.length?n:void 0}var ra=e=>Array.isArray(e)&&e.length===3&&e.every(t=>typeof t=="number"&&Number.isFinite(t));function Ma(e,t,n){let r=re(e);if(!r)return null;let o=typeof n=="number"&&Number.isFinite(n);switch(t){case"position":case"rotation":case"scale":ra(n)&&r[t].set(n[0],n[1],n[2]);break;case"visible":case"castShadow":case"receiveShadow":r[t]=!!n;break;case"color":typeof n=="string"&&r.color?.set(n);break;case"intensity":case"distance":case"decay":case"angle":case"penumbra":o&&(r[t]=n);break;case"fov":case"near":case"far":case"zoom":if(o&&r.isCamera){let i=r;i[t]=n,i.updateProjectionMatrix()}break;case"material.color":typeof n=="string"&&Ve(r)?.color?.set(n);break;case"material.roughness":case"material.metalness":case"material.opacity":{let i=Ve(r);i&&o&&(i[t.slice(9)]=n);break}case"material.emissive":{let i=Ve(r);i?.emissive&&typeof n=="string"&&i.emissive.set(n);break}case"material.emissiveIntensity":case"material.side":{let i=Ve(r);i&&o&&(i[t.slice(9)]=n,i.needsUpdate=!0);break}case"material.depthTest":case"material.depthWrite":case"material.wireframe":case"material.flatShading":{let i=Ve(r);i&&(i[t.slice(9)]=!!n,i.needsUpdate=!0);break}case"material.transparent":{let i=Ve(r);i&&(i.transparent=!!n,i.needsUpdate=!0);break}case"material.size":{let i=Ve(r);i&&o&&(i.size=n);break}default:{let i=t.startsWith("uniform.")?Ve(r)?.uniforms?.[t.slice(8)]:void 0;if(!i)throw new Error(`Unsupported property: ${t}`);let s=i.value;typeof s=="number"&&o?i.value=n:typeof s=="boolean"?i.value=!!n:s&&typeof s=="object"&&s.isColor&&typeof n=="string"?s.set?.(n):s&&typeof s=="object"&&s.isVector3&&ra(n)&&s.set?.(n[0],n[1],n[2])}}return yr(e)}function ka(e){return Tn=e,e?yr(e):null}function Ho(e){if(!e){if(vn)for(let[r,o]of vn)try{r.wireframe=o}catch{}vn=null;return}let t=_();if(!t||vn)return;let n=new Map;nt(t.scene,r=>{if(!r.isMesh)return;let o=Array.isArray(r.material)?r.material:r.material?[r.material]:[];for(let i of o)typeof i.wireframe=="boolean"&&!n.has(i)&&(n.set(i,i.wireframe),i.wireframe=!0)}),vn=n}function Ea(e){for(let t=e;t;t=t.parent)if(t.visible===!1)return!1;return!0}function Ta(e,t){return Aa(e,t)?.uuid??null}function Ra(e,t){let n=_(),r=n?.renderer.domElement;if(!n||!(r instanceof HTMLCanvasElement)||!r.isConnected)return!1;let o=gt??Cn(n.camera),i=_o(o.matrixWorld,o.projectionMatrixInverse,e,t),s=Aa(e,t)?.t??zo,a=[i.origin[0]+i.direction[0]*s,i.origin[1]+i.direction[1]*s,i.origin[2]+i.direction[2]*s],l=Mn??Ln.get(n.scene)??vr(n.camera),c=be(l.matrixWorld);if(!c)return!1;let u=ae(n.camera.projectionMatrix.elements.slice(0,16),c),f=u[3]*a[0]+u[7]*a[1]+u[11]*a[2]+u[15];if(!(f>1e-6))return!1;let d=(u[0]*a[0]+u[4]*a[1]+u[8]*a[2]+u[12])/f,p=(u[1]*a[0]+u[5]*a[1]+u[9]*a[2]+u[13])/f;if(Math.abs(d)>1||Math.abs(p)>1)return!1;let m=r.getBoundingClientRect(),g=m.left+(d+1)/2*m.width,h=m.top+(1-p)/2*m.height,b=document.elementsFromPoint(g,h).find(v=>v.id!==Ye)??r,y={bubbles:!0,cancelable:!0,composed:!0,clientX:g,clientY:h,screenX:g,screenY:h,view:window};try{b.dispatchEvent(new PointerEvent("pointermove",{...y,pointerId:1,pointerType:"mouse",isPrimary:!0})),b.dispatchEvent(new MouseEvent("mousemove",y))}catch{return!1}return!0}function Aa(e,t){let n=_();if(!n)return null;let r=gt??Cn(n.camera),o=_o(r.matrixWorld,r.projectionMatrixInverse,e,t),i=r.mask,s=[];nt(n.scene,l=>{if(l.visible===!1)return!1;if(!(l.isMesh||l.isPoints||l.isLine||l.isSprite)||l.layers&&(l.layers.mask&i)===0)return;let u=bt(l);if(!u&&l.isSprite){let m=le(l.matrixWorld.elements),g=Math.max(Math.abs(l.scale.x),Math.abs(l.scale.y),.001)/2;u=_t([m[0]-g,m[1]-g,m[2]-g],[m[0]+g,m[1]+g,m[2]+g])}if(!u)return;let{min:f,max:d}=tt(u),p=Io(o,f,d);p!==null&&s.push({o:l,t:p})}),s.sort((l,c)=>l.t-c.t);let a=null;for(let{o:l,t:c}of s.slice(0,8)){if(a&&c>a.t)break;let u=l.isPoints?Tf(l,o.origin,o.direction)??null:l.isLine||l.isSprite||l.isSkinnedMesh||l.isInstancedMesh?c:Ef(l,o.origin,o.direction)??null;u!==null&&(!a||u<a.t)&&(a={uuid:l.uuid,t:u})}return a}function Ef(e,t,n){let r=e.geometry?.attributes?.position,o=be(e.matrixWorld.elements);if(!r||!o||typeof r.getX!="function")return;let i=oe(o,t),s=fr(o,n),a=Ze(s);if(a===0)return;let l={origin:i,direction:[s[0]/a,s[1]/a,s[2]/a]},c=e.geometry?.index??null,u=Math.floor((c?c.count:r.count)/3);if(u>xf)return Io({origin:t,direction:n},...Rf(e))??void 0;let f=p=>[r.getX(p),r.getY(p),r.getZ(p)],d=1/0;for(let p=0;p<u;p++){let m=c?c.getX(p*3):p*3,g=c?c.getX(p*3+1):p*3+1,h=c?c.getX(p*3+2):p*3+2,b=ea(l,f(m),f(g),f(h));b!==null&&b<d&&(d=b)}return d===1/0?void 0:d/a}function Tf(e,t,n){let r=e.geometry?.attributes?.position;if(!r||typeof r.getX!="function"||r.count===0)return;let o=e.matrixWorld.elements,i=Math.max(1,Math.ceil(r.count/3e4)),s=1/0;for(let a=0;a<r.count;a+=i){let l=oe(o,[r.getX(a),r.getY(a),r.getZ(a)]),c=[l[0]-t[0],l[1]-t[1],l[2]-t[2]],u=c[0]*n[0]+c[1]*n[1]+c[2]*n[2];if(u<=0||u>=s)continue;Math.hypot(c[0]-n[0]*u,c[1]-n[1]*u,c[2]-n[2]*u)<u*.015&&(s=u)}return s===1/0?void 0:s}function Rf(e){let{min:t,max:n}=tt(bt(e)??[[0,0,0]]);return[t,n]}function Af(e){xn=[],nt(e,t=>{t.isLight&&xn.length<64&&xn.push(new WeakRef(t))}),An=mr}function Pf(){let e=[];for(let t of xn){let n=t.deref();if(!n||!Ea(n))continue;let r={uuid:n.uuid,type:n.type,name:typeof n.name=="string"?n.name:"",color:Sn(n.color)??"#ffffff",groundColor:Sn(n.groundColor),intensity:N(n.intensity)??1,position:le(n.matrixWorld.elements),angle:N(n.angle),distance:N(n.distance)};n.target?.matrixWorld&&(n.target.parent||n.target.updateMatrixWorld(),r.target=le(n.target.matrixWorld.elements)),e.push(r)}return e}function Cf(){if(!Tn)return null;let e=re(Tn);if(!e)return null;let t=bt(e);if(!t&&!e.isLight&&!e.isCamera&&e.children?.length){let n=[];if(nt(e,r=>{r.isMesh&&n.length<8e3&&n.push(...bt(r)??[])},2e3),n.length){let{min:r,max:o}=tt(n);t=_t(r,o)}}return{uuid:e.uuid,corners:t,parentMatrixWorld:e.parent?e.parent.matrixWorld.elements.slice(0,16):Ys(),position:pt(e.position),quaternion:[e.quaternion.x,e.quaternion.y,e.quaternion.z,e.quaternion.w],scale:pt(e.scale),worldPosition:le(e.matrixWorld.elements)}}function Lf(){if(wn?.isConnected)return wn;let e=document.getElementById(Ye)?.shadowRoot?.getElementById(ys);return wn=e instanceof HTMLCanvasElement?e:null,wn}function $f(e){return It&&It.constructor===e.constructor||(It=new e.constructor),It}function Cn(e){return{matrixWorld:e.matrixWorld.elements.slice(0,16),projectionMatrix:e.projectionMatrix.elements.slice(0,16),projectionMatrixInverse:e.projectionMatrixInverse.elements.slice(0,16),perspective:!!e.isPerspectiveCamera,fov:N(e.fov)??50,mask:e.layers?.mask??1}}function vr(e){return{matrixWorld:e.matrixWorld.elements.slice(0,16),projectionMatrixInverse:e.projectionMatrixInverse.elements.slice(0,16),near:e.near,far:e.far}}function jf(e,t,n,r){let o=e.parent?be(e.parent.matrixWorld.elements):null,i=o?ae(o,t):t,s=le(i),a=Fe(i);e.position.set(s[0],s[1],s[2]),e.quaternion.set(a[0],a[1],a[2],a[3]),e.scale.set(1,1,1),e.near=n.near,e.far=n.far,e.isPerspectiveCamera?(e.fov=n.fov,e.aspect=r):(e.top=n.orthoHalfHeight,e.bottom=-n.orthoHalfHeight,e.right=n.orthoHalfHeight*r,e.left=-n.orthoHalfHeight*r),e.zoom=1,e.updateProjectionMatrix();let l=et(le(t),Fe(t),[1,1,1]),c=be(l);dt(e.matrix,et(s,a,[1,1,1])),dt(e.matrixWorld,l),e.matrixWorldInverse&&c&&dt(e.matrixWorldInverse,c)}function Of(e,t,n){jf(e,et(t.position,t.quaternion,[1,1,1]),t,n)}function dt(e,t){for(let n=0;n<16;n++)e.elements[n]=t[n]}function Pa(e){let t=Lf();if(!t||t.width===0||t.height===0)return;let n=t.getContext("2d");n&&(n.clearRect(0,0,t.width,t.height),n.drawImage(e,0,0,t.width,t.height))}function Ca(e,t,n){let r=e.renderer.domElement;return mr++,mr-An>45&&Af(e.scene),{frame:mr,scene:e.scene.uuid,sceneName:e.scene.name||e.scene.children?.find(o=>o.name)?.name||"Scene",liveScenes:Math.max(Rn.size,1),reach:Wo(e.scene,e.camera),director:{matrixWorld:t.matrixWorld,projectionMatrix:t.projectionMatrix,perspective:t.perspective,fov:t.fov},siteCamera:{uuid:e.camera.uuid,...n},lights:Pf(),selection:Cf(),canvas:{width:r.width,height:r.height}}}function oa(e){let t=_();if(!t)return null;let{renderer:n,camera:r}=t,o=n.domElement;Dt(r);let i=r;e.site||(i=$f(r),i.layers&&r.layers&&(i.layers.mask=r.layers.mask),Of(i,e,o.height>0?o.width/o.height:1));let s=e.site?[]:ja(t.scene);try{Ft(t,i)}finally{for(let a of s)a.frustumCulled=!0}return gt=Cn(i),Pa(o),Ca(t,gt,vr(r))}var _f=[.25,.5,.75],ia=14;function If(e,t){let n=t,r=e.domElement,o=e.getContext?.(),i=Math.floor(n?n.width??0:o?.drawingBufferWidth??r.width),s=Math.floor(n?n.height??0:o?.drawingBufferHeight??r.height);if(i<8||s<8)return null;let a=n?.texture?.type,l=a===1015?new Float32Array(i*4):a===1016?new Uint16Array(i*4):new Uint8Array(i*4),c=[];for(let u of _f){let f=Math.floor(s*u);if(n){if(!e.readRenderTargetPixels)return null;e.readRenderTargetPixels(n,0,f,i,1,l)}else{if(!o)return null;o.readPixels(0,f,i,1,o.RGBA,o.UNSIGNED_BYTE,l)}for(let d=0;d<ia;d++){let p=Math.floor((d+.5)/ia*i)*4;c.push(l[p]+l[p+1]+l[p+2])}}return c}var W={hide:null,queue:[],base:null,changes:new Map,wait:20,signature:""};function sa(e){let t=e.getRenderTarget?.()??null;try{return e.setRenderTarget?.(null),If(e,null)}catch{return null}finally{e.setRenderTarget?.(t)}}function Ff(e,t){let n=0;for(let r=0;r<e.length;r++)n+=Math.abs(e[r]-(t[r]??0));return n/e.length}function Vf(e){let t=e[0]?.renderer;if(W.hide!==null&&t){let o=sa(t);if(o&&W.base&&W.changes.set(W.hide,Ff(o,W.base)),W.hide=W.queue.shift()??null,W.hide===null){let i=null,s=0,a=0;for(let[l,c]of W.changes)c>s?(a=s,s=c,i=l):c>a&&(a=c);T.visibleDebug=[...W.changes].map(([l,c])=>`${l.name||l.children?.[0]?.name}:${c.toFixed(1)}`).join(" "),i&&s>4&&s>a*1.6&&(T.visible={scene:new WeakRef(i),at:de()}),W.changes.clear(),W.base=null}return!0}let r=e.map(o=>o.scene.uuid).join(",");return r!==W.signature&&(W.signature=r,W.wait=Math.min(W.wait,6)),e.length<2||!t||!Vt||--W.wait>0||(W.wait=75,W.base=sa(t),!W.base)||(W.queue=e.slice(0,4).map(o=>o.scene),W.hide=W.queue.shift()??null),!1}function La(){let e=_();return or().map(t=>({uuid:t.scene.uuid,label:t.scene.name||t.scene.children?.find(n=>n.name)?.name||"Scene",objects:t.scene.children?.length??0,current:t.scene===e?.scene}))}function $a(e){if(e===null)return T.manual=null,!0;let t=or().find(n=>n.scene.uuid===e);return t?(T.manual=new WeakRef(t.scene),!0):!1}function Df(){Vo||(Vo=!0,queueMicrotask(Nf))}function Nf(){Vo=!1,fa=de();try{let t=or();Rn=new Map(t.map(i=>[i.scene,i.camera]));let n=Vf(t);T.visible.scene&&Rn.has(T.visible.scene.deref())&&(T.visible.at=Math.max(T.visible.at,de()-2500));let r=To(T.pinned?.scene);r&&r.scene!==T.pinned?.scene?(T.pinned=r,Tn=null,mt=new Map,An=-1e3):r&&(T.pinned=r);let o=_();o&&Vt&&!n&&(Pa(o.renderer.domElement),gt=kn??Cn(o.camera),ha?.(Ca(o,gt,Mn??Ln.get(o.scene)??vr(o.camera))))}catch{}Mn=null,kn=null;let e=En;En=[];for(let t of e)try{t()}catch{}}var Rn=new Map,pr=null,zo=1,aa=new WeakMap;function Wo(e,t,n){let r=aa.get(e),o=de();if(r&&(o-r.at<3e3||!n))return r.reach;let i=[];nt(e,d=>{if(d.visible===!1)return!1;if(!d.isMesh||i.length>=400)return;let p=bt(d);p&&i.push(tt(p))},4e3);let s=n??t.matrixWorld.elements,a=le(s),l=ur(fr(s,[0,0,-1])),c={center:a,radius:0},u=No(i,a,l,c,.8,.25);u===c&&(u=No(i,a,l,c));let f=Ze(Wf(u.center,a));return f>.001||(f=Ze(a)),f=Math.max(f,(t.near||.1)*50,.001),aa.set(e,{at:o,reach:f}),f}var Ln=new WeakMap;function zf(e,t){try{t.parent?t.updateWorldMatrix?.(!0,!1):t.updateMatrixWorld()}catch{}let n=vr(t);return Ln.set(e,n),n}var Wf=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Bf=["set","identity","copy","copyPosition","setFromMatrix3","makeBasis","extractRotation","makeRotationFromEuler","makeRotationFromQuaternion","lookAt","multiply","premultiply","multiplyMatrices","multiplyScalar","transpose","setPosition","invert","scale","makeTranslation","makeRotationX","makeRotationY","makeRotationZ","makeRotationAxis","makeScale","makeShear","compose","makePerspective","makeOrthographic","fromArray"],la=new WeakMap;function dr(e){let t=e.clone?e.clone():{elements:e.elements.slice()},n=t;for(let r of Bf)typeof n[r]=="function"&&(n[r]=()=>t);return t}function Hf(e){let t=la.get(e);if(!t){if(!e.matrixWorldInverse)return null;t={matrixWorld:dr(e.matrixWorld),matrixWorldInverse:dr(e.matrixWorldInverse),projectionMatrix:dr(e.projectionMatrix),projectionMatrixInverse:dr(e.projectionMatrixInverse)},la.set(e,t)}return t}var ca=new WeakMap;function ja(e){let t=de(),n=ca.get(e);if(!n||t-n.at>1e3){let r=[];nt(e,o=>{o.frustumCulled===!0&&(o.isMesh||o.isPoints||o.isLine||o.isSprite)&&r.push(o)}),n={at:t,list:r},ca.set(e,n)}for(let r of n.list)r.frustumCulled=!1;return n.list}function ua(e,t,n,r,o,i,s,a){let l=Hf(o),c=et(le(i),Fe(i),[1,1,1]),u=be(c);if(!l||!u)return t.call(n,r,o);let f=e.domElement,d=f.height>0?f.width/f.height:1,p=s.orthoHalfHeight,m=o.isPerspectiveCamera?Qs(s.fov,d,s.near,s.far):Zs(-p*d,p*d,p,-p,s.near,s.far);dt(l.matrixWorld,o.matrixWorld.elements),dt(l.matrixWorldInverse,u),dt(l.projectionMatrix,m),dt(l.projectionMatrixInverse,be(m)??m);let g={matrixWorld:o.matrixWorld,matrixWorldInverse:o.matrixWorldInverse,projectionMatrix:o.projectionMatrix,projectionMatrixInverse:o.projectionMatrixInverse},h=o.layers?.mask,b=[];try{return b=ja(r),Object.assign(o,l),a&&o.layers&&(o.layers.mask=0),o===T.pinned?.camera&&(kn={matrixWorld:c,projectionMatrix:m,projectionMatrixInverse:l.projectionMatrixInverse.elements.slice(0,16),perspective:!!o.isPerspectiveCamera,fov:s.fov,mask:h??1}),t.call(n,r,o)}finally{for(let y of b)y.frustumCulled=!0;Object.assign(o,g),o.layers&&h!==void 0&&(o.layers.mask=h);try{o.updateProjectionMatrix(),o.parent?o.updateWorldMatrix?.(!0,!1):o.updateMatrixWorld(!0)}catch{}}}T.liveRender=(e,t,n,r,o)=>{Df();let i=T.pinned,s=Vt,a=!!i&&o===i.camera,l=!a&&Rn.get(r)===o,c=W.hide===r;if(!i||!s||!a&&!l){if(!c||!o.layers)return t.call(n,r,o);let g=o.layers.mask;try{return o.layers.mask=0,t.call(n,r,o)}finally{o.layers.mask=g}}let u=zf(r,o);if(a&&(Mn=u),s.site){let g=o.layers?.mask;try{return c&&o.layers&&(o.layers.mask=0),t.call(n,r,o)}finally{o.layers&&g!==void 0&&(o.layers.mask=g),a&&(kn={...Cn(o),matrixWorld:u.matrixWorld})}}let f=u.matrixWorld;if(a){let g=et(s.position,s.quaternion,[1,1,1]),h=be(f);return h&&(pr=ae(h,g),zo=Wo(r,o,f)),ua(e,t,n,r,o,g,s,c)}if(!pr)return t.call(n,r,o);let d=Wo(r,o,f)/zo,p=pr.slice(0,16);p[12]=p[12]*d,p[13]=p[13]*d,p[14]=p[14]*d;let m=Math.hypot(p[12],p[13],p[14]);return ua(e,t,n,r,o,ae(f,p),{fov:s.fov,near:Math.max(Math.min(o.near,m/500),1e-4)||o.near,far:Math.max(o.far,m*10+o.far),orthoHalfHeight:s.orthoHalfHeight*d},c)};function Oa(e){ha=e}function Uo(e){T.live=e&&T.paused,e||(Vt=null)}function qo(e,t){if(!T.paused)return Promise.resolve(!0);let n=T.live;return T.live=!0,new Promise(r=>{let o=0,i=l=>{clearTimeout(s),T.live=n,r(l)},s=setTimeout(()=>i(!1),t),a=()=>{++o>=e?i(!0):En.push(a)};En.push(a)})}function _a(e,t){if(!t||!T.paused)return Uo(!1),oa(e);let n=de();return T.live||(ta=n),T.live=!0,Vt=e,n-fa>300&&n-ta>300?oa(e):null}function Ia(e){typeof e.updateWorldMatrix=="function"?e.updateWorldMatrix(!0,!1):e.updateMatrixWorld();let t=e.matrixWorld.elements;return{position:le(t),quaternion:Fe(t),fov:N(e.fov)??50}}function Fa(){let e=_();if(!e)return null;let t=T.live?Ln.get(e.scene):void 0;return t?{position:le(t.matrixWorld),quaternion:Fe(t.matrixWorld),fov:N(e.camera.fov)??50,scene:e.scene.uuid}:{...Ia(e.camera),scene:e.scene.uuid}}function Va(e){let t=Lt(),n=t?.timeline,r=_();if(!t||!n||!r||typeof t.advance!="function")return null;let o=Math.min(Math.max(Math.floor(e),2),400),i=n.getProgress(),s=[];try{for(let a=0;a<=o;a++){let l=a/o;n.setProgress(l),t.advance(),s.push({percent:l*100,...Ia(r.camera),section:n.getSection?.(l)??null})}}finally{n.setProgress(i),t.advance()}return s}var qf=(e,t)=>.2126*e[t]+.7152*e[t+1]+.0722*e[t+2];function Ko(e,t){let n=Math.max(1,Math.floor(e/t)),r=[];for(let o=Math.floor(n/2);o<e;o+=n)r.push(o);return r}function Gf(e,t,n){let r=1;for(let o of[2,3,4]){let i=0;for(let s of[!0,!1]){let a=new Float64Array(o),l=new Float64Array(o),c=s?t:n,u=s?n:t;for(let p of Ko(u,300))for(let m=0;m<c-1;m++){let g=s?p*t+m:m*t+p,h=s?g+1:g+t;a[m%o]+=Math.abs(e[g]-e[h]),l[m%o]++}let f=0,d=0;for(let p=0;p<o;p++){let m=a[p]/Math.max(1,l[p]);m>f?(d+=f,f=m):d+=m}f>.6&&d/(o-1)<f*.04&&i++}i===2&&(r=o)}return r}function Da(e,t,n,r,o){let s=r?t:n,a=r?n:t,l=(c,u)=>r?e[c*t+u]:e[u*t+c];for(let c of Ko(a,240)){let u=0;for(;u<s-1;){let f=l(c,u+1)-l(c,u);if(Math.abs(f)<2){u++;continue}let d=Math.sign(f),p=0,m=0,g=u;for(;g<s-1;){let h=(l(c,g+1)-l(c,g))*d;if(h<2)break;p+=h,h>m&&(m=h),g++}if(p>=48&&g-u<=24){let h=p/m;o.widths.push(h),h<=1.08&&o.hard++}u=Math.max(g,u+1)}}}function Kf(e,t,n){let r=0,o=0;for(let i of[!0,!1]){let s=i?t:n,a=i?n:t;for(let l of Ko(a,160)){let c=p=>e[(i?l*t+p:p*t+l)*4+1];o+=s;let u=0,f=0,d=0;for(let p=1;p<=s;p++){if(!(p===s||c(p)!==c(p-1)))continue;let g=p-d,h=p<s?Math.abs(c(p)-c(p-1)):0;g>=6&&(u++,f+=g),(g<6||h!==1)&&(u>=3&&(r+=f),u=0,f=0),d=p}}}return o?r/o:0}function Na(e,t,n){let r=t*n,o=new Float32Array(r),i=0,s=0,a=0,l=0;for(let h=0;h<r;h++){let b=h*4,y=qf(e,b);o[h]=y,i+=y,s+=y*y,e[b]>=254&&e[b+1]>=254&&e[b+2]>=254?a++:e[b]<=1&&e[b+1]<=1&&e[b+2]<=1&&l++}let c=r?i/r:0,f=Math.sqrt(Math.max(0,(r?s/r:0)-c*c))<.75,d={widths:[],hard:0};f||(Da(o,t,n,!0,d),Da(o,t,n,!1,d));let p=d.widths.length>=40,m=null;if(p){let h=d.widths.slice().sort((b,y)=>b-y);m=Math.round(h[Math.floor(h.length*.25)]*100)/100}let g=h=>Math.round(h/Math.max(1,r)*1e4)/1e4;return{width:t,height:n,blank:f,blockSize:f?1:Gf(o,t,n),sharpEdgeWidth:m,hardEdgeShare:p?Math.round(d.hard/d.widths.length*100)/100:null,edges:d.widths.length,bandShare:f?0:Math.round(Kf(e,t,n)*1e4)/1e4,whiteShare:g(a),blackShare:g(l)}}var Go=e=>`${Math.round(e*100)}%`;function za(e,t){let n=[];return e.blank?(n.push({id:"blank-frame",severity:"high",area:"renderer",title:"The canvas is one flat colour",evidence:`${e.width} \xD7 ${e.height} pixels, no variation`,cause:"Nothing is reaching the screen: the scene is empty or outside the camera, a shader failed, the render loop stopped, or the context was lost.",fix:"Check get_errors first (shader compile failures, exceptions), then describe_scene for the camera and what is in front of it.",tryLive:"get_errors"}),n):(e.blockSize>1?n.push({id:"pixel-blocks",severity:"high",area:"resolution",title:`The picture is made of ${e.blockSize} \xD7 ${e.blockSize} pixel blocks`,evidence:`neighbouring pixels only change every ${e.blockSize} pixels, across and down`,cause:`Something is drawn at 1/${e.blockSize} of the canvas resolution and enlarged with nearest-neighbour sampling: a low-resolution render target read with NearestFilter, or a pixelation pass.`,fix:"Size the render target to the drawing buffer (renderer.getDrawingBufferSize), or give its texture LinearFilter. If the blocks are a style, ignore this."}):e.sharpEdgeWidth!==null&&e.sharpEdgeWidth>=2&&n.push({id:"soft-picture",severity:e.sharpEdgeWidth>=3?"high":"medium",area:"resolution",title:`Even the sharpest edges are ${e.sharpEdgeWidth} pixels wide`,evidence:`sharpest quarter of ${e.edges} strong edges; a full-resolution render gives 1 to 1.6`,cause:`The scene reaches the screen at roughly 1/${Math.round(e.sharpEdgeWidth)} of the canvas resolution and is stretched: a render target or effect pass smaller than the canvas, or a pixel ratio below the screen's. A deliberate blur (depth of field, heavy bloom) reads the same.`,fix:"Find the small pass with get_performance (passesOfOneFrame lists every render target with its size) and size it to the drawing buffer. Check the canvas issues in this report.",tryLive:"set_viewport { pixelRatio: 2 }, then audit_visuals again"}),e.hardEdgeShare!==null&&e.hardEdgeShare>=.7&&e.blockSize===1&&(e.sharpEdgeWidth??9)<1.2&&n.push({id:"jagged-edges",severity:t.antialiased?"low":"medium",area:"edges",title:`${Go(e.hardEdgeShare)} of strong edges jump in a single pixel`,evidence:`${e.edges} strong edges measured; anti-aliased edges have an in-between pixel`,cause:t.antialiased?"Anti-aliasing is switched on but is not reaching these edges: with post-processing the scene is drawn into a render target, and the canvas's own multisampling does nothing there. Edges inside textures and alpha-tested cut-outs are not covered by multisampling either.":"No anti-aliasing: silhouettes are stair-stepped, and the steps crawl when anything moves.",fix:"Without post-processing: new WebGLRenderer({ antialias: true }). With it: samples: 4 on the composer's render target (pmndrs EffectComposer multisampling={4}), or an SMAA pass last. Cut-outs: alphaToCoverage.",tryLive:"set_look { effects: { antialias: true } } (needs the dev bridge)"}),e.bandShare>=.08&&n.push({id:"banding",severity:e.bandShare>=.2?"medium":"low",area:"colour",title:`${Go(e.bandShare)} of the picture is stepped gradient`,evidence:"flat bands one colour level apart, at least three in a row",cause:"A smooth gradient (sky, fog, vignette, soft light on a wall) has fewer than 256 levels to use and no noise to hide the steps. Dark gradients show it most.",fix:"Add about one level of noise before the output: material.dithering = true on the lit materials, a dither or film-grain step last in the post-processing chain, or in a shader `color += (hash(gl_FragCoord.xy) - 0.5) / 255.0`. Keep intermediate render targets HalfFloatType.",tryLive:"set_look { effects: { grain: 0.06 } } (needs the dev bridge)"}),e.whiteShare>=.03&&n.push({id:"clipped-highlights",severity:e.whiteShare>=.1?"medium":"low",area:"colour",title:`${Go(e.whiteShare)} of the picture is pure white`,evidence:"all three channels at 254 or more",cause:"Highlights are brighter than the output can show and clip to flat white, losing their shape.",fix:"Tone map (AgX or ACES Filmic) and lower the exposure or the light that causes it. A white page background counts too: ignore this if that is what it is.",tryLive:'set_look { color: { toneMapping: "agx" } }'}),n)}var ne=e=>e!==null&&typeof e=="object"?e:null,xr=e=>Array.isArray(e.material)?e.material:e.material?[e.material]:[],B=(e,t=3)=>{let n=10**t;return Math.round(e*n)/n};function In(e,t,n=2e4){let r=[e],o=0;for(;r.length&&o<n;){let i=r.pop();if(o++,t(i),Array.isArray(i.children))for(let s=i.children.length-1;s>=0;s--)r.push(i.children[s])}}var Xf=60,yt=[],vt=null;function jn(e,t){try{let n=t.map(o=>o instanceof Error?`${o.name}: ${o.message}`:typeof o=="string"?o:Jf(o)).join(" ").slice(0,2e3);if(!n)return;let r=yt[yt.length-1];if(r&&r.kind===e&&r.message===n){r.count++;return}yt.push({kind:e,message:n,count:1,at:Math.round(de())}),yt.length>Xf&&yt.shift()}catch{}}function Jf(e){try{return typeof e=="object"?JSON.stringify(e).slice(0,400):String(e)}catch{return Object.prototype.toString.call(e)}}function Ua(){window.addEventListener("error",e=>{e.message&&jn("exception",[`${e.message} (${e.filename}:${e.lineno})`])}),window.addEventListener("unhandledrejection",e=>jn("rejection",[e.reason]))}function Xo(){if(vt)return;vt={error:console.error,warn:console.warn};let{error:e,warn:t}=vt;console.error=function(...n){jn("error",n),e.apply(this,n)},console.warn=function(...n){jn("warning",n),t.apply(this,n)}}function Yf(){let e=[],t=_(),n=ne(t?.renderer.info)?.programs;if(!Array.isArray(n))return e;for(let r of n){let o=r?.diagnostics;!o||o.runnable!==!1||e.push([`Shader program "${String(r.name??r.type??"unnamed")}" failed.`,o.vertexShader?.log&&`vertex: ${o.vertexShader.log}`,o.fragmentShader?.log&&`fragment: ${o.fragmentShader.log}`,o.programLog&&`link: ${o.programLog}`].filter(Boolean).join(`
|
|
4
|
+
`).slice(0,2e3))}return e}function qa(e){let t={errors:yt.map(n=>({...n})),shaderPrograms:Yf()};return e&&(yt.length=0),t}var Ce=new Map,Qf=e=>new Promise(t=>setTimeout(t,e));function Jo(e,t){let n=[];try{let r=ne(ne(e)?.properties),o=r?.get,i=ne(ne(o?.call(r,t))?.currentProgram),s=e.getContext?.();if(!i||!s)return n;for(let c of["vertexShader","fragmentShader"]){let u=i[c];if(u&&!s.getShaderParameter(u,s.COMPILE_STATUS)){let f=s.getShaderInfoLog(u);f&&n.push(`${c==="vertexShader"?"vertex":"fragment"}: ${f.trim()}`)}}let a=i.program;if(a&&!s.getProgramParameter(a,s.LINK_STATUS)){let c=s.getProgramInfoLog(a);c&&!n.length&&n.push(`link: ${c.trim()}`)}let l=i.diagnostics;!n.length&&l?.runnable===!1&&n.push(l.fragmentShader?.log||l.vertexShader?.log||l.programLog||"Program failed.")}catch{}return n}async function Ga(e,t,n){let r=_(),o=re(e),i=o?xr(o)[0]:void 0;if(!r||!o||!i)throw new Error("That object has no material.");if(typeof i.vertexShader!="string"||typeof i.fragmentShader!="string")throw new Error(`${i.type??"This material"} is a built-in material: its shader is generated by three.js and cannot be replaced here. Only ShaderMaterial and RawShaderMaterial can.`);if(t===null&&n===null)throw new Error("Give a vertex or a fragment shader.");let s={vertex:i.vertexShader,fragment:i.fragmentShader};Ce.has(i)||Ce.set(i,s),i.vertexShader=t??s.vertex,i.fragmentShader=n??s.fragment,i.needsUpdate=!0;let a=[];for(let l=0;l<6&&(await Qf(120),a=Jo(r.renderer,i),!a.length);l++);return a.length?(i.vertexShader=s.vertex,i.fragmentShader=s.fragment,i.needsUpdate=!0,Ce.get(i)?.vertex===s.vertex&&Ce.get(i)?.fragment===s.fragment&&Ce.delete(i),{applied:!1,errors:a}):{applied:!0,errors:[]}}function Zf(){let e=[],t=_();return!t||Ce.size===0||In(t.scene,n=>{let r=xr(n)[0],o=r&&Ce.get(r);if(!r||!o)return;let i=[r.vertexShader!==o.vertex&&"vertex",r.fragmentShader!==o.fragment&&"fragment"].filter(Boolean);i.length&&e.push({kind:"shader",uuid:n.uuid,name:n.name||"",type:r.type??"ShaderMaterial",detail:`${i.join(" and ")} shader replaced`})}),e}function eh(){for(let[e,t]of Ce)e.vertexShader=t.vertex,e.fragmentShader=t.fragment,e.needsUpdate=!0;Ce.clear()}var $n=e=>{let t=ne(e);return typeof t?.getHexString=="function"?`#${t.getHexString.call(t)}`:""};function th(e,t){if(!e)return{min:[...t],max:[...t]};for(let n=0;n<3;n++)e.min[n]=Math.min(e.min[n],t[n]),e.max[n]=Math.max(e.max[n],t[n]);return e}function nh(e){let t=e.geometry;if(!t)return[];try{!t.boundingBox&&typeof t.computeBoundingBox=="function"&&t.computeBoundingBox()}catch{}let n=t.boundingBox;return!n||!Number.isFinite(n.min.x)||!Number.isFinite(n.max.x)?[]:_t([n.min.x,n.min.y,n.min.z],[n.max.x,n.max.y,n.max.z]).map(r=>oe(e.matrixWorld.elements,r))}function Sr(){let e=_();if(!e)return null;let t=ne(ne(e.renderer)?.shadowMap),n=!!t?.enabled,r=[],o=[],i=0;In(e.scene,f=>{f.isLight?r.push(f):f.isMesh&&f.visible!==!1&&(f.castShadow&&o.push(f),f.receiveShadow&&i++)});let s=[],a=[],l=0,c=0;for(let f of r){let d=ne(f.shadow),p=ne(d?.mapSize),m=d?.camera,g=f.name||f.type,h={uuid:f.uuid,name:f.name||"",type:f.type,visible:f.visible!==!1,color:$n(f.color),intensity:B(Number(f.intensity??0)),castShadow:!!f.castShadow};if(f.castShadow&&d&&p){let b=Number(p.x)||0,y=Number(p.y)||0,v=f.type==="PointLight"?6:1;l+=b*y*v,c+=v,h.shadow={mapSize:[b,y],bias:B(Number(d.bias??0),6),normalBias:B(Number(d.normalBias??0),6),radius:B(Number(d.radius??1)),passes:v},n?o.length===0?s.push(`"${g}" casts shadows, but no visible mesh has castShadow.`):i===0&&s.push(`"${g}" casts shadows, but no visible mesh has receiveShadow.`):s.push(`"${g}" has castShadow, but renderer.shadowMap.enabled is false: no shadow is drawn.`),Math.max(b,y)>2048&&s.push(`"${g}" has a ${b} \xD7 ${y} shadow map${v>1?" on each of 6 faces":""}: costly. 1024 or 2048 is usually enough once the shadow camera fits the scene.`),f.type==="PointLight"&&s.push(`"${g}" is a point light with shadows: the scene is drawn 6 more times for it every frame.`);let x=m?.matrixWorldInverse?.elements;if(m?.isOrthographicCamera&&x&&n&&o.length){let M=Number(m.left),S=Number(m.right),k=Number(m.top),E=Number(m.bottom),L=null;for(let O of o)for(let P of nh(O))L=th(L,oe(x,P));let A=S-M,C=k-E;if(L&&A>0&&C>0){let O=L,P=O.max[0]-O.min[0],j=O.max[1]-O.min[1],I=O.min[0]<M-.001||O.max[0]>S+.001||O.min[1]<E-.001||O.max[1]>k+.001||-O.max[2]<m.near-.001||-O.min[2]>m.far+.001,te=Math.min(1,P*j/(A*C));h.shadow.frustum={width:B(A),height:B(C),near:B(m.near),far:B(m.far),castersWidth:B(P),castersHeight:B(j),used:B(te,2),castersOutside:I,worldUnitsPerTexel:B(A/Math.max(1,b),4)},I?s.push(`"${g}": some shadow casters are outside its shadow camera (${B(A)} \xD7 ${B(C)}, near ${B(m.near)}, far ${B(m.far)}), so their shadows are cut off. The casters need ${B(P)} \xD7 ${B(j)}.`):te<.25&&s.push(`"${g}": the shadow camera covers ${B(A)} \xD7 ${B(C)}, but the casters need only ${B(P)} \xD7 ${B(j)} (${Math.round(te*100)}% of the map is used). Shrink left/right/top/bottom for sharper shadows from the same map.`)}}}else f.castShadow===!1&&n&&o.length&&f.type;a.push(h)}let u=r.filter(f=>f.visible!==!1&&f.type!=="AmbientLight").length;return u>8&&s.push(`${u} lights are on. Every lit material computes all of them per pixel: bake or remove some.`),n&&c===0&&o.length&&s.push("renderer.shadowMap.enabled is true and meshes have castShadow, but no light casts shadows."),{shadowMapEnabled:n,shadowMapType:Number(t?.type??-1),lights:a,castingMeshes:o.length,receivingMeshes:i,shadowPassesPerFrame:n?c:0,shadowMapBytes:n?l*4:0,issues:s}}var On=null;function Ka(e){let t={position:[e.position.x,e.position.y,e.position.z],rotation:[e.rotation.x,e.rotation.y,e.rotation.z],scale:[e.scale.x,e.scale.y,e.scale.z],visible:e.visible!==!1};e.isLight&&(typeof e.intensity=="number"&&(t.intensity=e.intensity),e.color&&(t.color=$n(e.color)));let n=e;e.isCamera&&(typeof n.fov=="number"&&(t.fov=n.fov),typeof n.zoom=="number"&&(t.zoom=n.zoom));let r=xr(e)[0];if(r){typeof r.opacity=="number"&&(t["material.opacity"]=r.opacity),r.color&&(t["material.color"]=$n(r.color)),r.emissive&&(t["material.emissive"]=$n(r.emissive)),typeof r.emissiveIntensity=="number"&&(t["material.emissiveIntensity"]=r.emissiveIntensity);for(let[o,i]of Object.entries(r.uniforms??{}).slice(0,60)){let s=i?.value,a=ne(s);typeof s=="number"||typeof s=="boolean"?t[`uniform.${o}`]=s:a?.isColor?t[`uniform.${o}`]=$n(s):a?.isVector3?t[`uniform.${o}`]=[Number(a.x),Number(a.y),Number(a.z)]:a?.isVector2&&(t[`uniform.${o}`]=`${B(Number(a.x),4)},${B(Number(a.y),4)}`)}}return t}function rh(){let e=new Map,t=_();if(!t)return e;let n=r=>{e.set(r.uuid,{o:new WeakRef(r),values:Ka(r)})};return n(t.camera),In(t.scene,n,4e3),e}var oh=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.some((n,r)=>Math.abs(n-(t[r]??0))>1e-5):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)>1e-5:e!==t,Wa=e=>Array.isArray(e)?e.map(t=>B(t)):typeof e=="number"?B(e):e;function Xa(){return On=rh(),On.size}function Ja(){let e=[];if(!On)return e;for(let[t,n]of On){let r=n.o.deref();if(!r)continue;let o=Ka(r),i=[];for(let s of Object.keys(n.values)){let a=n.values[s],l=o[s];l!==void 0&&oh(a,l)&&i.push({path:s,from:Wa(a),to:Wa(l)})}i.length&&e.push({uuid:t,name:r.name||"",type:r.type,changes:i})}return e.slice(0,200)}function Ya(){let e=_(),t=[],n=0;if(e){In(e.scene,o=>{let i=o.animations;if(Array.isArray(i))for(let s of i)t.length<40&&t.push({object:o.name||o.type,clip:String(s?.name??""),duration:B(Number(s?.duration??0))})});try{let o=ne(ne(e.scene.__r3f)?.root),i=o?.getState,s=ne(ne(i?.call(o))?.internal)?.subscribers;Array.isArray(s)&&(n=s.length)}catch{}}let r=null;try{let o=ne(window.gsap),i=ne(o?.globalTimeline),s=i?.getChildren;s&&(r=s.call(i,!0,!0,!0).length)}catch{}return{clips:t,useFrameCallbacks:n,gsapTweens:r,timeHeld:F.held}}var De=new Set,_n=[],Ba=e=>e?Object.getPrototypeOf(e):null;function Qa(e,t){let n=null;for(let o=Ba(e);o&&o!==Object.prototype;o=Ba(o))Object.prototype.hasOwnProperty.call(o,t)&&(n=o);let r=n&&n.constructor;return typeof r=="function"?r:null}function wr(e){let t=_(),n=new Set(t?[t.scene,..._e()]:_e());for(let r of n)In(r,e,8e3)}function Ha(e){let t=null;return wr(n=>{!t&&n.type===e&&!De.has(n)&&(t=n)}),t}var Za=["box","sphere","plane"];function ih(e){let t=[],n=[],r=(o,i,s,a)=>{let l=t.length/3;t.push(...o,...i,...s,...a),n.push(l,l+1,l+2,l,l+2,l+3)};if(e==="plane")r([-.5,-.5,0],[.5,-.5,0],[.5,.5,0],[-.5,.5,0]);else if(e==="box")r([-.5,-.5,.5],[.5,-.5,.5],[.5,.5,.5],[-.5,.5,.5]),r([.5,-.5,-.5],[-.5,-.5,-.5],[-.5,.5,-.5],[.5,.5,-.5]),r([.5,-.5,.5],[.5,-.5,-.5],[.5,.5,-.5],[.5,.5,.5]),r([-.5,-.5,-.5],[-.5,-.5,.5],[-.5,.5,.5],[-.5,.5,-.5]),r([-.5,.5,.5],[.5,.5,.5],[.5,.5,-.5],[-.5,.5,-.5]),r([-.5,-.5,-.5],[.5,-.5,-.5],[.5,-.5,.5],[-.5,-.5,.5]);else{for(let s=0;s<=16;s++){let a=s/16*Math.PI;for(let l=0;l<=24;l++){let c=l/24*Math.PI*2;t.push(-.5*Math.cos(c)*Math.sin(a),.5*Math.cos(a),.5*Math.sin(c)*Math.sin(a))}}for(let s=0;s<16;s++)for(let a=0;a<24;a++){let l=s*25+a,c=l+24+1;s!==0&&n.push(l,l+1,c),s!==15&&n.push(l+1,c+1,c)}}return{positions:t,indices:n}}function sh(e,t){let n=null,r=null,o=null,i=null;wr(b=>{if(!b.isMesh||!b.geometry?.attributes?.position||De.has(b))return;let y=b.geometry.attributes.position;!n&&!y.isInterleavedBufferAttribute&&(n=b),!r&&b.type==="Mesh"&&(r=b);let v=xr(b)[0];v&&/^Mesh(Standard|Physical|Lambert|Phong|Basic|Toon)Material$/.test(v.type??"")&&(i??=v,!o&&/Standard|Physical|Lambert|Phong/.test(v.type??"")&&(o=v))});let s=n,a=o??i;if(!s||!a)throw new Error("This scene has no ordinary mesh to take the three.js classes from, so a mesh cannot be made here. Add it in the source instead.");let l=Qa(s.geometry,"setAttribute"),c=s.geometry.attributes.position.constructor,u=(r??s).constructor,f=a.constructor;if(!l)throw new Error("Could not find the geometry class of this site.");let d=ih(e),p=new Float32Array(d.indices.length*3);d.indices.forEach((b,y)=>{p[y*3]=d.positions[b*3],p[y*3+1]=d.positions[b*3+1],p[y*3+2]=d.positions[b*3+2]});let m=new l,g=new c(p,3);if(!(g.array instanceof Float32Array)||g.count!==p.length/3)throw new Error("Could not build geometry with the classes of this site.");m.setAttribute.call(m,"position",g),m.computeVertexNormals?.call(m);let h=new f;return t&&h.color&&h.color.set(t),new u(m,h)}function Yo(){let e=new Set;wr(n=>{n.isLight&&e.add(n.type)});let t=!1;return wr(n=>{n.isMesh&&n.geometry?.attributes?.position&&(t=!0)}),[...e,"Group",...t?Za:[]]}function el(e){let t=_();if(!t)throw new Error("No active three.js scene.");let n=e.parent?re(e.parent):t.scene;if(!n)throw new Error(`No object with id ${e.parent} to add to.`);let r;if(e.copyOf){let o=re(e.copyOf);if(!o||o===t.scene)throw new Error("No such object to copy.");r=o.clone(!0),r.name=e.name??`${o.name||o.type} copy`}else if(Za.includes(e.kind))r=sh(e.kind,e.color??null),r.name=e.name??`New ${e.kind}`;else if(e.kind==="Group"){let o=Qa(t.scene,"traverseAncestors"),i=Ha("Group"),s=i?i.constructor:o;if(!s)throw new Error("Could not find the Object3D class of this site.");r=new s,r.name=e.name??"New group"}else{let o=Ha(e.kind);if(!o?.isLight)throw new Error(`This page has no ${e.kind} to take the class from. Available here: ${Yo().join(", ")}. Anything else must be added in the source.`);r=new o.constructor,r.name=e.name??`New ${e.kind}`,e.color&&r.color&&r.color.set(e.color),r.intensity=e.intensity??o.intensity??1}return e.position&&r.position.set(...e.position),n.add(r),r.updateMatrixWorld(!0),De.add(r),r.uuid}function tl(e){let t=_(),n=re(e);if(!t||!n)throw new Error(`No object with id ${e} in the scene.`);if(n===t.scene||n===t.camera)throw new Error("The scene itself and the site camera cannot be removed.");let r=n.parent;if(!r)throw new Error("That object is not in the scene.");let o=r.children.indexOf(n);return r.remove(n),De.has(n)?De.delete(n):_n.push({object:n,parent:r,index:o}),!0}function ah(){let e=[];for(let t of De)t.parent&&e.push({kind:"added",uuid:t.uuid,name:t.name||"",type:t.type,detail:""});for(let t of _n)e.push({kind:"removed",uuid:t.object.uuid,name:t.object.name||"",type:t.object.type,detail:`was a child of ${t.parent.name||t.parent.type}`,source:lh(t.object)});return[...e,...Zf()]}function lh(e){for(let t of Object.values(e.userData??{})){let n=ne(t);if(n&&typeof n.file=="string"&&typeof n.line=="number")return{file:n.file,line:n.line,component:String(n.component??"")}}}var nl=()=>ah();function ch(){for(let e of De)try{e.parent?.remove(e)}catch{}De.clear();for(let e of _n.reverse())try{e.parent.add(e.object);let t=e.parent.children.indexOf(e.object);t>=0&&e.index<e.parent.children.length&&(e.parent.children.splice(t,1),e.parent.children.splice(e.index,0,e.object))}catch{}_n.length=0}var F={held:!1,virtual:0,offset:0,queue:new Map,nextId:1e9,patched:!1};function uh(){if(F.patched)return;F.patched=!0,K.now=performance.now,K.raf=window.requestAnimationFrame,K.caf=window.cancelAnimationFrame;let{now:e,raf:t,caf:n}=K;performance.now=function(){return F.held?F.virtual:e.call(performance)-F.offset},window.requestAnimationFrame=function(r){if(F.held){let o=F.nextId++;return F.queue.set(o,r),o}return t.call(window,o=>r(o-F.offset))},window.cancelAnimationFrame=function(r){F.queue.delete(r)||n.call(window,r)}}function fh(){if(!F.patched)return;let e=[...F.queue.values()];F.queue.clear(),F.held=!1,K.now&&(performance.now=K.now),K.raf&&(window.requestAnimationFrame=K.raf),K.caf&&(window.cancelAnimationFrame=K.caf);let t=K.raf;K.now=K.raf=K.caf=null,F.patched=!1,F.offset=0;for(let n of e)t?.call(window,n)}var hh=()=>({held:F.held,pageTimeMs:B(F.held?F.virtual:de()-F.offset,1),waitingFrames:F.queue.size});function rl(e,t,n){if(e==="pause")F.held||(uh(),F.virtual=de()-F.offset,F.held=!0);else if(e==="step"){if(!F.held)throw new Error('Hold the time first: set_time with action "pause".');for(let r=0;r<Math.max(1,Math.min(600,t));r++){F.virtual+=n;let o=[...F.queue.values()];F.queue.clear();for(let i of o)try{i(F.virtual)}catch(s){jn("exception",[s])}}}else if(e==="resume"){if(F.held&&K.now&&K.raf){F.offset=K.now.call(performance)-F.virtual,F.held=!1;let r=[...F.queue.values()];F.queue.clear();for(let o of r)K.raf.call(window,i=>o(i-F.offset))}}else throw new Error(`Unknown action: ${e}`);return hh()}var Nt=new Map;function ol(e){let t=_();if(!t)throw new Error("No active three.js scene.");let n=t.renderer,r=n.getPixelRatio?.()??1;if(typeof n.setPixelRatio!="function")throw new Error("This renderer has no setPixelRatio.");if(e===null){let o=Nt.get(n);o!==void 0&&n.setPixelRatio(o),Nt.delete(n)}else Nt.has(n)||Nt.set(n,r),n.setPixelRatio(Math.min(4,Math.max(.25,e)));return{pixelRatio:n.getPixelRatio?.()??1,was:r}}function il(){ch(),eh()}function sl(){fh(),vt&&(console.error=vt.error,console.warn=vt.warn,vt=null);for(let[e,t]of Nt)try{e.setPixelRatio?.(t)}catch{}Nt.clear(),On=null,De.clear(),_n.length=0,Ce.clear()}var Mr=e=>e!==null&&typeof e=="object"?e:null,Zo=e=>Array.isArray(e.material)?e.material:e.material?[e.material]:[],Le=e=>Math.round(e*100)/100,zt=e=>e.name||e.type,Fn=e=>({uuid:e.uuid,name:zt(e)});function mh(e,t){let n=[],r=[e],o=0;for(;r.length&&o<2e4&&n.length<t;){let i=r.pop();if(o++,i.visible!==!1){(i.isMesh||i.isPoints||i.isSprite)&&i.material&&n.push(i);for(let s of i.children??[])r.push(s)}}return n}function ph(e,t,n,r){let o=1/0,i=-1/0,s=1/0,a=-1/0;for(let f=0;f<8;f++){let d=[f&1?t.max[0]:t.min[0],f&2?t.max[1]:t.min[1],f&4?t.max[2]:t.min[2]],p=e;if(p[3]*d[0]+p[7]*d[1]+p[11]*d[2]+p[15]<=0)return null;let g=oe(e,d);o=Math.min(o,g[0]),i=Math.max(i,g[0]),s=Math.min(s,g[1]),a=Math.max(a,g[1])}let l=f=>Math.max(-1,Math.min(1,f)),c=(l(i)-l(o))/2*n,u=(l(a)-l(s))/2*r;return c>0&&u>0?[c,u]:null}var gh=new Set(["map","emissiveMap","sheenColorMap","specularColorMap","matcap"]),Qo=new Set(["normalMap","roughnessMap","metalnessMap","aoMap","bumpMap","displacementMap","clearcoatNormalMap","clearcoatRoughnessMap","transmissionMap","thicknessMap"]),al=1003,bh=1006;function ll(e){return typeof e.colorSpace=="string"?e.colorSpace==="srgb"||e.colorSpace==="display-p3"?"srgb":"linear":typeof e.encoding=="number"?e.encoding===3001?"srgb":"linear":null}function yh(e,t,n){let r=[],o=window.devicePixelRatio||1,i=e.clientWidth||e.width,s=e.clientHeight||e.height,a=i?e.width/(i*o):1,l=s?e.height/(s*o):1,c=Math.min(a,l);if(c<.9&&r.push({id:"canvas-upscaled",severity:c<.6?"high":"medium",area:"resolution",title:`The canvas is drawn at ${Math.round(c*100)}% of the screen's resolution and stretched`,evidence:`drawing buffer ${e.width} \xD7 ${e.height}, shown at ${i} \xD7 ${s} CSS px on a ${Le(o)}\xD7 screen (needs ${Math.round(i*o)} \xD7 ${Math.round(s*o)})`,cause:"The browser enlarges the canvas to fit its box, which blurs it and shows pixels on edges and text. Usual reasons: setPixelRatio was never called (or is fixed at 1), setSize ran before the layout was final, or the canvas is resized in CSS only.",fix:"renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)) and renderer.setSize(width, height) from the element's real size, again on every resize (a ResizeObserver on the canvas parent). In R3F: <Canvas dpr={[1, 2]}>.",tryLive:`set_viewport { pixelRatio: ${Math.min(2,Math.round(o*100)/100)} }, then take_screenshot view:"site" compare:true`}),i&&s){let f=e.width/e.height,d=i/s;Math.abs(f/d-1)>.03&&r.push({id:"canvas-stretched",severity:"high",area:"resolution",title:"The canvas is squashed: its shape on the page differs from what was rendered",evidence:`rendered ${e.width} \xD7 ${e.height} (aspect ${Le(f)}), shown ${i} \xD7 ${s} (aspect ${Le(d)})`,cause:"CSS sets a width and height that the renderer was never told about, so circles become ovals.",fix:"Call renderer.setSize(element.clientWidth, element.clientHeight) and update camera.aspect whenever the element changes size, not only on window resize."}),n&&t.isPerspectiveCamera&&typeof t.aspect=="number"&&Math.abs(t.aspect/f-1)>.03&&r.push({id:"camera-aspect",severity:"high",area:"resolution",title:"The camera aspect does not match the canvas: the scene is distorted",evidence:`camera.aspect ${Le(t.aspect)}, canvas ${Le(f)}`,cause:"After a resize the camera kept its old aspect ratio.",fix:"On resize: camera.aspect = width / height; camera.updateProjectionMatrix()."})}let u=getComputedStyle(e).imageRendering;return(u==="pixelated"||u==="crisp-edges")&&r.push({id:"css-pixelated",severity:c<.99?"high":"low",area:"resolution",title:`The canvas has image-rendering: ${u}`,evidence:"computed style of the canvas element",cause:"Whenever the canvas is not shown at exactly its own size, the browser enlarges it in hard blocks.",fix:"Remove image-rendering from the canvas (or its ancestors) unless a pixel-art look is intended."}),{issues:r,density:Le(c),css:[i,s],dpr:o}}function vh(e,t){let n=[],r=e.reduce((i,s)=>!i||s.triangles>i.triangles?s:i,null);if(!r||r.target==="screen"||!r.targetWidth)return n;let o=r.targetWidth/t;return o<.9&&n.push({id:"target-upscaled",severity:o<.6?"high":"medium",area:"resolution",title:`The scene is rendered into a ${r.target} target, ${Math.round(o*100)}% of the canvas width`,evidence:`main pass "${r.scene}" (${r.triangles.toLocaleString("en-US")} triangles) draws to ${r.target}; the canvas is ${t} px wide`,cause:"The post-processing chain enlarges that picture to the screen: everything looks soft or pixelated however high the pixel ratio is. Usual reason: the composer was sized in CSS pixels and never told the pixel ratio, or not resized with the window.",fix:"composer.setPixelRatio(renderer.getPixelRatio()) and composer.setSize(width, height) on every resize (pmndrs: the EffectComposer follows the renderer; check resolutionScale is 1). Custom targets: size them from renderer.getDrawingBufferSize()."}),n}function wh(e,t,n,r){let o=new Map;for(let h of e){let b;for(let y of Zo(h)){let v=typeof y.vertexShader!="string";for(let{slot:x,texture:M}of Ot(y)){let S=M;if(S.isRenderTargetTexture||S.isDepthTexture||S.isCubeTexture||S.isData3DTexture)continue;let k=o.get(S.uuid);if(k||(k={texture:S,slots:new Set,users:[],stretch:0,shaderOnly:!0},o.set(S.uuid,k)),k.slots.add(x),v&&(k.shaderOnly=!1),k.users.length<4&&k.users.push(h),b===void 0){let A=Pn(h.uuid);b=A?ph(t,A,n,r):null}let{width:E,height:L}=me(S);if(b&&E&&L){let A=Mr(S.repeat),C=Math.max(.01,Math.abs(Number(A?.x??1))||1),O=Math.max(.01,Math.abs(Number(A?.y??1))||1);k.stretch=Math.max(k.stretch,Math.min(b[0]/(E*C),b[1]/(L*O)))}}}}let i=[],s=(h,b,y)=>{b.length&&i.push({id:h,...y(b),objects:[...new Map(b.flatMap(v=>v.users).map(v=>[v.uuid,Fn(v)])).values()].slice(0,8)})},a=h=>h.slice(0,4).map(b=>{let{width:y,height:v}=me(b.texture);return`${b.texture.name||[...b.slots][0]} (${y} \xD7 ${v})`}).join(", ")+(h.length>4?` and ${h.length-4} more`:""),l=[...o.values()],c=h=>{let{width:b,height:y}=me(h.texture);return b>=8&&y>=8&&!h.texture.isDataTexture},u=l.filter(h=>c(h)&&h.stretch>1.5&&[...h.slots].some(b=>!Qo.has(b))).sort((h,b)=>b.stretch-h.stretch);s("texture-magnified",u,h=>({severity:h[0].stretch>3?"high":"medium",area:"textures",title:`${h.length} texture${h.length===1?" is":"s are"} too small for the size on screen`,evidence:`${a(h)}; the worst covers about ${Le(h[0].stretch)} screen pixels per texel`,cause:"Each texel is spread over several screen pixels, so the surface looks blurry (or blocky with NearestFilter) while the edges of the model stay sharp. An estimate from the object's size on screen: a texture atlas that fills only part of the object reads lower than it is.",fix:"Use a larger source image for this camera distance (as KTX2 so memory stays low), tile a detail texture, or keep the camera further away. Check at the closest point of the scroll."}));let f=l.filter(h=>c(h)&&h.texture.magFilter===al&&(h.stretch>1||Math.max(me(h.texture).width,me(h.texture).height)>64));s("texture-nearest",f,h=>({severity:h.some(b=>b.stretch>1)?"medium":"low",area:"textures",title:`${h.length} texture${h.length===1?" uses":"s use"} NearestFilter`,evidence:a(h),cause:"Texels are shown as hard squares whenever the surface is larger on screen than the texture.",fix:"texture.magFilter = THREE.LinearFilter (the default), unless a pixel-art look is intended. Look-up tables and data textures are right to use Nearest."}));let d=l.filter(h=>{let{width:b,height:y}=me(h.texture),v=h.texture.minFilter;return c(h)&&!h.texture.isVideoTexture&&(v===al||v===bh)&&Math.max(b,y)>=512&&h.stretch>0&&h.stretch<.5});s("texture-no-mipmaps",d,h=>({severity:"medium",area:"textures",title:`${h.length} texture${h.length===1?" is":"s are"} shown small without mipmaps`,evidence:`${a(h)}; less than half a screen pixel per texel`,cause:"Several texels fall on each pixel and only one is read, so the surface sparkles and shows moir\xE9 when the camera moves.",fix:"texture.generateMipmaps = true with minFilter LinearMipmapLinearFilter (the default for images). Compressed textures must ship their mip levels: build KTX2 with --genmipmap / mipmaps on."}));let p=l.filter(h=>{let{width:b,height:y}=me(h.texture),v=Mr(h.texture.repeat),x=Math.max(Number(v?.x??1)||1,Number(v?.y??1)||1)>1.5;return c(h)&&!h.shaderOnly&&x&&Math.max(b,y)>=512&&(Number(h.texture.anisotropy)||1)<=1&&h.slots.has("map")});s("texture-anisotropy",p,h=>({severity:"low",area:"textures",title:`${h.length} tiled texture${h.length===1?" has":"s have"} no anisotropic filtering`,evidence:a(h),cause:"A tiled floor or wall seen at a shallow angle turns to blur a short way from the camera.",fix:"texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy()).",tryLive:"set_look { quality: { anisotropy: 8 } }"}));let m=l.filter(h=>c(h)&&!h.shaderOnly&&!h.texture.isCompressedTexture&&[...h.slots].some(b=>gh.has(b))&&![...h.slots].some(b=>Qo.has(b))&&ll(h.texture)==="linear");s("texture-colour-linear",m,h=>({severity:"medium",area:"colour",title:`${h.length} colour texture${h.length===1?" is":"s are"} not marked sRGB`,evidence:a(h),cause:"A colour image is stored in sRGB. Read as linear it comes out pale and washed-out, with wrong contrast under lighting.",fix:"texture.colorSpace = THREE.SRGBColorSpace for map, emissiveMap and other colour images (GLTFLoader and R3F's useTexture on `map` do it; a hand-made TextureLoader does not).",tryLive:"adapt_model with the model's name fixes texture colour spaces live"}));let g=l.filter(h=>c(h)&&!h.shaderOnly&&[...h.slots].every(b=>Qo.has(b))&&ll(h.texture)==="srgb");return s("texture-data-srgb",g,h=>({severity:"medium",area:"colour",title:`${h.length} normal / roughness / metalness / AO texture${h.length===1?" is":"s are"} marked sRGB`,evidence:a(h),cause:"These images hold numbers, not colours. Decoded as sRGB the numbers bend: normals tilt, surfaces come out too rough or too shiny.",fix:"texture.colorSpace = THREE.NoColorSpace for every non-colour map."})),{issues:i,count:o.size}}function xh(e){let t=[],n=[],r=[],o=[];for(let i of e){let s=i.matrixWorld.elements;if(s.some(a=>!Number.isFinite(a)))r.push(i);else{let a=Math.hypot(s[0],s[1],s[2]),l=Math.hypot(s[4],s[5],s[6]),c=Math.hypot(s[8],s[9],s[10]);[a,l,c].filter(u=>u<1e-9).length>=2&&o.push(i)}if(i.isMesh)for(let a of Zo(i)){let l=a;a.transparent&&a.depthWrite!==!1&&(a.opacity??1)<1&&!l.alphaToCoverage&&n.push(i)}}return r.length&&t.push({id:"nan-transform",severity:"high",area:"geometry",title:`${r.length} object${r.length===1?" has":"s have"} NaN or infinite numbers in the transform`,evidence:r.slice(0,4).map(zt).join(", "),cause:"A division by zero or an undefined value reached position, rotation or scale. The object vanishes, and can flicker or take its children with it.",fix:"Find the code that sets its transform (get_animated_values shows what is driven every frame) and guard the division: a delta of 0, a viewport of width 0, a normalised zero vector.",objects:r.slice(0,8).map(Fn)}),o.length&&t.push({id:"zero-scale",severity:"low",area:"geometry",title:`${o.length} visible object${o.length===1?" is":"s are"} scaled to nothing`,evidence:o.slice(0,4).map(zt).join(", "),cause:"Scale 0 hides an object but it is still processed, and a zero scale makes its normals undefined.",fix:"Set visible = false while it is hidden (an intro animation that starts from scale 0 is fine).",objects:o.slice(0,8).map(Fn)}),n.length&&t.push({id:"transparent-depth-write",severity:"medium",area:"transparency",title:`${n.length} see-through object${n.length===1?" writes":"s write"} depth`,evidence:n.slice(0,4).map(zt).join(", "),cause:"A transparent surface that writes depth hides whatever is drawn behind it afterwards: parts of the object, or objects behind it, pop in and out as the camera turns.",fix:"material.depthWrite = false on blended materials; order overlapping layers with renderOrder. For cut-outs (leaves, fences) use alphaTest or alphaToCoverage with transparent off instead of blending.",tryLive:'set_value { uuid, path: "material.depthWrite", value: false }',objects:n.slice(0,8).map(Fn)}),t}function Sh(e,t,n){let r=[];if(t.isPerspectiveCamera&&t.near>0&&!n){let l=t.far/t.near;l>1e5&&r.push({id:"depth-range",severity:l>5e6?"high":"medium",area:"depth",title:`The camera's depth range is ${Math.round(l).toLocaleString("en-US")} : 1`,evidence:`near ${t.near}, far ${t.far}`,cause:"Depth precision is spent between near and far. With a range this wide, surfaces that are close together far from the camera get the same depth and flicker through each other (z-fighting).",fix:"Raise near as far as the scene allows (it matters far more than far) and lower far to just past the scene. Only for truly huge scenes: logarithmicDepthBuffer or a reversed depth buffer.",tryLive:`set_value { uuid: "${t.uuid}", path: "near", value: ${t.near<.1?.1:Le(t.near*10)} } (check nothing close to the camera is cut off)`})}let o=[],i=t.matrixWorld.elements,s=[i[12],i[13],i[14]];for(let l of e){if(!l.isMesh||o.length>=160||Zo(l).some(p=>p.polygonOffset===!0))continue;let u=Pn(l.uuid);if(!u)continue;let f=Math.max(...u.size);if(f<=0)continue;let d=u.size.findIndex(p=>p<=f*1e-4);d<0||o.push({o:l,axis:d,at:u.center[d],min:u.min,max:u.max})}let a=[];for(let l=0;l<o.length&&a.length<6;l++)for(let c=l+1;c<o.length&&a.length<6;c++){let u=o[l],f=o[c];if(u.axis!==f.axis)continue;let d=Math.abs(s[u.axis]-u.at)+1e-6;if(Math.abs(u.at-f.at)>Math.max(d*2e-5,1e-6))continue;[0,1,2].filter(m=>m!==u.axis).every(m=>u.min[m]<f.max[m]&&f.min[m]<u.max[m])&&a.push([u.o,f.o])}return a.length&&r.push({id:"coplanar",severity:"high",area:"depth",title:`${a.length} pair${a.length===1?"":"s"} of flat surfaces lie in the same plane`,evidence:a.slice(0,3).map(([l,c])=>`${zt(l)} / ${zt(c)}`).join("; "),cause:"Two surfaces at the same depth: which one wins changes per pixel and per frame, so they flicker in stripes when the camera moves.",fix:"Move one of them a little along its normal (about 1/1000 of its distance to the camera), or give the one on top polygonOffset: true with polygonOffsetFactor: -1, or a higher renderOrder with depthTest off for a decal.",objects:[...new Map(a.flat().map(l=>[l.uuid,Fn(l)])).values()].slice(0,8)}),r}var cl={high:0,medium:1,low:2};async function ul(e={}){let t=_();if(!t)return null;let{renderer:n,scene:r,camera:o}=t,i=n.domElement,s=n.getContext?.(),a=s?.getContextAttributes?.()??null,l=Mr(n),c=[];s?.isContextLost?.()&&c.push({id:"context-lost",severity:"high",area:"renderer",title:"The WebGL context is lost",evidence:"gl.isContextLost() is true",cause:"The GPU process dropped the context: out of memory (too many or too large textures and render targets), too many contexts on the page, or a driver reset.",fix:"Check get_resources for the memory in use. Dispose what is not shown, keep one renderer, and handle webglcontextlost / webglcontextrestored."});let u=await lr(),f=u.length>0&&u.reduce((S,k)=>k.triangles>S.triangles?k:S).target==="screen",d=yh(i,o,f);c.push(...d.issues,...vh(u,i.width));let p=u.reduce((S,k)=>!S||k.triangles>S.triangles?k:S,null),m=p&&p.target!=="screen"?(p.samples??0)>0:a?.antialias===!0,g=n.getPixelRatio?.()??1;g>2.01&&c.push({id:"pixel-ratio-high",severity:"low",area:"renderer",title:`The renderer's pixel ratio is ${Le(g)}`,evidence:`${i.width} \xD7 ${i.height} drawing buffer`,cause:"Above 2 the eye sees no gain, and every pixel of every pass is paid for: a 3\xD7 phone draws 2.25 times the pixels of a 2\xD7 one.",fix:"renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)).",tryLive:"set_viewport { pixelRatio: 2 }, then get_performance"});let h=l?.outputColorSpace??(l?.outputEncoding===3001?"srgb":l?.outputEncoding===3e3?"srgb-linear":void 0);f&&typeof h=="string"&&h!=="srgb"&&h!=="display-p3"&&c.push({id:"output-colour-space",severity:"high",area:"colour",title:`The renderer outputs ${h}, not sRGB`,evidence:"renderer.outputColorSpace",cause:"Linear light is sent to the screen as it is: the picture is too dark and too contrasty, and colours do not match the design.",fix:"renderer.outputColorSpace = THREE.SRGBColorSpace (the default since r152; R3F sets it unless <Canvas linear> or flat is used).",tryLive:"fix_realism"});let b=mh(r,600),y=null;try{o.updateMatrixWorld(!0);let S=o.matrixWorldInverse?.elements;S&&(y=ae(o.projectionMatrix.elements,S))}catch{}let v=0;if(y){let S=wh(b,y,i.width,i.height);v=S.count,c.push(...S.issues)}c.push(...xh(b));let x=Mr(l?.capabilities);c.push(...Sh(b,o,x?.logarithmicDepthBuffer===!0));try{let S=Sr();for(let[k,E]of(S?.issues??[]).entries())c.push({id:`shadow-${k+1}`,severity:"medium",area:"shadows",title:E.split(". ")[0].replace(/\.$/,""),evidence:"get_lighting",cause:E,fix:"See get_lighting for the light and its shadow camera.",tryLive:"get_lighting"})}catch{}let M=null;if(e.pixels!==!1){let S=await br();if(S){M=Na(S.data,S.width,S.height);let k=za(M,{antialiased:m});c.push(...k)}}return c.sort((S,k)=>cl[S.severity]-cl[k.severity]),{issues:c,measured:M,canvas:{drawingBuffer:[i.width,i.height],cssSize:d.css,devicePixelRatio:Le(d.dpr),density:d.density,antialias:m},checked:{objects:b.length,textures:v,passes:u.length}}}var rt=(e,t)=>.2126*e[t]+.7152*e[t+1]+.0722*e[t+2],Wt=e=>Math.round(e*1e3)/1e3;function hl(e,t,n){let r={width:t,height:n,median:0,brightShare:0,flatShare:0,horizon:null,fringeShare:null,grain:null};if(t<64||n<64)return r;let o=new Uint32Array(256),i=0,s=0;for(let S=0;S<n;S+=3)for(let k=0;k<t;k+=3){let E=rt(e,(S*t+k)*4);o[Math.min(255,Math.round(E))]++,E>218&&s++,i++}let a=0;for(let S=0;S<256;S++)if(a+=o[S],a>=i/2){r.median=S;break}r.brightShare=Wt(s/i);let l=32,c=Math.floor(t/l),u=Math.floor(n/l),f=new Float32Array(c*u),d=new Float32Array(c*u);for(let S=0;S<u;S++)for(let k=0;k<c;k++){let E=0,L=0,A=0;for(let O=S*l;O<S*l+l;O+=2)for(let P=k*l;P<k*l+l;P+=2){let j=rt(e,(O*t+P)*4);E+=j,L+=j*j,A++}let C=E/A;f[S*c+k]=C,d[S*c+k]=Math.sqrt(Math.max(0,L/A-C*C))}let p=0,m=[];for(let S=0;S<u-1;S++)for(let k=0;k<c-1;k++){let E=S*c+k,L=f[E];Math.abs(L-f[E+1])<.9&&Math.abs(L-f[E+c])<.9&&d[E]<14&&(p++,m.push(E))}if(r.flatShare=Wt(p/Math.max(1,(u-1)*(c-1))),m.length>=6){let S=m.map(k=>d[k]).sort((k,E)=>k-E);r.grain=Math.round(S[Math.floor(S.length/2)]*10)/10}let g=0,h=0,b=Math.floor(n*.06),y=Math.floor(n*.94);for(let S=b;S<y;S+=2){let k=0,E=0,L=0;for(let C=4;C<t-4;C+=6){let O=rt(e,((S+3)*t+C)*4)-rt(e,((S-3)*t+C)*4);O>7?E++:O<-7&&k++,L++}let A=Math.max(k,E)/L;A>g&&(g=A,h=S)}g>=.55&&(r.horizon={y:Wt(h/n),span:Wt(g)});let v=0,x=0,M=Math.floor(t*.3);for(let S=8;S<n-8;S+=5)for(let k=8;k<t-8;k++){k===M&&(k=t-M);let E=(S*t+k)*4,L=rt(e,E+12)-rt(e,E-12);if(Math.abs(L)<60)continue;let A=0,C=0,O=0,P=0;for(let j=-6;j<=6;j++){let I=E+j*4,te=Math.abs(e[I+4]-e[I-4]),Ke=Math.abs(e[I+6]-e[I-2]);te>O&&(O=te,A=j),Ke>P&&(P=Ke,C=j)}O>30&&P>30&&(v++,Math.abs(A-C)>=4&&x++),k+=12}return v>=60&&(r.fringeShare=Wt(x/v)),r}function dl(e){let t=[],n=r=>`${Math.round(r*100)}%`;return e.brightShare>.1&&e.median<110&&t.push({id:"glare",severity:"high",title:"A white glare covers part of a dark frame",evidence:`${n(e.brightShare)} of the frame is near white; the median brightness is ${e.median} of 255`,why:"Something in the scene is far brighter than white and bloom spreads it, or a shader produced an invalid number (NaN) and bloom smeared that. The subject drowns in it.",fix:"Find the source: get_object on the brightest thing; environment panels and emissive values above about 5; bloom strength above 0.3 or a threshold under 1. A material with `anisotropy` on geometry that has no `tangent` attribute gives NaN at degenerate triangles: remove the anisotropy or call geometry.computeTangents()."}),e.flatShare>.55&&t.push({id:"flat-frame",severity:"medium",title:"Most of the frame is flat colour",evidence:`${n(e.flatShare)} of the frame has no gradient, light or texture`,why:"A background of one colour and a floor of another is what a tutorial scene looks like. Real set-ups have light falling off, a glow behind the subject, a floor that fades.",fix:"Give the background a soft gradient or a glow behind the subject, let the floor fade into it with fog of the same colour, and light the floor with a pool (a spot light with penumbra 1) instead of evenly."}),e.horizon&&t.push({id:"horizon-line",severity:"medium",title:"A hard horizontal line crosses the frame",evidence:`an edge across ${n(e.horizon.span)} of the width, ${n(e.horizon.y)} down`,why:"It is where the floor ends against the background (or a backdrop plane meets the floor). The eye goes to the line, not the subject, and the scene reads as a box.",fix:"scene.fog with exactly the background colour, starting before the floor ends; a floor much larger than the fog distance; a backdrop that fades out before it reaches the floor. Or frame the shot so the floor edge is out of view."}),e.fringeShare!==null&&e.fringeShare>.45&&t.push({id:"colour-fringe",severity:"medium",title:"Red and blue edges are pulled apart",evidence:`${n(e.fringeShare)} of the strong edges near the sides are split by 4 px or more`,why:"Chromatic aberration (or glass dispersion) this strong reads as a broken lens or a cheap filter.",fix:"Keep a fringe under about 1.5 px at the corners and zero in the centre; `dispersion` on glass under 0.2."}),e.grain!==null&&e.grain>4.5&&t.push({id:"grain-heavy",severity:"low",title:"The grain is strong enough to see as noise",evidence:`${e.grain} brightness levels of noise in the flat parts of the picture`,why:"Grain is there to hide banding and tie the picture together. Seen as noise, it looks like a bad encode.",fix:"Film grain at 0.015 to 0.03 of full brightness (4 to 7 of 255 peak to peak), less in the highlights."}),t}function fl(e,t,n){let r=o=>{let i=o/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4};return .2126*r(e)+.7152*r(t)+.0722*r(n)}var kh=(e,t)=>(Math.max(e,t)+.05)/(Math.min(e,t)+.05);function ml(e,t,n,r){let o=Math.max(0,Math.floor(r.x)),i=Math.max(0,Math.floor(r.y)),s=Math.min(t-2,Math.ceil(r.x+r.width)),a=Math.min(n-2,Math.ceil(r.y+r.height));if(s-o<6||a-i<6)return null;let l=Math.max(1,Math.floor((s-o)/40)),c=Math.max(1,Math.floor((a-i)/12)),u=[],f=0;for(let y=i;y<a;y+=c)for(let v=o;v<s;v+=l){let x=(y*t+v)*4;u.push(fl(e[x],e[x+1],e[x+2])),f++}if(f<8)return null;let d=0,p=0;for(let y=0;y<6;y++){let v=Math.min(a-1,i+Math.floor((y+.5)/6*(a-i)));for(let x=o;x<s-2;x++){let M=(v*t+x)*4;Math.abs(rt(e,M+8)-rt(e,M))>18&&d++,p++}}u.sort((y,v)=>y-v);let m=y=>u[Math.min(u.length-1,Math.floor(u.length*y))],g=fl(r.color[0],r.color[1],r.color[2]),h=g>m(.5)?m(.9):m(.1),b=g*r.alpha+h*(1-r.alpha);return{text:r.text,fontSize:r.fontSize,contrast:Math.round(kh(b,h)*10)/10,busy:Wt(d/Math.max(1,p))}}function pl(e){let t=[],n=i=>`"${i.text.slice(0,40)}" (${Math.round(i.fontSize)} px, ${i.contrast}:1)`,r=e.filter(i=>i.contrast<(i.fontSize>=24?2:2.6));r.length&&t.push({id:"text-unreadable",severity:"high",title:`${r.length} piece${r.length===1?"":"s"} of copy cannot be read over the picture`,evidence:r.slice(0,5).map(n).join("; "),why:"The scene behind the text is nearly the text's own brightness there. Copy the visitor cannot read is the first thing that makes a 3D page feel broken.",fix:"Move the subject or the copy so they do not share the same part of the frame (shift the subject with camera.setViewOffset, not by turning the camera), darken the picture behind the copy (a vignette, a gradient scrim), or change the text colour."});let o=e.filter(i=>i.busy>.2&&i.fontSize<40&&!r.includes(i));return o.length&&t.push({id:"text-on-detail",severity:"medium",title:`${o.length} piece${o.length===1?"":"s"} of copy sit on a busy part of the picture`,evidence:o.slice(0,5).map(i=>`"${i.text.slice(0,40)}"`).join("; "),why:"Small text over edges and detail is tiring to read even when the contrast is there: the subject and the copy are fighting for the same place.",fix:"Give the copy a calm side of the frame: put the subject in the other half with camera.setViewOffset and keep the background there plain."}),t}var gl=new Set(["BoxGeometry","SphereGeometry","CylinderGeometry","ConeGeometry","TorusGeometry","TorusKnotGeometry","IcosahedronGeometry","OctahedronGeometry","DodecahedronGeometry","TetrahedronGeometry","CapsuleGeometry"]),Eh=new Set(["PlaneGeometry","CircleGeometry","RingGeometry","ShapeGeometry"]),Th=/^(serif|sans-serif|monospace|system-ui|ui-sans-serif|ui-serif|-apple-system|blinkmacsystemfont|times|times new roman|arial|helvetica|segoe ui|roboto)$/i,Rh=e=>Array.isArray(e.material)?e.material:e.material?[e.material]:[];function ei(e){let t=/rgba?\(([^)]+)\)/.exec(e);if(!t)return null;let n=t[1].split(/[\s,/]+/).filter(Boolean).map(Number);return n.length<3||n.some(r=>!Number.isFinite(r))?null:{rgb:[n[0],n[1],n[2]],alpha:n[3]??1}}function Ah(e){for(let t=e;t&&t!==document.documentElement;t=t.parentElement){let n=getComputedStyle(t),r=ei(n.backgroundColor);if(r&&r.alpha>.5||n.backgroundImage&&n.backgroundImage!=="none")return!0;for(let o of["::before","::after"]){let i=getComputedStyle(t,o);if(i.content==="none"||i.content==="normal")continue;let s=ei(i.backgroundColor);if(s&&s.alpha>.5||i.backgroundImage&&i.backgroundImage!=="none")return!0}}return!1}function Ph(e){let t=[],n=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT),r=new Set,o,i=0;for(;(o=n.nextNode())&&i<6e3;){i++;let s=(o.textContent??"").replace(/\s+/g," ").trim(),a=o.parentElement;if(s.length<2||!a||r.has(a)||a.closest('script, style, noscript, [aria-hidden="true"], #depthview-root'))continue;r.add(a);let l=a.getBoundingClientRect();if(l.width<8||l.height<6||l.bottom<0||l.top>innerHeight||l.right<0||l.left>innerWidth)continue;let c=getComputedStyle(a);if(c.visibility==="hidden"||c.display==="none")continue;let u=1;for(let d=a;d;d=d.parentElement)u*=Number(getComputedStyle(d).opacity)||0;let f=ei(c.color);!f||u*f.alpha<.05||t.push({el:a,text:(a.textContent??"").replace(/\s+/g," ").trim().slice(0,80),rect:l,fontSize:parseFloat(c.fontSize)||16,font:c.fontFamily.split(",")[0].replace(/["']/g,"").trim(),color:f.rgb,alpha:Math.min(1,u*f.alpha)})}return t.sort((s,a)=>a.fontSize-s.fontSize).slice(0,e)}function Ch(e,t){let n=[],r=[],o=[e],i=0;for(;o.length&&i<2e4&&r.length<800;){let u=o.pop();if(i++,u.visible!==!1){u.isMesh&&u.geometry&&u.material&&r.push(u);for(let f of u.children??[])o.push(f)}}let s=null,a=0,l=0;for(let u of r){let f=u.geometry,d=f.type??"BufferGeometry";if(Eh.has(d))continue;let p=f.boundingBox??null;try{p||f.computeBoundingBox?.(),p=f.boundingBox??null}catch{}if(!p)continue;let m=[p.max.x-p.min.x,p.max.y-p.min.y,p.max.z-p.min.z].sort((b,y)=>b-y);if(m[0]<m[2]*.02)continue;let g=f.attributes?.position?.count??0,h=gl.has(d)||g>0&&g<260;if(l++,h&&a++,!!t)try{let b=u.matrixWorld.elements,y=1/0,v=-1/0,x=1/0,M=-1/0,S=!1;for(let A=0;A<8;A++){let C=[A&1?p.max.x:p.min.x,A&2?p.max.y:p.min.y,A&4?p.max.z:p.min.z],O=oe(b,C),P=t;if(P[3]*O[0]+P[7]*O[1]+P[11]*O[2]+P[15]<=0){S=!0;break}let I=oe(t,O);y=Math.min(y,I[0]),v=Math.max(v,I[0]),x=Math.min(x,I[1]),M=Math.max(M,I[1])}if(S)continue;let k=Math.max(0,Math.min(1,v)-Math.max(-1,y))/2,E=Math.max(0,Math.min(1,M)-Math.max(-1,x))/2,L=k*E;if(L>.9||L<.004)continue;(!s||L>s.screenShare)&&(s={uuid:u.uuid,name:u.name||u.type,geometry:d,screenShare:Math.round(L*1e3)/1e3,vertices:g,stock:h})}catch{}}s?.stock&&n.push({id:"primitive-subject",severity:"high",title:gl.has(s.geometry)?`The subject is a stock ${s.geometry.replace("Geometry","").toLowerCase()}`:"The subject is a bare block: a handful of vertices",evidence:`"${s.name}" (${s.geometry}, ${s.vertices} vertices) takes ${Math.round(s.screenShare*100)}% of the screen`,why:'A box, sphere or torus knot under good light is still a placeholder. Nothing reads as "first draft" faster.',fix:'Model the subject: a profile turned on a lathe (LatheGeometry), an outline extruded with a real bevel (ExtrudeGeometry), a shape displaced with noise, or a glTF model (find_assets, import_asset). get_guide topic:"modeling" has the recipes.'});let c=r.filter(u=>!u.geometry?.attributes?.tangent&&Rh(u).some(f=>Number(f.anisotropy)>0));return c.length&&n.push({id:"anisotropy-no-tangents",severity:"medium",title:`${c.length} object${c.length===1?" has":"s have"} anisotropy but no tangents`,evidence:c.slice(0,4).map(u=>`"${u.name||u.type}"`).join(", "),why:"Without a tangent attribute the shader derives tangents from the UVs. Where UVs collapse (the centre of a lathe or a circle, a pole) that is a division by zero: invalid pixels, which bloom spreads into a white blob.",fix:"geometry.computeTangents() (needs an index, normals and UVs), or drop `anisotropy` on that material."}),{facts:{meshes:r.length,subject:s,primitiveShare:l?Math.round(a/l*100)/100:0},issues:n}}async function bl(){let e=_();if(!e)return null;let{renderer:t,scene:n,camera:r}=e,o=t.domElement,i=[],s=null;try{r.updateMatrixWorld(!0);let h=r.matrixWorldInverse?.elements;h&&(s=ae(r.projectionMatrix.elements,h))}catch{}let a=Ch(n,s);i.push(...a.issues);let l=Ph(24),c=await br(),u=null,f=[],d=[];if(c){u=hl(c.data,c.width,c.height),i.push(...dl(u));let h=o.getBoundingClientRect(),b=o.width/Math.max(1,h.width),y=o.height/Math.max(1,h.height),v=Math.floor((o.width-c.width)/2),x=Math.floor((o.height-c.height)/2);for(let M of l){if(Ah(M.el))continue;let S={text:M.text,x:(M.rect.left-h.left)*b-v,y:(M.rect.top-h.top)*y-x,width:M.rect.width*b,height:M.rect.height*y,color:M.color,alpha:M.alpha,fontSize:M.fontSize},k=ml(c.data,c.width,c.height,S);k&&f.push(k)}i.push(...pl(f));for(let M=0;M<9;M++)for(let S=0;S<16;S++){let k=Math.floor((S+.5)/16*c.width),E=Math.floor((M+.5)/9*c.height),L=0,A=0;for(let C=-6;C<=6;C+=3)for(let O=-6;O<=6;O+=3){let P=Math.min(c.width-1,Math.max(0,k+O)),I=(Math.min(c.height-1,Math.max(0,E+C))*c.width+P)*4;L+=.2126*c.data[I]+.7152*c.data[I+1]+.0722*c.data[I+2],A++}d.push(Math.round(L/A))}}let p=l[0]??null,m=Math.round(document.documentElement.scrollHeight/innerHeight*10)/10;l.length===0?i.push({id:"no-copy",severity:"medium",title:"There is no copy in view",evidence:"no visible text over the scene at this scroll position",why:"A scene with nothing to read is a demo, not a page. On the award-level sites the type carries half of the impression.",fix:"Give every section a small label, a headline and one or two lines, set in a typeface chosen for the brand, on the calm side of the frame."}):p&&Th.test(p.font)&&i.push({id:"default-typeface",severity:"low",title:`The headline is set in a default typeface (${p.font})`,evidence:`"${p.text.slice(0,40)}" at ${Math.round(p.fontSize)} px`,why:"A system font next to a crafted 3D scene reads as unstyled. The typography has to be at the level of the picture.",fix:"Choose a display face for headlines and a quiet one for text, load them (and wait for document.fonts.ready before the reveal)."}),p&&p.fontSize<36&&innerWidth>=900&&i.push({id:"timid-headline",severity:"low",title:"The largest text in view is small",evidence:`"${p.text.slice(0,40)}" at ${Math.round(p.fontSize)} px on a ${innerWidth} px wide screen`,why:"Scale contrast is what gives a page hierarchy: a headline several times the body size, small labels in capitals.",fix:"Headline with clamp(), about 6 to 10% of the viewport width on a hero and 4 to 6% on a section; body 14 to 16 px; labels 10 to 12 px with wide letter spacing."});let g={high:0,medium:1,low:2};return i.sort((h,b)=>g[h.severity]-g[b.severity]),{issues:i,measured:u,text:f,page:{screens:m,textInView:l.length,headline:p?{text:p.text.slice(0,60),fontSize:Math.round(p.fontSize),font:p.font}:null},scene:a.facts,thumb:d}}var ce=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.texture=="string",Vn={uTime:"float: seconds, following the site clock (set_time holds it)",uResolution:"vec2: the drawing buffer in pixels",uCameraLocal:"vec3: the camera position in the effect object's own space",uNoise:"sampler2D: a 256 x 256 tiling noise texture (r and b: white noise, g: r moved by 37, 17 so one read gives 3D value noise; see dvNoise in the clouds shader)",uDepth:"sampler2D: the depth of the solid scene behind this pixel, read at gl_FragCoord.xy / uResolution (0 near, 1 far). Only valid while uHasDepth is 1",uHasDepth:"float: 1 when uDepth holds the scene depth, 0 when the page cannot provide it",uDepthToLocal:"mat4: takes vec4(screen * 2 - 1, depth * 2 - 1, 1) to the effect object's own space (divide by w)"},Ar=256,$h=1e5,yl=6e4,qt=`
|
|
5
|
+
float dvHash(vec3 p) {
|
|
6
|
+
p = fract(p * 0.3183099 + vec3(0.1, 0.2, 0.3));
|
|
7
|
+
p *= 17.0;
|
|
8
|
+
return fract(p.x * p.y * p.z * (p.x + p.y + p.z));
|
|
9
|
+
}
|
|
10
|
+
float dvNoise(vec3 x) {
|
|
11
|
+
vec3 i = floor(x);
|
|
12
|
+
vec3 f = fract(x);
|
|
13
|
+
f = f * f * (3.0 - 2.0 * f);
|
|
14
|
+
return mix(
|
|
15
|
+
mix(mix(dvHash(i), dvHash(i + vec3(1.0, 0.0, 0.0)), f.x),
|
|
16
|
+
mix(dvHash(i + vec3(0.0, 1.0, 0.0)), dvHash(i + vec3(1.0, 1.0, 0.0)), f.x), f.y),
|
|
17
|
+
mix(mix(dvHash(i + vec3(0.0, 0.0, 1.0)), dvHash(i + vec3(1.0, 0.0, 1.0)), f.x),
|
|
18
|
+
mix(dvHash(i + vec3(0.0, 1.0, 1.0)), dvHash(i + vec3(1.0, 1.0, 1.0)), f.x), f.y),
|
|
19
|
+
f.z);
|
|
20
|
+
}
|
|
21
|
+
float dvFbm(vec3 p) {
|
|
22
|
+
float amplitude = 0.5;
|
|
23
|
+
float sum = 0.0;
|
|
24
|
+
for (int i = 0; i < 4; i++) {
|
|
25
|
+
sum += amplitude * dvNoise(p);
|
|
26
|
+
p = p * 2.02 + vec3(13.1, 7.7, 3.3);
|
|
27
|
+
amplitude *= 0.5;
|
|
28
|
+
}
|
|
29
|
+
return sum / 0.9375;
|
|
30
|
+
}
|
|
31
|
+
float dvFbmLow(vec3 p) {
|
|
32
|
+
return (0.5 * dvNoise(p) + 0.25 * dvNoise(p * 2.02 + vec3(13.1, 7.7, 3.3))) / 0.75;
|
|
33
|
+
}
|
|
34
|
+
`,jh=`
|
|
35
|
+
uniform sampler2D uNoise;
|
|
36
|
+
float dvNoise(vec3 x) {
|
|
37
|
+
vec3 i = floor(x);
|
|
38
|
+
vec3 f = fract(x);
|
|
39
|
+
f = f * f * (3.0 - 2.0 * f);
|
|
40
|
+
vec2 uv = (i.xy + vec2(37.0, 17.0) * i.z) + f.xy;
|
|
41
|
+
vec2 rg = texture2D(uNoise, (uv + 0.5) / 256.0).yx;
|
|
42
|
+
return mix(rg.x, rg.y, f.z);
|
|
43
|
+
}
|
|
44
|
+
float dvFbm(vec3 p) {
|
|
45
|
+
float amplitude = 0.5;
|
|
46
|
+
float sum = 0.0;
|
|
47
|
+
for (int i = 0; i < 4; i++) {
|
|
48
|
+
sum += amplitude * dvNoise(p);
|
|
49
|
+
p = p * 2.02 + vec3(13.1, 7.7, 3.3);
|
|
50
|
+
amplitude *= 0.5;
|
|
51
|
+
}
|
|
52
|
+
return sum / 0.9375;
|
|
53
|
+
}
|
|
54
|
+
float dvFbmLow(vec3 p) {
|
|
55
|
+
return (0.5 * dvNoise(p) + 0.25 * dvNoise(p * 2.02 + vec3(13.1, 7.7, 3.3))) / 0.75;
|
|
56
|
+
}
|
|
57
|
+
`,$e=`#include <tonemapping_fragment>
|
|
58
|
+
#include <colorspace_fragment>`,Oh=`
|
|
59
|
+
attribute vec2 dvCorner;
|
|
60
|
+
attribute vec4 dvSeed;
|
|
61
|
+
uniform float uTime;
|
|
62
|
+
uniform float uSize;
|
|
63
|
+
uniform float uSizeRandom;
|
|
64
|
+
uniform float uSpeed;
|
|
65
|
+
uniform float uTurbulence;
|
|
66
|
+
uniform float uTwinkle;
|
|
67
|
+
uniform float uStretch;
|
|
68
|
+
uniform vec3 uDirection;
|
|
69
|
+
varying vec2 vUv;
|
|
70
|
+
varying float vFade;
|
|
71
|
+
varying float vSeed;
|
|
72
|
+
|
|
73
|
+
void main() {
|
|
74
|
+
// Each sprite drifts through a unit box and wraps round, so the field never empties.
|
|
75
|
+
vec3 p = position + uDirection * uSpeed * uTime * (0.5 + dvSeed.x);
|
|
76
|
+
float t = uTime * 0.25;
|
|
77
|
+
p += uTurbulence * 0.08 * vec3(
|
|
78
|
+
sin(t * 1.3 + dvSeed.y * 6.2832 + position.y * 4.0),
|
|
79
|
+
sin(t * 1.7 + dvSeed.z * 6.2832 + position.z * 4.0),
|
|
80
|
+
sin(t * 1.1 + dvSeed.w * 6.2832 + position.x * 4.0));
|
|
81
|
+
p = fract(p + 0.5) - 0.5;
|
|
82
|
+
// Fade out towards the faces of the box: the wrap is never seen.
|
|
83
|
+
vec3 edge = smoothstep(0.5, 0.4, abs(p));
|
|
84
|
+
vFade = edge.x * edge.y * edge.z;
|
|
85
|
+
vFade *= 1.0 - uTwinkle * (0.5 + 0.5 * sin(uTime * (1.0 + dvSeed.y * 3.0) + dvSeed.z * 6.2832));
|
|
86
|
+
|
|
87
|
+
vec4 mv = modelViewMatrix * vec4(p, 1.0);
|
|
88
|
+
// Size is in scene units whatever the scale of the box. Stretch pulls the sprite out along
|
|
89
|
+
// its direction of travel (rain, sparks).
|
|
90
|
+
float size = uSize * mix(1.0, 0.25 + 0.75 * dvSeed.w, uSizeRandom);
|
|
91
|
+
vec2 axis = (modelViewMatrix * vec4(uDirection, 0.0)).xy;
|
|
92
|
+
axis = length(axis) > 0.0001 ? normalize(axis) : vec2(0.0, 1.0);
|
|
93
|
+
vec2 across = vec2(-axis.y, axis.x);
|
|
94
|
+
mv.xy += (across * dvCorner.x + axis * dvCorner.y * (1.0 + uStretch)) * size * 0.5;
|
|
95
|
+
gl_Position = projectionMatrix * mv;
|
|
96
|
+
vUv = dvCorner;
|
|
97
|
+
vSeed = dvSeed.x;
|
|
98
|
+
}
|
|
99
|
+
`,ni=`
|
|
100
|
+
uniform vec3 uColor;
|
|
101
|
+
uniform vec3 uColor2;
|
|
102
|
+
uniform float uOpacity;
|
|
103
|
+
uniform float uSoftness;
|
|
104
|
+
varying vec2 vUv;
|
|
105
|
+
varying float vFade;
|
|
106
|
+
varying float vSeed;
|
|
107
|
+
|
|
108
|
+
void main() {
|
|
109
|
+
float d = length(vUv);
|
|
110
|
+
if (d > 1.0) discard;
|
|
111
|
+
float alpha = 1.0 - smoothstep(1.0 - max(uSoftness, 0.001), 1.0, d);
|
|
112
|
+
gl_FragColor = vec4(mix(uColor, uColor2, vSeed), alpha * uOpacity * vFade);
|
|
113
|
+
${$e}
|
|
114
|
+
}
|
|
115
|
+
`,kr=`
|
|
116
|
+
attribute vec2 dvCorner;
|
|
117
|
+
attribute vec4 dvSeed;
|
|
118
|
+
uniform float uTime;
|
|
119
|
+
uniform float uSize;
|
|
120
|
+
uniform float uSpeed;
|
|
121
|
+
uniform float uSpread;
|
|
122
|
+
uniform float uTurbulence;
|
|
123
|
+
uniform vec3 uWind;
|
|
124
|
+
varying vec2 vUv;
|
|
125
|
+
varying float vLife;
|
|
126
|
+
varying float vSeed;
|
|
127
|
+
|
|
128
|
+
void main() {
|
|
129
|
+
// One puff rises from the object's origin to one unit above it, then starts again: the
|
|
130
|
+
// position of the effect is where the smoke comes from.
|
|
131
|
+
float life = fract(dvSeed.x + uTime * uSpeed * (0.6 + 0.8 * dvSeed.y));
|
|
132
|
+
vec3 p = vec3(position.x, 0.0, position.z) * uSpread * (0.25 + life);
|
|
133
|
+
p.y = life;
|
|
134
|
+
p.xz += uTurbulence * 0.15 * life * vec2(
|
|
135
|
+
sin(life * 6.0 + dvSeed.z * 6.2832 + uTime * 0.3),
|
|
136
|
+
cos(life * 5.0 + dvSeed.w * 6.2832 + uTime * 0.25));
|
|
137
|
+
p += uWind * life * life;
|
|
138
|
+
|
|
139
|
+
vec4 mv = modelViewMatrix * vec4(p, 1.0);
|
|
140
|
+
float size = uSize * (0.4 + 1.6 * life) * (0.7 + 0.6 * dvSeed.w);
|
|
141
|
+
// Each puff has its own slow turn, so the sprites do not read as copies.
|
|
142
|
+
float turn = dvSeed.z * 6.2832 + life * (dvSeed.w - 0.5) * 2.0;
|
|
143
|
+
vec2 corner = vec2(
|
|
144
|
+
cos(turn) * dvCorner.x - sin(turn) * dvCorner.y,
|
|
145
|
+
sin(turn) * dvCorner.x + cos(turn) * dvCorner.y);
|
|
146
|
+
mv.xy += corner * size * 0.5;
|
|
147
|
+
gl_Position = projectionMatrix * mv;
|
|
148
|
+
vUv = dvCorner;
|
|
149
|
+
vLife = life;
|
|
150
|
+
vSeed = dvSeed.x * 31.0 + dvSeed.y * 17.0;
|
|
151
|
+
}
|
|
152
|
+
`,Er=`
|
|
153
|
+
uniform vec3 uColor;
|
|
154
|
+
uniform vec3 uColor2;
|
|
155
|
+
uniform float uOpacity;
|
|
156
|
+
uniform float uDetail;
|
|
157
|
+
uniform float uSoftEdge;
|
|
158
|
+
uniform sampler2D uDepth;
|
|
159
|
+
uniform float uHasDepth;
|
|
160
|
+
uniform vec2 uResolution;
|
|
161
|
+
uniform mat4 projectionMatrix;
|
|
162
|
+
varying vec2 vUv;
|
|
163
|
+
varying float vLife;
|
|
164
|
+
varying float vSeed;
|
|
165
|
+
${qt}
|
|
166
|
+
// Distance in front of the camera, from a depth-buffer value.
|
|
167
|
+
float dvViewDepth(float depth) {
|
|
168
|
+
return projectionMatrix[3][2] / (depth * 2.0 - 1.0 + projectionMatrix[2][2]);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
void main() {
|
|
172
|
+
float d = length(vUv);
|
|
173
|
+
if (d > 1.0) discard;
|
|
174
|
+
// A soft disc, eaten into by noise so the edge is ragged like real smoke.
|
|
175
|
+
float body = 1.0 - smoothstep(0.2, 1.0, d);
|
|
176
|
+
float wisps = dvFbm(vec3(vUv * 1.6, vSeed));
|
|
177
|
+
float alpha = body * mix(1.0, smoothstep(0.25, 0.75, wisps), uDetail);
|
|
178
|
+
// In fast, out slowly.
|
|
179
|
+
alpha *= smoothstep(0.0, 0.08, vLife) * pow(1.0 - vLife, 1.5);
|
|
180
|
+
// Fade out where a puff comes close to a surface: no hard line where it cuts the floor.
|
|
181
|
+
if (uHasDepth > 0.5) {
|
|
182
|
+
float solid = dvViewDepth(texture2D(uDepth, gl_FragCoord.xy / uResolution).r);
|
|
183
|
+
alpha *= smoothstep(0.0, max(uSoftEdge, 0.0001), solid - dvViewDepth(gl_FragCoord.z));
|
|
184
|
+
}
|
|
185
|
+
// Lit from above: the underside of a puff is darker.
|
|
186
|
+
float lit = mix(0.72, 1.0, vUv.y * 0.5 + 0.5);
|
|
187
|
+
gl_FragColor = vec4(mix(uColor, uColor2, vLife) * lit, alpha * uOpacity);
|
|
188
|
+
${$e}
|
|
189
|
+
}
|
|
190
|
+
`,_h=`
|
|
191
|
+
uniform vec3 uCameraLocal;
|
|
192
|
+
varying vec3 vOrigin;
|
|
193
|
+
varying vec3 vDirection;
|
|
194
|
+
|
|
195
|
+
void main() {
|
|
196
|
+
vOrigin = uCameraLocal;
|
|
197
|
+
vDirection = position - uCameraLocal;
|
|
198
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
199
|
+
}
|
|
200
|
+
`,Ih=`
|
|
201
|
+
uniform float uTime;
|
|
202
|
+
uniform float uSteps;
|
|
203
|
+
uniform float uDensity;
|
|
204
|
+
uniform float uCoverage;
|
|
205
|
+
uniform float uScale;
|
|
206
|
+
uniform float uDetail;
|
|
207
|
+
uniform float uEdge;
|
|
208
|
+
uniform float uBottom;
|
|
209
|
+
uniform float uTop;
|
|
210
|
+
uniform float uAbsorption;
|
|
211
|
+
uniform float uPowder;
|
|
212
|
+
uniform float uSilver;
|
|
213
|
+
uniform float uOpacity;
|
|
214
|
+
uniform vec3 uWind;
|
|
215
|
+
uniform vec3 uLightDir;
|
|
216
|
+
uniform vec3 uLightColor;
|
|
217
|
+
uniform vec3 uShadowColor;
|
|
218
|
+
uniform sampler2D uDepth;
|
|
219
|
+
uniform mat4 uDepthToLocal;
|
|
220
|
+
uniform float uHasDepth;
|
|
221
|
+
uniform vec2 uResolution;
|
|
222
|
+
varying vec3 vOrigin;
|
|
223
|
+
varying vec3 vDirection;
|
|
224
|
+
${jh}
|
|
225
|
+
// Where the ray enters and leaves the unit box.
|
|
226
|
+
vec2 dvHitBox(vec3 origin, vec3 direction) {
|
|
227
|
+
vec3 inv = 1.0 / direction;
|
|
228
|
+
vec3 t0 = (vec3(-0.5) - origin) * inv;
|
|
229
|
+
vec3 t1 = (vec3(0.5) - origin) * inv;
|
|
230
|
+
vec3 near = min(t0, t1);
|
|
231
|
+
vec3 far = max(t0, t1);
|
|
232
|
+
return vec2(max(near.x, max(near.y, near.z)), min(far.x, min(far.y, far.z)));
|
|
233
|
+
}
|
|
234
|
+
// Fades the volume out before the faces of the box, so the box itself is never seen.
|
|
235
|
+
float dvShape(vec3 p) {
|
|
236
|
+
vec3 edge = smoothstep(vec3(0.5), vec3(0.5 - uEdge), abs(p));
|
|
237
|
+
float h = p.y + 0.5;
|
|
238
|
+
float height = smoothstep(0.0, max(uBottom, 0.001), h) * (1.0 - smoothstep(1.0 - max(uTop, 0.001), 1.0, h));
|
|
239
|
+
return edge.x * edge.z * height;
|
|
240
|
+
}
|
|
241
|
+
float dvRemap(float n) {
|
|
242
|
+
return clamp((n - (1.0 - uCoverage)) / max(uCoverage, 0.001), 0.0, 1.0);
|
|
243
|
+
}
|
|
244
|
+
float dvDensity(vec3 p) {
|
|
245
|
+
float shape = dvShape(p);
|
|
246
|
+
if (shape <= 0.0) return 0.0;
|
|
247
|
+
vec3 q = p * uScale + uWind * uTime;
|
|
248
|
+
float n = dvFbm(q);
|
|
249
|
+
// Fine noise carves the edges: that is what makes the billows.
|
|
250
|
+
n -= uDetail * 0.25 * (1.0 - dvNoise(q * 4.1 + vec3(5.0)));
|
|
251
|
+
return dvRemap(n) * shape * uDensity;
|
|
252
|
+
}
|
|
253
|
+
// A cheaper density for the steps towards the light.
|
|
254
|
+
float dvDensityLow(vec3 p) {
|
|
255
|
+
float shape = dvShape(p);
|
|
256
|
+
if (shape <= 0.0) return 0.0;
|
|
257
|
+
return dvRemap(dvFbmLow(p * uScale + uWind * uTime)) * shape * uDensity;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
void main() {
|
|
261
|
+
vec3 direction = normalize(vDirection);
|
|
262
|
+
vec2 hit = dvHitBox(vOrigin, direction);
|
|
263
|
+
if (hit.x > hit.y) discard;
|
|
264
|
+
hit.x = max(hit.x, 0.0);
|
|
265
|
+
// Stop at whatever solid thing is behind this pixel: the cloud goes round objects, not over.
|
|
266
|
+
if (uHasDepth > 0.5) {
|
|
267
|
+
vec2 screen = gl_FragCoord.xy / uResolution;
|
|
268
|
+
float depth = texture2D(uDepth, screen).r;
|
|
269
|
+
if (depth < 1.0) {
|
|
270
|
+
vec4 solid = uDepthToLocal * vec4(screen * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
|
271
|
+
hit.y = min(hit.y, dot(solid.xyz / solid.w - vOrigin, direction));
|
|
272
|
+
}
|
|
273
|
+
if (hit.x >= hit.y) discard;
|
|
274
|
+
}
|
|
275
|
+
float stepLength = (hit.y - hit.x) / uSteps;
|
|
276
|
+
// Start each ray at a different depth: the slices of the march turn into fine grain.
|
|
277
|
+
float jitter = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715))));
|
|
278
|
+
float t = hit.x + stepLength * jitter;
|
|
279
|
+
vec3 toLight = normalize(uLightDir);
|
|
280
|
+
// Looking towards the light, thin edges glow (forward scattering).
|
|
281
|
+
float towards = max(dot(direction, toLight), 0.0);
|
|
282
|
+
float silver = 1.0 + uSilver * pow(towards, 8.0) * 2.0;
|
|
283
|
+
|
|
284
|
+
float transmittance = 1.0;
|
|
285
|
+
vec3 light = vec3(0.0);
|
|
286
|
+
for (int i = 0; i < 96; i++) {
|
|
287
|
+
if (float(i) >= uSteps || transmittance < 0.02) break;
|
|
288
|
+
vec3 p = vOrigin + direction * t;
|
|
289
|
+
float density = dvDensity(p);
|
|
290
|
+
if (density > 0.001) {
|
|
291
|
+
float towardsLight = 0.0;
|
|
292
|
+
for (int j = 1; j <= 3; j++) towardsLight += dvDensityLow(p + toLight * 0.07 * float(j));
|
|
293
|
+
float sun = exp(-towardsLight * 0.07 * uAbsorption);
|
|
294
|
+
// Dense cores scatter light back out: the "powdered sugar" look of cumulus.
|
|
295
|
+
float powder = mix(1.0, 1.0 - exp(-density * 2.0), uPowder);
|
|
296
|
+
vec3 colour = uShadowColor + uLightColor * sun * powder * silver;
|
|
297
|
+
float absorbed = 1.0 - exp(-density * stepLength * uAbsorption);
|
|
298
|
+
light += transmittance * absorbed * colour;
|
|
299
|
+
transmittance *= 1.0 - absorbed;
|
|
300
|
+
}
|
|
301
|
+
t += stepLength;
|
|
302
|
+
}
|
|
303
|
+
float alpha = 1.0 - transmittance;
|
|
304
|
+
if (alpha < 0.003) discard;
|
|
305
|
+
gl_FragColor = vec4(light / alpha, alpha * uOpacity);
|
|
306
|
+
${$e}
|
|
307
|
+
}
|
|
308
|
+
`,Fh=`
|
|
309
|
+
attribute vec2 dvCorner;
|
|
310
|
+
attribute vec4 dvSeed;
|
|
311
|
+
uniform float uTime;
|
|
312
|
+
uniform float uSize;
|
|
313
|
+
uniform float uArms;
|
|
314
|
+
uniform float uTwist;
|
|
315
|
+
uniform float uSpin;
|
|
316
|
+
uniform float uThickness;
|
|
317
|
+
varying vec2 vUv;
|
|
318
|
+
varying float vFade;
|
|
319
|
+
varying float vSeed;
|
|
320
|
+
|
|
321
|
+
void main() {
|
|
322
|
+
// Each sprite sits on one of the spiral arms, further out the larger its first seed.
|
|
323
|
+
float radius = pow(dvSeed.x, 0.7) * 0.5;
|
|
324
|
+
float arm = floor(dvSeed.y * uArms) / uArms * 6.2832;
|
|
325
|
+
float scatter = (dvSeed.z - 0.5) * (0.25 + radius * 1.2);
|
|
326
|
+
float angle = arm + radius * uTwist + scatter + uTime * uSpin * (1.0 - radius);
|
|
327
|
+
vec3 p = vec3(cos(angle) * radius, (dvSeed.w - 0.5) * uThickness * (1.0 - radius * 1.6), sin(angle) * radius);
|
|
328
|
+
vec4 mv = modelViewMatrix * vec4(p, 1.0);
|
|
329
|
+
mv.xy += dvCorner * uSize * (0.4 + 0.6 * dvSeed.w) * 0.5;
|
|
330
|
+
gl_Position = projectionMatrix * mv;
|
|
331
|
+
vUv = dvCorner;
|
|
332
|
+
vFade = 1.0 - smoothstep(0.35, 0.5, radius);
|
|
333
|
+
vSeed = radius * 2.0;
|
|
334
|
+
}
|
|
335
|
+
`,Vh=`
|
|
336
|
+
attribute vec2 dvCorner;
|
|
337
|
+
attribute vec4 dvSeed;
|
|
338
|
+
uniform float uTime;
|
|
339
|
+
uniform float uSize;
|
|
340
|
+
uniform float uShape;
|
|
341
|
+
uniform float uFlow;
|
|
342
|
+
uniform float uSpin;
|
|
343
|
+
varying vec2 vUv;
|
|
344
|
+
varying float vFade;
|
|
345
|
+
varying float vSeed;
|
|
346
|
+
|
|
347
|
+
// Three shapes built from the same seeds: a sphere, a ring and a box.
|
|
348
|
+
vec3 dvSphere(vec4 s) {
|
|
349
|
+
float z = s.x * 2.0 - 1.0;
|
|
350
|
+
float a = s.y * 6.2832;
|
|
351
|
+
float r = sqrt(max(1.0 - z * z, 0.0));
|
|
352
|
+
return vec3(r * cos(a), z, r * sin(a)) * 0.42;
|
|
353
|
+
}
|
|
354
|
+
vec3 dvRing(vec4 s) {
|
|
355
|
+
float a = s.x * 6.2832;
|
|
356
|
+
float b = s.y * 6.2832;
|
|
357
|
+
float tube = 0.09 * sqrt(s.z);
|
|
358
|
+
return vec3((0.36 + tube * cos(b)) * cos(a), tube * sin(b), (0.36 + tube * cos(b)) * sin(a));
|
|
359
|
+
}
|
|
360
|
+
vec3 dvBox(vec4 s) {
|
|
361
|
+
vec3 p = vec3(s.x, s.y, s.z) - 0.5;
|
|
362
|
+
// Push every point out to the nearest face, so the box is a shell, not a cloud.
|
|
363
|
+
vec3 a = abs(p);
|
|
364
|
+
float m = max(a.x, max(a.y, a.z));
|
|
365
|
+
return p / max(m, 0.001) * 0.36;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
void main() {
|
|
369
|
+
float shape = mod(uShape, 3.0);
|
|
370
|
+
vec3 a = dvSphere(dvSeed);
|
|
371
|
+
vec3 b = dvRing(dvSeed);
|
|
372
|
+
vec3 c = dvBox(dvSeed);
|
|
373
|
+
// Each sprite leaves a little earlier or later: the shape flows over instead of snapping.
|
|
374
|
+
float lag = (dvSeed.w - 0.5) * 0.35;
|
|
375
|
+
vec3 p = mix(a, b, smoothstep(0.0, 1.0, clamp(shape + lag, 0.0, 1.0)));
|
|
376
|
+
p = mix(p, c, smoothstep(0.0, 1.0, clamp(shape - 1.0 + lag, 0.0, 1.0)));
|
|
377
|
+
p = mix(p, a, smoothstep(0.0, 1.0, clamp(shape - 2.0 + lag, 0.0, 1.0)));
|
|
378
|
+
float t = uTime * 0.6;
|
|
379
|
+
p += uFlow * 0.03 * vec3(
|
|
380
|
+
sin(t * 1.3 + dvSeed.y * 40.0 + p.y * 9.0),
|
|
381
|
+
sin(t * 1.7 + dvSeed.z * 40.0 + p.z * 9.0),
|
|
382
|
+
sin(t * 1.1 + dvSeed.x * 40.0 + p.x * 9.0));
|
|
383
|
+
float turn = uTime * uSpin;
|
|
384
|
+
p.xz = mat2(cos(turn), -sin(turn), sin(turn), cos(turn)) * p.xz;
|
|
385
|
+
vec4 mv = modelViewMatrix * vec4(p, 1.0);
|
|
386
|
+
mv.xy += dvCorner * uSize * (0.5 + 0.5 * dvSeed.w) * 0.5;
|
|
387
|
+
gl_Position = projectionMatrix * mv;
|
|
388
|
+
vUv = dvCorner;
|
|
389
|
+
vFade = 1.0;
|
|
390
|
+
vSeed = dvSeed.x;
|
|
391
|
+
}
|
|
392
|
+
`,Dh=`
|
|
393
|
+
varying vec3 vWorld;
|
|
394
|
+
|
|
395
|
+
void main() {
|
|
396
|
+
vec4 world = modelMatrix * vec4(position.x, 0.0, -position.y, 1.0);
|
|
397
|
+
vWorld = world.xyz;
|
|
398
|
+
gl_Position = projectionMatrix * viewMatrix * world;
|
|
399
|
+
}
|
|
400
|
+
`,Nh=`
|
|
401
|
+
uniform float uTime;
|
|
402
|
+
uniform float uWaveScale;
|
|
403
|
+
uniform float uWaveHeight;
|
|
404
|
+
uniform float uSpeed;
|
|
405
|
+
uniform float uGloss;
|
|
406
|
+
uniform float uOpacity;
|
|
407
|
+
uniform vec3 uDeep;
|
|
408
|
+
uniform vec3 uShallow;
|
|
409
|
+
uniform vec3 uSky;
|
|
410
|
+
uniform vec3 uLightDir;
|
|
411
|
+
uniform vec3 uLightColor;
|
|
412
|
+
varying vec3 vWorld;
|
|
413
|
+
${qt}
|
|
414
|
+
// Height of the surface: a few crossing swells plus fine chop.
|
|
415
|
+
float dvWave(vec2 p) {
|
|
416
|
+
float t = uTime * uSpeed;
|
|
417
|
+
float h = sin(dot(p, vec2(1.0, 0.3)) * 1.1 + t * 1.1) * 0.5;
|
|
418
|
+
h += sin(dot(p, vec2(-0.4, 1.0)) * 1.7 + t * 1.4) * 0.3;
|
|
419
|
+
h += sin(dot(p, vec2(0.7, -0.8)) * 2.9 + t * 1.9) * 0.15;
|
|
420
|
+
h += (dvNoise(vec3(p * 3.0, t * 0.6)) - 0.5) * 0.35;
|
|
421
|
+
return h;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
void main() {
|
|
425
|
+
vec2 p = vWorld.xz * uWaveScale;
|
|
426
|
+
float e = 0.05;
|
|
427
|
+
float h = dvWave(p);
|
|
428
|
+
vec3 normal = normalize(vec3(
|
|
429
|
+
(h - dvWave(p + vec2(e, 0.0))) * uWaveHeight,
|
|
430
|
+
e,
|
|
431
|
+
(h - dvWave(p + vec2(0.0, e))) * uWaveHeight));
|
|
432
|
+
vec3 view = normalize(cameraPosition - vWorld);
|
|
433
|
+
// Water is a mirror at a glancing angle and see-through from above.
|
|
434
|
+
float fresnel = 0.02 + 0.98 * pow(1.0 - max(dot(normal, view), 0.0), 5.0);
|
|
435
|
+
vec3 body = mix(uDeep, uShallow, 0.5 + 0.5 * h * 0.6);
|
|
436
|
+
vec3 colour = mix(body, uSky, fresnel);
|
|
437
|
+
vec3 halfway = normalize(normalize(uLightDir) + view);
|
|
438
|
+
colour += uLightColor * pow(max(dot(normal, halfway), 0.0), uGloss) * 2.0;
|
|
439
|
+
gl_FragColor = vec4(colour, mix(uOpacity, 1.0, fresnel));
|
|
440
|
+
${$e}
|
|
441
|
+
}
|
|
442
|
+
`,zh=`
|
|
443
|
+
varying vec2 vUv;
|
|
444
|
+
|
|
445
|
+
void main() {
|
|
446
|
+
vUv = uv;
|
|
447
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
448
|
+
}
|
|
449
|
+
`,Wh=`
|
|
450
|
+
uniform float uTime;
|
|
451
|
+
uniform float uSpeed;
|
|
452
|
+
uniform float uBands;
|
|
453
|
+
uniform float uRays;
|
|
454
|
+
uniform float uOpacity;
|
|
455
|
+
uniform vec3 uColor;
|
|
456
|
+
uniform vec3 uColor2;
|
|
457
|
+
varying vec2 vUv;
|
|
458
|
+
${qt}
|
|
459
|
+
void main() {
|
|
460
|
+
float t = uTime * uSpeed;
|
|
461
|
+
// Slow folds along the curtain, fine vertical rays inside them.
|
|
462
|
+
float fold = dvFbm(vec3(vUv.x * uBands + t * 0.3, vUv.y * 0.4, t * 0.2));
|
|
463
|
+
float rays = dvNoise(vec3(vUv.x * 60.0 + fold * 6.0, t * 0.8, 3.0));
|
|
464
|
+
float curtain = smoothstep(0.35, 0.75, fold) * mix(1.0, 0.4 + 0.6 * rays, uRays);
|
|
465
|
+
// Bright along the lower edge, fading upwards; nothing at the very bottom and sides.
|
|
466
|
+
float height = smoothstep(0.0, 0.12, vUv.y) * pow(1.0 - vUv.y, 1.6);
|
|
467
|
+
float sides = smoothstep(0.0, 0.15, vUv.x) * smoothstep(1.0, 0.85, vUv.x);
|
|
468
|
+
float alpha = curtain * height * sides * uOpacity;
|
|
469
|
+
gl_FragColor = vec4(mix(uColor, uColor2, smoothstep(0.1, 0.9, vUv.y)) * 1.6, alpha);
|
|
470
|
+
${$e}
|
|
471
|
+
}
|
|
472
|
+
`,ti=`
|
|
473
|
+
varying vec3 vNormal;
|
|
474
|
+
varying vec3 vView;
|
|
475
|
+
varying vec3 vLocal;
|
|
476
|
+
varying vec2 vUv;
|
|
477
|
+
|
|
478
|
+
void main() {
|
|
479
|
+
vec4 mv = modelViewMatrix * vec4(position, 1.0);
|
|
480
|
+
vNormal = normalize(normalMatrix * normal);
|
|
481
|
+
vView = normalize(-mv.xyz);
|
|
482
|
+
vLocal = position;
|
|
483
|
+
vUv = uv;
|
|
484
|
+
gl_Position = projectionMatrix * mv;
|
|
485
|
+
}
|
|
486
|
+
`,Bh=`
|
|
487
|
+
uniform float uTime;
|
|
488
|
+
uniform float uLines;
|
|
489
|
+
uniform float uSpeed;
|
|
490
|
+
uniform float uRim;
|
|
491
|
+
uniform float uFlicker;
|
|
492
|
+
uniform float uOpacity;
|
|
493
|
+
uniform vec3 uColor;
|
|
494
|
+
varying vec3 vNormal;
|
|
495
|
+
varying vec3 vView;
|
|
496
|
+
varying vec3 vLocal;
|
|
497
|
+
${qt}
|
|
498
|
+
void main() {
|
|
499
|
+
float facing = abs(dot(normalize(vNormal), normalize(vView)));
|
|
500
|
+
float rim = pow(1.0 - facing, uRim);
|
|
501
|
+
float lines = 0.5 + 0.5 * sin((vLocal.y * uLines - uTime * uSpeed) * 6.2832);
|
|
502
|
+
lines = smoothstep(0.35, 0.65, lines);
|
|
503
|
+
// A bright band sweeps up now and then, and the whole thing flickers a little.
|
|
504
|
+
float sweep = smoothstep(0.06, 0.0, abs(fract(vLocal.y - uTime * 0.25) - 0.5));
|
|
505
|
+
float flicker = 1.0 - uFlicker * dvHash(vec3(floor(uTime * 24.0), 1.0, 2.0)) * 0.5;
|
|
506
|
+
float alpha = (rim + lines * 0.25 + sweep * 0.5) * flicker * uOpacity;
|
|
507
|
+
gl_FragColor = vec4(uColor * (1.0 + rim * 1.5), alpha);
|
|
508
|
+
${$e}
|
|
509
|
+
}
|
|
510
|
+
`,Hh=`
|
|
511
|
+
uniform float uTime;
|
|
512
|
+
uniform float uCells;
|
|
513
|
+
uniform float uPulse;
|
|
514
|
+
uniform float uRim;
|
|
515
|
+
uniform float uOpacity;
|
|
516
|
+
uniform vec3 uColor;
|
|
517
|
+
uniform vec3 uColor2;
|
|
518
|
+
varying vec3 vNormal;
|
|
519
|
+
varying vec3 vView;
|
|
520
|
+
varying vec3 vLocal;
|
|
521
|
+
|
|
522
|
+
// Distance to the nearest edge of a hexagonal cell.
|
|
523
|
+
float dvHex(vec2 p) {
|
|
524
|
+
p = abs(mod(p, vec2(1.7320508, 1.0) * 2.0) - vec2(1.7320508, 1.0));
|
|
525
|
+
vec2 q = abs(p - vec2(0.8660254, 0.5));
|
|
526
|
+
p = (dot(q, q) < dot(p, p)) ? q : p;
|
|
527
|
+
return max(p.y, p.x * 0.8660254 + p.y * 0.5);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
void main() {
|
|
531
|
+
vec3 n = normalize(vLocal);
|
|
532
|
+
float rim = pow(1.0 - abs(dot(normalize(vNormal), normalize(vView))), uRim);
|
|
533
|
+
vec2 surface = vec2(atan(n.z, n.x) * 1.9099, asin(clamp(n.y, -1.0, 1.0)) * 1.9099);
|
|
534
|
+
float edge = smoothstep(0.42, 0.5, dvHex(surface * uCells));
|
|
535
|
+
// A ring of light travels from the top of the shield to the bottom.
|
|
536
|
+
float wave = smoothstep(0.12, 0.0, abs(fract(n.y * 0.5 + 0.5 + uTime * uPulse) - 0.5));
|
|
537
|
+
float alpha = (rim + edge * (0.25 + wave) + wave * 0.15) * uOpacity;
|
|
538
|
+
gl_FragColor = vec4(mix(uColor, uColor2, wave) * (1.0 + rim), alpha);
|
|
539
|
+
${$e}
|
|
540
|
+
}
|
|
541
|
+
`,Uh=`
|
|
542
|
+
uniform float uTime;
|
|
543
|
+
uniform float uStreaks;
|
|
544
|
+
uniform float uFalloff;
|
|
545
|
+
uniform float uEdge;
|
|
546
|
+
uniform float uOpacity;
|
|
547
|
+
uniform vec3 uColor;
|
|
548
|
+
varying vec3 vNormal;
|
|
549
|
+
varying vec3 vView;
|
|
550
|
+
varying vec2 vUv;
|
|
551
|
+
${qt}
|
|
552
|
+
void main() {
|
|
553
|
+
// vUv.y is 1 at the lamp and 0 where the beam ends.
|
|
554
|
+
float along = pow(vUv.y, uFalloff);
|
|
555
|
+
// The sides of the cone fade out, so there is no hard silhouette.
|
|
556
|
+
float soft = pow(abs(dot(normalize(vNormal), normalize(vView))), uEdge);
|
|
557
|
+
float streaks = mix(1.0, 0.55 + 0.9 * dvNoise(vec3(vUv.x * 24.0, uTime * 0.15, 1.0)), uStreaks);
|
|
558
|
+
float alpha = along * soft * streaks * smoothstep(0.0, 0.08, vUv.y) * uOpacity;
|
|
559
|
+
gl_FragColor = vec4(uColor, alpha);
|
|
560
|
+
${$e}
|
|
561
|
+
}
|
|
562
|
+
`,qh=`
|
|
563
|
+
void main() {
|
|
564
|
+
gl_Position = vec4(position.xy, 1.0, 1.0);
|
|
565
|
+
}
|
|
566
|
+
`,Gh=`
|
|
567
|
+
uniform float uTime;
|
|
568
|
+
uniform vec2 uResolution;
|
|
569
|
+
uniform float uSpeed;
|
|
570
|
+
uniform float uBlobs;
|
|
571
|
+
uniform float uVignette;
|
|
572
|
+
uniform float uGrain;
|
|
573
|
+
uniform vec3 uColor;
|
|
574
|
+
uniform vec3 uColor2;
|
|
575
|
+
uniform vec3 uColor3;
|
|
576
|
+
${qt}
|
|
577
|
+
void main() {
|
|
578
|
+
vec2 uv = gl_FragCoord.xy / uResolution;
|
|
579
|
+
vec2 p = (uv - 0.5) * vec2(uResolution.x / uResolution.y, 1.0);
|
|
580
|
+
float t = uTime * uSpeed;
|
|
581
|
+
// Two soft fields that drift past each other: a gradient that is never still.
|
|
582
|
+
float a = dvFbmLow(vec3(p * uBlobs + vec2(t * 0.3, -t * 0.2), t * 0.15));
|
|
583
|
+
float b = dvFbmLow(vec3(p * uBlobs * 0.7 - vec2(t * 0.2, t * 0.25), t * 0.1 + 5.0));
|
|
584
|
+
vec3 colour = mix(uColor2, uColor, smoothstep(0.0, 1.0, uv.y + (a - 0.5) * 0.6));
|
|
585
|
+
colour = mix(colour, uColor3, smoothstep(0.45, 0.85, b) * 0.7);
|
|
586
|
+
colour *= 1.0 - uVignette * dot(p, p);
|
|
587
|
+
// A grain of noise: without it a dark gradient shows bands.
|
|
588
|
+
colour += (dvHash(vec3(gl_FragCoord.xy, fract(uTime) * 60.0)) - 0.5) * uGrain;
|
|
589
|
+
gl_FragColor = vec4(colour, 1.0);
|
|
590
|
+
${$e}
|
|
591
|
+
}
|
|
592
|
+
`,Kh=`
|
|
593
|
+
varying vec2 vUv;
|
|
594
|
+
|
|
595
|
+
void main() {
|
|
596
|
+
vUv = uv;
|
|
597
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
598
|
+
}
|
|
599
|
+
`,Xh=`
|
|
600
|
+
uniform float uTime;
|
|
601
|
+
uniform vec3 uColor;
|
|
602
|
+
varying vec2 vUv;
|
|
603
|
+
|
|
604
|
+
void main() {
|
|
605
|
+
float wave = 0.5 + 0.5 * sin(vUv.x * 12.0 + uTime * 2.0);
|
|
606
|
+
gl_FragColor = vec4(uColor * wave, 1.0);
|
|
607
|
+
${$e}
|
|
608
|
+
}
|
|
609
|
+
`,wt=(e,t,n,r,o,i)=>({geometry:"sprites",count:n,vertex:e,fragment:t,uniforms:i,blending:r,transparent:!0,depthTest:!0,depthWrite:!1,side:"double",volume:!1,scale:o}),Bt=(e,t,n,r)=>wt(Oh,ni,e,t,n,{uSize:.03,uSizeRandom:.6,uSpeed:.03,uTurbulence:1,uTwinkle:0,uStretch:0,uDirection:[0,1,0],uColor:"#ffffff",uColor2:"#ffffff",uOpacity:.6,uSoftness:.8,...r}),Ht=(e,t)=>({geometry:"box",count:0,vertex:_h,fragment:Ih,uniforms:{uSteps:32,uDensity:1,uCoverage:.5,uScale:3,uDetail:.6,uEdge:.2,uBottom:.15,uTop:.35,uAbsorption:9,uPowder:.6,uSilver:.5,uOpacity:1,uWind:[.03,0,.01],uLightDir:[.4,.8,.3],uLightColor:"#ffffff",uShadowColor:"#6f7f97",...t},blending:"normal",transparent:!0,depthTest:!0,depthWrite:!1,side:"front",volume:!0,scale:e}),Ut=(e,t,n,r,o,i,s={})=>({geometry:e,count:0,vertex:t,fragment:n,uniforms:o,blending:"additive",transparent:!0,depthTest:!0,depthWrite:!1,side:"double",volume:!1,scale:r,controls:i,...s}),V=(e,t,n,r)=>({uniform:e,min:t,max:n,about:r}),si={particles:{dust:Bt(600,"additive",[1.6,1.2,1.6],{uSize:.008,uSpeed:.012,uOpacity:.45,uTwinkle:.5,uColor:"#fff4dc",uColor2:"#ffffff"}),snow:Bt(1500,"normal",[2.2,1.6,2.2],{uSize:.012,uSpeed:.09,uDirection:[.15,-1,0],uTurbulence:1.6,uOpacity:.85,uSoftness:.6}),embers:Bt(300,"additive",[.8,1.2,.8],{uSize:.01,uSpeed:.12,uTurbulence:2.2,uTwinkle:.7,uOpacity:.9,uColor:"#ff7a1a",uColor2:"#ffd27a",uSoftness:1}),fireflies:Bt(80,"additive",[1.6,.8,1.6],{uSize:.016,uSpeed:.01,uTurbulence:3,uTwinkle:1,uOpacity:.9,uColor:"#d8ff7a",uColor2:"#fff2a8",uSoftness:1}),rain:Bt(2500,"normal",[2.2,1.6,2.2],{uSize:.004,uSizeRandom:.2,uSpeed:1.4,uDirection:[.08,-1,0],uTurbulence:0,uStretch:14,uOpacity:.35,uColor:"#b9c7d6",uColor2:"#e4ecf5",uSoftness:.5}),stars:Bt(3e3,"additive",[12,12,12],{uSize:.04,uSpeed:0,uTurbulence:0,uTwinkle:.6,uOpacity:.9,uColor:"#cfdcff",uColor2:"#fff1d6",uSoftness:1}),galaxy:{...wt(Fh,ni,6e3,"additive",[1.6,1.6,1.6],{uSize:.008,uArms:3,uTwist:9,uSpin:.08,uThickness:.12,uColor:"#ffd9a8",uColor2:"#5f8bff",uOpacity:.8,uSoftness:1}),controls:[V("uSize",.002,.2,"sprite size in scene units"),V("uArms",1,8,"spiral arms"),V("uTwist",0,30,"how tightly the arms wind"),V("uSpin",-1,1,"turns per second at the centre"),V("uThickness",0,.6,"height of the disc"),V("uOpacity",0,1,"additive: the dense core adds up fast")]},swarm:{...wt(Vh,ni,8e3,"additive",[.9,.9,.9],{uSize:.006,uShape:0,uFlow:1,uSpin:.15,uColor:"#7fd4ff",uColor2:"#ffffff",uOpacity:.7,uSoftness:1}),controls:[V("uSize",.002,.2,"sprite size in scene units"),V("uShape",0,3,"0 sphere, 1 ring, 2 box, 3 sphere again; in between it flows from one to the next"),V("uFlow",0,4,"how much the sprites wander on the shape"),V("uSpin",-2,2,"turns of the whole swarm"),V("uOpacity",0,1,"overall")]}},shader:{water:Ut("plane",Dh,Nh,[3,1,3],{uWaveScale:2.2,uWaveHeight:.35,uSpeed:.8,uGloss:180,uOpacity:.82,uDeep:"#0a2f44",uShallow:"#1f6f7f",uSky:"#a9c4d8",uLightDir:[.4,.6,.5],uLightColor:"#fff2d6"},[V("uWaveScale",.2,12,"waves per scene unit: higher means smaller waves"),V("uWaveHeight",0,1.5,"0 a mirror, 1 a choppy sea"),V("uSpeed",0,3,"how fast the swell travels"),V("uGloss",20,600,"tightness of the sun glint"),V("uOpacity",0,1,"looking straight down; the surface is always solid at a glancing angle")],{blending:"normal"}),aurora:Ut("plane",zh,Wh,[4,1.6,1],{uSpeed:.25,uBands:3,uRays:.7,uOpacity:.7,uColor:"#3dffa2",uColor2:"#b04dff"},[V("uSpeed",0,2,"how fast the curtain moves"),V("uBands",.5,10,"folds along the curtain"),V("uRays",0,1,"how strongly it breaks into vertical rays"),V("uOpacity",0,1,"additive: over 0.8 burns white")]),hologram:Ut("sphere",ti,Bh,[.7,.7,.7],{uLines:40,uSpeed:.6,uRim:2.2,uFlicker:.5,uOpacity:.8,uColor:"#4fd8ff"},[V("uLines",4,200,"scan lines across the object"),V("uSpeed",-4,4,"how fast the lines travel"),V("uRim",.5,6,"higher keeps the glow to the very edge"),V("uFlicker",0,1,"unsteadiness"),V("uOpacity",0,1,"overall")]),shield:Ut("sphere",ti,Hh,[1,1,1],{uCells:6,uPulse:.2,uRim:3,uOpacity:.7,uColor:"#38b6ff",uColor2:"#e8fbff"},[V("uCells",1,30,"hexagons around the sphere"),V("uPulse",0,2,"speed of the travelling ring"),V("uRim",.5,6,"higher keeps the glow to the very edge"),V("uOpacity",0,1,"overall")]),"light-shaft":Ut("cone",ti,Uh,[.7,1.6,.7],{uStreaks:.6,uFalloff:1.6,uEdge:1.5,uOpacity:.28,uColor:"#fff1cf"},[V("uStreaks",0,1,"dusty streaks inside the beam"),V("uFalloff",.3,5,"how quickly the beam dies away from the lamp"),V("uEdge",.3,5,"softness of the sides"),V("uOpacity",0,1,"a beam is faint: 0.1 to 0.4")]),backdrop:Ut("screen",qh,Gh,[1,1,1],{uSpeed:.15,uBlobs:1.4,uVignette:.5,uGrain:.006,uColor:"#1c2a5e",uColor2:"#05060b",uColor3:"#5a2f8a"},[V("uSpeed",0,2,"how fast the colours drift"),V("uBlobs",.3,6,"higher means smaller patches of colour"),V("uVignette",0,1.5,"darkening towards the corners"),V("uGrain",0,.05,"film grain; also hides banding. Keep it under 0.015")],{blending:"normal",transparent:!1,side:"front"})},smoke:{smoke:wt(kr,Er,90,"normal",[.35,.9,.35],{uSize:.2,uSoftEdge:.12,uSpeed:.12,uSpread:.5,uTurbulence:1,uWind:[.15,0,0],uColor:"#5a5a5e",uColor2:"#b9bcc2",uOpacity:.35,uDetail:.8}),steam:wt(kr,Er,50,"normal",[.2,.5,.2],{uSize:.1,uSoftEdge:.06,uSpeed:.22,uSpread:.35,uTurbulence:1.4,uWind:[0,0,0],uColor:"#f2f4f7",uColor2:"#ffffff",uOpacity:.22,uDetail:.6}),"ground-mist":wt(kr,Er,70,"normal",[2,.2,2],{uSize:.6,uSoftEdge:.15,uSpeed:.04,uSpread:1.6,uTurbulence:.6,uWind:[.3,0,.1],uColor:"#c9d2dc",uColor2:"#e7ecf2",uOpacity:.16,uDetail:.5}),fire:wt(kr,Er,80,"additive",[.2,.45,.2],{uSize:.12,uSoftEdge:.06,uSpeed:.55,uSpread:.3,uTurbulence:1.2,uWind:[0,0,0],uColor:"#ffb347",uColor2:"#c2260a",uOpacity:.5,uDetail:.9})},clouds:{cumulus:Ht([1.6,.7,1.6],{}),overcast:Ht([2.6,.5,2.6],{uCoverage:.75,uDensity:1.3,uPowder:.3,uSilver:.2,uLightColor:"#dfe5ee",uShadowColor:"#59626f"}),wisps:Ht([2,.45,2],{uCoverage:.38,uDensity:.6,uScale:4.5,uDetail:.9,uAbsorption:6}),sunset:Ht([1.8,.7,1.8],{uLightDir:[.9,.25,.2],uLightColor:"#ffb27a",uShadowColor:"#5b4a78",uSilver:1})},fog:{"ground-fog":Ht([3,.35,3],{uSteps:20,uCoverage:.9,uDensity:.35,uScale:2,uDetail:.2,uBottom:.02,uTop:.9,uAbsorption:5,uPowder:0,uSilver:.1,uLightColor:"#dfe6ee",uShadowColor:"#aab4c0",uWind:[.05,0,.02]}),haze:Ht([3,1.5,3],{uSteps:16,uCoverage:1,uDensity:.12,uScale:1.2,uDetail:0,uBottom:.05,uTop:.6,uAbsorption:4,uPowder:0,uSilver:.6,uLightColor:"#fff3df",uShadowColor:"#c8cfd8"})}},ri={particles:[{uniform:"uSize",min:.002,max:.2,about:"sprite size in scene units"},{uniform:"uSizeRandom",min:0,max:1,about:"0 all the same size, 1 mixed"},{uniform:"uSpeed",min:0,max:3,about:"boxes travelled per second along uDirection"},{uniform:"uTurbulence",min:0,max:4,about:"sideways wander"},{uniform:"uTwinkle",min:0,max:1,about:"how much each sprite blinks"},{uniform:"uStretch",min:0,max:30,about:"length along the direction (rain, sparks)"},{uniform:"uOpacity",min:0,max:1,about:"over 0.6 with additive blending burns white"},{uniform:"uSoftness",min:0,max:1,about:"0 a hard disc, 1 a soft glow"}],smoke:[{uniform:"uSize",min:.02,max:3,about:"puff size in scene units; it grows as it rises"},{uniform:"uSpeed",min:.01,max:1,about:"lifetimes per second"},{uniform:"uSpread",min:0,max:2,about:"how wide the column opens"},{uniform:"uTurbulence",min:0,max:3,about:"sideways curl"},{uniform:"uOpacity",min:0,max:1,about:"puffs overlap: 0.15 to 0.4 is plenty"},{uniform:"uDetail",min:0,max:1,about:"how ragged the edge of a puff is"},{uniform:"uSoftEdge",min:0,max:2,about:"distance in scene units over which a puff fades into a surface it touches"}],clouds:[{uniform:"uSteps",min:8,max:96,about:"samples per ray: the main cost. 24 to 40"},{uniform:"uDensity",min:0,max:3,about:"how thick"},{uniform:"uCoverage",min:0,max:1,about:"0 clear sky, 1 solid"},{uniform:"uScale",min:.5,max:10,about:"noise frequency: higher means smaller puffs"},{uniform:"uDetail",min:0,max:1,about:"fine erosion of the edges"},{uniform:"uEdge",min:.02,max:.5,about:"fade towards the sides of the box"},{uniform:"uBottom",min:0,max:1,about:"fade at the bottom (0 a flat base)"},{uniform:"uTop",min:0,max:1,about:"fade at the top"},{uniform:"uAbsorption",min:1,max:30,about:"how fast light dies inside"},{uniform:"uPowder",min:0,max:1,about:"dark creases between the billows"},{uniform:"uSilver",min:0,max:2,about:"glow on thin edges towards the light"},{uniform:"uOpacity",min:0,max:1,about:"overall"}],fog:[],shader:[]};ri.fog=ri.clouds;var Pr=["particles","smoke","clouds","fog","shader","custom"];function Jh(e){return e==="custom"?[]:Object.keys(si[e])}function ai(e,t){if(e==="custom")return[];let n=si[e];return n[t??Object.keys(n)[0]]?.controls??ri[e]}function Ml(){return Pr.map(e=>({kind:e,presets:Jh(e).map(t=>({preset:t,uniforms:ai(e,t)}))}))}var Yh=/^#[0-9a-fA-F]{6}$/,Qh=/^[A-Za-z_][A-Za-z0-9_]{0,47}$/;function li(e){return ce(e)?/^(scene:[\w-]{1,64}|file:[^\0]{1,400})$/.test(e.texture):typeof e=="number"?Number.isFinite(e):typeof e=="string"?Yh.test(e):Array.isArray(e)&&e.length>=2&&e.length<=4&&e.every(t=>typeof t=="number"&&Number.isFinite(t))}var Tr=e=>ce(e)?"a texture":typeof e=="number"?"a number":typeof e=="string"?'a colour "#rrggbb"':`${e.length} numbers`;function oi(e,t,n){let r={};for(let[o,i]of Object.entries(t)){if(!Qh.test(o))throw new Error(`"${o}" is not a uniform name.`);if(o in Vn)throw new Error(`${o} is filled in by the page every frame and cannot be set.`);if(!li(i))throw new Error(`${o}: a uniform is a number, 2 to 4 numbers, a colour as "#rrggbb", or a texture as { "texture": "scene:<uuid>" } or { "texture": "file:<path in the project>" }.`);let s=e.uniforms[o];if(s===void 0){if(!n)throw new Error(`This effect has no uniform ${o}. It has: ${Object.keys(e.uniforms).join(", ")}.`)}else if(ce(s)||ce(i)){if(!(ce(s)&&ce(i)))throw new Error(`${o} is ${Tr(s)}, not ${Tr(i)}.`)}else if(typeof s!=typeof i||Array.isArray(s)&&Array.isArray(i)&&s.length!==i.length){let a=l=>typeof l=="string"||Array.isArray(l)&&l.length===3;if(!(a(s)&&a(i)))throw new Error(`${o} is ${Tr(s)}, not ${Tr(i)}.`)}r[o]=i}return r}var ii=e=>Math.min($h,Math.max(1,Math.round(e)));function Cr(e,t){let n=Number.isFinite(t)&&t>0?t:1,r=e.position??[0,0,0];if(e.kind==="custom"){let f=e.geometry??"plane",d={kind:"custom",preset:null,name:e.name??"Custom effect",geometry:f,count:f==="sprites"?ii(e.count??500):0,vertex:e.vertex??Kh,fragment:e.fragment??Xh,uniforms:e.vertex||e.fragment?{}:{uColor:"#4f8cff"},blending:e.blending??"normal",transparent:e.transparent??!1,depthTest:e.depthTest??f!=="screen",depthWrite:e.depthWrite??!(e.transparent??!1),side:e.side??"double",volume:!1,position:r,scale:e.scale??[n,n,n]};return Rr(d.vertex,"vertex"),Rr(d.fragment,"fragment"),Object.assign(d.uniforms,oi(d,e.uniforms??{},!0)),d}let o=si[e.kind];if(!o)throw new Error(`Unknown effect kind "${String(e.kind)}".`);let i=e.preset??Object.keys(o)[0],s=o[i];if(!s)throw new Error(`${e.kind} has no preset "${i}". It has: ${Object.keys(o).join(", ")}.`);let a={...s.uniforms};for(let f of["uSize","uSoftEdge"])typeof a[f]=="number"&&(a[f]=xt(a[f]*n));let{controls:l,...c}=s,u={...c,uniforms:a,kind:e.kind,preset:i,name:e.name??`${i[0].toUpperCase()}${i.slice(1)}`,count:s.geometry==="sprites"?ii(e.count??s.count):0,position:r,scale:e.scale??s.scale.map(f=>xt(f*n))};return Object.assign(u.uniforms,oi(u,e.uniforms??{},!1)),u}function Rr(e,t){if(e.length>yl)throw new Error(`The ${t} shader is over ${yl} characters.`);if(!/void\s+main\s*\(/.test(e))throw new Error(`The ${t} shader has no main().`);if(/^\s*#version/m.test(e))throw new Error(`Leave #version out of the ${t} shader: three.js adds it, with the declarations of position, uv, the matrices and cameraPosition.`)}function kl(e,t){let n={...e,uniforms:{...e.uniforms}};if((t.vertex!==void 0||t.fragment!==void 0)&&(t.vertex!==void 0&&(Rr(t.vertex,"vertex"),n.vertex=t.vertex),t.fragment!==void 0&&(Rr(t.fragment,"fragment"),n.fragment=t.fragment),n.kind="custom"),t.uniforms&&Object.assign(n.uniforms,oi(n,t.uniforms,n.kind==="custom")),t.count!==void 0){if(n.geometry!=="sprites")throw new Error("Only a sprite effect has a count.");n.count=ii(t.count)}return t.blending&&(n.blending=t.blending),t.name&&(n.name=t.name),n}function El(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let n=t;return n=Math.imul(n^n>>>15,n|1),n^=n+Math.imul(n^n>>>7,n|61),((n^n>>>14)>>>0)/4294967296}}var vl=[-1,-1,1,-1,1,1,-1,-1,1,1,-1,1];function Zh(e){let t=El(e*7919+1),n=new Float32Array(e*18),r=new Float32Array(e*12),o=new Float32Array(e*24);for(let i=0;i<e;i++){let s=t()-.5,a=t()-.5,l=t()-.5,c=[t(),t(),t(),t()];for(let u=0;u<6;u++)n.set([s,a,l],i*18+u*3),r.set([vl[u*2],vl[u*2+1]],i*12+u*2),o.set(c,i*24+u*4)}return{position:n,corner:r,seed:o}}function ed(e){let t=[],n=[],r=[],o=(i,s,a,l,c)=>{for(let[u,f]of[[i,[0,0]],[s,[1,0]],[a,[1,1]],[i,[0,0]],[a,[1,1]],[l,[0,1]]])t.push(...u),n.push(...c),r.push(...f)};if(e==="screen")t.push(-1,-1,0,3,-1,0,-1,3,0),n.push(0,0,1,0,0,1,0,0,1),r.push(0,0,2,0,0,2);else if(e==="plane")o([-.5,-.5,0],[.5,-.5,0],[.5,.5,0],[-.5,.5,0],[0,0,1]);else if(e==="cone")for(let s=0;s<40;s++){let a=s/40*Math.PI*2,l=(s+1)/40*Math.PI*2,c=d=>[Math.cos(d)*.5,-.5,Math.sin(d)*.5],u=d=>[Math.cos(d)*.894,.447,Math.sin(d)*.894],f=(a+l)/2;t.push(0,.5,0,...c(l),...c(a)),n.push(...u(f),...u(l),...u(a)),r.push((s+.5)/40,1,(s+1)/40,0,s/40,0)}else if(e==="box")o([-.5,-.5,.5],[.5,-.5,.5],[.5,.5,.5],[-.5,.5,.5],[0,0,1]),o([.5,-.5,-.5],[-.5,-.5,-.5],[-.5,.5,-.5],[.5,.5,-.5],[0,0,-1]),o([.5,-.5,.5],[.5,-.5,-.5],[.5,.5,-.5],[.5,.5,.5],[1,0,0]),o([-.5,-.5,-.5],[-.5,-.5,.5],[-.5,.5,.5],[-.5,.5,-.5],[-1,0,0]),o([-.5,.5,.5],[.5,.5,.5],[.5,.5,-.5],[-.5,.5,-.5],[0,1,0]),o([-.5,-.5,-.5],[.5,-.5,-.5],[.5,-.5,.5],[-.5,-.5,.5],[0,-1,0]);else{let a=(c,u)=>{let f=c/24*Math.PI,d=u/36*Math.PI*2;return{p:[-.5*Math.cos(d)*Math.sin(f),.5*Math.cos(f),.5*Math.sin(d)*Math.sin(f)],t:[u/36,1-c/24]}},l=c=>{t.push(...c.p),n.push(c.p[0]*2,c.p[1]*2,c.p[2]*2),r.push(...c.t)};for(let c=0;c<24;c++)for(let u=0;u<36;u++){let f=a(c,u),d=a(c+1,u),p=a(c+1,u+1),m=a(c,u+1);c!==0&&[f,m,d].forEach(l),c!==23&&[m,p,d].forEach(l)}}return{position:new Float32Array(t),normal:new Float32Array(n),uv:new Float32Array(r)}}function Tl(e){return e.geometry==="sprites"?Zh(e.count):ed(e.geometry)}var td=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4);function ci(e){if(ce(e))return null;if(typeof e!="string")return e;let t=parseInt(e.slice(1),16);return[t>>16&255,t>>8&255,t&255].map(n=>td(n/255))}function Rl(e){return e.replace(/#include\s+<(colorspace_fragment|encodings_fragment)>/g,"gl_FragColor = linearToOutputTexel( gl_FragColor );")}function xt(e,t=4){let n=10**t;return Math.round(e*n)/n}var nd=e=>{let n=e.replace(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(Boolean).map(r=>r[0].toUpperCase()+r.slice(1)).join("");return/^[A-Za-z]/.test(n)?n:`Effect${n}`};function rd(e){if(ce(e)){let[n,...r]=e.texture.split(":"),o=r.join(":");return n==="file"?`new THREE.TextureLoader().load('/${o.replace(/^(\.\/)?(public\/)?/,"")}')`:`null /* the texture with id ${o} on the page: load the same image here */`}if(typeof e=="number")return String(xt(e,5));if(typeof e=="string")return`new THREE.Color('${e}')`;let t=e.map(n=>xt(n,5)).join(", ");return`new THREE.Vector${e.length}(${t})`}function ie(e,t){let n=new RegExp(`\\buniform\\s+\\w+\\s+${t}\\b`);return n.test(e.vertex)||n.test(e.fragment)}function od(e,t){let n=[];ie(e,"uTime")&&n.push("uTime: { value: 0 },"),ie(e,"uResolution")&&n.push("uResolution: { value: new THREE.Vector2(1, 1) },"),(ie(e,"uCameraLocal")||e.volume)&&n.push("uCameraLocal: { value: new THREE.Vector3() },"),ie(e,"uNoise")&&n.push("uNoise: { value: noiseTexture() },"),ie(e,"uDepth")&&n.push("uDepth: { value: null as THREE.Texture | null },","uHasDepth: { value: 0 },",...ie(e,"uDepthToLocal")?["uDepthToLocal: { value: new THREE.Matrix4() },"]:[]);for(let[r,o]of Object.entries(e.uniforms))n.push(`${r}: { value: ${rd(o)} },`);return n.map(r=>t+r).join(`
|
|
610
|
+
`)}var id={box:"new THREE.BoxGeometry(1, 1, 1)",plane:"new THREE.PlaneGeometry(1, 1)",sphere:"new THREE.SphereGeometry(0.5, 36, 24)",cone:"new THREE.ConeGeometry(0.5, 1, 40, 1, true)",screen:`new THREE.BufferGeometry()
|
|
611
|
+
.setAttribute('position', new THREE.Float32BufferAttribute([-1, -1, 0, 3, -1, 0, -1, 3, 0], 3))
|
|
612
|
+
.setAttribute('uv', new THREE.Float32BufferAttribute([0, 0, 2, 0, 0, 2], 2))`},sd=`/** Two triangles per sprite, each with its corner and four random numbers. */
|
|
613
|
+
function spriteGeometry(count: number): THREE.BufferGeometry {
|
|
614
|
+
let a = (count * 7919 + 1) >>> 0;
|
|
615
|
+
const random = (): number => {
|
|
616
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
617
|
+
let t = a;
|
|
618
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
619
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
620
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
621
|
+
};
|
|
622
|
+
const corners = [-1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1];
|
|
623
|
+
const position = new Float32Array(count * 18);
|
|
624
|
+
const corner = new Float32Array(count * 12);
|
|
625
|
+
const seed = new Float32Array(count * 24);
|
|
626
|
+
for (let i = 0; i < count; i++) {
|
|
627
|
+
const p = [random() - 0.5, random() - 0.5, random() - 0.5];
|
|
628
|
+
const s = [random(), random(), random(), random()];
|
|
629
|
+
for (let v = 0; v < 6; v++) {
|
|
630
|
+
position.set(p, i * 18 + v * 3);
|
|
631
|
+
corner.set([corners[v * 2]!, corners[v * 2 + 1]!], i * 12 + v * 2);
|
|
632
|
+
seed.set(s, i * 24 + v * 4);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
const geometry = new THREE.BufferGeometry();
|
|
636
|
+
geometry.setAttribute('position', new THREE.BufferAttribute(position, 3));
|
|
637
|
+
geometry.setAttribute('dvCorner', new THREE.BufferAttribute(corner, 2));
|
|
638
|
+
geometry.setAttribute('dvSeed', new THREE.BufferAttribute(seed, 4));
|
|
639
|
+
return geometry;
|
|
640
|
+
}
|
|
641
|
+
`,ad={front:"THREE.FrontSide",back:"THREE.BackSide",double:"THREE.DoubleSide"},wl=e=>`[${e.map(t=>xt(t,4)).join(", ")}]`;function xl(e,t,n,r){let o=[];if(ie(e,"uTime")&&o.push("material.uniforms.uTime.value = elapsed;"),ie(e,"uResolution")&&o.push(`material.uniforms.uResolution.value.copy(${r});`),ie(e,"uCameraLocal")||e.volume){let i=`${t}.worldToLocal(material.uniforms.uCameraLocal.value.copy(${n}.position))`;o.push(e.volume?`const local = ${i};`:`${i};`),e.volume&&o.push("// Inside the box the front faces are behind the camera: draw the back faces instead,","// without a depth test, or a floor in front of the far side would cut the volume away.","const inside = Math.max(Math.abs(local.x), Math.abs(local.y), Math.abs(local.z)) < 0.5;","const side = inside ? THREE.BackSide : THREE.FrontSide;","if (material.side !== side) {"," material.side = side;",` material.depthTest = inside ? false : ${e.depthTest};`," material.needsUpdate = true;","}")}return ie(e,"uDepth")&&(o.push("// With the depth of the solid scene the effect meets objects softly instead of cutting","// through them. Without it (no depth given) it draws as before.","material.uniforms.uDepth.value = depth ?? null;","material.uniforms.uHasDepth.value = depth ? 1 : 0;"),ie(e,"uDepthToLocal")&&o.push("if (depth) {"," const toLocal = material.uniforms.uDepthToLocal.value as THREE.Matrix4;",` toLocal.multiplyMatrices(${n}.projectionMatrix, ${n}.matrixWorldInverse).invert();`,` toLocal.premultiply(inverseWorld.copy(${t}.matrixWorld).invert());`,...e.volume?[" // The march now stops at solid objects by itself: draw the far faces, untested."," if (material.side !== THREE.BackSide || material.depthTest) {"," material.side = THREE.BackSide;"," material.depthTest = false;"," material.needsUpdate = true;"," }"]:[],"}")),o}var ld=`/** 256 x 256 tiling noise; green is red moved by (37, 17), so one read gives 3D noise. */
|
|
642
|
+
function noiseTexture(): THREE.DataTexture {
|
|
643
|
+
const size = 256;
|
|
644
|
+
let a = 20240229 >>> 0;
|
|
645
|
+
const random = (): number => {
|
|
646
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
647
|
+
let t = a;
|
|
648
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
649
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
650
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
651
|
+
};
|
|
652
|
+
const data = new Uint8Array(size * size * 4);
|
|
653
|
+
for (let i = 0; i < size * size; i++) {
|
|
654
|
+
data[i * 4] = Math.floor(random() * 256);
|
|
655
|
+
data[i * 4 + 2] = Math.floor(random() * 256);
|
|
656
|
+
data[i * 4 + 3] = 255;
|
|
657
|
+
}
|
|
658
|
+
for (let y = 0; y < size; y++)
|
|
659
|
+
for (let x = 0; x < size; x++) {
|
|
660
|
+
const from = ((y - 17 + size) % size) * size + ((x - 37 + size) % size);
|
|
661
|
+
data[(y * size + x) * 4 + 1] = data[from * 4]!;
|
|
662
|
+
}
|
|
663
|
+
const texture = new THREE.DataTexture(data, size, size, THREE.RGBAFormat);
|
|
664
|
+
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
|
665
|
+
texture.minFilter = texture.magFilter = THREE.LinearFilter;
|
|
666
|
+
texture.needsUpdate = true;
|
|
667
|
+
return texture;
|
|
668
|
+
}
|
|
669
|
+
`;function Al(){let e=Ar,t=El(20240229),n=new Uint8Array(e*e*4);for(let r=0;r<e*e;r++)n[r*4]=Math.floor(t()*256),n[r*4+2]=Math.floor(t()*256),n[r*4+3]=255;for(let r=0;r<e;r++)for(let o=0;o<e;o++){let i=(r-17+e)%e*e+(o-37+e)%e;n[(r*e+o)*4+1]=n[i*4]}return n}function Sl(e){return`new THREE.ShaderMaterial({
|
|
670
|
+
vertexShader,
|
|
671
|
+
fragmentShader,
|
|
672
|
+
uniforms: {
|
|
673
|
+
${od(e," ")}
|
|
674
|
+
},
|
|
675
|
+
transparent: ${e.transparent},
|
|
676
|
+
depthTest: ${e.depthTest},
|
|
677
|
+
depthWrite: ${e.depthWrite},
|
|
678
|
+
blending: ${e.blending==="additive"?"THREE.AdditiveBlending":"THREE.NormalBlending"},
|
|
679
|
+
side: ${ad[e.side]},
|
|
680
|
+
})`}function Pl(e,t){let n=nd(e.name),r=e.geometry==="sprites"?`spriteGeometry(${e.count})`:id[e.geometry],o=`const vertexShader = /* glsl */ \`${e.vertex}\`;
|
|
681
|
+
|
|
682
|
+
const fragmentShader = /* glsl */ \`${e.fragment}\`;
|
|
683
|
+
`,i=ie(e,"uDepth"),s=(e.geometry==="sprites"?`
|
|
684
|
+
${sd}`:"")+(ie(e,"uNoise")?`
|
|
685
|
+
${ld}`:"")+(i&&ie(e,"uDepthToLocal")?`
|
|
686
|
+
const inverseWorld = new THREE.Matrix4();
|
|
687
|
+
`:"");if(t==="r3f"){let c=xl(e,"mesh","state.camera","state.gl.getDrawingBufferSize(size)"),u=ie(e,"uResolution");return`import { useMemo, useRef } from 'react';
|
|
688
|
+
import { useFrame } from '@react-three/fiber';
|
|
689
|
+
import * as THREE from 'three';
|
|
690
|
+
|
|
691
|
+
${o}${s}
|
|
692
|
+
${u?`const size = new THREE.Vector2();
|
|
693
|
+
|
|
694
|
+
`:""}${i?"/**\n * `depth`: the depth texture of the solid scene, e.g. `useDepthBuffer()` from\n * @react-three/drei, at the size of the canvas. Without it the effect ignores what it touches.\n */\n":""}export function ${n}({${i?" depth,":""} ...props }: JSX.IntrinsicElements['mesh']${i?" & { depth?: THREE.Texture }":""}) {
|
|
695
|
+
const ref = useRef<THREE.Mesh>(null);
|
|
696
|
+
const geometry = useMemo(() => ${r}, []);
|
|
697
|
+
const material = useMemo(
|
|
698
|
+
() =>
|
|
699
|
+
${Sl(e).replace(/\n/g,`
|
|
700
|
+
`)},
|
|
701
|
+
[],
|
|
702
|
+
);
|
|
703
|
+
${c.length?` useFrame((state) => {
|
|
704
|
+
const mesh = ref.current;
|
|
705
|
+
if (!mesh) return;
|
|
706
|
+
const elapsed = state.clock.elapsedTime;
|
|
707
|
+
${c.join(`
|
|
708
|
+
`)}
|
|
709
|
+
});
|
|
710
|
+
`:""} return (
|
|
711
|
+
<mesh
|
|
712
|
+
ref={ref}
|
|
713
|
+
name="${e.name}"
|
|
714
|
+
geometry={geometry}
|
|
715
|
+
material={material}
|
|
716
|
+
position={${wl(e.position)}}
|
|
717
|
+
scale={${wl(e.scale)}}
|
|
718
|
+
frustumCulled={false}
|
|
719
|
+
{...props}
|
|
720
|
+
/>
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
`}let a=xl(e,"mesh","camera","renderer.getDrawingBufferSize(size)"),l=ie(e,"uResolution");return`import * as THREE from 'three';
|
|
724
|
+
|
|
725
|
+
${o}${s}
|
|
726
|
+
/**
|
|
727
|
+
* Add the returned mesh to the scene, and call update(elapsedSeconds) every frame.${i?`
|
|
728
|
+
* Pass the depth texture of the solid scene (a render target's depthTexture, at the size of
|
|
729
|
+
* the canvas) as the second argument: without it the effect ignores what it touches.`:""}
|
|
730
|
+
*/
|
|
731
|
+
export function create${n}(camera: THREE.Camera${l?", renderer: THREE.WebGLRenderer":""}) {
|
|
732
|
+
const material = ${Sl(e).replace(/\n/g,`
|
|
733
|
+
`)};
|
|
734
|
+
const mesh = new THREE.Mesh(${r}, material);
|
|
735
|
+
mesh.name = '${e.name}';
|
|
736
|
+
mesh.position.set(${e.position.map(c=>xt(c,4)).join(", ")});
|
|
737
|
+
mesh.scale.set(${e.scale.map(c=>xt(c,4)).join(", ")});
|
|
738
|
+
mesh.frustumCulled = false;
|
|
739
|
+
${l?` const size = new THREE.Vector2();
|
|
740
|
+
`:""} const update = (elapsed: number${i?", depth?: THREE.Texture":""}): void => {
|
|
741
|
+
${a.length?a.join(`
|
|
742
|
+
`):"void elapsed;"}
|
|
743
|
+
};
|
|
744
|
+
return { mesh, update };
|
|
745
|
+
}
|
|
746
|
+
`}var fi=new WeakMap;function cd(e){return[{internal:e.DEPTH24_STENCIL8,format:e.DEPTH_STENCIL,type:e.UNSIGNED_INT_24_8,attachment:e.DEPTH_STENCIL_ATTACHMENT},{internal:e.DEPTH_COMPONENT24,format:e.DEPTH_COMPONENT,type:e.UNSIGNED_INT,attachment:e.DEPTH_ATTACHMENT},{internal:e.DEPTH_COMPONENT16,format:e.DEPTH_COMPONENT,type:e.UNSIGNED_SHORT,attachment:e.DEPTH_ATTACHMENT},{internal:e.DEPTH_COMPONENT32F,format:e.DEPTH_COMPONENT,type:e.FLOAT,attachment:e.DEPTH_ATTACHMENT},{internal:e.DEPTH32F_STENCIL8,format:e.DEPTH_STENCIL,type:e.FLOAT_32_UNSIGNED_INT_24_8_REV,attachment:e.DEPTH_STENCIL_ATTACHMENT}]}var ui=-1;function Cl(e){let t=e.getContext?.();if(typeof WebGL2RenderingContext>"u"||!(t instanceof WebGL2RenderingContext))return null;let n=e.capabilities;if(n?.logarithmicDepthBuffer===!0||n?.reversedDepthBuffer===!0)return null;let r=fi.get(e);r||(r={texture:null,framebuffer:null,width:0,height:0,formats:new Map,current:ui,frame:-1,source:null,ok:!1},fi.set(e,r));let o=e.info?.render,i=Number(o?.frame??0),s=t.getParameter(t.DRAW_FRAMEBUFFER_BINDING),a=()=>r.ok&&r.texture?{texture:r.texture,width:r.width,height:r.height}:null;if(r.frame===i&&r.source===s)return a();r.frame=i,r.source=s,r.ok=!1;let l=r.formats.get(s);if(l===ui)return null;let c=t.getParameter(t.VIEWPORT),[u,f,d,p]=[c[0],c[1],c[2],c[3]];if(d<1||p<1)return null;let m=cd(t),g=t.getParameter(t.READ_FRAMEBUFFER_BINDING),h=t.getParameter(t.TEXTURE_BINDING_2D),b=t.isEnabled(t.SCISSOR_TEST);try{b&&t.disable(t.SCISSOR_TEST),r.framebuffer??=t.createFramebuffer();let y=l!==void 0?[l]:m.map((v,x)=>x);if(l===void 0)for(;t.getError()!==t.NO_ERROR;);for(let v of y){let x=m[v];if((!r.texture||r.current!==v||r.width!==d||r.height!==p)&&(r.texture&&t.deleteTexture(r.texture),r.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,r.texture),t.texImage2D(t.TEXTURE_2D,0,x.internal,d,p,0,x.format,x.type,null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,r.framebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.TEXTURE_2D,null,0),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,null,0),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,x.attachment,t.TEXTURE_2D,r.texture,0),r.current=v,r.width=d,r.height=p),t.bindFramebuffer(t.READ_FRAMEBUFFER,s),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,r.framebuffer),t.blitFramebuffer(u,f,u+d,f+p,0,0,d,p,t.DEPTH_BUFFER_BIT,t.NEAREST),l!==void 0){r.ok=!0;break}if(t.getError()===t.NO_ERROR){r.formats.set(s,v),r.ok=!0;break}}!r.ok&&l===void 0&&r.formats.set(s,ui)}catch{r.ok=!1}finally{t.bindFramebuffer(t.READ_FRAMEBUFFER,g),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,s),t.bindTexture(t.TEXTURE_2D,h),b&&t.enable(t.SCISSOR_TEST)}return a()}var Ll=e=>fi.get(e)?.ok===!0;var mi={none:0,linear:1,reinhard:2,cineon:3,aces:4,agx:6,neutral:7},Ol={agx:160,neutral:162},ud={top:"#2b2f38",horizon:"#3c4048",ground:"#15161a",intensity:1};function Ne(){return{version:1,color:{toneMapping:"site",exposure:null},quality:{pixelRatio:null,anisotropy:!1,supersample:!1},world:{preset:"site",strength:1,rotation:0,background:!1,sky:{...ud},boxes:[]},shadows:{mode:"site",softness:3,resolution:2048},materials:[],bevel:{mode:"off",amount:.06,segments:4,targets:[]},effects:{antialias:!1,ao:{on:!1,intensity:1,radius:.5},bloom:{on:!1,strength:.15,threshold:1.1,radius:.4},dof:{on:!1,focus:8,aperture:8e-4,maxBlur:.008},vignette:0,grain:0},performance:{adaptive:!1,targetFps:60},adapt:{follow:!0,textures:!1},models:[]}}var ue=(e,t,n,r,o,i,s,a="#ffffff",l=.35)=>({id:e,name:t,azimuth:n,elevation:r,width:o,height:i,intensity:s,color:a,softness:l}),pi={studio:{label:"Studio",hint:"Dark room, three softboxes: the product-shot look for metal and glass.",sky:{top:"#1b1d22",horizon:"#2a2d34",ground:"#0c0d10",intensity:1},boxes:[ue("key","Key",-42,34,62,44,7,"#fff4e6"),ue("fill","Fill",62,12,58,70,2.2,"#dfeaff",.6),ue("rim","Rim",158,26,34,80,6,"#ffffff",.25),ue("top","Top",0,86,80,80,3,"#ffffff",.5),ue("front","Front card",0,4,150,80,1.1,"#eef1f6",1)]},softbox:{label:"Softbox",hint:"Bright, even light from all sides: clean e-commerce product.",sky:{top:"#a9adb5",horizon:"#c3c6cc",ground:"#55575c",intensity:1},boxes:[ue("top","Top",0,88,120,120,3.2,"#ffffff",.7),ue("left","Left",-75,10,70,90,2.4,"#ffffff",.6),ue("right","Right",75,10,70,90,2.4,"#ffffff",.6)]},sunset:{label:"Sunset",hint:"Low warm sun, deep blue sky.",sky:{top:"#16264d",horizon:"#e2854a",ground:"#1c1410",intensity:1.1},boxes:[ue("sun","Sun",-58,7,10,10,40,"#ffb469",.5),ue("glow","Glow",-58,6,70,30,2.5,"#ff9a5c",1),ue("sky","Sky fill",120,40,90,70,.9,"#7fa2ff",1)]},overcast:{label:"Overcast",hint:"Soft daylight with no direct sun: matte, honest materials.",sky:{top:"#c9d2dc",horizon:"#aab3bd",ground:"#3a3b3d",intensity:1.15},boxes:[ue("zenith","Sky",0,80,150,150,1.4,"#eef3ff",1)]},night:{label:"Night",hint:"Dark blue world, a cool moon and one warm accent.",sky:{top:"#050a18",horizon:"#101b33",ground:"#04050a",intensity:1},boxes:[ue("moon","Moon",-35,48,26,26,6,"#bcd4ff",.4),ue("accent","Accent",110,6,26,40,3.5,"#ff9a4a",.6),ue("rim","Rim",170,22,28,70,2.2,"#8fb4ff",.4)]}},_l={"polished-metal":{label:"Polished metal",values:{color:"#c9ccd1",metalness:1,roughness:.12,envMapIntensity:1}},"brushed-metal":{label:"Brushed metal",values:{color:"#b9bcc2",metalness:1,roughness:.38,envMapIntensity:1}},gold:{label:"Gold",values:{color:"#ffc46b",metalness:1,roughness:.2,envMapIntensity:1}},"car-paint":{label:"Car paint",values:{metalness:.6,roughness:.45,clearcoat:1,clearcoatRoughness:.04,envMapIntensity:1}},glass:{label:"Glass",values:{color:"#ffffff",metalness:0,roughness:.03,transmission:1,ior:1.5,thickness:.5,envMapIntensity:1}},plastic:{label:"Plastic",values:{metalness:0,roughness:.42,clearcoat:.3,clearcoatRoughness:.25,envMapIntensity:.9}},ceramic:{label:"Ceramic",values:{metalness:0,roughness:.22,clearcoat:1,clearcoatRoughness:.08,envMapIntensity:1}},rubber:{label:"Rubber",values:{metalness:0,roughness:.85,clearcoat:0,envMapIntensity:.6}}},q=(e,t,n,r)=>typeof e=="number"&&Number.isFinite(e)?Math.min(r,Math.max(n,e)):t,$r=(e,t)=>typeof e=="string"&&/^#[0-9a-fA-F]{6}$/.test(e)?e.toLowerCase():t,Dn=(e,t,n)=>typeof e=="string"&&t.includes(e)?e:n,Z=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{},jr=(e,t,n)=>typeof e=="number"&&Number.isFinite(e)?Math.min(n,Math.max(t,e)):void 0,fd=["site","none","linear","reinhard","cineon","aces","agx","neutral"],hd=["site","studio","softbox","sunset","overcast","night"],dd=["custom","polished-metal","brushed-metal","gold","car-paint","glass","plastic","ceramic","rubber"],md=["brushed","rings","hammered","knurl","text"],pd={brushed:60,rings:14,hammered:18,knurl:40,text:1},gd={brushed:.3,rings:.8,hammered:.55,knurl:.7,text:1};function bd(e,t){let n=Z(e);return{id:typeof n.id=="string"&&n.id?n.id.slice(0,40):`box${t+1}`,name:typeof n.name=="string"&&n.name?n.name.slice(0,40):`Light ${t+1}`,azimuth:q(n.azimuth,0,-360,360),elevation:q(n.elevation,30,-90,90),width:q(n.width,40,1,180),height:q(n.height,40,1,180),intensity:q(n.intensity,4,0,100),color:$r(n.color,"#ffffff"),softness:q(n.softness,.35,0,1)}}function yd(e){let t=Z(e),n=typeof t.name=="string"?t.name.slice(0,128):"",r=typeof t.uuid=="string"?t.uuid.slice(0,64):void 0;if(!n&&!r)return null;let o={name:n,preset:Dn(t.preset,dd,"custom")};r&&(o.uuid=r),typeof t.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(t.color)&&(o.color=t.color.toLowerCase());let i=[["metalness",0,1],["roughness",0,1],["clearcoat",0,1],["clearcoatRoughness",0,1],["transmission",0,1],["ior",1,2.333],["thickness",0,100],["envMapIntensity",0,10]];for(let[a,l,c]of i){let u=jr(t[a],l,c);u!==void 0&&(o[a]=u)}let s=Z(t.detail);return typeof s.pattern=="string"&&md.includes(s.pattern)&&(o.detail={pattern:s.pattern,strength:q(s.strength,gd[s.pattern],0,2),scale:q(s.scale,pd[s.pattern],1,200)},typeof s.text=="string"&&s.text.trim()&&(o.detail.text=s.text.slice(0,120))),o}function vd(e){let t=Z(e),n=typeof t.name=="string"?t.name.slice(0,128):"",r=typeof t.uuid=="string"?t.uuid.slice(0,64):void 0;if(!n&&!r)return null;let o=jr(t.scale,1e-4,1e4),i=jr(t.lift,-1e5,1e5),s=jr(t.reflection,0,10),a={...r?{uuid:r}:{},name:n};return o!==void 0&&Math.abs(o-1)>1e-9&&(a.scale=o),i!==void 0&&Math.abs(i)>1e-9&&(a.lift=i),s!==void 0&&Math.abs(s-1)>1e-9&&(a.reflection=s),a.scale===void 0&&a.lift===void 0&&a.reflection===void 0?null:a}function ze(e){let t=Ne(),n=Z(e),r=Z(n.color),o=Z(n.quality),i=Z(n.world),s=Z(i.sky),a=Z(n.shadows),l=Z(n.bevel),c=Z(n.effects),u=Z(c.ao),f=Z(c.bloom),d=Z(c.dof),p=Z(n.performance),m=Z(n.adapt),g=Dn(i.preset,hd,"site"),h=g==="site"?null:pi[g],b=(Array.isArray(l.targets)?l.targets:[]).map(y=>Z(y)).filter(y=>typeof y.name=="string"||typeof y.uuid=="string").slice(0,200).map(y=>({...typeof y.uuid=="string"?{uuid:y.uuid.slice(0,64)}:{},name:typeof y.name=="string"?y.name.slice(0,128):""}));return{version:1,color:{toneMapping:Dn(r.toneMapping,fd,"site"),exposure:r.exposure===null||r.exposure===void 0?null:q(r.exposure,1,0,10)},quality:{pixelRatio:o.pixelRatio===null||o.pixelRatio===void 0?null:q(o.pixelRatio,2,.5,3),anisotropy:o.anisotropy===!0,supersample:o.supersample===!0},world:{preset:g,strength:q(i.strength,1,0,10),rotation:q(i.rotation,0,-360,360),background:i.background===!0,sky:{top:$r(s.top,h?.sky.top??t.world.sky.top),horizon:$r(s.horizon,h?.sky.horizon??t.world.sky.horizon),ground:$r(s.ground,h?.sky.ground??t.world.sky.ground),intensity:q(s.intensity,h?.sky.intensity??1,0,10)},boxes:Array.isArray(i.boxes)?i.boxes.slice(0,12).map(bd):h?.boxes.map(y=>({...y}))??[]},shadows:{mode:Dn(a.mode,["site","on","off"],"site"),softness:q(a.softness,t.shadows.softness,0,10),resolution:[1024,2048,4096].includes(a.resolution)?a.resolution:t.shadows.resolution},materials:(Array.isArray(n.materials)?n.materials:[]).map(yd).filter(y=>y!==null).slice(0,200),bevel:{mode:Dn(l.mode,["off","all","selected"],"off"),amount:q(l.amount,t.bevel.amount,0,.5),segments:Math.round(q(l.segments,t.bevel.segments,1,8)),targets:b},effects:{antialias:c.antialias===!0,ao:{on:u.on===!0,intensity:q(u.intensity,t.effects.ao.intensity,0,3),radius:q(u.radius,t.effects.ao.radius,.01,5)},bloom:{on:f.on===!0,strength:q(f.strength,t.effects.bloom.strength,0,3),threshold:q(f.threshold,t.effects.bloom.threshold,0,5),radius:q(f.radius,t.effects.bloom.radius,0,1)},dof:{on:d.on===!0,focus:q(d.focus,t.effects.dof.focus,.01,1e4),aperture:q(d.aperture,t.effects.dof.aperture,0,.01),maxBlur:q(d.maxBlur,t.effects.dof.maxBlur,0,.05)},vignette:q(c.vignette,0,0,1),grain:q(c.grain,0,0,1)},performance:{adaptive:p.adaptive===!0,targetFps:[30,45,60].includes(p.targetFps)?p.targetFps:60},adapt:{follow:m.follow!==!1,textures:m.textures===!0},models:(Array.isArray(n.models)?n.models:[]).map(vd).filter(y=>y!==null).slice(0,200)}}function Xt(e,t){let n=Z(t),r={...e};for(let o of["color","quality","world","shadows","bevel","effects","performance","adapt"]){if(n[o]===void 0)continue;let i=Z(n[o]),s=e[o],a={...s};for(let[l,c]of Object.entries(i)){let u=s[l];a[l]=u&&typeof u=="object"&&!Array.isArray(u)&&c&&typeof c=="object"&&!Array.isArray(c)?{...u,...c}:c}o==="world"&&typeof i.preset=="string"&&i.preset!==e.world.preset&&(i.sky===void 0&&delete a.sky,i.boxes===void 0&&delete a.boxes),r[o]=a}return Array.isArray(n.materials)&&(r.materials=n.materials),Array.isArray(n.models)&&(r.models=n.models),ze(r)}function St(e){return JSON.stringify(e)===JSON.stringify(Ne())}function gi(e,t){let n=r=>t.uuid?r.uuid===t.uuid:r.name===t.name&&!r.uuid;return ze({...e,materials:[...e.materials.filter(r=>!n(r)),t]})}function Or(e,t){let n=r=>t.uuid?r.uuid===t.uuid:r.name===t.name&&!r.uuid;return ze({...e,models:[...e.models.filter(r=>!n(r)),t]})}function Lr(e){let t=parseInt(e.slice(1),16),n=r=>{let o=r/255;return o<=.04045?o/12.92:((o+.055)/1.055)**2.4};return[n(t>>16&255),n(t>>8&255),n(t&255)]}var ot=Math.PI/180,Gt=(e,t,n)=>{if(t<=e)return n<e?0:1;let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)};function wd(e,t){let n=e*ot,r=t*ot;return[Math.cos(r)*Math.sin(n),Math.sin(r),Math.cos(r)*Math.cos(n)]}function Il(e,t=1024,n=512){let r=new Float32Array(t*n*4),o=Lr(e.sky.top),i=Lr(e.sky.horizon),s=Lr(e.sky.ground),a=e.sky.intensity*e.strength,l=e.boxes.map(f=>{let d=wd(f.azimuth+e.rotation,f.elevation),p=[d[2],0,-d[0]],m=Math.hypot(p[0],p[2]);p=m<1e-6?[1,0,0]:[p[0]/m,0,p[2]/m];let g=[d[1]*p[2]-d[2]*p[1],d[2]*p[0]-d[0]*p[2],d[0]*p[1]-d[1]*p[0]],h=Math.tan(Math.min(178,f.width)/2*ot),b=Math.tan(Math.min(178,f.height)/2*ot),y=Math.max(.02,f.softness),v=Lr(f.color),x=f.intensity*e.strength;return{c:d,right:p,up:g,hx:h,hy:b,soft:y,color:[v[0]*x,v[1]*x,v[2]*x]}}),c=new Float32Array(t),u=new Float32Array(t);for(let f=0;f<t;f++){let d=((f+.5)/t-.5)*Math.PI*2;c[f]=Math.cos(d),u[f]=Math.sin(d)}for(let f=0;f<n;f++){let d=((f+.5)/n-.5)*Math.PI,p=Math.cos(d),m=Math.sin(d),g=m>=0?Math.pow(m,.6):Math.pow(-m,.5),h=m>=0?o:s,b=(i[0]+(h[0]-i[0])*g)*a,y=(i[1]+(h[1]-i[1])*g)*a,v=(i[2]+(h[2]-i[2])*g)*a;for(let x=0;x<t;x++){let M=p*c[x],S=p*u[x],k=b,E=y,L=v;for(let C of l){let O=M*C.c[0]+m*C.c[1]+S*C.c[2];if(O<=.02)continue;let P=Math.abs((M*C.right[0]+m*C.right[1]+S*C.right[2])/O);if(P>=C.hx)continue;let j=Math.abs((M*C.up[0]+m*C.up[1]+S*C.up[2])/O);if(j>=C.hy)continue;let I=(1-Gt(C.hx*(1-C.soft),C.hx,P))*(1-Gt(C.hy*(1-C.soft),C.hy,j));k+=C.color[0]*I,E+=C.color[1]*I,L+=C.color[2]*I}let A=(f*t+x)*4;r[A]=k,r[A+1]=E,r[A+2]=L,r[A+3]=1}}return r}var Fl=new Float32Array(1),xd=new Uint32Array(Fl.buffer);function Sd(e){Fl[0]=Math.min(65504,Math.max(-65504,e));let t=xd[0],n=t>>16&32768,r=t>>12&2047,o=t>>23&255;return o<103?n:o>142?n|31744:o<113?(r|=2048,n|(r>>114-o)+(r>>113-o&1)):(n|o-112<<10|r>>1)+(r&1)}function Vl(e){let t=new Uint16Array(e.length);for(let n=0;n<e.length;n++)t[n]=Sd(e[n]);return t}var Kt=(e,t)=>{let n=Math.sin(e*127.1+t*311.7)*43758.5453;return n-Math.floor(n)};function hi(e,t){let n=Math.floor(e),r=Math.floor(t),o=e-n,i=t-r,s=o*o*(3-2*o),a=i*i*(3-2*i),l=Kt(n,r),c=Kt(n+1,r),u=Kt(n,r+1),f=Kt(n+1,r+1);return l+(c-l)*s+(u-l)*a+(l-c-u+f)*s*a}function Dl(e,t,n){let r=new Float32Array(t*t),o=e.scale;for(let i=0;i<t;i++){let s=(i+.5)/t;for(let a=0;a<t;a++){let l=(a+.5)/t,c=.5;switch(e.pattern){case"rings":{let u=Math.hypot(l-.5,s-.5)*2,f=.5+.5*Math.cos(u*o*Math.PI*2);c=Gt(.25,.75,f)*Gt(.08,.16,u)*(1-Gt(.86,.94,u));break}case"brushed":c=.6*hi(l*3,s*o*6)+.3*hi(l*7+13,s*o*14)+.1*hi(l*40,s*o*30+5);break;case"hammered":{let u=l*o,f=s*o,d=1;for(let p=-1;p<=1;p++)for(let m=-1;m<=1;m++){let g=Math.floor(u)+m,h=Math.floor(f)+p,b=g+Kt(g,h),y=h+Kt(h+31,g+17);d=Math.min(d,Math.hypot(u-b,f-y))}c=Gt(0,.75,d);break}case"knurl":{let u=Math.abs((l+s)*o%1-.5)*2,f=Math.abs(((l-s)*o%1+1)%1-.5)*2;c=Math.min(u,f);break}case"text":c=n?n[i*t+a]/255:0;break}r[i*t+a]=c}}if(e.pattern==="text"&&n){let i=new Float32Array(r.length);for(let s=0;s<2;s++){for(let a=0;a<t;a++)for(let l=0;l<t;l++){let c=l>0?l-1:l,u=l<t-1?l+1:l,f=a>0?a-1:a,d=a<t-1?a+1:a;i[a*t+l]=(r[a*t+l]*4+r[a*t+c]+r[a*t+u]+r[f*t+l]+r[d*t+l])/8}r.set(i)}}return r}function Nl(e,t,n){let r=new Uint8Array(t*t*4),o=n*t*.012,i=(s,a)=>e[Math.min(t-1,Math.max(0,a))*t+Math.min(t-1,Math.max(0,s))];for(let s=0;s<t;s++)for(let a=0;a<t;a++){let l=(i(a+1,s)-i(a-1,s))*o,c=(i(a,s+1)-i(a,s-1))*o,u=Math.hypot(l,c,1),f=(s*t+a)*4;r[f]=Math.round(-l/u*127.5+127.5),r[f+1]=Math.round(-c/u*127.5+127.5),r[f+2]=Math.round(1/u*127.5+127.5),r[f+3]=255}return r}function zl(e,t){let n=[e],r=e;for(let o=t;o>1;o>>=1){let i=o>>1,s=new Uint8Array(i*i*4);for(let a=0;a<i;a++)for(let l=0;l<i;l++){let c=0,u=0,f=0;for(let m=0;m<2;m++)for(let g=0;g<2;g++){let h=((a*2+m)*o+l*2+g)*4;c+=r[h]-127.5,u+=r[h+1]-127.5,f+=r[h+2]-127.5}let d=Math.hypot(c,u,f)||1,p=(a*i+l)*4;s[p]=Math.round(c/d*127.5+127.5),s[p+1]=Math.round(u/d*127.5+127.5),s[p+2]=Math.round(f/d*127.5+127.5),s[p+3]=255}n.push(s),r=s}return n}var Jt=1024;function di(e,t,n){let r=e-t,o=[];for(let i=n;i>=1;i--)o.push(-r-t*Math.tan(45*i/n*ot));o.push(-r),r>1e-9&&o.push(r);for(let i=1;i<=n;i++)o.push(r+t*Math.tan(45*i/n*ot));return o}function Wl(e,t,n,r,o,i=[1,1,1]){let s=[Math.abs(i[0])||1,Math.abs(i[1])||1,Math.abs(i[2])||1],a=[e*s[0]/2,t*s[1]/2,n*s[2]/2],l=Math.max(0,Math.min(r,Math.min(a[0],a[1],a[2]))),c=Math.max(1,Math.round(o)),u=[di(a[0],l,c),di(a[1],l,c),di(a[2],l,c)],f=[],d=[],p=[],m=[[0,1,1,2],[0,-1,2,1],[1,1,2,0],[1,-1,0,2],[2,1,0,1],[2,-1,1,0]],g=(h,b,y,v,x,M)=>{let S=[0,0,0];S[h]=b*a[h],S[y]=x,S[v]=M;let k=[0,0,0],E=[0,0,0];for(let P=0;P<3;P++){let j=a[P]-l;k[P]=Math.min(j,Math.max(-j,S[P])),E[P]=S[P]-k[P]}let L=Math.hypot(E[0],E[1],E[2])||1,A=[E[0]/L,E[1]/L,E[2]/L];l===0&&(A[0]=A[1]=A[2]=0,A[h]=b),f.push((k[0]+A[0]*l)/s[0],(k[1]+A[1]*l)/s[1],(k[2]+A[2]*l)/s[2]);let C=[A[0]*s[0],A[1]*s[1],A[2]*s[2]],O=Math.hypot(C[0],C[1],C[2])||1;d.push(C[0]/O,C[1]/O,C[2]/O),p.push(x/(2*a[y])+.5,M/(2*a[v])+.5)};for(let[h,b,y,v]of m){let x=u[y],M=u[v];for(let S=0;S<x.length-1;S++)for(let k=0;k<M.length-1;k++){let E=x[S],L=x[S+1],A=M[k],C=M[k+1];g(h,b,y,v,E,A),g(h,b,y,v,L,A),g(h,b,y,v,L,C),g(h,b,y,v,E,A),g(h,b,y,v,L,C),g(h,b,y,v,E,C)}}return{position:new Float32Array(f),normal:new Float32Array(d),uv:new Float32Array(p)}}function Bl(e,t,n,r,o){let i=Math.max(3,Math.round(n)),s=Math.max(0,Math.min(r,e*.95,t/2)),a=Math.max(1,Math.round(o)),l=i<=12,c=[];c.push([0,-t/2,0,-1],[e-s,-t/2,0,-1]);for(let m=0;m<=a;m++){let g=(-90+90*m/a)*ot;c.push([e-s+s*Math.cos(g),-t/2+s+s*Math.sin(g),Math.cos(g),Math.sin(g)])}for(let m=0;m<=a;m++){let g=90*m/a*ot;c.push([e-s+s*Math.cos(g),t/2-s+s*Math.sin(g),Math.cos(g),Math.sin(g)])}c.push([e-s,t/2,0,1],[0,t/2,0,1]);let u=[],f=[],d=[],p=c.length-1;for(let m=0;m<i;m++){let g=m/i*Math.PI*2,h=(m+1)/i*Math.PI*2,b=(g+h)/2,y=(v,x,M,S)=>{let k=v[0]*Math.sin(x),E=v[0]*Math.cos(x);u.push(k,v[1],E);let L=l?b:x;f.push(v[2]*Math.sin(L),v[3],v[2]*Math.cos(L)),S?d.push(.5+S*k/(2*e),.5-E/(2*e)):d.push(x/(Math.PI*2),M/p)};for(let v=0;v<p;v++){let x=c[v],M=c[v+1];if(Math.abs(x[0]-M[0])<1e-12&&Math.abs(x[1]-M[1])<1e-12)continue;let S=v===0?-1:v===p-1?1:0;x[0]>1e-12&&(y(x,g,v,S),y(x,h,v,S),y(M,h,v+1,S)),M[0]>1e-12&&(y(x,g,v,S),y(M,h,v+1,S),y(M,g,v+1,S))}}return{position:new Float32Array(u),normal:new Float32Array(f),uv:new Float32Array(d)}}function bi(e){let{quality:t,shadows:n,effects:r}=e,o=t.pixelRatio,i=(s,a)=>({look:Xt(e,s),step:a});return t.supersample?i({quality:{supersample:!1}},"Extra resolution on 1\xD7 screens off"):n.mode==="on"&&n.resolution>2048?i({shadows:{resolution:2048}},"Shadow detail 4096 \u2192 2048"):r.antialias&&o!==null&&o>1.5?i({quality:{pixelRatio:1.5}},`Pixel ratio ${o} \u2192 1.5 (edges are already smoothed)`):r.dof.on?i({effects:{dof:{on:!1}}},"Depth of field off"):n.mode==="on"&&n.resolution>1024?i({shadows:{resolution:1024}},"Shadow detail 2048 \u2192 1024"):o!==null&&o>1.5?i({quality:{pixelRatio:1.5}},`Pixel ratio ${o} \u2192 1.5`):r.ao.on?i({effects:{ao:{on:!1}}},"Ambient occlusion off"):r.bloom.on?i({effects:{bloom:{on:!1}}},"Bloom off"):o!==null&&o>1.25?i({quality:{pixelRatio:1.25}},`Pixel ratio ${o} \u2192 1.25`):r.antialias?i({effects:{antialias:!1}},"Smooth edges off"):o!==null&&o>1?i({quality:{pixelRatio:1}},`Pixel ratio ${o} \u2192 1`):n.mode==="on"?i({shadows:{mode:"off"}},"Shadows off"):null}function Hl(e){let t=[],n=(r,o,i)=>void t.push({id:r,label:o,without:Xt(e,i)});return e.quality.pixelRatio!==null&&n("pixel-ratio",`Full resolution (up to ${e.quality.pixelRatio}\xD7)`,{quality:{pixelRatio:null}}),e.quality.supersample&&n("supersample","Extra resolution on 1\xD7 screens",{quality:{supersample:!1}}),e.shadows.mode==="on"&&n("shadows",`Soft shadows (${e.shadows.resolution}px)`,{shadows:{mode:"site"}}),e.effects.antialias&&n("antialias","Smooth edges",{effects:{antialias:!1}}),e.effects.ao.on&&n("ao","Ambient occlusion",{effects:{ao:{on:!1}}}),e.effects.bloom.on&&n("bloom","Bloom",{effects:{bloom:{on:!1}}}),e.effects.dof.on&&n("dof","Depth of field",{effects:{dof:{on:!1}}}),e.bevel.mode!=="off"&&n("bevel","Bevelled edges",{bevel:{mode:"off"}}),t}var _r=e=>e.antialias||e.ao.on||e.bloom.on||e.dof.on||e.vignette>0||e.grain>0;function Ir(e,t){let n=[],r=[],o=m=>void n.push(m);e.srgbOutput===!1?o({id:"color-space",severity:"high",weight:12,title:"Output is not sRGB",detail:"Colours are written to the screen in the wrong colour space, so everything looks dark and oversaturated. Set renderer.outputColorSpace = THREE.SRGBColorSpace in the code."}):r.push("sRGB output");let i=t.color.toneMapping==="site"?e.toneMapping:mi[t.color.toneMapping];!e.sitePostProcessing&&(i===0||i===null)?o({id:"tone-mapping",severity:"high",weight:14,title:"No tone mapping",detail:"Bright areas clip to flat white and colours shift. A filmic curve (AgX or ACES) rolls highlights off the way a camera does.",fix:{color:{toneMapping:(e.revision??0)>=160?"agx":"aces",exposure:1}},fixLabel:(e.revision??0)>=160?"Use AgX":"Use ACES"}):r.push("Tone mapping");let s=Math.min(e.devicePixelRatio,2),a=t.quality.pixelRatio===null?e.pixelRatio:Math.min(e.devicePixelRatio,t.quality.pixelRatio);a<s-.05?o({id:"pixel-ratio",severity:"high",weight:14,title:`Rendering at ${Math.round(a*100)/100}\xD7 on a ${e.devicePixelRatio}\xD7 screen`,detail:"The picture is stretched to fit, which is what makes edges and textures look pixelated. Render at the screen density, capped at 2.",fix:{quality:{pixelRatio:2}},fixLabel:"Render at up to 2\xD7"}):r.push("Pixel ratio"),t.quality.supersample?r.push("Edges on 1\xD7 screens"):o({id:"supersample",severity:"low",weight:3,title:e.devicePixelRatio<1.5?"This 1\xD7 screen shows stair-stepped, shimmering edges":"Edges will stair-step and shimmer on 1\xD7 screens",detail:"On a screen with one device pixel per CSS pixel (most desktop monitors), multisampling alone leaves visible steps on silhouettes, and they crawl when anything moves. Rendering at 1.5\xD7 there and scaling down removes them. Denser screens are not affected, and it is the first thing given up when the frame rate drops.",fix:{quality:{supersample:!0}},fixLabel:"Render 1\xD7 screens at 1.5\xD7"}),e.antialias===!1&&!t.effects.antialias&&!e.sitePostProcessing?o({id:"antialias",severity:"medium",weight:8,title:"No anti-aliasing",detail:e.effectsAvailable?"Edges show stair-steps. Turn on smooth edges in Effects, or create the renderer with antialias: true.":"Edges show stair-steps. Create the renderer with { antialias: true } (it cannot be changed on a live page).",...e.effectsAvailable?{fix:{effects:{antialias:!0}},fixLabel:"Smooth edges"}:{}}):r.push("Anti-aliasing");let l=t.world.preset!=="site";!e.hasEnvironment&&!l&&e.pbrMaterials>0?o({id:"environment",severity:"high",weight:18,title:"Nothing for surfaces to reflect",detail:e.metals>0?`${e.metals} metal material${e.metals===1?"":"s"} have no world to reflect, so they render flat or black. A studio of soft light boxes gives metal and gloss their shape.`:"Without a world, shiny surfaces only show small dots from point lights. Soft light boxes give them broad, readable highlights.",fix:{world:{preset:"studio"}},fixLabel:"Add studio lighting"}):e.pbrMaterials>0&&r.push("World lighting"),e.simpleMaterials>0&&e.pbrMaterials===0&&o({id:"simple-materials",severity:"medium",weight:8,title:"No physically based materials",detail:`All ${e.simpleMaterials} mesh material${e.simpleMaterials===1?" is":"s are"} Basic, Lambert or Phong: they ignore roughness, metalness and the world. Use MeshStandardMaterial or MeshPhysicalMaterial in the code.`});let c=t.shadows.mode==="on"||t.shadows.mode==="site"&&e.shadowsEnabled;!c&&e.shadowCapableLights>0?o({id:"shadows",severity:"medium",weight:10,title:"No shadows",detail:"Objects look like they float. Soft shadows from the main light anchor them to the ground.",fix:{shadows:{mode:"on"}},fixLabel:"Turn on soft shadows"}):c&&r.push("Shadows"),e.hardEdgeMeshes>0&&t.bevel.mode==="off"?o({id:"hard-edges",severity:"medium",weight:10,title:`${e.hardEdgeMeshes} object${e.hardEdgeMeshes===1?" has":"s have"} razor-sharp edges`,detail:"Nothing real has a perfectly sharp edge. A small bevel catches a thin highlight along every edge, the strongest cue that an object is solid.",fix:{bevel:{mode:"all"}},fixLabel:"Bevel edges"}):t.bevel.mode!=="off"&&r.push("Bevelled edges"),e.lowPolyRound>0&&o({id:"low-poly",severity:"low",weight:4,title:`${e.lowPolyRound} round shape${e.lowPolyRound===1?" shows":"s show"} corners`,detail:"Spheres or cylinders with few segments have a visible polygon outline. Raise the segment counts in the code (64 for a sphere seen up close)."}),e.texturesWithoutAnisotropy>0&&!t.quality.anisotropy&&o({id:"anisotropy",severity:"low",weight:4,title:"Textures blur at glancing angles",detail:`${e.texturesWithoutAnisotropy} of ${e.textures} textures use no anisotropic filtering, so floors and walls smear into the distance.`,fix:{quality:{anisotropy:!0}},fixLabel:"Sharpen textures"}),e.depthRatio!==null&&e.depthRatio>2e5&&o({id:"depth-range",severity:"low",weight:4,title:"Camera depth range is very large",detail:`far / near is ${Math.round(e.depthRatio).toLocaleString("en-US")}: surfaces close to each other flicker (z-fighting). Raise camera.near or lower camera.far in the code.`}),!e.sitePostProcessing&&e.effectsAvailable&&!t.effects.ao.on&&e.pbrMaterials>0?o({id:"ambient-occlusion",severity:"low",weight:4,title:"No contact shading",detail:"Ambient occlusion darkens creases and the places where objects meet, which ties a scene together.",fix:{effects:{ao:{on:!0}}},fixLabel:"Add ambient occlusion"}):_r(t.effects)&&r.push("Lens effects");let u=e.fps??null,f=e.siteFps??null;if(u!==null&&f!==null&&u<f*.8&&u<Math.min(55,t.performance.targetFps)){let m=bi(t);o({id:"performance",severity:"high",weight:15,title:`The look costs frame rate: ${Math.round(u)} fps, the site alone runs at ${Math.round(f)}`,detail:m?`A dropped frame rate is felt before any detail is seen. Next step down: ${m.step}.`:"Nothing in the look is left to lighten: the scene itself is heavy. See the Perf tab for what costs the most.",...m?{fix:{quality:m.look.quality,shadows:m.look.shadows,effects:m.look.effects},fixLabel:"Lighten"}:{}})}else u!==null&&f!==null&&!St(t)&&r.push("Frame rate");let d=n.reduce((m,g)=>m+g.weight,0),p={high:0,medium:1,low:2};return n.sort((m,g)=>p[m.severity]-p[g.severity]||g.weight-m.weight),{score:Math.max(0,100-d),issues:n,passed:r}}function Ul(e,t,n){let r=e;for(let o of t.issues)o.fix&&(!n||n.includes(o.id))&&(r=Xt(r,o.fix));return r}var se=e=>{let t=Math.abs(e);return String(Number(t>=100?e.toFixed(0):t>=1?e.toFixed(2):e.toPrecision(2)))},$l=3e5,Md=4*2048*2048;function yi(e,t,n,r=[],o={}){let i=r.length?r:n.models,s=[],a=[],l=e,c=(h,b,y,v)=>{l=Xt(l,v),s.push({id:h,label:b,detail:y})},u=h=>h.name?`"${h.name}"`:"The model",f=h=>h.length===1?u(h[0]):`${h.length} models`,d=i.filter(h=>!h.castsShadow||!h.receivesShadow);d.length&&e.shadows.mode==="site"&&t.shadowCapableLights>0&&c("shadows","Soft shadows on, fitted to the scene",`${f(d)} did not ${d.some(h=>!h.castsShadow)?"cast":"receive"} shadows. Every mesh now casts and receives, and the shadow area covers the whole scene (radius ${se(n.radius)}).`,{shadows:{mode:"on"}});let p=i.reduce((h,b)=>h+b.wrongColorSpace,0);p&&!e.adapt.textures&&c("textures","Texture colour spaces corrected",`${p} texture${p===1?" was":"s were"} read in the wrong colour space (colour maps must be sRGB, normal and roughness maps plain numbers), which washes out or darkens the surface.`,{adapt:{textures:!0}});let m=i.reduce((h,b)=>h+b.texturesWithoutAnisotropy,0);m&&!e.quality.anisotropy&&c("anisotropy","Sharp textures at glancing angles",`${m} texture${m===1?"":"s"} had no anisotropic filtering and would smear on surfaces seen at an angle.`,{quality:{anisotropy:!0}}),!t.hasEnvironment&&e.world.preset==="site"&&i.some(h=>h.pbrMaterials)&&c("world","Studio world lighting","The scene had nothing for physically based surfaces to reflect, so metals and glossy parts would render flat or black.",{world:{preset:"studio"}});let g=r[0]??[...n.models].filter(h=>h.screen&&h.distance!==null).sort((h,b)=>jl(h)-jl(b))[0];if(e.effects.dof.on&&g?.distance){let h=g.distance;Math.abs(e.effects.dof.focus-h)/h>.08&&c("focus",`Focus on ${u(g).replace(/^The model$/,"the model")}`,`Depth of field was focused at ${se(e.effects.dof.focus)}; the model is ${se(h)} from the camera.`,{effects:{dof:{focus:Math.round(h*1e3)/1e3}}})}if(e.effects.ao.on&&n.radius>0){let h=Math.min(5,Math.max(.01,n.radius*.05)),b=e.effects.ao.radius/h;(b>2||b<.5)&&c("ao-radius","Ambient occlusion sized to the scene",`Its radius was ${se(e.effects.ao.radius)} in a scene of radius ${se(n.radius)}: ${b>2?"wide enough to darken whole objects":"too small to show in the creases"}.`,{effects:{ao:{radius:Math.round(h*1e3)/1e3}}})}for(let h of i){let b=()=>l.models.find(x=>x.uuid?x.uuid===h.uuid:x.name===h.name)??{uuid:h.uuid,name:h.name},y=h.size[1],v=Math.max(...h.size);if(o.scale!==void 0&&r.includes(h)&&o.scale>0){let x=b();l=Or(l,{...x,scale:(x.scale??1)*o.scale}),s.push({id:"scale",label:`${u(h)} scaled \xD7${se(o.scale)}`,detail:`Its largest side goes from ${se(v)} to ${se(v*o.scale)}.`})}else if(h.relativeSize!==null&&(h.relativeSize>20||h.relativeSize<.05)){let x=10**-Math.round(Math.log10(h.relativeSize));a.push({id:"scale",model:h.uuid,title:`${u(h)} is ${h.relativeSize>1?`${se(h.relativeSize)}\xD7 larger`:`${se(1/h.relativeSize)}\xD7 smaller`} than the rest of the scene`,detail:`Its largest side is ${se(v)}. A difference this big is usually a unit mismatch (a model made in centimetres or millimetres). Its real size cannot be read from the file, so this is not changed by itself.`,option:{scale:x},optionLabel:`Scale \xD7${se(x)}`})}if(h.gap!==null&&o.scale===void 0){let x=Math.max(y*.02,1e-5),M=h.support?`"${h.support}"`:"the surface under it";if(Math.abs(h.gap)>x)if(o.ground&&r.includes(h)){let S=b();l=Or(l,{...S,lift:(S.lift??0)-h.gap}),s.push({id:"ground",label:`${u(h)} set on ${M}`,detail:`It was ${h.gap>0?`${se(h.gap)} above`:`sunk ${se(-h.gap)} into`} it${h.gapExact?"":" (measured against its bounding box, so check the contact)"}.`})}else a.push({id:"ground",model:h.uuid,title:h.gap>0?`${u(h)} floats ${se(h.gap)} above ${M}`:`${u(h)} is sunk ${se(-h.gap)} into ${M}`,detail:`That is ${Math.round(Math.abs(h.gap)/Math.max(y,1e-9)*100)}% of its height${h.gapExact?"":", measured against a bounding box"}. Without contact it has no contact shadow and reads as pasted in. Leave it if it is meant to float.`,option:{ground:!0},optionLabel:"Set on the surface"})}h.simpleMaterials.length&&a.push({id:"materials",model:h.uuid,title:`${u(h)} uses ${h.simpleMaterials.join(", ")}`,detail:"These materials ignore the world lighting and reflections, so the model cannot match the scene. Change them to MeshStandardMaterial (or MeshPhysicalMaterial) in the code."}),h.triangles>$l&&a.push({id:"triangles",model:h.uuid,title:`${u(h)} has ${Math.round(h.triangles/1e3)}k triangles`,detail:`Over ${$l/1e3}k is heavy for a web page, mostly on phones. Simplify and compress the file: npx @gltf-transform/cli optimize in.glb out.glb --simplify --compress meshopt`}),(h.texturePixels>Md||h.largestTexture>4096)&&a.push({id:"textures",model:h.uuid,title:`${u(h)} carries ${h.textures} textures up to ${h.largestTexture}px`,detail:`About ${Math.round(h.texturePixels*4*1.33/1048576)} MB of GPU memory uncompressed. Resize to 2048 and use KTX2: npx @gltf-transform/cli optimize in.glb out.glb --texture-size 2048 --texture-compress ktx2`})}return{look:l,changes:s,advice:a}}function jl(e){return e.screen?Math.hypot((e.screen[0]+e.screen[2])/2-.5,(e.screen[1]+e.screen[3])/2-.5):1/0}function Nn(e){let t=ze(e);return{...t,materials:t.materials.filter(n=>n.name).map(({uuid:n,...r})=>r),bevel:{...t.bevel,targets:t.bevel.targets.filter(n=>n.name).map(n=>({name:n.name}))},models:t.models.filter(n=>n.name).map(({uuid:n,...r})=>r)}}function ql(e){return`${JSON.stringify(Nn(e),null,2)}
|
|
747
|
+
`}function Fr(e="./depthview-look.json"){return`// Depthview look: colour, world lighting, shadows, materials, bevels and lens effects
|
|
748
|
+
// tuned in the inspector. Needs three >= 0.160.
|
|
749
|
+
|
|
750
|
+
// React Three Fiber, inside <Canvas>:
|
|
751
|
+
import look from '${e}';
|
|
752
|
+
import { DepthviewLook } from 'depthview-r3f-bridge/look/react';
|
|
753
|
+
// <DepthviewLook look={look} />
|
|
754
|
+
|
|
755
|
+
// Plain three.js:
|
|
756
|
+
import { applyLook } from 'depthview-r3f-bridge/look';
|
|
757
|
+
const applied = applyLook({ renderer, scene, camera }, look);
|
|
758
|
+
// in the render loop, in place of renderer.render(scene, camera):
|
|
759
|
+
// applied.render();
|
|
760
|
+
`}function Gl(e){let t=[];if((e.color.toneMapping!=="site"||e.color.exposure!==null)&&t.push(`Colour: ${e.color.toneMapping==="site"?"site's tone mapping":e.color.toneMapping}${e.color.exposure===null?"":`, exposure ${e.color.exposure}`}`),e.quality.supersample&&t.push("Quality: 1\xD7 screens rendered at 1.5\xD7"),(e.quality.pixelRatio!==null||e.quality.anisotropy)&&t.push(`Quality: ${e.quality.pixelRatio===null?"":`pixel ratio up to ${e.quality.pixelRatio}`}${e.quality.pixelRatio!==null&&e.quality.anisotropy?", ":""}${e.quality.anisotropy?"anisotropic textures":""}`),e.world.preset!=="site"&&t.push(`World: ${e.world.preset}, ${e.world.boxes.length} light box${e.world.boxes.length===1?"":"es"}, strength ${e.world.strength}${e.world.rotation?`, rotated ${e.world.rotation}\xB0`:""}${e.world.background?", shown as background":""}`),e.shadows.mode!=="site"&&t.push(e.shadows.mode==="on"?`Shadows: on, softness ${e.shadows.softness}, ${e.shadows.resolution}px`:"Shadows: off"),e.materials.length&&t.push(`Materials: ${e.materials.map(n=>`${n.name||n.uuid} (${n.preset}${n.detail?`, ${n.detail.pattern} detail`:""})`).join(", ")}`),e.bevel.mode!=="off"&&t.push(`Bevel: ${e.bevel.mode==="all"?"all boxes and cylinders":`${e.bevel.targets.length} object(s)`}, amount ${e.bevel.amount}`),e.adapt.textures&&t.push("Textures: colour spaces corrected"),e.models.length&&t.push(`Models: ${e.models.map(n=>{let r=[n.scale!==void 0&&`scale \xD7${n.scale}`,n.lift!==void 0&&`${n.lift>0?"raised":"lowered"} ${Math.abs(n.lift)}`,n.reflection!==void 0&&`reflections \xD7${n.reflection}`].filter(Boolean);return`${n.name||n.uuid} (${r.join(", ")})`}).join(", ")}`),e.performance.adaptive&&t.push(`Performance: steps down by itself below ${e.performance.targetFps} fps`),_r(e.effects)){let n=e.effects,r=[n.antialias&&"smooth edges",n.ao.on&&"ambient occlusion",n.bloom.on&&"bloom",n.dof.on&&"depth of field",n.vignette>0&&"vignette",n.grain>0&&"grain"].filter(Boolean);t.push(`Effects: ${r.join(", ")}`)}return t}function Kl(e,t){let n=e.trim();if(!n)return null;let r;try{if(typeof document<"u")r=document.createElement("canvas"),r.width=r.height=t;else if(typeof OffscreenCanvas<"u")r=new OffscreenCanvas(t,t);else return null}catch{return null}let o=r.getContext("2d",{willReadFrequently:!0});if(!o)return null;o.fillStyle="#000",o.fillRect(0,0,t,t),o.fillStyle="#fff";let i=t*.062;o.font=`700 ${i}px "Helvetica Neue", Helvetica, Arial, sans-serif`,o.textAlign="center",o.textBaseline="middle";let s=t*.405,a=`${n} \xB7 `,l=o.measureText(a).width,c=2*Math.PI*s,u=Math.max(1,Math.floor(c/Math.max(1,l))),f=[...a.repeat(u)],d=f.map(y=>o.measureText(y).width),p=d.reduce((y,v)=>y+v,0),m=c/p,g=0;f.forEach((y,v)=>{let x=(g+d[v]/2)*m/s-Math.PI/2;g+=d[v],o.save(),o.translate(t/2+Math.cos(x)*s,t/2+Math.sin(x)*s),o.rotate(x+Math.PI/2),o.fillText(y,0,0),o.restore()});let h=o.getImageData(0,0,t,t).data,b=new Uint8Array(t*t);for(let y=0;y<t;y++)for(let v=0;v<t;v++)b[(t-1-y)*t+v]=h[(y*t+v)*4];return b}var Vr={width:1024,height:512},vi=["map","normalMap","roughnessMap","metalnessMap","aoMap","emissiveMap","bumpMap","alphaMap","clearcoatNormalMap","clearcoatRoughnessMap","sheenColorMap","specularMap"],kd=["metalness","roughness","clearcoat","clearcoatRoughness","transmission","ior","thickness","envMapIntensity"],Ed=new Set(["clearcoat","clearcoatRoughness","transmission","ior","thickness"]),Te=e=>Array.isArray(e.material)?e.material:e.material?[e.material]:[];function fe(e,t,n=2e4){let r=[e],o=0;for(;r.length&&o<n;){let i=r.pop();o++,t(i);let s=i.children;if(Array.isArray(s))for(let a=s.length-1;a>=0;a--)r.push(s[a])}}function Td(e){let t=e.matrixWorld?.elements;return t?[Math.hypot(t[0],t[1],t[2]),Math.hypot(t[4],t[5],t[6]),Math.hypot(t[8],t[9],t[10])]:[1,1,1]}function Rd(e){try{e.boundingBox||e.computeBoundingBox?.();let t=e.boundingBox;if(t)return[(t.min.x+t.max.x)/2,(t.min.y+t.max.y)/2,(t.min.z+t.max.z)/2]}catch{}return[0,0,0]}function Ad(e,t){let n=e?.matrixWorld?.elements;if(!n)return[0,t,0];let[r,o,i,s,a,l,c,u,f]=[n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]],d=r*(a*f-l*u)-o*(s*f-l*c)+i*(s*u-a*c);return!Number.isFinite(d)||Math.abs(d)<1e-12?[0,t,0]:[(i*u-o*f)/d*t,(r*f-i*c)/d*t,(o*c-r*u)/d*t]}function Pd(e,t,n){let r=e?.matrixWorld?.elements,o=e?.matrixWorldInverse?.elements,i=e?.projectionMatrix?.elements;if(!r||!o||!i)return{distance:null,screen:null};let s=Math.hypot(n[0]-r[12],n[1]-r[13],n[2]-r[14]),a=1/0,l=1/0,c=-1/0,u=-1/0;for(let p=0;p<8;p++){let m=p&1?t.max[0]:t.min[0],g=p&2?t.max[1]:t.min[1],h=p&4?t.max[2]:t.min[2],b=o[0]*m+o[4]*g+o[8]*h+o[12],y=o[1]*m+o[5]*g+o[9]*h+o[13],v=o[2]*m+o[6]*g+o[10]*h+o[14],x=i[3]*b+i[7]*y+i[11]*v+i[15];if(x<=1e-6)return{distance:s,screen:null};let M=(i[0]*b+i[4]*y+i[8]*v+i[12])/x,S=(i[1]*b+i[5]*y+i[9]*v+i[13])/x;a=Math.min(a,M),c=Math.max(c,M),l=Math.min(l,-S),u=Math.max(u,-S)}let f=p=>Math.min(1,Math.max(0,p*.5+.5)),d=[f(a),f(l),f(c),f(u)];return d[2]-d[0]<1e-4||d[3]-d[1]<1e-4?{distance:s,screen:null}:{distance:s,screen:d}}function wi(e){if(!e.isMesh||Array.isArray(e.material))return null;let t=e.geometry,n=t?.parameters;return!t||!n?null:t.type==="BoxGeometry"&&n.width>0&&n.height>0&&n.depth>0?"box":t.type==="CylinderGeometry"&&n.radiusTop>0&&Math.abs(n.radiusTop-n.radiusBottom)<1e-9&&n.height>0&&n.openEnded!==!0&&(n.thetaLength===void 0||Math.abs(n.thetaLength-Math.PI*2)<1e-6)?"cylinder":null}function Xl(e){let t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],r=0;if(fe(e,s=>{if(!(!s.isMesh||s.visible===!1||!s.geometry||r>4e3))try{let a=s.geometry;a.boundingBox||a.computeBoundingBox?.();let l=a.boundingBox,c=s.matrixWorld?.elements;if(!l||!c||!Number.isFinite(l.min.x)||!Number.isFinite(l.max.x))return;r++;for(let u=0;u<8;u++){let f=u&1?l.max.x:l.min.x,d=u&2?l.max.y:l.min.y,p=u&4?l.max.z:l.min.z,m=[c[0]*f+c[4]*d+c[8]*p+c[12],c[1]*f+c[5]*d+c[9]*p+c[13],c[2]*f+c[6]*d+c[10]*p+c[14]];for(let g=0;g<3;g++)m[g]<t[g]&&(t[g]=m[g]),m[g]>n[g]&&(n[g]=m[g])}}catch{}}),!r)return{center:[0,0,0],radius:10};let o=[(t[0]+n[0])/2,(t[1]+n[1])/2,(t[2]+n[2])/2],i=Math.hypot(n[0]-t[0],n[1]-t[1],n[2]-t[2])/2;return{center:o,radius:Math.max(i,.001)}}function Jl(e){try{let t=e.geometry;if(!t)return null;t.boundingBox||t.computeBoundingBox?.();let n=t.boundingBox,r=e.matrixWorld?.elements;if(!n||!r||!Number.isFinite(n.min.x)||!Number.isFinite(n.max.x))return null;let o=[1/0,1/0,1/0],i=[-1/0,-1/0,-1/0];for(let s=0;s<8;s++){let a=s&1?n.max.x:n.min.x,l=s&2?n.max.y:n.min.y,c=s&4?n.max.z:n.min.z,u=[r[0]*a+r[4]*l+r[8]*c+r[12],r[1]*a+r[5]*l+r[9]*c+r[13],r[2]*a+r[6]*l+r[10]*c+r[14]];for(let f=0;f<3;f++)u[f]<o[f]&&(o[f]=u[f]),u[f]>i[f]&&(i[f]=u[f])}return{min:o,max:i}}catch{return null}}function xi(e){if(!e.isMesh||e.visible===!1||!e.geometry)return!1;let t=Te(e)[0];return!!t&&t.side!==1&&t.depthWrite!==!1}var Cd=["map","emissiveMap","sheenColorMap","specularColorMap"],Ld=["normalMap","roughnessMap","metalnessMap","aoMap","bumpMap","alphaMap","displacementMap","clearcoatNormalMap","clearcoatRoughnessMap"],Si=e=>!!(e.isMeshStandardMaterial||e.isMeshPhysicalMaterial);function Yl(e){let t=new Map;for(let r of e)if(Si(r))for(let[o,i]of[[Cd,"color"],[Ld,"data"]])for(let s of o){let a=r[s];if(!a?.isTexture||typeof a.colorSpace!="string"||a.isRenderTargetTexture||a.isCompressedTexture||a.isCubeTexture)continue;let l=t.get(a)??{color:!1,data:!1};l[i]=!0,t.set(a,l)}let n=new Map;for(let[r,o]of t)o.color&&o.data||(o.color&&r.colorSpace===""&&(r.type===void 0||r.type===1009)?n.set(r,"srgb"):o.data&&r.colorSpace==="srgb"&&n.set(r,""));return n}var $d=6e5,Dr=class{constructor(t,n){this.target=t;this.kit=n;fe(t.scene,r=>{r.isMesh&&this.known.add(r.uuid)}),this.fitted=this.signature()}applied=null;undo={};site={toneMapping:null,exposure:null,pixelRatio:null,environment:void 0,shadowsEnabled:null,bevelled:new Map,anisotropy:new Map};notes=[];partNotes={};part="";fitted="";churn=0;seen="";known=new Set;detailMaps=new Map;note(t){(this.partNotes[this.part]??=[]).push(t)}revision(){let n=parseInt(String(globalThis.__THREE__??""),10);return Number.isFinite(n)?n:null}restore(t){let n=this.undo[t];if(n){for(let r=n.length-1;r>=0;r--)try{n[r]()}catch{}delete this.undo[t]}}touchMaterials(){let t=new Set;fe(this.target.scene,n=>{for(let r of Te(n))t.has(r)||(t.add(r),r.needsUpdate=!0)})}apply(t){return this.fit(t,!1)}follow(){let t=this.signature();if(t===this.fitted)return this.churn=0,!1;let n=t===this.seen;if(this.seen=t,++this.churn>3&&this.churn%8!==0&&!n)return!1;let r=this.applied;return r?.adapt.follow?this.fit(r,!0):this.fitted=t,!0}signature(){let t=0,n=2166136261;return fe(this.target.scene,r=>{if(!r.isMesh&&!r.isLight)return;t++;let o=String(r.uuid??"");for(let i=0;i<o.length&&i<13;i++)n=Math.imul(n^o.charCodeAt(i),16777619)}),`${t}:${n>>>0}`}fit(t,n){let r=this.applied,o=l=>!t||!r||JSON.stringify(r[l])!==JSON.stringify(t[l]),i=(l,c,u,f)=>{if(!(!(u&&n)&&!c.some(o))&&(this.restore(l),delete this.partNotes[l],!!t)){this.undo[l]=[],this.part=l;try{f()}catch(d){this.note(`${l}: ${d instanceof Error?d.message:String(d)}`)}}},s=n||o("models")||o("materials");if(s&&this.restore("reflection"),i("color",["color"],!1,()=>this.color(t)),i("quality",["quality"],!1,()=>this.quality(t)),i("world",["world"],!1,()=>this.world(t)),i("models",["models"],!0,()=>this.models(t)),i("anisotropy",["quality"],!0,()=>this.anisotropy(t)),i("textures",["adapt"],!0,()=>this.textures(t)),i("shadows",["shadows","models"],!0,()=>this.shadows(t)),i("materials",["materials"],!0,()=>this.materials(t)),s&&t){this.undo.reflection=[],this.part="reflection";try{this.reflection(t)}catch{}}i("bevel",["bevel","models"],!0,()=>this.bevel(t));let a=new Set((t?.materials??[]).map(l=>l.detail?JSON.stringify(l.detail):""));for(let[l,c]of this.detailMaps)a.has(l)||(this.kit.dispose(c),this.detailMaps.delete(l));return this.applied=t?JSON.parse(JSON.stringify(t)):null,t||(this.partNotes={}),this.fitted=this.signature(),this.notes=Object.values(this.partNotes).flat(),this.notes}reset(){this.apply(null)}color(t){let{renderer:n}=this.target,r=this.undo.color,{toneMapping:o,exposure:i}=t.color;if(o!=="site"&&typeof n.toneMapping=="number"){let s=o,a=Ol[o],l=this.revision();a&&l!==null&&l<a&&(this.note(`${o==="agx"?"AgX":"Neutral"} tone mapping needs three.js r${a} (this page has r${l}): ACES is used.`),s="aces");let c=n.toneMapping;this.site.toneMapping=c,n.toneMapping=mi[s],this.touchMaterials(),r.push(()=>{n.toneMapping=c,this.site.toneMapping=null,this.touchMaterials()})}if(i!==null&&typeof n.toneMappingExposure=="number"){let s=n.toneMappingExposure;this.site.exposure=s,n.toneMappingExposure=i,r.push(()=>{n.toneMappingExposure=s,this.site.exposure=null})}}quality(t){let{renderer:n}=this.target,r=this.undo.quality,o=this.kit.devicePixelRatio(),i=t.quality.supersample&&o<1.5;if((t.quality.pixelRatio!==null||i)&&typeof n.setPixelRatio=="function"){let s=n.getPixelRatio?.()??1,a=i?1.5:o,l=t.quality.pixelRatio!==null?Math.min(a,t.quality.pixelRatio):Math.max(s,a);this.site.pixelRatio=s,Math.abs(l-s)>.001&&n.setPixelRatio(l),r.push(()=>{Math.abs((n.getPixelRatio?.()??s)-s)>.001&&n.setPixelRatio(s),this.site.pixelRatio=null})}}anisotropy(t){let{renderer:n,scene:r}=this.target,o=this.undo.anisotropy;if(t.quality.anisotropy){let i=1;try{i=n.capabilities?.getMaxAnisotropy?.()??1}catch{}if(i>1){let s=Math.min(i,16);fe(r,a=>{for(let l of Te(a))for(let c of vi){let u=l[c];!u?.isTexture||this.site.anisotropy.has(u)||(u.anisotropy??1)>=s||(this.site.anisotropy.set(u,u.anisotropy??1),u.anisotropy=s,u.needsUpdate=!0)}}),o.push(()=>{for(let[a,l]of this.site.anisotropy)a.anisotropy=l,a.needsUpdate=!0;this.site.anisotropy.clear()})}}}world(t){let{scene:n}=this.target;if(t.world.preset==="site")return;let r=Il(t.world,Vr.width,Vr.height),o=this.kit.texture(Vl(r),Vr.width,Vr.height);if(!o){this.note("The world could not be made on this page. Set scene.environment in the code instead.");return}let i={environment:n.environment,background:n.background};this.site.environment=i.environment??null,n.environment=o,t.world.background&&(n.background=o),this.undo.world.push(()=>{n.environment=i.environment,n.background=i.background,this.site.environment=void 0,this.kit.dispose(o)})}shadows(t){let{renderer:n,scene:r}=this.target,o=this.undo.shadows,i=n.shadowMap;if(t.shadows.mode==="site"||!i)return;let s={enabled:i.enabled,type:i.type};if(this.site.shadowsEnabled=!!s.enabled,o.push(()=>{i.enabled=s.enabled,i.type=s.type,i.needsUpdate=!0,this.site.shadowsEnabled=null,this.touchMaterials()}),t.shadows.mode==="off"){i.enabled=!1,this.touchMaterials();return}i.enabled=!0,i.type=(this.revision()??0)>=182?1:2;let a=Xl(r),l=t.shadows.resolution,c=0;fe(r,u=>{if(u.isLight&&(u.isDirectionalLight||u.isSpotLight)&&u.shadow&&c<4){c++;let f=u.shadow,d=f.camera,p={cast:u.castShadow,w:f.mapSize?.x,h:f.mapSize?.y,bias:f.bias,normalBias:f.normalBias,radius:f.radius,cam:d?[d.left,d.right,d.top,d.bottom,d.near,d.far]:null};if(u.castShadow=!0,f.mapSize?.set?.(l,l),f.bias=-2e-4,f.normalBias=Math.max(.005,a.radius*.004),f.radius=t.shadows.softness,u.isDirectionalLight&&d&&typeof d.left=="number"){let m=u.matrixWorld?.elements,g=m?[m[12],m[13],m[14]]:[0,0,0],h=Math.hypot(g[0]-a.center[0],g[1]-a.center[1],g[2]-a.center[2]),b=a.radius*1.05+Math.min(h,a.radius);d.left=-b,d.right=b,d.top=b,d.bottom=-b,d.near=Math.max(.01,h-a.radius*2.2),d.far=h+a.radius*2.2,d.updateProjectionMatrix?.()}try{f.map?.dispose?.()}catch{}f.map=null,o.push(()=>{u.castShadow=p.cast,p.w!==void 0&&f.mapSize?.set?.(p.w,p.h),f.bias=p.bias,f.normalBias=p.normalBias,f.radius=p.radius,p.cam&&d&&([d.left,d.right,d.top,d.bottom,d.near,d.far]=p.cam,d.updateProjectionMatrix?.());try{f.map?.dispose?.()}catch{}f.map=null});return}if(u.isMesh){let f=Te(u)[0];if(!f||f.transparent===!0||f.side===1||f.depthWrite===!1)return;let d={cast:u.castShadow,receive:u.receiveShadow};u.castShadow=!0,u.receiveShadow=!0,o.push(()=>{u.castShadow=d.cast,u.receiveShadow=d.receive})}}),c||this.note("Shadows are on, but the scene has no directional or spot light to cast them. Add one in the code."),i.needsUpdate=!0,this.touchMaterials()}find(t){let n=[];return fe(this.target.scene,r=>{(t.uuid?r.uuid===t.uuid:t.name&&r.name===t.name)&&n.push(r)}),!n.length&&t.uuid&&t.name&&fe(this.target.scene,r=>{r.name===t.name&&n.push(r)}),n}detailMap(t){let n=JSON.stringify(t),r=this.detailMaps.get(n);if(r)return r;let o=t.pattern==="text"?Kl(t.text??"",Jt):null;if(t.pattern==="text"&&!o)return null;let i=Dl(t,Jt,o),s=this.kit.image(zl(Nl(i,Jt,t.strength),Jt),Jt);return s&&this.detailMaps.set(n,s),s}materials(t){let n=this.undo.materials;for(let r of t.materials){let o=this.find(r);if(!o.length){this.note(`No object named "${r.name||r.uuid}" for its material settings.`);continue}let i=new Set;for(let s of o){let a=Te(s)[0];if(a){if(r.color!==void 0&&a.color?.isColor){let l=`#${a.color.getHexString()}`;a.color.set(r.color),n.push(()=>a.color.set(l))}for(let l of kd){let c=r[l];if(typeof c!="number")continue;if(typeof a[l]!="number"){Ed.has(l)&&c!==0&&i.add(l);continue}let u=a[l];a[l]=c,n.push(()=>{a[l]=u,a.needsUpdate=!0})}if(r.detail&&r.detail.strength>0)if(!("normalMap"in a))i.add("surface detail");else if(!s.geometry?.attributes?.uv)this.note(`"${r.name||r.uuid}" has no UV coordinates, so surface detail cannot be mapped onto it.`);else if(r.detail.pattern==="text"&&!r.detail.text?.trim())this.note(`"${r.name||r.uuid}": engraved text needs the text to engrave.`);else{let l=this.detailMap(r.detail);if(!l)this.note("Surface detail could not be made on this page.");else{let c={map:a.normalMap,x:a.normalScale?.x,y:a.normalScale?.y};a.normalMap=l,a.normalScale?.set?.(1,1),n.push(()=>{a.normalMap=c.map,c.x!==void 0&&a.normalScale?.set?.(c.x,c.y),a.needsUpdate=!0})}}a.needsUpdate=!0}}i.size&&this.note(`"${r.name||r.uuid}": ${[...i].join(", ")} need${i.size===1?"s":""} MeshPhysicalMaterial (it uses ${Te(o[0])[0]?.type??"another material"}). Change the material in the code.`)}}models(t){let n=this.undo.models;for(let r of t.models){if(r.scale===void 0&&r.lift===void 0)continue;let o=this.find(r);if(!o.length){this.note(`No object named "${r.name||r.uuid}" to place.`);continue}for(let i of o){if(!i.position||!i.scale)continue;let s={p:[i.position.x,i.position.y,i.position.z],s:[i.scale.x,i.scale.y,i.scale.z]};if(r.scale!==void 0&&i.scale.set(s.s[0]*r.scale,s.s[1]*r.scale,s.s[2]*r.scale),r.lift!==void 0){let a=Ad(i.parent,r.lift);i.position.set(s.p[0]+a[0],s.p[1]+a[1],s.p[2]+a[2])}i.updateMatrixWorld?.(!0),n.push(()=>{i.position.set(s.p[0],s.p[1],s.p[2]),i.scale.set(s.s[0],s.s[1],s.s[2]),i.updateMatrixWorld?.(!0)})}}}reflection(t){let n=this.undo.reflection,r=new Set;for(let o of t.models)if(o.reflection!==void 0)for(let i of this.find(o))fe(i,s=>{for(let a of Te(s)){if(r.has(a)||!Si(a)||typeof a.envMapIntensity!="number")continue;r.add(a);let l=a.envMapIntensity;a.envMapIntensity=l*o.reflection,n.push(()=>{a.envMapIntensity=l})}})}textures(t){if(!t.adapt.textures)return;let n=this.undo.textures,r=new Set;fe(this.target.scene,i=>{for(let s of Te(i))r.add(s)});let o=Yl(r);if(o.size){for(let[i,s]of o){let a=i.colorSpace;i.colorSpace=s,i.needsUpdate=!0,n.push(()=>{i.colorSpace=a,i.needsUpdate=!0})}for(let i of r)i.needsUpdate=!0;n.push(()=>{for(let i of r)i.needsUpdate=!0})}}roots(){let t=o=>{let i=!1;return fe(o,s=>{xi(s)&&(i=!0)},4e3),i},n=this.target.scene,r=[];for(let o=0;o<4&&(r=(Array.isArray(n.children)?n.children:[]).filter(i=>i.visible!==!1&&t(i)),r.length===1&&!r[0].isMesh&&r[0].children?.length);o++)n=r[0];return r.slice(0,80)}measure(t=!1){let{scene:n,camera:r}=this.target;try{n.updateMatrixWorld?.(!0)}catch{}let o=this.roots(),i=new Map,s=o.map(()=>({meshes:[],box:null}));o.forEach((f,d)=>fe(f,p=>{if(!xi(p))return;i.set(p,d);let m=s[d];m.meshes.push(p);let g=Jl(p);if(g)if(!m.box)m.box={min:[...g.min],max:[...g.max]};else for(let h=0;h<3;h++)m.box.min[h]=Math.min(m.box.min[h],g.min[h]),m.box.max[h]=Math.max(m.box.max[h],g.max[h])}));let a=[];fe(n,f=>{xi(f)&&a.push(f)});let l=s.map(f=>f.box?Math.max(...f.box.max.map((d,p)=>d-f.box.min[p])):0),c=$d,u=[];if(o.forEach((f,d)=>{let{meshes:p,box:m}=s[d];if(!m||!p.length)return;let g=[m.max[0]-m.min[0],m.max[1]-m.min[1],m.max[2]-m.min[2]],h=[(m.min[0]+m.max[0])/2,(m.min[1]+m.max[1])/2,(m.min[2]+m.max[2])/2],b=0,y=new Set,v=new Set,x=!0,M=!0;for(let j of p){let I=j.geometry,te=I.index?I.index.count:I.attributes?.position?.count??0;b+=Math.floor(te/3)*(j.isInstancedMesh?j.count??1:1),Te(j)[0]?.transparent!==!0&&(j.castShadow||(x=!1),j.receiveShadow||(M=!1));for(let Oe of Te(j)){y.add(Oe);for(let Q of vi)Oe[Q]?.isTexture&&v.add(Oe[Q])}}let S=0,k=new Set;for(let j of y)Si(j)?S++:(j.isMeshBasicMaterial||j.isMeshLambertMaterial||j.isMeshPhongMaterial||j.isMeshToonMaterial)&&k.add(String(j.type));let E=0,L=0,A=0;for(let j of v){let I=Number(j.image?.width??j.image?.videoWidth??0)||0,te=Number(j.image?.height??j.image?.videoHeight??0)||0;E=Math.max(E,I,te),L+=I*te,(j.anisotropy??1)<=1&&A++}let C=l.filter((j,I)=>I!==d&&j>0).sort((j,I)=>j-I),O=C.length?C[Math.floor(C.length/2)]:null,P=this.ground(d,m,a,i,c);c-=P.tested,u.push({uuid:String(f.uuid),name:String(f.name??""),added:this.known.size>0&&p.every(j=>!this.known.has(j.uuid)),meshes:p.length,triangles:b,size:g,center:h,relativeSize:O?l[d]/O:null,gap:P.gap,gapExact:P.exact,support:P.support,...Pd(r,m,h),castsShadow:x,receivesShadow:M,pbrMaterials:S,simpleMaterials:[...k],textures:v.size,largestTexture:E,texturePixels:L,wrongColorSpace:Yl(y).size,texturesWithoutAnisotropy:A})}),t)for(let f of a)this.known.add(f.uuid);return{radius:Xl(n).radius,models:u}}ground(t,n,r,o,i){let s=n.min[1],a=Math.max(n.max[1]-s,1e-9),l=s+a*.5,c=(n.min[0]+n.max[0])/2,u=(n.min[2]+n.max[2])/2,f=(n.max[0]-n.min[0])*.3,d=(n.max[2]-n.min[2])*.3,p=[[c,u],[c-f,u-d],[c+f,u-d],[c-f,u+d],[c+f,u+d]],m=-1/0,g=null,h=!0,b=0,y=(x,M)=>{x<=l&&x>m&&(m=x,g=M)};for(let x of r){if(o.get(x)===t)continue;let M=Jl(x);if(!M||M.min[1]>l)continue;let S=p.filter(([j,I])=>j>=M.min[0]&&j<=M.max[0]&&I>=M.min[2]&&I<=M.max[2]);if(!S.length)continue;let k=x.geometry,E=k.attributes?.position,L=k.index?k.index.count:E?.count??0,A=x.matrixWorld?.elements;if(!(E&&typeof E.getX=="function"&&A&&!x.isInstancedMesh&&!x.isSkinnedMesh)||L/3>i-b){h=!1,M.max[1]<=l&&y(M.max[1],x);continue}b+=L/3;let O=k.index,P=[0,0,0,0,0,0,0,0,0];for(let j=0;j+2<L;j+=3){for(let Q=0;Q<3;Q++){let Se=O?O.getX(j+Q):j+Q,Me=E.getX(Se),ve=E.getY(Se),Ae=E.getZ(Se);P[Q*3]=A[0]*Me+A[4]*ve+A[8]*Ae+A[12],P[Q*3+1]=A[1]*Me+A[5]*ve+A[9]*Ae+A[13],P[Q*3+2]=A[2]*Me+A[6]*ve+A[10]*Ae+A[14]}let I=Math.min(P[0],P[3],P[6]),te=Math.max(P[0],P[3],P[6]),Ke=Math.min(P[2],P[5],P[8]),Oe=Math.max(P[2],P[5],P[8]);for(let[Q,Se]of S){if(Q<I||Q>te||Se<Ke||Se>Oe)continue;let Me=(P[5]-P[8])*(P[0]-P[6])+(P[6]-P[3])*(P[2]-P[8]);if(Math.abs(Me)<1e-12)continue;let ve=((P[5]-P[8])*(Q-P[6])+(P[6]-P[3])*(Se-P[8]))/Me,Ae=((P[8]-P[2])*(Q-P[6])+(P[0]-P[6])*(Se-P[8]))/Me,Rt=1-ve-Ae;ve<-1e-6||Ae<-1e-6||Rt<-1e-6||y(ve*P[1]+Ae*P[4]+Rt*P[7],x)}}}if(!g)return{gap:null,exact:h,support:null,tested:b};let v=g;return{gap:s-m,exact:h,support:String(v.name||v.type||""),tested:b}}bevelCandidates(){let t=[];return fe(this.target.scene,n=>{(this.site.bevelled.get(n)||wi(n))&&t.push(n)}),t}bevel(t){let n=this.undo.bevel;if(t.bevel.mode==="off")return;let r;if(t.bevel.mode==="all")r=this.bevelCandidates();else{r=[];for(let s of t.bevel.targets)r.push(...this.find(s))}let o=0,i=[];for(let s of r){let a=wi(s);if(!a){i.push(s.name||s.type);continue}let l=s.geometry,c=l.parameters,u=Td(s),f;if(a==="box"){let m=Math.min(c.width*u[0],c.height*u[1],c.depth*u[2]);f=Wl(c.width,c.height,c.depth,m*t.bevel.amount,t.bevel.segments,s.isInstancedMesh?[1,1,1]:u)}else{let m=Math.min(c.radiusTop*2,c.height);f=Bl(c.radiusTop,c.height,c.radialSegments??32,m*t.bevel.amount,t.bevel.segments)}let d=Rd(l);if(d[0]||d[1]||d[2])for(let m=0;m<f.position.length;m+=3)f.position[m]=f.position[m]+d[0],f.position[m+1]=f.position[m+1]+d[1],f.position[m+2]=f.position[m+2]+d[2];let p=this.kit.geometry(f);if(!p){this.note("Bevelled geometry could not be made on this page.");break}this.site.bevelled.set(s,l),s.geometry=p,o++,n.push(()=>{s.geometry=l,this.site.bevelled.delete(s),this.kit.dispose(p)})}i.length&&this.note(`Only box and cylinder meshes can be bevelled here (not ${i.slice(0,4).join(", ")}${i.length>4?"\u2026":""}). For other shapes, bevel the model in the modelling tool.`),!o&&t.bevel.mode==="all"&&!i.length&&this.note("No box or cylinder meshes to bevel in this scene.")}facts(t){let{renderer:n,scene:r,camera:o}=this.target,i=null;try{i=n.getContext?.()?.getContextAttributes?.()?.antialias??null}catch{}let s=typeof n.outputColorSpace=="string"?n.outputColorSpace==="srgb":typeof n.outputEncoding=="number"?n.outputEncoding===3001:null,a=0,l=0,c=0,u=0,f=0,d=new Set,p=new Set;fe(r,M=>{if(M.isLight&&(a++,(M.isDirectionalLight||M.isSpotLight)&&(c++,M.castShadow&&l++)),!M.isMesh||M.visible===!1)return;let S=this.site.bevelled.get(M);(S||wi(M))&&u++;let k=S??M.geometry,E=k?.parameters;(E&&k.type==="SphereGeometry"&&(E.widthSegments??32)<24||E&&(k.type==="CylinderGeometry"||k.type==="ConeGeometry")&&(E.radialSegments??32)>12&&(E.radialSegments??32)<24)&&f++;for(let L of Te(M)){d.add(L);for(let A of vi)L[A]?.isTexture&&p.add(L[A])}});let m=0,g=0,h=0;for(let M of d)M.isMeshStandardMaterial||M.isMeshPhysicalMaterial?(m++,(M.metalness??0)>=.9&&h++):(M.isMeshBasicMaterial||M.isMeshLambertMaterial||M.isMeshPhongMaterial||M.isMeshToonMaterial)&&g++;let b=0;for(let M of p)(this.site.anisotropy.get(M)??M.anisotropy??1)<=1&&b++;let y=this.site.environment!==void 0?this.site.environment:r.environment,v=o?.near,x=o?.far;return{revision:this.revision(),toneMapping:this.site.toneMapping??(typeof n.toneMapping=="number"?n.toneMapping:null),exposure:this.site.exposure??(typeof n.toneMappingExposure=="number"?n.toneMappingExposure:null),srgbOutput:s,pixelRatio:this.site.pixelRatio??n.getPixelRatio?.()??1,devicePixelRatio:this.kit.devicePixelRatio(),antialias:i,hasEnvironment:!!y,lights:a,pbrMaterials:m,simpleMaterials:g,metals:h,shadowsEnabled:this.site.shadowsEnabled??!!n.shadowMap?.enabled,shadowLights:l,shadowCapableLights:c,hardEdgeMeshes:u,lowPolyRound:f,textures:p.size,texturesWithoutAnisotropy:b,depthRatio:typeof v=="number"&&typeof x=="number"&&v>0?x/v:null,sitePostProcessing:t.sitePostProcessing,effectsAvailable:t.effectsAvailable}}};var Ql=e=>e?Object.getPrototypeOf(e):null;function Mi(e,t){let n=null;for(let o=Ql(e);o&&o!==Object.prototype;o=Ql(o))Object.prototype.hasOwnProperty.call(o,t)&&(n=o);let r=n&&n.constructor;return typeof r=="function"?r:null}function Zl(e,t,n=8e3){let r=[e],o=0;for(;r.length&&o<n;){let i=r.pop();if(o++,t(i)===!0)return;for(let s of i.children??[])r.push(s)}}function ec(e){let t=o=>!!o&&typeof o=="object"&&o.isTexture===!0,n=e;if(t(n.environment))return n.environment;if(t(n.background))return n.background;let r=null;return Zl(e,o=>{let i=Array.isArray(o.material)?o.material:o.material?[o.material]:[];for(let a of i)for(let l of Object.values(a))if(t(l))return r=l,!0;let s=o.shadow?.map?.texture;return t(s)?(r=s,!0):!1}),r}function Nr(){let e={},t={isSource:!0,uuid:crypto.randomUUID(),data:null,dataReady:!0,version:0},n={isTexture:!0,isRenderTargetTexture:!1,uuid:crypto.randomUUID(),name:"",source:t,mipmaps:[],channel:0,wrapS:1001,wrapT:1001,anisotropy:1,internalFormat:null,offset:{x:0,y:0},repeat:{x:1,y:1},center:{x:0,y:0},rotation:0,matrixAutoUpdate:!1,matrix:{elements:[1,0,0,0,1,0,0,0,1]},premultiplyAlpha:!1,userData:{},updateRanges:[],version:0,pmremVersion:0,onUpdate:null,addEventListener(r,o){let i=e[r]??=[];i.includes(o)||i.push(o)},hasEventListener:(r,o)=>!!e[r]?.includes(o),removeEventListener(r,o){let i=e[r],s=i?i.indexOf(o):-1;s>=0&&i.splice(s,1)},dispatchEvent(r){for(let o of[...e[String(r.type)]??[]])o.call(n,{...r,target:n})},clearUpdateRanges(){n.updateRanges.length=0},updateMatrix(){},dispose(){n.dispatchEvent({type:"dispose"})}};return Object.defineProperty(n,"image",{get:()=>t.data,set:r=>{t.data=r}}),Object.defineProperty(n,"needsUpdate",{set:r=>{r&&(n.version++,t.version++)}}),n}function zr(e){let t=ec(e),n=t?Mi(t,"updateMatrix"):null;try{return n?new n:Nr()}catch{return Nr()}}function jd(e){let t=(n,r,o)=>{let i=ec(e),s=i?Mi(i,"updateMatrix"):null,a;try{a=s?new s:Nr()}catch{a=Nr()}return a.image={data:n,width:r,height:o},a.isDataTexture=!0,a.format=1023,a.flipY=!1,a.unpackAlignment=1,a.magFilter=1006,("colorSpace"in a||!s)&&(a.colorSpace=""),"encoding"in a&&(a.encoding=3e3),a};return{image(n,r){let o=t(n[0],r,r);return o.mipmaps=n.map((i,s)=>({data:i,width:r>>s,height:r>>s})),o.type=1009,o.wrapS=1e3,o.wrapT=1e3,o.minFilter=1008,o.generateMipmaps=!1,o.anisotropy=8,o.name="Depthview detail",o.needsUpdate=!0,o},texture(n,r,o){let i=t(n,r,o);return i.type=1016,i.mapping=303,i.minFilter=1006,i.generateMipmaps=!1,i.colorSpace===""&&(i.colorSpace="srgb-linear"),i.name="Depthview world",i.needsUpdate=!0,i},geometry(n){let r=null;Zl(e,u=>{let f=u.geometry?.attributes?.position;return u.isMesh&&f&&!f.isInterleavedBufferAttribute?(r=u,!0):!1});let o=r;if(!o)return null;let i=Mi(o.geometry,"setAttribute"),s=o.geometry.attributes.position.constructor;if(!i)return null;let a=new i,l=a.setAttribute,c=new s(n.position,3);return!(c.array instanceof Float32Array)||c.count!==n.position.length/3?null:(l.call(a,"position",c),l.call(a,"normal",new s(n.normal,3)),l.call(a,"uv",new s(n.uv,2)),a.name="Depthview bevel",a)},dispose(n){try{n?.dispose?.()}catch{}},devicePixelRatio:()=>window.devicePixelRatio||1}}var tc=()=>{let e=window.__DEPTHVIEW_LOOK__;return e&&typeof e.load=="function"?e:null},ye=null,it=null,zn=null;function ki(){let e=_();if(!e)throw new Error("No active three.js scene.");return ye&&(ye.target.renderer!==e.renderer||ye.target.scene!==e.scene)&&Wr(),ye||(zn=Pe(),ye=new Dr({renderer:e.renderer,scene:e.scene,camera:e.camera},jd(e.scene))),ye.target.camera=e.camera,ye}function Yt(){T.effects=null;try{it?.handle.dispose()}catch{}it=null}async function Od(e,t){if(!_r(e)){Yt();return}let n=_(),r=tc();if(n){if(!r){Yt(),t.push("Lens effects (smooth edges, ambient occlusion, bloom, depth of field, vignette, grain) need the project's dev bridge: add depthviewVite() from depthview-r3f-bridge/vite to the plugins in the Vite config and reload. The rest of the look is applied.");return}if(zn){Yt(),t.push("This site already draws through its own post-processing, so Depthview does not add a second effect chain. Add these effects to the site's own composer in the code.");return}try{if(!it||it.renderer!==n.renderer){Yt();let i=await r.load();if(!i.sameThree(n.renderer)){t.push('Lens effects are off: the page renders with a different copy of three.js than the one depthview-r3f-bridge resolved. Add resolve: { dedupe: ["three"] } to the Vite config.');return}it={handle:i.createEffects(n.renderer),renderer:n.renderer,scene:n.scene}}it.scene=n.scene,it.handle.set(e);let o=it;T.effects=(i,s)=>i!==o.renderer||s!==o.scene||!o.handle.active||(i.getRenderTarget?i.getRenderTarget():null)!==null?null:((a,l)=>o.handle.render(a,l))}catch(o){Yt(),t.push(`Lens effects could not start: ${o instanceof Error?o.message:String(o)}. They need three >= 0.160 in the project.`)}}}function nc(e,t){let r=ki().facts({sitePostProcessing:zn??Pe(),effectsAvailable:tc()!==null});return{notes:t,facts:r,audit:Ir(r,e)}}function rc(e){return nc(ze(e),[])}async function oc(e){if(e==null)return Wr(),null;let t=ze(e),n=ki();try{n.target.scene.updateMatrixWorld?.(!0)}catch{}let r=[...n.apply(t)];return await Od(t.effects,r),nc(t,r)}function ic(){if(!ye)return{changed:!1};let e=_();if(!e||ye.target.scene!==e.scene)return{changed:!1};try{return{changed:ye.follow()}}catch{return{changed:!1}}}function sc(e){return ki().measure(e)}function Wr(){Yt();try{ye?.reset()}catch{}ye=null,zn=null}function ac(){ye=null,zn=null}var lc=()=>{let e=window.__DEPTHVIEW_CONTROLS__;return e&&typeof e.list=="function"&&typeof e.set=="function"?e:null};function cc(){try{return lc()?.list()??[]}catch{return[]}}function uc(e,t,n){let r=lc();if(!r)throw new Error("This page declares no Depthview controls.");if(!r.set(e,t,n))throw new Error(`No control "${e}.${t}" that takes ${JSON.stringify(n)}.`);return r.list()}var fc=e=>e?Object.getPrototypeOf(e):null;function hc(e,t){let n=null;for(let o=fc(e);o&&o!==Object.prototype;o=fc(o))Object.prototype.hasOwnProperty.call(o,t)&&(n=o);let r=n&&n.constructor;return typeof r=="function"?r:null}var pc=e=>Array.isArray(e.material)?e.material:e.material?[e.material]:[],Id=e=>new Promise(t=>setTimeout(t,e));function Fd(e){let t=_(),n=new Set(t?[t.scene,..._e()]:_e());for(let r of n){let o=[r],i=0;for(;o.length&&i<8e3;){let s=o.pop();i++,e(s);for(let a of s.children??[])o.push(a)}}}var dc=["MeshBasicMaterial","MeshLambertMaterial","MeshPhongMaterial","MeshToonMaterial","MeshStandardMaterial","MeshPhysicalMaterial","ShaderMaterial"];function gc(){let e=null,t=new Map;Fd(l=>{if(!l.isMesh||!l.geometry?.attributes?.position||je.has(l.uuid))return;let c=l.geometry.attributes.position;!e&&!c.isInterleavedBufferAttribute&&(e=l);for(let u of pc(l))u.type&&dc.includes(u.type)&&!t.has(u.type)&&t.set(u.type,u)});let n=e,r=dc.find(l=>t.has(l));if(!n||!r)throw new Error("This scene has no ordinary mesh with a built-in material to take the three.js classes from, so an effect cannot be made here. Use get_effect_code with a kind and add it in the source instead.");let o=hc(n.geometry,"setAttribute"),i=hc(n,"updateMorphTargets"),s=n.geometry.attributes.position.constructor,a=t.get(r).constructor;if(!o||!i)throw new Error("Could not find the mesh classes of this site.");return{Geometry:o,Attribute:s,Mesh:i,Material:a}}function bc(e,t){let n=Tl(t),r=new e.Geometry,o=r.setAttribute,i=new e.Attribute(n.position,3);if(!(i.array instanceof Float32Array)||i.count!==n.position.length/3)throw new Error("Could not build geometry with the classes of this site.");return o.call(r,"position",i),n.normal&&o.call(r,"normal",new e.Attribute(n.normal,3)),n.uv&&o.call(r,"uv",new e.Attribute(n.uv,2)),n.corner&&o.call(r,"dvCorner",new e.Attribute(n.corner,2)),n.seed&&o.call(r,"dvSeed",new e.Attribute(n.seed,4)),r.name="Depthview effect",r}var je=new Map,Vd=0,Dd={front:0,back:1,double:2},Zt=(e,t)=>new RegExp(`\\buniform\\s+\\w+\\s+${t}\\b`).test(e.vertex+e.fragment),Ur=1e3,Ei=1006,Br=null;function Nd(e){if(Br?.scene===e)return Br.texture;let t=zr(e);return t.image={data:Al(),width:Ar,height:Ar},t.isDataTexture=!0,t.format=1023,t.type=1009,t.flipY=!1,t.unpackAlignment=1,t.wrapS=Ur,t.wrapT=Ur,t.magFilter=Ei,t.minFilter=Ei,t.generateMipmaps=!1,"colorSpace"in t&&(t.colorSpace=""),"encoding"in t&&(t.encoding=3e3),t.name="Depthview noise",t.needsUpdate=!0,Br={scene:e,texture:t},t}var mc=new WeakMap;function zd(e,t,n){let r=mc.get(e);if(!r){let o=zr(t);o.name="Depthview scene depth",o.magFilter=1003,o.minFilter=1003,o.generateMipmaps=!1,r={holder:o,texture:null},mc.set(e,r)}if(r.texture!==n){let o=e.properties;if(!o||typeof o.get!="function")return null;let i=o.get(r.holder);i.__webglTexture=n,i.__webglInit=!0,r.texture=n}return r.holder}var Ti=new Map;async function yc(e,t,n){if(t.startsWith("scene:")){let c=_s(t.slice(6));if(!c)throw new Error(`No texture with id ${t.slice(6)} in the scene. get_resources lists the textures with their ids.`);return c}let r=Ti.get(t);if(r&&!n)return r;if(!n?.startsWith("data:image/"))throw new Error(`The image for ${t} did not arrive. Give a path to an image in the project.`);let o=atob(n.slice(n.indexOf(",")+1)),i=new Uint8Array(o.length);for(let c=0;c<o.length;c++)i[c]=o.charCodeAt(c);let s=n.slice(5,n.indexOf(";")),a=await createImageBitmap(new Blob([i],{type:s}),{imageOrientation:"flipY"}),l=zr(e);return l.image=a,l.flipY=!1,l.wrapS=Ur,l.wrapT=Ur,l.magFilter=Ei,l.name=t.slice(5),"colorSpace"in l?l.colorSpace="srgb":"encoding"in l&&(l.encoding=3001),l.needsUpdate=!0,Ti.set(t,l),l}async function vc(e,t){let n=_();if(n)for(let[r,o]of Object.entries(e.spec.uniforms)){if(!ce(o))continue;let i=await yc(n.scene,o.texture,t?.[r]);e.uniforms[r]?e.uniforms[r].value=i:e.uniforms[r]={value:i}}}function Hr(e){let{spec:t,uniforms:n}=e;for(let[r,o]of Object.entries(t.uniforms)){if(ce(o)){n[r]??={value:null};continue}let i=ci(o);n[r]?n[r].value=i:n[r]={value:i}}for(let r of Object.keys(n))!(r in t.uniforms)&&!(r in Vn)&&delete n[r];n.uTime??={value:0},n.uResolution??={value:[1,1]},n.uCameraLocal??={value:[0,0,0]},n.uNoise??={value:null},n.uDepth??={value:null},n.uHasDepth??={value:0},n.uDepthToLocal??={value:[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}}function Ri(e){let t=e.id,n=e.material;e.version++;let r=`DV_EFFECT_${t}_${e.version}`,o={...n.defines??{}};for(let i of Object.keys(o))i.startsWith("DV_EFFECT_")&&delete o[i];o[r]=1,n.defines=o,n.customProgramCacheKey=()=>r,n.needsUpdate=!0}function wc(e){let{spec:t,material:n}=e;n.transparent=t.transparent,n.depthWrite=t.depthWrite,(!t.volume||n.side===void 0||e.version===0)&&(n.depthTest=t.depthTest,n.side=Dd[t.side]),n.blending=t.blending==="additive"?2:1,n.fog=!1,n.name=t.name}async function Pi(e){let t=_();if(!t)return[];let n=[];for(let r=0;r<6&&(await Id(120),n=Jo(t.renderer,e),!n.length);r++);return n}var Qt=e=>Math.round(e*1e4)/1e4;function qr(e,t){let{position:n,scale:r}=t.object,o=_();return{uuid:e,...Zt(t.spec,"uDepth")&&o?{sceneDepth:Ll(o.renderer)}:{},spec:{...t.spec,position:[Qt(n.x),Qt(n.y),Qt(n.z)],scale:[Qt(r.x),Qt(r.y),Qt(r.z)]}}}async function xc(e,t,n){let r=_();if(!r)throw new Error("No active three.js scene.");let o=e.parent?re(e.parent):r.scene;if(!o)throw new Error(`No object with id ${e.parent} to add to.`);let i=Cr(e,t),s=gc(),a=++Vd,l=new s.Material,c=new s.Mesh(bc(s,i),l),u={spec:i,object:c,material:l,uniforms:{},version:0,id:a};Hr(u),await vc(u,n);let f=r.scene;l.onBeforeCompile=m=>{m.vertexShader=u.spec.vertex,m.fragmentShader=Rl(u.spec.fragment),Object.assign(m.uniforms,u.uniforms)},wc(u),Ri(u);let d=performance.now();c.onBeforeRender=(m,g,h)=>{try{let b=u.uniforms,y=u.spec;b.uTime.value=(performance.now()-d)/1e3;let v=m.getContext?.(),x=v?v.getParameter(v.VIEWPORT):null;x&&(b.uResolution.value=[x[2],x[3]]),Zt(y,"uNoise")&&(b.uNoise.value??=Nd(f));let M=y.volume||Zt(y,"uCameraLocal")||Zt(y,"uDepthToLocal")?be(c.matrixWorld.elements):null,S=[0,0,10];if(M){let E=h.matrixWorld.elements;S=oe(M,[E[12],E[13],E[14]]),b.uCameraLocal.value=S}let k=!1;if(Zt(y,"uDepth")){let E=Cl(m),L=E?zd(m,f,E.texture):null;if(k=L!==null,b.uDepth.value=L,b.uHasDepth.value=k?1:0,k&&M&&Zt(y,"uDepthToLocal")){let A=h.matrixWorldInverse?.elements,C=A?be(ae(h.projectionMatrix.elements,A)):null;C?b.uDepthToLocal.value=ae(M,C):b.uHasDepth.value=0}}if(y.volume){let E=Math.max(Math.abs(S[0]),Math.abs(S[1]),Math.abs(S[2]))<.5,L=k||E?1:0,A=k||E?!1:y.depthTest;(l.side!==L||l.depthTest!==A)&&(l.side=L,l.depthTest=A,l.needsUpdate=!0)}}catch{}},c.name=i.name,c.frustumCulled=!1,c.castShadow=!1,c.receiveShadow=!1,c.position.set(...i.position),c.scale.set(...i.scale),o.add(c),c.updateMatrixWorld(!0),je.set(c.uuid,u);let p=await Pi(l);return p.length?(Gr(c.uuid),{uuid:"",spec:i,applied:!1,errors:p}):{...qr(c.uuid,u),applied:!0,errors:[]}}async function Sc(e,t,n){let r=je.get(e);if(!r)throw new Error("That object is not an effect made with add_effect.");let o=r.spec,i=kl(o,t),s=i.vertex!==o.vertex||i.fragment!==o.fragment;r.spec=i,Hr(r);try{await vc(r,n)}catch(a){throw r.spec=o,Hr(r),a}if(wc(r),r.object.name=i.name,i.count!==o.count){let a=r.object.geometry;r.object.geometry=bc(gc(),i);try{a?.dispose?.()}catch{}}if(s){Ri(r);let a=await Pi(r.material);if(a.length)return r.spec={...i,vertex:o.vertex,fragment:o.fragment,kind:o.kind},Hr(r),Ri(r),{...qr(e,r),applied:!1,errors:a}}return{...qr(e,r),applied:!0,errors:[]}}function Mc(){let e=[];for(let[t,n]of je)n.object.parent&&e.push(qr(t,n));return e}var kc=e=>je.has(e);function Gr(e){let t=je.get(e);if(!t)return!1;je.delete(e);try{t.object.parent?.remove(t.object),t.object.geometry?.dispose?.(),t.material.dispose?.()}catch{}return!0}var en=new Map;function Ai(e){let t=e.material;t.onBeforeCompile=e.onBeforeCompile,t.customProgramCacheKey=e.customProgramCacheKey,t.defines=e.defines,t.needsUpdate=!0;let n=e.object;e.hadOwnRender?n.onBeforeRender=e.onBeforeRender:delete n.onBeforeRender,en.delete(t)}async function Ec(e,t,n){let r=re(e),o=r?pc(r)[0]:void 0;if(!r||!o)throw new Error("That object has no material.");if(je.has(e))throw new Error("That is an effect: change its shader with set_effect instead.");if(o.type==="RawShaderMaterial"||o.type==="ShaderMaterial")throw new Error(`${o.type} has its own shader source: replace it with set_shader instead.`);let i=o.type??"Material",s=en.get(o);if(t.length===0)return s&&Ai(s),{applied:!0,errors:[],missed:[],material:i};let a=r,l=s??{material:o,object:r,onBeforeCompile:o.onBeforeCompile,customProgramCacheKey:o.customProgramCacheKey,defines:o.defines,onBeforeRender:a.onBeforeRender,hadOwnRender:Object.prototype.hasOwnProperty.call(a,"onBeforeRender"),uniforms:{},patches:[],missed:[],version:0},c={patches:l.patches,uniforms:{...l.uniforms}};l.patches=t;for(let[p,m]of Object.entries(n)){let g=ce(m)?await yc(_().scene,m.texture,void 0):ci(m);l.uniforms[p]?l.uniforms[p].value=g:l.uniforms[p]={value:g}}l.uniforms.uTime??={value:0};let u=()=>{l.version++,l.missed=[];let p=`DV_PATCH_${l.version}_${o.uuid??""}`,m=l.customProgramCacheKey;o.customProgramCacheKey=()=>`${typeof m=="function"?m.call(o):""}|${p}`,o.onBeforeCompile=(g,h)=>{typeof l.onBeforeCompile=="function"&&l.onBeforeCompile.call(o,g,h);for(let b of l.patches){let y=b.stage==="vertex"?"vertexShader":"fragmentShader";if(!g[y].includes(b.find)){l.missed.push(b.find);continue}g[y]=g[y].replace(b.find,b.replace)}Object.assign(g.uniforms,l.uniforms)},o.needsUpdate=!0};if(!s){let p=performance.now(),m=l.onBeforeRender;a.onBeforeRender=function(...g){l.uniforms.uTime.value=(performance.now()-p)/1e3,typeof m=="function"&&m.apply(this,g)},en.set(o,l)}u();let f=await Pi(o),d=[...new Set(l.missed)];return f.length||d.length?(s?(l.patches=c.patches,l.uniforms=c.uniforms,u()):Ai(l),{applied:!1,errors:f,missed:d,material:i}):{applied:!0,errors:[],missed:[],material:i}}function Tc(){return[...en.values()].map(e=>({uuid:e.object.uuid,name:e.object.name||"",type:e.material.type??"Material",patches:e.patches,uniforms:Object.keys(e.uniforms)}))}function Rc(){for(let e of[...je.keys()])Gr(e);for(let e of[...en.values()])try{Ai(e)}catch{}}function Ac(){je.clear(),en.clear(),Ti.clear(),Br=null}var We=e=>e!==null&&typeof e=="object"?e:null,Bd=e=>Math.round(e).toLocaleString("en-US"),X=(e,t,n=`${t}s`)=>`${Bd(e)} ${e===1?t:n}`,Hd=e=>Array.isArray(e.material)?e.material:e.material?[e.material]:[];function Pc(e,t,n=2e4){let r=[e],o=0;for(;r.length&&o<n;){let i=r.pop();if(o++,t(i),Array.isArray(i.children))for(let s of i.children)r.push(s)}return o}function Ud(e){let t=[],n=window,r=u=>{try{return We(n[u])??(typeof n[u]=="function"?n[u]:null)}catch{return null}},o=[...document.scripts].map(u=>u.src.toLowerCase()).join(" "),i=document.documentElement,s=(u,f)=>{t.some(d=>d.name===u)||t.push({name:u,detail:f})},a=(We(n.__THREE__)?null:n.__THREE__)??null;s(`three.js${a?` r${a}`:""}`,"The 3D engine: scene graph, cameras, materials and the WebGL renderer."),We(e)?.__r3f&&s("React Three Fiber","The scene is written as React components that create three.js objects.");let l=r("gsap");if((l||/gsap|greensock/.test(o))&&s(`GSAP${typeof l?.version=="string"?` ${l.version}`:""}`,"Animation library: tweens and timelines move values over time."),(r("ScrollTrigger")||/scrolltrigger/.test(o))&&s("GSAP ScrollTrigger","Ties animations to the scroll position."),(r("lenis")||r("Lenis")||i.classList.contains("lenis")||/lenis/.test(o))&&s("Lenis","Smooth scrolling: the page eases towards where the wheel sent it."),(i.classList.contains("has-scroll-smooth")||r("LocomotiveScroll"))&&s("Locomotive Scroll","Smooth scrolling with scroll-linked effects."),(r("__TheatreJS_StudioBundle")||r("__TheatreJS_CoreBundle")||/theatre/.test(o))&&s("Theatre.js","Keyframe animation timeline, often driving the camera."),(r("Howler")||r("Howl"))&&s("Howler.js","Audio playback."),r("barba")&&s("Barba.js","Page transitions without a full reload."),(r("lottie")||r("bodymovin"))&&s("Lottie","Plays vector animations exported from After Effects."),(r("CANNON")||r("RAPIER")||r("Ammo"))&&s("Physics engine","Simulates collisions and gravity."),r("__NEXT_DATA__")||r("next")||document.getElementById("__next"))s("Next.js","React framework serving the page.");else if(r("__NUXT__")||document.getElementById("__nuxt"))s("Nuxt","Vue framework serving the page.");else if(r("__VUE__")||document.querySelector("[data-v-app]"))s("Vue","UI framework for the HTML part.");else if(document.querySelector("astro-island"))s("Astro","Site framework serving the page.");else if(document.querySelector("[data-reactroot], #root, #app")){let u=document.querySelector("#root, #app, [data-reactroot]");u&&Object.keys(u).some(f=>f.startsWith("__react"))&&s("React","UI framework for the HTML part.")}i.hasAttribute("data-wf-site")&&s("Webflow","The HTML page is built in Webflow.");let c=document.querySelector('meta[name="generator"]')?.getAttribute("content");return c&&s(c.slice(0,40),"Named by the page as its generator."),(/vite/.test(o)||document.querySelector('script[type="module"][src*="/assets/"]'))&&s("Bundled ES modules","The code ships as one bundled module (Vite-style build)."),t}var qd=["none","Linear","Reinhard","Cineon","ACES Filmic","custom","AgX","Neutral"];function Gd(e){let t=[],n=e,r=e.domElement;try{let s=e.getContext?.(),a=s?.getContextAttributes(),l=typeof WebGL2RenderingContext<"u"&&s instanceof WebGL2RenderingContext;t.push({name:"Context",detail:l?"WebGL 2":"WebGL 1"});let c=e.getPixelRatio?.()??1;t.push({name:"Picture size",detail:`${r.width} \xD7 ${r.height} px (pixel ratio ${Math.round(c*100)/100})`}),a&&(t.push({name:"Anti-aliasing",detail:a.antialias?"built-in (MSAA on the canvas)":"off on the canvas: edges are left as they are or smoothed in a shader pass"}),t.push({name:"Canvas",detail:a.alpha?"transparent: the page shows through":"opaque"}))}catch{}let o=typeof n.toneMapping=="number"?qd[n.toneMapping]:void 0;o&&t.push({name:"Tone mapping",detail:o}),typeof n.outputColorSpace=="string"&&t.push({name:"Output colour space",detail:n.outputColorSpace||"linear"});let i=We(n.shadowMap);return t.push({name:"Shadow maps",detail:i?.enabled?"on":"off"}),t}function Kd(){let e=-1/0;for(let n of T.pairs)n.t>e&&(e=n.t);let t=[];for(let n of T.pairs){let r=n.scene.deref(),o=n.camera.deref();if(!r||!o||e-n.t>120)continue;let i=We(n.target?.deref()),s=Number(i?.width)||0,a=Number(i?.height)||0,l=0;Pc(r,d=>{(d.isMesh||d.isPoints||d.isLine||d.isSprite)&&l++});let c=(r.children??[]).map(d=>d.name).filter(Boolean).slice(0,3),u=l<=1&&(r.children?.length??0)<=1?"fullscreen":"scene",f=!!i&&s<=512&&a<=512;t.push({scene:r,width:s,height:a,done:n.done,pass:{scene:c.length?c.join(", ")+((r.children?.length??0)>3?"\u2026":""):"unnamed",camera:o.isOrthographicCamera?"orthographic":o.isPerspectiveCamera?"perspective":"none",target:i?`${s} \xD7 ${a} off-screen`:"screen",objects:l,kind:u,note:u==="fullscreen"?f?"A shader runs over a small data picture: values are computed on the GPU and kept for the next frame (simulation).":i?"A shader runs over a whole picture: an effect step, or pictures being mixed.":"The final shader: mixes the pictures drawn before it and puts the result on screen.":o.isOrthographicCamera?"A flat layer drawn in screen coordinates: interface, text, labels.":i?"A 3D scene drawn into an off-screen picture, to be processed before it is shown.":"A 3D scene drawn straight to the screen."}})}return t.sort((n,r)=>n.done-r.done)}function Xd(e,t,n){let r=new Map,o=_()?.scene,i=(b,y,v,x=1)=>{let M=r.get(b);M||r.set(b,M={objects:new Map,n:0}),M.n+=x,y&&M.objects.size<12&&M.objects.set(y.uuid,{name:y.name||y.type,uuid:v?y.uuid:void 0})},s=new Set,a=0,l=0;for(let b of e){let y=b===o,v=b;v.fog&&i("fog",null,!1),v.environment&&i("environment",null,!1),Pc(b,x=>{let M=x;if(x.isLight){a++,x.castShadow&&i("shadows",x,y);return}if(!(x.isMesh||x.isPoints||x.isLine||x.isSprite))return;l++,x.isPoints&&i("particles",x,y,x.geometry?.attributes?.position?.count??0),x.isLine&&i("lines",x,y),x.isInstancedMesh&&i("instancing",x,y,Number(M.count)||0),x.isSkinnedMesh&&i("skinning",x,y);let S=We(We(x.geometry)?.morphAttributes);S&&Object.keys(S).length&&i("morph",x,y);for(let k of Hd(x)){let E=!s.has(k);s.add(k);let L=k;if(typeof k.vertexShader=="string"&&typeof k.fragmentShader=="string"&&!!k.uniforms){i("shader",x,y,E?1:0);let C=Object.keys(k.uniforms??{}).join(" ");/time|elapsed/i.test(C)&&i("time",x,y,E?1:0),/mouse|pointer|cursor|hover/i.test(C)&&i("pointer",x,y,E?1:0),/scroll|progress/i.test(C)&&i("scroll",x,y,E?1:0),/msdf|sdf/i.test(C)&&i("sdf",x,y,E?1:0);let O=k.vertexShader.length<2e5?k.vertexShader:"",P=k.fragmentShader.length<2e5?k.fragmentShader:"";/snoise|cnoise|simplex|perlin|fbm|noise\s*\(/i.test(O+P)&&i("noise",x,y,E?1:0),/fresnel/i.test(P)&&i("fresnel",x,y,E?1:0),/texture(2D)?\s*\(/.test(O)&&i("vertexTexture",x,y,E?1:0)}if(L.blending===2&&i("additive",x,y,E?1:0),L.envMap&&i("environment",x,y,E?1:0),E){let C=Object.values(L);for(let O of Object.values(k.uniforms??{}))C.push(O?.value);for(let O of C){let P=We(O);P?.isTexture&&(P.isVideoTexture&&i("video",x,y),P.isCompressedTexture&&i("compressed",x,y),P.isDataTexture&&i("dataTexture",x,y),P.isRenderTargetTexture&&i("feedback",x,y))}}}})}let c=t.filter(b=>b.pass.target!=="screen"),u=t.filter(b=>b.pass.kind==="fullscreen"&&b.width>0&&b.width<=512&&b.height<=512),f=t.filter(b=>b.pass.kind==="scene"),d=!!We(n.shadowMap)?.enabled,p=[],m=(b,y,v,x,M,S)=>{p.push({id:b,name:y,amount:v,what:x,how:M,api:S,objects:[...r.get(b)?.objects.values()??[]]})},g=b=>r.get(b)?.n??0,h=b=>r.has(b);return h("shader")&&m("shader","Custom shaders",X(g("shader"),"material"),"These surfaces are not built-in three.js materials: the site wrote its own GPU programs for them.",'A vertex shader places every vertex and a fragment shader colours every pixel. Values such as time, colours and textures are passed in as uniforms. Open "View shader" or "Node graph" on one of these objects to read it.',"THREE.ShaderMaterial, uniforms, GLSL"),c.length&&m("post","Off-screen rendering and post-processing",X(c.length,"off-screen draw")+" per frame","The scene is not drawn straight to the screen. It is drawn into pictures first, and shaders work on those pictures before the result is shown.","Create a render target, draw the scene into it, then draw one shape covering the screen whose shader reads that picture as a texture. Blur, glow, colour grading and scene transitions are all done this way.","THREE.WebGLRenderTarget, renderer.setRenderTarget(), EffectComposer"),f.length>1&&m("multi","Several scenes mixed into one picture",X(f.length,"scene")+" per frame","More than one scene is drawn each frame, each with its own camera, and a final shader blends them: a 3D world with a flat interface layer on top, or two sections while one turns into the next.","Keep one THREE.Scene per section. Draw each into its own render target and blend the textures in a full-screen shader with a progress value from 0 to 1.","THREE.Scene, THREE.WebGLRenderTarget, mix() in GLSL"),u.length&&m("gpgpu","Simulation on the GPU",X(u.length,"data picture"),"Small off-screen pictures are used as data, not as images: each pixel stores a number such as a position or a speed, updated every frame.","Draw a full-screen shape into a small float render target; the shader reads last frame's picture and writes the next state. Another shader then reads it to place particles or bend a surface.","THREE.WebGLRenderTarget (FloatType), GPUComputationRenderer, ping-pong buffers"),h("particles")&&m("particles","Particles",`${X(g("particles"),"point")} in ${X(r.get("particles").objects.size,"system")}`,"Many small dots drawn in one call: snow, dust, sparks.","Put one position per particle in a BufferGeometry and draw it with THREE.Points. A shader moves them, usually from a time uniform, so the CPU does no per-particle work.","THREE.Points, THREE.BufferGeometry, gl_PointSize"),h("instancing")&&m("instancing","Instancing",X(g("instancing"),"copy","copies"),"One shape is drawn many times in a single call, each copy with its own position.","Create an InstancedMesh with a count, and set a matrix per copy. Thousands of objects cost about as much as one.","THREE.InstancedMesh, setMatrixAt(), InstancedBufferAttribute"),h("lines")&&m("lines","Line drawings",X(r.get("lines").objects.size,"object"),"Thin lines: outlines, connectors between points, technical-looking overlays.","Give a BufferGeometry pairs of points and draw it with LineSegments. Move the points each frame (or in the shader) to make the lines follow objects.","THREE.LineSegments, THREE.LineBasicMaterial"),h("time")&&m("time","Animation inside the shader",X(g("time"),"material"),"These materials receive the time every frame and move by themselves on the GPU: drifting smoke, waves, flicker.","Add a uniform holding the elapsed seconds, update it in the render loop and use it in the shader, for example to offset texture coordinates or feed a noise function.","uniforms.uTime.value = clock.getElapsedTime()"),h("pointer")&&m("pointer","Reacts to the pointer",X(g("pointer"),"material"),"The pointer position is passed into these shaders, so the surface responds under the mouse.","Listen to pointermove, convert the position to -1..1, find the point under it with a Raycaster and write it into a uniform. Ease the value so the reaction feels soft.","THREE.Raycaster, pointermove, a vec2/vec3 uniform"),h("scroll")&&m("scroll","Driven by scroll or a progress value",X(g("scroll"),"material"),"These shaders receive a progress number, so the effect follows how far the visitor has scrolled.","Turn the scroll position into a number from 0 to 1, ease it, and write it into a uniform and into the camera position. Everything keyed to that one number stays in step.","scroll progress uniform, GSAP ScrollTrigger or a wheel listener"),h("noise")&&m("noise","Procedural noise",X(g("noise"),"material"),"Organic, never-repeating variation computed in the shader: clouds, smoke, uneven surfaces.",'Include a noise function (simplex, Perlin or layered "fbm") in the shader and feed it position plus time. No texture is needed.',"snoise(), fbm() in GLSL"),h("fresnel")&&m("fresnel","Fresnel edge glow",X(g("fresnel"),"material"),"Surfaces brighten where they turn away from the camera, which reads as glass, ice or a rim light.","In the fragment shader compare the surface normal with the direction to the camera: pow(1.0 - dot(normal, viewDir), power).","cameraPosition, normal, dot() in GLSL"),h("vertexTexture")&&m("vertexTexture","Geometry shaped by a texture",X(g("vertexTexture"),"material"),"The vertex shader reads a texture to decide where vertices go: displacement, or positions computed in a simulation step.","Sample a texture in the vertex shader and add the value to the position before projecting it.","texture2D() in the vertex shader, displacementMap"),h("sdf")&&m("sdf","Text drawn in WebGL",X(g("sdf"),"material"),"Text is drawn inside the 3D scene from a distance-field font texture, so it stays sharp at any size and can be animated by a shader.","Generate an MSDF font atlas, build one quad per letter and use a shader that takes the median of the three colour channels as the letter edge.","MSDF font atlas, three-msdf-text, troika-three-text"),h("additive")&&m("additive","Additive blending",X(g("additive"),"material"),"Colours are added to what is behind them instead of covering it: glows, light shafts, sparks.","Set the material to additive blending and switch depth writing off so layers do not cut each other.","material.blending = THREE.AdditiveBlending, depthWrite = false"),h("feedback")&&m("feedback","One draw feeding another",X(g("feedback"),"material"),"These materials use a picture drawn earlier in the same frame as a texture: reflections, refraction through glass, trails.","Draw into a render target, then assign target.texture to a uniform or map of another material.","renderTarget.texture as a uniform"),h("video")&&m("video","Video textures",X(g("video"),"material"),"A playing video is used as a surface texture.","Create a <video>, play it and wrap it in a VideoTexture.","THREE.VideoTexture"),h("compressed")&&m("compressed","GPU-compressed textures",X(g("compressed"),"material"),"Textures stay compressed in video memory, so large images cost a fraction of the memory.","Export textures as KTX2/Basis and load them with KTX2Loader.","KTX2Loader, CompressedTexture"),h("dataTexture")&&m("dataTexture","Data textures",X(g("dataTexture"),"material"),"Textures filled from numbers by code rather than from an image: lookup tables, positions, noise.","Fill a typed array and wrap it in a DataTexture.","THREE.DataTexture"),h("environment")&&m("environment","Environment lighting","in use","Surfaces are lit and reflect from a surrounding image instead of (or on top of) lamps.","Load an HDR image, set it as scene.environment; physically based materials pick it up.","scene.environment, RGBELoader, PMREMGenerator"),h("fog")&&m("fog","Fog","in use","Distant objects fade into a colour, which hides the edge of the world and adds depth.","Set scene.fog; built-in materials apply it automatically.","THREE.Fog, THREE.FogExp2"),h("skinning")&&m("skinning","Skeletal animation",X(r.get("skinning").objects.size,"mesh","meshes"),"A mesh is bent by a skeleton of bones, as characters are.","Export the rigged model as glTF and play its clips with an AnimationMixer.","THREE.SkinnedMesh, AnimationMixer, GLTFLoader"),h("morph")&&m("morph","Morph targets",X(r.get("morph").objects.size,"mesh","meshes"),"A mesh blends between stored shapes.","Export shape keys in glTF and animate morphTargetInfluences.","morphTargetInfluences"),a===0&&l>0?m("nolights","No light objects",`${X(l,"object")}, 0 lights`,"Nothing in the scene is a three.js light. The lighting you see is painted into the textures beforehand (baked) or computed by the custom shaders.","Bake lighting in Blender into the colour textures and show them with unlit materials or simple shaders. It looks rich and costs almost nothing per frame.","baked lightmaps, THREE.MeshBasicMaterial, custom shaders"):a>0&&m("lights","Real-time lights",`${X(a,"light")}${d&&h("shadows")?", with shadow maps":", no shadow maps"}`,"Light objects in the scene light the materials every frame.","Add lights to the scene and use lit materials (Standard, Physical). Turn on renderer.shadowMap and castShadow/receiveShadow for shadows.","THREE.DirectionalLight, MeshStandardMaterial, renderer.shadowMap"),p}function Jd(e){let t=[],r=(document.scrollingElement??document.documentElement).scrollHeight/Math.max(window.innerHeight,1),o=e.find(i=>/Lenis|Locomotive/.test(i.name));return r>1.2?t.push({name:"Scroll",detail:`Real page scroll, ${Math.round(r*10)/10} screens tall${o?`, smoothed by ${o.name}`:""}. The scroll position is turned into progress for the camera and the animations.`}):T.wheelListeners>0?t.push({name:"Scroll",detail:"The page itself does not scroll. The site listens to the wheel and moves its own timeline, so it controls speed, snapping and looping."}):t.push({name:"Scroll",detail:"The page does not scroll and no wheel listener was seen."}),t.push({name:"Render loop",detail:"The site redraws on requestAnimationFrame, once per screen refresh."}),e.some(i=>i.name.startsWith("GSAP"))&&t.push({name:"Tweens",detail:"GSAP eases values between states (camera moves, fades, text reveals)."}),e.some(i=>i.name==="Theatre.js")&&t.push({name:"Keyframes",detail:"Theatre.js plays a hand-authored keyframe sequence."}),t}function Cc(){let e=_();if(!e)return null;let t=Kd(),n=[...new Set([e.scene,...t.filter(o=>o.pass.kind==="scene").map(o=>o.scene)])],r=Ud(e.scene);return{stack:r,renderer:Gd(e.renderer),passes:t.map(o=>o.pass),techniques:Xd(n,t,e.renderer),motion:Jd(r)}}var jc=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],st=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Wn=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],nn=e=>Math.hypot(e[0],e[1],e[2]),Kr=e=>{let t=nn(e);return t>1e-12?Wn(e,1/t):[0,0,0]},Ci=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]];function at(e){let t=[...e].sort((n,r)=>n.percent-r.percent);return t.filter((n,r)=>r===0||n.percent-t[r-1].percent>1e-6)}var Lc=(e,t)=>Math.abs(e[0]-t[0])<1e-6&&Math.abs(e[1]-t[1])<1e-6&&Math.abs(e[2]-t[2])<1e-6;function tn(e,t){return Lc(e.position,t.position)&&Lc(e.target,t.target)&&Math.abs(e.fov-t.fov)<1e-6}function $c(e,t,n,r,o){let i=o*o,s=i*o,a=[0,0,0];for(let l=0;l<3;l++)a[l]=.5*(2*t[l]+(-e[l]+n[l])*o+(2*e[l]-5*t[l]+4*n[l]-r[l])*i+(-e[l]+3*t[l]-3*n[l]+r[l])*s);return a}function Be(e,t){let n=at(e);if(!n.length)return null;let r=n[0],o=n[n.length-1],i=v=>({position:[...v.position],target:[...v.target],fov:v.fov});if(n.length===1||t<=r.percent)return i(r);if(t>=o.percent)return i(o);let s=0;for(;s<n.length-2&&t>n[s+1].percent;)s++;let a=n[s],l=n[s+1];if(tn(a,l))return i(a);let c=n[s-1],u=n[s+2],f=c&&!tn(c,a)?c:void 0,d=u&&!tn(u,l)?u:void 0,p=(t-a.percent)/(l.percent-a.percent),m=v=>[f?f[v]:st(Wn(a[v],2),l[v]),d?d[v]:st(Wn(l[v],2),a[v])],[g,h]=m("position"),[b,y]=m("target");return{position:$c(g,a.position,l.position,h,p),target:$c(b,a.target,l.target,y,p),fov:a.fov+(l.fov-a.fov)*p}}function Oc(e,t,n=[0,1,0]){let r=Kr(st(e,t));nn(r)===0&&(r=[0,0,1]);let o=Kr(Ci(n,r));if(nn(o)===0){let b=Math.abs(n[2])===1?[r[0]+1e-4,r[1],r[2]]:[r[0],r[1],r[2]+1e-4];o=Kr(Ci(n,Kr(b)))}let i=Ci(r,o),s=o[0],a=i[0],l=r[0],c=o[1],u=i[1],f=r[1],d=o[2],p=i[2],m=r[2],g=s+u+m;if(g>0){let b=.5/Math.sqrt(g+1);return[(p-f)*b,(l-d)*b,(c-a)*b,.25/b]}if(s>u&&s>m){let b=2*Math.sqrt(1+s-u-m);return[.25*b,(a+c)/b,(l+d)/b,(p-f)/b]}if(u>m){let b=2*Math.sqrt(1+u-s-m);return[(a+c)/b,.25*b,(f+p)/b,(l-d)/b]}let h=2*Math.sqrt(1+m-s-u);return[(l+d)/h,(f+p)/h,.25*h,(c-a)/h]}function Li(e){let[t,n,r,o]=e;return[-(2*(t*r+o*n)),-(2*(n*r-o*t)),-(1-2*(t*t+n*n))]}function Qd(e,t,n){let r=st(n,t),o=r[0]**2+r[1]**2+r[2]**2;if(o===0)return nn(st(e,t));let i=st(e,t),s=Math.max(0,Math.min(1,(i[0]*r[0]+i[1]*r[1]+i[2]*r[2])/o));return nn(st(e,jc(t,Wn(r,s))))}function _c(e,t,n=10){if(!e.length)return[];let r=new Set([0,e.length-1]);for(let l=1;l<e.length;l++)(e[l].section??null)!==(e[l-1].section??null)&&r.add(l);let o=Math.max(1e-9,...e.map(l=>nn(st(l.position,e[0].position))));for(;r.size<Math.min(n,e.length);){let l=[...r].sort((f,d)=>f-d),c=-1,u=o*.01;for(let f=0;f<l.length-1;f++){let d=l[f],p=l[f+1];for(let m=d+1;m<p;m++){let g=Qd(e[m].position,e[d].position,e[p].position);g>u&&(u=g,c=m)}}if(c<0)break;r.add(c)}let i=t>0?t:1,s=l=>Math.round(l*1e3)/1e3,a=l=>[s(l[0]),s(l[1]),s(l[2])];return[...r].sort((l,c)=>l-c).slice(0,Math.max(2,n)).map(l=>{let c=e[l];return{percent:s(c.percent),position:a(c.position),target:a(jc(c.position,Wn(Li(c.quaternion),i))),fov:s(c.fov)}})}var Xr=null,$i=null,ji=0;function Zd(){try{let n=Lt()?.timeline;if(n)return Math.min(100,Math.max(0,n.getProgress()*100))}catch{}let e=document.scrollingElement??document.documentElement,t=e.scrollHeight-e.clientHeight;return t>1?Math.min(100,Math.max(0,e.scrollTop/t*100)):ji}var em=1e-9;function tm(e){for(let t=0;t<16;t++)if(Math.abs(e[t]-(t%5===0?1:0))>em)return!1;return!0}function nm(e){if(!Xr||e!==$i)return null;let t=Be(Xr,Zd());if(!t)return null;let n={p:[e.position.x,e.position.y,e.position.z],q:[e.quaternion.x,e.quaternion.y,e.quaternion.z,e.quaternion.w],fov:e.fov},r=t.position,o=Oc(t.position,t.target),i=e.parent?.matrixWorld?.elements;if(i&&!tm(i)){let a=be(Array.from(i));if(a){let l=ae(a,et(r,o,[1,1,1]));r=le(l),o=Fe(l)}}e.position.set(...r),e.quaternion.set(...o);let s=e.isPerspectiveCamera===!0&&typeof e.fov=="number";return s&&e.fov!==t.fov&&(e.fov=t.fov,e.updateProjectionMatrix?.()),e.updateMatrixWorld?.(!0),()=>{e.position.set(...n.p),e.quaternion.set(...n.q),s&&e.fov!==n.fov&&(e.fov=n.fov,e.updateProjectionMatrix?.()),e.updateMatrixWorld?.(!0)}}function Ic(e,t){if(typeof t=="number"&&Number.isFinite(t)&&(ji=t),!e||e.length===0)return Xr=null,$i=null,T.cameraOverride=null,!1;let n=_();return n?(Xr=e,$i=n.camera,T.cameraOverride=nm,!0):!1}function Fc(e){Number.isFinite(e)&&(ji=Math.min(100,Math.max(0,e)))}var Vc=Symbol.for("depthview.hook.installed");function rm(){let e=window;if(e[Vc])return;e[Vc]=!0,typeof e.__THREE_DEVTOOLS__>"u"&&(e.__THREE_DEVTOOLS__=new EventTarget);let t=e.__THREE_DEVTOOLS__;t instanceof EventTarget&&t.addEventListener("observe",o=>{try{let i=o.detail;if(!i||typeof i!="object")return;if(i.isScene)T.scenes.push(new WeakRef(i));else if("domElement"in i){let s=i;typeof s.render=="function"?rr(s):queueMicrotask(()=>{try{rr(s)}catch{}})}}catch{}});try{let o=HTMLCanvasElement.prototype,i=o.getContext,s=function(...l){let c=i.apply(this,l);try{let u=l[0];c&&(u==="webgl"||u==="webgl2"||u==="experimental-webgl"||u==="webgpu")&&nr(this)}catch{}return c};o.getContext=s;let a=o.transferControlToOffscreen;typeof a=="function"&&(o.transferControlToOffscreen=function(){let l=a.call(this);try{nr(this)}catch{}return l})}catch{}try{let o=EventTarget.prototype.addEventListener;EventTarget.prototype.addEventListener=function(i,...s){return(i==="wheel"||i==="mousewheel")&&T.wheelListeners++,o.call(this,i,...s)}}catch{}try{Ua()}catch{}T.onRender=Us;let n={status:()=>Bo(),"debug:pairs":()=>[{...Ro()[0],wheel:{...gr}},...Ro().slice(1)],activate:()=>(Xo(),ma()),deactivate:o=>(Ks(),sl(),Ac(),o.keepLook===!0?ac():Wr(),pa()),"look:check":o=>rc(o.look),"look:apply":o=>oc(o.look??null),"look:follow":()=>ic(),"look:models":o=>sc(o.acknowledge===!0),"controls:list":()=>cc(),"controls:set":o=>uc(String(o.group),String(o.key),o.value),"tools:watch":()=>Xo(),"tools:errors":o=>qa(!!o.clear),"tools:shader":o=>Ga(String(o.uuid),typeof o.vertex=="string"?o.vertex:null,typeof o.fragment=="string"?o.fragment:null),"tools:lighting":()=>Sr(),"tools:baseline":()=>Xa(),"tools:animated":()=>Ja(),"tools:sources":()=>Ya(),"tools:addable":()=>Yo(),"tools:add":o=>el(o),"tools:remove":o=>kc(String(o.uuid))?Gr(String(o.uuid)):tl(String(o.uuid)),"tools:changes":()=>nl(),"tools:revert":()=>{Rc(),il()},"fx:add":o=>xc(o.request,Number(o.radius)||1,o.textures),"fx:set":o=>Sc(String(o.uuid),o.patch,o.textures),"fx:list":()=>Mc(),"fx:patch":o=>Ec(String(o.uuid),Array.isArray(o.patches)?o.patches:[],o.uniforms??{}),"fx:patches":()=>Tc(),"audit:run":o=>ul({pixels:o.pixels!==!1}),"design:run":()=>bl(),"tools:time":o=>rl(String(o.action),Number(o.frames)||1,Number(o.stepMs)||1e3/60),"tools:ratio":o=>ol(typeof o.ratio=="number"?o.ratio:null),"perf:sample":o=>qs(!!o.on),"perf:read":o=>Gs(Number(o.since)||0),"frame:capture":()=>lr(),"res:list":()=>Vs(),"learn:report":()=>Cc(),"res:thumb":o=>Is(String(o.uuid)),"scene:count":()=>Ds(),"scene:isolate":o=>jo(typeof o.uuid=="string"?re(o.uuid):null),"mat:shader":o=>Ns(re(String(o.uuid))),"mat:graph":o=>Bs(re(String(o.uuid))),"mat:texture":o=>Ws(re(String(o.uuid)),String(o.path),typeof o.data=="string"?o.data:null),tagCanvases:()=>ga(),renderSite:()=>ba(),grab:()=>va(),wheel:o=>ya(Number(o.deltaY)),"scene:snapshot":()=>Sa(),"scene:info":()=>xa(),"scene:select":o=>ka(typeof o.uuid=="string"?o.uuid:null),"scene:pick":o=>Ta(Number(o.x),Number(o.y)),"site:hover":o=>Ra(Number(o.x),Number(o.y)),"scene:wireframe":o=>Ho(!!o.on),"scene:live":o=>Uo(!!o.on),"scene:candidates":()=>La(),"scene:choose":o=>$a(typeof o.uuid=="string"?o.uuid:null),"obj:props":o=>yr(String(o.uuid)),"obj:bounds":o=>Pn(String(o.uuid)),"obj:set":o=>Ma(String(o.uuid),String(o.path),o.value),"cam:pose":()=>Fa(),"bridge:sample":o=>Va(Number(o.steps)),"path:override":o=>Ic(Array.isArray(o.keys)?o.keys:null,typeof o.percent=="number"?o.percent:void 0),"path:progress":o=>Fc(Number(o.percent))},r=(o,i,s)=>{window.postMessage(dn(o,i,s),location.origin==="null"?"*":location.origin)};Oa(o=>r("evt:scene:frame",o,`f${o.frame}`)),window.addEventListener("message",o=>{try{if(o.source!==window)return;let i=o.data;if(!er(i)||!i.type.startsWith("req:"))return;let s=i.type.slice(4),a=typeof i.payload=="object"&&i.payload!==null?i.payload:{};if(s==="scene:render"){let f=_a(a.pose,!!a.live);f&&r("evt:scene:frame",f,i.id);return}let l=n[s],c=f=>r(`res:${s}`,f,i.id),u=f=>c({ok:!1,error:f instanceof Error?f.message:String(f)});if(!l){c({ok:!1,error:`Unknown request: ${s}`});return}try{Promise.resolve(l(a)).then(f=>c({ok:!0,data:f??null}),u)}catch(f){u(f)}}catch{}})}try{rm()}catch{}var Jr=class{pending=new Map;handlers=new Map;origin=location.origin==="null"?"*":location.origin;constructor(){window.addEventListener("message",this.onMessage)}onMessage=t=>{if(t.source!==window)return;let n=t.data;if(er(n)){if(n.type.startsWith("res:")){let r=this.pending.get(n.id);if(!r||!ks(n.payload))return;this.pending.delete(n.id),clearTimeout(r.timer),n.payload.ok?r.resolve(n.payload.data):r.reject(new Error(n.payload.error??"Hook error"))}else if(n.type.startsWith("evt:")){let r=this.handlers.get(n.type.slice(4));if(r)for(let o of r)o(n.payload)}}};request(t,n={},r=4e3){let o=xo("q");return new Promise((i,s)=>{let a=window.setTimeout(()=>{this.pending.delete(o),s(new Error(`Hook request timed out: ${t}`))},r);this.pending.set(o,{resolve:i,reject:s,timer:a}),window.postMessage(dn(`req:${t}`,n,o),this.origin)})}send(t,n){window.postMessage(dn(`req:${t}`,n,xo("s")),this.origin)}on(t,n){let r=this.handlers.get(t);return r||this.handlers.set(t,r=new Set),r.add(n),()=>r.delete(n)}dispose(){window.removeEventListener("message",this.onMessage);for(let t of this.pending.values())clearTimeout(t.timer),t.reject(new Error("Inspector closed"));this.pending.clear(),this.handlers.clear()}};var Mt=()=>new Promise(e=>requestAnimationFrame(()=>e())),om=10.5,Oi=.25;function im(){let e=document.scrollingElement;if(e&&e.scrollHeight-window.innerHeight>4)return e;let t=null,n=0,r=document.body?.getElementsByTagName("*")??[];for(let o=0;o<r.length&&o<6e3;o++){let i=r[o],s=i.scrollHeight-i.clientHeight;s<50||s<=n||i.clientWidth<window.innerWidth*.7||i.clientHeight<window.innerHeight*.7||/auto|scroll/.test(getComputedStyle(i).overflowY)&&(t=i,n=s)}return t}function sm(){let e=window.innerWidth/2,t=window.innerHeight/2,n=document.elementsFromPoint(e,t).find(r=>r.id!==Ye)??document.body;for(let r=0;r<8&&n.shadowRoot;r++){let o=n.shadowRoot.elementFromPoint(e,t);if(!o||o===n)break;n=o}return n}function am(e){sm().dispatchEvent(new WheelEvent("wheel",{deltaY:e,deltaMode:0,bubbles:!0,cancelable:!0,composed:!0}))}var Yr=class{constructor(t){this.siteWheel=t;this.scroller=im(),this.native=this.scroller!==null,this.total=this.scroller?this.scroller.scrollHeight-this.scroller.clientHeight:om*window.innerHeight,this.start=this.offset}native;total;scroller;start;virtual=0;async wheel(t){let n=!1;try{n=await this.siteWheel?.(t)??!1}catch{}n||am(t)}get offset(){return this.scroller?this.scroller.scrollTop:this.virtual}get percent(){return this.total>0?Math.min(100,Math.max(0,this.offset/this.total*100)):0}async goTo(t){let n=Math.min(this.total,Math.max(0,t));if(this.scroller){this.holdTarget=null,await this.settle(n);return}this.pumpTarget=null;let r=Oi*window.innerHeight,o=n-this.virtual;for(;Math.abs(o)>.5;){let i=Math.sign(o)*Math.min(Math.abs(o),r);await this.wheel(i),this.virtual+=i,o-=i,Math.abs(o)>.5&&await Mt()}}holdTarget=null;holdUntil=0;holding=!1;async settle(t,n=1800){let r=this.scroller,o=performance.now()+n,i=0;for(r.scrollTo({top:t,behavior:"instant"});performance.now()<o&&i<5;)await Mt(),Math.abs(r.scrollTop-t)>2?(r.scrollTo({top:t,behavior:"instant"}),i=0):i++}async hold(){this.holding=!0;let t=this.scroller,n=t.scrollTop,r=window.innerHeight*.6;try{for(;this.holdTarget!==null&&performance.now()<this.holdUntil;){let o=await this.siteJump(n,this.holdTarget);if(o!==null){if(n=o.at,o.stop){this.holdTarget=null;break}this.holdUntil=performance.now()+1200}let i=this.holdTarget-n;if(Math.abs(i)>1){let s=Math.sign(i)*Math.min(Math.max(Math.abs(i)*.16,2),r,Math.abs(i));n+=s,this.holdUntil=performance.now()+1200}else n=this.holdTarget;Math.abs(t.scrollTop-n)>.4&&t.scrollTo({top:n,behavior:"instant"}),await Mt()}}finally{this.holding=!1}}onSiteJump=null;async siteJump(t,n){let r=this.scroller,o=r.scrollTop;if((o-t)*Math.sign(n-t)<=window.innerHeight*2)return null;let s=o;for(let c=0,u=0;u<240&&c<20;u++)await Mt(),c=Math.abs(r.scrollTop-s)<1?c+1:0,s=r.scrollTop;await new Promise(c=>setTimeout(c,900));let a=r.scrollTop,l=(n-t)*(n-a)<=0;return l&&this.onSiteJump?.(),{at:a,stop:l}}pumpTarget=null;pumping=!1;nudgeTo(t){let n=Math.min(this.total,Math.max(0,t));if(this.scroller){this.holdTarget=n,this.holdUntil=performance.now()+1500,this.holding||this.hold();return}this.pumpTarget=n,this.pumping||this.pump()}async pump(){this.pumping=!0;let t=Oi*window.innerHeight;try{for(;this.pumpTarget!==null;){let n=this.pumpTarget-this.virtual;if(Math.abs(n)<=.5){this.pumpTarget=null;break}let r=this.pumpTarget-this.virtual;if(Math.abs(r)>.5){let o=Math.sign(r)*Math.min(Math.abs(r),t);this.virtual+=o,await this.wheel(o)}await Mt()}}finally{this.pumping=!1}}async travelTo(t,n=.8){let r=Math.min(this.total,Math.max(0,t)),o=this.scroller;if(!o)return this.goTo(r);this.holdTarget=null;let i=o.scrollTop,s=window.innerHeight*n;for(let a=0;a<600&&Math.abs(r-i)>1;a++){let l=r-i;i+=Math.sign(l)*Math.min(Math.max(Math.abs(l)*.16,2),s,Math.abs(l)),o.scrollTo({top:i,behavior:"instant"}),await Mt();let c=await this.siteJump(i,r);if(c?.stop)return;c&&(i=c.at)}await this.settle(r)}goToPercent(t){return this.goTo(t/100*this.total)}rebase(){this.pumpTarget=null,this.virtual=0}async wheelBy(t,n=Oi*window.innerHeight){let r=t;for(;Math.abs(r)>.5;){let o=Math.sign(r)*Math.min(Math.abs(r),n);await this.wheel(o),r-=o,Math.abs(r)>.5&&await Mt()}}async restore(){await this.travelTo(this.start,.8)}};function Dc(e,t=1e-4){let n=e[0];return n?e.some(r=>{let o=Math.abs(r.quaternion[0]*n.quaternion[0]+r.quaternion[1]*n.quaternion[1]+r.quaternion[2]*n.quaternion[2]+r.quaternion[3]*n.quaternion[3])<1-t;return Js(r.position,n.position)>t||o||Math.abs(r.fov-n.fov)>t}):!1}function Nc(e){let t=[],n=0;for(let r=1;r<=e.length;r++){let o=e[r-1];(r===e.length||e[r].section!==o.section)&&(o.section!==null&&t.push({label:o.section,index:Math.floor((n+r-1)/2),startPercent:e[n].percent,endPercent:o.percent}),n=r)}return t}function zc(e){let t=e.id?.trim();if(t)return`#${t}`;let n=e.className?.trim().split(/\s+/)[0];if(n)return`.${n}`;let r=e.heading?.trim().replace(/\s+/g," ");return r?r.length>28?`${r.slice(0,27)}\u2026`:r:"section"}var Bn=()=>new Promise(e=>requestAnimationFrame(()=>e()));function lm(){let e=i=>i.id===Ye||i.hasAttribute(xs)||["SCRIPT","STYLE","LINK","NOSCRIPT","CANVAS"].includes(i.tagName),t=i=>i.getBoundingClientRect().height>=window.innerHeight*.3,n=[...document.querySelectorAll("section")].filter(i=>!i.parentElement?.closest("section")&&!e(i));if(n.length>=2)return n;let r=document.querySelector("main"),o=r?[...r.children].filter(i=>!e(i)&&t(i)):[];return o.length>=2?o:[...document.body?.children??[]].filter(i=>!e(i)&&t(i))}function cm(e){let t=window.innerHeight/2,n=null,r=1/0;for(let o of e){let i=o.getBoundingClientRect();if(i.height===0)continue;let s=i.top<=t&&i.bottom>t?0:Math.min(Math.abs(i.top-t),Math.abs(i.bottom-t));s<r&&(r=s,n=o)}return n?zc({id:n.id,className:typeof n.className=="string"?n.className:"",heading:n.querySelector("h1, h2, h3")?.textContent??""}):null}var um=(e,t)=>Math.abs(e.position[0]-t.position[0])+Math.abs(e.position[1]-t.position[1])+Math.abs(e.position[2]-t.position[2])+Math.abs(e.quaternion[0]-t.quaternion[0])+Math.abs(e.quaternion[1]-t.quaternion[1])+Math.abs(e.quaternion[2]-t.quaternion[2])+Math.abs(e.quaternion[3]-t.quaternion[3])+Math.abs(e.fov-t.fov)*.01;async function Wc(e,t,n){try{let a=await e.request("bridge:sample",{steps:120});if(a&&a.length>1)return{samples:a,exact:!0}}catch{}let r=n.steps??48,o=t.offset,i=lm(),s=[];n.setRecording(!0);try{await t.goTo(0),await Bn();for(let a=0;a<=r;a++){let l=a/r*100;await t.goToPercent(l),await Bn(),await Bn();let c=await e.request("cam:pose");for(let u=0;c&&u<8;u++){await Bn();let f=await e.request("cam:pose");if(!f)break;let d=um(c,f)<1e-5;if(c=f,d)break}if(!c)break;s.push({percent:l,...c,section:cm(i)}),n.onProgress?.(a/r)}}finally{await t.goTo(o),await Bn(),n.setRecording(!1)}return{samples:s,exact:!1}}var Bc=["makeDefault","position","rotation","scale","fov","near","far","zoom","color","intensity","distance","decay","angle","penumbra","visible","castShadow","receiveShadow","material.color","material.roughness","material.metalness","material.opacity","material.transparent"],Hc=e=>{let t=Bc.indexOf(e);return t<0?Bc.length:t},fm=e=>Object.keys(e).sort((t,n)=>Hc(t)-Hc(n)||t.localeCompare(n)),Ii=e=>String(Ee(e,3)),hm=e=>e.map(Ii).join(", "),dm=e=>Ee(e[0])===Ee(e[1])&&Ee(e[1])===Ee(e[2]),qc=e=>e&&e.charAt(0).toLowerCase()+e.slice(1);function Hn(e){return typeof e=="number"?Ee(e,3):Array.isArray(e)?e.map(t=>Ee(t,3)):e}function mm(e){return e==="PerspectiveCamera"||e==="OrthographicCamera"?e:qc(e||"object3D")}function _i(e,t){return typeof t=="boolean"?t?e:`${e}={false}`:typeof t=="string"?`${e}="${t}"`:typeof t=="number"?`${e}={${Ii(t)}}`:e==="scale"&&dm(t)?`${e}={${Ii(t[0])}}`:`${e}={[${hm(t)}]}`}function pm(e){let t=[],n=[],r=mm(e.type);e.kind==="camera"&&r===e.type&&t.push("makeDefault");for(let a of fm(e.values)){let l=e.values[a];a.startsWith("material.")?n.push(_i(a.slice(9),l)):a.startsWith("uniform.")?n.push(_i(`uniforms-${a.slice(8)}-value`,l)):t.push(_i(a,l))}let o=[r,...t].join(" "),i=e.name?`{/* ${e.name.replace(/\*\//g,"* /")} */}
|
|
761
|
+
`:"";if(n.length===0)return`${i}<${o} />`;let s=qc(e.materialType||"meshStandardMaterial");return`${i}<${o}>
|
|
762
|
+
<${[s,...n].join(" ")} />
|
|
763
|
+
</${r}>`}function Qr(e){return e.map(pm).join(`
|
|
764
|
+
|
|
765
|
+
`)}var Uc=(e,t)=>e.every(n=>Ee(n)===t);function Fi(e){let t={position:e.position};if(Uc(e.rotation,0)||(t.rotation=e.rotation),Uc(e.scale,1)||(t.scale=e.scale),e.visible||(t.visible=!1),e.castShadow&&(t.castShadow=!0),e.receiveShadow&&(t.receiveShadow=!0),e.light){t.color=e.light.color,t.intensity=e.light.intensity;for(let n of["distance","decay","angle","penumbra"]){let r=e.light[n];r!==void 0&&(t[n]=r)}}return e.camera&&(e.camera.fov!==void 0&&(t.fov=e.camera.fov),t.near=e.camera.near,t.far=e.camera.far,Ee(e.camera.zoom)!==1&&(t.zoom=e.camera.zoom)),e.mesh&&(e.mesh.color!==void 0&&(t["material.color"]=e.mesh.color),e.mesh.roughness!==void 0&&(t["material.roughness"]=e.mesh.roughness),e.mesh.metalness!==void 0&&(t["material.metalness"]=e.mesh.metalness),e.mesh.opacity!==void 0&&Ee(e.mesh.opacity)!==1&&(t["material.opacity"]=e.mesh.opacity),e.mesh.transparent&&(t["material.transparent"]=!0)),{name:e.name,type:e.type,kind:e.kind,materialType:e.mesh?.materialType,values:t}}function Gc(e,t){let n=new Map;for(let r of e){let o=n.get(r.uuid);o||(o={...t(r.uuid)??{name:"",type:"Object3D",kind:"object"},values:{},original:{}},n.set(r.uuid,o)),o.values[r.path]=r.current,o.original[r.path]=r.original}return[...n.values()]}function Zr(e,t){let n=[],r=[];for(let o of e){let i=t(o.uuid),s=o.path.startsWith("uniform."),a=o.path.startsWith("material.")||s,l=a?i?.mesh?.materialSource:i?.source;if(!l){r.push(o);continue}n.push({uuid:o.uuid,path:o.path,file:l.file,line:l.line,column:l.column,component:l.component,prop:s?`uniforms-${o.path.slice(8)}-value`:a?o.path.slice(9):o.path,oldValue:Hn(o.original),newValue:Hn(o.current)})}return{intents:n,unmapped:r}}function Kc(e,t){let{intents:n}=Zr(e,t);return e.map(r=>{let o=t(r.uuid),i=n.find(s=>s.uuid===r.uuid&&s.path===r.path);return{uuid:r.uuid,object:o?.name??"",type:o?.type??"Object3D",path:r.path,original:Hn(r.original),current:Hn(r.current),source:i&&{file:i.file,line:i.line,column:i.column,component:i.component,prop:i.prop}}})}var Un=(e,t=1)=>{let n=10**t;return Math.round(e*n)/n};function eo(e){let t=e.filter(i=>i.dt>0&&i.dt<1e3);if(t.length===0)return null;let n=t.map(i=>i.dt).sort((i,s)=>i-s),r=n.reduce((i,s)=>i+s,0)/n.length,o=i=>Math.round(t.reduce((s,a)=>s+i(a),0)/t.length);return{frames:t.length,fps:Un(1e3/r),frameMs:{average:Un(r),p95:Un(n[Math.min(n.length-1,Math.floor(n.length*.95))]),worst:Un(n[n.length-1])},slowFrames:t.filter(i=>i.dt>r*1.5).length,drawCalls:o(i=>i.calls),triangles:o(i=>i.triangles),renderPasses:Un(t.reduce((i,s)=>i+s.passes,0)/t.length)}}function Di(e,t,n=1e-9){return Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((r,o)=>Math.abs(r-t[o])<=n):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=n:typeof e=="string"&&typeof t=="string"?e.toLowerCase()===t.toLowerCase():e===t}var Vi=(e,t)=>`${e}\0${t}`,to=class{stack=[];touched=new Map;record(t){let n=Vi(t.uuid,t.path),r=this.touched.get(n);r?r.current=t.after:this.touched.set(n,{uuid:t.uuid,path:t.path,original:t.before,current:t.after});let o=this.stack[this.stack.length-1];if(o&&t.group!==void 0&&o.group===t.group&&o.uuid===t.uuid&&o.path===t.path){o.after=t.after;return}this.stack.push({...t})}undo(){let t=this.stack.pop();if(!t)return null;let n=this.touched.get(Vi(t.uuid,t.path));return n&&(n.current=t.before),{uuid:t.uuid,path:t.path,value:t.before}}undoStep(){let t=this.stack[this.stack.length-1];if(!t)return[];let n=[];do{let r=this.undo();r&&n.push(r)}while(t.batch!==void 0&&this.stack.length>0&&this.stack[this.stack.length-1].batch===t.batch);return n}changed(){return[...this.touched.values()].filter(t=>!Di(t.original,t.current))}resetAll(){let t=this.changed().map(n=>({uuid:n.uuid,path:n.path,value:n.original}));return this.stack=[],this.touched.clear(),t}rebase(t,n){this.touched.delete(Vi(t,n)),this.stack=this.stack.filter(r=>!(r.uuid===t&&r.path===n))}get undoDepth(){return this.stack.length}};function rn(e,t){if(e)switch(t){case"position":case"rotation":case"scale":case"visible":case"castShadow":case"receiveShadow":return e[t];case"color":case"intensity":case"distance":case"decay":case"angle":case"penumbra":return e.light?.[t];case"fov":case"near":case"far":case"zoom":return e.camera?.[t];case"material.color":case"material.roughness":case"material.metalness":case"material.opacity":case"material.transparent":return e.mesh?.[t.slice(9)];case"material.size":return e.mesh?.size;case"material.emissive":case"material.emissiveIntensity":case"material.side":case"material.depthTest":case"material.depthWrite":case"material.wireframe":case"material.flatShading":return e.mesh?.[t.slice(9)];default:return t.startsWith("uniform.")?e.mesh?.uniforms?.find(n=>n.name===t.slice(8))?.value:void 0}}var gm=["position","rotation","scale","visible","castShadow","receiveShadow","color","intensity","distance","decay","angle","penumbra","fov","near","far","zoom","material.color","material.roughness","material.metalness","material.opacity","material.transparent","material.emissive","material.emissiveIntensity","material.side","material.depthTest","material.depthWrite","material.wireframe","material.flatShading","material.size"];function Xc(e){let t={};for(let n of gm){let r=rn(e,n);r!==void 0&&(t[n]=r)}for(let n of e.mesh?.uniforms??[])t[`uniform.${n.name}`]=n.value;return t}var Ni=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Jc=e=>Math.hypot(e[0],e[1],e[2]),Yc=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],zi=e=>e*180/Math.PI,U=(e,t=2)=>{let n=10**t;return Math.round(e*n)/n};function bm(e,t){let n=Math.abs(e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]);return zi(2*Math.acos(Math.min(1,n)))}function qn(e,t){let[n,r,o,i]=e,s=i*t[0]+r*t[2]-o*t[1],a=i*t[1]+o*t[0]-n*t[2],l=i*t[2]+n*t[1]-r*t[0],c=-n*t[0]-r*t[1]-o*t[2];return[s*i+c*-n+a*-o-l*-r,a*i+c*-r+l*-n-s*-o,l*i+c*-o+s*-r-a*-n]}function ym(e){let t=qn(e,[0,0,-1]);if(Math.abs(t[1])>.97)return 0;let n=qn(e,[1,0,0]),r=Math.hypot(t[0],t[2]);return zi(Math.asin(Math.max(-1,Math.min(1,n[1]/Math.max(r,1e-6)))))}function vm(e,t){let n=qn(e,[0,0,-1]),r=qn(t,[0,0,-1]),o=n[2]*r[0]-n[0]*r[2],i=n[0]*r[0]+n[2]*r[2];return zi(Math.atan2(o,i))}function Qc(e){if(e.length===0)return 0;let t=[...e].sort((n,r)=>n-r);return t[Math.floor(t.length/2)]}function lt(e,t){let n=[];for(let r of e){let o=U(t[r].percent,1),i=U(t[r+1].percent,1),s=n[n.length-1];s&&o<=s[1]+1e-6?s[1]=Math.max(s[1],i):n.push([o,i])}return n}var He=e=>e.slice(0,4).map(([t,n])=>n-t<1.5?`${t}%`:`${t}\u2013${n}%`).join(", ")+(e.length>4?` and ${e.length-4} more`:"");function Zc(e,t=[]){let n=e.length,r={score:0,verdict:"rough",issues:[],measured:{samples:n,pathLength:0,totalTurnDegrees:0,fovRange:[0,0],maxRollDegrees:0,movingShare:0,speedVariation:0,cuts:0},shots:[],checkAt:[]};if(n<8)return r;let o=n-1,i=[],s=[],a=[],l=[],c=[];for(let w=0;w<o;w++){let $=e[w],G=e[w+1],H=Ni(G.position,$.position),pe=Jc(H);i.push(pe),c.push(pe>0?[H[0]/pe,H[1]/pe,H[2]/pe]:[0,0,0]),s.push(bm($.quaternion,G.quaternion)),a.push(vm($.quaternion,G.quaternion)),l.push(G.fov-$.fov)}let u=i.filter(w=>w>0),f=Qc(u),d=s.filter(w=>w>.02),p=Qc(d),m=i.reduce((w,$)=>w+$,0),g=Math.max(...i),h=i.map((w,$)=>f>0&&w>f*25&&w>g*.5&&w>m*.08||s[$]>55&&s[$]>p*10),b=h.flatMap((w,$)=>w?[$]:[]),y=0,v=0;for(let w=0;w<o;w++)h[w]||(y+=i[w],v+=s[w]);let x=o-b.length,M=y/Math.max(1,x),S=v/Math.max(1,x),k=Math.max(M*.03,1e-9),E=.03,L=w=>i[w]<=k&&s[w]<=E&&Math.abs(l[w])<.02,A=[],C=100/o,O=[];for(let w=1;w<o-1;w++){if(h[w]||h[w-1]||h[w+1])continue;let $=(i[w-1]+i[w+1])/2,G=(s[w-1]+s[w+1])/2,H=i[w]>M*2&&i[w]>$*3.5,pe=s[w]>Math.max(4,S*3)&&s[w]>G*3.5;(H||pe)&&O.push(w)}if(O.length>0){let w=lt(O,e);A.push({id:"jump",severity:O.length>2?"high":"medium",title:`The camera jumps at ${w.length} point${w.length===1?"":"s"} of the scroll`,evidence:`at ${He(w)}: one scroll step moves or turns the camera more than 3.5 times its neighbours`,cause:"A keyframe out of line with the ones round it, two animations handing over without overlap, or a value that snaps (a section change, a class toggled) in the middle of a move.",fix:"Move the keyframe on to the curve of its neighbours, or overlap the two animations so one eases out while the next eases in. If a cut is meant, hide it: cut through black, a flash or a cloud.",at:w})}let P=[],j=w=>i[w]/Math.max(M,1e-9)+s[w]/Math.max(S,.05);for(let w=0;w<o;){if(h[w]||L(w)){w++;continue}let $=w;for(;$<o&&!h[$]&&!L($);)$++;if($-w>=6){let H=0;for(let Je=w;Je<$;Je++)H=Math.max(H,j(Je));let pe=w>0&&!h[w-1]&&L(w-1),ct=$<o&&!h[$]&&L($);pe&&j(w+1)>=H*.8&&P.push(w),ct&&j($-2)>=H*.8&&P.push($-1)}w=$}if(P.length>0){let w=lt([...new Set(P)],e);A.push({id:"abrupt",severity:P.length>3?"medium":"low",title:`${w.length} move${w.length===1?" starts or stops":"s start or stop"} at full speed`,evidence:`at ${He(w)}: the camera goes from still to faster than its average in one step, or the other way`,cause:'Linear interpolation between keyframes (ease: "none"), or a move clamped at the end of its range.',fix:"Ease the ends: smoothstep or a power2.inOut ease over the first and last tenth of the move, or a Catmull-Rom curve through the keys in place of straight segments.",at:w})}let I=[],te=null,Ke=-1;for(let w=0;w<o;w++){if(h[w]){te=null;continue}i[w]<M*.25||(te&&Yc(te,c[w])<-.5&&w-Ke<=3&&I.push(w),te=c[w],Ke=w)}if(I.length>0){let w=lt(I,e);A.push({id:"reversal",severity:I.length>2?"high":"medium",title:`The camera doubles back ${I.length} time${I.length===1?"":"s"}`,evidence:`at ${He(w)}: it travels one way and then, within 3 scroll steps, the opposite way`,cause:"Keyframes that overshoot and return, or two shots joined where the second starts behind the end of the first.",fix:"Take out the key that overshoots, or start the next shot from where this one ends. A visitor who scrolls forward expects to go forward.",at:w})}let Oe=[],Q=0,Se=-1,Me=[];for(let w=0;w<o;w++){if(h[w]){Q=0,Me=[];continue}if(Math.abs(a[w])<Math.max(.35,S*.35))continue;let $=Math.sign(a[w]);Q!==0&&$!==Q&&w-Se<=6&&(Me.push(w),Me.filter(H=>w-H<=10).length>=2&&Oe.push(w)),Q=$,Se=w}if(Oe.length>0){let w=lt(Oe,e);A.push({id:"wag",severity:"medium",title:"The view swings from side to side",evidence:`at ${He(w)}: it pans one way, back, and the first way again within 10% of scroll`,cause:"A look-at target that moves between keys on a zigzag, or a pan added on top of a move that already turns the camera.",fix:"Keep the look-at target on one smooth line through the shot (or hold it on the subject), and turn the camera one way per shot.",at:w})}let ve=[];for(let w=0;w<o;w++)!h[w]&&s[w]/C>22&&ve.push(w);if(ve.length>0){let w=lt(ve,e),$=Math.max(...ve.map(G=>s[G]/C));A.push({id:"whip",severity:$>45?"high":"medium",title:"The camera turns too fast to follow",evidence:`at ${He(w)}: up to ${U($,0)}\xB0 of turn per 1% of scroll (a wheel notch is often 1\u20132%)`,cause:"Too much of a turn given to too little scroll.",fix:"Give the turn more scroll (lengthen that section), or split it: turn part of the way in the shot before. Under about 12\xB0 per 1% reads as a move, not a spin.",at:w})}let Ae=e.map(w=>ym(w.quaternion)),Rt=Math.max(...Ae.map(Math.abs)),ho=[];for(let w=0;w<o;w++)Math.abs(Ae[w])>3.5&&ho.push(w);if(ho.length>0){let w=lt(ho,e);A.push({id:"roll",severity:Rt>12?"medium":"low",title:`The horizon tilts up to ${U(Rt,1)}\xB0`,evidence:`at ${He(w)}`,cause:"The camera is turned with a quaternion slerp between keys that do not share an up direction, or rotation.z is animated.",fix:"If the tilt is not meant (a banked turn, a fall), aim the camera with lookAt and a fixed up of (0, 1, 0) in place of interpolating its rotation.",at:w})}let ln=[],cn=-1;for(let w=0;w<=o;w++){let $=w<o&&L(w);if($&&cn<0&&(cn=w),!$&&cn>=0){let G=e[cn].percent,H=e[w].percent;H-G>=7&&ln.push([U(G,1),U(H,1)]),cn=-1}}let as=ln.reduce((w,[$,G])=>w+(G-$),0)/100;ln.length>0&&A.push({id:"dead",severity:as>.35?"medium":"low",title:`The camera holds still for ${U(as*100,0)}% of the scroll`,evidence:`at ${He(ln)}`,cause:"A pinned section, or a gap between two camera animations.",fix:"A hold is right while something else plays (text, an object animating). If nothing does, the visitor scrolls and sees no answer: add a slow push-in (2\u20134% of the distance to the subject) or shorten the section.",at:ln});let mo=0,Xn=0,ls=[];for(let w=0;w<o;w++){if(h[w]||L(w))continue;Xn++,(i[w]>M*.5?1:0)+(s[w]>Math.max(S*.8,.6)?1:0)+(Math.abs(l[w])>.25?1:0)===3&&(mo++,ls.push(w))}if(Xn>0&&mo/Xn>.3){let w=lt(ls,e);A.push({id:"busy",severity:"medium",title:"The camera travels, turns and zooms at the same time",evidence:`${U(mo/Xn*100,0)}% of the moving scroll, at ${He(w)}`,cause:"Position, look-at and field of view are all keyed through the same stretch.",fix:"One idea per shot: a push-in, or a pan, or an orbit. Keep the field of view fixed unless the zoom is the point of the shot.",at:w})}let cs=e.map(w=>w.fov),Jn=[Math.min(...cs),Math.max(...cs)],po=0,Yn=0,us=[];for(let w=0;w<o;w++){if(h[w]){Yn=0;continue}if(Math.abs(l[w])<.15)continue;let $=Math.sign(l[w]);Yn!==0&&$!==Yn&&(po++,us.push(w)),Yn=$}if(po>=4){let w=lt(us,e);A.push({id:"zoom-pump",severity:"low",title:`The field of view changes direction ${po} times`,evidence:`from ${U(Jn[0],1)}\xB0 to ${U(Jn[1],1)}\xB0, turning at ${He(w)}`,cause:"A field of view keyed per shot with different values, eased between them.",fix:"Pick one lens per scene and hold it. Change it at a cut, not during a move, unless the zoom is the shot.",at:w})}let Qn=t.filter(w=>w.moved>M*.4||w.turnedDegrees>.6);if(Qn.length>0){let w=Math.max(...Qn.map($=>$.turnedDegrees));A.push({id:"idle-drift",severity:w>2.5?"medium":"low",title:"The camera moves when the page is not scrolled",evidence:`at ${Qn.map($=>`${U($.percent,0)}%`).join(", ")}: up to ${U(w,2)}\xB0 of turn in half a second with no scroll`,cause:"A sway, a pointer parallax or a damped follow that is still catching up with the scroll.",fix:"A slow drift under 0.5\xB0 is a living frame. More than that competes with the scroll: lower its amplitude, or switch it off while the scroll is moving.",at:Qn.map($=>[U($.percent,1),U($.percent,1)])})}let At=[];for(let w=0;w<o;w++)h[w]||L(w)||At.push(i[w]/Math.max(M,1e-9)+s[w]/Math.max(S,.05));let go=At.reduce((w,$)=>w+$,0)/Math.max(1,At.length),zu=At.reduce((w,$)=>w+($-go)**2,0)/Math.max(1,At.length),fs=go>0?Math.sqrt(zu)/go:0,Wu=At.length/Math.max(1,o),bo=[],Bu=(w,$)=>{let G=0,H=0,pe=0;for(let hn=w;hn<$;hn++)G+=i[hn],H+=s[hn],pe+=a[hn];let ct=e[w],Je=e[$],fn=Jc(Ni(Je.position,ct.position)),Gu=qn(ct.quaternion,[0,0,-1]),ds=fn>0?Yc(Ni(Je.position,ct.position),Gu)/fn:0,ms=fn>0?(Je.position[1]-ct.position[1])/fn:0,ke=[];if(G<=k*($-w)&&H<.5)return"hold";G>M*($-w)*.3&&(ds>.7?ke.push("push in"):ds<-.7?ke.push("pull back"):ms>.7?ke.push("rise"):ms<-.7?ke.push("descend"):H>25&&fn<G*.85?ke.push("orbit"):ke.push("track")),H>6&&!ke.includes("orbit")&&ke.push(Math.abs(pe)>H*.6?`pan ${pe>0?"right":"left"} ${U(H,0)}\xB0`:`tilt ${U(H,0)}\xB0`);let ps=Je.fov-ct.fov;return Math.abs(ps)>2&&ke.push(ps<0?"zoom in":"zoom out"),ke.length?ke.join(", "):"drift"},un=0,Zn=L(0);for(let w=0;w<=o;w++){let $=w===o,G=!$&&h[w],H=!$&&L(w);($||G||H!==Zn)&&(w>un&&bo.push({from:U(e[un].percent,1),to:U(e[w].percent,1),move:Zn?"hold":Bu(un,w)}),G?(bo.push({from:U(e[w].percent,1),to:U(e[w+1].percent,1),move:"cut"}),un=w+1,Zn=w+1<o?L(w+1):!1):(un=w,Zn=H))}let hs=bo.filter((w,$)=>!(w.move==="hold"&&w.to-w.from<C*1.5&&$>0)),Hu={high:16,medium:9,low:4},Xe=100;for(let w of A)Xe-=Hu[w.severity];Xe-=Math.min(12,Math.max(0,fs-.9)*10),Xe=Math.max(0,Math.round(Xe));let Uu=Xe>=88?"cinematic":Xe>=72?"mostly smooth":Xe>=50?"uneven":"rough",qu=[...new Set([...hs.filter(w=>w.move!=="cut").map(w=>w.from),...A.flatMap(w=>w.at.slice(0,3).map(([$,G])=>($+G)/2))].map(w=>Math.round(w)))].sort((w,$)=>w-$).slice(0,16);return{score:Xe,verdict:Uu,issues:A,measured:{samples:n,pathLength:U(y,3),totalTurnDegrees:U(v,1),fovRange:[U(Jn[0],1),U(Jn[1],1)],maxRollDegrees:U(Rt,1),movingShare:U(Wu,2),speedVariation:U(fs,2),cuts:b.length},shots:hs.slice(0,40),checkAt:qu}}var Ue=.6,no=e=>Math.round(e*10)/10,Wi=(e,t)=>Math.abs(e-t)<Ue;function wm(e,t){if(e.length>=2){let o=e.length-1;return e.map((i,s)=>{let a=Math.max(0,i.endPercent-i.startPercent),l=(i.startPercent+i.endPercent)/2,c=s===0?0:s===o?100:no(l);return{id:s===0?"opening":`s${s}`,label:i.label,percent:c,holdFrom:s===0?0:no(s===o?i.startPercent+a*.4:l-a*.3),holdTo:s===o?100:no(s===0?i.startPercent+a*.6:l+a*.3)}})}let n=at(t),r=n.length?n.map(o=>o.percent):[0];return r[0]>Ue&&r.unshift(0),r.map((o,i)=>({id:i===0?"opening":i===r.length-1?"end":`s${i}`,label:i===0?"Top of the page":o>=100-Ue?"End of the page":`${no(o)}%`,percent:i===0?0:o,holdFrom:i===0?0:o,holdTo:o}))}function eu(e,t){if(t.holdTo-t.holdFrom<Ue)return!1;let n=e.find(o=>Wi(o.percent,t.holdFrom)),r=e.find(o=>Wi(o.percent,t.holdTo));return!n||!r||!tn(n,r)?!1:e.every(o=>o.percent<=t.holdFrom+Ue||o.percent>=t.holdTo-Ue||tn(o,n))}function xm(e,t){let n=(r,o)=>Math.abs(r-o)<.002;return e.position.every((r,o)=>n(r,t.position[o]))&&e.target.every((r,o)=>n(r,t.target[o]))&&n(e.fov,t.fov)}function tu(e,t,n){let r=at(t);return r.length?wm(e,n.length?n:r).map(o=>{let i=Be(r,o.percent),s=Be(n,o.percent),a=eu(r,o);return{id:o.id,label:o.label,opening:o.id==="opening",percent:o.percent,holdFrom:o.holdFrom,holdTo:o.holdTo,pose:i,hold:a,keyed:a||r.some(l=>Wi(l.percent,o.percent)),changed:!s||!xm(s,i)||a!==eu(at(n),o)}}):[]}function nu(e,t,n,r=t.hold){let o=r&&t.holdTo-t.holdFrom>=Ue,i=o?t.holdFrom:t.percent,s=o?t.holdTo:t.percent,a=Math.min(i,t.hold?t.holdFrom:t.percent)-Ue,l=Math.max(s,t.hold?t.holdTo:t.percent)+Ue,c=e.filter(f=>f.percent<a||f.percent>l),u=f=>({percent:f,position:[...n.position],target:[...n.target],fov:n.fov});return at([...c,...o?[u(i),u(s)]:[u(t.percent)]])}var Bi={front:[0,.12,1],back:[0,.12,-1],left:[-1,.12,0],right:[1,.12,0],top:[0,1,.001],"front-left":[-.7,.35,1],"front-right":[.7,.35,1]},Hi=Object.keys(Bi);function ru(e,t){let n=Bi[t.side??"front-right"]??Bi["front-right"],r=Math.hypot(n[0],n[1],n[2]),o=Math.min(1,Math.max(.05,t.fill??.6)),i=Math.max(Math.hypot(...e.size)/2,1e-4),s=Math.tan(Math.min(170,Math.max(1,t.fov))*Math.PI/360),a=Math.min(s,s*(t.aspect&&t.aspect>0?t.aspect:1)),l=i/Math.sin(Math.atan(a*o));return{position:[e.center[0]+n[0]/r*l,e.center[1]+n[1]/r*l,e.center[2]+n[2]/r*l],target:[...e.center],fov:t.fov}}function ou(e,t){let n=s=>Math.tan(Math.min(170,Math.max(1,s))*Math.PI/360),r=Math.max(e.distance,1e-4),o=[e.position[0]+e.forward[0]*r,e.position[1]+e.forward[1]*r,e.position[2]+e.forward[2]*r],i=r*n(e.fov)/n(t);return{position:[o[0]-e.forward[0]*i,o[1]-e.forward[1]*i,o[2]-e.forward[2]*i],target:o,fov:t}}var iu={get:null,set:null,view:null,keys:new Set,flyVector(){let e=this.keys;if(e.size===0)return null;let t=(r,o)=>(e.has(r)?1:0)-(e.has(o)?1:0),n=[t("d","a"),t("e","q"),t("w","s")];return n[0]||n[1]||n[2]?n:null}};var su=e=>{let t,n=new Set,r=(c,u)=>{let f=typeof c=="function"?c(t):c;if(!Object.is(f,t)){let d=t;t=u??(typeof f!="object"||f===null)?f:Object.assign({},t,f),n.forEach(p=>p(t,d))}},o=()=>t,a={setState:r,getState:o,getInitialState:()=>l,subscribe:c=>(n.add(c),()=>n.delete(c))},l=t=e(r,o,a);return a},au=(e=>e?su(e):su);var so=ef(xu(),1);var Fm=e=>e;function Vm(e,t=Fm){let n=so.default.useSyncExternalStore(e.subscribe,so.default.useCallback(()=>t(e.getState()),[e,t]),()=>t(e.getInitialState()));return so.default.useDebugValue(n),n}var Su=e=>{let t=au(e),n=r=>Vm(t,r);return Object.assign(n,t),n},Mu=(e=>e?Su(e):Su);var ao={present:!1,visible:!0},Dm={phase:"starting",progress:{done:0,total:1,label:""},status:null,hookMissing:!1,mode:"layer",tool:"rotate",toast:null,layers:{background:ao,webgl:ao,html:ao,fixed:ao},layersVersion:0,separation:0,rotationDeg:0,selectedLayer:null,page:{heightVh:1,stops:1,truncated:!1,native:!0,screens:1,stepped:!1},fullPage:!0,elements:[],hoverElement:null,selectedElement:null,snapshot:null,sceneOptions:[],sceneChoice:null,selectedUuid:null,props:null,toggles:{helpers:!0,htmlPlane:!0,grid:!1,wireframe:!1,pipeline:!0,siteHover:!0},htmlPlaneDistance:.25,gizmo:"none",lookThrough:!0,preview:!1,ai:{open:!1,turns:[],busy:!1,error:null,hasKey:!1,freeLeft:null},follow:!0,changeCount:0,undoDepth:0,keepOnExit:!1,codeModal:null,sideTab:"inspect",isolated:null,shader:null,graph:null,record:{status:"idle",progress:0,samples:[],exact:!1},scrub:0,playing:!1,sections:[],sectionShotsVersion:0,mcp:{status:"disconnected",port:7411,edits:[]},pathEdit:null,look:{look:Ne(),history:[],audit:null,notes:[],box:null,effectsAvailable:!1,savedTo:null,reference:null,facts:null,perf:{fps:null,siteFps:null,busy:!1,costs:null},adapt:{models:[],last:null,busy:!1}},controls:{list:[],dirty:[]}},ku=Mu(()=>({...Dm})),R=ku.getState,J=ku.setState;var Ji=new Set,Yi={emit(e){for(let t of Ji)t(e)},on(e){return Ji.add(e),()=>Ji.delete(e)}};function Nm(e){let t=[],n=(r,o)=>{let i=o?`${o} / ${r.name||r.type}`:r.name||r.type;t.push({uuid:r.uuid,name:r.name,type:r.type,kind:r.kind,visible:r.visible,path:i}),r.children.forEach(s=>n(s,i))};return n(e,""),t}async function Qi(e){if(!e.sceneAvailable)throw new Error("This page has no three.js scene that the inspector can read.");if(!await e.refreshSnapshot())throw new Error("No active three.js scene found.");let t=R().snapshot;return t?Nm(t.tree):[]}async function we(e,t){let n=typeof t.uuid=="string"?t.uuid:"",r=typeof t.name=="string"?t.name:"";if(!n&&!r){let a=R().selectedUuid;if(!a)throw new Error("Give a uuid or a name: nothing is selected in the inspector.");return a}let o=await Qi(e);if(n){if(!o.some(a=>a.uuid===n))throw new Error(`No object with id ${n}. Ids change when the page reloads: call find_objects again.`);return n}let i=o.filter(a=>a.name===r),s=i.length?i:o.filter(a=>a.name.toLowerCase()===r.toLowerCase());if(s.length===1)return s[0].uuid;throw s.length===0?new Error(`No object named "${r}". Call find_objects to search.`):new Error(`${s.length} objects are named "${r}". Use a uuid: ${s.slice(0,8).map(a=>`${a.uuid} (${a.path})`).join(", ")}`)}async function qe(e,t){let n=await e.hook?.request("obj:props",{uuid:t});if(!n)throw new Error(`No object with id ${t} in the scene.`);return e.propsCache.set(t,n),n}function Eu(e){return typeof e=="boolean"||typeof e=="string"||typeof e=="number"&&Number.isFinite(e)||Array.isArray(e)&&e.length===3&&e.every(t=>typeof t=="number"&&Number.isFinite(t))}var Ge=e=>new Promise(t=>setTimeout(t,e));function z(e){if(!e.hook||!e.sceneAvailable)throw new Error("This page has no three.js scene that the inspector can read.");return e.hook}var sn=e=>Array.isArray(e)&&e.length===3&&e.every(t=>typeof t=="number"&&Number.isFinite(t));function zm(e,t,n){let r=e.split(`
|
|
766
|
+
`),o=Math.max(1,Math.min(t,r.length));return{lines:r.length,text:r.slice(o-1,o-1+n).map((i,s)=>`${String(o+s).padStart(4)} ${i}`).join(`
|
|
767
|
+
`)}}async function kt(e,t){e.setScrub(Math.min(100,Math.max(0,t))),await Ge(R().page.stepped?1600:500)}async function Tu(e,t){if(z(e),!(e.path.editing&&!t)&&(R().mode!=="scene"&&await e.setMode("scene"),(t||R().record.status==="idle")&&await e.recordScroll(),!e.path.start()))throw new Error("The page could not be read for camera views: no scene camera was found.")}function Ru(e){let t=e.path.describe(),n=R();return{views:t.shots,cameraMovesOnScroll:n.record.status==="done",sectionsFound:n.sections.length,preview:t.preview,changes:t.changes,savedTo:t.savedTo}}function Au(e,t=40){return e.slice(0,t).map(n=>({...n,changes:n.changes.slice(0,12)}))}async function Pu(e,t){await Ge(150);let n=new Map,r=[];for(let o of t){n.has(o.uuid)||n.set(o.uuid,await qe(e,o.uuid).catch(()=>null));let i=rn(n.get(o.uuid)??void 0,o.path);r.push(i!==void 0&&!Di(i,o.value,1e-4))}return r}async function Et(e){R().mode!=="scene"&&await e.setMode("scene"),R().sideTab!=="look"&&J({sideTab:"look"})}function Zi(e){if(e==null)return{};if(typeof e!="object"||Array.isArray(e))throw new Error("uniforms is an object: { uName: value }.");let t={};for(let[n,r]of Object.entries(e)){if(!li(r))throw new Error(`${n}: a uniform is a number, 2 to 4 numbers, a colour as "#rrggbb", or a texture as { "texture": "scene:<uuid>" } or { "texture": "file:<path>" }.`);t[n]=ce(r)?{texture:r.texture}:r}return t}function Cu(e){let t={};if(e&&typeof e=="object"&&!Array.isArray(e))for(let[n,r]of Object.entries(e)){let o=r?.data;typeof o=="string"&&(t[n]=o)}return t}function Lu(e){let t=String(e.kind??"");if(!Pr.includes(t))throw new Error(`An effect needs a kind: ${Pr.join(", ")}.`);let n={kind:t};return typeof e.preset=="string"&&(n.preset=e.preset),typeof e.objectName=="string"&&(n.name=e.objectName),sn(e.position)&&(n.position=e.position),sn(e.scale)&&(n.scale=e.scale),typeof e.count=="number"&&(n.count=e.count),e.uniforms!==void 0&&(n.uniforms=Zi(e.uniforms)),typeof e.geometry=="string"&&(n.geometry=e.geometry),typeof e.vertex=="string"&&(n.vertex=e.vertex),typeof e.fragment=="string"&&(n.fragment=e.fragment),(e.blending==="normal"||e.blending==="additive")&&(n.blending=e.blending),typeof e.transparent=="boolean"&&(n.transparent=e.transparent),typeof e.depthTest=="boolean"&&(n.depthTest=e.depthTest),typeof e.depthWrite=="boolean"&&(n.depthWrite=e.depthWrite),(e.side==="front"||e.side==="back"||e.side==="double")&&(n.side=e.side),n}function $u(e,t){let{spec:n}=e;return{applied:!0,uuid:e.uuid,name:n.name,kind:n.kind,preset:n.preset,geometry:n.geometry,...n.geometry==="sprites"?{count:n.count}:{},position:n.position,scale:n.scale,blending:n.blending,uniforms:n.uniforms,ranges:ai(n.kind,n.preset),...e.sceneDepth===void 0?{}:{sceneDepth:e.sceneDepth,...e.sceneDepth?{}:{depthNote:"This page cannot hand the scene depth to the effect (WebGL 1, or a depth buffer that cannot be copied), so it ignores the objects it touches. Keep it clear of solid objects here; the written code takes a depth texture."}},note:t}}function Wm(e,t){let n=o=>ce(o)?`null /* ${o.texture} */`:typeof o=="number"?String(o):typeof o=="string"?`new THREE.Color('${o}')`:`new THREE.Vector${o.length}(${o.join(", ")})`;return["const uniforms = {"," uTime: { value: 0 },",...Object.entries(t).map(([o,i])=>` ${o}: { value: ${n(i)} },`),"};","material.onBeforeCompile = (shader) => {"," Object.assign(shader.uniforms, uniforms);",...e.map(o=>` shader.${o.stage}Shader = shader.${o.stage}Shader.replace(
|
|
768
|
+
${JSON.stringify(o.find)},
|
|
769
|
+
${JSON.stringify(o.replace)},
|
|
770
|
+
);`),"};","material.customProgramCacheKey = () => 'patched-1';"].join(`
|
|
771
|
+
`)}function ju(e){let t=n=>e.issues.filter(r=>r.severity===n).length;return{summary:e.issues.length?`${e.issues.length} issue${e.issues.length===1?"":"s"}: ${t("high")} high, ${t("medium")} medium, ${t("low")} low`:"No visual problems found by these checks.",issues:e.issues,measured:e.measured,canvas:e.canvas,checked:e.checked,note:"Checked for the view on screen now. Run it again at other scroll positions (scroll: [0, 25, 50, 75, 100]) and window sizes (set_viewport): textures, depth and resolution problems depend on where the camera is. It cannot see composition, taste or animation timing: judge those with take_screenshot."}}async function Ou(e,t,n){switch(t){case"status":{let r=R(),o=r.selectedUuid?e.propsCache.get(r.selectedUuid):void 0;return{inspectorOpen:!0,page:location.href,title:document.title,three:r.status?.three??!1,revision:r.status?.revision??null,sceneAvailable:e.sceneAvailable,sourceLocations:r.status?.bridge??!1,selected:o?{uuid:o.uuid,name:o.name,type:o.type}:null,changes:e.changes.changed().length}}case"inspector":{let r=R(),o={inspect:"Inspect",look:"Realism",performance:"Perf",resources:"Resources",animate:"Animate",learn:"Learn"},i=r.selectedUuid?e.propsCache.get(r.selectedUuid):void 0,s=[];return r.mode!=="scene"&&s.push("Layer mode is showing: the 3D tools still work, but the developer is looking at page layers, not the scene. select_object switches to scene mode."),r.toggles.pipeline||s.push(`"Site pipeline" is off: the site is not drawing, the view is a raw draw without its post-processing. get_performance counts no draw calls, audit_visuals cannot read a frame the site drew, and effects are not seen through the site's own passes. Ask the developer to turn it on (View > Site pipeline).`),r.isolated&&s.push("One object is shown alone (isolate): screenshots and the audit see only that object until the developer turns it off in the scene tree."),r.toggles.wireframe&&s.push('"Wireframe" is on: screenshots of the scene view show wireframes.'),r.preview&&s.push("Live preview is on: the inspector is hidden and the developer sees the real page."),r.pathEdit?.preview&&s.push("The edited camera path is being previewed: the site camera follows the edited keys, not the site's own code."),r.record.status==="recording"&&s.push("A scroll recording is running: the page is being scrolled by the inspector."),r.keepOnExit&&s.push('"Keep changes on the page after exit" is ticked: live changes stay on the page when the inspector closes (they are still not in the source).'),r.hookMissing&&s.push("The page was open before the extension was loaded: the three.js hook is missing. The developer must reload the page."),{mode:r.mode,sideTab:{id:r.sideTab,label:o[r.sideTab]??r.sideTab},tool:r.tool,gizmo:r.gizmo,view:{sitePipeline:r.toggles.pipeline,followCamera:r.follow,lookingThroughSiteCamera:r.lookThrough,helpers:r.toggles.helpers,htmlPlane:r.toggles.htmlPlane,grid:r.toggles.grid,wireframe:r.toggles.wireframe,siteHover:r.toggles.siteHover,livePreview:r.preview},selected:i?{uuid:i.uuid,name:i.name,type:i.type}:null,isolated:r.isolated,scenes:{drawnNow:Math.max(1,r.sceneOptions.length),pickedByHand:r.sceneChoice!==null},scroll:{percent:Math.round(r.scrub*10)/10,screens:r.page.screens,wheelDriven:!r.page.native,movesStopByStop:r.page.stepped},cameraPath:{recording:r.record.status,editing:r.pathEdit!==null,previewing:r.pathEdit?.preview??!1},realism:{lookActive:e.look.active,lensEffectsAvailable:r.look.effectsAvailable,savedTo:r.look.savedTo},changes:{values:e.changes.changed().length,undoSteps:r.undoDepth,keepOnExit:r.keepOnExit},assistantPanelOpen:r.ai.open,affectsYourTools:s,note:'What the developer sees and has switched in the inspector. get_guide topic "extension-ui" says where each of these is, so you can tell them what to click.'}}case"find":{let r=typeof n.query=="string"?n.query.trim().toLowerCase():"",o=typeof n.limit=="number"?n.limit:50,i=(await Qi(e)).filter(s=>(!n.kind||s.kind===n.kind)&&(!r||s.name.toLowerCase().includes(r)||s.type.toLowerCase().includes(r)));return{total:i.length,objects:i.slice(0,o)}}case"object":{let r=await we(e,n),o=await qe(e,r),i=await e.hook?.request("obj:bounds",{uuid:r}).catch(()=>null);return{...o,worldBounds:i??null,editable:Xc(o)}}case"set":{if(typeof n.path!="string"||!Eu(n.value))throw new Error("set_value needs a path and a value (number, boolean, string or [x, y, z]).");let r=await we(e,n),{before:o,value:i}=await e.agentSet(r,n.path,n.value),s=e.propsCache.get(r);e.toast(`AI set ${n.path} on ${s?.name||s?.type||"object"}`);let[a]=await Pu(e,[{uuid:r,path:n.path,value:i}]);return{uuid:r,object:s?.name??"",path:n.path,before:o,value:i,overwritten:a??!1}}case"setMany":{let r=Array.isArray(n.changes)?n.changes:[];if(!r.length||r.length>40)throw new Error("set_values needs 1 to 40 changes.");let o=[];for(let[l,c]of r.entries()){if(typeof c.path!="string"||!Eu(c.value))throw new Error(`Change ${l+1}: needs a path and a value (number, boolean, string or [x, y, z]).`);try{let u=await we(e,c);await e.agentCheck(u,c.path,c.value),o.push({uuid:u,path:c.path,value:c.value})}catch(u){throw new Error(`Change ${l+1}: ${u instanceof Error?u.message:String(u)} Nothing was changed.`)}}let i=`agent-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,s=[];for(let l of o){let{before:c,value:u}=await e.agentSet(l.uuid,l.path,l.value,i),f=e.propsCache.get(l.uuid);s.push({uuid:l.uuid,object:f?.name??"",path:l.path,before:c,value:u})}e.toast(`AI changed ${o.length} value${o.length===1?"":"s"}`);let a=await Pu(e,o);return s.forEach((l,c)=>l.overwritten=a[c]??!1),{changed:s.length,undo:"one undo_change takes back all of them",results:s}}case"pathEdit":return e.path.describe();case"pathAction":{let r=String(n.action??""),o=typeof n.index=="number"?n.index:-1,i=l=>sn(l)?l:void 0,s=()=>{if(!e.path.editing)throw new Error('Not editing a camera path. Use action "start" first.')},a=()=>{s();let l=R().pathEdit.keys;if(!l[o])throw new Error(`No key ${o}: there are ${l.length} (0 to ${l.length-1}).`)};switch(r){case"start":{R().mode!=="scene"&&await e.setMode("scene");let l=Array.isArray(n.keys)?n.keys:void 0;if(!e.path.start(l))throw new Error("No recorded camera path. Call get_camera_path first (it records the scroll).");break}case"set_key":{a(),e.path.checkpoint();let l={},c=i(n.position),u=i(n.target);c&&(l.position=c),u&&(l.target=u),typeof n.fov=="number"&&(l.fov=n.fov),typeof n.percent=="number"&&(l.percent=n.percent),e.path.update(o,l),e.path.select(o,u&&!c?"target":"position");break}case"add_key":{if(s(),typeof n.percent!="number")throw new Error("add_key needs a percent.");let l=e.path.addAt(n.percent),c=i(n.position),u=i(n.target);l>=0&&(c||u)&&e.path.update(l,{...c?{position:c}:{},...u?{target:u}:{}});break}case"remove_key":a(),e.path.remove(o);break;case"preview":s(),e.path.setPreview(n.on!==!1);break;case"reset":s(),e.path.reset();break;case"stop":return e.path.stop(),{editing:!1};default:throw new Error("action must be start, set_key, add_key, remove_key, preview, reset or stop.")}return typeof n.scroll=="number"&&await kt(e,n.scroll),e.path.describe()}case"shots":return await Tu(e,n.record===!0),Ru(e);case"shotSet":{await Tu(e,!1);let r=typeof n.view=="number"||typeof n.view=="string"?n.view:1,o=e.path.shot(r);if(!o)throw new Error(`No view "${String(r)}". Views: ${e.path.shots().map((l,c)=>`${c+1} ${l.id} (${l.label})`).join(", ")}.`);let i={},s=n.frame;if(s&&typeof s=="object"){let l=await we(e,{uuid:s.uuid,name:s.object??s.name}),c=await z(e).request("obj:bounds",{uuid:l}).catch(()=>null);if(!c)throw new Error("That object has no size to frame (a light, an empty group).");let u=Hi.includes(s.from)?s.from:void 0;if(s.from!==void 0&&!u)throw new Error(`frame.from must be one of: ${Hi.join(", ")}.`);let f=R().snapshot?.canvas;Object.assign(i,ru(c,{side:u,fill:typeof s.fill=="number"?s.fill:void 0,fov:typeof n.fov=="number"?n.fov:o.pose.fov,aspect:f&&f.height>0?f.width/f.height:void 0}))}else if(n.fromView===!0){let l=R().lookThrough?null:iu.view?.();if(!l)throw new Error("The developer has not framed a view: the 3D view is the site camera (or this is the headless preview). Ask them to drag the view first, or pass position and target, or frame an object.");Object.assign(i,ou(l,typeof n.fov=="number"?n.fov:o.pose.fov))}sn(n.position)&&(i.position=n.position),sn(n.target)&&(i.target=n.target),typeof n.fov=="number"&&(i.fov=n.fov);let a=typeof n.hold=="boolean"?n.hold:void 0;if(n.reset===!0)e.path.resetShot(o.id);else if(Object.keys(i).length||a!==void 0)e.path.setShot(o.id,i,a);else throw new Error("Say what the view shows: position and/or target, frame { object }, fromView: true, hold, or reset: true.");return n.show!==!1&&(e.path.setPreview(!0),J({lookThrough:!0}),await kt(e,o.percent)),{set:e.path.shot(o.id)?o.id:null,...Ru(e)}}case"pathSave":{if(!e.path.editing)throw new Error("Not editing a camera path.");let r=await e.path.save(typeof n.file=="string"?n.file:void 0);if(!r.ok)throw new Error(r.error??"Not saved.");return{file:r.file,json:e.path.describe().json}}case"look":return z(e),e.look.describe();case"lookFix":{z(e),await Et(e);let r=Array.isArray(n.ids)?n.ids.filter(i=>typeof i=="string"):void 0,o=await e.look.fix(r?.length?r:void 0);return o&&e.toast(`AI fixed ${o} realism issue${o===1?"":"s"}`),{fixed:o,...await e.look.describe()}}case"lookSet":{z(e),await Et(e),n.reset===!0&&await e.look.replace(Ne());let{reset:r,...o}=n;return Object.keys(o).length&&await e.look.set(o),e.toast(n.reset===!0?"AI reset the look":"AI changed the look"),e.look.describe()}case"lookSurface":{let r=await we(e,n),o=await qe(e,r);await Et(e),await e.selectObject(r);let i={uuid:r,name:o.name};if(n.clear===!0)await e.look.clearMaterial(r);else{let a={};typeof n.preset=="string"&&(a.preset=n.preset),typeof n.color=="string"&&(a.color=n.color);for(let l of["metalness","roughness","clearcoat","clearcoatRoughness","transmission","ior","thickness","envMapIntensity"])typeof n[l]=="number"&&(a[l]=n[l]);Object.keys(a).length&&await e.look.material(i,a)}n.detail===null?await e.look.surfaceDetail(i,null):n.detail&&typeof n.detail=="object"&&await e.look.surfaceDetail(i,n.detail),typeof n.bevel=="boolean"&&await e.look.bevelObject(i,n.bevel),e.toast(`AI set the surface of ${o.name||o.type}`);let s=await e.look.describe();return{object:{uuid:r,name:o.name,material:o.mesh?.materialType},...o.name?{}:{warning:"This object has no name: a saved look finds objects by name. Give it a name in the source before save_look."},...s}}case"lookReference":{z(e),await Et(e);let r=typeof n.image=="string"?await e.look.reference(n.image,typeof n.name=="string"?n.name:"Reference"):await e.look.compare();if(!r)throw new Error("No reference picture to compare with. Pass `file` (a picture in the project), or ask the developer to drop one into Realism \u203A Match a reference.");return{match:r.match,differences:r.differences,yours:r.yours,reference:r.reference}}case"lookCost":{if(z(e),!e.look.active)throw new Error("The look changes nothing yet, so there is nothing to measure the cost of.");await Et(e);let r=await e.look.profile(),{fps:o,siteFps:i}=await e.look.measure();return{fps:o,siteFps:i,costs:r,unit:"milliseconds of frame time per part"}}case"lookAdapt":{z(e),await Et(e),e.look.watch();let r=typeof n.uuid=="string"||typeof n.name=="string"?{...typeof n.uuid=="string"?{uuid:n.uuid}:{},...typeof n.name=="string"?{name:n.name}:{}}:null,o=await e.look.adapt(r,{ground:n.ground===!0,...typeof n.scale=="number"?{scale:n.scale}:{},lighten:n.lighten!==!1});return e.toast(o.changes.length?`AI adapted the look: ${o.changes.length} change(s)`:"AI checked the models: nothing to change"),{...o,modelsInScene:R().look.adapt.models,look:e.look.look,note:"Sizes and gaps are in world units, measured on the live page. Advice with an `option` is done by calling adapt_model again with that option and the model name."}}case"lookLighten":{z(e),await Et(e);let r=typeof n.targetFps=="number"?n.targetFps:void 0,o=await e.look.lightenUntil(r);return o.steps.length&&e.toast(`AI lightened the look: ${o.steps.length} step(s)`),{steps:o.steps,goalFps:o.goal,...await e.look.describe()}}case"lookSave":{if(!e.look.active)throw new Error("The look changes nothing yet: there is nothing to save.");let r=await e.look.save(typeof n.file=="string"?n.file:void 0);if(!r.ok)throw new Error(r.error??"Not saved.");let o=String(r.file).split("/").pop();return{file:r.file,json:Nn(e.look.look),usage:Fr(`./${o}`)}}case"controls":return z(e),{controls:await e.look.loadControls(),unsaved:R().controls.dirty.length};case"controlSet":{z(e);let r=n.value;if(typeof r!="number"&&typeof r!="boolean"&&typeof r!="string")throw new Error("set_site_control needs a number, boolean or string value.");let i=(await e.look.setControl(String(n.group),String(n.key),r)).find(s=>s.group===n.group&&s.key===n.key);return e.toast(`AI set ${String(n.group)}.${String(n.key)}`),{control:i,unsaved:R().controls.dirty.length}}case"controlsSave":{let r=await e.look.saveControls();if(r.error)throw new Error(r.error);return{saved:r.saved,failed:r.failed}}case"describe":{let r=await Qi(e),o=R().snapshot;if(!o)throw new Error("No active three.js scene found.");let i={};for(let d of r)i[d.kind]=(i[d.kind]??0)+1;let s=[];for(let d of r.filter(p=>p.kind==="light").slice(0,12)){let p=await qe(e,d.uuid).catch(()=>null);p&&s.push({uuid:p.uuid,name:p.name,type:p.type,color:p.light?.color,intensity:p.light?.intensity,position:p.position,castShadow:p.castShadow})}let a=o.siteCamera,{center:l,radius:c}=o.bounds,u=d=>Math.round(d*1e3)/1e3,f=Math.hypot(a.position[0]-l[0],a.position[1]-l[1],a.position[2]-l[2]);return{page:location.href,objects:{total:o.nodeCount,truncated:o.truncated,byKind:i},scene:{center:l.map(u),radius:u(c),note:`Scene units: everything fits in a sphere of radius ${u(c)} around center. Size moves and new objects to this scale.`},focus:{center:o.focus.center.map(u),radius:u(o.focus.radius)},camera:{uuid:a.uuid,type:a.type,position:a.position.map(u),fov:a.fov,near:a.near,far:a.far,distanceToCenter:u(f)},lights:s,renderer:o.info,changes:e.changes.changed().length}}case"changes":{let r=e.changes.changed(),o=Kc(r,a=>e.propsCache.get(a)),i=[];try{i=await e.hook?.request("tools:changes")??[]}catch{}let s=[];for(let a of i.filter(l=>l.kind==="added")){let l=await e.hook?.request("obj:props",{uuid:a.uuid}).catch(()=>null);s.push({...a,r3f:l?Qr([Fi(l)]):""})}return{page:location.href,changes:o,withoutSource:o.filter(a=>!a.source).length,r3f:Qr(e.codeTargets("changed")),added:s,removed:i.filter(a=>a.kind==="removed"),shaders:i.filter(a=>a.kind==="shader"),effects:(await e.hook?.request("fx:list").catch(()=>null)??[]).map(a=>({uuid:a.uuid,name:a.spec.name,kind:a.spec.kind,note:"Not written automatically: get_effect_code returns the file to add."})),shaderPatches:await e.hook?.request("fx:patches").catch(()=>null)??[]}}case"apply":return e.applyToCode();case"select":{let r=await we(e,n);R().mode!=="scene"&&await e.setMode("scene"),await e.selectObject(r);let o=e.propsCache.get(r);return{uuid:r,name:o?.name??"",type:o?.type??""}}case"undo":return await e.undo(),{changes:e.changes.changed().length};case"reset":return await e.resetChanges(),{changes:0};case"screenshot":{let r=n.view==="scene"||n.view==="site"?n.view:"inspector";return typeof n.angle=="string"&&r!=="site"&&(n.angle==="reset"?Yi.emit({type:"reset"}):Yi.emit({type:"preset",name:n.angle}),await Ge(700)),e.agentScreenshot(r)}case"performance":{let r=z(e),o=Math.min(5,Math.max(.5,Number(n.seconds)||1.5)),i=R().sideTab==="performance",s=await r.request("perf:read",{since:0});await r.request("perf:sample",{on:!0}),await Ge(o*1e3);let a=await r.request("perf:read",{since:s.seq}),l=await r.request("frame:capture",{},2500);i||await r.request("perf:sample",{on:!1});let c=await r.request("scene:info"),u=eo(a.samples);return{...u,measured:u?`${u.frames} frames over ${o}s`:"no frames",canvas:c&&{width:c.width,height:c.height,pixelRatio:c.pixelRatio},postProcessing:c?.postProcessing??!1,jsHeapMB:a.heap?Math.round(a.heap/1048576):null,loaded:a.loaded,passesOfOneFrame:l.slice(0,30),note:u&&u.drawCalls===0?'No draw calls were counted: the "Site pipeline" switch in the inspector is off, so the site is not drawing. Turn it on and measure again.':"Numbers are for the inspector view with the site pipeline. Frame rate is capped by the screen refresh rate."}}case"resources":{let r=await z(e).request("res:list");if(!r)throw new Error("No active three.js scene found.");let o=Math.min(100,Math.max(1,Number(n.limit)||15)),i=a=>Math.round(a/1048576*100)/100,s=a=>a.slice(0,o).map(l=>({name:l.name,detail:l.detail,megabytes:i(l.bytes),usedBy:l.users,anObjectUsingIt:l.owner}));return{objects:r.objects,textureMemoryMB:i(r.textureBytes),geometryMemoryMB:i(r.geometryBytes),counts:{textures:r.textures.length,geometries:r.geometries.length,materials:r.materials.length},loadedByRenderer:r.loaded,textures:s(r.textures),geometries:s(r.geometries),materials:s(r.materials),note:"Sorted biggest first. Memory is an estimate of GPU memory, mipmaps included."}}case"errors":{let r=e.hook;if(!r)throw new Error("The page is not reachable. Reload it and open the inspector again.");return{...await r.request("tools:errors",{clear:!!n.clear}),note:"Uncaught errors are kept from page load; console.error and console.warn only from when the inspector was opened. Reload the page with the inspector open to catch start-up messages."}}case"lighting":{let r=await z(e).request("tools:lighting");if(!r)throw new Error("No active three.js scene found.");return{...r,shadowMapType:["BasicShadowMap","PCFShadowMap","PCFSoftShadowMap","VSMShadowMap"][r.shadowMapType]??"unknown",shadowMapMB:Math.round(r.shadowMapBytes/1048576*100)/100}}case"shader":{let r=await we(e,n),o=await z(e).request("mat:shader",{uuid:r}),i=await qe(e,r);if(!o)throw new Error(`${i.name||i.type} has no shader to show.`);let s=n.stage==="vertex"||n.stage==="fragment"?n.stage:null,a=Math.max(1,Number(n.fromLine)||1),l=Math.min(2e3,Math.max(1,Number(n.lines)||400)),c={object:i.name,material:i.mesh?.materialType,kind:o.kind,note:o.kind==="compiled"?"This is the full program three.js compiled: the material's own code with three.js's header and chunks expanded. set_shader takes the material's own source, as in the project files, not this text.":"This is the source as the site wrote it.",canBeReplaced:/ShaderMaterial$/.test(i.mesh?.materialType??""),uniforms:i.mesh?.uniforms},u=s?[s]:["vertex","fragment"];for(let f of u){let d=zm(o[f],a,l);c[f]=d.text,c[`${f}Lines`]=d.lines}return c}case"setShader":{let r=await we(e,n),o=await z(e).request("tools:shader",{uuid:r,vertex:typeof n.vertex=="string"?n.vertex:null,fragment:typeof n.fragment=="string"?n.fragment:null},4e3),i=await qe(e,r);return e.toast(o.applied?`AI replaced the shader of ${i.name||i.type}`:"AI shader did not compile: the old one is back"),o.applied?{...o,note:"Live only. Write the same source into the project file to keep it."}:{...o,note:"The shader did not compile, so the previous one was put back."}}case"patchShader":{let r=await we(e,n),o=(Array.isArray(n.patches)?n.patches:[]).map(l=>{let c=l;if(c.stage!=="vertex"&&c.stage!=="fragment"||typeof c.find!="string"||typeof c.replace!="string"||!c.find)throw new Error('Each patch needs stage ("vertex" or "fragment"), find and replace.');return{stage:c.stage,find:c.find,replace:c.replace}}),i=Zi(n.uniforms),s=await z(e).request("fx:patch",{uuid:r,patches:o,uniforms:i},5e3),a=await qe(e,r);return o.length===0?{...s,note:`The shader of ${a.name||a.type} is as the site made it again.`}:(e.toast(s.applied?`AI changed the shader of ${a.name||a.type}`:"AI shader patch failed: the old shader is back"),s.applied?{...s,onBeforeCompile:Wm(o,i),note:`Live only. To keep it, set this onBeforeCompile on the ${s.material} in the source (in R3F: the onBeforeCompile prop of the material element) and update uTime every frame if the patch uses it.`}:{...s,note:s.missed.length?`Nothing was changed: ${s.missed.map(l=>JSON.stringify(l)).join(", ")} is not in the ${s.material} shader. Read it with get_shader (the compiled program has every #include expanded, so match an #include line by its name, e.g. "#include <begin_vertex>").`:"The patched shader did not compile, so the previous one was put back."})}case"effectKinds":return{kinds:Ml(),filledInEveryFrame:Vn};case"addEffect":{let r=z(e),o=Lu(n),i=R().snapshot,s=i?.focus??i?.bounds,a=s?.radius&&s.radius>0?s.radius:1;if(!o.position&&s){let[c,u,f]=s.center;o.position=o.kind==="clouds"?[c,u+a*.45,f]:[c,u,f]}let l=await r.request("fx:add",{request:{...o,parent:n.parent},radius:a,textures:Cu(n.uniforms)},6e3);return l.applied?(await e.refreshSnapshot(),R().mode!=="scene"&&await e.setMode("scene"),await e.selectObject(l.uuid),e.toast(`AI added ${l.spec.name}`),$u(l,"Live only. Move and size it with set_value (position, scale), tune it with set_effect, and when it is right: get_effect_code.")):{applied:!1,errors:l.errors,note:"The shader did not compile, so nothing was added. Line numbers count from the first line of the source you sent, after the declarations three.js puts in front."}}case"setEffect":{let r=await we(e,n),o={};if(n.uniforms!==void 0&&(o.uniforms=Zi(n.uniforms)),typeof n.count=="number"&&(o.count=n.count),typeof n.vertex=="string"&&(o.vertex=n.vertex),typeof n.fragment=="string"&&(o.fragment=n.fragment),(n.blending==="normal"||n.blending==="additive")&&(o.blending=n.blending),typeof n.objectName=="string"&&(o.name=n.objectName),Object.keys(o).length===0)throw new Error("set_effect needs uniforms, count, blending, vertex or fragment.");let i=await z(e).request("fx:set",{uuid:r,patch:o,textures:Cu(n.uniforms)},6e3);return i.applied?$u(i,'Check it: take_screenshot view:"site" compare:true.'):{applied:!1,errors:i.errors,note:"The shader did not compile, so the previous one was put back."}}case"effectCode":{let r=n.format==="three"?"three":"r3f",o;if(typeof n.uuid=="string"||typeof n.name=="string"){let i=await we(e,n),a=(await z(e).request("fx:list")).find(l=>l.uuid===i);if(!a)throw new Error("That object is not an effect made with add_effect.");o=a.spec}else o=Cr(Lu(n),1);return{format:r,code:Pl(o,r),note:r==="r3f"?"Save it as a component file and render it inside <Canvas>. It replaces the live effect: reset_changes (or a reload) takes the live one away.":"Save it as a module, add the returned mesh to the scene and call update(elapsedSeconds) every frame."}}case"audit":{let r=z(e),o=Array.isArray(n.scroll)?n.scroll.filter(u=>typeof u=="number"&&u>=0&&u<=100).slice(0,8):[],i=()=>r.request("audit:run",{pixels:n.pixels!==!1},9e3);if(o.length===0){let u=await i();if(!u)throw new Error("No active three.js scene found.");return ju(u)}let s=R().scrub,a=new Map,l=[],c=null;try{for(let u of o){await kt(e,u),await Ge(350);let f=await i();if(f){c=f,l.push({scroll:u,issues:f.issues.length,measured:f.measured});for(let d of f.issues){let p=a.get(d.id);p?p.atScroll.push(u):a.set(d.id,{...d,atScroll:[u]})}}}}finally{await kt(e,s).catch(()=>{})}if(!c)throw new Error("No active three.js scene found.");return{...ju({...c,issues:[...a.values()]}),stops:l}}case"scrollNow":return{percent:R().scrub};case"design":{let r=await z(e).request("design:run",{},12e3);if(!r)throw new Error("No active three.js scene found.");let o=await e.hook?.request("cam:pose",{},800).catch(()=>null);return{...r,scroll:R().scrub,siteCamera:o}}case"scroll":{if(typeof n.percent!="number")throw new Error("set_scroll needs a percent, 0 to 100.");z(e),await kt(e,n.percent);let r=await e.hook?.request("cam:pose",{},800).catch(()=>null);return{percent:R().scrub,siteCamera:r}}case"time":{let r=String(n.action),o=await z(e).request("tools:time",{action:r,frames:Number(n.frames)||1,stepMs:Number(n.stepMs)||1e3/60});return e.toast(r==="pause"?"AI holds the animation":r==="resume"?"Animation runs again":"AI stepped the animation"),o}case"animated":{let r=z(e),o=Math.min(4,Math.max(.3,Number(n.seconds)||1)),i=await r.request("tools:sources");if(i.timeHeld)throw new Error('The animation is held. Call set_time with action "resume" first.');await r.request("tools:baseline"),await Ge(o*1e3);let s=await r.request("tools:animated"),a=null;if(n.checkScroll!==!1&&e.driver&&e.driver.total>0){let l=R().scrub,c=new Set(s.flatMap(f=>f.changes.map(d=>`${f.uuid} ${d.path}`)));await r.request("tools:baseline"),await kt(e,l>50?l-35:l+35),a=(await r.request("tools:animated")).map(f=>({...f,changes:f.changes.filter(d=>!c.has(`${f.uuid} ${d.path}`))})).filter(f=>f.changes.length>0),await kt(e,l)}return{overTime:Au(s),onScroll:a&&Au(a),sources:i,note:"A value listed here is written by the site's own code every frame or on scroll. Setting it in JSX only changes its starting value, and set_value on it is overwritten. Change the code that drives it instead."}}case"cameraMotion":{let r=z(e);if(!e.driver||e.driver.total<=0)throw new Error("This page does not scroll, so there is no scroll-driven camera to check.");let o=Math.min(200,Math.max(24,Math.round(Number(n.steps)||96))),i=()=>r.request("cam:pose",{},1500).catch(()=>null),s=(b,y)=>Math.hypot(b.position[0]-y.position[0],b.position[1]-y.position[1],b.position[2]-y.position[2])/Math.max(1,Math.hypot(...b.position))+Math.hypot(...b.quaternion.map((v,x)=>v-y.quaternion[x])),a=R().page.stepped,l=3e-4,c=async b=>{await Ge(a?900:90);let y=await i(),v=!1,x=0;for(let M=0;y&&M<b;M++){await Ge(120);let S=await i();if(!S)break;if(x=s(y,S)<l?x+1:0,y=S,x>=2){v=!0;break}}return y?{pose:y,still:v}:null},u=R().scrub,f=[],d=[],p=0,m=new Set([.2,.5,.8].map(b=>Math.round(b*o)));try{e.setScrub(0),await c(45);for(let b=0;b<=o;b++){let y=b/o*100;e.setScrub(y);let v=await c(45);if(!v)break;let x=v.pose;if(v.still||p++,f.push({percent:y,position:x.position,quaternion:x.quaternion,fov:x.fov}),m.has(b)){await Ge(500);let M=await i();if(M){let S=Math.abs(x.quaternion.reduce((k,E,L)=>k+E*M.quaternion[L],0));d.push({percent:y,moved:Math.hypot(M.position[0]-x.position[0],M.position[1]-x.position[1],M.position[2]-x.position[2]),turnedDegrees:2*Math.acos(Math.min(1,S))*180/Math.PI})}}}}finally{e.setScrub(u)}if(f.length<8)throw new Error("The site camera could not be read while scrolling. Is the scene still loading?");let g=Zc(f,d);if(g.measured.pathLength===0&&g.measured.totalTurnDegrees<.5)return{moves:!1,note:"The site camera does not move when the page is scrolled. If the page is locked behind an intro (a button, a hold), pass that first, or open it at a URL that skips the intro."};let h=Math.round((1-p/f.length)*100)/100;return{moves:!0,confidence:h>=.85?"high":h>=.6?"medium":"low",settledShare:h,...h<.85?{warning:`At ${Math.round((1-h)*100)}% of the stops the camera was still moving 5 seconds after the scroll stopped: it is driven by time there (an animation that plays by itself, a sway, a pointer follow) as well as by the scroll. Jumps, reversals and swings reported in those ranges may come from that and not from the scroll path. set_time { action: "pause" } first, or read get_animated_values, to tell them apart.`}:{},...g,note:"Measured from the camera alone, at even scroll steps, after it settled at each one. It does not know the subject: take_screenshot at each of checkAt to judge framing. A cut is listed under shots and is not counted as a fault."}}case"cameraPath":{z(e),(n.record===!0||R().record.status==="idle")&&await e.recordScroll();let r=R().record;if(r.status==="static")return{moves:!1,note:"The site camera does not move when the page is scrolled."};let o=Math.max(1,Math.ceil(r.samples.length/40)),i=s=>Math.round(s*1e3)/1e3;return{moves:r.samples.length>0,exact:r.exact,samples:r.samples.length,path:r.samples.filter((s,a)=>a%o===0||a===r.samples.length-1).map(s=>({scrollPercent:i(s.percent),position:s.position.map(i),quaternion:s.quaternion.map(i),fov:i(s.fov),section:s.section}))}}case"add":{let r=z(e),o={kind:String(n.kind??"")};if(typeof n.copyOf=="string"&&(o.copyOf=n.copyOf),typeof n.parent=="string"&&(o.parent=n.parent),typeof n.objectName=="string"&&(o.name=n.objectName),sn(n.position)&&(o.position=n.position),typeof n.color=="string"&&(o.color=n.color),typeof n.intensity=="number"&&(o.intensity=n.intensity),!o.kind&&!o.copyOf)throw new Error(`add_object needs a kind or copyOf. Kinds here: ${(await r.request("tools:addable")).join(", ")}.`);let i=await r.request("tools:add",o);await e.refreshSnapshot(),R().mode!=="scene"&&await e.setMode("scene"),await e.selectObject(i);let s=await qe(e,i);return e.toast(`AI added ${s.name||s.type}`),{uuid:i,name:s.name,type:s.type,r3f:Qr([Fi(s)]),note:"Live only: it is gone after a reload. Put the JSX into the source to keep it."}}case"remove":{let r=await we(e,n),o=await qe(e,r);return await z(e).request("tools:remove",{uuid:r}),R().selectedUuid===r&&J({selectedUuid:null,props:null}),await e.refreshSnapshot(),e.toast(`AI removed ${o.name||o.type}`),{removed:{uuid:r,name:o.name,type:o.type},source:o.source,note:"Live only: reset_changes puts it back. To remove it for good, delete its element in the source."}}case"viewport":{let r={};if(n.reset===!0)return Object.assign(r,await e.agentViewport(null)),e.sceneAvailable&&(r.renderer=await e.hook?.request("tools:ratio",{ratio:null}).catch(()=>null)),r;if(typeof n.width=="number"&&typeof n.height=="number"){let o=await e.agentViewport({width:n.width,height:n.height});Object.assign(r,o),(Math.abs(o.width-n.width)>2||Math.abs(o.height-n.height)>2)&&(r.note=`The page is ${o.width} \xD7 ${o.height}, not the size asked for: a browser window cannot be made narrower than about 500 pixels or larger than the screen. For a real phone size use the device toolbar of Chrome DevTools.`)}if(typeof n.pixelRatio=="number"&&(r.renderer=await z(e).request("tools:ratio",{ratio:n.pixelRatio})),typeof n.devicePixelRatio=="number"&&(r.devicePixelRatio=window.devicePixelRatio),Object.keys(r).length===0)throw new Error("set_viewport needs width and height, a pixelRatio, or reset: true.");return r}default:throw new Error(`Unknown request: ${t}`)}}var _u=(e,t,n)=>(.2126*e+.7152*t+.0722*n)/255,ee=(e,t=3)=>{let n=10**t;return Math.round(e*n)/n},Bm=(e,t,n)=>`#${[e,t,n].map(r=>Math.round(r).toString(16).padStart(2,"0")).join("")}`;function ts(e,t,n){let r=t*n,o=new Float32Array(r),i=0,s=0,a=0,l=0,c=0,u=new Map;for(let v=0;v<r;v++){let x=e[v*4],M=e[v*4+1],S=e[v*4+2],k=_u(x,M,S);o[v]=k,i+=k;let E=Math.max(x,M,S),L=Math.min(x,M,S);s+=E===0?0:(E-L)/E,a+=(x-S)/255,k>.9&&l++,k<.08&&c++;let A=(x>>6)*16+(M>>6)*4+(S>>6),C=u.get(A);C?(C.n++,C.r+=x,C.g+=M,C.b+=S):u.set(A,{n:1,r:x,g:M,b:S})}let f=i/r,d=0;for(let v=0;v<r;v++)d+=(o[v]-f)**2;let p=Float32Array.from(o).sort(),m=v=>p[Math.min(r-1,Math.floor(r*v))],g=0;for(let v=0;v<n-1;v++)for(let x=0;x<t-1;x++){let M=v*t+x;g+=Math.abs(o[M]-o[M+1])+Math.abs(o[M]-o[M+t])}let h=(v,x,M,S)=>{let k=0,E=0;for(let L=Math.floor(x*n);L<Math.ceil(S*n);L++)for(let A=Math.floor(v*t);A<Math.ceil(M*t);A++)k+=o[L*t+A],E++;return E?k/E:0},b=(h(0,0,.15,.15)+h(.85,0,1,.15)+h(0,.85,.15,1)+h(.85,.85,1,1))/4,y=h(.3,.3,.7,.7);return{brightness:ee(f),black:ee(m(.05)),mid:ee(m(.5)),white:ee(m(.95)),contrast:ee(Math.sqrt(d/r)),saturation:ee(s/r),warmth:ee(a/r),highlights:ee(l/r),shadows:ee(c/r),sharpness:ee(g/Math.max(1,(t-1)*(n-1)),4),corners:ee(y>.01?b/y:1),palette:[...u.values()].sort((v,x)=>x.n-v.n).slice(0,5).map(v=>Bm(v.r/v.n,v.g/v.n,v.b/v.n))}}function Iu(e,t,n,r){let o=Math.floor(r[0]*t),i=Math.ceil(r[2]*t),s=Math.floor(r[1]*n),a=Math.ceil(r[3]*n),l=[{sum:0,high:0,low:0,n:0},{sum:0,high:0,low:0,n:0}];for(let u=0;u<n;u++)for(let f=0;f<t;f++){let d=(u*t+f)*4,p=_u(e[d],e[d+1],e[d+2]),m=l[f>=o&&f<i&&u>=s&&u<a?0:1];m.sum+=p,m.n++,p>.965?m.high++:p<.03&&m.low++}let c=u=>({brightness:u.n?ee(u.sum/u.n):0,highlights:u.n?ee(u.high/u.n):0,shadows:u.n?ee(u.low/u.n):0,pixels:u.n});return{inside:c(l[0]),outside:c(l[1])}}var es=(e,t,n)=>Math.min(n,Math.max(t,e));function Fu(e,t,n){let r=[],o=n.world.preset!=="site",i=n.world.boxes[0],s=(t.brightness+.02)/(e.brightness+.02);if(Math.abs(Math.log2(s))>.14){let f=ee(es((n.color.exposure??1)*s**1.6,.2,4),2);r.push({id:"brightness",size:Math.abs(Math.log2(s))*40,title:s>1?"The reference is brighter":"The reference is darker",yours:e.brightness,reference:t.brightness,advice:`Set the exposure to about ${f}.`,patch:{color:{exposure:f}},patchLabel:`Exposure ${f}`})}let a=(t.contrast+.02)/(e.contrast+.02);if(a>1.18||a<.84){let f=a>1,d=f?"aces":"agx",p=n.color.toneMapping===d;r.push({id:"contrast",size:Math.abs(Math.log2(a))*35,title:f?"The reference has more contrast":"The reference is softer, with less contrast",yours:e.contrast,reference:t.contrast,advice:f?`${p?"":"Filmic (ACES) tone mapping adds contrast. "}Then darken the room: lower the world's sky brightness and keep the light boxes, so lit sides stay bright and the rest falls off.`:`${p?"":"AgX tone mapping is gentler. "}Then lift the fill: raise the sky brightness or add a large, soft light box opposite the key.`,...p?o?{patch:{world:{sky:{intensity:ee(n.world.sky.intensity*(f?.6:1.5),2)}}},patchLabel:f?"Darker room":"Brighter room"}:{}:{patch:{color:{toneMapping:d}},patchLabel:f?"Filmic":"AgX"}})}t.black<e.black-.05&&r.push({id:"shadows",size:(e.black-t.black)*120,title:"The reference has deeper shadows",yours:e.black,reference:t.black,advice:"Its darkest parts are close to black; yours are lifted. Lower the sky brightness of the world, turn on ambient occlusion, or darken the page background.",...o?{patch:{world:{sky:{intensity:ee(n.world.sky.intensity*.6,2)}}},patchLabel:"Darker room"}:{}}),t.white>e.white+.08&&r.push({id:"highlights",size:(t.white-e.white)*100,title:"The reference has brighter highlights",yours:e.white,reference:t.white,advice:i?`Raise the "${i.name}" light box (and lower surface roughness a little) so highlights reach white.`:"Add world lighting with a bright key light box, so glossy surfaces have a highlight to show.",patch:o&&i?{world:{boxes:n.world.boxes.map((f,d)=>d===0?{...f,intensity:ee(Math.min(40,f.intensity*1.5),1)}:f)}}:{world:{preset:"studio"}},patchLabel:o&&i?"Brighter key light":"Add studio lighting"});let l=t.warmth-e.warmth;if(Math.abs(l)>.035){let f=l>0,d=f?"#ffd2a1":"#cfe2ff";r.push({id:"warmth",size:Math.abs(l)*300,title:f?"The reference is warmer":"The reference is cooler",yours:e.warmth,reference:t.warmth,advice:f?"Tint the key light towards amber and the sky towards a warm grey.":"Tint the key light towards blue-white and the sky towards a cool grey or navy.",...o&&i?{patch:{world:{boxes:n.world.boxes.map((p,m)=>m===0?{...p,color:d}:p)}},patchLabel:f?"Warm key light":"Cool key light"}:{}})}let c=t.saturation-e.saturation;if(Math.abs(c)>.07){let f=c>0,d=f?"neutral":"agx";r.push({id:"saturation",size:Math.abs(c)*150,title:f?"The reference is more colourful":"The reference is more muted",yours:e.saturation,reference:t.saturation,advice:f?"Neutral tone mapping keeps colours saturated (AgX washes bright colours out). Also check the materials\u2019 own colours.":"AgX tone mapping mutes bright colours the way film does. Or lower the saturation of the materials.",...n.color.toneMapping===d?{}:{patch:{color:{toneMapping:d}},patchLabel:f?"Neutral":"AgX"}})}if(t.corners<.85&&t.corners<e.corners-.1){let f=ee(es((1-t.corners)*1.2,.1,.8),2);r.push({id:"vignette",size:(e.corners-t.corners)*50,title:"The reference darkens towards the corners",yours:e.corners,reference:t.corners,advice:`Add a vignette of about ${f}, or darken the edges of the page background.`,patch:{effects:{vignette:f}},patchLabel:`Vignette ${f}`})}t.sharpness>e.sharpness*1.35&&n.quality.pixelRatio===null&&r.push({id:"sharpness",size:12,title:"The reference is crisper",yours:e.sharpness,reference:t.sharpness,advice:"Render at the full pixel ratio, and give surfaces fine detail (a brushed finish, bevels that catch a highlight).",patch:{quality:{pixelRatio:2}},patchLabel:"Full resolution"}),r.sort((f,d)=>d.size-f.size);let u=r.reduce((f,d)=>f+Math.min(30,d.size),0);return{match:Math.round(es(100-u,0,100)),differences:r.map(({size:f,...d})=>d),yours:e,reference:t}}var Hm=80,Tt=e=>`${e.group}\0${e.key}`,lo=class{constructor(t){this.host=t}timer=null;applying=Promise.resolve();lastGroup="";get look(){return R().look.look}get active(){return!St(this.look)}patchState(t){J({look:{...R().look,...t}})}set(t,n){return this.replace(Xt(this.look,t),n)}replace(t,n){let r=R().look,o=ze(t);if(JSON.stringify(o)===JSON.stringify(r.look))return this.applying;let i=n!==void 0&&n===this.lastGroup;return this.lastGroup=n??"",this.patchState({look:o,history:i?r.history:[...r.history.slice(-Hm+1),r.look]}),this.schedule()}schedule(){return this.timer!==null&&clearTimeout(this.timer),this.applying=new Promise(t=>{this.timer=setTimeout(()=>{this.timer=null,this.push().then(t)},70)}),this.applying}async push(){let t=this.host.hook;if(!t)return;let n=this.look;try{let r=await t.request("look:apply",{look:St(n)?null:n},45e3);r?this.take(r):await this.check()}catch(r){this.patchState({notes:[r instanceof Error?r.message:String(r)]})}}take(t){this.patchState({facts:t.facts,notes:t.notes,effectsAvailable:t.facts.effectsAvailable}),this.reaudit(),this.measureSoon()}reaudit(){let{facts:t,look:n,perf:r}=R().look;t&&this.patchState({audit:Ir({...t,fps:r.fps,siteFps:r.siteFps},n)})}measureTimer=null;wait=t=>new Promise(n=>setTimeout(n,t));patchPerf(t){this.patchState({perf:{...R().look.perf,...t}})}async sampleFps(t=1){let n=this.host.hook;if(!n)return null;try{let r=R().sideTab==="performance",o=await n.request("perf:read",{since:0});await n.request("perf:sample",{on:!0}),await this.wait(t*1e3);let i=await n.request("perf:read",{since:o.seq});return r||await n.request("perf:sample",{on:!1}),eo(i.samples)?.fps??null}catch{return null}}async measure(){let t=this.look;await this.wait(350);let n=await this.sampleFps();if(JSON.stringify(t)===JSON.stringify(this.look)&&n!==null){if(this.patchPerf(St(t)?{fps:n,siteFps:n}:{fps:n}),!St(t)&&R().look.perf.siteFps===null&&!R().look.perf.busy){this.patchPerf({busy:!0});try{await this.show(Ne()),await this.wait(350);let o=await this.sampleFps(.8);o!==null&&this.patchPerf({siteFps:o})}finally{await this.show(this.look).catch(()=>{}),this.patchPerf({busy:!1})}}this.reaudit()}let{perf:r}=R().look;return{fps:r.fps,siteFps:r.siteFps}}measureSoon(){this.measureTimer!==null&&clearTimeout(this.measureTimer),this.measureTimer=null,!(R().look.perf.busy||R().look.adapt.busy)&&(this.measureTimer=setTimeout(()=>{this.measureTimer=null,R().look.perf.busy||this.measure()},700))}async show(t){await this.host.hook?.request("look:apply",{look:St(t)?null:t},45e3)}async profile(){if(R().look.perf.busy)return R().look.perf.costs??[];let t=this.look,n=Hl(t);this.patchPerf({busy:!0,costs:null});let r=[];try{await this.wait(300);let o=await this.sampleFps();if(o!==null)for(let i of n){await this.show(i.without),await this.wait(400);let s=await this.sampleFps(.8);s!==null&&r.push({id:i.id,label:i.label,ms:Math.max(0,Math.round((1e3/o-1e3/s)*10)/10)})}r.sort((i,s)=>s.ms-i.ms)}finally{await this.show(t).catch(()=>{}),this.patchPerf({busy:!1,costs:r})}return r}async lightenUntil(t,n){if(R().look.perf.busy)return{steps:[],fps:R().look.perf.fps,goal:null};await this.applying,this.patchPerf({busy:!0});let r=[],o=n??`lighten-${Date.now()}`,i=null;try{let{siteFps:s}=R().look.perf,a=R().look.perf.fps??await this.sampleFps();for(i=t??(s!==null?Math.min(s*.9,this.look.performance.targetFps):null);i!==null&&a!==null&&a<i&&r.length<12;){let l=bi(this.look);if(!l)break;r.push(l.step),await this.replace(l.look,o),await this.wait(450),a=await this.sampleFps(.8),this.patchPerf({fps:a})}this.patchPerf({fps:a,costs:null})}finally{this.patchPerf({busy:!1}),this.reaudit()}return{steps:r,fps:R().look.perf.fps,goal:i}}async check(){let t=this.host.hook;if(!t)return null;try{let n=await t.request("look:check",{look:this.look},6e3);return this.take({...n,notes:R().look.notes}),R().look.audit}catch{return null}}async fix(t){let n=R().look.audit??await this.check();if(!n)return 0;let r=n.issues.filter(o=>o.fix&&(!t||t.includes(o.id)));return r.length?(await this.replace(Ul(this.look,n,t)),r.length):0}undo(){let t=R().look,n=t.history[t.history.length-1];return n?(this.lastGroup="",this.patchState({look:n,history:t.history.slice(0,-1)}),this.schedule(),!0):!1}reset(){return this.patchState({box:null}),this.replace(Ne())}world(t){return this.patchState({box:null}),this.set({world:{preset:t}})}selectBox(t){this.patchState({box:t})}updateBox(t,n,r){let o=this.look.world.boxes.map(i=>i.id===t?{...i,...n}:i);return this.set({world:{boxes:o}},r)}addBox(){let t=this.look.world.boxes;if(t.length>=12)return this.host.toast("A world holds up to 12 light boxes."),Promise.resolve();let n=t.length+1;for(;t.some(i=>i.id===`box${n}`);)n++;let r={id:`box${n}`,name:`Light ${n}`,azimuth:30,elevation:30,width:40,height:40,intensity:4,color:"#ffffff",softness:.35};this.patchState({box:r.id});let o=this.look.world.preset==="site"?"studio":this.look.world.preset;return this.set({world:{preset:o,...this.look.world.preset==="site"?{sky:pi.studio.sky}:{},boxes:[...t,r]}})}removeBox(t){return R().look.box===t&&this.patchState({box:null}),this.set({world:{boxes:this.look.world.boxes.filter(n=>n.id!==t)}})}materialOf(t){return this.look.materials.find(n=>n.uuid===t)}material(t,n,r){let o=this.materialOf(t.uuid),{preset:i,...s}=n,a=i&&i!=="custom"?{uuid:t.uuid,name:t.name,preset:i,..._l[i].values,...o?.detail?{detail:o.detail}:{}}:{...o??{name:t.name,preset:"custom"},uuid:t.uuid,name:t.name,preset:i??(Object.keys(s).length?"custom":o?.preset??"custom")};return this.replace(gi(this.look,{...a,...s}),r)}surfaceDetail(t,n,r){let{detail:o,...i}=this.materialOf(t.uuid)??{name:t.name,preset:"custom"},s={...i,uuid:t.uuid,name:t.name};return n&&(s.detail=n),this.replace(gi(this.look,s),r)}clearMaterial(t){return this.replace({...this.look,materials:this.look.materials.filter(n=>n.uuid!==t)})}bevelObject(t,n){let r=this.look.bevel.targets.filter(o=>o.uuid!==t.uuid);return n&&r.push(t),this.set({bevel:{mode:r.length?"selected":"off",targets:r}})}patchAdapt(t){this.patchState({adapt:{...R().look.adapt,...t}})}watchTimer=null;watch(){this.watchTimer===null&&(this.watchTimer=setInterval(()=>void this.followScene(),1200))}stopWatching(){this.watchTimer!==null&&clearInterval(this.watchTimer),this.watchTimer=null}async followScene(){let t=this.host.hook,n=R().look;if(!(!t||n.perf.busy||n.adapt.busy))try{let{changed:r}=await t.request("look:follow",{},2e3);if(!r)return;await this.check();let i=(await this.models())?.models.filter(s=>s.added)??[];i.length&&this.host.toast(`${i.length===1?`New model${i[0].name?` "${i[0].name}"`:""}`:`${i.length} new models`} in the scene${this.active?": the look was fitted to it":""}. Realism \u2192 Models to adapt.`)}catch{}}async models(t=!1){let n=this.host.hook;if(!n)return null;try{let r=await n.request("look:models",{acknowledge:t},8e3);return this.patchAdapt({models:r.models}),r}catch{return null}}async adapt(t,n={}){if(R().look.adapt.busy)throw new Error("An adapt pass is already running.");await this.applying,this.patchAdapt({busy:!0}),this.measureTimer!==null&&clearTimeout(this.measureTimer),this.measureTimer=null;for(let a=0;a<80&&R().look.perf.busy;a++)await this.wait(100);let r=`adapt-${Date.now()}`,o=[],i=[],s=null;try{let a=y=>{if(t?.uuid||t?.name){let v=y.models.filter(x=>t.uuid?x.uuid===t.uuid:x.name===t.name);if(!v.length)throw new Error(`No model "${t.name||t.uuid}" at the top of the scene. Models: ${y.models.map(x=>x.name||x.uuid).join(", ")||"none"}.`);return v}return y.models.filter(v=>v.added)},l=await this.models();if(!l)throw new Error("The page is not connected.");if(!l.models.length)throw new Error("This scene has no models to adapt.");let c=a(l);if((n.ground||n.scale!==void 0)&&c.length!==1)throw new Error("Name one model to scale or set on the ground.");let u=R().look.facts??(await this.check(),R().look.facts);if(!u)throw new Error("The scene could not be read.");if(n.scale!==void 0){let y=yi(this.look,u,l,c,{scale:n.scale});o.push(...y.changes),await this.replace(y.look,r),l=await this.models()??l,c=a(l)}let f=yi(this.look,u,l,c,{ground:n.ground});o.push(...f.changes),i=f.advice,await this.replace(f.look,r);let d=c.length===1?c[0]:null;if(d?.screen&&d.pbrMaterials>0)for(let y=0;y<4;y++){await this.wait(350);let v=await this.pixels(await this.host.siteImage()),x=Iu(v.data,v.width,v.height,d.screen),M=C=>`${Math.round(C*100)}%`;if(s=`On screen the model averages ${M(x.inside.brightness)} brightness against ${M(x.outside.brightness)} around it, with ${M(x.inside.highlights)} of it clipped to white.`,!(x.inside.pixels>40&&x.inside.highlights>.04&&x.inside.highlights>x.outside.highlights*3))break;let k=this.look.models.find(C=>C.uuid===d.uuid)??{uuid:d.uuid,name:d.name},E=Math.round((k.reflection??1)*.8*1e3)/1e3;await this.replace(Or(this.look,{...k,reflection:E}),r);let L=o.find(C=>C.id==="reflection"),A=`${M(x.inside.highlights)} of the model was clipped to white while the scene around it was not, so its reflections were turned down until the highlights held detail.`;L?L.label=`Reflections on the model \xD7${E}`:o.push({id:"reflection",label:`Reflections on the model \xD7${E}`,detail:A})}await this.applying;let p=await this.measure(),m=p.fps,g=p.siteFps;if(n.lighten!==!1&&this.active&&m!==null&&g!==null&&m<Math.min(g*.9,this.look.performance.targetFps)-1){let y=await this.lightenUntil(void 0,r);y.steps.length&&o.push({id:"cost",label:`Look lightened: ${y.steps.join(", ")}`,detail:`The page ran at ${Math.round(m)} fps against ${Math.round(g)} without the look.`}),m=y.fps??m}let h=await this.models(!0),b={models:(c.length?c:(h??l).models).map(y=>y.name||y.uuid),changes:o,advice:i,picture:s,fps:m,siteFps:g};return this.patchAdapt({last:b}),b}finally{this.patchAdapt({busy:!1})}}async pixels(t){let[n,r]=t.split(",",2);if(!n?.startsWith("data:image/")||!r)throw new Error("That is not a picture.");let o=Uint8Array.from(atob(r),u=>u.charCodeAt(0)),i=await createImageBitmap(new Blob([o],{type:n.slice(5).split(";")[0]})),s=Math.min(192,i.width),a=Math.max(1,Math.round(i.height/i.width*s)),l=document.createElement("canvas");l.width=s,l.height=a;let c=l.getContext("2d",{willReadFrequently:!0});return c.drawImage(i,0,0,s,a),i.close(),{data:c.getImageData(0,0,s,a).data,width:s,height:a,thumb:l.toDataURL("image/jpeg",.7)}}async reference(t,n="Reference"){if(!t)return this.patchState({reference:null}),null;let r=await this.pixels(t);return this.referencePixels=r,this.patchState({reference:{name:n,thumb:r.thumb,comparison:null,busy:!0}}),this.compare()}referencePixels=null;async compare(){let t=R().look.reference,n=this.referencePixels;if(!t||!n)return null;this.patchState({reference:{...t,busy:!0}});try{await this.applying;let r=await this.pixels(await this.host.siteImage()),o=Fu(ts(r.data,r.width,r.height),ts(n.data,n.width,n.height),this.look);return this.patchState({reference:{...t,comparison:o,busy:!1}}),o}catch(r){return this.patchState({reference:{...t,busy:!1}}),this.host.toast(r instanceof Error?r.message:String(r)),null}}async matchStep(t){let n=R().look.reference?.comparison?.differences.find(r=>r.id===t);return n?.patch?(await this.set(n.patch),await this.wait(500),this.compare()):null}async copyJson(){await this.host.copy(ql(this.look))}async copyCode(){await this.host.copy(Fr())}async save(t){if(R().mcp.status!=="paired"){let n="Pair with the local Depthview server first (AI agent & code sync).";return this.host.toast(n),{ok:!1,error:n}}try{let n=await this.host.sendToServer({type:"look_file",file:t??R().look.savedTo??void 0,look:Nn(this.look)});if(!n||n.ok!==!0){let o=typeof n?.error=="string"?n.error:"The local server did not save it.";return this.host.toast(o),{ok:!1,error:o}}let r=String(n.file);return this.patchState({savedTo:r}),this.host.toast(`Saved ${r}`),{ok:!0,file:r}}catch(n){let r=n instanceof Error?n.message:String(n);return this.host.toast(r),{ok:!1,error:r}}}async describe(){await this.applying,await this.check(),this.measureTimer!==null&&clearTimeout(this.measureTimer),this.measureTimer=null,R().look.perf.busy||await this.measure();let t=R().look,n=t.audit;return{score:n?.score??null,issues:(n?.issues??[]).map(r=>({id:r.id,severity:r.severity,title:r.title,detail:r.detail,fixable:!!r.fix,...r.fix?{fix:r.fix}:{}})),passed:n?.passed??[],look:t.look,changes:Gl(t.look),notes:t.notes,effectsAvailable:t.effectsAvailable,performance:{fps:t.perf.fps,siteFps:t.perf.siteFps,...t.perf.costs?{costs:t.perf.costs}:{},note:t.perf.fps===null?"Not measured yet.":"Measured on this machine with the inspector open: compare fps with siteFps, not with 60."},savedTo:t.savedTo}}async loadControls(){let t=this.host.hook;if(!t)return[];try{let n=await t.request("controls:list",{},3e3),r=new Set(n.map(Tt));return J({controls:{list:n,dirty:R().controls.dirty.filter(o=>r.has(o)&&n.some(i=>Tt(i)===o&&i.value!==i.initial))}}),n}catch{return[]}}async setControl(t,n,r){let o=this.host.hook;if(!o)throw new Error("The page is not connected.");let i=Tt({group:t,key:n}),s=R().controls;J({controls:{...s,list:s.list.map(u=>Tt(u)===i?{...u,value:r}:u)}});let a;try{a=await o.request("controls:set",{group:t,key:n,value:r},3e3)}catch(u){throw await this.loadControls(),u}let l=a.find(u=>Tt(u)===i),c=R().controls.dirty.filter(u=>u!==i);return l&&l.value!==l.initial&&c.push(i),J({controls:{list:a,dirty:c}}),a}async saveControls(){let{list:t,dirty:n}=R().controls,r=t.filter(o=>n.includes(Tt(o))).map(o=>({group:o.group,key:o.key,value:o.value}));if(!r.length)return{ok:!0,saved:[],failed:[]};if(R().mcp.status!=="paired"){let o="Pair with the local Depthview server first (AI agent & code sync).";return this.host.toast(o),{ok:!1,saved:[],failed:[],error:o}}try{let o=await this.host.sendToServer({type:"controls_file",values:r}),i=Array.isArray(o?.results)?o.results:[],s=i.filter(c=>c.ok===!0),a=i.filter(c=>c.ok!==!0),l=new Set(s.map(c=>Tt({group:String(c.group),key:String(c.key)})));return J({controls:{list:t,dirty:n.filter(c=>!l.has(c))}}),this.host.toast(a.length?`${s.length} saved, ${a.length} could not be written: ${String(a[0].error??"")}`:`${s.length} control value${s.length===1?"":"s"} written to the code`),{ok:a.length===0,saved:s,failed:a}}catch(o){let i=o instanceof Error?o.message:String(o);return this.host.toast(i),{ok:!1,saved:[],failed:[],error:i}}}};var an=e=>Math.round(e*1e3)/1e3,Vu=e=>[an(e[0]),an(e[1]),an(e[2])];function Re(e){return at(e).map(t=>({percent:an(Math.min(100,Math.max(0,t.percent))),position:Vu(t.position),target:Vu(t.target),fov:an(t.fov)}))}function co(e){return{version:1,keys:Re(e)}}function Du(e){return`${JSON.stringify(co(e),null,2)}
|
|
772
|
+
`}var xe=e=>`[${e.map(t=>an(t)).join(", ")}]`;function ns(e){return`// Camera path edited in Depthview: at each scroll percent (0 = top, 100 = bottom) the
|
|
773
|
+
// camera is at \`position\` looking at \`target\`; in between it follows a smooth curve.
|
|
774
|
+
const CAMERA_PATH = [
|
|
775
|
+
${Re(e).map(n=>` { percent: ${n.percent}, position: ${xe(n.position)}, target: ${xe(n.target)}, fov: ${n.fov} },`).join(`
|
|
776
|
+
`)}
|
|
777
|
+
];
|
|
778
|
+
|
|
779
|
+
// Drive the camera with it (inside <Canvas>):
|
|
780
|
+
// import { useCameraPath } from 'depthview-r3f-bridge/camera-path';
|
|
781
|
+
// useCameraPath(CAMERA_PATH);
|
|
782
|
+
`}function Nu(e,t){let n=Re(e),r=[];for(let o of Re(t)){let i=n.find(a=>Math.abs(a.percent-o.percent)<.05);if(!i){r.push(`${o.percent}%: new key, position ${xe(o.position)}, target ${xe(o.target)}`);continue}let s=[];xe(i.position)!==xe(o.position)&&s.push(`position ${xe(i.position)} \u2192 ${xe(o.position)}`),xe(i.target)!==xe(o.target)&&s.push(`target ${xe(i.target)} \u2192 ${xe(o.target)}`),i.fov!==o.fov&&s.push(`fov ${i.fov} \u2192 ${o.fov}`),s.length&&r.push(`${o.percent}%: ${s.join(", ")}`)}for(let o of n)t.some(i=>Math.abs(i.percent-o.percent)<.05)||r.push(`${o.percent}%: key removed`);return r}var Um=60,rs=e=>Math.round(e*1e3)/1e3,uo=class{constructor(t){this.host=t}get editing(){return R().pathEdit!==null}set(t){let n=R().pathEdit;n&&J({pathEdit:{...n,...t}})}start(t){let n=R(),r=t?Re(t):[];if(!r.length){let o=n.record.samples,i=n.snapshot,s=i?Math.max(Math.hypot(i.focus.center[0]-i.siteCamera.position[0],i.focus.center[1]-i.siteCamera.position[1],i.focus.center[2]-i.siteCamera.position[2]),i.focus.radius*.5):5;if(o.length>=2)r=_c(o,s,10);else if(n.record.status==="static"&&i){let a=i.siteCamera,l=Li(a.quaternion),c={position:a.position,target:[a.position[0]+l[0]*s,a.position[1]+l[1]*s,a.position[2]+l[2]*s],fov:a.fov||50};r=Re([{percent:0,...c},{percent:100,...c}])}else return this.host.toast("Record the scroll first: the path is made from the recording."),!1}return J({pathEdit:{keys:r,original:Re(t&&n.pathEdit?n.pathEdit.original:r),selected:null,preview:!1,history:[],savedTo:n.pathEdit?.savedTo??null},lookThrough:!1,toggles:{...n.toggles,helpers:!0}}),!0}stop(){this.editing&&(this.host.hook?.request("path:override",{keys:null}).catch(()=>{}),J({pathEdit:null}))}select(t,n="position"){let r=R().pathEdit;r&&this.set({selected:t===null||!r.keys[t]?null:{index:t,handle:n}})}checkpoint(){let t=R().pathEdit;t&&this.set({history:[...t.history.slice(-Um+1),t.keys]})}commit(t,n){this.set({keys:t,...n!==void 0?{selected:n}:{}}),R().pathEdit?.preview&&this.pushOverride()}update(t,n){let r=R().pathEdit,o=r?.keys[t];if(!r||!o)return;let i=r.keys.slice();i[t]={...o,...n,...n.percent!==void 0?{percent:Math.min(100,Math.max(0,n.percent))}:{}},this.commit(i)}addAt(t){let n=R().pathEdit;if(!n)return-1;let r=Math.round(Math.min(100,Math.max(0,t))*10)/10;if(n.keys.some(a=>Math.abs(a.percent-r)<.05)){let a=n.keys.findIndex(l=>Math.abs(l.percent-r)<.05);return this.select(a),a}let o=Be(n.keys,r);if(!o)return-1;this.checkpoint();let i=Re([...n.keys,{percent:r,...o}]),s=i.findIndex(a=>Math.abs(a.percent-r)<.05);return this.commit(i,{index:s,handle:"position"}),s}remove(t){let n=R().pathEdit;if(!(!n||!n.keys[t])){if(n.keys.length<=2){this.host.toast("A path needs at least two points.");return}this.checkpoint(),this.commit(n.keys.filter((r,o)=>o!==t),null)}}shots(){let t=R();return t.pathEdit?tu(t.sections,t.pathEdit.keys,t.pathEdit.original):[]}shot(t){let n=this.shots();if(typeof t=="number")return n[t-1]??null;let r=t.trim().toLowerCase();return n.find(o=>o.id===r)??n.find(o=>o.label.toLowerCase()===r)??n.find(o=>o.label.toLowerCase().replace(/^[#.]/,"")===r.replace(/^[#.]/,""))??null}shotAt(t){let n=null;for(let r of this.shots())(!n||Math.abs(r.percent-t)<Math.abs(n.percent-t))&&(n=r);return n}setShot(t,n,r){let o=R().pathEdit,i=this.shot(t);if(!o||!i)return null;this.checkpoint();let s={position:n.position??i.pose.position,target:n.target??i.pose.target,fov:Math.min(170,Math.max(1,n.fov??i.pose.fov))};return this.set({keys:Re(nu(o.keys,i,s,r??i.hold)),selected:null}),R().pathEdit?.preview?this.pushOverride():this.setPreview(!0),this.shot(i.id)}setHold(t,n){return this.setShot(t,{},n)}resetShot(t){let n=R().pathEdit,r=this.shot(t),o=n?Be(n.original,r?.percent??0):null;return!r||!o?null:this.setShot(t,o,!1)}reset(){let t=R().pathEdit;t&&(this.checkpoint(),this.commit(t.original.map(n=>({...n})),null))}undo(){let t=R().pathEdit,n=t?.history[t.history.length-1];return!t||!n?!1:(this.set({history:t.history.slice(0,-1)}),this.commit(n,null),!0)}setPreview(t){this.editing&&(this.set({preview:t}),t?this.pushOverride():this.host.hook?.request("path:override",{keys:null}).catch(()=>{}))}scrolled(t){R().pathEdit?.preview&&this.host.hook?.send("path:progress",{percent:t})}pushOverride(){let t=R().pathEdit;!t||!this.host.hook||this.host.hook.request("path:override",{keys:t.keys,percent:R().scrub}).then(n=>{n||this.host.toast("Could not find the site camera to preview the path on.")}).catch(()=>{})}poseAt(t){let n=R().pathEdit;return n?Be(n.keys,t):null}async copyJson(){let t=R().pathEdit;t&&await this.host.copy(Du(t.keys))}async copyCode(){let t=R().pathEdit;t&&await this.host.copy(ns(t.keys))}async save(t){let n=R().pathEdit;if(!n)return{ok:!1,error:"Not editing a camera path."};if(R().mcp.status!=="paired"){let r="Pair with the local Depthview server first (AI agent & code sync).";return this.host.toast(r),{ok:!1,error:r}}try{let r=await this.host.sendToServer({type:"path_file",file:t??n.savedTo??void 0,path:co(n.keys)});if(!r||r.ok!==!0){let i=typeof r?.error=="string"?r.error:"The local server did not save it.";return this.host.toast(i),{ok:!1,error:i}}let o=String(r.file);return this.set({savedTo:o}),this.host.toast(`Saved ${o}`),{ok:!0,file:o}}catch(r){let o=r instanceof Error?r.message:String(r);return this.host.toast(o),{ok:!1,error:o}}}describe(){let t=R().pathEdit,n=R();return t?{editing:!0,preview:t.preview,keys:Re(t.keys),original:t.original,changes:Nu(t.original,t.keys),selected:t.selected,shots:this.shots().map((r,o)=>({number:o+1,id:r.id,label:r.label,...r.opening?{opening:!0}:{},percent:r.percent,position:r.pose.position.map(rs),target:r.pose.target.map(rs),fov:rs(r.pose.fov),hold:r.hold,changed:r.changed})),savedTo:t.savedTo,json:co(t.keys),code:ns(t.keys)}:{editing:!1,recorded:n.record.samples.length>1,hint:n.record.samples.length>1?'Not editing. edit_camera_path with action "start" turns the recorded path into editable keys.':"No camera path yet: get_camera_path records one first."}}};var ss=window,Kn=new Map,qm=0;function fo(e,t=15e3){let n=ss.__depthviewSend;if(typeof n!="function")return Promise.reject(new Error("Not connected to the server."));let r=`h${++qm}`;return new Promise((o,i)=>{let s=setTimeout(()=>{Kn.delete(r),i(new Error("The local server did not answer."))},t);Kn.set(r,a=>{clearTimeout(s),Kn.delete(r),o(a)}),n(JSON.stringify({id:r,payload:e}))})}ss.__depthviewResolve=(e,t)=>{try{Kn.get(e)?.(JSON.parse(t))}catch{Kn.get(e)?.(null)}};var os=class{hook=new Jr;changes=new to;propsCache=new Map;look=new lo(this);path=new uo(this);scroll=null;get driver(){return this.scroll??=new Yr(t=>this.hook.request("wheel",{deltaY:t},1e3)),this.scroll}get sceneAvailable(){let t=R().status;return!!t&&t.three&&t.hasActive}toast(){}async copy(){}async sendToServer(t){return fo(t)}async siteImage(){let t=await fo({type:"screenshot"});return`data:${String(t?.mimeType??"image/jpeg")};base64,${String(t?.data??"")}`}async agentScreenshot(){return await fo({type:"screenshot"})??{}}async agentViewport(){return await new Promise(t=>setTimeout(t,250)),{width:window.innerWidth,height:window.innerHeight}}async refresh(){let t=await this.hook.request("status").catch(()=>null);t&&J({status:t}),!R().snapshot&&this.sceneAvailable&&await this.refreshSnapshot()}async refreshSnapshot(){try{let t=await this.hook.request("scene:snapshot");return t?(J({snapshot:t}),!0):!1}catch{return!1}}async setMode(t){J({mode:t})}async selectObject(t){let n=t?await this.hook.request("obj:props",{uuid:t}).catch(()=>null):null;n&&this.propsCache.set(n.uuid,n),J({selectedUuid:n?t:null,props:n})}setScrub(t){let n=Math.min(100,Math.max(0,t));J({scrub:n}),this.path.scrolled(n),this.driver.nudgeTo(n/100*this.driver.total)}async write(t,n,r){let o=await this.hook.request("obj:set",{uuid:t,path:n,value:r});return o&&this.propsCache.set(t,o),o}async agentCheck(t,n,r){let o=await this.hook.request("obj:props",{uuid:t});if(!o)throw new Error(`No object with id ${t} in the scene.`);this.propsCache.set(t,o);let i=rn(o,n);if(i===void 0)throw new Error(`"${n}" cannot be set on ${o.name||o.type}. Call get_object to see its editable paths.`);let s=a=>Array.isArray(a)?"a vector [x, y, z]":`a ${typeof a}`;if(s(i)!==s(r))throw new Error(`"${n}" on ${o.name||o.type} is ${s(i)} (now ${JSON.stringify(i)}), not ${s(r)}.`);return i}async agentSet(t,n,r,o){let i=await this.agentCheck(t,n,r),s=await this.write(t,n,r);return this.changes.record({uuid:t,path:n,before:i,after:r,batch:o}),{before:i,value:rn(s,n)??r}}async undo(){if(this.path.undo())return;let t=this.changes.undoStep();if(!t.length){this.look.undo();return}for(let n of t)await this.write(n.uuid,n.path,n.value).catch(()=>null)}async resetChanges(){for(let t of this.changes.resetAll())await this.write(t.uuid,t.path,t.value).catch(()=>null);await this.hook.request("tools:revert",{},800).catch(()=>null),await this.refreshSnapshot()}codeTargets(){return Gc(this.changes.changed(),t=>{let n=this.propsCache.get(t);return n&&{name:n.name,type:n.type,kind:n.kind,materialType:n.mesh?.materialType}})}async applyToCode(){let{intents:t,unmapped:n}=Zr(this.changes.changed(),a=>this.propsCache.get(a));if(t.length===0)return{edits:[],unmapped:n.length,message:n.length?"Changed objects have no source info. Add depthview-r3f-bridge to the project, or write the values yourself from get_changes.":"Nothing to apply."};let r=t.map(({uuid:a,path:l,...c})=>c),o=await fo({type:"edits",edits:r}),i=Array.isArray(o?.edits)?o.edits:[];i.forEach((a,l)=>{let c=t[l];c&&a.status==="applied"&&this.changes.rebase(c.uuid,c.path)});let s=a=>i.filter(l=>l.status===a).length;return{edits:i,unmapped:n.length,message:`${s("applied")} applied, ${s("queued")} queued, ${s("failed")} failed`}}async recordScroll(){if(R().record.status!=="recording"){this.path.stop(),J({record:{status:"recording",progress:0,samples:[],exact:!1}});try{let t=await Wc(this.hook,this.driver,{setRecording:()=>{}}),n=Dc(t.samples);J({record:{status:n?"done":"static",progress:1,samples:n?t.samples:[],exact:t.exact},sections:Nc(t.samples)})}catch(t){throw J({record:{status:"idle",progress:0,samples:[],exact:!1}}),new Error(`Recording failed: ${t instanceof Error?t.message:String(t)}`)}}}},is=new os;J({mode:"scene",mcp:{...R().mcp,status:"paired"}});is.hook.request("tools:watch").catch(()=>null);ss.__depthviewAgent=async(e,t)=>{try{await is.refresh();let n=await Ou(is,e,JSON.parse(t));return JSON.stringify({ok:!0,data:n??null})}catch(n){return JSON.stringify({ok:!1,error:n instanceof Error?n.message:String(n)})}};})();
|