text: /** seen.js v0.2.0 | themadcreator.github.io/seen | (c) Bill Dwyer | @license: Apache 2.0 */
  (function(){var t,n,e,i,r,o,s,a,u,h,l,c,p,f,d,y,m,g,_,v,w,x,M,P,S,b,C,q,z=function(t,n){return function(){return t.apply(n,arguments)}},E=[].slice,R={}.hasOwnProperty,D=function(t,n){function e(){this.constructor=t}for(var i in n)R.call(n,i)&&(t[i]=n[i]);return e.prototype=n.prototype,t.prototype=new e,t.__super__=n.prototype,t};P={},"undefined"!=typeof window&&null!==window&&(window.seen=P),null!=("undefined"!=typeof module&&null!==module?module.exports:void 0)&&(module.exports=P),d=1,P.Util={defaults:function(t,n,e){var i,r;for(i in n)null==t[i]&&(t[i]=n[i]);r=[];for(i in e)r.push(null==t[i]?t[i]=e[i]:void 0);return r},arraysEqual:function(t,n){var e,i,r,o;if(!t.length===n.length)return!1;for(e=r=0,o=t.length;o>r;e=++r)if(i=t[e],i!==n[e])return!1;return!0},uniqueId:function(t){return null==t&&(t=""),t+d++},element:function(t){return"string"==typeof t?document.getElementById(t):t}},P.Events={dispatch:function(){var t,n,e,i;for(n=new P.Events.Dispatcher,e=0,i=arguments.length;i>e;e++)t=arguments[e],n[t]=P.Events.Event();return n}},P.Events.Dispatcher=function(){function t(){this.on=z(this.on,this)}return t.prototype.on=function(t,n){var e,i;return e=t.indexOf("."),i="",e>0&&(i=t.substring(e+1),t=t.substring(0,e)),null!=this[t]&&this[t].on(i,n),this},t}(),P.Events.Event=function(){var t;return t=function(){var n,e,i,r;i=t.listenerMap,r=[];for(e in i)n=i[e],r.push(null!=n?n.apply(this,arguments):void 0);return r},t.listenerMap={},t.on=function(n,e){return delete t.listenerMap[n],null!=e?t.listenerMap[n]=e:void 0},t},t=new Array(16),f=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],w=[0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15],P.Matrix=function(){function n(t){this.m=null!=t?t:null,null==this.m&&(this.m=f.slice()),this.baked=f}return n.prototype.copy=function(){return new P.Matrix(this.m.slice())},n.prototype.matrix=function(n){var e,i,r,o,s;for(e=t,r=o=0;4>o;r=++o)for(i=s=0;16>s;i=s+=4)e[i+r]=n[i]*this.m[r]+n[i+1]*this.m[4+r]+n[i+2]*this.m[8+r]+n[i+3]*this.m[12+r];return t=this.m,this.m=e,this},n.prototype.reset=function(){return this.m=this.baked.slice(),this},n.prototype.bake=function(t){return this.baked=(null!=t?t:this.m).slice(),this},n.prototype.multiply=function(t){return this.matrix(t.m)},n.prototype.transpose=function(){var n,e,i,r,o;for(n=t,e=r=0,o=w.length;o>r;e=++r)i=w[e],n[e]=this.m[i];return t=this.m,this.m=n,this},n.prototype.rotx=function(t){var n,e,i;return n=Math.cos(t),i=Math.sin(t),e=[1,0,0,0,0,n,-i,0,0,i,n,0,0,0,0,1],this.matrix(e)},n.prototype.roty=function(t){var n,e,i;return n=Math.cos(t),i=Math.sin(t),e=[n,0,i,0,0,1,0,0,-i,0,n,0,0,0,0,1],this.matrix(e)},n.prototype.rotz=function(t){var n,e,i;return n=Math.cos(t),i=Math.sin(t),e=[n,-i,0,0,i,n,0,0,0,0,1,0,0,0,0,1],this.matrix(e)},n.prototype.translate=function(t,n,e){var i;return null==t&&(t=0),null==n&&(n=0),null==e&&(e=0),i=[1,0,0,t,0,1,0,n,0,0,1,e,0,0,0,1],this.matrix(i)},n.prototype.scale=function(t,n,e){var i;return null==t&&(t=1),null==n&&(n=t),null==e&&(e=n),i=[t,0,0,0,0,n,0,0,0,0,e,0,0,0,0,1],this.matrix(i)},n}(),P.M=function(t){return new P.Matrix(t)},P.Matrices={identity:function(){return P.M()},flipX:function(){return P.M().scale(-1,1,1)},flipY:function(){return P.M().scale(1,-1,1)},flipZ:function(){return P.M().scale(1,1,-1)}},P.Transformable=function(){function t(){var t,n,e,i,r;for(this.m=new P.Matrix,this.baked=f,r=["scale","translate","rotx","roty","rotz","matrix","reset","bake"],n=function(t){return function(n){return t[n]=function(){var t;return(t=this.m[n]).call.apply(t,[this.m].concat(E.call(arguments))),this}}}(this),e=0,i=r.length;i>e;e++)t=r[e],n(t)}return t.prototype.transform=function(t){return this.m.multiply(t),this},t}(),P.Point=function(){function t(t,n,e,i){this.x=null!=t?t:0,this.y=null!=n?n:0,this.z=null!=e?e:0,this.w=null!=i?i:1}return t.prototype.copy=function(){return new P.Point(this.x,this.y,this.z,this.w)},t.prototype.set=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},t.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},t.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},t.prototype.translate=function(t,n,e){return this.x+=t,this.y+=n,this.z+=e,this},t.prototype.multiply=function(t){return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.divide=function(t){return this.x/=t,this.y/=t,this.z/=t,this},t.prototype.round=function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this},t.prototype.normalize=function(){var t;return t=this.magnitude(),0===t?this.set(P.Points.Z()):this.divide(t),this},t.prototype.transform=function(t){var n;return n=y,n.x=this.x*t.m[0]+this.y*t.m[1]+this.z*t.m[2]+this.w*t.m[3],n.y=this.x*t.m[4]+this.y*t.m[5]+this.z*t.m[6]+this.w*t.m[7],n.z=this.x*t.m[8]+this.y*t.m[9]+this.z*t.m[10]+this.w*t.m[11],n.w=this.x*t.m[12]+this.y*t.m[13]+this.z*t.m[14]+this.w*t.m[15],this.set(n),this},t.prototype.magnitudeSquared=function(){return this.dot(this)},t.prototype.magnitude=function(){return Math.sqrt(this.magnitudeSquared())},t.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},t.prototype.cross=function(t){var n;return n=y,n.x=this.y*t.z-this.z*t.y,n.y=this.z*t.x-this.x*t.z,n.z=this.x*t.y-this.y*t.x,this.set(n),this},t}(),P.P=function(t,n,e,i){return new P.Point(t,n,e,i)},y=P.P(),P.Points={X:function(){return P.P(1,0,0)},Y:function(){return P.P(0,1,0)},Z:function(){return P.P(0,0,1)},ZERO:function(){return P.P(0,0,0)}},P.Quaternion=function(){function t(){this.q=P.P.apply(P,arguments)}return t.pixelsPerRadian=150,t.xyToTransform=function(t,n){var e,i;return e=P.Quaternion.pointAngle(P.Points.Y(),t/P.Quaternion.pixelsPerRadian),i=P.Quaternion.pointAngle(P.Points.X(),n/P.Quaternion.pixelsPerRadian),e.multiply(i).toMatrix()},t.axisAngle=function(t,n,e,i){var r,o;return r=Math.sin(i/2),o=Math.cos(i/2),new P.Quaternion(r*t,r*n,r*e,o)},t.pointAngle=function(t,n){var e,i;return e=Math.sin(n/2),i=Math.cos(n/2),new P.Quaternion(e*t.x,e*t.y,e*t.z,i)},t.prototype.multiply=function(t){var n,e;return n=P.P(),n.w=this.q.w*t.q.w-this.q.x*t.q.x-this.q.y*t.q.y-this.q.z*t.q.z,n.x=this.q.w*t.q.x+this.q.x*t.q.w+this.q.y*t.q.z-this.q.z*t.q.y,n.y=this.q.w*t.q.y+this.q.y*t.q.w+this.q.z*t.q.x-this.q.x*t.q.z,n.z=this.q.w*t.q.z+this.q.z*t.q.w+this.q.x*t.q.y-this.q.y*t.q.x,e=new P.Quaternion,e.q=n,e},t.prototype.toMatrix=function(){var t;return t=new Array(16),t[0]=1-2*(this.q.y*this.q.y+this.q.z*this.q.z),t[1]=2*(this.q.x*this.q.y-this.q.w*this.q.z),t[2]=2*(this.q.x*this.q.z+this.q.w*this.q.y),t[3]=0,t[4]=2*(this.q.x*this.q.y+this.q.w*this.q.z),t[5]=1-2*(this.q.x*this.q.x+this.q.z*this.q.z),t[6]=2*(this.q.y*this.q.z-this.q.w*this.q.x),t[7]=0,t[8]=2*(this.q.x*this.q.z-this.q.w*this.q.y),t[9]=2*(this.q.y*this.q.z+this.q.w*this.q.x),t[10]=1-2*(this.q.x*this.q.x+this.q.y*this.q.y),t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,P.M(t)},t}(),P.Color=function(){function t(t,n,e,i){this.r=null!=t?t:0,this.g=null!=n?n:0,this.b=null!=e?e:0,this.a=null!=i?i:255}return t.prototype.copy=function(){return new P.Color(this.r,this.g,this.b,this.a)},t.prototype.scale=function(t){return this.r*=t,this.g*=t,this.b*=t,this},t.prototype.offset=function(t){return this.r+=t,this.g+=t,this.b+=t,this},t.prototype.clamp=function(t,n){return null==t&&(t=0),null==n&&(n=255),this.r=Math.min(n,Math.max(t,this.r)),this.g=Math.min(n,Math.max(t,this.g)),this.b=Math.min(n,Math.max(t,this.b)),this},t.prototype.minChannels=function(t){return this.r=Math.min(t.r,this.r),this.g=Math.min(t.g,this.g),this.b=Math.min(t.b,this.b),this},t.prototype.addChannels=function(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this},t.prototype.multiplyChannels=function(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this},t.prototype.hex=function(){var t;for(t=(this.r<<16|this.g<<8|this.b).toString(16);t.length<6;)t="0"+t;return"#"+t},t.prototype.style=function(){return"rgba("+this.r+","+this.g+","+this.b+","+this.a+")"},t}(),P.Colors={rgb:function(t,n,e,i){return null==i&&(i=255),new P.Color(t,n,e,i)},hex:function(t){return"#"===t.charAt(0)&&(t=t.substring(1)),new P.Color(parseInt(t.substring(0,2),16),parseInt(t.substring(2,4),16),parseInt(t.substring(4,6),16))},hsl:function(t,n,e,i){var r,o,s,a,u,h;return null==i&&(i=1),h=o=r=0,0===n?h=o=r=e:(s=function(t,n,e){return 0>e?e+=1:e>1&&(e-=1),1/6>e?t+6*(n-t)*e:.5>e?n:2/3>e?t+(n-t)*(2/3-e)*6:t},u=.5>e?e*(1+n):e+n-e*n,a=2*e-u,h=s(a,u,t+1/3),o=s(a,u,t),r=s(a,u,t-1/3)),new P.Color(255*h,255*o,255*r,255*i)},randomSurfaces:function(t,n,e){var i,r,o,s,a;for(null==n&&(n=.5),null==e&&(e=.4),s=t.surfaces,a=[],r=0,o=s.length;o>r;r++)i=s[r],a.push(i.fill=new P.Material(P.Colors.hsl(Math.random(),n,e)));return a},randomSurfaces2:function(t,n,e,i){var r,o,s,a,u,h;for(null==n&&(n=.03),null==e&&(e=.5),null==i&&(i=.4),r=Math.random(),u=t.surfaces,h=[],s=0,a=u.length;a>s;s++){for(o=u[s],r+=(Math.random()-.5)*n;0>r;)r+=1;for(;r>1;)r-=1;h.push(o.fill=new P.Material(P.Colors.hsl(r,.5,.4)))}return h},randomShape:function(t,n,e){return null==n&&(n=.5),null==e&&(e=.4),t.fill(new P.Material(P.Colors.hsl(Math.random(),n,e)))},black:function(){return this.hex("#000000")},white:function(){return this.hex("#FFFFFF")},gray:function(){return this.hex("#888888")}},P.C=function(t,n,e,i){return new P.Color(t,n,e,i)},P.Material=function(){function t(t,n){this.color=t,null==n&&(n={}),P.Util.defaults(this,n,this.defaults)}return t.prototype.defaults={color:P.Colors.gray(),metallic:!1,specularColor:P.Colors.white(),specularExponent:15,shader:null},t.prototype.render=function(t,n,e){var i,r,o;return r=null!=(o=this.shader)?o:n,i=r.shade(t,e,this),i.a=this.color.a,i},t}(),P.Light=function(t){function n(t,e){this.type=t,n.__super__.constructor.apply(this,arguments),P.Util.defaults(this,e,this.defaults),this.id=P.Util.uniqueId("l")}return D(n,t),n.prototype.defaults={point:P.P(),color:P.Colors.white(),intensity:.01,normal:P.P(1,-1,-1).normalize(),enabled:!0},n.prototype.render=function(){return this.colorIntensity=this.color.copy().scale(this.intensity)},n}(P.Transformable),P.Lights={point:function(t){return new P.Light("point",t)},directional:function(t){return new P.Light("directional",t)},ambient:function(t){return new P.Light("ambient",t)}},a=P.Points.Z(),P.ShaderUtils={applyDiffuse:function(t,n,e,i){var r;return r=e.dot(i),r>0?t.addChannels(n.colorIntensity.copy().scale(r)):void 0},applyDiffuseAndSpecular:function(t,n,e,i,r){var o,s,u,h;return o=e.dot(i),o>0?(t.addChannels(n.colorIntensity.copy().scale(o)),s=i.copy().multiply(2*o).subtract(e),h=Math.pow(.5+s.dot(a),r.specularExponent),u=r.specularColor.copy().scale(h*n.intensity/255),t.addChannels(u)):void 0},applyAmbient:function(t,n){return t.addChannels(n.colorIntensity)}},P.Shader=function(){function t(){}return t.prototype.shade=function(){},t}(),_=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.shade=function(t,n,e){var i,r,o,s,a;for(i=new P.Color,s=0,a=t.length;a>s;s++)switch(r=t[s],r.type){case"point":o=r.point.copy().subtract(n.barycenter).normalize(),P.ShaderUtils.applyDiffuseAndSpecular(i,r,o,n.normal,e);break;case"directional":P.ShaderUtils.applyDiffuseAndSpecular(i,r,r.normal,n.normal,e);break;case"ambient":P.ShaderUtils.applyAmbient(i,r)}return i.multiplyChannels(e.color),e.metallic&&i.minChannels(e.specularColor),i.clamp(0,255),i},n}(P.Shader),o=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.shade=function(t,n,e){var i,r,o,s,a;for(i=new P.Color,s=0,a=t.length;a>s;s++)switch(r=t[s],r.type){case"point":o=r.point.copy().subtract(n.barycenter).normalize(),P.ShaderUtils.applyDiffuse(i,r,o,n.normal,e);break;case"directional":P.ShaderUtils.applyDiffuse(i,r,r.normal,n.normal,e);break;case"ambient":P.ShaderUtils.applyAmbient(i,r)}return i.multiplyChannels(e.color).clamp(0,255),i},n}(P.Shader),n=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.shade=function(t,n,e){var i,r,o,s;for(i=new P.Color,o=0,s=t.length;s>o;o++)switch(r=t[o],r.type){case"ambient":P.ShaderUtils.applyAmbient(i,r)}return i.multiplyChannels(e.color).clamp(0,255),i},n}(P.Shader),u=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.shade=function(t,n,e){return e.color},n}(P.Shader),P.Shaders={phong:function(){return new _},diffuse:function(){return new o},ambient:function(){return new n},flat:function(){return new u}},P.RenderContext=function(){function t(){this.render=z(this.render,this),this.layers=[]}return t.prototype.render=function(){var t,n,e,i;for(this.reset(),i=this.layers,n=0,e=i.length;e>n;n++)t=i[n],t.context.reset(),t.layer.render(t.context),t.context.cleanup();return this.cleanup(),this},t.prototype.animate=function(){return new P.RenderAnimator(this)},t.prototype.layer=function(t){return this.layers.push({layer:t,context:this}),this},t.prototype.sceneLayer=function(t){return this.layer(new P.SceneLayer(t)),this},t.prototype.reset=function(){},t.prototype.cleanup=function(){},t}(),P.RenderLayerContext=function(){function t(){}return t.prototype.path=function(){},t.prototype.rect=function(){},t.prototype.circle=function(){},t.prototype.text=function(){},t.prototype.reset=function(){},t.prototype.cleanup=function(){},t}(),P.Context=function(t,n){var e,i,r;return null==n&&(n=null),i=null!=(r=P.Util.element(t))?r.tagName.toUpperCase():void 0,e=function(){switch(i){case"SVG":return new P.SvgRenderContext(t);case"CANVAS":return new P.CanvasRenderContext(t)}}(),null!=e&&null!=n&&e.sceneLayer(n),e},P.Painter=function(){function t(){}return t.prototype.paint=function(){},t}(),g=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.paint=function(t,n){var e,i,r;return e=n.path().path(t.projected.points),null!=t.fill&&e.fill({fill:null==t.fill?"none":t.fill.hex(),"fill-opacity":null==(null!=(i=t.fill)?i.a:void 0)?1:t.fill.a/255}),null!=t.stroke?e.draw({fill:"none",stroke:null==t.stroke?"none":t.stroke.hex(),"stroke-width":null!=(r=t.surface["stroke-width"])?r:1}):void 0},n}(P.Painter),x=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.paint=function(t,n){var e,i,r;return i=t.transform.copy().multiply(t.projection),e={fill:null==t.fill?"none":t.fill.hex(),"text-anchor":null!=(r=t.surface.anchor)?r:"middle"},n.text().fillText(i,t.surface.text,e)},n}(P.Painter),P.Painters={path:new g,text:new x},r=P.Points.Z(),P.RenderModel=function(){function t(t,n,e){this.surface=t,this.transform=n,this.projection=e,this.points=this.surface.points,this.transformed=this._initRenderData(),this.projected=this._initRenderData(),this._update()}return t.prototype.update=function(t,n){return!this.surface.dirty&&P.Util.arraysEqual(t.m,this.transform.m)&&P.Util.arraysEqual(n.m,this.projection.m)?void 0:(this.transform=t,this.projection=n,this._update())},t.prototype._update=function(){return this._math(this.transformed,this.points,this.transform,!1),this._math(this.projected,this.transformed.points,this.projection,!0),this.surface.dirty=!1},t.prototype._initRenderData=function(){var t;return{points:function(){var n,e,i,r;for(i=this.points,r=[],n=0,e=i.length;e>n;n++)t=i[n],r.push(t.copy());return r}.call(this),barycenter:P.P(),normal:P.P(),v0:P.P(),v1:P.P()}},t.prototype._math=function(t,n,e,i){var o,s,a,u,h,l,c,p;for(null==i&&(i=!1),o=u=0,l=n.length;l>u;o=++u)s=n[o],a=t.points[o],a.set(s).transform(e),i&&a.divide(a.w);for(t.barycenter.multiply(0),p=t.points,h=0,c=p.length;c>h;h++)s=p[h],t.barycenter.add(s);return t.barycenter.divide(t.points.length),t.points.length<2?(t.v0.set(r),t.v1.set(r),t.normal.set(r)):(t.v0.set(t.points[1]).subtract(t.points[0]),t.v1.set(t.points[n.length-1]).subtract(t.points[0]),t.normal.set(t.v0).cross(t.v1).normalize())},t}(),P.LightRenderModel=function(){function t(t,n){var e;this.light=t,this.colorIntensity=t.color.copy().scale(t.intensity),this.type=t.type,this.intensity=t.intensity,this.point=t.point.copy().transform(n),e=P.Points.ZERO().transform(n),this.normal=t.normal.copy().transform(n).subtract(e).normalize()}return t}(),P.RenderLayer=function(){function t(){this.render=z(this.render,this)}return t.prototype.render=function(){},t}(),P.SceneLayer=function(t){function n(t){this.scene=t,this.render=z(this.render,this)}return D(n,t),n.prototype.render=function(t){var n,e,i,r,o;for(r=this.scene.render(),o=[],e=0,i=r.length;i>e;e++)n=r[e],o.push(n.surface.painter.paint(n,t));return o},n}(P.RenderLayer),P.FillLayer=function(t){function n(t,n,e){this.width=null!=t?t:500,this.height=null!=n?n:500,this.fill=null!=e?e:"#EEE",this.render=z(this.render,this)}return D(n,t),n.prototype.render=function(t){return t.rect().rect(this.width,this.height).fill({fill:this.fill})},n}(P.RenderLayer),q=function(t){return document.createElementNS("http://www.w3.org/2000/svg",t)},P.SvgStyler=function(){function t(t){this.elementFactory=t}return t.prototype._attributes={},t.prototype._svgTag="g",t.prototype.clear=function(){return this._attributes={},this},t.prototype.fill=function(t){return null==t&&(t={}),this._paint(t),this},t.prototype.draw=function(t){return null==t&&(t={}),this._paint(t),this},t.prototype._paint=function(t){var n,e,i,r,o;n=this.elementFactory(this._svgTag),i="";for(e in t)r=t[e],i+=""+e+":"+r+";";n.setAttribute("style",i),o=this._attributes;for(e in o)r=o[e],n.setAttribute(e,r);return n},t}(),P.SvgPathPainter=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype._svgTag="path",n.prototype.path=function(t){return this._attributes.d="M"+t.map(function(t){return""+t.x+" "+t.y}).join("L"),this},n}(P.SvgStyler),P.SvgTextPainter=function(){function t(t){this.elementFactory=t}return t.prototype._svgTag="text",t.prototype.fillText=function(t,n,e){var i,r,o,s,a;null==e&&(e={}),i=this.elementFactory(this._svgTag),o=P.Matrices.flipY().multiply(t).m,i.setAttribute("transform","matrix("+o[0]+" "+o[4]+" "+o[1]+" "+o[5]+" "+o[3]+" "+o[7]+")"),i.setAttribute("font-family","Roboto"),s="";for(r in e)a=e[r],s+=""+r+":"+a+";";return i.setAttribute("style",s),i.textContent=n},t}(),P.SvgRectPainter=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype._svgTag="rect",n.prototype.rect=function(t,n){return this._attributes.width=t,this._attributes.height=n,this},n}(P.SvgStyler),P.SvgCirclePainter=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype._svgTag="circle",n.prototype.circle=function(t,n){return this._attributes.cx=t.x,this._attributes.cy=t.y,this._attributes.r=n,this},n}(P.SvgStyler),P.SvgLayerRenderContext=function(t){function n(t){this.group=t,this._elementFactory=z(this._elementFactory,this),this.pathPainter=new P.SvgPathPainter(this._elementFactory),this.textPainter=new P.SvgTextPainter(this._elementFactory),this.circlePainter=new P.SvgCirclePainter(this._elementFactory),this.rectPainter=new P.SvgRectPainter(this._elementFactory),this._i=0}return D(n,t),n.prototype.path=function(){return this.pathPainter.clear()},n.prototype.rect=function(){return this.rectPainter.clear()},n.prototype.circle=function(){return this.circlePainter.clear()},n.prototype.text=function(){return this.textPainter},n.prototype.reset=function(){return this._i=0},n.prototype.cleanup=function(){var t,n;for(t=this.group.childNodes,n=[];this._i<t.length;)t[this._i].setAttribute("style","display: none;"),n.push(this._i++);return n},n.prototype._elementFactory=function(t){var n,e,i;return n=this.group.childNodes,this._i>=n.length?(i=q(t),this.group.appendChild(i),this._i++,i):(e=n[this._i],e.tagName===t?(this._i++,e):(i=q(t),this.group.replaceChild(i,e),this._i++,i))},n}(P.RenderLayerContext),P.SvgRenderContext=function(t){function n(t){this.svg=t,n.__super__.constructor.call(this),this.svg=P.Util.element(this.svg)}return D(n,t),n.prototype.layer=function(t){var n;return this.svg.appendChild(n=q("g")),this.layers.push({layer:t,context:new P.SvgLayerRenderContext(n)}),this},n}(P.RenderContext),P.SvgContext=function(t,n){var e;return e=new P.SvgRenderContext(t),null!=n&&e.sceneLayer(n),e},P.CanvasStyler=function(){function t(t){this.ctx=t}return t.prototype.draw=function(t){return null==t&&(t={}),null!=t.stroke&&(this.ctx.strokeStyle=t.stroke),null!=t["stroke-width"]&&(this.ctx.lineWidth=t["stroke-width"]),null!=t["text-anchor"]&&(this.ctx.textAlign=t["text-anchor"]),this.ctx.stroke(),this},t.prototype.fill=function(t){return null==t&&(t={}),null!=t.fill&&(this.ctx.fillStyle=t.fill),null!=t["text-anchor"]&&(this.ctx.textAlign=t["text-anchor"]),t["fill-opacity"]&&(this.ctx.globalAlpha=t["fill-opacity"]),this.ctx.fill(),this},t}(),P.CanvasPathPainter=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.path=function(t){var n,e,i,r;for(this.ctx.beginPath(),n=i=0,r=t.length;r>i;n=++i)e=t[n],0===n?this.ctx.moveTo(e.x,e.y):this.ctx.lineTo(e.x,e.y);return this.ctx.closePath(),this},n}(P.CanvasStyler),P.CanvasRectPainter=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.rect=function(t,n){return this.ctx.rect(0,0,t,n),this},n}(P.CanvasStyler),P.CanvasCirclePainter=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.circle=function(t,n){return this.ctx.beginPath(),this.ctx.arc(t.x,t.y,n,0,2*Math.PI,!0),this},n}(P.CanvasStyler),P.CanvasTextPainter=function(){function t(t){this.ctx=t}return t.prototype.fillText=function(t,n,e){var i;return null==e&&(e={}),i=P.Matrices.flipY().multiply(t).m,this.ctx.save(),this.ctx.font="16px Roboto",this.ctx.setTransform(i[0],i[4],i[1],i[5],i[3],i[7]),null!=e.fill&&(this.ctx.fillStyle=e.fill),null!=e["text-anchor"]&&(this.ctx.textAlign=e["text-anchor"]),this.ctx.fillText(n,0,0),this.ctx.restore(),this},t}(),P.CanvasLayerRenderContext=function(t){function n(t){this.ctx=t,this.pathPainter=new P.CanvasPathPainter(this.ctx),this.ciclePainter=new P.CanvasCirclePainter(this.ctx),this.textPainter=new P.CanvasTextPainter(this.ctx),this.rectPainter=new P.CanvasRectPainter(this.ctx)}return D(n,t),n.prototype.path=function(){return this.pathPainter},n.prototype.rect=function(){return this.rectPainter},n.prototype.circle=function(){return this.ciclePainter},n.prototype.text=function(){return this.textPainter},n}(P.RenderLayerContext),P.CanvasRenderContext=function(t){function n(t){this.el=t,n.__super__.constructor.call(this),this.el=P.Util.element(this.el),this.ctx=this.el.getContext("2d")}return D(n,t),n.prototype.layer=function(t){return this.layers.push({layer:t,context:new P.CanvasLayerRenderContext(this.ctx)}),this},n.prototype.reset=function(){return this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.el.width,this.el.height)},n}(P.RenderContext),P.CanvasContext=function(t,n){var e;return e=new P.CanvasRenderContext(t),null!=n&&e.sceneLayer(n),e},P.WindowEvents=function(){var t;return t=P.Events.dispatch("mouseMove","mouseDown","mouseUp","touchStart","touchMove","touchEnd","touchCancel"),"undefined"!=typeof window&&null!==window&&(window.addEventListener("mouseup",t.mouseUp,!0),window.addEventListener("mousedown",t.mouseDown,!0),window.addEventListener("mousemove",t.mouseMove,!0),window.addEventListener("touchstart",t.touchStart,!0),window.addEventListener("touchmove",t.touchMove,!0),window.addEventListener("touchend",t.touchEnd,!0),window.addEventListener("touchcancel",t.touchCancel,!0)),{on:t.on}}(),P.MouseEvents=function(){function t(t,n){this.el=t,this._onMouseWheel=z(this._onMouseWheel,this),this._onMouseUp=z(this._onMouseUp,this),this._onMouseDown=z(this._onMouseDown,this),this._onMouseMove=z(this._onMouseMove,this),P.Util.defaults(this,n,this.defaults),this._uid=P.Util.uniqueId("mouser-"),this.dispatch=P.Events.dispatch("dragStart","drag","dragEnd","mouseMove","mouseDown","mouseUp","mouseWheel"),this.on=this.dispatch.on,this._mouseDown=!1,this.attach()}return t.prototype.attach=function(){return this.el.addEventListener("touchstart",this._onMouseDown),this.el.addEventListener("mousedown",this._onMouseDown),this.el.addEventListener("mousewheel",this._onMouseWheel)},t.prototype.detach=function(){return this.el.removeEventListener("touchstart",this._onMouseDown),this.el.removeEventListener("mousedown",this._onMouseDown),this.el.removeEventListener("mousewheel",this._onMouseWheel)},t.prototype._onMouseMove=function(t){return this.dispatch.mouseMove(t),t.preventDefault(),t.stopPropagation(),this._mouseDown?this.dispatch.drag(t):void 0},t.prototype._onMouseDown=function(t){return this._mouseDown=!0,P.WindowEvents.on("mouseUp."+this._uid,this._onMouseUp),P.WindowEvents.on("mouseMove."+this._uid,this._onMouseMove),P.WindowEvents.on("touchEnd."+this._uid,this._onMouseUp),P.WindowEvents.on("touchCancel."+this._uid,this._onMouseUp),P.WindowEvents.on("touchMove."+this._uid,this._onMouseMove),this.dispatch.mouseDown(t),this.dispatch.dragStart(t)},t.prototype._onMouseUp=function(t){return this._mouseDown=!1,P.WindowEvents.on("mouseUp."+this._uid,null),P.WindowEvents.on("mouseMove."+this._uid,null),P.WindowEvents.on("touchEnd."+this._uid,null),P.WindowEvents.on("touchCancel."+this._uid,null),P.WindowEvents.on("touchMove."+this._uid,null),this.dispatch.mouseUp(t),this.dispatch.dragEnd(t)},t.prototype._onMouseWheel=function(t){return this.dispatch.mouseWheel(t)},t}(),P.InertialMouse=function(){function t(){this.reset()}return t.inertiaExtinction=.1,t.smoothingTimeout=300,t.inertiaMsecDelay=30,t.prototype.get=function(){var t;return t=1e3/P.InertialMouse.inertiaMsecDelay,[this.x*t,this.y*t]},t.prototype.reset=function(){return this.xy=[0,0],this},t.prototype.update=function(t){var n,e;return null!=this.lastUpdate?(n=(new Date).getTime()-this.lastUpdate.getTime(),t=t.map(function(t){return t/Math.max(n,1)}),e=Math.min(1,n/P.InertialMouse.smoothingTimeout),this.x=e*t[0]+(1-e)*this.x,this.y=e*t[1]+(1-e)*this.y):(this.x=t[0],this.y=t[1]),this.lastUpdate=new Date,this},t.prototype.damp=function(){return this.x*=1-P.InertialMouse.inertiaExtinction,this.y*=1-P.InertialMouse.inertiaExtinction,this},t}(),P.Drag=function(){function t(t,n){var e;this.el=t,this._stopInertia=z(this._stopInertia,this),this._startInertia=z(this._startInertia,this),this._onInertia=z(this._onInertia,this),this._onDrag=z(this._onDrag,this),this._onDragEnd=z(this._onDragEnd,this),this._onDragStart=z(this._onDragStart,this),this._getPageCoords=z(this._getPageCoords,this),P.Util.defaults(this,n,this.defaults),this.el=P.Util.element(this.el),this._uid=P.Util.uniqueId("dragger-"),this._inertiaRunning=!1,this._dragState={dragging:!1,origin:null,last:null,inertia:new P.InertialMouse},this.dispatch=P.Events.dispatch("drag"),this.on=this.dispatch.on,e=new P.MouseEvents(this.el),e.on("dragStart."+this._uid,this._onDragStart),e.on("dragEnd."+this._uid,this._onDragEnd),e.on("drag."+this._uid,this._onDrag)}return t.prototype.defaults={inertia:!1},t.prototype._getPageCoords=function(t){var n,e;return(null!=(n=t.touches)?n.length:void 0)>0?[t.touches[0].pageX,t.touches[0].pageY]:(null!=(e=t.changedTouches)?e.length:void 0)>0?[t.changedTouches[0].pageX,t.changedTouches[0].pageY]:[t.pageX,t.pageY]},t.prototype._onDragStart=function(t){return this._stopInertia(),this._dragState.dragging=!0,this._dragState.origin=this._getPageCoords(t),this._dragState.last=this._getPageCoords(t)},t.prototype._onDragEnd=function(t){var n,e;return this._dragState.dragging=!1,this.inertia?(e=this._getPageCoords(t),n={offset:[e[0]-this._dragState.origin[0],e[1]-this._dragState.origin[1]],offsetRelative:[e[0]-this._dragState.last[0],e[1]-this._dragState.last[1]]},this._dragState.inertia.update(n.offsetRelative),this._startInertia()):void 0},t.prototype._onDrag=function(t){var n,e;return e=this._getPageCoords(t),n={offset:[e[0]-this._dragState.origin[0],e[1]-this._dragState.origin[1]],offsetRelative:[e[0]-this._dragState.last[0],e[1]-this._dragState.last[1]]},this.dispatch.drag(n),this.inertia&&this._dragState.inertia.update(n.offsetRelative),this._dragState.last=e},t.prototype._onInertia=function(){var t;if(this._inertiaRunning)return t=this._dragState.inertia.damp().get(),Math.abs(t[0])<1&&Math.abs(t[1])<1?void this._stopInertia():(this.dispatch.drag({offset:[this._dragState.last[0]-this._dragState.origin[0],this._dragState.last[0]-this._dragState.origin[1]],offsetRelative:t}),this._dragState.last=[this._dragState.last[0]+t[0],this._dragState.last[1]+t[1]],this._startInertia())},t.prototype._startInertia=function(){return this._inertiaRunning=!0,setTimeout(this._onInertia,P.InertialMouse.inertiaMsecDelay)},t.prototype._stopInertia=function(){return this._dragState.inertia.reset(),this._inertiaRunning=!1},t}(),P.Zoom=function(){function t(t,n){var e;this.el=t,this._onMouseWheel=z(this._onMouseWheel,this),P.Util.defaults(this,n,this.defaults),this.el=P.Util.element(this.el),this._uid=P.Util.uniqueId("zoomer-"),this.dispatch=P.Events.dispatch("zoom"),this.on=this.dispatch.on,e=new P.MouseEvents(this.el),e.on("mouseWheel."+this._uid,this._onMouseWheel)}return t.prototype.defaults={speed:.25},t.prototype._onMouseWheel=function(t){var n,e,i;return t.preventDefault(),n=t.wheelDelta/Math.abs(t.wheelDelta),i=Math.abs(t.wheelDelta)/120*this.speed,e=Math.pow(2,n*i),this.dispatch.zoom({zoom:e})},t}(),P.Surface=function(){function t(t,n){this.points=t,this.painter=null!=n?n:P.Painters.path,this.id="s"+P.Util.uniqueId()}return t.prototype.cullBackfaces=!0,t.prototype.fill=new P.Material(P.C.gray),t.prototype.stroke=null,t}(),P.Shape=function(t){function n(t,e){this.type=t,this.surfaces=e,n.__super__.constructor.call(this)}return D(n,t),n.prototype.eachSurface=function(t){return this.surfaces.forEach(t),this},n.prototype.fill=function(t){return this.eachSurface(function(n){return n.fill=t}),this},n.prototype.stroke=function(t){return this.eachSurface(function(n){return n.stroke=t}),this},n}(P.Transformable),P.Model=function(t){function n(){n.__super__.constructor.call(this),this.children=[],this.lights=[]}return D(n,t),n.prototype.add=function(){var t,n,e,i;for(n=1<=arguments.length?E.call(arguments,0):[],e=0,i=n.length;i>e;e++)t=n[e],t instanceof P.Shape||t instanceof P.Model?this.children.push(t):t instanceof P.Light&&this.lights.push(t);return this},n.prototype.remove=function(){var t,n,e,i,r,o;for(n=1<=arguments.length?E.call(arguments,0):[],o=[],i=0,r=n.length;r>i;i++){for(t=n[i];(e=this.children.indexOf(t))>=0;)this.children.splice(e,1);o.push(function(){var n;for(n=[];(e=this.lights.indexOf(t))>=0;)n.push(this.lights.splice(e,1));return n}.call(this))}return o},n.prototype.append=function(){var t;return t=new P.Model,this.add(t),t},n.prototype.eachShape=function(t){var n,e,i,r,o;for(r=this.children,o=[],e=0,i=r.length;i>e;e++)n=r[e],n instanceof P.Shape&&t.call(this,n),o.push(n instanceof P.Model?n.eachShape(t):void 0);return o},n.prototype.eachRenderable=function(t,n){return this._eachRenderable(t,n,[],this.m)},n.prototype._eachRenderable=function(t,n,e,i){var r,o,s,a,u,h,l,c,p;for(this.lights.length>0&&(e=e.slice()),l=this.lights,s=0,u=l.length;u>s;s++)o=l[s],o.enabled&&e.push(t.call(this,o,o.m.copy().multiply(i)));for(c=this.children,p=[],a=0,h=c.length;h>a;a++)r=c[a],r instanceof P.Shape&&n.call(this,r,e,r.m.copy().multiply(i)),p.push(r instanceof P.Model?r._eachRenderable(t,n,e,r.m.copy().multiply(i)):void 0);return p},n}(P.Transformable),P.Models={"default":function(){var t;return t=new P.Model,t.add(P.Lights.directional({normal:P.P(-1,1,1).normalize(),color:P.Colors.hsl(.1,.3,.7),intensity:.004})),t.add(P.Lights.directional({normal:P.P(1,1,-1).normalize(),intensity:.003})),t.add(P.Lights.ambient({intensity:.0015})),t}},v=[[0,2,1],[0,1,3],[3,2,0],[1,2,3]],e=[[0,1,3,2],[5,4,6,7],[1,0,4,5],[2,3,7,6],[3,1,5,7],[0,2,6,4]],m=[[1,0,2,3],[0,1,4],[2,0,4],[3,2,4],[1,3,4]],s=Math.sqrt(3)/2,c=.5257311121191336,p=.8506508083520399,l=[P.P(-c,0,-p),P.P(c,0,-p),P.P(-c,0,p),P.P(c,0,p),P.P(0,p,-c),P.P(0,p,c),P.P(0,-p,-c),P.P(0,-p,c),P.P(p,c,0),P.P(-p,c,0),P.P(p,-c,0),P.P(-p,-c,0)],h=[[0,4,1],[0,9,4],[9,5,4],[4,5,8],[4,8,1],[8,10,1],[8,3,10],[5,3,8],[5,2,3],[2,7,3],[7,10,3],[7,6,10],[7,11,6],[11,0,6],[0,1,6],[6,1,10],[9,0,11],[9,11,2],[9,2,5],[7,2,11]],P.Shapes={cube:function(){return function(){var t;
  return t=[P.P(-1,-1,-1),P.P(-1,-1,1),P.P(-1,1,-1),P.P(-1,1,1),P.P(1,-1,-1),P.P(1,-1,1),P.P(1,1,-1),P.P(1,1,1)],new P.Shape("cube",P.Shapes.mapPointsToSurfaces(t,e))}}(this),unitcube:function(){return function(){var t;return t=[P.P(0,0,0),P.P(0,0,1),P.P(0,1,0),P.P(0,1,1),P.P(1,0,0),P.P(1,0,1),P.P(1,1,0),P.P(1,1,1)],new P.Shape("unitcube",P.Shapes.mapPointsToSurfaces(t,e))}}(this),rectangle:function(){return function(t,n){var i,r;return i=function(e,i,r){return P.P(e(t.x,n.x),i(t.y,n.y),r(t.z,n.z))},r=[i(Math.min,Math.min,Math.min),i(Math.min,Math.min,Math.max),i(Math.min,Math.max,Math.min),i(Math.min,Math.max,Math.max),i(Math.max,Math.min,Math.min),i(Math.max,Math.min,Math.max),i(Math.max,Math.max,Math.min),i(Math.max,Math.max,Math.max)],new P.Shape("rect",P.Shapes.mapPointsToSurfaces(r,e))}}(this),pyramid:function(){return function(){var t;return t=[P.P(0,0,0),P.P(0,0,1),P.P(1,0,0),P.P(1,0,1),P.P(.5,1,.5)],new P.Shape("pyramid",P.Shapes.mapPointsToSurfaces(t,m))}}(this),tetrahedron:function(){return function(){var t;return t=[P.P(1,1,1),P.P(-1,-1,1),P.P(-1,1,-1),P.P(1,-1,-1)],new P.Shape("tetrahedron",P.Shapes.mapPointsToSurfaces(t,v))}}(this),icosahedron:function(){return new P.Shape("icosahedron",P.Shapes.mapPointsToSurfaces(l,h))},sphere:function(t){var n,e,i;for(null==t&&(t=2),e=h.map(function(t){return t.map(function(t){return l[t]})}),n=i=0;t>=0?t>i:i>t;n=t>=0?++i:--i)e=P.Shapes._subdivideTriangles(e);return new P.Shape("sphere",e.map(function(t){return new P.Surface(t.map(function(t){return t.copy()}))}))},patch:function(t,n){var e,i,r,o,a,u,h,l,c,p,f,d,y,m,g,_,v,w;for(null==t&&(t=20),null==n&&(n=20),t=Math.round(t),n=Math.round(n),u=[],h=c=0;t>=0?t>c:c>t;h=t>=0?++c:--c){for(e=[],l=p=0;n>=0?n>p:p>n;l=n>=0?++p:--p)for(o=[P.P(h,l),P.P(h+1,l-.5),P.P(h+1,l+.5)],a=[P.P(h,l),P.P(h+1,l+.5),P.P(h,l+1)],v=[o,a],f=0,y=v.length;y>f;f++){for(r=v[f],d=0,m=r.length;m>d;d++)i=r[d],i.x*=s,i.y+=h%2===0?.5:0;e.push(r)}if(h%2!==0){for(w=e[0],_=0,g=w.length;g>_;_++)i=w[_],i.y+=n;e.push(e.shift())}u=u.concat(e)}return new P.Shape("patch",u.map(function(t){return new P.Surface(t)}))},text:function(t){var n;return n=new P.Surface([P.P(0,0,0),P.P(20,0,0),P.P(0,20,0)],P.Painters.text),n.text=t,new P.Shape("text",[n])},extrude:function(t,n){var e,i,r,o,s,a,u,h;for(a=[],i=new P.Surface(function(){var n,e,i;for(i=[],n=0,e=t.length;e>n;n++)s=t[n],i.push(s.copy());return i}()),e=new P.Surface(function(){var e,i,r;for(r=[],e=0,i=t.length;i>e;e++)s=t[e],r.push(s.add(n));return r}()),r=u=1,h=t.length;h>=1?h>u:u>h;r=h>=1?++u:--u)a.push(new P.Surface([i.points[r-1].copy(),e.points[r-1].copy(),e.points[r].copy(),i.points[r].copy()]));return o=t.length,a.push(new P.Surface([i.points[o-1].copy(),e.points[o-1].copy(),e.points[0].copy(),i.points[0].copy()])),e.points.reverse(),a.push(i),a.push(e),new P.Shape("extrusion",a)},arrow:function(t,n,e,i,r){var o,s;return null==t&&(t=1),null==n&&(n=1),null==e&&(e=1),null==i&&(i=1),null==r&&(r=0),o=e/2,s=[P.P(0,0,0),P.P(i+r,1,0),P.P(i,o,0),P.P(i+n,o,0),P.P(i+n,-o,0),P.P(i,-o,0),P.P(i+r,-1,0)],P.Shapes.extrude(s,P.P(0,0,t))},path:function(t){return new P.Shape("path",[new P.Surface(t)])},custom:function(t){var n,e,i,r,o,s;for(i=[],s=t.surfaces,r=0,o=s.length;o>r;r++)n=s[r],i.push(new P.Surface(function(){var t,i,r;for(r=[],t=0,i=n.length;i>t;t++)e=n[t],r.push(P.P.apply(P,e));return r}()));return new P.Shape("custom",i)},mapPointsToSurfaces:function(t,n){var e,i,r,o,s,a;for(o=[],s=0,a=n.length;a>s;s++)i=n[s],r=function(){var n,r,o;for(o=[],n=0,r=i.length;r>n;n++)e=i[n],o.push(t[e].copy());return o}(),o.push(new P.Surface(r));return o},_subdivideTriangles:function(t){var n,e,i,r,o,s,a;for(n=[],s=0,a=t.length;a>s;s++)e=t[s],i=e[0].copy().add(e[1]).normalize(),r=e[1].copy().add(e[2]).normalize(),o=e[2].copy().add(e[0]).normalize(),n.push([e[0],i,o]),n.push([e[1],r,i]),n.push([e[2],o,r]),n.push([i,r,o]);return n}},P.ObjParser=function(){function t(){this.vertices=[],this.faces=[],this.commands={v:function(t){return function(n){return t.vertices.push(n.map(function(t){return parseFloat(t)}))}}(this),f:function(t){return function(n){return t.faces.push(n.map(function(t){return parseInt(t)}))}}(this)}}return t.prototype.parse=function(t){var n,e,i,r,o,s,a;for(s=t.split(/[\r\n]+/),a=[],r=0,o=s.length;o>r;r++)i=s[r],e=i.trim().split(/[ ]+/),e.length<2||(n=e.slice(0,1)[0],e=e.slice(1),"#"!==n.charAt(0)&&(null!=this.commands[n]?a.push(this.commands[n](e)):console.log("OBJ Parser: Skipping unknown command '"+n+"'")));return a},t.prototype.mapFacePoints=function(t){return this.faces.map(function(n){return function(e){var i;return i=e.map(function(t){return P.P.apply(P,n.vertices[t-1])}),t.call(n,i)}}(this))},t}(),P.Shapes.obj=function(t,n){var e;return null==n&&(n=!0),e=new P.ObjParser,e.parse(t),new P.Shape("obj",e.mapFacePoints(function(t){var e;return e=new P.Surface(t),e.cullBackfaces=n,e}))},"undefined"!=typeof window&&null!==window&&(M=null!=(S=null!=(b=null!=(C=window.requestAnimationFrame)?C:window.mozRequestAnimationFrame)?b:window.webkitRequestAnimationFrame)?S:window.msRequestAnimationFrame),i=30,P.Animator=function(){function t(){this.frame=z(this.frame,this),this.dispatch=P.Events.dispatch("beforeFrame","afterFrame","frame"),this.on=this.dispatch.on,this.timestamp=0,this._running=!1}return t.prototype.start=function(t){return this._running=!0,this._msecDelay=t,this.animateFrame(),this},t.prototype.stop=function(){return this._running=!1,this},t.prototype.animateFrame=function(){return null!=M&&null==this._msecDelay?M(this.frame):(null==this._msecDelay&&(this._msecDelay=i),setTimeout(this.frame,this._msecDelay))},t.prototype.frame=function(t){var n,e;if(this._running)return this._timestamp=null!=t?t:this._timestamp+(null!=(e=this._msecDelay)?e:i),n=null!=this._lastTimestamp?this._timestamp-this._lastTimestamp:this._timestamp,this.dispatch.beforeFrame(this._timestamp,n),this.dispatch.frame(this._timestamp,n),this.dispatch.afterFrame(this._timestamp,n),this._lastTimestamp=this._timestamp,this.animateFrame(),this},t.prototype.onBefore=function(t){return this.on("beforeFrame."+P.Util.uniqueId("animator-"),t),this},t.prototype.onAfter=function(t){return this.on("afterFrame."+P.Util.uniqueId("animator-"),t),this},t.prototype.onFrame=function(t){return this.on("frame."+P.Util.uniqueId("animator-"),t),this},t}(),P.RenderAnimator=function(t){function n(t){n.__super__.constructor.apply(this,arguments),this.onFrame(t.render)}return D(n,t),n}(P.Animator),P.Transition=function(){function t(t){null==t&&(t={}),P.Util.defaults(this,t,this.defaults)}return t.prototype.defaults={duration:100},t.prototype.update=function(t){return null==this.t&&(this.firstFrame(),this.startT=t),this.t=t,this.tFrac=(this.t-this.startT)/this.duration,this.frame(),this.tFrac>=1?(this.lastFrame(),!1):!0},t.prototype.firstFrame=function(){},t.prototype.frame=function(){},t.prototype.lastFrame=function(){},t}(),P.TransitionAnimator=function(t){function n(){this.update=z(this.update,this),n.__super__.constructor.apply(this,arguments),this.queue=[],this.transitions=[],this.onFrame(this.update)}return D(n,t),n.prototype.add=function(t){return this.transitions.push(t)},n.prototype.keyframe=function(){return this.queue.push(this.transitions),this.transitions=[]},n.prototype.update=function(t){var n;if(this.queue.length)return n=this.queue.shift(),n=n.filter(function(n){return n.update(t)}),n.length?this.queue.unshift(n):void 0},n}(P.Animator),P.Projections={perspectiveFov:function(t,n){var e;return null==t&&(t=50),null==n&&(n=1),e=n*Math.tan(t*Math.PI/360),P.Projections.perspective(-e,e,-e,e,n,2*n)},perspective:function(t,n,e,i,r,o){var s,a,u,h,l;return null==t&&(t=-1),null==n&&(n=1),null==e&&(e=-1),null==i&&(i=1),null==r&&(r=1),null==o&&(o=100),l=2*r,s=n-t,a=i-e,u=o-r,h=new Array(16),h[0]=l/s,h[1]=0,h[2]=(n+t)/s,h[3]=0,h[4]=0,h[5]=l/a,h[6]=(i+e)/a,h[7]=0,h[8]=0,h[9]=0,h[10]=-(o+r)/u,h[11]=-(o*l)/u,h[12]=0,h[13]=0,h[14]=-1,h[15]=0,P.M(h)},ortho:function(t,n,e,i,r,o){var s,a,u,h,l;return null==t&&(t=-1),null==n&&(n=1),null==e&&(e=-1),null==i&&(i=1),null==r&&(r=1),null==o&&(o=100),l=2*r,s=n-t,a=i-e,u=o-r,h=new Array(16),h[0]=2/s,h[1]=0,h[2]=0,h[3]=(n+t)/s,h[4]=0,h[5]=2/a,h[6]=0,h[7]=-(i+e)/a,h[8]=0,h[9]=0,h[10]=-2/u,h[11]=-(o+r)/u,h[12]=0,h[13]=0,h[14]=0,h[15]=1,P.M(h)}},P.Viewports={center:function(t,n,e,i){var r,o;return null==t&&(t=500),null==n&&(n=500),null==e&&(e=0),null==i&&(i=0),o=P.M().translate(-e,-i,-n).scale(1/t,1/n,1/n),r=P.M().scale(t,-n,n).translate(e+t/2,i+n/2),{prescale:o,postscale:r}},origin:function(t,n,e,i){var r,o;return null==t&&(t=500),null==n&&(n=500),null==e&&(e=0),null==i&&(i=0),o=P.M().translate(-e,-i,-1).scale(1/t,1/n,1/n),r=P.M().scale(t,-n,n).translate(e,i),{prescale:o,postscale:r}}},P.Camera=function(t){function n(t){P.Util.defaults(this,t,this.defaults),n.__super__.constructor.apply(this,arguments)}return D(n,t),n.prototype.defaults={projection:P.Projections.perspective()},n}(P.Transformable),P.Scene=function(){function t(t){this.flushCache=z(this.flushCache,this),this.render=z(this.render,this),P.Util.defaults(this,t,this.defaults()),this._renderModelCache={}}return t.prototype.defaults=function(){return{model:new P.Model,camera:new P.Camera,viewport:P.Viewports.origin(1,1),shader:P.Shaders.phong(),cullBackfaces:!0,fractionalPoints:!1,cache:!0}},t.prototype.render=function(){var t,n;return t=this.camera.m.copy().multiply(this.viewport.prescale).multiply(this.camera.projection).multiply(this.viewport.postscale),n=[],this.model.eachRenderable(function(t,n){return new P.LightRenderModel(t,n)},function(e){return function(i,r,o){var s,a,u,h,l,c,p,f,d,y,m,g;for(f=i.surfaces,g=[],h=0,c=f.length;c>h;h++)if(u=f[h],a=e._renderSurface(u,o,t),!e.cullBackfaces||!u.cullBackfaces||a.projected.normal.z<0){if(a.fill=null!=(d=u.fill)?d.render(r,e.shader,a.transformed):void 0,a.stroke=null!=(y=u.stroke)?y.render(r,e.shader,a.transformed):void 0,e.fractionalPoints!==!0)for(m=a.projected.points,l=0,p=m.length;p>l;l++)s=m[l],s.round();g.push(n.push(a))}else g.push(void 0);return g}}(this)),n.sort(function(t,n){return n.projected.barycenter.z-t.projected.barycenter.z}),n},t.prototype._renderSurface=function(t,n,e){var i;return this.cache?(i=this._renderModelCache[t.id],null==i?i=this._renderModelCache[t.id]=new P.RenderModel(t,n,e):i.update(n,e),i):new P.RenderModel(t,n,e)},t.prototype.flushCache=function(){return this._renderModelCache={}},t}()}).call(this);