diff --git a/examples/assets/procedural-material.js b/examples/assets/procedural-material.js index f841e76..d01e0db 100644 --- a/examples/assets/procedural-material.js +++ b/examples/assets/procedural-material.js @@ -1,5 +1,21 @@ - function proc( options ) { - return { - color: [1, 0.2, 0] - }; - } +function proc( options ) { + options = options || {}; + if (options.colorR === undefined){ + options.colorR = 1; + }else{ + options.colorR = parseInt(options.colorR); + } + if (options.colorG === undefined){ + options.colorG = 0.2 + }else{ + options.colorG = parseInt(options.colorG); + } + if (options.colorB === undefined){ + options.colorB = 0; + }else{ + options.colorB = parseInt(options.colorB); + } + return { + color: [options.colorR, options.colorG, options.colorB] + }; +} diff --git a/examples/cube-collision/cube-collision.js b/examples/cube-collision/cube-collision.js index 266e133..87fa676 100644 --- a/examples/cube-collision/cube-collision.js +++ b/examples/cube-collision/cube-collision.js @@ -45,7 +45,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) { [ { type: engine["gladius-cubicvr"].Mesh, - url: 'procedural-mesh.js', + url: '../assets/procedural-mesh.js', load: engine.loaders.procedural, onsuccess: function( mesh ) { resources.mesh = mesh; @@ -55,7 +55,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) { }, { type: engine["gladius-cubicvr"].MaterialDefinition, - url: 'procedural-material.js', + url: '../assets/procedural-material.js', load: engine.loaders.procedural, onsuccess: function( material ) { resources.material = material; @@ -65,7 +65,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) { }, { type: engine["gladius-cubicvr"].MaterialDefinition, - url: 'procedural-material.js?colorR=0&colorG=0&colorB=1', + url: '../assets/procedural-material.js?colorR=0&colorG=0&colorB=1', load: engine.loaders.procedural, onsuccess: function( material ) { resources.materialBlue = material; @@ -75,7 +75,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) { }, { type: engine["gladius-cubicvr"].MaterialDefinition, - url: 'procedural-material.js?colorR=0&colorG=1&colorB=0', + url: '../assets/procedural-material.js?colorR=0&colorG=1&colorB=0', load: engine.loaders.procedural, onsuccess: function( material ) { resources.materialGreen = material; diff --git a/examples/cube-collision/procedural-material.js b/examples/cube-collision/procedural-material.js deleted file mode 100644 index af08c1f..0000000 --- a/examples/cube-collision/procedural-material.js +++ /dev/null @@ -1,21 +0,0 @@ - function proc( options ) { - options = options || {}; - if (options.colorR === undefined){ - options.colorR = 1; - }else{ - options.colorR = parseInt(options.colorR); - } - if (options.colorG === undefined){ - options.colorG = 0.2 - }else{ - options.colorG = parseInt(options.colorG); - } - if (options.colorB === undefined){ - options.colorB = 0; - }else{ - options.colorB = parseInt(options.colorB); - } - return { - color: [options.colorR, options.colorG, options.colorB] - }; - } diff --git a/examples/cube-collision/procedural-mesh.js b/examples/cube-collision/procedural-mesh.js deleted file mode 100644 index a580fcc..0000000 --- a/examples/cube-collision/procedural-mesh.js +++ /dev/null @@ -1,43 +0,0 @@ -function proc( options ) { - - options = options || {}; - options.size = options.size || 1.0; - var point = options.size / 2.0; - - var mesh = - { - points: [ - [ point, -point, point], - [ point, point, point], - [-point, point, point], - [-point, -point, point], - [ point, -point, -point], - [ point, point, -point], - [-point, point, -point], - [-point, -point, -point] - ], - faces: [ - [0, 1, 2, 3], - [7, 6, 5, 4], - [4, 5, 1, 0], - [5, 6, 2, 1], - [6, 7, 3, 2], - [7, 4, 0, 3] - ], - uv: [ - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ] - ], - uvmapper: { - projectionMode: "cubic", - scale: [1, 1, 1] - } - }; - - return mesh; - -} diff --git a/examples/cube-impulse/cube-impulse.js b/examples/cube-impulse/cube-impulse.js index 8cce490..5a93e55 100644 --- a/examples/cube-impulse/cube-impulse.js +++ b/examples/cube-impulse/cube-impulse.js @@ -45,7 +45,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) { [ { type: engine["gladius-cubicvr"].Mesh, - url: 'procedural-mesh.js', + url: '../assets/procedural-mesh.js', load: engine.loaders.procedural, onsuccess: function( mesh ) { resources.mesh = mesh; @@ -55,7 +55,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) { }, { type: engine["gladius-cubicvr"].MaterialDefinition, - url: 'procedural-material.js', + url: '../assets/procedural-material.js', load: engine.loaders.procedural, onsuccess: function( material ) { resources.material = material; diff --git a/examples/cube-impulse/procedural-material.js b/examples/cube-impulse/procedural-material.js deleted file mode 100644 index f841e76..0000000 --- a/examples/cube-impulse/procedural-material.js +++ /dev/null @@ -1,5 +0,0 @@ - function proc( options ) { - return { - color: [1, 0.2, 0] - }; - } diff --git a/examples/cube-impulse/procedural-mesh.js b/examples/cube-impulse/procedural-mesh.js deleted file mode 100644 index a580fcc..0000000 --- a/examples/cube-impulse/procedural-mesh.js +++ /dev/null @@ -1,43 +0,0 @@ -function proc( options ) { - - options = options || {}; - options.size = options.size || 1.0; - var point = options.size / 2.0; - - var mesh = - { - points: [ - [ point, -point, point], - [ point, point, point], - [-point, point, point], - [-point, -point, point], - [ point, -point, -point], - [ point, point, -point], - [-point, point, -point], - [-point, -point, -point] - ], - faces: [ - [0, 1, 2, 3], - [7, 6, 5, 4], - [4, 5, 1, 0], - [5, 6, 2, 1], - [6, 7, 3, 2], - [7, 4, 0, 3] - ], - uv: [ - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ], - [ [0, 1], [1, 1], [1, 0], [0, 0] ] - ], - uvmapper: { - projectionMode: "cubic", - scale: [1, 1, 1] - } - }; - - return mesh; - -} diff --git a/gladius-cubicvr.js b/gladius-cubicvr.js index 542cc6b..bb68a8f 100644 --- a/gladius-cubicvr.js +++ b/gladius-cubicvr.js @@ -23687,22 +23687,31 @@ define('src/components/model',['require','common/extend','base/component'],funct var Model = function( service, mesh, materialDefinition ) { Component.call( this, "Model", service, ["Transform"] ); - this._cubicvrMesh = mesh || new service.target.context.Mesh(); - setMaterialDefinition.call(this, materialDefinition || new service.target.context.Material()); + this._cubicvrMesh = null; + this._cubicvrMaterialDefinition = null; + + setMesh.call( this, mesh || new service.target.context.Mesh() ); + setMaterialDefinition.call( this, materialDefinition || new service.target.context.Material() ); }; Model.prototype = new Component(); Model.prototype.constructor = Model; - function setMaterialDefinition(materialDefinition){ - if (materialDefinition){ - this._cubicvrMaterialDefinition = materialDefinition; - } + function setMaterialDefinition( materialDefinition ){ + this._cubicvrMaterialDefinition = materialDefinition; } function getMaterialDefinition(){ return this._cubicvrMaterialDefinition; } + function setMesh( mesh ) { + this._cubicvrMesh = mesh; + } + + function getMesh() { + return this._cubicvrMesh; + } + function onUpdate( event ) { } @@ -23740,6 +23749,8 @@ define('src/components/model',['require','common/extend','base/component'],funct var prototype = { getMaterialDefinition: getMaterialDefinition, setMaterialDefinition: setMaterialDefinition, + getMesh: getMesh, + setMesh: setMesh, onUpdate: onUpdate, onEntitySpaceChanged: onEntitySpaceChanged, onComponentOwnerChanged: onComponentOwnerChanged, diff --git a/gladius-cubicvr.min.js b/gladius-cubicvr.min.js index 4f30962..9b8a8f9 100644 --- a/gladius-cubicvr.min.js +++ b/gladius-cubicvr.min.js @@ -21,4 +21,4 @@ a.undef,c=CubicVR.enums;c.motion={POS:0,ROT:1,SCL:2,POSITION:0,ROTATION:1,SCALE: [0],this.lscale[1]=this.scale[1],this.lscale[2]=this.scale[2],this.dirty=!0;if(this.hasEvents()){var f=this.getEventHandler();if(f.hasEvent(c.event.MOVE)){var h=f.triggerEvent(c.event.MOVE);h.oldPosition=this.lposition,h.position=this.position,h.oldRotation=this.lrotation,h.rotation=this.rotation,h.oldScale=this.lscale,h.scale=this.scale}}}},adjust_octree:function(){var a=this.getAABB(),c=this.octree_aabb,d=a[0][0],f=a[0][1],g=a[0][2],h=a[1][0],i=a[1][1],j=a[1][2],k=c[0][0],l=c[0][1],m=c[0][2],n=c[1][0],o=c[1][1],p=c[1][2];if(this.octree_leaves.length>0&&(dn||i>o||j>p)){for(var q=0;qj[0]&&(f[0]=j[0]),f[1]>j[1]&&(f[1]=j[1]),f[2]>j[2]&&(f[2]=j[2]),g[0]=0&&this.lights.splice(b,1)},removeSceneObject:function(a){var c;if(this.lockState){this.lockRemovals||(this.lockRemovals=[]),this.lockRemovals.indexOf(a)==-1&&this.lockRemovals.push(a);return}c=this.sceneObjects.indexOf(a),c>=0&&this.sceneObjects.splice(c,1),c=this.pickables.indexOf(a),c>=0&&this.pickables.splice(c,1),a.name!==null&&this.sceneObjectsByName[a.name]!==b&&delete this.sceneObjectsByName[a.name];if(a.children)for(var d=0,e=a.children.length;d=k[0]&&p[0]<=l[0]?1:0)+(p[1]>=k[1]&&p[1]<=l[1]?1:0)+(p[2]>=k[2]&&p[2]<=l[2]?1:0);r>=d&&h.push({dist:q,obj:j})}return h.length&&h.sort(function(a,b){return a.dist==b.dist?0:a.dist1){g=new Ammo.btTransform,L=new Ammo.btCompoundShape(!1);for(h=0,i=o.length;h0&&(r.push(t),this.dynamicsWorld.getDispatcher().clearManifold(p.mf[a].getPersistentManifold()))}r.length&&(d=c.triggerEvent(e.event.COLLIDE),d&&(d.collisions=r))}}}var v=this.ghostObjects.length;for(a=0;ay&&(d.contacts.length=y);for(b=0;b "+m),console.log(c+l+", :"+i)}}},bindSelf:function(a){var c,d,e,f;a.indexOf(".")!==-1?a.indexOf("[")!==-1?(c=a.split("["),e=c[0],c=c[1].split("]"),d=c[0],c=c[1].split("."),f=c[1],this[e]===b&&(this[e]=[]),this[e][d]===b&&(this[e][d]={}),this[e][d][f]=this.uniforms[a]):(c=a.split("."),e=c[0],f=c[1],this[e]===b&&(this[e]={}),this[e][f]=this.uniforms[a]):a.indexOf("[")!==-1?(c=a.split("["),e=c[0],c=c[1].split("]"),d=c[0],this[e]===b&&(this[e]=[]),this[e][d]=this.uniforms[a]):this[a]=this.uniforms[a]},addMatrix:function(a,e){return this.use(),this.uniforms[a]=c.gl.getUniformLocation(this.shader,a),this.uniform_type[a]=d.shader.uniform.MATRIX,this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]),e!==b&&this.setMatrix(a,e),this.bindSelf(a),this.uniforms[a]},addVector:function(a,e){return this.use(),this.uniforms[a]=c.gl.getUniformLocation(this.shader,a),this.uniform_type[a]=d.shader.uniform.VECTOR,this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]),e!==b&&this.setVector(a,e),this.bindSelf(a),this.uniforms[a]},addFloat:function(a,e){return this.use(),this.uniforms[a]=c.gl.getUniformLocation(this.shader,a),this.uniform_type[a]=d.shader.uniform.FLOAT,this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]),e!==b&&this.setFloat(a,e),this.bindSelf(a),this.uniforms[a]},addVertexArray:function(a){return this.use(),this.uniforms[a]=c.gl.getAttribLocation(this.shader,a),this.uniform_type[a]=d.shader.uniform.ARRAY_VERTEX,this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]),this.bindSelf(a),this.uniforms[a]},addUVArray:function(a){return this.use(),this.uniforms[a]=c.gl.getAttribLocation(this.shader,a),this.uniform_type[a]=d.shader.uniform.ARRAY_UV,this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]),this.bindSelf(a),this.uniforms[a]},addFloatArray:function(a){return this.use(),this.uniforms[a]=c.gl.getAttribLocation(this.shader,a),this.uniform_type[a]=d.shader.uniform.ARRAY_FLOAT,this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]),this.bindSelf(a),this.uniforms[a]},addInt:function(a,e){return this.use(),this.uniforms[a]=c.gl.getUniformLocation(this.shader,a),this.uniform_type[a]=d.shader.uniform.INT,this.uniform_typelist.push([this.uniforms[a],this.uniform_type[a]]),e!==b&&this.setInt(a,e),this.bindSelf(a),this.uniforms[a]},use:function(){c.gl.useProgram(this.shader)},setMatrix:function(a,b){var d=this.uniforms[a];if(d===null)return;var e=b.length;e===16?c.gl.uniformMatrix4fv(d,!1,b):e===9?c.gl.uniformMatrix3fv(d,!1,b):e===4&&c.gl.uniformMatrix2fv(d,!1,b)},setInt:function(a,b){var d=this.uniforms[a];if(d===null)return;c.gl.uniform1i(d,b)},setFloat:function(a,b){var d=this.uniforms[a];if(d===null)return;c.gl.uniform1f(d,b)},setVector:function(a,b){var d=this.uniforms[a];if(d===null)return;var e=b.length;e==3?c.gl.uniform3fv(d,b):e==2?c.gl.uniform2fv(d,b):c.gl.uniform4fv(d,b)},clearArray:function(a){var b=c.gl,d=this.uniforms[a];if(d===null)return;b.disableVertexAttribArray(d)},bindArray:function(a,b){var e=c.gl,f=this.uniforms[a];if(f===null)return;var g=this.uniform_type[a];g===d.shader.uniform.ARRAY_VERTEX?(e.bindBuffer(e.ARRAY_BUFFER,b),e.vertexAttribPointer(f,3,e.FLOAT,!1,0,0),e.enableVertexAttribArray(f)):g===d.shader.uniform.ARRAY_UV?(e.bindBuffer(e.ARRAY_BUFFER,b),e.vertexAttribPointer(f,2,e.FLOAT,!1,0,0)):g===d.shader.uniform.ARRAY_FLOAT&&(e.bindBuffer(e.ARRAY_BUFFER,b),e.vertexAttribPointer(f,1,e.FLOAT,!1,0,0))}};var k={tidyScript:function(a){return a.replace(/\t+/g," ").replace(/\/\/.*$/gm,"").replace(/\/\*(.|\n)*\*\//g,"").replace(/ +/g," ").replace(/ *\[ */g,"[").replace(/ *\] */g,"]").replace(/ *; */g,";").replace(/ *$/gm,"").replace(/^ */gm,"")},getDefines:function(a){var b={},c=f.multiSplit(a,"\n;");for(i=0,iMax=c.length;i2&&(b[e[1]]=e.slice(2).join(" "))}}return b},replaceAll:function(a,b,c,d){c=c||"",d=d||"";for(var e in b){if(!b.hasOwnProperty(e))continue;var f=c+e+d;while(a.indexOf(f)!==-1)a=a.replace(f,c+b[e]+d)}return a},getShaderInfo:function(a,c){var d,e,g,h,i,j,l=["uniform","attribute","varying"],m=[],n={},o={},p;c===b&&(c=""),a=k.tidyScript(a),c=k.tidyScript(c),n.v_define=k.getDefines(a),n.f_define=k.getDefines(c),a=k.replaceAll(a,n.v_define,"[","]"),c=k.replaceAll(c,n.f_define,"[","]");var q=a+"\n"+c;p=f.multiSplit(q,"\n;");var r=[],s=-1,t=-1;for(d=0,e=p.length;d=z&&y>=A&&(p=H[2]/this.scale[2]+this.scale[2]/2,q=-H[1]/this.scale[1]+this.scale[1]/2,c.faces[w].normal[0]<0?(p=(M[2][2]-M[2][0])*(1-p),q=1-(M[2][3]-M[2][1])*q,p+=M[2][0],q+=M[2][1]):(p=(M[3][2]-M[3][0])*p,q=1-(M[3][3]-M[3][1])*q,p+=M[3][0],q+=M[3][1])),z>=y&&z>=A&&(p=H[0]/this.scale[0]+this.scale[0]/2,q=-H[2]/this.scale[2]+this.scale[2]/2,c.faces[w].normal[1]<0?(p=(M[1][2]-M[1][0])*p,q=1-(M[1][3]-M[1][1])*q,p+=M[1][0],q-=M[1][1]):(p=(M[0][2]-M[0][0])*p,q=1-(M[0][3]-M[0][1])*q,p+=M[0][0],q-=M[0][1])),A>=y&&A>=z&&(p=H[0]/this.scale[0]+this.scale[0]/2,q=H[1]/this.scale[1]+this.scale[1]/2,c.faces[w].normal[2]<0?(p=(M[4][2]-M[4][0])*p,q=1-(M[4][3]-M[4][1])*(1-q),p+=M[4][0],q-=M[4][1]):(p=(M[5][2]-M[5][0])*(1-p),q=1-(M[5][3]-M[5][1])*(1-q),p+=M[5][0],q+=M[5][1])),c.faces[w].setUV([p,q],C)}else if(L===d.uv.projection.CUBIC)y>=z&&y>=A&&(p=H[2]/this.scale[2]+.5,q=H[1]/this.scale[1]+.5),z>=y&&z>=A&&(p=-H[0]/this.scale[0]+.5,q=H[2]/this.scale[2]+.5),A>=y&&A>=z&&(p=-H[0]/this.scale[0]+.5,q=H[1]/this.scale[1]+.5),c.faces[w].normal[0]>0&&(p=-p),c.faces[w].normal[1]<0&&(p=-p),c.faces[w].normal[2]>0&&(p=-p),c.faces[w].setUV([p,q],C);else if(L===d.uv.projection.PLANAR)p=this.projection_axis===d.uv.axis.X?H[2]/this.scale[2]+.5:-H[0]/this.scale[0]+.5,q=this.projection_axis===d.uv.axis.Y?H[2]/this.scale[2]+.5:H[1]/this.scale[1]+.5,c.faces[w].setUV([p,q],C);else if(L===d.uv.projection.CYLINDRICAL)K=this.projection_axis,K===d.uv.axis.X?(s=h(H[2],H[0],-H[1]),q=-H[0]/this.scale[0]+.5):K===d.uv.axis.Y?(s=h(-H[0],H[1],H[2]),q=-H[1]/this.scale[1]+.5):K===d.uv.axis.Z&&(s=h(-H[0],H[2],-H[1]),q=-H[2]/this.scale[2]+.5),s=1-s/f,this.wrap_w_count!==1&&(s*=this.wrap_w_count),n=s,o=q,c.faces[w].setUV([n,o],C);else if(L===d.uv.projection.SPHERICAL){var N,O,P;K=this.projection_axis,K===d.uv.axis.X?(B[E]?N=B[E]:N=i(H[2],H[0],-H[1]),B[E]||(B[E]=N),B[F]?O=B[F]:O=i(I[2],I[0],-I[1]),B[F]||(B[F]=O),B[G]?P=B[G]:P=i(J[2],J[0],-J[1]),B[G]||(B[G]=P)):K===d.uv.axis.Y?(B[E]?N=B[E]:N=i(H[0],-H[1],H[2]),B[E]||(B[E]=N),B[F]?O=B[F]:O=i(I[0],-I[1],I[2]),B[F]||(B[F]=O),B[G]?P=B[G]:P=i(J[0],-J[1],J[2]),B[G]||(B[G]=P)):K===d.uv.axis.Z&&(B[E]?N=B[E]:N=i(-H[0],H[2],-H[1]),B[E]||(B[E]=N),B[F]?O=B[F]:O=i(-I[0],I[2],-I[1]),B[F]||(B[F]=O),B[G]?P=B[G]:P=i(-J[0],J[2],-J[1]),B[G]||(B[G]=P)),Math.abs(N[0]-O[0])>g&&Math.abs(N[0]-P[0])>g&&(N[0]>O[0]&&N[0]>P[0]?N[0]-=f:N[0]+=f),Math.abs(N[1]-O[1])>g&&Math.abs(N[1]-P[1])>g&&(N[1]>O[1]&&N[1]>P[1]?N[1]-=f:N[1]+=f),s=1-N[0]/f,r=.5-N[1]/Math.PI,this.wrap_w_count!==1&&(s*=this.wrap_w_count),this.wrap_h_count!==1&&(r*=this.wrap_h_count),n=s,o=r,c.faces[w].setUV([n,o],C)}else n=0,o=0,c.faces[w].setUV([n,o],C)}}return this}};var k={UVMapper:j};return k}),CubicVR.RegisterModule("Worker",function(a){function n(a){function e(a){var b=a.parsed||function(){},c={},d;a.url.match(/\.dae/)&&(d=new CubicVR.Worker({type:"sceneFile",data:a.url,message:function(a){if(a.message==="loaded"){var e=new DOMParser,g=e.parseFromString(a.data,"text/xml"),h=m.xml2badgerfish(g);console.log(g),d.send("parse",h)}else if(a.message==="getMesh"){var i=new f;for(var j in a.data.mesh)a.data.mesh.hasOwnProperty(j)&&(i[j]=a.data.mesh[j]);i.bindBuffer(i.bufferVBO(a.data.vbo)),c.getMesh&&c.getMesh(i)}else a.message==="parsed"&&b()}})),this.getSceneObject=function(a,b){d.send("getMesh",a),c.getMesh=b}}function j(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}var b=this,c={},d={};this.createSceneFileManager=function(a){var b=new e({url:a.url,parsed:a.parsed});return d[a.url]=b,b},this.removeSceneFileManager=function(a){if(typeof settings=="string")delete d[settings];else for(var b in d)d[b]===a&&delete d[b]},this.createSceneObjectFromMesh=function(a){var c=a.scene,d=a.mesh,e=a.object,k=a.assetBase||"",l=a.options,m=b.createSceneFileManager({url:d,parsed:function(){e&&m.getSceneObject(e,function(a){var b=j(a,new f);for(var d=0,e=b.materials.length;d1&&(m.prev=null,m.next=l.keys[1],m=l.keys[1]);for(var n=1,o=l.keys.length-1;n1&&(m=l.keys[l.keys.length-1],m.prev=l.keys[l.keys.length-2],m.next=null),l.firstKey=l.keys[0],l.lastKey=l.keys[l.keys.length-1],l.keys=l.firstKey;var q=new k;p(l,q),g[h]=q}c[d]=g}a.motion.controllers=c;var r=new j;p(a.motion,r),a.motion=r}}function r(b){var c=new i;p(b,c);if(b.obj!==null){var g=o[b.obj.id];if(g===e){var h=new f;p(b.obj,h),c.obj=h,o[b.obj.id]=h;if(d){if(h.points.length>0){d.addMesh(a,a+":"+h.id,h);for(var j=0,k=h.faces.length;j0&&(c.children=[],s(b,c)),c}function s(a,b){if(a.children)for(var c=0,d=a.children.length;cthis.maxEngineForce&&(this.gEngineForce=this.maxEngineForce),this.gEngineForce<-this.maxEngineForce&&(this.gEngineForce=-this.maxEngineForce)},getEngineForce:function(a){return this.gEngineForce},incEngine:function(a){this.setEngineForce(this.getEngineForce()+a)},decEngine:function(a){this.setEngineForce(this.getEngineForce()-a)},setSteering:function(a){this.gVehicleSteering=a},getSteering:function(a){return this.gVehicleSteering},incSteering:function(a){this.gVehicleSteering+=a,this.gVehicleSteering>this.steeringClamp&&(this.gVehicleSteering=this.steeringClamp),this.gVehicleSteering<-this.steeringClamp&&(this.gVehicleSteering=-this.steeringClamp)},setBrake:function(a){this.gBreakingForce=a},getWheelGroundPosition:function(a){return this.wheels[a].wheelObj.getWorldPosition()-[0,wheels[a].getWheelRadius(),0]},getWheelSkid:function(a){var b=this.m_vehicle.getWheelInfo(a);return b.get_m_skidInfo()},getRigidGround:function(a){var b=this.m_vehicle.getWheelInfo(a)},addWheel:function(a,c){c===b&&(c=this.wheels.length),this.wheels[c]=a},getWheel:function(a){return this.wheels[a]},bindToScene:function(a){var b=this.wheels.length;for(var c=0;c0){var a=this._queuedEvents.shift();if("on"+a.type in this){var b=this["on"+a.type];try{b.call(this,a)}catch(c){debuggerconsole.log(c)}}}return this._queuedEvents.length}var b=a("core/event"),c=function(a,b,c){this.type=a,this.provider=b,this.dependsOn=c||[],this.owner=null,this._queuedEvents=[]};return c.prototype={setOwner:d,handleEvent:e,handleQueuedEvent:f},c}),function(a,b){typeof exports=="object"?module.exports=b():typeof define=="function"&&define.amd?define("_math",[],b):a._Math||(a._Math=b())}(this,function(){var a,b,c;return function(d){function j(a,b){if(a&&a.charAt(0)==="."&&b){b=b.split("/"),b=b.slice(0,b.length-1),a=b.concat(a.split("/"));var c,d;for(c=0;d=a[c];c++)if(d===".")a.splice(c,1),c-=1;else if(d===".."){if(c===1&&(a[2]===".."||a[0]===".."))break;c>0&&(a.splice(c-1,2),c-=2)}a=a.join("/")}return a}function k(a,b){return function(){return i.apply(d,g.call(arguments,0).concat([a,b]))}}function l(a){return function(b){return j(b,a)}}function m(a){return function(b){e[a]=b}}function n(a){if(f.hasOwnProperty(a)){var b=f[a];delete f[a],h.apply(d,b)}return e[a]}function o(a,b){var c,d,e=a.indexOf("!");return e!==-1?(c=j(a.slice(0,e),b),a=a.slice(e+1),d=n(c),d&&d.normalize?a=d.normalize(a,l(b)):a=j(a,b)):a=j(a,b),{f:c?c+"!"+a:a,n:a,p:d}}var e={},f={},g=[].slice,h,i;if(typeof c=="function")return;h=function(a,b,c,g){var h=[],i,j,l,p,q,r;g||(g=a);if(typeof c=="function"){!b.length&&c.length&&(b=["require","exports","module"]);for(p=0;pc)return!1;return!0},length:function(a){var b=0;for(var c=0;cc)return!1;return!0}};return c}}),c("matrix/matrix2",["require","./matrix"],function(a){return function(b){var c=a("./matrix")(b),d=function(){return 0===arguments.length?c.$(4,[0,0,0,0]):c.$(4,arguments)},e={$:d,add:function(a,b){b=b||d();var e=a[0];if(a.length==1)b=e;else for(var f=1;f";for(var d=0;d<4;++d)b+=" ("+a[4*c+d]+") "}return b+=" ]",b}};return Object.defineProperty(f,"zero",{get:function(){return e([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])},enumerable:!0}),Object.defineProperty(f,"one",{get:function(){return e([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])},enumerable:!0}),Object.defineProperty(f,"identity",{get:function(){return e([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])},enumerable:!0}),f}}),c("matrix/transform",["require","./matrix4"],function(a){return function(b){var c=a("./matrix4")(b),d=c.$,e={$:d,fixed:function(a,b,d){var f=c.identity;return a&&e.translate(a,f),b&&e.rotate(b,f),d&&e.scale(d,f),f},rotate:function(a,b){var d=b||c.identity,e,f,g;0!==a[2]&&(e=Math.sin(a[2]),f=Math.cos(a[2]),g=[],g.push(c.$([f,e,0,0,-e,f,0,0,0,0,1,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d)),0!==a[1]&&(e=Math.sin(a[1]),f=Math.cos(a[1]),g=[],g.push(c.$([f,0,-e,0,0,1,0,0,e,0,f,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d)),0!==a[0]&&(e=Math.sin(a[0]),f=Math.cos(a[0]),g=[],g.push(c.$([1,0,0,0,0,f,e,0,0,-e,f,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d));if(!b)return d},scale:function(a,b){var d=[a[0],0,0,0,0,a[1],0,0,0,0,a[2],0,0,0,0,1];if(!b)return d;c.multiply([d,c.$(b)],b)},translate:function(a,b){var d=[1,0,0,0,0,1,0,0,0,0,1,0,a[0],a[1],a[2],1];if(!b)return d;c.multiply([d,c.$(b)],b)}};return e}}),c("_math",["require","./lang","./constants","./vector/vector2","./vector/vector3","./vector/vector4","./vector/quaternion","./matrix/matrix2","./matrix/matrix3","./matrix/matrix4","./matrix/transform"],function(a){var b=a("./lang"),c=a("./constants"),d=a("./vector/vector2"),e=a("./vector/vector3"),f=a("./vector/vector4"),g=a("./vector/quaternion"),h=a("./matrix/matrix2"),i=a("./matrix/matrix3"),j=a("./matrix/matrix4"),k=a("./matrix/transform"),l=function(a){var l={Float32:Float32Array,Float64:Float64Array},m=l.Float32;Object.defineProperty(this,"ARRAY_TYPE",{get:function(){return m},enumerable:!0}),b.extend(this,c());var n=d(m),o=e(m),p=f(m),q=g(m),r=h(m),s=i(m),t=j(m),u=k(m);Object.defineProperty(this,"Vector2",{get:function(){return n.$},enumerable:!0}),Object.defineProperty(this,"vector2",{get:function(){return n},enumerable:!0}),Object.defineProperty(this,"Vector3",{get:function(){return o.$},enumerable:!0}),Object.defineProperty(this,"vector3",{get:function(){return o},enumerable:!0}),Object.defineProperty(this,"Vector4",{get:function(){return p.$},enumerable:!0}),Object.defineProperty(this,"vector4",{get:function(){return p},enumerable:!0}),Object.defineProperty(this,"Quaternion",{get:function(){return q.$},enumerable:!0}),Object.defineProperty(this,"quaternion",{get:function(){return q},enumerable:!0}),Object.defineProperty(this,"Matrix2",{get:function(){return r.$},enumerable:!0}),Object.defineProperty(this,"matrix2",{get:function(){return r},enumerable:!0}),Object.defineProperty(this,"Matrix3",{get:function(){return s.$},enumerable:!0}),Object.defineProperty(this,"matrix3",{get:function(){return s},enumerable:!0}),Object.defineProperty(this,"Matrix4",{get:function(){return t.$},enumerable:!0}),Object.defineProperty(this,"matrix4",{get:function(){return t},enumerable:!0}),Object.defineProperty(this,"Transform",{get:function(){return u.$},enumerable:!0}),Object.defineProperty(this,"transform",{get:function(){return u},enumerable:!0})};return new l}),b("_math")});if(typeof define!="function")var define=require("amdefine")(module);define("src/components/camera",["require","common/extend","base/component","_math"],function(a){function f(a){this._cubicvrCamera.parent.tMatrix=this.owner.findComponent("Transform").absolute(),this._targetHasChanged&&(this._cubicvrCamera.lookat(this.target),this._targetHasChanged=!1),this._cubicvrCamera.calcProjection()}function g(a){var b=a.data;b.previous===null&&b.current!==null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),b.previous!==null&&b.current===null&&this.owner!==null&&this.provider.unregisterComponent(this.owner.id,this)}function h(a){var b=a.data;b.previous===null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),this.owner&&(this._cubicvrCamera.parent.tMatrix=this.owner.findComponent("Transform").absolute()),this.owner===null&&b.previous!==null&&this.provider.unregisterComponent(b.previous.id,this)}function i(a){var b=a.data;b?this.provider.registerComponent(this.owner.id,this):this.provider.unregisterComponent(this.owner.id,this)}function j(a){this.target=a,this._targetHasChanged=!0}var b=a("common/extend"),c=a("base/component"),d=a("_math"),e=function(a,b){c.call(this,"Camera",a,["Transform"]),b=b||{},this._cubicvrCamera=new a.target.context.Camera({width:a.target.context.width,height:a.target.context.height,fov:60,calcNormalMatrix:!0,targeted:b.targeted===undefined?!1:b.targeted}),this._cubicvrCamera.parent={tMatrix:d.matrix4.identity},this.target=[0,0,0],this._targetHasChanged=!1,this._cubicvrCamera.lookat(this.target)};e.prototype=new c,e.prototype.constructor=e;var k={onUpdate:f,onEntitySpaceChanged:g,onComponentOwnerChanged:h,onEntityActivationChanged:i,setTarget:j};return b(e.prototype,k),e});if(typeof define!="function")var define=require("amdefine")(module);define("src/components/model",["require","common/extend","base/component"],function(a){function e(a){a&&(this._cubicvrMaterialDefinition=a)}function f(){return this._cubicvrMaterialDefinition}function g(a){}function h(a){var b=a.data;b.previous===null&&b.current!==null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),b.previous!==null&&b.current===null&&this.owner!==null&&this.provider.unregisterComponent(this.owner.id,this)}function i(a){var b=a.data;b.previous===null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),this.owner===null&&b.previous!==null&&this.provider.unregisterComponent(b.previous.id,this)}function j(a){var b=a.data;b?this.provider.registerComponent(this.owner.id,this):this.provider.unregisterComponent(this.owner.id,this)}var b=a("common/extend"),c=a("base/component"),d=function(a,b,d){c.call(this,"Model",a,["Transform"]),this._cubicvrMesh=b||new a.target.context.Mesh,e.call(this,d||new a.target.context.Material)};d.prototype=new c,d.prototype.constructor=d;var k={getMaterialDefinition:f,setMaterialDefinition:e,onUpdate:g,onEntitySpaceChanged:h,onComponentOwnerChanged:i,onEntityActivationChanged:j};return b(d.prototype,k),d});if(typeof define!="function")var define=require("amdefine")(module);define("src/resources/mesh",["require"],function(a){var b=function(a,b){var c=new a.target.context.Mesh(b);return c._gladius={},c.prepare(),c};return b});if(typeof define!="function")var define=require("amdefine")(module);define("src/resources/material-definition",["require"],function(a){var b=function(a,b){var c=new a.target.context.Material(b);return c._gladius={},c};return b});if(typeof define!="function")var define=require("amdefine")(module);define("src/resources/light-definition",["require"],function(a){var b=function(a){a=a||{},this._gladius={},this.light_type=a.light_type!==undefined?a.light_type:b.LightTypes.POINT,this.diffuse=a.diffuse!==undefined?a.diffuse:[1,1,1],this.specular=a.specular!==undefined?a.specular:[1,1,1],this.intensity=a.intensity!==undefined?a.intensity:1,this.distance=a.distance!==undefined?a.distance:this.light_type===b.LightTypes.AREA?30:10,this.cutoff=a.cutoff!==undefined?a.cutoff:60,this.map_res=a.map_res!==undefined?a.map_res:this.light_type===b.LightTypes.AREA?2048:512,this.method=a.method!==undefined?a.method:b.LightingMethods.DYNAMIC,this.areaCeiling=a.areaCeiling!==undefined?a.areaCeiling:40,this.areaFloor=a.areaFloor!==undefined?a.areaFloor:-40,this.areaAxis=a.areaAxis!==undefined?a.areaAxis:[1,1,0]};return b.LightTypes={NULL:0,POINT:1,DIRECTIONAL:2,SPOT:3,AREA:4},b.LightingMethods={GLOBAL:0,STATIC:1,DYNAMIC:2},b});if(typeof define!="function")var define=require("amdefine")(module);define("src/components/light",["require","src/resources/light-definition","base/component","common/extend","_math"],function(a){function h(a){for(var b=0;b";for(var d=0;d<4;++d)b+=" ("+a[4*c+d]+") "}return b+=" ]",b}};return Object.defineProperty(f,"zero",{get:function(){return e([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])},enumerable:!0}),Object.defineProperty(f,"one",{get:function(){return e([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])},enumerable:!0}),Object.defineProperty(f,"identity",{get:function(){return e([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])},enumerable:!0}),f}}),c("matrix/transform",["require","./matrix4"],function(a){return function(b){var c=a("./matrix4")(b),d=c.$,e={$:d,fixed:function(a,b,d){var f=c.identity;return a&&e.translate(a,f),b&&e.rotate(b,f),d&&e.scale(d,f),f},rotate:function(a,b){var d=b||c.identity,e,f,g;0!==a[2]&&(e=Math.sin(a[2]),f=Math.cos(a[2]),g=[],g.push(c.$([f,e,0,0,-e,f,0,0,0,0,1,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d)),0!==a[1]&&(e=Math.sin(a[1]),f=Math.cos(a[1]),g=[],g.push(c.$([f,0,-e,0,0,1,0,0,e,0,f,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d)),0!==a[0]&&(e=Math.sin(a[0]),f=Math.cos(a[0]),g=[],g.push(c.$([1,0,0,0,0,f,e,0,0,-e,f,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d));if(!b)return d},scale:function(a,b){var d=[a[0],0,0,0,0,a[1],0,0,0,0,a[2],0,0,0,0,1];if(!b)return d;c.multiply([d,c.$(b)],b)},translate:function(a,b){var d=[1,0,0,0,0,1,0,0,0,0,1,0,a[0],a[1],a[2],1];if(!b)return d;c.multiply([d,c.$(b)],b)}};return e}}),c("_math",["require","./lang","./constants","./vector/vector2","./vector/vector3","./vector/vector4","./vector/quaternion","./matrix/matrix2","./matrix/matrix3","./matrix/matrix4","./matrix/transform"],function(a){var b=a("./lang"),c=a("./constants"),d=a("./vector/vector2"),e=a("./vector/vector3"),f=a("./vector/vector4"),g=a("./vector/quaternion"),h=a("./matrix/matrix2"),i=a("./matrix/matrix3"),j=a("./matrix/matrix4"),k=a("./matrix/transform"),l=function(a){var l={Float32:Float32Array,Float64:Float64Array},m=l.Float32;Object.defineProperty(this,"ARRAY_TYPE",{get:function(){return m},enumerable:!0}),b.extend(this,c());var n=d(m),o=e(m),p=f(m),q=g(m),r=h(m),s=i(m),t=j(m),u=k(m);Object.defineProperty(this,"Vector2",{get:function(){return n.$},enumerable:!0}),Object.defineProperty(this,"vector2",{get:function(){return n},enumerable:!0}),Object.defineProperty(this,"Vector3",{get:function(){return o.$},enumerable:!0}),Object.defineProperty(this,"vector3",{get:function(){return o},enumerable:!0}),Object.defineProperty(this,"Vector4",{get:function(){return p.$},enumerable:!0}),Object.defineProperty(this,"vector4",{get:function(){return p},enumerable:!0}),Object.defineProperty(this,"Quaternion",{get:function(){return q.$},enumerable:!0}),Object.defineProperty(this,"quaternion",{get:function(){return q},enumerable:!0}),Object.defineProperty(this,"Matrix2",{get:function(){return r.$},enumerable:!0}),Object.defineProperty(this,"matrix2",{get:function(){return r},enumerable:!0}),Object.defineProperty(this,"Matrix3",{get:function(){return s.$},enumerable:!0}),Object.defineProperty(this,"matrix3",{get:function(){return s},enumerable:!0}),Object.defineProperty(this,"Matrix4",{get:function(){return t.$},enumerable:!0}),Object.defineProperty(this,"matrix4",{get:function(){return t},enumerable:!0}),Object.defineProperty(this,"Transform",{get:function(){return u.$},enumerable:!0}),Object.defineProperty(this,"transform",{get:function(){return u},enumerable:!0})};return new l}),b("_math")});if(typeof define!="function")var define=require("amdefine")(module);define("src/components/camera",["require","common/extend","base/component","_math"],function(a){function f(a){this._cubicvrCamera.parent.tMatrix=this.owner.findComponent("Transform").absolute(),this._targetHasChanged&&(this._cubicvrCamera.lookat(this.target),this._targetHasChanged=!1),this._cubicvrCamera.calcProjection()}function g(a){var b=a.data;b.previous===null&&b.current!==null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),b.previous!==null&&b.current===null&&this.owner!==null&&this.provider.unregisterComponent(this.owner.id,this)}function h(a){var b=a.data;b.previous===null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),this.owner&&(this._cubicvrCamera.parent.tMatrix=this.owner.findComponent("Transform").absolute()),this.owner===null&&b.previous!==null&&this.provider.unregisterComponent(b.previous.id,this)}function i(a){var b=a.data;b?this.provider.registerComponent(this.owner.id,this):this.provider.unregisterComponent(this.owner.id,this)}function j(a){this.target=a,this._targetHasChanged=!0}var b=a("common/extend"),c=a("base/component"),d=a("_math"),e=function(a,b){c.call(this,"Camera",a,["Transform"]),b=b||{},this._cubicvrCamera=new a.target.context.Camera({width:a.target.context.width,height:a.target.context.height,fov:60,calcNormalMatrix:!0,targeted:b.targeted===undefined?!1:b.targeted}),this._cubicvrCamera.parent={tMatrix:d.matrix4.identity},this.target=[0,0,0],this._targetHasChanged=!1,this._cubicvrCamera.lookat(this.target)};e.prototype=new c,e.prototype.constructor=e;var k={onUpdate:f,onEntitySpaceChanged:g,onComponentOwnerChanged:h,onEntityActivationChanged:i,setTarget:j};return b(e.prototype,k),e});if(typeof define!="function")var define=require("amdefine")(module);define("src/components/model",["require","common/extend","base/component"],function(a){function e(a){this._cubicvrMaterialDefinition=a}function f(){return this._cubicvrMaterialDefinition}function g(a){this._cubicvrMesh=a}function h(){return this._cubicvrMesh}function i(a){}function j(a){var b=a.data;b.previous===null&&b.current!==null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),b.previous!==null&&b.current===null&&this.owner!==null&&this.provider.unregisterComponent(this.owner.id,this)}function k(a){var b=a.data;b.previous===null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),this.owner===null&&b.previous!==null&&this.provider.unregisterComponent(b.previous.id,this)}function l(a){var b=a.data;b?this.provider.registerComponent(this.owner.id,this):this.provider.unregisterComponent(this.owner.id,this)}var b=a("common/extend"),c=a("base/component"),d=function(a,b,d){c.call(this,"Model",a,["Transform"]),this._cubicvrMesh=null,this._cubicvrMaterialDefinition=null,g.call(this,b||new a.target.context.Mesh),e.call(this,d||new a.target.context.Material)};d.prototype=new c,d.prototype.constructor=d;var m={getMaterialDefinition:f,setMaterialDefinition:e,getMesh:h,setMesh:g,onUpdate:i,onEntitySpaceChanged:j,onComponentOwnerChanged:k,onEntityActivationChanged:l};return b(d.prototype,m),d});if(typeof define!="function")var define=require("amdefine")(module);define("src/resources/mesh",["require"],function(a){var b=function(a,b){var c=new a.target.context.Mesh(b);return c._gladius={},c.prepare(),c};return b});if(typeof define!="function")var define=require("amdefine")(module);define("src/resources/material-definition",["require"],function(a){var b=function(a,b){var c=new a.target.context.Material(b);return c._gladius={},c};return b});if(typeof define!="function")var define=require("amdefine")(module);define("src/resources/light-definition",["require"],function(a){var b=function(a){a=a||{},this._gladius={},this.light_type=a.light_type!==undefined?a.light_type:b.LightTypes.POINT,this.diffuse=a.diffuse!==undefined?a.diffuse:[1,1,1],this.specular=a.specular!==undefined?a.specular:[1,1,1],this.intensity=a.intensity!==undefined?a.intensity:1,this.distance=a.distance!==undefined?a.distance:this.light_type===b.LightTypes.AREA?30:10,this.cutoff=a.cutoff!==undefined?a.cutoff:60,this.map_res=a.map_res!==undefined?a.map_res:this.light_type===b.LightTypes.AREA?2048:512,this.method=a.method!==undefined?a.method:b.LightingMethods.DYNAMIC,this.areaCeiling=a.areaCeiling!==undefined?a.areaCeiling:40,this.areaFloor=a.areaFloor!==undefined?a.areaFloor:-40,this.areaAxis=a.areaAxis!==undefined?a.areaAxis:[1,1,0]};return b.LightTypes={NULL:0,POINT:1,DIRECTIONAL:2,SPOT:3,AREA:4},b.LightingMethods={GLOBAL:0,STATIC:1,DYNAMIC:2},b});if(typeof define!="function")var define=require("amdefine")(module);define("src/components/light",["require","src/resources/light-definition","base/component","common/extend","_math"],function(a){function h(a){for(var b=0;b