bolt-engine/demos/mouse-gravitation/lithree.min.js
Mahdi Dibaiee fc7d76637d [WIP] New Demo
2015-01-28 19:26:03 +03:30

2 lines
28 KiB
JavaScript

!function(a){"use strict";function b(){var a,b,c=void 0===arguments[0]?1:arguments[0],d=void 0===arguments[1]?20:arguments[1],e=new y;e.vertices.push(0,0,0),e.vertexIndex=[],e.vertexNormals=[];var f=Math.PI/(d-1);for(d*=2,b=0,a=1;d>a;b+=f,a++)e.vertices.push(Math.cos(b)*c,Math.sin(b)*c,0);for(a=0;a<e.vertices.length;a++)e.vertexNormals.push(0,0,1);for(a=0;a<e.vertices.length/3;a++)e.vertexIndex.push(a);return e.darwingFunction=i.drawingFunctions.ELEMENTS,e.drawingMode=i.drawingMode.TRIANGLE_FAN,e}function c(){var a=void 0===arguments[0]?1:arguments[0],b=new y;return b.vertices=[-a,-a,a,a,-a,a,a,a,a,-a,a,a,-a,-a,-a,-a,a,-a,a,a,-a,a,-a,-a,-a,a,-a,-a,a,a,a,a,a,a,a,-a,-a,-a,-a,a,-a,-a,a,-a,a,-a,-a,a,a,-a,-a,a,a,-a,a,a,a,a,-a,a,-a,-a,-a,-a,-a,a,-a,a,a,-a,a,-a],b.vertexIndex=[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],b.vertexNormals=[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],b.darwingFunction=i.drawingFunctions.ELEMENTS,b.drawingMode=i.drawingMode.TRIANGLES,b}function d(){var a,b,c=void 0===arguments[0]?2:arguments[0],d=void 0===arguments[1]?1:arguments[1],e=void 0===arguments[2]?1:arguments[2],f=void 0===arguments[3]?20:arguments[3],g=new y;g.vertexIndex=[],g.vertexNormals=[];var h=Math.PI/(f-1);f*=2;var j=c/2,k=c/-2;for(b=0,a=1;f>=a;b+=h,a++){var l=new w(Math.cos(b)*d,j,Math.sin(b)*d),m=new w(Math.cos(b)*e,k,Math.sin(b)*e),n=l.cross(m);g.vertexNormals.push(n.x,n.y,n.z),g.vertexNormals.push(n.x,n.y,n.z),g.vertices.push(l.x,l.y,l.z),g.vertices.push(m.x,m.y,m.z)}for(a=0;a<g.vertices.length/3;a++)g.vertexIndex.push(a);return g.darwingFunction=i.drawingFunctions.ELEMENTS,g.drawingMode=i.drawingMode.TRIANGLE_STRIP,g}function e(){var a,b,c=void 0===arguments[0]?1:arguments[0],d=void 0===arguments[1]?30:arguments[1],e=void 0===arguments[2]?30:arguments[2],f=new y,g=[],h=[],j=[];for(a=0;d>=a;a++){var k=a*Math.PI/d,l=Math.sin(k),m=Math.cos(k);for(b=0;e>=b;b++){var n=2*b*Math.PI/e,o=Math.sin(n),p=Math.cos(n),q=p*l,r=m,s=o*l,t=1-b/e,u=1-a/d;h.push(q),h.push(r),h.push(s),j.push(t),j.push(u),g.push(c*q),g.push(c*r),g.push(c*s)}}var v=[];for(a=0;d>a;a++)for(b=0;e>b;b++){var w=a*(e+1)+b,x=w+e+1;v.push(w),v.push(x),v.push(w+1),v.push(x),v.push(x+1),v.push(w+1)}return f.vertexIndex=v,f.vertexNormals=h,f.vertices=g,f.darwingFunction=i.drawingFunctions.ELEMENTS,f.drawingMode=i.drawingMode.TRIANGLES,f}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 v,this.lookAt=new w,this.position=new w,this.rotation=new w,this.up=new w,this._zoom=1}return f(a,null,{zoom:{set:function(a){if(0>a)throw"Zoom should be equal or greater than 0";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.identity(),this.matrix.perspective(a,this.aspect,this.near,this.far)},writable:!0,enumerable:!0,configurable:!0},getMatrix:{value:function(){var a=new v;return a.identity(),a.translate(this.position),a.rotateX(this.rotation.x),a.rotateY(this.rotation.y),a.rotateZ(this.rotation.z),a},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],d=void 0===arguments[3]?1:arguments[3];this.array=[a,b,c,d]}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(){var a=void 0===arguments[0]?3:arguments[0];return this.array.slice(0,a)},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._events={}}return f(a,null,{on:{value:function(a,b){return this._events[a]=this._events[a]||[],this._events[a].push(b),this},writable:!0,enumerable:!0,configurable:!0},once:{value:function(a,b){var c=function(){d.off(a,c),b.apply(this,arguments)},d=this;return c.listener=b,this.on(a,c),this},writable:!0,enumerable:!0,configurable:!0},off:{value:function(a,b){var c=this._events[a];if(void 0!==c){for(var d=0;d<c.length;d+=1)if(c[d]===b||c[d].listener===b){c.splice(d,1);break}0===c.length&&this.removeAllListeners(a)}return this},writable:!0,enumerable:!0,configurable:!0},removeAllListeners:{value:function(a){try{delete this._events[a]}catch(b){}return this},writable:!0,enumerable:!0,configurable:!0},listeners:{value:function(a){try{return this._events[a]}catch(b){}},writable:!0,enumerable:!0,configurable:!0},emit:{value:function(){var a=[].slice.call(arguments,0),b=a.shift(),c=this._events[b];if(void 0!==c){c=c.slice(0);for(var d=c.length,e=0;d>e;e+=1)c[e].apply(this,a)}return this},writable:!0,enumerable:!0,configurable:!0}}),a}(),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},l=function(){function a(){this.children=[],this.lights=[]}return f(a,null,{add:{value:function(a){"light"===a.type?this.lights.push(a):"object"===a.type&&this.children.push(a)},writable:!0,enumerable:!0,configurable:!0},remove:{value:function(a){"light"===a.type?this.lights.splice(this.lights.indexOf(a),1):"object"===a.type&&this.children.splice(this.children.indexOf(a),1)},writable:!0,enumerable:!0,configurable:!0}}),a}(),m=0,n=function(){this.index=m++,this.type="light"},f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},o=function G(a,b,c){var d=Object.getOwnPropertyDescriptor(a,b);if(void 0===d){var e=Object.getPrototypeOf(a);return null===e?void 0:G(e,b,c)}if("value"in d&&d.writable)return d.value;var f=d.get;return void 0===f?void 0:f.call(c)},p=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)},q=function(a){function b(){o(Object.getPrototypeOf(b.prototype),"constructor",this).call(this),this.color=new h(1,1,1),this.direction=new w(1,1,1)}return p(b,a),f(b,null,{program:{value:function(a){var b=this,c=a.uniform("vec3",function(){this.value(b.direction)}),d=a.uniform("vec3",function(){this.value(b.color.toArray())});a.code("%lw += %c * max(dot(transformedNormal, %ld), 0.0);",{lw:"lightWeight",ld:c,c:d})},writable:!0,enumerable:!0,configurable:!0}}),b}(n),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},o=function H(a,b,c){var d=Object.getOwnPropertyDescriptor(a,b);if(void 0===d){var e=Object.getPrototypeOf(a);return null===e?void 0:H(e,b,c)}if("value"in d&&d.writable)return d.value;var f=d.get;return void 0===f?void 0:f.call(c)},p=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)},r=function(a){function b(){o(Object.getPrototypeOf(b.prototype),"constructor",this).call(this),this.specularColor=new h(.5,.5,.5),this.diffuseColor=new h(.3,.3,.3),this.position=new w(-10,4,-20)}return p(b,a),f(b,null,{program:{value:function(a){var b=this,c=a.uniform("vec3",function(){this.value(b.specularColor.toArray())}),d=a.uniform("vec3",function(){this.value(b.diffuseColor.toArray())}),e=a.uniform("vec3",function(){this.value(b.position)});a.code("\nvec3 %ld = normalize(%lp - %vp.xyz);\nfloat %sw = 0.0;\n\nif (bSpecular) {\n %sw = pow(max(dot(reflect(-%ld, normal), normalize(-%vp.xyz)), 0.0), fShininess);\n}\n\nfloat %dw = max(dot(normal, -%ld), 0.0);\n%lw += %sc * %sw + %dc * %dw;\n ",{sc:c,dc:d,lp:e,ld:"lightDirection"+this.index,vp:"vPosition",sw:"specularLightWeighting"+this.index,dw:"diffuseLightWeighting"+this.index,lw:"lightWeight",fs:"fShininess"})},writable:!0,enumerable:!0,configurable:!0}}),b}(n),s=function(){this.shininess=30,this.lighting=!0,this.specular=!0},f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},p=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)},t=function(a){function b(){for(var a=9;a--;)this.push(0)}return p(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)},p=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)},u=1e-5,v=function(a){function b(){for(var a=16;a--;)this.push(0)}return p(b,a),f(b,{multiply:{value:function(a,c){var d=new b,e=a[0],f=a[1],g=a[2],h=a[3],i=a[4],j=a[5],k=a[6],l=a[7],m=a[8],n=a[9],o=a[10],p=a[11],q=a[12],r=a[13],s=a[14],t=a[15],u=c[0],v=c[1],w=c[2],x=c[3];return d[0]=u*e+v*i+w*m+x*q,d[1]=u*f+v*j+w*n+x*r,d[2]=u*g+v*k+w*o+x*s,d[3]=u*h+v*l+w*p+x*t,u=c[4],v=c[5],w=c[6],x=c[7],d[4]=u*e+v*i+w*m+x*q,d[5]=u*f+v*j+w*n+x*r,d[6]=u*g+v*k+w*o+x*s,d[7]=u*h+v*l+w*p+x*t,u=c[8],v=c[9],w=c[10],x=c[11],d[8]=u*e+v*i+w*m+x*q,d[9]=u*f+v*j+w*n+x*r,d[10]=u*g+v*k+w*o+x*s,d[11]=u*h+v*l+w*p+x*t,u=c[12],v=c[13],w=c[14],x=c[15],d[12]=u*e+v*i+w*m+x*q,d[13]=u*f+v*j+w*n+x*r,d[14]=u*g+v*k+w*o+x*s,d[15]=u*h+v*l+w*p+x*t,d},writable:!0,enumerable:!0,configurable:!0}},{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;return Math.abs(a.x-b.x)<u&&Math.abs(a.y-b.y)<u&&Math.abs(a.z-b.z)<u?this.identity():(j=a.x-b.x,k=a.y-b.y,l=a.z-b.z,m=1/Math.sqrt(j*j+k*k+l*l),j*=m,k*=m,l*=m,d=c.y*l-c.z*k,e=c.z*j-c.x*l,f=c.x*k-c.y*j,m=Math.sqrt(d*d+e*e+f*f),m?(m=1/m,d*=m,e*=m,f*=m):(d=0,e=0,f=0),g=k*f-l*e,h=l*d-j*f,i=j*e-k*d,m=Math.sqrt(g*g+h*h+i*i),m?(m=1/m,g*=m,h*=m,i*=m):(g=0,h=0,i=0),this[0]=d,this[1]=g,this[2]=j,this[3]=0,this[4]=e,this[5]=h,this[6]=k,this[7]=0,this[8]=f,this[9]=i,this[10]=l,this[11]=0,this[12]=-(d*a.x+e*a.y+f*a.z),this[13]=-(g*a.x+h*a.y+i*a.z),this[14]=-(j*a.x+k*a.y+l*a.z),this[15]=1,this)},writable:!0,enumerable:!0,configurable:!0},translate:{value:function(a){return this[12]=this[0]*a.x+this[4]*a.y+this[8]*a.z+this[12],this[13]=this[1]*a.x+this[5]*a.y+this[9]*a.z+this[13],this[14]=this[2]*a.x+this[6]*a.y+this[10]*a.z+this[14],this[15]=this[3]*a.x+this[7]*a.y+this[11]*a.z+this[15],this},writable:!0,enumerable:!0,configurable:!0},rotate:{value:function(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A=b.clone();return A.normalize(),c=Math.sin(a),d=Math.cos(a),e=1-d,f=this[0],g=this[1],h=this[2],i=this[3],j=this[4],k=this[5],l=this[6],m=this[7],n=this[8],o=this[9],p=this[10],q=this[11],r=A.x*A.x*e+d,s=A.y*A.x*e+A.z*c,t=A.z*A.x*e-A.y*c,u=A.x*A.y*e-A.z*c,v=A.y*A.y*e+d,w=A.z*A.y*e+A.x*c,x=A.x*A.z*e+A.y*c,y=A.y*A.z*e-A.x*c,z=A.z*A.z*e+d,this[0]=f*r+j*s+n*t,this[1]=g*r+k*s+o*t,this[2]=h*r+l*s+p*t,this[3]=i*r+m*s+q*t,this[4]=f*u+j*v+n*w,this[5]=g*u+k*v+o*w,this[6]=h*u+l*v+p*w,this[7]=i*u+m*v+q*w,this[8]=f*x+j*y+n*z,this[9]=g*x+k*y+o*z,this[10]=h*x+l*y+p*z,this[11]=i*x+m*y+q*z,this},writable:!0,enumerable:!0,configurable:!0},toInverseMat3:{value:function(){var a=this[0],b=this[1],c=this[2],d=this[4],e=this[5],f=this[6],g=this[8],h=this[9],i=this[10],j=i*e-f*h,k=-i*d+f*g,l=h*d-e*g,m=a*j+b*k+c*l,n=1/m,o=new t;return o[0]=j*n,o[1]=(-i*b+c*h)*n,o[2]=(f*b-c*e)*n,o[3]=k*n,o[4]=(i*a-c*g)*n,o[5]=(-f*a+c*d)*n,o[6]=l*n,o[7]=(-h*a+b*g)*n,o[8]=(e*a-b*d)*n,o},writable:!0,enumerable:!0,configurable:!0},rotateX:{value:function(a){this.rotate(a,new w(1,0,0))},writable:!0,enumerable:!0,configurable:!0},rotateY:{value:function(a){this.rotate(a,new w(0,1,0))},writable:!0,enumerable:!0,configurable:!0},rotateZ:{value:function(a){this.rotate(a,new w(0,0,1))},writable:!0,enumerable:!0,configurable:!0},toArray:{value:function(){for(var a=[],b=16;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)},o=function I(a,b,c){var d=Object.getOwnPropertyDescriptor(a,b);if(void 0===d){var e=Object.getPrototypeOf(a);return null===e?void 0:I(e,b,c)}if("value"in d&&d.writable)return d.value;var f=d.get;return void 0===f?void 0:f.call(c)},p=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)},w=function(a){function b(){var a=void 0===arguments[0]?0:arguments[0],c=void 0===arguments[1]?0:arguments[1],d=void 0===arguments[2]?0:arguments[2];o(Object.getPrototypeOf(b.prototype),"constructor",this).call(this),this._x=a,this._y=c,this._z=d}return p(b,a),f(b,null,{clone:{value:function(){return new b(this.x,this.y,this.z)},writable:!0,enumerable:!0,configurable:!0},x:{get:function(){return this._x},set:function(a){this.emit("update"),this._x=a},enumerable:!0,configurable:!0},y:{get:function(){return this._y},set:function(a){this.emit("update"),this._y=a},enumerable:!0,configurable:!0},z:{get:function(){return this._z},set:function(a){this.emit("update"),this._z=a},enumerable:!0,configurable:!0},set:{value:function(a,b,c){this.x=a,this.y=b,this.z=c},writable:!0,enumerable:!0,configurable:!0},add:{value:function(a){var b,c=void 0===arguments[1]?!1:arguments[1];return b=c?this.clone():this,"object"==typeof a?(b.x+=a.x,b.y+=a.y,b.z+=a.z):(b.x+=a,b.y+=a,b.z+=a),b},writable:!0,enumerable:!0,configurable:!0},subtract:{value:function(a){var b,c=void 0===arguments[1]?!1:arguments[1];return b=c?this.clone():this,"object"==typeof a?(b.x-=a.x,b.y-=a.y,b.z-=a.z):b.add(-a),b},writable:!0,enumerable:!0,configurable:!0},multiply:{value:function(a){var b,c=void 0===arguments[1]?!1:arguments[1];return b=c?this.clone():this,"object"==typeof a?(b.x*=a.x,b.y*=a.y,b.z*=a.z):(b.x*=a,b.y*=a,b.z*=a),b},writable:!0,enumerable:!0,configurable:!0},divide:{value:function(a){var b,c=void 0===arguments[1]?!1:arguments[1];return b=c?this.clone():this,"object"==typeof a?(b.x/=a.x,b.y/=a.y,b.z/=a.z):b.multiply(1/a),b},writable:!0,enumerable:!0,configurable:!0},distance:{value:function(a){var b=a.x-this.x,c=a.y-this.y,d=a.z-this.z;return Math.sqrt(b*b+c*c+d*d)},writable:!0,enumerable:!0,configurable:!0},getLength:{value:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},writable:!0,enumerable:!0,configurable:!0},normalize:{value:function(){this.divide(this.getLength())},writable:!0,enumerable:!0,configurable:!0},dot:{value:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},writable:!0,enumerable:!0,configurable:!0},cross:{value:function(a){return new b(this.y*a.z-this.z*a.y,this.z*a.x-this.x*a.z,this.x*a.y-this.y*a.x)},writable:!0,enumerable:!0,configurable:!0},angle:{value:function(a){return Math.acos(this.dot(a)/this.getLength()/a.getLength())},writable:!0,enumerable:!0,configurable:!0},toArray:{value:function(){return[this.x,this.y,this.z]},writable:!0,enumerable:!0,configurable:!0}}),b}(k),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},x=0,y=function(){function a(){this.color=new h,this.type="object",this.scale=new w,this.position=new w,this.rotation=new w,this.vertices=[],this.vertexNormals=!1,this.vertexIndex=!1,this.vertexColor=!1,this.textureCoords=!1,this.index=x++,this.buffers={},this.material=new s,this.drawingMode=i.drawingMode.LINE_STRIP,this.darwingFunction=i.drawingFunctions.ARRAYS}return f(a,null,{getMatrix:{value:function(){var a=new v;return a.identity(),a.translate(this.position),a.rotateX(this.rotation.x),a.rotateY(this.rotation.y),a.rotateZ(this.rotation.z),a},writable:!0,enumerable:!0,configurable:!0}}),a}(),z=function(){var a=void 0===arguments[0]?640:arguments[0],b=void 0===arguments[1]?480:arguments[1];this.width=a,this.height=b},f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},o=function J(a,b,c){var d=Object.getOwnPropertyDescriptor(a,b);if(void 0===d){var e=Object.getPrototypeOf(a);return null===e?void 0:J(e,b,c)}if("value"in d&&d.writable)return d.value;var f=d.get;return void 0===f?void 0:f.call(c)},p=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)},A=function(a){function b(a,c,d){var e=void 0===arguments[3]?null:arguments[3];o(Object.getPrototypeOf(b.prototype),"constructor",this).call(this,a,c),this.world=d,this.camera=new g,this.camera.aspect=this.width/this.height,this.camera.updatePerspective(),this.canvas=document.createElement("canvas"),this.canvas.setAttribute("width",this.width),this.canvas.setAttribute("height",this.height),this.color=e,this.initGl()}return p(b,a),f(b,null,{initGl:{value:function(){this.gl=this.canvas.getContext("experimental-webgl"),this.gl.viewportWidth=this.canvas.width,this.gl.viewportHeight=this.canvas.height,null!==this.color&&this.gl.clearColor(this.color[0],this.color[1],this.color[2],this.color[3]),this.gl.enable(this.gl.DEPTH_TEST)},writable:!0,enumerable:!0,configurable:!0},initShapes:{value:function(){for(var a=this.world.children.length;a--;){var b=this.world.children[a];b.buffers.vertices=this.gl.createBuffer(),b.buffers.vertexColor=this.gl.createBuffer(),b.buffers.normals=this.gl.createBuffer(),b.buffers.vertexIndex=this.gl.createBuffer(),b.shader=new C(this,b)}},writable:!0,enumerable:!0,configurable:!0},draw:{value:function(){this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT);for(var a=this.world.children.length;a--;){var b=this.world.children[a],c=b.buffers;b.shader.use(),b.shader.assignValues(),b.darwingFunction===i.drawingFunctions.ELEMENTS?this.gl.drawElements(b.drawingMode,c.vertexIndex.numItems,this.gl.UNSIGNED_SHORT,0):b.darwingFunction===i.drawingFunctions.ARRAYS&&this.gl.drawArrays(b.drawingMode,0,c.vertices.numItems)}},writable:!0,enumerable:!0,configurable:!0}}),b}(z),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},B=function(){function a(a,b,c){this.type=a,this.name=b,this.onupdate=null,this._porgrammer=c}return f(a,null,{create:{value:function(){var a=this._porgrammer.renderer.gl;this.location=a.getAttribLocation(this._porgrammer.program,this.name),a.enableVertexAttribArray(this.location)},writable:!0,enumerable:!0,configurable:!0},update:{value:function(){"function"==typeof this.onupdate&&this.onupdate.apply(this)},writable:!0,enumerable:!0,configurable:!0},value:{value:function b(b){var a=this._porgrammer.gl;b instanceof WebGLBuffer&&(a.bindBuffer(a.ARRAY_BUFFER,b),a.vertexAttribPointer(this.location,b.itemSize,a.FLOAT,!1,0,0))},writable:!0,enumerable:!0,configurable:!0}}),a}(),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},C=function(){function a(a,b){this.object=b,this.renderer=a,this.vertexProgram=new E("vertex",this),this.fragmentProgram=new E("fragment",this),this.program=!1,this.gl=a.gl,this.initLighting(),this.initPositionCamera(),this.create()}return f(a,null,{assignValues:{value:function(){var a,b=this.object,c=this.vertexProgram,d=this.fragmentProgram;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,b.buffers.vertices),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(b.vertices),this.gl.STATIC_DRAW),b.buffers.vertices.itemSize=3,b.buffers.vertices.numItems=b.vertices.length/3,b.vertexColor&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,b.buffers.vertexColor),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(b.vertexColor),this.gl.STATIC_DRAW),b.buffers.vertexColor.itemSize=4,b.buffers.vertexColor.numItems=b.vertexColor.length),b.vertexNormals&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,b.buffers.normals),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(b.vertexNormals),this.gl.STATIC_DRAW),b.buffers.normals.itemSize=3,b.buffers.normals.numItems=b.vertexNormals.length),b.vertexIndex&&(this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,b.buffers.vertexIndex),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(b.vertexIndex),this.gl.STATIC_DRAW),b.buffers.vertexIndex.itemSize=1,b.buffers.vertexIndex.numItems=b.vertexIndex.length);for(a in c._variables)c._variables[a].update&&c._variables[a].update();for(a in d._variables)d._variables[a].update&&d._variables[a].update()},writable:!0,enumerable:!0,configurable:!0},initPositionCamera:{value:function(){var a=this.object,b=(this.gl,a.buffers),c=this.vertexProgram,d=this.renderer,e=c.attribute("vec3",function(){this.value(b.vertices)},"vPosition"),f=(c.attribute("vec3",function(){this.value(b.normals)},"vNormal"),c.uniform("mat4",function(){this.value(d.camera.matrix)},"pMatrix")),g=c.uniform("mat4",function(){this.value(v.multiply(d.camera.getMatrix(),a.getMatrix()))},"mvMatrix");c.code("gl_Position = %p * %m * vec4(%v, 1.0);",{p:f,m:g,v:e})},writable:!0,enumerable:!0,configurable:!0},initLighting:{value:function(){var a=this.object,b=this.vertexProgram,c=this.fragmentProgram,d=this.renderer,e=d.world;c.precision("mediump","float");var f=c.uniform("vec3",function(){this.value(a.color.toArray())},"vColor");if(e.lights.length>0){b.attribute("vec3",function(){this.value(a.buffers.normals)},"vNormal"),b.uniform("mat3",function(){var b=a.getMatrix(d.camera),c=b.toInverseMat3().transpose();this.value(c)},"nMatrix"),b.uniform("float",function(){this.value(a.material.shininess)},"fShininess"),b.uniform("bool",function(){this.value(a.material.specular)},"bSpecular"),b.code("vec3 transformedNormal = nMatrix * vNormal;"),b.code("vec3 normal = normalize(transformedNormal);"),b.code("%lw = vec3(0.0, 0.0, 0.0);",{lw:b.varying("vec3","lightWeight")});for(var g in e.lights)e.lights[g].program(b,c);c.code("gl_FragColor = vec4(%lw + %c, 1.0);",{c:f,lw:c.varying("vec3","lightWeight")})}else c.code("gl_FragColor = vec4(%c, 1.0);",{c:f})},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:\n"+c.getShaderInfoLog(d)+"\n"+a;return d},writable:!0,enumerable:!0,configurable:!0},create:{value:function(){var a=this.gl,b=a.createProgram();a.attachShader(b,this.compile(this.vertexProgram.toString(),a.VERTEX_SHADER)),a.attachShader(b,this.compile(this.fragmentProgram.toString(),a.FRAGMENT_SHADER)),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,this.vertexProgram.init(),this.fragmentProgram.init(),b},writable:!0,enumerable:!0,configurable:!0}}),a}(),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},D=0,E=function(){function a(a,b){this._variables={},this._programmer=b,this._code="",this.type=a}return f(a,null,{init:{value:function(){for(var a in this._variables)"undefined"!=typeof this._variables[a].create&&this._variables[a].create()},writable:!0,enumerable:!0,configurable:!0},uniform:{value:function(a){var b=this,c=void 0===arguments[1]?null:arguments[1],d=void 0===arguments[2]?"tmp_"+D++:arguments[2];return function(){var e=new F(a,d,b._programmer);return e.onupdate=c,b._variables[d]=e,e}()},writable:!0,enumerable:!0,configurable:!0},attribute:{value:function(a){var b=this,c=void 0===arguments[1]?null:arguments[1],d=void 0===arguments[2]?"tmp_"+D++:arguments[2];return function(){var e=new B(a,d,b._programmer);return e.onupdate=c,b._variables[d]=e,e}()},writable:!0,enumerable:!0,configurable:!0},varying:{value:function(a){var b=this,c=void 0===arguments[1]?"tmp_"+D++:arguments[1];return function(){return b._variables[c]={name:c,type:a,prefix:"varying"},b._variables[c]}()},writable:!0,enumerable:!0,configurable:!0},precision:{value:function(a,b){var c="tmp_"+D++;return this._variables[c]={name:b,type:a,prefix:"precision"},this._variables[c]},writable:!0,enumerable:!0,configurable:!0},code:{value:function b(b,a){var c;if("undefined"!=typeof a)for(var d in a)c="object"==typeof a[d]?a[d].name:a[d],b=b.replace(new RegExp("%"+d,"gm"),c);return this._code+=b+"\n",this},writable:!0,enumerable:!0,configurable:!0},getVariable:{value:function(a){if("undefined"!=typeof this._variables[a])return this._variables[a];throw"The variable "+a+" is not set."},writable:!0,enumerable:!0,configurable:!0},toString:{value:function(){var a,b,c="";for(a in this._variables)b=this._variables[a],b instanceof F?c+="uniform "+b.type+" "+b.name+";\n":b instanceof B?c+="attribute "+b.type+" "+b.name+";\n":"object"==typeof b&&(c+=""+b.prefix+" "+b.type+" "+b.name+";\n");return c+="void main() {\n"+this._code+"\n}"},writable:!0,enumerable:!0,configurable:!0}}),a}(),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},F=function(){function a(a,b,c){this.type=a,this.name=b,this.onupdate=null,this._porgrammer=c}return f(a,null,{create:{value:function(){this.location=this._porgrammer.renderer.gl.getUniformLocation(this._porgrammer.program,this.name)},writable:!0,enumerable:!0,configurable:!0},update:{value:function(){"function"==typeof this.onupdate&&this.onupdate.apply(this)},writable:!0,enumerable:!0,configurable:!0},value:{value:function b(b){var a=this._porgrammer.gl;b instanceof w?a.uniform3fv(this.location,b.toArray()):b instanceof v?a.uniformMatrix4fv(this.location,!1,b.toArray()):b instanceof t?a.uniformMatrix3fv(this.location,!1,b.toArray()):"object"==typeof b?4===b.length?a.uniform4fv(this.location,b):3===b.length?a.uniform3fv(this.location,b):9===b.length?a.uniformMatrix3fv(this.location,!1,b):16===b.length&&a.uniformMatrix4fv(this.location,!1,b):"boolean"==typeof b?a.uniform1i(this.location,b):a.uniform1f(this.location,b)},writable:!0,enumerable:!0,configurable:!0}}),a}();a.LiThree={Renderer:z,WebGLRenderer:A,World:l,Object3D:y,Camera:{Perspective:g},Color:h,Math:{Vector3:w,Matrix4:v},Light:{Directional:q,Point:r},ObjectFactory:{Circle:b,Cylinder:d,Cube:c,Sphere:e}}}(this);
//# sourceMappingURL=lithree.min.js.map