var me=Object.defineProperty;var fe=(n,e,t)=>e in n?me(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var v=(n,e,t)=>(fe(n,typeof e!="symbol"?e+"":e,t),t);import{ae as V,b1 as Y,N as J,$ as Z,y as Q,bD as ee,ah as te,aJ as q,aK as be,av as w,bk as ne,aI as N,ay as H,bz as ye,cm as ge,aN as we,e as P,dr as xe,aM as ve,aO as Me,K as Se,j as Ce,ad as I,T as S,p as A,C as j,aT as T,x as _e,n as Re,o as Te,bR as De,b3 as Oe,q as Be,a_ as K,a$ as ie,ey as Ae,ez as ae,eA as je}from"./index-03b6134d.js";import{k,H as re}from"./ktx2-encoder-4cac07f2.js";import{u as Ee}from"./index-0a53aaef.js";import"./postmen-9e6354af.js";import{e as se}from"./encode-ac4bb64e.js";import"./meshopt_simplifier.module-cd99529d.js";import{T as Ie}from"./Tooltip-9ce2e9d6.js";import{c as Ue}from"./createReactComponent-fcd6848b.js";import{A as Pe}from"./AssetViewer-1a9f3cad.js";const X=function(n,e,t){return n>=t?t:n<=e?e:n};function Le(n,e,t,i,a){const r=new Uint8Array(n);i=X(i,0,255),a=X(a,0,255);const s=(d,p)=>(p*e+d)*4,c=[[-1,0],[1,0],[0,-1],[0,1]],o=[];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 c){const h=p+y,m=d+b;if(h>=0&&h<e&&m>=0&&m<t&&r[s(h,m)+3]===0){o.push([p,d]);break}}const l=new Set,u=[];for(;o.length>0;){const d=[];for(const[p,y]of o)for(const[b,h]of c){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]>i)continue;const g=f*e+m;if(l.has(g))continue;l.add(g);const C=s(p,y);r[x]=r[C],r[x+1]=r[C+1],r[x+2]=r[C+2],r[x+3]=255,d.push([m,f]),u.push(x)}o.length=0;for(let p=0;p<d.length;p++)o.push(d[p])}for(const d of u)r[d+3]=a;return r}function L(n){const e=n instanceof Uint8Array?n:new Uint8Array(n);return e[0]===35&&e[1]===63}function z(n,e){const t=new Float32Array(1),i=new Uint32Array(t.buffer);for(let a=0;a<n.length;a++){t[0]=n[a];const r=i[0],s=r>>16&32768,c=(r>>23&255)-127+15,o=r&8388607;c<=0?e[a]=s:c>=31?e[a]=s|31744:e[a]=s|c<<10|o>>13}}function F(n){const e=Ge(n),{width:t,height:i,dataPosition:a}=e,r=He(n.subarray(a),t,i),s=Fe(r,t,i);return{width:t,height:i,pixels:s}}function Fe(n,e,t){const i=e*t,a=new Float32Array(i*4);for(let r=0;r<i;r++){const s=r*4,c=r*4,o=Math.pow(2,n[s+3]-128-8);a[c]=Math.min(n[s]*o,65504),a[c+1]=Math.min(n[s+1]*o,65504),a[c+2]=Math.min(n[s+2]*o,65504),a[c+3]=1}return a}function Ge(n){let e=$(n,0);if(e[0]!=="#"||e[1]!=="?")throw new Error("HDR: invalid header");let t=0,i=!1,a=!1;do t+=e.length+1,e=$(n,t),e==="FORMAT=32-bit_rle_rgbe"?i=!0:e.length===0&&(a=!0);while(!a);if(!i)throw new Error("HDR: unsupported format");t+=e.length+1,e=$(n,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 He(n,e,t){const i=n.byteLength,a=new Uint8Array(4*e*t);let r=0,s=0;const c=4*e,o=new Uint8Array(c);let l=t;for(;l>0&&s<i;){const u=n[s++],d=n[s++],p=n[s++],y=n[s++];if(u!==2||d!==2||p&128||e<8||e>32767)return n;if((p<<8|y)!==e)throw new Error("HDR: wrong scanline width");let b=0;for(;b<c&&s<i;){let h=n[s++];const m=h>128;if(m&&(h-=128),h===0||b+h>c)throw new Error("HDR: bad scanline");if(m){const f=n[s++];for(let x=0;x<h;x++)o[b++]=f}else o.set(n.subarray(s,s+h),b),b+=h,s+=h}for(let h=0;h<e;h++,r+=4)a[r]=o[h],a[r+1]=o[h+e],a[r+2]=o[h+e*2],a[r+3]=o[h+e*3];l--}return a}function $(n,e){let t="";for(let i=e;i<n.length;i++){const a=String.fromCharCode(n[i]);if(a===`
`)break;t+=a}return t}function Ve(n,e,t){if(n.length!==e*t*4)throw new Error(`HDREncoder: pixel count mismatch (expected ${e*t*4}, got ${n.length})`);const i=ke(e,t),a=ze(n,e,t),r=new Uint8Array(i.length+a.length);return r.set(i,0),r.set(a,i.length),r.buffer}function ke(n,e){const t=`#?RADIANCE
# Written by Galacean HDREncoder
FORMAT=32-bit_rle_rgbe

-Y ${e} +X ${n}
`;return new TextEncoder().encode(t)}function ze(n,e,t){const i=t*(4+4*e*2),a=new Uint8Array(i);let r=0;const s=new Uint8Array(4*e);for(let c=0;c<t;c++){Ne(n,c*e*4,e,s),a[r++]=2,a[r++]=2,a[r++]=e>>8&255,a[r++]=e&255;for(let o=0;o<4;o++)r=$e(s,o,e,a,r)}return a.subarray(0,r)}function Ne(n,e,t,i){for(let a=0;a<t;a++){const r=e+a*4,s=a*4,c=n[r],o=n[r+1],l=n[r+2],u=Math.max(c,o,l);if(u<1e-32)i[s]=0,i[s+1]=0,i[s+2]=0,i[s+3]=0;else{const d=Math.ceil(Math.log2(u)),p=256/Math.pow(2,d);i[s]=Math.min(255,Math.max(0,Math.round(c*p))),i[s+1]=Math.min(255,Math.max(0,Math.round(o*p))),i[s+2]=Math.min(255,Math.max(0,Math.round(l*p))),i[s+3]=d+128}}}function $e(n,e,t,i,a){let r=0;for(;r<t;){const s=r,c=n[r*4+e];let o=1;for(;r+o<t&&o<127&&n[(r+o)*4+e]===c;)o++;if(o>=4)i[a++]=128+o,i[a++]=c,r+=o;else{let l=1;for(r=s;r+l<t&&l<128;){const u=n[(r+l)*4+e];let d=1;for(;r+l+d<t&&d<4&&n[(r+l+d)*4+e]===u;)d++;if(d>=4)break;l++}i[a++]=l;for(let u=0;u<l;u++)i[a++]=n[(r+u)*4+e];r+=l}}return a}const qe=[[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 oe(n,e,t,i){const a=i??t>>1,r=[];for(let s=0;s<6;s++){const c=qe[s],o=new Float32Array(a*a*4);Ke(n,e,t,c,a,o),r.push(o)}return{faceSize:a,faces:r}}function Ke(n,e,t,i,a,r){const s=1/a,c=(i[3]-i[0])*s,o=(i[4]-i[1])*s,l=(i[5]-i[2])*s,u=(i[9]-i[6])*s,d=(i[10]-i[7])*s,p=(i[11]-i[8])*s;let y=0;for(let b=0;b<a;b++){let h=i[0],m=i[1],f=i[2],x=i[6],g=i[7],C=i[8];for(let D=0;D<a;D++){let O=h+(x-h)*y,B=m+(g-m)*y,U=f+(C-f)*y;const R=1/Math.sqrt(O*O+B*B+U*U);O*=R,B*=R,U*=R;const pe=Math.atan2(O,U)/Math.PI*.5+.5,de=Math.acos(B)/Math.PI,he=(b*a+D)*4;Xe(n,e,t,pe,de,r,he),h+=c,m+=o,f+=l,x+=u,g+=d,C+=p}y+=s}}function Xe(n,e,t,i,a,r,s){const c=i*e-.5,o=(1-a)*t-.5,l=Math.floor(c),u=Math.floor(o),d=c-l,p=o-u,y=(l%e+e)%e,b=((l+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,C=(m*e+b)*4,D=(1-d)*(1-p),O=d*(1-p),B=(1-d)*p,U=d*p;for(let R=0;R<4;R++)r[s+R]=n[f+R]*D+n[x+R]*O+n[g+R]*B+n[C+R]*U}const We={name:"editor-cube-preview",platformTarget:0,subShaders:[{name:"Default",tags:{},passes:[{name:"Default",isUsePass:!1,tags:{},renderStates:{constantMap:{},variableMap:{}},vertexShaderInstructions:[[0,`attribute vec3 POSITION;
attribute vec3 NORMAL;

varying vec3 v_reflectDir;

uniform mat4 renderer_MVPMat;
uniform vec3 camera_Position;
uniform mat4 renderer_ModelMat;
void main() { 
gl_Position = renderer_MVPMat * vec4 ( POSITION , 1.0 ) ;
mat4 worldToModel = inverse ( renderer_ModelMat ) ;
vec3 objSpaceCameraPos = ( worldToModel * vec4 ( camera_Position , 1.0 ) ).xyz ;
vec3 objSpaceViewDir = - normalize ( objSpaceCameraPos - POSITION ) ;
v_reflectDir = reflect ( objSpaceViewDir , NORMAL ) ;
 }`]],fragmentShaderInstructions:[[0,`varying vec3 v_reflectDir;

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