-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgladius-core.min.js
15 lines (12 loc) · 52.6 KB
/
gladius-core.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
Copyright (c) 2011-2012, Mozilla Foundation
Copyright (c) 2011-2012, Alan Kligman
Copyright (c) 2011-2012, Robert Richter
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the Mozilla Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/(function(a,b){typeof exports=="object"?module.exports=b():typeof define=="function"&&define.amd?define(b):a.Gladius||(a.Gladius=b())})(this,function(){var a,b,c;(function(d){function j(a,b){if(a&&a.charAt(0)==="."&&b){b=b.split("/"),b=b.slice(0,b.length-1),a=b.concat(a.split("/"));var c,d;for(c=0;d=a[c];c++)if(d===".")a.splice(c,1),c-=1;else if(d===".."){if(c===1&&(a[2]===".."||a[0]===".."))break;c>0&&(a.splice(c-1,2),c-=2)}a=a.join("/")}return a}function k(a,b){return function(){return i.apply(d,g.call(arguments,0).concat([a,b]))}}function l(a){return function(b){return j(b,a)}}function m(a){return function(b){e[a]=b}}function n(a){if(f.hasOwnProperty(a)){var b=f[a];delete f[a],h.apply(d,b)}return e[a]}function o(a,b){var c,d,e=a.indexOf("!");return e!==-1?(c=j(a.slice(0,e),b),a=a.slice(e+1),d=n(c),d&&d.normalize?a=d.normalize(a,l(b)):a=j(a,b)):a=j(a,b),{f:c?c+"!"+a:a,n:a,p:d}}var e={},f={},g=[].slice,h,i;if(typeof c=="function")return;h=function(a,b,c,g){var h=[],i,j,l,p,q,r;g||(g=a);if(typeof c=="function"){!b.length&&c.length&&(b=["require","exports","module"]);for(p=0;p<b.length;p++){r=o(b[p],g),l=r.f;if(l==="require")h[p]=k(a);else if(l==="exports")h[p]=e[a]={},i=!0;else if(l==="module")j=h[p]={id:a,uri:"",exports:e[a]};else if(e.hasOwnProperty(l)||f.hasOwnProperty(l))h[p]=n(l);else{if(!r.p)throw a+" missing "+l;r.p.load(r.n,k(g,!0),m(l),{}),h[p]=e[l]}}q=c.apply(e[a],h),a&&(j&&j.exports!==d?e[a]=j.exports:i||(e[a]=q))}else a&&(e[a]=c)},a=i=function(a,b,c,e){return typeof a=="string"?n(o(a,b).f):(a.splice||(b.splice?(a=b,b=arguments[2]):a=[]),e?h(d,a,b,c):setTimeout(function(){h(d,a,b,c)},15),i)},i.config=function(){return i},b||(b=i),c=function(a,b,d){b.splice||(d=b,b=[]),c.unordered?f[a]=[a,b,d]:h(a,b,d)},c.amd={jQuery:!0}})(),c("../tools/almond",function(){}),function(a,b){typeof exports=="object"?module.exports=b():typeof c=="function"&&c.amd?c("_math",[],b):a._Math||(a._Math=b())}(this,function(){var a,b,c;return function(d){function j(a,b){if(a&&a.charAt(0)==="."&&b){b=b.split("/"),b=b.slice(0,b.length-1),a=b.concat(a.split("/"));var c,d;for(c=0;d=a[c];c++)if(d===".")a.splice(c,1),c-=1;else if(d===".."){if(c===1&&(a[2]===".."||a[0]===".."))break;c>0&&(a.splice(c-1,2),c-=2)}a=a.join("/")}return a}function k(a,b){return function(){return i.apply(d,g.call(arguments,0).concat([a,b]))}}function l(a){return function(b){return j(b,a)}}function m(a){return function(b){e[a]=b}}function n(a){if(f.hasOwnProperty(a)){var b=f[a];delete f[a],h.apply(d,b)}return e[a]}function o(a,b){var c,d,e=a.indexOf("!");return e!==-1?(c=j(a.slice(0,e),b),a=a.slice(e+1),d=n(c),d&&d.normalize?a=d.normalize(a,l(b)):a=j(a,b)):a=j(a,b),{f:c?c+"!"+a:a,n:a,p:d}}var e={},f={},g=[].slice,h,i;if(typeof c=="function")return;h=function(a,b,c,g){var h=[],i,j,l,p,q,r;g||(g=a);if(typeof c=="function"){!b.length&&c.length&&(b=["require","exports","module"]);for(p=0;p<b.length;p++){r=o(b[p],g),l=r.f;if(l==="require")h[p]=k(a);else if(l==="exports")h[p]=e[a]={},i=!0;else if(l==="module")j=h[p]={id:a,uri:"",exports:e[a]};else if(e.hasOwnProperty(l)||f.hasOwnProperty(l))h[p]=n(l);else{if(!r.p)throw a+" missing "+l;r.p.load(r.n,k(g,!0),m(l),{}),h[p]=e[l]}}q=c.apply(e[a],h),a&&(j&&j.exports!==d?e[a]=j.exports:i||(e[a]=q))}else a&&(e[a]=c)},a=i=function(a,b,c,e){return typeof a=="string"?n(o(a,b).f):(a.splice||(b.splice?(a=b,b=arguments[2]):a=[]),e?h(d,a,b,c):setTimeout(function(){h(d,a,b,c)},15),i)},i.config=function(){return i},b||(b=i),c=function(a,b,d){b.splice||(d=b,b=[]),c.unordered?f[a]=[a,b,d]:h(a,b,d)},c.amd={jQuery:!0}}(),c("../tools/almond",function(){}),Array.prototype.remove||(Array.prototype.remove=function(a,b){var c=this.slice((b||a)+1||this.length);return this.length=a<0?this.length+a:a,this.push.apply(this,c)}),c("lang",["require"],function(a){return{bind:function(b,c){return function(){return c.apply(b,arguments)}},extend:function(b,c){for(var d in c)!b.hasOwnProperty(d)&&c.hasOwnProperty(d)&&(b[d]=c[d])}}}),c("constants",["require"],function(a){return function(){var a={TAU:2*Math.PI,PI:Math.PI,HALF_PI:Math.PI/2};return a}}),c("vector/vector",["require"],function(a){return function(a){var b=function(b,c){var d=null;1===c.length?d=c[0]:d=c;var e=new a(b);for(var f=0;f<b;++f)e[f]=d[f];return e},c={$:b,add:function(a,b,c){for(var d=0;d<a.length;++d)c[d]+=a[d]+b[d];return c},clear:function(a){for(var b=0;b<a.length;++b)a[b]=0},dot:function(a,b){var c=0;for(var d=0;d<a.length;++d)c+=a[d]*b[d];return c},equal:function(a,b,c){c=c||1e-6;if(a.length!=b.length)return!1;var d=a.length;for(var e=0;e<d;++e)if(Math.abs(a[e]-b[e])>c)return!1;return!0},length:function(a){var b=0;for(var c=0;c<a.length;++c)b+=a[c]*a[c];return Math.sqrt(b)},multiply:function(a,b,c){for(var d=0;d<a.length;++d)c[d]=a[d]*b;return c},negate:function(a,b){for(var c=0;c<a.length;++c)b[c]=a[c]*-1;return b},normalize:function(a,b){var d=a.length;for(var e=0,f=c.length(a);e<d;++e)b[e]=a[e]/f;return b},subtract:function(a,b,c){for(var d=0;d<a.length;++d)c[d]=a[d]-b[d];return c}};return Object.defineProperty(c,"x",{get:function(){return Vector2([1,0])},enumerable:!0}),Object.defineProperty(c,"u",{get:function(){return Vector2([1,0])},enumerable:!0}),Object.defineProperty(c,"y",{get:function(){return Vector2([0,1])},enumerable:!0}),Object.defineProperty(c,"v",{get:function(){return Vector2([0,1])},enumerable:!0}),Object.defineProperty(c,"zero",{get:function(){return Vector2([0,0])},enumerable:!0}),Object.defineProperty(c,"one",{get:function(){return Vector2([1,1])},enumerable:!0}),c}}),c("vector/vector2",["require","./vector","../constants"],function(a){return function(b){var c=a("./vector")(b),d=a("../constants")(),e=function(){return 0===arguments.length?c.$(2,[0,0]):c.$(2,arguments)},f={$:e,add:function(a,b,d){return d=d||e(),c.add(a,b,d)},angle:function(a,b){var d=e(),f=e();return c.normalize(a,d),c.normalize(b,f),Math.acos(c.dot(d,f))},clear:c.clear,dot:c.dot,equal:c.equal,length:c.length,multiply:function(a,b,d){return d=d||e(),c.multiply(a,b,d)},negate:function(a,b){return b=b||e(),c.negate(a,b)},normalize:function(a,b){b=b||e();var d=c.length(a);return b[0]=a[0]/d,b[1]=a[1]/d,b},project:function(a,b,c){c=c||e();var d=a[0]*b[0]+a[1]*b[1],f=d/(b[0]*b[0]+b[1]*b[1]);return c[0]=f*b[0],c[1]=f*b[1],c},set:function(a,b,c){a[0]=b,a[1]=c},subtract:function(a,b,d){return d=d||e(),c.subtract(a,b,d)}};return Object.defineProperty(f,"x",{get:function(){return e([1,0])},enumerable:!0}),Object.defineProperty(f,"u",{get:function(){return e([1,0])},enumerable:!0}),Object.defineProperty(f,"y",{get:function(){return e([0,1])},enumerable:!0}),Object.defineProperty(f,"v",{get:function(){return e([0,1])},enumerable:!0}),Object.defineProperty(f,"zero",{get:function(){return e([0,0])},enumerable:!0}),Object.defineProperty(f,"one",{get:function(){return e([1,1])},enumerable:!0}),f}}),c("vector/vector3",["require","./vector"],function(a){return function(b){var c=a("./vector")(b),d=function(){return 0===arguments.length?c.$(3,[0,0,0]):c.$(3,arguments)},e={$:d,add:function(a,b,e){return e=e||d(),c.add(a,b,e)},angle:function(a,b){return Math.acos((a[0]*b[0]+a[1]*b[1]+a[2]*b[2])/(Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])*Math.sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2])))},clear:c.clear,cross:function(a,b,c){return c=c||d(),c[0]=a[1]*b[2]-b[1]*a[2],c[1]=a[2]*b[0]-b[2]*a[0],c[2]=a[0]*b[1]-b[0]*a[1],c},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},equal:c.equal,length:c.length,multiply:function(a,b,e){return e=e||d(),c.multiply(a,b,e)},normal:function(a,b,c){return c=c||d(),d.cross(a,b,c)},normalize:function(a,b){b=b||d();var e=c.length(a);return b[0]=a[0]/e,b[1]=a[1]/e,b[2]=a[2]/e,b},set:function(a,b,c,d){a[0]=b,a[1]=c,a[2]=d},subtract:function(a,b,e){return e=e||d(),c.subtract(a,b,e)}};return Object.defineProperty(e,"x",{get:function(){return d([1,0,0])},enumerable:!0}),Object.defineProperty(e,"y",{get:function(){return d([0,1,0])},enumerable:!0}),Object.defineProperty(e,"z",{get:function(){return d([0,0,1])},enumerable:!0}),Object.defineProperty(e,"zero",{get:function(){return d([0,0,0])},enumerable:!0}),Object.defineProperty(e,"one",{get:function(){return d([1,1,1])},enumerable:!0}),e}}),c("vector/vector4",["require","./vector"],function(a){return function(b){var c=a("./vector")(b),d=function(){return 0===arguments.length?c.$(4,[0,0,0,0]):c.$(4,arguments)},e={$:d,add:function(a,b,c){return c=c||d(),c[0]=a[0]+b[0],c[1]=a[1]+b[1],c[2]=a[2]+b[2],c[3]=a[3]+b[3],c},angle:function(a,b){return Math.acos((a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3])/(Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3])*Math.sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2]+b[3]*b[3])))},clear:c.clear,dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},equal:c.equal,length:c.length,multiply:function(a,b,e){return e=e||d(),c.multiply(a,b,e)},normalize:function(a,b){b=b||d();var e=c.length(a);return b[0]=a[0]/e,b[1]=a[1]/e,b[2]=a[2]/e,b[3]=a[3]/e,b},set:function(a,b,c,d,e){a[0]=b,a[1]=c,a[2]=d,a[3]=e},subtract:function(a,b,e){return e=e||d(),c.subtract(a,b,e)}};return Object.defineProperty(e,"x",{get:function(){return d([1,0,0,0])},enumerable:!0}),Object.defineProperty(e,"y",{get:function(){return d([0,1,0,0])},enumerable:!0}),Object.defineProperty(e,"z",{get:function(){return d([0,0,1,0])},enumerable:!0}),Object.defineProperty(e,"w",{get:function(){return d([0,0,0,1])},enumerable:!0}),Object.defineProperty(e,"zero",{get:function(){return d([0,0,0,0])},enumerable:!0}),Object.defineProperty(e,"one",{get:function(){return d([1,1,1,1])},enumerable:!0}),e}}),c("vector/quaternion",["require","./vector4","./vector3"],function(a){return function(b){var c=a("./vector4")(b),d=a("./vector3")(b),e=c.$,f={$:e,to:{rpy:function(a,b){var c=b||d.$(),e=Math.atan2,f=Math.asin;c[0]=e(2*a[0]*a[1]+2*a[2]*a[3],1-2*a[1]*a[1]+2*a[2]*a[2]),c[1]=f(2*a[0]*a[2]-2*a[3]*a[1]),c[2]=e(2*a[0]*a[3]+2*a[1]*a[2],1-2*a[2]*a[2]+2*a[3]*a[3]);if(!b)return c}},from:{rpy:function(a,b){var c=b||f.$(),d=Math.sin,e=Math.cos,g=a[0]/2,h=a[1]/2,i=a[2]/2,j=d(g),k=e(g),l=d(h),m=e(h),n=d(i),o=e(i);c[0]=k*m*o+j*l*n,c[1]=j*m*o-k*l*n,c[2]=k*l*o+j*m*n,c[3]=k*m*n-j*l*o;if(!b)return c}},length:c.length,multiply:function(a,b,c){var d=c||f.$();d[0]=a[3]*b[0]+a[0]*b[3]+a[1]*b[2]-a[2]*b[1],d[1]=a[3]*b[1]-a[0]*b[2]+a[1]*b[3]+a[2]*b[0],d[2]=a[3]*b[2]+a[0]*b[1]-a[1]*b[0]+a[2]*b[3],d[3]=a[3]*b[3]-a[0]*b[0]-a[1]*b[1]-a[2]*b[2];if(!c)return d},normalize:c.normalize};return Object.defineProperty(f,"identity",{get:function(){return e([0,0,0,1])},enumerable:!0}),f}}),c("matrix/matrix",["require"],function(a){return function(a){var b=function(b,c){var d=null;1===c.length?d=c[0]:d=c;var e=new a(b);for(var f=0;f<b;++f)e[f]=d[f];return e},c={$:b,add:function(a,b,c){for(var d=0;d<a.length;++d)c[d]+=a[d]+b[d];return c},subtract:function(a,b,c){for(var d=0;d<a.length;++d)a[d]-=b[d];return a},clear:function(a){for(var b=0;b<a.length;++b)a[b]=0},equal:function(a,b,c){c=c||1e-6;if(a.length!=b.length)return!1;var d=a.length;for(var e=0;e<d;++e)if(Math.abs(a[e]-b[e])>c)return!1;return!0}};return c}}),c("matrix/matrix2",["require","./matrix"],function(a){return function(b){var c=a("./matrix")(b),d=function(){return 0===arguments.length?c.$(4,[0,0,0,0]):c.$(4,arguments)},e={$:d,add:function(a,b){b=b||d();var e=a[0];if(a.length==1)b=e;else for(var f=1;f<a.length;++f)b=c.add(e,a[f],b),e=b;return b},subtract:function(a,b){b=b||d();var e=a[0];if(a.length==1)b=e;else{var e=a[0];for(var f=1;f<a.length;++f)b=c.subtract(e,a[f],b),e=b}return b},clear:c.clear,equal:c.equal,determinant:function(a){return a[0]*a[3]-a[1]*a[2]},inverse:function(a,b){var c=e.determinant(a);if(c==0)throw"matrix is singular";return b=b||d(),b[0]=a[3]/c,b[1]=a[1]*-1/c,b[2]=a[2]*-1/c,b[3]=a[0]/c,b},multiply:function(a,b){b=b||d();if(a.length==1)return a[0];var c=a[0];for(var e=1;e<a.length;++e)b[0]=c[0]*a[e][0]+c[1]*a[e][2],b[1]=c[0]*a[e][1]+c[1]*a[e][3],b[2]=c[2]*a[e][0]+c[3]*a[e][2],b[3]=c[2]*a[e][1]+c[3]*a[e][3],c=b;return b},transpose:function(a,b){b=b||d();var c=a[1];return b[0]=a[0],b[1]=a[2],b[2]=c,b[3]=a[3],b}};return Object.defineProperty(e,"zero",{get:function(){return d([0,0,0,0])},enumerable:!0}),Object.defineProperty(e,"one",{get:function(){return d([1,1,1,1])},enumerable:!0}),Object.defineProperty(e,"identity",{get:function(){return d([1,0,0,1])},enumerable:!0}),e}}),c("matrix/matrix3",["require","./matrix"],function(a){return function(b){var c=a("./matrix")(b),d=function(){return 0===arguments.length?c.$(9,[0,0,0,0,0,0,0,0,0]):c.$(9,arguments)},e={$:d,add:function(a,b){b=b||d();if(a.length==1)return a[0];var e=a[0];for(var f=1;f<a.length;++f)b=c.add(e,a[f],b),e=b;return b},subtract:function(a,b){b=b||d();var e=a[0];if(a.length==1)b=e;else for(var f=1;f<a.length;++f)b=c.subtract(e,a[f],b),e=b;return b},clear:c.clear,equal:c.equal,determinant:function(a){return a[0]*(a[4]*a[8]-a[5]*a[7])-a[1]*(a[3]*a[8]-a[5]*a[6])+a[2]*(a[3]*a[7]-a[4]*a[6])},inverse:function(a,b){var c=e.determinant(a);if(c==0)throw"matrix is singular";return b=b||d(),b[0]=(a[8]*a[4]-a[7]*a[5])/c,b[1]=-(a[8]*a[1]-a[7]*[2])/c,b[2]=(a[5]*a[1]-a[4]*a[2])/c,b[3]=-(a[8]*a[3]-a[6]*a[5])/c,b[4]=(a[8]*a[0]-a[6]*a[2])/c,b[5]=-(a[5]*a[0]-a[3]*a[2])/c,b[6]=(a[7]*a[3]-a[6]*a[4])/c,b[7]=-(a[7]*a[0]-a[6]*a[1])/c,b[8]=(a[4]*a[0]-a[3]*a[1])/c,b},multiply:function(a,b){b=b||d();if(a.length==1)return a[0];var c=a[0];for(var e=1;e<a.length;++e)b[0]=c[0]*a[e][0]+c[1]*a[e][3]+c[2]*a[e][6],b[1]=c[0]*a[e][1]+c[1]*a[e][4]+c[2]*a[e][7],b[2]=c[0]*a[e][2]+c[1]*a[e][5]+c[2]*a[e][8],b[3]=c[3]*a[e][0]+c[4]*a[e][3]+c[5]*a[e][6],b[4]=c[3]*a[e][1]+c[4]*a[e][4]+c[5]*a[e][7],b[5]=c[3]*a[e][2]+c[4]*a[e][5]+c[5]*a[e][8],b[6]=c[6]*a[e][0]+c[7]*a[e][3]+c[8]*a[e][6],b[7]=c[6]*a[e][1]+c[7]*a[e][4]+c[8]*a[e][7],b[8]=c[6]*a[e][2]+c[7]*a[e][5]+c[8]*a[e][8],c=b;return b},rotate:function(a,b){var c=b||e.identity,d,f,g;0!==a[2]&&(d=Math.sin(a[2]),f=Math.cos(a[2]),g=[],g.push(e.$([f,d,0,-d,f,0,0,0,1])),g.push(e.$(c)),e.multiply(g,c)),0!==a[1]&&(d=Math.sin(a[1]),f=Math.cos(a[1]),g=[],g.push(e.$([f,0,-d,0,1,0,d,0,f])),g.push(e.$(c)),e.multiply(g,c)),0!==a[0]&&(d=Math.sin(a[0]),f=Math.cos(a[0]),g=[],g.push(e.$([1,0,0,0,f,d,0,-d,f])),g.push(e.$(c)),e.multiply(g,c));if(!b)return c},transpose:function(a,b){b=b||d();var c=a[1],e=a[2],f=a[5];return b[0]=a[0],b[1]=a[3],b[2]=a[6],b[3]=c,b[4]=a[4],b[5]=a[7],b[6]=e,b[7]=f,b[8]=a[8],b}};return Object.defineProperty(e,"zero",{get:function(){return d([0,0,0,0,0,0,0,0,0])},enumerable:!0}),Object.defineProperty(e,"one",{get:function(){return d([1,1,1,1,1,1,1,1,1])},enumerable:!0}),Object.defineProperty(e,"identity",{get:function(){return d([1,0,0,0,1,0,0,0,1])},enumerable:!0}),e}}),c("matrix/matrix4",["require","./matrix","../vector/vector3"],function(a){return function(b){var c=a("./matrix")(b),d=a("../vector/vector3")(b),e=function(){return 0===arguments.length?c.$(16,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]):c.$(16,arguments)},f={$:e,add:function(a,b){b=b||e();if(a.length==1)return a[0];var d=a[0];for(var f=1;f<a.length;++f)b=c.add(d,a[f],b),d=b;return b},subtract:function(a,b){b=b||e();var d=a[0];if(a.length==1)b=d;else for(var f=1;f<a.length;++f)b=c.subtract(d,a[f],b),d=b;return b},clear:c.clear,equal:c.equal,multiply:function(a,b){b=b||e();if(a.length==1)return a[0];var c=a[0];for(var d=1;d<a.length;++d)b[0]=c[0]*a[d][0]+c[1]*a[d][4]+c[2]*a[d][8]+c[3]*a[d][12],b[1]=c[0]*a[d][1]+c[1]*a[d][5]+c[2]*a[d][9]+c[3]*a[d][13],b[2]=c[0]*a[d][2]+c[1]*a[d][6]+c[2]*a[d][10]+c[3]*a[d][14],b[3]=c[0]*a[d][3]+c[1]*a[d][7]+c[2]*a[d][11]+c[3]*a[d][15],b[4]=c[4]*a[d][0]+c[5]*a[d][4]+c[6]*a[d][8]+c[7]*a[d][12],b[5]=c[4]*a[d][1]+c[5]*a[d][5]+c[6]*a[d][9]+c[7]*a[d][13],b[6]=c[4]*a[d][2]+c[5]*a[d][6]+c[6]*a[d][10]+c[7]*a[d][14],b[7]=c[4]*a[d][3]+c[5]*a[d][7]+c[6]*a[d][11]+c[7]*a[d][15],b[8]=c[8]*a[d][0]+c[9]*a[d][4]+c[10]*a[d][8]+c[11]*a[d][12],b[9]=c[8]*a[d][1]+c[9]*a[d][5]+c[10]*a[d][9]+c[11]*a[d][13],b[10]=c[8]*a[d][2]+c[9]*a[d][6]+c[10]*a[d][10]+c[11]*a[d][14],b[11]=c[8]*a[d][3]+c[9]*a[d][7]+c[10]*a[d][11]+c[11]*a[d][15],b[12]=c[12]*a[d][0]+c[13]*a[d][4]+c[14]*a[d][8]+c[15]*a[d][12],b[13]=c[12]*a[d][1]+c[13]*a[d][5]+c[14]*a[d][9]+c[15]*a[d][13],b[14]=c[12]*a[d][2]+c[13]*a[d][6]+c[14]*a[d][10]+c[15]*a[d][14],b[15]=c[12]*a[d][3]+c[13]*a[d][7]+c[14]*a[d][11]+c[15]*a[d][15],c=b;return b},multiplyVector3:function(a,b,c){return c=c||d.$(),c[0]=a[0]*b[0]+a[2]*b[1]+a[3]*b[2],c[1]=a[4]*b[0]+a[5]*b[1]+a[6]*b[2],c[2]=a[8]*b[0]+a[9]*b[1]+a[10]*b[2],c},determinant:function(a){var b=a[0]*a[5]-a[1]*a[4],c=a[0]*a[6]-a[2]*a[4],d=a[0]*a[7]-a[3]*a[4],e=a[1]*a[6]-a[2]*a[5],f=a[1]*a[7]-a[3]*a[5],g=a[2]*a[7]-a[3]*a[6],h=a[8]*a[13]-a[9]*a[12],i=a[8]*a[14]-a[10]*a[12],j=a[8]*a[15]-a[11]*a[12],k=a[9]*a[14]-a[10]*a[13],l=a[9]*a[15]-a[11]*a[13],m=a[10]*a[15]-a[11]*a[14],n=b*m-c*l+d*k+e*j-f*i+g*h;return n},transpose:function(a,b){return b=b||e(),b[0]=a[0],b[1]=a[4],b[2]=a[8],b[3]=a[12],b[4]=a[1],b[5]=a[5],b[6]=a[9],b[7]=a[13],b[8]=a[2],b[9]=a[6],b[10]=a[10],b[11]=a[14],b[12]=a[3],b[13]=a[7],b[14]=a[11],b[15]=a[15],b},inverse:function(a,b){b=b||e();var c=a[0],d=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=a[9],n=a[10],o=a[11],p=a[12],q=a[13],r=a[14],s=a[15],t=c*i-d*h,u=c*j-f*h,v=c*k-g*h,w=d*j-f*i,x=d*k-g*i,y=f*k-g*j,z=l*q-m*p,A=l*r-n*p,B=l*s-o*p,C=m*r-n*q,D=m*s-o*q,E=n*s-o*r,F=t*E-u*D+v*C+w*B-x*A+y*z,G;if(!F)throw"matrix is singular";return G=1/F,b[0]=(i*E-j*D+k*C)*G,b[1]=(-d*E+f*D-g*C)*G,b[2]=(q*y-r*x+s*w)*G,b[3]=(-m*y+n*x-o*w)*G,b[4]=(-h*E+j*B-k*A)*G,b[5]=(c*E-f*B+g*A)*G,b[6]=(-p*y+r*v-s*u)*G,b[7]=(l*y-n*v+o*u)*G,b[8]=(h*D-i*B+k*z)*G,b[9]=(-c*D+d*B-g*z)*G,b[10]=(p*x-q*v+s*t)*G,b[11]=(-l*x+m*v-o*t)*G,b[12]=(-h*C+i*A-j*z)*G,b[13]=(c*C-d*A+f*z)*G,b[14]=(-p*w+q*u-r*t)*G,b[15]=(l*w-m*u+n*t)*G,b},toHTML:function(a){var b="[ ";for(var c=0;c<4;++c){b+="<br>";for(var d=0;d<4;++d)b+=" ("+a[4*c+d]+") "}return b+=" ]",b}};return Object.defineProperty(f,"zero",{get:function(){return e([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])},enumerable:!0}),Object.defineProperty(f,"one",{get:function(){return e([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])},enumerable:!0}),Object.defineProperty(f,"identity",{get:function(){return e([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])},enumerable:!0}),f}}),c("matrix/transform",["require","./matrix4"],function(a){return function(b){var c=a("./matrix4")(b),d=c.$,e={$:d,fixed:function(a,b,d){var f=c.identity;return a&&e.translate(a,f),b&&e.rotate(b,f),d&&e.scale(d,f),f},rotate:function(a,b){var d=b||c.identity,e,f,g;0!==a[2]&&(e=Math.sin(a[2]),f=Math.cos(a[2]),g=[],g.push(c.$([f,e,0,0,-e,f,0,0,0,0,1,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d)),0!==a[1]&&(e=Math.sin(a[1]),f=Math.cos(a[1]),g=[],g.push(c.$([f,0,-e,0,0,1,0,0,e,0,f,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d)),0!==a[0]&&(e=Math.sin(a[0]),f=Math.cos(a[0]),g=[],g.push(c.$([1,0,0,0,0,f,e,0,0,-e,f,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d));if(!b)return d},scale:function(a,b){var d=[a[0],0,0,0,0,a[1],0,0,0,0,a[2],0,0,0,0,1];if(!b)return d;c.multiply([d,c.$(b)],b)},translate:function(a,b){var d=[1,0,0,0,0,1,0,0,0,0,1,0,a[0],a[1],a[2],1];if(!b)return d;c.multiply([d,c.$(b)],b)}};return e}}),c("_math",["require","./lang","./constants","./vector/vector2","./vector/vector3","./vector/vector4","./vector/quaternion","./matrix/matrix2","./matrix/matrix3","./matrix/matrix4","./matrix/transform"],function(a){var b=a("./lang"),c=a("./constants"),d=a("./vector/vector2"),e=a("./vector/vector3"),f=a("./vector/vector4"),g=a("./vector/quaternion"),h=a("./matrix/matrix2"),i=a("./matrix/matrix3"),j=a("./matrix/matrix4"),k=a("./matrix/transform"),l=function(a){var l={Float32:Float32Array,Float64:Float64Array},m=l.Float32;Object.defineProperty(this,"ARRAY_TYPE",{get:function(){return m},enumerable:!0}),b.extend(this,c());var n=d(m),o=e(m),p=f(m),q=g(m),r=h(m),s=i(m),t=j(m),u=k(m);Object.defineProperty(this,"Vector2",{get:function(){return n.$},enumerable:!0}),Object.defineProperty(this,"vector2",{get:function(){return n},enumerable:!0}),Object.defineProperty(this,"Vector3",{get:function(){return o.$},enumerable:!0}),Object.defineProperty(this,"vector3",{get:function(){return o},enumerable:!0}),Object.defineProperty(this,"Vector4",{get:function(){return p.$},enumerable:!0}),Object.defineProperty(this,"vector4",{get:function(){return p},enumerable:!0}),Object.defineProperty(this,"Quaternion",{get:function(){return q.$},enumerable:!0}),Object.defineProperty(this,"quaternion",{get:function(){return q},enumerable:!0}),Object.defineProperty(this,"Matrix2",{get:function(){return r.$},enumerable:!0}),Object.defineProperty(this,"matrix2",{get:function(){return r},enumerable:!0}),Object.defineProperty(this,"Matrix3",{get:function(){return s.$},enumerable:!0}),Object.defineProperty(this,"matrix3",{get:function(){return s},enumerable:!0}),Object.defineProperty(this,"Matrix4",{get:function(){return t.$},enumerable:!0}),Object.defineProperty(this,"matrix4",{get:function(){return t},enumerable:!0}),Object.defineProperty(this,"Transform",{get:function(){return u.$},enumerable:!0}),Object.defineProperty(this,"transform",{get:function(){return u},enumerable:!0})};return new l}),b("_math")});if(typeof c!="function")var c=b("amdefine")(module);c("common/guid",["require"],function(a){function b(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=Math.random()*16|0,c=a=="x"?b:b&3|8;return c.toString(16)}).toUpperCase()}return b});if(typeof c!="function")var c=b("amdefine")(module);c("common/multicast-delegate",["require","common/guid"],function(a){function c(a){a.hasOwnProperty("_id")||(a._id=b()),this._callbacks.hasOwnProperty(a._id)||(this._callbacks[a._id]=a,++this.size)}function d(a){a.hasOwnProperty("_id")&&this._callbacks.hasOwnProperty(a._id)&&(delete this._callbacks[a._id],--this.size)}var b=a("common/guid"),e=function(){function b(b){var c,d,e=0,f=Object.keys(a);for(c=0,d=f.length;c<d;++c){var g=f[c],h=a[g];h(b),++e}return e}var a={};return b._callbacks=a,b.subscribe=c,b.unsubscribe=d,b.size=0,b};return e});if(typeof c!="function")var c=b("amdefine")(module);c("core/loop",["require"],function(a){function c(){this._runState=this.R_RUNNING,this.callback&&(this.callback.call(this.context),this.L_STARTED===this._loopState?this._pump():this.suspend()),this._runState=this.R_IDLE}function d(){throw new Error("not implemented for base prototype")}function e(){this._loopState=this.L_PAUSED}function f(){if(!this.callback)throw new Error("callback not defined");this._loopState=this.L_STARTED,this._runState===this.R_IDLE&&this._pump()}function g(){return this._loopState===this.L_STARTED}var b=function(a,b){this.L_STARTED=0,this.L_PAUSED=1,this.L_CANCELLED=2,this.L_FINISHED=3,this.R_RUNNING=0,this.R_IDLE=1,this._loopState=this.L_PAUSED,this._runState=this.R_IDLE,this.callback=a,this.context=b||this};return b.prototype={suspend:e,resume:f,_pump:d,_run:c,isStarted:g},b});if(typeof c!="function")var c=b("amdefine")(module);c("core/request-animation-frame-loop",["require","core/loop"],function(a){function d(){requestAnimationFrame(this._run.bind(this))}window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a,b){window.setTimeout(a,1e3/60)});var b=a("core/loop"),c=function(a,c){b.call(this,a,c)};return c.prototype=new b,c.prototype._pump=d,c.prototype.constructor=c,c});if(typeof c!="function")var c=b("amdefine")(module);c("core/clock",["require","common/multicast-delegate"],function(a){function f(){this._clockState=d}function g(){this._clockState=c}function h(a){d!==this._clockState?this.delta=a*this._timeScale:(this.delta=this._stepCount*this._idealFrameInterval*this._timeScale,this._stepCount=0),this.time+=this.delta,this.signal(this.delta)}function i(a){d===this._clockState&&(this._stepCount+=undefined===a?1:a)}function j(){return this._clockState===c}function k(a){a&&a!=this._delegate&&(this._delegate.unsubscribe(this._delegateHandler),this._delegate=a||null,this._delegate.subscribe(this._delegateHandler)),this.time=0,this.delta=0}function l(a){this._timeScale=a}function m(a){this._idealFrameInterval=a}var b=a("common/multicast-delegate"),c=0,d=1,e=function(a){this.time=0,this.delta=0,this._timeScale=1,this._idealFrameInterval=1/30,this._clockState=undefined,this.signal=new b,this._delegate=a||null,this._delegateHandler=this.update.bind(this),this._delegate&&this._delegate.subscribe(this._delegateHandler),this._stepCount=0,this.start()};return e.prototype={pause:f,start:g,update:h,isStarted:j,step:i,reset:k,setTimeScale:l,setIdealFrameInterval:m},e});if(typeof c!="function")var c=b("amdefine")(module);c("common/graph",["require"],function(a){function c(a,b){return this._nodes[a]||(this._nodes[a]=!0,this._descendants[a]=0),this._nodes[b]||(this._nodes[b]=!0,this._descendants[b]=0,this._roots[b]=!0),this._adjacencies[b]||(this._adjacencies[b]={}),this._adjacencies[b][a]=!0,++this._descendants[a],this._roots[a]&&delete this._roots[a],this._cachedSort=null,this}function d(a,b){if(!this._adjacencies[b]||!this._adjacencies[b][a])throw new Error("no such link: ",a,"->",b);return delete this._adjacencies[b][a],--this._descendants[a],Object.keys(this._adjacencies[b]).length||delete this._adjacencies[b],this._descendants[a]||(this._roots[a]=!0),this._cachedSort=null,this}function e(a){return this._nodes[a]||(this._nodes[a]=!0,this._descendants[a]=0,this._roots[a]=!0,++this._cachedSize,this._cachedSort=null),this}function f(a){var b=this._adjacencies[a]||{};if(!this._nodes[a])throw new Error("no such node: ",a);for(var c in b)this.unlink(c,a);return delete this._nodes[a],delete this._descendants[a],--this._cachedSize,this._cachedSort=null,this}function g(){return this._cachedSize}function h(){return this._nodes={},this._adjacencies={},this._descendants={},this._roots={},this._cachedSort=null,this._cachedSize=0,this}function i(){function e(c,f){if(-1!==f.indexOf(c))throw new Error("directed cycle detected");f.push(c);if(-1===d.indexOf(c)){d.push(c);var g=a._adjacencies[c];for(var h in g)a._nodes[h]?e(h,f):delete g[h];b.push(c)}f.pop()}var a=this,b=[],c=Object.keys(this._roots),d=[];if(null===this._cachedSort){for(var f=0,g=c.length;f<g;++f)e(c[f],[]);if(b.length<Object.keys(this._nodes).length)throw new Error("directed cycle detected");this._cachedSort=b}return this._cachedSort.slice()}function j(a){return this._nodes.hasOwnProperty(a)}function k(a,b){return this.hasNode(a)?this._adjacencies.hasOwnProperty(b)&&this._adjacencies[b].hasOwnProperty(a):(this.unlink(a,b),!1)}var b=function(){this._nodes={},this._adjacencies={},this._descendants={},this._roots={},this._cachedSort=null,this._cachedSize=0};return b.prototype={link:c,unlink:d,insert:e,remove:f,size:g,clear:h,sort:i,hasNode:j,hasLink:k},b});if(typeof c!="function")var c=b("amdefine")(module);c("core/dependency-scheduler",["require","common/graph"],function(a){function e(){var a,b,c=this._graph.sort();this._schedule=[];for(a=0,b=c.length;a<b;++a)this._tasks.hasOwnProperty(c[a])&&this._schedule.push(c[a]);return this}function f(){if(!this._schedule)return undefined;var a=this._schedule.shift();return this._tasks[a]}function g(){return this._schedule&&this._schedule.length>0}function h(a,b,c){var d,e;this._tasks[b]=a,this._graph.insert(b);if(c){if(c.tags){var f=c.tags;for(d=0,e=c.tags.length;d<e;++d){var g=f[d];g[0]==="@"?this._graph.link(a.id,g):this._graph.link(g,a.id)}}if(c.dependsOn){var h=c.dependsOn;for(d=0,e=h.length;d<e;++d)this._graph.link(a.id,h[d])}}return this}function i(a){if(!this._graph.hasNode(a))throw new Error("task is not scheduled to run");return this._graph.remove(a),delete this._tasks[a],this}function j(){return this._graph.size()}function k(){this._schedule=null,this._graph.clear();var a;for(a=0;a<this._phases.length;++a)this._graph.insert(this._phases[a]),a>0&&this._graph.link(this._phases[a-1],this._phases[a])}var b=a("common/graph"),c=["@input","@update","@render"],d=function(a){this.current=null,this._tasks={},this._graph=new b,this._schedule=null,this._phases=a||c,this.clear()};return d.prototype={next:f,insert:h,remove:i,size:j,hasNext:g,update:e,clear:k},d}),function(a){a("when",[],function(){function d(){}function e(a){return new Array(a)}function f(){}function g(b){var d=new f;return d.then=function(a){i(arguments);var d;try{return a&&(d=a(b)),m(d===c?b:d)}catch(e){return h(e)}},a(d)}function h(b){var d=new f;return d.then=function(a,d){i(arguments);var e;try{return d?(e=d(b),m(e===c?b:e)):h(b)}catch(f){return h(f)}},a(d)}function i(a){var b,c=a.length;while(c){b=a[--c];if(b!=null&&typeof b!="function")throw new Error("callback is not a function")}}function j(){function o(a,b,c){return l(a,b,c)}function p(a){n(g(a))}function q(a){n(h(a))}function r(a){m(a)}var b,d,e,k,l,m,n;return e=[],k=[],l=function(b,c,d){i(arguments);var f=j();return e.push(function(a){a.then(b,c).then(f.resolve,f.reject,f.progress)}),d&&k.push(d),f.promise},m=function(a){var b,c=0;while(b=k[c++])b(a)},n=function(a){var b,d=0;l=a.then,n=m=function(){throw new Error("already completed")},k=c;while(b=e[d++])b(a);e=[]},b={},d=new f,d.then=b.then=o,b.promise=a(d),b.resolver=a({resolve:b.resolve=p,reject:b.reject=q,progress:b.progress=r}),b}function k(a){return a&&typeof a.then=="function"}function l(a,b,c,d){var e=m(a);return e.then(b,c,d)}function m(a){var b,c;return a instanceof f?b=a:(c=j(),k(a)?(a.then(c.resolve,c.reject,c.progress),b=c.promise):(c.resolve(a),b=c.promise)),b}function n(a,b,c,e,f){function r(a){m(a)}function s(a){n(a)}function t(a){o(a)}function u(){m=n=o=d}var g,h,i,k,m,n,o,p,q;p=a.length>>>0,g=Math.max(0,Math.min(b,p)),h=[],k=j(),i=l(k,c,e,f);if(!g)k.resolve(h);else{m=function(a){h.push(a),--g||(u(),k.resolve(h))},n=function(a){u(),k.reject(a)},o=k.progress;for(q=0;q<p;++q)q in a&&l(a[q],r,s,t)}return i}function o(a,b,c,d){var f,g;return f=e(a.length),g=s(a,p,f),l(g,b,c,d)}function p(a,b,c){return a[c]=b,a}function q(a,b,c,d){function e(a){return b(a[0])}return n(a,1,e,c,d)}function r(a,b){var c,d;d=a.length,c=e(d);for(;d>=0;--d)d in a&&(c[d]=l(a[d],b));return s(c,p,c)}function s(a,c,d){var e,f;return e=a.length,f=[function(a,b,d){return l(a,function(a){return l(b,function(b){return c(a,b,d,e)})})}],arguments.length>=3&&f.push(d),m(b.apply(a,f))}function t(a,b,c){var d=arguments.length>2;return l(a,function(a){return d&&(a=c),b.resolve(a),a},function(a){return b.reject(a),h(a)},b.progress)}var a,b,c;return a=Object.freeze||function(a){return a},b=[].reduce||function(a){var b,c,d,e,f;f=0,b=Object(this),e=b.length>>>0,c=arguments;if(c.length<=1)for(;;){if(f in b){d=b[f++];break}if(++f>=e)throw new TypeError}else d=c[1];for(;f<e;++f)f in b&&(d=a(d,b[f],f,b));return d},l.defer=j,l.isPromise=k,l.some=n,l.all=o,l.any=q,l.reduce=s,l.map=r,l.chain=t,l})}(typeof c=="function"?c:function(a){typeof module!="undefined"?module.exports=a():this.when=a()});if(typeof c!="function")var c=b("amdefine")(module);c("core/function-task",["require","common/guid","when"],function(a){function o(a){this._schedule=a||this._schedule;if(this._taskState!==g)throw new Error("task is already started or completed");return this._taskState=f,this._runState!==k&&this._scheduler.insert(this,this.id,this._schedule),this}function p(){if(this._runState===j)throw new Error("task can only be paused while blocked"
);return this._taskState=g,this._scheduler.remove(this.id),this}function q(){if(this._runState===j)throw new Error("tasks can only be cancelled while blocked");return this._taskState=h,this._scheduler.insert(this,this.id),this}function r(){return this._taskState===f}function s(){return this._runState===j}function t(){return this._taskState===i}function u(){var a=this,b=a.result;a.result=undefined,a._scheduler.current=a;try{a._runState=j;if(a._taskState===h)a._runState=l,a._taskState=i;else{if(a._taskState!==f)throw Error("task is not runnable");b=a._thunk.call(this._context,b),a._runState=k,b instanceof d?(a.result=b.value,a._taskState=i,a._runState=l,a._deferred.resolve(a.result)):a.result=c(b,function(b){a.result=b,a._runState=l,a._taskState===f&&a._scheduler.insert(a,a.id,a._schedule)},function(b){a.result=b,a._runState=m,a._threadState===f&&a._scheduler.insert(a,a.id,a._schedule)})}}catch(e){a.result=e,a._runState=m,a._deferred.reject(e)}return a._scheduler.current=null,this}function v(){return"[object FunctionTask "+this.id+"]"}var b=a("common/guid"),c=a("when"),d=function(a){if(!(this instanceof d))return new d(a);this.value=a},e=function(){if(!(this instanceof e))return new e;this.tags=[],this.dependsOn=[]},f=0,g=1,h=2,i=3,j=0,k=1,l=2,m=3,n=function(a,d,f,h){this.id=b(),this._thunk=d,this._taskState=g,this._runState=l,this._scheduler=a,this._schedule=f||e(),this.result=undefined,this._deferred=c.defer(),this.then=this._deferred.promise.then,this._context=h||this};return n.prototype={pause:p,start:o,cancel:q,isStarted:r,isRunning:s,isComplete:t,toString:v,run:u,when:c,Complete:d},n});if(typeof c!="function")var c=b("amdefine")(module);c("core/timer",["require"],function(a){function e(a){c!==this._timerState&&(this.elapsed+=a,this.elapsed>=this._delay&&(this._callback(this._data),this.pause()))}function f(){this._timerState=b,this._delegate.subscribe(this.update)}function g(){this._timerState=c,this._delegate.unsubscribe(this.update)}function h(){return this._timerState===b}function i(){this.elapsed=0,this.start()}var b=0,c=1,d=function(a,b,c,d){this._delegate=a,this._callback=c,this._data=d,this._delay=b,this.elapsed=0,this._timerState=undefined,this.start()};return d.prototype={start:f,pause:g,update:e,isStarted:h,reset:i},d});if(typeof c!="function")var c=b("amdefine")(module);c("core/event",["require"],function(a){function b(){var a=Array.prototype.slice.call(arguments,0),b,c;a.length>0&&Array.isArray(a[0])&&(a=a[0]);for(b=0,c=a.length;b<c;++b)try{var d=a[b];d.handleEvent&&d.handleEvent.call(d,this)}catch(e){console.log(e)}}var c=function(a,c,d){if(undefined===a||a.length<1)throw new Error("event must have a non-trivial type");this.type=a,this.data=c,undefined===d&&(d=!0),this.queue=d,this.dispatch=b.bind(this)};return c});if(typeof c!="function")var c=b("amdefine")(module);c("common/decode-data-uri",["require"],function(a){function b(a){var b=a.match(":.*,")[0].slice(1,-1).split(";"),c=b[0],d=b[1],e=b[2],f=decodeURIComponent(a.match(",.*")[0].slice(1));switch(c){case"":case"text/plain":return f;default:throw"unknown content type: "+c}}return b});if(typeof c!="function")var c=b("amdefine")(module);c("common/decode-javascript-uri",["require"],function(a){function b(a){var b=a.match("^javascript://.*")[0].slice("javascript://".length);return decodeURIComponent(b)}return b}),c("core/loaders/default",["require","common/decode-data-uri","common/decode-javascript-uri"],function(a){var b=a("common/decode-data-uri"),c=a("common/decode-javascript-uri");return function(a,d,e){if(a.match("^data:"))d(b(a));else if(a.match("^javascript:"))d(c(a));else{var f=new XMLHttpRequest;f.open("GET",a,!0),f.onreadystatechange=function(){if(4!=f.readyState)return;if(f.status<200||f.status>299){e(f.statusText);return}d(f.responseText)},f.send(null)}}}),c("core/get",["require","core/loaders/default"],function(a){var b=a("core/loaders/default"),c=function(c,d){d=d||{},d.oncomplete=d.oncomplete||function(){};if(!c.length){d.oncomplete();return}var e=0,f=function(){++e,e===c.length&&d.oncomplete()},g=function(a,b){a(b.url,function(c){if(undefined===c)b.onfailure("load returned with not data");else{var d=new b.type(c);b.onsuccess(d)}f()},function(c){b.onfailure("load failed: "+c),f()})};for(var h=0;h<c.length;h++){var i=c[h],j=i.load||b;g(j,i)}return};return c});if(typeof c!="function")var c=b("amdefine")(module);c("common/get-url-params",["require"],function(a){function b(a){var b=a.split("?"),c={};if(b[1]){var d=b[1].split("&");for(var e=0;e<d.length;++e){var f=d[e].split("="),g=decodeURIComponent(f[0]),h=decodeURIComponent(f[1]);c[g]=h}}return c}return b});if(typeof c!="function")var c=b("amdefine")(module);c("base/component",["require","core/event"],function(a){function d(a){if(a!==this.owner){var c=this.owner;this.owner=a;var d=new b("ComponentOwnerChanged",{current:a,previous:c},!1);d.dispatch(this)}}function e(a){if("on"+a.type in this)if(a.queue)this._queuedEvents.push(a);else{var b=this["on"+a.type];try{b.call(this,a)}catch(c){console.log(c)}}}function f(){if(this._queuedEvents.length>0){var a=this._queuedEvents.shift();if("on"+a.type in this){var b=this["on"+a.type];try{b.call(this,a)}catch(c){console.log(c)}}}return this._queuedEvents.length}var b=a("core/event"),c=function(a,b,c){this.type=a,this.provider=b,this.dependsOn=c||[],this.owner=null,this._queuedEvents=[]};return c.prototype={setOwner:d,handleEvent:e,handleQueuedEvent:f},c});if(typeof c!="function")var c=b("amdefine")(module);c("base/service",["require","core/function-task"],function(a){function d(a,b){return this._registeredComponents.hasOwnProperty(b.type)||(this._registeredComponents[b.type]={}),this._registeredComponents[b.type][a]=b,this}function e(a,b){return this._registeredComponents.hasOwnProperty(b.type)&&this._registeredComponents[b.type].hasOwnProperty(a)&&delete this._registeredComponents[b.type][a],this}function f(){var a,b,c=Object.keys(this._tasks);for(a=0,b=c.length;a<b;++a){var d=c[a];this._tasks[d].pause()}return this}function g(){var a,b,c=Object.keys(this._tasks);for(a=0,b=c.length;a<b;++a){var d=c[a],e=this._schedules[d]||{};this._tasks[d].start(e)}return this}function h(a){var b,c;if("on"+a.type in this){var d=this["on"+a.type];try{d.call(this,a)}catch(e){console.log(e)}}}var b=a("core/function-task"),c=function(a,c,d){this._schedules=c||{},this.dependsOn=d||[],this._tasks={},this._registeredComponents={};if(a){var e,f,g=Object.keys(this._schedules);for(e=0,f=g.length;e<f;++e){var h=g[e];if(!this[h])throw new Error("missing scheduler target: "+h);var i=this._schedules[h]||{};this._tasks[h]=new b(a,this[h],i,this),this._tasks[h].start()}}};return c.prototype={registerComponent:d,unregisterComponent:e,suspend:f,resume:g,handleEvent:h},c});if(typeof c!="function")var c=b("amdefine")(module);c("base/extension",["require"],function(a){var b=function(a,b){if(typeof a!="string"||a.length===0)throw new Error("extension needs a non-trivial name");this.name=a,b=b||{};var c,d,e,f,g,h,i,j,k,l,m,n,o;this.services={};if(b.hasOwnProperty("services")){c=Object.keys(b.services);for(l=0,m=c.length;l<m;++l){d=c[l],e=b.services[d];if(typeof e=="function")this.services[d]=e;else{if(typeof e!="object")throw new Error("malformed extension");this.services[d]={},this.services[d].service=e.service;if(e.hasOwnProperty("components")){this.services[d].components={},f=Object.keys(e.components);for(n=0,o=f.length;n<o;++n)g=f[n],this.services[d].components[g]=e.components[g]}if(e.hasOwnProperty("resources")){this.services[d].resources={},i=Object.keys(e.resources);for(n=0,o=i.length;n<o;++n)j=i[n],this.services[d].resources[j]=e.resources[j]}}}}this.components={},b.hasOwnProperty("components")&&(this.components=b.components),this.resources={},b.hasOwnProperty("resources")&&(this.resources=b.resources)};return b});if(typeof c!="function")var c=b("amdefine")(module);c("core/entity",["require","common/guid","core/event"],function(a){function e(a,b){if(b||this.validateDependencies.call(this,a)){var d=this.removeComponent(a.type);a.setOwner(this),this._components[a.type]=a,++this.size;var e=new c("EntityComponentAdded",a);return e.dispatch(this),d}throw new Error("required component missing")}function f(a){var b=null;if(this.hasComponent(a)){b=this._components[a],delete this._components[a],b.setOwner(null),--this.size;var d=new c("EntityComponentRemoved",b);d.dispatch(this);var e=[],f=Object.keys(this._components);for(var g=0;g<f.length;g++)e.push(this._components[f[g]]);if(!this.validateDependencies.call({_components:[]},e))throw new Error("required component removed from entity- component dependency missing")}return b}function g(a){var b;if(a!==this.parent){this.parent&&(b=new c("ChildEntityRemoved",this),b.dispatch(this.parent));var d=this.parent;this.parent=a,b=new c("EntityParentChanged",{previous:d,current:a}),b.dispatch(this),this.parent&&(b=new c("ChildEntityAdded",this),b.dispatch(this.parent))}}function h(a){if(a!==this.space){var b=this.space;this.space=a,!this.space&&this.active&&i.call(this,!1);var d=new c("EntitySpaceChanged",{previous:b,current:a});d.dispatch(this)}}function i(a){var b;if(this.space)a?(this.active=!0,b=new c("EntityActivationChanged",!0)):(this.active=!1,b=new c("EntityActivationChanged",!1));else{if(a)throw new Error("Cannot set active to true on an entity that isn't in a space");this.active=!1,b=new c("EntityActivationChanged",!1)}return b.dispatch(this),this}function j(a){return this._components.hasOwnProperty(a)?this._components[a]:null}function k(a){var b,c,d=Object.keys(this._components);if(Array.isArray(a)){if(a.length===0)return!0;for(b=0,c=a.length;b<c;++b)if(d.indexOf(a[b])<0)return!1}else{if(!a)return!0;if(d.indexOf(a)<0)return!1}return!0}function l(a){var b=Object.keys(this._components);Array.isArray(a)?a.forEach(function(a){b.push(a.type)}):(b.push(a.type),a=[a]);var c;for(var d=0;d<a.length;d++){c=a[d];for(var e=0;e<c.dependsOn.length;e++)if(b.indexOf(c.dependsOn[e])<0)return!1}return!0}function m(a){var b=Object.keys(this._components),c,d;if(this["on"+a.type]){var e=this["on"+a.type];try{e.call(this,a)}catch(f){console.log(f)}}for(c=0,d=b.length;c<d;++c){var g=b[c],h=this._components[g];h.handleEvent&&h.handleEvent.call(h,a)}}function n(a){var b=a.data;this._children[b.id]=b}function o(a){var b=a.data;delete this._children[b.id]}var b=a("common/guid"),c=a("core/event"),d=function(a,c,d,e){this.id=b(),this.name=a||"",this.active=!1,this.parent=null,this._children={},this.space=null,this.size=0,this._components={},this.tags=d||[];if(c&&c.length>0){if(!this.validateDependencies.call(this,c))throw new Error("required component missing");var f,g;for(f=0,g=c.length;f<g;++f)this.addComponent.call(this,c[f],!0)}e&&this.setParent(e)};return d.prototype={setParent:g,setSpace:h,setActive:i,findComponent:j,hasComponent:k,addComponent:e,removeComponent:f,validateDependencies:l,handleEvent:m,onChildEntityAdded:n,onChildEntityRemoved:o},d});if(typeof c!="function")var c=b("amdefine")(module);c("core/space",["require","common/guid","core/entity","core/clock"],function(a){function b(a){this.clock=new e(a.signal),this.id=c(),this.size=0,this._entities={},this._nameIndex={},this._tagIndex={}}function f(a){var b,c;this._entities[a.id]=a,a.space=this,++this.size,a.name&&(this._nameIndex.hasOwnProperty(a.name)||(this._nameIndex[a.name]=[]),this._nameIndex[a.name].push(a.id));if(a.tags)for(b=0,c=a.tags.length;b<c;++b){var d=a.tags[b];this._tagIndex.hasOwnProperty(d)||(this._tagIndex[d]=[]),this._tagIndex[d].push(a.id)}if(a._children)for(var e in a._children)this.add.call(this,a._children[e]);return this}function g(a){var b,c;if(!this._entities.hasOwnProperty(a.id))throw new Error("attempted to remove unavailable entity "+a.toString());delete this._entities[a.id],a.space=null,--this.size,a.name&&this._nameIndex.hasOwnProperty(a.name)&&delete this._nameIndex[a.name];if(a.tags)for(b=0,c=a.tags.length;b<c;++b){var d=a.tags[b];delete this._tagIndex[a.id]}if(a._children)for(var e in a._children)this.remove.call(this,a._children[e]);return this}function h(a){if(this._nameIndex.hasOwnProperty(a)){var b=this._nameIndex[a][0];return this._entities[b]}return null}function i(a){var b,c;if(this._nameIndex.hasOwnProperty(a)){var d=this._nameIndex[a],e=[];for(b=0,c=d.length;b<c;++b){var f=d[b];e.push(this._entities[f])}return e}return[]}function j(a){if(this._tagIndex.hasOwnProperty(a)){var b=this._tagIndex[a][0];return this._entities[b]}return null}function k(a){var b,c;if(this._tagIndex.hasOwnProperty(a)){var d=this._tagIndex[a],e=[];for(b=0,c=d.length;b<c;++b){var f=d[b];e.push(this._entities[f])}return e}return[]}function l(a){var b,c,d=Object.keys(this._entities);for(b=0,c=d.length;b<c;++b){var e=d[b],f=this._entities[e];if(f.hasComponent(a))return f}return null}function m(a){var b,c,d=[],e=Object.keys(this._entities);for(b=0,c=e.length;b<c;++b){var f=e[b],g=this._entities[f];g.hasComponent(a)&&d.push(g)}return d}var c=a("common/guid"),d=a("core/entity"),e=a("core/clock");return b.prototype={add:f,remove:g,findNamed:h,findAllNamed:i,findTagged:j,findAllTagged:k,findWith:l,findAllWith:m},b});if(typeof c!="function")var c=b("amdefine")(module);c("common/extend",["require"],function(a){function b(a,b){for(var c in b)!a.hasOwnProperty(c)&&b.hasOwnProperty(c)&&(a[c]=b[c]);return a}return b});if(typeof c!="function")var c=b("amdefine")(module);c("core/components/transform",["require","_math","common/extend","base/component"],function(a){function f(){return this._cachedIsValid?this._cachedMatrix:(this._cachedMatrix=b.transform.fixed(this.position,this.rotation,this.scale),this._cachedIsValid=!0,this._cachedMatrix)}function g(a){return b.vector3.set(this.position,a[0],a[1],a[2]),this._cachedIsValid=!1,this}function h(a){return b.vector3.set(this.rotation,a[0],a[1],a[2]),this._cachedIsValid=!1,this}function i(a){return b.vector3.set(this.scale,a[0],a[1],a[2]),this._cachedIsValid=!1,this}function j(){if(this.owner&&this.owner.parent&&this.owner.parent.hasComponent("Transform")){var a=this.owner.parent.findComponent(this.type);this._cachedAbsolute=b.matrix4.multiply([f.call(this),a.absolute()])}else this._cachedAbsolute=f.call(this);return this._cachedAbsolute}function k(){throw new Error("not implemented")}var b=a("_math"),c=a("common/extend"),d=a("base/component"),e=function(a,c,e){d.call(this,"Transform",null,[]),this.position=a?new b.Vector3(a):b.vector3.zero,this.rotation=c?new b.Vector3(c):b.vector3.zero,this.scale=e?new b.Vector3(e):b.vector3.one,this._cachedMatrix=b.matrix4.identity,this._cachedIsValid=!1,this._cachedAbsolute=b.matrix4.identity};e.prototype=new d,e.prototype.constructor=e;var l={setPosition:g,setRotation:h,setScale:i,absolute:j,relative:k};return c(e.prototype,l),e}),c("core/resources/script",["require"],function(a){var b=function(a){if(a===undefined)throw new Error("script body is undefined");var b=new Function([],"var f = "+a+"; return f.apply( null, Array.prototype.slice.call(arguments) );");return b};return b}),c("core/loaders/procedural",["require","core/get","core/resources/script","common/get-url-params"],function(a){var b=a("core/get"),c=a("core/resources/script"),d=a("common/get-url-params");return function(a,e,f){var g=a.split("?")[0],h=d(a);b([{url:g,type:c,onsuccess:function(a){try{var b=a(h);e(b)}catch(c){f(c)}},onfailure:f}])}});if(typeof c!="function")var c=b("amdefine")(module);c("core/services/updater",["require","base/service","core/event"],function(a){function e(){var a=this._registeredComponents,b,d=new c("Update",!1);for(var e in a)for(var f in a[e]){b=a[e][f];while(b.handleQueuedEvent());d.dispatch(b)}}var b=a("base/service"),c=a("core/event"),d=function(a,c){c=c||{};var d={update:{tags:["@update","logic"],dependsOn:["physics"]}};b.call(this,a,d)};return d.prototype=new b,d.prototype.constructor=d,d.prototype.update=e,d});if(typeof c!="function")var c=b("amdefine")(module);c("core/components/actor",["require","base/component","common/extend"],function(a){function e(a){var b=a.data;b.previous===null&&b.current!==null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),b.previous!==null&&b.current===null&&this.owner!==null&&this.provider.unregisterComponent(this.owner.id,this)}function f(a){var b=a.data;b.previous===null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),this.owner===null&&b.previous!==null&&this.provider.unregisterComponent(b.previous.id,this)}function g(a){var b=a.data;b?this.provider.registerComponent(this.owner.id,this):this.provider.unregisterComponent(this.owner.id,this)}var b=a("base/component"),c=a("common/extend"),d=function(a,c){b.call(this,"Logic",a,[]),c=c||{};var d,e,f=Object.keys(c);for(d=0,e=f.length;d<e;++d){var g=f[d];this["on"+g]=c[g]}};d.prototype=new b,d.prototype.constructor=d;var h={onEntitySpaceChanged:e,onComponentOwnerChanged:f,onEntityActivationChanged:g};return c(d.prototype,h),d}),c("core/resources/event-map",["require","core/get","core/resources/script"],function(a){var b=a("core/get"),c=a("core/resources/script"),d=function(a){a=a||{};var d={},e=[],f=Object.keys(a);for(var g in f)"string"==typeof a[g]?e.push({type:c,url:a[g],onsuccess:function(a){d[g]=a},onfailure:function(b){throw console.log("error loading script: "+a[g]),b}}):"function"==typeof a[g]&&(d[g]=a[g]);return b(e),d};return d});if(typeof c!="function")var c=b("amdefine")(module);c("core/engine",["require","_math","common/multicast-delegate","core/request-animation-frame-loop","core/clock","core/dependency-scheduler","core/function-task","core/timer","core/event","core/get","core/loaders/default","core/loaders/procedural","base/component","base/service","base/extension","core/space","core/entity","core/components/transform","core/resources/script","core/services/updater","core/components/actor","core/resources/event-map"],function(a){function q(){this.frame+=1;var a=Date.now();this.cachedTimestamp=this.cachedTimestamp||a;var b=a-this.cachedTimestamp;this.cachedTimestamp=a,this.realClock.update(b),this._scheduler.update();while(this._scheduler.hasNext())this._scheduler.next().run();this._monitor.size>0&&this._monitor(this)}function s(){return this._loop.suspend(),this}function t(){return this._loop.resume(),this}function u(a){return this._monitor.subscribe(a),this}function v(a){return this._monitor.unsubscribe(a),this}function w(){return this._loop.isStarted()}function x(a,b){if(!a instanceof l.Extension)throw new Error("argument is not an extension");b=b||{};var c,d,e,f,g={},h=a.services,i=Object.keys(h),j,k,m,n,o,p,q,r,s,t,u;for(c=0,d=i.length;c<d;++c){j=i[c],k=b[j]||{};if(typeof h[j]=="function")g[j]=new h[j](this._scheduler,k);else if(typeof h[j]=="object"){m=new h[j].service(this._scheduler,k),g[j]=m,n=h[j].components,o=Object.keys(n);for(e=0,f=o.length;e<f;++e){p=o[e],q=n[p].bind(null,m);var v=Object.keys(n[p]);for(c=0,d=v.length;c<d;++c)q[v[c]]=n[p][v[c]];g[p]=q}r=h[j].resources,s=Object.keys(r);for(e=0,f=s.length;e<f;++e){t=s[e],u=r[t].bind(null,m);var w=Object.keys(r[t]);for(c=0,d=w.length;c<d;++c)u[w[c]]=r[t][w[c]];g[t]=u}}}n=a.components,o=Object.keys(n);for(c=0,d=o.length;c<d;++c)p=o[c],q=n[p],g[p]=q;r=a.resources,s=Object.keys(r);for(c=0,d=s.length;c<d;++c)t=s[c],u=r[t],g[t]=u;return this._extensions[a.name]=g,this.hasOwnProperty(name)||(this[a.name]=g),this}function y(a){throw new Error("not implemented")}function z(a){return this._extensions.hasOwnProperty(a)?this._extensions[a]:undefined}function A(a){return this._extensions.hasOwnProperty(a)}var b=a("_math"),c=a("common/multicast-delegate"),d=a("core/request-animation-frame-loop"),e=a("core/clock"),f=a("core/dependency-scheduler"),g=a("core/function-task"),h=a("core/timer"),i=a("core/event"),j=a("core/get"),k={text:a("core/loaders/default"),procedural:a("core/loaders/procedural")},l={Component:a("base/component"),Service:a("base/service"),Extension:a("base/extension")},m=a("core/space"),n=a("core/entity"),o=new l.Extension("core",{components:{Transform:a("core/components/transform")},resources:{Script:a("core/resources/script")}}),p=new l.Extension("logic",{services:{updater:{service:a("core/services/updater"),components:{Actor:a("core/components/actor")},resources:{}}},resources:{EventMap:a("core/resources/event-map")}}),r=function(){this._loop=new d(q,this),this.frame=0,this._monitor=new c,this.realClock=new e,this.simulationClock=new e(this.realClock.signal),this._scheduler=new f,this.FunctionTask=g.bind(this,this._scheduler),this.Timer=h,this.Event=i,this.RealTimer=h.bind(this,this.realClock.signal),this.SimulationTimer=h.bind(this,this.simulationClock.signal),this.base=l,this.Space=m,this.RealSpace=m.bind(null,this.realClock),this.SimulationSpace=m.bind(null,this.simulationClock),this.Entity=n,this._extensions={},this.registerExtension(o),this.registerExtension(p)};return r.prototype={isRunning:w,suspend:s,resume:t,attach:u,detach:v,registerExtension:x,unregisterExtension:y,findExtension:z,hasExtension:A,get:j,loaders:k,math:b},r});if(typeof c!="function")var c=b("amdefine")(module);c("core/gladius-core",["require","core/engine"],function(a){var b=a("core/engine");return b});var d=b("core/gladius-core");return d});