Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phixl

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phixl - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

36

dist/attributes.d.ts
/**
* @fileoverview Shader attributes module.
*/
/**
* The type of data that can be sent to a shader as an attribute.
*/
export declare type AttributeData = Float32List | Float32List[];

@@ -14,8 +17,20 @@ /**

constructor(name_: string, dimension_: number, data_: Data);
/**
* Send the attribute data to the shader.
*/
send(gl: WebGLRenderingContext, program: WebGLProgram): void;
/**
* Get the number of vertices that will be sent to the shader.
* This is only used if the shader is using gl.drawArrays(...).
*/
length(): number;
}
/**
* Type of function used to create attributes.
*/
declare type AttributeBuilder = (name: string, data: Float32List) => Attribute<Float32List>;
/**
* Sends a float attribute to a shader.
* @param name of the attribute in the shader
* @param data the attribute will send
*/

@@ -25,2 +40,4 @@ export declare const FloatAttribute: AttributeBuilder;

* Sends a 2-dimensional vector attribute to a shader.
* @param name of the attribute in the shader
* @param data the attribute will send
*/

@@ -30,2 +47,4 @@ export declare const Vec2Attribute: AttributeBuilder;

* Sends a 3-dimensional vector attribute to a shader.
* @param name of the attribute in the shader
* @param data the attribute will send
*/

@@ -35,11 +54,24 @@ export declare const Vec3Attribute: AttributeBuilder;

* Sends a 4-dimensional vector attribute to a shader.
* @param name of the attribute in the shader
* @param data the attribute will send
*/
export declare const Vec4Attribute: AttributeBuilder;
/**
* Abstraction for sending a matrix attribute to a shader.
*/
declare class MatrixAttribute extends Attribute<Float32List[]> {
constructor(name: string, dimension: number, data: Float32List[]);
/**
* Send the data to the shader.
*/
send(gl: WebGLRenderingContext, program: WebGLProgram): void;
}
/**
* Type of function used to create matrix attributes.
*/
declare type MatAttributeBuilder = (name: string, data: Float32List[]) => MatrixAttribute;
/**
* Sends a 2-dimensional matrix attribute to a shader.
* @param name of the attribute in the shader
* @param data the attribute will send
*/

@@ -49,2 +81,4 @@ export declare const Mat2Attribute: MatAttributeBuilder;

* Sends a 3-dimensional matrix attribute to a shader.
* @param name of the attribute in the shader
* @param data the attribute will send
*/

@@ -54,4 +88,6 @@ export declare const Mat3Attribute: MatAttributeBuilder;

* Sends a 4-dimensional matrix attribute to a shader.
* @param name of the attribute in the shader
* @param data the attribute will send
*/
export declare const Mat4Attribute: MatAttributeBuilder;
export {};

2

dist/index.js

@@ -1,2 +0,2 @@

