endset_three_editor 0.10.25 → 0.10.27

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