@rings-webgpu/core 1.0.14 → 1.0.15

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.umd.js CHANGED
@@ -5992,7 +5992,7 @@ struct InstanceData {
5992
5992
  o.color = evalSplat(vTexCoord, vColor);
5993
5993
  return o;
5994
5994
  }
5995
- `;class at{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 at,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 pg=Object.getOwnPropertyDescriptor,Ag=(n,e,t,r)=>{for(var i=r>1?void 0:r?pg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.GSplatShader=class extends at{constructor(){super();const e=new Ne("gsplat_vs_dc","gsplat_fs_dc");e.passType=H.COLOR,e.setShaderEntry("VertMain","FragMain"),e.topology=Ms.triangle_list,e.depthWriteEnabled=!1,e.cullMode=Rt.none,e.shaderState.transparent=!0,e.shaderState.blendMode=se.NORMAL,e.shaderState.writeMasks=[15,15],e.shaderState.castReflection=!1,this.addRenderPass(e),this.setDefault()}setDefault(){const e=this.getDefaultColorShader(),t=new E;e.setUniform("modelMatrix",t.rawData),e.setUniform("pixelCull",new Float32Array([2,0,0,0]))}},c.GSplatShader=Ag([Tr(c.GSplatShader,"GSplatShader")],c.GSplatShader);class dh extends ft{_pixelCullArray=new Float32Array(4);constructor(){super(),z.register("gsplat_vs_dc",ch),z.register("gsplat_fs_dc",fh),this.shader=new c.GSplatShader}setSplatTextures(e,t,r,i,a){const s=this.shader.getDefaultColorShader();s.setTexture("splatColor",e),s.setTexture("transformA",t),s.setTexture("transformB",r),s.setUniformArray("tex_params",i),a&&s.setTexture("splatOrder",a),s.shaderState.depthCompare=$e.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 rs extends Dr{node;constructor(e){super(),this.bufferType=$t.VertexGPUBuffer,this.createVertexBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.VERTEX,e)}createVertexBuffer(e,t){let r=I.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 Xr,this.memoryNodes=new Map,this.memory.allocation(this.byteSize),this.node=this.memory.allocation_node(this.byteSize)}}var dt=(n=>(n[n.split=0]="split",n[n.compose=1]="compose",n[n.compose_bin=2]="compose_bin",n))(dt||{});class gh{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 s={name:a.name,format:a.format,offset:0,shaderLocation:a.location,stride:jr[a.format]};this._attributeSlotLayouts[a.location]=[s];let o=e.get(a.name);o||(o={attribute:a.name,data:new Float32Array(a.size*this.vertexCount)},e.set(a.name,o));let l=o.data.length/s.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 rs(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 s={name:a.name,format:a.format,offset:r*4,shaderLocation:a.location,stride:jr[a.format]};this._attributeSlotLayouts[0][a.location]=s;let o=e.get(a.name);if(o||(o={attribute:a.name,data:new Float32Array(a.size*this.vertexCount)},e.set(a.name,o)),o.data){let l=o.data.length/s.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 rs(this.vertexCount*r)}createComposBinVertexBuffer(e,t){this._attributeSlotLayouts[0]=[];let r=0;for(let s=0;s<t.attributes.length;s++){const o=t.attributes[s];if(o.name=="index"||o.type=="builtin")continue;this._attributeLocation[o.name]=o.location;let l={name:o.name,format:o.format,offset:r*4,shaderLocation:o.location,stride:jr[o.format]};this._attributeSlotLayouts[0][o.location]=l;let h=e.get(o.name);if(h||(h={attribute:o.name,data:new Float32Array(o.size*this.vertexCount)},e.set(o.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+=o.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 rs(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 s=t.data[r*i.stride+a],o=r*(this._vertexBufferLayouts[0].arrayStride/4)+i.offset/4+a;this.vertexGPUBuffer.node.setFloat(s,o)}}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 s=e.get(a.name);for(let o=0;o<a.stride;o++){let l=s.data[t*a.stride+o],h=t*(this._vertexBufferLayouts[0].arrayStride/4)+a.offset/4+o;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 mh extends Dr{indicesNode;constructor(e){super(),this.bufferType=$t.IndicesGPUBuffer,this.createIndicesBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.INDEX|GPUBufferUsage.INDIRECT,e)}createIndicesBuffer(e,t){let r=I.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 Xr,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 ph{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 mh(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 Ah{lodLevels}class Re{instanceID;name;subGeometries=[];morphTargetsRelative;morphTargetDictionary;skinNames;bindPose;blendShapeData;vertexDim;vertexCount=0;_bounds;_attributeMap;_attributes;_indicesBuffer;_vertexBuffer;_onChange=!0;_wireframeLines;constructor(){this.instanceID=bt(),this._attributeMap=new Map,this._attributes=[],this._vertexBuffer=new gh}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 xe(new g,new g(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 Ah;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 ph,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 s=t.data[a*3+0],o=t.data[a*3+1],l=t.data[a*3+2];let h=new g(r[s*3+0],r[s*3+1],r[s*3+2]),u=new g(r[o*3+0],r[o*3+1],r[o*3+2]),f=new g(r[l*3+0],r[l*3+1],r[l*3+2]);i.push(h,u),i.push(u,f),i.push(f,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 s=0;s<r.data.length/3;s++){const o=r.data[s*3+0],l=r.data[s*3+1],h=r.data[s*3+2];let u=new g(i[o*t+0],i[o*t+1],i[o*t+2]),f=new g(i[l*t+0],i[l*t+1],i[l*t+2]),d=new g(i[h*t+0],i[h*t+1],i[h*t+2]);a.push(u,f),a.push(f,d),a.push(d,u)}return this._wireframeLines=a,a}}return null}compute(){this._indicesBuffer&&this._indicesBuffer.compute(),this._vertexBuffer&&this._vertexBuffer.compute()}static crossA=g.UP.clone();static crossB=g.UP.clone();static crossRet=g.UP.clone();static point1=g.UP.clone();static point2=g.UP.clone();static point3=g.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=Re.point1,s=Re.point2,o=Re.point3,l=Re.crossA,h=Re.crossB,u=Re.crossRet;for(let f=0;f<i;f++){let d=r.data[f*3],m=r.data[f*3+1],p=r.data[f*3+2];a.set(e.data[d*3],e.data[d*3+1],e.data[d*3+2]),s.set(e.data[m*3],e.data[m*3+1],e.data[m*3+2]),o.set(e.data[p*3],e.data[p*3+1],e.data[p*3+2]),g.sub(a,s,l).normalize(),g.sub(a,o,h).normalize();let U=l.crossProduct(h,u).normalize();t.data[d*3]=t.data[m*3]=t.data[p*3]=U.x,t.data[d*3+1]=t.data[m*3+1]=t.data[p*3+1]=U.y,t.data[d*3+2]=t.data[m*3+2]=t.data[p*3+2]=U.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 Uh extends Re{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 rn extends He{_dataBuffer;create(e,t,r,i=!1){let a=I.device;const s=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 o=this._dataBuffer=a.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});a.queue.writeBuffer(o,0,r);const l=y.beginCommandEncoder();return l.copyBufferToTexture({buffer:o,bytesPerRow:s},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),y.endCommandEncoder(l),i&&rr.webGPUGenerateMipmap(this),this}updateTexture(e,t,r){let i=I.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 s=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(s,0,r);const o=y.beginCommandEncoder();o.copyBufferToTexture({buffer:s,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),y.endCommandEncoder(o),this.gpuSampler=i.createSampler(this),this.mipmapCount>1&&rr.webGPUGenerateMipmap(this)}}class Bh extends He{_dataBuffer;create(e,t,r){let i=I.device;const a=e*4*4;this.format=X.rgba32uint,this.createTextureDescriptor(e,t,1,this.format);const o=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(o,0,r.buffer);const l=i.createCommandEncoder();return l.copyBufferToTexture({buffer:o,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=I.device;const a=e*4*4;i.queue.writeTexture({texture:this.getGPUTexture()},r.buffer,{bytesPerRow:a},{width:e,height:t,depthOrArrayLayers:1})}}class vh extends He{_dataBuffer;create(e,t,r){let i=I.device;const a=e*4;this.format=X.r32uint,this.createTextureDescriptor(e,t,1,this.format);const o=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(o,0,r.buffer);const l=i.createCommandEncoder();return l.copyBufferToTexture({buffer:o,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=I.device;const a=e*4;i.queue.writeTexture({texture:this.getGPUTexture()},r.buffer,{bytesPerRow:a},{width:e,height:t,depthOrArrayLayers:1})}}const Ch=new Float32Array(1),Ug=new Int32Array(Ch.buffer);let ti=function(n){Ch[0]=n;const e=Ug[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 an extends He{uint16Array;floatArray;_dataBuffer;create(e,t,r=null,i=!0){if(r==null){r=[];for(let a=0,s=e*t*4;a<s;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=I.device;const s=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 o=this.uint16Array;for(let u=0,f=o.length;u<f;u++)o[u]=ti(r[u]);const l=this._dataBuffer=a.createBuffer({size:o.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});a.queue.writeBuffer(l,0,o);const h=y.beginCommandEncoder();h.copyBufferToTexture({buffer:l,bytesPerRow:s},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),this.useMipmap||(this.samplerBindingLayout.type="filtering",this.textureBindingLayout.sampleType="float"),y.endCommandEncoder(h),this.gpuSampler=a.createSampler(this),this.gpuTexture=this.getGPUTexture(),this.mipmapCount>1&&rr.webGPUGenerateMipmap(this)}}var Bg=Object.getOwnPropertyDescriptor,vg=(n,e,t,r)=>{for(var i=r>1?void 0:r?Bg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.GSplatRenderer=class extends kr{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(e){this.count=e.count,this._fullCount=e.count,this.size=this.evalTextureSize(e.count),this.buildColor(e),this.buildTransform(e),this.texParams=new Float32Array([this.count,this.size.x,this.count,1]),this._positions=e.position;const t=this.size.x*this.size.y;this._orderData=new Uint32Array(t);for(let r=0;r<t;r++)this._orderData[r]=r<this.count?r:this.count>0?this.count-1:0;this.splatOrder=new vh().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 dh,this.geometry=new Uh(this._batchSize),this.materials=[this.gsplatMaterial],this.instanceCount=0}onBeforeUpdate(e){this.count>0&&e?.camera&&(this._lodEnabled&&this.updateLOD(e),e.camera.viewMatrix&&this.scheduleOrder(e.camera.viewMatrix))}updateLOD(e){if(!this._worldPositions||this._fullCount===0)return;const r=e.camera.viewMatrix.rawData,i=-(r[0]*r[12]+r[1]*r[13]+r[2]*r[14]),a=-(r[4]*r[12]+r[5]*r[13]+r[6]*r[14]),s=-(r[8]*r[12]+r[9]*r[13]+r[10]*r[14]);let o=0,l=0,h=0;const u=Math.min(100,this._fullCount);for(let B=0;B<u;B++){const v=Math.floor(B/u*this._fullCount)*3;o+=this._worldPositions[v+0],l+=this._worldPositions[v+1],h+=this._worldPositions[v+2]}o/=u,l/=u,h/=u;const f=i-o,d=a-l,m=s-h,p=Math.sqrt(f*f+d*d+m*m);let U=this._lodDistances.length;for(let B=0;B<this._lodDistances.length;B++)if(p<this._lodDistances[B]){U=B;break}if(U!==this._currentLodLevel){this._currentLodLevel=U;const B=this._lodRatios[U],v=Math.floor(this._fullCount*B);if(this._mapping){const C=this._mapping;this._mapping=new Uint32Array(Math.min(v,C.length));for(let _=0;_<this._mapping.length;_++)this._mapping[_]=C[_];this.setMapping(this._mapping)}else this.count=v,this.texParams[0]=this.count,this.texParams[2]=this.count}}setMapping(e){this._mapping=e&&e.length>0?e: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 t=this.size.x*this.size.y;for(let r=0;r<t;r++)this._orderData[r]=r<this.count?r:this.count>0?this.count-1:0;if(this.splatOrder.updateTexture(this.size.x,this.size.y,this._orderData),this._sortWorker){const r=this._worldPositions||this._positions,i=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(r);if(this._mapping)for(let a=0;a<this._mapping.length;++a){const s=this._mapping[a]*3,o=a*3;i[o+0]=r[s+0],i[o+1]=r[s+1],i[o+2]=r[s+2]}this._sortWorker.postMessage({type:"centers",centers:i.buffer,mapping:this._mapping?this._mapping:null},[i.buffer]),this._centersSent=!0}else this._centersSent=!1;this.instanceCount=0}setVisBoost(e){this.texParams[3]=Math.max(0,e)}setSortThrottle(e){this._minIntervalMs=Math.max(0,e|0)}setAdaptiveSorting(e){this._adaptiveSorting=e}setLOD(e,t,r){this._lodEnabled=e,t&&(this._lodDistances=t),r&&(this._lodRatios=r)}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(e,t=0,r=0){this._minPixelCoverage=Math.max(0,e),this._maxPixelCoverage=Math.max(0,t),this._maxPixelCullDistance=Math.max(0,r)}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(e){let t=Math.ceil(Math.sqrt(e));const r=64;t=Math.ceil(t/r)*r;const i=Math.ceil(e/t);return new j(t,i)}buildColor(e){const t=this.size.x|0,r=this.size.y|0,i=new Uint8Array(t*r*4),a=.28209479177387814,s=e.count,o=e.sh?.coeffs,l=o?o.length/(3*s):1;for(let h=0;h<s;h++){let u=.5,f=.5,d=.5;if(o&&l>=1){const U=h*l*3;u=.5+o[U+0]*a,f=.5+o[U+l+0]*a,d=.5+o[U+2*l+0]*a}const m=e.opacity?1/(1+Math.exp(-e.opacity[h])):1,p=h*4;i[p+0]=Math.max(0,Math.min(255,Math.floor(u*255))),i[p+1]=Math.max(0,Math.min(255,Math.floor(f*255))),i[p+2]=Math.max(0,Math.min(255,Math.floor(d*255))),i[p+3]=Math.max(0,Math.min(255,Math.floor(m*255)))}this.splatColor=new rn().create(t,r,i,!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(e){const t=this.size.x|0,r=this.size.y|0,i=e.count,a=new Uint32Array(t*r*4),s=new Array(t*r*4).fill(0),o=new ArrayBuffer(4),l=new Float32Array(o),h=new Uint32Array(o),u=p=>(l[0]=p,h[0]),f=e.position,d=e.rotation,m=e.scale;for(let p=0;p<i;p++){const U=p*4,B=f[p*3+0],v=f[p*3+1],C=f[p*3+2];a[U+0]=u(B),a[U+1]=u(v),a[U+2]=u(C);let _=0,F=0,x=0,b=1;if(d){_=d[p*4+0],F=d[p*4+1],x=d[p*4+2],b=d[p*4+3];const qt=1/Math.hypot(_,F,x,b);_*=qt,F*=qt,x*=qt,b*=qt}let R=1,w=1,Q=1;m&&(R=Math.exp(m[p*3+0]),w=Math.exp(m[p*3+1]),Q=Math.exp(m[p*3+2]));const T=_+_,N=F+F,G=x+x,Z=_*T,$=_*N,he=_*G,ee=F*N,fe=F*G,ve=x*G,te=b*T,q=b*N,ae=b*G,Ae=1-(ee+ve),Ce=$+ae,ye=he-q,Me=$-ae,Se=1-(Z+ve),Pe=fe+te,St=he+q,_r=fe-te,xr=1-(Z+ee),Tt=Ae*R,Dt=Ce*R,Gt=ye*R,Ft=Me*w,Fr=Se*w,yr=Pe*w,br=St*Q,Rr=_r*Q,Qr=xr*Q,ci=Tt*Tt+Ft*Ft+br*br,Ir=Tt*Dt+Ft*Fr+br*Rr,bi=Tt*Gt+Ft*yr+br*Qr,fi=Dt*Dt+Fr*Fr+Rr*Rr,Ri=Dt*Gt+Fr*yr+Rr*Qr,Qi=Gt*Gt+yr*yr+Qr*Qr,Er=U;s[Er+0]=ci,s[Er+1]=Ir,s[Er+2]=bi,s[Er+3]=Qi;const Ii=ti(fi)&65535,Zr=ti(Ri)&65535;a[U+3]=Ii|Zr<<16}this.transformA=new Bh().create(t,r,a),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 an().create(t,r,s,!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 e=this.object3D.transform.worldMatrix,t=this._positions,r=this._fullCount;this._worldPositions||(this._worldPositions=new Float32Array(t.length));const i=e.rawData;for(let a=0;a<r;a++){const s=a*3,o=t[s+0],l=t[s+1],h=t[s+2];this._worldPositions[s+0]=i[0]*o+i[4]*l+i[8]*h+i[12],this._worldPositions[s+1]=i[1]*o+i[5]*l+i[9]*h+i[13],this._worldPositions[s+2]=i[2]*o+i[6]*l+i[10]*h+i[14]}this._centersSent=!1}scheduleOrder(e){if(this.count===0)return;const t=this.object3D.transform.localChange;(t||!this._worldPositions)&&this.updateWorldPositions();const r=e.rawData,i=r[2],a=r[6],s=r[10],o=-(r[0]*r[12]+r[1]*r[13]+r[2]*r[14]),l=-(r[4]*r[12]+r[5]*r[13]+r[6]*r[14]),h=-(r[8]*r[12]+r[9]*r[13]+r[10]*r[14]),u=performance.now(),f=(u-this._lastSentTime)/1e3,d=Math.floor(o*1e3)^Math.floor(l*1e3)^Math.floor(h*1e3),m=Math.floor(i*1e3)^Math.floor(a*1e3)^Math.floor(s*1e3),p=d^m;if(p===this._lastViewMatrixHash&&!t)return;let U=this._minIntervalMs;if(this._adaptiveSorting&&this._minIntervalMs>0){const v=Math.abs(p-this._lastViewMatrixHash)/Math.max(f,.001);v<1e3?U=this._minIntervalMs:v<1e4?U=this._minIntervalMs*.5:U=this._minIntervalMs*.2,this._lastCameraSpeed=v}if(!(u-this._lastSentTime<U)){if(this._lastViewMatrixHash=p,this._lastSentTime=u,!this._sortWorker){this._sortWorker=this.createSortWorker(),this._sortWorker.onmessage=_=>{const F=_.data.order,x=this._orderData.buffer;this._sortWorker.postMessage({order:x},[x]);const b=new Uint32Array(F),R=this.size.x*this.size.y,w=this.count;(!this._orderData||this._orderData.length!==R)&&(this._orderData=new Uint32Array(R));const Q=Math.min(w,b.length);if(this._orderData.set(b.subarray(0,Q),0),Q<R){const G=w>0?w-1:0;this._orderData.fill(G,Q,R)}this.splatOrder.updateTexture(this.size.x,this.size.y,this._orderData);const T=Math.max(0,Math.min(this.count,_.data.count|0));this.texParams[2]=T;const N=Math.ceil(T/this._batchSize);this.instanceCount=N};const B=this._worldPositions||this._positions,v=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(B);if(this._mapping)for(let _=0;_<this._mapping.length;++_){const F=this._mapping[_]*3,x=_*3;v[x+0]=B[F+0],v[x+1]=B[F+1],v[x+2]=B[F+2]}const C=new Uint32Array(this.count);for(let _=0;_<this.count;_++)C[_]=_;this._sortWorker.postMessage({order:C.buffer,centers:v.buffer,mapping:this._mapping},[C.buffer,v.buffer]),this._centersSent=!0}if(!this._centersSent&&this._sortWorker){const B=this._worldPositions||this._positions,v=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(B);if(this._mapping)for(let C=0;C<this._mapping.length;++C){const _=this._mapping[C]*3,F=C*3;v[F+0]=B[_+0],v[F+1]=B[_+1],v[F+2]=B[_+2]}this._sortWorker.postMessage({type:"centers",centers:v.buffer,mapping:this._mapping?this._mapping:null},[v.buffer]),this._centersSent=!0}this._sortWorker.postMessage({cameraPosition:{x:o,y:l,z:h},cameraDirection:{x:-i,y:-a,z:-s}})}}createSortWorker(){function e(){let o,l,h,u,f,d=!1;const m={x:0,y:0,z:0},p={x:0,y:0,z:0},U={x:0,y:0,z:0},B={x:0,y:0,z:0};let v,C;const _=(x,b,R)=>{for(;x<=b;){const w=b+x>>1,Q=R(w);if(Q>0)x=w+1;else if(Q<0)b=w-1;else return w}return~x},F=()=>{if(!o||!l||!u||!f)return;const x=u.x,b=u.y,R=u.z,w=f.x,Q=f.y,T=f.z,N=.001;if(!d&&Math.abs(x-m.x)<N&&Math.abs(b-m.y)<N&&Math.abs(R-m.z)<N&&Math.abs(w-p.x)<N&&Math.abs(Q-p.y)<N&&Math.abs(T-p.z)<N)return;d=!1,m.x=x,m.y=b,m.z=R,p.x=w,p.y=Q,p.z=T;const G=l.length/3;v?.length!==G&&(v=new Uint32Array(G));let Z,$;for(let q=0;q<8;++q){const ae=(q&1?U.x:B.x)-x,Ae=(q&2?U.y:B.y)-b,Ce=(q&4?U.z:B.z)-R,ye=ae*w+Ae*Q+Ce*T;q===0?Z=$=ye:(Z=Math.min(Z,ye),$=Math.max($,ye))}C?C.fill(0):C=new Uint32Array(65537);const he=$-Z,ee=he<1e-6?0:1/he*2**16;for(let q=0;q<G;++q){const ae=q*3,Ae=l[ae+0]-x,Ce=l[ae+1]-b,ye=l[ae+2]-R,Me=Ae*w+Ce*Q+ye*T,Se=Math.floor((Me-Z)*ee);v[q]=Se,C[Se]++}for(let q=1;q<65537;q++)C[q]+=C[q-1];for(let q=0;q<G;q++){const ae=v[q],Ae=--C[ae];o[Ae]=q}const fe=q=>v[o[q]]/ee+Z,ve=()=>{const q=_(0,G-1,ae=>-fe(ae));return Math.min(G,Math.abs(q))},te=fe(G-1)>=0?ve():G;if(h)for(let q=0;q<G;++q)o[q]=h[o[q]];self.postMessage({order:o.buffer,count:te},[o.buffer]),o=null};self.onmessage=x=>{if(x.data.order&&(o=new Uint32Array(x.data.order)),x.data.centers){l=new Float32Array(x.data.centers),U.x=B.x=l[0],U.y=B.y=l[1],U.z=B.z=l[2];const b=l.length/3;for(let R=1;R<b;++R){const w=l[R*3+0],Q=l[R*3+1],T=l[R*3+2];U.x=Math.min(U.x,w),U.y=Math.min(U.y,Q),U.z=Math.min(U.z,T),B.x=Math.max(B.x,w),B.y=Math.max(B.y,Q),B.z=Math.max(B.z,T)}d=!0}x.data.hasOwnProperty("mapping")&&(h=x.data.mapping?new Uint32Array(x.data.mapping):null,d=!0),x.data.cameraPosition&&(u=x.data.cameraPosition),x.data.cameraDirection&&(f=x.data.cameraDirection),F()}}const t=`(${e.toString()})()`,r=new Blob([t],{type:"application/javascript"}),i=URL.createObjectURL(r);return new Worker(i)}nodeUpdate(e,t,r,i){const a=this.object3D.transform.worldMatrix;this.gsplatMaterial.setTransformMatrix(a);const s=`${this._minPixelCoverage},${this._maxPixelCoverage},${this._maxPixelCullDistance},${this._batchSize}`;s!==this._lastPixelCullParams&&(this.gsplatMaterial.setPixelCulling(this._minPixelCoverage,this._maxPixelCoverage,this._maxPixelCullDistance,this._batchSize),this._lastPixelCullParams=s),this._texturesInitialized||(this.gsplatMaterial.setSplatTextures(this.splatColor,this.transformA,this.transformB,this.texParams,this.splatOrder),this._texturesInitialized=!0),super.nodeUpdate(e,t,r,i)}renderPass(e,t,r){const i=r.encoder;for(let a of this.materials){const s=a.getPass(t);if(!(!s||s.length===0))for(const o of s){if(!o.pipeline)continue;o.apply(this.geometry,r.rendererPassState||r),y.bindPipeline(i,o),y.bindGeometryBuffer(i,this.geometry);const h=this.geometry.subGeometries[0].lodLevels[0];this.instanceCount>0?y.drawIndexed(i,h.indexCount,this.instanceCount,h.indexStart,0,0):y.drawIndexed(i,h.indexCount,1,h.indexStart,0,0)}}}destroy(e){this._sortWorker&&(this._sortWorker.terminate(),this._sortWorker=null),this.splatColor&&(this.splatColor.destroy(e),this.splatColor=null),this.transformA&&(this.transformA.destroy(e),this.transformA=null),this.transformB&&(this.transformB.destroy(e),this.transformB=null),this.splatOrder&&(this.splatOrder.destroy(e),this.splatOrder=null),this.gsplatMaterial&&(this.gsplatMaterial.destroy(e),this.gsplatMaterial=null),this._positions=null,this._worldPositions=null,this._orderData=null,this.texParams=null,this._mapping=null,super.destroy(e)}},c.GSplatRenderer=vg([Pt(c.GSplatRenderer,"GSplatRenderer")],c.GSplatRenderer);class sn{static maxVector=new g(Number.MAX_VALUE*.1,Number.MAX_VALUE*.1,Number.MAX_VALUE*.1);static minVector=this.maxVector.clone().multiplyScalar(-1);static genMeshMaxVector=g.ZERO.clone();static genMeshMinVector=g.ZERO.clone();static genMeshVectorList8=[new g,new g,new g,new g,new g,new g,new g,new g];static genGSplatBounds(e,t){t||=new xe(g.ZERO,g.ZERO),t.setFromMinMax(this.maxVector,this.minVector);let r=e.getComponent(c.GSplatRenderer);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 s=e.transform.worldMatrix,o=new g;for(let l=0;l<a;l++){const h=l*3;o.set(i[h+0],i[h+1],i[h+2]),s.transformPoint(o,o),t.expandByPoint(o)}return t.setFromMinMax(t.min,t.max),t}static genMeshBounds(e,t){let r=this.genMeshMinVector,i=this.genMeshMaxVector,a=this.genMeshVectorList8;t||=new xe(g.ZERO,g.ZERO),t.setFromMinMax(this.maxVector,this.minVector);let s=e.getComponents(c.MeshRenderer);for(const o of s)if(o&&o.geometry){let l=o.object3D.transform.worldMatrix;r.copy(o.geometry.bounds.min),i.copy(o.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),s=this.genMeshVectorList8;r||=new xe(g.ZERO,g.ZERO),r.setFromMinMax(this.maxVector,this.minVector),s[0].set(i.x,i.y,i.z),s[1].set(i.x,i.y,a.z),s[2].set(i.x,a.y,i.z),s[3].set(i.x,a.y,a.z),s[4].set(a.x,i.y,i.z),s[5].set(a.x,i.y,a.z),s[6].set(a.x,a.y,i.z),s[7].set(a.x,a.y,a.z);for(const o of s)e.transformPoint(o,o),r.expandByPoint(o);return a.copyFrom(r.max),i.copyFrom(r.min),r.setFromMinMax(i,a),r}}class Sh extends wr{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=Ts().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 xe,this._boundWorld=this._bound.clone(),this._isBoundChange=!0),this._isBoundChange&&(sn.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()):_e.waitStartComponent.forEach((e,t)=>{for(;e.length>0;){const r=e.shift();r.__start(),_e.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 Cg=Object.getOwnPropertyDescriptor,Sg=(n,e,t,r)=>{for(var i=r>1?void 0:r?Cg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.Object3D=class extends Sh{_isScene3D;prefabRef;serializeTag;constructor(){super(),this.transform=this.addComponent(Qt),this.transform.eventDispatcher.addEventListener(Qt.LOCAL_ONCHANGE,this.onTransformLocalChange,this)}get isScene3D(){return this._isScene3D}forChild(e){this.entityChildren.forEach(t=>{e(t),t.forChild(e)})}addComponent(e,t){if(!this.components.has(e)){let r=new e;return r.object3D=this,this.components.set(e,r),r.__init(t),_e.appendWaitStart(r),r}return this.components.get(e)}getOrAddComponent(e){let t=this.components.get(e);return t||(t=this.addComponent(e)),t}removeComponent(e){if(this.components.has(e)){let t=this.components.get(e);_e.removeWaitStart(this,t),this.components.delete(e),t.__stop(),t.beforeDestroy(),t.destroy()}}hasComponent(e){return this.components.has(e)}getComponent(e){return this.components.get(e)}getComponentFromParent(e){if(!this.parent)return null;let t=this.parent.object3D.getComponent(e);return t||this.parent.object3D.getComponentFromParent(e)}getComponentsInChild(e){let t=[],r=this.components.get(e);r&&t.push(r);for(let i=0;i<this.entityChildren.length;i++){let s=this.entityChildren[i].getComponentsInChild(e);t.push(...s)}return t}getComponents(e,t,r){t||=[];let i=this.getComponent(e);i&&(i.enable||r)&&t.push(i);for(let a=0,s=this.entityChildren.length;a<s;a++){let o=this.entityChildren[a];o&&o instanceof c.Object3D&&o.getComponents(e,t,r)}return t}getComponentsExt(e,t,r){t||=[];let i=this.components.get(e);if(i&&(i.enable||r))t.push(i);else for(const a of this.entityChildren)a instanceof c.Object3D&&a.getComponentsExt(e,t,r);return t}getComponentsByProperty(e,t,r=!0,i,a){i||=[];let s;for(const o of this.components.values())o&&(o.enable||a)&&o[e]===t&&(i.push(o),s=!0);if(!(s&&r))for(const o of this.entityChildren)o instanceof c.Object3D&&o.getComponentsByProperty(e,t,r,i,a);return i}clone(){return this.instantiate()}instantiate(){let e=new c.Object3D;return e.name=this.name,e.serializeTag=this.serializeTag,e.prefabRef=this.prefabRef,this.entityChildren.forEach((t,r)=>{let i=t.instantiate();e.addChild(i)}),this.components.forEach((t,r)=>{t.cloneTo(e)}),e}get localPosition(){return this.transform.localPosition}set localPosition(e){this.transform.localPosition=e}get localRotation(){return this.transform.localRotation}set localRotation(e){this.transform.localRotation=e}get localScale(){return this.transform.localScale}set localScale(e){this.transform.localScale=e}get localQuaternion(){return this.transform.localRotQuat}set localQuaternion(e){this.transform.localRotQuat=e}notifyChange(){this.transform.notifyChange()}get parent(){return this.transform.parent}get parentObject(){return this.transform.parent.object3D}set x(e){this.transform.x=e}get x(){return this.transform.x}set y(e){this.transform.y=e}get y(){return this.transform.y}set z(e){this.transform.z=e}get z(){return this.transform.z}set scaleX(e){this.transform.scaleX=e}get scaleX(){return this.transform.scaleX}set scaleY(e){this.transform.scaleY=e}get scaleY(){return this.transform.scaleY}set scaleZ(e){this.transform.scaleZ=e}get scaleZ(){return this.transform.scaleZ}set rotationX(e){this.transform.rotationX=e}get rotationX(){return this.transform.rotationX}set rotationY(e){this.transform.rotationY=e}get rotationY(){return this.transform.rotationY}set rotationZ(e){this.transform.rotationZ=e}get rotationZ(){return this.transform.rotationZ}fixedUpdate(){}lateUpdate(){}traverse(e){e(this);for(let t=0,r=this.entityChildren.length;t<r;t++){let i=this.entityChildren[t];i instanceof c.Object3D&&i.traverse(e)}}destroy(e){this.transform.eventDispatcher.removeEventListener(Qt.LOCAL_ONCHANGE,this.onTransformLocalChange,this),super.destroy(e)}},c.Object3D=Sg([_g],c.Object3D);function _g(n,e){return class extends c.Object3D{set active(t){this.transform.enable=t>0}get active(){return this.transform.enable?1:0}get materialColor(){return this.getComponent(c.MeshRenderer)?.material?.shader.getDefaultColorShader().baseColor}set materialColor(t){let r=this.getComponent(c.MeshRenderer)?.material;r&&(r.shader.getDefaultColorShader().baseColor=t)}notifyMaterialColorChange(t,r){this.getComponent(c.MeshRenderer).materials?.[t]?.shader.getDefaultColorShader().uniforms[r].onChange()}}}class je{static createCamera3DObject(e,t){return this.createCamera3D(null,e,t)}static createCamera3D(e,t,r){return e||=new c.Object3D,t&&t.addChild(e),r&&(e.name=r),e.getOrAddComponent(Oi)}static UnProjection(e,t,r=1,i){let a=new g(e,t,0),s=1,o=g.HELP_0,l=I.canvas.offsetLeft,h=I.canvas.offsetTop,u=I.canvas.clientWidth,f=I.canvas.clientHeight;o.x=((a.x-l)*s/u-.5)*2,o.y=-((a.y-h)*s/f-.5)*2,o.z=r;let d=new g(0,0,0),m=E.helpMatrix2;m.copyFrom(i.projectionMatrix),m.invert();let p=E.helpMatrix;return p.identity(),p.multiply(m),p.multiply(i.transform.worldMatrix),p.perspectiveMultiplyPoint3(o,d),d}static Projection(e,t,r){let i=r||new g(0,0,0),a=E.helpMatrix;a.copyFrom(t.viewMatrix),a.multiply(t.projectionMatrix),a.perspectiveMultiplyPoint3(e,i);let s=I.canvas.clientWidth/2,o=I.canvas.clientHeight/2;return i.x=i.x*s+s,i.y=o-i.y*o,i}static UnProjection2(e,t,r,i,a){let s=a||new g(0,0,0),o=E.helpMatrix;o.copyFrom(i.pvMatrixInv);let l=I.canvas.clientWidth/2,h=I.canvas.clientHeight/2;return s.x=(e-l)/l,s.y=(h-t)/h,s.z=r,o.perspectiveMultiplyPoint3(s,s),s}}class It{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==Ye.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==Ye.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==Ye.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==Ye.DirectionLight){let r=this.directionLightList.get(e);return r||(r=[],this.directionLightList.set(e,r)),r}else if(t==Ye.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==Ye.DirectionLight){let r=this.directionLightList.get(t);if(r||(r=[],this.directionLightList.set(t,r)),!e.shadowCamera){e.shadowCamera=je.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==Ye.PointLight||e.lightData.lightType==Ye.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==Ye.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==Ye.PointLight||e.lightData.lightType==Ye.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=It.directionLightList.get(e.scene),i=It.pointLightList.get(e.scene),a=0,s=0,o=0,l=0;if(t.fill(0),r){let u=0;for(let f=0;f<r.length;f++){const d=r[f];t[f]=d.lightData.index,d.lightData.castShadowIndex=u++}s=r.length}if(i){o=s;let u=0;for(let f=o;f<i.length;f++){const d=i[f];t[f]=d.lightData.index,d.lightData.castShadowIndex=u++}l=o+i.length}oe.getAllCameraGroup().forEach(u=>{u.dirShadowStart=a,u.dirShadowEnd=s,u.pointShadowStart=o,u.pointShadowEnd=l,u.shadowLights.set(new Float32Array(t))})}}class nn{uuid;usage;globalBindGroup;uniformGPUBuffer;matrixBindGroup;uniformByteLength;matrixesByteLength;shadowMatrixRaw=new Float32Array(128);csmMatrixRaw=new Float32Array(Wt.Cascades*16);csmShadowBias=new Float32Array(4);shadowLights=new Float32Array(16);dirShadowStart=0;dirShadowEnd=0;pointShadowStart=0;pointShadowEnd=0;constructor(e){this.uuid=bt(),this.usage=GPUBufferUsage.UNIFORM|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,this.uniformGPUBuffer=new lt(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=E.block*4*E.maxCount,this.globalBindGroup=I.device.createBindGroup({label:"global_bindGroupLayout",layout:Hs.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=It.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=A.setting.shadow.shadowSize;if(Wt.Cascades>1&&e.enableCSM&&t[0])for(let l=0;l<Wt.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=A.setting.reflectionSetting,a=W.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",Ze.testObj.testValue2),this.uniformGPUBuffer.setFloat("test3",Ze.testObj.testValue3),this.uniformGPUBuffer.setFloat("test4",Ze.testObj.testValue4),this.uniformGPUBuffer.setVector3("CameraPos",e.transform.worldPosition),this.uniformGPUBuffer.setFloat("frame",be.frame),this.uniformGPUBuffer.setFloat32Array("SH",e.sh),this.uniformGPUBuffer.setFloat("time",be.time),this.uniformGPUBuffer.setFloat("delta",be.delta),this.uniformGPUBuffer.setFloat("shadowBias",e.getShadowBias(r)),this.uniformGPUBuffer.setFloat("skyExposure",A.setting.sky.skyExposure),this.uniformGPUBuffer.setFloat("renderPassState",A.setting.render.renderPassState),this.uniformGPUBuffer.setFloat("quadScale",A.setting.render.quadScale),this.uniformGPUBuffer.setFloat("hdrExposure",A.setting.render.hdrExposure),this.uniformGPUBuffer.setInt32("renderState_left",A.setting.render.renderState_left),this.uniformGPUBuffer.setInt32("renderState_right",A.setting.render.renderState_right),this.uniformGPUBuffer.setFloat("renderState_split",A.setting.render.renderState_split);let s=A.inputSystem.mouseX*I.pixelRatio,o=A.inputSystem.mouseY*I.pixelRatio;this.uniformGPUBuffer.setFloat("mouseX",s),this.uniformGPUBuffer.setFloat("mouseY",o),this.uniformGPUBuffer.setFloat("windowWidth",I.windowWidth),this.uniformGPUBuffer.setFloat("windowHeight",I.windowHeight),this.uniformGPUBuffer.setFloat("near",e.near),this.uniformGPUBuffer.setFloat("far",e.far),this.uniformGPUBuffer.setFloat("pointShadowBias",A.setting.shadow.pointShadowBias),this.uniformGPUBuffer.setFloat("shadowMapSize",r),this.uniformGPUBuffer.setFloat("shadowSoft",A.setting.shadow.shadowSoft),this.uniformGPUBuffer.setFloat("enableCSM",e.enableCSM?1:0),this.uniformGPUBuffer.setFloat("csmMargin",A.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",be.frame),this.uniformGPUBuffer.setFloat32Array("SH",e.sh),this.uniformGPUBuffer.setFloat("time",be.time),this.uniformGPUBuffer.setFloat("delta",be.delta),this.uniformGPUBuffer.setFloat("shadowBias",A.setting.shadow.shadowBias),this.uniformGPUBuffer.setFloat("skyExposure",A.setting.sky.skyExposure),this.uniformGPUBuffer.setFloat("renderPassState",A.setting.render.renderPassState),this.uniformGPUBuffer.setFloat("quadScale",A.setting.render.quadScale),this.uniformGPUBuffer.setFloat("hdrExposure",A.setting.render.hdrExposure),this.uniformGPUBuffer.setInt32("renderState_left",A.setting.render.renderState_left),this.uniformGPUBuffer.setInt32("renderState_right",A.setting.render.renderState_right),this.uniformGPUBuffer.setFloat("renderState_split",A.setting.render.renderState_split);let t=A.inputSystem.mouseX*I.pixelRatio,r=A.inputSystem.mouseY*I.pixelRatio;this.uniformGPUBuffer.setFloat("mouseX",t),this.uniformGPUBuffer.setFloat("mouseY",r),this.uniformGPUBuffer.setFloat("windowWidth",I.windowWidth),this.uniformGPUBuffer.setFloat("windowHeight",I.windowHeight),this.uniformGPUBuffer.setFloat("near",e.near),this.uniformGPUBuffer.setFloat("far",e.far),this.uniformGPUBuffer.setFloat("pointShadowBias",A.setting.shadow.pointShadowBias),this.uniformGPUBuffer.setFloat("shadowMapSize",A.setting.shadow.shadowSize),this.uniformGPUBuffer.setFloat("shadowSoft",A.setting.shadow.shadowSoft),this.uniformGPUBuffer.setFloat("enableCSM",0),this.uniformGPUBuffer.setFloat("csmMargin",A.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 _h{setting;probesBufferData;probesBuffer;isVolumeFrameChange=!0;randomOrientation;startPosition=new g;isVolumeChange=!0;irradianceVolumeBuffer;directionDistance=20;randomSeedCount=3;useRandomIndex=0;centerDirection=new g(0,0,this.directionDistance).normalize(1);arroundPositions=[];updateOrientation(){return this.useRandomIndex++,this.useRandomIndex>=this.arroundPositions.length&&(this.useRandomIndex=0),E.fromToRotation(this.centerDirection,this.arroundPositions[this.useRandomIndex],this.randomOrientation),this.randomOrientation}init(e){this.setting=e,this.randomOrientation=new E(!1),this.randomOrientation.identity(),this.irradianceVolumeBuffer=new lt(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 g(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,s=this.setting.probeSpace;return i=i||new g,i.x=e*s-s*(a.probeXCount-1)*.5+a.offsetX,i.y=t*s-s*(a.probeYCount-1)*.5+a.offsetY,i.z=r*s-s*(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(ja.lightSize*A.setting.light.maxLight,GPUBufferUsage.COPY_SRC),this.irradianceVolume=new _h,this.irradianceVolume.init(A.setting.gi);for(let e=0;e<A.setting.light.maxLight;e++){let t=this.storageGPUBuffer.memory.allocation_node(ja.lightSize*4);this._lightList.push(t)}this.storageGPUBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE}update(e){this.storageGPUBuffer.clean();let t=W.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 Fh{storageGPUBuffer;reflectionMap;sourceReflectionMap;count;constructor(){this.storageGPUBuffer=new Be(768)}update(e){this.storageGPUBuffer.clean();let t=W.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 yh extends Dr{size;constructor(e,t=0,r){super(),this.bufferType=$t.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=I.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 s=new Float32Array(r.buffer,r.byteOffset,t);new Float32Array(a.getMappedRange(0,t*4)).set(s),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 bh{uuid;index;usage;groupBufferSize;matrixBufferDst;constructor(){this.uuid=bt(),this.groupBufferSize=0,this.usage=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,this.cacheWorldMatrix()}cacheWorldMatrix(){this.groupBufferSize=E.maxCount*E.blockBytes,this.matrixBufferDst=new yh(this.groupBufferSize/4),this.matrixBufferDst.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.matrixBufferDst.buffer.label=this.groupBufferSize.toString()}writeBuffer(e){const t=E.dynamicMatrixBytes;this.matrixBufferDst.mapAsyncWrite(t,e)}}class oe{static _cameraBindGroups;static _lightEntriesMap;static _reflectionEntriesMap;static modelMatrixBindGroup;static init(){this.modelMatrixBindGroup=new bh,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 nn(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 nn(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 Fh,this._reflectionEntriesMap.set(e,t)),this._reflectionEntriesMap.get(e)}}class y{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(y.lastShader!=t)y.lastShader=t;else return!1;y.lastPipeline!=t.pipeline&&(y.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=oe.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 s=i[a];e.setVertexBuffer(a,r.buffer,s.offset,s.size)}}}static cleanCache(){this.lastGeometry=null,this.lastPipeline=null,this.lastShader=null}static createPipeline(e){return Ze.countStart("GPUContext","pipeline"),I.device.createRenderPipeline(e)}static beginCommandEncoder(){return Ze.countStart("GPUContext","beginCommandEncoder"),this.LastCommand&&I.device.queue.submit([this.LastCommand.finish()]),this.LastCommand=I.device.createCommandEncoder(),this.LastCommand}static endCommandEncoder(e){this.LastCommand==e&&(I.device.queue.submit([this.LastCommand.finish()]),this.LastCommand=null,Ze.countStart("GPUContext","endCommandEncoder"))}static recordBundleEncoder(e){return I.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=I.context.getCurrentTexture().createView()):r.view=I.context.getCurrentTexture().createView()),e.beginRenderPass(t.renderPassDescriptor)}}static drawIndexed(e,t,r,i,a,s){e.drawIndexed(t,r,i,a,s),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 Rh{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 Qh{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 Rh,this._normalAttrDataGroup=new Rh}initMorphTarget(e){this._collectMorphTargetData=this.collectMorphTargetList(e),this._computeShader&&this._computeShader.destroy();let t=Nt.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,y.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("."),f=u[u.length-1];this._blendTarget[f]=d=>this.updateInfluence(h,d)}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 s=this.collectAttribute("a_morphNormals_",e),o;if(s&&s.length>0){let l=0;o=new Float32Array(i*r*3);for(let h=0;h<r;h++){let u=s[h];o.set(u.data,l),l+=u.data.length}}return{mtCount:r,vCount:i,mergedPos:a,mergedNormal:o}}collectAttribute(e,t){let r=[];for(let i=0;i<this.MaxMorphTargetCount;i++){let a=e+i,s=t.getAttribute(a);if(s)r[i]=s;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 lt(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 xg=Object.defineProperty,Fg=Object.getOwnPropertyDescriptor,on=(n,e,t,r)=>{for(var i=r>1?void 0:r?Fg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=(r?s(e,t,i):s(i))||i);return r&&i&&xg(e,t,i),i};c.MeshRenderer=class extends kr{receiveShadow;morphData;constructor(){super()}onEnable(){super.onEnable()}onDisable(){super.onDisable()}cloneTo(e){e.addComponent(c.MeshRenderer).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this.receiveShadow=e.receiveShadow,this}get geometry(){return this._geometry}set geometry(e){if(super.geometry=e,e){let t=e.morphTargetDictionary!=null;t&&(this.morphData||=new Qh,this.morphData.morphTargetsRelative=e.morphTargetsRelative,this.morphData.initMorphTarget(e)),this.morphData&&(this.morphData.enable=t),this.morphData?.enable?this.addRendererMask(Ue.MorphTarget):this.removeRendererMask(Ue.MorphTarget),this.object3D.bound=this._geometry.bounds.clone()}else this.morphData&&(this.morphData.enable=!1),this.removeRendererMask(Ue.MorphTarget);this._readyPipeline||(this.initPipeline(),this._computes&&(this.onCompute=Za(this.onCompute,()=>{for(let t=0;t<this._computes.length;t++)this._computes[t].onUpdate()})))}get material(){return this._materials[0]}set material(e){this.materials=[e]}setMorphInfluence(e,t){if(this.morphData&&this.morphData.enable){let r=this._geometry.morphTargetDictionary[e];r>=0&&this.morphData.updateInfluence(r,t)}}setMorphInfluenceIndex(e,t){this.morphData&&this.morphData.enable&&e>=0&&this.morphData.updateInfluence(e,t)}onCompute(e,t){this.morphData&&this.morphData.enable&&this.morphData.computeMorphTarget(t)}nodeUpdate(e,t,r,i){if(this.morphData&&this.morphData.enable)for(let a=0;a<this.materials.length;a++){let o=this.materials[a].getPass(t);if(o)for(let l=0;l<o.length;l++)this.morphData.applyRenderShader(o[l])}super.nodeUpdate(e,t,r,i)}destroy(e){this.morphData&&(this.morphData.destroy(e),this.morphData=null),super.destroy(e)}},on([Ni],c.MeshRenderer.prototype,"geometry",1),on([Ni],c.MeshRenderer.prototype,"material",1),c.MeshRenderer=on([Pt(c.MeshRenderer,"MeshRenderer")],c.MeshRenderer);class mr{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 Ih{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]:A.res.redTexture}}class gt extends He{resolveTarget;sampleCount;autoResize;clear;constructor(e,t,r=X.rgba8unorm,i=!1,a,s=1,o=0,l=!0,h=!0){super(e,t,s),this.name=bt(),this.autoResize=h,this.useMipmap=i,this.sampleCount=o,this.format=r,this.numberLayer=s,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&&I.addEventListener(Yr.RESIZE,u=>{let{width:f,height:d}=u.data;this.resize(f,d),this._textureChange=!0},this)}resize(e,t){let r=I.device;this.gpuTexture&&(He.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=I.device.createSampler({}),this.gpuSampler_comparison=I.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=I.device.createSampler({}),this.gpuSampler_comparison=I.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=Vt.clamp_to_edge,this.addressModeV=Vt.clamp_to_edge,this.gpuSampler=r.createSampler(this)),this._textureChange=!0}create(e,t,r=!0){let i=I.device;const a=e*4;let s=new Float32Array(e*t*4);const o=i.createBuffer({size:s.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(o,0,s);const l=y.beginCommandEncoder();l.copyBufferToTexture({buffer:o,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),y.endCommandEncoder(l)}clone(){let e=new gt(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=I.device,t=I.windowWidth,r=I.windowHeight,i=new Float32Array(t*r*4);const a=e.createBuffer({size:i.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});return y.beginCommandEncoder().copyTextureToBuffer({texture:this.getGPUTexture()},{buffer:a},[t,r]),a.getMappedRange(0,i.byteLength)}}class Qe{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 Qe;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 ne 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,s){let o=this.renderTargets,l=this.rtDescriptors;if(a){let u=new Qe;u.loadOp="clear",this._colorBufferTex=mt.createRTTexture(e+mr.colorBufferTex_NAME,t,r,X.rgba16float,!0),o.push(this._colorBufferTex),l.push(u)}this._compressGBufferTex=new gt(t,r,X.rgba32float,!1,void 0,1,0,!0,!0),o.push(this._compressGBufferTex),s?this.depthTexture=s:(this.depthTexture=new gt(t,r,X.depth24plus,!1,void 0,1,0,!0,!0),this.depthTexture.name=e+"_depthTexture");let h;h=new Qe,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 s;if(ne.gBufferMap.has(e))s=ne.gBufferMap.get(e);else{s=new ne;let o=I.presentationSize;s.createGBuffer(e,t==0?o[0]:t,r==0?o[1]:r,t!=0&&r!=0,i,a),ne.gBufferMap.set(e,s)}return s}static getGUIBufferFrame(){let e=this.getGBufferFrame(this.colorPass_GBuffer);return ne.getGBufferFrame(ne.gui_GBuffer,0,0,!0,e.depthTexture)}clone(){let e=new ne;return this.clone2Frame(e),e}}class Ee{static rendererPassState=new Map;static createRendererPassState(e,t=null){let r=Ee.rendererPassState.get(e);if(r||(r=new Ih,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,Ee.rendererPassState.set(e,r)),e&&e.renderTargets.length>0){r.renderTargets=e.renderTargets,r.rtTextureDescriptors=e.rtDescriptors,r.renderPassDescriptor=Ee.getRenderPassDescriptor(r),r.renderPassDescriptor.depthStencilAttachment&&(r.renderPassDescriptor.depthStencilAttachment.depthLoadOp=e.depthLoadOp),t=="load"&&e?.renderTargets[0]&&e.renderTargets[0].name.startsWith(ne.gui_GBuffer)&&(r.renderPassDescriptor.colorAttachments[0].loadOp="load"),r.depthLoadOp=e.depthLoadOp,r.renderBundleEncoderDescriptor=Ee.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(mr.colorBufferTex_NAME)!=-1&&(r.outColor=i)}}else r.renderPassDescriptor=Ee.getRenderPassDescriptor(r,t),r.renderBundleEncoderDescriptor=Ee.getRenderBundleDescriptor(r),r.renderTargetTextures=[{format:I.presentationFormat}],r.outColor=0;return r}static getRenderPassDescriptor(e,t=null){if(e.renderPassDescriptor)return e.renderPassDescriptor;I.device,I.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 s=e.renderTargets[a],o=e.rtTextureDescriptors[a];r.push({view:s.getGPUView(),resolveTarget:void 0,loadOp:o.loadOp,clearValue:o.clearValue,storeOp:o.storeOp})}}else if(!e.customSize){let a=I.canvasConfig&&I.canvasConfig.alpha?[1,1,1,0]:[0,0,0,1];e.isOutTarget==!0&&r.push({view:void 0,resolveTarget:void 0,loadOp:I.canvasConfig&&I.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;I.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 Wi extends Re{width;height;segmentW;segmentH;up;constructor(e,t,r=1,i=1,a=g.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,s=this.segmentW+1;(this.segmentH+1)*s,this.bounds=new xe(g.ZERO.clone(),new g(this.width,1,this.height)),i=this.segmentH*this.segmentW*6;let o=(this.segmentW+1)*(this.segmentH+1),l=new Float32Array(o*3),h=new Float32Array(o*3),u=new Float32Array(o*2),f;this.segmentW*this.segmentH*2*3>=Uint16Array.length?f=new Uint32Array(this.segmentW*this.segmentH*2*3):f=new Uint16Array(this.segmentW*this.segmentH*2*3),i=0;for(var m=0,p=0,U=0,B=0;B<=this.segmentH;++B)for(var v=0;v<=this.segmentW;++v){switch(t=(v/this.segmentW-.5)*this.width,r=(B/this.segmentH-.5)*this.height,e){case g.Y_AXIS:l[m++]=t,l[m++]=0,l[m++]=r,h[p++]=0,h[p++]=1,h[p++]=0;break;case g.Z_AXIS:l[m++]=t,l[m++]=-r,l[m++]=0,h[p++]=0,h[p++]=0,h[p++]=1;break;case g.X_AXIS:l[m++]=0,l[m++]=t,l[m++]=r,h[p++]=1,h[p++]=0,h[p++]=0;break;default:l[m++]=t,l[m++]=0,l[m++]=r,h[p++]=0,h[p++]=1,h[p++]=0;break}u[U++]=v/this.segmentW,u[U++]=B/this.segmentH,v!=this.segmentW&&B!=this.segmentH&&(a=v+B*s,f[i++]=a+1,f[i++]=a,f[i++]=a+s,f[i++]=a+1,f[i++]=a+s,f[i++]=a+s+1)}this.setIndices(f),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:f.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0})}}var yg=Object.getOwnPropertyDescriptor,bg=(n,e,t,r)=>{for(var i=r>1?void 0:r?yg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.QuadShader=class extends at{constructor(e="QuadGlsl_vs",t="QuadGlsl_fs"){super();let r=new Ne(e,t);this.addRenderPass(r);let i=r.shaderState;r.blendMode=se.NONE,i.frontFace="cw",i.depthWriteEnabled=!1,i.depthCompare=$e.always,i.multisample=0,this.setTexture("baseMap",A.res.blackTexture),this.setUniformFloat("x",0),this.setUniformFloat("y",0),this.setUniformFloat("width",100),this.setUniformFloat("height",100)}},c.QuadShader=bg([Tr(c.QuadShader,"QuadShader")],c.QuadShader);class ln extends c.Object3D{width=128;height=128;quadRenderer;material;rendererPassState;quadShader;constructor(e="QuadGlsl_vs",t="QuadGlsl_fs",r,i=0,a=!1){super();let s=r?r.renderTargets:[];this.material=new ft,this.quadShader=new c.QuadShader(e,t),this.material.shader=this.quadShader,this.quadRenderer=this.addComponent(c.MeshRenderer),this.quadRenderer.material=this.material,this.quadRenderer.castGI=!1,this.quadRenderer.castShadow=!1,this.quadRenderer.drawType=a?2:0,this.quadRenderer.geometry=new Wi(100,100,1,1),this.quadRenderer.material=this.material,this.quadRenderer.__start(),this.quadRenderer._enable=!0,this.quadRenderer.onEnable(),this.rendererPassState=Ee.createRendererPassState(r,"load"),i>0&&(this.rendererPassState.multisample=this.quadShader.getDefaultColorShader().shaderState.multisample,this.rendererPassState.multiTexture=I.device.createTexture({size:{width:I.presentationSize[0],height:I.presentationSize[1]},sampleCount:i,format:s.length>0?s[0].format:I.presentationFormat,usage:GPUTextureUsage.RENDER_ATTACHMENT})),I.addEventListener(Yr.RESIZE,o=>{this.rendererPassState=Ee.createRendererPassState(r,"load"),i>0&&(this.rendererPassState.multisample=this.quadShader.getDefaultColorShader().shaderState.multisample,this.rendererPassState.multiTexture=I.device.createTexture({size:{width:I.presentationSize[0],height:I.presentationSize[1]},sampleCount:i,format:s.length>0?s[0].format:I.presentationFormat,usage:GPUTextureUsage.RENDER_ATTACHMENT}))},this)}renderTarget(e,t,r){let i=e.camera,a=y.beginRenderPass(r,t.rendererPassState);y.bindCamera(a,i),t.quadRenderer.nodeUpdate(e,H.COLOR,t.rendererPassState,null),t.quadRenderer.renderPass2(e,H.COLOR,t.rendererPassState,null,a),y.endPass(a)}renderToViewQuad(e,t,r,i){let a=e.camera;t.quadShader.setTexture("baseMap",i);let s=y.beginRenderPass(r,t.rendererPassState);y.bindCamera(s,a),t.quadRenderer.nodeUpdate(e,H.COLOR,t.rendererPassState,null),t.quadRenderer.renderPass2(e,H.COLOR,t.rendererPassState,null,s),y.endPass(s)}}class mt{static rtTextureMap;static rtViewQuad;static init(){this.rtTextureMap=new Map,this.rtViewQuad=new Map}static createRTTexture(e,t,r,i,a=!1,s=0){let o=this.rtTextureMap.get(e);return o||(e==mr.colorBufferTex_NAME?o=new gt(t,r,i,a,void 0,1,s,!1):o=new gt(t,r,i,a,void 0,1,s,!0),o.name=e,mt.rtTextureMap.set(e,o)),o}static createRTTextureArray(e,t,r,i,a=1,s=!1,o=0){let l=this.rtTextureMap.get(e);return l||(l=new gt(t,r,i,s,void 0,a,o),l.name=e,mt.rtTextureMap.set(e,l)),l}static createViewQuad(e,t,r,i,a=0){let s=new ze([i],[new Qe]),o=new ln(t,r,s,a);return mt.rtViewQuad.set(e,o),o}static getTexture(e){return this.rtTextureMap.get(e)}static CreateSplitTexture(e){let t=this.getTexture(mr.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(mr.colorBufferTex_NAME),r=this.getTexture(e+"_split");const i=y.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}),y.endCommandEncoder(i)}}class hn{command;encoder;rendererPassStates;rtFrame;constructor(e){this.rtFrame=e,this.rendererPassStates=[]}clean(){this.rendererPassStates.length=0,y.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=Ee.createRendererPassState(r,e);return this.rendererPassStates.push(i),i}else{this.rtFrame.depthLoadOp=t;let r=Ee.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=y.beginCommandEncoder(),this.command}endCommand(){y.endCommandEncoder(this.command),this.command=null}beginNewEncoder(){return this.encoder=y.beginRenderPass(this.command,this.rendererPassState),this.encoder}endEncoder(){y.endPass(this.encoder),this.encoder=null}}class pr extends wr{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=Ee.createRendererPassState(e);let t=e.clone();t.depthLoadOp="load";for(const r of t.rtDescriptors)r.loadOp="load";this.splitRendererPassState=Ee.createRendererPassState(t)}this.renderContext=new hn(e)}getRenderContext(e){return this._rtFrame=e,new hn(e)}setIrradiance(e,t){this.rendererPassState.irradianceBuffer=[e,t]}compute(e,t){}render(e,t,r,i=!1){y.cleanCache();let a=e.camera,s=e.scene;this.rendererPassState.camera3D=a;let o=W.instance.getRenderNodes(s,a),l=this.renderBundleOp(e,o,t,r),h=i?[]:this.renderBundleTr(e,o,t,r);{let u=y.beginCommandEncoder(),f=y.beginRenderPass(u,this.rendererPassState);l.length>0&&f.executeBundles(l),!i&&W.instance.sky&&(y.bindCamera(f,a),W.instance.sky.renderPass2(e,this._rendererType,this.rendererPassState,r,f)),this.drawRenderNodes(e,f,u,o.opaqueList,t),y.endPass(f),y.endCommandEncoder(u)}{let u=y.beginCommandEncoder(),f=y.beginRenderPass(u,this.rendererPassState);h.length>0&&f.executeBundles(h),i||(y.bindCamera(f,a),this.drawRenderNodes(e,f,u,o.transparentList,t)),y.endPass(f),y.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=W.instance.getOpRenderGroup(e.scene);if(a){let s=[];return a.renderGroup.forEach(o=>{if(o.bundleMap.has(this._rendererType))s.push(o.bundleMap.get(this._rendererType));else{let l=y.recordBundleEncoder(this.rendererPassState.renderBundleEncoderDescriptor);this.recordRenderBundleNode(e,l,o.renderNodes,i);let h=l.finish();o.bundleMap.set(this._rendererType,h),s.push(h)}}),s}return[]}renderBundleTr(e,t,r,i){let a=W.instance.getTrRenderGroup(e.scene);if(a){let s=[];return a.renderGroup.forEach(o=>{if(o.bundleMap.has(this._rendererType))s.push(o.bundleMap.get(this._rendererType));else{let l=y.recordBundleEncoder(this.rendererPassState.renderBundleEncoderDescriptor);this.recordRenderBundleNode(e,l,o.renderNodes,i);let h=l.finish();o.bundleMap.set(this._rendererType,h),s.push(h)}}),s}return[]}recordRenderBundleNode(e,t,r,i){y.bindCamera(t,e.camera),y.bindGeometryBuffer(t,r[0].geometry);for(let a=0;a<r.length;++a){let s=r[a];s.transform.worldMatrix.index,s.transform.enable&&s.recordRenderPass2(e,this._rendererType,this.rendererPassState,i,t)}}drawRenderNodes(e,t,r,i,a,s){y.bindCamera(t,e.camera);for(let o=A.setting.render.drawOpMin;o<Math.min(i.length,A.setting.render.drawOpMax);++o){let l=i[o];l.transform.enable&&l.enable&&l.renderPass2(e,this._rendererType,this.rendererPassState,s,t)}}}class Eh extends pr{constructor(){super(),this.passType=H.COLOR}render(e,t,r,i=!1){this.renderContext.clean();let a=e.scene,s=e.camera;oe.updateCameraGroup(s),this.rendererPassState.camera3D=s;let o=W.instance.getRenderNodes(a,s),l=this.renderBundleOp(e,o,t,r),h=i?[]:this.renderBundleTr(e,o,t,r);{this.renderContext.beginOpaqueRenderPass();let u=this.renderContext.encoder;l.length>0&&(W.instance.getOpRenderGroup(a),u.executeBundles(l)),!i&&W.instance.sky&&(y.bindCamera(u,s),W.instance.sky.preInit(this._rendererType)||W.instance.sky.nodeUpdate(e,this._rendererType,this.rendererPassState,r),W.instance.sky.renderPass2(e,this._rendererType,this.rendererPassState,r,u)),o.opaqueList&&(y.bindCamera(u,s),this.drawNodes(e,this.renderContext,o.opaqueList,t,r))}{let u=this.renderContext.encoder;h.length>0&&u.executeBundles(h),!i&&o.transparentList&&(y.bindCamera(u,s),this.drawNodes(e,this.renderContext,o.transparentList,t,r));let f=W.instance.getGraphicList();for(let d=0;d<f.length;d++){const m=f[d];m.nodeUpdate(e,this._rendererType,this.splitRendererPassState,r),m.renderPass2(e,this._rendererType,this.splitRendererPassState,r,u)}this.renderContext.endRenderPass(),Ze.end("ColorPass Draw Transparent")}}drawNodes(e,t,r,i,a){let s=W.instance.getRenderShaderCollect(e);if(s){for(const o of s){let l=o[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 o=A.setting.render.drawOpMin;o<Math.min(r.length,A.setting.render.drawOpMax);++o){let l=r[o];l.transform.enable&&l.enable&&(l.hasMask(Ue.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 un{frustumCullingList;zVisibleList;_renderList;static enable=!0;constructor(){this._renderList=new Map}occlusionRenderNodeTest(e){return A.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 Ji extends Dr{constructor(e,t){super(),this.bufferType=$t.ComputeGPUBuffer,this.createBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST,e,t,"ComputeGPUBuffer")}}class wh{clusterBuffer;lightAssignBuffer;assignTableBuffer;clustersUniformBuffer;constructor(e,t){this.clusterBuffer=new Ji(e*2*4),this.clustersUniformBuffer=new lt(10),this.clustersUniformBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.lightAssignBuffer=new Ji(e*t),this.lightAssignBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.assignTableBuffer=new Ji(e*4),this.assignTableBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE}update(e,t,r,i,a,s,o,l,h,u){this.clustersUniformBuffer.setFloat("clusterTileX",i),this.clustersUniformBuffer.setFloat("clusterTileY",a),this.clustersUniformBuffer.setFloat("clusterTileZ",s),this.clustersUniformBuffer.setFloat("numLights",o),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 pt{static clusterTileX=16;static clusterTileY=16;static clusterTileZ=32}let Th=`
5995
+ `;class at{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 at,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 pg=Object.getOwnPropertyDescriptor,Ag=(n,e,t,r)=>{for(var i=r>1?void 0:r?pg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.GSplatShader=class extends at{constructor(){super();const e=new Ne("gsplat_vs_dc","gsplat_fs_dc");e.passType=H.COLOR,e.setShaderEntry("VertMain","FragMain"),e.topology=Ms.triangle_list,e.depthWriteEnabled=!1,e.cullMode=Rt.none,e.shaderState.transparent=!0,e.shaderState.blendMode=se.NORMAL,e.shaderState.writeMasks=[15,15],e.shaderState.castReflection=!1,this.addRenderPass(e),this.setDefault()}setDefault(){const e=this.getDefaultColorShader(),t=new E;e.setUniform("modelMatrix",t.rawData),e.setUniform("pixelCull",new Float32Array([2,0,0,0]))}},c.GSplatShader=Ag([Tr(c.GSplatShader,"GSplatShader")],c.GSplatShader);class dh extends ft{_pixelCullArray=new Float32Array(4);constructor(){super(),z.register("gsplat_vs_dc",ch),z.register("gsplat_fs_dc",fh),this.shader=new c.GSplatShader}setSplatTextures(e,t,r,i,a){const s=this.shader.getDefaultColorShader();s.setTexture("splatColor",e),s.setTexture("transformA",t),s.setTexture("transformB",r),s.setUniformArray("tex_params",i),a&&s.setTexture("splatOrder",a),s.shaderState.depthCompare=$e.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 rs extends Dr{node;constructor(e){super(),this.bufferType=$t.VertexGPUBuffer,this.createVertexBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.VERTEX,e)}createVertexBuffer(e,t){let r=I.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 Xr,this.memoryNodes=new Map,this.memory.allocation(this.byteSize),this.node=this.memory.allocation_node(this.byteSize)}}var dt=(n=>(n[n.split=0]="split",n[n.compose=1]="compose",n[n.compose_bin=2]="compose_bin",n))(dt||{});class gh{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 s={name:a.name,format:a.format,offset:0,shaderLocation:a.location,stride:jr[a.format]};this._attributeSlotLayouts[a.location]=[s];let o=e.get(a.name);o||(o={attribute:a.name,data:new Float32Array(a.size*this.vertexCount)},e.set(a.name,o));let l=o.data.length/s.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 rs(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 s={name:a.name,format:a.format,offset:r*4,shaderLocation:a.location,stride:jr[a.format]};this._attributeSlotLayouts[0][a.location]=s;let o=e.get(a.name);if(o||(o={attribute:a.name,data:new Float32Array(a.size*this.vertexCount)},e.set(a.name,o)),o.data){let l=o.data.length/s.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 rs(this.vertexCount*r)}createComposBinVertexBuffer(e,t){this._attributeSlotLayouts[0]=[];let r=0;for(let s=0;s<t.attributes.length;s++){const o=t.attributes[s];if(o.name=="index"||o.type=="builtin")continue;this._attributeLocation[o.name]=o.location;let l={name:o.name,format:o.format,offset:r*4,shaderLocation:o.location,stride:jr[o.format]};this._attributeSlotLayouts[0][o.location]=l;let h=e.get(o.name);if(h||(h={attribute:o.name,data:new Float32Array(o.size*this.vertexCount)},e.set(o.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+=o.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 rs(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 s=t.data[r*i.stride+a],o=r*(this._vertexBufferLayouts[0].arrayStride/4)+i.offset/4+a;this.vertexGPUBuffer.node.setFloat(s,o)}}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 s=e.get(a.name);for(let o=0;o<a.stride;o++){let l=s.data[t*a.stride+o],h=t*(this._vertexBufferLayouts[0].arrayStride/4)+a.offset/4+o;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 mh extends Dr{indicesNode;constructor(e){super(),this.bufferType=$t.IndicesGPUBuffer,this.createIndicesBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.INDEX|GPUBufferUsage.INDIRECT,e)}createIndicesBuffer(e,t){let r=I.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 Xr,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 ph{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 mh(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 Ah{lodLevels}class Re{instanceID;name;subGeometries=[];morphTargetsRelative;morphTargetDictionary;skinNames;bindPose;blendShapeData;vertexDim;vertexCount=0;_bounds;_attributeMap;_attributes;_indicesBuffer;_vertexBuffer;_onChange=!0;_wireframeLines;constructor(){this.instanceID=bt(),this._attributeMap=new Map,this._attributes=[],this._vertexBuffer=new gh}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 xe(new g,new g(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 Ah;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 ph,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 s=t.data[a*3+0],o=t.data[a*3+1],l=t.data[a*3+2];let h=new g(r[s*3+0],r[s*3+1],r[s*3+2]),u=new g(r[o*3+0],r[o*3+1],r[o*3+2]),f=new g(r[l*3+0],r[l*3+1],r[l*3+2]);i.push(h,u),i.push(u,f),i.push(f,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 s=0;s<r.data.length/3;s++){const o=r.data[s*3+0],l=r.data[s*3+1],h=r.data[s*3+2];let u=new g(i[o*t+0],i[o*t+1],i[o*t+2]),f=new g(i[l*t+0],i[l*t+1],i[l*t+2]),d=new g(i[h*t+0],i[h*t+1],i[h*t+2]);a.push(u,f),a.push(f,d),a.push(d,u)}return this._wireframeLines=a,a}}return null}compute(){this._indicesBuffer&&this._indicesBuffer.compute(),this._vertexBuffer&&this._vertexBuffer.compute()}static crossA=g.UP.clone();static crossB=g.UP.clone();static crossRet=g.UP.clone();static point1=g.UP.clone();static point2=g.UP.clone();static point3=g.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=Re.point1,s=Re.point2,o=Re.point3,l=Re.crossA,h=Re.crossB,u=Re.crossRet;for(let f=0;f<i;f++){let d=r.data[f*3],m=r.data[f*3+1],p=r.data[f*3+2];a.set(e.data[d*3],e.data[d*3+1],e.data[d*3+2]),s.set(e.data[m*3],e.data[m*3+1],e.data[m*3+2]),o.set(e.data[p*3],e.data[p*3+1],e.data[p*3+2]),g.sub(a,s,l).normalize(),g.sub(a,o,h).normalize();let U=l.crossProduct(h,u).normalize();t.data[d*3]=t.data[m*3]=t.data[p*3]=U.x,t.data[d*3+1]=t.data[m*3+1]=t.data[p*3+1]=U.y,t.data[d*3+2]=t.data[m*3+2]=t.data[p*3+2]=U.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 Uh extends Re{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 rn extends He{_dataBuffer;create(e,t,r,i=!1){let a=I.device;const s=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 o=this._dataBuffer=a.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});a.queue.writeBuffer(o,0,r);const l=y.beginCommandEncoder();return l.copyBufferToTexture({buffer:o,bytesPerRow:s},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),y.endCommandEncoder(l),i&&rr.webGPUGenerateMipmap(this),this}updateTexture(e,t,r){let i=I.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 s=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(s,0,r);const o=y.beginCommandEncoder();o.copyBufferToTexture({buffer:s,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),y.endCommandEncoder(o),this.gpuSampler=i.createSampler(this),this.mipmapCount>1&&rr.webGPUGenerateMipmap(this)}}class Bh extends He{_dataBuffer;create(e,t,r){let i=I.device;const a=e*4*4;this.format=X.rgba32uint,this.createTextureDescriptor(e,t,1,this.format);const o=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(o,0,r.buffer);const l=i.createCommandEncoder();return l.copyBufferToTexture({buffer:o,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=I.device;const a=e*4*4;i.queue.writeTexture({texture:this.getGPUTexture()},r.buffer,{bytesPerRow:a},{width:e,height:t,depthOrArrayLayers:1})}}class vh extends He{_dataBuffer;create(e,t,r){let i=I.device;const a=e*4;this.format=X.r32uint,this.createTextureDescriptor(e,t,1,this.format);const o=this._dataBuffer=i.createBuffer({size:r.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(o,0,r.buffer);const l=i.createCommandEncoder();return l.copyBufferToTexture({buffer:o,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=I.device;const a=e*4;i.queue.writeTexture({texture:this.getGPUTexture()},r.buffer,{bytesPerRow:a},{width:e,height:t,depthOrArrayLayers:1})}}const Ch=new Float32Array(1),Ug=new Int32Array(Ch.buffer);let ti=function(n){Ch[0]=n;const e=Ug[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 an extends He{uint16Array;floatArray;_dataBuffer;create(e,t,r=null,i=!0){if(r==null){r=[];for(let a=0,s=e*t*4;a<s;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=I.device;const s=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 o=this.uint16Array;for(let u=0,f=o.length;u<f;u++)o[u]=ti(r[u]);const l=this._dataBuffer=a.createBuffer({size:o.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});a.queue.writeBuffer(l,0,o);const h=y.beginCommandEncoder();h.copyBufferToTexture({buffer:l,bytesPerRow:s},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),this.useMipmap||(this.samplerBindingLayout.type="filtering",this.textureBindingLayout.sampleType="float"),y.endCommandEncoder(h),this.gpuSampler=a.createSampler(this),this.gpuTexture=this.getGPUTexture(),this.mipmapCount>1&&rr.webGPUGenerateMipmap(this)}}var Bg=Object.getOwnPropertyDescriptor,vg=(n,e,t,r)=>{for(var i=r>1?void 0:r?Bg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.GSplatRenderer=class extends kr{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(e){this.count=e.count,this._fullCount=e.count,this.size=this.evalTextureSize(e.count),this.buildColor(e),this.buildTransform(e),this.texParams=new Float32Array([this.count,this.size.x,this.count,1]),this._positions=e.position;const t=this.size.x*this.size.y;this._orderData=new Uint32Array(t);for(let r=0;r<t;r++)this._orderData[r]=r<this.count?r:this.count>0?this.count-1:0;this.splatOrder=new vh().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 dh,this.geometry=new Uh(this._batchSize),this.materials=[this.gsplatMaterial],this.instanceCount=0}onBeforeUpdate(e){this.count>0&&e?.camera&&(this._lodEnabled&&this.updateLOD(e),e.camera.viewMatrix&&this.scheduleOrder(e.camera.viewMatrix))}updateLOD(e){if(!this._worldPositions||this._fullCount===0)return;const r=e.camera.viewMatrix.rawData,i=-(r[0]*r[12]+r[1]*r[13]+r[2]*r[14]),a=-(r[4]*r[12]+r[5]*r[13]+r[6]*r[14]),s=-(r[8]*r[12]+r[9]*r[13]+r[10]*r[14]);let o=0,l=0,h=0;const u=Math.min(100,this._fullCount);for(let B=0;B<u;B++){const v=Math.floor(B/u*this._fullCount)*3;o+=this._worldPositions[v+0],l+=this._worldPositions[v+1],h+=this._worldPositions[v+2]}o/=u,l/=u,h/=u;const f=i-o,d=a-l,m=s-h,p=Math.sqrt(f*f+d*d+m*m);let U=this._lodDistances.length;for(let B=0;B<this._lodDistances.length;B++)if(p<this._lodDistances[B]){U=B;break}if(U!==this._currentLodLevel){this._currentLodLevel=U;const B=this._lodRatios[U],v=Math.floor(this._fullCount*B);if(this._mapping){const C=this._mapping;this._mapping=new Uint32Array(Math.min(v,C.length));for(let _=0;_<this._mapping.length;_++)this._mapping[_]=C[_];this.setMapping(this._mapping)}else this.count=v,this.texParams[0]=this.count,this.texParams[2]=this.count}}setMapping(e){this._mapping=e&&e.length>0?e: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 t=this.size.x*this.size.y;for(let r=0;r<t;r++)this._orderData[r]=r<this.count?r:this.count>0?this.count-1:0;if(this.splatOrder.updateTexture(this.size.x,this.size.y,this._orderData),this._sortWorker){const r=this._worldPositions||this._positions,i=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(r);if(this._mapping)for(let a=0;a<this._mapping.length;++a){const s=this._mapping[a]*3,o=a*3;i[o+0]=r[s+0],i[o+1]=r[s+1],i[o+2]=r[s+2]}this._sortWorker.postMessage({type:"centers",centers:i.buffer,mapping:this._mapping?this._mapping:null},[i.buffer]),this._centersSent=!0}else this._centersSent=!1;this.instanceCount=0}setVisBoost(e){this.texParams[3]=Math.max(0,e)}setSortThrottle(e){this._minIntervalMs=Math.max(0,e|0)}setAdaptiveSorting(e){this._adaptiveSorting=e}setLOD(e,t,r){this._lodEnabled=e,t&&(this._lodDistances=t),r&&(this._lodRatios=r)}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(e,t=0,r=0){this._minPixelCoverage=Math.max(0,e),this._maxPixelCoverage=Math.max(0,t),this._maxPixelCullDistance=Math.max(0,r)}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(e){let t=Math.ceil(Math.sqrt(e));const r=64;t=Math.ceil(t/r)*r;const i=Math.ceil(e/t);return new j(t,i)}buildColor(e){const t=this.size.x|0,r=this.size.y|0,i=new Uint8Array(t*r*4),a=.28209479177387814,s=e.count,o=e.sh?.coeffs,l=o?o.length/(3*s):1;for(let h=0;h<s;h++){let u=.5,f=.5,d=.5;if(o&&l>=1){const U=h*l*3;u=.5+o[U+0]*a,f=.5+o[U+l+0]*a,d=.5+o[U+2*l+0]*a}const m=e.opacity?1/(1+Math.exp(-e.opacity[h])):1,p=h*4;i[p+0]=Math.max(0,Math.min(255,Math.floor(u*255))),i[p+1]=Math.max(0,Math.min(255,Math.floor(f*255))),i[p+2]=Math.max(0,Math.min(255,Math.floor(d*255))),i[p+3]=Math.max(0,Math.min(255,Math.floor(m*255)))}this.splatColor=new rn().create(t,r,i,!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(e){const t=this.size.x|0,r=this.size.y|0,i=e.count,a=new Uint32Array(t*r*4),s=new Array(t*r*4).fill(0),o=new ArrayBuffer(4),l=new Float32Array(o),h=new Uint32Array(o),u=p=>(l[0]=p,h[0]),f=e.position,d=e.rotation,m=e.scale;for(let p=0;p<i;p++){const U=p*4,B=f[p*3+0],v=f[p*3+1],C=f[p*3+2];a[U+0]=u(B),a[U+1]=u(v),a[U+2]=u(C);let _=0,F=0,x=0,b=1;if(d){_=d[p*4+0],F=d[p*4+1],x=d[p*4+2],b=d[p*4+3];const qt=1/Math.hypot(_,F,x,b);_*=qt,F*=qt,x*=qt,b*=qt}let R=1,w=1,Q=1;m&&(R=Math.exp(m[p*3+0]),w=Math.exp(m[p*3+1]),Q=Math.exp(m[p*3+2]));const T=_+_,N=F+F,G=x+x,Z=_*T,$=_*N,he=_*G,ee=F*N,fe=F*G,ve=x*G,te=b*T,q=b*N,ae=b*G,Ae=1-(ee+ve),Ce=$+ae,ye=he-q,Me=$-ae,Se=1-(Z+ve),Pe=fe+te,St=he+q,_r=fe-te,xr=1-(Z+ee),Tt=Ae*R,Dt=Ce*R,Gt=ye*R,Ft=Me*w,Fr=Se*w,yr=Pe*w,br=St*Q,Rr=_r*Q,Qr=xr*Q,ci=Tt*Tt+Ft*Ft+br*br,Ir=Tt*Dt+Ft*Fr+br*Rr,bi=Tt*Gt+Ft*yr+br*Qr,fi=Dt*Dt+Fr*Fr+Rr*Rr,Ri=Dt*Gt+Fr*yr+Rr*Qr,Qi=Gt*Gt+yr*yr+Qr*Qr,Er=U;s[Er+0]=ci,s[Er+1]=Ir,s[Er+2]=bi,s[Er+3]=Qi;const Ii=ti(fi)&65535,Zr=ti(Ri)&65535;a[U+3]=Ii|Zr<<16}this.transformA=new Bh().create(t,r,a),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 an().create(t,r,s,!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 e=this.object3D.transform.worldMatrix,t=this._positions,r=this._fullCount;this._worldPositions||(this._worldPositions=new Float32Array(t.length));const i=e.rawData;for(let a=0;a<r;a++){const s=a*3,o=t[s+0],l=t[s+1],h=t[s+2];this._worldPositions[s+0]=i[0]*o+i[4]*l+i[8]*h+i[12],this._worldPositions[s+1]=i[1]*o+i[5]*l+i[9]*h+i[13],this._worldPositions[s+2]=i[2]*o+i[6]*l+i[10]*h+i[14]}this._centersSent=!1}scheduleOrder(e){if(this.count===0)return;const t=this.object3D.transform.localChange;(t||!this._worldPositions)&&this.updateWorldPositions();const r=e.rawData,i=r[2],a=r[6],s=r[10],o=-(r[0]*r[12]+r[1]*r[13]+r[2]*r[14]),l=-(r[4]*r[12]+r[5]*r[13]+r[6]*r[14]),h=-(r[8]*r[12]+r[9]*r[13]+r[10]*r[14]),u=performance.now(),f=(u-this._lastSentTime)/1e3,d=Math.floor(o*1e3)^Math.floor(l*1e3)^Math.floor(h*1e3),m=Math.floor(i*1e3)^Math.floor(a*1e3)^Math.floor(s*1e3),p=d^m;if(p===this._lastViewMatrixHash&&!t)return;let U=this._minIntervalMs;if(this._adaptiveSorting&&this._minIntervalMs>0){const v=Math.abs(p-this._lastViewMatrixHash)/Math.max(f,.001);v<1e3?U=this._minIntervalMs:v<1e4?U=this._minIntervalMs*.5:U=this._minIntervalMs*.2,this._lastCameraSpeed=v}if(!(u-this._lastSentTime<U)){if(this._lastViewMatrixHash=p,this._lastSentTime=u,!this._sortWorker){this._sortWorker=this.createSortWorker(),this._sortWorker.onmessage=_=>{const F=_.data.order,x=this._orderData.buffer;this._sortWorker.postMessage({order:x},[x]);const b=new Uint32Array(F),R=this.size.x*this.size.y,w=this.count;(!this._orderData||this._orderData.length!==R)&&(this._orderData=new Uint32Array(R));const Q=Math.min(w,b.length);if(this._orderData.set(b.subarray(0,Q),0),Q<R){const G=w>0?w-1:0;this._orderData.fill(G,Q,R)}this.splatOrder.updateTexture(this.size.x,this.size.y,this._orderData);const T=Math.max(0,Math.min(this.count,_.data.count|0));this.texParams[2]=T;const N=Math.ceil(T/this._batchSize);this.instanceCount=N};const B=this._worldPositions||this._positions,v=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(B);if(this._mapping)for(let _=0;_<this._mapping.length;++_){const F=this._mapping[_]*3,x=_*3;v[x+0]=B[F+0],v[x+1]=B[F+1],v[x+2]=B[F+2]}const C=new Uint32Array(this.count);for(let _=0;_<this.count;_++)C[_]=_;this._sortWorker.postMessage({order:C.buffer,centers:v.buffer,mapping:this._mapping},[C.buffer,v.buffer]),this._centersSent=!0}if(!this._centersSent&&this._sortWorker){const B=this._worldPositions||this._positions,v=this._mapping?new Float32Array(this._mapping.length*3):new Float32Array(B);if(this._mapping)for(let C=0;C<this._mapping.length;++C){const _=this._mapping[C]*3,F=C*3;v[F+0]=B[_+0],v[F+1]=B[_+1],v[F+2]=B[_+2]}this._sortWorker.postMessage({type:"centers",centers:v.buffer,mapping:this._mapping?this._mapping:null},[v.buffer]),this._centersSent=!0}this._sortWorker.postMessage({cameraPosition:{x:o,y:l,z:h},cameraDirection:{x:-i,y:-a,z:-s}})}}createSortWorker(){function e(){let o,l,h,u,f,d=!1;const m={x:0,y:0,z:0},p={x:0,y:0,z:0},U={x:0,y:0,z:0},B={x:0,y:0,z:0};let v,C;const _=(x,b,R)=>{for(;x<=b;){const w=b+x>>1,Q=R(w);if(Q>0)x=w+1;else if(Q<0)b=w-1;else return w}return~x},F=()=>{if(!o||!l||!u||!f)return;const x=u.x,b=u.y,R=u.z,w=f.x,Q=f.y,T=f.z,N=.001;if(!d&&Math.abs(x-m.x)<N&&Math.abs(b-m.y)<N&&Math.abs(R-m.z)<N&&Math.abs(w-p.x)<N&&Math.abs(Q-p.y)<N&&Math.abs(T-p.z)<N)return;d=!1,m.x=x,m.y=b,m.z=R,p.x=w,p.y=Q,p.z=T;const G=l.length/3;v?.length!==G&&(v=new Uint32Array(G));let Z,$;for(let q=0;q<8;++q){const ae=(q&1?U.x:B.x)-x,Ae=(q&2?U.y:B.y)-b,Ce=(q&4?U.z:B.z)-R,ye=ae*w+Ae*Q+Ce*T;q===0?Z=$=ye:(Z=Math.min(Z,ye),$=Math.max($,ye))}C?C.fill(0):C=new Uint32Array(65537);const he=$-Z,ee=he<1e-6?0:1/he*2**16;for(let q=0;q<G;++q){const ae=q*3,Ae=l[ae+0]-x,Ce=l[ae+1]-b,ye=l[ae+2]-R,Me=Ae*w+Ce*Q+ye*T,Se=Math.floor((Me-Z)*ee);v[q]=Se,C[Se]++}for(let q=1;q<65537;q++)C[q]+=C[q-1];for(let q=0;q<G;q++){const ae=v[q],Ae=--C[ae];o[Ae]=q}const fe=q=>v[o[q]]/ee+Z,ve=()=>{const q=_(0,G-1,ae=>-fe(ae));return Math.min(G,Math.abs(q))},te=fe(G-1)>=0?ve():G;if(h)for(let q=0;q<G;++q)o[q]=h[o[q]];self.postMessage({order:o.buffer,count:te},[o.buffer]),o=null};self.onmessage=x=>{if(x.data.order&&(o=new Uint32Array(x.data.order)),x.data.centers){l=new Float32Array(x.data.centers),U.x=B.x=l[0],U.y=B.y=l[1],U.z=B.z=l[2];const b=l.length/3;for(let R=1;R<b;++R){const w=l[R*3+0],Q=l[R*3+1],T=l[R*3+2];U.x=Math.min(U.x,w),U.y=Math.min(U.y,Q),U.z=Math.min(U.z,T),B.x=Math.max(B.x,w),B.y=Math.max(B.y,Q),B.z=Math.max(B.z,T)}d=!0}x.data.hasOwnProperty("mapping")&&(h=x.data.mapping?new Uint32Array(x.data.mapping):null,d=!0),x.data.cameraPosition&&(u=x.data.cameraPosition),x.data.cameraDirection&&(f=x.data.cameraDirection),F()}}const t=`(${e.toString()})()`,r=new Blob([t],{type:"application/javascript"}),i=URL.createObjectURL(r);return new Worker(i)}nodeUpdate(e,t,r,i){const a=this.object3D.transform.worldMatrix;this.gsplatMaterial.setTransformMatrix(a);const s=`${this._minPixelCoverage},${this._maxPixelCoverage},${this._maxPixelCullDistance},${this._batchSize}`;s!==this._lastPixelCullParams&&(this.gsplatMaterial.setPixelCulling(this._minPixelCoverage,this._maxPixelCoverage,this._maxPixelCullDistance,this._batchSize),this._lastPixelCullParams=s),this._texturesInitialized||(this.gsplatMaterial.setSplatTextures(this.splatColor,this.transformA,this.transformB,this.texParams,this.splatOrder),this._texturesInitialized=!0),super.nodeUpdate(e,t,r,i)}renderPass(e,t,r){const i=r.encoder;for(let a of this.materials){const s=a.getPass(t);if(!(!s||s.length===0))for(const o of s){if(!o.pipeline)continue;o.apply(this.geometry,r.rendererPassState||r),y.bindPipeline(i,o),y.bindGeometryBuffer(i,this.geometry);const h=this.geometry.subGeometries[0].lodLevels[0];this.instanceCount>0?y.drawIndexed(i,h.indexCount,this.instanceCount,h.indexStart,0,0):y.drawIndexed(i,h.indexCount,1,h.indexStart,0,0)}}}destroy(e){this._sortWorker&&(this._sortWorker.terminate(),this._sortWorker=null),this.splatColor&&(this.splatColor.destroy(e),this.splatColor=null),this.transformA&&(this.transformA.destroy(e),this.transformA=null),this.transformB&&(this.transformB.destroy(e),this.transformB=null),this.splatOrder&&(this.splatOrder.destroy(e),this.splatOrder=null),this._positions=null,this._worldPositions=null,this._orderData=null,this.texParams=null,this._mapping=null,super.destroy(e)}},c.GSplatRenderer=vg([Pt(c.GSplatRenderer,"GSplatRenderer")],c.GSplatRenderer);class sn{static maxVector=new g(Number.MAX_VALUE*.1,Number.MAX_VALUE*.1,Number.MAX_VALUE*.1);static minVector=this.maxVector.clone().multiplyScalar(-1);static genMeshMaxVector=g.ZERO.clone();static genMeshMinVector=g.ZERO.clone();static genMeshVectorList8=[new g,new g,new g,new g,new g,new g,new g,new g];static genGSplatBounds(e,t){t||=new xe(g.ZERO,g.ZERO),t.setFromMinMax(this.maxVector,this.minVector);let r=e.getComponent(c.GSplatRenderer);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 s=e.transform.worldMatrix,o=new g;for(let l=0;l<a;l++){const h=l*3;o.set(i[h+0],i[h+1],i[h+2]),s.transformPoint(o,o),t.expandByPoint(o)}return t.setFromMinMax(t.min,t.max),t}static genMeshBounds(e,t){let r=this.genMeshMinVector,i=this.genMeshMaxVector,a=this.genMeshVectorList8;t||=new xe(g.ZERO,g.ZERO),t.setFromMinMax(this.maxVector,this.minVector);let s=e.getComponents(c.MeshRenderer);for(const o of s)if(o&&o.geometry){let l=o.object3D.transform.worldMatrix;r.copy(o.geometry.bounds.min),i.copy(o.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),s=this.genMeshVectorList8;r||=new xe(g.ZERO,g.ZERO),r.setFromMinMax(this.maxVector,this.minVector),s[0].set(i.x,i.y,i.z),s[1].set(i.x,i.y,a.z),s[2].set(i.x,a.y,i.z),s[3].set(i.x,a.y,a.z),s[4].set(a.x,i.y,i.z),s[5].set(a.x,i.y,a.z),s[6].set(a.x,a.y,i.z),s[7].set(a.x,a.y,a.z);for(const o of s)e.transformPoint(o,o),r.expandByPoint(o);return a.copyFrom(r.max),i.copyFrom(r.min),r.setFromMinMax(i,a),r}}class Sh extends wr{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=Ts().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 xe,this._boundWorld=this._bound.clone(),this._isBoundChange=!0),this._isBoundChange&&(sn.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()):_e.waitStartComponent.forEach((e,t)=>{for(;e.length>0;){const r=e.shift();r.__start(),_e.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 Cg=Object.getOwnPropertyDescriptor,Sg=(n,e,t,r)=>{for(var i=r>1?void 0:r?Cg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.Object3D=class extends Sh{_isScene3D;prefabRef;serializeTag;constructor(){super(),this.transform=this.addComponent(Qt),this.transform.eventDispatcher.addEventListener(Qt.LOCAL_ONCHANGE,this.onTransformLocalChange,this)}get isScene3D(){return this._isScene3D}forChild(e){this.entityChildren.forEach(t=>{e(t),t.forChild(e)})}addComponent(e,t){if(!this.components.has(e)){let r=new e;return r.object3D=this,this.components.set(e,r),r.__init(t),_e.appendWaitStart(r),r}return this.components.get(e)}getOrAddComponent(e){let t=this.components.get(e);return t||(t=this.addComponent(e)),t}removeComponent(e){if(this.components.has(e)){let t=this.components.get(e);_e.removeWaitStart(this,t),this.components.delete(e),t.__stop(),t.beforeDestroy(),t.destroy()}}hasComponent(e){return this.components.has(e)}getComponent(e){return this.components.get(e)}getComponentFromParent(e){if(!this.parent)return null;let t=this.parent.object3D.getComponent(e);return t||this.parent.object3D.getComponentFromParent(e)}getComponentsInChild(e){let t=[],r=this.components.get(e);r&&t.push(r);for(let i=0;i<this.entityChildren.length;i++){let s=this.entityChildren[i].getComponentsInChild(e);t.push(...s)}return t}getComponents(e,t,r){t||=[];let i=this.getComponent(e);i&&(i.enable||r)&&t.push(i);for(let a=0,s=this.entityChildren.length;a<s;a++){let o=this.entityChildren[a];o&&o instanceof c.Object3D&&o.getComponents(e,t,r)}return t}getComponentsExt(e,t,r){t||=[];let i=this.components.get(e);if(i&&(i.enable||r))t.push(i);else for(const a of this.entityChildren)a instanceof c.Object3D&&a.getComponentsExt(e,t,r);return t}getComponentsByProperty(e,t,r=!0,i,a){i||=[];let s;for(const o of this.components.values())o&&(o.enable||a)&&o[e]===t&&(i.push(o),s=!0);if(!(s&&r))for(const o of this.entityChildren)o instanceof c.Object3D&&o.getComponentsByProperty(e,t,r,i,a);return i}clone(){return this.instantiate()}instantiate(){let e=new c.Object3D;return e.name=this.name,e.serializeTag=this.serializeTag,e.prefabRef=this.prefabRef,this.entityChildren.forEach((t,r)=>{let i=t.instantiate();e.addChild(i)}),this.components.forEach((t,r)=>{t.cloneTo(e)}),e}get localPosition(){return this.transform.localPosition}set localPosition(e){this.transform.localPosition=e}get localRotation(){return this.transform.localRotation}set localRotation(e){this.transform.localRotation=e}get localScale(){return this.transform.localScale}set localScale(e){this.transform.localScale=e}get localQuaternion(){return this.transform.localRotQuat}set localQuaternion(e){this.transform.localRotQuat=e}notifyChange(){this.transform.notifyChange()}get parent(){return this.transform.parent}get parentObject(){return this.transform.parent.object3D}set x(e){this.transform.x=e}get x(){return this.transform.x}set y(e){this.transform.y=e}get y(){return this.transform.y}set z(e){this.transform.z=e}get z(){return this.transform.z}set scaleX(e){this.transform.scaleX=e}get scaleX(){return this.transform.scaleX}set scaleY(e){this.transform.scaleY=e}get scaleY(){return this.transform.scaleY}set scaleZ(e){this.transform.scaleZ=e}get scaleZ(){return this.transform.scaleZ}set rotationX(e){this.transform.rotationX=e}get rotationX(){return this.transform.rotationX}set rotationY(e){this.transform.rotationY=e}get rotationY(){return this.transform.rotationY}set rotationZ(e){this.transform.rotationZ=e}get rotationZ(){return this.transform.rotationZ}fixedUpdate(){}lateUpdate(){}traverse(e){e(this);for(let t=0,r=this.entityChildren.length;t<r;t++){let i=this.entityChildren[t];i instanceof c.Object3D&&i.traverse(e)}}destroy(e){this.transform.eventDispatcher.removeEventListener(Qt.LOCAL_ONCHANGE,this.onTransformLocalChange,this),super.destroy(e)}},c.Object3D=Sg([_g],c.Object3D);function _g(n,e){return class extends c.Object3D{set active(t){this.transform.enable=t>0}get active(){return this.transform.enable?1:0}get materialColor(){return this.getComponent(c.MeshRenderer)?.material?.shader.getDefaultColorShader().baseColor}set materialColor(t){let r=this.getComponent(c.MeshRenderer)?.material;r&&(r.shader.getDefaultColorShader().baseColor=t)}notifyMaterialColorChange(t,r){this.getComponent(c.MeshRenderer).materials?.[t]?.shader.getDefaultColorShader().uniforms[r].onChange()}}}class je{static createCamera3DObject(e,t){return this.createCamera3D(null,e,t)}static createCamera3D(e,t,r){return e||=new c.Object3D,t&&t.addChild(e),r&&(e.name=r),e.getOrAddComponent(Oi)}static UnProjection(e,t,r=1,i){let a=new g(e,t,0),s=1,o=g.HELP_0,l=I.canvas.offsetLeft,h=I.canvas.offsetTop,u=I.canvas.clientWidth,f=I.canvas.clientHeight;o.x=((a.x-l)*s/u-.5)*2,o.y=-((a.y-h)*s/f-.5)*2,o.z=r;let d=new g(0,0,0),m=E.helpMatrix2;m.copyFrom(i.projectionMatrix),m.invert();let p=E.helpMatrix;return p.identity(),p.multiply(m),p.multiply(i.transform.worldMatrix),p.perspectiveMultiplyPoint3(o,d),d}static Projection(e,t,r){let i=r||new g(0,0,0),a=E.helpMatrix;a.copyFrom(t.viewMatrix),a.multiply(t.projectionMatrix),a.perspectiveMultiplyPoint3(e,i);let s=I.canvas.clientWidth/2,o=I.canvas.clientHeight/2;return i.x=i.x*s+s,i.y=o-i.y*o,i}static UnProjection2(e,t,r,i,a){let s=a||new g(0,0,0),o=E.helpMatrix;o.copyFrom(i.pvMatrixInv);let l=I.canvas.clientWidth/2,h=I.canvas.clientHeight/2;return s.x=(e-l)/l,s.y=(h-t)/h,s.z=r,o.perspectiveMultiplyPoint3(s,s),s}}class It{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==Ye.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==Ye.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==Ye.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==Ye.DirectionLight){let r=this.directionLightList.get(e);return r||(r=[],this.directionLightList.set(e,r)),r}else if(t==Ye.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==Ye.DirectionLight){let r=this.directionLightList.get(t);if(r||(r=[],this.directionLightList.set(t,r)),!e.shadowCamera){e.shadowCamera=je.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==Ye.PointLight||e.lightData.lightType==Ye.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==Ye.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==Ye.PointLight||e.lightData.lightType==Ye.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=It.directionLightList.get(e.scene),i=It.pointLightList.get(e.scene),a=0,s=0,o=0,l=0;if(t.fill(0),r){let u=0;for(let f=0;f<r.length;f++){const d=r[f];t[f]=d.lightData.index,d.lightData.castShadowIndex=u++}s=r.length}if(i){o=s;let u=0;for(let f=o;f<i.length;f++){const d=i[f];t[f]=d.lightData.index,d.lightData.castShadowIndex=u++}l=o+i.length}oe.getAllCameraGroup().forEach(u=>{u.dirShadowStart=a,u.dirShadowEnd=s,u.pointShadowStart=o,u.pointShadowEnd=l,u.shadowLights.set(new Float32Array(t))})}}class nn{uuid;usage;globalBindGroup;uniformGPUBuffer;matrixBindGroup;uniformByteLength;matrixesByteLength;shadowMatrixRaw=new Float32Array(128);csmMatrixRaw=new Float32Array(Wt.Cascades*16);csmShadowBias=new Float32Array(4);shadowLights=new Float32Array(16);dirShadowStart=0;dirShadowEnd=0;pointShadowStart=0;pointShadowEnd=0;constructor(e){this.uuid=bt(),this.usage=GPUBufferUsage.UNIFORM|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,this.uniformGPUBuffer=new lt(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=E.block*4*E.maxCount,this.globalBindGroup=I.device.createBindGroup({label:"global_bindGroupLayout",layout:Hs.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=It.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=A.setting.shadow.shadowSize;if(Wt.Cascades>1&&e.enableCSM&&t[0])for(let l=0;l<Wt.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=A.setting.reflectionSetting,a=W.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",Ze.testObj.testValue2),this.uniformGPUBuffer.setFloat("test3",Ze.testObj.testValue3),this.uniformGPUBuffer.setFloat("test4",Ze.testObj.testValue4),this.uniformGPUBuffer.setVector3("CameraPos",e.transform.worldPosition),this.uniformGPUBuffer.setFloat("frame",be.frame),this.uniformGPUBuffer.setFloat32Array("SH",e.sh),this.uniformGPUBuffer.setFloat("time",be.time),this.uniformGPUBuffer.setFloat("delta",be.delta),this.uniformGPUBuffer.setFloat("shadowBias",e.getShadowBias(r)),this.uniformGPUBuffer.setFloat("skyExposure",A.setting.sky.skyExposure),this.uniformGPUBuffer.setFloat("renderPassState",A.setting.render.renderPassState),this.uniformGPUBuffer.setFloat("quadScale",A.setting.render.quadScale),this.uniformGPUBuffer.setFloat("hdrExposure",A.setting.render.hdrExposure),this.uniformGPUBuffer.setInt32("renderState_left",A.setting.render.renderState_left),this.uniformGPUBuffer.setInt32("renderState_right",A.setting.render.renderState_right),this.uniformGPUBuffer.setFloat("renderState_split",A.setting.render.renderState_split);let s=A.inputSystem.mouseX*I.pixelRatio,o=A.inputSystem.mouseY*I.pixelRatio;this.uniformGPUBuffer.setFloat("mouseX",s),this.uniformGPUBuffer.setFloat("mouseY",o),this.uniformGPUBuffer.setFloat("windowWidth",I.windowWidth),this.uniformGPUBuffer.setFloat("windowHeight",I.windowHeight),this.uniformGPUBuffer.setFloat("near",e.near),this.uniformGPUBuffer.setFloat("far",e.far),this.uniformGPUBuffer.setFloat("pointShadowBias",A.setting.shadow.pointShadowBias),this.uniformGPUBuffer.setFloat("shadowMapSize",r),this.uniformGPUBuffer.setFloat("shadowSoft",A.setting.shadow.shadowSoft),this.uniformGPUBuffer.setFloat("enableCSM",e.enableCSM?1:0),this.uniformGPUBuffer.setFloat("csmMargin",A.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",be.frame),this.uniformGPUBuffer.setFloat32Array("SH",e.sh),this.uniformGPUBuffer.setFloat("time",be.time),this.uniformGPUBuffer.setFloat("delta",be.delta),this.uniformGPUBuffer.setFloat("shadowBias",A.setting.shadow.shadowBias),this.uniformGPUBuffer.setFloat("skyExposure",A.setting.sky.skyExposure),this.uniformGPUBuffer.setFloat("renderPassState",A.setting.render.renderPassState),this.uniformGPUBuffer.setFloat("quadScale",A.setting.render.quadScale),this.uniformGPUBuffer.setFloat("hdrExposure",A.setting.render.hdrExposure),this.uniformGPUBuffer.setInt32("renderState_left",A.setting.render.renderState_left),this.uniformGPUBuffer.setInt32("renderState_right",A.setting.render.renderState_right),this.uniformGPUBuffer.setFloat("renderState_split",A.setting.render.renderState_split);let t=A.inputSystem.mouseX*I.pixelRatio,r=A.inputSystem.mouseY*I.pixelRatio;this.uniformGPUBuffer.setFloat("mouseX",t),this.uniformGPUBuffer.setFloat("mouseY",r),this.uniformGPUBuffer.setFloat("windowWidth",I.windowWidth),this.uniformGPUBuffer.setFloat("windowHeight",I.windowHeight),this.uniformGPUBuffer.setFloat("near",e.near),this.uniformGPUBuffer.setFloat("far",e.far),this.uniformGPUBuffer.setFloat("pointShadowBias",A.setting.shadow.pointShadowBias),this.uniformGPUBuffer.setFloat("shadowMapSize",A.setting.shadow.shadowSize),this.uniformGPUBuffer.setFloat("shadowSoft",A.setting.shadow.shadowSoft),this.uniformGPUBuffer.setFloat("enableCSM",0),this.uniformGPUBuffer.setFloat("csmMargin",A.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 _h{setting;probesBufferData;probesBuffer;isVolumeFrameChange=!0;randomOrientation;startPosition=new g;isVolumeChange=!0;irradianceVolumeBuffer;directionDistance=20;randomSeedCount=3;useRandomIndex=0;centerDirection=new g(0,0,this.directionDistance).normalize(1);arroundPositions=[];updateOrientation(){return this.useRandomIndex++,this.useRandomIndex>=this.arroundPositions.length&&(this.useRandomIndex=0),E.fromToRotation(this.centerDirection,this.arroundPositions[this.useRandomIndex],this.randomOrientation),this.randomOrientation}init(e){this.setting=e,this.randomOrientation=new E(!1),this.randomOrientation.identity(),this.irradianceVolumeBuffer=new lt(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 g(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,s=this.setting.probeSpace;return i=i||new g,i.x=e*s-s*(a.probeXCount-1)*.5+a.offsetX,i.y=t*s-s*(a.probeYCount-1)*.5+a.offsetY,i.z=r*s-s*(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(ja.lightSize*A.setting.light.maxLight,GPUBufferUsage.COPY_SRC),this.irradianceVolume=new _h,this.irradianceVolume.init(A.setting.gi);for(let e=0;e<A.setting.light.maxLight;e++){let t=this.storageGPUBuffer.memory.allocation_node(ja.lightSize*4);this._lightList.push(t)}this.storageGPUBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE}update(e){this.storageGPUBuffer.clean();let t=W.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 Fh{storageGPUBuffer;reflectionMap;sourceReflectionMap;count;constructor(){this.storageGPUBuffer=new Be(768)}update(e){this.storageGPUBuffer.clean();let t=W.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 yh extends Dr{size;constructor(e,t=0,r){super(),this.bufferType=$t.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=I.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 s=new Float32Array(r.buffer,r.byteOffset,t);new Float32Array(a.getMappedRange(0,t*4)).set(s),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 bh{uuid;index;usage;groupBufferSize;matrixBufferDst;constructor(){this.uuid=bt(),this.groupBufferSize=0,this.usage=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,this.cacheWorldMatrix()}cacheWorldMatrix(){this.groupBufferSize=E.maxCount*E.blockBytes,this.matrixBufferDst=new yh(this.groupBufferSize/4),this.matrixBufferDst.visibility=GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.matrixBufferDst.buffer.label=this.groupBufferSize.toString()}writeBuffer(e){const t=E.dynamicMatrixBytes;this.matrixBufferDst.mapAsyncWrite(t,e)}}class oe{static _cameraBindGroups;static _lightEntriesMap;static _reflectionEntriesMap;static modelMatrixBindGroup;static init(){this.modelMatrixBindGroup=new bh,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 nn(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 nn(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 Fh,this._reflectionEntriesMap.set(e,t)),this._reflectionEntriesMap.get(e)}}class y{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(y.lastShader!=t)y.lastShader=t;else return!1;y.lastPipeline!=t.pipeline&&(y.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=oe.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 s=i[a];e.setVertexBuffer(a,r.buffer,s.offset,s.size)}}}static cleanCache(){this.lastGeometry=null,this.lastPipeline=null,this.lastShader=null}static createPipeline(e){return Ze.countStart("GPUContext","pipeline"),I.device.createRenderPipeline(e)}static beginCommandEncoder(){return Ze.countStart("GPUContext","beginCommandEncoder"),this.LastCommand&&I.device.queue.submit([this.LastCommand.finish()]),this.LastCommand=I.device.createCommandEncoder(),this.LastCommand}static endCommandEncoder(e){this.LastCommand==e&&(I.device.queue.submit([this.LastCommand.finish()]),this.LastCommand=null,Ze.countStart("GPUContext","endCommandEncoder"))}static recordBundleEncoder(e){return I.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=I.context.getCurrentTexture().createView()):r.view=I.context.getCurrentTexture().createView()),e.beginRenderPass(t.renderPassDescriptor)}}static drawIndexed(e,t,r,i,a,s){e.drawIndexed(t,r,i,a,s),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 Rh{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 Qh{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 Rh,this._normalAttrDataGroup=new Rh}initMorphTarget(e){this._collectMorphTargetData=this.collectMorphTargetList(e),this._computeShader&&this._computeShader.destroy();let t=Nt.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,y.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("."),f=u[u.length-1];this._blendTarget[f]=d=>this.updateInfluence(h,d)}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 s=this.collectAttribute("a_morphNormals_",e),o;if(s&&s.length>0){let l=0;o=new Float32Array(i*r*3);for(let h=0;h<r;h++){let u=s[h];o.set(u.data,l),l+=u.data.length}}return{mtCount:r,vCount:i,mergedPos:a,mergedNormal:o}}collectAttribute(e,t){let r=[];for(let i=0;i<this.MaxMorphTargetCount;i++){let a=e+i,s=t.getAttribute(a);if(s)r[i]=s;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 lt(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 xg=Object.defineProperty,Fg=Object.getOwnPropertyDescriptor,on=(n,e,t,r)=>{for(var i=r>1?void 0:r?Fg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=(r?s(e,t,i):s(i))||i);return r&&i&&xg(e,t,i),i};c.MeshRenderer=class extends kr{receiveShadow;morphData;constructor(){super()}onEnable(){super.onEnable()}onDisable(){super.onDisable()}cloneTo(e){e.addComponent(c.MeshRenderer).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this.receiveShadow=e.receiveShadow,this}get geometry(){return this._geometry}set geometry(e){if(super.geometry=e,e){let t=e.morphTargetDictionary!=null;t&&(this.morphData||=new Qh,this.morphData.morphTargetsRelative=e.morphTargetsRelative,this.morphData.initMorphTarget(e)),this.morphData&&(this.morphData.enable=t),this.morphData?.enable?this.addRendererMask(Ue.MorphTarget):this.removeRendererMask(Ue.MorphTarget),this.object3D.bound=this._geometry.bounds.clone()}else this.morphData&&(this.morphData.enable=!1),this.removeRendererMask(Ue.MorphTarget);this._readyPipeline||(this.initPipeline(),this._computes&&(this.onCompute=Za(this.onCompute,()=>{for(let t=0;t<this._computes.length;t++)this._computes[t].onUpdate()})))}get material(){return this._materials[0]}set material(e){this.materials=[e]}setMorphInfluence(e,t){if(this.morphData&&this.morphData.enable){let r=this._geometry.morphTargetDictionary[e];r>=0&&this.morphData.updateInfluence(r,t)}}setMorphInfluenceIndex(e,t){this.morphData&&this.morphData.enable&&e>=0&&this.morphData.updateInfluence(e,t)}onCompute(e,t){this.morphData&&this.morphData.enable&&this.morphData.computeMorphTarget(t)}nodeUpdate(e,t,r,i){if(this.morphData&&this.morphData.enable)for(let a=0;a<this.materials.length;a++){let o=this.materials[a].getPass(t);if(o)for(let l=0;l<o.length;l++)this.morphData.applyRenderShader(o[l])}super.nodeUpdate(e,t,r,i)}destroy(e){this.morphData&&(this.morphData.destroy(e),this.morphData=null),super.destroy(e)}},on([Ni],c.MeshRenderer.prototype,"geometry",1),on([Ni],c.MeshRenderer.prototype,"material",1),c.MeshRenderer=on([Pt(c.MeshRenderer,"MeshRenderer")],c.MeshRenderer);class mr{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 Ih{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]:A.res.redTexture}}class gt extends He{resolveTarget;sampleCount;autoResize;clear;constructor(e,t,r=X.rgba8unorm,i=!1,a,s=1,o=0,l=!0,h=!0){super(e,t,s),this.name=bt(),this.autoResize=h,this.useMipmap=i,this.sampleCount=o,this.format=r,this.numberLayer=s,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&&I.addEventListener(Yr.RESIZE,u=>{let{width:f,height:d}=u.data;this.resize(f,d),this._textureChange=!0},this)}resize(e,t){let r=I.device;this.gpuTexture&&(He.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=I.device.createSampler({}),this.gpuSampler_comparison=I.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=I.device.createSampler({}),this.gpuSampler_comparison=I.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=Vt.clamp_to_edge,this.addressModeV=Vt.clamp_to_edge,this.gpuSampler=r.createSampler(this)),this._textureChange=!0}create(e,t,r=!0){let i=I.device;const a=e*4;let s=new Float32Array(e*t*4);const o=i.createBuffer({size:s.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});i.queue.writeBuffer(o,0,s);const l=y.beginCommandEncoder();l.copyBufferToTexture({buffer:o,bytesPerRow:a},{texture:this.getGPUTexture()},{width:e,height:t,depthOrArrayLayers:1}),y.endCommandEncoder(l)}clone(){let e=new gt(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=I.device,t=I.windowWidth,r=I.windowHeight,i=new Float32Array(t*r*4);const a=e.createBuffer({size:i.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC});return y.beginCommandEncoder().copyTextureToBuffer({texture:this.getGPUTexture()},{buffer:a},[t,r]),a.getMappedRange(0,i.byteLength)}}class Qe{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 Qe;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 ne 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,s){let o=this.renderTargets,l=this.rtDescriptors;if(a){let u=new Qe;u.loadOp="clear",this._colorBufferTex=mt.createRTTexture(e+mr.colorBufferTex_NAME,t,r,X.rgba16float,!0),o.push(this._colorBufferTex),l.push(u)}this._compressGBufferTex=new gt(t,r,X.rgba32float,!1,void 0,1,0,!0,!0),o.push(this._compressGBufferTex),s?this.depthTexture=s:(this.depthTexture=new gt(t,r,X.depth24plus,!1,void 0,1,0,!0,!0),this.depthTexture.name=e+"_depthTexture");let h;h=new Qe,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 s;if(ne.gBufferMap.has(e))s=ne.gBufferMap.get(e);else{s=new ne;let o=I.presentationSize;s.createGBuffer(e,t==0?o[0]:t,r==0?o[1]:r,t!=0&&r!=0,i,a),ne.gBufferMap.set(e,s)}return s}static getGUIBufferFrame(){let e=this.getGBufferFrame(this.colorPass_GBuffer);return ne.getGBufferFrame(ne.gui_GBuffer,0,0,!0,e.depthTexture)}clone(){let e=new ne;return this.clone2Frame(e),e}}class Ee{static rendererPassState=new Map;static createRendererPassState(e,t=null){let r=Ee.rendererPassState.get(e);if(r||(r=new Ih,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,Ee.rendererPassState.set(e,r)),e&&e.renderTargets.length>0){r.renderTargets=e.renderTargets,r.rtTextureDescriptors=e.rtDescriptors,r.renderPassDescriptor=Ee.getRenderPassDescriptor(r),r.renderPassDescriptor.depthStencilAttachment&&(r.renderPassDescriptor.depthStencilAttachment.depthLoadOp=e.depthLoadOp),t=="load"&&e?.renderTargets[0]&&e.renderTargets[0].name.startsWith(ne.gui_GBuffer)&&(r.renderPassDescriptor.colorAttachments[0].loadOp="load"),r.depthLoadOp=e.depthLoadOp,r.renderBundleEncoderDescriptor=Ee.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(mr.colorBufferTex_NAME)!=-1&&(r.outColor=i)}}else r.renderPassDescriptor=Ee.getRenderPassDescriptor(r,t),r.renderBundleEncoderDescriptor=Ee.getRenderBundleDescriptor(r),r.renderTargetTextures=[{format:I.presentationFormat}],r.outColor=0;return r}static getRenderPassDescriptor(e,t=null){if(e.renderPassDescriptor)return e.renderPassDescriptor;I.device,I.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 s=e.renderTargets[a],o=e.rtTextureDescriptors[a];r.push({view:s.getGPUView(),resolveTarget:void 0,loadOp:o.loadOp,clearValue:o.clearValue,storeOp:o.storeOp})}}else if(!e.customSize){let a=I.canvasConfig&&I.canvasConfig.alpha?[1,1,1,0]:[0,0,0,1];e.isOutTarget==!0&&r.push({view:void 0,resolveTarget:void 0,loadOp:I.canvasConfig&&I.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;I.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 Wi extends Re{width;height;segmentW;segmentH;up;constructor(e,t,r=1,i=1,a=g.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,s=this.segmentW+1;(this.segmentH+1)*s,this.bounds=new xe(g.ZERO.clone(),new g(this.width,1,this.height)),i=this.segmentH*this.segmentW*6;let o=(this.segmentW+1)*(this.segmentH+1),l=new Float32Array(o*3),h=new Float32Array(o*3),u=new Float32Array(o*2),f;this.segmentW*this.segmentH*2*3>=Uint16Array.length?f=new Uint32Array(this.segmentW*this.segmentH*2*3):f=new Uint16Array(this.segmentW*this.segmentH*2*3),i=0;for(var m=0,p=0,U=0,B=0;B<=this.segmentH;++B)for(var v=0;v<=this.segmentW;++v){switch(t=(v/this.segmentW-.5)*this.width,r=(B/this.segmentH-.5)*this.height,e){case g.Y_AXIS:l[m++]=t,l[m++]=0,l[m++]=r,h[p++]=0,h[p++]=1,h[p++]=0;break;case g.Z_AXIS:l[m++]=t,l[m++]=-r,l[m++]=0,h[p++]=0,h[p++]=0,h[p++]=1;break;case g.X_AXIS:l[m++]=0,l[m++]=t,l[m++]=r,h[p++]=1,h[p++]=0,h[p++]=0;break;default:l[m++]=t,l[m++]=0,l[m++]=r,h[p++]=0,h[p++]=1,h[p++]=0;break}u[U++]=v/this.segmentW,u[U++]=B/this.segmentH,v!=this.segmentW&&B!=this.segmentH&&(a=v+B*s,f[i++]=a+1,f[i++]=a,f[i++]=a+s,f[i++]=a+1,f[i++]=a+s,f[i++]=a+s+1)}this.setIndices(f),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:f.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0})}}var yg=Object.getOwnPropertyDescriptor,bg=(n,e,t,r)=>{for(var i=r>1?void 0:r?yg(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.QuadShader=class extends at{constructor(e="QuadGlsl_vs",t="QuadGlsl_fs"){super();let r=new Ne(e,t);this.addRenderPass(r);let i=r.shaderState;r.blendMode=se.NONE,i.frontFace="cw",i.depthWriteEnabled=!1,i.depthCompare=$e.always,i.multisample=0,this.setTexture("baseMap",A.res.blackTexture),this.setUniformFloat("x",0),this.setUniformFloat("y",0),this.setUniformFloat("width",100),this.setUniformFloat("height",100)}},c.QuadShader=bg([Tr(c.QuadShader,"QuadShader")],c.QuadShader);class ln extends c.Object3D{width=128;height=128;quadRenderer;material;rendererPassState;quadShader;constructor(e="QuadGlsl_vs",t="QuadGlsl_fs",r,i=0,a=!1){super();let s=r?r.renderTargets:[];this.material=new ft,this.quadShader=new c.QuadShader(e,t),this.material.shader=this.quadShader,this.quadRenderer=this.addComponent(c.MeshRenderer),this.quadRenderer.material=this.material,this.quadRenderer.castGI=!1,this.quadRenderer.castShadow=!1,this.quadRenderer.drawType=a?2:0,this.quadRenderer.geometry=new Wi(100,100,1,1),this.quadRenderer.material=this.material,this.quadRenderer.__start(),this.quadRenderer._enable=!0,this.quadRenderer.onEnable(),this.rendererPassState=Ee.createRendererPassState(r,"load"),i>0&&(this.rendererPassState.multisample=this.quadShader.getDefaultColorShader().shaderState.multisample,this.rendererPassState.multiTexture=I.device.createTexture({size:{width:I.presentationSize[0],height:I.presentationSize[1]},sampleCount:i,format:s.length>0?s[0].format:I.presentationFormat,usage:GPUTextureUsage.RENDER_ATTACHMENT})),I.addEventListener(Yr.RESIZE,o=>{this.rendererPassState=Ee.createRendererPassState(r,"load"),i>0&&(this.rendererPassState.multisample=this.quadShader.getDefaultColorShader().shaderState.multisample,this.rendererPassState.multiTexture=I.device.createTexture({size:{width:I.presentationSize[0],height:I.presentationSize[1]},sampleCount:i,format:s.length>0?s[0].format:I.presentationFormat,usage:GPUTextureUsage.RENDER_ATTACHMENT}))},this)}renderTarget(e,t,r){let i=e.camera,a=y.beginRenderPass(r,t.rendererPassState);y.bindCamera(a,i),t.quadRenderer.nodeUpdate(e,H.COLOR,t.rendererPassState,null),t.quadRenderer.renderPass2(e,H.COLOR,t.rendererPassState,null,a),y.endPass(a)}renderToViewQuad(e,t,r,i){let a=e.camera;t.quadShader.setTexture("baseMap",i);let s=y.beginRenderPass(r,t.rendererPassState);y.bindCamera(s,a),t.quadRenderer.nodeUpdate(e,H.COLOR,t.rendererPassState,null),t.quadRenderer.renderPass2(e,H.COLOR,t.rendererPassState,null,s),y.endPass(s)}}class mt{static rtTextureMap;static rtViewQuad;static init(){this.rtTextureMap=new Map,this.rtViewQuad=new Map}static createRTTexture(e,t,r,i,a=!1,s=0){let o=this.rtTextureMap.get(e);return o||(e==mr.colorBufferTex_NAME?o=new gt(t,r,i,a,void 0,1,s,!1):o=new gt(t,r,i,a,void 0,1,s,!0),o.name=e,mt.rtTextureMap.set(e,o)),o}static createRTTextureArray(e,t,r,i,a=1,s=!1,o=0){let l=this.rtTextureMap.get(e);return l||(l=new gt(t,r,i,s,void 0,a,o),l.name=e,mt.rtTextureMap.set(e,l)),l}static createViewQuad(e,t,r,i,a=0){let s=new ze([i],[new Qe]),o=new ln(t,r,s,a);return mt.rtViewQuad.set(e,o),o}static getTexture(e){return this.rtTextureMap.get(e)}static CreateSplitTexture(e){let t=this.getTexture(mr.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(mr.colorBufferTex_NAME),r=this.getTexture(e+"_split");const i=y.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}),y.endCommandEncoder(i)}}class hn{command;encoder;rendererPassStates;rtFrame;constructor(e){this.rtFrame=e,this.rendererPassStates=[]}clean(){this.rendererPassStates.length=0,y.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=Ee.createRendererPassState(r,e);return this.rendererPassStates.push(i),i}else{this.rtFrame.depthLoadOp=t;let r=Ee.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=y.beginCommandEncoder(),this.command}endCommand(){y.endCommandEncoder(this.command),this.command=null}beginNewEncoder(){return this.encoder=y.beginRenderPass(this.command,this.rendererPassState),this.encoder}endEncoder(){y.endPass(this.encoder),this.encoder=null}}class pr extends wr{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=Ee.createRendererPassState(e);let t=e.clone();t.depthLoadOp="load";for(const r of t.rtDescriptors)r.loadOp="load";this.splitRendererPassState=Ee.createRendererPassState(t)}this.renderContext=new hn(e)}getRenderContext(e){return this._rtFrame=e,new hn(e)}setIrradiance(e,t){this.rendererPassState.irradianceBuffer=[e,t]}compute(e,t){}render(e,t,r,i=!1){y.cleanCache();let a=e.camera,s=e.scene;this.rendererPassState.camera3D=a;let o=W.instance.getRenderNodes(s,a),l=this.renderBundleOp(e,o,t,r),h=i?[]:this.renderBundleTr(e,o,t,r);{let u=y.beginCommandEncoder(),f=y.beginRenderPass(u,this.rendererPassState);l.length>0&&f.executeBundles(l),!i&&W.instance.sky&&(y.bindCamera(f,a),W.instance.sky.renderPass2(e,this._rendererType,this.rendererPassState,r,f)),this.drawRenderNodes(e,f,u,o.opaqueList,t),y.endPass(f),y.endCommandEncoder(u)}{let u=y.beginCommandEncoder(),f=y.beginRenderPass(u,this.rendererPassState);h.length>0&&f.executeBundles(h),i||(y.bindCamera(f,a),this.drawRenderNodes(e,f,u,o.transparentList,t)),y.endPass(f),y.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=W.instance.getOpRenderGroup(e.scene);if(a){let s=[];return a.renderGroup.forEach(o=>{if(o.bundleMap.has(this._rendererType))s.push(o.bundleMap.get(this._rendererType));else{let l=y.recordBundleEncoder(this.rendererPassState.renderBundleEncoderDescriptor);this.recordRenderBundleNode(e,l,o.renderNodes,i);let h=l.finish();o.bundleMap.set(this._rendererType,h),s.push(h)}}),s}return[]}renderBundleTr(e,t,r,i){let a=W.instance.getTrRenderGroup(e.scene);if(a){let s=[];return a.renderGroup.forEach(o=>{if(o.bundleMap.has(this._rendererType))s.push(o.bundleMap.get(this._rendererType));else{let l=y.recordBundleEncoder(this.rendererPassState.renderBundleEncoderDescriptor);this.recordRenderBundleNode(e,l,o.renderNodes,i);let h=l.finish();o.bundleMap.set(this._rendererType,h),s.push(h)}}),s}return[]}recordRenderBundleNode(e,t,r,i){y.bindCamera(t,e.camera),y.bindGeometryBuffer(t,r[0].geometry);for(let a=0;a<r.length;++a){let s=r[a];s.transform.worldMatrix.index,s.transform.enable&&s.recordRenderPass2(e,this._rendererType,this.rendererPassState,i,t)}}drawRenderNodes(e,t,r,i,a,s){y.bindCamera(t,e.camera);for(let o=A.setting.render.drawOpMin;o<Math.min(i.length,A.setting.render.drawOpMax);++o){let l=i[o];l.transform.enable&&l.enable&&l.renderPass2(e,this._rendererType,this.rendererPassState,s,t)}}}class Eh extends pr{constructor(){super(),this.passType=H.COLOR}render(e,t,r,i=!1){this.renderContext.clean();let a=e.scene,s=e.camera;oe.updateCameraGroup(s),this.rendererPassState.camera3D=s;let o=W.instance.getRenderNodes(a,s),l=this.renderBundleOp(e,o,t,r),h=i?[]:this.renderBundleTr(e,o,t,r);{this.renderContext.beginOpaqueRenderPass();let u=this.renderContext.encoder;l.length>0&&(W.instance.getOpRenderGroup(a),u.executeBundles(l)),!i&&W.instance.sky&&(y.bindCamera(u,s),W.instance.sky.preInit(this._rendererType)||W.instance.sky.nodeUpdate(e,this._rendererType,this.rendererPassState,r),W.instance.sky.renderPass2(e,this._rendererType,this.rendererPassState,r,u)),o.opaqueList&&(y.bindCamera(u,s),this.drawNodes(e,this.renderContext,o.opaqueList,t,r))}{let u=this.renderContext.encoder;h.length>0&&u.executeBundles(h),!i&&o.transparentList&&(y.bindCamera(u,s),this.drawNodes(e,this.renderContext,o.transparentList,t,r));let f=W.instance.getGraphicList();for(let d=0;d<f.length;d++){const m=f[d];m.nodeUpdate(e,this._rendererType,this.splitRendererPassState,r),m.renderPass2(e,this._rendererType,this.splitRendererPassState,r,u)}this.renderContext.endRenderPass(),Ze.end("ColorPass Draw Transparent")}}drawNodes(e,t,r,i,a){let s=W.instance.getRenderShaderCollect(e);if(s){for(const o of s){let l=o[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 o=A.setting.render.drawOpMin;o<Math.min(r.length,A.setting.render.drawOpMax);++o){let l=r[o];l.transform.enable&&l.enable&&(l.hasMask(Ue.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 un{frustumCullingList;zVisibleList;_renderList;static enable=!0;constructor(){this._renderList=new Map}occlusionRenderNodeTest(e){return A.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 Ji extends Dr{constructor(e,t){super(),this.bufferType=$t.ComputeGPUBuffer,this.createBuffer(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST,e,t,"ComputeGPUBuffer")}}class wh{clusterBuffer;lightAssignBuffer;assignTableBuffer;clustersUniformBuffer;constructor(e,t){this.clusterBuffer=new Ji(e*2*4),this.clustersUniformBuffer=new lt(10),this.clustersUniformBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.lightAssignBuffer=new Ji(e*t),this.lightAssignBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,this.assignTableBuffer=new Ji(e*4),this.assignTableBuffer.visibility=GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE}update(e,t,r,i,a,s,o,l,h,u){this.clustersUniformBuffer.setFloat("clusterTileX",i),this.clustersUniformBuffer.setFloat("clusterTileY",a),this.clustersUniformBuffer.setFloat("clusterTileZ",s),this.clustersUniformBuffer.setFloat("numLights",o),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 pt{static clusterTileX=16;static clusterTileY=16;static clusterTileZ=32}let Th=`
5996
5996
  #include "GlobalUniform"
5997
5997
 
5998
5998
  struct ClusterBox{
@@ -7728,7 +7728,7 @@ $1\r
7728
7728
  `;class Zu{compute;constructor(){this.compute=new ue(Ju)}generateBRDFLUTTexture(){let e=new pe(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=y.beginCommandEncoder();return y.computeCommand(t,[this.compute]),y.endCommandEncoder(t),e}}class Zi{id;guiTexture;uvRec=new K(0,0,1,1);uvBorder=new K(0,0,0,0);offsetSize=new K(0,0,4,4);borderSize=new K(0,0,0,0);trimSize=new j;isSliced=!1;height=4;width=4;xadvance=0;xoffset=0;yoffset=0;constructor(e){this.guiTexture=e||A.res.defaultGUITexture}}class ii{static _maxUid=-1;_staticId=-1;dynamicId=-1;texture;width=1;height=1;get staticId(){return this._staticId}constructor(e){e||=A.res.whiteTexture,e.addressModeU="clamp-to-edge",e.addressModeV="clamp-to-edge",this.texture=e,ii._maxUid++,this._staticId=ii._maxUid,this.init()}init(){this.dynamicId=-1,this.width=this.texture.width,this.height=this.texture.height}}class tm{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 Yi=new tm;class Yu{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 Xu{id=0;file=""}class Hu{id=-1;x=0;y=0;width=0;height=0;xoffset=0;yoffset=0;xadvance=0;page=0;chnl=0}class Gr 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 Zi;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),Yi.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 Yu;r.trim().split(t).forEach((a,s)=>{if(s<2)Gr.readLineProperty(a,i);else if(s<i.pages+2){let o=new Xu;Gr.readLineProperty(a,o),i.fontPage.push(o)}else if(s<i.pages+3)Gr.readLineProperty(a,i);else if(i.count>0){let o=new Hu;Gr.readLineProperty(a,o),i.fontChar[o.id]=o,i.count--}}),r="",this.data=i,await this.loadFontTextures()}getNewLine(e){return e.indexOf(`\r
7729
7729
  `)!=-1?`\r
7730
7730
  `:e.indexOf("\r")!=-1?"\r":`
7731
- `}async loadFontTextures(){let e=[],t=this.data;for(const r of t.fontPage){let i=this.baseUrl+r.file;await A.res.loadTexture(i,null,!0);let a=A.res.getTexture(i),s=new ii(a);e.push(s)}Gr.parseSprite(e,t),t.fontChar[" "]||Gr.insertSpaceChar(t,e[0])}static insertSpaceChar(e,t){let r=new Zi,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),Yi.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 s=a[0],o=a[1];Object.prototype.hasOwnProperty.call(t,s)&&(o.indexOf('"')==-1?t[s]=parseFloat(a[1]):t[s]=o.replace('"',"").replace('"',""))}})}}function rm(n,e){let t=new Zi;return t.id=n,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 ii(e),t.uvRec.set(0,0,1,1),e.isVideoTexture||(e.flipY=!0),t}function ju(n,e,t){let r=new Zi;r.guiTexture=n,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/n.width,a=1/n.height;r.uvRec.set(r.uvRec.x*i,r.uvRec.y*a,r.uvRec.z*i,r.uvRec.w*a);let s=.1;return t.border.x<=s&&t.border.y<=s&&t.border.z<=s&&t.border.x<=s?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 Ku{_spriteMap=new Map;_spriteList=[];textureSize=new j;name;constructor(e){this.textureSize.set(e.x,e.y)}setTexture(e,t,r){let i=ju(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 qu 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 A.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 Ku(this._json.size),t=new ii(this._texture),r=this._json.atlas;for(const i in r)e.setTexture(t,i,r[i]);A.res.addAtlas(this.baseUrl,e),this.data=e}}var Lt=Uint8Array,Xi=Uint16Array,im=Int32Array,$u=new Lt([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]),ec=new Lt([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]),am=new Lt([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),tc=function(n,e){for(var t=new Xi(31),r=0;r<31;++r)t[r]=e+=1<<n[r-1];for(var i=new im(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}},rc=tc($u,2),ic=rc.b,sm=rc.r;ic[28]=258,sm[258]=28;for(var nm=tc(ec,0),om=nm.b,Nn=new Xi(32768),we=0;we<32768;++we){var ai=(we&43690)>>1|(we&21845)<<1;ai=(ai&52428)>>2|(ai&13107)<<2,ai=(ai&61680)>>4|(ai&3855)<<4,Nn[we]=((ai&65280)>>8|(ai&255)<<8)>>1}for(var va=(function(n,e,t){for(var r=n.length,i=0,a=new Xi(e);i<r;++i)n[i]&&++a[n[i]-1];var s=new Xi(e);for(i=1;i<e;++i)s[i]=s[i-1]+a[i-1]<<1;var o;if(t){o=new Xi(1<<e);var l=15-e;for(i=0;i<r;++i)if(n[i])for(var h=i<<4|n[i],u=e-n[i],f=s[n[i]-1]++<<u,d=f|(1<<u)-1;f<=d;++f)o[Nn[f]>>l]=h}else for(o=new Xi(r),i=0;i<r;++i)n[i]&&(o[i]=Nn[s[n[i]-1]++]>>15-n[i]);return o}),Ca=new Lt(288),we=0;we<144;++we)Ca[we]=8;for(var we=144;we<256;++we)Ca[we]=9;for(var we=256;we<280;++we)Ca[we]=7;for(var we=280;we<288;++we)Ca[we]=8;for(var ac=new Lt(32),we=0;we<32;++we)ac[we]=5;var lm=va(Ca,9,1),hm=va(ac,5,1),Vn=function(n){for(var e=n[0],t=1;t<n.length;++t)n[t]>e&&(e=n[t]);return e},or=function(n,e,t){var r=e/8|0;return(n[r]|n[r+1]<<8)>>(e&7)&t},kn=function(n,e){var t=e/8|0;return(n[t]|n[t+1]<<8|n[t+2]<<16)>>(e&7)},um=function(n){return(n+7)/8|0},Ln=function(n,e,t){return(e==null||e<0)&&(e=0),(t==null||t>n.length)&&(t=n.length),new Lt(n.subarray(e,t))},cm=["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"],Xt=function(n,e,t){var r=new Error(e||cm[n]);if(r.code=n,Error.captureStackTrace&&Error.captureStackTrace(r,Xt),!t)throw r;return r},fm=function(n,e,t,r){var i=n.length,a=r?r.length:0;if(!i||e.f&&!e.l)return t||new Lt(0);var s=!t,o=s||e.i!=2,l=e.i;s&&(t=new Lt(i*3));var h=function(Tt){var Dt=t.length;if(Tt>Dt){var Gt=new Lt(Math.max(Dt*2,Tt));Gt.set(t),t=Gt}},u=e.f||0,f=e.p||0,d=e.b||0,m=e.l,p=e.d,U=e.m,B=e.n,v=i*8;do{if(!m){u=or(n,f,1);var C=or(n,f+1,3);if(f+=3,C)if(C==1)m=lm,p=hm,U=9,B=5;else if(C==2){var b=or(n,f,31)+257,R=or(n,f+10,15)+4,w=b+or(n,f+5,31)+1;f+=14;for(var Q=new Lt(w),T=new Lt(19),N=0;N<R;++N)T[am[N]]=or(n,f+N*3,7);f+=R*3;for(var G=Vn(T),Z=(1<<G)-1,$=va(T,G,1),N=0;N<w;){var he=$[or(n,f,Z)];f+=he&15;var _=he>>4;if(_<16)Q[N++]=_;else{var ee=0,fe=0;for(_==16?(fe=3+or(n,f,3),f+=2,ee=Q[N-1]):_==17?(fe=3+or(n,f,7),f+=3):_==18&&(fe=11+or(n,f,127),f+=7);fe--;)Q[N++]=ee}}var ve=Q.subarray(0,b),te=Q.subarray(b);U=Vn(ve),B=Vn(te),m=va(ve,U,1),p=va(te,B,1)}else Xt(1);else{var _=um(f)+4,F=n[_-4]|n[_-3]<<8,x=_+F;if(x>i){l&&Xt(0);break}o&&h(d+F),t.set(n.subarray(_,x),d),e.b=d+=F,e.p=f=x*8,e.f=u;continue}if(f>v){l&&Xt(0);break}}o&&h(d+131072);for(var q=(1<<U)-1,ae=(1<<B)-1,Ae=f;;Ae=f){var ee=m[kn(n,f)&q],Ce=ee>>4;if(f+=ee&15,f>v){l&&Xt(0);break}if(ee||Xt(2),Ce<256)t[d++]=Ce;else if(Ce==256){Ae=f,m=null;break}else{var ye=Ce-254;if(Ce>264){var N=Ce-257,Me=$u[N];ye=or(n,f,(1<<Me)-1)+ic[N],f+=Me}var Se=p[kn(n,f)&ae],Pe=Se>>4;Se||Xt(3),f+=Se&15;var te=om[Pe];if(Pe>3){var Me=ec[Pe];te+=kn(n,f)&(1<<Me)-1,f+=Me}if(f>v){l&&Xt(0);break}o&&h(d+131072);var St=d+ye;if(d<te){var _r=a-te,xr=Math.min(te,St);for(_r+d<0&&Xt(3);d<xr;++d)t[d]=r[_r+d]}for(;d<St;++d)t[d]=t[d-te]}}e.l=m,e.p=Ae,e.b=d,e.f=u,m&&(u=1,e.m=U,e.d=p,e.n=B)}while(!u);return d!=t.length&&s?Ln(t,0,d):t.subarray(0,d)},dm=new Lt(0),Ur=function(n,e){return n[e]|n[e+1]<<8},lr=function(n,e){return(n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24)>>>0},On=function(n,e){return lr(n,e)+lr(n,e+4)*4294967296};function gm(n,e){return fm(n,{i:2},e&&e.out,e&&e.dictionary)}var Gn=typeof TextDecoder<"u"&&new TextDecoder,mm=0;try{Gn.decode(dm,{stream:!0}),mm=1}catch{}var pm=function(n){for(var e="",t=0;;){var r=n[t++],i=(r>127)+(r>223)+(r>239);if(t+i>n.length)return{s:e,r:Ln(n,t-1)};i?i==3?(r=((r&15)<<18|(n[t++]&63)<<12|(n[t++]&63)<<6|n[t++]&63)-65536,e+=String.fromCharCode(55296|r>>10,56320|r&1023)):i&1?e+=String.fromCharCode((r&31)<<6|n[t++]&63):e+=String.fromCharCode((r&15)<<12|(n[t++]&63)<<6|n[t++]&63):e+=String.fromCharCode(r)}};function sc(n,e){if(e){for(var t="",r=0;r<n.length;r+=16384)t+=String.fromCharCode.apply(null,n.subarray(r,r+16384));return t}else{if(Gn)return Gn.decode(n);var i=pm(n),a=i.s,t=i.r;return t.length&&Xt(8),a}}var Am=function(n,e){return e+30+Ur(n,e+26)+Ur(n,e+28)},Um=function(n,e,t){var r=Ur(n,e+28),i=sc(n.subarray(e+46,e+46+r),!(Ur(n,e+8)&2048)),a=e+46+r,s=lr(n,e+20),o=t&&s==4294967295?Bm(n,a):[s,lr(n,e+24),lr(n,e+42)],l=o[0],h=o[1],u=o[2];return[Ur(n,e+10),l,h,i,a+Ur(n,e+30)+Ur(n,e+32),u]},Bm=function(n,e){for(;Ur(n,e)!=1;e+=4+Ur(n,e+2));return[On(n,e+12),On(n,e+4),On(n,e+20)]};function vm(n,e){for(var t={},r=n.length-22;lr(n,r)!=101010256;--r)(!r||n.length-r>65558)&&Xt(13);var i=Ur(n,r+8);if(!i)return{};var a=lr(n,r+16),s=a==4294967295||i==65535;if(s){var o=lr(n,r-12);s=lr(n,o)==101075792,s&&(i=lr(n,o+32),a=lr(n,o+48))}for(var l=0;l<i;++l){var h=Um(n,a,s),u=h[0],f=h[1],d=h[2],m=h[3],p=h[4],U=h[5],B=Am(n,U);a=p,u?u==8?t[m]=gm(n.subarray(B,B+f),{out:new Lt(d)}):Xt(14,"unknown compression type "+u):t[m]=Ln(n,B,B+f)}return t}class Bt extends ft{constructor(){super(),this.shader=new c.UnLitShader,this.baseMap=A.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 Ci extends Re{shape_vertices=[];shape_indices=[];radius;widthSegments;heightSegments;phiStart;phiLength;thetaStart;thetaLength;constructor(e,t,r,i,a,s,o){super(),this.radius=e,this.widthSegments=t,this.heightSegments=r,this.phiStart=i,this.phiLength=a,this.thetaStart=s,this.thetaLength=o,this.buildGeometry()}buildGeometry(){var e,t,r=0;let i=this.heightSegments,a=this.widthSegments,s=this.radius;var o=(i+1)*(a+1);let l=new Float32Array(o*3),h=new Float32Array(o*3),u=new Float32Array(o*2),f=new Uint16Array(a*i*2*3),d=0,m=0,p=0;for(t=0;t<=i;++t){var U=Math.PI*t/i,B=s*Math.cos(U),v=s*Math.sin(U);for(e=0;e<=a;++e){var C=2*Math.PI*e/a,_=v*Math.cos(C),F=v*Math.sin(C),x=1/Math.sqrt(_*_+B*B+F*F);if(l[d++]=_,l[d++]=B,l[d++]=F,h[m++]=_*x,h[m++]=B*x,h[m++]=F*x,u[p++]=e/a,u[p++]=t/i,e>0&&t>0){var b=(a+1)*t+e,R=(a+1)*t+e-1,w=(a+1)*(t-1)+e-1,Q=(a+1)*(t-1)+e;t==i?(f[r++]=b,f[r++]=w,f[r++]=Q):t==1?(f[r++]=b,f[r++]=R,f[r++]=w):(f[r++]=b,f[r++]=R,f[r++]=w,f[r++]=b,f[r++]=w,f[r++]=Q)}}}this.setIndices(f),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:f.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0}),this.bounds=new xe(g.ZERO,new g(this.radius*2,this.radius*2,this.radius*2))}}class Sa extends c.Object3D{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 g(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),Sa.register3DRepresentation)this.marker=Sa.register3DRepresentation(this),this.marker&&this.addChild(this.marker);else{this.marker=new c.Object3D;const e=this.marker.addComponent(c.MeshRenderer);e.geometry=new Ci(.1,32,16),e.material=new Bt,e.material.baseColor=this.positionValid?new k(0,1,0,1):new k(1,0,0,1),this.addChild(this.marker),this.marker.name="WayPoint3DMarker"}}}class _a extends c.Object3D{static register3DRepresentation=null;line;constructor(e){super(),this.parseWayLineFile(e),this.setup3DRepresentation()}parseWayLineFile(e){for(const t of e.Folder.Placemark){const r=new Sa(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),_a.register3DRepresentation?(this.line=_a.register3DRepresentation(this),this.line&&this.addChild(this.line)):(this.line=this.createMultiLine(this.entityChildren.map(e=>e.localPosition),new k(1,1,1,1)),this.addChild(this.line),this.line.name="WayLines3DLine")}createMultiLine(e,t){if(e.length<2)return null;const r=new Re,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 s=new c.Object3D,o=s.addComponent(c.MeshRenderer),l=new Bt;return l.topology="line-list",l.baseColor=t,l.blendMode=se.ADD,l.castReflection=!1,o.geometry=r,o.material=l,s}}class nc extends st{static format=Ge.BIN;parseBuffer(e){try{const t={template:null,waylines:null},r=vm(new Uint8Array(e));for(const a in r){const s=r[a],l=new DOMParser().parseFromString(sc(s),"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 _a(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,s=!1;for(let o=0;o<e.childNodes.length;++o){const l=e.childNodes[o];if(l.nodeType==Node.TEXT_NODE){const h=l.nodeValue?.trim();h&&h.length>0&&(a=h)}else l.nodeType==Node.ELEMENT_NODE&&(s=!0)}if(a&&!s)t[i]=a;else if(s){r.includes(i)?t[i]?.length?t[i].push({}):t[i]=[{}]:t[i]={};for(let o=0;o<e.childNodes.length;++o){const l=e.childNodes[o];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 oc{_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 At().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 At;i==".gltf"?r=await a.load(e,Ut,t):r=await a.load(e,yn,t);let s=r.data;return this._prefabPool.set(e,s),this._gltfPool.set(e,r.gltf),s}async loadObj(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let r,i=e.substring(e.lastIndexOf(".")).toLowerCase(),a=new At;i==".obj"&&(r=await a.load(e,yu,t));let s=r.data;return this._prefabPool.set(e,s),s}async loadB3DM(e,t,r){if(this._prefabPool.has(e))return this._prefabPool.get(e);let s=(await new At().load(e,Vu,t,r)).data;return this._prefabPool.set(e,s),s}async loadI3DM(e,t,r){if(this._prefabPool.has(e))return this._prefabPool.get(e);let s=(await new At().load(e,Wu,t,r)).data;return this._prefabPool.set(e,s),s}async loadTexture(e,t,r){if(this._texturePool.has(e))return this._texturePool.get(e);let i=new Lr;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,s)=>{let o=0,l=[];t==0&&a(l);for(let h=0;h<t;h++){const u=e.shift();this.loadTexture(u,r,i).then(f=>{l.push(f),o++,o==t&&a(l)})}})}async loadBitmapTextures(e,t=5,r,i){let a=[],s=Math.floor(e.length/t)+1,o=Math.floor(e.length%t);for(let l=0;l<s;l++){let h=await this.loadTextureCount(e,l==s-1?o: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 Qn;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 hs;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 cs;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 bn;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 bn;return await r.loadStd(e),r}async loadJSON(e,t){return await new At().loadJson(e,t).then(async r=>r).catch(r=>{console.log(r)})}async loadFont(e,t,r){let a=await new At().load(e,Gr,t,r),s=a.data;return Yi.addFontData(s.face,s.size,s),a.data}async loadAtlas(e,t){return(await new At().load(e,qu,t,e)).data}async loadKMZ(e,t){return(await new At().load(e,nc,t)).data}normalTexture;maskTexture;whiteTexture;blackTexture;redTexture;blueTexture;greenTexture;yellowTexture;grayTexture;defaultSky;defaultGUITexture;defaultGUISprite;defaultMaterial;createTexture(e,t,r,i,a,s,o){let l=32,h=32,u=new Uint8Array(l*h*4);this.fillColor(u,e,t,r,i,a,s);let f=new rn;return f.name=o,f.create(16,16,u,!0),o&&this.addTexture(o,f),f}fillColor(e,t,r,i,a,s,o){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]=s,e[u*4+3]=o}}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 Zu().generateBRDFLUTTexture(),r=t.name="BRDFLUT";this.addTexture(r,t),this.defaultSky=new hs,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 ii(this.whiteTexture),this.defaultGUISprite=new Zi(this.defaultGUITexture),this.defaultGUISprite.trimSize.set(4,4),this.defaultMaterial=new Ar}}class lc extends Ve{_postList;init(e){this._postList=new Map}start(){}stop(){}onEnable(){this.activePost()}onDisable(){this.unActivePost()}activePost(){let e=this.transform.view3D,t=A.getRenderJob(e);this._postList.forEach(r=>{t.addPost(r)})}unActivePost(){let e=this.transform.view3D,t=A.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;A.getRenderJob(r).removePost(t)}getPost(e){return this._postList.has(e)?this._postList.get(e):null}}const Cm="1.0.14";class A{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 I.presentationSize}static get aspect(){return I.aspect}static get width(){return I.windowWidth}static get height(){return I.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 k(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",Cm),window.isSecureContext||console.warn("WebGPU is only supported in secure contexts (HTTPS or localhost)"),this.setting={...this.setting,...e.engineSetting},await ge.init(E.allocCount,this.setting.doublePrecision),await I.init(e.canvasConfig),this.setting.reflectionSetting.width=this.setting.reflectionSetting.reflectionProbeSize*6,this.setting.reflectionSetting.height=this.setting.reflectionSetting.reflectionProbeSize*this.setting.reflectionSetting.reflectionProbeMaxCount,ne.getGBufferFrame(ne.reflections_GBuffer,this.setting.reflectionSetting.width,this.setting.reflectionSetting.height,!1),z.init(),Vr.init(),oe.init(),mt.init(),It.init(),this.res=new oc,this.res.initDefault(),this._beforeRender=e.beforeRender,this._renderLoop=e.renderLoop,this._lateRender=e.lateRender,this.inputSystem=new Bo,this.inputSystem.initCanvas(I.canvas)}static startRenderJob(e){let t=new iu(e);return this.renderJobs.set(e,t),this.setting.pick.mode=="pixel"&&e.scene.getOrAddComponent(lc).addPost(fn),(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){be.delta=e-be.time,be.time=e,be.frame+=1,ri.tick(be.delta);let t=this.views,r=0;for(r=0;r<t.length;r++){const s=t[r];s.scene.waitUpdate();let[o,l]=I.presentationSize;s.camera.viewPort.setTo(0,0,o,l)}this._beforeRender&&await this._beforeRender();for(const s of _e.componentsBeforeUpdateList){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];u.enable&&f(o)}}let i=I.device.createCommandEncoder();for(const s of _e.componentsComputeList){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];u.enable&&f(o,i)}}I.device.queue.submit([i.finish()]);for(const s of _e.componentsUpdateList){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];u.enable&&f(o)}}for(const s of _e.graphicComponent){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];o&&u.enable&&f(o)}}this._renderLoop&&await this._renderLoop(),ge.updateAllContinueTransform(0,E.useCount,16),oe.modelMatrixBindGroup.writeBuffer(E.useCount*16),this.renderJobs.forEach((s,o)=>{s.renderState||s.start(),s.renderFrame()});for(const s of _e.componentsLateUpdateList){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];u.enable&&f(o)}}this._lateRender&&await this._lateRender()}}let fs=`
7731
+ `}async loadFontTextures(){let e=[],t=this.data;for(const r of t.fontPage){let i=this.baseUrl+r.file;await A.res.loadTexture(i,null,!0);let a=A.res.getTexture(i),s=new ii(a);e.push(s)}Gr.parseSprite(e,t),t.fontChar[" "]||Gr.insertSpaceChar(t,e[0])}static insertSpaceChar(e,t){let r=new Zi,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),Yi.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 s=a[0],o=a[1];Object.prototype.hasOwnProperty.call(t,s)&&(o.indexOf('"')==-1?t[s]=parseFloat(a[1]):t[s]=o.replace('"',"").replace('"',""))}})}}function rm(n,e){let t=new Zi;return t.id=n,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 ii(e),t.uvRec.set(0,0,1,1),e.isVideoTexture||(e.flipY=!0),t}function ju(n,e,t){let r=new Zi;r.guiTexture=n,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/n.width,a=1/n.height;r.uvRec.set(r.uvRec.x*i,r.uvRec.y*a,r.uvRec.z*i,r.uvRec.w*a);let s=.1;return t.border.x<=s&&t.border.y<=s&&t.border.z<=s&&t.border.x<=s?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 Ku{_spriteMap=new Map;_spriteList=[];textureSize=new j;name;constructor(e){this.textureSize.set(e.x,e.y)}setTexture(e,t,r){let i=ju(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 qu 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 A.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 Ku(this._json.size),t=new ii(this._texture),r=this._json.atlas;for(const i in r)e.setTexture(t,i,r[i]);A.res.addAtlas(this.baseUrl,e),this.data=e}}var Lt=Uint8Array,Xi=Uint16Array,im=Int32Array,$u=new Lt([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]),ec=new Lt([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]),am=new Lt([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),tc=function(n,e){for(var t=new Xi(31),r=0;r<31;++r)t[r]=e+=1<<n[r-1];for(var i=new im(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}},rc=tc($u,2),ic=rc.b,sm=rc.r;ic[28]=258,sm[258]=28;for(var nm=tc(ec,0),om=nm.b,Nn=new Xi(32768),we=0;we<32768;++we){var ai=(we&43690)>>1|(we&21845)<<1;ai=(ai&52428)>>2|(ai&13107)<<2,ai=(ai&61680)>>4|(ai&3855)<<4,Nn[we]=((ai&65280)>>8|(ai&255)<<8)>>1}for(var va=(function(n,e,t){for(var r=n.length,i=0,a=new Xi(e);i<r;++i)n[i]&&++a[n[i]-1];var s=new Xi(e);for(i=1;i<e;++i)s[i]=s[i-1]+a[i-1]<<1;var o;if(t){o=new Xi(1<<e);var l=15-e;for(i=0;i<r;++i)if(n[i])for(var h=i<<4|n[i],u=e-n[i],f=s[n[i]-1]++<<u,d=f|(1<<u)-1;f<=d;++f)o[Nn[f]>>l]=h}else for(o=new Xi(r),i=0;i<r;++i)n[i]&&(o[i]=Nn[s[n[i]-1]++]>>15-n[i]);return o}),Ca=new Lt(288),we=0;we<144;++we)Ca[we]=8;for(var we=144;we<256;++we)Ca[we]=9;for(var we=256;we<280;++we)Ca[we]=7;for(var we=280;we<288;++we)Ca[we]=8;for(var ac=new Lt(32),we=0;we<32;++we)ac[we]=5;var lm=va(Ca,9,1),hm=va(ac,5,1),Vn=function(n){for(var e=n[0],t=1;t<n.length;++t)n[t]>e&&(e=n[t]);return e},or=function(n,e,t){var r=e/8|0;return(n[r]|n[r+1]<<8)>>(e&7)&t},kn=function(n,e){var t=e/8|0;return(n[t]|n[t+1]<<8|n[t+2]<<16)>>(e&7)},um=function(n){return(n+7)/8|0},Ln=function(n,e,t){return(e==null||e<0)&&(e=0),(t==null||t>n.length)&&(t=n.length),new Lt(n.subarray(e,t))},cm=["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"],Xt=function(n,e,t){var r=new Error(e||cm[n]);if(r.code=n,Error.captureStackTrace&&Error.captureStackTrace(r,Xt),!t)throw r;return r},fm=function(n,e,t,r){var i=n.length,a=r?r.length:0;if(!i||e.f&&!e.l)return t||new Lt(0);var s=!t,o=s||e.i!=2,l=e.i;s&&(t=new Lt(i*3));var h=function(Tt){var Dt=t.length;if(Tt>Dt){var Gt=new Lt(Math.max(Dt*2,Tt));Gt.set(t),t=Gt}},u=e.f||0,f=e.p||0,d=e.b||0,m=e.l,p=e.d,U=e.m,B=e.n,v=i*8;do{if(!m){u=or(n,f,1);var C=or(n,f+1,3);if(f+=3,C)if(C==1)m=lm,p=hm,U=9,B=5;else if(C==2){var b=or(n,f,31)+257,R=or(n,f+10,15)+4,w=b+or(n,f+5,31)+1;f+=14;for(var Q=new Lt(w),T=new Lt(19),N=0;N<R;++N)T[am[N]]=or(n,f+N*3,7);f+=R*3;for(var G=Vn(T),Z=(1<<G)-1,$=va(T,G,1),N=0;N<w;){var he=$[or(n,f,Z)];f+=he&15;var _=he>>4;if(_<16)Q[N++]=_;else{var ee=0,fe=0;for(_==16?(fe=3+or(n,f,3),f+=2,ee=Q[N-1]):_==17?(fe=3+or(n,f,7),f+=3):_==18&&(fe=11+or(n,f,127),f+=7);fe--;)Q[N++]=ee}}var ve=Q.subarray(0,b),te=Q.subarray(b);U=Vn(ve),B=Vn(te),m=va(ve,U,1),p=va(te,B,1)}else Xt(1);else{var _=um(f)+4,F=n[_-4]|n[_-3]<<8,x=_+F;if(x>i){l&&Xt(0);break}o&&h(d+F),t.set(n.subarray(_,x),d),e.b=d+=F,e.p=f=x*8,e.f=u;continue}if(f>v){l&&Xt(0);break}}o&&h(d+131072);for(var q=(1<<U)-1,ae=(1<<B)-1,Ae=f;;Ae=f){var ee=m[kn(n,f)&q],Ce=ee>>4;if(f+=ee&15,f>v){l&&Xt(0);break}if(ee||Xt(2),Ce<256)t[d++]=Ce;else if(Ce==256){Ae=f,m=null;break}else{var ye=Ce-254;if(Ce>264){var N=Ce-257,Me=$u[N];ye=or(n,f,(1<<Me)-1)+ic[N],f+=Me}var Se=p[kn(n,f)&ae],Pe=Se>>4;Se||Xt(3),f+=Se&15;var te=om[Pe];if(Pe>3){var Me=ec[Pe];te+=kn(n,f)&(1<<Me)-1,f+=Me}if(f>v){l&&Xt(0);break}o&&h(d+131072);var St=d+ye;if(d<te){var _r=a-te,xr=Math.min(te,St);for(_r+d<0&&Xt(3);d<xr;++d)t[d]=r[_r+d]}for(;d<St;++d)t[d]=t[d-te]}}e.l=m,e.p=Ae,e.b=d,e.f=u,m&&(u=1,e.m=U,e.d=p,e.n=B)}while(!u);return d!=t.length&&s?Ln(t,0,d):t.subarray(0,d)},dm=new Lt(0),Ur=function(n,e){return n[e]|n[e+1]<<8},lr=function(n,e){return(n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24)>>>0},On=function(n,e){return lr(n,e)+lr(n,e+4)*4294967296};function gm(n,e){return fm(n,{i:2},e&&e.out,e&&e.dictionary)}var Gn=typeof TextDecoder<"u"&&new TextDecoder,mm=0;try{Gn.decode(dm,{stream:!0}),mm=1}catch{}var pm=function(n){for(var e="",t=0;;){var r=n[t++],i=(r>127)+(r>223)+(r>239);if(t+i>n.length)return{s:e,r:Ln(n,t-1)};i?i==3?(r=((r&15)<<18|(n[t++]&63)<<12|(n[t++]&63)<<6|n[t++]&63)-65536,e+=String.fromCharCode(55296|r>>10,56320|r&1023)):i&1?e+=String.fromCharCode((r&31)<<6|n[t++]&63):e+=String.fromCharCode((r&15)<<12|(n[t++]&63)<<6|n[t++]&63):e+=String.fromCharCode(r)}};function sc(n,e){if(e){for(var t="",r=0;r<n.length;r+=16384)t+=String.fromCharCode.apply(null,n.subarray(r,r+16384));return t}else{if(Gn)return Gn.decode(n);var i=pm(n),a=i.s,t=i.r;return t.length&&Xt(8),a}}var Am=function(n,e){return e+30+Ur(n,e+26)+Ur(n,e+28)},Um=function(n,e,t){var r=Ur(n,e+28),i=sc(n.subarray(e+46,e+46+r),!(Ur(n,e+8)&2048)),a=e+46+r,s=lr(n,e+20),o=t&&s==4294967295?Bm(n,a):[s,lr(n,e+24),lr(n,e+42)],l=o[0],h=o[1],u=o[2];return[Ur(n,e+10),l,h,i,a+Ur(n,e+30)+Ur(n,e+32),u]},Bm=function(n,e){for(;Ur(n,e)!=1;e+=4+Ur(n,e+2));return[On(n,e+12),On(n,e+4),On(n,e+20)]};function vm(n,e){for(var t={},r=n.length-22;lr(n,r)!=101010256;--r)(!r||n.length-r>65558)&&Xt(13);var i=Ur(n,r+8);if(!i)return{};var a=lr(n,r+16),s=a==4294967295||i==65535;if(s){var o=lr(n,r-12);s=lr(n,o)==101075792,s&&(i=lr(n,o+32),a=lr(n,o+48))}for(var l=0;l<i;++l){var h=Um(n,a,s),u=h[0],f=h[1],d=h[2],m=h[3],p=h[4],U=h[5],B=Am(n,U);a=p,u?u==8?t[m]=gm(n.subarray(B,B+f),{out:new Lt(d)}):Xt(14,"unknown compression type "+u):t[m]=Ln(n,B,B+f)}return t}class Bt extends ft{constructor(){super(),this.shader=new c.UnLitShader,this.baseMap=A.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 Ci extends Re{shape_vertices=[];shape_indices=[];radius;widthSegments;heightSegments;phiStart;phiLength;thetaStart;thetaLength;constructor(e,t,r,i,a,s,o){super(),this.radius=e,this.widthSegments=t,this.heightSegments=r,this.phiStart=i,this.phiLength=a,this.thetaStart=s,this.thetaLength=o,this.buildGeometry()}buildGeometry(){var e,t,r=0;let i=this.heightSegments,a=this.widthSegments,s=this.radius;var o=(i+1)*(a+1);let l=new Float32Array(o*3),h=new Float32Array(o*3),u=new Float32Array(o*2),f=new Uint16Array(a*i*2*3),d=0,m=0,p=0;for(t=0;t<=i;++t){var U=Math.PI*t/i,B=s*Math.cos(U),v=s*Math.sin(U);for(e=0;e<=a;++e){var C=2*Math.PI*e/a,_=v*Math.cos(C),F=v*Math.sin(C),x=1/Math.sqrt(_*_+B*B+F*F);if(l[d++]=_,l[d++]=B,l[d++]=F,h[m++]=_*x,h[m++]=B*x,h[m++]=F*x,u[p++]=e/a,u[p++]=t/i,e>0&&t>0){var b=(a+1)*t+e,R=(a+1)*t+e-1,w=(a+1)*(t-1)+e-1,Q=(a+1)*(t-1)+e;t==i?(f[r++]=b,f[r++]=w,f[r++]=Q):t==1?(f[r++]=b,f[r++]=R,f[r++]=w):(f[r++]=b,f[r++]=R,f[r++]=w,f[r++]=b,f[r++]=w,f[r++]=Q)}}}this.setIndices(f),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:f.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0}),this.bounds=new xe(g.ZERO,new g(this.radius*2,this.radius*2,this.radius*2))}}class Sa extends c.Object3D{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 g(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),Sa.register3DRepresentation)this.marker=Sa.register3DRepresentation(this),this.marker&&this.addChild(this.marker);else{this.marker=new c.Object3D;const e=this.marker.addComponent(c.MeshRenderer);e.geometry=new Ci(.1,32,16),e.material=new Bt,e.material.baseColor=this.positionValid?new k(0,1,0,1):new k(1,0,0,1),this.addChild(this.marker),this.marker.name="WayPoint3DMarker"}}}class _a extends c.Object3D{static register3DRepresentation=null;line;constructor(e){super(),this.parseWayLineFile(e),this.setup3DRepresentation()}parseWayLineFile(e){for(const t of e.Folder.Placemark){const r=new Sa(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),_a.register3DRepresentation?(this.line=_a.register3DRepresentation(this),this.line&&this.addChild(this.line)):(this.line=this.createMultiLine(this.entityChildren.map(e=>e.localPosition),new k(1,1,1,1)),this.addChild(this.line),this.line.name="WayLines3DLine")}createMultiLine(e,t){if(e.length<2)return null;const r=new Re,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 s=new c.Object3D,o=s.addComponent(c.MeshRenderer),l=new Bt;return l.topology="line-list",l.baseColor=t,l.blendMode=se.ADD,l.castReflection=!1,o.geometry=r,o.material=l,s}}class nc extends st{static format=Ge.BIN;parseBuffer(e){try{const t={template:null,waylines:null},r=vm(new Uint8Array(e));for(const a in r){const s=r[a],l=new DOMParser().parseFromString(sc(s),"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 _a(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,s=!1;for(let o=0;o<e.childNodes.length;++o){const l=e.childNodes[o];if(l.nodeType==Node.TEXT_NODE){const h=l.nodeValue?.trim();h&&h.length>0&&(a=h)}else l.nodeType==Node.ELEMENT_NODE&&(s=!0)}if(a&&!s)t[i]=a;else if(s){r.includes(i)?t[i]?.length?t[i].push({}):t[i]=[{}]:t[i]={};for(let o=0;o<e.childNodes.length;++o){const l=e.childNodes[o];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 oc{_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 At().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 At;i==".gltf"?r=await a.load(e,Ut,t):r=await a.load(e,yn,t);let s=r.data;return this._prefabPool.set(e,s),this._gltfPool.set(e,r.gltf),s}async loadObj(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let r,i=e.substring(e.lastIndexOf(".")).toLowerCase(),a=new At;i==".obj"&&(r=await a.load(e,yu,t));let s=r.data;return this._prefabPool.set(e,s),s}async loadB3DM(e,t,r){if(this._prefabPool.has(e))return this._prefabPool.get(e);let s=(await new At().load(e,Vu,t,r)).data;return this._prefabPool.set(e,s),s}async loadI3DM(e,t,r){if(this._prefabPool.has(e))return this._prefabPool.get(e);let s=(await new At().load(e,Wu,t,r)).data;return this._prefabPool.set(e,s),s}async loadTexture(e,t,r){if(this._texturePool.has(e))return this._texturePool.get(e);let i=new Lr;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,s)=>{let o=0,l=[];t==0&&a(l);for(let h=0;h<t;h++){const u=e.shift();this.loadTexture(u,r,i).then(f=>{l.push(f),o++,o==t&&a(l)})}})}async loadBitmapTextures(e,t=5,r,i){let a=[],s=Math.floor(e.length/t)+1,o=Math.floor(e.length%t);for(let l=0;l<s;l++){let h=await this.loadTextureCount(e,l==s-1?o: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 Qn;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 hs;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 cs;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 bn;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 bn;return await r.loadStd(e),r}async loadJSON(e,t){return await new At().loadJson(e,t).then(async r=>r).catch(r=>{console.log(r)})}async loadFont(e,t,r){let a=await new At().load(e,Gr,t,r),s=a.data;return Yi.addFontData(s.face,s.size,s),a.data}async loadAtlas(e,t){return(await new At().load(e,qu,t,e)).data}async loadKMZ(e,t){return(await new At().load(e,nc,t)).data}normalTexture;maskTexture;whiteTexture;blackTexture;redTexture;blueTexture;greenTexture;yellowTexture;grayTexture;defaultSky;defaultGUITexture;defaultGUISprite;defaultMaterial;createTexture(e,t,r,i,a,s,o){let l=32,h=32,u=new Uint8Array(l*h*4);this.fillColor(u,e,t,r,i,a,s);let f=new rn;return f.name=o,f.create(16,16,u,!0),o&&this.addTexture(o,f),f}fillColor(e,t,r,i,a,s,o){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]=s,e[u*4+3]=o}}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 Zu().generateBRDFLUTTexture(),r=t.name="BRDFLUT";this.addTexture(r,t),this.defaultSky=new hs,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 ii(this.whiteTexture),this.defaultGUISprite=new Zi(this.defaultGUITexture),this.defaultGUISprite.trimSize.set(4,4),this.defaultMaterial=new Ar}}class lc extends Ve{_postList;init(e){this._postList=new Map}start(){}stop(){}onEnable(){this.activePost()}onDisable(){this.unActivePost()}activePost(){let e=this.transform.view3D,t=A.getRenderJob(e);this._postList.forEach(r=>{t.addPost(r)})}unActivePost(){let e=this.transform.view3D,t=A.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;A.getRenderJob(r).removePost(t)}getPost(e){return this._postList.has(e)?this._postList.get(e):null}}const Cm="1.0.15";class A{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 I.presentationSize}static get aspect(){return I.aspect}static get width(){return I.windowWidth}static get height(){return I.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 k(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",Cm),window.isSecureContext||console.warn("WebGPU is only supported in secure contexts (HTTPS or localhost)"),this.setting={...this.setting,...e.engineSetting},await ge.init(E.allocCount,this.setting.doublePrecision),await I.init(e.canvasConfig),this.setting.reflectionSetting.width=this.setting.reflectionSetting.reflectionProbeSize*6,this.setting.reflectionSetting.height=this.setting.reflectionSetting.reflectionProbeSize*this.setting.reflectionSetting.reflectionProbeMaxCount,ne.getGBufferFrame(ne.reflections_GBuffer,this.setting.reflectionSetting.width,this.setting.reflectionSetting.height,!1),z.init(),Vr.init(),oe.init(),mt.init(),It.init(),this.res=new oc,this.res.initDefault(),this._beforeRender=e.beforeRender,this._renderLoop=e.renderLoop,this._lateRender=e.lateRender,this.inputSystem=new Bo,this.inputSystem.initCanvas(I.canvas)}static startRenderJob(e){let t=new iu(e);return this.renderJobs.set(e,t),this.setting.pick.mode=="pixel"&&e.scene.getOrAddComponent(lc).addPost(fn),(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){be.delta=e-be.time,be.time=e,be.frame+=1,ri.tick(be.delta);let t=this.views,r=0;for(r=0;r<t.length;r++){const s=t[r];s.scene.waitUpdate();let[o,l]=I.presentationSize;s.camera.viewPort.setTo(0,0,o,l)}this._beforeRender&&await this._beforeRender();for(const s of _e.componentsBeforeUpdateList){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];u.enable&&f(o)}}let i=I.device.createCommandEncoder();for(const s of _e.componentsComputeList){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];u.enable&&f(o,i)}}I.device.queue.submit([i.finish()]);for(const s of _e.componentsUpdateList){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];u.enable&&f(o)}}for(const s of _e.graphicComponent){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];o&&u.enable&&f(o)}}this._renderLoop&&await this._renderLoop(),ge.updateAllContinueTransform(0,E.useCount,16),oe.modelMatrixBindGroup.writeBuffer(E.useCount*16),this.renderJobs.forEach((s,o)=>{s.renderState||s.start(),s.renderFrame()});for(const s of _e.componentsLateUpdateList){let o=s[0],l=s[1];for(const h of l){let u=h[0],f=h[1];u.enable&&f(o)}}this._lateRender&&await this._lateRender()}}let fs=`
7732
7732
  struct BloomCfg{
7733
7733
  downSampleStep: f32,
7734
7734
  downSampleBlurSize: f32,
@@ -11626,7 +11626,7 @@ fn frag(){
11626
11626
  ${this.fs}
11627
11627
  `}class Kn extends ft{_scissorRect;_screenSize=new j(1024,768);_scissorEnable=!1;constructor(e){super(),z.register("GUI_shader_view",jn.GUI_shader_view),z.register("GUI_shader_world",jn.GUI_shader_world);let t=new at;this.addColorPass(t,H.COLOR,e),this.addColorPass(t,H.UI,e),this.shader=t}addColorPass(e,t,r){let i=r==Ht.View?"GUI_shader_view":"GUI_shader_world",a=new Ne(i,i);a.passType=t,a.setShaderEntry("VertMain","FragMain"),a.setUniformVector4("scissorRect",new K),a.setUniformVector2("screenSize",this._screenSize),a.setUniformFloat("scissorCornerRadius",0),a.setUniformFloat("scissorFadeOutSize",0),a.setUniformFloat("pixelRatio",1),a.setUniformVector3("v3",g.ZERO);let s=a.shaderState;s.depthWriteEnabled=!1,a.blendMode=se.NORMAL,a.depthCompare=r==Ht.View?$e.always:$e.less_equal,a.cullMode=Rt.back,e.addRenderPass(a)}setPanelRatio(e){this.shader.setUniformFloat("pixelRatio",e)}setScissorRect(e,t,r,i){this._scissorRect||=new K,this._scissorRect.set(e,t,r,i),this.shader.setUniformVector4("scissorRect",this._scissorRect)}setScissorEnable(e){this._scissorEnable!=e&&(this._scissorEnable=e,e?this.shader.setDefine("SCISSOR_ENABLE",!0):this.shader.deleteDefine("SCISSOR_ENABLE"),this.shader.noticeValueChange())}setScissorCorner(e,t){this.shader.setUniformFloat("scissorCornerRadius",e),this.shader.setUniformFloat("scissorFadeOutSize",t)}setScreenSize(e,t){return this._screenSize.set(e,t),this.shader.setUniformVector2("screenSize",this._screenSize),this}setTextures(e){for(let t=0;t<7;t++){let r=e[t]||A.res.whiteTexture;this.shader.setTexture(`tex_${t}`,r),this.setVideoTextureDefine(t,r.isVideoTexture)}}_videoTextureFlags={};setVideoTextureDefine(e,t){let r=!1;t!=this._videoTextureFlags[e]&&(t?this.shader.setDefine(`VideoTexture${e}`,!0):this.shader.deleteDefine(`VideoTexture${e}`),this._videoTextureFlags[e]=t,r=!0),r&&this.shader.noticeValueChange()}set envMap(e){}set shadowMap(e){}set baseMap(e){}set normalMap(e){}set emissiveMap(e){}set irradianceMap(e){}set irradianceDepthMap(e){}}class nf extends c.MeshRenderer{_guiGeometry;init(e){super.init(),this.addRendererMask(Ue.UI),this.removeRendererMask(Ue.Default),this.castGI=!1,this.castShadow=!1,this.alwaysRender=!0,this._ignoreEnvMap=this._ignorePrefilterMap=!0}get geometry(){return super.geometry}set geometry(e){super.geometry=e,this._guiGeometry=e}nodeUpdate(e,t,r,i){for(let a=0;a<this.materials.length;a++){let o=this.materials[a].getPass(t),l=this._guiGeometry.getPositionBuffer(),h=this._guiGeometry.getSpriteBuffer(),u=this._guiGeometry.getColorBuffer();if(o)for(let f=0;f<o.length;f++){const d=o[f];d.pipeline||(d.setStorageBuffer("vPositionBuffer",l),d.setStorageBuffer("vSpriteBuffer",h),d.setStorageBuffer("vColorBuffer",u))}}super.nodeUpdate(e,t,r,i)}onUpdate(e){}}class of{_use;_unUse;constructor(){this._use=[],this._unUse=[]}pushBack(e){let t=this._use.indexOf(e);t!=-1&&(this._use.splice(t,1),this._unUse.push(e))}getUseList(){return this._use}getOne(e,t){let r;return this._unUse.length>0?(r=this._unUse[0],this._unUse.splice(0,1),this._use.push(r),r):(r=new e(t),this._use.push(r),r)}hasFree(){return this._unUse.length>0}}let Ea;class Br{x=0;y=0;z=0;width=1;height=1;_globalX=0;_globalY=0;_globalWidth=0;_globalHeight=0;_visible=!0;_offsetX=0;_offsetY=0;_sprite=A.res.defaultGUISprite;_color=new k(1,1,1,1);_imageType=Hi.Simple;dirtyAttributes=We.MAX;cacheTextureId=-1;static textPool;static get quadPool(){return this.textPool||=new of,this.textPool}static recycleQuad(e){e.sprite=null,e.dirtyAttributes=We.MAX,e.x=0,e.y=0,e.z=-1,e.cacheTextureId=-1,Br.quadPool.pushBack(e)}static spawnQuad(){return Br.quadPool.getOne(Br)}get imageType(){return this._imageType}set imageType(e){this._imageType=e,this.setAttrChange(We.SPRITE|We.POSITION)}get color(){return this._color}set color(e){this._color.copyFrom(e),this.setAttrChange(We.COLOR)}get visible(){return this._visible}set visible(e){e!=this._visible&&(this._visible=e,this.setAttrChange(We.SPRITE))}get sprite(){return this._sprite}set sprite(e){this._sprite!=e&&(this._sprite=e,this.setAttrChange(We.SPRITE|We.POSITION))}get left(){return this._globalX-this._offsetX}get right(){return this.left+this._globalWidth}get top(){return this._globalY-this._offsetY}get bottom(){return this.top+this._globalHeight}setSize(e,t){this.width=e,this.height=t,this.setAttrChange(We.POSITION)}setXY(e,t){this.x=e,this.y=t,this.setAttrChange(We.POSITION)}setAttrChange(e){this.dirtyAttributes=this.dirtyAttributes|e}applyTransform(e){this.setAttrChange(We.POSITION);let t=this._sprite,r=e.getWorldMatrix();(this.x!=0||this.y!=0)&&(r=this.getQuadMatrix(r));let i=r.getScaleX(),a=r.getScaleY(),s=t.isSliced&&this._imageType==Hi.Sliced;if(this._offsetX=e.width*.5*i,this._offsetY=e.height*.5*a,s)this._globalWidth=i*(e.width-(t.offsetSize.z-t.trimSize.x)),this._globalHeight=a*(e.height-(t.offsetSize.w-t.trimSize.y)),this._globalX=r.tx+t.offsetSize.x*i,this._globalY=r.ty+t.offsetSize.y*a;else{let o=this.width/t.offsetSize.z,l=this.height/t.offsetSize.w;this._globalWidth=i*t.trimSize.x*o,this._globalHeight=a*t.trimSize.y*l,this._globalX=r.tx+t.offsetSize.x*o*i,this._globalY=r.ty+t.offsetSize.y*l*a}return this}getQuadMatrix(e){return Ea||=new xi,Ea.identity(),Ea.setTranslate(this.x,this.y),Ea.mul(e),Ea}writeToGeometry(e,t){return e.fillQuad(this,t),this.dirtyAttributes=We.NONE,this}}class qn extends Ve{_uiTransform;_visible=!0;destroy(){this._uiTransform.setNeedUpdateUIPanel(),super.destroy()}get uiTransform(){return this._uiTransform}get visible(){return this._visible}set visible(e){this._visible!=e&&(this._visible=e,this.onUIComponentVisible?.(this._visible))}init(e){super.init?.(e),this._uiTransform=this.object3D.getOrAddComponent(zr),this._uiTransform.setNeedUpdateUIPanel()}copyComponent(e){return this.visible=e.visible,this}}class wa extends qn{_mainQuads;_shadowRender;_shadowSource;isUIShadow;isShadowless;needUpdateShadow;init(e){super.init?.(e),this._mainQuads=[]}destroy(){this.detachQuads(),this._shadowRender?.setShadowSource(null),this._shadowSource?.setShadowRenderer(null),super.destroy(),this._shadowRender=null,this._shadowSource=null}start(){super.start?.(),this.isUIShadow?this.autoBindShadow(null,this):this.isShadowless||this.autoBindShadow(this,null),this.setShadowDirty()}setShadowDirty(){this._shadowRender&&(this._shadowRender.needUpdateShadow=!0)}get mainQuads(){return this._mainQuads}setShadowRenderer(e){this._shadowRender=e}setShadowSource(e){this._shadowSource=e}getShadowRender(){return this._shadowRender}autoBindShadow(e,t){let r=this.object3D.components.values();if(!e)for(let i of r){let a=i;if(!(a.isShadowless||a.isUIShadow)&&a.mainQuads){e=a;break}}if(!t)for(let i of r){let a=i;if(a.isUIShadow&&a.mainQuads){t=a;break}}return e&&t?(e.setShadowRenderer(t),t.setShadowSource(e),!0):!1}recycleQuad(e){if(e&&this._mainQuads){let t=this._mainQuads.indexOf(e);t>=0?(this._mainQuads.splice(t,1),Br.recycleQuad(e)):e=null}return e}attachQuad(e){return this._mainQuads&&this._mainQuads.push(e),this}detachQuads(){if(this._mainQuads)for(;this._mainQuads.length>0;){let e=this._mainQuads.shift();this.recycleQuad(e)}return this}copyComponent(e){return super.copyComponent(e),this.isUIShadow=e.isUIShadow,this.isShadowless=e.isShadowless,this}}class Fi extends wa{init(e){super.init?.(e),this.attachQuad(Br.spawnQuad()),this.sprite=A.res.defaultGUISprite}cloneTo(e){e.getOrAddComponent(Fi).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this.sprite=e.sprite,this.color=e.color,this.imageType=e.imageType,this}set sprite(e){e||=A.res.defaultGUISprite;for(let t of this._mainQuads)t.sprite=e,t.setSize(this._uiTransform.width,this._uiTransform.height);this.setShadowDirty()}onTransformResize(){this.applyTransformSize()}applyTransformSize(){for(let e of this._mainQuads)e.setSize(this._uiTransform.width,this._uiTransform.height);this.setShadowDirty()}get sprite(){return this._mainQuads[0].sprite}onUIComponentVisible(e){this.applyComponentVisible()}onUITransformVisible(e){this.applyComponentVisible()}applyComponentVisible(){let e=!this._visible||!this._uiTransform.globalVisible;for(let t of this._mainQuads)t.visible=!e;this.setShadowDirty()}get color(){return this._mainQuads[0].color}set color(e){for(let t of this._mainQuads)t.color=e;this.setShadowDirty()}get imageType(){return this._mainQuads[0].imageType}set imageType(e){for(let t of this._mainQuads)t.imageType=e;this.setShadowDirty()}}class Ta extends Fi{space=Ht.World;needUpdateGeometry=!0;panelOrder=0;needSortOnCameraZ;_billboard;_rebuild;scissorEnable=!1;scissorCornerRadius=0;scissorFadeOutSize=0;_uiRenderer;_geometry;_maxCount=128;panelRatio=1;isUIPanel=!0;cloneTo(e){e.getOrAddComponent(Ta).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this.panelOrder=e.panelOrder,this.needSortOnCameraZ=e.needSortOnCameraZ,this.cullMode=e.cullMode,this.billboard=e.billboard,this.scissorEnable=e.scissorEnable,this.scissorCornerRadius=e.scissorCornerRadius,this.scissorFadeOutSize=e.scissorFadeOutSize,this}init(e){super.init(e),this._uiTransform.resize(I.canvas.width,I.canvas.height),this.create(this.space),this.visible=!1}updateDrawCallSegment(e,t,r){this._geometry.updateSubGeometry(e,t,r);let i=this._uiRenderer.material,a=this._uiRenderer.materials[e];if(!a){a=new Kn(this.space);let s=this._uiRenderer.materials.slice();s.push(a),this._uiRenderer.materials=s,a.cullMode=i.cullMode,a.depthCompare=i.depthCompare}}create(e){this._maxCount=this.space==Ht.World?Si.quadMaxCountForWorld:Si.quadMaxCountForView,this._uiRenderer=this.object3D.addComponent(nf),this._geometry=this._uiRenderer.geometry=new rf(this._maxCount).create(),this._uiRenderer.material=new Kn(e),this._uiRenderer.renderOrder=Si.SortOrderStartWorld,this._rebuild=new sf,this.object3D.bound=new xe(new g,new g(1,1,1).multiplyScalar(Number.MAX_VALUE*.1))}get quadMaxCount(){return this._maxCount}get renderer(){return this._uiRenderer}set billboard(e){this.space==Ht.View&&(e=si.None,console.warn("Cannot enable billboard in view space")),e==si.BillboardXYZ||e==si.BillboardY?(this._billboard=this.object3D.getOrAddComponent(Fa),this._billboard.type=e):(this.object3D.removeComponent(Fa),this._billboard=null)}get billboard(){return this._billboard?this._billboard.type:si.None}set cullMode(e){if(this.space==Ht.World)for(let t of this._uiRenderer.materials)t.cullMode=e;else console.warn("Cannot change cullMode in view space")}get cullMode(){return this._uiRenderer.material.cullMode}onUpdate(e){super.onUpdate?.(e),this.rebuildGUIMesh(e)}_collectTransform=[];rebuildGUIMesh(e){let t=this,r=t._collectTransform;if(r.length=0,t.object3D.getComponents(zr,r),r.length>0){t._rebuild.build(r,t,t.needUpdateGeometry);for(const o of r)o.needUpdateQuads=!1}let i=t.object3D.getComponentFromParent(Ia),a=i?i.index:0;t._uiRenderer.enable=r.length>0;let s=t.isViewPanel?Si.SortOrderStartView:Si.SortOrderStartWorld;if(t._uiRenderer.renderOrder=a*Si.SortOrderCanvasSpan+s+t.panelOrder,t._uiRenderer.needSortOnCameraZ=t.needSortOnCameraZ,this.space==Ht.View){let o=I.canvas.clientWidth,l=I.canvas.clientHeight,h=this._uiTransform.width,u=this._uiTransform.height;this.panelRatio=this.updateGUIPixelRatio(o,l,h,u)}else this.panelRatio=1;for(let o of t._uiRenderer.materials){let l=o;if(l.setPanelRatio(this.panelRatio),l.setScreenSize(I.canvas.clientWidth,I.canvas.clientHeight),l.setScissorEnable(t.scissorEnable),t.scissorEnable){let h=t.mainQuads[0];l.setScissorRect(h.left,h.bottom,h.right,h.top),l.setScissorCorner(t.scissorCornerRadius,t.scissorFadeOutSize)}}t.needUpdateGeometry=!1}updateGUIPixelRatio(e,t,r,i){let a=r/i,s=e/t,o=1;return a<s?o=t/i:o=e/r,o}}class ms extends Ta{isViewPanel=!0;space=Ht.View;constructor(){super()}cloneTo(e){e.getOrAddComponent(ms).copyComponent(this)}}class ps extends Ta{isWorldPanel=!0;space=Ht.World;_depthTest=!0;constructor(){super()}cloneTo(e){e.getOrAddComponent(ps).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this.depthTest=e.depthTest,this}get depthTest(){return this._depthTest}set depthTest(e){if(this._depthTest!=e){this._depthTest=e;let t=this.depthTest?$e.less_equal:$e.always;for(let r of this._uiRenderer.materials)r.depthCompare=t}}}let lf;class zr extends Ve{useParentPivot=!1;parent;pivotX=.5;pivotY=.5;_width=100;_height=100;_localVisible=!0;_globalVisible=!0;_uiInteractiveList;get uiInteractiveList(){return this._uiInteractiveList}constructor(){super(),this._localMatrix=new xi,this._worldMatrix=new xi}init(e){super.init(e),this.transform.eventDispatcher.addEventListener(this.transform.eventLocalChange.type,this.onTransformChange,this),this.onParentChange(null,this.object3D.parent?.object3D)}onTransformChange(e){this.onChange=!0}addUIInteractive(e){return this._uiInteractiveList||=[],this._uiInteractiveList.push(e),this}removeUIInteractive(e){if(this._uiInteractiveList){let t=this._uiInteractiveList.indexOf(e);if(t>=0)return this._uiInteractiveList.slice(t,1),e}return null}get globalVisible(){return this._globalVisible}set visible(e){if(this._localVisible!=e){this._localVisible=e;let t=this.parent?this.parent._globalVisible:!0;this.onUITransformVisible(this._localVisible&&t)}}get visible(){return this._localVisible}onUITransformVisible(e){let t=this._localVisible&&e;t!=this._globalVisible&&(this._globalVisible=t,this.object3D.components.forEach((r,i)=>{let a=r;if(a.onUITransformVisible)if(a==this)for(let s of this.object3D.entityChildren){let o=s.getComponent(zr);o&&o.onUITransformVisible(this._globalVisible)}else a.onUITransformVisible(this._globalVisible)}))}onParentChange(e,t){this.parent?.setNeedUpdateUIPanel(),this.parent=t?.getComponent(zr),this.parent?.setNeedUpdateUIPanel()}get width(){return this._width}get height(){return this._height}resize(e,t){if(this._width!=e||this._height!=t){this._width=e,this._height=t,this.onChange=!0;for(let r of this.object3D.components.values())r.onTransformResize?.();return!0}return!1}get x(){return this.object3D.x}set x(e){e!=this.object3D.x&&(this.object3D.x=e,this.onChange=!0)}get y(){return this.object3D.y}set y(e){e!=this.object3D.y&&(this.object3D.y=e,this.onChange=!0)}setXY(e,t){let r=this.object3D.localPosition;r.set(e,t,r.z),this.object3D.localPosition=r,this.onChange=!0}get z(){return this.object3D.z}set z(e){e!=this.object3D.z&&(this.object3D.z=e,this.onChange=!0)}get scaleX(){return this.object3D.scaleX}set scaleX(e){this.onChange=!0,this.object3D.scaleX=e}get scaleY(){return this.object3D.scaleY}set scaleY(e){this.onChange=!0,this.object3D.scaleY=e}get scaleZ(){return this.object3D.scaleZ}set scaleZ(e){this.onChange=!0,this.object3D.scaleZ=e}_localMatrix;_worldMatrix;_onChange=!0;needUpdateQuads=!0;get onChange(){return this._onChange}_tempTransforms=[];set onChange(e){if(this._onChange!=e&&(this._onChange=e,e)){this._tempTransforms.length=0;let t=this.object3D.getComponents(zr,this._tempTransforms,!0);for(let r of t)r._onChange=!0,r.needUpdateQuads=!0}}onEnable(){this.setNeedUpdateUIPanel(),this.onChange=!0}onDisable(){this.setNeedUpdateUIPanel(),this.onChange=!0}setNeedUpdateUIPanel(){let e;e=this.object3D.getComponentFromParent(ps),e||(e=this.object3D.getComponentFromParent(ms)),e&&(e.needUpdateGeometry=!0)}cloneTo(e){let t=e.getOrAddComponent(zr);t.visible=this.visible,t.x=this.x,t.y=this.y,t.z=this.z,t.resize(this.width,this.height),t.pivotX=this.pivotX,t.pivotY=this.pivotY,t.scaleX=this.scaleX,t.scaleY=this.scaleY}matrix(){let e=this._localMatrix,t=this.object3D.rotationZ;return this.parent?(e.updateScaleAndRotation(this.object3D.scaleX,this.object3D.scaleY,t,t),e.tx=this.object3D.x,e.ty=this.object3D.y):e.updateScaleAndRotation(1,1,0,0),(this.pivotX!=.5||this.pivotY!=.5)&&(lf||=new xi().identity(),e.mul(lf.setTo(1,0,0,1,-(this.pivotX-.5)*this.width,-(this.pivotY-.5)*this.height))),e}getWorldMatrix(){let e=this,t=e._worldMatrix;return this._onChange&&(t.copyFrom(e.matrix()),e.parent&&t.mul(e.parent.getWorldMatrix()),e._onChange=!1),t}beforeDestroy(e){this.transform.eventDispatcher.addEventListener(this.transform.eventLocalChange.type,this.onTransformChange,this),super.beforeDestroy?.(e)}}class hf{_ray;_mouseCode;_clickEvent;_outEvent;_overEvent;_upEvent;_downEvent;_view;init(e){this._view=e,this._ray=new Jt,this._clickEvent=new ot(ot.PICK_CLICK_GUI),this._outEvent=new ot(ot.PICK_OUT_GUI),this._overEvent=new ot(ot.PICK_OVER_GUI),this._upEvent=new ot(ot.PICK_UP_GUI),this._downEvent=new ot(ot.PICK_DOWN_GUI),A.inputSystem.addEventListener(L.POINTER_DOWN,this.onTouchDown,this,null,1),A.inputSystem.addEventListener(L.POINTER_UP,this.onTouchUp,this,null,1),A.inputSystem.addEventListener(L.POINTER_MOVE,this.onTouchMove,this,null,1),A.inputSystem.addEventListener(L.POINTER_CLICK,this.onTouchClick,this,null,1)}_lastDownTarget;_lastOverTarget;onTouchClick(e){this._lastOverTarget&&e.stopImmediatePropagation()}onTouchMove(e){this._mouseCode=e.mouseCode,this.collectEntities();let t=this.pick(this._colliderOut);if(t){e.stopImmediatePropagation();let r=t.collider;r!=this._lastOverTarget&&(r.mouseStyle=Oe.OVER,Object.assign(this._overEvent,e),this._overEvent.type=ot.PICK_OVER_GUI,this._overEvent.target=r.object3D,this._overEvent.data=t,r.object3D.dispatchEvent(this._overEvent),this._lastOverTarget&&(this._lastOverTarget.mouseStyle=Oe.NORMAL,Object.assign(this._outEvent,e),this._outEvent.type=ot.PICK_OUT_GUI,this._outEvent.target=r.object3D,this._outEvent.data=t,this._lastOverTarget.object3D.dispatchEvent(this._outEvent))),this._lastOverTarget=r}else this._lastOverTarget&&(this._lastOverTarget.mouseStyle=Oe.NORMAL,Object.assign(this._outEvent,e),this._outEvent.type=ot.PICK_OUT_GUI,this._outEvent.target=this._lastOverTarget.object3D,this._outEvent.data=t,this._lastOverTarget.object3D.dispatchEvent(this._outEvent),this._lastOverTarget=null)}_lastDownPosition=new j;_calcDistanceVec2=new j;_lastDownTime=0;_clickTimeSpan=200;_clickDistanceSpan=10;onTouchDown(e){this._lastDownTime=be.time,this._lastDownPosition.set(e.mouseX,e.mouseY),this._mouseCode=e.mouseCode,this.collectEntities();let t=this.pick(this._colliderOut);t&&e.stopImmediatePropagation();let r=t?t.collider:null;r&&(r.mouseStyle=Oe.DOWN,Object.assign(this._downEvent,e),this._downEvent.type=ot.PICK_DOWN_GUI,this._downEvent.target=r.object3D,this._downEvent.data=t,r.object3D.dispatchEvent(this._downEvent)),this._lastDownTarget=r}onTouchUp(e){this._calcDistanceVec2.set(e.mouseX,e.mouseY),this._mouseCode=e.mouseCode,this.collectEntities();let t=this.pick(this._colliderOut);t&&e.stopImmediatePropagation();let r=t?t.collider:null;this._lastDownTarget&&this._lastDownTarget.enable&&(this._lastDownTarget.mouseStyle=Oe.NORMAL),r&&r==this._lastDownTarget&&be.time-this._lastDownTime<=this._clickTimeSpan&&(this._calcDistanceVec2.set(e.mouseX,e.mouseY),this._calcDistanceVec2.distance(this._lastDownPosition)<=this._clickDistanceSpan&&(Object.assign(this._clickEvent,e),this._clickEvent.type=ot.PICK_CLICK_GUI,this._clickEvent.target=r.object3D,this._clickEvent.data=t,r.object3D.dispatchEvent(this._clickEvent))),this._lastDownTarget=null}_colliderOut=[];_transformList=[];_sortWorldPanelList=[];_iteractive2PanelDict=new Map;collectEntities(){return this._colliderOut.length=0,this._sortWorldPanelList.length=0,this._iteractive2PanelDict.clear(),this._view.canvasList.slice().reverse().forEach(t=>{if(t&&t.transform&&t.transform.parent){let r=t.object3D.getComponentsByProperty("isUIPanel",!0,!0);r.sort((i,a)=>{let s=i._uiRenderer.__renderOrder,o=a._uiRenderer.__renderOrder;return s>o?-1:1});for(let i of r){this._transformList.length=0,i.object3D.getComponents(zr,this._transformList),this._transformList.reverse();for(const a of this._transformList){let s=a.uiInteractiveList;if(s&&s.length>0)for(let o of s)this._colliderOut.push(o),this._iteractive2PanelDict.set(o,i)}}}}),this._colliderOut}pick(e){this._ray=this._view.camera.screenPointToRay(A.inputSystem.mouseX,A.inputSystem.mouseY);let t=new j(A.inputSystem.mouseX,A.inputSystem.mouseY),r=new j(I.canvas.clientWidth,I.canvas.clientHeight),i;for(const a of e)if(a.interactive&&a.enable&&a.interactiveVisible){let s=this._iteractive2PanelDict.get(a);if(i=a.rayPick(this._ray,s,t,r),i)return i.collider=a,i}return null}}var uf=(n=>(n[n.COLLINEAR=0]="COLLINEAR",n[n.LINES_INTERSECT=1]="LINES_INTERSECT",n[n.SEGMENTS_INTERSECT=2]="SEGMENTS_INTERSECT",n[n.A_BISECTS_B=3]="A_BISECTS_B",n[n.B_BISECTS_A=4]="B_BISECTS_A",n[n.PARALELL=5]="PARALELL",n))(uf||{}),cf=(n=>(n[n.ON_LINE=0]="ON_LINE",n[n.LEFT_SIDE=1]="LEFT_SIDE",n[n.RIGHT_SIDE=2]="RIGHT_SIDE",n))(cf||{});class nt{static cacluteLine0=new nt(null,null);static cacluteLine1=new nt(null,null);start;end;color=new k(1,1,1,1);_normal;_normalCalculated=!1;constructor(e,t){this.start=e,this.end=t}set(e,t){this.start=e,this.end=t}getCenter(){let e=g.HELP_0;return this.start.subtract(this.end,e),e.scaleBy(.5),e.add(this.end),e}inverse(){let e=this.start;this.start=this.end,this.end=e}equals(e){return this.start==e.start&&this.end==e.end||this.start==e.end&&this.end==e.start}toArray(){return[this.start.x,this.start.y,this.start.z,this.end.x,this.end.y,this.end.z]}static getLines(e){let t=[];for(let r=0;r<e.length;r++){let i=r,a=Ys(r+1,e.length),s=e[i],o=e[a];t.push(new nt(s,o))}return t}intersection(e,t=null){var r=(e.end.z-e.start.z)*(this.end.x-this.start.x)-(e.end.x-e.start.x)*(this.end.z-this.start.z),i=(e.end.x-e.start.x)*(this.start.z-e.start.z)-(e.end.z-e.start.z)*(this.start.x-e.start.x),a=(e.start.x-this.start.x)*(this.end.z-this.start.z)-(e.start.z-this.start.z)*(this.end.x-this.start.x);if(r==0)return i==0&&a==0?0:5;i=i/r,a=a/r;var s=this.start.x+i*(this.end.x-this.start.x),o=this.start.z+i*(this.end.z-this.start.z);return t!=null&&(t.x=s,t.y=0,t.z=o),i>=0&&i<=1&&a>=0&&a<=1?2:a>=0&&a<=1?3:i>=0&&i<=1?4:1}getDirection(){var e=this.end.subtract(this.start),t=new g(e.x,e.y);return t.normalize()}copyFrom(e){this.start||(this.start=new g),this.end||(this.end=new g),this.start.copyFrom(e.start),this.end.copyFrom(e.end)}static IsEqual(e,t){return Math.abs(e-t)<1e-7}static squreDistanceSegmentToSegment(e,t,r){let i=e.start,a=e.end,s=t.start,o=t.end,l=i.x,h=i.y,u=i.z,f=a.x,d=a.y,m=a.z,p=s.x,U=s.y,B=s.z,v=o.x,C=o.y,_=o.z,F=f-l,x=d-h,b=m-u,R=v-p,w=C-U,Q=_-B,T=l-p,N=h-U,G=u-B,Z=F*F+x*x+b*b,$=F*R+x*w+b*Q,he=R*R+w*w+Q*Q,ee=F*T+x*N+b*G,fe=R*T+w*N+Q*G,ve=Z*he-$*$,te=ve,q=ve,ae=0,Ae=0;this.IsEqual(ve,0)?(ae=0,te=1,Ae=fe,q=he):(ae=$*fe-he*ee,Ae=Z*fe-$*ee,ae<0?(ae=0,Ae=fe,q=he):ae>te&&(ae=te,Ae=fe+$,q=he)),Ae<0?(Ae=0,-ee<0?ae=0:-ee>Z?ae=te:(ae=-ee,te=Z)):Ae>q&&(Ae=q,-ee+$<0?ae=0:-ee+$>Z?ae=te:(ae=-ee+$,te=Z));let Ce=0,ye=0;this.IsEqual(ae,0)?Ce=0:Ce=ae/te,this.IsEqual(Ae,0)?ye=0:ye=Ae/q;let Me=T+Ce*F-ye*R,Se=N+Ce*x-ye*w,Pe=G+Ce*b-ye*Q;return Me*Me+Se*Se+Pe*Pe}isNear(e,t=0,r){let i=g.HELP_0,a=g.HELP_1;i.copyFrom(e.origin),a.copyFrom(e.direction),a.scaleBy(9999),a.add(i,a),nt.cacluteLine0.set(i,a),nt.cacluteLine1.copyFrom(this),r&&(r.perspectiveMultiplyPoint3(nt.cacluteLine1.start,nt.cacluteLine1.start),r.perspectiveMultiplyPoint3(nt.cacluteLine1.end,nt.cacluteLine1.end));let s=nt.squreDistanceSegmentToSegment(nt.cacluteLine0,nt.cacluteLine1,r);return s+1e-4<=t?(e.length=s,!0):(e.length=-999999,!1)}}class Da{static ID=-1;v1;v2;v3;u1;u2;u3;n1;n2;n3;t0;t;u;v;min=new g;max=new g;id=0;constructor(e,t,r){this.id=Da.ID+++200,e&&t&&r&&this.set(e,t,r)}set(e,t,r){this.v1=e,this.v2=t,this.v3=r;let i=this.min,a=this.max;return i.x=Math.min(this.v1.x,this.v2.x,this.v3.x),i.y=Math.min(this.v1.y,this.v2.y,this.v3.y),i.z=Math.min(this.v1.z,this.v2.z,this.v3.z),a.x=Math.max(this.v1.x,this.v2.x,this.v3.x),a.y=Math.max(this.v1.y,this.v2.y,this.v3.y),a.z=Math.max(this.v1.z,this.v2.z,this.v3.z),this}getNormal(){let e=this.v1,t=this.v2,r=this.v3,i=new g(t.x-e.x,t.y-e.y,t.z-e.z),s=new g(r.x-e.x,r.y-e.y,r.z-e.z).crossProduct(i);return s.normalize(),s}turnBack(){let e=this.v3;this.v3=this.v1,this.v1=e}getLines(){let e=this.v1,t=this.v2,r=this.v3;return[new nt(e,t),new nt(t,r),new nt(r,e)]}equals(e){let t=this.getLines(),r=e.getLines(),i=0;for(let a=0;a<t.length;a++)for(let s=0;s<r.length;s++)t[a].equals(r[s])&&i++;return i==3}getCenter(){let e=this.min,t=this.max,r=new g;return r.x=(e.x+t.x)*.5,r.y=(e.y+t.y)*.5,r.z=(e.z+t.z)*.5,r}intersects(e){var t=this.max,r=this.min,i=e.max,a=e.min;return r.x<=i.x&&t.x>=a.x&&r.y<=i.y&&t.y>=a.y&&r.z<=i.z&&t.z>=a.z}sign2D(e,t,r){return(e.x-r.x)*(t.z-r.z)-(t.x-r.x)*(e.z-r.z)}pointInTriangle2D(e){let t=this.v1,r=this.v2,i=this.v3,a,s,o,l,h;return a=this.sign2D(e,t,r),s=this.sign2D(e,r,i),o=this.sign2D(e,i,t),l=a<0||s<0||o<0,h=a>0||s>0||o>0,!(l&&h)}toArray(){return[this.v1.x,this.v1.y,this.v1.z,this.v2.x,this.v2.y,this.v2.z,this.v3.x,this.v3.y,this.v3.z]}}class ff{static _pt0;static _pt1;static _pt2;static _pt3;static _hitPoint;static _worldMatrix;static _ray;static _triangle;static _isInit;static init(){this._pt0=new g,this._pt1=new g,this._pt2=new g,this._pt3=new g,this._ray=new Jt,this._triangle=new Da,this._hitPoint=new g,this._worldMatrix=new E}static rayPick(e,t,r,i,a,s,o){this._isInit||(this.init(),this._isInit=!0);let l=this._worldMatrix;if(i==Ht.World){let h;this.calculateHotArea_World(s,this._pt0,this._pt1,this._pt2,this._pt3),l.copyFrom(o).invert();let u=this._ray;if(u.copy(e).applyMatrix(l),this._triangle.set(this._pt0,this._pt1,this._pt2),h=u.intersectTriangle(u.origin,u.direction,this._triangle),h||(this._triangle.set(this._pt1,this._pt2,this._pt3),h=u.intersectTriangle(u.origin,u.direction,this._triangle)),h)return{distance:0,intersectPoint:h}}else{this.calculateHotArea_View(s,a,this._pt0,this._pt1,this._pt2,this._pt3);let h=r.x,u=r.y,f=Math.min(this._pt0.x,this._pt1.x,this._pt2.x,this._pt3.x)+h*.5,d=Math.min(this._pt0.y,this._pt1.y,this._pt2.y,this._pt3.y)+u*.5,m=Math.max(this._pt0.x,this._pt1.x,this._pt2.x,this._pt3.x)+h*.5,p=Math.max(this._pt0.y,this._pt1.y,this._pt2.y,this._pt3.y)+u*.5;return t.x<=m&&t.x>=f&&t.y<=p&&t.y>=d?(this._hitPoint.set(t.x,t.y,0),{distance:0,intersectPoint:this._hitPoint}):null}return null}static calculateHotArea_View(e,t,r,i,a,s){let o=e.getWorldMatrix(),l=o.getScaleX(),h=o.getScaleY(),u=e.width*.5*l,f=e.height*.5*h;r.set(-u,-f,0),i.set(u,-f,0),a.set(-u,f,0),s.set(u,f,0);let d=o.tx;r.x+=d,i.x+=d,a.x+=d,s.x+=d,d=o.ty,r.y-=d,i.y-=d,a.y-=d,s.y-=d,r.multiplyScalar(t),i.multiplyScalar(t),a.multiplyScalar(t),s.multiplyScalar(t)}static calculateHotArea_World(e,t,r,i,a){let s=e.getWorldMatrix(),o=s.getScaleX(),l=s.getScaleY(),h=e.width*.5*o,u=e.height*.5*l;t.set(-h,u,0),r.set(h,u,0),i.set(-h,-u,0),a.set(h,-u,0);let f=s.tx;t.x+=f,r.x+=f,i.x+=f,a.x+=f,f=s.ty,t.y+=f,r.y+=f,i.y+=f,a.y+=f}}var df=(n=>(n[n.UpperLeft=0]="UpperLeft",n[n.UpperCenter=1]="UpperCenter",n[n.UpperRight=2]="UpperRight",n[n.MiddleLeft=3]="MiddleLeft",n[n.MiddleCenter=4]="MiddleCenter",n[n.MiddleRight=5]="MiddleRight",n[n.LowerLeft=6]="LowerLeft",n[n.LowerCenter=7]="LowerCenter",n[n.LowerRight=8]="LowerRight",n))(df||{}),gf=(n=>(n[n.Upper=0]="Upper",n[n.Middle=1]="Middle",n[n.Lower=2]="Lower",n))(gf||{}),mf=(n=>(n[n.Left=0]="Left",n[n.Center=1]="Center",n[n.Right=2]="Right",n))(mf||{});class pf{charList=[];quadList=[];width=0;index=0}class Af{layout(e){let t=[],r=e.originSize,i=Yi.getFontData(e.font,r),a=e.fontSize/r;return this.makeTextLine(e.uiTransform,e.alignment,t,e.font,i,e.text,a,r,e.lineSpacing),t}makeTextLine(e,t,r,i,a,s,o,l,h){let u=-1,f=0,d=l*o,m=d*.5,p=e.width/o,U=e.height/o,B=0,v=e.height,C=()=>{f=0,u++;let b=new pf;return b.index=u,r.push(b),b},_=(b,R)=>{const w=b.charCodeAt(0).toString();let Q=Yi.getFnt(i,l,w),T=null;return Q?(T=Br.spawnQuad(),T.sprite=Q,T.x=(f+Q.xoffset)*o-B,T.y=(a.base-Q.height-Q.yoffset-a.base)*o+v,T.width=Q.offsetSize.width*o,T.height=Q.offsetSize.height*o,f+=Q.xadvance):b==`
11628
11628
  `||(b==" "?f+=d:f+=m),R.width=f,R.quadList.push(T),R.charList.push(b),T},F=()=>{let b=this.getAlignment(t);switch(b.v){case 0:for(let R=0,w=r.length;R<w;R++){let Q=r[R];if(R>0){let T=R*d*h;for(let N=0,G=Q.quadList.length;N<G;N++){let Z=Q.quadList[N];Z&&(Z.y-=T)}}}break;case 1:for(let R=0,w=r.length;R<w;R++){let Q=r[R],T=(U-w*l*h)*.5*o+R*d*h;for(let N=0,G=Q.quadList.length;N<G;N++){let Z=Q.quadList[N];Z&&(Z.y-=T)}}break;case 2:for(let R=0,w=r.length;R<w;R++){let Q=r[R],T=(U-w*l*h)*o+R*d*h;for(let N=0,G=Q.quadList.length;N<G;N++){let Z=Q.quadList[N];Z&&(Z.y-=T)}}break}switch(b.h){case 0:break;case 1:for(let R=0,w=r.length;R<w;R++){let Q=r[R],T=(p-Q.width)*.5*o;for(let N=0,G=Q.quadList.length;N<G;N++){let Z=Q.quadList[N];Z&&(Z.x+=T)}}break;case 2:for(let R=0,w=r.length;R<w;R++){let Q=r[R],T=(p-Q.width)*o;for(let N=0,G=Q.quadList.length;N<G;N++){let Z=Q.quadList[N];Z&&(Z.x+=T)}}break}};(()=>{let b=null,R=s.length;for(let w=0;w<R;w++){b||=C();let Q=s.charAt(w);Q==`
11629
- `||Q==" "?b=null:(_(Q,b),b.width+m>=p&&(b=C()))}})(),F()}getAlignment(e){let t={v:0,h:0};switch(e){case 1:t.v=0,t.h=1;break;case 0:t.v=0,t.h=0;break;case 2:t.v=0,t.h=2;break;case 4:t.v=1,t.h=1;break;case 3:t.v=1,t.h=0;break;case 5:t.v=1,t.h=2;break;case 7:t.v=2,t.h=1;break;case 6:t.v=2,t.h=0;break;case 8:t.v=2,t.h=2;break}return t}}class As extends qn{_style=Oe.NORMAL;_interactive=!1;set interactive(e){this._interactive=e}get interactive(){return this._interactive}set mouseStyle(e){this._style=e}get interactiveVisible(){return this._uiTransform.globalVisible&&this._visible}init(e){super.init(e),this._uiTransform.addUIInteractive(this)}destroy(){this._uiTransform.removeUIInteractive(this),super.destroy()}rayPick(e,t,r,i){return ff.rayPick(e,r,i,t.space,t.panelRatio,this._uiTransform,t.transform.worldMatrix)}cloneTo(e){e.getOrAddComponent(As).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this.enable=e._enable,this.interactive=e._interactive,this.mouseStyle=e._style,this}}var Uf=(n=>(n[n.NONE=0]="NONE",n[n.COLOR=1]="COLOR",n[n.SPRITE=2]="SPRITE",n))(Uf||{});class $n extends As{_spriteMap;_colorMap;_image;_isCreateImage;_transition=2;init(e){super.init(e),this._interactive=!0,this._spriteMap=new Map,this._colorMap=new Map,this._image=this.object3D.getComponent(Fi),this._isCreateImage=this._image==null,this._image||(this._image=this.object3D.addComponent(Fi)),this.imageType=Hi.Sliced}onEnable(){this.mouseStyle=Oe.NORMAL}onDisable(){this.mouseStyle=Oe.DISABLE}set transition(e){this._transition!=e&&(this._transition=e,this.validateStyle(this._style,!0))}get transition(){return this._transition}get imageType(){return this._image.imageType}set imageType(e){this._image.imageType=e}setStyleColor(e,t){return this._colorMap.set(e,t),this._style==e&&this.validateStyle(this._style,!0),this}getStyleColor(e){return this._colorMap.get(e)}set mouseStyle(e){super.mouseStyle=e,this.validateStyle(e,!0)}get normalSprite(){return this._spriteMap.get(Oe.NORMAL)}set normalSprite(e){this._spriteMap.set(Oe.NORMAL,e),this._style==Oe.NORMAL&&this.validateStyle(this._style,!0)}get overSprite(){return this._spriteMap.get(Oe.OVER)}set overSprite(e){this._spriteMap.set(Oe.OVER,e),this._style==Oe.OVER&&this.validateStyle(this._style,!0)}set downSprite(e){this._spriteMap.set(Oe.DOWN,e),this._style==Oe.DOWN&&this.validateStyle(this._style,!0)}get downSprite(){return this._spriteMap.get(Oe.DOWN)}set disableSprite(e){this._spriteMap.set(Oe.DISABLE,e),this._style==Oe.DISABLE&&this.validateStyle(this._style,!0)}get disableSprite(){return this._spriteMap.get(Oe.DISABLE)}validateStyle(e,t){if(this._transition&2){let r=this._spriteMap.get(e);this._image.sprite=r}if(this._transition&1){let r=this._colorMap.get(e);r&&(this._image.color=r)}}cloneTo(e){e.getOrAddComponent($n).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this.imageType=e.imageType,this.transition=e.transition,e._spriteMap.forEach((t,r)=>{t&&this._spriteMap.set(r,t)}),e._colorMap.forEach((t,r)=>{t&&this._colorMap.set(r,t.clone())}),this.mouseStyle=e.mouseStyle,this}destroy(){this._isCreateImage&&this._image&&(this.object3D.removeComponent(Fi),this._image=null),super.destroy()}}class eo extends wa{_count=0;constructor(){super()}init(e){super.init?.(e),this._count=e?e.count:1;for(let t=0;t<this._count;t++)this.attachQuad(Br.spawnQuad());this._uiTransform.resize(0,0)}getQuad(e){return this._mainQuads[e]}cloneTo(e){e.addComponent(eo,{count:this._count}).copyComponent(this)}copyComponent(e){super.copyComponent(e);for(let t=0;t<e._count;t++)this.setSprite(t,e.getSprite(t)),this.setColor(t,e.getColor(t)),this.setImageType(t,e.getImageType(t));return this}setSprite(e,t){this._mainQuads[e].sprite=t||A.res.defaultGUISprite,this.setShadowDirty()}getSprite(e){return this._mainQuads[e].sprite}onUIComponentVisible(e){this.applyComponentVisible()}onUITransformVisible(e){this.applyComponentVisible()}applyComponentVisible(){let e=!this._visible||!this._uiTransform.globalVisible;for(let t of this._mainQuads)t.visible=!e;this.setShadowDirty()}getColor(e){return this._mainQuads[e].color}setColor(e,t){this._mainQuads[e].color=t,this.setShadowDirty()}getImageType(e){return this._mainQuads[e].imageType}setImageType(e,t){this._mainQuads[e].imageType=t,this.setShadowDirty()}setSize(e,t,r){this._mainQuads[e].setSize(t,r),this.setShadowDirty()}setXY(e,t,r){this._mainQuads[e].setXY(t,r),this.setShadowDirty()}getXY(e,t){t||=new j;let r=this._mainQuads[e];return t.x=r.x,t.y=r.y,t}}class to extends wa{_shadowQuality=1;_shadowOffset;_shadowRadius;_shadowColor;_subShadowColor;needUpdateShadow=!1;init(e){super.init?.(e),this._shadowRadius=2,this._shadowQuality=1,this._shadowOffset=new j(4,-4),this._shadowColor=new k(.1,.1,.1,.8),this._subShadowColor=this._shadowColor.clone(),this.isUIShadow=!0}cloneTo(e){e.getOrAddComponent(to).copyComponent(this)}copyComponent(e){return super.copyComponent(this),this._shadowColor=e._shadowColor,this._shadowOffset=e._shadowOffset,this._shadowRadius=e._shadowRadius,this._shadowQuality=e.shadowQuality,this}get shadowColor(){return this._shadowColor}set shadowColor(e){this._shadowColor.copyFrom(e),this.needUpdateShadow=!0}set shadowQuality(e){e=ie(e,0,4),this._shadowQuality!=e&&(this._shadowQuality=e,this.needUpdateShadow=!0)}get shadowQuality(){return this._shadowQuality}set shadowOffset(e){this._shadowOffset=e,this.needUpdateShadow=!0}get shadowOffset(){return this._shadowOffset||=new j(4,-4),this._shadowOffset}set shadowRadius(e){this._shadowRadius!=e&&(this._shadowRadius=e,this.applyShadow())}get shadowRadius(){return this._shadowRadius}onUpdate(e){this.needUpdateShadow&&(this.applyShadow(),this.needUpdateShadow=!1)}applyShadow(){if(this.detachQuads(),this._shadowSource&&this._shadowQuality>0){let e=this._shadowSource.mainQuads;if(e.length>0)for(let t of e)this.createQuadShadow(t)}this._uiTransform.setNeedUpdateUIPanel()}createQuadShadow(e){let t=this._shadowQuality,r=Math.PI*2;this._subShadowColor.copyFrom(this._shadowColor),this._subShadowColor.a=1/Math.max(1,t);for(let i=0;i<t;i++){let a=Br.spawnQuad(),s=0,o=0;if(i==0)a.color=this._shadowColor;else{let l=r*(i-1)/(t-1);s=Math.sin(l)*this._shadowRadius,o=Math.cos(l)*this._shadowRadius,a.color=this._subShadowColor}a.setXY(s+this._shadowOffset.x+e.x,o+this._shadowOffset.y+e.y),a.setSize(e.width,e.height),a.sprite=e.sprite,a.visible=e.visible,a.imageType=e.imageType,this.attachQuad(a)}}}class ro extends wa{_font="\u5FAE\u8F6F\u96C5\u9ED1";_fontSize=14;_originSize=42;_alignment=0;_lineSpacing=1;_text="";_color=new k(1,1,1,1);constructor(){super()}cloneTo(e){e.getOrAddComponent(ro).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this._font=e._font,this._fontSize=e._fontSize,this._originSize=e._originSize,this._alignment=e._alignment,this._lineSpacing=e._lineSpacing,this._color.copyFrom(e._color),this.text=e.text,this}get originSize(){return this._originSize}get font(){return this._font}set font(e){this._font=e}get fontSize(){return this._fontSize}set fontSize(e){this._fontSize!=e&&(this._fontSize=e,this.layoutText())}get text(){return this._text}set text(e){this._text!=e&&(e||(e=""),this._text=e,this.layoutText())}textLine=null;layoutProxy=new Af;layoutText(){this.detachQuads(),this.textLine=this.layoutProxy.layout(this);for(let e=0,t=this.textLine.length;e<t;e++){let r=this.textLine[e];for(let i=0,a=r.quadList.length;i<a;i++){let s=r.quadList[i];s&&this.attachQuad(s)}}this.color=this._color,this._uiTransform.setNeedUpdateUIPanel(),this.onUIComponentVisible(this._visible),this.setShadowDirty()}onUIComponentVisible(e){this.applyComponentVisible()}onUITransformVisible(e){this.applyComponentVisible()}applyComponentVisible(){let e=!this._visible||!this._uiTransform.globalVisible;for(let t of this._mainQuads)t&&(t.visible=!e);this.setShadowDirty()}onTransformResize(){this.layoutText()}get color(){return this._color}set color(e){this._color.copyFrom(e);for(let t of this._mainQuads)t.color=e;this.setShadowDirty()}get alignment(){return this._alignment}set alignment(e){this._alignment!=e&&(this._alignment=e,this.layoutText())}get lineSpacing(){return this._lineSpacing}set lineSpacing(e){this._lineSpacing!=e&&(this._lineSpacing=e,this.layoutText())}}var up=Object.getOwnPropertyDescriptor,cp=(n,e,t,r)=>{for(var i=r>1?void 0:r?up(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.Light=class extends Ua{constructor(){super()}init(){super.init(),this.lightData.lightType=Ye.PointLight,this.object3D.name==""&&(this.object3D.name="PointLight"+bt())}get range(){return this.lightData.range}set range(e){this.lightData.range=e,this.onChange()}get at(){return this.lightData.linear}set at(e){this.lightData.linear=e,this.onChange()}get radius(){return this.lightData.radius}set radius(e){this.lightData.radius=e,this.onChange()}get quadratic(){return this.lightData.quadratic}set quadratic(e){this.lightData.quadratic=e,this.onChange()}start(){this.transform.rotationX=90,super.start()}onUpdate(){}onGraphic(e){let t=e.scene.getChildByName("graphic3D");if(!t)return;let r=t.createCustomShape(`PointLight_${this.object3D.instanceID}`,this.transform);r.buildAxis(),r.buildCircle(g.ZERO,this.range,32,g.X_AXIS),r.buildCircle(g.ZERO,this.range,32,g.Y_AXIS),r.buildCircle(g.ZERO,this.range,32,g.Z_AXIS)}debug(){}debugDraw(e){}},c.Light=cp([Pt(c.Light,"Light")],c.Light);var fp=Object.getOwnPropertyDescriptor,dp=(n,e,t,r)=>{for(var i=r>1?void 0:r?fp(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.FatLineRenderer=class extends kr{_fatLineMaterial=null;_fatLineGeometry=null;constructor(){super()}onEnable(){super.onEnable()}onDisable(){super.onDisable()}cloneTo(e){e.addComponent(c.FatLineRenderer).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this}set geometry(e){super.geometry=e,this._fatLineGeometry=e,e&&(this.instanceCount=e.instanceCount,this._fatLineMaterial&&e.instanceBuffer&&this._fatLineMaterial.setInstanceBuffer(e.instanceBuffer))}get geometry(){return this._fatLineGeometry}set material(e){this.materials=[e],this._fatLineMaterial=e,this._fatLineGeometry&&this._fatLineGeometry.instanceBuffer&&e.setInstanceBuffer(this._fatLineGeometry.instanceBuffer)}get material(){return this._fatLineMaterial}nodeUpdate(e,t,r,i){if(this._fatLineMaterial&&this.object3D){this._fatLineMaterial.setModelMatrix(this.object3D.transform.worldMatrix);const a=I.presentationSize[0],s=I.presentationSize[1];a>0&&s>0&&(this._fatLineMaterial.resolution=new j(a,s))}super.nodeUpdate(e,t,r,i)}},c.FatLineRenderer=dp([Pt(c.FatLineRenderer,"FatLineRenderer")],c.FatLineRenderer);class Bf extends c.Object3D{index=0;drawCallFrame=-1;constructor(){super()}}var io=(n=>(n[n.CastGI=0]="CastGI",n[n.ReceiveGI=1]="ReceiveGI",n[n.CastDepth=2]="CastDepth",n[n.Other=3]="Other",n))(io||{});class vf extends ft{static count=0;constructor(e=0,t=0){super(),z.register("GIProbeShader",Nc);let r=new at,i=new Ne("GIProbeShader","GIProbeShader");i.passType=H.COLOR,r.addRenderPass(i),i.setDefine("USE_BRDF",!0),i.setShaderEntry("VertMain","FragMain"),i.setUniformVector4("probeUniform",new K(t,e,0,0));let a=i.shaderState;a.acceptShadow=!1,a.castShadow=!1,a.receiveEnv=!1,a.acceptGI=!1,a.useLight=!1,r.setTexture("baseMap",A.res.whiteTexture),r.setTexture("normalMap",A.res.normalTexture),r.setTexture("emissiveMap",A.res.blackTexture),this.shader=r}}class gp extends Ve{_probes;_volume;_debugMr=[];init(e){e||=A.views[0]?.scene,A.setting.gi.enable=!0,this._volume=oe.getLightEntries(e).irradianceVolume,this.initProbe(e)}initProbe(e){let t=this._volume.setting.probeXCount,r=this._volume.setting.probeYCount,i=this._volume.setting.probeZCount,a=new Ci(4,16,16),s=new g;this._probes=[];for(let o=0;o<t;o++)for(let l=0;l<r;l++)for(let h=0;h<i;h++){let u=o+h*t+l*(t*i),f=new Bf;f.index=u,f.name=`${o}_${l}_${h}`;let d=f.addComponent(c.MeshRenderer);d.material=new vf(io.CastGI,u),d.geometry=a,d.castGI=!1,d.castShadow=!1,this._debugMr.push(d),this.object3D.addChild(f),this._volume.calcPosition(o,l,h,s),f.x=s.x,f.y=s.y,f.z=s.z,this._probes[u]=f,this._debugMr.push(d)}for(let o=0;o<this._probes.length;o++)W.instance.addGIProbe(e,this._probes[o]);this.object3D.transform.enable=!1,this._volume.setting.debug&&this.debug()}debug(){}debugProbeRay(e,t){const r=A.setting.gi.rayNumber;let i=new Y(0,-.7071067811865475,.7071067811865475,0);for(let a=0;a<r;a++){let s=e*r+a,o=new g(-t[s*4+0],-t[s*4+1],-t[s*4+2],0);i.transformVector(o,o);let l=t[s*4+3],h=this._probes[e].transform.worldPosition.clone(),u=o.scaleBy(l);u.add(h,u)}}changeProbesVolumeData(){this._volume.setVolumeDataChange()}changeProbesPosition(){this._volume.setVolumeDataChange();let e=this._volume.setting.probeXCount,t=this._volume.setting.probeYCount,r=this._volume.setting.probeZCount,i=new g;for(let a=0;a<e;a++)for(let s=0;s<t;s++)for(let o=0;o<r;o++){let l=a+o*e+s*(e*r),h=this._probes[l];this._volume.calcPosition(a,s,o,i),h.x=i.x,h.y=i.y,h.z=i.z}}onUpdate(){A.setting.gi.maxDistance=A.setting.gi.probeSpace*1.5;let e=this.transform.scene3D.view.camera,t=g.distance(e.transform.worldPosition,e.transform.targetPos)/300;if(this._debugMr&&this._debugMr.length>0)for(let r=0;r<this._debugMr.length;r++){const i=this._debugMr[r].transform;i.scaleX=t,i.scaleY=t,i.scaleZ=t}}}class mp extends kr{_keyRenderGroup;_keyBufferGroup;_keyIdsGroup;constructor(){super()}init(e){this._keyRenderGroup=new Map,this._keyBufferGroup=new Map,this._keyIdsGroup=new Map}start(){let e=[];this.object3D.getComponents(c.MeshRenderer,e,!0);for(let t=0;t<e.length;t++){const r=e[t];r.transform.updateWorldMatrix(!0),r.enable=!1;let i=r.geometry.instanceID;for(let a=0;a<r.materials.length;a++){const s=r.materials[a];i+=s.instanceID}if(this._keyRenderGroup.has(i))this._keyRenderGroup.get(i).push(r),this._keyIdsGroup.get(i).push(r.transform.worldMatrix.index);else{let a=new Be(e.length);a.visibility=GPUShaderStage.VERTEX,this._keyRenderGroup.set(i,[r]),this._keyBufferGroup.set(i,a),this._keyIdsGroup.set(i,[r.transform.worldMatrix.index])}}this._keyBufferGroup.forEach((t,r)=>{let i=this._keyIdsGroup.get(r),a=this._keyBufferGroup.get(r);a.setInt32Array("matrixIDs",new Int32Array(i)),a.apply()})}reset(){this._keyRenderGroup.size>0&&(this._keyRenderGroup.clear(),this._keyBufferGroup.clear(),this._keyIdsGroup.clear(),this.start())}nodeUpdate(e,t,r,i){this._keyRenderGroup.forEach((a,s)=>{let o=this._keyBufferGroup.get(s),l=a[0];for(let h=0;h<l.materials.length;h++){let f=l.materials[h].getPass(t);if(f)for(let d=0;d<f.length;d++){const m=f[d];m.setDefine("USE_INSTANCEDRAW",!0),m.setStorageBuffer("instanceDrawID",o)}}l.nodeUpdate(e,t,r,i)})}renderPass(e,t,r){this._keyRenderGroup.forEach((i,a)=>{let s=i[0];s.instanceCount=i.length,this.renderItem(e,t,s,r)})}renderItem(e,t,r,i){let a=r.transform._worldMatrix;for(let s=0;s<r.materials.length;s++){let l=r.materials[s].getPass(t);if(!(!l||l.length==0))for(let h=0;h<l.length;h++){let u=l[h];y.bindGeometryBuffer(i.encoder,r.geometry);const f=u;f.shaderState.splitTexture&&(i.endRenderPass(),mt.WriteSplitColorTexture(r.instanceID),i.beginOpaqueRenderPass(),y.bindCamera(i.encoder,e.camera),y.bindGeometryBuffer(i.encoder,r.geometry)),y.bindPipeline(i.encoder,f);let U=r.geometry.subGeometries[s].lodLevels[r.lodLevel];r.instanceCount>0?y.drawIndexed(i.encoder,U.indexCount,r.instanceCount,U.indexStart,0,0):y.drawIndexed(i.encoder,U.indexCount,1,U.indexStart,0,a.index)}}}beforeDestroy(e){this._keyRenderGroup.clear(),this._keyBufferGroup.clear(),this._keyIdsGroup.clear(),this._keyRenderGroup=this._keyBufferGroup=this._keyIdsGroup=void 0,_e.removeWaitStart(this.object3D,this)}}var pp=Object.getOwnPropertyDescriptor,Ap=(n,e,t,r)=>{for(var i=r>1?void 0:r?pp(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.MeshFilter=class extends c.MeshRenderer{constructor(){super()}get geometry(){return null}set geometry(e){}cloneTo(e){}set meshURL(e){let t=A.res.getGeometry(e);t?this.geometry=t:console.error("no geometry set",e)}},c.MeshFilter=Ap([Pt(c.MeshFilter,"MeshFilter")],c.MeshFilter);var Up=Object.getOwnPropertyDescriptor,Bp=(n,e,t,r)=>{for(var i=r>1?void 0:r?Up(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.SkinnedMeshRenderer=class extends c.MeshRenderer{skinJointsName;mInverseBindMatrixData;mInverseBindMatrixBuffer;mSkeletonAnimation;mJointIndexTableBuffer;constructor(){super(),this.addRendererMask(Ue.SkinnedMesh)}start(){if(super.start(),this.skeletonAnimation=this.object3D.getComponent(c.SkeletonAnimationComponent),!this.skeletonAnimation){let e=this.object3D.parentObject.parentObject.getComponentsInChild(c.SkeletonAnimationComponent);e.length>0&&(this.skeletonAnimation=e[0]);let t=this.object3D;for(;!this.skeletonAnimation&&t;)this.skeletonAnimation=t.getComponentFromParent(c.SkeletonAnimationComponent),t.parent&&(t=t.parent.object3D)}}onEnable(){super.onEnable()}get skeletonAnimation(){return this.mSkeletonAnimation}set skeletonAnimation(e){if(this.mSkeletonAnimation=e,!!e&&!this.mJointIndexTableBuffer){let t=this.mSkeletonAnimation.getJointIndexTable(this.skinJointsName);this.mJointIndexTableBuffer=new Be(t.length*4,0,new Float32Array(t)),this.mJointIndexTableBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.COMPUTE}}get skinInverseBindMatrices(){return this.mInverseBindMatrixData}set skinInverseBindMatrices(e){this.mInverseBindMatrixData=e;var t=new Float32Array(e.length*16);for(let r=0;r<e.length;r++){let i=r*16,a=e[r];t.set(a,i)}this.mInverseBindMatrixBuffer=new Be(t.byteLength,0,t),this.mInverseBindMatrixBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.COMPUTE}get inverseBindMatrixBuffer(){return this.mInverseBindMatrixBuffer}get jointIndexTableBuffer(){return this.mJointIndexTableBuffer.buffer}cloneTo(e){let t=e.addComponent(c.SkinnedMeshRenderer);t.geometry=this.geometry,t.material=this.material.clone(),t.castShadow=this.castShadow,t.castGI=this.castGI,t.receiveShadow=this.receiveShadow,t.rendererMask=this.rendererMask,t.skinJointsName=this.skinJointsName,t.skinInverseBindMatrices=this.skinInverseBindMatrices,t.mJointIndexTableBuffer=this.mJointIndexTableBuffer}nodeUpdate(e,t,r,i){for(let a=0;a<this.materials.length;a++){let o=this.materials[a].getPass(t);if(o)for(let l=0;l<o.length;l++){const h=o[l];!h.pipeline&&this.mSkeletonAnimation&&(h.setStorageBuffer("jointsMatrixIndexTable",this.mSkeletonAnimation.jointMatrixIndexTableBuffer),h.setStorageBuffer("jointsInverseMatrix",this.mInverseBindMatrixBuffer),h.setStorageBuffer("jointsIndexMapingTable",this.mJointIndexTableBuffer))}}super.nodeUpdate(e,t,r,i)}},c.SkinnedMeshRenderer=Bp([Pt(c.SkinnedMeshRenderer,"SkinnedMeshRenderer")],c.SkinnedMeshRenderer);class vp extends Ke{radius=2.5;height=10;constructor(){super(),this._shapeType=ji.Capsule}}class Us extends Ke{mesh;static triangle;_pickRet;constructor(){super(),this._shapeType=ji.Mesh}rayPick(e,t){if(this.mesh){Us.triangle||=new Da(new g,new g,new g);let r=this.mesh.getAttribute(V.position),i=this.mesh.getAttribute(V.indices),a=Ke.helpMatrix;a.copyFrom(t).invert();let s=Ke.helpRay.copy(e);if(s.applyMatrix(a),s.intersectBox(this.mesh.bounds),!s.intersectBox(this.mesh.bounds,Ke.v3_help_0))return null;if(i&&r&&i.data.length>0){let l=r.data;for(let h=0,u=i.data.length/3;h<u;h++){let f=h*3;const d=i.data[f+0]*3,m=i.data[f+1]*3,p=i.data[f+2]*3;let U=Us.triangle,B=U.v1.set(l[d+0],l[d+1],l[d+2]),v=U.v2.set(l[m+0],l[m+1],l[m+2]),C=U.v3.set(l[p+0],l[p+1],l[p+2]);U.set(B,v,C);let _=s.intersectTriangle(s.origin,s.direction,U);if(_){this._pickRet||={intersectPoint:new g,distance:0},this._pickRet.intersectPoint=_,this._pickRet.distance=g.distance(s.origin,_);let F=this.mesh.getAttribute(V.normal);if(F){let x=F.data,b=new g(x[d],x[d+1],x[d+2]);t.transformVector(b,b),b.normalize(),this._pickRet.normal=b}return this._pickRet}}}}return null}}class Cp extends Ke{_pickRet;box;radius=.5;constructor(e){super(),this._shapeType=ji.Sphere,this.radius=e,this.box=new xa(new g,1)}rayPick(e,t){this.box.setFromCenterAndSize(this.center,this.radius);let i=Ke.helpMatrix;i.copyFrom(t).invert();let a=Ke.helpRay.copy(e);a.applyMatrix(i);let s=a.intersectSphere(a.origin,a.direction,this.box.center,this.box.radius);return s?(this._pickRet||(this._pickRet={intersect:!1,intersectPoint:new g,distance:0}),this._pickRet.intersect=!0,this._pickRet.intersectPoint=s,this._pickRet.distance=g.distance(a.origin,Ke.v3_help_0),this._pickRet):null}}class Sp extends c.Object3D{_envMap;skyObject;envMapChange=!0;view;constructor(){super(),this.transform.scene3D=this,this.skyObject=new c.Object3D,this.addChild(this.skyObject),this._isScene3D=!0,this.envMap||=A.res.defaultSky}get envMap(){return this._envMap}set envMap(e){this._envMap!=e&&(this.envMapChange=!0),this._envMap=e,W.instance.sky&&"map"in W.instance.sky&&(W.instance.sky.map=e)}get exposure(){return W.instance.sky&&"exposure"in W.instance.sky?W.instance.sky.exposure:0}set exposure(e){W.instance.sky&&"exposure"in W.instance.sky&&(W.instance.sky.exposure=e,A.setting.sky.skyExposure=e)}get roughness(){if(W.instance.sky&&"roughness"in W.instance.sky)return W.instance.sky.roughness}set roughness(e){W.instance.sky&&"roughness"in W.instance.sky&&(W.instance.sky.roughness=e)}}class Cf{_computeShader;_outBuffer;constructor(){}init(){let e=ne.getGBufferFrame(ne.colorPass_GBuffer);this._computeShader=new ue(vc),this._outBuffer=new Ji(32),this._computeShader.setStorageBuffer("outBuffer",this._outBuffer),this._computeShader.setSamplerTexture("gBufferTexture",e.getCompressGBufferTexture())}compute(e){let t=oe.getCameraGroup(e.camera);this._computeShader.setStorageBuffer("globalUniform",t.uniformGPUBuffer);let r=y.beginCommandEncoder();y.computeCommand(r,[this._computeShader]),y.endCommandEncoder(r),this._outBuffer.readBuffer()}getPickMeshID(){var e=this._outBuffer.outFloat32Array[0]+.1;return Math.floor(e)}getPickWorldPosition(e){e||=new g;var t=this._outBuffer.outFloat32Array[4],r=this._outBuffer.outFloat32Array[5],i=this._outBuffer.outFloat32Array[6];return e.set(t,r,i),e}getPickWorldNormal(e){e||=new g;var t=this._outBuffer.outFloat32Array[8],r=this._outBuffer.outFloat32Array[9],i=this._outBuffer.outFloat32Array[10];return e.set(t*2-1,r*2-1,i*2-1).normalize(),e}getPickScreenUV(e){e||=new j;var t=this._outBuffer.outFloat32Array[2],r=this._outBuffer.outFloat32Array[3];return e.set(t,r),e}}class Sf extends wr{ray;isTouching=!1;_mouseCode;_pickEvent;_outEvent;_overEvent;_upEvent;_downEvent;_mouseMove;_pickCompute;_lastDownTarget;mouseEnableMap;_view;constructor(e){super(),this._view=e,this.init()}init(){this.ray=new Jt,this.mouseEnableMap=new Map,this._pickEvent=new L(L.PICK_CLICK),this._outEvent=new L(L.PICK_OUT),this._overEvent=new L(L.PICK_OVER),this._mouseMove=new L(L.PICK_MOVE),this._upEvent=new L(L.PICK_UP),this._downEvent=new L(L.PICK_DOWN)}start(){A.setting.pick.enable&&(A.inputSystem.addEventListener(L.POINTER_DOWN,this.onTouchStart,this),A.inputSystem.addEventListener(L.POINTER_UP,this.onTouchEnd,this),A.inputSystem.addEventListener(L.POINTER_CLICK,this.onTouchOnce,this),A.inputSystem.addEventListener(L.POINTER_RIGHT_CLICK,this.onTouchOnce,this),A.inputSystem.addEventListener(L.POINTER_MOVE,this.onTouchMove,this)),A.setting.pick.mode=="pixel"&&(this._pickCompute=new Cf,this._pickCompute.init())}stop(){A.inputSystem.removeEventListener(L.POINTER_DOWN,this.onTouchStart,this),A.inputSystem.removeEventListener(L.POINTER_UP,this.onTouchEnd,this),A.inputSystem.removeEventListener(L.POINTER_CLICK,this.onTouchOnce,this),A.inputSystem.removeEventListener(L.POINTER_RIGHT_CLICK,this.onTouchOnce,this),A.inputSystem.removeEventListener(L.POINTER_MOVE,this.onTouchMove,this)}onTouchStart(e){this.isTouching=!0,this._mouseCode=e.mouseCode,this.pick(this._view.camera);let t=this.findNearestObj(this._interestList,this._view.camera);this._lastDownTarget=t,t&&(Object.assign(this._downEvent,e),this._downEvent.type=L.PICK_DOWN,this._downEvent.target=t.object3D,this._downEvent.data=this.getPickInfo(),this.dispatchEvent(this._downEvent),t.object3D.containEventListener(L.PICK_DOWN)&&t.object3D.dispatchEvent(this._downEvent))}onTouchEnd(e){this.isTouching=!1,this._mouseCode=e.mouseCode,this.pick(this._view.camera);let t=this.findNearestObj(this._interestList,this._view.camera);t&&(Object.assign(this._upEvent,e),this._upEvent.type=L.PICK_UP,this._upEvent.target=t.object3D,this._upEvent.data=this.getPickInfo(),this.dispatchEvent(this._upEvent),t.object3D.containEventListener(L.PICK_UP)&&t.object3D.dispatchEvent(this._upEvent))}_lastFocus;getPickInfo(){if(A.setting.pick.mode=="pixel")return{worldPos:this._pickCompute.getPickWorldPosition(),worldNormal:this._pickCompute.getPickWorldNormal(),screenUv:this._pickCompute.getPickScreenUV(),meshID:this._pickCompute.getPickMeshID()};{let e=this._interestList[0];return{worldPos:e.intersectPoint,worldNormal:e.normal,meshID:e.collider.transform.worldMatrix.index,distance:e.distance}}}onTouchMove(e){this.isTouching=!0,this._mouseCode=e.mouseCode,this.pick(this._view.camera);let t=this.findNearestObj(this._interestList,this._view.camera);t&&(Object.assign(this._mouseMove,e),this._mouseMove.type=L.PICK_MOVE,this._mouseMove.target=t.object3D,this._mouseMove.data=this.getPickInfo(),this.dispatchEvent(this._mouseMove),t.object3D.containEventListener(L.PICK_MOVE)&&t.object3D.dispatchEvent(this._mouseMove)),t!=this._lastFocus&&(this._lastFocus&&this._lastFocus.object3D&&(Object.assign(this._outEvent,e),this._outEvent.type=L.PICK_OUT,this._outEvent.target=this._lastFocus.object3D,this._outEvent.data=this.getPickInfo(),this.dispatchEvent(this._outEvent),this._lastFocus.object3D.containEventListener(L.PICK_OUT)&&this._lastFocus.object3D.dispatchEvent(this._outEvent)),t&&(Object.assign(this._overEvent,e),this._overEvent.type=L.PICK_OVER,this._overEvent.target=t.object3D,this._overEvent.data=this.getPickInfo(),this.dispatchEvent(this._overEvent),t.object3D.containEventListener(L.PICK_OVER)&&t.object3D.dispatchEvent(this._overEvent))),this._lastFocus=t}onTouchOnce(e){this.isTouching=!0,this._mouseCode=e.mouseCode,this.pick(this._view.camera);let t=this.findNearestObj(this._interestList,this._view.camera);if(t){let r=this.getPickInfo();Object.assign(this._pickEvent,e),this._pickEvent.type=L.PICK_CLICK,this._pickEvent.target=t.object3D,this._pickEvent.data=r,this.dispatchEvent(this._pickEvent),t===this._lastDownTarget&&t.object3D.containEventListener(L.PICK_CLICK)&&t.object3D.dispatchEvent(this._pickEvent)}this._lastDownTarget=null}findNearestObj(e,t){return e.sort((r,i)=>r.distance>i.distance?1:-1),e[0]?.collider}_interestList=[];pick(e){if(this._interestList.length=0,A.setting.pick.mode=="pixel"){this._pickCompute.compute(this._view);let t=this._pickCompute.getPickMeshID(),r=this.mouseEnableMap.get(t);if(r){let i=this._pickCompute.getPickWorldPosition(),a=g.distance(i,this.ray.origin);this._interestList.push({distance:a,collider:r,intersectPoint:i})}}else if(A.setting.pick.mode=="bound"){this.ray=e.screenPointToRay(A.inputSystem.mouseX,A.inputSystem.mouseY);let t,r=_e.componentsEnablePickerList.get(this._view);if(r)for(const i of r){let a=i[0];a.enable&&(t=a.rayPick(this.ray),t&&(t.collider=a,this._interestList.push(t)))}}}}class _p extends Ja{_camera;_scene;_viewPort;_enablePick=!1;_enable=!0;pickFire;guiPick;canvasList;constructor(e=0,t=0,r=0,i=0){super(),this.canvasList=[],this._viewPort=new K(e,t,r,i)}get enable(){return this._enable}set enable(e){this._enable=e}get enablePick(){return this._enablePick}set enablePick(e){this._enablePick!=e&&(this.pickFire=new Sf(this),this.pickFire.start()),this._enablePick=e}get scene(){return this._scene}set scene(e){this._scene=e,e.view=this,It.createBuffer(this),e&&this.canvasList.forEach(t=>{t&&e.addChild(t.object3D)})}get camera(){return this._camera}set camera(e){this._camera=e}get viewPort(){return this._viewPort}set viewPort(e){this._viewPort=e}enableUICanvas(e=0){let t=this.canvasList[e];if(!t){let r=new c.Object3D;r.name="Canvas "+e,t=r.addComponent(Ia),t.index=e,this.canvasList[e]=t}return this.scene.addChild(t.object3D),this.guiPick||(this.guiPick=new hf,this.guiPick.init(this)),t}disableUICanvas(e=0){let t=this.canvasList[e];t&&t.object3D&&t.object3D.removeFromParent()}}class xp{normal;fixNormal;center;rotateShape;distance=0;index;constructor(e){this.index=e,this.rotateShape=[]}}class Fp extends Re{vScale;uNegate;sections;build(e,t,r,i=1,a=!0){if(r.length<2)throw new Error("path length is not enough");return this.vScale=i,this.uNegate=a,e=e.slice(),t&&e.push(e[0]),this.sections=this.buildSections(e,r),this.buildGeometry(e,this.sections),this.bounds=new xe(g.ZERO.clone(),new g(100,100,100)),this}buildSections(e,t){let r,i,a,s=[],o=t.length;for(let h=0;h<o;h++){let u=new xp(h);r=t[h],i=t[h+1],u.center=r.clone(),i==null?(u.normal=a.clone(),u.distance=0):(a=i.subtract(r),u.distance=a.length,u.normal=a.normalize()),s.push(u)}s[0].fixNormal=s[0].normal.clone();for(let h=1;h<o;h++){let u=s[h-1],f=s[h];f.fixNormal=f.normal.add(u.normal).normalize()}let l=new E().identity();for(let h=0;h<o;h++){let u=s[h],f,d;if(h==0)f=g.UP,d=e;else{let m=s[h-1];f=m.fixNormal,d=m.rotateShape}E.fromToRotation(f,u.fixNormal,l);for(let m=0,p=e.length;m<p;m++){let U=l.multiplyPoint3(d[m]);u.rotateShape.push(U)}}return s}buildGeometry(e,t){let r=t.length,i=e.length,a=r*i,s=r-1,o=new Float32Array(a*3),l=new Float32Array(a*3),h=new Float32Array(a*2),u=new Uint32Array(s*(i-1)*6),f=i-1,d=0,m=0,p=[0];for(let B=1;B<i;B++)m+=e[B-1].subtract(e[B]).length,p.push(m);for(let B=0;B<r;B++){let v=t[B];for(let C=0;C<i;C++){let _=(B*i+C)*3,F=v.rotateShape[C].add(v.center);o[_]=F.x,o[_+1]=F.y,o[_+2]=F.z,l[_+1]=1;let x=(B*i+C)*2,b=p[C]/m;h[x]=this.uNegate?1-b:b,h[x+1]=d*this.vScale}d+=v.distance}let U=0;for(let B=0;B<s;B++){let v=B*i;for(let C=0;C<f;C++){let _=C,F=C+1,x=_+i,b=F+i;u[U++]=_+v,u[U++]=F+v,u[U++]=x+v,u[U++]=F+v,u[U++]=b+v,u[U++]=x+v}}return this.setIndices(u),this.setAttribute(V.position,o),this.setAttribute(V.normal,l),this.setAttribute(V.uv,h),this.setAttribute(V.TEXCOORD_1,h),this.addSubGeometry({indexStart:0,indexCount:u.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0}),this.computeNormals(),this}}class yp extends Re{_instanceBuffer;_instanceData;_instanceCount=0;constructor(){super(),this.initBaseGeometry()}initBaseGeometry(){const e=new Float32Array([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0]),t=new Float32Array([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2]),r=new Uint16Array([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]);this.setIndices(r),this.setAttribute(V.position,e),this.setAttribute(V.uv,t),this.addSubGeometry({indexStart:0,indexCount:r.length,vertexStart:0,vertexCount:e.length/3,firstStart:0,index:0,topology:0})}setPositions(e){const t=e instanceof Float32Array?e:new Float32Array(e),i=t.length/3-1;if(i<=0)return console.warn("FatLineGeometry: Need at least 2 points"),this;const a=new Float32Array(i*16);for(let s=0;s<i;s++){const o=s*3,l=(s+1)*3;a[s*16+0]=t[o+0],a[s*16+1]=t[o+1],a[s*16+2]=t[o+2],a[s*16+3]=0,a[s*16+4]=t[l+0],a[s*16+5]=t[l+1],a[s*16+6]=t[l+2],a[s*16+7]=0,a[s*16+8]=1,a[s*16+9]=1,a[s*16+10]=1,a[s*16+11]=0,a[s*16+12]=1,a[s*16+13]=1,a[s*16+14]=1,a[s*16+15]=0}return this._instanceData=a,this._instanceCount=i,this.computeBoundingBox(t),this}setColors(e){const t=e instanceof Float32Array?e:new Float32Array(e);if(!this._instanceData)return console.warn("FatLineGeometry: Must call setPositions() before setColors()"),this;const i=t.length/3-1;if(i!==this._instanceCount)return console.warn("FatLineGeometry: Color array length doesn't match segment count"),this;for(let a=0;a<i;a++){const s=a*3,o=(a+1)*3;this._instanceData[a*16+8]=t[s+0],this._instanceData[a*16+9]=t[s+1],this._instanceData[a*16+10]=t[s+2],this._instanceData[a*16+12]=t[o+0],this._instanceData[a*16+13]=t[o+1],this._instanceData[a*16+14]=t[o+2]}return this}computeBoundingBox(e){const t=new g(1/0,1/0,1/0),r=new g(-1/0,-1/0,-1/0);for(let a=0;a<e.length;a+=3){const s=e[a],o=e[a+1],l=e[a+2];t.x=Math.min(t.x,s),t.y=Math.min(t.y,o),t.z=Math.min(t.z,l),r.x=Math.max(r.x,s),r.y=Math.max(r.y,o),r.z=Math.max(r.z,l)}const i=g.sub(r,t);this.bounds=new xe(g.ZERO.clone(),i),this.bounds.setFromMinMax(t,r)}get instanceData(){return this._instanceData}get instanceCount(){return this._instanceCount}get instanceBuffer(){return!this._instanceBuffer&&this._instanceData&&(this._instanceBuffer=new Be(this._instanceData.byteLength),this._instanceBuffer.setFloat32Array("",this._instanceData),this._instanceBuffer.apply()),this._instanceBuffer}updateInstanceBuffer(){this._instanceBuffer&&this._instanceData&&(this._instanceBuffer.setFloat32Array("",this._instanceData),this._instanceBuffer.apply())}}class bp{name;offset;size;arrayStride;stepMode;attributes}class Rp{name;format;offset;shaderLocation;stride}var _f=(n=>(n[n.position=3]="position",n[n.normal=3]="normal",n[n.TANGENT=4]="TANGENT",n[n.uv=2]="uv",n[n.TEXCOORD_1=2]="TEXCOORD_1",n[n.color=4]="color",n[n.joints0=4]="joints0",n[n.weights0=4]="weights0",n[n.joints1=4]="joints1",n[n.weights1=4]="weights1",n[n.vIndex=1]="vIndex",n[n.weight=1]="weight",n[n.a_morphPositions_0=3]="a_morphPositions_0",n))(_f||{});class Qp{get data(){return null}entity}class xf{min=0;max=0;set(e,t){return this.max=t,this.min=e,this}copy(e){return this.max=e.max,this.min=e.min,this}isInterestRange(e){return!(this.max>e.min||e.max<this.min)}}class Ff{_spaceDesc;getRange(e){return this._spaceDesc[e]}initSpace(e){this._spaceDesc={};for(let t of e)(this._spaceDesc[t]=new xf).set(-Number.MAX_VALUE,Number.MAX_VALUE);return this}isContain(e,t){let r=this._spaceDesc[e];return t>=r.min&&t<r.max}isInterestRange(e,t){let r=this._spaceDesc[e];return r?t.isInterestRange(r):!1}splitSpace(e,t,r){let i=this._spaceDesc[e];return t?i.max=r:i.min=r,this}copySpace(e){for(let t in e._spaceDesc){let r=e._spaceDesc[t];this._spaceDesc[t].copy(r)}return this}}class Ma{static MaxEntityCountInLeaf=4;static MaxLayer=10;static ClearLeafLayer=Ma.MaxLayer-4}class Pa{static UUID=0;uuid="0";constructor(){this.uuid=(Pa.UUID++).toString()}}class Ip{map={};_count=0;get count(){return this._count}push(e){return this.map[e.uuid]?!1:(this.map[e.uuid]=e,this._count++,!0)}remove(e){return this.map[e]?(delete this.map[e],this._count--,!0):!1}}class oi extends Pa{_dimensionIndex=0;_dimensions;_dimension;_left;_right;_space;_parent;_entities;layer;get dimension(){return this._dimension}constructor(e=0){super(),this.layer=e,oi.nodeCount++}initNode(e,t,r){return this._dimensions=t,this._dimensionIndex=r,this._dimension=t[r],this._space=new Ff().initSpace(t),e&&this._space.copySpace(e._space),this._parent=e,this._entities=new Ip,this}updateEntity(e){if(e.isInNode(this,this._dimension)&&(e.attachTreeNode(this),this.autoSplit(),this._left&&this._right)){let t=(this._dimensionIndex+1)%this._dimensions.length,r=this._dimensions[t];e.isInNode(this._right,r)?this._right.updateEntity(e):e.isInNode(this._left,r)&&this._left.updateEntity(e)}}buildRoot(e){for(const t of e)t.entity.attachTreeNode(this);this.autoSplit()}_splitEntityList=[];autoSplit(){if(this._entities.count>Ma.MaxEntityCountInLeaf&&!this._right&&!this._left&&this.layer<Ma.MaxLayer){let e=this._splitEntityList,t=(this._dimensionIndex+1)%this._dimensions.length,r=this._dimensions[t],i=0;for(const a in this._entities.map){let s=this._entities.map[a];i+=s.centerValue(r),e.push(s)}i/=this._entities.count,this._left=new oi(this.layer+1),this._right=new oi(this.layer+1),this._left.initNode(this,this._dimensions,t),this._right.initNode(this,this._dimensions,t),this._left.setSpace(!0,i),this._right.setSpace(!1,i);for(let a of e)a.isInNode(this._right,r)?a.attachTreeNode(this._right):a.isInNode(this._left,r)&&a.attachTreeNode(this._left)}this._left&&this._left.autoSplit(),this._right&&this._right.autoSplit()}setSpace(e,t){return this._parent&&this._space.splitSpace(this._dimension,e,t),this}isEmpty(){return this._left==null&&this._right==null&&this._entities.count==0}pushEntity(e){return this._entities.push(e)}removeEntity(e){return this._entities.remove(e.uuid)}static nodeCount=0;autoClear(){let e=this;for(;e&&e.layer>Ma.ClearLeafLayer&&e.clearLeaf();)e=e._parent}clearLeaf(){let e=!this._left&&!this._right,t=!e&&this._left.isEmpty()&&this._right.isEmpty();return t&&(this._left=this._right=null,oi.nodeCount-=2),e||t}isContain(e){return this._space.isContain(this._dimension,e)}static rangeBox=new xe(new g(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),new g(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE));nodeIntersectsBox(e){let t=this._space.getRange("x"),r=this._space.getRange("y"),i=this._space.getRange("z"),a=oi.rangeBox;return a.min.set(t.min,r.min,i.min),a.max.set(t.max,r.max,i.max),a.intersectsBox(e)}nodeIntersectsRay(e){let t=this._space.getRange("x"),r=this._space.getRange("y"),i=this._space.getRange("z"),a=oi.rangeBox;return a.min.set(t.min,r.min,i.min),a.max.set(t.max,r.max,i.max),!0}pointCast(e,t=0,r){if(r=r||[],this._entities.count>0){let i=this._entities.map;for(let a in i){let s=i[a],o=s.entityContainPoint(e);!o&&t>0&&(o=s.squareDistanceTo(e,this._dimensions)<=t),o&&r.push(s)}}this._left&&this._left.isContain(e[this._left.dimension])&&this._left.pointCast(e,t,r),this._right&&this._right.isContain(e[this._right.dimension])&&this._right.pointCast(e,t,r)}boxCast(e,t){if(t=t||[],this._entities.count>0){let r=this._entities.map;for(let i in r){let a=r[i];a.entityIntersectsBox(e)&&t.push(a)}}this._left&&this._left.nodeIntersectsBox(e)&&this._left.boxCast(e,t),this._right&&this._right.nodeIntersectsBox(e)&&this._right.boxCast(e,t)}pointIntersect=new g;rayCast(e,t,r){t=t||[],r=r||[];let i=this.pointIntersect;if(this._entities.count>0){let a=this._entities.map;for(let s in a){let o=a[s];o.entityIntersectsRay(e,i)&&(r.push(new g().copyFrom(i)),t.push(o))}}this._left&&this._left.nodeIntersectsRay(e)&&this._left.rayCast(e,t,r),this._right&&this._right.nodeIntersectsRay(e)&&this._right.rayCast(e,t,r)}}class Ep extends Pa{userData;node;constructor(e){super(),this.userData=e}centerValue(e){return 0}isInNode(e,t){return!1}entityContainPoint(e){return!1}squareDistanceTo(e,t){return Number.MAX_VALUE}entityIntersectsBox(e){return!1}entityIntersectsRay(e,t){return!1}attachTreeNode(e){return this.node&&this.detachTreeNode(),this.node=e,this.node.pushEntity(this)}detachTreeNode(){let e=this.node.removeEntity(this);return this.node=null,e}updateNode(e){let t=this.node;t&&this.detachTreeNode(),e.updateEntity(this),t&&t.autoClear()}}class vt{minPosX=0;minPosY=0;maxPosX=0;maxPosY=0;testID=0;points;offsetPosition;static TINY=1e-6;constructor(){this.points=new Array,this.offsetPosition=new g(0,0,0,0),this.clear()}setAABox(e,t,r,i){this.minPosX=e-r/2-vt.TINY,this.maxPosX=e+r/2+vt.TINY,this.minPosY=t-i/2-vt.TINY,this.maxPosY=t+i/2+vt.TINY,this.offsetPosition.setTo(0,0,0)}setOffset(e){this.maxPosX+=e.x-this.offsetPosition.x,this.minPosX+=e.x-this.offsetPosition.x,this.minPosY+=e.z-this.offsetPosition.z,this.maxPosY+=e.z-this.offsetPosition.z,this.offsetPosition.copyFrom(e)}setContainRect(e,t,r,i){this.minPosX>e&&(this.minPosX=e),this.minPosY>t&&(this.minPosY=t),this.maxPosX<r&&(this.maxPosX=r),this.maxPosY<i&&(this.maxPosY=i)}clear(){var e=1e9;this.minPosX=this.minPosY=e,this.maxPosX=this.maxPosY=-e,this.points.length=0,this.testID=0,this.offsetPosition.setTo(0,0,0)}addPoint(e){this.points.indexOf(e)==-1&&(e.x<this.minPosX&&(this.minPosX=e.x-vt.TINY),e.x>this.maxPosX&&(this.maxPosX=e.x+vt.TINY),e.z<this.minPosY&&(this.minPosY=e.z-vt.TINY),e.z>this.maxPosY&&(this.maxPosY=e.z+vt.TINY),this.points.push(e))}clone(){var e=new vt;return e.minPosX=this.minPosX,e.minPosY=this.minPosY,e.maxPosX=this.maxPosX,e.maxPosY=this.maxPosY,e}get radius(){return Math.sqrt((this.maxPosY-this.minPosY)*(this.maxPosY-this.minPosY)+(this.maxPosX-this.minPosX)*(this.maxPosX-this.minPosX))}get sideX(){return this.maxPosX-this.minPosX}get sideY(){return this.maxPosY-this.minPosY}get centreX(){return(this.maxPosX-this.minPosX)*.5+this.minPosX}get centreY(){return(this.maxPosY-this.minPosY)*.5+this.minPosY}overlapTest(e){return!(this.minPosY>=e.maxPosY||this.maxPosY<=e.minPosY||this.minPosX>=e.maxPosX||this.maxPosX<=e.minPosX)}isPointInside(e){return e.x>=this.minPosX&&e.x<=this.maxPosX&&e.z>=this.minPosY&&e.z<=this.maxPosY}isIntersectLineSegment(e,t,r,i){var a=!1,s=t-i,o=r-e,l=e*i-r*t,h=(-l-s*this.minPosX)/o;h<=this.maxPosY&&h>=this.minPosY&&(a=!0),h=(-l-s*this.maxPosX)/o,h<=this.maxPosY&&h>=this.minPosY&&(a=!0);var u=(-l-o*this.minPosY)/s;return u<=this.maxPosX&&u>=this.minPosX&&(a=!0),u=(-l-o*this.maxPosY)/s,u<=this.maxPosX&&u>=this.minPosX&&(a=!0),a}}class li{static NUM_CHILDREN=4;childCellIndices;nodeIndices;aabb;points;constructor(e){this.childCellIndices=new Array,this.childCellIndices.length=li.NUM_CHILDREN,this.nodeIndices=new Array,this.clear(),e?this.aabb=e.clone():this.aabb=new vt}isLeaf(){return this.childCellIndices[0]==-1}clear(){for(var e=0;e<li.NUM_CHILDREN;e++)this.childCellIndices[e]=-1;this.nodeIndices.splice(0,this.nodeIndices.length)}}class yf{_cells;_rootCell;_quadNodes;_aabb;_cellsToTest;_testID;constructor(){this._testID=0,this._cells=new Array,this._quadNodes=new Array,this._cellsToTest=new Array,this._aabb=new vt}getQuadNode(e){return this._quadNodes[e]}clear(){this._cells.length=0,this._quadNodes.length=0}initNodes(e){this.clear();for(var t=0,r=e.length;t<r;)e[t].calcGlobalQuadAABB(),this._quadNodes.push(e[t]),t++}buildQuadTree(e,t){this._aabb.clear();for(var r of this._quadNodes)if(r.isTriangle)for(var i of r.aabb.points)this._aabb.addPoint(i);else this._aabb.setContainRect(r.aabb.minPosX,r.aabb.minPosY,r.aabb.maxPosX,r.aabb.maxPosY);this._cells.length=0,this._rootCell=new li(this._aabb),this._cells.push(this._rootCell);for(var a=this._quadNodes.length,s=0;s<a;s++)this._cells[0].nodeIndices[s]=s;var o=new Array;o.push(0);for(var l,h,u;o.length!=0;)if(h=o.pop(),!(this._cells[h].nodeIndices.length<=e||this._cells[h].aabb.radius<t)){for(s=0;s<li.NUM_CHILDREN;s++){this._cells[h].childCellIndices[s]=this._cells.length,o.push(this._cells.length),this._cells.push(new li(this.createAABox(this._cells[h].aabb,s))),u=this._cells[this._cells.length-1],a=this._cells[h].nodeIndices.length;for(var f=0;f<a;f++)l=this._cells[h].nodeIndices[f],this.doesNodeIntersectCell(this._quadNodes[l],u)&&u.nodeIndices.push(l)}this._cells[h].nodeIndices.length=0}}createAABox(e,t){var r=e.centreX,i=e.centreY,a=e.sideX,s=e.sideY,o=new vt;switch(t){case 0:o.setAABox(r+a/4,i+s/4,a/2,s/2);break;case 1:o.setAABox(r-a/4,i+s/4,a/2,s/2);break;case 2:o.setAABox(r-a/4,i-s/4,a/2,s/2);break;case 3:o.setAABox(r+a/4,i-s/4,a/2,s/2);break;default:o.setAABox(r+a/4,i-s/4,a/2,s/2);break}return o}doesNodeIntersectCell(e,t){var r=e.aabb;if(!r.overlapTest(t.aabb))return!1;if(!e.isTriangle)return!0;var i=r.points,a=i[0],s=i[1],o=i[2];if(t.aabb.isPointInside(a)||t.aabb.isPointInside(s)||t.aabb.isPointInside(o))return!0;var l=this.pointInTriangle(t.aabb.minPosX,t.aabb.minPosY,a,s,o)||this.pointInTriangle(t.aabb.minPosX,t.aabb.maxPosY,a,s,o)||this.pointInTriangle(t.aabb.maxPosX,t.aabb.maxPosY,a,s,o)||this.pointInTriangle(t.aabb.maxPosX,t.aabb.minPosY,a,s,o);return l?!0:(l=t.aabb.isIntersectLineSegment(a.x,a.z,s.x,s.z)||t.aabb.isIntersectLineSegment(a.x,a.z,o.x,o.z)||t.aabb.isIntersectLineSegment(s.x,s.z,o.x,o.z),l)}getNodesIntersectingtAABox(e,t){if(this._cells.length==0)return 0;this._cellsToTest.length=0,this._cellsToTest.push(0),this.incrementTestCounter();for(var r,i,a,s,o=0;this._cellsToTest.length!=0;)if(r=this._cellsToTest.pop(),a=this._cells[r],!!t.overlapTest(a.aabb))if(a.isLeaf())for(i=a.nodeIndices.length,o=0;o<i;o++)s=this.getQuadNode(a.nodeIndices[o]).aabb,s.testID!=this._testID&&(s.testID=this._testID,t.overlapTest(s)&&e.push(a.nodeIndices[o]));else for(o=0;o<li.NUM_CHILDREN;o++)this._cellsToTest.push(a.childCellIndices[o]);return e.length}pointInTriangle(e,t,r,i,a){var s=r,o=i,l=a,h=s.z-o.z,u=o.x-s.x,f=s.x*o.z-o.x*s.z,d=o.z-l.z,m=l.x-o.x,p=o.x*l.z-l.x*o.z,U=l.z-s.z,B=s.x-l.x,v=l.x*s.z-s.x*l.z,C=!1,_=h*e+u*t+f,F=d*e+m*t+p,x=U*e+B*t+v;const b=.01;return(_>=-b&&F>=-b&&x>=-b||_<=b&&F<=b&&x<=b)&&(C=!0),C}incrementTestCounter(){if(++this._testID,this._testID==0){for(var e=this._quadNodes.length,t=0;t<e;t++)this._quadNodes[t].aabb.testID=0;this._testID=1}}logDeep=0;logTree(e){if(!(e<0)){this.logDeep++;for(var t=this._cells[e],r="",i=0;i<this.logDeep-1;i++)r+="-|";console.log(r+"i="+e+" "+t.aabb.minPosX.toFixed(2)+" "+t.aabb.maxPosX.toFixed(2)+" "+t.aabb.minPosY.toFixed(2)+" "+t.aabb.maxPosY.toFixed(2));var a;for(a=0;a<t.nodeIndices.length;a++)if(t.nodeIndices[a]>=0){var s=this._quadNodes[t.nodeIndices[a]];console.log(r+" t="+t.nodeIndices[a]+" "+s.aabb.minPosX.toFixed(2)+" "+s.aabb.maxPosX.toFixed(2)+" "+s.aabb.minPosY.toFixed(2)+" "+s.aabb.maxPosY.toFixed(2))}for(a=0;a<t.childCellIndices.length;a++)t.childCellIndices[a]>=0&&this.logTree(t.childCellIndices[a]);this.logDeep--}}}class bf{_maxNodesPerCell;_minCellSize;_quadTree;_collisionNodesIdx;_segBox;_collisionNodes;constructor(e=10,t=500){this._maxNodesPerCell=e,this._minCellSize=t,this._segBox=new vt,this._collisionNodesIdx=new Array,this._collisionNodes=new Array}createQuadTree(e){this._quadTree=new yf,this._quadTree.initNodes(e),this._quadTree.buildQuadTree(this._maxNodesPerCell,this._minCellSize)}getNodesByAABB(e,t,r,i){this._segBox.clear(),this._segBox.maxPosX=r,this._segBox.maxPosY=i,this._segBox.minPosX=e,this._segBox.minPosY=t,this._collisionNodesIdx.length=0,this._collisionNodes.length=0,this._quadTree.getNodesIntersectingtAABox(this._collisionNodesIdx,this._segBox);for(var a,s=0;s<this._collisionNodesIdx.length;s++)a=this._quadTree.getQuadNode(this._collisionNodesIdx[s]),this._collisionNodes.push(a);return this._collisionNodes}getTriangleAtPoint(e,t=5){this._segBox.clear(),this._segBox.setAABox(e.x,e.z,1,1),this._collisionNodesIdx.length=0,this._collisionNodes.length=0,this._quadTree.getNodesIntersectingtAABox(this._collisionNodesIdx,this._segBox);for(var r=4294967295,i=0,a,s,o,l,h=0;h<this._collisionNodesIdx.length;h++)s=this._quadTree.getQuadNode(this._collisionNodesIdx[h]),l=s.aabb,g.pointInsideTriangle(e,l.points[0],l.points[1],l.points[2])&&(o=s,i=Math.abs(o.plane.distance(e)),!(i>t)&&(s==null||i<=r)&&(a=o,r=i));return a}}var Bs=(n=>(n[n.MOUSE_LEFT=0]="MOUSE_LEFT",n[n.MOUSE_MID=1]="MOUSE_MID",n[n.MOUSE_RIGHT=2]="MOUSE_RIGHT",n))(Bs||{});class wp extends qe{static LOADER_PROGRESS="loaderProgress";static LOADER_COMPLETE="loaderComplete"}class Tp extends qe{static ADDED="added";static REMOVED="removed";static CHILD_ADD_EVENT="childAddEvent";static CHILD_REMOVED="childRemoved"}class Dp extends qe{static SHOW="show";static HIDE="hide";static UPDATE="update"}class Mp{static merge(e,t,r,i){let a=0,s=0;a=Math.max(e.width,a),a=Math.max(t.width,a),a=Math.max(r.width,a),a=Math.max(i.width,a),s=Math.max(e.height,s),s=Math.max(t.height,s),s=Math.max(r.height,s),s=Math.max(i.height,s);let o=new pe(a,s,X.rgba8unorm),l=new ue(pc);l.setSamplerTexture("textureR",e),l.setSamplerTexture("textureG",t),l.setSamplerTexture("textureB",r),l.setSamplerTexture("textureA",i),l.setStorageTexture("outTex",o),l.workerSizeX=Math.ceil(a/8),l.workerSizeY=Math.ceil(s/8);let h=y.beginCommandEncoder();return y.computeCommand(h,[l]),y.endCommandEncoder(h),o}}class Rf{computeShader;setInputes(e,t,r){this.computeShader=new ue(wc(e,t,r,8,8,1));for(let i=0;i<t.length;i++)this.computeShader.setSamplerTexture(`source${i}Map`,t[i]);for(let i=0;i<r.length;i++)this.computeShader.setStorageTexture(`dest${i}Map`,r[i]);e&&this.computeShader.setSamplerTexture("colorMap",e),this.computeShader.workerSizeX=r[0].width/8,this.computeShader.workerSizeY=r[0].height/8,this.computeShader.workerSizeZ=1}}class Qf{sourceShader;compute;needUpdate=!0;constructor(e,t){this.sourceShader=t,this.compute=new ue(e),this.init()}init(){}onUpdate(){this.onFrame&&this.onFrame(),this.onOnce&&this.needUpdate&&(this.needUpdate=!1,this.onFrame())}}class If extends Qf{constructor(e){super(Cc,e)}init(){let e=new pe(256,256,X.rgba8unorm,!1,GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING);return this.compute.setStorageTexture("sssMap",e),this.sourceShader.setTexture("lutMap",e),e}onFrame(){this.compute.workerSizeX=256/8,this.compute.workerSizeY=256/8;let e=y.beginCommandEncoder();y.computeCommand(e,[this.compute]),y.endCommandEncoder(e)}}class Pp{gpuBuffer;probes;memoryDo;_probeInfoList;initDataUniform(e){this.memoryDo=new Xr,this.probes=e,this._probeInfoList=[],this.memoryDo.destroy(),this.memoryDo.allocation(e.length*17*4);for(let r=0;r<e.length;r++){var t=17;let i=this.memoryDo.allocation_node(t*4);this._probeInfoList.push(i);let a=e[r].transform.worldPosition;i.setArray(0,[a.x,a.y,a.z])}this.gpuBuffer=I.device.createBuffer({size:this.memoryDo.shareDataBuffer.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.STORAGE,label:"ProbeBuffer",mappedAtCreation:!1})}updateGPUBuffer(){const e=this.memoryDo.shareDataBuffer;let t=this.memoryDo.shareDataBuffer.byteLength,r=0;const i=5e3*64;for(;r<t;)I.device.queue.writeBuffer(this.gpuBuffer,r,e,r,Math.floor(Math.min(i,t-r))),r+=i}}class Np extends Dr{constructor(e,t,r=0){super(),this.bufferType=$t.StructStorageGPUBuffer,this.createBufferByStruct(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|r,e,t)}}class Vp{static codeMax=`
11629
+ `||Q==" "?b=null:(_(Q,b),b.width+m>=p&&(b=C()))}})(),F()}getAlignment(e){let t={v:0,h:0};switch(e){case 1:t.v=0,t.h=1;break;case 0:t.v=0,t.h=0;break;case 2:t.v=0,t.h=2;break;case 4:t.v=1,t.h=1;break;case 3:t.v=1,t.h=0;break;case 5:t.v=1,t.h=2;break;case 7:t.v=2,t.h=1;break;case 6:t.v=2,t.h=0;break;case 8:t.v=2,t.h=2;break}return t}}class As extends qn{_style=Oe.NORMAL;_interactive=!1;set interactive(e){this._interactive=e}get interactive(){return this._interactive}set mouseStyle(e){this._style=e}get interactiveVisible(){return this._uiTransform.globalVisible&&this._visible}init(e){super.init(e),this._uiTransform.addUIInteractive(this)}destroy(){this._uiTransform.removeUIInteractive(this),super.destroy()}rayPick(e,t,r,i){return ff.rayPick(e,r,i,t.space,t.panelRatio,this._uiTransform,t.transform.worldMatrix)}cloneTo(e){e.getOrAddComponent(As).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this.enable=e._enable,this.interactive=e._interactive,this.mouseStyle=e._style,this}}var Uf=(n=>(n[n.NONE=0]="NONE",n[n.COLOR=1]="COLOR",n[n.SPRITE=2]="SPRITE",n))(Uf||{});class $n extends As{_spriteMap;_colorMap;_image;_isCreateImage;_transition=2;init(e){super.init(e),this._interactive=!0,this._spriteMap=new Map,this._colorMap=new Map,this._image=this.object3D.getComponent(Fi),this._isCreateImage=this._image==null,this._image||(this._image=this.object3D.addComponent(Fi)),this.imageType=Hi.Sliced}onEnable(){this.mouseStyle=Oe.NORMAL}onDisable(){this.mouseStyle=Oe.DISABLE}set transition(e){this._transition!=e&&(this._transition=e,this.validateStyle(this._style,!0))}get transition(){return this._transition}get imageType(){return this._image.imageType}set imageType(e){this._image.imageType=e}setStyleColor(e,t){return this._colorMap.set(e,t),this._style==e&&this.validateStyle(this._style,!0),this}getStyleColor(e){return this._colorMap.get(e)}set mouseStyle(e){super.mouseStyle=e,this.validateStyle(e,!0)}get normalSprite(){return this._spriteMap.get(Oe.NORMAL)}set normalSprite(e){this._spriteMap.set(Oe.NORMAL,e),this._style==Oe.NORMAL&&this.validateStyle(this._style,!0)}get overSprite(){return this._spriteMap.get(Oe.OVER)}set overSprite(e){this._spriteMap.set(Oe.OVER,e),this._style==Oe.OVER&&this.validateStyle(this._style,!0)}set downSprite(e){this._spriteMap.set(Oe.DOWN,e),this._style==Oe.DOWN&&this.validateStyle(this._style,!0)}get downSprite(){return this._spriteMap.get(Oe.DOWN)}set disableSprite(e){this._spriteMap.set(Oe.DISABLE,e),this._style==Oe.DISABLE&&this.validateStyle(this._style,!0)}get disableSprite(){return this._spriteMap.get(Oe.DISABLE)}validateStyle(e,t){if(this._transition&2){let r=this._spriteMap.get(e);this._image.sprite=r}if(this._transition&1){let r=this._colorMap.get(e);r&&(this._image.color=r)}}cloneTo(e){e.getOrAddComponent($n).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this.imageType=e.imageType,this.transition=e.transition,e._spriteMap.forEach((t,r)=>{t&&this._spriteMap.set(r,t)}),e._colorMap.forEach((t,r)=>{t&&this._colorMap.set(r,t.clone())}),this.mouseStyle=e.mouseStyle,this}destroy(){this._isCreateImage&&this._image&&(this.object3D.removeComponent(Fi),this._image=null),super.destroy()}}class eo extends wa{_count=0;constructor(){super()}init(e){super.init?.(e),this._count=e?e.count:1;for(let t=0;t<this._count;t++)this.attachQuad(Br.spawnQuad());this._uiTransform.resize(0,0)}getQuad(e){return this._mainQuads[e]}cloneTo(e){e.addComponent(eo,{count:this._count}).copyComponent(this)}copyComponent(e){super.copyComponent(e);for(let t=0;t<e._count;t++)this.setSprite(t,e.getSprite(t)),this.setColor(t,e.getColor(t)),this.setImageType(t,e.getImageType(t));return this}setSprite(e,t){this._mainQuads[e].sprite=t||A.res.defaultGUISprite,this.setShadowDirty()}getSprite(e){return this._mainQuads[e].sprite}onUIComponentVisible(e){this.applyComponentVisible()}onUITransformVisible(e){this.applyComponentVisible()}applyComponentVisible(){let e=!this._visible||!this._uiTransform.globalVisible;for(let t of this._mainQuads)t.visible=!e;this.setShadowDirty()}getColor(e){return this._mainQuads[e].color}setColor(e,t){this._mainQuads[e].color=t,this.setShadowDirty()}getImageType(e){return this._mainQuads[e].imageType}setImageType(e,t){this._mainQuads[e].imageType=t,this.setShadowDirty()}setSize(e,t,r){this._mainQuads[e].setSize(t,r),this.setShadowDirty()}setXY(e,t,r){this._mainQuads[e].setXY(t,r),this.setShadowDirty()}getXY(e,t){t||=new j;let r=this._mainQuads[e];return t.x=r.x,t.y=r.y,t}}class to extends wa{_shadowQuality=1;_shadowOffset;_shadowRadius;_shadowColor;_subShadowColor;needUpdateShadow=!1;init(e){super.init?.(e),this._shadowRadius=2,this._shadowQuality=1,this._shadowOffset=new j(4,-4),this._shadowColor=new k(.1,.1,.1,.8),this._subShadowColor=this._shadowColor.clone(),this.isUIShadow=!0}cloneTo(e){e.getOrAddComponent(to).copyComponent(this)}copyComponent(e){return super.copyComponent(this),this._shadowColor=e._shadowColor,this._shadowOffset=e._shadowOffset,this._shadowRadius=e._shadowRadius,this._shadowQuality=e.shadowQuality,this}get shadowColor(){return this._shadowColor}set shadowColor(e){this._shadowColor.copyFrom(e),this.needUpdateShadow=!0}set shadowQuality(e){e=ie(e,0,4),this._shadowQuality!=e&&(this._shadowQuality=e,this.needUpdateShadow=!0)}get shadowQuality(){return this._shadowQuality}set shadowOffset(e){this._shadowOffset=e,this.needUpdateShadow=!0}get shadowOffset(){return this._shadowOffset||=new j(4,-4),this._shadowOffset}set shadowRadius(e){this._shadowRadius!=e&&(this._shadowRadius=e,this.applyShadow())}get shadowRadius(){return this._shadowRadius}onUpdate(e){this.needUpdateShadow&&(this.applyShadow(),this.needUpdateShadow=!1)}applyShadow(){if(this.detachQuads(),this._shadowSource&&this._shadowQuality>0){let e=this._shadowSource.mainQuads;if(e.length>0)for(let t of e)this.createQuadShadow(t)}this._uiTransform.setNeedUpdateUIPanel()}createQuadShadow(e){let t=this._shadowQuality,r=Math.PI*2;this._subShadowColor.copyFrom(this._shadowColor),this._subShadowColor.a=1/Math.max(1,t);for(let i=0;i<t;i++){let a=Br.spawnQuad(),s=0,o=0;if(i==0)a.color=this._shadowColor;else{let l=r*(i-1)/(t-1);s=Math.sin(l)*this._shadowRadius,o=Math.cos(l)*this._shadowRadius,a.color=this._subShadowColor}a.setXY(s+this._shadowOffset.x+e.x,o+this._shadowOffset.y+e.y),a.setSize(e.width,e.height),a.sprite=e.sprite,a.visible=e.visible,a.imageType=e.imageType,this.attachQuad(a)}}}class ro extends wa{_font="\u5FAE\u8F6F\u96C5\u9ED1";_fontSize=14;_originSize=42;_alignment=0;_lineSpacing=1;_text="";_color=new k(1,1,1,1);constructor(){super()}cloneTo(e){e.getOrAddComponent(ro).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this._font=e._font,this._fontSize=e._fontSize,this._originSize=e._originSize,this._alignment=e._alignment,this._lineSpacing=e._lineSpacing,this._color.copyFrom(e._color),this.text=e.text,this}get originSize(){return this._originSize}get font(){return this._font}set font(e){this._font=e}get fontSize(){return this._fontSize}set fontSize(e){this._fontSize!=e&&(this._fontSize=e,this.layoutText())}get text(){return this._text}set text(e){this._text!=e&&(e||(e=""),this._text=e,this.layoutText())}textLine=null;layoutProxy=new Af;layoutText(){this.detachQuads(),this.textLine=this.layoutProxy.layout(this);for(let e=0,t=this.textLine.length;e<t;e++){let r=this.textLine[e];for(let i=0,a=r.quadList.length;i<a;i++){let s=r.quadList[i];s&&this.attachQuad(s)}}this.color=this._color,this._uiTransform.setNeedUpdateUIPanel(),this.onUIComponentVisible(this._visible),this.setShadowDirty()}onUIComponentVisible(e){this.applyComponentVisible()}onUITransformVisible(e){this.applyComponentVisible()}applyComponentVisible(){let e=!this._visible||!this._uiTransform.globalVisible;for(let t of this._mainQuads)t&&(t.visible=!e);this.setShadowDirty()}onTransformResize(){this.layoutText()}get color(){return this._color}set color(e){this._color.copyFrom(e);for(let t of this._mainQuads)t.color=e;this.setShadowDirty()}get alignment(){return this._alignment}set alignment(e){this._alignment!=e&&(this._alignment=e,this.layoutText())}get lineSpacing(){return this._lineSpacing}set lineSpacing(e){this._lineSpacing!=e&&(this._lineSpacing=e,this.layoutText())}}var up=Object.getOwnPropertyDescriptor,cp=(n,e,t,r)=>{for(var i=r>1?void 0:r?up(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.Light=class extends Ua{constructor(){super()}init(){super.init(),this.lightData.lightType=Ye.PointLight,this.object3D.name==""&&(this.object3D.name="PointLight"+bt())}get range(){return this.lightData.range}set range(e){this.lightData.range=e,this.onChange()}get at(){return this.lightData.linear}set at(e){this.lightData.linear=e,this.onChange()}get radius(){return this.lightData.radius}set radius(e){this.lightData.radius=e,this.onChange()}get quadratic(){return this.lightData.quadratic}set quadratic(e){this.lightData.quadratic=e,this.onChange()}start(){this.transform.rotationX=90,super.start()}onUpdate(){}onGraphic(e){let t=e.scene.getChildByName("graphic3D");if(!t)return;let r=t.createCustomShape(`PointLight_${this.object3D.instanceID}`,this.transform);r.buildAxis(),r.buildCircle(g.ZERO,this.range,32,g.X_AXIS),r.buildCircle(g.ZERO,this.range,32,g.Y_AXIS),r.buildCircle(g.ZERO,this.range,32,g.Z_AXIS)}debug(){}debugDraw(e){}},c.Light=cp([Pt(c.Light,"Light")],c.Light);var fp=Object.getOwnPropertyDescriptor,dp=(n,e,t,r)=>{for(var i=r>1?void 0:r?fp(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.FatLineRenderer=class extends kr{_fatLineMaterial=null;_fatLineGeometry=null;_cachedResolution=new j(0,0);constructor(){super()}onEnable(){super.onEnable()}onDisable(){super.onDisable()}cloneTo(e){e.addComponent(c.FatLineRenderer).copyComponent(this)}copyComponent(e){return super.copyComponent(e),this}set geometry(e){super.geometry=e,this._fatLineGeometry=e,e&&(this.instanceCount=e.instanceCount,this._fatLineMaterial&&e.instanceBuffer&&this._fatLineMaterial.setInstanceBuffer(e.instanceBuffer))}get geometry(){return this._fatLineGeometry}set material(e){this.materials=[e],this._fatLineMaterial=e,this._fatLineGeometry&&this._fatLineGeometry.instanceBuffer&&e.setInstanceBuffer(this._fatLineGeometry.instanceBuffer)}get material(){return this._fatLineMaterial}nodeUpdate(e,t,r,i){if(this._fatLineMaterial&&this.object3D){this._fatLineMaterial.setModelMatrix(this.object3D.transform.worldMatrix);const a=I.presentationSize[0],s=I.presentationSize[1];a>0&&s>0&&(this._cachedResolution.x!==a||this._cachedResolution.y!==s)&&(this._cachedResolution.set(a,s),this._fatLineMaterial.resolution=this._cachedResolution.clone())}super.nodeUpdate(e,t,r,i)}destroy(e){super.destroy(e)}},c.FatLineRenderer=dp([Pt(c.FatLineRenderer,"FatLineRenderer")],c.FatLineRenderer);class Bf extends c.Object3D{index=0;drawCallFrame=-1;constructor(){super()}}var io=(n=>(n[n.CastGI=0]="CastGI",n[n.ReceiveGI=1]="ReceiveGI",n[n.CastDepth=2]="CastDepth",n[n.Other=3]="Other",n))(io||{});class vf extends ft{static count=0;constructor(e=0,t=0){super(),z.register("GIProbeShader",Nc);let r=new at,i=new Ne("GIProbeShader","GIProbeShader");i.passType=H.COLOR,r.addRenderPass(i),i.setDefine("USE_BRDF",!0),i.setShaderEntry("VertMain","FragMain"),i.setUniformVector4("probeUniform",new K(t,e,0,0));let a=i.shaderState;a.acceptShadow=!1,a.castShadow=!1,a.receiveEnv=!1,a.acceptGI=!1,a.useLight=!1,r.setTexture("baseMap",A.res.whiteTexture),r.setTexture("normalMap",A.res.normalTexture),r.setTexture("emissiveMap",A.res.blackTexture),this.shader=r}}class gp extends Ve{_probes;_volume;_debugMr=[];init(e){e||=A.views[0]?.scene,A.setting.gi.enable=!0,this._volume=oe.getLightEntries(e).irradianceVolume,this.initProbe(e)}initProbe(e){let t=this._volume.setting.probeXCount,r=this._volume.setting.probeYCount,i=this._volume.setting.probeZCount,a=new Ci(4,16,16),s=new g;this._probes=[];for(let o=0;o<t;o++)for(let l=0;l<r;l++)for(let h=0;h<i;h++){let u=o+h*t+l*(t*i),f=new Bf;f.index=u,f.name=`${o}_${l}_${h}`;let d=f.addComponent(c.MeshRenderer);d.material=new vf(io.CastGI,u),d.geometry=a,d.castGI=!1,d.castShadow=!1,this._debugMr.push(d),this.object3D.addChild(f),this._volume.calcPosition(o,l,h,s),f.x=s.x,f.y=s.y,f.z=s.z,this._probes[u]=f,this._debugMr.push(d)}for(let o=0;o<this._probes.length;o++)W.instance.addGIProbe(e,this._probes[o]);this.object3D.transform.enable=!1,this._volume.setting.debug&&this.debug()}debug(){}debugProbeRay(e,t){const r=A.setting.gi.rayNumber;let i=new Y(0,-.7071067811865475,.7071067811865475,0);for(let a=0;a<r;a++){let s=e*r+a,o=new g(-t[s*4+0],-t[s*4+1],-t[s*4+2],0);i.transformVector(o,o);let l=t[s*4+3],h=this._probes[e].transform.worldPosition.clone(),u=o.scaleBy(l);u.add(h,u)}}changeProbesVolumeData(){this._volume.setVolumeDataChange()}changeProbesPosition(){this._volume.setVolumeDataChange();let e=this._volume.setting.probeXCount,t=this._volume.setting.probeYCount,r=this._volume.setting.probeZCount,i=new g;for(let a=0;a<e;a++)for(let s=0;s<t;s++)for(let o=0;o<r;o++){let l=a+o*e+s*(e*r),h=this._probes[l];this._volume.calcPosition(a,s,o,i),h.x=i.x,h.y=i.y,h.z=i.z}}onUpdate(){A.setting.gi.maxDistance=A.setting.gi.probeSpace*1.5;let e=this.transform.scene3D.view.camera,t=g.distance(e.transform.worldPosition,e.transform.targetPos)/300;if(this._debugMr&&this._debugMr.length>0)for(let r=0;r<this._debugMr.length;r++){const i=this._debugMr[r].transform;i.scaleX=t,i.scaleY=t,i.scaleZ=t}}}class mp extends kr{_keyRenderGroup;_keyBufferGroup;_keyIdsGroup;constructor(){super()}init(e){this._keyRenderGroup=new Map,this._keyBufferGroup=new Map,this._keyIdsGroup=new Map}start(){let e=[];this.object3D.getComponents(c.MeshRenderer,e,!0);for(let t=0;t<e.length;t++){const r=e[t];r.transform.updateWorldMatrix(!0),r.enable=!1;let i=r.geometry.instanceID;for(let a=0;a<r.materials.length;a++){const s=r.materials[a];i+=s.instanceID}if(this._keyRenderGroup.has(i))this._keyRenderGroup.get(i).push(r),this._keyIdsGroup.get(i).push(r.transform.worldMatrix.index);else{let a=new Be(e.length);a.visibility=GPUShaderStage.VERTEX,this._keyRenderGroup.set(i,[r]),this._keyBufferGroup.set(i,a),this._keyIdsGroup.set(i,[r.transform.worldMatrix.index])}}this._keyBufferGroup.forEach((t,r)=>{let i=this._keyIdsGroup.get(r),a=this._keyBufferGroup.get(r);a.setInt32Array("matrixIDs",new Int32Array(i)),a.apply()})}reset(){this._keyRenderGroup.size>0&&(this._keyRenderGroup.clear(),this._keyBufferGroup.clear(),this._keyIdsGroup.clear(),this.start())}nodeUpdate(e,t,r,i){this._keyRenderGroup.forEach((a,s)=>{let o=this._keyBufferGroup.get(s),l=a[0];for(let h=0;h<l.materials.length;h++){let f=l.materials[h].getPass(t);if(f)for(let d=0;d<f.length;d++){const m=f[d];m.setDefine("USE_INSTANCEDRAW",!0),m.setStorageBuffer("instanceDrawID",o)}}l.nodeUpdate(e,t,r,i)})}renderPass(e,t,r){this._keyRenderGroup.forEach((i,a)=>{let s=i[0];s.instanceCount=i.length,this.renderItem(e,t,s,r)})}renderItem(e,t,r,i){let a=r.transform._worldMatrix;for(let s=0;s<r.materials.length;s++){let l=r.materials[s].getPass(t);if(!(!l||l.length==0))for(let h=0;h<l.length;h++){let u=l[h];y.bindGeometryBuffer(i.encoder,r.geometry);const f=u;f.shaderState.splitTexture&&(i.endRenderPass(),mt.WriteSplitColorTexture(r.instanceID),i.beginOpaqueRenderPass(),y.bindCamera(i.encoder,e.camera),y.bindGeometryBuffer(i.encoder,r.geometry)),y.bindPipeline(i.encoder,f);let U=r.geometry.subGeometries[s].lodLevels[r.lodLevel];r.instanceCount>0?y.drawIndexed(i.encoder,U.indexCount,r.instanceCount,U.indexStart,0,0):y.drawIndexed(i.encoder,U.indexCount,1,U.indexStart,0,a.index)}}}beforeDestroy(e){this._keyRenderGroup.clear(),this._keyBufferGroup.clear(),this._keyIdsGroup.clear(),this._keyRenderGroup=this._keyBufferGroup=this._keyIdsGroup=void 0,_e.removeWaitStart(this.object3D,this)}}var pp=Object.getOwnPropertyDescriptor,Ap=(n,e,t,r)=>{for(var i=r>1?void 0:r?pp(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.MeshFilter=class extends c.MeshRenderer{constructor(){super()}get geometry(){return null}set geometry(e){}cloneTo(e){}set meshURL(e){let t=A.res.getGeometry(e);t?this.geometry=t:console.error("no geometry set",e)}},c.MeshFilter=Ap([Pt(c.MeshFilter,"MeshFilter")],c.MeshFilter);var Up=Object.getOwnPropertyDescriptor,Bp=(n,e,t,r)=>{for(var i=r>1?void 0:r?Up(e,t):e,a=n.length-1,s;a>=0;a--)(s=n[a])&&(i=s(i)||i);return i};c.SkinnedMeshRenderer=class extends c.MeshRenderer{skinJointsName;mInverseBindMatrixData;mInverseBindMatrixBuffer;mSkeletonAnimation;mJointIndexTableBuffer;constructor(){super(),this.addRendererMask(Ue.SkinnedMesh)}start(){if(super.start(),this.skeletonAnimation=this.object3D.getComponent(c.SkeletonAnimationComponent),!this.skeletonAnimation){let e=this.object3D.parentObject.parentObject.getComponentsInChild(c.SkeletonAnimationComponent);e.length>0&&(this.skeletonAnimation=e[0]);let t=this.object3D;for(;!this.skeletonAnimation&&t;)this.skeletonAnimation=t.getComponentFromParent(c.SkeletonAnimationComponent),t.parent&&(t=t.parent.object3D)}}onEnable(){super.onEnable()}get skeletonAnimation(){return this.mSkeletonAnimation}set skeletonAnimation(e){if(this.mSkeletonAnimation=e,!!e&&!this.mJointIndexTableBuffer){let t=this.mSkeletonAnimation.getJointIndexTable(this.skinJointsName);this.mJointIndexTableBuffer=new Be(t.length*4,0,new Float32Array(t)),this.mJointIndexTableBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.COMPUTE}}get skinInverseBindMatrices(){return this.mInverseBindMatrixData}set skinInverseBindMatrices(e){this.mInverseBindMatrixData=e;var t=new Float32Array(e.length*16);for(let r=0;r<e.length;r++){let i=r*16,a=e[r];t.set(a,i)}this.mInverseBindMatrixBuffer=new Be(t.byteLength,0,t),this.mInverseBindMatrixBuffer.visibility=GPUShaderStage.VERTEX|GPUShaderStage.COMPUTE}get inverseBindMatrixBuffer(){return this.mInverseBindMatrixBuffer}get jointIndexTableBuffer(){return this.mJointIndexTableBuffer.buffer}cloneTo(e){let t=e.addComponent(c.SkinnedMeshRenderer);t.geometry=this.geometry,t.material=this.material.clone(),t.castShadow=this.castShadow,t.castGI=this.castGI,t.receiveShadow=this.receiveShadow,t.rendererMask=this.rendererMask,t.skinJointsName=this.skinJointsName,t.skinInverseBindMatrices=this.skinInverseBindMatrices,t.mJointIndexTableBuffer=this.mJointIndexTableBuffer}nodeUpdate(e,t,r,i){for(let a=0;a<this.materials.length;a++){let o=this.materials[a].getPass(t);if(o)for(let l=0;l<o.length;l++){const h=o[l];!h.pipeline&&this.mSkeletonAnimation&&(h.setStorageBuffer("jointsMatrixIndexTable",this.mSkeletonAnimation.jointMatrixIndexTableBuffer),h.setStorageBuffer("jointsInverseMatrix",this.mInverseBindMatrixBuffer),h.setStorageBuffer("jointsIndexMapingTable",this.mJointIndexTableBuffer))}}super.nodeUpdate(e,t,r,i)}},c.SkinnedMeshRenderer=Bp([Pt(c.SkinnedMeshRenderer,"SkinnedMeshRenderer")],c.SkinnedMeshRenderer);class vp extends Ke{radius=2.5;height=10;constructor(){super(),this._shapeType=ji.Capsule}}class Us extends Ke{mesh;static triangle;_pickRet;constructor(){super(),this._shapeType=ji.Mesh}rayPick(e,t){if(this.mesh){Us.triangle||=new Da(new g,new g,new g);let r=this.mesh.getAttribute(V.position),i=this.mesh.getAttribute(V.indices),a=Ke.helpMatrix;a.copyFrom(t).invert();let s=Ke.helpRay.copy(e);if(s.applyMatrix(a),s.intersectBox(this.mesh.bounds),!s.intersectBox(this.mesh.bounds,Ke.v3_help_0))return null;if(i&&r&&i.data.length>0){let l=r.data;for(let h=0,u=i.data.length/3;h<u;h++){let f=h*3;const d=i.data[f+0]*3,m=i.data[f+1]*3,p=i.data[f+2]*3;let U=Us.triangle,B=U.v1.set(l[d+0],l[d+1],l[d+2]),v=U.v2.set(l[m+0],l[m+1],l[m+2]),C=U.v3.set(l[p+0],l[p+1],l[p+2]);U.set(B,v,C);let _=s.intersectTriangle(s.origin,s.direction,U);if(_){this._pickRet||={intersectPoint:new g,distance:0},this._pickRet.intersectPoint=_,this._pickRet.distance=g.distance(s.origin,_);let F=this.mesh.getAttribute(V.normal);if(F){let x=F.data,b=new g(x[d],x[d+1],x[d+2]);t.transformVector(b,b),b.normalize(),this._pickRet.normal=b}return this._pickRet}}}}return null}}class Cp extends Ke{_pickRet;box;radius=.5;constructor(e){super(),this._shapeType=ji.Sphere,this.radius=e,this.box=new xa(new g,1)}rayPick(e,t){this.box.setFromCenterAndSize(this.center,this.radius);let i=Ke.helpMatrix;i.copyFrom(t).invert();let a=Ke.helpRay.copy(e);a.applyMatrix(i);let s=a.intersectSphere(a.origin,a.direction,this.box.center,this.box.radius);return s?(this._pickRet||(this._pickRet={intersect:!1,intersectPoint:new g,distance:0}),this._pickRet.intersect=!0,this._pickRet.intersectPoint=s,this._pickRet.distance=g.distance(a.origin,Ke.v3_help_0),this._pickRet):null}}class Sp extends c.Object3D{_envMap;skyObject;envMapChange=!0;view;constructor(){super(),this.transform.scene3D=this,this.skyObject=new c.Object3D,this.addChild(this.skyObject),this._isScene3D=!0,this.envMap||=A.res.defaultSky}get envMap(){return this._envMap}set envMap(e){this._envMap!=e&&(this.envMapChange=!0),this._envMap=e,W.instance.sky&&"map"in W.instance.sky&&(W.instance.sky.map=e)}get exposure(){return W.instance.sky&&"exposure"in W.instance.sky?W.instance.sky.exposure:0}set exposure(e){W.instance.sky&&"exposure"in W.instance.sky&&(W.instance.sky.exposure=e,A.setting.sky.skyExposure=e)}get roughness(){if(W.instance.sky&&"roughness"in W.instance.sky)return W.instance.sky.roughness}set roughness(e){W.instance.sky&&"roughness"in W.instance.sky&&(W.instance.sky.roughness=e)}}class Cf{_computeShader;_outBuffer;constructor(){}init(){let e=ne.getGBufferFrame(ne.colorPass_GBuffer);this._computeShader=new ue(vc),this._outBuffer=new Ji(32),this._computeShader.setStorageBuffer("outBuffer",this._outBuffer),this._computeShader.setSamplerTexture("gBufferTexture",e.getCompressGBufferTexture())}compute(e){let t=oe.getCameraGroup(e.camera);this._computeShader.setStorageBuffer("globalUniform",t.uniformGPUBuffer);let r=y.beginCommandEncoder();y.computeCommand(r,[this._computeShader]),y.endCommandEncoder(r),this._outBuffer.readBuffer()}getPickMeshID(){var e=this._outBuffer.outFloat32Array[0]+.1;return Math.floor(e)}getPickWorldPosition(e){e||=new g;var t=this._outBuffer.outFloat32Array[4],r=this._outBuffer.outFloat32Array[5],i=this._outBuffer.outFloat32Array[6];return e.set(t,r,i),e}getPickWorldNormal(e){e||=new g;var t=this._outBuffer.outFloat32Array[8],r=this._outBuffer.outFloat32Array[9],i=this._outBuffer.outFloat32Array[10];return e.set(t*2-1,r*2-1,i*2-1).normalize(),e}getPickScreenUV(e){e||=new j;var t=this._outBuffer.outFloat32Array[2],r=this._outBuffer.outFloat32Array[3];return e.set(t,r),e}}class Sf extends wr{ray;isTouching=!1;_mouseCode;_pickEvent;_outEvent;_overEvent;_upEvent;_downEvent;_mouseMove;_pickCompute;_lastDownTarget;mouseEnableMap;_view;constructor(e){super(),this._view=e,this.init()}init(){this.ray=new Jt,this.mouseEnableMap=new Map,this._pickEvent=new L(L.PICK_CLICK),this._outEvent=new L(L.PICK_OUT),this._overEvent=new L(L.PICK_OVER),this._mouseMove=new L(L.PICK_MOVE),this._upEvent=new L(L.PICK_UP),this._downEvent=new L(L.PICK_DOWN)}start(){A.setting.pick.enable&&(A.inputSystem.addEventListener(L.POINTER_DOWN,this.onTouchStart,this),A.inputSystem.addEventListener(L.POINTER_UP,this.onTouchEnd,this),A.inputSystem.addEventListener(L.POINTER_CLICK,this.onTouchOnce,this),A.inputSystem.addEventListener(L.POINTER_RIGHT_CLICK,this.onTouchOnce,this),A.inputSystem.addEventListener(L.POINTER_MOVE,this.onTouchMove,this)),A.setting.pick.mode=="pixel"&&(this._pickCompute=new Cf,this._pickCompute.init())}stop(){A.inputSystem.removeEventListener(L.POINTER_DOWN,this.onTouchStart,this),A.inputSystem.removeEventListener(L.POINTER_UP,this.onTouchEnd,this),A.inputSystem.removeEventListener(L.POINTER_CLICK,this.onTouchOnce,this),A.inputSystem.removeEventListener(L.POINTER_RIGHT_CLICK,this.onTouchOnce,this),A.inputSystem.removeEventListener(L.POINTER_MOVE,this.onTouchMove,this)}onTouchStart(e){this.isTouching=!0,this._mouseCode=e.mouseCode,this.pick(this._view.camera);let t=this.findNearestObj(this._interestList,this._view.camera);this._lastDownTarget=t,t&&(Object.assign(this._downEvent,e),this._downEvent.type=L.PICK_DOWN,this._downEvent.target=t.object3D,this._downEvent.data=this.getPickInfo(),this.dispatchEvent(this._downEvent),t.object3D.containEventListener(L.PICK_DOWN)&&t.object3D.dispatchEvent(this._downEvent))}onTouchEnd(e){this.isTouching=!1,this._mouseCode=e.mouseCode,this.pick(this._view.camera);let t=this.findNearestObj(this._interestList,this._view.camera);t&&(Object.assign(this._upEvent,e),this._upEvent.type=L.PICK_UP,this._upEvent.target=t.object3D,this._upEvent.data=this.getPickInfo(),this.dispatchEvent(this._upEvent),t.object3D.containEventListener(L.PICK_UP)&&t.object3D.dispatchEvent(this._upEvent))}_lastFocus;getPickInfo(){if(A.setting.pick.mode=="pixel")return{worldPos:this._pickCompute.getPickWorldPosition(),worldNormal:this._pickCompute.getPickWorldNormal(),screenUv:this._pickCompute.getPickScreenUV(),meshID:this._pickCompute.getPickMeshID()};{let e=this._interestList[0];return{worldPos:e.intersectPoint,worldNormal:e.normal,meshID:e.collider.transform.worldMatrix.index,distance:e.distance}}}onTouchMove(e){this.isTouching=!0,this._mouseCode=e.mouseCode,this.pick(this._view.camera);let t=this.findNearestObj(this._interestList,this._view.camera);t&&(Object.assign(this._mouseMove,e),this._mouseMove.type=L.PICK_MOVE,this._mouseMove.target=t.object3D,this._mouseMove.data=this.getPickInfo(),this.dispatchEvent(this._mouseMove),t.object3D.containEventListener(L.PICK_MOVE)&&t.object3D.dispatchEvent(this._mouseMove)),t!=this._lastFocus&&(this._lastFocus&&this._lastFocus.object3D&&(Object.assign(this._outEvent,e),this._outEvent.type=L.PICK_OUT,this._outEvent.target=this._lastFocus.object3D,this._outEvent.data=this.getPickInfo(),this.dispatchEvent(this._outEvent),this._lastFocus.object3D.containEventListener(L.PICK_OUT)&&this._lastFocus.object3D.dispatchEvent(this._outEvent)),t&&(Object.assign(this._overEvent,e),this._overEvent.type=L.PICK_OVER,this._overEvent.target=t.object3D,this._overEvent.data=this.getPickInfo(),this.dispatchEvent(this._overEvent),t.object3D.containEventListener(L.PICK_OVER)&&t.object3D.dispatchEvent(this._overEvent))),this._lastFocus=t}onTouchOnce(e){this.isTouching=!0,this._mouseCode=e.mouseCode,this.pick(this._view.camera);let t=this.findNearestObj(this._interestList,this._view.camera);if(t){let r=this.getPickInfo();Object.assign(this._pickEvent,e),this._pickEvent.type=L.PICK_CLICK,this._pickEvent.target=t.object3D,this._pickEvent.data=r,this.dispatchEvent(this._pickEvent),t===this._lastDownTarget&&t.object3D.containEventListener(L.PICK_CLICK)&&t.object3D.dispatchEvent(this._pickEvent)}this._lastDownTarget=null}findNearestObj(e,t){return e.sort((r,i)=>r.distance>i.distance?1:-1),e[0]?.collider}_interestList=[];pick(e){if(this._interestList.length=0,A.setting.pick.mode=="pixel"){this._pickCompute.compute(this._view);let t=this._pickCompute.getPickMeshID(),r=this.mouseEnableMap.get(t);if(r){let i=this._pickCompute.getPickWorldPosition(),a=g.distance(i,this.ray.origin);this._interestList.push({distance:a,collider:r,intersectPoint:i})}}else if(A.setting.pick.mode=="bound"){this.ray=e.screenPointToRay(A.inputSystem.mouseX,A.inputSystem.mouseY);let t,r=_e.componentsEnablePickerList.get(this._view);if(r)for(const i of r){let a=i[0];a.enable&&(t=a.rayPick(this.ray),t&&(t.collider=a,this._interestList.push(t)))}}}}class _p extends Ja{_camera;_scene;_viewPort;_enablePick=!1;_enable=!0;pickFire;guiPick;canvasList;constructor(e=0,t=0,r=0,i=0){super(),this.canvasList=[],this._viewPort=new K(e,t,r,i)}get enable(){return this._enable}set enable(e){this._enable=e}get enablePick(){return this._enablePick}set enablePick(e){this._enablePick!=e&&(this.pickFire=new Sf(this),this.pickFire.start()),this._enablePick=e}get scene(){return this._scene}set scene(e){this._scene=e,e.view=this,It.createBuffer(this),e&&this.canvasList.forEach(t=>{t&&e.addChild(t.object3D)})}get camera(){return this._camera}set camera(e){this._camera=e}get viewPort(){return this._viewPort}set viewPort(e){this._viewPort=e}enableUICanvas(e=0){let t=this.canvasList[e];if(!t){let r=new c.Object3D;r.name="Canvas "+e,t=r.addComponent(Ia),t.index=e,this.canvasList[e]=t}return this.scene.addChild(t.object3D),this.guiPick||(this.guiPick=new hf,this.guiPick.init(this)),t}disableUICanvas(e=0){let t=this.canvasList[e];t&&t.object3D&&t.object3D.removeFromParent()}}class xp{normal;fixNormal;center;rotateShape;distance=0;index;constructor(e){this.index=e,this.rotateShape=[]}}class Fp extends Re{vScale;uNegate;sections;build(e,t,r,i=1,a=!0){if(r.length<2)throw new Error("path length is not enough");return this.vScale=i,this.uNegate=a,e=e.slice(),t&&e.push(e[0]),this.sections=this.buildSections(e,r),this.buildGeometry(e,this.sections),this.bounds=new xe(g.ZERO.clone(),new g(100,100,100)),this}buildSections(e,t){let r,i,a,s=[],o=t.length;for(let h=0;h<o;h++){let u=new xp(h);r=t[h],i=t[h+1],u.center=r.clone(),i==null?(u.normal=a.clone(),u.distance=0):(a=i.subtract(r),u.distance=a.length,u.normal=a.normalize()),s.push(u)}s[0].fixNormal=s[0].normal.clone();for(let h=1;h<o;h++){let u=s[h-1],f=s[h];f.fixNormal=f.normal.add(u.normal).normalize()}let l=new E().identity();for(let h=0;h<o;h++){let u=s[h],f,d;if(h==0)f=g.UP,d=e;else{let m=s[h-1];f=m.fixNormal,d=m.rotateShape}E.fromToRotation(f,u.fixNormal,l);for(let m=0,p=e.length;m<p;m++){let U=l.multiplyPoint3(d[m]);u.rotateShape.push(U)}}return s}buildGeometry(e,t){let r=t.length,i=e.length,a=r*i,s=r-1,o=new Float32Array(a*3),l=new Float32Array(a*3),h=new Float32Array(a*2),u=new Uint32Array(s*(i-1)*6),f=i-1,d=0,m=0,p=[0];for(let B=1;B<i;B++)m+=e[B-1].subtract(e[B]).length,p.push(m);for(let B=0;B<r;B++){let v=t[B];for(let C=0;C<i;C++){let _=(B*i+C)*3,F=v.rotateShape[C].add(v.center);o[_]=F.x,o[_+1]=F.y,o[_+2]=F.z,l[_+1]=1;let x=(B*i+C)*2,b=p[C]/m;h[x]=this.uNegate?1-b:b,h[x+1]=d*this.vScale}d+=v.distance}let U=0;for(let B=0;B<s;B++){let v=B*i;for(let C=0;C<f;C++){let _=C,F=C+1,x=_+i,b=F+i;u[U++]=_+v,u[U++]=F+v,u[U++]=x+v,u[U++]=F+v,u[U++]=b+v,u[U++]=x+v}}return this.setIndices(u),this.setAttribute(V.position,o),this.setAttribute(V.normal,l),this.setAttribute(V.uv,h),this.setAttribute(V.TEXCOORD_1,h),this.addSubGeometry({indexStart:0,indexCount:u.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0}),this.computeNormals(),this}}class yp extends Re{_instanceBuffer;_instanceData;_instanceCount=0;constructor(){super(),this.initBaseGeometry()}initBaseGeometry(){const e=new Float32Array([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0]),t=new Float32Array([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2]),r=new Uint16Array([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]);this.setIndices(r),this.setAttribute(V.position,e),this.setAttribute(V.uv,t),this.addSubGeometry({indexStart:0,indexCount:r.length,vertexStart:0,vertexCount:e.length/3,firstStart:0,index:0,topology:0})}setPositions(e){const t=e instanceof Float32Array?e:new Float32Array(e),i=t.length/3-1;if(i<=0)return console.warn("FatLineGeometry: Need at least 2 points"),this;const a=new Float32Array(i*16);for(let s=0;s<i;s++){const o=s*3,l=(s+1)*3;a[s*16+0]=t[o+0],a[s*16+1]=t[o+1],a[s*16+2]=t[o+2],a[s*16+3]=0,a[s*16+4]=t[l+0],a[s*16+5]=t[l+1],a[s*16+6]=t[l+2],a[s*16+7]=0,a[s*16+8]=1,a[s*16+9]=1,a[s*16+10]=1,a[s*16+11]=0,a[s*16+12]=1,a[s*16+13]=1,a[s*16+14]=1,a[s*16+15]=0}return this._instanceData=a,this._instanceCount=i,this.computeBoundingBox(t),this}setColors(e){const t=e instanceof Float32Array?e:new Float32Array(e);if(!this._instanceData)return console.warn("FatLineGeometry: Must call setPositions() before setColors()"),this;const i=t.length/3-1;if(i!==this._instanceCount)return console.warn("FatLineGeometry: Color array length doesn't match segment count"),this;for(let a=0;a<i;a++){const s=a*3,o=(a+1)*3;this._instanceData[a*16+8]=t[s+0],this._instanceData[a*16+9]=t[s+1],this._instanceData[a*16+10]=t[s+2],this._instanceData[a*16+12]=t[o+0],this._instanceData[a*16+13]=t[o+1],this._instanceData[a*16+14]=t[o+2]}return this}computeBoundingBox(e){const t=new g(1/0,1/0,1/0),r=new g(-1/0,-1/0,-1/0);for(let a=0;a<e.length;a+=3){const s=e[a],o=e[a+1],l=e[a+2];t.x=Math.min(t.x,s),t.y=Math.min(t.y,o),t.z=Math.min(t.z,l),r.x=Math.max(r.x,s),r.y=Math.max(r.y,o),r.z=Math.max(r.z,l)}const i=g.sub(r,t);this.bounds=new xe(g.ZERO.clone(),i),this.bounds.setFromMinMax(t,r)}get instanceData(){return this._instanceData}get instanceCount(){return this._instanceCount}get instanceBuffer(){return!this._instanceBuffer&&this._instanceData&&(this._instanceBuffer=new Be(this._instanceData.byteLength),this._instanceBuffer.setFloat32Array("",this._instanceData),this._instanceBuffer.apply()),this._instanceBuffer}updateInstanceBuffer(){this._instanceBuffer&&this._instanceData&&(this._instanceBuffer.setFloat32Array("",this._instanceData),this._instanceBuffer.apply())}}class bp{name;offset;size;arrayStride;stepMode;attributes}class Rp{name;format;offset;shaderLocation;stride}var _f=(n=>(n[n.position=3]="position",n[n.normal=3]="normal",n[n.TANGENT=4]="TANGENT",n[n.uv=2]="uv",n[n.TEXCOORD_1=2]="TEXCOORD_1",n[n.color=4]="color",n[n.joints0=4]="joints0",n[n.weights0=4]="weights0",n[n.joints1=4]="joints1",n[n.weights1=4]="weights1",n[n.vIndex=1]="vIndex",n[n.weight=1]="weight",n[n.a_morphPositions_0=3]="a_morphPositions_0",n))(_f||{});class Qp{get data(){return null}entity}class xf{min=0;max=0;set(e,t){return this.max=t,this.min=e,this}copy(e){return this.max=e.max,this.min=e.min,this}isInterestRange(e){return!(this.max>e.min||e.max<this.min)}}class Ff{_spaceDesc;getRange(e){return this._spaceDesc[e]}initSpace(e){this._spaceDesc={};for(let t of e)(this._spaceDesc[t]=new xf).set(-Number.MAX_VALUE,Number.MAX_VALUE);return this}isContain(e,t){let r=this._spaceDesc[e];return t>=r.min&&t<r.max}isInterestRange(e,t){let r=this._spaceDesc[e];return r?t.isInterestRange(r):!1}splitSpace(e,t,r){let i=this._spaceDesc[e];return t?i.max=r:i.min=r,this}copySpace(e){for(let t in e._spaceDesc){let r=e._spaceDesc[t];this._spaceDesc[t].copy(r)}return this}}class Ma{static MaxEntityCountInLeaf=4;static MaxLayer=10;static ClearLeafLayer=Ma.MaxLayer-4}class Pa{static UUID=0;uuid="0";constructor(){this.uuid=(Pa.UUID++).toString()}}class Ip{map={};_count=0;get count(){return this._count}push(e){return this.map[e.uuid]?!1:(this.map[e.uuid]=e,this._count++,!0)}remove(e){return this.map[e]?(delete this.map[e],this._count--,!0):!1}}class oi extends Pa{_dimensionIndex=0;_dimensions;_dimension;_left;_right;_space;_parent;_entities;layer;get dimension(){return this._dimension}constructor(e=0){super(),this.layer=e,oi.nodeCount++}initNode(e,t,r){return this._dimensions=t,this._dimensionIndex=r,this._dimension=t[r],this._space=new Ff().initSpace(t),e&&this._space.copySpace(e._space),this._parent=e,this._entities=new Ip,this}updateEntity(e){if(e.isInNode(this,this._dimension)&&(e.attachTreeNode(this),this.autoSplit(),this._left&&this._right)){let t=(this._dimensionIndex+1)%this._dimensions.length,r=this._dimensions[t];e.isInNode(this._right,r)?this._right.updateEntity(e):e.isInNode(this._left,r)&&this._left.updateEntity(e)}}buildRoot(e){for(const t of e)t.entity.attachTreeNode(this);this.autoSplit()}_splitEntityList=[];autoSplit(){if(this._entities.count>Ma.MaxEntityCountInLeaf&&!this._right&&!this._left&&this.layer<Ma.MaxLayer){let e=this._splitEntityList,t=(this._dimensionIndex+1)%this._dimensions.length,r=this._dimensions[t],i=0;for(const a in this._entities.map){let s=this._entities.map[a];i+=s.centerValue(r),e.push(s)}i/=this._entities.count,this._left=new oi(this.layer+1),this._right=new oi(this.layer+1),this._left.initNode(this,this._dimensions,t),this._right.initNode(this,this._dimensions,t),this._left.setSpace(!0,i),this._right.setSpace(!1,i);for(let a of e)a.isInNode(this._right,r)?a.attachTreeNode(this._right):a.isInNode(this._left,r)&&a.attachTreeNode(this._left)}this._left&&this._left.autoSplit(),this._right&&this._right.autoSplit()}setSpace(e,t){return this._parent&&this._space.splitSpace(this._dimension,e,t),this}isEmpty(){return this._left==null&&this._right==null&&this._entities.count==0}pushEntity(e){return this._entities.push(e)}removeEntity(e){return this._entities.remove(e.uuid)}static nodeCount=0;autoClear(){let e=this;for(;e&&e.layer>Ma.ClearLeafLayer&&e.clearLeaf();)e=e._parent}clearLeaf(){let e=!this._left&&!this._right,t=!e&&this._left.isEmpty()&&this._right.isEmpty();return t&&(this._left=this._right=null,oi.nodeCount-=2),e||t}isContain(e){return this._space.isContain(this._dimension,e)}static rangeBox=new xe(new g(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),new g(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE));nodeIntersectsBox(e){let t=this._space.getRange("x"),r=this._space.getRange("y"),i=this._space.getRange("z"),a=oi.rangeBox;return a.min.set(t.min,r.min,i.min),a.max.set(t.max,r.max,i.max),a.intersectsBox(e)}nodeIntersectsRay(e){let t=this._space.getRange("x"),r=this._space.getRange("y"),i=this._space.getRange("z"),a=oi.rangeBox;return a.min.set(t.min,r.min,i.min),a.max.set(t.max,r.max,i.max),!0}pointCast(e,t=0,r){if(r=r||[],this._entities.count>0){let i=this._entities.map;for(let a in i){let s=i[a],o=s.entityContainPoint(e);!o&&t>0&&(o=s.squareDistanceTo(e,this._dimensions)<=t),o&&r.push(s)}}this._left&&this._left.isContain(e[this._left.dimension])&&this._left.pointCast(e,t,r),this._right&&this._right.isContain(e[this._right.dimension])&&this._right.pointCast(e,t,r)}boxCast(e,t){if(t=t||[],this._entities.count>0){let r=this._entities.map;for(let i in r){let a=r[i];a.entityIntersectsBox(e)&&t.push(a)}}this._left&&this._left.nodeIntersectsBox(e)&&this._left.boxCast(e,t),this._right&&this._right.nodeIntersectsBox(e)&&this._right.boxCast(e,t)}pointIntersect=new g;rayCast(e,t,r){t=t||[],r=r||[];let i=this.pointIntersect;if(this._entities.count>0){let a=this._entities.map;for(let s in a){let o=a[s];o.entityIntersectsRay(e,i)&&(r.push(new g().copyFrom(i)),t.push(o))}}this._left&&this._left.nodeIntersectsRay(e)&&this._left.rayCast(e,t,r),this._right&&this._right.nodeIntersectsRay(e)&&this._right.rayCast(e,t,r)}}class Ep extends Pa{userData;node;constructor(e){super(),this.userData=e}centerValue(e){return 0}isInNode(e,t){return!1}entityContainPoint(e){return!1}squareDistanceTo(e,t){return Number.MAX_VALUE}entityIntersectsBox(e){return!1}entityIntersectsRay(e,t){return!1}attachTreeNode(e){return this.node&&this.detachTreeNode(),this.node=e,this.node.pushEntity(this)}detachTreeNode(){let e=this.node.removeEntity(this);return this.node=null,e}updateNode(e){let t=this.node;t&&this.detachTreeNode(),e.updateEntity(this),t&&t.autoClear()}}class vt{minPosX=0;minPosY=0;maxPosX=0;maxPosY=0;testID=0;points;offsetPosition;static TINY=1e-6;constructor(){this.points=new Array,this.offsetPosition=new g(0,0,0,0),this.clear()}setAABox(e,t,r,i){this.minPosX=e-r/2-vt.TINY,this.maxPosX=e+r/2+vt.TINY,this.minPosY=t-i/2-vt.TINY,this.maxPosY=t+i/2+vt.TINY,this.offsetPosition.setTo(0,0,0)}setOffset(e){this.maxPosX+=e.x-this.offsetPosition.x,this.minPosX+=e.x-this.offsetPosition.x,this.minPosY+=e.z-this.offsetPosition.z,this.maxPosY+=e.z-this.offsetPosition.z,this.offsetPosition.copyFrom(e)}setContainRect(e,t,r,i){this.minPosX>e&&(this.minPosX=e),this.minPosY>t&&(this.minPosY=t),this.maxPosX<r&&(this.maxPosX=r),this.maxPosY<i&&(this.maxPosY=i)}clear(){var e=1e9;this.minPosX=this.minPosY=e,this.maxPosX=this.maxPosY=-e,this.points.length=0,this.testID=0,this.offsetPosition.setTo(0,0,0)}addPoint(e){this.points.indexOf(e)==-1&&(e.x<this.minPosX&&(this.minPosX=e.x-vt.TINY),e.x>this.maxPosX&&(this.maxPosX=e.x+vt.TINY),e.z<this.minPosY&&(this.minPosY=e.z-vt.TINY),e.z>this.maxPosY&&(this.maxPosY=e.z+vt.TINY),this.points.push(e))}clone(){var e=new vt;return e.minPosX=this.minPosX,e.minPosY=this.minPosY,e.maxPosX=this.maxPosX,e.maxPosY=this.maxPosY,e}get radius(){return Math.sqrt((this.maxPosY-this.minPosY)*(this.maxPosY-this.minPosY)+(this.maxPosX-this.minPosX)*(this.maxPosX-this.minPosX))}get sideX(){return this.maxPosX-this.minPosX}get sideY(){return this.maxPosY-this.minPosY}get centreX(){return(this.maxPosX-this.minPosX)*.5+this.minPosX}get centreY(){return(this.maxPosY-this.minPosY)*.5+this.minPosY}overlapTest(e){return!(this.minPosY>=e.maxPosY||this.maxPosY<=e.minPosY||this.minPosX>=e.maxPosX||this.maxPosX<=e.minPosX)}isPointInside(e){return e.x>=this.minPosX&&e.x<=this.maxPosX&&e.z>=this.minPosY&&e.z<=this.maxPosY}isIntersectLineSegment(e,t,r,i){var a=!1,s=t-i,o=r-e,l=e*i-r*t,h=(-l-s*this.minPosX)/o;h<=this.maxPosY&&h>=this.minPosY&&(a=!0),h=(-l-s*this.maxPosX)/o,h<=this.maxPosY&&h>=this.minPosY&&(a=!0);var u=(-l-o*this.minPosY)/s;return u<=this.maxPosX&&u>=this.minPosX&&(a=!0),u=(-l-o*this.maxPosY)/s,u<=this.maxPosX&&u>=this.minPosX&&(a=!0),a}}class li{static NUM_CHILDREN=4;childCellIndices;nodeIndices;aabb;points;constructor(e){this.childCellIndices=new Array,this.childCellIndices.length=li.NUM_CHILDREN,this.nodeIndices=new Array,this.clear(),e?this.aabb=e.clone():this.aabb=new vt}isLeaf(){return this.childCellIndices[0]==-1}clear(){for(var e=0;e<li.NUM_CHILDREN;e++)this.childCellIndices[e]=-1;this.nodeIndices.splice(0,this.nodeIndices.length)}}class yf{_cells;_rootCell;_quadNodes;_aabb;_cellsToTest;_testID;constructor(){this._testID=0,this._cells=new Array,this._quadNodes=new Array,this._cellsToTest=new Array,this._aabb=new vt}getQuadNode(e){return this._quadNodes[e]}clear(){this._cells.length=0,this._quadNodes.length=0}initNodes(e){this.clear();for(var t=0,r=e.length;t<r;)e[t].calcGlobalQuadAABB(),this._quadNodes.push(e[t]),t++}buildQuadTree(e,t){this._aabb.clear();for(var r of this._quadNodes)if(r.isTriangle)for(var i of r.aabb.points)this._aabb.addPoint(i);else this._aabb.setContainRect(r.aabb.minPosX,r.aabb.minPosY,r.aabb.maxPosX,r.aabb.maxPosY);this._cells.length=0,this._rootCell=new li(this._aabb),this._cells.push(this._rootCell);for(var a=this._quadNodes.length,s=0;s<a;s++)this._cells[0].nodeIndices[s]=s;var o=new Array;o.push(0);for(var l,h,u;o.length!=0;)if(h=o.pop(),!(this._cells[h].nodeIndices.length<=e||this._cells[h].aabb.radius<t)){for(s=0;s<li.NUM_CHILDREN;s++){this._cells[h].childCellIndices[s]=this._cells.length,o.push(this._cells.length),this._cells.push(new li(this.createAABox(this._cells[h].aabb,s))),u=this._cells[this._cells.length-1],a=this._cells[h].nodeIndices.length;for(var f=0;f<a;f++)l=this._cells[h].nodeIndices[f],this.doesNodeIntersectCell(this._quadNodes[l],u)&&u.nodeIndices.push(l)}this._cells[h].nodeIndices.length=0}}createAABox(e,t){var r=e.centreX,i=e.centreY,a=e.sideX,s=e.sideY,o=new vt;switch(t){case 0:o.setAABox(r+a/4,i+s/4,a/2,s/2);break;case 1:o.setAABox(r-a/4,i+s/4,a/2,s/2);break;case 2:o.setAABox(r-a/4,i-s/4,a/2,s/2);break;case 3:o.setAABox(r+a/4,i-s/4,a/2,s/2);break;default:o.setAABox(r+a/4,i-s/4,a/2,s/2);break}return o}doesNodeIntersectCell(e,t){var r=e.aabb;if(!r.overlapTest(t.aabb))return!1;if(!e.isTriangle)return!0;var i=r.points,a=i[0],s=i[1],o=i[2];if(t.aabb.isPointInside(a)||t.aabb.isPointInside(s)||t.aabb.isPointInside(o))return!0;var l=this.pointInTriangle(t.aabb.minPosX,t.aabb.minPosY,a,s,o)||this.pointInTriangle(t.aabb.minPosX,t.aabb.maxPosY,a,s,o)||this.pointInTriangle(t.aabb.maxPosX,t.aabb.maxPosY,a,s,o)||this.pointInTriangle(t.aabb.maxPosX,t.aabb.minPosY,a,s,o);return l?!0:(l=t.aabb.isIntersectLineSegment(a.x,a.z,s.x,s.z)||t.aabb.isIntersectLineSegment(a.x,a.z,o.x,o.z)||t.aabb.isIntersectLineSegment(s.x,s.z,o.x,o.z),l)}getNodesIntersectingtAABox(e,t){if(this._cells.length==0)return 0;this._cellsToTest.length=0,this._cellsToTest.push(0),this.incrementTestCounter();for(var r,i,a,s,o=0;this._cellsToTest.length!=0;)if(r=this._cellsToTest.pop(),a=this._cells[r],!!t.overlapTest(a.aabb))if(a.isLeaf())for(i=a.nodeIndices.length,o=0;o<i;o++)s=this.getQuadNode(a.nodeIndices[o]).aabb,s.testID!=this._testID&&(s.testID=this._testID,t.overlapTest(s)&&e.push(a.nodeIndices[o]));else for(o=0;o<li.NUM_CHILDREN;o++)this._cellsToTest.push(a.childCellIndices[o]);return e.length}pointInTriangle(e,t,r,i,a){var s=r,o=i,l=a,h=s.z-o.z,u=o.x-s.x,f=s.x*o.z-o.x*s.z,d=o.z-l.z,m=l.x-o.x,p=o.x*l.z-l.x*o.z,U=l.z-s.z,B=s.x-l.x,v=l.x*s.z-s.x*l.z,C=!1,_=h*e+u*t+f,F=d*e+m*t+p,x=U*e+B*t+v;const b=.01;return(_>=-b&&F>=-b&&x>=-b||_<=b&&F<=b&&x<=b)&&(C=!0),C}incrementTestCounter(){if(++this._testID,this._testID==0){for(var e=this._quadNodes.length,t=0;t<e;t++)this._quadNodes[t].aabb.testID=0;this._testID=1}}logDeep=0;logTree(e){if(!(e<0)){this.logDeep++;for(var t=this._cells[e],r="",i=0;i<this.logDeep-1;i++)r+="-|";console.log(r+"i="+e+" "+t.aabb.minPosX.toFixed(2)+" "+t.aabb.maxPosX.toFixed(2)+" "+t.aabb.minPosY.toFixed(2)+" "+t.aabb.maxPosY.toFixed(2));var a;for(a=0;a<t.nodeIndices.length;a++)if(t.nodeIndices[a]>=0){var s=this._quadNodes[t.nodeIndices[a]];console.log(r+" t="+t.nodeIndices[a]+" "+s.aabb.minPosX.toFixed(2)+" "+s.aabb.maxPosX.toFixed(2)+" "+s.aabb.minPosY.toFixed(2)+" "+s.aabb.maxPosY.toFixed(2))}for(a=0;a<t.childCellIndices.length;a++)t.childCellIndices[a]>=0&&this.logTree(t.childCellIndices[a]);this.logDeep--}}}class bf{_maxNodesPerCell;_minCellSize;_quadTree;_collisionNodesIdx;_segBox;_collisionNodes;constructor(e=10,t=500){this._maxNodesPerCell=e,this._minCellSize=t,this._segBox=new vt,this._collisionNodesIdx=new Array,this._collisionNodes=new Array}createQuadTree(e){this._quadTree=new yf,this._quadTree.initNodes(e),this._quadTree.buildQuadTree(this._maxNodesPerCell,this._minCellSize)}getNodesByAABB(e,t,r,i){this._segBox.clear(),this._segBox.maxPosX=r,this._segBox.maxPosY=i,this._segBox.minPosX=e,this._segBox.minPosY=t,this._collisionNodesIdx.length=0,this._collisionNodes.length=0,this._quadTree.getNodesIntersectingtAABox(this._collisionNodesIdx,this._segBox);for(var a,s=0;s<this._collisionNodesIdx.length;s++)a=this._quadTree.getQuadNode(this._collisionNodesIdx[s]),this._collisionNodes.push(a);return this._collisionNodes}getTriangleAtPoint(e,t=5){this._segBox.clear(),this._segBox.setAABox(e.x,e.z,1,1),this._collisionNodesIdx.length=0,this._collisionNodes.length=0,this._quadTree.getNodesIntersectingtAABox(this._collisionNodesIdx,this._segBox);for(var r=4294967295,i=0,a,s,o,l,h=0;h<this._collisionNodesIdx.length;h++)s=this._quadTree.getQuadNode(this._collisionNodesIdx[h]),l=s.aabb,g.pointInsideTriangle(e,l.points[0],l.points[1],l.points[2])&&(o=s,i=Math.abs(o.plane.distance(e)),!(i>t)&&(s==null||i<=r)&&(a=o,r=i));return a}}var Bs=(n=>(n[n.MOUSE_LEFT=0]="MOUSE_LEFT",n[n.MOUSE_MID=1]="MOUSE_MID",n[n.MOUSE_RIGHT=2]="MOUSE_RIGHT",n))(Bs||{});class wp extends qe{static LOADER_PROGRESS="loaderProgress";static LOADER_COMPLETE="loaderComplete"}class Tp extends qe{static ADDED="added";static REMOVED="removed";static CHILD_ADD_EVENT="childAddEvent";static CHILD_REMOVED="childRemoved"}class Dp extends qe{static SHOW="show";static HIDE="hide";static UPDATE="update"}class Mp{static merge(e,t,r,i){let a=0,s=0;a=Math.max(e.width,a),a=Math.max(t.width,a),a=Math.max(r.width,a),a=Math.max(i.width,a),s=Math.max(e.height,s),s=Math.max(t.height,s),s=Math.max(r.height,s),s=Math.max(i.height,s);let o=new pe(a,s,X.rgba8unorm),l=new ue(pc);l.setSamplerTexture("textureR",e),l.setSamplerTexture("textureG",t),l.setSamplerTexture("textureB",r),l.setSamplerTexture("textureA",i),l.setStorageTexture("outTex",o),l.workerSizeX=Math.ceil(a/8),l.workerSizeY=Math.ceil(s/8);let h=y.beginCommandEncoder();return y.computeCommand(h,[l]),y.endCommandEncoder(h),o}}class Rf{computeShader;setInputes(e,t,r){this.computeShader=new ue(wc(e,t,r,8,8,1));for(let i=0;i<t.length;i++)this.computeShader.setSamplerTexture(`source${i}Map`,t[i]);for(let i=0;i<r.length;i++)this.computeShader.setStorageTexture(`dest${i}Map`,r[i]);e&&this.computeShader.setSamplerTexture("colorMap",e),this.computeShader.workerSizeX=r[0].width/8,this.computeShader.workerSizeY=r[0].height/8,this.computeShader.workerSizeZ=1}}class Qf{sourceShader;compute;needUpdate=!0;constructor(e,t){this.sourceShader=t,this.compute=new ue(e),this.init()}init(){}onUpdate(){this.onFrame&&this.onFrame(),this.onOnce&&this.needUpdate&&(this.needUpdate=!1,this.onFrame())}}class If extends Qf{constructor(e){super(Cc,e)}init(){let e=new pe(256,256,X.rgba8unorm,!1,GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING);return this.compute.setStorageTexture("sssMap",e),this.sourceShader.setTexture("lutMap",e),e}onFrame(){this.compute.workerSizeX=256/8,this.compute.workerSizeY=256/8;let e=y.beginCommandEncoder();y.computeCommand(e,[this.compute]),y.endCommandEncoder(e)}}class Pp{gpuBuffer;probes;memoryDo;_probeInfoList;initDataUniform(e){this.memoryDo=new Xr,this.probes=e,this._probeInfoList=[],this.memoryDo.destroy(),this.memoryDo.allocation(e.length*17*4);for(let r=0;r<e.length;r++){var t=17;let i=this.memoryDo.allocation_node(t*4);this._probeInfoList.push(i);let a=e[r].transform.worldPosition;i.setArray(0,[a.x,a.y,a.z])}this.gpuBuffer=I.device.createBuffer({size:this.memoryDo.shareDataBuffer.byteLength,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.STORAGE,label:"ProbeBuffer",mappedAtCreation:!1})}updateGPUBuffer(){const e=this.memoryDo.shareDataBuffer;let t=this.memoryDo.shareDataBuffer.byteLength,r=0;const i=5e3*64;for(;r<t;)I.device.queue.writeBuffer(this.gpuBuffer,r,e,r,Math.floor(Math.min(i,t-r))),r+=i}}class Np extends Dr{constructor(e,t,r=0){super(),this.bufferType=$t.StructStorageGPUBuffer,this.createBufferByStruct(GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|r,e,t)}}class Vp{static codeMax=`
11630
11630
  @group(0) @binding(0) var inputTexture : texture_2d<f32>;
11631
11631
  @group(0) @binding(1) var inputTextureSampler : sampler;
11632
11632
  @group(0) @binding(2) var outputTexture : texture_storage_2d<rgba8unorm, write>;