endset_three_editor 0.10.35 → 0.10.36

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.
@@ -135,7 +135,7 @@
135
135
  `,i.setAttribute("data-item-code",s.code||""),i.innerHTML=`
136
136
  <span class="item-label" style="flex-shrink:0;letter-spacing:0.02em;color:#8cc8ff;">${this.escapeHtml(s.label)}</span>
137
137
  <span class="item-value" style="font-weight:700;color:#ffffff;text-shadow:0 0 0.62em rgba(0, 200, 255, 0.40);text-align:right;word-break:break-all;">${this.escapeHtml(s.value)}${s.unit?`<span style="font-size:0.85em;margin-left:0.15em;color:#8cc8ff;">${this.escapeHtml(s.unit)}</span>`:""}</span>
138
- `,e.appendChild(i)})}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}attachTo(e){this.attachedObject&&this.attachedObject!==e&&this.detach();const t=new O.Vector3;e.getWorldPosition(t);const i=new O.Box3().setFromObject(e).max.y-t.y+this.options.offsetY;this.css2dObject||(this.css2dObject=new gi(this.container),this.css2dObject.name=`DataPanel_${e.name||e.uuid}`,this.css2dObject.center.set(.5,1)),this.css2dObject.position.set(this.options.offsetX,i,this.options.offsetZ??0),e.add(this.css2dObject),this.attachedObject=e}detach(){this.css2dObject&&this.attachedObject&&this.attachedObject.remove(this.css2dObject),this.attachedObject=null}show(){this._visible=!0,this.css2dObject&&(this.css2dObject.visible=!0)}hide(){this._visible=!1,this.css2dObject&&(this.css2dObject.visible=!1)}get visible(){return this._visible}set visible(e){e?this.show():this.hide()}setTitle(e){var s;this.options.title=e;const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-title]");e?t?t.textContent=e:this.rebuildPanel():t&&t.remove()}getTitle(){return this.options.title||""}setItems(e){var s;this.options.items=[...e];const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}getItems(){return[...this.options.items||[]]}addItem(e){var s;this.options.items.push(e);const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}removeItem(e){var s;this.options.items=this.options.items.filter(n=>n.label!==e);const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}updateItem(e,t,s){var i;const n=this.options.items.find(o=>o.label===e);if(n){n.value=t,s!==void 0&&(n.unit=s);const o=(i=this.container)==null?void 0:i.querySelector("[data-panel-list]");o&&this.renderItems(o,this.options.items)}}updateItemByCode(e,t){var n;const s=this.options.items.find(i=>i.code===e);if(s){s.value=t;const i=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");i&&this.renderItems(i,this.options.items)}}clearItems(){var t;this.options.items=[];const e=(t=this.container)==null?void 0:t.querySelector("[data-panel-list]");e&&this.renderItems(e,[])}rebuildPanel(){const e=this._visible,t=this.attachedObject;this.css2dObject&&this.attachedObject&&this.attachedObject.remove(this.css2dObject),this.buildPanel(),t&&(this.attachedObject=t,t.add(this.css2dObject),e||this.hide())}updateOptions(e){this.options={...this.options,...e},this.rebuildPanel()}getOffsetY(){return this.options.offsetY??.1}setOffsetY(e){if(this.options.offsetY=e,this.css2dObject&&this.attachedObject){const t=new O.Vector3;this.attachedObject.getWorldPosition(t);const n=new O.Box3().setFromObject(this.attachedObject).max.y-t.y;this.css2dObject.position.set(this.options.offsetX??0,n+e,this.options.offsetZ??0)}}getOffsetX(){return this.options.offsetX??0}setOffsetX(e){this.options.offsetX=e,this.css2dObject&&this.attachedObject&&(this.css2dObject.position.x=e)}getOffsetZ(){return this.options.offsetZ??0}setOffsetZ(e){this.options.offsetZ=e,this.css2dObject&&this.attachedObject&&(this.css2dObject.position.z=e)}getWidth(){return this.options.width||"20em"}getFontSize(){return this.options.fontSize||"0.85em"}setWidth(e){this.options.width=e,this.container&&(this.container.style.width=e)}setFontSize(e){if(this.options.fontSize=e,this.container){this.container.style.fontSize=e;const t=this.container.querySelector("[data-panel-title]");t&&(t.style.fontSize=`calc(${e} + 0.15em)`)}}getElement(){return this.container}dispose(){var e;this.detach(),(e=this.container)!=null&&e.parentNode&&this.container.parentNode.removeChild(this.container),this.css2dObject=null,this.container=null,this.attachedObject=null}};Te(He,"_breathInjected",!1);let Ke=He;const At=new WeakMap;function Wn(r,e){const t=a.toRaw(r);At.set(t,e),t.userData._hasDataPanel=!0}function je(r){return At.get(a.toRaw(r))||null}function zt(r){const e=a.toRaw(r),t=At.get(e);t&&(t.dispose(),At.delete(e)),e.userData._hasDataPanel=void 0}let $=null;function qn(r){return $?($.domElement.parentNode!==r&&r.appendChild($.domElement),$):($=new yi,$.setSize(r.clientWidth,r.clientHeight),$.domElement.style.position="absolute",$.domElement.style.top="0",$.domElement.style.left="0",$.domElement.style.pointerEvents="none",r.appendChild($.domElement),$)}function Di(){return $}function Xn(r,e){$&&$.render(r,e)}function Yn(r,e){$&&$.setSize(r,e)}function Kn(){$&&($.domElement.parentNode&&$.domElement.parentNode.removeChild($.domElement),$=null)}function Ni(){const r=new O.Scene;r.position.y=-3.5;const e=new O.BoxGeometry;e.deleteAttribute("uv");const t=new O.MeshStandardMaterial({side:O.BackSide}),s=new O.PointLight(16777215,900,28,2);s.position.set(.418,16.199,.3),r.add(s);const n=new O.Mesh(e,t);n.position.set(-.757,13.219,.717),n.scale.set(31.713,28.305,28.591),r.add(n);const i=new O.MeshStandardMaterial,o=new O.InstancedMesh(e,i,6),l=new O.Object3D;l.position.set(-10.906,2.009,1.846),l.rotation.set(0,-.195,0),l.scale.set(2.328,7.905,4.651),l.updateMatrix(),o.setMatrixAt(0,l.matrix),l.position.set(-5.607,-.754,-.758),l.rotation.set(0,.994,0),l.scale.set(1.97,1.534,3.955),l.updateMatrix(),o.setMatrixAt(1,l.matrix),l.position.set(6.167,.857,7.803),l.rotation.set(0,.561,0),l.scale.set(3.927,6.285,3.687),l.updateMatrix(),o.setMatrixAt(2,l.matrix),l.position.set(-2.017,.018,6.124),l.rotation.set(0,.333,0),l.scale.set(2.002,4.566,2.064),l.updateMatrix(),o.setMatrixAt(3,l.matrix),l.position.set(2.291,-.756,-2.621),l.rotation.set(0,-.286,0),l.scale.set(1.546,1.552,1.496),l.updateMatrix(),o.setMatrixAt(4,l.matrix),l.position.set(-2.193,-.369,-5.547),l.rotation.set(0,.516,0),l.scale.set(3.875,3.487,2.986),l.updateMatrix(),o.setMatrixAt(5,l.matrix),o.instanceMatrix.needsUpdate=!0,r.add(o);function u(m){return new O.MeshLambertMaterial({color:0,emissive:16777215,emissiveIntensity:m})}const d=new O.Mesh(e,u(50));d.position.set(-16.116,14.37,8.208),d.scale.set(.1,2.428,2.739),r.add(d);const p=new O.Mesh(e,u(50));p.position.set(-16.109,18.021,-8.207),p.scale.set(.1,2.425,2.751),r.add(p);const f=new O.Mesh(e,u(17));f.position.set(14.904,12.198,-1.832),f.scale.set(.15,4.265,6.331),r.add(f);const g=new O.Mesh(e,u(43));g.position.set(-.462,8.89,14.52),g.scale.set(4.38,5.441,.088),r.add(g);const y=new O.Mesh(e,u(20));y.position.set(3.235,11.486,-12.541),y.scale.set(2.5,2,.1),r.add(y);const x=new O.Mesh(e,u(100));return x.position.set(0,20,0),x.scale.set(1,.1,1),r.add(x),r}function ut(r){try{const e=new O.PMREMGenerator(r),t=Ni(),s=e.fromScene(t).texture;return t.traverse(n=>{if(n.isMesh){const i=n,o=Array.isArray(i.material)?i.material:[i.material];for(const l of o)l&&l.dispose()}}),e.dispose(),s}catch(e){return console.error("环境贴图生成失败:",e),null}}const En={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class qe{constructor(){this.textureUtils=null,this.pluginCallbacks=[],this.register(function(e){return new Fi(e)}),this.register(function(e){return new Ui(e)}),this.register(function(e){return new qi(e)}),this.register(function(e){return new Xi(e)}),this.register(function(e){return new Yi(e)}),this.register(function(e){return new Ki(e)}),this.register(function(e){return new Gi(e)}),this.register(function(e){return new zi(e)}),this.register(function(e){return new Wi(e)}),this.register(function(e){return new Zi(e)}),this.register(function(e){return new Qi(e)}),this.register(function(e){return new Ji(e)}),this.register(function(e){return new _i(e)}),this.register(function(e){return new $i(e)})}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}setTextureUtils(e){return this.textureUtils=e,this}parse(e,t,s,n){const i=new ji,o=[];for(let l=0,u=this.pluginCallbacks.length;l<u;l++)o.push(this.pluginCallbacks[l](i));i.setPlugins(o),i.setTextureUtils(this.textureUtils),i.writeAsync(e,t,n).catch(s)}parseAsync(e,t){const s=this;return new Promise(function(n,i){s.parse(e,n,i,t)})}}const z={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,ARRAY_BUFFER:34962,ELEMENT_ARRAY_BUFFER:34963,NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987,CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},Tt="KHR_mesh_quantization",le={};le[c.NearestFilter]=z.NEAREST;le[c.NearestMipmapNearestFilter]=z.NEAREST_MIPMAP_NEAREST;le[c.NearestMipmapLinearFilter]=z.NEAREST_MIPMAP_LINEAR;le[c.LinearFilter]=z.LINEAR;le[c.LinearMipmapNearestFilter]=z.LINEAR_MIPMAP_NEAREST;le[c.LinearMipmapLinearFilter]=z.LINEAR_MIPMAP_LINEAR;le[c.ClampToEdgeWrapping]=z.CLAMP_TO_EDGE;le[c.RepeatWrapping]=z.REPEAT;le[c.MirroredRepeatWrapping]=z.MIRRORED_REPEAT;const Tn={scale:"scale",position:"translation",quaternion:"rotation",morphTargetInfluences:"weights"},Si=new c.Color,Dn=12,Oi=1179937895,Ri=2,Nn=8,Pi=1313821514,Li=5130562;function ye(r,e){return r.length===e.length&&r.every(function(t,s){return t===e[s]})}function ki(r){return new TextEncoder().encode(r).buffer}function Vi(r){return ye(r.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Hi(r,e,t){const s={min:new Array(r.itemSize).fill(Number.POSITIVE_INFINITY),max:new Array(r.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let n=e;n<e+t;n++)for(let i=0;i<r.itemSize;i++){let o;r.itemSize>4?o=r.array[n*r.itemSize+i]:(i===0?o=r.getX(n):i===1?o=r.getY(n):i===2?o=r.getZ(n):i===3&&(o=r.getW(n)),r.normalized===!0&&(o=c.MathUtils.normalize(o,r.array))),s.min[i]=Math.min(s.min[i],o),s.max[i]=Math.max(s.max[i],o)}return s}function Zn(r){return Math.ceil(r/4)*4}function Dt(r,e=0){const t=Zn(r.byteLength);if(t!==r.byteLength){const s=new Uint8Array(t);if(s.set(new Uint8Array(r)),e!==0)for(let n=r.byteLength;n<t;n++)s[n]=e;return s.buffer}return r}function Sn(){return typeof document>"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function Bi(r,e){if(typeof OffscreenCanvas<"u"&&r instanceof OffscreenCanvas){let t;return e==="image/jpeg"?t=.92:e==="image/webp"&&(t=.8),r.convertToBlob({type:e,quality:t})}else return new Promise(t=>r.toBlob(t,e))}class ji{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:"2.0",generator:"THREE.GLTFExporter r"+c.REVISION}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map},this.textureUtils=null}setPlugins(e){this.plugins=e}setTextureUtils(e){this.textureUtils=e}async writeAsync(e,t,s={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1},s),this.options.animations.length>0&&(this.options.trs=!0),await this.processInputAsync(e),await Promise.all(this.pending);const n=this,i=n.buffers,o=n.json;s=n.options;const l=n.extensionsUsed,u=n.extensionsRequired,d=new Blob(i,{type:"application/octet-stream"}),p=Object.keys(l),f=Object.keys(u);if(p.length>0&&(o.extensionsUsed=p),f.length>0&&(o.extensionsRequired=f),o.buffers&&o.buffers.length>0&&(o.buffers[0].byteLength=d.size),s.binary===!0){const g=new FileReader;g.readAsArrayBuffer(d),g.onloadend=function(){const y=Dt(g.result),x=new DataView(new ArrayBuffer(Nn));x.setUint32(0,y.byteLength,!0),x.setUint32(4,Li,!0);const m=Dt(ki(JSON.stringify(o)),32),A=new DataView(new ArrayBuffer(Nn));A.setUint32(0,m.byteLength,!0),A.setUint32(4,Pi,!0);const M=new ArrayBuffer(Dn),v=new DataView(M);v.setUint32(0,Oi,!0),v.setUint32(4,Ri,!0);const w=Dn+A.byteLength+m.byteLength+x.byteLength+y.byteLength;v.setUint32(8,w,!0);const h=new Blob([M,A,m,x,y],{type:"application/octet-stream"}),I=new FileReader;I.readAsArrayBuffer(h),I.onloadend=function(){t(I.result)}}}else if(o.buffers&&o.buffers.length>0){const g=new FileReader;g.readAsDataURL(d),g.onloadend=function(){const y=g.result;o.buffers[0].uri=y,t(o)}}else t(o)}serializeUserData(e,t){if(Object.keys(e.userData).length===0)return;const s=this.options,n=this.extensionsUsed;try{const i=JSON.parse(JSON.stringify(e.userData));if(s.includeCustomExtensions&&i.gltfExtensions){t.extensions===void 0&&(t.extensions={});for(const o in i.gltfExtensions)t.extensions[o]=i.gltfExtensions[o],n[o]=!0;delete i.gltfExtensions}Object.keys(i).length>0&&(t.extras=i)}catch(i){console.warn("THREE.GLTFExporter: userData of '"+e.name+"' won't be serialized because of JSON.stringify error - "+i.message)}}getUID(e,t=!1){if(this.uids.has(e)===!1){const n=new Map;n.set(!0,this.uid++),n.set(!1,this.uid++),this.uids.set(e,n)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;const s=new c.Vector3;for(let n=0,i=e.count;n<i;n++)if(Math.abs(s.fromBufferAttribute(e,n).length()-1)>5e-4)return!1;return!0}createNormalizedNormalAttribute(e){const t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);const s=e.clone(),n=new c.Vector3;for(let i=0,o=s.count;i<o;i++)n.fromBufferAttribute(s,i),n.x===0&&n.y===0&&n.z===0?n.setX(1):n.normalize(),s.setXYZ(i,n.x,n.y,n.z);return t.attributesNormalized.set(e,s),s}applyTextureTransform(e,t){let s=!1;const n={};(t.offset.x!==0||t.offset.y!==0)&&(n.offset=t.offset.toArray(),s=!0),t.rotation!==0&&(n.rotation=t.rotation,s=!0),(t.repeat.x!==1||t.repeat.y!==1)&&(n.scale=t.repeat.toArray(),s=!0),s&&(e.extensions=e.extensions||{},e.extensions.KHR_texture_transform=n,this.extensionsUsed.KHR_texture_transform=!0)}async buildMetalRoughTextureAsync(e,t){if(e===t)return e;function s(y){return y.colorSpace===c.SRGBColorSpace?function(m){return m<.04045?m*.0773993808:Math.pow(m*.9478672986+.0521327014,2.4)}:function(m){return m}}e instanceof c.CompressedTexture&&(e=await this.decompressTextureAsync(e)),t instanceof c.CompressedTexture&&(t=await this.decompressTextureAsync(t));const n=e?e.image:null,i=t?t.image:null,o=Math.max(n?n.width:0,i?i.width:0),l=Math.max(n?n.height:0,i?i.height:0),u=Sn();u.width=o,u.height=l;const d=u.getContext("2d",{willReadFrequently:!0});d.fillStyle="#00ffff",d.fillRect(0,0,o,l);const p=d.getImageData(0,0,o,l);if(n){d.drawImage(n,0,0,o,l);const y=s(e),x=d.getImageData(0,0,o,l).data;for(let m=2;m<x.length;m+=4)p.data[m]=y(x[m]/256)*256}if(i){d.drawImage(i,0,0,o,l);const y=s(t),x=d.getImageData(0,0,o,l).data;for(let m=1;m<x.length;m+=4)p.data[m]=y(x[m]/256)*256}d.putImageData(p,0,0);const g=(e||t).clone();return g.source=new c.Source(u),g.colorSpace=c.NoColorSpace,g.channel=(e||t).channel,e&&t&&e.channel!==t.channel&&console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match."),console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures."),g}async decompressTextureAsync(e,t=1/0){if(this.textureUtils===null)throw new Error("THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.");return await this.textureUtils.decompress(e,t)}processBuffer(e){const t=this.json,s=this.buffers;return t.buffers||(t.buffers=[{byteLength:0}]),s.push(e),0}processBufferView(e,t,s,n,i){const o=this.json;o.bufferViews||(o.bufferViews=[]);let l;switch(t){case z.BYTE:case z.UNSIGNED_BYTE:l=1;break;case z.SHORT:case z.UNSIGNED_SHORT:l=2;break;default:l=4}let u=e.itemSize*l;i===z.ARRAY_BUFFER&&(u=Math.ceil(u/4)*4);const d=Zn(n*u),p=new DataView(new ArrayBuffer(d));let f=0;for(let x=s;x<s+n;x++){for(let m=0;m<e.itemSize;m++){let A;e.itemSize>4?A=e.array[x*e.itemSize+m]:(m===0?A=e.getX(x):m===1?A=e.getY(x):m===2?A=e.getZ(x):m===3&&(A=e.getW(x)),e.normalized===!0&&(A=c.MathUtils.normalize(A,e.array))),t===z.FLOAT?p.setFloat32(f,A,!0):t===z.INT?p.setInt32(f,A,!0):t===z.UNSIGNED_INT?p.setUint32(f,A,!0):t===z.SHORT?p.setInt16(f,A,!0):t===z.UNSIGNED_SHORT?p.setUint16(f,A,!0):t===z.BYTE?p.setInt8(f,A):t===z.UNSIGNED_BYTE&&p.setUint8(f,A),f+=l}f%u!==0&&(f+=u-f%u)}const g={buffer:this.processBuffer(p.buffer),byteOffset:this.byteOffset,byteLength:d};return i!==void 0&&(g.target=i),i===z.ARRAY_BUFFER&&(g.byteStride=u),this.byteOffset+=d,o.bufferViews.push(g),{id:o.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){const t=this,s=t.json;return s.bufferViews||(s.bufferViews=[]),new Promise(function(n){const i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){const o=Dt(i.result),l={buffer:t.processBuffer(o),byteOffset:t.byteOffset,byteLength:o.byteLength};t.byteOffset+=o.byteLength,n(s.bufferViews.push(l)-1)}})}processAccessor(e,t,s,n){const i=this.json,o={1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"};let l;if(e.array.constructor===Float32Array)l=z.FLOAT;else if(e.array.constructor===Int32Array)l=z.INT;else if(e.array.constructor===Uint32Array)l=z.UNSIGNED_INT;else if(e.array.constructor===Int16Array)l=z.SHORT;else if(e.array.constructor===Uint16Array)l=z.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)l=z.BYTE;else if(e.array.constructor===Uint8Array)l=z.UNSIGNED_BYTE;else throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(s===void 0&&(s=0),(n===void 0||n===1/0)&&(n=e.count),n===0)return null;const u=Hi(e,s,n);let d;t!==void 0&&(d=e===t.index?z.ELEMENT_ARRAY_BUFFER:z.ARRAY_BUFFER);const p=this.processBufferView(e,l,s,n,d),f={bufferView:p.id,byteOffset:p.byteOffset,componentType:l,count:n,max:u.max,min:u.min,type:o[e.itemSize]};return e.normalized===!0&&(f.normalized=!0),i.accessors||(i.accessors=[]),i.accessors.push(f)-1}processImage(e,t,s,n="image/png"){if(e!==null){const i=this,o=i.cache,l=i.json,u=i.options,d=i.pending;o.images.has(e)||o.images.set(e,{});const p=o.images.get(e),f=n+":flipY/"+s.toString();if(p[f]!==void 0)return p[f];l.images||(l.images=[]);const g={mimeType:n},y=Sn();y.width=Math.min(e.width,u.maxTextureSize),y.height=Math.min(e.height,u.maxTextureSize);const x=y.getContext("2d",{willReadFrequently:!0});if(s===!0&&(x.translate(0,y.height),x.scale(1,-1)),e.data!==void 0){t!==c.RGBAFormat&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>u.maxTextureSize||e.height>u.maxTextureSize)&&console.warn("GLTFExporter: Image size is bigger than maxTextureSize",e);const A=new Uint8ClampedArray(e.height*e.width*4);for(let M=0;M<A.length;M+=4)A[M+0]=e.data[M+0],A[M+1]=e.data[M+1],A[M+2]=e.data[M+2],A[M+3]=e.data[M+3];x.putImageData(new ImageData(A,e.width,e.height),0,0)}else if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)x.drawImage(e,0,0,y.width,y.height);else throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");u.binary===!0?d.push(Bi(y,n).then(A=>i.processBufferViewImage(A)).then(A=>{g.bufferView=A})):g.uri=c.ImageUtils.getDataURL(y,n);const m=l.images.push(g)-1;return p[f]=m,m}else throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){const t=this.json;t.samplers||(t.samplers=[]);const s={magFilter:le[e.magFilter],minFilter:le[e.minFilter],wrapS:le[e.wrapS],wrapT:le[e.wrapT]};return t.samplers.push(s)-1}async processTextureAsync(e){const s=this.options,n=this.cache,i=this.json;if(n.textures.has(e))return n.textures.get(e);i.textures||(i.textures=[]),e instanceof c.CompressedTexture&&(e=await this.decompressTextureAsync(e,s.maxTextureSize));const o=e.userData.mimeType,l=this.processImage(e.image,e.format,e.flipY,o),u={sampler:this.processSampler(e)};o==="image/webp"?(u.extensions=u.extensions||{},u.extensions.EXT_texture_webp={source:l},this.extensionsUsed.EXT_texture_webp=!0,this.extensionsRequired.EXT_texture_webp=!0):u.source=l,e.name&&(u.name=e.name),await this._invokeAllAsync(async function(p){p.writeTexture&&await p.writeTexture(e,u)});const d=i.textures.push(u)-1;return n.textures.set(e,d),d}async processMaterialAsync(e){const t=this.cache,s=this.json;if(t.materials.has(e))return t.materials.get(e);if(e.isShaderMaterial)return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."),null;s.materials||(s.materials=[]);const n={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");const i=e.color.toArray().concat([e.opacity]);if(ye(i,[1,1,1,1])||(n.pbrMetallicRoughness.baseColorFactor=i),e.isMeshStandardMaterial?(n.pbrMetallicRoughness.metallicFactor=e.metalness,n.pbrMetallicRoughness.roughnessFactor=e.roughness):(n.pbrMetallicRoughness.metallicFactor=0,n.pbrMetallicRoughness.roughnessFactor=1),e.metalnessMap||e.roughnessMap){const l=await this.buildMetalRoughTextureAsync(e.metalnessMap,e.roughnessMap),u={index:await this.processTextureAsync(l),texCoord:l.channel};this.applyTextureTransform(u,l),n.pbrMetallicRoughness.metallicRoughnessTexture=u}if(e.map){const l={index:await this.processTextureAsync(e.map),texCoord:e.map.channel};this.applyTextureTransform(l,e.map),n.pbrMetallicRoughness.baseColorTexture=l}if(e.emissive){const l=e.emissive;if(Math.max(l.r,l.g,l.b)>0&&(n.emissiveFactor=e.emissive.toArray()),e.emissiveMap){const d={index:await this.processTextureAsync(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(d,e.emissiveMap),n.emissiveTexture=d}}if(e.normalMap){const l={index:await this.processTextureAsync(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&e.normalScale.x!==1&&(l.scale=e.normalScale.x),this.applyTextureTransform(l,e.normalMap),n.normalTexture=l}if(e.aoMap){const l={index:await this.processTextureAsync(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(l.strength=e.aoMapIntensity),this.applyTextureTransform(l,e.aoMap),n.occlusionTexture=l}e.transparent?n.alphaMode="BLEND":e.alphaTest>0&&(n.alphaMode="MASK",n.alphaCutoff=e.alphaTest),e.side===c.DoubleSide&&(n.doubleSided=!0),e.name!==""&&(n.name=e.name),this.serializeUserData(e,n),await this._invokeAllAsync(async function(l){l.writeMaterialAsync&&await l.writeMaterialAsync(e,n)});const o=s.materials.push(n)-1;return t.materials.set(e,o),o}async processMeshAsync(e){const t=this.cache,s=this.json,n=[e.geometry.uuid];if(Array.isArray(e.material))for(let h=0,I=e.material.length;h<I;h++)n.push(e.material[h].uuid);else n.push(e.material.uuid);const i=n.join(":");if(t.meshes.has(i))return t.meshes.get(i);const o=e.geometry;let l;e.isLineSegments?l=z.LINES:e.isLineLoop?l=z.LINE_LOOP:e.isLine?l=z.LINE_STRIP:e.isPoints?l=z.POINTS:l=e.material.wireframe?z.LINES:z.TRIANGLES;const u={},d={},p=[],f=[],g={uv:"TEXCOORD_0",uv1:"TEXCOORD_1",uv2:"TEXCOORD_2",uv3:"TEXCOORD_3",color:"COLOR_0",skinWeight:"WEIGHTS_0",skinIndex:"JOINTS_0"},y=o.getAttribute("normal");y!==void 0&&!this.isNormalizedNormalAttribute(y)&&(console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."),o.setAttribute("normal",this.createNormalizedNormalAttribute(y)));let x=null;for(let h in o.attributes){if(h.slice(0,5)==="morph")continue;const I=o.attributes[h];if(h=g[h]||h.toUpperCase(),!/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(h)&&!h.startsWith("_")&&(h="_"+h),t.attributes.has(this.getUID(I))){d[h]=t.attributes.get(this.getUID(I));continue}x=null;const N=I.array;h==="JOINTS_0"&&!(N instanceof Uint16Array)&&!(N instanceof Uint8Array)?(console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'),x=qe.Utils.toTypedBufferAttribute(I,Uint16Array)):(N instanceof Uint32Array||N instanceof Int32Array)&&!h.startsWith("_")&&(console.warn(`GLTFExporter: Attribute "${h}" converted to type FLOAT.`),x=qe.Utils.toTypedBufferAttribute(I,Float32Array));const D=this.processAccessor(x||I,o);D!==null&&(h.startsWith("_")||this.detectMeshQuantization(h,I),d[h]=D,t.attributes.set(this.getUID(I),D))}if(y!==void 0&&o.setAttribute("normal",y),Object.keys(d).length===0)return null;if(e.morphTargetInfluences!==void 0&&e.morphTargetInfluences.length>0){const h=[],I=[],E={};if(e.morphTargetDictionary!==void 0)for(const N in e.morphTargetDictionary)E[e.morphTargetDictionary[N]]=N;for(let N=0;N<e.morphTargetInfluences.length;++N){const D={};let V=!1;for(const W in o.morphAttributes){if(W!=="position"&&W!=="normal"){V||(console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."),V=!0);continue}const Y=o.morphAttributes[W][N],Z=W.toUpperCase(),q=o.attributes[W];if(t.attributes.has(this.getUID(Y,!0))){D[Z]=t.attributes.get(this.getUID(Y,!0));continue}const j=Y.clone();if(!o.morphTargetsRelative)for(let P=0,L=Y.count;P<L;P++)for(let B=0;B<Y.itemSize;B++)B===0&&j.setX(P,Y.getX(P)-q.getX(P)),B===1&&j.setY(P,Y.getY(P)-q.getY(P)),B===2&&j.setZ(P,Y.getZ(P)-q.getZ(P)),B===3&&j.setW(P,Y.getW(P)-q.getW(P));D[Z]=this.processAccessor(j,o),t.attributes.set(this.getUID(q,!0),D[Z])}f.push(D),h.push(e.morphTargetInfluences[N]),e.morphTargetDictionary!==void 0&&I.push(E[N])}u.weights=h,I.length>0&&(u.extras={},u.extras.targetNames=I)}const m=Array.isArray(e.material);if(m&&o.groups.length===0)return null;let A=!1;if(m&&o.index===null){const h=[];for(let I=0,E=o.attributes.position.count;I<E;I++)h[I]=I;o.setIndex(h),A=!0}const M=m?e.material:[e.material],v=m?o.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let h=0,I=v.length;h<I;h++){const E={mode:l,attributes:d};if(this.serializeUserData(o,E),f.length>0&&(E.targets=f),o.index!==null){let D=this.getUID(o.index);(v[h].start!==void 0||v[h].count!==void 0)&&(D+=":"+v[h].start+":"+v[h].count),t.attributes.has(D)?E.indices=t.attributes.get(D):(E.indices=this.processAccessor(o.index,o,v[h].start,v[h].count),t.attributes.set(D,E.indices)),E.indices===null&&delete E.indices}const N=await this.processMaterialAsync(M[v[h].materialIndex]);N!==null&&(E.material=N),p.push(E)}A===!0&&o.setIndex(null),u.primitives=p,s.meshes||(s.meshes=[]),await this._invokeAllAsync(function(h){h.writeMesh&&h.writeMesh(e,u)});const w=s.meshes.push(u)-1;return t.meshes.set(i,w),w}detectMeshQuantization(e,t){if(this.extensionsUsed[Tt])return;let s;switch(t.array.constructor){case Int8Array:s="byte";break;case Uint8Array:s="unsigned byte";break;case Int16Array:s="short";break;case Uint16Array:s="unsigned short";break;default:return}t.normalized&&(s+=" normalized");const n=e.split("_",1)[0];En[n]&&En[n].includes(s)&&(this.extensionsUsed[Tt]=!0,this.extensionsRequired[Tt]=!0)}processCamera(e){const t=this.json;t.cameras||(t.cameras=[]);const s=e.isOrthographicCamera,n={type:s?"orthographic":"perspective"};return s?n.orthographic={xmag:e.right*2,ymag:e.top*2,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:n.perspective={aspectRatio:e.aspect,yfov:c.MathUtils.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==""&&(n.name=e.type),t.cameras.push(n)-1}processAnimation(e,t){const s=this.json,n=this.nodeMap;s.animations||(s.animations=[]),e=qe.Utils.mergeMorphTargetTracks(e.clone(),t);const i=e.tracks,o=[],l=[];for(let d=0;d<i.length;++d){const p=i[d],f=c.PropertyBinding.parseTrackName(p.name);let g=c.PropertyBinding.findNode(t,f.nodeName);const y=Tn[f.propertyName];if(f.objectName==="bones"&&(g.isSkinnedMesh===!0?g=g.skeleton.getBoneByName(f.objectIndex):g=void 0),!g||!y){console.warn('THREE.GLTFExporter: Could not export animation track "%s".',p.name);continue}const x=1;let m=p.values.length/p.times.length;y===Tn.morphTargetInfluences&&(m/=g.morphTargetInfluences.length);let A;p.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline===!0?(A="CUBICSPLINE",m/=3):p.getInterpolation()===c.InterpolateDiscrete?A="STEP":A="LINEAR",l.push({input:this.processAccessor(new c.BufferAttribute(p.times,x)),output:this.processAccessor(new c.BufferAttribute(p.values,m)),interpolation:A}),o.push({sampler:l.length-1,target:{node:n.get(g),path:y}})}const u={name:e.name||"clip_"+s.animations.length,samplers:l,channels:o};return this.serializeUserData(e,u),s.animations.push(u),s.animations.length-1}processSkin(e){const t=this.json,s=this.nodeMap,n=t.nodes[s.get(e)],i=e.skeleton;if(i===void 0)return null;const o=e.skeleton.bones[0];if(o===void 0)return null;const l=[],u=new Float32Array(i.bones.length*16),d=new c.Matrix4;for(let f=0;f<i.bones.length;++f)l.push(s.get(i.bones[f])),d.copy(i.boneInverses[f]),d.multiply(e.bindMatrix).toArray(u,f*16);return t.skins===void 0&&(t.skins=[]),t.skins.push({inverseBindMatrices:this.processAccessor(new c.BufferAttribute(u,16)),joints:l,skeleton:s.get(o)}),n.skin=t.skins.length-1}async processNodeAsync(e){const t=this.json,s=this.options,n=this.nodeMap;if(t.nodes||(t.nodes=[]),e.pivot!==null)return await this._processNodeWithPivotAsync(e);const i={};if(s.trs){const l=e.quaternion.toArray(),u=e.position.toArray(),d=e.scale.toArray();ye(l,[0,0,0,1])||(i.rotation=l),ye(u,[0,0,0])||(i.translation=u),ye(d,[1,1,1])||(i.scale=d)}else e.matrixAutoUpdate&&e.updateMatrix(),Vi(e.matrix)===!1&&(i.matrix=e.matrix.elements);if(e.name!==""&&(i.name=String(e.name)),this.serializeUserData(e,i),e.isMesh||e.isLine||e.isPoints){const l=await this.processMeshAsync(e);l!==null&&(i.mesh=l)}else e.isCamera&&(i.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);const o=t.nodes.push(i)-1;if(n.set(e,o),e.children.length>0){const l=[];for(let u=0,d=e.children.length;u<d;u++){const p=e.children[u];if(p.visible||s.onlyVisible===!1){const f=await this.processNodeAsync(p);f!==null&&l.push(f)}}l.length>0&&(i.children=l)}return await this._invokeAllAsync(function(l){l.writeNode&&l.writeNode(e,i)}),o}async _processNodeWithPivotAsync(e){const t=this.json,s=this.options,n=this.nodeMap,i=e.pivot,o={},l=e.quaternion.toArray(),u=[e.position.x+i.x,e.position.y+i.y,e.position.z+i.z],d=e.scale.toArray();ye(l,[0,0,0,1])||(o.rotation=l),ye(u,[0,0,0])||(o.translation=u),ye(d,[1,1,1])||(o.scale=d),o.extras={pivot:i.toArray()},e.name!==""&&(o.name=String(e.name)),this.serializeUserData(e,o);const p=t.nodes.push(o)-1;n.set(e,p);const f={},g=[-i.x,-i.y,-i.z];if(ye(g,[0,0,0])||(f.translation=g),e.isMesh||e.isLine||e.isPoints){const m=await this.processMeshAsync(e);m!==null&&(f.mesh=m)}else e.isCamera&&(f.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);const x=[t.nodes.push(f)-1];if(e.children.length>0){const m=[];for(let A=0,M=e.children.length;A<M;A++){const v=e.children[A];if(v.visible||s.onlyVisible===!1){const w=await this.processNodeAsync(v);w!==null&&m.push(w)}}m.length>0&&(f.children=m)}return o.children=x,await this._invokeAllAsync(function(m){m.writeNode&&m.writeNode(e,o)}),p}async processSceneAsync(e){const t=this.json,s=this.options;t.scenes||(t.scenes=[],t.scene=0);const n={};e.name!==""&&(n.name=e.name),t.scenes.push(n);const i=[];for(let o=0,l=e.children.length;o<l;o++){const u=e.children[o];if(u.visible||s.onlyVisible===!1){const d=await this.processNodeAsync(u);d!==null&&i.push(d)}}i.length>0&&(n.nodes=i),this.serializeUserData(e,n)}async processObjectsAsync(e){const t=new c.Scene;t.name="AuxScene";for(let s=0;s<e.length;s++)t.children.push(e[s]);await this.processSceneAsync(t)}async processInputAsync(e){const t=this.options;e=e instanceof Array?e:[e],await this._invokeAllAsync(function(n){n.beforeParse&&n.beforeParse(e)});const s=[];for(let n=0;n<e.length;n++)e[n]instanceof c.Scene?await this.processSceneAsync(e[n]):s.push(e[n]);s.length>0&&await this.processObjectsAsync(s);for(let n=0;n<this.skins.length;++n)this.processSkin(this.skins[n]);for(let n=0;n<t.animations.length;++n)this.processAnimation(t.animations[n],e[0]);await this._invokeAllAsync(function(n){n.afterParse&&n.afterParse(e)})}async _invokeAllAsync(e){for(let t=0,s=this.plugins.length;t<s;t++)await e(this.plugins[t])}}class Fi{constructor(e){this.writer=e,this.name="KHR_lights_punctual"}writeNode(e,t){if(!e.isLight)return;if(!e.isDirectionalLight&&!e.isPointLight&&!e.isSpotLight){console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.",e);return}const s=this.writer,n=s.json,i=s.extensionsUsed,o={};e.name&&(o.name=e.name),o.color=e.color.toArray(),o.intensity=e.intensity,e.isDirectionalLight?o.type="directional":e.isPointLight?(o.type="point",e.distance>0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."),i[this.name]||(n.extensions=n.extensions||{},n.extensions[this.name]={lights:[]},i[this.name]=!0);const l=n.extensions[this.name].lights;l.push(o),t.extensions=t.extensions||{},t.extensions[this.name]={light:l.length-1}}}let Ui=class{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}async writeMaterialAsync(e,t){if(!e.isMeshBasicMaterial)return;const n=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},n[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}},Gi=class{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;const s=this.writer,n=s.extensionsUsed,i={};if(i.clearcoatFactor=e.clearcoat,e.clearcoatMap){const o={index:await s.processTextureAsync(e.clearcoatMap),texCoord:e.clearcoatMap.channel};s.applyTextureTransform(o,e.clearcoatMap),i.clearcoatTexture=o}if(i.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){const o={index:await s.processTextureAsync(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};s.applyTextureTransform(o,e.clearcoatRoughnessMap),i.clearcoatRoughnessTexture=o}if(e.clearcoatNormalMap){const o={index:await s.processTextureAsync(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};e.clearcoatNormalScale.x!==1&&(o.scale=e.clearcoatNormalScale.x),s.applyTextureTransform(o,e.clearcoatNormalMap),i.clearcoatNormalTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},zi=class{constructor(e){this.writer=e,this.name="KHR_materials_dispersion"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.dispersion===0)return;const n=this.writer.extensionsUsed,i={};i.dispersion=e.dispersion,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Wi=class{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;const s=this.writer,n=s.extensionsUsed,i={};if(i.iridescenceFactor=e.iridescence,e.iridescenceMap){const o={index:await s.processTextureAsync(e.iridescenceMap),texCoord:e.iridescenceMap.channel};s.applyTextureTransform(o,e.iridescenceMap),i.iridescenceTexture=o}if(i.iridescenceIor=e.iridescenceIOR,i.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],i.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1],e.iridescenceThicknessMap){const o={index:await s.processTextureAsync(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};s.applyTextureTransform(o,e.iridescenceThicknessMap),i.iridescenceThicknessTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},qi=class{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const s=this.writer,n=s.extensionsUsed,i={};if(i.transmissionFactor=e.transmission,e.transmissionMap){const o={index:await s.processTextureAsync(e.transmissionMap),texCoord:e.transmissionMap.channel};s.applyTextureTransform(o,e.transmissionMap),i.transmissionTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Xi=class{constructor(e){this.writer=e,this.name="KHR_materials_volume"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const s=this.writer,n=s.extensionsUsed,i={};if(i.thicknessFactor=e.thickness,e.thicknessMap){const o={index:await s.processTextureAsync(e.thicknessMap),texCoord:e.thicknessMap.channel};s.applyTextureTransform(o,e.thicknessMap),i.thicknessTexture=o}e.attenuationDistance!==1/0&&(i.attenuationDistance=e.attenuationDistance),i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Yi=class{constructor(e){this.writer=e,this.name="KHR_materials_ior"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;const n=this.writer.extensionsUsed,i={};i.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Ki=class{constructor(e){this.writer=e,this.name="KHR_materials_specular"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(Si)&&!e.specularIntensityMap&&!e.specularColorMap)return;const s=this.writer,n=s.extensionsUsed,i={};if(e.specularIntensityMap){const o={index:await s.processTextureAsync(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};s.applyTextureTransform(o,e.specularIntensityMap),i.specularTexture=o}if(e.specularColorMap){const o={index:await s.processTextureAsync(e.specularColorMap),texCoord:e.specularColorMap.channel};s.applyTextureTransform(o,e.specularColorMap),i.specularColorTexture=o}i.specularFactor=e.specularIntensity,i.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Zi=class{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;const s=this.writer,n=s.extensionsUsed,i={};if(e.sheenRoughnessMap){const o={index:await s.processTextureAsync(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};s.applyTextureTransform(o,e.sheenRoughnessMap),i.sheenRoughnessTexture=o}if(e.sheenColorMap){const o={index:await s.processTextureAsync(e.sheenColorMap),texCoord:e.sheenColorMap.channel};s.applyTextureTransform(o,e.sheenColorMap),i.sheenColorTexture=o}i.sheenRoughnessFactor=e.sheenRoughness,i.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Qi=class{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;const s=this.writer,n=s.extensionsUsed,i={};if(e.anisotropyMap){const o={index:await s.processTextureAsync(e.anisotropyMap)};s.applyTextureTransform(o,e.anisotropyMap),i.anisotropyTexture=o}i.anisotropyStrength=e.anisotropy,i.anisotropyRotation=e.anisotropyRotation,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Ji=class{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;const n=this.writer.extensionsUsed,i={};i.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},_i=class{constructor(e){this.writer=e,this.name="EXT_materials_bump"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;const s=this.writer,n=s.extensionsUsed,i={};if(e.bumpMap){const o={index:await s.processTextureAsync(e.bumpMap),texCoord:e.bumpMap.channel};s.applyTextureTransform(o,e.bumpMap),i.bumpTexture=o}i.bumpFactor=e.bumpScale,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},$i=class{constructor(e){this.writer=e,this.name="EXT_mesh_gpu_instancing"}writeNode(e,t){if(!e.isInstancedMesh)return;const s=this.writer,n=e,i=new Float32Array(n.count*3),o=new Float32Array(n.count*4),l=new Float32Array(n.count*3),u=new c.Matrix4,d=new c.Vector3,p=new c.Quaternion,f=new c.Vector3;for(let y=0;y<n.count;y++)n.getMatrixAt(y,u),u.decompose(d,p,f),d.toArray(i,y*3),p.toArray(o,y*4),f.toArray(l,y*3);const g={TRANSLATION:s.processAccessor(new c.BufferAttribute(i,3)),ROTATION:s.processAccessor(new c.BufferAttribute(o,4)),SCALE:s.processAccessor(new c.BufferAttribute(l,3))};n.instanceColor&&(g._COLOR_0=s.processAccessor(n.instanceColor)),t.extensions=t.extensions||{},t.extensions[this.name]={attributes:g},s.extensionsUsed[this.name]=!0,s.extensionsRequired[this.name]=!0}};qe.Utils={insertKeyframe:function(r,e){const s=r.getValueSize(),n=new r.TimeBufferType(r.times.length+1),i=new r.ValueBufferType(r.values.length+s),o=r.createInterpolant(new r.ValueBufferType(s));let l;if(r.times.length===0){n[0]=e;for(let u=0;u<s;u++)i[u]=0;l=0}else if(e<r.times[0]){if(Math.abs(r.times[0]-e)<.001)return 0;n[0]=e,n.set(r.times,1),i.set(o.evaluate(e),0),i.set(r.values,s),l=0}else if(e>r.times[r.times.length-1]){if(Math.abs(r.times[r.times.length-1]-e)<.001)return r.times.length-1;n[n.length-1]=e,n.set(r.times,0),i.set(r.values,0),i.set(o.evaluate(e),r.values.length),l=n.length-1}else for(let u=0;u<r.times.length;u++){if(Math.abs(r.times[u]-e)<.001)return u;if(r.times[u]<e&&r.times[u+1]>e){n.set(r.times.slice(0,u+1),0),n[u+1]=e,n.set(r.times.slice(u+1),u+2),i.set(r.values.slice(0,(u+1)*s),0),i.set(o.evaluate(e),(u+1)*s),i.set(r.values.slice((u+1)*s),(u+2)*s),l=u+1;break}}return r.times=n,r.values=i,l},mergeMorphTargetTracks:function(r,e){const t=[],s={},n=r.tracks;for(let i=0;i<n.length;++i){let o=n[i];const l=c.PropertyBinding.parseTrackName(o.name),u=c.PropertyBinding.findNode(e,l.nodeName);if(l.propertyName!=="morphTargetInfluences"||l.propertyIndex===void 0){t.push(o);continue}if(o.createInterpolant!==o.InterpolantFactoryMethodDiscrete&&o.createInterpolant!==o.InterpolantFactoryMethodLinear){if(o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."),o=o.clone(),o.setInterpolation(c.InterpolateLinear)}const d=u.morphTargetInfluences.length,p=u.morphTargetDictionary[l.propertyIndex];if(p===void 0)throw new Error("THREE.GLTFExporter: Morph target name not found: "+l.propertyIndex);let f;if(s[u.uuid]===void 0){f=o.clone();const y=new f.ValueBufferType(d*f.times.length);for(let x=0;x<f.times.length;x++)y[x*d+p]=f.values[x];f.name=(l.nodeName||"")+".morphTargetInfluences",f.values=y,s[u.uuid]=f,t.push(f);continue}const g=o.createInterpolant(new o.ValueBufferType(1));f=s[u.uuid];for(let y=0;y<f.times.length;y++)f.values[y*d+p]=g.evaluate(f.times[y]);for(let y=0;y<o.times.length;y++){const x=this.insertKeyframe(f,o.times[y]);f.values[x*d+p]=o.values[y]}}return r.tracks=t,r},toTypedBufferAttribute:function(r,e){const t=new c.BufferAttribute(new e(r.count*r.itemSize),r.itemSize,!1);if(!r.normalized&&!r.isInterleavedBufferAttribute)return t.array.set(r.array),t;for(let s=0,n=r.count;s<n;s++)for(let i=0;i<r.itemSize;i++)t.setComponent(s,i,r.getComponent(s,i));return t}};function On(r,e){if(e===c.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),r;if(e===c.TriangleFanDrawMode||e===c.TriangleStripDrawMode){let t=r.getIndex();if(t===null){const o=[],l=r.getAttribute("position");if(l!==void 0){for(let u=0;u<l.count;u++)o.push(u);r.setIndex(o),t=r.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),r}const s=t.count-2,n=[];if(e===c.TriangleFanDrawMode)for(let o=1;o<=s;o++)n.push(t.getX(0)),n.push(t.getX(o)),n.push(t.getX(o+1));else for(let o=0;o<s;o++)o%2===0?(n.push(t.getX(o)),n.push(t.getX(o+1)),n.push(t.getX(o+2))):(n.push(t.getX(o+2)),n.push(t.getX(o+1)),n.push(t.getX(o)));n.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=r.clone();return i.setIndex(n),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),r}function eo(r){const e=new Map,t=new Map,s=r.clone();return Qn(r,s,function(n,i){e.set(i,n),t.set(n,i)}),s.traverse(function(n){if(!n.isSkinnedMesh)return;const i=n,o=e.get(n),l=o.skeleton.bones;i.skeleton=o.skeleton.clone(),i.bindMatrix.copy(o.bindMatrix),i.skeleton.bones=l.map(function(u){return t.get(u)}),i.bind(i.skeleton,i.bindMatrix)}),s}function Qn(r,e,t){t(r,e);for(let s=0;s<r.children.length;s++)Qn(r.children[s],e.children[s],t)}class Jn extends c.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new oo(t)}),this.register(function(t){return new ro(t)}),this.register(function(t){return new Ao(t)}),this.register(function(t){return new go(t)}),this.register(function(t){return new yo(t)}),this.register(function(t){return new lo(t)}),this.register(function(t){return new co(t)}),this.register(function(t){return new uo(t)}),this.register(function(t){return new fo(t)}),this.register(function(t){return new io(t)}),this.register(function(t){return new ho(t)}),this.register(function(t){return new ao(t)}),this.register(function(t){return new mo(t)}),this.register(function(t){return new po(t)}),this.register(function(t){return new no(t)}),this.register(function(t){return new Rn(t,G.EXT_MESHOPT_COMPRESSION)}),this.register(function(t){return new Rn(t,G.KHR_MESHOPT_COMPRESSION)}),this.register(function(t){return new bo(t)})}load(e,t,s,n){const i=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const d=c.LoaderUtils.extractUrlBase(e);o=c.LoaderUtils.resolveURL(d,this.path)}else o=c.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const l=function(d){n?n(d):console.error(d),i.manager.itemError(e),i.manager.itemEnd(e)},u=new c.FileLoader(this.manager);u.setPath(this.path),u.setResponseType("arraybuffer"),u.setRequestHeader(this.requestHeader),u.setWithCredentials(this.withCredentials),u.load(e,function(d){try{i.parse(d,o,function(p){t(p),i.manager.itemEnd(e)},l)}catch(p){l(p)}},s,l)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,s,n){let i;const o={},l={},u=new TextDecoder;if(typeof e=="string")i=JSON.parse(e);else if(e instanceof ArrayBuffer)if(u.decode(new Uint8Array(e,0,4))===_n){try{o[G.KHR_BINARY_GLTF]=new xo(e)}catch(f){n&&n(f);return}i=JSON.parse(o[G.KHR_BINARY_GLTF].content)}else i=JSON.parse(u.decode(e));else i=e;if(i.asset===void 0||i.asset.version[0]<2){n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const d=new Po(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});d.fileLoader.setRequestHeader(this.requestHeader);for(let p=0;p<this.pluginCallbacks.length;p++){const f=this.pluginCallbacks[p](d);f.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),l[f.name]=f,o[f.name]=!0}if(i.extensionsUsed)for(let p=0;p<i.extensionsUsed.length;++p){const f=i.extensionsUsed[p],g=i.extensionsRequired||[];switch(f){case G.KHR_MATERIALS_UNLIT:o[f]=new so;break;case G.KHR_DRACO_MESH_COMPRESSION:o[f]=new Io(i,this.dracoLoader);break;case G.KHR_TEXTURE_TRANSFORM:o[f]=new Co;break;case G.KHR_MESH_QUANTIZATION:o[f]=new Mo;break;default:g.indexOf(f)>=0&&l[f]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+f+'".')}}d.setExtensions(o),d.setPlugins(l),d.parse(s,n)}parseAsync(e,t){const s=this;return new Promise(function(n,i){s.parse(e,t,n,i)})}}function to(){let r={};return{get:function(e){return r[e]},add:function(e,t){r[e]=t},remove:function(e){delete r[e]},removeAll:function(){r={}}}}function ee(r,e,t){const s=r.json.materials[e];return s.extensions&&s.extensions[t]?s.extensions[t]:null}const G={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class no{constructor(e){this.parser=e,this.name=G.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const i=t[s];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,s="light:"+e;let n=t.cache.get(s);if(n)return n;const i=t.json,u=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let d;const p=new c.Color(16777215);u.color!==void 0&&p.setRGB(u.color[0],u.color[1],u.color[2],c.LinearSRGBColorSpace);const f=u.range!==void 0?u.range:0;switch(u.type){case"directional":d=new c.DirectionalLight(p),d.target.position.set(0,0,-1),d.add(d.target);break;case"point":d=new c.PointLight(p),d.distance=f;break;case"spot":d=new c.SpotLight(p),d.distance=f,u.spot=u.spot||{},u.spot.innerConeAngle=u.spot.innerConeAngle!==void 0?u.spot.innerConeAngle:0,u.spot.outerConeAngle=u.spot.outerConeAngle!==void 0?u.spot.outerConeAngle:Math.PI/4,d.angle=u.spot.outerConeAngle,d.penumbra=1-u.spot.innerConeAngle/u.spot.outerConeAngle,d.target.position.set(0,0,-1),d.add(d.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+u.type)}return d.position.set(0,0,0),Ae(d,u),u.intensity!==void 0&&(d.intensity=u.intensity),d.name=t.createUniqueName(u.name||"light_"+e),n=Promise.resolve(d),t.cache.add(s,n),n}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,i=s.json.nodes[e],l=(i.extensions&&i.extensions[this.name]||{}).light;return l===void 0?null:this._loadLight(l).then(function(u){return s._getNodeRef(t.cache,l,u)})}}class so{constructor(){this.name=G.KHR_MATERIALS_UNLIT}getMaterialType(){return c.MeshBasicMaterial}extendParams(e,t,s){const n=[];e.color=new c.Color(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const o=i.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],c.LinearSRGBColorSpace),e.opacity=o[3]}i.baseColorTexture!==void 0&&n.push(s.assignTexture(e,"map",i.baseColorTexture,c.SRGBColorSpace))}return Promise.all(n)}}class io{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);return s===null||s.emissiveStrength!==void 0&&(t.emissiveIntensity=s.emissiveStrength),Promise.resolve()}}class oo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];if(s.clearcoatFactor!==void 0&&(t.clearcoat=s.clearcoatFactor),s.clearcoatTexture!==void 0&&n.push(this.parser.assignTexture(t,"clearcoatMap",s.clearcoatTexture)),s.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=s.clearcoatRoughnessFactor),s.clearcoatRoughnessTexture!==void 0&&n.push(this.parser.assignTexture(t,"clearcoatRoughnessMap",s.clearcoatRoughnessTexture)),s.clearcoatNormalTexture!==void 0&&(n.push(this.parser.assignTexture(t,"clearcoatNormalMap",s.clearcoatNormalTexture)),s.clearcoatNormalTexture.scale!==void 0)){const i=s.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new c.Vector2(i,i)}return Promise.all(n)}}class ro{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_DISPERSION}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);return s===null||(t.dispersion=s.dispersion!==void 0?s.dispersion:0),Promise.resolve()}}class ao{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];return s.iridescenceFactor!==void 0&&(t.iridescence=s.iridescenceFactor),s.iridescenceTexture!==void 0&&n.push(this.parser.assignTexture(t,"iridescenceMap",s.iridescenceTexture)),s.iridescenceIor!==void 0&&(t.iridescenceIOR=s.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),s.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=s.iridescenceThicknessMinimum),s.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=s.iridescenceThicknessMaximum),s.iridescenceThicknessTexture!==void 0&&n.push(this.parser.assignTexture(t,"iridescenceThicknessMap",s.iridescenceThicknessTexture)),Promise.all(n)}}class lo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_SHEEN}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];if(t.sheenColor=new c.Color(0,0,0),t.sheenRoughness=0,t.sheen=1,s.sheenColorFactor!==void 0){const i=s.sheenColorFactor;t.sheenColor.setRGB(i[0],i[1],i[2],c.LinearSRGBColorSpace)}return s.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=s.sheenRoughnessFactor),s.sheenColorTexture!==void 0&&n.push(this.parser.assignTexture(t,"sheenColorMap",s.sheenColorTexture,c.SRGBColorSpace)),s.sheenRoughnessTexture!==void 0&&n.push(this.parser.assignTexture(t,"sheenRoughnessMap",s.sheenRoughnessTexture)),Promise.all(n)}}class co{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];return s.transmissionFactor!==void 0&&(t.transmission=s.transmissionFactor),s.transmissionTexture!==void 0&&n.push(this.parser.assignTexture(t,"transmissionMap",s.transmissionTexture)),Promise.all(n)}}class uo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_VOLUME}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];t.thickness=s.thicknessFactor!==void 0?s.thicknessFactor:0,s.thicknessTexture!==void 0&&n.push(this.parser.assignTexture(t,"thicknessMap",s.thicknessTexture)),t.attenuationDistance=s.attenuationDistance||1/0;const i=s.attenuationColor||[1,1,1];return t.attenuationColor=new c.Color().setRGB(i[0],i[1],i[2],c.LinearSRGBColorSpace),Promise.all(n)}}class fo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_IOR}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);return s===null||(t.ior=s.ior!==void 0?s.ior:1.5,t.ior===0&&(t.ior=1e3)),Promise.resolve()}}class ho{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_SPECULAR}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];t.specularIntensity=s.specularFactor!==void 0?s.specularFactor:1,s.specularTexture!==void 0&&n.push(this.parser.assignTexture(t,"specularIntensityMap",s.specularTexture));const i=s.specularColorFactor||[1,1,1];return t.specularColor=new c.Color().setRGB(i[0],i[1],i[2],c.LinearSRGBColorSpace),s.specularColorTexture!==void 0&&n.push(this.parser.assignTexture(t,"specularColorMap",s.specularColorTexture,c.SRGBColorSpace)),Promise.all(n)}}class po{constructor(e){this.parser=e,this.name=G.EXT_MATERIALS_BUMP}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];return t.bumpScale=s.bumpFactor!==void 0?s.bumpFactor:1,s.bumpTexture!==void 0&&n.push(this.parser.assignTexture(t,"bumpMap",s.bumpTexture)),Promise.all(n)}}class mo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];return s.anisotropyStrength!==void 0&&(t.anisotropy=s.anisotropyStrength),s.anisotropyRotation!==void 0&&(t.anisotropyRotation=s.anisotropyRotation),s.anisotropyTexture!==void 0&&n.push(this.parser.assignTexture(t,"anisotropyMap",s.anisotropyTexture)),Promise.all(n)}}class Ao{constructor(e){this.parser=e,this.name=G.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const i=n.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,o)}}class go{constructor(e){this.parser=e,this.name=G.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],l=n.images[o.source];let u=s.textureLoader;if(l.uri){const d=s.options.manager.getHandler(l.uri);d!==null&&(u=d)}return s.loadTextureImage(e,o.source,u)}}class yo{constructor(e){this.parser=e,this.name=G.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],l=n.images[o.source];let u=s.textureLoader;if(l.uri){const d=s.options.manager.getHandler(l.uri);d!==null&&(u=d)}return s.loadTextureImage(e,o.source,u)}}class Rn{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const n=s.extensions[this.name],i=this.parser.getDependency("buffer",n.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(l){const u=n.byteOffset||0,d=n.byteLength||0,p=n.count,f=n.byteStride,g=new Uint8Array(l,u,d);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(p,f,g,n.mode,n.filter).then(function(y){return y.buffer}):o.ready.then(function(){const y=new ArrayBuffer(p*f);return o.decodeGltfBuffer(new Uint8Array(y),p,f,g,n.mode,n.filter),y})})}else return null}}class bo{constructor(e){this.name=G.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,s=t.nodes[e];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;const n=t.meshes[s.mesh];for(const d of n.primitives)if(d.mode!==ue.TRIANGLES&&d.mode!==ue.TRIANGLE_STRIP&&d.mode!==ue.TRIANGLE_FAN&&d.mode!==void 0)return null;const o=s.extensions[this.name].attributes,l=[],u={};for(const d in o)l.push(this.parser.getDependency("accessor",o[d]).then(p=>(u[d]=p,u[d])));return l.length<1?null:(l.push(this.parser.createNodeMesh(e)),Promise.all(l).then(d=>{const p=d.pop(),f=p.isGroup?p.children:[p],g=d[0].count,y=[];for(const x of f){const m=new c.Matrix4,A=new c.Vector3,M=new c.Quaternion,v=new c.Vector3(1,1,1),w=new c.InstancedMesh(x.geometry,x.material,g);for(let h=0;h<g;h++)u.TRANSLATION&&A.fromBufferAttribute(u.TRANSLATION,h),u.ROTATION&&M.fromBufferAttribute(u.ROTATION,h),u.SCALE&&v.fromBufferAttribute(u.SCALE,h),w.setMatrixAt(h,m.compose(A,M,v));for(const h in u)if(h==="_COLOR_0"){const I=u[h];w.instanceColor=new c.InstancedBufferAttribute(I.array,I.itemSize,I.normalized)}else h!=="TRANSLATION"&&h!=="ROTATION"&&h!=="SCALE"&&x.geometry.setAttribute(h,u[h]);c.Object3D.prototype.copy.call(w,x),this.parser.assignFinalMaterial(w),y.push(w)}return p.isGroup?(p.clear(),p.add(...y),p):y[0]}))}}const _n="glTF",Ge=12,Pn={JSON:1313821514,BIN:5130562};class xo{constructor(e){this.name=G.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,Ge),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==_n)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const n=this.header.length-Ge,i=new DataView(e,Ge);let o=0;for(;o<n;){const l=i.getUint32(o,!0);o+=4;const u=i.getUint32(o,!0);if(o+=4,u===Pn.JSON){const d=new Uint8Array(e,Ge+o,l);this.content=s.decode(d)}else if(u===Pn.BIN){const d=Ge+o;this.body=e.slice(d,d+l)}o+=l}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Io{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=G.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,i=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,l={},u={},d={};for(const p in o){const f=Lt[p]||p.toLowerCase();l[f]=o[p]}for(const p in e.attributes){const f=Lt[p]||p.toLowerCase();if(o[p]!==void 0){const g=s.accessors[e.attributes[p]],y=Be[g.componentType];d[f]=y.name,u[f]=g.normalized===!0}}return t.getDependency("bufferView",i).then(function(p){return new Promise(function(f,g){n.decodeDracoFile(p,function(y){for(const x in y.attributes){const m=y.attributes[x],A=u[x];A!==void 0&&(m.normalized=A)}f(y)},l,d,c.LinearSRGBColorSpace,g)})})}}class Co{constructor(){this.name=G.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class Mo{constructor(){this.name=G.KHR_MESH_QUANTIZATION}}class $n extends c.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,i=e*n*3+n;for(let o=0;o!==n;o++)t[o]=s[i+o];return t}interpolate_(e,t,s,n){const i=this.resultBuffer,o=this.sampleValues,l=this.valueSize,u=l*2,d=l*3,p=n-t,f=(s-t)/p,g=f*f,y=g*f,x=e*d,m=x-d,A=-2*y+3*g,M=y-g,v=1-A,w=M-g+f;for(let h=0;h!==l;h++){const I=o[m+h+l],E=o[m+h+u]*p,N=o[x+h+l],D=o[x+h]*p;i[h]=v*I+w*E+A*N+M*D}return i}}const wo=new c.Quaternion;class vo extends $n{interpolate_(e,t,s,n){const i=super.interpolate_(e,t,s,n);return wo.fromArray(i).normalize().toArray(i),i}}const ue={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Be={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Ln={9728:c.NearestFilter,9729:c.LinearFilter,9984:c.NearestMipmapNearestFilter,9985:c.LinearMipmapNearestFilter,9986:c.NearestMipmapLinearFilter,9987:c.LinearMipmapLinearFilter},kn={33071:c.ClampToEdgeWrapping,33648:c.MirroredRepeatWrapping,10497:c.RepeatWrapping},Nt={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Lt={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},Me={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Eo={CUBICSPLINE:void 0,LINEAR:c.InterpolateLinear,STEP:c.InterpolateDiscrete},St={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function To(r){return r.DefaultMaterial===void 0&&(r.DefaultMaterial=new c.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:c.FrontSide})),r.DefaultMaterial}function Ne(r,e,t){for(const s in t.extensions)r[s]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[s]=t.extensions[s])}function Ae(r,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(r.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function Do(r,e,t){let s=!1,n=!1,i=!1;for(let d=0,p=e.length;d<p;d++){const f=e[d];if(f.POSITION!==void 0&&(s=!0),f.NORMAL!==void 0&&(n=!0),f.COLOR_0!==void 0&&(i=!0),s&&n&&i)break}if(!s&&!n&&!i)return Promise.resolve(r);const o=[],l=[],u=[];for(let d=0,p=e.length;d<p;d++){const f=e[d];if(s){const g=f.POSITION!==void 0?t.getDependency("accessor",f.POSITION):r.attributes.position;o.push(g)}if(n){const g=f.NORMAL!==void 0?t.getDependency("accessor",f.NORMAL):r.attributes.normal;l.push(g)}if(i){const g=f.COLOR_0!==void 0?t.getDependency("accessor",f.COLOR_0):r.attributes.color;u.push(g)}}return Promise.all([Promise.all(o),Promise.all(l),Promise.all(u)]).then(function(d){const p=d[0],f=d[1],g=d[2];return s&&(r.morphAttributes.position=p),n&&(r.morphAttributes.normal=f),i&&(r.morphAttributes.color=g),r.morphTargetsRelative=!0,r})}function No(r,e){if(r.updateMorphTargets(),e.weights!==void 0)for(let t=0,s=e.weights.length;t<s;t++)r.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(r.morphTargetInfluences.length===t.length){r.morphTargetDictionary={};for(let s=0,n=t.length;s<n;s++)r.morphTargetDictionary[t[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function So(r){let e;const t=r.extensions&&r.extensions[G.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Ot(t.attributes):e=r.indices+":"+Ot(r.attributes)+":"+r.mode,r.targets!==void 0)for(let s=0,n=r.targets.length;s<n;s++)e+=":"+Ot(r.targets[s]);return e}function Ot(r){let e="";const t=Object.keys(r).sort();for(let s=0,n=t.length;s<n;s++)e+=t[s]+":"+r[t[s]]+";";return e}function kt(r){switch(r){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function Oo(r){return r.search(/\.jpe?g($|\?)/i)>0||r.search(/^data\:image\/jpeg/)===0?"image/jpeg":r.search(/\.webp($|\?)/i)>0||r.search(/^data\:image\/webp/)===0?"image/webp":r.search(/\.ktx2($|\?)/i)>0||r.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const Ro=new c.Matrix4;class Po{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new to,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,n=-1,i=!1,o=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){const l=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(l)===!0;const u=l.match(/Version\/(\d+)/);n=s&&u?parseInt(u[1],10):-1,i=l.indexOf("Firefox")>-1,o=i?l.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||i&&o<98?this.textureLoader=new c.TextureLoader(this.options.manager):this.textureLoader=new c.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new c.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,n=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(o){const l={scene:o[0][n.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:n.asset,parser:s,userData:{}};return Ne(i,l,n),Ae(l,n),Promise.all(s._invokeAll(function(u){return u.afterRoot&&u.afterRoot(l)})).then(function(){for(const u of l.scenes)u.updateMatrixWorld();e(l)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let n=0,i=t.length;n<i;n++){const o=t[n].joints;for(let l=0,u=o.length;l<u;l++)e[o[l]].isBone=!0}for(let n=0,i=e.length;n<i;n++){const o=e[n];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(s[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const n=s.clone(),i=(o,l)=>{const u=this.associations.get(o);u!=null&&this.associations.set(l,u);for(const[d,p]of o.children.entries())i(p,l.children[d])};return i(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const i=e(t[n]);i&&s.push(i)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this._invokeOne(function(i){return i.loadNode&&i.loadNode(t)});break;case"mesh":n=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(t)});break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(t)});break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(t)});break;case"texture":n=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(t)});break;case"skin":n=this.loadSkin(t);break;case"animation":n=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(t)});break;case"camera":n=this.loadCamera(t);break;default:if(n=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(e,t)}),!n)throw new Error("Unknown type: "+e);break}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(n.map(function(i,o){return s.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],s=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[G.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(i,o){s.load(c.LoaderUtils.resolveURL(t.uri,n.path),i,void 0,function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(s){const n=t.byteLength||0,i=t.byteOffset||0;return s.slice(i,i+n)})}loadAccessor(e){const t=this,s=this.json,n=this.json.accessors[e];if(n.bufferView===void 0&&n.sparse===void 0){const o=Nt[n.type],l=Be[n.componentType],u=n.normalized===!0,d=new l(n.count*o);return Promise.resolve(new c.BufferAttribute(d,o,u))}const i=[];return n.bufferView!==void 0?i.push(this.getDependency("bufferView",n.bufferView)):i.push(null),n.sparse!==void 0&&(i.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(i).then(function(o){const l=o[0],u=Nt[n.type],d=Be[n.componentType],p=d.BYTES_PER_ELEMENT,f=p*u,g=n.byteOffset||0,y=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,x=n.normalized===!0;let m,A;if(y&&y!==f){const M=Math.floor(g/y),v="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+M+":"+n.count;let w=t.cache.get(v);w||(m=new d(l,M*y,n.count*y/p),w=new c.InterleavedBuffer(m,y/p),t.cache.add(v,w)),A=new c.InterleavedBufferAttribute(w,u,g%y/p,x)}else l===null?m=new d(n.count*u):m=new d(l,g,n.count*u),A=new c.BufferAttribute(m,u,x);if(n.sparse!==void 0){const M=Nt.SCALAR,v=Be[n.sparse.indices.componentType],w=n.sparse.indices.byteOffset||0,h=n.sparse.values.byteOffset||0,I=new v(o[1],w,n.sparse.count*M),E=new d(o[2],h,n.sparse.count*u);l!==null&&(A=new c.BufferAttribute(A.array.slice(),A.itemSize,A.normalized)),A.normalized=!1;for(let N=0,D=I.length;N<D;N++){const V=I[N];if(A.setX(V,E[N*u]),u>=2&&A.setY(V,E[N*u+1]),u>=3&&A.setZ(V,E[N*u+2]),u>=4&&A.setW(V,E[N*u+3]),u>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}A.normalized=x}return A})}loadTexture(e){const t=this.json,s=this.options,i=t.textures[e].source,o=t.images[i];let l=this.textureLoader;if(o.uri){const u=s.manager.getHandler(o.uri);u!==null&&(l=u)}return this.loadTextureImage(e,i,l)}loadTextureImage(e,t,s){const n=this,i=this.json,o=i.textures[e],l=i.images[t],u=(l.uri||l.bufferView)+":"+o.sampler;if(this.textureCache[u])return this.textureCache[u];const d=this.loadImageSource(t,s).then(function(p){p.flipY=!1,p.name=o.name||l.name||"",p.name===""&&typeof l.uri=="string"&&l.uri.startsWith("data:image/")===!1&&(p.name=l.uri);const g=(i.samplers||{})[o.sampler]||{};return p.magFilter=Ln[g.magFilter]||c.LinearFilter,p.minFilter=Ln[g.minFilter]||c.LinearMipmapLinearFilter,p.wrapS=kn[g.wrapS]||c.RepeatWrapping,p.wrapT=kn[g.wrapT]||c.RepeatWrapping,p.generateMipmaps=!p.isCompressedTexture&&p.minFilter!==c.NearestFilter&&p.minFilter!==c.LinearFilter,n.associations.set(p,{textures:e}),p}).catch(function(){return null});return this.textureCache[u]=d,d}loadImageSource(e,t){const s=this,n=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(f=>f.clone());const o=n.images[e],l=self.URL||self.webkitURL;let u=o.uri||"",d=!1;if(o.bufferView!==void 0)u=s.getDependency("bufferView",o.bufferView).then(function(f){d=!0;const g=new Blob([f],{type:o.mimeType});return u=l.createObjectURL(g),u});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const p=Promise.resolve(u).then(function(f){return new Promise(function(g,y){let x=g;t.isImageBitmapLoader===!0&&(x=function(m){const A=new c.Texture(m);A.needsUpdate=!0,g(A)}),t.load(c.LoaderUtils.resolveURL(f,i.path),x,void 0,y)})}).then(function(f){return d===!0&&l.revokeObjectURL(u),Ae(f,o),f.userData.mimeType=o.mimeType||Oo(o.uri),f}).catch(function(f){throw console.error("THREE.GLTFLoader: Couldn't load texture",u),f});return this.sourceCache[e]=p,p}assignTexture(e,t,s,n){const i=this;return this.getDependency("texture",s.index).then(function(o){if(!o)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(o=o.clone(),o.channel=s.texCoord),i.extensions[G.KHR_TEXTURE_TRANSFORM]){const l=s.extensions!==void 0?s.extensions[G.KHR_TEXTURE_TRANSFORM]:void 0;if(l){const u=i.associations.get(o);o=i.extensions[G.KHR_TEXTURE_TRANSFORM].extendTexture(o,l),i.associations.set(o,u)}}return n!==void 0&&(o.colorSpace=n),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let s=e.material;const n=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){const l="PointsMaterial:"+s.uuid;let u=this.cache.get(l);u||(u=new c.PointsMaterial,c.Material.prototype.copy.call(u,s),u.color.copy(s.color),u.map=s.map,u.sizeAttenuation=!1,this.cache.add(l,u)),s=u}else if(e.isLine){const l="LineBasicMaterial:"+s.uuid;let u=this.cache.get(l);u||(u=new c.LineBasicMaterial,c.Material.prototype.copy.call(u,s),u.color.copy(s.color),u.map=s.map,this.cache.add(l,u)),s=u}if(n||i||o){let l="ClonedMaterial:"+s.uuid+":";n&&(l+="derivative-tangents:"),i&&(l+="vertex-colors:"),o&&(l+="flat-shading:");let u=this.cache.get(l);u||(u=s.clone(),i&&(u.vertexColors=!0),o&&(u.flatShading=!0),n&&(u.normalScale&&(u.normalScale.y*=-1),u.clearcoatNormalScale&&(u.clearcoatNormalScale.y*=-1)),this.cache.add(l,u),this.associations.set(u,this.associations.get(s))),s=u}e.material=s}getMaterialType(){return c.MeshStandardMaterial}loadMaterial(e){const t=this,s=this.json,n=this.extensions,i=s.materials[e];let o;const l={},u=i.extensions||{},d=[];if(u[G.KHR_MATERIALS_UNLIT]){const f=n[G.KHR_MATERIALS_UNLIT];o=f.getMaterialType(),d.push(f.extendParams(l,i,t))}else{const f=i.pbrMetallicRoughness||{};if(l.color=new c.Color(1,1,1),l.opacity=1,Array.isArray(f.baseColorFactor)){const g=f.baseColorFactor;l.color.setRGB(g[0],g[1],g[2],c.LinearSRGBColorSpace),l.opacity=g[3]}f.baseColorTexture!==void 0&&d.push(t.assignTexture(l,"map",f.baseColorTexture,c.SRGBColorSpace)),l.metalness=f.metallicFactor!==void 0?f.metallicFactor:1,l.roughness=f.roughnessFactor!==void 0?f.roughnessFactor:1,f.metallicRoughnessTexture!==void 0&&(d.push(t.assignTexture(l,"metalnessMap",f.metallicRoughnessTexture)),d.push(t.assignTexture(l,"roughnessMap",f.metallicRoughnessTexture))),o=this._invokeOne(function(g){return g.getMaterialType&&g.getMaterialType(e)}),d.push(Promise.all(this._invokeAll(function(g){return g.extendMaterialParams&&g.extendMaterialParams(e,l)})))}i.doubleSided===!0&&(l.side=c.DoubleSide);const p=i.alphaMode||St.OPAQUE;if(p===St.BLEND?(l.transparent=!0,l.depthWrite=!1):(l.transparent=!1,p===St.MASK&&(l.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&o!==c.MeshBasicMaterial&&(d.push(t.assignTexture(l,"normalMap",i.normalTexture)),l.normalScale=new c.Vector2(1,1),i.normalTexture.scale!==void 0)){const f=i.normalTexture.scale;l.normalScale.set(f,f)}if(i.occlusionTexture!==void 0&&o!==c.MeshBasicMaterial&&(d.push(t.assignTexture(l,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(l.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&o!==c.MeshBasicMaterial){const f=i.emissiveFactor;l.emissive=new c.Color().setRGB(f[0],f[1],f[2],c.LinearSRGBColorSpace)}return i.emissiveTexture!==void 0&&o!==c.MeshBasicMaterial&&d.push(t.assignTexture(l,"emissiveMap",i.emissiveTexture,c.SRGBColorSpace)),Promise.all(d).then(function(){const f=new o(l);return i.name&&(f.name=i.name),Ae(f,i),t.associations.set(f,{materials:e}),i.extensions&&Ne(n,f,i),f})}createUniqueName(e){const t=c.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,s=this.extensions,n=this.primitiveCache;function i(l){return s[G.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(l,t).then(function(u){return Vn(u,l,t)})}const o=[];for(let l=0,u=e.length;l<u;l++){const d=e[l],p=So(d),f=n[p];if(f)o.push(f.promise);else{let g;d.extensions&&d.extensions[G.KHR_DRACO_MESH_COMPRESSION]?g=i(d):g=Vn(new c.BufferGeometry,d,t),n[p]={primitive:d,promise:g},o.push(g)}}return Promise.all(o)}loadMesh(e){const t=this,s=this.json,n=this.extensions,i=s.meshes[e],o=i.primitives,l=[];for(let u=0,d=o.length;u<d;u++){const p=o[u].material===void 0?To(this.cache):this.getDependency("material",o[u].material);l.push(p)}return l.push(t.loadGeometries(o)),Promise.all(l).then(function(u){const d=u.slice(0,u.length-1),p=u[u.length-1],f=[];for(let y=0,x=p.length;y<x;y++){const m=p[y],A=o[y];let M;const v=d[y];if(A.mode===ue.TRIANGLES||A.mode===ue.TRIANGLE_STRIP||A.mode===ue.TRIANGLE_FAN||A.mode===void 0)M=i.isSkinnedMesh===!0?new c.SkinnedMesh(m,v):new c.Mesh(m,v),M.isSkinnedMesh===!0&&M.normalizeSkinWeights(),A.mode===ue.TRIANGLE_STRIP?M.geometry=On(M.geometry,c.TriangleStripDrawMode):A.mode===ue.TRIANGLE_FAN&&(M.geometry=On(M.geometry,c.TriangleFanDrawMode));else if(A.mode===ue.LINES)M=new c.LineSegments(m,v);else if(A.mode===ue.LINE_STRIP)M=new c.Line(m,v);else if(A.mode===ue.LINE_LOOP)M=new c.LineLoop(m,v);else if(A.mode===ue.POINTS)M=new c.Points(m,v);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+A.mode);Object.keys(M.geometry.morphAttributes).length>0&&No(M,i),M.name=t.createUniqueName(i.name||"mesh_"+e),Ae(M,i),A.extensions&&Ne(n,M,A),t.assignFinalMaterial(M),f.push(M)}for(let y=0,x=f.length;y<x;y++)t.associations.set(f[y],{meshes:e,primitives:y});if(f.length===1)return i.extensions&&Ne(n,f[0],i),f[0];const g=new c.Group;i.extensions&&Ne(n,g,i),t.associations.set(g,{meshes:e});for(let y=0,x=f.length;y<x;y++)g.add(f[y]);return g})}loadCamera(e){let t;const s=this.json.cameras[e],n=s[s.type];if(!n){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?t=new c.PerspectiveCamera(c.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(t=new c.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(t.name=this.createUniqueName(s.name)),Ae(t,s),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],s=[];for(let n=0,i=t.joints.length;n<i;n++)s.push(this._loadNodeShallow(t.joints[n]));return t.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",t.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(n){const i=n.pop(),o=n,l=[],u=[];for(let d=0,p=o.length;d<p;d++){const f=o[d];if(f){l.push(f);const g=new c.Matrix4;i!==null&&g.fromArray(i.array,d*16),u.push(g)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[d])}return new c.Skeleton(l,u)})}loadAnimation(e){const t=this.json,s=this,n=t.animations[e],i=n.name?n.name:"animation_"+e,o=[],l=[],u=[],d=[],p=[];for(let f=0,g=n.channels.length;f<g;f++){const y=n.channels[f],x=n.samplers[y.sampler],m=y.target,A=m.node,M=n.parameters!==void 0?n.parameters[x.input]:x.input,v=n.parameters!==void 0?n.parameters[x.output]:x.output;m.node!==void 0&&(o.push(this.getDependency("node",A)),l.push(this.getDependency("accessor",M)),u.push(this.getDependency("accessor",v)),d.push(x),p.push(m))}return Promise.all([Promise.all(o),Promise.all(l),Promise.all(u),Promise.all(d),Promise.all(p)]).then(function(f){const g=f[0],y=f[1],x=f[2],m=f[3],A=f[4],M=[];for(let w=0,h=g.length;w<h;w++){const I=g[w],E=y[w],N=x[w],D=m[w],V=A[w];if(I===void 0)continue;I.updateMatrix&&I.updateMatrix();const W=s._createAnimationTracks(I,E,N,D,V);if(W)for(let Y=0;Y<W.length;Y++)M.push(W[Y])}const v=new c.AnimationClip(i,void 0,M);return Ae(v,n),v})}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return n.mesh===void 0?null:s.getDependency("mesh",n.mesh).then(function(i){const o=s._getNodeRef(s.meshCache,n.mesh,i);return n.weights!==void 0&&o.traverse(function(l){if(l.isMesh)for(let u=0,d=n.weights.length;u<d;u++)l.morphTargetInfluences[u]=n.weights[u]}),o})}loadNode(e){const t=this.json,s=this,n=t.nodes[e],i=s._loadNodeShallow(e),o=[],l=n.children||[];for(let d=0,p=l.length;d<p;d++)o.push(s.getDependency("node",l[d]));const u=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([i,Promise.all(o),u]).then(function(d){const p=d[0],f=d[1],g=d[2];g!==null&&p.traverse(function(y){y.isSkinnedMesh&&y.bind(g,Ro)});for(let y=0,x=f.length;y<x;y++)p.add(f[y]);if(p.userData.pivot!==void 0&&f.length>0){const y=p.userData.pivot,x=f[0];p.pivot=new c.Vector3().fromArray(y),p.position.x-=y[0],p.position.y-=y[1],p.position.z-=y[2],x.position.set(0,0,0),delete p.userData.pivot}return p})}_loadNodeShallow(e){const t=this.json,s=this.extensions,n=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const i=t.nodes[e],o=i.name?n.createUniqueName(i.name):"",l=[],u=n._invokeOne(function(d){return d.createNodeMesh&&d.createNodeMesh(e)});return u&&l.push(u),i.camera!==void 0&&l.push(n.getDependency("camera",i.camera).then(function(d){return n._getNodeRef(n.cameraCache,i.camera,d)})),n._invokeAll(function(d){return d.createNodeAttachment&&d.createNodeAttachment(e)}).forEach(function(d){l.push(d)}),this.nodeCache[e]=Promise.all(l).then(function(d){let p;if(i.isBone===!0?p=new c.Bone:d.length>1?p=new c.Group:d.length===1?p=d[0]:p=new c.Object3D,p!==d[0])for(let f=0,g=d.length;f<g;f++)p.add(d[f]);if(i.name&&(p.userData.name=i.name,p.name=o),Ae(p,i),i.extensions&&Ne(s,p,i),i.matrix!==void 0){const f=new c.Matrix4;f.fromArray(i.matrix),p.applyMatrix4(f)}else i.translation!==void 0&&p.position.fromArray(i.translation),i.rotation!==void 0&&p.quaternion.fromArray(i.rotation),i.scale!==void 0&&p.scale.fromArray(i.scale);if(!n.associations.has(p))n.associations.set(p,{});else if(i.mesh!==void 0&&n.meshCache.refs[i.mesh]>1){const f=n.associations.get(p);n.associations.set(p,{...f})}return n.associations.get(p).nodes=e,p}),this.nodeCache[e]}loadScene(e){const t=this.extensions,s=this.json.scenes[e],n=this,i=new c.Group;s.name&&(i.name=n.createUniqueName(s.name)),Ae(i,s),s.extensions&&Ne(t,i,s);const o=s.nodes||[],l=[];for(let u=0,d=o.length;u<d;u++)l.push(n.getDependency("node",o[u]));return Promise.all(l).then(function(u){for(let p=0,f=u.length;p<f;p++){const g=u[p];g.parent!==null?i.add(eo(g)):i.add(g)}const d=p=>{const f=new Map;for(const[g,y]of n.associations)(g instanceof c.Material||g instanceof c.Texture)&&f.set(g,y);return p.traverse(g=>{const y=n.associations.get(g);y!=null&&f.set(g,y)}),f};return n.associations=d(i),i})}_createAnimationTracks(e,t,s,n,i){const o=[],l=e.name?e.name:e.uuid,u=[];function d(y){y.morphTargetInfluences&&u.push(y.name?y.name:y.uuid)}Me[i.path]===Me.weights?(d(e),e.isGroup&&e.children.forEach(d)):u.push(l);let p;switch(Me[i.path]){case Me.weights:p=c.NumberKeyframeTrack;break;case Me.rotation:p=c.QuaternionKeyframeTrack;break;case Me.translation:case Me.scale:p=c.VectorKeyframeTrack;break;default:switch(s.itemSize){case 1:p=c.NumberKeyframeTrack;break;case 2:case 3:default:p=c.VectorKeyframeTrack;break}break}const f=n.interpolation!==void 0?Eo[n.interpolation]:c.InterpolateLinear,g=this._getArrayFromAccessor(s);for(let y=0,x=u.length;y<x;y++){const m=new p(u[y]+"."+Me[i.path],t.array,g,f);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(m),o.push(m)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const s=kt(t.constructor),n=new Float32Array(t.length);for(let i=0,o=t.length;i<o;i++)n[i]=t[i]*s;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(s){const n=this instanceof c.QuaternionKeyframeTrack?vo:$n;return new n(this.times,this.values,this.getValueSize()/3,s)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Lo(r,e,t){const s=e.attributes,n=new c.Box3;if(s.POSITION!==void 0){const l=t.json.accessors[s.POSITION],u=l.min,d=l.max;if(u!==void 0&&d!==void 0){if(n.set(new c.Vector3(u[0],u[1],u[2]),new c.Vector3(d[0],d[1],d[2])),l.normalized){const p=kt(Be[l.componentType]);n.min.multiplyScalar(p),n.max.multiplyScalar(p)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=e.targets;if(i!==void 0){const l=new c.Vector3,u=new c.Vector3;for(let d=0,p=i.length;d<p;d++){const f=i[d];if(f.POSITION!==void 0){const g=t.json.accessors[f.POSITION],y=g.min,x=g.max;if(y!==void 0&&x!==void 0){if(u.setX(Math.max(Math.abs(y[0]),Math.abs(x[0]))),u.setY(Math.max(Math.abs(y[1]),Math.abs(x[1]))),u.setZ(Math.max(Math.abs(y[2]),Math.abs(x[2]))),g.normalized){const m=kt(Be[g.componentType]);u.multiplyScalar(m)}l.max(u)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}n.expandByVector(l)}r.boundingBox=n;const o=new c.Sphere;n.getCenter(o.center),o.radius=n.min.distanceTo(n.max)/2,r.boundingSphere=o}function Vn(r,e,t){const s=e.attributes,n=[];function i(o,l){return t.getDependency("accessor",o).then(function(u){r.setAttribute(l,u)})}for(const o in s){const l=Lt[o]||o.toLowerCase();l in r.attributes||n.push(i(s[o],l))}if(e.indices!==void 0&&!r.index){const o=t.getDependency("accessor",e.indices).then(function(l){r.setIndex(l)});n.push(o)}return c.ColorManagement.workingColorSpace!==c.LinearSRGBColorSpace&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${c.ColorManagement.workingColorSpace}" not supported.`),Ae(r,e),Lo(r,e,t),Promise.all(n).then(function(){return e.targets!==void 0?Do(r,e.targets,t):r})}let Vt=null;function ko(r){Vt=r}const pe=a.reactive({scripts:[]});function es(){return"s_"+Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4)}function Vo(r){var t;const e={id:es(),name:((t=r==null?void 0:r.name)==null?void 0:t.trim())??"",code:r==null?void 0:r.code};return pe.scripts.push(e),e}function Ho(r){const e=pe.scripts.findIndex(t=>t.id===r);e!==-1&&pe.scripts.splice(e,1)}function Bo(r){pe.scripts=(r||[]).map(e=>({id:(e==null?void 0:e.id)||es(),name:(e==null?void 0:e.name)??"",code:(e==null?void 0:e.code)??""}))}function jo(){pe.scripts=[]}function Fo(r){const e=pe.scripts.find(t=>t.id===r);if(e){if(!Vt){console.warn("[脚本] 执行器尚未注册,请先初始化编辑器(initEditor)");return}try{Vt(e)}catch(t){console.error("[脚本] 执行出错:",e.name,t)}}}function ts(r){var e;return!!r&&((e=r.name)==null?void 0:e.trim())==="初始化"}function Uo(r,e=0){var n,i;if(r.name&&r.name.trim())return r.name.trim();const t=(n=r.code)==null?void 0:n.match(/function\s+([A-Za-z_$][\w$]*)\s*\(/);if(t)return t[1];const s=(i=r.code)==null?void 0:i.match(/(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s*)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)\s*=>/);return s?s[1]:`脚本${e+1}`}const C={mode:"",transformControlsMode:"translate",scene:null,camera:null,defaultMainCamera:null,renderer:null,orbitControls:null,transformControls:null,container:null,gridHelper:null,selectedObject:null};let dt=!1,Re=!1,we=null;const Go=16755200;let Ht=[],at=[],Ze=!0;const xt=-1;let Oe=null,de=null,ft=null,ve=[];const Pe=new Map;let Qe,ht=null,Xe=null,Ye=null;async function ns(r,e="edit",t){C.container=r,C.mode=e,Wo(),Xo(),Ko(),t&&(await ys(t.scene,e,t.dataPanels,t.waters,t.textures,t.ambientLight,t.scripts),t!=null&&t.camera&&(C.defaultMainCamera=t.camera,Wt(!0))),Qo(),Zo(),Qe&&C.orbitControls&&(C.orbitControls.target.fromArray(Qe),C.orbitControls.update()),qo(),Bt(),is(),Xe=s=>$o(s),Ye=()=>_o(),e==="edit"&&r.addEventListener("click",Xe),window.addEventListener("resize",Ye),t||Jo(),e==="edit"&&Yo(),hr()}function zo(){return window.devicePixelRatio}function Wo(){const r=zo(),e=new O.WebGLRenderer({antialias:!0,alpha:!0});e.setSize(C.container.clientWidth,C.container.clientHeight),e.setPixelRatio(r),e.toneMapping=O.NeutralToneMapping,e.toneMappingExposure=1,console.log(`[Renderer] css=${C.container.clientWidth}×${C.container.clientHeight}, dpr=${window.devicePixelRatio}, targetRatio=${r}, antialias=true`),C.container.appendChild(e.domElement),C.renderer=e}function qo(){if(!C.renderer||!C.scene||!C.camera)return;const r=C.renderer.getPixelRatio(),e=C.container.clientWidth*r,t=C.container.clientHeight*r,s=new O.WebGLRenderTarget(e,t,{type:O.HalfFloatType,samples:4});s.texture.name="EffectComposer.rt1";const n=new pi(C.renderer,s);n.addPass(new mi(C.scene,C.camera)),n.addPass(new Ai),we=n}function Xo(){if(C.scene=new O.Scene,C.scene.name="sl_scene",C.renderer){const r=ut(C.renderer);r?(C.scene.environment=r,C.scene.environmentIntensity=1):console.warn("[初始化] 环境贴图生成失败,场景将没有 IBL 间接光照")}}function Yo(){const r=new O.GridHelper(30,30,8956671,3364232);r.name="地板",r.userData.type="initFloor",C.scene.add(r),C.gridHelper=r}function Ko(){const r=C.container,e=r.clientWidth/r.clientHeight,t=new O.PerspectiveCamera(45,e,.1,1e3);t.position.set(0,6,15),t.lookAt(0,0,0),C.camera=t}function Wt(r=!1){if(!C.defaultMainCamera)return;const e=C.defaultMainCamera;if(r){C.camera.position.set(e.position[0],e.position[1],e.position[2]),C.camera.rotation.set(e.rotation[0],e.rotation[1],e.rotation[2]),C.camera.updateProjectionMatrix(),Qe=e.target;return}else Yt(""),gt();if(!C.camera||!C.orbitControls)return;const t=C.camera.position.clone(),s=C.orbitControls.target.clone(),n=new O.Vector3(e.position[0],e.position[1],e.position[2]),i=e.target?new O.Vector3(e.target[0],e.target[1],e.target[2]):new O.Vector3(0,0,0);C.orbitControls.enabled=!1,new se.Tween({x:t.x,y:t.y,z:t.z,tx:s.x,ty:s.y,tz:s.z}).to({x:n.x,y:n.y,z:n.z,tx:i.x,ty:i.y,tz:i.z},1e3).easing(se.Easing.Quadratic.InOut).onUpdate(o=>{C.camera.position.set(o.x,o.y,o.z),C.orbitControls.target.set(o.tx,o.ty,o.tz),C.orbitControls.update()}).onComplete(()=>{Qe=e.target,C.orbitControls.enabled=!0}).start()}function Zo(){const r=new Fs(C.camera,C.renderer.domElement);r.minDistance=0,r.maxDistance=1/0,r.addEventListener("start",()=>{dt=!1}),r.addEventListener("change",()=>{dt=!0}),r.addEventListener("end",()=>{dt&&(Re=!0,setTimeout(()=>{Re=!1},200))}),C.orbitControls=r}function Qo(){const r=new $s(C.camera,C.renderer.domElement);r.addEventListener("dragging-changed",e=>{C.orbitControls.enabled=!e.value,e.value||(Re=!0,setTimeout(()=>{Re=!1},200))}),r.addEventListener("objectChange",()=>{const e=C.selectedObject;if(de&&e&&de(e),e&&e.type==="DirectionalLight"){const t=e.userData.helper;t&&t.update&&t.update()}}),C.scene.add(r.getHelper()),C.transformControls=r}function ss(r=C.scene){if(!r||r.children.some(t=>t.type==="AmbientLight"))return null;const e=new O.AmbientLight(pr,mr);return e.name="环境光",r.add(e),e}function Jo(){ss(C.scene)}function is(){var e,t;ht=requestAnimationFrame(is),se.update(),(e=C.orbitControls)==null||e.update(),C.mode==="run"&&we&&C.scene&&C.camera?we.render():(t=C.renderer)==null||t.render(C.scene,C.camera),C.scene&&C.camera&&Xn(C.scene,C.camera),Ze&&C.scene&&(at=[],C.scene.traverse(s=>{s.userData.isWater&&s.type==="Mesh"&&at.push(s)}),Ze=!1);for(let s=0;s<at.length;s++){const n=at[s],i=n.material;if(i.uniforms&&i.uniforms.time){const o=n.userData.waterTimeScale??1;i.uniforms.time.value+=1/60*o,C.camera&&i.uniforms.eye&&i.uniforms.eye.value.copy(C.camera.position);continue}if(i.normalMap){const o=n.userData.waterSpeed||{x:.005,y:.003};i.normalMap.offset.x+=o.x,i.normalMap.offset.y+=o.y}}}function _o(){if(!C.container||!C.camera||!C.renderer)return;const r=C.container.clientWidth,e=C.container.clientHeight;r===0||e===0||(C.camera.aspect=r/e,C.camera.updateProjectionMatrix(),C.renderer.setSize(r,e),we&&we.setSize(r,e),Yn(r,e))}function _e(r){let e=r;for(;e;){if(e.isTransformControlsRoot)return;e=e.parent}C.selectedObject!==r&&(C.selectedObject&&C.transformControls.detach(),C.selectedObject=r,C.transformControls.attach(r),C.transformControls.setMode(C.transformControlsMode),C.transformControls.showX=!0,C.transformControls.showY=!0,C.transformControls.showZ=!0,rs(r),Oe==null||Oe(r))}let ae=null;function os(r){ae=r}function pt(r){ae==null||ae(r)}function qt(r){C.transformControlsMode=r,C.transformControls&&C.transformControls.setMode(C.transformControlsMode)}function rs(r){if(C.mode!=="edit"){gt();return}gt(),r.traverse(e=>{if(e.isMesh){const t=e,s=new O.EdgesGeometry(t.geometry),n=new O.LineBasicMaterial({color:Go,depthTest:!0}),i=new O.LineSegments(s,n);e.add(i),Ht.push(i)}})}function gt(){for(const r of Ht)r.parent&&r.parent.remove(r),r.geometry.dispose(),r.material.dispose();Ht=[]}function Xt(){C.selectedObject&&(gt(),C.transformControls.detach(),C.selectedObject=null,Oe==null||Oe(null))}function Yt(r){let e=null;Pe.forEach(t=>{t.userData.id==r&&(e=t),t.children&&t.children.forEach(s=>{s.name&&s.name.startsWith("DataPanel_")&&(s.visible=!1)})}),e&&(e.children.forEach(t=>{t.name&&t.name.startsWith("DataPanel_")&&(t.visible=!0)}),rs(e),C.selectedObject=e,setTimeout(()=>{Kt(e)},500))}function $o(r){if(Re){Re=!1;return}const e=er(r);e?_e(e):Xt()}function er(r){const e=C.renderer.domElement.getBoundingClientRect(),t=new O.Vector2((r.clientX-e.left)/e.width*2-1,-((r.clientY-e.top)/e.height)*2+1),s=new O.Raycaster;s.setFromCamera(t,C.camera);const n=[],i=l=>{l.isTransformControlsRoot||l.isLine||l.isLineSegments||((l.userData.isMovable||l.userData.type==="lightHelper")&&n.push(l),l.children.forEach(i))};i(C.scene);const o=s.intersectObjects(n);if(o.length===0)return null;for(const l of o){const u=Hn(l.object);if(u!==C.selectedObject)return u}return Hn(o[0].object)}function Hn(r){var t;let e=r;for(;e;){if(((t=e.userData)==null?void 0:t.type)==="lightHelper"||e.type==="DirectionalLightHelper")return e.light||e;e=e.parent}if(r.type==="Line"||r.type==="LineSegments"){const s=r.parent;if(s)switch(s.type){case"DirectionalLightHelper":return s.light;case"AmbientLight":return s;default:return s.isMesh?s:r}return r}return r}function Kt(r,e=500){if(!C.camera||!C.orbitControls){console.warn("[focusOnObject] 编辑器尚未初始化或已销毁,无法执行聚焦操作。请确保已调用 initEditor()");return}if(!r){console.warn("[focusOnObject] 传入的物体为空,无法执行聚焦操作。");return}let t=null;r.userData.closeUpView&&typeof r.userData.closeUpView.x=="number"&&typeof r.userData.closeUpView.y=="number"&&typeof r.userData.closeUpView.z=="number"&&(t=r.userData.closeUpView);const s=new O.Vector3;r.getWorldPosition(s);const i=new O.Box3().setFromObject(r).getSize(new O.Vector3),o=Math.max(i.x,i.y,i.z)*.5,l=Math.max(o*3.5,5),u=new O.Vector3().copy(C.camera.position).sub(s).normalize();u.lengthSq()<.001&&u.set(0,0,1);const d=s.clone().add(u.multiplyScalar(l)),p=C.camera.position.clone(),f=C.orbitControls.target.clone();try{new se.Tween({x:p.x,y:p.y,z:p.z,tx:f.x,ty:f.y,tz:f.z}).to({x:t?t.x:d.x,y:t?t.y:d.y,z:t?t.z:d.z,tx:s.x,ty:s.y,tz:s.z},e).easing(se.Easing.Quadratic.InOut).onUpdate(g=>{C.camera.position.set(g.x,g.y,g.z),C.orbitControls.target.set(g.tx,g.ty,g.tz),C.orbitControls.update()}).start()}catch(g){console.error("[focusOnObject] TWEEN 动画创建失败,请检查 @tweenjs/tween.js 是否已正确安装且版本兼容(^23.1.3):",g)}}function tr(r){r.userData.id&&Pe.set(String(r.userData.id),r)}function nr(r){r.userData.id&&Pe.delete(String(r.userData.id))}function as(r,e){const t=e||r.userData.id;if(t)Pe.set(String(t),r);else{const s=O.MathUtils.generateUUID();r.userData.id=s,Pe.set(s,r)}}function sr(r){r.traverse(e=>{if(e.name&&e.name.startsWith("DataPanel_")){const t=e;t.element&&t.element.parentNode&&t.element.parentNode.removeChild(t.element)}})}function ls(r){var s,n;const e=(s=C.scene)==null?void 0:s.environment;if(!e)return;const t=((n=C.scene)==null?void 0:n.environmentIntensity)??1;r.traverse(i=>{if(i.isMesh){const o=i,l=Array.isArray(o.material)?o.material:[o.material];for(const u of l){const d=u;d&&d.isMeshStandardMaterial&&!d.envMap&&(d.envMap=e,d.envMapIntensity=t,d.needsUpdate=!0)}}})}function ge(r,e=!1){C.scene.add(r),ls(r),Ze=!0,r.userData.isMovable&&(ir(r),It()),e&&C.mode==="edit"&&_e(r)}function Zt(r){C.selectedObject===r&&Xt(),Ze=!0,sr(r),nr(r),r.userData.helper&&C.scene.remove(r.userData.helper),r.parent?r.parent.remove(r):C.scene.remove(r),or(r),It()}function Qt(r){const e=C.scene.getObjectByProperty("uuid",r);e&&Zt(e)}function ir(r){r.userData.isMovable&&r.parent===C.scene&&(ve.includes(r)||ve.push(r))}function or(r){const e=ve.indexOf(r);e!==-1&&ve.splice(e,1)}function Bt(){const r=[];C.scene.children.forEach(e=>{e.userData.isMovable&&r.push(e)}),ve=r,It()}function It(){ft==null||ft([...ve])}function cs(r){Oe=r}function us(r){de=r}function ds(r){ft=r}function Jt(){return ve}function yt(){return C.selectedObject}function fs(r,e,t){if(!C.scene)return;const s=Pe.get(r);if(s){const n=je(s);n&&n.updateItemByCode(e,t)}}function jt(){return C.scene}function bt(){return C.camera}function Ft(){return C.renderer}const hs={linear:se.Easing.Linear.None,"quad.in":se.Easing.Quadratic.In,"quad.out":se.Easing.Quadratic.Out,"quad.inout":se.Easing.Quadratic.InOut,"cubic.inout":se.Easing.Cubic.InOut,"sine.inout":se.Easing.Sinusoidal.InOut,"back.out":se.Easing.Back.Out,"elastic.out":se.Easing.Elastic.Out,"bounce.out":se.Easing.Bounce.Out},Ut=new WeakMap;function ps(r){let e=Ut.get(r);return e||(e={position:new Set,rotation:new Set,scale:new Set,opacity:new Set},Ut.set(r,e)),e}function rr(r,e,t,s){const n=ps(r);for(const o of t)n[o].forEach(l=>l.stop()),n[o].clear(),n[o].add(e);const i=()=>{for(const o of t)n[o].delete(e)};e.onComplete(()=>{i(),s==null||s()}),e.onStop(i)}function _t(r,e=[]){if(!r)return;const t=Ut.get(r);if(!t)return;const s=e.length>0?e:["position","rotation","scale","opacity"];for(const n of s)t[n].forEach(i=>i.stop()),t[n].clear()}function ar(r){return r*Math.PI/180}function Ct(r,e={}){if(!r)return console.warn("[脚本动画] 目标对象为空,无法执行动画"),null;const t=e.duration??1e3,s=hs[e.easing??"quad.inout"]??se.Easing.Quadratic.InOut,n=[],i={};e.position&&(n.push("position"),i.position=e.position),e.rotation&&(n.push("rotation"),i.rotation=e.rotation),e.scale&&(n.push("scale"),i.scale=e.scale),_t(r,n);const o=new se.Tween(r).to(i,t).easing(s).onUpdate(()=>{r===C.selectedObject&&(de==null||de(r))}).start();return rr(r,o,n,()=>{var l;(l=e.onComplete)==null||l.call(e),r===C.selectedObject&&(de==null||de(r))}),o}function lr(r,e,t=1e3,s){return Ct(r,{position:e,duration:t,easing:s})}function cr(r,e,t=1e3,s){return Ct(r,{rotation:e,duration:t,easing:s})}function ur(r,e,t=1e3,s){return Ct(r,{scale:e,duration:t,easing:s})}const ms="__fadeToOrigin__",mt="__panelOriginTransparent__",Mt="__panelOpacity__";function dr(r,e,t=1e3,s,n){if(!r)return console.warn("[脚本动画] 目标对象为空,无法执行透明度动画"),null;const i=new Set;if(r.traverse(m=>{const A=m.material;if(!A)return;(Array.isArray(A)?A:[A]).forEach(v=>v&&i.add(v))}),i.size===0)return console.warn("[脚本动画] 目标及其子节点没有材质,无法执行透明度动画:",r.name),null;const o=t??1e3,l=hs[s??"quad.inout"]??se.Easing.Quadratic.InOut,u=Math.min(1,Math.max(0,e)),d=u<=.01;d||(r.visible=!0),_t(r,["opacity"]);const p=[...i],f=ms;p.forEach(m=>{const A=m.userData;!A[f]&&!m.uniforms&&(A[f]={transparent:m.transparent,opacity:m.opacity}),delete A[Mt]}),p.forEach(m=>{m.transparent=!0,m.uniforms||(m.depthWrite=!1),m.needsUpdate=!0}),C.renderer&&C.scene&&C.camera&&C.renderer.render(C.scene,C.camera);const g=ps(r),y=p.map(m=>{const A=new se.Tween(m).to({opacity:u},o).easing(l).start();return g.opacity.add(A),A}),x=()=>{p.forEach(m=>{if(m.uniforms)return;const M=m.userData[f];if(!M)return;!M.transparent&&m.transparent&&(m.transparent=!1,m.depthWrite=!0,m.needsUpdate=!0)})};return y.forEach((m,A)=>{A===0?m.onComplete(()=>{g.opacity.delete(m),!d&&u>=.999?x():d&&(x(),r.visible=!1),n==null||n(),r===C.selectedObject&&(de==null||de(r))}):m.onComplete(()=>g.opacity.delete(m)),m.onStop(()=>g.opacity.delete(m))}),y[0]??null}function fr(){return{THREE:O,scene:jt(),camera:bt(),renderer:Ft(),selectedObject:yt(),getScene:jt,getCamera:bt,getRenderer:Ft,getSelectedObject:yt,getSceneObjects:Jt,addModel:ge,removeModel:Zt,removeModelById:Qt,selectObject:_e,updateDataPanelValue:fs,setTransformMode:qt,focusOnObject:Kt,animateTo:Ct,moveTo:lr,rotateTo:cr,scaleTo:ur,fadeTo:dr,stopAnimations:_t,degToRad:ar,console,window,document,setTimeout,setInterval,requestAnimationFrame}}function As(r){var l;const e=(l=r==null?void 0:r.code)==null?void 0:l.trim();if(!e)return;const t=fr(),s=Object.keys(t),n=Object.values(t),i=/^\s*(?:async\s+)?function\s+[A-Za-z_$][\w$]*\s*\(/.test(e)||/^\s*(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*(?:async\s*)?(?:function\b|\([^)]*\)\s*=>|[A-Za-z_$][\w$]*\s*=>)/.test(e)||/^\s*[A-Za-z_$][\w$]*\s*=\s*(?:async\s*)?(?:function\b|\([^)]*\)\s*=>|[A-Za-z_$][\w$]*\s*=>)/.test(e)||/^\s*(?:async\s+)?\([^)]*\)\s*=>/.test(e);let o=null;if(i)try{const d=new Function(...s,`return (${e});`)(...n);typeof d=="function"&&(o=d)}catch{o=null}if(!o)try{o=new Function(...s,`return (function () { ${e}
138
+ `,e.appendChild(i)})}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}attachTo(e){this.attachedObject&&this.attachedObject!==e&&this.detach();const t=new O.Vector3;e.getWorldPosition(t);const i=new O.Box3().setFromObject(e).max.y-t.y+this.options.offsetY;this.css2dObject||(this.css2dObject=new gi(this.container),this.css2dObject.name=`DataPanel_${e.name||e.uuid}`,this.css2dObject.center.set(.5,1)),this.css2dObject.position.set(this.options.offsetX,i,this.options.offsetZ??0),e.add(this.css2dObject),this.attachedObject=e}detach(){this.css2dObject&&this.attachedObject&&this.attachedObject.remove(this.css2dObject),this.attachedObject=null}show(){this._visible=!0,this.css2dObject&&(this.css2dObject.visible=!0)}hide(){this._visible=!1,this.css2dObject&&(this.css2dObject.visible=!1)}get visible(){return this._visible}set visible(e){e?this.show():this.hide()}setTitle(e){var s;this.options.title=e;const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-title]");e?t?t.textContent=e:this.rebuildPanel():t&&t.remove()}getTitle(){return this.options.title||""}setItems(e){var s;this.options.items=[...e];const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}getItems(){return[...this.options.items||[]]}addItem(e){var s;this.options.items.push(e);const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}removeItem(e){var s;this.options.items=this.options.items.filter(n=>n.label!==e);const t=(s=this.container)==null?void 0:s.querySelector("[data-panel-list]");t&&this.renderItems(t,this.options.items)}updateItem(e,t,s){var i;const n=this.options.items.find(o=>o.label===e);if(n){n.value=t,s!==void 0&&(n.unit=s);const o=(i=this.container)==null?void 0:i.querySelector("[data-panel-list]");o&&this.renderItems(o,this.options.items)}}updateItemByCode(e,t){var n;const s=this.options.items.find(i=>i.code===e);if(s){s.value=t;const i=(n=this.container)==null?void 0:n.querySelector("[data-panel-list]");i&&this.renderItems(i,this.options.items)}}clearItems(){var t;this.options.items=[];const e=(t=this.container)==null?void 0:t.querySelector("[data-panel-list]");e&&this.renderItems(e,[])}rebuildPanel(){const e=this._visible,t=this.attachedObject;this.css2dObject&&this.attachedObject&&this.attachedObject.remove(this.css2dObject),this.buildPanel(),t&&(this.attachedObject=t,t.add(this.css2dObject),e||this.hide())}updateOptions(e){this.options={...this.options,...e},this.rebuildPanel()}getOffsetY(){return this.options.offsetY??.1}setOffsetY(e){if(this.options.offsetY=e,this.css2dObject&&this.attachedObject){const t=new O.Vector3;this.attachedObject.getWorldPosition(t);const n=new O.Box3().setFromObject(this.attachedObject).max.y-t.y;this.css2dObject.position.set(this.options.offsetX??0,n+e,this.options.offsetZ??0)}}getOffsetX(){return this.options.offsetX??0}setOffsetX(e){this.options.offsetX=e,this.css2dObject&&this.attachedObject&&(this.css2dObject.position.x=e)}getOffsetZ(){return this.options.offsetZ??0}setOffsetZ(e){this.options.offsetZ=e,this.css2dObject&&this.attachedObject&&(this.css2dObject.position.z=e)}getWidth(){return this.options.width||"20em"}getFontSize(){return this.options.fontSize||"0.85em"}setWidth(e){this.options.width=e,this.container&&(this.container.style.width=e)}setFontSize(e){if(this.options.fontSize=e,this.container){this.container.style.fontSize=e;const t=this.container.querySelector("[data-panel-title]");t&&(t.style.fontSize=`calc(${e} + 0.15em)`)}}getElement(){return this.container}dispose(){var e;this.detach(),(e=this.container)!=null&&e.parentNode&&this.container.parentNode.removeChild(this.container),this.css2dObject=null,this.container=null,this.attachedObject=null}};Te(He,"_breathInjected",!1);let Ke=He;const At=new WeakMap;function Wn(r,e){const t=a.toRaw(r);At.set(t,e),t.userData._hasDataPanel=!0}function je(r){return At.get(a.toRaw(r))||null}function zt(r){const e=a.toRaw(r),t=At.get(e);t&&(t.dispose(),At.delete(e)),e.userData._hasDataPanel=void 0}let $=null;function qn(r){return $?($.domElement.parentNode!==r&&r.appendChild($.domElement),$):($=new yi,$.setSize(r.clientWidth,r.clientHeight),$.domElement.style.position="absolute",$.domElement.style.top="0",$.domElement.style.left="0",$.domElement.style.pointerEvents="none",r.appendChild($.domElement),$)}function Di(){return $}function Xn(r,e){$&&$.render(r,e)}function Yn(r,e){$&&$.setSize(r,e)}function Kn(){$&&($.domElement.parentNode&&$.domElement.parentNode.removeChild($.domElement),$=null)}function Ni(){const r=new O.Scene;r.position.y=-3.5;const e=new O.BoxGeometry;e.deleteAttribute("uv");const t=new O.MeshStandardMaterial({side:O.BackSide}),s=new O.PointLight(16777215,900,28,2);s.position.set(.418,16.199,.3),r.add(s);const n=new O.Mesh(e,t);n.position.set(-.757,13.219,.717),n.scale.set(31.713,28.305,28.591),r.add(n);const i=new O.MeshStandardMaterial,o=new O.InstancedMesh(e,i,6),l=new O.Object3D;l.position.set(-10.906,2.009,1.846),l.rotation.set(0,-.195,0),l.scale.set(2.328,7.905,4.651),l.updateMatrix(),o.setMatrixAt(0,l.matrix),l.position.set(-5.607,-.754,-.758),l.rotation.set(0,.994,0),l.scale.set(1.97,1.534,3.955),l.updateMatrix(),o.setMatrixAt(1,l.matrix),l.position.set(6.167,.857,7.803),l.rotation.set(0,.561,0),l.scale.set(3.927,6.285,3.687),l.updateMatrix(),o.setMatrixAt(2,l.matrix),l.position.set(-2.017,.018,6.124),l.rotation.set(0,.333,0),l.scale.set(2.002,4.566,2.064),l.updateMatrix(),o.setMatrixAt(3,l.matrix),l.position.set(2.291,-.756,-2.621),l.rotation.set(0,-.286,0),l.scale.set(1.546,1.552,1.496),l.updateMatrix(),o.setMatrixAt(4,l.matrix),l.position.set(-2.193,-.369,-5.547),l.rotation.set(0,.516,0),l.scale.set(3.875,3.487,2.986),l.updateMatrix(),o.setMatrixAt(5,l.matrix),o.instanceMatrix.needsUpdate=!0,r.add(o);function u(m){return new O.MeshLambertMaterial({color:0,emissive:16777215,emissiveIntensity:m})}const d=new O.Mesh(e,u(50));d.position.set(-16.116,14.37,8.208),d.scale.set(.1,2.428,2.739),r.add(d);const p=new O.Mesh(e,u(50));p.position.set(-16.109,18.021,-8.207),p.scale.set(.1,2.425,2.751),r.add(p);const f=new O.Mesh(e,u(17));f.position.set(14.904,12.198,-1.832),f.scale.set(.15,4.265,6.331),r.add(f);const g=new O.Mesh(e,u(43));g.position.set(-.462,8.89,14.52),g.scale.set(4.38,5.441,.088),r.add(g);const y=new O.Mesh(e,u(20));y.position.set(3.235,11.486,-12.541),y.scale.set(2.5,2,.1),r.add(y);const x=new O.Mesh(e,u(100));return x.position.set(0,20,0),x.scale.set(1,.1,1),r.add(x),r}function ut(r){try{const e=new O.PMREMGenerator(r),t=Ni(),s=e.fromScene(t).texture;return t.traverse(n=>{if(n.isMesh){const i=n,o=Array.isArray(i.material)?i.material:[i.material];for(const l of o)l&&l.dispose()}}),e.dispose(),s}catch(e){return console.error("环境贴图生成失败:",e),null}}const En={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class qe{constructor(){this.textureUtils=null,this.pluginCallbacks=[],this.register(function(e){return new Fi(e)}),this.register(function(e){return new Ui(e)}),this.register(function(e){return new qi(e)}),this.register(function(e){return new Xi(e)}),this.register(function(e){return new Yi(e)}),this.register(function(e){return new Ki(e)}),this.register(function(e){return new Gi(e)}),this.register(function(e){return new zi(e)}),this.register(function(e){return new Wi(e)}),this.register(function(e){return new Zi(e)}),this.register(function(e){return new Qi(e)}),this.register(function(e){return new Ji(e)}),this.register(function(e){return new _i(e)}),this.register(function(e){return new $i(e)})}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}setTextureUtils(e){return this.textureUtils=e,this}parse(e,t,s,n){const i=new ji,o=[];for(let l=0,u=this.pluginCallbacks.length;l<u;l++)o.push(this.pluginCallbacks[l](i));i.setPlugins(o),i.setTextureUtils(this.textureUtils),i.writeAsync(e,t,n).catch(s)}parseAsync(e,t){const s=this;return new Promise(function(n,i){s.parse(e,n,i,t)})}}const z={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,ARRAY_BUFFER:34962,ELEMENT_ARRAY_BUFFER:34963,NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987,CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,REPEAT:10497},Tt="KHR_mesh_quantization",le={};le[c.NearestFilter]=z.NEAREST;le[c.NearestMipmapNearestFilter]=z.NEAREST_MIPMAP_NEAREST;le[c.NearestMipmapLinearFilter]=z.NEAREST_MIPMAP_LINEAR;le[c.LinearFilter]=z.LINEAR;le[c.LinearMipmapNearestFilter]=z.LINEAR_MIPMAP_NEAREST;le[c.LinearMipmapLinearFilter]=z.LINEAR_MIPMAP_LINEAR;le[c.ClampToEdgeWrapping]=z.CLAMP_TO_EDGE;le[c.RepeatWrapping]=z.REPEAT;le[c.MirroredRepeatWrapping]=z.MIRRORED_REPEAT;const Tn={scale:"scale",position:"translation",quaternion:"rotation",morphTargetInfluences:"weights"},Si=new c.Color,Dn=12,Oi=1179937895,Ri=2,Nn=8,Pi=1313821514,Li=5130562;function ye(r,e){return r.length===e.length&&r.every(function(t,s){return t===e[s]})}function ki(r){return new TextEncoder().encode(r).buffer}function Vi(r){return ye(r.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Hi(r,e,t){const s={min:new Array(r.itemSize).fill(Number.POSITIVE_INFINITY),max:new Array(r.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let n=e;n<e+t;n++)for(let i=0;i<r.itemSize;i++){let o;r.itemSize>4?o=r.array[n*r.itemSize+i]:(i===0?o=r.getX(n):i===1?o=r.getY(n):i===2?o=r.getZ(n):i===3&&(o=r.getW(n)),r.normalized===!0&&(o=c.MathUtils.normalize(o,r.array))),s.min[i]=Math.min(s.min[i],o),s.max[i]=Math.max(s.max[i],o)}return s}function Zn(r){return Math.ceil(r/4)*4}function Dt(r,e=0){const t=Zn(r.byteLength);if(t!==r.byteLength){const s=new Uint8Array(t);if(s.set(new Uint8Array(r)),e!==0)for(let n=r.byteLength;n<t;n++)s[n]=e;return s.buffer}return r}function Sn(){return typeof document>"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function Bi(r,e){if(typeof OffscreenCanvas<"u"&&r instanceof OffscreenCanvas){let t;return e==="image/jpeg"?t=.92:e==="image/webp"&&(t=.8),r.convertToBlob({type:e,quality:t})}else return new Promise(t=>r.toBlob(t,e))}class ji{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:"2.0",generator:"THREE.GLTFExporter r"+c.REVISION}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map},this.textureUtils=null}setPlugins(e){this.plugins=e}setTextureUtils(e){this.textureUtils=e}async writeAsync(e,t,s={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1},s),this.options.animations.length>0&&(this.options.trs=!0),await this.processInputAsync(e),await Promise.all(this.pending);const n=this,i=n.buffers,o=n.json;s=n.options;const l=n.extensionsUsed,u=n.extensionsRequired,d=new Blob(i,{type:"application/octet-stream"}),p=Object.keys(l),f=Object.keys(u);if(p.length>0&&(o.extensionsUsed=p),f.length>0&&(o.extensionsRequired=f),o.buffers&&o.buffers.length>0&&(o.buffers[0].byteLength=d.size),s.binary===!0){const g=new FileReader;g.readAsArrayBuffer(d),g.onloadend=function(){const y=Dt(g.result),x=new DataView(new ArrayBuffer(Nn));x.setUint32(0,y.byteLength,!0),x.setUint32(4,Li,!0);const m=Dt(ki(JSON.stringify(o)),32),A=new DataView(new ArrayBuffer(Nn));A.setUint32(0,m.byteLength,!0),A.setUint32(4,Pi,!0);const M=new ArrayBuffer(Dn),v=new DataView(M);v.setUint32(0,Oi,!0),v.setUint32(4,Ri,!0);const w=Dn+A.byteLength+m.byteLength+x.byteLength+y.byteLength;v.setUint32(8,w,!0);const h=new Blob([M,A,m,x,y],{type:"application/octet-stream"}),I=new FileReader;I.readAsArrayBuffer(h),I.onloadend=function(){t(I.result)}}}else if(o.buffers&&o.buffers.length>0){const g=new FileReader;g.readAsDataURL(d),g.onloadend=function(){const y=g.result;o.buffers[0].uri=y,t(o)}}else t(o)}serializeUserData(e,t){if(Object.keys(e.userData).length===0)return;const s=this.options,n=this.extensionsUsed;try{const i=JSON.parse(JSON.stringify(e.userData));if(s.includeCustomExtensions&&i.gltfExtensions){t.extensions===void 0&&(t.extensions={});for(const o in i.gltfExtensions)t.extensions[o]=i.gltfExtensions[o],n[o]=!0;delete i.gltfExtensions}Object.keys(i).length>0&&(t.extras=i)}catch(i){console.warn("THREE.GLTFExporter: userData of '"+e.name+"' won't be serialized because of JSON.stringify error - "+i.message)}}getUID(e,t=!1){if(this.uids.has(e)===!1){const n=new Map;n.set(!0,this.uid++),n.set(!1,this.uid++),this.uids.set(e,n)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;const s=new c.Vector3;for(let n=0,i=e.count;n<i;n++)if(Math.abs(s.fromBufferAttribute(e,n).length()-1)>5e-4)return!1;return!0}createNormalizedNormalAttribute(e){const t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);const s=e.clone(),n=new c.Vector3;for(let i=0,o=s.count;i<o;i++)n.fromBufferAttribute(s,i),n.x===0&&n.y===0&&n.z===0?n.setX(1):n.normalize(),s.setXYZ(i,n.x,n.y,n.z);return t.attributesNormalized.set(e,s),s}applyTextureTransform(e,t){let s=!1;const n={};(t.offset.x!==0||t.offset.y!==0)&&(n.offset=t.offset.toArray(),s=!0),t.rotation!==0&&(n.rotation=t.rotation,s=!0),(t.repeat.x!==1||t.repeat.y!==1)&&(n.scale=t.repeat.toArray(),s=!0),s&&(e.extensions=e.extensions||{},e.extensions.KHR_texture_transform=n,this.extensionsUsed.KHR_texture_transform=!0)}async buildMetalRoughTextureAsync(e,t){if(e===t)return e;function s(y){return y.colorSpace===c.SRGBColorSpace?function(m){return m<.04045?m*.0773993808:Math.pow(m*.9478672986+.0521327014,2.4)}:function(m){return m}}e instanceof c.CompressedTexture&&(e=await this.decompressTextureAsync(e)),t instanceof c.CompressedTexture&&(t=await this.decompressTextureAsync(t));const n=e?e.image:null,i=t?t.image:null,o=Math.max(n?n.width:0,i?i.width:0),l=Math.max(n?n.height:0,i?i.height:0),u=Sn();u.width=o,u.height=l;const d=u.getContext("2d",{willReadFrequently:!0});d.fillStyle="#00ffff",d.fillRect(0,0,o,l);const p=d.getImageData(0,0,o,l);if(n){d.drawImage(n,0,0,o,l);const y=s(e),x=d.getImageData(0,0,o,l).data;for(let m=2;m<x.length;m+=4)p.data[m]=y(x[m]/256)*256}if(i){d.drawImage(i,0,0,o,l);const y=s(t),x=d.getImageData(0,0,o,l).data;for(let m=1;m<x.length;m+=4)p.data[m]=y(x[m]/256)*256}d.putImageData(p,0,0);const g=(e||t).clone();return g.source=new c.Source(u),g.colorSpace=c.NoColorSpace,g.channel=(e||t).channel,e&&t&&e.channel!==t.channel&&console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match."),console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures."),g}async decompressTextureAsync(e,t=1/0){if(this.textureUtils===null)throw new Error("THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.");return await this.textureUtils.decompress(e,t)}processBuffer(e){const t=this.json,s=this.buffers;return t.buffers||(t.buffers=[{byteLength:0}]),s.push(e),0}processBufferView(e,t,s,n,i){const o=this.json;o.bufferViews||(o.bufferViews=[]);let l;switch(t){case z.BYTE:case z.UNSIGNED_BYTE:l=1;break;case z.SHORT:case z.UNSIGNED_SHORT:l=2;break;default:l=4}let u=e.itemSize*l;i===z.ARRAY_BUFFER&&(u=Math.ceil(u/4)*4);const d=Zn(n*u),p=new DataView(new ArrayBuffer(d));let f=0;for(let x=s;x<s+n;x++){for(let m=0;m<e.itemSize;m++){let A;e.itemSize>4?A=e.array[x*e.itemSize+m]:(m===0?A=e.getX(x):m===1?A=e.getY(x):m===2?A=e.getZ(x):m===3&&(A=e.getW(x)),e.normalized===!0&&(A=c.MathUtils.normalize(A,e.array))),t===z.FLOAT?p.setFloat32(f,A,!0):t===z.INT?p.setInt32(f,A,!0):t===z.UNSIGNED_INT?p.setUint32(f,A,!0):t===z.SHORT?p.setInt16(f,A,!0):t===z.UNSIGNED_SHORT?p.setUint16(f,A,!0):t===z.BYTE?p.setInt8(f,A):t===z.UNSIGNED_BYTE&&p.setUint8(f,A),f+=l}f%u!==0&&(f+=u-f%u)}const g={buffer:this.processBuffer(p.buffer),byteOffset:this.byteOffset,byteLength:d};return i!==void 0&&(g.target=i),i===z.ARRAY_BUFFER&&(g.byteStride=u),this.byteOffset+=d,o.bufferViews.push(g),{id:o.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){const t=this,s=t.json;return s.bufferViews||(s.bufferViews=[]),new Promise(function(n){const i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){const o=Dt(i.result),l={buffer:t.processBuffer(o),byteOffset:t.byteOffset,byteLength:o.byteLength};t.byteOffset+=o.byteLength,n(s.bufferViews.push(l)-1)}})}processAccessor(e,t,s,n){const i=this.json,o={1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"};let l;if(e.array.constructor===Float32Array)l=z.FLOAT;else if(e.array.constructor===Int32Array)l=z.INT;else if(e.array.constructor===Uint32Array)l=z.UNSIGNED_INT;else if(e.array.constructor===Int16Array)l=z.SHORT;else if(e.array.constructor===Uint16Array)l=z.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)l=z.BYTE;else if(e.array.constructor===Uint8Array)l=z.UNSIGNED_BYTE;else throw new Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(s===void 0&&(s=0),(n===void 0||n===1/0)&&(n=e.count),n===0)return null;const u=Hi(e,s,n);let d;t!==void 0&&(d=e===t.index?z.ELEMENT_ARRAY_BUFFER:z.ARRAY_BUFFER);const p=this.processBufferView(e,l,s,n,d),f={bufferView:p.id,byteOffset:p.byteOffset,componentType:l,count:n,max:u.max,min:u.min,type:o[e.itemSize]};return e.normalized===!0&&(f.normalized=!0),i.accessors||(i.accessors=[]),i.accessors.push(f)-1}processImage(e,t,s,n="image/png"){if(e!==null){const i=this,o=i.cache,l=i.json,u=i.options,d=i.pending;o.images.has(e)||o.images.set(e,{});const p=o.images.get(e),f=n+":flipY/"+s.toString();if(p[f]!==void 0)return p[f];l.images||(l.images=[]);const g={mimeType:n},y=Sn();y.width=Math.min(e.width,u.maxTextureSize),y.height=Math.min(e.height,u.maxTextureSize);const x=y.getContext("2d",{willReadFrequently:!0});if(s===!0&&(x.translate(0,y.height),x.scale(1,-1)),e.data!==void 0){t!==c.RGBAFormat&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>u.maxTextureSize||e.height>u.maxTextureSize)&&console.warn("GLTFExporter: Image size is bigger than maxTextureSize",e);const A=new Uint8ClampedArray(e.height*e.width*4);for(let M=0;M<A.length;M+=4)A[M+0]=e.data[M+0],A[M+1]=e.data[M+1],A[M+2]=e.data[M+2],A[M+3]=e.data[M+3];x.putImageData(new ImageData(A,e.width,e.height),0,0)}else if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)x.drawImage(e,0,0,y.width,y.height);else throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");u.binary===!0?d.push(Bi(y,n).then(A=>i.processBufferViewImage(A)).then(A=>{g.bufferView=A})):g.uri=c.ImageUtils.getDataURL(y,n);const m=l.images.push(g)-1;return p[f]=m,m}else throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){const t=this.json;t.samplers||(t.samplers=[]);const s={magFilter:le[e.magFilter],minFilter:le[e.minFilter],wrapS:le[e.wrapS],wrapT:le[e.wrapT]};return t.samplers.push(s)-1}async processTextureAsync(e){const s=this.options,n=this.cache,i=this.json;if(n.textures.has(e))return n.textures.get(e);i.textures||(i.textures=[]),e instanceof c.CompressedTexture&&(e=await this.decompressTextureAsync(e,s.maxTextureSize));const o=e.userData.mimeType,l=this.processImage(e.image,e.format,e.flipY,o),u={sampler:this.processSampler(e)};o==="image/webp"?(u.extensions=u.extensions||{},u.extensions.EXT_texture_webp={source:l},this.extensionsUsed.EXT_texture_webp=!0,this.extensionsRequired.EXT_texture_webp=!0):u.source=l,e.name&&(u.name=e.name),await this._invokeAllAsync(async function(p){p.writeTexture&&await p.writeTexture(e,u)});const d=i.textures.push(u)-1;return n.textures.set(e,d),d}async processMaterialAsync(e){const t=this.cache,s=this.json;if(t.materials.has(e))return t.materials.get(e);if(e.isShaderMaterial)return console.warn("GLTFExporter: THREE.ShaderMaterial not supported."),null;s.materials||(s.materials=[]);const n={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");const i=e.color.toArray().concat([e.opacity]);if(ye(i,[1,1,1,1])||(n.pbrMetallicRoughness.baseColorFactor=i),e.isMeshStandardMaterial?(n.pbrMetallicRoughness.metallicFactor=e.metalness,n.pbrMetallicRoughness.roughnessFactor=e.roughness):(n.pbrMetallicRoughness.metallicFactor=0,n.pbrMetallicRoughness.roughnessFactor=1),e.metalnessMap||e.roughnessMap){const l=await this.buildMetalRoughTextureAsync(e.metalnessMap,e.roughnessMap),u={index:await this.processTextureAsync(l),texCoord:l.channel};this.applyTextureTransform(u,l),n.pbrMetallicRoughness.metallicRoughnessTexture=u}if(e.map){const l={index:await this.processTextureAsync(e.map),texCoord:e.map.channel};this.applyTextureTransform(l,e.map),n.pbrMetallicRoughness.baseColorTexture=l}if(e.emissive){const l=e.emissive;if(Math.max(l.r,l.g,l.b)>0&&(n.emissiveFactor=e.emissive.toArray()),e.emissiveMap){const d={index:await this.processTextureAsync(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(d,e.emissiveMap),n.emissiveTexture=d}}if(e.normalMap){const l={index:await this.processTextureAsync(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&e.normalScale.x!==1&&(l.scale=e.normalScale.x),this.applyTextureTransform(l,e.normalMap),n.normalTexture=l}if(e.aoMap){const l={index:await this.processTextureAsync(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(l.strength=e.aoMapIntensity),this.applyTextureTransform(l,e.aoMap),n.occlusionTexture=l}e.transparent?n.alphaMode="BLEND":e.alphaTest>0&&(n.alphaMode="MASK",n.alphaCutoff=e.alphaTest),e.side===c.DoubleSide&&(n.doubleSided=!0),e.name!==""&&(n.name=e.name),this.serializeUserData(e,n),await this._invokeAllAsync(async function(l){l.writeMaterialAsync&&await l.writeMaterialAsync(e,n)});const o=s.materials.push(n)-1;return t.materials.set(e,o),o}async processMeshAsync(e){const t=this.cache,s=this.json,n=[e.geometry.uuid];if(Array.isArray(e.material))for(let h=0,I=e.material.length;h<I;h++)n.push(e.material[h].uuid);else n.push(e.material.uuid);const i=n.join(":");if(t.meshes.has(i))return t.meshes.get(i);const o=e.geometry;let l;e.isLineSegments?l=z.LINES:e.isLineLoop?l=z.LINE_LOOP:e.isLine?l=z.LINE_STRIP:e.isPoints?l=z.POINTS:l=e.material.wireframe?z.LINES:z.TRIANGLES;const u={},d={},p=[],f=[],g={uv:"TEXCOORD_0",uv1:"TEXCOORD_1",uv2:"TEXCOORD_2",uv3:"TEXCOORD_3",color:"COLOR_0",skinWeight:"WEIGHTS_0",skinIndex:"JOINTS_0"},y=o.getAttribute("normal");y!==void 0&&!this.isNormalizedNormalAttribute(y)&&(console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."),o.setAttribute("normal",this.createNormalizedNormalAttribute(y)));let x=null;for(let h in o.attributes){if(h.slice(0,5)==="morph")continue;const I=o.attributes[h];if(h=g[h]||h.toUpperCase(),!/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(h)&&!h.startsWith("_")&&(h="_"+h),t.attributes.has(this.getUID(I))){d[h]=t.attributes.get(this.getUID(I));continue}x=null;const N=I.array;h==="JOINTS_0"&&!(N instanceof Uint16Array)&&!(N instanceof Uint8Array)?(console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'),x=qe.Utils.toTypedBufferAttribute(I,Uint16Array)):(N instanceof Uint32Array||N instanceof Int32Array)&&!h.startsWith("_")&&(console.warn(`GLTFExporter: Attribute "${h}" converted to type FLOAT.`),x=qe.Utils.toTypedBufferAttribute(I,Float32Array));const D=this.processAccessor(x||I,o);D!==null&&(h.startsWith("_")||this.detectMeshQuantization(h,I),d[h]=D,t.attributes.set(this.getUID(I),D))}if(y!==void 0&&o.setAttribute("normal",y),Object.keys(d).length===0)return null;if(e.morphTargetInfluences!==void 0&&e.morphTargetInfluences.length>0){const h=[],I=[],E={};if(e.morphTargetDictionary!==void 0)for(const N in e.morphTargetDictionary)E[e.morphTargetDictionary[N]]=N;for(let N=0;N<e.morphTargetInfluences.length;++N){const D={};let V=!1;for(const W in o.morphAttributes){if(W!=="position"&&W!=="normal"){V||(console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."),V=!0);continue}const Y=o.morphAttributes[W][N],Z=W.toUpperCase(),q=o.attributes[W];if(t.attributes.has(this.getUID(Y,!0))){D[Z]=t.attributes.get(this.getUID(Y,!0));continue}const j=Y.clone();if(!o.morphTargetsRelative)for(let P=0,L=Y.count;P<L;P++)for(let B=0;B<Y.itemSize;B++)B===0&&j.setX(P,Y.getX(P)-q.getX(P)),B===1&&j.setY(P,Y.getY(P)-q.getY(P)),B===2&&j.setZ(P,Y.getZ(P)-q.getZ(P)),B===3&&j.setW(P,Y.getW(P)-q.getW(P));D[Z]=this.processAccessor(j,o),t.attributes.set(this.getUID(q,!0),D[Z])}f.push(D),h.push(e.morphTargetInfluences[N]),e.morphTargetDictionary!==void 0&&I.push(E[N])}u.weights=h,I.length>0&&(u.extras={},u.extras.targetNames=I)}const m=Array.isArray(e.material);if(m&&o.groups.length===0)return null;let A=!1;if(m&&o.index===null){const h=[];for(let I=0,E=o.attributes.position.count;I<E;I++)h[I]=I;o.setIndex(h),A=!0}const M=m?e.material:[e.material],v=m?o.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let h=0,I=v.length;h<I;h++){const E={mode:l,attributes:d};if(this.serializeUserData(o,E),f.length>0&&(E.targets=f),o.index!==null){let D=this.getUID(o.index);(v[h].start!==void 0||v[h].count!==void 0)&&(D+=":"+v[h].start+":"+v[h].count),t.attributes.has(D)?E.indices=t.attributes.get(D):(E.indices=this.processAccessor(o.index,o,v[h].start,v[h].count),t.attributes.set(D,E.indices)),E.indices===null&&delete E.indices}const N=await this.processMaterialAsync(M[v[h].materialIndex]);N!==null&&(E.material=N),p.push(E)}A===!0&&o.setIndex(null),u.primitives=p,s.meshes||(s.meshes=[]),await this._invokeAllAsync(function(h){h.writeMesh&&h.writeMesh(e,u)});const w=s.meshes.push(u)-1;return t.meshes.set(i,w),w}detectMeshQuantization(e,t){if(this.extensionsUsed[Tt])return;let s;switch(t.array.constructor){case Int8Array:s="byte";break;case Uint8Array:s="unsigned byte";break;case Int16Array:s="short";break;case Uint16Array:s="unsigned short";break;default:return}t.normalized&&(s+=" normalized");const n=e.split("_",1)[0];En[n]&&En[n].includes(s)&&(this.extensionsUsed[Tt]=!0,this.extensionsRequired[Tt]=!0)}processCamera(e){const t=this.json;t.cameras||(t.cameras=[]);const s=e.isOrthographicCamera,n={type:s?"orthographic":"perspective"};return s?n.orthographic={xmag:e.right*2,ymag:e.top*2,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:n.perspective={aspectRatio:e.aspect,yfov:c.MathUtils.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==""&&(n.name=e.type),t.cameras.push(n)-1}processAnimation(e,t){const s=this.json,n=this.nodeMap;s.animations||(s.animations=[]),e=qe.Utils.mergeMorphTargetTracks(e.clone(),t);const i=e.tracks,o=[],l=[];for(let d=0;d<i.length;++d){const p=i[d],f=c.PropertyBinding.parseTrackName(p.name);let g=c.PropertyBinding.findNode(t,f.nodeName);const y=Tn[f.propertyName];if(f.objectName==="bones"&&(g.isSkinnedMesh===!0?g=g.skeleton.getBoneByName(f.objectIndex):g=void 0),!g||!y){console.warn('THREE.GLTFExporter: Could not export animation track "%s".',p.name);continue}const x=1;let m=p.values.length/p.times.length;y===Tn.morphTargetInfluences&&(m/=g.morphTargetInfluences.length);let A;p.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline===!0?(A="CUBICSPLINE",m/=3):p.getInterpolation()===c.InterpolateDiscrete?A="STEP":A="LINEAR",l.push({input:this.processAccessor(new c.BufferAttribute(p.times,x)),output:this.processAccessor(new c.BufferAttribute(p.values,m)),interpolation:A}),o.push({sampler:l.length-1,target:{node:n.get(g),path:y}})}const u={name:e.name||"clip_"+s.animations.length,samplers:l,channels:o};return this.serializeUserData(e,u),s.animations.push(u),s.animations.length-1}processSkin(e){const t=this.json,s=this.nodeMap,n=t.nodes[s.get(e)],i=e.skeleton;if(i===void 0)return null;const o=e.skeleton.bones[0];if(o===void 0)return null;const l=[],u=new Float32Array(i.bones.length*16),d=new c.Matrix4;for(let f=0;f<i.bones.length;++f)l.push(s.get(i.bones[f])),d.copy(i.boneInverses[f]),d.multiply(e.bindMatrix).toArray(u,f*16);return t.skins===void 0&&(t.skins=[]),t.skins.push({inverseBindMatrices:this.processAccessor(new c.BufferAttribute(u,16)),joints:l,skeleton:s.get(o)}),n.skin=t.skins.length-1}async processNodeAsync(e){const t=this.json,s=this.options,n=this.nodeMap;if(t.nodes||(t.nodes=[]),e.pivot!==null)return await this._processNodeWithPivotAsync(e);const i={};if(s.trs){const l=e.quaternion.toArray(),u=e.position.toArray(),d=e.scale.toArray();ye(l,[0,0,0,1])||(i.rotation=l),ye(u,[0,0,0])||(i.translation=u),ye(d,[1,1,1])||(i.scale=d)}else e.matrixAutoUpdate&&e.updateMatrix(),Vi(e.matrix)===!1&&(i.matrix=e.matrix.elements);if(e.name!==""&&(i.name=String(e.name)),this.serializeUserData(e,i),e.isMesh||e.isLine||e.isPoints){const l=await this.processMeshAsync(e);l!==null&&(i.mesh=l)}else e.isCamera&&(i.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);const o=t.nodes.push(i)-1;if(n.set(e,o),e.children.length>0){const l=[];for(let u=0,d=e.children.length;u<d;u++){const p=e.children[u];if(p.visible||s.onlyVisible===!1){const f=await this.processNodeAsync(p);f!==null&&l.push(f)}}l.length>0&&(i.children=l)}return await this._invokeAllAsync(function(l){l.writeNode&&l.writeNode(e,i)}),o}async _processNodeWithPivotAsync(e){const t=this.json,s=this.options,n=this.nodeMap,i=e.pivot,o={},l=e.quaternion.toArray(),u=[e.position.x+i.x,e.position.y+i.y,e.position.z+i.z],d=e.scale.toArray();ye(l,[0,0,0,1])||(o.rotation=l),ye(u,[0,0,0])||(o.translation=u),ye(d,[1,1,1])||(o.scale=d),o.extras={pivot:i.toArray()},e.name!==""&&(o.name=String(e.name)),this.serializeUserData(e,o);const p=t.nodes.push(o)-1;n.set(e,p);const f={},g=[-i.x,-i.y,-i.z];if(ye(g,[0,0,0])||(f.translation=g),e.isMesh||e.isLine||e.isPoints){const m=await this.processMeshAsync(e);m!==null&&(f.mesh=m)}else e.isCamera&&(f.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);const x=[t.nodes.push(f)-1];if(e.children.length>0){const m=[];for(let A=0,M=e.children.length;A<M;A++){const v=e.children[A];if(v.visible||s.onlyVisible===!1){const w=await this.processNodeAsync(v);w!==null&&m.push(w)}}m.length>0&&(f.children=m)}return o.children=x,await this._invokeAllAsync(function(m){m.writeNode&&m.writeNode(e,o)}),p}async processSceneAsync(e){const t=this.json,s=this.options;t.scenes||(t.scenes=[],t.scene=0);const n={};e.name!==""&&(n.name=e.name),t.scenes.push(n);const i=[];for(let o=0,l=e.children.length;o<l;o++){const u=e.children[o];if(u.visible||s.onlyVisible===!1){const d=await this.processNodeAsync(u);d!==null&&i.push(d)}}i.length>0&&(n.nodes=i),this.serializeUserData(e,n)}async processObjectsAsync(e){const t=new c.Scene;t.name="AuxScene";for(let s=0;s<e.length;s++)t.children.push(e[s]);await this.processSceneAsync(t)}async processInputAsync(e){const t=this.options;e=e instanceof Array?e:[e],await this._invokeAllAsync(function(n){n.beforeParse&&n.beforeParse(e)});const s=[];for(let n=0;n<e.length;n++)e[n]instanceof c.Scene?await this.processSceneAsync(e[n]):s.push(e[n]);s.length>0&&await this.processObjectsAsync(s);for(let n=0;n<this.skins.length;++n)this.processSkin(this.skins[n]);for(let n=0;n<t.animations.length;++n)this.processAnimation(t.animations[n],e[0]);await this._invokeAllAsync(function(n){n.afterParse&&n.afterParse(e)})}async _invokeAllAsync(e){for(let t=0,s=this.plugins.length;t<s;t++)await e(this.plugins[t])}}class Fi{constructor(e){this.writer=e,this.name="KHR_lights_punctual"}writeNode(e,t){if(!e.isLight)return;if(!e.isDirectionalLight&&!e.isPointLight&&!e.isSpotLight){console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.",e);return}const s=this.writer,n=s.json,i=s.extensionsUsed,o={};e.name&&(o.name=e.name),o.color=e.color.toArray(),o.intensity=e.intensity,e.isDirectionalLight?o.type="directional":e.isPointLight?(o.type="point",e.distance>0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn("THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."),i[this.name]||(n.extensions=n.extensions||{},n.extensions[this.name]={lights:[]},i[this.name]=!0);const l=n.extensions[this.name].lights;l.push(o),t.extensions=t.extensions||{},t.extensions[this.name]={light:l.length-1}}}let Ui=class{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}async writeMaterialAsync(e,t){if(!e.isMeshBasicMaterial)return;const n=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},n[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}},Gi=class{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;const s=this.writer,n=s.extensionsUsed,i={};if(i.clearcoatFactor=e.clearcoat,e.clearcoatMap){const o={index:await s.processTextureAsync(e.clearcoatMap),texCoord:e.clearcoatMap.channel};s.applyTextureTransform(o,e.clearcoatMap),i.clearcoatTexture=o}if(i.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){const o={index:await s.processTextureAsync(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};s.applyTextureTransform(o,e.clearcoatRoughnessMap),i.clearcoatRoughnessTexture=o}if(e.clearcoatNormalMap){const o={index:await s.processTextureAsync(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};e.clearcoatNormalScale.x!==1&&(o.scale=e.clearcoatNormalScale.x),s.applyTextureTransform(o,e.clearcoatNormalMap),i.clearcoatNormalTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},zi=class{constructor(e){this.writer=e,this.name="KHR_materials_dispersion"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.dispersion===0)return;const n=this.writer.extensionsUsed,i={};i.dispersion=e.dispersion,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Wi=class{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;const s=this.writer,n=s.extensionsUsed,i={};if(i.iridescenceFactor=e.iridescence,e.iridescenceMap){const o={index:await s.processTextureAsync(e.iridescenceMap),texCoord:e.iridescenceMap.channel};s.applyTextureTransform(o,e.iridescenceMap),i.iridescenceTexture=o}if(i.iridescenceIor=e.iridescenceIOR,i.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],i.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1],e.iridescenceThicknessMap){const o={index:await s.processTextureAsync(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};s.applyTextureTransform(o,e.iridescenceThicknessMap),i.iridescenceThicknessTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},qi=class{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const s=this.writer,n=s.extensionsUsed,i={};if(i.transmissionFactor=e.transmission,e.transmissionMap){const o={index:await s.processTextureAsync(e.transmissionMap),texCoord:e.transmissionMap.channel};s.applyTextureTransform(o,e.transmissionMap),i.transmissionTexture=o}t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Xi=class{constructor(e){this.writer=e,this.name="KHR_materials_volume"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;const s=this.writer,n=s.extensionsUsed,i={};if(i.thicknessFactor=e.thickness,e.thicknessMap){const o={index:await s.processTextureAsync(e.thicknessMap),texCoord:e.thicknessMap.channel};s.applyTextureTransform(o,e.thicknessMap),i.thicknessTexture=o}e.attenuationDistance!==1/0&&(i.attenuationDistance=e.attenuationDistance),i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Yi=class{constructor(e){this.writer=e,this.name="KHR_materials_ior"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;const n=this.writer.extensionsUsed,i={};i.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Ki=class{constructor(e){this.writer=e,this.name="KHR_materials_specular"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(Si)&&!e.specularIntensityMap&&!e.specularColorMap)return;const s=this.writer,n=s.extensionsUsed,i={};if(e.specularIntensityMap){const o={index:await s.processTextureAsync(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};s.applyTextureTransform(o,e.specularIntensityMap),i.specularTexture=o}if(e.specularColorMap){const o={index:await s.processTextureAsync(e.specularColorMap),texCoord:e.specularColorMap.channel};s.applyTextureTransform(o,e.specularColorMap),i.specularColorTexture=o}i.specularFactor=e.specularIntensity,i.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Zi=class{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;const s=this.writer,n=s.extensionsUsed,i={};if(e.sheenRoughnessMap){const o={index:await s.processTextureAsync(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};s.applyTextureTransform(o,e.sheenRoughnessMap),i.sheenRoughnessTexture=o}if(e.sheenColorMap){const o={index:await s.processTextureAsync(e.sheenColorMap),texCoord:e.sheenColorMap.channel};s.applyTextureTransform(o,e.sheenColorMap),i.sheenColorTexture=o}i.sheenRoughnessFactor=e.sheenRoughness,i.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Qi=class{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}async writeMaterialAsync(e,t){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;const s=this.writer,n=s.extensionsUsed,i={};if(e.anisotropyMap){const o={index:await s.processTextureAsync(e.anisotropyMap)};s.applyTextureTransform(o,e.anisotropyMap),i.anisotropyTexture=o}i.anisotropyStrength=e.anisotropy,i.anisotropyRotation=e.anisotropyRotation,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},Ji=class{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;const n=this.writer.extensionsUsed,i={};i.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},_i=class{constructor(e){this.writer=e,this.name="EXT_materials_bump"}async writeMaterialAsync(e,t){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;const s=this.writer,n=s.extensionsUsed,i={};if(e.bumpMap){const o={index:await s.processTextureAsync(e.bumpMap),texCoord:e.bumpMap.channel};s.applyTextureTransform(o,e.bumpMap),i.bumpTexture=o}i.bumpFactor=e.bumpScale,t.extensions=t.extensions||{},t.extensions[this.name]=i,n[this.name]=!0}},$i=class{constructor(e){this.writer=e,this.name="EXT_mesh_gpu_instancing"}writeNode(e,t){if(!e.isInstancedMesh)return;const s=this.writer,n=e,i=new Float32Array(n.count*3),o=new Float32Array(n.count*4),l=new Float32Array(n.count*3),u=new c.Matrix4,d=new c.Vector3,p=new c.Quaternion,f=new c.Vector3;for(let y=0;y<n.count;y++)n.getMatrixAt(y,u),u.decompose(d,p,f),d.toArray(i,y*3),p.toArray(o,y*4),f.toArray(l,y*3);const g={TRANSLATION:s.processAccessor(new c.BufferAttribute(i,3)),ROTATION:s.processAccessor(new c.BufferAttribute(o,4)),SCALE:s.processAccessor(new c.BufferAttribute(l,3))};n.instanceColor&&(g._COLOR_0=s.processAccessor(n.instanceColor)),t.extensions=t.extensions||{},t.extensions[this.name]={attributes:g},s.extensionsUsed[this.name]=!0,s.extensionsRequired[this.name]=!0}};qe.Utils={insertKeyframe:function(r,e){const s=r.getValueSize(),n=new r.TimeBufferType(r.times.length+1),i=new r.ValueBufferType(r.values.length+s),o=r.createInterpolant(new r.ValueBufferType(s));let l;if(r.times.length===0){n[0]=e;for(let u=0;u<s;u++)i[u]=0;l=0}else if(e<r.times[0]){if(Math.abs(r.times[0]-e)<.001)return 0;n[0]=e,n.set(r.times,1),i.set(o.evaluate(e),0),i.set(r.values,s),l=0}else if(e>r.times[r.times.length-1]){if(Math.abs(r.times[r.times.length-1]-e)<.001)return r.times.length-1;n[n.length-1]=e,n.set(r.times,0),i.set(r.values,0),i.set(o.evaluate(e),r.values.length),l=n.length-1}else for(let u=0;u<r.times.length;u++){if(Math.abs(r.times[u]-e)<.001)return u;if(r.times[u]<e&&r.times[u+1]>e){n.set(r.times.slice(0,u+1),0),n[u+1]=e,n.set(r.times.slice(u+1),u+2),i.set(r.values.slice(0,(u+1)*s),0),i.set(o.evaluate(e),(u+1)*s),i.set(r.values.slice((u+1)*s),(u+2)*s),l=u+1;break}}return r.times=n,r.values=i,l},mergeMorphTargetTracks:function(r,e){const t=[],s={},n=r.tracks;for(let i=0;i<n.length;++i){let o=n[i];const l=c.PropertyBinding.parseTrackName(o.name),u=c.PropertyBinding.findNode(e,l.nodeName);if(l.propertyName!=="morphTargetInfluences"||l.propertyIndex===void 0){t.push(o);continue}if(o.createInterpolant!==o.InterpolantFactoryMethodDiscrete&&o.createInterpolant!==o.InterpolantFactoryMethodLinear){if(o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline)throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead."),o=o.clone(),o.setInterpolation(c.InterpolateLinear)}const d=u.morphTargetInfluences.length,p=u.morphTargetDictionary[l.propertyIndex];if(p===void 0)throw new Error("THREE.GLTFExporter: Morph target name not found: "+l.propertyIndex);let f;if(s[u.uuid]===void 0){f=o.clone();const y=new f.ValueBufferType(d*f.times.length);for(let x=0;x<f.times.length;x++)y[x*d+p]=f.values[x];f.name=(l.nodeName||"")+".morphTargetInfluences",f.values=y,s[u.uuid]=f,t.push(f);continue}const g=o.createInterpolant(new o.ValueBufferType(1));f=s[u.uuid];for(let y=0;y<f.times.length;y++)f.values[y*d+p]=g.evaluate(f.times[y]);for(let y=0;y<o.times.length;y++){const x=this.insertKeyframe(f,o.times[y]);f.values[x*d+p]=o.values[y]}}return r.tracks=t,r},toTypedBufferAttribute:function(r,e){const t=new c.BufferAttribute(new e(r.count*r.itemSize),r.itemSize,!1);if(!r.normalized&&!r.isInterleavedBufferAttribute)return t.array.set(r.array),t;for(let s=0,n=r.count;s<n;s++)for(let i=0;i<r.itemSize;i++)t.setComponent(s,i,r.getComponent(s,i));return t}};function On(r,e){if(e===c.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),r;if(e===c.TriangleFanDrawMode||e===c.TriangleStripDrawMode){let t=r.getIndex();if(t===null){const o=[],l=r.getAttribute("position");if(l!==void 0){for(let u=0;u<l.count;u++)o.push(u);r.setIndex(o),t=r.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),r}const s=t.count-2,n=[];if(e===c.TriangleFanDrawMode)for(let o=1;o<=s;o++)n.push(t.getX(0)),n.push(t.getX(o)),n.push(t.getX(o+1));else for(let o=0;o<s;o++)o%2===0?(n.push(t.getX(o)),n.push(t.getX(o+1)),n.push(t.getX(o+2))):(n.push(t.getX(o+2)),n.push(t.getX(o+1)),n.push(t.getX(o)));n.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=r.clone();return i.setIndex(n),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),r}function eo(r){const e=new Map,t=new Map,s=r.clone();return Qn(r,s,function(n,i){e.set(i,n),t.set(n,i)}),s.traverse(function(n){if(!n.isSkinnedMesh)return;const i=n,o=e.get(n),l=o.skeleton.bones;i.skeleton=o.skeleton.clone(),i.bindMatrix.copy(o.bindMatrix),i.skeleton.bones=l.map(function(u){return t.get(u)}),i.bind(i.skeleton,i.bindMatrix)}),s}function Qn(r,e,t){t(r,e);for(let s=0;s<r.children.length;s++)Qn(r.children[s],e.children[s],t)}class Jn extends c.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new oo(t)}),this.register(function(t){return new ro(t)}),this.register(function(t){return new Ao(t)}),this.register(function(t){return new go(t)}),this.register(function(t){return new yo(t)}),this.register(function(t){return new lo(t)}),this.register(function(t){return new co(t)}),this.register(function(t){return new uo(t)}),this.register(function(t){return new fo(t)}),this.register(function(t){return new io(t)}),this.register(function(t){return new ho(t)}),this.register(function(t){return new ao(t)}),this.register(function(t){return new mo(t)}),this.register(function(t){return new po(t)}),this.register(function(t){return new no(t)}),this.register(function(t){return new Rn(t,G.EXT_MESHOPT_COMPRESSION)}),this.register(function(t){return new Rn(t,G.KHR_MESHOPT_COMPRESSION)}),this.register(function(t){return new bo(t)})}load(e,t,s,n){const i=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const d=c.LoaderUtils.extractUrlBase(e);o=c.LoaderUtils.resolveURL(d,this.path)}else o=c.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const l=function(d){n?n(d):console.error(d),i.manager.itemError(e),i.manager.itemEnd(e)},u=new c.FileLoader(this.manager);u.setPath(this.path),u.setResponseType("arraybuffer"),u.setRequestHeader(this.requestHeader),u.setWithCredentials(this.withCredentials),u.load(e,function(d){try{i.parse(d,o,function(p){t(p),i.manager.itemEnd(e)},l)}catch(p){l(p)}},s,l)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,s,n){let i;const o={},l={},u=new TextDecoder;if(typeof e=="string")i=JSON.parse(e);else if(e instanceof ArrayBuffer)if(u.decode(new Uint8Array(e,0,4))===_n){try{o[G.KHR_BINARY_GLTF]=new xo(e)}catch(f){n&&n(f);return}i=JSON.parse(o[G.KHR_BINARY_GLTF].content)}else i=JSON.parse(u.decode(e));else i=e;if(i.asset===void 0||i.asset.version[0]<2){n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const d=new Po(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});d.fileLoader.setRequestHeader(this.requestHeader);for(let p=0;p<this.pluginCallbacks.length;p++){const f=this.pluginCallbacks[p](d);f.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),l[f.name]=f,o[f.name]=!0}if(i.extensionsUsed)for(let p=0;p<i.extensionsUsed.length;++p){const f=i.extensionsUsed[p],g=i.extensionsRequired||[];switch(f){case G.KHR_MATERIALS_UNLIT:o[f]=new so;break;case G.KHR_DRACO_MESH_COMPRESSION:o[f]=new Io(i,this.dracoLoader);break;case G.KHR_TEXTURE_TRANSFORM:o[f]=new Co;break;case G.KHR_MESH_QUANTIZATION:o[f]=new Mo;break;default:g.indexOf(f)>=0&&l[f]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+f+'".')}}d.setExtensions(o),d.setPlugins(l),d.parse(s,n)}parseAsync(e,t){const s=this;return new Promise(function(n,i){s.parse(e,t,n,i)})}}function to(){let r={};return{get:function(e){return r[e]},add:function(e,t){r[e]=t},remove:function(e){delete r[e]},removeAll:function(){r={}}}}function ee(r,e,t){const s=r.json.materials[e];return s.extensions&&s.extensions[t]?s.extensions[t]:null}const G={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class no{constructor(e){this.parser=e,this.name=G.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const i=t[s];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,s="light:"+e;let n=t.cache.get(s);if(n)return n;const i=t.json,u=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let d;const p=new c.Color(16777215);u.color!==void 0&&p.setRGB(u.color[0],u.color[1],u.color[2],c.LinearSRGBColorSpace);const f=u.range!==void 0?u.range:0;switch(u.type){case"directional":d=new c.DirectionalLight(p),d.target.position.set(0,0,-1),d.add(d.target);break;case"point":d=new c.PointLight(p),d.distance=f;break;case"spot":d=new c.SpotLight(p),d.distance=f,u.spot=u.spot||{},u.spot.innerConeAngle=u.spot.innerConeAngle!==void 0?u.spot.innerConeAngle:0,u.spot.outerConeAngle=u.spot.outerConeAngle!==void 0?u.spot.outerConeAngle:Math.PI/4,d.angle=u.spot.outerConeAngle,d.penumbra=1-u.spot.innerConeAngle/u.spot.outerConeAngle,d.target.position.set(0,0,-1),d.add(d.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+u.type)}return d.position.set(0,0,0),Ae(d,u),u.intensity!==void 0&&(d.intensity=u.intensity),d.name=t.createUniqueName(u.name||"light_"+e),n=Promise.resolve(d),t.cache.add(s,n),n}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,i=s.json.nodes[e],l=(i.extensions&&i.extensions[this.name]||{}).light;return l===void 0?null:this._loadLight(l).then(function(u){return s._getNodeRef(t.cache,l,u)})}}class so{constructor(){this.name=G.KHR_MATERIALS_UNLIT}getMaterialType(){return c.MeshBasicMaterial}extendParams(e,t,s){const n=[];e.color=new c.Color(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const o=i.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],c.LinearSRGBColorSpace),e.opacity=o[3]}i.baseColorTexture!==void 0&&n.push(s.assignTexture(e,"map",i.baseColorTexture,c.SRGBColorSpace))}return Promise.all(n)}}class io{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);return s===null||s.emissiveStrength!==void 0&&(t.emissiveIntensity=s.emissiveStrength),Promise.resolve()}}class oo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];if(s.clearcoatFactor!==void 0&&(t.clearcoat=s.clearcoatFactor),s.clearcoatTexture!==void 0&&n.push(this.parser.assignTexture(t,"clearcoatMap",s.clearcoatTexture)),s.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=s.clearcoatRoughnessFactor),s.clearcoatRoughnessTexture!==void 0&&n.push(this.parser.assignTexture(t,"clearcoatRoughnessMap",s.clearcoatRoughnessTexture)),s.clearcoatNormalTexture!==void 0&&(n.push(this.parser.assignTexture(t,"clearcoatNormalMap",s.clearcoatNormalTexture)),s.clearcoatNormalTexture.scale!==void 0)){const i=s.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new c.Vector2(i,i)}return Promise.all(n)}}class ro{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_DISPERSION}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);return s===null||(t.dispersion=s.dispersion!==void 0?s.dispersion:0),Promise.resolve()}}class ao{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];return s.iridescenceFactor!==void 0&&(t.iridescence=s.iridescenceFactor),s.iridescenceTexture!==void 0&&n.push(this.parser.assignTexture(t,"iridescenceMap",s.iridescenceTexture)),s.iridescenceIor!==void 0&&(t.iridescenceIOR=s.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),s.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=s.iridescenceThicknessMinimum),s.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=s.iridescenceThicknessMaximum),s.iridescenceThicknessTexture!==void 0&&n.push(this.parser.assignTexture(t,"iridescenceThicknessMap",s.iridescenceThicknessTexture)),Promise.all(n)}}class lo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_SHEEN}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];if(t.sheenColor=new c.Color(0,0,0),t.sheenRoughness=0,t.sheen=1,s.sheenColorFactor!==void 0){const i=s.sheenColorFactor;t.sheenColor.setRGB(i[0],i[1],i[2],c.LinearSRGBColorSpace)}return s.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=s.sheenRoughnessFactor),s.sheenColorTexture!==void 0&&n.push(this.parser.assignTexture(t,"sheenColorMap",s.sheenColorTexture,c.SRGBColorSpace)),s.sheenRoughnessTexture!==void 0&&n.push(this.parser.assignTexture(t,"sheenRoughnessMap",s.sheenRoughnessTexture)),Promise.all(n)}}class co{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];return s.transmissionFactor!==void 0&&(t.transmission=s.transmissionFactor),s.transmissionTexture!==void 0&&n.push(this.parser.assignTexture(t,"transmissionMap",s.transmissionTexture)),Promise.all(n)}}class uo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_VOLUME}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];t.thickness=s.thicknessFactor!==void 0?s.thicknessFactor:0,s.thicknessTexture!==void 0&&n.push(this.parser.assignTexture(t,"thicknessMap",s.thicknessTexture)),t.attenuationDistance=s.attenuationDistance||1/0;const i=s.attenuationColor||[1,1,1];return t.attenuationColor=new c.Color().setRGB(i[0],i[1],i[2],c.LinearSRGBColorSpace),Promise.all(n)}}class fo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_IOR}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);return s===null||(t.ior=s.ior!==void 0?s.ior:1.5,t.ior===0&&(t.ior=1e3)),Promise.resolve()}}class ho{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_SPECULAR}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];t.specularIntensity=s.specularFactor!==void 0?s.specularFactor:1,s.specularTexture!==void 0&&n.push(this.parser.assignTexture(t,"specularIntensityMap",s.specularTexture));const i=s.specularColorFactor||[1,1,1];return t.specularColor=new c.Color().setRGB(i[0],i[1],i[2],c.LinearSRGBColorSpace),s.specularColorTexture!==void 0&&n.push(this.parser.assignTexture(t,"specularColorMap",s.specularColorTexture,c.SRGBColorSpace)),Promise.all(n)}}class po{constructor(e){this.parser=e,this.name=G.EXT_MATERIALS_BUMP}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];return t.bumpScale=s.bumpFactor!==void 0?s.bumpFactor:1,s.bumpTexture!==void 0&&n.push(this.parser.assignTexture(t,"bumpMap",s.bumpTexture)),Promise.all(n)}}class mo{constructor(e){this.parser=e,this.name=G.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return ee(this.parser,e,this.name)!==null?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=ee(this.parser,e,this.name);if(s===null)return Promise.resolve();const n=[];return s.anisotropyStrength!==void 0&&(t.anisotropy=s.anisotropyStrength),s.anisotropyRotation!==void 0&&(t.anisotropyRotation=s.anisotropyRotation),s.anisotropyTexture!==void 0&&n.push(this.parser.assignTexture(t,"anisotropyMap",s.anisotropyTexture)),Promise.all(n)}}class Ao{constructor(e){this.parser=e,this.name=G.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const i=n.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,o)}}class go{constructor(e){this.parser=e,this.name=G.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],l=n.images[o.source];let u=s.textureLoader;if(l.uri){const d=s.options.manager.getHandler(l.uri);d!==null&&(u=d)}return s.loadTextureImage(e,o.source,u)}}class yo{constructor(e){this.parser=e,this.name=G.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],l=n.images[o.source];let u=s.textureLoader;if(l.uri){const d=s.options.manager.getHandler(l.uri);d!==null&&(u=d)}return s.loadTextureImage(e,o.source,u)}}class Rn{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const n=s.extensions[this.name],i=this.parser.getDependency("buffer",n.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(l){const u=n.byteOffset||0,d=n.byteLength||0,p=n.count,f=n.byteStride,g=new Uint8Array(l,u,d);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(p,f,g,n.mode,n.filter).then(function(y){return y.buffer}):o.ready.then(function(){const y=new ArrayBuffer(p*f);return o.decodeGltfBuffer(new Uint8Array(y),p,f,g,n.mode,n.filter),y})})}else return null}}class bo{constructor(e){this.name=G.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,s=t.nodes[e];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;const n=t.meshes[s.mesh];for(const d of n.primitives)if(d.mode!==ue.TRIANGLES&&d.mode!==ue.TRIANGLE_STRIP&&d.mode!==ue.TRIANGLE_FAN&&d.mode!==void 0)return null;const o=s.extensions[this.name].attributes,l=[],u={};for(const d in o)l.push(this.parser.getDependency("accessor",o[d]).then(p=>(u[d]=p,u[d])));return l.length<1?null:(l.push(this.parser.createNodeMesh(e)),Promise.all(l).then(d=>{const p=d.pop(),f=p.isGroup?p.children:[p],g=d[0].count,y=[];for(const x of f){const m=new c.Matrix4,A=new c.Vector3,M=new c.Quaternion,v=new c.Vector3(1,1,1),w=new c.InstancedMesh(x.geometry,x.material,g);for(let h=0;h<g;h++)u.TRANSLATION&&A.fromBufferAttribute(u.TRANSLATION,h),u.ROTATION&&M.fromBufferAttribute(u.ROTATION,h),u.SCALE&&v.fromBufferAttribute(u.SCALE,h),w.setMatrixAt(h,m.compose(A,M,v));for(const h in u)if(h==="_COLOR_0"){const I=u[h];w.instanceColor=new c.InstancedBufferAttribute(I.array,I.itemSize,I.normalized)}else h!=="TRANSLATION"&&h!=="ROTATION"&&h!=="SCALE"&&x.geometry.setAttribute(h,u[h]);c.Object3D.prototype.copy.call(w,x),this.parser.assignFinalMaterial(w),y.push(w)}return p.isGroup?(p.clear(),p.add(...y),p):y[0]}))}}const _n="glTF",Ge=12,Pn={JSON:1313821514,BIN:5130562};class xo{constructor(e){this.name=G.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,Ge),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==_n)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const n=this.header.length-Ge,i=new DataView(e,Ge);let o=0;for(;o<n;){const l=i.getUint32(o,!0);o+=4;const u=i.getUint32(o,!0);if(o+=4,u===Pn.JSON){const d=new Uint8Array(e,Ge+o,l);this.content=s.decode(d)}else if(u===Pn.BIN){const d=Ge+o;this.body=e.slice(d,d+l)}o+=l}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Io{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=G.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,i=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,l={},u={},d={};for(const p in o){const f=Lt[p]||p.toLowerCase();l[f]=o[p]}for(const p in e.attributes){const f=Lt[p]||p.toLowerCase();if(o[p]!==void 0){const g=s.accessors[e.attributes[p]],y=Be[g.componentType];d[f]=y.name,u[f]=g.normalized===!0}}return t.getDependency("bufferView",i).then(function(p){return new Promise(function(f,g){n.decodeDracoFile(p,function(y){for(const x in y.attributes){const m=y.attributes[x],A=u[x];A!==void 0&&(m.normalized=A)}f(y)},l,d,c.LinearSRGBColorSpace,g)})})}}class Co{constructor(){this.name=G.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class Mo{constructor(){this.name=G.KHR_MESH_QUANTIZATION}}class $n extends c.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,i=e*n*3+n;for(let o=0;o!==n;o++)t[o]=s[i+o];return t}interpolate_(e,t,s,n){const i=this.resultBuffer,o=this.sampleValues,l=this.valueSize,u=l*2,d=l*3,p=n-t,f=(s-t)/p,g=f*f,y=g*f,x=e*d,m=x-d,A=-2*y+3*g,M=y-g,v=1-A,w=M-g+f;for(let h=0;h!==l;h++){const I=o[m+h+l],E=o[m+h+u]*p,N=o[x+h+l],D=o[x+h]*p;i[h]=v*I+w*E+A*N+M*D}return i}}const wo=new c.Quaternion;class vo extends $n{interpolate_(e,t,s,n){const i=super.interpolate_(e,t,s,n);return wo.fromArray(i).normalize().toArray(i),i}}const ue={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Be={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Ln={9728:c.NearestFilter,9729:c.LinearFilter,9984:c.NearestMipmapNearestFilter,9985:c.LinearMipmapNearestFilter,9986:c.NearestMipmapLinearFilter,9987:c.LinearMipmapLinearFilter},kn={33071:c.ClampToEdgeWrapping,33648:c.MirroredRepeatWrapping,10497:c.RepeatWrapping},Nt={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Lt={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},Me={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Eo={CUBICSPLINE:void 0,LINEAR:c.InterpolateLinear,STEP:c.InterpolateDiscrete},St={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function To(r){return r.DefaultMaterial===void 0&&(r.DefaultMaterial=new c.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:c.FrontSide})),r.DefaultMaterial}function Ne(r,e,t){for(const s in t.extensions)r[s]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[s]=t.extensions[s])}function Ae(r,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(r.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function Do(r,e,t){let s=!1,n=!1,i=!1;for(let d=0,p=e.length;d<p;d++){const f=e[d];if(f.POSITION!==void 0&&(s=!0),f.NORMAL!==void 0&&(n=!0),f.COLOR_0!==void 0&&(i=!0),s&&n&&i)break}if(!s&&!n&&!i)return Promise.resolve(r);const o=[],l=[],u=[];for(let d=0,p=e.length;d<p;d++){const f=e[d];if(s){const g=f.POSITION!==void 0?t.getDependency("accessor",f.POSITION):r.attributes.position;o.push(g)}if(n){const g=f.NORMAL!==void 0?t.getDependency("accessor",f.NORMAL):r.attributes.normal;l.push(g)}if(i){const g=f.COLOR_0!==void 0?t.getDependency("accessor",f.COLOR_0):r.attributes.color;u.push(g)}}return Promise.all([Promise.all(o),Promise.all(l),Promise.all(u)]).then(function(d){const p=d[0],f=d[1],g=d[2];return s&&(r.morphAttributes.position=p),n&&(r.morphAttributes.normal=f),i&&(r.morphAttributes.color=g),r.morphTargetsRelative=!0,r})}function No(r,e){if(r.updateMorphTargets(),e.weights!==void 0)for(let t=0,s=e.weights.length;t<s;t++)r.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(r.morphTargetInfluences.length===t.length){r.morphTargetDictionary={};for(let s=0,n=t.length;s<n;s++)r.morphTargetDictionary[t[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function So(r){let e;const t=r.extensions&&r.extensions[G.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Ot(t.attributes):e=r.indices+":"+Ot(r.attributes)+":"+r.mode,r.targets!==void 0)for(let s=0,n=r.targets.length;s<n;s++)e+=":"+Ot(r.targets[s]);return e}function Ot(r){let e="";const t=Object.keys(r).sort();for(let s=0,n=t.length;s<n;s++)e+=t[s]+":"+r[t[s]]+";";return e}function kt(r){switch(r){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function Oo(r){return r.search(/\.jpe?g($|\?)/i)>0||r.search(/^data\:image\/jpeg/)===0?"image/jpeg":r.search(/\.webp($|\?)/i)>0||r.search(/^data\:image\/webp/)===0?"image/webp":r.search(/\.ktx2($|\?)/i)>0||r.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const Ro=new c.Matrix4;class Po{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new to,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,n=-1,i=!1,o=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){const l=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(l)===!0;const u=l.match(/Version\/(\d+)/);n=s&&u?parseInt(u[1],10):-1,i=l.indexOf("Firefox")>-1,o=i?l.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||i&&o<98?this.textureLoader=new c.TextureLoader(this.options.manager):this.textureLoader=new c.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new c.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,n=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(o){const l={scene:o[0][n.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:n.asset,parser:s,userData:{}};return Ne(i,l,n),Ae(l,n),Promise.all(s._invokeAll(function(u){return u.afterRoot&&u.afterRoot(l)})).then(function(){for(const u of l.scenes)u.updateMatrixWorld();e(l)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let n=0,i=t.length;n<i;n++){const o=t[n].joints;for(let l=0,u=o.length;l<u;l++)e[o[l]].isBone=!0}for(let n=0,i=e.length;n<i;n++){const o=e[n];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(s[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const n=s.clone(),i=(o,l)=>{const u=this.associations.get(o);u!=null&&this.associations.set(l,u);for(const[d,p]of o.children.entries())i(p,l.children[d])};return i(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const i=e(t[n]);i&&s.push(i)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this._invokeOne(function(i){return i.loadNode&&i.loadNode(t)});break;case"mesh":n=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(t)});break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(t)});break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(t)});break;case"texture":n=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(t)});break;case"skin":n=this.loadSkin(t);break;case"animation":n=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(t)});break;case"camera":n=this.loadCamera(t);break;default:if(n=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(e,t)}),!n)throw new Error("Unknown type: "+e);break}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(n.map(function(i,o){return s.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],s=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[G.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(i,o){s.load(c.LoaderUtils.resolveURL(t.uri,n.path),i,void 0,function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(s){const n=t.byteLength||0,i=t.byteOffset||0;return s.slice(i,i+n)})}loadAccessor(e){const t=this,s=this.json,n=this.json.accessors[e];if(n.bufferView===void 0&&n.sparse===void 0){const o=Nt[n.type],l=Be[n.componentType],u=n.normalized===!0,d=new l(n.count*o);return Promise.resolve(new c.BufferAttribute(d,o,u))}const i=[];return n.bufferView!==void 0?i.push(this.getDependency("bufferView",n.bufferView)):i.push(null),n.sparse!==void 0&&(i.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(i).then(function(o){const l=o[0],u=Nt[n.type],d=Be[n.componentType],p=d.BYTES_PER_ELEMENT,f=p*u,g=n.byteOffset||0,y=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,x=n.normalized===!0;let m,A;if(y&&y!==f){const M=Math.floor(g/y),v="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+M+":"+n.count;let w=t.cache.get(v);w||(m=new d(l,M*y,n.count*y/p),w=new c.InterleavedBuffer(m,y/p),t.cache.add(v,w)),A=new c.InterleavedBufferAttribute(w,u,g%y/p,x)}else l===null?m=new d(n.count*u):m=new d(l,g,n.count*u),A=new c.BufferAttribute(m,u,x);if(n.sparse!==void 0){const M=Nt.SCALAR,v=Be[n.sparse.indices.componentType],w=n.sparse.indices.byteOffset||0,h=n.sparse.values.byteOffset||0,I=new v(o[1],w,n.sparse.count*M),E=new d(o[2],h,n.sparse.count*u);l!==null&&(A=new c.BufferAttribute(A.array.slice(),A.itemSize,A.normalized)),A.normalized=!1;for(let N=0,D=I.length;N<D;N++){const V=I[N];if(A.setX(V,E[N*u]),u>=2&&A.setY(V,E[N*u+1]),u>=3&&A.setZ(V,E[N*u+2]),u>=4&&A.setW(V,E[N*u+3]),u>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}A.normalized=x}return A})}loadTexture(e){const t=this.json,s=this.options,i=t.textures[e].source,o=t.images[i];let l=this.textureLoader;if(o.uri){const u=s.manager.getHandler(o.uri);u!==null&&(l=u)}return this.loadTextureImage(e,i,l)}loadTextureImage(e,t,s){const n=this,i=this.json,o=i.textures[e],l=i.images[t],u=(l.uri||l.bufferView)+":"+o.sampler;if(this.textureCache[u])return this.textureCache[u];const d=this.loadImageSource(t,s).then(function(p){p.flipY=!1,p.name=o.name||l.name||"",p.name===""&&typeof l.uri=="string"&&l.uri.startsWith("data:image/")===!1&&(p.name=l.uri);const g=(i.samplers||{})[o.sampler]||{};return p.magFilter=Ln[g.magFilter]||c.LinearFilter,p.minFilter=Ln[g.minFilter]||c.LinearMipmapLinearFilter,p.wrapS=kn[g.wrapS]||c.RepeatWrapping,p.wrapT=kn[g.wrapT]||c.RepeatWrapping,p.generateMipmaps=!p.isCompressedTexture&&p.minFilter!==c.NearestFilter&&p.minFilter!==c.LinearFilter,n.associations.set(p,{textures:e}),p}).catch(function(){return null});return this.textureCache[u]=d,d}loadImageSource(e,t){const s=this,n=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(f=>f.clone());const o=n.images[e],l=self.URL||self.webkitURL;let u=o.uri||"",d=!1;if(o.bufferView!==void 0)u=s.getDependency("bufferView",o.bufferView).then(function(f){d=!0;const g=new Blob([f],{type:o.mimeType});return u=l.createObjectURL(g),u});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const p=Promise.resolve(u).then(function(f){return new Promise(function(g,y){let x=g;t.isImageBitmapLoader===!0&&(x=function(m){const A=new c.Texture(m);A.needsUpdate=!0,g(A)}),t.load(c.LoaderUtils.resolveURL(f,i.path),x,void 0,y)})}).then(function(f){return d===!0&&l.revokeObjectURL(u),Ae(f,o),f.userData.mimeType=o.mimeType||Oo(o.uri),f}).catch(function(f){throw console.error("THREE.GLTFLoader: Couldn't load texture",u),f});return this.sourceCache[e]=p,p}assignTexture(e,t,s,n){const i=this;return this.getDependency("texture",s.index).then(function(o){if(!o)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(o=o.clone(),o.channel=s.texCoord),i.extensions[G.KHR_TEXTURE_TRANSFORM]){const l=s.extensions!==void 0?s.extensions[G.KHR_TEXTURE_TRANSFORM]:void 0;if(l){const u=i.associations.get(o);o=i.extensions[G.KHR_TEXTURE_TRANSFORM].extendTexture(o,l),i.associations.set(o,u)}}return n!==void 0&&(o.colorSpace=n),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let s=e.material;const n=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){const l="PointsMaterial:"+s.uuid;let u=this.cache.get(l);u||(u=new c.PointsMaterial,c.Material.prototype.copy.call(u,s),u.color.copy(s.color),u.map=s.map,u.sizeAttenuation=!1,this.cache.add(l,u)),s=u}else if(e.isLine){const l="LineBasicMaterial:"+s.uuid;let u=this.cache.get(l);u||(u=new c.LineBasicMaterial,c.Material.prototype.copy.call(u,s),u.color.copy(s.color),u.map=s.map,this.cache.add(l,u)),s=u}if(n||i||o){let l="ClonedMaterial:"+s.uuid+":";n&&(l+="derivative-tangents:"),i&&(l+="vertex-colors:"),o&&(l+="flat-shading:");let u=this.cache.get(l);u||(u=s.clone(),i&&(u.vertexColors=!0),o&&(u.flatShading=!0),n&&(u.normalScale&&(u.normalScale.y*=-1),u.clearcoatNormalScale&&(u.clearcoatNormalScale.y*=-1)),this.cache.add(l,u),this.associations.set(u,this.associations.get(s))),s=u}e.material=s}getMaterialType(){return c.MeshStandardMaterial}loadMaterial(e){const t=this,s=this.json,n=this.extensions,i=s.materials[e];let o;const l={},u=i.extensions||{},d=[];if(u[G.KHR_MATERIALS_UNLIT]){const f=n[G.KHR_MATERIALS_UNLIT];o=f.getMaterialType(),d.push(f.extendParams(l,i,t))}else{const f=i.pbrMetallicRoughness||{};if(l.color=new c.Color(1,1,1),l.opacity=1,Array.isArray(f.baseColorFactor)){const g=f.baseColorFactor;l.color.setRGB(g[0],g[1],g[2],c.LinearSRGBColorSpace),l.opacity=g[3]}f.baseColorTexture!==void 0&&d.push(t.assignTexture(l,"map",f.baseColorTexture,c.SRGBColorSpace)),l.metalness=f.metallicFactor!==void 0?f.metallicFactor:1,l.roughness=f.roughnessFactor!==void 0?f.roughnessFactor:1,f.metallicRoughnessTexture!==void 0&&(d.push(t.assignTexture(l,"metalnessMap",f.metallicRoughnessTexture)),d.push(t.assignTexture(l,"roughnessMap",f.metallicRoughnessTexture))),o=this._invokeOne(function(g){return g.getMaterialType&&g.getMaterialType(e)}),d.push(Promise.all(this._invokeAll(function(g){return g.extendMaterialParams&&g.extendMaterialParams(e,l)})))}i.doubleSided===!0&&(l.side=c.DoubleSide);const p=i.alphaMode||St.OPAQUE;if(p===St.BLEND?(l.transparent=!0,l.depthWrite=!1):(l.transparent=!1,p===St.MASK&&(l.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&o!==c.MeshBasicMaterial&&(d.push(t.assignTexture(l,"normalMap",i.normalTexture)),l.normalScale=new c.Vector2(1,1),i.normalTexture.scale!==void 0)){const f=i.normalTexture.scale;l.normalScale.set(f,f)}if(i.occlusionTexture!==void 0&&o!==c.MeshBasicMaterial&&(d.push(t.assignTexture(l,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(l.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&o!==c.MeshBasicMaterial){const f=i.emissiveFactor;l.emissive=new c.Color().setRGB(f[0],f[1],f[2],c.LinearSRGBColorSpace)}return i.emissiveTexture!==void 0&&o!==c.MeshBasicMaterial&&d.push(t.assignTexture(l,"emissiveMap",i.emissiveTexture,c.SRGBColorSpace)),Promise.all(d).then(function(){const f=new o(l);return i.name&&(f.name=i.name),Ae(f,i),t.associations.set(f,{materials:e}),i.extensions&&Ne(n,f,i),f})}createUniqueName(e){const t=c.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,s=this.extensions,n=this.primitiveCache;function i(l){return s[G.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(l,t).then(function(u){return Vn(u,l,t)})}const o=[];for(let l=0,u=e.length;l<u;l++){const d=e[l],p=So(d),f=n[p];if(f)o.push(f.promise);else{let g;d.extensions&&d.extensions[G.KHR_DRACO_MESH_COMPRESSION]?g=i(d):g=Vn(new c.BufferGeometry,d,t),n[p]={primitive:d,promise:g},o.push(g)}}return Promise.all(o)}loadMesh(e){const t=this,s=this.json,n=this.extensions,i=s.meshes[e],o=i.primitives,l=[];for(let u=0,d=o.length;u<d;u++){const p=o[u].material===void 0?To(this.cache):this.getDependency("material",o[u].material);l.push(p)}return l.push(t.loadGeometries(o)),Promise.all(l).then(function(u){const d=u.slice(0,u.length-1),p=u[u.length-1],f=[];for(let y=0,x=p.length;y<x;y++){const m=p[y],A=o[y];let M;const v=d[y];if(A.mode===ue.TRIANGLES||A.mode===ue.TRIANGLE_STRIP||A.mode===ue.TRIANGLE_FAN||A.mode===void 0)M=i.isSkinnedMesh===!0?new c.SkinnedMesh(m,v):new c.Mesh(m,v),M.isSkinnedMesh===!0&&M.normalizeSkinWeights(),A.mode===ue.TRIANGLE_STRIP?M.geometry=On(M.geometry,c.TriangleStripDrawMode):A.mode===ue.TRIANGLE_FAN&&(M.geometry=On(M.geometry,c.TriangleFanDrawMode));else if(A.mode===ue.LINES)M=new c.LineSegments(m,v);else if(A.mode===ue.LINE_STRIP)M=new c.Line(m,v);else if(A.mode===ue.LINE_LOOP)M=new c.LineLoop(m,v);else if(A.mode===ue.POINTS)M=new c.Points(m,v);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+A.mode);Object.keys(M.geometry.morphAttributes).length>0&&No(M,i),M.name=t.createUniqueName(i.name||"mesh_"+e),Ae(M,i),A.extensions&&Ne(n,M,A),t.assignFinalMaterial(M),f.push(M)}for(let y=0,x=f.length;y<x;y++)t.associations.set(f[y],{meshes:e,primitives:y});if(f.length===1)return i.extensions&&Ne(n,f[0],i),f[0];const g=new c.Group;i.extensions&&Ne(n,g,i),t.associations.set(g,{meshes:e});for(let y=0,x=f.length;y<x;y++)g.add(f[y]);return g})}loadCamera(e){let t;const s=this.json.cameras[e],n=s[s.type];if(!n){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?t=new c.PerspectiveCamera(c.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(t=new c.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(t.name=this.createUniqueName(s.name)),Ae(t,s),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],s=[];for(let n=0,i=t.joints.length;n<i;n++)s.push(this._loadNodeShallow(t.joints[n]));return t.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",t.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(n){const i=n.pop(),o=n,l=[],u=[];for(let d=0,p=o.length;d<p;d++){const f=o[d];if(f){l.push(f);const g=new c.Matrix4;i!==null&&g.fromArray(i.array,d*16),u.push(g)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[d])}return new c.Skeleton(l,u)})}loadAnimation(e){const t=this.json,s=this,n=t.animations[e],i=n.name?n.name:"animation_"+e,o=[],l=[],u=[],d=[],p=[];for(let f=0,g=n.channels.length;f<g;f++){const y=n.channels[f],x=n.samplers[y.sampler],m=y.target,A=m.node,M=n.parameters!==void 0?n.parameters[x.input]:x.input,v=n.parameters!==void 0?n.parameters[x.output]:x.output;m.node!==void 0&&(o.push(this.getDependency("node",A)),l.push(this.getDependency("accessor",M)),u.push(this.getDependency("accessor",v)),d.push(x),p.push(m))}return Promise.all([Promise.all(o),Promise.all(l),Promise.all(u),Promise.all(d),Promise.all(p)]).then(function(f){const g=f[0],y=f[1],x=f[2],m=f[3],A=f[4],M=[];for(let w=0,h=g.length;w<h;w++){const I=g[w],E=y[w],N=x[w],D=m[w],V=A[w];if(I===void 0)continue;I.updateMatrix&&I.updateMatrix();const W=s._createAnimationTracks(I,E,N,D,V);if(W)for(let Y=0;Y<W.length;Y++)M.push(W[Y])}const v=new c.AnimationClip(i,void 0,M);return Ae(v,n),v})}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return n.mesh===void 0?null:s.getDependency("mesh",n.mesh).then(function(i){const o=s._getNodeRef(s.meshCache,n.mesh,i);return n.weights!==void 0&&o.traverse(function(l){if(l.isMesh)for(let u=0,d=n.weights.length;u<d;u++)l.morphTargetInfluences[u]=n.weights[u]}),o})}loadNode(e){const t=this.json,s=this,n=t.nodes[e],i=s._loadNodeShallow(e),o=[],l=n.children||[];for(let d=0,p=l.length;d<p;d++)o.push(s.getDependency("node",l[d]));const u=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([i,Promise.all(o),u]).then(function(d){const p=d[0],f=d[1],g=d[2];g!==null&&p.traverse(function(y){y.isSkinnedMesh&&y.bind(g,Ro)});for(let y=0,x=f.length;y<x;y++)p.add(f[y]);if(p.userData.pivot!==void 0&&f.length>0){const y=p.userData.pivot,x=f[0];p.pivot=new c.Vector3().fromArray(y),p.position.x-=y[0],p.position.y-=y[1],p.position.z-=y[2],x.position.set(0,0,0),delete p.userData.pivot}return p})}_loadNodeShallow(e){const t=this.json,s=this.extensions,n=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const i=t.nodes[e],o=i.name?n.createUniqueName(i.name):"",l=[],u=n._invokeOne(function(d){return d.createNodeMesh&&d.createNodeMesh(e)});return u&&l.push(u),i.camera!==void 0&&l.push(n.getDependency("camera",i.camera).then(function(d){return n._getNodeRef(n.cameraCache,i.camera,d)})),n._invokeAll(function(d){return d.createNodeAttachment&&d.createNodeAttachment(e)}).forEach(function(d){l.push(d)}),this.nodeCache[e]=Promise.all(l).then(function(d){let p;if(i.isBone===!0?p=new c.Bone:d.length>1?p=new c.Group:d.length===1?p=d[0]:p=new c.Object3D,p!==d[0])for(let f=0,g=d.length;f<g;f++)p.add(d[f]);if(i.name&&(p.userData.name=i.name,p.name=o),Ae(p,i),i.extensions&&Ne(s,p,i),i.matrix!==void 0){const f=new c.Matrix4;f.fromArray(i.matrix),p.applyMatrix4(f)}else i.translation!==void 0&&p.position.fromArray(i.translation),i.rotation!==void 0&&p.quaternion.fromArray(i.rotation),i.scale!==void 0&&p.scale.fromArray(i.scale);if(!n.associations.has(p))n.associations.set(p,{});else if(i.mesh!==void 0&&n.meshCache.refs[i.mesh]>1){const f=n.associations.get(p);n.associations.set(p,{...f})}return n.associations.get(p).nodes=e,p}),this.nodeCache[e]}loadScene(e){const t=this.extensions,s=this.json.scenes[e],n=this,i=new c.Group;s.name&&(i.name=n.createUniqueName(s.name)),Ae(i,s),s.extensions&&Ne(t,i,s);const o=s.nodes||[],l=[];for(let u=0,d=o.length;u<d;u++)l.push(n.getDependency("node",o[u]));return Promise.all(l).then(function(u){for(let p=0,f=u.length;p<f;p++){const g=u[p];g.parent!==null?i.add(eo(g)):i.add(g)}const d=p=>{const f=new Map;for(const[g,y]of n.associations)(g instanceof c.Material||g instanceof c.Texture)&&f.set(g,y);return p.traverse(g=>{const y=n.associations.get(g);y!=null&&f.set(g,y)}),f};return n.associations=d(i),i})}_createAnimationTracks(e,t,s,n,i){const o=[],l=e.name?e.name:e.uuid,u=[];function d(y){y.morphTargetInfluences&&u.push(y.name?y.name:y.uuid)}Me[i.path]===Me.weights?(d(e),e.isGroup&&e.children.forEach(d)):u.push(l);let p;switch(Me[i.path]){case Me.weights:p=c.NumberKeyframeTrack;break;case Me.rotation:p=c.QuaternionKeyframeTrack;break;case Me.translation:case Me.scale:p=c.VectorKeyframeTrack;break;default:switch(s.itemSize){case 1:p=c.NumberKeyframeTrack;break;case 2:case 3:default:p=c.VectorKeyframeTrack;break}break}const f=n.interpolation!==void 0?Eo[n.interpolation]:c.InterpolateLinear,g=this._getArrayFromAccessor(s);for(let y=0,x=u.length;y<x;y++){const m=new p(u[y]+"."+Me[i.path],t.array,g,f);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(m),o.push(m)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const s=kt(t.constructor),n=new Float32Array(t.length);for(let i=0,o=t.length;i<o;i++)n[i]=t[i]*s;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(s){const n=this instanceof c.QuaternionKeyframeTrack?vo:$n;return new n(this.times,this.values,this.getValueSize()/3,s)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Lo(r,e,t){const s=e.attributes,n=new c.Box3;if(s.POSITION!==void 0){const l=t.json.accessors[s.POSITION],u=l.min,d=l.max;if(u!==void 0&&d!==void 0){if(n.set(new c.Vector3(u[0],u[1],u[2]),new c.Vector3(d[0],d[1],d[2])),l.normalized){const p=kt(Be[l.componentType]);n.min.multiplyScalar(p),n.max.multiplyScalar(p)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=e.targets;if(i!==void 0){const l=new c.Vector3,u=new c.Vector3;for(let d=0,p=i.length;d<p;d++){const f=i[d];if(f.POSITION!==void 0){const g=t.json.accessors[f.POSITION],y=g.min,x=g.max;if(y!==void 0&&x!==void 0){if(u.setX(Math.max(Math.abs(y[0]),Math.abs(x[0]))),u.setY(Math.max(Math.abs(y[1]),Math.abs(x[1]))),u.setZ(Math.max(Math.abs(y[2]),Math.abs(x[2]))),g.normalized){const m=kt(Be[g.componentType]);u.multiplyScalar(m)}l.max(u)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}n.expandByVector(l)}r.boundingBox=n;const o=new c.Sphere;n.getCenter(o.center),o.radius=n.min.distanceTo(n.max)/2,r.boundingSphere=o}function Vn(r,e,t){const s=e.attributes,n=[];function i(o,l){return t.getDependency("accessor",o).then(function(u){r.setAttribute(l,u)})}for(const o in s){const l=Lt[o]||o.toLowerCase();l in r.attributes||n.push(i(s[o],l))}if(e.indices!==void 0&&!r.index){const o=t.getDependency("accessor",e.indices).then(function(l){r.setIndex(l)});n.push(o)}return c.ColorManagement.workingColorSpace!==c.LinearSRGBColorSpace&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${c.ColorManagement.workingColorSpace}" not supported.`),Ae(r,e),Lo(r,e,t),Promise.all(n).then(function(){return e.targets!==void 0?Do(r,e.targets,t):r})}let Vt=null;function ko(r){Vt=r}const pe=a.reactive({scripts:[]});function es(){return"s_"+Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4)}function Vo(r){var t;const e={id:es(),name:((t=r==null?void 0:r.name)==null?void 0:t.trim())??"",code:r==null?void 0:r.code};return pe.scripts.push(e),e}function Ho(r){const e=pe.scripts.findIndex(t=>t.id===r);e!==-1&&pe.scripts.splice(e,1)}function Bo(r){pe.scripts=(r||[]).map(e=>({id:(e==null?void 0:e.id)||es(),name:(e==null?void 0:e.name)??"",code:(e==null?void 0:e.code)??""}))}function jo(){pe.scripts=[]}function Fo(r){const e=pe.scripts.find(t=>t.id===r);if(e){if(!Vt){console.warn("[脚本] 执行器尚未注册,请先初始化编辑器(initEditor)");return}try{Vt(e)}catch(t){console.error("[脚本] 执行出错:",e.name,t)}}}function ts(r){var e;return!!r&&((e=r.name)==null?void 0:e.trim())==="初始化"}function Uo(r,e=0){var n,i;if(r.name&&r.name.trim())return r.name.trim();const t=(n=r.code)==null?void 0:n.match(/function\s+([A-Za-z_$][\w$]*)\s*\(/);if(t)return t[1];const s=(i=r.code)==null?void 0:i.match(/(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s*)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)\s*=>/);return s?s[1]:`脚本${e+1}`}const C={mode:"",transformControlsMode:"translate",scene:null,camera:null,defaultMainCamera:null,renderer:null,orbitControls:null,transformControls:null,container:null,gridHelper:null,selectedObject:null};let dt=!1,Re=!1,we=null;const Go=16755200;let Ht=[],at=[],Ze=!0;const xt=1;let Oe=null,de=null,ft=null,ve=[];const Pe=new Map;let Qe,ht=null,Xe=null,Ye=null;async function ns(r,e="edit",t){C.container=r,C.mode=e,Wo(),Xo(),Ko(),t&&(await ys(t.scene,e,t.dataPanels,t.waters,t.textures,t.ambientLight,t.scripts),t!=null&&t.camera&&(C.defaultMainCamera=t.camera,Wt(!0))),Qo(),Zo(),Qe&&C.orbitControls&&(C.orbitControls.target.fromArray(Qe),C.orbitControls.update()),qo(),Bt(),is(),Xe=s=>$o(s),Ye=()=>_o(),e==="edit"&&r.addEventListener("click",Xe),window.addEventListener("resize",Ye),t||Jo(),e==="edit"&&Yo(),hr()}function zo(){return window.devicePixelRatio}function Wo(){const r=zo(),e=new O.WebGLRenderer({antialias:!0,alpha:!0});e.setSize(C.container.clientWidth,C.container.clientHeight),e.setPixelRatio(r),e.toneMapping=O.NeutralToneMapping,e.toneMappingExposure=1,console.log(`[Renderer] css=${C.container.clientWidth}×${C.container.clientHeight}, dpr=${window.devicePixelRatio}, targetRatio=${r}, antialias=true`),C.container.appendChild(e.domElement),C.renderer=e}function qo(){if(!C.renderer||!C.scene||!C.camera)return;const r=C.renderer.getPixelRatio(),e=C.container.clientWidth*r,t=C.container.clientHeight*r,s=new O.WebGLRenderTarget(e,t,{type:O.HalfFloatType,samples:4});s.texture.name="EffectComposer.rt1";const n=new pi(C.renderer,s);n.addPass(new mi(C.scene,C.camera)),n.addPass(new Ai),we=n}function Xo(){if(C.scene=new O.Scene,C.scene.name="sl_scene",C.renderer){const r=ut(C.renderer);r?(C.scene.environment=r,C.scene.environmentIntensity=1):console.warn("[初始化] 环境贴图生成失败,场景将没有 IBL 间接光照")}}function Yo(){const r=new O.GridHelper(30,30,8956671,3364232);r.name="地板",r.userData.type="initFloor",C.scene.add(r),C.gridHelper=r}function Ko(){const r=C.container,e=r.clientWidth/r.clientHeight,t=new O.PerspectiveCamera(45,e,.1,1e3);t.position.set(0,6,15),t.lookAt(0,0,0),C.camera=t}function Wt(r=!1){if(!C.defaultMainCamera)return;const e=C.defaultMainCamera;if(r){C.camera.position.set(e.position[0],e.position[1],e.position[2]),C.camera.rotation.set(e.rotation[0],e.rotation[1],e.rotation[2]),C.camera.updateProjectionMatrix(),Qe=e.target;return}else Yt(""),gt();if(!C.camera||!C.orbitControls)return;const t=C.camera.position.clone(),s=C.orbitControls.target.clone(),n=new O.Vector3(e.position[0],e.position[1],e.position[2]),i=e.target?new O.Vector3(e.target[0],e.target[1],e.target[2]):new O.Vector3(0,0,0);C.orbitControls.enabled=!1,new se.Tween({x:t.x,y:t.y,z:t.z,tx:s.x,ty:s.y,tz:s.z}).to({x:n.x,y:n.y,z:n.z,tx:i.x,ty:i.y,tz:i.z},1e3).easing(se.Easing.Quadratic.InOut).onUpdate(o=>{C.camera.position.set(o.x,o.y,o.z),C.orbitControls.target.set(o.tx,o.ty,o.tz),C.orbitControls.update()}).onComplete(()=>{Qe=e.target,C.orbitControls.enabled=!0}).start()}function Zo(){const r=new Fs(C.camera,C.renderer.domElement);r.minDistance=0,r.maxDistance=1/0,r.addEventListener("start",()=>{dt=!1}),r.addEventListener("change",()=>{dt=!0}),r.addEventListener("end",()=>{dt&&(Re=!0,setTimeout(()=>{Re=!1},200))}),C.orbitControls=r}function Qo(){const r=new $s(C.camera,C.renderer.domElement);r.addEventListener("dragging-changed",e=>{C.orbitControls.enabled=!e.value,e.value||(Re=!0,setTimeout(()=>{Re=!1},200))}),r.addEventListener("objectChange",()=>{const e=C.selectedObject;if(de&&e&&de(e),e&&e.type==="DirectionalLight"){const t=e.userData.helper;t&&t.update&&t.update()}}),C.scene.add(r.getHelper()),C.transformControls=r}function ss(r=C.scene){if(!r||r.children.some(t=>t.type==="AmbientLight"))return null;const e=new O.AmbientLight(pr,mr);return e.name="环境光",r.add(e),e}function Jo(){ss(C.scene)}function is(){var e,t;ht=requestAnimationFrame(is),se.update(),(e=C.orbitControls)==null||e.update(),C.mode==="run"&&we&&C.scene&&C.camera?we.render():(t=C.renderer)==null||t.render(C.scene,C.camera),C.scene&&C.camera&&Xn(C.scene,C.camera),Ze&&C.scene&&(at=[],C.scene.traverse(s=>{s.userData.isWater&&s.type==="Mesh"&&at.push(s)}),Ze=!1);for(let s=0;s<at.length;s++){const n=at[s],i=n.material;if(i.uniforms&&i.uniforms.time){const o=n.userData.waterTimeScale??1;i.uniforms.time.value+=1/60*o,C.camera&&i.uniforms.eye&&i.uniforms.eye.value.copy(C.camera.position);continue}if(i.normalMap){const o=n.userData.waterSpeed||{x:.005,y:.003};i.normalMap.offset.x+=o.x,i.normalMap.offset.y+=o.y}}}function _o(){if(!C.container||!C.camera||!C.renderer)return;const r=C.container.clientWidth,e=C.container.clientHeight;r===0||e===0||(C.camera.aspect=r/e,C.camera.updateProjectionMatrix(),C.renderer.setSize(r,e),we&&we.setSize(r,e),Yn(r,e))}function _e(r){let e=r;for(;e;){if(e.isTransformControlsRoot)return;e=e.parent}C.selectedObject!==r&&(C.selectedObject&&C.transformControls.detach(),C.selectedObject=r,C.transformControls.attach(r),C.transformControls.setMode(C.transformControlsMode),C.transformControls.showX=!0,C.transformControls.showY=!0,C.transformControls.showZ=!0,rs(r),Oe==null||Oe(r))}let ae=null;function os(r){ae=r}function pt(r){ae==null||ae(r)}function qt(r){C.transformControlsMode=r,C.transformControls&&C.transformControls.setMode(C.transformControlsMode)}function rs(r){if(C.mode!=="edit"){gt();return}gt(),r.traverse(e=>{if(e.isMesh){const t=e,s=new O.EdgesGeometry(t.geometry),n=new O.LineBasicMaterial({color:Go,depthTest:!0}),i=new O.LineSegments(s,n);e.add(i),Ht.push(i)}})}function gt(){for(const r of Ht)r.parent&&r.parent.remove(r),r.geometry.dispose(),r.material.dispose();Ht=[]}function Xt(){C.selectedObject&&(gt(),C.transformControls.detach(),C.selectedObject=null,Oe==null||Oe(null))}function Yt(r){let e=null;Pe.forEach(t=>{t.userData.id==r&&(e=t),t.children&&t.children.forEach(s=>{s.name&&s.name.startsWith("DataPanel_")&&(s.visible=!1)})}),e&&(e.children.forEach(t=>{t.name&&t.name.startsWith("DataPanel_")&&(t.visible=!0)}),rs(e),C.selectedObject=e,setTimeout(()=>{Kt(e)},500))}function $o(r){if(Re){Re=!1;return}const e=er(r);e?_e(e):Xt()}function er(r){const e=C.renderer.domElement.getBoundingClientRect(),t=new O.Vector2((r.clientX-e.left)/e.width*2-1,-((r.clientY-e.top)/e.height)*2+1),s=new O.Raycaster;s.setFromCamera(t,C.camera);const n=[],i=l=>{l.isTransformControlsRoot||l.isLine||l.isLineSegments||((l.userData.isMovable||l.userData.type==="lightHelper")&&n.push(l),l.children.forEach(i))};i(C.scene);const o=s.intersectObjects(n);if(o.length===0)return null;for(const l of o){const u=Hn(l.object);if(u!==C.selectedObject)return u}return Hn(o[0].object)}function Hn(r){var t;let e=r;for(;e;){if(((t=e.userData)==null?void 0:t.type)==="lightHelper"||e.type==="DirectionalLightHelper")return e.light||e;e=e.parent}if(r.type==="Line"||r.type==="LineSegments"){const s=r.parent;if(s)switch(s.type){case"DirectionalLightHelper":return s.light;case"AmbientLight":return s;default:return s.isMesh?s:r}return r}return r}function Kt(r,e=500){if(!C.camera||!C.orbitControls){console.warn("[focusOnObject] 编辑器尚未初始化或已销毁,无法执行聚焦操作。请确保已调用 initEditor()");return}if(!r){console.warn("[focusOnObject] 传入的物体为空,无法执行聚焦操作。");return}let t=null;r.userData.closeUpView&&typeof r.userData.closeUpView.x=="number"&&typeof r.userData.closeUpView.y=="number"&&typeof r.userData.closeUpView.z=="number"&&(t=r.userData.closeUpView);const s=new O.Vector3;r.getWorldPosition(s);const i=new O.Box3().setFromObject(r).getSize(new O.Vector3),o=Math.max(i.x,i.y,i.z)*.5,l=Math.max(o*3.5,5),u=new O.Vector3().copy(C.camera.position).sub(s).normalize();u.lengthSq()<.001&&u.set(0,0,1);const d=s.clone().add(u.multiplyScalar(l)),p=C.camera.position.clone(),f=C.orbitControls.target.clone();try{new se.Tween({x:p.x,y:p.y,z:p.z,tx:f.x,ty:f.y,tz:f.z}).to({x:t?t.x:d.x,y:t?t.y:d.y,z:t?t.z:d.z,tx:s.x,ty:s.y,tz:s.z},e).easing(se.Easing.Quadratic.InOut).onUpdate(g=>{C.camera.position.set(g.x,g.y,g.z),C.orbitControls.target.set(g.tx,g.ty,g.tz),C.orbitControls.update()}).start()}catch(g){console.error("[focusOnObject] TWEEN 动画创建失败,请检查 @tweenjs/tween.js 是否已正确安装且版本兼容(^23.1.3):",g)}}function tr(r){r.userData.id&&Pe.set(String(r.userData.id),r)}function nr(r){r.userData.id&&Pe.delete(String(r.userData.id))}function as(r,e){const t=e||r.userData.id;if(t)Pe.set(String(t),r);else{const s=O.MathUtils.generateUUID();r.userData.id=s,Pe.set(s,r)}}function sr(r){r.traverse(e=>{if(e.name&&e.name.startsWith("DataPanel_")){const t=e;t.element&&t.element.parentNode&&t.element.parentNode.removeChild(t.element)}})}function ls(r){var s,n;const e=(s=C.scene)==null?void 0:s.environment;if(!e)return;const t=((n=C.scene)==null?void 0:n.environmentIntensity)??1;r.traverse(i=>{if(i.isMesh){const o=i,l=Array.isArray(o.material)?o.material:[o.material];for(const u of l){const d=u;d&&d.isMeshStandardMaterial&&!d.envMap&&(d.envMap=e,d.envMapIntensity=t,d.needsUpdate=!0)}}})}function ge(r,e=!1){C.scene.add(r),ls(r),Ze=!0,r.userData.isMovable&&(ir(r),It()),e&&C.mode==="edit"&&_e(r)}function Zt(r){C.selectedObject===r&&Xt(),Ze=!0,sr(r),nr(r),r.userData.helper&&C.scene.remove(r.userData.helper),r.parent?r.parent.remove(r):C.scene.remove(r),or(r),It()}function Qt(r){const e=C.scene.getObjectByProperty("uuid",r);e&&Zt(e)}function ir(r){r.userData.isMovable&&r.parent===C.scene&&(ve.includes(r)||ve.push(r))}function or(r){const e=ve.indexOf(r);e!==-1&&ve.splice(e,1)}function Bt(){const r=[];C.scene.children.forEach(e=>{e.userData.isMovable&&r.push(e)}),ve=r,It()}function It(){ft==null||ft([...ve])}function cs(r){Oe=r}function us(r){de=r}function ds(r){ft=r}function Jt(){return ve}function yt(){return C.selectedObject}function fs(r,e,t){if(!C.scene)return;const s=Pe.get(r);if(s){const n=je(s);n&&n.updateItemByCode(e,t)}}function jt(){return C.scene}function bt(){return C.camera}function Ft(){return C.renderer}const hs={linear:se.Easing.Linear.None,"quad.in":se.Easing.Quadratic.In,"quad.out":se.Easing.Quadratic.Out,"quad.inout":se.Easing.Quadratic.InOut,"cubic.inout":se.Easing.Cubic.InOut,"sine.inout":se.Easing.Sinusoidal.InOut,"back.out":se.Easing.Back.Out,"elastic.out":se.Easing.Elastic.Out,"bounce.out":se.Easing.Bounce.Out},Ut=new WeakMap;function ps(r){let e=Ut.get(r);return e||(e={position:new Set,rotation:new Set,scale:new Set,opacity:new Set},Ut.set(r,e)),e}function rr(r,e,t,s){const n=ps(r);for(const o of t)n[o].forEach(l=>l.stop()),n[o].clear(),n[o].add(e);const i=()=>{for(const o of t)n[o].delete(e)};e.onComplete(()=>{i(),s==null||s()}),e.onStop(i)}function _t(r,e=[]){if(!r)return;const t=Ut.get(r);if(!t)return;const s=e.length>0?e:["position","rotation","scale","opacity"];for(const n of s)t[n].forEach(i=>i.stop()),t[n].clear()}function ar(r){return r*Math.PI/180}function Ct(r,e={}){if(!r)return console.warn("[脚本动画] 目标对象为空,无法执行动画"),null;const t=e.duration??1e3,s=hs[e.easing??"quad.inout"]??se.Easing.Quadratic.InOut,n=[],i={};e.position&&(n.push("position"),i.position=e.position),e.rotation&&(n.push("rotation"),i.rotation=e.rotation),e.scale&&(n.push("scale"),i.scale=e.scale),_t(r,n);const o=new se.Tween(r).to(i,t).easing(s).onUpdate(()=>{r===C.selectedObject&&(de==null||de(r))}).start();return rr(r,o,n,()=>{var l;(l=e.onComplete)==null||l.call(e),r===C.selectedObject&&(de==null||de(r))}),o}function lr(r,e,t=1e3,s){return Ct(r,{position:e,duration:t,easing:s})}function cr(r,e,t=1e3,s){return Ct(r,{rotation:e,duration:t,easing:s})}function ur(r,e,t=1e3,s){return Ct(r,{scale:e,duration:t,easing:s})}const ms="__fadeToOrigin__",mt="__panelOriginTransparent__",Mt="__panelOpacity__";function dr(r,e,t=1e3,s,n){if(!r)return console.warn("[脚本动画] 目标对象为空,无法执行透明度动画"),null;const i=new Set;if(r.traverse(m=>{const A=m.material;if(!A)return;(Array.isArray(A)?A:[A]).forEach(v=>v&&i.add(v))}),i.size===0)return console.warn("[脚本动画] 目标及其子节点没有材质,无法执行透明度动画:",r.name),null;const o=t??1e3,l=hs[s??"quad.inout"]??se.Easing.Quadratic.InOut,u=Math.min(1,Math.max(0,e)),d=u<=.01;d||(r.visible=!0),_t(r,["opacity"]);const p=[...i],f=ms;p.forEach(m=>{const A=m.userData;!A[f]&&!m.uniforms&&(A[f]={transparent:m.transparent,opacity:m.opacity}),delete A[Mt]}),p.forEach(m=>{m.transparent=!0,m.uniforms||(m.depthWrite=!1),m.needsUpdate=!0}),C.renderer&&C.scene&&C.camera&&C.renderer.render(C.scene,C.camera);const g=ps(r),y=p.map(m=>{const A=new se.Tween(m).to({opacity:u},o).easing(l).start();return g.opacity.add(A),A}),x=()=>{p.forEach(m=>{if(m.uniforms)return;const M=m.userData[f];if(!M)return;!M.transparent&&m.transparent&&(m.transparent=!1,m.depthWrite=!0,m.needsUpdate=!0)})};return y.forEach((m,A)=>{A===0?m.onComplete(()=>{g.opacity.delete(m),!d&&u>=.999?x():d&&(x(),r.visible=!1),n==null||n(),r===C.selectedObject&&(de==null||de(r))}):m.onComplete(()=>g.opacity.delete(m)),m.onStop(()=>g.opacity.delete(m))}),y[0]??null}function fr(){return{THREE:O,scene:jt(),camera:bt(),renderer:Ft(),selectedObject:yt(),getScene:jt,getCamera:bt,getRenderer:Ft,getSelectedObject:yt,getSceneObjects:Jt,addModel:ge,removeModel:Zt,removeModelById:Qt,selectObject:_e,updateDataPanelValue:fs,setTransformMode:qt,focusOnObject:Kt,animateTo:Ct,moveTo:lr,rotateTo:cr,scaleTo:ur,fadeTo:dr,stopAnimations:_t,degToRad:ar,console,window,document,setTimeout,setInterval,requestAnimationFrame}}function As(r){var l;const e=(l=r==null?void 0:r.code)==null?void 0:l.trim();if(!e)return;const t=fr(),s=Object.keys(t),n=Object.values(t),i=/^\s*(?:async\s+)?function\s+[A-Za-z_$][\w$]*\s*\(/.test(e)||/^\s*(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*(?:async\s*)?(?:function\b|\([^)]*\)\s*=>|[A-Za-z_$][\w$]*\s*=>)/.test(e)||/^\s*[A-Za-z_$][\w$]*\s*=\s*(?:async\s*)?(?:function\b|\([^)]*\)\s*=>|[A-Za-z_$][\w$]*\s*=>)/.test(e)||/^\s*(?:async\s+)?\([^)]*\)\s*=>/.test(e);let o=null;if(i)try{const d=new Function(...s,`return (${e});`)(...n);typeof d=="function"&&(o=d)}catch{o=null}if(!o)try{o=new Function(...s,`return (function () { ${e}
139
139
  });`)(...n)}catch(u){console.error("[脚本] 代码编译失败:",r.name,u,`
140
140
  提示:JS 语法错误(多为括号不匹配或可选链 ?. 不能作为赋值目标)。例如 selectedObject?.rotation.y += 0.5 应改为 if (selectedObject) selectedObject.rotation.y += 0.5`);return}try{const u=o.call(t);u instanceof Promise&&u.catch(d=>console.error("[脚本] 执行异常:",r.name,d))}catch(u){console.error("[脚本] 执行异常:",r.name,u)}}ko(As);function hr(){for(const r of pe.scripts)ts(r)&&(console.log("[初始化] 自动执行脚本:",r.name),As(r))}const pr=16777215,mr=1;async function gs(){var h,I,E,N;ae==null||ae(!0),await new Promise(D=>setTimeout(D,50)),Xt();const r=C.scene;if(!r)return ae==null||ae(!1),{scene:new ArrayBuffer(0),camera:{position:void 0,rotation:void 0,target:[0,0,0]},dataPanels:{},waters:[],textures:{},ambientLight:null,scripts:[]};const e=[],t=new Map,s=new Map,n={},i=[],o=[];let l=null;const u=[];r.traverse(D=>{var V,W,Y,Z;if(D.userData._sourceUuid=D.uuid,D.type==="AmbientLight"){const q=D;l={color:"#"+q.color.getHexString(),intensity:q.intensity,name:q.name||"环境光",visible:q.visible,position:q.position.toArray()},u.push(q)}if(D.userData.type==="lightHelper"&&e.push(D),D.type==="DirectionalLight"&&D.userData.helper&&(t.set(D,D.userData.helper),D.userData.helper=void 0),D.userData.isWater&&D.type==="Mesh"&&D.parent&&((W=(V=D.material)==null?void 0:V.uniforms)!=null&&W.waterColor)){const q=D,j=q.material;let P="#4fc3f7";j.uniforms&&j.uniforms.waterColor&&(P="#"+j.uniforms.waterColor.value.getHexString());const L=q.geometry,B={uuid:D.uuid,name:D.name,position:D.position.toArray(),rotation:[D.rotation.x,D.rotation.y,D.rotation.z],scale:D.scale.toArray(),color:P,timeScale:D.userData.waterTimeScale??.05,alpha:j.uniforms&&j.uniforms.alpha?j.uniforms.alpha.value:.3,reflection:D.userData.reflectionEnabled!==!1,geometryType:"box",boxWidth:void 0,boxDepth:void 0,cylinderRadiusTop:void 0,cylinderRadiusBottom:void 0,cylinderRadialSegments:void 0};L.parameters&&L.parameters.radiusTop!==void 0?(B.geometryType="cylinder",B.cylinderRadiusTop=L.parameters.radiusTop,B.cylinderRadiusBottom=L.parameters.radiusBottom,B.cylinderRadialSegments=L.parameters.radialSegments):(B.geometryType="box",B.boxWidth=L.parameters.width,B.boxDepth=L.parameters.depth),i.push(B),o.push(D)}if(D.name&&D.name.startsWith("DataPanel_")){const q=D;if(q.element){const j=q.element.querySelector("[data-panel-title]"),P=[];if(q.element.querySelectorAll(".sl-css2d-data-panel-item").forEach(B=>{var oe,fe,he;const K=B.querySelector(".item-label"),U=B.querySelector(".item-value");if(K&&U){const be=(K.textContent||"").trim(),Le=((fe=(oe=U.childNodes[0])==null?void 0:oe.textContent)==null?void 0:fe.trim())||"",xe=U.querySelector("span"),Ie=xe?(xe.textContent||"").trim():void 0,ke=((he=B.getAttribute("data-item-code"))==null?void 0:he.trim())||void 0;P.push({label:be,value:Le,unit:Ie,code:ke})}}),D.parent){const B=q.element.style.width||"",K=q.element.style.fontSize||"",U=je(D.parent),oe=U?U.getOffsetY():.1;s.set(D.parent.userData.id?D.parent.userData.id:D.parent.uuid,{title:((Y=j==null?void 0:j.textContent)==null?void 0:Y.trim())||"",items:P,width:B,fontSize:K,offsetY:oe,offsetX:U?U.getOffsetX():0,offsetZ:U?U.getOffsetZ():0})}}}if(D.type==="Mesh"){const q=D,j=Array.isArray(q.material)?q.material:[q.material];for(const P of j)if(P&&P.userData){const L=P.userData;if(L._mapDataUrl||L._normalMapDataUrl||L._aoMapDataUrl){const B=P.uuid,K=n[B]||{};L._mapDataUrl&&(K.mapDataUrl=L._mapDataUrl,K.mapFileName=L._mapFileName),L._normalMapDataUrl&&(K.normalMapDataUrl=L._normalMapDataUrl,K.normalMapFileName=L._normalMapFileName,K.normalScale=((Z=P.normalScale)==null?void 0:Z.x)??1),L._aoMapDataUrl&&(K.aoMapDataUrl=L._aoMapDataUrl,K.aoMapFileName=L._aoMapFileName,K.aoMapIntensity=P.aoMapIntensity??1),n[B]=K}}}}),e.forEach(D=>r.remove(D));const d=(h=C.transformControls)==null?void 0:h.getHelper(),p=(d==null?void 0:d.parent)??null;d&&d.parent&&d.parent.remove(d);const f=new Map;for(const D of u)f.set(D,D.parent),D.parent&&D.parent.remove(D);const g=[];r.traverse(D=>{if(D.type==="DirectionalLight"){const V=D;V.target.parent===r&&g.push(V.target)}});for(const D of g)r.remove(D);const y=new Map;for(const D of o)y.set(D,D.parent),D.parent&&D.parent.remove(D);const x=r.clone();x.children=x.children.filter(D=>D.userData.type!=="initFloor"),x.traverse(D=>{D.name&&D.name.startsWith("DataPanel_")&&D.parent&&D.parent.remove(D)});const A=await new qe().parseAsync(x,{binary:!0,onlyVisible:!1,embedImages:!0});e.forEach(D=>r.add(D));for(const D of u){const V=f.get(D);V?V.add(D):r.add(D)}for(const D of g)r.add(D);for(const D of o){const V=y.get(D);V?V.add(D):r.add(D)}t.forEach((D,V)=>{V.userData.helper=D}),r.traverse(D=>{delete D.userData._sourceUuid}),d&&(p?p.add(d):r.add(d));const M={position:(I=C.camera)==null?void 0:I.position.toArray(),rotation:(E=C.camera)==null?void 0:E.rotation.toArray(),target:((N=C.orbitControls)==null?void 0:N.target.toArray())||[0,0,0]},v={};s.forEach((D,V)=>{v[V]=D});const w={scene:A,camera:M,dataPanels:v,waters:i,textures:n,ambientLight:l,scripts:pe.scripts.map(D=>({id:D.id,name:D.name,code:D.code}))};return ae==null||ae(!1),w}function Ar(r){if(r instanceof ArrayBuffer||ArrayBuffer.isView(r)){if(r instanceof ArrayBuffer)return r;const e=r;return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}if(typeof r=="string"){const e=r.trim();let t=e;if(e.startsWith("data:")){const s=e.indexOf(",");if(s===-1)return null;t=e.slice(s+1)}if(/^Z2xURg/.test(t)){const s=atob(t),n=new Uint8Array(s.length);for(let i=0;i<s.length;i++)n[i]=s.charCodeAt(i);return n.buffer}return null}return r&&typeof r=="object"&&r.type==="Buffer"&&Array.isArray(r.data)?new Uint8Array(r.data).buffer:null}async function ys(r,e="edit",t,s,n,i,o){var u,d,p,f,g,y,x;const l=Ar(r);if(l){const m=await new Jn().parseAsync(l,""),A=m.scene||((u=m.scenes)==null?void 0:u[0]),M=(d=C.scene)==null?void 0:d.environment;if(C.scene=A,!A.children.some(h=>h.type==="AmbientLight"))if(i){const h=new O.AmbientLight(i.color,i.intensity);h.name=i.name||"环境光",h.visible=i.visible??!0,i.position&&h.position.fromArray(i.position),A.add(h)}else ss(A);if(M)C.scene.environment=M,C.scene.environmentIntensity=1;else if(C.renderer){const h=ut(C.renderer);h&&(C.scene.environment=h,C.scene.environmentIntensity=1)}if(!C.scene.environment&&C.renderer){const h=ut(C.renderer);h?(C.scene.environment=h,C.scene.environmentIntensity=1,console.warn("[导入] 原环境贴图不可用,已重新生成")):console.error("[导入] 环境贴图生成失败,场景将没有 IBL 间接光照,模型会偏暗")}ls(A);let v=!0;for(;v;){v=!1;for(let h=A.children.length-1;h>=0;h--){const I=A.children[h];if(I.name==="sl_scene"||I.name.startsWith("AuxScene")){I.updateMatrixWorld();const E=I.matrixWorld.clone();[...I.children].forEach(N=>{I.remove(N),N.applyMatrix4(E),A.add(N)}),A.remove(I),v=!0}}}const w=h=>{if(h.isTransformControlsRoot||h.isLine||h.isLineSegments||h.type==="AmbientLight"||h.userData.type==="lightHelper"||h.userData.type==="initFloor")return;(h.isMesh||h.type==="Group"&&h.parent===A)&&(h.userData.isMovable=!0);const I=h.material;h.userData.isWater&&I&&!I.uniforms&&!h.userData.waterSpeed&&(h.userData.waterSpeed={x:5e-4,y:5e-4}),h.userData.isWater&&h.isMesh&&(h.renderOrder=xt),h.children.forEach(w)};w(A),A.traverse(h=>{const I=h.material;if(!I||I.uniforms)return;const E=Array.isArray(I)?I:[I];for(const N of E){if(!N)continue;const D=N.userData||{},V=D[Mt];if(V&&typeof V.opacity=="number"){const q=Math.min(1,Math.max(0,V.opacity)),j=q<1?!0:V.transparent===!0,P=!j;(N.opacity!==q||N.transparent!==j||N.depthWrite!==P)&&(N.opacity=q,N.transparent=j,N.depthWrite=P,N.needsUpdate=!0);continue}const W=D[ms];if(!W||typeof W.transparent!="boolean"){N.transparent&&N.opacity<=.01&&(N.opacity=1,N.transparent=!1,N.depthWrite=!0,N.needsUpdate=!0);continue}if(N.opacity>.01&&N.opacity<.999){(!N.transparent||N.depthWrite)&&(N.transparent=!0,N.depthWrite=!1,N.needsUpdate=!0);continue}const Y=W.transparent;let Z=typeof W.opacity=="number"?W.opacity:1;!Y&&Z<=.01&&(Z=1),(N.transparent!==Y||Math.abs(N.opacity-Z)>1e-6)&&(N.transparent=Y,N.opacity=Z,Y||(N.depthWrite=!0),N.needsUpdate=!0)}}),Bt()}else{const m=typeof r=="string"?JSON.parse(r):r,M=new O.ObjectLoader().parse(m);if(M.type==="Scene"){const v=(p=C.scene)==null?void 0:p.environment;if(C.scene=M,v)C.scene.environment=v,C.scene.environmentIntensity=1;else if(C.renderer){const w=ut(C.renderer);w&&(C.scene.environment=w,C.scene.environmentIntensity=1)}}else(f=C.scene)==null||f.add(M)}if(t&&((g=C.scene)==null||g.traverse(m=>{const A=m.userData.id||m.userData._sourceUuid||m.uuid,M=t[A];if(M&&m.userData.isMovable){tr(m);const v=new Ke({title:M.title,items:M.items});v.attachTo(m),v.visible=!1,M.width&&v.setWidth(M.width),M.fontSize&&v.setFontSize(M.fontSize),M.offsetY!==void 0&&v.setOffsetY(M.offsetY),M.offsetX!==void 0&&v.setOffsetX(M.offsetX),M.offsetZ!==void 0&&v.setOffsetZ(M.offsetZ),Wn(m,v)}})),s&&s.length>0&&Promise.resolve().then(()=>Er).then(({addWater:m,addWaterCylinder:A,setWaterReflection:M})=>{for(const v of s){const w=v.geometryType||"box";let h;w==="cylinder"?h=A({radiusTop:v.cylinderRadiusTop??5,radiusBottom:v.cylinderRadiusBottom??5,radialSegments:v.cylinderRadialSegments??32,height:.8,color:v.color,scale:4}):h=m({width:v.boxWidth??10,height:v.boxDepth??10,color:v.color,scale:4}),h.position.fromArray(v.position),h.rotation.set(v.rotation[0],v.rotation[1],v.rotation[2]),h.scale.fromArray(v.scale),h.name=v.name,h.userData.waterTimeScale=v.timeScale??.05,h.userData.isWater=!0,h.userData.isMovable=!0,v.alpha!==void 0&&h.material.uniforms&&h.material.uniforms.alpha&&(h.material.uniforms.alpha.value=v.alpha),v.reflection===!1&&M(h,!1),Ze=!0}Bt()}),n){const m=new O.TextureLoader;(y=C.scene)==null||y.traverse(A=>{if(A.type==="Mesh"){const M=A,v=Array.isArray(M.material)?M.material:[M.material];for(const w of v)if(w&&w.uuid&&n[w.uuid]){const h=n[w.uuid];if(h.mapDataUrl){const I=m.load(h.mapDataUrl);I.wrapS=I.wrapT=O.RepeatWrapping,I.repeat.set(1,1),w.map=I,w.userData=w.userData||{},w.userData._mapDataUrl=h.mapDataUrl,w.userData._mapFileName=h.mapFileName}if(h.normalMapDataUrl){const I=m.load(h.normalMapDataUrl);I.wrapS=I.wrapT=O.RepeatWrapping,I.repeat.set(1,1),w.normalMap=I,w.normalScale=new O.Vector2(h.normalScale??1,h.normalScale??1),w.userData=w.userData||{},w.userData._normalMapDataUrl=h.normalMapDataUrl,w.userData._normalMapFileName=h.normalMapFileName}if(h.aoMapDataUrl){const I=m.load(h.aoMapDataUrl);I.wrapS=I.wrapT=O.RepeatWrapping,I.repeat.set(1,1),w.aoMap=I,w.aoMapIntensity=h.aoMapIntensity??1,w.userData=w.userData||{},w.userData._aoMapDataUrl=h.aoMapDataUrl,w.userData._aoMapFileName=h.aoMapFileName}w.needsUpdate=!0}}})}o&&Bo(o),e==="edit"&&((x=C.scene)==null||x.traverse(m=>{var A,M;if(m.type==="DirectionalLight"){const v=m;if(!v.userData.helper){v.target.parent!==C.scene&&(v.target.parent&&v.target.parent.remove(v.target),v.target.position.set(0,0,0),(A=C.scene)==null||A.add(v.target));const w=new O.DirectionalLightHelper(v,1);w.userData.type="lightHelper",v.userData.helper=w,w.update(),(M=C.scene)==null||M.add(w)}}}))}function bs(r){if(!r)return;if(r.type==="Mesh"){const t=r;t.geometry&&t.geometry.dispose(),t.material&&(Array.isArray(t.material)?t.material:[t.material]).forEach(n=>{n.map&&(n.map=null),n.lightMap&&(n.lightMap=null),n.aoMap&&(n.aoMap=null),n.emissiveMap&&(n.emissiveMap=null),n.bumpMap&&(n.bumpMap=null),n.normalMap&&(n.normalMap=null),n.displacementMap&&(n.displacementMap=null),n.roughnessMap&&(n.roughnessMap=null),n.metalnessMap&&(n.metalnessMap=null),n.alphaMap&&(n.alphaMap=null),n.envMap&&(n.envMap=null),n.dispose()})}const e=r.children.slice();for(const t of e)bs(t)}function xs(){ht!==null&&(cancelAnimationFrame(ht),ht=null),Xe&&C.container&&(C.container.removeEventListener("click",Xe),Xe=null),Ye&&(window.removeEventListener("resize",Ye),Ye=null),C.orbitControls&&(C.orbitControls.dispose(),C.orbitControls=null),C.transformControls&&(C.transformControls.dispose(),C.transformControls=null),we&&(we.dispose(),we=null),C.scene&&(bs(C.scene),C.scene=null),C.renderer&&(C.renderer.dispose(),C.renderer.domElement&&C.container&&C.container.removeChild(C.renderer.domElement),C.renderer=null),Kn(),C.camera=null,C.gridHelper=null,C.selectedObject=null,C.container=null,C.mode="",C.defaultMainCamera=null,Qe=void 0,ve=[],Pe.clear(),It(),jo(),dt=!1,Re=!1}const gr=/^[og]\s*(.+)?/,yr=/^mtllib /,br=/^usemtl /,xr=/^usemap /,Bn=/\s+/,jn=new c.Vector3,Rt=new c.Vector3,Fn=new c.Vector3,Un=new c.Vector3,ce=new c.Vector3,lt=new c.Color;function Ir(){const r={objects:[],object:{},vertices:[],normals:[],colors:[],uvs:[],materials:{},materialLibraries:[],startObject:function(e,t){if(this.object&&this.object.fromDeclaration===!1){this.object.name=e,this.object.fromDeclaration=t!==!1;return}const s=this.object&&typeof this.object.currentMaterial=="function"?this.object.currentMaterial():void 0;if(this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0),this.object={name:e||"",fromDeclaration:t!==!1,geometry:{vertices:[],normals:[],colors:[],uvs:[],hasUVIndices:!1},materials:[],smooth:!0,startMaterial:function(n,i){const o=this._finalize(!1);o&&(o.inherited||o.groupCount<=0)&&this.materials.splice(o.index,1);const l={index:this.materials.length,name:n||"",mtllib:Array.isArray(i)&&i.length>0?i[i.length-1]:"",smooth:o!==void 0?o.smooth:this.smooth,groupStart:o!==void 0?o.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(u){const d={index:typeof u=="number"?u:this.index,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:0,groupEnd:-1,groupCount:-1,inherited:!1};return d.clone=this.clone.bind(d),d}};return this.materials.push(l),l},currentMaterial:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]},_finalize:function(n){const i=this.currentMaterial();if(i&&i.groupEnd===-1&&(i.groupEnd=this.geometry.vertices.length/3,i.groupCount=i.groupEnd-i.groupStart,i.inherited=!1),n&&this.materials.length>1)for(let o=this.materials.length-1;o>=0;o--)this.materials[o].groupCount<=0&&this.materials.splice(o,1);return n&&this.materials.length===0&&this.materials.push({name:"",smooth:this.smooth}),i}},s&&s.name&&typeof s.clone=="function"){const n=s.clone(0);n.inherited=!0,this.object.materials.push(n)}this.objects.push(this.object)},finalize:function(){this.object&&typeof this.object._finalize=="function"&&this.object._finalize(!0)},parseVertexIndex:function(e,t){const s=parseInt(e,10);return(s>=0?s-1:s+t/3)*3},parseNormalIndex:function(e,t){const s=parseInt(e,10);return(s>=0?s-1:s+t/3)*3},parseUVIndex:function(e,t){const s=parseInt(e,10);return(s>=0?s-1:s+t/2)*2},addVertex:function(e,t,s){const n=this.vertices,i=this.object.geometry.vertices;i.push(n[e+0],n[e+1],n[e+2]),i.push(n[t+0],n[t+1],n[t+2]),i.push(n[s+0],n[s+1],n[s+2])},addVertexPoint:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addVertexLine:function(e){const t=this.vertices;this.object.geometry.vertices.push(t[e+0],t[e+1],t[e+2])},addNormal:function(e,t,s){const n=this.normals,i=this.object.geometry.normals;i.push(n[e+0],n[e+1],n[e+2]),i.push(n[t+0],n[t+1],n[t+2]),i.push(n[s+0],n[s+1],n[s+2])},addFaceNormal:function(e,t,s){const n=this.vertices,i=this.object.geometry.normals;jn.fromArray(n,e),Rt.fromArray(n,t),Fn.fromArray(n,s),ce.subVectors(Fn,Rt),Un.subVectors(jn,Rt),ce.cross(Un),ce.normalize(),i.push(ce.x,ce.y,ce.z),i.push(ce.x,ce.y,ce.z),i.push(ce.x,ce.y,ce.z)},addColor:function(e,t,s){const n=this.colors,i=this.object.geometry.colors;n[e]!==void 0&&i.push(n[e+0],n[e+1],n[e+2]),n[t]!==void 0&&i.push(n[t+0],n[t+1],n[t+2]),n[s]!==void 0&&i.push(n[s+0],n[s+1],n[s+2])},addUV:function(e,t,s){const n=this.uvs,i=this.object.geometry.uvs;i.push(n[e+0],n[e+1]),i.push(n[t+0],n[t+1]),i.push(n[s+0],n[s+1])},addDefaultUV:function(){const e=this.object.geometry.uvs;e.push(0,0),e.push(0,0),e.push(0,0)},addUVLine:function(e){const t=this.uvs;this.object.geometry.uvs.push(t[e+0],t[e+1])},addFace:function(e,t,s,n,i,o,l,u,d){const p=this.vertices.length;let f=this.parseVertexIndex(e,p),g=this.parseVertexIndex(t,p),y=this.parseVertexIndex(s,p);if(this.addVertex(f,g,y),this.addColor(f,g,y),l!==void 0&&l!==""){const x=this.normals.length;f=this.parseNormalIndex(l,x),g=this.parseNormalIndex(u,x),y=this.parseNormalIndex(d,x),this.addNormal(f,g,y)}else this.addFaceNormal(f,g,y);if(n!==void 0&&n!==""){const x=this.uvs.length;f=this.parseUVIndex(n,x),g=this.parseUVIndex(i,x),y=this.parseUVIndex(o,x),this.addUV(f,g,y),this.object.geometry.hasUVIndices=!0}else this.addDefaultUV()},addPointGeometry:function(e){this.object.geometry.type="Points";const t=this.vertices.length;for(let s=0,n=e.length;s<n;s++){const i=this.parseVertexIndex(e[s],t);this.addVertexPoint(i),this.addColor(i)}},addLineGeometry:function(e,t){this.object.geometry.type="Line";const s=this.vertices.length,n=this.uvs.length;for(let i=0,o=e.length;i<o;i++)this.addVertexLine(this.parseVertexIndex(e[i],s));for(let i=0,o=t.length;i<o;i++)this.addUVLine(this.parseUVIndex(t[i],n))}};return r.startObject("",!1),r}class Cr extends c.Loader{constructor(e){super(e),this.materials=null}load(e,t,s,n){const i=this,o=new c.FileLoader(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(l){try{t(i.parse(l))}catch(u){n?n(u):console.error(u),i.manager.itemError(e)}},s,n)}setMaterials(e){return this.materials=e,this}parse(e){const t=new Ir;e.indexOf(`\r
141
141
  `)!==-1&&(e=e.replace(/\r\n/g,`