var fe=Object.defineProperty;var be=(i,e,t)=>e in i?fe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var v=(i,e,t)=>(be(i,typeof e!="symbol"?e+"":e,t),t);import{aN as ye,e8 as ge,ao as $,bo as Y,$ as J,a9 as Q,O as Z,bQ as ee,ap as te,aU as q,aV as we,aC as w,b6 as ie,aJ as N,aF as H,bw as xe,cH as ve,aW as Me,e as P,cF as Ce,aI as Se,aX as _e,_ as Re,j as Be,an as U,a0 as C,p as D,C as j,a$ as B,x as Te,n as Oe,o as Ae,c2 as De,B as je,q as Ee,b3 as X,b4 as ne,e9 as Ue,ea as ae,eb as Ie}from"./index-a76b28be.js";import{H as re}from"./enum-58295f88.js";import{u as Pe}from"./index-4d966268.js";import"./postmen-a4b10828.js";import{e as se}from"./encode-ac4bb64e.js";import"./meshopt_simplifier.module-cd99529d.js";import{T as Le}from"./Tooltip-1d89ba5a.js";import{A as Fe}from"./AssetViewer-06848056.js";import{k as G}from"./ktx2-encoder-f09e14bc.js";/**
 * @license @tabler/icons-react v3.24.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Ve=ye("filled","help-circle-filled","IconHelpCircleFilled",[["path",{d:"M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm0 13a1 1 0 0 0 -.993 .883l-.007 .117l.007 .127a1 1 0 0 0 1.986 0l.007 -.117l-.007 -.127a1 1 0 0 0 -.993 -.883zm1.368 -6.673a2.98 2.98 0 0 0 -3.631 .728a1 1 0 0 0 1.44 1.383l.171 -.18a.98 .98 0 0 1 1.11 -.15a1 1 0 0 1 -.34 1.886l-.232 .012a1 1 0 0 0 .111 1.994a3 3 0 0 0 1.371 -5.673z",key:"svg-0"}]]);const K=function(i,e,t){return i>=t?t:i<=e?e:i};function oe(i,e,t,n,a){const r=new Uint8Array(i);n=K(n,0,255),a=K(a,0,255);const s=(d,p)=>(p*e+d)*4,o=[[-1,0],[1,0],[0,-1],[0,1]],l=[];for(let d=0;d<t;d++)for(let p=0;p<e;p++)if(r[s(p,d)+3]!==0)for(const[y,b]of o){const h=p+y,m=d+b;if(h>=0&&h<e&&m>=0&&m<t&&r[s(h,m)+3]===0){l.push([p,d]);break}}const c=new Set,u=[];for(;l.length>0;){const d=[];for(const[p,y]of l)for(const[b,h]of o){const m=p+b,f=y+h;if(m<0||m>=e||f<0||f>=t)continue;const x=s(m,f);if(r[x+3]>n)continue;const g=f*e+m;if(c.has(g))continue;c.add(g);const S=s(p,y);r[x]=r[S],r[x+1]=r[S+1],r[x+2]=r[S+2],r[x+3]=255,d.push([m,f]),u.push(x)}l.length=0;for(let p=0;p<d.length;p++)l.push(d[p])}for(const d of u)r[d+3]=a;return r}async function le(i,e={range:10,alpha:0}){return typeof document<"u"?He(i,e):Ge(i,e)}async function He(i,e){const t=URL.createObjectURL(new Blob([i])),n=await new Promise((l,c)=>{const u=new Image;u.crossOrigin="*",u.onload=()=>l(u),u.onerror=c,u.src=t});URL.revokeObjectURL(t);const a=document.createElement("canvas");a.width=n.width,a.height=n.height;const r=a.getContext("2d");if(!r)return null;r.drawImage(n,0,0);const s=r.getImageData(0,0,n.width,n.height),o=oe(new Uint8Array(s.data.buffer),n.width,n.height,e.range,e.alpha);return r.putImageData(new ImageData(new Uint8ClampedArray(o),n.width,n.height),0,0),new Promise(l=>{a.toBlob(c=>l(c))})}async function Ge(i,e){const t=(await ge(()=>import("./index-ba5b96da.js").then(o=>o.i),["_static/index-ba5b96da.js","_static/index-a76b28be.js"])).default,{data:n,info:a}=await t(Buffer.from(i)).ensureAlpha().raw().toBuffer({resolveWithObject:!0}),r=oe(new Uint8Array(n.buffer,n.byteOffset,n.byteLength),a.width,a.height,e.range,e.alpha),s=await t(Buffer.from(r),{raw:{width:a.width,height:a.height,channels:4}}).png().toBuffer();return new Blob([new Uint8Array(s)])}function L(i){const e=i instanceof Uint8Array?i:new Uint8Array(i);return e[0]===35&&e[1]===63}function k(i,e){const t=new Float32Array(1),n=new Uint32Array(t.buffer);for(let a=0;a<i.length;a++){t[0]=i[a];const r=n[0],s=r>>16&32768,o=(r>>23&255)-127+15,l=r&8388607;o<=0?e[a]=s:o>=31?e[a]=s|31744:e[a]=s|o<<10|l>>13}}function F(i){const e=Ne(i),{width:t,height:n,dataPosition:a}=e,r=ze(i.subarray(a),t,n),s=ke(r,t,n);return{width:t,height:n,pixels:s}}function ke(i,e,t){const n=e*t,a=new Float32Array(n*4);for(let r=0;r<n;r++){const s=r*4,o=r*4,l=Math.pow(2,i[s+3]-128-8);a[o]=Math.min(i[s]*l,65504),a[o+1]=Math.min(i[s+1]*l,65504),a[o+2]=Math.min(i[s+2]*l,65504),a[o+3]=1}return a}function Ne(i){let e=z(i,0);if(e[0]!=="#"||e[1]!=="?")throw new Error("HDR: invalid header");let t=0,n=!1,a=!1;do t+=e.length+1,e=z(i,t),e==="FORMAT=32-bit_rle_rgbe"?n=!0:e.length===0&&(a=!0);while(!a);if(!n)throw new Error("HDR: unsupported format");t+=e.length+1,e=z(i,t);const r=/^\-Y (.*) \+X (.*)$/g.exec(e);if(!r||r.length<3)throw new Error("HDR: missing size");return{width:parseInt(r[2]),height:parseInt(r[1]),dataPosition:t+e.length+1}}function ze(i,e,t){const n=i.byteLength,a=new Uint8Array(4*e*t);let r=0,s=0;const o=4*e,l=new Uint8Array(o);let c=t;for(;c>0&&s<n;){const u=i[s++],d=i[s++],p=i[s++],y=i[s++];if(u!==2||d!==2||p&128||e<8||e>32767)return i;if((p<<8|y)!==e)throw new Error("HDR: wrong scanline width");let b=0;for(;b<o&&s<n;){let h=i[s++];const m=h>128;if(m&&(h-=128),h===0||b+h>o)throw new Error("HDR: bad scanline");if(m){const f=i[s++];for(let x=0;x<h;x++)l[b++]=f}else l.set(i.subarray(s,s+h),b),b+=h,s+=h}for(let h=0;h<e;h++,r+=4)a[r]=l[h],a[r+1]=l[h+e],a[r+2]=l[h+e*2],a[r+3]=l[h+e*3];c--}return a}function z(i,e){let t="";for(let n=e;n<i.length;n++){const a=String.fromCharCode(i[n]);if(a===`
`)break;t+=a}return t}function $e(i,e,t){if(i.length!==e*t*4)throw new Error(`HDREncoder: pixel count mismatch (expected ${e*t*4}, got ${i.length})`);const n=qe(e,t),a=Xe(i,e,t),r=new Uint8Array(n.length+a.length);return r.set(n,0),r.set(a,n.length),r.buffer}function qe(i,e){const t=`#?RADIANCE
# Written by Galacean HDREncoder
FORMAT=32-bit_rle_rgbe

-Y ${e} +X ${i}
`;return new TextEncoder().encode(t)}function Xe(i,e,t){const n=t*(4+4*e*2),a=new Uint8Array(n);let r=0;const s=new Uint8Array(4*e);for(let o=0;o<t;o++){Ke(i,o*e*4,e,s),a[r++]=2,a[r++]=2,a[r++]=e>>8&255,a[r++]=e&255;for(let l=0;l<4;l++)r=We(s,l,e,a,r)}return a.subarray(0,r)}function Ke(i,e,t,n){for(let a=0;a<t;a++){const r=e+a*4,s=a*4,o=i[r],l=i[r+1],c=i[r+2],u=Math.max(o,l,c);if(u<1e-32)n[s]=0,n[s+1]=0,n[s+2]=0,n[s+3]=0;else{const d=Math.ceil(Math.log2(u)),p=256/Math.pow(2,d);n[s]=Math.min(255,Math.max(0,Math.round(o*p))),n[s+1]=Math.min(255,Math.max(0,Math.round(l*p))),n[s+2]=Math.min(255,Math.max(0,Math.round(c*p))),n[s+3]=d+128}}}function We(i,e,t,n,a){let r=0;for(;r<t;){const s=r,o=i[r*4+e];let l=1;for(;r+l<t&&l<127&&i[(r+l)*4+e]===o;)l++;if(l>=4)n[a++]=128+l,n[a++]=o,r+=l;else{let c=1;for(r=s;r+c<t&&c<128;){const u=i[(r+c)*4+e];let d=1;for(;r+c+d<t&&d<4&&i[(r+c+d)*4+e]===u;)d++;if(d>=4)break;c++}n[a++]=c;for(let u=0;u<c;u++)n[a++]=i[(r+u)*4+e];r+=c}}return a}const Ye=[[1,-1,-1,1,-1,1,1,1,-1,1,1,1],[-1,-1,1,-1,-1,-1,-1,1,1,-1,1,-1],[-1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1],[-1,1,-1,1,1,-1,-1,1,1,1,1,1],[-1,-1,-1,1,-1,-1,-1,1,-1,1,1,-1],[1,-1,1,-1,-1,1,1,1,1,-1,1,1]];function ce(i,e,t,n){const a=n??t>>1,r=[];for(let s=0;s<6;s++){const o=Ye[s],l=new Float32Array(a*a*4);Je(i,e,t,o,a,l),r.push(l)}return{faceSize:a,faces:r}}function Je(i,e,t,n,a,r){const s=1/a,o=(n[3]-n[0])*s,l=(n[4]-n[1])*s,c=(n[5]-n[2])*s,u=(n[9]-n[6])*s,d=(n[10]-n[7])*s,p=(n[11]-n[8])*s;let y=0;for(let b=0;b<a;b++){let h=n[0],m=n[1],f=n[2],x=n[6],g=n[7],S=n[8];for(let T=0;T<a;T++){let O=h+(x-h)*y,A=m+(g-m)*y,I=f+(S-f)*y;const R=1/Math.sqrt(O*O+A*A+I*I);O*=R,A*=R,I*=R;const de=Math.atan2(O,I)/Math.PI*.5+.5,he=Math.acos(A)/Math.PI,me=(b*a+T)*4;Qe(i,e,t,de,he,r,me),h+=o,m+=l,f+=c,x+=u,g+=d,S+=p}y+=s}}function Qe(i,e,t,n,a,r,s){const o=n*e-.5,l=(1-a)*t-.5,c=Math.floor(o),u=Math.floor(l),d=o-c,p=l-u,y=(c%e+e)%e,b=((c+1)%e+e)%e,h=Math.max(0,Math.min(u,t-1)),m=Math.max(0,Math.min(u+1,t-1)),f=(h*e+y)*4,x=(h*e+b)*4,g=(m*e+y)*4,S=(m*e+b)*4,T=(1-d)*(1-p),O=d*(1-p),A=(1-d)*p,I=d*p;for(let R=0;R<4;R++)r[s+R]=i[f+R]*T+i[x+R]*O+i[g+R]*A+i[S+R]*I}$.create("editor-cube-preview",`
  attribute vec3 POSITION;
  attribute vec3 NORMAL;

  uniform mat4 renderer_MVPMat;
  uniform vec3 camera_Position;
  uniform mat4 renderer_ModelMat;
  varying vec3 v_reflectDir;

  void main(){
    gl_Position = renderer_MVPMat * vec4(POSITION, 1.0);
    // All in object space, same as Unity's PreviewCubemap.shader
    mat4 worldToModel = inverse(renderer_ModelMat);
    vec3 objSpaceCameraPos = (worldToModel * vec4(camera_Position, 1.0)).xyz;
    vec3 objSpaceViewDir = -normalize(objSpaceCameraPos - POSITION);
    v_reflectDir = reflect(objSpaceViewDir, NORMAL);
  }
`,`
  varying vec3 v_reflectDir;
  uniform samplerCube u_cubeTexture;

  void main(){
    gl_FragColor = textureCube(u_cubeTexture, normalize(v_reflectDir));
  }
  `);class E{static update(e,t){t.shape===V.Cube?this.updateCube(e,t):this.update2D(e,t)}static clear(){this.spriteEntity&&(this.spriteEntity.isActive=!1),this.cubeEntity&&(this.cubeEntity.isActive=!1)}static update2D(e,t){this.cubeEntity&&(this.cubeEntity.isActive=!1),this.spriteEntity?this.spriteEntity.isActive=!0:this.init2DScene(e),this.entity=this.spriteEntity,this.sprite.texture=t.engineObject}static updateCube(e,t){this.spriteEntity&&(this.spriteEntity.isActive=!1),this.cubeEntity?this.cubeEntity.isActive=!0:this.initCubeScene(e),this.entity=this.cubeEntity,this.cubeMaterial.shaderData.setTexture(Y.getByName("u_cubeTexture"),t.engineObject)}static init2DScene(e){const t=this.spriteEntity=e.createChild("sprite");this.spriteRenderer=t.addComponent(J),this.spriteRenderer.sprite=this.sprite=new Q(e.engine)}static initCubeScene(e){const{engine:t}=e,a=(this.cubeEntity=e.createChild("cube-preview-sphere")).addComponent(Z);a.mesh=ee.createSphere(t,.5,32),this.cubeMaterial=new te(t,$.find("editor-cube-preview")),a.setMaterial(this.cubeMaterial)}}v(E,"entity"),v(E,"spriteEntity"),v(E,"spriteRenderer"),v(E,"sprite"),v(E,"cubeEntity"),v(E,"cubeMaterial");const Ze=q(function(i){const{t:e}=we(),t=i.encodeOptions,n=i.isHDR;return w.jsxs(w.Fragment,{children:[w.jsx(ie,{formStartSlot:w.jsx(N,{css:{marginLeft:"$4"}}),label:e("asset.ktx2.mode.label"),formEndSlot:w.jsx(Le,{content:w.jsxs(N,{direction:"column",children:[w.jsx(H,{size:"1",weight:"medium",children:e("asset.ktx2.mode.uastc.label")}),w.jsx(H,{size:"1",muted:!0,children:e("asset.ktx2.mode.uastc.desc")}),w.jsx(xe,{css:{margin:"$1 0"}}),w.jsx(H,{size:"1",weight:"medium",children:e("asset.ktx2.mode.etc1s.label")}),w.jsx(H,{size:"1",muted:!0,children:e("asset.ktx2.mode.etc1s.desc")})]}),children:w.jsx(Ve,{size:"18px"})}),value:n?"UASTC":t.mode,disabled:i.disabled||n,onChange:a=>{t.mode=a,i.onChange&&i.onChange(),Tracert.click("c351684.d417985",{type:a})},options:[{label:e("asset.ktx2.mode.uastc.label"),value:"UASTC"},{label:e("asset.ktx2.mode.etc1s.label"),value:"ETC1S"}]}),!n&&t.mode==="ETC1S"?w.jsx(ve,{formStartSlot:w.jsx(N,{css:{marginLeft:"$8"}}),disabled:i.disabled,label:e("asset.ktx2.quality"),min:0,max:255,step:1,value:t.quality,onChange:a=>{t.quality=Math.floor(a),i.onChange&&i.onChange()}}):null]})}),et=q(({textureOptions:i,onChange:e,disabled:t,isHDR:n})=>w.jsx(w.Fragment,{children:w.jsxs(Me,{defaultOpen:!0,title:P("texture.bundle.format-options"),children:[w.jsx(Ce,{label:P("texture.bundle.overwrite"),disabled:t,value:i.overwrite,onChange:a=>{i.overwrite=a,e&&e()}}),w.jsx(ie,{label:P("texture.bundle.texture-compression"),value:i.textureType,disabled:!i.overwrite||t,onChange:a=>{i.textureType=a,e&&e()},options:[{label:P("texture.bundle.type.ktx2"),value:"ktx2"},{label:P("texture.bundle.type.original"),value:"original"}]}),i.textureType==="ktx2"?w.jsx(Ze,{labelFirst:!1,onChange:e,disabled:!i.overwrite||t,encodeOptions:i,isHDR:n}):null]})})),tt=new Set(["colorDilate"]),it=new Set(["isSRGBColorSpace","mipmap","filterMode","wrapModeU","wrapModeV","anisoLevel"]),nt=q(i=>{var l;const e=i.asset,{inspectorFacade:t}=Pe(),n=e.runtimeOptions,a=!e.getEditable(),r=e instanceof M&&e.shape===V.Cube,s=e instanceof M&&((l=e.name)==null?void 0:l.endsWith(".hdr")),o=Se.useMemo(()=>{let c=e.formSchema.items;return e.isSubAsset?c=c.filter(u=>it.has(u.property)):r&&(c=c.filter(u=>!tt.has(u.property))),s&&(c=c.map(u=>u.property==="isSRGBColorSpace"?{...u,disabled:!0}:u)),c},[r,s,e.isSubAsset,e.formSchema.items]);return w.jsxs(w.Fragment,{children:[w.jsx(_e.List,{model:e,configs:o,onModelChange:(c,u)=>{t.assetChange(e.id,c,u)}}),!e.isSubAsset&&w.jsx(et,{onChange:()=>{t.assetChange(e.id,"runtimeOptions",{...n},"asset-meta")},textureOptions:n,disabled:a,isHDR:s})]})});class at extends Fe{constructor(){super(...arguments);v(this,"_asset");v(this,"_rootEntity");v(this,"_onRebuild",()=>{var t;this._entity&&(this._entity.destroy(),this._entity=null),this._rebuild(),(t=this._requestResetCamera)==null||t.call(this)})}setViewAsset(t,n){this._asset=t,this._rootEntity=n,this._rebuild(),t.addPropertyChangeListener("engineObjectReady",this._onRebuild)}stopViewAsset(){var t;(t=this._asset)==null||t.removePropertyChangeListener("engineObjectReady",this._onRebuild),super.stopViewAsset(),this._asset=null,this._rootEntity=null}getDescription(t){return`${t.width}x${t.height}`}_rebuild(){const{_asset:t,_rootEntity:n}=this;!t||!n||!t.engineObject||t.engineObject.destroyed||(t.shape===V.Cube?this._buildCubePreview(n,t):this._build2DPreview(n,t))}_buildCubePreview(t,n){const a=t.engine,r=new Re(a,"cube-preview-sphere"),s=r.addComponent(Z);s.mesh=ee.createSphere(a,1,32);const o=new te(a,$.find("editor-cube-preview"));s.setMaterial(o),o.shaderData.setTexture(Y.getByName("u_cubeTexture"),n.engineObject),t.addChild(r),this._entity=r}_build2DPreview(t,n){const a=t.createChild("texture-preview"),r=a.addComponent(J);r.sprite=new Q(t.engine,n.engineObject),this._entity=a}}var rt=Object.defineProperty,st=Object.getOwnPropertyDescriptor,_=(i,e,t,n)=>{for(var a=n>1?void 0:n?st(e,t):e,r=i.length-1,s;r>=0;r--)(s=i[r])&&(a=(n?s(e,t,a):s(a))||a);return n&&a&&rt(e,t,a),a},V=(i=>(i["2D"]="2D",i.Cube="Cube",i))(V||{}),ue=(i=>(i[i.Default=0]="Default",i[i.Sprite=1]="Sprite",i))(ue||{});function ot(i){const{pixels:e,width:t,height:n}=F(new Uint8Array(i)),a=new Uint16Array(e.length);return k(e,a),{input:a.buffer,options:{isUASTC:!0,isHDR:!0,imageType:re.RGBAHalfFloat,width:t,height:n}}}function pe(i){return createImageBitmap(i,{premultiplyAlpha:"none"}).then(e=>{const n=new OffscreenCanvas(e.width,e.height).getContext("2d");n.drawImage(e,0,0);const a=n.getImageData(0,0,e.width,e.height),r=new Float32Array(a.data.length);for(let s=0;s<a.data.length;s++)r[s]=a.data[s]/255;return{pixels:r,width:e.width,height:e.height}})}async function lt(i,e,t,n,a){if(L(e)){const{pixels:r,width:s,height:o}=F(new Uint8Array(e)),l=new Uint16Array(r.length);k(r,l);const c=new X(i,s,o,ne.R16G16B16A16,t,!1);return c.name=a,c.setPixelBuffer(l),t&&c.generateMipmaps(),{texture:c,width:s,height:o}}else{const r=await createImageBitmap(new Blob([e]),{premultiplyAlpha:"none"}),s=new X(i,r.width,r.height,void 0,t,n);return s.name=a,s.setImageSource(r),t&&s.generateMipmaps(),{texture:s,width:r.width,height:r.height}}}async function ct(i,e,t,n,a){const r=L(e),{pixels:s,width:o,height:l}=r?F(new Uint8Array(e)):await pe(new Blob([e])),{faceSize:c,faces:u}=ce(s,o,l),d=r?ne.R16G16B16A16:void 0,p=new Ue(i,c,d,t,!r&&n);p.name=a;for(let y=0;y<6;y++)if(r){const b=new Uint16Array(c*c*4);k(u[y],b),p.setPixelBuffer(y,b,0)}else{const b=new OffscreenCanvas(c,c),h=b.getContext("2d"),m=h.createImageData(c,c),f=u[y];for(let g=0;g<f.length;g++)m.data[g]=Math.round(Math.min(1,Math.max(0,f[g]))*255);h.putImageData(m,0,0);const x=await createImageBitmap(b);p.setImageSource(y,x)}return t&&p.generateMipmaps(),{texture:p,faceSize:c}}async function ut({content:i,meta:e,name:t,path:n},a){let r=await i.arrayBuffer();const s=e.runtimeOptions;let o=a.assetOptions.textureOptions;s!=null&&s.overwrite&&(o=Object.assign({},a.assetOptions.textureOptions,s)),e.colorDilate&&(r=await(await le(r,{range:4,alpha:2})).arrayBuffer());const l=e.filterMode??U.Bilinear,c=e.wrapModeU??C.Repeat,u=e.wrapModeV??C.Repeat,d=e.anisoLevel??1,p=e.mipmap??!0,y=e.isSRGBColorSpace??!0,b=L(r);if(o.textureType==="ktx2")try{const{input:f,options:x}=b?ot(r):{input:r,options:{isUASTC:o.mode==="UASTC",qualityLevel:o.quality}};let g=await G.encode(f,{...x,generateMipmap:p,isSetKTX2SRGBTransferFunc:!b&&y});return g=G.setTextureParams(g,{wrapModeU:c,wrapModeV:u,filterMode:l,anisoLevel:d}),{name:ae(t,".ktx2"),type:"KTX2",content:new Blob([g],{type:"image/ktx2"})}}catch(f){console.error(f),console.error("downgrade to uncompressed texture")}let h,m;if(b){const f=F(new Uint8Array(r));h=f.width,m=f.height}else{const f=URL.createObjectURL(i);try{const x=await Ie(f);h=x.width,m=x.height}finally{URL.revokeObjectURL(f)}}return{type:"Texture",content:new Blob([se(r,{type:"Texture2D",name:t,width:h,height:m,mipmap:Number(p),isSRGBColorSpace:Number(b?0:y),filterMode:l,wrapModeU:c,wrapModeV:u,anisoLevel:d,format:b?7:e.format,url:n})])}}async function W(i,e){return Promise.all(i.map(async t=>{const n=new OffscreenCanvas(e,e),a=n.getContext("2d"),r=a.createImageData(e,e);for(let o=0;o<t.length;o++)r.data[o]=Math.round(Math.min(1,Math.max(0,t[o]))*255);return a.putImageData(r,0,0),(await n.convertToBlob({type:"image/png"})).arrayBuffer()}))}async function pt({content:i,meta:e,name:t},n){const a=e.runtimeOptions;let r=n.assetOptions.textureOptions;a!=null&&a.overwrite&&(r=Object.assign({},r,a));const s=e.filterMode??U.Bilinear,o=e.wrapModeU??C.Clamp,l=e.wrapModeV??C.Clamp,c=e.anisoLevel??1,u=e.mipmap??!0,d=await i.arrayBuffer(),p=L(d),{pixels:y,width:b,height:h}=p?F(new Uint8Array(d)):await pe(i),{faceSize:m,faces:f}=ce(y,b,h);if(r.textureType==="ktx2")try{let g,S;p?(g=f.map(O=>{const A=new Uint16Array(O.length);return k(O,A),A.buffer}),S={isUASTC:!0,isHDR:!0,imageType:re.RGBAHalfFloat,width:m,height:m}):(g=await W(f,m),S={isUASTC:r.mode==="UASTC",qualityLevel:r.quality});let T=await G.encode(g,{...S,generateMipmap:u,isSetKTX2SRGBTransferFunc:!p});return T=G.setTextureParams(T,{wrapModeU:o,wrapModeV:l,filterMode:s,anisoLevel:c}),{name:ae(t,".ktx2"),type:"KTX2",content:new Blob([T],{type:"image/ktx2"})}}catch(g){console.error(g),console.error("Cube: downgrade to uncompressed texture")}const x=p?f.map(g=>$e(g,m,m)):await W(f,m);return{type:"Texture",content:new Blob([se(x,{type:"TextureCube",name:t,faceSize:m,mipmap:Number(u),filterMode:s,anisoLevel:c,wrapModeU:o,wrapModeV:l,isSRGBColorSpace:Number(e.isSRGBColorSpace??0)})])}}let M=class extends Be{constructor(){super(...arguments);v(this,"shape","2D");v(this,"isSRGBColorSpace",!0);v(this,"mipmap",!0);v(this,"filterMode",U.Bilinear);v(this,"wrapModeU",C.Repeat);v(this,"wrapModeV",C.Repeat);v(this,"anisoLevel",1);v(this,"width",0);v(this,"height",0);v(this,"colorDilate",!1);v(this,"runtimeOptions",{overwrite:!1,textureType:"ktx2",mode:"ETC1S",quality:150,isNormal:!1});v(this,"_imageBuffer")}get imageBuffer(){return this._imageBuffer}beforeDelete(){}afterDelete(){var e;(e=this.engineObject)==null||e.destroy(!0)}setTextureType(e){e===1&&(this.wrapModeU=this.wrapModeV=C.Clamp,this.mipmap=!1,this.root.assetFacade.updateAssetMeta(this.id,{wrapModeU:this.wrapModeU,wrapModeV:this.wrapModeV,mipmap:this.mipmap}))}async initByEngineObject(e){this.bindEngineObject(e),this.filterMode=e.filterMode,this.wrapModeU=e.wrapModeU,this.wrapModeV=e.wrapModeV,this.anisoLevel=e.anisoLevel,this.width=e.width,this.height=e.height,this.mipmap=e._mipmap,this.isSRGBColorSpace=e.isSRGBColorSpace,this._name=e.name}async initByMain(e){const{meta:t}=this;this._imageBuffer=await e.arrayBuffer(),t.runtimeOptions&&(this.runtimeOptions=t.runtimeOptions),this.shape=t.shape??this.shape,this.filterMode=t.filterMode??this.filterMode,this.anisoLevel=t.anisoLevel??this.anisoLevel,this.wrapModeU=t.wrapModeU??this.wrapModeU,this.wrapModeV=t.wrapModeV??this.wrapModeV,this.colorDilate=t.colorDilate??this.colorDilate,this.mipmap=t.mipmap??this.mipmap,this.isSRGBColorSpace=t.isSRGBColorSpace??this.isSRGBColorSpace,await this._rebuildEngineObject()}async updateEngineObject(){var e;(e=this.engineObject)==null||e.destroy(),await this._rebuildEngineObject(),this.triggerPropertyChange("engineObjectReady",!1)}async updateTextureImageSource(e){const t=await createImageBitmap(new Blob([e]),{premultiplyAlpha:"none"});this.engineObject.setImageSource(t),this.mipmap&&this.engineObject.generateMipmaps()}async onShapeChanged(e){const t=this.engineObject;await this._rebuildEngineObject(),t==null||t.destroy(!0),await this.root.assetFacade.updateAssetMeta(this.id,{shape:e}),this.updateThumbnail(),this.triggerPropertyChange("engineObjectReady",!1)}async _rebuildEngineObject(){if(this.shape==="Cube"){const{texture:e,faceSize:t}=await ct(this.engine,this._imageBuffer,this.mipmap,this.isSRGBColorSpace,this.name);this.width=t,this.height=t,this.bindEngineObject(e)}else{const{texture:e,width:t,height:n}=await lt(this.engine,this._imageBuffer,this.mipmap,this.isSRGBColorSpace,this.name);this.width=t,this.height=n,this.bindEngineObject(e)}}};_([D({label:"texture.shape.title",type:j.Select,onChange:async(i,e,t)=>{i.isInitCompleted&&await i.onShapeChanged(t)},options:[{label:"2D",value:"2D"},{label:"Cube",value:"Cube"}]}),B()],M.prototype,"shape",2);_([D({label:"texture.sRGB.title",type:j.Toggle,onChange:async(i,e,t)=>{var n;i.isInitCompleted&&i.shape==="2D"&&(i.isSubAsset?await((n=i.mainAsset)==null?void 0:n._rebuild()):await i.updateEngineObject())}}),B()],M.prototype,"isSRGBColorSpace",2);_([D({label:"texture.mipmap.title",type:j.Toggle,onChange:async(i,e,t)=>{var n;i.isInitCompleted&&(i.isSubAsset?await((n=i.mainAsset)==null?void 0:n._rebuild()):await i.updateEngineObject())}}),B()],M.prototype,"mipmap",2);_([D({label:"texture.filter-mode.title",type:j.Select,value:U.Bilinear,bindPath:"filterMode",options:[{label:"texture.filter-mode.point",value:U.Point},{label:"texture.filter-mode.bilinear",value:U.Bilinear},{label:"texture.filter-mode.trilinear",value:U.Trilinear}]}),B()],M.prototype,"filterMode",2);_([D({label:"texture.wrap-mode.u.title",type:j.Select,bindPath:"wrapModeU",options:[{label:"texture.wrap-mode.clamp",value:C.Clamp},{label:"texture.wrap-mode.repeat",value:C.Repeat},{label:"texture.wrap-mode.mirror",value:C.Mirror}]}),B()],M.prototype,"wrapModeU",2);_([D({label:"texture.wrap-mode.v.title",type:j.Select,bindPath:"wrapModeV",options:[{label:"texture.wrap-mode.clamp",value:C.Clamp},{label:"texture.wrap-mode.repeat",value:C.Repeat},{label:"texture.wrap-mode.mirror",value:C.Mirror}]}),B()],M.prototype,"wrapModeV",2);_([D({label:"texture.aniso-level.title",type:j.Slider,dragStep:1,max:16,min:1,bindPath:"anisoLevel"}),B()],M.prototype,"anisoLevel",2);_([B()],M.prototype,"width",2);_([B()],M.prototype,"height",2);_([D({label:"texture.dilate.title",info:"texture.dilate.info",type:j.Toggle}),B()],M.prototype,"colorDilate",2);_([Te,B()],M.prototype,"runtimeOptions",2);M=_([Oe({type:"Texture",label:P("asset.texture.title"),loaderType:"Texture",importMenuConfig:{type:Ae.Upload,accept:".png,.jpg,.jpeg,.webp,.hdr",multiple:!0},preUpload:async i=>{const e=De(i.main,"texture.bin"),t=await e.arrayBuffer();return L(t)?{main:e,meta:JSON.stringify({isSRGBColorSpace:!1})}:e},viewer:at,thumbnail:E,extname:"tex",icon:{bgSolidColor:new je(0,0,0,0)},dragLayer:Ee.Texture,customInspector:nt,async preInitialize({main:i,meta:e,name:t}){if(e.colorDilate){const n=await i.arrayBuffer(),a=await le(n,{range:4,alpha:2});return new File([a],t,{type:"Texture"})}return i},async bundle({content:i,meta:e,name:t,path:n},a){return e.shape==="Cube"?pt({content:i,meta:e,name:t},a):ut({content:i,meta:e,name:t,path:n},a)}})],M);const Mt=Object.freeze(Object.defineProperty({__proto__:null,get TextureAsset(){return M},TextureShape:V,TextureUseType:ue},Symbol.toStringTag,{value:"Module"}));export{Ze as K,V as T,ue as a,M as b,nt as c,Mt as d};
