var gdjs;(function(x){const u=new x.Logger("PIXI Image manager"),d=GlobalPIXIModule.PIXI,T=(a,e)=>{u.error("Unable to load file "+a+" with error:",e||"(unknown error)")},E=(a,e)=>{!a||e.smoothed||(a.baseTexture.scaleMode=d.SCALE_MODES.NEAREST)},R=(a,e)=>{e&&!e.smoothed&&(a.magFilter=THREE.NearestFilter,a.minFilter=THREE.NearestFilter)},g=(a,e,r)=>{for(let o=0,t=a.length;o<t;++o){const i=a[o];if(i.name===e&&i.kind===r)return i}return null};class A{constructor(e,r){this._resources=e,this._resourcesLoader=r,this._invalidTexture=d.Texture.from("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVQoU2P8z/D/PwMewDgyFAAApMMX8Zi0uXAAAAAASUVORK5CYIIA"),this._loadedTextures=new Hashtable,this._loadedThreeTextures=new Hashtable,this._loadedThreeMaterials=new Hashtable}setResources(e){this._resources=e}getPIXITexture(e){if(this._loadedTextures.containsKey(e)){const i=this._loadedTextures.get(e);if(i.valid)return i;u.error("Texture for "+e+" is not valid anymore (or never was).")}if(e==="")return this._invalidTexture;const r=g(this._resources,e,"image");if(!r)return u.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;u.log('Loading texture for resource "'+e+'"...');const o=r.file,t=d.Texture.from(this._resourcesLoader.getFullUrl(o),{resourceOptions:{crossorigin:this._resourcesLoader.checkIfCredentialsRequired(o)?"use-credentials":"anonymous"}}).on("error",i=>{T(o,i)});return E(t,r),this._loadedTextures.put(e,t),t}getThreeTexture(e){const r=this._loadedThreeTextures.get(e);if(r)return r;const o=this.getPIXITexture(e);if(!this._resourcesLoader._runtimeGame.getRenderer().getPIXIRenderer())throw new Error("No PIXI renderer was found.");const i=o.baseTexture.resource.source;if(!(i instanceof HTMLImageElement))throw new Error(`Can't load texture for resource "${e}" as it's not an image.`);const s=new THREE.Texture(i);s.magFilter=THREE.LinearFilter,s.minFilter=THREE.LinearFilter,s.wrapS=THREE.RepeatWrapping,s.wrapT=THREE.RepeatWrapping,s.colorSpace=THREE.SRGBColorSpace,s.needsUpdate=!0;const h=g(this._resources,e,"image");return R(s,h),this._loadedThreeTextures.put(e,s),s}getThreeMaterial(e,{useTransparentTexture:r,forceBasicMaterial:o}){const t=`${e}|${r?1:0}|${o?1:0}`,i=this._loadedThreeMaterials.get(t);if(i)return i;const s=o?new THREE.MeshBasicMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r}):new THREE.MeshStandardMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r,metalness:0});return this._loadedThreeMaterials.put(t,s),s}getPIXIVideoTexture(e){if(this._loadedTextures.containsKey(e))return this._loadedTextures.get(e);if(e==="")return this._invalidTexture;const r=g(this._resources,e,"video");if(!r)return u.warn('Unable to find video texture for resource "'+e+'".'),this._invalidTexture;const o=r.file;u.log('Loading video texture for resource "'+e+'"...');const t=d.Texture.from(this._resourcesLoader.getFullUrl(o),{resourceOptions:{crossorigin:this._resourcesLoader.checkIfCredentialsRequired(o)?"use-credentials":"anonymous"}}).on("error",i=>{T(o,i)});return this._loadedTextures.put(e,t),t}getInvalidPIXITexture(){return this._invalidTexture}loadTextures(e,r){const o=this._resources,t={};for(let l=0,c=o.length;l<c;++l){const n=o[l];if(n.file&&n.kind==="image"){if(this._loadedTextures.containsKey(n.name))continue;t[n.file]=t[n.file]?t[n.file].concat(n):[n]}}const i=Object.keys(t).length;if(i===0)return r(i);const s=d.Loader.shared;let h=0;const _=s.onProgress.add(function(){h++,e(h,i)});for(const l in t)t.hasOwnProperty(l)&&s.add({name:l,url:this._resourcesLoader.getFullUrl(l),loadType:d.LoaderResource.LOAD_TYPE.IMAGE,crossOrigin:this._resourcesLoader.checkIfCredentialsRequired(l)?"use-credentials":"anonymous"});s.load((l,c)=>{l.onProgress.detach(_);for(const n in c)if(c.hasOwnProperty(n)){if(!t.hasOwnProperty(n))continue;t[n].forEach(I=>{const f=c[n].texture;if(!f){const p=c[n].error;T(n,p);return}this._loadedTextures.put(I.name,f),E(f,I)})}r(i)})}}x.PixiImageManager=A,x.ImageManager=x.PixiImageManager})(gdjs||(gdjs={}));
//# sourceMappingURL=pixi-image-manager.js.map
