var clay=(function(){var g='function';var j='string';var k=math.sin;var n=math.cos;var o=math.sqrt;var $={namespace:function(a,b){var c=a.split('.');var l=c.length;var d=this;for(var i=0;i=0;i--){mci=mc[i];m1i=b[i];m1i0=m1i[0];m1i1=m1i[1];m1i2=m1i[2];mci[0]=m1i0*m20[0]+m1i1*m21[0]+m1i2*m22[0];mci[1]=m1i0*m20[1]+m1i1*m21[1]+m1i2*m22[1];mci[2]=m1i0*m20[2]+m1i1*m21[2]+m1i2*m22[2];mci[3]=m1i0*m20[3]+m1i1*m21[3]+m1i2*m22[3]+m1i[3]}this.base=mc},scale:function(a,b,c){var m=[[a,0,0,0],[0,b,0,0],[0,0,c,0]];this.concat(m)},translate:function(a,b,c){var m=[[1,0,0,a],[0,1,0,b],[0,0,1,c]];this.concat(m)},rotatex:function(a){var s=k(a),c=n(a),m=[[1,0,0,0],[0,c,s,0],[0,-s,c,0]];this.concat(m)},rotatey:function(a){var s=k(a),c=n(a),m=[[c,0,-s,0],[0,1,0,0],[s,0,c,0]];this.concat(m)},rotatez:function(a){var s=k(a),c=n(a),m=[[c,s,0,0],[-s,c,0,0],[0,0,1,0]];this.concat(m)},clone:function(){var m=new t(),b0=this.base[0],b1=this.base[1],b2=this.base[2];m.set([[b0[0],b0[1],b0[2],b0[3]],[b1[0],b1[1],b1[2],b1[3]],[b2[0],b2[1],b2[2],b2[3]]]);return m}};$.namespace('matrix',t);return $})(); (function($){var g=math.floor;var j=function(w,h,a){this.zbuffer=new k();this.canvas=document.createelement('canvas');this.canvas.classname='canvas3d';document.getelementbyid('canvasmap').appendchild(this.canvas);this.setresolution(w,h)};j.prototype={setresolution:function(w,h){this.width=w;this.height=h;this.cx=w/2;this.cy=h/2;this.canvas.width=this.width;this.canvas.height=this.height;this.context=this.canvas.getcontext('2d')},setbackground:function(a){this.canvas.style.background=a},render:function(a,b){var c=this.context;this.prerender(this);var d=this.zbuffer.sort(b.render(a));var l=d.length;for(var i=0;i=0;i--){b=polies[i];if(q(x,y,b)){var c={targetpolygon:b,targetshape:b.shape,clientx:x,clienty:y};a(c);break}}}};$.namespace('renderer',j);var k=function(){this.polygons=[];this.visiblepolygons=[];this.hash=null};k.prototype={getpolygons:function(){return this.visiblepolygons},sort:function(a){if(this.hash!=a.length){var b=[];var l=a.length;for(var i=0;i1){o(this.visiblepolygons,0,v-1)}return this.visiblepolygons}};var m=function(a,b,c,d){if(a.behindscreen||b.behindscreen||c.behindscreen||(d&&d.behindscreen)){return true}return((c.screenx-a.screenx)*(b.screeny-c.screeny))>((c.screeny-a.screeny)*(b.screenx-c.screenx))};var n=function(a){var p=a.screen;if(m.apply(window,p)){return false}var l=p.length;var b=p[0].z;for(var i=1;i=d.depth){bot++}while(a[top].depthc&&xe&&ythis.width||y>this.height)?true:false;a.offscreen&=(p.behindscreen||p.offscreen)}}});g.implement(r,n);$.namespace('camera',r)})(clay); (function($){var e=$.class;var h=$.vector;var j=math.pi/2;var k=math.acos;var l=e.extend(h,function(x,y,z,b,i){this.direction=new h(z,y,z).normalize();this.light=new h(x,y,z);this.setbrightness(b||1);this.setintensity(i||1);this.setcolor(255,255,255)},{transform:function(a){this.direction=this.light.transform(a).normalize()},setcolor:function(r,g,b){this.r=r/255;this.g=g/255;this.b=b/255},setbrightness:function(b){this.brightness=b*j},setintensity:function(i){this.intensity=i/j},getfactor:function(a,b){var c=a.dot(this.direction);var d=k(c);var f=(this.brightness-d)*this.intensity;b[0]+=(this.r*f);b[1]+=(this.g*f);b[2]+=(this.b*f)},iterate:function(){}});$.namespace('light',l);$.namespace('ambientlight',e.extend(l,null,{getfactor:function(){var f=this.brightness*this.intensity;factors[0]+=(this.r*f);factors[1]+=(this.g*f);factors[2]+=(this.b*f)}}));$.namespace('directionallight',e.extend(l,null,{getfactor:function(){var a=normal.dot(this.direction);var b=k(a);var f=(this.brightness-b)*this.intensity;factors[0]+=(this.r*f);factors[1]+=(this.g*f);factors[2]+=(this.b*f)}}))})(clay); (function($){var q=$.class;var s=$.vector;var u=function(a,b){this.indices=a;this.shape=b;this.screen=[];this.points=[];for(var i=0;i1){a=(i*l)+j-n;b=(i*l)+(j+1)%l-n;c=b-l;d=a-l;g.push([d,c,b,a]);if(i==l-1){a=(i*l)+j-n;b=(i*l)+(j+1)%l-n;c=o;g.push([a,b,c])}}}}h.push({x:0,y:-r,z:0});return new $.shape(x,y,z,h,g,e,f)});$.namespace('tube',function(x,y,z,h,r,w,l,e,f){var g=[];var j=[];var k,sx2,sz1,sz2,sr1,sr2;var m=(math.pi*2)/l;var a,b,c,d;for(var i=0;i