-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-built.js
1 lines (1 loc) · 95.8 KB
/
main-built.js
1
define("engine/common/config",[],function(){return{touchable:"createTouch"in document,isiOS:function(){var e=navigator.userAgent;return/iPad/i.test(e)||/iPhone OS 3_1_2/i.test(e)||/iPhone OS 3_2_2/i.test(e)}(),maxBone:20,texturePath:"res/images/",shaderPath:"res/shaders/",modelPath:"res/models/"}}),define("engine/common/utils",[],function(){var e={};return e.makeCoordinate=function(e,t,n){vec3.normalize(e,e),vec3.cross(n,t,e),vec3.normalize(n,n),vec3.cross(t,e,n)},e.mat4Transform=function(t,n,r,i){var s=vec3.create(),o=[-i[0],-i[1],-i[2]],u=r;e.makeCoordinate(o,u,s),t[0]=s[0],t[1]=u[0],t[2]=o[0],t[3]=0,t[4]=s[1],t[5]=u[1],t[6]=o[1],t[7]=0,t[8]=s[2],t[9]=u[2],t[10]=o[2],t[11]=0,t[12]=-(s[0]*n[0]+s[1]*n[1]+s[2]*n[2]),t[13]=-(u[0]*n[0]+u[1]*n[1]+u[2]*n[2]),t[14]=-(o[0]*n[0]+o[1]*n[1]+o[2]*n[2]),t[15]=1},e.mat3Transform=function(t,n,r){var i=vec3.create(),s=[-r[0],-r[1],-r[2]],o=n;e.makeCoordinate(s,o,i),t[0]=i[0],t[1]=o[0],t[2]=s[0],t[3]=i[1],t[4]=o[1],t[5]=s[1],t[6]=i[2],t[7]=o[2],t[8]=s[2]},e.rayTraceAABB=function(e,t,n,r,i){var s=!0;i.pos=vec3.clone(e);var o=[0,0,0],u=[-1,-1,-1];for(var a=0;a<3;a++)e[a]<n[a]?(i.pos[a]=n[a],s=!1,o[a]=1,t[a]!=0&&(u[a]=(n[a]-e[a])/t[a])):e[a]>r[a]&&(i.pos[a]=r[a],s=!1,o[a]=-1,t[a]!=0&&(u[a]=(r[a]-e[a])/t[a]));if(s)return i.t=0,i.normal=[0,0,0],!0;var f=0;i.normal=[-o[0],0,0];var l=u[0];u[1]>u[f]&&(f=1,i.normal=[0,-o[1],0],l=u[1]),u[2]>u[f]&&(f=2,i.normal=[0,0,-o[2]],l=u[2]);if(l<0||i.maxt!=undefined&&i.maxt<l)return!1;for(var a=0;a<3;a++)if(a!=f){i.pos[a]=e[a]+l*t[a];if(i.pos[a]<n[a]||i.pos[a]>r[a])return!1}return i.t=l,!0},e.rayTraceSphere=function(e,t,n,r,i){var s=[e[0]-n[0],e[1]-n[1],e[2]-n[2]],o=vec3.dot(t,t),u=2*vec3.dot(t,s),a=vec3.dot(s,s)-r*r,f=u*u-4*o*a;if(f<0)return!1;var l=Math.sqrt(f),c;u<0?c=(-u-l)/2:c=(-u+l)/2;var h=c/o,p=a/c;if(h>p){var d=h;h=p,p=d}if(p<0)return!1;var v;return h<0?v=p:v=h,v<0||i.maxt!=undefined&&i.maxt<v?!1:(i.t=v,i.normal=[s[0]+v*t[0],s[1]+v*t[1],s[2]+v*t[2]],vec3.scale(i.normal,i.normal,1/r),!0)},e.normalizeAngle=function(e){while(e<0)e+=2*Math.PI;while(e>=2*Math.PI)e-=2*Math.PI;return e},e.clipProjectionMatrix=function(e,t,n){mat4.copy(e,n);if(t.constant>0)return;var r=[t.normal[0],t.normal[1],t.normal[2],t.constant],i=[0,0,0,0],s=function(e){return e>0?1:e<0?-1:0};i[0]=(s(r[0])+n[8])/n[0],i[1]=(s(r[1])+n[9])/n[5],i[2]=-1,i[3]=(1+n[10])/n[14];var o=2/vec4.dot(r,i);e[2]=r[0]*o,e[6]=r[1]*o,e[10]=r[2]*o+1,e[14]=r[3]*o},e.trimString=function(e){var t=0;while(t<e.length&&e.charCodeAt(t)<=32)t++;var n=e.length-1;while(n>t&&e.charCodeAt(n)<=32)n--;return e.substring(t,n+1)},vec3.transformQuatInv=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=n[0],u=n[1],a=n[2],f=n[3],l=f*r-u*s+a*i,c=f*i-a*r+o*s,h=f*s-o*i+u*r,p=o*r+u*i+a*s;return e[0]=l*f+p*o+c*a-h*u,e[1]=c*f+p*u+h*o-l*a,e[2]=h*f+p*a+l*u-c*o,e},vec3.isZero=function(e){return e[0]==0&&e[1]==0&&e[2]==0},mat4.multiply4x3=function(e,t,n){var r=t[0],i=t[1],s=t[2],o=t[4],u=t[5],a=t[6],f=t[8],l=t[9],c=t[10],h=t[12],p=t[13],d=t[14],v=n[0],m=n[1],g=n[2];return e[0]=v*r+m*o+g*f,e[1]=v*i+m*u+g*l,e[2]=v*s+m*a+g*c,v=n[4],m=n[5],g=n[6],e[4]=v*r+m*o+g*f,e[5]=v*i+m*u+g*l,e[6]=v*s+m*a+g*c,v=n[8],m=n[9],g=n[10],e[8]=v*r+m*o+g*f,e[9]=v*i+m*u+g*l,e[10]=v*s+m*a+g*c,v=n[12],m=n[13],g=n[14],e[12]=v*r+m*o+g*f+h,e[13]=v*i+m*u+g*l+p,e[14]=v*s+m*a+g*c+d,e},vec3.transformMat4NoTranslation=function(e,t,n){var r=t[0],i=t[1],s=t[2];return e[0]=n[0]*r+n[4]*i+n[8]*s,e[1]=n[1]*r+n[5]*i+n[9]*s,e[2]=n[2]*r+n[6]*i+n[10]*s,e},vec3.distanceXZ=function(e,t){var n=e[0]-t[0],r=e[2]-t[2];return Math.sqrt(n*n+r*r)},vec3.ToString=function(e){return"("+e[0].toFixed(2)+","+e[1].toFixed(2)+","+e[2].toFixed(2)+")"},vec3.randomInBox=function(e,t,n){e[0]=Math.random()*(n[0]-t[0])+t[0],e[1]=Math.random()*(n[1]-t[1])+t[1],e[2]=Math.random()*(n[2]-t[2])+t[2]},vec3.randomOnSphere=function(e,t,n){var r=Math.PI*Math.random(),i=Math.PI*2*Math.random(),s=Math.cos(r),o=Math.sin(r),u=Math.cos(i),a=Math.sin(i);e[0]=o*u*n+t[0],e[1]=s*n+t[1],e[2]=o*a*n+t[2]},vec3.randomOnCircleXZ=function(e,t,n){var r=Math.PI*2*Math.random(),i=Math.cos(r),s=Math.sin(r);e[0]=i*n+t[0],e[1]=t[1],e[2]=s*n+t[2]},e}),define("engine/common/mathlib",[],function(){var e=0,t=1,n=2,r=function(e,t){this.normal=e!==undefined?e:[1,0,0],this.constant=t!==undefined?t:0};r.prototype={constructor:r,set:function(e,t){return vec3.copy(this.normal,e),this.constant=t,this},fromNormalAndCoplanarPoint:function(e,t){return vec3.copy(this.normal,e),this.constant=-vec3.dot(t,this.normal),this},fromCoplanarPoints:function(){var e=[0,0,0],t=[0,0,0];return function(n,r,i){return vec3.sub(e,i,r),vec3.sub(t,n,r),vec3.cross(this.normal,e,t),vec3.normalize(this.normal,this.normal),this.constant=-vec3.dot(n,this.normal),this}}(),copy:function(e){return vec3.copy(this.normal,e.normal),this.constant=e.constant,this},clone:function(){var e=new r;return vec3.copy(e.normal,this.normal),e.constant=this.constant,e},normalize:function(){var e=1/vec3.length(this.normal);return vec3.scale(this.normal,this.normal,e),this.constant*=e,this},negate:function(){return this.constant*=-1,vec3.negate(this.normal,this.normal),this},distanceToPoint:function(e){return vec3.dot(this.normal,e)+this.constant},distanceToSphere:function(e,t){return this.distanceToPoint(e)-t},projectPoint:function(e,t){this.orthoPoint(e,t),vec3.sub(e,t,e)},orthoPoint:function(e,t){var n=this.distanceToPoint(t);vec3.scale(e,this.normal,n)},isIntersectionLine:function(e,t){var n=this.distanceToPoint(e),r=this.distanceToPoint(t);return n<0&&r>0||r<0&&n>0},intersectAABB:function(){var r=[0,0,0];return function(i){r[0]=Math.abs(this.normal[0]),r[1]=Math.abs(this.normal[1]),r[2]=Math.abs(this.normal[2]);var s=vec3.dot(i.extend,r),o=this.distanceToPoint(i.center);return o-s>0?e:o+s<0?t:n}}(),coplanarPoint:function(e){vec3.scale(e,this.normal,-this.constant)},applyMatrix4:function(){var e=mat4.create(),t=[0,0,0],n=[0,0,0];return function(r){return mat4.invert(e,r),mat4.transpose(e,e),vec3.transformMat4NoTranslation(t,this.normal,e),this.coplanarPoint(n),vec3.transformMat4(n,n,r),this.fromNormalAndCoplanarPoint(t,n),this}}(),translate:function(e){return this.constant=this.constant-vec3.dot(this.normal,e),this},mirrorVector:function(){var e=[0,0,0];return function(t,n){vec3.scale(e,this.normal,-2*vec3.dot(n,this.normal)),vec3.add(t,n,e)}}(),mirrorPoint:function(){var e=[0,0,0];return function(t,n){this.projectPoint(e,n),vec3.scale(e,e,2),vec3.sub(t,e,n)}}()};var i=function(e,t,n,i,s,o){this.planes=[e!==undefined?e:new r,t!==undefined?t:new r,n!==undefined?n:new r,i!==undefined?i:new r,s!==undefined?s:new r,o!==undefined?o:new r]};return i.prototype={constructor:i,set:function(e,t,n,r,i,s){var o=this.planes;return o[0].copy(e),o[1].copy(t),o[2].copy(n),o[3].copy(r),o[4].copy(i),o[5].copy(s),this},copy:function(e){var t=this.planes;for(var n=0;n<6;n++)t[n].copy(e.planes[n]);return this},setFromMatrix:function(e){var t=this.planes,n=e[0],r=e[1],i=e[2],s=e[3],o=e[4],u=e[5],a=e[6],f=e[7],l=e[8],c=e[9],h=e[10],p=e[11],d=e[12],v=e[13],m=e[14],g=e[15];return t[0].set([s-n,f-o,p-l],g-d).normalize(),t[1].set([s+n,f+o,p+l],g+d).normalize(),t[2].set([s+r,f+u,p+c],g+v).normalize(),t[3].set([s-r,f-u,p-c],g-v).normalize(),t[4].set([s-i,f-a,p-h],g-m).normalize(),t[5].set([s+i,f+a,p+h],g+m).normalize(),this},intersectsSphere:function(e,t){var n=this.planes,r=-t;for(var i=0;i<6;i++){var s=n[i].distanceToPoint(e);if(s<r)return!1}return!0},containsPoint:function(e){var t=this.planes;for(var n=0;n<6;n++)if(t[n].distanceToPoint(e)<0)return!1;return!0},intersectAABB:function(e){for(var n=0;n<6;n++){var r=this.planes[n].intersectAABB(e);if(r===t)return!1}return!0},clone:function(){return(new i).copy(this)}},{Plane:r,Frustum:i}}),define("engine/core/aabb",[],function(){var e=function(){this.clear()};return e.prototype.clear=function(){this.maxs=[-1e6,-1e6,-1e6],this.mins=[1e6,1e6,1e6],this.center=[0,0,0],this.extend=[0,0,0]},e.prototype.addVertex=function(e,t,n){this.maxs[0]=Math.max(e,this.maxs[0]),this.maxs[1]=Math.max(t,this.maxs[1]),this.maxs[2]=Math.max(n,this.maxs[2]),this.mins[0]=Math.min(e,this.mins[0]),this.mins[1]=Math.min(t,this.mins[1]),this.mins[2]=Math.min(n,this.mins[2])},e.prototype.completeCenterExt=function(){this.center[0]=.5*(this.maxs[0]+this.mins[0]),this.center[1]=.5*(this.maxs[1]+this.mins[1]),this.center[2]=.5*(this.maxs[2]+this.mins[2]),this.extend[0]=.5*(this.maxs[0]-this.mins[0]),this.extend[1]=.5*(this.maxs[1]-this.mins[1]),this.extend[2]=.5*(this.maxs[2]-this.mins[2])},e.prototype.mergeAABB=function(e){this.maxs[0]=Math.max(e.maxs[0],this.maxs[0]),this.maxs[1]=Math.max(e.maxs[1],this.maxs[1]),this.maxs[2]=Math.max(e.maxs[2],this.maxs[2]),this.mins[0]=Math.min(e.mins[0],this.mins[0]),this.mins[1]=Math.min(e.mins[1],this.mins[1]),this.mins[2]=Math.min(e.mins[2],this.mins[2])},e.prototype.transformAABB=function(t){var n=this.getCorners(),r=new e;for(var i=0;i<8;i++)vec3.transformMat4(n[i],n[i],t),r.addVertex(n[i][0],n[i][1],n[i][2]);return r.completeCenterExt(),r},e.prototype.clone=function(){var t=new e;return t.maxs=this.aabb.maxs.slice(),t.mins=this.aabb.mins.slice(),t.center=this.aabb.center.slice(),t.extend=this.aabb.extend.slice(),t},e.prototype.getCorners=function(){return new Array([this.mins[0],this.mins[1],this.mins[2]],[this.mins[0],this.mins[1],this.maxs[2]],[this.mins[0],this.maxs[1],this.mins[2]],[this.mins[0],this.maxs[1],this.maxs[2]],[this.maxs[0],this.mins[1],this.mins[2]],[this.maxs[0],this.mins[1],this.maxs[2]],[this.maxs[0],this.maxs[1],this.mins[2]],[this.maxs[0],this.maxs[1],this.maxs[2]])},e}),define("engine/core/camera",["../common/mathlib","../common/utils"],function(e,t){var n=function(t){t.pos?this.pos=t.pos:this.pos=[0,10,10],t.target?this.target=t.target:this.target=[0,0,0],t.dir?this.dir=t.dir:(this.dir=new Array(3),vec3.sub(this.dir,this.target,this.pos)),t.fov?this.fov=t.fov:this.fov=Math.PI/3,t.zn?this.zn=t.zn:this.zn=1,t.zf?this.zf=t.zf:this.zf=1e4,this.up=[0,1,0],this.right=[1,0,0],this.matView=mat4.create(),this.matProj=mat4.create(),this.matOrgProj=mat4.create(),this.matViewProj=mat4.create(),this.matInvView=mat4.create(),this.frustum=new e.Frustum,this.updateView(),this.updateProj(),this.rotX=Math.atan2(-this.dir[2],-this.dir[0]),this.rotY=Math.acos(-this.dir[1]),this.distance=vec3.distance(this.target,this.pos),this.clipPlaneViewSpace=null,this.clipPlane=null};return n.prototype.updateView=function(){vec3.normalize(this.dir,this.dir),vec3.normalize(this.up,this.up),t.makeCoordinate(this.dir,this.up,this.right),t.mat4Transform(this.matView,this.pos,this.up,this.dir),mat4.mul(this.matViewProj,this.matProj,this.matView),mat4.invert(this.matInvView,this.matView),this.clipPlane&&(this.clipPlaneViewSpace||(this.clipPlaneViewSpace=new e.Plane),this.clipPlaneViewSpace.copy(this.clipPlane),this.clipPlaneViewSpace.applyMatrix4(this.matView),t.clipProjectionMatrix(this.matProj,this.clipPlaneViewSpace,this.matOrgProj)),this.frustum.setFromMatrix(this.matViewProj)},n.prototype.updateProj=function(){mat4.perspective(this.matOrgProj,this.fov,canvas.width/canvas.height,this.zn,this.zf),this.clipPlaneViewSpace?t.clipProjectionMatrix(this.matProj,this.clipPlaneViewSpace,this.matOrgProj):mat4.copy(this.matProj,this.matOrgProj),mat4.mul(this.matViewProj,this.matProj,this.matView),this.frustum.setFromMatrix(this.matViewProj)},n.prototype.rotateRelative=function(e,t){this.rotX+=e,this.rotY+=t,this.rotY=Math.min(this.rotY,Math.PI/2-.001),this.rotY=Math.max(this.rotY,.001),this.dir[0]=-Math.sin(this.rotY)*Math.cos(this.rotX),this.dir[2]=-Math.sin(this.rotY)*Math.sin(this.rotX),this.dir[1]=-Math.cos(this.rotY),this.up=[0,1,0];var n=vec3.create();vec3.scale(n,this.dir,this.distance),vec3.sub(this.pos,this.target,n),this.updateView()},n.prototype.zoom=function(e){this.distance+=e;var t=vec3.create();vec3.scale(t,this.dir,this.distance),vec3.sub(this.pos,this.target,t),this.updateView()},n.prototype.invertDir=function(e,t,n,r,i){r==undefined&&(r=canvas.width),i==undefined&&(i=canvas.height);var s=2*t/r-1,o=1-2*n/i;e[0]=s*this.zf/this.matProj[0],e[1]=o*this.zf/this.matProj[5],e[2]=-this.zf;var u=[0,0,0];vec3.transformMat4(u,e,this.matInvView),vec3.sub(e,u,this.pos),vec3.normalize(e,e)},n.prototype.getDirXZ=function(){var e=[this.dir[0],0,this.dir[2]];return vec3.normalize(e,e),e},n.prototype.move=function(e){vec3.add(this.pos,this.pos,e),vec3.add(this.target,this.target,e),this.updateView()},n.prototype.setClipPlane=function(e){e?(this.clipPlane=e.clone(),this.clipPlaneViewSpace=e.clone(),this.clipPlaneViewSpace.applyMatrix4(this.matView)):this.clipPlaneViewSpace=null,this.updateProj()},n.prototype.isAABBVisible=function(e){return this.clipPlane&&this.clipPlane.intersectAABB(e)==1?!1:this.frustum.intersectAABB(e)},n}),define("engine/renderres/resman",[],function(){var e=100,t=[];return{newResource:function(n){e++,n.resid=e,t[e]=n},freeResource:function(n){n.resid=e,t[n.resid]=undefined},getResourceById:function(e){return t[e]}}}),define("engine/renderres/texture",["./resman"],function(e){var t=function(){this.texture=gl.createTexture(),this.image=null,this.dataInfo=null,this.flipY=!1,this.width=0,this.height=0,this.magFilter=gl.LINEAR,this.minFilter=gl.LINEAR_MIPMAP_LINEAR,this.wrapS=gl.REPEAT,this.wrapT=gl.REPEAT,this.mipmap=!0,this.loaded=!1,this.width=0,this.height=0,e.newResource(this)};t.prototype.recreate=function(){gl.bindTexture(gl.TEXTURE_2D,this.texture),gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL,this.flipY),this.image?(gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,this.image),this.width=this.image.width,this.height=this.image.height):(gl.texImage2D(gl.TEXTURE_2D,0,this.dataInfo.interFormat,this.dataInfo.width,this.dataInfo.height,0,this.dataInfo.format,this.dataInfo.dataType,this.dataInfo.data),this.width=this.dataInfo.width,this.height=this.dataInfo.height),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,this.magFilter),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,this.minFilter),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this.wrapS),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this.wrapT),this.mipmap&&gl.generateMipmap(gl.TEXTURE_2D),gl.bindTexture(gl.TEXTURE_2D,null),this.loaded=!0},t.prototype.load=function(e){this.image=new Image,this.dataInfo=null;var t=this;this.image.onload=function(){t.recreate.apply(t)},this.image.src=e,this.loaded=!1},t.prototype.createFromData=function(e,t,n,r,i,s){this.dataInfo={width:e,height:t,format:r||gl.RGBA,interFormat:i||gl.RGBA,dataType:s||gl.UNSIGNED_BYTE},this.dataInfo.data=n instanceof Array?new Uint8Array(n):n,this.loaded=!1,this.recreate()},t.prototype.release=function(){this.image=null,gl.deleteTexture(this.texture),this.texture=null,e.freeResource(this)},t.prototype.onlost=function(){this.texture=null,this.loaded=!1},t.prototype.onrestore=function(){this.texture=gl.createTexture(),this.recreate()},t.prototype.appear=function(e){if(!this.texture||!this.loaded){this!=n.error&&n.error.appear(e);return}gl.activeTexture(gl.TEXTURE0+e),gl.bindTexture(gl.TEXTURE_2D,this.texture)};var n={textureMap:{}};return n.init=function(){n.white=new t,n.white.magFilter=gl.NEAREST,n.white.minFilter=gl.NEAREST,n.white.createFromData(1,1,[255,255,255,255]),n.black=new t,n.black.magFilter=gl.NEAREST,n.black.minFilter=gl.NEAREST,n.black.createFromData(1,1,[0,0,0,255]),n.error=new t,n.error.magFilter=gl.NEAREST,n.error.minFilter=gl.NEAREST,n.error.minFilter=gl.NEAREST_MIPMAP_LINEAR;var e=16,r=new Array(e*e*4),i=0;for(var s=0;s<e;s++)for(var o=0;o<e;o++)(s+o)%2==0?(r[i*4+0]=0,r[i*4+1]=255,r[i*4+2]=255,r[i*4+3]=255):(r[i*4+0]=255,r[i*4+1]=0,r[i*4+2]=255,r[i*4+3]=255),i++;n.error.createFromData(e,e,r)},n.loadTexture=function(e){var n=this.textureMap[e];return n!=undefined?n:(n=new t,n.load(e),this.textureMap[e]=n,n)},t.Manager=n,t}),define("engine/common/domutils",[],function(){var e={};return e.mousePosFromEvent=function(e){return e.offsetX||e.offsetY?{x:e.offsetX,y:e.offsetY}:e.layerX||e.layerY?{x:e.layerX,y:e.layerY}:{x:e.pageX-e.target.offsetLeft,y:e.pageY-e.target.offsetTop}},e.setWheelEvent=function(t,n){var r=function(t){var r=0;t||(t=window.event),t.wheelDelta?r=t.wheelDelta/120:t.detail&&(r=-t.detail/3);var i=e.mousePosFromEvent(t);r&&n(i,r,t),t.preventDefault&&t.preventDefault(),t.returnValue=!1};t.addEventListener&&t.addEventListener("DOMMouseScroll",r,!1),t.onmousewheel=r},e.getTextFromElement=function(e){var t=document.getElementById(e);if(!t)return"";var n="",r=t.firstChild;while(r)r.nodeType==3&&(n+=r.textContent),r=r.nextSibling;return n},e.createXmlHttp=function(){return window.XMLHttpRequest?new XMLHttpRequest:ActiveXObject("Microsoft.XMLHTTP")},e}),define("engine/file/filemanager",[],function(){var e=function(){this.fileMap={}};return e.Item=function(e){this.name=e,this.callbacks=[],this.ready=!1,this.content=null},e.prototype.loadFile=function(e,t,n){var r;if(this.fileMap[e])r=this.fileMap[e];else{r=this.doLoadFile(e);if(!r)return r;r&&(this.fileMap[e]=r)}return n&&(r.ready?n.call(t,r):r.callbacks.push({owner:t,func:n})),r},e.prototype.onFileReady=function(e){e.ready=!0;for(var t=0;t<e.callbacks.length;t++)e.callbacks[t].func.call(e.callbacks[t].owner,e);e.callbacks.length=0},e.prototype.doLoadFile=function(){},e.prototype.clear=function(){this.fileMap={}},e}),define("engine/file/textfilemanager",["./filemanager","../common/domutils","../common/utils"],function(e,t,n){var r=new e;return r.doLoadFile=function(n){var r=t.createXmlHttp();r.open("GET",n,!1),r.send();if(r.status!=200)return alert("File open error:"+n+"\n"+r.statusText),null;var i=new e.Item;return i.content=r.responseText,i.content?(this.onFileReady(i),i):null},r.simpleLoad=function(e){var t=this.loadFile(e);return t?t.content:""},r.loadFileWithInclude=function(){var e={},t=0;return function(r,i){i=i||"",e[r],t++,e[r]=!0;var s=this.simpleLoad(r),o=s.split("\n"),u="";for(var a=0;a<o.length;a++){var f=null,l=n.trimString(o[a]);l.charAt(0)=="#"&&(f=l.match(/#include\s*[<"](.+)[>"]/)),f&&f[1]?u+=this.loadFileWithInclude(i+f[1],i):u+=l,u+="\n"}return t--,t==0&&(e={}),u}}(),r.loadXML=function(e){var t=r.simpleLoad(e),n=null;try{var i=new DOMParser;n=i.parseFromString(t,"text/xml")}catch(s){alert(s.message)}return n},r}),define("engine/renderres/shader",["./resman","../common/domutils","../file/textfilemanager","../common/config"],function(e,t,n,r){var i,s=function(t){this.vs=null,this.fs=null,this.program=null,this.vsContent="",this.fsContent="",this.name=t,e.newResource(this),i||require(["engine/renderres/texture"],function(e){i=e})};return s.prototype.compileShader=function(e,t){var n=gl.createShader(e);gl.shaderSource(n,t),gl.compileShader(n);if(!gl.getShaderParameter(n,gl.COMPILE_STATUS)){var r=e==gl.VERTEX_SHADER?"Vertex Shader":"Fragment Shader";return alert(r+" ["+this.name+"] ERROR:\n"+gl.getShaderInfoLog(n)+"\n"+t),null}return n},s.prototype.linkProgram=function(){this.program=gl.createProgram(),gl.attachShader(this.program,this.vs),gl.attachShader(this.program,this.fs),gl.linkProgram(this.program),gl.getProgramParameter(this.program,gl.LINK_STATUS)||(alert("Could not initialise shaders"),gl.deleteProgram(this.program),this.program=null)},s.prototype.create=function(){this.vs=this.compileShader(gl.VERTEX_SHADER,this.vsContent);if(!this.vs)return;this.fs=this.compileShader(gl.FRAGMENT_SHADER,this.fsContent);if(!this.fs)return;this.linkProgram()},s.prototype.initCommon=function(){this.posSlot=this.getAttrib("aPosition"),this.normalSlot=this.getAttrib("aNormal"),this.texcoordSlot=this.getAttrib("aTexcoord"),this.colorSlot=this.getAttrib("aColor"),this.unifWorld=this.getUniform("matWorld"),this.unifViewProj=this.getUniform("matViewProj"),this.unifDiffuseMap=this.getUniform("DiffuseMap"),this.unifDiffuseColor=this.getUniform("DiffuseColor")},s.prototype.generateDefineSource=function(e){var t="";if(!e)return t;var n=e.split(";");for(var r=0;r<n.length;r++){var i=n[r].split("=");if(!i[0])continue;i[1]?t+="#define "+i[0]+" "+i[1]+"\n":t+="#define "+i[0]+"\n"}return t},s.prototype.loadFromFile=function(e,t,i){var s=this.generateDefineSource(i);this.name=e+"#"+t+(i?"#"+i:""),this.vsContent=s+n.loadFileWithInclude(r.shaderPath+e,r.shaderPath),this.fsContent=s+n.loadFileWithInclude(r.shaderPath+t,r.shaderPath),this.create()},s.prototype.loadFromElement=function(e,n){this.vsContent=t.getTextFromElement(e),this.fsContent=t.getTextFromElement(n),this.create()},s.prototype.release=function(){gl.deleteShader(this.vs),this.vs=null,gl.deleteShader(this.fs),this.fs=null,gl.deleteProgram(this.program),this.program=null,e.freeResource(this)},s.prototype.appear=function(){return this.program?(gl.useProgram(this.program),!0):!1},s.prototype.getAttrib=function(e){return gl.getAttribLocation(this.program,e)},s.prototype.getUniform=function(e){return gl.getUniformLocation(this.program,e)},s.prototype.setCommon=function(){},s.prototype.setIndividual=function(){},s.prototype.setPass=function(){},s.createDiffuseShader=function(){var e;return function(){if(e)return e;var t=new s("diffuse mesh");return t.loadFromFile("model-vs.glsl","color_texture-fs.txt"),t.initCommon(),t.setCommon=function(){gl.uniformMatrix4fv(t.unifViewProj,!1,engine.activeCamera.matViewProj),gl.uniform1i(t.unifDiffuseMap,0)},t.setIndividual=function(e){gl.uniformMatrix4fv(t.unifWorld,!1,e.mat),e.mesh.vb.bindAttribute([t.posSlot,t.normalSlot,t.texcoordSlot]),e.mesh.texture?e.mesh.texture.appear(0):i&&i.Manager.error.appear(0)},e=t,t}}(),s.createSkinDiffuseShader=function(){var e;return function(){if(e)return e;var t=new s("skin diffuse mesh");return t.loadFromFile("model-vs.glsl","color_texture-fs.txt","_SKIN_"),t.initCommon(),t.blendWeightSlot=t.getAttrib("aBlendWeights"),t.blendIndicesSlot=t.getAttrib("aBlendIndices"),t.unifBlendMat=t.getUniform("matBlend"),t.setCommon=function(){gl.uniformMatrix4fv(t.unifViewProj,!1,engine.activeCamera.matViewProj),gl.uniform1i(t.unifDiffuseMap,0)},t.setIndividual=function(e){gl.uniformMatrix4fv(t.unifWorld,!1,e.mat),e.mesh.vb.bindAttribute([t.posSlot,t.normalSlot,t.texcoordSlot]),e.mesh.vbBoneWeights.bindAttribute([t.blendWeightSlot]),e.mesh.texture?e.mesh.texture.appear(0):i&&i.Manager.error.appear(0)},t.setPass=function(e,n){var r=e.submeshes[n];r.vbBoneIndices.bindAttribute([t.blendIndicesSlot]),gl.uniform4fv(t.unifBlendMat,r.skinUniforms)},e=t,t}}(),s.createColorShader=function(){var e;return function(){if(e)return e;var t=new s("color");return t.loadFromFile("color-vs.txt","color-fs.txt"),t.initCommon(),t.colorSlot=t.getAttrib("aColor"),t.setCommon=function(){gl.uniformMatrix4fv(t.unifViewProj,!1,engine.activeCamera.matViewProj)},t.setIndividual=function(e){gl.uniformMatrix4fv(t.unifWorld,!1,e.mat),e.mesh.vb.bindAttribute([t.posSlot,t.colorSlot])},e=t,t}}(),s.createTextureShader=function(){var e=[];return function(t,n){t=t||"texture",n=n||"";var r=t+"#"+n;if(e[r])return e[r];var i=new s(r);return i.loadFromFile("texture-vs.glsl",t+"-fs.glsl",n),i.positionSlot=i.getAttrib("aPosition"),i.texcoordSlot=i.getAttrib("aTexcoord"),i.unifDiffuse=i.getUniform("DiffuseMap"),i.unifViewProj=i.getUniform("matVP"),i.unifDiffuseColor=i.getUniform("diffuseColor"),i.unifEmissiveColor=i.getUniform("emissiveColor"),e[t]=i,i}}(),s.createMirrorShader=function(){var e;return function(){if(e)return e;var t=new s("mirror");return t.loadFromFile("mirror-vs.glsl","mirror-fs.glsl"),t.initCommon(),t.tangentSlot=t.getAttrib("aTangent"),t.unifReflectMat=t.getUniform("matViewProjReflect"),t.unifEyePos=t.getUniform("eyePos"),t.unifNormalMap=t.getUniform("NormalMap"),t.unifRefractMap=t.getUniform("RefractMap"),t.unifDetailNormalMap=t.getUniform("DetailNormalMap"),t.unifDetailMapParam=t.getUniform("detailParam"),t.setCommon=function(){gl.uniformMatrix4fv(t.unifViewProj,!1,engine.activeCamera.matViewProj),gl.uniform3fv(t.unifEyePos,engine.activeCamera.pos),gl.uniform1i(t.unifDiffuseMap,0),gl.uniform1i(t.unifNormalMap,1),gl.uniform1i(t.unifRefractMap,2),gl.uniform1i(t.unifDetailNormalMap,3)},t.setIndividual=function(e){gl.uniformMatrix4fv(t.unifWorld,!1,e.mat),gl.uniformMatrix4fv(t.unifReflectMat,!1,e.camera.matViewProj),e.mesh.vb.bindAttribute([t.posSlot,t.normalSlot,t.texcoordSlot]),gl.disableVertexAttribArray(t.tangentSlot),gl.vertexAttrib4f(t.tangentSlot,1,0,0,1),e.mesh.texture?e.mesh.texture.appear(0):i&&i.Manager.error.appear(0),e.mesh.normalmap.appear(1),e.mesh.textureRefract.appear(2),e.mesh.textureDetailNormal.appear(3);var n=engine.time%1e5*.001;gl.uniform3f(t.unifDetailMapParam,n*.01,n*.01,10)},e=t,t}}(),s}),define("engine/renderres/vertexbuffer",["./resman"],function(e){var t=function(){this.buffer=gl.createBuffer(),this.stride=0,this.usage=gl.STATIC_DRAW,this.desc=[],e.newResource(this)};return t.prototype.setData=function(e){this.data=e,gl.bindBuffer(gl.ARRAY_BUFFER,this.buffer),gl.bufferData(gl.ARRAY_BUFFER,e,this.usage)},t.prototype.setSubData=function(e,t){this.data=e,gl.bindBuffer(gl.ARRAY_BUFFER,this.buffer),gl.bufferSubData(gl.ARRAY_BUFFER,t,e)},t.prototype.onlost=function(){this.buffer=0},t.prototype.onrestore=function(){this.buffer=gl.createBuffer(),this.data&&(gl.bindBuffer(gl.ARRAY_BUFFER,this.buffer),gl.bufferData(gl.ARRAY_BUFFER,this.data,this.usage))},t.prototype.bindAttribute=function(e){gl.bindBuffer(gl.ARRAY_BUFFER,this.buffer);for(var t=0;t<this.desc.length;t++)e[t]>=0&&(gl.enableVertexAttribArray(e[t]),gl.vertexAttribPointer(e[t],this.desc[t].comps,this.desc[t].comptype,this.desc[t].norm==1,this.stride,this.desc[t].offsetByte))},t.prototype.release=function(){gl.deleteBuffer(this.buffer),e.freeResource(this)},t.createVec2VB=function(){var e=new t;return e.desc[0]={comps:2,comptype:gl.FLOAT,norm:!1,offsetByte:0},e.stride=2*Float32Array.BYTES_PER_ELEMENT,e},t.createVec3VB=function(){var e=new t;return e.desc[0]={comps:3,comptype:gl.FLOAT,norm:!1,offsetByte:0},e.stride=3*Float32Array.BYTES_PER_ELEMENT,e},t.createVec4VB=function(){var e=new t;return e.desc[0]={comps:4,comptype:gl.FLOAT,norm:!1,offsetByte:0},e.stride=4*Float32Array.BYTES_PER_ELEMENT,e},t.createColorVB=function(){var e=new t;return e.desc[0]={comps:4,comptype:gl.UNSIGNED_BYTE,norm:!0,offsetByte:0},e.stride=4*Uint8Array.BYTES_PER_ELEMENT,e},t.createByte2VB=function(){var e=new t;return e.desc[0]={comps:2,comptype:gl.UNSIGNED_BYTE,norm:!1,offsetByte:0},e.stride=2*Uint8Array.BYTES_PER_ELEMENT,e},t.createByte3VB=function(){var e=new t;return e.desc[0]={comps:3,comptype:gl.UNSIGNED_BYTE,norm:!1,offsetByte:0},e.stride=3*Uint8Array.BYTES_PER_ELEMENT,e},t.createByte4VB=function(){var e=new t;return e.desc[0]={comps:4,comptype:gl.UNSIGNED_BYTE,norm:!1,offsetByte:0},e.stride=4*Uint8Array.BYTES_PER_ELEMENT,e},t.createPosColorVB=function(){var e=new t;return e.stride=0,e.desc[0]={comps:3,comptype:gl.FLOAT,norm:!1,offsetByte:0},e.stride+=3*Float32Array.BYTES_PER_ELEMENT,e.desc[1]={comps:4,comptype:gl.UNSIGNED_BYTE,norm:!0,offsetByte:e.stride},e.stride+=4*Uint8Array.BYTES_PER_ELEMENT,e},t.createPosTexVB=function(){var e=new t;return e.stride=0,e.desc[0]={comps:3,comptype:gl.FLOAT,norm:!1,offsetByte:0},e.stride+=3*Float32Array.BYTES_PER_ELEMENT,e.desc[1]={comps:2,comptype:gl.FLOAT,norm:!1,offsetByte:e.stride},e.stride+=2*Float32Array.BYTES_PER_ELEMENT,e},t.createPosNormTexVB=function(){var e=new t;return e.stride=0,e.desc[0]={comps:3,comptype:gl.FLOAT,norm:!1,offsetByte:0},e.stride+=3*Float32Array.BYTES_PER_ELEMENT,e.desc[1]={comps:3,comptype:gl.FLOAT,norm:!1,offsetByte:e.stride},e.stride+=3*Float32Array.BYTES_PER_ELEMENT,e.desc[2]={comps:2,comptype:gl.FLOAT,norm:!1,offsetByte:e.stride},e.stride+=2*Float32Array.BYTES_PER_ELEMENT,e},t.createBlendWeightIndexVB=function(){var e=new t;return e.stride=0,e.desc[0]={comps:3,comptype:gl.FLOAT,norm:!1,offsetByte:0},e.stride+=3*Float32Array.BYTES_PER_ELEMENT,e.desc[1]={comps:4,comptype:gl.UNSIGNED_BYTE,norm:!1,offsetByte:e.stride},e.stride+=4*Uint8Array.BYTES_PER_ELEMENT,e},t}),define("engine/renderres/dynamicvb",[],function(){var e=function(e,t){this.vb=e,this.vb.usage=gl.DYNAMIC_DRAW,this.vertCount=0,this.vertMax=t,this.buf=new ArrayBuffer(this.vb.stride*t),this.vb.setData(this.buf),this.curOffset=-this.vb.stride};return e.prototype.begin=function(e){this.vertCount=0,this.curOffset=-this.vb.stride,this.callbackFlush=e},e.prototype.flush=function(){if(this.vertCount<=0)return;this.vb.setSubData(this.buf,0),this.callbackFlush&&this.callbackFlush(this),this.vertCount=0,this.curOffset=-this.vb.stride},e.prototype.addVertex=function(){this.vertCount>=this.vertMax&&this.flush(),this.vertCount++,this.curOffset+=this.vb.stride},e}),define("engine/core/simpledraw",["../renderres/shader","../renderres/vertexbuffer","../renderres/dynamicvb"],function(e,t,n){var r={},i=null,s,o,u,a,f,l,c;return r.init=function(r){i=r,s=e.createColorShader(),s.unifMat=s.getUniform("matVP"),s.attPosition=s.getAttrib("aPosition"),s.attColor=s.getAttrib("aColor"),o=new n(t.createPosColorVB(),1e3),o.pos=new Float32Array(o.buf),o.color=new Uint8Array(o.buf,12),u=new n(t.createPosColorVB(),1e3),u.pos=new Float32Array(u.buf),u.color=new Uint8Array(u.buf,12),a=new n(t.createPosColorVB(),960),a.pos=new Float32Array(a.buf),a.color=new Uint8Array(a.buf,12),f=new Uint8Array([255,255,255,255]),l=e.createTextureShader(),c=t.createPosTexVB(),c.setData(new Float32Array([-1,-1,0,0,0,-1,1,0,0,1,1,1,0,1,1,1,-1,0,1,0]))},r.beginDraw=function(){s.appear(),gl.uniformMatrix4fv(s.unifMat,!1,i.activeCamera.matViewProj);var e=[s.attPosition,s.attColor];u.begin(function(t){t.vb.bindAttribute(e),gl.drawArrays(gl.POINTS,0,t.vertCount),engine.statistics.drawCall++}),o.begin(function(t){t.vb.bindAttribute(e),gl.drawArrays(gl.LINES,0,t.vertCount),engine.statistics.drawCall++}),a.begin(function(t){t.vb.bindAttribute(e),gl.drawArrays(gl.TRIANGLES,0,t.vertCount),engine.statistics.drawCall++})},r.endDraw=function(){this.flush()},r.flush=function(){u.flush(),o.flush(),a.flush()},r.addVertex=function(e,t,n,r){e.addVertex();var i=e.curOffset/4,s=e.curOffset;e.pos[i+0]=t,e.pos[i+1]=n,e.pos[i+2]=r,e.color[s+0]=f[0],e.color[s+1]=f[1],e.color[s+2]=f[2],e.color[s+3]=f[3]},r.addPoint=function(e,t,n){this.addVertex(u,e,t,n)},r.addLine=function(e,t,n,r,i,s){this.addVertex(o,e,t,n),this.addVertex(o,r,i,s)},r.addTriangle=function(e,t,n,r,i){var s=e,o=t,u=n;i&&(s=vec3.create(),o=vec3.create(),u=vec3.create(),vec3.transformMat4(s,e,i),vec3.transformMat4(o,t,i),vec3.transformMat4(u,n,i)),r?(this.addLine(s[0],s[1],s[2],o[0],o[1],o[2]),this.addLine(o[0],o[1],o[2],u[0],u[1],u[2]),this.addLine(s[0],s[1],s[2],u[0],u[1],u[2])):(this.addVertex(a,s[0],s[1],s[2]),this.addVertex(a,o[0],o[1],o[2]),this.addVertex(a,u[0],u[1],u[2]))},r.addQuad=function(e,t,n,r,i,s){if(i){var o=e,u=t,a=n,f=r;s&&(o=vec3.create(),u=vec3.create(),a=vec3.create(),f=vec3.create(),vec3.transformMat4(o,e,s),vec3.transformMat4(u,t,s),vec3.transformMat4(a,n,s),vec3.transformMat4(f,r,s)),this.addLine(o[0],o[1],o[2],u[0],u[1],u[2]),this.addLine(u[0],u[1],u[2],a[0],a[1],a[2]),this.addLine(a[0],a[1],a[2],f[0],f[1],f[2]),this.addLine(f[0],f[1],f[2],o[0],o[1],o[2])}else this.addTriangle(e,t,n,i,s),this.addTriangle(e,n,r,i,s)},r.addAABB=function(e,t,n){var r=e.getCorners();if(n)for(var i=0;i<8;i++)vec3.transformMat4(r[i],r[i],n);this.addQuad(r[0],r[1],r[3],r[2],t),this.addQuad(r[4],r[5],r[7],r[6],t),this.addQuad(r[2],r[3],r[7],r[6],t),this.addQuad(r[0],r[1],r[5],r[4],t),this.addQuad(r[0],r[2],r[6],r[4],t),this.addQuad(r[1],r[3],r[7],r[5],t)},r.setColor=function(e,t,n,r){f[0]=e,f[1]=t,f[2]=n,f[3]=r},r.drawTexture=function(e,t,n,r,i,s,o){l.appear(),s=s||[1,1,1,1],o=o||[0,0,0,0],gl.uniform4fv(l.unifDiffuseColor,s),gl.uniform4fv(l.unifEmissiveColor,o),this.drawTextureWithShader(e,t,n,r,i,l)},r.drawTextureWithShader=function(e,t,n,r,i,s){var o=[r/gl.viewportWidth,0,0,0,0,-i/gl.viewportHeight,0,0,0,0,0,0,(t*2+r)/gl.viewportWidth-1,(-n*2-i)/gl.viewportHeight+1,0,1];gl.uniformMatrix4fv(s.unifViewProj,!1,o),gl.uniform1i(s.unifDiffuseMap,0),c.bindAttribute([s.positionSlot,s.texcoordSlot]),e.appear(0),gl.drawArrays(gl.TRIANGLE_FAN,0,4),engine.statistics.drawCall++},r}),define("engine/renderres/indexbuffer",["./resman"],function(e){var t=function(){this.buffer=gl.createBuffer(),e.newResource(this)};return t.prototype.setData=function(e){this.data=new Uint16Array(e),gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,this.buffer),gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,this.data,gl.STATIC_DRAW)},t.prototype.onlost=function(){this.buffer=0},t.prototype.onrestore=function(){this.buffer=gl.createBuffer(),this.data&&(gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,this.buffer),gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,this.data,gl.STATIC_DRAW))},t.prototype.appear=function(){gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,this.buffer)},t.prototype.release=function(){gl.deleteBuffer(this.buffer),e.freeResource(this)},t}),define("engine/model/shape",["../core/aabb","../common/utils","../common/config","../renderres/indexbuffer","../renderres/vertexbuffer"],function(e,t,n,r,i){var s=function(){this.numVert=0,this.numIndex=0,this.pos=[0,0,0],this.size=[1,1,1]};s.prototype.create=function(t,s){s||(s={}),s.pos==undefined&&(s.pos=[0,0,0]),s.size==undefined&&(s.size=[1,1,1]),s.texScale==undefined&&(s.texScale=[1,1]),vec3.copy(this.pos,s.pos),vec3.copy(this.size,s.size),this.ib=new r,this.ib.setData(t.indices),this.aabb=new e,this.vb=i.createPosNormTexVB();var o=new ArrayBuffer(this.vb.stride*this.numVert);for(var u=0;u<this.numVert;u++){var a=u*this.vb.stride,f=new Float32Array(o,a+0,3),l=new Float32Array(o,a+12,3),c=new Float32Array(o,a+24,2);f[0]=t.position[3*u+0]*s.size[0],f[1]=t.position[3*u+1]*s.size[1],f[2]=t.position[3*u+2]*s.size[2],l[0]=t.normal[3*u+0],l[1]=t.normal[3*u+1],l[2]=t.normal[3*u+2],f[0]+=s.pos[0],f[1]+=s.pos[1],f[2]+=s.pos[2],c[0]=t.texcoord[2*u+0]*s.texScale[0],c[1]=t.texcoord[2*u+1]*s.texScale[1],this.aabb.addVertex(f[0],f[1],f[2])}this.vb.setData(o);if(s.skin&&t.boneAssign){this.vbBoneWeights=i.createVec3VB();var h=[],p=new Uint8Array(4*this.numVert),d=new Float32Array(3*this.numVert);for(var u=0;u<this.numVert;u++)d[u*3+0]=0,d[u*3+1]=0,d[u*3+2]=0,p[u*4+0]=0,p[u*4+1]=0,p[u*4+2]=0,p[u*4+3]=0;var v=0;for(var u=0;u<t.boneAssign.length;u++){var m=t.boneAssign[u];h[m.boneIdx]=!0,v<m.boneIdx&&(v=m.boneIdx);var g=m.vertIdx,y=3;for(var b=0;b<3;b++)if(d[g*3+b]==0){y=b;break}y<3&&(d[g*3+y]=m.weight),p[g*4+y]=m.boneIdx}var w=[],E=[];for(var u=0;u<=v;u++)h[u]&&(w.push(u),E[u]=w.length-1);if(w.length<=n.maxBone){for(var u=0;u<this.numVert;u++){var S=E[p[u*4+0]]||0;p[u*4+0]=S,S=E[p[u*4+1]]||0,p[u*4+1]=S,S=E[p[u*4+2]]||0,p[u*4+2]=S,S=E[p[u*4+3]]||0,p[u*4+3]=S}var x={startIndex:0,numIndex:this.numIndex,boneIndexMap:w,boneIndices:p};this.submeshes=[x],x.vbBoneIndices=i.createByte4VB(),x.vbBoneIndices.setData(p)}else{var T=this.divideSubMesh(n.maxBone,t.indices,p,d);for(var u=0;u<T.length;u++){var x=T[u];x.vbBoneIndices=i.createByte4VB(),x.vbBoneIndices.setData(x.boneIndices)}this.submeshes=T,console.log("Shape : divided into "+this.submeshes.length+" parts")}this.vbBoneWeights.setData(d)}this.aabb.completeCenterExt()},s.prototype.rayTrace=function(e,t,n){return!1},s.prototype.divideSubMesh=function(e,t,n,r){var i=[],s=[],o=[],u=[],a=0,f=0,l=0,c=0,h=[],p=[],d=this.numVert,v=this.numIndex,m=function(e){for(var t=0;t<4;t++){var i=t<3?r[e*3+t]:1-r[e*3+0]-r[e*3+1]-r[e*3+2];if(i<1e-5)continue;var a=n[e*4+t];!s[a]&&!o[a]&&(f++,o[a]=!0,u.push(a))}},g=function(){if(l>=c)return;var e={startIndex:l*3,numIndex:(c-l)*3,boneIndexMap:h.slice(),boneIndices:new Uint8Array(d*4)};for(var t=0;t<d*4;t++){var r=p[n[t]];e.boneIndices[t]=r==undefined?0:r}i.push(e),s=[],a=0,l=c,h=[]};while(c<v/3){o=[],u=[],f=0,m(t[c*3]);if(f>e){g();continue}m(t[c*3+1]);if(f>e){g();continue}m(t[c*3+1]);if(f>e){g();continue}c++;for(var y=0;y<u.length;y++)s[u[y]]=!0,h.push(u[y]),p[u[y]]=h.length-1}return g(),i};var o=function(){s.apply(this),this.numVert=24,this.numIndex=36};extend(o,s),o.prototype.rayTrace=function(e,n,r){return t.rayTraceAABB(e,n,this.aabb.mins,this.aabb.maxs,r)},o.Data={position:[.5,.5,.5,.5,-0.5,.5,-0.5,-0.5,.5,-0.5,.5,.5,.5,.5,-0.5,-0.5,.5,-0.5,-0.5,-0.5,-0.5,.5,-0.5,-0.5,-0.5,.5,.5,-0.5,-0.5,.5,-0.5,-0.5,-0.5,-0.5,.5,-0.5,.5,.5,-0.5,.5,-0.5,-0.5,.5,-0.5,.5,.5,.5,.5,.5,.5,-0.5,.5,.5,.5,-0.5,.5,.5,-0.5,.5,-0.5,.5,-0.5,.5,.5,-0.5,-0.5,-0.5,-0.5,-0.5,-0.5,-0.5,.5],normal:[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,-1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0],texcoord:[1,1,1,0,0,0,0,1,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,0,1,1,0,1,0,0,1,1,1,0,0,0,0,1],indices:[0,2,1,0,3,2,4,6,5,4,7,6,8,10,9,8,11,10,12,14,13,12,15,14,16,18,17,16,19,18,20,22,21,20,23,22]};var u=function(){s.apply(this),this.numVert=4,this.numIndex=6};extend(u,s),u.prototype.rayTrace=function(e,t,n){if(Math.abs(t[2])<1e-6)return!1;var r=-(e[2]-this.pos[2])/t[2];if(r<0||n.maxt!=undefined&&n.maxt<r)return!1;var i=(e[0]-this.pos[0]+t[0]*r)/this.size[0],s=(e[1]-this.pos[1]+t[1]*r)/this.size[1];return i<.5&&i>-0.5&&s<.5&&s>-0.5?(n.t=r,n.normal=[0,0,1],!0):!1},u.Data={position:[-0.5,-0.5,0,.5,-0.5,0,.5,.5,0,-0.5,.5,0],normal:[0,0,1,0,0,1,0,0,1,0,0,1],texcoord:[1,0,0,0,0,1,1,1],indices:[0,1,2,0,2,3]};var a=function(){s.apply(this)};extend(a,s),a.prototype.create=function(e,t){t=t||{},this.radius=t.radius||1,s.prototype.create.call(this,e,t)},a.createData=function(e){var t={position:[],normal:[],texcoord:[],indices:[]};e=e||{};var n=e.radius||1,r=Math.max(3,Math.floor(e.widthSegments)||16),i=Math.max(2,Math.floor(e.heightSegments)||16),s=e.phiStart!==undefined?e.phiStart:0,o=e.phiLength!==undefined?e.phiLength:Math.PI*2,u=e.thetaStart!==undefined?e.thetaStart:0,a=e.thetaLength!==undefined?e.thetaLength:Math.PI,f=0;for(var l=0;l<=i;l++){var c=l/i,h=u+c*a;for(var p=0;p<=r;p++){var d;l==0?d=(p-.5)/r:l==i-1?d=(p-.5)/r:d=p/r;var v=s+d*o,m=Math.cos(v)*Math.sin(h),g=Math.cos(h),y=Math.sin(v)*Math.sin(h);t.position.push(n*m),t.position.push(n*g),t.position.push(n*y),t.normal.push(m),t.normal.push(g),t.normal.push(y),t.texcoord.push(d),t.texcoord.push(c),l>0&&p>0&&(t.indices.push(f-r-1),t.indices.push(f),t.indices.push(f-1),t.indices.push(f-r-1),t.indices.push(f-1),t.indices.push(f-r-2)),f++}}return t},a.prototype.rayTrace=function(e,n,r){return t.rayTraceSphere(e,n,this.pos,this.radius,r)};var f=function(e){s.apply(this),this.numVert=0,this.numIndex=0};return extend(f,s),{Cube:o,Plane:u,Sphere:a,Mesh:f,copyData:function(e,t){e.position=t.position.slice(),e.normal=t.normal.slice(),e.texcoord=t.texcoord.slice(),e.indices=t.indices.slice()}}}),define("engine/physics/physics",["../model/shape"],function(e){var t=function(e,t,n,r){this.transform=e,this.shape=t,this.mass=n,this.body=new CANNON.RigidBody(n,this.shape),r&&!vec3.isZero(r)&&(this.initPos=vec3.clone(r)),this.updateFromTransform()};t.prototype.updateFromTransform=function(){var e=this.transform.pos,t=this.transform.quat;this.initPos?this.body.position.set(e[0]+this.initPos[0],e[1]+this.initPos[1],e[2]+this.initPos[2]):this.body.position.set(e[0],e[1],e[2]),this.body.quaternion.set(t[0],t[1],t[2],t[3])},t.prototype.updateToTransform=function(){var e=[0,0,0];return function(){var e=this.transform.pos,t=this.transform.quat;t[0]=this.body.quaternion.x,t[1]=this.body.quaternion.y,t[2]=this.body.quaternion.z,t[3]=this.body.quaternion.w,e[0]=this.body.position.x,e[1]=this.body.position.y,e[2]=this.body.position.z,this.initPos&&vec3.sub(e,e,this.initPos)}}(),t.prototype.addCollideListener=function(e){this.body.addEventListener("collide",function(t){var n=s[t.with];e(n,t)})},t.prototype.setVelocity=function(e,t,n){this.body.velocity.set(e,this.body.velocity.y,n)};var n={enabled:!0,world:new CANNON.World},r=n.world;n.init=function(){r.gravity.set(0,-10,0),r.broadphase=new CANNON.NaiveBroadphase,r.solver.iterations=5,r.defaultContactMaterial.contactEquationStiffness=1e7,r.defaultContactMaterial.contactEquationRegularizationTime=2,r.broadphase.useBoundingBoxes=!0},n.createShapeForMesh=function(t){var n,r=[0,0,0];if(t instanceof e.Plane)n=new CANNON.Plane;else if(t instanceof e.Cube)n=new CANNON.Box(new CANNON.Vec3(t.size[0]*.5,t.size[1]*.5,t.size[2]*.5)),r=vec3.clone(t.pos);else if(t instanceof e.Sphere)n=new CANNON.Sphere(t.radius),r=vec3.clone(t.pos);else{var i=vec3.length(t.aabb.extend)*.5;n=new CANNON.Sphere(i),r=vec3.clone(t.aabb.center)}return{shape:n,initPos:r}},n.createShapeForModel=function(e){var t=e.meshes;if(t.length==0)return null;if(t.length==1)return n.createShapeForMesh(t[0]);var r=new CANNON.Compound,i=1.5;for(var s=0;s<t.length;s++){var o=n.createShapeForMesh(t[s]);if(!o.shape)continue;r.addChild(o.shape,new CANNON.Vec3(o.initPos[0],o.initPos[1],o.initPos[2]))}return{shape:r}};var i=[],s={};return n.addPhysics=function(e,n){var o=this.createShapeForModel(e.model);if(!o)return null;var u=new t(e.transform,o.shape,n,o.initPos);return r.add(u.body),i.push(u),s[u.body]=e,e.phyObj=u,u},n.updateFrequency=30,n.update=function(){var e=0;return function(t){if(!this.enabled)return;var n=1e3/this.updateFrequency;e+=t;var s=Math.ceil(e/n),o;for(o=0;o<s;o++)r.step(n*.001);e-=s*n;var u=i.length;for(o=0;o<u;o++)i[o].mass>0&&(i[o].updateToTransform(),i[o].transform.updateMatrix())}}(),n}),define("engine/input/keyboard",[],function(){var e={KeyCodes:{BackSpace:8,Tab:9,Enter:13,Shift:16,Ctrl:17,Alt:18,Pause:19,CapsLock:20,Escape:27,Space:32,PageUp:33,PageDown:34,End:35,Home:36,Left:37,Up:38,Right:39,Down:40,Insert:45,Delete:46,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,LeftWin:91,RightWin:92,Select:93,Numpad0:96,Numpad1:97,Numpad2:98,Numpad3:99,Numpad4:100,Numpad5:101,Numpad6:102,Numpad7:103,Numpad8:104,Numpad9:105,NumpadMultiply:106,NumpadAdd:107,NumpadSubtract:109,NumpadDot:110,NumpadDivide:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,NumLock:144,ScrollLock:145,SemiColon:186,EqualSign:187,Comma:188,Dash:189,Period:190,ForwardSlash:191,GraveAccent:192,OpenBracket:219,BackSlash:220,CloseBraket:221,SinglEquote:222},KeyNames:[],keyPressed:[],keyJustPressed:[],keyJustReleased:[],init:function(){for(var t in this.KeyCodes)this.KeyCodes.hasOwnProperty(t)&&(this.KeyNames[this.KeyCodes[t]]=t);document.onkeydown=function(t){t=t||window.event;var n=t.which||t.keyCode;e.onKeyDown(n,t)},document.onkeyup=function(t){t=t||window.event;var n=t.which||t.keyCode;e.onKeyUp(n,t)}},reset:function(){this.keyPressed.length=0,this.keyJustPressed.length=0,this.keyJustReleased.length=0},beginFrame:function(){},endFrame:function(){this.keyJustPressed.length=0,this.keyJustReleased.length=0},onKeyDown:function(e){this.keyPressed[e]||(this.keyJustPressed[e]=!0),this.keyPressed[e]=!0},onKeyUp:function(e){this.keyPressed[e]&&(this.keyJustReleased[e]=!0),this.keyPressed[e]=!1},isKeyPressed:function(e){return typeof e=="string"&&(e=this.KeyCodes[e]),e?this.keyPressed[e]:!1},isKeyJustPressed:function(e){return typeof e=="string"&&(e=this.KeyCodes[e]),e?this.keyJustPressed[e]:!1},isKeyJustReleased:function(e){return typeof e=="string"&&(e=this.KeyCodes[e]),e?this.keyJustReleased[e]:!1}};return e}),define("engine/particle/particlerender",["../renderres/vertexbuffer","../renderres/shader"],function(e,t){var n={},r=0,i=[],s={},o,u,a,f,l,c=!1,h=[];return n.init=function(n){r=n,i=[],s={},o=new Float32Array(r*4),a=e.createVec4VB(),a.usage=gl.DYNAMIC_DRAW,a.setData(o),u=new Uint8Array(r*4),f=e.createColorVB(),f.usage=gl.DYNAMIC_DRAW,f.setData(u),l=new t,l.loadFromFile("particle-vs.glsl","particle-fs.glsl"),l.initCommon(),l.unifSizeScale=l.getUniform("sizeScale")},n.add=function(e){var t=s[e.materialTag];t||(t=s[e.materialTag]=[]),t.push(e),i.push(e)},n.clear=function(){s={},i.length=0},n.remove=function(e){var t=i.indexOf(e);t>=0&&(c?h.push(t):i.splice(t,1));var n=s[e.materialTag];if(!n)return;t=n.indexOf(e),t>=0&&n.splice(t,1)},n.update=function(e){var t=e*.001;c=!0;for(var n=0,r=i.length;n<r;n++){var s=i[n];s.update(t)}if(h.length>0){h.sort();for(var o=0;o<h.length;o++)i.splice(h[o]-o,1);h.length=0}c=!1},n.render=function(){if(i.length==0)return;l.appear(),gl.uniformMatrix4fv(l.unifViewProj,!1,engine.activeCamera.matViewProj);var e=engine.activeCamera.matProj[5]*gl.viewportHeight;gl.uniform1f(l.unifSizeScale,e),gl.uniform1i(l.unifDiffuseMap,0),gl.depthMask(!1),gl.disable(gl.CULL_FACE),gl.disable(gl.DEPTH_TEST),gl.enable(gl.BLEND),a.bindAttribute([l.posSlot]),f.bindAttribute([l.colorSlot]);var t=function(e){a.setSubData(o,0),f.setSubData(u,0),gl.drawArrays(gl.POINTS,0,e)};for(var n in s){var c=s[n],h=0,p=0;for(var d=0,v=c.length;d<v;d++){var m=c[d];d==0&&(m.texture.appear(0),m.testZ?gl.enable(gl.DEPTH_TEST):gl.disable(gl.DEPTH_TEST),gl.blendFunc(m.srcBlend,m.dstBlend));for(var g=0,y=m.activeList.length;g<y;g++){var b=m.activeList[g];o[h++]=b.pos[0],o[h++]=b.pos[1],o[h++]=b.pos[2],o[h++]=b.scale,u[p++]=b.color[0],u[p++]=b.color[1],u[p++]=b.color[2],u[p++]=b.color[3],h>=r-4&&(t(h/4),h=0,p=0)}}h>0&&(t(h/4),h=0,p=0)}gl.depthMask(!0),gl.enable(gl.DEPTH_TEST),gl.disable(gl.CULL_FACE),gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA)},n}),define("engine/core/engine",["../renderres/resman","../renderres/texture","./simpledraw","../physics/physics","../input/keyboard","../particle/particlerender"],function(e,t,n,r,i,s){var o=new function(){this.time=undefined,this.frameCount=0,this.frameCountFPS=0,this.FPSTime=0,this.FPS=60,this.deltaTime=0,this.paused=!1,this.activeCamera=null,this.statistics={drawCall:0,triangles:0,meshes:0}},u={},a,f=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||window.oRequestAnimationFrame||function(e){setTimeout(e,1e3/60)},l=function(e){try{var t={antialias:!0,stencil:!0,premultipliedAlpha:!1,alpha:!1};o.gl=e.getContext("webgl",t)||e.getContext("experimental-webgl",t)}catch(n){}o.gl?o.contextAttribute=o.gl.getContextAttributes():alert("Could not initialise WebGL, sorry :-(")};o.init=function(e){var f=document.getElementById(e);l(f),u.dom=f,u.width=parseInt(f.getAttribute("width")),u.height=parseInt(f.getAttribute("height")),o.gl.viewportWidth=u.width,o.gl.viewportHeight=u.height,window.canvas=u,window.gl=a=o.gl,window.engine=o,a.viewport(0,0,a.viewportWidth,a.viewportHeight),f.addEventListener("webglcontextlost",o.onCanvasLost),f.addEventListener("webglcontextrestored",o.onCanvasRestore),u.dom.oncontextmenu=function(){return!1},o.modelRenderList=new o.RenderList,t.Manager.init(),n.init(this),i.init(),r.init(),s.init(1e3)};var c={};return o.beginStat=function(e){var t=c[e];t?t.begin=Date.now():c[e]={begin:Date.now(),time:0}},o.endStat=function(e){var t=c[e];t.time+=Date.now()-t.begin},o.getStat=function(e){var t=c[e];return t?t.time:0},o.clearStat=function(){c={}},o.mainLoop=function(){f(o.mainLoop);var e=Date.now();o.time=o.time||Date.now(),o.deltaTime=e-o.time,o.deltaTime>500&&(o.deltaTime=500),o.FPSTime+=o.deltaTime,o.FPSTime>1e3&&(o.FPSTime-=1e3,o.FPS=o.frameCountFPS,o.frameCountFPS=0),o.time=e,i.beginFrame();if(o.paused)return;o.renderCallback&&o.renderCallback(o.deltaTime),i.endFrame(),o.frameCountFPS++,o.frameCount++},o.update=function(e){s.update(e),r.update(e)},o.onCanvasLost=function(e){e.preventDefault()},o.onCanvasRestore=function(e){},o.beforeRender=function(){o.modelRenderList.reset(),this.statistics.drawCall=0,this.statistics.meshes=0,this.statistics.triangles=0},o.renderParticles=function(){s.render()},o.renderList=function(){o.modelRenderList.render(),a.flush()},o.RenderList=function(){this.list=[],this.sortByShader={}},o.RenderList.Item=function(e,t,n){return{mesh:e,mat:t,material:n,aabb:e.aabb.transformAABB(t)}},o.RenderList.prototype.reset=function(){this.list.length=0,this.sortByShader={}},o.RenderList.prototype.add=function(e){if(!e.material||!e.material.shader)return;this.list.push(e);var t=e.material.shader,n=t.resid;this.sortByShader[n]?this.sortByShader[n].push(e):this.sortByShader[n]=[e]},o.RenderList.prototype.render=function(){for(var t in this.sortByShader){if(!this.sortByShader.hasOwnProperty(t))continue;var n=this.sortByShader[t],r=e.getResourceById(t);r.appear(),r.setCommon();var i=n.length;for(var s=0;s<i;s++){var u=n[s];if(!o.activeCamera.isAABBVisible(u.aabb))continue;r.setIndividual(u),u.mesh.ib.appear(),engine.statistics.triangles+=u.mesh.numIndex/3;if(u.submeshes)for(var f=0,l=u.submeshes.length;f<l;f++){var c=u.submeshes[f];r.setPass(u,f),a.drawElements(a.TRIANGLES,c.numIndex,a.UNSIGNED_SHORT,c.startIndex)}else a.drawElements(a.TRIANGLES,u.mesh.numIndex,a.UNSIGNED_SHORT,0);engine.statistics.drawCall++,engine.statistics.meshes++}}},o}),define("engine/file/ajaxfile",["../common/domutils"],function(e){var t=function(){};return t.loadXMLDoc=function(t,n){var r=e.createXmlHttp();return r.open("GET",t,n),r.send(),r.responseXML},t.loadTextFile=function(t,n){var r=e.createXmlHttp();return r.open("GET",t,n),r.send(),r.responseText},t.sendTextToServer=function(t,n){var r=e.createXmlHttp();return r.open("POST",t,!1),r.send(n),r.status==200},t.sendBinaryToServer=function(t,n){var r=e.createXmlHttp();return r.open("POST",t,!1),r.send(n),r.status==200},t}),define("engine/model/model",["../core/aabb","../file/modelloaderxml","./shape"],function(e,t,n){var r=function(){};return r.prototype.init=function(){this.meshes=[],this.aabb=new e,this.ready=!1},r.prototype.load=function(e,t,r){this.modelData=t.loadMesh(e);if(!this.modelData){alert("load model error!");return}for(var i=0;i<this.modelData.meshes.length;i++)this.modelData.meshes[i].opts=r||{},this.modelData.meshes[i].creator=n.Mesh;this.ready=!0,this.recreate()},r.prototype.addCube=function(e){this.modelData=this.modelData||{meshes:[]};var t={};n.copyData(t,n.Cube.Data),t.opts=e||{},t.creator=n.Cube,this.modelData.meshes.push(t)},r.prototype.addPlane=function(e){this.modelData=this.modelData||{meshes:[]};var t={};n.copyData(t,n.Plane.Data),t.opts=e||{},t.creator=n.Plane,this.modelData.meshes.push(t)},r.prototype.addSphere=function(e){this.modelData=this.modelData||{meshes:[]};var t=n.Sphere.createData(e);t.opts=e||{},t.creator=n.Sphere,this.modelData.meshes.push(t)},r.prototype.recreate=function(){if(!this.ready)return!1;this.aabb.clear();for(var e=0;e<this.modelData.meshes.length;e++){var t=this.modelData.meshes[e],n=new t.creator;n.numVert=t.position.length/3,n.numIndex=t.indices.length,n.create(t,t.opts),n.texture=t.opts.texture||t.texture,this.meshes.push(n),this.aabb.mergeAABB(n.aabb)}return!0},r}),define("engine/animation/bone",[],function(){var e=function(e,t){this.name=e,this.index=t,this.firstChild=null,this.sibling=null,this.parent=null,this.orgPos=vec3.create(),this.orgQuat=quat.create(),this.pos=vec3.create(),this.quat=quat.create(),this.derivedPos=vec3.create(),this.derivedQuat=quat.create(),this.mat=mat4.create(),this.matRelative=mat4.create(),this.matInit=mat4.create(),this.matInitInv=mat4.create()};return e.prototype.clone=function(){var t=new e(this.name,this.index);return vec3.copy(t.orgPos,this.orgPos),vec3.copy(t.pos,this.pos),vec3.copy(t.derivedPos,this.derivedPos),quat.copy(t.orgQuat,this.orgQuat),quat.copy(t.quat,this.quat),quat.copy(t.derivedQuat,this.derivedQuat),mat4.copy(t.matInitInv,this.matInitInv),mat4.copy(t.matInit,this.matInit),mat4.copy(t.mat,this.mat),mat4.copy(t.matRelative,this.matRelative),t},e.prototype.addSibling=function(e){this.sibling?this.sibling.addSibling(e):this.sibling=e},e.prototype.addChild=function(e){this.firstChild?this.firstChild.addSibling(e):this.firstChild=e,e.parent=this},e.prototype.update=function(e){this.parent?(quat.mul(this.derivedQuat,this.parent.derivedQuat,this.quat),vec3.transformQuat(this.derivedPos,this.pos,this.parent.derivedQuat),vec3.add(this.derivedPos,this.derivedPos,this.parent.derivedPos)):(quat.copy(this.derivedQuat,this.quat),vec3.copy(this.derivedPos,this.pos)),e&&(this.firstChild&&this.firstChild.update(e),this.sibling&&this.sibling.update(e))},e}),define("engine/animation/animationclip",[],function(){var e=function(e,n,r,i){this.anim=e,this.skel=e.skel,this.start=n,this.end=r,this.loop=i,this.state=t.NONE,this.weight=1,this.time=0,this.fadeOutDuration=0,this.fadeInDuration=0,this.fadeTime=0,this.trackCache=new Array(e.tracks.length);for(var s=0;s<this.trackCache.length;s++)this.trackCache[s]={startKey:{time:0},endKey:{time:-1},period:1}},t={NONE:0,RUNNING:1,STOPPED:2,FADEIN:3,FADEOUT:4};return e.prototype.isPlaying=function(){return this.state==t.RUNNING||this.state==t.FADEIN||this.state==t.FADEOUT},e.prototype.updateFade=function(e){var n=1;return this.state==t.FADEIN&&(this.fadeTime+=e,this.fadeTime>=this.fadeInDuration?(this.fadeTime=this.fadeInDuration,this.state=t.RUNNING):this.fadeInDuration>0&&(n=this.fadeTime/this.fadeInDuration)),this.state==t.FADEOUT?(this.fadeTime+=e,this.fadeTime>=this.fadeOutDuration?(this.fadeTime=this.fadeOutDuration,this.state=t.STOPPED,n=0):this.fadeOutDuration>0&&(n=1-this.fadeTime/this.fadeOutDuration)):!this.loop&&this.fadeOutDuration>0&&this.time+this.fadeOutDuration>=this.end-this.start&&(this.state=t.FADEOUT,this.fadeTime=(1-n)*this.fadeOutDuration),n},e.prototype.update=function(e){var n=this.isPlaying();if(n){this.time+=e;var r=this.time+this.start,i=this.weight;i*=this.updateFade(e);if(i>0){var s=this.anim.tracks,o=this.skel.bones;for(var u=0,a=s.length;u<a;u++){var f=s[u];if(!f)continue;var l=f.getInterplatedKey(r,this.loop,this.trackCache[u]),c=o[u];i<1?(vec3.lerp(c.pos,c.pos,l.pos,i),quat.slerp(c.quat,c.quat,l.quat,i),quat.normalize(c.quat,c.quat)):(vec3.copy(c.pos,l.pos),quat.copy(c.quat,l.quat))}}!this.loop&&this.time>=this.end&&(this.state=t.STOPPED)}},e.prototype.play=function(){this.state=t.RUNNING,this.time=0},e.prototype.pause=function(){this.state=t.NONE},e.prototype.stop=function(){this.state=t.STOPPED},e.prototype.fadeOut=function(e){this.state=t.FADEOUT,this.fadeTime=0,this.fadeOutDuration=e},e.prototype.fadeIn=function(e){return!e||e<=0?this.play():(this.state=t.FADEIN,this.fadeTime=0,this.fadeInDuration=e,null)},e.State=t,e}),define("engine/animation/skeleton",["./bone","./animationclip"],function(e,t){var n=function(){this.bones=[],this.boneMap=[],this.rootBones=[],this.animMap={},this.animChannels=[],this.setChannelNum(1)};return n.prototype.clone=function(){var e=new n,t,r,i=this.bones.length;for(t=0;t<i;t++)r=this.bones[t].clone(),e.bones.push(r),e.boneMap[r.name]=r;for(t=0;t<i;t++)r=this.bones[t],r.parent&&(e.bones[t].parent=e.bones[r.parent.index]),r.firstChild&&(e.bones[t].firstChild=e.bones[r.firstChild.index]),r.sibling&&(e.bones[t].sibling=e.bones[r.sibling.index]);for(var s in this.animMap)this.animMap.hasOwnProperty(s)&&(e.animMap[s]=this.animMap[s]);return e.setChannelNum(this.animChannels.length),e.reset(),e},n.prototype.addBone=function(t){var n=this.bones.length,r=new e(t,n);return this.bones.push(r),this.boneMap[t]=r,r},n.prototype.setChannelNum=function(e){this.animChannels.length=e;for(var t=0;t<e;t++)this.animChannels[t]=[]},n.prototype.addAnimation=function(e,t){this.animMap[e]=t},n.prototype.setHierarchy=function(e,t){var n=this.boneMap[e],r=this.boneMap[t];if(!n||!r)return;n.addChild(r)},n.prototype.initBoneMat=function(){var e,t;for(e=0;e<this.rootBones.length;e++)t=this.rootBones[e],t.update(!0);for(e=0;e<this.bones.length;e++)t=this.bones[e],mat4.fromRotationTranslation(t.matInit,t.derivedQuat,t.derivedPos),mat4.invert(t.matInitInv,t.matInit)},n.prototype.update=function(){var e=quat.create(),t=vec3.create();return function(e){var t,n;this.updateAnimation(e);var r=this.rootBones.length;for(t=0;t<r;t++)n=this.rootBones[t],n.update(!0);var i=this.bones.length;for(t=0;t<i;t++)n=this.bones[t],mat4.fromRotationTranslation(n.mat,n.derivedQuat,n.derivedPos),mat4.multiply4x3(n.matRelative,n.mat,n.matInitInv)}}(),n.prototype.reset=function(){this.rootBones.length=0;for(var e=0;e<this.bones.length;e++){var t=this.bones[e];vec3.copy(t.pos,t.orgPos),quat.copy(t.quat,t.orgQuat),t.parent||this.rootBones.push(t)}for(var n=0;n<this.animChannels.length;n++)this.animChannels[n].length=0;this.initBoneMat()},n.prototype.outputBones=function(){for(var e=0;e<this.rootBones.length;e++){var t=this.bones[e];this.outputBoneTree(t,"")}},n.prototype.outputBoneTree=function(e,t){console.log(t+e.name),e.firstChild&&this.outputBoneTree(e.firstChild,t+" "),e.sibling&&this.outputBoneTree(e.sibling,t)},n.prototype.drawBones=function(){SimpleDraw.setColor(255,255,255,255);var e=mat4.create(),t=new AABB;t.mins=[-0.05,-0.05,-0.05],t.maxs=[.05,.05,.05];for(var n=0;n<this.bones.length;n++){var r=this.bones[n],i=r.derivedPos;mat4.fromRotationTranslation(e,r.derivedQuat,i),SimpleDraw.addAABB(t,!0,r.mat);if(r.parent){var s=r.parent.derivedPos;SimpleDraw.addLine(i[0],i[1],i[2],s[0],s[1],s[2])}}},n.prototype.updateAnimation=function(e){for(var n=0;n<this.animChannels.length;n++){var r=this.animChannels[n];for(var i=0;i<r.length;i++){var s=r[i];if(s.state==t.State.STOPPED){r.splice(i,1),i--;continue}s.update(e)}}},n.prototype.playAnimationClip=function(e,n,r){r=r||{};var i=this.animMap[n];if(!i)return null;var s=i.createClip(r.start,r.end,r.loop);s.skel=this,s.channel=e,r.weight&&(s.weight=r.weight),!r.loop&&r.autofadeout&&(s.fadeOutDuration=r.autofadeout);var o=this.animChannels[e];if(r.exclusive){if(r.trans)for(var u=0;u<o.length;u++)o[u].fadeOut(r.trans);else for(var u=0;u<o.length;u++)o[u].state=t.State.STOPPED;o.unshift(s),s.play()}else o.push(s),s.fadeIn(r.trans);return s},n}),define("engine/animation/skelanim",["./animationclip"],function(e){var t=function(){this.keys=[],this.time=.01,this.startTime=0,this.endTime=this.startTime,this.boneName="",this.orgPos=vec3.create(),this.orgQuat=quat.create()};t.prototype.addKey=function(e,t,n){var r={time:e,pos:vec3.create(),quat:quat.create()};vec3.add(r.pos,this.orgPos,t),quat.mul(r.quat,this.orgQuat,n),this.keys.length==0&&(this.startTime=e),this.keys.push(r),this.endTime=e},t.prototype.getInterplatedKey=function(){var e={time:0,pos:[0,0,0],quat:[0,0,0,1]},t={time:0,pos:[0,0,0],quat:[0,0,0,1]},n=function(e,t,n,r){var i=1-r;e.pos[0]=t.pos[0]*i+n.pos[0]*r,e.pos[1]=t.pos[1]*i+n.pos[1]*r,e.pos[2]=t.pos[2]*i+n.pos[2]*r,quat.lerp(e.quat,t.quat,n.quat,r)};return function(r,i,s){var o=r;if(this.keys.length==0)return e;if(this.keys.length==1)return this.keys[0];var u=1;i&&(o-=Math.floor(o/this.time)*this.time);if(o>=s.startKey.time&&o<=s.endKey.time)return u=s.period>0?(o-s.startKey.time)/s.period:1,n(t,s.startKey,s.endKey,u),t;if(o<=this.startTime)return this.keys[0];if(o>=this.endTime)return this.keys[this.keys.length-1];for(var a=1,f=this.keys.length;a<f;a++){var l=this.keys[a];if(l.time>o){s.startKey=this.keys[a-1],s.endKey=l,s.period=s.endKey.time-s.startKey.time,s.period>0&&(u=(o-s.startKey.time)/s.period);break}}return n(t,s.startKey,s.endKey,u),t}}();var n=function(e){this.time=0,this.tracks=new Array(e.bones.length),this.skel=e};return n.prototype.addTrack=function(e){var t=this.skel.boneMap[e.boneName];if(!t)return;var n=t.index;this.tracks[n]=e},n.prototype.createClip=function(t,n,r){return t=t||0,n=n||this.time,r=r||!1,new e(this,t,n,r)},n.Track=t,n}),define("engine/file/modelloaderxml",["./textfilemanager","../model/model","../animation/skeleton","../animation/skelanim","../common/config","../renderres/texture"],function(e,t,n,r,i,s){var o=new function(){var t=function(e,t){e||alert("null node");var n=e.attributes.getNamedItem(t);return n?n.value:n},o=function(e,t){var n=[],r=e.childNodes;for(var i=0;i<r.length;i++)r[i].nodeName==t&&n.push(r[i]);return n};this.loadMesh=function(n){var r=e.loadXML(n);if(!r)return console.log("Can not load model xml: "+n),null;var l=r.documentElement;if(l.nodeName!="mesh")return console.log("Can not find <mesh> tag in model xml: "+n),null;var c=o(l,"sharedgeometry"),h={position:[],normal:[],texcoord:[]};if(typeof c=="object"){var p=c[0];p&&a(p,h)}var d=o(l,"boneassignments");if(typeof d=="object"){var v=d[0];p&&f(v,h)}var m=o(l,"submeshes")[0];if(!m)return console.log("Can not find <submeshes> tag in model xml: "+n),null;var g={meshes:[]},y=o(m,"submesh");for(var b=0;b<y.length;b++){var w={position:h.position,normal:h.normal,texcoord:h.texcoord,boneAssign:h.boneAssign},E=y[b],S=t(E,"texture");S?w.texture=s.Manager.loadTexture(i.texturePath+S):w.texture=s.Manager.error;for(var x=0;x<E.childNodes.length;x++){var T=E.childNodes[x];T.nodeName=="faces"?u(T,w):T.nodeName=="geometry"?a(T,w):T.nodeName=="boneassignments"&&f(T,w)}w.indices&&w.position&&g.meshes.push(w)}return g};var u=function(e,t){var n=e.attributes.getNamedItem("count"),r=parseInt(n.value);t.indices=new Uint16Array(r*3);var i=o(e,"face");for(var s=0;s<i.length;s++){var u=i[s],a=u.attributes.getNamedItem("v1"),f=parseInt(a.value);a=u.attributes.getNamedItem("v2");var l=parseInt(a.value);a=u.attributes.getNamedItem("v3");var c=parseInt(a.value);t.indices[s*3+0]=f,t.indices[s*3+1]=l,t.indices[s*3+2]=c}},a=function(e,n){var r=e.attributes.getNamedItem("vertexcount"),i=parseInt(r.value);n.position=new Float32Array(i*3),n.normal=new Float32Array(i*3),n.texcoord=new Float32Array(i*2);var s=o(e,"vertexbuffer");for(var u=0;u<s.length;u++){var a=s[u],f=o(a,"vertex");for(var l=0;l<f.length;l++){var c=f[l];for(var h=0;h<c.childNodes.length;h++){var p=c.childNodes[h];if(p.nodeType!=1)continue;if(p.nodeName=="position"){var d=parseFloat(t(p,"x")),v=parseFloat(t(p,"y")),m=parseFloat(t(p,"z"));n.position[l*3+0]=d,n.position[l*3+1]=v,n.position[l*3+2]=m}else if(p.nodeName=="normal"){var d=parseFloat(t(p,"x")),v=parseFloat(t(p,"y")),m=parseFloat(t(p,"z"));n.normal[l*3+0]=d,n.normal[l*3+1]=v,n.normal[l*3+2]=m}else if(p.nodeName=="texcoord"){var g=parseFloat(t(p,"u")),y=parseFloat(t(p,"v"));n.texcoord[l*2+0]=g,n.texcoord[l*2+1]=y}}}}},f=function(e,n){var r=o(e,"vertexboneassignment");n.boneAssign=n.boneAssign||[];for(var i=0;i<r.length;i++){var s=r[i],u={vertIdx:parseInt(t(s,"vertexindex")),boneIdx:parseInt(t(s,"boneindex")),weight:parseFloat(t(s,"weight"))};n.boneAssign.push(u)}},l=function(e,n){e[0]=parseFloat(t(n,"x")),e[1]=parseFloat(t(n,"y")),e[2]=parseFloat(t(n,"z"))},c=function(e,n){var r=parseFloat(t(n,"angle")),i=o(n,"axis")[0];if(!i){console.log("Can not find <axis> tag in model xml: ");return}var s=[1,0,0];l(s,i),quat.setAxisAngle(e,s,r)};this.loadSkeleton=function(r){var i;typeof r=="string"?i=e.loadXML(r):i=r;if(!i)return console.log("Can not load skeleton xml: "+r),null;var s=i.documentElement;if(s.nodeName!="skeleton")return console.log("Can not find <skeleton> tag in model xml: "+r),null;var u=o(s,"bones")[0],a=new n;if(!u)return console.log("empty skelton in xml: "+r),a;var f=o(u,"bone");for(var h=0;h<f.length;h++){var p=f[h],d=t(p,"name"),v=a.addBone(d),m=o(p,"position")[0];if(!m)return console.log("Can not find <position> tag in model xml: "+r),null;l(v.orgPos,m);var g=o(p,"rotation")[0];if(!g)return console.log("Can not find <rotation> tag in model xml: "+r),null;c(v.orgQuat,g)}var y=o(s,"bonehierarchy")[0];if(!y)return console.log("empty skelton in xml: "+r),a;var b=o(y,"boneparent");for(var w=0;w<b.length;w++){var E=b[w],S=t(E,"parent"),x=t(E,"bone");a.setHierarchy(S,x)}return a.reset(),a.update(),a},this.loadAnimation=function(n,i){var s=e.loadXML(n);if(!s)return console.log("Can not load skeleton xml: "+n),null;var u=this.loadSkeleton(s),a=s.documentElement;if(a.nodeName!="skeleton")return console.log("Can not find <skeleton> tag in model xml: "+n),null;var f=o(a,"animations")[0],l=[];if(!f)return console.log("empty animation in xml: "+n),l;var c=o(f,"animation");for(var p=0;p<c.length;p++){var d=c[p],v=t(d,"name"),m=parseFloat(t(d,"length")),g=new r(i);g.name=v,g.time=m*1e3;var y=o(d,"tracks")[0];y&&(h(y,g,u),l.push(g))}return l};var h=function(e,n,i){var s=o(e,"track");for(var u=0;u<s.length;u++){var a=s[u],f=t(a,"bone"),l=new r.Track;l.boneName=f,l.time=n.time;var c=i.boneMap[f];c&&(vec3.copy(l.orgPos,c.orgPos),quat.copy(l.orgQuat,c.orgQuat));var h=o(a,"keyframes")[0];h&&p(h,l),n.addTrack(l)}for(var u=0;u<n.tracks.length;u++)if(!n.tracks[u]){var l=new r.Track,c=i.bones[u];l.boneName=c.name,l.time=n.time,l.addKey(0,c.orgPos,c.orgQuat),n.tracks[u]=l}},p=function(e,n){var r=o(e,"keyframe");for(var i=0;i<r.length;i++){var s=r[i],u=parseFloat(t(s,"time")),a=o(s,"translate")[0];if(!a){console.log("Can not find <translate> tag in model xml: ");return}var f=[0,0,0];l(f,a);var h=o(s,"rotate")[0];if(!h){console.log("Can not find <rotate> tag in model xml: ");return}var p=[0,0,0,1];c(p,h),n.addKey(u*1e3,f,p)}}};return o}),define("engine/input/canvasevent",["../common/config","../common/domutils"],function(e,t){return{bindCanvasEvent:function(n,r){var i=function(e){var t=e.target,n=t.getBoundingClientRect();return{x:(e.clientX-n.left)*(t.width/n.width),y:(e.clientY-n.top)*(t.height/n.height)}};e.isiOS?(n.addEventListener("touchstart",function(e){var t=e.touches[0];if(!t)return;t.button=0;var n=i(t);r.onMouseDown&&r.onMouseDown(n,t),e.preventDefault()}),n.addEventListener("touchmove",function(e){var t=e.touches[0];if(!t)return;t.button=0;var n=i(t);r.onMouseMove&&r.onMouseMove(n,t),e.preventDefault()}),n.addEventListener("touchend",function(e){var t=e.changedTouches[0];if(!t)return;t.button=0;var n=i(t);r.onMouseUp&&r.onMouseUp(n,t),e.preventDefault()})):(n.addEventListener("mousemove",function(e){e=e||window.event;var n=t.mousePosFromEvent(e);r.onMouseMove&&r.onMouseMove(n,e)}),n.addEventListener("mousedown",function(e){e=e||window.event;var n=t.mousePosFromEvent(e);r.onMouseDown&&r.onMouseDown(n,e)}),n.addEventListener("mouseup",function(e){e=e||window.event;var n=t.mousePosFromEvent(e);r.onMouseUp&&r.onMouseUp(n,e)}),t.setWheelEvent(n,function(e,t,n){r.onMouseWheel(e,t,n)}))}}}),define("engine/renderres/Texture",["./resman"],function(e){var t=function(){this.texture=gl.createTexture(),this.image=null,this.dataInfo=null,this.flipY=!1,this.width=0,this.height=0,this.magFilter=gl.LINEAR,this.minFilter=gl.LINEAR_MIPMAP_LINEAR,this.wrapS=gl.REPEAT,this.wrapT=gl.REPEAT,this.mipmap=!0,this.loaded=!1,this.width=0,this.height=0,e.newResource(this)};t.prototype.recreate=function(){gl.bindTexture(gl.TEXTURE_2D,this.texture),gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL,this.flipY),this.image?(gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,this.image),this.width=this.image.width,this.height=this.image.height):(gl.texImage2D(gl.TEXTURE_2D,0,this.dataInfo.interFormat,this.dataInfo.width,this.dataInfo.height,0,this.dataInfo.format,this.dataInfo.dataType,this.dataInfo.data),this.width=this.dataInfo.width,this.height=this.dataInfo.height),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,this.magFilter),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,this.minFilter),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,this.wrapS),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,this.wrapT),this.mipmap&&gl.generateMipmap(gl.TEXTURE_2D),gl.bindTexture(gl.TEXTURE_2D,null),this.loaded=!0},t.prototype.load=function(e){this.image=new Image,this.dataInfo=null;var t=this;this.image.onload=function(){t.recreate.apply(t)},this.image.src=e,this.loaded=!1},t.prototype.createFromData=function(e,t,n,r,i,s){this.dataInfo={width:e,height:t,format:r||gl.RGBA,interFormat:i||gl.RGBA,dataType:s||gl.UNSIGNED_BYTE},this.dataInfo.data=n instanceof Array?new Uint8Array(n):n,this.loaded=!1,this.recreate()},t.prototype.release=function(){this.image=null,gl.deleteTexture(this.texture),this.texture=null,e.freeResource(this)},t.prototype.onlost=function(){this.texture=null,this.loaded=!1},t.prototype.onrestore=function(){this.texture=gl.createTexture(),this.recreate()},t.prototype.appear=function(e){if(!this.texture||!this.loaded){this!=n.error&&n.error.appear(e);return}gl.activeTexture(gl.TEXTURE0+e),gl.bindTexture(gl.TEXTURE_2D,this.texture)};var n={textureMap:{}};return n.init=function(){n.white=new t,n.white.magFilter=gl.NEAREST,n.white.minFilter=gl.NEAREST,n.white.createFromData(1,1,[255,255,255,255]),n.black=new t,n.black.magFilter=gl.NEAREST,n.black.minFilter=gl.NEAREST,n.black.createFromData(1,1,[0,0,0,255]),n.error=new t,n.error.magFilter=gl.NEAREST,n.error.minFilter=gl.NEAREST,n.error.minFilter=gl.NEAREST_MIPMAP_LINEAR;var e=16,r=new Array(e*e*4),i=0;for(var s=0;s<e;s++)for(var o=0;o<e;o++)(s+o)%2==0?(r[i*4+0]=0,r[i*4+1]=255,r[i*4+2]=255,r[i*4+3]=255):(r[i*4+0]=255,r[i*4+1]=0,r[i*4+2]=255,r[i*4+3]=255),i++;n.error.createFromData(e,e,r)},n.loadTexture=function(e){var n=this.textureMap[e];return n!=undefined?n:(n=new t,n.load(e),this.textureMap[e]=n,n)},t.Manager=n,t}),define("engine/renderres/rendertarget",["./resman","./Texture"],function(e,t){var n=function(t,n){this.texture=t,this.depthFormat=n,this.frameBuffer=gl.createFramebuffer(),n&&(this.depthBuffer=gl.createRenderbuffer()),this.applied=!1,e.newResource(this)};return n.create=function(e,r,i){var s=new t;s.mipmap=!1,s.minFilter=gl.LINEAR,s.magFilter=gl.LINEAR,s.wrapS=gl.CLAMP_TO_EDGE,s.wrapT=gl.CLAMP_TO_EDGE;var o=new Array(e*r*4);for(var u=0;u<e*r;u++)o[u*4+0]=255,o[u*4+1]=0,o[u*4+2]=0,o[u*4+3]=255;s.createFromData(e,r,o);var a=new n(s,i);return a.recreate(),a},n.prototype.release=function(){this.texture&&this.texture.release(),this.texture=null,gl.deleteFramebuffer(this.frameBuffer),this.frameBuffer=null,this.depthFormat&&(gl.deleteRenderbuffer(this.depthBuffer),this.depthBuffer=null),e.freeResource(this)},n.prototype.onlost=function(){this.frameBuffer=null,this.depthBuffer=null,this.loaded=!1},n.prototype.onrestore=function(){this.frameBuffer=gl.createFramebuffer(),this.depthFormat&&(this.depthBuffer=gl.createRenderbuffer()),this.recreate()},n.prototype.recreate=function(){gl.bindFramebuffer(gl.FRAMEBUFFER,this.frameBuffer),this.width=this.texture.width,this.height=this.texture.height,gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,this.texture.texture,0),this.depthFormat&&(gl.bindRenderbuffer(gl.RENDERBUFFER,this.depthBuffer),gl.renderbufferStorage(gl.RENDERBUFFER,this.depthFormat,this.width,this.height),gl.framebufferRenderbuffer(gl.FRAMEBUFFER,gl.DEPTH_ATTACHMENT,gl.RENDERBUFFER,this.depthBuffer),gl.bindRenderbuffer(gl.RENDERBUFFER,null)),gl.bindFramebuffer(gl.FRAMEBUFFER,null)},n.prototype.bind=function(){console.assert(!this.applied),this.oldFbo=gl.getParameter(gl.FRAMEBUFFER_BINDING),this.oldViewport=gl.getParameter(gl.VIEWPORT),gl.viewport(0,0,this.width,this.height),gl.viewportWidth=this.width,gl.viewportHeight=this.height,gl.bindFramebuffer(gl.FRAMEBUFFER,this.frameBuffer),this.applied=!0},n.prototype.unbind=function(){console.assert(this.applied),gl.viewport(this.oldViewport[0],this.oldViewport[1],this.oldViewport[2],this.oldViewport[3]),gl.viewportWidth=this.oldViewport[2],gl.viewportHeight=this.oldViewport[3],gl.bindFramebuffer(gl.FRAMEBUFFER,this.oldFbo),this.applied=!1},n.prototype.clear=function(e,t,n,r){var i=this.applied;i||this.bind(),gl.clearColor(e,t,n,r),gl.clear(gl.COLOR_BUFFER_BIT),i||this.unbind()},n.prototype.readPixels=function(e,t,n,r){var i=this.applied;i||this.bind(),e=e||0,t=t||0,n=n||this.width,r=r||this.height;var s=new Uint8Array(n*r*4);return gl.readPixels(0,0,n,r,gl.RGBA,gl.UNSIGNED_BYTE,s),i||this.unbind(),s},n.Manager={freeTargets:[]},n.Manager.reset=function(){for(var e=0;e<this.freeTargets.length;e++)this.freeTargets[e].release();this.freeTargets.length=0},n.Manager.allocTarget=function(e,t,r){for(var i=0;i<this.freeTargets.length;i++){var s=this.freeTargets[i];if(s.width==e&&this.height==t&&this.depthFormat==r)return this.freeTargets.splice(i,1),s}var o=n.create(e,t,r);return o},n.Manager.freeTarget=function(e){console.assert(e instanceof n),this.freeTargets.push(e)},n}),define("engine/core/transform",["../common/utils"],function(e){var t=function(){this.pos=[0,0,0],this.quat=[0,0,0,1],this.scale=[1,1,1],this.mat=mat4.create(),this.dirty=!0};return t.prototype.setUpDir=function(t,n){var r=[1,0,0],i=[0,1,0],s=[0,0,1];vec3.normalize(i,t),vec3.normalize(s,n),e.makeCoordinate(s,i,r),quat.setAxes(this.quat,s,r,i),this.updateMatrix()},t.prototype.lookAt=function(t,n,r){var i=[1,0,0],s=[0,1,0],o=[0,0,1];vec3.normalize(s,n),vec3.normalize(o,r),e.makeCoordinate(o,s,i),quat.setAxes(this.quat,o,i,s),vec3.copy(this.pos,t),this.updateMatrix()},t.prototype.updateMatrix=function(){mat4.fromRotationTranslation(this.mat,this.quat,this.pos),this.dirty=!0},t.prototype.getDirUpRight=function(){var e=mat3.create();return function(t,n,r){mat3.fromQuat(e,this.quat),r&&(r[0]=e[0],r[1]=e[3],r[2]=e[6]),n&&(n[0]=e[1],n[1]=e[4],n[2]=e[7]),t&&(t[0]=e[2],t[1]=e[5],t[2]=e[8])}}(),t}),define("engine/model/modelins",["../core/transform","../core/engine"],function(e,t){var n=function(){this.material={shader:null},this.items=[],this.transform=new e,this.isSkin=!1,this.isPhysics=!1};return n.prototype.init=function(e,n){this.model=e,this.isSkin=!!n;for(var r=0;r<e.meshes.length;r++){var i=e.meshes[r],s=t.RenderList.Item(i,this.transform.mat,this.material);if(this.isSkin){s.submeshes=[];for(var o=0;o<i.submeshes.length;o++){var u={};u.skinUniforms=new Float32Array(i.submeshes[o].boneIndexMap.length*12),u.boneMap=i.submeshes[o].boneIndexMap,u.vbBoneIndices=i.submeshes[o].vbBoneIndices,u.numIndex=i.submeshes[o].numIndex,u.startIndex=i.submeshes[o].startIndex,s.submeshes.push(u)}}this.items.push(s)}this.aabb=e.aabb,this.skeleton=n},n.prototype.update=function(){this.updateSkin(),this.transform.dirty&&(this.updateMatrix(),this.transform.dirty=!1)},n.prototype.updateSkin=function(){if(this.isSkin){var e=this.skeleton.bones;for(var t=0,n=this.items.length;t<n;t++){var r=this.items[t].submeshes;for(var i=0,s=r.length;i<s;i++){var o=r[i],u=o.skinUniforms,a=o.boneMap,f=0;for(var l=0,c=a.length;l<c;l++){var h=e[a[l]];u[f++]=h.matRelative[0],u[f++]=h.matRelative[4],u[f++]=h.matRelative[8],u[f++]=h.matRelative[12],u[f++]=h.matRelative[1],u[f++]=h.matRelative[5],u[f++]=h.matRelative[9],u[f++]=h.matRelative[13],u[f++]=h.matRelative[2],u[f++]=h.matRelative[6],u[f++]=h.matRelative[10],u[f++]=h.matRelative[14]}}}}},n.prototype.draw=function(){for(var e=0;e<this.items.length;e++){var n=this.items[e];t.modelRenderList.add(n)}},n.prototype.updateMatrix=function(){for(var e=0,t=this.items.length;e<t;e++){var n=this.transform.mat,r=this.items[e];r.mat=n,r.aabb=r.mesh.aabb.transformAABB(n)}this.aabb=this.model.aabb.transformAABB(n)},n.prototype.setMaterial=function(e,t){if(t!=undefined)this.items[t].material=e;else for(var n=0;n<this.items.length;n++)this.items[n].material=e},n.prototype.rayTrace=function(){var e=mat4.create(),t=[0,0,0],n=[0,0,0];return function(r,i,s){mat4.invert(e,this.transform.mat),vec3.transformMat4(t,r,e),vec3.transformMat4NoTranslation(n,i,e);var o=s.maxt,u=!1;for(var a=0;a<this.items.length;a++){var f=this.items[a].mesh;f.rayTrace(t,n,s)&&(s.maxt=s.t,u=!0)}return s.maxt=o,u&&(vec3.transformMat4NoTranslation(s.normal,s.normal,this.transform.mat),vec3.normalize(s.normal,s.normal)),u}}(),n}),define("engine/particle/particle",[],function(){var e=function(){this.pos=[0,0,0],this.color=[0,0,0,0],this.scale=1,this.active=!1,this.life=0,this.dpos=[0,0,0],this.dcolor=[0,0,0,0],this.dscale=0};return e.prototype.setPosGrad=function(e,t,n){this.pos[0]=e[0],this.pos[1]=e[1],this.pos[2]=e[2];var r=1/n;this.dpos[0]=(t[0]-e[0])*r,this.dpos[1]=(t[1]-e[1])*r,this.dpos[2]=(t[2]-e[2])*r},e.prototype.setPos=function(e){this.pos[0]=e[0],this.pos[1]=e[1],this.pos[2]=e[2]},e.prototype.setColorGrad=function(e,t,n){this.color[0]=e[0],this.color[1]=e[1],this.color[2]=e[2],this.color[3]=e[3];var r=1/n;this.dcolor[0]=(t[0]-e[0])*r,this.dcolor[1]=(t[1]-e[1])*r,this.dcolor[2]=(t[2]-e[2])*r,this.dcolor[3]=(t[3]-e[3])*r},e.prototype.setColor=function(e){this.color[0]=e[0],this.color[1]=e[1],this.color[2]=e[2],this.color[3]=e[3]},e.prototype.setScaleGrad=function(e,t,n){this.scale=e,this.dscale=(t-e)/n},e.prototype.updatePos=function(e){this.pos[0]+=this.dpos[0]*e,this.pos[1]+=this.dpos[1]*e,this.pos[2]+=this.dpos[2]*e},e.prototype.updateColor=function(e){this.color[0]+=this.dcolor[0]*e,this.color[1]+=this.dcolor[1]*e,this.color[2]+=this.dcolor[2]*e,this.color[3]+=this.dcolor[3]*e},e.prototype.updateScale=function(e){this.scale+=this.dscale*e},e.prototype.update=function(e){this.pos[0]+=this.dpos[0]*e,this.pos[1]+=this.dpos[1]*e,this.pos[2]+=this.dpos[2]*e,this.color[0]+=this.dcolor[0]*e,this.color[1]+=this.dcolor[1]*e,this.color[2]+=this.dcolor[2]*e,this.color[3]+=this.dcolor[3]*e,this.scale+=this.dscale*e,this.life-=e},e}),define("engine/particle/particlesystem",["../common/config","./particle","./particlerender","../renderres/texture"],function(e,t,n,r){var i={maxPoint:10,writeZ:!1,testZ:!0,blendType:"add",start:function(e){},update:function(){var e=0;return function(t,n){e+=n;var r;while(e>100){e-=e,r=t.allocParticle();if(r){var i=Math.random()*1e3+500;vec3.randomInBox(r.pos,[-0.5,-0.5,-0.5],[.5,.5,.5]),vec3.randomOnCircleXZ(r.dpos,[0,.001,0],Math.random()*.003),r.setColorGrad([255,255,0,255],[0,0,255,255],i),r.scale=.1,r.life=i}}for(var s=0,o=t.activeList.length;s<o;s++)r=t.activeList[s],r.update(n),r.life<0&&t.freeParticle(r)}}()},s=function(n){this.control=n=n||i;var s=n.maxPoint;this.texture=r.Manager.white,n.texture&&(this.texture=r.Manager.loadTexture(e.texturePath+n.texture)),this.testZ=n.testZ;switch(n.blendType){case"alpha":this.srcBlend=gl.SRC_ALPHA,this.dstBlend=gl.ONE_MINUS_SRC_ALPHA;break;case"add":this.srcBlend=gl.SRC_ALPHA,this.dstBlend=gl.ONE;break;default:this.srcBlend=gl.ONE,this.dstBlend=gl.ZERO}this.materialTag=n.texture+"#"+(n.writeZ?"W":"w")+(n.testZ?"T":"t")+n.blendType,this.freeList=new Array(s),this.activeList=new Array(s),this.activeList.length=0;for(var o=0;o<s;o++)this.freeList[o]=new t(this);this.time=0,this.started=!1};return s.prototype.allocParticle=function(){var e;return this.freeList.length==0?e=new t:e=this.freeList.pop(),e.active=!0,this.activeList.push(e),e},s.prototype.freeParticle=function(e){e.active=!1,this.freeList.push(e),this.freeNum++},s.prototype.reset=function(){this.time=0;for(var e=0,t=this.activeList.length;e<t;e++){var n=this.activeList[e];n.active=!1,this.freeList.push(n)}this.activeList.length=0,this.control.start&&this.control.start(this)},s.prototype.update=function(e){this.freeNum=0,this.control.update&&this.control.update(this,e);if(this.freeNum>0)for(var t=0,n=this.activeList.length;t<n;t++){var r=this.activeList[t];r.active||(this.activeList.splice(t,1),t--,n--)}this.time+=e},s.prototype.start=function(){this.started||(this.reset(),n.add(this),this.started=!0)},s.prototype.stop=function(){this.started&&(n.remove(this),this.started=!1)},s}),define("phymaterial",["./engine/physics/physics"],function(e){return{materialNames:["wall","ball","actor"],contactTable:[[[0,0],[.5,.5],[0,0]],[[],[.5,.5],[.4,0]],[[],[],[0,0]]],materials:{},init:function(){var t=e.world,n,r,i=this.materialNames.length,s=[];for(n=0;n<i;n++){var o=new CANNON.Material(this.materialNames[n]);this.materials[this.materialNames[n]]=o,t.addMaterial(o),s.push(o)}for(n=0;n<i;n++)for(r=n;r<i;r++){var u=new CANNON.ContactMaterial(s[n],s[r],this.contactTable[n][r][0],this.contactTable[n][r][1]);t.addContactMaterial(u)}}}}),define("npc",["engine/common/utils","engine/model/modelins","engine/physics/physics","./phymaterial"],function(e,t,n,r){var i=function(){},s=100,o={STAND:0,MOVE:1,ATTACK:2,HURT:3,DYING:4,DEAD:5};i.prototype.init=function(e,n,r){this.id=s,s++,this.name="Actor",this.skel=n,this.model=e,this.modelIns=new t,this.modelIns.init(e,n),this.transform=this.modelIns.transform,this.modelIns.setMaterial(r)},i.prototype.update=function(e){this.skel&&this.skel.update(e),this.modelIns&&this.modelIns.update()},i.prototype.draw=function(){this.modelIns&&this.modelIns.draw()},i.prototype.playAnimationClip=function(e,t,n){return this.skel?this.skel.playAnimationClip(e,t,n):null};var u=function(){};return extend(u,i),u.prototype.init=function(e,t,s){i.prototype.init.call(this,e,t,s),this.speed=4,this.angle=0,this.targetAngle=this.angle,this.angleSpeed=8,this.targetPos=null,this.phyObj=n.addPhysics(this.modelIns,1e5),this.phyObj.body.angularDamping=.5,this.phyObj.body.linearDamping=.9,this.modelIns.phyObj.body.material=r.materials.actor,this.stand()},u.prototype.stand=function(){this.state!=o.STAND&&(this.state=o.STAND,this.playAnimationClip(0,"idle",{loop:!0,exclusive:!0,trans:100}))},u.prototype.walk=function(){this.state!=o.MOVE&&(this.state=o.MOVE,this.playAnimationClip(0,"walk",{loop:!0,trans:100,exclusive:!0}))},u.prototype.update=function(t){var n=[0,0,0];this.transform.getDirUpRight(n),this.transform.dirty&&(this.angle=e.normalizeAngle(Math.atan2(n[0],n[2])));var r=e.normalizeAngle(this.targetAngle-this.angle);if(r!=0){var s=this.angleSpeed*t*.001;r>Math.PI?(r=Math.PI*2-r,r=Math.min(r,s),this.angle-=r):(r=Math.min(r,s),this.angle+=r),this.transform.setUpDir([0,1,0],[Math.sin(this.angle),0,Math.cos(this.angle)]),this.phyObj.updateFromTransform()}if(this.state==o.MOVE){if(this.targetPos){var u=[Math.sin(this.targetAngle),Math.cos(this.targetAngle)],a=[this.targetPos[0]-this.transform.pos[0],this.targetPos[2]-this.transform.pos[2]];vec2.dot(u,a)<=0?(this.targetPos=null,this.phyObj.setVelocity(0,0,0),this.stand()):this.phyObj.setVelocity(this.speed*u[0],0,this.speed*u[1])}}else this.phyObj.setVelocity(0,0,0);i.prototype.update.call(this,t)},u.prototype.faceTo=function(t){typeof t!="number"&&(t=Math.atan2(t[0],t[2])),this.targetAngle=e.normalizeAngle(t)},u.prototype.moveTo=function(e){vec3.distance(this.transform.pos,e)<1e-6?(this.targetPos=null,this.state==o.MOVE&&this.stand()):(this.faceTo([e[0]-this.transform.pos[0],0,e[2]-this.transform.pos[2]]),this.walk(),this.targetPos=vec3.clone(e))},u}),define("gameeffect",["engine/renderres/texture","engine/particle/particlesystem"],function(e,t){var n={},r=function(e){n[e.name]?n[e.name].push(e):n[e.name]=[e]},i={};i.playeEffect=function(e,r){var i=n[e],o;if(i&&i.length>0)o=i.pop();else{var u=s(e);if(!u)return null;o=new t(u),o.name=e}return o.control.param=r,o.start(),o};var s=function(e){switch(e){case"fire":return function(){var e=0;return{texture:"p2.png",maxPoint:10,writeZ:!1,testZ:!0,blendType:"add",start:function(t){e=0},update:function(){return function(t,n){e+=n;var r;while(e>.05){e-=.05,r=t.allocParticle();if(r){var i=Math.random()*.5+.5;vec3.randomOnCircleXZ(r.pos,[0,.3,0],.5),r.dpos=[r.pos[0],3,r.pos[2]],vec3.add(r.pos,r.pos,this.param.pos),r.setColorGrad([100,255,100,255],[255,0,0,0],i),r.setScaleGrad(.5,1,i),r.life=i}}for(var s=0,o=t.activeList.length;s<o;s++)r=t.activeList[s],r.update(n),r.life<0&&t.freeParticle(r)}}()}}();case"bullet":return function(){var e=0,t=0,n=0;return{texture:"p3.png",maxPoint:10,writeZ:!1,testZ:!0,blendType:"add",start:function(r){e=0;var i=vec3.dist(this.param.pos,this.param.target);i>0?n=this.param.speed/i:n=1,t=0},update:function(i,s){t+=s;var o;while(e<=1&&t>.01){t-=.01,e+=n*.01,o=i.allocParticle();if(o){var u=.4;o.dpos=[0,0,0],vec3.lerp(o.pos,this.param.pos,this.param.target,e),o.setColorGrad(this.param.startColor,this.param.endColor,u),o.setScaleGrad(this.param.startScale,this.param.endScale,u),o.life=u}}for(var a=0,f=i.activeList.length;a<f;a++)o=i.activeList[a],o.update(s),o.life<0&&i.freeParticle(o);e>1&&i.activeList.length==0&&(i.stop(),r(i))}}}();case"touch":return function(){var e=0;return{texture:"p3.png",maxPoint:10,writeZ:!1,testZ:!0,blendType:"add",start:function(e){var t=[Math.random()*255,Math.random()*255,Math.random()*255,255],n=[Math.random()*255,Math.random()*255,Math.random()*255,0];for(var r=0;r<this.maxPoint;r++){var i=e.allocParticle();if(i){var s=1,o=Math.PI*2*r/this.maxPoint;i.pos[0]=Math.cos(o)*.3,i.pos[1]=.1,i.pos[2]=Math.sin(o)*.3,i.dpos=[-i.pos[0],.1,-i.pos[2]],vec3.add(i.pos,i.pos,this.param.pos),i.setColorGrad(t,n,s),i.setScaleGrad(.1,.3,s),i.life=s}}},update:function(){return function(e,t){for(var n=0,i=e.activeList.length;n<i;n++){var s=e.activeList[n];s.update(t);if(s.life<0){e.freeParticle(s),e.stop(),r(e);break}}}}()}}();default:return null}};return i}),define("gameui",["engine/common/config","engine/core/engine"],function(e,t){var n={},r={},i,s=document.getElementById("profileGrid"),o={drawcall:document.getElementById("drawcount"),mesh:document.getElementById("meshcount"),triangle:document.getElementById("trianglecount")},u=document.getElementById("fps");n.init=function(e){i=e;var t=document.getElementById("profile");t&&(a(t,"RenderActor",!0),a(t,"RenderWall",!0),a(t,"RenderNormal",!0),a(t,"RenderReflect",!0),a(t,"RenderParticle",!0),a(t,"RenderDebug",!1),a(t,"UpdateActor",!0),a(t,"UpdateEngine",!0)),f("fire1",function(){i.fire([0,255,0,255],.1,[255,0,0,0],.5)}),f("fire2",function(){i.fire([255,255,0,255],.5,[0,0,255,0],.1)})},n.update=function(){if(t.frameCountFPS==1){for(var e in r)if(r.hasOwnProperty(e)){var n=t.getStat(e);r[e].data=(n/t.FPS).toFixed(2)}t.clearStat();var s="FPS:"+engine.FPS;s+=vec3.ToString(i.camera.pos),u.innerText=s,o.drawcall.innerText=engine.statistics.drawCall.toString(),o.mesh.innerText=engine.statistics.meshes.toString(),o.triangle.innerText=engine.statistics.triangles.toString()}};var a=function(e,t,n){i.profile[t]=n;var s=document.createElement("div");s.className="itemLabel",s.appendChild(document.createTextNode(t));var o=document.createElement("input");o.type="checkbox",o.checked=n?"checked":undefined,o.addEventListener("change",function(){i.profile[t]=!!o.checked});var u=document.createElement("div");u.className="itemContent",u.appendChild(o);var a=document.createTextNode("aa");r[t]=a,u.appendChild(a),e.appendChild(s),e.appendChild(u)},f=function(t,n){var r=document.getElementById(t);if(!r)return;e.isiOS?r.addEventListener("touchstart",function(e){n(),e.preventDefault()}):r.addEventListener("click",function(e){n(),e.preventDefault()})};return n.showProfile=function(e){e?s.style.display="block":s.style.display="none"},n}),define("game",["engine/common/config","engine/common/utils","engine/common/mathlib","engine/core/aabb","engine/core/camera","engine/core/engine","engine/core/simpledraw","engine/file/ajaxfile","engine/file/modelloaderxml","engine/file/textfilemanager","engine/input/keyboard","engine/input/canvasevent","engine/renderres/shader","engine/renderres/texture","engine/renderres/rendertarget","engine/model/model","engine/model/modelins","engine/physics/physics","engine/particle/particlesystem","./phymaterial","./npc","./gameeffect","./gameui"],function(e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S){function T(){S.init(x),s.renderCallback=N,s.init("myCanvas"),x.init(),s.mainLoop()}function N(e){x.render(e),S.update()}function _(t){var n=a.loadSkeleton(e.modelPath+t.skeleton),r=a.loadAnimation(e.modelPath+t.walk,n)[0];n.addAnimation("walk",r),r=a.loadAnimation(e.modelPath+t.attack,n)[0],n.addAnimation("attack",r),r=a.loadAnimation(e.modelPath+t.idle,n)[0],n.addAnimation("idle",r),n.setChannelNum(2),n.playAnimationClip(0,"walk",{trans:100,loop:!0,exclusive:!0});var i=new v;i.init(),i.load(e.modelPath+t.mesh,a,{size:[1,1,1],skin:!0});var s=new w;return s.init(i,n,{shader:x.skinShader}),s.transform.pos=[0,-1.5,0],s.transform.updateMatrix(),s}function D(e,t,n,r,i,s,o){var u=new v;u.init(),u.addSphere({radius:t,texScale:n,texture:s}),u.ready=!0,u.recreate();var a=new m;return a.init(u),a.transform.lookAt(e,r,i),a.setMaterial(x.staticMaterial),o=o==undefined?10:o,a.phyObj=g.addPhysics(a,o*4/3*Math.PI*t*t*t),a.phyObj.body.material=b.materials.ball,a}function P(e,t,n,r,i,s){var o=new v;o.init(),o.addCube({size:t,texScale:n,texture:s}),o.ready=!0,o.recreate();var u=new m;return u.init(o),u.transform.lookAt(e,r,i),u.setMaterial(x.staticMaterial),u.phyObj=g.addPhysics(u,100*t[0]*t[1]*t[2]),u.phyObj.body.material=b.materials.wall,u}function H(e,t,n,r,i,s){var o=new v;o.init(),o.addPlane({size:t,texScale:n,texture:s}),o.ready=!0,o.recreate();var u=new m;return u.init(o),u.transform.lookAt(e,r,i),u.setMaterial(x.staticMaterial),u.phyObj=g.addPhysics(u,0),u.phyObj.body.material=b.materials.wall,u}function B(){var e=x.texture=new p;e.load("res/images/stone.jpg");var t=x.textureSpot=new p;t.load("res/images/spot.png");var r=x.texture=new p;r.load("res/images/stone.jpg"),x.staticMaterial={shader:h.createDiffuseShader()},x.staticModels=[],x.staticModels.push(H([0,-6,0],[60,60,1],[3,3],[0,0,1],[0,1,0],e)),x.staticModels.push(H([15,-1.5,0],[30,15,1],[3,1],[0,1,0],[-1,0,0],e)),x.staticModels.push(H([-15,-1.5,0],[30,15,1],[3,1],[0,1,0],[1,0,0],e)),x.staticModels.push(H([0,-1.5,15],[30,15,1],[3,1],[0,1,0],[0,0,-1],e)),x.staticModels.push(H([0,-1.5,-15],[30,15,1],[3,1],[0,1,0],[0,0,1],e)),x.mirror=H([0,-1.5,0],[30,30,1],[1,1],[0,0,1],[0,1,0],e),x.mirror.canRayTrace=!0,x.balls=[];for(var s=0;s<5;s++){var o=D([Math.random()*20-10,1,Math.random()*20-10],Math.random()+1,[3,3],[0,1,0],[0,0,1],r);x.staticModels.push(o),x.balls.push(o)}x.staticModels.push(D([10,-1,10],3,[3,3],[0,1,0],[0,0,1],r,0)),x.camera=new i({pos:[0,0,-10],target:[0,0,0]}),x.cameraReflect=new i({pos:[0,0,-10],target:[0,0,0]}),x.cameraRefract=new i({pos:[0,0,-10],target:[0,0,0]}),x.cameraReflect.setClipPlane(new n.Plane([0,1,0],1.5)),x.cameraRefract.setClipPlane(new n.Plane([0,-1,0],-1.5)),x.skinShader=h.createSkinDiffuseShader(),x.showModel=!0,x.lastPos={x:0,y:0},x.rtResult={},x.actor=_(M),x.npc=_(L),x.npcs=[];for(var u=0;u<=0;u++)for(var a=0;a<=1;a++){var f=new w;f.init(x.npc.model,x.npc.skel.clone(),{shader:x.skinShader}),f.transform.pos=[u*2,-1.5,a*2],f.transform.updateMatrix(),f.update(0),x.npcs.push(f)}var l=d.create(128,128);x.rt=l,x.shaderBlur=h.createTextureShader("blur","_BLUR_RADIUS_=1"),x.shaderBlur.unifOffset=x.shaderBlur.getUniform("offset"),x.shaderWave=h.createTextureShader("wave"),x.shaderWave.unifOffset=x.shaderWave.getUniform("offset"),x.shaderWave.unifMap2=x.shaderWave.getUniform("DiffuseMap2"),x.shaderH2N=h.createTextureShader("height2normal"),x.shaderH2N.unifOffset=x.shaderH2N.getUniform("offset"),x.shaderMirror=h.createMirrorShader(),x.mirror.setMaterial({shader:x.shaderMirror}),x.mirror.items[0].camera=x.cameraReflect,x.mirror.items[0].mesh.texture=l.texture;var c=x.texture=new p;c.load("res/images/normal-water.jpg"),x.mirror.items[0].mesh.textureDetailNormal=c;var v=128;x.rtHeight1=d.create(v,v),x.rtHeight1.clear(.5,.5,.5,1),x.rtHeight2=d.create(v,v),x.rtHeight2.clear(.5,.5,.5,1),x.rtHeight3=d.create(v,v),x.rtHeight3.clear(.5,.5,.5,1),x.rtNormal=d.create(v,v),x.rtRefract=d.create(256,256),x.mirror.items[0].mesh.normalmap=x.rtNormal.texture,x.mirror.items[0].mesh.textureRefract=x.rtRefract.texture,x.ps=E.playeEffect("fire",x.actor.transform)}var x={};window.game=x,x.profile={},x.ui=S,x.controlType=0;var C={mesh:"aabody.mesh.xml",skeleton:"aabody.SKELETON.xml",walk:"aabody.SKELETON.xml",idle:"aabody.SKELETON.xml",attack:"aabody.SKELETON.xml"},k={mesh:"frog/frog.mesh.xml",skeleton:"frog/frog.SKELETON.xml",walk:"frog/run.SKELETON.xml",idle:"frog/idle.SKELETON.xml",attack:"frog/idle.SKELETON.xml"},L={mesh:"mimic/mimic.mesh.xml",skeleton:"mimic/mimic.SKELETON.xml",walk:"mimic/Run.SKELETON.xml",idle:"mimic/Idle.SKELETON.xml",attack:"mimic/Attack1.SKELETON.xml"},A={mesh:"Cat/aa.mesh.xml",skeleton:"Cat/cat.SKELETON.xml",walk:"Cat/Walk.SKELETON.xml",idle:"Cat/Idle.SKELETON.xml",attack:"Cat/Attack1.SKELETON.xml"},O={mesh:"ghost/ghost.mesh.xml",skeleton:"ghost/ghost.SKELETON.xml",walk:"ghost/Walk.SKELETON.xml",idle:"ghost/Idle.SKELETON.xml",attack:"ghost/Attack1.SKELETON.xml"},M={mesh:"Zealot/Zealot.MESH.xml",skeleton:"Zealot/Zealot.SKELETON.xml",walk:"Zealot/Walk.SKELETON.xml",idle:"Zealot/Idle.SKELETON.xml",attack:"Zealot/Polearm1.SKELETON.xml"};x.init=function(){c.bindCanvasEvent(canvas.dom,this),b.init(),B()},x.onMouseMove=function(e,t){if(s.paused)return;if(isNaN(e.x)||isNaN(e.y))return;x.isdown&&(x.camera.rotateRelative((e.x-x.lastPos.x)*.01,-(e.y-x.lastPos.y)*.01),x.lastPos=e)},x.onMouseDown=function(e,t){if(isNaN(e.x)||isNaN(e.y))return;if(s.paused)return;x.isdown=!0,x.lastPos=e,x.downPos=e},x.onMouseUp=function(e,t){x.isdown=!1;if(isNaN(e.x)||isNaN(e.y))return;if(t.button==0){x.rtResult.pos=null;if(x.staticModels){var n={},r=[0,0,0];x.camera.invertDir(r,e.x,e.y);for(var i=0;i<x.staticModels.length;i++){var s=x.staticModels[i];if(!s.canRayTrace)continue;if(s.rayTrace(x.camera.pos,r,n)){n.maxt=n.t;var o=[0,0,0];vec3.scale(o,r,n.t),vec3.add(o,x.camera.pos,o),x.rtResult.pos=vec3.clone(o),x.rtResult.normal=vec3.clone(n.normal),x.actor.moveTo(o)}}s=x.mirror;if(s.rayTrace(x.camera.pos,r,n)){n.maxt=n.t;var o=[0,0,0];vec3.scale(o,r,n.t),vec3.add(o,x.camera.pos,o),x.rtResult.pos=vec3.clone(o),x.rtResult.normal=vec3.clone(n.normal),x.actor.moveTo(o),E.playeEffect("touch",{pos:o})}}}else t.button==1&&x.actor.skel.playAnimationClip(1,"attack",{trans:100,exclusive:!0,autofadeout:200})},x.onMouseWheel=function(e,t,n){if(s.paused)return;x.camera.zoom(t)},x.fire=function(e,t,n,r){var i={},s=[0,0,0];x.actor.transform.getDirUpRight(s),i.target=[0,0,0],i.pos=vec3.clone(x.actor.transform.pos),i.pos[1]+=2,i.pos[0]+=s[0],i.pos[2]+=s[2],vec3.scaleAndAdd(i.target,i.pos,s,15),i.speed=10,i.startColor=e,i.startScale=t,i.endColor=n,i.endScale=r,E.playeEffect("bullet",i)},x.handleKeyInput=function(){l.isKeyJustPressed("Q")&&x.actor.playAnimationClip(1,"attack",{exclusive:!0,trans:100,autofadeout:100});if(l.isKeyJustPressed("P")){var e=x.rtHeight2,t=e.readPixels();u.sendBinaryToServer("/saveimage?width="+e.width+"&height="+e.height+"&filename=a.png",t)}var n=!1;if(x.controlType==0){var r=[0,0,0],i=s.deltaTime*.01;l.isKeyPressed("W")&&(vec3.scale(r,x.camera.dir,i),n=!0),l.isKeyPressed("S")&&(vec3.scale(r,x.camera.dir,-i),n=!0),l.isKeyPressed("A")&&(vec3.scale(r,x.camera.right,i),n=!0),l.isKeyPressed("D")&&(vec3.scale(r,x.camera.right,-i),n=!0),n&&x.camera.move(r)}else{var o=[0,0,0],a=0,f=0;l.isKeyPressed("W")&&(vec3.scale(o,x.camera.dir,1),vec3.normalize(o,o),a+=o[0],f+=o[2],n=!0),l.isKeyPressed("S")&&(vec3.scale(o,x.camera.dir,-1),vec3.normalize(o,o),a+=o[0],f+=o[2],n=!0),l.isKeyPressed("A")&&(vec3.scale(o,x.camera.right,1),vec3.normalize(o,o),a+=o[0],f+=o[2],n=!0),l.isKeyPressed("D")&&(vec3.scale(o,x.camera.right,-1),vec3.normalize(o,o),a+=o[0],f+=o[2],n=!0);var c=a*a+f*f;if(c>1e-6){var h=Math.atan2(a,f);x.actor.faceTo(h),x.actor.walk()}else x.actor.stand()}};var j=0,F=!0;return x.renderHeightMap=function(){gl.depthMask(!1),gl.disable(gl.CULL_FACE),gl.disable(gl.DEPTH_TEST),j+=engine.deltaTime,gl.disable(gl.BLEND);if(j>30){j-=30;var e=x.rtHeight1,t=x.rtHeight2,n=x.rtHeight3,r=x.rtNormal;t.bind(),x.shaderWave.appear(),gl.uniform2f(x.shaderWave.unifOffset,.3/e.width,.3/e.height),gl.uniform1i(x.shaderWave.unifMap2,1),t.texture.appear(1),o.drawTextureWithShader(e.texture,0,0,t.width,t.height,x.shaderWave);if(F&&x.textureSpot.loaded){var i=(x.actor.transform.pos[0]+15)/30*t.width,s=(-x.actor.transform.pos[2]+15)/30*t.height;gl.enable(gl.BLEND),o.drawTexture(x.textureSpot,i-2,s-2,4,4,[0,0,0,1],[0,0,0,0]);for(var u=0;u<x.balls.length;u++)i=(x.balls[u].transform.pos[0]+15)/30*t.width,s=(-x.balls[u].transform.pos[2]+15)/30*t.height;gl.disable(gl.BLEND)}t.unbind(),x.rtHeight1=t,x.rtHeight2=e,r.bind(),x.shaderH2N.appear(),gl.uniform2f(x.shaderH2N.unifOffset,1/t.width,1/t.height),o.drawTextureWithShader(t.texture,0,0,r.width,r.height,x.shaderH2N),r.unbind()}},x.render=function(){x.profile.UpdateEngine&&(engine.beginStat("UpdateEngine"),engine.update(engine.deltaTime),engine.endStat("UpdateEngine"));var e=x.cameraReflect.clipPlane;e.mirrorPoint(x.cameraReflect.pos,x.camera.pos),e.mirrorVector(x.cameraReflect.dir,x.camera.dir),e.mirrorVector(x.cameraReflect.up,x.camera.up),vec3.copy(x.cameraReflect.target,x.camera.target),vec3.copy(x.cameraRefract.pos,x.camera.pos),vec3.copy(x.cameraRefract.dir,x.camera.dir),vec3.copy(x.cameraRefract.up,x.camera.up),vec3.copy(x.cameraRefract.target,x.camera.target),x.cameraReflect.updateView(),x.cameraRefract.updateView(),x.handleKeyInput();if(x.profile.UpdateActor){engine.beginStat("UpdateActor"),x.actor.update(s.deltaTime);for(var t=0;t<x.npcs.length;t++)x.npcs[t].update(s.deltaTime),x.npcs[t].targetPos||x.npcs[t].moveTo([Math.random()*30-15,-1.5,Math.random()*30-15]);engine.endStat("UpdateActor")}gl.enable(gl.BLEND),gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA),x.profile.RenderNormal&&(engine.beginStat("RenderNormal"),x.renderHeightMap(),engine.endStat("RenderNormal")),gl.depthMask(!0),gl.clearColor(0,0,0,1),gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT),gl.frontFace(gl.CCW),gl.cullFace(gl.BACK),gl.enable(gl.CULL_FACE),gl.enable(gl.DEPTH_TEST),gl.depthMask(!0),gl.depthFunc(gl.LESS),gl.depthRange(0,1),gl.enable(gl.BLEND),gl.blendFunc(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA),s.beforeRender(),s.activeCamera=x.camera;if(x.profile.RenderWall){engine.beginStat("RenderWall");for(var t=0;t<x.staticModels.length;t++)x.staticModels[t].update(),x.staticModels[t].draw();engine.endStat("RenderWall")}if(x.profile.RenderActor){engine.beginStat("RenderActor"),x.actor.draw();for(var t=0;t<x.npcs.length;t++)x.npcs[t].draw();engine.endStat("RenderActor")}x.profile.RenderReflect&&(engine.beginStat("RenderReflect"),s.activeCamera=x.cameraReflect,x.rt.bind(),gl.clearColor(0,0,0,1),gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT),s.renderList(),x.rt.unbind(),s.activeCamera=x.camera,x.mirror.draw(),engine.endStat("RenderReflect")),s.renderList(),x.profile.RenderParticle&&(engine.beginStat("RenderParticle"),s.renderParticles(),engine.endStat("RenderParticle")),gl.disable(gl.CULL_FACE),gl.enable(gl.DEPTH_TEST),gl.depthMask(!0);if(x.profile.RenderDebug){engine.beginStat("RenderDebug"),gl.depthMask(!1),o.beginDraw(),o.setColor(255,0,0,255),o.addLine(0,0,0,10,0,0),o.setColor(0,255,0,255),o.addLine(0,0,0,0,10,0),o.setColor(0,0,255,255),o.addLine(0,0,0,0,0,10),o.flush(),o.setColor(0,0,255,128);var n=new r;x.rtResult.pos&&(o.setColor(255,255,255,255),o.addLine(x.rtResult.pos[0],x.rtResult.pos[1],x.rtResult.pos[2],x.rtResult.pos[0]+x.rtResult.normal[0],x.rtResult.pos[1]+x.rtResult.normal[1],x.rtResult.pos[2]+x.rtResult.normal[2]),vec3.add(n.mins,x.rtResult.pos,[-0.01,-0.01,-0.01]),vec3.add(n.maxs,x.rtResult.pos,[.01,.01,.01]),o.setColor(255,0,0,255),o.addAABB(n)),o.endDraw(),gl.disable(gl.DEPTH_TEST),x.shaderBlur.appear(),gl.uniform2f(x.shaderBlur.unifOffset,1/256,0),o.drawTexture(x.rtHeight1.texture,0,0,64,64,[1,1,1,1],[0,0,0,1]),o.drawTexture(x.rtHeight2.texture,70,0,64,64),o.drawTexture(x.rtNormal.texture,140,0,64,64),engine.endStat("RenderDebug")}gl.useProgram(null)},T(),x}),require.config({baseUrl:"src",paths:{}}),require(["game"]),define("../main",function(){});