module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.glRender=t.cubeTextureFromFramebuffer=t.texture2DFromFramebuffer=t.renderBuffer=t.sendCubeTexture=t.send2DTexture=t.cubeTexure=t.texture2d=t.isVideo=t.newTextureOffset=t.sendVectorUniform=t.sendMatrixUniform=t.sendBytesUniform=t.UniformType=t.sendMatrixAttribute=t.sendAttribute=t.sendIndices=t.glProgram=t.glContext=void 0;const n=r(1);t.glContext=e=>{const t=e.getContext("webgl",{preserveDrawingBuffer:!0})||e.getContext("experimental-webgl",{preserveDrawingBuffer:!0});return t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t};const i=(e,t,r)=>{if(e.shaderSource(t,r),e.compileShader(t),!e.getShaderParameter(t,e.COMPILE_STATUS))throw new Error("Shader failed to compile: "+e.getShaderInfoLog(t));return t};var o;t.glProgram=(e,t,r)=>{const n=i(e,e.createShader(WebGLRenderingContext.VERTEX_SHADER),t),o=i(e,e.createShader(WebGLRenderingContext.FRAGMENT_SHADER),r),a=e.createProgram();if(e.attachShader(a,n),e.attachShader(a,o),e.linkProgram(a),!e.getProgramParameter(a,e.LINK_STATUS))throw new Error("Shader failed to compile: "+e.getProgramInfoLog(a));return a},t.sendIndices=(e,t)=>{e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,e.createBuffer()),e.bufferData(e.ELEMENT_ARRAY_BUFFER,t,e.STATIC_DRAW)},t.sendAttribute=(e,t,r,n,i,o)=>{const a=e.getAttribLocation(t,n);e.bindBuffer(e.ARRAY_BUFFER,r),e.vertexAttribPointer(a,o,e.FLOAT,!1,0,0),e.enableVertexAttribArray(a),e.bufferData(e.ARRAY_BUFFER,i,e.STATIC_DRAW)},t.sendMatrixAttribute=(e,t,r,n,i,o)=>{const a=e.getAttribLocation(t,n);for(let t=0;t<o;t++)e.enableVertexAttribArray(a+t),e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,i[t],e.STATIC_DRAW),e.vertexAttribPointer(a+t,o,e.FLOAT,!1,0,0)},function(e){e.BOOLEAN="boolean",e.FLOAT="float",e.INTEGER="integer",e.VECTOR="vector",e.MATRIX="matrix",e.TEXTURE="texture"}(o=t.UniformType||(t.UniformType={})),t.sendBytesUniform=(e,t,r,n,i)=>{const a=e.getUniformLocation(t,r);switch(n){case o.BOOLEAN:e.uniform1i(a,i);break;case o.FLOAT:e.uniform1f(a,i);break;case o.INTEGER:e.uniform1i(a,i);break;default:throw new Error("Unexpected uniform type: "+n)}},t.sendMatrixUniform=(e,t,r,n,i)=>{const o=e.getUniformLocation(t,r);switch(n){case 2:e.uniformMatrix2fv(o,!1,i);break;case 3:e.uniformMatrix3fv(o,!1,i);break;case 4:e.uniformMatrix4fv(o,!1,i)}},t.sendVectorUniform=(e,t,r,n,i)=>{const o=e.getUniformLocation(t,r);switch(n){case 2:e.uniform2fv(o,i);break;case 3:e.uniform3fv(o,i);break;case 4:e.uniform4fv(o,i);break;default:throw new Error("Unexpected dimension: "+n)}};const a=new WeakMap;t.newTextureOffset=(e,t)=>{const r=a.get(e)||[];for(let e=0;e<r.length;e++)if(r[e]===t)return e;const n=r.length;if(32===n)throw new Error("Already at maximum number of textures for this program");return r.push(t),n||a.set(e,r),n},t.isVideo=e=>n.isCube(e)?Object.keys(e).some(t=>e[t]instanceof HTMLVideoElement):e instanceof HTMLVideoElement,t.texture2d=(e,r)=>{const i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r),!t.isVideo(r)&&n.isPowerOfTwo(r.width)&&n.isPowerOfTwo(r.height)?e.generateMipmap(e.TEXTURE_2D):(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR)),i};const s={posx:WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X,negx:WebGLRenderingContext.TEXTURE_CUBE_MAP_NEGATIVE_X,posy:WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_Y,negy:WebGLRenderingContext.TEXTURE_CUBE_MAP_NEGATIVE_Y,posz:WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_Z,negz:WebGLRenderingContext.TEXTURE_CUBE_MAP_NEGATIVE_Z};t.cubeTexure=(e,r)=>{const i=e.createTexture();e.bindTexture(e.TEXTURE_CUBE_MAP,i);for(const t of n.cubeFaces())e.texImage2D(s[t],0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r[t]);return!t.isVideo(r)&&(e=>{for(const t of n.cubeFaces())if(!n.isPowerOfTwo(e[t].width)||!n.isPowerOfTwo(e[t].height))return!1;return!0})(r)?e.generateMipmap(e.TEXTURE_CUBE_MAP):(e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),i};const u=e=>(t,r,n,i,o)=>{const a=t.getUniformLocation(r,n);t.uniform1i(a,i),t.activeTexture(t.TEXTURE0+i),t.bindTexture(e,o)};t.send2DTexture=u(WebGLRenderingContext.TEXTURE_2D),t.sendCubeTexture=u(WebGLRenderingContext.TEXTURE_CUBE_MAP),t.renderBuffer=(e,t,r,n)=>{const i=e.createRenderbuffer();return e.bindFramebuffer(e.FRAMEBUFFER,t),e.bindRenderbuffer(e.RENDERBUFFER,i),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,r,n),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,i),i},t.texture2DFromFramebuffer=(e,t,r,n)=>{const i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindFramebuffer(e.FRAMEBUFFER,t),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r,n,0,e.RGBA,e.UNSIGNED_BYTE,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),i},t.cubeTextureFromFramebuffer=(e,t,r,i)=>{const o=e.createTexture();e.bindTexture(e.TEXTURE_CUBE_MAP,o),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);for(const a of n.cubeFaces())e.bindFramebuffer(e.FRAMEBUFFER,t[a]),e.texImage2D(s[a],0,e.RGBA,r,i,0,e.RGBA,e.UNSIGNED_BYTE,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,s[a],o,0);return o},t.glRender=(e,t,r,n,i,o)=>{e.clearColor(0,0,0,1),r&&(e.clearDepth(e.getParameter(e.DEPTH_CLEAR_VALUE)),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)),e.viewport(...n),o?e.drawElements(i,t,e.UNSIGNED_SHORT,0):e.drawArrays(i,0,t)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.cube=t.isCube=t.cubeFaces=t.perspective=t.lookAt=t.rotate=t.scale=t.translate=t.multiply=t.identity=t.add=t.isVector3=t.isPowerOfTwo=void 0,t.isPowerOfTwo=e=>0==(e&e-1),t.isVector3=e=>Array.isArray(e)&&3===e.length&&e.every(e=>!isNaN(e));const n=e=>{const t=Math.hypot(...e);if(!t)throw new Error("Cannot normalize a vector with no length");return e.map(e=>e/t)};t.add=(e,t)=>e.map((e,r)=>e+t[r]);const i=(e,t)=>e.reduce((e,r,n)=>e+r*t[n],0),o=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],a=e=>Math.sqrt(e.length),s=e=>[...Array(Math.pow(e,2))].map(()=>0);t.identity=e=>{const t=s(e);for(let r=0;r<e;r++)t[r*e+r]=1;return t};const u=(e,t,r)=>{const n=[...Array(r)].map(()=>0);for(let i=0;i<r;i++)for(let o=0;o<r;o++)n[i]+=e[i*r+o]*t[o];return n};t.multiply=(e,t)=>{const r=a(e);if(r!==a(t)){if(r!==t.length)throw new Error("Cannot multiply, incompatible dimensions");return u(e,t,r)}return((e,t,r)=>{const n=s(r);for(let i=0;i<r;i++)for(let o=0;o<r;o++)for(let a=0;a<r;a++)n[r*i+o]+=e[r*i+a]*t[r*a+o];return n})(e,t,r)},t.translate=(e,t,r,n)=>{const i=e.slice(0,16);return i[12]+=t,i[13]+=r,i[14]+=n,i},t.scale=(e,...r)=>{if(!r.length)throw new Error("You must provide at least one number to scale a matrix");const n=a(e);if(4===n&&2===r.length)throw new Error("You must provide 1, 3, or 4 arguments to scale for a 4D matrix");const i=t.identity(n);for(let e=0;e<n;e++)3===e&&t.scale.length<4?i[n*e+e]=1:i[n*e+e]=Number(isNaN(r[e])?r[0]:r[e]);return t.multiply(i,e)};t.rotate=(e,r,...i)=>{if(isNaN(r))throw new Error("Expected a number as a 2nd argument");const o=a(e);if(2===o)return((e,r)=>{const n=Math.cos(r),i=Math.sin(r);return t.multiply([n,i,n,-i],e)})(e,r);if(i=i.slice(0,3),!t.isVector3(i))throw new Error("Expected numeric 3rd, 4th, and 5th argument");i=n(i);const s=Math.sin(r/2),u=(e=>[1-2*(Math.pow(e[2],2)+Math.pow(e[3],2)),2*(e[1]*e[2]+e[3]*e[0]),2*(e[1]*e[3]-e[2]*e[0]),2*(e[1]*e[2]-e[3]*e[0]),1-2*(Math.pow(e[1],2)+Math.pow(e[3],2)),2*(e[2]*e[3]+e[1]*e[0]),2*(e[1]*e[3]+e[2]*e[0]),2*(e[2]*e[3]-e[1]*e[0]),1-2*(Math.pow(e[1],2)+Math.pow(e[2],2))])([Math.cos(r/2),i[0]*s,i[1]*s,i[2]*s]);if(3===o)return t.multiply(e,u);const f=[u[0],u[1],u[2],0,u[3],u[4],u[5],0,u[6],u[7],u[8],0,0,0,0,1];return t.multiply(e,f)},t.lookAt=(e,r,a,s=1e-6)=>{let u=(f=r,e.map((e,t)=>e-f[t]));var f;let c,m,d=0;for(let e=0;e<3;e++)Math.abs(u[e])<s&&d++;if(3===d)return t.identity(4);u=n(u);try{c=n(o(a,u))}catch(e){c=[0,0,0]}try{m=n(o(u,c))}catch(e){m=[0,0,0]}return[c[0],m[0],u[0],0,c[1],m[1],u[1],0,c[2],m[2],u[2],0,-i(c,e),-i(m,e),-i(u,e),1]},t.perspective=(e,t,r,n)=>{const i=1/Math.tan(e/2);let o,a;if(null!==n&&n!==1/0){const e=1/(r-n);o=(r+n)*e,a=2*n*r*e}else o=-1,a=-2*r;return[i/t,0,0,0,0,i,0,0,0,0,o,-1,0,0,a,0]},t.cubeFaces=()=>["posx","negx","posy","negy","posz","negz"],t.isCube=e=>Boolean(e)&&t.cubeFaces().every(t=>void 0!==e[t]),t.cube=e=>{const r={};for(const n of t.cubeFaces())r[n]=e(n);return r}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CubeCameraUniform=t.CubeCameraUniformImpl=t.isCubeTextureUniform=t.CubeTextureUniform=t.CubeTextureImpl=t.Texture2DUniform=t.Texture2DUniformImpl=t.isTextureUniform=t.TextureUniform=t.PerspectiveMatUniform=t.ViewMatUniform=t.ViewMatUniformImpl=t.NormalMatUniform=t.ModelMatUniform=t.Mat4Uniform=t.Mat3Uniform=t.Mat2Uniform=t.Vec4Uniform=t.Vec3Uniform=t.Vec2Uniform=t.IntegerUniform=t.FloatUniform=t.BooleanUniform=t.Uniform=void 0;const n=r(0),i=r(1);class o{constructor(e,t,r){this.type_=e,this.name=t,this.dataOrCb_=r}static checkType(e,t){if(e.type_!==t)throw new TypeError(`Expected uniform with type ${t} got type ${e.type_}`)}static dataOrCallback(e){return e.dataOrCb_}set(e){return this.dataOrCb_=e,this}data(){return"function"==typeof this.dataOrCb_?this.dataOrCb_():this.dataOrCb_}send(e,t){throw new Error("Virtual method should not be invoked")}}t.Uniform=o;class a extends o{send(e,t){if(isNaN(this.data()))throw TypeError(`Data for ${this.type_} uniform should be a number`);n.sendBytesUniform(e,t,this.name,this.type_,this.data())}}const s=e=>(t,r)=>new a(e,t,r);t.BooleanUniform=s(n.UniformType.BOOLEAN),t.FloatUniform=s(n.UniformType.FLOAT),t.IntegerUniform=s(n.UniformType.INTEGER);class u extends o{constructor(e,t,r,n){super(e,t,n),this.dimension=r}validateData_(){if(this.type_==n.UniformType.VECTOR){if(this.data().length!=this.dimension)throw new TypeError(`Dimension mismatch for a ${this.type_}${this.dimension} uniform`)}else if(this.data().length!=Math.pow(this.dimension,2))throw new TypeError(`Dimension mismatch for a ${this.type_}${this.dimension} uniform`)}send(e,t){this.validateData_(),this.type_===n.UniformType.VECTOR?n.sendVectorUniform(e,t,this.name,this.dimension,this.data()):n.sendMatrixUniform(e,t,this.name,this.dimension,this.data())}set(e){return this.dataOrCb_=e,this.validateData_(),this}static checkDimension(e,t){if(e.dimension!=t)throw new TypeError}}const f=(e,t)=>(r,n)=>new u(e,r,t,n);t.Vec2Uniform=f(n.UniformType.VECTOR,2),t.Vec3Uniform=f(n.UniformType.VECTOR,3),t.Vec4Uniform=f(n.UniformType.VECTOR,4),t.Mat2Uniform=f(n.UniformType.MATRIX,2),t.Mat3Uniform=f(n.UniformType.MATRIX,3),t.Mat4Uniform=f(n.UniformType.MATRIX,4);class c extends u{constructor(e,t){super(n.UniformType.MATRIX,e,4,()=>this.matrix_()),this.scaleMatrix_=i.identity(4),t.scale&&("number"==typeof t.scale?this.scaleMatrix_=i.scale(this.scaleMatrix_,t.scale):this.scaleMatrix_=i.scale(this.scaleMatrix_,...t.scale)),this.rotationMatrix_=i.identity(3),t.rotate&&(this.rotationMatrix_=i.rotate(this.rotationMatrix_,...t.rotate)),this.translation_=[0,0,0],t.translate&&(this.translation_=t.translate)}scaleMatrix(){return[...this.scaleMatrix_]}rotationMatrix(){return[...this.rotationMatrix_]}rotationMatrix4_(){const e=this.rotationMatrix_;return[e[0],e[1],e[2],0,e[3],e[4],e[5],0,e[6],e[7],e[8],0,0,0,0,1]}translation(){return[...this.translation_]}matrix_(){return i.translate(i.multiply(this.rotationMatrix4_(),this.scaleMatrix()),...this.translation_)}scale(...e){this.scaleMatrix_=i.scale(this.scaleMatrix_,...e)}setScale(...e){this.scaleMatrix_=i.scale(i.identity(4),...e)}rotate(e,...t){this.rotationMatrix_=i.rotate(this.rotationMatrix_,e,...t)}setRotate(e,...t){this.rotationMatrix_=i.rotate(i.identity(3),e,...t)}translate(...e){if(e=e.slice(0,3),!i.isVector3(e))throw new Error("Expected 3 numeric arguments");this.translation_=i.add(this.translation_,e)}setTranslation(...e){if(e=e.slice(0,3),!i.isVector3(e))throw new Error("Expected 3 numeric arguments");this.translation_=e}}t.ModelMatUniform=(e,t={})=>new c(e,t),t.NormalMatUniform=(e,t)=>f(n.UniformType.MATRIX,3)(e,()=>t.rotationMatrix());class m extends u{constructor(e,t,r,o){super(n.UniformType.MATRIX,e,4,()=>i.lookAt(this.eye_,this.at_,this.up_)),this.eye_=t,this.at_=r,this.up_=o}eye(){return[...this.eye_]}at(){return[...this.at_]}up(){return[...this.up_]}setEye(...e){m.validateVector3(e),this.eye_=e}setAt(...e){m.validateVector3(e),this.at_=e.slice(0,3)}setUp(...e){m.validateVector3(e),this.up_=[...e]}}t.ViewMatUniformImpl=m,m.validateVector3=e=>{if(!i.isVector3(e))throw new Error("Expected 3 numbers as arguments")},t.ViewMatUniform=(e,t,r,n)=>new m(e,t,r,n);class d extends u{constructor(e,t,r,o,a){super(n.UniformType.MATRIX,e,4,()=>i.perspective(this.fovy_,this.aspect_,this.near_,this.far_)),this.fovy_=t,this.aspect_=r,this.near_=o,this.far_=a}fovy(){return this.fovy_}aspect(){return this.aspect_}near(){return this.near_}far(){return this.far_}setFovy(e){this.fovy_=e}setAspect(e){this.aspect_=e}setNear(e){this.near_=e}setFar(e){this.far_=e}}t.PerspectiveMatUniform=(e,t,r,n,i=null)=>new d(e,t,r,n,i);class _ extends o{shouldBuildTextureFromData_(){return!this.textureBuffers_&&!!this.dataOrCb_&&(!this.texture_||n.isVideo(this.data()))}prepare(e,t){throw new Error("Virtual method should not be invoked")}buffers(e,t){throw new Error("Virtual method should not be invoked")}set(e){return this.dataOrCb_=e,this.texture_=void 0,this}}t.TextureUniform=_,t.isTextureUniform=e=>e instanceof _;class l extends _{constructor(e,t){super(n.UniformType.TEXTURE,e,t)}prepare(e,t){isNaN(this.offset_)&&(this.offset_=n.newTextureOffset(t,this.name)),this.shouldBuildTextureFromData_()&&(this.texture_=n.texture2d(e,this.data()))}send(e,t){n.send2DTexture(e,t,this.name,this.offset_,this.texture_)}buffers(e,t){if(this.textureBuffers_)return this.textureBuffers_;const r=e.createFramebuffer(),[,,i,o]=t;return this.textureBuffers_={frameBuffer:r,renderBuffer:n.renderBuffer(e,r,i,o)},this.texture_=n.texture2DFromFramebuffer(e,r,i,o),this.textureBuffers_}}t.Texture2DUniformImpl=l,t.Texture2DUniform=(e,t)=>new l(e,t);class E extends _{validateData(){if(!i.isCube(this.data()))throw new Error('You must provide an object with "posx", "negx", "posy", "negy", "posz", and "negz" keys')}set(e){return this.dataOrCb_=e,this.validateData(),this.texture_=void 0,this}prepare(e,t){isNaN(this.offset_)&&(this.offset_=n.newTextureOffset(t,this.name)),this.shouldBuildTextureFromData_()&&(this.texture_=n.cubeTexure(e,this.data()))}send(e,t){n.sendCubeTexture(e,t,this.name,this.offset_,this.texture_)}buffers(e,t){if(this.textureBuffers_)return this.textureBuffers_;const[,,r,o]=t,a=i.cube(()=>e.createFramebuffer());return this.textureBuffers_={frameBuffer:a,renderBuffer:i.cube(t=>n.renderBuffer(e,a[t],r,o))},this.texture_=n.cubeTextureFromFramebuffer(e,this.buffers(e,t).frameBuffer,r,o),this.textureBuffers_}}t.CubeTextureImpl=E,t.CubeTextureUniform=(e,t)=>new E(n.UniformType.TEXTURE,e,t),t.isCubeTextureUniform=e=>e instanceof E;class h extends E{constructor(e,t,r,a){if(super(n.UniformType.TEXTURE,e),this.position_=t,this.viewMat_=r,this.perspectiveMat_=a,!i.isVector3(t))throw new Error("Expected array of 3 arguments as the first argument");o.checkType(r,n.UniformType.MATRIX),u.checkDimension(r,4)}set(e){throw new Error("Cube camera uniforms should get their data from a shader")}render(e){const t=this.perspectiveMat_.fovy();this.perspectiveMat_.setFovy(Math.PI/2);const r=o.dataOrCallback(this.viewMat_);for(const t of i.cubeFaces()){const r=i.add(h.atVectors[t],this.position_),n=h.upVectors[t];this.viewMat_.set(i.lookAt(this.position_,r,n)),e(t)}this.viewMat_.set(r),this.perspectiveMat_.setFovy(t)}}t.CubeCameraUniformImpl=h,h.upVectors={posx:[0,-1,0],negx:[0,-1,0],posy:[0,0,1],negy:[0,0,1],posz:[0,-1,0],negz:[0,-1,0]},h.atVectors={posx:[1,0,0],negx:[-1,0,0],posy:[0,1,0],negy:[0,-1,0],posz:[0,0,1],negz:[0,0,-1]},t.CubeCameraUniform=(e,t,r,n)=>(t||(t=[0,0,0]),r||(r=new m("",[0,0,1],[0,0,0],[0,1,0])),new h(e,t,r,n))},function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||t.hasOwnProperty(r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0});var o=r(4);Object.defineProperty(t,"FloatAttribute",{enumerable:!0,get:function(){return o.FloatAttribute}}),Object.defineProperty(t,"Mat2Attribute",{enumerable:!0,get:function(){return o.Mat2Attribute}}),Object.defineProperty(t,"Mat3Attribute",{enumerable:!0,get:function(){return o.Mat3Attribute}}),Object.defineProperty(t,"Mat4Attribute",{enumerable:!0,get:function(){return o.Mat4Attribute}}),Object.defineProperty(t,"Vec2Attribute",{enumerable:!0,get:function(){return o.Vec2Attribute}}),Object.defineProperty(t,"Vec3Attribute",{enumerable:!0,get:function(){return o.Vec3Attribute}}),Object.defineProperty(t,"Vec4Attribute",{enumerable:!0,get:function(){return o.Vec4Attribute}}),i(r(5),t),i(r(6),t);var a=r(2);Object.defineProperty(t,"BooleanUniform",{enumerable:!0,get:function(){return a.BooleanUniform}}),Object.defineProperty(t,"CubeCameraUniform",{enumerable:!0,get:function(){return a.CubeCameraUniform}}),Object.defineProperty(t,"CubeTextureUniform",{enumerable:!0,get:function(){return a.CubeTextureUniform}}),Object.defineProperty(t,"FloatUniform",{enumerable:!0,get:function(){return a.FloatUniform}}),Object.defineProperty(t,"IntegerUniform",{enumerable:!0,get:function(){return a.IntegerUniform}}),Object.defineProperty(t,"Mat2Uniform",{enumerable:!0,get:function(){return a.Mat2Uniform}}),Object.defineProperty(t,"Mat3Uniform",{enumerable:!0,get:function(){return a.Mat3Uniform}}),Object.defineProperty(t,"Mat4Uniform",{enumerable:!0,get:function(){return a.Mat4Uniform}}),Object.defineProperty(t,"ModelMatUniform",{enumerable:!0,get:function(){return a.ModelMatUniform}}),Object.defineProperty(t,"NormalMatUniform",{enumerable:!0,get:function(){return a.NormalMatUniform}}),Object.defineProperty(t,"PerspectiveMatUniform",{enumerable:!0,get:function(){return a.PerspectiveMatUniform}}),Object.defineProperty(t,"Texture2DUniform",{enumerable:!0,get:function(){return a.Texture2DUniform}}),Object.defineProperty(t,"Vec2Uniform",{enumerable:!0,get:function(){return a.Vec2Uniform}}),Object.defineProperty(t,"Vec3Uniform",{enumerable:!0,get:function(){return a.Vec3Uniform}}),Object.defineProperty(t,"Vec4Uniform",{enumerable:!0,get:function(){return a.Vec4Uniform}}),Object.defineProperty(t,"ViewMatUniform",{enumerable:!0,get:function(){return a.ViewMatUniform}})},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Mat4Attribute=t.Mat3Attribute=t.Mat2Attribute=t.Vec4Attribute=t.Vec3Attribute=t.Vec2Attribute=t.FloatAttribute=t.Attribute=void 0;const n=r(0);class i{constructor(e,t,r){this.name_=e,this.dimension_=t,this.data_=r,Array.isArray(this.data_)&&!isNaN(this.data_[0])&&(this.data_=new Float32Array(this.data_))}send(e,t){this.buffer_||(this.buffer_=e.createBuffer()),n.sendAttribute(e,t,this.buffer_,this.name_,this.data_,this.dimension_)}length(){if(this.data_ instanceof Float32Array){let e=this.data_.byteLength/this.data_.BYTES_PER_ELEMENT;return e/=this.dimension_,e}return this.data_.length/this.dimension_}}t.Attribute=i;const o=e=>(t,r)=>new i(t,e,r);t.FloatAttribute=o(1),t.Vec2Attribute=o(2),t.Vec3Attribute=o(3),t.Vec4Attribute=o(4);class a extends i{constructor(e,t,r){super(e,t,r),Array.isArray(r[0])&&Array.isArray(r[0][0])&&(this.data_=this.data_.map(e=>new Float32Array(e)))}send(e,t){this.buffer_||(this.buffer_=e.createBuffer()),n.sendMatrixAttribute(e,t,this.buffer_,this.name_,this.data_,this.dimension_)}}const s=e=>(t,r)=>new a(t,e,r);t.Mat2Attribute=s(2),t.Mat3Attribute=s(3),t.Mat4Attribute=s(4)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CUBE_NORMALS=t.CUBE_TEX_COORDS=t.CUBE_INDICES=t.CUBE_VERTICES=t.PLANE_TEX_COORDS=t.PLANE_VERTICES=void 0,t.PLANE_VERTICES=new Float32Array([-1,1,1,1,-1,-1,1,-1]),t.PLANE_TEX_COORDS=new Float32Array([0,1,1,1,0,0,1,0]),t.CUBE_VERTICES=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1]),t.CUBE_INDICES=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]),t.CUBE_TEX_COORDS=new Float32Array([0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1]),t.CUBE_NORMALS=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0])},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Shader=void 0;const n=r(0),i=r(2),o={attributes:[],uniforms:[],mode:WebGLRenderingContext.TRIANGLE_STRIP,clear:!0},a=e=>[0,0,e.width,e.height],s=new WeakMap,u=new WeakMap,f=(e,t,r,f,c,m,d)=>{const{gl:_,program:l}=((e,t,r,i)=>{let o=s.get(e);if(!o){const a=n.glContext(t);o={gl:a,program:n.glProgram(a,r,i)},s.set(e,o)}return o})(e,t,r,f);((e,t,r,n)=>{for(const o of n){if(!i.isTextureUniform(o))continue;o.prepare(e,t);const n=u.get(o);if(n){u.delete(o);for(const e of n)e(r)}}})(_,l,t,d.uniforms),_.useProgram(l),_.bindFramebuffer(_.FRAMEBUFFER,c),_.bindRenderbuffer(_.RENDERBUFFER,m),((e,t,r)=>{let i;for(const n of r.attributes){if(isNaN(i))i=n.length();else if(n.length()!=i)throw new Error("Mismatched attrbute size");n.send(e,t)}for(const n of r.uniforms)n.send(e,t);r.indices&&n.sendIndices(e,r.indices)})(_,l,d),n.glRender(_,(e=>e.indices?e.indices.length:e.attributes[0].length())(d),(e=>void 0===e.clear||e.clear)(d),d.viewport||a(t),d.mode||o.mode,!!d.indices)},c=(e,t,r,o,s)=>u=>{i.isCubeTextureUniform(t)?((e,t,r,o,s,u)=>{if(!(o instanceof i.CubeCameraUniformImpl))throw new Error("Not implemented");{const i=n.glContext(t),c=r.viewport||a(t),{frameBuffer:m,renderBuffer:d}=o.buffers(i,c);o.render(n=>{f(e,t,s,u,m[n],d[n],r)})}})(e,u,s,t,r,o):((e,t,r,i,o,s)=>{const u=n.glContext(t),c=r.viewport||a(t),{frameBuffer:m,renderBuffer:d}=i.buffers(u,c);f(e,t,o,s,m,d,r)})(e,u,s,t,r,o)};t.Shader=(e,t,r)=>{var n;if(!r||!(null===(n=r.attributes)||void 0===n?void 0:n.length))throw new Error("Shaders require at least one attribute");const o={};return n=>{if(n instanceof HTMLCanvasElement)return f(o,n,e,t,null,null,r),n;if(i.isTextureUniform(n))return((e,t)=>{let r=u.get(e);r||(r=[],u.set(e,r)),r.push(t)})(n,c(o,n,e,t,r)),n;throw new Error("Shader function must be called with a canvas or texture uniform")}}}]);
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.glRender=t.cubeTextureFromFramebuffer=t.texture2DFromFramebuffer=t.renderBuffer=t.sendCubeTexture=t.send2DTexture=t.cubeTexure=t.texture2d=t.isVideo=t.newTextureOffset=t.sendVectorUniform=t.sendMatrixUniform=t.sendBytesUniform=t.UniformType=t.sendMatrixAttribute=t.sendAttribute=t.sendIndices=t.glProgram=t.glContext=void 0;const n=r(1);t.glContext=e=>{const t=e.getContext("webgl",{preserveDrawingBuffer:!0})||e.getContext("experimental-webgl",{preserveDrawingBuffer:!0});return t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t};const i=(e,t,r)=>{if(e.shaderSource(t,r),e.compileShader(t),!e.getShaderParameter(t,e.COMPILE_STATUS))throw new Error("Shader failed to compile: "+e.getShaderInfoLog(t));return t};var o;t.glProgram=(e,t,r)=>{const n=i(e,e.createShader(WebGLRenderingContext.VERTEX_SHADER),t),o=i(e,e.createShader(WebGLRenderingContext.FRAGMENT_SHADER),r),a=e.createProgram();if(e.attachShader(a,n),e.attachShader(a,o),e.linkProgram(a),!e.getProgramParameter(a,e.LINK_STATUS))throw new Error("Shader failed to compile: "+e.getProgramInfoLog(a));return a},t.sendIndices=(e,t)=>{e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,e.createBuffer()),e.bufferData(e.ELEMENT_ARRAY_BUFFER,t,e.STATIC_DRAW)},t.sendAttribute=(e,t,r,n,i,o)=>{const a=e.getAttribLocation(t,n);e.bindBuffer(e.ARRAY_BUFFER,r),e.vertexAttribPointer(a,o,e.FLOAT,!1,0,0),e.enableVertexAttribArray(a),e.bufferData(e.ARRAY_BUFFER,i,e.STATIC_DRAW)},t.sendMatrixAttribute=(e,t,r,n,i,o)=>{const a=e.getAttribLocation(t,n);for(let t=0;t<o;t++)e.enableVertexAttribArray(a+t),e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,i[t],e.STATIC_DRAW),e.vertexAttribPointer(a+t,o,e.FLOAT,!1,0,0)},function(e){e.BOOLEAN="boolean",e.FLOAT="float",e.INTEGER="integer",e.VECTOR="vector",e.MATRIX="matrix",e.TEXTURE="texture"}(o=t.UniformType||(t.UniformType={})),t.sendBytesUniform=(e,t,r,n,i)=>{const a=e.getUniformLocation(t,r);switch(n){case o.BOOLEAN:e.uniform1i(a,i);break;case o.FLOAT:e.uniform1f(a,i);break;case o.INTEGER:e.uniform1i(a,i);break;default:throw new Error("Unexpected uniform type: "+n)}},t.sendMatrixUniform=(e,t,r,n,i)=>{const o=e.getUniformLocation(t,r);switch(n){case 2:e.uniformMatrix2fv(o,!1,i);break;case 3:e.uniformMatrix3fv(o,!1,i);break;case 4:e.uniformMatrix4fv(o,!1,i)}},t.sendVectorUniform=(e,t,r,n,i)=>{const o=e.getUniformLocation(t,r);switch(n){case 2:e.uniform2fv(o,i);break;case 3:e.uniform3fv(o,i);break;case 4:e.uniform4fv(o,i);break;default:throw new Error("Unexpected dimension: "+n)}};const a=new WeakMap;t.newTextureOffset=(e,t)=>{const r=a.get(e)||[];for(let e=0;e<r.length;e++)if(r[e]===t)return e;const n=r.length;if(32===n)throw new Error("Already at maximum number of textures for this program");return r.push(t),n||a.set(e,r),n},t.isVideo=e=>n.isCube(e)?Object.keys(e).some(t=>e[t]instanceof HTMLVideoElement):e instanceof HTMLVideoElement,t.texture2d=(e,r)=>{const i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r),!t.isVideo(r)&&n.isPowerOfTwo(r.width)&&n.isPowerOfTwo(r.height)?e.generateMipmap(e.TEXTURE_2D):(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR)),i};const s={posx:WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_X,negx:WebGLRenderingContext.TEXTURE_CUBE_MAP_NEGATIVE_X,posy:WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_Y,negy:WebGLRenderingContext.TEXTURE_CUBE_MAP_NEGATIVE_Y,posz:WebGLRenderingContext.TEXTURE_CUBE_MAP_POSITIVE_Z,negz:WebGLRenderingContext.TEXTURE_CUBE_MAP_NEGATIVE_Z};t.cubeTexure=(e,r)=>{const i=e.createTexture();e.bindTexture(e.TEXTURE_CUBE_MAP,i);for(const t of n.cubeFaces())e.texImage2D(s[t],0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,r[t]);return!t.isVideo(r)&&(e=>{for(const t of n.cubeFaces())if(!n.isPowerOfTwo(e[t].width)||!n.isPowerOfTwo(e[t].height))return!1;return!0})(r)?e.generateMipmap(e.TEXTURE_CUBE_MAP):(e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),i};const u=e=>(t,r,n,i,o)=>{const a=t.getUniformLocation(r,n);t.uniform1i(a,i),t.activeTexture(t.TEXTURE0+i),t.bindTexture(e,o)};t.send2DTexture=u(WebGLRenderingContext.TEXTURE_2D),t.sendCubeTexture=u(WebGLRenderingContext.TEXTURE_CUBE_MAP),t.renderBuffer=(e,t,r,n)=>{const i=e.createRenderbuffer();return e.bindFramebuffer(e.FRAMEBUFFER,t),e.bindRenderbuffer(e.RENDERBUFFER,i),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,r,n),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,i),i},t.texture2DFromFramebuffer=(e,t,r,n)=>{const i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindFramebuffer(e.FRAMEBUFFER,t),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r,n,0,e.RGBA,e.UNSIGNED_BYTE,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),i},t.cubeTextureFromFramebuffer=(e,t,r,i)=>{const o=e.createTexture();e.bindTexture(e.TEXTURE_CUBE_MAP,o),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);for(const a of n.cubeFaces())e.bindFramebuffer(e.FRAMEBUFFER,t[a]),e.texImage2D(s[a],0,e.RGBA,r,i,0,e.RGBA,e.UNSIGNED_BYTE,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,s[a],o,0);return o},t.glRender=(e,t,r,n,i,o)=>{e.clearColor(0,0,0,1),r&&(e.clearDepth(e.getParameter(e.DEPTH_CLEAR_VALUE)),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)),e.viewport(...n),o?e.drawElements(i,t,e.UNSIGNED_SHORT,0):e.drawArrays(i,0,t)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.cube=t.isCube=t.cubeFaces=t.perspective=t.lookAt=t.rotate=t.scale=t.translate=t.multiply=t.identity=t.add=t.isVector3=t.isPowerOfTwo=void 0,t.isPowerOfTwo=e=>0==(e&e-1),t.isVector3=e=>Array.isArray(e)&&3===e.length&&e.every(e=>!isNaN(e));const n=e=>{const t=Math.hypot(...e);if(!t)throw new Error("Cannot normalize a vector with no length");return e.map(e=>e/t)};t.add=(e,t)=>e.map((e,r)=>e+t[r]);const i=(e,t)=>e.reduce((e,r,n)=>e+r*t[n],0),o=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],a=e=>Math.sqrt(e.length),s=e=>[...Array(Math.pow(e,2))].map(()=>0);t.identity=e=>{const t=s(e);for(let r=0;r<e;r++)t[r*e+r]=1;return t};const u=(e,t,r)=>{const n=[...Array(r)].map(()=>0);for(let i=0;i<r;i++)for(let o=0;o<r;o++)n[i]+=e[i*r+o]*t[o];return n};t.multiply=(e,t)=>{const r=a(e);if(r!==a(t)){if(r!==t.length)throw new Error("Cannot multiply, incompatible dimensions");return u(e,t,r)}return((e,t,r)=>{const n=s(r);for(let i=0;i<r;i++)for(let o=0;o<r;o++)for(let a=0;a<r;a++)n[r*i+o]+=e[r*i+a]*t[r*a+o];return n})(e,t,r)},t.translate=(e,t,r,n)=>{const i=e.slice(0,16);return i[12]+=t,i[13]+=r,i[14]+=n,i},t.scale=(e,...r)=>{if(!r.length)throw new Error("You must provide at least one number to scale a matrix");const n=a(e);if(4===n&&2===r.length)throw new Error("You must provide 1, 3, or 4 arguments to scale for a 4D matrix");const i=t.identity(n);for(let e=0;e<n;e++)3===e&&t.scale.length<4?i[n*e+e]=1:i[n*e+e]=Number(isNaN(r[e])?r[0]:r[e]);return t.multiply(i,e)};t.rotate=(e,r,...i)=>{if(isNaN(r))throw new Error("Expected a number as a 2nd argument");const o=a(e);if(2===o)return((e,r)=>{const n=Math.cos(r),i=Math.sin(r);return t.multiply([n,i,n,-i],e)})(e,r);if(i=i.slice(0,3),!t.isVector3(i))throw new Error("Expected numeric 3rd, 4th, and 5th argument");i=n(i);const s=Math.sin(r/2),u=(e=>[1-2*(Math.pow(e[2],2)+Math.pow(e[3],2)),2*(e[1]*e[2]+e[3]*e[0]),2*(e[1]*e[3]-e[2]*e[0]),2*(e[1]*e[2]-e[3]*e[0]),1-2*(Math.pow(e[1],2)+Math.pow(e[3],2)),2*(e[2]*e[3]+e[1]*e[0]),2*(e[1]*e[3]+e[2]*e[0]),2*(e[2]*e[3]-e[1]*e[0]),1-2*(Math.pow(e[1],2)+Math.pow(e[2],2))])([Math.cos(r/2),i[0]*s,i[1]*s,i[2]*s]);if(3===o)return t.multiply(e,u);const f=[u[0],u[1],u[2],0,u[3],u[4],u[5],0,u[6],u[7],u[8],0,0,0,0,1];return t.multiply(e,f)},t.lookAt=(e,r,a,s=1e-6)=>{let u=(f=r,e.map((e,t)=>e-f[t]));var f;let c,m,d=0;for(let e=0;e<3;e++)Math.abs(u[e])<s&&d++;if(3===d)return t.identity(4);u=n(u);try{c=n(o(a,u))}catch(e){c=[0,0,0]}try{m=n(o(u,c))}catch(e){m=[0,0,0]}return[c[0],m[0],u[0],0,c[1],m[1],u[1],0,c[2],m[2],u[2],0,-i(c,e),-i(m,e),-i(u,e),1]},t.perspective=(e,t,r,n)=>{const i=1/Math.tan(e/2);let o,a;if(null!==n&&n!==1/0){const e=1/(r-n);o=(r+n)*e,a=2*n*r*e}else o=-1,a=-2*r;return[i/t,0,0,0,0,i,0,0,0,0,o,-1,0,0,a,0]},t.cubeFaces=()=>["posx","negx","posy","negy","posz","negz"],t.isCube=e=>Boolean(e)&&t.cubeFaces().every(t=>void 0!==e[t]),t.cube=e=>{const r={};for(const n of t.cubeFaces())r[n]=e(n);return r}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CubeCameraUniform=t.CubeCameraUniformImpl=t.isCubeTextureUniform=t.CubeTextureUniform=t.CubeTextureImpl=t.Texture2DUniform=t.Texture2DUniformImpl=t.isTextureUniform=t.TextureUniform=t.PerspectiveMatUniform=t.ViewMatUniform=t.ViewMatUniformImpl=t.NormalMatUniform=t.ModelMatUniform=t.Mat4Uniform=t.Mat3Uniform=t.Mat2Uniform=t.Vec4Uniform=t.Vec3Uniform=t.Vec2Uniform=t.IntegerUniform=t.FloatUniform=t.BooleanUniform=t.Uniform=void 0;const n=r(0),i=r(1);class o{constructor(e,t,r){this.type_=e,this.name=t,this.dataOrCb_=r}static checkType(e,t){if(e.type_!==t)throw new TypeError(`Expected uniform with type ${t} got type ${e.type_}`)}static dataOrCallback(e){return e.dataOrCb_}set(e){return this.dataOrCb_=e,this}data(){return"function"==typeof this.dataOrCb_?this.dataOrCb_():this.dataOrCb_}send(e,t){throw new Error("Virtual method should not be invoked")}}t.Uniform=o;class a extends o{send(e,t){if(isNaN(this.data()))throw TypeError(`Data for ${this.type_} uniform should be a number`);n.sendBytesUniform(e,t,this.name,this.type_,this.data())}}const s=e=>(t,r)=>new a(e,t,r);t.BooleanUniform=s(n.UniformType.BOOLEAN),t.FloatUniform=s(n.UniformType.FLOAT),t.IntegerUniform=s(n.UniformType.INTEGER);class u extends o{constructor(e,t,r,n){super(e,t,n),this.dimension=r}validateData_(){if(this.type_==n.UniformType.VECTOR){if(this.data().length!=this.dimension)throw new TypeError(`Dimension mismatch for a ${this.type_}${this.dimension} uniform`)}else if(this.data().length!=Math.pow(this.dimension,2))throw new TypeError(`Dimension mismatch for a ${this.type_}${this.dimension} uniform`)}send(e,t){this.validateData_(),this.type_===n.UniformType.VECTOR?n.sendVectorUniform(e,t,this.name,this.dimension,this.data()):n.sendMatrixUniform(e,t,this.name,this.dimension,this.data())}set(e){return this.dataOrCb_=e,this.validateData_(),this}static checkDimension(e,t){if(e.dimension!=t)throw new TypeError}}const f=(e,t)=>(r,n)=>new u(e,r,t,n);t.Vec2Uniform=f(n.UniformType.VECTOR,2),t.Vec3Uniform=f(n.UniformType.VECTOR,3),t.Vec4Uniform=f(n.UniformType.VECTOR,4),t.Mat2Uniform=f(n.UniformType.MATRIX,2),t.Mat3Uniform=f(n.UniformType.MATRIX,3),t.Mat4Uniform=f(n.UniformType.MATRIX,4);class c extends u{constructor(e,t){super(n.UniformType.MATRIX,e,4,()=>this.matrix_()),this.scaleMatrix_=i.identity(4),t.scale&&("number"==typeof t.scale?this.scaleMatrix_=i.scale(this.scaleMatrix_,t.scale):this.scaleMatrix_=i.scale(this.scaleMatrix_,...t.scale)),this.rotationMatrix_=i.identity(3),t.rotate&&(this.rotationMatrix_=i.rotate(this.rotationMatrix_,...t.rotate)),this.translation_=[0,0,0],t.translate&&(this.translation_=t.translate)}scaleMatrix(){return[...this.scaleMatrix_]}rotationMatrix(){return[...this.rotationMatrix_]}rotationMatrix4_(){const e=this.rotationMatrix_;return[e[0],e[1],e[2],0,e[3],e[4],e[5],0,e[6],e[7],e[8],0,0,0,0,1]}translation(){return[...this.translation_]}matrix_(){return i.translate(i.multiply(this.rotationMatrix4_(),this.scaleMatrix()),...this.translation_)}scale(...e){this.scaleMatrix_=i.scale(this.scaleMatrix_,...e)}setScale(...e){this.scaleMatrix_=i.scale(i.identity(4),...e)}rotate(e,...t){this.rotationMatrix_=i.rotate(this.rotationMatrix_,e,...t)}setRotate(e,...t){this.rotationMatrix_=i.rotate(i.identity(3),e,...t)}translate(...e){if(e=e.slice(0,3),!i.isVector3(e))throw new Error("Expected 3 numeric arguments");this.translation_=i.add(this.translation_,e)}setTranslation(...e){if(e=e.slice(0,3),!i.isVector3(e))throw new Error("Expected 3 numeric arguments");this.translation_=e}}t.ModelMatUniform=(e,t={})=>new c(e,t),t.NormalMatUniform=(e,t)=>f(n.UniformType.MATRIX,3)(e,()=>t.rotationMatrix());class m extends u{constructor(e,t,r,o){super(n.UniformType.MATRIX,e,4,()=>i.lookAt(this.eye_,this.at_,this.up_)),this.eye_=t,this.at_=r,this.up_=o}eye(){return[...this.eye_]}at(){return[...this.at_]}up(){return[...this.up_]}setEye(...e){m.validateVector3(e),this.eye_=e}setAt(...e){m.validateVector3(e),this.at_=e.slice(0,3)}setUp(...e){m.validateVector3(e),this.up_=[...e]}}t.ViewMatUniformImpl=m,m.validateVector3=e=>{if(!i.isVector3(e))throw new Error("Expected 3 numbers as arguments")},t.ViewMatUniform=(e,t,r,n)=>new m(e,t,r,n);class d extends u{constructor(e,t,r,o,a){super(n.UniformType.MATRIX,e,4,()=>i.perspective(this.fovy_,this.aspect_,this.near_,this.far_)),this.fovy_=t,this.aspect_=r,this.near_=o,this.far_=a}fovy(){return this.fovy_}aspect(){return this.aspect_}near(){return this.near_}far(){return this.far_}setFovy(e){this.fovy_=e}setAspect(e){this.aspect_=e}setNear(e){this.near_=e}setFar(e){this.far_=e}}t.PerspectiveMatUniform=(e,t,r,n,i=null)=>new d(e,t,r,n,i);class _ extends o{shouldBuildTextureFromData_(){return!this.textureBuffers_&&!!this.dataOrCb_&&(!this.texture_||n.isVideo(this.data()))}prepare(e,t){throw new Error("Virtual method should not be invoked")}buffers(e,t){throw new Error("Virtual method should not be invoked")}set(e){return this.dataOrCb_=e,this.texture_=void 0,this}}t.TextureUniform=_,t.isTextureUniform=e=>e instanceof _;class h extends _{constructor(e,t){super(n.UniformType.TEXTURE,e,t)}prepare(e,t){isNaN(this.offset_)&&(this.offset_=n.newTextureOffset(t,this.name)),this.shouldBuildTextureFromData_()&&(this.texture_=n.texture2d(e,this.data()))}send(e,t){n.send2DTexture(e,t,this.name,this.offset_,this.texture_)}buffers(e,t){if(this.textureBuffers_)return this.textureBuffers_;const r=e.createFramebuffer(),[,,i,o]=t;return this.textureBuffers_={frameBuffer:r,renderBuffer:n.renderBuffer(e,r,i,o)},this.texture_=n.texture2DFromFramebuffer(e,r,i,o),this.textureBuffers_}}t.Texture2DUniformImpl=h,t.Texture2DUniform=(e,t)=>new h(e,t);class l extends _{validateData(){if(!i.isCube(this.data()))throw new Error('You must provide an object with "posx", "negx", "posy", "negy", "posz", and "negz" keys')}set(e){return this.dataOrCb_=e,this.validateData(),this.texture_=void 0,this}prepare(e,t){isNaN(this.offset_)&&(this.offset_=n.newTextureOffset(t,this.name)),this.shouldBuildTextureFromData_()&&(this.texture_=n.cubeTexure(e,this.data()))}send(e,t){n.sendCubeTexture(e,t,this.name,this.offset_,this.texture_)}buffers(e,t){if(this.textureBuffers_)return this.textureBuffers_;const[,,r,o]=t,a=i.cube(()=>e.createFramebuffer());return this.textureBuffers_={frameBuffer:a,renderBuffer:i.cube(t=>n.renderBuffer(e,a[t],r,o))},this.texture_=n.cubeTextureFromFramebuffer(e,this.buffers(e,t).frameBuffer,r,o),this.textureBuffers_}}t.CubeTextureImpl=l,t.CubeTextureUniform=(e,t)=>new l(n.UniformType.TEXTURE,e,t),t.isCubeTextureUniform=e=>e instanceof l;class E extends l{constructor(e,t,r,a){if(super(n.UniformType.TEXTURE,e),this.position_=t,this.viewMat_=r,this.perspectiveMat_=a,!i.isVector3(t))throw new Error("Expected array of 3 arguments as the first argument");o.checkType(r,n.UniformType.MATRIX),u.checkDimension(r,4)}set(e){throw new Error("Cube camera uniforms should get their data from a shader")}render(e){const t=this.perspectiveMat_.fovy();this.perspectiveMat_.setFovy(Math.PI/2);const r=o.dataOrCallback(this.viewMat_);for(const t of i.cubeFaces()){const r=i.add(E.atVectors[t],this.position_),n=E.upVectors[t];this.viewMat_.set(i.lookAt(this.position_,r,n)),e(t)}this.viewMat_.set(r),this.perspectiveMat_.setFovy(t)}}t.CubeCameraUniformImpl=E,E.upVectors={posx:[0,-1,0],negx:[0,-1,0],posy:[0,0,1],negy:[0,0,1],posz:[0,-1,0],negz:[0,-1,0]},E.atVectors={posx:[1,0,0],negx:[-1,0,0],posy:[0,1,0],negy:[0,-1,0],posz:[0,0,1],negz:[0,0,-1]},t.CubeCameraUniform=(e,t,r,n)=>(t||(t=[0,0,0]),r||(r=new m("",[0,0,1],[0,0,0],[0,1,0])),new E(e,t,r,n))},function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||t.hasOwnProperty(r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0});var o=r(4);Object.defineProperty(t,"FloatAttribute",{enumerable:!0,get:function(){return o.FloatAttribute}}),Object.defineProperty(t,"Mat2Attribute",{enumerable:!0,get:function(){return o.Mat2Attribute}}),Object.defineProperty(t,"Mat3Attribute",{enumerable:!0,get:function(){return o.Mat3Attribute}}),Object.defineProperty(t,"Mat4Attribute",{enumerable:!0,get:function(){return o.Mat4Attribute}}),Object.defineProperty(t,"Vec2Attribute",{enumerable:!0,get:function(){return o.Vec2Attribute}}),Object.defineProperty(t,"Vec3Attribute",{enumerable:!0,get:function(){return o.Vec3Attribute}}),Object.defineProperty(t,"Vec4Attribute",{enumerable:!0,get:function(){return o.Vec4Attribute}}),i(r(5),t),i(r(6),t);var a=r(2);Object.defineProperty(t,"BooleanUniform",{enumerable:!0,get:function(){return a.BooleanUniform}}),Object.defineProperty(t,"CubeCameraUniform",{enumerable:!0,get:function(){return a.CubeCameraUniform}}),Object.defineProperty(t,"CubeTextureUniform",{enumerable:!0,get:function(){return a.CubeTextureUniform}}),Object.defineProperty(t,"FloatUniform",{enumerable:!0,get:function(){return a.FloatUniform}}),Object.defineProperty(t,"IntegerUniform",{enumerable:!0,get:function(){return a.IntegerUniform}}),Object.defineProperty(t,"Mat2Uniform",{enumerable:!0,get:function(){return a.Mat2Uniform}}),Object.defineProperty(t,"Mat3Uniform",{enumerable:!0,get:function(){return a.Mat3Uniform}}),Object.defineProperty(t,"Mat4Uniform",{enumerable:!0,get:function(){return a.Mat4Uniform}}),Object.defineProperty(t,"ModelMatUniform",{enumerable:!0,get:function(){return a.ModelMatUniform}}),Object.defineProperty(t,"NormalMatUniform",{enumerable:!0,get:function(){return a.NormalMatUniform}}),Object.defineProperty(t,"PerspectiveMatUniform",{enumerable:!0,get:function(){return a.PerspectiveMatUniform}}),Object.defineProperty(t,"Texture2DUniform",{enumerable:!0,get:function(){return a.Texture2DUniform}}),Object.defineProperty(t,"Vec2Uniform",{enumerable:!0,get:function(){return a.Vec2Uniform}}),Object.defineProperty(t,"Vec3Uniform",{enumerable:!0,get:function(){return a.Vec3Uniform}}),Object.defineProperty(t,"Vec4Uniform",{enumerable:!0,get:function(){return a.Vec4Uniform}}),Object.defineProperty(t,"ViewMatUniform",{enumerable:!0,get:function(){return a.ViewMatUniform}})},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Mat4Attribute=t.Mat3Attribute=t.Mat2Attribute=t.Vec4Attribute=t.Vec3Attribute=t.Vec2Attribute=t.FloatAttribute=t.Attribute=void 0;const n=r(0);class i{constructor(e,t,r){this.name_=e,this.dimension_=t,this.data_=r,Array.isArray(this.data_)&&!isNaN(this.data_[0])&&(this.data_=new Float32Array(this.data_))}send(e,t){this.buffer_||(this.buffer_=e.createBuffer()),n.sendAttribute(e,t,this.buffer_,this.name_,this.data_,this.dimension_)}length(){if(this.data_ instanceof Float32Array){let e=this.data_.byteLength/this.data_.BYTES_PER_ELEMENT;return e/=this.dimension_,e}return this.data_.length/this.dimension_}}t.Attribute=i;const o=e=>(t,r)=>new i(t,e,r);t.FloatAttribute=o(1),t.Vec2Attribute=o(2),t.Vec3Attribute=o(3),t.Vec4Attribute=o(4);class a extends i{constructor(e,t,r){super(e,t,r),Array.isArray(r[0])&&Array.isArray(r[0][0])&&(this.data_=this.data_.map(e=>new Float32Array(e)))}send(e,t){this.buffer_||(this.buffer_=e.createBuffer()),n.sendMatrixAttribute(e,t,this.buffer_,this.name_,this.data_,this.dimension_)}}const s=e=>(t,r)=>new a(t,e,r);t.Mat2Attribute=s(2),t.Mat3Attribute=s(3),t.Mat4Attribute=s(4)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CUBE_NORMALS=t.CUBE_TEX_COORDS=t.CUBE_INDICES=t.CUBE_VERTICES=t.PLANE_TEX_COORDS=t.PLANE_VERTICES=void 0,t.PLANE_VERTICES=new Float32Array([-1,1,1,1,-1,-1,1,-1]),t.PLANE_TEX_COORDS=new Float32Array([0,1,1,1,0,0,1,0]),t.CUBE_VERTICES=new Float32Array([-1,-1,1,1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1]),t.CUBE_INDICES=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]),t.CUBE_TEX_COORDS=new Float32Array([0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1]),t.CUBE_NORMALS=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0])},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Shader=void 0;const n=r(0),i=r(2),o={attributes:[],uniforms:[],mode:WebGLRenderingContext.TRIANGLE_STRIP,clear:!0},a=e=>[0,0,e.width,e.height],s=new WeakMap,u=new WeakMap,f=(e,t,r,f,c,m,d)=>{const{gl:_,program:h}=((e,t,r,i)=>{let o=s.get(e);if(!o){const a=n.glContext(t);o={gl:a,program:n.glProgram(a,r,i)},s.set(e,o)}return o})(e,t,r,f);((e,t,r,n)=>{for(const o of n){if(!i.isTextureUniform(o))continue;o.prepare(e,t);const n=u.get(o);if(n){u.delete(o);for(const e of n)e(r)}}})(_,h,t,d.uniforms),_.useProgram(h),_.bindFramebuffer(_.FRAMEBUFFER,c),_.bindRenderbuffer(_.RENDERBUFFER,m),((e,t,r)=>{let i;for(const n of r.attributes){if(isNaN(i))i=n.length();else if(n.length()!=i)throw new Error("Mismatched attrbute size");n.send(e,t)}for(const n of r.uniforms)n.send(e,t);r.indices&&n.sendIndices(e,r.indices)})(_,h,d),n.glRender(_,(e=>e.indices?e.indices.length:e.attributes[0].length())(d),(e=>void 0===e.clear||e.clear)(d),d.viewport||a(t),d.mode||o.mode,!!d.indices)},c=(e,t,r,o,s)=>u=>{i.isCubeTextureUniform(t)?((e,t,r,o,s,u)=>{if(!(o instanceof i.CubeCameraUniformImpl))throw new Error("Not implemented");{const i=n.glContext(t),c=r.viewport||a(t),{frameBuffer:m,renderBuffer:d}=o.buffers(i,c);o.render(n=>{f(e,t,s,u,m[n],d[n],r)})}})(e,u,s,t,r,o):((e,t,r,i,o,s)=>{const u=n.glContext(t),c=r.viewport||a(t),{frameBuffer:m,renderBuffer:d}=i.buffers(u,c);f(e,t,o,s,m,d,r)})(e,u,s,t,r,o)};t.Shader=(e,t,r)=>{var n;if("string"!=typeof e)throw new Error("The first argument of Shader must be a string");if("string"!=typeof t)throw new Error("The second argument of Shader must be a string");if(!r||!(null===(n=r.attributes)||void 0===n?void 0:n.length))throw new Error("Shader requires at least one attribute");const o={};return n=>{if(n instanceof HTMLCanvasElement)return f(o,n,e,t,null,null,r),n;if(i.isTextureUniform(n))return((e,t)=>{let r=u.get(e);r||(r=[],u.set(e,r)),r.push(t)})(n,c(o,n,e,t,r)),n;throw new Error("Shader function must be called with a canvas or texture uniform")}}}]);
//# sourceMappingURL=index.js.map

