compass-code 0.1.0__py3-none-any.whl
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.
- compass_cli/__init__.py +0 -0
- compass_cli/commands/__init__.py +0 -0
- compass_cli/commands/ingest.py +310 -0
- compass_cli/commands/mcp.py +25 -0
- compass_cli/commands/query.py +181 -0
- compass_cli/commands/serve.py +123 -0
- compass_cli/commands/setup.py +171 -0
- compass_cli/display.py +231 -0
- compass_cli/errors.py +30 -0
- compass_cli/main.py +54 -0
- compass_cli/progress.py +191 -0
- compass_cli/result_views.py +389 -0
- compass_cli/types.py +41 -0
- compass_code-0.1.0.dist-info/METADATA +72 -0
- compass_code-0.1.0.dist-info/RECORD +137 -0
- compass_code-0.1.0.dist-info/WHEEL +4 -0
- compass_code-0.1.0.dist-info/entry_points.txt +2 -0
- compass_core/__init__.py +1 -0
- compass_core/contract/__init__.py +6 -0
- compass_core/contract/errors.py +116 -0
- compass_core/contract/models.py +204 -0
- compass_core/contract/params.py +99 -0
- compass_core/contract/results.py +370 -0
- compass_core/contract/serialize.py +59 -0
- compass_core/contract/types.py +76 -0
- compass_core/errors.py +148 -0
- compass_core/graph/__init__.py +0 -0
- compass_core/graph/db.py +205 -0
- compass_core/graph/schema.py +165 -0
- compass_core/graph/stored_ids.py +133 -0
- compass_core/graph/writer.py +482 -0
- compass_core/index/__init__.py +1 -0
- compass_core/index/freshness.py +55 -0
- compass_core/index/locate.py +155 -0
- compass_core/index/metadata.py +107 -0
- compass_core/ir/__init__.py +0 -0
- compass_core/ir/graph.py +65 -0
- compass_core/ir/models.py +75 -0
- compass_core/languages/__init__.py +1 -0
- compass_core/languages/base.py +26 -0
- compass_core/languages/python/__init__.py +6 -0
- compass_core/languages/python/extractor.py +670 -0
- compass_core/languages/python/import_resolver.py +107 -0
- compass_core/languages/registry.py +89 -0
- compass_core/logger.py +42 -0
- compass_core/phases/__init__.py +0 -0
- compass_core/phases/base.py +58 -0
- compass_core/phases/discovery.py +167 -0
- compass_core/phases/parse.py +80 -0
- compass_core/phases/persistence.py +33 -0
- compass_core/phases/pipeline.py +152 -0
- compass_core/phases/resolution.py +572 -0
- compass_core/phases/symbol_table.py +36 -0
- compass_core/phases/validation.py +76 -0
- compass_core/progress.py +45 -0
- compass_core/py.typed +0 -0
- compass_core/query/__init__.py +1 -0
- compass_core/query/cypher.py +92 -0
- compass_core/query/detail.py +241 -0
- compass_core/query/graph_map.py +127 -0
- compass_core/query/impact.py +273 -0
- compass_core/query/impact_walk.py +352 -0
- compass_core/query/overview.py +221 -0
- compass_core/query/references.py +235 -0
- compass_core/query/rows.py +378 -0
- compass_core/query/search.py +183 -0
- compass_core/query/status.py +49 -0
- compass_core/query/walk_queries.py +202 -0
- compass_core/render.py +408 -0
- compass_core/settings.py +61 -0
- compass_core/shared_types.py +78 -0
- compass_mcp/__init__.py +0 -0
- compass_mcp/guide.py +45 -0
- compass_mcp/py.typed +0 -0
- compass_mcp/server.py +261 -0
- compass_server/__init__.py +5 -0
- compass_server/errors.py +84 -0
- compass_server/main.py +42 -0
- compass_server/py.typed +0 -0
- compass_server/routers/__init__.py +0 -0
- compass_server/routers/query.py +182 -0
- compass_server/settings.py +37 -0
- compass_server/static/404.html +1 -0
- compass_server/static/_next/static/chunks/1629039a.eed2a06658ec4f9c.js +1 -0
- compass_server/static/_next/static/chunks/1ff282bf-bb7c483245264fc9.js +1 -0
- compass_server/static/_next/static/chunks/223.f881a22f446259bf.js +508 -0
- compass_server/static/_next/static/chunks/51fa5c19.6396973222c9d6fd.js +485 -0
- compass_server/static/_next/static/chunks/556.443c1682b6b20128.js +1 -0
- compass_server/static/_next/static/chunks/684-1aa0170f59baf77e.js +1 -0
- compass_server/static/_next/static/chunks/92e71660.3a42d4f70d017951.js +342 -0
- compass_server/static/_next/static/chunks/937-8692224bb6d1b605.js +1 -0
- compass_server/static/_next/static/chunks/app/_not-found/page-2c96ddf295eb6a86.js +1 -0
- compass_server/static/_next/static/chunks/app/layout-4bd0ba4a7d18aff9.js +1 -0
- compass_server/static/_next/static/chunks/app/page-5376a0a98bbd1faa.js +1 -0
- compass_server/static/_next/static/chunks/framework-96dcd958cfe08bd4.js +1 -0
- compass_server/static/_next/static/chunks/main-6dee8e626b16731a.js +1 -0
- compass_server/static/_next/static/chunks/main-app-460e8bc670818718.js +1 -0
- compass_server/static/_next/static/chunks/pages/_app-638a3e7363f92b80.js +1 -0
- compass_server/static/_next/static/chunks/pages/_error-6a72dbbb45cae743.js +1 -0
- compass_server/static/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- compass_server/static/_next/static/chunks/webpack-597057bf48ce4111.js +1 -0
- compass_server/static/_next/static/css/1b0fbfd8dd653f37.css +3 -0
- compass_server/static/_next/static/ctUZeD9K7jQUgLqmBas2L/_buildManifest.js +1 -0
- compass_server/static/_next/static/ctUZeD9K7jQUgLqmBas2L/_ssgManifest.js +1 -0
- compass_server/static/_next/static/media/0086f8992871c45b-s.woff2 +0 -0
- compass_server/static/_next/static/media/034d78ad42e9620c-s.woff2 +0 -0
- compass_server/static/_next/static/media/03b436aa846269de-s.woff2 +0 -0
- compass_server/static/_next/static/media/0484562807a97172-s.p.woff2 +0 -0
- compass_server/static/_next/static/media/08aedeceaf1dcd57-s.woff2 +0 -0
- compass_server/static/_next/static/media/0aa834ed78bf6d07-s.woff2 +0 -0
- compass_server/static/_next/static/media/29a4aea02fdee119-s.woff2 +0 -0
- compass_server/static/_next/static/media/29e7bbdce9332268-s.woff2 +0 -0
- compass_server/static/_next/static/media/36008747766f78c6-s.woff2 +0 -0
- compass_server/static/_next/static/media/39969fcf98a3026e-s.woff2 +0 -0
- compass_server/static/_next/static/media/4de1fea1a954a5b6-s.p.woff2 +0 -0
- compass_server/static/_next/static/media/5c0c2bcbaa4149ca-s.p.woff2 +0 -0
- compass_server/static/_next/static/media/67957d42bae0796d-s.woff2 +0 -0
- compass_server/static/_next/static/media/6d38f9d4e0f4772b-s.woff2 +0 -0
- compass_server/static/_next/static/media/6d664cce900333ee-s.p.woff2 +0 -0
- compass_server/static/_next/static/media/886030b0b59bc5a7-s.woff2 +0 -0
- compass_server/static/_next/static/media/8888a3826f4a3af4-s.p.woff2 +0 -0
- compass_server/static/_next/static/media/939c4f875ee75fbb-s.woff2 +0 -0
- compass_server/static/_next/static/media/a1386beebedccca4-s.woff2 +0 -0
- compass_server/static/_next/static/media/ab00a911ac2adf48-s.woff2 +0 -0
- compass_server/static/_next/static/media/b957ea75a84b6ea7-s.p.woff2 +0 -0
- compass_server/static/_next/static/media/bb3ef058b751a6ad-s.p.woff2 +0 -0
- compass_server/static/_next/static/media/c3bc380753a8436c-s.woff2 +0 -0
- compass_server/static/_next/static/media/cce080f35d014443-s.woff2 +0 -0
- compass_server/static/_next/static/media/db911767852bc875-s.woff2 +0 -0
- compass_server/static/_next/static/media/eafabf029ad39a43-s.p.woff2 +0 -0
- compass_server/static/_next/static/media/f10b8e9d91f3edcb-s.woff2 +0 -0
- compass_server/static/_next/static/media/f911b923c6adde36-s.woff2 +0 -0
- compass_server/static/_next/static/media/fe0777f1195381cb-s.woff2 +0 -0
- compass_server/static/index.html +1 -0
- compass_server/static/index.txt +25 -0
- compass_server/web_bundle.py +27 -0
- compass_server/web_limits.py +48 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[480],{3428:(e,t,r)=>{let i,s,n,a,o,l;r.d(t,{uV1:()=>f3});var u=r(84607);let d=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","aoMapIntensity","attenuationColor","attenuationDistance","bumpMap","bumpScale","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dashOffset","dashSize","dispersion","displacementBias","displacementMap","displacementScale","emissive","emissiveIntensity","emissiveMap","envMap","envMapIntensity","envMapRotation","gapSize","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThickness","iridescenceThicknessMap","lightMap","lightMapIntensity","linewidth","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","reflectivity","retroreflectivity","rotation","roughness","roughnessMap","scale","sheen","sheenColor","sheenColorMap","sheenRoughness","sheenRoughnessMap","shininess","size","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","steps","thickness","transmission","transmissionMap"],h=new WeakMap,c=new WeakMap,p=new WeakMap,m=new WeakMap;class g{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=d,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}hasDynamicInstancing(e){return!0===e.isInstancedMesh&&(e.instanceMatrix.usage===u.Vnu||null!==e.instanceColor&&e.instanceColor.usage===u.Vnu)}needsVelocity(e){let t=e.getMRT();return null!==t&&t.has("velocity")}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){let{geometry:r,object:i}=e;if(t={geometryId:r.id,geometryVersion:this.getGeometryData(r)._version,materialVersion:this.getMaterialData(e.material)._version,worldMatrix:i.matrixWorld.clone()},i.center&&(t.center=i.center.clone()),i.morphTargetInfluences&&(t.morphTargetInfluences=i.morphTargetInfluences.slice()),!0===i.isInstancedMesh&&(t.instanceMatrixVersion=i.instanceMatrix.version,t.instanceColorVersion=null!==i.instanceColor?i.instanceColor.version:null,t.morphTextureVersion=null!==i.morphTexture?i.morphTexture.version:null),!0===i.isBatchedMesh&&(t.matricesTextureVersion=i._matricesTexture.version,t.colorsTextureVersion=null!==i._colorsTexture?i._colorsTexture.version:null,t.indirectTextureVersion=i._indirectTexture.version),null!==e.bundle&&(t.version=e.bundle.version),e.material.transmission>0){let{width:r,height:i}=e.context;t.bufferWidth=r,t.bufferHeight=i}let{environmentIntensity:s,environmentRotation:n}=e.scene;t.environmentIntensity=s,t.environmentRotation=n.clone(),t.lights=this.getLightsData(e.lightsNode.getBuiltinLights(),[]),this.renderObjects.set(e,t)}return t}getAttributesData(e){let t={};for(let r in e){let i=e[r];t[r]={id:i.isInterleavedBufferAttribute?i.data.uuid:i.id,version:i.isInterleavedBufferAttribute?i.data.version:i.version}}return t}containsNode(e){let t=e.material;for(let e in t)if(t[e]&&t[e].isNode)return!0;return!!e.context.modelViewMatrix||!!e.context.modelNormalViewMatrix||!!e.context.getAO||!!e.context.getShadow}getGeometryData(e){let t=p.get(e);return void 0===t&&(t={_renderId:-1,_version:0,attributes:this.getAttributesData(e.attributes),indexId:e.index?e.index.id:null,indexVersion:e.index?e.index.version:null,drawRange:{start:e.drawRange.start,count:e.drawRange.count}},e.addEventListener("dispose",()=>{t._version++}),p.set(e,t)),t}getTextureData(e){let t=m.get(e);if(void 0===t){t={_version:0};let r=()=>{t._version++};null!==e.renderTarget?e.renderTarget.addEventListener("dispose",r):e.addEventListener("dispose",r),m.set(e,t)}return t}getMaterialData(e){let t=c.get(e);if(void 0===t){for(let r of(t={_renderId:-1,_version:0},this.refreshUniforms)){let i=e[r];void 0!==i&&(null===i?t[r]=null:"object"==typeof i&&void 0!==i.clone?!0===i.isTexture?t[r]={id:i.id,version:0,cacheVersion:this.getTextureData(i)._version}:t[r]=i.clone():t[r]=i)}c.set(e,t)}return t}equals(e,t,r){let{object:i,material:s,geometry:n}=e,a=this.getRenderObjectData(e);if(!0!==a.worldMatrix.equals(i.matrixWorld))return a.worldMatrix.copy(i.matrixWorld),!1;let o=this.getMaterialData(e.material);if(o._renderId!==r){o._renderId=r;let e=!1;for(let t in o){let r=o[t],i=s[t];if("_renderId"!==t&&"_version"!==t)if(null===r||null==i)r!==(void 0===i?null:i)&&(null==i?o[t]=null:!0===i.isTexture?o[t]={id:i.id,version:i.version,cacheVersion:this.getTextureData(i)._version}:"object"==typeof i&&void 0!==i.clone?o[t]=i.clone():o[t]=i,e=!0);else if(void 0!==r.equals)!1===r.equals(i)&&(r.copy(i),e=!0);else if(!0===i.isTexture){let t=this.getTextureData(i);(r.id!==i.id||r.version!==i.version||r.cacheVersion!==t._version)&&(r.id=i.id,r.version=i.version,r.cacheVersion=t._version,e=!0)}else r!==i&&(o[t]=i,e=!0)}!0===e&&o._version++}if(a.materialVersion!==o._version)return a.materialVersion=o._version,!1;if(o.transmission>0){let{width:t,height:r}=e.context;if(a.bufferWidth!==t||a.bufferHeight!==r)return a.bufferWidth=t,a.bufferHeight=r,!1}if(a.geometryId!==n.id)return a.geometryId=n.id,a.geometryVersion=this.getGeometryData(n)._version,!1;let l=this.getGeometryData(e.geometry);if(l._renderId!==r){l._renderId=r;let e=!1,t=n.attributes,i=l.attributes,s=0,a=0;for(let e in t)s++;for(let r in i){a++;let s=i[r],n=t[r];if(void 0===n){delete i[r],e=!0;continue}let o=n.isInterleavedBufferAttribute?n.data.uuid:n.id,l=n.isInterleavedBufferAttribute?n.data.version:n.version;(s.id!==o||s.version!==l)&&(s.id=o,s.version=l,e=!0)}a!==s&&(l.attributes=this.getAttributesData(t),e=!0);let o=n.index,u=o?o.id:null,d=o?o.version:null;(l.indexId!==u||l.indexVersion!==d)&&(l.indexId=u,l.indexVersion=d,e=!0),(l.drawRange.start!==n.drawRange.start||l.drawRange.count!==n.drawRange.count)&&(l.drawRange.start=n.drawRange.start,l.drawRange.count=n.drawRange.count,e=!0),!0===e&&l._version++}if(a.geometryVersion!==l._version)return a.geometryVersion=l._version,!1;if(a.morphTargetInfluences){let e=!1;for(let t=0;t<a.morphTargetInfluences.length;t++)a.morphTargetInfluences[t]!==i.morphTargetInfluences[t]&&(a.morphTargetInfluences[t]=i.morphTargetInfluences[t],e=!0);if(e)return!1}if(!0===i.isInstancedMesh){let e=null!==i.instanceColor?i.instanceColor.version:null,t=null!==i.morphTexture?i.morphTexture.version:null;if(a.instanceMatrixVersion!==i.instanceMatrix.version||a.instanceColorVersion!==e||a.morphTextureVersion!==t)return a.instanceMatrixVersion=i.instanceMatrix.version,a.instanceColorVersion=e,a.morphTextureVersion=t,!1}if(!0===i.isBatchedMesh){let e=null!==i._colorsTexture?i._colorsTexture.version:null;if(a.matricesTextureVersion!==i._matricesTexture.version||a.colorsTextureVersion!==e||a.indirectTextureVersion!==i._indirectTexture.version)return a.matricesTextureVersion=i._matricesTexture.version,a.colorsTextureVersion=e,a.indirectTextureVersion=i._indirectTexture.version,!1}if(a.lights)for(let e=0;e<t.length;e++){let r=a.lights[e],i=t[e];if(r.map!==i.map||r.cacheVersion!==i.cacheVersion||r.shadowMapWidth!==i.shadowMapWidth||r.shadowMapHeight!==i.shadowMapHeight)return r.map=i.map,r.cacheVersion=i.cacheVersion,r.shadowMapWidth=i.shadowMapWidth,r.shadowMapHeight=i.shadowMapHeight,!1}let u=e.scene;return null!==u.environment&&null===s.envMap&&(a.environmentIntensity!==u.environmentIntensity||!1===a.environmentRotation.equals(u.environmentRotation))?(a.environmentIntensity=u.environmentIntensity,a.environmentRotation.copy(u.environmentRotation),!1):a.center&&!1===a.center.equals(i.center)?(a.center.copy(i.center),!1):(null!==e.bundle&&(a.version=e.bundle.version),!0)}getLightsData(e,t){for(let r of(t.length=0,e)){let e=null;!0===r.isSpotLight&&null!==r.map&&(e={map:r.map.version,cacheVersion:this.getTextureData(r.map)._version}),!0===r.castShadow&&void 0!==r.shadow&&(null===e&&(e={}),e.shadowMapWidth=r.shadow.mapSize.width,e.shadowMapHeight=r.shadow.mapSize.height),null!==e&&t.push(e)}return t}getLights(e,t){let r=h.get(e);return void 0===r&&(r={renderId:-1,lightsData:[]},h.set(e,r)),r.renderId===t||(r.renderId=t,this.getLightsData(e.getBuiltinLights(),r.lightsData)),r.lightsData}needsRefresh(e,t){if(this.hasNode||this.hasAnimation||this.hasDynamicInstancing(e.object)||this.firstInitialization(e)||this.needsVelocity(t.renderer))return u.B0D.FULL;let{renderId:r}=t,i=u.B0D.NONE;this.renderId!==r&&(this.renderId=r,i=u.B0D.SHARED);let s=!0===e.object.static,n=null!==e.bundle&&!0===e.bundle.static&&this.getRenderObjectData(e).version===e.bundle.version;if(s||n)return i;let a=this.getLights(e.lightsNode,r);return!1===this.equals(e,a,r)&&(i=u.B0D.FULL),i}}let f=[/^StackTrace\.js$/,/^TSLCore\.js$/,/^.*Node\.js$/,/^three\.webgpu.*\.js$/];class b{constructor(e=null){this.isStackTrace=!0,this.stack=function(e){let t=/(?:at\s+(.+?)\s+\()?(?:(.+?)@)?([^@\s()]+):(\d+):(\d+)/;return e.split("\n").map(e=>{let r=e.match(t);if(!r)return null;let i=r[1]||r[2]||"",s=r[3].split("?")[0],n=parseInt(r[4],10),a=parseInt(r[5],10);return{fn:i,file:s.split("/").pop(),line:n,column:a}}).filter(e=>e&&!f.some(t=>t.test(e.file)))}(e||Error().stack)}getLocation(){if(0===this.stack.length)return"[Unknown location]";let e=this.stack[0],t=e.fn,r=t?`"${t}()" at `:"";return`${r}"${e.file}:${e.line}"`}getError(e){if(0===this.stack.length)return e;let t=this.stack.map(e=>{let t=`${e.file}:${e.line}:${e.column}`;return e.fn?` at ${e.fn} (${t})`:` at ${t}`}).join("\n");return`${e}
|
|
2
|
+
${t}`}}function y(e,t=0){let r=0xdeadbeef^t,i=0x41c6ce57^t;if(Array.isArray(e))for(let t=0,s;t<e.length;t++)r=Math.imul(r^(s=e[t]),0x9e3779b1),i=Math.imul(i^s,0x5f356495);else for(let t=0,s;t<e.length;t++)r=Math.imul(r^(s=e.charCodeAt(t)),0x9e3779b1),i=Math.imul(i^s,0x5f356495);return r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(i^i>>>13,0xc2b2ae35),0x100000000*(2097151&(i=Math.imul(i^i>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35)))+(r>>>0)}let x=e=>y(e),T=e=>y(e),_=(...e)=>y(e),v=new Map([[1,"float"],[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),S=new WeakMap;function R(e){if(null==e)return null;let t=typeof e;if(!0===e.isNode)return"node";if("number"===t)return"float";if("boolean"===t)return"bool";if("string"===t)return"string";if("function"===t)return"shader";else if(!0===e.isVector2)return"vec2";else if(!0===e.isVector3)return"vec3";else if(!0===e.isVector4)return"vec4";else if(!0===e.isMatrix2)return"mat2";else if(!0===e.isMatrix3)return"mat3";else if(!0===e.isMatrix4)return"mat4";else if(!0===e.isColor)return"color";else if(e instanceof ArrayBuffer)return"ArrayBuffer";return null}function N(e){let t,r;if(!0===e.isDepthTexture)return"float";let i=e.format;if(t=i===u.VT0||i===u.ZQM||i===u.zdS||i===u.dcC||i===u.wrO?1:i===u.paN||i===u.TkQ?2:i===u.HIg||i===u.VGF?3:4,r=e.type===u.bkx?"uint":e.type===u.Yuy?"int":"float",1===t)return r;let s=v.get(t);return"float"!==r&&(s=r[0]+s),s}function A(e,...t){let r=e?e.slice(-4):void 0;if(1===t.length&&("vec2"===r?t=[t[0],t[0]]:"vec3"===r?t=[t[0],t[0],t[0]]:"vec4"===r&&(t=[t[0],t[0],t[0],t[0]])),"color"===e)return new u.Q1f(...t);if("vec2"===r)return new u.I9Y(...t);if("vec3"===r)return new u.Pq0(...t);if("vec4"===r)return new u.IUQ(...t);if("mat2"===r)return new u.k_V(...t);else if("mat3"===r)return new u.dwI(...t);else if("mat4"===r)return new u.kn4(...t);else if("bool"===e)return t[0]||!1;else if("float"===e||"int"===e||"uint"===e)return t[0]||0;else if("string"===e)return t[0]||"";else if("ArrayBuffer"===e){var i;return i=t[0],Uint8Array.from(atob(i),e=>e.charCodeAt(0)).buffer}return null}function E(e){let t=S.get(e);return void 0===t&&(t={},S.set(e,t)),t}function C(e){return void 0!==e[0]&&null!==e[0]&&(e[0].isNode||Object.getPrototypeOf(e[0])!==Object.prototype)}let w={VERTEX:"vertex"},B={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},M={READ_ONLY:"readOnly",WRITE_ONLY:"writeOnly",READ_WRITE:"readWrite"},F=["setup","analyze","generate"],L=["fragment","vertex","compute"],U=["x","y","z","w"],P={analyze:"setup",generate:"analyze"},D=0;class O extends u.Qev{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=B.NONE,this.updateBeforeType=B.NONE,this.updateAfterType=B.NONE,this.version=0,this.name="",this.global=!1,this.parents=!1,this.isNode=!0,this._beforeNodes=null,this._cacheKey=null,this._uuid=null,this._cacheKeyVersion=0,this.id=D++,this.stackTrace=null,!0===O.captureStackTrace&&(this.stackTrace=new b)}set needsUpdate(e){!0===e&&this.version++}get uuid(){return null===this._uuid&&(this._uuid=u.cj9.generateUUID()),this._uuid}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this),this}onFrameUpdate(e){return this.onUpdate(e,B.FRAME)}onRenderUpdate(e){return this.onUpdate(e,B.RENDER)}onObjectUpdate(e){return this.onUpdate(e,B.OBJECT)}onReference(e){return this.updateReference=e.bind(this),this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(let{childNode:e}of this._getChildren())yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){for(let t of(e(this),this.getChildren()))t.traverse(e)}_getChildren(e=new Set){let t=[];for(let r of(e.add(this),Object.getOwnPropertyNames(this))){let i=this[r];if(!(!0===r.startsWith("_")||e.has(i))){if(!0===Array.isArray(i))for(let e=0;e<i.length;e++){let s=i[e];s&&!0===s.isNode&&t.push({property:r,index:e,childNode:s})}else if(i&&!0===i.isNode)t.push({property:r,childNode:i});else if(i&&Object.getPrototypeOf(i)===Object.prototype)for(let e in i){if(!0===e.startsWith("_"))continue;let s=i[e];s&&!0===s.isNode&&t.push({property:r,index:e,childNode:s})}}}return t}getCacheKey(e=!1,t=null){if(!0===(e=e||this.version!==this._cacheKeyVersion)||null===this._cacheKey){null===t&&(t=new Set);let r=[];for(let{property:i,childNode:s}of this._getChildren(t))r.push(x(i.slice(0,-4)),s.getCacheKey(e,t));this._cacheKey=_(T(r),this.customCacheKey()),this._cacheKeyVersion=this.version}return this._cacheKey}customCacheKey(){return this.id}getScope(){return this}getHash(){return String(this.id)}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){let t=this.getNodeType(e);return e.getElementType(t)}getMemberType(){return"void"}getNodeType(e,t=null){let r,i=e.getDataFromNode(this);return null!==t?(i.typeFromOutput=i.typeFromOutput||{},void 0===(r=i.typeFromOutput[t])&&(r=this.generateNodeType(e,t),i.typeFromOutput[t]=r)):void 0===(r=i.type)&&(i.type=r=this.generateNodeType(e)),r}generateNodeType(e,t=null){let r=e.getNodeProperties(this);return r.outputNode?r.outputNode.getNodeType(e,t):this.nodeType}getShared(e){let t=this.getHash(e),r=e.getNodeFromHash(t),i=null;if(r&&r!==this)i=r;else if(e.context.overrideNodes){let t=e.context.overrideNodes.get(this);if(t){let r=e.getDataFromNode(this);!0!==r.isOverwritten?(r.isOverwritten=!0,r.sharedNode=i=t(e).overrideNode(this,null)):i=r.sharedNode}}return i||this}getArrayCount(){return null}setup(e){let t=e.getNodeProperties(this),r=0;for(let e of this.getChildren())t["node"+r++]=e;return t.outputNode||null}analyze(e,t=null){let r=e.increaseUsage(this);if(!0===this.parents){let r=e.getDataFromNode(this,"any");r.stages=r.stages||{},r.stages[e.shaderStage]=r.stages[e.shaderStage]||[],r.stages[e.shaderStage].push(t)}if(1===r)for(let t of Object.values(e.getNodeProperties(this)))t&&!0===t.isNode&&t.build(e,this)}generate(e,t){let{outputNode:r}=e.getNodeProperties(this);if(r&&!0===r.isNode)return r.build(e,t)}updateBefore(){(0,u.R8M)("Abstract function.")}updateAfter(){(0,u.R8M)("Abstract function.")}update(){(0,u.R8M)("Abstract function.")}before(e){return null===this._beforeNodes&&(this._beforeNodes=[]),this._beforeNodes.push(e),this}build(e,t=null){let r=this.getShared(e);if(this!==r)return r.build(e,t);if(null!==this._beforeNodes){let r=this._beforeNodes;for(let i of(this._beforeNodes=null,r))i.build(e,t);this._beforeNodes=r}let i=e.getDataFromNode(this);i.buildStages=i.buildStages||{},i.buildStages[e.buildStage]=!0;let s=P[e.buildStage];if(s&&!0!==i.buildStages[s]){let t=e.getBuildStage();e.setBuildStage(s),this.build(e),e.setBuildStage(t)}e.addChain(this);let n=null,a=e.getBuildStage();if("setup"===a){e.addNode(this),this.updateReference(e);let t=e.getNodeProperties(this);if(!0!==t.initialized){for(let r of(t.initialized=!0,t.outputNode=this.setup(e)||t.outputNode||null,Object.values(t)))if(r&&!0===r.isNode){if(!0===r.parents){let t=e.getNodeProperties(r);t.parents=t.parents||[],t.parents.push(this)}r.build(e)}e.addSequentialNode(this)}n=t.outputNode}else if("analyze"===a)this.analyze(e,t);else if("generate"===a){if(this.generate.length<2){let r=this.getNodeType(e),i=e.getDataFromNode(this);void 0===(n=i.snippet)?void 0===i.generated?(i.generated=!0,i.snippet=n=this.generate(e)||""):((0,u.R8M)("Node: Recursion detected.",this),n="/* Recursion detected. */"):void 0!==i.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),n=e.format(n,r,t)}else n=this.generate(e,t)||"";""===n&&null!==t&&"void"!==t&&"OutputType"!==t&&((0,u.z3S)(`TSL: Invalid generated code, expected a "${t}".`),n=e.generateConst(t))}return e.removeChain(this),n}getSerializeChildren(){return this._getChildren()}serialize(e){let t=this.getSerializeChildren(),r={};for(let{property:i,index:s,childNode:n}of t)void 0!==s?(void 0===r[i]&&(r[i]=Number.isInteger(s)?[]:{}),r[i][s]=n.toJSON(e.meta).uuid):r[i]=n.toJSON(e.meta).uuid;Object.keys(r).length>0&&(e.inputNodes=r)}deserialize(e){if(void 0!==e.inputNodes){let t=e.meta.nodes;for(let r in e.inputNodes)if(Array.isArray(e.inputNodes[r])){let i=[];for(let s of e.inputNodes[r])i.push(t[s]);this[r]=i}else if("object"==typeof e.inputNodes[r]){let i={};for(let s in e.inputNodes[r]){let n=e.inputNodes[r][s];i[s]=t[n]}this[r]=i}else{let i=e.inputNodes[r];this[r]=t[i]}}}toJSON(e){let{uuid:t,type:r}=this,i=void 0===e||"string"==typeof e;i&&(e={textures:{},images:{},nodes:{}});let s=e.nodes[t];function n(e){let t=[];for(let r in e){let i=e[r];delete i.metadata,t.push(i)}return t}if(void 0===s&&(s={uuid:t,type:r,meta:e,metadata:{version:4.7,type:"Node",generator:"Node.toJSON"}},!0!==i&&(e.nodes[s.uuid]=s),this.serialize(s),delete s.meta),i){let t=n(e.textures),r=n(e.images),i=n(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),i.length>0&&(s.nodes=i)}return s}}O.captureStackTrace=!1;class I extends O{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}generateNodeType(e){return this.node.getElementType(e)}getMemberType(e,t){return this.node.getMemberType(e,t)}generate(e){let t=this.indexNode.getNodeType(e),r=this.node.build(e),i=this.indexNode.build(e,!e.isVector(t)&&e.isInteger(t)?t:"uint");return`${r}[ ${i} ]`}}class V extends O{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}generateNodeType(e){let t=this.node.getNodeType(e),r=null;for(let i of this.convertTo.split("|"))(null===r||e.getTypeLength(t)===e.getTypeLength(i))&&(r=i);return r}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){let r=this.node,i=this.getNodeType(e),s=r.build(e,i);return e.format(s,i,t)}}class G extends O{static get type(){return"TempNode"}constructor(e=null){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){let r=e.getVectorType(this.getNodeType(e,t)),i=e.getDataFromNode(this);if(void 0!==i.propertyName)return e.format(i.propertyName,r,t);if("void"!==r&&"void"!==t&&this.hasDependencies(e)){let s=super.build(e,r),n=e.getVarFromNode(this,null,r),a=e.getPropertyName(n);return e.addLineFlowCode(`${a} = ${s}`,this),i.snippet=s,i.propertyName=a,e.format(i.propertyName,r,t)}}return super.build(e,t)}}class k extends G{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}generateNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce((t,r)=>t+e.getTypeLength(r.getNodeType(e)),0))}generate(e,t){let r=this.getNodeType(e),i=e.getTypeLength(r),s=this.nodes,n=e.getComponentType(r),a=[],o=0;for(let t of s){let s;if(o>=i){(0,u.z3S)(`TSL: Length of parameters exceeds maximum length of function '${r}()' type.`,this.stackTrace);break}let l=t.getNodeType(e),d=e.getTypeLength(l);if(o+d>i&&((0,u.z3S)(`TSL: Length of '${r}()' data exceeds maximum length of output type.`,this.stackTrace),d=i-o,l=e.getTypeFromLength(d)),o+=d,s=t.build(e,l),e.getComponentType(l)!==n){let t=e.getTypeFromLength(d,n);s=e.format(s,l,t)}a.push(s)}let l=`${e.getType(r)}( ${a.join(", ")} )`;return e.format(l,r,t)}}let z=U.join("");class $ extends O{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(let t of this.components)e=Math.max(U.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}generateNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}getScope(){return this.node.getScope()}generate(e,t){let r=this.node,i=e.getTypeLength(r.getNodeType(e)),s=null;if(i>1){let n=null;this.getVectorLength()>=i&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));let a=r.build(e,n);s=this.components.length===i&&this.components===z.slice(0,this.components.length)?e.format(a,n,t):e.format(`${a}.${this.components}`,this.getNodeType(e),t)}else s=r.build(e,t);return s}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class W extends G{static get type(){return"SetNode"}constructor(e,t,r){super(),this.sourceNode=e,this.components=t,this.targetNode=r}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{sourceNode:t,components:r,targetNode:i}=this,s=this.getNodeType(e),n=e.getComponentType(i.getNodeType(e)),a=e.getTypeFromLength(r.length,n),o=i.build(e,a),l=t.build(e,s),u=e.getTypeLength(s),d=[];for(let e=0;e<u;e++){let t=U[e];t===r[0]?(d.push(o),e+=r.length-1):d.push(l+"."+t)}return`${e.getType(s)}( ${d.join(", ")} )`}}class H extends G{static get type(){return"FlipNode"}constructor(e,t){super(),this.sourceNode=e,this.components=t}generateNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){let{components:t,sourceNode:r}=this,i=this.getNodeType(e),s=r.build(e),n=e.getVarFromNode(this),a=e.getPropertyName(n);e.addLineFlowCode(a+" = "+s,this);let o=e.getTypeLength(i),l=[],u=0;for(let e=0;e<o;e++){let r=U[e];r===t[u]?(l.push("1.0 - "+a+"."+r),u++):l.push(a+"."+r)}return`${e.getType(i)}( ${l.join(", ")} )`}}class q extends O{static get type(){return"InputNode"}constructor(e,t=null){super(t),this.isInputNode=!0,this.value=e,this.precision=null}generateNodeType(){return null===this.nodeType?R(this.value):this.nodeType}getInputType(e){return this.getNodeType(e)}setPrecision(e){return this.precision=e,this}serialize(e){super.serialize(e),e.value=this.value,this.value&&this.value.toArray&&(e.value=this.value.toArray()),e.valueType=R(this.value),e.nodeType=this.nodeType,"ArrayBuffer"===e.valueType&&(e.value=function(e){let t="",r=new Uint8Array(e);for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return btoa(t)}(e.value)),e.precision=this.precision}deserialize(e){super.deserialize(e),this.nodeType=e.nodeType,this.value=Array.isArray(e.value)?A(e.valueType,...e.value):e.value,this.precision=e.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(e.value))}generate(){(0,u.R8M)("Abstract function.")}}let j=/float|u?int/;class X extends q{static get type(){return"ConstNode"}constructor(e,t=null){super(e,t),this.isConstNode=!0}generateConst(e){return e.generateConst(this.getNodeType(e),this.value)}generate(e,t){let r=this.getNodeType(e);return j.test(r)&&j.test(t)?e.generateConst(t,this.value):e.format(this.generateConst(e),r,t)}}class K extends O{static get type(){return"MemberNode"}constructor(e,t){super(),this.structNode=e,this.property=t,this.isMemberNode=!0}hasMember(e){return(!this.structNode.isMemberNode||!1!==this.structNode.hasMember(e))&&"void"!==this.structNode.getMemberType(e,this.property)}generateNodeType(e){return!1===this.hasMember(e)?"float":this.structNode.getMemberType(e,this.property)}getMemberType(e,t){if(!1===this.hasMember(e))return"float";let r=this.getNodeType(e);return e.getStructTypeNode(r).getMemberType(e,t)}generate(e){if(!1===this.hasMember(e)){(0,u.R8M)(`TSL: Member "${this.property}" does not exist in struct.`,this.stackTrace);let t=this.getNodeType(e);return e.generateConst(t)}return this.structNode.build(e)+"."+this.property}}let Q=null,Y=new Map;function Z(e,t){if(Y.has(e))return void(0,u.R8M)(`TSL: Redefinition of method chaining '${e}'.`);if("function"!=typeof t)throw Error(`THREE.TSL: Node element ${e} is not a function`);Y.set(e,t),"assign"!==e&&(O.prototype[e]=function(...e){return this.isStackNode?this.addToStack(t(...e)):t(this,...e)},O.prototype[e+"Assign"]=function(...e){return this.isStackNode?this.assign(e[0],t(...e)):this.assign(t(this,...e))})}let J=e=>e.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w").split("").sort().join("");O.prototype.assign=function(...e){if(!0!==this.isStackNode)return null!==Q?Q.assign(this,...e):(0,u.z3S)("TSL: No stack defined for assign operation. Make sure the assign is inside a Fn().",new b),this;{let t=Y.get("assign");return this.addToStack(t(...e))}},O.prototype.toVarIntent=function(){return this},O.prototype.get=function(e){return new K(this,e)};let ee={};function et(e,t,r){ee[e]=ee[t]=ee[r]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new $(this,e),this._cache[e]=t),t},set(t){this[e].assign(eS(t))}};let i=e.toUpperCase(),s=t.toUpperCase(),n=r.toUpperCase();O.prototype["set"+i]=O.prototype["set"+s]=O.prototype["set"+n]=function(t){return new W(this,J(e),eS(t))},O.prototype["flip"+i]=O.prototype["flip"+s]=O.prototype["flip"+n]=function(){return new H(this,J(e))}}let er=["x","y","z","w"],ei=["r","g","b","a"],es=["s","t","p","q"];for(let e=0;e<4;e++){let t=er[e],r=ei[e],i=es[e];et(t,r,i);for(let s=0;s<4;s++){t=er[e]+er[s],et(t,r=ei[e]+ei[s],i=es[e]+es[s]);for(let n=0;n<4;n++){t=er[e]+er[s]+er[n],et(t,r=ei[e]+ei[s]+ei[n],i=es[e]+es[s]+es[n]);for(let a=0;a<4;a++)t=er[e]+er[s]+er[n]+er[a],et(t,r=ei[e]+ei[s]+ei[n]+ei[a],i=es[e]+es[s]+es[n]+es[a])}}}for(let e=0;e<32;e++)ee[e]={get(){this._cache=this._cache||{};let t=this._cache[e];return void 0===t&&(t=new I(this,new X(e,"uint")),this._cache[e]=t),t},set(t){this[e].assign(eS(t))}};Object.defineProperties(O.prototype,ee);let en=function(e,t=null){let r=R(e);if("node"===r);else if(null===t&&("float"===r||"boolean"===r)||r&&"shader"!==r&&"string"!==r)return eS(ex(e,t));else if("shader"===r)return e.isFn?e:eF(e);return e},ea=function(e,t=null){for(let r in e)e[r]=eS(e[r],t);return e},eo=function(e,t=null){let r=e.length;for(let i=0;i<r;i++)e[i]=eS(e[i],t);return e},el=function(e,t=null,r=null,i=null){function s(e){return null!==i?(e=eS(Object.assign(e,i)),!0===i.intent&&(e=e.toVarIntent())):e=eS(e),e}let n,a=t,o,l;function d(t){let r;return(r=a?/[a-z]/i.test(a)?a+"()":a:e.type,void 0!==o&&t.length<o)?((0,u.z3S)(`TSL: "${r}" parameter length is less than minimum required.`,new b),t.concat(Array(o-t.length).fill(0))):void 0!==l&&t.length>l?((0,u.z3S)(`TSL: "${r}" parameter length exceeds limit.`,new b),t.slice(0,l)):t}return null===t?n=(...t)=>s(new e(...eA(d(t)))):null!==r?(r=eS(r),n=(...i)=>s(new e(t,...eA(d(i)),r))):n=(...r)=>s(new e(t,...eA(d(r)))),n.setParameterLength=(...e)=>(1===e.length?o=l=e[0]:2===e.length&&([o,l]=e),n),n.setName=e=>(a=e,n),n},eu=function(e,...t){return new e(...eA(t))};class ed extends O{constructor(e,t){super(),this.shaderNode=e,this.rawInputs=t,this.isShaderCallNodeInternal=!0}generateNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}getElementType(e){return this.getOutputNode(e).getElementType(e)}getMemberType(e,t){return this.getOutputNode(e).getMemberType(e,t)}call(e){var t,r;let{shaderNode:i,rawInputs:s}=this,n=e.getNodeProperties(i),a=e.getClosestSubBuild(i.subBuilds)||"",o=a||"default";if(n[o])return n[o];let l=e.subBuildFn,u=e.fnCall;e.subBuildFn=a,e.fnCall=this;let d=null;if(i.layout){if(s){let t=i.layout.inputs;if(C(s))for(let r=0;r<t.length;r++){let t=s[r];t&&t.isNode&&t.build(e)}else{let r=s[0];for(let i of t){let t=r[i.name];t&&t.isNode&&t.build(e)}}}let r=e.buildFunctionNode(i);e.addInclude(r);let n=s?(eN(t=s),C(t)?[...t]:t[0]):null;d=r.call(n)}else{let t,n=new Proxy(e,{get:(e,t,r)=>Symbol.iterator===t?function*(){yield}:Reflect.get(e,t,r)}),a=s?(t=0,eN(r=s),new Proxy(r,{get:(e,i,s)=>{let n;if("length"===i)return r.length;if(Symbol.iterator===i)n=function*(){for(let e of r)yield eS(e)};else{if(r.length>0)if(Object.getPrototypeOf(r[0])===Object.prototype){let e=r[0];n=void 0===e[i]?e[t++]:Reflect.get(e,i,s)}else r[0]instanceof O&&(n=void 0===r[i]?r[t++]:Reflect.get(r,i,s));else n=Reflect.get(e,i,s);n=eS(n)}return n}})):null,o=Array.isArray(s)?s.length>0:null!==s,l=i.jsFunc;d=eS(o||l.length>1?l(a,n):l(n))}return e.subBuildFn=l,e.fnCall=u,i.once&&(n[o]=d),d}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}getOutputNode(e){let t=e.getNodeProperties(this),r=e.getSubBuildOutput(this);return t[r]=t[r]||this.setupOutput(e),t[r].subBuild=e.getClosestSubBuild(this),t[r]}build(e,t=null){let r=null,i=e.getBuildStage(),s=e.getNodeProperties(this),n=e.getSubBuildOutput(this),a=this.getOutputNode(e),o=e.fnCall;if(e.fnCall=this,"setup"===i){let t=e.getSubBuildProperty("initialized",this);if(!0!==s[t]&&(s[t]=!0,s[n]=this.getOutputNode(e),s[n].build(e),this.shaderNode.subBuilds))for(let t of e.chaining){let r=e.getDataFromNode(t,"any");for(let e of(r.subBuilds=r.subBuilds||new Set,this.shaderNode.subBuilds))r.subBuilds.add(e)}r=s[n]}else"analyze"===i?a.build(e,t):"generate"===i&&(r=a.build(e,t)||"");return e.fnCall=o,r}}class eh extends O{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}getLayout(){return this.layout}call(e=null){return new ed(this,e)}setup(){return this.call()}}let ec=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],ep=new Map;for(let e of[!1,!0])ep.set(e,new X(e));let em=new Map;for(let e of[0,1,2,3])em.set(e,new X(e,"uint"));let eg=new Map([...em].map(e=>new X(e.value,"int")));for(let e of[-1,-2])eg.set(e,new X(e,"int"));let ef=new Map([...eg].map(e=>new X(e.value)));for(let e of ec)ef.set(e,new X(e));for(let e of ec)ef.set(-e,new X(-e));let eb={bool:ep,uint:em,ints:eg,float:ef},ey=new Map([...ep,...ef]),ex=(e,t)=>ey.has(e)?ey.get(e):!0===e.isNode?e:new X(e,t),eT=function(e,t=null){return(...r)=>{for(let t of r)if(void 0===t)return(0,u.z3S)(`TSL: Invalid parameter for the type "${e}".`,new b),new X(0,e);if((0===r.length||!["bool","float","int","uint"].includes(e)&&r.every(e=>{let t=typeof e;return"object"!==t&&"function"!==t}))&&(r=[A(e,...r)]),1===r.length&&null!==t&&t.has(r[0]))return eR(t.get(r[0]));if(1===r.length){let t=ex(r[0],e);return t.nodeType===e?eR(t):eR(new V(t,e))}return eR(new k(r.map(e=>ex(e)),e))}};function e_(e){return e&&e.isNode&&e.traverse(t=>{t.isConstNode&&(e=t.value)}),!!e}function ev(e,t){return new eh(e,t)}let eS=(e,t=null)=>en(e,t),eR=(e,t=null)=>eS(e,t).toVarIntent(),eN=(e,t=null)=>new ea(e,t),eA=(e,t=null)=>new eo(e,t),eE=(e,t=null,r=null,i=null)=>new el(e,t,r,i),eC=(e,...t)=>new eu(e,...t),ew=(e,t=null,r=null,i={})=>new el(e,t,r,{...i,intent:!0}),eB=0;class eM extends O{constructor(e,t=null){super();let r=null;null!==t&&("object"==typeof t?r=t.return:("string"==typeof t?r=t:(0,u.z3S)("TSL: Invalid layout type.",new b),t=null)),this.shaderNode=new ev(e,r),null!==t&&this.setLayout(t),this.isFn=!0}setLayout(e){let t=this.shaderNode.nodeType;if("object"!=typeof e.inputs){let r={name:"fn"+eB++,type:t,inputs:[]};for(let t in e)"return"!==t&&r.inputs.push({name:t,type:e[t]});e=r}return this.shaderNode.setLayout(e),this}generateNodeType(e){return this.shaderNode.getNodeType(e)||"float"}call(...e){let t=this.shaderNode.call(e);return"void"===this.shaderNode.nodeType&&t.toStack(),t.toVarIntent()}once(e=null){return this.shaderNode.once=!0,this.shaderNode.subBuilds=e,this}generate(e){let t=this.getNodeType(e);return(0,u.z3S)('TSL: "Fn()" was declared but not invoked. Try calling it like "Fn()( ...params )".',this.stackTrace),e.generateConst(t)}}function eF(e,t=null){let r=new eM(e,t);return new Proxy(()=>{},{apply:(e,t,i)=>r.call(...i),get:(e,t,i)=>Reflect.get(r,t,i),set:(e,t,i,s)=>Reflect.set(r,t,i,s)})}let eL=e=>{Q=e},eU=(...e)=>Q.If(...e);Z("toStack",function(e){return Q&&Q.addToStack(e),e});let eP=new eT("color"),eD=new eT("float",eb.float),eO=new eT("int",eb.ints),eI=new eT("uint",eb.uint),eV=new eT("bool",eb.bool),eG=new eT("vec2"),ek=new eT("ivec2"),ez=new eT("uvec2"),e$=new eT("bvec2"),eW=new eT("vec3"),eH=new eT("ivec3"),eq=new eT("uvec3"),ej=new eT("bvec3"),eX=new eT("vec4"),eK=new eT("ivec4"),eQ=new eT("uvec4"),eY=new eT("bvec4"),eZ=new eT("mat2"),eJ=new eT("mat3"),e0=new eT("mat4");Z("toColor",eP),Z("toFloat",eD),Z("toInt",eO),Z("toUint",eI),Z("toBool",eV),Z("toVec2",eG),Z("toIVec2",ek),Z("toUVec2",ez),Z("toBVec2",e$),Z("toVec3",eW),Z("toIVec3",eH),Z("toUVec3",eq),Z("toBVec3",ej),Z("toVec4",eX),Z("toIVec4",eK),Z("toUVec4",eQ),Z("toBVec4",eY),Z("toMat2",eZ),Z("toMat3",eJ),Z("toMat4",e0),Z("element",eE(I).setParameterLength(2)),Z("convert",(e,t)=>new V(eS(e),t));class e1 extends O{static get type(){return"PropertyNode"}constructor(e,t=null,r=!1,i=null){super(e),this.name=t,this.varying=r,this.placeholderNode=eS(i),this.isPropertyNode=!0,this.global=!0}getNodeType(e){let t=super.getNodeType(e);return"output"===t?e.getOutputType():t}customCacheKey(){return x(this.type+":"+(this.name||"")+":"+(this.varying?"1":"0"))}getHash(e){return this.name||super.getHash(e)}generate(e){let t;if(!0===this.varying)(t=e.getVaryingFromNode(this,this.name)).needsInterpolation=!0;else if(t=e.getVarFromNode(this,this.name),null!==this.placeholderNode&&!1===e.hasWriteUsage(this)){let r=this.placeholderNode.build(e,this.getNodeType(e));e.addLineFlowCode(`${e.getPropertyName(t)} = ${r}`,this)}return e.getPropertyName(t)}}let e2=(e,t,r=null)=>new e1(e,t,!1,r),e3=(e,t,r=null)=>new e1(e,t,!0,r),e4=eC(e1,"vec4","DiffuseColor"),e8=eC(e1,"vec3","DiffuseContribution"),e5=eC(e1,"vec3","EmissiveColor"),e6=eC(e1,"float","Roughness"),e9=eC(e1,"float","Metalness"),e7=eC(e1,"float","Clearcoat"),te=eC(e1,"float","ClearcoatRoughness"),tt=eC(e1,"vec3","Sheen"),tr=eC(e1,"float","SheenRoughness"),ti=eC(e1,"float","Iridescence"),ts=eC(e1,"float","IridescenceIOR"),tn=eC(e1,"float","IridescenceThickness"),ta=eC(e1,"float","AlphaT"),to=eC(e1,"float","Anisotropy"),tl=eC(e1,"vec3","AnisotropyT"),tu=eC(e1,"vec3","AnisotropyB"),td=eC(e1,"color","SpecularColor"),th=eC(e1,"color","SpecularColorBlended"),tc=eC(e1,"float","SpecularF90"),tp=eC(e1,"float","Shininess"),tm=eC(e1,"output","Output"),tg=eC(e1,"float","dashSize"),tf=eC(e1,"float","gapSize"),tb=eC(e1,"float","IOR"),ty=eC(e1,"float","Transmission"),tx=eC(e1,"float","Thickness"),tT=eC(e1,"float","AttenuationDistance"),t_=eC(e1,"color","AttenuationColor"),tv=eC(e1,"float","Dispersion"),tS=eC(e1,"float","Retroreflectivity"),tR=eC(e1,"float","AmbientOcclusion",!1,1);class tN extends O{static get type(){return"UniformGroupNode"}constructor(e,t=!1,r=1,i=null){super("string"),this.name=e,this.shared=t,this.order=r,this.updateType=i,this.isUniformGroup=!0}update(){this.needsUpdate=!0}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}let tA=(e,t=0,r=null)=>new tN(e,!0,t,r);B.FRAME;let tE=tA("render",0,B.RENDER),tC=((e,t=1,r=null)=>new tN(e,!1,t,r))("object",1,B.OBJECT);class tw extends q{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=tC}setName(e){return this.name=e,this}label(e){return(0,u.R8M)('TSL: "label()" has been deprecated. Use "setName()" instead.',new b),this.setName(e)}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}getSharedNode(e){let t=this.getUniformHash(e),r=e.getNodeFromHash(t);return void 0===r&&(e.setHashNode(this,t),r=this),r}onUpdate(e,t){return e=e.bind(this),super.onUpdate(t=>{let r=e(t,this);void 0!==r&&(this.value=r)},t)}getInputType(e){let t=super.getInputType(e);return"bool"===t&&(t="uint"),t}generate(e,t){let r=this.getNodeType(e),i=this.getSharedNode(e),s=i.getInputType(e),n=e.getUniformFromNode(i,s,e.shaderStage,this.name||e.context.nodeName),a=e.getPropertyName(n);void 0!==e.context.nodeName&&delete e.context.nodeName;let o=a;if("bool"===r){let t=e.getDataFromNode(this),i=t.propertyName;if(void 0===i){let n=e.getVarFromNode(this,null,"bool");t.propertyName=i=e.getPropertyName(n),o=e.format(a,s,r),e.addLineFlowCode(`${i} = ${o}`,this)}o=i}return e.format(o,r,t)}}let tB=(e,t)=>{let r=(e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null)(t||e);if(r===e&&(e=A(r)),e&&!0===e.isNode){let t=e.value;e.traverse(e=>{!0===e.isConstNode&&(t=e.value)}),e=t}return new tw(e,r)};class tM extends G{static get type(){return"ArrayNode"}constructor(e,t,r=null){super(e),this.count=t,this.values=r,this.isArrayNode=!0}getArrayCount(){return this.count}generateNodeType(e){return null===this.nodeType?this.values[0].getNodeType(e):this.nodeType}getElementType(e){return this.getNodeType(e)}getMemberType(e,t){return null===this.nodeType?this.values[0].getMemberType(e,t):super.getMemberType(e,t)}generate(e){let t=this.getNodeType(e);return e.generateArray(t,this.count,this.values)}}let tF=(...e)=>{let t;if(1===e.length){let r=e[0].map(e=>eS(e));t=new tM(null,r.length,r)}else t=new tM(e[0],e[1]);return t};Z("toArray",(e,t)=>tF(Array(t).fill(e)));class tL extends G{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t,this.isAssignNode=!0}hasDependencies(){return!1}generateNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){let{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){let r=e.getTypeLength(t.node.getNodeType(e));return U.join("").slice(0,r)!==t.components}return!1}setup(e){let{targetNode:t,sourceNode:r}=this,i=t.getScope();e.getDataFromNode(i).assign=!0;let s=e.getNodeProperties(this);s.sourceNode=r,s.targetNode=t.context({assign:!0})}generate(e,t){let r,{targetNode:i,sourceNode:s}=e.getNodeProperties(this),n=this.needsSplitAssign(e),a=i.build(e),o=i.getNodeType(e),l=s.build(e,o),u=s.getNodeType(e),d=e.getDataFromNode(this);if(!0===d.initialized)"void"!==t&&(r=a);else if(n){let s=e.getVarFromNode(this,null,o),n=e.getPropertyName(s);e.addLineFlowCode(`${n} = ${l}`,this);let u=i.node,d=u.node.context({assign:!0}).build(e);for(let t=0;t<u.components.length;t++){let r=u.components[t];e.addLineFlowCode(`${d}.${r} = ${n}[ ${t} ]`,this)}"void"!==t&&(r=a)}else r=`${a} = ${l}`,("void"===t||"void"===u)&&(e.addLineFlowCode(r,this),"void"!==t&&(r=a));return d.initialized=!0,e.format(r,o,t)}}Z("assign",eE(tL).setParameterLength(2));class tU extends G{static get type(){return"FunctionCallNode"}constructor(e=null,t={}){super(),this.functionNode=e,this.parameters=t}setParameters(e){return this.parameters=e,this}getParameters(){return this.parameters}generateNodeType(e){return this.functionNode.getNodeType(e)}getMemberType(e,t){return this.functionNode.getMemberType(e,t)}generate(e){let t=[],r=this.functionNode,i=r.getInputs(e),s=this.parameters,n=(t,r)=>{let i=r.type;return"pointer"===i?"&"+t.build(e):t.build(e,i)};if(Array.isArray(s)){if(s.length>i.length)(0,u.z3S)("TSL: The number of provided parameters exceeds the expected number of inputs in 'Fn()'."),s.length=i.length;else if(s.length<i.length)for((0,u.z3S)("TSL: The number of provided parameters is less than the expected number of inputs in 'Fn()'.");s.length<i.length;)s.push(eD(0));for(let e=0;e<s.length;e++)t.push(n(s[e],i[e]))}else for(let e of i){let r=s[e.name];void 0!==r?t.push(n(r,e)):((0,u.z3S)(`TSL: Input '${e.name}' not found in 'Fn()'.`),t.push(n(eD(0),e)))}let a=r.build(e,"property");return`${a}( ${t.join(", ")} )`}}Z("call",(e,...t)=>(t=t.length>1||t[0]&&!0===t[0].isNode?eA(t):eN(t[0]),new tU(eS(e),t)));let tP={"==":"equal","!=":"notEqual","<":"lessThan",">":"greaterThan","<=":"lessThanEqual",">=":"greaterThanEqual","%":"mod"};class tD extends G{static get type(){return"OperatorNode"}constructor(e,t,r,...i){if(super(),i.length>0){let s=new tD(e,t,r);for(let t=0;t<i.length-1;t++)s=new tD(e,s,i[t]);t=s,r=i[i.length-1]}this.op=e,this.aNode=t,this.bNode=r,this.isOperatorNode=!0}getOperatorMethod(e,t){return e.getMethod(tP[this.op],t)}generateNodeType(e,t=null){let r=this.op,i=this.aNode,s=this.bNode,n=i.getNodeType(e),a=s?s.getNodeType(e):null;if("void"===n||"void"===a)return t||"void";if("%"===r)return n;if("~"===r||"&"===r||"|"===r||"^"===r||">>"===r||"<<"===r)return e.getIntegerType(n);if("&&"===r||"||"===r||"^^"===r)return"bool";if("!"===r){let t=e.getTypeLength(n);return t>1?`bvec${t}`:"bool"}else if("=="===r||"!="===r||"<"===r||">"===r||"<="===r||">="===r){let t=Math.max(e.getTypeLength(n),e.getTypeLength(a));return t>1?`bvec${t}`:"bool"}else{if(e.isMatrix(n)){if("float"===a)return n;else if(e.isVector(a))return e.getVectorFromMatrix(n);else if(e.isMatrix(a))return n}else if(e.isMatrix(a)){if("float"===n)return a;else if(e.isVector(n))return e.getVectorFromMatrix(a)}return e.getTypeLength(a)>e.getTypeLength(n)?a:n}}generate(e,t){let r=this.op,{aNode:i,bNode:s}=this,n=this.getNodeType(e,t),a=null,o=null;"void"!==n?(a=i.getNodeType(e),o=s?s.getNodeType(e):null,"<"===r||">"===r||"<="===r||">="===r||"=="===r||"!="===r?e.isVector(a)?o=a:e.isVector(o)?a=o:a!==o&&(a=o="float"):">>"===r||"<<"===r?(a=n,o=e.changeComponentType(o,"uint")):"%"===r?(a=n,o=e.isInteger(a)&&e.isInteger(o)?o:a):e.isMatrix(a)?"float"===o?o="float":e.isVector(o)?o=e.getVectorFromMatrix(a):e.isMatrix(o)||(a=o=n):a=e.isMatrix(o)?"float"===a?"float":e.isVector(a)?e.getVectorFromMatrix(o):o=n:o=n):a=o=n;let l=i.build(e,a),d=s?s.build(e,o):null,h=e.getFunctionOperator(r);if("void"!==t){let i=e.renderer.coordinateSystem===u.TdN;if("=="===r||"!="===r||"<"===r||">"===r||"<="===r||">="===r)if(!i)return e.format(`( ${l} ${r} ${d} )`,n,t);else if(e.isVector(a))return e.format(`${this.getOperatorMethod(e,t)}( ${l}, ${d} )`,n,t);else return e.format(`( ${l} ${r} ${d} )`,n,t);if("%"===r)if(e.isInteger(o))return e.format(`( ${l} % ${d} )`,n,t);else return e.format(`${this.getOperatorMethod(e,n)}( ${l}, ${d} )`,n,t);if("!"===r)if(i&&e.isVector(a))return e.format(`not( ${l} )`,t);else return e.format(`( ${r} ${l} )`,a,t);else{if("~"===r)return e.format(`( ${r} ${l} )`,a,t);if(h)return e.format(`${h}( ${l}, ${d} )`,n,t);if(e.isMatrix(a)&&"float"===o)return e.format(`( ${d} ${r} ${l} )`,n,t);if("float"===a&&e.isMatrix(o))return e.format(`${l} ${r} ${d}`,n,t);let s=`( ${l} ${r} ${d} )`;return!i&&"bool"===n&&e.isVector(a)&&e.isVector(o)&&(s=`all${s}`),e.format(s,n,t)}}if("void"!==a)if(h)return e.format(`${h}( ${l}, ${d} )`,n,t);else if(e.isMatrix(a)&&"float"===o)return e.format(`${d} ${r} ${l}`,n,t);else return e.format(`${l} ${r} ${d}`,n,t)}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}let tO=ew(tD,"+").setParameterLength(2,1/0).setName("add"),tI=ew(tD,"-").setParameterLength(2,1/0).setName("sub"),tV=ew(tD,"*").setParameterLength(2,1/0).setName("mul"),tG=ew(tD,"/").setParameterLength(2,1/0).setName("div"),tk=ew(tD,"%").setParameterLength(2).setName("mod"),tz=ew(tD,"==").setParameterLength(2).setName("equal"),t$=ew(tD,"!=").setParameterLength(2).setName("notEqual"),tW=ew(tD,"<").setParameterLength(2).setName("lessThan"),tH=ew(tD,">").setParameterLength(2).setName("greaterThan"),tq=ew(tD,"<=").setParameterLength(2).setName("lessThanEqual"),tj=ew(tD,">=").setParameterLength(2).setName("greaterThanEqual"),tX=ew(tD,"&&").setParameterLength(2,1/0).setName("and"),tK=ew(tD,"||").setParameterLength(2,1/0).setName("or"),tQ=ew(tD,"!").setParameterLength(1).setName("not"),tY=ew(tD,"^^").setParameterLength(2).setName("xor"),tZ=ew(tD,"&").setParameterLength(2).setName("bitAnd"),tJ=ew(tD,"~").setParameterLength(1).setName("bitNot"),t0=ew(tD,"|").setParameterLength(2).setName("bitOr"),t1=ew(tD,"^").setParameterLength(2).setName("bitXor"),t2=ew(tD,"<<").setParameterLength(2).setName("shiftLeft"),t3=ew(tD,">>").setParameterLength(2).setName("shiftRight"),t4=eF(([e])=>(e.addAssign(1),e)),t8=eF(([e])=>(e.subAssign(1),e)),t5=eF(([e])=>{let t=eO(e).toConst();return e.addAssign(1),t}),t6=eF(([e])=>{let t=eO(e).toConst();return e.subAssign(1),t});Z("add",tO),Z("sub",tI),Z("mul",tV),Z("div",tG),Z("mod",tk),Z("equal",tz),Z("notEqual",t$),Z("lessThan",tW),Z("greaterThan",tH),Z("lessThanEqual",tq),Z("greaterThanEqual",tj),Z("and",tX),Z("or",tK),Z("not",tQ),Z("xor",tY),Z("bitAnd",tZ),Z("bitNot",tJ),Z("bitOr",t0),Z("bitXor",t1),Z("shiftLeft",t2),Z("shiftRight",t3),Z("incrementBefore",t4),Z("decrementBefore",t8),Z("increment",t5),Z("decrement",t6);class t9 extends G{static get type(){return"MathNode"}constructor(e,t,r=null,i=null){if(super(),(e===t9.MAX||e===t9.MIN)&&arguments.length>3){let s=new t9(e,t,r);for(let t=3;t<arguments.length-1;t++)s=new t9(e,s,arguments[t]);t=s,r=arguments[arguments.length-1],i=null}this.method=e,this.aNode=t,this.bNode=r,this.cNode=i,this.isMathNode=!0}getInputType(e){let t=this.aNode.getNodeType(e),r=this.bNode?this.bNode.getNodeType(e):null,i=this.cNode?this.cNode.getNodeType(e):null,s=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(r)?0:e.getTypeLength(r),a=e.isMatrix(i)?0:e.getTypeLength(i);if(s>n&&s>a);else if(n>a)return r;else if(a>s)return i;return t}generateNodeType(e){let t=this.method;return t===t9.LENGTH||t===t9.DISTANCE||t===t9.DOT||t===t9.DETERMINANT?"float":t===t9.CROSS?"vec3":t===t9.ALL||t===t9.ANY?"bool":t===t9.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):this.getInputType(e)}setup(e){let{aNode:t,bNode:r,method:i}=this,s=null;if(i===t9.ONE_MINUS)s=tI(1,t);else if(i===t9.RECIPROCAL)s=tG(1,t);else if(i===t9.DIFFERENCE)s=rE(tI(t,r));else if(i===t9.TRANSFORM_DIRECTION){let i,n;e.isMatrix(t.getNodeType(e))?(i=t,n=r):(i=r,n=t),s=rp(tV(i,eX(eW(n),0)).xyz)}return null!==s?s:super.setup(e)}generate(e,t){if(e.getNodeProperties(this).outputNode)return super.generate(e,t);let r=this.method,i=this.getNodeType(e),s=this.getInputType(e),n=this.aNode,a=this.bNode,o=this.cNode,l=e.renderer.coordinateSystem;if(r===t9.NEGATE)return e.format("( - "+n.build(e,s)+" )",i,t);{let d=[];return r===t9.CROSS?d.push(n.build(e,i),a.build(e,i)):l===u.TdN&&r===t9.STEP?d.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":s),a.build(e,s)):l===u.TdN&&(r===t9.MIN||r===t9.MAX)?d.push(n.build(e,s),a.build(e,1===e.getTypeLength(a.getNodeType(e))?e.getComponentType(s):s)):r===t9.REFRACT?d.push(n.build(e,s),a.build(e,s),o.build(e,"float")):r===t9.MIX?d.push(n.build(e,s),a.build(e,s),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":s)):(l===u.i7u&&r===t9.ATAN&&null!==a&&(r="atan2"),"fragment"!==e.shaderStage&&(r===t9.DFDX||r===t9.DFDY)&&((0,u.z3S)(`TSL: '${r}' is not supported in the ${e.shaderStage} stage.`,this.stackTrace),r="/*"+r+"*/"),d.push(n.build(e,s)),null!==a&&d.push(a.build(e,s)),null!==o&&d.push(o.build(e,s))),e.format(`${e.getMethod(r,i)}( ${d.join(", ")} )`,i,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}t9.ALL="all",t9.ANY="any",t9.RADIANS="radians",t9.DEGREES="degrees",t9.EXP="exp",t9.EXP2="exp2",t9.LOG="log",t9.LOG2="log2",t9.SQRT="sqrt",t9.INVERSE_SQRT="inversesqrt",t9.FLOOR="floor",t9.CEIL="ceil",t9.NORMALIZE="normalize",t9.FRACT="fract",t9.SIN="sin",t9.SINH="sinh",t9.COS="cos",t9.COSH="cosh",t9.TAN="tan",t9.TANH="tanh",t9.ASIN="asin",t9.ASINH="asinh",t9.ACOS="acos",t9.ACOSH="acosh",t9.ATAN="atan",t9.ATANH="atanh",t9.ABS="abs",t9.SIGN="sign",t9.LENGTH="length",t9.NEGATE="negate",t9.ONE_MINUS="oneMinus",t9.DFDX="dFdx",t9.DFDY="dFdy",t9.ROUND="round",t9.RECIPROCAL="reciprocal",t9.TRUNC="trunc",t9.FWIDTH="fwidth",t9.TRANSPOSE="transpose",t9.DETERMINANT="determinant",t9.INVERSE="inverse",t9.EQUALS="equals",t9.MIN="min",t9.MAX="max",t9.STEP="step",t9.REFLECT="reflect",t9.DISTANCE="distance",t9.DIFFERENCE="difference",t9.DOT="dot",t9.CROSS="cross",t9.POW="pow",t9.TRANSFORM_DIRECTION="transformDirection",t9.MIX="mix",t9.CLAMP="clamp",t9.REFRACT="refract",t9.SMOOTHSTEP="smoothstep",t9.FACEFORWARD="faceforward";let t7=eD(1e-6),re=eD(Math.PI),rt=ew(t9,t9.ALL).setParameterLength(1),rr=ew(t9,t9.ANY).setParameterLength(1),ri=ew(t9,t9.RADIANS).setParameterLength(1),rs=ew(t9,t9.DEGREES).setParameterLength(1),rn=ew(t9,t9.EXP).setParameterLength(1),ra=ew(t9,t9.EXP2).setParameterLength(1),ro=ew(t9,t9.LOG).setParameterLength(1),rl=ew(t9,t9.LOG2).setParameterLength(1),ru=ew(t9,t9.SQRT).setParameterLength(1),rd=ew(t9,t9.INVERSE_SQRT).setParameterLength(1),rh=ew(t9,t9.FLOOR).setParameterLength(1),rc=ew(t9,t9.CEIL).setParameterLength(1),rp=ew(t9,t9.NORMALIZE).setParameterLength(1),rm=ew(t9,t9.FRACT).setParameterLength(1),rg=ew(t9,t9.SIN).setParameterLength(1),rf=ew(t9,t9.SINH).setParameterLength(1),rb=ew(t9,t9.COS).setParameterLength(1),ry=ew(t9,t9.COSH).setParameterLength(1),rx=ew(t9,t9.TAN).setParameterLength(1),rT=ew(t9,t9.TANH).setParameterLength(1),r_=ew(t9,t9.ASIN).setParameterLength(1),rv=ew(t9,t9.ASINH).setParameterLength(1),rS=ew(t9,t9.ACOS).setParameterLength(1),rR=ew(t9,t9.ACOSH).setParameterLength(1),rN=ew(t9,t9.ATAN).setParameterLength(1,2),rA=ew(t9,t9.ATANH).setParameterLength(1),rE=ew(t9,t9.ABS).setParameterLength(1),rC=ew(t9,t9.SIGN).setParameterLength(1),rw=ew(t9,t9.LENGTH).setParameterLength(1),rB=ew(t9,t9.NEGATE).setParameterLength(1),rM=ew(t9,t9.ONE_MINUS).setParameterLength(1),rF=ew(t9,t9.DFDX).setParameterLength(1),rL=ew(t9,t9.DFDY).setParameterLength(1),rU=ew(t9,t9.ROUND).setParameterLength(1),rP=ew(t9,t9.RECIPROCAL).setParameterLength(1),rD=ew(t9,t9.TRUNC).setParameterLength(1),rO=ew(t9,t9.FWIDTH).setParameterLength(1),rI=ew(t9,t9.TRANSPOSE).setParameterLength(1),rV=ew(t9,t9.DETERMINANT).setParameterLength(1),rG=ew(t9,t9.INVERSE).setParameterLength(1),rk=ew(t9,t9.MIN).setParameterLength(2,1/0),rz=ew(t9,t9.MAX).setParameterLength(2,1/0),r$=ew(t9,t9.STEP).setParameterLength(2),rW=ew(t9,t9.REFLECT).setParameterLength(2),rH=ew(t9,t9.DISTANCE).setParameterLength(2),rq=ew(t9,t9.DIFFERENCE).setParameterLength(2),rj=ew(t9,t9.DOT).setParameterLength(2),rX=ew(t9,t9.CROSS).setParameterLength(2),rK=ew(t9,t9.POW).setParameterLength(2),rQ=e=>tV(e,e),rY=e=>tV(e,e,e,e),rZ=ew(t9,t9.TRANSFORM_DIRECTION).setParameterLength(2),rJ=e=>rj(e,e),r0=ew(t9,t9.MIX).setParameterLength(3),r1=(e,t=0,r=1)=>new t9(t9.CLAMP,eS(e),eS(t),eS(r)),r2=e=>r1(e),r3=ew(t9,t9.REFRACT).setParameterLength(3),r4=ew(t9,t9.SMOOTHSTEP).setParameterLength(3),r8=ew(t9,t9.FACEFORWARD).setParameterLength(3),r5=eF(([e])=>rm(rg(tk(rj(e.xy,eG(12.9898,78.233)),re)).mul(43758.5453)));Z("all",rt),Z("any",rr),Z("radians",ri),Z("degrees",rs),Z("exp",rn),Z("exp2",ra),Z("log",ro),Z("log2",rl),Z("sqrt",ru),Z("inverseSqrt",rd),Z("floor",rh),Z("ceil",rc),Z("normalize",rp),Z("fract",rm),Z("sin",rg),Z("sinh",rf),Z("cos",rb),Z("cosh",ry),Z("tan",rx),Z("tanh",rT),Z("asin",r_),Z("asinh",rv),Z("acos",rS),Z("acosh",rR),Z("atan",rN),Z("atanh",rA),Z("abs",rE),Z("sign",rC),Z("length",rw),Z("lengthSq",rJ),Z("negate",rB),Z("oneMinus",rM),Z("dFdx",rF),Z("dFdy",rL),Z("round",rU),Z("reciprocal",rP),Z("trunc",rD),Z("fwidth",rO),Z("min",rk),Z("max",rz),Z("step",(e,t)=>r$(t,e)),Z("reflect",rW),Z("distance",rH),Z("dot",rj),Z("cross",rX),Z("pow",rK),Z("pow2",rQ),Z("pow3",e=>tV(e,e,e)),Z("pow4",rY),Z("transformDirection",rZ),Z("transformNormalByViewMatrix",(e,t)=>rp(tV(t,eX(eW(e),0)).xyz)),Z("transformNormalByInverseViewMatrix",(e,t)=>rp(eX(eW(e),0).mul(t).xyz)),Z("mix",(e,t,r)=>r0(t,r,e)),Z("clamp",r1),Z("refract",r3),Z("smoothstep",(e,t,r)=>r4(t,r,e)),Z("faceForward",r8),Z("difference",rq),Z("saturate",r2),Z("cbrt",e=>tV(rC(e),rK(rE(e),1/3))),Z("transpose",rI),Z("determinant",rV),Z("inverse",rG),Z("rand",r5);class r6 extends O{static get type(){return"ConditionalNode"}constructor(e,t,r=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=r}generateNodeType(e){let{ifNode:t,elseNode:r}=e.getNodeProperties(this);if(void 0===t)return e.flowBuildStage(this,"setup"),this.getNodeType(e);let i=t.getNodeType(e);if(null!==r){let t=r.getNodeType(e);if(e.getTypeLength(t)>e.getTypeLength(i))return t}return i}setup(e){let t=this.condNode,r=this.ifNode.isolate(),i=this.elseNode?this.elseNode.isolate():null,s=e.context.nodeBlock;e.getDataFromNode(r).parentNodeBlock=s,null!==i&&(e.getDataFromNode(i).parentNodeBlock=s);let n=e.context.uniformFlow,a=e.getNodeProperties(this);a.condNode=t,a.ifNode=n?r:r.context({nodeBlock:r}),a.elseNode=i?n?i:i.context({nodeBlock:i}):null}generate(e,t){let r=this.getNodeType(e),i=e.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;let{condNode:s,ifNode:n,elseNode:a}=e.getNodeProperties(this),o=e.currentFunctionNode,l="void"!==t,d=l?e2(r).build(e):"";i.nodeProperty=d;let h=s.build(e,"bool");if(e.context.uniformFlow&&null!==a){let i=n.build(e,r),s=a.build(e,r),o=e.getTernary(h,i,s);return e.format(o,r,t)}e.addFlowCode(`
|
|
3
|
+
${e.tab}if ( ${h} ) {
|
|
4
|
+
|
|
5
|
+
`).addFlowTab();let c=n.build(e,r);if(c&&(l?c=d+" = "+c+";":(c="return "+c+";",null===o&&((0,u.R8M)("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),c="// "+c))),e.removeFlowTab().addFlowCode(e.tab+" "+c+"\n\n"+e.tab+"}"),null!==a){e.addFlowCode(" else {\n\n").addFlowTab();let t=a.build(e,r);t&&(l?t=d+" = "+t+";":(t="return "+t+";",null===o&&((0,u.R8M)("TSL: Return statement used in an inline 'Fn()'. Define a layout struct to allow return values.",this.stackTrace),t="// "+t))),e.removeFlowTab().addFlowCode(e.tab+" "+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(d,r,t)}}let r9=eE(r6).setParameterLength(2,3);Z("select",r9);class r7 extends O{static get type(){return"ContextNode"}constructor(e=null,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}generateNodeType(e){return this.node.getNodeType(e)}getFlowContextData(){let e=[];return this.traverse(t=>{!0===t.isContextNode&&e.push(t.value)}),Object.assign({},...e)}getMemberType(e,t){return this.node.getMemberType(e,t)}analyze(e){if(1===e.increaseUsage(this)){let t=e.addContext(this.value);this.node.build(e,this),e.setContext(t)}}setup(e){let t=e.addContext(this.value),r=this.node.build(e);return e.setContext(t),r}generate(e,t){let r=e.addContext(this.value),i=this.node.build(e,t);return e.setContext(r),i}}let ie=(e=null,t={})=>{let r=e;return(null===r||!0!==r.isNode)&&(t=r||t,r=null),new r7(r,t)},it=(e,t)=>ie(e,{nodeName:t});Z("context",ie),Z("label",function(e,t){return(0,u.R8M)('TSL: "label()" has been deprecated. Use "setName()" instead.'),it(e,t)}),Z("uniformFlow",e=>ie(e,{uniformFlow:!0})),Z("setName",it),Z("builtinShadowContext",(e,t,r)=>(function(e,t,r=null){return ie(r,{getShadow:({light:r,shadowColorNode:i})=>t===r?i.mul(e):i})})(t,r,e)),Z("builtinAOContext",(e,t)=>(function(e,t=null){return ie(t,{getAO:(t,{material:r})=>!0===r.transparent?t:null!==t?t.mul(e):e})})(t,e)),Z("builtinGIContext",(e,t,r)=>(function(e,t,r=null){let i=e.max(.001);return ie(r,{getAO:(e,{material:t})=>!0===t.transparent?e:null!==e?e.mul(i):i,getGI:(e,{material:r})=>{if(!0===r.transparent)return e;let s=t.div(i);return null!==e?e.add(s):s}})})(t,r,e));class ir extends O{static get type(){return"VarNode"}constructor(e,t=null,r=!1){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0,this.readOnly=r,this.parents=!0,this.intent=!1}setIntent(e){return this.intent=e,this}isIntent(e){return!0!==e.getDataFromNode(this).forceDeclaration&&this.intent}getIntent(){return this.intent}getMemberType(e,t){return this.node.getMemberType(e,t)}getElementType(e){return this.node.getElementType(e)}generateNodeType(e){return this.node.getNodeType(e)}getArrayCount(e){return this.node.getArrayCount(e)}isAssign(e){return e.getDataFromNode(this).assign}build(...e){let t=e[0],r=this.getShared(t);if(this!==r)return r.build(...e);if(!1===this._hasStack(t)&&"setup"===t.buildStage&&(t.context.nodeLoop||t.context.nodeBlock)){let e=!1;this.node.isShaderCallNodeInternal&&null===this.node.shaderNode.getLayout()&&t.fnCall&&t.fnCall.shaderNode&&t.getDataFromNode(this.node.shaderNode).hasLoop&&(t.getDataFromNode(this).forceDeclaration=!0,e=!0);let r=t.getBaseStack();e?r.addToStackBefore(this):r.addToStack(this)}return this.isIntent(t)&&!0!==this.isAssign(t)?this.node.build(...e):super.build(...e)}generate(e){let{node:t,name:r,readOnly:i}=this,{renderer:s}=e,n=!0===s.backend.isWebGPUBackend,a=!1,o=!1;i&&(a=e.isDeterministic(t),o=n?i:a);let l=this.getNodeType(e);if("void"==l)return!0!==this.isIntent(e)&&(0,u.z3S)('TSL: ".toVar()" can not be used with void type.',this.stackTrace),t.build(e);let d=e.getVectorType(l),h=t.build(e,d),c=e.getVarFromNode(this,r,d,void 0,o),p=e.getPropertyName(c),m=p;if(o)if(n)m=a?`const ${p}`:`let ${p}`;else{let r=t.getArrayCount(e);m=`const ${e.getVar(c.type,p,r)}`}return e.addLineFlowCode(`${m} = ${h}`,this),p}_hasStack(e){return void 0!==e.getDataFromNode(this).stack}}let ii=eE(ir);Z("toVar",(e,t=null)=>ii(e,t).toStack()),Z("toConst",(e,t=null)=>ii(e,t,!0).toStack()),Z("toVarIntent",e=>ii(e).setIntent(!0).toStack());class is extends O{static get type(){return"SubBuild"}constructor(e,t,r=null){super(r),this.node=e,this.name=t,this.isSubBuildNode=!0}generateNodeType(e){if(null!==this.nodeType)return this.nodeType;e.addSubBuild(this.name);let t=this.node.getNodeType(e);return e.removeSubBuild(),t}build(e,...t){e.addSubBuild(this.name);let r=this.node.build(e,...t);return e.removeSubBuild(),r}}let ia=(e,t,r=null)=>new is(eS(e),t,r);class io extends O{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=ia(e,"VERTEX"),this.name=t,this.isVaryingNode=!0,this.interpolationType=null,this.interpolationSampling=null,this.global=!0}setInterpolation(e,t=null){return this.interpolationType=e,this.interpolationSampling=t,this}getHash(e){return this.name||super.getHash(e)}generateNodeType(e){return this.node.getNodeType(e)}setupVarying(e){let t=e.getNodeProperties(this),r=t.varying;if(void 0===r){let i=this.name,s=this.getNodeType(e),n=this.interpolationType,a=this.interpolationSampling;t.varying=r=e.getVaryingFromNode(this,i,s,n,a),t.node=ia(this.node,"VERTEX")}return r.needsInterpolation||(r.needsInterpolation="fragment"===e.shaderStage),r}setup(e){this.setupVarying(e),e.flowNodeFromShaderStage(w.VERTEX,this.node)}analyze(e){this.setupVarying(e),e.flowNodeFromShaderStage(w.VERTEX,this.node)}generate(e){let t=e.getSubBuildProperty("property",e.currentStack),r=e.getNodeProperties(this),i=this.setupVarying(e);if(void 0===r[t]){let s=this.getNodeType(e),n=e.getPropertyName(i,w.VERTEX);if(e.shaderStage===w.VERTEX){let t=r.node.build(e,s);e.addLineFlowCode(`${n} = ${t}`,this)}else e.flowNodeFromShaderStage(w.VERTEX,r.node,s,n);r[t]=n}return e.getPropertyName(i)}}let il=eE(io).setParameterLength(1,2);Z("toVarying",il),Z("toVertexStage",e=>il(e));let iu=eF(([e])=>{let t=e.mul(.9478672986).add(.0521327014).pow(2.4);return r0(t,e.mul(.0773993808),e.lessThanEqual(.04045))}).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),id=eF(([e])=>{let t=e.pow(.41666).mul(1.055).sub(.055);return r0(t,e.mul(12.92),e.lessThanEqual(.0031308))}).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),ih="WorkingColorSpace";class ic extends G{static get type(){return"ColorSpaceNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this.source=t,this.target=r}resolveColorSpace(e,t){return t===ih?u.ppV.workingColorSpace:"OutputColorSpace"===t?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){let{colorNode:t}=this,r=this.resolveColorSpace(e,this.source),i=this.resolveColorSpace(e,this.target),s=t;return!1!==u.ppV.enabled&&r!==i&&r&&i&&(u.ppV.getTransfer(r)===u.KLL&&(s=eX(iu(s.rgb),s.a)),u.ppV.getPrimaries(r)!==u.ppV.getPrimaries(i)&&(s=eX(eJ(u.ppV._getMatrix(new u.dwI,r,i)).mul(s.rgb),s.a)),u.ppV.getTransfer(i)===u.KLL&&(s=eX(id(s.rgb),s.a))),s}}let ip=(e,t)=>new ic(eS(e),t,ih);Z("workingToColorSpace",(e,t)=>new ic(eS(e),ih,t)),Z("colorSpaceToWorking",ip);class im extends I{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}generateNodeType(){return this.referenceNode.uniformType}generate(e){let t=super.generate(e),r=this.referenceNode.getNodeType(e),i=this.getNodeType(e);return e.format(t,r,i)}}class ig extends O{static get type(){return"ReferenceBaseNode"}constructor(e,t,r=null,i=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=i,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.updateType=B.OBJECT}setGroup(e){return this.group=e,this}element(e){return new im(this,eS(e))}setNodeType(e){let t=tB(null,e);null!==this.group&&t.setGroup(this.group),this.node=t}generateNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,r=e[t[0]];for(let e=1;e<t.length;e++)r=r[t[e]];return r}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);let e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}class ib extends ig{static get type(){return"RendererReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.renderer=r,this.setGroup(tE)}updateReference(e){return this.reference=null!==this.renderer?this.renderer:e.renderer,this.reference}}class iy extends G{static get type(){return"ToneMappingNode"}constructor(e,t=ix,r=null){super("vec3"),this._toneMapping=e,this.exposureNode=t,this.colorNode=r}customCacheKey(){return _(this._toneMapping)}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup(e){let t=this.colorNode||e.context.color,r=this._toneMapping;if(r===u.y_p)return t;let i=null,s=e.renderer.library.getToneMappingFunction(r);return null!==s?i=eX(s(t.rgb,this.exposureNode),t.a):((0,u.z3S)("ToneMappingNode: Unsupported Tone Mapping configuration.",r),i=t),i}}let ix=((e,t,r=null)=>new ib(e,t,r))("toneMappingExposure","float");Z("toneMapping",(e,t,r)=>new iy(t,eS(r),eS(e)));let iT=new WeakMap;function i_(e,t){let r=iT.get(e);return void 0===r&&(r=new u.eB$(e,t),iT.set(e,r)),r}class iv extends q{static get type(){return"BufferAttributeNode"}constructor(e,t=null,r=0,i=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=r,this.bufferOffset=i,this.usage=u.agE,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&e.itemSize<=4&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){let t;if(0===this.bufferStride&&0===this.bufferOffset){let r=e.globalCache.getData(this.value);void 0===r&&(r={node:this},e.globalCache.setData(this.value,r)),t=r.node.id}else t=this.id;return String(t)}generateNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){let t;if(null!==this.attribute)return;let r=this.getNodeType(e),i=e.getTypeLength(r),s=this.value,n=this.bufferStride||i,a=this.bufferOffset;t=!0===s.isInterleavedBuffer?s:!0===s.isBufferAttribute?i_(s.array,n):i_(s,n);let o=new u.eHs(t,i,a);t.setUsage(this.usage),this.attribute=o,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){let t=this.getNodeType(e),r=e.context.nodeName;void 0!==r&&delete e.context.nodeName;let i=e.getBufferAttributeFromNode(this,t,r),s=e.getPropertyName(i),n=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=s,n=s;else{let i;r&&(i=r+"Varying"),n=il(this,i).build(e,t)}return n}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}function iS(e,t=null,r=0,i=0,s=u.agE,n=!1){return"mat3"===t||null===t&&9===e.itemSize?eJ(new iv(e,"vec3",9,0).setUsage(s).setInstanced(n),new iv(e,"vec3",9,3).setUsage(s).setInstanced(n),new iv(e,"vec3",9,6).setUsage(s).setInstanced(n)):"mat4"===t||null===t&&16===e.itemSize?e0(new iv(e,"vec4",16,0).setUsage(s).setInstanced(n),new iv(e,"vec4",16,4).setUsage(s).setInstanced(n),new iv(e,"vec4",16,8).setUsage(s).setInstanced(n),new iv(e,"vec4",16,12).setUsage(s).setInstanced(n)):new iv(e,t,r,i).setUsage(s)}let iR=(e,t=null,r=0,i=0)=>iS(e,t,r,i),iN=(e,t=null,r=0,i=0)=>iS(e,t,r,i,u.agE,!0),iA=(e,t=null,r=0,i=0)=>iS(e,t,r,i,u.Vnu,!0);Z("toAttribute",e=>iR(e.value,e.bufferType));class iE extends O{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isIndexNode=!0}generate(e){let t,r=this.getNodeType(e),i=this.scope;if(i===iE.VERTEX)t=e.getVertexIndex();else if(i===iE.INSTANCE)t=e.getInstanceIndex();else if(i===iE.DRAW)t=e.getDrawIndex();else if(i===iE.INVOCATION_LOCAL)t=e.getInvocationLocalIndex();else if(i===iE.INVOCATION_SUBGROUP)t=e.getInvocationSubgroupIndex();else if(i===iE.SUBGROUP)t=e.getSubgroupIndex();else throw Error("THREE.IndexNode: Unknown scope: "+i);return"vertex"===e.shaderStage||"compute"===e.shaderStage?t:il(this).build(e,r)}}iE.VERTEX="vertex",iE.INSTANCE="instance",iE.SUBGROUP="subgroup",iE.INVOCATION_LOCAL="invocationLocal",iE.INVOCATION_SUBGROUP="invocationSubgroup",iE.DRAW="draw";let iC=eC(iE,iE.VERTEX),iw=eC(iE,iE.INSTANCE);iE.SUBGROUP,iE.INVOCATION_SUBGROUP,iE.INVOCATION_LOCAL;let iB=eC(iE,iE.DRAW);class iM extends O{static get type(){return"ComputeNode"}constructor(e,t){super("void"),this.isComputeNode=!0,this.computeNode=e,this.workgroupSize=t,this.count=null,this.dispatchSize=null,this.version=1,this.name="",this.onInitFunction=null,this.countNode=null,this.updateBeforeType=B.FRAME}setName(e){return this.name=e,this}label(e){return(0,u.R8M)('TSL: "label()" has been deprecated. Use "setName()" instead.',new b),this.setName(e)}onInit(e){return this.onInitFunction=e,this}getUpdateBeforeType(e){return e.compute!==this?this.updateBeforeType:B.NONE}updateBefore({renderer:e}){e.compute(this)}setup(e){null!==this.count&&null===this.countNode&&(this.countNode=tB(this.count,"uint").onObjectUpdate(()=>this.count));let t=this.computeNode.build(e);return t&&(e.getNodeProperties(this).outputComputeNode=t.outputNode,t.outputNode=null),t}generate(e,t){let{shaderStage:r}=e;if("compute"===r){let t=this.computeNode.build(e,"void");if(""!==t&&e.addLineFlowCode(t,this),null!==this.count&&!0===e.allowEarlyReturns){let t=this.countNode.build(e,"uint"),r=iw.build(e,"uint");e.flow.code=`${e.tab}if ( ${r} >= ${t} ) { return; }
|
|
6
|
+
|
|
7
|
+
${e.flow.code}`}}else{let r=e.getNodeProperties(this).outputComputeNode;if(r)return r.build(e,t)}}}let iF=(e,t=[64])=>{(0===t.length||t.length>3)&&(0,u.z3S)("TSL: compute() workgroupSize must have 1, 2, or 3 elements",new b);for(let e=0;e<t.length;e++){let r=t[e];("number"!=typeof r||r<=0||!Number.isInteger(r))&&(0,u.z3S)(`TSL: compute() workgroupSize element at index [ ${e} ] must be a positive integer`,new b)}for(;t.length<3;)t.push(1);return new iM(eS(e),t)};Z("compute",(e,t,r)=>{let i=iF(e,r);return"number"==typeof t?i.count=t:i.dispatchSize=t,i}),Z("computeKernel",iF);class iL extends O{static get type(){return"IsolateNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isIsolateNode=!0}generateNodeType(e){let t=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);let i=this.node.getNodeType(e);return e.setCache(t),i}build(e,...t){let r=e.getCache(),i=e.getCacheFromNode(this,this.parent);e.setCache(i);let s=this.node.build(e,...t);return e.setCache(r),s}setParent(e){return this.parent=e,this}getParent(){return this.parent}}let iU=e=>new iL(eS(e));Z("cache",function(e,t=!0){return(0,u.R8M)('TSL: "cache()" has been deprecated. Use "isolate()" instead.'),iU(e).setParent(t)}),Z("isolate",iU);class iP extends O{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}generateNodeType(e){return this.outputNode.getNodeType(e)}generate(e){let t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}Z("bypass",eE(iP).setParameterLength(2));let iD=eF(([e,t,r,i=eD(0),s=eD(1),n=eV(!1)])=>{let a=e.sub(t).div(r.sub(t));return e_(n)&&(a=a.clamp()),a.mul(s.sub(i)).add(i)});Z("remap",iD),Z("remapClamp",function(e,t,r,i=eD(0),s=eD(1)){return iD(e,t,r,i,s,!0)});class iO extends O{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){let r=this.getNodeType(e),i=this.snippet;if("void"!==r)return e.format(i,r,t);e.addLineFlowCode(i,this)}}let iI=eE(iO).setParameterLength(1,2);Z("discard",e=>(e?r9(e,iI("discard")):iI("discard")).toStack());let iV=eF(([e])=>eX(e.rgb.mul(e.a),e.a),{color:"vec4",return:"vec4"}),iG=eF(([e])=>e.a.equal(0).select(eX(0),eX(e.rgb.div(e.a),e.a)),{color:"vec4",return:"vec4"});class ik extends G{static get type(){return"RenderOutputNode"}constructor(e,t,r){super("vec4"),this.colorNode=e,this._toneMapping=t,this.outputColorSpace=r,this.isRenderOutputNode=!0}setToneMapping(e){return this._toneMapping=e,this}getToneMapping(){return this._toneMapping}setup({context:e}){let t=this.colorNode||e.color;t=iG(t=eX(t.rgb,t.a.clamp(0,1)));let r=(null!==this._toneMapping?this._toneMapping:e.toneMapping)||u.y_p,i=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||u.jf0;return r!==u.y_p&&(t=t.toneMapping(r)),i!==u.jf0&&i!==u.ppV.workingColorSpace&&(t=t.workingToColorSpace(i)),t=iV(t)}}let iz=(e,t=null,r=null)=>new ik(eS(e),t,r);Z("renderOutput",iz);class i$ extends G{static get type(){return"DebugNode"}constructor(e,t=null){super(),this.node=e,this.callback=t}generateNodeType(e){return this.node.getNodeType(e)}setup(e){return this.node.build(e)}analyze(e){return this.node.build(e)}generate(e){let t=this.callback,r=this.node.build(e);if(null!==t)t(e,r);else{let t="--- TSL debug - "+e.shaderStage+" shader ---",i="-".repeat(t.length),s="";s+="// #"+t+"#\n"+e.flow.code.replace(/^\t/mg,"")+"\n"+("/* ... */ "+r)+" /* ... */\n"+("// #"+i)+"#\n",(0,u.Rm2)(s)}return r}}Z("debug",(e,t=null)=>new i$(eS(e),t).toStack());class iW extends u.Qev{constructor(){super(),this._renderer=null,this.currentFrame=null,this.isRunning=!1,this.enabled=!0}get nodeFrame(){return this._renderer._nodes.nodeFrame}setRenderer(e){return this._renderer=e,this}getRenderer(){return this._renderer}begin(){this.isRunning=!0}finish(){this.isRunning=!1}inspect(){}computeAsync(){}beginCompute(){}finishCompute(){}beginRender(){}finishRender(){}copyTextureToTexture(){}copyFramebufferToTexture(){}dispose(){!0===this.isRunning&&this.finish(),this.dispatchEvent({type:"dispose"})}}class iH extends O{static get type(){return"InspectorNode"}constructor(e,t="",r=null){super(),this.node=e,this.name=t,this.callback=r,this.updateType=B.FRAME,this.isInspectorNode=!0}getName(){return this.name||this.node.name}update(e){e.renderer.inspector.inspect(this)}generateNodeType(e){return this.node.getNodeType(e)}setup(e){let t=this.node;return!0===e.context.inspector&&null!==this.callback&&(t=this.callback(t)),!0!==e.renderer.backend.isWebGPUBackend&&e.renderer.inspector.constructor!==iW&&(0,u.mcG)('TSL: ".toInspector()" is only available with WebGPU.'),t}}Z("toInspector",function(e,t="",r=null){return(e=eS(e)).before(new iH(e,t,r))});class iq extends O{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}generateNodeType(e){let t=this.nodeType;if(null===t){let r=this.getAttributeName(e);if(e.hasGeometryAttribute(r)){let i=e.geometry.getAttribute(r);t=e.getTypeFromAttribute(i)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){let t=this.getAttributeName(e),r=this.getNodeType(e);if(!0!==e.hasGeometryAttribute(t))return(0,u.R8M)(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(r);{let i=e.geometry.getAttribute(t),s=e.getTypeFromAttribute(i),n=e.getAttribute(t,s);return"vertex"===e.shaderStage?e.format(n.name,s,r):il(this).build(e,r)}}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}let ij=(e,t=null)=>new iq(e,t),iX=(e=0)=>ij("uv"+(e>0?e:""),"vec2");class iK extends O{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e){let t=this.textureNode.build(e,"property"),r=null===this.levelNode?"0":this.levelNode.build(e,"int"),i=e.generateTextureSize(this.textureNode.value,t,r);return e.format(i,this.getNodeType(e))}}let iQ=eE(iK).setParameterLength(1,2);class iY extends tw{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=B.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){let e=this.texture,t=e.images,r=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(r&&void 0!==r.width){let{width:e,height:t}=r;this.value=Math.log2(Math.max(e,t))}}}let iZ=eE(iY).setParameterLength(1);class iJ extends Error{constructor(e,t=null){super(e),this.name="NodeError",this.stackTrace=t}}let i0=new u.gPd;class i1 extends tw{static get type(){return"TextureNode"}constructor(e=i0,t=null,r=null,i=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=r,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.gatherNode=null,this.offsetNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=B.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this._flipYUniform=null,this._samplerComparison=!1,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}generateNodeType(){return null!==this.gatherNode?"vec4":N(this.value)}getInputType(){return"texture"}getDefaultUV(){return iX(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=tB(this.value.matrix)),this._matrixUniform.mul(eW(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this}setupUV(e,t){return e.isFlipY()&&(null===this._flipYUniform&&(this._flipYUniform=tB(!1)),t=t.toVar(),t=this.sampler?this._flipYUniform.select(t.flipY(),t):this._flipYUniform.select(t.setY(eO(iQ(this,this.levelNode).y).sub(t.y).sub(1)),t)),t}setup(e){let t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let r=this.value;if(!r||!0!==r.isTexture)throw new iJ("THREE.TSL: `texture( value )` function expects a valid instance of THREE.Texture().",this.stackTrace);let i=eF(()=>{let t=this.uvNode;return(null===t||!0===e.context.forceUVContext)&&e.context.getUV&&(t=e.context.getUV(this,e)),t||(t=this.getDefaultUV()),!0===this.updateMatrix&&(t=this.getTransformedUV(t)),t=this.setupUV(e,t),this.updateType=null!==this._matrixUniform||null!==this._flipYUniform?B.OBJECT:B.NONE,t})(),s=this.levelNode;null===s&&e.context.getTextureLevel&&(s=e.context.getTextureLevel(this));let n=null,a=null;if(null!==this.compareNode)if(e.renderer.hasCompatibility(u.x$Y.TEXTURE_COMPARE))n=this.compareNode;else{let e=r.compareFunction;null===e||e===u.vim||e===u.TiK||e===u.eoi||e===u.gWB?a=this.compareNode:(n=this.compareNode,(0,u.mcG)('TSL: Only "LessCompare", "LessEqualCompare", "GreaterCompare" and "GreaterEqualCompare" are supported for depth texture comparison fallback.'))}t.uvNode=i,t.levelNode=s,t.biasNode=this.biasNode,t.compareNode=n,t.compareStepNode=a,t.gradNode=this.gradNode,t.gatherNode=this.gatherNode,t.depthNode=this.depthNode,t.offsetNode=this.offsetNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateOffset(e,t){return t.build(e,"ivec2")}generateSnippet(e,t,r,i,s,n,a,o,l,u,d){let h=this.value;return s?e.generateTextureBias(h,t,r,s,n,u):o?e.generateTextureGrad(h,t,r,o,n,u):l?a?e.generateTextureGatherCompare(h,t,r,a,n,u,d):e.generateTextureGather(h,t,r,l,n,u,d):a?e.generateTextureCompare(h,t,r,a,n,u):!1===this.sampler?e.generateTextureLoad(h,t,r,i,n,u):i?e.generateTextureLevel(h,t,r,i,n,u):e.generateTexture(h,t,r,n,u)}generate(e,t){let r=this.value,i=e.getNodeProperties(this),s=super.generate(e,"property");if(/^sampler/.test(t))return"samplerComparison"===t&&(this._samplerComparison=!0,this.getSharedNode(e)._samplerComparison=!0),s+"_sampler";{if(e.isReference(t))return s;let n=e.getDataFromNode(this),a=this.getNodeType(e),o=n.propertyName;if(void 0===o){let t,{uvNode:l,levelNode:d,biasNode:h,compareNode:c,compareStepNode:p,depthNode:m,gradNode:g,gatherNode:f,offsetNode:b}=i,y=this.generateUV(e,l),x=d?d.build(e,"float"):null,T=h?h.build(e,"float"):null,_=m?m.build(e,"int"):null,v=c?c.build(e,"float"):null,S=p?p.build(e,"float"):null,R=g?[g[0].build(e,"vec2"),g[1].build(e,"vec2")]:null,N=f?f.build(e,"int"):null,A=b?this.generateOffset(e,b):null,E=this._flipYUniform?this._flipYUniform.build(e,"bool"):null,C=_;null===C&&r.isArrayTexture&&!0!==this.isTexture3DNode&&(C="0");let w=e.getVarFromNode(this);o=e.getPropertyName(w);let B=this.generateSnippet(e,s,y,x,T,C,v,R,N,A,E);if(t=!0===r.isDepthTexture&&null===N?"float":r.type===u.bkx?"uvec4":r.type===u.Yuy?"ivec4":"vec4",B=e.format(B,t,a),null!==S){let t=r.compareFunction;B=t===u.eoi||t===u.gWB?r$(iI(B,a),iI(S,"float")).build(e,a):r$(iI(S,"float"),iI(B,a)).build(e,a)}e.addLineFlowCode(`${o} = ${B}`,this),n.snippet=B,n.propertyName=o}let l=o;return e.needsToWorkingColorSpace(r)&&(l=ip(iI(l,a),r.colorSpace).setup(e).build(e,a)),e.format(l,a,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}sample(e){let t=this.clone();return t.uvNode=eS(e),t.referenceNode=this.getBase(),eS(t)}load(e){return this.sample(e).setSampler(!1)}blur(e){let t=this.clone();t.biasNode=eS(e).mul(iZ(t)),t.referenceNode=this.getBase();let r=t.value;return!1===t.generateMipmaps&&(r&&!1===r.generateMipmaps||r.minFilter===u.hxR||r.magFilter===u.hxR)&&((0,u.R8M)("TSL: texture().blur() requires mipmaps and sampling. Use .generateMipmaps=true and .minFilter/.magFilter=THREE.LinearFilter in the Texture."),t.biasNode=null),eS(t)}level(e){let t=this.clone();return t.levelNode=eS(e),t.referenceNode=this.getBase(),eS(t)}size(e){return iQ(this,e)}bias(e){let t=this.clone();return t.biasNode=eS(e),t.referenceNode=this.getBase(),eS(t)}getBase(){return this.referenceNode?this.referenceNode.getBase():this}compare(e){let t=this.clone();return t.compareNode=eS(e),t.referenceNode=this.getBase(),eS(t)}grad(e,t){let r=this.clone();return r.gradNode=[eS(e),eS(t)],r.referenceNode=this.getBase(),eS(r)}gather(e=0){let t=this.clone();return t.gatherNode=eS(e),t.referenceNode=this.getBase(),eS(t)}isSampleCompare(){return null!==this.compareNode||!0===this._samplerComparison}depth(e){let t=this.clone();return t.depthNode=eS(e),t.referenceNode=this.getBase(),eS(t)}offset(e){let t=this.clone();return t.offsetNode=eS(e),t.referenceNode=this.getBase(),eS(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){let e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix();let r=this._flipYUniform;null!==r&&(r.value=e.image instanceof ImageBitmap&&!0===e.flipY||!0===e.isRenderTargetTexture||!0===e.isFramebufferTexture||!0===e.isDepthTexture)}clone(){let e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e.depthNode=this.depthNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.gatherNode=this.gatherNode,e.offsetNode=this.offsetNode,e}}let i2=eE(i1).setParameterLength(1,4).setName("texture"),i3=(e=i0,t=null,r=null,i=null)=>{let s;return e&&!0===e.isTextureNode?((s=eS(e.clone())).referenceNode=e.getBase(),null!==t&&(s.uvNode=eS(t)),null!==r&&(s.levelNode=eS(r)),null!==i&&(s.biasNode=eS(i))):s=i2(e,t,r,i),s},i4=(...e)=>i3(...e).setSampler(!1);class i8 extends tw{static get type(){return"BufferNode"}constructor(e,t,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=r,this.updateRanges=[]}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}let i5=(e,t,r)=>new i8(e,t,r);class i6 extends I{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){let t=super.generate(e),r=this.getNodeType(e),i=this.node.getPaddedType();return e.format(t,i,r)}}class i9 extends i8{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null),this.array=e,this.elementType=null===t?R(e[0]):t,this.paddedType=this.getPaddedType(),this.updateType=B.RENDER,this.isArrayBufferNode=!0}generateNodeType(){return this.paddedType}getElementType(){return this.elementType}getPaddedType(){let e=this.elementType,t="vec4";return"mat2"===e?t="mat2":!0===/mat/.test(e)?t="mat4":"i"===e.charAt(0)?t="ivec4":"u"===e.charAt(0)&&(t="uvec4"),t}update(){this.updateBuffer()}onUpdate(e,t){return e=e.bind(this),super.onUpdate((t,r)=>{e(t,r),this.updateBuffer()},t)}updateBuffer(){let{array:e,value:t}=this,r=this.elementType;if("float"===r||"int"===r||"uint"===r)for(let r=0;r<e.length;r++)t[4*r]=e[r];else if("color"===r)for(let r=0;r<e.length;r++){let i=4*r,s=e[r];t[i]=s.r,t[i+1]=s.g,t[i+2]=s.b||0}else if("mat2"===r)for(let r=0;r<e.length;r++){let i=4*r,s=e[r];t[i]=s.elements[0],t[i+1]=s.elements[1],t[i+2]=s.elements[2],t[i+3]=s.elements[3]}else if("mat3"===r)for(let r=0;r<e.length;r++){let i=16*r,s=e[r];t[i]=s.elements[0],t[i+1]=s.elements[1],t[i+2]=s.elements[2],t[i+4]=s.elements[3],t[i+5]=s.elements[4],t[i+6]=s.elements[5],t[i+8]=s.elements[6],t[i+9]=s.elements[7],t[i+10]=s.elements[8],t[i+15]=1}else if("mat4"===r)for(let r=0;r<e.length;r++){let i=16*r,s=e[r];for(let e=0;e<s.elements.length;e++)t[i+e]=s.elements[e]}else for(let r=0;r<e.length;r++){let i=4*r,s=e[r];t[i]=s.x,t[i+1]=s.y,t[i+2]=s.z||0,t[i+3]=s.w||0}}setup(e){let t=this.array.length,r=this.elementType,i=Float32Array,s=this.paddedType,n=e.getTypeLength(s);return"i"===r.charAt(0)&&(i=Int32Array),"u"===r.charAt(0)&&(i=Uint32Array),this.value=new i(t*n),this.bufferCount=t,this.bufferType=s,this.updateBuffer(),super.setup(e)}element(e){return new i6(this,eS(e))}}let i7=(e,t)=>new i9(e,t);class se extends O{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}}let st=eE(se).setParameterLength(1);class sr extends O{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}generateNodeType(){return this.scope===sr.VIEWPORT?"vec4":"vec2"}update({renderer:e}){let t=e.getRenderTarget();this.scope===sr.VIEWPORT?null!==t?s.copy(t.viewport):(e.getViewport(s),s.multiplyScalar(e.getPixelRatio())):null!==t?(i.width=t.width,i.height=t.height):e.getDrawingBufferSize(i)}setup(){let e=this.scope,t=null;t=e===sr.SIZE?tB(i||(i=new u.I9Y)).setGroup(tE):e===sr.VIEWPORT?tB(s||(s=new u.IUQ)).setGroup(tE):eG(sa.div(sn));let r=B.NONE;return(this.scope===sr.SIZE||this.scope===sr.VIEWPORT)&&(r=B.RENDER),this.updateType=r,t}generate(e){if(this.scope===sr.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){let r=e.getNodeProperties(sn).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${r}.y - ${t}.y )`}return t}return super.generate(e)}}sr.COORDINATE="coordinate",sr.VIEWPORT="viewport",sr.SIZE="size",sr.UV="uv";let si=tB(1).setGroup(tE).onRenderUpdate(({renderer:e})=>e.getPixelRatio()),ss=eC(sr,sr.UV),sn=eC(sr,sr.SIZE),sa=eC(sr,sr.COORDINATE),so=eC(sr,sr.VIEWPORT),sl=so.zw,su=null,sd=null,sh=null,sc=null,sp=null,sm=null,sg=null,sf=null,sb=null,sy=null,sx=null,sT=null,s_=tB(0,"uint").setName("u_cameraIndex").setGroup(tA("cameraIndex")).toVarying("v_cameraIndex"),sv=tB("float").setName("cameraNear").setGroup(tE).onRenderUpdate(({camera:e})=>e.near),sS=tB("float").setName("cameraFar").setGroup(tE).onRenderUpdate(({camera:e})=>e.far),sR=eF(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let t of e.cameras)r.push(t.projectionMatrix);null===sd?sd=i7(r).setGroup(tE).setName("cameraProjectionMatrices"):sd.array=r,t=sd.element(e.isMultiViewCamera?st("gl_ViewID_OVR"):s_)}else null===su&&(su=tB(e.projectionMatrix).setName("cameraProjectionMatrix").setGroup(tE).onRenderUpdate(({camera:e})=>e.projectionMatrix)),t=su;return t}).once()(),sN=eF(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let t of e.cameras)r.push(t.projectionMatrixInverse);null===sc?sc=i7(r).setGroup(tE).setName("cameraProjectionMatricesInverse"):sc.array=r,t=sc.element(e.isMultiViewCamera?st("gl_ViewID_OVR"):s_)}else null===sh&&(sh=tB(e.projectionMatrixInverse).setName("cameraProjectionMatrixInverse").setGroup(tE).onRenderUpdate(({camera:e})=>e.projectionMatrixInverse)),t=sh;return t}).once()(),sA=eF(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let t of e.cameras)r.push(t.matrixWorldInverse);null===sm?sm=i7(r).setGroup(tE).setName("cameraViewMatrices"):sm.array=r,t=sm.element(e.isMultiViewCamera?st("gl_ViewID_OVR"):s_)}else null===sp&&(sp=tB(e.matrixWorldInverse).setName("cameraViewMatrix").setGroup(tE).onRenderUpdate(({camera:e})=>e.matrixWorldInverse)),t=sp;return t}).once()(),sE=eF(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let t of e.cameras)r.push(t.matrixWorld);null===sf?sf=i7(r).setGroup(tE).setName("cameraWorldMatrices"):sf.array=r,t=sf.element(e.isMultiViewCamera?st("gl_ViewID_OVR"):s_)}else null===sg&&(sg=tB(e.matrixWorld).setName("cameraWorldMatrix").setGroup(tE).onRenderUpdate(({camera:e})=>e.matrixWorld)),t=sg;return t}).once()(),sC=eF(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let t=0,i=e.cameras.length;t<i;t++)r.push(new u.Pq0);null===sy?sy=i7(r).setGroup(tE).setName("cameraPositions").onRenderUpdate(({camera:e},t)=>{let r=e.cameras,i=t.array;for(let e=0,t=r.length;e<t;e++)i[e].setFromMatrixPosition(r[e].matrixWorld)}):sy.array=r,t=sy.element(e.isMultiViewCamera?st("gl_ViewID_OVR"):s_)}else null===sb&&(sb=tB(new u.Pq0).setName("cameraPosition").setGroup(tE).onRenderUpdate(({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld))),t=sb;return t}).once()(),sw=eF(({camera:e})=>{let t;if(e.isArrayCamera&&e.cameras.length>0){let r=[];for(let t of e.cameras)r.push(t.viewport);null===sT?sT=i7(r,"vec4").setGroup(tE).setName("cameraViewports"):sT.array=r,t=sT.element(s_)}else null===sx&&(sx=eX(0,0,sn.x,sn.y).toConst("cameraViewport")),t=sx;return t}).once()(),sB=new u.iyt;class sM extends O{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=B.OBJECT,this.uniformNode=new tw(null)}generateNodeType(){let e=this.scope;return e===sM.WORLD_MATRIX?"mat4":e===sM.POSITION||e===sM.VIEW_POSITION||e===sM.DIRECTION||e===sM.SCALE?"vec3":e===sM.RADIUS?"float":void 0}update(e){let t=this.object3d,r=this.uniformNode,i=this.scope;if(i===sM.WORLD_MATRIX)r.value=t.matrixWorld;else if(i===sM.POSITION)r.value=r.value||new u.Pq0,r.value.setFromMatrixPosition(t.matrixWorld);else if(i===sM.SCALE)r.value=r.value||new u.Pq0,r.value.setFromMatrixScale(t.matrixWorld);else if(i===sM.DIRECTION)r.value=r.value||new u.Pq0,t.getWorldDirection(r.value);else if(i===sM.VIEW_POSITION){let i=e.camera;r.value=r.value||new u.Pq0,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(i.matrixWorldInverse)}else if(i===sM.RADIUS){let i=e.object.geometry;null===i.boundingSphere&&i.computeBoundingSphere(),sB.copy(i.boundingSphere).applyMatrix4(t.matrixWorld),r.value=sB.radius}}generate(e){let t=this.scope;return t===sM.WORLD_MATRIX?this.uniformNode.nodeType="mat4":t===sM.POSITION||t===sM.VIEW_POSITION||t===sM.DIRECTION||t===sM.SCALE?this.uniformNode.nodeType="vec3":t===sM.RADIUS&&(this.uniformNode.nodeType="float"),this.uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}sM.WORLD_MATRIX="worldMatrix",sM.POSITION="position",sM.SCALE="scale",sM.VIEW_POSITION="viewPosition",sM.DIRECTION="direction",sM.RADIUS="radius";let sF=new u.kn4;class sL extends sM{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}sL.DIRECTION;let sU=eC(sL,sL.WORLD_MATRIX);sL.POSITION,sL.SCALE,sL.VIEW_POSITION,sL.RADIUS;let sP=tB(new u.dwI).onObjectUpdate(({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld)),sD=eF(e=>e.context.modelViewMatrix||sO).once()().toVar("modelViewMatrix"),sO=sA.mul(sU),sI=eF(e=>{let t;e.context.isHighPrecisionModelViewMatrix=!0;let r=e.camera;if(r.isArrayCamera&&r.cameras.length>0){let e=[];for(let t=0;t<r.cameras.length;t++)e.push(new u.kn4);t=i7(e).onObjectUpdate(({object:e,camera:t},r)=>{let i=t.cameras,s=r.array;for(let t=0,r=i.length;t<r;t++)s[t].multiplyMatrices(i[t].matrixWorldInverse,e.matrixWorld)}).element(r.isMultiViewCamera?st("gl_ViewID_OVR"):s_)}else t=tB("mat4").onObjectUpdate(({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld));return t}).once()().toVar("highpModelViewMatrix"),sV=eF(e=>{let t,r=e.context.isHighPrecisionModelViewMatrix,i=e.camera;if(i.isArrayCamera&&i.cameras.length>0){let e=[];for(let t=0;t<i.cameras.length;t++)e.push(new u.dwI);t=i7(e).onObjectUpdate(({object:e,camera:t},r)=>{let i=t.cameras,s=r.array;for(let t=0,r=i.length;t<r;t++)sF.multiplyMatrices(i[t].matrixWorldInverse,e.matrixWorld),s[t].getNormalMatrix(sF)}).element(i.isMultiViewCamera?st("gl_ViewID_OVR"):s_)}else t=tB("mat3").onObjectUpdate(({object:e,camera:t})=>(!0!==r&&e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix)));return t}).once()().toVar("highpModelNormalViewMatrix"),sG=eF(e=>"fragment"!==e.shaderStage?((0,u.mcG)("TSL: `clipSpace` is only available in fragment stage."),eX()):e.context.clipSpace.toVarying("v_clipSpace")).once()(),sk=ij("position","vec3"),sz=sk.toVarying("positionLocal"),s$=sk.toVarying("positionPrevious"),sW=eF(e=>sU.mul(sz).xyz.toVarying(e.getSubBuildProperty("v_positionWorld")),"vec3").once(["POSITION"])(),sH=eF(()=>sz.transformDirection(sU).toVarying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),"vec3").once(["POSITION"])(),sq=eF(e=>{if("fragment"===e.shaderStage&&e.material.vertexNode){let e=sN.mul(sG);return e.xyz.div(e.w).toVar("positionView")}return e.context.setupPositionView().toVarying("v_positionView")},"vec3").once(["POSITION","VERTEX"])(),sj=eF(e=>(e.camera.isOrthographicCamera?eW(0,0,1):sq.negate().toVarying("v_positionViewDirection").normalize()).toVar("positionViewDirection"),"vec3").once(["POSITION"])();class sX extends O{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){if("fragment"!==e.shaderStage)return"true";let{material:t}=e;return t.side===u.hsX?"false":e.getFrontFacing()}}let sK=eD(eC(sX)).mul(2).sub(1),sQ=eF(([e],{material:t})=>{let r=t.side;return r===u.hsX?e=e.mul(-1):r===u.$EB&&(e=e.mul(sK)),e}),sY=ij("normal","vec3"),sZ=eF(e=>!1===e.geometry.hasAttribute("normal")?((0,u.R8M)('TSL: Vertex attribute "normal" not found on geometry.'),eW(0,1,0)):sY,"vec3").once()().toVar("normalLocal"),sJ=sq.dFdx().cross(sq.dFdy()).normalize().toVar("normalFlat"),s0=eF(e=>e.isFlatShading()?sJ:s5(sZ).toVarying("v_normalViewGeometry").normalize(),"vec3").once()().toVar("normalViewGeometry"),s1=eF(e=>{let t=s0.transformNormalByInverseViewMatrix(sA);return!0!==e.isFlatShading()&&(t=t.toVarying("v_normalWorldGeometry")),t.normalize().toVar("normalWorldGeometry")},"vec3").once()(),s2=eF(e=>{let t;return"NORMAL"===e.subBuildFn||"VERTEX"===e.subBuildFn?(t=s0,!0!==e.isFlatShading()&&(t=sQ(t))):t=e.context.setupNormal().context({getUV:null,getTextureLevel:null}),t},"vec3").once(["NORMAL","VERTEX"])().toVar("normalView"),s3=s2.transformNormalByInverseViewMatrix(sA).toVar("normalWorld"),s4=eF(({subBuildFn:e,context:t})=>"NORMAL"===e||"VERTEX"===e?s2:t.setupClearcoatNormal().context({getUV:null,getTextureLevel:null}),"vec3").once(["NORMAL","VERTEX"])().toVar("clearcoatNormalView"),s8=eF(([e,t=sU])=>eJ(t).inverse().transpose().mul(e).normalize());Z("transformNormal",s8);let s5=eF(([e],t)=>{let r=t.context.modelNormalViewMatrix;return r?e.transformNormalByViewMatrix(r):sP.mul(e).transformNormalByViewMatrix(sA)});eF(()=>((0,u.R8M)('TSL: "transformedNormalView" is deprecated. Use "normalView" instead.'),s2)).once(["NORMAL","VERTEX"])(),eF(()=>((0,u.R8M)('TSL: "transformedNormalWorld" is deprecated. Use "normalWorld" instead.'),s3)).once(["NORMAL","VERTEX"])(),eF(()=>((0,u.R8M)('TSL: "transformedClearcoatNormalView" is deprecated. Use "clearcoatNormalView" instead.'),s4)).once(["NORMAL","VERTEX"])();let s6=new u.kn4,s9=tB(0).onReference(({material:e})=>e).onObjectUpdate(({material:e})=>e.refractionRatio),s7=tB(1).onReference(({material:e})=>e).onObjectUpdate(function({material:e,scene:t}){return e.envMap?e.envMapIntensity:t.environmentIntensity}),ne=tB(new u.kn4).onReference(function(e){return e.material}).onObjectUpdate(function({material:e,scene:t}){let r=(null!==t.environment||t.environmentNode&&t.environmentNode.isNode)&&null===e.envMap?t.environmentRotation:e.envMapRotation;return r?s6.makeRotationFromEuler(r).transpose():s6.identity(),s6}),nt=sj.negate().reflect(s2),nr=sj.negate().refract(s2,s9),ni=nt.transformDirection(sE).toVar("reflectVector"),ns=nr.transformDirection(sE).toVar("refractVector"),nn=new u.b4q;class na extends i1{static get type(){return"CubeTextureNode"}constructor(e,t=null,r=null,i=null){super(e,t,r,i),this.isCubeTextureNode=!0}getInputType(){return!0===this.value.isDepthTexture?"cubeDepthTexture":"cubeTexture"}getDefaultUV(){let e=this.value;return e.mapping===u.hy7?ni:e.mapping===u.xFO?ns:((0,u.z3S)('CubeTextureNode: Mapping "%s" not supported.',e.mapping),eW(0,0,0))}setUpdateMatrix(){}setupUV(e,t){let r=this.value;return!0===r.isDepthTexture?e.renderer.coordinateSystem===u.i7u?eW(t.x,t.y.negate(),t.z):t:(t=ne.mul(t),e.renderer.coordinateSystem!==u.i7u&&r.isRenderTargetTexture||(t=eW(t.x.negate(),t.yz)),t)}generateUV(e,t){return t.build(e,!0===this.sampler?"vec3":"ivec3")}}let no=eE(na).setParameterLength(1,4).setName("cubeTexture"),nl=(e=nn,t=null,r=null,i=null)=>{let s;return e&&!0===e.isCubeTextureNode?((s=eS(e.clone())).referenceNode=e,null!==t&&(s.uvNode=eS(t)),null!==r&&(s.levelNode=eS(r)),null!==i&&(s.biasNode=eS(i))):s=no(e,t,r,i),s};class nu extends O{static get type(){return"ReferenceNode"}constructor(e,t,r=null,i=null){super(),this.property=e,this.uniformType=t,this.object=r,this.count=i,this.properties=e.split("."),this.reference=r,this.node=null,this.group=null,this.name=null,this.updateType=B.OBJECT}element(e){return new im(this,eS(e))}setGroup(e){return this.group=e,this}setName(e){return this.name=e,this}label(e){return(0,u.R8M)('TSL: "label()" has been deprecated. Use "setName()" instead.'),this.setName(e)}setNodeType(e){let t=null;null!==this.count?t=i5(null,e,this.count):Array.isArray(this.getValueFromReference())?(t=i7(null,e)).updateType=B.OBJECT:t="texture"===e?i3(null):"cubeTexture"===e?nl(null):tB(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.setName(this.name),this.node=t}generateNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){let{properties:t}=this,r=e[t[0]];for(let e=1;e<t.length;e++)r=r[t[e]];return r}updateReference(e){return this.reference=null!==this.object?this.object:e.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);let e=this.getValueFromReference();Array.isArray(e)?this.node.array=e:this.node.value=e}}let nd=(e,t,r)=>new nu(e,t,r);class nh extends nu{static get type(){return"MaterialReferenceNode"}constructor(e,t,r=null){super(e,t,r),this.material=r,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}let nc=(e,t,r=null)=>new nh(e,t,r),np=iX(),nm=sq.dFdx(),ng=sq.dFdy(),nf=np.dFdx(),nb=np.dFdy(),ny=ng.cross(s2),nx=s2.cross(nm),nT=ny.mul(nf.x).add(nx.mul(nb.x)),n_=ny.mul(nf.y).add(nx.mul(nb.y)),nv=nT.dot(nT).max(n_.dot(n_)),nS=nv.equal(0).select(0,nv.inverseSqrt()),nR=nT.mul(nS).toVar("tangentViewFrame"),nN=n_.mul(nS).toVar("bitangentViewFrame"),nA=ij("tangent","vec4"),nE=nA.xyz.toVar("tangentLocal"),nC=eF(e=>{let t;return t="VERTEX"===e.subBuildFn||e.geometry.hasAttribute("tangent")?sD.mul(eX(nE,0)).xyz.toVarying("v_tangentView").normalize():nR,!0!==e.isFlatShading()&&(t=sQ(t)),t},"vec3").once(["NORMAL","VERTEX"])().toVar("tangentView"),nw=eF(([e,t],r)=>{let i=e.mul(nA.w).xyz;return"NORMAL"===r.subBuildFn&&!0!==r.isFlatShading()&&(i=i.toVarying(t)),i}).once(["NORMAL"]),nB=eF(e=>{let t;return t="VERTEX"===e.subBuildFn||e.geometry.hasAttribute("tangent")?nw(s2.cross(nC),"v_bitangentView").normalize():nN,!0!==e.isFlatShading()&&(t=sQ(t)),t},"vec3").once(["NORMAL","VERTEX"])().toVar("bitangentView"),nM=eJ(nC,nB,s2).toVar("TBNViewMatrix"),nF=eF(()=>{let e=tu.cross(sj);return r0(e=e.cross(tu).normalize(),s2,to.mul(e6.oneMinus()).oneMinus().pow2().pow2()).normalize()}).once()(),nL=e=>eW(e,ru(r2(eD(1).sub(rj(e,e)))));class nU extends G{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=u.bI3,this.unpackNormalMode=u.AZd}setup(e){let{normalMapType:t,scaleNode:r,unpackNormalMode:i}=this,s=this.node.mul(2).sub(1);if(t===u.bI3?i===u.IjV?s=nL(s.xy):i===u.pO5?s=nL(s.yw):i!==u.AZd&&(0,u.z3S)(`THREE.NodeMaterial: Unexpected unpack normal mode: ${i}`):i!==u.AZd&&(0,u.z3S)(`THREE.NodeMaterial: Normal map type '${t}' is not compatible with unpack normal mode '${i}'`),null!==r){let t=r;!0===e.isFlatShading()&&(t=sQ(t)),s=eW(s.xy.mul(t),s.z)}let n=null;return t===u.vyJ?n=s5(s):t===u.bI3?n=nM.mul(s).normalize():((0,u.z3S)(`NodeMaterial: Unsupported normal map type: ${t}`),n=s2),n}}let nP=eE(nU).setParameterLength(1,2),nD=eF(({textureNode:e,bumpScale:t})=>{let r=t=>e.isolate().context({getUV:e=>t(e.uvNode||iX()),forceUVContext:!0}),i=eD(r(e=>e));return eG(eD(r(e=>e.add(e.dFdx()))).sub(i),eD(r(e=>e.add(e.dFdy()))).sub(i)).mul(t)}),nO=eF(e=>{let{surf_pos:t,surf_norm:r,dHdxy:i}=e,s=t.dFdx().normalize(),n=t.dFdy().normalize().cross(r),a=r.cross(s),o=s.dot(n).mul(sK),l=o.sign().mul(i.x.mul(n).add(i.y.mul(a)));return o.abs().mul(r).sub(l).normalize()});class nI extends G{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(e){if(!0===e.material.wireframe)return s2;let t=null!==this.scaleNode?this.scaleNode:1;return nO({surf_pos:sq,surf_norm:s2,dHdxy:nD({textureNode:this.textureNode,bumpScale:t})})}}let nV=eE(nI).setParameterLength(1,2),nG=new Map;class nk extends O{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let r=nG.get(e);return void 0===r&&(r=nc(e,t),nG.set(e,r)),r}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){let t=e.context.material,r=this.scope,i=null;if(r===nk.COLOR){let e=void 0!==t.color?this.getColor(r):eW();i=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(r===nk.OPACITY){let e=this.getFloat(r);i=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(r===nk.SPECULAR_STRENGTH)i=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:eD(1);else if(r===nk.SPECULAR_INTENSITY){let e=this.getFloat(r);i=t.specularIntensityMap&&!0===t.specularIntensityMap.isTexture?e.mul(this.getTexture(r).a):e}else if(r===nk.SPECULAR_COLOR){let e=this.getColor(r);i=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(r).rgb):e}else if(r===nk.ROUGHNESS){let e=this.getFloat(r);i=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(r).g):e}else if(r===nk.METALNESS){let e=this.getFloat(r);i=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(r).b):e}else if(r===nk.EMISSIVE){let e=this.getFloat("emissiveIntensity"),s=this.getColor(r).mul(e);i=t.emissiveMap&&!0===t.emissiveMap.isTexture?s.mul(this.getTexture(r)):s}else if(r===nk.NORMAL)t.normalMap?((i=nP(this.getTexture("normal"),this.getCache("normalScale","vec2"))).normalMapType=t.normalMapType,(t.normalMap.format==u.paN||t.normalMap.format==u.HO_||t.normalMap.format==u.OtU)&&(i.unpackNormalMode=u.IjV)):i=t.bumpMap?nV(this.getTexture("bump").r,this.getFloat("bumpScale")):s2;else if(r===nk.CLEARCOAT){let e=this.getFloat(r);i=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(r).r):e}else if(r===nk.CLEARCOAT_ROUGHNESS){let e=this.getFloat(r);i=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(r).r):e}else if(r===nk.CLEARCOAT_NORMAL)i=t.clearcoatNormalMap?nP(this.getTexture(r),this.getCache(r+"Scale","vec2")):s2;else if(r===nk.SHEEN){let e=this.getColor("sheenColor").mul(this.getFloat("sheen"));i=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(r===nk.SHEEN_ROUGHNESS){let e=this.getFloat(r);i=(i=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(r).a):e).clamp(1e-4,1)}else if(r===nk.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){let e=this.getTexture(r);i=eZ(af.x,af.y,af.y.negate(),af.x).mul(e.rg.mul(2).sub(eG(1)).normalize().mul(e.b))}else i=af;else if(r===nk.IRIDESCENCE_THICKNESS){let e=nd("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){let s=nd("0","float",t.iridescenceThicknessRange);i=e.sub(s).mul(this.getTexture(r).g).add(s)}else i=e}else if(r===nk.TRANSMISSION){let e=this.getFloat(r);i=t.transmissionMap?e.mul(this.getTexture(r).r):e}else if(r===nk.THICKNESS){let e=this.getFloat(r);i=t.thicknessMap?e.mul(this.getTexture(r).g):e}else if(r===nk.IOR)i=this.getFloat(r);else if(r===nk.LIGHT_MAP)i=t.lightMap?this.getTexture(r).rgb.mul(this.getFloat("lightMapIntensity")):eW(0);else if(r===nk.AO)i=t.aoMap?this.getTexture(r).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1):eD(1);else if(r===nk.LINE_DASH_OFFSET)i=t.dashOffset?this.getFloat(r):eD(0);else{let t=this.getNodeType(e);i=this.getCache(r,t)}return i}}nk.ALPHA_TEST="alphaTest",nk.COLOR="color",nk.OPACITY="opacity",nk.SHININESS="shininess",nk.SPECULAR="specular",nk.SPECULAR_STRENGTH="specularStrength",nk.SPECULAR_INTENSITY="specularIntensity",nk.SPECULAR_COLOR="specularColor",nk.REFLECTIVITY="reflectivity",nk.ROUGHNESS="roughness",nk.METALNESS="metalness",nk.NORMAL="normal",nk.CLEARCOAT="clearcoat",nk.CLEARCOAT_ROUGHNESS="clearcoatRoughness",nk.CLEARCOAT_NORMAL="clearcoatNormal",nk.EMISSIVE="emissive",nk.ROTATION="rotation",nk.SHEEN="sheen",nk.SHEEN_ROUGHNESS="sheenRoughness",nk.ANISOTROPY="anisotropy",nk.IRIDESCENCE="iridescence",nk.IRIDESCENCE_IOR="iridescenceIOR",nk.IRIDESCENCE_THICKNESS="iridescenceThickness",nk.IOR="ior",nk.TRANSMISSION="transmission",nk.THICKNESS="thickness",nk.ATTENUATION_DISTANCE="attenuationDistance",nk.ATTENUATION_COLOR="attenuationColor",nk.LINE_SCALE="scale",nk.LINE_DASH_SIZE="dashSize",nk.LINE_GAP_SIZE="gapSize",nk.LINE_WIDTH="linewidth",nk.LINE_DASH_OFFSET="dashOffset",nk.POINT_SIZE="size",nk.DISPERSION="dispersion",nk.RETROREFLECTIVITY="retroreflectivity",nk.LIGHT_MAP="light",nk.AO="ao";let nz=eC(nk,nk.ALPHA_TEST),n$=eC(nk,nk.COLOR),nW=eC(nk,nk.SHININESS),nH=eC(nk,nk.EMISSIVE),nq=eC(nk,nk.OPACITY),nj=eC(nk,nk.SPECULAR),nX=eC(nk,nk.SPECULAR_INTENSITY),nK=eC(nk,nk.SPECULAR_COLOR),nQ=eC(nk,nk.SPECULAR_STRENGTH),nY=eC(nk,nk.REFLECTIVITY),nZ=eC(nk,nk.ROUGHNESS),nJ=eC(nk,nk.METALNESS),n0=eC(nk,nk.NORMAL),n1=eC(nk,nk.CLEARCOAT),n2=eC(nk,nk.CLEARCOAT_ROUGHNESS),n3=eC(nk,nk.CLEARCOAT_NORMAL),n4=eC(nk,nk.ROTATION),n8=eC(nk,nk.SHEEN),n5=eC(nk,nk.SHEEN_ROUGHNESS),n6=eC(nk,nk.ANISOTROPY),n9=eC(nk,nk.IRIDESCENCE),n7=eC(nk,nk.IRIDESCENCE_IOR),ae=eC(nk,nk.IRIDESCENCE_THICKNESS),at=eC(nk,nk.TRANSMISSION),ar=eC(nk,nk.THICKNESS),ai=eC(nk,nk.IOR),as=eC(nk,nk.ATTENUATION_DISTANCE),an=eC(nk,nk.ATTENUATION_COLOR),aa=eC(nk,nk.LINE_SCALE),ao=eC(nk,nk.LINE_DASH_SIZE),al=eC(nk,nk.LINE_GAP_SIZE),au=eC(nk,nk.LINE_WIDTH),ad=eC(nk,nk.LINE_DASH_OFFSET),ah=eC(nk,nk.POINT_SIZE),ac=eC(nk,nk.DISPERSION),ap=eC(nk,nk.RETROREFLECTIVITY),am=eC(nk,nk.LIGHT_MAP),ag=eC(nk,nk.AO),af=tB(new u.I9Y).onReference(function(e){return e.material}).onRenderUpdate(function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}),ab=eF(e=>e.context.setupModelViewProjection(),"vec4").once()().toVarying("v_modelViewProjection");class ay extends O{static get type(){return"EventNode"}constructor(e,t){super("void"),this.eventType=e,this.callback=t,e===ay.OBJECT?this.updateType=B.OBJECT:e===ay.MATERIAL?this.updateType=B.RENDER:e===ay.FRAME?this.updateType=B.FRAME:e===ay.AFTER_OBJECT?this.updateAfterType=B.OBJECT:e===ay.BEFORE_OBJECT?this.updateBeforeType=B.OBJECT:e===ay.BEFORE_MATERIAL?this.updateBeforeType=B.RENDER:e===ay.BEFORE_FRAME&&(this.updateBeforeType=B.FRAME)}setup(e){let{eventType:t,callback:r}=this;if(t===ay.BEFORE_RENDER_PIPELINE){let t=e.context.onBeforePipelineCallbacks;t&&t.push(r)}else if(t===ay.AFTER_RENDER_PIPELINE){let t=e.context.onAfterPipelineCallbacks;t&&t.push(r)}return super.setup(e)}update(e){this.callback(e)}updateBefore(e){this.callback(e)}updateAfter(e){this.callback(e)}}ay.OBJECT="object",ay.MATERIAL="material",ay.FRAME="frame",ay.AFTER_OBJECT="afterObject",ay.BEFORE_OBJECT="beforeObject",ay.BEFORE_MATERIAL="beforeMaterial",ay.BEFORE_FRAME="beforeFrame",ay.BEFORE_RENDER_PIPELINE="beforeRenderPipeline",ay.AFTER_RENDER_PIPELINE="afterRenderPipeline";let ax=(e,t)=>new ay(e,t).toStack(),aT=e=>ax(ay.OBJECT,e),a_=e=>ax(ay.AFTER_OBJECT,e);class av extends I{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}getMemberType(e,t){let r=this.storageBufferNode.structTypeNode;return r?r.getMemberType(e,t):"void"}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.isPBO&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let r,i=e.isContextAssign();if(r=!1===e.isAvailable("storageBuffer")?!0===this.node.isPBO&&!0!==i&&(this.node.value.isInstancedBufferAttribute||"compute"!==e.shaderStage)?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==i){let i=this.getNodeType(e);r=e.format(r,i,t)}return r}}let aS=eE(av).setParameterLength(2);class aR extends i8{static get type(){return"StorageBufferNode"}constructor(e,t=null,r=0){let i,s=null;if(t&&t.isStructTypeNode)i="struct",s=t,(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(r=e.count);else if(null===t&&(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)){var n;n=e.itemSize,i=v.get(n),r=e.count}else i=t;super(e,i,r),this.isStorageBufferNode=!0,this.structTypeNode=s,this.access=M.READ_WRITE,this.isAtomic=!1,this.isPBO=!1,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){let t;if(0===this.bufferCount){let r=e.globalCache.getData(this.value);void 0===r&&(r={node:this},e.globalCache.setData(this.value,r)),t=r.node.id}else t=this.id;return String(t)}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return aS(this,e)}setPBO(e){return this.isPBO=e,this}getPBO(){return this.isPBO}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(M.READ_ONLY)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=iR(this.value),this._varying=il(this._attribute)),{attribute:this._attribute,varying:this._varying}}generateNodeType(e){if(null!==this.structTypeNode)return this.structTypeNode.getNodeType(e);if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generateNodeType(e);let{attribute:t}=this.getAttributeData();return t.getNodeType(e)}getMemberType(e,t){return null!==this.structTypeNode?this.structTypeNode.getMemberType(e,t):"void"}generate(e){if(null!==this.structTypeNode&&this.structTypeNode.build(e),e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);let{attribute:t,varying:r}=this.getAttributeData(),i=r.build(e);return e.registerTransform(i,t),i}}let aN=(e,t=null,r=0)=>new aR(e,t,r),aA=new WeakMap,aE=new WeakMap,aC=new WeakMap;function aw(e,t){let r,i=Math.max(t.count,1);if(!0===t.isStorageInstancedBufferAttribute)r=aN(t,"mat4",i).element(iw);else if(16*i*4<=e.getUniformBufferLimit())r=i5(t.array,"mat4",i).element(iw);else{let e=aA.get(t);e||(e=new u.LuO(t.array,16,1),aA.set(t,e));let i=t.usage===u.Vnu?iA:iN;r=e0(i(e,"vec4",16,0),i(e,"vec4",16,4),i(e,"vec4",16,8),i(e,"vec4",16,12))}return r}let aB=e3("vec3","vInstanceColor"),aM=eF(([e,t=null],r)=>{let i=!0===e.isStorageInstancedBufferAttribute,s=t&&!0===t.isStorageInstancedBufferAttribute,n=aw(r,e),a=null;!i&&16*Math.max(e.count,1)*4>r.getUniformBufferLimit()&&(a=aA.get(e));let o=null,l=null;if(t)if(s)o=aN(t,"vec3",Math.max(t.count,1)).element(iw);else{let e=aE.get(t);e||(e=new u.uWO(t.array,3),aE.set(t,e)),l=e,o=eW((t.usage===u.Vnu?iA:iN)(e,"vec3",3,0))}(null!==a||null!==l)&&ax(ay.BEFORE_FRAME,()=>{null!==a&&a.version!==e.version&&(a.clearUpdateRanges(),a.updateRanges.push(...e.updateRanges),e.clearUpdateRanges(),a.version=e.version),t&&null!==l&&l.version!==t.version&&(l.clearUpdateRanges(),l.updateRanges.push(...t.updateRanges),t.clearUpdateRanges(),l.version=t.version)});let d=n.mul(sz).xyz;if(sz.assign(d),r.needsPreviousData()){let t=r.object;a_(({object:t})=>{let{previousInstanceMatrix:r}=aC.get(t);r.array.set(e.array),r.version=e.version;let i=aA.get(r);void 0!==i&&(i.version=e.version)});let i=function(e,t,r){let i=aC.get(e);if(void 0===i){let s=t.clone();i={previousInstanceMatrix:s,node:aw(r,s)},aC.set(e,i)}return i.node}(t,e,r);s$.assign(i.mul(s$).xyz)}if(r.hasGeometryAttribute("normal")){let e=s8(sZ,n);sZ.assign(e)}null!==o&&aB.assign(o)},"void"),aF=eF(([e])=>{let{instanceMatrix:t,instanceColor:r}=e;aM(t,r)},"void"),aL=new WeakMap,aU=eF(([e,t])=>{let r=eO(iQ(i4(e),0).x).toConst(),i=eO(t);return i4(e,ek(i.mod(r).toConst(),i.div(r).toConst()))}),aP=eF(([e,t])=>{let r=eO(iQ(i4(e),0).x).toConst();return i4(e,ek(eO(t).mod(r).toConst(),eO(t).div(r).toConst())).x});function aD(e,t){let r=eO(iQ(i4(e),0).x).toConst(),i=eD(t).mul(4).toInt().toConst(),s=i.mod(r).toConst(),n=i.div(r).toConst();return e0(i4(e,ek(s,n)),i4(e,ek(s.add(1),n)),i4(e,ek(s.add(2),n)),i4(e,ek(s.add(3),n)))}let aO=e3("vec4","vBatchColor"),aI=e3("uint","vBatchIndirectId"),aV=eF(([e],t)=>{let r=null===t.getDrawIndex()?iw:iB,i=aP(e._indirectTexture,eO(r));aI.assign(i);let s=aD(e._matricesTexture,i),n=e._colorsTexture;if(null!==n){let e=aU(n,i);aO.assign(e)}let a=eJ(s);if(sz.assign(s.mul(sz)),t.needsPreviousData()){a_(({object:e})=>{let t=aL.get(e);t.previousMatricesTexture.image.data.set(e._matricesTexture.image.data),t.previousMatricesTexture.needsUpdate=!0});let t=function(e,t){let r=aL.get(e);if(void 0===r){let{image:i,format:s,type:n}=e._matricesTexture,a=new u.GYF(i.data.slice(),i.width,i.height,s,n);r={previousMatricesTexture:a,node:aD(a,t)},aL.set(e,r)}return r.node}(e,i);s$.assign(t.mul(s$).xyz)}let o=sZ.div(eW(a[0].dot(a[0]),a[1].dot(a[1]),a[2].dot(a[2]))),l=a.mul(o).xyz;sZ.assign(l),t.hasGeometryAttribute("tangent")&&nE.mulAssign(a)},"void"),aG=new WeakMap,ak=new WeakMap;function az(e){return{element:t=>{let r=eO(iQ(e).x).toConst(),i=eO(t).mul(4).toConst(),s=i.div(r).toConst(),n=i.sub(s.mul(r)).toConst();return e0(e.load(ek(n,s)),e.load(ek(n.add(1),s)),e.load(ek(n.add(2),s)),e.load(ek(n.add(3),s)))}}}function a$(e,t,r,i,s,n){let a=e.element(s.x),o=e.element(s.y),l=e.element(s.z),u=e.element(s.w),d=r.mul(t),h=tO(a.mul(n.x).mul(d),o.mul(n.y).mul(d),l.mul(n.z).mul(d),u.mul(n.w).mul(d));return i.mul(h).xyz}function aW(e,t,r,i,s,n,a){let o=e.element(n.x),l=e.element(n.y),u=e.element(n.z),d=e.element(n.w),h=tO(a.x.mul(o),a.y.mul(l),a.z.mul(u),a.w.mul(d)),c=eJ(h=s.mul(h).mul(i));return{skinNormal:c.mul(t),skinTangent:c.mul(r)}}function aH(e,t,r,i,s,n){let a=t.skeleton,o=ak.get(a);if(void 0===o){if(a.update(),16*a.bones.length*4<=e.getUniformBufferLimit()){let e=new Float32Array(a.boneMatrices);o={previousBoneMatrices:e,previousBoneTexture:null,node:i5(e,"mat4",a.bones.length)}}else{null===a.boneTexture&&a.computeBoneTexture();let{width:e,height:t}=a.boneTexture.image,r=new Float32Array(a.boneMatrices),i=new u.GYF(r,e,t,u.GWd,u.RQf);i.needsUpdate=!0,o={previousBoneMatrices:r,previousBoneTexture:i,node:az(i3(i))}}ak.set(a,o)}return a$(o.node,s$,r,i,s,n)}let aq=eF(([e],t)=>{let r=ij("skinIndex","uvec4"),i=ij("skinWeight","vec4"),s=nd("bindMatrix","mat4"),n=nd("bindMatrixInverse","mat4"),a=function(e,t){let r;if(16*t.bones.length*4<=e.getUniformBufferLimit())r=new nu("skeleton.boneMatrices","mat4",void 0,t.bones.length);else{null===t.boneTexture&&t.computeBoneTexture();let e=i3(t.boneTexture);aT(({object:t})=>{let r=t.skeleton;null===r.boneTexture&&r.computeBoneTexture(),e.value=r.boneTexture}),r=az(e)}return r}(t,e.skeleton);if(aT(({object:e,frameId:t})=>{let r=e.skeleton;if(aG.get(r)!==t){aG.set(r,t);let e=ak.get(r);void 0!==e&&(e.previousBoneMatrices.set(r.boneMatrices),null!==e.previousBoneTexture&&(e.previousBoneTexture.needsUpdate=!0)),r.update()}}),t.needsPreviousData()){let a=aH(t,e,s,n,r,i);s$.assign(a)}let o=a$(a,sz,s,n,r,i);if(sz.assign(o),t.hasGeometryAttribute("normal")){let{skinNormal:e,skinTangent:o}=aW(a,sZ,nE,s,n,r,i);sZ.assign(e),t.hasGeometryAttribute("tangent")&&nE.assign(o)}},"void");class aj extends O{static get type(){return"LoopNode"}constructor(e=[]){super("void"),this.params=e}getVarName(e){return String.fromCharCode(105+e)}getProperties(e){let t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;let r={},i=this._getInternalParams();for(let e=0,t=i.length-1;e<t;e++){let t=i[e],s=!0!==t.isNode&&t.name||this.getVarName(e),n=!0!==t.isNode&&t.type||"int";r[s]=iI(s,n)}let s=e.addStack(),n=i[i.length-1](r);t.returnsNode=n.context({nodeLoop:n}),t.stackNode=s;let a=i[0];if(!0!==a.isNode&&"function"==typeof a.update){let e=eF(a.update)(r);t.updateNode=e.context({nodeLoop:e})}return e.removeStack(),t}_getInternalParams(){let e=this.params;return"function"==typeof e[0]?[eV(!0),e[0]]:e}setup(e){this.getProperties(e),e.fnCall&&(e.getDataFromNode(e.fnCall.shaderNode).hasLoop=!0)}generate(e){let t=this.getProperties(e),r=this._getInternalParams(),i=t.stackNode;for(let i=0,s=r.length-1;i<s;i++){let s,n=r[i],a=!1,o=null,l=null,d=null,h=null,c=null,p=null;if(n.isNode?"bool"===n.getNodeType(e)?(a=!0,h="bool",l=n.build(e,h)):(h="int",d=this.getVarName(i),o="0",l=n.build(e,h),c="<"):(h=n.type||"int",d=n.name||this.getVarName(i),o=n.start,l=n.end,c=n.condition,p=n.update,"number"==typeof o?o=e.generateConst(h,o):o&&o.isNode&&(o=o.build(e,h)),"number"==typeof l?l=e.generateConst(h,l):l&&l.isNode&&(l=l.build(e,h)),void 0!==o&&void 0===l?(o+=" - 1",l="0",c=">="):void 0!==l&&void 0===o&&(o="0",c="<"),void 0===c&&(c=Number(o)>Number(l)?">=":"<")),a)s=`while ( ${l} )`;else{let r,i=o,n=l,a=()=>c.includes("<")?"+=":"-=";if(null!=p)switch(typeof p){case"function":r=e.flowStagesNode(t.updateNode,"void").code.replace(/\t|;/g,"");break;case"number":r=d+" "+a()+" "+e.generateConst(h,p);break;case"string":r=d+" "+p;break;default:p.isNode?r=d+" "+a()+" "+p.build(e):((0,u.z3S)("TSL: 'Loop( { update: ... } )' is not a function, string or number.",this.stackTrace),r="break /* invalid update */")}else r=d+" "+(p="int"===h||"uint"===h?c.includes("<")?"++":"--":a()+" 1.");let m=e.getVar(h,d)+" = "+i,g=d+" "+c+" "+n;s=`for ( ${m}; ${g}; ${r} )`}e.addFlowCode((0===i?"\n":"")+e.tab+s+" {\n\n").addFlowTab()}let s=i.build(e,"void");t.returnsNode.build(e,"void"),e.removeFlowTab().addFlowCode("\n"+e.tab+s);for(let t=0,i=r.length-1;t<i;t++)e.addFlowCode((0===t?"":e.tab)+"}\n\n").removeFlowTab();e.addFlowTab()}}let aX=(...e)=>new aj(eA(e,"int")).toStack(),aK=new WeakMap,aQ=new u.IUQ,aY=new WeakMap,aZ=eF(({bufferMap:e,influence:t,stride:r,width:i,depth:s,offset:n})=>{let a=eO(iC).mul(r).add(n),o=a.div(i);return i4(e,ek(a.sub(o.mul(i)),o)).depth(s).xyz.mul(t)}),aJ=eF(([e])=>{let{geometry:t}=e,r=void 0!==t.morphAttributes.position,i=t.hasAttribute("normal")&&void 0!==t.morphAttributes.normal,s=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,n=void 0!==s?s.length:0;if(0===n)return;let a=aY.get(e);(void 0===a||a.count!==n)&&(a={base:tB(1),influences:e.morphTargetInfluences?i7(e.morphTargetInfluences,"float"):null,count:n},aY.set(e,a));let{base:o,influences:l}=a,{texture:d,stride:h,size:c}=function(e){let t=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,i=void 0!==e.morphAttributes.color,s=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,n=void 0!==s?s.length:0,a=aK.get(e);if(void 0===a||a.count!==n){void 0!==a&&a.texture.dispose();let s=e.morphAttributes.position||[],o=e.morphAttributes.normal||[],l=e.morphAttributes.color||[],d=0;!0===t&&(d=1),!0===r&&(d=2),!0===i&&(d=3);let h=e.attributes.position.count*d,c=1;h>4096&&(c=Math.ceil(h/4096),h=4096);let p=new Float32Array(h*c*4*n),m=new u.rFo(p,h,c,n);m.type=u.RQf,m.needsUpdate=!0;let g=4*d;for(let e=0;e<n;e++){let n=s[e],a=o[e],u=l[e],d=h*c*4*e;for(let e=0;e<n.count;e++){let s=e*g;!0===t&&(aQ.fromBufferAttribute(n,e),p[d+s+0]=aQ.x,p[d+s+1]=aQ.y,p[d+s+2]=aQ.z,p[d+s+3]=0),!0===r&&(aQ.fromBufferAttribute(a,e),p[d+s+4]=aQ.x,p[d+s+5]=aQ.y,p[d+s+6]=aQ.z,p[d+s+7]=0),!0===i&&(aQ.fromBufferAttribute(u,e),p[d+s+8]=aQ.x,p[d+s+9]=aQ.y,p[d+s+10]=aQ.z,p[d+s+11]=4===u.itemSize?aQ.w:1)}}a={count:n,texture:m,stride:d,size:new u.I9Y(h,c)},aK.set(e,a),e.addEventListener("dispose",function t(){m.dispose(),aK.delete(e),e.removeEventListener("dispose",t)})}return a}(t);!0===r&&sz.mulAssign(o),!0===i&&sZ.mulAssign(o);let p=eO(c.width);aX(n,({i:t})=>{let s=eD(0).toVar();e.count>1&&null!==e.morphTexture&&void 0!==e.morphTexture?s.assign(i4(e.morphTexture,ek(eO(t).add(1),eO(iw))).r):s.assign(l.element(t).toVar()),eU(s.notEqual(0),()=>{!0===r&&sz.addAssign(aZ({bufferMap:d,influence:s,stride:h,width:p,depth:t,offset:eO(0)})),!0===i&&sZ.addAssign(aZ({bufferMap:d,influence:s,stride:h,width:p,depth:t,offset:eO(1)}))})}),aT(({object:e})=>{let{base:t,influences:r}=a;e.geometry.morphTargetsRelative?t.value=1:t.value=1-e.morphTargetInfluences.reduce((e,t)=>e+t,0),r&&(r.array=e.morphTargetInfluences,r.update())})},"void");class a0 extends O{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}}class a1 extends a0{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class a2 extends r7{static get type(){return"LightingContextNode"}constructor(e,t=null,r=[],i=null,s=null){super(e),this.lightingModel=t,this.materialLightings=r,this.backdropNode=i,this.backdropAlphaNode=s,this._value=null}getContext(){let{materialLightings:e,backdropNode:t,backdropAlphaNode:r}=this,i=eW().toVar("directDiffuse"),s=eW().toVar("directSpecular"),n=eW().toVar("indirectDiffuse"),a=eW().toVar("indirectSpecular");return{radiance:eW().toVar("radiance"),irradiance:eW().toVar("irradiance"),iblIrradiance:eW().toVar("iblIrradiance"),ambientOcclusion:eD(1).toVar("ambientOcclusion"),reflectedLight:{directDiffuse:i,directSpecular:s,indirectDiffuse:n,indirectSpecular:a},materialLightings:e,backdrop:t,backdropAlpha:r}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}let a3=eE(a2);class a4 extends a0{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let a8=new u.I9Y;class a5 extends i1{static get type(){return"ViewportTextureNode"}constructor(e=ss,t=null,r=null){let i=null;null===r?((i=new u.Pem).minFilter=u.$_I,r=i):i=r,super(r,e,t),this.generateMipmaps=!1,this.defaultFramebuffer=i,this.isOutputTextureNode=!0,this.updateBeforeType=B.RENDER,this._cacheTextures=new WeakMap}getTextureForReference(e=null){let t,r;if(this.referenceNode?(t=this.referenceNode.defaultFramebuffer,r=this.referenceNode._cacheTextures):(t=this.defaultFramebuffer,r=this._cacheTextures),null===e)return t;if(!1===r.has(e)){let i=t.clone();r.set(e,i)}return r.get(e)}updateReference(e){let t=e.renderer,r=t.getRenderTarget(),i=t.getCanvasTarget();return this.value=this.getTextureForReference(r||i),this.value}updateBefore(e){let t=e.renderer,r=t.getRenderTarget(),i=t.getCanvasTarget(),s=r||i;null===s?t.getDrawingBufferSize(a8):s.getDrawingBufferSize?s.getDrawingBufferSize(a8):a8.set(s.width,s.height);let n=this.getTextureForReference(s);(n.image.width!==a8.width||n.image.height!==a8.height)&&(n.image.width=a8.width,n.image.height=a8.height,n.needsUpdate=!0);let a=n.generateMipmaps;n.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(n),n.generateMipmaps=a}clone(){let e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}let a6=eE(a5,null,null,{generateMipmaps:!0}).setParameterLength(0,3),a9=a6(),a7=null;class oe extends a5{static get type(){return"ViewportDepthTextureNode"}constructor(e=ss,t=null,r=null){null===r&&(null===a7&&(a7=new u.VCu),r=a7),super(e,t,r)}}let ot=eE(oe).setParameterLength(0,3);class or extends O{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){let{scope:t}=this;return t===or.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){let{scope:t}=this,r=this.valueNode,i=null;return t===or.DEPTH_BASE?null!==r&&(i=ol().assign(r)):t===or.DEPTH?i=e.isPerspectiveCamera?on(sq.z,sv,sS):oi(sq.z,sv,sS):t===or.LINEAR_DEPTH&&(i=null!==r?e.isPerspectiveCamera?oi(oa(r,sv,sS),sv,sS):r:oi(sq.z,sv,sS)),i}}or.DEPTH_BASE="depthBase",or.DEPTH="depth",or.LINEAR_DEPTH="linearDepth";let oi=(e,t,r)=>e.add(t).div(t.sub(r)),os=eF(([e,t,r],i)=>!0===i.renderer.reversedDepthBuffer?r.sub(t).mul(e).sub(r):t.sub(r).mul(e).sub(t)),on=(e,t,r)=>t.add(e).mul(r).div(r.sub(t).mul(e)),oa=eF(([e,t,r],i)=>!0===i.renderer.reversedDepthBuffer?t.mul(r).div(t.sub(r).mul(e).sub(t)):t.mul(r).div(r.sub(t).mul(e).sub(r))),oo=(e,t,r)=>{t=t.max(1e-6).toVar();let i=rl(e.negate().div(t)),s=rl(r.div(t));return i.div(s)},ol=eE(or,or.DEPTH_BASE),ou=eC(or,or.DEPTH),od=eE(or,or.LINEAR_DEPTH).setParameterLength(0,1);ot(),ou.assign=e=>ol(e);class oh extends O{static get type(){return"ClippingNode"}constructor(e=oh.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);let{intersectionPlanes:t,unionPlanes:r}=e.clippingContext;return(this.hardwareClipping=e.hardwareClipping,this.scope===oh.ALPHA_TO_COVERAGE)?this.setupAlphaToCoverage(t,r):this.scope===oh.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(t,r)}setupAlphaToCoverage(e,t){return eF(()=>{let r=eD().toVar("distanceToPlane"),i=eD().toVar("distanceToGradient"),s=eD(1).toVar("clipOpacity"),n=t.length;if(!1===this.hardwareClipping&&n>0){let e=i7(t).setGroup(tE);aX(n,({i:t})=>{let n=e.element(t);r.assign(sq.dot(n.xyz).negate().add(n.w)),i.assign(r.fwidth().div(2)),s.mulAssign(r4(i.negate(),i,r))})}let a=e.length;if(a>0){let t=i7(e).setGroup(tE),n=eD(1).toVar("intersectionClipOpacity");aX(a,({i:e})=>{let s=t.element(e);r.assign(sq.dot(s.xyz).negate().add(s.w)),i.assign(r.fwidth().div(2)),n.mulAssign(r4(i.negate(),i,r).oneMinus())}),s.mulAssign(n.oneMinus())}e4.a.mulAssign(s),e4.a.equal(0).discard()})()}setupDefault(e,t){return eF(()=>{let r=t.length;if(!1===this.hardwareClipping&&r>0){let e=i7(t).setGroup(tE);aX(r,({i:t})=>{let r=e.element(t);sq.dot(r.xyz).greaterThan(r.w).discard()})}let i=e.length;if(i>0){let t=i7(e).setGroup(tE),r=eV(!0).toVar("clipped");aX(i,({i:e})=>{let i=t.element(e);r.assign(sq.dot(i.xyz).greaterThan(i.w).and(r))}),r.discard()}})()}setupHardwareClipping(e,t){let r=e.length;return t.enableHardwareClipping(r),eF(()=>{let i=i7(e).setGroup(tE),s=st(t.getClipDistance());aX(r,({i:e})=>{let t=i.element(e),r=sq.dot(t.xyz).sub(t.w).negate();s.element(e).assign(r)})})()}}oh.ALPHA_TO_COVERAGE="alphaToCoverage",oh.DEFAULT="default",oh.HARDWARE="hardware";let oc=eF(([e])=>rm(tV(1e4,rg(tV(17,e.x).add(tV(.1,e.y)))).mul(tO(.1,rE(rg(tV(13,e.y).add(e.x))))))),op=eF(([e])=>oc(eG(oc(e.xy),e.z))),om=eF(([e])=>{let t=rz(rw(rF(e.xyz)),rw(rL(e.xyz))),r=eD(1).div(eD(.05).mul(t)).toVar("pixScale"),i=eG(ra(rh(rl(r))),ra(rc(rl(r)))),s=eG(op(rh(i.x.mul(e.xyz))),op(rh(i.y.mul(e.xyz)))),n=rm(rl(r)),a=tO(tV(n.oneMinus(),s.x),tV(n,s.y)),o=rk(n,n.oneMinus()),l=eW(a.mul(a).div(tV(2,o).mul(tI(1,o))),a.sub(tV(.5,o)).div(tI(1,o)),tI(1,tI(1,a).mul(tI(1,a)).div(tV(2,o).mul(tI(1,o)))));return r1(a.lessThan(o.oneMinus()).select(a.lessThan(o).select(l.x,l.y),l.z),1e-6,1)}).setLayout({name:"getAlphaHashThreshold",type:"float",inputs:[{name:"position",type:"vec3"}]});class og extends iq{static get type(){return"VertexColorNode"}constructor(e){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){let e=this.index;return"color"+(e>0?e:"")}generate(e){let t=this.getAttributeName(e);return!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new u.IUQ(1,1,1,1))}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}class of extends u.imn{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.fog=!0,this.lights=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.maskNode=null,this.maskShadowNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.receivedShadowPositionNode=null,this.castShadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null,this.contextNode=null}_getNodeChildren(){let e=[];for(let t of Object.getOwnPropertyNames(this)){if(!0===t.startsWith("_"))continue;let r=this[t];r&&!0===r.isNode&&e.push({property:t,childNode:r})}return e}customProgramCacheKey(){let e=[];for(let{property:t,childNode:r}of this._getNodeChildren())e.push(x(t.slice(0,-4)),r.getCacheKey());return this.type+T(e)}build(e){this.setup(e)}setupObserver(e){return new g(e)}setup(e){let t;e.context.setupNormal=()=>ia(this.setupNormal(e),"NORMAL","vec3"),e.context.setupPositionView=()=>this.setupPositionView(e),e.context.setupModelViewProjection=()=>this.setupModelViewProjection(e);let r=e.renderer,i=r.getRenderTarget();e.addStack();let s=this.setupVertex(e),n=ia(this.vertexNode||s,"VERTEX");e.context.clipSpace=n,e.stack.outputNode=n,this.setupHardwareClipping(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();let a=this.setupClipping(e);if((!0===this.depthWrite||!0===this.depthTest)&&(null!==i?!0===i.depthBuffer&&this.setupDepth(e):!0===r.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupAmbientOcclusion(e),this.setupVariants(e);let s=this.setupLighting(e);null!==a&&e.stack.addToStack(a);let n=eX(s,e4.a).max(0);t=this.setupOutput(e,n),tm.assign(t);let o=null!==this.outputNode;if(o&&(t=this.outputNode),e.context.getOutput&&(t=e.context.getOutput(t,e)),null!==i){let e=r.getMRT(),i=this.mrtNode;null!==e?(o&&tm.assign(t),t=e,null!==i&&(t=e.merge(i))):null!==i&&(t=i)}}else{let r=this.fragmentNode;!0!==r.isOutputStructNode&&(r=r.convert(e.getOutputType())),t=this.setupOutput(e,r)}e.stack.outputNode=t,e.addFlow("fragment",e.removeStack()),e.observer=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;let{unionPlanes:t,intersectionPlanes:r}=e.clippingContext,i=null;if(t.length>0||r.length>0){let t=e.renderer.currentSamples;this.alphaToCoverage&&t>1?i=new oh(oh.ALPHA_TO_COVERAGE):e.stack.addToStack(new oh)}return i}setupHardwareClipping(e){if(e.hardwareClipping=!1,null===e.clippingContext)return;let t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.addToStack(new oh(oh.HARDWARE)),e.hardwareClipping=!0)}setupDepth(e){let{renderer:t,camera:r}=e,i=this.depthNode;if(null===i){let e=t.getMRT();e&&e.has("depth")?i=e.get("depth"):!0===t.logarithmicDepthBuffer&&(i=r.isPerspectiveCamera?oo(sq.z,sv,sS):oi(sq.z,sv,sS))}null!==i&&ou.assign(i).toStack()}setupPositionView(){return sD.mul(sz).xyz}setupModelViewProjection(){return sR.mul(sq)}setupVertex(e){return e.addStack(),this.setupPosition(e),e.context.position=e.removeStack(),ab}setupPosition(e){let{object:t,geometry:r}=e;if((r.morphAttributes.position||r.morphAttributes.normal||r.morphAttributes.color)&&aJ(t),!0===t.isSkinnedMesh&&aq(t),this.displacementMap){let e=nc("displacementMap","texture"),t=nc("displacementScale","float"),r=nc("displacementBias","float");sz.addAssign(sZ.normalize().mul(e.x.mul(t).add(r)))}return t.isBatchedMesh&&aV(t),t.isInstancedMesh&&t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&aF(t),null!==this.positionNode&&sz.assign(ia(this.positionNode,"POSITION","vec3")),sz}setupDiffuseColor(e){let{object:t,geometry:r}=e;null!==this.maskNode&&eV(this.maskNode).not().discard();let i=this.colorNode?eX(this.colorNode):n$;!0===this.vertexColors&&r.hasAttribute("color")&&(i=i.mul(((e=0)=>new og(e))())),t.instanceColor&&(i=aB.mul(i)),t.isBatchedMesh&&t._colorsTexture&&(i=aO.mul(i)),e4.assign(i);let s=this.opacityNode?eD(this.opacityNode):nq;e4.a.assign(e4.a.mul(s));let n=null;(null!==this.alphaTestNode||this.alphaTest>0)&&(n=null!==this.alphaTestNode?eD(this.alphaTestNode):nz,!0===this.alphaToCoverage?(e4.a=r4(n,n.add(rO(e4.a)),e4.a),e4.a.lessThanEqual(0).discard()):e4.a.lessThanEqual(n).discard()),!0===this.alphaHash&&e4.a.lessThan(om(sz)).discard(),e.isOpaque()&&e4.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?eW(0):e4.rgb}setupNormal(){return this.normalNode?eW(this.normalNode):n0}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?nc("envMap","cubeTexture"):nc("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new a4(am)),t}setupMaterialLightings(e){let t=[],r=this.setupEnvironment(e);r&&r.isLightingNode&&t.push(r);let i=this.setupLightMap(e);if(i&&i.isLightingNode&&t.push(i),e.context.ambientOcclusion&&t.push(new a1(e.context.ambientOcclusion)),e.context.getGI){let r=e.context.getGI(null,e);null!==r&&t.push(new a4(r))}return t}setupAmbientOcclusion(e){let t=this.aoNode;null===t&&e.material.aoMap&&(t=ag),e.context.getAO&&(t=e.context.getAO(t,e)),null!==t&&(tR.assign(t),e.context.ambientOcclusion=tR)}setupLightingModel(){}setupLighting(e){let{material:t}=e,{backdropNode:r,backdropAlphaNode:i,emissiveNode:s}=this,n=!0===this.lights&&e.renderer.lighting.enabled,a=n||null!==this.lightsNode,o=n?this.setupMaterialLightings(e):[],l=a?this.lightsNode||e.lightsNode:null,u=this.setupOutgoingLight(e);return l&&(o.length>0||l.getScope().hasLights)?u=a3(l,this.setupLightingModel(e)||null,o,r,i):null!==r&&(u=eW(null!==i?r0(u,r,i):r)),(s&&!0===s.isNode||t.emissive&&!0===t.emissive.isColor)&&(e5.assign(eW(s||nH)),u=u.add(e5)),u}setupFog(e,t){let r=e.fogNode;return r&&(tm.assign(t),t=eX(r.toVar())),t}setupPremultipliedAlpha(e,t){return iV(t)}setupOutput(e,t){return!0===this.fog&&(t=this.setupFog(e,t)),!0===this.premultipliedAlpha&&(t=this.setupPremultipliedAlpha(e,t)),t}setDefaultValues(e){for(let t in e){let r=e[t];void 0===this[t]&&(this[t]=r,r&&r.clone&&(this[t]=r.clone()))}let t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(let e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){let t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});let r=u.imn.prototype.toJSON.call(this,e);for(let{property:t,childNode:i}of(r.inputNodes={},this._getNodeChildren()))r.inputNodes[t]=i.toJSON(e).uuid;function i(e){let t=[];for(let r in e){let i=e[r];delete i.metadata,t.push(i)}return t}if(t){let t=i(e.textures),s=i(e.images),n=i(e.nodes);t.length>0&&(r.textures=t),s.length>0&&(r.images=s),n.length>0&&(r.nodes=n)}return r}copy(e){let t=Object.getOwnPropertyDescriptors(this.constructor.prototype);for(let r in t)if(void 0!==t[r].set&&void 0!==e[r]){let t=e[r];this[r]&&void 0!==this[r].copy?this[r].copy(t):this[r]=t}for(let t in this)if(!/^(?:is[A-Z]|_)|^(?:id|uuid|version|type|userData|clippingPlanes)$/.test(t)&&void 0!==this[t]&&void 0!==e[t]){let r=e[t];this[t]&&void 0!==this[t].copy?this[t].copy(r):this[t]=r}return this.clippingPlanes=e.clippingPlanes?e.clippingPlanes.map(e=>e.clone()):null,this.userData=JSON.parse(JSON.stringify(e.userData)),this}}let ob=new u.mrM;class oy extends of{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.setDefaultValues(ob),this.setValues(e)}}let ox=new u.Fvt;class oT extends of{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.setDefaultValues(ox),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){let e=this.offsetNode?eD(this.offsetNode):ad,t=this.dashScaleNode?eD(this.dashScaleNode):aa,r=this.dashSizeNode?eD(this.dashSizeNode):ao,i=this.gapSizeNode?eD(this.gapSizeNode):al;tg.assign(r),tf.assign(i);let s=il(ij("lineDistance").mul(t));(e?s.add(e):s).mod(tg.add(tf)).greaterThan(tg).discard()}}let o_=e3("vec3","worldStart"),ov=e3("vec3","worldEnd"),oS=e3("float","lineDistance"),oR=e3("vec4","worldPos"),oN=eF(({start:e,end:t})=>{let r=sR.element(2).element(2),i=sR.element(3).element(2);return r.greaterThan(0).select(i.negate().div(r.add(1)),i.mul(-.5).div(r)).sub(e.z).div(t.z.sub(e.z))},{start:"vec4",end:"vec4",return:"float"}),oA=eF(({p1:e,p2:t,p3:r,p4:i})=>{let s=e.sub(r),n=i.sub(r),a=t.sub(e),o=s.dot(n),l=n.dot(a),u=s.dot(a),d=n.dot(n),h=a.dot(a).mul(d).sub(l.mul(l)),c=o.mul(l).sub(u.mul(d)).div(h).clamp(),p=o.add(l.mul(c)).div(d).clamp();return eG(c,p)},{p1:"vec3",p2:"vec3",p3:"vec3",p4:"vec3",return:"vec2"});eF(({material:e})=>{let t,r,i=e._useDash,s=e._useWorldUnits,n=ij("instanceStart"),a=ij("instanceEnd"),o=eX(sD.mul(eX(n,1))).toVar("start"),l=eX(sD.mul(eX(a,1))).toVar("end");i&&(t=eD(ij("instanceDistanceStart")).toVar("distanceStart"),r=eD(ij("instanceDistanceEnd")).toVar("distanceEnd")),s&&(o_.assign(o.xyz),ov.assign(l.xyz));let u=so.z.div(so.w);if(eU(sR.element(2).element(3).equal(-1),()=>{eU(o.z.lessThan(0).and(l.z.greaterThan(0)),()=>{let e=oN({start:o,end:l});l.assign(eX(r0(o.xyz,l.xyz,e),l.w)),i&&r.assign(r0(t,r,e))}).ElseIf(l.z.lessThan(0).and(o.z.greaterThanEqual(0)),()=>{let e=oN({start:l,end:o});o.assign(eX(r0(l.xyz,o.xyz,e),o.w)),i&&t.assign(r0(r,t,e))})}),i){let i=e.dashScaleNode?eD(e.dashScaleNode):aa,s=e.offsetNode?eD(e.offsetNode):ad,n=sk.y.lessThan(.5).select(i.mul(t),i.mul(r));n=n.add(s),oS.assign(n)}let d=sR.mul(o),h=sR.mul(l),c=d.xyz.div(d.w),p=h.xyz.div(h.w),m=p.xy.sub(c.xy).toVar();m.x.assign(m.x.mul(u)),m.assign(m.normalize());let g=eX().toVar();if(s){let e=l.xyz.sub(o.xyz).normalize(),t=r0(o.xyz,l.xyz,.5).normalize(),r=e.cross(t).normalize(),s=e.cross(r);oR.assign(sk.y.lessThan(.5).select(o,l));let n=au.mul(.5);oR.addAssign(eX(sk.x.lessThan(0).select(r.mul(n),r.mul(n).negate()),0)),i||(oR.addAssign(eX(sk.y.lessThan(.5).select(e.mul(n).negate(),e.mul(n)),0)),oR.addAssign(eX(s.mul(n),0)),eU(sk.y.greaterThan(1).or(sk.y.lessThan(0)),()=>{oR.subAssign(eX(s.mul(2).mul(n),0))})),g.assign(sR.mul(oR));let a=eW().toVar();a.assign(sk.y.lessThan(.5).select(c,p)),g.z.assign(a.z.mul(g.w))}else{let e=eG(m.y,m.x.negate()).toVar("offset");m.x.assign(m.x.div(u)),e.x.assign(e.x.div(u)),e.assign(sk.x.lessThan(0).select(e.negate(),e)),eU(sk.y.lessThan(0),()=>{e.assign(e.sub(m))}).ElseIf(sk.y.greaterThan(1),()=>{e.assign(e.add(m))}),e.assign(e.mul(au)),e.assign(e.div(so.w.div(si))),g.assign(sk.y.lessThan(.5).select(d,h)),e.assign(e.mul(g.w)),g.assign(g.add(eX(e,0,0)))}return g})(),eF(({material:e,renderer:t})=>{let r=e._useAlphaToCoverage,i=e._useDash,s=e._useWorldUnits,n=iX();if(i){let t=e.dashSizeNode?eD(e.dashSizeNode):ao,r=e.gapSizeNode?eD(e.gapSizeNode):al;tg.assign(t),tf.assign(r),n.y.lessThan(-1).or(n.y.greaterThan(1)).discard(),oS.mod(tg.add(tf)).greaterThan(tg).discard()}let a=eD(1).toVar("alpha");if(s){let e=oR.xyz.normalize().mul(1e5),s=ov.sub(o_),n=oA({p1:o_,p2:ov,p3:eW(0,0,0),p4:e}),o=o_.add(s.mul(n.x)),l=e.mul(n.y),u=o.sub(l).length().div(au);if(!i)if(r&&t.currentSamples>0){let e=u.fwidth();a.assign(r4(e.negate().add(.5),e.add(.5),u).oneMinus())}else u.greaterThan(.5).discard()}else if(r&&t.currentSamples>0){let e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1)),r=e.mul(e).add(t.mul(t)),i=eD(r.fwidth()).toVar("dlen");eU(n.y.abs().greaterThan(1),()=>{a.assign(r4(i.oneMinus(),i.add(1),r).oneMinus())})}else eU(n.y.abs().greaterThan(1),()=>{let e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()});return a})();let oE=new u.qBx;class oC extends of{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(oE),this.setValues(e)}setupDiffuseColor(){let e=this.opacityNode?eD(this.opacityNode):nq;e4.assign(ip(eX(eS(s2).mul(.5).add(.5),e),u.er$))}}let ow=eF(([e=sH])=>eG(e.z.atan(e.x).mul(1/(2*Math.PI)).add(.5),e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5))),oB=eF(([e=iX()])=>{let t=e.x.sub(.5).mul(2*Math.PI),r=e.y.sub(.5).mul(Math.PI),i=r.cos(),s=i.mul(t.cos());return eW(s,r.sin(),i.mul(t.sin()))});class oM extends u.O0B{constructor(e=1,t={}){super(e,e,t),this.isCubeRenderTarget=!0;let r={width:e,height:e,depth:1};this.texture=new u.b4q([r,r,r,r,r,r]),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){let r=t.minFilter,i=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;let s=new u.iNn(5,5,5),n=ow(sH),a=new of;a.colorNode=i3(t,n,0),a.side=u.hsX,a.blending=u.XIg;let o=new u.eaF(s,a),l=new u.Z58;l.add(o),t.minFilter===u.$_I&&(t.minFilter=u.k6q);let d=new u.F1T(1,10,this),h=e.getMRT();return e.setMRT(null),d.update(e,l),e.setMRT(h),t.minFilter=r,t.generateMipmaps=i,o.geometry.dispose(),o.material.dispose(),this}clear(e,t=!0,r=!0,i=!0){let s=e.getRenderTarget();for(let s=0;s<6;s++)e.setRenderTarget(this,s),e.clear(t,r,i);e.setRenderTarget(s)}}let oF=new WeakMap;class oL extends G{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=nl(null);let t=new u.b4q;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=B.RENDER}updateBefore(e){let{renderer:t,material:r}=e,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){let e=i.isTextureNode?i.value:r[i.property];if(e&&e.isTexture){let r=e.mapping;if(r===u.wfO||r===u.uV5){if(oF.has(e)){let t=oF.get(e);oP(t,e.mapping),this._cubeTexture=t}else{var s;let r=e.image;if(null!=(s=r)&&s.height>0){let i=new oM(r.height);i.fromEquirectangularTexture(t,e),oP(i.texture,e.mapping),this._cubeTexture=i.texture,oF.set(e,i.texture),e.addEventListener("dispose",oU)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function oU(e){let t=e.target;t.removeEventListener("dispose",oU);let r=oF.get(t);void 0!==r&&(oF.delete(t),r.dispose())}function oP(e,t){t===u.wfO?e.mapping=u.hy7:t===u.uV5&&(e.mapping=u.xFO)}let oD=eE(oL).setParameterLength(1);class oO extends a0{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=oD(this.envNode)}}class oI extends a0{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){let t=eD(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class oV{start(e){e.lightsNode.setupLights(e,e.lightsNode.getLightNodes(e)),this.indirect(e)}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class oG extends oV{constructor(){super()}indirect({context:e}){let t=e.ambientOcclusion,r=e.reflectedLight,i=e.irradianceLightMap;r.indirectDiffuse.assign(eX(0)),i?r.indirectDiffuse.addAssign(i):r.indirectDiffuse.addAssign(eX(1,1,1,0)),r.indirectDiffuse.mulAssign(t),r.indirectDiffuse.mulAssign(e4.rgb)}finish(e){let{material:t,context:r}=e,i=r.outgoingLight,s=e.context.environment;if(s)switch(t.combine){case u.caT:i.rgb.assign(r0(i.rgb,i.rgb.mul(s.rgb),nQ.mul(nY)));break;case u.KRh:i.rgb.assign(r0(i.rgb,s.rgb,nQ.mul(nY)));break;case u.XrR:i.rgb.addAssign(s.rgb.mul(nQ.mul(nY)));break;default:(0,u.R8M)("BasicLightingModel: Unsupported .combine value:",t.combine)}}}let ok=new u.V9B;class oz extends of{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(ok),this.setValues(e)}setupNormal(){return sQ(s0)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new oO(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new oI(am)),t}setupOutgoingLight(){return e4.rgb}setupLightingModel(){return new oG}}let o$=eF(({f0:e,f90:t,dotVH:r})=>{let i=r.mul(-5.55473).sub(6.98316).mul(r).exp2();return e.mul(i.oneMinus()).add(t.mul(i))}),oW=eF(e=>e.diffuseColor.mul(1/Math.PI)),oH=eF(({dotNH:e})=>tp.mul(eD(.5)).add(1).mul(eD(1/Math.PI)).mul(e.pow(tp))),oq=eF(({lightDirection:e})=>{let t=e.add(sj).normalize(),r=s2.dot(t).clamp(),i=o$({f0:td,f90:1,dotVH:sj.dot(t).clamp()}),s=eD(.25),n=oH({dotNH:r});return i.mul(s).mul(n)});class oj extends oG{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:r}){let i=s2.dot(e).clamp().mul(t);r.directDiffuse.addAssign(i.mul(oW({diffuseColor:e4.rgb}))),!0===this.specular&&r.directSpecular.addAssign(i.mul(oq({lightDirection:e})).mul(nQ))}indirect(e){let{ambientOcclusion:t,irradiance:r,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(r.mul(oW({diffuseColor:e4}))),i.indirectDiffuse.mulAssign(t)}}let oX=new u.G_z;class oK extends of{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(oX),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new oO(t):null}setupLightingModel(){return new oj(!1)}}let oQ=new u.tXL;class oY extends of{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(oQ),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return t?new oO(t):null}setupLightingModel(){return new oj}setupVariants(){let e=(this.shininessNode?eD(this.shininessNode):nW).max(1e-4);tp.assign(e);let t=this.specularNode||nj;td.assign(t)}}let oZ=eF(e=>{if(!1===e.geometry.hasAttribute("normal"))return eD(0);let t=s0.dFdx().abs().max(s0.dFdy().abs());return t.x.max(t.y).max(t.z)}),oJ=eF(e=>{let{roughness:t}=e,r=oZ(),i=t.max(.0525);return(i=i.add(r)).min(1)}),o0=eF(({alpha:e,dotNL:t,dotNV:r})=>{let i=e.pow2(),s=t.mul(i.add(i.oneMinus().mul(r.pow2())).sqrt()),n=r.mul(i.add(i.oneMinus().mul(t.pow2())).sqrt());return tG(.5,s.add(n).max(t7))}).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),o1=eF(({alphaT:e,alphaB:t,dotTV:r,dotBV:i,dotTL:s,dotBL:n,dotNV:a,dotNL:o})=>{let l=o.mul(eW(e.mul(r),t.mul(i),a).length()),u=a.mul(eW(e.mul(s),t.mul(n),o).length());return tG(.5,l.add(u).max(t7))}).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),o2=eF(({alpha:e,dotNH:t})=>{let r=e.pow2(),i=t.pow2().mul(r.oneMinus()).oneMinus();return r.div(i.pow2()).mul(1/Math.PI)}).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),o3=eD(1/Math.PI),o4=eF(({alphaT:e,alphaB:t,dotNH:r,dotTH:i,dotBH:s})=>{let n=e.mul(t),a=eW(t.mul(i),e.mul(s),n.mul(r)),o=a.dot(a),l=n.div(o);return o3.mul(n.mul(l.pow2()))}).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),o8=eF(({lightDirection:e,f0:t,f90:r,roughness:i,f:s,normalView:n=s2,viewDirection:a=sj,USE_IRIDESCENCE:o,USE_ANISOTROPY:l})=>{let u,d,h=i.pow2(),c=e.add(a).normalize(),p=n.dot(e).clamp(),m=n.dot(a).clamp(),g=n.dot(c).clamp(),f=o$({f0:t,f90:r,dotVH:a.dot(c).clamp()});if(e_(o)&&(f=ti.mix(f,s)),e_(l)){let t=tl.dot(e),r=tl.dot(a),i=tl.dot(c),s=tu.dot(e),n=tu.dot(a),o=tu.dot(c);u=o1({alphaT:ta,alphaB:h,dotTV:r,dotBV:n,dotTL:t,dotBL:s,dotNV:m,dotNL:p}),d=o4({alphaT:ta,alphaB:h,dotNH:g,dotTH:i,dotBH:o})}else u=o0({alpha:h,dotNL:p,dotNV:m}),d=o2({alpha:h,dotNH:g});return f.mul(u).mul(d)}),o5=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]),o6=null,o9=eF(({roughness:e,dotNV:t})=>{null===o6&&((o6=new u.GYF(o5,16,16,u.paN,u.ix0)).name="DFG_LUT",o6.minFilter=u.k6q,o6.magFilter=u.k6q,o6.wrapS=u.ghU,o6.wrapT=u.ghU,o6.generateMipmaps=!1,o6.needsUpdate=!0);let r=eG(e,t);return i3(o6,r).rg}),o7=eF(e=>{let{dotNV:t,specularColor:r,specularF90:i,roughness:s}=e,n=o9({dotNV:t,roughness:s});return r.mul(n.x).add(i.mul(n.y))}),le=eF(({f:e,f90:t,dotVH:r})=>{let i=r.oneMinus().saturate(),s=i.mul(i),n=i.mul(s,s).clamp(0,.9999);return e.sub(eW(t).mul(n)).div(n.oneMinus())}).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),lt=eF(({roughness:e,dotNH:t})=>{let r=e.pow2(),i=eD(1).div(r),s=t.pow2().oneMinus().max(.0078125);return eD(2).add(i).mul(s.pow(i.mul(.5))).div(2*Math.PI)}).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),lr=eF(({dotNV:e,dotNL:t})=>eD(1).div(eD(4).mul(t.add(e).sub(t.mul(e)))).clamp()).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),li=eF(({lightDirection:e})=>{let t=e.add(sj).normalize(),r=s2.dot(e).clamp(),i=s2.dot(sj).clamp(),s=lt({roughness:tr,dotNH:s2.dot(t).clamp()}),n=lr({dotNV:i,dotNL:r});return tt.mul(s).mul(n)}),ls=eF(({N:e,V:t,roughness:r})=>{let i=eG(r,e.dot(t).saturate().oneMinus().sqrt());return i.assign(i.mul(.984375).add(.0078125)),i}).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),ln=eF(({f:e})=>{let t=e.length();return rz(t.mul(t).add(e.z).div(t.add(1)),0)}).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),la=eF(({v1:e,v2:t})=>{let r=e.dot(t),i=r.abs().toVar(),s=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),n=i.add(4.1616724).mul(i).add(3.417594).toVar(),a=s.div(n),o=r.greaterThan(0).select(a,rz(r.mul(r).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(a));return e.cross(t).mul(o)}).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),lo=eF(({N:e,V:t,P:r,mInv:i,p0:s,p1:n,p2:a,p3:o})=>{let l=n.sub(s).toVar(),u=o.sub(s).toVar(),d=l.cross(u),h=eW().toVar();return eU(d.dot(r.sub(s)).greaterThanEqual(0),()=>{let l=t.sub(e.mul(t.dot(e))).normalize(),u=e.cross(l).negate(),d=i.mul(eJ(l,u,e).transpose()).toVar(),c=d.mul(s.sub(r)).normalize().toVar(),p=d.mul(n.sub(r)).normalize().toVar(),m=d.mul(a.sub(r)).normalize().toVar(),g=d.mul(o.sub(r)).normalize().toVar(),f=eW(0).toVar();f.addAssign(la({v1:c,v2:p})),f.addAssign(la({v1:p,v2:m})),f.addAssign(la({v1:m,v2:g})),f.addAssign(la({v1:g,v2:c})),h.assign(eW(ln({f:f})))}),h}).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),ll=1/6,lu=e=>tV(ll,tV(e,tV(e,e.negate().add(3)).sub(3)).add(1)),ld=e=>tV(ll,tV(e,tV(e,tV(3,e).sub(6))).add(4)),lh=e=>tV(ll,tV(e,tV(e,tV(-3,e).add(3)).add(3)).add(1)),lc=e=>tV(ll,rK(e,3)),lp=e=>lu(e).add(ld(e)),lm=e=>lh(e).add(lc(e)),lg=e=>tO(-1,ld(e).div(lu(e).add(ld(e)))),lf=e=>tO(1,lc(e).div(lh(e).add(lc(e)))),lb=(e,t,r)=>{let i=tV(e.uvNode,t.zw).add(.5),s=rh(i),n=rm(i),a=lp(n.x),o=lm(n.x),l=lg(n.x),u=lf(n.x),d=lg(n.y),h=lf(n.y),c=eG(s.x.add(l),s.y.add(d)).sub(.5).mul(t.xy),p=eG(s.x.add(u),s.y.add(d)).sub(.5).mul(t.xy),m=eG(s.x.add(l),s.y.add(h)).sub(.5).mul(t.xy),g=eG(s.x.add(u),s.y.add(h)).sub(.5).mul(t.xy),f=lp(n.y).mul(tO(a.mul(e.sample(c).level(r)),o.mul(e.sample(p).level(r)))),b=lm(n.y).mul(tO(a.mul(e.sample(m).level(r)),o.mul(e.sample(g).level(r))));return f.add(b)},ly=eF(([e,t])=>{let r=eG(e.size(eO(t))),i=eG(e.size(eO(t.add(1)))),s=tG(1,r),n=tG(1,i),a=lb(e,eX(s,r),rh(t)),o=lb(e,eX(n,i),rc(t));return rm(t).mix(a,o)}),lx=eF(([e,t,r,i,s])=>{let n=eW(r3(t.negate(),rp(e),tG(1,i))),a=eW(rw(s[0].xyz),rw(s[1].xyz),rw(s[2].xyz));return rp(n).mul(r.mul(a))}).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),lT=eF(([e,t])=>e.mul(r1(t.mul(2).sub(2),0,1))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),l_=a6(),lv=((e=ss,t=null)=>a9.sample(e,t))(),lS=eF(([e,t,r],{material:i})=>ly((i.side===u.hsX?l_:lv).sample(e.mul(sw.zw).add(sw.xy).div(sn)),rl(sw.z).mul(lT(t,r)))),lR=eF(([e,t,r])=>(eU(r.notEqual(0),()=>rn(ro(t).negate().div(r).negate().mul(e))),eW(1))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),lN=eF(([e,t,r,i,s,n,a,o,l,u,d,h,c,p,m])=>{let g,f;if(m){g=eX().toVar(),f=eW().toVar();let s=d.sub(1).mul(m.mul(.025)),n=eW(d.sub(s),d,d.add(s));aX({start:0,end:3},({i:s})=>{let d=n.element(s),m=lx(e,t,h,d,o),b=a.add(m),y=u.mul(l.mul(eX(b,1))),x=eG(y.xy.div(y.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(eG(x.x,x.y.oneMinus()));let T=lS(x,r,d);g.element(s).assign(T.element(s)),g.a.addAssign(T.a),f.element(s).assign(i.element(s).mul(lR(rw(m),c,p).element(s)))}),g.a.divAssign(3)}else{let s=lx(e,t,h,d,o),n=a.add(s),m=u.mul(l.mul(eX(n,1))),b=eG(m.xy.div(m.w)).toVar();b.addAssign(1),b.divAssign(2),b.assign(eG(b.x,b.y.oneMinus())),g=lS(b,r,d),f=i.mul(lR(rw(s),c,p))}let b=f.rgb.mul(g.rgb),y=eW(o7({dotNV:e.dot(t).clamp(),specularColor:s,specularF90:n,roughness:r})),x=f.r.add(f.g,f.b).div(3);return eX(y.oneMinus().mul(b),g.a.oneMinus().mul(x).oneMinus())}),lA=eJ(3.2404542,-1.5371385,-.4985314,-.969266,1.8760108,.041556,.0556434,-.2040259,1.0572252),lE=(e,t)=>e.sub(t).div(e.add(t)).pow2(),lC=eF(({outsideIOR:e,eta2:t,cosTheta1:r,thinFilmThickness:i,baseF0:s})=>{let n=r0(e,t,r4(0,.03,i)),a=e.div(n).pow2().mul(r.pow2().oneMinus()).oneMinus();eU(a.lessThan(0),()=>eW(1));let o=a.sqrt(),l=o$({f0:lE(n,e),f90:1,dotVH:r}),u=l.oneMinus(),d=n.lessThan(e).select(Math.PI,0),h=eD(Math.PI).sub(d),c=(e=>{let t=e.sqrt();return eW(1).add(t).div(eW(1).sub(t))})(s.clamp(0,.9999)),p=o$({f0:lE(c,n.toVec3()),f90:1,dotVH:o}),m=eW(c.x.lessThan(n).select(Math.PI,0),c.y.lessThan(n).select(Math.PI,0),c.z.lessThan(n).select(Math.PI,0)),g=n.mul(i,o,2),f=eW(h).add(m),b=l.mul(p).clamp(1e-5,.9999),y=b.sqrt(),x=u.pow2().mul(p).div(eW(1).sub(b)),T=l.add(x).toVar(),_=x.sub(u).toVar();return aX({start:1,end:2,condition:"<=",name:"m"},({m:e})=>{_.mulAssign(y);let t=((e,t)=>{let r=e.mul(2*Math.PI*1e-9),i=eW(54856e-17,44201e-17,52481e-17),s=eW(1681e3,1795300,2208400),n=eW(43278e5,93046e5,66121e5),a=eD(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(r.mul(2239900).add(t.x).cos()).mul(r.pow2().mul(-45282e5).exp()),o=i.mul(n.mul(2*Math.PI).sqrt()).mul(s.mul(r).add(t).cos()).mul(r.pow2().negate().mul(n).exp());return o=eW(o.x.add(a),o.y,o.z).div(10685e-11),lA.mul(o)})(eD(e).mul(g),eD(e).mul(f)).mul(2);T.addAssign(_.mul(t))}),T.max(eW(0))}).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),lw=eF(({normal:e,viewDir:t,roughness:r})=>{let i=e.dot(t).saturate(),s=r.mul(r),n=r.add(.1).reciprocal(),a=eD(-1.9362).add(r.mul(1.0678)).add(s.mul(.4573)).sub(n.mul(.8469)),o=eD(-.6014).add(r.mul(.5538)).sub(s.mul(.467)).sub(n.mul(.1255));return a.mul(i).add(o).exp().saturate()}),lB=eW(.04),lM=eD(1);class lF extends oV{constructor(e=!1,t=!1,r=!1,i=!1,s=!1,n=!1,a=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=r,this.anisotropy=i,this.transmission=s,this.dispersion=n,this.retroreflection=a,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0Dielectric=null,this.iridescenceF0Metallic=null,this.dfg=null,this.multiScatteringCompensation=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=eW().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=eW().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=eW().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=eW().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=eW().toVar("sheenSpecularIndirect")),!0===this.iridescence){let e=s2.dot(sj).clamp(),t=lC({outsideIOR:eD(1),eta2:ts,cosTheta1:e,thinFilmThickness:tn,baseF0:td}),r=lC({outsideIOR:eD(1),eta2:ts,cosTheta1:e,thinFilmThickness:tn,baseF0:e4.rgb});this.iridescenceFresnel=r0(t,r,e9),this.iridescenceF0Dielectric=le({f:t,f90:1,dotVH:e}),this.iridescenceF0Metallic=le({f:r,f90:1,dotVH:e})}if(!0===this.transmission){let t=sC.sub(sW).normalize(),r=e.context;r.backdrop=lN(s3,t,e6,e8,th,tc,sW,sU,sA,sR,tb,tx,t_,tT,this.dispersion?tv:null),r.backdropAlpha=ty,e4.a.mulAssign(r0(1,r.backdrop.a,ty))}let t=s2.dot(sj).clamp();this.dfg=o9({roughness:e6,dotNV:t}).toConst("dfg");let r=this.dfg.x.add(this.dfg.y);this.multiScatteringCompensation=th.mul(r.reciprocal().sub(1)).add(1).toConst("multiScatteringCompensation"),super.start(e)}computeMultiscattering(e,t,r,i,s=null){let n=this.dfg,a=s?ti.mix(i,s):i,o=a.mul(n.x).add(r.mul(n.y)),l=n.x.add(n.y).oneMinus(),u=a.add(a.oneMinus().mul(.047619)),d=o.mul(u).div(l.mul(u).oneMinus());e.addAssign(o),t.addAssign(d.mul(l))}direct({lightDirection:e,lightColor:t,reflectedLight:r}){let i=s2.dot(e).clamp().mul(t).toVar();if(!0===this.sheen){this.sheenSpecularDirect.addAssign(i.mul(li({lightDirection:e})));let t=lw({normal:s2,viewDir:sj,roughness:tr}),r=lw({normal:s2,viewDir:e,roughness:tr}),s=tt.r.max(tt.g).max(tt.b).mul(t.max(r)).oneMinus();i.mulAssign(s)}if(!0===this.clearcoat){let r=s4.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(r.mul(o8({lightDirection:e,f0:lB,f90:lM,roughness:te,normalView:s4})))}let s=e.add(sj).normalize(),n=o$({f0:td,f90:tc,dotVH:sj.dot(s).clamp()}),a=o8({lightDirection:e,f0:th,f90:1,roughness:e6,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy});if(!0===this.retroreflection){let t=sj.negate().reflect(s2),r=e.add(t).normalize(),i=o$({f0:td,f90:tc,dotVH:t.dot(r).clamp()}),s=o8({lightDirection:e,viewDirection:t,f0:th,f90:1,roughness:e6,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy});n=r0(n,i,tS.clamp()),a=r0(a,s,tS.clamp())}r.directDiffuse.addAssign(i.mul(oW({diffuseColor:e8})).mul(n.oneMinus())),r.directSpecular.addAssign(i.mul(a).mul(this.multiScatteringCompensation))}directRectArea({lightColor:e,lightPosition:t,halfWidth:r,halfHeight:i,reflectedLight:s,ltc_1:n,ltc_2:a}){let o=t.add(r).sub(i),l=t.sub(r).sub(i),u=t.sub(r).add(i),d=t.add(r).add(i),h=sq.toVar(),c=ls({N:s2,V:sj,roughness:e6}),p=n.sample(c).toVar(),m=a.sample(c).toVar(),g=eJ(eW(p.x,0,p.y),eW(0,1,0),eW(p.z,0,p.w)).toVar(),f=th.mul(m.x).add(tc.sub(th).mul(m.y)).toVar();if(s.directSpecular.addAssign(e.mul(f).mul(lo({N:s2,V:sj,P:h,mInv:g,p0:o,p1:l,p2:u,p3:d}))),s.directDiffuse.addAssign(e.mul(e8).mul(lo({N:s2,V:sj,P:h,mInv:eJ(1,0,0,0,1,0,0,0,1),p0:o,p1:l,p2:u,p3:d}))),!0===this.clearcoat){let t=ls({N:s4,V:sj,roughness:te}),r=n.sample(t),i=a.sample(t),s=eJ(eW(r.x,0,r.y),eW(0,1,0),eW(r.z,0,r.w)),c=lB.mul(i.x).add(lM.sub(lB).mul(i.y));this.clearcoatSpecularDirect.addAssign(e.mul(c).mul(lo({N:s4,V:sj,P:h,mInv:s,p0:o,p1:l,p2:u,p3:d})))}}indirect(e){this.indirectDiffuse(e),this.indirectSpecular(e),this.ambientOcclusion(e)}indirectDiffuse(e){let{irradiance:t,reflectedLight:r}=e.context,i=eW().toVar(),s=eW().toVar();this.computeMultiscattering(i,s,tc,td,this.iridescenceF0Dielectric);let n=t.mul(oW({diffuseColor:e8})).mul(i.add(s).oneMinus()).toVar();if(!0===this.sheen){let e=lw({normal:s2,viewDir:sj,roughness:tr});this.sheenSpecularIndirect.addAssign(t.mul(tt,e,1/Math.PI));let r=tt.r.max(tt.g).max(tt.b).mul(e).oneMinus();n.mulAssign(r)}r.indirectDiffuse.addAssign(n)}indirectSpecular(e){let{radiance:t,iblIrradiance:r,reflectedLight:i}=e.context;if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(r.mul(tt,lw({normal:s2,viewDir:sj,roughness:tr}),1/Math.PI)),!0===this.clearcoat){let e=o7({dotNV:s4.dot(sj).clamp(),specularColor:lB,specularF90:lM,roughness:te});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}let s=eW().toVar("singleScatteringDielectric"),n=eW().toVar("multiScatteringDielectric"),a=eW().toVar("singleScatteringMetallic"),o=eW().toVar("multiScatteringMetallic");this.computeMultiscattering(s,n,tc,td,this.iridescenceF0Dielectric),this.computeMultiscattering(a,o,tc,e4.rgb,this.iridescenceF0Metallic);let l=r0(s,a,e9),u=r0(n,o,e9),d=s.add(n),h=e8.mul(d.oneMinus()),c=r.mul(1/Math.PI),p=t.mul(l).add(u.mul(c)).toVar(),m=h.mul(c).toVar();if(!0===this.sheen){let e=lw({normal:s2,viewDir:sj,roughness:tr}),t=tt.r.max(tt.g).max(tt.b).mul(e).oneMinus();p.mulAssign(t),m.mulAssign(t)}i.indirectSpecular.addAssign(p),i.indirectDiffuse.addAssign(m)}ambientOcclusion(e){let{ambientOcclusion:t,reflectedLight:r}=e.context,i=s2.dot(sj).clamp().add(t),s=e6.mul(-16).oneMinus().negate().exp2(),n=t.sub(i.pow(s).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(t),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(t),r.indirectDiffuse.mulAssign(t),r.indirectSpecular.mulAssign(n)}finish({context:e}){let{outgoingLight:t}=e;if(!0===this.clearcoat){let e=o$({dotVH:s4.dot(sj).clamp(),f0:lB,f90:lM}),r=t.mul(e7.mul(e).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(e7));t.assign(r)}if(!0===this.sheen){let e=t.add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(e)}}}let lL=eD(1),lU=eD(-2),lP=eD(.8),lD=eD(-1),lO=eD(.4),lI=eD(2),lV=eD(.305),lG=eD(3),lk=eD(.21),lz=eD(4),l$=eD(4),lW=eD(16),lH=eF(([e])=>{let t=eW(rE(e)).toVar(),r=eD(-1).toVar();return eU(t.x.greaterThan(t.z),()=>{eU(t.x.greaterThan(t.y),()=>{r.assign(r9(e.x.greaterThan(0),0,3))}).Else(()=>{r.assign(r9(e.y.greaterThan(0),1,4))})}).Else(()=>{eU(t.z.greaterThan(t.y),()=>{r.assign(r9(e.z.greaterThan(0),2,5))}).Else(()=>{r.assign(r9(e.y.greaterThan(0),1,4))})}),r}).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),lq=eF(([e,t])=>{let r=eG().toVar();return eU(t.equal(0),()=>{r.assign(eG(e.z,e.y).div(rE(e.x)))}).ElseIf(t.equal(1),()=>{r.assign(eG(e.x.negate(),e.z.negate()).div(rE(e.y)))}).ElseIf(t.equal(2),()=>{r.assign(eG(e.x.negate(),e.y).div(rE(e.z)))}).ElseIf(t.equal(3),()=>{r.assign(eG(e.z.negate(),e.y).div(rE(e.x)))}).ElseIf(t.equal(4),()=>{r.assign(eG(e.x.negate(),e.z).div(rE(e.y)))}).Else(()=>{r.assign(eG(e.x,e.y).div(rE(e.z)))}),tV(.5,r.add(1))}).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),lj=eF(([e])=>{let t=eD(0).toVar();return eU(e.greaterThanEqual(lP),()=>{t.assign(lL.sub(e).mul(lD.sub(lU)).div(lL.sub(lP)).add(lU))}).ElseIf(e.greaterThanEqual(lO),()=>{t.assign(lP.sub(e).mul(lI.sub(lD)).div(lP.sub(lO)).add(lD))}).ElseIf(e.greaterThanEqual(lV),()=>{t.assign(lO.sub(e).mul(lG.sub(lI)).div(lO.sub(lV)).add(lI))}).ElseIf(e.greaterThanEqual(lk),()=>{t.assign(lV.sub(e).mul(lz.sub(lG)).div(lV.sub(lk)).add(lG))}).Else(()=>{t.assign(eD(-2).mul(rl(tV(1.16,e))))}),t}).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),lX=eF(([e,t,r,i,s,n])=>{let a=eD(r),o=eW(t),l=r1(lj(a),lU,n),u=rm(l),d=rh(l),h=eW(lK(e,o,d,i,s,n)).toVar();return eU(u.notEqual(0),()=>{let t=eW(lK(e,o,d.add(1),i,s,n)).toVar();h.assign(r0(h,t,u))}),h}),lK=eF(([e,t,r,i,s,n])=>{let a=eD(r).toVar(),o=eW(t),l=eD(lH(o)).toVar(),u=eD(rz(l$.sub(a),0)).toVar();a.assign(rz(a,l$));let d=eD(ra(a)).toVar(),h=eG(lq(o,l).mul(d.sub(2)).add(1)).toVar();return eU(l.greaterThan(2),()=>{h.y.addAssign(d),l.subAssign(3)}),h.x.addAssign(l.mul(d)),h.x.addAssign(u.mul(tV(3,lW))),h.y.addAssign(tV(4,ra(n).sub(d))),h.x.mulAssign(i),h.y.mulAssign(s),e.sample(h).grad(eG(),eG())}),lQ=eF(({SAMPLES:e,sigma:t,outputDirection:r,mipInt:i,envMap:s,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:o})=>{let l=eW(0).toVar();return eU(t.equal(0),()=>{l.assign(lK(s,r,i,n,a,o))}).Else(()=>{let u=rp(rX(r9(rE(r.z).lessThan(.999),eW(0,0,1),eW(1,0,0)),r)).toVar(),d=rX(r,u).toVar(),h=rk(t.mul(3),Math.PI),c=rn(h.mul(h).mul(-.5).div(t.mul(t))).oneMinus().toVar(),p=eD(0).toVar();aX({start:eO(0),end:e},({i:h})=>{let m=eD(h).add(.5).div(eD(e)),g=t.mul(ru(ro(m.mul(c).oneMinus()).mul(-2))).toVar(),f=eD(h).mul(2.399963229728653).toVar(),b=u.mul(rb(f)).add(d.mul(rg(f))),y=r.mul(rb(g)).add(b.mul(rg(g))),x=rg(g).div(g).toVar();l.addAssign(lK(s,y,i,n,a,o).mul(x)),p.addAssign(x)}),l.divAssign(p)}),eX(l,1)}),lY=eF(([e])=>{let t=eI(e).toVar();return t.assign(t.shiftLeft(eI(16)).bitOr(t.shiftRight(eI(16)))),t.assign(t.bitAnd(eI(0x55555555)).shiftLeft(eI(1)).bitOr(t.bitAnd(eI(0xaaaaaaaa)).shiftRight(eI(1)))),t.assign(t.bitAnd(eI(0x33333333)).shiftLeft(eI(2)).bitOr(t.bitAnd(eI(0xcccccccc)).shiftRight(eI(2)))),t.assign(t.bitAnd(eI(0xf0f0f0f)).shiftLeft(eI(4)).bitOr(t.bitAnd(eI(0xf0f0f0f0)).shiftRight(eI(4)))),t.assign(t.bitAnd(eI(0xff00ff)).shiftLeft(eI(8)).bitOr(t.bitAnd(eI(0xff00ff00)).shiftRight(eI(8)))),eD(t).mul(23283064365386963e-26)}),lZ=eF(([e,t])=>eG(eD(e).div(eD(t)),lY(e))),lJ=eF(([e,t,r])=>{let i=r.mul(r).toConst(),s=eW(1,0,0).toConst(),n=rX(t,s).toConst(),a=ru(e.x).toConst(),o=tV(2,3.14159265359).mul(e.y).toConst(),l=a.mul(rb(o)).toConst(),u=a.mul(rg(o)).toVar(),d=tV(.5,t.z.add(1)).toConst();u.assign(d.oneMinus().mul(ru(l.mul(l).oneMinus())).add(d.mul(u)));let h=s.mul(l).add(n.mul(u)).add(t.mul(ru(rz(0,l.mul(l).add(u.mul(u)).oneMinus()))));return rp(eW(i.mul(h.x),i.mul(h.y),rz(0,h.z)))}),l0=eF(({roughness:e,mipInt:t,envMap:r,N_immutable:i,GGX_SAMPLES:s,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:o})=>{let l=eW(i).toVar(),u=eW(0).toVar(),d=eD(0).toVar();return eU(e.lessThan(.001),()=>{u.assign(lK(r,l,t,n,a,o))}).Else(()=>{let i=rp(rX(r9(rE(l.z).lessThan(.999),eW(0,0,1),eW(1,0,0)),l)).toVar(),h=rX(l,i).toVar();aX({start:eI(0),end:s},({i:c})=>{let p=lJ(lZ(c,s),eW(0,0,1),e),m=rp(i.mul(p.x).add(h.mul(p.y)).add(l.mul(p.z))),g=rp(m.mul(rj(l,m).mul(2)).sub(l)),f=rz(rj(l,g),0);eU(f.greaterThan(0),()=>{let e=lK(r,g,t,n,a,o);u.addAssign(e.mul(f)),d.addAssign(f)})}),eU(d.greaterThan(0),()=>{u.assign(u.div(d))})}),eX(u,1)}),l1=new u.qUd(-1,1,1,-1,0,1),l2=new u.ubm(90,1),l3=new u.Q1f,l4=null,l8=0,l5=0,l6=new u.Pq0,l9=new u.Pq0,l7=new WeakMap,ue=[3,1,5,0,4,2],ut=ij("outputDirection").normalize();class ur{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._lodMeshes=[],this._blurMaterial=null,this._ggxMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}get _hasInitialized(){return this._renderer.hasInitialized()}fromScene(e,t=0,r=.1,i=100,s={}){let{size:n=256,position:a=l6,renderTarget:o=null}=s;if(this._setSize(n),!1===this._hasInitialized)throw Error('THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Use "await renderer.init();" before using this method.');l4=this._renderer.getRenderTarget(),l8=this._renderer.getActiveCubeFace(),l5=this._renderer.getActiveMipmapLevel();let l=o||this._allocateTarget(!0);return this._init(l),this._sceneToCubeUV(e,r,i,l,a),t>0&&this._blur(l,0,0,t),this._applyPMREM(l),this._cleanup(l),l}async fromSceneAsync(e,t=0,r=.1,i=100,s={}){return(0,u.mcG)('PMREMGenerator: ".fromSceneAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this.fromScene(e,t,r,i,s)}fromEquirectangular(e,t=null){if(!1===this._hasInitialized)throw Error('THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this._fromTexture(e,t)}async fromEquirectangularAsync(e,t=null){return(0,u.mcG)('PMREMGenerator: ".fromEquirectangularAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}fromCubemap(e,t=null){if(!1===this._hasInitialized)throw Error('THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this._fromTexture(e,t)}async fromCubemapAsync(e,t=null){return(0,u.mcG)('PMREMGenerator: ".fromCubemapAsync()" is deprecated. Use "await renderer.init()" instead.'),await this._renderer.init(),this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=un(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=ua(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSizeFromTexture(e){e.mapping===u.hy7||e.mapping===u.xFO?this._setSize(0===e.image.length?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4)}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._ggxMaterial&&this._ggxMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(l4,l8,l5),e.scissorTest=!1,this._setViewport(e,0,0,e.width,e.height)}_fromTexture(e,t){this._setSizeFromTexture(e),l4=this._renderer.getRenderTarget(),l8=this._renderer.getActiveCubeFace(),l5=this._renderer.getActiveMipmapLevel();let r=t||this._allocateTarget(!1);return this._init(r),this._textureToCubeUV(e,r),this._applyPMREM(r),this._cleanup(r),r}_allocateTarget(e){return ui(3*Math.max(this._cubeSize,112),4*this._cubeSize,e)}_init(e){if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==e.width||this._pingPongRenderTarget.height!==e.height){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=ui(e.width,e.height);let{_lodMax:t}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods}=function(e){let t=[],r=[],i=e,s=e-4+1+6;for(let e=0;e<s;e++){let e=Math.pow(2,i);t.push(e);let s=1/(e-2),n=-s,a=1+s,o=[n,n,a,n,a,a,n,n,a,a,n,a],l=new Float32Array(108),d=new Float32Array(108);for(let e=0;e<6;e++){let t=e%3*2/3-1,r=e>2?0:-1,i=[t,r,0,t+2/3,r,0,t+2/3,r+1,0,t,r,0,t+2/3,r+1,0,t,r+1,0],s=ue[e];l.set(i,18*s);for(let e=0;e<6;e++){let t=2*o[2*e]-1,r=2*o[2*e+1]-1;0===s?l9.set(1,r,t):1===s?l9.set(-t,1,-r):2===s?l9.set(-t,r,1):3===s?l9.set(-1,r,-t):4===s?l9.set(-t,-1,r):l9.set(t,r,-1),l9.toArray(d,(6*s+e)*3)}}let h=new u.LoY;h.setAttribute("position",new u.THS(l,3)),h.setAttribute("outputDirection",new u.THS(d,3)),r.push(new u.eaF(h,null)),i>4&&i--}return{lodMeshes:r,sizeLods:t}}(t)),this._blurMaterial=function(e,t,r){let i=i3(),s=tB(0),n=tB(0),a=eD(1/t),o={envMap:i,sigma:s,mipInt:n,CUBEUV_TEXEL_WIDTH:a,CUBEUV_TEXEL_HEIGHT:eD(1/r),CUBEUV_MAX_MIP:eD(e)},l=us("blur");return l.fragmentNode=lQ({...o,outputDirection:ut,SAMPLES:eO(20)}),l7.set(l,o),l}(t,e.width,e.height),this._ggxMaterial=function(e,t,r){let i=i3(),s=tB(0),n=tB(0),a=eD(1/t),o={envMap:i,roughness:s,mipInt:n,CUBEUV_TEXEL_WIDTH:a,CUBEUV_TEXEL_HEIGHT:eD(1/r),CUBEUV_MAX_MIP:eD(e)},l=us("ggx");return l.fragmentNode=l0({...o,N_immutable:ut,GGX_SAMPLES:eI(256)}),l7.set(l,o),l}(t,e.width,e.height)}}async _compileMaterial(e){let t=new u.eaF(new u.LoY,e);await this._renderer.compile(t,l1)}_sceneToCubeUV(e,t,r,i,s){l2.near=t,l2.far=r;let n=[1,1,1,1,-1,1],a=[1,-1,1,-1,1,-1],o=this._renderer,l=o.autoClear;o.getClearColor(l3),o.autoClear=!1,null===this._backgroundBox&&(this._backgroundBox=new u.eaF(new u.iNn,new u.V9B({name:"PMREM.Background",side:u.hsX,depthWrite:!1,depthTest:!1})));let d=this._backgroundBox,h=d.material,c=!1,p=e.background;p?p.isColor&&(h.color.copy(p),e.background=null,c=!0):(h.color.copy(l3),c=!0),o.setRenderTarget(i),o.clear(),c&&o.render(d,l2);for(let t=0;t<6;t++){let r=t%3;0===r?(l2.up.set(0,n[t],0),l2.position.set(s.x,s.y,s.z),l2.lookAt(s.x+a[t],s.y,s.z)):1===r?(l2.up.set(0,0,n[t]),l2.position.set(s.x,s.y,s.z),l2.lookAt(s.x,s.y+a[t],s.z)):(l2.up.set(0,n[t],0),l2.position.set(s.x,s.y,s.z),l2.lookAt(s.x,s.y,s.z+a[t]));let l=this._cubeSize;this._setViewport(i,r*l,t>2?l:0,l,l),o.render(e,l2)}o.autoClear=l,e.background=p}_textureToCubeUV(e,t){let r=this._renderer,i=e.mapping===u.hy7||e.mapping===u.xFO;i?null===this._cubemapMaterial&&(this._cubemapMaterial=un(e)):null===this._equirectMaterial&&(this._equirectMaterial=ua(e));let s=i?this._cubemapMaterial:this._equirectMaterial;s.fragmentNode.value=e;let n=this._lodMeshes[0];n.material=s;let a=this._cubeSize;this._setViewport(t,0,0,3*a,2*a),r.setRenderTarget(t),r.render(n,l1)}_applyPMREM(e){let t=this._renderer,r=t.autoClear;t.autoClear=!1;let i=this._lodMeshes.length;for(let t=1;t<i;t++)this._applyGGXFilter(e,t-1,t);t.autoClear=r}_applyGGXFilter(e,t,r){let i=this._renderer,s=this._pingPongRenderTarget,n=this._ggxMaterial,a=this._lodMeshes[r];a.material=n;let o=l7.get(n),l=r/(this._lodMeshes.length-1),u=t/(this._lodMeshes.length-1),d=Math.sqrt(l*l-u*u),{_lodMax:h}=this,c=this._sizeLods[r],p=3*c*(r>h-4?r-h+4:0),m=4*(this._cubeSize-c);e.texture.frame=(e.texture.frame||0)+1,o.envMap.value=e.texture,o.roughness.value=1.25*l*d,o.mipInt.value=h-t,this._setViewport(s,p,m,3*c,2*c),i.setRenderTarget(s),i.render(a,l1),s.texture.frame=(s.texture.frame||0)+1,o.envMap.value=s.texture,o.roughness.value=0,o.mipInt.value=h-r,this._setViewport(e,p,m,3*c,2*c),i.setRenderTarget(e),i.render(a,l1)}_blur(e,t,r,i){let s=this._pingPongRenderTarget,n=Math.min(i,Math.PI)/Math.SQRT2;this._blurPass(e,s,t,r,n),this._blurPass(s,e,r,r,n)}_blurPass(e,t,r,i,s){let n=this._renderer,a=this._blurMaterial,o=this._lodMeshes[i];o.material=a;let l=l7.get(a);e.texture.frame=(e.texture.frame||0)+1,l.envMap.value=e.texture,l.sigma.value=s,l.mipInt.value=this._lodMax-r;let u=this._sizeLods[i],d=3*u*(i>this._lodMax-4?i-this._lodMax+4:0),h=4*(this._cubeSize-u);this._setViewport(t,d,h,3*u,2*u),n.setRenderTarget(t),n.render(o,l1)}_setViewport(e,t,r,i,s){this._renderer.isWebGLRenderer?(e.viewport.set(t,e.height-s-r,i,s),e.scissor.set(t,e.height-s-r,i,s)):(e.viewport.set(t,r,i,s),e.scissor.set(t,r,i,s))}}function ui(e,t,r){let i={magFilter:u.k6q,minFilter:u.k6q,generateMipmaps:!1,type:u.ix0,format:u.GWd,colorSpace:u.Zr2,depthBuffer:r},s=new u.O0B(e,t,i);return s.texture.mapping=u.Om,s.texture.name="PMREM.cubeUv",s.texture.isPMREMTexture=!0,s.scissorTest=!0,s}function us(e){let t=new of;return t.depthTest=!1,t.depthWrite=!1,t.blending=u.XIg,t.name=`PMREM_${e}`,t}function un(e){let t=us("cubemap");return t.fragmentNode=nl(e,ut),t}function ua(e){let t=us("equirect");return t.fragmentNode=i3(e,ow(ut),0),t}let uo=new WeakMap;class ul extends G{static get type(){return"PMREMNode"}constructor(e,t=null,r=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=r,this._generator=null;let i=new u.gPd;i.isRenderTargetTexture=!0,this._texture=i3(i),this._width=tB(0),this._height=tB(0),this._maxMip=tB(0),this.updateBeforeType=B.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){let t=function(e){let t=Math.log2(e)-2;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:1/e,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(e){let t=this._pmrem,r=t?t.pmremVersion:-1,i=this._value;r!==i.pmremVersion&&null!==(t=!0===i.isPMREMTexture||i.mapping===u.Om?i:function(e,t,r){var i,s;let n,a=(i=t,void 0===(n=uo.get(i))&&(n=new WeakMap,uo.set(i,n)),n),o=a.get(e);if((void 0!==o?o.pmremVersion:-1)!==e.pmremVersion){let t=e.image;if(e.isCubeTexture)if(!function(e){if(null==e)return!1;let t=0;for(let r=0;r<6;r++)void 0!==e[r]&&t++;return 6===t}(t))return null;else o=r.fromCubemap(e,o);else{if(!(null!=(s=t)&&s.height>0))return null;o=r.fromEquirectangular(e,o)}if(o.pmremVersion=e.pmremVersion,!1===a.has(e)){let t=()=>{e.removeEventListener("dispose",t);let r=a.get(e);void 0!==r&&(r.dispose(),a.delete(e))};e.addEventListener("dispose",t)}a.set(e,o)}return o.texture}(i,e.renderer,this._generator))&&(this._pmrem=t,this.updateFromTexture(t))}setup(e){null===this._generator&&(this._generator=new ur(e.renderer)),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this,e)),t=null===this._pmrem||this._pmrem.isRenderTargetTexture?ne.mul(eW(t.x,t.y.negate(),t.z)):ne.mul(t);let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),lX(this._texture,t,r,this._width,this._height,this._maxMip)}dispose(){super.dispose(),null!==this._generator&&this._generator.dispose()}}let uu=eE(ul).setParameterLength(1,3),ud=new WeakMap;class uh extends a0{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){let{material:t}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){let i=r.isTextureNode?r.value:t[r.property],s=this._getPMREMNodeCache(e.renderer),n=s.get(i);void 0===n&&(n=uu(i),s.set(i,n)),r=n}let i=!0===t.useAnisotropy||t.anisotropy>0?nF:s2,s=iU(r.context(uc(e6,i)).mul(s7));if(!0===t.useRetroreflection||t.retroreflectivity>0){let e=iU(r.context(up(e6,i)).mul(s7));s=tS.clamp().mix(s,e)}let n=iU(r.context(um(s3)).mul(Math.PI).mul(s7));e.context.radiance.addAssign(s),e.context.iblIrradiance.addAssign(n);let a=e.context.lightingModel.clearcoatRadiance;if(a){let e=iU(r.context(uc(te,s4)).mul(s7));a.addAssign(e)}}_getPMREMNodeCache(e){let t=ud.get(e);return void 0===t&&(t=new WeakMap,ud.set(e,t)),t}}let uc=(e,t)=>{let r=null;return{getUV:()=>(null===r&&(r=sj.negate().reflect(t),r=(r=rY(e).mix(r,t).normalize()).transformDirection(sE)),r),getTextureLevel:()=>e}},up=(e,t)=>{let r=null;return{getUV:()=>(null===r&&(r=(r=rY(e).mix(sj,t).normalize()).transformDirection(sE)),r),getTextureLevel:()=>e}},um=e=>({getUV:()=>e,getTextureLevel:()=>eD(1)}),ug=new u._4j;class uf extends of{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(ug),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new uh(t):null}setupLightingModel(){return new lF}setupSpecular(){let e=r0(eW(.04),e4.rgb,e9);td.assign(eW(.04)),th.assign(e),tc.assign(1)}setupVariants(){let e=this.metalnessNode?eD(this.metalnessNode):nJ;e9.assign(e);let t=this.roughnessNode?eD(this.roughnessNode):nZ;t=oJ({roughness:t}),e6.assign(t),this.setupSpecular(),e8.assign(e4.rgb.mul(e.oneMinus()))}}let ub=new u.uSd;class uy extends uf{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.retroreflectivityNode=null,this.anisotropyNode=null,this.setDefaultValues(ub),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}get useRetroreflection(){return this.retroreflectivity>0||null!==this.retroreflectivityNode}setupSpecular(){let e=this.iorNode?eD(this.iorNode):ai,t=this.specularColorNode?eW(this.specularColorNode):nK,r=this.specularIntensityNode?eD(this.specularIntensityNode):nX;tb.assign(e),td.assign(rk(rQ(tb.sub(1).div(tb.add(1))).mul(t),eW(1)).mul(r)),th.assign(r0(td,e4.rgb,e9)),tc.assign(r0(r,1,e9))}setupLightingModel(){return new lF(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion,this.useRetroreflection)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){let e=this.clearcoatNode?eD(this.clearcoatNode):n1,t=this.clearcoatRoughnessNode?eD(this.clearcoatRoughnessNode):n2;e7.assign(e),te.assign(oJ({roughness:t}))}if(this.useSheen){let e=this.sheenNode?eW(this.sheenNode):n8,t=this.sheenRoughnessNode?eD(this.sheenRoughnessNode):n5;tt.assign(e),tr.assign(t)}if(this.useRetroreflection){let e=this.retroreflectivityNode?eD(this.retroreflectivityNode):ap;tS.assign(e)}if(this.useIridescence){let e=this.iridescenceNode?eD(this.iridescenceNode):n9,t=this.iridescenceIORNode?eD(this.iridescenceIORNode):n7,r=this.iridescenceThicknessNode?eD(this.iridescenceThicknessNode):ae;ti.assign(e),ts.assign(t),tn.assign(r)}if(this.useAnisotropy){let e=(this.anisotropyNode?eG(this.anisotropyNode):n6).toVar();to.assign(e.length()),eU(to.equal(0),()=>{e.assign(eG(1,0))}).Else(()=>{e.divAssign(eG(to)),to.assign(to.saturate())}),ta.assign(to.pow2().mix(e6.pow2(),1)),tl.assign(nM[0].mul(e.x).add(nM[1].mul(e.y))),tu.assign(nM[1].mul(e.x).sub(nM[0].mul(e.y)))}if(this.useTransmission){let e=this.transmissionNode?eD(this.transmissionNode):at,t=this.thicknessNode?eD(this.thicknessNode):ar,r=this.attenuationDistanceNode?eD(this.attenuationDistanceNode):as,i=this.attenuationColorNode?eW(this.attenuationColorNode):an;if(ty.assign(e),tx.assign(t),tT.assign(r),t_.assign(i),this.useDispersion){let e=this.dispersionNode?eD(this.dispersionNode):ac;tv.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?eW(this.clearcoatNormalNode):n3}setup(e){e.context.setupClearcoatNormal=()=>ia(this.setupClearcoatNormal(e),"NORMAL","vec3"),super.setup(e)}}let ux=eF(({normal:e,lightDirection:t,builder:r})=>{let i=eG(e.dot(t).mul(.5).add(.5),0);if(r.material.gradientMap)return eW(nc("gradientMap","texture").context({getUV:()=>i}).r);{let e=i.fwidth().mul(.5);return r0(eW(.7),eW(1),r4(eD(.7).sub(e.x),eD(.7).add(e.x),i.x))}});class uT extends oV{direct({lightDirection:e,lightColor:t,reflectedLight:r},i){let s=ux({normal:s2,lightDirection:e,builder:i}).mul(t);r.directDiffuse.addAssign(s.mul(oW({diffuseColor:e4.rgb})))}indirect(e){let{ambientOcclusion:t,irradiance:r,reflectedLight:i}=e.context;i.indirectDiffuse.addAssign(r.mul(oW({diffuseColor:e4}))),i.indirectDiffuse.mulAssign(t)}}let u_=new u.Df;class uv extends of{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(u_),this.setValues(e)}setupLightingModel(){return new uT}}let uS=eF(()=>{let e=eW(sj.z,0,sj.x.negate()).normalize(),t=sj.cross(e);return eG(e.dot(s2),t.dot(s2)).mul(.495).add(.5)}).once(["NORMAL","VERTEX"])().toVar("matcapUV"),uR=new u.FNr;class uN extends of{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(uR),this.setValues(e)}setupVariants(e){let t;t=e.material.matcap?nc("matcap","texture").context({getUV:()=>uS}):eW(r0(.2,.8,uS.y)),e4.rgb.mulAssign(t.rgb)}}class uA extends G{static get type(){return"RotateNode"}constructor(e,t,r="XYZ"){super(),this.positionNode=e,this.rotationNode=t,this._order=r}customCacheKey(){return x(this._order)}setOrder(e){return this._order=e,this}getOrder(){return this._order}generateNodeType(e){return this.positionNode.getNodeType(e)}setup(e){let{rotationNode:t,positionNode:r}=this;if("vec2"===this.getNodeType(e)){let e=t.cos(),i=t.sin();return eZ(e,i,i.negate(),e).mul(r)}{let e=this._order,i=e0(eX(1,0,0,0),eX(0,rb(t.x),rg(t.x),0),eX(0,rg(t.x).negate(),rb(t.x),0),eX(0,0,0,1)),s={X:i,Y:e0(eX(rb(t.y),0,rg(t.y).negate(),0),eX(0,1,0,0),eX(rg(t.y),0,rb(t.y),0),eX(0,0,0,1)),Z:e0(eX(rb(t.z),rg(t.z),0,0),eX(rg(t.z).negate(),rb(t.z),0,0),eX(0,0,1,0),eX(0,0,0,1))};return s[e.charAt(0)].mul(s[e.charAt(1)]).mul(s[e.charAt(2)]).mul(eX(r,1)).xyz}}serialize(e){super.serialize(e),e.order=this._order}deserialize(e){super.deserialize(e),this._order=e.order}}let uE=eE(uA).setParameterLength(2,3),uC=new u.RoJ;class uw extends of{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.transparent=!0,this.setDefaultValues(uC),this.setValues(e)}setupPositionView(e){let{object:t,camera:r}=e,{positionNode:i,rotationNode:s,scaleNode:n,sizeAttenuation:a}=this,o=sD.mul(eW(i||0)),l=eG(sU[0].xyz.length(),sU[1].xyz.length());null!==n&&(l=l.mul(eG(n))),r.isPerspectiveCamera&&!1===a&&(l=l.mul(o.z.negate()));let u=sk.xy;if(t.center&&!0===t.center.isVector2){let e=new ig("center","vec2",t);u=u.sub(e.sub(.5))}let d=uE(u=u.mul(l),eD(s||n4));return eX(o.xy.add(d),o.zw)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}let uB=new u.BH$,uM=new u.I9Y;class uF extends uw{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.sizeNode=null,this.isPointsNodeMaterial=!0,this.setDefaultValues(uB),this.setValues(e)}setupPositionView(){let{positionNode:e}=this;return sD.mul(eW(e||sz)).xyz}setupVertexSprite(e){let{material:t,camera:r}=e,{rotationNode:i,scaleNode:s,sizeNode:n,sizeAttenuation:a}=this,o=super.setupVertex(e);if(!0!==t.isNodeMaterial)return o;let l=null!==n?eG(n):ah;l=l.mul(si),r.isPerspectiveCamera&&!0===a&&(l=l.mul(uL.div(sq.z.negate()))),s&&s.isNode&&(l=l.mul(eG(s)));let u=sk.xy;return i&&i.isNode&&(u=uE(u,eD(i))),u=(u=(u=u.mul(l)).div(sl.div(2))).mul(o.w),o=o.add(eX(u,0,0))}setupVertex(e){return e.object.isPoints?super.setupVertex(e):this.setupVertexSprite(e)}get alphaToCoverage(){return this._useAlphaToCoverage}set alphaToCoverage(e){this._useAlphaToCoverage!==e&&(this._useAlphaToCoverage=e,this.needsUpdate=!0)}}let uL=tB(1).setGroup(tE).onRenderUpdate(function({renderer:e}){let t=e.getSize(uM);this.value=.5*t.y});class uU extends oV{constructor(){super(),this.shadowNode=eD(1).toVar("shadowMask")}direct({lightNode:e}){null!==e.shadowNode&&this.shadowNode.mulAssign(e.shadowNode)}finish({context:e}){e4.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(e4.rgb)}}let uP=new u.q2;class uD extends of{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.transparent=!0,this.setDefaultValues(uP),this.setValues(e)}setupLightingModel(){return new uU}}e2("vec3"),e2("vec3"),e2("vec3");class uO{constructor(e,t,r){this.renderer=e,this.nodes=t,this.info=r,this._context="undefined"!=typeof self?self:null,this._animationLoop=null,this._requestId=null}start(){let e=(t,r)=>{this._requestId=this._context.requestAnimationFrame(e),this.renderer._inspector.isRunning&&this.renderer._inspector.finish(),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,this.renderer._inspector.begin(),null!==this._animationLoop&&this._animationLoop(t,r)};e()}stop(){this.renderer._inspector.isRunning&&this.renderer._inspector.finish(),null!==this._context&&this._context.cancelAnimationFrame(this._requestId),this._requestId=null}getAnimationLoop(){return this._animationLoop}setAnimationLoop(e){this._animationLoop=e}getContext(){return this._context}setContext(e){this._context=e}dispose(){this.stop()}}class uI{constructor(){this.weakMaps={}}_getWeakMap(e){let t=e.length,r=this.weakMaps[t];return void 0===r&&(r=new WeakMap,this.weakMaps[t]=r),r}get(e){let t=this._getWeakMap(e);for(let r=0;r<e.length-1;r++)if(void 0===(t=t.get(e[r])))return;return t.get(e[e.length-1])}set(e,t){let r=this._getWeakMap(e);for(let t=0;t<e.length-1;t++){let i=e[t];!1===r.has(i)&&r.set(i,new WeakMap),r=r.get(i)}return r.set(e[e.length-1],t),this}delete(e){let t=this._getWeakMap(e);for(let r=0;r<e.length-1;r++)if(void 0===(t=t.get(e[r])))return!1;return t.delete(e[e.length-1])}}let uV=0,uG=new WeakMap;class uk{constructor(e,t,r,i,s,n,a,o,l,u){this.id=uV++,this._nodes=e,this._geometries=t,this.renderer=r,this.object=i,this.material=s,this.scene=n,this.camera=a,this.lightsNode=o,this.context=l,this.geometry=i.geometry,this.version=s.version,this.drawRange=null,this.attributes=null,this.attributesId=null,this.pipeline=null,this.group=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.clippingContext=u,this.clippingContextCacheKey=null!==u?u.cacheKey:"",this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this._sourceMaterial=r._currentSourceMaterial,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.onGeometryDispose=()=>{this.attributes=null,this.attributesId=null},this.onObjectDispose=()=>{this.dispose()},this.object.addEventListener("dispose",this.onObjectDispose),this.material.addEventListener("dispose",this.onMaterialDispose),this.geometry.addEventListener("dispose",this.onGeometryDispose),null!==this._sourceMaterial&&this._sourceMaterial.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.getNodeBuilderState().hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().observer)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getBindingGroup(e){for(let t of this.getBindings())if(t.name===e)return t}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getIndirectOffset(){return this._geometries.getIndirectOffset(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null,this.attributesId=null}getAttributes(){if(null!==this.attributes)return this.attributes;let e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,r=[],i=new Set,s={};for(let n of e){let e;if(n.node&&n.node.attribute?e=n.node.attribute:void 0!==(e=t.getAttribute(n.name))&&(e.isInterleavedBufferAttribute?s[n.name]=e.data.uuid:s[n.name]=e.id),void 0===e)continue;r.push(e);let a=e.isInterleavedBufferAttribute?e.data:e;i.add(a)}return this.attributes=r,this.attributesId=s,this.vertexBuffers=Array.from(i.values()),r}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){let{object:e,material:t,geometry:r,group:i,drawRange:s}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),a=this.getIndex(),o=null!==a,l=1;if(!0===r.isInstancedBufferGeometry?l=r.instanceCount:void 0!==e.count&&(l=Math.max(0,e.count)),0===l)return null;if(n.instanceCount=l,!0===e.isBatchedMesh)return n;let u=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(u=2);let d=s.start*u,h=(s.start+s.count)*u;null!==i&&(d=Math.max(d,i.start*u),h=Math.min(h,(i.start+i.count)*u));let c=r.attributes.position,p=1/0;o?p=a.count:null!=c&&(p=c.count),d=Math.max(d,0);let m=(h=Math.min(h,p))-d;return m<0||m===1/0?null:(n.vertexCount=m,n.firstVertex=d,n)}getGeometryCacheKey(){let{geometry:e}=this,t="";for(let r of Object.keys(e.attributes).sort()){let i=e.attributes[r];t+=r+",",i.data&&(t+=i.data.stride+","),i.offset&&(t+=i.offset+","),i.itemSize&&(t+=i.itemSize+","),i.normalized&&(t+="n,")}for(let r of Object.keys(e.morphAttributes).sort()){let i=e.morphAttributes[r];t+="morph-"+r+",";for(let e=0,r=i.length;e<r;e++)t+=i[e].id+","}return e.index&&(t+="index,"),t}getMaterialCacheKey(){let{object:e,material:t,renderer:r}=this,i=t.customProgramCacheKey();for(let e of function(e){let t=Object.keys(e),r=uG.get(e.constructor);if(void 0===r){r=[];let t=Object.getPrototypeOf(e);for(;t;){let e=Object.getOwnPropertyDescriptors(t);for(let t in e){let i=e[t];i&&"function"==typeof i.get&&r.push(t)}t=Object.getPrototypeOf(t)}uG.set(e.constructor,r)}for(let e=0;e<r.length;e++)t.push(r[e]);return t}(t)){let s;if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;let n=t[e];if(null!==n){let t=typeof n;"number"===t?s="side"===e?String(n):0!==n?"1":"0":"object"===t?(s="{",n.isTexture&&(s+=n.mapping,!0===r.backend.isWebGPUBackend&&(s+=n.magFilter,s+=n.minFilter,s+=n.wrapS,s+=n.wrapT,s+=n.wrapR)),s+="}"):s=String(n)}else s=String(n);i+=s+","}return i+=this.clippingContextCacheKey+",",e.geometry&&(i+=this.getGeometryCacheKey()),e.skeleton&&(i+=e.skeleton.bones.length+","),e.isBatchedMesh&&(i+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(i+=e._colorsTexture.uuid+",")),(e.isInstancedMesh||e.count>1)&&(i+=e.uuid+","),i+=this.context.id+",",x(i+=e.receiveShadow+",")}get needsGeometryUpdate(){if(this.geometry.id!==this.object.geometry.id)return!0;if(null!==this.attributes){let e=this.attributesId;for(let t in e){let r=this.geometry.getAttribute(t);if(void 0===r)return!0;let i=r.isInterleavedBufferAttribute?r.data.uuid:r.id;if(e[t]!==i)return!0}}return!1}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=0;return!0!==this.material.isShadowPassMaterial&&(e=this._nodes.getCacheKey(this.scene,this.lightsNode)),this.camera.isArrayCamera&&(e=_(e,this.camera.cameras.length)),this.object.receiveShadow&&(e=_(e,1)),e=_(e,this.renderer.contextNode.id,this.renderer.contextNode.version)}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.object.removeEventListener("dispose",this.onObjectDispose),this.material.removeEventListener("dispose",this.onMaterialDispose),this.geometry.removeEventListener("dispose",this.onGeometryDispose),null!==this._sourceMaterial&&this._sourceMaterial.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}let uz=[];class u${constructor(e,t,r,i,s,n){this.renderer=e,this.nodes=t,this.geometries=r,this.pipelines=i,this.bindings=s,this.info=n,this._chainMaps={},this._renderObjects=new Set}get(e,t,r,i,s,n,a,o){let l=this.getChainMap(o);uz[0]=e,uz[1]=t,uz[2]=n,uz[3]=s;let u=l.get(uz);return void 0===u?(u=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,r,i,s,n,a,o),l.set(uz,u)):(u.camera=i,u.updateClipping(a),u.needsGeometryUpdate&&u.setGeometry(e.geometry),(u.version!==t.version||u.needsUpdate)&&(u.initialCacheKey!==u.getCacheKey()?(u.dispose(),u=this.get(e,t,r,i,s,n,a,o)):u.version=t.version)),uz[0]=null,uz[1]=null,uz[2]=null,uz[3]=null,u}getChainMap(e="default"){return this._chainMaps[e]||(this._chainMaps[e]=new uI)}dispose(){for(let e of this._renderObjects)e.dispose();this._renderObjects.clear(),this._chainMaps={}}createRenderObject(e,t,r,i,s,n,a,o,l,u,d){let h=this.getChainMap(d),c=new uk(e,t,r,i,s,n,a,o,l,u);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.deleteForRender(c),this.nodes.delete(c),h.delete(c.getChainArray()),this._renderObjects.delete(c)},this._renderObjects.add(c),c}}class uW{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t=null;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}let uH={VERTEX:1,INDEX:2,STORAGE:3,INDIRECT:4};class uq extends uW{constructor(e,t){super(),this.backend=e,this.info=t}delete(e){let t=super.delete(e);return null!==t&&(this.backend.destroyAttribute(e),this.info.destroyAttribute(e)),t}update(e,t){let r=this.get(e);if(void 0===r.version)t===uH.VERTEX?(this.backend.createAttribute(e),this.info.createAttribute(e)):t===uH.INDEX?(this.backend.createIndexAttribute(e),this.info.createIndexAttribute(e)):t===uH.STORAGE?(this.backend.createStorageAttribute(e),this.info.createStorageAttribute(e)):t===uH.INDIRECT&&(this.backend.createIndirectStorageAttribute(e),this.info.createIndirectStorageAttribute(e)),r.version=this._getBufferAttribute(e).version;else{let t=this._getBufferAttribute(e);(r.version<t.version||t.usage===u.Vnu)&&(this.backend.updateAttribute(e),r.version=t.version)}}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}function uj(e){return null!==e.index?e.index.version:e.attributes.position.version}function uX(e){return null!==e.index?e.index.id:e.attributes.position.id}function uK(e){let t=[],r=e.index,i=e.attributes.position;if(null!==r){let e=r.array;for(let r=0,i=e.length;r<i;r+=3){let i=e[r+0],s=e[r+1],n=e[r+2];t.push(i,s,s,n,n,i)}}else{let e=i.array;for(let r=0,i=e.length/3-1;r<i;r+=3){let e=r+0,i=r+1,s=r+2;t.push(e,i,i,s,s,e)}}let s=new(i.count>=65535?u.MW4:u.A$4)(t,1);return s.version=uj(e),s.__id=uX(e),s}class uQ extends uW{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap,this._geometryDisposeListeners=new Map}has(e){let t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){let t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;let r=()=>{this.info.memory.geometries--;let i=t.index;for(let e of(null!==i&&this.attributes.delete(i),Object.values(t.attributes)))this.attributes.delete(e);let s=this.wireframes.get(t);void 0!==s&&this.attributes.delete(s);let n=new Set(Object.values(e.geometry.attributes));for(let t of e.getAttributes())!1===n.has(t)&&this.attributes.delete(t);t.removeEventListener("dispose",r),this._geometryDisposeListeners.delete(t)};t.addEventListener("dispose",r),this._geometryDisposeListeners.set(t,r)}updateAttributes(e){for(let t of e.getAttributes())t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute?this.updateAttribute(t,uH.STORAGE):this.updateAttribute(t,uH.VERTEX);let t=this.getIndex(e);null!==t&&this.updateAttribute(t,uH.INDEX);let r=e.geometry.indirect;null!==r&&this.updateAttribute(r,uH.INDIRECT)}updateAttribute(e,t){let r=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,r)):this.attributeCall.get(e.data)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e.data,r),this.attributeCall.set(e,r)):this.attributeCall.get(e)!==r&&(this.attributes.update(e,t),this.attributeCall.set(e,r))}getIndirect(e){return e.geometry.indirect}getIndirectOffset(e){return e.geometry.indirectOffset}getIndex(e){let{geometry:t,material:r}=e,i=t.index;if(!0===r.wireframe){let e=this.wireframes,r=e.get(t);void 0===r?(r=uK(t),e.set(t,r)):(r.version!==uj(t)||r.__id!==uX(t))&&(this.attributes.delete(r),r=uK(t),e.set(t,r)),i=r}return i}dispose(){for(let[e,t]of this._geometryDisposeListeners.entries())e.removeEventListener("dispose",t);this._geometryDisposeListeners.clear()}}class uY{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0},this.compute={calls:0,frameCalls:0,timestamp:0},this.memory={attributes:0,attributesSize:0,geometries:0,indexAttributes:0,indexAttributesSize:0,indirectStorageAttributes:0,indirectStorageAttributesSize:0,programs:0,programsSize:0,readbackBuffers:0,readbackBuffersSize:0,renderTargets:0,storageAttributes:0,storageAttributesSize:0,textures:0,texturesSize:0,uniformBuffers:0,uniformBuffersSize:0,total:0},this.memoryMap=new WeakMap}update(e,t,r){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=t/3*r:e.isPoints?this.render.points+=r*t:e.isLineSegments?this.render.lines+=t/2*r:e.isLine?this.render.lines+=r*(t-1):(0,u.z3S)("WebGPUInfo: Unknown object type.")}reset(){this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){for(let e in this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory)this.memory[e]=0;this.memoryMap=new WeakMap}createTexture(e){let t=this._getTextureMemorySize(e);this.memoryMap.set(e,t),this.memory.textures++,this.memory.total+=t,this.memory.texturesSize+=t}destroyTexture(e){let t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.textures--,this.memory.total-=t,this.memory.texturesSize-=t}_createAttribute(e,t){let r=this._getAttributeMemorySize(e);this.memoryMap.set(e,{size:r,type:t}),this.memory[t]++,this.memory.total+=r,this.memory[t+"Size"]+=r}createAttribute(e){this._createAttribute(e,"attributes")}createIndexAttribute(e){this._createAttribute(e,"indexAttributes")}createStorageAttribute(e){this._createAttribute(e,"storageAttributes")}createIndirectStorageAttribute(e){this._createAttribute(e,"indirectStorageAttributes")}destroyAttribute(e){let t=this.memoryMap.get(e);t&&(this.memoryMap.delete(e),this.memory[t.type]--,this.memory.total-=t.size,this.memory[t.type+"Size"]-=t.size)}createReadbackBuffer(e){let t=e.maxByteLength;this.memoryMap.set(e,{size:t,type:"readbackBuffers"}),this.memory.readbackBuffers++,this.memory.total+=t,this.memory.readbackBuffersSize+=t}destroyReadbackBuffer(e){let{size:t}=this.memoryMap.get(e);this.memoryMap.delete(e),this.memory.readbackBuffers--,this.memory.total-=t,this.memory.readbackBuffersSize-=t}createUniformBuffer(e){let t=e.byteLength;this.memoryMap.set(e,{size:t,type:"uniformBuffers"}),this.memory.uniformBuffers++,this.memory.total+=t,this.memory.uniformBuffersSize+=t}destroyUniformBuffer(e){let t=this.memoryMap.get(e);t&&(this.memoryMap.delete(e),this.memory.uniformBuffers--,this.memory.total-=t.size,this.memory.uniformBuffersSize-=t.size)}createProgram(e){let t=e.code.length;this.memoryMap.set(e,t),this.memory.programs++,this.memory.total+=t,this.memory.programsSize+=t}destroyProgram(e){let t=this.memoryMap.get(e)||0;this.memoryMap.delete(e),this.memory.programs--,this.memory.total-=t,this.memory.programsSize-=t}_getTextureMemorySize(e){if(e.isCompressedTexture)return 1;let t=1;e.type===u.tJf||e.type===u.OUM?t=1:e.type===u.fBL||e.type===u.cHt||e.type===u.ix0?t=2:(e.type===u.Yuy||e.type===u.bkx||e.type===u.RQf)&&(t=4);let r=4;e.format===u.wrO||e.format===u.VT0||e.format===u.ZQM||e.format===u.zdS||e.format===u.dcC?r=1:e.format===u.paN||e.format===u.TkQ?r=2:(e.format===u.HIg||e.format===u.VGF)&&(r=3);let i=t*r;e.type===u.Wew||e.type===u.gJ2?i=2:(e.type===u.V3x||e.type===u.Dmk||e.type===u.yT7)&&(i=4);let s=e.width||1,n=e.height||1,a=e.isCubeTexture?6:e.depth||1,o=s*n*a*i,l=e.mipmaps;if(l&&l.length>0){let e=0;for(let t=0;t<l.length;t++){let r=l[t];r.data?e+=r.data.byteLength:e+=(r.width||Math.max(1,s>>t))*(r.height||Math.max(1,n>>t))*a*i}o+=e}else e.generateMipmaps&&(o*=1.333);return Math.round(o)}_getAttributeMemorySize(e){return(e.isInterleavedBufferAttribute&&(e=e.data),e.array)?e.array.byteLength:e.count&&e.itemSize?e.count*e.itemSize*4:0}}class uZ{constructor(e){this.cacheKey=e,this.usedTimes=0}}class uJ extends uZ{constructor(e,t,r){super(e),this.vertexProgram=t,this.fragmentProgram=r}}class u0 extends uZ{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let u1=0;class u2{constructor(e,t,r,i=null,s=null){this.id=u1++,this.code=e,this.stage=t,this.name=r,this.transforms=i,this.attributes=s,this.usedTimes=0}}class u3 extends uW{constructor(e,t,r){super(),this.backend=e,this.nodes=t,this.info=r,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t,r=null){let{backend:i}=this,s=this.get(e);if(this._needsComputeUpdate(e)){let n=s.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);let a=this.nodes.getForCompute(e),o=this.programs.compute.get(a.computeShader);void 0===o&&(n&&0===n.computeProgram.usedTimes&&this._releaseProgram(n.computeProgram),o=new u2(a.computeShader,"compute",e.name,a.transforms,a.nodeAttributes),this.programs.compute.set(a.computeShader,o),i.createProgram(o),this.info.createProgram(o));let l=this._getComputeCacheKey(e,o),u=this.caches.get(l);void 0===u&&(n&&0===n.usedTimes&&this._releasePipeline(n),u=this._getComputePipeline(e,o,l,t,r)),u.usedTimes++,o.usedTimes++,s.version=e.version,s.pipeline=u}return s.pipeline}getForRender(e,t=null){let{backend:r}=this,i=this.get(e);if(this._needsRenderUpdate(e)){let s=i.pipeline;s&&(s.usedTimes--,s.vertexProgram.usedTimes--,s.fragmentProgram.usedTimes--);let n=e.getNodeBuilderState(),a=e.material?e.material.name:"",o=this.programs.vertex.get(n.vertexShader);void 0===o&&(s&&0===s.vertexProgram.usedTimes&&this._releaseProgram(s.vertexProgram),o=new u2(n.vertexShader,"vertex",a),this.programs.vertex.set(n.vertexShader,o),r.createProgram(o),this.info.createProgram(o));let l=this.programs.fragment.get(n.fragmentShader);void 0===l&&(s&&0===s.fragmentProgram.usedTimes&&this._releaseProgram(s.fragmentProgram),l=new u2(n.fragmentShader,"fragment",a),this.programs.fragment.set(n.fragmentShader,l),r.createProgram(l),this.info.createProgram(l));let u=this._getRenderCacheKey(e,o,l),d=this.caches.get(u);void 0===d?(s&&0===s.usedTimes&&this._releasePipeline(s),d=this._getRenderPipeline(e,o,l,u,t)):e.pipeline=d,d.usedTimes++,o.usedTimes++,l.usedTimes++,i.pipeline=d}return i.pipeline}isReady(e){let t=this.get(e).pipeline;if(void 0===t)return!1;let r=this.backend.get(t);return void 0!==r.pipeline&&null!==r.pipeline}delete(e){let t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,r,i,s){r=r||this._getComputeCacheKey(e,t);let n=this.caches.get(r);return void 0===n&&(n=new u0(r,t),this.caches.set(r,n),this.backend.createComputePipeline(n,i,s)),n}_getRenderPipeline(e,t,r,i,s){i=i||this._getRenderCacheKey(e,t,r);let n=this.caches.get(i);return void 0===n&&(n=new uJ(i,t,r),this.caches.set(i,n),e.pipeline=n,this.backend.createRenderPipeline(e,s)),n}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,r){return t.id+","+r.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){let t=e.code,r=e.stage;this.programs[r].delete(t),this.info.destroyProgram(e)}_needsComputeUpdate(e){let t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class u4 extends uW{constructor(e,t,r,i,s,n){super(),this.backend=e,this.textures=r,this.pipelines=s,this.attributes=i,this.nodes=t,this.info=n,this.pipelines.bindings=this}getForRender(e){let t=e.getBindings(),r=this.get(e);return!0!==r.initialized&&(this._createBindings(t),r.initialized=!0),t}getForCompute(e){let t=this.nodes.getForCompute(e).bindings,r=this.get(e);return(!0!==r.initialized||r.bindings!==t)&&(void 0!==r.bindings&&this._destroyBindings(r.bindings),this._createBindings(t),r.initialized=!0,r.bindings=t),t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}updateSharedForRender(e){for(let t of this.getForRender(e))for(let e of t.bindings)if((!0===e.isNodeUniformsGroup||!0===e.isNodeUniformBuffer)&&!0===e.groupNode.shared){if(!1===this.nodes.updateGroup(e))continue;e.update()&&this.backend.updateBinding(e),e.updateRanges.length>0&&e.clearUpdateRanges()}}deleteForCompute(e){let t=this.get(e).bindings||this.nodes.getForCompute(e).bindings;this._destroyBindings(t),this.delete(e)}deleteForRender(e){let t=e.getBindings();this._destroyBindings(t),this.delete(e)}_createBindings(e){for(let t of e){let r=this.get(t);if(void 0===r.bindGroup){for(let e of t.bindings)if(e.isUniformBuffer)this.backend.createUniformBuffer(e),this.info.createUniformBuffer(e);else if(e.isSampledTexture)this.textures.updateTexture(e.texture);else if(e.isSampler)this.textures.updateSampler(e);else if(e.isStorageBuffer){let t=e.attribute,r=t.isIndirectStorageBufferAttribute?uH.INDIRECT:uH.STORAGE;this.attributes.update(t,r)}this.backend.createBindings(t,e,""),r.bindGroup=t,r.usedTimes=1}else r.usedTimes++}}_destroyBindings(e){for(let t of e){let e=this.get(t);if(e.usedTimes--,0===e.usedTimes){for(let e of t.bindings)if(e.isUniformBuffer)this.backend.destroyUniformBuffer(e),this.info.destroyUniformBuffer(e),e.release();else if(e.isSampler){if(!0!==e.isSampledTexture)this.backend.destroySampler(e);else if(null!==e.texture){let r=this.textures.get(e.texture);void 0!==r.bindGroups&&r.bindGroups.delete(t)}e.release()}this.backend.deleteBindGroupData(t),this.delete(t)}}}_updateBindings(e){for(let t of e)this._update(t,e)}_update(e,t){let{backend:r}=this,i=!1,s=!0,n="",a=0;for(let t of e.bindings)if(!1!==this.nodes.updateGroup(t)){if(t.isStorageBuffer){let e=t.attribute,s=e.isIndirectStorageBufferAttribute?uH.INDIRECT:uH.STORAGE,a=r.get(t);this.attributes.update(e,s),a.attribute!==e&&(a.attribute=e,i=!0),n+=e.id+","}if(t.isUniformBuffer)t.update()&&r.updateBinding(t);else if(t.isSampledTexture){let o=t.update(),l=t.texture,u=this.textures.get(l);if(o&&(this.textures.updateTexture(l),t.generation!==u.generation&&(t.generation=u.generation,i=!0),u.bindGroups.add(e)),void 0!==r.get(l).externalTexture||u.isDefaultTexture?s=!1:(n+=l.id+",",a+=l.version),!0===l.isStorageTexture&&!0===l.mipmapsAutoUpdate){let e=this.get(l);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(l)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(l),e.needsMipmap=!1)}}else if(t.isSampler&&t.update()){let e=this.textures.updateSampler(t);t.samplerKey!==e&&(t.samplerKey=e,i=!0)}t.isBuffer&&t.updateRanges.length>0&&t.clearUpdateRanges()}!0===i&&this.backend.updateBindings(e,t,s?n:"",a)}}let u8=Object.freeze([]);function u5(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?e.z-t.z:e.id-t.id}function u6(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function u9(e){return(e.transmission>0||e.transmissionNode&&e.transmissionNode.isNode)&&e.side===u.$EB&&!1===e.forceSinglePass}class u7{constructor(e,t,r){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lighting=e,this.lightsNode=e.getNode(t),this.lightsArray=[],this.scene=t,this.camera=r,this.occlusionQueryCount=0,this.frameId=-1,this._lastOcclusionObject=null}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,r,i,s,n,a){let o=this.renderItems[this.renderItemsIndex];return void 0===o?(o={id:e.id,object:e,geometry:t,material:r,groupOrder:i,renderOrder:e.renderOrder,z:s,group:n,clippingContext:a},this.renderItems[this.renderItemsIndex]=o):(o.id=e.id,o.object=e,o.geometry=t,o.material=r,o.groupOrder=i,o.renderOrder=e.renderOrder,o.z=s,o.group=n,o.clippingContext=a),this.renderItemsIndex++,o}push(e,t,r,i,s,n,a){!0===this.camera.reversedDepth&&(s=-s);let o=this.getNextRenderItem(e,t,r,i,s,n,a);!0===e.occlusionTest&&this._lastOcclusionObject!==e&&(this.occlusionQueryCount++,this._lastOcclusionObject=e),!0===r.transparent||r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode||r.backdropNode&&r.backdropNode.isNode?(u9(r)&&this.transparentDoublePass.push(o),this.transparent.push(o)):this.opaque.push(o)}unshift(e,t,r,i,s,n,a){let o=this.getNextRenderItem(e,t,r,i,s,n,a);!0===r.transparent||r.transmission>0||r.transmissionNode&&r.transmissionNode.isNode||r.backdropNode&&r.backdropNode.isNode?(u9(r)&&this.transparentDoublePass.unshift(o),this.transparent.unshift(o)):this.opaque.unshift(o)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||u5),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||u6),this.transparent.length>1&&this.transparent.sort(t||u6)}finish(){this.lightsNode.setLights(this.lighting.enabled?this.lightsArray:u8);for(let e=this.renderItemsIndex,t=this.renderItems.length;e<t;e++){let t=this.renderItems[e];if(null===t.id)break;de(t)}this._lastOcclusionObject=null}clear(){for(let e=0,t=this.renderItems.length;e<t;e++){let t=this.renderItems[e];if(null===t.id)break;de(t)}this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0}}function de(e){e.id=null,e.object=null,e.geometry=null,e.material=null,e.groupOrder=null,e.renderOrder=null,e.z=null,e.group=null,e.clippingContext=null}let dt=[];class dr{constructor(){this.lists=new uI,this._activeLists=new Set,this._frameId=-1}get(e,t,r){let i=this.lists;dt[0]=e,dt[1]=t,dt[2]=r;let s=i.get(dt);return void 0===s&&(s=new u7(r,e,t),i.set(dt,s)),dt[0]=null,dt[1]=null,dt[2]=null,s.frameId=this._frameId,this._activeLists.add(s),s}update(e){if(e!==this._frameId)for(let t of(this._frameId=e,this._activeLists))e-t.frameId>10&&(t.clear(),this._activeLists.delete(t))}dispose(){this.lists=new uI,this._activeLists.clear(),this._frameId=-1}}let di=0;class ds{constructor(){this.id=di++,this.mrt=null,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new u.IUQ,this.scissor=!1,this.scissorValue=new u.IUQ,this.renderTarget=null,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.activeMipmapLevel=0,this.sampleCount=1,this.width=0,this.height=0,this.occlusionQueryCount=0,this.clippingContext=null,this.camera=null,this.fullscreenPass=!1,this.isRenderContext=!0}getCacheKey(){return dn(this)}}function dn(e){let{textures:t,activeCubeFace:r,activeMipmapLevel:i}=e,s=[r,i];for(let e of t)s.push(e.id);return T(s)}class da{constructor(e){this.renderer=e,this._renderContexts={}}get(e=null,t=null,r=0){let i;if(null===e)i="default";else{let t=e.texture.format,r=e.texture.type,s=e.textures.length;i=`${s}:${t}:${r}:${e.samples}:${e.depthBuffer}:${e.stencilBuffer}`}let s=i+"-"+(null!==t?t.id:"default")+"-"+r,n=this._renderContexts[s];return void 0===n&&((n=new ds).mrt=t,this._renderContexts[s]=n),null!==e&&(n.sampleCount=0===e.samples?1:e.samples),n.clearDepthValue=this.renderer.getClearDepth(),n.clearStencilValue=this.renderer.getClearStencil(),n}dispose(){this._renderContexts={}}}let dl=new u.Pq0;class du extends uW{constructor(e,t,r){super(),this.renderer=e,this.backend=t,this.info=r,this._htmlTextures=new Set}updateRenderTarget(e,t=0){let r=this.get(e),i=0===e.samples?1:e.samples,s=r.depthTextureMips||(r.depthTextureMips={}),n=e.textures,a=this.getSize(n[0]),o=a.width>>t,l=a.height>>t,d=e.depthTexture||s[t],h=!0===e.depthBuffer||!0===e.stencilBuffer,c=!1,p=void 0!==d&&void 0!==d.image&&d.image.depth>1,m=a.depth>1&&(e.useArrayDepthTexture||e.multiview||p);void 0===d&&h&&((d=new u.VCu).format=e.stencilBuffer?u.dcC:u.zdS,d.type=e.stencilBuffer?u.V3x:u.bkx,d.image.width=o,d.image.height=l,d.image.depth=a.depth,d.renderTarget=e,s[t]=d),d&&(d.isArrayTexture=m),(r.width!==a.width||a.height!==r.height)&&(c=!0,d&&d.renderTarget===e&&(d.needsUpdate=!0,d.image.width=o,d.image.height=l,d.image.depth=m?a.depth:1)),r.width=a.width,r.height=a.height,r.textures=n,r.depthTexture=d||null,r.depth=e.depthBuffer,r.stencil=e.stencilBuffer,r.renderTarget=e,r.sampleCount!==i&&(c=!0,d&&d.renderTarget===e&&(d.needsUpdate=!0),r.sampleCount=i);let g={sampleCount:i};if(!0!==e.isXRRenderTarget){for(let e=0;e<n.length;e++){let t=n[e];c&&(t.needsUpdate=!0),this.updateTexture(t,g)}d&&this.updateTexture(d,g)}!0!==r.initialized&&(r.initialized=!0,this.info.memory.renderTargets++,r.onDispose=()=>{this._destroyRenderTarget(e)},e.addEventListener("dispose",r.onDispose))}updateTexture(e,t={}){let r=this.get(e);if(!0===r.initialized&&r.version===e.version)return;let i=e.isRenderTargetTexture||e.isDepthTexture||e.isFramebufferTexture,s=this.backend;if(i&&!0===r.initialized&&s.destroyTexture(e),e.isFramebufferTexture){let t=this.renderer.getRenderTarget();t?e.type=t.texture.type:e.type=u.OUM}if(e.isHTMLTexture&&e.image){let t=this.renderer.domElement;if("requestPaint"in t){if(t.hasAttribute("layoutsubtree")||t.setAttribute("layoutsubtree","true"),e.image.parentNode!==t&&t.appendChild(e.image),0===this._htmlTextures.size){let e=this._htmlTextures;t.onpaint=t=>{let r=t&&t.changedElements;for(let t of e)(!r||r.includes(t.image))&&(t.needsUpdate=!0)}}this._htmlTextures.add(e)}}let{width:n,height:a,depth:o}=this.getSize(e);if(t.width=n,t.height=a,t.depth=o,t.needsMipmaps=this.needsMipmaps(e),t.levels=t.needsMipmaps?this.getMipLevels(e,n,a):1,e.isCubeTexture&&e.mipmaps.length>0&&t.levels++,i||!0===e.isStorageTexture||!0===e.isExternalTexture)s.createTexture(e,t),r.generation=e.version;else if(e.version>0){let i=e.image;if(void 0===i)(0,u.R8M)("Renderer: Texture marked for update but image is undefined.");else if(!1===i.complete)(0,u.R8M)("Renderer: Texture marked for update but image is incomplete.");else{if(e.images){let r=[];for(let t of e.images)r.push(t);t.images=r}else t.image=i;(void 0===r.isDefaultTexture||!0===r.isDefaultTexture)&&(s.createTexture(e,t),r.isDefaultTexture=!1,r.generation=e.version),!0===e.source.dataReady&&s.updateTexture(e,t);let n=!0===e.isStorageTexture&&!1===e.mipmapsAutoUpdate;t.needsMipmaps&&0===e.mipmaps.length&&!n&&s.generateMipmaps(e),e.onUpdate&&e.onUpdate(e)}}else s.createDefaultTexture(e),r.isDefaultTexture=!0,r.generation=e.version;!0!==r.initialized&&(r.initialized=!0,r.generation=e.version,r.bindGroups=new Set,this.info.createTexture(e),e.isVideoTexture&&!0===u.ppV.enabled&&u.ppV.getTransfer(e.colorSpace)!==u.KLL&&(0,u.R8M)("WebGPURenderer: Video textures must use a color space with a sRGB transfer function, e.g. SRGBColorSpace."),r.onDispose=()=>{this._destroyTexture(e)},e.addEventListener("dispose",r.onDispose)),r.version=e.version}updateSampler(e){return this.backend.updateSampler(e)}getSize(e,t=dl){let r=e.images?e.images[0]:e.image;return r?(void 0!==r.image&&(r=r.image),e.isHTMLTexture?(t.width=r.offsetWidth||1,t.height=r.offsetHeight||1,t.depth=1):"undefined"!=typeof HTMLVideoElement&&r instanceof HTMLVideoElement?(t.width=r.videoWidth||1,t.height=r.videoHeight||1,t.depth=1):"undefined"!=typeof VideoFrame&&r instanceof VideoFrame?(t.width=r.displayWidth||1,t.height=r.displayHeight||1,t.depth=1):(t.width=r.width||1,t.height=r.height||1,t.depth=e.isCubeTexture?6:r.depth||1)):t.width=t.height=t.depth=1,t}getMipLevels(e,t,r){return e.mipmaps.length>0?e.mipmaps.length:!0===e.isCompressedTexture?1:Math.floor(Math.log2(Math.max(t,r)))+1}needsMipmaps(e){return!0===e.generateMipmaps||e.mipmaps.length>0}_destroyRenderTarget(e){if(!0===this.has(e)){let t=this.get(e),r=t.textures,i=t.depthTexture;e.removeEventListener("dispose",t.onDispose);for(let e=0;e<r.length;e++)this._destroyTexture(r[e]);i&&i.renderTarget===e&&this._destroyTexture(i),this.delete(e),this.backend.delete(e),this.info.memory.renderTargets--}}_destroyTexture(e){if(!0===this.has(e)){let t=this.get(e);e.removeEventListener("dispose",t.onDispose);let r=t.isDefaultTexture;if(this.backend.destroyTexture(e,r),t.bindGroups)for(let r of t.bindGroups){let t=this.backend.get(r);for(let i of(t.groups=void 0,t.versions=void 0,r.bindings))i.isSampler&&i.texture===e&&(!0!==i.isSampledTexture&&this.backend.destroySampler(i),i.reset(),i.release())}this._htmlTextures.delete(e),this.delete(e),this.info.destroyTexture(e)}}}class dd extends u.Q1f{constructor(e,t,r,i=1){super(e,t,r),this.a=i}set(e,t,r,i=1){return this.a=i,super.set(e,t,r)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b,yield this.a}}class dh extends r7{static get type(){return"OverrideContextNode"}constructor(e,t=null){super(t,{overrideNodes:e}),this.isOverrideContextNode=!0}getFlowContextData(){let e=[];this.traverse(t=>{!0===t.isOverrideContextNode&&e.push(t.value.overrideNodes)});let t=new Map(e.flatMap(e=>Array.from(e.entries()))),r=super.getFlowContextData();return r.overrideNodes=t,r}}Z("overrideNode",(e,t,r)=>(function(e,t=null,r=null){if(t&&t.isNode){let e=t;t=()=>e}return new dh(new Map([[e,t]]),r)})(t,r,e)),Z("overrideNodes",(e,t)=>(function(e,t=null){let r=new Map;for(let[t,i]of e){let e=null!==i?"function"==typeof i?i:()=>i:null;r.set(t,e)}return new dh(r,t)})(t,e));class dc extends e1{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getMemberType(e,t){let r,i=this.getNodeType(e),s=e.getStructTypeNode(i);return null!==s?r=s.getMemberType(e,t):((0,u.z3S)(`TSL: Member "${t}" not found in struct "${i}".`,new b),r="float"),r}getHash(){return String(this.id)}generate(){return this.name}}class dp extends O{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this._expressionNode=null,this._currentNode=null,this._nodeDataLibrary=new Map,this.isStackNode=!0}getElementType(e){return this.outputNode?this.outputNode.getElementType(e):"void"}generateNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}getMemberType(e,t){return this.outputNode?this.outputNode.getMemberType(e,t):"void"}addToStack(e,t=-1){if(!0!==e.isNode)return(0,u.z3S)("TSL: Invalid node added to stack.",new b),this;if(-1===t)if(this._currentNode){let e=this._nodeDataLibrary.get(this._currentNode);void 0===e&&(e={delta:0},this._nodeDataLibrary.set(this._currentNode,e)),e.delta++,t=this.nodes.indexOf(this._currentNode)+e.delta}else t=this.nodes.length;return this.nodes.splice(t,0,e),this}addToStackBefore(e){let t=this._currentNode?this.nodes.indexOf(this._currentNode):0;return this.addToStack(e,t)}If(e,t){let r=new ev(t);return this._currentCond=r9(e,r),this.addToStack(this._currentCond)}ElseIf(e,t){let r=r9(e,new ev(t));return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new ev(e),this}Switch(e){return this._expressionNode=eS(e),this}Case(...e){let t=[];if(e.length>=2)for(let r=0;r<e.length-1;r++)t.push(this._expressionNode.equal(eS(e[r])));else(0,u.z3S)("TSL: Invalid parameter length. Case() requires at least two parameters.",new b);let r=new ev(e[e.length-1]),i=t[0];for(let e=1;e<t.length;e++)i=i.or(t[e]);let s=r9(i,r);return null===this._currentCond?(this._currentCond=s,this.addToStack(this._currentCond)):(this._currentCond.elseNode=s,this._currentCond=s,this)}Default(e){return this.Else(e),this}setup(e){let t=e.getNodeProperties(this),r=0;for(let i of this.getChildren())i.isVarNode&&i.isIntent(e)&&!0!==i.isAssign(e)||(t["node"+r++]=i);return t.outputNode||null}build(e,...t){let r,i=Q,s=e.buildStage;eL(this),e.setActiveStack(this);for(let t=0;t<this.nodes.length;t++){let r=this.nodes[t],i=this._currentNode;if(this._currentNode=r,!(r.isVarNode&&r.isIntent(e))||!0===r.isAssign(e)){if("setup"===s)r.build(e);else if("analyze"===s)r.build(e,this);else if("generate"===s){let t=e.getDataFromNode(r,"any").stages,i=t&&t[e.shaderStage];if(r.isVarNode&&i&&1===i.length&&i[0]&&i[0].isStackNode)continue;r.build(e,"void")}this._currentNode=i}}if(this.outputNode){let i=this.outputNode.build(e,...t);("generate"!==e.buildStage||"void"!==this.outputNode.getNodeType(e))&&(r=i)}else r=super.build(e,...t);return eL(i),e.removeActiveStack(this),r}}let dm=eE(dp).setParameterLength(0,1);class dg extends O{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}generateNodeType(){return"OutputType"}generate(e){let t=e.getDataFromNode(this);if(void 0===t.membersLayout){let r=this.members,i=[];for(let t=0;t<r.length;t++){let s="m"+t,n=r[t].getNodeType(e);i.push({name:s,type:n,index:t})}t.membersLayout=i,t.structType=e.getOutputStructTypeFromNode(this,t.membersLayout)}let r=e.getOutputStructName(),i=this.members,s=""!==r?r+".":"";for(let r=0;r<i.length;r++){let n=i[r].build(e,t.membersLayout[r].type);e.addLineFlowCode(`${s}m${r} = ${n}`,this)}return r}}class df{constructor(e=u.NTi){this.blending=e,this.blendSrc=u.ie2,this.blendDst=u.OuU,this.blendEquation=u.gO9,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.premultiplyAlpha=!1}copy(e){return this.blending=e.blending,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.premultiplyAlpha=e.premultiplyAlpha,this}clone(){return new this.constructor().copy(this)}}let db=new df(u.XIg),dy=new df(u.pCc);class dx extends dg{static get type(){return"MRTNode"}constructor(e){super(),this.outputNodes=e,this.blendModes={output:dy},this.clearColors={},this.isMRTNode=!0}setBlendMode(e,t){return this.blendModes[e]=t,this}getBlendMode(e){return this.blendModes[e]||db}setClearColor(e,t,r=1){let i=this.clearColors[e]||(this.clearColors[e]=new dd);return i.set(t),i.a=r,this}getClearColor(e){return this.clearColors[e]||null}has(e){return void 0!==this.outputNodes[e]}get(e){return this.outputNodes[e]}merge(e){let t={...this.outputNodes,...e.outputNodes},r={...this.blendModes,...e.blendModes},i={...this.clearColors,...e.clearColors},s=dT(t);return s.blendModes=r,s.clearColors=i,s}setup(e){let t=this.outputNodes,r=e.renderer.getRenderTarget(),i=[],s=r.textures;for(let r in t){let n=function(e,t){for(let r=0;r<e.length;r++)if(e[r].name===t)return r;return -1}(s,r);if(-1===n)continue;let a=e.getOutputType(n);i[n]=t[r].convert(a)}return this.members=i,super.setup(e)}}let dT=eE(dx);class d_ extends G{static get type(){return"BitcastNode"}constructor(e,t,r=null){super(),this.valueNode=e,this.conversionType=t,this.inputType=r,this.isBitcastNode=!0}generateNodeType(e){if(null!==this.inputType){let t=this.valueNode.getNodeType(e),r=e.getTypeLength(t);return e.getTypeFromLength(r,this.conversionType)}return this.conversionType}generate(e){let t=this.getNodeType(e),r="";if(null!==this.inputType){let t=this.valueNode.getNodeType(e);r=1===e.getTypeLength(t)?this.inputType:e.changeComponentType(t,this.inputType)}else r=this.valueNode.getNodeType(e);return`${e.getBitcastMethod(t,r)}( ${this.valueNode.build(e,r)} )`}}let dv=eF(([e])=>{let t=e.x.bitAnd(eI(255)),r=e.y.bitAnd(eI(255)),i=e.z.bitAnd(eI(255)),s=e.w.bitAnd(eI(255));return t.bitOr(r.shiftLeft(eI(8))).bitOr(i.shiftLeft(eI(16))).bitOr(s.shiftLeft(eI(24)))}).setLayout({name:"tsl_packed4x8_pack4xU8",type:"uint",inputs:[{name:"v",type:"uvec4"}]}),dS=eF(([e])=>dv(eQ(e))).setLayout({name:"tsl_packed4x8_pack4xI8",type:"uint",inputs:[{name:"v",type:"ivec4"}]}),dR=eF(([e])=>dv(r1(e,eQ(0),eQ(255)))).setLayout({name:"tsl_packed4x8_pack4xU8Clamp",type:"uint",inputs:[{name:"v",type:"uvec4"}]}),dN=eF(([e])=>dS(r1(e,eK(-128),eK(127)))).setLayout({name:"tsl_packed4x8_pack4xI8Clamp",type:"uint",inputs:[{name:"v",type:"ivec4"}]}),dA=eF(([e])=>eQ(e.bitAnd(eI(255)),e.shiftRight(eI(8)).bitAnd(eI(255)),e.shiftRight(eI(16)).bitAnd(eI(255)),e.shiftRight(eI(24)).bitAnd(eI(255)))).setLayout({name:"tsl_packed4x8_unpack4xU8",type:"uvec4",inputs:[{name:"v",type:"uint"}]});function dE(e,t){return eO(e.shiftLeft(eI(24-t))).shiftRight(eO(24))}let dC=eF(([e])=>eK(dE(e,0),dE(e,8),dE(e,16),dE(e,24))).setLayout({name:"tsl_packed4x8_unpack4xI8",type:"ivec4",inputs:[{name:"v",type:"uint"}]}),dw=eF(([e,t])=>{let r=dA(e),i=dA(t);return r.x.mul(i.x).add(r.y.mul(i.y)).add(r.z.mul(i.z)).add(r.w.mul(i.w))}).setLayout({name:"tsl_packed4x8_dot4U8Packed",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"}]}),dB=eF(([e,t])=>{let r=dC(e),i=dC(t);return r.x.mul(i.x).add(r.y.mul(i.y)).add(r.z.mul(i.z)).add(r.w.mul(i.w))}).setLayout({name:"tsl_packed4x8_dot4I8Packed",type:"int",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"}]}),dM=eF(([e])=>e.fract().sub(.5).abs()).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]});class dF extends O{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFn=null,this.global=!0}generateNodeType(e){return this.getCandidateFn(e).shaderNode.layout.type}getCandidateFn(e){let t=this.parametersNodes,r=this._candidateFn;if(null===r){let i=null,s=-1;for(let r of this.functionNodes){let n=r.shaderNode.layout;if(null===n)throw Error("THREE.FunctionOverloadingNode: FunctionNode must be a layout.");let a=n.inputs;if(t.length===a.length){let n=0;for(let r=0;r<t.length;r++){let i=t[r],s=a[r];i.getNodeType(e)===s.type&&n++}n>s&&(i=r,s=n)}}this._candidateFn=r=i}return r}setup(e){return this.getCandidateFn(e)(...this.parametersNodes)}}let dL=eE(dF),dU=e=>(...t)=>dL(e,...t);e=>e.time;e=>e.frameId;([e,t=null,r=null,i=eD(1),s=sz,n=sZ])=>{let a=n.abs().normalize();a=a.div(a.dot(eW(1)));let o=s.yz.mul(i),l=s.zx.mul(i),u=s.xy.mul(i),d=e.value,h=null!==t?t.value:d,c=null!==r?r.value:d;return tO(i3(d,o).mul(a.x),i3(h,l).mul(a.y),i3(c,u).mul(a.z))};let dP=new u.Zcv,dD=new u.Pq0,dO=new u.Pq0,dI=new u.Pq0,dV=new u.kn4,dG=new u.Pq0(0,0,-1),dk=new u.IUQ,dz=new u.Pq0,d$=new u.Pq0,dW=new u.IUQ,dH=new u.I9Y,dq=new u.O0B,dj=ss.flipX();dq.depthTexture=new u.VCu(1,1);let dX=new u.qUd(-1,1,1,-1,0,1);class dK extends u.LoY{constructor(e=!1){super(),this.setAttribute("position",new u.qtW([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new u.qtW(!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0],2))}}let dQ=new dK,dY=eX(tF([-1,-1,3]).element(iC),tF([3,-1,-1]).element(iC),0,1);class dZ extends u.eaF{constructor(e){super(dQ,e),this.camera=dX,this.isQuadMesh=!0}async renderAsync(e){(0,u.mcG)('QuadMesh: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await e.init(),e.render(this,dX)}render(e){let t=this.material.vertexNode;this.material.vertexNode=dY,e.render(this,dX),this.material.vertexNode=t}}function dJ(e,t){return t=function(e,t={}){return t.toneMapping=e.toneMapping,t.toneMappingExposure=e.toneMappingExposure,t.outputColorSpace=e.outputColorSpace,t.renderTarget=e.getRenderTarget(),t.activeCubeFace=e.getActiveCubeFace(),t.activeMipmapLevel=e.getActiveMipmapLevel(),t.renderObjectFunction=e.getRenderObjectFunction(),t.pixelRatio=e.getPixelRatio(),t.mrt=e.getMRT(),t.clearColor=e.getClearColor(t.clearColor||new u.Q1f),t.clearAlpha=e.getClearAlpha(),t.autoClear=e.autoClear,t.scissorTest=e.getScissorTest(),t}(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t}function d0(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}([e,t,r],i)=>{let s;s=i.renderer.coordinateSystem===u.i7u?eX(eW(e=eG(e.x,e.y.oneMinus()).mul(2).sub(1),t),1):eX(eW(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);let n=eX(r.mul(s));return n.xyz.div(n.w)};let d1=eF(([e])=>rm(eD(52.9829189).mul(rm(rj(e,eG(.06711056,.00583715)))))).setLayout({name:"interleavedGradientNoise",type:"float",inputs:[{name:"position",type:"vec2"}]}),d2=eF(([e,t,r])=>{let i=eD(2.399963229728653),s=ru(eD(e).add(.5).div(eD(t))),n=eD(e).mul(i).add(r);return eG(rb(n),rg(n)).mul(s)}).setLayout({name:"vogelDiskSample",type:"vec2",inputs:[{name:"sampleIndex",type:"int"},{name:"samplesCount",type:"int"},{name:"phi",type:"float"}]});u.uWO,u.THS;let d3=new u.kn4,d4=tB(0).setGroup(tE).onRenderUpdate(({scene:e})=>e.backgroundBlurriness),d8=tB(1).setGroup(tE).onRenderUpdate(({scene:e})=>e.backgroundIntensity),d5=tB(new u.kn4).setGroup(tE).onRenderUpdate(({scene:e})=>{let t=e.background;return null!==t&&t.isTexture&&t.mapping!==u.UTZ||e.backgroundNode&&e.backgroundNode.isNode?d3.makeRotationFromEuler(e.backgroundRotation).transpose():d3.identity(),d3});class d6 extends i1{static get type(){return"StorageTextureNode"}constructor(e,t,r=null){super(e,t),this.storeNode=r,this.mipLevel=0,this.isStorageTextureNode=!0,this.access=M.WRITE_ONLY}getInputType(){return"storageTexture"}getTransformedUV(e){return e}setup(e){super.setup(e);let t=e.getNodeProperties(this);return t.storeNode=this.storeNode,t}setAccess(e){return this.access=e,this}setMipLevel(e){return this.mipLevel=e,this}generate(e,t){return null!==this.storeNode?(this.generateStore(e),""):super.generate(e,t)}generateSnippet(e,t,r,i,s,n,a,o,l){let u=this.value;return e.generateStorageTextureLoad(u,t,r,i,n,l)}toReadWrite(){return this.setAccess(M.READ_WRITE)}toReadOnly(){return this.setAccess(M.READ_ONLY)}toWriteOnly(){return this.setAccess(M.WRITE_ONLY)}store(e,t){let r=this.clone();return r.referenceNode=this.getBase(),r.uvNode=e,r.storeNode=t,null!==t&&r.toStack(),r}generateStore(e){let{uvNode:t,storeNode:r,depthNode:i}=e.getNodeProperties(this),s=super.generate(e,"property"),n=t.build(e,!0===this.value.is3DTexture?"uvec3":"uvec2"),a=e.getTypeFromLength(4,e.getComponentTypeFromTexture(this.value)),o=r.build(e,a),l=i?i.build(e,"int"):null,u=e.generateTextureStore(this.value,s,n,l,o);e.addLineFlowCode(u,this)}clone(){let e=super.clone();return e.storeNode=this.storeNode,e.mipLevel=this.mipLevel,e.access=this.access,e}}let d9=eF(({texture:e,uv:t})=>{let r=eW().toVar();return eU(t.x.lessThan(1e-4),()=>{r.assign(eW(1,0,0))}).ElseIf(t.y.lessThan(1e-4),()=>{r.assign(eW(0,1,0))}).ElseIf(t.z.lessThan(1e-4),()=>{r.assign(eW(0,0,1))}).ElseIf(t.x.greaterThan(.9999),()=>{r.assign(eW(-1,0,0))}).ElseIf(t.y.greaterThan(.9999),()=>{r.assign(eW(0,-1,0))}).ElseIf(t.z.greaterThan(.9999),()=>{r.assign(eW(0,0,-1))}).Else(()=>{let i=e.sample(t.add(eW(-.01,0,0))).r.sub(e.sample(t.add(eW(.01,0,0))).r),s=e.sample(t.add(eW(0,-.01,0))).r.sub(e.sample(t.add(eW(0,.01,0))).r),n=e.sample(t.add(eW(0,0,-.01))).r.sub(e.sample(t.add(eW(0,0,.01))).r);r.assign(eW(i,s,n))}),r.normalize()});class d7 extends i1{static get type(){return"Texture3DNode"}constructor(e,t=null,r=null){super(e,t,r),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return eW(.5,.5,.5)}setUpdateMatrix(){}generateUV(e,t){return t.build(e,!0===this.sampler?"vec3":"ivec3")}generateOffset(e,t){return t.build(e,"ivec3")}normal(e){return d9({texture:this,uv:e})}}new WeakMap;let he=eF(([e,t])=>e.mul(t).clamp()).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),ht=eF(([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp()).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),hr=eF(([e,t])=>{let r=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),i=e.mul(e.mul(6.2).add(1.7)).add(.06);return r.div(i).pow(2.2)}).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),hi=eF(([e])=>{let t=e.mul(e.add(.0245786)).sub(90537e-9),r=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(r)}),hs=eF(([e,t])=>{let r=eJ(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=eJ(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=hi(e=r.mul(e)),(e=i.mul(e)).clamp()}).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),hn=eJ(eW(1.6605,-.1246,-.0182),eW(-.5876,1.1329,-.1006),eW(-.0728,-.0083,1.1187)),ha=eJ(eW(.6274,.0691,.0164),eW(.3293,.9195,.088),eW(.0433,.0113,.8956)),ho=eF(([e])=>{let t=eW(e).toVar(),r=eW(t.mul(t)).toVar(),i=eW(r.mul(r)).toVar();return eD(15.5).mul(i.mul(r)).sub(tV(40.14,i.mul(t))).add(tV(31.96,i).sub(tV(6.868,r.mul(t))).add(tV(.4298,r).add(tV(.1191,t).sub(.00232))))}),hl=eF(([e,t])=>{let r=eW(e).toVar(),i=eJ(eW(.856627153315983,.137318972929847,.11189821299995),eW(.0951212405381588,.761241990602591,.0767994186031903),eW(.0482516061458583,.101439036467562,.811302368396859)),s=eJ(eW(1.1271005818144368,-.1413297634984383,-.14132976349843826),eW(-.11060664309660323,1.157823702216272,-.11060664309660294),eW(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=eD(-12.47393),a=eD(4.026069);return r.mulAssign(t),r.assign(ha.mul(r)),r.assign(i.mul(r)),r.assign(rz(r,1e-10)),r.assign(rl(r)),r.assign(r.sub(n).div(a.sub(n))),r.assign(r1(r,0,1)),r.assign(ho(r)),r.assign(s.mul(r)),r.assign(rK(rz(eW(0),r),eW(2.2))),r.assign(hn.mul(r)),r.assign(r1(r,0,1)),r}).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),hu=eF(([e,t])=>{let r=eD(.76),i=eD(.15),s=rk((e=e.mul(t)).r,rk(e.g,e.b)),n=r9(s.lessThan(.08),s.sub(tV(6.25,s.mul(s))),.04);e.subAssign(n);let a=rz(e.r,rz(e.g,e.b));eU(a.lessThan(r),()=>e);let o=tI(1,r),l=tI(1,o.mul(o).div(a.add(o.sub(r))));e.mulAssign(l.div(a));let u=tI(1,tG(1,i.mul(a.sub(l)).add(1)));return r0(e,eW(l),u)}).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class hd extends O{static get type(){return"CodeNode"}constructor(e="",t=[],r=""){super("code"),this.isCodeNode=!0,this.global=!0,this.code=e,this.includes=t,this.language=r}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){for(let t of this.getIncludes(e))t.build(e,"void");let t=e.getCodeFromNode(this,this.getNodeType(e));return t.code=this.code,t.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}class hh extends hd{static get type(){return"FunctionNode"}constructor(e="",t=[],r=""){super(e,t,r)}generateNodeType(e){return this.getNodeFunction(e).type}getMemberType(e,t){let r=this.getNodeType(e);return e.getStructTypeNode(r).getMemberType(e,t)}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){let t=e.getDataFromNode(this),r=t.nodeFunction;return void 0===r&&(t.nodeFunction=r=e.parser.parseFunction(this.code)),r}generate(e,t){super.generate(e);let r=this.getNodeFunction(e),i=r.name,s=r.type,n=e.getCodeFromNode(this,s);if(""!==i){let t=e.getDataFromNode(this);!0!==t.declarationRegistered&&(n.name=i,e.registerDeclaration(n),t.declarationRegistered=!0)}let a=e.getPropertyName(n);return(n.code=this.getNodeFunction(e).getCode(a)+"\n","property"===t)?a:e.format(`${a}()`,s,t)}}function hc(e){let t,r=e.context.getViewZ;return void 0!==r&&(t=r(this)),(t||sq.z).negate()}let hp=eF(([e,t],r)=>r4(e,t,hc(r))),hm=eF(([e],t)=>{let r=hc(t);return e.mul(e,r,r).negate().exp().oneMinus()}),hg=eF(([e,t])=>eX(t.toFloat().mix(tm.rgb,e.toVec3()),tm.a));class hf extends O{constructor(e){super(),this.scope=e,this.isBarrierNode=!0}setup(e){e.allowEarlyReturns=!1,e.allowGlobalVariables=!1}generate(e){let{scope:t}=this,{renderer:r,shaderStage:i}=e,s=`${t}Barrier`;"compute"!==i&&(0,u.z3S)(`TSL: "${s}" is not supported in the ${i} stage and can only be executed in compute.`),!0===r.backend.isWebGLBackend?e.addFlowCode(` // ${s}()
|
|
8
|
+
`):e.addLineFlowCode(`${s}()`,this)}}class hb extends O{static get type(){return"AtomicFunctionNode"}constructor(e,t,r){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=r,this.parents=!0}getInputType(e){return this.pointerNode.getNodeType(e)}generateNodeType(e){return this.getInputType(e)}generate(e){let t=this.method;"vertex"===e.shaderStage&&(0,u.z3S)(`TSL: "${this.method}" is not supported in the vertex stage.`);let r=e.getNodeProperties(this),i=r.parents,s=this.getNodeType(e),n=this.getInputType(e),a=this.pointerNode,o=this.valueNode,l=[];l.push(`&${a.build(e,n)}`),null!==o&&l.push(o.build(e,n));let d=`${e.getMethod(t,s)}( ${l.join(", ")} )`;if(!(i&&1===i.length&&!0===i[0].isStackNode))return void 0===r.constNode&&(r.constNode=iI(d,s).toConst()),r.constNode.build(e);e.addLineFlowCode(d,this)}static get ATOMIC_LOAD(){return"atomicLoad"}static get ATOMIC_STORE(){return"atomicStore"}static get ATOMIC_ADD(){return"atomicAdd"}static get ATOMIC_SUB(){return"atomicSub"}static get ATOMIC_MAX(){return"atomicMax"}static get ATOMIC_MIN(){return"atomicMin"}static get ATOMIC_AND(){return"atomicAnd"}static get ATOMIC_OR(){return"atomicOr"}static get ATOMIC_XOR(){return"atomicXor"}}function hy(e){let t=(n=n||new WeakMap).get(e);return void 0===t&&n.set(e,t={}),t}function hx(e){let t=hy(e);return t.shadowMatrix||(t.shadowMatrix=tB("mat4").setGroup(tE).onRenderUpdate(t=>((!0!==e.castShadow||!1===t.renderer.shadowMap.enabled)&&(e.shadow.camera.coordinateSystem!==t.camera.coordinateSystem&&(e.shadow.camera.coordinateSystem=t.camera.coordinateSystem,e.shadow.camera.updateProjectionMatrix()),e.shadow.updateMatrices(e)),e.shadow.matrix)))}function hT(e){let t=hy(e);return t.position||(t.position=tB(new u.Pq0).setGroup(tE).onRenderUpdate((t,r)=>r.value.setFromMatrixPosition(e.matrixWorld)))}function h_(e){let t=hy(e);return t.viewPosition||(t.viewPosition=tB(new u.Pq0).setGroup(tE).onRenderUpdate(({camera:t},r)=>{r.value=r.value||new u.Pq0,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)}))}let hv=e=>sA.transformDirection(hT(e).sub(function(e){let t=hy(e);return t.targetPosition||(t.targetPosition=tB(new u.Pq0).setGroup(tE).onRenderUpdate((t,r)=>r.value.setFromMatrixPosition(e.target.matrixWorld)))}(e))),hS=e2("vec3","totalDiffuse"),hR=e2("vec3","totalSpecular"),hN=e2("vec3","outgoingLight"),hA=(e,t)=>{for(let r of t)if(r.isAnalyticLightNode&&r.light.id===e)return r;return null},hE=new WeakMap,hC=[];class hw extends O{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=hS,this.totalSpecularNode=hR,this.outgoingLightNode=hN,this._lights=[],this.global=!0}customCacheKey(){let e=this.getBuiltinLights();for(let t=0;t<e.length;t++){let r=e[t];if(hC.push(r.id),hC.push(+!!r.castShadow),!0===r.isSpotLight){let e=null!==r.map?r.map.id:-1,t=r.colorNode?r.colorNode.getCacheKey():-1;hC.push(e,t)}}let t=T(hC);return hC.length=0,t}getHash(e){let t=e.getDataFromNode(this);if(void 0===t.lightNodesHash){let r=this.setupLightsNode(e);t.lightNodes=r;let i=[];for(let e of r)i.push(e.getHash());t.lightNodesHash="lights-"+i.join(",")}return t.lightNodesHash}analyze(e){let t=e.getNodeProperties(this);for(let r of t.nodes)r.build(e);t.outputNode.build(e)}setupLightsNode(e){let t=e.getDataFromNode(this),r=[],i=t.lightNodes||null,s=[...e.context.materialLightings,...this.getBuiltinLights()].sort((e,t)=>e.id-t.id),n=e.renderer.library;for(let e of s)if(e.isNode)r.push(e);else{let t=null;if(null!==i&&(t=hA(e.id,i)),null===t){let r=n.getLightNodeClass(e.constructor);if(null===r){(0,u.R8M)(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}!1===hE.has(e)&&hE.set(e,new r(e)),t=hE.get(e)}r.push(t)}return r}setupDirectLight(e,t,r){let{lightingModel:i,reflectedLight:s}=e.context;i.direct({...r,lightNode:t,reflectedLight:s},e)}setupDirectRectAreaLight(e,t,r){let{lightingModel:i,reflectedLight:s}=e.context;i.directRectArea({...r,lightNode:t,reflectedLight:s},e)}setupLights(e,t){for(let r of t)r.build(e)}getLightNodes(e){let t=e.getDataFromNode(this);return void 0===t.lightNodes&&(t.lightNodes=this.setupLightsNode(e)),t.lightNodes}setup(e){let t=e.lightsNode;e.lightsNode=this;let r=this.outgoingLightNode,i=e.context,s=i.lightingModel,n=e.getNodeProperties(this);if(s){let{totalDiffuseNode:t,totalSpecularNode:a}=this;i.outgoingLight=r,n.nodes=e.addStack().nodes,s.start(e);let{backdrop:o,backdropAlpha:l}=i,{directDiffuse:u,directSpecular:d,indirectDiffuse:h,indirectSpecular:c}=i.reflectedLight,p=u.add(h);null!==o&&(p=null!==l?eW(l.mix(p,o)):eW(o)),t.assign(p),a.assign(d.add(c)),r.assign(t.add(a)),s.finish(e),r=r.bypass(e.removeStack())}else n.nodes=[];return e.lightsNode=t,r}setLights(e){return this._lights=e,this}getLights(){return this._lights}getBuiltinLights(){return this._lights}get hasLights(){return this._lights.length>0}}let hB=new WeakMap,hM=new uI,hF=[];class hL extends O{static get type(){return"ShadowBaseNode"}constructor(e){super(),this.light=e,this.updateBeforeType=B.RENDER,this.isShadowBaseNode=!0}getShadowMaterial(){var e;let t;return e=this.light,void 0===(t=hB.get(e))&&((t=new of).colorNode=eX(0,0,0,1),t.isShadowPassMaterial=!0,t.name="ShadowMaterial",t.blending=u.XIg,t.fog=!1,hB.set(e,t)),t}disposeShadowMaterial(){var e=this.light;let t=hB.get(e);void 0!==t&&(t.dispose(),hB.delete(e))}getShadowRenderObjectFunction(e,t=this.light.shadow){let r,i=e.shadowMap.type,s=e.getMRT(),n=!!s&&s.has("velocity");return hF[0]=e,hF[1]=t,(void 0===(r=hM.get(hF))||r.shadowType!==i||r.useVelocity!==n)&&((r=(r,s,a,o,l,d,h,c,p)=>{(!0===r.castShadow||r.receiveShadow&&i===u.RyA)&&(n&&(E(r).useVelocity=!0),r.onBeforeShadow(e,r,a,t.camera,o,s.overrideMaterial,d),e.renderObject(r,s,a,o,l,d,h,c,p),r.onAfterShadow(e,r,a,t.camera,o,s.overrideMaterial,d))}).shadowType=i,r.useVelocity=n,hM.set(hF,r)),hF[0]=null,hF[1]=null,r}setupShadowPosition({context:e,material:t}){hU.assign(t.receivedShadowPositionNode||e.shadowPositionWorld||sW)}}let hU=e2("vec3","shadowPositionWorld"),hP=eF(({depthTexture:e,shadowCoord:t,depthLayer:r})=>{let i=i3(e,t.xy).setName("t_basic");return e.isArrayTexture&&(i=i.depth(r)),i.compare(t.z)}),hD=eF(({depthTexture:e,shadowCoord:t,shadow:r,depthLayer:i})=>{let s=(t,r)=>{let s=i3(e,t);return e.isArrayTexture&&(s=s.depth(i)),s.compare(r)},n=nd("mapSize","vec2",r).setGroup(tE),a=nd("radius","float",r).setGroup(tE),o=eG(1).div(n),l=a.mul(o.x),u=d1(sa.xy).mul(6.28318530718);return tO(s(t.xy.add(d2(0,5,u).mul(l)),t.z),s(t.xy.add(d2(1,5,u).mul(l)),t.z),s(t.xy.add(d2(2,5,u).mul(l)),t.z),s(t.xy.add(d2(3,5,u).mul(l)),t.z),s(t.xy.add(d2(4,5,u).mul(l)),t.z)).mul(.2)}),hO=eF(({depthTexture:e,shadowCoord:t,depthLayer:r},i)=>{let s=i3(e).sample(t.xy);e.isArrayTexture&&(s=s.depth(r));let n=(s=s.rg).x,a=rz(1e-7,s.y.mul(s.y)),o=i.renderer.reversedDepthBuffer?r$(n,t.z):r$(t.z,n),l=eD(1).toVar();return eU(o.notEqual(1),()=>{let e=t.z.sub(n),r=a.div(a.add(e.mul(e)));r=r1(tI(r,.3).div(.65)),l.assign(rz(o,r))}),l}),hI=eF(({samples:e,radius:t,size:r,shadowPass:i,depthLayer:s})=>{let n=eD(0).toVar("meanVertical"),a=eD(0).toVar("squareMeanVertical"),o=e.lessThanEqual(eD(1)).select(eD(0),eD(2).div(e.sub(1))),l=e.lessThanEqual(eD(1)).select(eD(0),eD(-1));aX({start:eO(0),end:eO(e),type:"int",condition:"<"},({i:e})=>{let u=l.add(eD(e).mul(o)),d=i.sample(tO(sa.xy,eG(0,u).mul(t)).div(r));i.value.isArrayTexture&&(d=d.depth(s)),d=d.x,n.addAssign(d),a.addAssign(d.mul(d))}),n.divAssign(e),a.divAssign(e);let u=ru(a.sub(n.mul(n)).max(0));return eG(n,u)}),hV=eF(({samples:e,radius:t,size:r,shadowPass:i,depthLayer:s})=>{let n=eD(0).toVar("meanHorizontal"),a=eD(0).toVar("squareMeanHorizontal"),o=e.lessThanEqual(eD(1)).select(eD(0),eD(2).div(e.sub(1))),l=e.lessThanEqual(eD(1)).select(eD(0),eD(-1));aX({start:eO(0),end:eO(e),type:"int",condition:"<"},({i:e})=>{let u=l.add(eD(e).mul(o)),d=i.sample(tO(sa.xy,eG(u,0).mul(t)).div(r));i.value.isArrayTexture&&(d=d.depth(s)),n.addAssign(d.x),a.addAssign(tO(d.y.mul(d.y),d.x.mul(d.x)))}),n.divAssign(e),a.divAssign(e);let u=ru(a.sub(n.mul(n)).max(0));return eG(n,u)}),hG=[hP,hD,null,hO],hk=new dZ;class hz extends hL{static get type(){return"ShadowNode"}constructor(e,t=null){super(e),this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this._node=null,this._currentShadowType=null,this._cameraFrameId=new WeakMap,this.isShadowNode=!0,this.depthLayer=0}setupShadowFilter(e,{filterFn:t,depthTexture:r,shadowCoord:i,shadow:s,depthLayer:n}){let a=i.x.greaterThanEqual(0).and(i.x.lessThanEqual(1)).and(i.y.greaterThanEqual(0)).and(i.y.lessThanEqual(1)).and(i.z.lessThanEqual(1)),o=t({depthTexture:r,shadowCoord:i,shadow:s,depthLayer:n});return a.select(o,eD(1))}setupShadowCoord(e,t){let r,{shadow:i}=this,{renderer:s}=e,n=i.biasNode||nd("bias","float",i).setGroup(tE),a=t;if(i.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)r=(a=a.xyz.div(a.w)).z;else{let e=a.w;a=a.xy.div(e);let t=nd("near","float",i.camera).setGroup(tE),s=nd("far","float",i.camera).setGroup(tE);r=oo(e.negate(),t,s)}return eW(a.x,a.y.oneMinus(),s.reversedDepthBuffer?r.sub(n):r.add(n))}getShadowFilterFn(e){return hG[e]}setupRenderTarget(e,t){let r=new u.VCu(e.mapSize.width,e.mapSize.height);r.name="ShadowDepthTexture",r.compareFunction=t.renderer.reversedDepthBuffer?u.gWB:u.TiK;let i=t.createRenderTarget(e.mapSize.width,e.mapSize.height);return i.texture.name="ShadowMap",i.texture.type=e.mapType,i.depthTexture=r,{shadowMap:i,depthTexture:r}}setupShadow(e){let t,r,i,{renderer:s,camera:n}=e,{light:a,shadow:o}=this,{depthTexture:l,shadowMap:d}=this.setupRenderTarget(o,e),h=s.shadowMap.type,c=s.hasCompatibility(u.x$Y.TEXTURE_COMPARE);if(h===u.QP0&&c?(l.minFilter=u.k6q,l.magFilter=u.k6q):(l.minFilter=u.hxR,l.magFilter=u.hxR),o.camera.coordinateSystem=n.coordinateSystem,o.camera.updateProjectionMatrix(),h===u.RyA&&!0!==o.isPointLightShadow){l.compareFunction=null,d.depth>1?(d._vsmShadowMapVertical||(d._vsmShadowMapVertical=e.createRenderTarget(o.mapSize.width,o.mapSize.height,{format:u.paN,type:u.ix0,depth:d.depth,depthBuffer:!1}),d._vsmShadowMapVertical.texture.name="VSMVertical"),this.vsmShadowMapVertical=d._vsmShadowMapVertical,d._vsmShadowMapHorizontal||(d._vsmShadowMapHorizontal=e.createRenderTarget(o.mapSize.width,o.mapSize.height,{format:u.paN,type:u.ix0,depth:d.depth,depthBuffer:!1}),d._vsmShadowMapHorizontal.texture.name="VSMHorizontal"),this.vsmShadowMapHorizontal=d._vsmShadowMapHorizontal):(this.vsmShadowMapVertical=e.createRenderTarget(o.mapSize.width,o.mapSize.height,{format:u.paN,type:u.ix0,depthBuffer:!1}),this.vsmShadowMapHorizontal=e.createRenderTarget(o.mapSize.width,o.mapSize.height,{format:u.paN,type:u.ix0,depthBuffer:!1}));let t=i3(l);l.isArrayTexture&&(t=t.depth(this.depthLayer));let r=i3(this.vsmShadowMapVertical.texture);l.isArrayTexture&&(r=r.depth(this.depthLayer));let i=nd("blurSamples","float",o).setGroup(tE),s=nd("radius","float",o).setGroup(tE),n=nd("mapSize","vec2",o).setGroup(tE),a=ie(e.getSharedContext()),h=this.vsmMaterialVertical||(this.vsmMaterialVertical=new of);h.contextNode=a,h.fragmentNode=hI({samples:i,radius:s,size:n,shadowPass:t,depthLayer:this.depthLayer}),h.name="VSMVertical",(h=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new of)).contextNode=a,h.fragmentNode=hV({samples:i,radius:s,size:n,shadowPass:r,depthLayer:this.depthLayer}),h.name="VSMHorizontal"}let p=nd("intensity","float",o).setGroup(tE),m=nd("normalBias","float",o).setGroup(tE),g=hx(a),f=s3.mul(m);t=!s.highPrecision||e.material.receivedShadowPositionNode||e.context.shadowPositionWorld?g.mul(hU.add(f)):tB("mat4").onObjectUpdate(({object:e},t)=>t.value.multiplyMatrices(g.value,e.matrixWorld)).mul(sz).add(g.mul(eX(f,0)));let b=this.setupShadowCoord(e,t),y=o.filterNode||this.getShadowFilterFn(s.shadowMap.type)||null;if(null===y)throw Error("THREE.WebGPURenderer: Shadow map type not supported yet.");let x=h===u.RyA&&!0!==o.isPointLightShadow?this.vsmShadowMapHorizontal.texture:l,T=this.setupShadowFilter(e,{filterFn:y,shadowTexture:d.texture,depthTexture:x,shadowCoord:b,shadow:o,depthLayer:this.depthLayer});!0===s.shadowMap.transmitted&&(d.texture.isCubeTexture?r=nl(d.texture,b.xyz):(r=i3(d.texture,b),l.isArrayTexture&&(r=r.depth(this.depthLayer)))),i=r?r0(1,T.rgb.mix(r,1),p.mul(r.a)).toVar():r0(1,T,p).toVar(),this.shadowMap=d,this.shadow.map=d;let _=`${this.light.type} Shadow [ ${this.light.name||"ID: "+this.light.id} ]`;return r&&i.toInspector(`${_} / Color`,()=>this.shadowMap.texture.isCubeTexture?nl(this.shadowMap.texture,oB()):i3(this.shadowMap.texture)),i.toInspector(`${_} / Depth`,()=>{let e,t=nd("near","float",this.shadow.camera),r=nd("far","float",this.shadow.camera);return e=this.shadowMap.texture.isCubeTexture?nl(this.shadowMap.depthTexture,oB()).r:i3(this.shadowMap.depthTexture).r,oi(this.shadow.camera.isPerspectiveCamera?oa(e,t,r):os(e,t,r),t,r).oneMinus()})}setup(e){if(!1!==e.renderer.shadowMap.enabled)return eF(()=>{let t=e.renderer.shadowMap.type;this._currentShadowType!==t&&(this._reset(),this._node=null);let r=this._node;return this.setupShadowPosition(e),null===r&&(this._node=r=this.setupShadow(e),this._currentShadowType=t),e.material.receivedShadowNode&&(r=e.material.receivedShadowNode(r)),r})()}renderShadow(e){let{shadow:t,shadowMap:r,light:i}=this,{renderer:s,scene:n}=e;t.updateMatrices(i),r.setSize(t.mapSize.width,t.mapSize.height,r.depth);let a=n.name;n.name=`Shadow Map [ ${i.name||"ID: "+i.id} ]`,s.render(n,t.camera),n.name=a}updateShadow(e){var t,r,i;let{shadowMap:s,shadow:n}=this,{renderer:o,scene:l,camera:d}=e,h=o.shadowMap.type,c=s.depthTexture.version;this._depthVersionCached=c;let p=n.camera.layers.mask;(0xfffffffe&n.camera.layers.mask)==0&&(n.camera.layers.mask=d.layers.mask);let m=o.getRenderObjectFunction();r=function(e,t={}){return t.background=e.background,t.backgroundNode=e.backgroundNode,t.overrideMaterial=e.overrideMaterial,t}(l,r=t=dJ(o,a)),l.background=null,l.backgroundNode=null,l.overrideMaterial=null,a=r,l.overrideMaterial=this.getShadowMaterial(),o.setRenderObjectFunction(this.getShadowRenderObjectFunction(o,this.shadow||this.light.shadow)),o.setClearColor(0,0),o.setRenderTarget(s),this.renderShadow(e),o.setRenderObjectFunction(m),h===u.RyA&&!0!==n.isPointLightShadow&&this.vsmPass(o),n.camera.layers.mask=p,d0(o,i=a),l.background=i.background,l.backgroundNode=i.backgroundNode,l.overrideMaterial=i.overrideMaterial}vsmPass(e){let{shadow:t}=this,r=this.shadowMap.depth;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height,r),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height,r),e.setRenderTarget(this.vsmShadowMapVertical),hk.material=this.vsmMaterialVertical,hk.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),hk.material=this.vsmMaterialHorizontal,hk.render(e)}dispose(){this._reset(),super.dispose()}_reset(){this._currentShadowType=null,this.disposeShadowMaterial(),this.shadowMap&&(this.shadowMap.dispose(),this.shadowMap=null),null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null)}updateBefore(e){if(!0===e.renderer._isPreCompiling)return;let{shadow:t}=this,r=t.needsUpdate||t.autoUpdate;r&&(this._cameraFrameId.get(e.camera)===e.frameId&&(r=!1),this._cameraFrameId.set(e.camera,e.frameId)),r&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}let h$=new u.Q1f,hW=new u.kn4,hH=new u.Pq0,hq=new u.Pq0,hj=[new u.Pq0(1,0,0),new u.Pq0(-1,0,0),new u.Pq0(0,-1,0),new u.Pq0(0,1,0),new u.Pq0(0,0,1),new u.Pq0(0,0,-1)],hX=[new u.Pq0(0,-1,0),new u.Pq0(0,-1,0),new u.Pq0(0,0,-1),new u.Pq0(0,0,1),new u.Pq0(0,-1,0),new u.Pq0(0,-1,0)],hK=[new u.Pq0(1,0,0),new u.Pq0(-1,0,0),new u.Pq0(0,1,0),new u.Pq0(0,-1,0),new u.Pq0(0,0,1),new u.Pq0(0,0,-1)],hQ=[new u.Pq0(0,-1,0),new u.Pq0(0,-1,0),new u.Pq0(0,0,1),new u.Pq0(0,0,-1),new u.Pq0(0,-1,0),new u.Pq0(0,-1,0)],hY=eF(({depthTexture:e,bd3D:t,dp:r})=>nl(e,t).compare(r)),hZ=eF(({depthTexture:e,bd3D:t,dp:r,shadow:i})=>{let s=nd("radius","float",i).setGroup(tE),n=nd("mapSize","vec2",i).setGroup(tE),a=s.div(n.x),o=rE(t),l=rp(rX(t,o.x.greaterThan(o.z).select(eW(0,1,0),eW(1,0,0)))),u=rX(t,l),d=d1(sa.xy).mul(6.28318530718),h=d2(0,5,d),c=d2(1,5,d),p=d2(2,5,d),m=d2(3,5,d),g=d2(4,5,d);return nl(e,t.add(l.mul(h.x).add(u.mul(h.y)).mul(a))).compare(r).add(nl(e,t.add(l.mul(c.x).add(u.mul(c.y)).mul(a))).compare(r)).add(nl(e,t.add(l.mul(p.x).add(u.mul(p.y)).mul(a))).compare(r)).add(nl(e,t.add(l.mul(m.x).add(u.mul(m.y)).mul(a))).compare(r)).add(nl(e,t.add(l.mul(g.x).add(u.mul(g.y)).mul(a))).compare(r)).mul(.2)}),hJ=eF(({filterFn:e,depthTexture:t,shadowCoord:r,shadow:i},s)=>{let n=r.xyz.toConst(),a=n.abs().toConst(),o=a.x.max(a.y).max(a.z),l=tB("float").setGroup(tE).onRenderUpdate(()=>i.camera.near),u=tB("float").setGroup(tE).onRenderUpdate(()=>i.camera.far),d=nd("bias","float",i).setGroup(tE),h=eD(1).toVar();return eU(o.sub(u).lessThanEqual(0).and(o.sub(l).greaterThanEqual(0)),()=>{let r;s.renderer.reversedDepthBuffer?(r=((e,t,r)=>t.mul(e.add(r)).div(e.mul(t.sub(r))))(o.negate(),l,u)).subAssign(d):s.renderer.logarithmicDepthBuffer?(r=oo(o.negate(),l,u)).addAssign(d):(r=on(o.negate(),l,u)).addAssign(d);let a=n.normalize();h.assign(e({depthTexture:t,bd3D:a,dp:r,shadow:i}))}),h});class h0 extends hz{static get type(){return"PointShadowNode"}constructor(e,t=null){super(e,t)}getShadowFilterFn(e){return e===u.bTm?hY:hZ}setupShadowCoord(e,t){return t}setupShadowFilter(e,{filterFn:t,depthTexture:r,shadowCoord:i,shadow:s}){return hJ({filterFn:t,depthTexture:r,shadowCoord:i,shadow:s})}setupRenderTarget(e,t){let r=new u.Gc6(e.mapSize.width);r.name="PointShadowDepthTexture",r.compareFunction=t.renderer.reversedDepthBuffer?u.gWB:u.TiK;let i=t.createCubeRenderTarget(e.mapSize.width);return i.texture.name="PointShadowMap",i.depthTexture=r,{shadowMap:i,depthTexture:r}}renderShadow(e){let{shadow:t,shadowMap:r,light:i}=this,{renderer:s,scene:n}=e,a=t.camera,o=t.matrix,l=s.coordinateSystem===u.i7u,d=l?hj:hK,h=l?hX:hQ;r.setSize(t.mapSize.width,t.mapSize.width);let c=s.autoClear,p=s.getClearColor(h$),m=s.getClearAlpha();s.autoClear=!1,s.setClearColor(t.clearColor,t.clearAlpha);for(let e=0;e<6;e++){s.setRenderTarget(r,e),s.clear();let l=i.distance||a.far;l!==a.far&&(a.far=l,a.updateProjectionMatrix()),hH.setFromMatrixPosition(i.matrixWorld),a.position.copy(hH),hq.copy(a.position),hq.add(d[e]),a.up.copy(h[e]),a.lookAt(hq),a.updateMatrixWorld(),o.makeTranslation(-hH.x,-hH.y,-hH.z),hW.multiplyMatrices(a.projectionMatrix,a.matrixWorldInverse),t._frustum.setFromProjectionMatrix(hW,a.coordinateSystem,a.reversedDepth);let u=n.name;n.name=`Point Light Shadow [ ${i.name||"ID: "+i.id} ] - Face ${e+1}`,s.render(n,a),n.name=u}s.autoClear=c,s.setClearColor(p,m)}}class h1 extends a0{static get type(){return"AnalyticLightNode"}constructor(e=null){super(),this.light=e,this.color=new u.Q1f,this.colorNode=e&&e.colorNode||tB(this.color).setGroup(tE),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0,this.updateType=B.FRAME,e&&e.shadow&&(this._shadowDisposeListener=()=>{this.disposeShadow()},e.addEventListener("dispose",this._shadowDisposeListener))}dispose(){this._shadowDisposeListener&&this.light.removeEventListener("dispose",this._shadowDisposeListener),super.dispose()}disposeShadow(){null!==this.shadowNode&&(this.shadowNode.dispose(),this.shadowNode=null),this.shadowColorNode=null,null!==this.baseColorNode&&(this.colorNode=this.baseColorNode,this.baseColorNode=null)}getHash(){return this.light.uuid}getLightVector(e){return h_(this.light).sub(e.context.positionView||sq)}setupDirect(){}setupDirectRectArea(){}setupShadowNode(){let e;return new hz(this.light,e)}setupShadow(e){let{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let r=this.shadowColorNode;if(null===r){let e,t=this.light.shadow.shadowNode;e=void 0!==t?eS(t):this.setupShadowNode(),this.shadowNode=e,this.shadowColorNode=r=this.colorNode.mul(e),this.baseColorNode=this.colorNode}e.context.getShadow&&(r=e.context.getShadow(this,e)),this.colorNode=r}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&(this.shadowNode.dispose(),this.shadowNode=null,this.shadowColorNode=null);let t=this.setupDirect(e),r=this.setupDirectRectArea(e);t&&e.lightsNode.setupDirectLight(e,this,t),r&&e.lightsNode.setupDirectRectAreaLight(e,this,r)}update(){let{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}let h2=eF(({lightDistance:e,cutoffDistance:t,decayExponent:r})=>{let i=e.pow(r).max(.01).reciprocal();return t.greaterThan(0).select(i.mul(e.div(t).pow4().oneMinus().clamp().pow2()),i)});class h3 extends h1{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=tB(0).setGroup(tE),this.decayExponentNode=tB(2).setGroup(tE)}update(e){let{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setupShadowNode(){let e;return new h0(this.light,e)}setupDirect(e){return(({color:e,lightVector:t,cutoffDistance:r,decayExponent:i})=>{let s=t.normalize(),n=h2({lightDistance:t.length(),cutoffDistance:r,decayExponent:i});return{lightDirection:s,lightColor:e.mul(n)}})({color:this.colorNode,lightVector:this.getLightVector(e),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode})}}let h4=eF(([e,t,r])=>{let i=eD(r).toVar(),s=eD(t).toVar();return r9(eV(e).toVar(),s,i).uniformFlow()}).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),h8=eF(([e,t])=>{let r=eV(t).toVar(),i=eD(e).toVar();return r9(r,i.negate(),i).uniformFlow()}).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),h5=eF(([e])=>eO(rh(eD(e).toVar()))).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),h6=eF(([e,t])=>{let r=eD(e).toVar();return t.assign(h5(r)),r.sub(eD(t))}),h9=(e,t,r,i,s,n)=>{let a=eD(tI(1,s)).toVar();return tI(1,n).mul(e.mul(a).add(t.mul(s))).add(n.mul(r.mul(a).add(i.mul(s))))},h7=(e,t,r,i,s,n,a,o,l,u,d)=>{let h=eD(tI(1,l)).toVar(),c=eD(tI(1,u)).toVar();return eD(tI(1,d)).toVar().mul(c.mul(e.mul(h).add(t.mul(l))).add(u.mul(r.mul(h).add(i.mul(l))))).add(d.mul(c.mul(s.mul(h).add(n.mul(l))).add(u.mul(a.mul(h).add(o.mul(l))))))},ce=dU([eF(([e,t,r,i,s,n])=>{let a=eD(n).toVar(),o=eD(s).toVar(),l=eD(i).toVar(),u=eD(r).toVar(),d=eD(t).toVar();return h9(eD(e).toVar(),d,u,l,o,a)}).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),eF(([e,t,r,i,s,n])=>{let a=eD(n).toVar(),o=eD(s).toVar(),l=eW(i).toVar(),u=eW(r).toVar(),d=eW(t).toVar();return h9(eW(e).toVar(),d,u,l,o,a)}).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),ct=dU([eF(([e,t,r,i,s,n,a,o,l,u,d])=>{let h=eD(d).toVar(),c=eD(u).toVar(),p=eD(l).toVar(),m=eD(o).toVar(),g=eD(a).toVar(),f=eD(n).toVar(),b=eD(s).toVar(),y=eD(i).toVar(),x=eD(r).toVar(),T=eD(t).toVar();return h7(eD(e).toVar(),T,x,y,b,f,g,m,p,c,h)}).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),eF(([e,t,r,i,s,n,a,o,l,u,d])=>{let h=eD(d).toVar(),c=eD(u).toVar(),p=eD(l).toVar(),m=eW(o).toVar(),g=eW(a).toVar(),f=eW(n).toVar(),b=eW(s).toVar(),y=eW(i).toVar(),x=eW(r).toVar(),T=eW(t).toVar();return h7(eW(e).toVar(),T,x,y,b,f,g,m,p,c,h)}).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),cr=dU([eF(([e,t,r])=>{let i=eD(r).toVar(),s=eD(t).toVar(),n=eI(e).toVar(),a=eI(n.bitAnd(eI(7))).toVar(),o=eD(h4(a.lessThan(eI(4)),s,i)).toVar(),l=eD(tV(2,h4(a.lessThan(eI(4)),i,s))).toVar();return h8(o,eV(a.bitAnd(eI(1)))).add(h8(l,eV(a.bitAnd(eI(2)))))}).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),eF(([e,t,r,i])=>{let s=eD(i).toVar(),n=eD(r).toVar(),a=eD(t).toVar(),o=eI(e).toVar(),l=eI(o.bitAnd(eI(15))).toVar(),u=eD(h4(l.lessThan(eI(8)),a,n)).toVar(),d=eD(h4(l.lessThan(eI(4)),n,h4(l.equal(eI(12)).or(l.equal(eI(14))),a,s))).toVar();return h8(u,eV(l.bitAnd(eI(1)))).add(h8(d,eV(l.bitAnd(eI(2)))))}).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]})]),ci=dU([eF(([e,t,r])=>{let i=eD(r).toVar(),s=eD(t).toVar(),n=eq(e).toVar();return eW(cr(n.x,s,i),cr(n.y,s,i),cr(n.z,s,i))}).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),eF(([e,t,r,i])=>{let s=eD(i).toVar(),n=eD(r).toVar(),a=eD(t).toVar(),o=eq(e).toVar();return eW(cr(o.x,a,n,s),cr(o.y,a,n,s),cr(o.z,a,n,s))}).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]})]),cs=eF(([e])=>tV(.6616,eD(e).toVar())).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),cn=eF(([e])=>tV(.982,eD(e).toVar())).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),ca=dU([cs,eF(([e])=>tV(.6616,eW(e).toVar())).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),co=dU([cn,eF(([e])=>tV(.982,eW(e).toVar())).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),cl=eF(([e,t])=>{let r=eO(t).toVar(),i=eI(e).toVar();return i.shiftLeft(r).bitOr(i.shiftRight(eO(32).sub(r)))}).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),cu=eF(([e,t,r])=>(e=eI(e).toVar(),t=eI(t).toVar(),r=eI(r).toVar(),e.subAssign(r),e.bitXorAssign(cl(r,eO(4))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(cl(e,eO(6))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(cl(t,eO(8))),t.addAssign(e),e.subAssign(r),e.bitXorAssign(cl(r,eO(16))),r.addAssign(t),t.subAssign(e),t.bitXorAssign(cl(e,eO(19))),e.addAssign(r),r.subAssign(t),r.bitXorAssign(cl(t,eO(4))),t.addAssign(e),eq(e,t,r))).setLayout({name:"mx_bjmix",type:"uvec3",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),cd=eF(([e,t,r])=>{let i=eI(r).toVar(),s=eI(t).toVar(),n=eI(e).toVar();return i.bitXorAssign(s),i.subAssign(cl(s,eO(14))),n.bitXorAssign(i),n.subAssign(cl(i,eO(11))),s.bitXorAssign(n),s.subAssign(cl(n,eO(25))),i.bitXorAssign(s),i.subAssign(cl(s,eO(16))),n.bitXorAssign(i),n.subAssign(cl(i,eO(4))),s.bitXorAssign(n),s.subAssign(cl(n,eO(14))),i.bitXorAssign(s),i.subAssign(cl(s,eO(24))),i}).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),ch=eF(([e])=>eD(eI(e).toVar()).div(eD(eI(0xffffffff)))).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),cc=eF(([e])=>{let t=eD(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))}).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),cp=eF(([e])=>{let t=eO(e).toVar(),r=eI(eI(1)).toVar(),i=eI(eI(0xdeadbeef).add(r.shiftLeft(eI(2))).add(eI(13))).toVar();return cd(i.add(eI(t)),i,i)}).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),cm=eF(([e,t])=>{let r=eO(t).toVar(),i=eO(e).toVar(),s=eI(eI(2)).toVar(),n=eI().toVar(),a=eI().toVar(),o=eI().toVar();return n.assign(a.assign(o.assign(eI(0xdeadbeef).add(s.shiftLeft(eI(2))).add(eI(13))))),n.addAssign(eI(i)),a.addAssign(eI(r)),cd(n,a,o)}).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),cg=eF(([e,t,r])=>{let i=eO(r).toVar(),s=eO(t).toVar(),n=eO(e).toVar(),a=eI(eI(3)).toVar(),o=eI().toVar(),l=eI().toVar(),u=eI().toVar();return o.assign(l.assign(u.assign(eI(0xdeadbeef).add(a.shiftLeft(eI(2))).add(eI(13))))),o.addAssign(eI(n)),l.addAssign(eI(s)),u.addAssign(eI(i)),cd(o,l,u)}).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),cf=dU([cp,cm,cg,eF(([e,t,r,i])=>{let s=eO(i).toVar(),n=eO(r).toVar(),a=eO(t).toVar(),o=eO(e).toVar(),l=eI(eI(4)).toVar(),u=eI().toVar(),d=eI().toVar(),h=eI().toVar();u.assign(d.assign(h.assign(eI(0xdeadbeef).add(l.shiftLeft(eI(2))).add(eI(13))))),u.addAssign(eI(o)),d.addAssign(eI(a)),h.addAssign(eI(n));let c=eq(cu(u,d,h)).toVar();return u.assign(c.x),d.assign(c.y),h.assign(c.z),u.addAssign(eI(s)),cd(u,d,h)}).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),eF(([e,t,r,i,s])=>{let n=eO(s).toVar(),a=eO(i).toVar(),o=eO(r).toVar(),l=eO(t).toVar(),u=eO(e).toVar(),d=eI(eI(5)).toVar(),h=eI().toVar(),c=eI().toVar(),p=eI().toVar();h.assign(c.assign(p.assign(eI(0xdeadbeef).add(d.shiftLeft(eI(2))).add(eI(13))))),h.addAssign(eI(u)),c.addAssign(eI(l)),p.addAssign(eI(o));let m=eq(cu(h,c,p)).toVar();return h.assign(m.x),c.assign(m.y),p.assign(m.z),h.addAssign(eI(a)),c.addAssign(eI(n)),cd(h,c,p)}).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),cb=dU([eF(([e,t])=>{let r=eO(t).toVar(),i=eI(cf(eO(e).toVar(),r)).toVar(),s=eq().toVar();return s.x.assign(i.bitAnd(eO(255))),s.y.assign(i.shiftRight(eO(8)).bitAnd(eO(255))),s.z.assign(i.shiftRight(eO(16)).bitAnd(eO(255))),s}).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),eF(([e,t,r])=>{let i=eO(r).toVar(),s=eO(t).toVar(),n=eI(cf(eO(e).toVar(),s,i)).toVar(),a=eq().toVar();return a.x.assign(n.bitAnd(eO(255))),a.y.assign(n.shiftRight(eO(8)).bitAnd(eO(255))),a.z.assign(n.shiftRight(eO(16)).bitAnd(eO(255))),a}).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),cy=dU([eF(([e])=>{let t=eG(e).toVar(),r=eO().toVar(),i=eO().toVar(),s=eD(h6(t.x,r)).toVar(),n=eD(h6(t.y,i)).toVar(),a=eD(cc(s)).toVar(),o=eD(cc(n)).toVar();return ca(eD(ce(cr(cf(r,i),s,n),cr(cf(r.add(eO(1)),i),s.sub(1),n),cr(cf(r,i.add(eO(1))),s,n.sub(1)),cr(cf(r.add(eO(1)),i.add(eO(1))),s.sub(1),n.sub(1)),a,o)).toVar())}).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),eF(([e])=>{let t=eW(e).toVar(),r=eO().toVar(),i=eO().toVar(),s=eO().toVar(),n=eD(h6(t.x,r)).toVar(),a=eD(h6(t.y,i)).toVar(),o=eD(h6(t.z,s)).toVar(),l=eD(cc(n)).toVar(),u=eD(cc(a)).toVar(),d=eD(cc(o)).toVar();return co(eD(ct(cr(cf(r,i,s),n,a,o),cr(cf(r.add(eO(1)),i,s),n.sub(1),a,o),cr(cf(r,i.add(eO(1)),s),n,a.sub(1),o),cr(cf(r.add(eO(1)),i.add(eO(1)),s),n.sub(1),a.sub(1),o),cr(cf(r,i,s.add(eO(1))),n,a,o.sub(1)),cr(cf(r.add(eO(1)),i,s.add(eO(1))),n.sub(1),a,o.sub(1)),cr(cf(r,i.add(eO(1)),s.add(eO(1))),n,a.sub(1),o.sub(1)),cr(cf(r.add(eO(1)),i.add(eO(1)),s.add(eO(1))),n.sub(1),a.sub(1),o.sub(1)),l,u,d)).toVar())}).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),cx=dU([eF(([e])=>{let t=eG(e).toVar(),r=eO().toVar(),i=eO().toVar(),s=eD(h6(t.x,r)).toVar(),n=eD(h6(t.y,i)).toVar(),a=eD(cc(s)).toVar(),o=eD(cc(n)).toVar();return ca(eW(ce(ci(cb(r,i),s,n),ci(cb(r.add(eO(1)),i),s.sub(1),n),ci(cb(r,i.add(eO(1))),s,n.sub(1)),ci(cb(r.add(eO(1)),i.add(eO(1))),s.sub(1),n.sub(1)),a,o)).toVar())}).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),eF(([e])=>{let t=eW(e).toVar(),r=eO().toVar(),i=eO().toVar(),s=eO().toVar(),n=eD(h6(t.x,r)).toVar(),a=eD(h6(t.y,i)).toVar(),o=eD(h6(t.z,s)).toVar(),l=eD(cc(n)).toVar(),u=eD(cc(a)).toVar(),d=eD(cc(o)).toVar();return co(eW(ct(ci(cb(r,i,s),n,a,o),ci(cb(r.add(eO(1)),i,s),n.sub(1),a,o),ci(cb(r,i.add(eO(1)),s),n,a.sub(1),o),ci(cb(r.add(eO(1)),i.add(eO(1)),s),n.sub(1),a.sub(1),o),ci(cb(r,i,s.add(eO(1))),n,a,o.sub(1)),ci(cb(r.add(eO(1)),i,s.add(eO(1))),n.sub(1),a,o.sub(1)),ci(cb(r,i.add(eO(1)),s.add(eO(1))),n,a.sub(1),o.sub(1)),ci(cb(r.add(eO(1)),i.add(eO(1)),s.add(eO(1))),n.sub(1),a.sub(1),o.sub(1)),l,u,d)).toVar())}).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),cT=eF(([e])=>ch(cf(eO(h5(eD(e).toVar())).toVar()))).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),c_=eF(([e])=>{let t=eG(e).toVar();return ch(cf(eO(h5(t.x)).toVar(),eO(h5(t.y)).toVar()))}).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),cv=dU([cT,c_,eF(([e])=>{let t=eW(e).toVar(),r=eO(h5(t.x)).toVar();return ch(cf(r,eO(h5(t.y)).toVar(),eO(h5(t.z)).toVar()))}).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),eF(([e])=>{let t=eX(e).toVar(),r=eO(h5(t.x)).toVar(),i=eO(h5(t.y)).toVar();return ch(cf(r,i,eO(h5(t.z)).toVar(),eO(h5(t.w)).toVar()))}).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),cS=eF(([e])=>{let t=eO(h5(eD(e).toVar())).toVar();return eW(ch(cf(t,eO(0))),ch(cf(t,eO(1))),ch(cf(t,eO(2))))}).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),cR=eF(([e])=>{let t=eG(e).toVar(),r=eO(h5(t.x)).toVar(),i=eO(h5(t.y)).toVar();return eW(ch(cf(r,i,eO(0))),ch(cf(r,i,eO(1))),ch(cf(r,i,eO(2))))}).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),cN=dU([cS,cR,eF(([e])=>{let t=eW(e).toVar(),r=eO(rh(t.x)).toVar(),i=eO(rh(t.y)).toVar(),s=eO(rh(t.z)).toVar(),n=eI(0xdeadbf0c).toVar(),a=eI().toVar(),o=eI().toVar(),l=eI().toVar();a.assign(o.assign(l.assign(n))),a.addAssign(eI(r)),o.addAssign(eI(i)),l.addAssign(eI(s));let u=eq(cu(a,o,l)).toVar(),d=cd(u.x,u.y,u.z),h=cd(tO(u.x,eI(1)),u.y,u.z),c=cd(tO(u.x,eI(2)),u.y,u.z);return eW(ch(d),ch(h),ch(c))}).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),eF(([e])=>{let t=eX(e).toVar(),r=eO(h5(t.x)).toVar(),i=eO(h5(t.y)).toVar(),s=eO(h5(t.z)).toVar(),n=eO(h5(t.w)).toVar(),a=eI(0xdeadbf10).toVar(),o=eI().toVar(),l=eI().toVar(),u=eI().toVar();o.assign(l.assign(u.assign(a))),o.addAssign(eI(r)),l.addAssign(eI(i)),u.addAssign(eI(s));let d=eq(cu(o,l,u)).toVar();return o.assign(d.x),l.assign(d.y),u.assign(d.z),o.addAssign(eI(n)),eW(ch(cd(o,l,u)),ch(cd(o,tO(l,eI(1)),u)),ch(cd(o,tO(l,eI(2)),u)))}).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),cA=eF(([e])=>{let t=eW(e).toVar(),r=eO(rh(t.x)).toVar(),i=eO(rh(t.y)).toVar(),s=eO(rh(t.z)).toVar(),n=eI(0xdeadbf0c).toVar(),a=eI().toVar(),o=eI().toVar(),l=eI().toVar();a.assign(o.assign(l.assign(n))),a.addAssign(eI(r)),o.addAssign(eI(i)),l.addAssign(eI(s));let u=eq(cu(a,o,l)).toVar(),d=cd(u.x,u.y,u.z),h=cd(tO(u.x,eI(1)),u.y,u.z),c=cd(tO(u.x,eI(2)),u.y,u.z);return eW(ch(d),ch(h),ch(c))}),cE=eF(([e,t,r,i])=>{let s=eD(i).toVar(),n=eD(r).toVar(),a=eO(t).toVar(),o=eW(e).toVar(),l=eD(0).toVar(),u=eD(1).toVar();return aX(a,()=>{l.addAssign(u.mul(cy(o))),u.mulAssign(s),o.mulAssign(n)}),l}).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),cC=eF(([e,t,r,i])=>{let s=eD(i).toVar(),n=eD(r).toVar(),a=eO(t).toVar(),o=eW(e).toVar(),l=eW(0).toVar(),u=eD(1).toVar();return aX(a,()=>{l.addAssign(u.mul(cx(o))),u.mulAssign(s),o.mulAssign(n)}),l}).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),cw=dU([eF(([e,t,r,i,s,n,a])=>{let o=eO(a).toVar(),l=eD(n).toVar(),u=eO(s).toVar(),d=eO(i).toVar(),h=eO(r).toVar(),c=eO(t).toVar(),p=eG(e).toVar(),m=eW(cN(eG(c.add(d),h.add(u)))).toVar(),g=eG(m.x,m.y).toVar();g.subAssign(.5),g.mulAssign(l),g.addAssign(.5);let f=eG(eG(eD(c),eD(h)).add(g)).toVar(),b=eG(f.sub(p)).toVar();return eU(o.equal(eO(2)),()=>rE(b.x).add(rE(b.y))),eU(o.equal(eO(3)),()=>rz(rE(b.x),rE(b.y))),rj(b,b)}).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),eF(([e,t,r,i,s,n,a,o,l])=>{let u=eO(l).toVar(),d=eD(o).toVar(),h=eO(a).toVar(),c=eO(n).toVar(),p=eO(s).toVar(),m=eO(i).toVar(),g=eO(r).toVar(),f=eO(t).toVar(),b=eW(e).toVar(),y=eW(cA(eW(f.add(p),g.add(c),m.add(h)))).toVar();y.subAssign(.5),y.mulAssign(d),y.addAssign(.5);let x=eW(eW(eD(f),eD(g),eD(m)).add(y)).toVar(),T=eW(x.sub(b)).toVar();return eU(u.equal(eO(2)),()=>rE(T.x).add(rE(T.y)).add(rE(T.z))),eU(u.equal(eO(3)),()=>rz(rE(T.x),rE(T.y),rE(T.z))),rj(T,T)}).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),cB=(e,t=1,r=0)=>cy(e).mul(t).add(r),cM=eF(([e,t,r])=>{let i=eW(e).toVar(),s=eD(t).toVar(),n=eO(r).toVar(),a=eO().toVar(),o=eO().toVar(),l=eO().toVar(),u=eW(h6(i.x,a),h6(i.y,o),h6(i.z,l)).toVar(),d=eD(1e6).toVar(),h=eW(0,0,0).toVar();return aX({start:-1,end:eO(1),name:"x",condition:"<="},({x:e})=>{aX({start:-1,end:eO(1),name:"y",condition:"<="},({y:t})=>{aX({start:-1,end:eO(1),name:"z",condition:"<="},({z:r})=>{let i=eD(cw(u,e,t,r,a,o,l,s,eO(0))).toVar(),n=eW(cA(eW(a.add(e),o.add(t),l.add(r)))).toVar();n.subAssign(.5),n.mulAssign(s),n.addAssign(.5);let c=eW(eW(eD(e),eD(t),eD(r)).add(n).sub(u)).toVar();eU(i.lessThan(d),()=>{d.assign(i),h.assign(c)})})})}),eU(n.equal(eO(1)),()=>{d.assign(cv(h.add(i)))}).Else(()=>{d.assign(ru(d))}),d}),cF=eF(([e,t,r])=>{let i=eG(e).toVar(),s=eD(t).toVar(),n=eO(r).toVar(),a=rh(i).toVar(),o=eG(rm(i.x),rm(i.y)).toVar(),l=eD(1e6).toVar(),u=eG(0,0).toVar();return aX({start:-1,end:eO(1),name:"x",condition:"<="},({x:e})=>{aX({start:-1,end:eO(1),name:"y",condition:"<="},({y:t})=>{let r=eG(eD(e),eD(t)).toVar(),i=eG(r.x.add(a.x),r.y.add(a.y)).toVar(),n=eG(cv(eW(i.x,i.y,0)),cv(eW(i.x,i.y,1))).toVar();n.subAssign(.5),n.mulAssign(s),n.addAssign(.5);let d=eG(r.add(n).sub(o)).toVar(),h=rj(d,d).toVar();eU(h.lessThan(l),()=>{l.assign(h),u.assign(d)})})}),eU(n.equal(eO(1)),()=>{l.assign(cv(u.add(i)))}).Else(()=>{l.assign(ru(l))}),l}),cL=eF(([e,t,r])=>{let i=eO(r).toVar(),s=eD(t).toVar(),n=eG(e).toVar(),a=eO().toVar(),o=eO().toVar(),l=eG(h6(n.x,a),h6(n.y,o)).toVar(),u=eG(1e6,1e6).toVar();return aX({start:-1,end:eO(1),name:"x",condition:"<="},({x:e})=>{aX({start:-1,end:eO(1),name:"y",condition:"<="},({y:t})=>{let r=eD(cw(l,e,t,a,o,s,i)).toVar();eU(r.lessThan(u.x),()=>{u.y.assign(u.x),u.x.assign(r)}).ElseIf(r.lessThan(u.y),()=>{u.y.assign(r)})})}),eU(i.equal(eO(0)),()=>{u.assign(ru(u))}),u}).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),cU=eF(([e,t,r])=>{let i=eO(r).toVar(),s=eD(t).toVar(),n=eG(e).toVar(),a=eO().toVar(),o=eO().toVar(),l=eG(h6(n.x,a),h6(n.y,o)).toVar(),u=eW(1e6,1e6,1e6).toVar();return aX({start:-1,end:eO(1),name:"x",condition:"<="},({x:e})=>{aX({start:-1,end:eO(1),name:"y",condition:"<="},({y:t})=>{let r=eD(cw(l,e,t,a,o,s,i)).toVar();eU(r.lessThan(u.x),()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(r)}).ElseIf(r.lessThan(u.y),()=>{u.z.assign(u.y),u.y.assign(r)}).ElseIf(r.lessThan(u.z),()=>{u.z.assign(r)})})}),eU(i.equal(eO(0)),()=>{u.assign(ru(u))}),u}).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),cP=dU([cU,eF(([e,t,r])=>{let i=eO(r).toVar(),s=eD(t).toVar(),n=eW(e).toVar(),a=eO().toVar(),o=eO().toVar(),l=eO().toVar(),u=eW(h6(n.x,a),h6(n.y,o),h6(n.z,l)).toVar(),d=eW(1e6,1e6,1e6).toVar();return aX({start:-1,end:eO(1),name:"x",condition:"<="},({x:e})=>{aX({start:-1,end:eO(1),name:"y",condition:"<="},({y:t})=>{aX({start:-1,end:eO(1),name:"z",condition:"<="},({z:r})=>{let n=eD(cw(u,e,t,r,a,o,l,s,i)).toVar();eU(n.lessThan(d.x),()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(n)}).ElseIf(n.lessThan(d.y),()=>{d.z.assign(d.y),d.y.assign(n)}).ElseIf(n.lessThan(d.z),()=>{d.z.assign(n)})})})}),eU(i.equal(eO(0)),()=>{d.assign(ru(d))}),d}).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]);([e,t,r,i,s,n,a,o,l,u,d,h])=>{let c=eO(e).toVar(),p=eG(t).toVar(),m=eG(r).toVar(),g=eG(i).toVar(),f=eD(s).toVar(),b=eD(n).toVar(),y=eD(a).toVar(),x=eD(o).toVar(),T=eO(l).toVar(),_=eD(u).toVar(),v=eD(d).toVar(),S=eO(h).toVar(),R=tO(tV(p,m).toVar(),g).toVar(),N=tV(tI(f,1),9e4).toVar(),A=((e,t=0)=>{e=eG(e);let r=tV(t=eD(t),Math.PI/180),i=rg(r),s=rb(r),n=e.x,a=e.y;return eG(tO(tV(s,n),tV(i,a)),tI(tV(s,a),tV(i,n)))})(R,N).toVar(),E=eW(R.x,R.y,N).toVar(),C=eD(0).toVar();eU(c.equal(eO(0)),()=>{C.assign(cB(A,.5,.5))}),eU(c.equal(eO(1)),()=>{C.assign(cv(A))}),eU(c.equal(eO(2)),()=>{C.assign(cF(R,f,S))}),eU(c.equal(eO(3)),()=>{C.assign(cE(E,T,_,v))});let w=tO(b,tV(C,tI(y,b))).toVar(),B=r1(w,b,y).toVar(),M=w.toVar();return eU(x.equal(eD(1)),()=>{M.assign(B)}),M},([e,t,r,i,s,n,a,o,l,u,d,h])=>{let c=eO(e).toVar(),p=eW(t).toVar(),m=eW(r).toVar(),g=eW(i).toVar(),f=eD(s).toVar(),b=eD(n).toVar(),y=eD(a).toVar(),x=eD(o).toVar(),T=eO(l).toVar(),_=eD(u).toVar(),v=eD(d).toVar(),S=eO(h).toVar(),R=tO(tV(p,m).toVar(),g).toVar(),N=((e,t=0,r=eW(0,1,0))=>{e=eW(e),t=eD(t);let i=rp(r=eW(r)),s=tV(t,Math.PI/180),n=rg(s),a=rb(s),o=tI(1,a);return e.mul(a).add(e.cross(i).mul(n)).add(i.mul(i.dot(e).mul(o)))})(R,tV(tI(f,1),9e4).toVar(),eW(.1,1,0)).toVar(),A=cB(N,.5,.5),E=cv(N),C=cM(R,f,S),w=cE(N,T,_,v),B=A.toVar();eU(c.equal(eO(1)),()=>{B.assign(E)}),eU(c.equal(eO(2)),()=>{B.assign(C)}),eU(c.equal(eO(3)),()=>{B.assign(w)});let M=tO(b,tV(B,tI(y,b))).toVar(),F=r1(M,b,y).toVar(),L=M.toVar();return eU(x.equal(eD(1)),()=>{L.assign(F)}),L};let cD=eF(([e,t])=>{let r=e.x,i=e.y,s=e.z,n=t.element(0).mul(.886227);return(n=(n=(n=(n=(n=(n=(n=n.add(t.element(1).mul(1.023328).mul(i))).add(t.element(2).mul(1.023328).mul(s))).add(t.element(3).mul(1.023328).mul(r))).add(t.element(4).mul(.858086).mul(r).mul(i))).add(t.element(5).mul(.858086).mul(i).mul(s))).add(t.element(6).mul(s.mul(s).mul(.743125).sub(.247708)))).add(t.element(7).mul(.858086).mul(r).mul(s))).add(t.element(8).mul(.429043).mul(tV(r,r).sub(tV(i,i))))}),cO=new dd;class cI extends uW{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,r){let i=this.renderer,s=this.nodes.getBackgroundNode(e)||e.background,n=!1;if(null===s)i._clearColor.getRGB(cO),cO.a=i._clearColor.a;else if(!0===s.isColor)s.getRGB(cO),cO.a=1,n=!0;else if(!0===s.isNode){let r=this.get(e);cO.copy(i._clearColor);let n=r.backgroundMesh;if(void 0===n){let e=eX(s).mul(d8).context({getUV:()=>d5.mul(s1),getTextureLevel:()=>d4}),t=sR.element(3).element(3).equal(1),i=tG(1,sR.element(1).element(1)).mul(3),a=t.select(sz.mul(i),sz),o=sD.mul(eX(a,0)),l=sR.mul(eX(o.xyz,1));l=l.setZ(l.w);let d=new of;d.name="Background.material",d.side=u.hsX,d.depthTest=!1,d.depthWrite=!1,d.allowOverride=!1,d.fog=!1,d.lights=!1,d.vertexNode=l,d.colorNode=e,r.backgroundMeshNode=e,r.backgroundMesh=n=new u.eaF(new u.Gu$(1,32,32),d),n.frustumCulled=!1,n.name="Background.mesh",s.addEventListener("dispose",function e(){s.removeEventListener("dispose",e),n.material.dispose(),n.geometry.dispose()})}let a=s.getCacheKey();r.backgroundCacheKey!==a&&(r.backgroundMeshNode.node=eX(s).mul(d8),r.backgroundMeshNode.needsUpdate=!0,n.material.needsUpdate=!0,r.backgroundCacheKey=a),t.unshift(n,n.geometry,n.material,0,0,null,null)}else(0,u.z3S)("Renderer: Unsupported background configuration.",s);let a=i.xr.getEnvironmentBlendMode();if("additive"===a?cO.set(0,0,0,1):"alpha-blend"===a&&cO.set(0,0,0,0),!0===i.autoClear||!0===n){let e=r.clearColorValue;e.r=cO.r,e.g=cO.g,e.b=cO.b,e.a=cO.a,(!0===i.backend.isWebGLBackend||!0===i.alpha)&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),r.depthClearValue=i.getClearDepth(),r.stencilClearValue=i.getClearStencil(),r.clearColor=!0===i.autoClearColor,r.clearDepth=!0===i.autoClearDepth,r.clearStencil=!0===i.autoClearStencil}else r.clearColor=!1,r.clearDepth=!1,r.clearStencil=!1}}let cV=0;class cG{constructor(e="",t=[]){this.name=e,this.bindings=t,this.id=cV++}}class ck{constructor(e,t,r,i,s,n,a,o,l,u,d=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=r,this.transforms=d,this.nodeAttributes=i,this.bindings=s,this.updateNodes=n,this.updateBeforeNodes=a,this.updateAfterNodes=o,this.observer=l,this.hardwareClipping=u,this.usedTimes=0}createBindings(){let e=[];for(let t of this.bindings)if(!0!==t.bindings[0].groupNode.shared){let r=new cG(t.name,[]);for(let i of(e.push(r),t.bindings))r.bindings.push(i.clone())}else e.push(t);return e}}class cz{constructor(e,t,r=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=r}}class c${constructor(e,t,r){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=r}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class cW{constructor(e,t,r=!1,i=null){this.isNodeVar=!0,this.name=e,this.type=t,this.readOnly=r,this.count=i}}class cH extends cW{constructor(e,t,r=null,i=null){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0,this.interpolationType=r,this.interpolationSampling=i}}class cq{constructor(e,t,r=""){this.name=e,this.type=t,this.code=r,Object.defineProperty(this,"isNodeCode",{value:!0})}}let cj=0;class cX{constructor(e=null){this.id=cj++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class cK{constructor(e,t){this.name=e,this.members=t,this.output=!1}}class cQ{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0,this.index=-1}setValue(e){this.value=e}getValue(){return this.value}}class cY extends cQ{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class cZ extends cQ{constructor(e,t=new u.I9Y){super(e,t),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class cJ extends cQ{constructor(e,t=new u.Pq0){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class c0 extends cQ{constructor(e,t=new u.IUQ){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class c1 extends cQ{constructor(e,t=new u.Q1f){super(e,t),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class c2 extends cQ{constructor(e,t=new u.k_V){super(e,t),this.isMatrix2Uniform=!0,this.boundary=8,this.itemSize=4}}class c3 extends cQ{constructor(e,t=new u.dwI){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class c4 extends cQ{constructor(e,t=new u.kn4){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class c8 extends cY{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class c5 extends cZ{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class c6 extends cJ{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class c9 extends c0{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class c7 extends c1{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class pe extends c2{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class pt extends c3{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}class pr extends c4{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}getType(){return this.nodeUniform.type}}let pi=0,ps=new WeakMap,pn=new WeakMap,pa=new WeakMap,po=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),pl=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0"),pu=e=>{if(e.writeUsageCount>0)return!0;if(void 0!==e.subBuildsCache){for(let t in e.subBuildsCache)if(pu(e.subBuildsCache[t]))return!0}return!1};class pd{constructor(e,t,r){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.compute=null,this.renderer=t,this.parser=r,this.scene=null,this.camera=null,this.nodes=new Set,this.sequentialNodes=new Set,this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.observer=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.hardwareClipping=!1,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.types={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.declarations={},this.flow={code:""},this.chaining=[],this.stack=dm(),this.stacks=[],this.tab=" ",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new cX,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.subBuildLayers=[],this.activeStacks=[],this.subBuildFn=null,this.fnCall=null,Object.defineProperty(this,"id",{value:pi++})}isFlatShading(){return!0===this.material.flatShading||!1===this.geometry.hasAttribute("normal")}isOpaque(){let e=this.material;return!1===e.transparent&&e.blending===u.NTi&&!1===e.alphaToCoverage}createRenderTarget(e,t,r){return new u.O0B(e,t,r)}createCubeRenderTarget(e,t){return new oM(e,t)}includes(e){return this.nodes.has(e)}getOutputType(e=0){let t=this.renderer.getRenderTarget();return null!==t?N(t.textures[e]):"vec4"}getOutputStructName(){}_getBindGroup(e,t){let r,i=t[0].groupNode,s=i.shared;if(s)for(let e=1;e<t.length;e++)i!==t[e].groupNode&&(s=!1);if(s){let i="";for(let e of t)if(e.isNodeUniformsGroup)for(let t of(e.uniforms.sort((e,t)=>e.nodeUniform.node.id-t.nodeUniform.node.id),e.uniforms))i+=t.nodeUniform.node.id;else i+=e.nodeUniform.id;let s=this.renderer._currentRenderContext||this.renderer,n=ps.get(s);void 0===n&&(n=new Map,ps.set(s,n));let a=x(i);void 0===(r=n.get(a))&&(r=new cG(e,t),n.set(a,r))}else r=new cG(e,t);return r}getBindGroupArray(e,t){let r=this.bindings[t],i=r[e];return void 0===i&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),r[e]=i=[]),i}getBindings(){let e=this.bindGroups;if(null===e){let t={},r=this.bindings;for(let e of L)for(let i in r[e]){let s=r[e][i],n=t[i]||(t[i]=[]);for(let e of s)!1===n.includes(e)&&n.push(e)}for(let r in e=[],t){let i=t[r],s=this._getBindGroup(r,i);e.push(s)}this.bindGroups=e}return e}sortBindingGroups(){let e=this.getBindings();e.sort((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order);for(let t=0;t<e.length;t++){let r=e[t];this.bindingsIndexes[r.name].group=t}}setHashNode(e,t){this.hashNodes[t]=e}addNode(e){!1===this.nodes.has(e)&&(this.nodes.add(e),this.setHashNode(e,e.getHash(this)))}addSequentialNode(e){let t=e.updateBeforeType,r=e.updateAfterType;(t!==B.NONE||r!==B.NONE)&&this.sequentialNodes.add(e)}buildUpdateNodes(){for(let e of this.nodes)e.updateType!==B.NONE&&this.updateNodes.push(e);for(let e of this.sequentialNodes){let t=e.updateBeforeType,r=e.updateAfterType;t!==B.NONE&&this.updateBeforeNodes.push(e),r!==B.NONE&&this.updateAfterNodes.push(e)}}get currentNode(){return this.chaining[this.chaining.length-1]}get renderPipeline(){return this.context.renderPipeline}isFilteredTexture(e){return e.magFilter===u.k6q||e.magFilter===u.kRr||e.magFilter===u.Cfg||e.magFilter===u.$_I||e.minFilter===u.k6q||e.minFilter===u.kRr||e.minFilter===u.Cfg||e.minFilter===u.$_I}getUniformBufferLimit(){return this.renderer.backend.capabilities.getUniformBufferLimit()}addChain(e){this.chaining.push(e)}removeChain(e){if(this.chaining.pop()!==e)throw Error("THREE.NodeBuilder: Invalid node chaining!")}getMethod(e){return e}getTernary(){return null}getNodeFromHash(e){return this.hashNodes[e]}addFlow(e,t){return this.flowNodes[e].push(t),t}setContext(e){this.context=e}getContext(){return this.context}addContext(e){let t=this.getContext();return this.setContext({...this.context,...e}),t}getSharedContext(){let e={...this.context};return delete e.material,delete e.getUV,delete e.getOutput,delete e.getTextureLevel,delete e.getAO,delete e.getGI,delete e.getShadow,e}setCache(e){this.cache=e}getCache(){return this.cache}getCacheFromNode(e,t=!0){let r=this.getDataFromNode(e);return void 0===r.cache&&(r.cache=new cX(t?this.getCache():null)),r.cache}isAvailable(){return!1}getVertexIndex(){(0,u.R8M)("Abstract function.")}getInstanceIndex(){(0,u.R8M)("Abstract function.")}getDrawIndex(){(0,u.R8M)("Abstract function.")}getFrontFacing(){(0,u.R8M)("Abstract function.")}getFragCoord(){(0,u.R8M)("Abstract function.")}isFlipY(){return!1}isContextAssign(){return!0===this.context.assign}increaseUsage(e){let t=this.getDataFromNode(e);return t.usageCount=void 0===t.usageCount?1:t.usageCount+1,this.isContextAssign()?t.writeUsageCount=void 0===t.writeUsageCount?1:t.writeUsageCount+1:t.readUsageCount=void 0===t.readUsageCount?1:t.readUsageCount+1,t.usageCount}hasWriteUsage(e){let t=e.getShared(this),r=(t.isGlobal(this)?this.globalCache:this.cache).getData(t);if(void 0!==r){for(let e in r)if(pu(r[e]))return!0}return!1}generateTexture(){(0,u.R8M)("Abstract function.")}generateTextureLod(){(0,u.R8M)("Abstract function.")}generateTextureSize(){(0,u.R8M)("Abstract function.")}generateArrayDeclaration(e,t){return this.getType(e)+"[ "+t+" ]"}generateArray(e,t,r=null){let i=this.generateArrayDeclaration(e,t)+"( ";for(let s=0;s<t;s++){let n=r?r[s]:null;null!==n?i+=n.build(this,e):i+=this.generateConst(e),s<t-1&&(i+=", ")}return i+" )"}generateStruct(e,t,r=null){let i=[];for(let e of t){let{name:t,type:s}=e;r&&r[t]&&r[t].isNode?i.push(r[t].build(this,s)):i.push(this.generateConst(s))}return e+"( "+i.join(", ")+" )"}generateConst(e,t=null){if(null===t&&("float"===e||"int"===e||"uint"===e?t=0:"bool"===e?t=!1:"color"===e?t=new u.Q1f:"vec2"===e||"uvec2"===e||"ivec2"===e?t=new u.I9Y:"vec3"===e||"uvec3"===e||"ivec3"===e?t=new u.Pq0:("vec4"===e||"uvec4"===e||"ivec4"===e)&&(t=new u.IUQ)),"float"===e)return pl(t);if("int"===e)return`${Math.round(t)}`;if("uint"===e)return t>=0?`${Math.round(t)}u`:"0u";if("bool"===e)return t?"true":"false";if("color"===e)return`${this.getType("vec3")}( ${pl(t.r)}, ${pl(t.g)}, ${pl(t.b)} )`;let r=this.getTypeLength(e),i=this.getComponentType(e),s=e=>this.generateConst(i,e);if(2===r)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)} )`;if(3===r)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)} )`;if(4===r&&"mat2"!==e)return`${this.getType(e)}( ${s(t.x)}, ${s(t.y)}, ${s(t.z)}, ${s(t.w)} )`;if(r>=4&&t&&(t.isMatrix2||t.isMatrix3||t.isMatrix4))return`${this.getType(e)}( ${t.elements.map(s).join(", ")} )`;if(r>4)return`${this.getType(e)}()`;throw Error(`THREE.NodeBuilder: Type '${e}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){let r=this.attributes;for(let t of r)if(t.name===e)return t;let i=new cz(e,t);return this.registerDeclaration(i),r.push(i),i}getPropertyName(e){return e.name}isReservedKeyword(){return!1}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"samplerComparison"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){let t=e.type;return!0===e.isDepthTexture?"float":t===u.Yuy?"int":t===u.bkx?"uint":"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;let t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;let r=v.get(e),i="float"===t?"":t[0];return!0===/mat2/.test(t)&&(r=r.replace("vec","mat")),i+r}getTypeFromArray(e){return po.get(e.constructor)}isInteger(e){return/int|uint|(i|u)vec/.test(e)}getTypeFromAttribute(e){let t,r=e;e.isInterleavedBufferAttribute&&(r=e.data);let i=r.array,s=e.itemSize,n=e.normalized;return e instanceof u.Oax||!0===n||(t=this.getTypeFromArray(i)),this.getTypeFromLength(s,t)}getTypeLength(e){let t=this.getVectorType(e),r=/vec([2-4])/.exec(t);return null!==r?Number(r[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:16*(!0===/mat4/.test(e))}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){let t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}setActiveStack(e){this.activeStacks.push(e)}removeActiveStack(e){if(this.activeStacks[this.activeStacks.length-1]===e)this.activeStacks.pop();else throw Error("THREE.NodeBuilder: Invalid active stack removal.")}getActiveStack(){return this.activeStacks[this.activeStacks.length-1]}getBaseStack(){return this.activeStacks[0]}addStack(){this.stack=dm(this.stack);let e=Q;return this.stacks.push(e),eL(this.stack),this.stack}removeStack(){let e=this.stack;for(let t of e.nodes)this.getDataFromNode(t).stack=e;return this.stack=e.parent,eL(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,r=null){let i=(r=null===r?e.isGlobal(this)?this.globalCache:this.cache:r).getData(e);void 0===i&&(i={},r.setData(e,i)),void 0===i[t]&&(i[t]={});let s=i[t];if(0===this.subBuildLayers.length)return s;let n=i.any?i.any.subBuilds:null,a=this.getClosestSubBuild(n);return a&&(void 0===s.subBuildsCache&&(s.subBuildsCache={}),(s=s.subBuildsCache[a]||(s.subBuildsCache[a]={})).subBuilds=n),s}getNodeProperties(e,t="any"){let r=this.getDataFromNode(e,t);return r.properties||(r.properties={outputNode:null})}getBufferAttributeFromNode(e,t,r=null){let i=this.getDataFromNode(e,"vertex"),s=i.bufferAttribute;if(void 0===s){let n=this.uniforms.index++;null===r&&(r="nodeAttribute"+n),s=new cz(r,t,e),this.bufferAttributes.push(s),i.bufferAttribute=s}return s}getStructTypeNode(e,t=this.shaderStage){return this.types[t][e]||null}getStructTypeFromNode(e,t,r=null,i=this.shaderStage){let s=this.getDataFromNode(e,i,this.globalCache),n=s.structType;if(void 0===n){let a=this.structs.index++;null===r&&(r="StructType"+a),n=new cK(r,t),this.structs[i].push(n),this.types[i][r]=e,s.structType=n}return n}getOutputStructTypeFromNode(e,t){let r=this.getStructTypeFromNode(e,t,"OutputType","fragment");return r.output=!0,r}getUniformFromNode(e,t,r=this.shaderStage,i=null){let s=this.getDataFromNode(e,r,this.globalCache),n=s.uniform;if(void 0===n){let a=this.uniforms.index++;n=new c$(i||"nodeUniform"+a,t,e),this.uniforms[r].push(n),this.registerDeclaration(n),s.uniform=n}return n}getVarFromNode(e,t=null,r=e.getNodeType(this),i=this.shaderStage,s=!1){let n=this.getDataFromNode(e,i),a=this.getSubBuildProperty("variable",n.subBuilds),o=n[a];if(void 0===o){let l=s?"_const":"_var",u=this.vars[i]||(this.vars[i]=[]),d=this.vars[l]||(this.vars[l]=0);null===t&&(t=(s?"nodeConst":"nodeVar")+d,this.vars[l]++),"variable"!==a&&(t=this.getSubBuildProperty(t,n.subBuilds));let h=e.getArrayCount(this);o=new cW(t,r,s,h),s||u.push(o),this.registerDeclaration(o),n[a]=o}return o}isDeterministic(e){if(e.isMathNode)return this.isDeterministic(e.aNode)&&(!e.bNode||this.isDeterministic(e.bNode))&&(!e.cNode||this.isDeterministic(e.cNode));if(e.isOperatorNode)return this.isDeterministic(e.aNode)&&(!e.bNode||this.isDeterministic(e.bNode));if(e.isArrayNode){if(null!==e.values){for(let t of e.values)if(!this.isDeterministic(t))return!1}return!0}return!!e.isConstNode||!1}getVaryingFromNode(e,t=null,r=e.getNodeType(this),i=null,s=null){let n=this.getDataFromNode(e,"any"),a=this.getSubBuildProperty("varying",n.subBuilds),o=n[a];if(void 0===o){let e=this.varyings,l=e.length;null===t&&(t="nodeVarying"+l),"varying"!==a&&(t=this.getSubBuildProperty(t,n.subBuilds)),o=new cH(t,r,i,s),e.push(o),this.registerDeclaration(o),n[a]=o}return o}registerDeclaration(e){let t=this.shaderStage,r=this.declarations[t]||(this.declarations[t]={}),i=this.renderer.debug.diagnostics.keywords,s=e.name,n=s,a=this.getPropertyName(e),o=1;for(;i&&this.isReservedKeyword(n)||void 0!==r[a];)e.name=n=s+"_"+o++,a=this.getPropertyName(e);n!==s&&(0,u.R8M)(`TSL: Declaration name '${s}' of '${e.type}' is a reserved keyword or already in use. Renamed to '${n}'.`),r[a]=e}getCodeFromNode(e,t,r=this.shaderStage){let i=this.getDataFromNode(e),s=i.code;if(void 0===s){let e=this.codes[r]||(this.codes[r]=[]);s=new cq("nodeCode"+e.length,t),e.push(s),i.code=s}return s}addFlowCodeHierarchy(e,t){let{flowCodes:r,flowCodeBlock:i}=this.getDataFromNode(e),s=!0,n=t;for(;n;){if(!0===i.get(n)){s=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(s)for(let e of r)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,r){let i=this.getDataFromNode(e),s=i.flowCodes||(i.flowCodes=[]),n=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);s.push(t),n.set(r,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+=" ",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){let t=e.getNodeType(this),r=this.flowChildNode(e,t);return this.flowsData.set(e,r),r}addInclude(e){null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(e)}buildFunctionNode(e){let t=this.renderer.backend,r=pn.get(t);void 0===r&&(r=new WeakMap,pn.set(t,r));let i=r.get(e);if(void 0===i){i=new hh;let t=this.currentFunctionNode;this.currentFunctionNode=i,i.code=this.buildFunctionCode(e),this.currentFunctionNode=t,r.set(e,i)}return i}flowShaderNode(e){let t=e.layout,r={[Symbol.iterator](){let e=0,t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(let e of t.inputs)r[e.name]=new dc(e.type,e.name);e.layout=null;let i=e.call(r),s=this.flowStagesNode(i,t.type);return e.layout=t,s}flowBuildStage(e,t,r=null){let i=this.getBuildStage();this.setBuildStage(t);let s=e.build(this,r);return this.setBuildStage(i),s}flowStagesNode(e,t=null){let r=this.flow,i=this.vars,s=this.declarations,n=this.cache,a=this.buildStage,o=this.stack,l={code:""};for(let r of(this.flow=l,this.vars={},this.declarations={},this.cache=new cX,this.stack=dm(),F))this.setBuildStage(r),l.result=e.build(this,t);return l.vars=this.getVars(this.shaderStage),this.flow=r,this.vars=i,this.declarations=s,this.cache=n,this.stack=o,this.setBuildStage(a),l}getFunctionOperator(){return null}buildFunctionCode(){(0,u.R8M)("Abstract function.")}flowChildNode(e,t=null){let r=this.flow,i={code:""};return this.flow=i,i.result=e.build(this,t),this.flow=r,i}flowNodeFromShaderStage(e,t,r=null,i=null){let s=this.tab,n=this.cache,a=this.shaderStage,o=this.context;this.setShaderStage(e);let l={...this.context};delete l.nodeBlock,this.cache=this.globalCache,this.tab=" ",this.context=l;let u=null;if("generate"===this.buildStage){let s=this.flowChildNode(t,r);null!==i&&(s.code+=`${this.tab+i} = ${s.result};
|
|
9
|
+
`),this.flowCode[e]=this.flowCode[e]+s.code,u=s}else u=t.build(this);return this.setShaderStage(a),this.cache=n,this.tab=s,this.context=o,u}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){(0,u.R8M)("Abstract function.")}getVaryings(){(0,u.R8M)("Abstract function.")}getVar(e,t,r=null){return`${null!==r?this.generateArrayDeclaration(e,r):this.getType(e)} ${t}`}getVars(e,t=!1){let r=[],i=this.vars[e];if(void 0!==i)for(let e of i)r.push(`${this.getVar(e.type,e.name,e.count)};`);return r.join(t?"\n":"\n ")}getUniforms(){(0,u.R8M)("Abstract function.")}getCodes(e){let t=this.codes[e],r="";if(void 0!==t)for(let e of t)r+=e.code+"\n";return r}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){(0,u.R8M)("Abstract function.")}get subBuild(){return this.subBuildLayers[this.subBuildLayers.length-1]||null}addSubBuild(e){this.subBuildLayers.push(e)}removeSubBuild(){return this.subBuildLayers.pop()}getClosestSubBuild(e){let t;if(!(t=e&&e.isNode?e.isShaderCallNodeInternal?e.shaderNode.subBuilds:e.isStackNode?[e.subBuild]:this.getDataFromNode(e,"any").subBuilds:e instanceof Set?[...e]:e))return null;let r=this.subBuildLayers;for(let e=t.length-1;e>=0;e--){let i=t[e];if(r.includes(i))return i}return null}getSubBuildOutput(e){return this.getSubBuildProperty("outputNode",e)}getSubBuildProperty(e="",t=null){let r;return(r=null!==t?this.getClosestSubBuild(t):this.subBuildFn)?e?r+"_"+e:r:e}prebuild(){let{renderer:e,material:t}=this;if(!0===e.contextNode.isContextNode?this.context={...this.context,...e.contextNode.getFlowContextData()}:(0,u.z3S)('NodeBuilder: "renderer.contextNode" must be an instance of `context()`.'),t&&t.contextNode&&(!0===t.contextNode.isContextNode?this.context={...this.context,...t.contextNode.getFlowContextData()}:(0,u.z3S)('NodeBuilder: "material.contextNode" must be an instance of `context()`.')),null!==t){let r=e.library.fromMaterial(t);null===r&&((0,u.z3S)(`NodeBuilder: Material "${t.type}" is not compatible.`),r=new of),r.build(this)}else this.addFlow("compute",this.compute)}build(){for(let e of(this.prebuild(),F))for(let t of(this.setBuildStage(e),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position),L))for(let r of(this.setShaderStage(t),this.flowNodes[t]))"generate"===e?this.flowNode(r):r.build(this);return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}async buildAsync(){for(let e of(this.prebuild(),F))for(let t of(this.setBuildStage(e),this.context.position&&this.context.position.isNode&&this.flowNodeFromShaderStage("vertex",this.context.position),L)){for(let r of(this.setShaderStage(t),this.flowNodes[t]))"generate"===e?this.flowNode(r):r.build(this);await (0,u.aH0)()}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getSharedDataFromNode(e){let t=pa.get(e);return void 0===t&&(t={}),t}getNodeUniform(e,t){let r=this.getSharedDataFromNode(e),i=r.cache;if(void 0===i){if("float"===t||"int"===t||"uint"===t)i=new c8(e);else if("vec2"===t||"ivec2"===t||"uvec2"===t)i=new c5(e);else if("vec3"===t||"ivec3"===t||"uvec3"===t)i=new c6(e);else if("vec4"===t||"ivec4"===t||"uvec4"===t)i=new c9(e);else if("color"===t)i=new c7(e);else if("mat2"===t)i=new pe(e);else if("mat3"===t)i=new pt(e);else if("mat4"===t)i=new pr(e);else throw Error(`THREE.NodeBuilder: Uniform "${t}" not implemented.`);r.cache=i}return i}format(e,t,r){if(t=this.getVectorType(t),r=this.getVectorType(r),t===r||null===r||this.isReference(r))return e;let i=this.getTypeLength(t),s=this.getTypeLength(r);return 16===i&&9===s?`${this.getType(r)}( ${e}[ 0 ].xyz, ${e}[ 1 ].xyz, ${e}[ 2 ].xyz )`:9===i&&4===s?`${this.getType(r)}( ${e}[ 0 ].xy, ${e}[ 1 ].xy )`:i>4||s>4||0===s?e:i===s?`${this.getType(r)}( ${e} )`:i>s?(e="bool"===r?`all( ${e} )`:`${e}.${"xyz".slice(0,s)}`,this.format(e,this.getTypeFromLength(s,this.getComponentType(t)),r)):4===s&&i>1?`${this.getType(r)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===i?`${this.getType(r)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===i&&s>1&&t!==this.getComponentType(r)&&(e=`${this.getType(this.getComponentType(r))}( ${e} )`),`${this.getType(r)}( ${e} )`)}getSignature(){return`// Three.js r${u.sPf} - Node System
|
|
10
|
+
`}needsPreviousData(){let e=this.renderer.getMRT();return e&&e.has("velocity")||null!==this.object&&!0===E(this.object).useVelocity}}class ph{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null,this.compute=null}_getMaps(e,t){let r=e.get(t);return void 0===r&&(r={renderId:0,frameId:0},e.set(t,r)),r}updateBeforeNode(e){let t=e.getUpdateBeforeType(this),r=e.updateReference(this);if(t===B.FRAME){let t=this._getMaps(this.updateBeforeMap,r);if(t.frameId!==this.frameId){let r=t.frameId;t.frameId=this.frameId,!1===e.updateBefore(this)&&(t.frameId=r)}}else if(t===B.RENDER){let t=this._getMaps(this.updateBeforeMap,r);if(t.renderId!==this.renderId){let r=t.renderId;t.renderId=this.renderId,!1===e.updateBefore(this)&&(t.renderId=r)}}else t===B.OBJECT&&e.updateBefore(this)}updateAfterNode(e){let t=e.getUpdateAfterType(this),r=e.updateReference(this);if(t===B.FRAME){let t=this._getMaps(this.updateAfterMap,r);t.frameId!==this.frameId&&!1!==e.updateAfter(this)&&(t.frameId=this.frameId)}else if(t===B.RENDER){let t=this._getMaps(this.updateAfterMap,r);t.renderId!==this.renderId&&!1!==e.updateAfter(this)&&(t.renderId=this.renderId)}else t===B.OBJECT&&e.updateAfter(this)}updateNode(e){let t=e.getUpdateType(this),r=e.updateReference(this);if(t===B.FRAME){let t=this._getMaps(this.updateMap,r);t.frameId!==this.frameId&&!1!==e.update(this)&&(t.frameId=this.frameId)}else if(t===B.RENDER){let t=this._getMaps(this.updateMap,r);t.renderId!==this.renderId&&!1!==e.update(this)&&(t.renderId=this.renderId)}else t===B.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class pc{constructor(e,t,r=null,i="",s=!1){this.type=e,this.name=t,this.count=r,this.qualifier=i,this.isConst=s}}pc.isNodeFunctionInput=!0;class pp extends h1{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class pm extends h1{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setupDirect(){let e=this.colorNode;return{lightDirection:hv(this.light),lightColor:e}}}class pg extends h1{static get type(){return"HemisphereLightNode"}constructor(e=null){super(e),this.lightPositionNode=hT(e),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=tB(new u.Q1f).setGroup(tE)}update(e){let{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){let{colorNode:t,groundColorNode:r,lightDirectionNode:i}=this,s=r0(r,t,s3.dot(i).mul(.5).add(.5));e.context.irradiance.addAssign(s)}}class pf extends h1{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=tB(0).setGroup(tE),this.penumbraCosNode=tB(0).setGroup(tE),this.cutoffDistanceNode=tB(0).setGroup(tE),this.decayExponentNode=tB(0).setGroup(tE),this.colorNode=tB(this.color).setGroup(tE)}update(e){super.update(e);let{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e,t){let{coneCosNode:r,penumbraCosNode:i}=this;return r4(r,i,t)}getLightCoord(e){let t=e.getNodeProperties(this),r=t.projectionUV;return void 0===r&&(t.projectionUV=r=function(e,t=sW){let r=hx(e).mul(t);return r.xyz.div(r.w)}(this.light,e.context.positionWorld)),r}setupDirect(e){let t,r,{colorNode:i,cutoffDistanceNode:s,decayExponentNode:n,light:a}=this,o=this.getLightVector(e),l=o.normalize(),u=l.dot(hv(a)),d=this.getSpotAttenuation(e,u),h=h2({lightDistance:o.length(),cutoffDistance:s,decayExponent:n}),c=i.mul(d).mul(h);return a.colorNode?(r=this.getLightCoord(e),t=a.colorNode(r)):a.map&&(r=this.getLightCoord(e),t=i3(a.map,r.xy).onRenderUpdate(()=>a.map)),t&&(c=r.mul(2).sub(1).abs().lessThan(1).all().select(c.mul(t),c)),{lightColor:c,lightDirection:l}}}class pb extends pf{static get type(){return"IESSpotLightNode"}constructor(e=null){super(e),this._iesTextureNode=null}getSpotAttenuation(e,t){let r=this.light.iesMap,i=null;if(r&&!0===r.isTexture){let e=t.acos().mul(1/Math.PI);this._iesTextureNode=i3(r,eG(e,0),0),i=this._iesTextureNode.r}else i=super.getSpotAttenuation(e,t);return i}update(e){super.update(e),null!==this._iesTextureNode&&this.light.iesMap&&(this._iesTextureNode.value=this.light.iesMap)}}class py extends h1{static get type(){return"LightProbeNode"}constructor(e=null){super(e);let t=[];for(let e=0;e<9;e++)t.push(new u.Pq0);this.lightProbe=i7(t)}update(e){let{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){let t=cD(s3,this.lightProbe);e.context.irradiance.addAssign(t)}}let px=eF(([e,t])=>{let r=e.abs().sub(t);return rw(rz(r,0)).add(rk(rz(r.x,r.y),0))});class pT extends pf{static get type(){return"ProjectorLightNode"}update(e){super.update(e);let t=this.light;if(this.penumbraCosNode.value=Math.min(Math.cos(t.angle*(1-t.penumbra)),.99999),null===t.aspect){let e=1;null!==t.map&&(e=t.map.width/t.map.height),t.shadow.aspect=e}else t.shadow.aspect=t.aspect}getSpotAttenuation(e){let t=eD(0),r=this.penumbraCosNode,i=hx(this.light).mul(e.context.positionWorld||sW);return eU(i.w.greaterThan(0),()=>{let e=px(i.xyz.div(i.w).xy.sub(eG(.5)),eG(.5)),s=tG(-1,tI(1,rS(r)).sub(1));t.assign(r2(e.mul(-2).mul(s)))}),t}}let p_=new u.kn4,pv=new u.kn4,pS=null;class pR extends h1{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=tB(new u.Pq0).setGroup(tE),this.halfWidth=tB(new u.Pq0).setGroup(tE),this.updateType=B.RENDER}update(e){super.update(e);let{light:t}=this,r=e.camera.matrixWorldInverse;pv.identity(),p_.copy(t.matrixWorld),p_.premultiply(r),pv.extractRotation(p_),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(pv),this.halfHeight.value.applyMatrix4(pv)}setupDirectRectArea(e){let t,r;e.isAvailable("float32Filterable")?(t=i3(pS.LTC_FLOAT_1),r=i3(pS.LTC_FLOAT_2)):(t=i3(pS.LTC_HALF_1),r=i3(pS.LTC_HALF_2));let{colorNode:i,light:s}=this;return{lightColor:i,lightPosition:h_(s),halfWidth:this.halfWidth,halfHeight:this.halfHeight,ltc_1:t,ltc_2:r}}static setLTC(e){pS=e}}class pN{parseFunction(){(0,u.R8M)("Abstract function.")}}class pA{constructor(e,t,r="",i=""){this.type=e,this.inputs=t,this.name=r,this.precision=i}getCode(){(0,u.R8M)("Abstract function.")}}pA.isNodeFunction=!0;let pE=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,pC=/[a-z_0-9]+/ig,pw="#pragma main";class pB extends pA{constructor(e){let{type:t,inputs:r,name:i,precision:s,inputsCode:n,blockCode:a,headerCode:o}=(e=>{let t=(e=e.trim()).indexOf(pw),r=(-1!==t?e.slice(t+pw.length):e).replace(/^(?:\s*\/\/[^\r\n]*|\s*\/\*[\s\S]*?\*\/|\s*)+/,""),i=r.match(pE);if(null!==i&&5===i.length){let s=i[4],n=[],a=null;for(;null!==(a=pC.exec(s));)n.push(a);let o=[],l=0;for(;l<n.length;){let e="const"===n[l][0];!0===e&&l++;let t=n[l][0];"in"===t||"out"===t||"inout"===t?l++:t="";let r=n[l++][0],i=Number.parseInt(n[l][0]);!1===Number.isNaN(i)?l++:i=null;let s=n[l++][0];o.push(new pc(r,s,i,t,e))}let u=r.substring(i[0].length),d=void 0!==i[3]?i[3]:"",h=i[2];return{type:h,inputs:o,name:d,precision:void 0!==i[1]?i[1]:"",inputsCode:s,blockCode:u,headerCode:-1!==t?e.slice(0,t):""}}throw Error("THREE.FunctionNode: Function is not a GLSL code.")})(e);super(t,r,i,s),this.inputsCode=n,this.blockCode=a,this.headerCode=o}getCode(e=this.name){let t,r=this.blockCode;if(""!==r){let{type:i,inputsCode:s,headerCode:n,precision:a}=this,o=`${i} ${e} ( ${s.trim()} )`;""!==a&&(o=`${a} ${o}`),t=n+o+r}else t="";return t}}class pM extends pN{parseFunction(e){return new pB(e)}}let pF=[],pL=[],pU=tB(0,"int").setGroup(tE);class pP extends uW{constructor(e,t){super(),this.renderer=e,this.backend=t,this.nodeFrame=new ph,this.nodeBuilderCache=new Map,this.callHashCache=new uI,this.groupsData=new uI,this._buildQueue=[],this._buildInProgress=!1,this.cacheLib={}}updateGroup(e){let t=e.groupNode;if(t.updateType===B.OBJECT)return!0;pF[0]=t,pF[1]=e;let r=this.groupsData.get(pF);return void 0===r&&this.groupsData.set(pF,r={}),pF[0]=null,pF[1]=null,r.version!==t.version&&(r.version=t.version,!0)}getForRenderCacheKey(e){return e.initialCacheKey}_createNodeBuilder(e,t){let r=this.backend.createNodeBuilder(e.object,this.renderer),i=this.renderer.debug.onNodeBuilderCreated;return null!==i&&i(r,e),r.scene=e.scene,r.material=t,r.camera=e.camera,r.context.material=t,r.lightsNode=e.lightsNode,r.environmentNode=this.getEnvironmentNode(e.scene),r.fogNode=this.getFogNode(e.scene),r.clippingContext=e.clippingContext,this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview&&r.enableMultiview(),r}getForRender(e,t=!1){let r=this.get(e),i=r.nodeBuilderState;if(void 0===i){let{nodeBuilderCache:s}=this,n=this.getForRenderCacheKey(e);if(void 0===(i=s.get(n))){let a=async()=>{let r=this._createNodeBuilder(e,e.material);try{t?await r.buildAsync():r.build()}catch(i){r=this._createNodeBuilder(e,new of),t?await r.buildAsync():r.build(),(0,u.z3S)("TSL: "+i)}return r};if(t)return a().then(e=>(i=this._createNodeBuilderState(e),s.set(n,i),i.usedTimes++,r.nodeBuilderState=i,i));{let t=this._createNodeBuilder(e,e.material);try{t.build()}catch(i){(t=this._createNodeBuilder(e,new of)).build();let r=i.stackTrace;!r&&i.stack&&(r=new b(i.stack)),(0,u.z3S)("TSL: "+i,r)}i=this._createNodeBuilderState(t),s.set(n,i)}}i.usedTimes++,r.nodeBuilderState=i}return i}getForRenderAsync(e){let t=this.getForRender(e,!0);return t.then?t:Promise.resolve(t)}getForRenderDeferred(e){let t=this.get(e);if(void 0!==t.nodeBuilderState)return t.nodeBuilderState;let r=this.getForRenderCacheKey(e),i=this.nodeBuilderCache.get(r);return void 0!==i?(i.usedTimes++,t.nodeBuilderState=i,i):(!0!==t.pendingBuild&&(t.pendingBuild=!0,this._buildQueue.push(()=>this.getForRenderAsync(e).then(()=>{t.pendingBuild=!1})),this._processBuildQueue()),null)}_processBuildQueue(){this._buildInProgress||0===this._buildQueue.length||(this._buildInProgress=!0,this._buildQueue.shift()().then(()=>{this._buildInProgress=!1,this._processBuildQueue()}))}delete(e){if(e.isRenderObject){let t=this.get(e).nodeBuilderState;void 0!==t&&(t.usedTimes--,0===t.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(e)))}return super.delete(e)}getForCompute(e,t=!1){let r=this.get(e),i=r.nodeBuilderState;if(void 0===i||r.version!==e.version){let s=this.backend.createNodeBuilder(null,this.renderer);s.compute=e;let n=this.renderer.debug.onNodeBuilderCreated;if(null!==n&&n(s,e),t)return s.buildAsync().then(()=>(r.nodeBuilderState=i=this._createNodeBuilderState(s),r.version=e.version,i));s.build(),r.nodeBuilderState=i=this._createNodeBuilderState(s),r.version=e.version}return i}getForComputeAsync(e){let t=this.getForCompute(e,!0);return t.then?t:Promise.resolve(t)}_createNodeBuilderState(e){return new ck(e.vertexShader,e.fragmentShader,e.computeShader,e.getAttributesArray(),e.getBindings(),e.updateNodes,e.updateBeforeNodes,e.updateAfterNodes,e.observer,e.hardwareClipping,e.transforms)}getEnvironmentNode(e){if(!1===this.renderer.lighting.enabled)return null;this.updateEnvironment(e);let t=null;if(e.environmentNode&&e.environmentNode.isNode)t=e.environmentNode;else{let r=this.get(e);r.environmentNode&&(t=r.environmentNode)}return t}getBackgroundNode(e){this.updateBackground(e);let t=null;if(e.backgroundNode&&e.backgroundNode.isNode)t=e.backgroundNode;else{let r=this.get(e);r.backgroundNode&&(t=r.backgroundNode)}return t}getFogNode(e){return this.updateFog(e),e.fogNode||this.get(e).fogNode||null}getCacheKey(e,t){pF[0]=e,pF[1]=t;let r=this.renderer.info.calls,i=this.callHashCache.get(pF)||{};if(i.callId!==r){if(pL.push(this.renderer.getOutputRenderTarget()&&this.renderer.getOutputRenderTarget().multiview?1:0),pL.push(+!!this.renderer.lighting.enabled),this.renderer.lighting.enabled){pL.push(t.getCacheKey(!0)),pL.push(+!!this.renderer.shadowMap.enabled),pL.push(this.renderer.shadowMap.type);let r=this.getEnvironmentNode(e);r&&pL.push(r.getCacheKey())}let s=this.getFogNode(e);s&&pL.push(s.getCacheKey()),i.callId=r,i.cacheKey=T(pL),this.callHashCache.set(pF,i),pL.length=0}return pF[0]=null,pF[1]=null,i.cacheKey}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(e){let t=this.get(e),r=e.background;if(r){let i=0===e.backgroundBlurriness&&t.backgroundBlurriness>0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;(t.background!==r||i)&&(t.backgroundNode=this.getCacheNode("background",r,()=>{if(!0===r.isCubeTexture||r.mapping===u.wfO||r.mapping===u.uV5||r.mapping===u.Om)if(e.backgroundBlurriness>0||r.mapping===u.Om)return uu(r);else return oD(!0===r.isCubeTexture?nl(r):i3(r));if(!0===r.isTexture)return i3(r,ss.flipY()).setUpdateMatrix(!0);!0!==r.isColor&&(0,u.z3S)("WebGPUNodes: Unsupported background configuration.",r)},i),t.background=r,t.backgroundBlurriness=e.backgroundBlurriness)}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}getCacheNode(e,t,r,i=!1){let s=this.cacheLib[e]||(this.cacheLib[e]=new WeakMap),n=s.get(t);if(void 0===n||i){if(void 0===n&&!0===t.isTexture){let e=()=>{t.removeEventListener("dispose",e);let r=s.get(t);void 0!==r&&(s.delete(t),r.dispose())};t.addEventListener("dispose",e)}n=r(),s.set(t,n)}return n}updateFog(e){let t=this.get(e),r=e.fog;r?t.fog!==r&&(t.fogNode=this.getCacheNode("fog",r,()=>{if(r.isFogExp2)return hg(nd("color","color",r).setGroup(tE),hm(nd("density","float",r).setGroup(tE)));if(r.isFog){let e=nd("color","color",r).setGroup(tE);return hg(e,hp(nd("near","float",r).setGroup(tE),nd("far","float",r).setGroup(tE)))}(0,u.z3S)("Renderer: Unsupported fog configuration.",r)}),t.fog=r):(delete t.fogNode,delete t.fog)}updateEnvironment(e){let t=this.get(e),r=e.environment;r?t.environment!==r&&(t.environmentNode=this.getCacheNode("environment",r,()=>!0===r.isCubeTexture?nl(r):!0===r.isTexture?i3(r):void(0,u.z3S)("Nodes: Unsupported environment configuration.",r)),t.environment=r):t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,r=null,i=null,s=null,n=null){let a=this.nodeFrame;return a.renderer=e,a.scene=t,a.object=r,a.camera=i,a.material=s,a.compute=n,a}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getNodeFrameForCompute(e){return this.getNodeFrame(this.renderer,null,null,null,null,e)}getOutputCacheKey(){let e=this.renderer;return e.toneMapping+","+e.currentColorSpace+","+e.xr.isPresenting}getOutputNode(e){let t=this.renderer;return e.isArrayTexture?this.backend.isWebGLBackend?i3(e,ss).depth(st("gl_ViewID_OVR")).renderOutput(t.toneMapping,t.currentColorSpace):i3(e,ss).depth(pU).renderOutput(t.toneMapping,t.currentColorSpace):i3(e,ss).renderOutput(t.toneMapping,t.currentColorSpace)}setOutputLayerIndex(e){pU.value=e}updateBefore(e){for(let t of e.getNodeBuilderState().updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(t)}updateAfter(e){for(let t of e.getNodeBuilderState().updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(t)}updateBeforeForCompute(e){for(let t of this.getForCompute(e).updateBeforeNodes)this.getNodeFrameForCompute(e).updateBeforeNode(t)}updateAfterForCompute(e){for(let t of this.getForCompute(e).updateAfterNodes)this.getNodeFrameForCompute(e).updateAfterNode(t)}updateForCompute(e){let t=this.getNodeFrame();for(let r of this.getForCompute(e).updateNodes)t.updateNode(r)}updateForRender(e){let t=this.getNodeFrameForRender(e);for(let r of e.getNodeBuilderState().updateNodes)t.updateNode(r)}needsRefresh(e){let t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new ph,this.nodeBuilderCache=new Map,this.cacheLib={}}}let pD=new u.Zcv,pO=0;class pI{constructor(e=null){this.id=pO++,this.version=0,this.clipIntersection=null,this.cacheKey="",this.shadowPass=!1,this.viewMatrix=new u.kn4,this.viewNormalMatrix=new u.dwI,this.clippingGroupContexts=new WeakMap,this.intersectionPlanes=[],this.unionPlanes=[],this.parentVersion=null,null!==e&&(this.viewMatrix=e.viewMatrix,this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass)}projectPlanes(e,t,r){let i=e.length;for(let s=0;s<i;s++){pD.copy(e[s]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);let i=t[r+s],n=pD.normal;i.x=-n.x,i.y=-n.y,i.z=-n.z,i.w=pD.constant}}updateGlobal(e,t){this.shadowPass=null!==e.overrideMaterial&&e.overrideMaterial.isShadowPassMaterial,this.viewMatrix.copy(t.matrixWorldInverse),this.viewNormalMatrix.getNormalMatrix(this.viewMatrix)}update(e,t){let r,i,s=!1;e.version!==this.parentVersion&&(this.intersectionPlanes=Array.from(e.intersectionPlanes),this.unionPlanes=Array.from(e.unionPlanes),this.parentVersion=e.version),this.clipIntersection!==t.clipIntersection&&(this.clipIntersection=t.clipIntersection,this.clipIntersection?this.unionPlanes.length=e.unionPlanes.length:this.intersectionPlanes.length=e.intersectionPlanes.length);let n=t.clippingPlanes,a=n.length;if(this.clipIntersection?(r=this.intersectionPlanes,i=e.intersectionPlanes.length):(r=this.unionPlanes,i=e.unionPlanes.length),r.length!==i+a){r.length=i+a;for(let e=0;e<a;e++)r[i+e]=new u.IUQ;s=!0}this.projectPlanes(n,r,i),s&&(this.version++,this.cacheKey=`${this.id}:${this.intersectionPlanes.length}:${this.unionPlanes.length}`)}getGroupContext(e){if(this.shadowPass&&!e.clipShadows)return this;let t=this.clippingGroupContexts.get(e);return void 0===t&&(t=new pI(this),this.clippingGroupContexts.set(e,t)),t.update(this,e),t}get unionClippingCount(){return this.unionPlanes.length}}class pV{constructor(e,t,r){this.bundleGroup=e,this.camera=t,this.renderContext=r}}let pG=[];class pk{constructor(){this.bundles=new uI}get(e,t,r){let i=this.bundles;pG[0]=e,pG[1]=t,pG[2]=r;let s=i.get(pG);return void 0===s&&(s=new pV(e,t,r),i.set(pG,s)),pG[0]=null,pG[1]=null,pG[2]=null,s}dispose(){this.bundles=new uI}}class pz{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map}fromMaterial(e){if(e.isNodeMaterial)return e;let t=null,r=this.getMaterialNodeClass(e.type);if(null!==r)for(let i in t=new r,e)t[i]=e[i];return t}addToneMapping(e,t){this.addType(e,t,this.toneMappingNodes)}getToneMappingFunction(e){return this.toneMappingNodes.get(e)||null}getMaterialNodeClass(e){return this.materialNodes.get(e)||null}addMaterial(e,t){this.addType(e,t,this.materialNodes)}getLightNodeClass(e){return this.lightNodes.get(e)||null}addLight(e,t){this.addClass(e,t,this.lightNodes)}addType(e,t,r){if(r.has(t))return void(0,u.R8M)(`Redefinition of node ${t}`);if("function"!=typeof e)throw Error(`THREE.NodeLibrary: Node class ${e.name} is not a class.`);if("function"==typeof t||"object"==typeof t)throw Error(`THREE.NodeLibrary: Base class ${t} is not a class.`);r.set(t,e)}addClass(e,t,r){if(r.has(t))return void(0,u.R8M)(`Redefinition of node ${t.name}`);if("function"!=typeof e)throw Error(`THREE.NodeLibrary: Node class ${e.name} is not a class.`);if("function"!=typeof t)throw Error(`THREE.NodeLibrary: Base class ${t.name} is not a class.`);r.set(t,e)}}let p$=new hw;class pW{constructor(){this.enabled=!0,this._cache=[],this._lightsNodeMap=new WeakMap}createNode(e=[]){return new hw().setLights(e)}getNode(e){if(!0!==e.isScene&&!0!==e.isGroup)return p$;let t=this._lightsNodeMap.get(e);return void 0===t&&(t=this.createNode(),this._lightsNodeMap.set(e,t)),t}beginRender(e){this._cache.push(this.getNode(e).getLights())}finishRender(e){this.getNode(e).setLights(this._cache.pop())}}class pH extends u.O0B{constructor(e=1,t=1,r={}){super(e,t,r),this.isXRRenderTarget=!0,this._hasExternalTextures=!1,this._autoAllocateDepthBuffer=!0,this._isOpaqueFramebuffer=!1}copy(e){return super.copy(e),this._hasExternalTextures=e._hasExternalTextures,this._autoAllocateDepthBuffer=e._autoAllocateDepthBuffer,this._isOpaqueFramebuffer=e._isOpaqueFramebuffer,this}}let pq=new u.Pq0,pj=new u.Pq0,pX=new WeakMap;class pK extends u.Qev{constructor(e,t=!1){super(),this.enabled=!1,this.isPresenting=!1,this.cameraAutoUpdate=!0,this._renderer=e,this._cameraL=new u.ubm,this._cameraL.viewport=new u.IUQ,this._cameraL.matrixWorldAutoUpdate=!1,this._cameraR=new u.ubm,this._cameraR.viewport=new u.IUQ,this._cameraR.matrixWorldAutoUpdate=!1,this._cameras=[this._cameraL,this._cameraR],this._cameraXR=new u.nZQ,this._currentDepthNear=null,this._currentDepthFar=null,this._controllers=[],this._controllerInputSources=[],this._xrRenderTarget=null,this._layers=[],this._sessionUsesLayers=!1,this._supportsGlBinding="undefined"!=typeof XRWebGLBinding,this._supportsWebGPUBinding=void 0!==globalThis.XRGPUBinding,this._createXRLayer=p0.bind(this),this._gl=null,this._currentAnimationContext=null,this._currentAnimationLoop=null,this._currentPixelRatio=null,this._currentSize=new u.I9Y,this._currentCameraSettings=null,this._onSessionEvent=pY.bind(this),this._onSessionEnd=pZ.bind(this),this._onInputSourcesChange=pJ.bind(this),this._onAnimationFrame=p1.bind(this),this._referenceSpace=null,this._referenceSpaceType="local-floor",this._customReferenceSpace=null,this._framebufferScaleFactor=1,this._foveation=1,this._session=null,this._glBaseLayer=null,this._glBinding=null,this._webgpuBinding=null,this._glProjLayer=null,this._xrFrame=null,this._supportsLayers=this._supportsGlBinding&&"createProjectionLayer"in XRWebGLBinding.prototype,this._useMultiviewIfPossible=t,this._useMultiview=!1}getController(e){return this._getController(e).getTargetRaySpace()}getControllerGrip(e){return this._getController(e).getGripSpace()}getHand(e){return this._getController(e).getHandSpace()}getFoveation(){return this._foveation}setFoveation(e){this._foveation=e,null!==this._glProjLayer&&(this._glProjLayer.fixedFoveation=e),null!==this._glBaseLayer&&void 0!==this._glBaseLayer.fixedFoveation&&(this._glBaseLayer.fixedFoveation=e)}getFramebufferScaleFactor(){return this._framebufferScaleFactor}setFramebufferScaleFactor(e){this._framebufferScaleFactor=e,!0===this.isPresenting&&(0,u.R8M)("XRManager: Cannot change framebuffer scale while presenting.")}getReferenceSpaceType(){return this._referenceSpaceType}setReferenceSpaceType(e){this._referenceSpaceType=e,!0===this.isPresenting&&(0,u.R8M)("XRManager: Cannot change reference space type while presenting.")}getReferenceSpace(){return this._customReferenceSpace||this._referenceSpace}setReferenceSpace(e){this._customReferenceSpace=e}getCamera(){return this._cameraXR}getEnvironmentBlendMode(){if(null!==this._session)return this._session.environmentBlendMode}getBaseLayer(){return null!==this._glProjLayer?this._glProjLayer:this._glBaseLayer}getBinding(){return null===this._glBinding&&this._supportsGlBinding&&(this._glBinding=new XRWebGLBinding(this._session,this._gl)),this._glBinding}foveateBoundTexture(e){if(null===e||!0!==e.isPostProcessingRenderTarget||!0!==this.isPresenting||null===this._glProjLayer)return;let t=this._renderer.backend;if(void 0===t||!0!==t.isWebGLBackend||null===t.state)return;let r=this._renderer.getOutputRenderTarget();if(null===r||!0!==r.isXRRenderTarget)return;let i=this.getBinding();if(null===i||"function"!=typeof i.foveateBoundTexture)return;this._renderer._textures.updateRenderTarget(e);let{textureGPU:s,glTextureType:n}=t.get(e.texture);if(void 0!==s&&void 0!==n&&e._xrFoveationTextureGPU!==s){e._xrFoveationTextureGPU=s,t.state.bindTexture(n,s);try{i.foveateBoundTexture(n,this.getFoveation())}catch(e){(0,u.mcG)(`XRManager: Unable to foveate bound XR post-processing texture. ${e.name}: ${e.message}`)}finally{t.state.unbindTexture()}}}getWebGPUBinding(){return null===this._webgpuBinding&&this._supportsWebGPUBinding&&(this._webgpuBinding=new globalThis.XRGPUBinding(this._session,this._renderer.backend.device)),this._webgpuBinding}_isWebGPUSession(){return!0===this._renderer.backend.isWebGPUBackend&&null!==this._session&&this._session.enabledFeatures.includes("webgpu")}_validateWebGPUSession(){if(!0===this._renderer.backend.isWebGPUBackend&&!1===this._session.enabledFeatures.includes("webgpu"))throw Error('THREE.XRManager: WebGPU XR sessions require the "webgpu" session feature. Use VRButtonGPU/XRButton with "webgpu" enabled or use a WebGL backend.')}async _initWebGPUSession(e){let t=this.getWebGPUBinding(),r=t.createProjectionLayer({colorFormat:t.getPreferredColorFormat()});this._glProjLayer=r,e.updateRenderState({layers:[r]}),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._xrRenderTarget=new u.O0B(r.textureWidth,r.textureHeight,{depth:2,minFilter:u.k6q,magFilter:u.k6q,depthBuffer:!0,multiview:!1,useArrayDepthTexture:!0,storeMultisampledColorBuffer:!1,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1,samples:this._renderer.samples}),this._xrRenderTarget.texture.isArrayTexture=!0,!0===this._useMultiviewIfPossible&&(0,u.mcG)("THREE.XRManager: WebGPU XR does not support multiview yet. Disabling multiview for this XR session."),this._useMultiview=!1}_disposeWebGPUSession(){let e=this._renderer,t=e.backend,r=this._xrRenderTarget;if(null!==r&&!0===t.isWebGPUBackend){for(let i of(e._renderContexts&&e._renderContexts.dispose&&e._renderContexts.dispose(),r.dispose(),r.textures))t.has(i)&&t.destroyTexture(i);t.delete(r)}}_getWebGPUViewData(e){let t=this.getWebGPUBinding(),r={colorTexture:null,viewDescriptors:[],viewports:[]};for(let i=0;i<e.length;i++){let s=t.getViewSubImage(this._glProjLayer,e[i]);null===r.colorTexture&&(r.colorTexture=s.colorTexture),r.viewports.push(s.viewport),s.getViewDescriptor&&r.viewDescriptors.push(s.getViewDescriptor())}return r}getFrame(){return this._xrFrame}useMultiview(){return this._useMultiview}createQuadLayer(e,t,r,i,s,n,a,o={}){let l=new u.bdM(e,t),d=new pH(s,n,{format:u.GWd,type:u.OUM,depthTexture:new u.VCu(s,n,o.stencil?u.V3x:u.bkx,void 0,void 0,void 0,void 0,void 0,void 0,o.stencil?u.dcC:u.zdS),stencilBuffer:o.stencil,samples:o.samples??this._renderer.samples,resolveDepthBuffer:!1,resolveStencilBuffer:!1,storeMultisampledColorBuffer:!1,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1}),h=new u.V9B({color:0xffffff,side:u.hB5});h.map=d.texture,h.map.offset.y=1,h.map.repeat.y=-1;let c=new u.eaF(l,h);c.position.copy(r),c.quaternion.copy(i);let p={type:"quad",width:e,height:t,translation:r,quaternion:i,pixelwidth:s,pixelheight:n,samples:d.samples,plane:c,material:h,rendercall:a,renderTarget:d};if(this._layers.push(p),null!==this._session){p.plane.material=new u.V9B({color:0xffffff,side:u.hB5}),p.plane.material.blending=u.bCz,p.plane.material.blendEquation=u.gO9,p.plane.material.blendSrc=u.ojh,p.plane.material.blendDst=u.ojh,p.xrlayer=this._createXRLayer(p);let e=this._session.renderState.layers;e.unshift(p.xrlayer),this._session.updateRenderState({layers:e})}else d.isXRRenderTarget=!1;return c}createCylinderLayer(e,t,r,i,s,n,a,o,l={}){let d=new u.Ho_(e,e,e*t/r,64,64,!0,Math.PI-t/2,t),h=new pH(n,a,{format:u.GWd,type:u.OUM,depthTexture:new u.VCu(n,a,l.stencil?u.V3x:u.bkx,void 0,void 0,void 0,void 0,void 0,void 0,l.stencil?u.dcC:u.zdS),stencilBuffer:l.stencil,samples:l.samples??this._renderer.samples,resolveDepthBuffer:!1,resolveStencilBuffer:!1,storeMultisampledColorBuffer:!1,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1}),c=new u.V9B({color:0xffffff,side:u.hsX});c.map=h.texture,c.map.offset.y=1,c.map.repeat.y=-1;let p=new u.eaF(d,c);p.position.copy(i),p.quaternion.copy(s);let m={type:"cylinder",radius:e,centralAngle:t,aspectratio:r,translation:i,quaternion:s,pixelwidth:n,pixelheight:a,samples:h.samples,plane:p,material:c,rendercall:o,renderTarget:h};if(this._layers.push(m),null!==this._session){m.plane.material=new u.V9B({color:0xffffff,side:u.hsX}),m.plane.material.blending=u.bCz,m.plane.material.blendEquation=u.gO9,m.plane.material.blendSrc=u.ojh,m.plane.material.blendDst=u.ojh,m.xrlayer=this._createXRLayer(m);let e=this._session.renderState.layers;e.unshift(m.xrlayer),this._session.updateRenderState({layers:e})}else h.isXRRenderTarget=!1;return p}renderLayers(){let e=new u.Pq0,t=new u.PTz,r=this._renderer,i=this.isPresenting;this.isPresenting=!1;let s=new u.I9Y;r.getSize(s);let n=r.getRenderTarget();for(let i of this._layers){let s;i.renderTarget.isXRRenderTarget=null!==this._session,i.renderTarget._hasExternalTextures=i.renderTarget.isXRRenderTarget;let n=r.contextNode;if(i.renderTarget.isXRRenderTarget&&this._sessionUsesLayers){i.xrlayer.transform=new XRRigidTransform(i.plane.getWorldPosition(e),i.plane.getWorldQuaternion(t));let a=this._glBinding.getSubImage(i.xrlayer,this._xrFrame);r.backend.setXRRenderTargetTextures(i.renderTarget,a.colorTexture,void 0),r._setXRLayerSize(i.renderTarget.width,i.renderTarget.height),void 0===(s=pX.get(n))&&(s=ie({getOutput:e=>iz(e,r.toneMapping,r.outputColorSpace),...n.getFlowContextData()}),pX.set(n,s))}else s=n;r.contextNode=s,r.setRenderTarget(i.renderTarget),i.rendercall(),r.contextNode=n}r.setRenderTarget(n),r._setXRLayerSize(s.x,s.y),this.isPresenting=i}getSession(){return this._session}async setSession(e){let t=this._renderer;!1===t.initialized&&await t.init(),this._gl=t.getContext();let r=this._gl;if(this._session=e,null!==e){if(e.addEventListener("select",this._onSessionEvent),e.addEventListener("selectstart",this._onSessionEvent),e.addEventListener("selectend",this._onSessionEvent),e.addEventListener("squeeze",this._onSessionEvent),e.addEventListener("squeezestart",this._onSessionEvent),e.addEventListener("squeezeend",this._onSessionEvent),e.addEventListener("end",this._onSessionEnd),e.addEventListener("inputsourceschange",this._onInputSourcesChange),this._validateWebGPUSession(),this._currentPixelRatio=t.getPixelRatio(),t.getSize(this._currentSize),this._currentAnimationContext=t._animation.getContext(),this._currentAnimationLoop=t._animation.getAnimationLoop(),t._animation.stop(),this._isWebGPUSession())await this._initWebGPUSession(e);else if(!0===this._supportsLayers){let i=null,s=null,n=null,a=r.getContextAttributes();await t.backend.makeXRCompatible(),this.setFoveation(this.getFoveation()),t.depth&&(n=t.stencil?r.DEPTH24_STENCIL8:r.DEPTH_COMPONENT24,i=t.stencil?u.dcC:u.zdS,s=t.stencil?u.V3x:u.bkx);let o={colorFormat:r.RGBA8,depthFormat:n,scaleFactor:this._framebufferScaleFactor,clearOnAccess:!1};this._useMultiviewIfPossible&&t.hasFeature("OVR_multiview2")&&(o.textureType="texture-array",this._useMultiview=!0),this._glBinding=this.getBinding();let l=this._glBinding.createProjectionLayer(o),d=[l];this._glProjLayer=l,t.setPixelRatio(1),t._setXRLayerSize(l.textureWidth,l.textureHeight);let h=this._useMultiview?2:1,c=new u.VCu(l.textureWidth,l.textureHeight,s,void 0,void 0,void 0,void 0,void 0,void 0,i,h);if(this._xrRenderTarget=new pH(l.textureWidth,l.textureHeight,{format:u.GWd,type:u.OUM,colorSpace:t.outputColorSpace,depthTexture:c,stencilBuffer:t.stencil,samples:4*!!a.antialias,resolveDepthBuffer:!1===l.ignoreDepthValues,resolveStencilBuffer:!1===l.ignoreDepthValues,storeMultisampledColorBuffer:!1,storeMultisampledDepthBuffer:!1===l.ignoreDepthValues,storeMultisampledStencilBuffer:!1===l.ignoreDepthValues,depth:this._useMultiview?2:1,multiview:this._useMultiview}),this._xrRenderTarget._hasExternalTextures=!0,this._xrRenderTarget.depth=this._useMultiview?2:1,this._sessionUsesLayers=e.enabledFeatures.includes("layers"),this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType()),this._sessionUsesLayers)for(let e of this._layers)e.plane.material=new u.V9B({color:0xffffff,side:"cylinder"===e.type?u.hsX:u.hB5}),e.plane.material.blending=u.bCz,e.plane.material.blendEquation=u.gO9,e.plane.material.blendSrc=u.ojh,e.plane.material.blendDst=u.ojh,e.xrlayer=this._createXRLayer(e),d.unshift(e.xrlayer);e.updateRenderState({layers:d})}else{await t.backend.makeXRCompatible(),this.setFoveation(this.getFoveation());let i=new XRWebGLLayer(e,r,{antialias:t.currentSamples>0,alpha:!0,depth:t.depth,stencil:t.stencil,framebufferScaleFactor:this.getFramebufferScaleFactor()});this._glBaseLayer=i,e.updateRenderState({baseLayer:i}),t.setPixelRatio(1),t._setXRLayerSize(i.framebufferWidth,i.framebufferHeight),this._xrRenderTarget=new pH(i.framebufferWidth,i.framebufferHeight,{format:u.GWd,type:u.OUM,colorSpace:t.outputColorSpace,stencilBuffer:t.stencil}),this._xrRenderTarget._isOpaqueFramebuffer=!0,this._referenceSpace=await e.requestReferenceSpace(this.getReferenceSpaceType())}t._animation.setAnimationLoop(this._onAnimationFrame),t._animation.setContext(e),t._animation.start(),this.isPresenting=!0,this.dispatchEvent({type:"sessionstart"})}}updateCamera(e){var t,r,i;let s=this._session;if(null===s)return;let n=e.near,a=e.far,o=this._cameraXR,l=this._cameraL,d=this._cameraR;o.near=d.near=l.near=n,o.far=d.far=l.far=a,o.isMultiViewCamera=this._useMultiview,(this._currentDepthNear!==o.near||this._currentDepthFar!==o.far)&&(s.updateRenderState({depthNear:o.near,depthFar:o.far}),this._currentDepthNear=o.near,this._currentDepthFar=o.far),o.layers.mask=6|e.layers.mask,l.layers.mask=-5&o.layers.mask,d.layers.mask=-3&o.layers.mask;let h=e.parent,c=o.cameras;pQ(o,h);for(let e=0;e<c.length;e++)pQ(c[e],h);2===c.length?function(e,t,r){pq.setFromMatrixPosition(t.matrixWorld),pj.setFromMatrixPosition(r.matrixWorld);let i=pq.distanceTo(pj),s=t.projectionMatrix.elements,n=r.projectionMatrix.elements,a=s[14]/(s[10]-1),o=s[14]/(s[10]+1),l=(s[9]+1)/s[5],u=(s[9]-1)/s[5],d=(s[8]-1)/s[0],h=(n[8]+1)/n[0],c=i/(-d+h),p=-(c*d);if(t.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.translateX(p),e.translateZ(c),e.matrixWorld.compose(e.position,e.quaternion,e.scale),e.matrixWorldInverse.copy(e.matrixWorld).invert(),-1===s[10])e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse);else{let t=a+c,r=o+c;e.projectionMatrix.makePerspective(a*d-p,a*h+(i-p),l*o/r*t,u*o/r*t,t,r),e.projectionMatrixInverse.copy(e.projectionMatrix).invert()}}(o,l,d):o.projectionMatrix.copy(l.projectionMatrix),null===this._currentCameraSettings&&e.isPerspectiveCamera&&(this._currentCameraSettings={camera:e,fov:e.fov,zoom:e.zoom}),t=e,r=o,null===(i=h)?t.matrix.copy(r.matrixWorld):(t.matrix.copy(i.matrixWorld),t.matrix.invert(),t.matrix.multiply(r.matrixWorld)),t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),t.projectionMatrix.copy(r.projectionMatrix),t.projectionMatrixInverse.copy(r.projectionMatrixInverse),t.isPerspectiveCamera&&(t.fov=2*u.a55*Math.atan(1/t.projectionMatrix.elements[5]),t.zoom=1)}_getController(e){let t=this._controllers[e];return void 0===t&&(t=new u.R3r,this._controllers[e]=t),t}}function pQ(e,t){null===t?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}function pY(e){let t=this._controllerInputSources.indexOf(e.inputSource);if(-1===t)return;let r=this._controllers[t];if(void 0!==r){let t=this.getReferenceSpace();r.update(e.inputSource,e.frame,t),r.dispatchEvent({type:e.type,data:e.inputSource})}}function pZ(){let e=this._session,t=this._renderer;e.removeEventListener("select",this._onSessionEvent),e.removeEventListener("selectstart",this._onSessionEvent),e.removeEventListener("selectend",this._onSessionEvent),e.removeEventListener("squeeze",this._onSessionEvent),e.removeEventListener("squeezestart",this._onSessionEvent),e.removeEventListener("squeezeend",this._onSessionEvent),e.removeEventListener("end",this._onSessionEnd),e.removeEventListener("inputsourceschange",this._onInputSourcesChange);for(let e=0;e<this._controllers.length;e++){let t=this._controllerInputSources[e];null!==t&&(this._controllerInputSources[e]=null,this._controllers[e].disconnect(t))}if(this._currentDepthNear=null,this._currentDepthFar=null,t._resetXRState(),this._disposeWebGPUSession(),this._session=null,this._xrRenderTarget=null,this._glBinding=null,this._webgpuBinding=null,this._glBaseLayer=null,this._glProjLayer=null,!0===this._sessionUsesLayers)for(let e of this._layers)e.renderTarget=new pH(e.pixelwidth,e.pixelheight,{format:u.GWd,type:u.OUM,depthTexture:new u.VCu(e.pixelwidth,e.pixelheight,e.stencilBuffer?u.V3x:u.bkx,void 0,void 0,void 0,void 0,void 0,void 0,e.stencilBuffer?u.dcC:u.zdS),stencilBuffer:e.stencilBuffer,samples:e.samples,resolveDepthBuffer:!1,resolveStencilBuffer:!1,storeMultisampledColorBuffer:!1,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1}),e.renderTarget.isXRRenderTarget=!1,e.plane.material=e.material,e.material.map=e.renderTarget.texture,e.material.map.offset.y=1,e.material.map.repeat.y=-1,delete e.xrlayer;if(this.isPresenting=!1,this._useMultiview=!1,t._animation.stop(),t._animation.setAnimationLoop(this._currentAnimationLoop),t._animation.setContext(this._currentAnimationContext),t._animation.start(),t.setPixelRatio(this._currentPixelRatio),t.setSize(this._currentSize.width,this._currentSize.height,!1),null!==this._currentCameraSettings){let e=this._currentCameraSettings.camera;e.fov=this._currentCameraSettings.fov,e.zoom=this._currentCameraSettings.zoom,e.updateProjectionMatrix(),this._currentCameraSettings=null}this.dispatchEvent({type:"sessionend"})}function pJ(e){let t=this._controllers,r=this._controllerInputSources;for(let i=0;i<e.removed.length;i++){let s=e.removed[i],n=r.indexOf(s);n>=0&&(r[n]=null,t[n].disconnect(s))}for(let i=0;i<e.added.length;i++){let s=e.added[i],n=r.indexOf(s);if(-1===n){for(let e=0;e<t.length;e++)if(e>=r.length){r.push(s),n=e;break}else if(null===r[e]){r[e]=s,n=e;break}if(-1===n)break}let a=t[n];a&&a.connect(s)}}function p0(e){return"quad"===e.type?this._glBinding.createQuadLayer({transform:new XRRigidTransform(e.translation,e.quaternion),width:e.width/2,height:e.height/2,space:this._referenceSpace,viewPixelWidth:e.pixelwidth,viewPixelHeight:e.pixelheight,clearOnAccess:!1}):this._glBinding.createCylinderLayer({transform:new XRRigidTransform(e.translation,e.quaternion),radius:e.radius,centralAngle:e.centralAngle,aspectRatio:e.aspectRatio,space:this._referenceSpace,viewPixelWidth:e.pixelwidth,viewPixelHeight:e.pixelheight,clearOnAccess:!1})}function p1(e,t){if(void 0===t)return;let r=this._cameraXR,i=this._renderer,s=i.backend,n=this._glBaseLayer,a=this.getReferenceSpace(),o=t.getViewerPose(a);if(this._xrFrame=t,null!==o){let e=o.views,t=this._isWebGPUSession()?this._getWebGPUViewData(e):null;null!==this._glBaseLayer&&null===t&&s.setXRTarget(n.framebuffer);let a=!1;e.length!==r.cameras.length&&(r.cameras.length=0,a=!0);for(let i=0;i<e.length;i++){let o,l=e[i];if(null!==t)o=t.viewports[i];else if(!0===this._supportsLayers){let e=this._glBinding.getViewSubImage(this._glProjLayer,l);o=e.viewport,0===i&&s.setXRRenderTargetTextures(this._xrRenderTarget,e.colorTexture,this._glProjLayer.ignoreDepthValues&&!this._useMultiview?void 0:e.depthStencilTexture)}else o=n.getViewport(l);let d=this._cameras[i];void 0===d&&((d=new u.ubm).layers.enable(i),d.viewport=new u.IUQ,d.matrixWorldAutoUpdate=!1,this._cameras[i]=d),d.matrix.fromArray(l.transform.matrix),d.matrix.decompose(d.position,d.quaternion,d.scale),d.projectionMatrix.fromArray(l.projectionMatrix),d.projectionMatrixInverse.copy(d.projectionMatrix).invert(),d.viewport.set(o.x,o.y,o.width,o.height),0===i&&(r.matrix.copy(d.matrix),r.matrix.decompose(r.position,r.quaternion,r.scale)),!0===a&&r.cameras.push(d)}null!==t&&null!==t.colorTexture&&s.setXRRenderTargetTextures(this._xrRenderTarget,t.colorTexture,t.viewDescriptors),i.setOutputRenderTarget(this._xrRenderTarget);let l=i._getFrameBufferTarget();null!==t&&(this._xrRenderTarget.samples=null===l?i.samples:0,this._xrRenderTarget.depthBuffer=null===l),i.xr.foveateBoundTexture(l)}for(let e=0;e<this._controllers.length;e++){let r=this._controllerInputSources[e],i=this._controllers[e];null!==r&&void 0!==i&&i.update(r,t,a)}this._currentAnimationLoop&&this._currentAnimationLoop(e,t),t.detectedPlanes&&this.dispatchEvent({type:"planesdetected",data:t}),this._xrFrame=null}class p2 extends u.Qev{constructor(e){super(),this.domElement=e,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new u.IUQ(0,0,this._width,this._height),this._scissor=new u.IUQ(0,0,this._width,this._height),this._scissorTest=!1,this.colorTexture=new u.Pem,this.depthTexture=new u.VCu}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,r){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this._pixelRatio=r,this.domElement.width=Math.floor(e*r),this.domElement.height=Math.floor(t*r),this.setViewport(0,0,e,t),this._dispatchResize())}setSize(e,t,r=!0){this.xr&&this.xr.isPresenting||(this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===r&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._dispatchResize())}getScissor(e){let t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,r,i){let s=this._scissor;e.isVector4?s.copy(e):s.set(e,t,r,i)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,r,i,s=0,n=1){let a=this._viewport;e.isVector4?a.copy(e):a.set(e,t,r,i),a.minDepth=s,a.maxDepth=n}_dispatchResize(){this.dispatchEvent({type:"resize"})}dispose(){this.dispatchEvent({type:"dispose"})}}let p3=new u.Z58,p4=new u.I9Y,p8=new u.IUQ,p5=new u.PPD,p6=new u.uf3,p9=new u.kn4,p7=new u.IUQ,me={[u.hB5]:u.hsX,[u.hsX]:u.hB5,[u.$EB]:u.$EB};class mt{constructor(e,t={}){this.isRenderer=!0;let{logarithmicDepthBuffer:r=!1,reversedDepthBuffer:i=!1,alpha:s=!0,depth:n=!0,stencil:a=!1,antialias:o=!1,samples:l=0,getFallback:d=null,outputBufferType:h=u.ix0,multiview:c=!1}=t;this.backend=e,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=s,this.logarithmicDepthBuffer=r,this.reversedDepthBuffer=i,this.outputColorSpace=u.er$,this.toneMapping=u.y_p,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=n,this.stencil=a,this.info=new uY,this.contextNode=ie(),this.library=new pz,this.lighting=new pW,this._samples=l||4*(!0===o),this._onCanvasTargetResize=this._onCanvasTargetResize.bind(this),this._canvasTarget=new p2(e.getDomElement()),this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize),this._canvasTarget.isDefaultCanvasTarget=!0,this._inspector=new iW,this._inspector.setRenderer(this),this._getFallback=d,this._attributes=null,this._geometries=null,this._nodes=null,this._animation=null,this._bindings=null,this._objects=null,this._pipelines=null,this._bundles=null,this._renderLists=null,this._renderContexts=null,this._textures=null,this._background=null,this._quadCache=new Map,this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTargets=new Map;let p=+(!0!==this.alpha);this._clearColor=new dd(0,0,0,p),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._outputRenderTarget=null,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._isDeviceLost=!1,this.onDeviceLost=this._onDeviceLost,this.onError=this._onError,this._outputBufferType=h,this._cacheShadowNodes=new WeakMap,this._initialized=!1,this._callDepth=-1,this._initPromise=null,this._compilationPromises=null,this._isPreCompiling=!1,this._currentSourceMaterial=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,transmitted:!1,type:u.QP0},this.xr=new pK(this,c),this.debug={checkShaderErrors:!0,diagnostics:{keywords:!1},onNodeBuilderCreated:null,onShaderError:null,getShaderAsync:async(e,t,r)=>{await this.compileAsync(r,t,e);let i=this.needsFrameBufferTarget&&null===this._renderTarget?this._getFrameBufferTarget():this._renderTarget||this._outputRenderTarget,s=this._renderLists.get(e,t,this.lighting),n=this._renderContexts.get(i,this._mrt),a=e.overrideMaterial||r.material,{fragmentShader:o,vertexShader:l}=this._objects.get(r,a,e,t,s.lightsNode,n,n.clippingContext).getNodeBuilderState();return{fragmentShader:o,vertexShader:l}}}}async init(){return null!==this._initPromise||(this._initPromise=new Promise(async(e,t)=>{let r=this.backend;try{await r.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=r=this._getFallback(e),await r.init(this)}catch(e){t(e);return}}this._nodes=new pP(this,r),this._animation=new uO(this,this._nodes,this.info),this._attributes=new uq(r,this.info),this._background=new cI(this,this._nodes),this._geometries=new uQ(this._attributes,this.info),this._textures=new du(this,r,this.info),this._pipelines=new u3(r,this._nodes,this.info),this._bindings=new u4(r,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new u$(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new dr,this._bundles=new pk,this._renderContexts=new da(this),this._animation.start(),this._initialized=!0,e(this)})),this._initPromise}get domElement(){return this._canvasTarget.domElement}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,r=null,i=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init(),this.shadowMap.type===u.Wk7&&((0,u.R8M)("WebGPURenderer: PCFSoftShadowMap has been removed. Using PCFShadowMap instead."),this.shadowMap.type=u.QP0);let s=this._nodes.nodeFrame,n=s.renderId,a=this._currentRenderContext,o=this._currentRenderObjectFunction,l=this._handleObjectFunction,d=this._compilationPromises;null===r&&(r=e);let h=!0===e.isScene?e:!0===r.isScene?r:p3,c=this.needsFrameBufferTarget&&null===this._renderTarget,p=this._renderTarget||this._outputRenderTarget,m=!0===this.xr.isPresenting&&this.isOutputTarget,g=c?this._getFrameBufferTarget():p,f=this._renderContexts.get(g,this._mrt),b=this._activeMipmapLevel,y=[];this._currentRenderContext=f,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=y,s.renderId++,s.update(),f.depth=this.depth,f.stencil=this.stencil,f.clippingContext||(f.clippingContext=new pI),f.clippingContext.updateGlobal(h,t),!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),t=this._updateCamera(t,m),h.onBeforeRender(this,e,t,g),p9.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),t.isArrayCamera?p6.setFromArrayCamera(t):p5.setFromProjectionMatrix(p9,t.coordinateSystem,t.reversedDepth);let x=this._renderLists.get(h,t,this.lighting);if(x.begin(),this._projectObject(e,t,0,x,f.clippingContext),r!==e&&r.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&x.pushLight(e)}),x.finish(),null!==g){this._textures.updateRenderTarget(g,b);let e=this._textures.get(g);f.textures=e.textures,f.depthTexture=e.depthTexture}else f.textures=null,f.depthTexture=null;r!==e?this._background.update(r,x,f):this._background.update(h,x,f);let T=x.opaque,_=x.transparent,v=x.transparentDoublePass,S=x.lightsNode;!0===this.opaque&&T.length>0&&this._renderObjects(T,t,h,S),!0===this.transparent&&_.length>0&&this._renderTransparents(_,v,t,h,S),s.renderId=n,this._currentRenderContext=a,this._currentRenderObjectFunction=o,this._handleObjectFunction=l,this._compilationPromises=d;let R=y.length,N=0;for(let e of y){let t=this._objects.get(e.object,e.material,e.scene,e.camera,e.lightsNode,e.renderContext,e.clippingContext,e.passId);t.drawRange=e.object.geometry.drawRange,t.group=e.group,await this._nodes.getForRenderAsync(t),this._isPreCompiling=!0,this._nodes.updateBefore(t),this._geometries.updateForRender(t),this._nodes.updateForRender(t),this._bindings.updateForRender(t),this._isPreCompiling=!1;let r=[];this._pipelines.getForRender(t,r),r.length>0&&await Promise.all(r),this._isPreCompiling=!0,this._nodes.updateAfter(t),this._isPreCompiling=!1,N++,null!==i&&i(new ProgressEvent("progress",{lengthComputable:!0,loaded:N,total:R})),await (0,u.aH0)()}}async compileComputeAsync(e,t=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();let r=Array.isArray(e)?e:[e];if(0===r.length||r.some(e=>null==e||!0!==e.isComputeNode))throw Error("THREE.Renderer: .compileComputeAsync() expects a ComputeNode.");let i=r.length,s=0,n=this._pipelines,a=this._bindings,o=this._nodes;for(let e of r){if(!1===n.has(e)){let t=()=>{e.removeEventListener("dispose",t),n.delete(e),a.deleteForCompute(e),o.delete(e)};e.addEventListener("dispose",t);let r=e.onInitFunction;null!==r&&r.call(e,{renderer:this})}await o.getForComputeAsync(e),o.updateBeforeForCompute(e),o.updateForCompute(e),a.updateForCompute(e);let r=a.getForCompute(e),l=[];n.getForCompute(e,r,l),await Promise.all(l),o.updateAfterForCompute(e),s++,null!==t&&t(new ProgressEvent("progress",{lengthComputable:!0,loaded:s,total:i})),s<i&&await (0,u.aH0)()}}async renderAsync(e,t){(0,u.mcG)('Renderer: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.render(e,t)}async waitForGPU(){(0,u.z3S)("Renderer: waitForGPU() has been removed. Read https://github.com/mrdoob/three.js/issues/32012 for more information.")}set inspector(e){null!==this._inspector&&this._inspector.setRenderer(null),this._inspector=e,this._inspector.setRenderer(this)}get inspector(){return this._inspector}set highPrecision(e){let t=this.contextNode.value;!0===e?(t.modelViewMatrix=sI,t.modelNormalViewMatrix=sV):this.highPrecision&&(delete t.modelViewMatrix,delete t.modelNormalViewMatrix)}get highPrecision(){let e=this.contextNode.value;return e.modelViewMatrix===sI&&e.modelNormalViewMatrix===sV}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}getOutputBufferType(){return this._outputBufferType}getColorBufferType(){return(0,u.mcG)('Renderer: ".getColorBufferType()" has been renamed to ".getOutputBufferType()".'),this.getOutputBufferType()}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:
|
|
11
|
+
|
|
12
|
+
Message: ${e.message}`;e.reason&&(t+=`
|
|
13
|
+
Reason: ${e.reason}`),(0,u.z3S)(t),this._isDeviceLost=!0}_onError(e){let t=`WebGPURenderer: Uncaptured ${e.api} ${e.type}`;e.message&&(t+=`: ${e.message}`),(0,u.z3S)(t)}_bundleNeedsUpdate(e,t){return void 0===t.bundleGPU||e.version!==t.version}_renderBundle(e,t,r){let{bundleGroup:i,camera:s,renderList:n}=e,a=this._currentRenderContext,o=this._bundles.get(i,s,a),l=this.backend.get(o);if(this._bundleNeedsUpdate(i,l)){this.backend.beginBundle(a),this._currentRenderBundle=o;let{transparentDoublePass:e,transparent:u,opaque:d}=n;!0===this.opaque&&d.length>0&&this._renderObjects(d,s,t,r),!0===this.transparent&&u.length>0&&this._renderTransparents(u,e,s,t,r),this._currentRenderBundle=null,this.backend.finishBundle(a,o),l.version=i.version}else{let{renderObjects:e}=l;for(let t=0,r=e.length;t<r;t++){let r=e[t],i=this._nodes.needsRefresh(r);i===u.B0D.FULL?(this._nodes.updateBefore(r),this._geometries.updateForRender(r),this._nodes.updateForRender(r),this._bindings.updateForRender(r),this._nodes.updateAfter(r)):i===u.B0D.SHARED&&(this._nodes.updateBefore(r),this._nodes.updateForRender(r),this._bindings.updateSharedForRender(r),this._nodes.updateAfter(r))}}this.backend.addBundle(a,o)}render(e,t){if(!1===this._initialized)throw Error('THREE.Renderer: .render() called before the backend is initialized. Use "await renderer.init();" before rendering.');this._renderScene(e,t)}get initialized(){return this._initialized}_renderOutputLayers(e,t){if(!0===this.backend.isWebGLBackend&&!0===t.multiview||!0!==t.texture.isArrayTexture||t.texture.image.depth<=1)return void this._renderScene(e,e.camera,!1);let r=this._activeCubeFace;try{for(let r=0;r<t.texture.image.depth;r++)this._nodes.setOutputLayerIndex(r),this._activeCubeFace=r,this._renderScene(e,e.camera,!1)}finally{this._nodes.setOutputLayerIndex(0),this._activeCubeFace=r}}_getFrameBufferTarget(){if(!1===this.needsFrameBufferTarget)return null;let{width:e,height:t}=this.getDrawingBufferSize(p4),{depth:r,stencil:i}=this,s=this._outputRenderTarget||this._canvasTarget,n=this._frameBufferTargets.get(s);if(void 0===n){(n=new u.O0B(e,t,{depthBuffer:r,stencilBuffer:i,type:this._outputBufferType,format:u.GWd,colorSpace:u.ppV.workingColorSpace,generateMipmaps:!1,minFilter:u.k6q,magFilter:u.k6q,samples:this.samples})).isPostProcessingRenderTarget=!0;let a=()=>{s.removeEventListener("dispose",a),n.dispose(),this._frameBufferTargets.delete(s)};s.addEventListener("dispose",a),this._frameBufferTargets.set(s,n)}let a=this.getOutputRenderTarget();n.depthBuffer=r,n.stencilBuffer=i,null!==a?n.setSize(a.width,a.height,a.depth):n.setSize(e,t,1);let o=this._outputRenderTarget?this._outputRenderTarget.viewport:s._viewport,l=this._outputRenderTarget?this._outputRenderTarget.scissor:s._scissor,d=this._outputRenderTarget?1:s._pixelRatio,h=this._outputRenderTarget?this._outputRenderTarget.scissorTest:s._scissorTest;return n.viewport.copy(o),n.scissor.copy(l),n.viewport.multiplyScalar(d),n.scissor.multiplyScalar(d),n.scissorTest=h,n.multiview=null!==a&&a.multiview,n.useArrayDepthTexture=null!==a&&a.useArrayDepthTexture,n.resolveDepthBuffer=null===a||a.resolveDepthBuffer,n.resolveStencilBuffer=null===a||a.resolveStencilBuffer,n.storeMultisampledColorBuffer=null===a||a.storeMultisampledColorBuffer,n.storeMultisampledDepthBuffer=null===a||a.storeMultisampledDepthBuffer,n.storeMultisampledStencilBuffer=null===a||a.storeMultisampledStencilBuffer,n._autoAllocateDepthBuffer=null!==a&&a._autoAllocateDepthBuffer,n}_renderScene(e,t,r=!0){let i;if(!0===this._isDeviceLost)return;this.shadowMap.type===u.Wk7&&((0,u.R8M)("WebGPURenderer: PCFSoftShadowMap has been removed. Using PCFShadowMap instead."),this.shadowMap.type=u.QP0);let s=r?this._getFrameBufferTarget():null,n=this._nodes.nodeFrame,a=n.renderId,o=this._currentRenderContext,l=this._currentRenderObjectFunction,d=this._handleObjectFunction;this.lighting.beginRender(e),this._callDepth++;let h=!0===e.isScene?e:p3,c=this._renderTarget||this._outputRenderTarget,p=!0===this.xr.isPresenting&&this.isOutputTarget,m=this._activeCubeFace,g=this._activeMipmapLevel;if(null!==s?(i=s,this.setRenderTarget(i)):i=c,null!==i&&!0===i.depthBuffer){let e=this._textures.get(i);!0!==e.depthInitialized&&((!1===this.autoClear||!0===this.autoClear&&!1===this.autoClearDepth)&&this.clearDepth(),e.depthInitialized=!0)}let f=this._renderContexts.get(i,this._mrt,this._callDepth);this._currentRenderContext=f,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this._handleObjectFunction=this._renderObjectDirect,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,n.renderId=this.info.calls,this.backend.updateTimeStampUID(f),this.inspector.beginRender(this.backend.getTimestampUID(f),e,t,i),!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),t=this._updateCamera(t,p);let b=this._canvasTarget,y=b._viewport,x=b._scissor,T=b._pixelRatio;null!==i&&(y=i.viewport,x=i.scissor,T=1),this.getDrawingBufferSize(p4),p8.set(0,0,p4.width,p4.height);let _=void 0===y.minDepth?0:y.minDepth,v=void 0===y.maxDepth?1:y.maxDepth;f.viewportValue.copy(y).multiplyScalar(T).floor(),f.viewportValue.width>>=g,f.viewportValue.height>>=g,f.viewportValue.minDepth=_,f.viewportValue.maxDepth=v,f.viewport=!1===f.viewportValue.equals(p8),f.scissorValue.copy(x).multiplyScalar(T).floor(),f.scissor=b._scissorTest&&!1===f.scissorValue.equals(p8),f.scissorValue.width>>=g,f.scissorValue.height>>=g,f.clippingContext||(f.clippingContext=new pI),f.clippingContext.updateGlobal(h,t),h.onBeforeRender(this,e,t,i),p9.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),t.isArrayCamera?p6.setFromArrayCamera(t):p5.setFromProjectionMatrix(p9,t.coordinateSystem,t.reversedDepth),this._renderLists.update(n.frameId);let S=this._renderLists.get(e,t,this.lighting);if(S.begin(),this._projectObject(e,t,0,S,f.clippingContext),S.finish(),!0===this.sortObjects&&S.sort(this._opaqueSort,this._transparentSort),null!==i){this._textures.updateRenderTarget(i,g);let e=this._textures.get(i);f.textures=e.textures,f.depthTexture=e.depthTexture,f.width=e.width,f.height=e.height,f.renderTarget=i,f.depth=i.depthBuffer,f.stencil=i.stencilBuffer}else f.textures=null,f.depthTexture=null,f.width=p4.width,f.height=p4.height,f.depth=this.depth,f.stencil=this.stencil;f.width>>=g,f.height>>=g,f.activeCubeFace=m,f.activeMipmapLevel=g,f.occlusionQueryCount=S.occlusionQueryCount,f.fullscreenPass=!0===e.isQuadMesh,f.scissorValue.max(p7.set(0,0,0,0)),f.scissorValue.x+f.scissorValue.width>f.width&&(f.scissorValue.width=Math.max(f.width-f.scissorValue.x,0)),f.scissorValue.y+f.scissorValue.height>f.height&&(f.scissorValue.height=Math.max(f.height-f.scissorValue.y,0)),this._background.update(h,S,f),f.camera=t,this.backend.beginRender(f);let{bundles:R,lightsNode:N,transparentDoublePass:A,transparent:E,opaque:C}=S;return R.length>0&&this._renderBundles(R,h,N),!0===this.opaque&&C.length>0&&this._renderObjects(C,t,h,N),!0===this.transparent&&E.length>0&&this._renderTransparents(E,A,t,h,N),this.backend.finishRender(f),n.renderId=a,this._currentRenderContext=o,this._currentRenderObjectFunction=l,this._handleObjectFunction=d,this.lighting.finishRender(e),this._callDepth--,null!==s&&(this.setRenderTarget(c,m,g),this._renderOutput(i)),h.onAfterRender(this,e,t,i),this.inspector.finishRender(this.backend.getTimestampUID(f)),f}_setXRLayerSize(e,t){this._canvasTarget._width=e,this._canvasTarget._height=t,this.setViewport(0,0,e,t)}_renderOutput(e){let t,r=this._nodes.getOutputCacheKey(),i=this._quadCache.get(e.texture);if(void 0===i){(t=new dZ(new of)).name="Output Color Transform",t.material.name="outputColorTransform",t.material.fragmentNode=this._nodes.getOutputNode(e.texture),i={quad:t,cacheKey:r},this._quadCache.set(e.texture,i);let s=()=>{t.material.dispose(),this._quadCache.delete(e.texture),e.texture.removeEventListener("dispose",s)};e.texture.addEventListener("dispose",s)}else t=i.quad,i.cacheKey!==r&&(t.material.fragmentNode=this._nodes.getOutputNode(e.texture),t.material.needsUpdate=!0,i.cacheKey=r);let s=this.autoClear,n=this.xr.enabled;this.autoClear=!1,this.xr.enabled=!1,this._renderOutputLayers(t,e),this.autoClear=s,this.xr.enabled=n}getMaxAnisotropy(){return this.backend.capabilities.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}getAnimationLoop(){return this._animation.getAnimationLoop()}async getArrayBufferAsync(e,t=null,r=0,i=-1){if(null!==t&&t.isReadbackBuffer&&!1===this.info.memoryMap.has(t)){this.info.createReadbackBuffer(t);let e=()=>{t.removeEventListener("dispose",e),this.info.destroyReadbackBuffer(t)};t.addEventListener("dispose",e)}if(r%4!=0||i>0&&i%4!=0)throw Error('THREE.Renderer: "getArrayBufferAsync()" offset and count must be a multiple of 4.');return await this.backend.getArrayBufferAsync(e,t,r,i)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._canvasTarget.getPixelRatio()}getDrawingBufferSize(e){return this._canvasTarget.getDrawingBufferSize(e)}getSize(e){return this._canvasTarget.getSize(e)}setPixelRatio(e=1){this._canvasTarget.setPixelRatio(e)}setDrawingBufferSize(e,t,r){this.xr&&this.xr.isPresenting||this._canvasTarget.setDrawingBufferSize(e,t,r)}setSize(e,t,r=!0){this.xr&&this.xr.isPresenting||this._canvasTarget.setSize(e,t,r)}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){return this._canvasTarget.getScissor(e)}setScissor(e,t,r,i){this._canvasTarget.setScissor(e,t,r,i)}getScissorTest(){return this._canvasTarget.getScissorTest()}setScissorTest(e){this._canvasTarget.setScissorTest(e),this.backend.setScissorTest(e)}resetState(){if(!1===this._initialized)throw Error('THREE.Renderer: .resetState() called before the backend is initialized. Use "await renderer.init();" before using this method.');this.backend.resetState()}getViewport(e){return this._canvasTarget.getViewport(e)}setViewport(e,t,r,i,s=0,n=1){this._canvasTarget.setViewport(e,t,r,i,s,n)}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return!0===this.reversedDepthBuffer?1-this._clearDepth:this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){let t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,r=!0){if(!1===this._initialized)throw Error('THREE.Renderer: .clear() called before the backend is initialized. Use "await renderer.init();" before using this method.');let i=this._renderTarget||this._getFrameBufferTarget(),s=null;if(null!==i){this._textures.updateRenderTarget(i);let e=this._textures.get(i);(s=this._renderContexts.get(i,null,-1)).textures=e.textures,s.depthTexture=e.depthTexture,s.width=e.width,s.height=e.height,s.renderTarget=i,s.depth=i.depthBuffer,s.stencil=i.stencilBuffer;let t=this.backend.getClearColor();s.clearColorValue.r=t.r,s.clearColorValue.g=t.g,s.clearColorValue.b=t.b,s.clearColorValue.a=t.a,s.clearDepthValue=this.getClearDepth(),s.clearStencilValue=this.getClearStencil(),s.activeCubeFace=this.getActiveCubeFace(),s.activeMipmapLevel=this.getActiveMipmapLevel(),!0===i.depthBuffer&&(e.depthInitialized=!0)}this.backend.clear(e,t,r,s),null!==i&&null===this._renderTarget&&this._renderOutput(i)}clearColor(){this.clear(!0,!1,!1)}clearDepth(){this.clear(!1,!0,!1)}clearStencil(){this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,r=!0){(0,u.mcG)('Renderer: "clearAsync()" has been deprecated. Use "clear()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.clear(e,t,r)}async clearColorAsync(){(0,u.mcG)('Renderer: "clearColorAsync()" has been deprecated. Use "clearColor()" and "await renderer.init();" when creating the renderer.'),this.clear(!0,!1,!1)}async clearDepthAsync(){(0,u.mcG)('Renderer: "clearDepthAsync()" has been deprecated. Use "clearDepth()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!0,!1)}async clearStencilAsync(){(0,u.mcG)('Renderer: "clearStencilAsync()" has been deprecated. Use "clearStencil()" and "await renderer.init();" when creating the renderer.'),this.clear(!1,!1,!0)}get needsFrameBufferTarget(){let e=this.currentToneMapping!==u.y_p,t=this.currentColorSpace!==u.ppV.workingColorSpace;return e||t}get samples(){return this._samples}get currentSamples(){let e=this._samples;return null!==this._renderTarget?e=this._renderTarget.samples:(this.needsFrameBufferTarget||this._currentRenderContext?.fullscreenPass===!0)&&(e=0),e}get currentToneMapping(){return this.isOutputTarget?this.toneMapping:u.y_p}get currentColorSpace(){return this.isOutputTarget?this.outputColorSpace:u.ppV.workingColorSpace}get isOutputTarget(){return this._renderTarget===this._outputRenderTarget||null===this._renderTarget}async dispose(){if(!0===this._initialized){for(let e of(this.info.dispose(),this._inspector.dispose(),this._animation.dispose(),this._objects.dispose(),this._geometries.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this._frameBufferTargets.keys()))e.dispose();await this.backend.dispose()}this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,r=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=r}getRenderTarget(){return this._renderTarget}setOutputRenderTarget(e){this._outputRenderTarget=e}getOutputRenderTarget(){return this._outputRenderTarget}setCanvasTarget(e){this._canvasTarget.removeEventListener("resize",this._onCanvasTargetResize),this._canvasTarget=e,this._canvasTarget.addEventListener("resize",this._onCanvasTargetResize)}getCanvasTarget(){return this._canvasTarget}_resetXRState(){for(let e of(this.backend.setXRTarget(null),this.setOutputRenderTarget(null),this.setRenderTarget(null),this._frameBufferTargets.keys()))e.dispose()}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e,t=null){if(!0===this._isDeviceLost)return;if(!1===this._initialized)return(0,u.R8M)('Renderer: ".compute()" called before the backend is initialized. Try using ".computeAsync()" instead.'),this.computeAsync(e,t);let r=this._nodes.nodeFrame,i=r.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,r.renderId=this.info.calls,this.backend.updateTimeStampUID(e),this.inspector.beginCompute(this.backend.getTimestampUID(e),e);let s=this.backend,n=this._pipelines,a=this._bindings,o=this._nodes,l=Array.isArray(e)?e:[e];if(void 0===l[0]||!0!==l[0].isComputeNode)throw Error("THREE.Renderer: .compute() expects a ComputeNode.");for(let r of(s.beginCompute(e),l)){if(!1===n.has(r)){let e=()=>{r.removeEventListener("dispose",e),n.delete(r),a.deleteForCompute(r),o.delete(r)};r.addEventListener("dispose",e);let t=r.onInitFunction;null!==t&&t.call(r,{renderer:this})}o.updateBeforeForCompute(r),o.updateForCompute(r),a.updateForCompute(r);let i=a.getForCompute(r),l=n.getForCompute(r,i);s.compute(e,r,i,l,t),o.updateAfterForCompute(r)}s.finishCompute(e),r.renderId=i,this.inspector.finishCompute(this.backend.getTimestampUID(e))}async computeAsync(e,t=null){!1===this._initialized&&await this.init(),this.compute(e,t)}async hasFeatureAsync(e){return(0,u.mcG)('Renderer: "hasFeatureAsync()" has been deprecated. Use "hasFeature()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.hasFeature(e)}async resolveTimestampsAsync(e="render"){return!1===this._initialized&&await this.init(),this.backend.resolveTimestampsAsync(e)}hasFeature(e){if(!1===this._initialized)throw Error('THREE.Renderer: .hasFeature() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this.backend.hasFeature(e)}hasInitialized(){return this._initialized}async initTextureAsync(e){(0,u.mcG)('Renderer: "initTextureAsync()" has been deprecated. Use "initTexture()" and "await renderer.init();" when creating the renderer.'),await this.init(),this.initTexture(e)}initTexture(e){if(!1===this._initialized)throw Error('THREE.Renderer: .initTexture() called before the backend is initialized. Use "await renderer.init();" before using this method.');this._textures.updateTexture(e)}initRenderTarget(e){if(!1===this._initialized)throw Error('THREE.Renderer: .initRenderTarget() called before the backend is initialized. Use "await renderer.init();" before using this method.');this._textures.updateRenderTarget(e);let t=this._textures.get(e),r=this._renderContexts.get(e);r.textures=t.textures,r.depthTexture=t.depthTexture,r.width=t.width,r.height=t.height,r.renderTarget=e,r.depth=e.depthBuffer,r.stencil=e.stencilBuffer,this.backend.initRenderTarget(r)}copyFramebufferToTexture(e,t=null){let r;if(null!==t)if(t.isVector2)t=p7.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void(0,u.z3S)("Renderer.copyFramebufferToTexture: Invalid rectangle.");t=p7.copy(t).floor()}else t=p7.set(0,0,e.image.width,e.image.height);let i=this._currentRenderContext;null!==i?r=i.renderTarget:null!==(r=this._renderTarget||this._getFrameBufferTarget())&&(this._textures.updateRenderTarget(r),i=this._textures.get(r)),this._textures.updateTexture(e,{renderTarget:r}),this.backend.copyFramebufferToTexture(e,i,t),this._inspector.copyFramebufferToTexture(e)}copyTextureToTexture(e,t,r=null,i=null,s=0,n=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,r,i,s,n),this._inspector.copyTextureToTexture(e,t)}async readRenderTargetPixelsAsync(e,t,r,i,s,n=0,a=0){return this.backend.copyTextureToBuffer(e.textures[n],t,r,i,s,a)}_projectObject(e,t,r,i,s){if(!1===e.visible)return;if(e.layers.test(t.layers)){if(e.isGroup)r=e.renderOrder,e.isClippingGroup&&e.enabled&&(s=s.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)i.pushLight(e);else if(e.isSprite){let n=t.isArrayCamera?p6:p5;if(!e.frustumCulled||e.intersectsFrustum(n)){!0===this.sortObjects&&p7.setFromMatrixPosition(e.matrixWorld).applyMatrix4(p9);let{geometry:t,material:n}=e;n.visible&&i.push(e,t,n,r,p7.z,null,s)}}else if(e.isLineLoop)(0,u.z3S)("Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if(e.isMesh||e.isLine||e.isPoints){let n=t.isArrayCamera?p6:p5;if(!e.frustumCulled||e.intersectsFrustum(n)){let{geometry:t,material:n}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),p7.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(p9)),Array.isArray(n)){let a=t.groups;for(let o=0,l=a.length;o<l;o++){let l=a[o],u=n[l.materialIndex];u&&u.visible&&i.push(e,t,u,r,p7.z,l,s)}}else n.visible&&i.push(e,t,n,r,p7.z,null,s)}}}if(!0===e.isBundleGroup&&void 0!==this.backend.beginBundle){let n=i;i=this._renderLists.get(e,t,this.lighting);let a=this._bundles.get(e,t,this._currentRenderContext),o=this.backend.get(a);if(this._bundleNeedsUpdate(e,o)){i.begin(),void 0===o.renderObjects?o.renderObjects=[]:o.renderObjects.length=0;let n=e.children;for(let e=0,a=n.length;e<a;e++)this._projectObject(n[e],t,r,i,s);i.finish()}n.pushBundle({bundleGroup:e,camera:t,renderList:i});return}let n=e.children;for(let e=0,a=n.length;e<a;e++)this._projectObject(n[e],t,r,i,s)}_renderBundles(e,t,r){for(let i of e)this._renderBundle(i,t,r)}_renderTransparents(e,t,r,i,s){if(t.length>0){for(let{material:e}of t)e.side=u.hsX;for(let{material:e}of(this._renderObjects(t,r,i,s,"backSide"),t))e.side=u.hB5;for(let{material:n}of(this._renderObjects(e,r,i,s),t))n.side=u.$EB}else this._renderObjects(e,r,i,s)}_renderObjects(e,t,r,i,s=null){for(let n=0,a=e.length;n<a;n++){let{object:a,geometry:o,material:l,group:u,clippingContext:d}=e[n];this._currentRenderObjectFunction(a,r,t,o,l,u,i,d,s)}}_getShadowNodes(e){let t=e.version,r=this._cacheShadowNodes.get(e);if(void 0===r||r.version!==t){let i=e.map&&e.map.isTexture,s=e.colorNode&&e.colorNode.isNode,n=e.castShadowNode&&e.castShadowNode.isNode,a=e.maskShadowNode&&e.maskShadowNode.isNode||e.maskNode&&e.maskNode.isNode,o=null,l=null,d=null;if(i||s||n||a){let t,r;if(n?(t=e.castShadowNode.rgb,r=e.castShadowNode.a,!0!==this.shadowMap.transmitted&&(0,u.mcG)("Renderer: `shadowMap.transmitted` needs to be set to `true` when using `material.castShadowNode`.")):(t=eW(0),r=eD(1)),i&&(r=r.mul(nd("map","texture",e).a)),s&&(r=r.mul(e.colorNode.a)),l=eX(t,r),a){let t=e.maskShadowNode||e.maskNode;l=eF(([e])=>(t.not().discard(),e))(l)}}e.depthNode&&e.depthNode.isNode&&(d=e.depthNode),e.castShadowPositionNode&&e.castShadowPositionNode.isNode?o=e.castShadowPositionNode:e.positionNode&&e.positionNode.isNode&&(o=e.positionNode),r={version:t,colorNode:l,depthNode:d,positionNode:o},this._cacheShadowNodes.set(e,r)}return r}_updateCamera(e,t){let r=this.xr;if(!1===r.isPresenting||!1===t){let t=!1;if(!0===this.reversedDepthBuffer&&!0!==e.reversedDepth){if(e._reversedDepth=!0,e.isArrayCamera)for(let t of e.cameras)t._reversedDepth=!0;t=!0}let r=this.coordinateSystem;if(e.coordinateSystem!==r){if(e.coordinateSystem=r,e.isArrayCamera)for(let t of e.cameras)t.coordinateSystem=r;t=!0}if(!0===t&&(e.updateProjectionMatrix(),e.isArrayCamera))for(let t of e.cameras)t.updateProjectionMatrix()}return null===e.parent&&!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),!0===t&&!0===r.enabled&&!0===r.isPresenting&&(!0===r.cameraAutoUpdate&&r.updateCamera(e),e=r.getCamera()),e}renderObject(e,t,r,i,s,n,a,o=null,l=null){let d,h,c,p,m,g,f,b=!1,y=this._currentSourceMaterial;if(e.onBeforeRender(this,t,r,i,s,n),!0===s.allowOverride&&null!==t.overrideMaterial){this._currentSourceMaterial=s;let e=t.overrideMaterial;if(b=!0,d=e.isNodeMaterial?e.colorNode:null,h=e.isNodeMaterial?e.depthNode:null,c=e.isNodeMaterial?e.positionNode:null,p=t.overrideMaterial.side,m=e.displacementMap,g=e.displacementScale,f=e.displacementBias,s.positionNode&&s.positionNode.isNode&&(e.positionNode=s.positionNode),e.alphaTest=s.alphaTest,e.alphaMap=s.alphaMap,e.displacementMap=s.displacementMap,e.displacementScale=s.displacementScale,e.displacementBias=s.displacementBias,e.transparent=s.transparent||s.transmission>0||s.transmissionNode&&s.transmissionNode.isNode||s.backdropNode&&s.backdropNode.isNode,e.isShadowPassMaterial){let{colorNode:t,depthNode:r,positionNode:i}=this._getShadowNodes(s);this.shadowMap.type===u.RyA?e.side=null!==s.shadowSide?s.shadowSide:s.side:e.side=null!==s.shadowSide?s.shadowSide:me[s.side],null!==t&&(e.colorNode=t),null!==r&&(e.depthNode=r),null!==i&&(e.positionNode=i)}s=e}!0===s.transparent&&s.side===u.$EB&&!1===s.forceSinglePass?(s.side=u.hsX,this._handleObjectFunction(e,s,t,r,a,n,o,"backSide"),s.side=u.hB5,this._handleObjectFunction(e,s,t,r,a,n,o,l),s.side=u.$EB):this._handleObjectFunction(e,s,t,r,a,n,o,l),b&&(t.overrideMaterial.colorNode=d,t.overrideMaterial.depthNode=h,t.overrideMaterial.positionNode=c,t.overrideMaterial.side=p,t.overrideMaterial.displacementMap=m,t.overrideMaterial.displacementScale=g,t.overrideMaterial.displacementBias=f),this._currentSourceMaterial=y,e.onAfterRender(this,t,r,i,s,n)}hasCompatibility(e){if(!1===this._initialized)throw Error('THREE.Renderer: .hasCompatibility() called before the backend is initialized. Use "await renderer.init();" before using this method.');return this.backend.hasCompatibility(e)}_renderObjectDirect(e,t,r,i,s,n,a,o){let l=this._objects.get(e,t,r,i,s,this._currentRenderContext,a,o);l.drawRange=e.geometry.drawRange,l.group=n,null!==this._currentRenderBundle&&(this.backend.get(this._currentRenderBundle).renderObjects.push(l),l.bundle=this._currentRenderBundle.bundleGroup);let d=this._nodes.needsRefresh(l);d===u.B0D.FULL?(this._nodes.updateBefore(l),this._geometries.updateForRender(l),this._nodes.updateForRender(l),this._bindings.updateForRender(l)):d===u.B0D.SHARED&&(this._nodes.updateBefore(l),this._nodes.updateForRender(l),this._bindings.updateSharedForRender(l)),this._pipelines.updateForRender(l),this._pipelines.isReady(l)&&(this.backend.draw(l,this.info),d!==u.B0D.NONE&&this._nodes.updateAfter(l))}_createObjectPipeline(e,t,r,i,s,n,a,o){if(null!==this._compilationPromises)return void this._compilationPromises.push({object:e,material:t,scene:r,camera:i,lightsNode:s,group:n,clippingContext:a,passId:o,renderContext:this._currentRenderContext});let l=this._objects.get(e,t,r,i,s,this._currentRenderContext,a,o);l.drawRange=e.geometry.drawRange,l.group=n,this._nodes.updateBefore(l),this._geometries.updateForRender(l),this._nodes.updateForRender(l),this._bindings.updateForRender(l),this._pipelines.getForRender(l,this._compilationPromises),this._nodes.updateAfter(l)}_onCanvasTargetResize(){this._initialized&&this.backend.updateSize()}get compile(){return this.compileAsync}}class mr{constructor(e=""){this.name=e,this.visibility=0}setVisibility(e){this.visibility|=e}getVisibility(){return this.visibility}clone(){return Object.assign(new this.constructor,this)}}function mi(e){return e+(16-e%16)%16}class ms extends mr{constructor(e,t=null){super(e),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=t,this._updateRanges=[]}get updateRanges(){return this._updateRanges}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}get byteLength(){return mi(this._buffer.byteLength)}get buffer(){return this._buffer}update(){return!0}release(){this._buffer=null}}class mn extends ms{constructor(e,t=null){super(e,t),this.isUniformBuffer=!0}}let ma=0;class mo extends mn{constructor(e,t){super("UniformBuffer_"+(e&&e.name?e.name:ma++),e?e.value:null),this.nodeUniform=e,this.groupNode=t,this.isNodeUniformBuffer=!0}set updateRanges(e){this.nodeUniform.updateRanges=e}get updateRanges(){return this.nodeUniform.updateRanges}addUpdateRange(e,t){this.nodeUniform.addUpdateRange(e,t)}clearUpdateRanges(){this.nodeUniform.clearUpdateRanges()}get byteLength(){return mi(this.buffer.byteLength)}get buffer(){return this.nodeUniform.value}}class ml extends mn{constructor(e){super(e),this.isUniformsGroup=!0,this._values=null,this.uniforms=[],this._updateRangeCache=new Map,this._addedIndices=new Set}addUniformUpdateRange(e){let t=e.index;if(this._addedIndices.has(t))return;let r=this._updateRangeCache.get(t);void 0===r&&(r={start:0,count:0},this._updateRangeCache.set(t,r)),r.start=e.offset,r.count=e.itemSize,this._addedIndices.add(t),this.updateRanges.push(r)}clearUpdateRanges(){this._addedIndices.clear(),super.clearUpdateRanges()}addUniform(e){return this.uniforms.push(e),this}removeUniform(e){let t=this.uniforms.indexOf(e);return -1!==t&&this.uniforms.splice(t,1),this}get values(){return null===this._values&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let e=this._buffer;return null===e&&(e=new Float32Array(new ArrayBuffer(this.byteLength)),this._buffer=e),e}get byteLength(){let e=this.bytesPerElement,t=0;for(let r=0,i=this.uniforms.length;r<i;r++){let i=this.uniforms[r],s=i.boundary,n=i.itemSize*e,a=t%16,o=a%s,l=a+o;t+=o,0!==l&&16-l<n&&(t+=16-l),i.offset=t/e,i.index=r,t+=n}return 16*Math.ceil(t/16)}update(){let e=!1;for(let t of this.uniforms)!0===this.updateByType(t)&&(e=!0);return e}release(){super.release(),this._values=null}updateByType(e){return e.isNumberUniform?this.updateNumber(e):e.isVector2Uniform?this.updateVector2(e):e.isVector3Uniform?this.updateVector3(e):e.isVector4Uniform?this.updateVector4(e):e.isColorUniform?this.updateColor(e):e.isMatrix3Uniform?this.updateMatrix3(e):e.isMatrix4Uniform?this.updateMatrix4(e):void(0,u.z3S)("WebGPUUniformsGroup: Unsupported uniform type.",e)}updateNumber(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,n=e.getType();return r[s]!==i&&(this._getBufferForType(n)[s]=r[s]=i,t=!0,this.addUniformUpdateRange(e)),t}updateVector2(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,n=e.getType();if(r[s+0]!==i.x||r[s+1]!==i.y){let a=this._getBufferForType(n);a[s+0]=r[s+0]=i.x,a[s+1]=r[s+1]=i.y,t=!0,this.addUniformUpdateRange(e)}return t}updateVector3(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,n=e.getType();if(r[s+0]!==i.x||r[s+1]!==i.y||r[s+2]!==i.z){let a=this._getBufferForType(n);a[s+0]=r[s+0]=i.x,a[s+1]=r[s+1]=i.y,a[s+2]=r[s+2]=i.z,t=!0,this.addUniformUpdateRange(e)}return t}updateVector4(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset,n=e.getType();if(r[s+0]!==i.x||r[s+1]!==i.y||r[s+2]!==i.z||r[s+3]!==i.w){let a=this._getBufferForType(n);a[s+0]=r[s+0]=i.x,a[s+1]=r[s+1]=i.y,a[s+2]=r[s+2]=i.z,a[s+3]=r[s+3]=i.w,t=!0,this.addUniformUpdateRange(e)}return t}updateColor(e){let t=!1,r=this.values,i=e.getValue(),s=e.offset;if(r[s+0]!==i.r||r[s+1]!==i.g||r[s+2]!==i.b){let n=this.buffer;n[s+0]=r[s+0]=i.r,n[s+1]=r[s+1]=i.g,n[s+2]=r[s+2]=i.b,t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix3(e){let t=!1,r=this.values,i=e.getValue().elements,s=e.offset;if(r[s+0]!==i[0]||r[s+1]!==i[1]||r[s+2]!==i[2]||r[s+4]!==i[3]||r[s+5]!==i[4]||r[s+6]!==i[5]||r[s+8]!==i[6]||r[s+9]!==i[7]||r[s+10]!==i[8]){let n=this.buffer;n[s+0]=r[s+0]=i[0],n[s+1]=r[s+1]=i[1],n[s+2]=r[s+2]=i[2],n[s+4]=r[s+4]=i[3],n[s+5]=r[s+5]=i[4],n[s+6]=r[s+6]=i[5],n[s+8]=r[s+8]=i[6],n[s+9]=r[s+9]=i[7],n[s+10]=r[s+10]=i[8],t=!0,this.addUniformUpdateRange(e)}return t}updateMatrix4(e){let t=!1,r=this.values,i=e.getValue().elements,s=e.offset;return!1===function(e,t,r){for(let i=0,s=t.length;i<s;i++)if(e[r+i]!==t[i])return!1;return!0}(r,i,s)&&(this.buffer.set(i,s),function(e,t,r){for(let i=0,s=t.length;i<s;i++)e[r+i]=t[i]}(r,i,s),t=!0,this.addUniformUpdateRange(e)),t}_getBufferForType(e){return"int"===e||"ivec2"===e||"ivec3"===e||"ivec4"===e?new Int32Array(this.buffer.buffer):"uint"===e||"uvec2"===e||"uvec3"===e||"uvec4"===e?new Uint32Array(this.buffer.buffer):this.buffer}}let mu=0;class md extends ml{constructor(e,t){super(e),this.id=mu++,this.groupNode=t,this.isNodeUniformsGroup=!0}}class mh extends mr{constructor(e,t){super(e),this._texture=t,this.version=-1,this.generation=null,this.samplerKey="",this.isSampler=!0}set texture(e){this._texture!==e&&(this._texture=e,this.reset())}get texture(){return this._texture}update(){let{texture:e,version:t}=this;return t!==e.version&&(this.version=e.version,!0)}reset(){this.generation=null,this.version=-1}release(){this._texture=null}}let mc=0;class mp extends mh{constructor(e,t){super(e,t),this.id=mc++,this.store=!1,this.mipLevel=0,this.isSampledTexture=!0}}class mm extends mp{constructor(e,t,r,i=null){super(e,t?t.value:null),this.textureNode=t,this.groupNode=r,this.access=i}update(){let{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class mg extends mm{constructor(e,t,r,i=null){super(e,t,r,i),this.isSampledCubeTexture=!0}}class mf extends mm{constructor(e,t,r,i=null){super(e,t,r,i),this.isSampledTexture3D=!0}}let mb={textureGather:new hd(`
|
|
14
|
+
vec4 tsl_textureGather( const int comp, sampler2D map, vec2 coord, ivec2 offset, bool flipY ) {
|
|
15
|
+
if ( flipY ) offset.y = - offset.y;
|
|
16
|
+
vec2 size = vec2( textureSize( map, 0 ) );
|
|
17
|
+
vec2 st = floor( coord * size + vec2( offset ) - 0.5 );
|
|
18
|
+
vec4 ij = vec4( st + 0.5, st + 1.5 ) / size.xyxy;
|
|
19
|
+
vec4 ret = vec4(
|
|
20
|
+
textureLod( map, ij.xw, 0.0 )[ comp ],
|
|
21
|
+
textureLod( map, ij.zw, 0.0 )[ comp ],
|
|
22
|
+
textureLod( map, ij.zy, 0.0 )[ comp ],
|
|
23
|
+
textureLod( map, ij.xy, 0.0 )[ comp ]
|
|
24
|
+
);
|
|
25
|
+
return flipY ? ret.wzyx : ret;
|
|
26
|
+
}
|
|
27
|
+
`),textureGatherArray:new hd(`
|
|
28
|
+
vec4 tsl_textureGather_array( const int comp, sampler2DArray map, vec3 coord, ivec2 offset, bool flipY ) {
|
|
29
|
+
if ( flipY ) offset.y = - offset.y;
|
|
30
|
+
vec2 size = vec2( textureSize( map, 0 ).xy );
|
|
31
|
+
vec2 st = floor( coord.xy * size + vec2( offset ) - 0.5 );
|
|
32
|
+
vec4 ij = vec4( st + 0.5, st + 1.5 ) / size.xyxy;
|
|
33
|
+
vec4 ret = vec4(
|
|
34
|
+
textureLod( map, vec3( ij.xw, coord.z ), 0.0 )[ comp ],
|
|
35
|
+
textureLod( map, vec3( ij.zw, coord.z ), 0.0 )[ comp ],
|
|
36
|
+
textureLod( map, vec3( ij.zy, coord.z ), 0.0 )[ comp ],
|
|
37
|
+
textureLod( map, vec3( ij.xy, coord.z ), 0.0 )[ comp ]
|
|
38
|
+
);
|
|
39
|
+
return flipY ? ret.wzyx : ret;
|
|
40
|
+
}
|
|
41
|
+
`),textureGatherCompare:new hd(`
|
|
42
|
+
vec4 tsl_textureGatherCompare( sampler2DShadow map, vec2 coord, ivec2 offset, float ref, bool flipY ) {
|
|
43
|
+
if ( flipY ) offset.y = - offset.y;
|
|
44
|
+
vec2 size = vec2( textureSize( map, 0 ) );
|
|
45
|
+
vec2 st = floor( coord * size + vec2( offset ) - 0.5 );
|
|
46
|
+
vec4 ij = vec4( st + 0.5, st + 1.5 ) / size.xyxy;
|
|
47
|
+
vec4 ret = vec4(
|
|
48
|
+
textureLod( map, vec3( ij.xw, ref ), 0.0 ),
|
|
49
|
+
textureLod( map, vec3( ij.zw, ref ), 0.0 ),
|
|
50
|
+
textureLod( map, vec3( ij.zy, ref ), 0.0 ),
|
|
51
|
+
textureLod( map, vec3( ij.xy, ref ), 0.0 )
|
|
52
|
+
);
|
|
53
|
+
return flipY ? ret.wzyx : ret;
|
|
54
|
+
}
|
|
55
|
+
`),textureGatherCompareArray:new hd(`
|
|
56
|
+
vec4 tsl_textureGatherCompare_array( sampler2DArrayShadow map, vec3 coord, ivec2 offset, float ref, bool flipY ) {
|
|
57
|
+
if ( flipY ) offset.y = - offset.y;
|
|
58
|
+
vec2 size = vec2( textureSize( map, 0 ).xy );
|
|
59
|
+
vec2 st = floor( coord.xy * size + vec2( offset ) - 0.5 );
|
|
60
|
+
vec4 ij = vec4( st + 0.5, st + 1.5 ) / size.xyxy;
|
|
61
|
+
vec4 ret = vec4(
|
|
62
|
+
texture( map, vec4( ij.xw, coord.z, ref ) ),
|
|
63
|
+
texture( map, vec4( ij.zw, coord.z, ref ) ),
|
|
64
|
+
texture( map, vec4( ij.zy, coord.z, ref ) ),
|
|
65
|
+
texture( map, vec4( ij.xy, coord.z, ref ) )
|
|
66
|
+
);
|
|
67
|
+
return flipY ? ret.wzyx : ret;
|
|
68
|
+
}
|
|
69
|
+
`),floatpack_snorm_4x8:new hd("uint tsl_packSnorm4x8( vec4 v ) { uvec4 u = uvec4( ivec4( round( clamp( v, -1.0, 1.0 ) * 127.0 ) ) & 0xff ); return u.x | u.y << 8 | u.z << 16 | u.w << 24; }"),floatpack_unorm_4x8:new hd("uint tsl_packUnorm4x8( vec4 v ) { uvec4 u = uvec4( round( clamp( v, 0.0, 1.0 ) * 255.0 ) ); return u.x | u.y << 8 | u.z << 16 | u.w << 24; }"),floatunpack_snorm_4x8:new hd("vec4 tsl_unpackSnorm4x8( uint x ) { return max( vec4( ivec4( x << 24, x << 16, x << 8, x ) >> 24 ) / 127.0, -1.0 ); }"),floatunpack_unorm_4x8:new hd("vec4 tsl_unpackUnorm4x8( uint x ) { return vec4( uvec4( x, x >> 8, x >> 16, x >> 24 ) & 0xffu ) / 255.0; }")},my={equals:"equal",bitcast_float_int:"floatBitsToInt",bitcast_int_float:"intBitsToFloat",bitcast_uint_float:"uintBitsToFloat",bitcast_float_uint:"floatBitsToUint",floatpack_snorm_2x16:"packSnorm2x16",floatpack_unorm_2x16:"packUnorm2x16",floatpack_float16_2x16:"packHalf2x16",floatpack_snorm_4x8:"tsl_packSnorm4x8",floatpack_unorm_4x8:"tsl_packUnorm4x8",floatunpack_snorm_2x16:"unpackSnorm2x16",floatunpack_unorm_2x16:"unpackUnorm2x16",floatunpack_float16_2x16:"unpackHalf2x16",floatunpack_snorm_4x8:"tsl_unpackSnorm4x8",floatunpack_unorm_4x8:"tsl_unpackUnorm4x8"},mx={low:"lowp",medium:"mediump",high:"highp"},mT={swizzleAssign:!0,storageBuffer:!1},m_={perspective:"smooth",linear:"noperspective"},mv={centroid:"centroid"},mS=`
|
|
70
|
+
precision highp float;
|
|
71
|
+
precision highp int;
|
|
72
|
+
precision highp sampler2D;
|
|
73
|
+
precision highp sampler3D;
|
|
74
|
+
precision highp samplerCube;
|
|
75
|
+
precision highp sampler2DArray;
|
|
76
|
+
|
|
77
|
+
precision highp usampler2D;
|
|
78
|
+
precision highp usampler3D;
|
|
79
|
+
precision highp usamplerCube;
|
|
80
|
+
precision highp usampler2DArray;
|
|
81
|
+
|
|
82
|
+
precision highp isampler2D;
|
|
83
|
+
precision highp isampler3D;
|
|
84
|
+
precision highp isamplerCube;
|
|
85
|
+
precision highp isampler2DArray;
|
|
86
|
+
|
|
87
|
+
precision highp sampler2DShadow;
|
|
88
|
+
precision highp sampler2DArrayShadow;
|
|
89
|
+
precision highp samplerCubeShadow;
|
|
90
|
+
`,mR=new Set(["const","uniform","buffer","shared","attribute","varying","coherent","volatile","restrict","readonly","writeonly","atomic_uint","layout","centroid","flat","smooth","noperspective","patch","sample","invariant","precise","break","continue","do","for","while","switch","case","default","if","else","subroutine","in","out","inout","int","void","bool","true","false","float","double","discard","return","vec2","vec3","vec4","ivec2","ivec3","ivec4","bvec2","bvec3","bvec4","uint","uvec2","uvec3","uvec4","dvec2","dvec3","dvec4","mat2","mat3","mat4","mat2x2","mat2x3","mat2x4","mat3x2","mat3x3","mat3x4","mat4x2","mat4x3","mat4x4","dmat2","dmat3","dmat4","dmat2x2","dmat2x3","dmat2x4","dmat3x2","dmat3x3","dmat3x4","dmat4x2","dmat4x3","dmat4x4","lowp","mediump","highp","precision","sampler2D","sampler3D","samplerCube","sampler2DShadow","samplerCubeShadow","sampler2DArray","sampler2DArrayShadow","isampler2D","isampler3D","isamplerCube","isampler2DArray","usampler2D","usampler3D","usamplerCube","usampler2DArray","struct","common","partition","active","asm","class","union","enum","typedef","template","this","resource","goto","inline","noinline","public","static","extern","external","interface","long","short","half","fixed","unsigned","superp","input","output","hvec2","hvec3","hvec4","fvec2","fvec3","fvec4","sampler3DRect","filter","sizeof","cast","namespace","using","main"]);class mN extends pd{constructor(e,t){super(e,t,new pM),this.uniformGroups={},this.transforms=[],this.extensions={},this.builtins={vertex:[],fragment:[],compute:[]}}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==u.jf0}_include(e){let t=mb[e];return t.build(this),this.addInclude(t),t}getMethod(e){return void 0!==mb[e]&&this._include(e),my[e]||e}getBitcastMethod(e,t){let r=this.getComponentType(t),i=this.getComponentType(e);return"float"!==r&&"float"!==i&&this.getTypeLength(t)===this.getTypeLength(e)?this.getType(e):this.getMethod(`bitcast_${r}_${i}`)}getFloatPackingMethod(e,t="2x16"){return this.getMethod(`floatpack_${e}_${t}`)}getFloatUnpackingMethod(e,t="2x16"){return this.getMethod(`floatunpack_${e}_${t}`)}getTernary(e,t,r){return`${e} ? ${t} : ${r}`}getOutputStructName(){return""}buildFunctionCode(e){let t=e.layout,r=this.flowShaderNode(e),i=[];for(let e of t.inputs)i.push(this.getType(e.type)+" "+e.name);return`${this.getType(t.type)} ${t.name}( ${i.join(", ")} ) {
|
|
91
|
+
|
|
92
|
+
${r.vars}
|
|
93
|
+
|
|
94
|
+
${r.code}
|
|
95
|
+
return ${r.result};
|
|
96
|
+
|
|
97
|
+
}`}setupPBO(e){let t=e.value;if(void 0===t.pbo){let e=t.array,r=t.count*t.itemSize,{itemSize:i}=t,s=t.array.constructor.name.toLowerCase().includes("int"),n=s?u.ZQM:u.VT0;2===i?n=s?u.TkQ:u.paN:3===i?n=s?u.VGF:u.HIg:4===i&&(n=s?u.c90:u.GWd);let a={Float32Array:u.RQf,Uint8Array:u.OUM,Uint16Array:u.cHt,Uint32Array:u.bkx,Int8Array:u.tJf,Int16Array:u.fBL,Int32Array:u.Yuy,Uint8ClampedArray:u.OUM},o=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(r/i)))),l=Math.ceil(r/i/o);o*l*i<r&&l++;let d=o*l*i,h=new e.constructor(d);h.set(e,0),t.array=h;let c=new u.GYF(t.array,o,l,n,a[t.array.constructor.name]||u.RQf);c.needsUpdate=!0,c.isPBOTexture=!0;let p=new i1(c,null,null);p.setPrecision("high"),t.pboNode=p,t.pbo=p.value,this.getUniformFromNode(t.pboNode,"texture",this.shaderStage,this.context.nodeName)}}getPropertyName(e,t=this.shaderStage){return e.isNodeUniform&&!0!==e.node.isTextureNode&&!0!==e.node.isBufferNode?e.name:super.getPropertyName(e,t)}isReservedKeyword(e){return mR.has(e)}generatePBO(e){let{node:t,indexNode:r}=e,i=t.value;this.renderer.backend.has(i)&&(this.renderer.backend.get(i).pbo=i.pbo);let s=this.getUniformFromNode(i.pboNode,"texture",this.shaderStage,this.context.nodeName),n=this.getPropertyName(s);this.increaseUsage(r);let a=r.build(this,"uint"),o=this.getDataFromNode(e),l=o.propertyName;if(void 0===l){let r=this.getVarFromNode(e);l=this.getPropertyName(r);let s=this.getDataFromNode(t),d=s.propertySizeName;void 0===d&&(d=l+"Size",this.getVarFromNode(t,d,"uint"),this.addLineFlowCode(`${d} = uint( textureSize( ${n}, 0 ).x )`,e),s.propertySizeName=d);let{itemSize:h}=i,c="."+U.join("").slice(0,h),p=`ivec2(${a} % ${d}, ${a} / ${d})`,m=this.generateTextureLoad(null,n,p,"0",null,null),g="vec4";i.pbo.type===u.bkx?g="uvec4":i.pbo.type===u.Yuy&&(g="ivec4"),this.addLineFlowCode(`${l} = ${g}(${m})${c}`,e),o.propertyName=l}return l}generateTextureLoad(e,t,r,i,s,n){let a;return null===i&&(i="0"),a=s?n?`texelFetchOffset( ${t}, ivec3( ${r}, ${s} ), int( ${i} ), ${n} )`:`texelFetch( ${t}, ivec3( ${r}, ${s} ), int( ${i} ) )`:n?`texelFetchOffset( ${t}, ${r}, int( ${i} ), ${n} )`:`texelFetch( ${t}, ${r}, int( ${i} ) )`,null!==e&&e.isDepthTexture&&(a+=".x"),a}generateTexture(e,t,r,i,s){return(i&&(r=`vec3( ${r}, ${i} )`),e.isDepthTexture)?s?`textureOffset( ${t}, ${r}, ${s} ).x`:`texture( ${t}, ${r} ).x`:s?`textureOffset( ${t}, ${r}, ${s} )`:`texture( ${t}, ${r} )`}generateTextureSize(e,t,r){return`textureSize( ${t}, ${r} )`}generateTextureLevel(e,t,r,i,s,n){return(s&&(r=`vec3( ${r}, ${s} )`),n)?`textureLodOffset( ${t}, ${r}, ${i}, ${n} )`:`textureLod( ${t}, ${r}, ${i} )`}generateTextureBias(e,t,r,i,s,n){return(s&&(r=`vec3( ${r}, ${s} )`),n)?`textureOffset( ${t}, ${r}, ${n}, ${i} )`:`texture( ${t}, ${r}, ${i} )`}generateTextureGrad(e,t,r,i,s,n){return(s&&(r=`vec3( ${r}, ${s} )`),n)?`textureGradOffset( ${t}, ${r}, ${i[0]}, ${i[1]}, ${n} )`:`textureGrad( ${t}, ${r}, ${i[0]}, ${i[1]} )`}generateTextureCompare(e,t,r,i,s,n,a=this.shaderStage){if("fragment"===a)return e.isCubeTexture?`texture( ${t}, vec4( ${r}, ${i} ) )`:s?n?`textureOffset( ${t}, vec4( ${r}, ${s}, ${i} ), ${n} )`:`texture( ${t}, vec4( ${r}, ${s}, ${i} ) )`:n?`textureOffset( ${t}, vec3( ${r}, ${i} ), ${n} )`:`texture( ${t}, vec3( ${r}, ${i} ) )`;(0,u.z3S)(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}generateTextureGather(e,t,r,i,s,n,a){return(e.isDepthTexture&&(i="0"),null===n&&(n="ivec2( 0 )"),null===a&&(a="false"),s)?(this._include("textureGatherArray"),`tsl_textureGather_array( ${i}, ${t}, vec3( ${r}, ${s} ), ${n}, ${a} )`):(this._include("textureGather"),`tsl_textureGather( ${i}, ${t}, ${r}, ${n}, ${a} )`)}generateTextureGatherCompare(e,t,r,i,s,n,a){return(null===n&&(n="ivec2( 0 )"),null===a&&(a="false"),s)?(this._include("textureGatherCompareArray"),`tsl_textureGatherCompare_array( ${t}, vec3( ${r}, ${s} ), ${n}, ${i}, ${a} )`):(this._include("textureGatherCompare"),`tsl_textureGatherCompare( ${t}, ${r}, ${n}, ${i}, ${a} )`)}getUniforms(e){let t=this.uniforms[e],r=[],i={};for(let e of t){let t=null,s=!1;if("texture"===e.type||"texture3D"===e.type){let r=e.node,i=r.value,s=this.getComponentTypeFromTexture(i),n="float"===s?"":s.charAt(0);t="texture3D"===e.type&&!1===i.isArrayTexture?`${n}sampler3D ${e.name};`:i.compareFunction&&r.isSampleCompare()?!0===i.isArrayTexture?`sampler2DArrayShadow ${e.name};`:`sampler2DShadow ${e.name};`:!0===i.isArrayTexture||!0===i.isDataArrayTexture||!0===i.isCompressedArrayTexture?`${n}sampler2DArray ${e.name};`:`${n}sampler2D ${e.name};`}else if("cubeTexture"===e.type)t=`samplerCube ${e.name};`;else if("cubeDepthTexture"===e.type)t=e.node.value.compareFunction?`samplerCubeShadow ${e.name};`:`samplerCube ${e.name};`;else if("buffer"===e.type){let r=e.node,i=this.getType(r.bufferType),s=r.bufferCount,n=s>0?s:"";t=`${r.name} {
|
|
98
|
+
${i} ${e.name}[${n}];
|
|
99
|
+
};
|
|
100
|
+
`}else{let t=e.groupNode.name;if(void 0===i[t]){let e=this.uniformGroups[t];if(void 0!==e){let r=[];for(let t of e.uniforms){let e=t.getType(),i=this.getVectorType(e),s=t.nodeUniform.node.precision,n=`${i} ${t.name};`;null!==s&&(n=mx[s]+" "+n),r.push(" "+n)}i[t]=r}}s=!0}if(!s){let i=e.node.precision;null!==i&&(t=mx[i]+" "+t),t="uniform "+t,r.push(t)}}let s="";for(let e in i){let t=i[e];s+=this._getGLSLUniformStruct(e,t.join("\n"))+"\n"}return s+r.join("\n")}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==u.Yuy){let r=e;e.isInterleavedBufferAttribute&&(r=e.data);let i=r.array;!1==(i instanceof Uint32Array||i instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){let e=this.getAttributesArray(),r=0;for(let i of e)t+=`layout( location = ${r++} ) in ${i.type} ${i.name};
|
|
101
|
+
`}return t}getStructMembers(e){let t=[];for(let r of e.members)t.push(` ${r.type} ${r.name};`);return t.join("\n")}getStructs(e){let t=[],r=this.structs[e],i=[];for(let e of r)if(e.output)for(let t of e.members)i.push(`layout( location = ${t.index} ) out ${t.type} ${t.name};`);else{let r="struct "+e.name+" {\n";r+=this.getStructMembers(e),r+="\n};\n",t.push(r)}return"fragment"===e&&0===i.length&&i.push(`layout( location = 0 ) out ${this.getOutputType()} fragColor;`),"\n"+i.join("\n")+"\n\n"+t.join("\n")}getVaryings(e){let t="",r=this.varyings;if("vertex"===e||"compute"===e)for(let i of r){"compute"===e&&(i.needsInterpolation=!0);let r=this.getType(i.type);if(i.needsInterpolation)if(i.interpolationType){let e=m_[i.interpolationType]||i.interpolationType,s=mv[i.interpolationSampling]||"";t+=`${e} ${s} out ${r} ${i.name};
|
|
102
|
+
`}else{let e=r.includes("int")||r.includes("uv")||r.includes("iv")?"flat ":"";t+=`${e}out ${r} ${i.name};
|
|
103
|
+
`}else t+=`${r} ${i.name};
|
|
104
|
+
`}else if("fragment"===e){for(let e of r)if(e.needsInterpolation){let r=this.getType(e.type);if(e.interpolationType){let i=m_[e.interpolationType]||e.interpolationType,s=mv[e.interpolationSampling]||"";t+=`${i} ${s} in ${r} ${e.name};
|
|
105
|
+
`}else{let i=r.includes("int")||r.includes("uv")||r.includes("iv")?"flat ":"";t+=`${i}in ${r} ${e.name};
|
|
106
|
+
`}}}for(let r of this.builtins[e])t+=`${r};
|
|
107
|
+
`;return t}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){let e=this.compute.workgroupSize.reduce((e,t)=>e*t,1);return`uint( gl_InstanceID ) % ${e}u`}getSubgroupSize(){(0,u.z3S)("GLSLNodeBuilder: WebGLBackend does not support the subgroupSize node")}getInvocationSubgroupIndex(){(0,u.z3S)("GLSLNodeBuilder: WebGLBackend does not support the invocationSubgroupIndex node")}getSubgroupIndex(){(0,u.z3S)("GLSLNodeBuilder: WebGLBackend does not support the subgroupIndex node")}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":"nodeUniformDrawId"}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,r=this.shaderStage){let i=this.extensions[r]||(this.extensions[r]=new Map);!1===i.has(e)&&i.set(e,{name:e,behavior:t})}getExtensions(e){let t=[];if("vertex"===e){let t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}let r=this.extensions[e];if(void 0!==r)for(let{name:e,behavior:i}of r.values())t.push(`#extension ${e} : ${i}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=mT[e];if(void 0===t){let r;switch(t=!1,e){case"float32Filterable":r="OES_texture_float_linear";break;case"clipDistance":r="WEBGL_clip_cull_distance"}if(void 0!==r){let e=this.renderer.backend.extensions;e.has(r)&&(e.get(r),t=!0)}mT[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}enableMultiview(){this.enableExtension("GL_OVR_multiview2","require","fragment"),this.enableExtension("GL_OVR_multiview2","require","vertex"),this.builtins.vertex.push("layout(num_views = 2) in")}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){let e=this.transforms,t="";for(let r=0;r<e.length;r++){let i=e[r],s=this.getPropertyName(i.attributeNode);s&&(t+=`${i.varyingName} = ${s};
|
|
108
|
+
`)}return t}_getGLSLUniformStruct(e,t){return`
|
|
109
|
+
layout( std140 ) uniform ${e} {
|
|
110
|
+
${t}
|
|
111
|
+
};`}_getGLSLVertexCode(e){return`#version 300 es
|
|
112
|
+
|
|
113
|
+
${this.getSignature()}
|
|
114
|
+
|
|
115
|
+
// extensions
|
|
116
|
+
${e.extensions}
|
|
117
|
+
|
|
118
|
+
// precision
|
|
119
|
+
${mS}
|
|
120
|
+
|
|
121
|
+
// structs
|
|
122
|
+
${e.structs}
|
|
123
|
+
|
|
124
|
+
// uniforms
|
|
125
|
+
${e.uniforms}
|
|
126
|
+
|
|
127
|
+
// varyings
|
|
128
|
+
${e.varyings}
|
|
129
|
+
|
|
130
|
+
// attributes
|
|
131
|
+
${e.attributes}
|
|
132
|
+
|
|
133
|
+
// vars
|
|
134
|
+
${e.vars}
|
|
135
|
+
|
|
136
|
+
// codes
|
|
137
|
+
${e.codes}
|
|
138
|
+
|
|
139
|
+
void main() {
|
|
140
|
+
|
|
141
|
+
// transforms
|
|
142
|
+
${e.transforms}
|
|
143
|
+
|
|
144
|
+
// flow
|
|
145
|
+
${e.flow}
|
|
146
|
+
|
|
147
|
+
gl_PointSize = 1.0;
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
`}_getGLSLFragmentCode(e){return`#version 300 es
|
|
151
|
+
|
|
152
|
+
${this.getSignature()}
|
|
153
|
+
|
|
154
|
+
// extensions
|
|
155
|
+
${e.extensions}
|
|
156
|
+
|
|
157
|
+
// precision
|
|
158
|
+
${mS}
|
|
159
|
+
|
|
160
|
+
// structs
|
|
161
|
+
${e.structs}
|
|
162
|
+
|
|
163
|
+
// uniforms
|
|
164
|
+
${e.uniforms}
|
|
165
|
+
|
|
166
|
+
// varyings
|
|
167
|
+
${e.varyings}
|
|
168
|
+
|
|
169
|
+
// vars
|
|
170
|
+
${e.vars}
|
|
171
|
+
|
|
172
|
+
// codes
|
|
173
|
+
${e.codes}
|
|
174
|
+
|
|
175
|
+
void main() {
|
|
176
|
+
|
|
177
|
+
// flow
|
|
178
|
+
${e.flow}
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
`}buildCode(){let e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};for(let t in this.sortBindingGroups(),e){let r="// code\n\n";r+=this.flowCode[t];let i=this.flowNodes[t],s=i[i.length-1];for(let e of i){let i=this.getFlowData(e),n=e.name;n&&(r.length>0&&(r+="\n"),r+=` // flow -> ${n}
|
|
182
|
+
`),r+=`${i.code}
|
|
183
|
+
`,e===s&&"compute"!==t&&(r+="// result\n ","vertex"===t?(r+="gl_Position = ",r+=`${this.format(i.result,s.getNodeType(this),"vec4")};`):"fragment"!==t||e.outputNode.isOutputStructNode||(r+="fragColor = ",r+=`${this.format(i.result,s.getNodeType(this),this.getOutputType())};`))}let n=e[t];if(n.extensions=this.getExtensions(t),n.uniforms=this.getUniforms(t),n.attributes=this.getAttributes(t),n.varyings=this.getVaryings(t),n.vars=this.getVars(t,!0),n.structs=this.getStructs(t),n.codes=this.getCodes(t),n.transforms=this.getTransforms(t),n.flow=r,"vertex"===t){let e=this.renderer.backend.extensions;this.object.isBatchedMesh&&!1===e.has("WEBGL_multi_draw")&&(n.uniforms+="\nuniform uint nodeUniformDrawId;\n")}}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,r,i=null){let s=super.getUniformFromNode(e,t,r,i),n=this.getDataFromNode(e,r,this.globalCache),a=n.uniformGPU;if(void 0===a){let i=e.groupNode,o=i.name,l=this.getBindGroupArray(o,r);if("texture"===t)a=new mm(s.name,s.node,i),l.push(a);else if("cubeTexture"===t||"cubeDepthTexture"===t)a=new mg(s.name,s.node,i),l.push(a);else if("texture3D"===t)a=new mf(s.name,s.node,i),l.push(a);else if("buffer"===t){s.name=`buffer${e.id}`;let t=this.getSharedDataFromNode(e),r=t.buffer;void 0===r&&(e.name=`NodeBuffer_${e.id}`,(r=new mo(e,i)).name=e.name,t.buffer=r),l.push(r),a=r}else{let e=this.uniformGroups[o];void 0===e?(e=new md(o,i),this.uniformGroups[o]=e,l.push(e)):-1===l.indexOf(e)&&l.push(e);let r=(a=this.getNodeUniform(s,t)).name;e.uniforms.some(e=>e.name===r)||e.addUniform(a)}n.uniformGPU=a}return s}}let mA=null,mE=null;class mC{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null,this.timestampQueryPool={[u.v9J.RENDER]:null,[u.v9J.COMPUTE]:null},this.trackTimestamp=!0===e.trackTimestamp}async init(e){this.renderer=e}get coordinateSystem(){}beginRender(){}finishRender(){}setXRTarget(){}beginCompute(){}finishCompute(){}draw(){}compute(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}updateBinding(){}createRenderPipeline(){}createComputePipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}updateSampler(){}destroySampler(){}createDefaultTexture(){}createTexture(){}updateTexture(){}generateMipmaps(){}destroyTexture(){}async copyTextureToBuffer(){}copyTextureToTexture(){}copyFramebufferToTexture(){}createAttribute(){}createIndexAttribute(){}createStorageAttribute(){}createUniformBuffer(){}destroyUniformBuffer(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}updateViewport(){}updateTimeStampUID(e){let t,r=this.get(e),i=this.renderer.info.frame,s=e.id;Array.isArray(e)?(s=e.map(e=>e.id).join(","),t="c:"+this.renderer.info.compute.frameCalls):t=!0===e.isComputeNode?"c:"+this.renderer.info.compute.frameCalls:"r:"+this.renderer.info.render.frameCalls,r.timestampUID=t+":"+s+":f"+i}getTimestampUID(e){return this.get(e).timestampUID}getTimestampFrames(e){let t=this.timestampQueryPool[e];return t?t.getTimestampFrames():[]}_getQueryPool(e){let t=e.startsWith("c:")?u.v9J.COMPUTE:u.v9J.RENDER;return this.timestampQueryPool[t]}getTimestamp(e){return this._getQueryPool(e).getTimestamp(e)}get hasTimestamp(){return!1}hasTimestampQuery(e){return this._getQueryPool(e).hasTimestampQuery(e)}isOccluded(){}async resolveTimestampsAsync(e="render"){if(!this.trackTimestamp)return void(0,u.mcG)("WebGPURenderer: Timestamp tracking is disabled.");let t=this.timestampQueryPool[e];if(!t)return;let r=await t.resolveQueriesAsync();return this.renderer.info[e].timestamp=r,r}async getArrayBufferAsync(){}async hasFeatureAsync(){}hasFeature(){}getDrawingBufferSize(){return mA=mA||new u.I9Y,this.renderer.getDrawingBufferSize(mA)}setScissorTest(){}resetState(){}getClearColor(){let e=this.renderer;return mE=mE||new dd,e.getClearColor(mE),mE.getRGB(mE),mE}getDomElement(){let e=this.domElement;return null===e&&("setAttribute"in(e=void 0!==this.parameters.canvas?this.parameters.canvas:(0,u.lPF)())&&e.setAttribute("data-engine",`three.js r${u.sPf} webgpu`),this.domElement=e),e}hasCompatibility(){return!1}initRenderTarget(){}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}deleteBindGroupData(){}async dispose(){for(let e of Object.values(this.timestampQueryPool))null!==e&&await e.dispose()}}let mw=0;class mB{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class mM{constructor(e){this.backend=e}createAttribute(e,t){let r,i=this.backend,{gl:s}=i,n=e.array,a=e.usage||s.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,l=i.get(o),d=l.bufferGPU;if(void 0===d&&(l.bufferGPU=d=this._createBuffer(s,t,n,a),l.bufferType=t,l.version=o.version),n instanceof Float32Array)r=s.FLOAT;else if("undefined"!=typeof Float16Array&&n instanceof Float16Array)r=s.HALF_FLOAT;else if(n instanceof Uint16Array)r=e.isFloat16BufferAttribute?s.HALF_FLOAT:s.UNSIGNED_SHORT;else if(n instanceof Int16Array)r=s.SHORT;else if(n instanceof Uint32Array)r=s.UNSIGNED_INT;else if(n instanceof Int32Array)r=s.INT;else if(n instanceof Int8Array)r=s.BYTE;else if(n instanceof Uint8Array)r=s.UNSIGNED_BYTE;else if(n instanceof Uint8ClampedArray)r=s.UNSIGNED_BYTE;else throw Error("THREE.WebGLBackend: Unsupported buffer data format: "+n);let h={bufferGPU:d,bufferType:t,type:r,byteLength:n.byteLength,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:r===s.INT||r===s.UNSIGNED_INT||e.gpuType===u.Yuy,id:mw++};(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(h=new mB(h,this._createBuffer(s,t,n,a))),i.set(e,h)}updateAttribute(e){let t=this.backend,{gl:r}=t,i=e.array,s=e.isInterleavedBufferAttribute?e.data:e,n=t.get(s),a=n.bufferType,o=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(r.bindBuffer(a,n.bufferGPU),0===o.length)r.bufferSubData(a,0,i);else{for(let e=0,t=o.length;e<t;e++){let t=o[e];r.bufferSubData(a,t.start*i.BYTES_PER_ELEMENT,i,t.start,t.count)}s.clearUpdateRanges()}r.bindBuffer(a,null),n.version=s.version}destroyAttribute(e){let t=this.backend,{gl:r}=t;e.isInterleavedBufferAttribute&&t.delete(e.data);let i=t.get(e);r.deleteBuffer(i.bufferGPU),t.delete(e)}async getArrayBufferAsync(e,t=null,r=0,i=-1){let s,n=this.backend,{gl:a}=n,o=e.isInterleavedBufferAttribute?e.data:e,l=n.get(o),{bufferGPU:u}=l,d=-1===i?l.byteLength-r:i;if(null===t)s=new Uint8Array(new ArrayBuffer(d));else if(t.isReadbackBuffer){if(!0===t._mapped)throw Error("THREE.WebGPURenderer: ReadbackBuffer must be released before being used again.");let e=()=>{t.buffer=null,t._mapped=!1,t.removeEventListener("release",e),t.removeEventListener("dispose",e)};t.addEventListener("release",e),t.addEventListener("dispose",e),t.buffer=(s=new Uint8Array(new ArrayBuffer(d))).buffer}else s=new Uint8Array(t);return(a.bindBuffer(a.COPY_READ_BUFFER,u),a.getBufferSubData(a.COPY_READ_BUFFER,r,s),a.bindBuffer(a.COPY_READ_BUFFER,null),a.bindBuffer(a.COPY_WRITE_BUFFER,null),t&&t.isReadbackBuffer)?t:s.buffer}_createBuffer(e,t,r,i){let s=e.createBuffer();return e.bindBuffer(t,s),e.bufferData(t,r,i),e.bindBuffer(t,null),s}}class mF{constructor(e){this.backend=e,this.gl=this.backend.gl,this.enabled={},this.parameters={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendEquation=null,this.currentBlendEquationAlpha=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlendColor=new u.Q1f(0,0,0),this.currentBlendAlpha=0,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthReversed=!1,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentClippingPlanes=0,this.currentVAO=null,this.currentIndex=null,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},this._init()}_init(){let e=this.gl;o={[u.gO9]:e.FUNC_ADD,[u.FXf]:e.FUNC_SUBTRACT,[u.nST]:e.FUNC_REVERSE_SUBTRACT,[u.znC]:e.MIN,[u.$ei]:e.MAX},l={[u.ojh]:e.ZERO,[u.qad]:e.ONE,[u.f4X]:e.SRC_COLOR,[u.ie2]:e.SRC_ALPHA,[u.hgQ]:e.SRC_ALPHA_SATURATE,[u.wn6]:e.DST_COLOR,[u.hdd]:e.DST_ALPHA,[u.LiQ]:e.ONE_MINUS_SRC_COLOR,[u.OuU]:e.ONE_MINUS_SRC_ALPHA,[u.aEY]:e.ONE_MINUS_DST_COLOR,[u.Nt7]:e.ONE_MINUS_DST_ALPHA,[u.RrE]:e.CONSTANT_COLOR,[u.$Yl]:e.ONE_MINUS_CONSTANT_COLOR,[u.e0p]:e.CONSTANT_ALPHA,[u.ov9]:e.ONE_MINUS_CONSTANT_ALPHA};let t=e.getParameter(e.SCISSOR_BOX),r=e.getParameter(e.VIEWPORT);this.currentScissor=new u.IUQ().fromArray(t),this.currentViewport=new u.IUQ().fromArray(r),this._tempVec4=new u.IUQ}enable(e){let{enabled:t}=this;!0!==t[e]&&(this.gl.enable(e),t[e]=!0)}disable(e){let{enabled:t}=this;!1!==t[e]&&(this.gl.disable(e),t[e]=!1)}setFlipSided(e){if(this.currentFlipSided!==e){let{gl:t}=this;e?t.frontFace(t.CW):t.frontFace(t.CCW),this.currentFlipSided=e}}setCullFace(e){let{gl:t}=this;e!==u.WNZ?(this.enable(t.CULL_FACE),e!==this.currentCullFace&&(e===u.Vb5?t.cullFace(t.BACK):e===u.Jnc?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):this.disable(t.CULL_FACE),this.currentCullFace=e}setLineWidth(e){let{currentLineWidth:t,gl:r}=this;e!==t&&(r.lineWidth(e),this.currentLineWidth=e)}setMRTBlending(e,t,r){let i=this.gl,s=this.backend.drawBuffersIndexedExt;if(!s)return void(0,u.mcG)("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets.");for(let n=0;n<e.length;n++){let a=e[n],o=null;if(null!==t){let e=t.getBlendMode(a.name);e.blending===u.pCc?o=r:e.blending!==u.XIg&&(o=e)}else o=r;null!==o?this._setMRTBlendingIndex(n,o):s.blendFuncSeparateiOES(n,i.ONE,i.ZERO,i.ONE,i.ZERO)}}_setMRTBlendingIndex(e,t){let{gl:r}=this,i=this.backend.drawBuffersIndexedExt,s=t.blending,n=t.blendSrc,a=t.blendDst,d=t.blendEquation,h=t.premultipliedAlpha;if(s===u.bCz){let r=null!==t.blendSrcAlpha?t.blendSrcAlpha:n,s=null!==t.blendDstAlpha?t.blendDstAlpha:a,u=null!==t.blendEquationAlpha?t.blendEquationAlpha:d;i.blendEquationSeparateiOES(e,o[d],o[u]),i.blendFuncSeparateiOES(e,l[n],l[a],l[r],l[s])}else if(i.blendEquationSeparateiOES(e,r.FUNC_ADD,r.FUNC_ADD),h)switch(s){case u.NTi:i.blendFuncSeparateiOES(e,r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case u.EZo:i.blendFuncSeparateiOES(e,r.ONE,r.ONE,r.ONE,r.ONE);break;case u.Kwu:i.blendFuncSeparateiOES(e,r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case u.EdD:i.blendFuncSeparateiOES(e,r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:i.blendFuncSeparateiOES(e,r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)}else switch(s){case u.NTi:i.blendFuncSeparateiOES(e,r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case u.EZo:i.blendFuncSeparateiOES(e,r.SRC_ALPHA,r.ONE,r.ONE,r.ONE);break;case u.Kwu:i.blendFuncSeparateiOES(e,r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case u.EdD:i.blendFuncSeparateiOES(e,r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:i.blendFuncSeparateiOES(e,r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA)}}setBlending(e,t,r,i,s,n,a,d,h,c){let{gl:p}=this;if(e===u.XIg){!0===this.currentBlendingEnabled&&(this.disable(p.BLEND),this.currentBlendingEnabled=!1);return}if(!1===this.currentBlendingEnabled&&(this.enable(p.BLEND),this.currentBlendingEnabled=!0),e!==u.bCz){if(e!==this.currentBlending||c!==this.currentPremultipledAlpha){if((this.currentBlendEquation!==u.gO9||this.currentBlendEquationAlpha!==u.gO9)&&(p.blendEquation(p.FUNC_ADD),this.currentBlendEquation=u.gO9,this.currentBlendEquationAlpha=u.gO9),c)switch(e){case u.NTi:p.blendFuncSeparate(p.ONE,p.ONE_MINUS_SRC_ALPHA,p.ONE,p.ONE_MINUS_SRC_ALPHA);break;case u.EZo:p.blendFunc(p.ONE,p.ONE);break;case u.Kwu:p.blendFuncSeparate(p.ZERO,p.ONE_MINUS_SRC_COLOR,p.ZERO,p.ONE);break;case u.EdD:p.blendFuncSeparate(p.DST_COLOR,p.ONE_MINUS_SRC_ALPHA,p.ZERO,p.ONE);break;default:(0,u.z3S)("WebGLState: Invalid blending: ",e)}else switch(e){case u.NTi:p.blendFuncSeparate(p.SRC_ALPHA,p.ONE_MINUS_SRC_ALPHA,p.ONE,p.ONE_MINUS_SRC_ALPHA);break;case u.EZo:p.blendFuncSeparate(p.SRC_ALPHA,p.ONE,p.ONE,p.ONE);break;case u.Kwu:(0,u.z3S)("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case u.EdD:(0,u.z3S)("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:(0,u.z3S)("WebGLState: Invalid blending: ",e)}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=e,this.currentPremultipledAlpha=c}return}s=s||t,n=n||r,a=a||i,(t!==this.currentBlendEquation||s!==this.currentBlendEquationAlpha)&&(p.blendEquationSeparate(o[t],o[s]),this.currentBlendEquation=t,this.currentBlendEquationAlpha=s),(r!==this.currentBlendSrc||i!==this.currentBlendDst||n!==this.currentBlendSrcAlpha||a!==this.currentBlendDstAlpha)&&(p.blendFuncSeparate(l[r],l[i],l[n],l[a]),this.currentBlendSrc=r,this.currentBlendDst=i,this.currentBlendSrcAlpha=n,this.currentBlendDstAlpha=a),(!1===d.equals(this.currentBlendColor)||h!==this.currentBlendAlpha)&&(p.blendColor(d.r,d.g,d.b,h),this.currentBlendColor.copy(d),this.currentBlendAlpha=h),this.currentBlending=e,this.currentPremultipledAlpha=!1}setColorMask(e){this.currentColorMask!==e&&(this.gl.colorMask(e,e,e,e),this.currentColorMask=e)}setDepthTest(e){let{gl:t}=this;e?this.enable(t.DEPTH_TEST):this.disable(t.DEPTH_TEST)}setReversedDepth(e){if(this.currentDepthReversed!==e){let t=this.backend.extensions.get("EXT_clip_control");e?t.clipControlEXT(t.LOWER_LEFT_EXT,t.ZERO_TO_ONE_EXT):t.clipControlEXT(t.LOWER_LEFT_EXT,t.NEGATIVE_ONE_TO_ONE_EXT),this.currentDepthReversed=e}}setDepthMask(e){this.currentDepthMask!==e&&(this.gl.depthMask(e),this.currentDepthMask=e)}setDepthFunc(e){if(this.currentDepthReversed&&(e=u.ri6[e]),this.currentDepthFunc!==e){let{gl:t}=this;switch(e){case u.eHc:t.depthFunc(t.NEVER);break;case u.lGu:t.depthFunc(t.ALWAYS);break;case u.brA:t.depthFunc(t.LESS);break;case u.xSv:t.depthFunc(t.LEQUAL);break;case u.U3G:t.depthFunc(t.EQUAL);break;case u.Gwm:t.depthFunc(t.GEQUAL);break;case u.K52:t.depthFunc(t.GREATER);break;case u.bw0:t.depthFunc(t.NOTEQUAL);break;default:t.depthFunc(t.LEQUAL)}this.currentDepthFunc=e}}scissor(e,t,r,i){let s=this._tempVec4.set(e,t,r,i);if(!1===this.currentScissor.equals(s)){let{gl:e}=this;e.scissor(s.x,s.y,s.z,s.w),this.currentScissor.copy(s)}}viewport(e,t,r,i){let s=this._tempVec4.set(e,t,r,i);if(!1===this.currentViewport.equals(s)){let{gl:e}=this;e.viewport(s.x,s.y,s.z,s.w),this.currentViewport.copy(s)}}setScissorTest(e){let t=this.gl;e?this.enable(t.SCISSOR_TEST):this.disable(t.SCISSOR_TEST)}setStencilTest(e){let{gl:t}=this;e?this.enable(t.STENCIL_TEST):this.disable(t.STENCIL_TEST)}setStencilMask(e){this.currentStencilMask!==e&&(this.gl.stencilMask(e),this.currentStencilMask=e)}setStencilFunc(e,t,r){(this.currentStencilFunc!==e||this.currentStencilRef!==t||this.currentStencilFuncMask!==r)&&(this.gl.stencilFunc(e,t,r),this.currentStencilFunc=e,this.currentStencilRef=t,this.currentStencilFuncMask=r)}setStencilOp(e,t,r){(this.currentStencilFail!==e||this.currentStencilZFail!==t||this.currentStencilZPass!==r)&&(this.gl.stencilOp(e,t,r),this.currentStencilFail=e,this.currentStencilZFail=t,this.currentStencilZPass=r)}setMaterial(e,t,r){let{gl:i}=this;e.side===u.$EB?this.disable(i.CULL_FACE):this.enable(i.CULL_FACE);let s=e.side===u.hsX;t&&(s=!s),this.setFlipSided(s),e.blending===u.NTi&&!1===e.transparent?this.setBlending(u.XIg):this.setBlending(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.blendColor,e.blendAlpha,e.premultipliedAlpha),this.setDepthFunc(e.depthFunc),this.setDepthTest(e.depthTest),this.setDepthMask(e.depthWrite),this.setColorMask(e.colorWrite);let n=e.stencilWrite;if(this.setStencilTest(n),n&&(this.setStencilMask(e.stencilWriteMask),this.setStencilFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),this.setStencilOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),this.setPolygonOffset(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage&&this.backend.renderer.currentSamples>0?this.enable(i.SAMPLE_ALPHA_TO_COVERAGE):this.disable(i.SAMPLE_ALPHA_TO_COVERAGE),this.currentClippingPlanes!==r){for(let e=0;e<8;e++)e<r?this.enable(12288+e):this.disable(12288+e);this.currentClippingPlanes=r}}setPolygonOffset(e,t,r){let{gl:i}=this;e?(this.enable(i.POLYGON_OFFSET_FILL),(this.currentPolygonOffsetFactor!==t||this.currentPolygonOffsetUnits!==r)&&(i.polygonOffset(t,r),this.currentPolygonOffsetFactor=t,this.currentPolygonOffsetUnits=r)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(e){return this.currentProgram!==e&&(this.gl.useProgram(e),this.currentProgram=e,!0)}setVertexState(e,t=null){let r=this.gl;return(this.currentVAO!==e||this.currentIndex!==t)&&(r.bindVertexArray(e),null!==t&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t),this.currentVAO=e,this.currentIndex=t,!0)}resetVertexState(){let e=this.gl;e.bindVertexArray(null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),this.currentVAO=null,this.currentIndex=null}bindFramebuffer(e,t){let{gl:r,currentBoundFramebuffers:i}=this;return i[e]!==t&&(r.bindFramebuffer(e,t),i[e]=t,e===r.DRAW_FRAMEBUFFER&&(i[r.FRAMEBUFFER]=t),e===r.FRAMEBUFFER&&(i[r.DRAW_FRAMEBUFFER]=t),!0)}drawBuffers(e,t){let{gl:r}=this,i=[],s=!1;if(null!==e.textures){void 0===(i=this.currentDrawbuffers.get(t))&&(i=[],this.currentDrawbuffers.set(t,i));let n=e.textures;if(i.length!==n.length||i[0]!==r.COLOR_ATTACHMENT0){for(let e=0,t=n.length;e<t;e++)i[e]=r.COLOR_ATTACHMENT0+e;i.length=n.length,s=!0}}else i[0]!==r.BACK&&(i[0]=r.BACK,s=!0);s&&r.drawBuffers(i)}activeTexture(e){let{gl:t,currentTextureSlot:r,maxTextures:i}=this;void 0===e&&(e=t.TEXTURE0+i-1),r!==e&&(t.activeTexture(e),this.currentTextureSlot=e)}bindTexture(e,t,r){let{gl:i,currentTextureSlot:s,currentBoundTextures:n,maxTextures:a}=this;void 0===r&&(r=null===s?i.TEXTURE0+a-1:s);let o=n[r];void 0===o&&(o={type:void 0,texture:void 0},n[r]=o),(o.type!==e||o.texture!==t)&&(s!==r&&(i.activeTexture(r),this.currentTextureSlot=r),i.bindTexture(e,t),o.type=e,o.texture=t)}bindBufferBase(e,t,r){let{gl:i}=this,s=`${e}-${t}`;return this.currentBoundBufferBases[s]!==r&&(i.bindBufferBase(e,t,r),this.currentBoundBufferBases[s]=r,!0)}unbindTexture(){let{gl:e,currentTextureSlot:t,currentBoundTextures:r}=this,i=r[t];void 0!==i&&void 0!==i.type&&(e.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}getParameter(e){let{gl:t,parameters:r}=this;return void 0!==r[e]?r[e]:t.getParameter(e)}pixelStorei(e,t){let{gl:r,parameters:i}=this;i[e]!==t&&(r.pixelStorei(e,t),i[e]=t)}reset(){let{gl:e}=this;e.disable(e.BLEND),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.POLYGON_OFFSET_FILL),e.disable(e.SCISSOR_TEST),e.disable(e.STENCIL_TEST),e.disable(e.SAMPLE_ALPHA_TO_COVERAGE),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO),e.blendFuncSeparate(e.ONE,e.ZERO,e.ONE,e.ZERO),e.blendColor(0,0,0,0),e.colorMask(!0,!0,!0,!0),e.clearColor(0,0,0,0),e.depthMask(!0),e.depthFunc(e.LESS),e.clearDepth(1),e.stencilMask(0xffffffff),e.stencilFunc(e.ALWAYS,0,0xffffffff),e.stencilOp(e.KEEP,e.KEEP,e.KEEP),e.clearStencil(0),e.cullFace(e.BACK),e.frontFace(e.CCW),e.polygonOffset(0,0),e.activeTexture(e.TEXTURE0),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.useProgram(null),e.lineWidth(1),e.scissor(0,0,e.canvas.width,e.canvas.height),e.viewport(0,0,e.canvas.width,e.canvas.height),e.pixelStorei(e.PACK_ALIGNMENT,4),e.pixelStorei(e.UNPACK_ALIGNMENT,4),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.BROWSER_DEFAULT_WEBGL),e.pixelStorei(e.PACK_ROW_LENGTH,0),e.pixelStorei(e.PACK_SKIP_PIXELS,0),e.pixelStorei(e.PACK_SKIP_ROWS,0),e.pixelStorei(e.UNPACK_ROW_LENGTH,0),e.pixelStorei(e.UNPACK_IMAGE_HEIGHT,0),e.pixelStorei(e.UNPACK_SKIP_PIXELS,0),e.pixelStorei(e.UNPACK_SKIP_ROWS,0),e.pixelStorei(e.UNPACK_SKIP_IMAGES,0),this.resetVertexState(),this.enabled={},this.parameters={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendEquation=null,this.currentBlendEquationAlpha=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlendColor.set(0,0,0),this.currentBlendAlpha=0,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentClippingPlanes=0,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.currentTextureSlot=null,this.currentBoundTextures={},this.currentBoundBufferBases={},this.currentScissor.set(0,0,e.canvas.width,e.canvas.height),this.currentViewport.set(0,0,e.canvas.width,e.canvas.height),this.currentDepthReversed=!1,!0===this.backend.renderer.reversedDepthBuffer&&this.setReversedDepth(!0)}}class mL{constructor(e){this.backend=e,this.gl=this.backend.gl,this.extensions=e.extensions}convert(e,t=u.jf0){let r,{gl:i,extensions:s}=this,n=u.ppV.getTransfer(t);if(e===u.OUM)return i.UNSIGNED_BYTE;if(e===u.Wew)return i.UNSIGNED_SHORT_4_4_4_4;if(e===u.gJ2)return i.UNSIGNED_SHORT_5_5_5_1;if(e===u.Dmk)return i.UNSIGNED_INT_5_9_9_9_REV;if(e===u.yT7)return i.UNSIGNED_INT_10F_11F_11F_REV;if(e===u.tJf)return i.BYTE;if(e===u.fBL)return i.SHORT;if(e===u.cHt)return i.UNSIGNED_SHORT;if(e===u.Yuy)return i.INT;if(e===u.bkx)return i.UNSIGNED_INT;if(e===u.RQf)return i.FLOAT;if(e===u.ix0)return i.HALF_FLOAT;if(e===u.wrO)return i.ALPHA;if(e===u.HIg)return i.RGB;if(e===u.GWd)return i.RGBA;if(e===u.zdS)return i.DEPTH_COMPONENT;if(e===u.dcC)return i.DEPTH_STENCIL;if(e===u.VT0)return i.RED;if(e===u.ZQM)return i.RED_INTEGER;if(e===u.paN)return i.RG;if(e===u.TkQ)return i.RG_INTEGER;if(e===u.c90)return i.RGBA_INTEGER;if(e===u.IE4||e===u.Nz6||e===u.jR7||e===u.BXX)if(n===u.KLL){if(null===(r=s.get("WEBGL_compressed_texture_s3tc_srgb")))return null;if(e===u.IE4)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(e===u.Nz6)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(e===u.jR7)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(e===u.BXX)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(null===(r=s.get("WEBGL_compressed_texture_s3tc")))return null;if(e===u.IE4)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===u.Nz6)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===u.jR7)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===u.BXX)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(e===u.k6Q||e===u.kTp||e===u.HXV||e===u.pBf){if(null===(r=s.get("WEBGL_compressed_texture_pvrtc")))return null;if(e===u.k6Q)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===u.kTp)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===u.HXV)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===u.pBf)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(e===u.CVz||e===u.Riy||e===u.KDk||e===u.BVL||e===u.gZr||e===u.OtU||e===u.jSS){if(null===(r=s.get("WEBGL_compressed_texture_etc")))return null;if(e===u.CVz||e===u.Riy)return n===u.KLL?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(e===u.KDk)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC;if(e===u.BVL)return r.COMPRESSED_R11_EAC;if(e===u.gZr)return r.COMPRESSED_SIGNED_R11_EAC;if(e===u.OtU)return r.COMPRESSED_RG11_EAC;if(e===u.jSS)return r.COMPRESSED_SIGNED_RG11_EAC}if(e===u.qa3||e===u.B_h||e===u.czI||e===u.rSH||e===u.Qrf||e===u.psI||e===u.a5J||e===u._QJ||e===u.uB5||e===u.lyL||e===u.bC7||e===u.y3Z||e===u.ojs||e===u.S$4){if(null===(r=s.get("WEBGL_compressed_texture_astc")))return null;if(e===u.qa3)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(e===u.B_h)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(e===u.czI)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(e===u.rSH)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(e===u.Qrf)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(e===u.psI)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(e===u.a5J)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(e===u._QJ)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(e===u.uB5)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(e===u.lyL)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(e===u.bC7)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(e===u.y3Z)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(e===u.ojs)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(e===u.S$4)return n===u.KLL?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}if(e===u.Fn||e===u.H23||e===u.W9U){if(null===(r=s.get("EXT_texture_compression_bptc")))return null;if(e===u.Fn)return n===u.KLL?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(e===u.H23)return r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(e===u.W9U)return r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}if(e===u.Kef||e===u.XG_||e===u.HO_||e===u.CWW){if(null===(r=s.get("EXT_texture_compression_rgtc")))return null;if(e===u.Kef)return r.COMPRESSED_RED_RGTC1_EXT;if(e===u.XG_)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(e===u.HO_)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(e===u.CWW)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return e===u.V3x?i.UNSIGNED_INT_24_8:void 0!==i[e]?i[e]:null}_clientWaitAsync(){let{gl:e}=this,t=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),new Promise((r,i)=>{!function s(){let n=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(n===e.WAIT_FAILED){e.deleteSync(t),i();return}if(n===e.TIMEOUT_EXPIRED)return void requestAnimationFrame(s);e.deleteSync(t),r()}()})}}let mU=!1,mP,mD,mO;class mI{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},this._srcFramebuffer=null,this._dstFramebuffer=null,!1===mU&&(this._init(),mU=!0)}_init(){let e=this.gl;mP={[u.GJx]:e.REPEAT,[u.ghU]:e.CLAMP_TO_EDGE,[u.kTW]:e.MIRRORED_REPEAT},mD={[u.hxR]:e.NEAREST,[u.pHI]:e.NEAREST_MIPMAP_NEAREST,[u.Cfg]:e.NEAREST_MIPMAP_LINEAR,[u.k6q]:e.LINEAR,[u.kRr]:e.LINEAR_MIPMAP_NEAREST,[u.$_I]:e.LINEAR_MIPMAP_LINEAR},mO={[u.amv]:e.NEVER,[u.FFZ]:e.ALWAYS,[u.vim]:e.LESS,[u.TiK]:e.LEQUAL,[u.kO0]:e.EQUAL,[u.gWB]:e.GEQUAL,[u.eoi]:e.GREATER,[u.jzd]:e.NOTEQUAL}}getGLTextureType(e){let{gl:t}=this;return!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isArrayTexture||!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D}getInternalFormat(e,t,r,i,s,n=!1){let{gl:a,extensions:o}=this;if(null!==e){if(void 0!==a[e])return a[e];(0,u.R8M)("WebGLBackend: Attempt to use non-existing WebGL internal format '"+e+"'")}let l=null;i&&((l=o.get("EXT_texture_norm16"))||(0,u.R8M)("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let d=t;if(t===a.RED&&(r===a.FLOAT&&(d=a.R32F),r===a.HALF_FLOAT&&(d=a.R16F),r===a.UNSIGNED_BYTE&&(d=a.R8),r===a.BYTE&&(d=a.R8_SNORM),r===a.UNSIGNED_SHORT&&l&&(d=l.R16_EXT),r===a.SHORT&&l&&(d=l.R16_SNORM_EXT)),t===a.RED_INTEGER&&(r===a.UNSIGNED_BYTE&&(d=a.R8UI),r===a.UNSIGNED_SHORT&&(d=a.R16UI),r===a.UNSIGNED_INT&&(d=a.R32UI),r===a.BYTE&&(d=a.R8I),r===a.SHORT&&(d=a.R16I),r===a.INT&&(d=a.R32I)),t===a.RG&&(r===a.FLOAT&&(d=a.RG32F),r===a.HALF_FLOAT&&(d=a.RG16F),r===a.UNSIGNED_BYTE&&(d=a.RG8),r===a.BYTE&&(d=a.RG8_SNORM),r===a.UNSIGNED_SHORT&&l&&(d=l.RG16_EXT),r===a.SHORT&&l&&(d=l.RG16_SNORM_EXT)),t===a.RG_INTEGER&&(r===a.UNSIGNED_BYTE&&(d=a.RG8UI),r===a.UNSIGNED_SHORT&&(d=a.RG16UI),r===a.UNSIGNED_INT&&(d=a.RG32UI),r===a.BYTE&&(d=a.RG8I),r===a.SHORT&&(d=a.RG16I),r===a.INT&&(d=a.RG32I)),t===a.RGB){let e=n?u.VxR:u.ppV.getTransfer(s);r===a.FLOAT&&(d=a.RGB32F),r===a.HALF_FLOAT&&(d=a.RGB16F),r===a.UNSIGNED_BYTE&&(d=e===u.KLL?a.SRGB8:a.RGB8),r===a.BYTE&&(d=a.RGB8_SNORM),r===a.UNSIGNED_SHORT&&l&&(d=l.RGB16_EXT),r===a.SHORT&&l&&(d=l.RGB16_SNORM_EXT),r===a.UNSIGNED_SHORT_5_6_5&&(d=a.RGB565),r===a.UNSIGNED_SHORT_5_5_5_1&&(d=a.RGB5_A1),r===a.UNSIGNED_SHORT_4_4_4_4&&(d=a.RGB4),r===a.UNSIGNED_INT_5_9_9_9_REV&&(d=a.RGB9_E5),r===a.UNSIGNED_INT_10F_11F_11F_REV&&(d=a.R11F_G11F_B10F)}if(t===a.RGB_INTEGER&&(r===a.UNSIGNED_BYTE&&(d=a.RGB8UI),r===a.UNSIGNED_SHORT&&(d=a.RGB16UI),r===a.UNSIGNED_INT&&(d=a.RGB32UI),r===a.BYTE&&(d=a.RGB8I),r===a.SHORT&&(d=a.RGB16I),r===a.INT&&(d=a.RGB32I)),t===a.RGBA){let e=n?u.VxR:u.ppV.getTransfer(s);r===a.FLOAT&&(d=a.RGBA32F),r===a.HALF_FLOAT&&(d=a.RGBA16F),r===a.UNSIGNED_BYTE&&(d=e===u.KLL?a.SRGB8_ALPHA8:a.RGBA8),r===a.BYTE&&(d=a.RGBA8_SNORM),r===a.UNSIGNED_SHORT&&l&&(d=l.RGBA16_EXT),r===a.SHORT&&l&&(d=l.RGBA16_SNORM_EXT),r===a.UNSIGNED_SHORT_4_4_4_4&&(d=a.RGBA4),r===a.UNSIGNED_SHORT_5_5_5_1&&(d=a.RGB5_A1)}return t===a.RGBA_INTEGER&&(r===a.UNSIGNED_BYTE&&(d=a.RGBA8UI),r===a.UNSIGNED_SHORT&&(d=a.RGBA16UI),r===a.UNSIGNED_INT&&(d=a.RGBA32UI),r===a.BYTE&&(d=a.RGBA8I),r===a.SHORT&&(d=a.RGBA16I),r===a.INT&&(d=a.RGBA32I)),t===a.DEPTH_COMPONENT&&(r===a.UNSIGNED_SHORT&&(d=a.DEPTH_COMPONENT16),r===a.UNSIGNED_INT&&(d=a.DEPTH_COMPONENT24),r===a.FLOAT&&(d=a.DEPTH_COMPONENT32F)),t===a.DEPTH_STENCIL&&r===a.UNSIGNED_INT_24_8&&(d=a.DEPTH24_STENCIL8),(d===a.R16F||d===a.R32F||d===a.RG16F||d===a.RG32F||d===a.RGBA16F||d===a.RGBA32F)&&o.get("EXT_color_buffer_float"),d}setTextureParameters(e,t){let{gl:r,extensions:i,backend:s}=this,{state:n}=this.backend,a=u.ppV.getPrimaries(u.ppV.workingColorSpace),o=t.colorSpace===u.jf0?null:u.ppV.getPrimaries(t.colorSpace),l=t.colorSpace===u.jf0||a===o?r.NONE:r.BROWSER_DEFAULT_WEBGL;n.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,t.flipY),n.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),n.pixelStorei(r.UNPACK_ALIGNMENT,t.unpackAlignment),n.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,l),r.texParameteri(e,r.TEXTURE_WRAP_S,mP[t.wrapS]),r.texParameteri(e,r.TEXTURE_WRAP_T,mP[t.wrapT]),e!==r.TEXTURE_3D&&e!==r.TEXTURE_2D_ARRAY||t.isArrayTexture||r.texParameteri(e,r.TEXTURE_WRAP_R,mP[t.wrapR]),r.texParameteri(e,r.TEXTURE_MAG_FILTER,mD[t.magFilter]);let d=void 0!==t.mipmaps&&t.mipmaps.length>0,h=t.minFilter===u.k6q&&d?u.$_I:t.minFilter;if(r.texParameteri(e,r.TEXTURE_MIN_FILTER,mD[h]),t.compareFunction&&(r.texParameteri(e,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(e,r.TEXTURE_COMPARE_FUNC,mO[t.compareFunction])),!0===i.has("EXT_texture_filter_anisotropic")){if(t.magFilter===u.hxR||t.minFilter!==u.Cfg&&t.minFilter!==u.$_I||t.type===u.RQf&&!1===i.has("OES_texture_float_linear"))return;if(t.anisotropy>1){let n=i.get("EXT_texture_filter_anisotropic");r.texParameterf(e,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,s.capabilities.getMaxAnisotropy()))}}}createDefaultTexture(e){let{gl:t,backend:r,defaultTextures:i}=this,s=this.getGLTextureType(e),n=i[s];void 0===n&&(n=t.createTexture(),r.state.bindTexture(s,n),t.texParameteri(s,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(s,t.TEXTURE_MAG_FILTER,t.NEAREST),i[s]=n),r.set(e,{textureGPU:n,glTextureType:s})}createTexture(e,t){let r,i,s,n,a,{gl:o,backend:l}=this;if(!0===e.isExternalTexture)r=e.sourceTexture,i=this.getGLTextureType(e);else{let{levels:u,width:d,height:h,depth:c}=t;s=l.utils.convert(e.format,e.colorSpace),n=l.utils.convert(e.type),a=this.getInternalFormat(e.internalFormat,s,n,e.normalized,e.colorSpace,e.isVideoTexture),r=o.createTexture(),i=this.getGLTextureType(e),l.state.bindTexture(i,r),this.setTextureParameters(i,e),e.isArrayTexture||e.isDataArrayTexture||e.isCompressedArrayTexture?o.texStorage3D(o.TEXTURE_2D_ARRAY,u,a,d,h,c):e.isData3DTexture?o.texStorage3D(o.TEXTURE_3D,u,a,d,h,c):e.isVideoTexture||o.texStorage2D(i,u,a,d,h)}l.set(e,{textureGPU:r,glTextureType:i,glFormat:s,glType:n,glInternalFormat:a})}copyBufferToTexture(e,t){let{gl:r,backend:i}=this,{state:s}=i,{textureGPU:n,glTextureType:a,glFormat:o,glType:l}=i.get(t),{width:u,height:d}=t.source.data;r.bindBuffer(r.PIXEL_UNPACK_BUFFER,e),i.state.bindTexture(a,n),s.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.texSubImage2D(a,0,0,0,u,d,o,l,0),r.bindBuffer(r.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(e,t){let{gl:r}=this,{width:i,height:s}=t,{textureGPU:n,glTextureType:a,glFormat:o,glType:l,glInternalFormat:d}=this.backend.get(e);if(!e.isRenderTargetTexture&&void 0!==n)if(this.backend.state.bindTexture(a,n),this.setTextureParameters(a,e),e.isCompressedTexture){let i=e.mipmaps,s=t.image;for(let t=0;t<i.length;t++){let n=i[t];if(e.isCompressedArrayTexture)if(e.format!==r.RGBA)if(null!==o)if(e.layerUpdates.size>0){let i=(0,u.Nex)(n.width,n.height,e.format,e.type);for(let s of e.layerUpdates){let e=n.data.subarray(s*i/n.data.BYTES_PER_ELEMENT,(s+1)*i/n.data.BYTES_PER_ELEMENT);r.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,t,0,0,s,n.width,n.height,1,o,e)}}else r.compressedTexSubImage3D(r.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,s.depth,o,n.data);else(0,u.R8M)("WebGLBackend: Attempt to load unsupported compressed texture format in .uploadTexture()");else r.texSubImage3D(r.TEXTURE_2D_ARRAY,t,0,0,0,n.width,n.height,s.depth,o,l,n.data);else null!==o?r.compressedTexSubImage2D(r.TEXTURE_2D,t,0,0,n.width,n.height,o,n.data):(0,u.R8M)("WebGLBackend: Unsupported compressed texture format")}e.isCompressedArrayTexture&&e.layerUpdates.size>0&&e.clearLayerUpdates()}else if(e.isCubeTexture){let n=t.images,a=e.mipmaps;for(let e=0;e<6;e++){let t=mV(n[e]);r.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,i,s,o,l,t);for(let t=0;t<a.length;t++){let i=mV(a[t].images[e]);r.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+e,t+1,0,0,i.width,i.height,o,l,i)}}}else if(e.isDataArrayTexture||e.isArrayTexture){let i=t.image;if(e.layerUpdates.size>0){let t=(0,u.Nex)(i.width,i.height,e.format,e.type);for(let s of e.layerUpdates){let e=i.data.subarray(s*t/i.data.BYTES_PER_ELEMENT,(s+1)*t/i.data.BYTES_PER_ELEMENT);r.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,s,i.width,i.height,1,o,l,e)}e.clearLayerUpdates()}else r.texSubImage3D(r.TEXTURE_2D_ARRAY,0,0,0,0,i.width,i.height,i.depth,o,l,i.data)}else if(e.isData3DTexture){let e=t.image;r.texSubImage3D(r.TEXTURE_3D,0,0,0,0,e.width,e.height,e.depth,o,l,e.data)}else if(e.isVideoTexture)e.update(),r.texImage2D(a,0,d,o,l,t.image);else if(e.isHTMLTexture)"function"==typeof r.texElementImage2D&&(3===r.texElementImage2D.length?r.texElementImage2D(r.TEXTURE_2D,r.RGBA8,t.image):r.texElementImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t.image));else{let n=e.mipmaps;if(n.length>0)for(let e=0,t=n.length;e<t;e++){let t=n[e],i=mV(t);r.texSubImage2D(a,e,0,0,t.width,t.height,o,l,i)}else{let e=mV(t.image);r.texSubImage2D(a,0,0,0,i,s,o,l,e)}}}generateMipmaps(e){let{gl:t,backend:r}=this,{textureGPU:i,glTextureType:s}=r.get(e);r.state.bindTexture(s,i),t.generateMipmap(s)}deallocateRenderBuffers(e){let{gl:t,backend:r}=this;if(e){let i=r.get(e);if(i.renderBufferStorageSetup=void 0,i.framebuffers){for(let e in i.framebuffers)t.deleteFramebuffer(i.framebuffers[e]);delete i.framebuffers}if(i.depthRenderbuffer&&(t.deleteRenderbuffer(i.depthRenderbuffer),delete i.depthRenderbuffer),i.stencilRenderbuffer&&(t.deleteRenderbuffer(i.stencilRenderbuffer),delete i.stencilRenderbuffer),i.msaaFrameBuffer&&(t.deleteFramebuffer(i.msaaFrameBuffer),delete i.msaaFrameBuffer),i.msaaRenderbuffers){for(let e=0;e<i.msaaRenderbuffers.length;e++)t.deleteRenderbuffer(i.msaaRenderbuffers[e]);delete i.msaaRenderbuffers}}}destroyTexture(e,t=!1){let{gl:r,backend:i}=this,{textureGPU:s,renderTarget:n}=i.get(e);this.deallocateRenderBuffers(n),!1===t&&!0!==e.isExternalTexture&&r.deleteTexture(s),i.delete(e)}copyTextureToTexture(e,t,r=null,i=null,s=0,n=0){let a,o,l,u,d,h,c,p,m,{gl:g,backend:f}=this,{state:b}=this.backend,{textureGPU:y,glTextureType:x,glType:T,glFormat:_}=f.get(t);b.bindTexture(x,y);let v=e.isCompressedTexture?e.mipmaps[n]:e.image;if(null!==r)a=r.max.x-r.min.x,o=r.max.y-r.min.y,l=r.isBox3?r.max.z-r.min.z:1,u=r.min.x,d=r.min.y,h=r.isBox3?r.min.z:0;else{let t=Math.pow(2,-s);a=Math.floor(v.width*t),o=Math.floor(v.height*t),l=e.isDataArrayTexture||e.isArrayTexture?v.depth:e.isData3DTexture?Math.floor(v.depth*t):1,u=0,d=0,h=0}null!==i?(c=i.x,p=i.y,m=i.z):(c=0,p=0,m=0),b.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,t.flipY),b.pixelStorei(g.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),b.pixelStorei(g.UNPACK_ALIGNMENT,t.unpackAlignment);let S=b.getParameter(g.UNPACK_ROW_LENGTH),R=b.getParameter(g.UNPACK_IMAGE_HEIGHT),N=b.getParameter(g.UNPACK_SKIP_PIXELS),A=b.getParameter(g.UNPACK_SKIP_ROWS),E=b.getParameter(g.UNPACK_SKIP_IMAGES);b.pixelStorei(g.UNPACK_ROW_LENGTH,v.width),b.pixelStorei(g.UNPACK_IMAGE_HEIGHT,v.height),b.pixelStorei(g.UNPACK_SKIP_PIXELS,u),b.pixelStorei(g.UNPACK_SKIP_ROWS,d),b.pixelStorei(g.UNPACK_SKIP_IMAGES,h);let C=e.isDataArrayTexture||e.isData3DTexture||t.isArrayTexture,w=t.isDataArrayTexture||t.isData3DTexture||t.isArrayTexture;if(e.isDepthTexture){let r=f.get(e),i=f.get(t),x=f.get(r.renderTarget),T=f.get(i.renderTarget),_=x.framebuffers[r.cacheKey],v=T.framebuffers[i.cacheKey],S=b.currentBoundFramebuffers[g.READ_FRAMEBUFFER]??null,R=b.currentBoundFramebuffers[g.DRAW_FRAMEBUFFER]??null;b.bindFramebuffer(g.READ_FRAMEBUFFER,_),b.bindFramebuffer(g.DRAW_FRAMEBUFFER,v);for(let e=0;e<l;e++)C&&(g.framebufferTextureLayer(g.READ_FRAMEBUFFER,g.COLOR_ATTACHMENT0,r.textureGPU,s,h+e),g.framebufferTextureLayer(g.DRAW_FRAMEBUFFER,g.COLOR_ATTACHMENT0,y,n,m+e)),g.blitFramebuffer(u,d,a,o,c,p,a,o,g.DEPTH_BUFFER_BIT,g.NEAREST);b.bindFramebuffer(g.READ_FRAMEBUFFER,S),b.bindFramebuffer(g.DRAW_FRAMEBUFFER,R)}else if(0!==s||e.isRenderTargetTexture||f.has(e)){let t=f.get(e);null===this._srcFramebuffer&&(this._srcFramebuffer=g.createFramebuffer()),null===this._dstFramebuffer&&(this._dstFramebuffer=g.createFramebuffer());let r=b.currentBoundFramebuffers[g.READ_FRAMEBUFFER]??null,i=b.currentBoundFramebuffers[g.DRAW_FRAMEBUFFER]??null;b.bindFramebuffer(g.READ_FRAMEBUFFER,this._srcFramebuffer),b.bindFramebuffer(g.DRAW_FRAMEBUFFER,this._dstFramebuffer);for(let e=0;e<l;e++)C?g.framebufferTextureLayer(g.READ_FRAMEBUFFER,g.COLOR_ATTACHMENT0,t.textureGPU,s,h+e):g.framebufferTexture2D(g.READ_FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,t.textureGPU,s),w?g.framebufferTextureLayer(g.DRAW_FRAMEBUFFER,g.COLOR_ATTACHMENT0,y,n,m+e):g.framebufferTexture2D(g.DRAW_FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,y,n),0!==s?g.blitFramebuffer(u,d,a,o,c,p,a,o,g.COLOR_BUFFER_BIT,g.NEAREST):w?g.copyTexSubImage3D(x,n,c,p,m+e,u,d,a,o):g.copyTexSubImage2D(x,n,c,p,u,d,a,o);b.bindFramebuffer(g.READ_FRAMEBUFFER,r),b.bindFramebuffer(g.DRAW_FRAMEBUFFER,i)}else w?e.isDataTexture||e.isData3DTexture?g.texSubImage3D(x,n,c,p,m,a,o,l,_,T,v.data):t.isCompressedArrayTexture?g.compressedTexSubImage3D(x,n,c,p,m,a,o,l,_,v.data):g.texSubImage3D(x,n,c,p,m,a,o,l,_,T,v):e.isDataTexture?g.texSubImage2D(g.TEXTURE_2D,n,c,p,a,o,_,T,v.data):e.isCompressedTexture?g.compressedTexSubImage2D(g.TEXTURE_2D,n,c,p,v.width,v.height,_,v.data):g.texSubImage2D(g.TEXTURE_2D,n,c,p,a,o,_,T,v);b.pixelStorei(g.UNPACK_ROW_LENGTH,S),b.pixelStorei(g.UNPACK_IMAGE_HEIGHT,R),b.pixelStorei(g.UNPACK_SKIP_PIXELS,N),b.pixelStorei(g.UNPACK_SKIP_ROWS,A),b.pixelStorei(g.UNPACK_SKIP_IMAGES,E),0===n&&t.generateMipmaps&&g.generateMipmap(x),b.unbindTexture()}copyFramebufferToTexture(e,t,r){let{gl:i}=this,{state:s}=this.backend,{textureGPU:n}=this.backend.get(e),{x:a,y:o,z:l,w:u}=r,d=!0===e.isDepthTexture||t.renderTarget&&t.renderTarget.samples>0,h=t.renderTarget?t.renderTarget.height:this.backend.getDrawingBufferSize().y;if(d){let r,d,c=0!==a||0!==o;if(!0===e.isDepthTexture?(r=i.DEPTH_BUFFER_BIT,d=i.DEPTH_ATTACHMENT,t.stencil&&(r|=i.STENCIL_BUFFER_BIT)):(r=i.COLOR_BUFFER_BIT,d=i.COLOR_ATTACHMENT0),c){let e=this.backend.get(t.renderTarget),d=e.framebuffers[t.getCacheKey()],c=e.msaaFrameBuffer;s.bindFramebuffer(i.DRAW_FRAMEBUFFER,d),s.bindFramebuffer(i.READ_FRAMEBUFFER,c);let p=h-o-u;i.blitFramebuffer(a,p,a+l,p+u,a,p,a+l,p+u,r,i.NEAREST),s.bindFramebuffer(i.READ_FRAMEBUFFER,d),s.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,p,l,u),s.unbindTexture()}else{let e=i.createFramebuffer();s.bindFramebuffer(i.DRAW_FRAMEBUFFER,e),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,d,i.TEXTURE_2D,n,0),i.blitFramebuffer(0,0,l,u,0,0,l,u,r,i.NEAREST),i.deleteFramebuffer(e)}}else s.bindTexture(i.TEXTURE_2D,n),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,h-u-o,l,u),s.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t,r,i=!1){let{gl:s}=this,n=t.renderTarget,{depthTexture:a,depthBuffer:o,stencilBuffer:l,width:u,height:d}=n;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!l){let t=s.DEPTH_COMPONENT24;!0===i?this.extensions.get("WEBGL_multisampled_render_to_texture").renderbufferStorageMultisampleEXT(s.RENDERBUFFER,n.samples,t,u,d):r>0?(a&&a.isDepthTexture&&a.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,t,u,d)):s.renderbufferStorage(s.RENDERBUFFER,t,u,d),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&l&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,u,d):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,d),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e));s.bindRenderbuffer(s.RENDERBUFFER,null)}async copyTextureToBuffer(e,t,r,i,s,n){let{backend:a,gl:o}=this,{textureGPU:l,glFormat:u,glType:d}=this.backend.get(e),h=o.createFramebuffer();if(a.state.bindFramebuffer(o.READ_FRAMEBUFFER,h),e.isData3DTexture||e.isDataArrayTexture||e.isArrayTexture)o.framebufferTextureLayer(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,l,0,n);else{let t=e.isCubeTexture?o.TEXTURE_CUBE_MAP_POSITIVE_X+n:o.TEXTURE_2D;o.framebufferTexture2D(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,t,l,0)}let c=this._getTypedArrayType(d),p=i*s*this._getBytesPerTexel(d,u),m=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,m),o.bufferData(o.PIXEL_PACK_BUFFER,p,o.STREAM_READ),o.readPixels(t,r,i,s,u,d,0),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),await a.utils._clientWaitAsync();let g=new c(p/c.BYTES_PER_ELEMENT);return o.bindBuffer(o.PIXEL_PACK_BUFFER,m),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,g),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),a.state.bindFramebuffer(o.READ_FRAMEBUFFER,null),o.deleteBuffer(m),o.deleteFramebuffer(h),g}_getTypedArrayType(e){let{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4||e===t.UNSIGNED_SHORT_5_5_5_1||e===t.UNSIGNED_SHORT_5_6_5||e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw Error(`THREE.WebGLTextureUtils: Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){let{gl:r}=this,i=0;return(e===r.UNSIGNED_BYTE&&(i=1),(e===r.UNSIGNED_SHORT_4_4_4_4||e===r.UNSIGNED_SHORT_5_5_5_1||e===r.UNSIGNED_SHORT_5_6_5||e===r.UNSIGNED_SHORT||e===r.HALF_FLOAT)&&(i=2),(e===r.UNSIGNED_INT||e===r.FLOAT)&&(i=4),t===r.RGBA)?4*i:t===r.RGB?3*i:t===r.ALPHA?i:void 0}dispose(){let{gl:e}=this;null!==this._srcFramebuffer&&e.deleteFramebuffer(this._srcFramebuffer),null!==this._dstFramebuffer&&e.deleteFramebuffer(this._dstFramebuffer)}}function mV(e){return e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas?e:e.data}class mG{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class mk{constructor(e){this.backend=e,this.maxAnisotropy=null,this.maxUniformBlockSize=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;let e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){let r=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}getUniformBufferLimit(){if(null!==this.maxUniformBlockSize)return this.maxUniformBlockSize;let e=this.backend.gl;return this.maxUniformBlockSize=e.getParameter(e.MAX_UNIFORM_BLOCK_SIZE),this.maxUniformBlockSize}}let mz={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-s3tc",EXT_texture_compression_bptc:"texture-compression-bc",EXT_disjoint_timer_query_webgl2:"timestamp-query",OVR_multiview2:"OVR_multiview2"};class m${constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){let{gl:r,mode:i,object:s,type:n,info:a,index:o}=this;0!==o?r.drawElements(i,t,n,e):r.drawArrays(i,e,t),a.update(s,t,1)}renderInstances(e,t,r){let{gl:i,mode:s,type:n,index:a,object:o,info:l}=this;0!==r&&(0!==a?i.drawElementsInstanced(s,t,n,e,r):i.drawArraysInstanced(s,e,t,r),l.update(o,t,r))}renderMultiDraw(e,t,r){let{extensions:i,mode:s,object:n,info:a}=this;if(0===r)return;let o=i.get("WEBGL_multi_draw");if(null===o)for(let i=0;i<r;i++)this.render(e[i],t[i]);else{0!==this.index?o.multiDrawElementsWEBGL(s,t,0,this.type,e,0,r):o.multiDrawArraysWEBGL(s,e,0,t,0,r);let i=0;for(let e=0;e<r;e++)i+=t[e];a.update(n,i,1)}}}class mW{constructor(e=256){this.trackTimestamp=!0,this.maxQueries=e,this.currentQueryIndex=0,this.queryOffsets=new Map,this.isDisposed=!1,this.lastValue=0,this.frames=[],this.pendingResolve=!1,this.timestamps=new Map}getTimestampFrames(){return this.frames}getTimestamp(e){let t=this.timestamps.get(e);return void 0===t&&((0,u.R8M)(`TimestampQueryPool: No timestamp available for uid ${e}.`),t=0),t}hasTimestampQuery(e){return this.timestamps.has(e)}allocateQueriesForContext(){}async resolveQueriesAsync(){}dispose(){}}class mH extends mW{constructor(e,t,r=2048){if(super(r),this.gl=e,this.type=t,this.ext=e.getExtension("EXT_disjoint_timer_query_webgl2")||e.getExtension("EXT_disjoint_timer_query"),!this.ext){(0,u.R8M)("EXT_disjoint_timer_query not supported; timestamps will be disabled."),this.trackTimestamp=!1;return}this.queries=[];for(let t=0;t<this.maxQueries;t++)this.queries.push(e.createQuery());this.activeQuery=null,this.queryStates=new Map}allocateQueriesForContext(e){if(!this.trackTimestamp)return null;this.currentQueryIndex+2>this.maxQueries&&(this.resolveQueriesAsync(),this.currentQueryIndex=0,this.queryOffsets.clear(),this.queryStates.clear(),this.activeQuery=null);let t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryStates.set(t,"inactive"),this.queryOffsets.set(e,t),t}beginQuery(e){if(!this.trackTimestamp||this.isDisposed)return;let t=this.queryOffsets.get(e);if(null==t||null!==this.activeQuery)return;let r=this.queries[t];if(r)try{"inactive"===this.queryStates.get(t)&&(this.gl.beginQuery(this.ext.TIME_ELAPSED_EXT,r),this.activeQuery=t,this.queryStates.set(t,"started"))}catch(e){(0,u.z3S)("Error in beginQuery:",e),this.activeQuery=null,this.queryStates.set(t,"inactive")}}endQuery(e){if(!this.trackTimestamp||this.isDisposed)return;let t=this.queryOffsets.get(e);if(null!=t&&this.activeQuery===t)try{this.gl.endQuery(this.ext.TIME_ELAPSED_EXT),this.queryStates.set(t,"ended"),this.activeQuery=null}catch(e){(0,u.z3S)("Error in endQuery:",e),this.queryStates.set(t,"inactive"),this.activeQuery=null}}async resolveQueriesAsync(){if(!this.trackTimestamp||this.pendingResolve)return this.lastValue;this.pendingResolve=!0;try{let e=new Map;for(let[t,r]of this.queryOffsets){let i=this.queryStates.get(r);if("ended"===i){let i=this.queries[r];e.set(t,this.resolveQuery(i))}}if(0===e.size)return this.lastValue;let t={},r=[];for(let[i,s]of(this.timestamps.clear(),e)){let e=i.match(/^(.*):f(\d+)$/),n=parseInt(e[2]);!1===r.includes(n)&&r.push(n),void 0===t[n]&&(t[n]=0);let a=await s;this.timestamps.set(i,a),t[n]+=a}let i=t[r[r.length-1]];return this.lastValue=i,this.frames=r,this.currentQueryIndex=0,this.queryOffsets.clear(),this.queryStates.clear(),this.activeQuery=null,i}catch(e){return(0,u.z3S)("Error resolving queries:",e),this.lastValue}finally{this.pendingResolve=!1}}async resolveQuery(e){return new Promise(t=>{let r;if(this.isDisposed)return void t(this.lastValue);let i=!1,s=e=>{i||(i=!0,r&&(clearTimeout(r),r=null),t(e))},n=()=>{if(this.isDisposed)return void s(this.lastValue);try{if(this.gl.getParameter(this.ext.GPU_DISJOINT_EXT))return void s(this.lastValue);if(!this.gl.getQueryParameter(e,this.gl.QUERY_RESULT_AVAILABLE)){r=setTimeout(n,1);return}let i=this.gl.getQueryParameter(e,this.gl.QUERY_RESULT);t(Number(i)/1e6)}catch(e){(0,u.z3S)("Error checking query:",e),t(this.lastValue)}};n()})}dispose(){if(!this.isDisposed&&(this.isDisposed=!0,this.trackTimestamp)){for(let e of this.queries)this.gl.deleteQuery(e);this.queries=[],this.queryStates.clear(),this.queryOffsets.clear(),this.timestamps.clear(),this.frames=[],this.lastValue=0,this.activeQuery=null}}}let mq=[];class mj extends mC{constructor(e={}){super(e),this.isWebGLBackend=!0,this.attributeUtils=null,this.extensions=null,this.capabilities=null,this.textureUtils=null,this.bufferRenderer=null,this.gl=null,this.state=null,this.utils=null,this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.disjoint=null,this.parallel=null,this._currentContext=null,this._knownBindings=new WeakSet,this._supportsInvalidateFramebuffer="undefined"!=typeof navigator&&/OculusBrowser/g.test(navigator.userAgent),this._xrFramebuffer=null}init(e){super.init(e);let t=this.parameters,r={antialias:e.currentSamples>0,alpha:!0,depth:e.depth,stencil:e.stencil},i=void 0!==t.context?t.context:e.domElement.getContext("webgl2",r);function s(t){t.preventDefault();let r={api:"WebGL",message:t.statusMessage||"Unknown reason",reason:null,originalEvent:t};e.onDeviceLost(r)}this._onContextLost=s,e.domElement.addEventListener("webglcontextlost",s,!1),this.gl=i,this.extensions=new mG(this),this.capabilities=new mk(this),this.attributeUtils=new mM(this),this.textureUtils=new mI(this),this.bufferRenderer=new m$(this),this.state=new mF(this),this.utils=new mL(this),this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_clip_cull_distance"),this.extensions.get("OES_texture_float_linear"),this.extensions.get("EXT_color_buffer_half_float"),this.extensions.get("WEBGL_multisampled_render_to_texture"),this.extensions.get("WEBGL_render_shared_exponent"),this.extensions.get("WEBGL_multi_draw"),this.extensions.get("OVR_multiview2"),this.extensions.get("EXT_clip_control"),this.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile"),this.drawBuffersIndexedExt=this.extensions.get("OES_draw_buffers_indexed"),t.reversedDepthBuffer&&(this.extensions.has("EXT_clip_control")?e.reversedDepthBuffer=!0:((0,u.R8M)("WebGPURenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer."),e.reversedDepthBuffer=!1)),e.reversedDepthBuffer&&this.state.setReversedDepth(!0)}get coordinateSystem(){return u.TdN}get hasTimestamp(){return null!==this.disjoint}async getArrayBufferAsync(e,t=null,r=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,r,i)}async makeXRCompatible(){!0!==this.gl.getContextAttributes().xrCompatible&&await this.gl.makeXRCompatible()}setXRTarget(e){this._xrFramebuffer=e}setXRRenderTargetTextures(e,t,r=null){let i=this.gl;if(this.set(e.texture,{textureGPU:t,glInternalFormat:i.RGBA8}),null!==r){let t=e.stencilBuffer?i.DEPTH24_STENCIL8:i.DEPTH_COMPONENT24;this.set(e.depthTexture,{textureGPU:r,glInternalFormat:t}),!0===this.extensions.has("WEBGL_multisampled_render_to_texture")&&!0===e._autoAllocateDepthBuffer&&!1===e.multiview&&(0,u.R8M)("WebGLBackend: Render-to-texture extension was disabled because an external texture was provided"),e._autoAllocateDepthBuffer=!1}}initTimestampQuery(e,t){if(!this.disjoint||!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new mH(this.gl,e,2048));let r=this.timestampQueryPool[e];null!==r.allocateQueriesForContext(t)&&r.beginQuery(t)}prepareTimestampBuffer(e,t){this.disjoint&&this.trackTimestamp&&this.timestampQueryPool[e].endQuery(t)}getContext(){return this.gl}beginRender(e){let{state:t}=this,r=this.get(e);if(e.viewport)this.updateViewport(e);else{let{width:e,height:r}=this.getDrawingBufferSize();t.viewport(0,0,e,r)}if(e.scissor)this.updateScissor(e);else{let{width:e,height:r}=this.getDrawingBufferSize();t.scissor(0,0,e,r)}this.initTimestampQuery(u.v9J.RENDER,this.getTimestampUID(e)),r.previousContext=this._currentContext,this._currentContext=e,this._setFramebuffer(e),this.clear(e.clearColor,e.clearDepth,e.clearStencil,e,!1);let i=e.occlusionQueryCount;i>0?(r.currentOcclusionQueries=r.occlusionQueries,r.currentOcclusionQueryObjects=r.occlusionQueryObjects,r.lastOcclusionObject=null,r.occlusionQueries=Array(i),r.occlusionQueryObjects=Array(i),r.occlusionQueryIndex=0):void 0!==r.lastOcclusionObject&&(r.lastOcclusionObject=void 0)}finishRender(e){let{gl:t,state:r}=this,i=this.get(e),s=i.previousContext;if(r.resetVertexState(),e.occlusionQueryCount>0){let r=i.lastOcclusionObject;r&&!0===r.occlusionTest&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e)}let n=e.textures;if(null!==n)for(let e=0;e<n.length;e++){let t=n[e];t.generateMipmaps&&this.generateMipmaps(t)}if(this._currentContext=s,this._resolveRenderTarget(e),null!==s){if(this._setFramebuffer(s),s.viewport)this.updateViewport(s);else{let{width:e,height:t}=this.getDrawingBufferSize();r.viewport(0,0,e,t)}if(s.scissor)this.updateScissor(s);else{let{width:e,height:t}=this.getDrawingBufferSize();r.scissor(0,0,e,t)}}this.prepareTimestampBuffer(u.v9J.RENDER,this.getTimestampUID(e))}resolveOccludedAsync(e){let t=this.get(e),{currentOcclusionQueries:r,currentOcclusionQueryObjects:i}=t;if(r&&i){let e=new WeakSet,{gl:s}=this;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueries=null;let n=()=>{let a=!0;for(let t=0;t<r.length;t++){let n=r[t];n&&(s.getQueryParameter(n,s.QUERY_RESULT_AVAILABLE)?(0===s.getQueryParameter(n,s.QUERY_RESULT)&&e.add(i[t]),r[t]=null,s.deleteQuery(n)):a=!1)}!1===a?requestAnimationFrame(n):t.occluded=e};n()}}isOccluded(e,t){let r=this.get(e);return r.occluded&&r.occluded.has(t)}updateViewport(e){let{state:t}=this,{x:r,y:i,width:s,height:n}=e.viewportValue;t.viewport(r,e.height-n-i,s,n)}updateScissor(e){let{state:t}=this,{x:r,y:i,width:s,height:n}=e.scissorValue;t.scissor(r,e.height-n-i,s,n)}setScissorTest(e){this.state.setScissorTest(e)}resetState(){this.state.reset()}getClearColor(){let e=super.getClearColor();return e.r*=e.a,e.g*=e.a,e.b*=e.a,e}clear(e,t,r,i=null,s=!0,n=!0){let{gl:a,renderer:o}=this;null===i&&(i={textures:null,clearColorValue:this.getClearColor()});let l=0;if(e&&(l|=a.COLOR_BUFFER_BIT),t&&(l|=a.DEPTH_BUFFER_BIT),r&&(l|=a.STENCIL_BUFFER_BIT),0!==l){let u;u=i.clearColorValue?i.clearColorValue:this.getClearColor();let d=o.getClearDepth(),h=o.getClearStencil();if(t&&this.state.setDepthMask(!0),r&&this.state.setStencilMask(0xffffffff),null===i.textures)e&&a.clearColor(u.r,u.g,u.b,u.a),t&&a.clearDepth(d),r&&a.clearStencil(h),a.clear(l);else{if(s&&this._setFramebuffer(i),e)for(let e=0;e<i.textures.length;e++){let t=i.mrt?i.mrt.getClearColor(i.textures[e].name):null;null!==t?a.clearBufferfv(a.COLOR,e,[t.r,t.g,t.b,t.a]):0===e?a.clearBufferfv(a.COLOR,e,[u.r,u.g,u.b,u.a]):a.clearBufferfv(a.COLOR,e,[0,0,0,1])}t&&r?a.clearBufferfi(a.DEPTH_STENCIL,0,d,h):t?a.clearBufferfv(a.DEPTH,0,[d]):r&&a.clearBufferiv(a.STENCIL,0,[h]),s&&n&&this._resolveRenderTarget(i),s&&null!==this._currentContext&&this._currentContext!==i&&this._setFramebuffer(this._currentContext)}}}beginCompute(e){let{state:t,gl:r}=this;t.bindFramebuffer(r.FRAMEBUFFER,null),this.initTimestampQuery(u.v9J.COMPUTE,this.getTimestampUID(e))}compute(e,t,r,i,s=null){let{state:n,gl:a}=this;!1===this.discard&&(n.enable(a.RASTERIZER_DISCARD),this.discard=!0);let{programGPU:o,transformBuffers:l,attributes:d}=this.get(i),h=this._getVaoKey(d),c=this.vaoCache[h];void 0===c?this.vaoCache[h]=this._createVao(d):n.setVertexState(c),n.useProgram(o),this._bindUniforms(r);let p=this._getTransformFeedback(l);a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,p),a.beginTransformFeedback(a.POINTS),Array.isArray(s=null!==s?s:t.count)?((0,u.mcG)("WebGLBackend.compute(): The count parameter must be a single number, not an array."),s=s[0]):s&&"object"==typeof s&&s.isIndirectStorageBufferAttribute&&((0,u.mcG)("WebGLBackend.compute(): The count parameter must be a single number, not IndirectStorageBufferAttribute"),s=t.count),d[0].isStorageInstancedBufferAttribute?a.drawArraysInstanced(a.POINTS,0,1,s):a.drawArrays(a.POINTS,0,s),a.endTransformFeedback(),a.bindTransformFeedback(a.TRANSFORM_FEEDBACK,null);for(let e=0;e<l.length;e++){let t=l[e];t.pbo&&this.has(t.pbo)&&this.textureUtils.copyBufferToTexture(t.transformBuffer,t.pbo),t.switchBuffers()}}finishCompute(e){let{state:t,gl:r}=this;this.discard=!1,t.disable(r.RASTERIZER_DISCARD),this.prepareTimestampBuffer(u.v9J.COMPUTE,this.getTimestampUID(e)),this._currentContext&&this._setFramebuffer(this._currentContext)}_isRenderCameraDepthArray(e){return e.depthTexture&&e.depthTexture.isArrayTexture&&e.camera.isArrayCamera}_draw(e,t,r,i,s,n){if(e.isBatchedMesh)if(!1===this.hasFeature("WEBGL_multi_draw")){let{gl:r}=this,i=r.getUniformLocation(n,"nodeUniformDrawId"),s=e._multiDrawStarts,a=e._multiDrawCounts,o=e._multiDrawCount;for(let e=0;e<o;e++)r.uniform1ui(i,e),t.render(s[e],a[e])}else t.renderMultiDraw(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount);else s>1?t.renderInstances(r,i,s):t.render(r,i)}draw(e){let{object:t,pipeline:r,material:i,context:s,hardwareClippingPlanes:n}=e,{programGPU:a}=this.get(r),{gl:o,state:l}=this,u=this.get(s),d=e.getDrawParameters();if(null===d)return;this._bindUniforms(e.getBindings());let h=t.isMesh&&0>t.matrixWorld.determinantAffine();l.setMaterial(i,h,n),null!==s.mrt&&null!==s.textures&&l.setMRTBlending(s.textures,s.mrt,i),l.useProgram(a);let c=e.getAttributes(),p=this.get(c),m=p.vaoGPU;if(void 0===m){let e=this._getVaoKey(c);void 0===(m=this.vaoCache[e])&&(m=this._createVao(c),this.vaoCache[e]=m,p.vaoGPU=m)}let g=e.getIndex(),f=null!==g?this.get(g).bufferGPU:null;l.setVertexState(m,f);let b=u.lastOcclusionObject;if(b!==t&&void 0!==b){if(null!==b&&!0===b.occlusionTest&&(o.endQuery(o.ANY_SAMPLES_PASSED),u.occlusionQueryIndex++),!0===t.occlusionTest){let e=o.createQuery();o.beginQuery(o.ANY_SAMPLES_PASSED,e),u.occlusionQueries[u.occlusionQueryIndex]=e,u.occlusionQueryObjects[u.occlusionQueryIndex]=t}u.lastOcclusionObject=t}let y=this.bufferRenderer;t.isPoints?y.mode=o.POINTS:t.isLineSegments?y.mode=o.LINES:t.isLine?y.mode=o.LINE_STRIP:t.isLineLoop?y.mode=o.LINE_LOOP:!0===i.wireframe?(l.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),y.mode=o.LINES):y.mode=o.TRIANGLES;let{vertexCount:x,instanceCount:T}=d,{firstVertex:_}=d;if(y.object=t,null!==g){_*=g.array.BYTES_PER_ELEMENT;let e=this.get(g);y.index=g.count,y.type=e.type}else y.index=0;if(!0===e.camera.isArrayCamera&&e.camera.cameras.length>0&&!1===e.camera.isMultiViewCamera){let r=this.get(e.camera),i=e.camera.cameras,s=e.getBindingGroup("cameraIndex").bindings[0];if(void 0===r.indexesGPU||r.indexesGPU.length!==i.length){let e=new Uint32Array([0,0,0,0]),t=[];for(let r=0,s=i.length;r<s;r++){let i=o.createBuffer();e[0]=r,o.bindBuffer(o.UNIFORM_BUFFER,i),o.bufferData(o.UNIFORM_BUFFER,e,o.STATIC_DRAW),t.push(i)}r.indexesGPU=t}let n=0;e:for(let t of e.getBindings())for(let e of t.bindings){if(e===s)break e;(e.isUniformsGroup||e.isUniformBuffer)&&n++}let u=this._currentContext.renderTarget,d=null===u||!0===u.isPostProcessingRenderTarget?this.renderer.getPixelRatio():1,h=this._isRenderCameraDepthArray(this._currentContext),c=this._currentContext.activeCubeFace;if(h){let e=this.get(u.depthTexture);if(e.clearedRenderId!==this.renderer._nodes.nodeFrame.renderId){e.clearedRenderId=this.renderer._nodes.nodeFrame.renderId;let{stencilBuffer:t}=u;for(let e=0,r=i.length;e<r;e++)this.renderer._activeCubeFace=e,this._currentContext.activeCubeFace=e,this._setFramebuffer(this._currentContext),this.clear(!1,!0,t,this._currentContext,!1,!1);this.renderer._activeCubeFace=c,this._currentContext.activeCubeFace=c}}for(let s=0,u=i.length;s<u;s++){let u=i[s];if(t.layers.test(u.layers)){h&&(this.renderer._activeCubeFace=s,this._currentContext.activeCubeFace=s,this._setFramebuffer(this._currentContext));let i=u.viewport;if(void 0!==i){let t=i.x*d,r=i.y*d,s=i.width*d,n=i.height*d;l.viewport(Math.floor(t),Math.floor(e.context.height-n-r),Math.floor(s),Math.floor(n))}l.bindBufferBase(o.UNIFORM_BUFFER,n,r.indexesGPU[s]),this._draw(t,y,_,x,T,a)}this._currentContext.activeCubeFace=c,this.renderer._activeCubeFace=c}}else this._draw(t,y,_,x,T,a)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,r,i,s,n){return this.textureUtils.copyTextureToBuffer(e,t,r,i,s,n)}updateSampler(){return""}createNodeBuilder(e,t){return new mN(e,t)}createProgram(e){let t=this.gl,{stage:r,code:i}=e,s="fragment"===r?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(s,i),t.compileShader(s),this.set(e,{shaderGPU:s})}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){let r=this.gl,i=e.pipeline,{fragmentProgram:s,vertexProgram:n}=i,a=r.createProgram(),o=this.get(s).shaderGPU,l=this.get(n).shaderGPU;if(r.attachShader(a,o),r.attachShader(a,l),r.linkProgram(a),this.set(i,{programGPU:a,fragmentShader:o,vertexShader:l}),null!==t&&this.parallel){let s=new Promise(t=>{let s=this.parallel,n=()=>{r.getProgramParameter(a,s.COMPLETION_STATUS_KHR)?(this._completeCompile(e,i),t()):requestAnimationFrame(n)};n()});t.push(s);return}this._completeCompile(e,i)}_handleSource(e,t){let r=e.split("\n"),i=[],s=Math.max(t-6,0),n=Math.min(t+6,r.length);for(let e=s;e<n;e++){let s=e+1;i.push(`${s===t?">":" "} ${s}: ${r[e]}`)}return i.join("\n")}_getShaderErrors(e,t,r){let i=e.getShaderParameter(t,e.COMPILE_STATUS),s=(e.getShaderInfoLog(t)||"").trim();if(i&&""===s)return"";let n=/ERROR: 0:(\d+)/.exec(s);if(!n)return s;{let i=parseInt(n[1]);return r.toUpperCase()+"\n\n"+s+"\n\n"+this._handleSource(e.getShaderSource(t),i)}}_logProgramError(e,t,r){if(this.renderer.debug.checkShaderErrors){let i=this.gl,s=(i.getProgramInfoLog(e)||"").trim();if(!1===i.getProgramParameter(e,i.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(i,e,r,t);else{let n=this._getShaderErrors(i,r,"vertex"),a=this._getShaderErrors(i,t,"fragment");(0,u.z3S)("WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(e,i.VALIDATE_STATUS)+"\n\nProgram Info Log: "+s+"\n"+n+"\n"+a)}else""!==s&&(0,u.R8M)("WebGLProgram: Program Info Log:",s)}}_completeCompile(e,t){let{state:r,gl:i}=this,{programGPU:s,fragmentShader:n,vertexShader:a}=this.get(t);!1===i.getProgramParameter(s,i.LINK_STATUS)&&this._logProgramError(s,n,a),r.useProgram(s);let o=e.getBindings();this._setupBindings(o,s),this.set(t,{programGPU:s,pipeline:s})}createComputePipeline(e,t,r=null){let{gl:i}=this,s={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(s);let{computeProgram:n}=e,a=i.createProgram(),o=this.get(s).shaderGPU,l=this.get(n).shaderGPU,u=n.transforms,d=[],h=[];for(let e=0;e<u.length;e++){let t=u[e];d.push(t.varyingName),h.push(t.attributeNode)}i.attachShader(a,o),i.attachShader(a,l),i.transformFeedbackVaryings(a,d,i.SEPARATE_ATTRIBS),i.linkProgram(a);let c=n.attributes,p=[],m=[];for(let e=0;e<c.length;e++){let t=c[e].node.attribute;p.push(t),this.has(t)||this.attributeUtils.createAttribute(t,i.ARRAY_BUFFER)}for(let e=0;e<h.length;e++){let t=h[e].attribute;this.has(t)||this.attributeUtils.createAttribute(t,i.ARRAY_BUFFER);let r=this.get(t);m.push(r)}if(this.set(e,{programGPU:a,fragmentShader:o,vertexShader:l,transformBuffers:m,attributes:p}),null!==r&&this.parallel){let s=this.parallel,n=new Promise(r=>{let n=()=>{i.getProgramParameter(a,s.COMPLETION_STATUS_KHR)?(this._completeComputeCompile(e,t),r()):requestAnimationFrame(n)};n()});r.push(n);return}this._completeComputeCompile(e,t)}_completeComputeCompile(e,t){let{state:r,gl:i}=this,{programGPU:s,fragmentShader:n,vertexShader:a}=this.get(e);!1===i.getProgramParameter(s,i.LINK_STATUS)&&this._logProgramError(s,n,a),r.useProgram(s),this._setupBindings(t,s)}createBindings(e,t){if(!1===this._knownBindings.has(t)){this._knownBindings.add(t);let e=0,r=0;for(let i of t)for(let t of(this.set(i,{textures:r,uniformBuffers:e}),i.bindings))t.isUniformBuffer&&e++,t.isSampledTexture&&r++}this.updateBindings(e,t)}updateBindings(e){let{gl:t}=this;for(let r of e.bindings){let e=this.get(r);if(r.isUniformsGroup||r.isUniformBuffer){let i=r.buffer,s=e.bufferGPU;t.bindBuffer(t.UNIFORM_BUFFER,s);let n=r.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,s),0===n.length)t.bufferData(t.UNIFORM_BUFFER,i,t.DYNAMIC_DRAW);else{let e=(0,u.iu4)(i),r=e?1:i.BYTES_PER_ELEMENT;for(let s=0,a=n.length;s<a;s++){let a=n[s],o=a.start*r,l=a.count*r,u=o*(e?i.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,u,i,o,l)}}this.set(r,e)}else if(r.isSampledTexture){let{textureGPU:t,glTextureType:i}=this.get(r.texture);e.textureGPU=t,e.glTextureType=i,this.set(r,e)}}}updateBinding(e){let t=this.gl;if(e.isUniformsGroup||e.isUniformBuffer){let r=this.get(e).bufferGPU,i=e.buffer,s=e.updateRanges;if(t.bindBuffer(t.UNIFORM_BUFFER,r),0===s.length)t.bufferData(t.UNIFORM_BUFFER,i,t.DYNAMIC_DRAW);else{let e=(0,u.iu4)(i),r=e?1:i.BYTES_PER_ELEMENT,n=s[0].start;for(let a=0,o=s.length;a<o;a++){let o=s[a],l=s[a+1],u=o.start+o.count;if(void 0!==l&&l.start===u)continue;let d=n*r,h=(u-n)*r,c=d*(e?i.BYTES_PER_ELEMENT:1);t.bufferSubData(t.UNIFORM_BUFFER,c,i,d,h),void 0!==l&&(n=l.start)}}}}createUniformBuffer(e){let t=this.get(e);if(void 0===t.bufferGPU){let r=this.gl,i=e.buffer;t.bufferGPU=r.createBuffer(),r.bindBuffer(r.UNIFORM_BUFFER,t.bufferGPU),r.bufferData(r.UNIFORM_BUFFER,i.byteLength,r.DYNAMIC_DRAW)}}destroyUniformBuffer(e){let t=this.get(e);this.gl.deleteBuffer(t.bufferGPU),this.delete(e)}createIndexAttribute(e){let t=this.gl;this.attributeUtils.createAttribute(e,t.ELEMENT_ARRAY_BUFFER)}createAttribute(e){if(this.has(e))return;let t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}createStorageAttribute(e){if(this.has(e))return;let t=this.gl;this.attributeUtils.createAttribute(e,t.ARRAY_BUFFER)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}hasFeature(e){let t=Object.keys(mz).filter(t=>mz[t]===e),r=this.extensions;for(let e=0;e<t.length;e++)if(r.has(t[e]))return!0;return!1}copyTextureToTexture(e,t,r=null,i=null,s=0,n=0){this.textureUtils.copyTextureToTexture(e,t,r,i,s,n)}copyFramebufferToTexture(e,t,r){this.textureUtils.copyFramebufferToTexture(e,t,r)}hasCompatibility(e){return e===u.x$Y.TEXTURE_COMPARE||super.hasCompatibility(e)}initRenderTarget(e){let{gl:t,state:r}=this;this._setFramebuffer(e),r.bindFramebuffer(t.FRAMEBUFFER,null)}_setFramebuffer(e){let{gl:t,state:r}=this,i=null;if(null!==e.textures){let s,n=e.renderTarget,a=this.get(n),{depthBuffer:o,stencilBuffer:l}=n,d=!0===n.isCubeRenderTarget,h=!0===n.isRenderTarget3D,c=n.depth>1,p=!0===n.isXRRenderTarget,m=!0===p&&!0===n._hasExternalTextures,g=a.msaaFrameBuffer,f=a.depthRenderbuffer,b=this.extensions.get("WEBGL_multisampled_render_to_texture"),y=this.extensions.get("OVR_multiview2"),x=this._useMultisampledExtension(n),T=n.samples;null!==e.depthTexture&&e.depthTexture.renderTarget!==n&&!1===x&&T>0&&((0,u.mcG)('WebGLBackend: Shared depth texture is not supported with MSAA when "WEBGL_multisampled_render_to_texture" is unsupported. Falling back to single-sample rendering.'),T=0);let _=dn(e);if(d?(a.cubeFramebuffers||(a.cubeFramebuffers={}),s=a.cubeFramebuffers[_]):p&&!1===m?s=this._xrFramebuffer:(a.framebuffers||(a.framebuffers={}),s=a.framebuffers[_]),void 0===s){s=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,s);let i=e.textures,o=[];if(d){a.cubeFramebuffers[_]=s;let{textureGPU:e}=this.get(i[0]),r=this.renderer._activeCubeFace,n=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+r,e,n)}else{a.framebuffers[_]=s;for(let r=0;r<i.length;r++){let s=i[r],a=this.get(s);a.renderTarget=e.renderTarget,a.cacheKey=_;let o=t.COLOR_ATTACHMENT0+r;if(n.multiview)y.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,o,a.textureGPU,0,T,0,2);else if(h||c){let e=this.renderer._activeCubeFace,r=this.renderer._activeMipmapLevel;t.framebufferTextureLayer(t.FRAMEBUFFER,o,a.textureGPU,r,e)}else if(x)b.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,o,t.TEXTURE_2D,a.textureGPU,0,T);else{let e=this.renderer._activeMipmapLevel;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,a.textureGPU,e)}}}let u=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(!0===n._autoAllocateDepthBuffer){let r=t.createRenderbuffer();this.textureUtils.setupRenderBufferStorage(r,e,0,x),a.xrDepthRenderbuffer=r,o.push(l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT),t.bindRenderbuffer(t.RENDERBUFFER,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,u,t.RENDERBUFFER,r)}else if(null!==e.depthTexture){o.push(l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT);let r=this.get(e.depthTexture);if(r.renderTarget=e.renderTarget,r.cacheKey=_,n.multiview)y.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,u,r.textureGPU,0,T,0,2);else if(m&&x)b.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,u,t.TEXTURE_2D,r.textureGPU,0,T);else if(e.depthTexture.isArrayTexture){let e=this.renderer._activeCubeFace;t.framebufferTextureLayer(t.FRAMEBUFFER,u,r.textureGPU,0,e)}else if(e.depthTexture.isCubeTexture){let e=this.renderer._activeCubeFace;t.framebufferTexture2D(t.FRAMEBUFFER,u,t.TEXTURE_CUBE_MAP_POSITIVE_X+e,r.textureGPU,0)}else t.framebufferTexture2D(t.FRAMEBUFFER,u,t.TEXTURE_2D,r.textureGPU,0)}a.depthInvalidationArray=o}else{if(this._isRenderCameraDepthArray(e)){r.bindFramebuffer(t.FRAMEBUFFER,s);let i=this.renderer._activeCubeFace,n=this.get(e.depthTexture),a=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.framebufferTextureLayer(t.FRAMEBUFFER,a,n.textureGPU,0,i)}if((p||x||n.multiview)&&!0!==n._isOpaqueFramebuffer){r.bindFramebuffer(t.FRAMEBUFFER,s);let i=this.get(e.textures[0]);n.multiview?y.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,i.textureGPU,0,T,0,2):x?b.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i.textureGPU,0,T):t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i.textureGPU,0);let o=l?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;if(!0===n._autoAllocateDepthBuffer){let e=a.xrDepthRenderbuffer;t.bindRenderbuffer(t.RENDERBUFFER,e),t.framebufferRenderbuffer(t.FRAMEBUFFER,o,t.RENDERBUFFER,e)}else{let r=this.get(e.depthTexture);n.multiview?y.framebufferTextureMultisampleMultiviewOVR(t.FRAMEBUFFER,o,r.textureGPU,0,T,0,2):x?b.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,o,t.TEXTURE_2D,r.textureGPU,0,T):t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,r.textureGPU,0)}}}if(T>0&&!1===x&&!n.multiview){if(void 0===g){g=t.createFramebuffer(),r.bindFramebuffer(t.FRAMEBUFFER,g);let i=[],s=e.textures;for(let r=0;r<s.length;r++){i[r]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,i[r]);let s=e.textures[r],n=this.get(s);t.renderbufferStorageMultisample(t.RENDERBUFFER,T,n.glInternalFormat,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+r,t.RENDERBUFFER,i[r])}t.bindRenderbuffer(t.RENDERBUFFER,null),a.msaaFrameBuffer=g,a.msaaRenderbuffers=i,o&&void 0===f&&(f=t.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(f,e,T),a.depthRenderbuffer=f)}i=a.msaaFrameBuffer}else i=s;r.drawBuffers(e,s)}r.bindFramebuffer(t.FRAMEBUFFER,i)}_getVaoKey(e){let t="";for(let r=0;r<e.length;r++)t+=":"+this.get(e[r]).id;return t}_createVao(e){let{gl:t}=this,r=t.createVertexArray();t.bindVertexArray(r);for(let r=0;r<e.length;r++){let i,s,n=e[r],a=this.get(n);t.bindBuffer(t.ARRAY_BUFFER,a.bufferGPU),t.enableVertexAttribArray(r),!0===n.isInterleavedBufferAttribute?(i=n.data.stride*a.bytesPerElement,s=n.offset*a.bytesPerElement):(i=0,s=0),a.isInteger?t.vertexAttribIPointer(r,n.itemSize,a.type,i,s):t.vertexAttribPointer(r,n.itemSize,a.type,n.normalized,i,s),n.isInstancedBufferAttribute&&!n.isInterleavedBufferAttribute?t.vertexAttribDivisor(r,n.meshPerAttribute):n.isInterleavedBufferAttribute&&n.data.isInstancedInterleavedBuffer&&t.vertexAttribDivisor(r,n.data.meshPerAttribute)}return t.bindBuffer(t.ARRAY_BUFFER,null),r}_getTransformFeedback(e){let t="";for(let r=0;r<e.length;r++)t+=":"+e[r].id;let r=this.transformFeedbackCache[t];if(void 0!==r)return r;let{gl:i}=this;r=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,r);for(let t=0;t<e.length;t++){let r=e[t];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,t,r.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[t]=r,r}_setupBindings(e,t){let r=this.gl,i=0,s=0;for(let n of e)for(let e of n.bindings)if(e.isUniformsGroup||e.isUniformBuffer){let s=i++,n=r.getUniformBlockIndex(t,e.name);r.uniformBlockBinding(t,n,s)}else if(e.isSampledTexture){let i=s++,n=r.getUniformLocation(t,e.name);r.uniform1i(n,i)}}_bindUniforms(e){let{gl:t,state:r}=this,i=0,s=0;for(let n of e)for(let e of n.bindings){let n=this.get(e);if(e.isUniformsGroup||e.isUniformBuffer){let e=i++;r.bindBufferBase(t.UNIFORM_BUFFER,e,n.bufferGPU)}else if(e.isSampledTexture){let e=s++;r.bindTexture(n.glTextureType,n.textureGPU,t.TEXTURE0+e)}}}_resolveRenderTarget(e){let{gl:t,state:r}=this,i=e.renderTarget;if(null!==e.textures&&i){let s=this.get(i);if(i.samples>0&&void 0!==s.msaaFrameBuffer&&!1===this._useMultisampledExtension(i)){let n=s.framebuffers[e.getCacheKey()],a=!1===i.resolveColorBuffer?0:t.COLOR_BUFFER_BIT;i.resolveDepthBuffer&&(i.depthBuffer&&(a|=t.DEPTH_BUFFER_BIT),i.stencilBuffer&&i.resolveStencilBuffer&&(a|=t.STENCIL_BUFFER_BIT));let o=s.msaaFrameBuffer,l=s.msaaRenderbuffers,u=e.textures,d=u.length>1;if(r.bindFramebuffer(t.READ_FRAMEBUFFER,o),r.bindFramebuffer(t.DRAW_FRAMEBUFFER,n),d)for(let e=0;e<u.length;e++)t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,null),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,null,0);for(let r=0;r<u.length;r++){if(d){let{textureGPU:e}=this.get(u[r]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,l[r]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0)}if(e.scissor){let{x:r,y:i,width:s,height:n}=e.scissorValue,o=e.height-n-i;t.blitFramebuffer(r,o,r+s,o+n,r,o,r+s,o+n,a,t.NEAREST)}else t.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,a,t.NEAREST)}if(d)for(let e=0;e<u.length;e++){let{textureGPU:r}=this.get(u[e]);t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,l[e]),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,r,0)}if(!0===this._supportsInvalidateFramebuffer){if(!1===i.storeMultisampledColorBuffer)for(let e=0;e<u.length;e++)mq.push(t.COLOR_ATTACHMENT0+e);i.depthBuffer&&!1===i.storeMultisampledDepthBuffer&&mq.push(i.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT),mq.length>0&&(t.invalidateFramebuffer(t.READ_FRAMEBUFFER,mq),mq.length=0)}}else if(!0===this._supportsInvalidateFramebuffer&&s.framebuffers&&(!0===i._autoAllocateDepthBuffer||i.samples>0&&!1===i.storeMultisampledDepthBuffer)){let i=s.framebuffers[e.getCacheKey()];r.bindFramebuffer(t.DRAW_FRAMEBUFFER,i),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,s.depthInvalidationArray)}}}_useMultisampledExtension(e){return!0===e.multiview||e.samples>0&&!0===this.extensions.has("WEBGL_multisampled_render_to_texture")&&!1!==e._autoAllocateDepthBuffer}async dispose(){await super.dispose(),null!==this.textureUtils&&this.textureUtils.dispose();let e=this.extensions.get("WEBGL_lose_context");e&&e.loseContext(),this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}}let mX={PointList:"point-list",LineList:"line-list",LineStrip:"line-strip",TriangleList:"triangle-list"},mK="undefined"!=typeof self&&self.GPUShaderStage?self.GPUShaderStage:{VERTEX:1,FRAGMENT:2,COMPUTE:4},mQ={Never:"never",Less:"less",Equal:"equal",LessEqual:"less-equal",Greater:"greater",NotEqual:"not-equal",GreaterEqual:"greater-equal",Always:"always"},mY={Store:"store",Discard:"discard"},mZ={Load:"load",Clear:"clear"},mJ={CCW:"ccw",CW:"cw"},m0={None:"none",Back:"back"},m1={Uint16:"uint16",Uint32:"uint32"},m2={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R16Unorm:"r16unorm",R16Snorm:"r16snorm",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RG16Unorm:"rg16unorm",RG16Snorm:"rg16snorm",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10UFloat:"rg11b10ufloat",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA16Unorm:"rgba16unorm",RGBA16Snorm:"rgba16snorm",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-unorm-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},m3={ClampToEdge:"clamp-to-edge",Repeat:"repeat",MirrorRepeat:"mirror-repeat"},m4={Linear:"linear",Nearest:"nearest"},m8={Zero:"zero",One:"one",Src:"src",OneMinusSrc:"one-minus-src",SrcAlpha:"src-alpha",OneMinusSrcAlpha:"one-minus-src-alpha",Dst:"dst",OneMinusDst:"one-minus-dst",DstAlpha:"dst-alpha",OneMinusDstAlpha:"one-minus-dst-alpha",SrcAlphaSaturated:"src-alpha-saturated",Constant:"constant",OneMinusConstant:"one-minus-constant"},m5={Add:"add",Subtract:"subtract",ReverseSubtract:"reverse-subtract",Min:"min",Max:"max"},m6={None:0,All:15},m9={Keep:"keep",Zero:"zero",Replace:"replace",Invert:"invert",IncrementClamp:"increment-clamp",DecrementClamp:"decrement-clamp",IncrementWrap:"increment-wrap",DecrementWrap:"decrement-wrap"},m7={Storage:"storage",ReadOnlyStorage:"read-only-storage"},ge={WriteOnly:"write-only",ReadOnly:"read-only",ReadWrite:"read-write"},gt={NonFiltering:"non-filtering",Comparison:"comparison"},gr={Float:"float",UnfilterableFloat:"unfilterable-float",Depth:"depth",SInt:"sint",UInt:"uint"},gi={TwoD:"2d",ThreeD:"3d"},gs={TwoD:"2d",TwoDArray:"2d-array",Cube:"cube",ThreeD:"3d"},gn={All:"all"},ga={Vertex:"vertex",Instance:"instance"},go={CoreFeaturesAndLimits:"core-features-and-limits",DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionBCSliced3D:"texture-compression-bc-sliced-3d",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TextureCompressionASTCSliced3D:"texture-compression-astc-sliced-3d",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",Float32Blendable:"float32-blendable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups",TextureFormatsTier1:"texture-formats-tier1",TextureFormatsTier2:"texture-formats-tier2"},gl={"texture-compression-s3tc":"texture-compression-bc","texture-compression-etc1":"texture-compression-etc2"};class gu extends mh{constructor(e,t,r){super(e,t?t.value:null),this.textureNode=t,this.groupNode=r}update(){let{textureNode:e}=this;return this.texture!==e.value?(this.texture=e.value,!0):super.update()}}class gd extends ms{constructor(e,t){super(e,t?t.array:null),this._attribute=t,this.isStorageBuffer=!0}get attribute(){return this._attribute}}let gh=0;class gc extends gd{constructor(e,t){super("StorageBuffer_"+(e&&e.name?e.name:gh++),e?e.value:null),this.nodeUniform=e,this.access=e?e.access:M.READ_WRITE,this.groupNode=t}get attribute(){return this.nodeUniform.value}get buffer(){return this.nodeUniform.value.array}}let gp=[null];class gm{constructor(e){this.backend=e,this._preferredCanvasFormat=null}getCurrentDepthStencilFormat(e){let t;return e.depth&&(t=null!==e.depthTexture?this.getTextureFormatGPU(e.depthTexture):e.stencil?!0===this.backend.renderer.reversedDepthBuffer?m2.Depth32FloatStencil8:m2.Depth24PlusStencil8:!0===this.backend.renderer.reversedDepthBuffer?m2.Depth32Float:m2.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getTextureSampleData(e){let t;if(e.isFramebufferTexture)t=1;else if(e.isDepthTexture&&!e.renderTarget){let r=this.backend.get(e);t=void 0!==r.texture?r.texture.sampleCount:this.backend.renderer.currentSamples}else e.renderTarget&&(t=e.renderTarget.samples);let r=(t=this.getSampleCount(t||1))>1&&null!==e.renderTarget&&!0!==e.isDepthTexture&&!0!==e.isFramebufferTexture,i=t>1&&null!==e.renderTarget&&!0===e.isDepthTexture&&!0===e.isArrayTexture,s=r||i?1:t;return{samples:t,primarySamples:s,isMSAA:r}}getCurrentColorFormat(e){return null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat()}getCurrentColorFormats(e){return null!==e.textures?e.textures.map(e=>this.getTextureFormatGPU(e)):[this.getPreferredCanvasFormat()]}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?mX.PointList:e.isLineSegments||e.isMesh&&!0===t.wireframe?mX.LineList:e.isLine?mX.LineStrip:e.isMesh?mX.TriangleList:void 0}getSampleCount(e){return e>=4?4:1}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.currentSamples)}getPreferredCanvasFormat(){let e=this.backend.parameters.outputType;if(void 0===e)return null===this._preferredCanvasFormat&&(this._preferredCanvasFormat=navigator.gpu.getPreferredCanvasFormat()),this._preferredCanvasFormat;if(e===u.OUM)return m2.BGRA8Unorm;if(e===u.ix0)return m2.RGBA16Float;throw Error("THREE.WebGPUUtils: Unsupported output buffer type.")}}function gg(e,t){gp[0]=t,e.queue.submit(gp),gp[0]=null}class gf{constructor(){this.label="",this.layout=null,this.entries=[]}reset(){this.label="",this.layout=null,this.entries.length=0}}class gb{constructor(){this.label="",this.size=0,this.usage=0,this.mappedAtCreation=!1}reset(){this.label="",this.size=0,this.usage=0,this.mappedAtCreation=!1}}class gy{constructor(){this.label=""}reset(){this.label=""}}class gx{constructor(){this.label="",this.colorFormats=null,this.depthStencilFormat=void 0,this.sampleCount=1,this.depthReadOnly=!1,this.stencilReadOnly=!1}reset(){this.label="",this.colorFormats=null,this.depthStencilFormat=void 0,this.sampleCount=1,this.depthReadOnly=!1,this.stencilReadOnly=!1}}class gT{constructor(){this.view=null,this.depthSlice=void 0,this.resolveTarget=void 0,this.clearValue=void 0,this.loadOp=void 0,this.storeOp=void 0}reset(){this.view=null,this.depthSlice=void 0,this.resolveTarget=void 0,this.clearValue=void 0,this.loadOp=void 0,this.storeOp=void 0}}class g_{constructor(){this.label="",this.colorAttachments=[],this.depthStencilAttachment=void 0,this.occlusionQuerySet=void 0,this.timestampWrites=void 0,this.maxDrawCount=5e7}reset(){this.label="",this.colorAttachments.length=0,this.depthStencilAttachment=void 0,this.occlusionQuerySet=void 0,this.timestampWrites=void 0,this.maxDrawCount=5e7}}class gv{constructor(){this.label="",this.layout=null,this.vertex=null,this.primitive={},this.depthStencil=void 0,this.multisample=new gS,this.fragment=null}reset(){this.label="",this.layout=null,this.vertex=null,this.primitive={},this.depthStencil=void 0,this.multisample.reset(),this.fragment=null}}class gS{constructor(){this.count=1,this.mask=0xffffffff,this.alphaToCoverageEnabled=!1}reset(){this.count=1,this.mask=0xffffffff,this.alphaToCoverageEnabled=!1}}class gR{constructor(){this.label="",this.code="",this.compilationHints=[]}reset(){this.label="",this.code="",this.compilationHints.length=0}}class gN{constructor(){this.label="",this.size={width:0,height:1,depthOrArrayLayers:1},this.mipLevelCount=1,this.sampleCount=1,this.dimension="2d",this.format=void 0,this.usage=void 0,this.viewFormats=[],this.textureBindingViewDimension=void 0}reset(){this.label="",this.size.width=0,this.size.height=1,this.size.depthOrArrayLayers=1,this.mipLevelCount=1,this.sampleCount=1,this.dimension="2d",this.format=void 0,this.usage=void 0,this.viewFormats.length=0,this.textureBindingViewDimension=void 0}}class gA{constructor(){this.label="",this.format=void 0,this.dimension=void 0,this.usage=0,this.aspect="all",this.baseMipLevel=0,this.mipLevelCount=void 0,this.baseArrayLayer=0,this.arrayLayerCount=void 0,this.swizzle="rgba"}reset(){this.label="",this.format=void 0,this.dimension=void 0,this.usage=0,this.aspect="all",this.baseMipLevel=0,this.mipLevelCount=void 0,this.baseArrayLayer=0,this.arrayLayerCount=void 0,this.swizzle="rgba"}}let gE=new gf,gC=new gb,gw=new gy,gB=new gx,gM=new g_,gF=new gv,gL=new gT,gU=new gR,gP=new gN,gD=new gA;class gO extends uW{constructor(e){super(),this.device=e;let t=`
|
|
184
|
+
struct VarysStruct {
|
|
185
|
+
@builtin( position ) Position: vec4f,
|
|
186
|
+
@location( 0 ) vTex : vec2f,
|
|
187
|
+
@location( 1 ) @interpolate(flat, either) vBaseArrayLayer: u32,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
@group( 0 ) @binding ( 2 )
|
|
191
|
+
var<uniform> flipY: u32;
|
|
192
|
+
|
|
193
|
+
@vertex
|
|
194
|
+
fn mainVS(
|
|
195
|
+
@builtin( vertex_index ) vertexIndex : u32,
|
|
196
|
+
@builtin( instance_index ) instanceIndex : u32 ) -> VarysStruct {
|
|
197
|
+
|
|
198
|
+
var Varys : VarysStruct;
|
|
199
|
+
|
|
200
|
+
var pos = array(
|
|
201
|
+
vec2f( -1, -1 ),
|
|
202
|
+
vec2f( -1, 3 ),
|
|
203
|
+
vec2f( 3, -1 ),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
let p = pos[ vertexIndex ];
|
|
207
|
+
let mult = select( vec2f( 0.5, -0.5 ), vec2f( 0.5, 0.5 ), flipY != 0 );
|
|
208
|
+
Varys.vTex = p * mult + vec2f( 0.5 );
|
|
209
|
+
Varys.Position = vec4f( p, 0, 1 );
|
|
210
|
+
Varys.vBaseArrayLayer = instanceIndex;
|
|
211
|
+
|
|
212
|
+
return Varys;
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@group( 0 ) @binding( 0 )
|
|
217
|
+
var imgSampler : sampler;
|
|
218
|
+
|
|
219
|
+
@group( 0 ) @binding( 1 )
|
|
220
|
+
var img2d : texture_2d<f32>;
|
|
221
|
+
|
|
222
|
+
@fragment
|
|
223
|
+
fn main_2d( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {
|
|
224
|
+
|
|
225
|
+
return textureSample( img2d, imgSampler, Varys.vTex );
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
@group( 0 ) @binding( 1 )
|
|
230
|
+
var img2dArray : texture_2d_array<f32>;
|
|
231
|
+
|
|
232
|
+
@fragment
|
|
233
|
+
fn main_2d_array( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {
|
|
234
|
+
|
|
235
|
+
return textureSample( img2dArray, imgSampler, Varys.vTex, Varys.vBaseArrayLayer );
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const faceMat = array(
|
|
240
|
+
mat3x3f( 0, 0, -2, 0, -2, 0, 1, 1, 1 ), // pos-x
|
|
241
|
+
mat3x3f( 0, 0, 2, 0, -2, 0, -1, 1, -1 ), // neg-x
|
|
242
|
+
mat3x3f( 2, 0, 0, 0, 0, 2, -1, 1, -1 ), // pos-y
|
|
243
|
+
mat3x3f( 2, 0, 0, 0, 0, -2, -1, -1, 1 ), // neg-y
|
|
244
|
+
mat3x3f( 2, 0, 0, 0, -2, 0, -1, 1, 1 ), // pos-z
|
|
245
|
+
mat3x3f( -2, 0, 0, 0, -2, 0, 1, 1, -1 ), // neg-z
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
@group( 0 ) @binding( 1 )
|
|
249
|
+
var imgCube : texture_cube<f32>;
|
|
250
|
+
|
|
251
|
+
@fragment
|
|
252
|
+
fn main_cube( Varys: VarysStruct ) -> @location( 0 ) vec4<f32> {
|
|
253
|
+
|
|
254
|
+
return textureSample( imgCube, imgSampler, faceMat[ Varys.vBaseArrayLayer ] * vec3f( fract( Varys.vTex ), 1 ) );
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
`;this.mipmapSampler=e.createSampler({minFilter:m4.Linear}),this.flipYSampler=e.createSampler({minFilter:m4.Nearest}),gC.size=4,gC.usage=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,this.flipUniformBuffer=e.createBuffer(gC),gC.reset(),e.queue.writeBuffer(this.flipUniformBuffer,0,new Uint32Array([1])),gC.size=4,gC.usage=GPUBufferUsage.UNIFORM,this.noFlipUniformBuffer=e.createBuffer(gC),gC.reset(),this.transferPipelines={},gU.label="mipmap",gU.code=t,this.mipmapShaderModule=e.createShaderModule(gU),gU.reset()}getTransferPipeline(e,t){t=t||"2d-array";let r=`${e}-${t}`,i=this.transferPipelines[r];return void 0===i&&(gF.label=`mipmap-${e}-${t}`,gF.vertex={module:this.mipmapShaderModule},gF.fragment={module:this.mipmapShaderModule,entryPoint:`main_${t.replace("-","_")}`,targets:[{format:e}]},gF.layout="auto",i=this.device.createRenderPipeline(gF),gF.reset(),this.transferPipelines[r]=i),i}flipY(e,t,r=0){let i=t.format,{width:s,height:n}=t.size;gP.size.width=s,gP.size.height=n,gP.format=i,gP.usage=GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING;let a=this.device.createTexture(gP);gP.reset();let o=this.getTransferPipeline(i,e.textureBindingViewDimension),l=this.getTransferPipeline(i,a.textureBindingViewDimension),u=this.device.createCommandEncoder(gw),d=(e,t,r,i,s,n)=>{let a=e.getBindGroupLayout(0);gD.dimension=t.textureBindingViewDimension||"2d-array",gD.mipLevelCount=1;let o=t.createView(gD);gD.reset(),gE.layout=a,gE.entries.push({binding:0,resource:this.flipYSampler},{binding:1,resource:o},{binding:2,resource:{buffer:n?this.flipUniformBuffer:this.noFlipUniformBuffer}});let l=this.device.createBindGroup(gE);gE.reset(),gD.dimension="2d",gD.mipLevelCount=1,gD.baseArrayLayer=s,gD.arrayLayerCount=1;let d=i.createView(gD);gD.reset(),gL.view=d,gL.loadOp=mZ.Clear,gL.storeOp=mY.Store,gM.colorAttachments.push(gL);let h=u.beginRenderPass(gM);gM.reset(),gL.reset(),h.setPipeline(e),h.setBindGroup(0,l),h.draw(3,1,0,r),h.end()};d(o,e,r,a,0,!1),d(l,a,0,e,r,!0),gg(this.device,u.finish()),a.destroy()}generateMipmaps(e,t=null){let r=this.get(e),i=r.layers||this._mipmapCreateBundles(e),s=t;null===s&&(gw.label="mipmapEncoder",s=this.device.createCommandEncoder(gw),gw.reset()),this._mipmapRunBundles(s,i),null===t&&gg(this.device,s.finish()),r.layers=i}_mipmapCreateBundles(e){let t=e.textureBindingViewDimension||"2d-array",r=this.getTransferPipeline(e.format,t),i=r.getBindGroupLayout(0),s=[];for(let n=1;n<e.mipLevelCount;n++)for(let a=0;a<e.depthOrArrayLayers;a++){gD.dimension=t,gD.baseMipLevel=n-1,gD.mipLevelCount=1;let o=e.createView(gD);gD.reset(),gE.layout=i,gE.entries.push({binding:0,resource:this.mipmapSampler},{binding:1,resource:o},{binding:2,resource:{buffer:this.noFlipUniformBuffer}});let l=this.device.createBindGroup(gE);gE.reset(),gD.dimension="2d",gD.baseMipLevel=n,gD.mipLevelCount=1,gD.baseArrayLayer=a,gD.arrayLayerCount=1;let u=e.createView(gD);gD.reset();let d=new gT;d.view=u,d.loadOp=mZ.Clear,d.storeOp=mY.Store;let h=new g_;h.colorAttachments.push(d),gB.colorFormats=[e.format];let c=this.device.createRenderBundleEncoder(gB);gB.reset(),c.setPipeline(r),c.setBindGroup(0,l),c.draw(3,1,0,a),s.push({renderBundles:[c.finish()],passDescriptor:h})}return s}_mipmapRunBundles(e,t){let r=t.length;for(let i=0;i<r;i++){let r=t[i],s=e.beginRenderPass(r.passDescriptor);s.executeBundles(r.renderBundles),s.end()}}}class gI{constructor(){this.label="",this.addressModeU="clamp-to-edge",this.addressModeV="clamp-to-edge",this.addressModeW="clamp-to-edge",this.magFilter="nearest",this.minFilter="nearest",this.mipmapFilter="nearest",this.lodMinClamp=0,this.lodMaxClamp=32,this.compare=void 0,this.maxAnisotropy=1}reset(){this.label="",this.addressModeU="clamp-to-edge",this.addressModeV="clamp-to-edge",this.addressModeW="clamp-to-edge",this.magFilter="nearest",this.minFilter="nearest",this.mipmapFilter="nearest",this.lodMinClamp=0,this.lodMaxClamp=32,this.compare=void 0,this.maxAnisotropy=1}}class gV{constructor(){this.texture=null,this.mipLevel=0,this.origin={x:0,y:0,z:0},this.aspect="all"}reset(){this.texture=null,this.mipLevel=0,this.origin.x=0,this.origin.y=0,this.origin.z=0,this.aspect="all"}}class gG{constructor(){this.buffer=null,this.offset=0,this.bytesPerRow=void 0,this.rowsPerImage=void 0}reset(){this.buffer=null,this.offset=0,this.bytesPerRow=void 0,this.rowsPerImage=void 0}}class gk{constructor(){this.offset=0,this.bytesPerRow=void 0,this.rowsPerImage=void 0}reset(){this.offset=0,this.bytesPerRow=void 0,this.rowsPerImage=void 0}}class gz{constructor(){this.source=null,this.origin={x:0,y:0},this.flipY=!1}reset(){this.source=null,this.origin.x=0,this.origin.y=0,this.flipY=!1}}class g$ extends gV{constructor(){super(),this.colorSpace="srgb",this.premultipliedAlpha=!1}reset(){super.reset(),this.colorSpace="srgb",this.premultipliedAlpha=!1}}class gW{constructor(){this.width=0,this.height=1,this.depthOrArrayLayers=1}reset(){this.width=0,this.height=1,this.depthOrArrayLayers=1}}let gH=new gb,gq=new gy,gj=new gI,gX=new gV,gK=new gG,gQ=new gk,gY=new gz,gZ=new g$,gJ=new gN,g0=new gW,g1={[u.amv]:"never",[u.vim]:"less",[u.kO0]:"equal",[u.TiK]:"less-equal",[u.eoi]:"greater",[u.gWB]:"greater-equal",[u.FFZ]:"always",[u.jzd]:"not-equal"},g2=[0,1,3,2,4,5];function g3(e,t,r,i,s,n,a,o,l,u){gX.texture=t,gX.mipLevel=r,gX.origin.z=i,gQ.offset=i*n,gQ.bytesPerRow=a,gQ.rowsPerImage=o,g0.width=l,g0.height=u,e.queue.writeTexture(gX,s.data,gQ,g0),gX.reset(),gQ.reset(),g0.reset()}class g4{constructor(e){this.backend=e,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this._samplerCache=new Map}updateSampler(e){let t=this.backend,r=e.texture,i=e.textureNode,s=!0===r.isDepthTexture&&null!==r.compareFunction&&i.isSampleCompare()&&t.hasCompatibility(u.x$Y.TEXTURE_COMPARE),n=r.minFilter+"-"+r.magFilter+"-"+r.wrapS+"-"+r.wrapT+"-"+(r.wrapR||"0")+"-"+r.anisotropy+"-"+ +(!0===r.isDepthTexture)+"-"+(s?r.compareFunction:0),a=this._samplerCache.get(n);if(void 0===a){gj.addressModeU=this._convertAddressMode(r.wrapS),gj.addressModeV=this._convertAddressMode(r.wrapT),gj.addressModeW=this._convertAddressMode(r.wrapR),gj.magFilter=this._convertFilterMode(r.magFilter),gj.minFilter=this._convertFilterMode(r.minFilter),gj.mipmapFilter=this._convertMipmapFilterMode(r.minFilter),r.isDepthTexture&&!1===s&&(gj.magFilter=m4.Nearest,gj.minFilter=m4.Nearest,gj.mipmapFilter=m4.Nearest),gj.magFilter===m4.Linear&&gj.minFilter===m4.Linear&&gj.mipmapFilter===m4.Linear&&(gj.maxAnisotropy=r.anisotropy),s&&(gj.compare=g1[r.compareFunction]);let e=t.device.createSampler(gj);gj.reset(),a={sampler:e,usedTimes:0},this._samplerCache.set(n,a)}let o=t.get(e);return o.sampler!==a.sampler&&(this._releaseSampler(o),o.samplerKey=n,o.sampler=a.sampler,a.usedTimes++),n}destroySampler(e){this._releaseSampler(this.backend.get(e))}_releaseSampler(e){if(void 0!==e.sampler){let t=this._samplerCache.get(e.samplerKey);t.usedTimes--,0===t.usedTimes&&this._samplerCache.delete(e.samplerKey),e.sampler=void 0,e.samplerKey=void 0}}createDefaultTexture(e){let t,r=g8(e,this.backend.device);t=e.isCubeTexture?this._getDefaultCubeTextureGPU(r):this._getDefaultTextureGPU(r),this.backend.get(e).texture=t}createTexture(e,t={}){let r=this.backend,i=r.get(e);if(i.initialized){if(!0===i.externalTexture)return;throw Error("THREE.WebGPUTextureUtils: Texture already initialized.")}if(e.isExternalTexture){i.texture=e.sourceTexture,i.initialized=!0;return}void 0===t.needsMipmaps&&(t.needsMipmaps=!1),void 0===t.levels&&(t.levels=1),void 0===t.depth&&(t.depth=1);let{width:s,height:n,depth:a,levels:o}=t;e.isFramebufferTexture&&(t.renderTarget?t.format=this.backend.utils.getCurrentColorFormat(t.renderTarget):t.format=this.backend.utils.getPreferredCanvasFormat());let l=this._getDimension(e),d=e.internalFormat||t.format||g8(e,r.device);i.format=d;let{samples:h,primarySamples:c,isMSAA:p}=r.utils.getTextureSampleData(e),m=e.renderTarget,g=h>1&&null!==m&&a>1&&l===gi.TwoD,f=void 0!==GPUTextureUsage.TRANSIENT_ATTACHMENT&&!1===g,b=!0===e.isDepthTexture&&f&&m?.storeMultisampledDepthBuffer===!1&&(!1===m.stencilBuffer||!1===m.storeMultisampledStencilBuffer),y=!0!==e.isDepthTexture&&f&&m?.storeMultisampledColorBuffer===!1,x=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;!0===e.isStorageTexture&&(x|=GPUTextureUsage.STORAGE_BINDING),!0!==e.isCompressedTexture&&!0!==e.isCompressedArrayTexture&&d!==m2.RGB9E5UFloat&&(x|=GPUTextureUsage.RENDER_ATTACHMENT),c>1&&b&&(x=GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TRANSIENT_ATTACHMENT);let T=new gN;if(T.label=e.name,T.size.width=s,T.size.height=n,T.size.depthOrArrayLayers=a,T.mipLevelCount=o,T.sampleCount=c,T.dimension=l,T.format=d,T.usage=x,void 0===d){(0,u.R8M)("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(e);return}e.isCubeTexture&&(T.textureBindingViewDimension=gs.Cube);try{i.texture=r.device.createTexture(T)}catch(t){(0,u.R8M)("WebGPURenderer: Failed to create texture with descriptor:",T),this.createDefaultTexture(e);return}if(p||g){let e=Object.assign({},T);if(e.label=e.label+"-msaa",e.sampleCount=h,e.mipLevelCount=1,(b||y)&&(e.usage=GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TRANSIENT_ATTACHMENT),g){e.size=Object.assign({},e.size,{depthOrArrayLayers:1}),i.msaaTextures=[];for(let t=0;t<a;t++)e.label=T.label+"-msaa-"+t,i.msaaTextures.push(r.device.createTexture(e))}else i.msaaTexture=r.device.createTexture(e)}i.initialized=!0,i.textureDescriptorGPU=T}destroyTexture(e,t=!1){let r=this.backend,i=r.get(e);if(void 0!==i.texture&&!1===t&&!0!==e.isExternalTexture&&!0!==i.externalTexture&&i.texture.destroy(),void 0!==i.msaaTexture&&i.msaaTexture.destroy(),void 0!==i.msaaTextures)for(let e of i.msaaTextures)e.destroy();r.delete(e)}generateMipmaps(e,t=null){let r=this.backend.get(e);this._generateMipmaps(r.texture,t)}getColorBuffer(){let e=this.backend,t=e.renderer.getCanvasTarget(),{width:r,height:i}=e.getDrawingBufferSize(),s=e.renderer.currentSamples,n=t.colorTexture,a=e.get(n);if(n.width===r&&n.height===i&&n.samples===s)return a.texture;let o=a.texture;return o&&o.destroy(),gJ.label="colorBuffer",gJ.size.width=r,gJ.size.height=i,gJ.sampleCount=e.utils.getSampleCount(e.renderer.currentSamples),gJ.format=e.utils.getPreferredCanvasFormat(),gJ.usage=GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,o=e.device.createTexture(gJ),gJ.reset(),n.source.width=r,n.source.height=i,n.samples=s,a.texture=o,o}getDepthBuffer(e=!0,t=!1){let r,i,s=this.backend,n=s.renderer.getCanvasTarget(),{width:a,height:o}=s.getDrawingBufferSize(),l=s.renderer.currentSamples,d=n.depthTexture;if(d.width===a&&d.height===o&&d.samples===l&&d.depth===e&&d.stencil===t)return s.get(d).texture;let h=s.get(d).texture;if(t?(r=u.dcC,i=!0===s.renderer.reversedDepthBuffer?u.RQf:u.V3x):e&&(r=u.zdS,i=!0===s.renderer.reversedDepthBuffer?u.RQf:u.bkx),void 0!==h){if(d.image.width===a&&d.image.height===o&&d.format===r&&d.type===i&&d.samples===l)return h;this.destroyTexture(d)}return d.name="depthBuffer",d.format=r,d.type=i,d.image.width=a,d.image.height=o,d.samples=l,this.createTexture(d,{width:a,height:o}),s.get(d).texture}updateTexture(e,t){let r=this.backend.get(e),i=e.mipmaps,{textureDescriptorGPU:s}=r;if(!e.isRenderTargetTexture&&void 0!==s){if(e.isDataTexture)if(i.length>0)for(let t=0,n=i.length;t<n;t++){let n=i[t];this._copyBufferToTexture(n,r.texture,s,0,e.flipY,0,t)}else this._copyBufferToTexture(t.image,r.texture,s,0,e.flipY);else if(e.isArrayTexture||e.isDataArrayTexture||e.isData3DTexture)if(e.layerUpdates&&e.layerUpdates.size>0){for(let i of e.layerUpdates)this._copyBufferToTexture(t.image,r.texture,s,i,e.flipY,i);e.clearLayerUpdates()}else for(let i=0;i<t.image.depth;i++)this._copyBufferToTexture(t.image,r.texture,s,i,e.flipY,i);else if(e.isCompressedTexture||e.isCompressedArrayTexture)e.isCompressedArrayTexture&&e.layerUpdates.size>0?(this._copyCompressedBufferToTexture(e.mipmaps,r.texture,s,e.layerUpdates),e.clearLayerUpdates()):this._copyCompressedBufferToTexture(e.mipmaps,r.texture,s);else if(e.isCubeTexture)this._copyCubeMapToTexture(e,r.texture,s);else if(e.isHTMLTexture){let t=this.backend.device,i=this.backend.renderer.domElement,n=e.image;if("function"!=typeof t.queue.copyElementImageToTexture)return;if(!r.hasPaintCallback){r.hasPaintCallback=!0,i.requestPaint();return}let a=s.size.width,o=s.size.height;2===t.queue.copyElementImageToTexture.length?t.queue.copyElementImageToTexture({source:n},{destination:{texture:r.texture},width:a,height:o}):t.queue.copyElementImageToTexture(n,a,o,{texture:r.texture}),e.flipY&&this._flipY(r.texture,s)}else if(i.length>0)for(let t=0,n=i.length;t<n;t++){let n=i[t];this._copyImageToTexture(n,r.texture,s,0,e.flipY,e.premultiplyAlpha,t)}else this._copyImageToTexture(t.image,r.texture,s,0,e.flipY,e.premultiplyAlpha);r.version=e.version}}async copyTextureToBuffer(e,t,r,i,s,n){let a=this.backend.device,o=this.backend.get(e),l=o.texture,u=o.textureDescriptorGPU.format,d=this._getBytesPerTexel(u),h=i*d;gH.size=(s-1)*(h=256*Math.ceil(h/256))+i*d,gH.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ;let c=a.createBuffer(gH);gH.reset();let p=a.createCommandEncoder(gq);gX.texture=l,gX.origin.x=t,gX.origin.y=r,gX.origin.z=n,gK.buffer=c,gK.bytesPerRow=h,g0.width=i,g0.height=s,p.copyTextureToBuffer(gX,gK,g0),gX.reset(),gK.reset(),g0.reset();let m=this._getTypedArrayType(u);gg(a,p.finish()),await c.mapAsync(GPUMapMode.READ);let g=c.getMappedRange().slice();return c.destroy(),new m(g)}dispose(){this._samplerCache.clear()}_getDefaultTextureGPU(e){let t=this.defaultTexture[e];if(void 0===t){let r=new u.gPd;r.minFilter=u.hxR,r.magFilter=u.hxR,this.createTexture(r,{width:1,height:1,format:e}),this.defaultTexture[e]=t=r}return this.backend.get(t).texture}_getDefaultCubeTextureGPU(e){let t=this.defaultCubeTexture[e];if(void 0===t){let r=new u.b4q;r.minFilter=u.hxR,r.magFilter=u.hxR,this.createTexture(r,{width:1,height:1,depth:6}),this.defaultCubeTexture[e]=t=r}return this.backend.get(t).texture}_copyCubeMapToTexture(e,t,r){let i=e.images,s=e.mipmaps;for(let n=0;n<6;n++){let a=i[n],o=!0===e.flipY?g2[n]:n;a.isDataTexture?this._copyBufferToTexture(a.image,t,r,o,e.flipY):this._copyImageToTexture(a,t,r,o,e.flipY,e.premultiplyAlpha);for(let i=0;i<s.length;i++){let a=s[i].images[n];a.isDataTexture?this._copyBufferToTexture(a.image,t,r,o,e.flipY,0,i+1):this._copyImageToTexture(a,t,r,o,e.flipY,e.premultiplyAlpha,i+1)}}}_copyImageToTexture(e,t,r,i,s,n,a=0){let o=this.backend.device,l=a>0?e.width:r.size.width,u=a>0?e.height:r.size.height;gY.source=e,gY.flipY=s,gZ.texture=t,gZ.mipLevel=a,gZ.origin.z=i,gZ.premultipliedAlpha=n,g0.width=l,g0.height=u;try{o.queue.copyExternalImageToTexture(gY,gZ,g0)}catch(e){}finally{gY.reset(),gZ.reset(),g0.reset()}}_getPassUtils(){let e=this._passUtils;return null===e&&(this._passUtils=e=new gO(this.backend.device)),e}_generateMipmaps(e,t=null){this._getPassUtils().generateMipmaps(e,t)}_flipY(e,t,r=0){this._getPassUtils().flipY(e,t,r)}_copyBufferToTexture(e,t,r,i,s,n=0,a=0){let o=this.backend.device,l=e.data,u=this._getBytesPerTexel(r.format),d=e.width*u;gX.texture=t,gX.mipLevel=a,gX.origin.z=i,gQ.offset=e.width*e.height*u*n,gQ.bytesPerRow=d,g0.width=e.width,g0.height=e.height,o.queue.writeTexture(gX,l,gQ,g0),gX.reset(),gQ.reset(),g0.reset(),!0===s&&this._flipY(t,r,i)}_copyCompressedBufferToTexture(e,t,r,i=null){let s=this.backend.device,n=this._getBlockData(r.format),a=r.size.depthOrArrayLayers>1,o=i&&i.size>0?i:null;for(let i=0;i<e.length;i++){let l=e[i],u=l.width,d=l.height,h=a?r.size.depthOrArrayLayers:1,c=Math.ceil(u/n.width)*n.byteLength,p=Math.ceil(d/n.height),m=c*p,g=Math.ceil(u/n.width)*n.width,f=p*n.height;if(null!==o)for(let e of o)g3(s,t,i,e,l,m,c,p,g,f);else for(let e=0;e<h;e++)g3(s,t,i,e,l,m,c,p,g,f)}}_getBlockData(e){return e===m2.BC1RGBAUnorm||e===m2.BC1RGBAUnormSRGB?{byteLength:8,width:4,height:4}:e===m2.BC2RGBAUnorm||e===m2.BC2RGBAUnormSRGB||e===m2.BC3RGBAUnorm||e===m2.BC3RGBAUnormSRGB?{byteLength:16,width:4,height:4}:e===m2.BC4RUnorm||e===m2.BC4RSnorm?{byteLength:8,width:4,height:4}:e===m2.BC5RGUnorm||e===m2.BC5RGSnorm||e===m2.BC6HRGBUFloat||e===m2.BC6HRGBFloat||e===m2.BC7RGBAUnorm||e===m2.BC7RGBAUnormSRGB?{byteLength:16,width:4,height:4}:e===m2.ETC2RGB8Unorm||e===m2.ETC2RGB8UnormSRGB||e===m2.ETC2RGB8A1Unorm||e===m2.ETC2RGB8A1UnormSRGB?{byteLength:8,width:4,height:4}:e===m2.ETC2RGBA8Unorm||e===m2.ETC2RGBA8UnormSRGB?{byteLength:16,width:4,height:4}:e===m2.EACR11Unorm||e===m2.EACR11Snorm?{byteLength:8,width:4,height:4}:e===m2.EACRG11Unorm||e===m2.EACRG11Snorm||e===m2.ASTC4x4Unorm||e===m2.ASTC4x4UnormSRGB?{byteLength:16,width:4,height:4}:e===m2.ASTC5x4Unorm||e===m2.ASTC5x4UnormSRGB?{byteLength:16,width:5,height:4}:e===m2.ASTC5x5Unorm||e===m2.ASTC5x5UnormSRGB?{byteLength:16,width:5,height:5}:e===m2.ASTC6x5Unorm||e===m2.ASTC6x5UnormSRGB?{byteLength:16,width:6,height:5}:e===m2.ASTC6x6Unorm||e===m2.ASTC6x6UnormSRGB?{byteLength:16,width:6,height:6}:e===m2.ASTC8x5Unorm||e===m2.ASTC8x5UnormSRGB?{byteLength:16,width:8,height:5}:e===m2.ASTC8x6Unorm||e===m2.ASTC8x6UnormSRGB?{byteLength:16,width:8,height:6}:e===m2.ASTC8x8Unorm||e===m2.ASTC8x8UnormSRGB?{byteLength:16,width:8,height:8}:e===m2.ASTC10x5Unorm||e===m2.ASTC10x5UnormSRGB?{byteLength:16,width:10,height:5}:e===m2.ASTC10x6Unorm||e===m2.ASTC10x6UnormSRGB?{byteLength:16,width:10,height:6}:e===m2.ASTC10x8Unorm||e===m2.ASTC10x8UnormSRGB?{byteLength:16,width:10,height:8}:e===m2.ASTC10x10Unorm||e===m2.ASTC10x10UnormSRGB?{byteLength:16,width:10,height:10}:e===m2.ASTC12x10Unorm||e===m2.ASTC12x10UnormSRGB?{byteLength:16,width:12,height:10}:e===m2.ASTC12x12Unorm||e===m2.ASTC12x12UnormSRGB?{byteLength:16,width:12,height:12}:void 0}_convertAddressMode(e){let t=m3.ClampToEdge;return e===u.GJx?t=m3.Repeat:e===u.kTW&&(t=m3.MirrorRepeat),t}_convertFilterMode(e){let t=m4.Linear;return(e===u.hxR||e===u.pHI||e===u.Cfg)&&(t=m4.Nearest),t}_convertMipmapFilterMode(e){return e===u.Cfg||e===u.$_I?m4.Linear:m4.Nearest}_getBytesPerTexel(e){return e===m2.R8Unorm||e===m2.R8Snorm||e===m2.R8Uint||e===m2.R8Sint?1:e===m2.R16Uint||e===m2.R16Sint||e===m2.R16Float||e===m2.RG8Unorm||e===m2.RG8Snorm||e===m2.RG8Uint||e===m2.RG8Sint||e===m2.R16Unorm||e===m2.R16Snorm?2:e===m2.R32Uint||e===m2.R32Sint||e===m2.R32Float||e===m2.RG16Uint||e===m2.RG16Sint||e===m2.RG16Float||e===m2.RGBA8Unorm||e===m2.RGBA8UnormSRGB||e===m2.RGBA8Snorm||e===m2.RGBA8Uint||e===m2.RGBA8Sint||e===m2.BGRA8Unorm||e===m2.BGRA8UnormSRGB||e===m2.RG16Unorm||e===m2.RG16Snorm||e===m2.RGB9E5UFloat||e===m2.RGB10A2Unorm||e===m2.RG11B10UFloat||e===m2.Depth32Float||e===m2.Depth24Plus||e===m2.Depth24PlusStencil8||e===m2.Depth32FloatStencil8?4:e===m2.RG32Uint||e===m2.RG32Sint||e===m2.RG32Float||e===m2.RGBA16Uint||e===m2.RGBA16Sint||e===m2.RGBA16Float||e===m2.RGBA16Unorm||e===m2.RGBA16Snorm?8:e===m2.RGBA32Uint||e===m2.RGBA32Sint||e===m2.RGBA32Float?16:void 0}_getTypedArrayType(e){return e===m2.R8Uint?Uint8Array:e===m2.R8Sint?Int8Array:e===m2.R8Unorm?Uint8Array:e===m2.R8Snorm?Int8Array:e===m2.RG8Uint?Uint8Array:e===m2.RG8Sint?Int8Array:e===m2.RG8Unorm?Uint8Array:e===m2.RG8Snorm?Int8Array:e===m2.RGBA8Uint?Uint8Array:e===m2.RGBA8Sint?Int8Array:e===m2.RGBA8Unorm||e===m2.RGBA8UnormSRGB?Uint8Array:e===m2.RGBA8Snorm?Int8Array:e===m2.R16Uint?Uint16Array:e===m2.R16Sint?Int16Array:e===m2.RG16Uint?Uint16Array:e===m2.RG16Sint?Int16Array:e===m2.RGBA16Uint?Uint16Array:e===m2.RGBA16Sint?Int16Array:e===m2.R16Float||e===m2.RG16Float||e===m2.RGBA16Float||e===m2.R16Unorm?Uint16Array:e===m2.R16Snorm?Int16Array:e===m2.RG16Unorm?Uint16Array:e===m2.RG16Snorm?Int16Array:e===m2.RGBA16Unorm?Uint16Array:e===m2.RGBA16Snorm?Int16Array:e===m2.R32Uint?Uint32Array:e===m2.R32Sint?Int32Array:e===m2.R32Float?Float32Array:e===m2.RG32Uint?Uint32Array:e===m2.RG32Sint?Int32Array:e===m2.RG32Float?Float32Array:e===m2.RGBA32Uint?Uint32Array:e===m2.RGBA32Sint?Int32Array:e===m2.RGBA32Float?Float32Array:e===m2.BGRA8Unorm||e===m2.BGRA8UnormSRGB?Uint8Array:e===m2.RGB10A2Unorm||e===m2.RGB9E5UFloat||e===m2.RG11B10UFloat?Uint32Array:e===m2.Depth32Float?Float32Array:e===m2.Depth24Plus||e===m2.Depth24PlusStencil8?Uint32Array:e===m2.Depth32FloatStencil8?Float32Array:void 0}_getDimension(e){return e.is3DTexture||e.isData3DTexture?gi.ThreeD:gi.TwoD}}function g8(e,t){let r,i=e.format,s=e.type,n=e.normalized,a=e.colorSpace,o=u.ppV.getTransfer(a),l=!1;if(n&&!1===(l=t.features.has(go.TextureFormatsTier1))&&(0,u.R8M)("WebGPURenderer: Unable to use normalized textures without texture-formats-tier1 feature."),!0===e.isCompressedTexture||!0===e.isCompressedArrayTexture)switch(i){case u.IE4:case u.Nz6:r=o===u.KLL?m2.BC1RGBAUnormSRGB:m2.BC1RGBAUnorm;break;case u.jR7:r=o===u.KLL?m2.BC2RGBAUnormSRGB:m2.BC2RGBAUnorm;break;case u.BXX:r=o===u.KLL?m2.BC3RGBAUnormSRGB:m2.BC3RGBAUnorm;break;case u.Kef:r=m2.BC4RUnorm;break;case u.XG_:r=m2.BC4RSnorm;break;case u.HO_:r=m2.BC5RGUnorm;break;case u.CWW:r=m2.BC5RGSnorm;break;case u.Fn:r=o===u.KLL?m2.BC7RGBAUnormSRGB:m2.BC7RGBAUnorm;break;case u.H23:r=m2.BC6HRGBFloat;break;case u.W9U:r=m2.BC6HRGBUFloat;break;case u.Riy:case u.CVz:r=o===u.KLL?m2.ETC2RGB8UnormSRGB:m2.ETC2RGB8Unorm;break;case u.KDk:r=o===u.KLL?m2.ETC2RGBA8UnormSRGB:m2.ETC2RGBA8Unorm;break;case u.BVL:r=m2.EACR11Unorm;break;case u.gZr:r=m2.EACR11Snorm;break;case u.OtU:r=m2.EACRG11Unorm;break;case u.jSS:r=m2.EACRG11Snorm;break;case u.qa3:r=o===u.KLL?m2.ASTC4x4UnormSRGB:m2.ASTC4x4Unorm;break;case u.B_h:r=o===u.KLL?m2.ASTC5x4UnormSRGB:m2.ASTC5x4Unorm;break;case u.czI:r=o===u.KLL?m2.ASTC5x5UnormSRGB:m2.ASTC5x5Unorm;break;case u.rSH:r=o===u.KLL?m2.ASTC6x5UnormSRGB:m2.ASTC6x5Unorm;break;case u.Qrf:r=o===u.KLL?m2.ASTC6x6UnormSRGB:m2.ASTC6x6Unorm;break;case u.psI:r=o===u.KLL?m2.ASTC8x5UnormSRGB:m2.ASTC8x5Unorm;break;case u.a5J:r=o===u.KLL?m2.ASTC8x6UnormSRGB:m2.ASTC8x6Unorm;break;case u._QJ:r=o===u.KLL?m2.ASTC8x8UnormSRGB:m2.ASTC8x8Unorm;break;case u.uB5:r=o===u.KLL?m2.ASTC10x5UnormSRGB:m2.ASTC10x5Unorm;break;case u.lyL:r=o===u.KLL?m2.ASTC10x6UnormSRGB:m2.ASTC10x6Unorm;break;case u.bC7:r=o===u.KLL?m2.ASTC10x8UnormSRGB:m2.ASTC10x8Unorm;break;case u.y3Z:r=o===u.KLL?m2.ASTC10x10UnormSRGB:m2.ASTC10x10Unorm;break;case u.ojs:r=o===u.KLL?m2.ASTC12x10UnormSRGB:m2.ASTC12x10Unorm;break;case u.S$4:r=o===u.KLL?m2.ASTC12x12UnormSRGB:m2.ASTC12x12Unorm;break;case u.GWd:r=o===u.KLL?m2.RGBA8UnormSRGB:m2.RGBA8Unorm;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture format.",i)}else switch(i){case u.GWd:switch(s){case u.tJf:r=m2.RGBA8Snorm;break;case u.fBL:r=l?m2.RGBA16Snorm:m2.RGBA16Sint;break;case u.cHt:r=l?m2.RGBA16Unorm:m2.RGBA16Uint;break;case u.bkx:r=m2.RGBA32Uint;break;case u.Yuy:r=m2.RGBA32Sint;break;case u.OUM:r=o===u.KLL?m2.RGBA8UnormSRGB:m2.RGBA8Unorm;break;case u.ix0:r=m2.RGBA16Float;break;case u.RQf:r=m2.RGBA32Float;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture type with RGBAFormat.",s)}break;case u.HIg:switch(s){case u.Dmk:r=m2.RGB9E5UFloat;break;case u.yT7:r=m2.RG11B10UFloat;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture type with RGBFormat.",s)}break;case u.VT0:switch(s){case u.tJf:r=m2.R8Snorm;break;case u.fBL:r=l?m2.R16Snorm:m2.R16Sint;break;case u.cHt:r=l?m2.R16Unorm:m2.R16Uint;break;case u.bkx:r=m2.R32Uint;break;case u.Yuy:r=m2.R32Sint;break;case u.OUM:r=m2.R8Unorm;break;case u.ix0:r=m2.R16Float;break;case u.RQf:r=m2.R32Float;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture type with RedFormat.",s)}break;case u.paN:switch(s){case u.tJf:r=m2.RG8Snorm;break;case u.fBL:r=l?m2.RG16Snorm:m2.RG16Sint;break;case u.cHt:r=l?m2.RG16Unorm:m2.RG16Uint;break;case u.bkx:r=m2.RG32Uint;break;case u.Yuy:r=m2.RG32Sint;break;case u.OUM:r=m2.RG8Unorm;break;case u.ix0:r=m2.RG16Float;break;case u.RQf:r=m2.RG32Float;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture type with RGFormat.",s)}break;case u.zdS:switch(s){case u.cHt:r=m2.Depth16Unorm;break;case u.bkx:r=m2.Depth24Plus;break;case u.RQf:r=m2.Depth32Float;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture type with DepthFormat.",s)}break;case u.dcC:switch(s){case u.V3x:r=m2.Depth24PlusStencil8;break;case u.RQf:t&&!1===t.features.has(go.Depth32FloatStencil8)&&(0,u.z3S)('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),r=m2.Depth32FloatStencil8;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",s)}break;case u.ZQM:switch(s){case u.Yuy:r=m2.R32Sint;break;case u.bkx:r=m2.R32Uint;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",s)}break;case u.TkQ:switch(s){case u.Yuy:r=m2.RG32Sint;break;case u.bkx:r=m2.RG32Uint;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",s)}break;case u.c90:switch(s){case u.Yuy:r=m2.RGBA32Sint;break;case u.bkx:r=m2.RGBA32Uint;break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",s)}break;default:(0,u.z3S)("WebGPURenderer: Unsupported texture format.",i)}return r}let g5=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,g6=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/ig,g9={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2<f32>":"vec2","vec2<i32>":"ivec2","vec2<u32>":"uvec2","vec2<bool>":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3<f32>":"vec3","vec3<i32>":"ivec3","vec3<u32>":"uvec3","vec3<bool>":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4<f32>":"vec4","vec4<i32>":"ivec4","vec4<u32>":"uvec4","vec4<bool>":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2<f32>":"mat2",mat2x2f:"mat2","mat3x3<f32>":"mat3",mat3x3f:"mat3","mat4x4<f32>":"mat4",mat4x4f:"mat4",sampler:"sampler",sampler_comparison:"samplerComparison",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_depth_2d_array:"depthTexture",texture_depth_multisampled_2d:"depthTexture",texture_depth_cube:"depthTexture",texture_depth_cube_array:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class g7 extends pA{constructor(e){let{type:t,inputs:r,name:i,inputsCode:s,blockCode:n,outputType:a}=(e=>{let t=(e=e.replace(/^(?:\s*\/\/[^\r\n]*|\s*\/\*[\s\S]*?\*\/|\s*)+/,"")).match(g5);if(null!==t&&4===t.length){let r=t[2],i=[],s=null;for(;null!==(s=g6.exec(r));)i.push({name:s[1],type:s[2]});let n=[];for(let e=0;e<i.length;e++){let{name:t,type:r}=i[e],s=r;s.startsWith("ptr")?s="pointer":(s.startsWith("texture")&&(s=r.split("<")[0]),s=g9[s]),n.push(new pc(s,t))}let a=e.substring(t[0].length),o=t[3]||"void",l=void 0!==t[1]?t[1]:"";return{type:g9[o]||o,inputs:n,name:l,inputsCode:r,blockCode:a,outputType:o}}throw Error("THREE.WGSLNodeFunction: Function is not a WGSL code.")})(e);super(t,r,i),this.inputsCode=s,this.blockCode=n,this.outputType=a}getCode(e=this.name){let t="void"!==this.outputType?"-> "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class fe extends pN{parseFunction(e){return new g7(e)}}let ft={[M.READ_ONLY]:"read",[M.WRITE_ONLY]:"write",[M.READ_WRITE]:"read_write"},fr={[u.GJx]:"repeat",[u.ghU]:"clamp",[u.kTW]:"mirror"},fi={vertex:mK.VERTEX,fragment:mK.FRAGMENT,compute:mK.COMPUTE},fs={instance:!0,swizzleAssign:!1,storageBuffer:!0},fn={"^^":"tsl_xor"},fa={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3<f32>",vec2:"vec2<f32>",ivec2:"vec2<i32>",uvec2:"vec2<u32>",bvec2:"vec2<bool>",vec3:"vec3<f32>",ivec3:"vec3<i32>",uvec3:"vec3<u32>",bvec3:"vec3<bool>",vec4:"vec4<f32>",ivec4:"vec4<i32>",uvec4:"vec4<u32>",bvec4:"vec4<bool>",mat2:"mat2x2<f32>",mat3:"mat3x3<f32>",mat4:"mat4x4<f32>"},fo={},fl={tsl_xor:new hd("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new hd("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new hd("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new hd("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new hd("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new hd("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new hd("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new hd("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new hd("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new hd("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new hd("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new hd("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),inverse_mat2:new hd(`
|
|
258
|
+
fn tsl_inverse_mat2( m : mat2x2<f32> ) -> mat2x2<f32> {
|
|
259
|
+
|
|
260
|
+
let det = m[ 0 ][ 0 ] * m[ 1 ][ 1 ] - m[ 0 ][ 1 ] * m[ 1 ][ 0 ];
|
|
261
|
+
|
|
262
|
+
return mat2x2<f32>(
|
|
263
|
+
m[ 1 ][ 1 ], - m[ 0 ][ 1 ],
|
|
264
|
+
- m[ 1 ][ 0 ], m[ 0 ][ 0 ]
|
|
265
|
+
) * ( 1.0 / det );
|
|
266
|
+
|
|
267
|
+
}
|
|
268
|
+
`),inverse_mat3:new hd(`
|
|
269
|
+
fn tsl_inverse_mat3( m : mat3x3<f32> ) -> mat3x3<f32> {
|
|
270
|
+
|
|
271
|
+
let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ];
|
|
272
|
+
let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ];
|
|
273
|
+
let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ];
|
|
274
|
+
|
|
275
|
+
let b01 = a22 * a11 - a12 * a21;
|
|
276
|
+
let b11 = - a22 * a10 + a12 * a20;
|
|
277
|
+
let b21 = a21 * a10 - a11 * a20;
|
|
278
|
+
|
|
279
|
+
let det = a00 * b01 + a01 * b11 + a02 * b21;
|
|
280
|
+
|
|
281
|
+
return mat3x3<f32>(
|
|
282
|
+
b01, ( - a22 * a01 + a02 * a21 ), ( a12 * a01 - a02 * a11 ),
|
|
283
|
+
b11, ( a22 * a00 - a02 * a20 ), ( - a12 * a00 + a02 * a10 ),
|
|
284
|
+
b21, ( - a21 * a00 + a01 * a20 ), ( a11 * a00 - a01 * a10 )
|
|
285
|
+
) * ( 1.0 / det );
|
|
286
|
+
|
|
287
|
+
}
|
|
288
|
+
`),inverse_mat4:new hd(`
|
|
289
|
+
fn tsl_inverse_mat4( m : mat4x4<f32> ) -> mat4x4<f32> {
|
|
290
|
+
|
|
291
|
+
let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ]; let a03 = m[ 0 ][ 3 ];
|
|
292
|
+
let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ]; let a13 = m[ 1 ][ 3 ];
|
|
293
|
+
let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ]; let a23 = m[ 2 ][ 3 ];
|
|
294
|
+
let a30 = m[ 3 ][ 0 ]; let a31 = m[ 3 ][ 1 ]; let a32 = m[ 3 ][ 2 ]; let a33 = m[ 3 ][ 3 ];
|
|
295
|
+
|
|
296
|
+
let b00 = a00 * a11 - a01 * a10;
|
|
297
|
+
let b01 = a00 * a12 - a02 * a10;
|
|
298
|
+
let b02 = a00 * a13 - a03 * a10;
|
|
299
|
+
let b03 = a01 * a12 - a02 * a11;
|
|
300
|
+
let b04 = a01 * a13 - a03 * a11;
|
|
301
|
+
let b05 = a02 * a13 - a03 * a12;
|
|
302
|
+
let b06 = a20 * a31 - a21 * a30;
|
|
303
|
+
let b07 = a20 * a32 - a22 * a30;
|
|
304
|
+
let b08 = a20 * a33 - a23 * a30;
|
|
305
|
+
let b09 = a21 * a32 - a22 * a31;
|
|
306
|
+
let b10 = a21 * a33 - a23 * a31;
|
|
307
|
+
let b11 = a22 * a33 - a23 * a32;
|
|
308
|
+
|
|
309
|
+
let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
310
|
+
|
|
311
|
+
return mat4x4<f32>(
|
|
312
|
+
a11 * b11 - a12 * b10 + a13 * b09,
|
|
313
|
+
a02 * b10 - a01 * b11 - a03 * b09,
|
|
314
|
+
a31 * b05 - a32 * b04 + a33 * b03,
|
|
315
|
+
a22 * b04 - a21 * b05 - a23 * b03,
|
|
316
|
+
a12 * b08 - a10 * b11 - a13 * b07,
|
|
317
|
+
a00 * b11 - a02 * b08 + a03 * b07,
|
|
318
|
+
a32 * b02 - a30 * b05 - a33 * b01,
|
|
319
|
+
a20 * b05 - a22 * b02 + a23 * b01,
|
|
320
|
+
a10 * b10 - a11 * b08 + a13 * b06,
|
|
321
|
+
a01 * b08 - a00 * b10 - a03 * b06,
|
|
322
|
+
a30 * b04 - a31 * b02 + a33 * b00,
|
|
323
|
+
a21 * b02 - a20 * b04 - a23 * b00,
|
|
324
|
+
a11 * b07 - a10 * b09 - a12 * b06,
|
|
325
|
+
a00 * b09 - a01 * b07 + a02 * b06,
|
|
326
|
+
a31 * b01 - a30 * b03 - a32 * b00,
|
|
327
|
+
a20 * b03 - a21 * b01 + a22 * b00
|
|
328
|
+
) * ( 1.0 / det );
|
|
329
|
+
|
|
330
|
+
}
|
|
331
|
+
`),biquadraticTexture:new hd(`
|
|
332
|
+
fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {
|
|
333
|
+
|
|
334
|
+
let res = vec2f( iRes );
|
|
335
|
+
|
|
336
|
+
let uvScaled = coord * res;
|
|
337
|
+
let uvWrapping = ( ( uvScaled % res ) + res ) % res;
|
|
338
|
+
|
|
339
|
+
// https://www.shadertoy.com/view/WtyXRy
|
|
340
|
+
|
|
341
|
+
let uv = uvWrapping - 0.5;
|
|
342
|
+
let iuv = floor( uv );
|
|
343
|
+
let f = fract( uv );
|
|
344
|
+
|
|
345
|
+
let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );
|
|
346
|
+
let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );
|
|
347
|
+
let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );
|
|
348
|
+
let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );
|
|
349
|
+
|
|
350
|
+
return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
|
|
351
|
+
|
|
352
|
+
}
|
|
353
|
+
`),biquadraticTextureArray:new hd(`
|
|
354
|
+
fn tsl_biquadraticTexture_array( map : texture_2d_array<f32>, coord : vec2f, iRes : vec2u, layer : u32, level : u32 ) -> vec4f {
|
|
355
|
+
|
|
356
|
+
let res = vec2f( iRes );
|
|
357
|
+
|
|
358
|
+
let uvScaled = coord * res;
|
|
359
|
+
let uvWrapping = ( ( uvScaled % res ) + res ) % res;
|
|
360
|
+
|
|
361
|
+
// https://www.shadertoy.com/view/WtyXRy
|
|
362
|
+
|
|
363
|
+
let uv = uvWrapping - 0.5;
|
|
364
|
+
let iuv = floor( uv );
|
|
365
|
+
let f = fract( uv );
|
|
366
|
+
|
|
367
|
+
let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, layer, level );
|
|
368
|
+
let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, layer, level );
|
|
369
|
+
let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, layer, level );
|
|
370
|
+
let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, layer, level );
|
|
371
|
+
|
|
372
|
+
return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
|
|
373
|
+
|
|
374
|
+
}
|
|
375
|
+
`)},fu={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inverse_mat2:"tsl_inverse_mat2",inverse_mat3:"tsl_inverse_mat3",inverse_mat4:"tsl_inverse_mat4",inversesqrt:"inverseSqrt",faceforward:"faceForward",bitcast:"bitcast<f32>",floatpack_snorm_2x16:"pack2x16snorm",floatpack_unorm_2x16:"pack2x16unorm",floatpack_float16_2x16:"pack2x16float",floatpack_snorm_4x8:"pack4x8snorm",floatpack_unorm_4x8:"pack4x8unorm",floatunpack_snorm_2x16:"unpack2x16snorm",floatunpack_unorm_2x16:"unpack2x16unorm",floatunpack_float16_2x16:"unpack2x16float",floatunpack_snorm_4x8:"unpack4x8snorm",floatunpack_unorm_4x8:"unpack4x8unorm"},fd=new Set(["alias","break","case","const","const_assert","continue","continuing","default","diagnostic","discard","else","enable","false","fn","for","if","let","loop","override","requires","return","struct","switch","true","var","while","NULL","Self","abstract","active","alignas","alignof","as","asm","asm_fragment","async","attribute","auto","await","become","binding_array","cast","catch","class","co_await","co_return","co_yield","coherent","column_major","common","compile","compile_fragment","concept","const_cast","consteval","constexpr","constinit","crate","debugger","decltype","delete","demote","demote_to_helper","do","dynamic_cast","enum","explicit","export","extends","extern","external","fallthrough","filter","final","finally","friend","from","fxgroup","get","goto","groupshared","highp","impl","implements","import","inline","instanceof","interface","layout","lowp","macro","macro_rules","match","mediump","meta","mod","module","move","mut","mutable","namespace","new","nil","noexcept","noinline","nointerpolation","non_coherent","noncoherent","noperspective","null","nullptr","of","operator","package","packoffset","partition","pass","patch","pixelfragment","precise","precision","premerge","priv","protected","pub","public","readonly","ref","regardless","register","reinterpret_cast","require","resource","restrict","self","set","shared","sizeof","smooth","snorm","static","static_assert","static_cast","std","subroutine","super","target","template","this","thread_local","throw","trait","try","type","typedef","typeid","typename","typeof","union","unless","unorm","unsafe","unsized","use","using","varying","virtual","volatile","wgsl","where","with","writeonly","yield","main"]),fh="";!0!==("undefined"!=typeof navigator&&/Firefox|Deno/g.test(navigator.userAgent))&&(fh+="diagnostic( off, derivative_uniformity );\n");class fc extends pd{constructor(e,t){super(e,t,new fe),this.uniformGroups={},this.uniformGroupsBindings={},this.builtins={},this.directives={},this.scopedArrays=new Map,this.allowEarlyReturns=!0,this.allowGlobalVariables=!0}_generateTextureSample(e,t,r,i,s,n=this.shaderStage){return"fragment"!==n?this.generateTextureSampleLevel(e,t,r,"0",i):i?s?`textureSample( ${t}, ${t}_sampler, ${r}, ${i}, ${s} )`:`textureSample( ${t}, ${t}_sampler, ${r}, ${i} )`:s?`textureSample( ${t}, ${t}_sampler, ${r}, ${s} )`:`textureSample( ${t}, ${t}_sampler, ${r} )`}generateTextureSampleLevel(e,t,r,i,s,n){if(!1===this.isUnfilterable(e))if(s)return n?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${n} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`;else return n?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${n} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i} )`;return this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,n,i,s):this.generateTextureLod(e,t,r,s,n,i)}generateWrapFunction(e){let t=`tsl_coord_${fr[e.wrapS]}S_${fr[e.wrapT]}T_${e.is3DTexture||e.isData3DTexture?"3d":"2d"}`,r=fo[t];if(void 0===r){let i=[],s=e.is3DTexture||e.isData3DTexture?"vec3f":"vec2f",n=`fn ${t}( coord : ${s} ) -> ${s} {
|
|
376
|
+
|
|
377
|
+
return ${s}(
|
|
378
|
+
`,a=(e,t)=>{e===u.GJx?(i.push(fl.repeatWrapping_float),n+=` tsl_repeatWrapping_float( coord.${t} )`):e===u.ghU?(i.push(fl.clampWrapping_float),n+=` tsl_clampWrapping_float( coord.${t} )`):e===u.kTW?(i.push(fl.mirrorWrapping_float),n+=` tsl_mirrorWrapping_float( coord.${t} )`):(n+=` coord.${t}`,(0,u.R8M)(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};a(e.wrapS,"x"),n+=",\n",a(e.wrapT,"y"),(e.is3DTexture||e.isData3DTexture)&&(n+=",\n",a(e.wrapR,"z")),n+="\n );\n\n}\n",fo[t]=r=new hd(n,i)}return r.build(this),t}generateArrayDeclaration(e,t){return`array< ${this.getType(e)}, ${t} >`}generateTextureDimension(e,t,r){let i=this.getDataFromNode(e,this.shaderStage,this.cache);void 0===i.dimensionsSnippet&&(i.dimensionsSnippet={});let s=i.dimensionsSnippet[r];if(void 0===i.dimensionsSnippet[r]){let n,a,{primarySamples:o}=this.renderer.backend.utils.getTextureSampleData(e);a=e.is3DTexture||e.isData3DTexture?"vec3<u32>":"vec2<u32>",n=o>1||e.isStorageTexture?t:`${t}${r?`, u32( ${r} )`:""}`,s=new ir(new iO(`textureDimensions( ${n} )`,a)),i.dimensionsSnippet[r]=s,(e.isArrayTexture||e.isDataArrayTexture||e.is3DTexture||e.isData3DTexture)&&(i.arrayLayerCount=new ir(new iO(`textureNumLayers(${t})`,"u32"))),e.isTextureCube&&(i.cubeFaceCount=new ir(new iO("6u","u32")))}return s.build(this)}generateTextureSize(e,t,r){let{primarySamples:i}=this.renderer.backend.utils.getTextureSampleData(e),s=i>1||e.isStorageTexture?t:`${t}, ${r}`;return`textureDimensions( ${s} )`}generateFilteredTexture(e,t,r,i,s="0u",n){let a=this.generateWrapFunction(e),o=this.generateTextureDimension(e,t,s);return(i&&(r=`${r} + vec2<f32>(${i}) / ${o}`),n)?(this._include("biquadraticTextureArray"),`tsl_biquadraticTexture_array( ${t}, ${a}( ${r} ), ${o}, u32( ${n} ), u32( ${s} ) )`):(this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${t}, ${a}( ${r} ), ${o}, u32( ${s} ) )`)}generateTextureLod(e,t,r,i,s,n="0u"){if(!0===e.isCubeTexture){s&&(r=`${r} + vec3<f32>(${s})`);let i=e.isDepthTexture?"u32":"f32";return`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}( ${n} ) )`}let a=this.generateWrapFunction(e),o=this.generateTextureDimension(e,t,n),l=e.is3DTexture||e.isData3DTexture?"vec3":"vec2",u="vec3"===l?"vec3<u32>( 1, 1, 1 )":"vec2<u32>( 1, 1 )";s&&(r=`${r} + ${l}<f32>(${s}) / ${l}<f32>( ${o} )`);let d=`${l}<f32>( 0 )`,h=`${l}<f32>( ${o} - ${u} )`;return r=`${l}<u32>( clamp( floor( ${a}( ${r} ) * ${l}<f32>( ${o} ) ), ${d}, ${h} ) )`,this.generateTextureLoad(e,t,r,n,i,null)}generateStorageTextureLoad(e,t,r,i,s,n){return n&&(r=`${r} + ${n}`),s?`textureLoad( ${t}, ${r}, ${s} )`:`textureLoad( ${t}, ${r} )`}generateTextureLoad(e,t,r,i,s,n){let a;return null===i&&(i="0u"),n&&(r=`${r} + ${n}`),s?a=`textureLoad( ${t}, ${r}, ${s}, u32( ${i} ) )`:(a=`textureLoad( ${t}, ${r}, u32( ${i} ) )`,this.renderer.backend.compatibilityMode&&e.isDepthTexture&&(a+=".x")),a}generateTextureStore(e,t,r,i,s){return i?`textureStore( ${t}, ${r}, ${i}, ${s} )`:`textureStore( ${t}, ${r}, ${s} )`}isSampleCompare(e){return!0===e.isDepthTexture&&null!==e.compareFunction&&this.renderer.hasCompatibility(u.x$Y.TEXTURE_COMPARE)}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&e.type===u.RQf||!1===this.isSampleCompare(e)&&e.minFilter===u.hxR&&e.magFilter===u.hxR||this.renderer.backend.utils.getTextureSampleData(e).primarySamples>1||!0===e.normalized&&(e.type===u.fBL||e.type===u.cHt)}generateTexture(e,t,r,i,s,n=this.shaderStage){return this.isUnfilterable(e)?this.generateTextureLod(e,t,r,i,s,"0",n):this._generateTextureSample(e,t,r,i,s,n)}generateTextureGrad(e,t,r,i,s,n,a=this.shaderStage){if("fragment"===a)if(s)return n?`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${s}, ${i[0]}, ${i[1]}, ${n} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${s}, ${i[0]}, ${i[1]} )`;else return n?`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${i[0]}, ${i[1]}, ${n} )`:`textureSampleGrad( ${t}, ${t}_sampler, ${r}, ${i[0]}, ${i[1]} )`;(0,u.z3S)(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${a} shader.`)}generateTextureCompare(e,t,r,i,s,n,a=this.shaderStage){if("fragment"===a)return!0===e.isDepthTexture&&!0===e.isArrayTexture?n?`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${n} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`:n?`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${i}, ${n} )`:`textureSampleCompare( ${t}, ${t}_sampler, ${r}, ${i} )`;(0,u.z3S)(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${a} shader.`)}generateTextureGather(e,t,r,i,s,n){let a=!0===e.isDepthTexture?"":`${i}, `;return s?n?`textureGather( ${a}${t}, ${t}_sampler, ${r}, ${s}, ${n} )`:`textureGather( ${a}${t}, ${t}_sampler, ${r}, ${s} )`:n?`textureGather( ${a}${t}, ${t}_sampler, ${r}, ${n} )`:`textureGather( ${a}${t}, ${t}_sampler, ${r})`}generateTextureGatherCompare(e,t,r,i,s,n){return s?n?`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${n} )`:`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${s}, ${i})`:n?`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${i}, ${n} )`:`textureGatherCompare( ${t}, ${t}_sampler, ${r}, ${i})`}generateTextureLevel(e,t,r,i,s,n){if(!1===this.isUnfilterable(e))if(s)return n?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${n} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`;else return n?`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i}, ${n} )`:`textureSampleLevel( ${t}, ${t}_sampler, ${r}, ${i} )`;return this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,r,n,i,s):this.generateTextureLod(e,t,r,s,n,i)}generateTextureBias(e,t,r,i,s,n,a=this.shaderStage){if("fragment"===a)if(s)return n?`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${s}, ${i}, ${n} )`:`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${s}, ${i} )`;else return n?`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${i}, ${n} )`:`textureSampleBias( ${t}, ${t}_sampler, ${r}, ${i} )`;(0,u.z3S)(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${a} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){let t=e.name,r=e.type;return"texture"===r||"cubeTexture"===r||"cubeDepthTexture"===r||"storageTexture"===r||"texture3D"===r?t:"buffer"!==r&&"storageBuffer"!==r&&"indirectStorageBuffer"!==r?e.groupNode.name+"."+t:this.isCustomStruct(e)?t:t+".value"}return super.getPropertyName(e)}isReservedKeyword(e){return fd.has(e)}getOutputStructName(){return"output"}getFunctionOperator(e){let t=fn[e];return void 0!==t?(this._include(t),t):null}getNodeAccess(e,t){if("compute"!==t)return!0===e.isAtomic?"vertex"===t?((0,u.R8M)("WebGPURenderer: Atomic operations are not supported in the vertex stage. They are only available in the fragment and compute stages."),M.READ_ONLY):M.READ_WRITE:M.READ_ONLY;return e.access}getStorageAccess(e,t){return ft[this.getNodeAccess(e,t)]}getUniformFromNode(e,t,r,i=null){let s=super.getUniformFromNode(e,t,r,i),n=this.getDataFromNode(e,r,this.globalCache);if(void 0===n.uniformGPU){let a,o=e.groupNode,l=o.name,u=this.getBindGroupArray(l,r);if("texture"===t||"cubeTexture"===t||"cubeDepthTexture"===t||"storageTexture"===t||"texture3D"===t){let i=null,n=this.getNodeAccess(e,r);if("texture"===t||"storageTexture"===t?i=!0===e.value.is3DTexture?new mf(s.name,s.node,o,n):new mm(s.name,s.node,o,n):"cubeTexture"===t||"cubeDepthTexture"===t?i=new mg(s.name,s.node,o,n):"texture3D"===t&&(i=new mf(s.name,s.node,o,n)),i.store=!0===e.isStorageTextureNode,i.mipLevel=i.store?e.mipLevel:0,i.setVisibility(fi[r]),!0===e.value.isCubeTexture||!1===this.isUnfilterable(e.value)&&!1===i.store||null!==e.gatherNode){let e=new gu(`${s.name}_sampler`,s.node,o);e.setVisibility(fi[r]),u.push(e,i),a=[e,i]}else u.push(i),a=[i]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){let n=this.getSharedDataFromNode(e),l=n.buffer;void 0===l&&(n.buffer=l=new("buffer"===t?mo:gc)(e,o)),l.setVisibility(l.getVisibility()|fi[r]),u.push(l),a=l,s.name=i||"NodeBuffer_"+s.id}else{let e=this.uniformGroups[l];void 0===e&&((e=new md(l,o)).setVisibility(mK.VERTEX|mK.FRAGMENT|mK.COMPUTE),this.uniformGroups[l]=e),-1===u.indexOf(e)&&u.push(e);let r=(a=this.getNodeUniform(s,t)).name;e.uniforms.some(e=>e.name===r)||e.addUniform(a)}n.uniformGPU=a}return s}getBuiltin(e,t,r,i=this.shaderStage){let s=this.builtins[i]||(this.builtins[i]=new Map);return!1===s.has(e)&&s.set(e,{name:e,property:t,type:r}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){let t=e.layout,r=this.flowShaderNode(e),i=[];for(let e of t.inputs)i.push(e.name+" : "+this.getType(e.type));let s=`fn ${t.name}( ${i.join(", ")} ) -> ${this.getType(t.type)} {
|
|
379
|
+
${r.vars}
|
|
380
|
+
${r.code}
|
|
381
|
+
`;return r.result&&(s+=` return ${r.result};
|
|
382
|
+
`),s+="\n}\n"}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){let t=[],r=this.directives[e];if(void 0!==r)for(let e of r)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array<f32, ${e} >`,"vertex")}getBuiltins(e){let t=[],r=this.builtins[e];if(void 0!==r)for(let{name:e,property:i,type:s}of r.values())t.push(`@builtin( ${e} ) ${i} : ${s}`);return t.join(",\n ")}getScopedArray(e,t,r,i,s){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:r,bufferCount:i,isAtomic:s}),e}getScopedArrays(e){if("compute"!==e)return;let t=[];for(let{name:e,scope:r,bufferType:i,bufferCount:s,isAtomic:n}of this.scopedArrays.values()){let a=this.getType(i);!0===n&&(a=`atomic<${a}>`),t.push(`var<${r}> ${e}: array< ${a}, ${s} >;`)}return t.join("\n")}getAttributes(e){let t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","globalId","vec3<u32>","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3<u32>","attribute"),this.getBuiltin("local_invocation_id","localId","vec3<u32>","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3<u32>","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){let e=this.getBuiltins("attribute");e&&t.push(e);let r=this.getAttributesArray();for(let e=0,i=r.length;e<i;e++){let i=r[e],s=i.name,n=this.getType(i.type);t.push(`@location( ${e} ) ${s} : ${n}`)}}return t.join(",\n ")}getStructMembers(e){let t=[];for(let r of e.members){let i=e.output?"@location( "+r.index+" ) ":"",s=this.getType(r.type);r.atomic&&(s="atomic< "+s+" >"),t.push(` ${i+r.name} : ${s}`)}return e.output&&t.push(` ${this.getBuiltins("output")}`),t.join(",\n")}getStructs(e){let t="",r=this.structs[e];if(r.length>0){let e=[];for(let t of r){let r=`struct ${t.name} {
|
|
383
|
+
`;r+=this.getStructMembers(t),r+="\n};",e.push(r)}t="\n"+e.join("\n\n")+"\n"}return t}getVar(e,t,r=null,i=""){let s=`var${i} ${t} : `;return null!==r?s+=this.generateArrayDeclaration(e,r):s+=this.getType(e),s}getVars(e,t=!1){let r="";t&&(r="<private>");let i=[],s=this.vars[e];if(void 0!==s)for(let e of s)i.push(`${this.getVar(e.type,e.name,e.count,r)};`);return t?i.join("\n"):`
|
|
384
|
+
${i.join("\n ")}
|
|
385
|
+
`}getVaryings(e){let t=[];if("vertex"===e&&this.getBuiltin("position","builtinClipSpace","vec4<f32>","vertex"),"vertex"===e||"fragment"===e){let r=this.varyings,i=this.vars[e],s=0;for(let n=0;n<r.length;n++){let a=r[n];if(a.needsInterpolation){let e=`@location( ${s++} )`;if(a.interpolationType){let t=null!==a.interpolationSampling?`, ${a.interpolationSampling} )`:" )";e+=` @interpolate( ${a.interpolationType}${t}`}else/^(int|uint|ivec|uvec)/.test(a.type)&&(e+=" @interpolate(flat, either)");t.push(`${e} ${a.name} : ${this.getType(a.type)}`)}else"vertex"===e&&!1===i.includes(a)&&i.push(a)}}let r=this.getBuiltins(e);r&&t.push(r);let i=t.join(",\n ");return"vertex"===e?this._getWGSLStruct("VaryingsStruct"," "+i):i}isCustomStruct(e){let t=e.value,r=e.node,i=(t.isBufferAttribute||t.isInstancedBufferAttribute)&&null!==r.structTypeNode,s=r.value&&r.value.array&&"number"==typeof r.value.itemSize&&r.value.array.length>r.value.itemSize;return i&&!s}getUniforms(e){let t=this.renderer.backend,r=this.uniforms[e],i=[],s=[],n=[],a={};for(let n of r){let r=n.groupNode.name,o=this.bindingsIndexes[r];if("texture"===n.type||"cubeTexture"===n.type||"cubeDepthTexture"===n.type||"storageTexture"===n.type||"texture3D"===n.type){let r,s=n.node,a=s.value;(!0===a.isCubeTexture||!1===this.isUnfilterable(a)&&!0!==s.isStorageTextureNode||null!==s.gatherNode)&&(this.isSampleCompare(a)&&s.isSampleCompare()?i.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${n.name}_sampler : sampler_comparison;`):i.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${n.name}_sampler : sampler;`));let l="",{primarySamples:u}=t.utils.getTextureSampleData(a);if(u>1&&(l="_multisampled"),!0===a.isCubeTexture&&!0===a.isDepthTexture)r="texture_depth_cube";else if(!0===a.isCubeTexture)r="texture_cube<f32>";else if(!0===a.isDepthTexture)r=t.compatibilityMode&&null===a.compareFunction?`texture${l}_2d<f32>`:`texture_depth${l}_2d${!0===a.isArrayTexture?"_array":""}`;else if(!0===n.node.isStorageTextureNode){let i=g8(a,t.device),s=this.getStorageAccess(n.node,e),o=n.node.value.is3DTexture,l=n.node.value.isArrayTexture,u=o?"3d":`2d${l?"_array":""}`;r=`texture_storage_${u}<${i}, ${s}>`}else if(!0===a.isArrayTexture||!0===a.isDataArrayTexture||!0===a.isCompressedArrayTexture){let e=this.getComponentTypeFromTexture(a).charAt(0);r=`texture_2d_array<${e}32>`}else if(!0===a.is3DTexture||!0===a.isData3DTexture){let e=this.getComponentTypeFromTexture(a).charAt(0);r=`texture_3d<${e}32>`}else{let e=this.getComponentTypeFromTexture(a).charAt(0);r=`texture${l}_2d<${e}32>`}i.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${n.name} : ${r};`)}else if("buffer"===n.type||"storageBuffer"===n.type||"indirectStorageBuffer"===n.type){let t=n.node,r=this.getType(t.getNodeType(this)),i=t.bufferCount,a=i>0&&"buffer"===n.type?", "+i:"",l=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t,e)}`:"uniform";if(this.isCustomStruct(n))s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var<${l}> ${n.name} : ${r};`);else{let e=t.isAtomic?`atomic<${r}>`:`${r}`,i=` value : array< ${e}${a} >`;s.push(this._getWGSLStructBinding(n.name,i,l,o.binding++,o.group))}}else{let e=n.groupNode.name;if(void 0===a[e]){let t=this.uniformGroups[e];if(void 0!==t){let r=[];for(let e of t.uniforms){let t=e.getType(),i=this.getType(this.getVectorType(t));r.push(` ${e.name} : ${i}`)}let i=this.uniformGroupsBindings[e];void 0===i&&(i={index:o.binding++,id:o.group},this.uniformGroupsBindings[e]=i),a[e]={index:i.index,id:i.id,snippets:r}}}}}for(let e in a){let t=a[e];n.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}return[...i,...s,...n].join("\n")}buildCode(){let e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};for(let t in this.sortBindingGroups(),e){this.shaderStage=t;let r=this.allowGlobalVariables,i=e[t];i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.structs=this.getStructs(t),i.vars=this.getVars(t,r),i.codes=this.getCodes(t),i.directives=this.getDirectives(t),i.scopedArrays=this.getScopedArrays(t);let s="// code\n\n";s+=this.flowCode[t];let n=this.flowNodes[t],a=n[n.length-1],o=a.outputNode,l=void 0!==o&&!0===o.isOutputStructNode;for(let e of n){let r=this.getFlowData(e),n=e.name;if(n&&(s.length>0&&(s+="\n"),s+=` // flow -> ${n}
|
|
386
|
+
`),s+=`${r.code}
|
|
387
|
+
`,e===a&&"compute"!==t){if(s+="// result\n\n ","vertex"===t)s+=`varyings.builtinClipSpace = ${r.result};`;else if("fragment"===t)if(l)i.returnType=o.getNodeType(this),i.structs+="var<private> output : "+i.returnType+";",s+=`return ${r.result};`;else{let e=` @location( 0 ) color: ${this.getType(this.getOutputType())}`,t=this.getBuiltins("output");t&&(e+=",\n "+t),i.returnType="OutputStruct",i.structs+=this._getWGSLStruct("OutputStruct",e),i.structs+="\nvar<private> output : OutputStruct;",s+=`output.color = ${this.format(r.result,a.getNodeType(this),this.getOutputType())};
|
|
388
|
+
|
|
389
|
+
return output;`}}}i.flow=s}if(this.shaderStage=null,null!==this.material)this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment);else{let t=this.compute.workgroupSize;this.computeShader=this._getWGSLComputeCode(e.compute,t)}}getMethod(e,t=null){let r;return null!==t&&(r=this._getWGSLMethod(e+"_"+t)),void 0===r&&(r=this._getWGSLMethod(e)),r||e}getBitcastMethod(e){let t=this.getType(e);return`bitcast<${t}>`}getFloatPackingMethod(e,t="2x16"){return this.getMethod(`floatpack_${e}_${t}`)}getFloatUnpackingMethod(e,t="2x16"){return this.getMethod(`floatunpack_${e}_${t}`)}getTernary(e,t,r){return`select( ${r}, ${t}, ${e} )`}getType(e){return fa[e]||e}isAvailable(e){let t=fs[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),fs[e]=t),t}_getWGSLMethod(e){return void 0!==fl[e]&&this._include(e),fu[e]}_include(e){let t=fl[e];return t.build(this),this.addInclude(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}
|
|
390
|
+
// directives
|
|
391
|
+
${e.directives}
|
|
392
|
+
|
|
393
|
+
// structs
|
|
394
|
+
${e.structs}
|
|
395
|
+
|
|
396
|
+
// uniforms
|
|
397
|
+
${e.uniforms}
|
|
398
|
+
|
|
399
|
+
// varyings
|
|
400
|
+
${e.varyings}
|
|
401
|
+
var<private> varyings : VaryingsStruct;
|
|
402
|
+
|
|
403
|
+
// vars
|
|
404
|
+
${e.vars}
|
|
405
|
+
|
|
406
|
+
// codes
|
|
407
|
+
${e.codes}
|
|
408
|
+
|
|
409
|
+
@vertex
|
|
410
|
+
fn main( ${e.attributes} ) -> VaryingsStruct {
|
|
411
|
+
|
|
412
|
+
// flow
|
|
413
|
+
${e.flow}
|
|
414
|
+
|
|
415
|
+
return varyings;
|
|
416
|
+
|
|
417
|
+
}
|
|
418
|
+
`}_getWGSLFragmentCode(e){return`${this.getSignature()}
|
|
419
|
+
// global
|
|
420
|
+
${fh}
|
|
421
|
+
|
|
422
|
+
// structs
|
|
423
|
+
${e.structs}
|
|
424
|
+
|
|
425
|
+
// uniforms
|
|
426
|
+
${e.uniforms}
|
|
427
|
+
|
|
428
|
+
// vars
|
|
429
|
+
${e.vars}
|
|
430
|
+
|
|
431
|
+
// codes
|
|
432
|
+
${e.codes}
|
|
433
|
+
|
|
434
|
+
@fragment
|
|
435
|
+
fn main( ${e.varyings} ) -> ${e.returnType} {
|
|
436
|
+
|
|
437
|
+
// flow
|
|
438
|
+
${e.flow}
|
|
439
|
+
|
|
440
|
+
}
|
|
441
|
+
`}_getWGSLComputeCode(e,t){let[r,i,s]=t;return`${this.getSignature()}
|
|
442
|
+
// directives
|
|
443
|
+
${e.directives}
|
|
444
|
+
|
|
445
|
+
// system
|
|
446
|
+
var<private> instanceIndex : u32;
|
|
447
|
+
|
|
448
|
+
// locals
|
|
449
|
+
${e.scopedArrays}
|
|
450
|
+
|
|
451
|
+
// structs
|
|
452
|
+
${e.structs}
|
|
453
|
+
|
|
454
|
+
// uniforms
|
|
455
|
+
${e.uniforms}
|
|
456
|
+
|
|
457
|
+
// vars
|
|
458
|
+
${this.allowGlobalVariables?e.vars:""}
|
|
459
|
+
|
|
460
|
+
// codes
|
|
461
|
+
${e.codes}
|
|
462
|
+
|
|
463
|
+
@compute @workgroup_size( ${r}, ${i}, ${s} )
|
|
464
|
+
fn main( ${e.attributes} ) {
|
|
465
|
+
|
|
466
|
+
// local vars
|
|
467
|
+
${this.allowGlobalVariables?"":e.vars}
|
|
468
|
+
|
|
469
|
+
// system
|
|
470
|
+
instanceIndex = globalId.x
|
|
471
|
+
+ globalId.y * ( ${r} * numWorkgroups.x )
|
|
472
|
+
+ globalId.z * ( ${r} * numWorkgroups.x ) * ( ${i} * numWorkgroups.y );
|
|
473
|
+
|
|
474
|
+
// flow
|
|
475
|
+
${e.flow}
|
|
476
|
+
|
|
477
|
+
}
|
|
478
|
+
`}_getWGSLStruct(e,t){return`
|
|
479
|
+
struct ${e} {
|
|
480
|
+
${t}
|
|
481
|
+
};`}_getWGSLStructBinding(e,t,r,i=0,s=0){let n=e+"Struct",a=this._getWGSLStruct(n,t);return`${a}
|
|
482
|
+
@binding( ${i} ) @group( ${s} )
|
|
483
|
+
var<${r}> ${e} : ${n};`}}let fp=new gb,fm=new gy,fg=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32"]],[Uint32Array,["uint32"]],[Float32Array,["float32"]]]);"undefined"!=typeof Float16Array&&fg.set(Float16Array,["float16"]);let ff=new Map([[u.Oax,["float16"]]]),fb=new Map([[Int32Array,"sint32"],[Uint32Array,"uint32"],[Float32Array,"float32"]]);class fy{constructor(e){this.backend=e}createAttribute(e,t){let r=this._getBufferAttribute(e),i=this.backend,s=i.get(r),n=s.buffer;if(void 0===n){let a,o=i.device,l=r.array;if(!1===e.normalized&&!0!==e.isInterleavedBufferAttribute){if(l.constructor===Int16Array||l.constructor===Int8Array)l=new Int32Array(l);else if((l.constructor===Uint16Array||l.constructor===Uint8Array)&&(l=new Uint32Array(l),t&GPUBufferUsage.INDEX))for(let e=0;e<l.length;e++)65535===l[e]&&(l[e]=0xffffffff)}if(r.array=l,(r.isStorageBufferAttribute||r.isStorageInstancedBufferAttribute)&&3===r.itemSize?a=4:r.itemSize>1&&r.itemSize*l.BYTES_PER_ELEMENT%4!=0&&(a=4*Math.floor((r.itemSize*l.BYTES_PER_ELEMENT+3)/4)/l.BYTES_PER_ELEMENT),void 0!==a){let e=r.itemSize,t=new l.constructor(r.count*a);for(let i=0;i<r.count;i++)t.set(l.subarray(i*e,i*e+e),i*a);(r.isStorageBufferAttribute||r.isStorageInstancedBufferAttribute)&&(r.itemSize=a,r.array=t),l=t,s._itemSize=e,s._paddedItemSize=a}let u=l.byteLength;fp.label=r.name,fp.size=u+(4-u%4)%4,fp.usage=t,fp.mappedAtCreation=!0,n=o.createBuffer(fp),fp.reset(),new l.constructor(n.getMappedRange()).set(l),n.unmap(),s.buffer=n}}updateAttribute(e){let t=this._getBufferAttribute(e),r=this.backend,i=r.device,s=r.get(t),n=r.get(t).buffer,a=t.array,o=s._itemSize,l=s._paddedItemSize;if(void 0!==l){a=new a.constructor(t.count*l);for(let e=0;e<t.count;e++)a.set(t.array.subarray(e*o,e*o+o),e*l);(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute)&&(t.array=a)}let d=t.updateRanges;if(0===d.length)i.queue.writeBuffer(n,0,a,0);else{let e=(0,u.iu4)(a),r=e?1:a.BYTES_PER_ELEMENT;for(let t=0,s=d.length;t<s;t++){let s,u,h=d[t];if(void 0!==l){let e=Math.floor(h.start/o),t=Math.ceil((h.start+h.count)/o)-e;s=e*l*r,u=t*l*r}else s=h.start*r,u=h.count*r;let c=s*(e?a.BYTES_PER_ELEMENT:1);i.queue.writeBuffer(n,c,a,s,u)}t.clearUpdateRanges()}}createShaderVertexBuffers(e){let t=e.getAttributes(),r=new Map;for(let e=0;e<t.length;e++){let i=t[e],s=i.array.BYTES_PER_ELEMENT,n=this._getBufferAttribute(i),a=r.get(n);if(void 0===a){let e,t;!0===i.isInterleavedBufferAttribute?(e=i.data.stride*s,t=i.data.isInstancedInterleavedBuffer?ga.Instance:ga.Vertex):(e=i.itemSize*s,t=i.isInstancedBufferAttribute?ga.Instance:ga.Vertex,i.itemSize>1&&e%4!=0&&(e=4*Math.floor((e+3)/4))),a={arrayStride:e,attributes:[],stepMode:t},r.set(n,a)}let o=this._getVertexFormat(i),l=!0===i.isInterleavedBufferAttribute?i.offset*s:0;a.attributes.push({shaderLocation:e,offset:l,format:o})}return Array.from(r.values())}destroyAttribute(e){let t=this.backend;t.get(this._getBufferAttribute(e)).buffer.destroy(),t.delete(e)}async getArrayBufferAsync(e,t=null,r=0,i=-1){let s,n=this.backend,a=n.device,o=n.get(this._getBufferAttribute(e)).buffer,l=-1===i?o.size-r:i;if(null!==t&&t.isReadbackBuffer){let e=n.get(t);if(!0===t._mapped)throw Error("THREE.WebGPUAttributeUtils: ReadbackBuffer must be released before being used again.");if(t._mapped=!0,void 0===e.readBufferGPU){fp.label=`${t.name}_readback`,fp.size=t.maxByteLength,fp.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,s=a.createBuffer(fp),fp.reset();let r=()=>{t.buffer=null,t._mapped=!1,s.unmap()},i=()=>{t.buffer=null,t._mapped=!1,s.destroy(),n.delete(t),t.removeEventListener("release",r),t.removeEventListener("dispose",i)};t.addEventListener("release",r),t.addEventListener("dispose",i),e.readBufferGPU=s}else s=e.readBufferGPU}else fp.label=`${e.name}_readback`,fp.size=l,fp.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,s=a.createBuffer(fp),fp.reset();fm.label=`readback_encoder_${e.name}`;let u=a.createCommandEncoder(fm);if(fm.reset(),u.copyBufferToBuffer(o,r,s,0,l),gg(a,u.finish()),await s.mapAsync(GPUMapMode.READ,0,l),null===t){let e=s.getMappedRange(0,l).slice();return s.destroy(),e}if(t.isReadbackBuffer)return t.buffer=s.getMappedRange(0,l),t;{let e=s.getMappedRange(0,l);return new Uint8Array(t).set(new Uint8Array(e)),s.destroy(),t}}_getVertexFormat(e){let t,{itemSize:r,normalized:i}=e,s=e.array.constructor,n=e.constructor;if(1===r)t=fb.get(s);else{let e=(ff.get(n)||fg.get(s))[+!!i];if(e){let i=4*Math.floor((s.BYTES_PER_ELEMENT*r+3)/4)/s.BYTES_PER_ELEMENT;if(i%1)throw Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");t=`${e}x${i}`}}return t||(0,u.z3S)("WebGPUAttributeUtils: Vertex format not supported yet."),t}_getBufferAttribute(e){return e.isInterleavedBufferAttribute&&(e=e.data),e}}let fx=new gf,fT=new gb,f_=new gA;class fv{constructor(e){this.layoutGPU=e,this.usedTimes=0}}class fS{constructor(e){this.backend=e,this._bindGroupLayoutCache=new Map}createBindingsLayout(e){let t=this.backend,r=t.device,i=t.get(e);if(i.layout)return i.layout.layoutGPU;let s=this._createLayoutEntries(e),n=x(JSON.stringify(s)),a=this._bindGroupLayoutCache.get(n);return void 0===a&&(a=new fv(r.createBindGroupLayout({entries:s})),this._bindGroupLayoutCache.set(n,a)),a.usedTimes++,i.layout=a,i.layoutKey=n,a.layoutGPU}createBindings(e,t,r,i=0){let s,{backend:n}=this,a=n.get(e),o=this.createBindingsLayout(e);""!==r&&(void 0===a.groups&&(a.groups={},a.versions={}),a.versions[r]===i&&(s=a.groups[r])),void 0===s&&(s=this.createBindGroup(e,o),""!==r&&(a.groups[r]=s,a.versions[r]=i)),a.group=s}updateBinding(e){let t=this.backend,r=t.device,i=e.buffer,s=t.get(e).buffer,n=e.updateRanges;if(0===n.length)r.queue.writeBuffer(s,0,i,0);else{let e=(0,u.iu4)(i),t=e?1:i.BYTES_PER_ELEMENT,a=n[0].start;for(let o=0,l=n.length;o<l;o++){let l=n[o],u=n[o+1],d=l.start+l.count;if(void 0!==u&&u.start===d)continue;let h=a*t,c=(d-a)*t,p=h*(e?i.BYTES_PER_ELEMENT:1);r.queue.writeBuffer(s,p,i,h,c),void 0!==u&&(a=u.start)}}}createBindGroupIndex(e,t){let r=this.backend.device,i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,s=e[0];fT.label="bindingCameraIndex_"+s,fT.size=16,fT.usage=i;let n=r.createBuffer(fT);fT.reset(),r.queue.writeBuffer(n,0,e,0),fx.label="bindGroupCameraIndex_"+s,fx.layout=t,fx.entries.push({binding:0,resource:{buffer:n}});let a=r.createBindGroup(fx);return fx.reset(),a}createBindGroup(e,t){let r=this.backend,i=r.device,s=0;for(let n of(fx.label="bindGroup_"+e.name,fx.layout=t,e.bindings)){if(n.isUniformBuffer){let e=r.get(n);fx.entries.push({binding:s,resource:{buffer:e.buffer}})}else if(n.isStorageBuffer){let e=r.get(n.attribute).buffer;fx.entries.push({binding:s,resource:{buffer:e}})}else if(n.isSampledTexture){let e,t=r.get(n.texture);if(void 0!==t.externalTexture)e=i.importExternalTexture({source:t.externalTexture});else{let r=n.store?1:t.texture.mipLevelCount,i=n.store?n.mipLevel:0,s=`view-${t.texture.width}-${t.texture.height}`;if(t.texture.depthOrArrayLayers>1&&(s+=`-${t.texture.depthOrArrayLayers}`),s+=`-${r}-${i}`,void 0===(e=t[s])){let a,o=gn.All;a=n.isSampledCubeTexture?gs.Cube:n.texture.isArrayTexture||n.texture.isDataArrayTexture||n.texture.isCompressedArrayTexture?gs.TwoDArray:n.isSampledTexture3D?gs.ThreeD:gs.TwoD,f_.aspect=o,f_.dimension=a,f_.mipLevelCount=r,f_.baseMipLevel=i,e=t[s]=t.texture.createView(f_),f_.reset()}}fx.entries.push({binding:s,resource:e})}else if(n.isSampler){let e=r.get(n);fx.entries.push({binding:s,resource:e.sampler})}s++}let n=i.createBindGroup(fx);return fx.reset(),n}_createLayoutEntries(e){let t=[],r=0;for(let i of e.bindings){let e=this.backend,s={binding:r,visibility:i.visibility};if(i.isUniformBuffer||i.isStorageBuffer){let e={};i.isStorageBuffer&&(i.visibility&mK.COMPUTE?i.access===M.READ_WRITE||i.access===M.WRITE_ONLY?e.type=m7.Storage:e.type=m7.ReadOnlyStorage:i.nodeUniform&&i.nodeUniform.isAtomic&&i.visibility&mK.FRAGMENT?e.type=m7.Storage:e.type=m7.ReadOnlyStorage),s.buffer=e}else if(i.isSampledTexture&&i.store){let e={};e.format=this.backend.get(i.texture).texture.format;let t=i.access;t===M.READ_WRITE?e.access=ge.ReadWrite:t===M.WRITE_ONLY?e.access=ge.WriteOnly:e.access=ge.ReadOnly,i.texture.isArrayTexture?e.viewDimension=gs.TwoDArray:i.texture.is3DTexture&&(e.viewDimension=gs.ThreeD),s.storageTexture=e}else if(i.isSampledTexture){let t={},{primarySamples:r}=e.utils.getTextureSampleData(i.texture);if(r>1&&(t.multisampled=!0,i.texture.isDepthTexture||(t.sampleType=gr.UnfilterableFloat)),i.texture.isDepthTexture)e.compatibilityMode&&null===i.texture.compareFunction?t.sampleType=gr.UnfilterableFloat:t.sampleType=gr.Depth;else{let e=i.texture.type;e===u.Yuy?t.sampleType=gr.SInt:e===u.bkx?t.sampleType=gr.UInt:!0===i.texture.normalized&&(e===u.fBL||e===u.cHt)?t.sampleType=gr.UnfilterableFloat:e===u.RQf&&(this.backend.hasFeature("float32-filterable")?t.sampleType=gr.Float:t.sampleType=gr.UnfilterableFloat)}i.isSampledCubeTexture?t.viewDimension=gs.Cube:i.texture.isArrayTexture||i.texture.isDataArrayTexture||i.texture.isCompressedArrayTexture?t.viewDimension=gs.TwoDArray:i.isSampledTexture3D&&(t.viewDimension=gs.ThreeD),s.texture=t}else if(i.isSampler){let t={};i.texture.isDepthTexture&&(null!==i.texture.compareFunction&&i.textureNode.isSampleCompare()&&e.hasCompatibility(u.x$Y.TEXTURE_COMPARE)?t.type=gt.Comparison:t.type=gt.NonFiltering),s.sampler=t}else(0,u.z3S)(`WebGPUBindingUtils: Unsupported binding "${i}".`);t.push(s),r++}return t}deleteBindGroupData(e){let{backend:t}=this,r=t.get(e);r.layout&&(r.layout.usedTimes--,0===r.layout.usedTimes&&this._bindGroupLayoutCache.delete(r.layoutKey),r.layout=void 0,r.layoutKey=void 0)}dispose(){this._bindGroupLayoutCache.clear()}}class fR{constructor(e){this.backend=e}getMaxAnisotropy(){return 16}getUniformBufferLimit(){return this.backend.device.limits.maxUniformBufferBindingSize}}class fN{constructor(){this.label="",this.layout=null,this.compute=null}reset(){this.label="",this.layout=null,this.compute=null}}class fA{constructor(){this.label="",this.bindGroupLayouts=null}reset(){this.label="",this.bindGroupLayouts=null}}let fE=new fN,fC=new fA,fw=new gx,fB=new gv;class fM{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){let r,{object:i,material:s,geometry:n,pipeline:a}=e,{vertexProgram:o,fragmentProgram:l}=a,d=this.backend,h=d.device,c=d.utils,p=d.get(a),m=[];for(let t of e.getBindings()){let{layoutGPU:e}=d.get(t).layout;m.push(e)}let g=d.attributeUtils.createShaderVertexBuffers(e);s.blending!==u.XIg&&(s.blending!==u.NTi||!1!==s.transparent)&&(r=this._getBlending(s));let f={};!0===s.stencilWrite&&(f={compare:this._getStencilCompare(s),failOp:this._getStencilOperation(s.stencilFail),depthFailOp:this._getStencilOperation(s.stencilZFail),passOp:this._getStencilOperation(s.stencilZPass)});let b=this._getColorWriteMask(s),y=[];if(null!==e.context.textures){let t=e.context.textures,i=e.context.mrt;for(let e=0;e<t.length;e++){let s,n=t[e],a=c.getTextureFormatGPU(n);if(null!==i)if(!0!==this.backend.compatibilityMode){let e=i.getBlendMode(n.name);e.blending===u.pCc?s=r:e.blending!==u.XIg&&(s=this._getBlending(e))}else(0,u.mcG)("WebGPURenderer: Multiple Render Targets (MRT) blending configuration is not fully supported in compatibility mode. The material blending will be used for all render targets."),s=r;else s=r;y.push({format:a,blend:s,writeMask:b})}}else{let t=c.getCurrentColorFormat(e.context);y.push({format:t,blend:r,writeMask:b})}let x=d.get(o).module,T=d.get(l).module,_=this._getPrimitiveState(i,n,s),v=this._getDepthCompare(s),S=c.getCurrentDepthStencilFormat(e.context),R=this._getSampleCount(e.context);fC.bindGroupLayouts=m;let N=h.createPipelineLayout(fC);fC.reset(),fB.label=`renderPipeline_${s.name||s.type}_${s.id}`,fB.vertex=Object.assign({},x,{buffers:g}),fB.fragment=Object.assign({},T,{targets:y}),fB.primitive=_,fB.multisample.count=R,fB.multisample.alphaToCoverageEnabled=s.alphaToCoverage&&R>1,fB.layout=N;let A={},E=e.context.depth,C=e.context.stencil;(!0===E||!0===C)&&(!0===E&&(A.format=S,A.depthWriteEnabled=s.depthWrite,A.depthCompare=v),!0===C&&(A.stencilFront=f,A.stencilBack=f,A.stencilReadMask=s.stencilFuncMask,A.stencilWriteMask=s.stencilWriteMask),!0===s.polygonOffset&&_.topology===mX.TriangleList&&(A.depthBias=s.polygonOffsetUnits,A.depthBiasSlopeScale=s.polygonOffsetFactor,A.depthBiasClamp=0),fB.depthStencil=A),h.pushErrorScope("validation");let w=[{program:o,module:x.module},{program:l,module:T.module}],B=fB.label;if(null===t)p.pipeline=h.createRenderPipeline(fB),fB.reset(),h.popErrorScope().then(e=>{null!==e&&(p.error=!0,(0,u.z3S)(`WebGPURenderer: Render pipeline creation failed (${B}): ${e.message}`),this._reportShaderDiagnostics(w,B))});else{let e=new Promise(async e=>{try{let e=null,t=null;try{t=h.createRenderPipelineAsync(fB)}catch(t){e=t}if(fB.reset(),null!==t)try{p.pipeline=await t}catch(t){e=t}let r=await h.popErrorScope();if(null!==r||null!==e){p.error=!0;let t=r&&r.message||e&&e.message||"unknown";(0,u.z3S)(`WebGPURenderer: Async render pipeline creation failed (${B}): ${t}`),await this._reportShaderDiagnostics(w,B)}}finally{e()}});t.push(e)}}createBundleEncoder(e,t="renderBundleEncoder"){let{utils:r,device:i}=this.backend,s=r.getCurrentDepthStencilFormat(e),n=r.getCurrentColorFormats(e),a=this._getSampleCount(e);fw.label=t,fw.colorFormats=n,fw.depthStencilFormat=s,fw.sampleCount=a;let o=i.createRenderBundleEncoder(fw);return fw.reset(),o}createComputePipeline(e,t,r=null){let i=this.backend,s=i.device,n=i.get(e.computeProgram).module,a=i.get(e),o=[];for(let e of t){let{layoutGPU:t}=i.get(e).layout;o.push(t)}let l=e.computeProgram,d=`computePipeline_${l.stage}${l.name?`_${l.name}`:""}`;s.pushErrorScope("validation"),fC.bindGroupLayouts=o;let h=s.createPipelineLayout(fC);if(fC.reset(),fE.label=d,fE.compute=n,fE.layout=h,null===r)a.pipeline=s.createComputePipeline(fE),fE.reset(),s.popErrorScope().then(e=>{null!==e&&(a.error=!0,(0,u.z3S)(`WebGPURenderer: Compute pipeline creation failed (${d}): ${e.message}`),this._reportShaderDiagnostics([{program:l,module:n.module}],d))});else{let e=new Promise(async e=>{try{let e=null,t=null;try{t=s.createComputePipelineAsync(fE)}catch(t){e=t}if(fE.reset(),null!==t)try{a.pipeline=await t}catch(t){e=t}let r=await s.popErrorScope();if(null!==r||null!==e){a.error=!0;let t=r&&r.message||e&&e.message||"unknown";(0,u.z3S)(`WebGPURenderer: Async compute pipeline creation failed (${d}): ${t}`),await this._reportShaderDiagnostics([{program:l,module:n.module}],d)}}finally{e()}});r.push(e)}}async _reportShaderDiagnostics(e,t){for(let{program:r,module:i}of e){let e=await i.getCompilationInfo();if(0===e.messages.length)continue;let s=r.code.split("\n");for(let i of e.messages){let e=i.lineNum>0?` at line ${i.lineNum}${i.linePos>0?`:${i.linePos}`:""}`:"",n=`WebGPURenderer [${t} / ${r.stage} ${i.type}]${e}: ${i.message}`,a="";i.lineNum>0&&i.lineNum<=s.length&&(a=`
|
|
484
|
+
${s[i.lineNum-1]}`,i.linePos>0&&(a+=`
|
|
485
|
+
${" ".repeat(i.linePos-1)}^`)),("error"===i.type?u.z3S:u.R8M)(n+a)}}}_getBlending(e){let t,r,i=e.blending,s=e.blendSrc,n=e.blendDst,a=e.blendEquation;if(i===u.bCz){let i=null!==e.blendSrcAlpha?e.blendSrcAlpha:s,o=null!==e.blendDstAlpha?e.blendDstAlpha:n,l=null!==e.blendEquationAlpha?e.blendEquationAlpha:a;t={srcFactor:this._getBlendFactor(s),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(a)},r={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(o),operation:this._getBlendOperation(l)}}else{let s=e.premultipliedAlpha,n=(e,i,s,n)=>{t={srcFactor:e,dstFactor:i,operation:m5.Add},r={srcFactor:s,dstFactor:n,operation:m5.Add}};if(s)switch(i){case u.NTi:n(m8.One,m8.OneMinusSrcAlpha,m8.One,m8.OneMinusSrcAlpha);break;case u.EZo:n(m8.One,m8.One,m8.One,m8.One);break;case u.Kwu:n(m8.Zero,m8.OneMinusSrc,m8.Zero,m8.One);break;case u.EdD:n(m8.Dst,m8.OneMinusSrcAlpha,m8.Zero,m8.One)}else switch(i){case u.NTi:n(m8.SrcAlpha,m8.OneMinusSrcAlpha,m8.One,m8.OneMinusSrcAlpha);break;case u.EZo:n(m8.SrcAlpha,m8.One,m8.One,m8.One);break;case u.Kwu:(0,u.z3S)(`WebGPURenderer: "SubtractiveBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`);break;case u.EdD:(0,u.z3S)(`WebGPURenderer: "MultiplyBlending" requires "${e.isMaterial?"material":"blendMode"}.premultipliedAlpha = true".`)}}if(void 0!==t&&void 0!==r)return{color:t,alpha:r};(0,u.z3S)("WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(e){let t;switch(e){case u.ojh:t=m8.Zero;break;case u.qad:t=m8.One;break;case u.f4X:t=m8.Src;break;case u.LiQ:t=m8.OneMinusSrc;break;case u.ie2:t=m8.SrcAlpha;break;case u.OuU:t=m8.OneMinusSrcAlpha;break;case u.wn6:t=m8.Dst;break;case u.aEY:t=m8.OneMinusDst;break;case u.hdd:t=m8.DstAlpha;break;case u.Nt7:t=m8.OneMinusDstAlpha;break;case u.hgQ:t=m8.SrcAlphaSaturated;break;case u.RrE:case u.e0p:t=m8.Constant;break;case u.$Yl:case u.ov9:t=m8.OneMinusConstant;break;default:(0,u.z3S)("WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t,r=e.stencilFunc;switch(r){case u.HPb:t=mQ.Never;break;case u.sKt:t=mQ.Always;break;case u.kYr:t=mQ.Less;break;case u.CR7:t=mQ.LessEqual;break;case u.jsO:t=mQ.Equal;break;case u.TMh:t=mQ.GreaterEqual;break;case u.RcT:t=mQ.Greater;break;case u.klZ:t=mQ.NotEqual;break;default:(0,u.z3S)("WebGPURenderer: Invalid stencil function.",r)}return t}_getStencilOperation(e){let t;switch(e){case u.VVr:t=m9.Keep;break;case u.kqe:t=m9.Zero;break;case u.kG0:t=m9.Replace;break;case u.oVO:t=m9.Invert;break;case u.HLH:t=m9.IncrementClamp;break;case u.ROr:t=m9.DecrementClamp;break;case u.Ru$:t=m9.IncrementWrap;break;case u.fJr:t=m9.DecrementWrap;break;default:(0,u.z3S)("WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case u.gO9:t=m5.Add;break;case u.FXf:t=m5.Subtract;break;case u.nST:t=m5.ReverseSubtract;break;case u.znC:t=m5.Min;break;case u.$ei:t=m5.Max;break;default:(0,u.z3S)("WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,r){let i={};i.topology=this.backend.utils.getPrimitiveTopology(e,r),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(i.stripIndexFormat=t.index.array instanceof Uint16Array?m1.Uint16:m1.Uint32);let s=r.side===u.hsX;return e.isMesh&&0>e.matrixWorld.determinantAffine()&&(s=!s),i.frontFace=!0===s?mJ.CW:mJ.CCW,i.cullMode=r.side===u.$EB?m0.None:m0.Back,i}_getColorWriteMask(e){return!0===e.colorWrite?m6.All:m6.None}_getDepthCompare(e){let t;if(!1===e.depthTest)t=mQ.Always;else{let r=this.backend.parameters.reversedDepthBuffer?u.ri6[e.depthFunc]:e.depthFunc;switch(r){case u.eHc:t=mQ.Never;break;case u.lGu:t=mQ.Always;break;case u.brA:t=mQ.Less;break;case u.xSv:t=mQ.LessEqual;break;case u.U3G:t=mQ.Equal;break;case u.Gwm:t=mQ.GreaterEqual;break;case u.K52:t=mQ.Greater;break;case u.bw0:t=mQ.NotEqual;break;default:(0,u.z3S)("WebGPUPipelineUtils: Invalid depth function.",r)}}return t}}class fF{constructor(){this.label="",this.type=void 0,this.count=0}reset(){this.label="",this.type=void 0,this.count=0}}let fL=new gb,fU=new gy,fP=new fF;class fD extends mW{constructor(e,t,r=2048){super(r),this.device=e,this.type=t,fP.label=`queryset_global_timestamp_${t}`,fP.type="timestamp",fP.count=this.maxQueries,this.querySet=this.device.createQuerySet(fP),fP.reset();let i=8*this.maxQueries;fL.label=`buffer_timestamp_resolve_${t}`,fL.size=i,fL.usage=GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC,this.resolveBuffer=this.device.createBuffer(fL),fL.reset(),fL.label=`buffer_timestamp_result_${t}`,fL.size=i,fL.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ,this.resultBuffer=this.device.createBuffer(fL),fL.reset()}allocateQueriesForContext(e){if(!this.trackTimestamp||this.isDisposed)return null;this.currentQueryIndex+2>this.maxQueries&&(this.resolveQueriesAsync(),this.currentQueryIndex=0,this.queryOffsets.clear());let t=this.currentQueryIndex;return this.currentQueryIndex+=2,this.queryOffsets.set(e,t),t}async resolveQueriesAsync(){if(!this.trackTimestamp||0===this.currentQueryIndex||this.isDisposed)return this.lastValue;if(this.pendingResolve)return this.pendingResolve;this.pendingResolve=this._resolveQueries();try{return await this.pendingResolve}finally{this.pendingResolve=null}}async _resolveQueries(){if(this.isDisposed)return this.lastValue;try{if("unmapped"!==this.resultBuffer.mapState)return this.lastValue;let e=new Map(this.queryOffsets),t=this.currentQueryIndex,r=8*t;this.currentQueryIndex=0,this.queryOffsets.clear();let i=this.device.createCommandEncoder(fU);i.resolveQuerySet(this.querySet,0,t,this.resolveBuffer,0),i.copyBufferToBuffer(this.resolveBuffer,0,this.resultBuffer,0,r);let s=i.finish();if(gg(this.device,s),"unmapped"!==this.resultBuffer.mapState)return this.lastValue;if(await this.resultBuffer.mapAsync(GPUMapMode.READ,0,r),this.isDisposed)return"mapped"===this.resultBuffer.mapState&&this.resultBuffer.unmap(),this.lastValue;let n=new BigUint64Array(this.resultBuffer.getMappedRange(0,r)),a={},o=[];for(let[t,r]of(this.timestamps.clear(),e)){let e=t.match(/^(.*):f(\d+)$/),i=parseInt(e[2]);!1===o.includes(i)&&o.push(i),void 0===a[i]&&(a[i]=0);let s=n[r],l=n[r+1],u=Number(l-s)/1e6;this.timestamps.set(t,u),a[i]+=u}let l=a[o[o.length-1]];return this.resultBuffer.unmap(),this.lastValue=l,this.frames=o,l}catch(e){return(0,u.z3S)("Error resolving queries:",e),"mapped"===this.resultBuffer.mapState&&this.resultBuffer.unmap(),this.lastValue}}async dispose(){if(!this.isDisposed){if(this.isDisposed=!0,this.pendingResolve)try{await this.pendingResolve}catch(e){(0,u.z3S)("Error waiting for pending resolve:",e)}if(this.resultBuffer&&"mapped"===this.resultBuffer.mapState)try{this.resultBuffer.unmap()}catch(e){(0,u.z3S)("Error unmapping buffer:",e)}this.querySet&&(this.querySet.destroy(),this.querySet=null),this.resolveBuffer&&(this.resolveBuffer.destroy(),this.resolveBuffer=null),this.resultBuffer&&(this.resultBuffer.destroy(),this.resultBuffer=null),this.queryOffsets.clear(),this.timestamps.clear(),this.frames=[],this.pendingResolve=null}}}class fO{constructor(){this.label="",this.timestampWrites=void 0}reset(){this.label="",this.timestampWrites=void 0}}class fI{constructor(){this.view=null,this.depthLoadOp=void 0,this.depthStoreOp=void 0,this.depthClearValue=void 0,this.depthReadOnly=!1,this.stencilLoadOp=void 0,this.stencilStoreOp=void 0,this.stencilClearValue=0,this.stencilReadOnly=!1}reset(){this.view=null,this.depthLoadOp=void 0,this.depthStoreOp=void 0,this.depthClearValue=void 0,this.depthReadOnly=!1,this.stencilLoadOp=void 0,this.stencilStoreOp=void 0,this.stencilClearValue=0,this.stencilReadOnly=!1}}class fV{constructor(){this.querySet=null,this.beginningOfPassWriteIndex=void 0,this.endOfPassWriteIndex=void 0}reset(){this.querySet=null,this.beginningOfPassWriteIndex=void 0,this.endOfPassWriteIndex=void 0}}let fG={r:0,g:0,b:0,a:1},fk={r:0,g:0,b:0,a:0},fz=new gb,f$=new gy,fW=new fO,fH=new fF,fq=new gR,fj=new fV,fX=new gV,fK=new gV,fQ=new gN,fY=new gA,fZ=new gW;class fJ extends mC{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.compatibilityMode=null,this.device=null,this.defaultRenderPassdescriptor=null,this.utils=new gm(this),this.attributeUtils=new fy(this),this.bindingUtils=new fS(this),this.capabilities=new fR(this),this.pipelineUtils=new fM(this),this.textureUtils=new g4(this),this.occludedResolveCache=new Map;let t="undefined"==typeof navigator||!1===/Android/.test(navigator.userAgent);this._compatibility={[u.x$Y.TEXTURE_COMPARE]:t}}async init(e){let t;await super.init(e);let r=this.parameters;if(void 0===r.device){let i={powerPreference:r.powerPreference,featureLevel:"compatibility",xrCompatible:e.xr.enabled},s="undefined"!=typeof navigator?await navigator.gpu.requestAdapter(i):null;if(null===s)throw Error("THREE.WebGPUBackend: Unable to create WebGPU adapter.");let n=Object.values(go),a=[];for(let e of n)s.features.has(e)&&a.push(e);let o={requiredFeatures:a,requiredLimits:r.requiredLimits};t=await s.requestDevice(o)}else t=r.device;this.compatibilityMode=!t.features.has("core-features-and-limits"),this.compatibilityMode&&(e._samples=0),t.lost.then(t=>{if("destroyed"===t.reason)return;let r={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(r)}),t.onuncapturederror=t=>{let r=t.error,i=r&&r.constructor?r.constructor.name:"GPUError",s=r&&r.message||"Unknown uncaptured GPU error";e.onError({api:"WebGPU",type:i,message:s,originalEvent:t})},this.device=t,this.trackTimestamp=this.trackTimestamp&&this.hasFeature(go.TimestampQuery),this.updateSize()}setXRRenderTargetTextures(e,t,r=null){let i=this.get(e.texture);i.texture=t,i.format=t.format,i.externalTexture=!0,i.xrViewDescriptors=r,i.initialized=!0}get context(){let e=this.renderer.getCanvasTarget(),t=this.get(e),r=t.context;if(void 0===r){let i=this.parameters;r=!0===e.isDefaultCanvasTarget&&void 0!==i.context?i.context:e.domElement.getContext("webgpu"),"setAttribute"in e.domElement&&e.domElement.setAttribute("data-engine",`three.js r${u.sPf} webgpu`);let s=i.alpha?"premultiplied":"opaque",n=i.outputType===u.ix0?"extended":"standard";r.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:s,toneMapping:{mode:n}}),t.context=r}return r}get coordinateSystem(){return u.i7u}get hasTimestamp(){return!0}async getArrayBufferAsync(e,t=null,r=0,i=-1){return await this.attributeUtils.getArrayBufferAsync(e,t,r,i)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.renderer,t=e.getCanvasTarget(),r=this.get(t),i=e.currentSamples,s=r.descriptor;if(void 0===s||r.samples!==i){if((s=new g_).colorAttachments.push(new gT),!0===e.depth||!0===e.stencil){let t=new fI;t.view=this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView(),s.depthStencilAttachment=t}let t=s.colorAttachments[0];i>0?t.view=this.textureUtils.getColorBuffer().createView():t.resolveTarget=void 0,r.descriptor=s,r.samples=i}let n=s.colorAttachments[0];return i>0?n.resolveTarget=this.context.getCurrentTexture().createView():n.view=this.context.getCurrentTexture().createView(),s}_isRenderCameraDepthArray(e){let t=e.camera;return e.depthTexture&&!0===e.depthTexture.isArrayTexture&&null!==t&&!0===t.isArrayCamera}_hasExternalTexture(e){let t=e.textures;if(null===t)return!1;for(let e=0;e<t.length;e++)if(!0===this.get(t[e]).externalTexture)return!0;return!1}_getExternalMSAATextures(e,t,r){let i=this.utils.getSampleCount(e.sampleCount);if(1===i){if(void 0!==t.msaaTextures){for(let e of t.msaaTextures)e.destroy();t.msaaTextures=void 0}return null}let s=e.renderTarget,n=s.width,a=s.height,o=t.format;if(void 0===t.msaaTextures||t.msaaTextures.length!==r||t.msaaWidth!==n||t.msaaHeight!==a||t.msaaSamples!==i||t.msaaFormat!==o){if(void 0!==t.msaaTextures)for(let e of t.msaaTextures)e.destroy();fQ.size.width=n,fQ.size.height=a,fQ.sampleCount=i,fQ.format=o,fQ.usage=GPUTextureUsage.RENDER_ATTACHMENT,t.msaaTextures=[];for(let e=0;e<r;e++)fQ.label=s.texture.name+"-msaa-"+e,t.msaaTextures.push(this.device.createTexture(fQ));fQ.reset(),t.msaaWidth=n,t.msaaHeight=a,t.msaaSamples=i,t.msaaFormat=o}return t.msaaTextures}_createExternalTextureViews(e,t){let r=[],i=e.camera,s=t.xrViewDescriptors,n=Math.max(s?.length||0,e.activeCubeFace+1,1),a=this._getExternalMSAATextures(e,t,n);if(s&&null!==i&&!0===i.isArrayCamera)for(let i=0;i<s.length;i++){let n=t.texture.createView(s[i]);r.push({view:null!==a?a[i].createView():n,resolveTarget:null!==a&&!0===e.renderTarget.resolveColorBuffer?n:void 0,depthSlice:void 0})}else{let i=e.activeCubeFace,s=t.texture.createView({dimension:gs.TwoD,baseArrayLayer:i,arrayLayerCount:1});r.push({view:null!==a?a[i].createView():s,resolveTarget:null!==a&&!0===e.renderTarget.resolveColorBuffer?s:void 0,depthSlice:void 0})}return r}_getRenderPassDescriptor(e,t={}){let r=e.renderTarget,i=this.get(r),s=this._hasExternalTexture(e),n=i.descriptors;(void 0===n||i.width!==r.width||i.height!==r.height||i.samples!==r.samples||s)&&(i.descriptors=n={});let a=e.getCacheKey(),o=n[a];if(void 0===o||s){let t,s=e.textures,l=[],u=this._isRenderCameraDepthArray(e);for(let i=0;i<s.length;i++){let n=this.get(s[i]);if(!0===n.externalTexture){l.push(...this._createExternalTextureViews(e,n));continue}if(fY.label=`colorAttachment_${i}`,fY.baseMipLevel=e.activeMipmapLevel,fY.mipLevelCount=1,fY.baseArrayLayer=e.activeCubeFace,fY.arrayLayerCount=1,fY.dimension=gs.TwoD,r.isRenderTarget3D)t=e.activeCubeFace,fY.baseArrayLayer=0,fY.dimension=gs.ThreeD;else if(r.isRenderTarget&&s[i].image.depth>1)if(!0===u){let t=e.camera.cameras;for(let e=0;e<t.length;e++){fY.baseArrayLayer=e,fY.arrayLayerCount=1,fY.dimension=gs.TwoD;let t=n.texture.createView(fY),i=n.msaaTextures?.[e];l.push({view:void 0!==i?i.createView():t,resolveTarget:void 0!==i&&!0===r.resolveColorBuffer?t:void 0,depthSlice:void 0})}}else fY.dimension=gs.TwoDArray;if(!0!==u){let i,s,a=n.texture.createView(fY);void 0!==n.msaaTexture?(i=n.msaaTexture.createView(),s=!0===r.resolveColorBuffer?a:void 0):void 0!==n.msaaTextures?(i=n.msaaTextures[e.activeCubeFace].createView(),s=!0===r.resolveColorBuffer?a:void 0):(i=a,s=void 0),l.push({view:i,resolveTarget:s,depthSlice:t})}fY.reset()}let d=[];for(let e=0;e<l.length;e++){let t=l[e],r=new gT;r.view=t.view,r.depthSlice=t.depthSlice,r.resolveTarget=t.resolveTarget,d.push(r)}if(o={textureViews:l,colorAttachments:d,descriptor:new g_},e.depth){let t=this.get(e.depthTexture);(e.depthTexture.isArrayTexture||e.depthTexture.isCubeTexture)&&(fY.dimension=gs.TwoD,fY.arrayLayerCount=1,fY.baseArrayLayer=e.activeCubeFace);let r=new fI,i=t.msaaTextures?.[e.activeCubeFace];r.view=void 0!==i?i.createView():t.texture.createView(fY),o.depthStencilAttachment=r,fY.reset()}n[a]=o,i.width=r.width,i.height=r.height,i.samples=r.samples,i.activeMipmapLevel=e.activeMipmapLevel,i.activeCubeFace=e.activeCubeFace}let l=o.descriptor;l.reset();for(let e=0;e<o.colorAttachments.length;e++){let r=o.colorAttachments[e],i={r:0,g:0,b:0,a:1};0===e&&t.clearValue&&(i=t.clearValue),r.loadOp=t.loadOp||mZ.Load,r.storeOp=t.storeOp||mY.Store,r.clearValue=i,l.colorAttachments.push(r)}return o.depthStencilAttachment&&(l.depthStencilAttachment=o.depthStencilAttachment),l}beginRender(e){let t,r,i=this.get(e),s=this.device,n=e.occlusionQueryCount;n>0?(i.currentOcclusionQuerySet&&i.currentOcclusionQuerySet.destroy(),i.currentOcclusionQueryBuffer&&i.currentOcclusionQueryBuffer.destroy(),i.currentOcclusionQuerySet=i.occlusionQuerySet,i.currentOcclusionQueryBuffer=i.occlusionQueryBuffer,i.currentOcclusionQueryObjects=i.occlusionQueryObjects,fH.label=`occlusionQuerySet_${e.id}`,fH.type="occlusion",fH.count=n,t=s.createQuerySet(fH),fH.reset(),i.occlusionQuerySet=t,i.occlusionQueryIndex=0,i.occlusionQueryObjects=Array(n),i.lastOcclusionObject=null):void 0!==i.lastOcclusionObject&&(i.lastOcclusionObject=void 0,i.occlusionQuerySet.destroy(),i.occlusionQuerySet=void 0),r=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e,{loadOp:mZ.Load}),this.initTimestampQuery(u.v9J.RENDER,this.getTimestampUID(e),r),r.occlusionQuerySet=t;let a=r.depthStencilAttachment,o=e.renderTarget,l=e.sampleCount>1&&o?.storeMultisampledColorBuffer===!1,d=e.sampleCount>1&&o?.storeMultisampledDepthBuffer===!1,h=e.sampleCount>1&&o?.storeMultisampledStencilBuffer===!1,c=!0===e.fullscreenPass&&this._hasExternalTexture(e);if(null!==e.textures){let t=r.colorAttachments;for(let r=0;r<t.length;r++){let i=t[r];if(e.clearColor||l||c){let t=e.mrt?e.mrt.getClearColor(e.textures[r].name):null;null!==t?i.clearValue=t:0===r?i.clearValue=e.clearColorValue:(fG.r=0,fG.g=0,fG.b=0,fG.a=1,i.clearValue=fG),i.loadOp=mZ.Clear}else i.loadOp=mZ.Load;l?i.storeOp=mY.Discard:i.storeOp=mY.Store}}else{let t=r.colorAttachments[0];e.clearColor?(t.clearValue=e.clearColorValue,t.loadOp=mZ.Clear):t.loadOp=mZ.Load,t.storeOp=mY.Store}e.depth&&(e.clearDepth||d?(a.depthClearValue=e.clearDepthValue,a.depthLoadOp=mZ.Clear):a.depthLoadOp=mZ.Load,d?a.depthStoreOp=mY.Discard:a.depthStoreOp=mY.Store),e.stencil&&(e.clearStencil||h?(a.stencilClearValue=e.clearStencilValue,a.stencilLoadOp=mZ.Clear):a.stencilLoadOp=mZ.Load,h?a.stencilStoreOp=mY.Discard:a.stencilStoreOp=mY.Store),f$.label="renderContext_"+e.id;let p=s.createCommandEncoder(f$);if(f$.reset(),!0===this._isRenderCameraDepthArray(e)){let t=e.camera.cameras;i.layerDescriptors&&i.layerDescriptors.length===t.length?this._updateArrayCameraLayerDescriptors(e,i,r,t):this._createArrayCameraLayerDescriptors(e,i,r,t),this._createArrayCameraBundleEncoders(e,i),i.arrayCameraRenderStages=[],i.currentPass=null}else i.bundleEncoders=void 0,i.bundleSets=void 0,i.arrayCameraRenderStages=void 0,i.currentPass=p.beginRenderPass(r),e.viewport&&this.updateViewport(e),e.scissor&&this.updateScissor(e);i.descriptor=r,i.encoder=p,i.renderBundles=[],this._resetRenderContextData(i)}_resetRenderContextData(e){e.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},void 0===e.currentBlendColor&&(e.currentBlendColor=new u.Q1f),e.currentBlendColor.setRGB(0,0,0),e.currentBlendAlpha=0,e.currentStencilRef=0}_createArrayCameraBundleEncoders(e,t){let r=e.camera.cameras;t.bundleEncoders=[],t.bundleSets=[];for(let i=0;i<r.length;i++){let r=this.pipelineUtils.createBundleEncoder(e,"renderBundleArrayCamera_"+i),s={attributes:{},bindingGroups:[],pipeline:null,index:null};t.bundleEncoders.push(r),t.bundleSets.push(s)}}_finishArrayCameraBundleEncoders(e){let t=[];for(let r of e.bundleEncoders)t.push(r.finish());return t}_createArrayCameraLayerDescriptors(e,t,r,i){let s=r.depthStencilAttachment;t.layerDescriptors=[];let n=this.get(e.depthTexture);n.viewCache||(n.viewCache=[]);for(let a=0;a<i.length;a++){let i=r.colorAttachments[0],o=r.colorAttachments[a],l=new gT;l.view=o.view,l.depthSlice=o.depthSlice,l.resolveTarget=o.resolveTarget,l.loadOp=i.loadOp,l.storeOp=i.storeOp,l.clearValue=i.clearValue;let u=new g_;if(u.label=r.label,u.occlusionQuerySet=r.occlusionQuerySet,u.timestampWrites=r.timestampWrites,u.colorAttachments.push(l),r.depthStencilAttachment){let t=a;if(!n.viewCache[t]){let e=n.msaaTextures?.[t];void 0!==e?n.viewCache[t]=e.createView():(fY.dimension=gs.TwoD,fY.baseArrayLayer=a,fY.arrayLayerCount=1,n.viewCache[t]=n.texture.createView(fY)),fY.reset()}let r=new fI;r.view=n.viewCache[t],r.depthLoadOp=s.depthLoadOp||mZ.Clear,r.depthStoreOp=s.depthStoreOp||mY.Store,r.depthClearValue=s.depthClearValue||1,e.stencil&&(r.stencilLoadOp=s.stencilLoadOp,r.stencilStoreOp=s.stencilStoreOp,r.stencilClearValue=s.stencilClearValue),u.depthStencilAttachment=r}else{let e=new fI;e.view=s.view,e.depthLoadOp=s.depthLoadOp,e.depthStoreOp=s.depthStoreOp,e.depthClearValue=s.depthClearValue,e.depthReadOnly=s.depthReadOnly,e.stencilLoadOp=s.stencilLoadOp,e.stencilStoreOp=s.stencilStoreOp,e.stencilClearValue=s.stencilClearValue,e.stencilReadOnly=s.stencilReadOnly,u.depthStencilAttachment=e}t.layerDescriptors.push(u)}}_updateArrayCameraLayerDescriptors(e,t,r,i){let s=e.renderTarget,n=e.sampleCount>1&&s?.storeMultisampledDepthBuffer===!1,a=e.sampleCount>1&&s?.storeMultisampledStencilBuffer===!1;for(let s=0;s<i.length;s++){let i=t.layerDescriptors[s],o=r.colorAttachments[0],l=r.colorAttachments[s],u=i.colorAttachments[0];if(u.view=l.view,u.resolveTarget=l.resolveTarget,u.depthSlice=l.depthSlice,u.loadOp=o.loadOp,u.storeOp=o.storeOp,u.clearValue=o.clearValue,i.depthStencilAttachment){let t=i.depthStencilAttachment;e.depth&&(e.clearDepth||n?(t.depthClearValue=e.clearDepthValue,t.depthLoadOp=mZ.Clear):t.depthLoadOp=mZ.Load),e.stencil&&(e.clearStencil||a?(t.stencilClearValue=e.clearStencilValue,t.stencilLoadOp=mZ.Clear):t.stencilLoadOp=mZ.Load)}}}finishRender(e){let t=this.get(e),r=e.occlusionQueryCount;t.renderBundles.length>0&&t.currentPass.executeBundles(t.renderBundles);let i=t.lastOcclusionObject;i&&!0===i.occlusionTest&&t.currentPass.endOcclusionQuery();let s=t.encoder;if(!0===this._isRenderCameraDepthArray(e)){let r=this._finishArrayCameraBundleEncoders(t),i=t.arrayCameraRenderStages;i.push({bundles:r});for(let r=0;r<t.layerDescriptors.length;r++){let n=t.layerDescriptors[r],a=n.colorAttachments.map(e=>e.loadOp),o=n.colorAttachments.map(e=>e.storeOp),l=n.depthStencilAttachment?.depthLoadOp,u=n.depthStencilAttachment?.depthStoreOp,d=n.depthStencilAttachment?.stencilLoadOp,h=n.depthStencilAttachment?.stencilStoreOp;for(let t=0;t<i.length;t++){let c=i[t],p=c.bundles[r],m=t===i.length-1;for(let e=0;e<n.colorAttachments.length;e++){let r=n.colorAttachments[e];r.loadOp=0===t?a[e]:mZ.Load,r.storeOp=m?o[e]:mY.Store}e.depth&&(n.depthStencilAttachment.depthLoadOp=0===t?l:mZ.Load,n.depthStencilAttachment.depthStoreOp=m?u:mY.Store),e.stencil&&(n.depthStencilAttachment.stencilLoadOp=0===t?d:mZ.Load,n.depthStencilAttachment.stencilStoreOp=m?h:mY.Store);let g=s.beginRenderPass(n);if(e.viewport){let{x:t,y:r,width:i,height:s,minDepth:n,maxDepth:a}=e.viewportValue;g.setViewport(t,r,i,s,n,a)}if(e.scissor){let{x:t,y:r,width:i,height:s}=e.scissorValue;g.setScissorRect(t,r,i,s)}if(g.executeBundles([p]),g.end(),void 0!==c.framebufferCopy){let{texture:e,sourceGPU:t,destinationGPU:i,rectangle:n,generateMipmaps:a}=c.framebufferCopy;this._copyFramebufferToTexture(s,e,t,i,n,r,a)}}for(let e=0;e<n.colorAttachments.length;e++)n.colorAttachments[e].loadOp=a[e],n.colorAttachments[e].storeOp=o[e];e.depth&&(n.depthStencilAttachment.depthLoadOp=l,n.depthStencilAttachment.depthStoreOp=u),e.stencil&&(n.depthStencilAttachment.stencilLoadOp=d,n.depthStencilAttachment.stencilStoreOp=h)}}else t.currentPass&&t.currentPass.end();if(r>0){let i=8*r,s=this.occludedResolveCache.get(i);void 0===s&&(fz.size=i,fz.usage=GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC,s=this.device.createBuffer(fz),fz.reset(),this.occludedResolveCache.set(i,s)),fz.size=i,fz.usage=GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ;let n=this.device.createBuffer(fz);fz.reset(),t.encoder.resolveQuerySet(t.occlusionQuerySet,0,r,s,0),t.encoder.copyBufferToBuffer(s,0,n,0,i),t.occlusionQueryBuffer=n,this.resolveOccludedAsync(e)}if(gg(this.device,t.encoder.finish()),null!==e.textures){let t=e.textures;for(let e=0;e<t.length;e++){let r=t[e];!0===r.generateMipmaps&&this.textureUtils.generateMipmaps(r)}}}isOccluded(e,t){let r=this.get(e);return r.occluded&&r.occluded.has(t)}async resolveOccludedAsync(e){let t=this.get(e),{currentOcclusionQueryBuffer:r,currentOcclusionQueryObjects:i}=t;if(r&&i){let e=new WeakSet;t.currentOcclusionQueryObjects=null,t.currentOcclusionQueryBuffer=null,await r.mapAsync(GPUMapMode.READ);let s=new BigUint64Array(r.getMappedRange());for(let t=0;t<i.length;t++){let r=i[t];void 0!==r&&s[t]===BigInt(0)&&e.add(r)}r.destroy(),t.occluded=e}}updateViewport(e){let{currentPass:t}=this.get(e),{x:r,y:i,width:s,height:n,minDepth:a,maxDepth:o}=e.viewportValue;t.setViewport(r,i,s,n,a,o)}updateScissor(e){let{currentPass:t}=this.get(e),{x:r,y:i,width:s,height:n}=e.scissorValue;t.setScissorRect(r,i,s,n)}getClearColor(){let e=super.getClearColor();return!0===this.renderer.alpha&&(e.r*=e.a,e.g*=e.a,e.b*=e.a),e}clear(e,t,r,i=null){let s,n,a,o=this.device,l=this.renderer,u=[];if(e){let e=this.getClearColor();fG.r=e.r,fG.g=e.g,fG.b=e.b,fG.a=e.a}if(null===i){n=l.depth,a=l.stencil;let t=this._getDefaultRenderPassDescriptor();if(e){let e=(u=t.colorAttachments)[0];e.clearValue=fG,e.loadOp=mZ.Clear,e.storeOp=mY.Store}(n||a)&&(s=t.depthStencilAttachment)}else{n=i.depth,a=i.stencil;let o={loadOp:e?mZ.Clear:mZ.Load,clearValue:e?fG:void 0};n&&(o.depthLoadOp=t?mZ.Clear:mZ.Load,o.depthClearValue=t?l.getClearDepth():void 0,o.depthStoreOp=mY.Store),a&&(o.stencilLoadOp=r?mZ.Clear:mZ.Load,o.stencilClearValue=r?l.getClearStencil():void 0,o.stencilStoreOp=mY.Store);let d=this._getRenderPassDescriptor(i,o);u=d.colorAttachments,s=d.depthStencilAttachment}n&&s&&(t?(s.depthLoadOp=mZ.Clear,s.depthClearValue=l.getClearDepth()):s.depthLoadOp=mZ.Load,s.depthStoreOp=mY.Store),a&&s&&(r?(s.stencilLoadOp=mZ.Clear,s.stencilClearValue=l.getClearStencil()):s.stencilLoadOp=mZ.Load,s.stencilStoreOp=mY.Store),f$.label="clear";let d=o.createCommandEncoder(f$);f$.reset(),d.beginRenderPass({colorAttachments:u,depthStencilAttachment:s}).end(),gg(o,d.finish())}beginCompute(e){let t=this.get(e),r="computeGroup_"+e.id;fW.label=r,f$.label=r,this.initTimestampQuery(u.v9J.COMPUTE,this.getTimestampUID(e),fW),t.cmdEncoderGPU=this.device.createCommandEncoder(f$),t.passEncoderGPU=t.cmdEncoderGPU.beginComputePass(fW),t.currentPipeline=null,f$.reset(),fW.reset()}compute(e,t,r,i,s=null){let n=this.get(t),a=this.get(e),{passEncoderGPU:o}=a,l=this.get(i).pipeline;a.currentPipeline!==l&&(o.setPipeline(l),a.currentPipeline=l);for(let e=0,t=r.length;e<t;e++){let t=r[e],i=this.get(t);o.setBindGroup(e,i.group)}if(null===s&&(s=t.dispatchSize||t.count),s&&s.isIndirectStorageBufferAttribute){let e=this.get(s).buffer;o.dispatchWorkgroupsIndirect(e,0);return}if("number"==typeof s){let e=s;if(void 0===n.dispatchSize||n.count!==e){n.dispatchSize=[0,1,1],n.count=e;let r=t.workgroupSize,i=r[0];for(let e=1;e<r.length;e++)i*=r[e];let a=Math.ceil(e/i),o=this.device.limits.maxComputeWorkgroupsPerDimension;s=[a,1,1],a>o&&(s[0]=Math.min(a,o),s[1]=Math.ceil(a/o)),n.dispatchSize=s}s=n.dispatchSize}o.dispatchWorkgroups(s[0],s[1]||1,s[2]||1)}finishCompute(e){let t=this.get(e);t.passEncoderGPU.end(),gg(this.device,t.cmdEncoderGPU.finish())}_draw(e,t,r,i,s,n,a,o,l,d=-1){let{object:h,material:c,context:p}=e,m=e.getIndex(),g=null!==m;l.pipeline!==i&&(o.setPipeline(i),l.pipeline=i);let f=l.bindingGroups;for(let e=0,t=s.length;e<t;e++){if(e===d)continue;let t=s[e],r=this.get(t).group;f[e]!==r&&(o.setBindGroup(e,r),f[e]=r)}if(!0===g&&l.index!==m){let e=this.get(m).buffer,t=m.array instanceof Uint16Array?m1.Uint16:m1.Uint32;o.setIndexBuffer(e,t),l.index=m}for(let e=0,t=n.length;e<t;e++){let t=n[e];if(l.attributes[e]!==t){let r=this.get(t).buffer;o.setVertexBuffer(e,r),l.attributes[e]=t}}if(!0===p.stencil&&!0===c.stencilWrite&&r.currentStencilRef!==c.stencilRef&&(o.setStencilReference(c.stencilRef),r.currentStencilRef=c.stencilRef),c.blending===u.bCz&&void 0!==o.setBlendConstant){let e=c.blendColor,t=c.blendAlpha;(!1===e.equals(r.currentBlendColor)||t!==r.currentBlendAlpha)&&(fk.r=e.r,fk.g=e.g,fk.b=e.b,fk.a=t,o.setBlendConstant(fk),r.currentBlendColor.copy(e),r.currentBlendAlpha=t)}if(!0===h.isBatchedMesh){let e=h._multiDrawStarts,r=h._multiDrawCounts,i=h._multiDrawCount,s=h._multiDrawBytesPerElement;for(let n=0;n<i;n++)!0===g?o.drawIndexed(r[n],1,e[n]/s,0,n):o.draw(r[n],1,e[n],n),t.update(h,r[n],1)}else if(!0===g){let{vertexCount:r,instanceCount:i,firstVertex:s}=a,n=e.getIndirect();if(null!==n){let t=this.get(n).buffer,r=e.getIndirectOffset(),i=Array.isArray(r)?r:[r];for(let e=0;e<i.length;e++)o.drawIndexedIndirect(t,i[e])}else o.drawIndexed(r,i,s,0,0);t.update(h,r,i)}else{let{vertexCount:r,instanceCount:i,firstVertex:s}=a,n=e.getIndirect();if(null!==n){let t=this.get(n).buffer,r=e.getIndirectOffset(),i=Array.isArray(r)?r:[r];for(let e=0;e<i.length;e++)o.drawIndirect(t,i[e])}else o.draw(r,i,s,0);t.update(h,r,i)}}draw(e,t){let{object:r,context:i,pipeline:s}=e,n=this.get(i),a=this.get(s),o=a.pipeline;if(!0===a.error)return;let l=e.getDrawParameters();if(null===l)return;let d=e.getBindings(),h=e.getVertexBuffers();if(e.camera.isArrayCamera&&e.camera.cameras.length>0){let s=this.get(e.camera),a=e.camera.cameras,u=e.getBindingGroup("cameraIndex");if(void 0===s.indexesGPU||s.indexesGPU.length!==a.length){let e=this.get(u),t=[],r=new Uint32Array([0,0,0,0]);for(let i=0,s=a.length;i<s;i++){r[0]=i;let{layoutGPU:s}=e.layout,n=this.bindingUtils.createBindGroupIndex(r,s);t.push(n)}s.indexesGPU=t}let c=i.renderTarget,p=null===c||!0===c.isPostProcessingRenderTarget?this.renderer.getPixelRatio():1,m=u?d.indexOf(u):-1;for(let u=0,c=a.length;u<c;u++){let c=a[u];if(r.layers.test(c.layers)){let r=c.viewport,a=n.currentPass,g=n.currentSets,f=void 0!==n.bundleEncoders;if(f){let e=n.bundleEncoders[u],t=n.bundleSets[u];a=e,g=t}if(r&&!f&&a.setViewport(Math.floor(r.x*p),Math.floor(r.y*p),Math.floor(r.width*p),Math.floor(r.height*p),i.viewportValue.minDepth,i.viewportValue.maxDepth),-1!==m&&s.indexesGPU){let e=s.indexesGPU[u];g.bindingGroups[m]!==e&&(a.setBindGroup(m,e),g.bindingGroups[m]=e)}this._draw(e,t,n,o,d,h,l,a,g,m)}}}else if(n.currentPass){if(n.currentPass instanceof GPURenderBundleEncoder)!0===r.occlusionTest&&(0,u.mcG)("WebGPUBackend: Occlusion queries can not be recorded into render bundles.");else if(void 0!==n.occlusionQuerySet){let e=n.lastOcclusionObject;e!==r&&(null!==e&&!0===e.occlusionTest&&(n.currentPass.endOcclusionQuery(),n.occlusionQueryIndex++),!0===r.occlusionTest&&(n.currentPass.beginOcclusionQuery(n.occlusionQueryIndex),n.occlusionQueryObjects[n.occlusionQueryIndex]=r),n.lastOcclusionObject=r)}this._draw(e,t,n,o,d,h,l,n.currentPass,n.currentSets)}}needsRenderUpdate(e){let t=this.get(e),{object:r,material:i}=e,s=this.utils,n=s.getSampleCountRenderContext(e.context),a=s.getCurrentColorSpace(e.context),o=s.getCurrentColorFormat(e.context),l=s.getCurrentDepthStencilFormat(e.context),u=s.getPrimitiveTopology(r,i),d=r.isMesh&&0>r.matrixWorld.determinantAffine(),h=!1;return(t.material!==i||t.materialVersion!==i.version||t.transparent!==i.transparent||t.blending!==i.blending||t.premultipliedAlpha!==i.premultipliedAlpha||t.blendSrc!==i.blendSrc||t.blendDst!==i.blendDst||t.blendEquation!==i.blendEquation||t.blendSrcAlpha!==i.blendSrcAlpha||t.blendDstAlpha!==i.blendDstAlpha||t.blendEquationAlpha!==i.blendEquationAlpha||t.colorWrite!==i.colorWrite||t.depthWrite!==i.depthWrite||t.depthTest!==i.depthTest||t.depthFunc!==i.depthFunc||t.stencilWrite!==i.stencilWrite||t.stencilFunc!==i.stencilFunc||t.stencilFail!==i.stencilFail||t.stencilZFail!==i.stencilZFail||t.stencilZPass!==i.stencilZPass||t.stencilFuncMask!==i.stencilFuncMask||t.stencilWriteMask!==i.stencilWriteMask||t.polygonOffset!==i.polygonOffset||t.polygonOffsetFactor!==i.polygonOffsetFactor||t.polygonOffsetUnits!==i.polygonOffsetUnits||t.side!==i.side||t.alphaToCoverage!==i.alphaToCoverage||t.sampleCount!==n||t.colorSpace!==a||t.colorFormat!==o||t.depthStencilFormat!==l||t.primitiveTopology!==u||t.frontFaceCW!==d||t.clippingContextCacheKey!==e.clippingContextCacheKey)&&(t.material=i,t.materialVersion=i.version,t.transparent=i.transparent,t.blending=i.blending,t.premultipliedAlpha=i.premultipliedAlpha,t.blendSrc=i.blendSrc,t.blendDst=i.blendDst,t.blendEquation=i.blendEquation,t.blendSrcAlpha=i.blendSrcAlpha,t.blendDstAlpha=i.blendDstAlpha,t.blendEquationAlpha=i.blendEquationAlpha,t.colorWrite=i.colorWrite,t.depthWrite=i.depthWrite,t.depthTest=i.depthTest,t.depthFunc=i.depthFunc,t.stencilWrite=i.stencilWrite,t.stencilFunc=i.stencilFunc,t.stencilFail=i.stencilFail,t.stencilZFail=i.stencilZFail,t.stencilZPass=i.stencilZPass,t.stencilFuncMask=i.stencilFuncMask,t.stencilWriteMask=i.stencilWriteMask,t.polygonOffset=i.polygonOffset,t.polygonOffsetFactor=i.polygonOffsetFactor,t.polygonOffsetUnits=i.polygonOffsetUnits,t.side=i.side,t.alphaToCoverage=i.alphaToCoverage,t.sampleCount=n,t.colorSpace=a,t.colorFormat=o,t.depthStencilFormat=l,t.primitiveTopology=u,t.frontFaceCW=d,t.clippingContextCacheKey=e.clippingContextCacheKey,h=!0),h}getRenderCacheKey(e){let{object:t,material:r}=e,i=this.utils,s=e.context,n=t.isMesh&&0>t.matrixWorld.determinantAffine();return[r.transparent,r.blending,r.premultipliedAlpha,r.blendSrc,r.blendDst,r.blendEquation,r.blendSrcAlpha,r.blendDstAlpha,r.blendEquationAlpha,r.colorWrite,r.depthWrite,r.depthTest,r.depthFunc,r.stencilWrite,r.stencilFunc,r.stencilFail,r.stencilZFail,r.stencilZPass,r.stencilFuncMask,r.stencilWriteMask,r.polygonOffset,r.polygonOffsetFactor,r.polygonOffsetUnits,r.side,r.alphaToCoverage,n,i.getSampleCountRenderContext(s),i.getCurrentColorSpace(s),i.getCurrentColorFormat(s),i.getCurrentDepthStencilFormat(s),i.getPrimitiveTopology(t,r),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}updateSampler(e){return this.textureUtils.updateSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){return this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e,t=!1){this.textureUtils.destroyTexture(e,t)}async copyTextureToBuffer(e,t,r,i,s,n){return this.textureUtils.copyTextureToBuffer(e,t,r,i,s,n)}initTimestampQuery(e,t,r){if(!this.trackTimestamp)return;this.timestampQueryPool[e]||(this.timestampQueryPool[e]=new fD(this.device,e,2048));let i=this.timestampQueryPool[e],s=i.allocateQueriesForContext(t);fj.querySet=i.querySet,fj.beginningOfPassWriteIndex=s,fj.endOfPassWriteIndex=s+1,r.timestampWrites=fj}createNodeBuilder(e,t){return new fc(e,t)}createProgram(e){let t=this.get(e);fq.label=e.stage+(""!==e.name?`_${e.name}`:""),fq.code=e.code,t.module={module:this.device.createShaderModule(fq),entryPoint:"main"},fq.reset()}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t,r=null){this.pipelineUtils.createComputePipeline(e,t,r)}beginBundle(e){let t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){let r=this.get(e),i=r.currentPass.finish();this.get(t).bundleGPU=i,r.currentSets=r._currentSets,r.currentPass=r._currentPass,r._currentPass=null,r._currentSets=null}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createUniformBuffer(e){let t=this.get(e);if(void 0===t.buffer){let r=e.byteLength,i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,s=[];e.visibility&mK.VERTEX&&s.push("vertex"),e.visibility&mK.FRAGMENT&&s.push("fragment"),e.visibility&mK.COMPUTE&&s.push("compute");let n=`(${s.join(",")})`;fz.label=`bindingBuffer${e.id}_${e.name}_${n}`,fz.size=r,fz.usage=i;let a=this.device.createBuffer(fz);fz.reset(),t.buffer=a}}destroyUniformBuffer(e){this.get(e).buffer.destroy(),this.delete(e)}createBindings(e,t,r,i){this.bindingUtils.createBindings(e,t,r,i)}updateBindings(e,t,r,i){this.bindingUtils.createBindings(e,t,r,i)}updateBinding(e){this.bindingUtils.updateBinding(e)}deleteBindGroupData(e){this.bindingUtils.deleteBindGroupData(e)}createIndexAttribute(e){let t=GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST;(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute)&&(t|=GPUBufferUsage.STORAGE),this.attributeUtils.createAttribute(e,t)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.delete(this.renderer.getCanvasTarget())}hasFeature(e){return void 0!==gl[e]&&(e=gl[e]),this.device.features.has(e)}copyTextureToTexture(e,t,r=null,i=null,s=0,n=0){let a=0,o=0,l=0,u=0,d=0,h=0,c=e.image.width,p=e.image.height,m=1;null!==r&&(!0===r.isBox3?(u=r.min.x,d=r.min.y,h=r.min.z,c=r.max.x-r.min.x,p=r.max.y-r.min.y,m=r.max.z-r.min.z):(u=r.min.x,d=r.min.y,c=r.max.x-r.min.x,p=r.max.y-r.min.y,m=1)),null!==i&&(a=i.x,o=i.y,l=i.z||0),f$.label="copyTextureToTexture_"+e.id+"_"+t.id;let g=this.device.createCommandEncoder(f$);f$.reset();let f=this.get(e).texture,b=this.get(t).texture;fX.texture=f,fX.mipLevel=s,fX.origin.x=u,fX.origin.y=d,fX.origin.z=h,fK.texture=b,fK.mipLevel=n,fK.origin.x=a,fK.origin.y=o,fK.origin.z=l,fZ.width=c,fZ.height=p,fZ.depthOrArrayLayers=m,g.copyTextureToTexture(fX,fK,fZ),fX.reset(),fK.reset(),fZ.reset(),gg(this.device,g.finish()),0===n&&t.generateMipmaps&&this.textureUtils.generateMipmaps(t)}copyFramebufferToTexture(e,t,r){let i,s=this.get(t),n=null;n=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();let a=this.get(e).texture;if(n.format!==a.format)return void(0,u.z3S)("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,a.format);if(!0===this._isRenderCameraDepthArray(t)){let i=this._finishArrayCameraBundleEncoders(s);s.arrayCameraRenderStages.push({bundles:i,framebufferCopy:{texture:e,sourceGPU:n,destinationGPU:a,rectangle:{x:r.x,y:r.y,z:r.z,w:r.w},generateMipmaps:e.generateMipmaps}}),this._createArrayCameraBundleEncoders(t,s);return}if(s.currentPass?(s.currentPass.end(),i=s.encoder):(f$.label="copyFramebufferToTexture_"+e.id,i=this.device.createCommandEncoder(f$),f$.reset()),this._copyFramebufferToTexture(i,e,n,a,r),s.currentPass){let{descriptor:e}=s;for(let t=0;t<e.colorAttachments.length;t++)e.colorAttachments[t].loadOp=mZ.Load;t.depth&&(e.depthStencilAttachment.depthLoadOp=mZ.Load),t.stencil&&(e.depthStencilAttachment.stencilLoadOp=mZ.Load),s.currentPass=i.beginRenderPass(e),this._resetRenderContextData(s),t.viewport&&this.updateViewport(t),t.scissor&&this.updateScissor(t)}else gg(this.device,i.finish())}_copyFramebufferToTexture(e,t,r,i,s,n=0,a=t.generateMipmaps){fX.texture=r,fX.origin.x=s.x,fX.origin.y=s.y,fX.origin.z=n,fK.texture=i,fZ.width=s.z,fZ.height=s.w,e.copyTextureToTexture(fX,fK,fZ),fX.reset(),fK.reset(),fZ.reset(),a&&this.textureUtils.generateMipmaps(t,e)}hasCompatibility(e){return void 0!==this._compatibility[e]?this._compatibility[e]:super.hasCompatibility(e)}async dispose(){if(await super.dispose(),this.bindingUtils.dispose(),this.textureUtils.dispose(),this.occludedResolveCache){for(let e of this.occludedResolveCache.values())e.destroy();this.occludedResolveCache.clear()}void 0===this.parameters.device&&null!==this.device&&this.device.destroy()}}class f0 extends u.nCl{constructor(e,t,r,i,s,n){super(e,t,r,i,s,n),this.iesMap=null}copy(e,t){return super.copy(e,t),this.iesMap=e.iesMap,this}}class f1 extends u.nCl{constructor(e,t,r,i,s,n){super(e,t,r,i,s,n),this.aspect=null}copy(e,t){return super.copy(e,t),this.aspect=e.aspect,this}}class f2 extends pz{constructor(){super(),this.addMaterial(oY,"MeshPhongMaterial"),this.addMaterial(uf,"MeshStandardMaterial"),this.addMaterial(uy,"MeshPhysicalMaterial"),this.addMaterial(uv,"MeshToonMaterial"),this.addMaterial(oz,"MeshBasicMaterial"),this.addMaterial(oK,"MeshLambertMaterial"),this.addMaterial(oC,"MeshNormalMaterial"),this.addMaterial(uN,"MeshMatcapMaterial"),this.addMaterial(oy,"LineBasicMaterial"),this.addMaterial(oT,"LineDashedMaterial"),this.addMaterial(uF,"PointsMaterial"),this.addMaterial(uw,"SpriteMaterial"),this.addMaterial(uD,"ShadowMaterial"),this.addLight(h3,u.HiM),this.addLight(pm,u.ZyN),this.addLight(pR,u.ure),this.addLight(pf,u.nCl),this.addLight(pp,u.$p8),this.addLight(pg,u.dth),this.addLight(py,u.FZo),this.addLight(pb,f0),this.addLight(pT,f1),this.addToneMapping(he,u.kyO),this.addToneMapping(ht,u.Mjd),this.addToneMapping(hr,u.nNL),this.addToneMapping(hs,u.FV),this.addToneMapping(hl,u.LAk),this.addToneMapping(hu,u.aJ8)}}class f3 extends mt{constructor(e={}){let t;e.forceWebGL?t=mj:(t=fJ,e.getFallback=()=>((0,u.R8M)("WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new mj(e))),super(new t(e),e),this.library=new f2,this.isWebGPURenderer=!0,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}}u.YJl,u.Qev,u.gPd,u.gPd,u.gPd,u.aHM,u.jut,u.XTe,u.YJl}}]);
|