three-stdlib 2.20.3 → 2.20.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -240,7 +240,7 @@ export { HDRCubeTextureLoader } from './loaders/HDRCubeTextureLoader.js';
240
240
  export { PDBLoader } from './loaders/PDBLoader.js';
241
241
  export { PRWMLoader } from './loaders/PRWMLoader.js';
242
242
  export { RGBMLoader } from './loaders/RGBMLoader.js';
243
- export { VOXDataTexture3D, VOXLoader, VOXMesh } from './loaders/VOXLoader.js';
243
+ export { VOXData3DTexture, VOXLoader, VOXMesh } from './loaders/VOXLoader.js';
244
244
  export { NodeMaterialLoaderUtils } from './loaders/NodeMaterialLoader.js';
245
245
  export { PCDLoader } from './loaders/PCDLoader.js';
246
246
  export { LWOLoader } from './loaders/LWOLoader.js';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{load(t,r,a,i){const n=new e.FileLoader(this.manager);n.setPath(this.path),n.setResponseType("text"),n.load(t,(e=>{try{r(this.parse(e))}catch(e){i?i(e):console.error(e),this.manager.itemError(t)}}),a,i)}parse(t){const r=(t=t.replace(/^#.*?(\n|\r)/gm,"").replace(/^\s*?(\n|\r)/gm,"").trim()).split(/[\n\r]+/g),a=r[0].trim().split(/\s+/g).map((e=>parseFloat(e))),i=a[1]-a[0],n=a.length;for(let e=1,t=a.length;e<t;e++)if(i!==a[e]-a[e-1])throw new Error("LUT3dlLoader: Inconsistent grid size not supported.");const o=new Array(n*n*n*4);let p=0,s=0;for(let e=1,t=r.length;e<t;e++){const t=r[e].trim().split(/\s/g),a=parseFloat(t[0]),i=parseFloat(t[1]),l=parseFloat(t[2]);s=Math.max(s,a,i,l);const g=p%n*n*n+Math.floor(p/n)%n*n+Math.floor(p/(n*n))%n;o[4*g+0]=a,o[4*g+1]=i,o[4*g+2]=l,o[4*g+3]=1,p+=1}const l=Math.ceil(Math.log2(s)),g=Math.pow(2,l);for(let e=0,t=o.length;e<t;e+=4){const t=o[e+0],r=o[e+1],a=o[e+2];o[e+0]=255*t/g,o[e+1]=255*r/g,o[e+2]=255*a/g}const m=new Uint8Array(o),h=new e.DataTexture;h.image.data=m,h.image.width=n,h.image.height=n*n,h.format=e.RGBAFormat,h.type=e.UnsignedByteType,h.magFilter=e.LinearFilter,h.minFilter=e.LinearFilter,h.wrapS=e.ClampToEdgeWrapping,h.wrapT=e.ClampToEdgeWrapping,h.generateMipmaps=!1;const d=new e.DataTexture3D;return d.image.data=m,d.image.width=n,d.image.height=n,d.image.depth=n,d.format=e.RGBAFormat,d.type=e.UnsignedByteType,d.magFilter=e.LinearFilter,d.minFilter=e.LinearFilter,d.wrapS=e.ClampToEdgeWrapping,d.wrapT=e.ClampToEdgeWrapping,d.wrapR=e.ClampToEdgeWrapping,d.generateMipmaps=!1,{size:n,texture:h,texture3D:d}}}exports.LUT3dlLoader=t;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{load(t,r,a,i){const n=new e.FileLoader(this.manager);n.setPath(this.path),n.setResponseType("text"),n.load(t,(e=>{try{r(this.parse(e))}catch(e){i?i(e):console.error(e),this.manager.itemError(t)}}),a,i)}parse(t){const r=(t=t.replace(/^#.*?(\n|\r)/gm,"").replace(/^\s*?(\n|\r)/gm,"").trim()).split(/[\n\r]+/g),a=r[0].trim().split(/\s+/g).map((e=>parseFloat(e))),i=a[1]-a[0],n=a.length;for(let e=1,t=a.length;e<t;e++)if(i!==a[e]-a[e-1])throw new Error("LUT3dlLoader: Inconsistent grid size not supported.");const p=new Array(n*n*n*4);let o=0,s=0;for(let e=1,t=r.length;e<t;e++){const t=r[e].trim().split(/\s/g),a=parseFloat(t[0]),i=parseFloat(t[1]),l=parseFloat(t[2]);s=Math.max(s,a,i,l);const g=o%n*n*n+Math.floor(o/n)%n*n+Math.floor(o/(n*n))%n;p[4*g+0]=a,p[4*g+1]=i,p[4*g+2]=l,p[4*g+3]=1,o+=1}const l=Math.ceil(Math.log2(s)),g=Math.pow(2,l);for(let e=0,t=p.length;e<t;e+=4){const t=p[e+0],r=p[e+1],a=p[e+2];p[e+0]=255*t/g,p[e+1]=255*r/g,p[e+2]=255*a/g}const m=new Uint8Array(p),d=new e.DataTexture;d.image.data=m,d.image.width=n,d.image.height=n*n,d.format=e.RGBAFormat,d.type=e.UnsignedByteType,d.magFilter=e.LinearFilter,d.minFilter=e.LinearFilter,d.wrapS=e.ClampToEdgeWrapping,d.wrapT=e.ClampToEdgeWrapping,d.generateMipmaps=!1,d.needsUpdate=!0;const h=new e.Data3DTexture;return h.image.data=m,h.image.width=n,h.image.height=n,h.image.depth=n,h.format=e.RGBAFormat,h.type=e.UnsignedByteType,h.magFilter=e.LinearFilter,h.minFilter=e.LinearFilter,h.wrapS=e.ClampToEdgeWrapping,h.wrapT=e.ClampToEdgeWrapping,h.wrapR=e.ClampToEdgeWrapping,h.generateMipmaps=!1,h.needsUpdate=!0,{size:n,texture:d,texture3D:h}}}exports.LUT3dlLoader=t;
@@ -1,4 +1,4 @@
1
- import { Loader, FileLoader, DataTexture, RGBAFormat, UnsignedByteType, LinearFilter, ClampToEdgeWrapping, DataTexture3D } from 'three';
1
+ import { Loader, FileLoader, DataTexture, RGBAFormat, UnsignedByteType, LinearFilter, ClampToEdgeWrapping, Data3DTexture } from 'three';
2
2
 
3
3
  // http://download.autodesk.com/us/systemdocs/help/2011/lustre/index.html?url=./files/WSc4e151a45a3b785a24c3d9a411df9298473-7ffd.htm,topicNumber=d0e9492
4
4
  class LUT3dlLoader extends Loader {
@@ -87,7 +87,8 @@ class LUT3dlLoader extends Loader {
87
87
  texture.wrapS = ClampToEdgeWrapping;
88
88
  texture.wrapT = ClampToEdgeWrapping;
89
89
  texture.generateMipmaps = false;
90
- const texture3D = new DataTexture3D();
90
+ texture.needsUpdate = true;
91
+ const texture3D = new Data3DTexture();
91
92
  texture3D.image.data = data;
92
93
  texture3D.image.width = size;
93
94
  texture3D.image.height = size;
@@ -100,6 +101,7 @@ class LUT3dlLoader extends Loader {
100
101
  texture3D.wrapT = ClampToEdgeWrapping;
101
102
  texture3D.wrapR = ClampToEdgeWrapping;
102
103
  texture3D.generateMipmaps = false;
104
+ texture3D.needsUpdate = true;
103
105
  return {
104
106
  size,
105
107
  texture,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class a extends e.Loader{load(a,t,r,i){const n=new e.FileLoader(this.manager);n.setPath(this.path),n.setResponseType("text"),n.load(a,(e=>{try{t(this.parse(e))}catch(e){i?i(e):console.error(e),this.manager.itemError(a)}}),r,i)}parse(a){a=a.replace(/^#.*?(\n|\r)/gm,"").replace(/^\s*?(\n|\r)/gm,"").trim();let t=null,r=null;const i=new e.Vector3(0,0,0),n=new e.Vector3(1,1,1),s=a.split(/[\n\r]+/g);let p=null,l=0;for(let e=0,a=s.length;e<a;e++){const a=s[e].trim(),o=a.split(/\s/g);switch(o[0]){case"TITLE":t=a.substring(7,a.length-1);break;case"LUT_3D_SIZE":const e=o[1];r=parseFloat(e),p=new Uint8Array(r*r*r*4);break;case"DOMAIN_MIN":i.x=parseFloat(o[1]),i.y=parseFloat(o[2]),i.z=parseFloat(o[3]);break;case"DOMAIN_MAX":n.x=parseFloat(o[1]),n.y=parseFloat(o[2]),n.z=parseFloat(o[3]);break;default:const s=parseFloat(o[0]),g=parseFloat(o[1]),m=parseFloat(o[2]);if(s>1||s<0||g>1||g<0||m>1||m<0)throw new Error("LUTCubeLoader : Non normalized values not supported.");p[l+0]=255*s,p[l+1]=255*g,p[l+2]=255*m,p[l+3]=255,l+=4}}const o=new e.DataTexture;o.image.data=p,o.image.width=r,o.image.height=r*r,o.type=e.UnsignedByteType,o.magFilter=e.LinearFilter,o.minFilter=e.LinearFilter,o.wrapS=e.ClampToEdgeWrapping,o.wrapT=e.ClampToEdgeWrapping,o.generateMipmaps=!1;const g=new e.DataTexture3D;return g.image.data=p,g.image.width=r,g.image.height=r,g.image.depth=r,g.type=e.UnsignedByteType,g.magFilter=e.LinearFilter,g.minFilter=e.LinearFilter,g.wrapS=e.ClampToEdgeWrapping,g.wrapT=e.ClampToEdgeWrapping,g.wrapR=e.ClampToEdgeWrapping,g.generateMipmaps=!1,{title:t,size:r,domainMin:i,domainMax:n,texture:o,texture3D:g}}}exports.LUTCubeLoader=a;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class a extends e.Loader{load(a,t,r,i){const n=new e.FileLoader(this.manager);n.setPath(this.path),n.setResponseType("text"),n.load(a,(e=>{try{t(this.parse(e))}catch(e){i?i(e):console.error(e),this.manager.itemError(a)}}),r,i)}parse(a){a=a.replace(/^#.*?(\n|\r)/gm,"").replace(/^\s*?(\n|\r)/gm,"").trim();let t=null,r=null;const i=new e.Vector3(0,0,0),n=new e.Vector3(1,1,1),s=a.split(/[\n\r]+/g);let p=null,l=0;for(let e=0,a=s.length;e<a;e++){const a=s[e].trim(),o=a.split(/\s/g);switch(o[0]){case"TITLE":t=a.substring(7,a.length-1);break;case"LUT_3D_SIZE":const e=o[1];r=parseFloat(e),p=new Uint8Array(r*r*r*4);break;case"DOMAIN_MIN":i.x=parseFloat(o[1]),i.y=parseFloat(o[2]),i.z=parseFloat(o[3]);break;case"DOMAIN_MAX":n.x=parseFloat(o[1]),n.y=parseFloat(o[2]),n.z=parseFloat(o[3]);break;default:const s=parseFloat(o[0]),g=parseFloat(o[1]),d=parseFloat(o[2]);if(s>1||s<0||g>1||g<0||d>1||d<0)throw new Error("LUTCubeLoader : Non normalized values not supported.");p[l+0]=255*s,p[l+1]=255*g,p[l+2]=255*d,p[l+3]=255,l+=4}}const o=new e.DataTexture;o.image.data=p,o.image.width=r,o.image.height=r*r,o.type=e.UnsignedByteType,o.magFilter=e.LinearFilter,o.minFilter=e.LinearFilter,o.wrapS=e.ClampToEdgeWrapping,o.wrapT=e.ClampToEdgeWrapping,o.generateMipmaps=!1,o.needsUpdate=!0;const g=new e.Data3DTexture;return g.image.data=p,g.image.width=r,g.image.height=r,g.image.depth=r,g.type=e.UnsignedByteType,g.magFilter=e.LinearFilter,g.minFilter=e.LinearFilter,g.wrapS=e.ClampToEdgeWrapping,g.wrapT=e.ClampToEdgeWrapping,g.wrapR=e.ClampToEdgeWrapping,g.generateMipmaps=!1,g.needsUpdate=!0,{title:t,size:r,domainMin:i,domainMax:n,texture:o,texture3D:g}}}exports.LUTCubeLoader=a;
@@ -1,4 +1,4 @@
1
- import { Loader, FileLoader, Vector3, DataTexture, UnsignedByteType, LinearFilter, ClampToEdgeWrapping, DataTexture3D } from 'three';
1
+ import { Loader, FileLoader, Vector3, DataTexture, UnsignedByteType, LinearFilter, ClampToEdgeWrapping, Data3DTexture } from 'three';
2
2
 
3
3
  // https://wwwimages2.adobe.com/content/dam/acom/en/products/speedgrade/cc/pdfs/cube-lut-specification-1.0.pdf
4
4
  class LUTCubeLoader extends Loader {
@@ -88,7 +88,8 @@ class LUTCubeLoader extends Loader {
88
88
  texture.wrapS = ClampToEdgeWrapping;
89
89
  texture.wrapT = ClampToEdgeWrapping;
90
90
  texture.generateMipmaps = false;
91
- const texture3D = new DataTexture3D();
91
+ texture.needsUpdate = true;
92
+ const texture3D = new Data3DTexture();
92
93
  texture3D.image.data = data;
93
94
  texture3D.image.width = size;
94
95
  texture3D.image.height = size;
@@ -100,6 +101,7 @@ class LUTCubeLoader extends Loader {
100
101
  texture3D.wrapT = ClampToEdgeWrapping;
101
102
  texture3D.wrapR = ClampToEdgeWrapping;
102
103
  texture3D.generateMipmaps = false;
104
+ texture3D.needsUpdate = true;
103
105
  return {
104
106
  title,
105
107
  size,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{load(t,r,s,n){const o=this,a=new e.FileLoader(o.manager);a.setPath(o.path),a.setResponseType("arraybuffer"),a.setRequestHeader(o.requestHeader),a.load(t,(function(e){try{r(o.parse(e))}catch(e){n?n(e):console.error(e),o.manager.itemError(t)}}),s,n)}parse(e){const t=new DataView(e),r=t.getUint32(0,!0),s=t.getUint32(4,!0);if(542658390!==r||150!==s)return void console.error("Not a valid VOX file");const n=[0,4294967295,4291624959,4288282623,4284940287,4281597951,4278255615,4294954239,4291611903,4288269567,4284927231,4281584895,4278242559,4294941183,4291598847,4288256511,4284914175,4281571839,4278229503,4294928127,4291585791,4288243455,4284901119,4281558783,4278216447,4294915071,4291572735,4288230399,4284888063,4281545727,4278203391,4294902015,4291559679,4288217343,4284875007,4281532671,4278190335,4294967244,4291624908,4288282572,4284940236,4281597900,4278255564,4294954188,4291611852,4288269516,4284927180,4281584844,4278242508,4294941132,4291598796,4288256460,4284914124,4281571788,4278229452,4294928076,4291585740,4288243404,4284901068,4281558732,4278216396,4294915020,4291572684,4288230348,4284888012,4281545676,4278203340,4294901964,4291559628,4288217292,4284874956,4281532620,4278190284,4294967193,4291624857,4288282521,4284940185,4281597849,4278255513,4294954137,4291611801,4288269465,4284927129,4281584793,4278242457,4294941081,4291598745,4288256409,4284914073,4281571737,4278229401,4294928025,4291585689,4288243353,4284901017,4281558681,4278216345,4294914969,4291572633,4288230297,4284887961,4281545625,4278203289,4294901913,4291559577,4288217241,4284874905,4281532569,4278190233,4294967142,4291624806,4288282470,4284940134,4281597798,4278255462,4294954086,4291611750,4288269414,4284927078,4281584742,4278242406,4294941030,4291598694,4288256358,4284914022,4281571686,4278229350,4294927974,4291585638,4288243302,4284900966,4281558630,4278216294,4294914918,4291572582,4288230246,4284887910,4281545574,4278203238,4294901862,4291559526,4288217190,4284874854,4281532518,4278190182,4294967091,4291624755,4288282419,4284940083,4281597747,4278255411,4294954035,4291611699,4288269363,4284927027,4281584691,4278242355,4294940979,4291598643,4288256307,4284913971,4281571635,4278229299,4294927923,4291585587,4288243251,4284900915,4281558579,4278216243,4294914867,4291572531,4288230195,4284887859,4281545523,4278203187,4294901811,4291559475,4288217139,4284874803,4281532467,4278190131,4294967040,4291624704,4288282368,4284940032,4281597696,4278255360,4294953984,4291611648,4288269312,4284926976,4281584640,4278242304,4294940928,4291598592,4288256256,4284913920,4281571584,4278229248,4294927872,4291585536,4288243200,4284900864,4281558528,4278216192,4294914816,4291572480,4288230144,4284887808,4281545472,4278203136,4294901760,4291559424,4288217088,4284874752,4281532416,4278190318,4278190301,4278190267,4278190250,4278190216,4278190199,4278190165,4278190148,4278190114,4278190097,4278251008,4278246656,4278237952,4278233600,4278224896,4278220544,4278211840,4278207488,4278198784,4278194432,4293787648,4292673536,4290445312,4289331200,4287102976,4285988864,4283760640,4282646528,4280418304,4279304192,4293848814,4292730333,4290493371,4289374890,4287137928,4286019447,4283782485,4282664004,4280427042,4279308561];let o,a=8;const i=[];for(;a<t.byteLength;){let r="";for(let e=0;e<4;e++)r+=String.fromCharCode(t.getUint8(a++,!0));const s=t.getUint32(a,!0);if(a+=4,t.getUint32(a,!0),a+=4,"SIZE"===r){const e=t.getUint32(a,!0);a+=4;const r=t.getUint32(a,!0);a+=4;const l=t.getUint32(a,!0);a+=4,o={palette:n,size:{x:e,y:r,z:l}},i.push(o),a+=s-12}else if("XYZI"===r){const r=t.getUint32(a,!0);a+=4,o.data=new Uint8Array(e,a,4*r),a+=4*r}else if("RGBA"===r){const e=[0];for(let r=0;r<256;r++)e[r+1]=t.getUint32(a,!0),a+=4;o.palette=e}else a+=s}return i}}class r extends e.Mesh{constructor(t){const r=t.data,s=t.size,n=t.palette,o=[],a=[],i=[0,0,0,0,0,1,0,1,0,0,1,1,0,1,0,0,0,1],l=[1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0],c=[0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,1],u=[0,0,0,0,1,0,1,0,0,1,1,0,1,0,0,0,1,0],f=[0,0,1,0,0,0,1,0,1,1,0,0,1,0,1,0,0,0],d=[0,1,1,1,1,1,0,1,0,1,1,0,0,1,0,1,1,1];function p(e,t,r,n,i,l,c){t-=s.x/2,r-=s.z/2,n+=s.y/2;for(let s=0;s<18;s+=3)o.push(e[s+0]+t,e[s+1]+r,e[s+2]+n),a.push(i,l,c)}const x=s.x,h=s.x*s.y,g=new Uint8Array(s.x*s.y*s.z);for(let e=0;e<r.length;e+=4){g[r[e+0]+r[e+1]*x+r[e+2]*h]=255}let y=!1;for(let e=0;e<r.length;e+=4){const t=r[e+0],o=r[e+1],a=r[e+2],U=n[r[e+3]],m=(U>>0&255)/255,w=(U>>8&255)/255,z=(U>>16&255)/255;(m>0||w>0||z>0)&&(y=!0);const A=t+o*x+a*h;0!==g[A+1]&&t!==s.x-1||p(l,t,a,-o,m,w,z),0!==g[A-1]&&0!==t||p(i,t,a,-o,m,w,z),0!==g[A+x]&&o!==s.y-1||p(u,t,a,-o,m,w,z),0!==g[A-x]&&0!==o||p(c,t,a,-o,m,w,z),0!==g[A+h]&&a!==s.z-1||p(d,t,a,-o,m,w,z),0!==g[A-h]&&0!==a||p(f,t,a,-o,m,w,z)}const U=new e.BufferGeometry;U.setAttribute("position",new e.Float32BufferAttribute(o,3)),U.computeVertexNormals();const m=new e.MeshStandardMaterial;y&&(U.setAttribute("color",new e.Float32BufferAttribute(a,3)),m.vertexColors=!0),super(U,m)}}class s extends e.DataTexture3D{constructor(t){const r=t.data,s=t.size,n=s.x,o=s.x*s.y,a=new Uint8Array(s.x*s.y*s.z);for(let e=0;e<r.length;e+=4){a[r[e+0]+r[e+1]*n+r[e+2]*o]=255}super(a,s.x,s.y,s.z),this.format=e.RedFormat,this.minFilter=e.NearestFilter,this.magFilter=e.LinearFilter,this.unpackAlignment=1}}exports.VOXDataTexture3D=s,exports.VOXLoader=t,exports.VOXMesh=r;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{load(t,r,s,n){const o=this,a=new e.FileLoader(o.manager);a.setPath(o.path),a.setResponseType("arraybuffer"),a.setRequestHeader(o.requestHeader),a.load(t,(function(e){try{r(o.parse(e))}catch(e){n?n(e):console.error(e),o.manager.itemError(t)}}),s,n)}parse(e){const t=new DataView(e),r=t.getUint32(0,!0),s=t.getUint32(4,!0);if(542658390!==r||150!==s)return void console.error("Not a valid VOX file");const n=[0,4294967295,4291624959,4288282623,4284940287,4281597951,4278255615,4294954239,4291611903,4288269567,4284927231,4281584895,4278242559,4294941183,4291598847,4288256511,4284914175,4281571839,4278229503,4294928127,4291585791,4288243455,4284901119,4281558783,4278216447,4294915071,4291572735,4288230399,4284888063,4281545727,4278203391,4294902015,4291559679,4288217343,4284875007,4281532671,4278190335,4294967244,4291624908,4288282572,4284940236,4281597900,4278255564,4294954188,4291611852,4288269516,4284927180,4281584844,4278242508,4294941132,4291598796,4288256460,4284914124,4281571788,4278229452,4294928076,4291585740,4288243404,4284901068,4281558732,4278216396,4294915020,4291572684,4288230348,4284888012,4281545676,4278203340,4294901964,4291559628,4288217292,4284874956,4281532620,4278190284,4294967193,4291624857,4288282521,4284940185,4281597849,4278255513,4294954137,4291611801,4288269465,4284927129,4281584793,4278242457,4294941081,4291598745,4288256409,4284914073,4281571737,4278229401,4294928025,4291585689,4288243353,4284901017,4281558681,4278216345,4294914969,4291572633,4288230297,4284887961,4281545625,4278203289,4294901913,4291559577,4288217241,4284874905,4281532569,4278190233,4294967142,4291624806,4288282470,4284940134,4281597798,4278255462,4294954086,4291611750,4288269414,4284927078,4281584742,4278242406,4294941030,4291598694,4288256358,4284914022,4281571686,4278229350,4294927974,4291585638,4288243302,4284900966,4281558630,4278216294,4294914918,4291572582,4288230246,4284887910,4281545574,4278203238,4294901862,4291559526,4288217190,4284874854,4281532518,4278190182,4294967091,4291624755,4288282419,4284940083,4281597747,4278255411,4294954035,4291611699,4288269363,4284927027,4281584691,4278242355,4294940979,4291598643,4288256307,4284913971,4281571635,4278229299,4294927923,4291585587,4288243251,4284900915,4281558579,4278216243,4294914867,4291572531,4288230195,4284887859,4281545523,4278203187,4294901811,4291559475,4288217139,4284874803,4281532467,4278190131,4294967040,4291624704,4288282368,4284940032,4281597696,4278255360,4294953984,4291611648,4288269312,4284926976,4281584640,4278242304,4294940928,4291598592,4288256256,4284913920,4281571584,4278229248,4294927872,4291585536,4288243200,4284900864,4281558528,4278216192,4294914816,4291572480,4288230144,4284887808,4281545472,4278203136,4294901760,4291559424,4288217088,4284874752,4281532416,4278190318,4278190301,4278190267,4278190250,4278190216,4278190199,4278190165,4278190148,4278190114,4278190097,4278251008,4278246656,4278237952,4278233600,4278224896,4278220544,4278211840,4278207488,4278198784,4278194432,4293787648,4292673536,4290445312,4289331200,4287102976,4285988864,4283760640,4282646528,4280418304,4279304192,4293848814,4292730333,4290493371,4289374890,4287137928,4286019447,4283782485,4282664004,4280427042,4279308561];let o,a=8;const i=[];for(;a<t.byteLength;){let r="";for(let e=0;e<4;e++)r+=String.fromCharCode(t.getUint8(a++));const s=t.getUint32(a,!0);if(a+=4,a+=4,"SIZE"===r){const e=t.getUint32(a,!0);a+=4;const r=t.getUint32(a,!0);a+=4;const l=t.getUint32(a,!0);a+=4,o={palette:n,size:{x:e,y:r,z:l}},i.push(o),a+=s-12}else if("XYZI"===r){const r=t.getUint32(a,!0);a+=4,o.data=new Uint8Array(e,a,4*r),a+=4*r}else if("RGBA"===r){const e=[0];for(let r=0;r<256;r++)e[r+1]=t.getUint32(a,!0),a+=4;o.palette=e}else a+=s}return i}}class r extends e.Mesh{constructor(t){const r=t.data,s=t.size,n=t.palette,o=[],a=[],i=[0,0,0,0,0,1,0,1,0,0,1,1,0,1,0,0,0,1],l=[1,0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0],c=[0,0,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,1],u=[0,0,0,0,1,0,1,0,0,1,1,0,1,0,0,0,1,0],f=[0,0,1,0,0,0,1,0,1,1,0,0,1,0,1,0,0,0],d=[0,1,1,1,1,1,0,1,0,1,1,0,0,1,0,1,1,1];function p(e,t,r,n,i,l,c){t-=s.x/2,r-=s.z/2,n+=s.y/2;for(let s=0;s<18;s+=3)o.push(e[s+0]+t,e[s+1]+r,e[s+2]+n),a.push(i,l,c)}const h=s.x,x=s.x*s.y,g=new Uint8Array(s.x*s.y*s.z);for(let e=0;e<r.length;e+=4){g[r[e+0]+r[e+1]*h+r[e+2]*x]=255}let y=!1;for(let e=0;e<r.length;e+=4){const t=r[e+0],o=r[e+1],a=r[e+2],U=n[r[e+3]],m=(U>>0&255)/255,w=(U>>8&255)/255,z=(U>>16&255)/255;(m>0||w>0||z>0)&&(y=!0);const A=t+o*h+a*x;0!==g[A+1]&&t!==s.x-1||p(l,t,a,-o,m,w,z),0!==g[A-1]&&0!==t||p(i,t,a,-o,m,w,z),0!==g[A+h]&&o!==s.y-1||p(u,t,a,-o,m,w,z),0!==g[A-h]&&0!==o||p(c,t,a,-o,m,w,z),0!==g[A+x]&&a!==s.z-1||p(d,t,a,-o,m,w,z),0!==g[A-x]&&0!==a||p(f,t,a,-o,m,w,z)}const U=new e.BufferGeometry;U.setAttribute("position",new e.Float32BufferAttribute(o,3)),U.computeVertexNormals();const m=new e.MeshStandardMaterial;y&&(U.setAttribute("color",new e.Float32BufferAttribute(a,3)),m.vertexColors=!0),super(U,m)}}class s extends e.Data3DTexture{constructor(t){const r=t.data,s=t.size,n=s.x,o=s.x*s.y,a=new Uint8Array(s.x*s.y*s.z);for(let e=0;e<r.length;e+=4){a[r[e+0]+r[e+1]*n+r[e+2]*o]=255}super(a,s.x,s.y,s.z),this.format=e.RedFormat,this.minFilter=e.NearestFilter,this.magFilter=e.LinearFilter,this.unpackAlignment=1,this.needsUpdate=!0}}exports.VOXData3DTexture=s,exports.VOXLoader=t,exports.VOXMesh=r;
@@ -1,4 +1,4 @@
1
- import { Loader, FileLoader, Mesh, BufferGeometry, Float32BufferAttribute, MeshStandardMaterial, DataTexture3D, RedFormat, NearestFilter, LinearFilter } from 'three';
1
+ import { Loader, FileLoader, Mesh, BufferGeometry, Float32BufferAttribute, MeshStandardMaterial, Data3DTexture, RedFormat, NearestFilter, LinearFilter } from 'three';
2
2
 
3
3
  class VOXLoader extends Loader {
4
4
  load(url, onLoad, onProgress, onError) {
@@ -41,12 +41,11 @@ class VOXLoader extends Loader {
41
41
  let id = '';
42
42
 
43
43
  for (let j = 0; j < 4; j++) {
44
- id += String.fromCharCode(data.getUint8(i++, true));
44
+ id += String.fromCharCode(data.getUint8(i++));
45
45
  }
46
46
 
47
47
  const chunkSize = data.getUint32(i, true);
48
48
  i += 4;
49
- data.getUint32(i, true);
50
49
  i += 4; // childChunks
51
50
 
52
51
  if (id === 'SIZE') {
@@ -167,7 +166,7 @@ class VOXMesh extends Mesh {
167
166
 
168
167
  }
169
168
 
170
- class VOXDataTexture3D extends DataTexture3D {
169
+ class VOXData3DTexture extends Data3DTexture {
171
170
  constructor(chunk) {
172
171
  const data = chunk.data;
173
172
  const size = chunk.size;
@@ -188,8 +187,9 @@ class VOXDataTexture3D extends DataTexture3D {
188
187
  this.minFilter = NearestFilter;
189
188
  this.magFilter = LinearFilter;
190
189
  this.unpackAlignment = 1;
190
+ this.needsUpdate = true;
191
191
  }
192
192
 
193
193
  }
194
194
 
195
- export { VOXDataTexture3D, VOXLoader, VOXMesh };
195
+ export { VOXData3DTexture, VOXLoader, VOXMesh };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-stdlib",
3
- "version": "2.20.3",
3
+ "version": "2.20.5",
4
4
  "private": false,
5
5
  "description": "stand-alone library of threejs examples",
6
6
  "main": "index.cjs.js",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@babel/runtime/helpers/defineProperty"),e=require("./Pass.cjs.js"),i=require("three"),a=require("../shaders/DigitalGlitch.cjs.js");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=s(t);class n extends e.Pass{constructor(t=64){super(),r.default(this,"material",void 0),r.default(this,"fsQuad",void 0),r.default(this,"goWild",void 0),r.default(this,"curF",void 0),r.default(this,"randX",void 0),r.default(this,"uniforms",void 0),void 0===a.DigitalGlitch&&console.error("THREE.GlitchPass relies on DigitalGlitch");const s=a.DigitalGlitch;this.uniforms=i.UniformsUtils.clone(s.uniforms),this.uniforms.tDisp.value=this.generateHeightmap(t),this.material=new i.ShaderMaterial({uniforms:this.uniforms,vertexShader:s.vertexShader,fragmentShader:s.fragmentShader}),this.fsQuad=new e.FullScreenQuad(this.material),this.goWild=!1,this.curF=0,this.generateTrigger()}render(t,e,a){!1===t.capabilities.isWebGL2&&(this.uniforms.tDisp.value.format=i.LuminanceFormat),this.uniforms.tDiffuse.value=a.texture,this.uniforms.seed.value=Math.random(),this.uniforms.byp.value=0,this.curF%this.randX==0||1==this.goWild?(this.uniforms.amount.value=Math.random()/30,this.uniforms.angle.value=i.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.seed_x.value=i.MathUtils.randFloat(-1,1),this.uniforms.seed_y.value=i.MathUtils.randFloat(-1,1),this.uniforms.distortion_x.value=i.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=i.MathUtils.randFloat(0,1),this.curF=0,this.generateTrigger()):this.curF%this.randX<this.randX/5?(this.uniforms.amount.value=Math.random()/90,this.uniforms.angle.value=i.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.distortion_x.value=i.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=i.MathUtils.randFloat(0,1),this.uniforms.seed_x.value=i.MathUtils.randFloat(-.3,.3),this.uniforms.seed_y.value=i.MathUtils.randFloat(-.3,.3)):0==this.goWild&&(this.uniforms.byp.value=1),this.curF++,this.renderToScreen?(t.setRenderTarget(null),this.fsQuad.render(t)):(t.setRenderTarget(e),this.clear&&t.clear(),this.fsQuad.render(t))}generateTrigger(){this.randX=i.MathUtils.randInt(120,240)}generateHeightmap(t){const e=new Float32Array(t*t),a=t*t;for(let t=0;t<a;t++){const a=i.MathUtils.randFloat(0,1);e[t]=a}const s=new i.DataTexture(e,t,t,i.RedFormat,i.FloatType);return s.needsUpdate=!0,s}}exports.GlitchPass=n;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@babel/runtime/helpers/defineProperty"),e=require("./Pass.cjs.js"),i=require("three"),a=require("../shaders/DigitalGlitch.cjs.js");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=s(t);class n extends e.Pass{constructor(t=64){super(),r.default(this,"material",void 0),r.default(this,"fsQuad",void 0),r.default(this,"goWild",void 0),r.default(this,"curF",void 0),r.default(this,"randX",void 0),r.default(this,"uniforms",void 0),this.uniforms=i.UniformsUtils.clone(a.DigitalGlitch.uniforms),this.uniforms.tDisp.value=this.generateHeightmap(t),this.material=new i.ShaderMaterial({uniforms:this.uniforms,vertexShader:a.DigitalGlitch.vertexShader,fragmentShader:a.DigitalGlitch.fragmentShader}),this.fsQuad=new e.FullScreenQuad(this.material),this.goWild=!1,this.curF=0,this.generateTrigger()}render(t,e,a){!1===t.capabilities.isWebGL2&&(this.uniforms.tDisp.value.format=i.LuminanceFormat),this.uniforms.tDiffuse.value=a.texture,this.uniforms.seed.value=Math.random(),this.uniforms.byp.value=0,this.curF%this.randX==0||1==this.goWild?(this.uniforms.amount.value=Math.random()/30,this.uniforms.angle.value=i.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.seed_x.value=i.MathUtils.randFloat(-1,1),this.uniforms.seed_y.value=i.MathUtils.randFloat(-1,1),this.uniforms.distortion_x.value=i.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=i.MathUtils.randFloat(0,1),this.curF=0,this.generateTrigger()):this.curF%this.randX<this.randX/5?(this.uniforms.amount.value=Math.random()/90,this.uniforms.angle.value=i.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.distortion_x.value=i.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=i.MathUtils.randFloat(0,1),this.uniforms.seed_x.value=i.MathUtils.randFloat(-.3,.3),this.uniforms.seed_y.value=i.MathUtils.randFloat(-.3,.3)):0==this.goWild&&(this.uniforms.byp.value=1),this.curF++,this.renderToScreen?(t.setRenderTarget(null),this.fsQuad.render(t)):(t.setRenderTarget(e),this.clear&&t.clear(),this.fsQuad.render(t))}generateTrigger(){this.randX=i.MathUtils.randInt(120,240)}generateHeightmap(t){const e=new Float32Array(t*t),a=t*t;for(let t=0;t<a;t++){const a=i.MathUtils.randFloat(0,1);e[t]=a}const s=new i.DataTexture(e,t,t,i.RedFormat,i.FloatType);return s.needsUpdate=!0,s}}exports.GlitchPass=n;
@@ -19,14 +19,12 @@ class GlitchPass extends Pass {
19
19
 
20
20
  _defineProperty(this, "uniforms", void 0);
21
21
 
22
- if (DigitalGlitch === undefined) console.error('THREE.GlitchPass relies on DigitalGlitch');
23
- const shader = DigitalGlitch;
24
- this.uniforms = UniformsUtils.clone(shader.uniforms);
22
+ this.uniforms = UniformsUtils.clone(DigitalGlitch.uniforms);
25
23
  this.uniforms['tDisp'].value = this.generateHeightmap(dt_size);
26
24
  this.material = new ShaderMaterial({
27
25
  uniforms: this.uniforms,
28
- vertexShader: shader.vertexShader,
29
- fragmentShader: shader.fragmentShader
26
+ vertexShader: DigitalGlitch.vertexShader,
27
+ fragmentShader: DigitalGlitch.fragmentShader
30
28
  });
31
29
  this.fsQuad = new FullScreenQuad(this.material);
32
30
  this.goWild = false;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./ShaderPass.cjs.js");require("@babel/runtime/helpers/defineProperty"),require("three"),require("./Pass.cjs.js");const e={defines:{USE_3DTEXTURE:1},uniforms:{lut3d:{value:null},lut:{value:null},lutSize:{value:0},tDiffuse:{value:null},intensity:{value:1}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}\n\n\t",fragmentShader:"\n\t\tprecision highp sampler3D;\n\n\t\tuniform float lutSize;\n\t\t#if USE_3DTEXTURE\n\t\tuniform sampler3D lut3d;\n\t\t#else\n\t\tuniform sampler2D lut;\n\n\t\tvec3 lutLookup( sampler2D tex, float size, vec3 rgb ) {\n\n\t\t\tfloat sliceHeight = 1.0 / size;\n\t\t\tfloat yPixelHeight = 1.0 / ( size * size );\n\n\t\t\t// Get the slices on either side of the sample\n\t\t\tfloat slice = rgb.b * size;\n\t\t\tfloat interp = fract( slice );\n\t\t\tfloat slice0 = slice - interp;\n\t\t\tfloat centeredInterp = interp - 0.5;\n\n\t\t\tfloat slice1 = slice0 + sign( centeredInterp );\n\n\t\t\t// Pull y sample in by half a pixel in each direction to avoid color\n\t\t\t// bleeding from adjacent slices.\n\t\t\tfloat greenOffset = clamp( rgb.g * sliceHeight, yPixelHeight * 0.5, sliceHeight - yPixelHeight * 0.5 );\n\n\t\t\tvec2 uv0 = vec2(\n\t\t\t\trgb.r,\n\t\t\t\tslice0 * sliceHeight + greenOffset\n\t\t\t);\n\t\t\tvec2 uv1 = vec2(\n\t\t\t\trgb.r,\n\t\t\t\tslice1 * sliceHeight + greenOffset\n\t\t\t);\n\n\t\t\tvec3 sample0 = texture2D( tex, uv0 ).rgb;\n\t\t\tvec3 sample1 = texture2D( tex, uv1 ).rgb;\n\n\t\t\treturn mix( sample0, sample1, abs( centeredInterp ) );\n\n\t\t}\n\t\t#endif\n\n\t\tvarying vec2 vUv;\n\t\tuniform float intensity;\n\t\tuniform sampler2D tDiffuse;\n\t\tvoid main() {\n\n\t\t\tvec4 val = texture2D( tDiffuse, vUv );\n\t\t\tvec4 lutVal;\n\n\t\t\t// pull the sample in by half a pixel so the sample begins\n\t\t\t// at the center of the edge pixels.\n\t\t\tfloat pixelWidth = 1.0 / lutSize;\n\t\t\tfloat halfPixelWidth = 0.5 / lutSize;\n\t\t\tvec3 uvw = vec3( halfPixelWidth ) + val.rgb * ( 1.0 - pixelWidth );\n\n\t\t\t#if USE_3DTEXTURE\n\n\t\t\tlutVal = vec4( texture( lut3d, uvw ).rgb, val.a );\n\n\t\t\t#else\n\n\t\t\tlutVal = vec4( lutLookup( lut, lutSize, uvw ), val.a );\n\n\t\t\t#endif\n\n\t\t\tgl_FragColor = vec4( mix( val, lutVal, intensity ) );\n\n\t\t}\n\n\t"};class n extends t.ShaderPass{set lut(t){const e=this.material;if(t!==this.lut&&(e.uniforms.lut3d.value=null,e.uniforms.lut.value=null,t)){const n=t.isDataTexture3D?1:0;n!==e.defines.USE_3DTEXTURE&&(e.defines.USE_3DTEXTURE=n,e.needsUpdate=!0),e.uniforms.lutSize.value=t.image.width,t.isDataTexture3D?e.uniforms.lut3d.value=t:e.uniforms.lut.value=t}}get lut(){return this.material.uniforms.lut.value||this.material.uniforms.lut3d.value}set intensity(t){this.material.uniforms.intensity.value=t}get intensity(){return this.material.uniforms.intensity.value}constructor(t={}){super(e),this.lut=t.lut||null,this.intensity="intensity"in t?t.intensity:1}}exports.LUTPass=n;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./ShaderPass.cjs.js");require("@babel/runtime/helpers/defineProperty"),require("three"),require("./Pass.cjs.js");const e={defines:{USE_3DTEXTURE:1},uniforms:{lut3d:{value:null},lut:{value:null},lutSize:{value:0},tDiffuse:{value:null},intensity:{value:1}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}\n\n\t",fragmentShader:"\n\n\t\tuniform float lutSize;\n\t\t#if USE_3DTEXTURE\n\t\tprecision highp sampler3D;\n\t\tuniform sampler3D lut3d;\n\t\t#else\n\t\tuniform sampler2D lut;\n\n\t\tvec3 lutLookup( sampler2D tex, float size, vec3 rgb ) {\n\n\t\t\tfloat sliceHeight = 1.0 / size;\n\t\t\tfloat yPixelHeight = 1.0 / ( size * size );\n\n\t\t\t// Get the slices on either side of the sample\n\t\t\tfloat slice = rgb.b * size;\n\t\t\tfloat interp = fract( slice );\n\t\t\tfloat slice0 = slice - interp;\n\t\t\tfloat centeredInterp = interp - 0.5;\n\n\t\t\tfloat slice1 = slice0 + sign( centeredInterp );\n\n\t\t\t// Pull y sample in by half a pixel in each direction to avoid color\n\t\t\t// bleeding from adjacent slices.\n\t\t\tfloat greenOffset = clamp( rgb.g * sliceHeight, yPixelHeight * 0.5, sliceHeight - yPixelHeight * 0.5 );\n\n\t\t\tvec2 uv0 = vec2(\n\t\t\t\trgb.r,\n\t\t\t\tslice0 * sliceHeight + greenOffset\n\t\t\t);\n\t\t\tvec2 uv1 = vec2(\n\t\t\t\trgb.r,\n\t\t\t\tslice1 * sliceHeight + greenOffset\n\t\t\t);\n\n\t\t\tvec3 sample0 = texture2D( tex, uv0 ).rgb;\n\t\t\tvec3 sample1 = texture2D( tex, uv1 ).rgb;\n\n\t\t\treturn mix( sample0, sample1, abs( centeredInterp ) );\n\n\t\t}\n\t\t#endif\n\n\t\tvarying vec2 vUv;\n\t\tuniform float intensity;\n\t\tuniform sampler2D tDiffuse;\n\t\tvoid main() {\n\n\t\t\tvec4 val = texture2D( tDiffuse, vUv );\n\t\t\tvec4 lutVal;\n\n\t\t\t// pull the sample in by half a pixel so the sample begins\n\t\t\t// at the center of the edge pixels.\n\t\t\tfloat pixelWidth = 1.0 / lutSize;\n\t\t\tfloat halfPixelWidth = 0.5 / lutSize;\n\t\t\tvec3 uvw = vec3( halfPixelWidth ) + val.rgb * ( 1.0 - pixelWidth );\n\n\t\t\t#if USE_3DTEXTURE\n\n\t\t\tlutVal = vec4( texture( lut3d, uvw ).rgb, val.a );\n\n\t\t\t#else\n\n\t\t\tlutVal = vec4( lutLookup( lut, lutSize, uvw ), val.a );\n\n\t\t\t#endif\n\n\t\t\tgl_FragColor = vec4( mix( val, lutVal, intensity ) );\n\n\t\t}\n\n\t"};class n extends t.ShaderPass{set lut(t){const e=this.material;if(t!==this.lut&&(e.uniforms.lut3d.value=null,e.uniforms.lut.value=null,t)){const n=t.isData3DTexture?1:0;n!==e.defines.USE_3DTEXTURE&&(e.defines.USE_3DTEXTURE=n,e.needsUpdate=!0),e.uniforms.lutSize.value=t.image.width,t.isData3DTexture?e.uniforms.lut3d.value=t:e.uniforms.lut.value=t}}get lut(){return this.material.uniforms.lut.value||this.material.uniforms.lut3d.value}set intensity(t){this.material.uniforms.intensity.value=t}get intensity(){return this.material.uniforms.intensity.value}constructor(t={}){super(e),this.lut=t.lut||null,this.intensity="intensity"in t?t.intensity:1}}exports.LUTPass=n;
@@ -38,10 +38,10 @@ const LUTShader = {
38
38
  fragmentShader:
39
39
  /* glsl */
40
40
  `
41
- precision highp sampler3D;
42
41
 
43
42
  uniform float lutSize;
44
43
  #if USE_3DTEXTURE
44
+ precision highp sampler3D;
45
45
  uniform sampler3D lut3d;
46
46
  #else
47
47
  uniform sampler2D lut;
@@ -120,7 +120,7 @@ class LUTPass extends ShaderPass {
120
120
  material.uniforms.lut.value = null;
121
121
 
122
122
  if (v) {
123
- const is3dTextureDefine = v.isDataTexture3D ? 1 : 0;
123
+ const is3dTextureDefine = v.isData3DTexture ? 1 : 0;
124
124
 
125
125
  if (is3dTextureDefine !== material.defines.USE_3DTEXTURE) {
126
126
  material.defines.USE_3DTEXTURE = is3dTextureDefine;
@@ -129,7 +129,7 @@ class LUTPass extends ShaderPass {
129
129
 
130
130
  material.uniforms.lutSize.value = v.image.width;
131
131
 
132
- if (v.isDataTexture3D) {
132
+ if (v.isData3DTexture) {
133
133
  material.uniforms.lut3d.value = v;
134
134
  } else {
135
135
  material.uniforms.lut.value = v;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=function(t){e.Object3D.call(this),this.element=t||document.createElement("div"),this.element.style.position="absolute",this.addEventListener("removed",(function(){this.traverse((function(e){e.element instanceof Element&&null!==e.element.parentNode&&e.element.parentNode.removeChild(e.element)}))}))};t.prototype=Object.assign(Object.create(e.Object3D.prototype),{constructor:t,copy:function(t,n){return e.Object3D.prototype.copy.call(this,t,n),this.element=t.element.cloneNode(!0),this}});exports.CSS2DObject=t,exports.CSS2DRenderer=function(){var n,r,o,i,a=this,s=new e.Vector3,l=new e.Matrix4,c=new e.Matrix4,d={objects:new WeakMap},u=document.createElement("div");u.style.overflow="hidden",this.domElement=u,this.getSize=function(){return{width:n,height:r}},this.setSize=function(e,t){o=(n=e)/2,i=(r=t)/2,u.style.width=e+"px",u.style.height=t+"px"};var p,m,h=function(e,n,r){if(e instanceof t){e.onBeforeRender(a,n,r),s.setFromMatrixPosition(e.matrixWorld),s.applyMatrix4(c);var l=e.element;l.style.transform="translate(-50%,-50%) translate("+(s.x*o+o)+"px,"+(-s.y*i+i)+"px)",l.style.display=e.visible&&s.z>=-1&&s.z<=1?"":"none";var p={distanceToCameraSquared:f(r,e)};d.objects.set(e,p),l.parentNode!==u&&u.appendChild(l),e.onAfterRender(a,n,r)}for(let t=0,o=e.children.length;t<o;t++)h(e.children[t],n,r)},f=(p=new e.Vector3,m=new e.Vector3,function(e,t){return p.setFromMatrixPosition(e.matrixWorld),m.setFromMatrixPosition(t.matrixWorld),p.distanceToSquared(m)}),x=function(e){var n=function(e){var n=[];return e.traverse((function(e){e instanceof t&&n.push(e)})),n}(e).sort((function(e,t){return d.objects.get(e).distanceToCameraSquared-d.objects.get(t).distanceToCameraSquared})),r=n.length;for(let e=0,t=n.length;e<t;e++)n[e].element.style.zIndex=r-e};this.render=function(e,t){!0===e.autoUpdate&&e.updateMatrixWorld(),null===t.parent&&t.updateMatrixWorld(),l.copy(t.matrixWorldInverse),c.multiplyMatrices(t.projectionMatrix,l),h(e,e,t),x(e)}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Object3D{constructor(e=document.createElement("div")){super(),this.isCSS2DObject=!0,this.element=e,this.element.style.position="absolute",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.addEventListener("removed",(function(){this.traverse((function(e){e.element instanceof Element&&null!==e.element.parentNode&&e.element.parentNode.removeChild(e.element)}))}))}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this}}const r=new e.Vector3,n=new e.Matrix4,o=new e.Matrix4,i=new e.Vector3,s=new e.Vector3;exports.CSS2DObject=t,exports.CSS2DRenderer=class{constructor(e={}){const t=this;let l,a,d,c;const u={objects:new WeakMap},m=void 0!==e.element?e.element:document.createElement("div");function p(e,n,i){if(e.isCSS2DObject){r.setFromMatrixPosition(e.matrixWorld),r.applyMatrix4(o);const s=!0===e.visible&&r.z>=-1&&r.z<=1&&!0===e.layers.test(i.layers);if(e.element.style.display=!0===s?"":"none",!0===s){e.onBeforeRender(t,n,i);const o=e.element;o.style.transform="translate(-50%,-50%) translate("+(r.x*d+d)+"px,"+(-r.y*c+c)+"px)",o.parentNode!==m&&m.appendChild(o),e.onAfterRender(t,n,i)}const l={distanceToCameraSquared:h(i,e)};u.objects.set(e,l)}for(let t=0,r=e.children.length;t<r;t++)p(e.children[t],n,i)}function h(e,t){return i.setFromMatrixPosition(e.matrixWorld),s.setFromMatrixPosition(t.matrixWorld),i.distanceToSquared(s)}m.style.overflow="hidden",this.domElement=m,this.getSize=function(){return{width:l,height:a}},this.render=function(e,t){!0!==e.matrixWorldAutoUpdate&&!0!==e.autoUpdate||e.updateMatrixWorld(),null!==t.parent||null!=t.matrixWorldAutoUpdate&&!0!==t.matrixWorldAutoUpdate||t.updateMatrixWorld(),n.copy(t.matrixWorldInverse),o.multiplyMatrices(t.projectionMatrix,n),p(e,e,t),function(e){const t=function(e){const t=[];return e.traverse((function(e){e.isCSS2DObject&&t.push(e)})),t}(e).sort((function(e,t){if(e.renderOrder!==t.renderOrder)return t.renderOrder-e.renderOrder;return u.objects.get(e).distanceToCameraSquared-u.objects.get(t).distanceToCameraSquared})),r=t.length;for(let e=0,n=t.length;e<n;e++)t[e].element.style.zIndex=r-e}(e)},this.setSize=function(e,t){l=e,a=t,d=l/2,c=a/2,m.style.width=e+"px",m.style.height=t+"px"}}};
@@ -1,124 +1,149 @@
1
1
  import { Object3D, Vector3, Matrix4 } from 'three';
2
2
 
3
- var CSS2DObject = function (element) {
4
- Object3D.call(this);
5
- this.element = element || document.createElement('div');
6
- this.element.style.position = 'absolute';
7
- this.addEventListener('removed', function () {
8
- this.traverse(function (object) {
9
- if (object.element instanceof Element && object.element.parentNode !== null) {
10
- object.element.parentNode.removeChild(object.element);
11
- }
3
+ class CSS2DObject extends Object3D {
4
+ constructor(element = document.createElement('div')) {
5
+ super();
6
+ this.isCSS2DObject = true;
7
+ this.element = element;
8
+ this.element.style.position = 'absolute';
9
+ this.element.style.userSelect = 'none';
10
+ this.element.setAttribute('draggable', false);
11
+ this.addEventListener('removed', function () {
12
+ this.traverse(function (object) {
13
+ if (object.element instanceof Element && object.element.parentNode !== null) {
14
+ object.element.parentNode.removeChild(object.element);
15
+ }
16
+ });
12
17
  });
13
- });
14
- };
18
+ }
15
19
 
16
- CSS2DObject.prototype = Object.assign(Object.create(Object3D.prototype), {
17
- constructor: CSS2DObject,
18
- copy: function (source, recursive) {
19
- Object3D.prototype.copy.call(this, source, recursive);
20
+ copy(source, recursive) {
21
+ super.copy(source, recursive);
20
22
  this.element = source.element.cloneNode(true);
21
23
  return this;
22
24
  }
23
- }); //
24
25
 
25
- var CSS2DRenderer = function () {
26
- var _this = this;
26
+ }
27
+
28
+ const _vector = /*#__PURE__*/new Vector3();
29
+
30
+ const _viewMatrix = /*#__PURE__*/new Matrix4();
31
+
32
+ const _viewProjectionMatrix = /*#__PURE__*/new Matrix4();
27
33
 
28
- var _width, _height;
34
+ const _a = /*#__PURE__*/new Vector3();
29
35
 
30
- var _widthHalf, _heightHalf;
36
+ const _b = /*#__PURE__*/new Vector3();
31
37
 
32
- var vector = new Vector3();
33
- var viewMatrix = new Matrix4();
34
- var viewProjectionMatrix = new Matrix4();
35
- var cache = {
36
- objects: new WeakMap()
37
- };
38
- var domElement = document.createElement('div');
39
- domElement.style.overflow = 'hidden';
40
- this.domElement = domElement;
38
+ class CSS2DRenderer {
39
+ constructor(parameters = {}) {
40
+ const _this = this;
41
41
 
42
- this.getSize = function () {
43
- return {
44
- width: _width,
45
- height: _height
42
+ let _width, _height;
43
+
44
+ let _widthHalf, _heightHalf;
45
+
46
+ const cache = {
47
+ objects: new WeakMap()
46
48
  };
47
- };
48
-
49
- this.setSize = function (width, height) {
50
- _width = width;
51
- _height = height;
52
- _widthHalf = _width / 2;
53
- _heightHalf = _height / 2;
54
- domElement.style.width = width + 'px';
55
- domElement.style.height = height + 'px';
56
- };
57
-
58
- var renderObject = function (object, scene, camera) {
59
- if (object instanceof CSS2DObject) {
60
- object.onBeforeRender(_this, scene, camera);
61
- vector.setFromMatrixPosition(object.matrixWorld);
62
- vector.applyMatrix4(viewProjectionMatrix);
63
- var element = object.element;
64
- element.style.transform = 'translate(-50%,-50%) translate(' + (vector.x * _widthHalf + _widthHalf) + 'px,' + (-vector.y * _heightHalf + _heightHalf) + 'px)';
65
- element.style.display = object.visible && vector.z >= -1 && vector.z <= 1 ? '' : 'none';
66
- var objectData = {
67
- distanceToCameraSquared: getDistanceToSquared(camera, object)
49
+ const domElement = parameters.element !== undefined ? parameters.element : document.createElement('div');
50
+ domElement.style.overflow = 'hidden';
51
+ this.domElement = domElement;
52
+
53
+ this.getSize = function () {
54
+ return {
55
+ width: _width,
56
+ height: _height
68
57
  };
69
- cache.objects.set(object, objectData);
58
+ };
59
+
60
+ this.render = function (scene, camera) {
61
+ if (scene.matrixWorldAutoUpdate === true || scene.autoUpdate === true) scene.updateMatrixWorld();
62
+ if (camera.parent === null && (camera.matrixWorldAutoUpdate == null || camera.matrixWorldAutoUpdate === true)) camera.updateMatrixWorld();
63
+
64
+ _viewMatrix.copy(camera.matrixWorldInverse);
65
+
66
+ _viewProjectionMatrix.multiplyMatrices(camera.projectionMatrix, _viewMatrix);
67
+
68
+ renderObject(scene, scene, camera);
69
+ zOrder(scene);
70
+ };
71
+
72
+ this.setSize = function (width, height) {
73
+ _width = width;
74
+ _height = height;
75
+ _widthHalf = _width / 2;
76
+ _heightHalf = _height / 2;
77
+ domElement.style.width = width + 'px';
78
+ domElement.style.height = height + 'px';
79
+ };
80
+
81
+ function renderObject(object, scene, camera) {
82
+ if (object.isCSS2DObject) {
83
+ _vector.setFromMatrixPosition(object.matrixWorld);
84
+
85
+ _vector.applyMatrix4(_viewProjectionMatrix);
70
86
 
71
- if (element.parentNode !== domElement) {
72
- domElement.appendChild(element);
87
+ const visible = object.visible === true && _vector.z >= -1 && _vector.z <= 1 && object.layers.test(camera.layers) === true;
88
+ object.element.style.display = visible === true ? '' : 'none';
89
+
90
+ if (visible === true) {
91
+ object.onBeforeRender(_this, scene, camera);
92
+ const element = object.element;
93
+ element.style.transform = 'translate(-50%,-50%) translate(' + (_vector.x * _widthHalf + _widthHalf) + 'px,' + (-_vector.y * _heightHalf + _heightHalf) + 'px)';
94
+
95
+ if (element.parentNode !== domElement) {
96
+ domElement.appendChild(element);
97
+ }
98
+
99
+ object.onAfterRender(_this, scene, camera);
100
+ }
101
+
102
+ const objectData = {
103
+ distanceToCameraSquared: getDistanceToSquared(camera, object)
104
+ };
105
+ cache.objects.set(object, objectData);
73
106
  }
74
107
 
75
- object.onAfterRender(_this, scene, camera);
108
+ for (let i = 0, l = object.children.length; i < l; i++) {
109
+ renderObject(object.children[i], scene, camera);
110
+ }
76
111
  }
77
112
 
78
- for (let i = 0, l = object.children.length; i < l; i++) {
79
- renderObject(object.children[i], scene, camera);
113
+ function getDistanceToSquared(object1, object2) {
114
+ _a.setFromMatrixPosition(object1.matrixWorld);
115
+
116
+ _b.setFromMatrixPosition(object2.matrixWorld);
117
+
118
+ return _a.distanceToSquared(_b);
80
119
  }
81
- };
82
-
83
- var getDistanceToSquared = function () {
84
- var a = new Vector3();
85
- var b = new Vector3();
86
- return function (object1, object2) {
87
- a.setFromMatrixPosition(object1.matrixWorld);
88
- b.setFromMatrixPosition(object2.matrixWorld);
89
- return a.distanceToSquared(b);
90
- };
91
- }();
92
120
 
93
- var filterAndFlatten = function (scene) {
94
- var result = [];
95
- scene.traverse(function (object) {
96
- if (object instanceof CSS2DObject) result.push(object);
97
- });
98
- return result;
99
- };
100
-
101
- var zOrder = function (scene) {
102
- var sorted = filterAndFlatten(scene).sort(function (a, b) {
103
- var distanceA = cache.objects.get(a).distanceToCameraSquared;
104
- var distanceB = cache.objects.get(b).distanceToCameraSquared;
105
- return distanceA - distanceB;
106
- });
107
- var zMax = sorted.length;
121
+ function filterAndFlatten(scene) {
122
+ const result = [];
123
+ scene.traverse(function (object) {
124
+ if (object.isCSS2DObject) result.push(object);
125
+ });
126
+ return result;
127
+ }
128
+
129
+ function zOrder(scene) {
130
+ const sorted = filterAndFlatten(scene).sort(function (a, b) {
131
+ if (a.renderOrder !== b.renderOrder) {
132
+ return b.renderOrder - a.renderOrder;
133
+ }
108
134
 
109
- for (let i = 0, l = sorted.length; i < l; i++) {
110
- sorted[i].element.style.zIndex = zMax - i;
135
+ const distanceA = cache.objects.get(a).distanceToCameraSquared;
136
+ const distanceB = cache.objects.get(b).distanceToCameraSquared;
137
+ return distanceA - distanceB;
138
+ });
139
+ const zMax = sorted.length;
140
+
141
+ for (let i = 0, l = sorted.length; i < l; i++) {
142
+ sorted[i].element.style.zIndex = zMax - i;
143
+ }
111
144
  }
112
- };
113
-
114
- this.render = function (scene, camera) {
115
- if (scene.autoUpdate === true) scene.updateMatrixWorld();
116
- if (camera.parent === null) camera.updateMatrixWorld();
117
- viewMatrix.copy(camera.matrixWorldInverse);
118
- viewProjectionMatrix.multiplyMatrices(camera.projectionMatrix, viewMatrix);
119
- renderObject(scene, scene, camera);
120
- zOrder(scene);
121
- };
122
- };
145
+ }
146
+
147
+ }
123
148
 
124
149
  export { CSS2DObject, CSS2DRenderer };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t={uniforms:{tDiffuse:{value:null},tDisp:{value:null},byp:{value:0},amount:{value:.08},angle:{value:.02},seed:{value:.02},seed_x:{value:.02},seed_y:{value:.02},distortion_x:{value:.5},distortion_y:{value:.6},col_s:{value:.05}},vertexShader:["varying vec2 vUv;","void main() {","\tvUv = uv;","\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform int byp;","uniform sampler2D tDiffuse;","uniform sampler2D tDisp;","uniform float amount;","uniform float angle;","uniform float seed;","uniform float seed_x;","uniform float seed_y;","uniform float distortion_x;","uniform float distortion_y;","uniform float col_s;","varying vec2 vUv;","float rand(vec2 co){","\treturn fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);","}","void main() {","\tif(byp<1) {","\t\tvec2 p = vUv;","\t\tfloat xs = floor(gl_FragCoord.x / 0.5);","\t\tfloat ys = floor(gl_FragCoord.y / 0.5);","\t\tvec4 normal = texture2D (tDisp, p*seed*seed);","\t\tif(p.y<distortion_x+col_s && p.y>distortion_x-col_s*seed) {","\t\t\tif(seed_x>0.){","\t\t\t\tp.y = 1. - (p.y + distortion_y);","\t\t\t}","\t\t\telse {","\t\t\t\tp.y = distortion_y;","\t\t\t}","\t\t}","\t\tif(p.x<distortion_y+col_s && p.x>distortion_y-col_s*seed) {","\t\t\tif(seed_y>0.){","\t\t\t\tp.x=distortion_x;","\t\t\t}","\t\t\telse {","\t\t\t\tp.x = 1. - (p.x + distortion_x);","\t\t\t}","\t\t}","\t\tp.x+=normal.x*seed_x*(seed/5.);","\t\tp.y+=normal.y*seed_y*(seed/5.);","\t\tvec2 offset = amount * vec2( cos(angle), sin(angle));","\t\tvec4 cr = texture2D(tDiffuse, p + offset);","\t\tvec4 cga = texture2D(tDiffuse, p);","\t\tvec4 cb = texture2D(tDiffuse, p - offset);","\t\tgl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);","\t\tvec4 snow = 200.*amount*vec4(rand(vec2(xs * seed,ys * seed*50.))*0.2);","\t\tgl_FragColor = gl_FragColor+ snow;","\t}","\telse {","\t\tgl_FragColor=texture2D (tDiffuse, vUv);","\t}","}"].join("\n")};exports.DigitalGlitch=t;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t={uniforms:{tDiffuse:{value:null},tDisp:{value:null},byp:{value:0},amount:{value:.08},angle:{value:.02},seed:{value:.02},seed_x:{value:.02},seed_y:{value:.02},distortion_x:{value:.5},distortion_y:{value:.6},col_s:{value:.05}},vertexShader:"varying vec2 vUv;\n void main() {\n \t vUv = uv;\n \t gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"uniform int byp; //should we apply the glitch ?\n uniform sampler2D tDiffuse;\n uniform sampler2D tDisp;\n uniform float amount;\n uniform float angle;\n uniform float seed;\n uniform float seed_x;\n uniform float seed_y;\n uniform float distortion_x;\n uniform float distortion_y;\n uniform float col_s;\n\n varying vec2 vUv;\n\n float rand(vec2 co){\n \t return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);\n }\n\n void main() {\n \tif(byp<1) {\n \t\tvec2 p = vUv;\n \t\tfloat xs = floor(gl_FragCoord.x / 0.5);\n \t\tfloat ys = floor(gl_FragCoord.y / 0.5);\n //based on staffantans glitch shader for unity https://github.com/staffantan/unityglitch\n \t\tvec4 normal = texture2D (tDisp, p*seed*seed);\n \t\tif(p.y<distortion_x+col_s && p.y>distortion_x-col_s*seed) {\n \t\t\tif(seed_x>0.){\n \t\t\t\tp.y = 1. - (p.y + distortion_y);\n \t\t\t}\n \t\t\telse {\n \t\t\t\tp.y = distortion_y;\n \t\t\t}\n \t\t}\n \t\tif(p.x<distortion_y+col_s && p.x>distortion_y-col_s*seed) {\n \t\t\tif(seed_y>0.){\n \t\t\t\tp.x=distortion_x;\n \t\t\t}\n \t\t\telse {\n \t\t\t\tp.x = 1. - (p.x + distortion_x);\n \t\t\t}\n \t\t}\n \t\tp.x+=normal.x*seed_x*(seed/5.);\n \t\tp.y+=normal.y*seed_y*(seed/5.);\n //base from RGB shift shader\n \t\tvec2 offset = amount * vec2( cos(angle), sin(angle));\n \t\tvec4 cr = texture2D(tDiffuse, p + offset);\n \t\tvec4 cga = texture2D(tDiffuse, p);\n \t\tvec4 cb = texture2D(tDiffuse, p - offset);\n \t\tgl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);\n //add noise\n \t\tvec4 snow = 200.*amount*vec4(rand(vec2(xs * seed,ys * seed*50.))*0.2);\n \t\tgl_FragColor = gl_FragColor+ snow;\n \t}\n \telse {\n \t\tgl_FragColor=texture2D (tDiffuse, vUv);\n \t}\n }"};exports.DigitalGlitch=t;
@@ -39,12 +39,68 @@ const DigitalGlitch = {
39
39
  value: 0.05
40
40
  }
41
41
  },
42
- vertexShader: ['varying vec2 vUv;', 'void main() {', ' vUv = uv;', ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );', '}'].join('\n'),
43
- fragmentShader: ['uniform int byp;', //should we apply the glitch ?
44
- 'uniform sampler2D tDiffuse;', 'uniform sampler2D tDisp;', 'uniform float amount;', 'uniform float angle;', 'uniform float seed;', 'uniform float seed_x;', 'uniform float seed_y;', 'uniform float distortion_x;', 'uniform float distortion_y;', 'uniform float col_s;', 'varying vec2 vUv;', 'float rand(vec2 co){', ' return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);', '}', 'void main() {', ' if(byp<1) {', ' vec2 p = vUv;', ' float xs = floor(gl_FragCoord.x / 0.5);', ' float ys = floor(gl_FragCoord.y / 0.5);', //based on staffantans glitch shader for unity https://github.com/staffantan/unityglitch
45
- ' vec4 normal = texture2D (tDisp, p*seed*seed);', ' if(p.y<distortion_x+col_s && p.y>distortion_x-col_s*seed) {', ' if(seed_x>0.){', ' p.y = 1. - (p.y + distortion_y);', ' }', ' else {', ' p.y = distortion_y;', ' }', ' }', ' if(p.x<distortion_y+col_s && p.x>distortion_y-col_s*seed) {', ' if(seed_y>0.){', ' p.x=distortion_x;', ' }', ' else {', ' p.x = 1. - (p.x + distortion_x);', ' }', ' }', ' p.x+=normal.x*seed_x*(seed/5.);', ' p.y+=normal.y*seed_y*(seed/5.);', //base from RGB shift shader
46
- ' vec2 offset = amount * vec2( cos(angle), sin(angle));', ' vec4 cr = texture2D(tDiffuse, p + offset);', ' vec4 cga = texture2D(tDiffuse, p);', ' vec4 cb = texture2D(tDiffuse, p - offset);', ' gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);', //add noise
47
- ' vec4 snow = 200.*amount*vec4(rand(vec2(xs * seed,ys * seed*50.))*0.2);', ' gl_FragColor = gl_FragColor+ snow;', ' }', ' else {', ' gl_FragColor=texture2D (tDiffuse, vUv);', ' }', '}'].join('\n')
42
+ vertexShader: `varying vec2 vUv;
43
+ void main() {
44
+ vUv = uv;
45
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
46
+ }`,
47
+ fragmentShader: `uniform int byp; //should we apply the glitch ?
48
+ uniform sampler2D tDiffuse;
49
+ uniform sampler2D tDisp;
50
+ uniform float amount;
51
+ uniform float angle;
52
+ uniform float seed;
53
+ uniform float seed_x;
54
+ uniform float seed_y;
55
+ uniform float distortion_x;
56
+ uniform float distortion_y;
57
+ uniform float col_s;
58
+
59
+ varying vec2 vUv;
60
+
61
+ float rand(vec2 co){
62
+ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
63
+ }
64
+
65
+ void main() {
66
+ if(byp<1) {
67
+ vec2 p = vUv;
68
+ float xs = floor(gl_FragCoord.x / 0.5);
69
+ float ys = floor(gl_FragCoord.y / 0.5);
70
+ //based on staffantans glitch shader for unity https://github.com/staffantan/unityglitch
71
+ vec4 normal = texture2D (tDisp, p*seed*seed);
72
+ if(p.y<distortion_x+col_s && p.y>distortion_x-col_s*seed) {
73
+ if(seed_x>0.){
74
+ p.y = 1. - (p.y + distortion_y);
75
+ }
76
+ else {
77
+ p.y = distortion_y;
78
+ }
79
+ }
80
+ if(p.x<distortion_y+col_s && p.x>distortion_y-col_s*seed) {
81
+ if(seed_y>0.){
82
+ p.x=distortion_x;
83
+ }
84
+ else {
85
+ p.x = 1. - (p.x + distortion_x);
86
+ }
87
+ }
88
+ p.x+=normal.x*seed_x*(seed/5.);
89
+ p.y+=normal.y*seed_y*(seed/5.);
90
+ //base from RGB shift shader
91
+ vec2 offset = amount * vec2( cos(angle), sin(angle));
92
+ vec4 cr = texture2D(tDiffuse, p + offset);
93
+ vec4 cga = texture2D(tDiffuse, p);
94
+ vec4 cb = texture2D(tDiffuse, p - offset);
95
+ gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);
96
+ //add noise
97
+ vec4 snow = 200.*amount*vec4(rand(vec2(xs * seed,ys * seed*50.))*0.2);
98
+ gl_FragColor = gl_FragColor+ snow;
99
+ }
100
+ else {
101
+ gl_FragColor=texture2D (tDiffuse, vUv);
102
+ }
103
+ }`
48
104
  };
49
105
 
50
106
  export { DigitalGlitch };