@@ -93,2 +93,5 @@ /**

export declare type Cube<T> = Record<CubeFace, T>;
/**
* Can either be the type, T, or a Cube of T.
*/
export declare type CubeOr<T> = T | Cube<T>;

@@ -95,0 +98,0 @@ /**

@@ -18,10 +18,17 @@ /**

}
/**
* The type of objects the function returned by Shader can be called with.
*/
declare type RenderTarget = HTMLCanvasElement | TextureUniform<TextureData>;
/**
* The type of function returned by Shader.
*/
declare type ShaderFunc = (target: RenderTarget) => RenderTarget;
/**
* Create a shader function to render to a target.
*
* TODO validation for arguments
* @param vertexSrc the vertex shader source
* @param fragmentSrc the fragment shader source
* @param options for the shader
*/
export declare const Shader: (vertexSrc: string, fragmentSrc: string, opts: ShaderOptions) => ShaderFunc;
export declare const Shader: (vertexSrc: string, fragmentSrc: string, options: ShaderOptions) => ShaderFunc;
export {};

@@ -6,2 +6,5 @@ /**

import { Cube, CubeFace, CubeOr, Matrix3, Matrix4, Vector3, Vector4 } from './math';
/**
* Either is type T or a nullary function that returns T.
*/
declare type IsOrReturns<T> = T | (() => T);

