UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

3 lines (2 loc) 3.52 kB
import{y as t}from"./index-BPURObVq.esm.min.js";function e(t){let e=0;return{id_length:t[e++],colormap_type:t[e++],image_type:t[e++],colormap_index:t[e++]|t[e++]<<8,colormap_length:t[e++]|t[e++]<<8,colormap_size:t[e++],origin:[t[e++]|t[e++]<<8,t[e++]|t[e++]<<8],width:t[e++]|t[e++]<<8,height:t[e++]|t[e++]<<8,pixel_size:t[e++],flags:t[17]}}function r(r,a){if(a.length<19)return void t.Error("Unable to load TGA file - Not enough data to contain header");let i=18;const o=e(a);if(o.id_length+i>a.length)return void t.Error("Unable to load TGA file - Not enough data");i+=o.id_length;let s,h=!1,c=!1,g=!1;switch(o.image_type){case 9:h=!0;case 1:c=!0;break;case 10:h=!0;case 2:break;case 11:h=!0;case 3:g=!0}const l=o.pixel_size>>3,f=o.width*o.height*l;let d,u,w,p,_,b,y;if(c&&(d=a.subarray(i,i+=o.colormap_length*(o.colormap_size>>3))),h){let t,e,r;s=new Uint8Array(f);let n=0;const o=new Uint8Array(l);for(;i<f&&n<f;)if(t=a[i++],e=1+(127&t),128&t){for(r=0;r<l;++r)o[r]=a[i++];for(r=0;r<e;++r)s.set(o,n+r*l);n+=l*e}else{for(e*=l,r=0;r<e;++r)s[n+r]=a[i++];n+=e}}else s=a.subarray(i,i+(c?o.width*o.height:f));switch((48&o.flags)>>4){default:case 2:u=0,p=1,y=o.width,w=0,_=1,b=o.height;break;case 0:u=0,p=1,y=o.width,w=o.height-1,_=-1,b=-1;break;case 3:u=o.width-1,p=-1,y=-1,w=0,_=1,b=o.height;break;case 1:u=o.width-1,p=-1,y=-1,w=o.height-1,_=-1,b=-1}const m="_getImageData"+(g?"Grey":"")+o.pixel_size+"bits",A=n[m](o,d,s,w,_,b,u,p,y);r.getEngine()._uploadDataToTextureDirectly(r,A)}const n={GetTGAHeader:e,UploadContent:r,_getImageData8bits:function(t,e,r,n,a,i,o,s,h){const c=r,g=e,l=t.width,f=t.height;let d,u,w,p=0;const _=new Uint8Array(l*f*4);for(w=n;w!==i;w+=a)for(u=o;u!==h;u+=s,p++)d=c[p],_[4*(u+l*w)+3]=255,_[4*(u+l*w)+2]=g[3*d+0],_[4*(u+l*w)+1]=g[3*d+1],_[4*(u+l*w)+0]=g[3*d+2];return _},_getImageData16bits:function(t,e,r,n,a,i,o,s,h){const c=r,g=t.width,l=t.height;let f,d,u,w=0;const p=new Uint8Array(g*l*4);for(u=n;u!==i;u+=a)for(d=o;d!==h;d+=s,w+=2){f=c[w+0]+(c[w+1]<<8);const t=255*((31744&f)>>10)/31|0,e=255*((992&f)>>5)/31|0,r=255*(31&f)/31|0;p[4*(d+g*u)+0]=t,p[4*(d+g*u)+1]=e,p[4*(d+g*u)+2]=r,p[4*(d+g*u)+3]=32768&f?0:255}return p},_getImageData24bits:function(t,e,r,n,a,i,o,s,h){const c=r,g=t.width,l=t.height;let f,d,u=0;const w=new Uint8Array(g*l*4);for(d=n;d!==i;d+=a)for(f=o;f!==h;f+=s,u+=3)w[4*(f+g*d)+3]=255,w[4*(f+g*d)+2]=c[u+0],w[4*(f+g*d)+1]=c[u+1],w[4*(f+g*d)+0]=c[u+2];return w},_getImageData32bits:function(t,e,r,n,a,i,o,s,h){const c=r,g=t.width,l=t.height;let f,d,u=0;const w=new Uint8Array(g*l*4);for(d=n;d!==i;d+=a)for(f=o;f!==h;f+=s,u+=4)w[4*(f+g*d)+2]=c[u+0],w[4*(f+g*d)+1]=c[u+1],w[4*(f+g*d)+0]=c[u+2],w[4*(f+g*d)+3]=c[u+3];return w},_getImageDataGrey8bits:function(t,e,r,n,a,i,o,s,h){const c=r,g=t.width,l=t.height;let f,d,u,w=0;const p=new Uint8Array(g*l*4);for(u=n;u!==i;u+=a)for(d=o;d!==h;d+=s,w++)f=c[w],p[4*(d+g*u)+0]=f,p[4*(d+g*u)+1]=f,p[4*(d+g*u)+2]=f,p[4*(d+g*u)+3]=255;return p},_getImageDataGrey16bits:function(t,e,r,n,a,i,o,s,h){const c=r,g=t.width,l=t.height;let f,d,u=0;const w=new Uint8Array(g*l*4);for(d=n;d!==i;d+=a)for(f=o;f!==h;f+=s,u+=2)w[4*(f+g*d)+0]=c[u+0],w[4*(f+g*d)+1]=c[u+0],w[4*(f+g*d)+2]=c[u+0],w[4*(f+g*d)+3]=c[u+1];return w}};class a{constructor(){this.supportCascades=!1}loadCubeData(){throw".env not supported in Cube."}loadData(t,n,a){const i=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),o=e(i);a(o.width,o.height,n.generateMipMaps,!1,()=>{r(n,i)})}}export{a as _TGATextureLoader}; //# sourceMappingURL=tgaTextureLoader-CbiNnccc.esm.min.js.map