@rings-webgpu/core 1.0.23 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rings.es.js CHANGED
@@ -7272,7 +7272,7 @@ else if (typeof define === 'function' && define['amd'])
7272
7272
  define([], function() { return DracoDecoderModule; });
7273
7273
  else if (typeof exports === 'object')
7274
7274
  exports["DracoDecoderModule"] = DracoDecoderModule;
7275
- `;class Hn{static _workerCode;static _workers=new Map;static async apply(e,t){if(!t.extensions)return;const a=t.extensions.KHR_draco_mesh_compression;if(!a)return;let r=this._workers.get(e.gltf);r||(r=new Worker(await this.initDecoder()),this._workers.set(e.gltf,r)),r.postMessage({type:"init",decoderConfig:{}});let i=e.parseBufferView(a.bufferView);if(!i.result){let n=await new Promise((o,l)=>{r.onmessage=c=>{const f=c.data;f.type=="decode"?o(f.result):f.type=="error"&&l(f.error)},r.postMessage({type:"decoder",buffer:i,attributes:a.attributes},[i])});i.result=n}return i.result}static unload(e){let t=this._workers.get(e);t&&(t.terminate(),this._workers.delete(e))}static async initDecoder(){if(!this._workerCode){const e=new Blob([ef,"",`(${Y2})()`],{type:"application/javascript"});this._workerCode=URL.createObjectURL(e)}return this._workerCode}}function Y2(){let s,e;onmessage=t=>{const a=t.data;switch(a.type){case"init":s=a.decoderConfig,e=new Promise((n,o)=>{s.onModuleLoaded=l=>{n({draco:l})},DracoDecoderModule(s)});break;case"decoder":const r=a.buffer,i=a.attributes;e.then(n=>{const o=n.draco;let l=new o.Decoder,c=new o.DecoderBuffer;c.Init(new Int8Array(r),r.byteLength);let f,d;try{const h=l.GetEncodedGeometryType(c);h==o.TRIANGULAR_MESH?(d=new o.Mesh,f=l.DecodeBufferToMesh(c,d)):self.postMessage(new Error("INVALID_GEOMETRY_TYPE:"+h)),f.ok()||self.postMessage(new Error("DracoDecode:"+f.error_msg()));let b={};for(const p in i){let g=l.GetAttributeByUniqueId(d,i[p]);const A=g.num_components(),_=d.num_points()*A,U=_*Float32Array.BYTES_PER_ELEMENT,v=o.DT_FLOAT32,x=o._malloc(U);l.GetAttributeDataArrayForAllPoints(d,g,v,U,x);const C=new Float32Array(o.HEAPF32.buffer,x,_).slice();o._free(x),b[p]={data:C,numComponents:A,normalize:!1}}{const g=d.num_faces()*3,A=g*4,D=o._malloc(A);l.GetTrianglesUInt32Array(d,A,D);const _=new Uint32Array(o.HEAPF32.buffer,D,g).slice();o._free(D),b.indices={data:_,numComponents:1,normalize:!1}}self.postMessage({type:"decode",result:b})}catch(h){self.postMessage({type:"error",error:h.message})}finally{o.destroy(d),o.destroy(l),o.destroy(c)}});break}}}class tf{gltf;constructor(e){this.gltf=e}parse(e){const t=this.gltf.cameras[e];if(!t)return this.errorMiss("camera",e);if(t.isParsed)return t.dcamera;t.isParsed=!0,t.dcamera=!1;const{name:a,type:r,perspective:i,orthographic:n}=t;if(r==="perspective"&&i){const{aspectRatio:o,yfov:l,zfar:c,znear:f}=i;t.dcamera=Object.assign({},{name:a,type:r,yfov:l,znear:f,aspectRatio:o,zfar:c})}else if(r==="orthographic"&&n){const{xmag:o,ymag:l,zfar:c,znear:f}=n;t.dcamera=Object.assign({},{name:a,type:r,xmag:o,ymag:l,zfar:c,znear:f})}return t.dcamera}errorMiss(e,t){throw new Error(e+t)}}class Dt extends st{static format=ze.JSON;_gltf;async parseJson(e){this._gltf=new Bs,this._gltf={...this._gltf,...e},this._gltf.resources={},await Promise.all([this.load_gltf_bin(),this.load_gltf_textures()]);let t=new vs,a=await t.parse(this.initUrl,this._gltf,this._gltf.scene);return t.destroy(),t=null,a?(this.data=a.rootNode,a.rootNode):(this._gltf=null,null)}verification(){if(this.data)return!0;throw new Error("Method not implemented.")}static _counter=0;static getMeshNameCounter(){return function(){return`GLTF_NO_NAME_PRIMITIVE_${Dt._counter++}`}}static getModelNameCounter(){let e=0;return function(){return`GLTF_NO_NAME_MESH_${e++}`}}static getTexCoordDefine(e){return`UV_NUM ${e}`}static getVertexColorDefine(e){return`HAS_VERTEXCOLOR ${e}`}static getBaseColorTextureDefine(){return"HAS_BASECOLORMAP"}static getMetalRoughnessDefine(){return"HAS_METALROUGHNESSMAP"}static getNormalMapDefine(){return"HAS_NORMALMAP"}static getEmissiveMapDefine(){return"HAS_EMISSIVEMAP"}static getOcclusionMapDefine(){return"HAS_OCCLUSIONMAP"}static getMorphTargetsDefine(e){return`MORPH_TARGET_NUM ${e}`}static getMorphtargetPositionDefine(){return"HAS_MORPH_POSITION"}static getMorphtargetNormalDefine(){return"HAS_MORPH_NORMAL"}static getMorphtargetTangentDefine(){return"HAS_MORPH_TANGENT"}static getJointsNumDefine(e){return`JOINTS_NUM ${e}`}static getJointVec8Define(){return"JOINT_VEC8"}static getHasNormalDefine(){return"HAS_NORMAL"}static getHasTangentDefine(){return"HAS_TANGENT"}static getHasNormalMapDefine(){return"HAS_NORMAL_MAP"}static getAlphaMaskDefine(){return"ALPHA_MASK"}static getAlphaBlendDefine(){return"ALPHA_BLEND"}static defaultMaterial={name:"GLTF_DEFAULT_MATERIAL",alphaCutoff:.33,alphaMode:"MASK",pbrMetallicRoughness:{name:"GLTF_DEFAULT_MATERIAL",defines:[],doubleSided:!1,baseColorFactor:[1,1,1,1],metallicFactor:1,roughnessFactor:1,emissiveFactor:[0,0,0]}};async load_gltf_bin(){if(this._gltf.buffers&&this._gltf.buffers.length>0){let e=[];for(let t=0;t<this._gltf.buffers.length;t++){const a=this._gltf.buffers[t];if(a.uri.substring(0,5)!=="data:"){let r=Ct.parseUrl(this.baseUrl,a.uri);this.loaderFunctions?.onUrl&&(r=await this.loaderFunctions.onUrl(r));let i=new pt().loadBinData(r,this.loaderFunctions).then(n=>{this._gltf.resources[a.uri]=n});e.push(i)}}await Promise.all(e)}}async load_gltf_textures(){if(this._gltf,this._gltf.images){let e=[];for(let t=0;t<this._gltf.images.length;t++){const a=this._gltf.images[t];if(a.uri){let r=Ct.parseUrl(this.baseUrl,a.uri);this.loaderFunctions?.onUrl&&(r=await this.loaderFunctions.onUrl(r));let i=new pt().loadAsyncBitmapTexture(r,this.loaderFunctions).then(n=>{n.name=Ct.getURLName(a.uri),this._gltf.resources[n.name]=n});e.push(i)}}await Promise.all(e)}}}class af{gltf;subParser;constructor(e){this.gltf=e.gltf,this.subParser=e}async parse(e){const t=this.gltf.meshes[e];if(!t)return this.errorMiss("mesh",e);if(t.isParsed)return t.dprimitives;const a=t.primitives,r=t.extras,i=[];for(let n=0;n<a.length;n++){const o=a[n],{attributes:l,indices:c,material:f,mode:d,name:h,targets:b,morphTargetsRelative:p,extensions:g}=o;let A=t.name;for(let F in l)A+=F;A+=`indices:${c}`,A+=`material:${f}`;const D={attribArrays:{indices:[]},weights:[],defines:[],material:null,drawMode:null,meshName:null,modelName:null,morphTargetsRelative:!1,targetNames:r?r.targetNames:null};let _=!1,U=0,v=!1,x;g&&g.KHR_draco_mesh_compression&&(x=await Hn.apply(this.subParser,o));for(const F in l){const w=x?x[F]:this.parseAccessor(l[F]);if(w){let S;switch(F){case"POSITION":S=V.position;break;case"NORMAL":S=V.normal,_=!0;break;case"TEXCOORD_0":S=V.uv,U++;break;case"JOINTS_0":S=V.joints0;break;case"JOINTS_1":S=V.joints1,v=!0;break;case"WEIGHTS_0":S=V.weights0;break;case"WEIGHTS_1":S=V.weights1;break;default:S=F}D.attribArrays[S]=w}}if(_&&D.defines.push(Dt.getHasNormalDefine()),U&&D.defines.push(Dt.getTexCoordDefine(U)),v&&D.defines.push(Dt.getJointVec8Define()),c!==void 0){const F=x?x.indices:this.parseAccessor(c);F&&(D.attribArrays.indices=F)}const C=await this.parseMaterial(f);if(C&&(D.material=C,D.defines=D.defines.concat(C.defines)),D.drawMode=d===void 0?4:d,D.meshName=()=>A,D.modelName=t.name||Dt.getModelNameCounter(),b){D.defines.push(Dt.getMorphTargetsDefine(b.length)),D.morphTargetsRelative=!0;let F=!1,w=!1,S=!1;for(let M=0;M<b.length;M++){const T=b[M];Object.keys(T).forEach(Q=>{const L=this.parseAccessor(T[Q]);if(L){let X;switch(Q){case"POSITION":X=Yt.MORPH_POSITION_PREFIX+M,F=!0;break;case"NORMAL":X=Yt.MORPH_NORMAL_PREFIX+M,w=!0;break;case"TANGENT":X=Yt.MORPH_TANGENT_PREFIX+M,S=!0;break;default:X=!1}X?D.attribArrays[X]=L:console.error(`glTF has unsupported morph target attribute ${Q}`)}})}F&&D.defines.push(Dt.getMorphtargetPositionDefine()),w&&D.defines.push(Dt.getMorphtargetNormalDefine()),S&&D.defines.push(Dt.getMorphtargetTangentDefine()),D.weights=t.weights||new Array(b.length).fill(0)}i.push(D)}return t.dprimitives=i,t.isParsed=!0,t.dprimitives}parseAccessor(e){return this.subParser.parseAccessor(e)}parseMaterial(e){return this.subParser.parseMaterial(e)}errorMiss(e,t){throw new Error(e+t)}}class rf{gltf;subParser;constructor(e){this.gltf=e.gltf,this.subParser=e}async parse(e){let t;if(e==null?t=Dt.defaultMaterial:t=this.gltf.materials[e],!t)return this.errorMiss("material",e);if(t.isParsed)return t.dmaterial;let{name:a,pbrMetallicRoughness:r,normalTexture:i,occlusionTexture:n,emissiveTexture:o,emissiveFactor:l,alphaMode:c,alphaCutoff:f,doubleSided:d,extensions:h}=t;const b={name:a,defines:[],doubleSided:!!d,baseColorFactor:[1,1,1,1],emissiveFactor:null,alphaCutoff:0,enableBlend:!1,baseColorTexture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,emissiveTexture:null,extensions:null,baseMapOffsetSize:null,normalMapOffsetSize:null,emissiveMapOffsetSize:null,roughnessMapOffsetSize:null,metallicMapOffsetSize:null,aoMapOffsetSize:null,metallicFactor:0,roughnessFactor:1};if(r){const{baseColorFactor:p,metallicFactor:g,roughnessFactor:A,baseColorTexture:D,metallicRoughnessTexture:_}=r;if(Object.assign(b,{baseColorFactor:p||[1,1,1,1],metallicFactor:g===void 0?1:g,roughnessFactor:A===void 0?.5:A}),D){let U=D.extensions;if(U){let x=U.KHR_texture_transform;if(x){let C=new te(x.offset?x.offset[0]:0,x.offset?x.offset[1]:0,x.scale?x.scale[0]:1,x.scale?x.scale[1]:1);b.baseMapOffsetSize=C}}const v=await this.parseTexture(D.index);v?b.baseColorTexture=v:b.baseColorTexture=m.res.redTexture}if(i){let U=i.extensions;if(U){let x=U.KHR_texture_transform;if(x){let C=new te(x.offset?x.offset[0]:0,x.offset?x.offset[1]:0,x.scale?x.scale[0]:1,x.scale?x.scale[1]:1);b.normalMapOffsetSize=C}}const v=await this.parseTexture(i.index);v?b.normalTexture=v:b.normalTexture=m.res.normalTexture}if(_){let U=_.extensions;if(U){let x=U.KHR_texture_transform;if(x){let C=new te(x.offset?x.offset[0]:0,x.offset?x.offset[1]:0,x.scale?x.scale[0]:1,x.scale?x.scale[1]:1);b.roughnessMapOffsetSize=C}}const v=await this.parseTexture(_.index);v?b.metallicRoughnessTexture=v:b.metallicRoughnessTexture=m.res.blackTexture}}else Object.assign(b,{baseColorFactor:[1,1,1,1],metallicFactor:0,roughnessFactor:.5});if(b.baseColorFactor&&b.baseColorFactor[3]<1&&(c=c==="MASK"?"MASK":"BLEND"),c&&c!=="OPAQUE"&&(c==="MASK"&&(b.defines.push(Dt.getAlphaMaskDefine()),b.alphaCutoff=f===void 0?.5:f),c==="BLEND"&&(b.defines.push(Dt.getAlphaBlendDefine()),b.enableBlend=!0)),i){const p=await this.parseTexture(i.index);p?b.normalTexture=p:b.normalTexture=m.res.normalTexture}if(n){const p=await this.parseTexture(n.index);p&&(b.occlusionTexture=p)}if(l&&(b.emissiveFactor=l),o){const p=await this.parseTexture(o.index);p?b.emissiveTexture=p:b.emissiveTexture=m.res.blackTexture}return h&&(b.extensions=h),t.isParsed=!0,t.dmaterial=b,b}async parseTexture(e){return this.subParser.parseTexture(e)}errorMiss(e,t){throw new Error(e+t)}}class sf{gltf;subParser;constructor(e){this.gltf=e.gltf,this.subParser=e}parse(e){const t=this.gltf.skins[e];if(!t)return this.errorMiss("skin",e);if(t.isParsed)return t.dskin;const{name:a,joints:r,inverseBindMatrices:i,skeleton:n}=t;if(!r)return this.errorMiss("skin.joints",e);t.isParsed=!0,t.dskin=!1;let o={name:a,skeleton:null,inverseBindMatrices:null,joints:r,defines:[Dt.getJointsNumDefine(r.length)]};if(n)o.skeleton=n;else{var l=-1;for(let c=0;c<this.gltf.nodes.length;c++)if(this.gltf.nodes[c].name=="root"){l=c;break}if(l==-1){let c=this.gltf.scenes[this.gltf.scene];l=c.nodes[c.nodes.length-1]}o.skeleton=l}if(o.inverseBindMatrices=Yt.IDENTITY_INVERSE_BIND_MATRICES,i!==void 0){const c=this.parseAccessor(i);if(c){const f=c.data,d=[];for(let h=0;h<f.length;h+=16)d.push(f.slice(h,h+16));o.inverseBindMatrices=d}else o=null}return t.dskin=o,t.dskin}parseAccessor(e){return this.subParser.parseAccessor(e)}errorMiss(e,t){throw new Error(e+t)}}class nf{name="";index=0;instanceID="";parent=null;scale=new u;rotation=new j;translation=new u;constructor(e=""){this.name=e}}class Kn{index;worldMatrix;constructor(e,t=!1){this.index=e,this.worldMatrix=new E(!t)}}class Ui{time;_skeleton;_jointsPose;mJointMatrixIndexTable;constructor(e,t=!1){this._skeleton=e,this._jointsPose=new Array(e.numJoint),this.mJointMatrixIndexTable=new Array(e.numJoint);for(let a=0;a<e.numJoint;a++){let r=new Kn(a,t);this._jointsPose[a]=r,this.mJointMatrixIndexTable[a]=r.worldMatrix.index}}buildSkeletonPose(e){let t=new u,a=new j,r=new u,i=new Array(this._skeleton.numJoint);this.time=e[11]>0?e[11]:e[24];for(let n=0;n<this._skeleton.numJoint;n++){let o=12*n*4,l=new Float32Array(e.buffer,e.byteOffset+o,12),c=new E;t.set(l[0],l[1],l[2]),a.set(l[4],l[5],l[6],l[7]),r.set(l[8],l[9],l[10]),ps(a.getEulerAngles(),r,t,c),i[n]=c;let f=new Kn(n);const d=this._skeleton.getJointParentIndex(n);if(d<0)f.worldMatrix.copyFrom(c);else{let h=this._jointsPose[d];yc(h.worldMatrix,c,f.worldMatrix)}this._jointsPose[n]=f}}get numJoint(){return this._skeleton.numJoint}get joints(){return this._jointsPose}get jointMatrixIndexTable(){return this.mJointMatrixIndexTable}lerp(e,t,a){if(e&&t)for(let r=0;r<this._jointsPose.length;r++){let i=e._jointsPose[r],n=t._jointsPose[r];this._jointsPose[r].worldMatrix.lerp(i.worldMatrix,n.worldMatrix,a)}else for(let r=0;r<this._jointsPose.length;r++){let i=e._jointsPose[r];this._jointsPose[r].worldMatrix.copyFrom(i.worldMatrix)}}copyFrom(e){for(let t=0;t<this._jointsPose.length;t++)this._jointsPose[t].worldMatrix.copyFrom(e._jointsPose[t].worldMatrix)}reset(){for(let e=0;e<this._jointsPose.length;e++)this._jointsPose[e].worldMatrix.identity()}}class of extends $e{skeletonAnimation;constructor(e,t){super(),this.type=e,this.time=t}}class js{name="";_skeleton;_skeletonPoses;_animationClipData;_events;constructor(e,t,a,r){if(this.name=e,this._skeleton=t,this._animationClipData=r,a>0&&r){this._skeletonPoses=new Array(a);let i=12*t.numJoint;for(let n=0;n<a;n++){let o=i*n*4;const l=r.buffer instanceof ArrayBuffer?r.buffer:new Uint8Array(r.buffer).buffer;let c=new Float32Array(l,o,i),f=new Ui(t);f.buildSkeletonPose(c),this._skeletonPoses[n]=f}}}get totalTime(){return this._skeletonPoses[this._skeletonPoses.length-1].time}get frameRate(){return this.totalTime/this._skeletonPoses.length}get skeleton(){return this._skeleton}get numFrame(){return this._skeletonPoses.length-1}get animationClipData(){return this._animationClipData}getSkeletonPose(e){return this._skeletonPoses[e]}getLerpSkeletonPose(e,t,a,r){let i=this.getSkeletonPose(e),n=this.getSkeletonPose(t);return r.lerp(i,n,a),r}createSubClip(e,t,a){var r=new js(e,this._skeleton,0,null);const i=Math.max(Math.floor(t/this.frameRate),0),n=Math.min(Math.floor(a/this.frameRate),this._skeletonPoses.length-1);r._skeletonPoses=this._skeletonPoses.slice(i,n);const o=12*this._skeleton.numJoint*4,l=this._animationClipData.buffer instanceof ArrayBuffer?this._animationClipData.buffer:new Uint8Array(this._animationClipData.buffer).buffer;return this._animationClipData=new Float32Array(l,i*o,(n-i)*o),r}addEvent(e,t){this._events||(this._events=new Array),this._events.push(new of(e,t))}removeEvent(e){this._events&&(this._events=this._events.filter(t=>t.type!=e))}getEvents(){return this._events}}class qn{gltf;subParser;constructor(e){this.gltf=e.gltf,this.subParser=e}parse(e){let t=new Eo;return t.name="Id:"+e,t.count=0,t.boneData=[],t.boneMap=new Map,this.buildSkeleton(t,void 0,e),t}parseSkeletonAnimation(e,t){let a=new Jo;a.clipName=t.name,a.useSkeletonPos=!1,a.useSkeletonScale=!1;for(let r of t.channels){let i=t.samplers[r.sampler];const n=this.subParser.parseAccessor(i.input),o=this.subParser.parseAccessor(i.output);let l=r.target.node,c=r.target.path,f=this.gltf.nodes[l];if(!f||!e.boneMap.has(f.name))continue;let d=e.boneMap.get(f.name);switch(c){case"scale":{let h=new hr(o.numComponents);h.path="",h.attribute="",h.propertys=h.attribute.split("."),h.preInfinity=0,h.postInfinity=0,h.rotationOrder=0,a.useSkeletonScale=!0,a.scaleCurves.set(d.bonePath,h);for(let b=0;b<n.data.length;b++){const p=n.data[b],g=b*o.numComponents;let A=new Ji(0);A.time=p;const D=new u().set(o.data[g+0],o.data[g+1],o.data[g+2]);A.split(G.vector3,D,"value"),h.addKeyFrame(A)}}break;case"rotation":{let h=new hr(o.numComponents);h.path="",h.attribute="",h.propertys=h.attribute.split("."),h.preInfinity=0,h.postInfinity=0,h.rotationOrder=0,a.rotationCurves.set(d.bonePath,h);for(let b=0;b<n.data.length;b++){const p=n.data[b],g=b*o.numComponents;let A=new Ji(0);A.time=p;const D=new j().set(o.data[g+0],o.data[g+1],o.data[g+2],o.data[g+3]);A.split(G.quaternion,D,"value"),h.addKeyFrame(A)}}break;case"translation":{let h=new hr(o.numComponents);h.path="",h.attribute="",h.propertys=h.attribute.split("."),h.preInfinity=0,h.postInfinity=0,h.rotationOrder=0,a.useSkeletonPos=!0,a.positionCurves.set(d.bonePath,h);for(let b=0;b<n.data.length;b++){const p=n.data[b],g=b*o.numComponents;let A=new Ji(0);A.time=p;const D=new u().set(o.data[g+0],o.data[g+1],o.data[g+2]);A.split(G.vector3,D,"value"),h.addKeyFrame(A)}}break}}return a}parseSkeletonAnimationOld(e,t){let a=this.subParser.parseAccessor(t.samplers[0].input),r=a.data.length,i=a.data[1]-a.data[0];a.data[a.data.length-1];let n=12*e.numJoint,o=new Float32Array(n*r);for(var l=0;l<e.numJoint;l++)for(var c=0;c<r;c++){var f=n*c+12*l;o[f+0]=1,o[f+1]=1,o[f+2]=1,o[f+3]=1}for(let g of t.channels){let A=t.samplers[g.sampler];const D=this.subParser.parseAccessor(A.input),_=this.subParser.parseAccessor(A.output);let U=g.target.node,v=g.target.path,x=this.gltf.nodes[U];if(!x)continue;let C=e.getJointByName(x.name);if(C)switch(v){case"scale":if(r*_.numComponents==_.data.length)for(var c=0;c<r;c++){var d=c*_.numComponents,f=n*c+12*C.index;o[f+0]=_.data[d+0],o[f+1]=_.data[d+1],o[f+2]=_.data[d+2],o[f+3]=1}else if(D.data.length==2){let F=0;D.data[0];let w=D.data[1];var h=0*_.numComponents;u.HELP_0.set(_.data[h+0],_.data[h+1],_.data[h+2]);var b=1*_.numComponents;u.HELP_1.set(_.data[b+0],_.data[b+1],_.data[b+2]);for(var c=0;c<r;c++){let M=F/w;u.HELP_2.lerp(u.HELP_0,u.HELP_1,M);var f=n*c+12*C.index;o[f+0]=u.HELP_2.x,o[f+1]=u.HELP_2.y,o[f+2]=u.HELP_2.z,o[f+3]=1,F+=i}}else throw new Error("Unsupported animation sampler interpolation.");break;case"rotation":if(r*_.numComponents==_.data.length)for(var c=0;c<r;c++){var d=c*_.numComponents,f=n*c+12*C.index+4;o[f+0]=_.data[d+0],o[f+1]=_.data[d+1],o[f+2]=_.data[d+2],o[f+3]=_.data[d+3]}else if(D.data.length==2){let F=0;D.data[0];let w=D.data[1];var h=0*_.numComponents;u.HELP_0.set(_.data[h+0],_.data[h+1],_.data[h+2],_.data[h+3]);var b=1*_.numComponents;u.HELP_1.set(_.data[b+0],_.data[b+1],_.data[b+2],_.data[b+3]);for(var c=0;c<r;c++){let Q=F/w;u.HELP_2.lerp(u.HELP_0,u.HELP_1,Q);var f=n*c+12*C.index+4;o[f+0]=u.HELP_2.x,o[f+1]=u.HELP_2.y,o[f+2]=u.HELP_2.z,o[f+3]=u.HELP_2.w,F+=i}}else throw new Error("Unsupported animation sampler interpolation.");break;case"translation":if(r*_.numComponents==_.data.length)for(var c=0;c<r;c++){var d=c*_.numComponents,f=n*c+12*C.index+8;o[f+0]=_.data[d+0],o[f+1]=_.data[d+1],o[f+2]=_.data[d+2],o[f+3]=D.data[c*D.numComponents]}else if(D.data.length==2){let F=0;D.data[0];let w=D.data[1];var h=0*_.numComponents;u.HELP_0.set(_.data[h+0],_.data[h+1],_.data[h+2]);var b=1*_.numComponents;u.HELP_1.set(_.data[b+0],_.data[b+1],_.data[b+2]);for(var c=0;c<r;c++){let Q=F/w;u.HELP_2.lerp(u.HELP_0,u.HELP_1,Q);var f=n*c+12*C.index+8;o[f+0]=u.HELP_2.x,o[f+1]=u.HELP_2.y,o[f+2]=u.HELP_2.z,o[f+3]=F,F+=i}}else throw new Error("Unsupported animation sampler interpolation.");break}}return new js(t.name,e,r,o)}buildSkeleton(e,t,a){let r=this.gltf.nodes[a];r.name||(r.name="Bone"+e.count);let i=new ko;if(i.boneName=r.name,i.bonePath=t?t.bonePath+"/"+r.name:r.name,i.parentBoneName=t?t.boneName:"",i.boneID=e.count++,i.parentBoneID=t?t.boneID:-1,i.instanceID="",i.parentInstanceID="",i.s=new u(1,1,1),r.scale&&i.s.set(r.scale[0],r.scale[1],r.scale[2]),i.q=new j,r.rotation&&i.q.set(r.rotation[0],r.rotation[1],r.rotation[2],r.rotation[3]),i.t=new u,r.translation&&i.t.set(r.translation[0],r.translation[1],r.translation[2]),e.boneData.push(i),e.boneMap.set(i.boneName,i),r.children)for(let n of r.children)this.buildSkeleton(e,i,n)}buildSkeletonOld(e,t,a,r=0){let i=this.gltf.nodes[a];i.name||(i.name="Node_"+a);let n=new nf(i.name);if(n.parent=t,i.scale&&n.scale.set(i.scale[0],i.scale[1],i.scale[2]),i.rotation&&n.rotation.set(i.rotation[0],i.rotation[1],i.rotation[2],i.rotation[3]),i.translation&&n.translation.set(i.translation[0],i.translation[1],i.translation[2]),e.addJoint(n),i.children)for(let o of i.children)this.buildSkeletonOld(e,n,o,r+1)}}class $n{static list=[];static add(e){this.list.indexOf(e)==-1&&this.list.push(e)}static remove(e){let t=this.list.indexOf(e);t!=-1&&this.list.splice(t,1)}}class xi extends Pe{name;size=1;lightData;dirFix=1;bindOnChange;needUpdateShadow=!0;realTimeShadow=!0;_castGI=!1;_castShadow=!1;_iesProfiles;constructor(){super()}init(){this.transform.object3D.bound=new ge(new u,new u),this.lightData=new ms,this.lightData.lightMatrixIndex=this.transform.worldMatrix.index}onChange(){this.bindOnChange&&this.bindOnChange(),this.transform.object3D.bound.setFromCenterAndSize(this.transform.worldPosition,new u(this.size,this.size,this.size)),this._castGI&&(J.instance.state.giLightingChange=!0),this._castShadow?(this.needUpdateShadow=!0,It.addShadowLight(this)):It.removeShadowLight(this),this.transform.view3D&&m.renderJobs&&m.renderJobs.get(this.transform.view3D).reflectionRenderer&&m.renderJobs.get(this.transform.view3D).reflectionRenderer.forceUpdate()}start(){this.transform.onPositionChange=()=>this.onPositionChange(),this.transform.onRotationChange=()=>this.onRotChange(),this.onPositionChange(),this.onRotChange()}onPositionChange(){this.lightData.lightPosition.copyFrom(this.transform.worldPosition),this.onChange()}onRotChange(){this.dirFix==1?this.lightData.direction.copyFrom(this.transform.forward):this.lightData.direction.copyFrom(this.transform.back),this.lightData.lightTangent.copyFrom(this.transform.up),this.onChange()}onScaleChange(){this.onChange()}onEnable(){this.onChange(),J.instance.addLight(this.transform.scene3D,this)}onDisable(){this.onChange(),J.instance.removeLight(this.transform.scene3D,this),It.removeShadowLight(this)}set iesProfiles(e){this._iesProfiles=e,this.lightData.iesIndex=e.index,ba.use=!0,this.onChange()}get iesProfile(){return this._iesProfiles}get r(){return this.lightData.lightColor.r}set r(e){this.lightData.lightColor.r=e,this.onChange()}get g(){return this.lightData.lightColor.g}set g(e){this.lightData.lightColor.g=e,this.onChange()}get b(){return this.lightData.lightColor.b}set b(e){this.lightData.lightColor.b=e,this.onChange()}get lightColor(){return this.lightData.lightColor}set lightColor(e){this.lightData.lightColor=e,this.onChange()}get color(){return this.lightData.lightColor}set color(e){this.lightData.lightColor=e,this.onChange()}get intensity(){return this.lightData.intensity}set intensity(e){this.lightData.intensity=e,this.onChange()}set castShadow(e){e!=this._castShadow&&(this._castShadow=e,this.onChange())}get castShadow(){return this._castShadow}get shadowIndex(){return this.lightData.castShadowIndex}get castGI(){return this._castGI}set castGI(e){e?$n.add(this):$n.remove(this),this._castGI=e,e&&this.onChange()}get direction(){return this.lightData.direction}destroy(e){this.bindOnChange=null,J.instance.removeLight(this.transform.scene3D,this),It.removeShadowLight(this),this.transform.eventDispatcher.removeEventListener(Qt.ROTATION_ONCHANGE,this.onRotChange,this),this.transform.eventDispatcher.removeEventListener(Qt.SCALE_ONCHANGE,this.onScaleChange,this),super.destroy(e)}}var X2=Object.getOwnPropertyDescriptor,H2=(s,e,t,a)=>{for(var r=a>1?void 0:a?X2(e,t):e,i=s.length-1,n;i>=0;i--)(n=s[i])&&(r=n(r)||r);return r};let yi=class extends xi{shadowCamera;constructor(){super()}init(){super.init(),this.object3D.name==""&&(this.object3D.name="DirectionLight_"+Et()),this.radius=Number.MAX_SAFE_INTEGER,this.lightData.lightType=Xe.DirectionLight,this.lightData.linear=0,this.lightData.quadratic=.3}start(){super.start(),this.castGI=!0}get radius(){return this.lightData.range}set radius(s){this.lightData.range=s,this.onChange()}get indirect(){return this.lightData.quadratic}set indirect(s){this.lightData.quadratic=s,this.onChange()}debug(){}};yi=H2([Vt(yi,"DirectLight")],yi);var K2=Object.getOwnPropertyDescriptor,q2=(s,e,t,a)=>{for(var r=a>1?void 0:a?K2(e,t):e,i=s.length-1,n;i>=0;i--)(n=s[i])&&(r=n(r)||r);return r};let ai=class extends xi{constructor(){super()}init(){super.init(),this.lightData.lightType=Xe.PointLight,this.object3D.name==""&&(this.object3D.name="PointLight"+Et())}get range(){return this.lightData.range}set range(s){this.lightData.range=s,this.onChange()}get at(){return this.lightData.linear}set at(s){this.lightData.linear=s,this.onChange()}get radius(){return this.lightData.radius}set radius(s){this.lightData.radius=s,this.onChange()}get quadratic(){return this.lightData.quadratic}set quadratic(s){this.lightData.quadratic=s,this.onChange()}start(){this.transform.rotationX=90,super.start()}onUpdate(){}onGraphic(s){}debug(){}debugDraw(s){}};ai=q2([Vt(ai,"PointLight")],ai);var $2=Object.getOwnPropertyDescriptor,eb=(s,e,t,a)=>{for(var r=a>1?void 0:a?$2(e,t):e,i=s.length-1,n;i>=0;i--)(n=s[i])&&(r=n(r)||r);return r};let Ci=class extends xi{constructor(){super()}init(){super.init(),this.lightData.lightType=Xe.SpotLight,this.object3D.name==""&&(this.object3D.name="SpotLight"+Et())}get innerAngle(){return this.lightData.innerAngle/this.lightData.outerAngle*100}set innerAngle(s){this.lightData.innerAngle=se(s,0,100)/100*this.lightData.outerAngle,this.onChange()}get outerAngle(){return this.lightData.outerAngle*Xr*2}set outerAngle(s){this.lightData.outerAngle=se(s,1,179)*rt*.5,this.onChange()}get radius(){return this.lightData.radius}set radius(s){this.lightData.radius=s,this.onChange()}get range(){return this.lightData.range}set range(s){this.lightData.range=s,this.onChange()}get at(){return this.lightData.linear}set at(s){this.lightData.linear=s,this.onChange()}start(){super.start(),this.lightData.lightType=Xe.SpotLight}onUpdate(){}onGraphic(s){}debug(){}debugDraw(s){}};Ci=eb([Vt(Ci,"SpotLight")],Ci);class lf{static apply(e,t,a){let r=t.extensions;if(r&&r.KHR_materials_clearcoat){a.shader.getDefaultColorShader().setDefine("USE_CLEARCOAT",!0);let i=r.KHR_materials_clearcoat;"clearcoatFactor"in i&&(t.clearcoatFactor=i.clearcoatFactor,a.clearcoatFactor=t.clearcoatFactor),"clearcoatRoughnessFactor"in i&&(t.clearcoatRoughnessFactor=i.clearcoatRoughnessFactor,a.clearcoatRoughnessFactor=t.clearcoatRoughnessFactor)}}}class cf{static apply(e,t,a){let r=t.extensions;r&&r.KHR_materials_emissive_strength?(a.emissiveIntensity=r.KHR_materials_emissive_strength.emissiveStrength,a.emissiveMap==m.res.blackTexture&&(a.emissiveMap=m.res.whiteTexture)):a.emissiveIntensity=1}}class ff{static apply(e,t,a){let r=t.extensions;r&&r.KHR_materials_unlit?a.supportLight=!1:a.supportLight=!0}}class df{gltf;subParser;_testCount=8;_hasCastShadow=!1;constructor(e){this.gltf=e.gltf,this.subParser=e}async convertNodeToObject3D(e,t){const a=new ee;if(a.name=e.name,a[Yt.GLTF_NODE_INDEX_PROPERTY]=e.nodeId,e.nodeObj=a,e.matrix&&(e.translation=[0,0,0],e.rotation=[0,0,0,1],e.scale=[1,1,1]),e.translation&&(a.transform.x=e.translation[0],a.transform.y=e.translation[1],a.transform.z=e.translation[2]),e.rotation){let r=new j;r.setFromArray(e.rotation),a.transform.localRotQuat=r}return e.scale&&(a.transform.scaleX=e.scale[0],a.transform.scaleY=e.scale[1],a.transform.scaleZ=e.scale[2]),t.addChild(a),e.light&&this.convertLight(e,a),e.primitives&&this.convertprimitives(e,a),e.skeleton&&this.convertSkeletonAnim(a,e.skeleton),a}convertSkeletonAnim(e,t){let a=this.subParser.parseSkeleton(t.skeleton);m.res.addObj(a.name,a);let r=[];for(let n=0;n<this.gltf.animations.length;n++){let o=this.gltf.animations[n];o.name||(o.name=n.toString());let l=this.subParser.parseSkeletonAnimation(a,o);r.push(l)}let i=e.addComponent(Pa);i.avatar=a.name,i.clips=r}convertLight(e,t){switch(e.light.type){case"directional":let a=t.addComponent(yi);t.name=e.light.name,a.intensity=e.light.intensity*.1,a.radius=Number.MAX_SAFE_INTEGER,a.dirFix=-1,this._hasCastShadow||(this._hasCastShadow=!0,a.castShadow=this._hasCastShadow),a.lightColor=e.light.color?new P(e.light.color[0],e.light.color[1],e.light.color[2]):new P(1,1,1,1),a.debug();break;case"point":if(this._testCount>0){let i=t.addComponent(ai);i.name=e.light.name,i.intensity=e.light.intensity?e.light.intensity*8*2:1,i.radius=8,i.at=2,i.range=e.light.range?e.light.range:8,i.lightColor=e.light.color?new P(e.light.color[0],e.light.color[1],e.light.color[2]):new P(1,1,1,1)}this._testCount--;break;case"spot":let r=t.addComponent(Ci);r.name=e.light.name,r.intensity=e.light.intensity*5,r.radius=1,r.dirFix=-1,r.at=2,r.range=e.light.range?e.light.range:8,r.outerAngle=e.light.spot.outerConeAngle*Xr,r.lightColor=e.light.color?new P(e.light.color[0],e.light.color[1],e.light.color[2]):new P(1,1,1,1);break}}convertprimitives(e,t){for(let a=0;a<e.primitives.length;a++){const r=e.primitives[a];r.modelName;let i=r.material;i.name==null&&(i.name=Et());let n,o=`matkey_${i.name}`;if(i&&this.gltf.resources[o])n=this.gltf.resources[o];else{let b=i;const p=b?.extensions?.KHR_materials_unlit!==void 0;let g=p?new nt:new ka;if(n=g,this.gltf.resources[o]=g,g.name=i.name,b){const{baseColorTexture:A,baseColorFactor:D,metallicFactor:_,roughnessFactor:U,doubleSided:v,metallicRoughnessTexture:x,normalTexture:C,occlusionTexture:F,emissiveTexture:w,emissiveFactor:S,enableBlend:M,alphaCutoff:T}=b;let Q=g=this.applyMaterialExtensions(b,g);if(p){const L=Q;L.baseColor=new P(D[0],D[1],D[2],D[3]),A&&(L.baseMap=A),Q.doubleSide=v,"enableBlend"in b&&(b.enableBlend?(b.defines?.includes("ALPHA_BLEND")?Q.blendMode=ae.ALPHA:Q.blendMode=ae.NORMAL,Q.castShadow=!1):Q.blendMode=ae.NONE),"alphaCutoff"in b&&T>0&&T<1&&(Q.setUniformFloat("alphaCutoff",T),Q.blendMode=ae.NORMAL,Q.transparent=!0)}else if("enableBlend"in b&&(b.enableBlend?(b.defines?.includes("ALPHA_BLEND")?Q.blendMode=ae.ALPHA:Q.blendMode=ae.NORMAL,Q.castShadow=!1):Q.blendMode=ae.NONE),"alphaCutoff"in b&&T>0&&T<1&&(Q.setUniformFloat("alphaCutoff",T),Q.blendMode=ae.NORMAL,Q.transparent=!0),b.baseMapOffsetSize&&Q.setUniformVector4("baseMapOffsetSize",b.baseMapOffsetSize),b.normalMapOffsetSize&&Q.setUniformVector4("normalMapOffsetSize",b.normalMapOffsetSize),b.emissiveMapOffsetSize&&Q.setUniformVector4("emissiveMapOffsetSize",b.emissiveMapOffsetSize),b.roughnessMapOffsetSize&&Q.setUniformVector4("roughnessMapOffsetSize",b.roughnessMapOffsetSize),b.metallicMapOffsetSize&&Q.setUniformVector4("metallicMapOffsetSize",b.metallicMapOffsetSize),b.aoMapOffsetSize&&Q.setUniformVector4("aoMapOffsetSize",b.aoMapOffsetSize),Q.setUniformColor("baseColor",new P(D[0],D[1],D[2],D[3])),Q.setUniformFloat("roughness",U??1),Q.setUniformFloat("metallic",_??0),Q.setUniformFloat("ao",1),Q.doubleSide=v,A&&Q.setTexture("baseMap",A),C&&Q.setTexture("normalMap",C),x?(Q.setTexture("maskMap",x),Q.shader.setDefine("USE_ROUGHNESS_G",!0),Q.shader.setDefine("USE_METALLIC_B",!0)):(Q.shader.setDefine("USE_ROUGHNESS_G",!1),Q.shader.setDefine("USE_METALLIC_B",!1)),w&&Q.setTexture("emissiveMap",w),S&&(S[0]>0||S[1]>0||S[2]>0)){Q.shader.getTexture("emissiveMap")||Q.shader.setTexture("emissiveMap",m.res.whiteTexture),Q.shader.setDefine("USE_EMISSIVEMAP",!0),Q.setUniformColor("emissiveColor",new P(S[0],S[1],S[2],S[3])),Q.blendMode!=ae.NONE&&(Q.blendMode=ae.ADD);let L=n.getUniformFloat("emissiveIntensity");(!L||L<=0)&&n.setUniformFloat("emissiveIntensity",1)}}}const{attribArrays:l,modelName:c,drawMode:f}=r;let d;if(!l.indices.data){let b=[],p=l.position.data.length/3/3;for(let g=0;g<p;g++){let A=g*3;b.push(A+2),b.push(A+0),b.push(A+1)}l.indices={data:new Uint8Array(b),normalize:!1,numComponents:1}}let h=!l.normal;if(h){let b=[],p=l.position.data.length/3;for(let g=0;g<p;g++)b.push(0),b.push(0),b.push(0);l.normal={data:new Float32Array(b),normalize:!1,numComponents:3}}if(l.indices.data&&l.indices.data.length>3){let b=r.meshName();this.gltf.resources[b]&&(d=this.gltf.resources[b]);const p=new ee;if(p.name=c+a,this.gltf.animations&&l[V.joints0]!=null){d||=this.createGeometryBase(c,l,r,e.skin),this.gltf.resources[b]=d,h&&l.indices?.data&&l.indices.data.length>0&&d.computeNormals();let g=this.gltf.nodes[e.skin.skeleton];g.dnode&&g.dnode.nodeObj?this.convertSkeletonAnim(t,e.skin):g.dnode.skeleton=e.skin;let A=p.addComponent(lr);A.geometry=d,A.material=n}else{d||=this.createGeometryBase(c,l,r),this.gltf.resources[b]=d,h&&l.indices?.data&&l.indices.data.length>0&&d.computeNormals(),d.hasAttribute(V.joints0)&&d.vertexAttributeMap.delete(V.joints0);let g=p.addComponent($);g.castShadow=!0,g.castGI=!0,g.geometry=d,g.material=n}e.skin&&e.skin.defines,t.addChild(p)}}}createGeometryBase(e,t,a,r){"indices"in t&&(t.indices.data.length>65534?t.indices.data=new Uint32Array(t.indices.data):t.indices.data=new Uint16Array(t.indices.data));let i=new Ee;if(i.name=e,"indices"in t&&(t.indices.data.length>65535?t.indices.data=new Uint32Array(t.indices.data):t.indices.data=new Uint16Array(t.indices.data)),a.morphTargetsRelative){let l=new Io,c=a.targetNames;if(c&&c.length>0){l.shapeNames=[],l.shapeIndexs=[];for(let f=0;f<c.length;f++)l.shapeNames.push(c[f]),l.shapeIndexs.push(f)}l.vertexCount=t.position.data.length/3,l.blendCount=l.shapeNames.length,l.blendShapePropertyDatas=[],l.blendShapeMap=new Map;for(let f=0;f<l.blendCount;f++){let d=new Ro;d.shapeName=l.shapeNames[f],d.shapeIndex=l.shapeIndexs[f],d.frameCount=1,d.blendPositionList=t[Yt.MORPH_POSITION_PREFIX+f].data,d.blendNormalList=t[Yt.MORPH_NORMAL_PREFIX+f].data,l.blendShapePropertyDatas.push(d),l.blendShapeMap.set(d.shapeName,d)}i.blendShapeData=l}i.morphTargetsRelative=a.morphTargetsRelative;let n=a.targetNames;if(n&&n.length>0){let l=i.morphTargetDictionary={};for(let c=0;c<n.length;c++)l[n[c]]=c}if(i.morphTargetDictionary){let l=t.position.data.length/3,c=new Float32Array(l);for(let f=0;f<l;f++)c[f]=f;t.vIndex={data:c,normalize:!1,numComponents:1}}for(const l in t){let c=t[l];i.setAttribute(l,c.data)}if(r){i.skinNames=new Array(r.joints.length);for(let l=0;l<r.joints.length;l++){const c=r.joints[l],f=this.gltf.nodes[c];i.skinNames[l]=f.name}i.bindPose=new Array(r.inverseBindMatrices.length);for(let l=0;l<r.inverseBindMatrices.length;l++){const c=r.inverseBindMatrices[l];let f=new E;f.rawData.set(c),i.bindPose[l]=f}}let o=i.getAttribute(V.indices);return i.addSubGeometry({indexStart:0,indexCount:o.data.length,vertexStart:0,index:0,vertexCount:0,firstStart:0,topology:0}),i}applyMaterialExtensions(e,t){return e.extensions&&(lf.apply(this.gltf,e,t),ff.apply(this.gltf,e,t),cf.apply(this.gltf,e,t)),t}parseSkinJoints(e){let t=[];for(let a of e.joints){let r=this.gltf.nodes[a];t.push(r.name)}return t}}class vs{currentSceneName;gltf;initUrl;_generator;_version;_BASE64_MARKER=";base64,";_cameraParser=null;_meshParser=null;_materialParser=null;_skinParser=null;_skeletonParser=null;_converter=null;constructor(){}get version(){return this.version?this.version:this.gltf?this.gltf.asset?(this._version=this.gltf.asset.version,this.gltf.asset.minVersion&&(this._version+=`\r minVersion${this.gltf.asset.minVersion}`),this.version):this.errorMiss("asset"):(console.warn("glTF not loaded."),null)}async parse(e,t,a){this.gltf=t,this.initUrl=e;const{version:r,generator:i}=this.gltf.asset;if(this._generator=i,r!=="2.0")return console.error(`GLTFParser only support glTF 2.0 for now! Received glTF version: ${this.version}`),!1;const n={nodes:await this.parseScene(a),animations:this.parseAnimations(),name:this.currentSceneName};return await this.convertToNode(n)}destroy(){Hn.unload(this.gltf),this.gltf=null}async parseScene(e){const t=e||this.gltf.scene||0,a=this.gltf.scenes[t];if(typeof a>"u")return this.errorMiss("scene",t);this.currentSceneName=a.name||"GLTF_NO_NAME_SCENE";const r=[],i=a.nodes;for(let n=0;n<i.length;n++){const o=await this.parseNode(i[n]);o&&r.push(o)}return r}async parseNode(e){const t=this.gltf.nodes[e];if(!t)return this.errorMiss("node",e);if(t.isParsed)return t.dnode;const{name:a,matrix:r,translation:i,rotation:n,scale:o}=t,l={name:a,matrix:r,translation:i,rotation:n,scale:o,nodeId:e,camera:null,primitives:null,skin:null,children:null,light:null};if(t.camera!==void 0&&(l.camera=this.parseCamera(t.camera)),t.mesh!==void 0&&(l.primitives=await this.parseMesh(t.mesh)),t.extensions!==void 0&&this.applyNodeExtensions(t,l),t.skin!==void 0){const c=this.parseSkin(t.skin);c&&(l.skin=c)}if(l.children=[],t.children)for(let c=0;c<t.children.length;c++)l.children.push(await this.parseNode(t.children[c]));return t.dnode=l,t.isParsed=!0,t.dnode}errorMiss(e,t){throw new Error(e+t)}parseCamera(e){return this._cameraParser||(this._cameraParser=new tf(this.gltf)),this._cameraParser.parse(e)}async parseMesh(e){return this._meshParser||(this._meshParser=new af(this)),this._meshParser.parse(e)}async parseTexture(e){let t=this.gltf.textures[e];if(t&&!t.dtexture){if(t&&t.source!=null){let a=this.gltf.images[t.source];if(a.uri){let r=a.uri;r=Ct.getURLName(r),t.dtexture=this.gltf.resources[r]}else if(a.bufferView){let r=this.parseBufferView(a.bufferView),i=new Va,n=new Blob([r],{type:a.mimeType});await i.loadFromBlob(n),t.dtexture=i}else t.dtexture=this.gltf.resources[a.name]}else if(t.name){let a=Ct.getURLName(t.name);t.dtexture=this.gltf.resources[a]}}return t.dtexture||console.log("miss texture , please check texture!",e,t),t.dtexture}async parseMaterial(e){return this._materialParser||(this._materialParser=new rf(this)),this._materialParser.parse(e)}parseAnimations(){return[]}async parseObject3D(e,t){return this._converter||(this._converter=new df(this)),this._converter.convertNodeToObject3D(e,t)}parseSkeleton(e){return this._skeletonParser||(this._skeletonParser=new qn(this)),this._skeletonParser.parse(e)}parseSkeletonAnimation(e,t){return this._skeletonParser||(this._skeletonParser=new qn(this)),this._skeletonParser.parseSkeletonAnimation(e,t)}async traverse(e,t){for(let a=0;a<t.length;a++){const r=await this.parseObject3D(t[a],e);await this.traverse(r,t[a].children)}}async convertToNode(e){const t=new ee;t.name=e.name;const a=e.nodes;e.animations;const r=[],i=[];return await this.traverse(t,a),{rootNode:t,textures:r,animations:void 0,cameras:i}}parseSkin(e){return this._skinParser||(this._skinParser=new sf(this)),this._skinParser.parse(e)}parseAccessor(e){const t=this.gltf.accessors[e];if(!t)return this.errorMiss("accessor",e);if(t.isParsed)return t.daccessor;t.isParsed=!0,t.daccessor=!1;const a=!!t.normalized,r=this.gltf.bufferViews[t.bufferView],i=r&&r.byteStride,n=Xn(t.componentType);let o=1;switch(t.type){case"SCALAR":o=1;break;case"VEC2":o=2;break;case"VEC3":o=3;break;case"VEC4":case"MAT2":o=4;break;case"MAT3":o=9;break;case"MAT4":o=16;break;default:o=0;break}if(o===0)return console.error(`glTF has unknown data type in accessor: ${t.type}`),!1;const l=o*n.BYTES_PER_ELEMENT;let c;if(r!==void 0){if(c=this.parseBufferView(t.bufferView),!c)return t.daccessor}else c=new Uint8Array(l*t.count).buffer;let f=this.getTypedArrayFromArrayBuffer(c,i,t.byteOffset||0,n,o,t.count);if(t.sparse){const{count:d,indices:h,values:b}=t.sparse;f=new n(f);const p=h.byteOffset||0,g=this.gltf.bufferViews[h.bufferView],A=Xn(h.componentType),D=this.parseBufferView(h.bufferView),_=this.getTypedArrayFromArrayBuffer(D,g.byteStride,p,A,1,d),U=b.byteOffset||0,v=this.gltf.bufferViews[b.bufferView],x=this.parseBufferView(b.bufferView),C=this.getTypedArrayFromArrayBuffer(x,v.byteStride,U,n,o,d);for(let F=0;F<_.length;F++)f.set(C.slice(F*o,F*o+o),_[F]*o)}return t.computeResult={typedArray:f,arrayType:n,numComponents:o},t.daccessor={data:f,numComponents:o,normalize:a},t.daccessor}getTypedArrayFromArrayBuffer(e,t,a,r,i,n){let o;const l=i*r.BYTES_PER_ELEMENT;if(t&&l!==t){const c=i*n;o=new r(c);for(let f=0;f<n;f++){const d=new r(e,a+f*t,i);for(let h=0;h<i;h++)o[f*i+h]=d[h]}}else o=new r(e,a,n*i);return o}parseBufferView(e){const t=this.gltf.bufferViews[e];if(!t)return this.errorMiss("bufferView",e);if(t.isParsed)return t.dbufferView;t.isParsed=!0,t.dbufferView=!1;const a=this.parseBuffer(t.buffer);if(a){const{byteOffset:r,byteLength:i}=t,n=new Uint8Array(a,r||0,i);t.dbufferView=new Uint8Array(n).buffer}return t.dbufferView}parseBuffer(e){const t=this.gltf.buffers[e];if(!t)return this.errorMiss("buffer",e);if(t.isParsed)return t.dbuffer;if(t.isParsed=!0,t.dbuffer=!1,t.uri.substring(0,5)!=="data:"){const a=t.uri,r=this.gltf.resources[a];r?r.byteLength===t.byteLength?t.dbuffer=this.gltf.resources[a]:console.error(`load gltf resource "${a}" at buffers[${e} failed, ArrayBuffer.byteLength not equals buffer's byteLength]`):console.error(`load gltf resource "${a}" at buffers[${e}] failed`)}else{const a=t.uri.indexOf(this._BASE64_MARKER)+this._BASE64_MARKER.length,r=window.atob(t.uri.substring(a)),i=new Uint8Array(r.length);for(let n=0;n<r.length;n++)i[n]=r.charCodeAt(n);t.dbuffer=i.buffer}return t.dbuffer}getLight(e){return this.gltf.extensions.KHR_lights_punctual.lights[e]}applyNodeExtensions(e,t){let a=e.extensions;a.KHR_lights_punctual&&this.gltf.extensions.KHR_lights_punctual&&(t.light=this.getLight(a.KHR_lights_punctual.light))}}class hf{magic;version;length}class uf{chunkLength;chunkType;chunkData}class eo extends st{static format=ze.BIN;_gltf;async parseBuffer(e){let t=new Uint8Array(e);t.pos=0;const a=this.parseHeader(t);if(a.magic!=1179937895)return console.error("invalid GLB file"),!1;if(a.version!==2)return console.error(`GLBParser only support glTF 2.0 for now! Received glTF version: ${a.version}`),!1;let r=[];for(;t.pos<t.length;){let d=this.parseChunk(t);r.push(d)}if(r[0].chunkType!=1313821514)return console.error("invalid GLBChunk"),!1;let i="",n=65535,o=r[0].chunkData;for(let d=0;d<o.length;d+=n){let h=o.length-d;h=Math.min(h,n);let b=o.subarray(d,d+h);i+=String.fromCharCode(...b)}let l=JSON.parse(i);this._gltf=new Bs,this._gltf={...this._gltf,...l},this._gltf.resources={};for(let d=0;d<this._gltf.buffers.length;d++){let h=this._gltf.buffers[d];h.isParsed=!0,h.dbuffer=r[d+1].chunkData.buffer}if(this._gltf.images)for(let d=0;d<this._gltf.images.length;d++){let h=this._gltf.images[d];h.name=h.name||"bufferView_"+h.bufferView.toString();const b=this._gltf.bufferViews[h.bufferView],p=this._gltf.buffers[b.buffer];let g=new Uint8Array(p.dbuffer,b.byteOffset,b.byteLength),A=new Blob([g],{type:h.mimeType}),D=new Va;await D.loadFromBlob(A),D.name=h.name,this._gltf.resources[h.name]=D}let f=await new vs().parse(this.initUrl,this._gltf,this._gltf.scene);return f?(this.data=f.rootNode,f.rootNode):null}async parseJsonAndBuffer(e,t){this._gltf=new Bs,this._gltf={...this._gltf,...e},this._gltf.resources={};let a=this._gltf.buffers[0];if(a.isParsed=!0,a.dbuffer=t,this._gltf.images)for(let n=0;n<this._gltf.images.length;n++){let o=this._gltf.images[n];o.name=o.name||"bufferView_"+o.bufferView.toString();const l=this._gltf.bufferViews[o.bufferView],c=this._gltf.buffers[l.buffer];let f=new Uint8Array(c.dbuffer,l.byteOffset,l.byteLength),d=new Blob([f],{type:o.mimeType}),h=new Va;await h.loadFromBlob(d),h.name=o.name,this._gltf.resources[o.name]=h}let i=await new vs().parse(this.initUrl,this._gltf,this._gltf.scene);return i?(this.data=i.rootNode,i.rootNode):null}verification(){if(this.data)return!0;throw new Error("Method not implemented.")}parseHeader(e){let t=e.pos,a=new hf,r=new Uint32Array(e.buffer,t,3);return e.pos+=r.byteLength,a.magic=r[0],a.version=r[1],a.length=r[2],a}parseChunk(e){let t=e.pos,a=new uf,r=new Uint32Array(e.buffer,t,2);t=e.pos+=r.byteLength,a.chunkLength=r[0],a.chunkType=r[1],a.chunkData=new Uint8Array(e.buffer,t,a.chunkLength);const i=new Uint8Array(a.chunkLength);for(let n=0;n<a.chunkLength;n++)i[n]=a.chunkData[n];return a.chunkData=i,e.pos+=a.chunkLength,a}}class bf extends ot{constructor(){super();let e=new Ve("PBRLItShader","PBRLItShader");e.setShaderEntry("VertMain","FragMain"),e.passType=H.COLOR,this.addRenderPass(e);let t=e.shaderState;t.acceptShadow=!0,t.castShadow=!0,t.receiveEnv=!0,t.acceptGI=!0,t.useLight=!0,this.setDefine("USE_BRDF",!0),this.setDefine("USE_ROUGHNESS_G",!0),this.setDefine("USE_METALLIC_B",!0),this.setDefine("USE_ALPHA_A",!0),this.setDefault()}setDefault(){this.setUniformFloat("shadowBias",35e-5),this.setUniformColor("baseColor",new P(.75,.75,.75,1)),this.setUniformColor("emissiveColor",new P(0,0,0)),this.setUniformVector4("materialF0",new te(.04,.04,.04,1)),this.setUniformColor("specularColor",new P(.04,.04,.04)),this.setUniformFloat("envIntensity",1),this.setUniformFloat("normalScale",1),this.setUniformFloat("roughness",1),this.setUniformFloat("metallic",1),this.setUniformFloat("ao",1),this.setUniformFloat("roughness_min",0),this.setUniformFloat("roughness_max",1),this.setUniformFloat("metallic_min",0),this.setUniformFloat("metallic_max",1),this.setUniformFloat("emissiveIntensity",0),this.setUniformFloat("alphaCutoff",0),this.setUniformFloat("ior",1.5),this.setUniformFloat("clearcoatFactor",0),this.setUniformFloat("clearcoatRoughnessFactor",0),this.setUniformColor("clearcoatColor",new P(1,1,1)),this.setUniformFloat("clearcoatWeight",0),this.setUniformFloat("clearcoatIor",1.5),this.setUniformVector4("baseMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("normalMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("emissiveMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("roughnessMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("metallicMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("aoMapOffsetSize",new te(0,0,1,1)),this.baseMap=m.res.whiteTexture,this.normalMap=m.res.normalTexture,this.maskMap=m.res.maskTexture}get baseMap(){return this.getDefaultColorShader().getTexture("baseMap")}set baseMap(e){this.getDefaultColorShader().setTexture("baseMap",e)}get baseColor(){return this.getDefaultColorShader().getUniform("baseColor")}set baseColor(e){this.getDefaultColorShader().setUniformColor("baseColor",e)}get normalMap(){return this.getDefaultColorShader().getTexture("normalMap")}set normalMap(e){this.getDefaultColorShader().setTexture("normalMap",e)}get doubleSide(){return this.getDefaultColorShader().doubleSide}set doubleSide(e){this.getDefaultColorShader().doubleSide=e}get alphaCutoff(){return this.getDefaultColorShader().shaderState.alphaCutoff}set alphaCutoff(e){this.getDefaultColorShader().setDefine("USE_ALPHACUT",!0),this.getDefaultColorShader().shaderState.alphaCutoff=e,this.getDefaultColorShader().setUniform("alphaCutoff",e)}get emissiveColor(){return this.getDefaultColorShader().getUniform("emissiveColor")}set emissiveColor(e){this.getDefaultColorShader().setUniform("emissiveColor",e)}get emissiveIntensity(){return this.getDefaultColorShader().getUniform("emissiveIntensity")}set emissiveIntensity(e){this.getDefaultColorShader().setUniform("emissiveIntensity",e)}get transformUV1(){return this.getDefaultColorShader().uniforms.transformUV1.vector4}set transformUV1(e){this.getDefaultColorShader().setUniform("transformUV1",e)}get uvTransform_2(){return this.getDefaultColorShader().uniforms.transformUV2.vector4}set uvTransform_2(e){this.getDefaultColorShader().setUniform("transformUV2",e)}get depthWriteEnabled(){return this.getDefaultColorShader().shaderState.depthWriteEnabled}set depthWriteEnabled(e){this.getDefaultColorShader().shaderState.depthWriteEnabled=e}get materialF0(){return this.getDefaultColorShader().uniforms.materialF0.vector4}set materialF0(e){this.getDefaultColorShader().setUniform("materialF0",e)}get specularColor(){return this.getDefaultColorShader().uniforms.specularColor.color}set specularColor(e){this.getDefaultColorShader().setUniform("specularColor",e)}get roughness(){return this.getDefaultColorShader().uniforms.roughness.value}set roughness(e){this.getDefaultColorShader().setUniform("roughness",e)}get metallic(){return this.getDefaultColorShader().uniforms.metallic.value}set metallic(e){this.getDefaultColorShader().setUniform("metallic",e)}get ao(){return this.getDefaultColorShader().uniforms.ao.value}set ao(e){this.getDefaultColorShader().setUniform("ao",e)}get metallic_min(){return this.getDefaultColorShader().uniforms.metallic_min.value}set metallic_min(e){this.getDefaultColorShader().setUniform("metallic_min",e)}get metallic_max(){return this.getDefaultColorShader().uniforms.metallic_max.value}set metallic_max(e){this.getDefaultColorShader().setUniform("metallic_max",e)}get roughness_min(){return this.getDefaultColorShader().uniforms.roughness_min.value}set roughness_min(e){this.getDefaultColorShader().setUniform("roughness_min",e)}get roughness_max(){return this.getDefaultColorShader().uniforms.roughness_max.value}set roughness_max(e){this.getDefaultColorShader().setUniform("roughness_max",e)}get normalScale(){return this.getDefaultColorShader().uniforms.normalScale.value}set normalScale(e){this.getDefaultColorShader().setUniform("normalScale",e)}get maskMap(){return this.getDefaultColorShader().textures.maskMap}set maskMap(e){this.getDefaultColorShader().setDefine("USE_MR",!0),this.getDefaultColorShader().setTexture("maskMap",e)}set aoMap(e){e&&(this.getDefaultColorShader().setTexture("aoMap",e),e!=m.res.whiteTexture&&this.getDefaultColorShader().setDefine("USE_AOTEX",!0))}get aoMap(){return this.getDefaultColorShader().textures.aoMap}set clearCoatRoughnessMap(e){e&&(console.log("USE_CLEARCOAT_ROUGHNESS"),this.getDefaultColorShader().setTexture("clearCoatRoughnessMap",e),this.getDefaultColorShader().setDefine("USE_CLEARCOAT_ROUGHNESS",!0))}get clearCoatRoughnessMap(){return this.getDefaultColorShader().textures.clearCoatRoughnessMap}get brdfLUT(){return this.getDefaultColorShader().textures.brdfLUT}set brdfLUT(e){this.getDefaultColorShader().setTexture("brdfLUT",e),this.getDefaultColorShader().setTexture("brdflutMap",e)}get emissiveMap(){return this.getDefaultColorShader().textures.emissiveMap}set emissiveMap(e){this.getDefaultColorShader().setTexture("emissiveMap",e)}set envIntensity(e){this.getDefaultColorShader().setUniformFloat("envIntensity",e)}get envIntensity(){return this.getDefaultColorShader().uniforms.envIntensity.value}set ior(e){this.getDefaultColorShader().setUniformFloat("ior",e)}get ior(){return this.getDefaultColorShader().uniforms.ior.value}useCleanCoat(){this.getDefaultColorShader().setDefine("USE_CLEARCOAT",!0)}set clearcoatFactor(e){this.getDefaultColorShader().setUniformFloat("clearcoatFactor",e),this.useCleanCoat()}get clearcoatFactor(){return this.getDefaultColorShader().uniforms.clearcoatFactor.value}set clearcoatRoughnessFactor(e){this.getDefaultColorShader().setUniformFloat("clearcoatRoughnessFactor",e),this.useCleanCoat()}get clearcoatRoughnessFactor(){return this.getDefaultColorShader().uniforms.clearcoatRoughnessFactor.value}set clearcoatWeight(e){this.getDefaultColorShader().setUniformFloat("clearcoatWeight",e),this.useCleanCoat()}get clearcoatWeight(){return this.getDefaultColorShader().uniforms.clearcoatWeight.value}set clearcoatColor(e){this.getDefaultColorShader().setUniformColor("clearcoatColor",e),this.useCleanCoat()}get clearcoatColor(){return this.getDefaultColorShader().uniforms.clearcoatColor.color}}class ka extends mt{constructor(){super();let e=new bf;this.shader=e}clone(){let e=new ka,t=e.shader.getDefaultColorShader(),a=this.shader.getDefaultColorShader();return t.defineValue={...a.defineValue},t.setUniform("shadowBias",a.getUniform("shadowBias")),t.setUniform("baseColor",a.getUniform("baseColor")),t.setUniform("specularColor",a.getUniform("specularColor")),t.setUniform("emissiveColor",a.getUniform("emissiveColor")),t.setUniform("materialF0",a.getUniform("materialF0")),t.setUniform("envIntensity",a.getUniform("envIntensity")),t.setUniform("normalScale",a.getUniform("normalScale")),t.setUniform("roughness",a.getUniform("roughness")),t.setUniform("metallic",a.getUniform("metallic")),t.setUniform("ao",a.getUniform("ao")),t.setUniform("roughness_min",a.getUniform("roughness_min")),t.setUniform("roughness_max",a.getUniform("roughness_max")),t.setUniform("metallic_min",a.getUniform("metallic_min")),t.setUniform("metallic_max",a.getUniform("metallic_max")),t.setUniform("emissiveIntensity",a.getUniform("emissiveIntensity")),t.setUniform("alphaCutoff",a.getUniform("alphaCutoff")),t.setUniform("ior",a.getUniform("ior")),t.setUniform("clearcoatFactor",a.getUniform("clearcoatFactor")),t.setUniform("clearcoatRoughnessFactor",a.getUniform("clearcoatRoughnessFactor")),t.setUniform("clearcoatColor",a.getUniform("clearcoatColor")),t.setUniform("clearcoatWeight",a.getUniform("clearcoatWeight")),t.setUniform("clearcoatIor",a.getUniform("clearcoatIor")),t.setTexture("baseMap",a.getTexture("baseMap")),t.setTexture("normalMap",a.getTexture("normalMap")),t.setTexture("emissiveMap",a.getTexture("emissiveMap")),t.setTexture("aoMap",a.getTexture("aoMap")),t.setTexture("maskMap",a.getTexture("maskMap")),t.setTexture("empty",a.getTexture("empty")),t.setUniform("baseMapOffsetSize",a.getUniform("baseMapOffsetSize")),t.setUniform("normalMapOffsetSize",a.getUniform("normalMapOffsetSize")),t.setUniform("emissiveMapOffsetSize",a.getUniform("emissiveMapOffsetSize")),t.setUniform("roughnessMapOffsetSize",a.getUniform("roughnessMapOffsetSize")),t.setUniform("metallicMapOffsetSize",a.getUniform("metallicMapOffsetSize")),t.setUniform("aoMapOffsetSize",a.getUniform("aoMapOffsetSize")),e}set baseMap(e){this.shader.setTexture("baseMap",e)}get baseMap(){return this.shader.getTexture("baseMap")}set maskMap(e){this.shader.setTexture("maskMap",e)}get maskMap(){return this.shader.getTexture("maskMap")}set normalMap(e){this.shader.setTexture("normalMap",e)}get normalMap(){return this.shader.getTexture("normalMap")}set emissiveMap(e){this.shader.setTexture("emissiveMap",e)}get emissiveMap(){return this.shader.getTexture("emissiveMap")}set aoMap(e){this.shader.setTexture("aoMap",e)}get aoMap(){return this.shader.getTexture("aoMap")}set clearCoatRoughnessMap(e){this.shader.setTexture("clearCoatRoughnessMap",e),this.shader.setDefine("USE_CLEARCOAT",!0),this.shader.setDefine("USE_CLEARCOAT_ROUGHNESS",!0)}get clearCoatRoughnessMap(){return this.shader.getTexture("clearCoatRoughnessMap")}set clearcoatColor(e){this.shader.setUniformColor("clearcoatColor",e),this.shader.setDefine("USE_CLEARCOAT",!0)}get clearcoatColor(){return this.shader.getUniformColor("clearcoatColor")}set clearcoatWeight(e){this.shader.setUniformFloat("clearcoatWeight",e),this.shader.setDefine("USE_CLEARCOAT",!0)}get clearcoatWeight(){return this.shader.getUniformFloat("clearcoatWeight")}set clearcoatFactor(e){this.shader.setUniformFloat("clearcoatFactor",e),this.shader.setDefine("USE_CLEARCOAT",!0)}get clearcoatFactor(){return this.shader.getUniformFloat("clearcoatFactor")}set clearcoatRoughnessFactor(e){this.shader.setUniformFloat("clearcoatRoughnessFactor",e),this.shader.setDefine("USE_CLEARCOAT",!0)}get clearcoatRoughnessFactor(){return this.shader.getUniformFloat("clearcoatRoughnessFactor")}set ior(e){this.shader.setUniformFloat("clearcoatIor",e)}get ior(){return this.shader.getUniformFloat("clearcoatIor")}set alphaCutoff(e){this.shader.setUniform("alphaCutoff",e)}get alphaCutoff(){return this.shader.getUniform("alphaCutoff")}set baseColor(e){this.shader.setUniformColor("baseColor",e)}get baseColor(){return this.shader.getUniformColor("baseColor")}get roughness(){return this.shader.getUniformFloat("roughness")}set roughness(e){this.shader.setUniformFloat("roughness",e)}get metallic(){return this.shader.getUniformFloat("metallic")}set metallic(e){this.shader.setUniformFloat("metallic",e)}get emissiveColor(){return this.shader.getUniformColor("emissiveColor")}set emissiveColor(e){this.shader.setUniformColor("emissiveColor",e)}get emissiveIntensity(){return this.shader.getUniformFloat("emissiveIntensity")}set emissiveIntensity(e){this.shader.setUniformFloat("emissiveIntensity",e)}get ao(){return this.shader.getUniform("ao")}set ao(e){this.shader.setUniform("ao",e)}}class gf extends st{static format=ze.TEXT;textData="";source_vertices;source_normals;source_tangents;source_textureCoords;matLibs;geometrys;activeGeo;currentObjectName;currentMaterialName;facesMaterialsIndex;mtl;mtlUrl;async parseString(e){return this.source_vertices=[],this.source_normals=[],this.source_tangents=[],this.source_textureCoords=[],this.currentObjectName="default",this.currentMaterialName="",this.matLibs={},this.geometrys={},this.activeGeo=void 0,this.textData=e,await Promise.all([this.parserOBJ(),this.loadMTL()]),this.parser_mesh(),"null"}applyVector2(e,t,a){e>=0&&t[e]&&t[e].length>0?(a.push(t[e][0]),a.push(-t[e][1])):(a.push(0),a.push(0))}applyVector3(e,t,a){e>=0&&t[e]&&t[e].length>0?(a.push(t[e][0]),a.push(t[e][1]),a.push(t[e][2])):(a.push(0),a.push(0),a.push(0))}applyVector4(e,t,a){a.push(t[e][0]),a.push(t[e][1]),a.push(t[e][2]),a.push(t[e][3])}parseUVIndex(e,t){const a=parseInt(e,10);return a>=0?a-1:t+a}parseVertexIndex(e,t){const a=parseInt(e,10);return a>=0?a-1:t+a}parseNormalIndex(e,t){const a=parseInt(e,10);return a>=0?a-1:t+a}calculateFaceNormal(e,t,a){const r=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],i=[a[0]-e[0],a[1]-e[1],a[2]-e[2]],n=[r[1]*i[2]-r[2]*i[1],r[2]*i[0]-r[0]*i[2],r[0]*i[1]-r[1]*i[0]],o=Math.sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);return o>0&&(n[0]/=o,n[1]/=o,n[2]/=o),n}async loadMTL(){let t=await new pt().loadTxt(this.baseUrl+this.mtlUrl),a=t.data,r,i=a.split(/\r?\n/);for(let l=0;l<i.length;l++){let c=i[l];var n=c.indexOf("#");n!=-1&&(c=c.substring(0,n)),c=c.trim();var o=c.split(/\s+/);o[0]==="newmtl"?(r={name:o[1]},this.matLibs[o[1]]=r):o[0].indexOf("map_")!=-1?(r[o[0]]=o[1],r.textures||(r.textures=[o[o.length-1]]),r.textures.push(o[o.length-1])):o.length==2?r[o[0]]=Number(o[1]):o.length==3?r[o[0]]=[Number(o[1]),Number(o[2])]:o.length==4&&(r[o[0]]=[Number(o[1]),Number(o[2]),Number(o[3])])}for(const l in this.matLibs){const c=this.matLibs[l];if(c.textures&&c.textures.length>0)for(let f=0;f<c.textures.length;f++){const d=Ct.normalizePath(this.baseUrl+c.textures[f]);await m.res.loadTexture(d)}}return t=null,!0}async load_textures(){}getGeometryKey(e,t){const a=(e??this.currentObjectName??"default")||"default",r=t??this.currentMaterialName??"",i=r.length>0?r:"default";return`${a}::${i}`}ensureActiveGeo(e,t){const a=(e??this.currentObjectName??"default")||"default",r=t??this.currentMaterialName??"",i=this.getGeometryKey(a,r);this.geometrys[i]?this.geometrys[i].source_mat!==r&&(this.geometrys[i].source_mat=r):this.geometrys[i]={type:a,name:i,source_mat:r,source_faces:[]},this.activeGeo=this.geometrys[i]}parserLine(e){var t=e.indexOf("#");if(t!=-1){if(e.indexOf("# object")!=-1){const p=e.split(/\s+/),g=p[1]||"default",A=p[2]||"default";this.currentObjectName=A,this.activeGeo=void 0,this.ensureActiveGeo(A,this.currentMaterialName),this.activeGeo&&(this.activeGeo.type=g)}e=e.substring(0,t)}e=e.trim();var a=e.split(/\s+/);if(a[0]==="v"){var r=[Number(a[1]),Number(a[2]),Number(a[3]),a[4]?1:Number(a[4])];this.source_vertices.push(r)}else if(a[0]==="vt"){var i=[Number(a[1]),Number(a[2]),a[3]?1:Number(a[3])];this.source_textureCoords.push(i)}else if(a[0]==="vn"){var n=[Number(a[1]),Number(a[2]),Number(a[3])];this.source_normals.push(n)}else if(a[0]==="f"){for(var o={indices:[],texture:[],normal:[]},l=1;l<a.length;++l){var c=a[l];if(c.length!==0){var f=c.split("/"),d=f[0]||"",h=f.length>=2&&f[1]||"",b=f.length>=3&&f[2]||"";d.length!==0&&(o.indices.push(d),o.texture.push(h),o.normal.push(b))}}this.ensureActiveGeo(),this.activeGeo.source_faces.push(o)}else a[0]==="usemtl"?(this.currentMaterialName=a[1]||"",this.ensureActiveGeo(this.currentObjectName,this.currentMaterialName)):a[0]==="mtllib"&&(this.mtlUrl=a[1])}async parserOBJ(){let e=this.textData.split(/\r?\n/);for(let t=0;t<e.length;t++){const a=e[t];this.parserLine(a)}return this.textData="",!0}async parser_mesh(){let e=new ee;for(const t in this.geometrys){const a=this.geometrys[t];a.vertex_arr=[],a.normal_arr=[],a.uv_arr=[],a.indeice_arr=[];let r=0;const i=this.source_vertices.length,n=this.source_normals.length,o=this.source_textureCoords.length;for(let p=0;p<a.source_faces.length;p++){const g=a.source_faces[p];let A=this.parseVertexIndex(g.indices[0],i),D=this.parseVertexIndex(g.indices[1],i),_=this.parseVertexIndex(g.indices[2],i);const U=L=>{if(!L||L.length===0)return-1;const X=this.parseNormalIndex(L,n);return Number.isFinite(X)&&X>=0&&X<n?X:-1},v=L=>{if(!L||L.length===0)return-1;const X=this.parseUVIndex(L,o);return Number.isFinite(X)&&X>=0&&X<o?X:-1};let x=U(g.normal[0]),C=U(g.normal[1]),F=U(g.normal[2]);const w=x<0||C<0||F<0;let S=null;w&&A>=0&&D>=0&&_>=0&&this.source_vertices[A]&&this.source_vertices[D]&&this.source_vertices[_]&&(S=this.calculateFaceNormal(this.source_vertices[A],this.source_vertices[D],this.source_vertices[_]));let M=v(g.texture[0]),T=v(g.texture[1]),Q=v(g.texture[2]);if(this.applyVector3(A,this.source_vertices,a.vertex_arr),x>=0?this.applyVector3(x,this.source_normals,a.normal_arr):S?a.normal_arr.push(S[0],S[1],S[2]):a.normal_arr.push(0,0,0),M>=0?this.applyVector2(M,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,this.applyVector3(D,this.source_vertices,a.vertex_arr),C>=0?this.applyVector3(C,this.source_normals,a.normal_arr):S?a.normal_arr.push(S[0],S[1],S[2]):a.normal_arr.push(0,0,0),T>=0?this.applyVector2(T,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,this.applyVector3(_,this.source_vertices,a.vertex_arr),F>=0?this.applyVector3(F,this.source_normals,a.normal_arr):S?a.normal_arr.push(S[0],S[1],S[2]):a.normal_arr.push(0,0,0),Q>=0?this.applyVector2(Q,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,g.indices.length>3){let L=this.parseVertexIndex(g.indices[3],i),X=U(g.normal[3]),ie=v(g.texture[3]),q=null;(x<0||F<0||X<0)&&A>=0&&_>=0&&L>=0&&this.source_vertices[A]&&this.source_vertices[_]&&this.source_vertices[L]&&(q=this.calculateFaceNormal(this.source_vertices[A],this.source_vertices[_],this.source_vertices[L])),this.applyVector3(A,this.source_vertices,a.vertex_arr),x>=0?this.applyVector3(x,this.source_normals,a.normal_arr):q?a.normal_arr.push(q[0],q[1],q[2]):a.normal_arr.push(0,0,0),M>=0?this.applyVector2(M,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,this.applyVector3(_,this.source_vertices,a.vertex_arr),F>=0?this.applyVector3(F,this.source_normals,a.normal_arr):q?a.normal_arr.push(q[0],q[1],q[2]):a.normal_arr.push(0,0,0),Q>=0?this.applyVector2(Q,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,this.applyVector3(L,this.source_vertices,a.vertex_arr),X>=0?this.applyVector3(X,this.source_normals,a.normal_arr):q?a.normal_arr.push(q[0],q[1],q[2]):a.normal_arr.push(0,0,0),ie>=0?this.applyVector2(ie,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++}}let l=new Ee;l.setIndices(new Uint32Array(a.indeice_arr)),l.setAttribute(V.position,new Float32Array(a.vertex_arr)),l.setAttribute(V.normal,new Float32Array(a.normal_arr)),l.setAttribute(V.uv,new Float32Array(a.uv_arr)),l.setAttribute(V.TEXCOORD_1,new Float32Array(a.uv_arr)),l.addSubGeometry({indexStart:0,indexCount:a.indeice_arr.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0});let c=new ka;const f=a.source_mat,d=f?this.matLibs[f]:void 0;if(d&&d.map_Kd){const p=Ct.normalizePath(this.baseUrl+d.map_Kd),g=m.res.getTexture(p);g&&(c.baseMap=g)}let h=new ee,b=h.addComponent($);b.geometry=l,b.material=c,e.addChild(h)}this.data=e}verification(){if(this.data)return!0;throw new Error("Method not implemented.")}}let pf=`
7275
+ `;class Hn{static _workerCode;static _workers=new Map;static async apply(e,t){if(!t.extensions)return;const a=t.extensions.KHR_draco_mesh_compression;if(!a)return;let r=this._workers.get(e.gltf);r||(r=new Worker(await this.initDecoder()),this._workers.set(e.gltf,r)),r.postMessage({type:"init",decoderConfig:{}});let i=e.parseBufferView(a.bufferView);if(!i.result){let n=await new Promise((o,l)=>{r.onmessage=c=>{const f=c.data;f.type=="decode"?o(f.result):f.type=="error"&&l(f.error)},r.postMessage({type:"decoder",buffer:i,attributes:a.attributes},[i])});i.result=n}return i.result}static unload(e){let t=this._workers.get(e);t&&(t.terminate(),this._workers.delete(e))}static async initDecoder(){if(!this._workerCode){const e=new Blob([ef,"",`(${Y2})()`],{type:"application/javascript"});this._workerCode=URL.createObjectURL(e)}return this._workerCode}}function Y2(){let s,e;onmessage=t=>{const a=t.data;switch(a.type){case"init":s=a.decoderConfig,e=new Promise((n,o)=>{s.onModuleLoaded=l=>{n({draco:l})},DracoDecoderModule(s)});break;case"decoder":const r=a.buffer,i=a.attributes;e.then(n=>{const o=n.draco;let l=new o.Decoder,c=new o.DecoderBuffer;c.Init(new Int8Array(r),r.byteLength);let f,d;try{const h=l.GetEncodedGeometryType(c);h==o.TRIANGULAR_MESH?(d=new o.Mesh,f=l.DecodeBufferToMesh(c,d)):self.postMessage(new Error("INVALID_GEOMETRY_TYPE:"+h)),f.ok()||self.postMessage(new Error("DracoDecode:"+f.error_msg()));let b={};for(const p in i){let g=l.GetAttributeByUniqueId(d,i[p]);const A=g.num_components(),_=d.num_points()*A,U=_*Float32Array.BYTES_PER_ELEMENT,v=o.DT_FLOAT32,x=o._malloc(U);l.GetAttributeDataArrayForAllPoints(d,g,v,U,x);const C=new Float32Array(o.HEAPF32.buffer,x,_).slice();o._free(x),b[p]={data:C,numComponents:A,normalize:!1}}{const g=d.num_faces()*3,A=g*4,D=o._malloc(A);l.GetTrianglesUInt32Array(d,A,D);const _=new Uint32Array(o.HEAPF32.buffer,D,g).slice();o._free(D),b.indices={data:_,numComponents:1,normalize:!1}}self.postMessage({type:"decode",result:b})}catch(h){self.postMessage({type:"error",error:h.message})}finally{o.destroy(d),o.destroy(l),o.destroy(c)}});break}}}class tf{gltf;constructor(e){this.gltf=e}parse(e){const t=this.gltf.cameras[e];if(!t)return this.errorMiss("camera",e);if(t.isParsed)return t.dcamera;t.isParsed=!0,t.dcamera=!1;const{name:a,type:r,perspective:i,orthographic:n}=t;if(r==="perspective"&&i){const{aspectRatio:o,yfov:l,zfar:c,znear:f}=i;t.dcamera=Object.assign({},{name:a,type:r,yfov:l,znear:f,aspectRatio:o,zfar:c})}else if(r==="orthographic"&&n){const{xmag:o,ymag:l,zfar:c,znear:f}=n;t.dcamera=Object.assign({},{name:a,type:r,xmag:o,ymag:l,zfar:c,znear:f})}return t.dcamera}errorMiss(e,t){throw new Error(e+t)}}class Dt extends st{static format=ze.JSON;_gltf;async parseJson(e){this._gltf=new Bs,this._gltf={...this._gltf,...e},this._gltf.resources={},await Promise.all([this.load_gltf_bin(),this.load_gltf_textures()]);let t=new vs,a=await t.parse(this.initUrl,this._gltf,this._gltf.scene);return t.destroy(),t=null,a?(this.data=a.rootNode,a.rootNode):(this._gltf=null,null)}verification(){if(this.data)return!0;throw new Error("Method not implemented.")}static _counter=0;static getMeshNameCounter(){return function(){return`GLTF_NO_NAME_PRIMITIVE_${Dt._counter++}`}}static getModelNameCounter(){let e=0;return function(){return`GLTF_NO_NAME_MESH_${e++}`}}static getTexCoordDefine(e){return`UV_NUM ${e}`}static getVertexColorDefine(e){return`HAS_VERTEXCOLOR ${e}`}static getBaseColorTextureDefine(){return"HAS_BASECOLORMAP"}static getMetalRoughnessDefine(){return"HAS_METALROUGHNESSMAP"}static getNormalMapDefine(){return"HAS_NORMALMAP"}static getEmissiveMapDefine(){return"HAS_EMISSIVEMAP"}static getOcclusionMapDefine(){return"HAS_OCCLUSIONMAP"}static getMorphTargetsDefine(e){return`MORPH_TARGET_NUM ${e}`}static getMorphtargetPositionDefine(){return"HAS_MORPH_POSITION"}static getMorphtargetNormalDefine(){return"HAS_MORPH_NORMAL"}static getMorphtargetTangentDefine(){return"HAS_MORPH_TANGENT"}static getJointsNumDefine(e){return`JOINTS_NUM ${e}`}static getJointVec8Define(){return"JOINT_VEC8"}static getHasNormalDefine(){return"HAS_NORMAL"}static getHasTangentDefine(){return"HAS_TANGENT"}static getHasNormalMapDefine(){return"HAS_NORMAL_MAP"}static getAlphaMaskDefine(){return"ALPHA_MASK"}static getAlphaBlendDefine(){return"ALPHA_BLEND"}static defaultMaterial={name:"GLTF_DEFAULT_MATERIAL",alphaCutoff:.33,alphaMode:"MASK",pbrMetallicRoughness:{name:"GLTF_DEFAULT_MATERIAL",defines:[],doubleSided:!1,baseColorFactor:[1,1,1,1],metallicFactor:1,roughnessFactor:1,emissiveFactor:[0,0,0]}};async load_gltf_bin(){if(this._gltf.buffers&&this._gltf.buffers.length>0){let e=[];for(let t=0;t<this._gltf.buffers.length;t++){const a=this._gltf.buffers[t];if(a.uri.substring(0,5)!=="data:"){let r=Ct.parseUrl(this.baseUrl,a.uri);this.loaderFunctions?.onUrl&&(r=await this.loaderFunctions.onUrl(r));let i=new pt().loadBinData(r,this.loaderFunctions).then(n=>{this._gltf.resources[a.uri]=n});e.push(i)}}await Promise.all(e)}}async load_gltf_textures(){if(this._gltf,this._gltf.images){let e=[];for(let t=0;t<this._gltf.images.length;t++){const a=this._gltf.images[t];if(a.uri){let r=Ct.parseUrl(this.baseUrl,a.uri);this.loaderFunctions?.onUrl&&(r=await this.loaderFunctions.onUrl(r));let i=new pt().loadAsyncBitmapTexture(r,this.loaderFunctions).then(n=>{n.name=Ct.getURLName(a.uri),this._gltf.resources[n.name]=n});e.push(i)}}await Promise.all(e)}}}class af{gltf;subParser;constructor(e){this.gltf=e.gltf,this.subParser=e}async parse(e){const t=this.gltf.meshes[e];if(!t)return this.errorMiss("mesh",e);if(t.isParsed)return t.dprimitives;const a=t.primitives,r=t.extras,i=[];for(let n=0;n<a.length;n++){const o=a[n],{attributes:l,indices:c,material:f,mode:d,name:h,targets:b,morphTargetsRelative:p,extensions:g}=o;let A=t.name;for(let F in l)A+=F;A+=`indices:${c}`,A+=`material:${f}`;const D={attribArrays:{indices:[]},weights:[],defines:[],material:null,drawMode:null,meshName:null,modelName:null,morphTargetsRelative:!1,targetNames:r?r.targetNames:null};let _=!1,U=0,v=!1,x;g&&g.KHR_draco_mesh_compression&&(x=await Hn.apply(this.subParser,o));for(const F in l){const w=x?x[F]:this.parseAccessor(l[F]);if(w){let S;switch(F){case"POSITION":S=V.position;break;case"NORMAL":S=V.normal,_=!0;break;case"TEXCOORD_0":S=V.uv,U++;break;case"JOINTS_0":S=V.joints0;break;case"JOINTS_1":S=V.joints1,v=!0;break;case"WEIGHTS_0":S=V.weights0;break;case"WEIGHTS_1":S=V.weights1;break;default:S=F}D.attribArrays[S]=w}}if(_&&D.defines.push(Dt.getHasNormalDefine()),U&&D.defines.push(Dt.getTexCoordDefine(U)),v&&D.defines.push(Dt.getJointVec8Define()),c!==void 0){const F=x?x.indices:this.parseAccessor(c);F&&(D.attribArrays.indices=F)}const C=await this.parseMaterial(f);if(C&&(D.material=C,D.defines=D.defines.concat(C.defines)),D.drawMode=d===void 0?4:d,D.meshName=()=>A,D.modelName=t.name||Dt.getModelNameCounter(),b){D.defines.push(Dt.getMorphTargetsDefine(b.length)),D.morphTargetsRelative=!0;let F=!1,w=!1,S=!1;for(let M=0;M<b.length;M++){const T=b[M];Object.keys(T).forEach(Q=>{const L=this.parseAccessor(T[Q]);if(L){let X;switch(Q){case"POSITION":X=Yt.MORPH_POSITION_PREFIX+M,F=!0;break;case"NORMAL":X=Yt.MORPH_NORMAL_PREFIX+M,w=!0;break;case"TANGENT":X=Yt.MORPH_TANGENT_PREFIX+M,S=!0;break;default:X=!1}X?D.attribArrays[X]=L:console.error(`glTF has unsupported morph target attribute ${Q}`)}})}F&&D.defines.push(Dt.getMorphtargetPositionDefine()),w&&D.defines.push(Dt.getMorphtargetNormalDefine()),S&&D.defines.push(Dt.getMorphtargetTangentDefine()),D.weights=t.weights||new Array(b.length).fill(0)}i.push(D)}return t.dprimitives=i,t.isParsed=!0,t.dprimitives}parseAccessor(e){return this.subParser.parseAccessor(e)}parseMaterial(e){return this.subParser.parseMaterial(e)}errorMiss(e,t){throw new Error(e+t)}}class rf{gltf;subParser;constructor(e){this.gltf=e.gltf,this.subParser=e}async parse(e){let t;if(e==null?t=Dt.defaultMaterial:t=this.gltf.materials[e],!t)return this.errorMiss("material",e);if(t.isParsed)return t.dmaterial;let{name:a,pbrMetallicRoughness:r,normalTexture:i,occlusionTexture:n,emissiveTexture:o,emissiveFactor:l,alphaMode:c,alphaCutoff:f,doubleSided:d,extensions:h}=t;const b={name:a,defines:[],doubleSided:!!d,baseColorFactor:[1,1,1,1],emissiveFactor:null,alphaCutoff:0,enableBlend:!1,baseColorTexture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,emissiveTexture:null,extensions:null,baseMapOffsetSize:null,normalMapOffsetSize:null,emissiveMapOffsetSize:null,roughnessMapOffsetSize:null,metallicMapOffsetSize:null,aoMapOffsetSize:null,metallicFactor:0,roughnessFactor:1};if(r){const{baseColorFactor:p,metallicFactor:g,roughnessFactor:A,baseColorTexture:D,metallicRoughnessTexture:_}=r;if(Object.assign(b,{baseColorFactor:p||[1,1,1,1],metallicFactor:g===void 0?1:g,roughnessFactor:A===void 0?.5:A}),D){let U=D.extensions;if(U){let x=U.KHR_texture_transform;if(x){let C=new te(x.offset?x.offset[0]:0,x.offset?x.offset[1]:0,x.scale?x.scale[0]:1,x.scale?x.scale[1]:1);b.baseMapOffsetSize=C}}const v=await this.parseTexture(D.index);v?b.baseColorTexture=v:b.baseColorTexture=m.res.redTexture}if(i){let U=i.extensions;if(U){let x=U.KHR_texture_transform;if(x){let C=new te(x.offset?x.offset[0]:0,x.offset?x.offset[1]:0,x.scale?x.scale[0]:1,x.scale?x.scale[1]:1);b.normalMapOffsetSize=C}}const v=await this.parseTexture(i.index);v?b.normalTexture=v:b.normalTexture=m.res.normalTexture}if(_){let U=_.extensions;if(U){let x=U.KHR_texture_transform;if(x){let C=new te(x.offset?x.offset[0]:0,x.offset?x.offset[1]:0,x.scale?x.scale[0]:1,x.scale?x.scale[1]:1);b.roughnessMapOffsetSize=C}}const v=await this.parseTexture(_.index);v?b.metallicRoughnessTexture=v:b.metallicRoughnessTexture=m.res.blackTexture}}else Object.assign(b,{baseColorFactor:[1,1,1,1],metallicFactor:0,roughnessFactor:.5});if(b.baseColorFactor&&b.baseColorFactor[3]<1&&(c=c==="MASK"?"MASK":"BLEND"),c&&c!=="OPAQUE"&&(c==="MASK"&&(b.defines.push(Dt.getAlphaMaskDefine()),b.alphaCutoff=f===void 0?.5:f),c==="BLEND"&&(b.defines.push(Dt.getAlphaBlendDefine()),b.enableBlend=!0)),i){const p=await this.parseTexture(i.index);p?b.normalTexture=p:b.normalTexture=m.res.normalTexture}if(n){const p=await this.parseTexture(n.index);p&&(b.occlusionTexture=p)}if(l&&(b.emissiveFactor=l),o){const p=await this.parseTexture(o.index);p?b.emissiveTexture=p:b.emissiveTexture=m.res.blackTexture}return h&&(b.extensions=h),t.isParsed=!0,t.dmaterial=b,b}async parseTexture(e){return this.subParser.parseTexture(e)}errorMiss(e,t){throw new Error(e+t)}}class sf{gltf;subParser;constructor(e){this.gltf=e.gltf,this.subParser=e}parse(e){const t=this.gltf.skins[e];if(!t)return this.errorMiss("skin",e);if(t.isParsed)return t.dskin;const{name:a,joints:r,inverseBindMatrices:i,skeleton:n}=t;if(!r)return this.errorMiss("skin.joints",e);t.isParsed=!0,t.dskin=!1;let o={name:a,skeleton:null,inverseBindMatrices:null,joints:r,defines:[Dt.getJointsNumDefine(r.length)]};if(n)o.skeleton=n;else{var l=-1;for(let c=0;c<this.gltf.nodes.length;c++)if(this.gltf.nodes[c].name=="root"){l=c;break}if(l==-1){let c=this.gltf.scenes[this.gltf.scene];l=c.nodes[c.nodes.length-1]}o.skeleton=l}if(o.inverseBindMatrices=Yt.IDENTITY_INVERSE_BIND_MATRICES,i!==void 0){const c=this.parseAccessor(i);if(c){const f=c.data,d=[];for(let h=0;h<f.length;h+=16)d.push(f.slice(h,h+16));o.inverseBindMatrices=d}else o=null}return t.dskin=o,t.dskin}parseAccessor(e){return this.subParser.parseAccessor(e)}errorMiss(e,t){throw new Error(e+t)}}class nf{name="";index=0;instanceID="";parent=null;scale=new u;rotation=new j;translation=new u;constructor(e=""){this.name=e}}class Kn{index;worldMatrix;constructor(e,t=!1){this.index=e,this.worldMatrix=new E(!t)}}class Ui{time;_skeleton;_jointsPose;mJointMatrixIndexTable;constructor(e,t=!1){this._skeleton=e,this._jointsPose=new Array(e.numJoint),this.mJointMatrixIndexTable=new Array(e.numJoint);for(let a=0;a<e.numJoint;a++){let r=new Kn(a,t);this._jointsPose[a]=r,this.mJointMatrixIndexTable[a]=r.worldMatrix.index}}buildSkeletonPose(e){let t=new u,a=new j,r=new u,i=new Array(this._skeleton.numJoint);this.time=e[11]>0?e[11]:e[24];for(let n=0;n<this._skeleton.numJoint;n++){let o=12*n*4,l=new Float32Array(e.buffer,e.byteOffset+o,12),c=new E;t.set(l[0],l[1],l[2]),a.set(l[4],l[5],l[6],l[7]),r.set(l[8],l[9],l[10]),ps(a.getEulerAngles(),r,t,c),i[n]=c;let f=new Kn(n);const d=this._skeleton.getJointParentIndex(n);if(d<0)f.worldMatrix.copyFrom(c);else{let h=this._jointsPose[d];yc(h.worldMatrix,c,f.worldMatrix)}this._jointsPose[n]=f}}get numJoint(){return this._skeleton.numJoint}get joints(){return this._jointsPose}get jointMatrixIndexTable(){return this.mJointMatrixIndexTable}lerp(e,t,a){if(e&&t)for(let r=0;r<this._jointsPose.length;r++){let i=e._jointsPose[r],n=t._jointsPose[r];this._jointsPose[r].worldMatrix.lerp(i.worldMatrix,n.worldMatrix,a)}else for(let r=0;r<this._jointsPose.length;r++){let i=e._jointsPose[r];this._jointsPose[r].worldMatrix.copyFrom(i.worldMatrix)}}copyFrom(e){for(let t=0;t<this._jointsPose.length;t++)this._jointsPose[t].worldMatrix.copyFrom(e._jointsPose[t].worldMatrix)}reset(){for(let e=0;e<this._jointsPose.length;e++)this._jointsPose[e].worldMatrix.identity()}}class of extends $e{skeletonAnimation;constructor(e,t){super(),this.type=e,this.time=t}}class js{name="";_skeleton;_skeletonPoses;_animationClipData;_events;constructor(e,t,a,r){if(this.name=e,this._skeleton=t,this._animationClipData=r,a>0&&r){this._skeletonPoses=new Array(a);let i=12*t.numJoint;for(let n=0;n<a;n++){let o=i*n*4;const l=r.buffer instanceof ArrayBuffer?r.buffer:new Uint8Array(r.buffer).buffer;let c=new Float32Array(l,o,i),f=new Ui(t);f.buildSkeletonPose(c),this._skeletonPoses[n]=f}}}get totalTime(){return this._skeletonPoses[this._skeletonPoses.length-1].time}get frameRate(){return this.totalTime/this._skeletonPoses.length}get skeleton(){return this._skeleton}get numFrame(){return this._skeletonPoses.length-1}get animationClipData(){return this._animationClipData}getSkeletonPose(e){return this._skeletonPoses[e]}getLerpSkeletonPose(e,t,a,r){let i=this.getSkeletonPose(e),n=this.getSkeletonPose(t);return r.lerp(i,n,a),r}createSubClip(e,t,a){var r=new js(e,this._skeleton,0,null);const i=Math.max(Math.floor(t/this.frameRate),0),n=Math.min(Math.floor(a/this.frameRate),this._skeletonPoses.length-1);r._skeletonPoses=this._skeletonPoses.slice(i,n);const o=12*this._skeleton.numJoint*4,l=this._animationClipData.buffer instanceof ArrayBuffer?this._animationClipData.buffer:new Uint8Array(this._animationClipData.buffer).buffer;return this._animationClipData=new Float32Array(l,i*o,(n-i)*o),r}addEvent(e,t){this._events||(this._events=new Array),this._events.push(new of(e,t))}removeEvent(e){this._events&&(this._events=this._events.filter(t=>t.type!=e))}getEvents(){return this._events}}class qn{gltf;subParser;constructor(e){this.gltf=e.gltf,this.subParser=e}parse(e){let t=new Eo;return t.name="Id:"+e,t.count=0,t.boneData=[],t.boneMap=new Map,this.buildSkeleton(t,void 0,e),t}parseSkeletonAnimation(e,t){let a=new Jo;a.clipName=t.name,a.useSkeletonPos=!1,a.useSkeletonScale=!1;for(let r of t.channels){let i=t.samplers[r.sampler];const n=this.subParser.parseAccessor(i.input),o=this.subParser.parseAccessor(i.output);let l=r.target.node,c=r.target.path,f=this.gltf.nodes[l];if(!f||!e.boneMap.has(f.name))continue;let d=e.boneMap.get(f.name);switch(c){case"scale":{let h=new hr(o.numComponents);h.path="",h.attribute="",h.propertys=h.attribute.split("."),h.preInfinity=0,h.postInfinity=0,h.rotationOrder=0,a.useSkeletonScale=!0,a.scaleCurves.set(d.bonePath,h);for(let b=0;b<n.data.length;b++){const p=n.data[b],g=b*o.numComponents;let A=new Ji(0);A.time=p;const D=new u().set(o.data[g+0],o.data[g+1],o.data[g+2]);A.split(G.vector3,D,"value"),h.addKeyFrame(A)}}break;case"rotation":{let h=new hr(o.numComponents);h.path="",h.attribute="",h.propertys=h.attribute.split("."),h.preInfinity=0,h.postInfinity=0,h.rotationOrder=0,a.rotationCurves.set(d.bonePath,h);for(let b=0;b<n.data.length;b++){const p=n.data[b],g=b*o.numComponents;let A=new Ji(0);A.time=p;const D=new j().set(o.data[g+0],o.data[g+1],o.data[g+2],o.data[g+3]);A.split(G.quaternion,D,"value"),h.addKeyFrame(A)}}break;case"translation":{let h=new hr(o.numComponents);h.path="",h.attribute="",h.propertys=h.attribute.split("."),h.preInfinity=0,h.postInfinity=0,h.rotationOrder=0,a.useSkeletonPos=!0,a.positionCurves.set(d.bonePath,h);for(let b=0;b<n.data.length;b++){const p=n.data[b],g=b*o.numComponents;let A=new Ji(0);A.time=p;const D=new u().set(o.data[g+0],o.data[g+1],o.data[g+2]);A.split(G.vector3,D,"value"),h.addKeyFrame(A)}}break}}return a}parseSkeletonAnimationOld(e,t){let a=this.subParser.parseAccessor(t.samplers[0].input),r=a.data.length,i=a.data[1]-a.data[0];a.data[a.data.length-1];let n=12*e.numJoint,o=new Float32Array(n*r);for(var l=0;l<e.numJoint;l++)for(var c=0;c<r;c++){var f=n*c+12*l;o[f+0]=1,o[f+1]=1,o[f+2]=1,o[f+3]=1}for(let g of t.channels){let A=t.samplers[g.sampler];const D=this.subParser.parseAccessor(A.input),_=this.subParser.parseAccessor(A.output);let U=g.target.node,v=g.target.path,x=this.gltf.nodes[U];if(!x)continue;let C=e.getJointByName(x.name);if(C)switch(v){case"scale":if(r*_.numComponents==_.data.length)for(var c=0;c<r;c++){var d=c*_.numComponents,f=n*c+12*C.index;o[f+0]=_.data[d+0],o[f+1]=_.data[d+1],o[f+2]=_.data[d+2],o[f+3]=1}else if(D.data.length==2){let F=0;D.data[0];let w=D.data[1];var h=0*_.numComponents;u.HELP_0.set(_.data[h+0],_.data[h+1],_.data[h+2]);var b=1*_.numComponents;u.HELP_1.set(_.data[b+0],_.data[b+1],_.data[b+2]);for(var c=0;c<r;c++){let M=F/w;u.HELP_2.lerp(u.HELP_0,u.HELP_1,M);var f=n*c+12*C.index;o[f+0]=u.HELP_2.x,o[f+1]=u.HELP_2.y,o[f+2]=u.HELP_2.z,o[f+3]=1,F+=i}}else throw new Error("Unsupported animation sampler interpolation.");break;case"rotation":if(r*_.numComponents==_.data.length)for(var c=0;c<r;c++){var d=c*_.numComponents,f=n*c+12*C.index+4;o[f+0]=_.data[d+0],o[f+1]=_.data[d+1],o[f+2]=_.data[d+2],o[f+3]=_.data[d+3]}else if(D.data.length==2){let F=0;D.data[0];let w=D.data[1];var h=0*_.numComponents;u.HELP_0.set(_.data[h+0],_.data[h+1],_.data[h+2],_.data[h+3]);var b=1*_.numComponents;u.HELP_1.set(_.data[b+0],_.data[b+1],_.data[b+2],_.data[b+3]);for(var c=0;c<r;c++){let Q=F/w;u.HELP_2.lerp(u.HELP_0,u.HELP_1,Q);var f=n*c+12*C.index+4;o[f+0]=u.HELP_2.x,o[f+1]=u.HELP_2.y,o[f+2]=u.HELP_2.z,o[f+3]=u.HELP_2.w,F+=i}}else throw new Error("Unsupported animation sampler interpolation.");break;case"translation":if(r*_.numComponents==_.data.length)for(var c=0;c<r;c++){var d=c*_.numComponents,f=n*c+12*C.index+8;o[f+0]=_.data[d+0],o[f+1]=_.data[d+1],o[f+2]=_.data[d+2],o[f+3]=D.data[c*D.numComponents]}else if(D.data.length==2){let F=0;D.data[0];let w=D.data[1];var h=0*_.numComponents;u.HELP_0.set(_.data[h+0],_.data[h+1],_.data[h+2]);var b=1*_.numComponents;u.HELP_1.set(_.data[b+0],_.data[b+1],_.data[b+2]);for(var c=0;c<r;c++){let Q=F/w;u.HELP_2.lerp(u.HELP_0,u.HELP_1,Q);var f=n*c+12*C.index+8;o[f+0]=u.HELP_2.x,o[f+1]=u.HELP_2.y,o[f+2]=u.HELP_2.z,o[f+3]=F,F+=i}}else throw new Error("Unsupported animation sampler interpolation.");break}}return new js(t.name,e,r,o)}buildSkeleton(e,t,a){let r=this.gltf.nodes[a];r.name||(r.name="Bone"+e.count);let i=new ko;if(i.boneName=r.name,i.bonePath=t?t.bonePath+"/"+r.name:r.name,i.parentBoneName=t?t.boneName:"",i.boneID=e.count++,i.parentBoneID=t?t.boneID:-1,i.instanceID="",i.parentInstanceID="",i.s=new u(1,1,1),r.scale&&i.s.set(r.scale[0],r.scale[1],r.scale[2]),i.q=new j,r.rotation&&i.q.set(r.rotation[0],r.rotation[1],r.rotation[2],r.rotation[3]),i.t=new u,r.translation&&i.t.set(r.translation[0],r.translation[1],r.translation[2]),e.boneData.push(i),e.boneMap.set(i.boneName,i),r.children)for(let n of r.children)this.buildSkeleton(e,i,n)}buildSkeletonOld(e,t,a,r=0){let i=this.gltf.nodes[a];i.name||(i.name="Node_"+a);let n=new nf(i.name);if(n.parent=t,i.scale&&n.scale.set(i.scale[0],i.scale[1],i.scale[2]),i.rotation&&n.rotation.set(i.rotation[0],i.rotation[1],i.rotation[2],i.rotation[3]),i.translation&&n.translation.set(i.translation[0],i.translation[1],i.translation[2]),e.addJoint(n),i.children)for(let o of i.children)this.buildSkeletonOld(e,n,o,r+1)}}class $n{static list=[];static add(e){this.list.indexOf(e)==-1&&this.list.push(e)}static remove(e){let t=this.list.indexOf(e);t!=-1&&this.list.splice(t,1)}}class xi extends Pe{name;size=1;lightData;dirFix=1;bindOnChange;needUpdateShadow=!0;realTimeShadow=!0;_castGI=!1;_castShadow=!1;_iesProfiles;constructor(){super()}init(){this.transform.object3D.bound=new ge(new u,new u),this.lightData=new ms,this.lightData.lightMatrixIndex=this.transform.worldMatrix.index}onChange(){this.bindOnChange&&this.bindOnChange(),this.transform.object3D.bound.setFromCenterAndSize(this.transform.worldPosition,new u(this.size,this.size,this.size)),this._castGI&&(J.instance.state.giLightingChange=!0),this._castShadow?(this.needUpdateShadow=!0,It.addShadowLight(this)):It.removeShadowLight(this),this.transform.view3D&&m.renderJobs&&m.renderJobs.get(this.transform.view3D).reflectionRenderer&&m.renderJobs.get(this.transform.view3D).reflectionRenderer.forceUpdate()}start(){this.transform.onPositionChange=()=>this.onPositionChange(),this.transform.onRotationChange=()=>this.onRotChange(),this.onPositionChange(),this.onRotChange()}onPositionChange(){this.lightData.lightPosition.copyFrom(this.transform.worldPosition),this.onChange()}onRotChange(){this.dirFix==1?this.lightData.direction.copyFrom(this.transform.forward):this.lightData.direction.copyFrom(this.transform.back),this.lightData.lightTangent.copyFrom(this.transform.up),this.onChange()}onScaleChange(){this.onChange()}onEnable(){this.onChange(),J.instance.addLight(this.transform.scene3D,this)}onDisable(){this.onChange(),J.instance.removeLight(this.transform.scene3D,this),It.removeShadowLight(this)}set iesProfiles(e){this._iesProfiles=e,this.lightData.iesIndex=e.index,ba.use=!0,this.onChange()}get iesProfile(){return this._iesProfiles}get r(){return this.lightData.lightColor.r}set r(e){this.lightData.lightColor.r=e,this.onChange()}get g(){return this.lightData.lightColor.g}set g(e){this.lightData.lightColor.g=e,this.onChange()}get b(){return this.lightData.lightColor.b}set b(e){this.lightData.lightColor.b=e,this.onChange()}get lightColor(){return this.lightData.lightColor}set lightColor(e){this.lightData.lightColor=e,this.onChange()}get color(){return this.lightData.lightColor}set color(e){this.lightData.lightColor=e,this.onChange()}get intensity(){return this.lightData.intensity}set intensity(e){this.lightData.intensity=e,this.onChange()}set castShadow(e){e!=this._castShadow&&(this._castShadow=e,this.onChange())}get castShadow(){return this._castShadow}get shadowIndex(){return this.lightData.castShadowIndex}get castGI(){return this._castGI}set castGI(e){e?$n.add(this):$n.remove(this),this._castGI=e,e&&this.onChange()}get direction(){return this.lightData.direction}destroy(e){this.bindOnChange=null,J.instance.removeLight(this.transform.scene3D,this),It.removeShadowLight(this),this.transform.eventDispatcher.removeEventListener(Qt.ROTATION_ONCHANGE,this.onRotChange,this),this.transform.eventDispatcher.removeEventListener(Qt.SCALE_ONCHANGE,this.onScaleChange,this),super.destroy(e)}}var X2=Object.getOwnPropertyDescriptor,H2=(s,e,t,a)=>{for(var r=a>1?void 0:a?X2(e,t):e,i=s.length-1,n;i>=0;i--)(n=s[i])&&(r=n(r)||r);return r};let yi=class extends xi{shadowCamera;constructor(){super()}init(){super.init(),this.object3D.name==""&&(this.object3D.name="DirectionLight_"+Et()),this.radius=Number.MAX_SAFE_INTEGER,this.lightData.lightType=Xe.DirectionLight,this.lightData.linear=0,this.lightData.quadratic=.3}start(){super.start(),this.castGI=!0}get radius(){return this.lightData.range}set radius(s){this.lightData.range=s,this.onChange()}get indirect(){return this.lightData.quadratic}set indirect(s){this.lightData.quadratic=s,this.onChange()}debug(){}};yi=H2([Vt(yi,"DirectLight")],yi);var K2=Object.getOwnPropertyDescriptor,q2=(s,e,t,a)=>{for(var r=a>1?void 0:a?K2(e,t):e,i=s.length-1,n;i>=0;i--)(n=s[i])&&(r=n(r)||r);return r};let ai=class extends xi{constructor(){super()}init(){super.init(),this.lightData.lightType=Xe.PointLight,this.object3D.name==""&&(this.object3D.name="PointLight"+Et())}get range(){return this.lightData.range}set range(s){this.lightData.range=s,this.onChange()}get at(){return this.lightData.linear}set at(s){this.lightData.linear=s,this.onChange()}get radius(){return this.lightData.radius}set radius(s){this.lightData.radius=s,this.onChange()}get quadratic(){return this.lightData.quadratic}set quadratic(s){this.lightData.quadratic=s,this.onChange()}start(){this.transform.rotationX=90,super.start()}onUpdate(){}onGraphic(s){}debug(){}debugDraw(s){}};ai=q2([Vt(ai,"PointLight")],ai);var $2=Object.getOwnPropertyDescriptor,eb=(s,e,t,a)=>{for(var r=a>1?void 0:a?$2(e,t):e,i=s.length-1,n;i>=0;i--)(n=s[i])&&(r=n(r)||r);return r};let Ci=class extends xi{constructor(){super()}init(){super.init(),this.lightData.lightType=Xe.SpotLight,this.object3D.name==""&&(this.object3D.name="SpotLight"+Et())}get innerAngle(){return this.lightData.innerAngle/this.lightData.outerAngle*100}set innerAngle(s){this.lightData.innerAngle=se(s,0,100)/100*this.lightData.outerAngle,this.onChange()}get outerAngle(){return this.lightData.outerAngle*Xr*2}set outerAngle(s){this.lightData.outerAngle=se(s,1,179)*rt*.5,this.onChange()}get radius(){return this.lightData.radius}set radius(s){this.lightData.radius=s,this.onChange()}get range(){return this.lightData.range}set range(s){this.lightData.range=s,this.onChange()}get at(){return this.lightData.linear}set at(s){this.lightData.linear=s,this.onChange()}start(){super.start(),this.lightData.lightType=Xe.SpotLight}onUpdate(){}onGraphic(s){}debug(){}debugDraw(s){}};Ci=eb([Vt(Ci,"SpotLight")],Ci);class lf{static apply(e,t,a){let r=t.extensions;if(r&&r.KHR_materials_clearcoat){a.shader.getDefaultColorShader().setDefine("USE_CLEARCOAT",!0);let i=r.KHR_materials_clearcoat;"clearcoatFactor"in i&&(t.clearcoatFactor=i.clearcoatFactor,a.clearcoatFactor=t.clearcoatFactor),"clearcoatRoughnessFactor"in i&&(t.clearcoatRoughnessFactor=i.clearcoatRoughnessFactor,a.clearcoatRoughnessFactor=t.clearcoatRoughnessFactor)}}}class cf{static apply(e,t,a){let r=t.extensions;r&&r.KHR_materials_emissive_strength?(a.emissiveIntensity=r.KHR_materials_emissive_strength.emissiveStrength,a.emissiveMap==m.res.blackTexture&&(a.emissiveMap=m.res.whiteTexture)):a.emissiveIntensity=1}}class ff{static apply(e,t,a){let r=t.extensions;r&&r.KHR_materials_unlit?a.supportLight=!1:a.supportLight=!0}}class df{gltf;subParser;_testCount=8;_hasCastShadow=!1;constructor(e){this.gltf=e.gltf,this.subParser=e}async convertNodeToObject3D(e,t){const a=new ee;if(a.name=e.name,a[Yt.GLTF_NODE_INDEX_PROPERTY]=e.nodeId,e.nodeObj=a,e.matrix&&(e.translation=[0,0,0],e.rotation=[0,0,0,1],e.scale=[1,1,1]),e.translation&&(a.transform.x=e.translation[0],a.transform.y=e.translation[1],a.transform.z=e.translation[2]),e.rotation){let r=new j;r.setFromArray(e.rotation),a.transform.localRotQuat=r}return e.scale&&(a.transform.scaleX=e.scale[0],a.transform.scaleY=e.scale[1],a.transform.scaleZ=e.scale[2]),t.addChild(a),e.light&&this.convertLight(e,a),e.primitives&&this.convertprimitives(e,a),e.skeleton&&this.convertSkeletonAnim(a,e.skeleton),a}convertSkeletonAnim(e,t){let a=this.subParser.parseSkeleton(t.skeleton);m.res.addObj(a.name,a);let r=[];for(let n=0;n<this.gltf.animations.length;n++){let o=this.gltf.animations[n];o.name||(o.name=n.toString());let l=this.subParser.parseSkeletonAnimation(a,o);r.push(l)}let i=e.addComponent(Pa);i.avatar=a.name,i.clips=r}convertLight(e,t){switch(e.light.type){case"directional":let a=t.addComponent(yi);t.name=e.light.name,a.intensity=e.light.intensity*.1,a.radius=Number.MAX_SAFE_INTEGER,a.dirFix=-1,this._hasCastShadow||(this._hasCastShadow=!0,a.castShadow=this._hasCastShadow),a.lightColor=e.light.color?new P(e.light.color[0],e.light.color[1],e.light.color[2]):new P(1,1,1,1),a.debug();break;case"point":if(this._testCount>0){let i=t.addComponent(ai);i.name=e.light.name,i.intensity=e.light.intensity?e.light.intensity*8*2:1,i.radius=8,i.at=2,i.range=e.light.range?e.light.range:8,i.lightColor=e.light.color?new P(e.light.color[0],e.light.color[1],e.light.color[2]):new P(1,1,1,1)}this._testCount--;break;case"spot":let r=t.addComponent(Ci);r.name=e.light.name,r.intensity=e.light.intensity*5,r.radius=1,r.dirFix=-1,r.at=2,r.range=e.light.range?e.light.range:8,r.outerAngle=e.light.spot.outerConeAngle*Xr,r.lightColor=e.light.color?new P(e.light.color[0],e.light.color[1],e.light.color[2]):new P(1,1,1,1);break}}convertprimitives(e,t){for(let a=0;a<e.primitives.length;a++){const r=e.primitives[a];r.modelName;let i=r.material;i.name==null&&(i.name=Et());let n,o=`matkey_${i.name}`;if(i&&this.gltf.resources[o])n=this.gltf.resources[o];else{let b=i;const p=b?.extensions?.KHR_materials_unlit!==void 0;let g=p?new nt:new ka;if(n=g,this.gltf.resources[o]=g,g.name=i.name,b){const{baseColorTexture:A,baseColorFactor:D,metallicFactor:_,roughnessFactor:U,doubleSided:v,metallicRoughnessTexture:x,normalTexture:C,occlusionTexture:F,emissiveTexture:w,emissiveFactor:S,enableBlend:M,alphaCutoff:T}=b;let Q=g=this.applyMaterialExtensions(b,g);if(p){const L=Q;L.baseColor=new P(D[0],D[1],D[2],D[3]),A&&(L.baseMap=A),Q.doubleSide=v,"enableBlend"in b&&(b.enableBlend?(b.defines?.includes("ALPHA_BLEND")?Q.blendMode=ae.ALPHA:Q.blendMode=ae.NORMAL,Q.castShadow=!1):Q.blendMode=ae.NONE),"alphaCutoff"in b&&T>0&&T<1&&(Q.setUniformFloat("alphaCutoff",T),Q.blendMode=ae.NORMAL,Q.transparent=!0)}else if("enableBlend"in b&&(b.enableBlend?(b.defines?.includes("ALPHA_BLEND")?Q.blendMode=ae.ALPHA:Q.blendMode=ae.NORMAL,Q.castShadow=!1):Q.blendMode=ae.NONE),"alphaCutoff"in b&&T>0&&T<1&&(Q.setUniformFloat("alphaCutoff",T),Q.blendMode=ae.NORMAL,Q.transparent=!0),b.baseMapOffsetSize&&Q.setUniformVector4("baseMapOffsetSize",b.baseMapOffsetSize),b.normalMapOffsetSize&&Q.setUniformVector4("normalMapOffsetSize",b.normalMapOffsetSize),b.emissiveMapOffsetSize&&Q.setUniformVector4("emissiveMapOffsetSize",b.emissiveMapOffsetSize),b.roughnessMapOffsetSize&&Q.setUniformVector4("roughnessMapOffsetSize",b.roughnessMapOffsetSize),b.metallicMapOffsetSize&&Q.setUniformVector4("metallicMapOffsetSize",b.metallicMapOffsetSize),b.aoMapOffsetSize&&Q.setUniformVector4("aoMapOffsetSize",b.aoMapOffsetSize),Q.setUniformColor("baseColor",new P(D[0],D[1],D[2],D[3])),Q.setUniformFloat("roughness",U??1),Q.setUniformFloat("metallic",_??0),Q.setUniformFloat("ao",1),Q.doubleSide=v,A&&Q.setTexture("baseMap",A),C&&Q.setTexture("normalMap",C),x?(Q.setTexture("maskMap",x),Q.shader.setDefine("USE_ROUGHNESS_G",!0),Q.shader.setDefine("USE_METALLIC_B",!0)):(Q.shader.setDefine("USE_ROUGHNESS_G",!1),Q.shader.setDefine("USE_METALLIC_B",!1)),w&&Q.setTexture("emissiveMap",w),S&&(S[0]>0||S[1]>0||S[2]>0)){Q.shader.getTexture("emissiveMap")||Q.shader.setTexture("emissiveMap",m.res.whiteTexture),Q.shader.setDefine("USE_EMISSIVEMAP",!0),Q.setUniformColor("emissiveColor",new P(S[0],S[1],S[2],S[3])),Q.blendMode!=ae.NONE&&(Q.blendMode=ae.ADD);let L=n.getUniformFloat("emissiveIntensity");(!L||L<=0)&&n.setUniformFloat("emissiveIntensity",1)}}}const{attribArrays:l,modelName:c,drawMode:f}=r;let d;if(!l.indices.data){let b=[],p=l.position.data.length/3/3;for(let g=0;g<p;g++){let A=g*3;b.push(A+2),b.push(A+0),b.push(A+1)}l.indices={data:new Uint8Array(b),normalize:!1,numComponents:1}}let h=!l.normal;if(h){let b=[],p=l.position.data.length/3;for(let g=0;g<p;g++)b.push(0),b.push(0),b.push(0);l.normal={data:new Float32Array(b),normalize:!1,numComponents:3}}if(l.indices.data&&l.indices.data.length>3){let b=r.meshName();this.gltf.resources[b]&&(d=this.gltf.resources[b]);const p=new ee;if(p.name=c+a,this.gltf.animations&&l[V.joints0]!=null){d||=this.createGeometryBase(c,l,r,e.skin),this.gltf.resources[b]=d,h&&l.indices?.data&&l.indices.data.length>0&&d.computeNormals();let g=this.gltf.nodes[e.skin.skeleton];g.dnode&&g.dnode.nodeObj?this.convertSkeletonAnim(t,e.skin):g.dnode.skeleton=e.skin;let A=p.addComponent(lr);A.geometry=d,A.material=n}else{d||=this.createGeometryBase(c,l,r),this.gltf.resources[b]=d,h&&l.indices?.data&&l.indices.data.length>0&&d.computeNormals(),d.hasAttribute(V.joints0)&&d.vertexAttributeMap.delete(V.joints0);let g=p.addComponent($);g.castShadow=!0,g.castGI=!0,g.geometry=d,g.material=n}e.skin&&e.skin.defines,t.addChild(p)}}}createGeometryBase(e,t,a,r){"indices"in t&&(t.indices.data.length>65534?t.indices.data=new Uint32Array(t.indices.data):t.indices.data=new Uint16Array(t.indices.data));let i=new Ee;if(i.name=e,"indices"in t&&(t.indices.data.length>65535?t.indices.data=new Uint32Array(t.indices.data):t.indices.data=new Uint16Array(t.indices.data)),a.morphTargetsRelative){let l=new Io,c=a.targetNames;if(c&&c.length>0){l.shapeNames=[],l.shapeIndexs=[];for(let f=0;f<c.length;f++)l.shapeNames.push(c[f]),l.shapeIndexs.push(f)}l.vertexCount=t.position.data.length/3,l.blendCount=l.shapeNames.length,l.blendShapePropertyDatas=[],l.blendShapeMap=new Map;for(let f=0;f<l.blendCount;f++){let d=new Ro;d.shapeName=l.shapeNames[f],d.shapeIndex=l.shapeIndexs[f],d.frameCount=1,d.blendPositionList=t[Yt.MORPH_POSITION_PREFIX+f].data,d.blendNormalList=t[Yt.MORPH_NORMAL_PREFIX+f].data,l.blendShapePropertyDatas.push(d),l.blendShapeMap.set(d.shapeName,d)}i.blendShapeData=l}i.morphTargetsRelative=a.morphTargetsRelative;let n=a.targetNames;if(n&&n.length>0){let l=i.morphTargetDictionary={};for(let c=0;c<n.length;c++)l[n[c]]=c}if(i.morphTargetDictionary){let l=t.position.data.length/3,c=new Float32Array(l);for(let f=0;f<l;f++)c[f]=f;t.vIndex={data:c,normalize:!1,numComponents:1}}for(const l in t){let c=t[l];i.setAttribute(l,c.data)}if(r){i.skinNames=new Array(r.joints.length);for(let l=0;l<r.joints.length;l++){const c=r.joints[l],f=this.gltf.nodes[c];i.skinNames[l]=f.name}i.bindPose=new Array(r.inverseBindMatrices.length);for(let l=0;l<r.inverseBindMatrices.length;l++){const c=r.inverseBindMatrices[l];let f=new E;f.rawData.set(c),i.bindPose[l]=f}}let o=i.getAttribute(V.indices);return i.addSubGeometry({indexStart:0,indexCount:o.data.length,vertexStart:0,index:0,vertexCount:0,firstStart:0,topology:0}),i}applyMaterialExtensions(e,t){return e.extensions&&(lf.apply(this.gltf,e,t),ff.apply(this.gltf,e,t),cf.apply(this.gltf,e,t)),t}parseSkinJoints(e){let t=[];for(let a of e.joints){let r=this.gltf.nodes[a];t.push(r.name)}return t}}class vs{currentSceneName;gltf;initUrl;_generator;_version;_BASE64_MARKER=";base64,";_cameraParser=null;_meshParser=null;_materialParser=null;_skinParser=null;_skeletonParser=null;_converter=null;constructor(){}get version(){return this.version?this.version:this.gltf?this.gltf.asset?(this._version=this.gltf.asset.version,this.gltf.asset.minVersion&&(this._version+=`\r minVersion${this.gltf.asset.minVersion}`),this.version):this.errorMiss("asset"):(console.warn("glTF not loaded."),null)}async parse(e,t,a){this.gltf=t,this.initUrl=e;const{version:r,generator:i}=this.gltf.asset;if(this._generator=i,r!=="2.0")return console.error(`GLTFParser only support glTF 2.0 for now! Received glTF version: ${this.version}`),!1;const n={nodes:await this.parseScene(a),animations:this.parseAnimations(),name:this.currentSceneName};return await this.convertToNode(n)}destroy(){Hn.unload(this.gltf),this.gltf=null}async parseScene(e){const t=e||this.gltf.scene||0,a=this.gltf.scenes[t];if(typeof a>"u")return this.errorMiss("scene",t);this.currentSceneName=a.name||"GLTF_NO_NAME_SCENE";const r=[],i=a.nodes;for(let n=0;n<i.length;n++){const o=await this.parseNode(i[n]);o&&r.push(o)}return r}async parseNode(e){const t=this.gltf.nodes[e];if(!t)return this.errorMiss("node",e);if(t.isParsed)return t.dnode;const{name:a,matrix:r,translation:i,rotation:n,scale:o}=t,l={name:a,matrix:r,translation:i,rotation:n,scale:o,nodeId:e,camera:null,primitives:null,skin:null,children:null,light:null};if(t.camera!==void 0&&(l.camera=this.parseCamera(t.camera)),t.mesh!==void 0&&(l.primitives=await this.parseMesh(t.mesh)),t.extensions!==void 0&&this.applyNodeExtensions(t,l),t.skin!==void 0){const c=this.parseSkin(t.skin);c&&(l.skin=c)}if(l.children=[],t.children)for(let c=0;c<t.children.length;c++)l.children.push(await this.parseNode(t.children[c]));return t.dnode=l,t.isParsed=!0,t.dnode}errorMiss(e,t){throw new Error(e+t)}parseCamera(e){return this._cameraParser||(this._cameraParser=new tf(this.gltf)),this._cameraParser.parse(e)}async parseMesh(e){return this._meshParser||(this._meshParser=new af(this)),this._meshParser.parse(e)}async parseTexture(e){let t=this.gltf.textures[e];if(t&&!t.dtexture){if(t&&t.source!=null){let a=this.gltf.images[t.source];if(a.uri){let r=a.uri;r=Ct.getURLName(r),t.dtexture=this.gltf.resources[r]}else if(a.bufferView){let r=this.parseBufferView(a.bufferView),i=new Va,n=new Blob([r],{type:a.mimeType});await i.loadFromBlob(n),t.dtexture=i}else t.dtexture=this.gltf.resources[a.name]}else if(t.name){let a=Ct.getURLName(t.name);t.dtexture=this.gltf.resources[a]}}return t.dtexture||console.log("miss texture , please check texture!",e,t),t.dtexture}async parseMaterial(e){return this._materialParser||(this._materialParser=new rf(this)),this._materialParser.parse(e)}parseAnimations(){return[]}async parseObject3D(e,t){return this._converter||(this._converter=new df(this)),this._converter.convertNodeToObject3D(e,t)}parseSkeleton(e){return this._skeletonParser||(this._skeletonParser=new qn(this)),this._skeletonParser.parse(e)}parseSkeletonAnimation(e,t){return this._skeletonParser||(this._skeletonParser=new qn(this)),this._skeletonParser.parseSkeletonAnimation(e,t)}async traverse(e,t){for(let a=0;a<t.length;a++){const r=await this.parseObject3D(t[a],e);await this.traverse(r,t[a].children)}}async convertToNode(e){const t=new ee;t.name=e.name;const a=e.nodes;e.animations;const r=[],i=[];return await this.traverse(t,a),{rootNode:t,textures:r,animations:void 0,cameras:i}}parseSkin(e){return this._skinParser||(this._skinParser=new sf(this)),this._skinParser.parse(e)}parseAccessor(e){const t=this.gltf.accessors[e];if(!t)return this.errorMiss("accessor",e);if(t.isParsed)return t.daccessor;t.isParsed=!0,t.daccessor=!1;const a=!!t.normalized,r=this.gltf.bufferViews[t.bufferView],i=r&&r.byteStride,n=Xn(t.componentType);let o=1;switch(t.type){case"SCALAR":o=1;break;case"VEC2":o=2;break;case"VEC3":o=3;break;case"VEC4":case"MAT2":o=4;break;case"MAT3":o=9;break;case"MAT4":o=16;break;default:o=0;break}if(o===0)return console.error(`glTF has unknown data type in accessor: ${t.type}`),!1;const l=o*n.BYTES_PER_ELEMENT;let c;if(r!==void 0){if(c=this.parseBufferView(t.bufferView),!c)return t.daccessor}else c=new Uint8Array(l*t.count).buffer;let f=this.getTypedArrayFromArrayBuffer(c,i,t.byteOffset||0,n,o,t.count);if(t.sparse){const{count:d,indices:h,values:b}=t.sparse;f=new n(f);const p=h.byteOffset||0,g=this.gltf.bufferViews[h.bufferView],A=Xn(h.componentType),D=this.parseBufferView(h.bufferView),_=this.getTypedArrayFromArrayBuffer(D,g.byteStride,p,A,1,d),U=b.byteOffset||0,v=this.gltf.bufferViews[b.bufferView],x=this.parseBufferView(b.bufferView),C=this.getTypedArrayFromArrayBuffer(x,v.byteStride,U,n,o,d);for(let F=0;F<_.length;F++)f.set(C.slice(F*o,F*o+o),_[F]*o)}return t.computeResult={typedArray:f,arrayType:n,numComponents:o},t.daccessor={data:f,numComponents:o,normalize:a},t.daccessor}getTypedArrayFromArrayBuffer(e,t,a,r,i,n){let o;const l=i*r.BYTES_PER_ELEMENT;if(t&&l!==t){const c=i*n;o=new r(c);for(let f=0;f<n;f++){const d=new r(e,a+f*t,i);for(let h=0;h<i;h++)o[f*i+h]=d[h]}}else o=new r(e,a,n*i);return o}parseBufferView(e){const t=this.gltf.bufferViews[e];if(!t)return this.errorMiss("bufferView",e);if(t.isParsed)return t.dbufferView;t.isParsed=!0,t.dbufferView=!1;const a=this.parseBuffer(t.buffer);if(a){const{byteOffset:r,byteLength:i}=t,n=new Uint8Array(a,r||0,i);t.dbufferView=new Uint8Array(n).buffer}return t.dbufferView}parseBuffer(e){const t=this.gltf.buffers[e];if(!t)return this.errorMiss("buffer",e);if(t.isParsed)return t.dbuffer;if(t.isParsed=!0,t.dbuffer=!1,t.uri.substring(0,5)!=="data:"){const a=t.uri,r=this.gltf.resources[a];r?r.byteLength===t.byteLength?t.dbuffer=this.gltf.resources[a]:console.error(`load gltf resource "${a}" at buffers[${e} failed, ArrayBuffer.byteLength not equals buffer's byteLength]`):console.error(`load gltf resource "${a}" at buffers[${e}] failed`)}else{const a=t.uri.indexOf(this._BASE64_MARKER)+this._BASE64_MARKER.length,r=window.atob(t.uri.substring(a)),i=new Uint8Array(r.length);for(let n=0;n<r.length;n++)i[n]=r.charCodeAt(n);t.dbuffer=i.buffer}return t.dbuffer}getLight(e){return this.gltf.extensions.KHR_lights_punctual.lights[e]}applyNodeExtensions(e,t){let a=e.extensions;a.KHR_lights_punctual&&this.gltf.extensions.KHR_lights_punctual&&(t.light=this.getLight(a.KHR_lights_punctual.light))}}class hf{magic;version;length}class uf{chunkLength;chunkType;chunkData}class eo extends st{static format=ze.BIN;_gltf;async parseBuffer(e){let t=new Uint8Array(e);t.pos=0;const a=this.parseHeader(t);if(a.magic!=1179937895)return console.error("invalid GLB file"),!1;if(a.version!==2)return console.error(`GLBParser only support glTF 2.0 for now! Received glTF version: ${a.version}`),!1;let r=[];for(;t.pos<t.length;){let d=this.parseChunk(t);r.push(d)}if(r[0].chunkType!=1313821514)return console.error("invalid GLBChunk"),!1;let i="",n=65535,o=r[0].chunkData;for(let d=0;d<o.length;d+=n){let h=o.length-d;h=Math.min(h,n);let b=o.subarray(d,d+h);i+=String.fromCharCode(...b)}let l=JSON.parse(i);this._gltf=new Bs,this._gltf={...this._gltf,...l},this._gltf.resources={};for(let d=0;d<this._gltf.buffers.length;d++){let h=this._gltf.buffers[d];h.isParsed=!0,h.dbuffer=r[d+1].chunkData.buffer}if(this._gltf.images)for(let d=0;d<this._gltf.images.length;d++){let h=this._gltf.images[d];h.name=h.name||"bufferView_"+h.bufferView.toString();const b=this._gltf.bufferViews[h.bufferView],p=this._gltf.buffers[b.buffer];let g=new Uint8Array(p.dbuffer,b.byteOffset,b.byteLength),A=new Blob([g],{type:h.mimeType}),D=new Va;await D.loadFromBlob(A),D.name=h.name,this._gltf.resources[h.name]=D}let f=await new vs().parse(this.initUrl,this._gltf,this._gltf.scene);return f?(this.data=f.rootNode,f.rootNode):null}async parseJsonAndBuffer(e,t){this._gltf=new Bs,this._gltf={...this._gltf,...e},this._gltf.resources={};let a=this._gltf.buffers[0];if(a.isParsed=!0,a.dbuffer=t,this._gltf.images)for(let n=0;n<this._gltf.images.length;n++){let o=this._gltf.images[n];o.name=o.name||"bufferView_"+o.bufferView.toString();const l=this._gltf.bufferViews[o.bufferView],c=this._gltf.buffers[l.buffer];let f=new Uint8Array(c.dbuffer,l.byteOffset,l.byteLength),d=new Blob([f],{type:o.mimeType}),h=new Va;await h.loadFromBlob(d),h.name=o.name,this._gltf.resources[o.name]=h}let i=await new vs().parse(this.initUrl,this._gltf,this._gltf.scene);return i?(this.data=i.rootNode,i.rootNode):null}verification(){if(this.data)return!0;throw new Error("Method not implemented.")}parseHeader(e){let t=e.pos,a=new hf,r=new Uint32Array(e.buffer,t,3);return e.pos+=r.byteLength,a.magic=r[0],a.version=r[1],a.length=r[2],a}parseChunk(e){let t=e.pos,a=new uf,r=new Uint32Array(e.buffer,t,2);t=e.pos+=r.byteLength,a.chunkLength=r[0],a.chunkType=r[1],a.chunkData=new Uint8Array(e.buffer,t,a.chunkLength);const i=new Uint8Array(a.chunkLength);for(let n=0;n<a.chunkLength;n++)i[n]=a.chunkData[n];return a.chunkData=i,e.pos+=a.chunkLength,a}}class bf extends ot{constructor(){super();let e=new Ve("PBRLItShader","PBRLItShader");e.setShaderEntry("VertMain","FragMain"),e.passType=H.COLOR,this.addRenderPass(e);let t=e.shaderState;t.acceptShadow=!0,t.castShadow=!0,t.receiveEnv=!0,t.acceptGI=!0,t.useLight=!0,this.setDefine("USE_BRDF",!0),this.setDefine("USE_ROUGHNESS_G",!0),this.setDefine("USE_METALLIC_B",!0),this.setDefine("USE_ALPHA_A",!0),this.setDefault()}setDefault(){this.setUniformFloat("shadowBias",35e-5),this.setUniformColor("baseColor",new P(.75,.75,.75,1)),this.setUniformColor("emissiveColor",new P(0,0,0)),this.setUniformVector4("materialF0",new te(.04,.04,.04,1)),this.setUniformColor("specularColor",new P(.04,.04,.04)),this.setUniformFloat("envIntensity",1),this.setUniformFloat("normalScale",1),this.setUniformFloat("roughness",1),this.setUniformFloat("metallic",1),this.setUniformFloat("ao",1),this.setUniformFloat("roughness_min",0),this.setUniformFloat("roughness_max",1),this.setUniformFloat("metallic_min",0),this.setUniformFloat("metallic_max",1),this.setUniformFloat("emissiveIntensity",0),this.setUniformFloat("alphaCutoff",0),this.setUniformFloat("ior",1.5),this.setUniformFloat("clearcoatFactor",0),this.setUniformFloat("clearcoatRoughnessFactor",0),this.setUniformColor("clearcoatColor",new P(1,1,1)),this.setUniformFloat("clearcoatWeight",0),this.setUniformFloat("clearcoatIor",1.5),this.setUniformVector4("baseMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("normalMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("emissiveMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("roughnessMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("metallicMapOffsetSize",new te(0,0,1,1)),this.setUniformVector4("aoMapOffsetSize",new te(0,0,1,1)),this.baseMap=m.res.whiteTexture,this.normalMap=m.res.normalTexture,this.maskMap=m.res.maskTexture}get baseMap(){return this.getDefaultColorShader().getTexture("baseMap")}set baseMap(e){this.getDefaultColorShader().setTexture("baseMap",e)}get baseColor(){return this.getDefaultColorShader().getUniform("baseColor")}set baseColor(e){this.getDefaultColorShader().setUniformColor("baseColor",e)}get normalMap(){return this.getDefaultColorShader().getTexture("normalMap")}set normalMap(e){this.getDefaultColorShader().setTexture("normalMap",e)}get doubleSide(){return this.getDefaultColorShader().doubleSide}set doubleSide(e){this.getDefaultColorShader().doubleSide=e}get alphaCutoff(){return this.getDefaultColorShader().shaderState.alphaCutoff}set alphaCutoff(e){this.getDefaultColorShader().setDefine("USE_ALPHACUT",!0),this.getDefaultColorShader().shaderState.alphaCutoff=e,this.getDefaultColorShader().setUniform("alphaCutoff",e)}get emissiveColor(){return this.getDefaultColorShader().getUniform("emissiveColor")}set emissiveColor(e){this.getDefaultColorShader().setUniform("emissiveColor",e)}get emissiveIntensity(){return this.getDefaultColorShader().getUniform("emissiveIntensity")}set emissiveIntensity(e){this.getDefaultColorShader().setUniform("emissiveIntensity",e)}get transformUV1(){return this.getDefaultColorShader().uniforms.transformUV1.vector4}set transformUV1(e){this.getDefaultColorShader().setUniform("transformUV1",e)}get uvTransform_2(){return this.getDefaultColorShader().uniforms.transformUV2.vector4}set uvTransform_2(e){this.getDefaultColorShader().setUniform("transformUV2",e)}get depthWriteEnabled(){return this.getDefaultColorShader().shaderState.depthWriteEnabled}set depthWriteEnabled(e){this.getDefaultColorShader().shaderState.depthWriteEnabled=e}get materialF0(){return this.getDefaultColorShader().uniforms.materialF0.vector4}set materialF0(e){this.getDefaultColorShader().setUniform("materialF0",e)}get specularColor(){return this.getDefaultColorShader().uniforms.specularColor.color}set specularColor(e){this.getDefaultColorShader().setUniform("specularColor",e)}get roughness(){return this.getDefaultColorShader().uniforms.roughness.value}set roughness(e){this.getDefaultColorShader().setUniform("roughness",e)}get metallic(){return this.getDefaultColorShader().uniforms.metallic.value}set metallic(e){this.getDefaultColorShader().setUniform("metallic",e)}get ao(){return this.getDefaultColorShader().uniforms.ao.value}set ao(e){this.getDefaultColorShader().setUniform("ao",e)}get metallic_min(){return this.getDefaultColorShader().uniforms.metallic_min.value}set metallic_min(e){this.getDefaultColorShader().setUniform("metallic_min",e)}get metallic_max(){return this.getDefaultColorShader().uniforms.metallic_max.value}set metallic_max(e){this.getDefaultColorShader().setUniform("metallic_max",e)}get roughness_min(){return this.getDefaultColorShader().uniforms.roughness_min.value}set roughness_min(e){this.getDefaultColorShader().setUniform("roughness_min",e)}get roughness_max(){return this.getDefaultColorShader().uniforms.roughness_max.value}set roughness_max(e){this.getDefaultColorShader().setUniform("roughness_max",e)}get normalScale(){return this.getDefaultColorShader().uniforms.normalScale.value}set normalScale(e){this.getDefaultColorShader().setUniform("normalScale",e)}get maskMap(){return this.getDefaultColorShader().textures.maskMap}set maskMap(e){this.getDefaultColorShader().setDefine("USE_MR",!0),this.getDefaultColorShader().setTexture("maskMap",e)}set aoMap(e){e&&(this.getDefaultColorShader().setTexture("aoMap",e),e!=m.res.whiteTexture&&this.getDefaultColorShader().setDefine("USE_AOTEX",!0))}get aoMap(){return this.getDefaultColorShader().textures.aoMap}set clearCoatRoughnessMap(e){e&&(console.log("USE_CLEARCOAT_ROUGHNESS"),this.getDefaultColorShader().setTexture("clearCoatRoughnessMap",e),this.getDefaultColorShader().setDefine("USE_CLEARCOAT_ROUGHNESS",!0))}get clearCoatRoughnessMap(){return this.getDefaultColorShader().textures.clearCoatRoughnessMap}get brdfLUT(){return this.getDefaultColorShader().textures.brdfLUT}set brdfLUT(e){this.getDefaultColorShader().setTexture("brdfLUT",e),this.getDefaultColorShader().setTexture("brdflutMap",e)}get emissiveMap(){return this.getDefaultColorShader().textures.emissiveMap}set emissiveMap(e){this.getDefaultColorShader().setTexture("emissiveMap",e)}set envIntensity(e){this.getDefaultColorShader().setUniformFloat("envIntensity",e)}get envIntensity(){return this.getDefaultColorShader().uniforms.envIntensity.value}set ior(e){this.getDefaultColorShader().setUniformFloat("ior",e)}get ior(){return this.getDefaultColorShader().uniforms.ior.value}useCleanCoat(){this.getDefaultColorShader().setDefine("USE_CLEARCOAT",!0)}set clearcoatFactor(e){this.getDefaultColorShader().setUniformFloat("clearcoatFactor",e),this.useCleanCoat()}get clearcoatFactor(){return this.getDefaultColorShader().uniforms.clearcoatFactor.value}set clearcoatRoughnessFactor(e){this.getDefaultColorShader().setUniformFloat("clearcoatRoughnessFactor",e),this.useCleanCoat()}get clearcoatRoughnessFactor(){return this.getDefaultColorShader().uniforms.clearcoatRoughnessFactor.value}set clearcoatWeight(e){this.getDefaultColorShader().setUniformFloat("clearcoatWeight",e),this.useCleanCoat()}get clearcoatWeight(){return this.getDefaultColorShader().uniforms.clearcoatWeight.value}set clearcoatColor(e){this.getDefaultColorShader().setUniformColor("clearcoatColor",e),this.useCleanCoat()}get clearcoatColor(){return this.getDefaultColorShader().uniforms.clearcoatColor.color}}class ka extends mt{constructor(){super();let e=new bf;this.shader=e}clone(){let e=new ka,t=e.shader.getDefaultColorShader(),a=this.shader.getDefaultColorShader();return t.defineValue={...a.defineValue},t.setUniform("shadowBias",a.getUniform("shadowBias")),t.setUniform("baseColor",a.getUniform("baseColor")),t.setUniform("specularColor",a.getUniform("specularColor")),t.setUniform("emissiveColor",a.getUniform("emissiveColor")),t.setUniform("materialF0",a.getUniform("materialF0")),t.setUniform("envIntensity",a.getUniform("envIntensity")),t.setUniform("normalScale",a.getUniform("normalScale")),t.setUniform("roughness",a.getUniform("roughness")),t.setUniform("metallic",a.getUniform("metallic")),t.setUniform("ao",a.getUniform("ao")),t.setUniform("roughness_min",a.getUniform("roughness_min")),t.setUniform("roughness_max",a.getUniform("roughness_max")),t.setUniform("metallic_min",a.getUniform("metallic_min")),t.setUniform("metallic_max",a.getUniform("metallic_max")),t.setUniform("emissiveIntensity",a.getUniform("emissiveIntensity")),t.setUniform("alphaCutoff",a.getUniform("alphaCutoff")),t.setUniform("ior",a.getUniform("ior")),t.setUniform("clearcoatFactor",a.getUniform("clearcoatFactor")),t.setUniform("clearcoatRoughnessFactor",a.getUniform("clearcoatRoughnessFactor")),t.setUniform("clearcoatColor",a.getUniform("clearcoatColor")),t.setUniform("clearcoatWeight",a.getUniform("clearcoatWeight")),t.setUniform("clearcoatIor",a.getUniform("clearcoatIor")),t.setTexture("baseMap",a.getTexture("baseMap")),t.setTexture("normalMap",a.getTexture("normalMap")),t.setTexture("emissiveMap",a.getTexture("emissiveMap")),t.setTexture("aoMap",a.getTexture("aoMap")),t.setTexture("maskMap",a.getTexture("maskMap")),t.setTexture("empty",a.getTexture("empty")),t.setUniform("baseMapOffsetSize",a.getUniform("baseMapOffsetSize")),t.setUniform("normalMapOffsetSize",a.getUniform("normalMapOffsetSize")),t.setUniform("emissiveMapOffsetSize",a.getUniform("emissiveMapOffsetSize")),t.setUniform("roughnessMapOffsetSize",a.getUniform("roughnessMapOffsetSize")),t.setUniform("metallicMapOffsetSize",a.getUniform("metallicMapOffsetSize")),t.setUniform("aoMapOffsetSize",a.getUniform("aoMapOffsetSize")),e}set baseMap(e){this.shader.setTexture("baseMap",e)}get baseMap(){return this.shader.getTexture("baseMap")}set maskMap(e){this.shader.setTexture("maskMap",e)}get maskMap(){return this.shader.getTexture("maskMap")}set normalMap(e){this.shader.setTexture("normalMap",e)}get normalMap(){return this.shader.getTexture("normalMap")}set emissiveMap(e){this.shader.setTexture("emissiveMap",e)}get emissiveMap(){return this.shader.getTexture("emissiveMap")}set aoMap(e){this.shader.setTexture("aoMap",e)}get aoMap(){return this.shader.getTexture("aoMap")}set clearCoatRoughnessMap(e){this.shader.setTexture("clearCoatRoughnessMap",e),this.shader.setDefine("USE_CLEARCOAT",!0),this.shader.setDefine("USE_CLEARCOAT_ROUGHNESS",!0)}get clearCoatRoughnessMap(){return this.shader.getTexture("clearCoatRoughnessMap")}set clearcoatColor(e){this.shader.setUniformColor("clearcoatColor",e),this.shader.setDefine("USE_CLEARCOAT",!0)}get clearcoatColor(){return this.shader.getUniformColor("clearcoatColor")}set clearcoatWeight(e){this.shader.setUniformFloat("clearcoatWeight",e),this.shader.setDefine("USE_CLEARCOAT",!0)}get clearcoatWeight(){return this.shader.getUniformFloat("clearcoatWeight")}set clearcoatFactor(e){this.shader.setUniformFloat("clearcoatFactor",e),this.shader.setDefine("USE_CLEARCOAT",!0)}get clearcoatFactor(){return this.shader.getUniformFloat("clearcoatFactor")}set clearcoatRoughnessFactor(e){this.shader.setUniformFloat("clearcoatRoughnessFactor",e),this.shader.setDefine("USE_CLEARCOAT",!0)}get clearcoatRoughnessFactor(){return this.shader.getUniformFloat("clearcoatRoughnessFactor")}set ior(e){this.shader.setUniformFloat("clearcoatIor",e)}get ior(){return this.shader.getUniformFloat("clearcoatIor")}set alphaCutoff(e){this.shader.setUniform("alphaCutoff",e)}get alphaCutoff(){return this.shader.getUniform("alphaCutoff")}set baseColor(e){this.shader.setUniformColor("baseColor",e)}get baseColor(){return this.shader.getUniformColor("baseColor")}get roughness(){return this.shader.getUniformFloat("roughness")}set roughness(e){this.shader.setUniformFloat("roughness",e)}get metallic(){return this.shader.getUniformFloat("metallic")}set metallic(e){this.shader.setUniformFloat("metallic",e)}get emissiveColor(){return this.shader.getUniformColor("emissiveColor")}set emissiveColor(e){this.shader.setUniformColor("emissiveColor",e)}get emissiveIntensity(){return this.shader.getUniformFloat("emissiveIntensity")}set emissiveIntensity(e){this.shader.setUniformFloat("emissiveIntensity",e)}get ao(){return this.shader.getUniform("ao")}set ao(e){this.shader.setUniform("ao",e)}}class gf extends st{static format=ze.TEXT;textData="";source_vertices;source_normals;source_tangents;source_textureCoords;matLibs;geometrys;activeGeo;currentObjectName;currentMaterialName;facesMaterialsIndex;mtl;mtlUrl;async parseString(e){return this.source_vertices=[],this.source_normals=[],this.source_tangents=[],this.source_textureCoords=[],this.currentObjectName="default",this.currentMaterialName="",this.matLibs={},this.geometrys={},this.activeGeo=void 0,this.textData=e,await Promise.all([this.parserOBJ(),this.loadMTL()]),this.parser_mesh(),"null"}applyVector2(e,t,a){e>=0&&t[e]&&t[e].length>0?(a.push(t[e][0]),a.push(-t[e][1])):(a.push(0),a.push(0))}applyVector3(e,t,a){e>=0&&t[e]&&t[e].length>0?(a.push(t[e][0]),a.push(t[e][1]),a.push(t[e][2])):(a.push(0),a.push(0),a.push(0))}applyVector4(e,t,a){a.push(t[e][0]),a.push(t[e][1]),a.push(t[e][2]),a.push(t[e][3])}parseUVIndex(e,t){const a=parseInt(e,10);return a>=0?a-1:t+a}parseVertexIndex(e,t){const a=parseInt(e,10);return a>=0?a-1:t+a}parseNormalIndex(e,t){const a=parseInt(e,10);return a>=0?a-1:t+a}calculateFaceNormal(e,t,a){const r=[t[0]-e[0],t[1]-e[1],t[2]-e[2]],i=[a[0]-e[0],a[1]-e[1],a[2]-e[2]],n=[r[1]*i[2]-r[2]*i[1],r[2]*i[0]-r[0]*i[2],r[0]*i[1]-r[1]*i[0]],o=Math.sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);return o>0&&(n[0]/=o,n[1]/=o,n[2]/=o),n}async loadMTL(){let t=await new pt().loadTxt(this.baseUrl+this.mtlUrl),a=t.data,r,i=a.split(/\r?\n/);for(let c=0;c<i.length;c++){let f=i[c];var n=f.indexOf("#");n!=-1&&(f=f.substring(0,n)),f=f.trim();var o=f.split(/\s+/);o[0]==="newmtl"?(r={name:o[1]},this.matLibs[o[1]]=r):o[0].indexOf("map_")!=-1?(r[o[0]]=o[1],r.textures||(r.textures=[o[o.length-1]]),r.textures.push(o[o.length-1])):o.length==2?r[o[0]]=Number(o[1]):o.length==3?r[o[0]]=[Number(o[1]),Number(o[2])]:o.length==4&&(r[o[0]]=[Number(o[1]),Number(o[2]),Number(o[3])])}const l=[];for(const c in this.matLibs){const f=this.matLibs[c];if(f.textures&&f.textures.length>0)for(let d=0;d<f.textures.length;d++){const h=Ct.normalizePath(this.baseUrl+f.textures[d]);l.push(m.res.loadTexture(h).catch(b=>(console.error(`Failed to load texture: ${h}`,b),null)))}}return await Promise.all(l),t=null,!0}async load_textures(){}getGeometryKey(e,t){const a=(e??this.currentObjectName??"default")||"default",r=t??this.currentMaterialName??"",i=r.length>0?r:"default";return`${a}::${i}`}ensureActiveGeo(e,t){const a=(e??this.currentObjectName??"default")||"default",r=t??this.currentMaterialName??"",i=this.getGeometryKey(a,r);this.geometrys[i]?this.geometrys[i].source_mat!==r&&(this.geometrys[i].source_mat=r):this.geometrys[i]={type:a,name:i,source_mat:r,source_faces:[]},this.activeGeo=this.geometrys[i]}parserLine(e){var t=e.indexOf("#");if(t!=-1){if(e.indexOf("# object")!=-1){const p=e.split(/\s+/),g=p[1]||"default",A=p[2]||"default";this.currentObjectName=A,this.activeGeo=void 0,this.ensureActiveGeo(A,this.currentMaterialName),this.activeGeo&&(this.activeGeo.type=g)}e=e.substring(0,t)}e=e.trim();var a=e.split(/\s+/);if(a[0]==="v"){var r=[Number(a[1]),Number(a[2]),Number(a[3]),a[4]?1:Number(a[4])];this.source_vertices.push(r)}else if(a[0]==="vt"){var i=[Number(a[1]),Number(a[2]),a[3]?1:Number(a[3])];this.source_textureCoords.push(i)}else if(a[0]==="vn"){var n=[Number(a[1]),Number(a[2]),Number(a[3])];this.source_normals.push(n)}else if(a[0]==="f"){for(var o={indices:[],texture:[],normal:[]},l=1;l<a.length;++l){var c=a[l];if(c.length!==0){var f=c.split("/"),d=f[0]||"",h=f.length>=2&&f[1]||"",b=f.length>=3&&f[2]||"";d.length!==0&&(o.indices.push(d),o.texture.push(h),o.normal.push(b))}}this.ensureActiveGeo(),this.activeGeo.source_faces.push(o)}else a[0]==="usemtl"?(this.currentMaterialName=a[1]||"",this.ensureActiveGeo(this.currentObjectName,this.currentMaterialName)):a[0]==="mtllib"&&(this.mtlUrl=a[1])}async parserOBJ(){let e=this.textData.split(/\r?\n/);for(let t=0;t<e.length;t++){const a=e[t];this.parserLine(a)}return this.textData="",!0}async parser_mesh(){let e=new ee;for(const t in this.geometrys){const a=this.geometrys[t];a.vertex_arr=[],a.normal_arr=[],a.uv_arr=[],a.indeice_arr=[];let r=0;const i=this.source_vertices.length,n=this.source_normals.length,o=this.source_textureCoords.length;for(let p=0;p<a.source_faces.length;p++){const g=a.source_faces[p];let A=this.parseVertexIndex(g.indices[0],i),D=this.parseVertexIndex(g.indices[1],i),_=this.parseVertexIndex(g.indices[2],i);const U=L=>{if(!L||L.length===0)return-1;const X=this.parseNormalIndex(L,n);return Number.isFinite(X)&&X>=0&&X<n?X:-1},v=L=>{if(!L||L.length===0)return-1;const X=this.parseUVIndex(L,o);return Number.isFinite(X)&&X>=0&&X<o?X:-1};let x=U(g.normal[0]),C=U(g.normal[1]),F=U(g.normal[2]);const w=x<0||C<0||F<0;let S=null;w&&A>=0&&D>=0&&_>=0&&this.source_vertices[A]&&this.source_vertices[D]&&this.source_vertices[_]&&(S=this.calculateFaceNormal(this.source_vertices[A],this.source_vertices[D],this.source_vertices[_]));let M=v(g.texture[0]),T=v(g.texture[1]),Q=v(g.texture[2]);if(this.applyVector3(A,this.source_vertices,a.vertex_arr),x>=0?this.applyVector3(x,this.source_normals,a.normal_arr):S?a.normal_arr.push(S[0],S[1],S[2]):a.normal_arr.push(0,0,0),M>=0?this.applyVector2(M,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,this.applyVector3(D,this.source_vertices,a.vertex_arr),C>=0?this.applyVector3(C,this.source_normals,a.normal_arr):S?a.normal_arr.push(S[0],S[1],S[2]):a.normal_arr.push(0,0,0),T>=0?this.applyVector2(T,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,this.applyVector3(_,this.source_vertices,a.vertex_arr),F>=0?this.applyVector3(F,this.source_normals,a.normal_arr):S?a.normal_arr.push(S[0],S[1],S[2]):a.normal_arr.push(0,0,0),Q>=0?this.applyVector2(Q,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,g.indices.length>3){let L=this.parseVertexIndex(g.indices[3],i),X=U(g.normal[3]),ie=v(g.texture[3]),q=null;(x<0||F<0||X<0)&&A>=0&&_>=0&&L>=0&&this.source_vertices[A]&&this.source_vertices[_]&&this.source_vertices[L]&&(q=this.calculateFaceNormal(this.source_vertices[A],this.source_vertices[_],this.source_vertices[L])),this.applyVector3(A,this.source_vertices,a.vertex_arr),x>=0?this.applyVector3(x,this.source_normals,a.normal_arr):q?a.normal_arr.push(q[0],q[1],q[2]):a.normal_arr.push(0,0,0),M>=0?this.applyVector2(M,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,this.applyVector3(_,this.source_vertices,a.vertex_arr),F>=0?this.applyVector3(F,this.source_normals,a.normal_arr):q?a.normal_arr.push(q[0],q[1],q[2]):a.normal_arr.push(0,0,0),Q>=0?this.applyVector2(Q,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++,this.applyVector3(L,this.source_vertices,a.vertex_arr),X>=0?this.applyVector3(X,this.source_normals,a.normal_arr):q?a.normal_arr.push(q[0],q[1],q[2]):a.normal_arr.push(0,0,0),ie>=0?this.applyVector2(ie,this.source_textureCoords,a.uv_arr):a.uv_arr.push(0,0),a.indeice_arr[r]=r++}}let l=new Ee;l.setIndices(new Uint32Array(a.indeice_arr)),l.setAttribute(V.position,new Float32Array(a.vertex_arr)),l.setAttribute(V.normal,new Float32Array(a.normal_arr)),l.setAttribute(V.uv,new Float32Array(a.uv_arr)),l.setAttribute(V.TEXCOORD_1,new Float32Array(a.uv_arr)),l.addSubGeometry({indexStart:0,indexCount:a.indeice_arr.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0});let c=new ka;const f=a.source_mat,d=f?this.matLibs[f]:void 0;if(d&&d.map_Kd){const p=Ct.normalizePath(this.baseUrl+d.map_Kd),g=m.res.getTexture(p);g&&(c.baseMap=g)}let h=new ee,b=h.addComponent($);b.geometry=l,b.material=c,e.addChild(h)}this.data=e}verification(){if(this.data)return!0;throw new Error("Method not implemented.")}}let pf=`
7276
7276
  struct ImageSize {
7277
7277
  srcWidth: i32,
7278
7278
  srcHeight: i32,
@@ -7762,7 +7762,7 @@ else if (typeof exports === 'object')
7762
7762
  `;class Qf{compute;constructor(){this.compute=new fe(If)}generateBRDFLUTTexture(){let e=new Ae(256,256,Y.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 ri{id;guiTexture;uvRec=new te(0,0,1,1);uvBorder=new te(0,0,0,0);offsetSize=new te(0,0,4,4);borderSize=new te(0,0,0,0);trimSize=new K;isSliced=!1;height=4;width=4;xadvance=0;xoffset=0;yoffset=0;constructor(e){this.guiTexture=e||m.res.defaultGUITexture}}class mr{static _maxUid=-1;_staticId=-1;dynamicId=-1;texture;width=1;height=1;get staticId(){return this._staticId}constructor(e){e||=m.res.whiteTexture,e.addressModeU="clamp-to-edge",e.addressModeV="clamp-to-edge",this.texture=e,mr._maxUid++,this._staticId=mr._maxUid,this.init()}init(){this.dynamicId=-1,this.width=this.texture.width,this.height=this.texture.height}}class tb{fntCache={};fntData={};addFontData(e,t,a){this.fntData[`${e}${t}`]=a}getFontData(e,t){return this.fntData[`${e}${t}`]}addFnt(e,t,a,r){let i=`${e}${t}`;this.fntCache[i]||(this.fntCache[i]={}),this.fntCache[i][a]=r}getFnt(e,t,a){let r=`${e}${t}`,i=this.fntCache[r];return i?i[a]:this.fntCache[" "]}}let ii=new tb;class Tf{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 Mf{id=0;file=""}class Nf{id=-1;x=0;y=0;width=0;height=0;xoffset=0;yoffset=0;xadvance=0;page=0;chnl=0}class za extends st{static format=ze.TEXT;static parseSprite(e,t){for(const a in t.fontChar)if(Object.prototype.hasOwnProperty.call(t.fontChar,a)){const r=t.fontChar[a];let i=new ri;i.id=r.id.toString(),i.offsetSize.set(0,0,r.width,r.height),i.trimSize.set(r.width,r.height),i.width=r.width,i.height=r.height,i.xadvance=r.xadvance,i.xoffset=r.xoffset,i.yoffset=r.yoffset,i.guiTexture=e[r.page],i.uvRec.set(r.x/t.scaleW,(t.scaleH-(r.y+r.height))/t.scaleH,r.width/t.scaleW,r.height/t.scaleH),ii.addFnt(t.face,t.size,i.id,i)}}verification(){if(this.data)return!0;throw new Error("Method not implemented.")}async parseString(e){let t=this.getNewLine(e),a=e,r=new Tf;a.trim().split(t).forEach((i,n)=>{if(n<2)za.readLineProperty(i,r);else if(n<r.pages+2){let o=new Mf;za.readLineProperty(i,o),r.fontPage.push(o)}else if(n<r.pages+3)za.readLineProperty(i,r);else if(r.count>0){let o=new Nf;za.readLineProperty(i,o),r.fontChar[o.id]=o,r.count--}}),a="",this.data=r,await this.loadFontTextures()}getNewLine(e){return e.indexOf(`\r
7763
7763
  `)!=-1?`\r
7764
7764
  `:e.indexOf("\r")!=-1?"\r":`
7765
- `}async loadFontTextures(){let e=[],t=this.data;for(const a of t.fontPage){let r=this.baseUrl+a.file;await m.res.loadTexture(r,null,!0);let i=m.res.getTexture(r),n=new mr(i);e.push(n)}za.parseSprite(e,t),t.fontChar[" "]||za.insertSpaceChar(t,e[0])}static insertSpaceChar(e,t){let a=new ri,r=e.size*.5,i=e.lineHeight*.5;a.id=" ",a.offsetSize.set(0,0,e.size,e.size),a.trimSize.set(r,i),a.width=r,a.height=i,a.xadvance=0,a.xoffset=0,a.yoffset=0,a.guiTexture=t,a.uvRec.set(0,0,1e-6,1e-6),ii.addFnt(e.face,e.size,a.id,a)}static readLineProperty(e,t){e.trim().split(" ").forEach((a,r)=>{let i=a.split("=");if(i.length>1){let n=i[0],o=i[1];Object.prototype.hasOwnProperty.call(t,n)&&(o.indexOf('"')==-1?t[n]=parseFloat(i[1]):t[n]=o.replace('"',"").replace('"',""))}})}}function ab(s,e){let t=new ri;return t.id=s,t.offsetSize.set(0,0,e.width,e.height),t.trimSize.set(e.width,e.height),t.width=e.width,t.height=e.height,t.xadvance=0,t.xoffset=0,t.yoffset=0,t.guiTexture=new mr(e),t.uvRec.set(0,0,1,1),e.isVideoTexture||(e.flipY=!0),t}function Vf(s,e,t){let a=new ri;a.guiTexture=s,a.id=e,a.uvRec.copyFrom(t.textureRect),a.trimSize.x=t.textureRect.z,a.trimSize.y=t.textureRect.w,a.offsetSize.x=t.textureRectOffset.x,a.offsetSize.y=t.textureRectOffset.y,a.offsetSize.z=t.size.x,a.offsetSize.w=t.size.y,a.width=t.size.x,a.height=t.size.y;let r=1/s.width,i=1/s.height;a.uvRec.set(a.uvRec.x*r,a.uvRec.y*i,a.uvRec.z*r,a.uvRec.w*i);let n=.1;return t.border.x<=n&&t.border.y<=n&&t.border.z<=n&&t.border.x<=n?a.isSliced=!1:(a.borderSize.copyFrom(t.border),a.uvBorder.copyFrom(t.border),a.uvBorder.x-=t.textureRectOffset.x,a.uvBorder.y-=t.textureRectOffset.y,a.uvBorder.z=t.border.z-(t.size.x-t.textureRect.z-t.textureRectOffset.x),a.uvBorder.w=t.border.w-(t.size.y-t.textureRect.w-t.textureRectOffset.y),a.uvBorder.x/=t.textureRect.z,a.uvBorder.z/=t.textureRect.z,a.uvBorder.y/=t.textureRect.w,a.uvBorder.w/=t.textureRect.w,a.isSliced=!0),a}class Pf{_spriteMap=new Map;_spriteList=[];textureSize=new K;name;constructor(e){this.textureSize.set(e.x,e.y)}setTexture(e,t,a){let r=Vf(e,t,a);return this._spriteMap.set(r.id,r),this._spriteList.push(r),r}getSprite(e){return this._spriteMap.get(e)}get spriteList(){return this._spriteList}}class Of extends st{static format=ze.TEXT;_json;_texture;async parseString(e){this._json=JSON.parse(e);let t=this.userData.replace(".json",".png");this._texture=await m.res.loadTexture(t,null,!0),this.data={json:this._json,texture:this._texture},this.parseAtlas()}verification(){if(this.data)return!0;throw new Error("verify failed.")}parseAtlas(){let e=new Pf(this._json.size),t=new mr(this._texture),a=this._json.atlas;for(const r in a)e.setTexture(t,r,a[r]);m.res.addAtlas(this.baseUrl,e),this.data=e}}var Lt=Uint8Array,si=Uint16Array,rb=Int32Array,Lf=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]),Gf=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]),ib=new Lt([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),zf=function(s,e){for(var t=new si(31),a=0;a<31;++a)t[a]=e+=1<<s[a-1];for(var r=new rb(t[30]),a=1;a<30;++a)for(var i=t[a];i<t[a+1];++i)r[i]=i-t[a]<<5|a;return{b:t,r}},Jf=zf(Lf,2),Wf=Jf.b,sb=Jf.r;Wf[28]=258,sb[258]=28;for(var nb=zf(Gf,0),ob=nb.b,uo=new si(32768),Te=0;Te<32768;++Te){var ir=(Te&43690)>>1|(Te&21845)<<1;ir=(ir&52428)>>2|(ir&13107)<<2,ir=(ir&61680)>>4|(ir&3855)<<4,uo[Te]=((ir&65280)>>8|(ir&255)<<8)>>1}for(var Fi=(function(s,e,t){for(var a=s.length,r=0,i=new si(e);r<a;++r)s[r]&&++i[s[r]-1];var n=new si(e);for(r=1;r<e;++r)n[r]=n[r-1]+i[r-1]<<1;var o;if(t){o=new si(1<<e);var l=15-e;for(r=0;r<a;++r)if(s[r])for(var c=r<<4|s[r],f=e-s[r],d=n[s[r]-1]++<<f,h=d|(1<<f)-1;d<=h;++d)o[uo[d]>>l]=c}else for(o=new si(a),r=0;r<a;++r)s[r]&&(o[r]=uo[n[s[r]-1]++]>>15-s[r]);return o}),ki=new Lt(288),Te=0;Te<144;++Te)ki[Te]=8;for(var Te=144;Te<256;++Te)ki[Te]=9;for(var Te=256;Te<280;++Te)ki[Te]=7;for(var Te=280;Te<288;++Te)ki[Te]=8;for(var Zf=new Lt(32),Te=0;Te<32;++Te)Zf[Te]=5;var lb=Fi(ki,9,1),cb=Fi(Zf,5,1),bo=function(s){for(var e=s[0],t=1;t<s.length;++t)s[t]>e&&(e=s[t]);return e},sa=function(s,e,t){var a=e/8|0;return(s[a]|s[a+1]<<8)>>(e&7)&t},go=function(s,e){var t=e/8|0;return(s[t]|s[t+1]<<8|s[t+2]<<16)>>(e&7)},fb=function(s){return(s+7)/8|0},po=function(s,e,t){return(e==null||e<0)&&(e=0),(t==null||t>s.length)&&(t=s.length),new Lt(s.subarray(e,t))},db=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Ht=function(s,e,t){var a=new Error(e||db[s]);if(a.code=s,Error.captureStackTrace&&Error.captureStackTrace(a,Ht),!t)throw a;return a},hb=function(s,e,t,a){var r=s.length,i=a?a.length:0;if(!r||e.f&&!e.l)return t||new Lt(0);var n=!t,o=n||e.i!=2,l=e.i;n&&(t=new Lt(r*3));var c=function(Ft){var kt=t.length;if(Ft>kt){var Nt=new Lt(Math.max(kt*2,Ft));Nt.set(t),t=Nt}},f=e.f||0,d=e.p||0,h=e.b||0,b=e.l,p=e.d,g=e.m,A=e.n,D=r*8;do{if(!b){f=sa(s,d,1);var _=sa(s,d+1,3);if(d+=3,_)if(_==1)b=lb,p=cb,g=9,A=5;else if(_==2){var C=sa(s,d,31)+257,F=sa(s,d+10,15)+4,w=C+sa(s,d+5,31)+1;d+=14;for(var S=new Lt(w),M=new Lt(19),T=0;T<F;++T)M[ib[T]]=sa(s,d+T*3,7);d+=F*3;for(var Q=bo(M),L=(1<<Q)-1,X=Fi(M,Q,1),T=0;T<w;){var ie=X[sa(s,d,L)];d+=ie&15;var U=ie>>4;if(U<16)S[T++]=U;else{var q=0,be=0;for(U==16?(be=3+sa(s,d,3),d+=2,q=S[T-1]):U==17?(be=3+sa(s,d,7),d+=3):U==18&&(be=11+sa(s,d,127),d+=7);be--;)S[T++]=q}}var Ue=S.subarray(0,C),Z=S.subarray(C);g=bo(Ue),A=bo(Z),b=Fi(Ue,g,1),p=Fi(Z,A,1)}else Ht(1);else{var U=fb(d)+4,v=s[U-4]|s[U-3]<<8,x=U+v;if(x>r){l&&Ht(0);break}o&&c(h+v),t.set(s.subarray(U,x),h),e.b=h+=v,e.p=d=x*8,e.f=f;continue}if(d>D){l&&Ht(0);break}}o&&c(h+131072);for(var de=(1<<g)-1,ce=(1<<A)-1,De=d;;De=d){var q=b[go(s,d)&de],_e=q>>4;if(d+=q&15,d>D){l&&Ht(0);break}if(q||Ht(2),_e<256)t[h++]=_e;else if(_e==256){De=d,b=null;break}else{var Ne=_e-254;if(_e>264){var T=_e-257,we=Lf[T];Ne=sa(s,d,(1<<we)-1)+Wf[T],d+=we}var Ce=p[go(s,d)&ce],Me=Ce>>4;Ce||Ht(3),d+=Ce&15;var Z=ob[Me];if(Me>3){var we=Gf[Me];Z+=go(s,d)&(1<<we)-1,d+=we}if(d>D){l&&Ht(0);break}o&&c(h+131072);var ct=h+Ne;if(h<Z){var ga=i-Z,Mt=Math.min(Z,ct);for(ga+h<0&&Ht(3);h<Mt;++h)t[h]=a[ga+h]}for(;h<ct;++h)t[h]=t[h-Z]}}e.l=b,e.p=De,e.b=h,e.f=f,b&&(f=1,e.m=g,e.d=p,e.n=A)}while(!f);return h!=t.length&&n?po(t,0,h):t.subarray(0,h)},ub=new Lt(0),ya=function(s,e){return s[e]|s[e+1]<<8},na=function(s,e){return(s[e]|s[e+1]<<8|s[e+2]<<16|s[e+3]<<24)>>>0},mo=function(s,e){return na(s,e)+na(s,e+4)*4294967296};function bb(s,e){return hb(s,{i:2},e&&e.out,e&&e.dictionary)}var Ao=typeof TextDecoder<"u"&&new TextDecoder,gb=0;try{Ao.decode(ub,{stream:!0}),gb=1}catch{}var pb=function(s){for(var e="",t=0;;){var a=s[t++],r=(a>127)+(a>223)+(a>239);if(t+r>s.length)return{s:e,r:po(s,t-1)};r?r==3?(a=((a&15)<<18|(s[t++]&63)<<12|(s[t++]&63)<<6|s[t++]&63)-65536,e+=String.fromCharCode(55296|a>>10,56320|a&1023)):r&1?e+=String.fromCharCode((a&31)<<6|s[t++]&63):e+=String.fromCharCode((a&15)<<12|(s[t++]&63)<<6|s[t++]&63):e+=String.fromCharCode(a)}};function jf(s,e){if(e){for(var t="",a=0;a<s.length;a+=16384)t+=String.fromCharCode.apply(null,s.subarray(a,a+16384));return t}else{if(Ao)return Ao.decode(s);var r=pb(s),i=r.s,t=r.r;return t.length&&Ht(8),i}}var mb=function(s,e){return e+30+ya(s,e+26)+ya(s,e+28)},Ab=function(s,e,t){var a=ya(s,e+28),r=jf(s.subarray(e+46,e+46+a),!(ya(s,e+8)&2048)),i=e+46+a,n=na(s,e+20),o=t&&n==4294967295?Db(s,i):[n,na(s,e+24),na(s,e+42)],l=o[0],c=o[1],f=o[2];return[ya(s,e+10),l,c,r,i+ya(s,e+30)+ya(s,e+32),f]},Db=function(s,e){for(;ya(s,e)!=1;e+=4+ya(s,e+2));return[mo(s,e+12),mo(s,e+4),mo(s,e+20)]};function _b(s,e){for(var t={},a=s.length-22;na(s,a)!=101010256;--a)(!a||s.length-a>65558)&&Ht(13);var r=ya(s,a+8);if(!r)return{};var i=na(s,a+16),n=i==4294967295||r==65535;if(n){var o=na(s,a-12);n=na(s,o)==101075792,n&&(r=na(s,o+32),i=na(s,o+48))}for(var l=0;l<r;++l){var c=Ab(s,i,n),f=c[0],d=c[1],h=c[2],b=c[3],p=c[4],g=c[5],A=mb(s,g);i=p,f?f==8?t[b]=bb(s.subarray(A,A+d),{out:new Lt(h)}):Ht(14,"unknown compression type "+f):t[b]=po(s,A,A+d)}return t}class nt extends mt{constructor(){super(),this.shader=new Oi,this.baseMap=m.res.whiteTexture}set baseMap(e){this.shader.setTexture("baseMap",e)}get baseMap(){return this.shader.getTexture("baseMap")}set baseColor(e){this.shader.setUniformColor("baseColor",e)}get baseColor(){return this.shader.getUniformColor("baseColor")}set envMap(e){}set shadowMap(e){}}class Rr extends Ee{shape_vertices=[];shape_indices=[];radius;widthSegments;heightSegments;phiStart;phiLength;thetaStart;thetaLength;constructor(e,t,a,r,i,n,o){super(),this.radius=e,this.widthSegments=t,this.heightSegments=a,this.phiStart=r,this.phiLength=i,this.thetaStart=n,this.thetaLength=o,this.buildGeometry()}buildGeometry(){var e,t,a=0;let r=this.heightSegments,i=this.widthSegments,n=this.radius;var o=(r+1)*(i+1);let l=new Float32Array(o*3),c=new Float32Array(o*3),f=new Float32Array(o*2),d=new Uint16Array(i*r*2*3),h=0,b=0,p=0;for(t=0;t<=r;++t){var g=Math.PI*t/r,A=n*Math.cos(g),D=n*Math.sin(g);for(e=0;e<=i;++e){var _=2*Math.PI*e/i,U=D*Math.cos(_),v=D*Math.sin(_),x=1/Math.sqrt(U*U+A*A+v*v);if(l[h++]=U,l[h++]=A,l[h++]=v,c[b++]=U*x,c[b++]=A*x,c[b++]=v*x,f[p++]=e/i,f[p++]=t/r,e>0&&t>0){var C=(i+1)*t+e,F=(i+1)*t+e-1,w=(i+1)*(t-1)+e-1,S=(i+1)*(t-1)+e;t==r?(d[a++]=C,d[a++]=w,d[a++]=S):t==1?(d[a++]=C,d[a++]=F,d[a++]=w):(d[a++]=C,d[a++]=F,d[a++]=w,d[a++]=C,d[a++]=w,d[a++]=S)}}}this.setIndices(d),this.setAttribute(V.position,l),this.setAttribute(V.normal,c),this.setAttribute(V.uv,f),this.setAttribute(V.TEXCOORD_1,f),this.addSubGeometry({indexStart:0,indexCount:d.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0}),this.bounds=new ge(u.ZERO,new u(this.radius*2,this.radius*2,this.radius*2))}}class os extends ee{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 u(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),os.register3DRepresentation)this.marker=os.register3DRepresentation(this),this.marker&&this.addChild(this.marker);else{this.marker=new ee;const e=this.marker.addComponent($);e.geometry=new Rr(.1,32,16),e.material=new nt,e.material.baseColor=this.positionValid?new P(0,1,0,1):new P(1,0,0,1),this.addChild(this.marker),this.marker.name="WayPoint3DMarker"}}}class ls extends ee{static register3DRepresentation=null;line;constructor(e){super(),this.parseWayLineFile(e),this.setup3DRepresentation()}parseWayLineFile(e){for(const t of e.Folder.Placemark){const a=new os(t);this.addChild(a)}this.entityChildren=this.entityChildren.sort((t,a)=>t.positionIndex-a.positionIndex)}setup3DRepresentation(){this.line&&(this.removeChild(this.line),this.line=null),ls.register3DRepresentation?(this.line=ls.register3DRepresentation(this),this.line&&this.addChild(this.line)):(this.line=this.createMultiLine(this.entityChildren.map(e=>e.localPosition),new P(1,1,1,1)),this.addChild(this.line),this.line.name="WayLines3DLine")}createMultiLine(e,t){if(e.length<2)return null;const a=new Ee,r=new Float32Array(e.length*3);for(let c=0;c<e.length;c++)r[c*3]=e[c].x,r[c*3+1]=e[c].y,r[c*3+2]=e[c].z;const i=new Uint16Array((e.length-1)*2);for(let c=0;c<e.length-1;c++)i[c*2]=c,i[c*2+1]=c+1;a.setIndices(i),a.setAttribute(V.position,r),a.addSubGeometry({indexStart:0,indexCount:i.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0});const n=new ee,o=n.addComponent($),l=new nt;return l.topology="line-list",l.baseColor=t,l.blendMode=ae.ADD,l.castReflection=!1,o.geometry=a,o.material=l,n}}class Yf extends st{static format=ze.BIN;parseBuffer(e){try{const t={template:null,waylines:null},a=_b(new Uint8Array(e));for(const i in a){const n=a[i],l=new DOMParser().parseFromString(jf(n),"application/xml"),c={};this.parseNode(l,c);const f=i.replace("wpmz/","").split(".")[0];Object.assign(t,{[f]:c["#document"].kml.Document})}const r=new ls(t.waylines);this.data=r}catch(t){this.parserError(`KMZ parsing failed: ${t}`,-1)}}parseNode(e,t){const a=["Placemark","actionGroup","action"],r=e.nodeName.replace("wpml:","");if(!e.childNodes.length)t[r]=void 0;else{let i=null,n=!1;for(let o=0;o<e.childNodes.length;++o){const l=e.childNodes[o];if(l.nodeType==Node.TEXT_NODE){const c=l.nodeValue?.trim();c&&c.length>0&&(i=c)}else l.nodeType==Node.ELEMENT_NODE&&(n=!0)}if(i&&!n)t[r]=i;else if(n){a.includes(r)?t[r]?.length?t[r].push({}):t[r]=[{}]:t[r]={};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[r])?t[r].at(-1):t[r])}}else t[r]=void 0}}verification(){if(this.data)return!0;throw new Error("verify failed.")}}class Xf{_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 a=t.getSprite(e);if(a)return a}return null}async load(e,t,a){return(await new pt().load(e,t,a)).data}async loadGltf(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let a,r=e.substring(e.lastIndexOf(".")).toLowerCase(),i=new pt;r==".gltf"?a=await i.load(e,Dt,t):a=await i.load(e,eo,t);let n=a.data;return this._prefabPool.set(e,n),this._gltfPool.set(e,a.gltf),n}async loadObj(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let a,r=e.substring(e.lastIndexOf(".")).toLowerCase(),i=new pt;r==".obj"&&(a=await i.load(e,gf,t));let n=a.data;return this._prefabPool.set(e,n),n}async loadB3DM(e,t,a){if(this._prefabPool.has(e))return this._prefabPool.get(e);let n=(await new pt().load(e,co,t,a)).data;return this._prefabPool.set(e,n),n}async loadI3DM(e,t,a){if(this._prefabPool.has(e))return this._prefabPool.get(e);let n=(await new pt().load(e,Rf,t,a)).data;return this._prefabPool.set(e,n),n}async loadTexture(e,t,a){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new Va;return r.flipY=a,await r.load(e,t),this._texturePool.set(e,r),r}async loadTextureCount(e,t,a,r){return new Promise(async(i,n)=>{let o=0,l=[];t==0&&i(l);for(let c=0;c<t;c++){const f=e.shift();this.loadTexture(f,a,r).then(d=>{l.push(d),o++,o==t&&i(l)})}})}async loadBitmapTextures(e,t=5,a,r){let i=[],n=Math.floor(e.length/t)+1,o=Math.floor(e.length%t);for(let l=0;l<n;l++){let c=await this.loadTextureCount(e,l==n-1?o:t,a,r);i.push(...c)}return i}async loadHDRTexture(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let a=new ro;return a=await a.load(e,t),this._texturePool.set(e,a),a}async loadHDRTextureCube(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let a=new xs;return a=await a.load(e,t),this._texturePool.set(e,a),a}async loadLDRTextureCube(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let a=new Cs;return a=await a.load(e,t),this._texturePool.set(e,a),a}async loadTextureCubeMaps(e){let t=e[0];if(this._texturePool.has(t))return this._texturePool.get(t);let a=new to;return await a.load(e),this._texturePool.set(e[0],a),a}async loadTextureCubeStd(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let a=new to;return await a.loadStd(e),a}async loadJSON(e,t){return await new pt().loadJson(e,t).then(async a=>a).catch(a=>{console.log(a)})}async loadFont(e,t,a){let i=await new pt().load(e,za,t,a),n=i.data;return ii.addFontData(n.face,n.size,n),i.data}async loadAtlas(e,t){return(await new pt().load(e,Of,t,e)).data}async loadKMZ(e,t){return(await new pt().load(e,Yf,t)).data}normalTexture;maskTexture;whiteTexture;blackTexture;redTexture;blueTexture;greenTexture;yellowTexture;grayTexture;defaultSky;defaultGUITexture;defaultGUISprite;defaultMaterial;createTexture(e,t,a,r,i,n,o){let l=32,c=32,f=new Uint8Array(l*c*4);this.fillColor(f,e,t,a,r,i,n);let d=new wn;return d.name=o,d.create(16,16,f,!0),o&&this.addTexture(o,d),d}fillColor(e,t,a,r,i,n,o){for(let l=0;l<t;l++)for(let c=0;c<a;c++){let f=c*t+l;e[f*4+0]=r,e[f*4+1]=i,e[f*4+2]=n,e[f*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 Qf().generateBRDFLUTTexture(),a=t.name="BRDFLUT";this.addTexture(a,t),this.defaultSky=new xs,this.defaultSky.createFromTexture(128,this.blackTexture),me.getInstance().attached(this.defaultSky,this),me.getInstance().attached(t,this),me.getInstance().attached(this.normalTexture,this),me.getInstance().attached(this.maskTexture,this),me.getInstance().attached(this.whiteTexture,this),me.getInstance().attached(this.blackTexture,this),me.getInstance().attached(this.redTexture,this),me.getInstance().attached(this.blueTexture,this),me.getInstance().attached(this.greenTexture,this),me.getInstance().attached(this.yellowTexture,this),me.getInstance().attached(this.grayTexture,this),this.defaultGUITexture=new mr(this.whiteTexture),this.defaultGUISprite=new ri(this.defaultGUITexture),this.defaultGUISprite.trimSize.set(4,4),this.defaultMaterial=new ka}}class Hf extends Pe{_postList;init(e){this._postList=new Map}start(){}stop(){}onEnable(){this.activePost()}onDisable(){this.unActivePost()}activePost(){let e=this.transform.view3D,t=m.getRenderJob(e);this._postList.forEach(a=>{t.addPost(a)})}unActivePost(){let e=this.transform.view3D,t=m.getRenderJob(e);this._postList.forEach(a=>{t.removePost(a)})}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 a=this.transform.view3D;m.getRenderJob(a).removePost(t)}getPost(e){return this._postList.has(e)?this._postList.get(e):null}}const Bb="1.0.22";class m{static res;static inputSystem;static views;static _frameRateValue=0;static _frameRate=360;static _time=0;static _beforeRender;static _renderLoop;static _lateRender;static _requestAnimationFrameID=0;static get frameRate(){return this._frameRate}static set frameRate(e){this._frameRate=e,this._frameRateValue=1e3/e,e>=360&&(this._frameRateValue=0)}static get size(){return k.presentationSize}static get aspect(){return k.aspect}static get width(){return k.windowWidth}static get height(){return k.windowHeight}static setting={doublePrecision:!1,occlusionQuery:{enable:!0,debug:!1},pick:{enable:!0,mode:"bound",detail:"mesh"},render:{debug:!1,renderPassState:4,renderState_left:5,renderState_right:5,renderState_split:.5,quadScale:1,hdrExposure:1.5,debugQuad:-1,maxPointLight:1e3,maxDirectLight:4,maxSportLight:1e3,drawOpMin:0,drawOpMax:Number.MAX_SAFE_INTEGER,drawTrMin:0,drawTrMax:Number.MAX_SAFE_INTEGER,zPrePass:!1,useLogDepth:!1,useCompressGBuffer:!1,gi:!1,postProcessing:{bloom:{downSampleStep:3,downSampleBlurSize:9,downSampleBlurSigma:1,upSampleBlurSize:9,upSampleBlurSigma:1,luminanceThreshole:1,bloomIntensity:1,hdr:1},globalFog:{debug:!1,enable:!1,fogType:0,fogHeightScale:.1,start:400,end:10,density:.02,ins:.5,skyFactor:.5,skyRoughness:.4,overrideSkyFactor:.8,fogColor:new P(96/255,117/255,133/255,1),falloff:.7,rayLength:200,scatteringExponent:2.7,dirHeightLine:10},godRay:{blendColor:!0,rayMarchCount:16,scatteringExponent:5,intensity:.5},ssao:{enable:!1,radius:.15,bias:-.1,aoPower:2,debug:!0},outline:{enable:!1,strength:1,groupCount:4,outlinePixel:2,fadeOutlinePixel:4,textureScale:1,useAddMode:!1,debug:!0},taa:{enable:!1,jitterSeedCount:8,blendFactor:.1,sharpFactor:.6,sharpPreBlurFactor:.5,temporalJitterScale:.13,debug:!0},gtao:{enable:!1,darkFactor:1,maxDistance:5,maxPixel:50,rayMarchSegment:6,multiBounce:!1,usePosFloat32:!0,blendColor:!0,debug:!0},ssr:{enable:!1,pixelRatio:1,fadeEdgeRatio:.2,rayMarchRatio:.5,fadeDistanceMin:600,fadeDistanceMax:2e3,roughnessThreshold:.5,powDotRN:.2,mixThreshold:.1,debug:!0},fxaa:{enable:!1},depthOfView:{enable:!1,iterationCount:3,pixelOffset:1,near:150,far:300}}},shadow:{enable:!0,type:"HARD",pointShadowBias:5e-4,shadowSize:2048,pointShadowSize:1024,shadowSoft:.005,shadowBound:100,shadowBias:.05,needUpdate:!0,autoUpdate:!0,updateFrameRate:2,csmMargin:.1,csmScatteringExp:.7,csmAreaScale:.4,debug:!1},gi:{enable:!1,offsetX:0,offsetY:0,offsetZ:0,probeSpace:64,probeXCount:4,probeYCount:2,probeZCount:4,probeSize:32,probeSourceTextureSize:2048,octRTMaxSize:2048,octRTSideSize:16,maxDistance:64*1.73,normalBias:.25,depthSharpness:1,hysteresis:.98,lerpHysteresis:.01,irradianceChebyshevBias:.01,rayNumber:144,irradianceDistanceBias:32,indirectIntensity:1,ddgiGamma:2.2,bounceIntensity:.025,probeRoughness:1,realTimeGI:!1,debug:!1,autoRenderProbe:!1},sky:{type:"HDRSKY",sky:null,skyExposure:1,defaultFar:65536,defaultNear:1},light:{maxLight:4096},material:{materialChannelDebug:!1,materialDebug:!1},loader:{numConcurrent:20},reflectionSetting:{reflectionProbeMaxCount:8,reflectionProbeSize:256,width:256*6,height:8*256,enable:!0}};static renderJobs;static async init(e={}){console.log("Rings Version",Bb),window.isSecureContext||console.warn("WebGPU is only supported in secure contexts (HTTPS or localhost)"),this.setting={...this.setting,...e.engineSetting},await pe.init(E.allocCount,this.setting.doublePrecision),await k.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(),Ma.init(),oe.init(),vt.init(),It.init(),this.res=new Xf,this.res.initDefault(),this._beforeRender=e.beforeRender,this._renderLoop=e.renderLoop,this._lateRender=e.lateRender,this.inputSystem=new nl,this.inputSystem.initCanvas(k.canvas)}static startRenderJob(e){let t=new J0(e);return this.renderJobs.set(e,t),this.setting.pick.mode=="pixel"&&e.scene.getOrAddComponent(Hf).addPost(On),(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 a=performance.now();await new Promise(r=>{setTimeout(()=>{e+=performance.now()-a,r(!0)},this._frameRateValue-t)})}this._time=e}await this.updateFrame(e),this._requestAnimationFrameID=0,this.resume()}static async updateFrame(e){Fe.delta=e-Fe.time,Fe.time=e,Fe.frame+=1,pr.tick(Fe.delta);let t=this.views,a=0;for(a=0;a<t.length;a++){const n=t[a];n.scene.waitUpdate();let[o,l]=k.presentationSize;n.camera.viewPort.setTo(0,0,o,l)}this._beforeRender&&await this._beforeRender();for(const n of xe.componentsBeforeUpdateList){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];f.enable&&d(o)}}let r=k.device.createCommandEncoder();for(const n of xe.componentsComputeList){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];f.enable&&d(o,r)}}k.device.queue.submit([r.finish()]);for(const n of xe.componentsUpdateList){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];f.enable&&d(o)}}for(const n of xe.graphicComponent){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];o&&f.enable&&d(o)}}this._renderLoop&&await this._renderLoop(),pe.updateAllContinueTransform(0,E.useCount,16),oe.modelMatrixBindGroup.writeBuffer(E.useCount*16),this.renderJobs.forEach((n,o)=>{n.renderState||n.start(),n.renderFrame()});for(const n of xe.componentsLateUpdateList){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];f.enable&&d(o)}}this._lateRender&&await this._lateRender()}}let Ss=`
7765
+ `}async loadFontTextures(){let e=[],t=this.data;for(const a of t.fontPage){let r=this.baseUrl+a.file;await m.res.loadTexture(r,null,!0);let i=m.res.getTexture(r),n=new mr(i);e.push(n)}za.parseSprite(e,t),t.fontChar[" "]||za.insertSpaceChar(t,e[0])}static insertSpaceChar(e,t){let a=new ri,r=e.size*.5,i=e.lineHeight*.5;a.id=" ",a.offsetSize.set(0,0,e.size,e.size),a.trimSize.set(r,i),a.width=r,a.height=i,a.xadvance=0,a.xoffset=0,a.yoffset=0,a.guiTexture=t,a.uvRec.set(0,0,1e-6,1e-6),ii.addFnt(e.face,e.size,a.id,a)}static readLineProperty(e,t){e.trim().split(" ").forEach((a,r)=>{let i=a.split("=");if(i.length>1){let n=i[0],o=i[1];Object.prototype.hasOwnProperty.call(t,n)&&(o.indexOf('"')==-1?t[n]=parseFloat(i[1]):t[n]=o.replace('"',"").replace('"',""))}})}}function ab(s,e){let t=new ri;return t.id=s,t.offsetSize.set(0,0,e.width,e.height),t.trimSize.set(e.width,e.height),t.width=e.width,t.height=e.height,t.xadvance=0,t.xoffset=0,t.yoffset=0,t.guiTexture=new mr(e),t.uvRec.set(0,0,1,1),e.isVideoTexture||(e.flipY=!0),t}function Vf(s,e,t){let a=new ri;a.guiTexture=s,a.id=e,a.uvRec.copyFrom(t.textureRect),a.trimSize.x=t.textureRect.z,a.trimSize.y=t.textureRect.w,a.offsetSize.x=t.textureRectOffset.x,a.offsetSize.y=t.textureRectOffset.y,a.offsetSize.z=t.size.x,a.offsetSize.w=t.size.y,a.width=t.size.x,a.height=t.size.y;let r=1/s.width,i=1/s.height;a.uvRec.set(a.uvRec.x*r,a.uvRec.y*i,a.uvRec.z*r,a.uvRec.w*i);let n=.1;return t.border.x<=n&&t.border.y<=n&&t.border.z<=n&&t.border.x<=n?a.isSliced=!1:(a.borderSize.copyFrom(t.border),a.uvBorder.copyFrom(t.border),a.uvBorder.x-=t.textureRectOffset.x,a.uvBorder.y-=t.textureRectOffset.y,a.uvBorder.z=t.border.z-(t.size.x-t.textureRect.z-t.textureRectOffset.x),a.uvBorder.w=t.border.w-(t.size.y-t.textureRect.w-t.textureRectOffset.y),a.uvBorder.x/=t.textureRect.z,a.uvBorder.z/=t.textureRect.z,a.uvBorder.y/=t.textureRect.w,a.uvBorder.w/=t.textureRect.w,a.isSliced=!0),a}class Pf{_spriteMap=new Map;_spriteList=[];textureSize=new K;name;constructor(e){this.textureSize.set(e.x,e.y)}setTexture(e,t,a){let r=Vf(e,t,a);return this._spriteMap.set(r.id,r),this._spriteList.push(r),r}getSprite(e){return this._spriteMap.get(e)}get spriteList(){return this._spriteList}}class Of extends st{static format=ze.TEXT;_json;_texture;async parseString(e){this._json=JSON.parse(e);let t=this.userData.replace(".json",".png");this._texture=await m.res.loadTexture(t,null,!0),this.data={json:this._json,texture:this._texture},this.parseAtlas()}verification(){if(this.data)return!0;throw new Error("verify failed.")}parseAtlas(){let e=new Pf(this._json.size),t=new mr(this._texture),a=this._json.atlas;for(const r in a)e.setTexture(t,r,a[r]);m.res.addAtlas(this.baseUrl,e),this.data=e}}var Lt=Uint8Array,si=Uint16Array,rb=Int32Array,Lf=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]),Gf=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]),ib=new Lt([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),zf=function(s,e){for(var t=new si(31),a=0;a<31;++a)t[a]=e+=1<<s[a-1];for(var r=new rb(t[30]),a=1;a<30;++a)for(var i=t[a];i<t[a+1];++i)r[i]=i-t[a]<<5|a;return{b:t,r}},Jf=zf(Lf,2),Wf=Jf.b,sb=Jf.r;Wf[28]=258,sb[258]=28;for(var nb=zf(Gf,0),ob=nb.b,uo=new si(32768),Te=0;Te<32768;++Te){var ir=(Te&43690)>>1|(Te&21845)<<1;ir=(ir&52428)>>2|(ir&13107)<<2,ir=(ir&61680)>>4|(ir&3855)<<4,uo[Te]=((ir&65280)>>8|(ir&255)<<8)>>1}for(var Fi=(function(s,e,t){for(var a=s.length,r=0,i=new si(e);r<a;++r)s[r]&&++i[s[r]-1];var n=new si(e);for(r=1;r<e;++r)n[r]=n[r-1]+i[r-1]<<1;var o;if(t){o=new si(1<<e);var l=15-e;for(r=0;r<a;++r)if(s[r])for(var c=r<<4|s[r],f=e-s[r],d=n[s[r]-1]++<<f,h=d|(1<<f)-1;d<=h;++d)o[uo[d]>>l]=c}else for(o=new si(a),r=0;r<a;++r)s[r]&&(o[r]=uo[n[s[r]-1]++]>>15-s[r]);return o}),ki=new Lt(288),Te=0;Te<144;++Te)ki[Te]=8;for(var Te=144;Te<256;++Te)ki[Te]=9;for(var Te=256;Te<280;++Te)ki[Te]=7;for(var Te=280;Te<288;++Te)ki[Te]=8;for(var Zf=new Lt(32),Te=0;Te<32;++Te)Zf[Te]=5;var lb=Fi(ki,9,1),cb=Fi(Zf,5,1),bo=function(s){for(var e=s[0],t=1;t<s.length;++t)s[t]>e&&(e=s[t]);return e},sa=function(s,e,t){var a=e/8|0;return(s[a]|s[a+1]<<8)>>(e&7)&t},go=function(s,e){var t=e/8|0;return(s[t]|s[t+1]<<8|s[t+2]<<16)>>(e&7)},fb=function(s){return(s+7)/8|0},po=function(s,e,t){return(e==null||e<0)&&(e=0),(t==null||t>s.length)&&(t=s.length),new Lt(s.subarray(e,t))},db=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Ht=function(s,e,t){var a=new Error(e||db[s]);if(a.code=s,Error.captureStackTrace&&Error.captureStackTrace(a,Ht),!t)throw a;return a},hb=function(s,e,t,a){var r=s.length,i=a?a.length:0;if(!r||e.f&&!e.l)return t||new Lt(0);var n=!t,o=n||e.i!=2,l=e.i;n&&(t=new Lt(r*3));var c=function(Ft){var kt=t.length;if(Ft>kt){var Nt=new Lt(Math.max(kt*2,Ft));Nt.set(t),t=Nt}},f=e.f||0,d=e.p||0,h=e.b||0,b=e.l,p=e.d,g=e.m,A=e.n,D=r*8;do{if(!b){f=sa(s,d,1);var _=sa(s,d+1,3);if(d+=3,_)if(_==1)b=lb,p=cb,g=9,A=5;else if(_==2){var C=sa(s,d,31)+257,F=sa(s,d+10,15)+4,w=C+sa(s,d+5,31)+1;d+=14;for(var S=new Lt(w),M=new Lt(19),T=0;T<F;++T)M[ib[T]]=sa(s,d+T*3,7);d+=F*3;for(var Q=bo(M),L=(1<<Q)-1,X=Fi(M,Q,1),T=0;T<w;){var ie=X[sa(s,d,L)];d+=ie&15;var U=ie>>4;if(U<16)S[T++]=U;else{var q=0,be=0;for(U==16?(be=3+sa(s,d,3),d+=2,q=S[T-1]):U==17?(be=3+sa(s,d,7),d+=3):U==18&&(be=11+sa(s,d,127),d+=7);be--;)S[T++]=q}}var Ue=S.subarray(0,C),Z=S.subarray(C);g=bo(Ue),A=bo(Z),b=Fi(Ue,g,1),p=Fi(Z,A,1)}else Ht(1);else{var U=fb(d)+4,v=s[U-4]|s[U-3]<<8,x=U+v;if(x>r){l&&Ht(0);break}o&&c(h+v),t.set(s.subarray(U,x),h),e.b=h+=v,e.p=d=x*8,e.f=f;continue}if(d>D){l&&Ht(0);break}}o&&c(h+131072);for(var de=(1<<g)-1,ce=(1<<A)-1,De=d;;De=d){var q=b[go(s,d)&de],_e=q>>4;if(d+=q&15,d>D){l&&Ht(0);break}if(q||Ht(2),_e<256)t[h++]=_e;else if(_e==256){De=d,b=null;break}else{var Ne=_e-254;if(_e>264){var T=_e-257,we=Lf[T];Ne=sa(s,d,(1<<we)-1)+Wf[T],d+=we}var Ce=p[go(s,d)&ce],Me=Ce>>4;Ce||Ht(3),d+=Ce&15;var Z=ob[Me];if(Me>3){var we=Gf[Me];Z+=go(s,d)&(1<<we)-1,d+=we}if(d>D){l&&Ht(0);break}o&&c(h+131072);var ct=h+Ne;if(h<Z){var ga=i-Z,Mt=Math.min(Z,ct);for(ga+h<0&&Ht(3);h<Mt;++h)t[h]=a[ga+h]}for(;h<ct;++h)t[h]=t[h-Z]}}e.l=b,e.p=De,e.b=h,e.f=f,b&&(f=1,e.m=g,e.d=p,e.n=A)}while(!f);return h!=t.length&&n?po(t,0,h):t.subarray(0,h)},ub=new Lt(0),ya=function(s,e){return s[e]|s[e+1]<<8},na=function(s,e){return(s[e]|s[e+1]<<8|s[e+2]<<16|s[e+3]<<24)>>>0},mo=function(s,e){return na(s,e)+na(s,e+4)*4294967296};function bb(s,e){return hb(s,{i:2},e&&e.out,e&&e.dictionary)}var Ao=typeof TextDecoder<"u"&&new TextDecoder,gb=0;try{Ao.decode(ub,{stream:!0}),gb=1}catch{}var pb=function(s){for(var e="",t=0;;){var a=s[t++],r=(a>127)+(a>223)+(a>239);if(t+r>s.length)return{s:e,r:po(s,t-1)};r?r==3?(a=((a&15)<<18|(s[t++]&63)<<12|(s[t++]&63)<<6|s[t++]&63)-65536,e+=String.fromCharCode(55296|a>>10,56320|a&1023)):r&1?e+=String.fromCharCode((a&31)<<6|s[t++]&63):e+=String.fromCharCode((a&15)<<12|(s[t++]&63)<<6|s[t++]&63):e+=String.fromCharCode(a)}};function jf(s,e){if(e){for(var t="",a=0;a<s.length;a+=16384)t+=String.fromCharCode.apply(null,s.subarray(a,a+16384));return t}else{if(Ao)return Ao.decode(s);var r=pb(s),i=r.s,t=r.r;return t.length&&Ht(8),i}}var mb=function(s,e){return e+30+ya(s,e+26)+ya(s,e+28)},Ab=function(s,e,t){var a=ya(s,e+28),r=jf(s.subarray(e+46,e+46+a),!(ya(s,e+8)&2048)),i=e+46+a,n=na(s,e+20),o=t&&n==4294967295?Db(s,i):[n,na(s,e+24),na(s,e+42)],l=o[0],c=o[1],f=o[2];return[ya(s,e+10),l,c,r,i+ya(s,e+30)+ya(s,e+32),f]},Db=function(s,e){for(;ya(s,e)!=1;e+=4+ya(s,e+2));return[mo(s,e+12),mo(s,e+4),mo(s,e+20)]};function _b(s,e){for(var t={},a=s.length-22;na(s,a)!=101010256;--a)(!a||s.length-a>65558)&&Ht(13);var r=ya(s,a+8);if(!r)return{};var i=na(s,a+16),n=i==4294967295||r==65535;if(n){var o=na(s,a-12);n=na(s,o)==101075792,n&&(r=na(s,o+32),i=na(s,o+48))}for(var l=0;l<r;++l){var c=Ab(s,i,n),f=c[0],d=c[1],h=c[2],b=c[3],p=c[4],g=c[5],A=mb(s,g);i=p,f?f==8?t[b]=bb(s.subarray(A,A+d),{out:new Lt(h)}):Ht(14,"unknown compression type "+f):t[b]=po(s,A,A+d)}return t}class nt extends mt{constructor(){super(),this.shader=new Oi,this.baseMap=m.res.whiteTexture}set baseMap(e){this.shader.setTexture("baseMap",e)}get baseMap(){return this.shader.getTexture("baseMap")}set baseColor(e){this.shader.setUniformColor("baseColor",e)}get baseColor(){return this.shader.getUniformColor("baseColor")}set envMap(e){}set shadowMap(e){}}class Rr extends Ee{shape_vertices=[];shape_indices=[];radius;widthSegments;heightSegments;phiStart;phiLength;thetaStart;thetaLength;constructor(e,t,a,r,i,n,o){super(),this.radius=e,this.widthSegments=t,this.heightSegments=a,this.phiStart=r,this.phiLength=i,this.thetaStart=n,this.thetaLength=o,this.buildGeometry()}buildGeometry(){var e,t,a=0;let r=this.heightSegments,i=this.widthSegments,n=this.radius;var o=(r+1)*(i+1);let l=new Float32Array(o*3),c=new Float32Array(o*3),f=new Float32Array(o*2),d=new Uint16Array(i*r*2*3),h=0,b=0,p=0;for(t=0;t<=r;++t){var g=Math.PI*t/r,A=n*Math.cos(g),D=n*Math.sin(g);for(e=0;e<=i;++e){var _=2*Math.PI*e/i,U=D*Math.cos(_),v=D*Math.sin(_),x=1/Math.sqrt(U*U+A*A+v*v);if(l[h++]=U,l[h++]=A,l[h++]=v,c[b++]=U*x,c[b++]=A*x,c[b++]=v*x,f[p++]=e/i,f[p++]=t/r,e>0&&t>0){var C=(i+1)*t+e,F=(i+1)*t+e-1,w=(i+1)*(t-1)+e-1,S=(i+1)*(t-1)+e;t==r?(d[a++]=C,d[a++]=w,d[a++]=S):t==1?(d[a++]=C,d[a++]=F,d[a++]=w):(d[a++]=C,d[a++]=F,d[a++]=w,d[a++]=C,d[a++]=w,d[a++]=S)}}}this.setIndices(d),this.setAttribute(V.position,l),this.setAttribute(V.normal,c),this.setAttribute(V.uv,f),this.setAttribute(V.TEXCOORD_1,f),this.addSubGeometry({indexStart:0,indexCount:d.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0}),this.bounds=new ge(u.ZERO,new u(this.radius*2,this.radius*2,this.radius*2))}}class os extends ee{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 u(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),os.register3DRepresentation)this.marker=os.register3DRepresentation(this),this.marker&&this.addChild(this.marker);else{this.marker=new ee;const e=this.marker.addComponent($);e.geometry=new Rr(.1,32,16),e.material=new nt,e.material.baseColor=this.positionValid?new P(0,1,0,1):new P(1,0,0,1),this.addChild(this.marker),this.marker.name="WayPoint3DMarker"}}}class ls extends ee{static register3DRepresentation=null;line;constructor(e){super(),this.parseWayLineFile(e),this.setup3DRepresentation()}parseWayLineFile(e){for(const t of e.Folder.Placemark){const a=new os(t);this.addChild(a)}this.entityChildren=this.entityChildren.sort((t,a)=>t.positionIndex-a.positionIndex)}setup3DRepresentation(){this.line&&(this.removeChild(this.line),this.line=null),ls.register3DRepresentation?(this.line=ls.register3DRepresentation(this),this.line&&this.addChild(this.line)):(this.line=this.createMultiLine(this.entityChildren.map(e=>e.localPosition),new P(1,1,1,1)),this.addChild(this.line),this.line.name="WayLines3DLine")}createMultiLine(e,t){if(e.length<2)return null;const a=new Ee,r=new Float32Array(e.length*3);for(let c=0;c<e.length;c++)r[c*3]=e[c].x,r[c*3+1]=e[c].y,r[c*3+2]=e[c].z;const i=new Uint16Array((e.length-1)*2);for(let c=0;c<e.length-1;c++)i[c*2]=c,i[c*2+1]=c+1;a.setIndices(i),a.setAttribute(V.position,r),a.addSubGeometry({indexStart:0,indexCount:i.length,vertexStart:0,vertexCount:0,firstStart:0,index:0,topology:0});const n=new ee,o=n.addComponent($),l=new nt;return l.topology="line-list",l.baseColor=t,l.blendMode=ae.ADD,l.castReflection=!1,o.geometry=a,o.material=l,n}}class Yf extends st{static format=ze.BIN;parseBuffer(e){try{const t={template:null,waylines:null},a=_b(new Uint8Array(e));for(const i in a){const n=a[i],l=new DOMParser().parseFromString(jf(n),"application/xml"),c={};this.parseNode(l,c);const f=i.replace("wpmz/","").split(".")[0];Object.assign(t,{[f]:c["#document"].kml.Document})}const r=new ls(t.waylines);this.data=r}catch(t){this.parserError(`KMZ parsing failed: ${t}`,-1)}}parseNode(e,t){const a=["Placemark","actionGroup","action"],r=e.nodeName.replace("wpml:","");if(!e.childNodes.length)t[r]=void 0;else{let i=null,n=!1;for(let o=0;o<e.childNodes.length;++o){const l=e.childNodes[o];if(l.nodeType==Node.TEXT_NODE){const c=l.nodeValue?.trim();c&&c.length>0&&(i=c)}else l.nodeType==Node.ELEMENT_NODE&&(n=!0)}if(i&&!n)t[r]=i;else if(n){a.includes(r)?t[r]?.length?t[r].push({}):t[r]=[{}]:t[r]={};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[r])?t[r].at(-1):t[r])}}else t[r]=void 0}}verification(){if(this.data)return!0;throw new Error("verify failed.")}}class Xf{_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 a=t.getSprite(e);if(a)return a}return null}async load(e,t,a){return(await new pt().load(e,t,a)).data}async loadGltf(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let a,r=e.substring(e.lastIndexOf(".")).toLowerCase(),i=new pt;r==".gltf"?a=await i.load(e,Dt,t):a=await i.load(e,eo,t);let n=a.data;return this._prefabPool.set(e,n),this._gltfPool.set(e,a.gltf),n}async loadObj(e,t){if(this._prefabPool.has(e))return this._prefabPool.get(e);let a,r=e.substring(e.lastIndexOf(".")).toLowerCase(),i=new pt;r==".obj"&&(a=await i.load(e,gf,t));let n=a.data;return this._prefabPool.set(e,n),n}async loadB3DM(e,t,a){if(this._prefabPool.has(e))return this._prefabPool.get(e);let n=(await new pt().load(e,co,t,a)).data;return this._prefabPool.set(e,n),n}async loadI3DM(e,t,a){if(this._prefabPool.has(e))return this._prefabPool.get(e);let n=(await new pt().load(e,Rf,t,a)).data;return this._prefabPool.set(e,n),n}async loadTexture(e,t,a){if(this._texturePool.has(e))return this._texturePool.get(e);let r=new Va;r.flipY=a;try{await r.load(e,t)}catch(i){return console.error(`Failed to load texture: ${e}`,i),null}return this._texturePool.set(e,r),r}async loadTextureCount(e,t,a,r){return new Promise(async(i,n)=>{let o=0,l=[];t==0&&i(l);for(let c=0;c<t;c++){const f=e.shift();this.loadTexture(f,a,r).then(d=>{l.push(d),o++,o==t&&i(l)})}})}async loadBitmapTextures(e,t=5,a,r){let i=[],n=Math.floor(e.length/t)+1,o=Math.floor(e.length%t);for(let l=0;l<n;l++){let c=await this.loadTextureCount(e,l==n-1?o:t,a,r);i.push(...c)}return i}async loadHDRTexture(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let a=new ro;return a=await a.load(e,t),this._texturePool.set(e,a),a}async loadHDRTextureCube(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let a=new xs;return a=await a.load(e,t),this._texturePool.set(e,a),a}async loadLDRTextureCube(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let a=new Cs;return a=await a.load(e,t),this._texturePool.set(e,a),a}async loadTextureCubeMaps(e){let t=e[0];if(this._texturePool.has(t))return this._texturePool.get(t);let a=new to;return await a.load(e),this._texturePool.set(e[0],a),a}async loadTextureCubeStd(e,t){if(this._texturePool.has(e))return this._texturePool.get(e);let a=new to;return await a.loadStd(e),a}async loadJSON(e,t){return await new pt().loadJson(e,t).then(async a=>a).catch(a=>{console.log(a)})}async loadFont(e,t,a){let i=await new pt().load(e,za,t,a),n=i.data;return ii.addFontData(n.face,n.size,n),i.data}async loadAtlas(e,t){return(await new pt().load(e,Of,t,e)).data}async loadKMZ(e,t){return(await new pt().load(e,Yf,t)).data}normalTexture;maskTexture;whiteTexture;blackTexture;redTexture;blueTexture;greenTexture;yellowTexture;grayTexture;defaultSky;defaultGUITexture;defaultGUISprite;defaultMaterial;createTexture(e,t,a,r,i,n,o){let l=32,c=32,f=new Uint8Array(l*c*4);this.fillColor(f,e,t,a,r,i,n);let d=new wn;return d.name=o,d.create(16,16,f,!0),o&&this.addTexture(o,d),d}fillColor(e,t,a,r,i,n,o){for(let l=0;l<t;l++)for(let c=0;c<a;c++){let f=c*t+l;e[f*4+0]=r,e[f*4+1]=i,e[f*4+2]=n,e[f*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 Qf().generateBRDFLUTTexture(),a=t.name="BRDFLUT";this.addTexture(a,t),this.defaultSky=new xs,this.defaultSky.createFromTexture(128,this.blackTexture),me.getInstance().attached(this.defaultSky,this),me.getInstance().attached(t,this),me.getInstance().attached(this.normalTexture,this),me.getInstance().attached(this.maskTexture,this),me.getInstance().attached(this.whiteTexture,this),me.getInstance().attached(this.blackTexture,this),me.getInstance().attached(this.redTexture,this),me.getInstance().attached(this.blueTexture,this),me.getInstance().attached(this.greenTexture,this),me.getInstance().attached(this.yellowTexture,this),me.getInstance().attached(this.grayTexture,this),this.defaultGUITexture=new mr(this.whiteTexture),this.defaultGUISprite=new ri(this.defaultGUITexture),this.defaultGUISprite.trimSize.set(4,4),this.defaultMaterial=new ka}}class Hf extends Pe{_postList;init(e){this._postList=new Map}start(){}stop(){}onEnable(){this.activePost()}onDisable(){this.unActivePost()}activePost(){let e=this.transform.view3D,t=m.getRenderJob(e);this._postList.forEach(a=>{t.addPost(a)})}unActivePost(){let e=this.transform.view3D,t=m.getRenderJob(e);this._postList.forEach(a=>{t.removePost(a)})}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 a=this.transform.view3D;m.getRenderJob(a).removePost(t)}getPost(e){return this._postList.has(e)?this._postList.get(e):null}}const Bb="1.0.23";class m{static res;static inputSystem;static views;static _frameRateValue=0;static _frameRate=360;static _time=0;static _beforeRender;static _renderLoop;static _lateRender;static _requestAnimationFrameID=0;static get frameRate(){return this._frameRate}static set frameRate(e){this._frameRate=e,this._frameRateValue=1e3/e,e>=360&&(this._frameRateValue=0)}static get size(){return k.presentationSize}static get aspect(){return k.aspect}static get width(){return k.windowWidth}static get height(){return k.windowHeight}static setting={doublePrecision:!1,occlusionQuery:{enable:!0,debug:!1},pick:{enable:!0,mode:"bound",detail:"mesh"},render:{debug:!1,renderPassState:4,renderState_left:5,renderState_right:5,renderState_split:.5,quadScale:1,hdrExposure:1.5,debugQuad:-1,maxPointLight:1e3,maxDirectLight:4,maxSportLight:1e3,drawOpMin:0,drawOpMax:Number.MAX_SAFE_INTEGER,drawTrMin:0,drawTrMax:Number.MAX_SAFE_INTEGER,zPrePass:!1,useLogDepth:!1,useCompressGBuffer:!1,gi:!1,postProcessing:{bloom:{downSampleStep:3,downSampleBlurSize:9,downSampleBlurSigma:1,upSampleBlurSize:9,upSampleBlurSigma:1,luminanceThreshole:1,bloomIntensity:1,hdr:1},globalFog:{debug:!1,enable:!1,fogType:0,fogHeightScale:.1,start:400,end:10,density:.02,ins:.5,skyFactor:.5,skyRoughness:.4,overrideSkyFactor:.8,fogColor:new P(96/255,117/255,133/255,1),falloff:.7,rayLength:200,scatteringExponent:2.7,dirHeightLine:10},godRay:{blendColor:!0,rayMarchCount:16,scatteringExponent:5,intensity:.5},ssao:{enable:!1,radius:.15,bias:-.1,aoPower:2,debug:!0},outline:{enable:!1,strength:1,groupCount:4,outlinePixel:2,fadeOutlinePixel:4,textureScale:1,useAddMode:!1,debug:!0},taa:{enable:!1,jitterSeedCount:8,blendFactor:.1,sharpFactor:.6,sharpPreBlurFactor:.5,temporalJitterScale:.13,debug:!0},gtao:{enable:!1,darkFactor:1,maxDistance:5,maxPixel:50,rayMarchSegment:6,multiBounce:!1,usePosFloat32:!0,blendColor:!0,debug:!0},ssr:{enable:!1,pixelRatio:1,fadeEdgeRatio:.2,rayMarchRatio:.5,fadeDistanceMin:600,fadeDistanceMax:2e3,roughnessThreshold:.5,powDotRN:.2,mixThreshold:.1,debug:!0},fxaa:{enable:!1},depthOfView:{enable:!1,iterationCount:3,pixelOffset:1,near:150,far:300}}},shadow:{enable:!0,type:"HARD",pointShadowBias:5e-4,shadowSize:2048,pointShadowSize:1024,shadowSoft:.005,shadowBound:100,shadowBias:.05,needUpdate:!0,autoUpdate:!0,updateFrameRate:2,csmMargin:.1,csmScatteringExp:.7,csmAreaScale:.4,debug:!1},gi:{enable:!1,offsetX:0,offsetY:0,offsetZ:0,probeSpace:64,probeXCount:4,probeYCount:2,probeZCount:4,probeSize:32,probeSourceTextureSize:2048,octRTMaxSize:2048,octRTSideSize:16,maxDistance:64*1.73,normalBias:.25,depthSharpness:1,hysteresis:.98,lerpHysteresis:.01,irradianceChebyshevBias:.01,rayNumber:144,irradianceDistanceBias:32,indirectIntensity:1,ddgiGamma:2.2,bounceIntensity:.025,probeRoughness:1,realTimeGI:!1,debug:!1,autoRenderProbe:!1},sky:{type:"HDRSKY",sky:null,skyExposure:1,defaultFar:65536,defaultNear:1},light:{maxLight:4096},material:{materialChannelDebug:!1,materialDebug:!1},loader:{numConcurrent:20},reflectionSetting:{reflectionProbeMaxCount:8,reflectionProbeSize:256,width:256*6,height:8*256,enable:!0}};static renderJobs;static async init(e={}){console.log("Rings Version",Bb),window.isSecureContext||console.warn("WebGPU is only supported in secure contexts (HTTPS or localhost)"),this.setting={...this.setting,...e.engineSetting},await pe.init(E.allocCount,this.setting.doublePrecision),await k.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(),Ma.init(),oe.init(),vt.init(),It.init(),this.res=new Xf,this.res.initDefault(),this._beforeRender=e.beforeRender,this._renderLoop=e.renderLoop,this._lateRender=e.lateRender,this.inputSystem=new nl,this.inputSystem.initCanvas(k.canvas)}static startRenderJob(e){let t=new J0(e);return this.renderJobs.set(e,t),this.setting.pick.mode=="pixel"&&e.scene.getOrAddComponent(Hf).addPost(On),(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 a=performance.now();await new Promise(r=>{setTimeout(()=>{e+=performance.now()-a,r(!0)},this._frameRateValue-t)})}this._time=e}await this.updateFrame(e),this._requestAnimationFrameID=0,this.resume()}static async updateFrame(e){Fe.delta=e-Fe.time,Fe.time=e,Fe.frame+=1,pr.tick(Fe.delta);let t=this.views,a=0;for(a=0;a<t.length;a++){const n=t[a];n.scene.waitUpdate();let[o,l]=k.presentationSize;n.camera.viewPort.setTo(0,0,o,l)}this._beforeRender&&await this._beforeRender();for(const n of xe.componentsBeforeUpdateList){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];f.enable&&d(o)}}let r=k.device.createCommandEncoder();for(const n of xe.componentsComputeList){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];f.enable&&d(o,r)}}k.device.queue.submit([r.finish()]);for(const n of xe.componentsUpdateList){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];f.enable&&d(o)}}for(const n of xe.graphicComponent){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];o&&f.enable&&d(o)}}this._renderLoop&&await this._renderLoop(),pe.updateAllContinueTransform(0,E.useCount,16),oe.modelMatrixBindGroup.writeBuffer(E.useCount*16),this.renderJobs.forEach((n,o)=>{n.renderState||n.start(),n.renderFrame()});for(const n of xe.componentsLateUpdateList){let o=n[0],l=n[1];for(const c of l){let f=c[0],d=c[1];f.enable&&d(o)}}this._lateRender&&await this._lateRender()}}let Ss=`
7766
7766
  struct BloomCfg{
7767
7767
  downSampleStep: f32,
7768
7768
  downSampleBlurSize: f32,