endset_three_editor 0.10.12 → 0.10.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -135,9 +135,9 @@
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 S.Vector3;e.getWorldPosition(t);const i=new S.Box3().setFromObject(e).max.y-t.y+this.options.offsetY;this.css2dObject||(this.css2dObject=new oi(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 S.Vector3;this.attachedObject.getWorldPosition(t);const n=new S.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(ke,"_breathInjected",!1);let qe=ke;const dt=new WeakMap;function Hn(r,e){const t=a.toRaw(r);dt.set(t,e),t.userData._hasDataPanel=!0}function He(r){return dt.get(a.toRaw(r))||null}function Ht(r){const e=a.toRaw(r),t=dt.get(e);t&&(t.dispose(),dt.delete(e)),e.userData._hasDataPanel=void 0}let $=null;function Bn(r){return $?($.domElement.parentNode!==r&&r.appendChild($.domElement),$):($=new ri,$.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 mi(){return $}function jn(r,e){$&&$.render(r,e)}function Fn(r,e){$&&$.setSize(r,e)}function Un(){$&&($.domElement.parentNode&&$.domElement.parentNode.removeChild($.domElement),$=null)}function Ai(){const r=new S.Scene;r.position.y=-3.5;const e=new S.BoxGeometry;e.deleteAttribute("uv");const t=new S.MeshStandardMaterial({side:S.BackSide}),s=new S.PointLight(16777215,900,28,2);s.position.set(.418,16.199,.3),r.add(s);const n=new S.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 S.MeshStandardMaterial,o=new S.InstancedMesh(e,i,6),l=new S.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(y){return new S.MeshLambertMaterial({color:0,emissive:16777215,emissiveIntensity:y})}const d=new S.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 f=new S.Mesh(e,u(50));f.position.set(-16.109,18.021,-8.207),f.scale.set(.1,2.425,2.751),r.add(f);const h=new S.Mesh(e,u(17));h.position.set(14.904,12.198,-1.832),h.scale.set(.15,4.265,6.331),r.add(h);const b=new S.Mesh(e,u(43));b.position.set(-.462,8.89,14.52),b.scale.set(4.38,5.441,.088),r.add(b);const A=new S.Mesh(e,u(20));A.position.set(3.235,11.486,-12.541),A.scale.set(2.5,2,.1),r.add(A);const x=new S.Mesh(e,u(100));return x.position.set(0,20,0),x.scale.set(1,.1,1),r.add(x),r}function rt(r){try{const e=new S.PMREMGenerator(r),t=Ai(),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 bn={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 ze{constructor(){this.textureUtils=null,this.pluginCallbacks=[],this.register(function(e){return new Ti(e)}),this.register(function(e){return new Di(e)}),this.register(function(e){return new Ri(e)}),this.register(function(e){return new Pi(e)}),this.register(function(e){return new Li(e)}),this.register(function(e){return new ki(e)}),this.register(function(e){return new Ni(e)}),this.register(function(e){return new Si(e)}),this.register(function(e){return new Oi(e)}),this.register(function(e){return new Vi(e)}),this.register(function(e){return new Hi(e)}),this.register(function(e){return new Bi(e)}),this.register(function(e){return new ji(e)}),this.register(function(e){return new Fi(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 Ei,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 F={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},Ct="KHR_mesh_quantization",le={};le[c.NearestFilter]=F.NEAREST;le[c.NearestMipmapNearestFilter]=F.NEAREST_MIPMAP_NEAREST;le[c.NearestMipmapLinearFilter]=F.NEAREST_MIPMAP_LINEAR;le[c.LinearFilter]=F.LINEAR;le[c.LinearMipmapNearestFilter]=F.LINEAR_MIPMAP_NEAREST;le[c.LinearMipmapLinearFilter]=F.LINEAR_MIPMAP_LINEAR;le[c.ClampToEdgeWrapping]=F.CLAMP_TO_EDGE;le[c.RepeatWrapping]=F.REPEAT;le[c.MirroredRepeatWrapping]=F.MIRRORED_REPEAT;const xn={scale:"scale",position:"translation",quaternion:"rotation",morphTargetInfluences:"weights"},gi=new c.Color,In=12,yi=1179937895,bi=2,Cn=8,xi=1313821514,Ii=5130562;function xe(r,e){return r.length===e.length&&r.every(function(t,s){return t===e[s]})}function Ci(r){return new TextEncoder().encode(r).buffer}function Mi(r){return xe(r.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function wi(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 Gn(r){return Math.ceil(r/4)*4}function Mt(r,e=0){const t=Gn(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 Mn(){return typeof document>"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function vi(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 Ei{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"}),f=Object.keys(l),h=Object.keys(u);if(f.length>0&&(o.extensionsUsed=f),h.length>0&&(o.extensionsRequired=h),o.buffers&&o.buffers.length>0&&(o.buffers[0].byteLength=d.size),s.binary===!0){const b=new FileReader;b.readAsArrayBuffer(d),b.onloadend=function(){const A=Mt(b.result),x=new DataView(new ArrayBuffer(Cn));x.setUint32(0,A.byteLength,!0),x.setUint32(4,Ii,!0);const y=Mt(Ci(JSON.stringify(o)),32),g=new DataView(new ArrayBuffer(Cn));g.setUint32(0,y.byteLength,!0),g.setUint32(4,xi,!0);const C=new ArrayBuffer(In),w=new DataView(C);w.setUint32(0,yi,!0),w.setUint32(4,bi,!0);const p=In+g.byteLength+y.byteLength+x.byteLength+A.byteLength;w.setUint32(8,p,!0);const m=new Blob([C,g,y,x,A],{type:"application/octet-stream"}),v=new FileReader;v.readAsArrayBuffer(m),v.onloadend=function(){t(v.result)}}}else if(o.buffers&&o.buffers.length>0){const b=new FileReader;b.readAsDataURL(d),b.onloadend=function(){const A=b.result;o.buffers[0].uri=A,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(A){return A.colorSpace===c.SRGBColorSpace?function(y){return y<.04045?y*.0773993808:Math.pow(y*.9478672986+.0521327014,2.4)}:function(y){return y}}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=Mn();u.width=o,u.height=l;const d=u.getContext("2d",{willReadFrequently:!0});d.fillStyle="#00ffff",d.fillRect(0,0,o,l);const f=d.getImageData(0,0,o,l);if(n){d.drawImage(n,0,0,o,l);const A=s(e),x=d.getImageData(0,0,o,l).data;for(let y=2;y<x.length;y+=4)f.data[y]=A(x[y]/256)*256}if(i){d.drawImage(i,0,0,o,l);const A=s(t),x=d.getImageData(0,0,o,l).data;for(let y=1;y<x.length;y+=4)f.data[y]=A(x[y]/256)*256}d.putImageData(f,0,0);const b=(e||t).clone();return b.source=new c.Source(u),b.colorSpace=c.NoColorSpace,b.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."),b}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 F.BYTE:case F.UNSIGNED_BYTE:l=1;break;case F.SHORT:case F.UNSIGNED_SHORT:l=2;break;default:l=4}let u=e.itemSize*l;i===F.ARRAY_BUFFER&&(u=Math.ceil(u/4)*4);const d=Gn(n*u),f=new DataView(new ArrayBuffer(d));let h=0;for(let x=s;x<s+n;x++){for(let y=0;y<e.itemSize;y++){let g;e.itemSize>4?g=e.array[x*e.itemSize+y]:(y===0?g=e.getX(x):y===1?g=e.getY(x):y===2?g=e.getZ(x):y===3&&(g=e.getW(x)),e.normalized===!0&&(g=c.MathUtils.normalize(g,e.array))),t===F.FLOAT?f.setFloat32(h,g,!0):t===F.INT?f.setInt32(h,g,!0):t===F.UNSIGNED_INT?f.setUint32(h,g,!0):t===F.SHORT?f.setInt16(h,g,!0):t===F.UNSIGNED_SHORT?f.setUint16(h,g,!0):t===F.BYTE?f.setInt8(h,g):t===F.UNSIGNED_BYTE&&f.setUint8(h,g),h+=l}h%u!==0&&(h+=u-h%u)}const b={buffer:this.processBuffer(f.buffer),byteOffset:this.byteOffset,byteLength:d};return i!==void 0&&(b.target=i),i===F.ARRAY_BUFFER&&(b.byteStride=u),this.byteOffset+=d,o.bufferViews.push(b),{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=Mt(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=F.FLOAT;else if(e.array.constructor===Int32Array)l=F.INT;else if(e.array.constructor===Uint32Array)l=F.UNSIGNED_INT;else if(e.array.constructor===Int16Array)l=F.SHORT;else if(e.array.constructor===Uint16Array)l=F.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)l=F.BYTE;else if(e.array.constructor===Uint8Array)l=F.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=wi(e,s,n);let d;t!==void 0&&(d=e===t.index?F.ELEMENT_ARRAY_BUFFER:F.ARRAY_BUFFER);const f=this.processBufferView(e,l,s,n,d),h={bufferView:f.id,byteOffset:f.byteOffset,componentType:l,count:n,max:u.max,min:u.min,type:o[e.itemSize]};return e.normalized===!0&&(h.normalized=!0),i.accessors||(i.accessors=[]),i.accessors.push(h)-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 f=o.images.get(e),h=n+":flipY/"+s.toString();if(f[h]!==void 0)return f[h];l.images||(l.images=[]);const b={mimeType:n},A=Mn();A.width=Math.min(e.width,u.maxTextureSize),A.height=Math.min(e.height,u.maxTextureSize);const x=A.getContext("2d",{willReadFrequently:!0});if(s===!0&&(x.translate(0,A.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 g=new Uint8ClampedArray(e.height*e.width*4);for(let C=0;C<g.length;C+=4)g[C+0]=e.data[C+0],g[C+1]=e.data[C+1],g[C+2]=e.data[C+2],g[C+3]=e.data[C+3];x.putImageData(new ImageData(g,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,A.width,A.height);else throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");u.binary===!0?d.push(vi(A,n).then(g=>i.processBufferViewImage(g)).then(g=>{b.bufferView=g})):b.uri=c.ImageUtils.getDataURL(A,n);const y=l.images.push(b)-1;return f[h]=y,y}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(f){f.writeTexture&&await f.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(xe(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 m=0,v=e.material.length;m<v;m++)n.push(e.material[m].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=F.LINES:e.isLineLoop?l=F.LINE_LOOP:e.isLine?l=F.LINE_STRIP:e.isPoints?l=F.POINTS:l=e.material.wireframe?F.LINES:F.TRIANGLES;const u={},d={},f=[],h=[],b={uv:"TEXCOORD_0",uv1:"TEXCOORD_1",uv2:"TEXCOORD_2",uv3:"TEXCOORD_3",color:"COLOR_0",skinWeight:"WEIGHTS_0",skinIndex:"JOINTS_0"},A=o.getAttribute("normal");A!==void 0&&!this.isNormalizedNormalAttribute(A)&&(console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."),o.setAttribute("normal",this.createNormalizedNormalAttribute(A)));let x=null;for(let m in o.attributes){if(m.slice(0,5)==="morph")continue;const v=o.attributes[m];if(m=b[m]||m.toUpperCase(),!/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(m)&&!m.startsWith("_")&&(m="_"+m),t.attributes.has(this.getUID(v))){d[m]=t.attributes.get(this.getUID(v));continue}x=null;const O=v.array;m==="JOINTS_0"&&!(O instanceof Uint16Array)&&!(O instanceof Uint8Array)?(console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'),x=ze.Utils.toTypedBufferAttribute(v,Uint16Array)):(O instanceof Uint32Array||O instanceof Int32Array)&&!m.startsWith("_")&&(console.warn(`GLTFExporter: Attribute "${m}" converted to type FLOAT.`),x=ze.Utils.toTypedBufferAttribute(v,Float32Array));const T=this.processAccessor(x||v,o);T!==null&&(m.startsWith("_")||this.detectMeshQuantization(m,v),d[m]=T,t.attributes.set(this.getUID(v),T))}if(A!==void 0&&o.setAttribute("normal",A),Object.keys(d).length===0)return null;if(e.morphTargetInfluences!==void 0&&e.morphTargetInfluences.length>0){const m=[],v=[],N={};if(e.morphTargetDictionary!==void 0)for(const O in e.morphTargetDictionary)N[e.morphTargetDictionary[O]]=O;for(let O=0;O<e.morphTargetInfluences.length;++O){const T={};let U=!1;for(const Y in o.morphAttributes){if(Y!=="position"&&Y!=="normal"){U||(console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."),U=!0);continue}const Q=o.morphAttributes[Y][O],J=Y.toUpperCase(),X=o.attributes[Y];if(t.attributes.has(this.getUID(Q,!0))){T[J]=t.attributes.get(this.getUID(Q,!0));continue}const z=Q.clone();if(!o.morphTargetsRelative)for(let P=0,k=Q.count;P<k;P++)for(let V=0;V<Q.itemSize;V++)V===0&&z.setX(P,Q.getX(P)-X.getX(P)),V===1&&z.setY(P,Q.getY(P)-X.getY(P)),V===2&&z.setZ(P,Q.getZ(P)-X.getZ(P)),V===3&&z.setW(P,Q.getW(P)-X.getW(P));T[J]=this.processAccessor(z,o),t.attributes.set(this.getUID(X,!0),T[J])}h.push(T),m.push(e.morphTargetInfluences[O]),e.morphTargetDictionary!==void 0&&v.push(N[O])}u.weights=m,v.length>0&&(u.extras={},u.extras.targetNames=v)}const y=Array.isArray(e.material);if(y&&o.groups.length===0)return null;let g=!1;if(y&&o.index===null){const m=[];for(let v=0,N=o.attributes.position.count;v<N;v++)m[v]=v;o.setIndex(m),g=!0}const C=y?e.material:[e.material],w=y?o.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let m=0,v=w.length;m<v;m++){const N={mode:l,attributes:d};if(this.serializeUserData(o,N),h.length>0&&(N.targets=h),o.index!==null){let T=this.getUID(o.index);(w[m].start!==void 0||w[m].count!==void 0)&&(T+=":"+w[m].start+":"+w[m].count),t.attributes.has(T)?N.indices=t.attributes.get(T):(N.indices=this.processAccessor(o.index,o,w[m].start,w[m].count),t.attributes.set(T,N.indices)),N.indices===null&&delete N.indices}const O=await this.processMaterialAsync(C[w[m].materialIndex]);O!==null&&(N.material=O),f.push(N)}g===!0&&o.setIndex(null),u.primitives=f,s.meshes||(s.meshes=[]),await this._invokeAllAsync(function(m){m.writeMesh&&m.writeMesh(e,u)});const p=s.meshes.push(u)-1;return t.meshes.set(i,p),p}detectMeshQuantization(e,t){if(this.extensionsUsed[Ct])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];bn[n]&&bn[n].includes(s)&&(this.extensionsUsed[Ct]=!0,this.extensionsRequired[Ct]=!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=ze.Utils.mergeMorphTargetTracks(e.clone(),t);const i=e.tracks,o=[],l=[];for(let d=0;d<i.length;++d){const f=i[d],h=c.PropertyBinding.parseTrackName(f.name);let b=c.PropertyBinding.findNode(t,h.nodeName);const A=xn[h.propertyName];if(h.objectName==="bones"&&(b.isSkinnedMesh===!0?b=b.skeleton.getBoneByName(h.objectIndex):b=void 0),!b||!A){console.warn('THREE.GLTFExporter: Could not export animation track "%s".',f.name);continue}const x=1;let y=f.values.length/f.times.length;A===xn.morphTargetInfluences&&(y/=b.morphTargetInfluences.length);let g;f.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline===!0?(g="CUBICSPLINE",y/=3):f.getInterpolation()===c.InterpolateDiscrete?g="STEP":g="LINEAR",l.push({input:this.processAccessor(new c.BufferAttribute(f.times,x)),output:this.processAccessor(new c.BufferAttribute(f.values,y)),interpolation:g}),o.push({sampler:l.length-1,target:{node:n.get(b),path:A}})}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 h=0;h<i.bones.length;++h)l.push(s.get(i.bones[h])),d.copy(i.boneInverses[h]),d.multiply(e.bindMatrix).toArray(u,h*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();xe(l,[0,0,0,1])||(i.rotation=l),xe(u,[0,0,0])||(i.translation=u),xe(d,[1,1,1])||(i.scale=d)}else e.matrixAutoUpdate&&e.updateMatrix(),Mi(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 f=e.children[u];if(f.visible||s.onlyVisible===!1){const h=await this.processNodeAsync(f);h!==null&&l.push(h)}}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();xe(l,[0,0,0,1])||(o.rotation=l),xe(u,[0,0,0])||(o.translation=u),xe(d,[1,1,1])||(o.scale=d),o.extras={pivot:i.toArray()},e.name!==""&&(o.name=String(e.name)),this.serializeUserData(e,o);const f=t.nodes.push(o)-1;n.set(e,f);const h={},b=[-i.x,-i.y,-i.z];if(xe(b,[0,0,0])||(h.translation=b),e.isMesh||e.isLine||e.isPoints){const y=await this.processMeshAsync(e);y!==null&&(h.mesh=y)}else e.isCamera&&(h.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);const x=[t.nodes.push(h)-1];if(e.children.length>0){const y=[];for(let g=0,C=e.children.length;g<C;g++){const w=e.children[g];if(w.visible||s.onlyVisible===!1){const p=await this.processNodeAsync(w);p!==null&&y.push(p)}}y.length>0&&(h.children=y)}return o.children=x,await this._invokeAllAsync(function(y){y.writeNode&&y.writeNode(e,o)}),f}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 Ti{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 Di=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}},Ni=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}},Si=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}},Oi=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}},Ri=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}},Pi=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}},Li=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(gi)&&!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}},Vi=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}},Hi=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}},Bi=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}},ji=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}},Fi=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,f=new c.Quaternion,h=new c.Vector3;for(let A=0;A<n.count;A++)n.getMatrixAt(A,u),u.decompose(d,f,h),d.toArray(i,A*3),f.toArray(o,A*4),h.toArray(l,A*3);const b={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&&(b._COLOR_0=s.processAccessor(n.instanceColor)),t.extensions=t.extensions||{},t.extensions[this.name]={attributes:b},s.extensionsUsed[this.name]=!0,s.extensionsRequired[this.name]=!0}};ze.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,f=u.morphTargetDictionary[l.propertyIndex];if(f===void 0)throw new Error("THREE.GLTFExporter: Morph target name not found: "+l.propertyIndex);let h;if(s[u.uuid]===void 0){h=o.clone();const A=new h.ValueBufferType(d*h.times.length);for(let x=0;x<h.times.length;x++)A[x*d+f]=h.values[x];h.name=(l.nodeName||"")+".morphTargetInfluences",h.values=A,s[u.uuid]=h,t.push(h);continue}const b=o.createInterpolant(new o.ValueBufferType(1));h=s[u.uuid];for(let A=0;A<h.times.length;A++)h.values[A*d+f]=b.evaluate(h.times[A]);for(let A=0;A<o.times.length;A++){const x=this.insertKeyframe(h,o.times[A]);h.values[x*d+f]=o.values[A]}}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 wn(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 Ui(r){const e=new Map,t=new Map,s=r.clone();return zn(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 zn(r,e,t){t(r,e);for(let s=0;s<r.children.length;s++)zn(r.children[s],e.children[s],t)}class Wn extends c.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new qi(t)}),this.register(function(t){return new Yi(t)}),this.register(function(t){return new no(t)}),this.register(function(t){return new so(t)}),this.register(function(t){return new io(t)}),this.register(function(t){return new Zi(t)}),this.register(function(t){return new Qi(t)}),this.register(function(t){return new Ji(t)}),this.register(function(t){return new _i(t)}),this.register(function(t){return new Xi(t)}),this.register(function(t){return new $i(t)}),this.register(function(t){return new Ki(t)}),this.register(function(t){return new to(t)}),this.register(function(t){return new eo(t)}),this.register(function(t){return new zi(t)}),this.register(function(t){return new vn(t,j.EXT_MESHOPT_COMPRESSION)}),this.register(function(t){return new vn(t,j.KHR_MESHOPT_COMPRESSION)}),this.register(function(t){return new oo(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(f){t(f),i.manager.itemEnd(e)},l)}catch(f){l(f)}},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))===Xn){try{o[j.KHR_BINARY_GLTF]=new ro(e)}catch(h){n&&n(h);return}i=JSON.parse(o[j.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 xo(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 f=0;f<this.pluginCallbacks.length;f++){const h=this.pluginCallbacks[f](d);h.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),l[h.name]=h,o[h.name]=!0}if(i.extensionsUsed)for(let f=0;f<i.extensionsUsed.length;++f){const h=i.extensionsUsed[f],b=i.extensionsRequired||[];switch(h){case j.KHR_MATERIALS_UNLIT:o[h]=new Wi;break;case j.KHR_DRACO_MESH_COMPRESSION:o[h]=new ao(i,this.dracoLoader);break;case j.KHR_TEXTURE_TRANSFORM:o[h]=new lo;break;case j.KHR_MESH_QUANTIZATION:o[h]=new co;break;default:b.indexOf(h)>=0&&l[h]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+h+'".')}}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 Gi(){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 j={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 zi{constructor(e){this.parser=e,this.name=j.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 f=new c.Color(16777215);u.color!==void 0&&f.setRGB(u.color[0],u.color[1],u.color[2],c.LinearSRGBColorSpace);const h=u.range!==void 0?u.range:0;switch(u.type){case"directional":d=new c.DirectionalLight(f),d.target.position.set(0,0,-1),d.add(d.target);break;case"point":d=new c.PointLight(f),d.distance=h;break;case"spot":d=new c.SpotLight(f),d.distance=h,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),ge(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 Wi{constructor(){this.name=j.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 Xi{constructor(e){this.parser=e,this.name=j.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 qi{constructor(e){this.parser=e,this.name=j.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 Yi{constructor(e){this.parser=e,this.name=j.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 Ki{constructor(e){this.parser=e,this.name=j.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 Zi{constructor(e){this.parser=e,this.name=j.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 Qi{constructor(e){this.parser=e,this.name=j.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 Ji{constructor(e){this.parser=e,this.name=j.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 _i{constructor(e){this.parser=e,this.name=j.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 $i{constructor(e){this.parser=e,this.name=j.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 eo{constructor(e){this.parser=e,this.name=j.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 to{constructor(e){this.parser=e,this.name=j.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 no{constructor(e){this.parser=e,this.name=j.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 so{constructor(e){this.parser=e,this.name=j.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 io{constructor(e){this.parser=e,this.name=j.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 vn{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,f=n.count,h=n.byteStride,b=new Uint8Array(l,u,d);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(f,h,b,n.mode,n.filter).then(function(A){return A.buffer}):o.ready.then(function(){const A=new ArrayBuffer(f*h);return o.decodeGltfBuffer(new Uint8Array(A),f,h,b,n.mode,n.filter),A})})}else return null}}class oo{constructor(e){this.name=j.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(f=>(u[d]=f,u[d])));return l.length<1?null:(l.push(this.parser.createNodeMesh(e)),Promise.all(l).then(d=>{const f=d.pop(),h=f.isGroup?f.children:[f],b=d[0].count,A=[];for(const x of h){const y=new c.Matrix4,g=new c.Vector3,C=new c.Quaternion,w=new c.Vector3(1,1,1),p=new c.InstancedMesh(x.geometry,x.material,b);for(let m=0;m<b;m++)u.TRANSLATION&&g.fromBufferAttribute(u.TRANSLATION,m),u.ROTATION&&C.fromBufferAttribute(u.ROTATION,m),u.SCALE&&w.fromBufferAttribute(u.SCALE,m),p.setMatrixAt(m,y.compose(g,C,w));for(const m in u)if(m==="_COLOR_0"){const v=u[m];p.instanceColor=new c.InstancedBufferAttribute(v.array,v.itemSize,v.normalized)}else m!=="TRANSLATION"&&m!=="ROTATION"&&m!=="SCALE"&&x.geometry.setAttribute(m,u[m]);c.Object3D.prototype.copy.call(p,x),this.parser.assignFinalMaterial(p),A.push(p)}return f.isGroup?(f.clear(),f.add(...A),f):A[0]}))}}const Xn="glTF",Fe=12,En={JSON:1313821514,BIN:5130562};class ro{constructor(e){this.name=j.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,Fe),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!==Xn)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-Fe,i=new DataView(e,Fe);let o=0;for(;o<n;){const l=i.getUint32(o,!0);o+=4;const u=i.getUint32(o,!0);if(o+=4,u===En.JSON){const d=new Uint8Array(e,Fe+o,l);this.content=s.decode(d)}else if(u===En.BIN){const d=Fe+o;this.body=e.slice(d,d+l)}o+=l}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class ao{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=j.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 f in o){const h=Nt[f]||f.toLowerCase();l[h]=o[f]}for(const f in e.attributes){const h=Nt[f]||f.toLowerCase();if(o[f]!==void 0){const b=s.accessors[e.attributes[f]],A=Ve[b.componentType];d[h]=A.name,u[h]=b.normalized===!0}}return t.getDependency("bufferView",i).then(function(f){return new Promise(function(h,b){n.decodeDracoFile(f,function(A){for(const x in A.attributes){const y=A.attributes[x],g=u[x];g!==void 0&&(y.normalized=g)}h(A)},l,d,c.LinearSRGBColorSpace,b)})})}}class lo{constructor(){this.name=j.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 co{constructor(){this.name=j.KHR_MESH_QUANTIZATION}}class qn 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,f=n-t,h=(s-t)/f,b=h*h,A=b*h,x=e*d,y=x-d,g=-2*A+3*b,C=A-b,w=1-g,p=C-b+h;for(let m=0;m!==l;m++){const v=o[y+m+l],N=o[y+m+u]*f,O=o[x+m+l],T=o[x+m]*f;i[m]=w*v+p*N+g*O+C*T}return i}}const uo=new c.Quaternion;class ho extends qn{interpolate_(e,t,s,n){const i=super.interpolate_(e,t,s,n);return uo.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},Ve={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Tn={9728:c.NearestFilter,9729:c.LinearFilter,9984:c.NearestMipmapNearestFilter,9985:c.LinearMipmapNearestFilter,9986:c.NearestMipmapLinearFilter,9987:c.LinearMipmapLinearFilter},Dn={33071:c.ClampToEdgeWrapping,33648:c.MirroredRepeatWrapping,10497:c.RepeatWrapping},wt={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Nt={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"},fo={CUBICSPLINE:void 0,LINEAR:c.InterpolateLinear,STEP:c.InterpolateDiscrete},vt={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function po(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 ge(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 mo(r,e,t){let s=!1,n=!1,i=!1;for(let d=0,f=e.length;d<f;d++){const h=e[d];if(h.POSITION!==void 0&&(s=!0),h.NORMAL!==void 0&&(n=!0),h.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,f=e.length;d<f;d++){const h=e[d];if(s){const b=h.POSITION!==void 0?t.getDependency("accessor",h.POSITION):r.attributes.position;o.push(b)}if(n){const b=h.NORMAL!==void 0?t.getDependency("accessor",h.NORMAL):r.attributes.normal;l.push(b)}if(i){const b=h.COLOR_0!==void 0?t.getDependency("accessor",h.COLOR_0):r.attributes.color;u.push(b)}}return Promise.all([Promise.all(o),Promise.all(l),Promise.all(u)]).then(function(d){const f=d[0],h=d[1],b=d[2];return s&&(r.morphAttributes.position=f),n&&(r.morphAttributes.normal=h),i&&(r.morphAttributes.color=b),r.morphTargetsRelative=!0,r})}function Ao(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 go(r){let e;const t=r.extensions&&r.extensions[j.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Et(t.attributes):e=r.indices+":"+Et(r.attributes)+":"+r.mode,r.targets!==void 0)for(let s=0,n=r.targets.length;s<n;s++)e+=":"+Et(r.targets[s]);return e}function Et(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 St(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 yo(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 bo=new c.Matrix4;class xo{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Gi,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),ge(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,f]of o.children.entries())i(f,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[j.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=wt[n.type],l=Ve[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=wt[n.type],d=Ve[n.componentType],f=d.BYTES_PER_ELEMENT,h=f*u,b=n.byteOffset||0,A=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,x=n.normalized===!0;let y,g;if(A&&A!==h){const C=Math.floor(b/A),w="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+C+":"+n.count;let p=t.cache.get(w);p||(y=new d(l,C*A,n.count*A/f),p=new c.InterleavedBuffer(y,A/f),t.cache.add(w,p)),g=new c.InterleavedBufferAttribute(p,u,b%A/f,x)}else l===null?y=new d(n.count*u):y=new d(l,b,n.count*u),g=new c.BufferAttribute(y,u,x);if(n.sparse!==void 0){const C=wt.SCALAR,w=Ve[n.sparse.indices.componentType],p=n.sparse.indices.byteOffset||0,m=n.sparse.values.byteOffset||0,v=new w(o[1],p,n.sparse.count*C),N=new d(o[2],m,n.sparse.count*u);l!==null&&(g=new c.BufferAttribute(g.array.slice(),g.itemSize,g.normalized)),g.normalized=!1;for(let O=0,T=v.length;O<T;O++){const U=v[O];if(g.setX(U,N[O*u]),u>=2&&g.setY(U,N[O*u+1]),u>=3&&g.setZ(U,N[O*u+2]),u>=4&&g.setW(U,N[O*u+3]),u>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}g.normalized=x}return g})}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(f){f.flipY=!1,f.name=o.name||l.name||"",f.name===""&&typeof l.uri=="string"&&l.uri.startsWith("data:image/")===!1&&(f.name=l.uri);const b=(i.samplers||{})[o.sampler]||{};return f.magFilter=Tn[b.magFilter]||c.LinearFilter,f.minFilter=Tn[b.minFilter]||c.LinearMipmapLinearFilter,f.wrapS=Dn[b.wrapS]||c.RepeatWrapping,f.wrapT=Dn[b.wrapT]||c.RepeatWrapping,f.generateMipmaps=!f.isCompressedTexture&&f.minFilter!==c.NearestFilter&&f.minFilter!==c.LinearFilter,n.associations.set(f,{textures:e}),f}).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(h=>h.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(h){d=!0;const b=new Blob([h],{type:o.mimeType});return u=l.createObjectURL(b),u});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const f=Promise.resolve(u).then(function(h){return new Promise(function(b,A){let x=b;t.isImageBitmapLoader===!0&&(x=function(y){const g=new c.Texture(y);g.needsUpdate=!0,b(g)}),t.load(c.LoaderUtils.resolveURL(h,i.path),x,void 0,A)})}).then(function(h){return d===!0&&l.revokeObjectURL(u),ge(h,o),h.userData.mimeType=o.mimeType||yo(o.uri),h}).catch(function(h){throw console.error("THREE.GLTFLoader: Couldn't load texture",u),h});return this.sourceCache[e]=f,f}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[j.KHR_TEXTURE_TRANSFORM]){const l=s.extensions!==void 0?s.extensions[j.KHR_TEXTURE_TRANSFORM]:void 0;if(l){const u=i.associations.get(o);o=i.extensions[j.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[j.KHR_MATERIALS_UNLIT]){const h=n[j.KHR_MATERIALS_UNLIT];o=h.getMaterialType(),d.push(h.extendParams(l,i,t))}else{const h=i.pbrMetallicRoughness||{};if(l.color=new c.Color(1,1,1),l.opacity=1,Array.isArray(h.baseColorFactor)){const b=h.baseColorFactor;l.color.setRGB(b[0],b[1],b[2],c.LinearSRGBColorSpace),l.opacity=b[3]}h.baseColorTexture!==void 0&&d.push(t.assignTexture(l,"map",h.baseColorTexture,c.SRGBColorSpace)),l.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,l.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(d.push(t.assignTexture(l,"metalnessMap",h.metallicRoughnessTexture)),d.push(t.assignTexture(l,"roughnessMap",h.metallicRoughnessTexture))),o=this._invokeOne(function(b){return b.getMaterialType&&b.getMaterialType(e)}),d.push(Promise.all(this._invokeAll(function(b){return b.extendMaterialParams&&b.extendMaterialParams(e,l)})))}i.doubleSided===!0&&(l.side=c.DoubleSide);const f=i.alphaMode||vt.OPAQUE;if(f===vt.BLEND?(l.transparent=!0,l.depthWrite=!1):(l.transparent=!1,f===vt.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 h=i.normalTexture.scale;l.normalScale.set(h,h)}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 h=i.emissiveFactor;l.emissive=new c.Color().setRGB(h[0],h[1],h[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 h=new o(l);return i.name&&(h.name=i.name),ge(h,i),t.associations.set(h,{materials:e}),i.extensions&&Ne(n,h,i),h})}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[j.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(l,t).then(function(u){return Nn(u,l,t)})}const o=[];for(let l=0,u=e.length;l<u;l++){const d=e[l],f=go(d),h=n[f];if(h)o.push(h.promise);else{let b;d.extensions&&d.extensions[j.KHR_DRACO_MESH_COMPRESSION]?b=i(d):b=Nn(new c.BufferGeometry,d,t),n[f]={primitive:d,promise:b},o.push(b)}}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 f=o[u].material===void 0?po(this.cache):this.getDependency("material",o[u].material);l.push(f)}return l.push(t.loadGeometries(o)),Promise.all(l).then(function(u){const d=u.slice(0,u.length-1),f=u[u.length-1],h=[];for(let A=0,x=f.length;A<x;A++){const y=f[A],g=o[A];let C;const w=d[A];if(g.mode===ue.TRIANGLES||g.mode===ue.TRIANGLE_STRIP||g.mode===ue.TRIANGLE_FAN||g.mode===void 0)C=i.isSkinnedMesh===!0?new c.SkinnedMesh(y,w):new c.Mesh(y,w),C.isSkinnedMesh===!0&&C.normalizeSkinWeights(),g.mode===ue.TRIANGLE_STRIP?C.geometry=wn(C.geometry,c.TriangleStripDrawMode):g.mode===ue.TRIANGLE_FAN&&(C.geometry=wn(C.geometry,c.TriangleFanDrawMode));else if(g.mode===ue.LINES)C=new c.LineSegments(y,w);else if(g.mode===ue.LINE_STRIP)C=new c.Line(y,w);else if(g.mode===ue.LINE_LOOP)C=new c.LineLoop(y,w);else if(g.mode===ue.POINTS)C=new c.Points(y,w);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+g.mode);Object.keys(C.geometry.morphAttributes).length>0&&Ao(C,i),C.name=t.createUniqueName(i.name||"mesh_"+e),ge(C,i),g.extensions&&Ne(n,C,g),t.assignFinalMaterial(C),h.push(C)}for(let A=0,x=h.length;A<x;A++)t.associations.set(h[A],{meshes:e,primitives:A});if(h.length===1)return i.extensions&&Ne(n,h[0],i),h[0];const b=new c.Group;i.extensions&&Ne(n,b,i),t.associations.set(b,{meshes:e});for(let A=0,x=h.length;A<x;A++)b.add(h[A]);return b})}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)),ge(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,f=o.length;d<f;d++){const h=o[d];if(h){l.push(h);const b=new c.Matrix4;i!==null&&b.fromArray(i.array,d*16),u.push(b)}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=[],f=[];for(let h=0,b=n.channels.length;h<b;h++){const A=n.channels[h],x=n.samplers[A.sampler],y=A.target,g=y.node,C=n.parameters!==void 0?n.parameters[x.input]:x.input,w=n.parameters!==void 0?n.parameters[x.output]:x.output;y.node!==void 0&&(o.push(this.getDependency("node",g)),l.push(this.getDependency("accessor",C)),u.push(this.getDependency("accessor",w)),d.push(x),f.push(y))}return Promise.all([Promise.all(o),Promise.all(l),Promise.all(u),Promise.all(d),Promise.all(f)]).then(function(h){const b=h[0],A=h[1],x=h[2],y=h[3],g=h[4],C=[];for(let p=0,m=b.length;p<m;p++){const v=b[p],N=A[p],O=x[p],T=y[p],U=g[p];if(v===void 0)continue;v.updateMatrix&&v.updateMatrix();const Y=s._createAnimationTracks(v,N,O,T,U);if(Y)for(let Q=0;Q<Y.length;Q++)C.push(Y[Q])}const w=new c.AnimationClip(i,void 0,C);return ge(w,n),w})}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,f=l.length;d<f;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 f=d[0],h=d[1],b=d[2];b!==null&&f.traverse(function(A){A.isSkinnedMesh&&A.bind(b,bo)});for(let A=0,x=h.length;A<x;A++)f.add(h[A]);if(f.userData.pivot!==void 0&&h.length>0){const A=f.userData.pivot,x=h[0];f.pivot=new c.Vector3().fromArray(A),f.position.x-=A[0],f.position.y-=A[1],f.position.z-=A[2],x.position.set(0,0,0),delete f.userData.pivot}return f})}_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 f;if(i.isBone===!0?f=new c.Bone:d.length>1?f=new c.Group:d.length===1?f=d[0]:f=new c.Object3D,f!==d[0])for(let h=0,b=d.length;h<b;h++)f.add(d[h]);if(i.name&&(f.userData.name=i.name,f.name=o),ge(f,i),i.extensions&&Ne(s,f,i),i.matrix!==void 0){const h=new c.Matrix4;h.fromArray(i.matrix),f.applyMatrix4(h)}else i.translation!==void 0&&f.position.fromArray(i.translation),i.rotation!==void 0&&f.quaternion.fromArray(i.rotation),i.scale!==void 0&&f.scale.fromArray(i.scale);if(!n.associations.has(f))n.associations.set(f,{});else if(i.mesh!==void 0&&n.meshCache.refs[i.mesh]>1){const h=n.associations.get(f);n.associations.set(f,{...h})}return n.associations.get(f).nodes=e,f}),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)),ge(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 f=0,h=u.length;f<h;f++){const b=u[f];b.parent!==null?i.add(Ui(b)):i.add(b)}const d=f=>{const h=new Map;for(const[b,A]of n.associations)(b instanceof c.Material||b instanceof c.Texture)&&h.set(b,A);return f.traverse(b=>{const A=n.associations.get(b);A!=null&&h.set(b,A)}),h};return n.associations=d(i),i})}_createAnimationTracks(e,t,s,n,i){const o=[],l=e.name?e.name:e.uuid,u=[];function d(A){A.morphTargetInfluences&&u.push(A.name?A.name:A.uuid)}Me[i.path]===Me.weights?(d(e),e.isGroup&&e.children.forEach(d)):u.push(l);let f;switch(Me[i.path]){case Me.weights:f=c.NumberKeyframeTrack;break;case Me.rotation:f=c.QuaternionKeyframeTrack;break;case Me.translation:case Me.scale:f=c.VectorKeyframeTrack;break;default:switch(s.itemSize){case 1:f=c.NumberKeyframeTrack;break;case 2:case 3:default:f=c.VectorKeyframeTrack;break}break}const h=n.interpolation!==void 0?fo[n.interpolation]:c.InterpolateLinear,b=this._getArrayFromAccessor(s);for(let A=0,x=u.length;A<x;A++){const y=new f(u[A]+"."+Me[i.path],t.array,b,h);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(y),o.push(y)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const s=St(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?ho:qn;return new n(this.times,this.values,this.getValueSize()/3,s)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Io(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 f=St(Ve[l.componentType]);n.min.multiplyScalar(f),n.max.multiplyScalar(f)}}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,f=i.length;d<f;d++){const h=i[d];if(h.POSITION!==void 0){const b=t.json.accessors[h.POSITION],A=b.min,x=b.max;if(A!==void 0&&x!==void 0){if(u.setX(Math.max(Math.abs(A[0]),Math.abs(x[0]))),u.setY(Math.max(Math.abs(A[1]),Math.abs(x[1]))),u.setZ(Math.max(Math.abs(A[2]),Math.abs(x[2]))),b.normalized){const y=St(Ve[b.componentType]);u.multiplyScalar(y)}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 Nn(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=Nt[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.`),ge(r,e),Io(r,e,t),Promise.all(n).then(function(){return e.targets!==void 0?mo(r,e.targets,t):r})}let Ot=null;function Co(r){Ot=r}const pe=a.reactive({scripts:[]});function Yn(){return"s_"+Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4)}function Mo(r){var t;const e={id:Yn(),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 wo(r){const e=pe.scripts.findIndex(t=>t.id===r);e!==-1&&pe.scripts.splice(e,1)}function vo(r){pe.scripts=(r||[]).map(e=>({id:(e==null?void 0:e.id)||Yn(),name:(e==null?void 0:e.name)??"",code:(e==null?void 0:e.code)??""}))}function Eo(){pe.scripts=[]}function To(r){const e=pe.scripts.find(t=>t.id===r);if(e){if(!Ot){console.warn("[脚本] 执行器尚未注册,请先初始化编辑器(initEditor)");return}try{Ot(e)}catch(t){console.error("[脚本] 执行出错:",e.name,t)}}}function Kn(r){var e;return!!r&&((e=r.name)==null?void 0:e.trim())==="初始化"}function Do(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 M={mode:"",transformControlsMode:"translate",scene:null,camera:null,defaultMainCamera:null,renderer:null,orbitControls:null,transformControls:null,container:null,gridHelper:null,selectedObject:null};let at=!1,Re=!1,we=null;const No=16755200;let Rt=[],st=[],Ye=!0,Oe=null,de=null,lt=null,ve=[];const Pe=new Map;let Ke,ct=null,We=null,Xe=null;async function Zn(r,e="edit",t){M.container=r,M.mode=e,Oo(),Po(),ko(),t&&(await ds(t.scene,e,t.dataPanels,t.waters,t.textures,t.ambientLight,t.scripts),t!=null&&t.camera&&(M.defaultMainCamera=t.camera,Bt(!0))),Ho(),Vo(),Ke&&M.orbitControls&&(M.orbitControls.target.fromArray(Ke),M.orbitControls.update()),Ro(),ns(),Jn(),We=s=>Fo(s),Xe=()=>jo(),e==="edit"&&r.addEventListener("click",We),window.addEventListener("resize",Xe),t||Bo(),e==="edit"&&Lo(),er()}function So(){return window.devicePixelRatio}function Oo(){const r=So(),e=new S.WebGLRenderer({antialias:!0,alpha:!0});e.setSize(M.container.clientWidth,M.container.clientHeight),e.setPixelRatio(r),e.toneMapping=S.NeutralToneMapping,e.toneMappingExposure=1,console.log(`[Renderer] css=${M.container.clientWidth}×${M.container.clientHeight}, dpr=${window.devicePixelRatio}, targetRatio=${r}, antialias=true`),M.container.appendChild(e.domElement),M.renderer=e}function Ro(){if(!M.renderer||!M.scene||!M.camera)return;const r=M.renderer.getPixelRatio(),e=M.container.clientWidth*r,t=M.container.clientHeight*r,s=new S.WebGLRenderTarget(e,t,{type:S.HalfFloatType,samples:4});s.texture.name="EffectComposer.rt1";const n=new ni(M.renderer,s);n.addPass(new si(M.scene,M.camera)),n.addPass(new ii),we=n}function Po(){if(M.scene=new S.Scene,M.scene.name="sl_scene",M.renderer){const r=rt(M.renderer);r?(M.scene.environment=r,M.scene.environmentIntensity=1):console.warn("[初始化] 环境贴图生成失败,场景将没有 IBL 间接光照")}}function Lo(){const r=new S.GridHelper(30,30,8956671,3364232);r.name="地板",r.userData.type="initFloor",M.scene.add(r),M.gridHelper=r}function ko(){const r=M.container,e=r.clientWidth/r.clientHeight,t=new S.PerspectiveCamera(45,e,.1,1e3);t.position.set(0,6,15),t.lookAt(0,0,0),M.camera=t}function Bt(r=!1){if(!M.defaultMainCamera)return;const e=M.defaultMainCamera;if(r){M.camera.position.set(e.position[0],e.position[1],e.position[2]),M.camera.rotation.set(e.rotation[0],e.rotation[1],e.rotation[2]),M.camera.updateProjectionMatrix(),Ke=e.target;return}else Ut(""),ht();if(!M.camera||!M.orbitControls)return;const t=M.camera.position.clone(),s=M.orbitControls.target.clone(),n=new S.Vector3(e.position[0],e.position[1],e.position[2]),i=e.target?new S.Vector3(e.target[0],e.target[1],e.target[2]):new S.Vector3(0,0,0);M.orbitControls.enabled=!1,new ne.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(ne.Easing.Quadratic.InOut).onUpdate(o=>{M.camera.position.set(o.x,o.y,o.z),M.orbitControls.target.set(o.tx,o.ty,o.tz),M.orbitControls.update()}).onComplete(()=>{Ke=e.target,M.orbitControls.enabled=!0}).start()}function Vo(){const r=new Ds(M.camera,M.renderer.domElement);r.minDistance=0,r.maxDistance=1/0,r.addEventListener("start",()=>{at=!1}),r.addEventListener("change",()=>{at=!0}),r.addEventListener("end",()=>{at&&(Re=!0,setTimeout(()=>{Re=!1},200))}),M.orbitControls=r}function Ho(){const r=new Us(M.camera,M.renderer.domElement);r.addEventListener("dragging-changed",e=>{M.orbitControls.enabled=!e.value,e.value||(Re=!0,setTimeout(()=>{Re=!1},200))}),r.addEventListener("objectChange",()=>{const e=M.selectedObject;if(de&&e&&de(e),e&&e.type==="DirectionalLight"){const t=e.userData.helper;t&&t.update&&t.update()}}),M.scene.add(r.getHelper()),M.transformControls=r}function Qn(r=M.scene){if(!r||r.children.some(t=>t.type==="AmbientLight"))return null;const e=new S.AmbientLight(tr,nr);return e.name="环境光",r.add(e),e}function Bo(){Qn(M.scene)}function Jn(){var e,t;ct=requestAnimationFrame(Jn),ne.update(),(e=M.orbitControls)==null||e.update(),M.mode==="run"&&we&&M.scene&&M.camera?we.render():(t=M.renderer)==null||t.render(M.scene,M.camera),M.scene&&M.camera&&jn(M.scene,M.camera),Ye&&M.scene&&(st=[],M.scene.traverse(s=>{s.userData.isWater&&s.type==="Mesh"&&st.push(s)}),Ye=!1);for(let s=0;s<st.length;s++){const n=st[s],i=n.material;if(i.uniforms&&i.uniforms.time){const o=n.userData.waterTimeScale??1;i.uniforms.time.value+=1/60*o,M.camera&&i.uniforms.eye&&i.uniforms.eye.value.copy(M.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 jo(){if(!M.container||!M.camera||!M.renderer)return;const r=M.container.clientWidth,e=M.container.clientHeight;r===0||e===0||(M.camera.aspect=r/e,M.camera.updateProjectionMatrix(),M.renderer.setSize(r,e),we&&we.setSize(r,e),Fn(r,e))}function Qe(r){M.selectedObject!==r&&(M.selectedObject&&M.transformControls.detach(),M.selectedObject=r,M.transformControls.attach(r),M.transformControls.setMode(M.transformControlsMode),M.transformControls.showX=!0,M.transformControls.showY=!0,M.transformControls.showZ=!0,$n(r),Oe==null||Oe(r))}let ae=null;function _n(r){ae=r}function ut(r){ae==null||ae(r)}function jt(r){M.transformControlsMode=r,M.transformControls&&M.transformControls.setMode(M.transformControlsMode)}function $n(r){if(M.mode!=="edit"){ht();return}ht(),r.traverse(e=>{if(e.isMesh){const t=e,s=new S.EdgesGeometry(t.geometry),n=new S.LineBasicMaterial({color:No,depthTest:!0}),i=new S.LineSegments(s,n);e.add(i),Rt.push(i)}})}function ht(){for(const r of Rt)r.parent&&r.parent.remove(r),r.geometry.dispose(),r.material.dispose();Rt=[]}function Ft(){M.selectedObject&&(ht(),M.transformControls.detach(),M.selectedObject=null,Oe==null||Oe(null))}function Ut(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)}),$n(e),M.selectedObject=e,setTimeout(()=>{Gt(e)},500))}function Fo(r){if(Re){Re=!1;return}const e=Uo(r);e?Qe(e):Ft()}function Uo(r){const e=M.renderer.domElement.getBoundingClientRect(),t=new S.Vector2((r.clientX-e.left)/e.width*2-1,-((r.clientY-e.top)/e.height)*2+1),s=new S.Raycaster;s.setFromCamera(t,M.camera);const n=[],i=l=>{l.isTransformControlsRoot||((l.userData.isMovable||l.userData.type==="lightHelper")&&n.push(l),l.children.forEach(i))};i(M.scene);const o=s.intersectObjects(n);if(o.length===0)return null;for(const l of o){const u=Sn(l.object);if(u!==M.selectedObject)return u}return Sn(o[0].object)}function Sn(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 Gt(r,e=500){if(!M.camera||!M.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 S.Vector3;r.getWorldPosition(s);const i=new S.Box3().setFromObject(r).getSize(new S.Vector3),o=Math.max(i.x,i.y,i.z)*.5,l=Math.max(o*3.5,5),u=new S.Vector3().copy(M.camera.position).sub(s).normalize();u.lengthSq()<.001&&u.set(0,0,1);const d=s.clone().add(u.multiplyScalar(l)),f=M.camera.position.clone(),h=M.orbitControls.target.clone();try{new ne.Tween({x:f.x,y:f.y,z:f.z,tx:h.x,ty:h.y,tz:h.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(ne.Easing.Quadratic.InOut).onUpdate(b=>{M.camera.position.set(b.x,b.y,b.z),M.orbitControls.target.set(b.tx,b.ty,b.tz),M.orbitControls.update()}).start()}catch(b){console.error("[focusOnObject] TWEEN 动画创建失败,请检查 @tweenjs/tween.js 是否已正确安装且版本兼容(^23.1.3):",b)}}function Go(r){r.userData.id&&Pe.set(String(r.userData.id),r)}function zo(r){r.userData.id&&Pe.delete(String(r.userData.id))}function es(r,e){const t=e||r.userData.id;if(t)Pe.set(String(t),r);else{const s=S.MathUtils.generateUUID();r.userData.id=s,Pe.set(s,r)}}function Wo(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 ts(r){var s,n;const e=(s=M.scene)==null?void 0:s.environment;if(!e)return;const t=((n=M.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 ye(r,e=!1){M.scene.add(r),ts(r),Ye=!0,r.userData.isMovable&&(Xo(r),mt()),e&&M.mode==="edit"&&Qe(r)}function zt(r){M.selectedObject===r&&Ft(),Ye=!0,Wo(r),zo(r),r.userData.helper&&M.scene.remove(r.userData.helper),r.parent?r.parent.remove(r):M.scene.remove(r),qo(r),mt()}function Wt(r){const e=M.scene.getObjectByProperty("uuid",r);e&&zt(e)}function Xo(r){r.userData.isMovable&&r.parent===M.scene&&(ve.includes(r)||ve.push(r))}function qo(r){const e=ve.indexOf(r);e!==-1&&ve.splice(e,1)}function ns(){const r=[];M.scene.children.forEach(e=>{e.userData.isMovable&&r.push(e)}),ve=r,mt()}function mt(){lt==null||lt([...ve])}function ss(r){Oe=r}function is(r){de=r}function os(r){lt=r}function Xt(){return ve}function ft(){return M.selectedObject}function rs(r,e,t){if(!M.scene)return;const s=Pe.get(r);if(s){const n=He(s);n&&n.updateItemByCode(e,t)}}function Pt(){return M.scene}function pt(){return M.camera}function Lt(){return M.renderer}const as={linear:ne.Easing.Linear.None,"quad.in":ne.Easing.Quadratic.In,"quad.out":ne.Easing.Quadratic.Out,"quad.inout":ne.Easing.Quadratic.InOut,"cubic.inout":ne.Easing.Cubic.InOut,"sine.inout":ne.Easing.Sinusoidal.InOut,"back.out":ne.Easing.Back.Out,"elastic.out":ne.Easing.Elastic.Out,"bounce.out":ne.Easing.Bounce.Out},kt=new WeakMap;function ls(r){let e=kt.get(r);return e||(e={position:new Set,rotation:new Set,scale:new Set,opacity:new Set},kt.set(r,e)),e}function Yo(r,e,t,s){const n=ls(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 qt(r,e=[]){if(!r)return;const t=kt.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 Ko(r){return r*Math.PI/180}function At(r,e={}){if(!r)return console.warn("[脚本动画] 目标对象为空,无法执行动画"),null;const t=e.duration??1e3,s=as[e.easing??"quad.inout"]??ne.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),qt(r,n);const o=new ne.Tween(r).to(i,t).easing(s).onUpdate(()=>{r===M.selectedObject&&(de==null||de(r))}).start();return Yo(r,o,n,()=>{var l;(l=e.onComplete)==null||l.call(e),r===M.selectedObject&&(de==null||de(r))}),o}function Zo(r,e,t=1e3,s){return At(r,{position:e,duration:t,easing:s})}function Qo(r,e,t=1e3,s){return At(r,{rotation:e,duration:t,easing:s})}function Jo(r,e,t=1e3,s){return At(r,{scale:e,duration:t,easing:s})}function _o(r,e,t=1e3,s,n){if(!r)return console.warn("[脚本动画] 目标对象为空,无法执行透明度动画"),null;const i=new Set;if(r.traverse(A=>{const x=A.material;if(!x)return;(Array.isArray(x)?x:[x]).forEach(g=>g&&i.add(g))}),i.size===0)return console.warn("[脚本动画] 目标及其子节点没有材质,无法执行透明度动画:",r.name),null;const o=t??1e3,l=as[s??"quad.inout"]??ne.Easing.Quadratic.InOut,u=Math.min(1,Math.max(0,e)),d=u<=.01;d||(r.visible=!0),qt(r,["opacity"]);const f=[...i];f.forEach(A=>{A.transparent=!0,A.needsUpdate=!0}),M.renderer&&M.scene&&M.camera&&M.renderer.render(M.scene,M.camera);const h=ls(r),b=f.map(A=>{const x=new ne.Tween(A).to({opacity:u},o).easing(l).start();return h.opacity.add(x),x});return b.forEach((A,x)=>{x===0?A.onComplete(()=>{h.opacity.delete(A),d&&(r.visible=!1),n==null||n(),r===M.selectedObject&&(de==null||de(r))}):A.onComplete(()=>h.opacity.delete(A)),A.onStop(()=>h.opacity.delete(A))}),b[0]??null}function $o(){return{THREE:S,scene:Pt(),camera:pt(),renderer:Lt(),selectedObject:ft(),getScene:Pt,getCamera:pt,getRenderer:Lt,getSelectedObject:ft,getSceneObjects:Xt,addModel:ye,removeModel:zt,removeModelById:Wt,selectObject:Qe,updateDataPanelValue:rs,setTransformMode:jt,focusOnObject:Gt,animateTo:At,moveTo:Zo,rotateTo:Qo,scaleTo:Jo,fadeTo:_o,stopAnimations:qt,degToRad:Ko,console,window,document,setTimeout,setInterval,requestAnimationFrame}}function cs(r){var l;const e=(l=r==null?void 0:r.code)==null?void 0:l.trim();if(!e)return;const t=$o(),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 S.Vector3;e.getWorldPosition(t);const i=new S.Box3().setFromObject(e).max.y-t.y+this.options.offsetY;this.css2dObject||(this.css2dObject=new oi(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 S.Vector3;this.attachedObject.getWorldPosition(t);const n=new S.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(ke,"_breathInjected",!1);let qe=ke;const dt=new WeakMap;function Hn(r,e){const t=a.toRaw(r);dt.set(t,e),t.userData._hasDataPanel=!0}function He(r){return dt.get(a.toRaw(r))||null}function Ht(r){const e=a.toRaw(r),t=dt.get(e);t&&(t.dispose(),dt.delete(e)),e.userData._hasDataPanel=void 0}let $=null;function Bn(r){return $?($.domElement.parentNode!==r&&r.appendChild($.domElement),$):($=new ri,$.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 mi(){return $}function jn(r,e){$&&$.render(r,e)}function Fn(r,e){$&&$.setSize(r,e)}function Un(){$&&($.domElement.parentNode&&$.domElement.parentNode.removeChild($.domElement),$=null)}function Ai(){const r=new S.Scene;r.position.y=-3.5;const e=new S.BoxGeometry;e.deleteAttribute("uv");const t=new S.MeshStandardMaterial({side:S.BackSide}),s=new S.PointLight(16777215,900,28,2);s.position.set(.418,16.199,.3),r.add(s);const n=new S.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 S.MeshStandardMaterial,o=new S.InstancedMesh(e,i,6),l=new S.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(y){return new S.MeshLambertMaterial({color:0,emissive:16777215,emissiveIntensity:y})}const d=new S.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 f=new S.Mesh(e,u(50));f.position.set(-16.109,18.021,-8.207),f.scale.set(.1,2.425,2.751),r.add(f);const h=new S.Mesh(e,u(17));h.position.set(14.904,12.198,-1.832),h.scale.set(.15,4.265,6.331),r.add(h);const b=new S.Mesh(e,u(43));b.position.set(-.462,8.89,14.52),b.scale.set(4.38,5.441,.088),r.add(b);const A=new S.Mesh(e,u(20));A.position.set(3.235,11.486,-12.541),A.scale.set(2.5,2,.1),r.add(A);const x=new S.Mesh(e,u(100));return x.position.set(0,20,0),x.scale.set(1,.1,1),r.add(x),r}function rt(r){try{const e=new S.PMREMGenerator(r),t=Ai(),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 bn={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 ze{constructor(){this.textureUtils=null,this.pluginCallbacks=[],this.register(function(e){return new Ti(e)}),this.register(function(e){return new Di(e)}),this.register(function(e){return new Ri(e)}),this.register(function(e){return new Pi(e)}),this.register(function(e){return new Li(e)}),this.register(function(e){return new ki(e)}),this.register(function(e){return new Ni(e)}),this.register(function(e){return new Si(e)}),this.register(function(e){return new Oi(e)}),this.register(function(e){return new Vi(e)}),this.register(function(e){return new Hi(e)}),this.register(function(e){return new Bi(e)}),this.register(function(e){return new ji(e)}),this.register(function(e){return new Fi(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 Ei,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 F={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},Ct="KHR_mesh_quantization",le={};le[c.NearestFilter]=F.NEAREST;le[c.NearestMipmapNearestFilter]=F.NEAREST_MIPMAP_NEAREST;le[c.NearestMipmapLinearFilter]=F.NEAREST_MIPMAP_LINEAR;le[c.LinearFilter]=F.LINEAR;le[c.LinearMipmapNearestFilter]=F.LINEAR_MIPMAP_NEAREST;le[c.LinearMipmapLinearFilter]=F.LINEAR_MIPMAP_LINEAR;le[c.ClampToEdgeWrapping]=F.CLAMP_TO_EDGE;le[c.RepeatWrapping]=F.REPEAT;le[c.MirroredRepeatWrapping]=F.MIRRORED_REPEAT;const xn={scale:"scale",position:"translation",quaternion:"rotation",morphTargetInfluences:"weights"},gi=new c.Color,In=12,yi=1179937895,bi=2,Cn=8,xi=1313821514,Ii=5130562;function xe(r,e){return r.length===e.length&&r.every(function(t,s){return t===e[s]})}function Ci(r){return new TextEncoder().encode(r).buffer}function Mi(r){return xe(r.elements,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function wi(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 Gn(r){return Math.ceil(r/4)*4}function Mt(r,e=0){const t=Gn(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 Mn(){return typeof document>"u"&&typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):document.createElement("canvas")}function vi(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 Ei{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"}),f=Object.keys(l),h=Object.keys(u);if(f.length>0&&(o.extensionsUsed=f),h.length>0&&(o.extensionsRequired=h),o.buffers&&o.buffers.length>0&&(o.buffers[0].byteLength=d.size),s.binary===!0){const b=new FileReader;b.readAsArrayBuffer(d),b.onloadend=function(){const A=Mt(b.result),x=new DataView(new ArrayBuffer(Cn));x.setUint32(0,A.byteLength,!0),x.setUint32(4,Ii,!0);const y=Mt(Ci(JSON.stringify(o)),32),g=new DataView(new ArrayBuffer(Cn));g.setUint32(0,y.byteLength,!0),g.setUint32(4,xi,!0);const C=new ArrayBuffer(In),w=new DataView(C);w.setUint32(0,yi,!0),w.setUint32(4,bi,!0);const p=In+g.byteLength+y.byteLength+x.byteLength+A.byteLength;w.setUint32(8,p,!0);const m=new Blob([C,g,y,x,A],{type:"application/octet-stream"}),v=new FileReader;v.readAsArrayBuffer(m),v.onloadend=function(){t(v.result)}}}else if(o.buffers&&o.buffers.length>0){const b=new FileReader;b.readAsDataURL(d),b.onloadend=function(){const A=b.result;o.buffers[0].uri=A,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(A){return A.colorSpace===c.SRGBColorSpace?function(y){return y<.04045?y*.0773993808:Math.pow(y*.9478672986+.0521327014,2.4)}:function(y){return y}}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=Mn();u.width=o,u.height=l;const d=u.getContext("2d",{willReadFrequently:!0});d.fillStyle="#00ffff",d.fillRect(0,0,o,l);const f=d.getImageData(0,0,o,l);if(n){d.drawImage(n,0,0,o,l);const A=s(e),x=d.getImageData(0,0,o,l).data;for(let y=2;y<x.length;y+=4)f.data[y]=A(x[y]/256)*256}if(i){d.drawImage(i,0,0,o,l);const A=s(t),x=d.getImageData(0,0,o,l).data;for(let y=1;y<x.length;y+=4)f.data[y]=A(x[y]/256)*256}d.putImageData(f,0,0);const b=(e||t).clone();return b.source=new c.Source(u),b.colorSpace=c.NoColorSpace,b.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."),b}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 F.BYTE:case F.UNSIGNED_BYTE:l=1;break;case F.SHORT:case F.UNSIGNED_SHORT:l=2;break;default:l=4}let u=e.itemSize*l;i===F.ARRAY_BUFFER&&(u=Math.ceil(u/4)*4);const d=Gn(n*u),f=new DataView(new ArrayBuffer(d));let h=0;for(let x=s;x<s+n;x++){for(let y=0;y<e.itemSize;y++){let g;e.itemSize>4?g=e.array[x*e.itemSize+y]:(y===0?g=e.getX(x):y===1?g=e.getY(x):y===2?g=e.getZ(x):y===3&&(g=e.getW(x)),e.normalized===!0&&(g=c.MathUtils.normalize(g,e.array))),t===F.FLOAT?f.setFloat32(h,g,!0):t===F.INT?f.setInt32(h,g,!0):t===F.UNSIGNED_INT?f.setUint32(h,g,!0):t===F.SHORT?f.setInt16(h,g,!0):t===F.UNSIGNED_SHORT?f.setUint16(h,g,!0):t===F.BYTE?f.setInt8(h,g):t===F.UNSIGNED_BYTE&&f.setUint8(h,g),h+=l}h%u!==0&&(h+=u-h%u)}const b={buffer:this.processBuffer(f.buffer),byteOffset:this.byteOffset,byteLength:d};return i!==void 0&&(b.target=i),i===F.ARRAY_BUFFER&&(b.byteStride=u),this.byteOffset+=d,o.bufferViews.push(b),{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=Mt(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=F.FLOAT;else if(e.array.constructor===Int32Array)l=F.INT;else if(e.array.constructor===Uint32Array)l=F.UNSIGNED_INT;else if(e.array.constructor===Int16Array)l=F.SHORT;else if(e.array.constructor===Uint16Array)l=F.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)l=F.BYTE;else if(e.array.constructor===Uint8Array)l=F.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=wi(e,s,n);let d;t!==void 0&&(d=e===t.index?F.ELEMENT_ARRAY_BUFFER:F.ARRAY_BUFFER);const f=this.processBufferView(e,l,s,n,d),h={bufferView:f.id,byteOffset:f.byteOffset,componentType:l,count:n,max:u.max,min:u.min,type:o[e.itemSize]};return e.normalized===!0&&(h.normalized=!0),i.accessors||(i.accessors=[]),i.accessors.push(h)-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 f=o.images.get(e),h=n+":flipY/"+s.toString();if(f[h]!==void 0)return f[h];l.images||(l.images=[]);const b={mimeType:n},A=Mn();A.width=Math.min(e.width,u.maxTextureSize),A.height=Math.min(e.height,u.maxTextureSize);const x=A.getContext("2d",{willReadFrequently:!0});if(s===!0&&(x.translate(0,A.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 g=new Uint8ClampedArray(e.height*e.width*4);for(let C=0;C<g.length;C+=4)g[C+0]=e.data[C+0],g[C+1]=e.data[C+1],g[C+2]=e.data[C+2],g[C+3]=e.data[C+3];x.putImageData(new ImageData(g,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,A.width,A.height);else throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");u.binary===!0?d.push(vi(A,n).then(g=>i.processBufferViewImage(g)).then(g=>{b.bufferView=g})):b.uri=c.ImageUtils.getDataURL(A,n);const y=l.images.push(b)-1;return f[h]=y,y}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(f){f.writeTexture&&await f.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(xe(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 m=0,v=e.material.length;m<v;m++)n.push(e.material[m].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=F.LINES:e.isLineLoop?l=F.LINE_LOOP:e.isLine?l=F.LINE_STRIP:e.isPoints?l=F.POINTS:l=e.material.wireframe?F.LINES:F.TRIANGLES;const u={},d={},f=[],h=[],b={uv:"TEXCOORD_0",uv1:"TEXCOORD_1",uv2:"TEXCOORD_2",uv3:"TEXCOORD_3",color:"COLOR_0",skinWeight:"WEIGHTS_0",skinIndex:"JOINTS_0"},A=o.getAttribute("normal");A!==void 0&&!this.isNormalizedNormalAttribute(A)&&(console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one."),o.setAttribute("normal",this.createNormalizedNormalAttribute(A)));let x=null;for(let m in o.attributes){if(m.slice(0,5)==="morph")continue;const v=o.attributes[m];if(m=b[m]||m.toUpperCase(),!/^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/.test(m)&&!m.startsWith("_")&&(m="_"+m),t.attributes.has(this.getUID(v))){d[m]=t.attributes.get(this.getUID(v));continue}x=null;const O=v.array;m==="JOINTS_0"&&!(O instanceof Uint16Array)&&!(O instanceof Uint8Array)?(console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.'),x=ze.Utils.toTypedBufferAttribute(v,Uint16Array)):(O instanceof Uint32Array||O instanceof Int32Array)&&!m.startsWith("_")&&(console.warn(`GLTFExporter: Attribute "${m}" converted to type FLOAT.`),x=ze.Utils.toTypedBufferAttribute(v,Float32Array));const T=this.processAccessor(x||v,o);T!==null&&(m.startsWith("_")||this.detectMeshQuantization(m,v),d[m]=T,t.attributes.set(this.getUID(v),T))}if(A!==void 0&&o.setAttribute("normal",A),Object.keys(d).length===0)return null;if(e.morphTargetInfluences!==void 0&&e.morphTargetInfluences.length>0){const m=[],v=[],N={};if(e.morphTargetDictionary!==void 0)for(const O in e.morphTargetDictionary)N[e.morphTargetDictionary[O]]=O;for(let O=0;O<e.morphTargetInfluences.length;++O){const T={};let U=!1;for(const Y in o.morphAttributes){if(Y!=="position"&&Y!=="normal"){U||(console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported."),U=!0);continue}const Q=o.morphAttributes[Y][O],J=Y.toUpperCase(),X=o.attributes[Y];if(t.attributes.has(this.getUID(Q,!0))){T[J]=t.attributes.get(this.getUID(Q,!0));continue}const z=Q.clone();if(!o.morphTargetsRelative)for(let P=0,k=Q.count;P<k;P++)for(let V=0;V<Q.itemSize;V++)V===0&&z.setX(P,Q.getX(P)-X.getX(P)),V===1&&z.setY(P,Q.getY(P)-X.getY(P)),V===2&&z.setZ(P,Q.getZ(P)-X.getZ(P)),V===3&&z.setW(P,Q.getW(P)-X.getW(P));T[J]=this.processAccessor(z,o),t.attributes.set(this.getUID(X,!0),T[J])}h.push(T),m.push(e.morphTargetInfluences[O]),e.morphTargetDictionary!==void 0&&v.push(N[O])}u.weights=m,v.length>0&&(u.extras={},u.extras.targetNames=v)}const y=Array.isArray(e.material);if(y&&o.groups.length===0)return null;let g=!1;if(y&&o.index===null){const m=[];for(let v=0,N=o.attributes.position.count;v<N;v++)m[v]=v;o.setIndex(m),g=!0}const C=y?e.material:[e.material],w=y?o.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let m=0,v=w.length;m<v;m++){const N={mode:l,attributes:d};if(this.serializeUserData(o,N),h.length>0&&(N.targets=h),o.index!==null){let T=this.getUID(o.index);(w[m].start!==void 0||w[m].count!==void 0)&&(T+=":"+w[m].start+":"+w[m].count),t.attributes.has(T)?N.indices=t.attributes.get(T):(N.indices=this.processAccessor(o.index,o,w[m].start,w[m].count),t.attributes.set(T,N.indices)),N.indices===null&&delete N.indices}const O=await this.processMaterialAsync(C[w[m].materialIndex]);O!==null&&(N.material=O),f.push(N)}g===!0&&o.setIndex(null),u.primitives=f,s.meshes||(s.meshes=[]),await this._invokeAllAsync(function(m){m.writeMesh&&m.writeMesh(e,u)});const p=s.meshes.push(u)-1;return t.meshes.set(i,p),p}detectMeshQuantization(e,t){if(this.extensionsUsed[Ct])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];bn[n]&&bn[n].includes(s)&&(this.extensionsUsed[Ct]=!0,this.extensionsRequired[Ct]=!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=ze.Utils.mergeMorphTargetTracks(e.clone(),t);const i=e.tracks,o=[],l=[];for(let d=0;d<i.length;++d){const f=i[d],h=c.PropertyBinding.parseTrackName(f.name);let b=c.PropertyBinding.findNode(t,h.nodeName);const A=xn[h.propertyName];if(h.objectName==="bones"&&(b.isSkinnedMesh===!0?b=b.skeleton.getBoneByName(h.objectIndex):b=void 0),!b||!A){console.warn('THREE.GLTFExporter: Could not export animation track "%s".',f.name);continue}const x=1;let y=f.values.length/f.times.length;A===xn.morphTargetInfluences&&(y/=b.morphTargetInfluences.length);let g;f.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline===!0?(g="CUBICSPLINE",y/=3):f.getInterpolation()===c.InterpolateDiscrete?g="STEP":g="LINEAR",l.push({input:this.processAccessor(new c.BufferAttribute(f.times,x)),output:this.processAccessor(new c.BufferAttribute(f.values,y)),interpolation:g}),o.push({sampler:l.length-1,target:{node:n.get(b),path:A}})}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 h=0;h<i.bones.length;++h)l.push(s.get(i.bones[h])),d.copy(i.boneInverses[h]),d.multiply(e.bindMatrix).toArray(u,h*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();xe(l,[0,0,0,1])||(i.rotation=l),xe(u,[0,0,0])||(i.translation=u),xe(d,[1,1,1])||(i.scale=d)}else e.matrixAutoUpdate&&e.updateMatrix(),Mi(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 f=e.children[u];if(f.visible||s.onlyVisible===!1){const h=await this.processNodeAsync(f);h!==null&&l.push(h)}}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();xe(l,[0,0,0,1])||(o.rotation=l),xe(u,[0,0,0])||(o.translation=u),xe(d,[1,1,1])||(o.scale=d),o.extras={pivot:i.toArray()},e.name!==""&&(o.name=String(e.name)),this.serializeUserData(e,o);const f=t.nodes.push(o)-1;n.set(e,f);const h={},b=[-i.x,-i.y,-i.z];if(xe(b,[0,0,0])||(h.translation=b),e.isMesh||e.isLine||e.isPoints){const y=await this.processMeshAsync(e);y!==null&&(h.mesh=y)}else e.isCamera&&(h.camera=this.processCamera(e));e.isSkinnedMesh&&this.skins.push(e);const x=[t.nodes.push(h)-1];if(e.children.length>0){const y=[];for(let g=0,C=e.children.length;g<C;g++){const w=e.children[g];if(w.visible||s.onlyVisible===!1){const p=await this.processNodeAsync(w);p!==null&&y.push(p)}}y.length>0&&(h.children=y)}return o.children=x,await this._invokeAllAsync(function(y){y.writeNode&&y.writeNode(e,o)}),f}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 Ti{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 Di=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}},Ni=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}},Si=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}},Oi=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}},Ri=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}},Pi=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}},Li=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(gi)&&!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}},Vi=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}},Hi=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}},Bi=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}},ji=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}},Fi=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,f=new c.Quaternion,h=new c.Vector3;for(let A=0;A<n.count;A++)n.getMatrixAt(A,u),u.decompose(d,f,h),d.toArray(i,A*3),f.toArray(o,A*4),h.toArray(l,A*3);const b={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&&(b._COLOR_0=s.processAccessor(n.instanceColor)),t.extensions=t.extensions||{},t.extensions[this.name]={attributes:b},s.extensionsUsed[this.name]=!0,s.extensionsRequired[this.name]=!0}};ze.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,f=u.morphTargetDictionary[l.propertyIndex];if(f===void 0)throw new Error("THREE.GLTFExporter: Morph target name not found: "+l.propertyIndex);let h;if(s[u.uuid]===void 0){h=o.clone();const A=new h.ValueBufferType(d*h.times.length);for(let x=0;x<h.times.length;x++)A[x*d+f]=h.values[x];h.name=(l.nodeName||"")+".morphTargetInfluences",h.values=A,s[u.uuid]=h,t.push(h);continue}const b=o.createInterpolant(new o.ValueBufferType(1));h=s[u.uuid];for(let A=0;A<h.times.length;A++)h.values[A*d+f]=b.evaluate(h.times[A]);for(let A=0;A<o.times.length;A++){const x=this.insertKeyframe(h,o.times[A]);h.values[x*d+f]=o.values[A]}}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 wn(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 Ui(r){const e=new Map,t=new Map,s=r.clone();return zn(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 zn(r,e,t){t(r,e);for(let s=0;s<r.children.length;s++)zn(r.children[s],e.children[s],t)}class Wn extends c.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new qi(t)}),this.register(function(t){return new Yi(t)}),this.register(function(t){return new no(t)}),this.register(function(t){return new so(t)}),this.register(function(t){return new io(t)}),this.register(function(t){return new Zi(t)}),this.register(function(t){return new Qi(t)}),this.register(function(t){return new Ji(t)}),this.register(function(t){return new _i(t)}),this.register(function(t){return new Xi(t)}),this.register(function(t){return new $i(t)}),this.register(function(t){return new Ki(t)}),this.register(function(t){return new to(t)}),this.register(function(t){return new eo(t)}),this.register(function(t){return new zi(t)}),this.register(function(t){return new vn(t,j.EXT_MESHOPT_COMPRESSION)}),this.register(function(t){return new vn(t,j.KHR_MESHOPT_COMPRESSION)}),this.register(function(t){return new oo(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(f){t(f),i.manager.itemEnd(e)},l)}catch(f){l(f)}},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))===Xn){try{o[j.KHR_BINARY_GLTF]=new ro(e)}catch(h){n&&n(h);return}i=JSON.parse(o[j.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 xo(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 f=0;f<this.pluginCallbacks.length;f++){const h=this.pluginCallbacks[f](d);h.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),l[h.name]=h,o[h.name]=!0}if(i.extensionsUsed)for(let f=0;f<i.extensionsUsed.length;++f){const h=i.extensionsUsed[f],b=i.extensionsRequired||[];switch(h){case j.KHR_MATERIALS_UNLIT:o[h]=new Wi;break;case j.KHR_DRACO_MESH_COMPRESSION:o[h]=new ao(i,this.dracoLoader);break;case j.KHR_TEXTURE_TRANSFORM:o[h]=new lo;break;case j.KHR_MESH_QUANTIZATION:o[h]=new co;break;default:b.indexOf(h)>=0&&l[h]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+h+'".')}}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 Gi(){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 j={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 zi{constructor(e){this.parser=e,this.name=j.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 f=new c.Color(16777215);u.color!==void 0&&f.setRGB(u.color[0],u.color[1],u.color[2],c.LinearSRGBColorSpace);const h=u.range!==void 0?u.range:0;switch(u.type){case"directional":d=new c.DirectionalLight(f),d.target.position.set(0,0,-1),d.add(d.target);break;case"point":d=new c.PointLight(f),d.distance=h;break;case"spot":d=new c.SpotLight(f),d.distance=h,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),ge(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 Wi{constructor(){this.name=j.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 Xi{constructor(e){this.parser=e,this.name=j.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 qi{constructor(e){this.parser=e,this.name=j.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 Yi{constructor(e){this.parser=e,this.name=j.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 Ki{constructor(e){this.parser=e,this.name=j.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 Zi{constructor(e){this.parser=e,this.name=j.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 Qi{constructor(e){this.parser=e,this.name=j.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 Ji{constructor(e){this.parser=e,this.name=j.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 _i{constructor(e){this.parser=e,this.name=j.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 $i{constructor(e){this.parser=e,this.name=j.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 eo{constructor(e){this.parser=e,this.name=j.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 to{constructor(e){this.parser=e,this.name=j.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 no{constructor(e){this.parser=e,this.name=j.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 so{constructor(e){this.parser=e,this.name=j.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 io{constructor(e){this.parser=e,this.name=j.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 vn{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,f=n.count,h=n.byteStride,b=new Uint8Array(l,u,d);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(f,h,b,n.mode,n.filter).then(function(A){return A.buffer}):o.ready.then(function(){const A=new ArrayBuffer(f*h);return o.decodeGltfBuffer(new Uint8Array(A),f,h,b,n.mode,n.filter),A})})}else return null}}class oo{constructor(e){this.name=j.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(f=>(u[d]=f,u[d])));return l.length<1?null:(l.push(this.parser.createNodeMesh(e)),Promise.all(l).then(d=>{const f=d.pop(),h=f.isGroup?f.children:[f],b=d[0].count,A=[];for(const x of h){const y=new c.Matrix4,g=new c.Vector3,C=new c.Quaternion,w=new c.Vector3(1,1,1),p=new c.InstancedMesh(x.geometry,x.material,b);for(let m=0;m<b;m++)u.TRANSLATION&&g.fromBufferAttribute(u.TRANSLATION,m),u.ROTATION&&C.fromBufferAttribute(u.ROTATION,m),u.SCALE&&w.fromBufferAttribute(u.SCALE,m),p.setMatrixAt(m,y.compose(g,C,w));for(const m in u)if(m==="_COLOR_0"){const v=u[m];p.instanceColor=new c.InstancedBufferAttribute(v.array,v.itemSize,v.normalized)}else m!=="TRANSLATION"&&m!=="ROTATION"&&m!=="SCALE"&&x.geometry.setAttribute(m,u[m]);c.Object3D.prototype.copy.call(p,x),this.parser.assignFinalMaterial(p),A.push(p)}return f.isGroup?(f.clear(),f.add(...A),f):A[0]}))}}const Xn="glTF",Fe=12,En={JSON:1313821514,BIN:5130562};class ro{constructor(e){this.name=j.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,Fe),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!==Xn)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-Fe,i=new DataView(e,Fe);let o=0;for(;o<n;){const l=i.getUint32(o,!0);o+=4;const u=i.getUint32(o,!0);if(o+=4,u===En.JSON){const d=new Uint8Array(e,Fe+o,l);this.content=s.decode(d)}else if(u===En.BIN){const d=Fe+o;this.body=e.slice(d,d+l)}o+=l}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class ao{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=j.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 f in o){const h=Nt[f]||f.toLowerCase();l[h]=o[f]}for(const f in e.attributes){const h=Nt[f]||f.toLowerCase();if(o[f]!==void 0){const b=s.accessors[e.attributes[f]],A=Ve[b.componentType];d[h]=A.name,u[h]=b.normalized===!0}}return t.getDependency("bufferView",i).then(function(f){return new Promise(function(h,b){n.decodeDracoFile(f,function(A){for(const x in A.attributes){const y=A.attributes[x],g=u[x];g!==void 0&&(y.normalized=g)}h(A)},l,d,c.LinearSRGBColorSpace,b)})})}}class lo{constructor(){this.name=j.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 co{constructor(){this.name=j.KHR_MESH_QUANTIZATION}}class qn 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,f=n-t,h=(s-t)/f,b=h*h,A=b*h,x=e*d,y=x-d,g=-2*A+3*b,C=A-b,w=1-g,p=C-b+h;for(let m=0;m!==l;m++){const v=o[y+m+l],N=o[y+m+u]*f,O=o[x+m+l],T=o[x+m]*f;i[m]=w*v+p*N+g*O+C*T}return i}}const uo=new c.Quaternion;class ho extends qn{interpolate_(e,t,s,n){const i=super.interpolate_(e,t,s,n);return uo.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},Ve={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Tn={9728:c.NearestFilter,9729:c.LinearFilter,9984:c.NearestMipmapNearestFilter,9985:c.LinearMipmapNearestFilter,9986:c.NearestMipmapLinearFilter,9987:c.LinearMipmapLinearFilter},Dn={33071:c.ClampToEdgeWrapping,33648:c.MirroredRepeatWrapping,10497:c.RepeatWrapping},wt={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Nt={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"},fo={CUBICSPLINE:void 0,LINEAR:c.InterpolateLinear,STEP:c.InterpolateDiscrete},vt={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function po(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 ge(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 mo(r,e,t){let s=!1,n=!1,i=!1;for(let d=0,f=e.length;d<f;d++){const h=e[d];if(h.POSITION!==void 0&&(s=!0),h.NORMAL!==void 0&&(n=!0),h.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,f=e.length;d<f;d++){const h=e[d];if(s){const b=h.POSITION!==void 0?t.getDependency("accessor",h.POSITION):r.attributes.position;o.push(b)}if(n){const b=h.NORMAL!==void 0?t.getDependency("accessor",h.NORMAL):r.attributes.normal;l.push(b)}if(i){const b=h.COLOR_0!==void 0?t.getDependency("accessor",h.COLOR_0):r.attributes.color;u.push(b)}}return Promise.all([Promise.all(o),Promise.all(l),Promise.all(u)]).then(function(d){const f=d[0],h=d[1],b=d[2];return s&&(r.morphAttributes.position=f),n&&(r.morphAttributes.normal=h),i&&(r.morphAttributes.color=b),r.morphTargetsRelative=!0,r})}function Ao(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 go(r){let e;const t=r.extensions&&r.extensions[j.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Et(t.attributes):e=r.indices+":"+Et(r.attributes)+":"+r.mode,r.targets!==void 0)for(let s=0,n=r.targets.length;s<n;s++)e+=":"+Et(r.targets[s]);return e}function Et(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 St(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 yo(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 bo=new c.Matrix4;class xo{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Gi,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),ge(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,f]of o.children.entries())i(f,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[j.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=wt[n.type],l=Ve[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=wt[n.type],d=Ve[n.componentType],f=d.BYTES_PER_ELEMENT,h=f*u,b=n.byteOffset||0,A=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,x=n.normalized===!0;let y,g;if(A&&A!==h){const C=Math.floor(b/A),w="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+C+":"+n.count;let p=t.cache.get(w);p||(y=new d(l,C*A,n.count*A/f),p=new c.InterleavedBuffer(y,A/f),t.cache.add(w,p)),g=new c.InterleavedBufferAttribute(p,u,b%A/f,x)}else l===null?y=new d(n.count*u):y=new d(l,b,n.count*u),g=new c.BufferAttribute(y,u,x);if(n.sparse!==void 0){const C=wt.SCALAR,w=Ve[n.sparse.indices.componentType],p=n.sparse.indices.byteOffset||0,m=n.sparse.values.byteOffset||0,v=new w(o[1],p,n.sparse.count*C),N=new d(o[2],m,n.sparse.count*u);l!==null&&(g=new c.BufferAttribute(g.array.slice(),g.itemSize,g.normalized)),g.normalized=!1;for(let O=0,T=v.length;O<T;O++){const U=v[O];if(g.setX(U,N[O*u]),u>=2&&g.setY(U,N[O*u+1]),u>=3&&g.setZ(U,N[O*u+2]),u>=4&&g.setW(U,N[O*u+3]),u>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}g.normalized=x}return g})}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(f){f.flipY=!1,f.name=o.name||l.name||"",f.name===""&&typeof l.uri=="string"&&l.uri.startsWith("data:image/")===!1&&(f.name=l.uri);const b=(i.samplers||{})[o.sampler]||{};return f.magFilter=Tn[b.magFilter]||c.LinearFilter,f.minFilter=Tn[b.minFilter]||c.LinearMipmapLinearFilter,f.wrapS=Dn[b.wrapS]||c.RepeatWrapping,f.wrapT=Dn[b.wrapT]||c.RepeatWrapping,f.generateMipmaps=!f.isCompressedTexture&&f.minFilter!==c.NearestFilter&&f.minFilter!==c.LinearFilter,n.associations.set(f,{textures:e}),f}).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(h=>h.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(h){d=!0;const b=new Blob([h],{type:o.mimeType});return u=l.createObjectURL(b),u});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const f=Promise.resolve(u).then(function(h){return new Promise(function(b,A){let x=b;t.isImageBitmapLoader===!0&&(x=function(y){const g=new c.Texture(y);g.needsUpdate=!0,b(g)}),t.load(c.LoaderUtils.resolveURL(h,i.path),x,void 0,A)})}).then(function(h){return d===!0&&l.revokeObjectURL(u),ge(h,o),h.userData.mimeType=o.mimeType||yo(o.uri),h}).catch(function(h){throw console.error("THREE.GLTFLoader: Couldn't load texture",u),h});return this.sourceCache[e]=f,f}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[j.KHR_TEXTURE_TRANSFORM]){const l=s.extensions!==void 0?s.extensions[j.KHR_TEXTURE_TRANSFORM]:void 0;if(l){const u=i.associations.get(o);o=i.extensions[j.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[j.KHR_MATERIALS_UNLIT]){const h=n[j.KHR_MATERIALS_UNLIT];o=h.getMaterialType(),d.push(h.extendParams(l,i,t))}else{const h=i.pbrMetallicRoughness||{};if(l.color=new c.Color(1,1,1),l.opacity=1,Array.isArray(h.baseColorFactor)){const b=h.baseColorFactor;l.color.setRGB(b[0],b[1],b[2],c.LinearSRGBColorSpace),l.opacity=b[3]}h.baseColorTexture!==void 0&&d.push(t.assignTexture(l,"map",h.baseColorTexture,c.SRGBColorSpace)),l.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,l.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(d.push(t.assignTexture(l,"metalnessMap",h.metallicRoughnessTexture)),d.push(t.assignTexture(l,"roughnessMap",h.metallicRoughnessTexture))),o=this._invokeOne(function(b){return b.getMaterialType&&b.getMaterialType(e)}),d.push(Promise.all(this._invokeAll(function(b){return b.extendMaterialParams&&b.extendMaterialParams(e,l)})))}i.doubleSided===!0&&(l.side=c.DoubleSide);const f=i.alphaMode||vt.OPAQUE;if(f===vt.BLEND?(l.transparent=!0,l.depthWrite=!1):(l.transparent=!1,f===vt.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 h=i.normalTexture.scale;l.normalScale.set(h,h)}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 h=i.emissiveFactor;l.emissive=new c.Color().setRGB(h[0],h[1],h[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 h=new o(l);return i.name&&(h.name=i.name),ge(h,i),t.associations.set(h,{materials:e}),i.extensions&&Ne(n,h,i),h})}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[j.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(l,t).then(function(u){return Nn(u,l,t)})}const o=[];for(let l=0,u=e.length;l<u;l++){const d=e[l],f=go(d),h=n[f];if(h)o.push(h.promise);else{let b;d.extensions&&d.extensions[j.KHR_DRACO_MESH_COMPRESSION]?b=i(d):b=Nn(new c.BufferGeometry,d,t),n[f]={primitive:d,promise:b},o.push(b)}}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 f=o[u].material===void 0?po(this.cache):this.getDependency("material",o[u].material);l.push(f)}return l.push(t.loadGeometries(o)),Promise.all(l).then(function(u){const d=u.slice(0,u.length-1),f=u[u.length-1],h=[];for(let A=0,x=f.length;A<x;A++){const y=f[A],g=o[A];let C;const w=d[A];if(g.mode===ue.TRIANGLES||g.mode===ue.TRIANGLE_STRIP||g.mode===ue.TRIANGLE_FAN||g.mode===void 0)C=i.isSkinnedMesh===!0?new c.SkinnedMesh(y,w):new c.Mesh(y,w),C.isSkinnedMesh===!0&&C.normalizeSkinWeights(),g.mode===ue.TRIANGLE_STRIP?C.geometry=wn(C.geometry,c.TriangleStripDrawMode):g.mode===ue.TRIANGLE_FAN&&(C.geometry=wn(C.geometry,c.TriangleFanDrawMode));else if(g.mode===ue.LINES)C=new c.LineSegments(y,w);else if(g.mode===ue.LINE_STRIP)C=new c.Line(y,w);else if(g.mode===ue.LINE_LOOP)C=new c.LineLoop(y,w);else if(g.mode===ue.POINTS)C=new c.Points(y,w);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+g.mode);Object.keys(C.geometry.morphAttributes).length>0&&Ao(C,i),C.name=t.createUniqueName(i.name||"mesh_"+e),ge(C,i),g.extensions&&Ne(n,C,g),t.assignFinalMaterial(C),h.push(C)}for(let A=0,x=h.length;A<x;A++)t.associations.set(h[A],{meshes:e,primitives:A});if(h.length===1)return i.extensions&&Ne(n,h[0],i),h[0];const b=new c.Group;i.extensions&&Ne(n,b,i),t.associations.set(b,{meshes:e});for(let A=0,x=h.length;A<x;A++)b.add(h[A]);return b})}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)),ge(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,f=o.length;d<f;d++){const h=o[d];if(h){l.push(h);const b=new c.Matrix4;i!==null&&b.fromArray(i.array,d*16),u.push(b)}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=[],f=[];for(let h=0,b=n.channels.length;h<b;h++){const A=n.channels[h],x=n.samplers[A.sampler],y=A.target,g=y.node,C=n.parameters!==void 0?n.parameters[x.input]:x.input,w=n.parameters!==void 0?n.parameters[x.output]:x.output;y.node!==void 0&&(o.push(this.getDependency("node",g)),l.push(this.getDependency("accessor",C)),u.push(this.getDependency("accessor",w)),d.push(x),f.push(y))}return Promise.all([Promise.all(o),Promise.all(l),Promise.all(u),Promise.all(d),Promise.all(f)]).then(function(h){const b=h[0],A=h[1],x=h[2],y=h[3],g=h[4],C=[];for(let p=0,m=b.length;p<m;p++){const v=b[p],N=A[p],O=x[p],T=y[p],U=g[p];if(v===void 0)continue;v.updateMatrix&&v.updateMatrix();const Y=s._createAnimationTracks(v,N,O,T,U);if(Y)for(let Q=0;Q<Y.length;Q++)C.push(Y[Q])}const w=new c.AnimationClip(i,void 0,C);return ge(w,n),w})}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,f=l.length;d<f;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 f=d[0],h=d[1],b=d[2];b!==null&&f.traverse(function(A){A.isSkinnedMesh&&A.bind(b,bo)});for(let A=0,x=h.length;A<x;A++)f.add(h[A]);if(f.userData.pivot!==void 0&&h.length>0){const A=f.userData.pivot,x=h[0];f.pivot=new c.Vector3().fromArray(A),f.position.x-=A[0],f.position.y-=A[1],f.position.z-=A[2],x.position.set(0,0,0),delete f.userData.pivot}return f})}_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 f;if(i.isBone===!0?f=new c.Bone:d.length>1?f=new c.Group:d.length===1?f=d[0]:f=new c.Object3D,f!==d[0])for(let h=0,b=d.length;h<b;h++)f.add(d[h]);if(i.name&&(f.userData.name=i.name,f.name=o),ge(f,i),i.extensions&&Ne(s,f,i),i.matrix!==void 0){const h=new c.Matrix4;h.fromArray(i.matrix),f.applyMatrix4(h)}else i.translation!==void 0&&f.position.fromArray(i.translation),i.rotation!==void 0&&f.quaternion.fromArray(i.rotation),i.scale!==void 0&&f.scale.fromArray(i.scale);if(!n.associations.has(f))n.associations.set(f,{});else if(i.mesh!==void 0&&n.meshCache.refs[i.mesh]>1){const h=n.associations.get(f);n.associations.set(f,{...h})}return n.associations.get(f).nodes=e,f}),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)),ge(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 f=0,h=u.length;f<h;f++){const b=u[f];b.parent!==null?i.add(Ui(b)):i.add(b)}const d=f=>{const h=new Map;for(const[b,A]of n.associations)(b instanceof c.Material||b instanceof c.Texture)&&h.set(b,A);return f.traverse(b=>{const A=n.associations.get(b);A!=null&&h.set(b,A)}),h};return n.associations=d(i),i})}_createAnimationTracks(e,t,s,n,i){const o=[],l=e.name?e.name:e.uuid,u=[];function d(A){A.morphTargetInfluences&&u.push(A.name?A.name:A.uuid)}Me[i.path]===Me.weights?(d(e),e.isGroup&&e.children.forEach(d)):u.push(l);let f;switch(Me[i.path]){case Me.weights:f=c.NumberKeyframeTrack;break;case Me.rotation:f=c.QuaternionKeyframeTrack;break;case Me.translation:case Me.scale:f=c.VectorKeyframeTrack;break;default:switch(s.itemSize){case 1:f=c.NumberKeyframeTrack;break;case 2:case 3:default:f=c.VectorKeyframeTrack;break}break}const h=n.interpolation!==void 0?fo[n.interpolation]:c.InterpolateLinear,b=this._getArrayFromAccessor(s);for(let A=0,x=u.length;A<x;A++){const y=new f(u[A]+"."+Me[i.path],t.array,b,h);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(y),o.push(y)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const s=St(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?ho:qn;return new n(this.times,this.values,this.getValueSize()/3,s)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Io(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 f=St(Ve[l.componentType]);n.min.multiplyScalar(f),n.max.multiplyScalar(f)}}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,f=i.length;d<f;d++){const h=i[d];if(h.POSITION!==void 0){const b=t.json.accessors[h.POSITION],A=b.min,x=b.max;if(A!==void 0&&x!==void 0){if(u.setX(Math.max(Math.abs(A[0]),Math.abs(x[0]))),u.setY(Math.max(Math.abs(A[1]),Math.abs(x[1]))),u.setZ(Math.max(Math.abs(A[2]),Math.abs(x[2]))),b.normalized){const y=St(Ve[b.componentType]);u.multiplyScalar(y)}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 Nn(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=Nt[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.`),ge(r,e),Io(r,e,t),Promise.all(n).then(function(){return e.targets!==void 0?mo(r,e.targets,t):r})}let Ot=null;function Co(r){Ot=r}const pe=a.reactive({scripts:[]});function Yn(){return"s_"+Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4)}function Mo(r){var t;const e={id:Yn(),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 wo(r){const e=pe.scripts.findIndex(t=>t.id===r);e!==-1&&pe.scripts.splice(e,1)}function vo(r){pe.scripts=(r||[]).map(e=>({id:(e==null?void 0:e.id)||Yn(),name:(e==null?void 0:e.name)??"",code:(e==null?void 0:e.code)??""}))}function Eo(){pe.scripts=[]}function To(r){const e=pe.scripts.find(t=>t.id===r);if(e){if(!Ot){console.warn("[脚本] 执行器尚未注册,请先初始化编辑器(initEditor)");return}try{Ot(e)}catch(t){console.error("[脚本] 执行出错:",e.name,t)}}}function Kn(r){var e;return!!r&&((e=r.name)==null?void 0:e.trim())==="初始化"}function Do(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 M={mode:"",transformControlsMode:"translate",scene:null,camera:null,defaultMainCamera:null,renderer:null,orbitControls:null,transformControls:null,container:null,gridHelper:null,selectedObject:null};let at=!1,Re=!1,we=null;const No=16755200;let Rt=[],st=[],Ye=!0,Oe=null,de=null,lt=null,ve=[];const Pe=new Map;let Ke,ct=null,We=null,Xe=null;async function Zn(r,e="edit",t){M.container=r,M.mode=e,Oo(),Po(),ko(),t&&(await ds(t.scene,e,t.dataPanels,t.waters,t.textures,t.ambientLight,t.scripts),t!=null&&t.camera&&(M.defaultMainCamera=t.camera,Bt(!0))),Ho(),Vo(),Ke&&M.orbitControls&&(M.orbitControls.target.fromArray(Ke),M.orbitControls.update()),Ro(),ns(),Jn(),We=s=>Fo(s),Xe=()=>jo(),e==="edit"&&r.addEventListener("click",We),window.addEventListener("resize",Xe),t||Bo(),e==="edit"&&Lo(),er()}function So(){return window.devicePixelRatio}function Oo(){const r=So(),e=new S.WebGLRenderer({antialias:!0,alpha:!0});e.setSize(M.container.clientWidth,M.container.clientHeight),e.setPixelRatio(r),e.toneMapping=S.NeutralToneMapping,e.toneMappingExposure=1,console.log(`[Renderer] css=${M.container.clientWidth}×${M.container.clientHeight}, dpr=${window.devicePixelRatio}, targetRatio=${r}, antialias=true`),M.container.appendChild(e.domElement),M.renderer=e}function Ro(){if(!M.renderer||!M.scene||!M.camera)return;const r=M.renderer.getPixelRatio(),e=M.container.clientWidth*r,t=M.container.clientHeight*r,s=new S.WebGLRenderTarget(e,t,{type:S.HalfFloatType,samples:4});s.texture.name="EffectComposer.rt1";const n=new ni(M.renderer,s);n.addPass(new si(M.scene,M.camera)),n.addPass(new ii),we=n}function Po(){if(M.scene=new S.Scene,M.scene.name="sl_scene",M.renderer){const r=rt(M.renderer);r?(M.scene.environment=r,M.scene.environmentIntensity=1):console.warn("[初始化] 环境贴图生成失败,场景将没有 IBL 间接光照")}}function Lo(){const r=new S.GridHelper(30,30,8956671,3364232);r.name="地板",r.userData.type="initFloor",M.scene.add(r),M.gridHelper=r}function ko(){const r=M.container,e=r.clientWidth/r.clientHeight,t=new S.PerspectiveCamera(45,e,.1,1e3);t.position.set(0,6,15),t.lookAt(0,0,0),M.camera=t}function Bt(r=!1){if(!M.defaultMainCamera)return;const e=M.defaultMainCamera;if(r){M.camera.position.set(e.position[0],e.position[1],e.position[2]),M.camera.rotation.set(e.rotation[0],e.rotation[1],e.rotation[2]),M.camera.updateProjectionMatrix(),Ke=e.target;return}else Ut(""),ht();if(!M.camera||!M.orbitControls)return;const t=M.camera.position.clone(),s=M.orbitControls.target.clone(),n=new S.Vector3(e.position[0],e.position[1],e.position[2]),i=e.target?new S.Vector3(e.target[0],e.target[1],e.target[2]):new S.Vector3(0,0,0);M.orbitControls.enabled=!1,new ne.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(ne.Easing.Quadratic.InOut).onUpdate(o=>{M.camera.position.set(o.x,o.y,o.z),M.orbitControls.target.set(o.tx,o.ty,o.tz),M.orbitControls.update()}).onComplete(()=>{Ke=e.target,M.orbitControls.enabled=!0}).start()}function Vo(){const r=new Ds(M.camera,M.renderer.domElement);r.minDistance=0,r.maxDistance=1/0,r.addEventListener("start",()=>{at=!1}),r.addEventListener("change",()=>{at=!0}),r.addEventListener("end",()=>{at&&(Re=!0,setTimeout(()=>{Re=!1},200))}),M.orbitControls=r}function Ho(){const r=new Us(M.camera,M.renderer.domElement);r.addEventListener("dragging-changed",e=>{M.orbitControls.enabled=!e.value,e.value||(Re=!0,setTimeout(()=>{Re=!1},200))}),r.addEventListener("objectChange",()=>{const e=M.selectedObject;if(de&&e&&de(e),e&&e.type==="DirectionalLight"){const t=e.userData.helper;t&&t.update&&t.update()}}),M.scene.add(r.getHelper()),M.transformControls=r}function Qn(r=M.scene){if(!r||r.children.some(t=>t.type==="AmbientLight"))return null;const e=new S.AmbientLight(tr,nr);return e.name="环境光",r.add(e),e}function Bo(){Qn(M.scene)}function Jn(){var e,t;ct=requestAnimationFrame(Jn),ne.update(),(e=M.orbitControls)==null||e.update(),M.mode==="run"&&we&&M.scene&&M.camera?we.render():(t=M.renderer)==null||t.render(M.scene,M.camera),M.scene&&M.camera&&jn(M.scene,M.camera),Ye&&M.scene&&(st=[],M.scene.traverse(s=>{s.userData.isWater&&s.type==="Mesh"&&st.push(s)}),Ye=!1);for(let s=0;s<st.length;s++){const n=st[s],i=n.material;if(i.uniforms&&i.uniforms.time){const o=n.userData.waterTimeScale??1;i.uniforms.time.value+=1/60*o,M.camera&&i.uniforms.eye&&i.uniforms.eye.value.copy(M.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 jo(){if(!M.container||!M.camera||!M.renderer)return;const r=M.container.clientWidth,e=M.container.clientHeight;r===0||e===0||(M.camera.aspect=r/e,M.camera.updateProjectionMatrix(),M.renderer.setSize(r,e),we&&we.setSize(r,e),Fn(r,e))}function Qe(r){let e=r;for(;e;){if(e.isTransformControlsRoot)return;e=e.parent}M.selectedObject!==r&&(M.selectedObject&&M.transformControls.detach(),M.selectedObject=r,M.transformControls.attach(r),M.transformControls.setMode(M.transformControlsMode),M.transformControls.showX=!0,M.transformControls.showY=!0,M.transformControls.showZ=!0,$n(r),Oe==null||Oe(r))}let ae=null;function _n(r){ae=r}function ut(r){ae==null||ae(r)}function jt(r){M.transformControlsMode=r,M.transformControls&&M.transformControls.setMode(M.transformControlsMode)}function $n(r){if(M.mode!=="edit"){ht();return}ht(),r.traverse(e=>{if(e.isMesh){const t=e,s=new S.EdgesGeometry(t.geometry),n=new S.LineBasicMaterial({color:No,depthTest:!0}),i=new S.LineSegments(s,n);e.add(i),Rt.push(i)}})}function ht(){for(const r of Rt)r.parent&&r.parent.remove(r),r.geometry.dispose(),r.material.dispose();Rt=[]}function Ft(){M.selectedObject&&(ht(),M.transformControls.detach(),M.selectedObject=null,Oe==null||Oe(null))}function Ut(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)}),$n(e),M.selectedObject=e,setTimeout(()=>{Gt(e)},500))}function Fo(r){if(Re){Re=!1;return}const e=Uo(r);e?Qe(e):Ft()}function Uo(r){const e=M.renderer.domElement.getBoundingClientRect(),t=new S.Vector2((r.clientX-e.left)/e.width*2-1,-((r.clientY-e.top)/e.height)*2+1),s=new S.Raycaster;s.setFromCamera(t,M.camera);const n=[],i=l=>{l.isTransformControlsRoot||l.isGridHelper||l.type==="Line"||l.type==="LineSegments"||((l.userData.isMovable||l.userData.type==="lightHelper")&&n.push(l),l.children.forEach(i))};i(M.scene);const o=s.intersectObjects(n);if(o.length===0)return null;for(const l of o){const u=Sn(l.object);if(u!==M.selectedObject)return u}return Sn(o[0].object)}function Sn(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 Gt(r,e=500){if(!M.camera||!M.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 S.Vector3;r.getWorldPosition(s);const i=new S.Box3().setFromObject(r).getSize(new S.Vector3),o=Math.max(i.x,i.y,i.z)*.5,l=Math.max(o*3.5,5),u=new S.Vector3().copy(M.camera.position).sub(s).normalize();u.lengthSq()<.001&&u.set(0,0,1);const d=s.clone().add(u.multiplyScalar(l)),f=M.camera.position.clone(),h=M.orbitControls.target.clone();try{new ne.Tween({x:f.x,y:f.y,z:f.z,tx:h.x,ty:h.y,tz:h.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(ne.Easing.Quadratic.InOut).onUpdate(b=>{M.camera.position.set(b.x,b.y,b.z),M.orbitControls.target.set(b.tx,b.ty,b.tz),M.orbitControls.update()}).start()}catch(b){console.error("[focusOnObject] TWEEN 动画创建失败,请检查 @tweenjs/tween.js 是否已正确安装且版本兼容(^23.1.3):",b)}}function Go(r){r.userData.id&&Pe.set(String(r.userData.id),r)}function zo(r){r.userData.id&&Pe.delete(String(r.userData.id))}function es(r,e){const t=e||r.userData.id;if(t)Pe.set(String(t),r);else{const s=S.MathUtils.generateUUID();r.userData.id=s,Pe.set(s,r)}}function Wo(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 ts(r){var s,n;const e=(s=M.scene)==null?void 0:s.environment;if(!e)return;const t=((n=M.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 ye(r,e=!1){M.scene.add(r),ts(r),Ye=!0,r.userData.isMovable&&(Xo(r),mt()),e&&M.mode==="edit"&&Qe(r)}function zt(r){M.selectedObject===r&&Ft(),Ye=!0,Wo(r),zo(r),r.userData.helper&&M.scene.remove(r.userData.helper),r.parent?r.parent.remove(r):M.scene.remove(r),qo(r),mt()}function Wt(r){const e=M.scene.getObjectByProperty("uuid",r);e&&zt(e)}function Xo(r){r.userData.isMovable&&r.parent===M.scene&&(ve.includes(r)||ve.push(r))}function qo(r){const e=ve.indexOf(r);e!==-1&&ve.splice(e,1)}function ns(){const r=[];M.scene.children.forEach(e=>{e.userData.isMovable&&r.push(e)}),ve=r,mt()}function mt(){lt==null||lt([...ve])}function ss(r){Oe=r}function is(r){de=r}function os(r){lt=r}function Xt(){return ve}function ft(){return M.selectedObject}function rs(r,e,t){if(!M.scene)return;const s=Pe.get(r);if(s){const n=He(s);n&&n.updateItemByCode(e,t)}}function Pt(){return M.scene}function pt(){return M.camera}function Lt(){return M.renderer}const as={linear:ne.Easing.Linear.None,"quad.in":ne.Easing.Quadratic.In,"quad.out":ne.Easing.Quadratic.Out,"quad.inout":ne.Easing.Quadratic.InOut,"cubic.inout":ne.Easing.Cubic.InOut,"sine.inout":ne.Easing.Sinusoidal.InOut,"back.out":ne.Easing.Back.Out,"elastic.out":ne.Easing.Elastic.Out,"bounce.out":ne.Easing.Bounce.Out},kt=new WeakMap;function ls(r){let e=kt.get(r);return e||(e={position:new Set,rotation:new Set,scale:new Set,opacity:new Set},kt.set(r,e)),e}function Yo(r,e,t,s){const n=ls(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 qt(r,e=[]){if(!r)return;const t=kt.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 Ko(r){return r*Math.PI/180}function At(r,e={}){if(!r)return console.warn("[脚本动画] 目标对象为空,无法执行动画"),null;const t=e.duration??1e3,s=as[e.easing??"quad.inout"]??ne.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),qt(r,n);const o=new ne.Tween(r).to(i,t).easing(s).onUpdate(()=>{r===M.selectedObject&&(de==null||de(r))}).start();return Yo(r,o,n,()=>{var l;(l=e.onComplete)==null||l.call(e),r===M.selectedObject&&(de==null||de(r))}),o}function Zo(r,e,t=1e3,s){return At(r,{position:e,duration:t,easing:s})}function Qo(r,e,t=1e3,s){return At(r,{rotation:e,duration:t,easing:s})}function Jo(r,e,t=1e3,s){return At(r,{scale:e,duration:t,easing:s})}function _o(r,e,t=1e3,s,n){if(!r)return console.warn("[脚本动画] 目标对象为空,无法执行透明度动画"),null;const i=new Set;if(r.traverse(A=>{const x=A.material;if(!x)return;(Array.isArray(x)?x:[x]).forEach(g=>g&&i.add(g))}),i.size===0)return console.warn("[脚本动画] 目标及其子节点没有材质,无法执行透明度动画:",r.name),null;const o=t??1e3,l=as[s??"quad.inout"]??ne.Easing.Quadratic.InOut,u=Math.min(1,Math.max(0,e)),d=u<=.01;d||(r.visible=!0),qt(r,["opacity"]);const f=[...i];f.forEach(A=>{A.transparent=!0,A.needsUpdate=!0}),M.renderer&&M.scene&&M.camera&&M.renderer.render(M.scene,M.camera);const h=ls(r),b=f.map(A=>{const x=new ne.Tween(A).to({opacity:u},o).easing(l).start();return h.opacity.add(x),x});return b.forEach((A,x)=>{x===0?A.onComplete(()=>{h.opacity.delete(A),d&&(r.visible=!1),n==null||n(),r===M.selectedObject&&(de==null||de(r))}):A.onComplete(()=>h.opacity.delete(A)),A.onStop(()=>h.opacity.delete(A))}),b[0]??null}function $o(){return{THREE:S,scene:Pt(),camera:pt(),renderer:Lt(),selectedObject:ft(),getScene:Pt,getCamera:pt,getRenderer:Lt,getSelectedObject:ft,getSceneObjects:Xt,addModel:ye,removeModel:zt,removeModelById:Wt,selectObject:Qe,updateDataPanelValue:rs,setTransformMode:jt,focusOnObject:Gt,animateTo:At,moveTo:Zo,rotateTo:Qo,scaleTo:Jo,fadeTo:_o,stopAnimations:qt,degToRad:Ko,console,window,document,setTimeout,setInterval,requestAnimationFrame}}function cs(r){var l;const e=(l=r==null?void 0:r.code)==null?void 0:l.trim();if(!e)return;const t=$o(),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
- 提示: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)}}Co(cs);function er(){for(const r of pe.scripts)Kn(r)&&(console.log("[初始化] 自动执行脚本:",r.name),cs(r))}const tr=16777215,nr=1;async function us(){var m,v,N,O;ae==null||ae(!0),await new Promise(T=>setTimeout(T,50)),Ft();const r=M.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(T=>{var U,Y,Q,J;if(T.userData._sourceUuid=T.uuid,T.type==="AmbientLight"){const X=T;l={color:"#"+X.color.getHexString(),intensity:X.intensity,name:X.name||"环境光",visible:X.visible,position:X.position.toArray()},u.push(X)}if(T.userData.type==="lightHelper"&&e.push(T),T.type==="DirectionalLight"&&T.userData.helper&&(t.set(T,T.userData.helper),T.userData.helper=void 0),T.userData.isWater&&T.type==="Mesh"&&T.parent&&((Y=(U=T.material)==null?void 0:U.uniforms)!=null&&Y.waterColor)){const X=T,z=X.material;let P="#4fc3f7";z.uniforms&&z.uniforms.waterColor&&(P="#"+z.uniforms.waterColor.value.getHexString());const k=X.geometry,V={uuid:T.uuid,name:T.name,position:T.position.toArray(),rotation:[T.rotation.x,T.rotation.y,T.rotation.z],scale:T.scale.toArray(),color:P,timeScale:T.userData.waterTimeScale??.05,alpha:z.uniforms&&z.uniforms.alpha?z.uniforms.alpha.value:.3,geometryType:"box",boxWidth:void 0,boxDepth:void 0,cylinderRadiusTop:void 0,cylinderRadiusBottom:void 0,cylinderRadialSegments:void 0};k.parameters&&k.parameters.radiusTop!==void 0?(V.geometryType="cylinder",V.cylinderRadiusTop=k.parameters.radiusTop,V.cylinderRadiusBottom=k.parameters.radiusBottom,V.cylinderRadialSegments=k.parameters.radialSegments):(V.geometryType="box",V.boxWidth=k.parameters.width,V.boxDepth=k.parameters.depth),i.push(V),o.push(T)}if(T.name&&T.name.startsWith("DataPanel_")){const X=T;if(X.element){const z=X.element.querySelector("[data-panel-title]"),P=[];if(X.element.querySelectorAll(".sl-css2d-data-panel-item").forEach(V=>{var re,he,fe;const q=V.querySelector(".item-label"),H=V.querySelector(".item-value");if(q&&H){const Ie=(q.textContent||"").trim(),me=((he=(re=H.childNodes[0])==null?void 0:re.textContent)==null?void 0:he.trim())||"",be=H.querySelector("span"),gt=be?(be.textContent||"").trim():void 0,yt=((fe=V.getAttribute("data-item-code"))==null?void 0:fe.trim())||void 0;P.push({label:Ie,value:me,unit:gt,code:yt})}}),T.parent){const V=X.element.style.width||"",q=X.element.style.fontSize||"",H=He(T.parent),re=H?H.getOffsetY():.1;s.set(T.parent.userData.id?T.parent.userData.id:T.parent.uuid,{title:((Q=z==null?void 0:z.textContent)==null?void 0:Q.trim())||"",items:P,width:V,fontSize:q,offsetY:re,offsetX:H?H.getOffsetX():0,offsetZ:H?H.getOffsetZ():0})}}}if(T.type==="Mesh"){const X=T,z=Array.isArray(X.material)?X.material:[X.material];for(const P of z)if(P&&P.userData){const k=P.userData;if(k._mapDataUrl||k._normalMapDataUrl||k._aoMapDataUrl){const V=P.uuid,q=n[V]||{};k._mapDataUrl&&(q.mapDataUrl=k._mapDataUrl,q.mapFileName=k._mapFileName),k._normalMapDataUrl&&(q.normalMapDataUrl=k._normalMapDataUrl,q.normalMapFileName=k._normalMapFileName,q.normalScale=((J=P.normalScale)==null?void 0:J.x)??1),k._aoMapDataUrl&&(q.aoMapDataUrl=k._aoMapDataUrl,q.aoMapFileName=k._aoMapFileName,q.aoMapIntensity=P.aoMapIntensity??1),n[V]=q}}}}),e.forEach(T=>r.remove(T));const d=(m=M.transformControls)==null?void 0:m.getHelper(),f=(d==null?void 0:d.parent)??null;d&&d.parent&&d.parent.remove(d);const h=new Map;for(const T of u)h.set(T,T.parent),T.parent&&T.parent.remove(T);const b=[];r.traverse(T=>{if(T.type==="DirectionalLight"){const U=T;U.target.parent===r&&b.push(U.target)}});for(const T of b)r.remove(T);const A=new Map;for(const T of o)A.set(T,T.parent),T.parent&&T.parent.remove(T);const x=r.clone();x.children=x.children.filter(T=>T.userData.type!=="initFloor"),x.traverse(T=>{T.name&&T.name.startsWith("DataPanel_")&&T.parent&&T.parent.remove(T)});const g=await new ze().parseAsync(x,{binary:!0,onlyVisible:!1,embedImages:!0});e.forEach(T=>r.add(T));for(const T of u){const U=h.get(T);U?U.add(T):r.add(T)}for(const T of b)r.add(T);for(const T of o){const U=A.get(T);U?U.add(T):r.add(T)}t.forEach((T,U)=>{U.userData.helper=T}),r.traverse(T=>{delete T.userData._sourceUuid}),d&&(f?f.add(d):r.add(d));const C={position:(v=M.camera)==null?void 0:v.position.toArray(),rotation:(N=M.camera)==null?void 0:N.rotation.toArray(),target:((O=M.orbitControls)==null?void 0:O.target.toArray())||[0,0,0]},w={};s.forEach((T,U)=>{w[U]=T});const p={scene:g,camera:C,dataPanels:w,waters:i,textures:n,ambientLight:l,scripts:pe.scripts.map(T=>({id:T.id,name:T.name,code:T.code}))};return ae==null||ae(!1),p}function sr(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 ds(r,e="edit",t,s,n,i,o){var u,d,f,h,b,A,x;const l=sr(r);if(l){const y=await new Wn().parseAsync(l,""),g=y.scene||((u=y.scenes)==null?void 0:u[0]),C=(d=M.scene)==null?void 0:d.environment;if(M.scene=g,!g.children.some(p=>p.type==="AmbientLight"))if(i){const p=new S.AmbientLight(i.color,i.intensity);p.name=i.name||"环境光",p.visible=i.visible??!0,i.position&&p.position.fromArray(i.position),g.add(p)}else Qn(g);if(C)M.scene.environment=C,M.scene.environmentIntensity=1;else if(M.renderer){const p=rt(M.renderer);p&&(M.scene.environment=p,M.scene.environmentIntensity=1)}if(!M.scene.environment&&M.renderer){const p=rt(M.renderer);p?(M.scene.environment=p,M.scene.environmentIntensity=1,console.warn("[导入] 原环境贴图不可用,已重新生成")):console.error("[导入] 环境贴图生成失败,场景将没有 IBL 间接光照,模型会偏暗")}ts(g);const w=p=>{if(p.isTransformControlsRoot)return;p.type!=="AmbientLight"&&p.userData.type!=="lightHelper"&&p.userData.type!=="initFloor"&&(p.userData.isMovable=!0);const m=p.material;p.userData.isWater&&m&&!m.uniforms&&!p.userData.waterSpeed&&(p.userData.waterSpeed={x:5e-4,y:5e-4}),p.children.forEach(w)};w(g)}else{const y=typeof r=="string"?JSON.parse(r):r,C=new S.ObjectLoader().parse(y);if(C.type==="Scene"){const w=(f=M.scene)==null?void 0:f.environment;if(M.scene=C,w)M.scene.environment=w,M.scene.environmentIntensity=1;else if(M.renderer){const p=rt(M.renderer);p&&(M.scene.environment=p,M.scene.environmentIntensity=1)}}else(h=M.scene)==null||h.add(C)}if(t&&((b=M.scene)==null||b.traverse(y=>{const g=y.userData.id||y.userData._sourceUuid||y.uuid,C=t[g];if(C&&y.userData.isMovable){Go(y);const w=new qe({title:C.title,items:C.items});w.attachTo(y),w.visible=!1,C.width&&w.setWidth(C.width),C.fontSize&&w.setFontSize(C.fontSize),C.offsetY!==void 0&&w.setOffsetY(C.offsetY),C.offsetX!==void 0&&w.setOffsetX(C.offsetX),C.offsetZ!==void 0&&w.setOffsetZ(C.offsetZ),Hn(y,w)}})),s&&s.length>0&&Promise.resolve().then(()=>fr).then(({addWater:y,addWaterCylinder:g})=>{for(const C of s){const w=C.geometryType||"box";let p;w==="cylinder"?p=g({radiusTop:C.cylinderRadiusTop??5,radiusBottom:C.cylinderRadiusBottom??5,radialSegments:C.cylinderRadialSegments??32,height:.8,color:C.color,scale:4}):p=y({width:C.boxWidth??10,height:C.boxDepth??10,color:C.color,scale:4}),p.position.fromArray(C.position),p.rotation.set(C.rotation[0],C.rotation[1],C.rotation[2]),p.scale.fromArray(C.scale),p.name=C.name,p.userData.waterTimeScale=C.timeScale??.05,p.userData.isWater=!0,p.userData.isMovable=!0,C.alpha!==void 0&&p.material.uniforms&&p.material.uniforms.alpha&&(p.material.uniforms.alpha.value=C.alpha),Ye=!0}ns()}),n){const y=new S.TextureLoader;(A=M.scene)==null||A.traverse(g=>{if(g.type==="Mesh"){const C=g,w=Array.isArray(C.material)?C.material:[C.material];for(const p of w)if(p&&p.uuid&&n[p.uuid]){const m=n[p.uuid];if(m.mapDataUrl){const v=y.load(m.mapDataUrl);v.wrapS=v.wrapT=S.RepeatWrapping,v.repeat.set(1,1),p.map=v,p.userData=p.userData||{},p.userData._mapDataUrl=m.mapDataUrl,p.userData._mapFileName=m.mapFileName}if(m.normalMapDataUrl){const v=y.load(m.normalMapDataUrl);v.wrapS=v.wrapT=S.RepeatWrapping,v.repeat.set(1,1),p.normalMap=v,p.normalScale=new S.Vector2(m.normalScale??1,m.normalScale??1),p.userData=p.userData||{},p.userData._normalMapDataUrl=m.normalMapDataUrl,p.userData._normalMapFileName=m.normalMapFileName}if(m.aoMapDataUrl){const v=y.load(m.aoMapDataUrl);v.wrapS=v.wrapT=S.RepeatWrapping,v.repeat.set(1,1),p.aoMap=v,p.aoMapIntensity=m.aoMapIntensity??1,p.userData=p.userData||{},p.userData._aoMapDataUrl=m.aoMapDataUrl,p.userData._aoMapFileName=m.aoMapFileName}p.needsUpdate=!0}}})}o&&vo(o),e==="edit"&&((x=M.scene)==null||x.traverse(y=>{var g,C;if(y.type==="DirectionalLight"){const w=y;if(!w.userData.helper){w.target.parent!==M.scene&&(w.target.parent&&w.target.parent.remove(w.target),w.target.position.set(0,0,0),(g=M.scene)==null||g.add(w.target));const p=new S.DirectionalLightHelper(w,1);p.userData.type="lightHelper",w.userData.helper=p,p.update(),(C=M.scene)==null||C.add(p)}}}))}function hs(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)hs(t)}function fs(){ct!==null&&(cancelAnimationFrame(ct),ct=null),We&&M.container&&(M.container.removeEventListener("click",We),We=null),Xe&&(window.removeEventListener("resize",Xe),Xe=null),M.orbitControls&&(M.orbitControls.dispose(),M.orbitControls=null),M.transformControls&&(M.transformControls.dispose(),M.transformControls=null),we&&(we.dispose(),we=null),M.scene&&(hs(M.scene),M.scene=null),M.renderer&&(M.renderer.dispose(),M.renderer.domElement&&M.container&&M.container.removeChild(M.renderer.domElement),M.renderer=null),Un(),M.camera=null,M.gridHelper=null,M.selectedObject=null,M.container=null,M.mode="",M.defaultMainCamera=null,Ke=void 0,ve=[],Pe.clear(),mt(),Eo(),at=!1,Re=!1}const ir=/^[og]\s*(.+)?/,or=/^mtllib /,rr=/^usemtl /,ar=/^usemap /,On=/\s+/,Rn=new c.Vector3,Tt=new c.Vector3,Pn=new c.Vector3,Ln=new c.Vector3,ce=new c.Vector3,it=new c.Color;function lr(){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;Rn.fromArray(n,e),Tt.fromArray(n,t),Pn.fromArray(n,s),ce.subVectors(Pn,Tt),Ln.subVectors(Rn,Tt),ce.cross(Ln),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 f=this.vertices.length;let h=this.parseVertexIndex(e,f),b=this.parseVertexIndex(t,f),A=this.parseVertexIndex(s,f);if(this.addVertex(h,b,A),this.addColor(h,b,A),l!==void 0&&l!==""){const x=this.normals.length;h=this.parseNormalIndex(l,x),b=this.parseNormalIndex(u,x),A=this.parseNormalIndex(d,x),this.addNormal(h,b,A)}else this.addFaceNormal(h,b,A);if(n!==void 0&&n!==""){const x=this.uvs.length;h=this.parseUVIndex(n,x),b=this.parseUVIndex(i,x),A=this.parseUVIndex(o,x),this.addUV(h,b,A),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 lr;e.indexOf(`\r
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)}}Co(cs);function er(){for(const r of pe.scripts)Kn(r)&&(console.log("[初始化] 自动执行脚本:",r.name),cs(r))}const tr=16777215,nr=1;async function us(){var m,v,N,O;ae==null||ae(!0),await new Promise(T=>setTimeout(T,50)),Ft();const r=M.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(T=>{var U,Y,Q,J;if(T.userData._sourceUuid=T.uuid,T.type==="AmbientLight"){const X=T;l={color:"#"+X.color.getHexString(),intensity:X.intensity,name:X.name||"环境光",visible:X.visible,position:X.position.toArray()},u.push(X)}if(T.userData.type==="lightHelper"&&e.push(T),T.type==="DirectionalLight"&&T.userData.helper&&(t.set(T,T.userData.helper),T.userData.helper=void 0),T.userData.isWater&&T.type==="Mesh"&&T.parent&&((Y=(U=T.material)==null?void 0:U.uniforms)!=null&&Y.waterColor)){const X=T,z=X.material;let P="#4fc3f7";z.uniforms&&z.uniforms.waterColor&&(P="#"+z.uniforms.waterColor.value.getHexString());const k=X.geometry,V={uuid:T.uuid,name:T.name,position:T.position.toArray(),rotation:[T.rotation.x,T.rotation.y,T.rotation.z],scale:T.scale.toArray(),color:P,timeScale:T.userData.waterTimeScale??.05,alpha:z.uniforms&&z.uniforms.alpha?z.uniforms.alpha.value:.3,geometryType:"box",boxWidth:void 0,boxDepth:void 0,cylinderRadiusTop:void 0,cylinderRadiusBottom:void 0,cylinderRadialSegments:void 0};k.parameters&&k.parameters.radiusTop!==void 0?(V.geometryType="cylinder",V.cylinderRadiusTop=k.parameters.radiusTop,V.cylinderRadiusBottom=k.parameters.radiusBottom,V.cylinderRadialSegments=k.parameters.radialSegments):(V.geometryType="box",V.boxWidth=k.parameters.width,V.boxDepth=k.parameters.depth),i.push(V),o.push(T)}if(T.name&&T.name.startsWith("DataPanel_")){const X=T;if(X.element){const z=X.element.querySelector("[data-panel-title]"),P=[];if(X.element.querySelectorAll(".sl-css2d-data-panel-item").forEach(V=>{var re,he,fe;const q=V.querySelector(".item-label"),H=V.querySelector(".item-value");if(q&&H){const Ie=(q.textContent||"").trim(),me=((he=(re=H.childNodes[0])==null?void 0:re.textContent)==null?void 0:he.trim())||"",be=H.querySelector("span"),gt=be?(be.textContent||"").trim():void 0,yt=((fe=V.getAttribute("data-item-code"))==null?void 0:fe.trim())||void 0;P.push({label:Ie,value:me,unit:gt,code:yt})}}),T.parent){const V=X.element.style.width||"",q=X.element.style.fontSize||"",H=He(T.parent),re=H?H.getOffsetY():.1;s.set(T.parent.userData.id?T.parent.userData.id:T.parent.uuid,{title:((Q=z==null?void 0:z.textContent)==null?void 0:Q.trim())||"",items:P,width:V,fontSize:q,offsetY:re,offsetX:H?H.getOffsetX():0,offsetZ:H?H.getOffsetZ():0})}}}if(T.type==="Mesh"){const X=T,z=Array.isArray(X.material)?X.material:[X.material];for(const P of z)if(P&&P.userData){const k=P.userData;if(k._mapDataUrl||k._normalMapDataUrl||k._aoMapDataUrl){const V=P.uuid,q=n[V]||{};k._mapDataUrl&&(q.mapDataUrl=k._mapDataUrl,q.mapFileName=k._mapFileName),k._normalMapDataUrl&&(q.normalMapDataUrl=k._normalMapDataUrl,q.normalMapFileName=k._normalMapFileName,q.normalScale=((J=P.normalScale)==null?void 0:J.x)??1),k._aoMapDataUrl&&(q.aoMapDataUrl=k._aoMapDataUrl,q.aoMapFileName=k._aoMapFileName,q.aoMapIntensity=P.aoMapIntensity??1),n[V]=q}}}}),e.forEach(T=>r.remove(T));const d=(m=M.transformControls)==null?void 0:m.getHelper(),f=(d==null?void 0:d.parent)??null;d&&d.parent&&d.parent.remove(d);const h=new Map;for(const T of u)h.set(T,T.parent),T.parent&&T.parent.remove(T);const b=[];r.traverse(T=>{if(T.type==="DirectionalLight"){const U=T;U.target.parent===r&&b.push(U.target)}});for(const T of b)r.remove(T);const A=new Map;for(const T of o)A.set(T,T.parent),T.parent&&T.parent.remove(T);const x=r.clone();x.children=x.children.filter(T=>T.userData.type!=="initFloor"),x.traverse(T=>{T.name&&T.name.startsWith("DataPanel_")&&T.parent&&T.parent.remove(T)});const g=await new ze().parseAsync(x,{binary:!0,onlyVisible:!1,embedImages:!0});e.forEach(T=>r.add(T));for(const T of u){const U=h.get(T);U?U.add(T):r.add(T)}for(const T of b)r.add(T);for(const T of o){const U=A.get(T);U?U.add(T):r.add(T)}t.forEach((T,U)=>{U.userData.helper=T}),r.traverse(T=>{delete T.userData._sourceUuid}),d&&(f?f.add(d):r.add(d));const C={position:(v=M.camera)==null?void 0:v.position.toArray(),rotation:(N=M.camera)==null?void 0:N.rotation.toArray(),target:((O=M.orbitControls)==null?void 0:O.target.toArray())||[0,0,0]},w={};s.forEach((T,U)=>{w[U]=T});const p={scene:g,camera:C,dataPanels:w,waters:i,textures:n,ambientLight:l,scripts:pe.scripts.map(T=>({id:T.id,name:T.name,code:T.code}))};return ae==null||ae(!1),p}function sr(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 ds(r,e="edit",t,s,n,i,o){var u,d,f,h,b,A,x;const l=sr(r);if(l){const y=await new Wn().parseAsync(l,""),g=y.scene||((u=y.scenes)==null?void 0:u[0]),C=(d=M.scene)==null?void 0:d.environment;if(M.scene=g,!g.children.some(w=>w.type==="AmbientLight"))if(i){const w=new S.AmbientLight(i.color,i.intensity);w.name=i.name||"环境光",w.visible=i.visible??!0,i.position&&w.position.fromArray(i.position),g.add(w)}else Qn(g);if(C)M.scene.environment=C,M.scene.environmentIntensity=1;else if(M.renderer){const w=rt(M.renderer);w&&(M.scene.environment=w,M.scene.environmentIntensity=1)}if(!M.scene.environment&&M.renderer){const w=rt(M.renderer);w?(M.scene.environment=w,M.scene.environmentIntensity=1,console.warn("[导入] 原环境贴图不可用,已重新生成")):console.error("[导入] 环境贴图生成失败,场景将没有 IBL 间接光照,模型会偏暗")}ts(g),g.traverse(w=>{const p=w.material;w.userData.isWater&&p&&!p.uniforms&&!w.userData.waterSpeed&&(w.userData.waterSpeed={x:5e-4,y:5e-4})})}else{const y=typeof r=="string"?JSON.parse(r):r,C=new S.ObjectLoader().parse(y);if(C.type==="Scene"){const w=(f=M.scene)==null?void 0:f.environment;if(M.scene=C,w)M.scene.environment=w,M.scene.environmentIntensity=1;else if(M.renderer){const p=rt(M.renderer);p&&(M.scene.environment=p,M.scene.environmentIntensity=1)}}else(h=M.scene)==null||h.add(C)}if(t&&((b=M.scene)==null||b.traverse(y=>{const g=y.userData.id||y.userData._sourceUuid||y.uuid,C=t[g];if(C&&y.userData.isMovable){Go(y);const w=new qe({title:C.title,items:C.items});w.attachTo(y),w.visible=!1,C.width&&w.setWidth(C.width),C.fontSize&&w.setFontSize(C.fontSize),C.offsetY!==void 0&&w.setOffsetY(C.offsetY),C.offsetX!==void 0&&w.setOffsetX(C.offsetX),C.offsetZ!==void 0&&w.setOffsetZ(C.offsetZ),Hn(y,w)}})),s&&s.length>0&&Promise.resolve().then(()=>fr).then(({addWater:y,addWaterCylinder:g})=>{for(const C of s){const w=C.geometryType||"box";let p;w==="cylinder"?p=g({radiusTop:C.cylinderRadiusTop??5,radiusBottom:C.cylinderRadiusBottom??5,radialSegments:C.cylinderRadialSegments??32,height:.8,color:C.color,scale:4}):p=y({width:C.boxWidth??10,height:C.boxDepth??10,color:C.color,scale:4}),p.position.fromArray(C.position),p.rotation.set(C.rotation[0],C.rotation[1],C.rotation[2]),p.scale.fromArray(C.scale),p.name=C.name,p.userData.waterTimeScale=C.timeScale??.05,p.userData.isWater=!0,p.userData.isMovable=!0,C.alpha!==void 0&&p.material.uniforms&&p.material.uniforms.alpha&&(p.material.uniforms.alpha.value=C.alpha),Ye=!0}ns()}),n){const y=new S.TextureLoader;(A=M.scene)==null||A.traverse(g=>{if(g.type==="Mesh"){const C=g,w=Array.isArray(C.material)?C.material:[C.material];for(const p of w)if(p&&p.uuid&&n[p.uuid]){const m=n[p.uuid];if(m.mapDataUrl){const v=y.load(m.mapDataUrl);v.wrapS=v.wrapT=S.RepeatWrapping,v.repeat.set(1,1),p.map=v,p.userData=p.userData||{},p.userData._mapDataUrl=m.mapDataUrl,p.userData._mapFileName=m.mapFileName}if(m.normalMapDataUrl){const v=y.load(m.normalMapDataUrl);v.wrapS=v.wrapT=S.RepeatWrapping,v.repeat.set(1,1),p.normalMap=v,p.normalScale=new S.Vector2(m.normalScale??1,m.normalScale??1),p.userData=p.userData||{},p.userData._normalMapDataUrl=m.normalMapDataUrl,p.userData._normalMapFileName=m.normalMapFileName}if(m.aoMapDataUrl){const v=y.load(m.aoMapDataUrl);v.wrapS=v.wrapT=S.RepeatWrapping,v.repeat.set(1,1),p.aoMap=v,p.aoMapIntensity=m.aoMapIntensity??1,p.userData=p.userData||{},p.userData._aoMapDataUrl=m.aoMapDataUrl,p.userData._aoMapFileName=m.aoMapFileName}p.needsUpdate=!0}}})}o&&vo(o),e==="edit"&&((x=M.scene)==null||x.traverse(y=>{var g,C;if(y.type==="DirectionalLight"){const w=y;if(!w.userData.helper){w.target.parent!==M.scene&&(w.target.parent&&w.target.parent.remove(w.target),w.target.position.set(0,0,0),(g=M.scene)==null||g.add(w.target));const p=new S.DirectionalLightHelper(w,1);p.userData.type="lightHelper",w.userData.helper=p,p.update(),(C=M.scene)==null||C.add(p)}}}))}function hs(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)hs(t)}function fs(){ct!==null&&(cancelAnimationFrame(ct),ct=null),We&&M.container&&(M.container.removeEventListener("click",We),We=null),Xe&&(window.removeEventListener("resize",Xe),Xe=null),M.orbitControls&&(M.orbitControls.dispose(),M.orbitControls=null),M.transformControls&&(M.transformControls.dispose(),M.transformControls=null),we&&(we.dispose(),we=null),M.scene&&(hs(M.scene),M.scene=null),M.renderer&&(M.renderer.dispose(),M.renderer.domElement&&M.container&&M.container.removeChild(M.renderer.domElement),M.renderer=null),Un(),M.camera=null,M.gridHelper=null,M.selectedObject=null,M.container=null,M.mode="",M.defaultMainCamera=null,Ke=void 0,ve=[],Pe.clear(),mt(),Eo(),at=!1,Re=!1}const ir=/^[og]\s*(.+)?/,or=/^mtllib /,rr=/^usemtl /,ar=/^usemap /,On=/\s+/,Rn=new c.Vector3,Tt=new c.Vector3,Pn=new c.Vector3,Ln=new c.Vector3,ce=new c.Vector3,it=new c.Color;function lr(){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;Rn.fromArray(n,e),Tt.fromArray(n,t),Pn.fromArray(n,s),ce.subVectors(Pn,Tt),Ln.subVectors(Rn,Tt),ce.cross(Ln),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 f=this.vertices.length;let h=this.parseVertexIndex(e,f),b=this.parseVertexIndex(t,f),A=this.parseVertexIndex(s,f);if(this.addVertex(h,b,A),this.addColor(h,b,A),l!==void 0&&l!==""){const x=this.normals.length;h=this.parseNormalIndex(l,x),b=this.parseNormalIndex(u,x),A=this.parseNormalIndex(d,x),this.addNormal(h,b,A)}else this.addFaceNormal(h,b,A);if(n!==void 0&&n!==""){const x=this.uvs.length;h=this.parseUVIndex(n,x),b=this.parseUVIndex(i,x),A=this.parseUVIndex(o,x),this.addUV(h,b,A),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 lr;e.indexOf(`\r
141
141
  `)!==-1&&(e=e.replace(/\r\n/g,`
142
142
  `)),e.indexOf(`\\
143
143
  `)!==-1&&(e=e.replace(/\\\n/g,""));const s=e.split(`