1var m=["x","y","z"],l=function(t){Object.assign(this,{uniforms:{},geometry:{vertices:[{x:0,y:0,z:0}]},mode:0,modifiers:{},attributes:[],multiplier:1,buffers:[]}),Object.assign(this,t),this.prepareProgram(),this.prepareUniforms(),this.prepareAttributes()};l.prototype.compileShader=function(t,e){var i=this.gl.createShader(t);return this.gl.shaderSource(i,e),this.gl.compileShader(i),i},l.prototype.prepareProgram=function(){var t=this.gl,e=this.vertex,i=this.fragment,s=t.createProgram();t.attachShader(s,this.compileShader(35633,e)),t.attachShader(s,this.compileShader(35632,i)),t.linkProgram(s),t.useProgram(s),this.program=s},l.prototype.prepareUniforms=function(){for(var t=Object.keys(this.uniforms),e=0;e<t.length;e+=1){var i=this.gl.getUniformLocation(this.program,t[e]);this.uniforms[t[e]].location=i}},l.prototype.prepareAttributes=function(){this.geometry.vertices!==void 0&&this.attributes.push({name:"aPosition",size:3}),this.geometry.normal!==void 0&&this.attributes.push({name:"aNormal",size:3}),this.attributeKeys=[];for(var t=0;t<this.attributes.length;t+=1)this.attributeKeys.push(this.attributes[t].name),this.prepareAttribute(this.attributes[t])},l.prototype.prepareAttribute=function(t){for(var e=this.geometry,i=this.multiplier,s=e.vertices,o=e.normal,h=new Float32Array(i*s.length*t.size),u=0;u<i;u+=1)for(var r=t.data&&t.data(u,i),a=u*s.length*t.size,n=0;n<s.length;n+=1)for(var f=0;f<t.size;f+=1){var c=this.modifiers[t.name];h[a]=c!==void 0?c(r,n,f,this):t.name==="aPosition"?s[n][m[f]]:t.name==="aNormal"?o[n][m[f]]:r[f],a+=1}this.attributes[this.attributeKeys.indexOf(t.name)].data=h,this.prepareBuffer(this.attributes[this.attributeKeys.indexOf(t.name)])},l.prototype.prepareBuffer=function(t){var e=t.data,i=t.name,s=t.size,o=this.gl.createBuffer();this.gl.bindBuffer(34962,o),this.gl.bufferData(34962,e,35044);var h=this.gl.getAttribLocation(this.program,i);this.gl.enableVertexAttribArray(h),this.gl.vertexAttribPointer(h,s,5126,!1,0,0),this.buffers[this.attributeKeys.indexOf(t.name)]={buffer:o,location:h,size:s}},l.prototype.render=function(t){var e=this,i=this.uniforms,s=this.multiplier,o=this.gl;o.useProgram(this.program);for(var h=0;h<this.buffers.length;h+=1){var u=this.buffers[h],r=u.location,a=u.buffer,n=u.size;o.enableVertexAttribArray(r),o.bindBuffer(34962,a),o.vertexAttribPointer(r,n,5126,!1,0,0)}Object.keys(t).forEach(function(f){i[f].value=t[f].value}
1),Object.keys(i).forEach(function(f){var c=i[f];e.uniformMap[c.type](c.location,c.value)}),o.drawArrays(this.mode,0,s*this.geometry.vertices.length),this.onRender&&this.onRender(this)},l.prototype.destroy=function(){for(var t=0;t<this.buffers.length;t+=1)this.gl.deleteBuffer(this.buffers[t].buffer);this.gl.deleteProgram(this.program),this.gl=null};var p=function(t){var e=this,i=t||{},s=i.canvas;s===void 0&&(s=document.querySelector("canvas"));var o=i.context;o===void 0&&(o={});var h=i.contextType;h===void 0&&(h="experimental-webgl");var u=i.settings;u===void 0&&(u={});var r=s.getContext(h,Object.assign({alpha:!1,antialias:!1},o));Object.assign(this,{gl:r,canvas:s,uniforms:{},instances:new Map,shouldRender:!0}),Object.assign(this,{devicePixelRatio:1,clearColor:[1,1,1,1],position:{x:0,y:0,z:2},clip:[.001,100]}),Object.assign(this,u),this.uniformMap={float:function(a,n){return r.uniform1f(a,n)},vec2:function(a,n){return r.uniform2fv(a,n)},vec3:function(a,n){return r.uniform3fv(a,n)},vec4:function(a,n){return r.uniform4fv(a,n)},mat2:function(a,n){return r.uniformMatrix2fv(a,!1,n)},mat3:function(a,n){return r.uniformMatrix3fv(a,!1,n)},mat4:function(a,n){return r.uniformMatrix4fv(a,!1,n)}},r.enable(r.DEPTH_TEST),r.depthFunc(r.LEQUAL),r.getContextAttributes().alpha===!1&&(r.clearColor.apply(r,this.clearColor),r.clearDepth(1)),this.onSetup&&this.onSetup(r),window.addEventListener("resize",function(){return e.resize()}),this.resize(),this.render()};p.prototype.resize=function(){var t=this.gl,e=this.canvas,i=this.devicePixelRatio,s=this.position;e.width=e.clientWidth*i,e.height=e.clientHeight*i;var o=t.drawingBufferWidth,h=t.drawingBufferHeight,u=o/h;t.viewport(0,0,o,h);var r=Math.tan(Math.PI/180*22.5),a=[1,0,0,0,0,1,0,0,0,0,1,0,s.x,s.y,(u<1?1:u)*-s.z,1];this.uniforms.uProjectionMatrix={type:"mat4",value:[.5/r,0,0,0,0,u/r*.5,0,0,0,0,-(this.clip[1]+this.clip[0])/(this.clip[1]-this.clip[0]),-1,0,0,-2*this.clip[1]*(this.clip[0]/(this.clip[1]-this.clip[0])),0]}
1,this.uniforms.uViewMatrix={type:"mat4",value:[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},this.uniforms.uModelMatrix={type:"mat4",value:a}},p.prototype.toggle=function(t){t!==this.shouldRender&&(this.shouldRender=t!==void 0?t:!this.shouldRender,this.shouldRender&&this.render())},p.prototype.render=function(){var t=this;this.gl.clear(16640),this.instances.forEach(function(e){e.render(t.uniforms)}),this.onRender&&this.onRender(this),this.shouldRender&&requestAnimationFrame(function(){return t.render()})},p.prototype.add=function(t,e){e===void 0&&(e={uniforms:{}}),e.uniforms===void 0&&(e.uniforms={}),Object.assign(e.uniforms,JSON.parse(JSON.stringify(this.uniforms))),Object.assign(e,{gl:this.gl,uniformMap:this.uniformMap});var i=new l(e);return this.instances.set(t,i),i},p.prototype.remove=function(t){var e=this.instances.get(t);e!==void 0&&(e.destroy(),this.instances.delete(t))},p.prototype.destroy=function(){var t=this;this.instances.forEach(function(e,i){e.destroy(),t.instances.delete(i)}),this.toggle(!1)};export{p as i};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.