UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

2 lines (1 loc) 3.21 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var t=require("../../../build/three.module.js");class e extends t.DataTextureLoader{constructor(e){super(e),this.type=t.HalfFloatType}parse(e){const r=function(t,e,r){e=e||1024;let a=t.pos,n=-1,s=0,o="",i=String.fromCharCode.apply(null,new Uint16Array(t.subarray(a,a+128)));for(;0>(n=i.indexOf("\n"))&&s<e&&a<t.byteLength;)o+=i,s+=i.length,a+=128,i+=String.fromCharCode.apply(null,new Uint16Array(t.subarray(a,a+128)));return-1<n&&(!1!==r&&(t.pos+=s+n+1),o+i.slice(0,n))},a=function(t,e,r,a){const n=t[e+3],s=Math.pow(2,n-128)/255;r[a+0]=t[e+0]*s,r[a+1]=t[e+1]*s,r[a+2]=t[e+2]*s,r[a+3]=1},n=function(e,r,a,n){const s=e[r+3],o=Math.pow(2,s-128)/255;a[n+0]=t.DataUtils.toHalfFloat(Math.min(e[r+0]*o,65504)),a[n+1]=t.DataUtils.toHalfFloat(Math.min(e[r+1]*o,65504)),a[n+2]=t.DataUtils.toHalfFloat(Math.min(e[r+2]*o,65504)),a[n+3]=t.DataUtils.toHalfFloat(1)},s=new Uint8Array(e);s.pos=0;const o=function(t){const e=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,a=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,n=/^\s*FORMAT=(\S+)\s*$/,s=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,o={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let i,l;if(t.pos>=t.byteLength||!(i=r(t)))return-1;if(!(l=i.match(/^#\?(\S+)/)))return-1;for(o.valid|=1,o.programtype=l[1],o.string+=i+"\n";i=r(t),!1!==i;)if(o.string+=i+"\n","#"!==i.charAt(0)){if((l=i.match(e))&&(o.gamma=parseFloat(l[1])),(l=i.match(a))&&(o.exposure=parseFloat(l[1])),(l=i.match(n))&&(o.valid|=2,o.format=l[1]),(l=i.match(s))&&(o.valid|=4,o.height=parseInt(l[1],10),o.width=parseInt(l[2],10)),2&o.valid&&4&o.valid)break}else o.comments+=i+"\n";return 2&o.valid&&4&o.valid?o:-1}(s);if(-1!==o){const e=o.width,r=o.height,i=function(t,e,r){const a=e;if(a<8||a>32767||2!==t[0]||2!==t[1]||128&t[2])return new Uint8Array(t);if(a!==(t[2]<<8|t[3]))return-1;const n=new Uint8Array(4*e*r);if(!n.length)return-1;let s=0,o=0;const i=4*a,l=new Uint8Array(4),p=new Uint8Array(i);let u=r;for(;u>0&&o<t.byteLength;){if(o+4>t.byteLength)return-1;if(l[0]=t[o++],l[1]=t[o++],l[2]=t[o++],l[3]=t[o++],2!=l[0]||2!=l[1]||(l[2]<<8|l[3])!=a)return-1;let e,r=0;for(;r<i&&o<t.byteLength;){e=t[o++];const a=e>128;if(a&&(e-=128),0===e||r+e>i)return-1;if(a){const a=t[o++];for(let t=0;t<e;t++)p[r++]=a}else p.set(t.subarray(o,o+e),r),r+=e,o+=e}const c=a;for(let t=0;t<c;t++){let e=0;n[s]=p[t+e],e+=a,n[s+1]=p[t+e],e+=a,n[s+2]=p[t+e],e+=a,n[s+3]=p[t+e],s+=4}u--}return n}(s.subarray(s.pos),e,r);if(-1!==i){let s,l,p;switch(this.type){case t.FloatType:p=i.length/4;const e=new Float32Array(4*p);for(let t=0;t<p;t++)a(i,4*t,e,4*t);s=e,l=t.FloatType;break;case t.HalfFloatType:p=i.length/4;const r=new Uint16Array(4*p);for(let t=0;t<p;t++)n(i,4*t,r,4*t);s=r,l=t.HalfFloatType}return{width:e,height:r,data:s,header:o.string,gamma:o.gamma,exposure:o.exposure,type:l}}}return null}setDataType(t){return this.type=t,this}load(e,r,a,n){return super.load(e,(function(e,a){switch(e.type){case t.FloatType:case t.HalfFloatType:e.encoding=t.LinearEncoding,e.minFilter=t.LinearFilter,e.magFilter=t.LinearFilter,e.generateMipmaps=!1,e.flipY=!0}r&&r(e,a)}),a,n)}}exports.RGBELoader=e;