@rings-webgpu/core 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rings.es.js CHANGED
@@ -5745,6 +5745,13 @@ struct InstanceData {
5745
5745
  `}return r}return r}}function Xt(s){switch(s){case"int":return"i32";case"int[]":return"array<i32>";case"uint":return"u32";case"uint[]":return"array<u32>";case"float":return"f32";case"float[]":return"array<f32>";case"vec2":return"vec2<f32>";case"vec3":return"vec3<f32>";case"vec4":return"vec4<f32>";case"vec2[]":return"array<vec2<f32>>";case"vec3[]":return"array<vec3<f32>>";case"vec4[]":return"array<vec4<f32>>";case"ivec2":return"vec2<i32>";case"ivec3":return"vec3<i32>";case"ivec4":return"vec4<i32>";case"ivec2[]":return"array<vec2<i32>>";case"ivec3[]":return"array<vec3<i32>>";case"ivec4[]":return"array<vec4<i32>>";case"mat2":return"mat2x2<f32>";case"mat2x2":return"mat2x2<f32>";case"mat2x3":return"mat2x3<f32>";case"mat2x4":return"mat2x4<f32>";case"mat2[]":return"array<mat2x2<f32>>";case"mat2x2[]":return"array<mat2x2<f32>>";case"mat2x3[]":return"array<mat2x3<f32>>";case"mat2x4[]":return"array<mat2x4<f32>>";case"mat3":return"mat3x3<f32>";case"mat3x2":return"mat3x2<f32>";case"mat3x3":return"mat3x3<f32>";case"mat3x4":return"mat3x4<f32>";case"mat3[]":return"array<mat3x3<f32>>";case"mat3x2[]":return"array<mat3x2<f32>>";case"mat3x3[]":return"array<mat3x3<f32>>";case"mat3x4[]":return"array<mat3x4<f32>>";case"mat4":return"mat4x4<f32>";case"mat4x2":return"mat4x2<f32>";case"mat4x3":return"mat4x3<f32>";case"mat4x4":return"mat4x4<f32>";case"mat4[]":return"array<mat4x4<f32>>";case"mat4x2[]":return"array<mat4x2<f32>>";case"mat4x3[]":return"array<mat4x3<f32>>";case"mat4x4[]":return"array<mat4x4<f32>>";case"texture2D":return"texture_2d<f32>"}return s}class xh{_lexer;_rootNode;constructor(e){this._lexer=e,this._rootNode=new _e,this.parse()}get lexer(){return this._lexer}parse(){for(;this.peekToken(0).Type!==B.EOF;){if(this.peekToken(0).Type==B.SEMICOLON){this.skipToken(1);continue}let e=this.parseStatement();e!==null&&this._rootNode.addNode(e)}}parseStatement(){let e=this.peekToken();if(e.Type==B.LAYOUT&&this.peekToken(1).Type==B.LEFTSAMLL)return Ja.parse(this._lexer);if(e.Type==B.STRUCT)return this.skipToken(1),kr.parse(this._lexer);if((e.isBuiltinType()||e.Type==B.VOID)&&this.peekToken(1).Type==B.IDENT&&this.peekToken(2).Type==B.LEFTSAMLL)return Ns.parse(this._lexer);if(e.Type==B.CONST&&this.peekToken(1).isDataType())return ze.parse(this._lexer);if(e.isDataType()&&this.peekToken(1).Type==B.IDENT)return ze.parse(this._lexer);if(e.Type==B.OUT&&this.peekToken(1).isDataType()&&this.peekToken(2).Type==B.IDENT)return ze.parse(this._lexer);if(e.Type==B.PRECISION)return ks.parse(this._lexer);throw"Error parsing statement: Unexpected character"}skipToken(e){this._lexer.skipToken(e)}peekToken(e=0){return this._lexer.peekToken(e)}getNextToken(){return this._lexer.GetNextToken()}get ASTRoot(){return this._rootNode}}class vh{static VertexShader="VertexShader";static FragmentShader="FragmentShader";static convertGLSL(e){var t=new ph(e),r=new gh(t),i=new xh(r),a=new mh(i);return a.generateWGSL()}}class Uo{setID=0;bindingID=0;name="";type=""}class xo{name="";type="";locationID=0;builtinName="";isBuiltinAttribute(){return this.builtinName!=""}}class Bh{uniformInfo=[];inputAttribute=[];outputAttribute=[];sourceCode=""}var ar=(s=>(s[s.vertex=0]="vertex",s[s.fragment=1]="fragment",s[s.computer=2]="computer",s))(ar||{});class Ch{blendMode=ae.NONE;depthCompare=et.less_equal;depthWriteEnabled=!0;frontFace="ccw";cullMode=Et.back;topology=to.triangle_list;depthBias=10;useLight=!1;useProbe=!1;acceptGI=!1;acceptShadow=!1;castShadow=!1;castReflection=!0;receiveEnv=!1;renderLayer=1e3;renderOrder=2e3;unclippedDepth=!1;transparent=!1;multisample=0;label;useZ=!0;splitTexture=!1;alphaCutoff;useFragDepth=!1;writeMasks=[];setFromMapValues(e){e.has("blendMode")&&(this.blendMode=this.convertBlendMode(e.get("blendMode"))),e.has("depthCompare")&&(this.depthCompare=e.get("depthCompare")),e.has("depthWriteEnabled")&&(this.depthWriteEnabled=e.get("depthWriteEnabled")),e.has("frontFace")&&(this.frontFace=e.get("frontFace")),e.has("cullMode")&&(this.cullMode=e.get("cullMode")),e.has("topology")&&(this.topology=e.get("topology")),e.has("depthBias")&&(this.depthBias=e.get("depthBias")),e.has("useLight")&&(this.useLight=e.get("useLight")),e.has("useProbe")&&(this.useProbe=e.get("useProbe")),e.has("acceptGI")&&(this.acceptGI=e.get("acceptGI")),e.has("acceptShadow")&&(this.acceptShadow=e.get("acceptShadow")),e.has("castShadow")&&(this.castShadow=e.get("castShadow")),e.has("receiveEnv")&&(this.receiveEnv=e.get("receiveEnv")),e.has("renderLayer")&&(this.renderLayer=e.get("renderLayer")),e.has("renderOrder")&&(this.renderOrder=e.get("renderOrder")),e.has("unclippedDepth")&&(this.unclippedDepth=e.get("unclippedDepth")),e.has("multisample")&&(this.multisample=e.get("multisample")),e.has("label")&&(this.label=e.get("label")),e.has("useZ")&&(this.useZ=e.get("useZ"))}convertBlendMode(e){switch(e){case"ABOVE":return ae.ABOVE;case"ALPHA":return ae.ALPHA;case"NORMAL":return ae.NORMAL;case"ADD":return ae.ADD;case"BELOW":return ae.BELOW;case"ERASE":return ae.ERASE;case"MUL":return ae.MUL;case"SCREEN":return ae.SCREEN;case"DIVD":return ae.DIVD;case"SOFT_ADD":return ae.SOFT_ADD}return ae.NONE}}class Sh extends Tr{uniformNodes=[];_onChange=!0;constructor(){super(),this.bufferType=tr.MaterialDataUniformGPUBuffer}initDataUniform(e){this.uniformNodes=e;let t=0;for(const r in e){const i=e[r];i||console.error(r,"is empty"),t+=i.size*4}t=Math.floor(t/256+1)*256,this.createBuffer(GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,t/4,null,"MaterialDataUniformGPUBuffer");for(const r in e){const i=e[r];i||console.error(r,"is empty");let a=this.memory.allocation_node(i.size*4);i.memoryInfo=a,i.bindOnChange=()=>this.onChange()}}onChange(){this._onChange=!0}apply(){if(this.uniformNodes.length!=0&&this._onChange){for(const e in this.uniformNodes)this.uniformNodes[e].update();super.apply(),this._onChange=!1}}}class Mr{static renderShaderModulePool;static renderShader;static init(){this.renderShaderModulePool=new Map,this.renderShader=new Map}}class me{reference;static _ins;static getInstance(){return this._ins||=new me,this._ins}attached(e,t){this.reference||=new Map;let r=this.reference.get(e);r||=new Map,r.set(t,e),this.reference.set(e,r)}detached(e,t){let r=this.reference.get(e);r&&r.delete(t)}hasReference(e){let t=this.reference.get(e);return t?t.size>0:!1}getReferenceCount(e){let t=this.reference.get(e);return t?t.size:0}getReference(e){let t=this.reference.get(e);return t||null}}class vo{static pipelineMap=new Map;static getSharePipeline(e){let t=this.pipelineMap.get(e);return t||null}static setSharePipeline(e,t){this.pipelineMap.set(e,t)}}class Pe extends eo{passType=H.COLOR;useRz=!1;vsName;fsName;shaderState;textures;pipeline;bindGroupLayouts;envMap;prefilterMap;reflectionMap;_sourceVS;_sourceFS;_destVS;_destFS;_vsShaderModule;_fsShaderModule;_textureGroup=-1;_textureChange=!1;_groupsShaderReflectionVarInfos;outBufferMask;constructor(e,t){super(),this.vsName=e.toLowerCase(),this.fsName=t.toLowerCase(),this.vsName in O||console.error("Shader Not Register, Please Register Shader!",this.vsName),this.fsName in O||console.error("Shader Not Register, Please Register Shader!",this.fsName),O[this.vsName]&&(this._sourceVS=O[this.vsName]),O[this.fsName]&&(this._sourceFS=O[this.fsName]),this.textures={},this.bindGroups=[],this.shaderState=new Ch,this.materialDataUniformBuffer=new Sh,this.materialDataUniformBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,this._bufferDic.set("global",this.materialDataUniformBuffer),this._bufferDic.set("materialUniform",this.materialDataUniformBuffer)}get renderOrder(){return this.shaderState.renderOrder}set renderOrder(e){this.shaderState.renderOrder!=e&&(this._valueChange=!0),this.shaderState.renderOrder=e}get doubleSide(){return this.shaderState.cullMode==Et.none}set doubleSide(e){let t=e?Et.none:this.cullMode;this.shaderState.cullMode!=t&&(this._valueChange=!0),this.shaderState.cullMode=t}get depthWriteEnabled(){return this.shaderState.depthWriteEnabled}set depthWriteEnabled(e){this.shaderState.depthWriteEnabled!=e&&(this._valueChange=!0),this.shaderState.depthWriteEnabled=e}get cullMode(){return this.shaderState.cullMode}set cullMode(e){this.shaderState.cullMode!=e&&(this._valueChange=!0),this.shaderState.cullMode=e}get frontFace(){return this.shaderState.frontFace}set frontFace(e){this.shaderState.frontFace!=e&&(this._valueChange=!0),this.shaderState.frontFace=e}get depthBias(){return this.shaderState.depthBias}set depthBias(e){this.shaderState.depthBias!=e&&(this._valueChange=!0),this.shaderState.depthBias=e}get topology(){return this.shaderState.topology}set topology(e){this.shaderState.topology!=e&&(this._valueChange=!0),this.shaderState.topology=e}get blendMode(){return this.shaderState.blendMode}set blendMode(e){this.shaderState.blendMode!=e&&(this._valueChange=!0,e!=ae.NORMAL&&e!=ae.NONE&&(this.renderOrder=3e3)),this.shaderState.blendMode=e}get depthCompare(){return this.shaderState.depthCompare}set depthCompare(e){this.shaderState.depthCompare!=e&&(this._valueChange=!0),this.shaderState.depthCompare=e}setShaderEntry(e="",t=""){this.vsEntryPoint=e,this.fsEntryPoint=t}setUniform(e,t){super.setUniform(e,t),this.materialDataUniformBuffer.onChange()}setTexture(e,t){t&&this.textures[e]!=t&&(this.textures[e]&&this.textures[e].unBindStateChange(this),this._textureChange=!0,this.textures[e]=t,e=="envMap"?this.envMap=t:e=="prefilterMap"?this.prefilterMap=t:e=="reflectionMap"&&(this.reflectionMap=t),t.bindStateChange(()=>{this._textureChange=!0},this))}get baseColor(){return this.getUniform("baseColor")}set baseColor(e){this.setUniform("baseColor",e)}getTexture(e){return this.textures[e]}genRenderPipeline(e,t){let r=this.createGroupLayouts();this.createPipeline(e,t,r)}reBuild(e,t){this.compileShader(ar.vertex,this._destVS,t),this.compileShader(ar.fragment,this._destFS,t),this.genRenderPipeline(e,t)}apply(e,t,r){this.materialDataUniformBuffer.apply(),this._textureChange&&this._textureGroup!=-1&&(this._textureChange=!1,this.genGroups(this._textureGroup,this.shaderReflection.groups,!0)),this._valueChange&&(this._shaderChange&&(this.preCompile(e),this._shaderChange=!1),this.shaderVariant=Bt.genRenderShaderVariant(this),this.reBuild(e,t),this._valueChange=!1,r&&r())}preCompile(e){this.preDefine(e),this.preCompileShader(ar.vertex,this._sourceVS.concat()),this.preCompileShader(ar.fragment,this._sourceFS.concat()),this.genReflection()}applyPostDefine(e,t){return t.renderTargetTextures.length>1?(this.defineValue.USE_WORLDPOS=!0,this.defineValue.USEGBUFFER=!0):(this.defineValue.USE_WORLDPOS=!1,this.defineValue.USEGBUFFER=!1),m.setting.render.useCompressGBuffer?this.defineValue.USE_COMPRESSGBUFFER=!0:this.defineValue.USE_COMPRESSGBUFFER=!1,rr.parse(e,this.defineValue)}setBindGroup(e,t){this.bindGroups[e]=t}checkBuffer(e,t){}preCompileShader(e,t,r){let i=t;if(i.indexOf("version ")!=-1){var a=vh.convertGLSL(i);i=a.sourceCode}for(const o in this.constValues)if(Object.prototype.hasOwnProperty.call(this.constValues,o)){const n=this.constValues[o];i=i.replaceAll(`&${o}`,n.toString())}switch(e){case ar.vertex:this._destVS=i;break;case ar.fragment:this._destFS=i;break}}compileShader(e,t,r){let i=t;i=this.applyPostDefine(i,r);let a=t;for(let n in this.defineValue)a+=`${n}=${this.defineValue[n]},`;let o=Mr.renderShaderModulePool.get(a);switch(o||(i=this.applyPostDefine(i,r),o=Q.device.createShaderModule({label:e==ar.vertex?this.vsName:this.fsName,code:i}),o.getCompilationInfo().then(n=>{n.messages.length>0&&(console.log(i),console.log(n))}),Mr.renderShaderModulePool.set(a,o)),e){case ar.vertex:this._vsShaderModule=o,this._destVS=i;break;case ar.fragment:this._fsShaderModule=o,this._destFS=i;break}}getGroupLayout(e,t){let r=[];for(let i=0;i<t.length;i++){const a=t[i];if(a)if(a.varType=="uniform"){this._bufferDic.has(a.varName)||console.error(`not set ${a.varName} buffer`);let o=this._bufferDic.get(a.varName).visibility,n={binding:a.binding,visibility:o,buffer:{type:"uniform"}};r.push(n)}else if(a.varType=="storage-read"){this._bufferDic.has(a.varName)||console.error(`not set ${a.varName} buffer`);let o=this._bufferDic.get(a.varName).visibility,n={binding:a.binding,visibility:o,buffer:{type:"read-only-storage"}};r.push(n)}else if(a.varType=="var")switch(a.dataType){case"sampler":{let o=a.varName.replace("Sampler",""),n=this.textures[o]?this.textures[o]:m.res.redTexture,l={binding:a.binding,visibility:n.visibility,sampler:n.samplerBindingLayout};r.push(l),this._textureGroup=e}break;case"sampler_comparison":{let o=a.varName.replace("Sampler",""),n=this.textures[o]?this.textures[o]:m.res.redTexture,l={binding:a.binding,visibility:n.visibility,sampler:n.sampler_comparisonBindingLayout};r.push(l),this._textureGroup=e}break;case"texture_2d<f32>":case"texture_2d_array<f32>":case"texture_cube<f32>":case"texture_depth_2d":case"texture_depth_2d_array":case"texture_depth_cube":case"texture_depth_cube_array":{let o=this.textures[a.varName]?this.textures[a.varName]:m.res.redTexture,n={binding:a.binding,visibility:o.visibility,texture:o.textureBindingLayout};r.push(n),this._textureGroup=e,me.getInstance().attached(o,this)}break;case"texture_external":{let o=this.textures[a.varName]?this.textures[a.varName]:m.res.redTexture,n={binding:a.binding,visibility:o.visibility,externalTexture:{}};r.push(n),this._textureGroup=e,me.getInstance().attached(o,this)}break;default:{let o=this.textures[a.varName]?this.textures[a.varName]:m.res.redTexture,n={binding:a.binding,visibility:o.visibility,texture:o.textureBindingLayout};r.push(n),this._textureGroup=e,me.getInstance().attached(o,this)}break}else{debugger;console.error("bind group can't empty")}}return r}_cacheEntries;genGroups(e,t,r=!1){if(!this.bindGroups[e]||r){const i=t[e];let a=[];for(let n=0;n<i.length;n++){const l=i[n];if(l){if(l.varType=="uniform"){let h=this._bufferDic.get(l.varName);if(h){if(h.bufferType==tr.MaterialDataUniformGPUBuffer){let c=[];for(let f=0;f<l.dataFields.length;f++){const g=l.dataFields[f];this.uniforms[g.name]||console.error(`shader-${this.vsName}:${this.fsName} ${g.name}is empty`),c.push(this.uniforms[g.name])}this.materialDataUniformBuffer.initDataUniform(c)}let u={binding:l.binding,resource:{buffer:h.buffer,offset:0,size:h.memory.shareDataBuffer.byteLength}};a.push(u),this.checkBuffer(l.varName,h)}else console.error(`shader${this.vsName}-${this.fsName}`,`buffer ${l.varName} is missing!`)}else if(l.varType=="storage-read"){let h=this._bufferDic.get(l.varName);if(h){let u={binding:l.binding,resource:{buffer:h.buffer,offset:0,size:h.memory.shareDataBuffer.byteLength}};a.push(u),this.checkBuffer(l.varName,h)}else console.error(`buffer ${l.varName} is missing!`)}else if(l.varType=="var")if(l.dataType=="sampler"){let h=l.varName.replace("Sampler",""),u=this.textures[h];if(u||(u=m.res.blackTexture,this.setTexture(h,u)),u){let c={binding:l.binding,resource:u.gpuSampler};a.push(c)}else console.error(`shader${this.vsName}-${this.fsName}`,`texture ${l.varName} is missing! `)}else if(l.dataType=="sampler_comparison"){let h=l.varName.replace("Sampler",""),u=this.textures[h];if(u){let c={binding:l.binding,resource:u.gpuSampler_comparison};a.push(c)}else console.error(`shader${this.vsName}-${this.fsName}`,`texture ${l.varName} is missing! `)}else{let h=this.textures[l.varName];if(h||(h=m.res.whiteTexture,this.setTexture(l.varName,h)),h){let u={binding:l.binding,resource:h.getGPUView()};a.push(u)}else console.error(`shader${this.vsName}-${this.fsName}`,`texture ${l.varName} is missing! `)}}}let o=Q.device.createBindGroup({layout:this.bindGroupLayouts[e],entries:a});this.bindGroups[e]=o}}createPipeline(e,t,r){let i=e,a=this.shaderState,o=[];for(const h of t.renderTargetTextures)o.push({format:h.format});for(let h=0;h<o.length;h++){const u=o[h];a.writeMasks&&a.writeMasks.length>0&&(u.writeMask=a.writeMasks[h])}if(t.outColor!=-1){let h=o[t.outColor];a.blendMode!=ae.NONE?h.blend=fh.getBlend(a.blendMode):delete h.blend}let n={label:this.vsName+"|"+this.fsName,layout:r,primitive:{topology:a.topology,cullMode:a.cullMode,frontFace:a.frontFace},vertex:void 0};this.vsEntryPoint!=""&&(n.vertex={module:this._vsShaderModule,entryPoint:this.vsEntryPoint,buffers:i.vertexBuffer.vertexBufferLayouts}),this.fsEntryPoint!=""&&(n.fragment={module:this._fsShaderModule,entryPoint:this.fsEntryPoint,targets:o}),a.multisample>0&&(n.multisample={count:a.multisample}),(t.zPreTexture||t.depthTexture)&&(a.blendMode!=ae.NONE,m.setting.render.zPrePass&&t.zPreTexture&&a.useZ?n.depthStencil={depthWriteEnabled:!1,depthCompare:et.less,format:t.zPreTexture.format}:n.depthStencil={depthWriteEnabled:a.depthWriteEnabled,depthCompare:a.depthCompare,format:t.depthTexture.format});let l=vo.getSharePipeline(this.shaderVariant);l?this.pipeline=l:(this.pipeline=F.createPipeline(n),vo.setSharePipeline(this.shaderVariant,this.pipeline))}createGroupLayouts(){this._groupsShaderReflectionVarInfos=[];let e=this.shaderReflection;this.bindGroupLayouts=[mo.getGlobalDataBindGroupLayout()];for(let r=1;r<e.groups.length;r++){let i=e.groups[r];if(i){let a=this.getGroupLayout(r,i);this._groupsShaderReflectionVarInfos[r]=i;let o=Q.device.createBindGroupLayout({entries:a,label:`vs${this.vsName} fs${this.fsName} ${i.length}`});this.bindGroupLayouts[r]=o}else console.error("can't set empty group!",r)}let t=Q.device.createPipelineLayout({bindGroupLayouts:this.bindGroupLayouts});return this._groupsShaderReflectionVarInfos[1]&&this.genGroups(1,this._groupsShaderReflectionVarInfos),this._groupsShaderReflectionVarInfos[2]&&this.genGroups(2,this._groupsShaderReflectionVarInfos),this._groupsShaderReflectionVarInfos[3]&&this.genGroups(3,this._groupsShaderReflectionVarInfos),t}preDefine(e){let t=e.hasAttribute(V.TEXCOORD_1),r=e.hasAttribute(V.joints0),i=e.hasAttribute(V.a_morphPositions_0),a=e.hasAttribute(V.TANGENT),o=e.hasAttribute(V.color),n=this.shaderState.acceptGI,l=this.shaderState.useLight;t&&(this.defineValue.USE_SECONDUV=!0),r&&i?this.defineValue.USE_METAHUMAN=!0:(this.defineValue.USE_SKELETON=r,this.defineValue.USE_MORPHTARGETS=i),"USE_TANGENT"in this.defineValue||(this.defineValue.USE_TANGENT=a),this.defineValue.USE_GI=n,this.defineValue.USE_SHADOWMAPING=this.shaderState.acceptShadow,this.defineValue.USE_LIGHT=l,this.defineValue.USE_VERTXCOLOR=o,m.setting.pick.mode=="pixel"&&(this.defineValue.USE_WORLDPOS=!0),m.setting.gi.enable?this.defineValue.USEGI=!0:this.defineValue.USEGI=!1,m.setting.render.debug&&(this.defineValue.USE_DEBUG=!0,this.defineValue.DEBUG_CLUSTER=!0),this.shaderState.useLight?this.defineValue.USE_LIGHT=!0:this.defineValue.USE_LIGHT=!1,m.setting.render.useLogDepth?(this.defineValue.USE_LOGDEPTH=!0,this.shaderState.useFragDepth=!0):this.defineValue.USE_LOGDEPTH=!1,this.shaderState.useFragDepth?this.defineValue.USE_OUTDEPTH=!0:this.defineValue.USE_OUTDEPTH=!1,this.defineValue.USE_PCF_SHADOW=m.setting.shadow.type=="PCF",this.defineValue.USE_HARD_SHADOW=m.setting.shadow.type=="HARD",this.defineValue.USE_SOFT_SHADOW=m.setting.shadow.type=="SOFT",this.defineValue.USE_CSM=Zt.Cascades>1,this.defineValue.USE_IES_PROFILE=gr.use}genReflection(){this.shaderVariant=Bt.genRenderShaderVariant(this);let e=Bt.poolGetReflection(this.shaderVariant);if(e)this.shaderReflection=e;else{let t=rr.parse(this._destVS,this.defineValue);t=rr.parse(t,this.defineValue),Bt.getShaderReflection2(t,this);let r=rr.parse(this._destFS,this.defineValue);r=rr.parse(r,this.defineValue),Bt.getShaderReflection2(r,this),Bt.final(this)}this.shaderState.splitTexture=this.shaderReflection.useSplit}destroy(e){for(const t in this.textures)if(Object.prototype.hasOwnProperty.call(this.textures,t)){const r=this.textures[t];if(me.getInstance().detached(r,this),e&&!me.getInstance().hasReference(r))r.destroy(e);else{r.destroy(!1);let i=me.getInstance().getReference(r);if(i){let a=[];i.forEach((o,n)=>{"name"in o?a.push(o.name):a.push("NaN")})}}}this.bindGroups.length=0,this.shaderState=null,this.textures=null,this.pipeline=null,this.bindGroupLayouts=null,this._sourceVS=null,this._sourceFS=null,this._destVS=null,this._destFS=null,this._vsShaderModule=null,this._fsShaderModule=null,this.materialDataUniformBuffer.destroy(e),this.materialDataUniformBuffer=null}static destroyShader(e){Mr.renderShader.has(e)&&(Mr.renderShader.get(e).destroy(),Mr.renderShader.delete(e))}static getShader(e){return Mr.renderShader.get(e)}static createShader(e,t){let r=new Pe(e,t);return Mr.renderShader.set(r.instanceID,r),r.instanceID}}class _h extends Pe{constructor(){super("sky_vs_frag_wgsl","SkyGBuffer_fs"),this.passType=H.GI,this.setUniformVector3("eyesPos",new d),this.setUniformFloat("exposure",1),this.setUniformFloat("roughness",0);let e=this.shaderState;e.frontFace="ccw",e.cullMode=Et.front,e.depthWriteEnabled=!1,e.depthCompare=et.less}}class Fh extends Pe{transparency;constructor(){super("gbuffer_vs","gbuffer_fs"),this.setShaderEntry("VertMain","FragMain"),this.passType=H.GI,this.setUniformColor("baseColor",new P),this.setUniformColor("emissiveColor",new P),this.setUniformFloat("emissiveIntensity",1),this.setUniformFloat("normalScale",1),this.setUniformFloat("alphaCutoff",1),this.blendMode=ae.NONE,this.setTexture("normalMap",m.res.normalTexture)}}class yh extends Pe{constructor(){super("shadowCastMap_vert","directionShadowCastMap_frag"),this.passType=H.SHADOW,this.setShaderEntry("main"),this.setUniformFloat("cameraFar",5e3),this.setUniformVector3("lightWorldPos",d.ZERO),this.shaderState.receiveEnv=!1,this.shaderState.castShadow=!1,this.shaderState.acceptShadow=!1,this.setDefine("USE_ALPHACUT",!0)}}class bh extends Pe{constructor(){super("castPointShadowMap_vert","shadowCastMap_frag"),this.passType=H.POINT_SHADOW,this.setShaderEntry("main","main"),this.setUniformFloat("cameraFar",5e3),this.setUniformVector3("lightWorldPos",d.ZERO),this.shaderState.receiveEnv=!1,this.shaderState.castShadow=!1,this.shaderState.acceptShadow=!1,this.setDefine("USE_ALPHACUT",!0)}}class Qh extends Pe{constructor(){super("ZPass_shader_vs","ZPass_shader_vs"),this.passType=H.DEPTH,this.setShaderEntry("main"),this.useRz=!1;let e=this.shaderState;e.receiveEnv=!1}}class ca{static createGIPass(e,t){if(Jt.hasMask(e.rendererMask,ve.Sky)){if(!t.passShader.get(H.GI)){let i=t.getSubShaders(H.COLOR)[0],a=new _h;a.setTexture("baseMap",i.getTexture("baseMap")),a.cullMode=i.cullMode,a.frontFace=i.frontFace,t.addRenderPass(a,0),a.preCompile(e.geometry)}}else this.castGBufferPass(e,t)}static castGBufferPass(e,t){let r=t.getDefaultShaders();for(let i=0;i<r.length;i++){const a=r[i];let o=t.getSubShaders(H.GI);if(!o||o.length==0||o.length<i){let n=new Fh;n.setTexture("baseMap",a.getTexture("baseMap")),n.setTexture("normalMap",a.getTexture("normalMap")),n.setTexture("emissiveMap",a.getTexture("emissiveMap")),n.setUniform("baseColor",a.getUniform("baseColor")),n.setUniform("envIntensity",a.getUniform("envIntensity")),n.setUniform("emissiveColor",a.getUniform("emissiveColor")),n.setUniform("emissiveIntensity",a.getUniform("emissiveIntensity")),n.setUniform("alphaCutoff",a.getUniform("alphaCutoff")),n.cullMode=a.cullMode,n.frontFace=a.frontFace,n.preCompile(e.geometry),t.addRenderPass(n)}}}static createShadowPass(e,t){let r=Jt.hasMask(e.rendererMask,ve.SkinnedMesh),i=e.geometry.hasAttribute(V.TANGENT),a=e.geometry.hasAttribute(Yt.MORPH_POSITION_PREFIX+"0"),o=e.geometry.hasAttribute(Yt.MORPH_NORMAL_PREFIX+"0"),n=t.getSubShaders(H.COLOR);for(let l=0;l<n.length;l++){const h=n[l];let u=t.getSubShaders(H.SHADOW);if(!u||u.length<l+1){let f=new yh;f.setTexture("baseMap",h.getTexture("baseMap")),f.setUniform("alphaCutoff",h.getUniform("alphaCutoff")),i&&f.setDefine("USE_TANGENT",i),r&&f.setDefine("USE_SKELETON",r),a&&f.setDefine("USE_MORPHTARGETS",a),o&&f.setDefine("USE_MORPHNORMALS",o),h.cullMode=="none"?f.shaderState.cullMode="none":h.cullMode=="back"?f.shaderState.cullMode="front":h.cullMode=="front"&&(f.shaderState.cullMode="back"),f.preCompile(e.geometry),t.addRenderPass(f)}let c=t.getSubShaders(H.POINT_SHADOW);if(!c||c.length<l+1){let f=new bh;f.setTexture("baseMap",h.getTexture("baseMap")),f.setUniform("alphaCutoff",h.getUniform("alphaCutoff")),f.setDefine("USE_ALPHACUT",1);for(let g=0;g<1;g++)i&&f.setDefine("USE_TANGENT",i),r&&f.setDefine("USE_SKELETON",r),a&&f.setDefine("USE_MORPHTARGETS",a),o&&f.setDefine("USE_MORPHNORMALS",o),f.shaderState.cullMode="front",f.preCompile(e.geometry);t.addRenderPass(f)}}}static createDepthPass(e,t){let r=t.getSubShaders(H.COLOR),i=e.geometry.hasAttribute("TANGENT"),a=e.geometry.hasAttribute(Yt.MORPH_POSITION_PREFIX+"0"),o=e.geometry.hasAttribute(Yt.MORPH_NORMAL_PREFIX+"0"),n=Jt.hasMask(e.rendererMask,ve.SkinnedMesh);for(let l=0;l<r.length;l++){const h=r[l];let u=t.getSubShaders(H.DEPTH);if(!u&&h.shaderState.useZ&&(!u||u.length<l)){let c=new Qh;c.setTexture("baseMap",h.getTexture("baseMap")),i||c.setDefine("USE_TANGENT",i),n&&c.setDefine("USE_SKELETON",n),a&&c.setDefine("USE_MORPHTARGETS",a),o&&c.setDefine("USE_MORPHNORMALS",o),c.cullMode=h.cullMode,c.frontFace=h.frontFace,c.preCompile(e.geometry),t.addRenderPass(c)}}}static createReflectionPass(e,t){let r=t.getDefaultShaders();for(let n=0;n<r.length;n++){const l=r[n];let h=t.getSubShaders(H.REFLECTION);if(!h||h.length==0||h.length<n){let u=new Pe(l.vsName,l.fsName);u.vsEntryPoint=l.vsEntryPoint,u.fsEntryPoint=l.fsEntryPoint,u.passType=H.REFLECTION;for(const c in l.shaderState){var i=l.shaderState[c];u.shaderState[c]=i}for(const c in l.textures){var a=l.getTexture(c);u.setTexture(c,a)}for(const c in l.uniforms){var o=l.getUniform(c);u.setUniform(c,o)}for(const c in l.defineValue){var o=l.defineValue[c];u.setDefine(c,o)}u.setDefine("USE_CASTREFLECTION",!0),u.preCompile(e.geometry),t.addRenderPass(u)}}}}class ci{static _v1=new d;static _v2=new d;entities;box;subTrees=[];parent;level;static maxSplitLevel=6;static autoSplitLevel=3;index;uuid;constructor(e,t=0,r=null,i=0){this.parent=r,this.box=e.clone(),this.level=i,this.index=t,this.uuid=i+"_"+t,this.entities=new Map}tryInsertEntity(e){let t=e.renderer.object3D.bound;if(this.level==0||this.box.containsBox(t)){this.subTrees.length==0&&this.level<ci.maxSplitLevel&&this.splitTree();let r;if(this.subTrees.length>0){for(let i of this.subTrees)if(i.tryInsertEntity(e)){r=!0;break}}return r||e.enterNode(this),!0}return!1}splitTree(){if(this.subTrees.length==0){const e=ci._v1,t=this.box.extents.clone();let r=this.level+1,i=0;for(let a=0;a<2;a++)for(let o=0;o<2;o++)for(let n=0;n<2;n++){const l=new Fe;this.box.min.add(e.set(a,o,n).multiply(t),l.min),l.min.add(t,l.max),l.setFromMinMax(l.min,l.max);let h=new ci(l,i++,this,r);this.subTrees.push(h)}}}__rayCastTempVector=new d;rayCasts(e,t){if(this.level==0||e.intersectBox(this.box,this.__rayCastTempVector)){this.entities.size>0&&t.push(...this.entities.values());for(let r of this.subTrees)r.rayCasts(e,t);return!0}return!1}frustumCasts(e,t){if(this.level==0||e.containsBox2(this.box)>0){if(this.entities.size>0)for(const r of this.entities.values())(this.level>ci.autoSplitLevel||e.containsBox2(r.renderer.object3D.bound)>0)&&t.push(r);for(let r of this.subTrees)r.frustumCasts(e,t);return!0}return!1}getRenderNode(e,t){if(this.level==0||e.containsBox2(this.box)>0){if(this.entities.size>0)for(const r of this.entities.values())(this.level>ci.autoSplitLevel||e.containsBox2(r.renderer.object3D.bound)>0)&&(r.renderer.renderOrder<3e3?t.opaqueList.push(r.renderer):r.renderer.renderOrder>=3e3&&t.transparentList.push(r.renderer));for(let r of this.subTrees)r.getRenderNode(e,t);return!0}return!1}boxCasts(e,t){if(e.intersectsBox(this.box)){this.entities.size>0&&t.push(...this.entities.values());for(let r of this.subTrees)r.boxCasts(e,t);return!0}return!1}clean(){for(let e of this.entities.values())e.leaveNode();return this.entities.clear(),this}}class Rh{_pool=[];_worldPosition=new d;_viewPosition=new d;_zSortList=[];pop(){return this._pool.pop()||{}}recycle(){for(let e of this._zSortList)e.z=0,e.userData=null,e.obj3d=null,this._pool.push(e);this._zSortList.length=0}sort(e,t,r,i){this._zSortList=[];for(let a of t){let o=this.pop();o.userData=a,o.obj3d=r(a),o.z=this.worldToCameraDepth(o.obj3d,e),this._zSortList.push(o)}this._zSortList.sort((a,o)=>a.z-o.z>0?1:-1),i||=[];for(let a of this._zSortList)i.push(a.userData);return this.recycle(),i}worldToCameraDepth(e,t){t||=e.transform.view3D.camera;let r=0;return t&&(this._worldPosition.copyFrom(e.transform.worldPosition),t.worldToScreenPoint(this._worldPosition,this._viewPosition),r=this._viewPosition.z),r}}let Ih=new Rh;var fa=(s=>(s[s.None=2]="None",s[s.StaticBatch=4]="StaticBatch",s[s.DynamicBatch=8]="DynamicBatch",s[s.Hiden=16]="Hiden",s))(fa||{});class Bo{static addMask(e,t){return e|t}static removeMask(e,t){return e&~t}static hasMask(e,t){return(e&t)!=0}}class Eh{opaqueList=[];transparentList=[];sky;clean(){this.opaqueList.length=0,this.transparentList.length=0}}class wh{renderGroup;constructor(){this.renderGroup=new Map}collect_add(e){let t="",r="";t+=e.geometry.instanceID;for(let a=0;a<e.materials.length;a++){const o=e.materials[a];r+=o.shader.getDefaultColorShader().shaderVariant}let i=t+r;this.renderGroup.has(i)||this.renderGroup.set(i,{bundleMap:new Map,key:i,renderNodes:[]}),this.renderGroup.get(i).renderNodes.indexOf(e)==-1&&this.renderGroup.get(i).renderNodes.push(e)}}class Th{renderShaderUpdateList=new Map;renderNodeList=new Map;collect_add(e){let t=e.transform.view3D;t&&e.materials&&e.materials.forEach(r=>{let i=this.renderShaderUpdateList.get(t);i||(i=new Map,this.renderShaderUpdateList.set(t,i));let a=this.renderNodeList.get(t);a||(a=new Map,this.renderNodeList.set(t,a)),a.set(e.instanceID,e);let o=r.getAllPass();for(let n=0;n<o.length;n++){const l=o[n];let h=`${e.geometry.instanceID+l.instanceID}`,u=i.get(h);u||(u=new Map,i.set(h,u)),u.set(e.instanceID,e)}})}collect_remove(e){let t=e.transform.view3D;if(t&&e.materials){let r=this.renderShaderUpdateList.get(t);r&&e.materials.forEach(i=>{let a=i.getAllPass();for(let o=0;o<a.length;o++){const n=a[o];let l=`${e.geometry.instanceID+n.instanceID}`;r.delete(l)}})}}}class G{static _instance;_sceneLights;_sceneGIProbes;_op_RenderNodes;_tr_RenderNodes;_octreeRenderNodes;_reflections;_graphics;_op_renderGroup;_tr_renderGroup;_renderShaderCollect;state={giLightingChange:!0};sky;_collectInfo;rendererOctree;static get instance(){return this._instance||(this._instance=new G),this._instance}constructor(){this._sceneLights=new Map,this._sceneGIProbes=new Map,this._op_RenderNodes=new Map,this._tr_RenderNodes=new Map,this._reflections=new Map,this._graphics=[],this._op_renderGroup=new Map,this._tr_renderGroup=new Map,this._collectInfo=new Eh,this._renderShaderCollect=new Th,this._octreeRenderNodes=new Map}getPashList(e,t){if(t.renderOrder<3e3)return this._op_RenderNodes.get(e);if(t.renderOrder>=3e3)return this._tr_RenderNodes.get(e)}sortRenderNode(e,t){for(let r=e.length-1;r>0;r--)if(e[r].renderOrder<t.renderOrder){e.push(t);return}e.push(t)}addRenderNode(e,t){if(!e)return;let r=t.renderOrder>=3e3;if(t.hasMask(ve.Sky))this.sky=t;else if(t.hasMask(ve.Reflection)){this.removeRenderNode(e,t);let i=this._reflections.get(e);i||(i=[],this._reflections.set(e,i),i.push(t)),i.includes(t)||i.push(t)}else if(t.hasMask(ve.Graphic3D))this._graphics.indexOf(t)==-1&&this._graphics.push(t);else if(Bo.hasMask(t.renderLayer,fa.None)){this.removeRenderNode(e,t);let i=r?this._tr_RenderNodes:this._op_RenderNodes;i.has(e)||i.set(e,[]),i.get(e).push(t),m.setting.occlusionQuery.octree&&t.attachSceneOctree(this.getOctree(e));let a=this.getPashList(e,t);a.indexOf(t)==-1&&this.sortRenderNode(a,t)}else{this.removeRenderNode(e,t);let i=r?this._tr_renderGroup:this._op_renderGroup;i.has(e)||i.set(e,new wh),i.get(e).collect_add(t)}t.object3D.renderNode=t,this._renderShaderCollect.collect_add(t)}getOctree(e){let t,r=m.setting.occlusionQuery.octree;if(r&&(t=this._octreeRenderNodes.get(e),!t)){let i=new d(r.x,r.y,r.z),a=new d(r.width,r.height,r.depth),o=new Fe(i,a);t=new ci(o),this._octreeRenderNodes.set(e,t)}return t}removeRenderNode(e,t){if(t.detachSceneOctree(),t.hasMask(ve.Sky))this.sky=null;else if(t.hasMask(ve.Reflection)){let r=this._reflections.get(e);if(r){let i=r.indexOf(t);i!=-1&&r.splice(i,1)}}else if(Bo.hasMask(t.renderLayer,fa.None)){let r=this.getPashList(e,t);if(r){let i=r.indexOf(t);i!=-1&&r.splice(i,1)}}this._renderShaderCollect.collect_remove(t)}addLight(e,t){if(!this._sceneLights.has(e))this._sceneLights.set(e,[t]);else{let r=this._sceneLights.get(e);if(r.length>=m.setting.light.maxLight){console.warn("Alreay meet maxmium light number:",m.setting.light.maxLight);return}r.indexOf(t)!=-1||r.push(t)}}removeLight(e,t){if(this._sceneLights.has(e)){let r=this._sceneLights.get(e),i=r.indexOf(t);i!=-1&&r.splice(i,1)}}getLights(e){let t=this._sceneLights.get(e);return t||[]}addGIProbe(e,t){this._sceneGIProbes.has(e)?this._sceneGIProbes.get(e).push(t):this._sceneGIProbes.set(e,[t])}removeGIProbe(e,t){if(this._sceneGIProbes.has(e)){let r=this._sceneGIProbes.get(e),i=r.indexOf(t);i!=-1&&r.splice(i,1)}}getProbes(e){let t=this._sceneGIProbes.get(e);return t||[]}getReflections(e){let t=this._reflections.get(e);return t||[]}autoSortRenderNodes(e){let t=this._tr_RenderNodes.get(e);if(!t)return;let r=!1;for(const i of t)if(i.isRenderOrderChange||i.needSortOnCameraZ){r=!0;break}if(r){for(const i of t){let a=i.renderOrder;if(i.needSortOnCameraZ){let o=Ih.worldToCameraDepth(i.object3D);o=1-Math.max(0,Math.min(1,o)),a+=o}i.__renderOrder=a,i.isRenderOrderChange=!1}t.sort((i,a)=>i.__renderOrder>a.__renderOrder?1:-1)}return this}getRenderNodes(e,t){if(this.autoSortRenderNodes(e),this._collectInfo.clean(),this._collectInfo.sky=this.sky,m.setting.occlusionQuery.octree)this.rendererOctree=this.getOctree(e),this.rendererOctree.getRenderNode(t.frustum,this._collectInfo);else{let r=this._op_RenderNodes.get(e);r&&(this._collectInfo.opaqueList=r.concat());let i=this._tr_RenderNodes.get(e);i&&(this._collectInfo.transparentList=i.concat())}return this._collectInfo}getOpRenderGroup(e){return this._op_renderGroup.get(e)}getTrRenderGroup(e){return this._tr_renderGroup.get(e)}getGraphicList(){return this._graphics}getRenderShaderCollect(e){return this._renderShaderCollect.renderShaderUpdateList.get(e)}}class Dh{renderer;owner;uuid;constructor(e){this.renderer=e,this.uuid=e.object3D.instanceID}leaveNode(){this.owner&&(this.owner.entities.delete(this.uuid),this.owner=null)}enterNode(e){this.owner&&this.leaveNode(),this.owner=e,e.entities.set(this.uuid,this)}update(e){return this.owner?.tryInsertEntity(this)||(this.leaveNode(),e.tryInsertEntity(this)),this.owner}}var Og=Object.defineProperty,zg=Object.getOwnPropertyDescriptor,Co=(s,e,t,r)=>{for(var i=zg(e,t),a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=o(e,t,i)||i);return i&&Og(e,t,i),i};class Nr extends ke{instanceCount=0;lodLevel=0;alwaysRender=!1;instanceID;drawType=0;_geometry;_materials=[];_castShadow=!0;_castReflection=!0;_castGI=!1;_rendererMask=ve.Default;_inRenderer=!1;_readyPipeline=!1;_combineShaderRefection;_ignoreEnvMap;_ignorePrefilterMap;__renderOrder=0;_renderOrder=0;_passInit=new Map;isRenderOrderChange;needSortOnCameraZ;isRecievePostEffectUI;_octreeBinder;_renderLayer=fa.None;_computes;init(e){this.renderOrder=0,this.rendererMask=ve.Default,this.instanceID=$s().toString(),this._computes=[]}attachSceneOctree(e){this._octreeBinder={octree:e,entity:new Dh(this)},this.transform.eventDispatcher.addEventListener(Dt.LOCAL_ONCHANGE,this.updateOctreeEntity,this)}detachSceneOctree(){this._octreeBinder&&(this._octreeBinder.entity?.leaveNode(),this.transform.eventDispatcher.removeEventListener(Dt.LOCAL_ONCHANGE,this.updateOctreeEntity,this),this._octreeBinder=null)}updateOctreeEntity(e){this._octreeBinder?.entity?.update(this._octreeBinder.octree)}copyComponent(e){return super.copyComponent(e),this.geometry=e._geometry,this.materials=e._materials.slice(),this.drawType=e.drawType,this.alwaysRender=e.alwaysRender,this.needSortOnCameraZ=e.needSortOnCameraZ,this.isRenderOrderChange=e.isRenderOrderChange,this.castShadow=e.castShadow,this.castGI=e.castGI,this.rendererMask=e.rendererMask,this.isRecievePostEffectUI=e.isRecievePostEffectUI,this}get renderLayer(){return this._renderLayer}set renderLayer(e){this._renderLayer=e}get geometry(){return this._geometry}set geometry(e){this._geometry!=e&&(this._readyPipeline=!1,this._geometry&&me.getInstance().detached(this._geometry,this),e&&me.getInstance().attached(e,this)),this._geometry=e}addMask(e){this._rendererMask=Jt.addMask(this.rendererMask,e)}removeMask(e){this._rendererMask=Jt.removeMask(this.rendererMask,e)}hasMask(e){return Jt.hasMask(this.rendererMask,e)}get rendererMask(){return this._rendererMask}set rendererMask(e){this._rendererMask=e}get renderOrder(){return this._renderOrder}set renderOrder(e){e!=this._renderOrder&&(this.isRenderOrderChange=!0,this.__renderOrder=e),this._renderOrder=e}get materials(){return this._materials}set materials(e){this._readyPipeline=!1;for(let r=0;r<this._materials.length;r++){let i=this._materials[r];me.getInstance().detached(i,this),i.shader&&i.shader.computes&&this.removeComputes(i.shader.computes)}for(let r=0;r<e.length;r++){let i=e[r];me.getInstance().attached(i,this),i.shader&&i.shader.computes&&this.addComputes(i.shader.computes)}this._materials=e;let t=0;for(let r=0;r<e.length;r++){const o=e[r].getPass(H.COLOR)[0];o.shaderState.transparent&&(t=t>o.renderOrder?t:o.renderOrder)}this.renderOrder=t,this._readyPipeline||this.initPipeline()}addComputes(e){this._computes.push(...e)}removeComputes(e){for(const t of e){let r=this._computes.indexOf(t);r!=-1&&this._computes.splice(r,1)}}addRendererMask(e){this._rendererMask=Jt.addMask(this._rendererMask,e)}removeRendererMask(e){this._rendererMask=Jt.removeMask(this._rendererMask,e)}onEnable(){this._readyPipeline||this.initPipeline(),G.instance.addRenderNode(this.transform.scene3D,this),this.updateOctreeEntity()}onDisable(){this._enable=!1,G.instance.removeRenderNode(this.transform.scene3D,this),super.onDisable?.()}selfCloneMaterials(e){let t=[];for(let r=0,i=this.materials.length;r<i;r++){const a=this.materials[r].clone();t.push(a)}return this.materials=t,this._readyPipeline=!1,this.initPipeline(),this}initPipeline(){if(this._geometry&&this._materials.length>0){for(let t=0;t<this._materials.length;t++){let i=this._materials[t].getPass(H.COLOR);for(let a=0;a<i.length;a++){const o=i[a];o.shaderReflection||o.preCompile(this._geometry),this._geometry.generate(o.shaderReflection)}this.object3D.bound=this._geometry.bounds.clone()}this._readyPipeline=!0;let e=0;for(let t=0;t<this.materials.length;t++){const a=this.materials[t].getPass(H.COLOR)[0];a.renderOrder>=3e3?e=e>a.renderOrder?e:a.renderOrder:e=Math.max(e-3e3,0),this.castNeedPass()}this.renderOrder=e,this.enable&&this.transform&&this.transform.scene3D&&G.instance.addRenderNode(this.transform.scene3D,this)}}castNeedPass(){if(this.castGI)for(let t=0;t<this.materials.length;t++){const r=this.materials[t];ca.createGIPass(this,r.shader)}for(let t=0;t<this.materials.length;t++){const r=this.materials[t];r.castShadow&&ca.createShadowPass(this,r.shader)}if(this.castReflection)for(let t=0;t<this.materials.length;t++){const r=this.materials[t];r.castReflection&&ca.createReflectionPass(this,r.shader)}if(!Jt.hasMask(this.rendererMask,ve.IgnoreDepthPass)&&m.setting.render.zPrePass)for(let t=0;t<this.materials.length;t++){const r=this.materials[t];ca.createDepthPass(this,r.shader)}else for(let t=0;t<this.materials.length;t++)this.materials[t].shader.removeShaderByIndex(H.DEPTH,0)}get castShadow(){return this._castShadow}set castShadow(e){this._castShadow=e}get castGI(){return this._castGI}set castGI(e){this._castGI=e}get castReflection(){return this._castReflection}set castReflection(e){this._castReflection=e}renderPass(e,t,r){if(!this._geometry)return;let i=this,a=i.transform._worldMatrix;const o=Math.max(i.materials.length,i._geometry.subGeometries.length);for(let n=0;n<o;n++){const l=n>=i.materials.length?i.materials[0]:i.materials[n];if(!l||!l.enable)continue;let h=l.getPass(t);if(!(!h||h.length==0)){F.bindGeometryBuffer(r.encoder,i._geometry),Ye.viewCount_vertex(e,H[t],i._geometry.vertexCount);for(let u=0;u<h.length;u++){if(!h||h.length==0)continue;const f=h[u];if(f.pipeline){f.shaderState.splitTexture&&(r.endRenderPass(),Ct.WriteSplitColorTexture(i.instanceID),r.beginOpaqueRenderPass(),F.bindCamera(r.encoder,e.camera),F.bindGeometryBuffer(r.encoder,i._geometry)),F.bindPipeline(r.encoder,f)&&Ye.viewCount_pipeline(e,H[t]);let U=(n>=i._geometry.subGeometries.length?i._geometry.subGeometries[0]:i._geometry.subGeometries[n]).lodLevels[i.lodLevel];i.instanceCount>0?(Ye.viewCount_instance(e,H[t],i.instanceCount),Ye.viewCount_indices(e,H[t],U.indexCount),Ye.viewCount_tri(e,H[t],U.indexCount/3*i.instanceCount),F.drawIndexed(r.encoder,U.indexCount,i.instanceCount,U.indexStart,0,0)):(Ye.viewCount_indices(e,H[t],U.indexCount),Ye.viewCount_tri(e,H[t],U.indexCount/3),F.drawIndexed(r.encoder,U.indexCount,1,U.indexStart,0,a.index)),Ye.viewCount_draw(e,H[t])}}}}}renderPass2(e,t,r,i,a,o=!1){if(!this.enable||!this._geometry)return;let n=this,l=n.object3D.transform._worldMatrix;for(let h=0;h<this.materials.length;h++){const u=this.materials[h];if(!u.castShadow&&t==H.SHADOW)continue;let c=u.getPass(t);if(!c||c.length==0)return;if(this.drawType==2)for(let f of c)f.pipeline&&(F.bindPipeline(a,f),F.draw(a,6,1,0,l.index));else{F.bindGeometryBuffer(a,n._geometry);for(let f of c)if(f.pipeline){F.bindPipeline(a,f);let U=n._geometry.subGeometries[h].lodLevels[n.lodLevel];F.drawIndexed(a,U.indexCount,1,U.indexStart,0,l.index)}}}}recordRenderPass2(e,t,r,i,a,o=!1){if(!this.enable)return;let n=this;for(let l=0;l<this.materials.length;l++){let u=this.materials[l].getPass(t);if(!u||u.length==0)return;let c=n.object3D.transform._worldMatrix;for(let f=0;f<u.length;f++){const g=u[f];F.bindPipeline(a,g);let x=n._geometry.subGeometries[l].lodLevels[n.lodLevel];F.drawIndexed(a,x.indexCount,1,x.indexStart,0,c.index)}}}noticeShaderChange(){this.enable&&(this.onEnable(),this._passInit.forEach((e,t)=>{this._passInit.set(t,!1)}))}preInit(e){return this._passInit.get(e)}nodeUpdate(e,t,r,i){let a=this,o=e.scene.envMap;for(let n=0;n<a.materials.length;n++){let h=a.materials[n].getPass(t);if(h)for(let u=0;u<h.length;u++){const f=h[u];if(f.shaderState.splitTexture){let S=Ct.CreateSplitTexture(a.instanceID);f.setTexture("splitTexture_Map",S)}!a._ignoreEnvMap&&f.envMap!=o&&f.setTexture("envMap",o),f.prefilterMap||f.setTexture("prefilterMap",o);let g=ne.getReflectionEntries(e.scene);if(!f.reflectionMap&&g&&g.reflectionMap&&(f.setTexture("reflectionMap",g.reflectionMap),f.setStorageBuffer("reflectionBuffer",g.storageGPUBuffer)),f.pipeline){f.apply(a._geometry,r,()=>a.noticeShaderChange());continue}let p=m.res.getTexture("BRDFLUT");f.setTexture("brdflutMap",p);let A=m.getRenderJob(e).shadowMapPassRenderer;A&&A.depth2DArrayTexture&&f.setTexture("shadowMap",m.getRenderJob(e).shadowMapPassRenderer.depth2DArrayTexture);let U=m.getRenderJob(e).pointLightShadowRenderer;U&&U.cubeArrayTexture&&f.setTexture("pointShadowMap",U.cubeArrayTexture);let x=gr.iesTexture;x&&f.setTexture("iesTextureArrayMap",x),r.irradianceBuffer&&r.irradianceBuffer.length>0&&(f.setTexture("irradianceMap",r.irradianceBuffer[0]),f.setTexture("irradianceDepthMap",r.irradianceBuffer[1]));let v=ne.getLightEntries(e.scene);v&&(f.setStorageBuffer("lightBuffer",v.storageGPUBuffer),v.irradianceVolume&&f.setUniformBuffer("irradianceData",v.irradianceVolume.irradianceVolumeBuffer)),i&&(f.setStorageBuffer("clustersUniform",i.clustersUniformBuffer),f.setStorageBuffer("lightAssignBuffer",i.lightAssignBuffer),f.setStorageBuffer("assignTable",i.assignTableBuffer),f.setStorageBuffer("clusterBuffer",i.clusterBuffer)),f.apply(a._geometry,r),this._passInit.set(t,!0)}}}beforeDestroy(e){me.getInstance().detached(this._geometry,this),me.getInstance().hasReference(this._geometry)||this._geometry.destroy(e);for(let t=0;t<this._materials.length;t++){const r=this._materials[t];me.getInstance().detached(r,this),me.getInstance().hasReference(r)||r.destroy(e)}super.beforeDestroy(e)}destroy(e){super.destroy(e),this._geometry=void 0,this._materials.length=0,this._combineShaderRefection=void 0}}Co([Oi],Nr.prototype,"materials"),Co([Oi],Nr.prototype,"castShadow"),Co([Oi],Nr.prototype,"castGI");class At{instanceID;name;enable=!0;_defaultSubShader;_shader;constructor(){this.instanceID=It()}set shader(e){this._shader=e,this._defaultSubShader=e.getDefaultShaders()[0]}get shader(){return this._shader}get doubleSide(){return this._defaultSubShader.doubleSide}set doubleSide(e){this._defaultSubShader.doubleSide=e}get castShadow(){return this._defaultSubShader.shaderState.castShadow}set castShadow(e){let t=this._defaultSubShader.shaderState;e!=t.castShadow&&(t.castShadow=e)}get acceptShadow(){return this._defaultSubShader.shaderState.acceptShadow}set acceptShadow(e){let t=this._defaultSubShader.shaderState;t.acceptShadow!=e&&(t.acceptShadow=e,this._defaultSubShader.noticeShaderChange(),this._defaultSubShader.noticeValueChange())}get castReflection(){return this._defaultSubShader.shaderState.castReflection}set castReflection(e){this._defaultSubShader.shaderState.castReflection=e}get blendMode(){return this._defaultSubShader.blendMode}set blendMode(e){this._defaultSubShader.blendMode=e}get depthCompare(){return this._defaultSubShader.depthCompare}set depthCompare(e){this._defaultSubShader.depthCompare=e;for(let t of this._shader.passShader.values())for(let r of t)r.depthCompare=e}get transparent(){return this._defaultSubShader.shaderState.transparent}set transparent(e){this._defaultSubShader.shaderState.transparent=e,e&&(this._defaultSubShader.renderOrder=3e3)}get cullMode(){return this._defaultSubShader.cullMode}set cullMode(e){if(this._defaultSubShader.cullMode!=e){for(let t of this._shader.passShader.values())for(let r of t)r.cullMode=e;this._defaultSubShader.cullMode=e}}get depthWriteEnabled(){return this._defaultSubShader.depthWriteEnabled}set depthWriteEnabled(e){this._defaultSubShader.depthWriteEnabled=e}set useBillboard(e){this._defaultSubShader.setDefine("USE_BILLBOARD",e)}get topology(){return this._defaultSubShader.topology}set topology(e){this._defaultSubShader.topology=e}set baseColor(e){this.shader.setUniformColor("baseColor",e)}get baseColor(){return this.shader.getUniformColor("baseColor")}getPass(e){return this._shader.getSubShaders(e)}getAllPass(){return this._shader.getSubShaders(H.COLOR)}clone(){let e=new At;return e.shader=this.shader.clone(),e}destroy(e){this.name=null,this.instanceID=null,this._shader.destroy(),this._shader=null}setDefine(e,t){this.shader.setDefine(e,t)}setTexture(e,t){this._shader.setTexture(e,t)}setStorageBuffer(e,t){this._shader.setStorageBuffer(e,t)}setUniformBuffer(e,t){this._shader.setStorageBuffer(e,t)}setUniformFloat(e,t){this._shader.setUniformFloat(e,t)}setUniformVector2(e,t){this._shader.setUniformVector2(e,t)}setUniformVector3(e,t){this._shader.setUniformVector3(e,t)}setUniformVector4(e,t){this._shader.setUniformVector4(e,t)}setUniformColor(e,t){this._shader.setUniformColor(e,t)}getUniformFloat(e){return this._shader.getUniform(e).data}getUniformV2(e){return this._shader.getUniformVector2(e)}getUniformV3(e){return this._shader.getUniformVector3(e)}getUniformV4(e){return this._shader.getUniformVector4(e)}getUniformColor(e){return this._shader.getUniformColor(e)}getTexture(e){return this._shader.getTexture(e)}getStorageBuffer(e){return this._shader.getStorageBuffer(e)}getStructStorageBuffer(e){return this._shader.getStructStorageBuffer(e)}getUniformBuffer(e){return this._shader.getUniformBuffer(e)}applyUniform(){this._shader.applyUniform()}}const Mh=`
5746
5746
  #include "GlobalUniform"
5747
5747
 
5748
+ // Constants
5749
+ const ALPHA_THRESHOLD: f32 = 0.00392156863; // 1.0 / 255.0
5750
+ const COV_COMPENSATION: f32 = 0.3;
5751
+ const MAX_SPLAT_SIZE: f32 = 1024.0;
5752
+ const MIN_LAMBDA: f32 = 0.1;
5753
+ const LOG_255: f32 = 5.541263545; // log(255.0) - natural log for WGSL
5754
+
5748
5755
  struct MaterialUniform {
5749
5756
  modelMatrix: mat4x4<f32>,
5750
5757
  tex_params: vec4<f32>, // [numSplats, texWidth, validCount, visBoost]
@@ -5764,107 +5771,92 @@ struct InstanceData {
5764
5771
  @group(1) @binding(3) var transformB: texture_2d<f32>;
5765
5772
  @group(1) @binding(4) var splatOrder: texture_2d<u32>;
5766
5773
 
5767
- // Global variables for texture lookups
5768
- var<private> splatUV: vec2<i32>;
5769
- var<private> splatId: u32;
5770
- var<private> tA: vec4<u32>;
5774
+ struct SplatData {
5775
+ center: vec3f,
5776
+ covA: vec3f,
5777
+ covB: vec3f,
5778
+ };
5771
5779
 
5772
- // === calcSplatUV() - returns bool ===
5773
- fn calcSplatUV(orderId: u32) -> bool {
5774
- let textureWidth = u32(materialUniform.tex_params.y);
5775
- let numSplats = u32(materialUniform.tex_params.x);
5776
-
5777
- if (orderId >= numSplats) {
5778
- return false;
5779
- }
5780
-
5780
+ // Helper function to discard splat
5781
+ fn discardSplat() -> VSOut {
5782
+ var o: VSOut;
5783
+ o.member = vec4f(0.0, 0.0, 2.0, 1.0);
5784
+ o.vColor = vec4f(0.0);
5785
+ o.vTexCoord = vec2f(0.0);
5786
+ return o;
5787
+ }
5788
+
5789
+ // === calcSplatUV() - returns optional UV ===
5790
+ fn calcSplatUV(orderId: u32, textureWidth: u32, numSplats: u32) -> vec2<i32> {
5781
5791
  let orderUV = vec2<i32>(
5782
5792
  i32(orderId % textureWidth),
5783
5793
  i32(orderId / textureWidth)
5784
5794
  );
5785
5795
 
5786
- // calculate splatUV
5787
- splatId = textureLoad(splatOrder, orderUV, 0).r;
5788
- splatUV = vec2<i32>(
5796
+ let splatId = textureLoad(splatOrder, orderUV, 0).r;
5797
+ return vec2<i32>(
5789
5798
  i32(splatId % textureWidth),
5790
5799
  i32(splatId / textureWidth)
5791
5800
  );
5792
-
5793
- return true;
5794
- }
5795
-
5796
- // === getCenter() - returns vec3 ===
5797
- fn getCenter() -> vec3f {
5798
- tA = textureLoad(transformA, splatUV, 0);
5799
- return vec3f(bitcast<f32>(tA.x), bitcast<f32>(tA.y), bitcast<f32>(tA.z));
5800
5801
  }
5801
5802
 
5802
- // Struct to return covA and covB
5803
- struct CovarianceData {
5804
- covA: vec3f,
5805
- covB: vec3f,
5806
- };
5807
-
5808
- // === getCovariance() - returns struct ===
5809
- fn getCovariance() -> CovarianceData {
5810
- let tB = textureLoad(transformB, splatUV, 0);
5803
+ // === getSplatData() - unified texture loading ===
5804
+ fn getSplatData(splatUV: vec2<i32>) -> SplatData {
5805
+ var data: SplatData;
5811
5806
 
5812
- // Use WGSL built-in unpack2x16float (equivalent to GLSL unpackHalf2x16)
5807
+ // Load both textures once
5808
+ let tA = textureLoad(transformA, splatUV, 0);
5809
+ let tB = textureLoad(transformB, splatUV, 0);
5813
5810
  let tC = unpack2x16float(tA.w);
5814
5811
 
5815
- var result: CovarianceData;
5816
- result.covA = tB.xyz;
5817
- result.covB = vec3f(tC.x, tC.y, tB.w);
5812
+ // Extract center
5813
+ data.center = vec3f(bitcast<f32>(tA.x), bitcast<f32>(tA.y), bitcast<f32>(tA.z));
5818
5814
 
5819
- return result;
5820
- }
5821
-
5822
- // === getRotationMatrix() - returns mat3x3 ===
5823
- fn getRotationMatrix() -> mat3x3f {
5824
- let cov_data = getCovariance();
5825
- let covA = cov_data.covA;
5826
- let covB = cov_data.covB;
5815
+ // Extract covariance
5816
+ data.covA = tB.xyz;
5817
+ data.covB = vec3f(tC.x, tC.y, tB.w);
5827
5818
 
5828
- return mat3x3f(
5829
- vec3f(1.0 - 2.0 * (covA.z * covA.z + covB.x * covB.x), 2.0 * (covA.y * covA.z + covB.y * covB.x), 2.0 * (covA.y * covB.x - covB.y * covA.z)),
5830
- vec3f(2.0 * (covA.y * covA.z - covB.y * covB.x), 1.0 - 2.0 * (covA.y * covA.y + covB.x * covB.x), 2.0 * (covA.z * covB.x + covA.y * covB.y)),
5831
- vec3f(2.0 * (covA.y * covB.x + covB.y * covA.z), 2.0 * (covA.z * covB.x - covA.y * covB.y), 1.0 - 2.0 * (covA.y * covA.y + covA.z * covA.z))
5832
- );
5819
+ return data;
5833
5820
  }
5834
5821
 
5835
5822
  // === calcV1V2() - returns vec4 ===
5836
5823
  fn calcV1V2(splat_cam: vec3f, covA: vec3f, covB: vec3f, W: mat3x3f, viewport: vec2f, projMat: mat4x4f) -> vec4f {
5824
+ // Construct symmetric covariance matrix
5837
5825
  let Vrk = mat3x3f(
5838
5826
  vec3f(covA.x, covA.y, covA.z),
5839
5827
  vec3f(covA.y, covB.x, covB.y),
5840
5828
  vec3f(covA.z, covB.y, covB.z)
5841
5829
  );
5842
5830
 
5831
+ // Calculate Jacobian
5843
5832
  let focal = viewport.x * projMat[0][0];
5844
-
5845
- let J1 = focal / splat_cam.z;
5846
- let J2 = -J1 / splat_cam.z * splat_cam.xy;
5833
+ let inv_z = 1.0 / splat_cam.z;
5834
+ let J1 = focal * inv_z;
5835
+ let J2 = -J1 * inv_z * splat_cam.xy;
5847
5836
  let J = mat3x3f(
5848
5837
  vec3f(J1, 0.0, J2.x),
5849
5838
  vec3f(0.0, J1, J2.y),
5850
5839
  vec3f(0.0, 0.0, 0.0)
5851
5840
  );
5852
5841
 
5842
+ // Project covariance to screen space
5853
5843
  let T = W * J;
5854
5844
  let cov = transpose(T) * Vrk * T;
5855
5845
 
5856
- let diagonal1 = cov[0][0] + 0.3;
5846
+ // Eigenvalue decomposition with compensation
5847
+ let diagonal1 = cov[0][0] + COV_COMPENSATION;
5857
5848
  let offDiagonal = cov[0][1];
5858
- let diagonal2 = cov[1][1] + 0.3;
5849
+ let diagonal2 = cov[1][1] + COV_COMPENSATION;
5859
5850
 
5860
5851
  let mid = 0.5 * (diagonal1 + diagonal2);
5861
- let radius = length(vec2f((diagonal1 - diagonal2) / 2.0, offDiagonal));
5852
+ let radius = length(vec2f((diagonal1 - diagonal2) * 0.5, offDiagonal));
5862
5853
  let lambda1 = mid + radius;
5863
- let lambda2 = max(mid - radius, 0.1);
5854
+ let lambda2 = max(mid - radius, MIN_LAMBDA);
5864
5855
  let diagonalVector = normalize(vec2f(offDiagonal, lambda1 - diagonal1));
5865
5856
 
5866
- let v1 = min(sqrt(2.0 * lambda1), 1024.0) * diagonalVector;
5867
- let v2 = min(sqrt(2.0 * lambda2), 1024.0) * vec2f(diagonalVector.y, -diagonalVector.x);
5857
+ // Calculate axis vectors with size clamping
5858
+ let v1 = min(sqrt(2.0 * lambda1), MAX_SPLAT_SIZE) * diagonalVector;
5859
+ let v2 = min(sqrt(2.0 * lambda2), MAX_SPLAT_SIZE) * vec2f(diagonalVector.y, -diagonalVector.x);
5868
5860
 
5869
5861
  // WebGPU Y-axis flip: WebGPU NDC Y goes from top(-1) to bottom(1), opposite of WebGL
5870
5862
  return vec4f(v1.x, -v1.y, v2.x, -v2.y);
@@ -5878,135 +5870,117 @@ struct InstanceData {
5878
5870
  @builtin(instance_index) iid : u32,
5879
5871
  @location(0) position: vec3<f32> // vertex_position from mesh (x, y, local_index)
5880
5872
  ) -> VSOut {
5881
- var o: VSOut;
5882
- let discardVec = vec4f(0.0, 0.0, 2.0, 1.0);
5883
-
5884
5873
  // Calculate splat ID
5885
- // orderId = vertex_id_attrib + uint(vertex_position.z)
5886
- // In our case: vertex_id_attrib = iid * batchSize
5887
5874
  let batchSize = u32(materialUniform.pixelCull.w);
5888
- let base_splat_index = iid * batchSize;
5889
- let local_splat_index = u32(position.z);
5890
- let orderId = base_splat_index + local_splat_index;
5875
+ let orderId = iid * batchSize + u32(position.z);
5891
5876
 
5892
- // Use vertex position from mesh
5893
- let vertex_pos = position.xy;
5894
-
5895
- // calculate splat uv
5896
- if (!calcSplatUV(orderId)) {
5897
- o.member = discardVec;
5898
- o.vColor = vec4f(0.0);
5899
- o.vTexCoord = vec2f(0.0);
5900
- return o;
5877
+ // Early bounds check
5878
+ let textureWidth = u32(materialUniform.tex_params.y);
5879
+ let numSplats = u32(materialUniform.tex_params.x);
5880
+ if (orderId >= numSplats) {
5881
+ return discardSplat();
5901
5882
  }
5902
5883
 
5903
- // get center
5904
- let center = getCenter();
5884
+ // Calculate splat UV and load all data in one go
5885
+ let splatUV = calcSplatUV(orderId, textureWidth, numSplats);
5886
+ let splatData = getSplatData(splatUV);
5887
+
5888
+ // Load color early for alpha test
5889
+ let color = textureLoad(splatColor, splatUV, 0);
5890
+ if (color.a < ALPHA_THRESHOLD) {
5891
+ return discardSplat();
5892
+ }
5905
5893
 
5906
- // handle transforms
5894
+ // Transform matrices
5895
+ let matrix_model = materialUniform.modelMatrix;
5907
5896
  let matrix_view = globalUniform.viewMat;
5908
5897
  let matrix_projection = globalUniform.projMat;
5909
- let matrix_model = materialUniform.modelMatrix;
5910
-
5911
5898
  let model_view = matrix_view * matrix_model;
5912
- let splat_cam = model_view * vec4f(center, 1.0);
5913
- let splat_proj = matrix_projection * splat_cam;
5914
5899
 
5915
- // Frustum culling: cull splats behind camera
5916
- if (splat_proj.z < 0.0) {
5917
- o.member = discardVec;
5918
- o.vColor = vec4f(0.0);
5919
- o.vTexCoord = vec2f(0.0);
5920
- return o;
5900
+ // Transform center to camera and clip space
5901
+ let splat_cam = model_view * vec4f(splatData.center, 1.0);
5902
+
5903
+ // Early depth culling
5904
+ if (splat_cam.z <= 0.0) {
5905
+ return discardSplat();
5921
5906
  }
5922
5907
 
5923
- // Frustum culling: cull splats outside screen bounds
5924
- let ndc = splat_proj.xyz / splat_proj.w;
5925
- let margin = 0.0;
5926
- if (ndc.x < -1.0 - margin || ndc.x > 1.0 + margin ||
5927
- ndc.y < -1.0 - margin || ndc.y > 1.0 + margin ||
5908
+ let splat_proj = matrix_projection * splat_cam;
5909
+
5910
+ // Frustum culling with NDC check
5911
+ let inv_w = 1.0 / splat_proj.w;
5912
+ let ndc = splat_proj.xyz * inv_w;
5913
+ if (ndc.x < -1.0 || ndc.x > 1.0 ||
5914
+ ndc.y < -1.0 || ndc.y > 1.0 ||
5928
5915
  ndc.z < 0.0 || ndc.z > 1.0) {
5929
- o.member = discardVec;
5930
- o.vColor = vec4f(0.0);
5931
- o.vTexCoord = vec2f(0.0);
5932
- return o;
5916
+ return discardSplat();
5933
5917
  }
5934
5918
 
5935
- // get covariance
5936
- let cov_data = getCovariance();
5937
-
5919
+ // Calculate v1v2 (screen-space ellipse axes)
5938
5920
  let viewport = vec2f(globalUniform.windowWidth, globalUniform.windowHeight);
5939
- let v1v2 = calcV1V2(splat_cam.xyz, cov_data.covA, cov_data.covB, transpose(mat3x3f(model_view[0].xyz, model_view[1].xyz, model_view[2].xyz)), viewport, matrix_projection);
5940
-
5941
- // get color
5942
- let color = textureLoad(splatColor, splatUV, 0);
5943
- if (color.a < 1.0 / 255.0) {
5944
- o.member = discardVec;
5945
- o.vColor = vec4f(0.0);
5946
- o.vTexCoord = vec2f(0.0);
5947
- return o;
5948
- }
5921
+ let W = transpose(mat3x3f(model_view[0].xyz, model_view[1].xyz, model_view[2].xyz));
5922
+ let v1v2 = calcV1V2(splat_cam.xyz, splatData.covA, splatData.covB, W, viewport, matrix_projection);
5949
5923
 
5950
- // calculate scale based on alpha
5951
- let scale = min(1.0, sqrt(-log(1.0 / 255.0 / color.a)) / 2.0);
5924
+ // Calculate scale based on alpha (optimized formula)
5925
+ let scale = min(1.0, sqrt(LOG_255 + log(color.a)) * 0.5);
5952
5926
 
5953
- // apply visBoost (size multiplier)
5927
+ // Apply visBoost (size multiplier)
5954
5928
  let visBoost = materialUniform.tex_params.w;
5955
- var v1v2_scaled = v1v2 * scale * visBoost;
5929
+ let v1v2_scaled = v1v2 * (scale * visBoost);
5956
5930
 
5957
- // Pixel coverage culling
5958
- let v1_len_sq = dot(v1v2_scaled.xy, v1v2_scaled.xy);
5959
- let v2_len_sq = dot(v1v2_scaled.zw, v1v2_scaled.zw);
5931
+ // Pixel coverage culling (vectorized squared length calculation)
5932
+ let v1v2_sq = v1v2_scaled * v1v2_scaled;
5933
+ let v1_len_sq = v1v2_sq.x + v1v2_sq.y;
5934
+ let v2_len_sq = v1v2_sq.z + v1v2_sq.w;
5960
5935
 
5961
5936
  let minPixels = materialUniform.pixelCull.x;
5962
5937
  let maxPixels = materialUniform.pixelCull.y;
5963
- let maxPixelCullDistance = materialUniform.pixelCull.z;
5964
5938
 
5965
5939
  // Early out tiny splats
5966
5940
  if (v1_len_sq < minPixels && v2_len_sq < minPixels) {
5967
- o.member = discardVec;
5968
- o.vColor = vec4f(0.0);
5969
- o.vTexCoord = vec2f(0.0);
5970
- return o;
5941
+ return discardSplat();
5971
5942
  }
5972
5943
 
5973
5944
  // Cull oversized splats
5974
5945
  if (maxPixels > 0.0) {
5946
+ let maxPixelCullDistance = materialUniform.pixelCull.z;
5975
5947
  let splatDistance = length(splat_cam.xyz);
5976
5948
  if (maxPixelCullDistance <= 0.0 || splatDistance < maxPixelCullDistance) {
5977
5949
  let maxAxisSq = maxPixels * maxPixels;
5978
5950
  if (v1_len_sq > maxAxisSq || v2_len_sq > maxAxisSq) {
5979
- o.member = discardVec;
5980
- o.vColor = vec4f(0.0);
5981
- o.vTexCoord = vec2f(0.0);
5982
- return o;
5951
+ return discardSplat();
5983
5952
  }
5984
5953
  }
5985
5954
  }
5986
5955
 
5987
- // Final position
5988
- o.member = splat_proj + vec4f((vertex_pos.x * v1v2_scaled.xy + vertex_pos.y * v1v2_scaled.zw) / viewport * splat_proj.w, 0.0, 0.0);
5989
- o.vTexCoord = vertex_pos * scale / 2.0;
5956
+ // Final position calculation (optimized)
5957
+ let vertex_pos = position.xy;
5958
+ let inv_viewport = 1.0 / viewport;
5959
+ let offset = (vertex_pos.x * v1v2_scaled.xy + vertex_pos.y * v1v2_scaled.zw) * inv_viewport * splat_proj.w;
5960
+
5961
+ var o: VSOut;
5962
+ o.member = splat_proj + vec4f(offset, 0.0, 0.0);
5963
+ o.vTexCoord = vertex_pos * (scale * 0.5);
5990
5964
  o.vColor = color;
5991
5965
 
5992
5966
  return o;
5993
5967
  }
5994
5968
  `,Nh=`
5995
5969
  #include "FragmentOutput"
5970
+
5971
+ // Constants
5972
+ const ALPHA_THRESHOLD: f32 = 0.00392156863; // 1.0 / 255.0
5973
+ const GAUSSIAN_SCALE: f32 = 4.0;
5996
5974
 
5997
- // === evalSplat() - like PlayCanvas splatCoreFS ===
5975
+ // === evalSplat() - optimized gaussian evaluation ===
5998
5976
  fn evalSplat(texCoord: vec2f, color: vec4f) -> vec4f {
5999
5977
  let A = dot(texCoord, texCoord);
6000
- var B = exp(-A * 4.0) * color.a;
6001
- if (A > 1.0) {
6002
- B = 0.0;
6003
- }
6004
5978
 
6005
- if (B < 1.0 / 255.0) {
6006
- B = 0.0;
6007
- }
5979
+ // Branch-less optimization using select
5980
+ let gaussian = exp(-A * GAUSSIAN_SCALE) * color.a;
5981
+ let alpha = select(gaussian, 0.0, A > 1.0 || gaussian < ALPHA_THRESHOLD);
6008
5982
 
6009
- return vec4f(color.rgb, B);
5983
+ return vec4f(color.rgb, alpha);
6010
5984
  }
6011
5985
 
6012
5986
  @fragment
@@ -6018,7 +5992,7 @@ struct InstanceData {
6018
5992
  o.color = evalSplat(vTexCoord, vColor);
6019
5993
  return o;
6020
5994
  }
6021
- `;class ot{computes;passShader;constructor(){this.computes=[],this.passShader=new Map}addRenderPass(e,t=-1){let r=this.passShader.get(e.passType)||[];t==-1?r.push(e):r.splice(t,-1,e),this.passShader.set(e.passType,r)}removeShader(e,t=-1){let r=this.passShader.get(e.passType);if(r)if(t==-1){let i=r.indexOf(e);i!=-1&&r.splice(i)}else r.splice(t,1)}removeShaderByIndex(e,t=-1){let r=this.passShader.get(e);r&&(t==-1?this.passShader.delete(e):r.splice(t,1))}getSubShaders(e){return this.passShader.get(e)||[]}hasSubShaders(e){return this.passShader.get(e).length>0}getDefaultShaders(){return this.passShader.get(H.COLOR)}getDefaultColorShader(){return this.passShader.get(H.COLOR)[0]}setDefine(e,t){for(const r of this.passShader)for(const i of r[1])i.setDefine(e,t)}hasDefine(e){for(const t of this.passShader)for(const r of t[1]){let i=r.hasDefine(e);if(i)return i}return!1}deleteDefine(e){for(const t of this.passShader)for(const r of t[1])r.deleteDefine(e)}setUniform(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniform(e,t)}setUniformFloat(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformFloat(e,t)}setUniformVector2(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformVector2(e,t)}setUniformVector3(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformVector3(e,t)}setUniformVector4(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformVector4(e,t)}setUniformColor(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformColor(e,t)}getUniform(e){return this.getDefaultColorShader().getUniform(e)}getUniformFloat(e){return this.getDefaultColorShader().getUniformFloat(e)}getUniformVector2(e){return this.getDefaultColorShader().getUniformVector2(e)}getUniformVector3(e){return this.getDefaultColorShader().getUniformVector3(e)}getUniformVector4(e){return this.getDefaultColorShader().getUniformVector4(e)}getUniformColor(e){return this.getDefaultColorShader().getUniformColor(e)}setTexture(e,t){for(const r of this.passShader)for(const i of r[1])i.setTexture(e,t);this.setDefine(`USE_${e.toLocaleUpperCase()}`,!0)}getTexture(e){return this.getDefaultColorShader().textures[e]}setUniformBuffer(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformBuffer(e,t)}getUniformBuffer(e){return this.getDefaultColorShader().getBuffer(e)}setStorageBuffer(e,t){for(const r of this.passShader)for(const i of r[1])i.setStorageBuffer(e,t)}getStorageBuffer(e){return this.getDefaultColorShader().getBuffer(e)}setStructStorageBuffer(e,t){for(const r of this.passShader)for(const i of r[1])i.setStructStorageBuffer(e,t)}getStructStorageBuffer(e){return this.getDefaultColorShader().getBuffer(e)}noticeValueChange(){for(const e of this.passShader)for(const t of e[1])t.noticeValueChange()}destroy(){this.getDefaultColorShader().destroy()}clone(){let e=new ot,t=this.getDefaultShaders();for(const r of t)e.addRenderPass(r);return e}applyUniform(){for(const e of this.passShader)for(const t of e[1])t.applyUniform()}}var Gg=Object.getOwnPropertyDescriptor,Wg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Gg(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=o(i)||i);return i};let da=class extends ot{constructor(){super();const s=new Pe("gsplat_vs_dc","gsplat_fs_dc");s.passType=H.COLOR,s.setShaderEntry("VertMain","FragMain"),s.topology=to.triangle_list,s.depthWriteEnabled=!1,s.cullMode=Et.none,s.shaderState.transparent=!0,s.shaderState.blendMode=ae.NORMAL,s.shaderState.writeMasks=[15,15],this.addRenderPass(s),this.setDefault()}setDefault(){const s=this.getDefaultColorShader(),e=new I;s.setUniform("modelMatrix",e.rawData),s.setUniform("pixelCull",new Float32Array([2,0,0,0]))}};da=Wg([wr(da,"GSplatShader")],da);class Vh extends At{_pixelCullArray=new Float32Array(4);constructor(){super(),O.register("gsplat_vs_dc",Mh),O.register("gsplat_fs_dc",Nh),this.shader=new da}setSplatTextures(e,t,r,i,a){const o=this.shader.getDefaultColorShader();o.setTexture("splatColor",e),o.setTexture("transformA",t),o.setTexture("transformB",r),o.setUniformArray("tex_params",i),a&&o.setTexture("splatOrder",a),o.shaderState.depthCompare=et.less}setTransformMatrix(e){this.shader.getDefaultColorShader().setUniform("modelMatrix",e.rawData)}setPixelCulling(e,t,r=0,i=128){this._pixelCullArray[0]=e,this._pixelCullArray[1]=t,this._pixelCullArray[2]=r,this._pixelCullArray[3]=i,this.shader.getDefaultColorShader().setUniform("pixelCull",this._pixelCullArray)}}class gs extends Tr{node;constructor(e){super(),this.bufferType=tr.VertexGPUBuffer,this.createVertexBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.VERTEX,e)}createVertexBuffer(e,t){let r=Q.device;this.byteSize=t*Float32Array.BYTES_PER_ELEMENT,this.usage=e,this.buffer&&this.destroy(),this.buffer=r.createBuffer({label:"VertexGPUBuffer",size:this.byteSize,usage:e,mappedAtCreation:!1}),this.memory=new jr,this.memoryNodes=new Map,this.memory.allocation(this.byteSize),this.node=this.memory.allocation_node(this.byteSize)}}var dt=(s=>(s[s.split=0]="split",s[s.compose=1]="compose",s[s.compose_bin=2]="compose_bin",s))(dt||{});class Ph{vertexCount=0;vertexGPUBuffer;geometryType=dt.compose;_vertexBufferLayouts;_attributeSlotLayouts;_attributeLocation;constructor(){this._vertexBufferLayouts=[],this._attributeLocation={},this._attributeSlotLayouts=[]}get vertexBufferLayouts(){return this._vertexBufferLayouts}createVertexBuffer(e,t){switch(this.geometryType){case dt.split:this.createSplitVertexBuffer(e,t);break;case dt.compose:this.createComposeVertexBuffer(e,t);break;case dt.compose_bin:this.createComposBinVertexBuffer(e,t);break}}createSplitVertexBuffer(e,t){let r=0;for(let i=0;i<t.attributes.length;i++){const a=t.attributes[i];if(a.name=="index")continue;this._attributeLocation[a.name]=a.location;let o={name:a.name,format:a.format,offset:0,shaderLocation:a.location,stride:qr[a.format]};this._attributeSlotLayouts[a.location]=[o];let n=e.get(a.name);n||(n={attribute:a.name,data:new Float32Array(a.size*this.vertexCount)},e.set(a.name,n));let l=n.data.length/o.stride;this.vertexCount!=0&&this.vertexCount!=l&&console.error(" vertex count not match attribute count"),this.vertexCount=l,this._vertexBufferLayouts[a.location]={name:a.name,arrayStride:a.size*4,stepMode:"vertex",attributes:this._attributeSlotLayouts[a.location],offset:r*4,size:this.vertexCount*a.size*4},r+=this.vertexCount*a.size}this.vertexGPUBuffer=new gs(r)}createComposeVertexBuffer(e,t){this._attributeSlotLayouts[0]=[];let r=0;for(let i=0;i<t.attributes.length;i++){const a=t.attributes[i];if(a.name=="index"||a.type=="builtin")continue;this._attributeLocation[a.name]=a.location;let o={name:a.name,format:a.format,offset:r*4,shaderLocation:a.location,stride:qr[a.format]};this._attributeSlotLayouts[0][a.location]=o;let n=e.get(a.name);if(n||(n={attribute:a.name,data:new Float32Array(a.size*this.vertexCount)},e.set(a.name,n)),n.data){let l=n.data.length/o.stride;this.vertexCount!=0&&this.vertexCount!=l&&console.error(" vertex count not match attribute count"),this.vertexCount=l}r+=a.size}this._vertexBufferLayouts[0]={name:"composeStruct",arrayStride:r*4,stepMode:"vertex",attributes:this._attributeSlotLayouts[0],offset:0,size:this.vertexCount*r*4},this.vertexGPUBuffer=new gs(this.vertexCount*r)}createComposBinVertexBuffer(e,t){this._attributeSlotLayouts[0]=[];let r=0;for(let o=0;o<t.attributes.length;o++){const n=t.attributes[o];if(n.name=="index"||n.type=="builtin")continue;this._attributeLocation[n.name]=n.location;let l={name:n.name,format:n.format,offset:r*4,shaderLocation:n.location,stride:qr[n.format]};this._attributeSlotLayouts[0][n.location]=l;let h=e.get(n.name);if(h||(h={attribute:n.name,data:new Float32Array(n.size*this.vertexCount)},e.set(n.name,h)),h.data){let u=h.data.length/l.stride;this.vertexCount!=0&&this.vertexCount!=u&&console.error(" vertex count not match attribute count"),this.vertexCount=u}r+=n.size}let a=e.get(V.all).data.length/r;this.vertexCount=a,this._vertexBufferLayouts[0]={name:"composeStruct",arrayStride:r*4,stepMode:"vertex",attributes:this._attributeSlotLayouts[0],offset:0,size:this.vertexCount*r*4},this.vertexGPUBuffer=new gs(this.vertexCount*r)}upload(e,t){if(this.vertexGPUBuffer){switch(this.geometryType){case dt.split:{let r=this._attributeLocation[e],i=this._vertexBufferLayouts[r];this.vertexGPUBuffer.node.setFloat32Array(i.offset/4,t.data)}break;case dt.compose:for(let r=0;r<this.vertexCount;r++){const i=this._attributeSlotLayouts[0][this._attributeLocation[e]];for(let a=0;a<i.stride;a++){let o=t.data[r*i.stride+a],n=r*(this._vertexBufferLayouts[0].arrayStride/4)+i.offset/4+a;this.vertexGPUBuffer.node.setFloat(o,n)}}break;case dt.compose_bin:this.vertexGPUBuffer.node.setFloat32Array(0,t.data);break}this.vertexGPUBuffer?.apply()}}updateAttributes(e){switch(this.geometryType){case dt.split:for(let t=0;t<this._vertexBufferLayouts.length;t++){const r=this._vertexBufferLayouts[t];let i=e.get(r.name);this.vertexGPUBuffer.node.setFloat32Array(r.offset/4,i.data)}break;case dt.compose:for(let t=0;t<this.vertexCount;t++)this._attributeSlotLayouts.forEach(r=>{for(let i=0;i<r.length;i++){const a=r[i];let o=e.get(a.name);for(let n=0;n<a.stride;n++){let l=o.data[t*a.stride+n],h=t*(this._vertexBufferLayouts[0].arrayStride/4)+a.offset/4+n;this.vertexGPUBuffer.node.setFloat(l,h)}}});break;case dt.compose_bin:{let t=e.get(V.all);this.vertexGPUBuffer.node.setFloat32Array(0,t.data)}break}this.vertexGPUBuffer.apply()}compute(){}destroy(e){this.vertexCount=null,this.geometryType=null,this._vertexBufferLayouts=null,this._attributeSlotLayouts=null,this._attributeLocation=null,this.vertexGPUBuffer&&this.vertexGPUBuffer.destroy(e),this.vertexGPUBuffer=null}}class kh extends Tr{indicesNode;constructor(e){super(),this.bufferType=tr.IndicesGPUBuffer,this.createIndicesBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.INDEX|GPUBufferUsage.INDIRECT,e)}createIndicesBuffer(e,t){let r=Q.device;if(this.byteSize=t.length*4,this.usage=e,this.buffer&&this.destroy(),this.buffer=r.createBuffer({label:"IndicesGPUBuffer",size:this.byteSize,usage:e,mappedAtCreation:!1}),this.memory=new jr,this.memoryNodes=new Map,this.memory.allocation(this.byteSize),t){this.indicesNode=this.memory.allocation_node(t.length*4);const i=t.buffer instanceof ArrayBuffer?t.buffer:new Uint8Array(t.buffer).buffer;this.indicesNode.setArrayBuffer(0,i),this.apply()}}}class Lh{uuid="";name;indicesGPUBuffer;indicesFormat="uint16";indicesCount=0;constructor(){}createIndicesBuffer(e){e.data instanceof Uint16Array?this.indicesFormat="uint16":e.data instanceof Uint32Array&&(this.indicesFormat="uint32"),this.indicesCount=e.data.length,this.indicesGPUBuffer=new kh(e.data)}upload(e){this.indicesGPUBuffer.indicesNode.setArrayBuffer(0,e),this.indicesGPUBuffer.apply()}compute(){}destroy(){this.uuid=null,this.name=null,this.indicesFormat=null,this.indicesCount=null,this.indicesGPUBuffer.destroy(),this.indicesGPUBuffer=null}}class Oh{lodLevels}class Ie{instanceID;name;subGeometries=[];morphTargetsRelative;morphTargetDictionary;skinNames;bindPose;blendShapeData;vertexDim;vertexCount=0;_bounds;_attributeMap;_attributes;_indicesBuffer;_vertexBuffer;_onChange=!0;_wireframeLines;constructor(){this.instanceID=It(),this._attributeMap=new Map,this._attributes=[],this._vertexBuffer=new Ph}get indicesBuffer(){return this._indicesBuffer}get vertexBuffer(){return this._vertexBuffer}get vertexAttributes(){return this._attributes}get vertexAttributeMap(){return this._attributeMap}get geometryType(){return this._vertexBuffer.geometryType}set geometryType(e){this._vertexBuffer.geometryType=e}get bounds(){if(!this._bounds){this._bounds=new Fe(new d,new d(1,1,1)),this._bounds.min.x=Number.MAX_VALUE,this._bounds.min.y=Number.MAX_VALUE,this._bounds.min.z=Number.MAX_VALUE,this._bounds.max.x=-Number.MAX_VALUE,this._bounds.max.y=-Number.MAX_VALUE,this._bounds.max.z=-Number.MAX_VALUE;let e=this.getAttribute(V.position);if(e&&e.data)for(let t=0;t<e.data.length/3;t++){const r=e.data[t*3+0],i=e.data[t*3+1],a=e.data[t*3+2];this._bounds.min.x>r&&(this._bounds.min.x=r),this._bounds.min.y>i&&(this._bounds.min.y=i),this._bounds.min.z>a&&(this._bounds.min.z=a),this._bounds.max.x<r&&(this._bounds.max.x=r),this._bounds.max.y<i&&(this._bounds.max.y=i),this._bounds.max.z<a&&(this._bounds.max.z=a)}this._bounds.setFromMinMax(this._bounds.min,this._bounds.max)}return this._bounds}set bounds(e){this._bounds=e}addSubGeometry(...e){let t=new Oh;return t.lodLevels=e,this.subGeometries.push(t),t}generate(e){this._onChange&&(this._onChange=!1,this._indicesBuffer.upload(this.getAttribute(V.indices).data),this._vertexBuffer.createVertexBuffer(this._attributeMap,e),this._vertexBuffer.updateAttributes(this._attributeMap),this.vertexCount=this._vertexBuffer.vertexCount)}setIndices(e){if(!this._attributeMap.has(V.indices)){let t={attribute:V.indices,data:e};this._attributeMap.set(V.indices,t),this._indicesBuffer=new Lh,this._indicesBuffer.createIndicesBuffer(t)}}setAttribute(e,t){if(e==V.indices)this.setIndices(t);else{let r={attribute:e,data:t};this._attributeMap.set(e,r),this._attributes.push(e)}}getAttribute(e){return this._attributeMap.get(e)}hasAttribute(e){return this._attributeMap.has(e)}genWireframe(){if(this._wireframeLines)return this._wireframeLines;if(this.geometryType==dt.split||this.geometryType==dt.compose){let e=this.getAttribute(V.position),t=this.getAttribute(V.indices);if(t&&e&&t.data.length>0){let r=e.data,i=[];for(let a=0;a<t.data.length/3;a++){const o=t.data[a*3+0],n=t.data[a*3+1],l=t.data[a*3+2];let h=new d(r[o*3+0],r[o*3+1],r[o*3+2]),u=new d(r[n*3+0],r[n*3+1],r[n*3+2]),c=new d(r[l*3+0],r[l*3+1],r[l*3+2]);i.push(h,u),i.push(u,c),i.push(c,h)}return this._wireframeLines=i,i}}else if(this.geometryType==dt.compose_bin){let e=this.getAttribute(V.all),t=this.vertexDim,r=this.getAttribute(V.indices);if(r&&e&&r.data.length>0){let i=e.data,a=[];for(let o=0;o<r.data.length/3;o++){const n=r.data[o*3+0],l=r.data[o*3+1],h=r.data[o*3+2];let u=new d(i[n*t+0],i[n*t+1],i[n*t+2]),c=new d(i[l*t+0],i[l*t+1],i[l*t+2]),f=new d(i[h*t+0],i[h*t+1],i[h*t+2]);a.push(u,c),a.push(c,f),a.push(f,u)}return this._wireframeLines=a,a}}return null}compute(){this._indicesBuffer&&this._indicesBuffer.compute(),this._vertexBuffer&&this._vertexBuffer.compute()}static crossA=d.UP.clone();static crossB=d.UP.clone();static crossRet=d.UP.clone();static point1=d.UP.clone();static point2=d.UP.clone();static point3=d.UP.clone();computeNormals(){let e=this.getAttribute(V.position),t=this.getAttribute(V.normal),r=this.getAttribute(V.indices);if(!e||!t||!r)return this;let i=r.data.length/3,a=Ie.point1,o=Ie.point2,n=Ie.point3,l=Ie.crossA,h=Ie.crossB,u=Ie.crossRet;for(let c=0;c<i;c++){let f=r.data[c*3],g=r.data[c*3+1],p=r.data[c*3+2];a.set(e.data[f*3],e.data[f*3+1],e.data[f*3+2]),o.set(e.data[g*3],e.data[g*3+1],e.data[g*3+2]),n.set(e.data[p*3],e.data[p*3+1],e.data[p*3+2]),d.sub(a,o,l).normalize(),d.sub(a,n,h).normalize();let A=l.crossProduct(h,u).normalize();t.data[f*3]=t.data[g*3]=t.data[p*3]=A.x,t.data[f*3+1]=t.data[g*3+1]=t.data[p*3+1]=A.y,t.data[f*3+2]=t.data[g*3+2]=t.data[p*3+2]=A.z}return this._vertexBuffer.upload(V.normal,t),this}isPrimitive(){return!1}destroy(e){this.instanceID=null,this.name=null,this.subGeometries=null,this.morphTargetDictionary=null,this._bounds.destroy(),this._bounds=null,this._attributeMap=null,this._attributes=null,this._indicesBuffer.destroy(),this._vertexBuffer.destroy(),this._indicesBuffer=null,this._vertexBuffer=null}}class zh extends Ie{batchSize;constructor(e=128){super(),this.batchSize=e;const t=new Float32Array(12*e);for(let i=0;i<e;++i)t.set([-2,-2,i,2,-2,i,2,2,i,-2,2,i],i*12);const r=new Uint32Array(6*e);for(let i=0;i<e;++i){const a=i*4;r.set([0+a,1+a,2+a,0+a,2+a,3+a],i*6)}this.setAttribute(V.position,t),this.setIndices(r),this.addSubGeometry({indexStart:0,indexCount:r.length,vertexStart:0,vertexCount:t.length/3,firstStart:0,index:0,topology:0})}}class So extends je{_dataBuffer;create(e,t,r,i=!1){let a=Q.device;const o=Math.ceil(e*4/256)*256;this.format=X.rgba8unorm,this.mipmapCount=Math.floor(i?Math.log2(e):1),this.createTextureDescriptor(e,t,this.mipmapCount,this.format);const n=this._dataBuffer=a.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});a.queue.writeBuffer(n,0,r);const l=F.beginCommandEncoder();return l.copyBufferToTexture({buffer:n,bytesPerRow:o},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),F.endCommandEncoder(l),i&&dr.webGPUGenerateMipmap(this),this}updateTexture(e,t,r){let i=Q.device;const a=Math.ceil(e*4/256)*256;this.mipmapCount=Math.floor(Math.log2(e)),this._dataBuffer&&this._dataBuffer.destroy(),this._dataBuffer=null;const o=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(o,0,r);const n=F.beginCommandEncoder();n.copyBufferToTexture({buffer:o,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),F.endCommandEncoder(n),this.gpuSampler=i.createSampler(this),this.mipmapCount>1&&dr.webGPUGenerateMipmap(this)}}class Gh extends je{_dataBuffer;create(e,t,r){let i=Q.device;const a=e*4*4;this.format=X.rgba32uint,this.createTextureDescriptor(e,t,1,this.format);const n=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(n,0,r.buffer);const l=i.createCommandEncoder();return l.copyBufferToTexture({buffer:n,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),i.queue.submit([l.finish()]),this.samplerBindingLayout.type="non-filtering",this.textureBindingLayout.sampleType="uint",this.gpuSampler=i.createSampler({}),this}updateTexture(e,t,r){let i=Q.device;const a=e*4*4;i.queue.writeTexture({texture:this.getGPUTexture()},r.buffer,{bytesPerRow:a},{width:e,height:t,depthOrArrayLayers:1})}}class Wh extends je{_dataBuffer;create(e,t,r){let i=Q.device;const a=e*4;this.format=X.r32uint,this.createTextureDescriptor(e,t,1,this.format);const n=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(n,0,r.buffer);const l=i.createCommandEncoder();return l.copyBufferToTexture({buffer:n,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),i.queue.submit([l.finish()]),this.samplerBindingLayout.type="non-filtering",this.textureBindingLayout.sampleType="uint",this.gpuSampler=i.createSampler({}),this}updateTexture(e,t,r){let i=Q.device;const a=e*4;i.queue.writeTexture({texture:this.getGPUTexture()},r.buffer,{bytesPerRow:a},{width:e,height:t,depthOrArrayLayers:1})}}const Jh=new Float32Array(1),Jg=new Int32Array(Jh.buffer);let ri=function(s){Jh[0]=s;const e=Jg[0];let t=e>>16&32768,r=e>>12&2047;const i=e>>23&255;return i<103?t:i>142?(t|=31744,t|=(i==255?1:0)&&e&8388607,t):i<114?(r|=2048,t|=(r>>114-i)+(r>>113-i&1),t):(t|=i-112<<10|r>>1,t+=r&1,t)};class _o extends je{uint16Array;floatArray;_dataBuffer;create(e,t,r=null,i=!0){if(r==null){r=[];for(let a=0,o=e*t*4;a<o;a++)r[a]=0}return this.updateTexture(e,t,r,i),this}updateTexture(e,t,r,i=!0){(e!=this.width||t!=this.height)&&(this._dataBuffer&&this._dataBuffer.destroy(),this._dataBuffer=null,this.gpuTexture&&this.gpuTexture.destroy(),this.gpuTexture=null),this.floatArray=r;let a=Q.device;const o=e*4*2;this.format=X.rgba16float,this.mipmapCount=Math.floor(i?Math.log2(e):1),this.createTextureDescriptor(e,t,this.mipmapCount,this.format),(!this.uint16Array||this.uint16Array.length!=r.length)&&(this.uint16Array=new Uint16Array(r.length));let n=this.uint16Array;for(let u=0,c=n.length;u<c;u++)n[u]=ri(r[u]);const l=this._dataBuffer=a.createBuffer({size:n.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});a.queue.writeBuffer(l,0,n);const h=F.beginCommandEncoder();h.copyBufferToTexture({buffer:l,bytesPerRow:o},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),this.useMipmap||(this.samplerBindingLayout.type="filtering",this.textureBindingLayout.sampleType="float"),F.endCommandEncoder(h),this.gpuSampler=a.createSampler(this),this.gpuTexture=this.getGPUTexture(),this.mipmapCount>1&&dr.webGPUGenerateMipmap(this)}}var Zg=Object.getOwnPropertyDescriptor,Yg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Zg(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=o(i)||i);return i};let ga=class extends Nr{count=0;size=new j;splatColor;transformA;transformB;texParams;splatOrder;gsplatMaterial;_positions;get positions(){return this._positions}_worldPositions;_orderData;_sortWorker;_lastSentTime=0;_minIntervalMs=16;_centersSent=!1;_lastViewMatrixHash=0;_lastCameraSpeed=0;_adaptiveSorting=!0;_lastPixelCullParams="";_texturesInitialized=!1;_lodEnabled=!1;_lodDistances=[5,10,20,40];_lodRatios=[1,.75,.5,.25,.1];_currentLodLevel=0;_minPixelCoverage=4;_maxPixelCoverage=0;_maxPixelCullDistance=0;_mapping=null;_fullCount=0;get fullCount(){return this._fullCount}_batchSize=128;instanceCount=0;constructor(){super()}initAsset(s){this.count=s.count,this._fullCount=s.count,this.size=this.evalTextureSize(s.count),this.buildColor(s),this.buildTransform(s),this.texParams=new Float32Array([this.count,this.size.x,this.count,1]),this._positions=s.position;const e=this.size.x*this.size.y;this._orderData=new Uint32Array(e);for(let t=0;t<e;t++)this._orderData[t]=t<this.count?t:this.count>0?this.count-1:0;this.splatOrder=new Wh().create(this.size.x,this.size.y,this._orderData),this.splatOrder.name="splatOrder",this.splatOrder.minFilter="nearest",this.splatOrder.magFilter="nearest",this.splatOrder.addressModeU="clamp-to-edge",this.splatOrder.addressModeV="clamp-to-edge",this.gsplatMaterial=new Vh,this.geometry=new zh(this._batchSize),this.materials=[this.gsplatMaterial],this.instanceCount=0}onBeforeUpdate(s){this.count>0&&s?.camera&&(this._lodEnabled&&this.updateLOD(s),s.camera.viewMatrix&&this.scheduleOrder(s.camera.viewMatrix))}updateLOD(s){if(!this._worldPositions||this._fullCount===0)return;const t=s.camera.viewMatrix.rawData,r=-(t[0]*t[12]+t[1]*t[13]+t[2]*t[14]),i=-(t[4]*t[12]+t[5]*t[13]+t[6]*t[14]),a=-(t[8]*t[12]+t[9]*t[13]+t[10]*t[14]);let o=0,n=0,l=0;const h=Math.min(100,this._fullCount);for(let A=0;A<h;A++){const U=Math.floor(A/h*this._fullCount)*3;o+=this._worldPositions[U+0],n+=this._worldPositions[U+1],l+=this._worldPositions[U+2]}o/=h,n/=h,l/=h;const u=r-o,c=i-n,f=a-l,g=Math.sqrt(u*u+c*c+f*f);let p=this._lodDistances.length;for(let A=0;A<this._lodDistances.length;A++)if(g<this._lodDistances[A]){p=A;break}if(p!==this._currentLodLevel){this._currentLodLevel=p;const A=this._lodRatios[p],U=Math.floor(this._fullCount*A);if(this._mapping){const x=this._mapping;this._mapping=new Uint32Array(Math.min(U,x.length));for(let v=0;v<this._mapping.length;v++)this._mapping[v]=x[v];this.setMapping(this._mapping)}else this.count=U,this.texParams[0]=this.count,this.texParams[2]=this.count}}setMapping(s){this._mapping=s&&s.length>0?s:null,this.count=this._mapping?this._mapping.length:this._fullCount,this.texParams[0]=this.count,this.texParams[2]=Math.min(this.texParams[0],this.count);const e=this.size.x*this.size.y;for(let t=0;t<e;t++)this._orderData[t]=t<this.count?t:this.count>0?this.count-1:0;if(this.splatOrder.updateTexture(this.size.x,this.size.y,this._orderData),this._sortWorker){const t=this._worldPositions||this._positions,r=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(t);if(this._mapping)for(let i=0;i<this._mapping.length;++i){const a=this._mapping[i]*3,o=i*3;r[o+0]=t[a+0],r[o+1]=t[a+1],r[o+2]=t[a+2]}this._sortWorker.postMessage({type:"centers",centers:r.buffer,mapping:this._mapping?this._mapping:null},[r.buffer]),this._centersSent=!0}else this._centersSent=!1;this.instanceCount=0}setVisBoost(s){this.texParams[3]=Math.max(0,s)}setSortThrottle(s){this._minIntervalMs=Math.max(0,s|0)}setAdaptiveSorting(s){this._adaptiveSorting=s}setLOD(s,e,t){this._lodEnabled=s,e&&(this._lodDistances=e),t&&(this._lodRatios=t)}getLODStats(){return{enabled:this._lodEnabled,currentLevel:this._currentLodLevel,distances:this._lodDistances,ratios:this._lodRatios,currentRatio:this._lodRatios[this._currentLodLevel],visibleCount:this._lodEnabled?Math.floor(this._fullCount*this._lodRatios[this._currentLodLevel]):this._fullCount}}setPixelCulling(s,e=0,t=0){this._minPixelCoverage=Math.max(0,s),this._maxPixelCoverage=Math.max(0,e),this._maxPixelCullDistance=Math.max(0,t)}getPixelCullingStats(){return{minPixels:this._minPixelCoverage,maxPixels:this._maxPixelCoverage,maxPixelCullDistance:this._maxPixelCullDistance,maxEnabled:this._maxPixelCoverage>0,distanceEnabled:this._maxPixelCullDistance>0}}getBatchingStats(){return{enabled:!0,batchSize:this._batchSize,instanceCount:this.instanceCount,splatCount:this.count,reduction:this.count>0?(1-this.instanceCount/this.count)*100:0}}evalTextureSize(s){let e=Math.ceil(Math.sqrt(s));const t=64;e=Math.ceil(e/t)*t;const r=Math.ceil(s/e);return new j(e,r)}buildColor(s){const e=this.size.x|0,t=this.size.y|0,r=new Uint8Array(e*t*4),i=.28209479177387814,a=s.count,o=s.sh?.coeffs,n=o?o.length/(3*a):1;for(let l=0;l<a;l++){let h=.5,u=.5,c=.5;if(o&&n>=1){const p=l*n*3;h=.5+o[p+0]*i,u=.5+o[p+n+0]*i,c=.5+o[p+2*n+0]*i}const f=s.opacity?1/(1+Math.exp(-s.opacity[l])):1,g=l*4;r[g+0]=Math.max(0,Math.min(255,Math.floor(h*255))),r[g+1]=Math.max(0,Math.min(255,Math.floor(u*255))),r[g+2]=Math.max(0,Math.min(255,Math.floor(c*255))),r[g+3]=Math.max(0,Math.min(255,Math.floor(f*255)))}this.splatColor=new So().create(e,t,r,!1),this.splatColor.name="splatColor",this.splatColor.minFilter="nearest",this.splatColor.magFilter="nearest",this.splatColor.mipmapFilter="nearest",this.splatColor.addressModeU="clamp-to-edge",this.splatColor.addressModeV="clamp-to-edge"}buildTransform(s){const e=this.size.x|0,t=this.size.y|0,r=s.count,i=new Uint32Array(e*t*4),a=new Array(e*t*4).fill(0),o=new ArrayBuffer(4),n=new Float32Array(o),l=new Uint32Array(o),h=g=>(n[0]=g,l[0]),u=s.position,c=s.rotation,f=s.scale;for(let g=0;g<r;g++){const p=g*4,A=u[g*3+0],U=u[g*3+1],x=u[g*3+2];i[p+0]=h(A),i[p+1]=h(U),i[p+2]=h(x);let v=0,S=0,C=0,_=1;if(c){v=c[g*4+0],S=c[g*4+1],C=c[g*4+2],_=c[g*4+3];const Wt=1/Math.hypot(v,S,C,_);v*=Wt,S*=Wt,C*=Wt,_*=Wt}let y=1,b=1,w=1;f&&(y=Math.exp(f[g*3+0]),b=Math.exp(f[g*3+1]),w=Math.exp(f[g*3+2]));const R=v+v,E=S+S,N=C+C,z=v*R,Y=v*E,ee=v*N,oe=S*E,te=S*N,ge=C*N,Ce=_*R,J=_*E,ce=_*N,he=1-(oe+ge),Ue=Y+ce,xe=ee-J,Ve=Y-ce,Ee=1-(z+ge),ye=te+Ce,Ne=ee+J,lt=te-Ce,pr=1-(z+oe),Nt=he*y,Qt=Ue*y,Rt=xe*y,Vt=Ve*b,_t=Ee*b,mr=ye*b,Ar=Ne*w,Ur=lt*w,xr=pr*w,pi=Nt*Nt+Vt*Vt+Ar*Ar,Zr=Nt*Qt+Vt*_t+Ar*Ur,vr=Nt*Rt+Vt*mr+Ar*xr,mi=Qt*Qt+_t*_t+Ur*Ur,Yr=Qt*Rt+_t*mr+Ur*xr,Ai=Rt*Rt+mr*mr+xr*xr,Br=p;a[Br+0]=pi,a[Br+1]=Zr,a[Br+2]=vr,a[Br+3]=Ai;const Ui=ri(mi)&65535,xi=ri(Yr)&65535;i[p+3]=Ui|xi<<16}this.transformA=new Gh().create(e,t,i),this.transformA.name="transformA",this.transformA.minFilter="nearest",this.transformA.magFilter="nearest",this.transformA.addressModeU="clamp-to-edge",this.transformA.addressModeV="clamp-to-edge",this.transformB=new _o().create(e,t,a,!1),this.transformB.name="transformB",this.transformB.minFilter="nearest",this.transformB.magFilter="nearest",this.transformB.mipmapFilter="nearest",this.transformB.addressModeU="clamp-to-edge",this.transformB.addressModeV="clamp-to-edge"}updateWorldPositions(){if(!this._positions)return;const s=this.object3D.transform.worldMatrix,e=this._positions,t=this._fullCount;this._worldPositions||(this._worldPositions=new Float32Array(e.length));const r=s.rawData;for(let i=0;i<t;i++){const a=i*3,o=e[a+0],n=e[a+1],l=e[a+2];this._worldPositions[a+0]=r[0]*o+r[4]*n+r[8]*l+r[12],this._worldPositions[a+1]=r[1]*o+r[5]*n+r[9]*l+r[13],this._worldPositions[a+2]=r[2]*o+r[6]*n+r[10]*l+r[14]}this._centersSent=!1}scheduleOrder(s){if(this.count===0)return;const e=this.object3D.transform.localChange;(e||!this._worldPositions)&&this.updateWorldPositions();const t=s.rawData,r=t[2],i=t[6],a=t[10],o=-(t[0]*t[12]+t[1]*t[13]+t[2]*t[14]),n=-(t[4]*t[12]+t[5]*t[13]+t[6]*t[14]),l=-(t[8]*t[12]+t[9]*t[13]+t[10]*t[14]),h=performance.now(),u=(h-this._lastSentTime)/1e3,c=Math.floor(o*1e3)^Math.floor(n*1e3)^Math.floor(l*1e3),f=Math.floor(r*1e3)^Math.floor(i*1e3)^Math.floor(a*1e3),g=c^f;if(g===this._lastViewMatrixHash&&!e)return;let p=this._minIntervalMs;if(this._adaptiveSorting&&this._minIntervalMs>0){const U=Math.abs(g-this._lastViewMatrixHash)/Math.max(u,.001);U<1e3?p=this._minIntervalMs:U<1e4?p=this._minIntervalMs*.5:p=this._minIntervalMs*.2,this._lastCameraSpeed=U}if(!(h-this._lastSentTime<p)){if(this._lastViewMatrixHash=g,this._lastSentTime=h,!this._sortWorker){this._sortWorker=this.createSortWorker(),this._sortWorker.onmessage=v=>{const S=v.data.order,C=this._orderData.buffer;this._sortWorker.postMessage({order:C},[C]);const _=new Uint32Array(S),y=this.size.x*this.size.y,b=this.count;(!this._orderData||this._orderData.length!==y)&&(this._orderData=new Uint32Array(y));const w=Math.min(b,_.length);if(this._orderData.set(_.subarray(0,w),0),w<y){const N=b>0?b-1:0;this._orderData.fill(N,w,y)}this.splatOrder.updateTexture(this.size.x,this.size.y,this._orderData);const R=Math.max(0,Math.min(this.count,v.data.count|0));this.texParams[2]=R;const E=Math.ceil(R/this._batchSize);this.instanceCount=E};const A=this._worldPositions||this._positions,U=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(A);if(this._mapping)for(let v=0;v<this._mapping.length;++v){const S=this._mapping[v]*3,C=v*3;U[C+0]=A[S+0],U[C+1]=A[S+1],U[C+2]=A[S+2]}const x=new Uint32Array(this.count);for(let v=0;v<this.count;v++)x[v]=v;this._sortWorker.postMessage({order:x.buffer,centers:U.buffer,mapping:this._mapping},[x.buffer,U.buffer]),this._centersSent=!0}if(!this._centersSent&&this._sortWorker){const A=this._worldPositions||this._positions,U=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(A);if(this._mapping)for(let x=0;x<this._mapping.length;++x){const v=this._mapping[x]*3,S=x*3;U[S+0]=A[v+0],U[S+1]=A[v+1],U[S+2]=A[v+2]}this._sortWorker.postMessage({type:"centers",centers:U.buffer,mapping:this._mapping?this._mapping:null},[U.buffer]),this._centersSent=!0}this._sortWorker.postMessage({cameraPosition:{x:o,y:n,z:l},cameraDirection:{x:-r,y:-i,z:-a}})}}createSortWorker(){function s(){let o,n,l,h,u,c=!1;const f={x:0,y:0,z:0},g={x:0,y:0,z:0},p={x:0,y:0,z:0},A={x:0,y:0,z:0};let U,x;const v=(C,_,y)=>{for(;C<=_;){const b=_+C>>1,w=y(b);if(w>0)C=b+1;else if(w<0)_=b-1;else return b}return~C},S=()=>{if(!o||!n||!h||!u)return;const C=h.x,_=h.y,y=h.z,b=u.x,w=u.y,R=u.z,E=.001;if(!c&&Math.abs(C-f.x)<E&&Math.abs(_-f.y)<E&&Math.abs(y-f.z)<E&&Math.abs(b-g.x)<E&&Math.abs(w-g.y)<E&&Math.abs(R-g.z)<E)return;c=!1,f.x=C,f.y=_,f.z=y,g.x=b,g.y=w,g.z=R;const N=n.length/3;U?.length!==N&&(U=new Uint32Array(N));let z,Y;for(let J=0;J<8;++J){const ce=(J&1?p.x:A.x)-C,he=(J&2?p.y:A.y)-_,Ue=(J&4?p.z:A.z)-y,xe=ce*b+he*w+Ue*R;J===0?z=Y=xe:(z=Math.min(z,xe),Y=Math.max(Y,xe))}x?x.fill(0):x=new Uint32Array(65537);const ee=Y-z,oe=ee<1e-6?0:1/ee*2**16;for(let J=0;J<N;++J){const ce=J*3,he=n[ce+0]-C,Ue=n[ce+1]-_,xe=n[ce+2]-y,Ve=he*b+Ue*w+xe*R,Ee=Math.floor((Ve-z)*oe);U[J]=Ee,x[Ee]++}for(let J=1;J<65537;J++)x[J]+=x[J-1];for(let J=0;J<N;J++){const ce=U[J],he=--x[ce];o[he]=J}const te=J=>U[o[J]]/oe+z,ge=()=>{const J=v(0,N-1,ce=>-te(ce));return Math.min(N,Math.abs(J))},Ce=te(N-1)>=0?ge():N;if(l)for(let J=0;J<N;++J)o[J]=l[o[J]];self.postMessage({order:o.buffer,count:Ce},[o.buffer]),o=null};self.onmessage=C=>{if(C.data.order&&(o=new Uint32Array(C.data.order)),C.data.centers){n=new Float32Array(C.data.centers),p.x=A.x=n[0],p.y=A.y=n[1],p.z=A.z=n[2];const _=n.length/3;for(let y=1;y<_;++y){const b=n[y*3+0],w=n[y*3+1],R=n[y*3+2];p.x=Math.min(p.x,b),p.y=Math.min(p.y,w),p.z=Math.min(p.z,R),A.x=Math.max(A.x,b),A.y=Math.max(A.y,w),A.z=Math.max(A.z,R)}c=!0}C.data.hasOwnProperty("mapping")&&(l=C.data.mapping?new Uint32Array(C.data.mapping):null,c=!0),C.data.cameraPosition&&(h=C.data.cameraPosition),C.data.cameraDirection&&(u=C.data.cameraDirection),S()}}const e=`(${s.toString()})()`,t=new Blob([e],{type:"application/javascript"}),r=URL.createObjectURL(t);return new Worker(r)}nodeUpdate(s,e,t,r){const i=this.object3D.transform.worldMatrix;this.gsplatMaterial.setTransformMatrix(i);const a=`${this._minPixelCoverage},${this._maxPixelCoverage},${this._maxPixelCullDistance},${this._batchSize}`;a!==this._lastPixelCullParams&&(this.gsplatMaterial.setPixelCulling(this._minPixelCoverage,this._maxPixelCoverage,this._maxPixelCullDistance,this._batchSize),this._lastPixelCullParams=a),this._texturesInitialized||(this.gsplatMaterial.setSplatTextures(this.splatColor,this.transformA,this.transformB,this.texParams,this.splatOrder),this._texturesInitialized=!0),super.nodeUpdate(s,e,t,r)}renderPass(s,e,t){const r=t.encoder;for(let i of this.materials){const a=i.getPass(e);if(!(!a||a.length===0))for(const o of a){if(!o.pipeline)continue;o.apply(this.geometry,t.rendererPassState||t),F.bindPipeline(r,o),F.bindGeometryBuffer(r,this.geometry);const l=this.geometry.subGeometries[0].lodLevels[0];this.instanceCount>0?F.drawIndexed(r,l.indexCount,this.instanceCount,l.indexStart,0,0):F.drawIndexed(r,l.indexCount,1,l.indexStart,0,0)}}}destroy(s){this._sortWorker&&(this._sortWorker.terminate(),this._sortWorker=null),super.destroy(s)}};ga=Yg([Pt(ga,"GSplatRenderer")],ga);class Fo{static maxVector=new d(Number.MAX_VALUE*.1,Number.MAX_VALUE*.1,Number.MAX_VALUE*.1);static minVector=this.maxVector.clone().multiplyScalar(-1);static genMeshMaxVector=d.ZERO.clone();static genMeshMinVector=d.ZERO.clone();static genMeshVectorList8=[new d,new d,new d,new d,new d,new d,new d,new d];static genGSplatBounds(e,t){t||=new Fe(d.ZERO,d.ZERO),t.setFromMinMax(this.maxVector,this.minVector);let r=e.getComponent(ga);if(!r)return console.warn("genGSplatBounds: No GSplatRenderer found on object"),t;const i=r.positions,a=r.fullCount;if(!i||a===0)return console.warn("genGSplatBounds: No position data available"),t;const o=e.transform.worldMatrix,n=new d;for(let l=0;l<a;l++){const h=l*3;n.set(i[h+0],i[h+1],i[h+2]),o.transformPoint(n,n),t.expandByPoint(n)}return t.setFromMinMax(t.min,t.max),t}static genMeshBounds(e,t){let r=this.genMeshMinVector,i=this.genMeshMaxVector,a=this.genMeshVectorList8;t||=new Fe(d.ZERO,d.ZERO),t.setFromMinMax(this.maxVector,this.minVector);let o=e.getComponents(K);for(const n of o)if(n&&n.geometry){let l=n.object3D.transform.worldMatrix;r.copy(n.geometry.bounds.min),i.copy(n.geometry.bounds.max),a[0].set(r.x,r.y,r.z),a[1].set(r.x,r.y,i.z),a[2].set(r.x,i.y,r.z),a[3].set(r.x,i.y,i.z),a[4].set(i.x,r.y,r.z),a[5].set(i.x,r.y,i.z),a[6].set(i.x,i.y,r.z),a[7].set(i.x,i.y,i.z);for(const h of a)l.transformPoint(h,h),t.expandByPoint(h)}return i.copyFrom(t.max),r.copyFrom(t.min),t.setFromMinMax(r,i),t}static transformBound(e,t,r){let i=this.genMeshMinVector.copyFrom(t.min),a=this.genMeshMaxVector.copyFrom(t.max),o=this.genMeshVectorList8;r||=new Fe(d.ZERO,d.ZERO),r.setFromMinMax(this.maxVector,this.minVector),o[0].set(i.x,i.y,i.z),o[1].set(i.x,i.y,a.z),o[2].set(i.x,a.y,i.z),o[3].set(i.x,a.y,a.z),o[4].set(a.x,i.y,i.z),o[5].set(a.x,i.y,a.z),o[6].set(a.x,a.y,i.z),o[7].set(a.x,a.y,a.z);for(const n of o)e.transformPoint(n,n),r.expandByPoint(n);return a.copyFrom(r.max),i.copyFrom(r.min),r.setFromMinMax(i,a),r}}class Zh extends Er{name="";_instanceID="";_numChildren;get instanceID(){return this._instanceID}transform;renderNode;entityChildren;components;waitDisposeComponents;_bound;_boundWorld;_isBoundChange=!0;_dispose=!1;get dispose(){return this._dispose}getObjectByName(e){if(e.indexOf("/")>=0){let r=e.split("/"),i=this;for(;r.length>0&&i;){let a=r.shift();if(i=i.getChildByName(a,!1),!i)return null}return i}else return this.getChildByName(e,!1)}constructor(){super(),this.entityChildren=[],this.components=new Map,this._instanceID=$s().toString(),this.waitDisposeComponents=[]}get numChildren(){return this._numChildren}addChild(e){if(e==null)throw new Error("child is null!");if(e===this)throw new Error("child is self!");return this.entityChildren.indexOf(e)==-1?(e.removeFromParent(),e.transform.parent=this.transform,this.entityChildren.push(e),this._numChildren=this.entityChildren.length,this.noticeComponents("onAddChild",e),e):null}removeChild(e){if(e===null)return;if(e===this)throw new Error("add child is self!");let t=this.entityChildren.indexOf(e);t!=-1&&(this.entityChildren.splice(t,1),e.transform.parent=null,this._numChildren=this.entityChildren.length,this.noticeComponents("onRemoveChild",e))}removeAllChild(){for(;this.numChildren>0;)this.removeChild(this.entityChildren[0])}removeSelf(){return this.removeFromParent()}removeChildByIndex(e){e>=0&&e<this.entityChildren.length?this.removeChild(this.entityChildren[e]):console.error("remove child by index , index out of range")}hasChild(e){return this.entityChildren.indexOf(e)!=-1}removeFromParent(){let e=this.transform.parent;return e&&e.object3D&&e.object3D.removeChild(this),this}getChildByIndex(e){let t=null;return e<this.entityChildren.length&&(t=this.entityChildren[e]),t}getChildByName(e,t=!0){let r=null;for(const i of this.entityChildren){if(i.name==e)return r=i,r;if(t&&(r=i.getChildByName(e,t),r))return r}return r}update(){}instantiate(){return null}onTransformLocalChange(e){this._isBoundChange=!0}get bound(){return(this._isBoundChange||!this._bound)&&this.updateBound(),this._boundWorld}set bound(e){this._bound=e,this._boundWorld=this._bound.clone(),this._isBoundChange=!0}updateBound(){return this._bound||(this._bound=new Fe,this._boundWorld=this._bound.clone(),this._isBoundChange=!0),this._isBoundChange&&(Fo.transformBound(this.transform.worldMatrix,this._bound,this._boundWorld),this._isBoundChange=!1),this._boundWorld}waitUpdate(){this._dispose?(this.transform.parent&&this.transform.parent.object3D.removeChild(this),this.components.forEach((e,t)=>{e.enable=!1,e.beforeDestroy(),e.destroy()}),this.components.clear()):Se.waitStartComponent.forEach((e,t)=>{for(;e.length>0;){const r=e.shift();r.__start(),Se.waitStartComponent.delete(r.object3D)}})}noticeComponents(e,t){for(let r of this.components.values())r[e]?.(t)}destroy(e){this._dispose||(this.components.forEach(t=>{t.beforeDestroy(e)}),this.components.forEach(t=>{t.destroy(e)}),this.components.clear(),this.entityChildren.forEach(t=>{t.destroy(e)}),this.removeAllChild(),this.transform.parent=null,this._dispose=!0,super.destroy())}}var Xg=Object.getOwnPropertyDescriptor,Hg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Xg(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=o(i)||i);return i};let q=class extends Zh{_isScene3D;prefabRef;serializeTag;constructor(){super(),this.transform=this.addComponent(Dt),this.transform.eventDispatcher.addEventListener(Dt.LOCAL_ONCHANGE,this.onTransformLocalChange,this)}get isScene3D(){return this._isScene3D}forChild(s){this.entityChildren.forEach(e=>{s(e),e.forChild(s)})}addComponent(s,e){if(!this.components.has(s)){let t=new s;return t.object3D=this,this.components.set(s,t),t.__init(e),Se.appendWaitStart(t),t}return this.components.get(s)}getOrAddComponent(s){let e=this.components.get(s);return e||(e=this.addComponent(s)),e}removeComponent(s){if(this.components.has(s)){let e=this.components.get(s);Se.removeWaitStart(this,e),this.components.delete(s),e.__stop(),e.beforeDestroy(),e.destroy()}}hasComponent(s){return this.components.has(s)}getComponent(s){return this.components.get(s)}getComponentFromParent(s){if(!this.parent)return null;let e=this.parent.object3D.getComponent(s);return e||this.parent.object3D.getComponentFromParent(s)}getComponentsInChild(s){let e=[],t=this.components.get(s);t&&e.push(t);for(let r=0;r<this.entityChildren.length;r++){let a=this.entityChildren[r].getComponentsInChild(s);e.push(...a)}return e}getComponents(s,e,t){e||=[];let r=this.getComponent(s);r&&(r.enable||t)&&e.push(r);for(let i=0,a=this.entityChildren.length;i<a;i++){let o=this.entityChildren[i];o&&o instanceof q&&o.getComponents(s,e,t)}return e}getComponentsExt(s,e,t){e||=[];let r=this.components.get(s);if(r&&(r.enable||t))e.push(r);else for(const i of this.entityChildren)i instanceof q&&i.getComponentsExt(s,e,t);return e}getComponentsByProperty(s,e,t=!0,r,i){r||=[];let a;for(const o of this.components.values())o&&(o.enable||i)&&o[s]===e&&(r.push(o),a=!0);if(!(a&&t))for(const o of this.entityChildren)o instanceof q&&o.getComponentsByProperty(s,e,t,r,i);return r}clone(){return this.instantiate()}instantiate(){let s=new q;return s.name=this.name,s.serializeTag=this.serializeTag,s.prefabRef=this.prefabRef,this.entityChildren.forEach((e,t)=>{let r=e.instantiate();s.addChild(r)}),this.components.forEach((e,t)=>{e.cloneTo(s)}),s}get localPosition(){return this.transform.localPosition}set localPosition(s){this.transform.localPosition=s}get localRotation(){return this.transform.localRotation}set localRotation(s){this.transform.localRotation=s}get localScale(){return this.transform.localScale}set localScale(s){this.transform.localScale=s}get localQuaternion(){return this.transform.localRotQuat}set localQuaternion(s){this.transform.localRotQuat=s}notifyChange(){this.transform.notifyChange()}get parent(){return this.transform.parent}get parentObject(){return this.transform.parent.object3D}set x(s){this.transform.x=s}get x(){return this.transform.x}set y(s){this.transform.y=s}get y(){return this.transform.y}set z(s){this.transform.z=s}get z(){return this.transform.z}set scaleX(s){this.transform.scaleX=s}get scaleX(){return this.transform.scaleX}set scaleY(s){this.transform.scaleY=s}get scaleY(){return this.transform.scaleY}set scaleZ(s){this.transform.scaleZ=s}get scaleZ(){return this.transform.scaleZ}set rotationX(s){this.transform.rotationX=s}get rotationX(){return this.transform.rotationX}set rotationY(s){this.transform.rotationY=s}get rotationY(){return this.transform.rotationY}set rotationZ(s){this.transform.rotationZ=s}get rotationZ(){return this.transform.rotationZ}fixedUpdate(){}lateUpdate(){}traverse(s){s(this);for(let e=0,t=this.entityChildren.length;e<t;e++){let r=this.entityChildren[e];r instanceof q&&r.traverse(s)}}destroy(s){this.transform.eventDispatcher.removeEventListener(Dt.LOCAL_ONCHANGE,this.onTransformLocalChange,this),super.destroy(s)}};q=Hg([jg],q);function jg(s,e){return class extends q{set active(t){this.transform.enable=t>0}get active(){return this.transform.enable?1:0}get materialColor(){return this.getComponent(K)?.material?.shader.getDefaultColorShader().baseColor}set materialColor(t){let r=this.getComponent(K)?.material;r&&(r.shader.getDefaultColorShader().baseColor=t)}notifyMaterialColorChange(t,r){this.getComponent(K).materials?.[t]?.shader.getDefaultColorShader().uniforms[r].onChange()}}}class Ke{static createCamera3DObject(e,t){return this.createCamera3D(null,e,t)}static createCamera3D(e,t,r){return e||=new q,t&&t.addChild(e),r&&(e.name=r),e.getOrAddComponent(Ji)}static UnProjection(e,t,r=1,i){let a=new d(e,t,0),o=1,n=d.HELP_0,l=Q.canvas.offsetLeft,h=Q.canvas.offsetTop,u=Q.canvas.clientWidth,c=Q.canvas.clientHeight;n.x=((a.x-l)*o/u-.5)*2,n.y=-((a.y-h)*o/c-.5)*2,n.z=r;let f=new d(0,0,0),g=I.helpMatrix2;g.copyFrom(i.projectionMatrix),g.invert();let p=I.helpMatrix;return p.identity(),p.multiply(g),p.multiply(i.transform.worldMatrix),p.perspectiveMultiplyPoint3(n,f),f}static Projection(e,t,r){let i=r||new d(0,0,0),a=I.helpMatrix;a.copyFrom(t.viewMatrix),a.multiply(t.projectionMatrix),a.perspectiveMultiplyPoint3(e,i);let o=Q.canvas.clientWidth/2,n=Q.canvas.clientHeight/2;return i.x=i.x*o+o,i.y=n-i.y*n,i}static UnProjection2(e,t,r,i,a){let o=a||new d(0,0,0),n=I.helpMatrix;n.copyFrom(i.pvMatrixInv);let l=Q.canvas.clientWidth/2,h=Q.canvas.clientHeight/2;return o.x=(e-l)/l,o.y=(h-t)/h,o.z=r,n.perspectiveMultiplyPoint3(o,o),o}}class Tt{static maxNumDirectionShadow=8;static maxNumPointShadow=8;static directionLightList;static pointLightList;static shadowLights;static init(){this.directionLightList=new Map,this.pointLightList=new Map,this.shadowLights=new Map}static createBuffer(e){if(!this.shadowLights.has(e.scene)){let t=new Float32Array(16);this.shadowLights.set(e.scene,t)}}static getShadowLightList(e){if(!e.transform.view3D)return null;if(e.lightData.lightType==Xe.DirectionLight){let t=this.directionLightList.get(e.transform.view3D.scene);return t||(t=[],this.directionLightList.set(e.transform.view3D.scene,t)),t}else if(e.lightData.lightType==Xe.PointLight){let t=this.pointLightList.get(e.transform.view3D.scene);return t||(t=[],this.pointLightList.set(e.transform.view3D.scene,t)),t}else if(e.lightData.lightType==Xe.SpotLight){let t=this.pointLightList.get(e.transform.view3D.scene);return t||(t=[],this.pointLightList.set(e.transform.view3D.scene,t)),t}}static getShadowLightWhichScene(e,t){if(t==Xe.DirectionLight){let r=this.directionLightList.get(e);return r||(r=[],this.directionLightList.set(e,r)),r}else if(t==Xe.PointLight){let r=this.pointLightList.get(e);return r||(r=[],this.pointLightList.set(e,r)),r}}static getDirectShadowLightWhichScene(e){let t=this.directionLightList.get(e);return t||(t=[],this.directionLightList.set(e,t)),t}static getPointShadowLightWhichScene(e){let t=this.pointLightList.get(e);return t||(t=[],this.pointLightList.set(e,t)),t}static addShadowLight(e){if(!e.transform.view3D)return null;let t=e.transform.view3D.scene;if(e.lightData.lightType==Xe.DirectionLight){let r=this.directionLightList.get(t);if(r||(r=[],this.directionLightList.set(t,r)),!e.shadowCamera){e.shadowCamera=Ke.createCamera3DObject(null,"shadowCamera"),e.shadowCamera.isShadowCamera=!0;let i=-1e3;e.shadowCamera.orthoOffCenter(i,-i,i,-i,1,1e4)}return r.indexOf(e)==-1&&r.push(e),r}else if(e.lightData.lightType==Xe.PointLight||e.lightData.lightType==Xe.SpotLight){let r=this.pointLightList.get(t);return r&&r.length>=8||(r||(r=[],this.pointLightList.set(t,r)),r.indexOf(e)==-1&&r.push(e)),r}}static removeShadowLight(e){if(e.lightData.castShadowIndex=-1,!e.transform.view3D)return null;if(e.lightData.lightType==Xe.DirectionLight){let t=this.directionLightList.get(e.transform.view3D.scene);if(t){let r=t.indexOf(e);r!=-1&&t.splice(r,1)}return e.lightData.castShadowIndex=-1,t}else if(e.lightData.lightType==Xe.PointLight||e.lightData.lightType==Xe.SpotLight){let t=this.pointLightList.get(e.transform.view3D.scene);if(t){let r=t.indexOf(e);r!=-1&&t.splice(r,1)}return e.lightData.castShadowIndex=-1,t}}static update(e){let t=this.shadowLights.get(e.scene),r=Tt.directionLightList.get(e.scene),i=Tt.pointLightList.get(e.scene),a=0,o=0,n=0,l=0;if(t.fill(0),r){let u=0;for(let c=0;c<r.length;c++){const f=r[c];t[c]=f.lightData.index,f.lightData.castShadowIndex=u++}o=r.length}if(i){n=o;let u=0;for(let c=n;c<i.length;c++){const f=i[c];t[c]=f.lightData.index,f.lightData.castShadowIndex=u++}l=n+i.length}ne.getAllCameraGroup().forEach(u=>{u.dirShadowStart=a,u.dirShadowEnd=o,u.pointShadowStart=n,u.pointShadowEnd=l,u.shadowLights.set(new Float32Array(t))})}}class yo{uuid;usage;globalBindGroup;uniformGPUBuffer;matrixBindGroup;uniformByteLength;matrixesByteLength;shadowMatrixRaw=new Float32Array(128);csmMatrixRaw=new Float32Array(Zt.Cascades*16);csmShadowBias=new Float32Array(4);shadowLights=new Float32Array(16);dirShadowStart=0;dirShadowEnd=0;pointShadowStart=0;pointShadowEnd=0;constructor(e){this.uuid=It(),this.usage=GPUBufferUsage.UNIFORM|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,this.uniformGPUBuffer=new ut(8336),this.uniformGPUBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.matrixBindGroup=e,this.createBindGroup()}createBindGroup(){this.uniformByteLength=this.uniformGPUBuffer.memory.shareDataBuffer.byteLength,this.matrixesByteLength=I.block*4*I.maxCount,this.globalBindGroup=Q.device.createBindGroup({label:"global_bindGroupLayout",layout:mo.getGlobalDataBindGroupLayout(),entries:[{binding:0,resource:{buffer:this.uniformGPUBuffer.buffer,offset:0,size:this.uniformByteLength}},{binding:1,resource:{buffer:this.matrixBindGroup.matrixBufferDst.buffer,offset:0,size:this.matrixesByteLength}}]})}setCamera(e){this.uniformGPUBuffer.setMatrix("_projectionMatrix",e.projectionMatrix),this.uniformGPUBuffer.setMatrix("_viewMatrix",e.viewMatrix),this.uniformGPUBuffer.setMatrix("_cameraWorldMatrix",e.transform.worldMatrix),this.uniformGPUBuffer.setMatrix("pvMatrixInv",e.projectionMatrixInv),this.uniformGPUBuffer.setMatrix("viewToWorld",e.cameraToWorld);let t=Tt.getDirectShadowLightWhichScene(e.transform.scene3D);this.csmShadowBias.fill(1e-4),this.shadowMatrixRaw.fill(0),this.csmMatrixRaw.fill(0);for(let l=0;l<8;l++)if(l<t.length){let h=t[l].shadowCamera;this.shadowMatrixRaw.set(h.pvMatrix.rawData,l*16)}else this.shadowMatrixRaw.set(e.transform.worldMatrix.rawData,l*16);this.uniformGPUBuffer.setFloat32Array("shadowMatrix",this.shadowMatrixRaw);let r=m.setting.shadow.shadowSize;if(Zt.Cascades>1&&e.enableCSM&&t[0])for(let l=0;l<Zt.Cascades;l++){let h=e.csm.children[l].shadowCamera;this.csmMatrixRaw.set(h.pvMatrix.rawData,l*16),this.csmShadowBias[l]=e.getCSMShadowBiasScale(h)}this.uniformGPUBuffer.setFloat32Array("csmShadowBias",this.csmShadowBias),this.uniformGPUBuffer.setFloat32Array("csmMatrix",this.csmMatrixRaw),this.uniformGPUBuffer.setFloat32Array("shadowLights",this.shadowLights);let i=m.setting.reflectionSetting,a=G.instance.getReflections(e.transform.scene3D).length;this.uniformGPUBuffer.setFloat("reflectionProbeSize",i.reflectionProbeSize),this.uniformGPUBuffer.setFloat("reflectionProbeMaxCount",i.reflectionProbeMaxCount),this.uniformGPUBuffer.setFloat("reflectionMapWidth",i.width),this.uniformGPUBuffer.setFloat("reflectionMapHeight",i.height),this.uniformGPUBuffer.setFloat("reflectionCount",a),this.uniformGPUBuffer.setFloat("test2",Ye.testObj.testValue2),this.uniformGPUBuffer.setFloat("test3",Ye.testObj.testValue3),this.uniformGPUBuffer.setFloat("test4",Ye.testObj.testValue4),this.uniformGPUBuffer.setVector3("CameraPos",e.transform.worldPosition),this.uniformGPUBuffer.setFloat("frame",Qe.frame),this.uniformGPUBuffer.setFloat32Array("SH",e.sh),this.uniformGPUBuffer.setFloat("time",Qe.time),this.uniformGPUBuffer.setFloat("delta",Qe.delta),this.uniformGPUBuffer.setFloat("shadowBias",e.getShadowBias(r)),this.uniformGPUBuffer.setFloat("skyExposure",m.setting.sky.skyExposure),this.uniformGPUBuffer.setFloat("renderPassState",m.setting.render.renderPassState),this.uniformGPUBuffer.setFloat("quadScale",m.setting.render.quadScale),this.uniformGPUBuffer.setFloat("hdrExposure",m.setting.render.hdrExposure),this.uniformGPUBuffer.setInt32("renderState_left",m.setting.render.renderState_left),this.uniformGPUBuffer.setInt32("renderState_right",m.setting.render.renderState_right),this.uniformGPUBuffer.setFloat("renderState_split",m.setting.render.renderState_split);let o=m.inputSystem.mouseX*Q.pixelRatio,n=m.inputSystem.mouseY*Q.pixelRatio;this.uniformGPUBuffer.setFloat("mouseX",o),this.uniformGPUBuffer.setFloat("mouseY",n),this.uniformGPUBuffer.setFloat("windowWidth",Q.windowWidth),this.uniformGPUBuffer.setFloat("windowHeight",Q.windowHeight),this.uniformGPUBuffer.setFloat("near",e.near),this.uniformGPUBuffer.setFloat("far",e.far),this.uniformGPUBuffer.setFloat("pointShadowBias",m.setting.shadow.pointShadowBias),this.uniformGPUBuffer.setFloat("shadowMapSize",r),this.uniformGPUBuffer.setFloat("shadowSoft",m.setting.shadow.shadowSoft),this.uniformGPUBuffer.setFloat("enableCSM",e.enableCSM?1:0),this.uniformGPUBuffer.setFloat("csmMargin",m.setting.shadow.csmMargin),this.uniformGPUBuffer.setInt32("nDirShadowStart",this.dirShadowStart),this.uniformGPUBuffer.setInt32("nDirShadowEnd",this.dirShadowEnd),this.uniformGPUBuffer.setInt32("nPointShadowStart",this.pointShadowStart),this.uniformGPUBuffer.setInt32("nPointShadowEnd",this.pointShadowEnd),this.uniformGPUBuffer.setVector3("cameraForward",e.transform.forward),this.uniformGPUBuffer.setVector4Array("frustumPlanes",e.frustum.planes),this.uniformGPUBuffer.apply()}setShadowCamera(e){this.uniformGPUBuffer.setMatrix("_projectionMatrix",e.projectionMatrix),this.uniformGPUBuffer.setMatrix("_viewMatrix",e.viewMatrix),this.uniformGPUBuffer.setMatrix("_pvMatrix",e.pvMatrix),this.uniformGPUBuffer.setMatrix("pvMatrixInv",e.projectionMatrixInv),this.uniformGPUBuffer.setMatrix("viewToWorld",e.cameraToWorld),this.csmShadowBias.fill(1e-4),this.shadowMatrixRaw.fill(0),this.csmMatrixRaw.fill(0),this.uniformGPUBuffer.setFloat32Array("shadowCamera",this.shadowMatrixRaw),this.uniformGPUBuffer.setFloat32Array("csmShadowBias",this.csmShadowBias),this.uniformGPUBuffer.setFloat32Array("csmMatrix",this.csmMatrixRaw),this.uniformGPUBuffer.setFloat32Array("shadowLights",this.shadowLights),this.uniformGPUBuffer.setVector3("CameraPos",e.transform.worldPosition),this.uniformGPUBuffer.setFloat("frame",Qe.frame),this.uniformGPUBuffer.setFloat32Array("SH",e.sh),this.uniformGPUBuffer.setFloat("time",Qe.time),this.uniformGPUBuffer.setFloat("delta",Qe.delta),this.uniformGPUBuffer.setFloat("shadowBias",m.setting.shadow.shadowBias),this.uniformGPUBuffer.setFloat("skyExposure",m.setting.sky.skyExposure),this.uniformGPUBuffer.setFloat("renderPassState",m.setting.render.renderPassState),this.uniformGPUBuffer.setFloat("quadScale",m.setting.render.quadScale),this.uniformGPUBuffer.setFloat("hdrExposure",m.setting.render.hdrExposure),this.uniformGPUBuffer.setInt32("renderState_left",m.setting.render.renderState_left),this.uniformGPUBuffer.setInt32("renderState_right",m.setting.render.renderState_right),this.uniformGPUBuffer.setFloat("renderState_split",m.setting.render.renderState_split);let t=m.inputSystem.mouseX*Q.pixelRatio,r=m.inputSystem.mouseY*Q.pixelRatio;this.uniformGPUBuffer.setFloat("mouseX",t),this.uniformGPUBuffer.setFloat("mouseY",r),this.uniformGPUBuffer.setFloat("windowWidth",Q.windowWidth),this.uniformGPUBuffer.setFloat("windowHeight",Q.windowHeight),this.uniformGPUBuffer.setFloat("near",e.near),this.uniformGPUBuffer.setFloat("far",e.far),this.uniformGPUBuffer.setFloat("pointShadowBias",m.setting.shadow.pointShadowBias),this.uniformGPUBuffer.setFloat("shadowMapSize",m.setting.shadow.shadowSize),this.uniformGPUBuffer.setFloat("shadowSoft",m.setting.shadow.shadowSoft),this.uniformGPUBuffer.setFloat("enableCSM",0),this.uniformGPUBuffer.setFloat("csmMargin",m.setting.shadow.csmMargin),this.uniformGPUBuffer.setInt32("nDirShadowStart",this.dirShadowStart),this.uniformGPUBuffer.setInt32("nDirShadowEnd",this.dirShadowEnd),this.uniformGPUBuffer.setInt32("nPointShadowStart",this.pointShadowStart),this.uniformGPUBuffer.setInt32("nPointShadowEnd",this.pointShadowEnd),this.uniformGPUBuffer.apply()}setShadowLight(){}}class Yh{setting;probesBufferData;probesBuffer;isVolumeFrameChange=!0;randomOrientation;startPosition=new d;isVolumeChange=!0;irradianceVolumeBuffer;directionDistance=20;randomSeedCount=3;useRandomIndex=0;centerDirection=new d(0,0,this.directionDistance).normalize(1);arroundPositions=[];updateOrientation(){return this.useRandomIndex++,this.useRandomIndex>=this.arroundPositions.length&&(this.useRandomIndex=0),I.fromToRotation(this.centerDirection,this.arroundPositions[this.useRandomIndex],this.randomOrientation),this.randomOrientation}init(e){this.setting=e,this.randomOrientation=new I(!1),this.randomOrientation.identity(),this.irradianceVolumeBuffer=new ut(80),this.createFramesBuffer(),this.arroundPositions.push(this.centerDirection.clone());for(let t=0;t<this.randomSeedCount;t++){let r=Math.PI*2*t/this.randomSeedCount,i=new d(Math.sin(r),Math.cos(r),this.directionDistance).normalize(1);this.arroundPositions.push(i)}}setVolumeDataChange(){this.isVolumeChange=!0}updateProbes(e){let t=this.probesBufferData;for(let r of e){let i=r.index*4;t[i+3]=r.drawCallFrame}}createFramesBuffer(){if(!this.probesBufferData){let e=this.setting.probeXCount*this.setting.probeYCount*this.setting.probeZCount;this.probesBufferData=new Float32Array(e*4),this.probesBufferData.fill(-1),this.probesBuffer=new Be(e*4,GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST)}}uploadBuffer(){this.isVolumeChange&&(this.fillIrradianceData(),this.isVolumeChange=!1,this.isVolumeFrameChange=!0),this.probesBuffer.setFloat32Array("uniformFramesBuffer",this.probesBufferData)}calcPosition(e,t,r,i){let a=this.setting,o=this.setting.probeSpace;return i=i||new d,i.x=e*o-o*(a.probeXCount-1)*.5+a.offsetX,i.y=t*o-o*(a.probeYCount-1)*.5+a.offsetY,i.z=r*o-o*(a.probeZCount-1)*.5+a.offsetZ,i}debugX=0;debugY=0;debugZ=0;fillIrradianceData(){let e=this.setting,t=this.calcPosition(0,0,0,this.startPosition);this.irradianceVolumeBuffer.setFloat("orientationIndex",this.randomOrientation.index),this.irradianceVolumeBuffer.setFloat("hysteresis",e.hysteresis),this.irradianceVolumeBuffer.setFloat("OctRTSideSize",e.octRTSideSize),this.irradianceVolumeBuffer.setFloat("OctRTMaxSize",e.octRTMaxSize),this.irradianceVolumeBuffer.setFloat("startX",t.x),this.irradianceVolumeBuffer.setFloat("startY",t.y),this.irradianceVolumeBuffer.setFloat("startZ",t.z),this.irradianceVolumeBuffer.setFloat("ProbeSpace",e.probeSpace),this.irradianceVolumeBuffer.setFloat("probeXCount",e.probeXCount),this.irradianceVolumeBuffer.setFloat("probeYCount",e.probeYCount),this.irradianceVolumeBuffer.setFloat("probeZCount",e.probeZCount),this.irradianceVolumeBuffer.setFloat("maxDistance",e.probeSpace*1.732),this.irradianceVolumeBuffer.setFloat("depthSharpness",e.depthSharpness),this.irradianceVolumeBuffer.setFloat("ProbeSourceTextureSize",e.probeSourceTextureSize),this.irradianceVolumeBuffer.setFloat("ProbeSize",e.probeSize),this.irradianceVolumeBuffer.setFloat("bounceIntensity",e.bounceIntensity),this.irradianceVolumeBuffer.setFloat("probeRoughness",e.probeRoughness),this.irradianceVolumeBuffer.setFloat("normalBias",e.normalBias),this.irradianceVolumeBuffer.setFloat("irradianceChebyshevBias",e.irradianceChebyshevBias),this.irradianceVolumeBuffer.setFloat("rayNumber",e.rayNumber),this.irradianceVolumeBuffer.setFloat("irradianceDistanceBias",e.irradianceDistanceBias),this.irradianceVolumeBuffer.setFloat("indirectIntensity",e.indirectIntensity),this.irradianceVolumeBuffer.setFloat("ddgiGamma",e.ddgiGamma),this.irradianceVolumeBuffer.setFloat("lerpHysteresis",e.lerpHysteresis),this.irradianceVolumeBuffer.setFloat("debugX",this.debugX),this.irradianceVolumeBuffer.setFloat("debugY",this.debugY),this.irradianceVolumeBuffer.setFloat("debugZ",this.debugZ),this.irradianceVolumeBuffer.apply()}}class Xh{storageGPUBuffer;irradianceVolume;_lightList=[];constructor(){this.storageGPUBuffer=new Be(fs.lightSize*m.setting.light.maxLight,GPUBufferUsage.COPY_SRC),this.irradianceVolume=new Yh,this.irradianceVolume.init(m.setting.gi);for(let e=0;e<m.setting.light.maxLight;e++){let t=this.storageGPUBuffer.memory.allocation_node(fs.lightSize*4);this._lightList.push(t)}this.storageGPUBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE}update(e){this.storageGPUBuffer.clean();let t=G.instance.getLights(e.scene);for(let r=0;r<t.length;r++){const i=t[r].lightData;i.index=r,this.writeLightBytes(i,this._lightList[r])}this.storageGPUBuffer.apply()}writeLightBytes(e,t){t.offset=0,t.writeFloat(e.index),t.writeInt32(e.lightType),t.writeFloat(e.radius),t.writeFloat(e.linear),t.writeVector3(e.lightPosition),t.writeFloat(e.lightMatrixIndex),t.writeVector3(e.direction),t.writeFloat(e.quadratic),t.writeRGBColor(e.lightColor),t.writeFloat(e.intensity),t.writeFloat(e.innerAngle),t.writeFloat(e.outerAngle),t.writeFloat(e.range),t.writeInt32(e.castShadowIndex),t.writeVector3(e.lightTangent),t.writeFloat(e.iesIndex)}}class Hh{storageGPUBuffer;reflectionMap;sourceReflectionMap;count;constructor(){this.storageGPUBuffer=new Be(768)}update(e){this.storageGPUBuffer.clean();let t=G.instance.getReflections(e.scene);for(let r=0;r<t.length;r++){const i=t[r];i.gid=r,this.storageGPUBuffer.setFloat("gid",i.gid),this.storageGPUBuffer.setVector3("worldPosition",i.transform.worldPosition),this.storageGPUBuffer.setFloat("radius",i.radius),this.storageGPUBuffer.setVector3("bound",i.transform.worldPosition)}this.count=t.length,this.storageGPUBuffer.apply()}}class jh extends Tr{size;constructor(e,t=0,r){super(),this.bufferType=tr.StorageGPUBuffer,this.size=e,this.createBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|t,e,r,"MatrixGPUBuffer")}writeBufferByHeap(e,t){let r;e instanceof Float64Array?r=new Float32Array(e):r=e;let i=Q.device;if(r.length>0){let a=null;for(;this.mapAsyncReady.length&&(a=this.mapAsyncReady.shift(),a.usedSize!=r.byteLength);)a.destroy(),this.mapAsyncBuffersOutstanding--,a=null;a||(a=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,mappedAtCreation:!0}),a.usedSize=r.byteLength,this.mapAsyncBuffersOutstanding++,this.mapAsyncBuffersOutstanding>10&&console.warn(` Warning: mapAsync requests from ${this.mapAsyncBuffersOutstanding} frames ago have not resolved yet. MB of staging buffers allocated.`));let o=new Float32Array(r.buffer,r.byteOffset,t);new Float32Array(a.getMappedRange(0,t*4)).set(o),a.unmap();const l=i.createCommandEncoder();l.copyBufferToBuffer(a,0,this.buffer,0,t*4),i.queue.submit([l.finish()]),a.mapAsync(GPUMapMode.WRITE).then(()=>this.mapAsyncReady.push(a))}}}class Kh{uuid;index;usage;groupBufferSize;matrixBufferDst;constructor(){this.uuid=It(),this.groupBufferSize=0,this.usage=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,this.cacheWorldMatrix()}cacheWorldMatrix(){this.groupBufferSize=I.maxCount*I.blockBytes,this.matrixBufferDst=new jh(this.groupBufferSize/4),this.matrixBufferDst.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.matrixBufferDst.buffer.label=this.groupBufferSize.toString()}writeBuffer(e){const t=I.dynamicMatrixBytes;this.matrixBufferDst.mapAsyncWrite(t,e)}}class ne{static _cameraBindGroups;static _lightEntriesMap;static _reflectionEntriesMap;static modelMatrixBindGroup;static init(){this.modelMatrixBindGroup=new Kh,this._cameraBindGroups=new Map,this._lightEntriesMap=new Map,this._reflectionEntriesMap=new Map}static getAllCameraGroup(){return this._cameraBindGroups}static getCameraGroup(e){let t=this._cameraBindGroups.get(e);return t||(t=new yo(this.modelMatrixBindGroup),this._cameraBindGroups.set(e,t)),e.isShadowCamera?t.setShadowCamera(e):t.setCamera(e),t}static updateCameraGroup(e){let t=this._cameraBindGroups.get(e);t||(t=new yo(this.modelMatrixBindGroup),this._cameraBindGroups.set(e,t)),e.isShadowCamera?t.setShadowCamera(e):t.setCamera(e)}static getLightEntries(e){e||console.log("getLightEntries scene is null");let t=this._lightEntriesMap.get(e);return t||(t=new Xh,this._lightEntriesMap.set(e,t)),this._lightEntriesMap.get(e)}static getReflectionEntries(e){e||console.log("getLightEntries scene is null");let t=this._reflectionEntriesMap.get(e);return t||(t=new Hh,this._reflectionEntriesMap.set(e,t)),this._reflectionEntriesMap.get(e)}}class F{static lastGeometry;static lastPipeline;static lastShader;static drawCount=0;static renderPassCount=0;static geometryCount=0;static pipelineCount=0;static matrixCount=0;static lastRenderPassState;static LastCommand;static bindPipeline(e,t){if(F.lastShader!=t)F.lastShader=t;else return!1;F.lastPipeline!=t.pipeline&&(F.lastPipeline=t.pipeline,e.setPipeline(t.pipeline));for(let r=1;r<t.bindGroups.length;r++){const i=t.bindGroups[r];i&&e.setBindGroup(r,i)}return!0}static bindCamera(e,t){let r=ne.getCameraGroup(t);e.setBindGroup(0,r.globalBindGroup)}static bindGeometryBuffer(e,t){if(this.lastGeometry!=t&&(this.lastGeometry=t,t.indicesBuffer)){e.setIndexBuffer(t.indicesBuffer.indicesGPUBuffer.buffer,t.indicesBuffer.indicesFormat);let r=t.vertexBuffer.vertexGPUBuffer,i=t.vertexBuffer.vertexBufferLayouts;for(let a=0;a<i.length;a++){const o=i[a];e.setVertexBuffer(a,r.buffer,o.offset,o.size)}}}static cleanCache(){this.lastGeometry=null,this.lastPipeline=null,this.lastShader=null}static createPipeline(e){return Ye.countStart("GPUContext","pipeline"),Q.device.createRenderPipeline(e)}static beginCommandEncoder(){return Ye.countStart("GPUContext","beginCommandEncoder"),this.LastCommand&&Q.device.queue.submit([this.LastCommand.finish()]),this.LastCommand=Q.device.createCommandEncoder(),this.LastCommand}static endCommandEncoder(e){this.LastCommand==e&&(Q.device.queue.submit([this.LastCommand.finish()]),this.LastCommand=null,Ye.countStart("GPUContext","endCommandEncoder"))}static recordBundleEncoder(e){return Q.device.createRenderBundleEncoder(e)}static beginRenderPass(e,t){if(this.cleanCache(),this.renderPassCount++,this.lastRenderPassState=t,t.depthTexture){let r=t.renderPassDescriptor.depthStencilAttachment;r.view=t.depthTexture.getGPUView()}if(t.renderTargets&&t.renderTargets.length>0){for(let r=0;r<t.renderTargets.length;++r){const i=t.renderTargets[r];let a=t.renderPassDescriptor.colorAttachments[r];t.multisample>0&&t.renderTargets.length==1?(a.view=t.multiTexture.createView(),a.resolveTarget=i.getGPUView()):a.view=i.getGPUTexture().createView()}return e.beginRenderPass(t.renderPassDescriptor)}else{let r=t.renderPassDescriptor.colorAttachments[0];return r&&(t.multisample>0?(r.view=t.multiTexture.createView(),r.resolveTarget=Q.context.getCurrentTexture().createView()):r.view=Q.context.getCurrentTexture().createView()),e.beginRenderPass(t.renderPassDescriptor)}}static drawIndexed(e,t,r,i,a,o){e.drawIndexed(t,r,i,a,o),this.drawCount++}static draw(e,t,r,i,a){e.draw(t,r,i,a),this.drawCount++}static endPass(e){e.insertDebugMarker("end"),e.end()}static computeCommand(e,t){let r=e.beginComputePass();for(let i=0;i<t.length;i++)t[i].compute(r);r.end()}static copyTexture(e,t,r){e.copyTextureToTexture({texture:t.getGPUTexture(),mipLevel:0,origin:{x:0,y:0,z:0}},{texture:r.getGPUTexture(),mipLevel:0,origin:{x:0,y:0,z:0}},{width:r.width,height:r.height,depthOrArrayLayers:1})}}class qh{source;input;output;reset(e){this.input&&this.input.destroy(),this.output&&this.output.destroy(),this.input=this.output=null,this.source=e}apply(e){if(this.source){if(!this.input){let t=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST;this.input=new Be(this.source.length,t,this.source),this.input.apply()}if(!this.output){let t=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC;this.output=new Be(e*3,t),this.output.apply()}}}}class $h{enable;morphTargetsRelative;MaxMorphTargetCount=64;_computeConfigArray;_computeConfigBuffer;_morphInfluenceArray;_morphInfluenceBuffer;_positionAttrDataGroup;_normalAttrDataGroup;_isInfluenceDirty;_morphTargetCount;_totalVertexCount;_computeShader;_computeShaders;_computeWorkGroupXY=1;_collectMorphTargetData;_blendTarget;constructor(){this._isInfluenceDirty=!0,this.generateGPUBuffer(),this._positionAttrDataGroup=new qh,this._normalAttrDataGroup=new qh}initMorphTarget(e){this._collectMorphTargetData=this.collectMorphTargetList(e),this._computeShader&&this._computeShader.destroy();let t=kt.CsMain;this._computeShader=new ue(t),this._collectMorphTargetData.mergedNormal?this._computeShader.setDefine("USE_MORPHNORMALS",!0):this._computeShader.deleteDefine("USE_MORPHNORMALS"),this._computeShaders=[this._computeShader],this._isInfluenceDirty=!0,this._morphTargetCount=this._collectMorphTargetData.mtCount,this._totalVertexCount=this._collectMorphTargetData.vCount,this._morphInfluenceArray.fill(0),this._computeWorkGroupXY=this.calcWorkGroup(this._totalVertexCount),this._positionAttrDataGroup.reset(this._collectMorphTargetData.mergedPos),this._normalAttrDataGroup.reset(this._collectMorphTargetData.mergedNormal)}applyRenderShader(e){this.uploadMorphTargetBuffer(),this.uploadConfigGBuffer(),e.setUniformBuffer("morphTargetConfig",this._computeConfigBuffer),e.setStorageBuffer("morphTargetOpPositions",this._positionAttrDataGroup.output),this._collectMorphTargetData.mergedNormal&&e.setStorageBuffer("morphTargetOpNormals",this._normalAttrDataGroup.output)}computeMorphTarget(e){this.uploadConfigGBuffer(),this.uploadMorphTargetBuffer(),this._computeShader.setUniformBuffer("morphTargetConfig",this._computeConfigBuffer),this._computeShader.setStorageBuffer("morphTargetInfluence",this._morphInfluenceBuffer),this._computeShader.setStorageBuffer("morphTargetPositions",this._positionAttrDataGroup.input),this._computeShader.setStorageBuffer("morphTargetOpPositions",this._positionAttrDataGroup.output),this._collectMorphTargetData.mergedNormal&&(this._computeShader.setStorageBuffer("morphTargetNormals",this._normalAttrDataGroup.input),this._computeShader.setStorageBuffer("morphTargetOpNormals",this._normalAttrDataGroup.output)),this._computeShader.workerSizeX=this._computeWorkGroupXY,this._computeShader.workerSizeY=this._computeWorkGroupXY,this._computeShader.workerSizeZ=1,F.computeCommand(e,this._computeShaders)}updateInfluence(e,t){this._isInfluenceDirty=!0,this._morphInfluenceArray[e]=t}get blendShape(){return this._blendTarget}collectMorphTargetList(e){let t=this.collectAttribute("a_morphPositions_",e),r=t.length,i=t[0].data.length/3;if(this._blendTarget={},e.blendShapeData)for(let l=0;l<e.blendShapeData.shapeIndexs.length;l++){let h=e.blendShapeData.shapeIndexs[l],u=e.blendShapeData.shapeNames[l].split("."),c=u[u.length-1];this._blendTarget[c]=f=>this.updateInfluence(h,f)}let a=new Float32Array(i*r*3);{let l=0;for(let h=0;h<r;h++){let u=t[h];a.set(u.data,l),l+=u.data.length}}let o=this.collectAttribute("a_morphNormals_",e),n;if(o&&o.length>0){let l=0;n=new Float32Array(i*r*3);for(let h=0;h<r;h++){let u=o[h];n.set(u.data,l),l+=u.data.length}}return{mtCount:r,vCount:i,mergedPos:a,mergedNormal:n}}collectAttribute(e,t){let r=[];for(let i=0;i<this.MaxMorphTargetCount;i++){let a=e+i,o=t.getAttribute(a);if(o)r[i]=o;else break}return r}uploadConfigGBuffer(){if(this._isInfluenceDirty){let e=0;for(let t=0;t<this._morphTargetCount;t++)e+=this._morphInfluenceArray[t];this._morphInfluenceBuffer.setFloat32Array("data",this._morphInfluenceArray),this._morphInfluenceBuffer.apply(),this._computeConfigArray[0]=this.morphTargetsRelative?1:1-e,this._computeConfigArray[1]=this._morphTargetCount,this._computeConfigArray[2]=this._totalVertexCount,this._computeConfigArray[3]=this._computeWorkGroupXY,this._computeConfigBuffer.setFloat32Array("data",this._computeConfigArray),this._computeConfigBuffer.apply(),this._isInfluenceDirty=!1}}calcWorkGroup(e){let t=Math.ceil(Math.sqrt(e)),r=Math.ceil(Math.log2(t));return t=Math.pow(2,r),t}uploadMorphTargetBuffer(){this._positionAttrDataGroup.output||this._positionAttrDataGroup.apply(this._totalVertexCount),this._normalAttrDataGroup.output||this._normalAttrDataGroup.apply(this._totalVertexCount)}generateGPUBuffer(){this._computeConfigArray=new Float32Array(4),this._computeConfigBuffer=new ut(4),this._morphInfluenceArray=new Float32Array(this.MaxMorphTargetCount);let e=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST;this._morphInfluenceBuffer=new Be(this.MaxMorphTargetCount,e)}}var Kg=Object.defineProperty,qg=Object.getOwnPropertyDescriptor,bo=(s,e,t,r)=>{for(var i=r>1?void 0:r?qg(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&Kg(e,t,i),i};let K=class extends Nr{receiveShadow;morphData;constructor(){super()}onEnable(){super.onEnable()}onDisable(){super.onDisable()}cloneTo(s){s.addComponent(K).copyComponent(this)}copyComponent(s){return super.copyComponent(s),this.receiveShadow=s.receiveShadow,this}get geometry(){return this._geometry}set geometry(s){if(super.geometry=s,s){let e=s.morphTargetDictionary!=null;e&&(this.morphData||=new $h,this.morphData.morphTargetsRelative=s.morphTargetsRelative,this.morphData.initMorphTarget(s)),this.morphData&&(this.morphData.enable=e),this.morphData?.enable?this.addRendererMask(ve.MorphTarget):this.removeRendererMask(ve.MorphTarget),this.object3D.bound=this._geometry.bounds.clone()}else this.morphData&&(this.morphData.enable=!1),this.removeRendererMask(ve.MorphTarget);this._readyPipeline||(this.initPipeline(),this._computes&&(this.onCompute=ls(this.onCompute,()=>{for(let e=0;e<this._computes.length;e++)this._computes[e].onUpdate()})))}get material(){return this._materials[0]}set material(s){this.materials=[s]}setMorphInfluence(s,e){if(this.morphData&&this.morphData.enable){let t=this._geometry.morphTargetDictionary[s];t>=0&&this.morphData.updateInfluence(t,e)}}setMorphInfluenceIndex(s,e){this.morphData&&this.morphData.enable&&s>=0&&this.morphData.updateInfluence(s,e)}onCompute(s,e){this.morphData&&this.morphData.enable&&this.morphData.computeMorphTarget(e)}nodeUpdate(s,e,t,r){if(this.morphData&&this.morphData.enable)for(let i=0;i<this.materials.length;i++){let o=this.materials[i].getPass(e);if(o)for(let n=0;n<o.length;n++)this.morphData.applyRenderShader(o[n])}super.nodeUpdate(s,e,t,r)}destroy(s){super.destroy(s)}};bo([Oi],K.prototype,"geometry",1),bo([Oi],K.prototype,"material",1),K=bo([Pt(K,"MeshRenderer")],K);class Sr{static compressGBufferTex_NAME="compressGBufferTex_NAME";static colorBufferTex_NAME="colorBufferTex";static positionBufferTex_NAME="positionBufferTex";static normalBufferTex_NAME="normalBufferTex";static materialBufferTex_NAME="materialBufferTex";static zBufferTexture_NAME="zBufferTexture";static zPreDepthTexture_NAME="zPreDepthTexture";static outTex_NAME="outTex"}class eu{label="";customSize=!1;zPreTexture=null;depthTexture=null;renderTargetTextures;outColor=-1;renderTargets;rtTextureDescriptors;irradianceBuffer;multisample=0;multiTexture;depthViewIndex=0;depthCleanValue=0;isOutTarget=!0;camera3D;rtFrame;renderPassDescriptor;renderBundleEncoderDescriptor;depthLoadOp;getLastRenderTexture(){return this.renderTargets&&this.renderTargets.length>0?this.renderTargets[0]:m.res.redTexture}}class Ut extends je{resolveTarget;sampleCount;autoResize;clear;constructor(e,t,r=X.rgba8unorm,i=!1,a,o=1,n=0,l=!0,h=!0){super(e,t,o),this.name=It(),this.autoResize=h,this.useMipmap=i,this.sampleCount=n,this.format=r,this.numberLayer=o,this.clear=l,a!=null?this.usage=a:this.usage=a|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.COPY_DST,this.resize(e,t),this.autoResize&&Q.addEventListener(Hr.RESIZE,u=>{let{width:c,height:f}=u.data;this.resize(c,f),this._textureChange=!0},this)}resize(e,t){let r=Q.device;this.gpuTexture&&(je.delayDestroyTexture(this.gpuTexture),this.gpuTexture=null,this.view=null),this.width=e,this.height=t,this.createTextureDescriptor(e,t,1,this.format,this.usage,this.numberLayer,this.sampleCount),this.useMipmap=!1,this.visibility=GPUShaderStage.COMPUTE|GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,this.format==X.rgba32float?(this.samplerBindingLayout.type="non-filtering",this.textureBindingLayout.sampleType="unfilterable-float",this.gpuSampler=r.createSampler({})):this.format==X.depth32float?(this.samplerBindingLayout.type="filtering",this.sampler_comparisonBindingLayout.type="comparison",this.textureBindingLayout.sampleType="depth",this.gpuSampler=Q.device.createSampler({}),this.gpuSampler_comparison=Q.device.createSampler({compare:"less",label:"sampler_comparison"})):this.format==X.depth24plus?(this.samplerBindingLayout={type:"filtering"},this.sampler_comparisonBindingLayout={type:"comparison"},this.textureBindingLayout.sampleType="depth",this.gpuSampler=Q.device.createSampler({}),this.gpuSampler_comparison=Q.device.createSampler({compare:"less",label:"sampler_comparison"})):(this.samplerBindingLayout.type="filtering",this.textureBindingLayout.sampleType="float",this.sampleCount>0&&(this.textureBindingLayout.multisampled=!0),this.minFilter="linear",this.magFilter="linear",this.mipmapFilter="linear",this.addressModeU=Lt.clamp_to_edge,this.addressModeV=Lt.clamp_to_edge,this.gpuSampler=r.createSampler(this)),this._textureChange=!0}create(e,t,r=!0){let i=Q.device;const a=e*4;let o=new Float32Array(e*t*4);const n=i.createBuffer({size:o.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(n,0,o);const l=F.beginCommandEncoder();l.copyBufferToTexture({buffer:n,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),F.endCommandEncoder(l)}clone(){let e=new Ut(this.width,this.height,this.format,this.useMipmap,this.usage,this.numberLayer,this.sampleCount,this.clear,this.autoResize);return e.name="clone_"+e.name,e}readTextureToImage(){let e=Q.device,t=Q.windowWidth,r=Q.windowHeight,i=new Float32Array(t*r*4);const a=e.createBuffer({size:i.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});return F.beginCommandEncoder().copyTextureToBuffer({texture:this.getGPUTexture()},{buffer:a},[t,r]),a.getMappedRange(0,i.byteLength)}}class Re{storeOp="store";loadOp="clear";clearValue=[0,0,0,0]}class Ze{label;customSize=!1;renderTargets;rtDescriptors;zPreTexture;depthTexture;depthViewIndex=0;depthCleanValue=1;depthLoadOp="clear";isOutTarget=!0;constructor(e,t,r,i,a=!0){this.renderTargets=e,this.rtDescriptors=t,this.depthTexture=r,this.zPreTexture=i,this.isOutTarget=a}clone2Frame(e){e.renderTargets.push(...this.renderTargets.concat());for(let t=0;t<this.rtDescriptors.length;t++){const r=this.rtDescriptors[t];let i=new Re;i.loadOp=r.loadOp,i.storeOp=r.storeOp,i.clearValue=r.clearValue,e.rtDescriptors.push(i)}e.depthTexture=this.depthTexture,e.zPreTexture=this.zPreTexture,e.customSize=this.customSize}clone(){let e=new Ze([],[]);return this.clone2Frame(e),e}}class se extends Ze{static colorPass_GBuffer="ColorPassGBuffer";static reflections_GBuffer="reflections_GBuffer";static gui_GBuffer="gui_GBuffer";static gBufferMap=new Map;_colorBufferTex;_compressGBufferTex;constructor(){super([],[])}createGBuffer(e,t,r,i=!0,a=!0,o){let n=this.renderTargets,l=this.rtDescriptors;if(a){let u=new Re;u.loadOp="clear",this._colorBufferTex=Ct.createRTTexture(e+Sr.colorBufferTex_NAME,t,r,X.rgba16float,!0),n.push(this._colorBufferTex),l.push(u)}this._compressGBufferTex=new Ut(t,r,X.rgba32float,!1,void 0,1,0,!0,!0),n.push(this._compressGBufferTex),o?this.depthTexture=o:(this.depthTexture=new Ut(t,r,X.depth24plus,!1,void 0,1,0,!0,!0),this.depthTexture.name=e+"_depthTexture");let h;h=new Re,l.push(h)}getPositionMap(){return this.renderTargets[1]}getNormalMap(){return this.renderTargets[2]}getColorTexture(){return this._colorBufferTex}getCompressGBufferTexture(){return this._compressGBufferTex}static getGBufferFrame(e,t=0,r=0,i=!0,a){let o;if(se.gBufferMap.has(e))o=se.gBufferMap.get(e);else{o=new se;let n=Q.presentationSize;o.createGBuffer(e,t==0?n[0]:t,r==0?n[1]:r,t!=0&&r!=0,i,a),se.gBufferMap.set(e,o)}return o}static getGUIBufferFrame(){let e=this.getGBufferFrame(this.colorPass_GBuffer);return se.getGBufferFrame(se.gui_GBuffer,0,0,!0,e.depthTexture)}clone(){let e=new se;return this.clone2Frame(e),e}}class De{static rendererPassState=new Map;static createRendererPassState(e,t=null){let r=De.rendererPassState.get(e);if(r||(r=new eu,r.label=e.label,r.customSize=e.customSize,r.rtFrame=e,r.zPreTexture=e.zPreTexture,r.depthTexture=e.depthTexture,r.depthViewIndex=e.depthViewIndex,r.isOutTarget=e.isOutTarget,r.depthCleanValue=e.depthCleanValue,r.depthLoadOp=e.depthLoadOp,De.rendererPassState.set(e,r)),e&&e.renderTargets.length>0){r.renderTargets=e.renderTargets,r.rtTextureDescriptors=e.rtDescriptors,r.renderPassDescriptor=De.getRenderPassDescriptor(r),r.renderPassDescriptor.depthStencilAttachment&&(r.renderPassDescriptor.depthStencilAttachment.depthLoadOp=e.depthLoadOp),t=="load"&&e?.renderTargets[0]&&e.renderTargets[0].name.startsWith(se.gui_GBuffer)&&(r.renderPassDescriptor.colorAttachments[0].loadOp="load"),r.depthLoadOp=e.depthLoadOp,r.renderBundleEncoderDescriptor=De.getRenderBundleDescriptor(r),r.renderTargetTextures=[];for(let i=0;i<e.renderTargets.length;i++){const a=e.renderTargets[i];r.renderTargetTextures[i]={format:a.format},a.name.indexOf(Sr.colorBufferTex_NAME)!=-1&&(r.outColor=i)}}else r.renderPassDescriptor=De.getRenderPassDescriptor(r,t),r.renderBundleEncoderDescriptor=De.getRenderBundleDescriptor(r),r.renderTargetTextures=[{format:Q.presentationFormat}],r.outColor=0;return r}static getRenderPassDescriptor(e,t=null){if(e.renderPassDescriptor)return e.renderPassDescriptor;Q.device,Q.presentationSize;let r=[];if(e.renderTargets&&e.renderTargets.length>0){e.renderTargets[0].width,e.renderTargets[0].height;for(let a=0;a<e.renderTargets.length;a++){const o=e.renderTargets[a],n=e.rtTextureDescriptors[a];r.push({view:o.getGPUView(),resolveTarget:void 0,loadOp:n.loadOp,clearValue:n.clearValue,storeOp:n.storeOp})}}else if(!e.customSize){let a=Q.canvasConfig&&Q.canvasConfig.alpha?[1,1,1,0]:[0,0,0,1];e.isOutTarget==!0&&r.push({view:void 0,resolveTarget:void 0,loadOp:Q.canvasConfig&&Q.canvasConfig.alpha||t!=null?"load":"clear",clearValue:a,storeOp:"store"})}let i=null;return e.depthTexture||e.zPreTexture?(e.zPreTexture&&(e.depthTexture=e.zPreTexture),i={label:`${e.label} renderPassDescriptor zPreTexture${e.zPreTexture?"load":"clear"}`,colorAttachments:r,depthStencilAttachment:{view:e.depthTexture.getGPUView(),depthLoadOp:e.zPreTexture?"load":e.depthLoadOp,depthClearValue:e.zPreTexture?1:e.depthCleanValue,depthStoreOp:"store"}}):i={colorAttachments:r,label:"renderPassDescriptor not writeDepth"},e.renderPassDescriptor=i,i}static getRenderBundleDescriptor(e){if(e.renderBundleEncoderDescriptor)return e.renderBundleEncoderDescriptor;Q.presentationSize;let t=[];if(e.renderTargets&&e.renderTargets.length>0){e.renderTargets[0].width,e.renderTargets[0].height;for(let i=0;i<e.renderTargets.length;i++){const a=e.renderTargets[i];t.push(a.format)}}let r=null;return e.depthTexture?r={colorFormats:t,depthStencilFormat:e.depthTexture.format}:r={colorFormats:t},e.renderBundleEncoderDescriptor=r,e.renderBundleEncoderDescriptor}}class Xi extends Ie{width;height;segmentW;segmentH;up;constructor(e,t,r=1,i=1,a=d.Y_AXIS){super(),this.width=e,this.height=t,this.segmentW=r,this.segmentH=i,this.up=a,this.buildGeometry(this.up)}buildGeometry(e){var t,r,i,a,o=this.segmentW+1;(this.segmentH+1)*o,this.bounds=new Fe(d.ZERO.clone(),new d(this.width,1,this.height)),i=this.segmentH*this.segmentW*6;let n=(this.segmentW+1)*(this.segmentH+1),l=new Float32Array(n*3),h=new Float32Array(n*3),u=new Float32Array(n*2),c;this.segmentW*this.segmentH*2*3>=Uint16Array.length?c=new Uint32Array(this.segmentW*this.segmentH*2*3):c=new Uint16Array(this.segmentW*this.segmentH*2*3),i=0;for(var g=0,p=0,A=0,U=0;U<=this.segmentH;++U)for(var x=0;x<=this.segmentW;++x){switch(t=(x/this.segmentW-.5)*this.width,r=(U/this.segmentH-.5)*this.height,e){case d.Y_AXIS:l[g++]=t,l[g++]=0,l[g++]=r,h[p++]=0,h[p++]=1,h[p++]=0;break;case d.Z_AXIS:l[g++]=t,l[g++]=-r,l[g++]=0,h[p++]=0,h[p++]=0,h[p++]=1;break;case d.X_AXIS:l[g++]=0,l[g++]=t,l[g++]=r,h[p++]=1,h[p++]=0,h[p++]=0;break;default:l[g++]=t,l[g++]=0,l[g++]=r,h[p++]=0,h[p++]=1,h[p++]=0;break}u[A++]=x/this.segmentW,u[A++]=U/this.segmentH,x!=this.segmentW&&U!=this.segmentH&&(a=x+U*o,c[i++]=a+1,c[i++]=a,c[i++]=a+o,c[i++]=a+1,c[i++]=a+o,c[i++]=a+o+1)}this.setIndices(c),this.setAttribute(V.position,l),this.setAttribute(V.normal,h),this.setAttribute(V.uv,u),this.setAttribute(V.TEXCOORD_1,u),this.addSubGeometry({indexStart:0,indexCount:c.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0})}}var $g=Object.getOwnPropertyDescriptor,ep=(s,e,t,r)=>{for(var i=r>1?void 0:r?$g(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=o(i)||i);return i};let pa=class extends ot{constructor(s="QuadGlsl_vs",e="QuadGlsl_fs"){super();let t=new Pe(s,e);this.addRenderPass(t);let r=t.shaderState;t.blendMode=ae.NONE,r.frontFace="cw",r.depthWriteEnabled=!1,r.depthCompare=et.always,r.multisample=0,this.setTexture("baseMap",m.res.blackTexture),this.setUniformFloat("x",0),this.setUniformFloat("y",0),this.setUniformFloat("width",100),this.setUniformFloat("height",100)}};pa=ep([wr(pa,"QuadShader")],pa);class Qo extends q{width=128;height=128;quadRenderer;material;rendererPassState;quadShader;constructor(e="QuadGlsl_vs",t="QuadGlsl_fs",r,i=0,a=!1){super();let o=r?r.renderTargets:[];this.material=new At,this.quadShader=new pa(e,t),this.material.shader=this.quadShader,this.quadRenderer=this.addComponent(K),this.quadRenderer.material=this.material,this.quadRenderer.castGI=!1,this.quadRenderer.castShadow=!1,this.quadRenderer.drawType=a?2:0,this.quadRenderer.geometry=new Xi(100,100,1,1),this.quadRenderer.material=this.material,this.quadRenderer.__start(),this.quadRenderer._enable=!0,this.quadRenderer.onEnable(),this.rendererPassState=De.createRendererPassState(r,"load"),i>0&&(this.rendererPassState.multisample=this.quadShader.getDefaultColorShader().shaderState.multisample,this.rendererPassState.multiTexture=Q.device.createTexture({size:{width:Q.presentationSize[0],height:Q.presentationSize[1]},sampleCount:i,format:o.length>0?o[0].format:Q.presentationFormat,usage:GPUTextureUsage.RENDER_ATTACHMENT})),Q.addEventListener(Hr.RESIZE,n=>{this.rendererPassState=De.createRendererPassState(r,"load"),i>0&&(this.rendererPassState.multisample=this.quadShader.getDefaultColorShader().shaderState.multisample,this.rendererPassState.multiTexture=Q.device.createTexture({size:{width:Q.presentationSize[0],height:Q.presentationSize[1]},sampleCount:i,format:o.length>0?o[0].format:Q.presentationFormat,usage:GPUTextureUsage.RENDER_ATTACHMENT}))},this)}renderTarget(e,t,r){let i=e.camera,a=F.beginRenderPass(r,t.rendererPassState);F.bindCamera(a,i),t.quadRenderer.nodeUpdate(e,H.COLOR,t.rendererPassState,null),t.quadRenderer.renderPass2(e,H.COLOR,t.rendererPassState,null,a),F.endPass(a)}renderToViewQuad(e,t,r,i){let a=e.camera;t.quadShader.setTexture("baseMap",i);let o=F.beginRenderPass(r,t.rendererPassState);F.bindCamera(o,a),t.quadRenderer.nodeUpdate(e,H.COLOR,t.rendererPassState,null),t.quadRenderer.renderPass2(e,H.COLOR,t.rendererPassState,null,o),F.endPass(o)}}class Ct{static rtTextureMap;static rtViewQuad;static init(){this.rtTextureMap=new Map,this.rtViewQuad=new Map}static createRTTexture(e,t,r,i,a=!1,o=0){let n=this.rtTextureMap.get(e);return n||(e==Sr.colorBufferTex_NAME?n=new Ut(t,r,i,a,void 0,1,o,!1):n=new Ut(t,r,i,a,void 0,1,o,!0),n.name=e,Ct.rtTextureMap.set(e,n)),n}static createRTTextureArray(e,t,r,i,a=1,o=!1,n=0){let l=this.rtTextureMap.get(e);return l||(l=new Ut(t,r,i,o,void 0,a,n),l.name=e,Ct.rtTextureMap.set(e,l)),l}static createViewQuad(e,t,r,i,a=0){let o=new Ze([i],[new Re]),n=new Qo(t,r,o,a);return Ct.rtViewQuad.set(e,n),n}static getTexture(e){return this.rtTextureMap.get(e)}static CreateSplitTexture(e){let t=this.getTexture(Sr.colorBufferTex_NAME),r=this.getTexture(e+"_split");return r||(r=this.createRTTexture(e+"_split",t.width,t.height,t.format,!1)),r}static WriteSplitColorTexture(e){let t=this.getTexture(Sr.colorBufferTex_NAME),r=this.getTexture(e+"_split");const i=F.beginCommandEncoder();i.copyTextureToTexture({texture:t.getGPUTexture(),mipLevel:0,origin:{x:0,y:0,z:0}},{texture:r.getGPUTexture(),mipLevel:0,origin:{x:0,y:0,z:0}},{width:r.width,height:r.height,depthOrArrayLayers:1}),F.endCommandEncoder(i)}}class Ro{command;encoder;rendererPassStates;rtFrame;constructor(e){this.rtFrame=e,this.rendererPassStates=[]}clean(){this.rendererPassStates.length=0,F.cleanCache()}beginContinueRendererPassState(e="load",t="load"){if(this.rendererPassStates.length>0){let r=this.rtFrame.clone();for(const a of r.rtDescriptors)a.loadOp="load";r.depthLoadOp=t;let i=De.createRendererPassState(r,e);return this.rendererPassStates.push(i),i}else{this.rtFrame.depthLoadOp=t;let r=De.createRendererPassState(this.rtFrame,e);return this.rendererPassStates.push(r),r}}get rendererPassState(){return this.rendererPassStates[this.rendererPassStates.length-1]}beginOpaqueRenderPass(){this.beginContinueRendererPassState("clear","clear"),this.begineNewCommand(),this.beginNewEncoder()}beginTransparentRenderPass(){this.beginContinueRendererPassState("load","load"),this.begineNewCommand(),this.beginNewEncoder()}specialtRenderPass(){this.beginContinueRendererPassState("load","load"),this.begineNewCommand(),this.beginNewEncoder()}endRenderPass(){this.endEncoder(),this.endCommand()}begineNewCommand(){return this.command=F.beginCommandEncoder(),this.command}endCommand(){F.endCommandEncoder(this.command),this.command=null}beginNewEncoder(){return this.encoder=F.beginRenderPass(this.command,this.rendererPassState),this.encoder}endEncoder(){F.endPass(this.encoder),this.encoder=null}}class _r extends Er{rendererPassState;splitRendererPassState;useRenderBundle=!1;debugViewQuads;debugTextures;renderContext;_rendererType;_rtFrame;get passType(){return this._rendererType}set passType(e){this._rendererType=e}constructor(){super(),this.debugTextures=[],this.debugViewQuads=[]}setRenderStates(e){if(this._rtFrame=e,e){this.rendererPassState=De.createRendererPassState(e);let t=e.clone();t.depthLoadOp="load";for(const r of t.rtDescriptors)r.loadOp="load";this.splitRendererPassState=De.createRendererPassState(t)}this.renderContext=new Ro(e)}getRenderContext(e){return this._rtFrame=e,new Ro(e)}setIrradiance(e,t){this.rendererPassState.irradianceBuffer=[e,t]}compute(e,t){}render(e,t,r,i=!1){F.cleanCache();let a=e.camera,o=e.scene;this.rendererPassState.camera3D=a;let n=G.instance.getRenderNodes(o,a),l=this.renderBundleOp(e,n,t,r),h=i?[]:this.renderBundleTr(e,n,t,r);{let u=F.beginCommandEncoder(),c=F.beginRenderPass(u,this.rendererPassState);l.length>0&&c.executeBundles(l),!i&&G.instance.sky&&(F.bindCamera(c,a),G.instance.sky.renderPass2(e,this._rendererType,this.rendererPassState,r,c)),this.drawRenderNodes(e,c,u,n.opaqueList,t),F.endPass(c),F.endCommandEncoder(u)}{let u=F.beginCommandEncoder(),c=F.beginRenderPass(u,this.rendererPassState);h.length>0&&c.executeBundles(h),i||(F.bindCamera(c,a),this.drawRenderNodes(e,c,u,n.transparentList,t)),F.endPass(c),F.endCommandEncoder(u)}}nodeUpload(e,t,r){}occlusionRenderNodeTest(e,t,r){return r?r.occlusionRenderNodeTest(e)>0:!0}renderOp(e,t,r,i,a){}renderTr(e,t,r,i,a){}renderBundleOp(e,t,r,i){let a=G.instance.getOpRenderGroup(e.scene);if(a){let o=[];return a.renderGroup.forEach(n=>{if(n.bundleMap.has(this._rendererType))o.push(n.bundleMap.get(this._rendererType));else{let l=F.recordBundleEncoder(this.rendererPassState.renderBundleEncoderDescriptor);this.recordRenderBundleNode(e,l,n.renderNodes,i);let h=l.finish();n.bundleMap.set(this._rendererType,h),o.push(h)}}),o}return[]}renderBundleTr(e,t,r,i){let a=G.instance.getTrRenderGroup(e.scene);if(a){let o=[];return a.renderGroup.forEach(n=>{if(n.bundleMap.has(this._rendererType))o.push(n.bundleMap.get(this._rendererType));else{let l=F.recordBundleEncoder(this.rendererPassState.renderBundleEncoderDescriptor);this.recordRenderBundleNode(e,l,n.renderNodes,i);let h=l.finish();n.bundleMap.set(this._rendererType,h),o.push(h)}}),o}return[]}recordRenderBundleNode(e,t,r,i){F.bindCamera(t,e.camera),F.bindGeometryBuffer(t,r[0].geometry);for(let a=0;a<r.length;++a){let o=r[a];o.transform.worldMatrix.index,o.transform.enable&&o.recordRenderPass2(e,this._rendererType,this.rendererPassState,i,t)}}drawRenderNodes(e,t,r,i,a,o){F.bindCamera(t,e.camera);for(let n=m.setting.render.drawOpMin;n<Math.min(i.length,m.setting.render.drawOpMax);++n){let l=i[n];l.transform.enable&&l.enable&&l.renderPass2(e,this._rendererType,this.rendererPassState,o,t)}}}class tu extends _r{constructor(){super(),this.passType=H.COLOR}render(e,t,r,i=!1){this.renderContext.clean();let a=e.scene,o=e.camera;ne.updateCameraGroup(o),this.rendererPassState.camera3D=o;let n=G.instance.getRenderNodes(a,o),l=this.renderBundleOp(e,n,t,r),h=i?[]:this.renderBundleTr(e,n,t,r);{this.renderContext.beginOpaqueRenderPass();let u=this.renderContext.encoder;l.length>0&&(G.instance.getOpRenderGroup(a),u.executeBundles(l)),!i&&G.instance.sky&&(F.bindCamera(u,o),G.instance.sky.preInit(this._rendererType)||G.instance.sky.nodeUpdate(e,this._rendererType,this.rendererPassState,r),G.instance.sky.renderPass2(e,this._rendererType,this.rendererPassState,r,u)),n.opaqueList&&(F.bindCamera(u,o),this.drawNodes(e,this.renderContext,n.opaqueList,t,r))}{let u=this.renderContext.encoder;h.length>0&&u.executeBundles(h),!i&&n.transparentList&&(F.bindCamera(u,o),this.drawNodes(e,this.renderContext,n.transparentList,t,r));let c=G.instance.getGraphicList();for(let f=0;f<c.length;f++){const g=c[f];g.nodeUpdate(e,this._rendererType,this.splitRendererPassState,r),g.renderPass2(e,this._rendererType,this.splitRendererPassState,r,u)}this.renderContext.endRenderPass(),Ye.end("ColorPass Draw Transparent")}}drawNodes(e,t,r,i,a){let o=G.instance.getRenderShaderCollect(e);if(o){for(const n of o){let l=n[1];for(const h of l){let u=h[1];if(!u.isDestroyed&&u.preInit(this._rendererType)){u.nodeUpdate(e,this._rendererType,this.rendererPassState,a);break}}}for(let n=m.setting.render.drawOpMin;n<Math.min(r.length,m.setting.render.drawOpMax);++n){let l=r[n];l.transform.enable&&l.enable&&(l.hasMask(ve.UI)&&!l.isRecievePostEffectUI||l.isDestroyed||(l.preInit(this._rendererType)||l.nodeUpdate(e,this._rendererType,this.rendererPassState,a),l.renderPass(e,this.passType,this.renderContext)))}}}occlusionRenderNodeTest(e,t,r){return r.zDepthRenderNodeTest(t)>0}}class Io{frustumCullingList;zVisibleList;_renderList;static enable=!0;constructor(){this._renderList=new Map}occlusionRenderNodeTest(e){return m.setting.occlusionQuery.enable?this.frustumCullingList?this.frustumCullingList[e]:0:1}zDepthRenderNodeTest(e){return this.zVisibleList?this.zVisibleList[e]:0}update(e,t){}collect(e,t){}renderCommitTesting(e,t){return!0}}class Hi extends Tr{constructor(e,t){super(),this.bufferType=tr.ComputeGPUBuffer,this.createBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST,e,t,"ComputeGPUBuffer")}}class ru{clusterBuffer;lightAssignBuffer;assignTableBuffer;clustersUniformBuffer;constructor(e,t){this.clusterBuffer=new Hi(e*2*4),this.clustersUniformBuffer=new ut(10),this.clustersUniformBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.lightAssignBuffer=new Hi(e*t),this.lightAssignBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.assignTableBuffer=new Hi(e*4),this.assignTableBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE}update(e,t,r,i,a,o,n,l,h,u){this.clustersUniformBuffer.setFloat("clusterTileX",i),this.clustersUniformBuffer.setFloat("clusterTileY",a),this.clustersUniformBuffer.setFloat("clusterTileZ",o),this.clustersUniformBuffer.setFloat("numLights",n),this.clustersUniformBuffer.setFloat("maxNumLightsPerCluster",l),this.clustersUniformBuffer.setFloat("near",h),this.clustersUniformBuffer.setFloat("far",u),this.clustersUniformBuffer.setFloat("screenWidth",e),this.clustersUniformBuffer.setFloat("screenHeight",t),this.clustersUniformBuffer.setFloat("clusterPix",r),this.clustersUniformBuffer.apply()}}class gt{static clusterTileX=16;static clusterTileY=16;static clusterTileZ=32}let iu=`
5995
+ `;class ot{computes;passShader;constructor(){this.computes=[],this.passShader=new Map}addRenderPass(e,t=-1){let r=this.passShader.get(e.passType)||[];t==-1?r.push(e):r.splice(t,-1,e),this.passShader.set(e.passType,r)}removeShader(e,t=-1){let r=this.passShader.get(e.passType);if(r)if(t==-1){let i=r.indexOf(e);i!=-1&&r.splice(i)}else r.splice(t,1)}removeShaderByIndex(e,t=-1){let r=this.passShader.get(e);r&&(t==-1?this.passShader.delete(e):r.splice(t,1))}getSubShaders(e){return this.passShader.get(e)||[]}hasSubShaders(e){return this.passShader.get(e).length>0}getDefaultShaders(){return this.passShader.get(H.COLOR)}getDefaultColorShader(){return this.passShader.get(H.COLOR)[0]}setDefine(e,t){for(const r of this.passShader)for(const i of r[1])i.setDefine(e,t)}hasDefine(e){for(const t of this.passShader)for(const r of t[1]){let i=r.hasDefine(e);if(i)return i}return!1}deleteDefine(e){for(const t of this.passShader)for(const r of t[1])r.deleteDefine(e)}setUniform(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniform(e,t)}setUniformFloat(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformFloat(e,t)}setUniformVector2(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformVector2(e,t)}setUniformVector3(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformVector3(e,t)}setUniformVector4(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformVector4(e,t)}setUniformColor(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformColor(e,t)}getUniform(e){return this.getDefaultColorShader().getUniform(e)}getUniformFloat(e){return this.getDefaultColorShader().getUniformFloat(e)}getUniformVector2(e){return this.getDefaultColorShader().getUniformVector2(e)}getUniformVector3(e){return this.getDefaultColorShader().getUniformVector3(e)}getUniformVector4(e){return this.getDefaultColorShader().getUniformVector4(e)}getUniformColor(e){return this.getDefaultColorShader().getUniformColor(e)}setTexture(e,t){for(const r of this.passShader)for(const i of r[1])i.setTexture(e,t);this.setDefine(`USE_${e.toLocaleUpperCase()}`,!0)}getTexture(e){return this.getDefaultColorShader().textures[e]}setUniformBuffer(e,t){for(const r of this.passShader)for(const i of r[1])i.setUniformBuffer(e,t)}getUniformBuffer(e){return this.getDefaultColorShader().getBuffer(e)}setStorageBuffer(e,t){for(const r of this.passShader)for(const i of r[1])i.setStorageBuffer(e,t)}getStorageBuffer(e){return this.getDefaultColorShader().getBuffer(e)}setStructStorageBuffer(e,t){for(const r of this.passShader)for(const i of r[1])i.setStructStorageBuffer(e,t)}getStructStorageBuffer(e){return this.getDefaultColorShader().getBuffer(e)}noticeValueChange(){for(const e of this.passShader)for(const t of e[1])t.noticeValueChange()}destroy(){this.getDefaultColorShader().destroy()}clone(){let e=new ot,t=this.getDefaultShaders();for(const r of t)e.addRenderPass(r);return e}applyUniform(){for(const e of this.passShader)for(const t of e[1])t.applyUniform()}}var Gg=Object.getOwnPropertyDescriptor,Wg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Gg(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=o(i)||i);return i};let da=class extends ot{constructor(){super();const s=new Pe("gsplat_vs_dc","gsplat_fs_dc");s.passType=H.COLOR,s.setShaderEntry("VertMain","FragMain"),s.topology=to.triangle_list,s.depthWriteEnabled=!1,s.cullMode=Et.none,s.shaderState.transparent=!0,s.shaderState.blendMode=ae.NORMAL,s.shaderState.writeMasks=[15,15],s.shaderState.castReflection=!1,this.addRenderPass(s),this.setDefault()}setDefault(){const s=this.getDefaultColorShader(),e=new I;s.setUniform("modelMatrix",e.rawData),s.setUniform("pixelCull",new Float32Array([2,0,0,0]))}};da=Wg([wr(da,"GSplatShader")],da);class Vh extends At{_pixelCullArray=new Float32Array(4);constructor(){super(),O.register("gsplat_vs_dc",Mh),O.register("gsplat_fs_dc",Nh),this.shader=new da}setSplatTextures(e,t,r,i,a){const o=this.shader.getDefaultColorShader();o.setTexture("splatColor",e),o.setTexture("transformA",t),o.setTexture("transformB",r),o.setUniformArray("tex_params",i),a&&o.setTexture("splatOrder",a),o.shaderState.depthCompare=et.less}setTransformMatrix(e){this.shader.getDefaultColorShader().setUniform("modelMatrix",e.rawData)}setPixelCulling(e,t,r=0,i=128){this._pixelCullArray[0]=e,this._pixelCullArray[1]=t,this._pixelCullArray[2]=r,this._pixelCullArray[3]=i,this.shader.getDefaultColorShader().setUniform("pixelCull",this._pixelCullArray)}}class gs extends Tr{node;constructor(e){super(),this.bufferType=tr.VertexGPUBuffer,this.createVertexBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.VERTEX,e)}createVertexBuffer(e,t){let r=Q.device;this.byteSize=t*Float32Array.BYTES_PER_ELEMENT,this.usage=e,this.buffer&&this.destroy(),this.buffer=r.createBuffer({label:"VertexGPUBuffer",size:this.byteSize,usage:e,mappedAtCreation:!1}),this.memory=new jr,this.memoryNodes=new Map,this.memory.allocation(this.byteSize),this.node=this.memory.allocation_node(this.byteSize)}}var dt=(s=>(s[s.split=0]="split",s[s.compose=1]="compose",s[s.compose_bin=2]="compose_bin",s))(dt||{});class Ph{vertexCount=0;vertexGPUBuffer;geometryType=dt.compose;_vertexBufferLayouts;_attributeSlotLayouts;_attributeLocation;constructor(){this._vertexBufferLayouts=[],this._attributeLocation={},this._attributeSlotLayouts=[]}get vertexBufferLayouts(){return this._vertexBufferLayouts}createVertexBuffer(e,t){switch(this.geometryType){case dt.split:this.createSplitVertexBuffer(e,t);break;case dt.compose:this.createComposeVertexBuffer(e,t);break;case dt.compose_bin:this.createComposBinVertexBuffer(e,t);break}}createSplitVertexBuffer(e,t){let r=0;for(let i=0;i<t.attributes.length;i++){const a=t.attributes[i];if(a.name=="index")continue;this._attributeLocation[a.name]=a.location;let o={name:a.name,format:a.format,offset:0,shaderLocation:a.location,stride:qr[a.format]};this._attributeSlotLayouts[a.location]=[o];let n=e.get(a.name);n||(n={attribute:a.name,data:new Float32Array(a.size*this.vertexCount)},e.set(a.name,n));let l=n.data.length/o.stride;this.vertexCount!=0&&this.vertexCount!=l&&console.error(" vertex count not match attribute count"),this.vertexCount=l,this._vertexBufferLayouts[a.location]={name:a.name,arrayStride:a.size*4,stepMode:"vertex",attributes:this._attributeSlotLayouts[a.location],offset:r*4,size:this.vertexCount*a.size*4},r+=this.vertexCount*a.size}this.vertexGPUBuffer=new gs(r)}createComposeVertexBuffer(e,t){this._attributeSlotLayouts[0]=[];let r=0;for(let i=0;i<t.attributes.length;i++){const a=t.attributes[i];if(a.name=="index"||a.type=="builtin")continue;this._attributeLocation[a.name]=a.location;let o={name:a.name,format:a.format,offset:r*4,shaderLocation:a.location,stride:qr[a.format]};this._attributeSlotLayouts[0][a.location]=o;let n=e.get(a.name);if(n||(n={attribute:a.name,data:new Float32Array(a.size*this.vertexCount)},e.set(a.name,n)),n.data){let l=n.data.length/o.stride;this.vertexCount!=0&&this.vertexCount!=l&&console.error(" vertex count not match attribute count"),this.vertexCount=l}r+=a.size}this._vertexBufferLayouts[0]={name:"composeStruct",arrayStride:r*4,stepMode:"vertex",attributes:this._attributeSlotLayouts[0],offset:0,size:this.vertexCount*r*4},this.vertexGPUBuffer=new gs(this.vertexCount*r)}createComposBinVertexBuffer(e,t){this._attributeSlotLayouts[0]=[];let r=0;for(let o=0;o<t.attributes.length;o++){const n=t.attributes[o];if(n.name=="index"||n.type=="builtin")continue;this._attributeLocation[n.name]=n.location;let l={name:n.name,format:n.format,offset:r*4,shaderLocation:n.location,stride:qr[n.format]};this._attributeSlotLayouts[0][n.location]=l;let h=e.get(n.name);if(h||(h={attribute:n.name,data:new Float32Array(n.size*this.vertexCount)},e.set(n.name,h)),h.data){let u=h.data.length/l.stride;this.vertexCount!=0&&this.vertexCount!=u&&console.error(" vertex count not match attribute count"),this.vertexCount=u}r+=n.size}let a=e.get(V.all).data.length/r;this.vertexCount=a,this._vertexBufferLayouts[0]={name:"composeStruct",arrayStride:r*4,stepMode:"vertex",attributes:this._attributeSlotLayouts[0],offset:0,size:this.vertexCount*r*4},this.vertexGPUBuffer=new gs(this.vertexCount*r)}upload(e,t){if(this.vertexGPUBuffer){switch(this.geometryType){case dt.split:{let r=this._attributeLocation[e],i=this._vertexBufferLayouts[r];this.vertexGPUBuffer.node.setFloat32Array(i.offset/4,t.data)}break;case dt.compose:for(let r=0;r<this.vertexCount;r++){const i=this._attributeSlotLayouts[0][this._attributeLocation[e]];for(let a=0;a<i.stride;a++){let o=t.data[r*i.stride+a],n=r*(this._vertexBufferLayouts[0].arrayStride/4)+i.offset/4+a;this.vertexGPUBuffer.node.setFloat(o,n)}}break;case dt.compose_bin:this.vertexGPUBuffer.node.setFloat32Array(0,t.data);break}this.vertexGPUBuffer?.apply()}}updateAttributes(e){switch(this.geometryType){case dt.split:for(let t=0;t<this._vertexBufferLayouts.length;t++){const r=this._vertexBufferLayouts[t];let i=e.get(r.name);this.vertexGPUBuffer.node.setFloat32Array(r.offset/4,i.data)}break;case dt.compose:for(let t=0;t<this.vertexCount;t++)this._attributeSlotLayouts.forEach(r=>{for(let i=0;i<r.length;i++){const a=r[i];let o=e.get(a.name);for(let n=0;n<a.stride;n++){let l=o.data[t*a.stride+n],h=t*(this._vertexBufferLayouts[0].arrayStride/4)+a.offset/4+n;this.vertexGPUBuffer.node.setFloat(l,h)}}});break;case dt.compose_bin:{let t=e.get(V.all);this.vertexGPUBuffer.node.setFloat32Array(0,t.data)}break}this.vertexGPUBuffer.apply()}compute(){}destroy(e){this.vertexCount=null,this.geometryType=null,this._vertexBufferLayouts=null,this._attributeSlotLayouts=null,this._attributeLocation=null,this.vertexGPUBuffer&&this.vertexGPUBuffer.destroy(e),this.vertexGPUBuffer=null}}class kh extends Tr{indicesNode;constructor(e){super(),this.bufferType=tr.IndicesGPUBuffer,this.createIndicesBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.INDEX|GPUBufferUsage.INDIRECT,e)}createIndicesBuffer(e,t){let r=Q.device;if(this.byteSize=t.length*4,this.usage=e,this.buffer&&this.destroy(),this.buffer=r.createBuffer({label:"IndicesGPUBuffer",size:this.byteSize,usage:e,mappedAtCreation:!1}),this.memory=new jr,this.memoryNodes=new Map,this.memory.allocation(this.byteSize),t){this.indicesNode=this.memory.allocation_node(t.length*4);const i=t.buffer instanceof ArrayBuffer?t.buffer:new Uint8Array(t.buffer).buffer;this.indicesNode.setArrayBuffer(0,i),this.apply()}}}class Lh{uuid="";name;indicesGPUBuffer;indicesFormat="uint16";indicesCount=0;constructor(){}createIndicesBuffer(e){e.data instanceof Uint16Array?this.indicesFormat="uint16":e.data instanceof Uint32Array&&(this.indicesFormat="uint32"),this.indicesCount=e.data.length,this.indicesGPUBuffer=new kh(e.data)}upload(e){this.indicesGPUBuffer.indicesNode.setArrayBuffer(0,e),this.indicesGPUBuffer.apply()}compute(){}destroy(){this.uuid=null,this.name=null,this.indicesFormat=null,this.indicesCount=null,this.indicesGPUBuffer.destroy(),this.indicesGPUBuffer=null}}class Oh{lodLevels}class Ie{instanceID;name;subGeometries=[];morphTargetsRelative;morphTargetDictionary;skinNames;bindPose;blendShapeData;vertexDim;vertexCount=0;_bounds;_attributeMap;_attributes;_indicesBuffer;_vertexBuffer;_onChange=!0;_wireframeLines;constructor(){this.instanceID=It(),this._attributeMap=new Map,this._attributes=[],this._vertexBuffer=new Ph}get indicesBuffer(){return this._indicesBuffer}get vertexBuffer(){return this._vertexBuffer}get vertexAttributes(){return this._attributes}get vertexAttributeMap(){return this._attributeMap}get geometryType(){return this._vertexBuffer.geometryType}set geometryType(e){this._vertexBuffer.geometryType=e}get bounds(){if(!this._bounds){this._bounds=new Fe(new d,new d(1,1,1)),this._bounds.min.x=Number.MAX_VALUE,this._bounds.min.y=Number.MAX_VALUE,this._bounds.min.z=Number.MAX_VALUE,this._bounds.max.x=-Number.MAX_VALUE,this._bounds.max.y=-Number.MAX_VALUE,this._bounds.max.z=-Number.MAX_VALUE;let e=this.getAttribute(V.position);if(e&&e.data)for(let t=0;t<e.data.length/3;t++){const r=e.data[t*3+0],i=e.data[t*3+1],a=e.data[t*3+2];this._bounds.min.x>r&&(this._bounds.min.x=r),this._bounds.min.y>i&&(this._bounds.min.y=i),this._bounds.min.z>a&&(this._bounds.min.z=a),this._bounds.max.x<r&&(this._bounds.max.x=r),this._bounds.max.y<i&&(this._bounds.max.y=i),this._bounds.max.z<a&&(this._bounds.max.z=a)}this._bounds.setFromMinMax(this._bounds.min,this._bounds.max)}return this._bounds}set bounds(e){this._bounds=e}addSubGeometry(...e){let t=new Oh;return t.lodLevels=e,this.subGeometries.push(t),t}generate(e){this._onChange&&(this._onChange=!1,this._indicesBuffer.upload(this.getAttribute(V.indices).data),this._vertexBuffer.createVertexBuffer(this._attributeMap,e),this._vertexBuffer.updateAttributes(this._attributeMap),this.vertexCount=this._vertexBuffer.vertexCount)}setIndices(e){if(!this._attributeMap.has(V.indices)){let t={attribute:V.indices,data:e};this._attributeMap.set(V.indices,t),this._indicesBuffer=new Lh,this._indicesBuffer.createIndicesBuffer(t)}}setAttribute(e,t){if(e==V.indices)this.setIndices(t);else{let r={attribute:e,data:t};this._attributeMap.set(e,r),this._attributes.push(e)}}getAttribute(e){return this._attributeMap.get(e)}hasAttribute(e){return this._attributeMap.has(e)}genWireframe(){if(this._wireframeLines)return this._wireframeLines;if(this.geometryType==dt.split||this.geometryType==dt.compose){let e=this.getAttribute(V.position),t=this.getAttribute(V.indices);if(t&&e&&t.data.length>0){let r=e.data,i=[];for(let a=0;a<t.data.length/3;a++){const o=t.data[a*3+0],n=t.data[a*3+1],l=t.data[a*3+2];let h=new d(r[o*3+0],r[o*3+1],r[o*3+2]),u=new d(r[n*3+0],r[n*3+1],r[n*3+2]),c=new d(r[l*3+0],r[l*3+1],r[l*3+2]);i.push(h,u),i.push(u,c),i.push(c,h)}return this._wireframeLines=i,i}}else if(this.geometryType==dt.compose_bin){let e=this.getAttribute(V.all),t=this.vertexDim,r=this.getAttribute(V.indices);if(r&&e&&r.data.length>0){let i=e.data,a=[];for(let o=0;o<r.data.length/3;o++){const n=r.data[o*3+0],l=r.data[o*3+1],h=r.data[o*3+2];let u=new d(i[n*t+0],i[n*t+1],i[n*t+2]),c=new d(i[l*t+0],i[l*t+1],i[l*t+2]),f=new d(i[h*t+0],i[h*t+1],i[h*t+2]);a.push(u,c),a.push(c,f),a.push(f,u)}return this._wireframeLines=a,a}}return null}compute(){this._indicesBuffer&&this._indicesBuffer.compute(),this._vertexBuffer&&this._vertexBuffer.compute()}static crossA=d.UP.clone();static crossB=d.UP.clone();static crossRet=d.UP.clone();static point1=d.UP.clone();static point2=d.UP.clone();static point3=d.UP.clone();computeNormals(){let e=this.getAttribute(V.position),t=this.getAttribute(V.normal),r=this.getAttribute(V.indices);if(!e||!t||!r)return this;let i=r.data.length/3,a=Ie.point1,o=Ie.point2,n=Ie.point3,l=Ie.crossA,h=Ie.crossB,u=Ie.crossRet;for(let c=0;c<i;c++){let f=r.data[c*3],g=r.data[c*3+1],p=r.data[c*3+2];a.set(e.data[f*3],e.data[f*3+1],e.data[f*3+2]),o.set(e.data[g*3],e.data[g*3+1],e.data[g*3+2]),n.set(e.data[p*3],e.data[p*3+1],e.data[p*3+2]),d.sub(a,o,l).normalize(),d.sub(a,n,h).normalize();let A=l.crossProduct(h,u).normalize();t.data[f*3]=t.data[g*3]=t.data[p*3]=A.x,t.data[f*3+1]=t.data[g*3+1]=t.data[p*3+1]=A.y,t.data[f*3+2]=t.data[g*3+2]=t.data[p*3+2]=A.z}return this._vertexBuffer.upload(V.normal,t),this}isPrimitive(){return!1}destroy(e){this.instanceID=null,this.name=null,this.subGeometries=null,this.morphTargetDictionary=null,this._bounds.destroy(),this._bounds=null,this._attributeMap=null,this._attributes=null,this._indicesBuffer.destroy(),this._vertexBuffer.destroy(),this._indicesBuffer=null,this._vertexBuffer=null}}class zh extends Ie{batchSize;constructor(e=128){super(),this.batchSize=e;const t=new Float32Array(12*e);for(let i=0;i<e;++i)t.set([-2,-2,i,2,-2,i,2,2,i,-2,2,i],i*12);const r=new Uint32Array(6*e);for(let i=0;i<e;++i){const a=i*4;r.set([0+a,1+a,2+a,0+a,2+a,3+a],i*6)}this.setAttribute(V.position,t),this.setIndices(r),this.addSubGeometry({indexStart:0,indexCount:r.length,vertexStart:0,vertexCount:t.length/3,firstStart:0,index:0,topology:0})}}class So extends je{_dataBuffer;create(e,t,r,i=!1){let a=Q.device;const o=Math.ceil(e*4/256)*256;this.format=X.rgba8unorm,this.mipmapCount=Math.floor(i?Math.log2(e):1),this.createTextureDescriptor(e,t,this.mipmapCount,this.format);const n=this._dataBuffer=a.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});a.queue.writeBuffer(n,0,r);const l=F.beginCommandEncoder();return l.copyBufferToTexture({buffer:n,bytesPerRow:o},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),F.endCommandEncoder(l),i&&dr.webGPUGenerateMipmap(this),this}updateTexture(e,t,r){let i=Q.device;const a=Math.ceil(e*4/256)*256;this.mipmapCount=Math.floor(Math.log2(e)),this._dataBuffer&&this._dataBuffer.destroy(),this._dataBuffer=null;const o=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(o,0,r);const n=F.beginCommandEncoder();n.copyBufferToTexture({buffer:o,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),F.endCommandEncoder(n),this.gpuSampler=i.createSampler(this),this.mipmapCount>1&&dr.webGPUGenerateMipmap(this)}}class Gh extends je{_dataBuffer;create(e,t,r){let i=Q.device;const a=e*4*4;this.format=X.rgba32uint,this.createTextureDescriptor(e,t,1,this.format);const n=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(n,0,r.buffer);const l=i.createCommandEncoder();return l.copyBufferToTexture({buffer:n,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),i.queue.submit([l.finish()]),this.samplerBindingLayout.type="non-filtering",this.textureBindingLayout.sampleType="uint",this.gpuSampler=i.createSampler({}),this}updateTexture(e,t,r){let i=Q.device;const a=e*4*4;i.queue.writeTexture({texture:this.getGPUTexture()},r.buffer,{bytesPerRow:a},{width:e,height:t,depthOrArrayLayers:1})}}class Wh extends je{_dataBuffer;create(e,t,r){let i=Q.device;const a=e*4;this.format=X.r32uint,this.createTextureDescriptor(e,t,1,this.format);const n=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(n,0,r.buffer);const l=i.createCommandEncoder();return l.copyBufferToTexture({buffer:n,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),i.queue.submit([l.finish()]),this.samplerBindingLayout.type="non-filtering",this.textureBindingLayout.sampleType="uint",this.gpuSampler=i.createSampler({}),this}updateTexture(e,t,r){let i=Q.device;const a=e*4;i.queue.writeTexture({texture:this.getGPUTexture()},r.buffer,{bytesPerRow:a},{width:e,height:t,depthOrArrayLayers:1})}}const Jh=new Float32Array(1),Jg=new Int32Array(Jh.buffer);let ri=function(s){Jh[0]=s;const e=Jg[0];let t=e>>16&32768,r=e>>12&2047;const i=e>>23&255;return i<103?t:i>142?(t|=31744,t|=(i==255?1:0)&&e&8388607,t):i<114?(r|=2048,t|=(r>>114-i)+(r>>113-i&1),t):(t|=i-112<<10|r>>1,t+=r&1,t)};class _o extends je{uint16Array;floatArray;_dataBuffer;create(e,t,r=null,i=!0){if(r==null){r=[];for(let a=0,o=e*t*4;a<o;a++)r[a]=0}return this.updateTexture(e,t,r,i),this}updateTexture(e,t,r,i=!0){(e!=this.width||t!=this.height)&&(this._dataBuffer&&this._dataBuffer.destroy(),this._dataBuffer=null,this.gpuTexture&&this.gpuTexture.destroy(),this.gpuTexture=null),this.floatArray=r;let a=Q.device;const o=e*4*2;this.format=X.rgba16float,this.mipmapCount=Math.floor(i?Math.log2(e):1),this.createTextureDescriptor(e,t,this.mipmapCount,this.format),(!this.uint16Array||this.uint16Array.length!=r.length)&&(this.uint16Array=new Uint16Array(r.length));let n=this.uint16Array;for(let u=0,c=n.length;u<c;u++)n[u]=ri(r[u]);const l=this._dataBuffer=a.createBuffer({size:n.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});a.queue.writeBuffer(l,0,n);const h=F.beginCommandEncoder();h.copyBufferToTexture({buffer:l,bytesPerRow:o},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),this.useMipmap||(this.samplerBindingLayout.type="filtering",this.textureBindingLayout.sampleType="float"),F.endCommandEncoder(h),this.gpuSampler=a.createSampler(this),this.gpuTexture=this.getGPUTexture(),this.mipmapCount>1&&dr.webGPUGenerateMipmap(this)}}var Zg=Object.getOwnPropertyDescriptor,Yg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Zg(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=o(i)||i);return i};let ga=class extends Nr{count=0;size=new j;splatColor;transformA;transformB;texParams;splatOrder;gsplatMaterial;_positions;get positions(){return this._positions}_worldPositions;_orderData;_sortWorker;_lastSentTime=0;_minIntervalMs=16;_centersSent=!1;_lastViewMatrixHash=0;_lastCameraSpeed=0;_adaptiveSorting=!0;_lastPixelCullParams="";_texturesInitialized=!1;_lodEnabled=!1;_lodDistances=[5,10,20,40];_lodRatios=[1,.75,.5,.25,.1];_currentLodLevel=0;_minPixelCoverage=4;_maxPixelCoverage=0;_maxPixelCullDistance=0;_mapping=null;_fullCount=0;get fullCount(){return this._fullCount}_batchSize=128;instanceCount=0;constructor(){super()}initAsset(s){this.count=s.count,this._fullCount=s.count,this.size=this.evalTextureSize(s.count),this.buildColor(s),this.buildTransform(s),this.texParams=new Float32Array([this.count,this.size.x,this.count,1]),this._positions=s.position;const e=this.size.x*this.size.y;this._orderData=new Uint32Array(e);for(let t=0;t<e;t++)this._orderData[t]=t<this.count?t:this.count>0?this.count-1:0;this.splatOrder=new Wh().create(this.size.x,this.size.y,this._orderData),this.splatOrder.name="splatOrder",this.splatOrder.minFilter="nearest",this.splatOrder.magFilter="nearest",this.splatOrder.addressModeU="clamp-to-edge",this.splatOrder.addressModeV="clamp-to-edge",this.gsplatMaterial=new Vh,this.geometry=new zh(this._batchSize),this.materials=[this.gsplatMaterial],this.instanceCount=0}onBeforeUpdate(s){this.count>0&&s?.camera&&(this._lodEnabled&&this.updateLOD(s),s.camera.viewMatrix&&this.scheduleOrder(s.camera.viewMatrix))}updateLOD(s){if(!this._worldPositions||this._fullCount===0)return;const t=s.camera.viewMatrix.rawData,r=-(t[0]*t[12]+t[1]*t[13]+t[2]*t[14]),i=-(t[4]*t[12]+t[5]*t[13]+t[6]*t[14]),a=-(t[8]*t[12]+t[9]*t[13]+t[10]*t[14]);let o=0,n=0,l=0;const h=Math.min(100,this._fullCount);for(let A=0;A<h;A++){const U=Math.floor(A/h*this._fullCount)*3;o+=this._worldPositions[U+0],n+=this._worldPositions[U+1],l+=this._worldPositions[U+2]}o/=h,n/=h,l/=h;const u=r-o,c=i-n,f=a-l,g=Math.sqrt(u*u+c*c+f*f);let p=this._lodDistances.length;for(let A=0;A<this._lodDistances.length;A++)if(g<this._lodDistances[A]){p=A;break}if(p!==this._currentLodLevel){this._currentLodLevel=p;const A=this._lodRatios[p],U=Math.floor(this._fullCount*A);if(this._mapping){const x=this._mapping;this._mapping=new Uint32Array(Math.min(U,x.length));for(let v=0;v<this._mapping.length;v++)this._mapping[v]=x[v];this.setMapping(this._mapping)}else this.count=U,this.texParams[0]=this.count,this.texParams[2]=this.count}}setMapping(s){this._mapping=s&&s.length>0?s:null,this.count=this._mapping?this._mapping.length:this._fullCount,this.texParams[0]=this.count,this.texParams[2]=Math.min(this.texParams[0],this.count);const e=this.size.x*this.size.y;for(let t=0;t<e;t++)this._orderData[t]=t<this.count?t:this.count>0?this.count-1:0;if(this.splatOrder.updateTexture(this.size.x,this.size.y,this._orderData),this._sortWorker){const t=this._worldPositions||this._positions,r=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(t);if(this._mapping)for(let i=0;i<this._mapping.length;++i){const a=this._mapping[i]*3,o=i*3;r[o+0]=t[a+0],r[o+1]=t[a+1],r[o+2]=t[a+2]}this._sortWorker.postMessage({type:"centers",centers:r.buffer,mapping:this._mapping?this._mapping:null},[r.buffer]),this._centersSent=!0}else this._centersSent=!1;this.instanceCount=0}setVisBoost(s){this.texParams[3]=Math.max(0,s)}setSortThrottle(s){this._minIntervalMs=Math.max(0,s|0)}setAdaptiveSorting(s){this._adaptiveSorting=s}setLOD(s,e,t){this._lodEnabled=s,e&&(this._lodDistances=e),t&&(this._lodRatios=t)}getLODStats(){return{enabled:this._lodEnabled,currentLevel:this._currentLodLevel,distances:this._lodDistances,ratios:this._lodRatios,currentRatio:this._lodRatios[this._currentLodLevel],visibleCount:this._lodEnabled?Math.floor(this._fullCount*this._lodRatios[this._currentLodLevel]):this._fullCount}}setPixelCulling(s,e=0,t=0){this._minPixelCoverage=Math.max(0,s),this._maxPixelCoverage=Math.max(0,e),this._maxPixelCullDistance=Math.max(0,t)}getPixelCullingStats(){return{minPixels:this._minPixelCoverage,maxPixels:this._maxPixelCoverage,maxPixelCullDistance:this._maxPixelCullDistance,maxEnabled:this._maxPixelCoverage>0,distanceEnabled:this._maxPixelCullDistance>0}}getBatchingStats(){return{enabled:!0,batchSize:this._batchSize,instanceCount:this.instanceCount,splatCount:this.count,reduction:this.count>0?(1-this.instanceCount/this.count)*100:0}}evalTextureSize(s){let e=Math.ceil(Math.sqrt(s));const t=64;e=Math.ceil(e/t)*t;const r=Math.ceil(s/e);return new j(e,r)}buildColor(s){const e=this.size.x|0,t=this.size.y|0,r=new Uint8Array(e*t*4),i=.28209479177387814,a=s.count,o=s.sh?.coeffs,n=o?o.length/(3*a):1;for(let l=0;l<a;l++){let h=.5,u=.5,c=.5;if(o&&n>=1){const p=l*n*3;h=.5+o[p+0]*i,u=.5+o[p+n+0]*i,c=.5+o[p+2*n+0]*i}const f=s.opacity?1/(1+Math.exp(-s.opacity[l])):1,g=l*4;r[g+0]=Math.max(0,Math.min(255,Math.floor(h*255))),r[g+1]=Math.max(0,Math.min(255,Math.floor(u*255))),r[g+2]=Math.max(0,Math.min(255,Math.floor(c*255))),r[g+3]=Math.max(0,Math.min(255,Math.floor(f*255)))}this.splatColor=new So().create(e,t,r,!1),this.splatColor.name="splatColor",this.splatColor.minFilter="nearest",this.splatColor.magFilter="nearest",this.splatColor.mipmapFilter="nearest",this.splatColor.addressModeU="clamp-to-edge",this.splatColor.addressModeV="clamp-to-edge"}buildTransform(s){const e=this.size.x|0,t=this.size.y|0,r=s.count,i=new Uint32Array(e*t*4),a=new Array(e*t*4).fill(0),o=new ArrayBuffer(4),n=new Float32Array(o),l=new Uint32Array(o),h=g=>(n[0]=g,l[0]),u=s.position,c=s.rotation,f=s.scale;for(let g=0;g<r;g++){const p=g*4,A=u[g*3+0],U=u[g*3+1],x=u[g*3+2];i[p+0]=h(A),i[p+1]=h(U),i[p+2]=h(x);let v=0,S=0,C=0,_=1;if(c){v=c[g*4+0],S=c[g*4+1],C=c[g*4+2],_=c[g*4+3];const Wt=1/Math.hypot(v,S,C,_);v*=Wt,S*=Wt,C*=Wt,_*=Wt}let y=1,b=1,w=1;f&&(y=Math.exp(f[g*3+0]),b=Math.exp(f[g*3+1]),w=Math.exp(f[g*3+2]));const R=v+v,E=S+S,N=C+C,z=v*R,Y=v*E,ee=v*N,oe=S*E,te=S*N,ge=C*N,Ce=_*R,J=_*E,ce=_*N,he=1-(oe+ge),Ue=Y+ce,xe=ee-J,Ve=Y-ce,Ee=1-(z+ge),ye=te+Ce,Ne=ee+J,lt=te-Ce,pr=1-(z+oe),Nt=he*y,Qt=Ue*y,Rt=xe*y,Vt=Ve*b,_t=Ee*b,mr=ye*b,Ar=Ne*w,Ur=lt*w,xr=pr*w,pi=Nt*Nt+Vt*Vt+Ar*Ar,Zr=Nt*Qt+Vt*_t+Ar*Ur,vr=Nt*Rt+Vt*mr+Ar*xr,mi=Qt*Qt+_t*_t+Ur*Ur,Yr=Qt*Rt+_t*mr+Ur*xr,Ai=Rt*Rt+mr*mr+xr*xr,Br=p;a[Br+0]=pi,a[Br+1]=Zr,a[Br+2]=vr,a[Br+3]=Ai;const Ui=ri(mi)&65535,xi=ri(Yr)&65535;i[p+3]=Ui|xi<<16}this.transformA=new Gh().create(e,t,i),this.transformA.name="transformA",this.transformA.minFilter="nearest",this.transformA.magFilter="nearest",this.transformA.addressModeU="clamp-to-edge",this.transformA.addressModeV="clamp-to-edge",this.transformB=new _o().create(e,t,a,!1),this.transformB.name="transformB",this.transformB.minFilter="nearest",this.transformB.magFilter="nearest",this.transformB.mipmapFilter="nearest",this.transformB.addressModeU="clamp-to-edge",this.transformB.addressModeV="clamp-to-edge"}updateWorldPositions(){if(!this._positions)return;const s=this.object3D.transform.worldMatrix,e=this._positions,t=this._fullCount;this._worldPositions||(this._worldPositions=new Float32Array(e.length));const r=s.rawData;for(let i=0;i<t;i++){const a=i*3,o=e[a+0],n=e[a+1],l=e[a+2];this._worldPositions[a+0]=r[0]*o+r[4]*n+r[8]*l+r[12],this._worldPositions[a+1]=r[1]*o+r[5]*n+r[9]*l+r[13],this._worldPositions[a+2]=r[2]*o+r[6]*n+r[10]*l+r[14]}this._centersSent=!1}scheduleOrder(s){if(this.count===0)return;const e=this.object3D.transform.localChange;(e||!this._worldPositions)&&this.updateWorldPositions();const t=s.rawData,r=t[2],i=t[6],a=t[10],o=-(t[0]*t[12]+t[1]*t[13]+t[2]*t[14]),n=-(t[4]*t[12]+t[5]*t[13]+t[6]*t[14]),l=-(t[8]*t[12]+t[9]*t[13]+t[10]*t[14]),h=performance.now(),u=(h-this._lastSentTime)/1e3,c=Math.floor(o*1e3)^Math.floor(n*1e3)^Math.floor(l*1e3),f=Math.floor(r*1e3)^Math.floor(i*1e3)^Math.floor(a*1e3),g=c^f;if(g===this._lastViewMatrixHash&&!e)return;let p=this._minIntervalMs;if(this._adaptiveSorting&&this._minIntervalMs>0){const U=Math.abs(g-this._lastViewMatrixHash)/Math.max(u,.001);U<1e3?p=this._minIntervalMs:U<1e4?p=this._minIntervalMs*.5:p=this._minIntervalMs*.2,this._lastCameraSpeed=U}if(!(h-this._lastSentTime<p)){if(this._lastViewMatrixHash=g,this._lastSentTime=h,!this._sortWorker){this._sortWorker=this.createSortWorker(),this._sortWorker.onmessage=v=>{const S=v.data.order,C=this._orderData.buffer;this._sortWorker.postMessage({order:C},[C]);const _=new Uint32Array(S),y=this.size.x*this.size.y,b=this.count;(!this._orderData||this._orderData.length!==y)&&(this._orderData=new Uint32Array(y));const w=Math.min(b,_.length);if(this._orderData.set(_.subarray(0,w),0),w<y){const N=b>0?b-1:0;this._orderData.fill(N,w,y)}this.splatOrder.updateTexture(this.size.x,this.size.y,this._orderData);const R=Math.max(0,Math.min(this.count,v.data.count|0));this.texParams[2]=R;const E=Math.ceil(R/this._batchSize);this.instanceCount=E};const A=this._worldPositions||this._positions,U=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(A);if(this._mapping)for(let v=0;v<this._mapping.length;++v){const S=this._mapping[v]*3,C=v*3;U[C+0]=A[S+0],U[C+1]=A[S+1],U[C+2]=A[S+2]}const x=new Uint32Array(this.count);for(let v=0;v<this.count;v++)x[v]=v;this._sortWorker.postMessage({order:x.buffer,centers:U.buffer,mapping:this._mapping},[x.buffer,U.buffer]),this._centersSent=!0}if(!this._centersSent&&this._sortWorker){const A=this._worldPositions||this._positions,U=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(A);if(this._mapping)for(let x=0;x<this._mapping.length;++x){const v=this._mapping[x]*3,S=x*3;U[S+0]=A[v+0],U[S+1]=A[v+1],U[S+2]=A[v+2]}this._sortWorker.postMessage({type:"centers",centers:U.buffer,mapping:this._mapping?this._mapping:null},[U.buffer]),this._centersSent=!0}this._sortWorker.postMessage({cameraPosition:{x:o,y:n,z:l},cameraDirection:{x:-r,y:-i,z:-a}})}}createSortWorker(){function s(){let o,n,l,h,u,c=!1;const f={x:0,y:0,z:0},g={x:0,y:0,z:0},p={x:0,y:0,z:0},A={x:0,y:0,z:0};let U,x;const v=(C,_,y)=>{for(;C<=_;){const b=_+C>>1,w=y(b);if(w>0)C=b+1;else if(w<0)_=b-1;else return b}return~C},S=()=>{if(!o||!n||!h||!u)return;const C=h.x,_=h.y,y=h.z,b=u.x,w=u.y,R=u.z,E=.001;if(!c&&Math.abs(C-f.x)<E&&Math.abs(_-f.y)<E&&Math.abs(y-f.z)<E&&Math.abs(b-g.x)<E&&Math.abs(w-g.y)<E&&Math.abs(R-g.z)<E)return;c=!1,f.x=C,f.y=_,f.z=y,g.x=b,g.y=w,g.z=R;const N=n.length/3;U?.length!==N&&(U=new Uint32Array(N));let z,Y;for(let J=0;J<8;++J){const ce=(J&1?p.x:A.x)-C,he=(J&2?p.y:A.y)-_,Ue=(J&4?p.z:A.z)-y,xe=ce*b+he*w+Ue*R;J===0?z=Y=xe:(z=Math.min(z,xe),Y=Math.max(Y,xe))}x?x.fill(0):x=new Uint32Array(65537);const ee=Y-z,oe=ee<1e-6?0:1/ee*2**16;for(let J=0;J<N;++J){const ce=J*3,he=n[ce+0]-C,Ue=n[ce+1]-_,xe=n[ce+2]-y,Ve=he*b+Ue*w+xe*R,Ee=Math.floor((Ve-z)*oe);U[J]=Ee,x[Ee]++}for(let J=1;J<65537;J++)x[J]+=x[J-1];for(let J=0;J<N;J++){const ce=U[J],he=--x[ce];o[he]=J}const te=J=>U[o[J]]/oe+z,ge=()=>{const J=v(0,N-1,ce=>-te(ce));return Math.min(N,Math.abs(J))},Ce=te(N-1)>=0?ge():N;if(l)for(let J=0;J<N;++J)o[J]=l[o[J]];self.postMessage({order:o.buffer,count:Ce},[o.buffer]),o=null};self.onmessage=C=>{if(C.data.order&&(o=new Uint32Array(C.data.order)),C.data.centers){n=new Float32Array(C.data.centers),p.x=A.x=n[0],p.y=A.y=n[1],p.z=A.z=n[2];const _=n.length/3;for(let y=1;y<_;++y){const b=n[y*3+0],w=n[y*3+1],R=n[y*3+2];p.x=Math.min(p.x,b),p.y=Math.min(p.y,w),p.z=Math.min(p.z,R),A.x=Math.max(A.x,b),A.y=Math.max(A.y,w),A.z=Math.max(A.z,R)}c=!0}C.data.hasOwnProperty("mapping")&&(l=C.data.mapping?new Uint32Array(C.data.mapping):null,c=!0),C.data.cameraPosition&&(h=C.data.cameraPosition),C.data.cameraDirection&&(u=C.data.cameraDirection),S()}}const e=`(${s.toString()})()`,t=new Blob([e],{type:"application/javascript"}),r=URL.createObjectURL(t);return new Worker(r)}nodeUpdate(s,e,t,r){const i=this.object3D.transform.worldMatrix;this.gsplatMaterial.setTransformMatrix(i);const a=`${this._minPixelCoverage},${this._maxPixelCoverage},${this._maxPixelCullDistance},${this._batchSize}`;a!==this._lastPixelCullParams&&(this.gsplatMaterial.setPixelCulling(this._minPixelCoverage,this._maxPixelCoverage,this._maxPixelCullDistance,this._batchSize),this._lastPixelCullParams=a),this._texturesInitialized||(this.gsplatMaterial.setSplatTextures(this.splatColor,this.transformA,this.transformB,this.texParams,this.splatOrder),this._texturesInitialized=!0),super.nodeUpdate(s,e,t,r)}renderPass(s,e,t){const r=t.encoder;for(let i of this.materials){const a=i.getPass(e);if(!(!a||a.length===0))for(const o of a){if(!o.pipeline)continue;o.apply(this.geometry,t.rendererPassState||t),F.bindPipeline(r,o),F.bindGeometryBuffer(r,this.geometry);const l=this.geometry.subGeometries[0].lodLevels[0];this.instanceCount>0?F.drawIndexed(r,l.indexCount,this.instanceCount,l.indexStart,0,0):F.drawIndexed(r,l.indexCount,1,l.indexStart,0,0)}}}destroy(s){this._sortWorker&&(this._sortWorker.terminate(),this._sortWorker=null),this.splatColor&&(this.splatColor.destroy(s),this.splatColor=null),this.transformA&&(this.transformA.destroy(s),this.transformA=null),this.transformB&&(this.transformB.destroy(s),this.transformB=null),this.splatOrder&&(this.splatOrder.destroy(s),this.splatOrder=null),this.gsplatMaterial&&(this.gsplatMaterial.destroy(s),this.gsplatMaterial=null),this._positions=null,this._worldPositions=null,this._orderData=null,this.texParams=null,this._mapping=null,super.destroy(s)}};ga=Yg([Pt(ga,"GSplatRenderer")],ga);class Fo{static maxVector=new d(Number.MAX_VALUE*.1,Number.MAX_VALUE*.1,Number.MAX_VALUE*.1);static minVector=this.maxVector.clone().multiplyScalar(-1);static genMeshMaxVector=d.ZERO.clone();static genMeshMinVector=d.ZERO.clone();static genMeshVectorList8=[new d,new d,new d,new d,new d,new d,new d,new d];static genGSplatBounds(e,t){t||=new Fe(d.ZERO,d.ZERO),t.setFromMinMax(this.maxVector,this.minVector);let r=e.getComponent(ga);if(!r)return console.warn("genGSplatBounds: No GSplatRenderer found on object"),t;const i=r.positions,a=r.fullCount;if(!i||a===0)return console.warn("genGSplatBounds: No position data available"),t;const o=e.transform.worldMatrix,n=new d;for(let l=0;l<a;l++){const h=l*3;n.set(i[h+0],i[h+1],i[h+2]),o.transformPoint(n,n),t.expandByPoint(n)}return t.setFromMinMax(t.min,t.max),t}static genMeshBounds(e,t){let r=this.genMeshMinVector,i=this.genMeshMaxVector,a=this.genMeshVectorList8;t||=new Fe(d.ZERO,d.ZERO),t.setFromMinMax(this.maxVector,this.minVector);let o=e.getComponents(K);for(const n of o)if(n&&n.geometry){let l=n.object3D.transform.worldMatrix;r.copy(n.geometry.bounds.min),i.copy(n.geometry.bounds.max),a[0].set(r.x,r.y,r.z),a[1].set(r.x,r.y,i.z),a[2].set(r.x,i.y,r.z),a[3].set(r.x,i.y,i.z),a[4].set(i.x,r.y,r.z),a[5].set(i.x,r.y,i.z),a[6].set(i.x,i.y,r.z),a[7].set(i.x,i.y,i.z);for(const h of a)l.transformPoint(h,h),t.expandByPoint(h)}return i.copyFrom(t.max),r.copyFrom(t.min),t.setFromMinMax(r,i),t}static transformBound(e,t,r){let i=this.genMeshMinVector.copyFrom(t.min),a=this.genMeshMaxVector.copyFrom(t.max),o=this.genMeshVectorList8;r||=new Fe(d.ZERO,d.ZERO),r.setFromMinMax(this.maxVector,this.minVector),o[0].set(i.x,i.y,i.z),o[1].set(i.x,i.y,a.z),o[2].set(i.x,a.y,i.z),o[3].set(i.x,a.y,a.z),o[4].set(a.x,i.y,i.z),o[5].set(a.x,i.y,a.z),o[6].set(a.x,a.y,i.z),o[7].set(a.x,a.y,a.z);for(const n of o)e.transformPoint(n,n),r.expandByPoint(n);return a.copyFrom(r.max),i.copyFrom(r.min),r.setFromMinMax(i,a),r}}class Zh extends Er{name="";_instanceID="";_numChildren;get instanceID(){return this._instanceID}transform;renderNode;entityChildren;components;waitDisposeComponents;_bound;_boundWorld;_isBoundChange=!0;_dispose=!1;get dispose(){return this._dispose}getObjectByName(e){if(e.indexOf("/")>=0){let r=e.split("/"),i=this;for(;r.length>0&&i;){let a=r.shift();if(i=i.getChildByName(a,!1),!i)return null}return i}else return this.getChildByName(e,!1)}constructor(){super(),this.entityChildren=[],this.components=new Map,this._instanceID=$s().toString(),this.waitDisposeComponents=[]}get numChildren(){return this._numChildren}addChild(e){if(e==null)throw new Error("child is null!");if(e===this)throw new Error("child is self!");return this.entityChildren.indexOf(e)==-1?(e.removeFromParent(),e.transform.parent=this.transform,this.entityChildren.push(e),this._numChildren=this.entityChildren.length,this.noticeComponents("onAddChild",e),e):null}removeChild(e){if(e===null)return;if(e===this)throw new Error("add child is self!");let t=this.entityChildren.indexOf(e);t!=-1&&(this.entityChildren.splice(t,1),e.transform.parent=null,this._numChildren=this.entityChildren.length,this.noticeComponents("onRemoveChild",e))}removeAllChild(){for(;this.numChildren>0;)this.removeChild(this.entityChildren[0])}removeSelf(){return this.removeFromParent()}removeChildByIndex(e){e>=0&&e<this.entityChildren.length?this.removeChild(this.entityChildren[e]):console.error("remove child by index , index out of range")}hasChild(e){return this.entityChildren.indexOf(e)!=-1}removeFromParent(){let e=this.transform.parent;return e&&e.object3D&&e.object3D.removeChild(this),this}getChildByIndex(e){let t=null;return e<this.entityChildren.length&&(t=this.entityChildren[e]),t}getChildByName(e,t=!0){let r=null;for(const i of this.entityChildren){if(i.name==e)return r=i,r;if(t&&(r=i.getChildByName(e,t),r))return r}return r}update(){}instantiate(){return null}onTransformLocalChange(e){this._isBoundChange=!0}get bound(){return(this._isBoundChange||!this._bound)&&this.updateBound(),this._boundWorld}set bound(e){this._bound=e,this._boundWorld=this._bound.clone(),this._isBoundChange=!0}updateBound(){return this._bound||(this._bound=new Fe,this._boundWorld=this._bound.clone(),this._isBoundChange=!0),this._isBoundChange&&(Fo.transformBound(this.transform.worldMatrix,this._bound,this._boundWorld),this._isBoundChange=!1),this._boundWorld}waitUpdate(){this._dispose?(this.transform.parent&&this.transform.parent.object3D.removeChild(this),this.components.forEach((e,t)=>{e.enable=!1,e.beforeDestroy(),e.destroy()}),this.components.clear()):Se.waitStartComponent.forEach((e,t)=>{for(;e.length>0;){const r=e.shift();r.__start(),Se.waitStartComponent.delete(r.object3D)}})}noticeComponents(e,t){for(let r of this.components.values())r[e]?.(t)}destroy(e){this._dispose||(this.components.forEach(t=>{t.beforeDestroy(e)}),this.components.forEach(t=>{t.destroy(e)}),this.components.clear(),this.entityChildren.forEach(t=>{t.destroy(e)}),this.removeAllChild(),this.transform.parent=null,this._dispose=!0,super.destroy())}}var Xg=Object.getOwnPropertyDescriptor,Hg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Xg(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=o(i)||i);return i};let q=class extends Zh{_isScene3D;prefabRef;serializeTag;constructor(){super(),this.transform=this.addComponent(Dt),this.transform.eventDispatcher.addEventListener(Dt.LOCAL_ONCHANGE,this.onTransformLocalChange,this)}get isScene3D(){return this._isScene3D}forChild(s){this.entityChildren.forEach(e=>{s(e),e.forChild(s)})}addComponent(s,e){if(!this.components.has(s)){let t=new s;return t.object3D=this,this.components.set(s,t),t.__init(e),Se.appendWaitStart(t),t}return this.components.get(s)}getOrAddComponent(s){let e=this.components.get(s);return e||(e=this.addComponent(s)),e}removeComponent(s){if(this.components.has(s)){let e=this.components.get(s);Se.removeWaitStart(this,e),this.components.delete(s),e.__stop(),e.beforeDestroy(),e.destroy()}}hasComponent(s){return this.components.has(s)}getComponent(s){return this.components.get(s)}getComponentFromParent(s){if(!this.parent)return null;let e=this.parent.object3D.getComponent(s);return e||this.parent.object3D.getComponentFromParent(s)}getComponentsInChild(s){let e=[],t=this.components.get(s);t&&e.push(t);for(let r=0;r<this.entityChildren.length;r++){let a=this.entityChildren[r].getComponentsInChild(s);e.push(...a)}return e}getComponents(s,e,t){e||=[];let r=this.getComponent(s);r&&(r.enable||t)&&e.push(r);for(let i=0,a=this.entityChildren.length;i<a;i++){let o=this.entityChildren[i];o&&o instanceof q&&o.getComponents(s,e,t)}return e}getComponentsExt(s,e,t){e||=[];let r=this.components.get(s);if(r&&(r.enable||t))e.push(r);else for(const i of this.entityChildren)i instanceof q&&i.getComponentsExt(s,e,t);return e}getComponentsByProperty(s,e,t=!0,r,i){r||=[];let a;for(const o of this.components.values())o&&(o.enable||i)&&o[s]===e&&(r.push(o),a=!0);if(!(a&&t))for(const o of this.entityChildren)o instanceof q&&o.getComponentsByProperty(s,e,t,r,i);return r}clone(){return this.instantiate()}instantiate(){let s=new q;return s.name=this.name,s.serializeTag=this.serializeTag,s.prefabRef=this.prefabRef,this.entityChildren.forEach((e,t)=>{let r=e.instantiate();s.addChild(r)}),this.components.forEach((e,t)=>{e.cloneTo(s)}),s}get localPosition(){return this.transform.localPosition}set localPosition(s){this.transform.localPosition=s}get localRotation(){return this.transform.localRotation}set localRotation(s){this.transform.localRotation=s}get localScale(){return this.transform.localScale}set localScale(s){this.transform.localScale=s}get localQuaternion(){return this.transform.localRotQuat}set localQuaternion(s){this.transform.localRotQuat=s}notifyChange(){this.transform.notifyChange()}get parent(){return this.transform.parent}get parentObject(){return this.transform.parent.object3D}set x(s){this.transform.x=s}get x(){return this.transform.x}set y(s){this.transform.y=s}get y(){return this.transform.y}set z(s){this.transform.z=s}get z(){return this.transform.z}set scaleX(s){this.transform.scaleX=s}get scaleX(){return this.transform.scaleX}set scaleY(s){this.transform.scaleY=s}get scaleY(){return this.transform.scaleY}set scaleZ(s){this.transform.scaleZ=s}get scaleZ(){return this.transform.scaleZ}set rotationX(s){this.transform.rotationX=s}get rotationX(){return this.transform.rotationX}set rotationY(s){this.transform.rotationY=s}get rotationY(){return this.transform.rotationY}set rotationZ(s){this.transform.rotationZ=s}get rotationZ(){return this.transform.rotationZ}fixedUpdate(){}lateUpdate(){}traverse(s){s(this);for(let e=0,t=this.entityChildren.length;e<t;e++){let r=this.entityChildren[e];r instanceof q&&r.traverse(s)}}destroy(s){this.transform.eventDispatcher.removeEventListener(Dt.LOCAL_ONCHANGE,this.onTransformLocalChange,this),super.destroy(s)}};q=Hg([jg],q);function jg(s,e){return class extends q{set active(t){this.transform.enable=t>0}get active(){return this.transform.enable?1:0}get materialColor(){return this.getComponent(K)?.material?.shader.getDefaultColorShader().baseColor}set materialColor(t){let r=this.getComponent(K)?.material;r&&(r.shader.getDefaultColorShader().baseColor=t)}notifyMaterialColorChange(t,r){this.getComponent(K).materials?.[t]?.shader.getDefaultColorShader().uniforms[r].onChange()}}}class Ke{static createCamera3DObject(e,t){return this.createCamera3D(null,e,t)}static createCamera3D(e,t,r){return e||=new q,t&&t.addChild(e),r&&(e.name=r),e.getOrAddComponent(Ji)}static UnProjection(e,t,r=1,i){let a=new d(e,t,0),o=1,n=d.HELP_0,l=Q.canvas.offsetLeft,h=Q.canvas.offsetTop,u=Q.canvas.clientWidth,c=Q.canvas.clientHeight;n.x=((a.x-l)*o/u-.5)*2,n.y=-((a.y-h)*o/c-.5)*2,n.z=r;let f=new d(0,0,0),g=I.helpMatrix2;g.copyFrom(i.projectionMatrix),g.invert();let p=I.helpMatrix;return p.identity(),p.multiply(g),p.multiply(i.transform.worldMatrix),p.perspectiveMultiplyPoint3(n,f),f}static Projection(e,t,r){let i=r||new d(0,0,0),a=I.helpMatrix;a.copyFrom(t.viewMatrix),a.multiply(t.projectionMatrix),a.perspectiveMultiplyPoint3(e,i);let o=Q.canvas.clientWidth/2,n=Q.canvas.clientHeight/2;return i.x=i.x*o+o,i.y=n-i.y*n,i}static UnProjection2(e,t,r,i,a){let o=a||new d(0,0,0),n=I.helpMatrix;n.copyFrom(i.pvMatrixInv);let l=Q.canvas.clientWidth/2,h=Q.canvas.clientHeight/2;return o.x=(e-l)/l,o.y=(h-t)/h,o.z=r,n.perspectiveMultiplyPoint3(o,o),o}}class Tt{static maxNumDirectionShadow=8;static maxNumPointShadow=8;static directionLightList;static pointLightList;static shadowLights;static init(){this.directionLightList=new Map,this.pointLightList=new Map,this.shadowLights=new Map}static createBuffer(e){if(!this.shadowLights.has(e.scene)){let t=new Float32Array(16);this.shadowLights.set(e.scene,t)}}static getShadowLightList(e){if(!e.transform.view3D)return null;if(e.lightData.lightType==Xe.DirectionLight){let t=this.directionLightList.get(e.transform.view3D.scene);return t||(t=[],this.directionLightList.set(e.transform.view3D.scene,t)),t}else if(e.lightData.lightType==Xe.PointLight){let t=this.pointLightList.get(e.transform.view3D.scene);return t||(t=[],this.pointLightList.set(e.transform.view3D.scene,t)),t}else if(e.lightData.lightType==Xe.SpotLight){let t=this.pointLightList.get(e.transform.view3D.scene);return t||(t=[],this.pointLightList.set(e.transform.view3D.scene,t)),t}}static getShadowLightWhichScene(e,t){if(t==Xe.DirectionLight){let r=this.directionLightList.get(e);return r||(r=[],this.directionLightList.set(e,r)),r}else if(t==Xe.PointLight){let r=this.pointLightList.get(e);return r||(r=[],this.pointLightList.set(e,r)),r}}static getDirectShadowLightWhichScene(e){let t=this.directionLightList.get(e);return t||(t=[],this.directionLightList.set(e,t)),t}static getPointShadowLightWhichScene(e){let t=this.pointLightList.get(e);return t||(t=[],this.pointLightList.set(e,t)),t}static addShadowLight(e){if(!e.transform.view3D)return null;let t=e.transform.view3D.scene;if(e.lightData.lightType==Xe.DirectionLight){let r=this.directionLightList.get(t);if(r||(r=[],this.directionLightList.set(t,r)),!e.shadowCamera){e.shadowCamera=Ke.createCamera3DObject(null,"shadowCamera"),e.shadowCamera.isShadowCamera=!0;let i=-1e3;e.shadowCamera.orthoOffCenter(i,-i,i,-i,1,1e4)}return r.indexOf(e)==-1&&r.push(e),r}else if(e.lightData.lightType==Xe.PointLight||e.lightData.lightType==Xe.SpotLight){let r=this.pointLightList.get(t);return r&&r.length>=8||(r||(r=[],this.pointLightList.set(t,r)),r.indexOf(e)==-1&&r.push(e)),r}}static removeShadowLight(e){if(e.lightData.castShadowIndex=-1,!e.transform.view3D)return null;if(e.lightData.lightType==Xe.DirectionLight){let t=this.directionLightList.get(e.transform.view3D.scene);if(t){let r=t.indexOf(e);r!=-1&&t.splice(r,1)}return e.lightData.castShadowIndex=-1,t}else if(e.lightData.lightType==Xe.PointLight||e.lightData.lightType==Xe.SpotLight){let t=this.pointLightList.get(e.transform.view3D.scene);if(t){let r=t.indexOf(e);r!=-1&&t.splice(r,1)}return e.lightData.castShadowIndex=-1,t}}static update(e){let t=this.shadowLights.get(e.scene),r=Tt.directionLightList.get(e.scene),i=Tt.pointLightList.get(e.scene),a=0,o=0,n=0,l=0;if(t.fill(0),r){let u=0;for(let c=0;c<r.length;c++){const f=r[c];t[c]=f.lightData.index,f.lightData.castShadowIndex=u++}o=r.length}if(i){n=o;let u=0;for(let c=n;c<i.length;c++){const f=i[c];t[c]=f.lightData.index,f.lightData.castShadowIndex=u++}l=n+i.length}ne.getAllCameraGroup().forEach(u=>{u.dirShadowStart=a,u.dirShadowEnd=o,u.pointShadowStart=n,u.pointShadowEnd=l,u.shadowLights.set(new Float32Array(t))})}}class yo{uuid;usage;globalBindGroup;uniformGPUBuffer;matrixBindGroup;uniformByteLength;matrixesByteLength;shadowMatrixRaw=new Float32Array(128);csmMatrixRaw=new Float32Array(Zt.Cascades*16);csmShadowBias=new Float32Array(4);shadowLights=new Float32Array(16);dirShadowStart=0;dirShadowEnd=0;pointShadowStart=0;pointShadowEnd=0;constructor(e){this.uuid=It(),this.usage=GPUBufferUsage.UNIFORM|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,this.uniformGPUBuffer=new ut(8336),this.uniformGPUBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.matrixBindGroup=e,this.createBindGroup()}createBindGroup(){this.uniformByteLength=this.uniformGPUBuffer.memory.shareDataBuffer.byteLength,this.matrixesByteLength=I.block*4*I.maxCount,this.globalBindGroup=Q.device.createBindGroup({label:"global_bindGroupLayout",layout:mo.getGlobalDataBindGroupLayout(),entries:[{binding:0,resource:{buffer:this.uniformGPUBuffer.buffer,offset:0,size:this.uniformByteLength}},{binding:1,resource:{buffer:this.matrixBindGroup.matrixBufferDst.buffer,offset:0,size:this.matrixesByteLength}}]})}setCamera(e){this.uniformGPUBuffer.setMatrix("_projectionMatrix",e.projectionMatrix),this.uniformGPUBuffer.setMatrix("_viewMatrix",e.viewMatrix),this.uniformGPUBuffer.setMatrix("_cameraWorldMatrix",e.transform.worldMatrix),this.uniformGPUBuffer.setMatrix("pvMatrixInv",e.projectionMatrixInv),this.uniformGPUBuffer.setMatrix("viewToWorld",e.cameraToWorld);let t=Tt.getDirectShadowLightWhichScene(e.transform.scene3D);this.csmShadowBias.fill(1e-4),this.shadowMatrixRaw.fill(0),this.csmMatrixRaw.fill(0);for(let l=0;l<8;l++)if(l<t.length){let h=t[l].shadowCamera;this.shadowMatrixRaw.set(h.pvMatrix.rawData,l*16)}else this.shadowMatrixRaw.set(e.transform.worldMatrix.rawData,l*16);this.uniformGPUBuffer.setFloat32Array("shadowMatrix",this.shadowMatrixRaw);let r=m.setting.shadow.shadowSize;if(Zt.Cascades>1&&e.enableCSM&&t[0])for(let l=0;l<Zt.Cascades;l++){let h=e.csm.children[l].shadowCamera;this.csmMatrixRaw.set(h.pvMatrix.rawData,l*16),this.csmShadowBias[l]=e.getCSMShadowBiasScale(h)}this.uniformGPUBuffer.setFloat32Array("csmShadowBias",this.csmShadowBias),this.uniformGPUBuffer.setFloat32Array("csmMatrix",this.csmMatrixRaw),this.uniformGPUBuffer.setFloat32Array("shadowLights",this.shadowLights);let i=m.setting.reflectionSetting,a=G.instance.getReflections(e.transform.scene3D).length;this.uniformGPUBuffer.setFloat("reflectionProbeSize",i.reflectionProbeSize),this.uniformGPUBuffer.setFloat("reflectionProbeMaxCount",i.reflectionProbeMaxCount),this.uniformGPUBuffer.setFloat("reflectionMapWidth",i.width),this.uniformGPUBuffer.setFloat("reflectionMapHeight",i.height),this.uniformGPUBuffer.setFloat("reflectionCount",a),this.uniformGPUBuffer.setFloat("test2",Ye.testObj.testValue2),this.uniformGPUBuffer.setFloat("test3",Ye.testObj.testValue3),this.uniformGPUBuffer.setFloat("test4",Ye.testObj.testValue4),this.uniformGPUBuffer.setVector3("CameraPos",e.transform.worldPosition),this.uniformGPUBuffer.setFloat("frame",Qe.frame),this.uniformGPUBuffer.setFloat32Array("SH",e.sh),this.uniformGPUBuffer.setFloat("time",Qe.time),this.uniformGPUBuffer.setFloat("delta",Qe.delta),this.uniformGPUBuffer.setFloat("shadowBias",e.getShadowBias(r)),this.uniformGPUBuffer.setFloat("skyExposure",m.setting.sky.skyExposure),this.uniformGPUBuffer.setFloat("renderPassState",m.setting.render.renderPassState),this.uniformGPUBuffer.setFloat("quadScale",m.setting.render.quadScale),this.uniformGPUBuffer.setFloat("hdrExposure",m.setting.render.hdrExposure),this.uniformGPUBuffer.setInt32("renderState_left",m.setting.render.renderState_left),this.uniformGPUBuffer.setInt32("renderState_right",m.setting.render.renderState_right),this.uniformGPUBuffer.setFloat("renderState_split",m.setting.render.renderState_split);let o=m.inputSystem.mouseX*Q.pixelRatio,n=m.inputSystem.mouseY*Q.pixelRatio;this.uniformGPUBuffer.setFloat("mouseX",o),this.uniformGPUBuffer.setFloat("mouseY",n),this.uniformGPUBuffer.setFloat("windowWidth",Q.windowWidth),this.uniformGPUBuffer.setFloat("windowHeight",Q.windowHeight),this.uniformGPUBuffer.setFloat("near",e.near),this.uniformGPUBuffer.setFloat("far",e.far),this.uniformGPUBuffer.setFloat("pointShadowBias",m.setting.shadow.pointShadowBias),this.uniformGPUBuffer.setFloat("shadowMapSize",r),this.uniformGPUBuffer.setFloat("shadowSoft",m.setting.shadow.shadowSoft),this.uniformGPUBuffer.setFloat("enableCSM",e.enableCSM?1:0),this.uniformGPUBuffer.setFloat("csmMargin",m.setting.shadow.csmMargin),this.uniformGPUBuffer.setInt32("nDirShadowStart",this.dirShadowStart),this.uniformGPUBuffer.setInt32("nDirShadowEnd",this.dirShadowEnd),this.uniformGPUBuffer.setInt32("nPointShadowStart",this.pointShadowStart),this.uniformGPUBuffer.setInt32("nPointShadowEnd",this.pointShadowEnd),this.uniformGPUBuffer.setVector3("cameraForward",e.transform.forward),this.uniformGPUBuffer.setVector4Array("frustumPlanes",e.frustum.planes),this.uniformGPUBuffer.apply()}setShadowCamera(e){this.uniformGPUBuffer.setMatrix("_projectionMatrix",e.projectionMatrix),this.uniformGPUBuffer.setMatrix("_viewMatrix",e.viewMatrix),this.uniformGPUBuffer.setMatrix("_pvMatrix",e.pvMatrix),this.uniformGPUBuffer.setMatrix("pvMatrixInv",e.projectionMatrixInv),this.uniformGPUBuffer.setMatrix("viewToWorld",e.cameraToWorld),this.csmShadowBias.fill(1e-4),this.shadowMatrixRaw.fill(0),this.csmMatrixRaw.fill(0),this.uniformGPUBuffer.setFloat32Array("shadowCamera",this.shadowMatrixRaw),this.uniformGPUBuffer.setFloat32Array("csmShadowBias",this.csmShadowBias),this.uniformGPUBuffer.setFloat32Array("csmMatrix",this.csmMatrixRaw),this.uniformGPUBuffer.setFloat32Array("shadowLights",this.shadowLights),this.uniformGPUBuffer.setVector3("CameraPos",e.transform.worldPosition),this.uniformGPUBuffer.setFloat("frame",Qe.frame),this.uniformGPUBuffer.setFloat32Array("SH",e.sh),this.uniformGPUBuffer.setFloat("time",Qe.time),this.uniformGPUBuffer.setFloat("delta",Qe.delta),this.uniformGPUBuffer.setFloat("shadowBias",m.setting.shadow.shadowBias),this.uniformGPUBuffer.setFloat("skyExposure",m.setting.sky.skyExposure),this.uniformGPUBuffer.setFloat("renderPassState",m.setting.render.renderPassState),this.uniformGPUBuffer.setFloat("quadScale",m.setting.render.quadScale),this.uniformGPUBuffer.setFloat("hdrExposure",m.setting.render.hdrExposure),this.uniformGPUBuffer.setInt32("renderState_left",m.setting.render.renderState_left),this.uniformGPUBuffer.setInt32("renderState_right",m.setting.render.renderState_right),this.uniformGPUBuffer.setFloat("renderState_split",m.setting.render.renderState_split);let t=m.inputSystem.mouseX*Q.pixelRatio,r=m.inputSystem.mouseY*Q.pixelRatio;this.uniformGPUBuffer.setFloat("mouseX",t),this.uniformGPUBuffer.setFloat("mouseY",r),this.uniformGPUBuffer.setFloat("windowWidth",Q.windowWidth),this.uniformGPUBuffer.setFloat("windowHeight",Q.windowHeight),this.uniformGPUBuffer.setFloat("near",e.near),this.uniformGPUBuffer.setFloat("far",e.far),this.uniformGPUBuffer.setFloat("pointShadowBias",m.setting.shadow.pointShadowBias),this.uniformGPUBuffer.setFloat("shadowMapSize",m.setting.shadow.shadowSize),this.uniformGPUBuffer.setFloat("shadowSoft",m.setting.shadow.shadowSoft),this.uniformGPUBuffer.setFloat("enableCSM",0),this.uniformGPUBuffer.setFloat("csmMargin",m.setting.shadow.csmMargin),this.uniformGPUBuffer.setInt32("nDirShadowStart",this.dirShadowStart),this.uniformGPUBuffer.setInt32("nDirShadowEnd",this.dirShadowEnd),this.uniformGPUBuffer.setInt32("nPointShadowStart",this.pointShadowStart),this.uniformGPUBuffer.setInt32("nPointShadowEnd",this.pointShadowEnd),this.uniformGPUBuffer.apply()}setShadowLight(){}}class Yh{setting;probesBufferData;probesBuffer;isVolumeFrameChange=!0;randomOrientation;startPosition=new d;isVolumeChange=!0;irradianceVolumeBuffer;directionDistance=20;randomSeedCount=3;useRandomIndex=0;centerDirection=new d(0,0,this.directionDistance).normalize(1);arroundPositions=[];updateOrientation(){return this.useRandomIndex++,this.useRandomIndex>=this.arroundPositions.length&&(this.useRandomIndex=0),I.fromToRotation(this.centerDirection,this.arroundPositions[this.useRandomIndex],this.randomOrientation),this.randomOrientation}init(e){this.setting=e,this.randomOrientation=new I(!1),this.randomOrientation.identity(),this.irradianceVolumeBuffer=new ut(80),this.createFramesBuffer(),this.arroundPositions.push(this.centerDirection.clone());for(let t=0;t<this.randomSeedCount;t++){let r=Math.PI*2*t/this.randomSeedCount,i=new d(Math.sin(r),Math.cos(r),this.directionDistance).normalize(1);this.arroundPositions.push(i)}}setVolumeDataChange(){this.isVolumeChange=!0}updateProbes(e){let t=this.probesBufferData;for(let r of e){let i=r.index*4;t[i+3]=r.drawCallFrame}}createFramesBuffer(){if(!this.probesBufferData){let e=this.setting.probeXCount*this.setting.probeYCount*this.setting.probeZCount;this.probesBufferData=new Float32Array(e*4),this.probesBufferData.fill(-1),this.probesBuffer=new Be(e*4,GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST)}}uploadBuffer(){this.isVolumeChange&&(this.fillIrradianceData(),this.isVolumeChange=!1,this.isVolumeFrameChange=!0),this.probesBuffer.setFloat32Array("uniformFramesBuffer",this.probesBufferData)}calcPosition(e,t,r,i){let a=this.setting,o=this.setting.probeSpace;return i=i||new d,i.x=e*o-o*(a.probeXCount-1)*.5+a.offsetX,i.y=t*o-o*(a.probeYCount-1)*.5+a.offsetY,i.z=r*o-o*(a.probeZCount-1)*.5+a.offsetZ,i}debugX=0;debugY=0;debugZ=0;fillIrradianceData(){let e=this.setting,t=this.calcPosition(0,0,0,this.startPosition);this.irradianceVolumeBuffer.setFloat("orientationIndex",this.randomOrientation.index),this.irradianceVolumeBuffer.setFloat("hysteresis",e.hysteresis),this.irradianceVolumeBuffer.setFloat("OctRTSideSize",e.octRTSideSize),this.irradianceVolumeBuffer.setFloat("OctRTMaxSize",e.octRTMaxSize),this.irradianceVolumeBuffer.setFloat("startX",t.x),this.irradianceVolumeBuffer.setFloat("startY",t.y),this.irradianceVolumeBuffer.setFloat("startZ",t.z),this.irradianceVolumeBuffer.setFloat("ProbeSpace",e.probeSpace),this.irradianceVolumeBuffer.setFloat("probeXCount",e.probeXCount),this.irradianceVolumeBuffer.setFloat("probeYCount",e.probeYCount),this.irradianceVolumeBuffer.setFloat("probeZCount",e.probeZCount),this.irradianceVolumeBuffer.setFloat("maxDistance",e.probeSpace*1.732),this.irradianceVolumeBuffer.setFloat("depthSharpness",e.depthSharpness),this.irradianceVolumeBuffer.setFloat("ProbeSourceTextureSize",e.probeSourceTextureSize),this.irradianceVolumeBuffer.setFloat("ProbeSize",e.probeSize),this.irradianceVolumeBuffer.setFloat("bounceIntensity",e.bounceIntensity),this.irradianceVolumeBuffer.setFloat("probeRoughness",e.probeRoughness),this.irradianceVolumeBuffer.setFloat("normalBias",e.normalBias),this.irradianceVolumeBuffer.setFloat("irradianceChebyshevBias",e.irradianceChebyshevBias),this.irradianceVolumeBuffer.setFloat("rayNumber",e.rayNumber),this.irradianceVolumeBuffer.setFloat("irradianceDistanceBias",e.irradianceDistanceBias),this.irradianceVolumeBuffer.setFloat("indirectIntensity",e.indirectIntensity),this.irradianceVolumeBuffer.setFloat("ddgiGamma",e.ddgiGamma),this.irradianceVolumeBuffer.setFloat("lerpHysteresis",e.lerpHysteresis),this.irradianceVolumeBuffer.setFloat("debugX",this.debugX),this.irradianceVolumeBuffer.setFloat("debugY",this.debugY),this.irradianceVolumeBuffer.setFloat("debugZ",this.debugZ),this.irradianceVolumeBuffer.apply()}}class Xh{storageGPUBuffer;irradianceVolume;_lightList=[];constructor(){this.storageGPUBuffer=new Be(fs.lightSize*m.setting.light.maxLight,GPUBufferUsage.COPY_SRC),this.irradianceVolume=new Yh,this.irradianceVolume.init(m.setting.gi);for(let e=0;e<m.setting.light.maxLight;e++){let t=this.storageGPUBuffer.memory.allocation_node(fs.lightSize*4);this._lightList.push(t)}this.storageGPUBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE}update(e){this.storageGPUBuffer.clean();let t=G.instance.getLights(e.scene);for(let r=0;r<t.length;r++){const i=t[r].lightData;i.index=r,this.writeLightBytes(i,this._lightList[r])}this.storageGPUBuffer.apply()}writeLightBytes(e,t){t.offset=0,t.writeFloat(e.index),t.writeInt32(e.lightType),t.writeFloat(e.radius),t.writeFloat(e.linear),t.writeVector3(e.lightPosition),t.writeFloat(e.lightMatrixIndex),t.writeVector3(e.direction),t.writeFloat(e.quadratic),t.writeRGBColor(e.lightColor),t.writeFloat(e.intensity),t.writeFloat(e.innerAngle),t.writeFloat(e.outerAngle),t.writeFloat(e.range),t.writeInt32(e.castShadowIndex),t.writeVector3(e.lightTangent),t.writeFloat(e.iesIndex)}}class Hh{storageGPUBuffer;reflectionMap;sourceReflectionMap;count;constructor(){this.storageGPUBuffer=new Be(768)}update(e){this.storageGPUBuffer.clean();let t=G.instance.getReflections(e.scene);for(let r=0;r<t.length;r++){const i=t[r];i.gid=r,this.storageGPUBuffer.setFloat("gid",i.gid),this.storageGPUBuffer.setVector3("worldPosition",i.transform.worldPosition),this.storageGPUBuffer.setFloat("radius",i.radius),this.storageGPUBuffer.setVector3("bound",i.transform.worldPosition)}this.count=t.length,this.storageGPUBuffer.apply()}}class jh extends Tr{size;constructor(e,t=0,r){super(),this.bufferType=tr.StorageGPUBuffer,this.size=e,this.createBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|t,e,r,"MatrixGPUBuffer")}writeBufferByHeap(e,t){let r;e instanceof Float64Array?r=new Float32Array(e):r=e;let i=Q.device;if(r.length>0){let a=null;for(;this.mapAsyncReady.length&&(a=this.mapAsyncReady.shift(),a.usedSize!=r.byteLength);)a.destroy(),this.mapAsyncBuffersOutstanding--,a=null;a||(a=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_SRC|GPUBufferUsage.MAP_WRITE,mappedAtCreation:!0}),a.usedSize=r.byteLength,this.mapAsyncBuffersOutstanding++,this.mapAsyncBuffersOutstanding>10&&console.warn(` Warning: mapAsync requests from ${this.mapAsyncBuffersOutstanding} frames ago have not resolved yet. MB of staging buffers allocated.`));let o=new Float32Array(r.buffer,r.byteOffset,t);new Float32Array(a.getMappedRange(0,t*4)).set(o),a.unmap();const l=i.createCommandEncoder();l.copyBufferToBuffer(a,0,this.buffer,0,t*4),i.queue.submit([l.finish()]),a.mapAsync(GPUMapMode.WRITE).then(()=>this.mapAsyncReady.push(a))}}}class Kh{uuid;index;usage;groupBufferSize;matrixBufferDst;constructor(){this.uuid=It(),this.groupBufferSize=0,this.usage=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,this.cacheWorldMatrix()}cacheWorldMatrix(){this.groupBufferSize=I.maxCount*I.blockBytes,this.matrixBufferDst=new jh(this.groupBufferSize/4),this.matrixBufferDst.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.matrixBufferDst.buffer.label=this.groupBufferSize.toString()}writeBuffer(e){const t=I.dynamicMatrixBytes;this.matrixBufferDst.mapAsyncWrite(t,e)}}class ne{static _cameraBindGroups;static _lightEntriesMap;static _reflectionEntriesMap;static modelMatrixBindGroup;static init(){this.modelMatrixBindGroup=new Kh,this._cameraBindGroups=new Map,this._lightEntriesMap=new Map,this._reflectionEntriesMap=new Map}static getAllCameraGroup(){return this._cameraBindGroups}static getCameraGroup(e){let t=this._cameraBindGroups.get(e);return t||(t=new yo(this.modelMatrixBindGroup),this._cameraBindGroups.set(e,t)),e.isShadowCamera?t.setShadowCamera(e):t.setCamera(e),t}static updateCameraGroup(e){let t=this._cameraBindGroups.get(e);t||(t=new yo(this.modelMatrixBindGroup),this._cameraBindGroups.set(e,t)),e.isShadowCamera?t.setShadowCamera(e):t.setCamera(e)}static getLightEntries(e){e||console.log("getLightEntries scene is null");let t=this._lightEntriesMap.get(e);return t||(t=new Xh,this._lightEntriesMap.set(e,t)),this._lightEntriesMap.get(e)}static getReflectionEntries(e){e||console.log("getLightEntries scene is null");let t=this._reflectionEntriesMap.get(e);return t||(t=new Hh,this._reflectionEntriesMap.set(e,t)),this._reflectionEntriesMap.get(e)}}class F{static lastGeometry;static lastPipeline;static lastShader;static drawCount=0;static renderPassCount=0;static geometryCount=0;static pipelineCount=0;static matrixCount=0;static lastRenderPassState;static LastCommand;static bindPipeline(e,t){if(F.lastShader!=t)F.lastShader=t;else return!1;F.lastPipeline!=t.pipeline&&(F.lastPipeline=t.pipeline,e.setPipeline(t.pipeline));for(let r=1;r<t.bindGroups.length;r++){const i=t.bindGroups[r];i&&e.setBindGroup(r,i)}return!0}static bindCamera(e,t){let r=ne.getCameraGroup(t);e.setBindGroup(0,r.globalBindGroup)}static bindGeometryBuffer(e,t){if(this.lastGeometry!=t&&(this.lastGeometry=t,t.indicesBuffer)){e.setIndexBuffer(t.indicesBuffer.indicesGPUBuffer.buffer,t.indicesBuffer.indicesFormat);let r=t.vertexBuffer.vertexGPUBuffer,i=t.vertexBuffer.vertexBufferLayouts;for(let a=0;a<i.length;a++){const o=i[a];e.setVertexBuffer(a,r.buffer,o.offset,o.size)}}}static cleanCache(){this.lastGeometry=null,this.lastPipeline=null,this.lastShader=null}static createPipeline(e){return Ye.countStart("GPUContext","pipeline"),Q.device.createRenderPipeline(e)}static beginCommandEncoder(){return Ye.countStart("GPUContext","beginCommandEncoder"),this.LastCommand&&Q.device.queue.submit([this.LastCommand.finish()]),this.LastCommand=Q.device.createCommandEncoder(),this.LastCommand}static endCommandEncoder(e){this.LastCommand==e&&(Q.device.queue.submit([this.LastCommand.finish()]),this.LastCommand=null,Ye.countStart("GPUContext","endCommandEncoder"))}static recordBundleEncoder(e){return Q.device.createRenderBundleEncoder(e)}static beginRenderPass(e,t){if(this.cleanCache(),this.renderPassCount++,this.lastRenderPassState=t,t.depthTexture){let r=t.renderPassDescriptor.depthStencilAttachment;r.view=t.depthTexture.getGPUView()}if(t.renderTargets&&t.renderTargets.length>0){for(let r=0;r<t.renderTargets.length;++r){const i=t.renderTargets[r];let a=t.renderPassDescriptor.colorAttachments[r];t.multisample>0&&t.renderTargets.length==1?(a.view=t.multiTexture.createView(),a.resolveTarget=i.getGPUView()):a.view=i.getGPUTexture().createView()}return e.beginRenderPass(t.renderPassDescriptor)}else{let r=t.renderPassDescriptor.colorAttachments[0];return r&&(t.multisample>0?(r.view=t.multiTexture.createView(),r.resolveTarget=Q.context.getCurrentTexture().createView()):r.view=Q.context.getCurrentTexture().createView()),e.beginRenderPass(t.renderPassDescriptor)}}static drawIndexed(e,t,r,i,a,o){e.drawIndexed(t,r,i,a,o),this.drawCount++}static draw(e,t,r,i,a){e.draw(t,r,i,a),this.drawCount++}static endPass(e){e.insertDebugMarker("end"),e.end()}static computeCommand(e,t){let r=e.beginComputePass();for(let i=0;i<t.length;i++)t[i].compute(r);r.end()}static copyTexture(e,t,r){e.copyTextureToTexture({texture:t.getGPUTexture(),mipLevel:0,origin:{x:0,y:0,z:0}},{texture:r.getGPUTexture(),mipLevel:0,origin:{x:0,y:0,z:0}},{width:r.width,height:r.height,depthOrArrayLayers:1})}}class qh{source;input;output;reset(e){this.input&&this.input.destroy(),this.output&&this.output.destroy(),this.input=this.output=null,this.source=e}apply(e){if(this.source){if(!this.input){let t=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST;this.input=new Be(this.source.length,t,this.source),this.input.apply()}if(!this.output){let t=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC;this.output=new Be(e*3,t),this.output.apply()}}}}class $h{enable;morphTargetsRelative;MaxMorphTargetCount=64;_computeConfigArray;_computeConfigBuffer;_morphInfluenceArray;_morphInfluenceBuffer;_positionAttrDataGroup;_normalAttrDataGroup;_isInfluenceDirty;_morphTargetCount;_totalVertexCount;_computeShader;_computeShaders;_computeWorkGroupXY=1;_collectMorphTargetData;_blendTarget;constructor(){this._isInfluenceDirty=!0,this.generateGPUBuffer(),this._positionAttrDataGroup=new qh,this._normalAttrDataGroup=new qh}initMorphTarget(e){this._collectMorphTargetData=this.collectMorphTargetList(e),this._computeShader&&this._computeShader.destroy();let t=kt.CsMain;this._computeShader=new ue(t),this._collectMorphTargetData.mergedNormal?this._computeShader.setDefine("USE_MORPHNORMALS",!0):this._computeShader.deleteDefine("USE_MORPHNORMALS"),this._computeShaders=[this._computeShader],this._isInfluenceDirty=!0,this._morphTargetCount=this._collectMorphTargetData.mtCount,this._totalVertexCount=this._collectMorphTargetData.vCount,this._morphInfluenceArray.fill(0),this._computeWorkGroupXY=this.calcWorkGroup(this._totalVertexCount),this._positionAttrDataGroup.reset(this._collectMorphTargetData.mergedPos),this._normalAttrDataGroup.reset(this._collectMorphTargetData.mergedNormal)}applyRenderShader(e){this.uploadMorphTargetBuffer(),this.uploadConfigGBuffer(),e.setUniformBuffer("morphTargetConfig",this._computeConfigBuffer),e.setStorageBuffer("morphTargetOpPositions",this._positionAttrDataGroup.output),this._collectMorphTargetData.mergedNormal&&e.setStorageBuffer("morphTargetOpNormals",this._normalAttrDataGroup.output)}computeMorphTarget(e){this.uploadConfigGBuffer(),this.uploadMorphTargetBuffer(),this._computeShader.setUniformBuffer("morphTargetConfig",this._computeConfigBuffer),this._computeShader.setStorageBuffer("morphTargetInfluence",this._morphInfluenceBuffer),this._computeShader.setStorageBuffer("morphTargetPositions",this._positionAttrDataGroup.input),this._computeShader.setStorageBuffer("morphTargetOpPositions",this._positionAttrDataGroup.output),this._collectMorphTargetData.mergedNormal&&(this._computeShader.setStorageBuffer("morphTargetNormals",this._normalAttrDataGroup.input),this._computeShader.setStorageBuffer("morphTargetOpNormals",this._normalAttrDataGroup.output)),this._computeShader.workerSizeX=this._computeWorkGroupXY,this._computeShader.workerSizeY=this._computeWorkGroupXY,this._computeShader.workerSizeZ=1,F.computeCommand(e,this._computeShaders)}updateInfluence(e,t){this._isInfluenceDirty=!0,this._morphInfluenceArray[e]=t}get blendShape(){return this._blendTarget}collectMorphTargetList(e){let t=this.collectAttribute("a_morphPositions_",e),r=t.length,i=t[0].data.length/3;if(this._blendTarget={},e.blendShapeData)for(let l=0;l<e.blendShapeData.shapeIndexs.length;l++){let h=e.blendShapeData.shapeIndexs[l],u=e.blendShapeData.shapeNames[l].split("."),c=u[u.length-1];this._blendTarget[c]=f=>this.updateInfluence(h,f)}let a=new Float32Array(i*r*3);{let l=0;for(let h=0;h<r;h++){let u=t[h];a.set(u.data,l),l+=u.data.length}}let o=this.collectAttribute("a_morphNormals_",e),n;if(o&&o.length>0){let l=0;n=new Float32Array(i*r*3);for(let h=0;h<r;h++){let u=o[h];n.set(u.data,l),l+=u.data.length}}return{mtCount:r,vCount:i,mergedPos:a,mergedNormal:n}}collectAttribute(e,t){let r=[];for(let i=0;i<this.MaxMorphTargetCount;i++){let a=e+i,o=t.getAttribute(a);if(o)r[i]=o;else break}return r}uploadConfigGBuffer(){if(this._isInfluenceDirty){let e=0;for(let t=0;t<this._morphTargetCount;t++)e+=this._morphInfluenceArray[t];this._morphInfluenceBuffer.setFloat32Array("data",this._morphInfluenceArray),this._morphInfluenceBuffer.apply(),this._computeConfigArray[0]=this.morphTargetsRelative?1:1-e,this._computeConfigArray[1]=this._morphTargetCount,this._computeConfigArray[2]=this._totalVertexCount,this._computeConfigArray[3]=this._computeWorkGroupXY,this._computeConfigBuffer.setFloat32Array("data",this._computeConfigArray),this._computeConfigBuffer.apply(),this._isInfluenceDirty=!1}}calcWorkGroup(e){let t=Math.ceil(Math.sqrt(e)),r=Math.ceil(Math.log2(t));return t=Math.pow(2,r),t}uploadMorphTargetBuffer(){this._positionAttrDataGroup.output||this._positionAttrDataGroup.apply(this._totalVertexCount),this._normalAttrDataGroup.output||this._normalAttrDataGroup.apply(this._totalVertexCount)}generateGPUBuffer(){this._computeConfigArray=new Float32Array(4),this._computeConfigBuffer=new ut(4),this._morphInfluenceArray=new Float32Array(this.MaxMorphTargetCount);let e=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST;this._morphInfluenceBuffer=new Be(this.MaxMorphTargetCount,e)}destroy(e){this._computeConfigBuffer&&(this._computeConfigBuffer.destroy(e),this._computeConfigBuffer=null),this._morphInfluenceBuffer&&(this._morphInfluenceBuffer.destroy(e),this._morphInfluenceBuffer=null),this._computeShader&&(this._computeShader.destroy(e),this._computeShader=null),this._positionAttrDataGroup&&(this._positionAttrDataGroup.input&&this._positionAttrDataGroup.input.destroy(e),this._positionAttrDataGroup.output&&this._positionAttrDataGroup.output.destroy(e),this._positionAttrDataGroup=null),this._normalAttrDataGroup&&(this._normalAttrDataGroup.input&&this._normalAttrDataGroup.input.destroy(e),this._normalAttrDataGroup.output&&this._normalAttrDataGroup.output.destroy(e),this._normalAttrDataGroup=null),this._computeConfigArray=null,this._morphInfluenceArray=null,this._collectMorphTargetData=null,this._blendTarget=null,this._computeShaders=null}}var Kg=Object.defineProperty,qg=Object.getOwnPropertyDescriptor,bo=(s,e,t,r)=>{for(var i=r>1?void 0:r?qg(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&Kg(e,t,i),i};let K=class extends Nr{receiveShadow;morphData;constructor(){super()}onEnable(){super.onEnable()}onDisable(){super.onDisable()}cloneTo(s){s.addComponent(K).copyComponent(this)}copyComponent(s){return super.copyComponent(s),this.receiveShadow=s.receiveShadow,this}get geometry(){return this._geometry}set geometry(s){if(super.geometry=s,s){let e=s.morphTargetDictionary!=null;e&&(this.morphData||=new $h,this.morphData.morphTargetsRelative=s.morphTargetsRelative,this.morphData.initMorphTarget(s)),this.morphData&&(this.morphData.enable=e),this.morphData?.enable?this.addRendererMask(ve.MorphTarget):this.removeRendererMask(ve.MorphTarget),this.object3D.bound=this._geometry.bounds.clone()}else this.morphData&&(this.morphData.enable=!1),this.removeRendererMask(ve.MorphTarget);this._readyPipeline||(this.initPipeline(),this._computes&&(this.onCompute=ls(this.onCompute,()=>{for(let e=0;e<this._computes.length;e++)this._computes[e].onUpdate()})))}get material(){return this._materials[0]}set material(s){this.materials=[s]}setMorphInfluence(s,e){if(this.morphData&&this.morphData.enable){let t=this._geometry.morphTargetDictionary[s];t>=0&&this.morphData.updateInfluence(t,e)}}setMorphInfluenceIndex(s,e){this.morphData&&this.morphData.enable&&s>=0&&this.morphData.updateInfluence(s,e)}onCompute(s,e){this.morphData&&this.morphData.enable&&this.morphData.computeMorphTarget(e)}nodeUpdate(s,e,t,r){if(this.morphData&&this.morphData.enable)for(let i=0;i<this.materials.length;i++){let o=this.materials[i].getPass(e);if(o)for(let n=0;n<o.length;n++)this.morphData.applyRenderShader(o[n])}super.nodeUpdate(s,e,t,r)}destroy(s){this.morphData&&(this.morphData.destroy(s),this.morphData=null),super.destroy(s)}};bo([Oi],K.prototype,"geometry",1),bo([Oi],K.prototype,"material",1),K=bo([Pt(K,"MeshRenderer")],K);class Sr{static compressGBufferTex_NAME="compressGBufferTex_NAME";static colorBufferTex_NAME="colorBufferTex";static positionBufferTex_NAME="positionBufferTex";static normalBufferTex_NAME="normalBufferTex";static materialBufferTex_NAME="materialBufferTex";static zBufferTexture_NAME="zBufferTexture";static zPreDepthTexture_NAME="zPreDepthTexture";static outTex_NAME="outTex"}class eu{label="";customSize=!1;zPreTexture=null;depthTexture=null;renderTargetTextures;outColor=-1;renderTargets;rtTextureDescriptors;irradianceBuffer;multisample=0;multiTexture;depthViewIndex=0;depthCleanValue=0;isOutTarget=!0;camera3D;rtFrame;renderPassDescriptor;renderBundleEncoderDescriptor;depthLoadOp;getLastRenderTexture(){return this.renderTargets&&this.renderTargets.length>0?this.renderTargets[0]:m.res.redTexture}}class Ut extends je{resolveTarget;sampleCount;autoResize;clear;constructor(e,t,r=X.rgba8unorm,i=!1,a,o=1,n=0,l=!0,h=!0){super(e,t,o),this.name=It(),this.autoResize=h,this.useMipmap=i,this.sampleCount=n,this.format=r,this.numberLayer=o,this.clear=l,a!=null?this.usage=a:this.usage=a|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.COPY_DST,this.resize(e,t),this.autoResize&&Q.addEventListener(Hr.RESIZE,u=>{let{width:c,height:f}=u.data;this.resize(c,f),this._textureChange=!0},this)}resize(e,t){let r=Q.device;this.gpuTexture&&(je.delayDestroyTexture(this.gpuTexture),this.gpuTexture=null,this.view=null),this.width=e,this.height=t,this.createTextureDescriptor(e,t,1,this.format,this.usage,this.numberLayer,this.sampleCount),this.useMipmap=!1,this.visibility=GPUShaderStage.COMPUTE|GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,this.format==X.rgba32float?(this.samplerBindingLayout.type="non-filtering",this.textureBindingLayout.sampleType="unfilterable-float",this.gpuSampler=r.createSampler({})):this.format==X.depth32float?(this.samplerBindingLayout.type="filtering",this.sampler_comparisonBindingLayout.type="comparison",this.textureBindingLayout.sampleType="depth",this.gpuSampler=Q.device.createSampler({}),this.gpuSampler_comparison=Q.device.createSampler({compare:"less",label:"sampler_comparison"})):this.format==X.depth24plus?(this.samplerBindingLayout={type:"filtering"},this.sampler_comparisonBindingLayout={type:"comparison"},this.textureBindingLayout.sampleType="depth",this.gpuSampler=Q.device.createSampler({}),this.gpuSampler_comparison=Q.device.createSampler({compare:"less",label:"sampler_comparison"})):(this.samplerBindingLayout.type="filtering",this.textureBindingLayout.sampleType="float",this.sampleCount>0&&(this.textureBindingLayout.multisampled=!0),this.minFilter="linear",this.magFilter="linear",this.mipmapFilter="linear",this.addressModeU=Lt.clamp_to_edge,this.addressModeV=Lt.clamp_to_edge,this.gpuSampler=r.createSampler(this)),this._textureChange=!0}create(e,t,r=!0){let i=Q.device;const a=e*4;let o=new Float32Array(e*t*4);const n=i.createBuffer({size:o.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(n,0,o);const l=F.beginCommandEncoder();l.copyBufferToTexture({buffer:n,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),F.endCommandEncoder(l)}clone(){let e=new Ut(this.width,this.height,this.format,this.useMipmap,this.usage,this.numberLayer,this.sampleCount,this.clear,this.autoResize);return e.name="clone_"+e.name,e}readTextureToImage(){let e=Q.device,t=Q.windowWidth,r=Q.windowHeight,i=new Float32Array(t*r*4);const a=e.createBuffer({size:i.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});return F.beginCommandEncoder().copyTextureToBuffer({texture:this.getGPUTexture()},{buffer:a},[t,r]),a.getMappedRange(0,i.byteLength)}}class Re{storeOp="store";loadOp="clear";clearValue=[0,0,0,0]}class Ze{label;customSize=!1;renderTargets;rtDescriptors;zPreTexture;depthTexture;depthViewIndex=0;depthCleanValue=1;depthLoadOp="clear";isOutTarget=!0;constructor(e,t,r,i,a=!0){this.renderTargets=e,this.rtDescriptors=t,this.depthTexture=r,this.zPreTexture=i,this.isOutTarget=a}clone2Frame(e){e.renderTargets.push(...this.renderTargets.concat());for(let t=0;t<this.rtDescriptors.length;t++){const r=this.rtDescriptors[t];let i=new Re;i.loadOp=r.loadOp,i.storeOp=r.storeOp,i.clearValue=r.clearValue,e.rtDescriptors.push(i)}e.depthTexture=this.depthTexture,e.zPreTexture=this.zPreTexture,e.customSize=this.customSize}clone(){let e=new Ze([],[]);return this.clone2Frame(e),e}}class se extends Ze{static colorPass_GBuffer="ColorPassGBuffer";static reflections_GBuffer="reflections_GBuffer";static gui_GBuffer="gui_GBuffer";static gBufferMap=new Map;_colorBufferTex;_compressGBufferTex;constructor(){super([],[])}createGBuffer(e,t,r,i=!0,a=!0,o){let n=this.renderTargets,l=this.rtDescriptors;if(a){let u=new Re;u.loadOp="clear",this._colorBufferTex=Ct.createRTTexture(e+Sr.colorBufferTex_NAME,t,r,X.rgba16float,!0),n.push(this._colorBufferTex),l.push(u)}this._compressGBufferTex=new Ut(t,r,X.rgba32float,!1,void 0,1,0,!0,!0),n.push(this._compressGBufferTex),o?this.depthTexture=o:(this.depthTexture=new Ut(t,r,X.depth24plus,!1,void 0,1,0,!0,!0),this.depthTexture.name=e+"_depthTexture");let h;h=new Re,l.push(h)}getPositionMap(){return this.renderTargets[1]}getNormalMap(){return this.renderTargets[2]}getColorTexture(){return this._colorBufferTex}getCompressGBufferTexture(){return this._compressGBufferTex}static getGBufferFrame(e,t=0,r=0,i=!0,a){let o;if(se.gBufferMap.has(e))o=se.gBufferMap.get(e);else{o=new se;let n=Q.presentationSize;o.createGBuffer(e,t==0?n[0]:t,r==0?n[1]:r,t!=0&&r!=0,i,a),se.gBufferMap.set(e,o)}return o}static getGUIBufferFrame(){let e=this.getGBufferFrame(this.colorPass_GBuffer);return se.getGBufferFrame(se.gui_GBuffer,0,0,!0,e.depthTexture)}clone(){let e=new se;return this.clone2Frame(e),e}}class De{static rendererPassState=new Map;static createRendererPassState(e,t=null){let r=De.rendererPassState.get(e);if(r||(r=new eu,r.label=e.label,r.customSize=e.customSize,r.rtFrame=e,r.zPreTexture=e.zPreTexture,r.depthTexture=e.depthTexture,r.depthViewIndex=e.depthViewIndex,r.isOutTarget=e.isOutTarget,r.depthCleanValue=e.depthCleanValue,r.depthLoadOp=e.depthLoadOp,De.rendererPassState.set(e,r)),e&&e.renderTargets.length>0){r.renderTargets=e.renderTargets,r.rtTextureDescriptors=e.rtDescriptors,r.renderPassDescriptor=De.getRenderPassDescriptor(r),r.renderPassDescriptor.depthStencilAttachment&&(r.renderPassDescriptor.depthStencilAttachment.depthLoadOp=e.depthLoadOp),t=="load"&&e?.renderTargets[0]&&e.renderTargets[0].name.startsWith(se.gui_GBuffer)&&(r.renderPassDescriptor.colorAttachments[0].loadOp="load"),r.depthLoadOp=e.depthLoadOp,r.renderBundleEncoderDescriptor=De.getRenderBundleDescriptor(r),r.renderTargetTextures=[];for(let i=0;i<e.renderTargets.length;i++){const a=e.renderTargets[i];r.renderTargetTextures[i]={format:a.format},a.name.indexOf(Sr.colorBufferTex_NAME)!=-1&&(r.outColor=i)}}else r.renderPassDescriptor=De.getRenderPassDescriptor(r,t),r.renderBundleEncoderDescriptor=De.getRenderBundleDescriptor(r),r.renderTargetTextures=[{format:Q.presentationFormat}],r.outColor=0;return r}static getRenderPassDescriptor(e,t=null){if(e.renderPassDescriptor)return e.renderPassDescriptor;Q.device,Q.presentationSize;let r=[];if(e.renderTargets&&e.renderTargets.length>0){e.renderTargets[0].width,e.renderTargets[0].height;for(let a=0;a<e.renderTargets.length;a++){const o=e.renderTargets[a],n=e.rtTextureDescriptors[a];r.push({view:o.getGPUView(),resolveTarget:void 0,loadOp:n.loadOp,clearValue:n.clearValue,storeOp:n.storeOp})}}else if(!e.customSize){let a=Q.canvasConfig&&Q.canvasConfig.alpha?[1,1,1,0]:[0,0,0,1];e.isOutTarget==!0&&r.push({view:void 0,resolveTarget:void 0,loadOp:Q.canvasConfig&&Q.canvasConfig.alpha||t!=null?"load":"clear",clearValue:a,storeOp:"store"})}let i=null;return e.depthTexture||e.zPreTexture?(e.zPreTexture&&(e.depthTexture=e.zPreTexture),i={label:`${e.label} renderPassDescriptor zPreTexture${e.zPreTexture?"load":"clear"}`,colorAttachments:r,depthStencilAttachment:{view:e.depthTexture.getGPUView(),depthLoadOp:e.zPreTexture?"load":e.depthLoadOp,depthClearValue:e.zPreTexture?1:e.depthCleanValue,depthStoreOp:"store"}}):i={colorAttachments:r,label:"renderPassDescriptor not writeDepth"},e.renderPassDescriptor=i,i}static getRenderBundleDescriptor(e){if(e.renderBundleEncoderDescriptor)return e.renderBundleEncoderDescriptor;Q.presentationSize;let t=[];if(e.renderTargets&&e.renderTargets.length>0){e.renderTargets[0].width,e.renderTargets[0].height;for(let i=0;i<e.renderTargets.length;i++){const a=e.renderTargets[i];t.push(a.format)}}let r=null;return e.depthTexture?r={colorFormats:t,depthStencilFormat:e.depthTexture.format}:r={colorFormats:t},e.renderBundleEncoderDescriptor=r,e.renderBundleEncoderDescriptor}}class Xi extends Ie{width;height;segmentW;segmentH;up;constructor(e,t,r=1,i=1,a=d.Y_AXIS){super(),this.width=e,this.height=t,this.segmentW=r,this.segmentH=i,this.up=a,this.buildGeometry(this.up)}buildGeometry(e){var t,r,i,a,o=this.segmentW+1;(this.segmentH+1)*o,this.bounds=new Fe(d.ZERO.clone(),new d(this.width,1,this.height)),i=this.segmentH*this.segmentW*6;let n=(this.segmentW+1)*(this.segmentH+1),l=new Float32Array(n*3),h=new Float32Array(n*3),u=new Float32Array(n*2),c;this.segmentW*this.segmentH*2*3>=Uint16Array.length?c=new Uint32Array(this.segmentW*this.segmentH*2*3):c=new Uint16Array(this.segmentW*this.segmentH*2*3),i=0;for(var g=0,p=0,A=0,U=0;U<=this.segmentH;++U)for(var x=0;x<=this.segmentW;++x){switch(t=(x/this.segmentW-.5)*this.width,r=(U/this.segmentH-.5)*this.height,e){case d.Y_AXIS:l[g++]=t,l[g++]=0,l[g++]=r,h[p++]=0,h[p++]=1,h[p++]=0;break;case d.Z_AXIS:l[g++]=t,l[g++]=-r,l[g++]=0,h[p++]=0,h[p++]=0,h[p++]=1;break;case d.X_AXIS:l[g++]=0,l[g++]=t,l[g++]=r,h[p++]=1,h[p++]=0,h[p++]=0;break;default:l[g++]=t,l[g++]=0,l[g++]=r,h[p++]=0,h[p++]=1,h[p++]=0;break}u[A++]=x/this.segmentW,u[A++]=U/this.segmentH,x!=this.segmentW&&U!=this.segmentH&&(a=x+U*o,c[i++]=a+1,c[i++]=a,c[i++]=a+o,c[i++]=a+1,c[i++]=a+o,c[i++]=a+o+1)}this.setIndices(c),this.setAttribute(V.position,l),this.setAttribute(V.normal,h),this.setAttribute(V.uv,u),this.setAttribute(V.TEXCOORD_1,u),this.addSubGeometry({indexStart:0,indexCount:c.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0})}}var $g=Object.getOwnPropertyDescriptor,ep=(s,e,t,r)=>{for(var i=r>1?void 0:r?$g(e,t):e,a=s.length-1,o;a>=0;a--)(o=s[a])&&(i=o(i)||i);return i};let pa=class extends ot{constructor(s="QuadGlsl_vs",e="QuadGlsl_fs"){super();let t=new Pe(s,e);this.addRenderPass(t);let r=t.shaderState;t.blendMode=ae.NONE,r.frontFace="cw",r.depthWriteEnabled=!1,r.depthCompare=et.always,r.multisample=0,this.setTexture("baseMap",m.res.blackTexture),this.setUniformFloat("x",0),this.setUniformFloat("y",0),this.setUniformFloat("width",100),this.setUniformFloat("height",100)}};pa=ep([wr(pa,"QuadShader")],pa);class Qo extends q{width=128;height=128;quadRenderer;material;rendererPassState;quadShader;constructor(e="QuadGlsl_vs",t="QuadGlsl_fs",r,i=0,a=!1){super();let o=r?r.renderTargets:[];this.material=new At,this.quadShader=new pa(e,t),this.material.shader=this.quadShader,this.quadRenderer=this.addComponent(K),this.quadRenderer.material=this.material,this.quadRenderer.castGI=!1,this.quadRenderer.castShadow=!1,this.quadRenderer.drawType=a?2:0,this.quadRenderer.geometry=new Xi(100,100,1,1),this.quadRenderer.material=this.material,this.quadRenderer.__start(),this.quadRenderer._enable=!0,this.quadRenderer.onEnable(),this.rendererPassState=De.createRendererPassState(r,"load"),i>0&&(this.rendererPassState.multisample=this.quadShader.getDefaultColorShader().shaderState.multisample,this.rendererPassState.multiTexture=Q.device.createTexture({size:{width:Q.presentationSize[0],height:Q.presentationSize[1]},sampleCount:i,format:o.length>0?o[0].format:Q.presentationFormat,usage:GPUTextureUsage.RENDER_ATTACHMENT})),Q.addEventListener(Hr.RESIZE,n=>{this.rendererPassState=De.createRendererPassState(r,"load"),i>0&&(this.rendererPassState.multisample=this.quadShader.getDefaultColorShader().shaderState.multisample,this.rendererPassState.multiTexture=Q.device.createTexture({size:{width:Q.presentationSize[0],height:Q.presentationSize[1]},sampleCount:i,format:o.length>0?o[0].format:Q.presentationFormat,usage:GPUTextureUsage.RENDER_ATTACHMENT}))},this)}renderTarget(e,t,r){let i=e.camera,a=F.beginRenderPass(r,t.rendererPassState);F.bindCamera(a,i),t.quadRenderer.nodeUpdate(e,H.COLOR,t.rendererPassState,null),t.quadRenderer.renderPass2(e,H.COLOR,t.rendererPassState,null,a),F.endPass(a)}renderToViewQuad(e,t,r,i){let a=e.camera;t.quadShader.setTexture("baseMap",i);let o=F.beginRenderPass(r,t.rendererPassState);F.bindCamera(o,a),t.quadRenderer.nodeUpdate(e,H.COLOR,t.rendererPassState,null),t.quadRenderer.renderPass2(e,H.COLOR,t.rendererPassState,null,o),F.endPass(o)}}class Ct{static rtTextureMap;static rtViewQuad;static init(){this.rtTextureMap=new Map,this.rtViewQuad=new Map}static createRTTexture(e,t,r,i,a=!1,o=0){let n=this.rtTextureMap.get(e);return n||(e==Sr.colorBufferTex_NAME?n=new Ut(t,r,i,a,void 0,1,o,!1):n=new Ut(t,r,i,a,void 0,1,o,!0),n.name=e,Ct.rtTextureMap.set(e,n)),n}static createRTTextureArray(e,t,r,i,a=1,o=!1,n=0){let l=this.rtTextureMap.get(e);return l||(l=new Ut(t,r,i,o,void 0,a,n),l.name=e,Ct.rtTextureMap.set(e,l)),l}static createViewQuad(e,t,r,i,a=0){let o=new Ze([i],[new Re]),n=new Qo(t,r,o,a);return Ct.rtViewQuad.set(e,n),n}static getTexture(e){return this.rtTextureMap.get(e)}static CreateSplitTexture(e){let t=this.getTexture(Sr.colorBufferTex_NAME),r=this.getTexture(e+"_split");return r||(r=this.createRTTexture(e+"_split",t.width,t.height,t.format,!1)),r}static WriteSplitColorTexture(e){let t=this.getTexture(Sr.colorBufferTex_NAME),r=this.getTexture(e+"_split");const i=F.beginCommandEncoder();i.copyTextureToTexture({texture:t.getGPUTexture(),mipLevel:0,origin:{x:0,y:0,z:0}},{texture:r.getGPUTexture(),mipLevel:0,origin:{x:0,y:0,z:0}},{width:r.width,height:r.height,depthOrArrayLayers:1}),F.endCommandEncoder(i)}}class Ro{command;encoder;rendererPassStates;rtFrame;constructor(e){this.rtFrame=e,this.rendererPassStates=[]}clean(){this.rendererPassStates.length=0,F.cleanCache()}beginContinueRendererPassState(e="load",t="load"){if(this.rendererPassStates.length>0){let r=this.rtFrame.clone();for(const a of r.rtDescriptors)a.loadOp="load";r.depthLoadOp=t;let i=De.createRendererPassState(r,e);return this.rendererPassStates.push(i),i}else{this.rtFrame.depthLoadOp=t;let r=De.createRendererPassState(this.rtFrame,e);return this.rendererPassStates.push(r),r}}get rendererPassState(){return this.rendererPassStates[this.rendererPassStates.length-1]}beginOpaqueRenderPass(){this.beginContinueRendererPassState("clear","clear"),this.begineNewCommand(),this.beginNewEncoder()}beginTransparentRenderPass(){this.beginContinueRendererPassState("load","load"),this.begineNewCommand(),this.beginNewEncoder()}specialtRenderPass(){this.beginContinueRendererPassState("load","load"),this.begineNewCommand(),this.beginNewEncoder()}endRenderPass(){this.endEncoder(),this.endCommand()}begineNewCommand(){return this.command=F.beginCommandEncoder(),this.command}endCommand(){F.endCommandEncoder(this.command),this.command=null}beginNewEncoder(){return this.encoder=F.beginRenderPass(this.command,this.rendererPassState),this.encoder}endEncoder(){F.endPass(this.encoder),this.encoder=null}}class _r extends Er{rendererPassState;splitRendererPassState;useRenderBundle=!1;debugViewQuads;debugTextures;renderContext;_rendererType;_rtFrame;get passType(){return this._rendererType}set passType(e){this._rendererType=e}constructor(){super(),this.debugTextures=[],this.debugViewQuads=[]}setRenderStates(e){if(this._rtFrame=e,e){this.rendererPassState=De.createRendererPassState(e);let t=e.clone();t.depthLoadOp="load";for(const r of t.rtDescriptors)r.loadOp="load";this.splitRendererPassState=De.createRendererPassState(t)}this.renderContext=new Ro(e)}getRenderContext(e){return this._rtFrame=e,new Ro(e)}setIrradiance(e,t){this.rendererPassState.irradianceBuffer=[e,t]}compute(e,t){}render(e,t,r,i=!1){F.cleanCache();let a=e.camera,o=e.scene;this.rendererPassState.camera3D=a;let n=G.instance.getRenderNodes(o,a),l=this.renderBundleOp(e,n,t,r),h=i?[]:this.renderBundleTr(e,n,t,r);{let u=F.beginCommandEncoder(),c=F.beginRenderPass(u,this.rendererPassState);l.length>0&&c.executeBundles(l),!i&&G.instance.sky&&(F.bindCamera(c,a),G.instance.sky.renderPass2(e,this._rendererType,this.rendererPassState,r,c)),this.drawRenderNodes(e,c,u,n.opaqueList,t),F.endPass(c),F.endCommandEncoder(u)}{let u=F.beginCommandEncoder(),c=F.beginRenderPass(u,this.rendererPassState);h.length>0&&c.executeBundles(h),i||(F.bindCamera(c,a),this.drawRenderNodes(e,c,u,n.transparentList,t)),F.endPass(c),F.endCommandEncoder(u)}}nodeUpload(e,t,r){}occlusionRenderNodeTest(e,t,r){return r?r.occlusionRenderNodeTest(e)>0:!0}renderOp(e,t,r,i,a){}renderTr(e,t,r,i,a){}renderBundleOp(e,t,r,i){let a=G.instance.getOpRenderGroup(e.scene);if(a){let o=[];return a.renderGroup.forEach(n=>{if(n.bundleMap.has(this._rendererType))o.push(n.bundleMap.get(this._rendererType));else{let l=F.recordBundleEncoder(this.rendererPassState.renderBundleEncoderDescriptor);this.recordRenderBundleNode(e,l,n.renderNodes,i);let h=l.finish();n.bundleMap.set(this._rendererType,h),o.push(h)}}),o}return[]}renderBundleTr(e,t,r,i){let a=G.instance.getTrRenderGroup(e.scene);if(a){let o=[];return a.renderGroup.forEach(n=>{if(n.bundleMap.has(this._rendererType))o.push(n.bundleMap.get(this._rendererType));else{let l=F.recordBundleEncoder(this.rendererPassState.renderBundleEncoderDescriptor);this.recordRenderBundleNode(e,l,n.renderNodes,i);let h=l.finish();n.bundleMap.set(this._rendererType,h),o.push(h)}}),o}return[]}recordRenderBundleNode(e,t,r,i){F.bindCamera(t,e.camera),F.bindGeometryBuffer(t,r[0].geometry);for(let a=0;a<r.length;++a){let o=r[a];o.transform.worldMatrix.index,o.transform.enable&&o.recordRenderPass2(e,this._rendererType,this.rendererPassState,i,t)}}drawRenderNodes(e,t,r,i,a,o){F.bindCamera(t,e.camera);for(let n=m.setting.render.drawOpMin;n<Math.min(i.length,m.setting.render.drawOpMax);++n){let l=i[n];l.transform.enable&&l.enable&&l.renderPass2(e,this._rendererType,this.rendererPassState,o,t)}}}class tu extends _r{constructor(){super(),this.passType=H.COLOR}render(e,t,r,i=!1){this.renderContext.clean();let a=e.scene,o=e.camera;ne.updateCameraGroup(o),this.rendererPassState.camera3D=o;let n=G.instance.getRenderNodes(a,o),l=this.renderBundleOp(e,n,t,r),h=i?[]:this.renderBundleTr(e,n,t,r);{this.renderContext.beginOpaqueRenderPass();let u=this.renderContext.encoder;l.length>0&&(G.instance.getOpRenderGroup(a),u.executeBundles(l)),!i&&G.instance.sky&&(F.bindCamera(u,o),G.instance.sky.preInit(this._rendererType)||G.instance.sky.nodeUpdate(e,this._rendererType,this.rendererPassState,r),G.instance.sky.renderPass2(e,this._rendererType,this.rendererPassState,r,u)),n.opaqueList&&(F.bindCamera(u,o),this.drawNodes(e,this.renderContext,n.opaqueList,t,r))}{let u=this.renderContext.encoder;h.length>0&&u.executeBundles(h),!i&&n.transparentList&&(F.bindCamera(u,o),this.drawNodes(e,this.renderContext,n.transparentList,t,r));let c=G.instance.getGraphicList();for(let f=0;f<c.length;f++){const g=c[f];g.nodeUpdate(e,this._rendererType,this.splitRendererPassState,r),g.renderPass2(e,this._rendererType,this.splitRendererPassState,r,u)}this.renderContext.endRenderPass(),Ye.end("ColorPass Draw Transparent")}}drawNodes(e,t,r,i,a){let o=G.instance.getRenderShaderCollect(e);if(o){for(const n of o){let l=n[1];for(const h of l){let u=h[1];if(!u.isDestroyed&&u.preInit(this._rendererType)){u.nodeUpdate(e,this._rendererType,this.rendererPassState,a);break}}}for(let n=m.setting.render.drawOpMin;n<Math.min(r.length,m.setting.render.drawOpMax);++n){let l=r[n];l.transform.enable&&l.enable&&(l.hasMask(ve.UI)&&!l.isRecievePostEffectUI||l.isDestroyed||(l.preInit(this._rendererType)||l.nodeUpdate(e,this._rendererType,this.rendererPassState,a),l.renderPass(e,this.passType,this.renderContext)))}}}occlusionRenderNodeTest(e,t,r){return r.zDepthRenderNodeTest(t)>0}}class Io{frustumCullingList;zVisibleList;_renderList;static enable=!0;constructor(){this._renderList=new Map}occlusionRenderNodeTest(e){return m.setting.occlusionQuery.enable?this.frustumCullingList?this.frustumCullingList[e]:0:1}zDepthRenderNodeTest(e){return this.zVisibleList?this.zVisibleList[e]:0}update(e,t){}collect(e,t){}renderCommitTesting(e,t){return!0}}class Hi extends Tr{constructor(e,t){super(),this.bufferType=tr.ComputeGPUBuffer,this.createBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST,e,t,"ComputeGPUBuffer")}}class ru{clusterBuffer;lightAssignBuffer;assignTableBuffer;clustersUniformBuffer;constructor(e,t){this.clusterBuffer=new Hi(e*2*4),this.clustersUniformBuffer=new ut(10),this.clustersUniformBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.lightAssignBuffer=new Hi(e*t),this.lightAssignBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.assignTableBuffer=new Hi(e*4),this.assignTableBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE}update(e,t,r,i,a,o,n,l,h,u){this.clustersUniformBuffer.setFloat("clusterTileX",i),this.clustersUniformBuffer.setFloat("clusterTileY",a),this.clustersUniformBuffer.setFloat("clusterTileZ",o),this.clustersUniformBuffer.setFloat("numLights",n),this.clustersUniformBuffer.setFloat("maxNumLightsPerCluster",l),this.clustersUniformBuffer.setFloat("near",h),this.clustersUniformBuffer.setFloat("far",u),this.clustersUniformBuffer.setFloat("screenWidth",e),this.clustersUniformBuffer.setFloat("screenHeight",t),this.clustersUniformBuffer.setFloat("clusterPix",r),this.clustersUniformBuffer.apply()}}class gt{static clusterTileX=16;static clusterTileY=16;static clusterTileZ=32}let iu=`
6022
5996
  #include "GlobalUniform"
6023
5997
 
6024
5998
  struct ClusterBox{
@@ -7754,7 +7728,7 @@ $1\r
7754
7728
  `;class mc{compute;constructor(){this.compute=new ue(pc)}generateBRDFLUTTexture(){let e=new Ae(256,256,X.rgba8unorm,!1,GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING);this.compute.setStorageTexture("brdflutTexture",e),this.compute.workerSizeX=256/8,this.compute.workerSizeY=256/8;let t=F.beginCommandEncoder();return F.computeCommand(t,[this.compute]),F.endCommandEncoder(t),e}}class Ki{id;guiTexture;uvRec=new $(0,0,1,1);uvBorder=new $(0,0,0,0);offsetSize=new $(0,0,4,4);borderSize=new $(0,0,0,0);trimSize=new j;isSliced=!1;height=4;width=4;xadvance=0;xoffset=0;yoffset=0;constructor(e){this.guiTexture=e||m.res.defaultGUITexture}}class di{static _maxUid=-1;_staticId=-1;dynamicId=-1;texture;width=1;height=1;get staticId(){return this._staticId}constructor(e){e||=m.res.whiteTexture,e.addressModeU="clamp-to-edge",e.addressModeV="clamp-to-edge",this.texture=e,di._maxUid++,this._staticId=di._maxUid,this.init()}init(){this.dynamicId=-1,this.width=this.texture.width,this.height=this.texture.height}}class Qp{fntCache={};fntData={};addFontData(e,t,r){this.fntData[`${e}${t}`]=r}getFontData(e,t){return this.fntData[`${e}${t}`]}addFnt(e,t,r,i){let a=`${e}${t}`;this.fntCache[a]||(this.fntCache[a]={}),this.fntCache[a][r]=i}getFnt(e,t,r){let i=`${e}${t}`,a=this.fntCache[i];return a?a[r]:this.fntCache[" "]}}let qi=new Qp;class Ac{face="";size=0;bold=!1;italic=!1;stretchH=0;spacing="";outline=0;lineHeight=0;base=0;scaleW=0;scaleH=0;pages=0;packed=0;alphaChnl=0;redChnl=0;greenChnl=0;blueChnl=0;count=0;fontPage=[];fontChar={};constructor(){}}class Uc{id=0;file=""}class xc{id=-1;x=0;y=0;width=0;height=0;xoffset=0;yoffset=0;xadvance=0;page=0;chnl=0}class zr extends st{static format=Ge.TEXT;static parseSprite(e,t){for(const r in t.fontChar)if(Object.prototype.hasOwnProperty.call(t.fontChar,r)){const i=t.fontChar[r];let a=new Ki;a.id=i.id.toString(),a.offsetSize.set(0,0,i.width,i.height),a.trimSize.set(i.width,i.height),a.width=i.width,a.height=i.height,a.xadvance=i.xadvance,a.xoffset=i.xoffset,a.yoffset=i.yoffset,a.guiTexture=e[i.page],a.uvRec.set(i.x/t.scaleW,(t.scaleH-(i.y+i.height))/t.scaleH,i.width/t.scaleW,i.height/t.scaleH),qi.addFnt(t.face,t.size,a.id,a)}}verification(){if(this.data)return!0;throw new Error("Method not implemented.")}async parseString(e){let t=this.getNewLine(e),r=e,i=new Ac;r.trim().split(t).forEach((a,o)=>{if(o<2)zr.readLineProperty(a,i);else if(o<i.pages+2){let n=new Uc;zr.readLineProperty(a,n),i.fontPage.push(n)}else if(o<i.pages+3)zr.readLineProperty(a,i);else if(i.count>0){let n=new xc;zr.readLineProperty(a,n),i.fontChar[n.id]=n,i.count--}}),r="",this.data=i,await this.loadFontTextures()}getNewLine(e){return e.indexOf(`\r
7755
7729
  `)!=-1?`\r
7756
7730
  `:e.indexOf("\r")!=-1?"\r":`
7757
- `}async loadFontTextures(){let e=[],t=this.data;for(const r of t.fontPage){let i=this.baseUrl+r.file;await m.res.loadTexture(i,null,!0);let a=m.res.getTexture(i),o=new di(a);e.push(o)}zr.parseSprite(e,t),t.fontChar[" "]||zr.insertSpaceChar(t,e[0])}static insertSpaceChar(e,t){let r=new Ki,i=e.size*.5,a=e.lineHeight*.5;r.id=" ",r.offsetSize.set(0,0,e.size,e.size),r.trimSize.set(i,a),r.width=i,r.height=a,r.xadvance=0,r.xoffset=0,r.yoffset=0,r.guiTexture=t,r.uvRec.set(0,0,1e-6,1e-6),qi.addFnt(e.face,e.size,r.id,r)}static readLineProperty(e,t){e.trim().split(" ").forEach((r,i)=>{let a=r.split("=");if(a.length>1){let o=a[0],n=a[1];Object.prototype.hasOwnProperty.call(t,o)&&(n.indexOf('"')==-1?t[o]=parseFloat(a[1]):t[o]=n.replace('"',"").replace('"',""))}})}}function Rp(s,e){let t=new Ki;return t.id=s,t.offsetSize.set(0,0,e.width,e.height),t.trimSize.set(e.width,e.height),t.width=e.width,t.height=e.height,t.xadvance=0,t.xoffset=0,t.yoffset=0,t.guiTexture=new di(e),t.uvRec.set(0,0,1,1),e.isVideoTexture||(e.flipY=!0),t}function vc(s,e,t){let r=new Ki;r.guiTexture=s,r.id=e,r.uvRec.copyFrom(t.textureRect),r.trimSize.x=t.textureRect.z,r.trimSize.y=t.textureRect.w,r.offsetSize.x=t.textureRectOffset.x,r.offsetSize.y=t.textureRectOffset.y,r.offsetSize.z=t.size.x,r.offsetSize.w=t.size.y,r.width=t.size.x,r.height=t.size.y;let i=1/s.width,a=1/s.height;r.uvRec.set(r.uvRec.x*i,r.uvRec.y*a,r.uvRec.z*i,r.uvRec.w*a);let o=.1;return t.border.x<=o&&t.border.y<=o&&t.border.z<=o&&t.border.x<=o?r.isSliced=!1:(r.borderSize.copyFrom(t.border),r.uvBorder.copyFrom(t.border),r.uvBorder.x-=t.textureRectOffset.x,r.uvBorder.y-=t.textureRectOffset.y,r.uvBorder.z=t.border.z-(t.size.x-t.textureRect.z-t.textureRectOffset.x),r.uvBorder.w=t.border.w-(t.size.y-t.textureRect.w-t.textureRectOffset.y),r.uvBorder.x/=t.textureRect.z,r.uvBorder.z/=t.textureRect.z,r.uvBorder.y/=t.textureRect.w,r.uvBorder.w/=t.textureRect.w,r.isSliced=!0),r}class Bc{_spriteMap=new Map;_spriteList=[];textureSize=new j;name;constructor(e){this.textureSize.set(e.x,e.y)}setTexture(e,t,r){let i=vc(e,t,r);return this._spriteMap.set(i.id,i),this._spriteList.push(i),i}getSprite(e){return this._spriteMap.get(e)}get spriteList(){return this._spriteList}}class Cc extends st{static format=Ge.TEXT;_json;_texture;async parseString(e){this._json=JSON.parse(e);let t=this.userData.replace(".json",".png");this._texture=await m.res.loadTexture(t,null,!0),this.data={json:this._json,texture:this._texture},this.parseAtlas()}verification(){if(this.data)return!0;throw new Error("verify failed.")}parseAtlas(){let e=new Bc(this._json.size),t=new di(this._texture),r=this._json.atlas;for(const i in r)e.setTexture(t,i,r[i]);m.res.addAtlas(this.baseUrl,e),this.data=e}}var Ot=Uint8Array,$i=Uint16Array,Ip=Int32Array,Sc=new Ot([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),_c=new Ot([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ep=new Ot([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Fc=function(s,e){for(var t=new $i(31),r=0;r<31;++r)t[r]=e+=1<<s[r-1];for(var i=new Ip(t[30]),r=1;r<30;++r)for(var a=t[r];a<t[r+1];++a)i[a]=a-t[r]<<5|r;return{b:t,r:i}},yc=Fc(Sc,2),bc=yc.b,wp=yc.r;bc[28]=258,wp[258]=28;for(var Tp=Fc(_c,0),Dp=Tp.b,an=new $i(32768),Me=0;Me<32768;++Me){var ii=(Me&43690)>>1|(Me&21845)<<1;ii=(ii&52428)>>2|(ii&13107)<<2,ii=(ii&61680)>>4|(ii&3855)<<4,an[Me]=((ii&65280)>>8|(ii&255)<<8)>>1}for(var Ca=(function(s,e,t){for(var r=s.length,i=0,a=new $i(e);i<r;++i)s[i]&&++a[s[i]-1];var o=new $i(e);for(i=1;i<e;++i)o[i]=o[i-1]+a[i-1]<<1;var n;if(t){n=new $i(1<<e);var l=15-e;for(i=0;i<r;++i)if(s[i])for(var h=i<<4|s[i],u=e-s[i],c=o[s[i]-1]++<<u,f=c|(1<<u)-1;c<=f;++c)n[an[c]>>l]=h}else for(n=new $i(r),i=0;i<r;++i)s[i]&&(n[i]=an[o[s[i]-1]++]>>15-s[i]);return n}),Sa=new Ot(288),Me=0;Me<144;++Me)Sa[Me]=8;for(var Me=144;Me<256;++Me)Sa[Me]=9;for(var Me=256;Me<280;++Me)Sa[Me]=7;for(var Me=280;Me<288;++Me)Sa[Me]=8;for(var Qc=new Ot(32),Me=0;Me<32;++Me)Qc[Me]=5;var Mp=Ca(Sa,9,1),Np=Ca(Qc,5,1),sn=function(s){for(var e=s[0],t=1;t<s.length;++t)s[t]>e&&(e=s[t]);return e},sr=function(s,e,t){var r=e/8|0;return(s[r]|s[r+1]<<8)>>(e&7)&t},on=function(s,e){var t=e/8|0;return(s[t]|s[t+1]<<8|s[t+2]<<16)>>(e&7)},Vp=function(s){return(s+7)/8|0},nn=function(s,e,t){return(e==null||e<0)&&(e=0),(t==null||t>s.length)&&(t=s.length),new Ot(s.subarray(e,t))},Pp=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Ht=function(s,e,t){var r=new Error(e||Pp[s]);if(r.code=s,Error.captureStackTrace&&Error.captureStackTrace(r,Ht),!t)throw r;return r},kp=function(s,e,t,r){var i=s.length,a=r?r.length:0;if(!i||e.f&&!e.l)return t||new Ot(0);var o=!t,n=o||e.i!=2,l=e.i;o&&(t=new Ot(i*3));var h=function(Qt){var Rt=t.length;if(Qt>Rt){var Vt=new Ot(Math.max(Rt*2,Qt));Vt.set(t),t=Vt}},u=e.f||0,c=e.p||0,f=e.b||0,g=e.l,p=e.d,A=e.m,U=e.n,x=i*8;do{if(!g){u=sr(s,c,1);var v=sr(s,c+1,3);if(c+=3,v)if(v==1)g=Mp,p=Np,A=9,U=5;else if(v==2){var y=sr(s,c,31)+257,b=sr(s,c+10,15)+4,w=y+sr(s,c+5,31)+1;c+=14;for(var R=new Ot(w),E=new Ot(19),N=0;N<b;++N)E[Ep[N]]=sr(s,c+N*3,7);c+=b*3;for(var z=sn(E),Y=(1<<z)-1,ee=Ca(E,z,1),N=0;N<w;){var oe=ee[sr(s,c,Y)];c+=oe&15;var S=oe>>4;if(S<16)R[N++]=S;else{var te=0,ge=0;for(S==16?(ge=3+sr(s,c,3),c+=2,te=R[N-1]):S==17?(ge=3+sr(s,c,7),c+=3):S==18&&(ge=11+sr(s,c,127),c+=7);ge--;)R[N++]=te}}var Ce=R.subarray(0,y),J=R.subarray(y);A=sn(Ce),U=sn(J),g=Ca(Ce,A,1),p=Ca(J,U,1)}else Ht(1);else{var S=Vp(c)+4,C=s[S-4]|s[S-3]<<8,_=S+C;if(_>i){l&&Ht(0);break}n&&h(f+C),t.set(s.subarray(S,_),f),e.b=f+=C,e.p=c=_*8,e.f=u;continue}if(c>x){l&&Ht(0);break}}n&&h(f+131072);for(var ce=(1<<A)-1,he=(1<<U)-1,Ue=c;;Ue=c){var te=g[on(s,c)&ce],xe=te>>4;if(c+=te&15,c>x){l&&Ht(0);break}if(te||Ht(2),xe<256)t[f++]=xe;else if(xe==256){Ue=c,g=null;break}else{var Ve=xe-254;if(xe>264){var N=xe-257,Ee=Sc[N];Ve=sr(s,c,(1<<Ee)-1)+bc[N],c+=Ee}var ye=p[on(s,c)&he],Ne=ye>>4;ye||Ht(3),c+=ye&15;var J=Dp[Ne];if(Ne>3){var Ee=_c[Ne];J+=on(s,c)&(1<<Ee)-1,c+=Ee}if(c>x){l&&Ht(0);break}n&&h(f+131072);var lt=f+Ve;if(f<J){var pr=a-J,Nt=Math.min(J,lt);for(pr+f<0&&Ht(3);f<Nt;++f)t[f]=r[pr+f]}for(;f<lt;++f)t[f]=t[f-J]}}e.l=g,e.p=Ue,e.b=f,e.f=u,g&&(u=1,e.m=A,e.d=p,e.n=U)}while(!u);return f!=t.length&&o?nn(t,0,f):t.subarray(0,f)},Lp=new Ot(0),Fr=function(s,e){return s[e]|s[e+1]<<8},or=function(s,e){return(s[e]|s[e+1]<<8|s[e+2]<<16|s[e+3]<<24)>>>0},ln=function(s,e){return or(s,e)+or(s,e+4)*4294967296};function Op(s,e){return kp(s,{i:2},e&&e.out,e&&e.dictionary)}var hn=typeof TextDecoder<"u"&&new TextDecoder,zp=0;try{hn.decode(Lp,{stream:!0}),zp=1}catch{}var Gp=function(s){for(var e="",t=0;;){var r=s[t++],i=(r>127)+(r>223)+(r>239);if(t+i>s.length)return{s:e,r:nn(s,t-1)};i?i==3?(r=((r&15)<<18|(s[t++]&63)<<12|(s[t++]&63)<<6|s[t++]&63)-65536,e+=String.fromCharCode(55296|r>>10,56320|r&1023)):i&1?e+=String.fromCharCode((r&31)<<6|s[t++]&63):e+=String.fromCharCode((r&15)<<12|(s[t++]&63)<<6|s[t++]&63):e+=String.fromCharCode(r)}};function Rc(s,e){if(e){for(var t="",r=0;r<s.length;r+=16384)t+=String.fromCharCode.apply(null,s.subarray(r,r+16384));return t}else{if(hn)return hn.decode(s);var i=Gp(s),a=i.s,t=i.r;return t.length&&Ht(8),a}}var Wp=function(s,e){return e+30+Fr(s,e+26)+Fr(s,e+28)},Jp=function(s,e,t){var r=Fr(s,e+28),i=Rc(s.subarray(e+46,e+46+r),!(Fr(s,e+8)&2048)),a=e+46+r,o=or(s,e+20),n=t&&o==4294967295?Zp(s,a):[o,or(s,e+24),or(s,e+42)],l=n[0],h=n[1],u=n[2];return[Fr(s,e+10),l,h,i,a+Fr(s,e+30)+Fr(s,e+32),u]},Zp=function(s,e){for(;Fr(s,e)!=1;e+=4+Fr(s,e+2));return[ln(s,e+12),ln(s,e+4),ln(s,e+20)]};function Yp(s,e){for(var t={},r=s.length-22;or(s,r)!=101010256;--r)(!r||s.length-r>65558)&&Ht(13);var i=Fr(s,r+8);if(!i)return{};var a=or(s,r+16),o=a==4294967295||i==65535;if(o){var n=or(s,r-12);o=or(s,n)==101075792,o&&(i=or(s,n+32),a=or(s,n+48))}for(var l=0;l<i;++l){var h=Jp(s,a,o),u=h[0],c=h[1],f=h[2],g=h[3],p=h[4],A=h[5],U=Wp(s,A);a=p,u?u==8?t[g]=Op(s.subarray(U,U+c),{out:new Ot(f)}):Ht(14,"unknown compression type "+u):t[g]=nn(s,U,U+c)}return t}class mt extends At{constructor(){super(),this.shader=new Da,this.baseMap=m.res.whiteTexture}set baseMap(e){this.shader.setTexture("baseMap",e)}get baseMap(){return this.shader.getTexture("baseMap")}set baseColor(e){this.shader.setUniformColor("baseColor",e)}get baseColor(){return this.shader.getUniformColor("baseColor")}set envMap(e){}set shadowMap(e){}}class Qi extends Ie{shape_vertices=[];shape_indices=[];radius;widthSegments;heightSegments;phiStart;phiLength;thetaStart;thetaLength;constructor(e,t,r,i,a,o,n){super(),this.radius=e,this.widthSegments=t,this.heightSegments=r,this.phiStart=i,this.phiLength=a,this.thetaStart=o,this.thetaLength=n,this.buildGeometry()}buildGeometry(){var e,t,r=0;let i=this.heightSegments,a=this.widthSegments,o=this.radius;var n=(i+1)*(a+1);let l=new Float32Array(n*3),h=new Float32Array(n*3),u=new Float32Array(n*2),c=new Uint16Array(a*i*2*3),f=0,g=0,p=0;for(t=0;t<=i;++t){var A=Math.PI*t/i,U=o*Math.cos(A),x=o*Math.sin(A);for(e=0;e<=a;++e){var v=2*Math.PI*e/a,S=x*Math.cos(v),C=x*Math.sin(v),_=1/Math.sqrt(S*S+U*U+C*C);if(l[f++]=S,l[f++]=U,l[f++]=C,h[g++]=S*_,h[g++]=U*_,h[g++]=C*_,u[p++]=e/a,u[p++]=t/i,e>0&&t>0){var y=(a+1)*t+e,b=(a+1)*t+e-1,w=(a+1)*(t-1)+e-1,R=(a+1)*(t-1)+e;t==i?(c[r++]=y,c[r++]=w,c[r++]=R):t==1?(c[r++]=y,c[r++]=b,c[r++]=w):(c[r++]=y,c[r++]=b,c[r++]=w,c[r++]=y,c[r++]=w,c[r++]=R)}}}this.setIndices(c),this.setAttribute(V.position,l),this.setAttribute(V.normal,h),this.setAttribute(V.uv,u),this.setAttribute(V.TEXCOORD_1,u),this.addSubGeometry({indexStart:0,indexCount:c.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0}),this.bounds=new Fe(d.ZERO,new d(this.radius*2,this.radius*2,this.radius*2))}}class rs extends q{static register3DRepresentation=null;positionIndex=-1;positionValid=!1;marker;constructor(e){super(),this.parsePlacemark(e),this.setup3DRepresentation()}parsePlacemark(e){if(!e.slamPositionInfo){console.warn("WayPoint3D: slamPositionInfo is not found");return}const t=e.slamPositionInfo.slamPosition.split(",").map(Number);this.localPosition=new d(t[0],t[1],t[2]),this.positionIndex=Number(e.slamPositionInfo.slamPositionIndex),this.positionValid=e.slamPositionInfo.slamPositionValid==="1"}setup3DRepresentation(){if(this.marker&&(this.removeChild(this.marker),this.marker=null),rs.register3DRepresentation)this.marker=rs.register3DRepresentation(this),this.marker&&this.addChild(this.marker);else{this.marker=new q;const e=this.marker.addComponent(K);e.geometry=new Qi(.1,32,16),e.material=new mt,e.material.baseColor=this.positionValid?new P(0,1,0,1):new P(1,0,0,1),this.addChild(this.marker),this.marker.name="WayPoint3DMarker"}}}class is extends q{static register3DRepresentation=null;line;constructor(e){super(),this.parseWayLineFile(e),this.setup3DRepresentation()}parseWayLineFile(e){for(const t of e.Folder.Placemark){const r=new rs(t);this.addChild(r)}this.entityChildren=this.entityChildren.sort((t,r)=>t.positionIndex-r.positionIndex)}setup3DRepresentation(){this.line&&(this.removeChild(this.line),this.line=null),is.register3DRepresentation?(this.line=is.register3DRepresentation(this),this.line&&this.addChild(this.line)):(this.line=this.createMultiLine(this.entityChildren.map(e=>e.localPosition),new P(1,1,1,1)),this.addChild(this.line),this.line.name="WayLines3DLine")}createMultiLine(e,t){if(e.length<2)return null;const r=new Ie,i=new Float32Array(e.length*3);for(let h=0;h<e.length;h++)i[h*3]=e[h].x,i[h*3+1]=e[h].y,i[h*3+2]=e[h].z;const a=new Uint16Array((e.length-1)*2);for(let h=0;h<e.length-1;h++)a[h*2]=h,a[h*2+1]=h+1;r.setIndices(a),r.setAttribute(V.position,i),r.addSubGeometry({indexStart:0,indexCount:a.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0});const o=new q,n=o.addComponent(K),l=new mt;return l.topology="line-list",l.baseColor=t,l.blendMode=ae.ADD,l.castReflection=!1,n.geometry=r,n.material=l,o}}class Ic extends st{static format=Ge.BIN;parseBuffer(e){try{const t={template:null,waylines:null},r=Yp(new Uint8Array(e));for(const a in r){const o=r[a],l=new DOMParser().parseFromString(Rc(o),"application/xml"),h={};this.parseNode(l,h);const u=a.replace("wpmz/","").split(".")[0];Object.assign(t,{[u]:h["#document"].kml.Document})}const i=new is(t.waylines);this.data=i}catch(t){this.parserError(`KMZ parsing failed: ${t}`,-1)}}parseNode(e,t){const r=["Placemark","actionGroup","action"],i=e.nodeName.replace("wpml:","");if(!e.childNodes.length)t[i]=void 0;else{let a=null,o=!1;for(let n=0;n<e.childNodes.length;++n){const l=e.childNodes[n];if(l.nodeType==Node.TEXT_NODE){const h=l.nodeValue?.trim();h&&h.length>0&&(a=h)}else l.nodeType==Node.ELEMENT_NODE&&(o=!0)}if(a&&!o)t[i]=a;else if(o){r.includes(i)?t[i]?.length?t[i].push({}):t[i]=[{}]:t[i]={};for(let n=0;n<e.childNodes.length;++n){const l=e.childNodes[n];l.nodeType==Node.ELEMENT_NODE&&this.parseNode(l,Array.isArray(t[i])?t[i].at(-1):t[i])}}else t[i]=void 0}}verification(){if(this.data)return!0;throw new Error("verify failed.")}}class Ec{_texturePool;_materialPool;_prefabPool;_gltfPool;_geometryPool;_atlasList;_obj;constructor(){this._texturePool=new Map,this._materialPool=new Map,this._prefabPool=new Map,this._geometryPool=new Map,this._gltfPool=new Map,this._atlasList=new Map,this._obj=new Map}getGltf(e){return this._gltfPool.get(e)}addObj(e,t){this._obj.set(e,t)}getObj(e){return this._obj.get(e)}addTexture(e,t){this._texturePool.set(e,t)}getTexture(e){return this._texturePool.get(e)}addGeometry(e,t){this._geometryPool.set(e,t)}getGeometry(e){return this._geometryPool.get(e)}addMat(e,t){return this._materialPool.set(e,t)}getMat(e){return this._materialPool.get(e)}addPrefab(e,t){this._prefabPool.set(e,t)}getPrefab(e){return this._prefabPool.get(e).instantiate()}addAtlas(e,t){t.name=e,this._atlasList.set(e,t)}getAtlas(e){return this._atlasList.get(e)}getGUISprite(e){for(let t of this._atlasList.values()){let r=t.getSprite(e);if(r)return r}return null}async load(e,t,r){return(await new pt().load(e,t,r)).data}async loadGltf(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let r,i=e.substring(e.lastIndexOf(".")).toLowerCase(),a=new pt;i==".gltf"?r=await a.load(e,xt,t):r=await a.load(e,Zo,t);let o=r.data;return this._prefabPool.set(e,o),this._gltfPool.set(e,r.gltf),o}async loadObj(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let r,i=e.substring(e.lastIndexOf(".")).toLowerCase(),a=new pt;i==".obj"&&(r=await a.load(e,ju,t));let o=r.data;return this._prefabPool.set(e,o),o}async loadB3DM(e,t,r){if(this._prefabPool.has(e))return this._prefabPool.get(e);let o=(await new pt().load(e,lc,t,r)).data;return this._prefabPool.set(e,o),o}async loadI3DM(e,t,r){if(this._prefabPool.has(e))return this._prefabPool.get(e);let o=(await new pt().load(e,gc,t,r)).data;return this._prefabPool.set(e,o),o}async loadTexture(e,t,r){if(this._texturePool.has(e))return this._texturePool.get(e);let i=new Vr;return i.flipY=r,await i.load(e,t),this._texturePool.set(e,i),i}async loadTextureCount(e,t,r,i){return new Promise(async(a,o)=>{let n=0,l=[];t==0&&a(l);for(let h=0;h<t;h++){const u=e.shift();this.loadTexture(u,r,i).then(c=>{l.push(c),n++,n==t&&a(l)})}})}async loadBitmapTextures(e,t=5,r,i){let a=[],o=Math.floor(e.length/t)+1,n=Math.floor(e.length%t);for(let l=0;l<o;l++){let h=await this.loadTextureCount(e,l==o-1?n:t,r,i);a.push(...h)}return a}async loadHDRTexture(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new Ho;return r=await r.load(e,t),this._texturePool.set(e,r),r}async loadHDRTextureCube(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new xs;return r=await r.load(e,t),this._texturePool.set(e,r),r}async loadLDRTextureCube(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new Bs;return r=await r.load(e,t),this._texturePool.set(e,r),r}async loadTextureCubeMaps(e){let t=e[0];if(this._texturePool.has(t))return this._texturePool.get(t);let r=new Yo;return await r.load(e),this._texturePool.set(e[0],r),r}async loadTextureCubeStd(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new Yo;return await r.loadStd(e),r}async loadJSON(e,t){return await new pt().loadJson(e,t).then(async r=>r).catch(r=>{console.log(r)})}async loadFont(e,t,r){let a=await new pt().load(e,zr,t,r),o=a.data;return qi.addFontData(o.face,o.size,o),a.data}async loadAtlas(e,t){return(await new pt().load(e,Cc,t,e)).data}async loadKMZ(e,t){return(await new pt().load(e,Ic,t)).data}normalTexture;maskTexture;whiteTexture;blackTexture;redTexture;blueTexture;greenTexture;yellowTexture;grayTexture;defaultSky;defaultGUITexture;defaultGUISprite;defaultMaterial;createTexture(e,t,r,i,a,o,n){let l=32,h=32,u=new Uint8Array(l*h*4);this.fillColor(u,e,t,r,i,a,o);let c=new So;return c.name=n,c.create(16,16,u,!0),n&&this.addTexture(n,c),c}fillColor(e,t,r,i,a,o,n){for(let l=0;l<t;l++)for(let h=0;h<r;h++){let u=h*t+l;e[u*4+0]=i,e[u*4+1]=a,e[u*4+2]=o,e[u*4+3]=n}}initDefault(){this.normalTexture=this.createTexture(32,32,255*.5,255*.5,255,255,"default-normalTexture"),this.maskTexture=this.createTexture(32,32,255,255*.5,255,255,"default-maskTexture"),this.whiteTexture=this.createTexture(32,32,255,255,255,255,"default-whiteTexture"),this.blackTexture=this.createTexture(32,32,0,0,0,255,"default-blackTexture"),this.redTexture=this.createTexture(32,32,255,0,0,255,"default-redTexture"),this.blueTexture=this.createTexture(32,32,0,0,255,255,"default-blueTexture"),this.greenTexture=this.createTexture(32,32,0,255,0,255,"default-greenTexture"),this.yellowTexture=this.createTexture(32,32,0,255,255,255,"default-yellowTexture"),this.grayTexture=this.createTexture(32,32,128,128,128,255,"default-grayTexture");let t=new mc().generateBRDFLUTTexture(),r=t.name="BRDFLUT";this.addTexture(r,t),this.defaultSky=new xs,this.defaultSky.createFromTexture(128,this.blackTexture),me.getInstance().attached(this.defaultSky,this),me.getInstance().attached(t,this),me.getInstance().attached(this.normalTexture,this),me.getInstance().attached(this.maskTexture,this),me.getInstance().attached(this.whiteTexture,this),me.getInstance().attached(this.blackTexture,this),me.getInstance().attached(this.redTexture,this),me.getInstance().attached(this.blueTexture,this),me.getInstance().attached(this.greenTexture,this),me.getInstance().attached(this.yellowTexture,this),me.getInstance().attached(this.grayTexture,this),this.defaultGUITexture=new di(this.whiteTexture),this.defaultGUISprite=new Ki(this.defaultGUITexture),this.defaultGUISprite.trimSize.set(4,4),this.defaultMaterial=new Qr}}class wc extends ke{_postList;init(e){this._postList=new Map}start(){}stop(){}onEnable(){this.activePost()}onDisable(){this.unActivePost()}activePost(){let e=this.transform.view3D,t=m.getRenderJob(e);this._postList.forEach(r=>{t.addPost(r)})}unActivePost(){let e=this.transform.view3D,t=m.getRenderJob(e);this._postList.forEach(r=>{t.removePost(r)})}addPost(e){if(this._postList.has(e))return;let t=new e;return this._postList.set(e,t),this._enable&&this.activePost(),t}removePost(e){if(!this._postList.has(e))return;let t=this._postList.get(e);this._postList.delete(e);let r=this.transform.view3D;m.getRenderJob(r).removePost(t)}getPost(e){return this._postList.has(e)?this._postList.get(e):null}}const Xp="1.0.13";class m{static res;static inputSystem;static views;static _frameRateValue=0;static _frameRate=360;static _time=0;static _beforeRender;static _renderLoop;static _lateRender;static _requestAnimationFrameID=0;static get frameRate(){return this._frameRate}static set frameRate(e){this._frameRate=e,this._frameRateValue=1e3/e,e>=360&&(this._frameRateValue=0)}static get size(){return Q.presentationSize}static get aspect(){return Q.aspect}static get width(){return Q.windowWidth}static get height(){return Q.windowHeight}static setting={doublePrecision:!1,occlusionQuery:{enable:!0,debug:!1},pick:{enable:!0,mode:"bound",detail:"mesh"},render:{debug:!1,renderPassState:4,renderState_left:5,renderState_right:5,renderState_split:.5,quadScale:1,hdrExposure:1.5,debugQuad:-1,maxPointLight:1e3,maxDirectLight:4,maxSportLight:1e3,drawOpMin:0,drawOpMax:Number.MAX_SAFE_INTEGER,drawTrMin:0,drawTrMax:Number.MAX_SAFE_INTEGER,zPrePass:!1,useLogDepth:!1,useCompressGBuffer:!1,gi:!1,postProcessing:{bloom:{downSampleStep:3,downSampleBlurSize:9,downSampleBlurSigma:1,upSampleBlurSize:9,upSampleBlurSigma:1,luminanceThreshole:1,bloomIntensity:1,hdr:1},globalFog:{debug:!1,enable:!1,fogType:0,fogHeightScale:.1,start:400,end:10,density:.02,ins:.5,skyFactor:.5,skyRoughness:.4,overrideSkyFactor:.8,fogColor:new P(96/255,117/255,133/255,1),falloff:.7,rayLength:200,scatteringExponent:2.7,dirHeightLine:10},godRay:{blendColor:!0,rayMarchCount:16,scatteringExponent:5,intensity:.5},ssao:{enable:!1,radius:.15,bias:-.1,aoPower:2,debug:!0},outline:{enable:!1,strength:1,groupCount:4,outlinePixel:2,fadeOutlinePixel:4,textureScale:1,useAddMode:!1,debug:!0},taa:{enable:!1,jitterSeedCount:8,blendFactor:.1,sharpFactor:.6,sharpPreBlurFactor:.5,temporalJitterScale:.13,debug:!0},gtao:{enable:!1,darkFactor:1,maxDistance:5,maxPixel:50,rayMarchSegment:6,multiBounce:!1,usePosFloat32:!0,blendColor:!0,debug:!0},ssr:{enable:!1,pixelRatio:1,fadeEdgeRatio:.2,rayMarchRatio:.5,fadeDistanceMin:600,fadeDistanceMax:2e3,roughnessThreshold:.5,powDotRN:.2,mixThreshold:.1,debug:!0},fxaa:{enable:!1},depthOfView:{enable:!1,iterationCount:3,pixelOffset:1,near:150,far:300}}},shadow:{enable:!0,type:"HARD",pointShadowBias:5e-4,shadowSize:2048,pointShadowSize:1024,shadowSoft:.005,shadowBound:100,shadowBias:.05,needUpdate:!0,autoUpdate:!0,updateFrameRate:2,csmMargin:.1,csmScatteringExp:.7,csmAreaScale:.4,debug:!1},gi:{enable:!1,offsetX:0,offsetY:0,offsetZ:0,probeSpace:64,probeXCount:4,probeYCount:2,probeZCount:4,probeSize:32,probeSourceTextureSize:2048,octRTMaxSize:2048,octRTSideSize:16,maxDistance:64*1.73,normalBias:.25,depthSharpness:1,hysteresis:.98,lerpHysteresis:.01,irradianceChebyshevBias:.01,rayNumber:144,irradianceDistanceBias:32,indirectIntensity:1,ddgiGamma:2.2,bounceIntensity:.025,probeRoughness:1,realTimeGI:!1,debug:!1,autoRenderProbe:!1},sky:{type:"HDRSKY",sky:null,skyExposure:1,defaultFar:65536,defaultNear:1},light:{maxLight:4096},material:{materialChannelDebug:!1,materialDebug:!1},loader:{numConcurrent:20},reflectionSetting:{reflectionProbeMaxCount:8,reflectionProbeSize:256,width:256*6,height:8*256,enable:!0}};static renderJobs;static async init(e={}){console.log("Rings Version",Xp),window.isSecureContext||console.warn("WebGPU is only supported in secure contexts (HTTPS or localhost)"),this.setting={...this.setting,...e.engineSetting},await pe.init(I.allocCount,this.setting.doublePrecision),await Q.init(e.canvasConfig),this.setting.reflectionSetting.width=this.setting.reflectionSetting.reflectionProbeSize*6,this.setting.reflectionSetting.height=this.setting.reflectionSetting.reflectionProbeSize*this.setting.reflectionSetting.reflectionProbeMaxCount,se.getGBufferFrame(se.reflections_GBuffer,this.setting.reflectionSetting.width,this.setting.reflectionSetting.height,!1),O.init(),Mr.init(),ne.init(),Ct.init(),Tt.init(),this.res=new Ec,this.res.initDefault(),this._beforeRender=e.beforeRender,this._renderLoop=e.renderLoop,this._lateRender=e.lateRender,this.inputSystem=new zn,this.inputSystem.initCanvas(Q.canvas)}static startRenderJob(e){let t=new bu(e);return this.renderJobs.set(e,t),this.setting.pick.mode=="pixel"&&e.scene.getOrAddComponent(wc).addPost(wo),(this.setting.pick.mode=="pixel"||this.setting.pick.mode=="bound")&&(e.enablePick=!0),t}static startRenderView(e){this.renderJobs||=new Map,this.views=[e];let t=this.startRenderJob(e);return this.resume(),t}static startRenderViews(e){this.renderJobs||=new Map,this.views=e;for(let t=0;t<e.length;t++)this.startRenderJob(e[t]);this.resume()}static getRenderJob(e){return this.renderJobs.get(e)}static pause(){this._requestAnimationFrameID!==0&&(cancelAnimationFrame(this._requestAnimationFrameID),this._requestAnimationFrameID=0)}static resume(){this._requestAnimationFrameID===0&&(this._requestAnimationFrameID=requestAnimationFrame(e=>this.render(e)))}static async render(e){if(this._frameRateValue>0){let t=e-this._time;if(t<this._frameRateValue){let r=performance.now();await new Promise(i=>{setTimeout(()=>{e+=performance.now()-r,i(!0)},this._frameRateValue-t)})}this._time=e}await this.updateFrame(e),this._requestAnimationFrameID=0,this.resume()}static async updateFrame(e){Qe.delta=e-Qe.time,Qe.time=e,Qe.frame+=1,fi.tick(Qe.delta);let t=this.views,r=0;for(r=0;r<t.length;r++){const o=t[r];o.scene.waitUpdate();let[n,l]=Q.presentationSize;o.camera.viewPort.setTo(0,0,n,l)}this._beforeRender&&await this._beforeRender();for(const o of Se.componentsBeforeUpdateList){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];u.enable&&c(n)}}let i=Q.device.createCommandEncoder();for(const o of Se.componentsComputeList){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];u.enable&&c(n,i)}}Q.device.queue.submit([i.finish()]);for(const o of Se.componentsUpdateList){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];u.enable&&c(n)}}for(const o of Se.graphicComponent){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];n&&u.enable&&c(n)}}this._renderLoop&&await this._renderLoop(),pe.updateAllContinueTransform(0,I.useCount,16),ne.modelMatrixBindGroup.writeBuffer(I.useCount*16),this.renderJobs.forEach((o,n)=>{o.renderState||o.start(),o.renderFrame()});for(const o of Se.componentsLateUpdateList){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];u.enable&&c(n)}}this._lateRender&&await this._lateRender()}}let Cs=`
7731
+ `}async loadFontTextures(){let e=[],t=this.data;for(const r of t.fontPage){let i=this.baseUrl+r.file;await m.res.loadTexture(i,null,!0);let a=m.res.getTexture(i),o=new di(a);e.push(o)}zr.parseSprite(e,t),t.fontChar[" "]||zr.insertSpaceChar(t,e[0])}static insertSpaceChar(e,t){let r=new Ki,i=e.size*.5,a=e.lineHeight*.5;r.id=" ",r.offsetSize.set(0,0,e.size,e.size),r.trimSize.set(i,a),r.width=i,r.height=a,r.xadvance=0,r.xoffset=0,r.yoffset=0,r.guiTexture=t,r.uvRec.set(0,0,1e-6,1e-6),qi.addFnt(e.face,e.size,r.id,r)}static readLineProperty(e,t){e.trim().split(" ").forEach((r,i)=>{let a=r.split("=");if(a.length>1){let o=a[0],n=a[1];Object.prototype.hasOwnProperty.call(t,o)&&(n.indexOf('"')==-1?t[o]=parseFloat(a[1]):t[o]=n.replace('"',"").replace('"',""))}})}}function Rp(s,e){let t=new Ki;return t.id=s,t.offsetSize.set(0,0,e.width,e.height),t.trimSize.set(e.width,e.height),t.width=e.width,t.height=e.height,t.xadvance=0,t.xoffset=0,t.yoffset=0,t.guiTexture=new di(e),t.uvRec.set(0,0,1,1),e.isVideoTexture||(e.flipY=!0),t}function vc(s,e,t){let r=new Ki;r.guiTexture=s,r.id=e,r.uvRec.copyFrom(t.textureRect),r.trimSize.x=t.textureRect.z,r.trimSize.y=t.textureRect.w,r.offsetSize.x=t.textureRectOffset.x,r.offsetSize.y=t.textureRectOffset.y,r.offsetSize.z=t.size.x,r.offsetSize.w=t.size.y,r.width=t.size.x,r.height=t.size.y;let i=1/s.width,a=1/s.height;r.uvRec.set(r.uvRec.x*i,r.uvRec.y*a,r.uvRec.z*i,r.uvRec.w*a);let o=.1;return t.border.x<=o&&t.border.y<=o&&t.border.z<=o&&t.border.x<=o?r.isSliced=!1:(r.borderSize.copyFrom(t.border),r.uvBorder.copyFrom(t.border),r.uvBorder.x-=t.textureRectOffset.x,r.uvBorder.y-=t.textureRectOffset.y,r.uvBorder.z=t.border.z-(t.size.x-t.textureRect.z-t.textureRectOffset.x),r.uvBorder.w=t.border.w-(t.size.y-t.textureRect.w-t.textureRectOffset.y),r.uvBorder.x/=t.textureRect.z,r.uvBorder.z/=t.textureRect.z,r.uvBorder.y/=t.textureRect.w,r.uvBorder.w/=t.textureRect.w,r.isSliced=!0),r}class Bc{_spriteMap=new Map;_spriteList=[];textureSize=new j;name;constructor(e){this.textureSize.set(e.x,e.y)}setTexture(e,t,r){let i=vc(e,t,r);return this._spriteMap.set(i.id,i),this._spriteList.push(i),i}getSprite(e){return this._spriteMap.get(e)}get spriteList(){return this._spriteList}}class Cc extends st{static format=Ge.TEXT;_json;_texture;async parseString(e){this._json=JSON.parse(e);let t=this.userData.replace(".json",".png");this._texture=await m.res.loadTexture(t,null,!0),this.data={json:this._json,texture:this._texture},this.parseAtlas()}verification(){if(this.data)return!0;throw new Error("verify failed.")}parseAtlas(){let e=new Bc(this._json.size),t=new di(this._texture),r=this._json.atlas;for(const i in r)e.setTexture(t,i,r[i]);m.res.addAtlas(this.baseUrl,e),this.data=e}}var Ot=Uint8Array,$i=Uint16Array,Ip=Int32Array,Sc=new Ot([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),_c=new Ot([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ep=new Ot([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Fc=function(s,e){for(var t=new $i(31),r=0;r<31;++r)t[r]=e+=1<<s[r-1];for(var i=new Ip(t[30]),r=1;r<30;++r)for(var a=t[r];a<t[r+1];++a)i[a]=a-t[r]<<5|r;return{b:t,r:i}},yc=Fc(Sc,2),bc=yc.b,wp=yc.r;bc[28]=258,wp[258]=28;for(var Tp=Fc(_c,0),Dp=Tp.b,an=new $i(32768),Me=0;Me<32768;++Me){var ii=(Me&43690)>>1|(Me&21845)<<1;ii=(ii&52428)>>2|(ii&13107)<<2,ii=(ii&61680)>>4|(ii&3855)<<4,an[Me]=((ii&65280)>>8|(ii&255)<<8)>>1}for(var Ca=(function(s,e,t){for(var r=s.length,i=0,a=new $i(e);i<r;++i)s[i]&&++a[s[i]-1];var o=new $i(e);for(i=1;i<e;++i)o[i]=o[i-1]+a[i-1]<<1;var n;if(t){n=new $i(1<<e);var l=15-e;for(i=0;i<r;++i)if(s[i])for(var h=i<<4|s[i],u=e-s[i],c=o[s[i]-1]++<<u,f=c|(1<<u)-1;c<=f;++c)n[an[c]>>l]=h}else for(n=new $i(r),i=0;i<r;++i)s[i]&&(n[i]=an[o[s[i]-1]++]>>15-s[i]);return n}),Sa=new Ot(288),Me=0;Me<144;++Me)Sa[Me]=8;for(var Me=144;Me<256;++Me)Sa[Me]=9;for(var Me=256;Me<280;++Me)Sa[Me]=7;for(var Me=280;Me<288;++Me)Sa[Me]=8;for(var Qc=new Ot(32),Me=0;Me<32;++Me)Qc[Me]=5;var Mp=Ca(Sa,9,1),Np=Ca(Qc,5,1),sn=function(s){for(var e=s[0],t=1;t<s.length;++t)s[t]>e&&(e=s[t]);return e},sr=function(s,e,t){var r=e/8|0;return(s[r]|s[r+1]<<8)>>(e&7)&t},on=function(s,e){var t=e/8|0;return(s[t]|s[t+1]<<8|s[t+2]<<16)>>(e&7)},Vp=function(s){return(s+7)/8|0},nn=function(s,e,t){return(e==null||e<0)&&(e=0),(t==null||t>s.length)&&(t=s.length),new Ot(s.subarray(e,t))},Pp=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Ht=function(s,e,t){var r=new Error(e||Pp[s]);if(r.code=s,Error.captureStackTrace&&Error.captureStackTrace(r,Ht),!t)throw r;return r},kp=function(s,e,t,r){var i=s.length,a=r?r.length:0;if(!i||e.f&&!e.l)return t||new Ot(0);var o=!t,n=o||e.i!=2,l=e.i;o&&(t=new Ot(i*3));var h=function(Qt){var Rt=t.length;if(Qt>Rt){var Vt=new Ot(Math.max(Rt*2,Qt));Vt.set(t),t=Vt}},u=e.f||0,c=e.p||0,f=e.b||0,g=e.l,p=e.d,A=e.m,U=e.n,x=i*8;do{if(!g){u=sr(s,c,1);var v=sr(s,c+1,3);if(c+=3,v)if(v==1)g=Mp,p=Np,A=9,U=5;else if(v==2){var y=sr(s,c,31)+257,b=sr(s,c+10,15)+4,w=y+sr(s,c+5,31)+1;c+=14;for(var R=new Ot(w),E=new Ot(19),N=0;N<b;++N)E[Ep[N]]=sr(s,c+N*3,7);c+=b*3;for(var z=sn(E),Y=(1<<z)-1,ee=Ca(E,z,1),N=0;N<w;){var oe=ee[sr(s,c,Y)];c+=oe&15;var S=oe>>4;if(S<16)R[N++]=S;else{var te=0,ge=0;for(S==16?(ge=3+sr(s,c,3),c+=2,te=R[N-1]):S==17?(ge=3+sr(s,c,7),c+=3):S==18&&(ge=11+sr(s,c,127),c+=7);ge--;)R[N++]=te}}var Ce=R.subarray(0,y),J=R.subarray(y);A=sn(Ce),U=sn(J),g=Ca(Ce,A,1),p=Ca(J,U,1)}else Ht(1);else{var S=Vp(c)+4,C=s[S-4]|s[S-3]<<8,_=S+C;if(_>i){l&&Ht(0);break}n&&h(f+C),t.set(s.subarray(S,_),f),e.b=f+=C,e.p=c=_*8,e.f=u;continue}if(c>x){l&&Ht(0);break}}n&&h(f+131072);for(var ce=(1<<A)-1,he=(1<<U)-1,Ue=c;;Ue=c){var te=g[on(s,c)&ce],xe=te>>4;if(c+=te&15,c>x){l&&Ht(0);break}if(te||Ht(2),xe<256)t[f++]=xe;else if(xe==256){Ue=c,g=null;break}else{var Ve=xe-254;if(xe>264){var N=xe-257,Ee=Sc[N];Ve=sr(s,c,(1<<Ee)-1)+bc[N],c+=Ee}var ye=p[on(s,c)&he],Ne=ye>>4;ye||Ht(3),c+=ye&15;var J=Dp[Ne];if(Ne>3){var Ee=_c[Ne];J+=on(s,c)&(1<<Ee)-1,c+=Ee}if(c>x){l&&Ht(0);break}n&&h(f+131072);var lt=f+Ve;if(f<J){var pr=a-J,Nt=Math.min(J,lt);for(pr+f<0&&Ht(3);f<Nt;++f)t[f]=r[pr+f]}for(;f<lt;++f)t[f]=t[f-J]}}e.l=g,e.p=Ue,e.b=f,e.f=u,g&&(u=1,e.m=A,e.d=p,e.n=U)}while(!u);return f!=t.length&&o?nn(t,0,f):t.subarray(0,f)},Lp=new Ot(0),Fr=function(s,e){return s[e]|s[e+1]<<8},or=function(s,e){return(s[e]|s[e+1]<<8|s[e+2]<<16|s[e+3]<<24)>>>0},ln=function(s,e){return or(s,e)+or(s,e+4)*4294967296};function Op(s,e){return kp(s,{i:2},e&&e.out,e&&e.dictionary)}var hn=typeof TextDecoder<"u"&&new TextDecoder,zp=0;try{hn.decode(Lp,{stream:!0}),zp=1}catch{}var Gp=function(s){for(var e="",t=0;;){var r=s[t++],i=(r>127)+(r>223)+(r>239);if(t+i>s.length)return{s:e,r:nn(s,t-1)};i?i==3?(r=((r&15)<<18|(s[t++]&63)<<12|(s[t++]&63)<<6|s[t++]&63)-65536,e+=String.fromCharCode(55296|r>>10,56320|r&1023)):i&1?e+=String.fromCharCode((r&31)<<6|s[t++]&63):e+=String.fromCharCode((r&15)<<12|(s[t++]&63)<<6|s[t++]&63):e+=String.fromCharCode(r)}};function Rc(s,e){if(e){for(var t="",r=0;r<s.length;r+=16384)t+=String.fromCharCode.apply(null,s.subarray(r,r+16384));return t}else{if(hn)return hn.decode(s);var i=Gp(s),a=i.s,t=i.r;return t.length&&Ht(8),a}}var Wp=function(s,e){return e+30+Fr(s,e+26)+Fr(s,e+28)},Jp=function(s,e,t){var r=Fr(s,e+28),i=Rc(s.subarray(e+46,e+46+r),!(Fr(s,e+8)&2048)),a=e+46+r,o=or(s,e+20),n=t&&o==4294967295?Zp(s,a):[o,or(s,e+24),or(s,e+42)],l=n[0],h=n[1],u=n[2];return[Fr(s,e+10),l,h,i,a+Fr(s,e+30)+Fr(s,e+32),u]},Zp=function(s,e){for(;Fr(s,e)!=1;e+=4+Fr(s,e+2));return[ln(s,e+12),ln(s,e+4),ln(s,e+20)]};function Yp(s,e){for(var t={},r=s.length-22;or(s,r)!=101010256;--r)(!r||s.length-r>65558)&&Ht(13);var i=Fr(s,r+8);if(!i)return{};var a=or(s,r+16),o=a==4294967295||i==65535;if(o){var n=or(s,r-12);o=or(s,n)==101075792,o&&(i=or(s,n+32),a=or(s,n+48))}for(var l=0;l<i;++l){var h=Jp(s,a,o),u=h[0],c=h[1],f=h[2],g=h[3],p=h[4],A=h[5],U=Wp(s,A);a=p,u?u==8?t[g]=Op(s.subarray(U,U+c),{out:new Ot(f)}):Ht(14,"unknown compression type "+u):t[g]=nn(s,U,U+c)}return t}class mt extends At{constructor(){super(),this.shader=new Da,this.baseMap=m.res.whiteTexture}set baseMap(e){this.shader.setTexture("baseMap",e)}get baseMap(){return this.shader.getTexture("baseMap")}set baseColor(e){this.shader.setUniformColor("baseColor",e)}get baseColor(){return this.shader.getUniformColor("baseColor")}set envMap(e){}set shadowMap(e){}}class Qi extends Ie{shape_vertices=[];shape_indices=[];radius;widthSegments;heightSegments;phiStart;phiLength;thetaStart;thetaLength;constructor(e,t,r,i,a,o,n){super(),this.radius=e,this.widthSegments=t,this.heightSegments=r,this.phiStart=i,this.phiLength=a,this.thetaStart=o,this.thetaLength=n,this.buildGeometry()}buildGeometry(){var e,t,r=0;let i=this.heightSegments,a=this.widthSegments,o=this.radius;var n=(i+1)*(a+1);let l=new Float32Array(n*3),h=new Float32Array(n*3),u=new Float32Array(n*2),c=new Uint16Array(a*i*2*3),f=0,g=0,p=0;for(t=0;t<=i;++t){var A=Math.PI*t/i,U=o*Math.cos(A),x=o*Math.sin(A);for(e=0;e<=a;++e){var v=2*Math.PI*e/a,S=x*Math.cos(v),C=x*Math.sin(v),_=1/Math.sqrt(S*S+U*U+C*C);if(l[f++]=S,l[f++]=U,l[f++]=C,h[g++]=S*_,h[g++]=U*_,h[g++]=C*_,u[p++]=e/a,u[p++]=t/i,e>0&&t>0){var y=(a+1)*t+e,b=(a+1)*t+e-1,w=(a+1)*(t-1)+e-1,R=(a+1)*(t-1)+e;t==i?(c[r++]=y,c[r++]=w,c[r++]=R):t==1?(c[r++]=y,c[r++]=b,c[r++]=w):(c[r++]=y,c[r++]=b,c[r++]=w,c[r++]=y,c[r++]=w,c[r++]=R)}}}this.setIndices(c),this.setAttribute(V.position,l),this.setAttribute(V.normal,h),this.setAttribute(V.uv,u),this.setAttribute(V.TEXCOORD_1,u),this.addSubGeometry({indexStart:0,indexCount:c.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0}),this.bounds=new Fe(d.ZERO,new d(this.radius*2,this.radius*2,this.radius*2))}}class rs extends q{static register3DRepresentation=null;positionIndex=-1;positionValid=!1;marker;constructor(e){super(),this.parsePlacemark(e),this.setup3DRepresentation()}parsePlacemark(e){if(!e.slamPositionInfo){console.warn("WayPoint3D: slamPositionInfo is not found");return}const t=e.slamPositionInfo.slamPosition.split(",").map(Number);this.localPosition=new d(t[0],t[1],t[2]),this.positionIndex=Number(e.slamPositionInfo.slamPositionIndex),this.positionValid=e.slamPositionInfo.slamPositionValid==="1"}setup3DRepresentation(){if(this.marker&&(this.removeChild(this.marker),this.marker=null),rs.register3DRepresentation)this.marker=rs.register3DRepresentation(this),this.marker&&this.addChild(this.marker);else{this.marker=new q;const e=this.marker.addComponent(K);e.geometry=new Qi(.1,32,16),e.material=new mt,e.material.baseColor=this.positionValid?new P(0,1,0,1):new P(1,0,0,1),this.addChild(this.marker),this.marker.name="WayPoint3DMarker"}}}class is extends q{static register3DRepresentation=null;line;constructor(e){super(),this.parseWayLineFile(e),this.setup3DRepresentation()}parseWayLineFile(e){for(const t of e.Folder.Placemark){const r=new rs(t);this.addChild(r)}this.entityChildren=this.entityChildren.sort((t,r)=>t.positionIndex-r.positionIndex)}setup3DRepresentation(){this.line&&(this.removeChild(this.line),this.line=null),is.register3DRepresentation?(this.line=is.register3DRepresentation(this),this.line&&this.addChild(this.line)):(this.line=this.createMultiLine(this.entityChildren.map(e=>e.localPosition),new P(1,1,1,1)),this.addChild(this.line),this.line.name="WayLines3DLine")}createMultiLine(e,t){if(e.length<2)return null;const r=new Ie,i=new Float32Array(e.length*3);for(let h=0;h<e.length;h++)i[h*3]=e[h].x,i[h*3+1]=e[h].y,i[h*3+2]=e[h].z;const a=new Uint16Array((e.length-1)*2);for(let h=0;h<e.length-1;h++)a[h*2]=h,a[h*2+1]=h+1;r.setIndices(a),r.setAttribute(V.position,i),r.addSubGeometry({indexStart:0,indexCount:a.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0});const o=new q,n=o.addComponent(K),l=new mt;return l.topology="line-list",l.baseColor=t,l.blendMode=ae.ADD,l.castReflection=!1,n.geometry=r,n.material=l,o}}class Ic extends st{static format=Ge.BIN;parseBuffer(e){try{const t={template:null,waylines:null},r=Yp(new Uint8Array(e));for(const a in r){const o=r[a],l=new DOMParser().parseFromString(Rc(o),"application/xml"),h={};this.parseNode(l,h);const u=a.replace("wpmz/","").split(".")[0];Object.assign(t,{[u]:h["#document"].kml.Document})}const i=new is(t.waylines);this.data=i}catch(t){this.parserError(`KMZ parsing failed: ${t}`,-1)}}parseNode(e,t){const r=["Placemark","actionGroup","action"],i=e.nodeName.replace("wpml:","");if(!e.childNodes.length)t[i]=void 0;else{let a=null,o=!1;for(let n=0;n<e.childNodes.length;++n){const l=e.childNodes[n];if(l.nodeType==Node.TEXT_NODE){const h=l.nodeValue?.trim();h&&h.length>0&&(a=h)}else l.nodeType==Node.ELEMENT_NODE&&(o=!0)}if(a&&!o)t[i]=a;else if(o){r.includes(i)?t[i]?.length?t[i].push({}):t[i]=[{}]:t[i]={};for(let n=0;n<e.childNodes.length;++n){const l=e.childNodes[n];l.nodeType==Node.ELEMENT_NODE&&this.parseNode(l,Array.isArray(t[i])?t[i].at(-1):t[i])}}else t[i]=void 0}}verification(){if(this.data)return!0;throw new Error("verify failed.")}}class Ec{_texturePool;_materialPool;_prefabPool;_gltfPool;_geometryPool;_atlasList;_obj;constructor(){this._texturePool=new Map,this._materialPool=new Map,this._prefabPool=new Map,this._geometryPool=new Map,this._gltfPool=new Map,this._atlasList=new Map,this._obj=new Map}getGltf(e){return this._gltfPool.get(e)}addObj(e,t){this._obj.set(e,t)}getObj(e){return this._obj.get(e)}addTexture(e,t){this._texturePool.set(e,t)}getTexture(e){return this._texturePool.get(e)}addGeometry(e,t){this._geometryPool.set(e,t)}getGeometry(e){return this._geometryPool.get(e)}addMat(e,t){return this._materialPool.set(e,t)}getMat(e){return this._materialPool.get(e)}addPrefab(e,t){this._prefabPool.set(e,t)}getPrefab(e){return this._prefabPool.get(e).instantiate()}addAtlas(e,t){t.name=e,this._atlasList.set(e,t)}getAtlas(e){return this._atlasList.get(e)}getGUISprite(e){for(let t of this._atlasList.values()){let r=t.getSprite(e);if(r)return r}return null}async load(e,t,r){return(await new pt().load(e,t,r)).data}async loadGltf(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let r,i=e.substring(e.lastIndexOf(".")).toLowerCase(),a=new pt;i==".gltf"?r=await a.load(e,xt,t):r=await a.load(e,Zo,t);let o=r.data;return this._prefabPool.set(e,o),this._gltfPool.set(e,r.gltf),o}async loadObj(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let r,i=e.substring(e.lastIndexOf(".")).toLowerCase(),a=new pt;i==".obj"&&(r=await a.load(e,ju,t));let o=r.data;return this._prefabPool.set(e,o),o}async loadB3DM(e,t,r){if(this._prefabPool.has(e))return this._prefabPool.get(e);let o=(await new pt().load(e,lc,t,r)).data;return this._prefabPool.set(e,o),o}async loadI3DM(e,t,r){if(this._prefabPool.has(e))return this._prefabPool.get(e);let o=(await new pt().load(e,gc,t,r)).data;return this._prefabPool.set(e,o),o}async loadTexture(e,t,r){if(this._texturePool.has(e))return this._texturePool.get(e);let i=new Vr;return i.flipY=r,await i.load(e,t),this._texturePool.set(e,i),i}async loadTextureCount(e,t,r,i){return new Promise(async(a,o)=>{let n=0,l=[];t==0&&a(l);for(let h=0;h<t;h++){const u=e.shift();this.loadTexture(u,r,i).then(c=>{l.push(c),n++,n==t&&a(l)})}})}async loadBitmapTextures(e,t=5,r,i){let a=[],o=Math.floor(e.length/t)+1,n=Math.floor(e.length%t);for(let l=0;l<o;l++){let h=await this.loadTextureCount(e,l==o-1?n:t,r,i);a.push(...h)}return a}async loadHDRTexture(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new Ho;return r=await r.load(e,t),this._texturePool.set(e,r),r}async loadHDRTextureCube(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new xs;return r=await r.load(e,t),this._texturePool.set(e,r),r}async loadLDRTextureCube(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new Bs;return r=await r.load(e,t),this._texturePool.set(e,r),r}async loadTextureCubeMaps(e){let t=e[0];if(this._texturePool.has(t))return this._texturePool.get(t);let r=new Yo;return await r.load(e),this._texturePool.set(e[0],r),r}async loadTextureCubeStd(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new Yo;return await r.loadStd(e),r}async loadJSON(e,t){return await new pt().loadJson(e,t).then(async r=>r).catch(r=>{console.log(r)})}async loadFont(e,t,r){let a=await new pt().load(e,zr,t,r),o=a.data;return qi.addFontData(o.face,o.size,o),a.data}async loadAtlas(e,t){return(await new pt().load(e,Cc,t,e)).data}async loadKMZ(e,t){return(await new pt().load(e,Ic,t)).data}normalTexture;maskTexture;whiteTexture;blackTexture;redTexture;blueTexture;greenTexture;yellowTexture;grayTexture;defaultSky;defaultGUITexture;defaultGUISprite;defaultMaterial;createTexture(e,t,r,i,a,o,n){let l=32,h=32,u=new Uint8Array(l*h*4);this.fillColor(u,e,t,r,i,a,o);let c=new So;return c.name=n,c.create(16,16,u,!0),n&&this.addTexture(n,c),c}fillColor(e,t,r,i,a,o,n){for(let l=0;l<t;l++)for(let h=0;h<r;h++){let u=h*t+l;e[u*4+0]=i,e[u*4+1]=a,e[u*4+2]=o,e[u*4+3]=n}}initDefault(){this.normalTexture=this.createTexture(32,32,255*.5,255*.5,255,255,"default-normalTexture"),this.maskTexture=this.createTexture(32,32,255,255*.5,255,255,"default-maskTexture"),this.whiteTexture=this.createTexture(32,32,255,255,255,255,"default-whiteTexture"),this.blackTexture=this.createTexture(32,32,0,0,0,255,"default-blackTexture"),this.redTexture=this.createTexture(32,32,255,0,0,255,"default-redTexture"),this.blueTexture=this.createTexture(32,32,0,0,255,255,"default-blueTexture"),this.greenTexture=this.createTexture(32,32,0,255,0,255,"default-greenTexture"),this.yellowTexture=this.createTexture(32,32,0,255,255,255,"default-yellowTexture"),this.grayTexture=this.createTexture(32,32,128,128,128,255,"default-grayTexture");let t=new mc().generateBRDFLUTTexture(),r=t.name="BRDFLUT";this.addTexture(r,t),this.defaultSky=new xs,this.defaultSky.createFromTexture(128,this.blackTexture),me.getInstance().attached(this.defaultSky,this),me.getInstance().attached(t,this),me.getInstance().attached(this.normalTexture,this),me.getInstance().attached(this.maskTexture,this),me.getInstance().attached(this.whiteTexture,this),me.getInstance().attached(this.blackTexture,this),me.getInstance().attached(this.redTexture,this),me.getInstance().attached(this.blueTexture,this),me.getInstance().attached(this.greenTexture,this),me.getInstance().attached(this.yellowTexture,this),me.getInstance().attached(this.grayTexture,this),this.defaultGUITexture=new di(this.whiteTexture),this.defaultGUISprite=new Ki(this.defaultGUITexture),this.defaultGUISprite.trimSize.set(4,4),this.defaultMaterial=new Qr}}class wc extends ke{_postList;init(e){this._postList=new Map}start(){}stop(){}onEnable(){this.activePost()}onDisable(){this.unActivePost()}activePost(){let e=this.transform.view3D,t=m.getRenderJob(e);this._postList.forEach(r=>{t.addPost(r)})}unActivePost(){let e=this.transform.view3D,t=m.getRenderJob(e);this._postList.forEach(r=>{t.removePost(r)})}addPost(e){if(this._postList.has(e))return;let t=new e;return this._postList.set(e,t),this._enable&&this.activePost(),t}removePost(e){if(!this._postList.has(e))return;let t=this._postList.get(e);this._postList.delete(e);let r=this.transform.view3D;m.getRenderJob(r).removePost(t)}getPost(e){return this._postList.has(e)?this._postList.get(e):null}}const Xp="1.0.14";class m{static res;static inputSystem;static views;static _frameRateValue=0;static _frameRate=360;static _time=0;static _beforeRender;static _renderLoop;static _lateRender;static _requestAnimationFrameID=0;static get frameRate(){return this._frameRate}static set frameRate(e){this._frameRate=e,this._frameRateValue=1e3/e,e>=360&&(this._frameRateValue=0)}static get size(){return Q.presentationSize}static get aspect(){return Q.aspect}static get width(){return Q.windowWidth}static get height(){return Q.windowHeight}static setting={doublePrecision:!1,occlusionQuery:{enable:!0,debug:!1},pick:{enable:!0,mode:"bound",detail:"mesh"},render:{debug:!1,renderPassState:4,renderState_left:5,renderState_right:5,renderState_split:.5,quadScale:1,hdrExposure:1.5,debugQuad:-1,maxPointLight:1e3,maxDirectLight:4,maxSportLight:1e3,drawOpMin:0,drawOpMax:Number.MAX_SAFE_INTEGER,drawTrMin:0,drawTrMax:Number.MAX_SAFE_INTEGER,zPrePass:!1,useLogDepth:!1,useCompressGBuffer:!1,gi:!1,postProcessing:{bloom:{downSampleStep:3,downSampleBlurSize:9,downSampleBlurSigma:1,upSampleBlurSize:9,upSampleBlurSigma:1,luminanceThreshole:1,bloomIntensity:1,hdr:1},globalFog:{debug:!1,enable:!1,fogType:0,fogHeightScale:.1,start:400,end:10,density:.02,ins:.5,skyFactor:.5,skyRoughness:.4,overrideSkyFactor:.8,fogColor:new P(96/255,117/255,133/255,1),falloff:.7,rayLength:200,scatteringExponent:2.7,dirHeightLine:10},godRay:{blendColor:!0,rayMarchCount:16,scatteringExponent:5,intensity:.5},ssao:{enable:!1,radius:.15,bias:-.1,aoPower:2,debug:!0},outline:{enable:!1,strength:1,groupCount:4,outlinePixel:2,fadeOutlinePixel:4,textureScale:1,useAddMode:!1,debug:!0},taa:{enable:!1,jitterSeedCount:8,blendFactor:.1,sharpFactor:.6,sharpPreBlurFactor:.5,temporalJitterScale:.13,debug:!0},gtao:{enable:!1,darkFactor:1,maxDistance:5,maxPixel:50,rayMarchSegment:6,multiBounce:!1,usePosFloat32:!0,blendColor:!0,debug:!0},ssr:{enable:!1,pixelRatio:1,fadeEdgeRatio:.2,rayMarchRatio:.5,fadeDistanceMin:600,fadeDistanceMax:2e3,roughnessThreshold:.5,powDotRN:.2,mixThreshold:.1,debug:!0},fxaa:{enable:!1},depthOfView:{enable:!1,iterationCount:3,pixelOffset:1,near:150,far:300}}},shadow:{enable:!0,type:"HARD",pointShadowBias:5e-4,shadowSize:2048,pointShadowSize:1024,shadowSoft:.005,shadowBound:100,shadowBias:.05,needUpdate:!0,autoUpdate:!0,updateFrameRate:2,csmMargin:.1,csmScatteringExp:.7,csmAreaScale:.4,debug:!1},gi:{enable:!1,offsetX:0,offsetY:0,offsetZ:0,probeSpace:64,probeXCount:4,probeYCount:2,probeZCount:4,probeSize:32,probeSourceTextureSize:2048,octRTMaxSize:2048,octRTSideSize:16,maxDistance:64*1.73,normalBias:.25,depthSharpness:1,hysteresis:.98,lerpHysteresis:.01,irradianceChebyshevBias:.01,rayNumber:144,irradianceDistanceBias:32,indirectIntensity:1,ddgiGamma:2.2,bounceIntensity:.025,probeRoughness:1,realTimeGI:!1,debug:!1,autoRenderProbe:!1},sky:{type:"HDRSKY",sky:null,skyExposure:1,defaultFar:65536,defaultNear:1},light:{maxLight:4096},material:{materialChannelDebug:!1,materialDebug:!1},loader:{numConcurrent:20},reflectionSetting:{reflectionProbeMaxCount:8,reflectionProbeSize:256,width:256*6,height:8*256,enable:!0}};static renderJobs;static async init(e={}){console.log("Rings Version",Xp),window.isSecureContext||console.warn("WebGPU is only supported in secure contexts (HTTPS or localhost)"),this.setting={...this.setting,...e.engineSetting},await pe.init(I.allocCount,this.setting.doublePrecision),await Q.init(e.canvasConfig),this.setting.reflectionSetting.width=this.setting.reflectionSetting.reflectionProbeSize*6,this.setting.reflectionSetting.height=this.setting.reflectionSetting.reflectionProbeSize*this.setting.reflectionSetting.reflectionProbeMaxCount,se.getGBufferFrame(se.reflections_GBuffer,this.setting.reflectionSetting.width,this.setting.reflectionSetting.height,!1),O.init(),Mr.init(),ne.init(),Ct.init(),Tt.init(),this.res=new Ec,this.res.initDefault(),this._beforeRender=e.beforeRender,this._renderLoop=e.renderLoop,this._lateRender=e.lateRender,this.inputSystem=new zn,this.inputSystem.initCanvas(Q.canvas)}static startRenderJob(e){let t=new bu(e);return this.renderJobs.set(e,t),this.setting.pick.mode=="pixel"&&e.scene.getOrAddComponent(wc).addPost(wo),(this.setting.pick.mode=="pixel"||this.setting.pick.mode=="bound")&&(e.enablePick=!0),t}static startRenderView(e){this.renderJobs||=new Map,this.views=[e];let t=this.startRenderJob(e);return this.resume(),t}static startRenderViews(e){this.renderJobs||=new Map,this.views=e;for(let t=0;t<e.length;t++)this.startRenderJob(e[t]);this.resume()}static getRenderJob(e){return this.renderJobs.get(e)}static pause(){this._requestAnimationFrameID!==0&&(cancelAnimationFrame(this._requestAnimationFrameID),this._requestAnimationFrameID=0)}static resume(){this._requestAnimationFrameID===0&&(this._requestAnimationFrameID=requestAnimationFrame(e=>this.render(e)))}static async render(e){if(this._frameRateValue>0){let t=e-this._time;if(t<this._frameRateValue){let r=performance.now();await new Promise(i=>{setTimeout(()=>{e+=performance.now()-r,i(!0)},this._frameRateValue-t)})}this._time=e}await this.updateFrame(e),this._requestAnimationFrameID=0,this.resume()}static async updateFrame(e){Qe.delta=e-Qe.time,Qe.time=e,Qe.frame+=1,fi.tick(Qe.delta);let t=this.views,r=0;for(r=0;r<t.length;r++){const o=t[r];o.scene.waitUpdate();let[n,l]=Q.presentationSize;o.camera.viewPort.setTo(0,0,n,l)}this._beforeRender&&await this._beforeRender();for(const o of Se.componentsBeforeUpdateList){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];u.enable&&c(n)}}let i=Q.device.createCommandEncoder();for(const o of Se.componentsComputeList){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];u.enable&&c(n,i)}}Q.device.queue.submit([i.finish()]);for(const o of Se.componentsUpdateList){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];u.enable&&c(n)}}for(const o of Se.graphicComponent){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];n&&u.enable&&c(n)}}this._renderLoop&&await this._renderLoop(),pe.updateAllContinueTransform(0,I.useCount,16),ne.modelMatrixBindGroup.writeBuffer(I.useCount*16),this.renderJobs.forEach((o,n)=>{o.renderState||o.start(),o.renderFrame()});for(const o of Se.componentsLateUpdateList){let n=o[0],l=o[1];for(const h of l){let u=h[0],c=h[1];u.enable&&c(n)}}this._lateRender&&await this._lateRender()}}let Cs=`
7758
7732
  struct BloomCfg{
7759
7733
  downSampleStep: f32,
7760
7734
  downSampleBlurSize: f32,