@@ -21,9 +24,32 @@ /**

constructor(type_: UniformType, name: string, dataOrCb_?: IsOrReturns<Data>);
/**
* Check that the type of a uniform matches the expected type.
*/
static checkType(u: Uniform<UniformData>, wantType: UniformType): void;
/**
* Get the data or callback to compute the data for the uniform.
* Static because this method should only be used in phixl's internals.
*/
static dataOrCallback<Data extends UniformData>(u: Uniform<Data>): IsOrReturns<Data>;
/**
* Set the data the uniform object will send to the shader.
* @param dataOrCb new data or a callback to compute the new data.
*/
set(dataOrCb: IsOrReturns<Data>): this;
/**
* Get the data the uniform will send to the shader.
*/
data(): Data;
/**
* Send the uniform data to the shader.
*/
send(gl: WebGLRenderingContext, program: WebGLProgram): void;
}
/**
*
*/
declare class BytesUniform extends Uniform<number> {
/**
* Send the uniform data to the shader.
*/
send(gl: WebGLRenderingContext, program: WebGLProgram): void;

@@ -33,2 +59,4 @@ }

* Send a boolean uniform to a shader.
* @param name of the uniform in the shader
* @param data the uniform will send to the shader
*/

@@ -38,2 +66,4 @@ export declare const BooleanUniform: (name: string, data?: IsOrReturns<number>) => BytesUniform;

