var f=Object.defineProperty;var d=(s,e,t)=>e in s?f(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var p=(s,e,t)=>(d(s,typeof e!="symbol"?e+"":e,t),t);import{$ as y,j as R,a9 as b,b3 as u,b4 as w,a$ as U,p as _,e as c,C as j,n as x,o as I}from"./index-a76b28be.js";import{X as O}from"./module-0d03e6f6.js";import"./index-4d966268.js";import"./postmen-a4b10828.js";import{A as v}from"./AssetViewer-06848056.js";import{e as W}from"./encode-ac4bb64e.js";import"./meshopt_simplifier.module-cd99529d.js";class X extends v{constructor(){super()}setViewAsset(e,t){const a=t.createChild("sprite_entity"),r=a.addComponent(y);r.sprite=e._sprite,this._entity=a}}var A=Object.defineProperty,B=Object.getOwnPropertyDescriptor,g=(s,e,t,a)=>{for(var r=a>1?void 0:a?B(e,t):e,i=s.length-1,n;i>=0;i--)(n=s[i])&&(r=(a?n(e,t,r):n(r))||r);return a&&r&&A(e,t,r),r};let h=class extends R{constructor(e){super(e);p(this,"imgUrl");p(this,"_sprite");p(this,"physicalWidth",.1);this._sprite=new b(this.engine)}async initByMain(e){this.imgUrl&&(URL.revokeObjectURL(this.imgUrl),this.imgUrl=""),await new Promise((t,a)=>{const{_sprite:r}=this,i=new Image;i.crossOrigin="*";const n=URL.createObjectURL(e),m=()=>{URL.revokeObjectURL(n),this.imgUrl===n&&(this.imgUrl="")};this.imgUrl=i.src=n,i.onload=()=>{try{const o=new O("reference",i,i.width/100),l=new u(this.engine,i.width,i.height,w.R8G8B8A8,!1);l.setImageSource(i),r.texture=l,r.width=i.width/100,r.height=i.height/100,this.physicalWidth=o.physicalWidth=this.meta.physicalWidth,this.bindEngineObject(o),t(this)}catch(o){a(o)}finally{m()}},i.onerror=o=>{m(),a(o)}})}initByEngineObject(e){this.bindEngineObject(e),this.physicalWidth=e.physicalWidth}};g([U(),_({label:c("xr.image.width.label"),info:c("xr.image.width.info"),type:j.Number})],h.prototype,"physicalWidth",2);h=g([x({type:"XRReferenceImage",label:c("asset.xr-reference-image.title"),loaderType:"XRReferenceImage",importMenuConfig:{type:I.Upload,tooltip:"支持多选",accept:".png,.jpg,.jpeg,.webp",multiple:!0},viewer:X,defaultName:"ReferenceImage",extname:"bin",async bundle({content:s,meta:e,name:t}){const a=await s.arrayBuffer();return{type:"XRReferenceImage",content:new Blob([W([a],{type:"XRReferenceImage",name:t,physicalWidth:e.physicalWidth})])}}})],h);export{h as XRReferenceImageAsset};
