!function(a){"use strict";function b(){var a=void 0===arguments[0]?1:arguments[0],b=void 0===arguments[1]?20:arguments[1],c=new t;c.vertices.push(0,0,0),c.vertexIndex=[],c.vertexNormals=[];var d=Math.PI/(b-1);b*=2;for(var e=0,f=1;b>f;e+=d,f++)c.vertices.push(Math.cos(e)*a,Math.sin(e)*a,0);for(var f=0;f=k;j+=f,k++){var l=new r(Math.cos(j)*b,Math.sin(j)*b,g),m=new r(Math.cos(j)*c,Math.sin(j)*c,h),n=l.cross(m);e.vertexNormals.push(n.x,n.y,n.z),e.vertexNormals.push(n.x,n.y,n.z),e.vertices.push(l.x,l.y,l.z),e.vertices.push(m.x,m.y,m.z)}for(var k=0;k=h;h++)for(var j=h*Math.PI/b,k=Math.sin(j),l=Math.cos(j),m=0;c>=m;m++){var n=2*m*Math.PI/c,o=Math.sin(n),p=Math.cos(n),q=p*k,r=l,s=o*k,u=1-m/c,v=1-h/b;f.push(q),f.push(r),f.push(s),g.push(u),g.push(v),e.push(a*q),e.push(a*r),e.push(a*s)}for(var w=[],h=0;b>h;h++)for(var m=0;c>m;m++){var x=h*(c+1)+m,y=x+c+1;w.push(x),w.push(y),w.push(x+1),w.push(y),w.push(y+1),w.push(x+1)}return d.vertexIndex=w,d.vertexNormals=f,d.vertices=e,d.darwingFunction=i.drawingFunctions.ELEMENTS,d.drawingMode=i.drawingMode.TRIANGLES,d}var f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},g=function(){function a(){var a=void 0===arguments[0]?.785398:arguments[0],b=void 0===arguments[1]?1:arguments[1],c=void 0===arguments[2]?.1:arguments[2],d=void 0===arguments[3]?100:arguments[3];this.fovy=a,this.aspect=b,this.near=c,this.far=d,this.matrix=new q,this.lookAt=[0,0,0],this.position=[0,0,5],this.up=[0,1,0],this._zoom=1}return f(a,null,{zoom:{set:function(a){if(1>a)throw"Zoom should be equal or greater than 1";this._zoom=a},get:function(){return this._zoom},enumerable:!0,configurable:!0},updatePerspective:{value:function(){var a=2*Math.atan(Math.tan(.5*this.fovy)/this._zoom);this.matrix.perspective(a,this.aspect,this.near,this.far)},writable:!0,enumerable:!0,configurable:!0}}),a}(),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},h=function(){function a(){{var a=void 0===arguments[0]?1:arguments[0],b=void 0===arguments[1]?1:arguments[1],c=void 0===arguments[2]?1:arguments[2];void 0===arguments[3]?1:arguments[3]}this.array=[a,b,c]}return f(a,null,{hex:{set:function(a){var b=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;a=a.replace(b,function(a,b,c,d){return b+b+c+c+d+d});var c=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);this.array[0]=parseInt(c[1],16)/255,this.array[1]=parseInt(c[2],16)/255,this.array[2]=parseInt(c[3],16)/255},get:function(){var a=function(a){var b=a.toString(16);return 1==b.length?"0"+b:b};return"#"+a(this.array[0])+a(this.array[1])+a(this.array[2])},enumerable:!0,configurable:!0},rgb:{value:function(a,b,c){return this.array[0]=a,this.array[1]=b,this.array[2]=c,this},writable:!0,enumerable:!0,configurable:!0},alpha:{value:function b(b){return this.array[3]=b,this},writable:!0,enumerable:!0,configurable:!0},rgba:{value:function(a,b,c,d){return this.rgb(a,b,c),this.alpha(d),this},writable:!0,enumerable:!0,configurable:!0},toArray:{value:function(){return this.array},writable:!0,enumerable:!0,configurable:!0}}),a}(),i={};if(WebGLRenderingContext){var j=WebGLRenderingContext;i={support:!0,drawingMode:{POINTS:j.POINTS,LINES:j.LINES,LINE_LOOP:j.LINE_LOOP,LINE_STRIP:j.LINE_STRIP,TRIANGLES:j.TRIANGLES,TRIANGLE_FAN:j.TRIANGLE_FAN,TRIANGLE_STRIP:j.TRIANGLE_STRIP},drawingFunctions:{ARRAYS:1,ELEMENTS:0}}}else i.support=!1;var f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},k=function(){function a(){this.children=[],this.lights=[]}return f(a,null,{add:{value:function(a){a instanceof m?this.lights.push(a):this.children.push(a)},writable:!0,enumerable:!0,configurable:!0},remove:{value:function(a){a instanceof m?this.lights.splice(this.lights.indexOf(a),1):this.children.splice(this.children.indexOf(a),1)},writable:!0,enumerable:!0,configurable:!0}}),a}(),l=0,m=function(){this.color=new h(1,1,1),this.direction=new r(1,1,1),this.index=l++},f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},n=function(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(a.__proto__=b)},o=function(a){function b(){for(var a=9;a--;)this.push(0)}return n(b,a),f(b,null,{transpose:{value:function(){var a=this[1],b=this[2],c=this[5];return this[1]=this[3],this[2]=this[6],this[3]=a,this[5]=this[7],this[6]=b,this[7]=c,this},writable:!0,enumerable:!0,configurable:!0},toArray:{value:function(){for(var a=[],b=9;b--;)a[b]=this[b];return a},writable:!0,enumerable:!0,configurable:!0}}),b}(Array),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},n=function(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(a.__proto__=b)},p=1e-5,q=function(a){function b(){for(var a=16;a--;)this.push(0)}return n(b,a),f(b,null,{identity:{value:function(){for(var a=16;a--;)this[a]=a%5===0?1:0;return this},writable:!0,enumerable:!0,configurable:!0},determinant:{value:function(){var a=this[0],b=this[1],c=this[2],d=this[3],e=this[4],f=this[5],g=this[6],h=this[7],i=this[8],j=this[9],k=this[10],l=this[11],m=this[12],n=this[13],o=this[14],p=this[15],q=a*f-b*e,r=a*g-c*e,s=a*h-d*e,t=b*g-c*f,u=b*h-d*f,v=c*h-d*g,w=i*n-j*m,x=i*o-k*m,y=i*p-l*m,z=j*o-k*n,A=j*p-l*n,B=k*p-l*o;return q*B-r*A+s*z+t*y-u*x+v*w},writable:!0,enumerable:!0,configurable:!0},perspective:{value:function(a,b,c,d){var e=1/Math.tan(a/2),f=1/(c-d);return this[0]=e/b,this[1]=0,this[2]=0,this[3]=0,this[4]=0,this[5]=e,this[6]=0,this[7]=0,this[8]=0,this[9]=0,this[10]=(d+c)*f,this[11]=-1,this[12]=0,this[13]=0,this[14]=2*d*c*f,this[15]=0,this},writable:!0,enumerable:!0,configurable:!0},lookAt:{value:function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n=a[0],o=a[1],q=a[2],r=c[0],s=c[1],t=c[2],u=b[0],v=b[1],w=b[2];return Math.abs(n-u)0&&(a+=y.fragment.pars.directionalLight,b+=y.fragment.main.directionalLight);var c=""+a+" void main() { "+b+" }";return this.compile(c,WebGLRenderingContext.FRAGMENT_SHADER)},writable:!0,enumerable:!0,configurable:!0},assignValues:{value:function(){var a=this.object,b=a.buffers;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,b.vertices),this.attributeValue("aVertexPosition",b.vertices);try{this.gl.bindBuffer(this.gl.ARRAY_BUFFER,b.normals),this.attributeValue("aVertexNormal",b.normals)}catch(c){}var d=a.getMatrix(this.renderer.camera);this.uniformValue("uPMatrix",this.renderer.camera.matrix.toArray()),this.uniformValue("uMVMatrix",a.getMatrix(this.renderer.camera).toArray()),this.uniformValue("uvColor",a.color.toArray());for(var e in this.renderer.world.lights){var f=this.renderer.world.lights[e],g=f.index;this.uniformValue("uLightingDirection"+g,f.direction.toArray()),this.uniformValue("uDirectionalColor"+g,f.color.array)}var h=d.toInverseMat3().transpose();this.uniformValue("uNMatrix",h.toArray())},writable:!0,enumerable:!0,configurable:!0},uniformLocation:{value:function(a){this.uniforms[a]=this.gl.getUniformLocation(this.program,a)},writable:!0,enumerable:!0,configurable:!0},attributeLocation:{value:function(a){if(this.attributes[a]=this.gl.getAttribLocation(this.program,a),-1===this.attributes[a])throw"Attribute "+a+" cannot be located";this.gl.enableVertexAttribArray(this.attributes[a])},writable:!0,enumerable:!0,configurable:!0},uniformValue:{value:function(a,b){var c=this.gl;"undefined"==typeof this.uniforms[a]&&this.uniformLocation(a),4===b.length?c.uniform4fv(this.uniforms[a],b):3===b.length?c.uniform3fv(this.uniforms[a],b):9===b.length?c.uniformMatrix3fv(this.uniforms[a],!1,b):16===b.length&&c.uniformMatrix4fv(this.uniforms[a],!1,b)},writable:!0,enumerable:!0,configurable:!0},attributeValue:{value:function(a,b){this.gl;"undefined"==typeof this.attributes[a]&&this.attributeLocation(a),-1!==this.attributes[a]&&this.gl.vertexAttribPointer(this.attributes[a],b.itemSize,this.gl.FLOAT,!1,0,0)},writable:!0,enumerable:!0,configurable:!0},use:{value:function(){this.gl.useProgram(this.program)},writable:!0,enumerable:!0,configurable:!0},compile:{value:function(a,b){var c=this.gl,d=c.createShader(b);c.shaderSource(d,a),c.compileShader(d);var e=c.getShaderParameter(d,c.COMPILE_STATUS);if(!e)throw"Could not compile shader:"+c.getShaderInfoLog(d);return d},writable:!0,enumerable:!0,configurable:!0},create:{value:function(){var a=this.gl,b=a.createProgram();a.attachShader(b,this.vertex()),a.attachShader(b,this.fragment()),a.linkProgram(b);var c=a.getProgramParameter(b,a.LINK_STATUS);if(!c)throw"Program failed to link:"+a.getProgramInfoLog(b);return this.program=b,b},writable:!0,enumerable:!0,configurable:!0}}),a}(),y={vertex:{pars:{"default":"attribute vec3 aVertexNormal; attribute vec3 aVertexPosition; uniform mat4 uMVMatrix; uniform mat4 uPMatrix; uniform mat3 uNMatrix;",directionalLight:function(a){return"varying vec3 vLightWeighting; uniform vec3 uLightingDirection"+a+"; uniform vec3 uDirectionalColor"+a+";"}},main:{"default":"gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);",directionalLight:function(a){return"vec3 transformedNormal = uNMatrix * aVertexNormal; float directionalLightWeighting"+a+" = max(dot(transformedNormal, uLightingDirection"+a+"), 0.0); vLightWeighting = uDirectionalColor"+a+" * directionalLightWeighting"+a+";"}}},fragment:{pars:{"default":"precision mediump float;",color:"uniform vec3 uvColor;",directionalLight:"varying vec3 vLightWeighting;"},main:{color:"",directionalLight:"gl_FragColor = vec4(vLightWeighting + uvColor, 1.0);"}}};a.LiThree={Renderer:u,WebGLRenderer:w,World:k,Object3D:t,Camera:g,Color:h,Math:{Vector3:r,Matrix4:q},DirectionalLight:m,ObjectFactory:{Circle:b,Cylinder:d,Cube:c,Sphere:e}}}(this);