* Send a float uniform to a shader.
* @param name of the uniform in the shader
* @param data the uniform will send to the shader
*/

@@ -43,16 +73,43 @@ export declare const FloatUniform: (name: string, data?: IsOrReturns<number>) => BytesUniform;

* Send a integer uniform to a shader.
* @param name of the uniform in the shader
* @param data the uniform will send to the shader
*/
export declare const IntegerUniform: (name: string, data?: IsOrReturns<number>) => BytesUniform;
/**
* Type of uniform data for sequence uniforms, i.e. uniforms
* which send a sequence of float values to a shader.
*/
declare type SequenceUniformType = UniformType.VECTOR | UniformType.MATRIX;
/**
* Abstraction for sending sequence uniforms to a shader.
*/
declare class SequenceUniform extends Uniform<Float32List> {
readonly dimension: number;
constructor(type: SequenceUniformType, name: string, dimension: number, dataOrCb?: IsOrReturns<Float32List>);
/**
* Validate the sequence uniform's data.
*/
private validateData_;
/**
* Send the data to a shader.
*/
send(gl: WebGLRenderingContext, program: WebGLProgram): void;
/**
* Set the uniform's data.
* @param dataOrCb new data or a callback which computes the data.
*/
set(dataOrCb: IsOrReturns<Float32List>): this;
/**
* Check the dimension of a uniform.
*/
static checkDimension(u: SequenceUniform, wantDimension: number): void;
}
/**
* Type of function used to create sequence uniforms.
*/
declare type SequenceUniformBuilder = (name: string, data?: IsOrReturns<Float32List>) => SequenceUniform;
/**
* Sends a 2-dimensional vector to a shader.
* @param name of the uniform
* @param data for the uniform
*/

@@ -62,2 +119,4 @@ export declare const Vec2Uniform: SequenceUniformBuilder;

* Sends a 3-dimensional vector to a shader.
* @param name of the uniform
* @param data for the uniform
*/

@@ -67,2 +126,4 @@ export declare const Vec3Uniform: SequenceUniformBuilder;

* Sends a 4-dimensional vector to a shader.
* @param name of the uniform
* @param data for the uniform
*/

@@ -72,2 +133,4 @@ export declare const Vec4Uniform: SequenceUniformBuilder;

* Sends a 2-dimensional matrix to a shader.
* @param name of the uniform
* @param data for the uniform
*/

@@ -77,2 +140,4 @@ export declare const Mat2Uniform: SequenceUniformBuilder;

* Sends a 3-dimensional matrix to a shader.
* @param name of the uniform
* @param data for the uniform
*/

@@ -82,4 +147,9 @@ export declare const Mat3Uniform: SequenceUniformBuilder;

* Sends a 4-dimensional matrix to a shader.
* @param name of the uniform
* @param data for the uniform
*/
export declare const Mat4Uniform: SequenceUniformBuilder;
/**
* Type definition of the 2nd argument for ModelMatUniform.
*/
interface ModelMatOptions {

@@ -90,2 +160,6 @@ scale?: number | Vector3;

}
/**
* Abstraction for sending a model matrix to a shader
* as a uniform.
*/
declare class ModelMatUniformImpl extends SequenceUniform {

@@ -96,12 +170,49 @@ private scaleMatrix_;

constructor(name: string, opts: ModelMatOptions);
/**
* Get the scale component for the model matrix as a 4D matrix.
*/
scaleMatrix(): Matrix4;
/**
* Get the rotation component of the model matrix as a 3D matrix.
*/
rotationMatrix(): Matrix3;
/**
* Gets the rotation matrix as a 4D matrix.
*/
private rotationMatrix4_;
/**
* Gets the translation component of the model matrix as a 3D vector.
*/
translation(): Vector3;
/**
* Get the model matrix this uniform will send as a 4D matrix.
*/
private matrix_;
/**
* Apply a new scale to the model matrix.
*/
scale(...args: number[]): void;
/**
* Set the scale of the model matrix.
*/
setScale(...args: number[]): void;
/**
* Apply a rotation to the model matrix.
* @param theta angle of rotation in radians
* @param axis of rotation
*/
rotate(theta: number, ...axis: Vector3): void;
/**
* Set the rotation component of the model matrix.
* @param theta angle of rotation in radians
* @param axis of rotation
*/
setRotate(theta: number, ...axis: Vector3): void;
/**
* Apply a translation to the model matrix.
*/
translate(...args: Vector3): void;
/**
* Set the translation component of the model matrix.
*/
setTranslation(...args: Vector3): void;

@@ -133,8 +244,30 @@ }

constructor(name: string, eye_: Vector3, at_: Vector3, up_: Vector3);
/**
* Checks if the provided data is a 3D vector.
* @param data to validate
*/
private static validateVector3;
/**
* Get the eye vector for the view matrix.
*/
eye(): Vector3;
/**
* Get the look at vector for the view matrix.
*/
at(): Vector3;
/**
* Get the up vector for the view matrix.
*/
up(): Vector3;
/**
* Set the eye vector.
*/
setEye(...eye: Vector3): void;
/**
* Set the look at vector.
*/
setAt(...at: Vector3): void;
/**
* Set the up vector.
*/
setUp(...up: Vector3): void;

@@ -147,2 +280,5 @@ }

export declare const ViewMatUniform: (name: string, eye: Vector3, at: Vector3, up: Vector3) => ViewMatUniformImpl;
/**
* Abstraction for a perspective matrix uniform.
*/
declare class PerspectiveMatUniformImpl extends SequenceUniform {

@@ -154,9 +290,33 @@ private fovy_;

constructor(name: string, fovy_: number, aspect_: number, near_: number, far_: number | null);
/**
* Get the field of view in radians.
*/
fovy(): number;
/**
* Get the aspect ratio (width / height).
*/
aspect(): number;
/**
* Get the near plane.
*/
near(): number;
/**
* Get the far plane.
*/
far(): number;
/**
* Set the field of view in radians.
*/
setFovy(fovy: number): void;
/**
* Set the aspect ratio (width / height).
*/
setAspect(aspect: number): void;
/**
* Set the near plane.
*/
setNear(near: number): void;
/**
* Set the far plane.
*/
setFar(far: number): void;

@@ -172,2 +332,6 @@ }

export declare type TextureData = CubeOr<TexImageSource>;
/**
* This type contains the WebGLFramebuffer and WebGLRenderbuffer used
* to render a shader to a texture.
*/
interface Texture2DBuffers {

@@ -177,6 +341,15 @@ frameBuffer: WebGLFramebuffer;

}
/**
* A cube of texture buffers for rendering a shader to a cube texture.
*/
declare type CubeTextureBuffers = {
[k in keyof Texture2DBuffers]: Cube<Texture2DBuffers[k]>;
};
/**
* Union type for buffers for 2D and cube textures.
*/
declare type TextureBuffers = Texture2DBuffers | CubeTextureBuffers;
/**
* Abstraction for a texture uniform.
*/
export declare class TextureUniform<Data extends TextureData> extends Uniform<Data> {

@@ -186,5 +359,19 @@ protected offset_: number;

protected textureBuffers_: TextureBuffers;
/**
* Check if the uniform needs to build the texture.
*/
protected shouldBuildTextureFromData_(): boolean;
/**
* Prepare the texture before using it in a shader.
*/
prepare(gl: WebGLRenderingContext, p: WebGLProgram): void;
/**
* Get the WebGLFramebuffer and WebGLRenderbuffer to render a shader
* to this texture.
*/
buffers(gl: WebGLRenderingContext, v: Viewport): TextureBuffers;
/**
* Set new data for the uniform.
* @param dataOrCb the new data or a callback computing the data.
*/
set(dataOrCb: IsOrReturns<Data>): this;

@@ -202,4 +389,13 @@ }

constructor(name: string, dataOrCb?: IsOrReturns<TexImageSource>);
/**
* Prepare the 2D texture before using it in a shader.
*/
prepare(gl: WebGLRenderingContext, program: WebGLProgram): void;
/**
* Send the 2D texture to a shader.
*/
send(gl: WebGLRenderingContext, program: WebGLProgram): void;
/**
* Get the buffers needed to render a shader to this texture.
*/
buffers(gl: WebGLRenderingContext, viewport: Viewport): Texture2DBuffers;

@@ -211,8 +407,27 @@ }

export declare const Texture2DUniform: (name: string, data?: IsOrReturns<TexImageSource>) => Texture2DUniformImpl;
/**
* Implementation of a cube texture.
*/
export declare class CubeTextureImpl extends TextureUniform<Cube<TexImageSource>> {
protected textureBuffers_: CubeTextureBuffers;
/**
* Validate that the data is a cube.
*/
private validateData;
/**
* Set the data of the cube texture.
* @param dataOrCb new data or callback that computes the data.
*/
set(dataOrCb: IsOrReturns<Cube<TexImageSource>>): this;
/**
* Prepare the cube texture to be used in a shader.
*/
prepare(gl: WebGLRenderingContext, program: WebGLProgram): void;
/**
* Send the cube texture to a shader.
*/
send(gl: WebGLRenderingContext, program: WebGLProgram): void;
/**
* Get a Cube of buffers needed to render a shader to the cube texture.
*/
buffers(gl: WebGLRenderingContext, viewport: Viewport): CubeTextureBuffers;

@@ -238,3 +453,10 @@ }

constructor(name: string, position_: Vector3, viewMat_: ViewMatUniformImpl, perspectiveMat_: PerspectiveMatUniformImpl);
/**
* You should not use this method with a cube camera uniform.
*/
set(dataOrCb: IsOrReturns<Cube<TexImageSource>>): never;
/**
* Render a scene to a cube camera texture. Should only be used by
* phixl internals.
*/
render(renderShader: (cf: CubeFace) => void): void;

@@ -241,0 +463,0 @@ }

{
"name": "phixl",
"version": "1.0.3",
"version": "1.0.4",
"description": "A functional WebGL library for rendering WebGL shaders",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc