-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgladius-cubicvr.min.js
24 lines (21 loc) · 338 KB
/
gladius-cubicvr.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
Copyright (c) 2011-2012, Mozilla Foundation
Copyright (c) 2011-2012, Alan Kligman
Copyright (c) 2011-2012, Robert Richter
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the Mozilla Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/(function(a,b){if(typeof exports=="object")module.exports=b();else if(typeof define=="function"&&define.amd)define(b);else{if(!a.Gladius)throw new Error("failed to load gladius-cubicvr; depends on Gladius");a.Gladius["gladius-cubicvr"]=b()}})(this,function(){var requirejs,require,define;(function(a){function g(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 h(b,c){return function(){return f.apply(a,d.call(arguments,0).concat([b,c]))}}function i(a){return function(b){return g(b,a)}}function j(a){return function(c){b[a]=c}}function k(d){if(c.hasOwnProperty(d)){var f=c[d];delete c[d],e.apply(a,f)}return b[d]}function l(a,b){var c,d,e=a.indexOf("!");return e!==-1?(c=g(a.slice(0,e),b),a=a.slice(e+1),d=k(c),d&&d.normalize?a=d.normalize(a,i(b)):a=g(a,b)):a=g(a,b),{f:c?c+"!"+a:a,n:a,p:d}}var b={},c={},d=[].slice,e,f;if(typeof define=="function")return;e=function(d,e,f,g){var i=[],m,n,o,p,q,r;g||(g=d);if(typeof f=="function"){!e.length&&f.length&&(e=["require","exports","module"]);for(p=0;p<e.length;p++){r=l(e[p],g),o=r.f;if(o==="require")i[p]=h(d);else if(o==="exports")i[p]=b[d]={},m=!0;else if(o==="module")n=i[p]={id:d,uri:"",exports:b[d]};else if(b.hasOwnProperty(o)||c.hasOwnProperty(o))i[p]=k(o);else{if(!r.p)throw d+" missing "+o;r.p.load(r.n,h(g,!0),j(o),{}),i[p]=b[o]}}q=f.apply(b[d],i),d&&(n&&n.exports!==a?b[d]=n.exports:m||(b[d]=q))}else d&&(b[d]=f)},requirejs=f=function(b,c,d,g){return typeof b=="string"?k(l(b,c).f):(b.splice||(c.splice?(b=c,c=arguments[2]):b=[]),g?e(a,b,c,d):setTimeout(function(){e(a,b,c,d)},15),f)},f.config=function(){return f},require||(require=f),define=function(a,b,d){b.splice||(d=b,b=[]),define.unordered?c[a]=[a,b,d]:e(a,b,d)},define.amd={jQuery:!0}})(),define("../tools/almond",function(){});if(typeof define!="function")var define=require("amdefine")(module);define("base/extension",["require"],function(a){var b=function(a,b){if(typeof a!="string"||a.length===0)throw new Error("extension needs a non-trivial name");this.name=a,b=b||{};var c,d,e,f,g,h,i,j,k,l,m,n,o;this.services={};if(b.hasOwnProperty("services")){c=Object.keys(b.services);for(l=0,m=c.length;l<m;++l){d=c[l],e=b.services[d];if(typeof e=="function")this.services[d]=e;else{if(typeof e!="object")throw new Error("malformed extension");this.services[d]={},this.services[d].service=e.service;if(e.hasOwnProperty("components")){this.services[d].components={},f=Object.keys(e.components);for(n=0,o=f.length;n<o;++n)g=f[n],this.services[d].components[g]=e.components[g]}if(e.hasOwnProperty("resources")){this.services[d].resources={},i=Object.keys(e.resources);for(n=0,o=i.length;n<o;++n)j=i[n],this.services[d].resources[j]=e.resources[j]}}}}this.components={},b.hasOwnProperty("components")&&(this.components=b.components),this.resources={},b.hasOwnProperty("resources")&&(this.resources=b.resources)};return b});if(typeof define!="function")var define=require("amdefine")(module);define("common/guid",["require"],function(a){function b(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=Math.random()*16|0,c=a=="x"?b:b&3|8;return c.toString(16)}).toUpperCase()}return b}),function(a){a("when",[],function(){function d(){}function e(a){return new Array(a)}function f(){}function g(b){var d=new f;return d.then=function(a){i(arguments);var d;try{return a&&(d=a(b)),m(d===c?b:d)}catch(e){return h(e)}},a(d)}function h(b){var d=new f;return d.then=function(a,d){i(arguments);var e;try{return d?(e=d(b),m(e===c?b:e)):h(b)}catch(f){return h(f)}},a(d)}function i(a){var b,c=a.length;while(c){b=a[--c];if(b!=null&&typeof b!="function")throw new Error("callback is not a function")}}function j(){function o(a,b,c){return l(a,b,c)}function p(a){n(g(a))}function q(a){n(h(a))}function r(a){m(a)}var b,d,e,k,l,m,n;return e=[],k=[],l=function(b,c,d){i(arguments);var f=j();return e.push(function(a){a.then(b,c).then(f.resolve,f.reject,f.progress)}),d&&k.push(d),f.promise},m=function(a){var b,c=0;while(b=k[c++])b(a)},n=function(a){var b,d=0;l=a.then,n=m=function(){throw new Error("already completed")},k=c;while(b=e[d++])b(a);e=[]},b={},d=new f,d.then=b.then=o,b.promise=a(d),b.resolver=a({resolve:b.resolve=p,reject:b.reject=q,progress:b.progress=r}),b}function k(a){return a&&typeof a.then=="function"}function l(a,b,c,d){var e=m(a);return e.then(b,c,d)}function m(a){var b,c;return a instanceof f?b=a:(c=j(),k(a)?(a.then(c.resolve,c.reject,c.progress),b=c.promise):(c.resolve(a),b=c.promise)),b}function n(a,b,c,e,f){function r(a){m(a)}function s(a){n(a)}function t(a){o(a)}function u(){m=n=o=d}var g,h,i,k,m,n,o,p,q;p=a.length>>>0,g=Math.max(0,Math.min(b,p)),h=[],k=j(),i=l(k,c,e,f);if(!g)k.resolve(h);else{m=function(a){h.push(a),--g||(u(),k.resolve(h))},n=function(a){u(),k.reject(a)},o=k.progress;for(q=0;q<p;++q)q in a&&l(a[q],r,s,t)}return i}function o(a,b,c,d){var f,g;return f=e(a.length),g=s(a,p,f),l(g,b,c,d)}function p(a,b,c){return a[c]=b,a}function q(a,b,c,d){function e(a){return b(a[0])}return n(a,1,e,c,d)}function r(a,b){var c,d;d=a.length,c=e(d);for(;d>=0;--d)d in a&&(c[d]=l(a[d],b));return s(c,p,c)}function s(a,c,d){var e,f;return e=a.length,f=[function(a,b,d){return l(a,function(a){return l(b,function(b){return c(a,b,d,e)})})}],arguments.length>=3&&f.push(d),m(b.apply(a,f))}function t(a,b,c){var d=arguments.length>2;return l(a,function(a){return d&&(a=c),b.resolve(a),a},function(a){return b.reject(a),h(a)},b.progress)}var a,b,c;return a=Object.freeze||function(a){return a},b=[].reduce||function(a){var b,c,d,e,f;f=0,b=Object(this),e=b.length>>>0,c=arguments;if(c.length<=1)for(;;){if(f in b){d=b[f++];break}if(++f>=e)throw new TypeError}else d=c[1];for(;f<e;++f)f in b&&(d=a(d,b[f],f,b));return d},l.defer=j,l.isPromise=k,l.some=n,l.all=o,l.any=q,l.reduce=s,l.map=r,l.chain=t,l})}(typeof define=="function"?define:function(a){typeof module!="undefined"?module.exports=a():this.when=a()});if(typeof define!="function")var define=require("amdefine")(module);define("core/function-task",["require","common/guid","when"],function(a){function o(a){this._schedule=a||this._schedule;if(this._taskState!==g)throw new Error("task is already started or completed");return this._taskState=f,this._runState!==k&&this._scheduler.insert(this,this.id,this._schedule),this}function p(){if(this._runState===j)throw new Error("task can only be paused while blocked");return this._taskState=g,this._scheduler.remove(this.id),this}function q(){if(this._runState===j)throw new Error("tasks can only be cancelled while blocked");return this._taskState=h,this._scheduler.insert(this,this.id),this}function r(){return this._taskState===f}function s(){return this._runState===j}function t(){return this._taskState===i}function u(){var a=this,b=a.result;a.result=undefined,a._scheduler.current=a;try{a._runState=j;if(a._taskState===h)a._runState=l,a._taskState=i;else{if(a._taskState!==f)throw Error("task is not runnable");b=a._thunk.call(this._context,b),a._runState=k,b instanceof d?(a.result=b.value,a._taskState=i,a._runState=l,a._deferred.resolve(a.result)):a.result=c(b,function(b){a.result=b,a._runState=l,a._taskState===f&&a._scheduler.insert(a,a.id,a._schedule)},function(b){a.result=b,a._runState=m,a._threadState===f&&a._scheduler.insert(a,a.id,a._schedule)})}}catch(e){a.result=e,a._runState=m,a._deferred.reject(e)}return a._scheduler.current=null,this}function v(){return"[object FunctionTask "+this.id+"]"}var b=a("common/guid"),c=a("when"),d=function(a){if(!(this instanceof d))return new d(a);this.value=a},e=function(){if(!(this instanceof e))return new e;this.tags=[],this.dependsOn=[]},f=0,g=1,h=2,i=3,j=0,k=1,l=2,m=3,n=function(a,d,f,h){this.id=b(),this._thunk=d,this._taskState=g,this._runState=l,this._scheduler=a,this._schedule=f||e(),this.result=undefined,this._deferred=c.defer(),this.then=this._deferred.promise.then,this._context=h||this};return n.prototype={pause:p,start:o,cancel:q,isStarted:r,isRunning:s,isComplete:t,toString:v,run:u,when:c,Complete:d},n});if(typeof define!="function")var define=require("amdefine")(module);define("base/service",["require","core/function-task"],function(a){function d(a,b){return this._registeredComponents.hasOwnProperty(b.type)||(this._registeredComponents[b.type]={}),this._registeredComponents[b.type][a]=b,this}function e(a,b){return this._registeredComponents.hasOwnProperty(b.type)&&this._registeredComponents[b.type].hasOwnProperty(a)&&delete this._registeredComponents[b.type][a],this}function f(){var a,b,c=Object.keys(this._tasks);for(a=0,b=c.length;a<b;++a){var d=c[a];this._tasks[d].pause()}return this}function g(){var a,b,c=Object.keys(this._tasks);for(a=0,b=c.length;a<b;++a){var d=c[a],e=this._schedules[d]||{};this._tasks[d].start(e)}return this}function h(a){var b,c;if("on"+a.type in this){var d=this["on"+a.type];try{d.call(this,a)}catch(e){console.log(e)}}}var b=a("core/function-task"),c=function(a,c,d){this._schedules=c||{},this.dependsOn=d||[],this._tasks={},this._registeredComponents={};if(a){var e,f,g=Object.keys(this._schedules);for(e=0,f=g.length;e<f;++e){var h=g[e];if(!this[h])throw new Error("missing scheduler target: "+h);var i=this._schedules[h]||{};this._tasks[h]=new b(a,this[h],i,this),this._tasks[h].start()}}};return c.prototype={registerComponent:d,unregisterComponent:e,suspend:f,resume:g,handleEvent:h},c});try{window||(self.window=self,self.document={},self.fakeWindow=!0,self.console={log:function(){}})}catch(e){self.window=self,self.document={},self.fakeWindow=!0,self.console={log:function(){}}}(function(a,b,c,d,e){function r(a,b){if(typeof a!="object")return o("enumerator validation failed, invalid type base object."),e;if(b===e)return e;if(typeof b=="number")return b;if(typeof b=="string"){var c=parseInt(b,10);if(b!==""&&isFinite(c))return c;var d=b.toUpperCase(),f=a[d];if(f!==e)return f;o("enumerator validation failed, unknown enum value: "+b);var g="";for(var h in a)a.hasOwnProperty(h)&&(g!==""&&(g+=", "),g+=h.toLowerCase());return o("possible enum values are: "+g),e}return e}var f=2*c.PI,g=c.PI/2,h="";try{var i=b.querySelectorAll("script");for(var j=0,k=i.length;j<k;j++){var l=i[j].src.lastIndexOf("/CubicVR.js");l>-1&&(h=i[j].src.substr(0,l)+"/")}}catch(m){}var n=a.CubicVR={};n.contexts={};var o;try{o=console!==undefined&&console.log?function(a){console.log("CubicVR Log: "+a)}:function(){}}catch(p){o=d}var q={quality:{LOW:0,MEDIUM:1,HIGH:2}};a.cubicvr=q;var s={},t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],u=function(f){function k(){for(var a in s){var b=s[a](g);for(var c in b)b.hasOwnProperty(c)&&(g[c]=b[c])}}function p(a,b,c,d,f){typeof a=="string"&&a.toLowerCase()==="auto"&&(a=e),c=c||"Sorry, your browser does not appear to support WebGL :-(";var h=m(a,d,f);if(h)return b&&typeof b=="function"&&b(h,g.getCanvas()),h;if(!h)return c&&typeof c=="function"?c():alert(c),!1}var g=this,i;f&&(i=f+"",Object.defineProperty(this,"context",{enumerable:!0,configurable:!1,get:function(){return i}})),g.undef=e,g.nop=d,g.scriptLocation=h,g.GLCore=l,g.Textures=[],g.Textures_obj=[],g.Textures_ref=[],g.Images=[],g.ShaderPool=[],g.log=o,g.enums=n.enums,g.MAX_LIGHTS=6,g.features={},g.quality=n.enums.HIGH;var j={low:{antiAlias:!1,lightPerPixel:!1,lightShadows:!1,texturePerPixel:!1,postProcess:!1},medium:{antiAlias:!1,lightPerPixel:!0,lightShadows:!1,texturePerPixel:!1,postProcess:!1},high:{antiAlias:!0,lightPerPixel:!0,lightShadows:!0,texturePerPixel:!0,postProcess:!0}};g.features=j.high;var l={CoreShader_vs:null,CoreShader_fs:null,canvas:null,width:null,height:null,fixed_aspect:0,fixed_size:null,depth_alpha:!1,default_filter:1,mainloop:null,shadow_near:.1,shadow_far:100,soft_shadow:!1,resize_active:!1,emptyLight:null,resizeList:[],canvasSizeFactor:1};l.init=function(d,f,i){var j,k=g.util,m=n.enums,p;f&&i?(f=k.getScriptContents(f),i=k.getScriptContents(i)):a.CubicVRShader.CubicVRCoreVS&&a.CubicVRShader.CubicVRCoreFS?(f=a.CubicVRShader.CubicVRCoreVS,i=a.CubicVRShader.CubicVRCoreFS):(f=k.getScriptContents(h+"CubicVR_Core.vs"),i=k.getScriptContents(h+"CubicVR_Core.fs"));if(d===e){d=b.createElement("canvas");if(!j)try{j=d.getContext("experimental-webgl",{antialias:g.features.antiAlias})}catch(q){return null}l.gl=j;if(l.fixed_size!==null)l.width=l.fixed_size[0],l.height=l.fixed_size[1],l.resizeElement(d,l.width,l.height);else{l.addResizeable(d);if(l.canvasSizeFactor!==1&&d.getContext!==e){var r=c.round(a.innerWidth*l.canvasSizeFactor),s=c.round(a.innerHeight*l.canvasSizeFactor);l.resizeElement(d,r,s),d.style.top=a.innerHeight/2-s/2+"px",d.style.left=a.innerWidth/2-r/2+"px",d.style.position="absolute"}else l.resizeElement(d,a.innerWidth,a.innerHeight)}b.body.appendChild(d)}if(d.getContext!==e&&d.width!==e&&d.height!==e){try{j||(j=d.getContext("experimental-webgl",{antialias:g.features.antiAlias})),j.viewport(0,0,d.width,d.height),l.canvas=d,l.width=d.width,l.height=d.height,j.clearColor(0,0,0,1),j.clearDepth(1),j.enable(j.DEPTH_TEST),j.depthFunc(j.LEQUAL)}catch(t){}if(!j)return null}else j=d;l.gl=j,l.CoreShader_vs=f,l.CoreShader_fs=i,j.enable(j.CULL_FACE),j.cullFace(j.BACK),j.frontFace(j.CCW);for(p=n.enums.light.type.NULL;p<m.light.type.MAX;p++)g.ShaderPool[p]=[];var u=new g.Texture,v=new g.Material;for(p=0;p<m.texture.map.MAX;p++){if(p===m.texture.map.BUMP)continue;v.setTexture(u,p)}v.opacity=.5;var w=1;for(;;){if(!v.use(m.light.type.POINT,w)||w===8){g.MAX_LIGHTS=w;break}w++}var x=l.emptyLight=new g.Light(m.light.type.POINT);x.diffuse=[0,0,0],x.specular=[0,0,0],x.distance=0,x.intensity=0,x.cutoff=0,o("Calibrated maximum lights per pass to: "+w);for(p=m.light.type.NULL;p<m.light.type.MAX;p++)g.ShaderPool[p]=[];return l.resizeList.length&&(a.addEventListener("resize",function(){g.GLCore.onResize()},!1),l.resize_active=!0),j},l.addResizeable=function(a){g.GLCore.resizeList.push(a)},l.onResize=function(){var b=a.innerWidth,c=a.innerHeight;l.fixed_size!==null&&(b=g.GLCore.fixed_size[0],c=g.GLCore.fixed_size[1]);for(var d=0,e=g.GLCore.resizeList.length;d<e;d++)l.resizeElement(g.GLCore.resizeList[d],b,c)},l.setFixedAspect=function(a){g.GLCore.fixed_aspect=a},l.setFixedSize=function(a,b){g.GLCore.fixed_size=[a,b]},l.getCanvas=function(){return g.GLCore.canvas},l.resizeElement=function(b,c,d){var f=l.gl;if(l.fixed_aspect!==0){var h=c*(1/g.GLCore.fixed_aspect);h>d&&(h=d,c=d*g.GLCore.fixed_aspect),d=h}b.getContext!==e?(b.width=c,b.height=d,g.GLCore.fixed_size||(b.style.left=(a.innerWidth/2-c/2|0)+"px",b.style.top=(a.innerHeight/2-d/2|0)+"px",b.style.position="absolute"),f.viewport(0,0,c,d)):b.resize(c,d)},l.setDepthAlpha=function(a,b,c){l.depth_alpha=a,l.depth_alpha_near=b,l.depth_alpha_far=c},l.setDefaultFilter=function(a){l.default_filter=r(g.enums.texture.filter,a)},l.setSoftShadows=function(a){l.soft_shadow=a},l.setCanvasSizeFactor=function(a){l.canvasSizeFactor=a},l.setQuality=function(a){return a=r(q.quality,a),a===q.quality.HIGH?g.features=j.high:a===q.quality.MEDIUM?g.features=j.medium:a===q.quality.LOW&&(g.features=j.low),g.quality=a,g.features},l.getQuality=function(a){return g.features};var m=function(a,c,d){var e,f=b.getElementsByTagName("script");for(var g=0;g<f.length;++g){var h=f[g];if(!h.getAttribute("data-cubicvr"))continue;var i=h.getAttribute("src");if(i){var j=new XMLHttpRequest;j.open("GET",i,!1),j.send(null);if(j.status===200||j.status===0)h.text=j.responseText}}return typeof a=="object"?a.getContext?e=a:(e=a.canvas,c=a.vertexShader||c,d=a.fragmentShader||d):a&&(a[0]=="#"&&(a=a.substr(1)),e=b.getElementById(a)),k(),l.init(e,c,d),l.gl};g.GLCore=l,g.init=m,g.start=p,g.addResizeable=l.addResizeable,g.setFixedAspect=l.setFixedAspect,g.setFixedSize=l.setFixedSize,g.setCanvasSizeFactor=l.setCanvasSizeFactor,g.getCanvas=l.getCanvas,g.enums=q,g.IdentityMatrix=t,g.Textures=g.Textures,g.Textures_obj=g.Textures_obj,g.Images=g.Images,g.globalAmbient=[.1,.1,.1],g.setGlobalAmbient=function(a){g.globalAmbient=a},g.setGlobalDepthAlpha=l.setDepthAlpha,g.setDefaultFilter=l.setDefaultFilter,g.setSoftShadows=l.setSoftShadows,g.setQuality=l.setQuality,g.getQuality=l.getQuality,g.RegisterModule=n.RegisterModule,g.getScriptLocation=n.getScriptLocation,g.parseEnum=r};n.init=function(b,c,d){var e,f;return b&&b.context&&typeof b.context=="string"&&(e=b.context),f=new u(e),f.context?(n.contexts[f.context]=f,f.init(b,c,d),f):(a.CubicVR=n=f,f.init(b,c,d),f.GLCore.gl)},n.start=function(b,c,d,e,f){var g=new u;return a.CubicVR=n=g,g.start(b,c,d,e,f),g},n.RegisterModule=function(a,b){s[a]=b},n.getScriptLocation=function(){return h},n.enums=q})(window,window.document,Math,function(){}),window.CubicVRShader={},CubicVR.RegisterModule("Math",function(a){function k(a){return this.clearStack(a)}function l(){arguments.length===1&&(this.x=arguments[0][0],this.y=arguments[0][1],this.z=arguments[0][2],this.w=arguments[0][3]),arguments.length===4&&(this.x=arguments[0],this.y=arguments[1],this.z=arguments[2],this.w=arguments[3])}var b=a.undef,c=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],d=2*Math.PI,e=Math.PI/2,f={equal:function(a,c,d){return d===b&&(d=1e-8),a===b&&c===b?!0:a===b||c===b?!1:Math.abs(a[0]-c[0])<d&&Math.abs(a[1]-c[1])<d}},g={length:function(a){var b=a[0],c=a[1],d=a[2];return Math.sqrt(b*b+c*c+d*d)},normalize:function(a){var b=a[0],c=a[1],d=a[2],e=Math.sqrt(b*b+c*c+d*d);return e?[a[0]/e,a[1]/e,a[2]/e]:[0,0,0]},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},angle:function(a,b){var c=Math.acos((a[0]*b[0]+a[1]*b[1]+a[2]*b[2])/(Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])*Math.sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2])));return c},cross:function(a,b){return[a[1]*b[2]-b[1]*a[2],a[2]*b[0]-b[2]*a[0],a[0]*b[1]-b[0]*a[1]]},multiply:function(a,b){return[a[0]*b,a[1]*b,a[2]*b]},add:function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2]]},subtract:function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2]]},equal:function(a,c,d){return d===b&&(d=1e-7),a===b&&c===b?!0:a===b||c===b?!1:Math.abs(a[0]-c[0])<d&&Math.abs(a[1]-c[1])<d&&Math.abs(a[2]-c[2])<d},moveViewRelative:function(a,b,c,d,f){var g=Math.atan2(d,c),h=Math.atan2(b[2]-a[2],b[0]-a[0]),i=Math.sqrt(c*c+d*d),j=h+g+e;return typeof f=="object"?[f[0]+i*Math.cos(j),f[1],f[2]+i*Math.sin(j)]:[a[0]+i*Math.cos(j),a[1],a[2]+i*Math.sin(j)]},trackTarget:function(a,b,c,d){var e=g.subtract(b,a),f=e,h=g.length(f),i=e;i=g.normalize(i),i=g.multiply(i,c*(1/(1/(h-d))));var j;return h>d?j=g.add(a,i):h<d?(i=e,i=g.normalize(i),i=g.multiply(i,c*(1/(1/Math.abs(h-d)))),j=g.subtract(a,i)):j=[a[0],a[1]+i[2],a[2]],j},getClosestTo:function(a,b,c){var d,e,f;return d=g.subtract(b,a),e=g.subtract(c,a),f=g.add(g.multiply(d,g.dot(d,e)/g.dot(d,d)),a),f},linePlaneIntersect:function(a,b,c,d){var e,f,g=-a[0]*b[0]-a[1]*b[1]-a[2]*b[2];return e=a[0]*(d[0]-c[0])+a[1]*(d[1]-c[1])+a[2]*(d[2]-c[2]),Math.abs(e)<.001?!1:(f=-(g+a[0]*c[0]+a[1]*c[1]+a[2]*c[2])/e,[c[0]+f*(d[0]-c[0]),c[1]+f*(d[1]-c[1]),c[2]+f*(d[2]-c[2])])}},h={normal:function(a,c,d,e){e===b&&(e=[]);var f=a[0]-c[0],g=a[1]-c[1],h=a[2]-c[2],i=c[0]-d[0],j=c[1]-d[1],k=c[2]-d[2];return e[0]=g*k-h*j,e[1]=h*i-f*k,e[2]=f*j-g*i,e}},i={transpose_inline:function(a){var b=a[1],c=a[2],d=a[5];a[1]=a[3],a[2]=a[6],a[3]=b,a[5]=a[7],a[6]=c,a[7]=d},vec3_multiply:function(a,c,d){return d===b&&(d=[]),d[0]=c[0]*a[0]+c[3]*a[1]+c[6]*a[2],d[1]=c[1]*a[0]+c[4]*a[1]+c[7]*a[2],d[2]=c[2]*a[0]+c[5]*a[1]+c[8]*a[2],d}},j={lookat:function(b,c,d,e,f,h,i,j,k){var l=[],m=[],n=[],o=[];l[0]=e-b,l[1]=f-c,l[2]=h-d,n[0]=i,n[1]=j,n[2]=k,l=g.normalize(l),m=g.cross(l,n),m=g.normalize(m),n=g.cross(m,l),o=[m[0],n[0],-l[0],0,m[1],n[1],-l[1],0,m[2],n[2],-l[2],0,0,0,0,1];var p=new a.Transform(o);return p.translate([-b,-c,-d]),p.getResult()},multiply:function(a,c,d){return d===b&&(d=[]),d[0]=a[0]*c[0]+a[4]*c[1]+a[8]*c[2]+a[12]*c[3],d[1]=a[1]*c[0]+a[5]*c[1]+a[9]*c[2]+a[13]*c[3],d[2]=a[2]*c[0]+a[6]*c[1]+a[10]*c[2]+a[14]*c[3],d[3]=a[3]*c[0]+a[7]*c[1]+a[11]*c[2]+a[15]*c[3],d[4]=a[0]*c[4]+a[4]*c[5]+a[8]*c[6]+a[12]*c[7],d[5]=a[1]*c[4]+a[5]*c[5]+a[9]*c[6]+a[13]*c[7],d[6]=a[2]*c[4]+a[6]*c[5]+a[10]*c[6]+a[14]*c[7],d[7]=a[3]*c[4]+a[7]*c[5]+a[11]*c[6]+a[15]*c[7],d[8]=a[0]*c[8]+a[4]*c[9]+a[8]*c[10]+a[12]*c[11],d[9]=a[1]*c[8]+a[5]*c[9]+a[9]*c[10]+a[13]*c[11],d[10]=a[2]*c[8]+a[6]*c[9]+a[10]*c[10]+a[14]*c[11],d[11]=a[3]*c[8]+a[7]*c[9]+a[11]*c[10]+a[15]*c[11],d[12]=a[0]*c[12]+a[4]*c[13]+a[8]*c[14]+a[12]*c[15],d[13]=a[1]*c[12]+a[5]*c[13]+a[9]*c[14]+a[13]*c[15],d[14]=a[2]*c[12]+a[6]*c[13]+a[10]*c[14]+a[14]*c[15],d[15]=a[3]*c[12]+a[7]*c[13]+a[11]*c[14]+a[15]*c[15],d},vec4_multiply:function(a,c,d){return d===b&&(d=[]),d[0]=c[0]*a[0]+c[4]*a[1]+c[8]*a[2]+c[12]*a[3],d[1]=c[1]*a[0]+c[5]*a[1]+c[9]*a[2]+c[13]*a[3],d[2]=c[2]*a[0]+c[6]*a[1]+c[10]*a[2]+c[14]*a[3],d[3]=c[3]*a[0]+c[7]*a[1]+c[11]*a[2]+c[15]*a[3],d},vec3_multiply:function(a,c,d){return d===b&&(d=[]),d[0]=c[0]*a[0]+c[4]*a[1]+c[8]*a[2]+c[12],d[1]=c[1]*a[0]+c[5]*a[1]+c[9]*a[2]+c[13],d[2]=c[2]*a[0]+c[6]*a[1]+c[10]*a[2]+c[14],d},perspective:function(a,b,c,d){var e=Math.tan(a*Math.PI/360),f=e*b;return[1/f,0,0,0,0,1/e,0,0,0,0,-(d+c)/(d-c),-1,0,0,-(2*d*c)/(d-c),0]},ortho:function(a,b,c,d,e,f){return[2/(b-a),0,0,0,0,2/(d-c),0,0,0,0,-2/(f-e),0,-(a+b)/(b-a),-(d+c)/(d-c),-(f+e)/(f-e),1]},determinant:function(a){var b=a[0]*a[5]-a[1]*a[4],c=a[0]*a[6]-a[2]*a[4],d=a[0]*a[7]-a[3]*a[4],e=a[1]*a[6]-a[2]*a[5],f=a[1]*a[7]-a[3]*a[5],g=a[2]*a[7]-a[3]*a[6],h=a[8]*a[13]-a[9]*a[12],i=a[8]*a[14]-a[10]*a[12],j=a[8]*a[15]-a[11]*a[12],k=a[9]*a[14]-a[10]*a[13],l=a[9]*a[15]-a[11]*a[13],m=a[10]*a[15]-a[11]*a[14],n=b*m-c*l+d*k+e*j-f*i+g*h;return n},coFactor:function(a,b,c){},transpose:function(a){return[a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]]},inverse_mat3:function(a){var b=[],c=a[0],d=a[1],e=a[2],f=a[4],g=a[5],h=a[6],i=a[8],j=a[9],k=a[10],l=k*g-h*j,m=-k*f+h*i,n=j*f-g*i,o=c*l+d*m+e*n;if(!o)return null;var p=1/o;return b[0]=l*p,b[1]=(-k*d+e*j)*p,b[2]=(h*d-e*g)*p,b[3]=m*p,b[4]=(k*c-e*i)*p,b[5]=(-h*c+e*f)*p,b[6]=n*p,b[7]=(-j*c+d*i)*p,b[8]=(g*c-d*f)*p,b},inverse:function(a,c){var d=a[0]*a[5]-a[1]*a[4],e=a[0]*a[6]-a[2]*a[4],f=a[0]*a[7]-a[3]*a[4],g=a[1]*a[6]-a[2]*a[5],h=a[1]*a[7]-a[3]*a[5],i=a[2]*a[7]-a[3]*a[6],j=a[8]*a[13]-a[9]*a[12],k=a[8]*a[14]-a[10]*a[12],l=a[8]*a[15]-a[11]*a[12],m=a[9]*a[14]-a[10]*a[13],n=a[9]*a[15]-a[11]*a[13],o=a[10]*a[15]-a[11]*a[14],p=d*o-e*n+f*m+g*l-h*k+i*j;if(p!==0){c===b&&(c=[]),c[0]=0+a[5]*o-a[6]*n+a[7]*m,c[4]=0-a[4]*o+a[6]*l-a[7]*k,c[8]=0+a[4]*n-a[5]*l+a[7]*j,c[12]=0-a[4]*m+a[5]*k-a[6]*j,c[1]=0-a[1]*o+a[2]*n-a[3]*m,c[5]=0+a[0]*o-a[2]*l+a[3]*k,c[9]=0-a[0]*n+a[1]*l-a[3]*j,c[13]=0+a[0]*m-a[1]*k+a[2]*j,c[2]=0+a[13]*i-a[14]*h+a[15]*g,c[6]=0-a[12]*i+a[14]*f-a[15]*e,c[10]=0+a[12]*h-a[13]*f+a[15]*d,c[14]=0-a[12]*g+a[13]*e-a[14]*d,c[3]=0-a[9]*i+a[10]*h-a[11]*g,c[7]=0+a[8]*i-a[10]*f+a[11]*e,c[11]=0-a[8]*h+a[9]*f-a[11]*d,c[15]=0+a[8]*g-a[9]*e+a[10]*d;var q=1/p;return c[0]*=q,c[1]*=q,c[2]*=q,c[3]*=q,c[4]*=q,c[5]*=q,c[6]*=q,c[7]*=q,c[8]*=q,c[9]*=q,c[10]*=q,c[11]*=q,c[12]*=q,c[13]*=q,c[14]*=q,c[15]*=q,c}return null},identity:function(a){if(a==b)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1},translate:function(a,c,d,e){var f=[1,0,0,0,0,1,0,0,0,0,1,0,a,c,d,1];if(e===b)return f;j.multiply(e.slice(0),f,e)},rotateAxis:function(a,c,d,e,f){var g=Math.sin(a*(Math.PI/180)),h=Math.cos(a*(Math.PI/180)),i=[h+c*c*(1-h),c*d*(1-h)-e*g,c*e*(1-h)+d*g,0,d*c*(1-h)+e*g,h+d*d*(1-h),d*e*(1-h)-c*g,0,e*c*(1-h)-d*g,e*d*(1-h)+c*g,h+e*e*(1-h),0,0,0,0,1];if(f===b)return i;j.multiply(f.slice(0),i,f)},rotate:function(a,c,d,e){var f,g;return e===b&&(e=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),d!==0&&(f=Math.sin(d*(Math.PI/180)),g=Math.cos(d*(Math.PI/180)),j.multiply(e.slice(0),[g,f,0,0,-f,g,0,0,0,0,1,0,0,0,0,1],e)),c!==0&&(f=Math.sin(c*(Math.PI/180)),g=Math.cos(c*(Math.PI/180)),j.multiply(e.slice(0),[g,0,-f,0,0,1,0,0,f,0,g,0,0,0,0,1],e)),a!==0&&(f=Math.sin(a*(Math.PI/180)),g=Math.cos(a*(Math.PI/180)),j.multiply(e.slice(0),[1,0,0,0,0,g,f,0,0,-f,g,0,0,0,0,1],e)),e},scale:function(a,c,d,e){if(e===b)return[a,0,0,0,0,c,0,0,0,0,d,0,0,0,0,1];j.multiply(e.slice(0),[a,0,0,0,0,c,0,0,0,0,d,0,0,0,0,1],e)},transform:function(a,b,c){var d=j.identity();return a&&j.translate(a[0],a[1],a[2],d),b&&(b[0]!==0||b[1]!==0||b[2]!==0)&&j.rotate(b[0],b[1],b[2],d),c&&(c[0]!==1||c[1]!==1||c[2]!==1)&&j.scale(c[0],c[1],c[2],d),d}};k.prototype={setIdentity:function(){return this.m_stack[this.c_stack]=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],this.valid===this.c_stack&&this.c_stack&&this.valid--,this},getIdentity:function(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},invalidate:function(){return this.valid=0,this.result=null,this},getResult:function(){var b=a.mat4;if(!this.c_stack)return this.m_stack[0];var d=c;this.valid>this.c_stack-1&&(this.valid=this.c_stack-1);for(var e=this.valid;e<this.c_stack+1;e++)d=b.multiply(d,this.m_stack[e]),this.m_cache[e]=d;return this.valid=this.c_stack-1,this.result=this.m_cache[this.c_stack],this.result},pushMatrix:function(a){return this.c_stack++,this.m_stack[this.c_stack]=a?a:c,this},popMatrix:function(){if(this.c_stack===0)return;return this.c_stack--,this},clearStack:function(a){return this.m_stack=[],this.m_cache=[],this.c_stack=0,this.valid=0,this.result=null,a!==b?this.m_stack[0]=a:this.setIdentity(),this},translate:function(b,c,d){var e=a.mat4;if(typeof b=="object")return this.translate(b[0],b[1],b[2]);var f=this.getIdentity();return f[12]=b,f[13]=c,f[14]=d,this.m_stack[this.c_stack]=e.multiply(this.m_stack[this.c_stack],f),this.valid===this.c_stack&&this.c_stack&&this.valid--,this},scale:function(b,c,d){var e=a.mat4;if(typeof b=="object")return this.scale(b[0],b[1],b[2]);var f=this.getIdentity();return f[0]=b,f[5]=c,f[10]=d,this.m_stack[this.c_stack]=e.multiply(this.m_stack[this.c_stack],f),this.valid===this.c_stack&&this.c_stack&&this.valid--,this},rotate:function(b,c,d,e){var f=a.mat4;if(typeof b=="object")return this.rotate(b[0],1,0,0),this.rotate(b[1],0,1,0),this.rotate(b[2],0,0,1),this;var g,h;if(c||d||e)g=Math.sin(-b*(Math.PI/180)),h=Math.cos(-b*(Math.PI/180));if(c){var i=this.getIdentity();i[5]=h*c,i[9]=g*c,i[6]=-g*c,i[10]=h*c,this.m_stack[this.c_stack]=f.multiply(i,this.m_stack[this.c_stack])}if(d){var j=this.getIdentity();j[0]=h*d,j[8]=-g*d,j[2]=g*d,j[10]=h*d,this.m_stack[this.c_stack]=f.multiply(j,this.m_stack[this.c_stack])}if(e){var k=this.getIdentity();k[0]=h*e,k[4]=g*e,k[1]=-g*e,k[5]=h*e,this.m_stack[this.c_stack]=f.multiply(k,this.m_stack[this.c_stack])}return this.valid===this.c_stack&&this.c_stack&&this.valid--,this}},l.prototype={length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.length());this.x/=a,this.y/=a,this.z/=a,this.w/=a},fromMatrix:function(a){var b=1+a[0]+a[5]+a[10],c,d,e,f,g;b>1e-8?(c=Math.sqrt(b)*2,d=(a[9]-a[6])/c,e=(a[2]-a[8])/c,f=(a[4]-a[1])/c,g=.25*c):a[0]>a[5]&&a[0]>a[10]?(c=Math.sqrt(1+a[0]-a[5]-a[10])*2,d=.25*c,e=(a[4]+a[1])/c,f=(a[2]+a[8])/c,g=(a[9]-a[6])/c):a[5]>a[10]?(c=Math.sqrt(1+a[5]-a[0]-a[10])*2,d=(a[4]+a[1])/c,e=.25*c,f=(a[9]+a[6])/c,g=(a[2]-a[8])/c):(c=Math.sqrt(1+a[10]-a[0]-a[5])*2,d=(a[2]+a[8])/c,e=(a[9]+a[6])/c,f=.25*c,g=(a[4]-a[1])/c),this.x=d,this.y=e,this.z=f,this.w=g},fromEuler:function(a,b,c){var d=Math.cos(Math.PI/180*b/2),e=Math.sin(Math.PI/180*b/2),f=Math.cos(Math.PI/180*c/2),g=Math.sin(Math.PI/180*c/2),h=Math.cos(Math.PI/180*a/2),i=Math.sin(Math.PI/180*a/2),j=d*f,k=e*g;this.w=j*h-k*i,this.x=j*i+k*h,this.y=e*f*h+d*g*i,this.z=d*g*h-e*f*i},toEuler:function(){var a=this.w*this.w,b=this.x*this.x,c=this.y*this.y,d=this.z*this.z,e=180/Math.PI*Math.atan2(2*(this.y*this.z+this.x*this.w),-b-c+d+a),f=180/Math.PI*Math.asin(-2*(this.x*this.z-this.y*this.w)),g=180/Math.PI*Math.atan2(2*(this.x*this.y+this.z*this.w),b-c-d+a);return[e,f,g]},multiply:function(a,c){var d=!1;c===b&&(c=a,a=this);var e=a.x*c.w+a.w*c.x+a.y*c.z-a.z*c.y,f=a.y*c.w+a.w*c.y+a.z*c.x-a.x*c.z,g=a.z*c.w+a.w*c.z+a.x*c.y-a.y*c.x,h=a.w*c.w-a.x*c.x-a.y*c.y-a.z*c.z;if(!d)return new l(e,f,g,h);this.x=e,this.y=f,this.z=g,this.w=h}};var m={engulf:function(a,b){a[0][0]>b[0]&&(a[0][0]=b[0]),a[0][1]>b[1]&&(a[0][1]=b[1]),a[0][2]>b[2]&&(a[0][2]=b[2]),a[1][0]<b[0]&&(a[1][0]=b[0]),a[1][1]<b[1]&&(a[1][1]=b[1]),a[1][2]<b[2]&&(a[1][2]=b[2])},reset:function(a,b){b===undefined&&(b=[0,0,0]),a[0][0]=b[0],a[0][1]=b[1],a[0][2]=b[2],a[1][0]=b[0],a[1][1]=b[1],a[1][2]=b[2]},size:function(a){var b=a[0][0]<a[1][0]?a[1][0]-a[0][0]:a[0][0]-a[1][0],c=a[0][1]<a[1][1]?a[1][1]-a[0][1]:a[0][1]-a[1][1],d=a[0][2]<a[1][2]?a[1][2]-a[0][2]:a[0][2]-a[1][2];return[b,c,d]}},n={classifyPoint:function(a,b){var c=a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3];return c<0?-1:c>0?1:0},normalize:function(a){var b=Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);a[0]=a[0]/b,a[1]=a[1]/b,a[2]=a[2]/b,a[3]=a[3]/b}},o={intersects:function(b,c){var d=a.vec3,e=[b[0],b[1],b[2]],f=[c[0],c[1],c[2]],g=d.subtract(e,f),h=Math.sqrt(g[0]*g[0]+g[1]*g[1]+g[2]*g[2]),i=b[3]+c[3];return h*h<i*i?!0:!1}},p={vec2:f,vec3:g,mat3:i,mat4:j,aabb:m,plane:n,sphere:o,triangle:h,Transform:k,Quaternion:l};return p}),CubicVR.RegisterModule("Utility",function(base){var undef=base.undef,log=base.log,classBin={},jsonBin={},util={multiSplit:function(a,b){var c=a.split(b[0]);for(var d=1,e=b.length;d<e;d++){var f=b[d];for(var g=0,h=c.length;g<h;g++){var i=c[g].trim().split(f),j=!0;if(i.length>1)for(var k=0;k<i.length;k++)i[k].trim()!==""&&(c.splice(g+k,k===0?1:0,i[k]),k&&h++,j=!1);else c[g]=c[g].trim().replace(f,""),c[g]!==""&&(j=!1);j&&(c.splice(g,1),h--,g--)}}return c},getJSONScriptObj:function(a,b){if(typeof a=="string"&&a.length>0&&a.charAt(0)==="#"){var c=document.getElementById(a.substr(1));if(c){var d=c.innerHTML||c.text,e=JSON.parse(d);return b&&b(e),e}}return a},getScriptContents:function(a){var b=document.getElementById(a),c="",d="";if(!b)d=a;else if(b.src!==""||b.attributes.srcUrl!==undef)d=b.src!==""?b.src:b.attributes.srcUrl.value;if(d.length!==0){var e=new XMLHttpRequest;e.overrideMimeType&&e.overrideMimeType("application/json"),e.open("GET",d,!1),e.send(null);if(e.status===200||e.status===0)c=e.responseText}else{var f=b.firstChild;while(f)f.nodeType===3&&(c+=f.textContent),f=f.nextSibling}return c},xmlNeedsBadgerFish:function(a){var b=[a];while(b.length){var c=b.pop();if(c.attributes&&c.attributes.length)return!0;for(var d=0,e=c.childNodes.length;d<e;d++)b.push(c.childNodes[d])}return!1},getFirstEntry:function(a){for(var b in a)if(a.hasOwnProperty(b))return a[b]},getURIFileType:function(a){function e(a){for(var b in d){if(!d.hasOwnProperty(b))continue;if(d[b].indexOf(a)!==-1)return b}return undef}var b=a.toLowerCase(),c=["_ext","ext"],d={json:["js","javascript","json"],xml:["xml"]};if(b.indexOf("?")!==-1){var f=b.split("?");b=f[0];if(f[1]){var g;f[1].indexOf("&")===-1?g=[f[1]]:g=f[1].split("&");for(var h=0,i=g.length;h<i;h++){var j=g[h];if(j.indexOf("=")!==-1){var k=j.split("=");if(c.indexOf(k[0])!==-1){var l=e(k[1]);if(l)return l;log("Unable to determine extension type '"+k[1]+"' provided for URI: ["+a+"], falling back to filename part.")}}}}}if(b.indexOf(".")!==-1){var m=b.split(".");return e(m[m.length-1])}return undef},get:function(a,b){var c=null,d=null,e=null;b=b||null;if(a===undef)return undef;if(isFinite(a))
return a;typeof a=="function"&&(a=a(b));if(typeof a=="object")return b?a instanceof b?a:new b(a):a;if(typeof a=="string"){if(a.indexOf("\n")!==-1)return a;a[0]=="#"&&(c=a.substr(1),e=document.getElementById(c),e&&(d=e.src||null)),!e&&!c&&!d&&a&&(d=a)}if(e&&!d)return CubicVR.util.collectTextNode(e);if(d){var f=null,g=jsonBin[d]||null;if(!g){var h=util.getURIFileType(d);if(h===undef&&!e)return d;h==="json"?g=CubicVR.util.getJSON(d):h==="xml"?f=CubicVR.util.getXML(d):f=CubicVR.util.getURL(d),f&&f.childNodes?g=util.getFirstEntry(util.xml2json(f)):f&&(g=f)}g&&jsonBin[d]===undef&&(jsonBin[d]=g);if(b){if(classBin[d]&&classBin[d]instanceof b)return classBin[d];if(g)return classBin[d]=new b(g),classBin[d]}else if(g)return g;return d}return c&&!e?(console.log("Unable to retrieve requested ID: '"+a+"'"),undef):undef},clearCache:function(){classBin={},jsonBin={}},getURL:function(a){try{var b=new XMLHttpRequest;b.open("GET",a,!1),b.send(null);if(b.status===200||b.status===0){if(b.responseText.length)return b.responseText;if(b.responseXML)return b.responseXML}}catch(c){alert(a+" failed to load.")}return null},getXML:function(a){try{var b=new XMLHttpRequest;b.open("GET",a,!1),b.overrideMimeType("application/xml"),b.send(null);if(b.status===200||b.status===0)return b.responseXML}catch(c){try{alert(a+" failed to load.")}catch(d){throw c}}return null},getJSON:function(srcUrl){try{var xmlHttp=new XMLHttpRequest;xmlHttp.open("GET",srcUrl,!1),xmlHttp.overrideMimeType("application/json"),xmlHttp.send(null);if(xmlHttp.status===200||xmlHttp.status===0)return eval("("+xmlHttp.responseText+")")}catch(e){try{alert(srcUrl+" failed to load.")}catch(ex){throw e}}return null},repackArray:function(a,b,c){a.length!==parseInt(b,10)*parseInt(c,10)&&log("array repack error, data size !== stride*count: data.length="+a.length+" stride="+b+" count="+c);var d=[],e=0;for(var f=0,g=a.length;f<g;f++){var h=f%b;h===0&&(d[e]=[]),d[e][h]=a[f],h===b-1&&e++}return d},collectTextNode:function(a){if(!a)return"";var b="",c=a.childNodes;for(var d=0,e=c.length;d<e;d++)b+=c[d].nodeValue;return b},floatDelimArray:function(a,b){b!="\n"&&(a=a.replace(/\n/g," ").replace(/^\s+|\s+$/,""));var c=a.split(b?b:",");for(var d=0,e=c.length;d<e;d++)c[d]=parseFloat(c[d]);return c[c.length-1]!==c[c.length-1]&&c.pop(),c},intDelimArray:function(a,b){b!="\n"&&(a=a.replace(/\n/g," ").replace(/^\s+|\s+$/,""));var c=a.split(b?b:",");for(var d=0,e=c.length;d<e;d++)c[d]=parseInt(c[d],10);return c[c.length-1]!==c[c.length-1]&&c.pop(),c},textDelimArray:function(a,b){b!="\n"&&(a=a.replace(/\n/g," ").replace(/^\s+|\s+$/,""));var c=a.split(b?b:",");for(var d=0,e=c.length;d<e;d++)c[d]=c[d];return c},xmlstring2json:function(a){var b=a.replace(/<!--.*?-->/gm,"").replace(/\n/g," ").split(/(<[^>]*>)([^<]*)/gm),c=/^\s+$/gm,d,e=[],f=[],g={},h=g;for(var i=0,j=b.length;i<j;i++){var k=b[i];if(c.test(k)||k==="")continue;if(/<\?\s?xml[^>]*>/.test(k))continue;if(/<.*?>/.test(k)){var l=k.split(/<([^>]*?)(.*)?>/g);d=l[2];if(d[0]!=="/"){var m=d.split(" ");d=m[0];var n=m.slice(1).join(" ");e.push(d),f.push(g),!g[d]||g[d]instanceof Array?g[d]?g=g[d]:(g[d]={},g=g[d]):g[d]=[g[d]],g instanceof Array&&(g.push({}),g=g[g.length-1]);if(d.substr(d.length-1)==="/"||n.substr(n.length-1)==="/")d="/"+d}if(d[0]==="/"){d=d.substr(1);if(e.length&&e[e.length-1]!==d)return console.log("Unmatched tag, aborting: "+d),!1;e.pop(),f.length?g=f[f.length-1]:g=null,f.pop()}}else{var o=f[f.length-1][d];o instanceof Array?(o.pop(),o.push(util.parseNumeric(k))):f[f.length-1][d]=util.parseNumeric(k)}}return h},xmlstring2badgerfish:function(a){var b=a.replace(/<!--.*?-->/gm,"").replace(/\n/g," ").split(/(<[^>]*>)([^<]*)/gm),c=/^\s+$/gm,d,e=[],f=[],g={},h=g;for(var i=0,j=b.length;i<j;i++){var k=b[i];if(c.test(k)||k==="")continue;if(/<\?\s?xml[^>]*>/.test(k))continue;if(/<.*?>/.test(k)){var l=k.split(/<([^>]*?)(.*)?>/g);d=l[2];if(d[0]!=="/"){var m=d.split(" ");d=m[0];var n=m.slice(1).join(" ");e.push(d),f.push(g),!g[d]||g[d]instanceof Array?g[d]?g=g[d]:(g[d]={},g=g[d]):(g[d]=[g[d]],g=g[d]),g instanceof Array&&(g.push({}),g=g[g.length-1]);if(d.substr(d.length-1)==="/"||n.substr(n.length-1)==="/")d="/"+d;var o=util.multiSplit(n,"= "),p="";for(var q=0;q<o.length;q++){var r=o[q];r[r.length-1]==="/"&&(r=r.substr(0,r.length-1));var s=q%2===1;if(s){if(r[0]==="'"||r[0]==='"'){var t=r[0];r=r.substr(1);while(r[r.length-1]!==t&&o.length+1<q)r+=o.splice(q+1,1);r[r.length-1]===t&&(r=r.substr(0,r.length-1))}g["@"+p]=r}else p=r}}if(d[0]==="/"){d=d.substr(1);if(e.length&&e[e.length-1]!==d)return console.log("Unmatched tag, aborting: "+e[e.length-1]),!1;e.pop(),f.length?g=f[f.length-1]:g=null,f.pop()}}else g.$=k}return h},xml2badgerfish:function(a){var b={},c=[],d,e,f,g,h=b,i,j,k=/^\s+|\s+$/g;a.jsonParent=h,c.push(a);while(c.length){g=c.pop();var l=null;h=g.jsonParent;for(d=0,e=g.childNodes.length;d<e;d++)i=g.childNodes[d],j=i.tagName,j!==undef&&(l=l||{},l[j]=l[j]||0,l[j]++);if(g.attributes&&g.attributes.length)for(d=0,e=g.attributes.length;d<e;d++){var m=g.attributes[d];h["@"+m.name]=m.value}for(d=0,e=g.childNodes.length;d<e;d++)i=g.childNodes[d],j=i.tagName,i.nodeType===1?(l[j]>1?(h[j]=h[j]||[],h[j].push({}),i.jsonParent=h[j][h[j].length-1]):(h[j]=h[j]||{},i.jsonParent=h[j]),c.push(i)):i.nodeType===3&&i.nodeValue.replace(k,"")!==""&&(h.$=h.$||"",h.$+=i.nodeValue)}return b},isTextNode:function(a){var b="",c=a.childNodes;for(var d=0,e=c.length;d<e;d++)if(c[d].nodeType!==3||c[d].childNodes.length)return!1;return!0},parseNumeric:function(a){var b=null,c,d,e;e=a.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"").replace(/\n/g," ").replace(/ *, */gm,",").replace(/\s+/g," ");if(e==="")return e;if((e.indexOf(" ")!==-1||e.indexOf(",")!==-1)&&/[0-9\.,e\-\+ ]+/g.test(e)){if(!/[^0-9\-\+]+/g.test(e))return parseInt(e,10);if(!/[^0-9\- ]+/g.test(e))return util.intDelimArray(e," ");if(!/[^0-9\-,]+/g.test(e))return util.intDelimArray(e,",");if(!/[^0-9\.e\-\+ ]+/g.test(e))return util.floatDelimArray(e," ");if(!/[^0-9\.,e\+\-]+/g.test(e))return util.floatDelimArray(e,",");if(!/[^0-9,\-\+ ]+/g.test(e)){b=e.split(" ");for(c=0,d=b.length;c<d;c++)b[c]=util.intDelimArray(b[c],",");return b}if(!/[^0-9\.,e\-\+ ]+/g.test(e)){b=e.split(" ");for(c=0,d=b.length;c<d;c++)b[c]=util.floatDelimArray(b[c],",");return b}}var f=parseFloat(e);return isNaN(f)?a:/[^0-9\-\+]+/g.test(e)?f:parseInt(e,10)},xml2json:function(a){var b={},c=[],d,e,f,g,h=b,i,j,k=/^\s+|\s+$/g;a.jsonParent=h,c.push(a);while(c.length){g=c.pop();var l=null;h=g.jsonParent;for(d=0,e=g.childNodes.length;d<e;d++)i=g.childNodes[d],j=i.tagName,j!==undef&&(l=l||{},l[j]=l[j]||0,l[j]++);for(d=0,e=g.childNodes.length;d<e;d++){i=g.childNodes[d],j=i.tagName;var m=util.isTextNode(i);i.nodeType===1&&(l[j]>1?(h[j]=h[j]||[],m?h[j].push(util.parseNumeric(util.collectTextNode(i))):(h[j].push({}),i.jsonParent=h[j][h[j].length-1])):m?h[j]=util.parseNumeric(util.collectTextNode(i)):(h[j]=h[j]||{},i.jsonParent=h[j]),m||c.push(i))}}return b}},extend={util:util,get:util.get,clearCache:util.clearCache};return extend}),CubicVR.RegisterModule("COLLADA",function(a){function h(e,h,i){function ob(a){var b=a.color;if(!b)return!1;var c=a.color,d=c?j.floatDelimArray(c.$.replace(/ {2}/g," ").replace(/^\s+|\s+$/,"")," "):!1;return d}function pb(a){var b=a["float"];if(!b)return!1;var c=a["float"];return c=c?parseFloat(c.$.replace(/ {2}/g," ").replace(/^\s+|\s+$/,"")):0,c}function qb(a){var b=a.texture;if(!b)return!1;var c=a.texture["@texture"];return c}var j=a.util,k,l,m,n,o,p,q,r=null;typeof e=="object"?q=e:e.indexOf(".js")!=-1?q=j.getJSON(e):q=a.util.xml2badgerfish(j.getXML(e));var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N=q;q=null;if(!N.COLLADA)throw new Error(e+" does not appear to be a valid COLLADA file.");N=N.COLLADA;var O={up_axis:1,images:[],effects:[],materials:[],meshes:[],scenes:[],lights:[],cameras:[],animations:[]};if(N.asset){var P=N.asset.up_axis.$;P==="X_UP"?O.up_axis=0:P==="Y_UP"?O.up_axis=1:P==="Z_UP"&&(O.up_axis=2)}var Q=O.up_axis;if(N.library_images){N.library_images.image&&!N.library_images.image.length&&(N.library_images.image=[N.library_images.image]);if(N.library_images.image.length){var R=N.library_images.image;for(var S=0,T=R.length;S<T;S++){var U=R[S],V=U["@id"],W=U["@name"],X=U.init_from;if(X.$){var Y=X.$;h!==b&&Y.lastIndexOf("/")!==-1&&(Y=Y.substr(Y.lastIndexOf("/")+1)),h!==b&&Y.lastIndexOf("\\")!==-1&&(Y=Y.substr(Y.lastIndexOf("\\")+1)),O.images[V]={source:Y,id:V,name:W}}}}}var Z,$,_,ab,bb,cb,db,eb,fb,gb,hb,ib,jb,kb,lb,mb,nb;if(N.library_effects){var rb=N.library_effects.effect;rb&&!rb.length&&(rb=[rb]);for($=0,_=rb.length;$<_;$++){var sb=rb[$];Z=sb["@id"];var tb={};tb.id=Z,tb.surfaces=[],tb.samplers=[],eb=sb.profile_COMMON.newparam,eb&&!eb.length&&(eb=[eb]);var ub=[],vb;if(eb)for(J=0,K=eb.length;J<K;J++){var wb=eb[J],xb=wb["@sid"];if(wb.surface){tb.surfaces[xb]={};var yb=wb.surface.init_from.$;if(typeof O.images[yb]=="object"){var zb=h+"/"+O.images[yb].source;tb.surfaces[xb].source=zb}}else wb.sampler2D&&(tb.samplers[xb]={},tb.samplers[xb].source=wb.sampler2D.source.$,wb.sampler2D.minfilter&&(tb.samplers[xb].minfilter=wb.sampler2D.minfilter.$),wb.sampler2D.magfilter&&(tb.samplers[xb].magfiter=wb.sampler2D.magfilter.$))}var Ab=sb.profile_COMMON.technique;Ab&&!Ab.length&&(Ab=[Ab]),tb.material={textures_ref:[]};for(ab=0,bb=Ab.length;ab<bb;ab++){k=Ab[ab].blinn,k||(k=Ab[ab].phong),k||(k=Ab[ab].lambert);if(k)for(var Bb in k){var Cb=k[Bb],Db=ob(Cb),Eb=pb(Cb),Fb=qb(Cb);Db!==!1&&Db.length>3&&Db.pop(),Bb=="emission"?Db!==!1&&(tb.material.ambient=Db):Bb!="ambient"&&(Bb=="diffuse"?Db!==!1&&(tb.material.color=Db):Bb=="specular"?Db!==!1&&(tb.material.specular=Db):Bb=="shininess"?Eb!==!1&&(tb.material.shininess=Eb):Bb=="reflective"?c():Bb=="reflectivity"?c():Bb=="transparent"?c():Bb=="index_of_refraction"&&c());if(Fb!==!1){var Gb=tb.surfaces[tb.samplers[Fb].source].source;Bb=="emission"?tb.material.textures_ref.push({image:Gb,type:d.texture.map.AMBIENT}):Bb=="ambient"?tb.material.textures_ref.push({image:Gb,type:d.texture.map.AMBIENT}):Bb=="diffuse"?tb.material.textures_ref.push({image:Gb,type:d.texture.map.COLOR}):Bb=="specular"?tb.material.textures_ref.push({image:Gb,type:d.texture.map.SPECULAR}):Bb!="shininess"&&(Bb=="reflective"?tb.material.textures_ref.push({image:Gb,type:d.texture.map.REFLECT}):Bb!="reflectivity"&&(Bb=="transparent"?tb.material.textures_ref.push({image:Gb,type:d.texture.map.ALPHA}):Bb=="transparency"?c():Bb=="index_of_refraction"&&c()))}}O.effects[Z]=tb}}}var Hb=g.getAllOf(N,"instance_geometry"),Ib=[];if(Hb.length)for(x=0,z=Hb.length;x<z;x++){var Jb=Hb[x],Kb=g.getAllOf(Jb,"instance_material");if(Kb.length)for(L=0,M=Kb.length;L<M;L++){var Lb=Kb[L],Mb=Lb["@symbol"],Nb=Lb["@target"].substr(1);Ib[Jb["@url"].substr(1)+":"+Mb]=Nb}}var Ob=N.library_materials;if(Ob&&Ob.material){var Pb=Ob.material;Pb&&!Pb.length&&(Pb=[Pb]);for(B=0,C=Pb.length;B<C;B++){var Qb=Pb[B],Rb=Qb["@id"],Sb=Qb["@name"],Tb=Qb.instance_effect;Tb&&(Z=Tb["@url"].substr(1),O.materials.push({id:Rb,name:Sb,mat:O.effects[Z].material}))}}var Ub=N.library_geometries,Vb;if(Ub){var Wb=Ub.geometry;Wb&&!Wb.length&&(Wb=[Wb]);if(Wb.length)for(var Xb=0,Yb=Wb.length;Xb<Yb;Xb++){var Zb={id:b,points:[],parts:[]},$b,_b=Wb[Xb].mesh;if(_b){Vb=Wb[Xb]["@id"],p=Wb[Xb]["@name"];var ac=_b.source;ac&&!ac.length&&(ac=[ac]);var bc=[];for(var cc=0,dc=ac.length;cc<dc;cc++){var ec=ac[cc];l=ec["@id"];var fc=ec["@name"],gc=ec.float_array;gc&&(bc[l]={id:l,name:fc,data:j.floatDelimArray(gc.$?gc.$:""," ")});var hc=ec.technique_common.accessor;hc&&(bc[l].count=hc["@count"]|0,bc[l].stride=hc["@stride"]|0,bc[l].count&&(bc[l].data=j.repackArray(bc[l].data,bc[l].stride,bc[l].count)))}var ic=[],jc=_b.vertices,kc=null,lc=null,mc=null,nc=null,oc=null,pc=null;if(jc){lc=jc["@id"],fb=jc.input,fb&&!fb.length&&(fb=[fb]);if(fb)for(cb=0,db=fb.length;cb<db;cb++)gb=fb[cb],gb["@semantic"]==="POSITION"&&(kc=gb["@source"].substr(1))}var qc=0,rc=1,sc=2,tc=3,uc=4,vc=_b.triangles;vc&&!vc.length&&(vc=[vc]);if(vc)for(ab=0,bb=vc.length;ab<bb;ab++){nb={material:0,faces:[],normals:[],texcoords:[],colors:[]};var wc=parseInt(vc[ab]["@count"],10);fb=vc[ab].input,fb&&!fb.length&&(fb=[fb]),hb=[];if(fb.length)for(cb=0,db=fb.length;cb<db;cb++)gb=fb[cb],mb=parseInt(gb["@offset"],10),n=gb["@source"].substr(1),gb["@semantic"]==="VERTEX"?(n===lc?n=mc=kc:mc=n,hb[mb]=qc):gb["@semantic"]==="NORMAL"?(nc=n,bc[nc].count&&(hb[mb]=rc)):gb["@semantic"]==="TEXCOORD"?(pc=n,bc[pc].count&&(hb[mb]=sc)):gb["@semantic"]==="COLOR"?(oc=n,bc[oc].count&&(hb[mb]=tc)):hb[mb]=uc;v=hb.length,m=Vb+":"+vc[ab]["@material"],m===null?nb.material=0:Ib[m]===b?(f("missing material ["+m+"]@"+Vb+"?"),nb.material=0):nb.material=Ib[m];var xc=vc[ab].p,yc=[];xc&&(yc=j.intDelimArray(xc.$," "));if(yc.length){w=yc.length/hb.length/3;if(w===wc){Zb.points.length===0&&(Zb.points=bc[kc].data),mb=0;for(x=0,z=yc.length,A=hb.length;x<z;x+=A*3){s=[],t=[],u=[],id=[];for(L=0;L<A*3;L++){var zc=L%A;hb[zc]===qc?t.push(yc[x+L]):hb[zc]===rc?s.push(yc[x+L]):hb[zc]===sc?u.push(yc[x+L]):hb[zc]===tc&&id.push(yc[x+L])}t.length&&(nb.faces.push(t),s.length===3&&nb.normals.push([g.fixuaxis(O.up_axis,bc[nc].data[s[0]]),g.fixuaxis(O.up_axis,bc[nc].data[s[1]]),g.fixuaxis(O.up_axis,bc[nc].data[s[2]])]),u.length===3&&nb.texcoords.push([bc[pc].data[u[0]],bc[pc].data[u[1]],bc[pc].data[u[2]]]),id.length===3&&nb.colors.push([bc[oc].data[id[0]],bc[oc].data[id[1]],bc[oc].data[id[2]]]))}}}Zb.parts.push(nb)}var Ac=_b.polylist;Ac||(Ac=_b.polygons),Ac&&!Ac.length&&(Ac=[Ac]);if(Ac)for(ab=0,bb=Ac.length;ab<bb;ab++){nb={material:0,faces:[],normals:[],texcoords:[],colors:[]};var Bc=parseInt(Ac[ab]["@count"],10);fb=Ac[ab].input,fb&&!fb.length&&(fb=[fb]),hb=[];if(fb.length)for(cb=0,db=fb.length;cb<db;cb++){gb=fb[cb];var Cc=gb["@offset"];Cc===null&&(Cc=gb["@idx"]),mb=parseInt(Cc,10),n=gb["@source"].substr(1),gb["@semantic"]==="VERTEX"?(n===lc?n=mc=kc:mc=n,hb[mb]=qc):gb["@semantic"]==="NORMAL"?(nc=n,hb[mb]=rc):gb["@semantic"]==="TEXCOORD"?(pc=n,hb[mb]=sc):gb["@semantic"]==="COLOR"?(oc=n,hb[mb]=tc):hb[mb]=uc}var Dc=Ac[ab].vcount,Ec=[];Dc&&(Ec=j.intDelimArray(Dc.$," ")),m=Vb+":"+Ac[ab]["@material"],m===b?nb.material=0:nb.material=Ib[m];var Fc=Ac[ab].p;v=hb.length;var Gc=[];if(Fc.length>1&&!Ec.length){var Hc="";for(J=0,K=Fc.length;J<K;J++){var Ic=j.intDelimArray(Fc[J].$," ");Ec[J]=parseInt(Ic.length/v,10),Gc=Gc.concat(Ic)}}else Fc&&(Gc=j.intDelimArray(Fc.$," "));if(Gc.length){w=Ec.length;if(w!==Bc)f("poly vcount data doesn't add up, skipping object load: "+w+" !== "+Bc);else{Zb.points.length===0&&(Zb.points=bc[kc].data),mb=0;for(x=0,z=Ec.length;x<z;x++){s=[],t=[],u=[],id=[];for(L=0,M=Ec[x]*v;L<M;L++)hb[L%v]===qc?(t.push(Gc[mb]),mb++):hb[L%v]===rc?(s.push(Gc[mb]),mb++):hb[L%v]===sc?(u.push(Gc[mb]),mb++):hb[L%v]===tc?(id.push(Gc[mb]),mb++):mb++;var Jc;if(t.length){nb.faces.push(t);if(s.length){wd=[];for(D=0,E=s.length;D<E;D++)wd.push(g.fixuaxis(O.up_axis,bc[nc].data[s[D]]));nb.normals.push(wd)}if(u.length){Jc=[];for(D=0,E=u.length;D<E;D++)Jc.push(bc[pc].data[u[D]]);nb.texcoords.push(Jc)}if(id.length){Jc=[];for(D=0,E=id.length;D<E;D++)Jc.push(bc[oc].data[id[D]]);nb.colors.push(Jc)}}}}}Zb.parts.push(nb)}if(Q!==1)for(x=0,z=Zb.points.length;x<z;x++)Zb.points[x]=g.fixuaxis(O.up_axis,Zb.points[x]);Zb.id=Vb,O.meshes.push(Zb)}}}var Kc=N.library_cameras,Lc=[];if(Kc){kb=Kc.camera,kb&&!kb.length&&(kb=[kb]);for(F=0,G=kb.length;F<G;F++){jb=kb[F];var Mc=jb["@id"],Nc=jb["@name"],Oc=0,Pc=0,Qc=0;jb.optics&&jb.optics.technique_common&&jb.optics.technique_common.perspective&&(Oc=jb.optics.technique_common.perspective.yfov,Pc=jb.optics.technique_common.perspective.znear,Qc=jb.optics.technique_common.perspective.zfar);var Rc,Sc,Tc;if(!Oc&&!Pc&&!Qc){eb=jb.param,eb&&!eb.length&&(eb=[eb]);for(x=0,z=eb.length;x<z;x++){var Uc=eb[x].$,Vc=eb[x]["@name"];Vc=="YFOV"?Rc=parseFloat(Uc):Vc=="ZNEAR"?Sc=parseFloat(Uc):Vc=="ZFAR"&&(Tc=parseFloat(Uc))}}else Rc=Oc?parseFloat(Oc.$):60,Sc=Pc?parseFloat(Pc.$):.1,Tc=Qc?parseFloat(Qc.$):1e3;O.cameras.push({id:Mc,targeted:!1,fov:parseFloat(Rc),nearclip:parseFloat(Sc),farclip:parseFloat(Tc)})}}var Wc=N.library_lights,Xc;if(Wc){var Yc=Wc.light;Yc&&!Yc.length&&(Yc=[Yc]);if(Yc)for(var Zc=0,$c=Yc.length;Zc<$c;Zc++){Xc=Yc[Zc];var _c=Xc.technique_common.point,ad=_c?_c:null,bd=Xc["@id"],cd=Xc["@name"];if(ad!==null){var dd=ad.intensity,ed=dd?parseFloat(dd.$):1,fd=ad.distance,gd=fd?parseFloat(fd.$):10,hd=ad.color,id=[1,1,1];hd&&(id=j.floatDelimArray(hd.$," ")),O.lights.push({id:bd,name:bd,type:d.light.type.POINT,method:d.light.method.STATIC,diffuse:id,specular:[0,0,0],distance:gd,intensity:ed})}}}var jd=N.library_visual_scenes;if(jd){var kd=null;kd=jd.visual_scene,kd&&!kd.length&&(kd=[kd]);for(var ld=0,md=kd.length;ld<md;ld++){lb=kd[ld];var nd=lb["@id"],od=lb["@name"],pd={id:nd,sceneObjects:[],cameras:[],lights:[],parentMap:[]},qd=[],rd=[],sd,td,ud,vd,wd,xd,yd,zd=N.library_nodes;if(zd){var Ad=zd.node;Ad&&!Ad.length&&(Ad=[Ad]),qd=[];for(x=0,z=Ad.length;x<z;x++)td=Ad[x],mnodeId=td["@id"],qd[ud]=td;sd=[lb];while(sd.length){vd=sd.pop();if(vd.node){wd=vd.node,wd&&!wd.length&&(wd=[wd]);if(wd)for(x=0,z=wd.length;x<z;x++)sd.push(wd[x])}if(vd.instance_node){var Bd=vd.instance_node;Bd&&!Bd.length&&(Bd=[Bd]);for(x=0,z=Bd.length;x<z;x++){var Cd=Bd[x],Dd=Cd["@url"].substr(1);qd[Dd]&&(vd.node&&vd.node.length&&(vd.node=[vd.node]),vd.node?vd.node.push(qd[Dd]):vd.node=[qd[Dd]])}}}}sd=[lb];while(sd.length){vd=sd.pop();if(vd.node){wd=vd.node,wd&&!wd.length&&(wd=[wd]);if(wd)for(x=0,z=wd.length;x<z;x++)wd[x].parentNode=vd,rd.push(wd[x]),sd.push(wd[x])}}if(rd.length)for(var Ed=0,Fd=rd.length;Ed<Fd;Ed++){var Gd=rd[Ed],Hd=Gd.instance_geometry;Xc=rd[Ed].instance_light,jb=rd[Ed].instance_camera,ud=Gd["@id"];var Id=Gd["@name"],Jd=g.cl_getInitalTransform(O.up_axis,Gd);Q===2&&(Jd.rotation=g.quaternionFilterZYYZ(Jd.rotation,jb?[-90,0,0]:b));var Kd=null,Ld=null,Md;if(Hd){Hd&&!Hd.length&&(Hd=[Hd]);for(x=0,z=Hd.length;x<z;x++){var Nd=Hd[x];p=Nd["@url"].substr(1),Ld={},Ld.name=(Id?Id:ud)+(x?x:""),Ld.id=(ud?ud:Id)+(x?x:""),Ld.meshId=Vb,Ld.meshName=p,Kd||(Ld.position=Jd.position,Ld.rotation=Jd.rotation,Ld.scale=Jd.scale,Ld.matrix=Jd.matrix),pd.sceneObjects.push(Ld),qd[Ld.id]=!0,Gd.parentNode&&(Md=Gd.parentNode["@id"],xd=Gd.parentNode["@name"],Md&&qd[Md]?pd.parentMap.push({parent:Md,child:Ld.id}):Hd.length>1&&(Kd?qd[Kd.id]&&pd.parentMap.push({parent:Kd.id,child:Ld.id}):(Kd=Ld,Ld={})))}}else if(jb){var Od=jb,Pd=Od["@url"].substr(1);pd.cameras.push({name:Id?Id:ud,id:Id?Id:ud,source:Pd,position:Jd.position,rotation:Jd.rotation})}else if(Xc){var Qd=Xc["@url"].substr(1);pd.lights.push({name:Id?Id:ud,id:Id?Id:ud,source:Qd,position:Jd.position})}else Ld={position:Jd.position,rotation:Jd.rotation,scale:Jd.scale,matrix:Jd.matrix},Ld.name=Id?Id:ud,Ld.id=ud?ud:Id,pd.sceneObjects.push(Ld),qd[Ld.id]=!0,Gd.parentNode&&(Md=Gd.parentNode["@id"],xd=Gd.parentNode["@name"],Md&&qd[Md]&&pd.parentMap.push({parent:Md,child:Ld.id}))}O.scenes.push(pd)}}var Rd=N.library_animations,Sd;if(Rd){var Td=Rd.animation;Td&&!Td.length&&(Td=[Td]);if(Td)for(var Ud=0,Vd=Td.length;Ud<Vd;Ud++){var Wd=Td[Ud];Sd=Wd["@id"];var Xd=Wd["@name"];O.animations[Sd]={},O.animations[Sd].sources=[];var Yd=Wd.source;Yd&&!Yd.length&&(Yd=[Yd]);if(Yd.length)for(H=0,I=Yd.length;H<I;H++){var Zd=Yd[H];l=Zd["@id"];var $d=Zd.technique_common,_d=null,ae=null,be=null;Zd.name_array?_d=j.textDelimArray(Zd.name_array.$," "):Zd.Name_array?_d=j.textDelimArray(Zd.Name_array.$," "):Zd.float_array&&(ae=j.floatDelimArray(Zd.float_array.$," "));var ce=0,de="",ee=1;if($d){k=$d;var fe=k.accessor;ce=parseInt(fe["@count"],10),de=fe["@source"].substr(1);var ge=fe["@stride"];ge&&(ee=parseInt(ge,10))}O.animations[Sd].sources[l]={data:_d?_d:ae,count:ce,source:de,stride:ee},ee!==1&&(O.animations[Sd].sources[l].data=j.repackArray(O.animations[Sd].sources[l].data,ee,ce))}ib=Wd.sampler,ib&&!ib.length&&(ib=[ib]);if(ib){O.animations[Sd].samplers=[];for(H=0,I=ib.length;H<I;H++){var he=ib[H],ie=he["@id"];fb=he.input,fb&&!fb.length&&(fb=[fb]);if(fb){var je=[];for(y=0,z=fb.length;y<z;y++){gb=fb[y];var ke=gb["@semantic"];je[ke]=gb["@source"].substr(1)}O.animations[Sd].samplers[ie]=je}}}var le=Wd.channel;le&&!le.length&&(le=[le]);if(le){O.animations[Sd].channels=[];for(F=0,G=le.length;F<G;F++){var me=le[F],ne=me["@source"].substr(1),oe=me["@target"],pe=oe.split("/"),qe=pe[0],re=pe[1].split("."),se=re[0],te=re[1];O.animations[Sd].channels.push({source:ne,target:oe,targetName:qe,paramName:se,typeName:te})}}}}var ue=N.scene;if(ue){lb=ue.instance_visual_scene;if(lb){var ve=lb["@url"].substr(1);O.scene=ve}}return O}function j(c,f,j){var l=h(c,f,j),m=l.up_axis,n=[],o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E;for(p=0,q=l.materials.length;p<q;p++){var F=l.materials[p],G=new a.Material(F.mat);G.name=F.name||null;for(v=0,w=F.mat.textures_ref.length;v<w;v++){var H=F.mat.textures_ref[v],I=null;a.Textures_ref[H.image]===undefined?I=new a.Texture(H.image,e.default_filter,j,c):I=a.Textures_obj[a.Textures_ref[H.image]],G.setTexture(I,H.type)}n[F.id]=G}var J=[];for(p=0,q=l.meshes.length;p<q;p++){var K=l.meshes[p],L=new a.Mesh({name:K.id});L.points=K.points;var M=!1;for(x=0,y=K.parts.length;x<y;x++){var N=K.parts[x];if(N.material!==0){var O=n[N.material];O||(O=new a.Material({name:N.material})),L.setFaceMaterial(O)}var P=N.normals.length?!0:!1,Q=N.texcoords.length?!0:!1,R=N.colors.length?!0:!1;R&&(n[N.material].color_map=!0);for(z=0,A=N.faces.length;z<A;z++){var S=L.addFace(N.faces[z]);P&&(L.faces[S].point_normals=N.normals[z]),Q&&(L.faces[S].uvs=N.texcoords[z]),R&&(L.faces[S].point_colors=N.colors[z])}M|=P}L.faces.length&&(j?j.addMesh(c,c+":"+meshId,L):(M||L.calcNormals(),L.triangulateQuads(),L.compile()),J[K.id]=L)}var T=[];for(r=0,s=l.cameras.length;r<s;r++)T[l.cameras[r].id]=l.cameras[r];var U=[];for(t=0,u=l.lights.length;t<u;t++)U[l.lights[t].id]=l.lights[t];var V={},W={},X={},Y={};for(B=0,C=l.scenes.length;B<C;B++){var Z=l.scenes[B],$=new a.Scene;for(D=0,E=Z.sceneObjects.length;D<E;D++){var _=Z.sceneObjects[D],ab=new a.SceneObject(_),bb=(J[_.meshName]?J[_.meshName]:J[_.meshId])||null;ab.obj=bb,_.matrix&&ab.setMatrix(_.matrix),V[_.id]=ab,$.bindSceneObject(ab)}for(t=0,u=Z.lights.length;t<u;t++){var cb=Z.lights[t],db=new a.Light(U[cb.source]);db.position=cb.position,W[cb.id]=db,$.bindLight(db)}if(Z.cameras.length){var eb=Z.cameras[0],fb=new a.Camera(T[eb.source]);fb.position=eb.position,fb.rotation=eb.rotation,X[eb.id]=fb,$.camera=fb}for(z=0,A=Z.parentMap.length;z<A;z++){var gb=Z.parentMap[z];V[gb.parent].bindChild(V[gb.child])}Y[Z.id]=$}for(var hb in l.animations)if(l.animations.hasOwnProperty(hb)){var ib=l.animations[hb];if(ib.channels.length)for(cCount=0,s=ib.channels.length;cCount<s;cCount++){var jb=ib.channels[cCount],kb=ib.samplers[jb.source],lb=ib.sources[kb.INPUT],mb=ib.sources[kb.OUTPUT],nb=ib.sources[kb.INTERPOLATION],ob=ib.sources[kb.IN_TANGENT],pb=ib.sources[kb.OUT_TANGENT],qb=kb.IN_TANGENT!==b,rb=kb.OUT_TANGENT!==b,sb=null,tb=V[jb.targetName],ub=X[jb.targetName],vb=W[jb.targetName];tb?(tb.motion===null&&(tb.motion=new a.Motion),sb=tb.motion):ub?(ub.motion===null&&(ub.motion=new a.Motion),sb=ub.motion):vb&&(vb.motion===null&&(vb.motion=new a.Motion),sb=vb.motion);if(sb===null)continue;var wb=d.motion.POS,xb=d.motion.X;m===2&&(sb.yzflip=!0);var yb=jb.paramName;if(yb==="rotateX"||yb==="rotationX")wb=d.motion.ROT,xb=d.motion.X;else if(yb==="rotateY"||yb==="rotationY")wb=d.motion.ROT,xb=d.motion.Y;else if(yb==="rotateZ"||yb==="rotationZ")wb=d.motion.ROT,xb=d.motion.Z;else if(yb==="location")wb=d.motion.POS,jb.typeName==="X"&&(xb=d.motion.X),jb.typeName==="Y"&&(xb=d.motion.Y),jb.typeName==="Z"&&(xb=d.motion.Z);else if(yb==="translate")wb=d.motion.POS,jb.typeName==="X"&&(xb=d.motion.X),jb.typeName==="Y"&&(xb=d.motion.Y),jb.typeName==="Z"&&(xb=d.motion.Z);else{if(yb==="LENS"){wb=10,xb=10;continue}yb==="FOV"?(wb=d.motion.FOV,xb=3):yb==="ZNEAR"?(wb=d.motion.NEARCLIP,xb=3):yb==="ZFAR"?(wb=d.motion.FARCLIP,xb=3):yb==="intensity"&&(wb=d.motion.INTENSITY,xb=3)}vb&&wb<3&&(vb.method=d.light.method.DYNAMIC);var zb;for(mCount=0,q=lb.data.length;mCount<q;mCount++){k=null;if(typeof mb.data[mCount]=="object")for(i=0,iMax=mb.data[mCount].length;i<iMax;i++)zb=i,m===2&&i===2?zb=1:m===2&&i===1&&(zb=2),k=sb.setKey(wb,zb,lb.data[mCount],g.fixukaxis(l.up_axis,wb,zb,mb.data[mCount][i])),nb&&(o=nb.data[mCount][i],o==="LINEAR"?k.shape=d.envelope.shape.LINE:o==="BEZIER"&&(!qb&&!rb?k.shape=d.envelope.shape.LINEAR:k.shape=d.envelope.shape.BEZI));else{zb=xb,ofs=0,ub&&wb===d.motion.ROT&&m===2&&zb===0&&(ofs=-90),wb===d.motion.ROT?k=sb.setKey(wb,zb,lb.data[mCount],mb.data[mCount]+ofs):(m===2&&xb===2?zb=1:m===2&&xb===1&&(zb=2),k=sb.setKey(wb,zb,lb.data[mCount],g.fixukaxis(l.up_axis,wb,zb,mb.data[mCount])));if(nb){o=nb.data[mCount];if(o==="LINEAR")k.shape=d.envelope.shape.LINE;else if(o==="BEZIER")if(!qb&&!rb)k.shape=d.envelope.shape.LINEAR,k.continutity=1;else{k.shape=d.envelope.shape.BEZ2;var Ab=ob.data[mCount][0],Bb,Cb=pb.data[mCount][0],Db;wb===d.motion.ROT?(Bb=ob.data[mCount][1],Db=pb.data[mCount][1],k.param[0]=Ab-k.time,k.param[1]=Bb-k.value+ofs,k.param[2]=Cb-k.time,k.param[3]=Db-k.value+ofs):(Bb=g.fixukaxis(l.up_axis,wb,zb,ob.data[mCount][1]),Db=g.fixukaxis(l.up_axis,wb,zb,pb.data[mCount][1]),k.param[0]=Ab-k.time,k.param[1]=Bb-k.value,k.param[2]=Cb-k.time,k.param[3]=Db-k.value)}}}}}}var Eb=null;return l.scene?Eb=Y[l.scene]:Eb=Y.pop(),Eb}var b=a.undef,c=function(){},d=a.enums,e=a.GLCore,f=a.log,g={fixuaxis:function(a,b){if(a===0)return[b[1],b[0],b[2]];if(a===1)return b;if(a===2)return[b[0],b[2],-b[1]]},fixscaleaxis:function(a,b){if(a===0)return[b[1],b[0],b[2]];if(a===1)return b;if(a===2)return[b[0],b[2],b[1]]},fixukaxis:function(a,b,c,e){return b===d.motion.POS&&c===d.motion.Z&&a===d.motion.Z?-e:e},getAllOf:function(a,b){var c=[a],d=[],e,f,g,h;while(c.length){e=c.pop();for(f in e){if(!e.hasOwnProperty(f))continue;if(f===b)if(e[f].length)for(g=0,h=e[f].length;g<h;g++)d.push(e[f][g]);else d.push(e[f]);if(typeof e[f]=="object")if(e[f].length)for(g=0,h=e[f].length;g<h;g++)c.push(e[f][g]);else c.push(e[f])}}return d},quaternionFilterZYYZ:function(c,d){var e=a.vec3,f=c,g=new a.Quaternion;return d!==b&&(f=e.add(c,d)),g.fromEuler(f[0],f[2],-f[1]),g.toEuler()},cl_getInitalTransform:function(b,c){var d=a.util,e={position:[0,0,0],rotation:[0,0,0],scale:[1,1,1]},f=c.translate,h=c.rotate,i=c.scale,j=c.matrix;if(j&&!f&&!h&&!i)return e;f&&f.$&&(e.position=g.fixuaxis(b,d.floatDelimArray(f.$," ")));if(h)for(var k=0,l=h.length;k<l;k++){var m=h[k],n=m["@sid"],o=d.floatDelimArray(m.$," ");if(n=="rotateX"||n=="rotationX")e.rotation[0]=o[3];else if(n=="rotateY"||n=="rotationY")e.rotation[1]=o[3];else if(n=="rotateZ"||n=="rotationZ")e.rotation[2]=o[3]}return i&&(e.scale=g.fixscaleaxis(b,d.floatDelimArray(i.$," "))),e}},l={loadCollada:j,parseCollada:h};return l}),CubicVR.RegisterModule("CVRXML",function(a){function h(a,b,c,d){var e=CubicVR.util,f=null,h=null;d.triangles&&(h=e.intDelimArray(g.getTextNode(d,"triangles")," "));if(!h)return;d.segments&&(f=e.intDelimArray(g.getTextNode(d,"segments")," ")),f===null&&(f=[0,parseInt(h.length/3,10)]);var i=0;a.setFaceMaterial(b);if(h.length)for(p=0,pMax=f.length;p<pMax;p+=2){var k=f[p],l=f[p+1]*3;a.setSegment(k);for(j=i,jMax=i+l;j<jMax;j+=3){var m=a.addFace([h[j],h[j+1],h[j+2]]);c&&a.faces[m].setUV([c[j],c[j+1],c[j+2]])}i+=l}}function k(a,b){var c=CubicVR.util,e=new CubicVR.UVMapper,f=null,h=null;if(a.type){f=g.getTextNode(a,"type");switch(f){case"uv":break;case"planar":e.projection_mode=d.uv.projection.PLANAR;break;case"cylindrical":e.projection_mode=d.uv.projection.CYLINDRICAL;break;case"spherical":e.projection_mode=d.uv.projection.SPHERICAL;break;case"cubic":e.projection_mode=d.uv.projection.CUBIC}}if(!f)return null;f==="uv"&&a.uv&&(h=g.getPoints(a,"uv"));if(a.axis){var i=g.getTextNode(a,"axis");switch(i){case"x":e.projection_axis=d.uv.axis.X;break;case"y":e.projection_axis=d.uv.axis.Y;break;case"z":e.projection_axis=d.uv.axis.Z}}return a.center&&(e.center=c.floatDelimArray(g.getTextNode(a,"center"))),a.rotation&&(e.rotation=c.floatDelimArray(g.getTextNode(a,"rotation"))),a.scale&&(e.scale=c.floatDelimArray(g.getTextNode(a,"scale"))),a.wrap_w&&(e.wrap_w_count=parseFloat(g.getTextNode(a,"wrap_w"))),a.wrap_h&&(e.wrap_h_count=parseFloat(g.getTextNode(a,"wrap_h"))),f!==""&&f!=="uv"?e:h}function l(c,e){var f=CubicVR.util,h=c.name?c.name.$:null,i=new CubicVR.Material({name:h});c.shininess&&(i.shininess=g.getFloatNode(c,"shininess",i.shininess)/100),i.opacity=g.getFloatNode(c,"alpha",i.opacity),i.max_smooth=g.getFloatNode(c,"max_smooth",i.max_smooth),i.color=g.getFloatDelimNode(c,"color",i.color),i.ambient=g.getFloatDelimNode(c,"ambient",i.ambient),i.diffuse=g.getFloatDelimNode(c,"diffuse",i.diffuse),i.specular=g.getFloatDelimNode(c,"specular",i.specular);var j;return!(j=g.getTextNode(c,"texture"))||(j=(e?e:"")+j,tex=a.Textures_ref[j]!==b?a.Textures_obj[a.Textures_ref[j]]:new CubicVR.Texture(j),i.setTexture(tex,d.texture.map.COLOR)),!(j=g.getTextNode(c,"texture_luminosity"))||(j=(e?e:"")+j,tex=a.Textures_ref[j]!==b?a.Textures_obj[a.Textures_ref[j]]:new CubicVR.Texture(j),i.setTexture(tex,d.texture.map.AMBIENT)),!(j=g.getTextNode(c,"texture_normal"))||(j=(e?e:"")+j,tex=a.Textures_ref[j]!==b?a.Textures_obj[a.Textures_ref[j]]:new CubicVR.Texture(j),i.setTexture(tex,d.texture.map.NORMAL)),!(j=g.getTextNode(c,"texture_specular"))||(j=(e?e:"")+j,tex=a.Textures_ref[j]!==b?a.Textures_obj[a.Textures_ref[j]]:new CubicVR.Texture(j),i.setTexture(tex,d.texture.map.SPECULAR)),!(j=g.getTextNode(c,"texture_bump"))||(j=(e?e:"")+j,tex=a.Textures_ref[j]!==b?a.Textures_obj[a.Textures_ref[j]]:new CubicVR.Texture(j),i.setTexture(tex,d.texture.map.BUMP)),!(j=g.getTextNode(c,"texture_envsphere"))||(j=(e?e:"")+j,tex=a.Textures_ref[j]!==b?a.Textures_obj[a.Textures_ref[j]]:new CubicVR.Texture(j),i.setTexture(tex,d.texture.map.ENVSPHERE)),!(j=g.getTextNode(c,"texture_alpha"))||(j=(e?e:"")+j,tex=a.Textures_ref[j]!==b?a.Textures_obj[a.Textures_ref[j]]:new CubicVR.Texture(j),i.setTexture(tex,d.texture.map.ALPHA)),i}function m(a,c){if(f[a]!==b)return f[a];var d=CubicVR.util,e,i,j,m,n,o,p=null;typeof a=="object"?p=a:a.indexOf(".js")!=-1?p=d.getJSON(a):p=CubicVR.util.xml2badgerfish(d.getXML(a)),p.root&&(p=p.root),p.properties&&(p=p.properties);var q=new CubicVR.Mesh;if(p.points){var r=g.getPoints(p,"points");r&&q.addPoint(r)}var s=p.material;s&&!s.length&&(s=[s]);var t=[];if(s)for(e=0,m=s.length;e<m;e++){var u=s[e],v=l(u,c),w=null,x=null,y=null;u.uvmapper&&(x=k(u.uvmapper),x&&!x.length?t.push([x,v]):y=x);var z=u.part;z&&!z.length&&(z=[z]);if(z&&z.length){var A=null,B=null;for(i=0,n=z.length;i<n;i++){var C=z[i];A=null,y=null,w=C.uvmapper;if(w){A=k(w);if(u.triangles){var D=q.faces.length,E=D;A&&!A.length?(h(q,v,null,C),E=q.faces.length-1,q.calcFaceNormals(D,E),A.apply(q,v,b,D,E)):A&&A.length?h(q,v,A,C):x&&!x.length&&(h(q,v,null,C),E=q.faces.length-1,q.calcFaceNormals(D,E),x.apply(q,v,b,D,E))}}if(C.procedural){w=C.uvmapper,w&&(A=k(w)),C.transform?B=g.getTransform(C.transform):B=b;var F=b,G=C.procedural,H=g.getTextNode(G,"type");B&&(F=new CubicVR.Transform,F.translate(B.position),F.pushMatrix(),F.rotate(B.rotation),F.pushMatrix(),F.scale(B.scale)),x||(x=b);var I={material:v,uvmapper:x||A};if(H==="box"||H==="cube")I.size=g.getFloatNode(G,"size"),q.booleanAdd(CubicVR.primitives.box(I),F);else if(H==="sphere")I.radius=g.getFloatNode(G,"radius"),I.lat=g.getIntNode(G,"lat"),I.lon=g.getIntNode(G,"lon"),q.booleanAdd(CubicVR.primitives.sphere(I),F);else if(H==="cone")I.base=g.getFloatNode(G,"base"),I.height=g.getFloatNode(G,"height"),I.lon=g.getIntNode(G,"lon"),q.booleanAdd(CubicVR.primitives.cone(I),F);else if(H==="plane")I.size=g.getFloatNode(G,"size"),q.booleanAdd(CubicVR.primitives.plane(I),F);else if(H==="cylinder")I.radius=g.getFloatNode(G,"radius"),I.height=g.getFloatNode(G,"height"),I.lon=g.getIntNode(G,"lon"),q.booleanAdd(CubicVR.primitives.cylinder(I),F);else if(H==="torus")I.innerRadius=g.getFloatNode(G,"innerRadius"),I.outerRadius=g.getFloatNode(G,"outerRadius"),I.lat=g.getIntNode(G,"lat"),I.lon=g.getIntNode(G,"lon"),q.booleanAdd(CubicVR.primitives.torus(I),F);else if(H==="lathe")I.points=g.getPoints(G,"p"),I.lon=g.getIntNode(G,"lon"),q.booleanAdd(CubicVR.primitives.lathe(I),F);else if(H==="polygon"){var J=g.getPoints(G,"p"),K=new CubicVR.Polygon(J),L=G.cut;L&&!L.length&&(L=[L]);if(L.length)for(i=0,m=L.length;i<n;i++)K.cut(new CubicVR.Polygon(g.getPoints(L[i])));I.front=0,I.back=0,I.frontShift=0,I.backShift=0,I.frontDepth=0,I.backDepth=0;if(G.extrude){var M=G.extrude;I.front=g.getFloatNode(M,"front",0),I.back=g.getFloatNode(M,"back",0),I.frontShift=g.getFloatNode(M,"frontBevelShift",0),I.backShift=g.getFloatNode(M,"backBevelShift",0),I.frontDepth=g.getFloatNode(M,"frontBevelDepth",0),I.backDepth=g.getFloatNode(M,"backBevelDepth",0),I.depth=g.getFloatNode(M,"depth",0),I.shift=g.getFloatNode(M,"shift",0),I.bevel=g.getFloatNode(M,"bevel",0),I.depth&&!
I.backDepth&&!I.frontDepth&&(I.front=-I.depth/2,I.back=I.depth/2),I.shift&&!I.backShift&&!I.frontShift&&(I.frontShift=I.shift,I.backShift=I.shift),I.bevel&&!I.backDepth&&!I.frontDepth&&(I.frontDepth=I.bevel,I.backDepth=I.bevel)}var N=K.toExtrudedBeveledMesh(new CubicVR.Mesh,I);N.setFaceMaterial(I.material),q.booleanAdd(N,F)}}}}else h(q,v,y,u)}q.triangulateQuads(),q.calcNormals();for(e=0,m=t.length;e<m;e++)t[e][0].apply(q,t[e][1]);return q.compile(),f[a]=q,q}function n(a){return a===null?!1:a.getElementsByTagName("x").length||a.getElementsByTagName("y").length||a.getElementsByTagName("z").length||a.getElementsByTagName("fov").length}function o(a,c,e){var f=CubicVR.util,g=[];g[0]=a.getElementsByTagName("x"),g[1]=a.getElementsByTagName("y"),g[2]=a.getElementsByTagName("z"),g[3]=a.getElementsByTagName("fov");var h,i,j,k,l;for(var m in g)if(g.hasOwnProperty(m)&&g[m]!==b&&g[m].length){h=g[m][0].getElementsByTagName("time"),i=g[m][0].getElementsByTagName("value"),j=g[m][0].getElementsByTagName("in"),k=g[m][0].getElementsByTagName("out"),l=g[m][0].getElementsByTagName("tcb");var n=null,o=null,p=null,q=null,r=null;j.length&&(q=f.collectTextNode(j[0])),k.length&&(r=f.collectTextNode(k[0])),h.length&&(n=f.floatDelimArray(f.collectTextNode(h[0])," ")),i.length&&(o=f.floatDelimArray(f.collectTextNode(i[0])," ")),l.length&&(p=f.floatDelimArray(f.collectTextNode(l[0])," "));if(n!==null&&o!==null)for(var s=0,t=n.length;s<t;s++){var u=e.setKey(c,m,n[s],o[s]);p&&(u.tension=p[s*3],u.continuity=p[s*3+1],u.bias=p[s*3+2])}var v=d.envelope.behavior.CONSTANT,w=d.envelope.behavior.CONSTANT;if(q)switch(q){case"reset":v=d.envelope.behavior.RESET;break;case"constant":v=d.envelope.behavior.CONSTANT;break;case"repeat":v=d.envelope.behavior.REPEAT;break;case"oscillate":v=d.envelope.behavior.OSCILLATE;break;case"offset":v=d.envelope.behavior.OFFSET;break;case"linear":v=d.envelope.behavior.LINEAR}if(r)switch(r){case"reset":w=d.envelope.behavior.RESET;break;case"constant":w=d.envelope.behavior.CONSTANT;break;case"repeat":w=d.envelope.behavior.REPEAT;break;case"oscillate":w=d.envelope.behavior.OSCILLATE;break;case"offset":w=d.envelope.behavior.OFFSET;break;case"linear":w=d.envelope.behavior.LINEAR}e.setBehavior(c,m,v,w)}}function q(a,c,e){var f=CubicVR.util;c===b&&(c=""),e===b&&(e="");var g=new CubicVR.Mesh,h=f.getXML(a),i=new CubicVR.Scene,j=[],k=h.getElementsByTagName("sceneobjects"),l,p,q,r;for(var s=0,t=k[0].childNodes.length;s<t;s++){var u=k[0].childNodes[s];if(u.tagName==="sceneobject"){var v="unnamed",w="",x="";l=u.getElementsByTagName("name"),l.length&&(v=f.collectTextNode(l[0])),l=u.getElementsByTagName("parent"),l.length&&(w=f.collectTextNode(l[0])),l=u.getElementsByTagName("model"),l.length&&(x=f.collectTextNode(l[0])),p=null,q=null,r=null,l=u.getElementsByTagName("position"),l.length&&(p=l[0]),l=u.getElementsByTagName("rotation"),l.length&&(q=l[0]),l=u.getElementsByTagName("scale"),l.length&&(r=l[0]),g=null,x!==""&&(g=m(c+x,e));var y=new CubicVR.SceneObject(g,v);n(p)?(y.motion||(y.motion=new CubicVR.Motion),o(p,d.motion.POS,y.motion)):p&&(y.position=f.floatDelimArray(f.collectTextNode(p))),n(q)?(y.motion||(y.motion=new CubicVR.Motion),o(q,d.motion.ROT,y.motion)):y.rotation=f.floatDelimArray(f.collectTextNode(q)),n(r)?(y.motion||(y.motion=new CubicVR.Motion),o(r,d.motion.SCL,y.motion)):y.scale=f.floatDelimArray(f.collectTextNode(r)),i.bindSceneObject(y),w!==""&&j.push([y,w])}}for(var z in j)j.hasOwnProperty(z)&&i.getSceneObject(j[z][1]).bindChild(j[z][0]);var A=h.getElementsByTagName("camera");if(A.length){p=null,q=null;var B="";l=A[0].getElementsByTagName("name");var C=i.camera,D=null;l.length&&(B=l[0].firstChild.nodeValue),l=A[0].getElementsByTagName("target"),l.length&&(B=l[0].firstChild.nodeValue),B!==""&&(C.targetSceneObject=i.getSceneObject(B)),l=A[0].getElementsByTagName("position"),l.length&&(p=l[0]),l=A[0].getElementsByTagName("rotation"),l.length&&(q=l[0]),l=A[0].getElementsByTagName("fov"),l.length&&(D=l[0]),n(p)?(C.motion||(C.motion=new CubicVR.Motion),o(p,d.motion.POS,C.motion)):p&&(C.position=f.floatDelimArray(p.firstChild.nodeValue)),n(q)?(C.motion||(C.motion=new CubicVR.Motion),o(q,d.motion.ROT,C.motion)):q&&(C.rotation=f.floatDelimArray(q.firstChild.nodeValue)),n(D)?(C.motion||(C.motion=new CubicVR.Motion),o(D,d.motion.FOV,C.motion)):D&&(C.fov=parseFloat(D.firstChild.nodeValue))}return i}var b=a.undef,c=function(){},d=CubicVR.enums,e=a.GLCore,f=[],g={getPoints:function(a,c,d){var e=CubicVR.util,f;c?f=g.getTextNode(a,c):f=a.$;if(!f)return b;var h=f.split(" "),k,l;for(i=0,iMax=h.length;i<iMax;i++){h[i]=h[i].split(",");for(j=0,jMax=h[i].length;j<jMax;j++)h[i][j]=parseFloat(h[i][j]);d&&(h[i][2]=0)}return h},getTransform:function(a){var b=CubicVR.util;if(!a)return null;var c={position:[0,0,0],rotation:[0,0,0],scale:[1,1,1]},d,e,f,g;return postition=a.position,e=a.rotation,f=a.scale,d&&(c.position=b.floatDelimArray(d.$)),e&&(c.rotation=b.floatDelimArray(e.$)),f&&(c.scale=b.floatDelimArray(f.$)),d||e||f?c:null},getTextNode:function(a,b,c){var d=CubicVR.util,e=a[b];return e?(e.length&&(e=e[0]),e.$?e.$:c):c},getFloatNode:function(a,b,c){var d=CubicVR.util,e=g.getTextNode(a,b);if(e){var f=parseFloat(e);return f!=f?c:f}return c},getIntNode:function(a,b,c){var d=CubicVR.util,e=g.getTextNode(a,b);if(e){var f=parseInt(e,10);return f!=f?c:f}return c},getFloatDelimNode:function(a,b,c,d){var e=CubicVR.util,f=g.getTextNode(a,b);return f?e.floatDelimArray(f,d):c},getIntDelimNode:function(a,b,c,d){var e=CubicVR.util,f=g.getTextNode(a,b);return f?e.intDelimArray(f,d):c}},r={loadMesh:m,loadScene:q};return r}),CubicVR.RegisterModule("Camera",function(a){function g(c,d,e,g,h){var i=a.mat4;this.frustum=new a.Frustum;if(typeof c=="object"){var j=c;this.position=j.position||[0,0,-1],this.rotation=j.rotation||[0,0,0],this.target=j.target||[0,0,0],this.fov=j.fov||60,this.nearclip=j.nearclip||j.nearClip||j.near||.1,this.farclip=j.farclip||j.farClip||j.far||400,this.targeted=j.targeted!==b?j.targeted:!0,this.calc_nmatrix=j.calcNormalMatrix!==b?j.calcNormalMatrix:!0,this.name=j.name||"camera"+f,d=j.height?j.height:b,c=j.width?j.width:b}else this.position=[0,0,0],this.rotation=[0,0,0],this.target=[0,0,0],this.fov=e!==b?e:60,this.nearclip=g!==b?g:.1,this.farclip=h!==b?h:400,this.targeted=!0,this.calc_nmatrix=!0,this.name="camera"+f;this.targetSceneObject=null,this.motion=null,this.transform=new a.Transform,this.manual=!1,this.setDimensions(c!==b?c:512,d!==b?d:512),this.mvMatrix=i.identity(),this.pMatrix=null,this.calcProjection(),this.ortho=!1,this.ortho_view={left:-1,right:1,bottom:-1,top:1},this.parent=null,++f}function h(a){this.position=a!==b?a:[0,0,0]}function i(c,d,e){this.camPath=new a.Motion,this.targetPath=new a.Motion,this.start_position=c!==b?c:[8,8,8],this.target=d!==b?d:[0,0,0],this.bounds=e!==b?e:[[-15,3,-15],[15,20,15]],this.safe_bb=[],this.avoid_sphere=[],this.segment_time=3,this.buffer_time=20,this.start_time=0,this.current_time=0,this.path_time=0,this.path_length=0,this.min_distance=2,this.max_distance=40,this.angle_min=40,this.angle_max=180}var b=a.undef,c=a.enums,d=a.GLCore,e=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],f=0;g.prototype={trackTarget:function(b,c,d){this.position=a.vec3.trackTarget(this.position,b,c,d)},setParent:function(a){this.parent=a},hasParent:function(){return!!this.parent},getParent:function(){return this.parent},getParentedPosition:function(){return this.parent!==null&&this.mvMatrix&&this.parent.tMatrix?a.mat4.vec3_multiply(this.position,this.parent.tMatrix):this.position},setOrtho:function(a,b,c,d){this.ortho=!0,this.ortho_view.left=a,this.ortho_view.right=b,this.ortho_view.bottom=c,this.ortho_view.top=d},control:function(a,b,d){a===c.motion.ROT?this.rotation[b]=d:a===c.motion.POS?this.position[b]=d:a===c.motion.FOV?this.setFOV(d):a===c.motion.LENS?this.setLENS(d):a===c.motion.NEARCLIP?this.setClip(d,this.farclip):a===c.motion.FARCLIP&&this.setClip(this.nearclip,d)},makeFrustum:function(a,b,c,d,e,f){var g=(b+a)/(b-a),h=(d+c)/(d-c),i=-(f+e)/(f-e),j=-2*f*e/(f-e);return[2*e/(b-a),0,0,0,0,2*e/(d-c),0,0,g,h,i,-1,0,0,j,0]},setTargeted:function(a){this.targeted=a},calcProjection:function(){var b=a.mat4,c=a.mat3,e=a.vec3,f=d.gl;this.ortho?this.pMatrix=b.ortho(this.ortho_view.left,this.ortho_view.right,this.ortho_view.bottom,this.ortho_view.top,this.nearclip,this.farclip):this.pMatrix=b.perspective(this.fov,this.aspect,this.nearclip,this.farclip),!this.targeted&&this.mvMatrix&&(b.identity(this.mvMatrix),b.rotate(-this.rotation[0],-this.rotation[1],-this.rotation[2],this.mvMatrix),b.translate(-this.position[0],-this.position[1],-this.position[2],this.mvMatrix),this.parent&&b.multiply(this.mvMatrix.slice(0),b.inverse(this.parent.tMatrix),this.mvMatrix),this.calc_nmatrix?(this.nMatrix=b.inverse_mat3(this.mvMatrix),c.transpose_inline(this.nMatrix)):b.identity(this.nMatrix)),this.frustum.extract(this,this.mvMatrix,this.pMatrix)},setClip:function(a,b){this.nearclip=a,this.farclip=b,this.calcProjection()},setDimensions:function(a,b){this.width=a,this.height=b,this.aspect=a/b,this.calcProjection()},resize:function(a,b){this.setDimensions(a,b)},setFOV:function(a){this.fov=a,this.ortho=!1,this.calcProjection()},setLENS:function(a){this.setFOV(2*Math.atan(16/a)*(180/Math.PI))},lookat:function(b,c,d,f,g,h,i,j,k){var l=a.mat4,m=a.mat3;if(typeof b=="object"){this.lookat(this.position[0],this.position[1],this.position[2],b[0],b[1],b[2],0,1,0);return}this.mvMatrix=l.lookat(b,c,d,f,g,h,i,j,k),this.rotation[2]&&(this.transform.clearStack(),this.transform.rotate(-this.rotation[2],0,0,1),this.transform.pushMatrix(this.mvMatrix),this.mvMatrix=this.transform.getResult()),this.parent!==null&&l.multiply(this.mvMatrix.slice(0),l.inverse(this.parent.tMatrix),this.mvMatrix),this.calc_nmatrix?(this.nMatrix=l.inverse_mat3(this.mvMatrix),m.transpose_inline(this.nMatrix)):this.nMatrix=e,this.frustum.extract(this,this.mvMatrix,this.pMatrix)},unProject:function(c,d,e){var f=a.mat4,g=a.vec3,h=[0,0,this.width,this.height],i=[(c-h[0])/h[2]*2-1,-((d-h[1])/h[3]*2-1),1,1],j=f.vec4_multiply(f.vec4_multiply(i,f.inverse(this.pMatrix)),f.inverse(this.mvMatrix)),k=[j[0]/j[3],j[1]/j[3],j[2]/j[3]];if(e!==b){var l=this.getParentedPosition();return g.add(l,g.multiply(g.normalize(g.subtract(k,l)),e))}return k},project:function(b,c,d){var e=a.mat4,f=[b,c,d,1],g=e.vec4_multiply(e.vec4_multiply(f,this.mvMatrix),this.pMatrix);return g[2]=a.vec3.length(a.vec3.subtract([b,c,d],this.position)),[(g[0]/g[3]+1)/2*this.width,(-g[1]/g[3]+1)/2*this.height,g[2]]}},h.prototype={control:function(a,b,d){a===c.motion.POS&&(this.position[b]=d)}},i.prototype={inBounds:function(b){var c=a.vec3;if(b[0]>this.bounds[0][0]&&b[1]>this.bounds[0][1]&&b[2]>this.bounds[0][2]&&b[0]<this.bounds[1][0]&&b[1]<this.bounds[1][1]&&b[2]<this.bounds[1][2]){for(var d=0,e=this.avoid_sphere.length;d<e;d++){var f=c.length(b,this.avoid_sphere[d][0]);if(f<this.avoid_sphere[d][1])return!1}return!0}return!1},findNextNode:function(b,c){var d=a.vec3,e=[this.bounds[1][0]-this.bounds[0][0],this.bounds[1][1]-this.bounds[0][1],this.bounds[1][2]-this.bounds[0][2]],f=[0,0,0],g=[0,0,0],h=0,i=0,j=!1;do{g[0]=Math.random()-.5,g[1]=Math.random()-.5,g[2]=Math.random()-.5,g=d.normalize(g);var k=Math.random();h=k*(this.max_distance-this.min_distance)+this.min_distance,f=d.add(c.position,d.multiply(g,h)),j=this.inBounds(f),i++;if(i>30){f=c.position;break}}while(!j);return f},run:function(a){this.current_time=a,this.path_time===0&&(this.path_time=this.current_time,this.camPath.setKey(c.motion.POS,c.motion.X,this.path_time,this.start_position[0]),this.camPath.setKey(c.motion.POS,c.motion.Y,this.path_time,this.start_position[1]),this.camPath.setKey(c.motion.POS,c.motion.Z,this.path_time,this.start_position[2]));while(this.path_time<this.current_time+this.buffer_time){this.path_time+=this.segment_time;var b=new h,d=new h;this.path_length&&this.camPath.apply(this.path_time-this.segment_time*2,b),this.camPath.apply(this.path_time-this.segment_time,d);var e=this.findNextNode(b,d);this.camPath.setKey(c.motion.POS,c.motion.X,this.path_time,e[0]),this.camPath.setKey(c.motion.POS,c.motion.Y,this.path_time,e[1]),this.camPath.setKey(c.motion.POS,c.motion.Z,this.path_time,e[2]),this.path_length++}var f=new h;return this.camPath.apply(a,f),f.position},addSafeBound:function(a,b){this.safe_bb.push([a,b])},addAvoidSphere:function(a,b){this.avoid_sphere.push([a,b])}};var j={Camera:g,AutoCamera:i};return j}),CubicVR.RegisterModule("CollisionMap",function(a){var b=a.undef,c=a.util,d=a.vec3,e=a.enums;e.collision={shape:{BOX:0,SPHERE:1,CYLINDER:2,CONE:3,CAPSULE:4,MESH:5,HEIGHTFIELD:6,CONVEX_HULL:7}};var f=function(a){this.shapes=[],this.result=null;if(a){a&&!a.length&&(a=[a]);for(var b=0,c=a.length;b<c;b++)this.addShape(a[b])}};f.prototype={addShape:function(b){b.type=a.parseEnum(e.collision.shape,b.type),b.position=b.position||[0,0,0],b.rotation=b.rotation||[0,0,0],b.size=b.size||[1,1,1],b.radius=b.radius||1,b.height=b.height||1,b.margin=b.margin||0,b.mesh=b.mesh||null,this.shapes.push(b)},getShapes:function(){return this.shapes},setResult:function(a){this.result=a},getResult:function(){return this.result}};var g={CollisionMap:f};return g}),CubicVR.RegisterModule("GML",function(a){function e(a){var c=CubicVR.util;this.strokes=[],this.bounds=[1,1,1],this.origin=[0,0,0],this.upvector=[0,1,0],this.viewvector=[0,0,1],this.manual_pos=0;if(a===b)return;var d=c.getXML(a),e=d.getElementsByTagName("header");if(!e.length)return null;var f=e[0],g=d.getElementsByTagName("environment");if(!g.length)return null;this.name=null;var h=f.getElementsByTagName("name");h.length&&(this.name=c.collectTextNode(h[0]));var i=g[0].getElementsByTagName("screenBounds");i.length&&(this.bounds=[parseFloat(c.collectTextNode(i[0].getElementsByTagName("x")[0])),parseFloat(c.collectTextNode(i[0].getElementsByTagName("y")[0])),parseFloat(c.collectTextNode(i[0].getElementsByTagName("z")[0]))]);var j=g[0].getElementsByTagName("origin");j.length&&(this.origin=[parseFloat(c.collectTextNode(j[0].getElementsByTagName("x")[0])),parseFloat(c.collectTextNode(j[0].getElementsByTagName("y")[0])),parseFloat(c.collectTextNode(j[0].getElementsByTagName("z")[0]))]);var k=g[0].getElementsByTagName("up");k.length&&(this.upvector=[parseFloat(c.collectTextNode(k[0].getElementsByTagName("x")[0])),parseFloat(c.collectTextNode(k[0].getElementsByTagName("y")[0])),parseFloat(c.collectTextNode(k[0].getElementsByTagName("z")[0]))]);var l=d.getElementsByTagName("drawing"),m=[];for(var n=0,o=l.length;n<o;n++){var p=l[n],q=p.getElementsByTagName("stroke"),r=0,s=0,t=0,u=0;for(var v=0,w=q.length;v<w;v++){var x=q[v],y=x.getElementsByTagName("pt"),z=y.length,A=new Array(z),B,C,D,E;for(var F=0,G=z;F<G;F++){var H=y[F];B=parseFloat(c.collectTextNode(H.getElementsByTagName("x")[0])),C=parseFloat(c.collectTextNode(H.getElementsByTagName("y")[0])),D=parseFloat(c.collectTextNode(H.getElementsByTagName("z")[0])),E=parseFloat(c.collectTextNode(H.getElementsByTagName("time")[0])),this.upvector[0]===1?A[F]=[C!==C?0:C,B!==B?0:-B,D!==D?0:D,E]:this.upvector[1]===1?A[F]=[B!==B?0:B,C!==C?0:C,D!==D?0:D,E]:this.upvector[2]===1&&(A[F]=[B!==B?0:B,D!==D?0:-D,C!==C?0:C,E]),r<B&&(r=B),s<C&&(s=C),t<D&&(t=D),u<E&&(u=E)}if(t>u)for(var I=0,J=A.length;I<J;I++){var K=A[I][3];A[I][3]=A[I][2],A[I][2]=K/this.bounds[2]}this.strokes[v]=A}}}var b=a.undef,c=a.GLCore,d=CubicVR.enums;e.prototype={addStroke:function(a,c){var d=[];c===b&&(c=.1);for(var e=0,f=a.length;e<f;e++){var g=[a[e][0],a[e][1],a[e][2]];this.manual_pos+=c,g.push(this.manual_pos),d.push(g)}this.strokes.push(d)},recenter:function(){var a=CubicVR.vec3,b=[0,0,0],c=[this.strokes[0][0][0],this.strokes[0][0][1],this.strokes[0][0][2]],d,e,f,g;for(f=0,g=this.strokes.length;f<g;f++)for(d=0,e=this.strokes[f].length;d<e;d++)b[0]>this.strokes[f][d][0]&&(b[0]=this.strokes[f][d][0]),b[1]>this.strokes[f][d][1]&&(b[1]=this.strokes[f][d][1]),b[2]>this.strokes[f][d][2]&&(b[2]=this.strokes[f][d][2]),c[0]<this.strokes[f][d][0]&&(c[0]=this.strokes[f][d][0]),c[1]<this.strokes[f][d][1]&&(c[1]=this.strokes[f][d][1]),c[2]<this.strokes[f][d][2]&&(c[2]=this.strokes[f][d][2]);var h=a.multiply(a.subtract(c,b),.5);for(f=0,g=this.strokes.length;f<g;f++)for(d=0,e=this.strokes[f].length;d<e;d++)this.strokes[f][d][0]=this.strokes[f][d][0]-h[0],this.strokes[f][d][1]=this.strokes[f][d][1]-(this.upvector[1]?h[1]:-h[1]),this.strokes[f][d][2]=this.strokes[f][d][2]-h[2]},generateObject:function(a,c,d,e,f){var g=CubicVR.vec3;a===b&&(a=0),c===b&&(c=0),f===b&&(f=!1);var h=3;e===b&&(e=.02),d===b&&(d=.015);var i=c!==0,j=0,k=0,l=new CubicVR.Mesh(this.name),m,n,o,p,q,r,s;for(var t=0,u=this.strokes.length;t<u;t++){var v=new CubicVR.Envelope,w=new CubicVR.Envelope,x=new CubicVR.Envelope,y=this.strokes[t].length,z=0,A=[],B=[],C=0,D=this.strokes[t];for(s=0;s<y;s++){var E=D[s],F=v.addKey(E[3],E[0]),G=w.addKey(E[3],E[1]),H;f?H=x.addKey(E[3],E[2]):H=x.addKey(E[3],0),F.tension=.5,G.tension=.5,H.tension=.5;if(s!==0){var I=E[0]-m,J=E[1]-n,K=E[2]-o,L=E[3]-p,M=Math.sqrt(I*I+J*J+K*K);z+=M,A[s-1]=M,B[s-1]=L}else C=E[3];m=E[0],n=E[1],o=E[2],p=E[3]}var N=C,O=l.points.length;for(s=0;s<A.length;s++){var P=A[s],Q=B[s],R=Math.ceil(P/e*h);for(var S=N,T=N+Q,U=Q/R;S<T-U;S+=U){S===N&&(m=v.evaluate(S),n=w.evaluate(S),o=x.evaluate(S));var V,W,X;V=v.evaluate(S+U),W=w.evaluate(S+U),X=x.evaluate(S+U);var Y=V-m,Z=W-n,$=X-o,_=Math.sqrt(Y*Y+Z*Z+$*$),ab;ab=g.multiply(g.normalize(g.cross(this.viewvector,g.normalize([Y,Z,$]))),d/2),l.addPoint([m-ab[0],-(n-ab[1]),o-ab[2]+(i?c/2:0)]),l.addPoint([m+ab[0],-(n+ab[1]),o+ab[2]+(i?c/2:0)]),m=V,n=W,o=X}N+=Q}var bb=l.points.length;if(i)for(q=O,r=bb;q<r;q++)l.addPoint([l.points[q][0],l.points[q][1],l.points[q][2]-(i?c/2:0)]);for(q=0,r=bb-O;q<=r-4;q+=2){j%a===0&&k++,l.setSegment(k);var cb=[O+q,O+q+1,O+q+3,O+q+2],db=l.addFace(cb);if(i){var eb=[cb[3]+bb-O,cb[2]+bb-O,cb[1]+bb-O,cb[0]+bb-O];db=l.addFace(eb),eb=[O+q,O+q+2,O+q+2+bb-O,O+q+bb-O],db=l.addFace(eb),eb=[O+q+1+bb-O,O+q+3+bb-O,O+q+3,O+q+1],db=l.addFace(eb),q===0&&(eb=[O+q+bb-O,O+q+1+bb-O,O+q+1,O+q],db=l.addFace(eb)),q===r-4&&(eb=[O+q+2,O+q+3,O+q+3+bb-O,O+q+2+bb-O],db=l.addFace(eb))}j++}}return l.calcFaceNormals(),l.triangulateQuads(),l.calcNormals(),l.compile(),l}};var f={GML:e};return f}),CubicVR.RegisterModule("Landscape",function(a){function h(b,c,d,f){this.doTransform=function(){},this.tMatrix=e,this.parent=null,this.position=[0,0,0],this.scale=[1,1,1],this.rotation=[0,0,0],this.size=b,this.divisions_w=c,this.divisions_h=d,this.matRef=f,this.children=null,this.visible=!0,this.obj=new a.Mesh({dynamic:!0,buildWireframe:!0});var g,h;this.divisions_w>this.divisions_h?(this.size_w=b,this.size_h=b/this.divisions_w*this.divisions_h):this.divisions_h>this.divisions_w?(this.size_w=b/this.divisions_h*this.divisions_w,this.size_h=b):(this.size_w=b,this.size_h=b);for(h=-(this.size_h/2);h<this.size_h/2;h+=this.size_h/this.divisions_h)for(g=-(this.size_w/2);g<this.size_w/2;g+=this.size_w/this.divisions_w)this.obj.addPoint([g+this.size_w/this.divisions_w/2,0,h+this.size_h/this.divisions_h/2]);var i,j;this.obj.setFaceMaterial(this.matRef);for(j=0;j<this.divisions_h-1;j++)for(i=0;i<this.divisions_w-1;i++)this.obj.addFace([i+(j+1)*this.divisions_w,i+1+j*this.divisions_w,i+j*this.divisions_w]),this.obj.addFace([i+(j+1)*this.divisions_w,i+1+(j+1)*this.divisions_w,i+1+j*this.divisions_w])}var b=a.undef,c=a.enums,d=a.GLCore,e=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],f=2*Math.PI,g=Math.PI/2;h.prototype={isWireframe:function(){return!1},getMesh:function(){return this.obj},getEventHandler:function(){return b},setIndexedHeight:function(a,b,c){obj.points[a+b*this.divisions_w][1]=c},mapGen:function(a,c,d,e,f){var g;if(c!==b&&d!==b&&e!==b&&f!==b){if(c>=this.divisions_w)return;if(d>=this.divisions_h)return;c+e>=this.divisions_w&&(e=this.divisions_w-1-c),d+f>=this.divisions_h&&(f=this.divisions_h-1-d);if(e<=0||f<=0)return;for(var h=c,i=c+e;h<i;h++)for(var j=d,k=d+f;j<k;j++){var l=h+j*this.divisions_w;g=this.obj.points[l],g[1]=a(g[0],g[2],l)}}else for(var m=0,n=this.obj.points.length;m<n;m++)g=this.obj.points[m],g[1]=a(g[0],g[2],m)},getFaceAt:function(a,b){if(typeof a=="object")return this.getFaceAt(a[0],a[2]);var c=this.size_w/2-this.size_w/this.divisions_w/2,d=this.size_h/2-this.size_h/this.divisions_h/2,e=parseInt(Math.floor((a+c)/this.size_w*this.divisions_w),10),f=parseInt(Math.floor((b+d)/this.size_h*this.divisions_h),10);if(e<0)return-1;if(e>=this.divisions_w-1)return-1;if(f<0)return-1;if(f>=this.divisions_h-1)return-1;var g=parseInt(e+f*(this.divisions_w-1),10)*2,h=parseInt(g+1,10),i=this.obj.points[this.obj.faces[g].points[0]],j=Math.abs(b-i[2])/Math.abs(a-i[0]);return j>=1?g:h},getHeightValue:function(b,c){var d=a.triangle;if(typeof b=="object")return this.getHeightValue(b[0],b[2]);var e,f,g=this.getFaceAt(b,c);if(g===-1)return 0;e=this.obj.faces[g],f=this.obj.points[this.obj.faces[g].points[0]];var h=d.normal(this.obj.points[this.obj.faces[g].points[0]],this.obj.points[this.obj.faces[g].points[1]],this.obj.points[this.obj.faces[g].points[2]]),i=h[0],j=h[1],k=h[2],l=-(i*f[0])-j*f[1]-k*f[2];return(i*b+k*c+l)/-j},orient:function(a,c,d,e,f,h){h===b&&(h=0);var i,j,k,l,m=[],n,o=d/2,p=e/2,q=Math.sqrt(p*p+o*o),r=Math.atan2(p,o);return f*=Math.PI/180,i=a+Math.sin(f)*h,j=c+Math.cos(f)*h,m[0]=this.getHeightValue([i+q*Math.cos(-r-g+f),0,j+q*-Math.sin(-r-g+f)]),m[1]=this.getHeightValue([i+q*Math.cos(r-g+f),0,j+q*-Math.sin(r-g+f)]),m[2]=this.getHeightValue([i+q*Math.cos(-r+g+f),0,j+q*-Math.sin(-r+g+f)]),m[3]=this.getHeightValue([i+q*Math.cos(r+g+f),0,j+q*-Math.sin(r+g+f)]),k=-Math.atan2(m[1]-m[2],d),l=-Math.atan2(m[0]-m[1],e),k+=-Math.atan2(m[0]-m[3],d),l+=-Math.atan2(m[3]-m[2],e),k/=2,l/=2,[[a,(m[2]+m[3]+m[1]+m[0])/4,c],[k*(180/Math.PI),f,l*(180/Math.PI)]]}};var i={Landscape:h};return i}),CubicVR.RegisterModule("Layout",function(a){function d(a){this.texture=a.texture?a.texture:null,this.width=a.width?a.width:128,this.height=a.height?a.height:128,this.x=a.x?a.x:0,this.y=a.y?a.y:0,this.blend=a.blend?a.blend:!1,this.opacity=typeof a.opacity!="undefined"?a.opacity:1,this.tint=a.tint?a.tint:[1,1,1],this.type="view",this.superView=null,this.childViews=[],this.panel=null}function e(a){this.texture=a.texture?a.texture:null,this.width=a.width?a.width:128,this.height=a.height?a.height:128,this.x=a.x?a.x:0,this.y=a.y?a.y:0,this.blend=a.blend?a.blend:!1,this.opacity=typeof a.opacity!="undefined"?a.opacity:1,this.tint=a.tint?a.tint:[1,1,1],this.type="root",this.superView=null,this.childViews=[],this.setupShader(),this.panel=null,this.makePanel(this)}var b=a.undef,c=a.GLCore;d.prototype={addSubview:function(a){this.childViews.push(a),a.superView=this},makePanel:function(a){return this.superView.makePanel(a)}},e.prototype={resize:function(a,b){this.width=a,this.height=b},setupShader:function(){this.shader=new CubicVR.PostProcessShader({shader_vertex:["attribute vec3 aVertex;","attribute vec2 aTex;","varying vec2 vTex;","uniform vec3 screen;","uniform vec3 position;","uniform vec3 size;","void main(void) {","vTex = aTex;","vec4 vPos = vec4(aVertex.xyz,1.0);","vPos.x *= size.x/screen.x;","vPos.y *= size.y/screen.y;","vPos.x += (size.x/screen.x);","vPos.y -= (size.y/screen.y);","vPos.x += (position.x/screen.x)*2.0 - 1.0;","vPos.y -= (position.y/screen.y)*2.0 - 1.0;","gl_Position = vPos;","}"].join("\n"),shader_fragment:["#ifdef GL_ES","precision highp float;","#endif","uniform sampler2D srcTex;","uniform vec3 tint;","varying vec2 vTex;","void main(void) {","vec4 color = texture2D(srcTex, vTex)*vec4(tint,1.0);","gl_FragColor = color;","}"].join("\n"),init:function(a){a.setInt("srcTex",0),a.addVector("screen"),a.addVector("position"),a.addVector("tint"),a.addVector("size")}})},addSubview:function(a){this.childViews.push(a),a.superView=this},removeSubview:function(a){var b=this.childViews.indexOf(a);b>-1&&this.childViews.splice(b,1)},makePanel:function(a){var b=CubicVR.GLCore.gl,c={};c.vbo_points=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0,-1,-1,0,1,1,0]),c.vbo_uvs=new Float32Array([0,0,1,0,1,1,0,1,0,0,1,1]),c.gl_points=b.createBuffer(),b.bindBuffer(b.ARRAY_BUFFER,c.gl_points),b.bufferData(b.ARRAY_BUFFER,c.vbo_points,b.STATIC_DRAW),c.gl_uvs=b.createBuffer(),b.bindBuffer(b.ARRAY_BUFFER,c.gl_uvs),b.bufferData(b.ARRAY_BUFFER,c.vbo_uvs,b.STATIC_DRAW),a.panel=c},renderPanel:function(a,b){var c=CubicVR.GLCore.gl;if(!a.texture)return!1;a.texture.use(c.TEXTURE0)},renderView:function(a){if(!a.texture)return;var b=CubicVR.GLCore.gl,c=a.offsetLeft,d=a.offsetTop;c||(c=0),d||(d=0);var e=this.shader.shader;e.use(),e.setVector("screen",[this.width,this.height,0]),e.setVector("position",[a.x+c,a.y+d,0]),e.setVector("size",[a.width,a.height,0]),e.setVector("tint",a.tint),a.blend&&(b.enable(b.BLEND),b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA)),a.texture.use(b.TEXTURE0),b.drawArrays(b.TRIANGLES,0,6),a.blend&&(b.disable(b.BLEND),b.blendFunc(b.ONE,b.ZERO))},render:function(){var a=CubicVR.GLCore.gl;a.disable(a.DEPTH_TEST),this.texture&&this.renderView(this);var b=[],c=[];this.offsetLeft=0,this.offsetTop=0,b.push(this);var d=this.shader.shader;d.use(),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,null),a.bindBuffer(a.ARRAY_BUFFER,this.panel.gl_points),a.vertexAttribPointer(d.uniforms.aVertex,3,a.FLOAT,!1,0,0),a.enableVertexAttribArray(d.uniforms.aVertex),a.bindBuffer(a.ARRAY_BUFFER,this.panel.gl_uvs),a.vertexAttribPointer(d.uniforms.aTex,2,a.FLOAT,!1,0,0),a.enableVertexAttribArray(d.uniforms.aTex),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,null);while(b.length){var e=b.pop();this.renderView(e);if(e.childViews.length)for(var f=e.childViews.length-1,g=0;f>=g;f--)e.childViews[f].offsetLeft=e.x+e.offsetLeft,e.childViews[f].offsetTop=e.y+e.offsetTop,b.push(e.childViews[f])}a.disableVertexAttribArray(d.uniforms.aTex),a.enable(a.DEPTH_TEST)}};var f={Layout:e,View:d};return f}),CubicVR.RegisterModule("Light",function(a){function g(b,e){var f=a.mat4,g=a.aabb;b=a.get(b)||{},b===d&&(b=c.light.type.POINT),e===d&&(e=c.light.method.DYNAMIC),typeof b=="object"?(this.light_type=b.type!==d?a.parseEnum(c.light.type,b.type):c.light.type.POINT,this.diffuse=b.diffuse!==d?b.diffuse:[1,1,1],this.specular=b.specular!==d?b.specular:[1,1,1],this.intensity=b.intensity!==d?b.intensity:1,this.position=b.position!==d?b.position:[0,0,0],this.direction=b.direction!==d?b.direction:[0,0,0],this.distance=b.distance!==d?b.distance:this.light_type===c.light.type.AREA?30:10,this.cutoff=b.cutoff!==d?b.cutoff:60,this.map_res=b.map_res!==d?b.map_res:this.light_type===c.light.type.AREA?2048:512,this.map_res=b.mapRes!==d?b.mapRes:this.map_res,this.method=b.method!==d?a.parseEnum(c.light.method,b.method):e,this.areaCam=b.areaCam!==d?b.areaCam:null,this.areaCeiling=b.areaCeiling!==d?b.areaCeiling:40,this.areaFloor=b.areaFloor!==d?b.areaFloor:-40,this.areaAxis=b.areaAxis!==d?b.areaAxis:[1,1,0],this.projectorTex=b.projector!==d?b.projector:null):(this.light_type=a.parseEnum(c.light.type,b),this.diffuse=[1,1,1],this.specular=[1,1,1],this.intensity=1,this.position=[0,0,0],this.direction=[0,0,0],this.distance=this.light_type===c.light.type.AREA?30:10,this.cutoff=60,this.map_res=this.light_type===c.light.type.AREA?2048:512,this.method=a.parseEnum(c.light.method,e),this.areaCam=null,this.areaCeiling=40,this.areaFloor=-40,this.areaAxis=[1,1,0],this.projectorTex=null);if(this.projectorTex&&typeof this.projectorTex=="string"){var h=this.projectorTex;this.projectorTex=a.Textures_ref[h]!==d?a.Textures_obj[a.Textures_ref[h]]:new a.Texture(h)}this.setType(this.light_type),this.lposition=[0,0,0],this.dirty=!0,this.octree_leaves=[],this.octree_common_root=null,this.octree_aabb=[[0,0,0],[0,0,0]],this.ignore_octree=!1,this.visible=!0,this.culled=!0,this.was_culled=!0,this.aabb=[[0,0,0],[0,0,0]],g.reset(this.aabb,this.position),this.adjust_octree=a.SceneObject.prototype.adjust_octree,this.motion=null,this.rotation=[0,0,0],(this.light_type===c.light.type.SPOT_SHADOW||this.light_type===c.light.type.SPOT_SHADOW_PROJECTOR||this.light_type===c.light.type.AREA&&a.features.lightShadows)&&this.setShadow(this.map_res),this.lDir=[0,0,0],this.lPos=[0,0,0],this.parent=null}var b=a.GLCore,c=a.enums,d=a.undef,e=a.util,f=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];c.light={type:{NULL:0,POINT:1,DIRECTIONAL:2,SPOT:3,AREA:4,DEPTH_PACK:5,SPOT_SHADOW:6,SPOT_SHADOW_PROJECTOR:7,MAX:8},method:{GLOBAL:0,STATIC:1,DYNAMIC:2}},g.prototype={setType:function(b){b===c.light.type.AREA&&!a.features.lightShadows?(this.dummyCam=new a.Camera,this.areaCam=new a.Camera,this.updateAreaLight(),this.dummyCam=null,this.areaCam=null,b=c.light.type.DIRECTIONAL):(b===c.light.type.SPOT_SHADOW||b===c.light.type.SPOT_SHADOW_PROJECTOR)&&!a.features.lightShadows&&(b=c.light.type.SPOT),this.light_type=b},setParent:function(a){this.parent=a},setMethod:function(a){this.method=a},setDiffuse:function(a){this.diffuse=a},setSpecular:function(a){this.specular=a},setIntensity:function(a){this.intensity=a},setPosition:function(a){this.position=a},setDistance:function(a){this.distance=a},setCutoff:function(a){this.cutoff=a},prepare:function(b){var d=a.mat4,e=a.mat3,f=this.light_type;if(this.parent)if(f===c.light.type.SPOT||f===c.light.type.SPOT_SHADOW||f===c.light.type.SPOT_SHADOW_PROJECTOR){var g=d.inverse_mat3(this.parent.tMatrix);e.transpose_inline(g),this.lDir=e.vec3_multiply(this.direction,g),this.lDir=e.vec3_multiply(this.lDir,b.nMatrix),this.lPos=d.vec3_multiply(this.position,d.multiply(b.mvMatrix,this.parent.tMatrix))}else f===c.light.type.POINT&&(this.lPos=d.vec3_multiply(this.position,d.multiply(b.mvMatrix,this.parent.tMatrix)));else f===c.light.type.DIRECTIONAL?this.lDir=e.vec3_multiply(this.direction,b.nMatrix):f===c.light.type.SPOT||f===c.light.type.SPOT_SHADOW||f===c.light.type.SPOT_SHADOW_PROJECTOR?(this.lDir=e.vec3_multiply(this.direction,b.nMatrix),this.lPos=d.vec3_multiply(this.position,b.mvMatrix)):f===c.light.type.POINT?this.lPos=d.vec3_multiply(this.position,b.mvMatrix):f===c.light.type.AREA&&(this.lDir=e.vec3_multiply(this.direction,b.nMatrix))},control:function(a,b,d){a===c.motion.POS?this.position[b]=d:a===c.motion.INTENSITY&&(this.intensity=d)},getAABB:function(){var b=a.vec3,c=a.aabb,d=[[0,0,0],[0,0,0]];return c.engulf(d,[this.distance,this.distance,this.distance]),c.engulf(d,[-this.distance,-this.distance,-this.distance]),d[0]=b.add(d[0],this.position),d[1]=b.add(d[1],this.position),this.aabb=d,this.aabb},setDirection:function(b,c,d){var e=a.vec3;if(typeof b=="object"){this.setDirection(b[0],b[1],b[2]);return}return this.direction=e.normalize([b,c,d]),this},lookat:function(b,c,d){var e=a.vec3;if(typeof b=="object"){this.lookat(b[0],b[1],b[2]);return}return this.direction=e.normalize(e.subtract([b,c,d],this.position)),this},setRotation:function(b,c,d){var e=a.mat4,f=a.vec3;if(typeof b=="object"){this.setRotation(b[0],b[1],b[2]);return}var g=new a.Transform;return g.rotate([-b,-c,-d]),g.pushMatrix(),this.direction=f.normalize(e.vec3_multiply([1,0,0],g.getResult())),this.rotation=[b,c,d],this},setupShader:function(a,d){var e=b.gl,f=a;e.uniform3fv(f.lightDiffuse[d],this.diffuse),e.uniform3fv(f.lightSpecular[d],this.specular),this.lPos&&e.uniform3fv(f.lightPosition[d],this.lPos),this.lDir&&e.uniform3fv(f.lightDirection[d],this.lDir),e.uniform1f(f.lightIntensity[d],this.intensity),e.uniform1f(f.lightDistance[d],this.distance),(this.light_type===c.light.type.SPOT_SHADOW||this.light_type===c.light.type.SPOT_SHADOW_PROJECTOR||this.light_type===c.light.type.SPOT)&&e.uniform1f(f.lightCutOffAngle[d],this.cutoff);if(this.light_type===c.light.type.SPOT_SHADOW||this.light_type===c.light.type.SPOT_SHADOW_PROJECTOR||this.light_type===c.light.type.AREA)this.light_type===c.light.type.SPOT_SHADOW_PROJECTOR?(this.shadowMapTex.texture.use(b.gl.TEXTURE0+d*2),e.uniform1i(a.lightShadowMap[d],d*2),this.projectorTex.use(b.gl.TEXTURE0+d*2+1),e.uniform1i(a.lightProjectionMap[d],d*2+1)):(this.shadowMapTex.texture.use(b.gl.TEXTURE0+d),e.uniform1i(a.lightShadowMap[d],d)),e.uniform3fv(a.lightDepthClip[d],[this.dummyCam.nearclip,this.dummyCam.farclip,1/this.map_res]),e.uniformMatrix4fv(a.lightShadowMatrix[d],!1,this.spMatrix)},setShadow:function(b){if(!a.features.lightShadows)return;this.map_res=b,this.shadowMapTex=new a.RenderBuffer(this.map_res,this.map_res,!0),this.shadowMapTex.texture.setFilter(c.texture.filter.NEAREST),this.dummyCam=new a.Camera(this.map_res,this.map_res,80,.1,this.distance),this.dummyCam.calc_nmatrix=!1,this.dummyCam.setTargeted(!0),this.has_shadow=!0},hasShadow:function(){return has_shadow},setProjector:function(a){this.projectorTex=a},hasProjector:function(){return this.projectorTex!==null?!0:!1},shadowBegin:function(){var d=b.gl,e=a.mat4,f=a.mat3;this.shadowMapTex.use(),d.viewport(0,0,this.map_res,this.map_res),d.clear(d.DEPTH_BUFFER_BIT|d.COLOR_BUFFER_BIT),this.light_type!==c.light.type.AREA?(this.dummyCam.setClip(.1,this.distance),this.dummyCam.setFOV(this.cutoff)):this.dummyCam.calcProjection();if(this.parent
){var g=e.inverse_mat3(this.parent.tMatrix);f.transpose_inline(g);var h=f.vec3_multiply(this.direction,g),i=e.vec3_multiply(this.position,this.parent.tMatrix);this.dummyCam.lookat(this.position[0],this.position[1],this.position[2],this.position[0]+this.direction[0]*10,this.position[1]+this.direction[1]*10,this.position[2]+this.direction[2]*10,0,1,0),e.multiply(this.dummyCam.mvMatrix.slice(0),e.inverse(this.parent.tMatrix),this.dummyCam.mvMatrix)}else this.dummyCam.lookat(this.position[0],this.position[1],this.position[2],this.position[0]+this.direction[0]*10,this.position[1]+this.direction[1]*10,this.position[2]+this.direction[2]*10,0,1,0);d.cullFace(d.FRONT)},shadowEnd:function(){var a=b.gl;a.bindFramebuffer(a.FRAMEBUFFER,null),a.cullFace(a.BACK),this.setupTexGen()},setupTexGen:function(){var b=a.mat4,c=[.5,0,0,0,0,.5,0,0,0,0,.5,0,.5,.5,.5,1];this.spMatrix=b.multiply(f,c),this.spMatrix=b.multiply(this.spMatrix,this.dummyCam.pMatrix),this.spMatrix=b.multiply(this.spMatrix,this.dummyCam.mvMatrix)},setAreaAxis:function(a){this.areaAxis=a},updateAreaLight:function(){var b=a.vec3,c=this.areaCeiling-this.areaFloor;this.dummyCam.ortho=!0,this.dummyCam.setClip(.01,1);var d=0,e=Math.tan(this.areaCam.fov/2*(Math.PI/180)),f=b.subtract(this.areaCam.target,this.areaCam.position);f[1]=0,f=b.normalize(f);var g=b.normalize(b.cross(f,[0,1,0])),h=-Math.atan2(f[2],f[0]);d=this.distance/2*Math.abs(e)-this.distance/2,d<this.distance/3/2&&(d=this.distance/3/2),f=b.multiply(f,d);var i=this.areaAxis[0]*(Math.PI/180),j=this.areaAxis[1]*(Math.PI/180),k=Math.tan(i),l=Math.tan(j),m=[l,0,k];h-=Math.atan2(m[0],m[2]),this.position=b.add(b.add(this.areaCam.position,f),b.multiply(m,c)),this.position[1]=this.areaCeiling,this.target=b.add(b.add(this.areaCam.position,f),b.multiply(m,-c)),this.target[1]=this.areaFloor,this.direction=b.normalize(b.subtract(this.target,this.position)),this.dummyCam.rotation[2]=h*(180/Math.PI);var n=this.dummyCam.nearclip,o=this.dummyCam.farclip*Math.abs(this.direction[1])*c,p=this.orthoBounds(this.position,this.distance,this.distance,this.dummyCam.pMatrix,this.dummyCam.mvMatrix,this.dummyCam.nearclip),q;p[0][1]<this.areaCeiling&&(q=this.areaCeiling-p[0][1],n-=q/Math.abs(this.direction[1])),p=this.orthoBounds(this.position,this.distance,this.distance,this.dummyCam.pMatrix,this.dummyCam.mvMatrix,this.dummyCam.farclip),p[1][1]>this.areaFloor&&(q=p[1][1]-this.areaFloor,o+=q/Math.abs(this.direction[1])),n=.01,this.dummyCam.nearclip=n,this.dummyCam.farclip=o,this.dummyCam.setOrtho(-this.distance/2,this.distance/2,-this.distance/2,this.distance/2)},orthoBounds:function(b,c,d,e,f,g){var h=a.vec3,i=h.normalize([f[0],f[4],f[8]]),j=h.normalize([f[1],f[5],f[9]]),k=h.normalize(h.cross(j,i)),l,m;l=c/2,m=d/2;var n=[],o=h.multiply(i,l),p=h.multiply(j,m),q=h.multiply(k,g);n[0]=h.add(h.subtract(b,o),h.add(p,q)),n[1]=h.add(h.add(b,o),h.add(p,q)),n[2]=h.subtract(h.subtract(b,o),h.add(p,q)),n[3]=h.subtract(h.add(b,o),h.add(p,q)),aabb1=n[0],aabb2=n[0];for(var r=1;r<4;r++)aabb1[0]>n[r][0]&&(aabb1[0]=n[r][0]),aabb1[1]>n[r][1]&&(aabb1[1]=n[r][1]),aabb1[2]>n[r][2]&&(aabb1[2]=n[r][2]),aabb2[0]<n[r][0]&&(aabb2[0]=n[r][0]),aabb2[1]<n[r][1]&&(aabb2[1]=n[r][1]),aabb2[2]<n[r][2]&&(aabb2[2]=n[r][2]);return[aabb1,aabb2]}};var h={Light:g};return h}),CubicVR.RegisterModule("PDF",function(a){function e(a){if(!a.src)throw"PDF Error: you must specify a src url for a PDF.";var b=a.src,c=a.width||null,d=a.height||null,e=a.callback||function(){},f,g=[],h=[];this.__defineGetter__("pages",function(){return f?f.numPages:0}),this.getPage=function(a){var b=f.numPages;return a=a<1?1:a,a=a>b?b:a,a-=1,g[a]},this.getPageTexture=function(a,b,c){var d=this.getPage(a);return b=b||d.width,c=c||d.height,new CubicVR.PdfTexture(d,{width:b,height:c})},getPdf({url:b,error:function(){console.log("PDF Error: error loading pdf `"+b+"`")}},function(a){f=new PDFDoc(a);for(var b=1,c=f.numPages;b<=c;b++){var d=f.getPage(b);g.push(d),h.push(d)}e()})}var b=a.undef,c=a.GLCore,d=CubicVR.enums,f={PDF:e};return f}),CubicVR.RegisterModule("MainLoop",function(a){function f(){this.time_elapsed=0,this.system_milliseconds=0,this.start_time=0,this.end_time=0,this.last_update=0,this.paused_time=0,this.offset=0,this.paused_state=0}function g(){var b=e.gl;if(a.GLCore.mainloop===null)return;window.requestAnimationFrame&&window.requestAnimationFrame(g),a.GLCore.mainloop.interval()}function h(b){a.GLCore.mainloop=b}function i(c,d,h){window.requestAnimationFrame===b&&(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||null),a.GLCore.mainloop!==null&&(!window.requestAnimationFrame&&a.GLCore.mainloop&&clearInterval(a.GLCore.mainloop.interval),a.GLCore.mainloop=null);if(c===null){a.GLCore.mainloop=null;return}var i=this.renderList=[],j=this.renderStack=[{scenes:[],update:function(){},start:function(){},stop:function(){}}],k=new f;k.start(),this.timer=k,this.func=c,this.doclear=d!==b?d:!0,a.GLCore.mainloop=this,e.resizeList.length&&!a.GLCore.resize_active&&(window.addEventListener("resize",function(){a.GLCore.onResize()},!1),a.GLCore.resize_active=!0);var l=function(){return function(){var b=a.GLCore.gl;k.update(),a.GLCore.mainloop.doclear&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT),c(k,a.GLCore.gl);var d=j[j.length-1],e=d.scenes;d.update&&d.update(k,b);if(e)for(var f=0,g=e.length;f<g;++f){var h=e[f];if(h.paused)continue;h.update&&h.update(k,a.GLCore.gl),h.render()}}}();h?this.loopFunc=l:window.requestAnimationFrame?(this.interval=l,window.requestAnimationFrame(g)):this.interval=setInterval(l,20)}function j(a,c,e){this.canvas=a,this.camera=c,this.mpos=[0,0],this.mdown=!1;var f=this;this.mEvents={},this.keyState=[];for(var g in d.keyboard)this.keyState[g]=!1;this.onMouseDown=function(){return function(a){f.mdown=!0,f.mpos=[a.pageX-a.target.offsetLeft,a.pageY-a.target.offsetTop],f.mEvents.mouseDown&&f.mEvents.mouseDown(f,f.mpos,f.keyState)}}(),this.onMouseUp=function(){return function(a){f.mdown=!1,f.mpos=[a.pageX-a.target.offsetLeft,a.pageY-a.target.offsetTop],f.mEvents.mouseUp&&f.mEvents.mouseUp(f,f.mpos,f.keyState)}}(),this.onMouseMove=function(){return function(a){var b=[],c=[a.pageX-a.target.offsetLeft,a.pageY-a.target.offsetTop];b[0]=c[0]-f.mpos[0],b[1]=c[1]-f.mpos[1],f.mpos=c,f.mEvents.mouseMove&&f.mEvents.mouseMove(f,f.mpos,b,f.keyState)}}(),this.onMouseWheel=function(){return function(a){var b=a.wheelDelta?a.wheelDelta:-a.detail*100;f.mEvents.mouseWheel&&f.mEvents.mouseWheel(f,f.mpos,b,f.keyState)}}(),this.onKeyDown=function(){return function(a){var c=a.keyCode,d=null;f.mEvents.keyPress?(d=f.mEvents.keyPress(f,f.mpos,c,f.keyState),d!==b?f.keyState[c]=!!d:f.keyState[c]=!0):f.keyState[c]=!0;if(!f.keyState[c])return;f.mEvents.keyDown&&(d=f.mEvents.keyDown(f,f.mpos,c,f.keyState),d!==b?f.keyState[c]=!!d:f.keyState[c]=!0)}}(),this.onKeyUp=function(){return function(a){var b=a.keyCode;f.mEvents.keyUp&&f.mEvents.keyUp(f,f.mpos,b,f.keyState),f.keyState[b]=!1}}(),this.eventDefaults={mouseMove:function(a,b,c,d){if(!a.mdown)return;a.orbitView(c)},mouseWheel:function(a,b,c,d){a.zoomView(c)},mouseDown:null,mouseUp:null,keyDown:null,keyUp:null,keyPress:null},e!==!1&&this.setEvents(e===b?this.eventDefaults:e),this.bind()}var b=a.undef,c=function(){},d=a.enums,e=a.GLCore;d.keyboard={BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,CAPS_LOCK:20,ESCAPE:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT_ARROW:37,UP_ARROW:38,RIGHT_ARROW:39,DOWN_ARROW:40,INSERT:45,DELETE:46,KEY_0:48,KEY_1:49,KEY_2:50,KEY_3:51,KEY_4:52,KEY_5:53,KEY_6:54,KEY_7:55,KEY_8:56,KEY_9:57,KEY_A:65,KEY_B:66,KEY_C:67,KEY_D:68,KEY_E:69,KEY_F:70,KEY_G:71,KEY_H:72,KEY_I:73,KEY_J:74,KEY_K:75,KEY_L:76,KEY_M:77,KEY_N:78,KEY_O:79,KEY_P:80,KEY_Q:81,KEY_R:82,KEY_S:83,KEY_T:84,KEY_U:85,KEY_V:86,KEY_W:87,KEY_X:88,KEY_Y:89,KEY_Z:90,LEFT_META:91,RIGHT_META:92,SELECT:93,NUMPAD_0:96,NUMPAD_1:97,NUMPAD_2:98,NUMPAD_3:99,NUMPAD_4:100,NUMPAD_5:101,NUMPAD_6:102,NUMPAD_7:103,NUMPAD_8:104,NUMPAD_9:105,MULTIPLY:106,ADD:107,SUBTRACT:109,DECIMAL:110,DIVIDE: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,NUM_LOCK:144,SCROLL_LOCK:145,SEMICOLON:186,EQUALS:187,COMMA:188,DASH:189,PERIOD:190,FORWARD_SLASH:191,GRAVE_ACCENT:192,OPEN_BRACKET:219,BACK_SLASH:220,CLOSE_BRACKET:221,SINGLE_QUOTE:222},f.prototype={start:function(){this.update(),this.num_updates=0,this.start_time=this.system_milliseconds,this.last_update=this.start_time,this.paused_state=!1,this.lock_state=!1,this.lock_rate=0,this.paused_time=0,this.offset=0},stop:function(){this.end_time=this.system_milliseconds},reset:function(){this.start()},lockFramerate:function(a){this.lock_rate=1/a,this.lock_state=!0},unlock:function(){var a=this.system_milliseconds;this.lock_state=!1,this.update(),this.last_update=this.system_milliseconds-this.lock_rate,this.offset+=a-this.system_milliseconds,this.lock_rate=0},locked:function(){return this.lock_state},update:function(){this.num_updates++,this.last_update=this.system_milliseconds,this.lock_state?this.system_milliseconds+=this.lock_rate*1e3|0:this.system_milliseconds=Date.now(),this.paused_state&&(this.paused_time+=this.system_milliseconds-this.last_update),this.time_elapsed=this.system_milliseconds-this.start_time-this.paused_time+this.offset},getMilliseconds:function(){return this.time_elapsed},getSeconds:function(){return this.getMilliseconds()/1e3},setMilliseconds:function(a){this.offset-=this.system_milliseconds-this.start_time-this.paused_time+this.offset-a},setSeconds:function(a){this.setMilliseconds(a*1e3|0)},getLastUpdateSeconds:function(){return this.getLastUpdateMilliseconds()/1e3},getLastUpdateMilliseconds:function(){return this.system_milliseconds-this.last_update},getTotalMilliseconds:function(){return this.system_milliseconds-this.start_time},getTotalSeconds:function(){return this.getTotalMilliseconds()/1e3},getNumUpdates:function(){return this.num_updates},setPaused:function(a){this.paused_state=a},getPaused:function(){return this.paused_state}},i.prototype={setPaused:function(a){this.timer.setPaused(a)},getPaused:function(){return this.timer.getPaused()},setTimerSeconds:function(a){this.timer.setSeconds(a)},getTimerSeconds:function(){return this.timer.getSeconds()},resetTimer:function(){this.timer.reset()},addScene:function(a,b,c){var d=this.renderStack[this.renderStack.length-1];return d.scenes.push(a),a},pushSceneGroup:function(a){a.scenes=a.scenes||[],this.renderStack.push(a);for(var b=0;b<a.scenes.length;++b)a.scenes[b].enable();a.start&&a.start()},popSceneGroup:function(){var a=this.renderStack[this.renderStack.length-1];for(var b=0;b<a.scenes.length;++b)a.scenes[b].disable();this.renderStack.length>1&&this.renderStack.pop(),a.stop&&a.stop()},getScene:function(a){var b=renderStack[renderStack.length-1],c;for(var d=0,e=b.scenes.length;d<e;++d)if(b.scenes[d].scene.name===a){c=b.scenes[d];break}return c},resumeScene:function(a){typeof a=="string"&&(a=this.getScene(a)),a.enable(),a.paused=!1},pauseScene:function(a){typeof a=="string"&&(a=this.getScene(a)),a.paused=!0,a.disable()},removeScene:function(a){var b=renderStack[renderStack.length-1];typeof a=="string"&&(a=this.getScene(a));var c=b.scenes.indexOf(a);return c>-1&&b.scenes.splice(c,1),a},runOnce:function(){this.loopFunc()}},j.prototype={isKeyPressed:function(a){return this.keyState[a]},setEvents:function(a){this.mEvents={};for(var b in a)this.bindEvent(b,a[b])},orbitView:function(b){var c=a.vec3,d=c.subtract(this.camera.target,this.camera.position),e=c.length(d);this.camera.position=c.moveViewRelative(this.camera.position,this.camera.target,-e*b[0]/300,0),this.camera.position[1]+=e*b[1]/300,this.camera.position=c.add(this.camera.target,c.multiply(c.normalize(c.subtract(this.camera.position,this.camera.target)),e))},panView:function(b,c){var d=a.vec3;c||(c=!1);var e=d.subtract(this.camera.target,this.camera.position),f=d.length(e),g=this.camera.position;c?this.camera.position=d.moveViewRelative(this.camera.position,this.camera.target,-f*b[0]/300,-f*b[1]/300):(this.camera.position=d.moveViewRelative(this.camera.position,this.camera.target,-f*b[0]/300,0),this.camera.position[1]+=f*b[1]/300);var h=d.subtract(this.camera.position,g);this.camera.target=d.add(this.camera.target,h)},zoomView:function(b,c,d){var e=a.vec3,f=e.subtract(this.camera.target,this.camera.position),g=e.length(f);g-=b/1e3,c||(c=.1),d||(d=1e3),g<c&&(g=c),g>d&&(g=d),this.camera.position=e.add(this.camera.target,e.multiply(e.normalize(e.subtract(this.camera.position,this.camera.target)),g))},bindEvent:function(a,c){c===b?this.mEvents[a]=this.eventDefaults[a]:this.mEvents[a]=c},unbindEvent:function(a){this.bindEvent(a,null)},bind:function(){this.canvas.addEventListener("mousemove",this.onMouseMove,!1),this.canvas.addEventListener("mousedown",this.onMouseDown,!1),this.canvas.addEventListener("mouseup",this.onMouseUp,!1),this.canvas.addEventListener("mousewheel",this.onMouseWheel,!1),this.canvas.addEventListener("DOMMouseScroll",this.onMouseWheel,!1),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keyup",this.onKeyUp,!1)},unbind:function(){this.canvas.removeEventListener("mousemove",this.onMouseMove,!1),this.canvas.removeEventListener("mousedown",this.onMouseDown,!1),this.canvas.removeEventListener("mouseup",this.onMouseUp,!1),this.canvas.removeEventListener("mousewheel",this.onMouseWheel,!1),this.canvas.removeEventListener("DOMMouseScroll",this.onMouseWheel,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keyup",this.onKeyUp,!1)},setCamera:function(a){this.camera=a},getMousePosition:function(){return this.mpos}};var k={Timer:f,MainLoop:i,MouseViewController:j,setMainLoop:h,keyboard:d.keyboard};return k}),CubicVR.RegisterModule("Texture",function(a){function f(a,b){if(a===1||b===1)return!1;if(a!==1)while(a%2===0)a/=2;if(b!==1)while(b%2===0)b/=2;return a>1?!1:b>1?!1:!0}function i(b){var d=a.GLCore.gl;if(b.nodeName==="CANVAS"||b.nodeName==="IMG"||b.nodeName==="VIDEO")this.canvasSource=b;else{this.canvasSource=document.createElement("CANVAS");if(b.width===undefined||b.height===undefined)throw new Error("Width and height must be specified for generating a new CanvasTexture.");this.canvasSource.width=b.width,this.canvasSource.height=b.height,this.canvasContext=this.canvasSource.getContext("2d")}this.updateFunction=b.update,this.texture=new a.Texture,this.setFilter=this.texture.setFilter,this.clear=this.texture.clear,this.use=this.texture.use,this.tex_id=this.texture.tex_id,this.filterType=this.texture.filterType;var g=this.canvasSource;(!g.height||!g.width)&&e("Warning - CanvasTexture input has no initial width and height, edges clamped."),!g.height||!g.width||!f(g.width,g.height)?(this.setFilter(c.texture.filter.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE)):(this.setFilter(c.texture.filter.LINEAR_MIP),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.REPEAT),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,d.REPEAT)),b.nodeName==="IMG"&&this.update()}function j(b,d){if(!b)throw"PDF Texture Error: page is null.";var e=this,g=a.GLCore.gl,h=this.canvasSource=document.createElement("canvas"),i;h.mozOpaque=!0,h.width=d.width,h.height=d.height,i=this.canvasContext=h.getContext("2d"),i.save(),i.fillStyle="rgb(255, 255, 255)",i.fillRect(0,0,h.width,h.height),i.restore(),b.startRendering(i,function(){e.update()}),this.texture=new a.Texture,this.updateFunction=d.update||function(){},this.setFilter=this.texture.setFilter,this.clear=this.texture.clear,this.use=this.texture.use,this.tex_id=this.texture.tex_id,this.filterType=this.texture.filterType,f(h.width,h.height)?(this.setFilter(c.texture.filter.LINEAR_MIP),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.REPEAT),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.REPEAT)):(this.setFilter(c.texture.filter.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE))}function k(a,b){var c=b&&b.color||"#fff",e=b&&b.bgcolor,f=b&&b.font||"18pt Arial",g=b&&b.align||"start",h=b&&b.y||0,j=b&&b.width||d,k=b&&b.height||d,l,m=document.createElement("CANVAS"),n=m.getContext("2d"),o,p=0;typeof a=="string"?p=1:p=a.length,n.font=f;var q=b&&b.lineHeight||n.measureText("OO").width,r;if(p===1)r=n.measureText(a).width;else{r=0;for(l=0;l<p;++l){var s=n.measureText(a[l]).width;s>r&&(r=s)}}m.width=j||r,m.height=k||q*p,e&&(n.fillStyle=e,n.fillRect(0,0,m.width,m.height)),n.fillStyle=c,n.font=f,n.textAlign=g,n.textBaseline="top";if(p===1)o=b&&b.x||g==="center"?m.width/2:g==="right"?m.width:0,n.fillText(a,o,h);else for(l=0;l<p;++l)o=b&&b.x||g==="center"?m.width/2:g==="right"?m.width:0,n.fillText(a[l],o,h+l*q);n.fill(),this.use=i.prototype.use,this.clear=i.prototype.clear,this.update=i.prototype.update,i.apply(this,[m]),this.update(),this.canvasSource=m=n=null}function l(b,d,e){var g=a.util,h=a.GLCore.gl;this.texture=new a.Texture,this.canvas=document.createElement("CANVAS"),this.canvas.width=d,this.canvas.height=e,this.pjs=new Processing(this.canvas,a.util.getURL(b)),this.pjs.noLoop(),this.pjs.redraw(),this.setFilter=this.texture.setFilter,this.clear=this.texture.clear,this.use=this.texture.use,this.tex_id=this.texture.tex_id,this.filterType=this.texture.filterType,f(this.canvas.width,this.canvas.height)?this.setFilter(c.texture.filter.LINEAR_MIP):(this.setFilter(c.texture.filter.LINEAR),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE))}function m(d,e,g){var h=b.gl;this.width=e,this.height=g,this.srcTex=d,this.outTex=new a.RenderBuffer(e,g);var i=f(e,g),j=[1/e,1/g,0];this.outputBuffer=new a.RenderBuffer(e,g,!1),this.fsQuad=a.fsQuad.make(e,g);var k=["attribute vec3 aVertex;","attribute vec2 aTex;","varying vec2 vTex;","void main(void)","{"," vTex = aTex;"," vec4 vPos = vec4(aVertex.xyz,1.0);"," gl_Position = vPos;","}"].join("\n");shaderNMap=new a.Shader(k,["#ifdef GL_ES","precision highp float;","#endif","uniform sampler2D srcTex;","varying vec2 vTex;","uniform vec3 texel;","void main(void)","{"," vec3 color;"," color.r = (texture2D(srcTex,vTex + vec2(texel.x,0)).r-texture2D(srcTex,vTex + vec2(-texel.x,0)).r)/2.0 + 0.5;"," color.g = (texture2D(srcTex,vTex + vec2(0,-texel.y)).r-texture2D(srcTex,vTex + vec2(0,texel.y)).r)/2.0 + 0.5;"," color.b = 1.0;"," gl_FragColor.rgb = color;"," gl_FragColor.a = 1.0;","}"].join("\n")),shaderNMap.use(),shaderNMap.addUVArray("aTex"),shaderNMap.addVertexArray("aVertex"),shaderNMap.addInt("srcTex",0),shaderNMap.addVector("texel"),shaderNMap.setVector("texel",j),this.shaderNorm=shaderNMap,this.setFilter=this.outputBuffer.texture.setFilter,this.clear=this.outputBuffer.texture.clear,this.use=this.outputBuffer.texture.use,this.tex_id=this.outputBuffer.texture.tex_id,this.filterType=this.outputBuffer.texture.filterType,this.outTex.use(h.TEXTURE0),this.setFilter(c.texture.filter.LINEAR),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.REPEAT),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.REPEAT)}function n(d,e,g){var h=b.gl;this.width=d,this.height=e,this.outTex=new a.RenderBuffer(d,e,g),this.texture=this.outTex.texture;var i=f(d,e);this.setFilter=this.outTex.texture.setFilter,this.clear=this.outTex.texture.clear,this.use=this.outTex.texture.use,this.tex_id=this.outTex.texture.tex_id,this.filterType=this.outTex.texture.filterType,this.texture.use(h.TEXTURE0),i?(this.setFilter(c.texture.filter.LINEAR),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.REPEAT),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.REPEAT)):(this.setFilter(c.texture.filter.LINEAR),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE)),this.dims=[d,e],this.depth=g?!0:!1}function o(a,b){this.scene=a,this.renderTex=new n(b?b.width:a.camera.width,b?b.height:a.camera.height,!0),this.setFilter=this.renderTex.texture.setFilter,this.clear=this.renderTex.texture.clear,this.use=this.renderTex.texture.use,this.tex_id=this.renderTex.texture.tex_id,this.filterType=this.renderTex.texture.filterType}var b=a.GLCore,c=a.enums,d=a.undef,e=a.log;c.texture={map:{COLOR:0,ENVSPHERE:1,NORMAL:2,BUMP:3,REFLECT:4,SPECULAR:5,AMBIENT:6,ALPHA:7,MAX:8},filter:{LINEAR:0,LINEAR_MIP:1,NEAREST:2,NEAREST_MIP:3}};var g=function(a,b){this.img_path=a,this.filter_type=b};g.prototype={getTexture:function(a,b){return new h(this.img_path,this.filter_type,a,b)}};var h=function(e,g,h,i,j){var k=b.gl;this.tex_id=a.Textures.length,this.filterType=-1,this.onready=j,this.loaded=!1,a.Textures[this.tex_id]=k.createTexture(),a.Textures_obj[this.tex_id]=this,e&&(typeof e=="string"?a.Images[this.tex_id]=new Image:typeof e=="object"&&e.nodeName==="IMG"&&(a.Images[this.tex_id]=e),a.Textures_ref[e]=this.tex_id),k.bindTexture(k.TEXTURE_2D,a.Textures[this.tex_id]),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_MAG_FILTER,k.LINEAR),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_MIN_FILTER,k.LINEAR);if(e){var l=this.tex_id,m=g!==d?g:b.default_filter,n=this;a.Images[this.tex_id].onload=function(b){k.bindTexture(k.TEXTURE_2D,a.Textures[l]),k.pixelStorei(k.UNPACK_FLIP_Y_WEBGL,!0),k.pixelStorei(k.UNPACK_COLORSPACE_CONVERSION_WEBGL,k.NONE);var d=a.Images[l];k.texImage2D(k.TEXTURE_2D,0,k.RGBA,k.RGBA,k.UNSIGNED_BYTE,d);var e=f(d.width,d.height);e?(k.texParameteri(k.TEXTURE_2D,k.TEXTURE_WRAP_S,k.REPEAT),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_WRAP_T,k.REPEAT)):(k.texParameteri(k.TEXTURE_2D,k.TEXTURE_WRAP_S,k.CLAMP_TO_EDGE),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_WRAP_T,k.CLAMP_TO_EDGE)),a.Textures_obj[l].filterType===-1?(e?m=c.texture.filter.LINEAR_MIP:m===c.texture.filter.LINEAR_MIP&&(m=c.texture.filter.LINEAR),a.Textures_obj[l].filterType===-1&&a.Textures_obj[l].setFilter(m)):a.Textures_obj[l].setFilter(a.Textures_obj[l].filterType),n.onready&&n.onready(),k.bindTexture(k.TEXTURE_2D,null),n.loaded=!0},h?(a.Images[this.tex_id].deferredSrc=e,h.addImage(i,e,a.Images[this.tex_id])):typeof e=="string"&&(a.Images[this.tex_id].src=e)}this.active_unit=-1};h.prototype={setFilter:function(b){if(this.tex_id>-1){var d=a.GLCore.gl;d.bindTexture(d.TEXTURE_2D,a.Textures[this.tex_id]),b===c.texture.filter.LINEAR?(d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.LINEAR)):b===c.texture.filter.LINEAR_MIP?(d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.LINEAR_MIPMAP_NEAREST),d.generateMipmap(d.TEXTURE_2D)):b===c.texture.filter.NEAREST?(d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.NEAREST),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.NEAREST)):b===c.texture.filter.NEAREST_MIP&&(d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.NEAREST),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.NEAREST_MIPMAP_LINEAR),d.generateMipmap(d.TEXTURE_2D)),this.filterType=b}},use:function(c){this.tex_id>-1&&(b.gl.activeTexture(c),b.gl.bindTexture(b.gl.TEXTURE_2D,a.Textures[this.tex_id]),this.active_unit=c)},clear:function(){this.tex_id>-1&&this.active_unit!==-1&&(b.gl.activeTexture(this.active_unit),b.gl.bindTexture(b.gl.TEXTURE_2D,null),this.active_unit=-1)},destroy:function(){var b=a.GLCore.gl;this.tex_id>-1&&a.Textures[this.tex_id]&&(b.deleteTexture(a.Textures[this.tex_id]),delete a.Textures_obj[this.tex_id],this.tex_id=-1)}},i.prototype={update:function(){this.updateFunction&&this.updateFunction(this.canvasSource,this.canvasContext);var b=a.GLCore.gl;b.bindTexture(b.TEXTURE_2D,a.Textures[this.texture.tex_id]),b.pixelStorei(b.UNPACK_FLIP_Y_WEBGL,!0),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,this.canvasSource),this.filterType===c.texture.filter.LINEAR_MIP&&b.generateMipmap(b.TEXTURE_2D),b.bindTexture(b.TEXTURE_2D,null)}},j.prototype={update:function(){this.updateFunction(this.canvasSource,this.canvasContext);var b=a.GLCore.gl;b.bindTexture(b.TEXTURE_2D,a.Textures[this.texture.tex_id]),b.pixelStorei(b.UNPACK_FLIP_Y_WEBGL,!0),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,this.canvasSource),this.filterType===c.texture.filter.LINEAR_MIP&&b.generateMipmap(b.TEXTURE_2D),b.bindTexture(b.TEXTURE_2D,null)}},l.prototype={update:function(){var b=a.GLCore.gl;this.pjs.redraw(),b.bindTexture(b.TEXTURE_2D,a.Textures[this.texture.tex_id]),b.pixelStorei(b.UNPACK_FLIP_Y_WEBGL,!0),b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,this.canvas),this.filterType===c.texture.filter.LINEAR_MIP&&b.generateMipmap(b.TEXTURE_2D),b.bindTexture(b.TEXTURE_2D,null)}},m.prototype={update:function(){var c=b.gl,d=c.getParameter(c.VIEWPORT);this.outputBuffer.use(),c.viewport(0,0,this.width,this.height),c.clearColor(0,0,0,1),c.clear(c.COLOR_BUFFER_BIT),this.srcTex.use(c.TEXTURE0),a.fsQuad.render(this.shaderNorm,this.fsQuad),c.bindFramebuffer(c.FRAMEBUFFER,null),c.viewport(d[0],d[1],d[2],d[3])}},n.prototype={begin:function(){var a=b.gl;this.dims=a.getParameter(a.VIEWPORT),this.outTex.use(),a.viewport(0,0,this.width,this.height),this.depth?a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT):a.clear(a.COLOR_BUFFER_BIT)},end:function(){var a=b.gl;a.bindFramebuffer(a.FRAMEBUFFER,null),a.viewport(this.dims[0],this.dims[1],this.dims[2],this.dims[3])}},o.prototype={update:function(){this.renderTex.begin(),this.scene.updateShadows(),this.scene.render(),this.renderTex.end()}};var p={Texture:h,DeferredLoadTexture:g,CanvasTexture:i,PdfTexture:j,TextTexture:k,PJSTexture:l,NormalMapGen:m,RenderTexture:n,SceneRenderTexture:o};return p}),CubicVR.RegisterModule("Material",function(a){function g(c){this.initialized=!1,this.dirtyFlag=!1,this.blendEnabled=!1,this.textures=[],this.shader=[],c=a.get(c)||{},this.customShader=c?c.shader||null:null,f===null&&(f=new a.CustomShader({vertex:["precision lowp float; \nattribute vec3 vertexPosition; uniform mat4 matrixModelView; uniform mat4 matrixProjection; uniform mat4 matrixObject;","void main(void) { gl_Position = matrixProjection * matrixModelView * matrixObject * vec4(vertexPosition,1.0); }"].join("\n"),fragment:"precision lowp float; \nvoid main(void) { gl_FragColor = vec4(1.0,0.0,1.0,1.0); }\n"}),f._init_shader(f._vertex,f._fragment,!1)),this.customShader&&!this.customShader._init_shader&&typeof this.customShader=="object"&&(this.customShader=new a.CustomShader(this.customShader)),this.diffuse=c.diffuse||[1,1,1],this.specular=c.specular||[.1,.1,.1],this.color=c.color||[1,1,1],this.ambient=c.ambient||[0,0,0],this.name=c.name||null,this.visible=c.visible!==b?c.visible:!0,this.friction=c.friction!==b?c.friction:.3,this.collision=c.visible!==b?c.collision:!0,this.opacity=c.opacity===b?1:c.opacity,this.shininess=c.shininess===b?1:c.shininess,this.max_smooth=c.max_smooth===b?60:c.max_smooth,this.env_amount=c.env_amount===b?.75:c.env_amount,this.morph=c.morph===b?!1:c.morph,this.color_map=c.colorMap===b?!1:c.colorMap,this.uvOffset=c.uvOffset===b?[0,0]:c.uvOffset;if(c.textures)for(var d in c.textures)this.setTexture(c.textures[d],d)}var b=a.undef,c=a.GLCore,d=a.enums,e=a.util,f=null,h=[d.texture.map.REFLECT,d.texture.map.SPECULAR,d.texture.map.NORMAL,d.texture.map.BUMP],i=[],j=["textureColor","textureEnvSphere","textureNormal","textureBump","textureReflect","textureSpecular","textureAmbient","textureAlpha","matrixModelView","matrixProjection","matrixObject","matrixNormal","vertexPosition","vertexNormal","vertexColor","vertexTexCoord","materialTexOffset","vertexMorphPosition","vertexMorphNormal","materialMorphWeight","lightDiffuse","lightSpecular","lightIntensity","lightDistance","lightPosition","lightDirection","lightCutOffAngle","lightShadowMap","lightProjectionMap","lightDepthClip","lightShadowMatrix","lightAmbient","materialDiffuse","materialColor","materialAmbient","materialSpecular","materialShininess","materialEnvironment","materialAlpha","postDepthInfo"];g.prototype={clone:function(){var b=new a.Material({diffuse:this.diffuse,specular:this.specular,color:this.color,ambient:this.ambient,opacity:this.opacity,shininess:this.shininess,max_smooth:this.max_smooth,env_amount:this.env_amount,morph:this.morph,colorMap:this.color_map,visible:this.visible,friction:this.friction,collision:this.collision,name:this.name});for(var c in this.textures){if(!this.textures.hasOwnProperty(c))continue;b.setTexture(this.textures[c],c)}return b},setVisibility:function(a){this.visible=a},getVisibility:function(){return this.visible},setCollision:function(a){this.collision=a},getCollision:function(){return this.collision},setFriction:function(a){this.friction=a},getFriction:function(){return this.friction},setTexture:function(c,e){if(!c)return;e=a.parseEnum(d.texture.map,e)||0;if(!a.features.texturePerPixel&&h.indexOf(e)!==-1)return;!c.use&&typeof c=="string"&&(c=a.Textures_ref[c]!==b?a.Textures_obj[a.Textures_ref[c]]:new a.Texture(c)),this.textures[e]=c},calcShaderMask:function(){var a=0;return a+=typeof this.textures[d.texture.map.COLOR]=="object"?d.shader.map.COLOR:0,a+=typeof this.textures[d.texture.map.SPECULAR]=="object"?d.shader.map.SPECULAR:0,a+=typeof this.textures[d.texture.map.NORMAL]=="object"?d.shader.map.NORMAL:0,a+=typeof this.textures[d.texture.map.BUMP]=="object"?d.shader.map.BUMP:0,a+=typeof this.textures[d.texture.map.REFLECT]=="object"?d.shader.map.REFLECT:0,a+=typeof this.textures[d.texture.map.ENVSPHERE]=="object"?d.shader.map.ENVSPHERE:0,a+=typeof this.textures[d.texture.map.AMBIENT]=="object"?d.shader.map.AMBIENT:0,a+=typeof this.textures[d.texture.map.ALPHA]=="object"?d.shader.map.ALPHA:0,a+=this.opacity!==1?d.shader.map.ALPHA:0,a+=this.color_map?d.shader.map.COLORMAP:0,this.opacity!==1&&(this.blendEnabled=!0),a},getShaderHeader:function(e,f){return(f!==b?"#define LIGHT_COUNT "+f+"\n":"")+"#define TEXTURE_COLOR "+(typeof this.textures[d.texture.map.COLOR]=="object"?1:0)+"\n#define TEXTURE_SPECULAR "+(typeof this.textures[d.texture.map.SPECULAR]=="object"?1:0)+"\n#define TEXTURE_NORMAL "+(typeof this.textures[d.texture.map.NORMAL]=="object"?1:0)+"\n#define TEXTURE_BUMP "+(typeof this.textures[d.texture.map.BUMP]=="object"?1:0)+"\n#define TEXTURE_REFLECT "+(typeof this.textures[d.texture.map.REFLECT]=="object"?1:0)+"\n#define TEXTURE_ENVSPHERE "+(typeof this.textures[d.texture.map.ENVSPHERE]=="object"?1:0)+"\n#define TEXTURE_AMBIENT "+(typeof this.textures[d.texture.map.AMBIENT]=="object"?1:0)+"\n#define TEXTURE_ALPHA "+(typeof this.textures[d.texture.map.ALPHA]=="object"?1:0)+"\n#define MATERIAL_ALPHA "+(this.opacity!==1?1:0)+"\n#define LIGHT_IS_POINT "+(e===d.light.type.POINT?1:0)+"\n#define LIGHT_IS_DIRECTIONAL "+(e===d.light.type.DIRECTIONAL?1:0)+"\n#define LIGHT_IS_SPOT "+(e===d.light.type.SPOT||e===d.light.type.SPOT_SHADOW||e===d.light.type.SPOT_SHADOW_PROJECTOR?1:0)+"\n#define LIGHT_SHADOWED "+(e===d.light.type.SPOT_SHADOW||e===d.light.type.SPOT_SHADOW_PROJECTOR||e===d.light.type.AREA?1:0)+"\n#define LIGHT_IS_PROJECTOR "+(e===d.light.type.SPOT_SHADOW_PROJECTOR?1:0)+"\n#define LIGHT_SHADOWED_SOFT "+(c.soft_shadow?1:0)+"\n#define LIGHT_IS_AREA "+(e===d.light.type.AREA?1:0)+"\n#define LIGHT_DEPTH_PASS "+(e===d.light.type.DEPTH_PACK?1:0)+"\n#define FX_DEPTH_ALPHA "+(c.depth_alpha?1:0)+"\n#define VERTEX_MORPH "+(this.morph?1:0)+"\n#define VERTEX_COLOR "+(this.color_map?1:0)+"\n#define LIGHT_PERPIXEL "+(a.features.lightPerPixel?1:0)+"\n\n"},bindObject:function(a,b){var d=c.gl,e=b,f=e.vertexPosition,g=e.vertexTexCoord,h=e.vertexNormal,j=e.vertexColor;d.bindBuffer(d.ARRAY_BUFFER,a.compiled.gl_points),d.vertexAttribPointer(f,3,d.FLOAT,!1,0,0),d.enableVertexAttribArray(f),g!==null&&a.compiled.gl_uvs!==null&&g!==-1&&(d.bindBuffer(d.ARRAY_BUFFER,a.compiled.gl_uvs),d.vertexAttribPointer(g,2,d.FLOAT,!1,0,0),d.enableVertexAttribArray(g)),i.uv=g,h!==null&&a.compiled.gl_normals!==null&&h!==-1&&(d.bindBuffer(d.ARRAY_BUFFER,a.compiled.gl_normals),d.vertexAttribPointer(h,3,d.FLOAT,!1,0,0),d.enableVertexAttribArray(h)),i.un=h,j!==null&&a.compiled.gl_colors!==null&&j!==-1&&(d.bindBuffer(d.ARRAY_BUFFER,a.compiled.gl_colors),d.vertexAttribPointer(j,3,d.FLOAT,!1,0,0),d.enableVertexAttribArray(j)),i.uc=j,a.morphTarget&&(f=e.vertexMorphPosition,h=e.vertexMorphNormal,d.bindBuffer(d.ARRAY_BUFFER,a.morphTarget.gl_points),d.vertexAttribPointer(f,3,d.FLOAT,!1,0,0),d.enableVertexAttribArray(f),h!==null&&a.morphTarget.gl_normals!==null&&h!==-1&&(d.bindBuffer(d.ARRAY_BUFFER,a.morphTarget.gl_normals),d.vertexAttribPointer(h,3,d.FLOAT,!1,0,0),d.enableVertexAttribArray(h)),d.uniform1f(e.materialMorphWeight,a.morphWeight)),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,a.compiled.gl_elements)},clearObject:function(a,d){var e=c.gl;i.uv!==b&&i.uv!==-1&&e.disableVertexAttribArray(i.uv),i.un!==b&&i.un!==-1&&e.disableVertexAttribArray(i.un),i.uc!==b&&i.uc!==-1&&e.disableVertexAttribArray(i.uc);var f=d;a.morphTarget&&f&&(up=f.vertexMorphPosition
,e.disableVertexAttribArray(up),un=f.vertexMorphNormal,un!==null&&a.compiled.gl_normals!==null&&un!==-1&&e.disableVertexAttribArray(un))},use:function(b,e){var g,h=c.gl,i=this.textures,k=!0;e=e||0,b=b||0,this.shader[b]||(this.shader[b]=[]);var l=this.shader[b][e],m=this.customShader&&b===d.light.type.DEPTH_PACK&&!this.customShader.hasDepthPack();l&&this.opacity!==1&&this.blendEnabled!==!0&&(this.dirtyFlag=!0),this.dirtyFlag===!0&&(l=null,this.dirtyFlag=!1);if(!l){var n=this.calcShaderMask(b);if(!this.customShader||m)a.ShaderPool[b][n]||(a.ShaderPool[b][n]=[]),l=a.ShaderPool[b][n][e];if(!l){var o=this.getShaderHeader(b,e),p=o+c.CoreShader_vs,q=o+c.CoreShader_fs;this.customShader&&!m?this.customShader._initialized||(this.customShader._init_shader(p,q,j),l=this.customShader.getShader(),l.isCompiled()||(k=!1,l=f.getShader())):(l=new a.Shader(p,q),l.isCompiled()||(k=!1,l=f.getShader()),a.ShaderPool[b][n][e]=l),g=0;if(b!==d.light.type.DEPTH_PACK){if(b===d.light.type.SPOT_SHADOW||b===d.light.type.SPOT_SHADOW_PROJECTOR||b===d.light.type.AREA)g+=e,b===d.light.type.SPOT_SHADOW_PROJECTOR&&(g+=e);typeof i[d.texture.map.COLOR]=="object"&&l.addInt("textureColor",g++),typeof i[d.texture.map.ENVSPHERE]=="object"&&l.addInt("textureEnvSphere",g++),typeof i[d.texture.map.NORMAL]=="object"&&l.addInt("textureNormal",g++),typeof i[d.texture.map.BUMP]=="object"&&l.addInt("textureBump",g++),typeof i[d.texture.map.REFLECT]=="object"&&l.addInt("textureReflect",g++),typeof i[d.texture.map.SPECULAR]=="object"&&l.addInt("textureSpecular",g++),typeof i[d.texture.map.AMBIENT]=="object"&&l.addInt("textureAmbient",g++)}typeof i[d.texture.map.ALPHA]=="object"&&l.addInt("textureAlpha",g++),l.addMatrix("matrixModelView"),l.addMatrix("matrixProjection"),l.addMatrix("matrixObject"),l.addMatrix("matrixNormal"),l.addVertexArray("vertexPosition"),l.addVertexArray("vertexNormal"),this.color_map&&l.addVertexArray("vertexColor"),this.morph&&(l.addVertexArray("vertexMorphPosition"),l.addVertexArray("vertexMorphNormal"),l.addFloat("materialMorphWeight",0));for(var r=0;r<e;r++){l.addVector("lightDiffuse["+r+"]"),l.addVector("lightSpecular["+r+"]"),l.addFloat("lightIntensity["+r+"]"),l.addFloat("lightDistance["+r+"]"),l.addVector("lightPosition["+r+"]"),l.addVector("lightDirection["+r+"]"),(b===d.light.type.SPOT_SHADOW||b===d.light.type.SPOT_SHADOW_PROJECTOR||b===d.light.type.SPOT)&&l.addFloat("lightCutOffAngle["+r+"]");if(b===d.light.type.SPOT_SHADOW||b===d.light.type.SPOT_SHADOW_PROJECTOR||b===d.light.type.AREA)l.addInt("lightShadowMap["+r+"]"),b===d.light.type.SPOT_SHADOW_PROJECTOR&&l.addInt("lightProjectionMap["+r+"]"),l.addVector("lightDepthClip["+r+"]"),l.addMatrix("lightShadowMatrix["+r+"]")}b!==d.light.type.DEPTH_PACK&&(l.addVector("lightAmbient"),l.addVector("materialDiffuse"),l.addVector("materialColor"),l.addVector("materialAmbient"),l.addVector("materialSpecular"),l.addFloat("materialShininess"),l.addFloat("materialEnvironment")),l.addFloat("materialAlpha"),(c.depth_alpha||b===d.light.type.DEPTH_PACK||b===d.light.type.SPOT_SHADOW||b===d.light.type.SPOT_SHADOW_PROJECTOR||b===d.light.type.AREA)&&l.addVector("postDepthInfo"),l.addUVArray("vertexTexCoord"),l.addVector("materialTexOffset")}this.shader[b][e]=l,l.use(),l.materialTexOffset!=-1&&h.uniform2fv(l.materialTexOffset,[0,0]),this.customShader&&this.customShader._doUpdate()}else k=l!==f,l.use(),this.customShader&&!m&&this.customShader._doUpdate();g=0;var s;if(b!==d.light.type.DEPTH_PACK){if(b===d.light.type.SPOT_SHADOW||b===d.light.type.SPOT_SHADOW_PROJECTOR||b===d.light.type.AREA)g+=e,b===d.light.type.SPOT_SHADOW_PROJECTOR&&(g+=e);!(s=i[d.texture.map.COLOR])||(s.use(c.gl.TEXTURE0+g),g++),!(s=i[d.texture.map.ENVSPHERE])||(s.use(c.gl.TEXTURE0+g),g++,h.uniform1f(l.materialEnvironment,this.env_amount)),!(s=i[d.texture.map.NORMAL])||(s.use(c.gl.TEXTURE0+g),g++),!(s=i[d.texture.map.BUMP])||(s.use(c.gl.TEXTURE0+g),g++),!(s=i[d.texture.map.REFLECT])||(s.use(c.gl.TEXTURE0+g),g++),!(s=i[d.texture.map.SPECULAR])||(s.use(c.gl.TEXTURE0+g),g++),!(s=i[d.texture.map.AMBIENT])||(s.use(c.gl.TEXTURE0+g),g++)}return!(s=i[d.texture.map.ALPHA])||(s.use(c.gl.TEXTURE0+g),g++),b!==d.light.type.DEPTH_PACK?(h.uniform3fv(l.materialColor,this.color),h.uniform3fv(l.materialDiffuse,this.diffuse),h.uniform3fv(l.materialAmbient,this.ambient),h.uniform3fv(l.materialSpecular,this.specular),h.uniform1f(l.materialShininess,this.shininess*128),h.uniform3fv(l.lightAmbient,a.globalAmbient),this.opacity!==1&&h.uniform1f(l.materialAlpha,this.opacity),(c.depth_alpha||b===d.light.type.SPOT_SHADOW||b===d.light.type.SPOT_SHADOW_PROJECTOR||b===d.light.type.AREA)&&h.uniform3fv(l.postDepthInfo,[c.depth_alpha_near,c.depth_alpha_far,0])):h.uniform3fv(l.postDepthInfo,[c.shadow_near,c.shadow_far,0]),l.materialTexOffset&&h.uniform2fv(l.materialTexOffset,this.uvOffset),k}};var k={Material:g};return k}),CubicVR.RegisterModule("Mesh",function(a){function e(c){if(c===b)return b;if(typeof c=="array")return c;if(typeof c=="object")return c.getResult?c.getResult():!c.position&&!c.rotation&&!c.scale?b:a.mat4.transform(c.position,c.rotation,c.scale)}function f(){this.points=[],this.point_normals=[],this.point_colors=[],this.uvs=[],this.normal=[0,0,0],this.material=0,this.segment=0}function g(b){this.compiled=null,this.materials=[],this.bb=null,this.instanceMaterials=null,this.edges=null,this.faces=[],this.points=[],this.currentFace=-1,this.currentMaterial=0,this.currentSegment=0,this.morphTargets=null,this.morphTarget=null,this.morphWeight=0,this.morphSourceIndex=-1,this.morphTargetIndex=-1,this.originBuffer=null,b=a.get(b)||{};if(b instanceof a.Mesh){this.booleanAdd(b),b._clones=b._clones||1,b._clones++,b.name?this.name=b.name+"_copy"+b._clones:this.name=null;return}this.name=b.name||null,this.dynamic=b.dynamic||!1;if(b.material){var c=b.material;c.length?this.materials=c:typeof c=="object"&&(c.use?this.setFaceMaterial(c):this.setFaceMaterial(new a.Material(c)))}b.points&&this.build(b),b.part?this.build(b.part):b.parts&&this.build(b.parts),this.primitives=b.primitives||b.primitive||null;if(this.primitives&&!this.primitives.length||typeof this.primitives=="string")this.primitives=[this.primitives];if(this.primitives&&this.primitives.length)for(var e=0,f=this.primitives.length;e<f;e++){var g=this.primitives[e];typeof g=="string"&&(g=a.get(g));var h=a.primitives[g.type];if(g.type&&!!h)this.booleanAdd(h(g));else if(g.type){d("Mesh error, primitive "+g.type+" is unknown.");var i="";for(var j in a.primitives)a.primitives.hasOwnProperty(j)&&(i!==""&&(i+=", "),i+=j);d("Available primitive types are: "+i)}else d("Mesh error, primitive "+(e+1)+" lacks type.")}this.buildWireframe=b.buildWireframe||b.wireframe||!!b.wireframeMaterial||b.triangulateWireframe||!1,this.triangulateWireframe=b.triangulateWireframe||null,this.wireframeMaterial=a.get(b.wireframeMaterial,a.Material)||null,this.wireframe=b.wireframe||!1,b.flipFaces&&this.faces.length&&this.flipFaces(),(b.prepare||b.compile&&this.faces.length)&&this.prepare(),(b.clean||b.compile&&this.faces.length&&!this.dynamic)&&this.clean(),b.calcNormals&&!b.compile&&!b.prepare&&this.calcNormals()}var b=a.undef,c=a.GLCore,d=a.log;f.prototype={setUV:function(a,c){c!==b?this.uvs[c]=a:a.length!==2?this.uvs=a:this.uvs.push(a)},setColor:function(a,c){c!==b?this.point_colors[c]=a:typeof a[0]!="number"?this.point_colors=a:this.point_colors.push(a)},flip:function(){for(var a=0,b=this.point_normals.length;a<b;a++)this.point_normals[a]=[-this.point_normals[a][0],-this.point_normals[a][1],-this.point_normals[a][2]];this.points.reverse(),this.point_normals.reverse(),this.uvs.reverse(),this.normal=[-this.normal[0],-this.normal[1],-this.normal[2]]}},g.prototype={setWireframe:function(a){this.wireframe=a},isWireframe:function(){return this.wireframe},setWireframeMaterial:function(a){this.wireframeMaterial=a},build:function(b,c){var e,f;typeof b=="string"&&(b=a.get(b)),b&&!b.length&&(b=[b]);var g=0,h=0,i=this.faces.length;c&&c.length&&(g=this.points.length,this.points.concat(c));for(var j=0,k=b.length;j<k;j++){var l=b[j],m=l.material,n=l.points,o=l.faces,p=l.uv,q=l.color,r=l.segment||null;r!==null&&this.setSegment(parseInt(r,10));if(n&&n.length){h=this.points.length,this.points=this.points.concat(n);if(o&&i){o=o.slice(0);for(var s=0,t=o.length;s<t;s++){var u=o[s];for(var v=0,w=o.length;v<w;v++)u[v]+=i}}}else h=g;m&&(m.length?this.materials=m:typeof m=="object"&&(m.use?this.setFaceMaterial(m):this.setFaceMaterial(new a.Material(m)))),o&&o.length&&this.addFace(o);if(o&&p&&typeof p=="object"){var x=null;if(p.length&&p.length===o.length)if(p.length===o.length)for(e=0,f=p.length;e<f;e++)this.faces[e+i].setUV(p[e]);else d("Mesh error in part, face count: "+o.length+", uv count:"+p.length);else x=p.apply?p:new a.UVMapper(p);x&&x.apply(this,this.currentMaterial,this.currentSegment,i,this.faces.length-i)}if(o&&q&&typeof q=="object")if(q.length&&q.length===o.length){for(e=0,f=q.length;e<f;e++)this.faces[e+i].setColor(q[e]);this.materials[this.currentMaterial].colorMap=!0}else d("Mesh error in part, face count: "+o.length+", color count:"+q.length)}return this},showAllSegments:function(){for(var a in this.segment_state)this.segment_state.hasOwnProperty(a)&&(this.segment_state[a]=!0)},hideAllSegments:function(){for(var a in this.segment_state)this.segment_state.hasOwnProperty(a)&&(this.segment_state[a]=!1)},setSegment:function(a,c){c!==b?this.segment_state[a]=c:this.currentSegment=a},addPoint:function(a){if(a.length!==3||typeof a[0]=="object")for(var b=0,c=a.length;b<c;b++)this.points.push(a[b]);else this.points.push(a);return this.points.length-1},getMaterialIndex:function(a){return this.materials.indexOf(a)},setFaceMaterial:function(a,c){var d;return typeof a=="number"?d=a:(d=this.materials.indexOf(a),d===-1&&(this.materials.push(a),d=this.materials.length-1)),c!==b?this.faces[c]!==b&&(this.faces[c].material=d):this.currentMaterial=d,this},addFace:function(a,c,d,e){if(typeof a[0]!="number"){for(var g=0,h=a.length;g<h;g++)this.addFace(a[g]);return}return c===b?(this.currentFace=this.faces.length,this.faces.push(new f)):(this.faces[c]===b&&(this.faces[c]=new f),this.currentFace=c),typeof a=="object"&&(this.faces[this.currentFace].points=a),d!==b?this.setFaceMaterial(d,this.currentFace):this.faces[this.currentFace].material=this.currentMaterial,e!==b?this.faces[this.currentFace].segment=e:this.faces[this.currentFace].segment=this.currentSegment,this.currentFace},flipFaces:function(){for(var a=0,b=this.faces.length;a<b;a++)this.faces[a].flip()},triangulateQuads:function(){for(var a=0,b=this.faces.length;a<b;a++)if(this.faces[a].points.length===4){var c=this.faces.length;this.addFace([this.faces[a].points[2],this.faces[a].points[3],this.faces[a].points[0]],this.faces.length,this.faces[a].material,this.faces[a].segment),this.faces[a].points.pop(),this.faces[c].normal=this.faces[a].normal.slice(0),this.faces[a].point_colors.length===4&&(this.faces[c].setColor(this.faces[a].point_colors[2],0),this.faces[c].setColor(this.faces[a].point_colors[3],1),this.faces[c].setColor(this.faces[a].point_colors[0],2),this.faces[a].point_colors.pop()),this.faces[a].uvs.length===4&&(this.faces[c].setUV(this.faces[a].uvs[2],0),this.faces[c].setUV(this.faces[a].uvs[3],1),this.faces[c].setUV(this.faces[a].uvs[0],2),this.faces[a].uvs.pop()),this.faces[a].point_normals.length===4&&(this.faces[c].point_normals[0]=this.faces[a].point_normals[2],this.faces[c].point_normals[1]=this.faces[a].point_normals[3],this.faces[c].point_normals[2]=this.faces[a].point_normals[0],this.faces[a].point_normals.pop())}return this},booleanAdd:function(c,d){var f=a.mat4,g=this.points.length,h=this.faces.length,i,j,k,l;d=e(d),c.wireframeMaterial&&(this.wireframeMaterial=c.wireframeMaterial);if(d!==b){var m=d;for(i=0,k=c.points.length;i<k;i++)this.addPoint(f.vec3_multiply(c.points[i],m))}else for(i=0,k=c.points.length;i<k;i++)this.addPoint([c.points[i][0],c.points[i][1],c.points[i][2]]);var n=[];for(i=0,k=c.materials.length;i<k;i++){var o=this.materials.indexOf(c.materials[i]);o===-1?(this.materials.push(c.materials[i]),n[i]=this.materials.length-1):n[i]=o}for(i=0,k=c.faces.length;i<k;i++){var p=[];for(j=0,l=c.faces[i].points.length;j<l;j++)p.push(c.faces[i].points[j]+g);var q=this.addFace(p),r=this.faces[q];r.segment=c.faces[i].segment,r.material=n[c.faces[i].material],r.material===b&&(r.material=0);for(j=0,l=c.faces[i].uvs.length;j<l;j++)r.uvs[j]=[c.faces[i].uvs[j][0],c.faces[i].uvs[j][1]];for(j=0,l=c.faces[i].point_normals.length;j<l;j++)r.point_normals[j]=[c.faces[i].point_normals[j][0],c.faces[i].point_normals[j][1],c.faces[i].point_normals[j][2]]}return this},calcFaceNormals:function(b,c){var d=a.vec3,e=a.triangle,f=0,g=this.faces.length,h,i=this.points,j;b&&(f=b),c&&(g=c+1);for(;f<g;f++){h=this.faces[f],j=h.points;if(j.length<3){h.normal=[0,0,0];continue}d.normalize(e.normal(i[j[0]],i[j[1]],i[j[2]],h.normal))}return this},getMaterial:function(a){if(!isNaN(parseInt(a,10)))return this.materials[b];for(var b=0,c=this.materials.length;b<c;b++)if(this.materials[b].name===a)return this.materials[b];return null},getMaterials:function(){return this.materials},bindInstanceMaterials:function(a){this.instanceMaterials=a},calcNormals:function(c){var d=a.vec3,e=!1,f;this.dynamic&&(f=[],c=c||{}),c!==b&&(f=[],e=!0),this.calcFaceNormals();var g,h,i,j,k,l,m=new Array(this.points.length);for(g=0,j=m.length;g<j;g++)m[g]=[];var n=this.faces.length;for(g=0;g<n;g++){var o=this.faces[g].points.length;for(h=0;h<o;h++){var p=this.faces[g].points[h];m[p].push([g,h])}}for(g=0,j=this.points.length;g<j;g++){var q=m[g].length;for(h=0;h<q;h++){var r=1,s=m[g][h][0],t=m[g][h][1],u=this.materials.length?this.materials[this.faces[s].material].max_smooth:60,v=this.faces[s];e&&(f[s]===b&&(f[s]=[]),f[s][t]===b&&(f[s][t]=[]));var w=new Array(3);w[0]=v.normal[0],w[1]=v.normal[1],w[2]=v.normal[2];if(u!==0)for(i=0;i<q;i++){if(h===i)continue;var x=m[g][i][0],y=this.faces[x],z=d.angle(y.normal,v.normal);if(z!==z||z*(180/Math.PI)<=u)e&&f[s][t].push(x),w[0]+=y.normal[0],w[1]+=y.normal[1],w[2]+=y.normal[2],r++}w[0]/=r,w[1]/=r,w[2]/=r,this.faces[s].point_normals[t]=d.normalize(w)}}if(e){var A=0;for(g=0,j=f.length;g<j;g++)for(h=0,k=f[g].length;h<k;h++)A+=f[g][h].length;c.faceCount||(c.faceCount=new Uint8Array(this.faces.length*3)),c.faceNorm||(c.faceNorm=new Uint16Array(A));var B=0;for(g=0,j=this.faces.length;g<j;g++)for(h=0;h<3;h++){var C=f[g][h];c.faceCount[g*3+h]=C?C.length:0;if(C)for(i=0,l=C.length;i<l;i++)c.faceNorm[B++]=f[g][h][i];else B++}this.normalMapRef=c}return this},recalcNormals:function(a){var b,c,d,e,f,g,h,i,k,l,m,n,o,p,q,r,s;a=a||this.normalMapRef;if(!a)return;this.calcFaceNormals();var t=0,u=0,v=0,w;for(b=0,c=this.faces.length;b<c;b++){q=this.faces[b],w=q.normal;for(j=0;j<3;j++){n=q.point_normals[j],i=w[0],k=w[1],l=w[2],s=a.faceCount[u++];for(f=0,iMax=s;f<iMax;f++)o=a.faceNorm[t++],p=this.faces[o],h=p.normal,i+=h[0],k+=h[1],l+=h[2];s?(m=s+1,i/=m,k/=m,l/=m,g=Math.sqrt(i*i+k*k+l*l),i/=g,k/=g,l/=g,n[0]=i,n[1]=k,n[2]=l):v++}}return this},removeDoubles:function(b){var c=[],d=[],e,f,g,h;for(e=0,f=this.points.length;e<f;e++){var i=-1,j=this.points[e];for(g=0,h=c.length;g<h;g++){var k=c[g];if(a.vec3.equal(j,k,b)){i=g;break}}i!=-1?d[e]=i:(d[e]=c.length,c.push(this.points[e]))}this.points=c;for(e=0,f=this.faces.length;e<f;e++){var l=this.faces[e];for(g=0,h=l.points.length;g<h;g++)l.points[g]=d[l.points[g]]}return this},buildEdges:function(){var a,b,c,d,e=[],f=[];for(a=0,c=this.faces.length;a<c;a++){var g=this.faces[a];for(b=0,d=g.points.length;b<d;b++){var h,i,j;j=g.segment,matId=g.material,b?(i=g.points[b],h=g.points[b-1]):(i=g.points[b],h=g.points[d-1]),e[h]=e[h]||{},e[h][matId]=e[h][matId]||{},e[h][matId][j]=e[h][matId][j]||{},!e[h][matId][j][i]&&(!e[i]||!e[i][matId][j][h])&&f.push([matId,j,h,i])}}return this.edges=f,this},subdivide:function(c,e){var f=a.vec3;e=e===b?!0:e,c===b&&(c=1);if(c===0)return;var g,h,i,j,k,l,m,n,o={},p=[],q=[],r=this.points.length,s=this.faces.length,t=[],u=[],v=[],w=[];for(g=0,i=s;g<i;g++){m=this.faces[g];if(m.points&&(m.points.length===3||m.points.length===4)){var x=[0,0,0];for(h=0,j=m.points.length;h<j;h++){var y=this.points[m.points[h]];x[0]+=y[0],x[1]+=y[1],x[2]+=y[2]}x[0]/=j,x[1]/=j,x[2]/=j,t[g]=this.addPoint(x);if(m.uvs.length===m.points.length){var z=[0,0];for(h=0,j=m.uvs.length;h<j;h++){var A=m.uvs[h];z[0]+=A[0],z[1]+=A[1]}z[0]/=j,z[1]/=j,u[g]=z}if(m.point_colors.length===m.points.length){var B=[0,0,0];for(h=0,j=m.point_colors.length;h<j;h++){var C=m.point_colors[h];B[0]+=C[0],B[1]+=C[1],B[2]+=C[2]}B[0]/=j,B[1]/=j,B[2]/=j,v[g]=B}if(m.point_normals.length===m.points.length){var D=[0,0,0];for(h=0,j=m.point_normals.length;h<j;h++){var E=m.point_normals[h];D[0]+=E[0],D[1]+=E[1],D[2]+=E[2]}D[0]/=j,D[1]/=j,D[2]/=j,w[g]=D}}}for(g=0,i=this.faces.length;g<i;g++){m=this.faces[g];for(h=0,j=m.points.length;h<j;h++){var F,G,H,I;h?(H=h,I=h-1):(H=h,I=j-1),G=m.points[H],F=m.points[I],o[F]=o[F]||{},p[F]=p[F]||[],p[F].push(g),o[F][G]===b,o[F][G]={face:g,a:F,b:G,fpa:H,fpb:I}}}for(g in o){if(!o.hasOwnProperty(g))continue;for(h in o[g]){if(!o[g].hasOwnProperty(h))continue;var J=o[g][h],K=o[h][g];if(K===b){d("Mesh.subdivide error. Hole at face #"+J.face+", Edge:["+J.fpa+"->"+J.fpb+"], holes not yet supported; perhaps use Mesh.removeDoubles()?");return}if(!J.edge_point){var L=f.multiply(f.add(this.points[J.a],this.points[J.b]),.5);if(e){var M=f.multiply(f.add(this.points[t[J.face]],this.points[t[K.face]]),.5);J.edge_point=f.multiply(f.add(L,M),.5)}else J.edge_point=L;K.edge_point=J.edge_point,J.edge_avg=L,K.edge_avg=L,J.ep_idx=this.addPoint(J.edge_point),K.ep_idx=J.ep_idx}q[J.a]=q[J.a]||[],q[J.a].push(J.edge_avg);var N=this.faces[J.face].uvs;if(N.length){var O=N[J.fpa],P=N[J.fpb];J.uv=[(O[0]+P[0])/2,(O[1]+P[1])/2]}var Q=this.faces[J.face].point_colors;if(Q.length){var R=Q[J.fpa],S=Q[J.fpb];J.color=f.multiply(f.add(R,S),.5)}var T=this.faces[J.face].point_normals;if(T.length){var U=T[J.fpa],V=T[J.fpb];J.normal=f.normalize(f.multiply(f.add(U,V),.5))}}}if(e){var W=[];for(g=0,i=r;g<i;g++){var X=[0,0,0];if(!p[g])continue;for(h=0,j=p[g].length;h<j;h++){var Y=this.points[t[p[g][h]]];X[0]+=Y[0],X[1]+=Y[1],X[2]+=Y[2]}X[0]/=j,X[1]/=j,X[2]/=j,W[g]=X}var Z=[];for(g=0,i=r;g<i;g++){var $=[0,0,0];if(!q[g])continue;for(h=0,j=q[g].length;h<j;h++){var _=q[g][h];$[0]+=_[0],$[1]+=_[1],$[2]+=_[2]}$[0]/=j,$[1]/=j,$[2]/=j,Z[g]=$}for(g=0,i=r;g<i;g++){if(!p[g])continue;var ab=p[g].length,bb=this.points[g],cb=(ab-3)/ab,db=1/ab,eb=2/ab,fb=f.multiply(bb,cb);fb=f.add(fb,f.multiply(W[g],db)),fb=f.add(fb,f.multiply(Z[g],eb)),this.points[g]=fb}}for(g=0;g<s;g++){m=this.faces[g];if(m.points.length!==3&&m.points.length!==4)continue;var gb=m.points.slice(0),hb=m.uvs.slice(0),ib=m.point_colors.slice(0),jb=m.point_normals.slice(0),kb=hb.length===gb.length,lb=ib.length===gb.length,mb=jb.length===gb.length,nb=m.material,ob,pb,qb;gb.length===3?(this.setFaceMaterial(nb),pb=o[gb[0]][gb[1]],qb=o[gb[2]][gb[0]],this.addFace([gb[0],pb.ep_idx,t[g],qb.ep_idx],g),kb&&(this.faces[g].uvs=[hb[0],pb.uv,u[g],qb.uv]),lb&&(this.faces[g].point_colors=[ib[0],pb.color,v[g],qb.color]),mb&&(this.faces[g].point_normals=[jb[0],pb.normal,w[g],qb.normal]),pb=o[gb[1]][gb[2]],qb=o[gb[0]][gb[1]],ob=this.addFace([gb[1],pb.ep_idx,t[g],qb.ep_idx]),kb&&(this.faces[ob].uvs=[hb[1],pb.uv,u[g],qb.uv]),lb&&(this.faces[ob].point_colors=[ib[1],pb.color,v[g],qb.color]),mb&&(this.faces[ob].point_normals=[jb[1],pb.normal,w[g],qb.normal]),pb=o[gb[2]][gb[0]],qb=o[gb[1]][gb[2]],ob=this.addFace([gb[2],pb.ep_idx,t[g],qb.ep_idx]),kb&&(this.faces[ob].uvs=[hb[2],pb.uv,u[g],qb.uv]),lb&&(this.faces[ob].point_colors=[ib[2],pb.color,v[g],qb.color]),mb&&(this.faces[ob].point_normals=[jb[2],pb.normal,w[g],qb.normal])):(this.setFaceMaterial(nb),pb=o[gb[0]][gb[1]],qb=o[gb[3]][gb[0]],this.addFace([gb[0],pb.ep_idx,t[g],qb.ep_idx],g),kb&&(this.faces[g].uvs=[hb[0],pb.uv,u[g],qb.uv]),lb&&(this.faces[g].point_colors=[ib[0],pb.color,v[g],qb.color]),mb&&(this.faces[g].point_normals=[jb[0],pb.normal,w[g],qb.normal]),pb=o[gb[1]][gb[2]],qb=o[gb[0]][gb[1]],ob=this.addFace([gb[1],pb.ep_idx,t[g],qb.ep_idx]),kb&&(this.faces[ob].uvs=[hb[1],pb.uv,u[g],qb.uv]),lb&&(this.faces[ob].point_colors=[ib[1],pb.color,v[g],qb.color]),mb&&(this.faces[ob].point_normals=[jb[1],pb.normal,w[g],qb.normal]),pb=o[gb[2]][gb[3]],qb=o[gb[1]][gb[2]],ob=this.addFace([gb[2],pb.ep_idx,t[g],qb.ep_idx]),kb&&(this.faces[ob].uvs=[hb[2],pb.uv,u[g],qb.uv]),lb&&(this.faces[ob].point_colors=[ib[2],pb.color,v[g],qb.color]),mb&&(this.faces[ob].point_normals=[jb[2],pb.normal,w[g],qb.normal]),pb=o[gb[3]][gb[0]],qb=o[gb[2]][gb[3]],ob=this.addFace([gb[3],pb.ep_idx,t[g],qb.ep_idx]),kb&&(this.faces[ob].uvs=[hb[3],pb.uv,u[g],qb.uv]),lb&&(this.faces[ob].point_colors=[ib[3],pb.color,v[g],qb.color]),mb&&(this.faces[ob].point_normals=[jb[3],pb.normal,w[g],qb.normal]))}c--;if(c!==0){this.subdivide(c,e);return}return this},removeInternals:function(){var c=a.vec3,d,e,f,g,h,i,j,k,l={},m=this.points.length,n=this.faces.length,o,p,q,r;for(d=0,f=this.faces.length;d<f;d++){j=this.faces[d];for(e=0,g=j.points.length;e<g;e++)e?(q=e,r=e-1):(q=e,r=g-1),o=j.points[q],p=j.points[r],l[o]=l[o]||{},l[o][p]===b?l[o][p]=[d]:l[o][p].push(d)}var s=function(a){return l[p][o].indexOf(a)!==-1};for(d=0;d<n;d++){var t=0;j=this.faces[d];var u=null;for(e=0,g=j.points.length;e<g;e++)e?(q=e,r=e-1):(q=e,r=g-1),o=j.points[q],p=j.points[r],u?u=u.filter(s):u=l[p][o];u.length&&(this.faces.splice(d,1),n--,d--)}return this},prepare:function(a){return a===b&&(a=!0),this.buildWireframe&&!this.triangulateWireframe&&this.buildEdges(),this.triangulateQuads().calcNormals(),this.buildWireframe&&this.triangulateWireframe&&this.buildEdges(),this.compile(),a&&!this.dynamic&&this.clean(),this},clean:function(){var a,b;for(a=0,b=this.points.length;a<b;a++)delete this.points[a],this.points[a]=null;this.points=[];for(a=0,b=this.faces.length;a<b;a++)delete this.faces[a].points,delete this.faces[a].point_normals,delete this.faces[a].uvs,delete this.faces[a].normal,delete this.faces[a],this.faces[a]=null;return this.faces=[],this},compileMap:function(c){var d=a.vec3,e=a.vec2;c===b&&(c=1e-5);var f={segments:[],bounds:[]},g=[],h,i,j,k,l,m,n,o,p,q;this.materials.length||this.materials.push(new a.Material);for(h=0,m=this.materials.length;h<m;h++)g[h]=[];for(h=0,m=this.faces.length;h<m;h++)this.faces[h].points.length===3&&(p=this.faces[h].material,q=this.faces[h].segment,g[p][q]===b&&(g[p][q]=[],f.segments.push(q)),g[p][q].push(h));var r=[],s=0,t=!1,u=!1,v=!1,w;for(h=0,m=g.length;h<m;h++)for(i in g[h])if(g[h].hasOwnProperty(i))for(j=0;j<g[h][i].length;j++)w=g[h][i][j],t=t||this.faces[w].uvs.length!==0,u=u||this.faces[w].point_normals.length!==0,v=v||this.faces[w].point_colors.length!==0;if(t)for(h=0;h<this.faces.length;h++)if(!this.faces[h].uvs.length)for(i=0;i<this.faces[h].points.length;i++)this.faces[h].uvs.push([0,0]);if(u)for(h=0;h<this.faces.length;h++)if(!this.faces[h].point_normals.length)for(i=0;i<this.faces[h].points.length;i++)this.faces[h].point_normals.push([0,0,0]);if(v)for(h=0;h<this.faces.length;h++)if(!this.faces[h].point_colors.length)for(i=0;i<this.faces[h].points.length;i++)this.faces[h].point_colors.push([0,0,0]);var x=[];for(h=0,m=g.length;h<m;h++)for(i in g[h])if(g[h].hasOwnProperty(i))for(j=0,n=g[h][i].length;j<n;j++){w=g[h][i][j];var y=!1;for(k=0;k<3;k++){var z=this.faces[w].points[k],A=-1;if(r[z]!==b)for(l=0,o=r[z].length;l<o;l++){var B=r[z][l][0],C=r[z][l][1],D=r[z][l][2];A=D,u&&(A=d.equal(this.faces[B].point_normals[C],this.faces[w].point_normals[k],c)?A:-1),t&&(A=e.equal(this.faces[B].uvs[C],this.faces[w].uvs[k],c)?A:-1),v&&(A=d.equal(this.faces[B].point_colors[C],this.faces[w].point_colors[k],c)?A:-1)}A!==-1?(f.elements===b&&(f.elements=[]),f.elements[h]===b&&(f.elements[h]=[]),f.elements[h][i]===b&&(f.elements[h][i]=[]),f.elements[h][i].push(A)):(f.points===b&&(f.points=[]),f.points.push(z),f.bounds.length===0?(f.bounds[0]=[this.points[z][0],this.points[z][1],this.points[z][2]],f.bounds[1]=[this.points[z][0],this.points[z][1],this.points[z][2]]):(this.points[z][0]<f.bounds[0][0]&&(f.bounds[0][0]=this.points[z][0]),this.points[z][1]<f.bounds[0][1]&&(f.bounds[0][1]=this.points[z][1]),this.points[z][2]<f.bounds[0][2]&&(f.bounds[0][2]=this.points[z][2]),this.points[z][0]>f.bounds[1][0]&&(f.bounds[1][0]=this.points[z][0]),this.points[z][1]>f.bounds[1][1]&&(f.bounds[1][1]=this.points[z][1]),this.points[z][2]>f.bounds[1][2]&&(f.bounds[1][2]=this.points[z][2])),u&&(f.normals===b&&(f.normals=[]),f.normals.push([w,k])),v&&(f.colors===b&&(f.colors=[]),f.colors.push([w,k])),t&&(f.uvs===b&&(f.uvs=[]),f.uvs.push([w,k])),f.elements===b&&(f.elements=[]),f.elements[h]===b&&(f.elements[h]=[]),f.elements[h][i]===b&&(f.elements[h][i]=[]),f.elements[h][i].push(s),r[z]===b&&(r[z]=[]),r[z].push([w,k,s]),s++)}}if(this.edges){f.line_elements=[];for(h=0,m=this.edges.length;h<m;h++){var E=this.edges[h];p=E[0],q=E[1];var F=E[2],G=E[3];f.line_elements[p]=f.line_elements[p]||[],f.line_elements[p][q]=f.line_elements[p][q]||[],f.line_elements[p][q].push(r[F][0][2]),f.line_elements[p][q].push(r[G][0][2])}}return f.dynamic=this.dynamic,f},compileVBO:function(a,c,d,e,f,g,h,i){typeof c=="object"?(c=c.element!==b?c.element:!0,d=c.vertex!==b?c.vertex:!0,g=c.color!==b?c.color:!0,e=c.normal!==b?c.normal:!0,f=c.uv!==b?c.uv:!0,h=c.lines!==b?c.lines:!!a.line_elements,i=c.dynamic!==b?c.dynamic:a.dynamic):(c===b&&(c=!0),d===b&&(d=!0),g===b&&(g=!0),e===b&&(e=!0),f===b&&(f=!0),h===b&&(h=!!a.line_elements),i===b&&(i=a.dynamic));var j={},k,l,m,n,o,p,q,r,s,t,u,v;i&&(u={points:new Int16Array(a.points.length),face_points:new Int16Array(a.points.length*2)},j.dynamicMap=u,j.dynamic=!0);if(a.points&&d){k=a.points.length,j.vbo_points=new Float32Array(k*3);for(n=0,q=k;n<q;n++)m=a.points[n],j.vbo_points[n*3]=this.points[m][0],j.vbo_points[n*3+1]=this.points[m][1],j.vbo_points[n*3+2]=this.points[m][2],i&&(u.points[n]=m)}if(i){var w=a.normals||a.colors||a.uvs;for(n=0,q=w.length;n<q;n++)m=w[n],u.face_points[n*2]=m[0],u.face_points[n*2+1]=m[1]}if(a.normals&&e){k=a.normals.length,j.vbo_normals=new Float32Array(k*3),l=0;for(n=0,q=k;n<q;n++)m=a.normals[n],j.vbo_normals[l++]=this.faces[m[0]].point_normals[m[1]][0],j.vbo_normals[l++]=this.faces[m[0]].point_normals[m[1]][1],j.vbo_normals[l++]=this.faces[m[0]].point_normals[m[1]][2]}if(a.colors&&g){k=a.colors.length,j.vbo_colors=new Float32Array(k*3),l=0;for(n=0,q=k;n<q;n++)m=a.colors[n],j.vbo_colors[l++]=this.faces[m[0]].point_colors[m[1]][0],j.vbo_colors[l++]=this.faces[m[0]].point_colors[m[1]][1],j.vbo_colors[l++]=this.faces[m[0]].point_colors[m[1]][2]}if(a.uvs&&f){k=a.uvs.length,j.vbo_uvs=new Float32Array(k*2),l=0;for(n=0,q=k;n<q;n++)m=a.uvs[n],j.vbo_uvs[l++]=this.faces[m[0]].uvs[m[1]][0],j.vbo_uvs[l++]=this.faces[m[0]].uvs[m[1]][1]}if(c){j.elements_ref=[],j.vbo_elements=[];for(n=0,q=a.elements.length;n<q;n++){j.elements_ref[n]=[],p=0;for(o in a.elements[n])if(a.elements[n].hasOwnProperty(o)){t=a.elements[n][o];for(r=0,s=t.length;r<s;r++)j.vbo_elements.push(t[r]);j.elements_ref[n][p]=[o|0,t.length|0],p++}}j.vbo_elements=new Uint16Array(j.vbo_elements)}if(h){j.line_elements_ref=[],j.vbo_line_elements=[];for(n=0,q=a.line_elements.length;n<q;n++){j.line_elements_ref[n]=[],p=0;for(o in a.line_elements[n])if(a.line_elements[n].hasOwnProperty(o)){t=a.line_elements[n][o];for(r=0,s=t.length;r<s;r++)j.vbo_line_elements.push(t[r]);j.line_elements_ref[n][p]=[o|0,t.length|0],p++}}j.vbo_line_elements=new Uint16Array(j.vbo_line_elements)}return j.segments=a.segments,j.bounds=a.bounds,j},updateVBO:function(a,b){if(!a.dynamic)return!1;var c,d,e=a.dynamicMap,f=b.points&&!!a.vbo_points,g=b.normals&&!!a.vbo_normals,h=b.uvs&&!!a.vbo_uvs,i=b.colors&&!!a.vbo_colors,j,k,l,m=0;for(c=0,d=e.points.length;c<d;c++)k=this.faces[e.face_points[c*2]],l=e.face_points[c*2+1],f&&(j=this.points[e.points[c]],a.vbo_points[c*3]=j[0],a.vbo_points[c*3+1]=j[1],a.vbo_points[c*3+2]=j[2]),g&&(j=k.point_normals[l],a.vbo_normals[c*3]=j[0],a.vbo_normals[c*3+1]=j[1],a.vbo_normals[c*3+2]=j[2]),i&&(j=k.point_colors[l],a.vbo_colors[c*3]=j[0],a.vbo_colors[c*3+1]=j[1],a.vbo_colors[c*3+2]=j[2]),h&&(j=k.uvs[l],a.vbo_uvs[c*2]=j[0],a.vbo_uvs[c*2+1]=j[1]);return this},rebufferVBO:function(a,b,d){var e=c.gl;return d.points&&(e.bindBuffer(e.ARRAY_BUFFER,b.gl_points),e.bufferData(e.ARRAY_BUFFER,a.vbo_points,e.DYNAMIC_DRAW)),d.normals&&a.vbo_normals&&(e.bindBuffer(e.ARRAY_BUFFER,b.gl_normals),e.bufferData(e.ARRAY_BUFFER,a.vbo_normals,e.DYNAMIC_DRAW)),d.uvs&&a.vbo_uvs&&(e.bindBuffer(e.ARRAY_BUFFER,b.gl_uvs),e.bufferData(e.ARRAY_BUFFER,a.vbo_uvs,e.DYNAMIC_DRAW)),d.colors&&a.vbo_colors&&(e.bindBuffer(e.ARRAY_BUFFER,b.gl_colors),e.bufferData(e.ARRAY_BUFFER,a.vbo_colors,e.DYNAMIC_DRAW)),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),this},bufferVBO:function(a,d){var e=c.gl,f={};return d===b&&(d={}),f.gl_points=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,f.gl_points),e.bufferData(e.ARRAY_BUFFER,a.vbo_points,e.STATIC_DRAW),a.vbo_normals?(f.gl_normals=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,f.gl_normals),e.bufferData(e.ARRAY_BUFFER,a.vbo_normals,e.STATIC_DRAW)):f.gl_normals=d.gl_normals?d.gl_normals:null,a.vbo_uvs?(f.gl_uvs=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,f.gl_uvs),e.bufferData(e.ARRAY_BUFFER,a.vbo_uvs,e.STATIC_DRAW)):f.gl_uvs=d.gl_uvs?d.gl_uvs:null,a.vbo_colors?(f.gl_colors=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,f.gl_colors),e.bufferData(e.ARRAY_BUFFER,a.vbo_colors,e.STATIC_DRAW)):f.gl_colors=d.gl_colors?d.gl_colors:null,!a.vbo_elements&&d.gl_elements?(f.gl_elements=d.gl_elements,f.elements_ref=d.elements_ref):(f.gl_elements=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.gl_elements),e.bufferData(e.ELEMENT_ARRAY_BUFFER,a.vbo_elements,e.STATIC_DRAW),f.elements_ref=a.elements_ref),!a.vbo_line_elements&&d.gl_line_elements?(f.gl_line_elements=d.gl_line_elements,f.line_elements_ref=d.line_elements_ref):(f.gl_line_elements=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.gl_line_elements),e.bufferData(e.ELEMENT_ARRAY_BUFFER,a.vbo_line_elements,e.STATIC_DRAW),f.line_elements_ref=a.line_elements_ref),f.segments=a.segments,f.bounds=a.bounds,e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),f},update:function(a){a=a||{};var b=a.points||a.point||a.vertex||a.vertices||a.all||!0,c=a.uvs||a.uv||a.texture||a.all||!1,e=a.normals||a.normal||a.all||!0,f=a.colors||a.color||a.all||!1;if(!this.dynamic)return d("Mesh not defined as dynamic, cannot update."),!1;e&&this.normalMapRef&&this.recalcNormals();var g={points:b,uvs:c,normals:e,colors:f};this.updateVBO(this.dynamicData.VBO,g),this.rebufferVBO(this.dynamicData.VBO,this.dynamicData.buffer,g)},bindBuffer:function(a){this.originBuffer===null&&(this.originBuffer=a),this.compiled=a,this.segment_state=[];for(var b=0,c=a.segments.length;b<c;b++)this.segment_state[a.segments[b]]=!0;this.bb=a.bounds},compile:function(a){if(this.faces.length>0&&this.points.length>0){var b=this.compileVBO(this.compileMap(a)),c=this.bufferVBO(b);this.bindBuffer(c);if(this.dynamic){this.sourcePoints=[];for(var d=0,e=this.points.length;d<e;d++)this.sourcePoints[d]=this.points[d].slice(0);this.dynamicData={VBO:b,buffer:c}}}return this},addMorphTarget:function(a){this.morphTargets===null&&(this.morphTargets=[]),this.morphTargets.push(a)},setMorphSource:function(a){if(this.morphSourceIndex===a)return;this.morphSourceIndex=a,this.bindBuffer(this.morphTargets[a])},setMorphTarget:function(a){if(this.morphTargetIndex===a)return;this.morphTargetIndex=a,this.morphTarget=this.morphTargets[a]},setMorphWeight:function(a){this.morphWeight=a},morphTargetCount:function(){return this.morphTargets!==null?this.morphTargets.length:0}};var h={Mesh:g,Face:f};return h}),CubicVR.RegisterModule("Motion",function(a){function k(){this.value=0,this.time=0,this.shape=c.envelope.shape.TCB,this.tension=0,this.continuity=0,this.bias=0,this.prev=null,this.next=null,this.param=[0,0,0,0]}function l(a){this.nKeys=0,this.keys=null,this.firstKey=null,this.lastKey=null,a?(this.in_behavior=CubicVR.parseEnum(c.envelope.behavior,a.in_behavior||a.inBehavior||a.behavior)||c.envelope.behavior.CONSTANT,this.out_behavior=CubicVR.parseEnum(c.envelope.behavior,a.out_behavior||a.outBehavior||a.behavior)||c.envelope.behavior.CONSTANT):(this.in_behavior=c.envelope.behavior.CONSTANT,this.out_behavior=c.envelope.behavior.CONSTANT)}function m(a,b){this.controllers=[],this.yzflip=!1;if(typeof a=="object"){var c=CubicVR.get(a);this.env_init=CubicVR.get(c.envelope),this.key_init=CubicVR.get(c.key);for(var d in c){if(!c.hasOwnProperty(d))continue;if(d==="envelope"||d==="key")continue;var e=c[d],f=CubicVR.get(e.envelope);for(var g in e){if(!e.hasOwnProperty(g))continue;if(g==="envelope"||g==="key")continue;var h=e[g];if(typeof h=="object")for(var i in h)this.setKey(d,i,g,h[i]),f&&this.setBehavior(d,i,f)}}}else this.env_init=a,this.key_init=b}var b=
a.undef,c=CubicVR.enums;c.motion={POS:0,ROT:1,SCL:2,POSITION:0,ROTATION:1,SCALE:2,FOV:3,LENS:4,NEARCLIP:5,FARCLIP:6,INTENSITY:7,X:0,Y:1,Z:2,V:3},c.envelope={shape:{TCB:0,HERM:1,BEZI:2,LINE:3,STEP:4,BEZ2:5},behavior:{RESET:0,CONSTANT:1,REPEAT:2,OSCILLATE:3,OFFSET:4,LINEAR:5}};var d=function(a,b,c){var d,e=0,f;return f=c-b,f===0?[b,0]:(d=a-f*Math.floor((a-b)/f),e=-parseInt((d-a)/f+(d>a?.5:-0.5),10),[d,e])},e=function(a){var b,c,d,e,f,g;return f=a*a,g=a*f,c=3*f-g-g,b=1-c,e=g-f,d=e-f+a,[b,c,d,e]},f=function(a,b,c,d,e){var f,g,h,i,j;return i=e*e,j=i*e,h=3*(b-a),g=3*(c-b)-h,f=d-a-h-g,f*j+g*i+h*e+a},g=function(a,b,c,d,e,h,i){var j,k;return k=h+(i-h)*.5,j=f(a,b,c,d,k),Math.abs(e-j)>1e-4?(j>e?i=k:h=k,g(a,b,c,d,e,h,i)):k},h=function(a,b,d){var e,h,i,j=0,k=1;return a.shape===c.envelope.shape.BEZ2?e=a.time+a.param[2]:e=a.time+(b.time-a.time)/3,i=g(a.time,e,b.time+b.param[0],b.time,d,j,k),a.shape===c.envelope.shape.BEZ2?h=a.value+a.param[3]:h=a.value+a.param[1]/3,f(a.value,h,b.param[1]+b.value,b.value,i)},i=function(a,b){var d,e,f,g,h;return a.shape===c.envelope.shape.TCB?(d=(1-a.tension)*(1+a.continuity)*(1+a.bias),e=(1-a.tension)*(1-a.continuity)*(1-a.bias),f=b.value-a.value,a.prev?(g=(b.time-a.time)/(b.time-a.prev.time),h=g*(d*(a.value-a.prev.value)+e*f)):h=e*f):a.shape===c.envelope.shape.LINE?(f=b.value-a.value,a.prev?(g=(b.time-a.time)/(b.time-a.prev.time),h=g*(a.value-a.prev.value+f)):h=f):a.shape===c.envelope.shape.BEZI||a.shape===c.envelope.shape.HERM?(h=a.param[1],a.prev&&(h*=(b.time-a.time)/(b.time-a.prev.time))):a.shape===c.envelope.shape.BEZ2?(h=a.param[3]*(b.time-a.time),Math.abs(a.param[2])>1e-5?h/=a.param[2]:h*=1e5):a.shape===c.envelope.shape.STEP?h=0:h=0,h},j=function(a,b){var d,e,f,g,h;return b.shape===c.envelope.shape.LINE?(f=b.value-a.value,b.next?(g=(b.time-a.time)/(b.next.time-a.time),h=g*(b.next.value-b.value+f)):h=f):b.shape===c.envelope.shape.TCB?(d=(1-b.tension)*(1-b.continuity)*(1+b.bias),e=(1-b.tension)*(1+b.continuity)*(1-b.bias),f=b.value-a.value,b.next?(g=(b.time-a.time)/(b.next.time-a.time),h=g*(e*(b.next.value-b.value)+d*f)):h=d*f):b.shape===c.envelope.shape.HERM||b.shape===c.envelope.shape.BEZI?(h=b.param[0],b.next&&(h*=(b.time-a.time)/(b.next.time-a.time))):b.shape===c.envelope.shape.BEZ2?(h=b.param[1]*(b.time-a.time),Math.abs(b.param[0])>1e-5?h/=b.param[0]:h*=1e5):b.shape===c.envelope.shape.STEP?h=0:h=0,h};l.prototype={setBehavior:function(a,b){this.in_behavior=CubicVR.parseEnum(c.envelope.behavior,a),this.out_behavior=CubicVR.parseEnum(c.envelope.behavior,b)},empty:function(){return this.nKeys===0},addKey:function(a,b,d){var e,f=typeof a=="object"?a:d;return b||(b=0),a||(a=0),f?(f=a,a=f.time,e=this.insertKey(a),e.value=f.value?f.value:b,e.time=f.time?f.time:a,e.shape=CubicVR.parseEnum(c.envelope.shape,f.shape)||c.envelope.shape.TCB,e.tension=f.tension?f.tension:0,e.continuity=f.continuity?f.continuity:0,e.bias=f.bias?f.bias:0,e.param=f.param?f.param:[0,0,0,0]):(e=this.insertKey(a),e.value=b),e},insertKey:function(a){var b=new k;b.time=a;if(!this.nKeys)return this.keys=b,this.firstKey=b,this.lastKey=b,this.nKeys++,b;var c=this.keys;while(c){this.firstKey.time>a?this.firstKey=b:this.lastKey.time<a&&(this.lastKey=b);if(c.time>b.time)return b.prev=c.prev,b.prev&&(b.prev.next=b),b.next=c,b.next.prev=b,this.nKeys++,b;if(!c.next)return b.prev=c,c.next=b,this.nKeys++,b;c=c.next}return null},evaluate:function(a){var b,f,g,k,l,m,n,o,p,q,r,s=0,t;if(this.nKeys===0)return 0;if(this.nKeys===1)return this.keys.value;g=this.firstKey,k=this.lastKey;var u,v;if(a<g.time){v=this.in_behavior;if(v===c.envelope.behavior.RESET)return 0;if(v===c.envelope.behavior.CONSTANT)return g.value;if(v===c.envelope.behavior.REPEAT)u=d(a,g.time,k.time),a=u[0];else if(v===c.envelope.behavior.OCILLATE)u=d(a,g.time,k.time),a=u[0],t=u[1],t%2&&(a=k.time-g.time-a);else if(v===c.envelope.behavior.OFFSET)u=d(a,g.time,k.time),a=u[0],t=u[1],s=t*(k.value-g.value);else if(v===c.envelope.behavior.LINEAR)return r=i(g,g.next)/(g.next.time-g.time),r*(a-g.time)+g.value}else if(a>k.time){v=this.out_behavior;if(v===c.envelope.behavior.RESET)return 0;if(v===c.envelope.behavior.CONSTANT)return k.value;if(v===c.envelope.behavior.REPEAT)u=d(a,g.time,k.time),a=u[0];else if(v===c.envelope.behavior.OCILLATE)u=d(a,g.time,k.time),a=u[0],t=u[1],t%2&&(a=k.time-g.time-a);else if(v===c.envelope.behavior.OFFSET)u=d(a,g.time,k.time),a=u[0],t=u[1],s=t*(k.value-g.value);else if(v===c.envelope.behavior.LINEAR)return q=j(k.prev,k)/(k.time-k.prev.time),q*(a-k.time)+k.value}if(this.lastKey0)if(a>this.lastKey0.time)b=this.lastKey0;else if(a<this.lastKey0.time){b=this.lastKey;while(a<b.time&&b.prev)b=b.prev}else b=this.keys;else b=this.keys;while(a>b.next.time)b=b.next;f=b.next,this.lastKey0=b;if(a===b.time)return b.value+s;if(a===f.time)return f.value+s;l=(a-b.time)/(f.time-b.time);var w=f.shape;if(w===c.envelope.shape.TCB||w===c.envelope.shape.BEZI||w===c.envelope.shape.HERM){r=i(b,f),q=j(b,f);var x=e(l);return x[0]*b.value+x[1]*f.value+x[2]*r+x[3]*q+s}return w===c.envelope.shape.BEZ2?h(b,f,a)+s:w===c.envelope.shape.LINE?b.value+l*(f.value-b.value)+s:w===c.envelope.shape.STEP?b.value+s:s}},m.prototype={envelope:function(a,d){return d=CubicVR.parseEnum(c.motion,d)||0,a=CubicVR.parseEnum(c.motion,a)||0,this.controllers[a]===b&&(this.controllers[a]=[]),this.controllers[a][d]===b&&(this.controllers[a][d]=new l(this.env_init)),this.controllers[a][d]},evaluate:function(a){var b=[];for(var c in this.controllers)if(this.controllers.hasOwnProperty(c)){b[c]=[];for(var d in this.controllers[c])this.controllers[c].hasOwnProperty(d)&&(b[c][d]=this.controllers[c][d].evaluate(a))}return b},apply:function(a,b){for(var d in this.controllers)if(this.controllers.hasOwnProperty(d)){var e=parseInt(d,10);if(this.yzflip&&e===c.motion.ROT){this.q||(this.q=new CubicVR.Quaternion);var f=this.q,g=this.controllers[d][0].evaluate(a),h=this.controllers[d][1].evaluate(a),i=this.controllers[d][2].evaluate(a);f.fromEuler(g,i,-h);var j=f.toEuler();b.control(e,0,j[0]),b.control(e,1,j[1]),b.control(e,2,j[2])}else for(var k in this.controllers[d])this.controllers[d].hasOwnProperty(k)&&b.control(e,parseInt(k,10),this.controllers[d][k].evaluate(a))}},setKey:function(a,b,d,e,f){b=CubicVR.parseEnum(c.motion,b)||0,a=CubicVR.parseEnum(c.motion,a)||0;var g=this.envelope(a,b);return g.addKey(d,e,f?f:this.key_init)},setArray:function(a,b,d,e){var f=[];a=CubicVR.parseEnum(c.motion,a)||0;for(var g in d)if(d.hasOwnProperty(g)){var h=this.envelope(a,CubicVR.parseEnum(c.motion,g));f[g]=h.addKey(b,d[g],e?e:this.key_init)}return f},setBehavior:function(a,b,d,e){var f=this.envelope(a,b);if(typeof d=="object"){var g=d;d=g.in_behavior||g.inBehavior||g.behavior,e=g.out_behavior||g.outBehavior||g.behavior}b=CubicVR.parseEnum(c.motion,b)||0,a=CubicVR.parseEnum(c.motion,a)||0,f.setBehavior(d,e)},setBehaviorArray:function(a,b,d){a=CubicVR.parseEnum(c.motion,a)||0;var e=this.controllers[a];for(var f in e)if(e.hasOwnProperty(f)){var g=this.envelope(a,CubicVR.parseEnum(c.motion,f)||0);g.setBehavior(b,d)}}};var n={Motion:m,Envelope:l,EnvelopeKey:k};return n}),CubicVR.RegisterModule("Octree",function(a){function g(a,b){var c=this;this.size=a,this.depth=b,this.worker=new base_Worker({message:function(a){console.log("Octree Worker Message:",a)},error:function(a){console.log("Octree Worker Error:",a)},type:"octree"}),this.worker.start(),this.init=function(a){c.scene=a,c.worker.init({size:c.size,max_depth:c.depth,camera:a.camera})},this.insert=function(a){c.worker.send({message:"insert",node:a})},this.draw_on_map=function(){return},this.reset_node_visibility=function(){return},this.get_frustum_hits=function(){}}function h(b,c,d,e,f){var g=this._children=[];this._dirty=!1,g[0]=null,g[1]=null,g[2]=null,g[3]=null,g[4]=null,g[5]=null,g[6]=null,g[7]=null,f=this._child_index=f||-1,d=this._root=d||null,c=this._max_depth=c||0,b=this._size=b||0,e=this._position=e||[0,0,0],this._nodes=[],this._lights=[],this._static_lights=[];var h=this._sphere=[e[0],e[1],e[2],Math.sqrt(3*(this._size/2*this._size/2))],i=this._bbox=[[0,0,0],[0,0,0]],j=a.aabb;j.reset(i,e);var k=b/2;j.engulf(i,[e[0]+k,e[1]+k,e[2]+k]),j.engulf(i,[e[0]-k,e[1]-k,e[2]-k]),this._debug_visible=!1}function j(){this.position=[0,0,0],this.visible=!1,this._object=null}function k(){this.octree=null,this.nodes=[],this.camera=null}function m(a,b){this.camera=b,this.worker=a,this.draw_on_map=function(a){return}}function n(){this.last_in=[],this._planes=[],this.sphere=null;for(var a=0;a<6;++a)this._planes[a]=[0,0,0,0]}var b=a.undef,c=a.GLCore,d=a.plane,e=a.sphere,f=a.enums;f.frustum={plane:{LEFT:0,RIGHT:1,TOP:2,BOTTOM:3,NEAR:4,FAR:5}},f.octree={TOP_NW:0,TOP_NE:1,TOP_SE:2,TOP_SW:3,BOTTOM_NW:4,BOTTOM_NE:5,BOTTOM_SE:6,BOTTOM_SW:7};var i=function(a,b,c){var d=a.slice((c||b)+1||a.length);return a.length=b<0?a.length+b:b,a.push.apply(a,d)};h.prototype.destroy=function(){var a,b,c;for(a=0,b=this._static_lights.length;a<b;++a)c=this._static_lights[a],c.octree_leaves=null,c.octree_common_root=null,c.octree_aabb=null;for(a=0,b=this._lights.length;a<b;++a)c=this._lights[a],c.octree_leaves=null,c.octree_common_root=null,c.octree_aabb=null;this._static_lights=null,this._lights=null;for(a=0,b=this._children.length;a<b;++a)this._children[a]!==null&&this._children[a].destroy();for(a=0,b=this._nodes.length;a<b;++a){var d=this._nodes[a];d.octree_leaves=null,d.octree_common_root=null,d.octree_aabb=null,d.dynamic_lights=[],d.static_lights=[]}this._children[0]=null,this._children[1]=null,this._children[2]=null,this._children[3]=null,this._children[4]=null,this._children[5]=null,this._children[6]=null,this._children[7]=null,this._children=null,this._root=null,this._position=null,this._nodes=null,this._lights=null,this._static_lights=null,this._sphere=null,this._bbox=null},h.prototype.toString=function(){var a=[this._bbox[1][0]-this._bbox[0][0],this._bbox[1][2]-this._bbox[0][2]];return"[Octree: @"+this._position+", depth: "+this._max_depth+", size: "+this._size+", nodes: "+this._nodes.length+", measured size:"+a+"]"},h.prototype.remove=function(a){var b=!1,c=this._nodes.length,d;for(d=c-1,c=this._nodes.length;d>=0;--d)if(a===this._nodes[d]){i(this._nodes,d),this.dirty_lineage(),b=!0;break}if(!b)for(d=c-1,c=this._lights.length;d>=0;--d)if(a===this._lights[d]){i(this._lights,d),this.dirty_lineage();break}},h.prototype.dirty_lineage=function(){this._dirty=!0,this._root!==null&&this._root.dirty_lineage()},h.prototype.cleanup=function(){var a=this._children.length,b=0;for(var c=0;c<a;++c){var d=this._children[c];if(d!==null){var e=!0;d._dirty===!0&&(e=d.cleanup()),e?++b:this._children[c]=null}}return this._nodes.length!==0||this._static_lights.length!==0||this._lights.length!==0||b!==0&&a!==0?!0:!1},h.prototype.insert_light=function(a){this.insert(a,!0)},h.prototype.propagate_static_light=function(a){var b,c;for(b=0,c=this._nodes.length;b<c;++b)this._nodes[b].static_lights.indexOf(a)===-1&&this._nodes[b].static_lights.push(a);for(b=0;b<8;++b)this._children[b]!==null&&this._children[b].propagate_static_light(a)},h.prototype.collect_static_lights=function(a){var b,c;for(b=0,c=this._static_lights.length;b<c;++b)a.static_lights.indexOf(this._static_lights[b])===-1&&a.static_lights.push(this._static_lights[b]);for(b=0;b<8;++b)this._children[b]!==null&&this._children[b].collect_static_lights(a)},h.prototype.insert=function(c,d){function e(b,c,d,e){var g,h,i;if(d)if(c.method===f.light.method.STATIC){b._static_lights.indexOf(c)===-1&&b._static_lights.push(c);for(g=0,h=b._nodes.length;g<h;++g)b._nodes[g].static_lights.indexOf(c)===-1&&b._nodes[g].static_lights.push(c);i=b._root;while(i!==null){for(g=0,l=i._nodes.length;g<l;++g){var j=i._nodes[g];j.static_lights.indexOf(c)===-1&&j.static_lights.push(c)}i=i._root}}else b._lights.indexOf(c)===-1&&b._lights.push(c);else{b._nodes.push(c);for(g=0,h=b._static_lights.length;g<h;++g)c.static_lights.indexOf(b._static_lights[g])===-1&&c.static_lights.push(b._static_lights[g]);i=b._root;while(i!==null){for(g=0,h=i._static_lights.length;g<h;++g){var k=i._static_lights[g];c.static_lights.indexOf(k)===-1&&c.static_lights.push(k)}i=i._root}}c.octree_leaves.push(b),c.octree_common_root=e;var m=a.aabb;m.engulf(c.octree_aabb,b._bbox[0]),m.engulf(c.octree_aabb,b._bbox[1])}d===b&&(d=!1),this._root===null&&(c.octree_leaves=[],c.octree_common_root=null);if(this._max_depth===0){e(this,c,d,this._root);return}var g=this._position,i,j,k,m,n,o,p,q,r=c.getAABB(),s=[r[0][0],r[0][1],r[0][2]],t=[r[1][0],r[1][1],r[1][2]];i=s[0]<g[0]&&s[1]<g[1]&&s[2]<g[2],j=t[0]>g[0]&&s[1]<g[1]&&s[2]<g[2],n=s[0]<g[0]&&t[1]>g[1]&&s[2]<g[2],o=t[0]>g[0]&&t[1]>g[1]&&s[2]<g[2],k=s[0]<g[0]&&s[1]<g[1]&&t[2]>g[2],m=t[0]>g[0]&&s[1]<g[1]&&t[2]>g[2],p=s[0]<g[0]&&t[1]>g[1]&&t[2]>g[2],q=t[0]>g[0]&&t[1]>g[1]&&t[2]>g[2];if(i&&j&&n&&o&&k&&m&&p&&q)e(this,c,d,this),d?c.method==f.light.method.STATIC&&this.propagate_static_light(c):this.collect_static_lights(c);else{for(var u=0,v=this._static_lights.length;u<v;++u)c.static_lights===b&&(c.static_lights=[]),c.static_lights.indexOf(this._static_lights[u])===-1&&c.static_lights.push(this._static_lights[u]);var w=this._size/2,x=this._size/4,y,z=0,A=this._position[0],B=this._position[1],C=this._position[2];i&&(y=[A-x,B-x,C-x],this._children[f.octree.TOP_NW]===null&&(this._children[f.octree.TOP_NW]=new h(w,this._max_depth-1,this,y,f.octree.TOP_NW)),this._children[f.octree.TOP_NW].insert(c,d),++z),j&&(y=[A+x,B-x,C-x],this._children[f.octree.TOP_NE]===null&&(this._children[f.octree.TOP_NE]=new h(w,this._max_depth-1,this,y,f.octree.TOP_NE)),this._children[f.octree.TOP_NE].insert(c,d),++z),n&&(y=[A-x,B+x,C-x],this._children[f.octree.BOTTOM_NW]===null&&(this._children[f.octree.BOTTOM_NW]=new h(w,this._max_depth-1,this,y,f.octree.BOTTOM_NW)),this._children[f.octree.BOTTOM_NW].insert(c,d),++z),o&&(y=[A+x,B+x,C-x],this._children[f.octree.BOTTOM_NE]===null&&(this._children[f.octree.BOTTOM_NE]=new h(w,this._max_depth-1,this,y,f.octree.BOTTOM_NE)),this._children[f.octree.BOTTOM_NE].insert(c,d),++z),k&&(y=[A-x,B-x,C+x],this._children[f.octree.TOP_SW]===null&&(this._children[f.octree.TOP_SW]=new h(w,this._max_depth-1,this,y,f.octree.TOP_SW)),this._children[f.octree.TOP_SW].insert(c,d),++z),m&&(y=[A+x,B-x,C+x],this._children[f.octree.TOP_SE]===null&&(this._children[f.octree.TOP_SE]=new h(w,this._max_depth-1,this,y,f.octree.TOP_SE)),this._children[f.octree.TOP_SE].insert(c,d),++z),p&&(y=[A-x,B+x,C+x],this._children[f.octree.BOTTOM_SW]===null&&(this._children[f.octree.BOTTOM_SW]=new h(w,this._max_depth-1,this,y,f.octree.BOTTOM_SW)),this._children[f.octree.BOTTOM_SW].insert(c,d),++z),q&&(y=[A+x,B+x,C+x],this._children[f.octree.BOTTOM_SE]===null&&(this._children[f.octree.BOTTOM_SE]=new h(w,this._max_depth-1,this,y,f.octree.BOTTOM_SE)),this._children[f.octree.BOTTOM_SE].insert(c,d),++z);if(z>1||c.octree_common_root===null)c.octree_common_root=this}},h.prototype.draw_on_map=function(a,c,d){function q(a,b,d,g,h){var i=a<d?a:d,j=b<g?b:g,k=a<d?d-a:a-d,l=b<g?g-b:b-g;c.save(),h!==undefined&&(c.fillStyle=h,c.fillRect(e+i,f+j,k,l)),c.strokeRect(e+i,f+j,k,l),c.restore()}function r(a,b){var c=a._bbox[0][0],d=a._bbox[0][2],e=a._bbox[1][0],f=a._bbox[1][2];q(c,d,e,f,b)}var e=a.width/2,f=a.height/2,g,h,i,j,k,l,m,n,o;if(d===b||d==="map"){c.save(),this._debug_visible!==!1?(c.fillStyle="rgba(0,0,0,0)",c.strokeStyle="#FF0000"):(c.fillStyle="rgba(0,0,0,0)",c.strokeStyle="rgba(0,0,0,0)"),c.beginPath();var p=this._size/2;g=this._position[0],h=this._position[2],c.moveTo(e+g-p,e+h-p),c.lineTo(e+g-p,e+h+p),c.lineTo(e+g+p,e+h+p),c.lineTo(e+g+p,e+h-p),c.stroke(),c.fill(),c.restore()}if(d===b||d==="objects"){c.save();for(k=0,o=this._nodes.length;k<o;++k)n=this._nodes[k],c.fillStyle="#5500FF",n.visible===!0&&n.culled===!1?c.strokeStyle="#FFFFFF":c.strokeStyle="#000000",c.beginPath(),g=n.aabb[0][0],h=n.aabb[0][2],i=n.aabb[1][0]-g,j=n.aabb[1][2]-h,c.rect(e+g,f+h,i,j),c.stroke();c.restore()}if(d===b||d==="lights"){for(k=0,o=this._lights.length;k<o;++k)l=this._lights[k],l.culled===!1&&l.visible===!0?c.fillStyle="rgba(255, 255, 255, 0.1)":c.fillStyle="rgba(255, 255, 255, 0.0)",c.strokeStyle="#FFFF00",c.beginPath(),m=l.distance,g=l.position[0],h=l.position[2],c.arc(e+g,f+h,m,0,Math.PI*2,!0),c.closePath(),c.stroke(),c.fill(),c.beginPath(),g=l.aabb[0][0],h=l.aabb[0][2],i=l.aabb[1][0]-g,j=l.aabb[1][2]-h,c.rect(e+g,f+h,i,j),c.closePath(),c.stroke();for(k=0,o=this._static_lights.length;k<o;++k)l=this._static_lights[k],l.culled===!1&&l.visible===!0?c.fillStyle="rgba(255, 255, 255, 0.01)":c.fillStyle="rgba(255, 255, 255, 0.0)",c.strokeStyle="#FF66BB",c.beginPath(),m=l.distance,g=l.position[0],h=l.position[2],c.arc(e+g,f+h,m,0,Math.PI*2,!0),c.closePath(),c.stroke(),c.fill(),c.beginPath(),g=l.aabb[0][0],h=l.aabb[0][2],i=l.aabb[1][0]-g,j=l.aabb[1][2]-h,c.rect(e+g,f+h,i,j),c.closePath(),c.stroke()}if(d!="lights"&&d!="objects"&&d!="map"){c.save();var s=this._nodes;for(k=0,l=s.length;k<l;++k){n=s[k];if(n.name==d){c.strokeStyle="#FFFF00",c.lineWidth=3,c.beginPath(),g=n.aabb[0][0],h=n.aabb[0][2],i=n.aabb[1][0]-g,j=n.aabb[1][2]-h,c.rect(e+g,f+h,i,j),c.closePath(),c.stroke();var t=n.octree_aabb;c.strokeStyle="#0000FF",q(t[0][0],t[0][2],t[1][0],t[1][2]),c.lineWidth=1,n.common_root!==null&&(c.strokeStyle="#00FF00");break}}c.lineWidth=1,c.strokeStyle="#FFFF00",r(this,"#444444"),c.fill(),c.restore()}for(k=0,o=this._children.length;k<o;++k)this._children[k]!==null&&this._children[k].draw_on_map(a,c,d)},h.prototype.contains_point=function(a){return a[0]<=this._position[0]+this._size/2&&a[1]<=this._position[1]+this._size/2&&a[2]<=this._position[2]+this._size/2&&a[0]>=this._position[0]-this._size/2&&a[1]>=this._position[1]-this._size/2&&a[2]>=this._position[2]-this._size/2},h.prototype.get_frustum_hits=function(a,c){var d={objects:[],lights:[]};if(c===b||c===!0)if(!this.contains_point(a.position)){if(e.intersects(a.frustum.sphere,this._sphere)===!1)return d;var f=a.frustum.contains_sphere(this._sphere);if(f===-1)return this._debug_visible=!1,d;if(f===1)this._debug_visible=2,c=!1;else if(f===0){this._debug_visible=!0;var g=a.frustum.contains_box(this._bbox);if(g===-1)return this._debug_visible=!1,d;g===1&&(this._debug_visible=3,c=!1)}}var h,i,j;for(h=0,i=this._nodes.length;h<i;++h){var k=this._nodes[h];d.objects.push(k),k.dynamic_lights=[].concat(this._lights),k.was_culled=k.culled,k.culled=!1,k.drawn_this_frame=!1}this._debug_visible=this._lights.length>0?4:this._debug_visible;for(h=0,i=this._lights.length;h<i;++h)j=this._lights[h],j.visible===!0&&(d.lights.push(j),j.was_culled=j.culled,j.culled=!1);for(h=0,i=this._static_lights.length;h<i;++h)j=this._static_lights[h],j.visible===!0&&(j.culled=!1);for(h=0;h<8;++h)if(this._children[h]!==null){var l=this._children[h].get_frustum_hits(a,c),m,n;for(m=0,n=l.objects.length;m<n;++m){d.objects.push(l.objects[m]);var o=l.objects[m].dynamic_lights;for(var p=0,q=this._lights.length;p<q;++p)o.indexOf(this._lights[p])<0&&o.push(this._lights[p])}for(m=0,n=l.lights.length;m<n;++m)d.lights.indexOf(l.lights[m])<0&&d.lights.push(l.lights[m])}return d},h.prototype.reset_node_visibility=function(){this._debug_visible=!1;var a,b;for(a=0,b=this._nodes.length;a<b;++a)this._nodes[a].culled=!0;for(a=0,b=this._lights.length;a<b;++a)this._lights[a].culled=!0;for(a=0,b=this._static_lights.length;a<b;++a)this._static_lights[a].culled=!0;for(a=0,b=this._children.length;a<b;++a)this._children[a]!==null&&this._children[a].reset_node_visibility()},j.prototype.toString=function(){return"[OctreeNode "+this.position+"]"},j.prototype.attach=function(a){this._object=a},k.prototype.onmessage=function(b){var c=b.message;if(c==="init"){var d=b.data;this.octree=new h(d.size,d.max_depth),this.camera=new Camera}else if(type==="set_camera"){var e=c.data;this.camera.mvMatrix=e.mvMatrix,this.camera.pMatrix=e.pMatrix,this.camera.position=e.position,this.camera.target=e.target,this.camera.frustum.extract(this.camera,this.camera.mvMatrix,this.camera.pMatrix)}else if(type==="insert"){var f=JSON.parse(c.data),g=new a.SceneObject,i=new a.Transform,j;for(j in f)f.hasOwnProperty(j)&&(g[j]=f[j]);for(j in f.trans)f.trans.hasOwnProperty(j)&&(i[j]=f.trans[j]);g.trans=i,g.id=f.id,this.octree.insert(g),this.nodes[g.id]=g}else type==="cleaup"&&this.octree.cleanup()},m.prototype.extract=function(a,b,c){this.worker.send({type:"set_camera",data:{mvMatrix:this.camera.mvMatrix,pMatrix:this.camera.pMatrix,position:this.camera.position,target:this.camera.target}})},n.prototype.extract=function(c,e,g){var h=a.mat4,i=a.vec3;if(e===b||g===b)return;var j=h.multiply(g,e),k=this._planes;k[f.frustum.plane.LEFT][0]=j[3]+j[0],k[f.frustum.plane.LEFT][1]=j[7]+j[4],k[f.frustum.plane.LEFT][2]=j[11]+j[8],k[f.frustum.plane.LEFT][3]=j[15]+j[12],k[f.frustum.plane.RIGHT][0]=j[3]-j[0],k[f.frustum.plane.RIGHT][1]=j[7]-j[4],k[f.frustum.plane.RIGHT][2]=j[11]-j[8],k[f.frustum.plane.RIGHT][3]=j[15]-j[12],k[f.frustum.plane.TOP][0]=j[3]-j[1],k[f.frustum.plane.TOP][1]=j[7]-j[5],k[f.frustum.plane.TOP][2]=j[11]-j[9],k[f.frustum.plane.TOP][3]=j[15]-j[13],k[f.frustum.plane.BOTTOM][0]=j[3]+j[1],k[f.frustum.plane.BOTTOM][1]=j[7]+j[5],k[f.frustum.plane.BOTTOM][2]=j[11]+j[9],k[f.frustum.plane.BOTTOM][3]=j[15]+j[13],k[f.frustum.plane.NEAR][0]=j[3]+j[2],k[f.frustum.plane.NEAR][1]=j[7]+j[6],k[f.frustum.plane.NEAR][2]=j[11]+j[10],k[f.frustum.plane.NEAR][3]=j[15]+j[14],k[f.frustum.plane.FAR][0]=j[3]-j[2],k[f.frustum.plane.FAR][1]=j[7]-j[6],k[f.frustum.plane.FAR][2]=j[11]-j[10],k[f.frustum.plane.FAR][3]=j[15]-j[14];for(var l=0;l<6;++l)d.normalize(k[l]);var m=1/g[5],n=-k[f.frustum.plane.NEAR][3],o=k[f.frustum.plane.FAR][3],p=o-n,q=p*m,r=q,s=[0,0,n+p*.5],t=[r,q,n+p],u=i.subtract(s,t),v=i.length(u),w=[j[3],j[9],j[10]],x=i.length(w);w=i.multiply(w,1/x);var y=[c.position[0],c.position[1],c.position[2]];y=i.add(y,i.multiply(w,p*.5)),y=i.add(y,i.multiply(w,1)),this.sphere=[y[0],y[1],y[2],v]},n.prototype.contains_sphere=function(b){var c=a.vec3,d=this._planes;for(var e=0;e<6;++e){var f=d[e],g=[f[0],f[1],f[2]],h=c.dot(g,[b[0],b[1],b[2]])+f.d;this.last_in[e]=1;if(h<-b[3])return-1;if(Math.abs(h)<b[3])return 0}return 1},n.prototype.draw_on_map=function(a,b){var c=a.width/2,d=a.height/2;b.save();var e=this._planes,f=[0,1,4,5];for(var g=0,h=f.length;g<h;++g){var i=e[f[g]];b.strokeStyle="#FF00FF",g<this.last_in.length&&this.last_in[g]&&(b.strokeStyle="#FFFF00");var j=-c,k=(-i[3]-i[0]*j)/i[2],l=c,m=(-i[3]-i[0]*l)/i[2];b.moveTo(c+j,d+k),b.lineTo(c+l,d+m),b.stroke()}b.strokeStyle="#0000FF",b.beginPath(),b.arc(c+this.sphere[0],d+this.sphere[2],this.sphere[3],0,Math.PI*2,!1),b.closePath(),b.stroke(),b.restore()},n.prototype.contains_box=function(a){var b=0,c=[];c[0]=a[0],c[1]=[a[0][0],a[0][1],a[1][2]],c[2]=[a[0][0],a[1][1],a[0][2]],c[3]=[a[0][0],a[1][1],a[1][2]],c[4]=[a[1][0],a[0][1],a[0][2]],c[5]=[a[1][0],a[0][1],a[1][2]],c[6]=[a[1][0],a[1][1],a[0][2]],c[7]=a[1];var e=this._planes;for(var f=0;f<6;++f){var g=8,h=1;for(var i=0;i<8;++i)d.classifyPoint(e[f],c[i])===-1&&(h=0,--g);this.last_in[f]=h;if(g===0)return-1;b+=h}return b===6?1:0};var o={Frustum:n,Octree:h};return o}),CubicVR.RegisterModule("Particles",function(a){function e(a,c,d,e,f){this.startpos=new Float32Array(a),this.pos=new Float32Array(a),this.velocity=new Float32Array(e!==b?e:[0,0,0]),this.accel=new Float32Array(f!==b?f:[0,0,0]),this.start_time=c!==b?c:0,this.life_time=d!==b?d:0,this.color=null,this.nextParticle=null}function f(a,d,e,f,g,h,i){var j=c.gl;if(!a)return;this.particles=null,this.last_particle=null,this.pTex=e!==b?e:null,this.vWidth=f,this.vHeight=g,this.alpha=h!==b?h:!1,this.alphaCut=i!==b?i:0,this.pfunc=function(a,b){var c=b-a.start_time;return c<0?0:c>a.life_time&&a.life_time?-1:(a.pos[0]=a.startpos[0]+c*a.velocity[0]+c*c*a.accel[0],a.pos[1]=a.startpos[1]+c*a.velocity[1]+c*c*a.accel[1],a.pos[2]=a.startpos[2]+c*a.velocity[2]+c*c*a.accel[2],this.pgov!==null&&this.pgov(a,b),1)},this.pgov=null,d===b?this.hasColor=!1:this.hasColor=d;var k=this.pTex!==null;this.vs=["#ifdef GL_ES","precision highp float;","#endif","attribute vec3 aVertexPosition;",this.hasColor?"attribute vec3 aColor;":"","uniform mat4 uMVMatrix;","uniform mat4 uPMatrix;","varying vec4 color;","varying vec2 screenPos;",k?"varying float pSize;":"","void main(void) {","vec4 position = uPMatrix * uMVMatrix * vec4(aVertexPosition,1.0);",k?"screenPos=vec2(position.x/position.w,position.y/position.w);":"","gl_Position = position;",this.hasColor?"color = vec4(aColor.r,aColor.g,aColor.b,1.0);":"color = vec4(1.0,1.0,1.0,1.0);",k?"pSize=200.0/position.z;":"float pSize=200.0/position.z;","gl_PointSize = pSize;","}"].join("\n"),this.fs=["#ifdef GL_ES","precision highp float;","#endif",k?"uniform sampler2D pMap;":"","varying vec4 color;",k?"varying vec2 screenPos;":"",k?"uniform vec3 screenDim;":"",k?"varying float pSize;":"","void main(void) {","vec4 c = color;",k?"vec2 screen=vec2((gl_FragCoord.x/screenDim.x-0.5)*2.0,(gl_FragCoord.y/screenDim.y-0.5)*2.0);":"",k?"vec2 pointCoord=vec2( ((screen.x-screenPos.x)/(pSize/screenDim.x))/2.0+0.5,((screen.y-screenPos.y)/(pSize/screenDim.y))/2.0+0.5);":"",k?"vec4 tc = texture2D(pMap,pointCoord); gl_FragColor = vec4(c.rgb*tc.rgb,1.0);":"gl_FragColor = c;","}"].join("\n"),this.maxPoints=a,this.numParticles=0,this.arPoints=new Float32Array(a*3),this.glPoints=null,d&&(this.arColor=new Float32Array(a*3),this.glColor=null),this.shader_particle=new CubicVR.Shader(this.vs,this.fs),this.shader_particle.use(),this.shader_particle.addVertexArray("aVertexPosition"),this.hasColor&&this.shader_particle.addVertexArray("aColor"),this.shader_particle.addMatrix("uMVMatrix"),this.shader_particle.addMatrix("uPMatrix"),this.pTex!==null&&(this.shader_particle.addInt("pMap",0),this.shader_particle.addVector("screenDim"),this.shader_particle.setVector("screenDim",[f,g,0])),this.genBuffer()}var b=a.undef,c=a.GLCore,d=CubicVR.enums;f.prototype={resizeView:function(a,b){this.vWidth=a,this.vHeight=b,this.pTex!==null&&(this.shader_particle.addVector("screenDim"),this.shader_particle.setVector("screenDim",[a,b,0]))},addParticle:function(a){this.last_particle===null?(this.particles=a,this.last_particle=a):(this.last_particle.nextParticle=a,this.last_particle=a)},genBuffer:function(){var a=c.gl;this.glPoints=a.createBuffer(),a.bindBuffer(a.ARRAY_BUFFER,this.glPoints),a.bufferData(a.ARRAY_BUFFER,this.arPoints,a.DYNAMIC_DRAW),this.hasColor&&(this.glColor=a.createBuffer(),a.bindBuffer(a.ARRAY_BUFFER,this.glColor),a.bufferData(a.ARRAY_BUFFER,this.arColor,a.DYNAMIC_DRAW))},updatePoints:function(){var a=c.gl;a.bindBuffer(a.ARRAY_BUFFER,this.glPoints),a.bufferData(a.ARRAY_BUFFER,this.arPoints,a.DYNAMIC_DRAW)},updateColors:function(){var a=c.gl;if(!this.hasColor)return;a.bindBuffer(a.ARRAY_BUFFER,this.glColor),a.bufferData(a.ARRAY_BUFFER,this.arColor,a.DYNAMIC_DRAW)},draw:function(a,d,e){var f=c.gl;this.shader_particle.use(),this.pTex!==null&&this.pTex.use(f.TEXTURE0),this.shader_particle.setMatrix("uMVMatrix",a),this.shader_particle.setMatrix("uPMatrix",d),f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,null),f.bindBuffer(f.ARRAY_BUFFER,this.glPoints),f.vertexAttribPointer(this.shader_particle.uniforms.aVertexPosition,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(this.shader_particle.uniforms.aVertexPosition),this.hasColor&&(f.bindBuffer(f.ARRAY_BUFFER,this.glColor),f.vertexAttribPointer(this.shader_particle.uniforms.aColor,3,f.FLOAT,!1,0,0),f.enableVertexAttribArray(this.shader_particle.uniforms.aColor));if(e!==b){this.numParticles=0;if(this.particles===null){f.disable(f.BLEND);return}var g=this.particles,h=null,i=0;while(g!==null){var j=this.numParticles*3,k=this.pfunc(g,e);if(k===1){this.arPoints[j]=g.pos[0],this.arPoints[j+1]=g.pos[1],this.arPoints[j+2]=g.pos[2],g.color!==null&&this.arColor!==b&&(this.arColor[j]=g.color[0],this.arColor[j+1]=g.color[1],this.arColor[j+2]=g.color[2]),this.numParticles++,i++;if(this.numParticles===this.maxPoints)break}else k===-1?h!==null&&(h.nextParticle=g.nextParticle):k===0&&i++;h=g,g=g.nextParticle}i||(this.particles=null,this.last_particle=null),this.updatePoints(),this.hasColor&&this.updateColors()}this.alpha&&(f.enable(f.BLEND),f.enable(f.DEPTH_TEST),f.depthMask(0),f.blendFunc(f.ONE,f.ONE_MINUS_SRC_COLOR)),f.drawArrays(f.POINTS,0,this.numParticles),this.alpha&&(f.disable(f.BLEND),f.depthMask(1),f.blendFunc(f.ONE,f.ONE)),this.hasColor&&f.disableVertexAttribArray(this.shader_particle.uniforms.aColor)}};var g={ParticleSystem:f,Particle:e};return g}),CubicVR.RegisterModule("PostProcess",function(a){function j(a){if(a.shader_vertex===b)return null;if(a.shader_fragment===b)return null;this.outputMode=a.outputMode===b?d.post.output.REPLACE:CubicVR.parseEnum(CubicVR.enums.post.output,a.outputMode),this.onresize=a.onresize===b?null:a.onresize,this.onupdate=a.onupdate===b?null:a.onupdate,this.init=a.init===b?null:a.init,this.enabled=a.enabled===b?!0:a.enabled,this.outputDivisor=a.outputDivisor===b?1:a.outputDivisor,this.shader=new CubicVR.Shader(a.shader_vertex,a.shader_fragment),this.shader.use(),this.shader.addUVArray("aTex"),this.shader.addVertexArray("aVertex"),this.shader.addInt("srcTex",0),this.shader.addInt("captureTex",1),this.shader.addVector("texel"),this.init!==null&&this.init(this.shader)}function k(a,d,e){var f=c.gl;this.width=a,this.height=d,this.accum=e===b?!1:!0,this.vTexel=[1/this.width,1/this.height,0],this.captureBuffer=new CubicVR.RenderBuffer(a,d,!0),this.bufferA=new CubicVR.RenderBuffer(a,d,!1),this.bufferB=new CubicVR.RenderBuffer(a,d,!1),this.bufferC=new CubicVR.RenderBuffer(a,d,!1),this.accumOpacity=1,this.accumIntensity=.3,this.accum&&(this.accumBuffer=new CubicVR.RenderBuffer(a,d,!1),this.accumBuffer.use(),f.clearColor(0,0,0,1),f.clear(f.COLOR_BUFFER_BIT),this.blur_shader=new j({shader_vertex:["attribute vec3 aVertex;","attribute vec2 aTex;","varying vec2 vTex;","void main(void)","{","vTex = aTex;","vec4 vPos = vec4(aVertex.xyz,1.0);","gl_Position = vPos;","}"].join("\n"),shader_fragment:["#ifdef GL_ES","precision highp float;","#endif","uniform sampler2D srcTex;","varying vec2 vTex;","uniform float opacity;","void main(void)","{ gl_FragColor = vec4(texture2D(srcTex, vTex).rgb, opacity);","}"].join("\n"),init:function(a){a.addFloat("opacity"),a.setFloat("opacity",1)}})),this.bufferA.use(),f.clearColor(0,0,0,1),f.clear(f.COLOR_BUFFER_BIT),this.bufferB.use(),f.clearColor(0,0,0,1),f.clear(f.COLOR_BUFFER_BIT),this.end(),this.fsQuad=this.makeFSQuad(this.width,this.height),this.shaders=[],this.copy_shader=new j({shader_vertex:["attribute vec3 aVertex;","attribute vec2 aTex;","varying vec2 vTex;","void main(void) {","vTex = aTex;","vec4 vPos = vec4(aVertex.xyz,1.0);","gl_Position = vPos;","}"].join("\n"),shader_fragment:["#ifdef GL_ES","precision highp float;","#endif","uniform sampler2D srcTex;","varying vec2 vTex;","void main(void) {","gl_FragColor = texture2D(srcTex, vTex);","}"].join("\n")}),this.resize(a,d)}function l(a,b,c){this.createBuffer(a,b,c)}var b=a.undef,c=a.GLCore,d=CubicVR.enums,e,f,g;d.post={output:{REPLACE:0,BLEND:1,ADD:2,ALPHACUT:3}};var h=[],i=[];k.prototype={setBlurOpacity:function(a){this.accumOpacity=a},setBlurIntensity:function(a){this.accumIntensity=a},makeFSQuad:function(a,b){var d=c.gl,e={},f=a,g=b,h=a/f,i=b/g;return e.vbo_points=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0,-1,-1,0,1,1,0]),e.vbo_uvs=new Float32Array([0,0,h,0,h,i,0,i,0,0,h,i]),e.gl_points=d.createBuffer(),d.bindBuffer(d.ARRAY_BUFFER,e.gl_points),d.bufferData(d.ARRAY_BUFFER,e.vbo_points,d.STATIC_DRAW),e.gl_uvs=d.createBuffer(),d.bindBuffer(d.ARRAY_BUFFER,e.gl_uvs),d.bufferData(d.ARRAY_BUFFER,e.vbo_uvs,d.STATIC_DRAW),e},destroyFSQuad:function(a){var b=c.gl;b.deleteBuffer(a.gl_points),b.deleteBuffer(a.gl_uvs)},renderFSQuad:function(a,b){var d=c.gl;a.use(),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,null),d.bindBuffer(d.ARRAY_BUFFER,b.gl_points),d.vertexAttribPointer(a.aVertex,3,d.FLOAT,!1,0,0),d.enableVertexAttribArray(a.aVertex),d.bindBuffer(d.ARRAY_BUFFER,b.gl_uvs),d.vertexAttribPointer(a.aTex,2,d.FLOAT,!1,0,0),d.enableVertexAttribArray(a.aTex),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,null),d.drawArrays(d.TRIANGLES,0,6)},addShader:function(a){this.shaders[this.shaders.length]=a,a.shader.use(),a.shader.setVector("texel",this.vTexel);if(a.outputDivisor&&a.outputDivisor!=1&&h[a.outputDivisor]===b){var c=this.width/a.outputDivisor|0,d=this.height/a.outputDivisor|0;h[a.outputDivisor]=new CubicVR.RenderBuffer(c,d,!1),i[a.outputDivisor]=this.makeFSQuad(c,d)}},resize:function(a,b){var d=c.gl;this.width=a,this.height=b,this.vTexel=[1/this.width,1/this.height,0],this.captureBuffer.destroyBuffer(),this.captureBuffer.createBuffer(this.width,this.height,!0),this.bufferA.destroyBuffer(),this.bufferA.createBuffer(this.width,this.height,!1),this.bufferB.destroyBuffer(),this.bufferB.createBuffer(this.width,this.height,!1),this.bufferC.destroyBuffer(),this.bufferC.createBuffer(this.width,this.height,!1),this.accum&&(this.accumBuffer.destroyBuffer(),this.accumBuffer
.createBuffer(this.width,this.height,!1),this.accumBuffer.use(),d.clearColor(0,0,0,1),d.clear(d.COLOR_BUFFER_BIT));for(var e in h){var f=this.width/e|0,g=this.height/e|0;h[e].destroyBuffer(),h[e].createBuffer(f,g,!1),this.destroyFSQuad(i[e]),i[e]=this.makeFSQuad(f,g)}this.inputBuffer=this.bufferA,this.outputBuffer=this.bufferB;for(var j=0,k=this.shaders.length;j<k;j++)this.shaders[j].shader.use(),this.shaders[j].shader.setVector("texel",this.vTexel),this.shaders[j].onresize!==null&&this.shaders[j].onresize(this.shaders[j].shader,this.width,this.height);this.destroyFSQuad(this.fsQuad),this.fsQuad=this.makeFSQuad(this.width,this.height)},swap:function(){var a=this.inputBuffer;this.inputBuffer=this.outputBuffer,this.outputBuffer=a},begin:function(a){var b=c.gl;this.captureBuffer.use(),a&&(this.captureBuffer.depth?b.clear(b.DEPTH_BUFFER_BIT|b.COLOR_BUFFER_BIT):b.clear(b.COLOR_BUFFER_BIT))},end:function(){var a=c.gl;a.bindFramebuffer(a.FRAMEBUFFER,null)},render:function(){var a=c.gl,b=null;this.captureBuffer.texture.use(a.TEXTURE1),this.outputBuffer.use(),this.captureBuffer.texture.use(a.TEXTURE0),a.clearColor(0,0,0,1),a.clear(a.COLOR_BUFFER_BIT),this.renderFSQuad(this.copy_shader.shader,this.fsQuad),this.end();var e=0;for(var f=0,g=this.shaders.length;f<g;f++){var j=this.shaders[f];if(!j.enabled)continue;this.swap(),this.inputBuffer.texture.use(a.TEXTURE0);var k=j.outputMode;if(k===d.post.output.REPLACE)j.outputDivisor!==1?h[j.outputDivisor].use():this.outputBuffer.use(),a.clearColor(0,0,0,1),a.clear(a.COLOR_BUFFER_BIT);else if(k===d.post.output.ADD||k===d.post.output.BLEND)j.outputDivisor!==1?h[j.outputDivisor].use():this.bufferC.use(),a.clearColor(0,0,0,1),a.clear(a.COLOR_BUFFER_BIT);j.onupdate!==null&&(j.shader.use(),j.onupdate(j.shader)),j.outputDivisor!==1?(a.viewport(0,0,h[j.outputDivisor].width,h[j.outputDivisor].height),this.renderFSQuad(j.shader,i[j.outputDivisor]),j.outputMode===d.post.output.REPLACE?(this.outputBuffer.use(),h[j.outputDivisor].texture.use(a.TEXTURE0),a.viewport(0,0,this.width,this.height),this.renderFSQuad(this.copy_shader.shader,this.fsQuad)):a.viewport(0,0,this.width,this.height)):this.renderFSQuad(j.shader,this.fsQuad),k===d.post.output.BLEND?(this.swap(),this.outputBuffer.use(),a.enable(a.BLEND),a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA),this.inputBuffer.texture.use(a.TEXTURE0),j.outputDivisor!==1?h[j.outputDivisor].texture.use(a.TEXTURE0):this.bufferC.texture.use(a.TEXTURE0),this.renderFSQuad(this.copy_shader.shader,this.fsQuad),a.disable(a.BLEND)):k===d.post.output.ADD&&(this.swap(),this.outputBuffer.use(),a.enable(a.BLEND),a.blendFunc(a.ONE,a.ONE),j.outputDivisor!==1?h[j.outputDivisor].texture.use(a.TEXTURE0):this.bufferC.texture.use(a.TEXTURE0),this.renderFSQuad(this.copy_shader.shader,this.fsQuad),a.disable(a.BLEND)),this.end(),e++}e===0?this.captureBuffer.texture.use(a.TEXTURE0):this.outputBuffer.texture.use(a.TEXTURE0),this.accum&&this.accumOpacity!==1?(this.blur_shader.shader.use(),this.blur_shader.shader.setFloat("opacity",this.accumOpacity),this.accumBuffer.use(),a.enable(a.BLEND),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),this.renderFSQuad(this.blur_shader.shader,this.fsQuad),this.end(),a.disable(a.BLEND),this.renderFSQuad(this.copy_shader.shader,this.fsQuad),a.enable(a.BLEND),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),this.blur_shader.shader.use(),this.blur_shader.shader.setFloat("opacity",this.accumIntensity),this.accumBuffer.texture.use(a.TEXTURE0),this.renderFSQuad(this.blur_shader.shader,this.fsQuad),a.disable(a.BLEND)):this.renderFSQuad(this.copy_shader.shader,this.fsQuad)}},l.prototype={createBuffer:function(b,d,e){this.fbo=null,this.depth=null,this.texture=null,this.width=parseInt(b,10),this.height=parseInt(d,10);var f=this.sizeParam(b),g=this.sizeParam(d),h=c.gl;this.fbo=h.createFramebuffer(),e&&(this.depth=h.createRenderbuffer()),h.bindFramebuffer(h.FRAMEBUFFER,this.fbo),e&&(h.bindRenderbuffer(h.RENDERBUFFER,this.depth),navigator.appVersion.indexOf("Windows")!==-1?(h.renderbufferStorage(h.RENDERBUFFER,h.DEPTH_COMPONENT16,f,g),h.framebufferRenderbuffer(h.FRAMEBUFFER,h.DEPTH_ATTACHMENT,h.RENDERBUFFER,this.depth)):(h.renderbufferStorage(h.RENDERBUFFER,h.DEPTH_STENCIL,f,g),h.framebufferRenderbuffer(h.FRAMEBUFFER,h.DEPTH_STENCIL_ATTACHMENT,h.RENDERBUFFER,this.depth))),this.texture=new CubicVR.Texture,h.bindTexture(h.TEXTURE_2D,a.Textures[this.texture.tex_id]),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.LINEAR),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,h.NEAREST),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE),h.texImage2D(h.TEXTURE_2D,0,h.RGBA,f,g,0,h.RGBA,h.UNSIGNED_BYTE,null),h.framebufferTexture2D(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0,h.TEXTURE_2D,a.Textures[this.texture.tex_id],0),h.bindFramebuffer(h.FRAMEBUFFER,null)},destroyBuffer:function(){var b=c.gl;b.bindFramebuffer(b.FRAMEBUFFER,null),b.deleteRenderbuffer(this.depth),b.deleteFramebuffer(this.fbo),b.deleteTexture(a.Textures[this.texture.tex_id]),a.Textures[this.texture.tex_id]=null},sizeParam:function(a){return a},use:function(){var a=c.gl;a.bindFramebuffer(a.FRAMEBUFFER,this.fbo)}};var m={make:k.prototype.makeFSQuad,destroy:k.prototype.destroyFSQuad,render:k.prototype.renderFSQuad},n={RenderBuffer:l,PostProcessShader:j,PostProcessChain:k,fsQuad:m};return n}),CubicVR.RegisterModule("Polygon",function(a){function d(a){var b=a.length,c=0;for(var d=b-1,e=0;e<b;d=e++)c+=a[d][0]*a[e][1]-a[e][0]*a[d][1];return c*.5}function e(a,b,c,d,e,f,g,h){var i,j,k,l,m,n,o,p,q,r,s,t,u,v,w;return i=e-c,j=f-d,k=a-e,l=b-f,m=c-a,n=d-b,o=g-a,p=h-b,q=g-c,r=h-d,s=g-e,t=h-f,w=i*r-j*q,u=m*p-n*o,v=k*t-l*s,w>=0&&v>=0&&u>=0}function f(a,b,d,f,g,h){var i,j,k,l,m,n,o,p,q;j=a[h[b]][0],k=a[h[b]][1],l=a[h[d]][0],m=a[h[d]][1],n=a[h[f]][0],o=a[h[f]][1];if(c>(l-j)*(o-k)-(m-k)*(n-j))return!1;for(i=0;i<g;i++){if(i==b||i==d||i==f)continue;p=a[h[i]][0],q=a[h[i]][1];if(e(j,k,l,m,n,o,p,q))return!1}return!0}function g(a){var b=[],c=a.length;if(c<3)return null;var e=[],g;if(0<d(a))for(g=0;g<c;g++)e[g]=g;else for(g=0;g<c;g++)e[g]=c-1-g;var h=c,i=2*h,j;for(j=0,g=h-1;h>2;){if(0>=i--)return null;var k=g;h<=k&&(k=0),g=k+1,h<=g&&(g=0);var l=g+1;h<=l&&(l=0);if(f(a,k,g,l,h,e)){var m,n,o,p,q;m=e[k],n=e[g],o=e[l],b.push(m),b.push(n),b.push(o),j++;for(p=g,q=g+1;q<h;p++,q++)e[p]=e[q];h--,i=2*h}}return b}function h(a,c,d){d===b&&(d=0);var e,f=g(c),h=CubicVR.util.repackArray(f,3,f.length/3),i=[],j=a.points.length;for(e=0,iMax=c.length;e<iMax;e++)i.push([c[e][0],c[e][1],d]);a.addPoint(i);for(e=0,iMax=h.length;e<iMax;e++)a.addFace([h[e][0]+j,h[e][1]+j,h[e][2]+j])}function i(a,b){var c=b[0]-a[0],d=b[1]-a[1];return Math.sqrt(c*c+d*d)}function j(a,b){var c=[0,0],d=i(a[0],b[0]),e=a.length,f=b.length;for(var g=0;g<e;g++)for(var h=0;h<f;h++){var j=i(a[g],b[h]);j<d&&(c[0]=g,c[1]=h,d=j)}return c}function k(a,b){var c=j(a,b),d=a.slice(c[0]);c[0]>0&&(d=d.concat(a.slice(0,c[0])));var e=b.slice(c[1]);c[1]>0&&(e=e.concat(b.slice(0,c[1]))),a.length=0,b.length=0;var f,g;for(f=0,g=d.length;f<g;f++)a.push(d[f]);for(f=0,g=e.length;f<g;f++)b.push(e[f])}function l(a,b){var c,d,e=[],f=a.length,g=b.length,h=[];for(c=0;c<f;c++)for(d=0;d<g;d++){var j=i(a[c],b[d]);e.push([j,c,d])}e.sort(function(a,b){return a[0]>b[0]});var k=4;for(c=0;c<5;c++)for(d=0;d<e.length;d++){if(c==d)continue;e[c][1]!=e[d][1]&&e[c][2]!=e[d][2]&&e[c][1]<e[d][1]&&e[c][2]<e[d][2]&&Math.abs(e[c][1]-e[d][1])<k&&Math.abs(e[c][2]-e[d][2])<k&&h.push([c,d])}h.sort(function(a,b){return e[a[0]][0]+e[a[1]][0]>e[b[0]][0]+e[b[1]][0]}),h.length>10&&(h.length=10);var l=[];for(c=0;c<h.length;c++)l.push([e[h[c][0]],e[h[c][1]]]);return l}function m(a,b){function n(a,b){return a<0&&(a+=b),a>b&&(a-=b),a}var c=l(a,b),d=[],e;if(!c.length)return null;var f=c[0][0],g=c[0][1],h=g[1]-f[1],i=g[2]-f[2],j=a.slice(f[1]);j=j.concat(a.slice(0,f[1]));var k=b.slice(f[2]);k=k.concat(b.slice(0,f[2]));var m=[];for(e=h;e<j.length;e++)m.push(j[e]);m.push(j[0]);for(e=i;e<k.length;e++)m.push(k[e]);m.push(k[0]);var o=[];for(e=0;e<=h;e++)o.push(j[e]);for(e=0;e<=i;e++)o.push(k[e]);return[m,o]}function n(a){var b=[0,0];for(var c=0;c<a.length;c++)b[0]+=a[c][0],b[1]+=a[c][1];return b[0]/=a.length,b[1]/=a.length,b}function o(a,b,c){var d=[];for(var e=0;e<a.length;e++){var f=[a[e][0]-b[0],a[e][1]-b[1]],g=Math.sqrt(f[0]*f[0]+f[1]*f[1])+c,h=Math.atan2(f[1],f[0]);d[e]=[b[0]+Math.cos(h)*g,b[1]+Math.sin(h)*g]}return d}function p(a,b,c,d,e){var f,g=a.points.length;if(b.length!=c.length)return null;var h=b.length;for(f=0;f<h;f++)a.addPoint([b[f][0],b[f][1],d]);for(f=0;f<h;f++)a.addPoint([c[f][0],c[f][1],e]);for(f=0;f<h-1;f++)a.addFace([g+f,g+f+1,g+(f+h+1),g+(f+h)]);f=h-1,a.addFace([g+f,g,g+h,g+(f+h)])}function q(a,b){var c=[];for(var d=0,e=a.length;d<e;d++){var f=a[d];c.push([f[0]+b[0],f[1]+b[1]])}return c}function r(a){this.points=a,this.cuts=[],this.result=[]}var b=a.undef,c=1e-10;r.prototype={cut:function(a){this.cuts.push(a)},toMesh:function(a){if(this.points.length===0)return;var b;a||(a=new CubicVR.Mesh),this.result=[this.points];for(b=0;b<this.cuts.length;b++){var c=this.cuts[b].points.slice(0);c=c.reverse();var d=m(this.result[0],c);this.result[0]=d[0],this.result.push(d[1])}for(b=0;b<this.result.length;b++)h(a,this.result[b]);return a.removeDoubles(),a},toExtrudedMesh:function(a,c,d){if(this.points.length===0)return;var e,f;c===b&&(c=0),d===b&&(d=0);var g=c!=d;a||(a=new CubicVR.Mesh),this.result=[this.points];for(f=0;f<this.cuts.length;f++){e=this.cuts[f].points.slice(0),e=e.reverse();var i=m(this.result[0],e);this.result[0]=i[0],this.result.push(i[1])}var j=new CubicVR.Mesh;for(f=0;f<this.result.length;f++)h(j,this.result[f],d);a.booleanAdd(j),j.flipFaces();if(g)for(f=0;f<j.points.length;f++)j.points[f][2]=c;a.booleanAdd(j);if(g){p(a,this.points,this.points,c,d);for(f=0;f<this.cuts.length;f++)e=this.cuts[f].points.slice(0),e=e.reverse(),p(a,e,e,c,d)}return a.removeDoubles(),a},toExtrudedBeveledMesh:function(a,b,c,d,e,f,g){var i=[],j=[],k,l,q,r,s,t;if(this.points.length===0)return;if(typeof b=="object"){var u=b;b=u.front||0,c=u.back||0,d=u.frontDepth||0,e=u.frontShift||0,f=u.backDepth||0,g=u.backShift||0}var v=b!==c,w=f!==0,x=d!==0;a||(a=new CubicVR.Mesh);if(x){var y=n(this.points);l=o(this.points,y,-e),this.result=[l.slice(0)]}else this.result=[this.points.slice(0)];for(r=0;r<this.cuts.length;r++)t=n(this.cuts[r].points),q=o(this.cuts[r].points,t,e),q=q.reverse(),i.push(q),s=m(this.result[0],q),this.result[0]=s[0],this.result.push(s[1]);var z=new CubicVR.Mesh;for(r=0;r<this.result.length;r++)h(z,this.result[r],b-d);z.flipFaces(),a.booleanAdd(z);if(w||x){var A=n(this.points);k=o(this.points,A,-g),this.result=[k.slice(0)];for(r=0;r<this.cuts.length;r++)t=n(this.cuts[r].points),q=o(this.cuts[r].points,t,g),q=q.reverse(),j.push(q),s=m(this.result[0],q),this.result[0]=s[0],this.result.push(s[1]);z=new CubicVR.Mesh;for(r=0;r<this.result.length;r++)h(z,this.result[r],c+f)}else{for(r=0;r<z.points.length;r++)z.points[r][2]=c;z.flipFaces()}a.booleanAdd(z),x&&p(a,l,this.points,b-d,b),v&&p(a,this.points,this.points,b,c),w&&p(a,this.points,k,c,c+f);for(r=0;r<i.length;r++)q=this.cuts[r].points.slice(0).reverse(),x&&p(a,i[r],q,b-d,b),v&&p(a,q,q,b,c),w&&p(a,q,j[r],c,c+f);return a.removeDoubles(),a}};var s={triangulate2D:g,toMesh:h,findNearPair:j,subtract:m,addOffset:q},t={polygon:s,Polygon:r};return t}),CubicVR.RegisterModule("Primitives",function(a){function h(b,d,e,g,h,i){var j=a.mat4,k=a.vec3,l=[],m,n=[0,1,0],o=[1,0,0],p=[0,0,0],q=b.points.length,r,s,t,u,v;m=0;for(r=0;r<f;r+=f/e){if(m===e)break;o=[Math.cos(r),0,Math.sin(r)];for(s=0,t=d.length;s<t;s++)p=k.add(k.multiply(o,d[s][0]),k.multiply(n,d[s][1])),l[m]===c&&(l[m]=[]),l[m].push(p);m++}var w=null;h!==c&&(w=h.getResult!==c?h.getResult():h);for(s=0;s<e;s++)for(u=0,v=d.length;u<v;u++)w?b.addPoint(j.vec3_multiply(l[s][u],w)):b.addPoint(l[s][u]);typeof g=="string"&&(g=new a.Material(g)),b.setFaceMaterial(g);for(u=0;u<e;u++)for(s=0,t=d.length-1;s<t;s++){var x=s+d.length*u,y=s+d.length*((u+1)%e);k.equal(b.points[q+x],b.points[q+y])?b.addFace([q+x+1,q+y+1,q+y]):k.equal(b.points[q+x+1],b.points[q+y+1])?b.addFace([q+x,q+x+1,q+y]):b.addFace([q+x,q+x+1,q+y+1,q+y])}if(i!==c){var z=null;i.apply!==c?z=i:i&&(z=new a.UVMapper(i)),z!==null&&(b.calcFaceNormals(),z.apply(b,g))}}function i(b,d,e,f,g){var h=a.mat4,i=d*.5,j=b.points.length;typeof e=="string"&&(e=new a.Material(e)),b.setFaceMaterial(e);if(f!==c){var k=f.getResult!==c?f.getResult():f;b.addPoint([h.vec3_multiply([i,-i,0],k),h.vec3_multiply([i,i,0],k),h.vec3_multiply([-i,i,0],k),h.vec3_multiply([-i,-i,0],k)])}else b.addPoint([[i,-i,0],[i,i,0],[-i,i,0],[-i,-i,0]]);b.addFace([[j+0,j+1,j+2,j+3],[j+3,j+2,j+1,j+0]]);if(g!==c){var l=null;g.apply!==c?l=g:g&&(l=new a.UVMapper(g)),l!==null&&(b.calcFaceNormals(),l.apply(b,e))}}function j(b,d,e,f,g){var h=a.mat4,i,j,k;typeof d=="object"?(i=d[0]/2,j=d[1]/2,k=d[2]/2):i=j=k=d/2;var l=b.points.length;typeof e=="string"&&(e=new a.Material(e)),b.setFaceMaterial(e);if(f!==c){var m=f.getResult!==c?f.getResult():f;b.addPoint([h.vec3_multiply([i,-j,k],m),h.vec3_multiply([i,j,k],m),h.vec3_multiply([-i,j,k],m),h.vec3_multiply([-i,-j,k],m),h.vec3_multiply([i,-j,-k],m),h.vec3_multiply([i,j,-k],m),h.vec3_multiply([-i,j,-k],m),h.vec3_multiply([-i,-j,-k],m)])}else b.addPoint([[i,-j,k],[i,j,k],[-i,j,k],[-i,-j,k],[i,-j,-k],[i,j,-k],[-i,j,-k],[-i,-j,-k]]);b.addFace([[l+0,l+1,l+2,l+3],[l+7,l+6,l+5,l+4],[l+4,l+5,l+1,l+0],[l+5,l+6,l+2,l+1],[l+6,l+7,l+3,l+2],[l+7,l+4,l+0,l+3]]);if(g!==c){var n=null;g.apply!==c?n=g:g&&(n=new a.UVMapper(g)),n!==null&&(b.calcFaceNormals(),n.apply(b,e))}}function k(b,c,d,e,g,h,i,j){var k=[],l=d-c,m=c+l/2,n=f/g,o=0;for(var p=0;p<=g;p++)k.push([m+Math.cos(o)*l,Math.sin(o)*l,0]),o+=n;a.genLatheObject(b,k,e,h,i,j)}function l(b,c,d,e,f,g,h){a.genLatheObject(b,[[0,-d/2,0],[c/2,-d/2,0],[0,d/2,0]],e,f,g,h)}function m(b,c,d,e,f,g,h){a.genLatheObject(b,[[0,-d/2,0],[c,-d/2,0],[c,d/2,0],[0,d/2,0]],e,f,g,h)}function n(b,c,d,e,f,h,i){var j=[];e=(e/=2)|0,d|=0;var k=Math.PI/e,l=-g;for(var m=0;m<=e;m++)j.push([Math.cos(l)*c,Math.sin(l)*c,0]),l+=k;a.genLatheObject(b,j,d,f,h,i)}function o(b){return typeof b=="string"&&(b=a.get(b,a.Material)),b===c?new a.Material:b.use?b:typeof b=="object"?new a.Material(b):new a.Material}function p(b){if(b===c)return c;if(typeof b=="array")return b;if(typeof b=="object")return b.getResult?b.getResult():!b.position&&!b.rotation&&!b.scale?c:a.mat4.transform(b.position,b.rotation,b.scale)}function q(b){return typeof b=="string"&&(b=a.get(b)),b===c?c:b.apply?b:typeof b=="object"?new a.UVMapper(b):c}var b=a.enums,c=a.undef,d=a.GLCore,e=a.util,f=2*Math.PI,g=Math.PI/2,r={lathe:function(b){var d,e,f,g,i,j;return b.points==c?null:(d=b.mesh!==c?b.mesh:new a.Mesh(b.name!==c?b.name:c),e=o(b.material),f=p(b.transform),g=q(b.uvmapper||b.uv),j=b.divisions!==c?b.divisions:24,h(d,b.points,j,e,f,g),d)},box:function(b){var d,e,f,g,h;return d=b.mesh!==c?b.mesh:new a.Mesh(b.name!==c?b.name:c),e=o(b.material),f=p(b.transform),g=q(b.uvmapper||b.uv),h=b.size!==c?b.size:1,j(d,h,e,f,g),d},plane:function(b){var d,e,f,g,h;return d=b.mesh!==c?b.mesh:new a.Mesh(b.name!==c?b.name:c),e=o(b.material),f=p(b.transform),g=q(b.uvmapper||b.uv),h=b.size!==c?b.size:1,i(d,h,e,f,g),d},sphere:function(b){var d,e,f,g,h,i,j;return d=b.mesh!==c?b.mesh:new a.Mesh(b.name!==c?b.name:c),e=o(b.material),f=p(b.transform),g=q(b.uvmapper||b.uv),h=b.radius!==c?b.radius:1,i=b.lon!==c?b.lon:24,j=b.lat!==c?b.lat:24,n(d,h,i,j,e,f,g),d},torus:function(b){var d,e,f,g,h,i,j,l;return d=b.mesh!==c?b.mesh:new a.Mesh(b.name!==c?b.name:c),e=o(b.material),f=p(b.transform),g=q(b.uvmapper||b.uv),h=b.innerRadius!==c?b.innerRadius:.75,i=b.outerRadius!==c?b.outerRadius:1,j=b.lon!==c?b.lon:24,l=b.lat!==c?b.lat:24,k(d,h,i,j,l,e,f,g),d},cone:function(b){var d,e,f,g,h,i,j;return d=b.mesh!==c?b.mesh:new a.Mesh(b.name!==c?b.name:c),e=o(b.material),f=p(b.transform),g=q(b.uvmapper||b.uv),h=b.base!==c?b.base:1,i=b.height!==c?b.height:1,j=b.lon!==c?b.lon:24,l(d,h,i,j,e,f,g),d},cylinder:function(b){var d,e,f,g,h,i,j;return d=b.mesh!==c?b.mesh:new a.Mesh(b.name!==c?b.name:c),e=o(b.material),f=p(b.transform),g=q(b.uvmapper||b.uv),h=b.radius!==c?b.radius:1,i=b.height!==c?b.height:1,j=b.lon!==c?b.lon:24,m(d,h,i,j,e,f,g),d}},s={genPlaneObject:i,genBoxObject:j,genLatheObject:h,genTorusObject:k,genConeObject:l,genCylinderObject:m,genSphereObject:n,primitives:r};return s}),CubicVR.RegisterModule("Renderer",function(a){function e(c,d,e,f,g,h,i){var j=!1;g=g||!1,h=h||!1;if(c.compiled===null)return;var k=0,l=a.GLCore.gl,m,n=f===b?0:f.length,o,p,q,r=0,s,t=null,u=c.instanceMaterials||c.materials,v=(c.wireframe||i)&&c.compiled.line_elements_ref,w=v?c.compiled.line_elements_ref:c.compiled.elements_ref,x=!1,y,z,A;l.depthFunc(l.LEQUAL),e===b&&(e=cubicvr_identity);for(var B=0,C=w.length;B<C;B++){v&&c.wireframeMaterial?t=c.wireframeMaterial:t=u[B];var D=0,E=!1;if(t.opacity<1&&g){j=!0;continue}if(h&&t.opacity>=1)continue;t.opacity!==1?(l.enable(l.BLEND),l.depthMask(0),l.blendFunc(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA)):(l.depthMask(1),l.disable(l.BLEND),l.blendFunc(l.ONE,l.ONE));for(var F=0,G=w[B].length;F<G;F++){s=w[B][F][0],E=!1;var H=w[B][F][1];D+=H;if(!t.visible){k+=H*2,D-=H;continue}if(!c.segment_state[s])if(D>H){k+=H*2,D-=H;if(!n)t.use(0,0),l.uniformMatrix4fv(t.shader[0][0].matrixModelView,!1,d.mvMatrix),l.uniformMatrix4fv(t.shader[0][0].matrixProjection,!1,d.pMatrix),l.uniformMatrix4fv(t.shader[0][0].matrixObject,!1,e),l.uniformMatrix3fv(t.shader[0][0].matrixNormal,!1,d.nMatrix),x||(t.bindObject(c,t.shader[0][0]),x=t.shader[0][0].vertexTexCoord!=-1,v&&l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,c.compiled.gl_line_elements)),v?l.drawElements(l.LINES,D,l.UNSIGNED_SHORT,k):l.drawElements(l.TRIANGLES,D,l.UNSIGNED_SHORT,k);else{y=0,z=!1;for(y=0;y<n;){m=n-y,m>a.MAX_LIGHTS&&(m=a.MAX_LIGHTS),y>0&&!z&&(l.enable(l.BLEND),l.blendFunc(l.ONE,l.ONE),l.depthFunc(l.EQUAL),z=!0),o=b,q=f[y],A=q.light_type;for(r=0;r<m;r++)if(f[r+y].light_type!=A){m=r;break}t.use(q.light_type,m),o=t.shader[q.light_type][m],l.uniformMatrix4fv(o.matrixModelView,!1,d.mvMatrix),l.uniformMatrix4fv(o.matrixProjection,!1,d.pMatrix),l.uniformMatrix4fv(o.matrixObject,!1,e),l.uniformMatrix3fv(o.matrixNormal,!1,d.nMatrix),x||(t.bindObject(c,o),x=o.vertexTexCoord!=-1,v&&l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,c.compiled.gl_line_elements));for(r=0;r<m;r++)f[r+y].setupShader(o,r);v?l.drawElements(l.LINES,D,l.UNSIGNED_SHORT,k):l.drawElements(l.TRIANGLES,D,l.UNSIGNED_SHORT,k),y+=m}z&&(l.disable(l.BLEND),l.depthFunc(l.LEQUAL))}k+=D*2,D=0,E=!0}else k+=D*2,D=0}if(!E&&c.segment_state[s]&&t.visible){if(!n)t.use(0,0),l.uniformMatrix4fv(t.shader[0][0].matrixModelView,!1,d.mvMatrix),l.uniformMatrix4fv(t.shader[0][0].matrixProjection,!1,d.pMatrix),l.uniformMatrix4fv(t.shader[0][0].matrixObject,!1,e),l.uniformMatrix3fv(t.shader[0][0].matrixNormal,!1,d.nMatrix),x||(t.bindObject(c,t.shader[0][0]),x=t.shader[0][0].vertexTexCoord!=-1,v&&l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,c.compiled.gl_line_elements)),v?l.drawElements(l.LINES,D,l.UNSIGNED_SHORT,k):l.drawElements(l.TRIANGLES,D,l.UNSIGNED_SHORT,k);else{y=0,z=!1;for(y=0;y<n;){m=n-y,m>a.MAX_LIGHTS&&(m=a.MAX_LIGHTS),y>0&&!z&&(l.enable(l.BLEND),l.blendFunc(l.ONE,l.ONE),l.depthFunc(l.EQUAL),z=!0),o=b,q=f[y],A=q.light_type;for(r=0;r<m;r++)if(f[r+y].light_type!=A){m=r;break}t.use(q.light_type,m),o=t.shader[q.light_type][m],l.uniformMatrix4fv(o.matrixModelView,!1,d.mvMatrix),l.uniformMatrix4fv(o.matrixProjection,!1,d.pMatrix),l.uniformMatrix4fv(o.matrixObject,!1,e),l.uniformMatrix3fv(o.matrixNormal,!1,d.nMatrix),x||(t.bindObject(c,o),x=o.vertexTexCoord!=-1,v&&l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,c.compiled.gl_line_elements));for(r=0;r<m;r++)f[r+y].setupShader(o,r);v?l.drawElements(l.LINES,D,l.UNSIGNED_SHORT,k):l.drawElements(l.TRIANGLES,D,l.UNSIGNED_SHORT,k),y+=m}z&&(l.disable(l.BLEND),l.depthFunc(l.LEQUAL))}k+=D*2}}return t&&o?t.clearObject(c,o):t.clearObject(c,null),l.depthMask(1),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,null),j}var b=a.undef,c=a.enums,d=a.GLCore,f={renderObject:e};return f}),CubicVR.RegisterModule("EventHandler",function(a){function i(a){return a=CubicVR.parseEnum(c.event,a),a===b?(h("For custom events use CubicVR.registerEvent('event_name'); and use the resulting CubicVR.enums.event.EVENT_NAME for type checks and 'event_name' for construction."),!1):!isNaN(parseInt(a,10))&&(a>=c.event.EVENT_MAX||a<0)?(h("Unknown event ID passed: "+a),!1):a}function j(a){a=a.toUpperCase();if(c.event[a]!==b){h("Error, event '"+a+"' is already registered.");return}c.event[a]=c.event.ENUM_MAX,c.event.ENUM_MAX++}function k(a){a=a||{},this.name=a.name,a.id=i(a.id)||c.event.TICK,this.id=a.id,this.interval=a.interval||0,this.enabled=a.enabled||!0,this.action=a.action||null,this.properties=a.properties||{},this.event_properties=a.event_properties||{},this.buffered=a.buffered||!1,this.weight=a.weight===b?-1:a.weight,this.subject=null,this.t_sleep=0,this.t_active=0,this.t_updatecall=0,this.t_update=0,this.t_last=0,this.t_rest=0,this.t_resting=0,this.n_updates=0,this.break_chain=!1}function l(){this.events=[],this.eventProperties=[],this.eventPropertyCount=[],this.eventHandled=[],this.listeners=[],this.listenerNames=[],this.eventParameters=[]}var b=a.undef,c=CubicVR.enums,d=a.GLCore,e=CubicVR.aabb,f=CubicVR.primitives,g=CubicVR.mat4,h=a.log;c.event={TICK:0,MOVE:1,MATRIX_UPDATE:2,OCTREE_ADJUST:3,COLLIDE:4,CONTACT:5,CONTACT_ADD:6,CONTACT_REMOVE:7,CONTACT_GHOST:8,RIGID_REST:9,RIGID_AWAKE:10,ENUM_MAX:11},k.prototype={getName:function(){return this.name},setName:function(a){this.name=a},getSubject:function(){return this.subject},setSubject:function(a){this.subject=a},getId:function(){return this.id},setId:function(a){this.id=a},isEnabled:function(){return this.enabled},disable:function(){this.setEnabled(!1)},enable:function(){this.setEnabled(!0)},setEnabled:function(a){a&&!this.enabled&&(this.t_sleep=0,this.t_active=0,this.t_updatecall=0,this.t_update=0,this.t_last=0,this.t_rest=0,this.t_resting=0,this.n_updates=0,this.break_chain=!1),this.enabled=a},isBuffered:function(){return this.buffered},setBuffered:function(a){this.buffered=a},setInterval:function(a){this.interval=a},getInterval:function(){return this.interval},setAction:function(a){this.action=a},getAction:function(){return this.action},getProperties:function(){return this.properties},setProperties:function(a){this.properties=a},getProperty:function(a){return this.properties[a]},setProperty:function(a,b){this.properties[a]=b},setEventProperties:function(a){this.event_properties=a},getEventProperties:function(){return this.event_properties},getEventProperty:function(a){return this.event_properties[a]},setEventProperty:function(a,b){this.properties[a]=b},getTimeSleeping:function(){return this.t_sleep},getTimeActive:function(){return this.t_active},getTimeUpdated:function(){return this.t_update},getSeconds:function(){return this.getTimeUpdated()},getRestInterval:function(){return this.t_rest},getLastUpdateSeconds:function(){return this.t_last},setRestInterval:function(a){this.t_rest=a},getUpdateCount:function(){return this.n_updates},breakChain:function(a){this.break_chain=!0},isChainBroken:function(){return this.break_chain},rest:function(a){this.setRestInterval(a||0)},awake:function(){this.t_rest=0},update:function(a,b){if(!this.enabled)return!1;var c=0,d=!0;return this.n_updates===0?(this.t_update=a,this.t_updatecall=a,c=1/60):a!==this.t_update?(this.t_rest||(this.t_last=a-this.t_update,this.t_update=a),c=a-this.t_updatecall,this.t_updatecall=a):d=!1,this.t_rest>0?(d&&(this.t_resting+=c,this.t_rest-=c,this.t_rest<0&&(this.t_rest=0)),d&&this.n_updates++,!1):(d&&(this.t_active+=this.t_last,!this.t_rest&&this.interval&&(this.t_rest=this.interval),this.n_updates++),this.callEvent(b),!0)},callEvent:function(a){return this.action?this.action(this,a):!1}},l.prototype={addEvent:function(a){a.callEvent||(a=new k(a));var b=a.getId();return this.eventProperties[b]||(this.eventProperties[b]={}),this.listeners[b]=this.listeners[b]||0,this.listeners[b]++,this.events.push(a),this.listenerNames.indexOf(b)===-1&&this.listenerNames.push(b),a},removeEvent:function(a){if(this.lockState){this.lockRemovals||(this.lockRemovals=[]),this.lockRemovals.indexOf(a)==-1&&this.lockRemovals.push(a);return}var b=this.events.indexOf(a);if(b===-1)return;var c=a.getId();this.events.splice(b,1),this.listeners[c]--;if(!this.listeners[c]){this.eventHandled[c]=!0,this.eventParameters[c]={},this.eventProperties[c]=[],this.eventPropertyCount[c]=0;var d=this.listenerNames.indexOf(c);d>=0&&this.listenerNames.splice(d,1)}},getProperties:function(a){return this.eventParameters[a]=this.eventParameters[a]||{},this.eventParameters[a]},setProperties:function(a,b){this.eventParameters[a]=b},getProperty:function(a,b){return this.getProperties(a)[b]},setProperty:function(a,b,c){this.getProperties(a)[b]=c},hasEvent:function(a){return!!this.listeners[a]},triggerEvent:function(a,c){if(!this.listeners[a])return null;this.eventProperties[a]==b&&(this.eventProperties[a]=[]);var d=this.eventProperties[a];this.eventPropertyCount[a]===b&&(this.eventPropertyCount[a]=0);var e=this.eventPropertyCount[a];return e>20&&console.log("Warning, event "+a+" count > 20: "+e),c&&d?(d[e]=c,this.eventPropertyCount[a]++):(d[e]=d[e]||{},this.eventPropertyCount[a]++),this.eventHandled[a]=!1,d[e]},update:function(a){var b,d,e,f,g,h,i,j;this.hasEvent(c.event.TICK)&&this.eventPropertyCount[c.event.TICK]===0&&!!(j=this.triggerEvent(c.event.TICK))&&(j.time=a,j.handler=this),this.lockState=!0;for(b=0,d=this.events.length;b<d;b++){g=this.events[b],h=g.getId();var k=this.eventPropertyCount[h],l=!1,m=!1;if(k){var n=this.eventProperties[h];if(g.isEnabled()){if(g.isBuffered()){n.length=k,g.setEventProperties(n),l=l||g.update(a,this);if(g.isChainBroken()){g.breakChain(!1);break}}else for(e=0,f=k;e<f;e++){g.setEventProperties(n[b]),l=l||g.update(a,this);if(g.isChainBroken()){g.breakChain(!1);break}}m=!0}}if(l||!m)this.eventHandled[h]=!0}for(b=0,d=this.listenerNames.length;b<d;b++)h=this.listenerNames[b],this.eventHandled[h]&&(this.eventPropertyCount[h]=0);this.lockState=!1;if(this.lockRemovals&&this.lockRemovals.length){for(b=0,d=this.lockRemovals.length;b<d;b++)this.removeEvent(this.lockRemovals[b]);this.lockRemovals.length=0}}};var m={Event:k,EventHandler:l,registerEvent:j,validateEvent:i};return m}),CubicVR.RegisterModule("Scene",function(a){function i(a,b){return a.light_type-b.light_type}function j(c,d){var f=null,h,i;c!==b&&c!==null?c.compile?f={}:(f=a.get(c)||{},c=null):f={},this.morphWeight=f.morphWeight||0,this.morphSource=f.morphSource||-1,this.morphTarget=f.morphTarget||-1,this.position=f.position===b?[0,0,0]:f.position,this.rotation=f.rotation===b?[0,0,0]:f.rotation,this.scale=f.scale===b?[1,1,1]:f.scale,this.shadowCast=f.shadowCast===b?!0:f.shadowCast,this.wireframe=f.wireframe||!1,this.motion=f.motion===b?null:a.get(f.motion,a.Motion)||null,this.obj=f.mesh?a.get(f.mesh,a.Mesh):c?a.get(c,a.Mesh):null,this.name=f.name===b?d!==b?d:null:f.name,this.properties=a.get(f.properties)||{},this.children=null,this.parent=null;var j=f.children||f.child||f.sceneObject||f.sceneObjects;if(j){if(j&&!j.length||typeof j=="string")j=[j];if(j.length)for(h=0,i=j.length;h<i;h++)this.bindChild(a.get(j[h],a.SceneObject))}this.drawn_this_frame=!1,this.lposition=[0,0,0],this.lrotation=[0,0,0],this.lscale=[0,0,0],this.lMatrix=g.identity(),this.tMatrix=g.identity(),this.dirty=!0,this.aabb=[],this.id=-1,this.octree_leaves=[],this.octree_common_root=null,this.octree_aabb=[[0,0,0],[0,0,0]],e.reset(this.octree_aabb,[0,0,0]),this.ignore_octree=!1,this.visible=!0,this.culled=!0,this.was_culled=!0,this.dynamic_lights=[],this.static_lights=[],this.matrixLock=!1,this.instanceMaterials=null,this.eventHandler=null}function l(b,c,d,e,f,g){var h,i;this.frames=0,this.sceneObjects=[],this.sceneObjectsByName=[],this.sceneObjectsById=[],this.lights=[],this.global_lights=[],this.dynamic_lights=[],this.pickables=[],this.stats=[],this.cameras=[],this.camerasByName=[],this.collect_stats=!1,this.shadows_updated=!1;if(typeof b=="object"||typeof b=="string"){var j=a.get(b);this.octree=j.octree,this.skybox=j.skybox||null,this.name=j.name||"scene"+k,this.wireframe=j.wireframe||!1,this.destroy=j.destroy||function(){},this.update=j.update||function(){},this.enable=j.enable||function(){},this.disable=j.disable||function(){};var l=j.setup&&j.setup(this)||{};this.update=l.update||this.update,this.enable=l.enable||this.enable,this.disable=l.disable||this.disable,this.destroy=l.destroy||this.destroy;var m=j.sceneObjects||j.sceneObject||j.objects;if(m&&!m.length||typeof m=="string")m=[m];if(m&&m.length)for(h=0,i=m.length;h<i;h++)this.bindSceneObject(a.get(m[h],a.SceneObject));var n=j.lights||j.light;if(n&&!n.length||typeof n=="string")n=[n];if(n&&n.length)for(h=0,i=n.length;h<i;h++)this.bindLight(a.get(n[h],a.Light));var o=j.cameras||j.camera;if(o&&!o.length||typeof o=="string")o=[o];if(o&&o.length){for(h=0,i=o.length;h<i;h++)this.bindCamera(a.get(o[h],a.Camera));this.camera=this.cameras[0]}o||(this.camera=new a.Camera(j.width,j.height,j.fov,j.nearclip,j.farclip))}else this.skybox=null,this.octree=g,this.name="scene"+k,this.camera=new a.Camera(b,c,d,e,f),this.wireframe=!1;this.paused=!1,++k}function m(){this.meshBin={},this.imageBin={},this.meshMap={},this.imageMap={},this.imageBinPtr={},this.meshBinPtr={}}function n(b){var c=b.texture,d=b.mapping,e=this;this.mapping=null,this.ready=!1,this.texture=null,this.onready=function(){c.onready=null;var b=1/a.Images[e.texture.tex_id].width,d=1/a.Images[e.texture.tex_id].height;e.mapping===null&&(e.mapping=[[1/3,.5,2/3-b,1],[0,.5,1/3,1],[0,0,1/3-b,.5],[2/3,0,1,.5],[2/3+b,.5,1,1],[1/3,0,2/3,.5]]);var f=new a.Material({name:"skybox",textures:{color:c}}),g=new a.Mesh;g.sky_mapping=e.mapping,a.primitives.box({mesh:g,size:1,material:f,uvmapper:{projectionMode:a.enums.uv.projection.SKY,scale:[1,1,1]}}),g.prepare(),e.scene_object=new a.SceneObject(g),e.ready=!0},c&&(typeof c=="string"?c=new a.Texture(c,null,null,null,this.onready):c.loaded||(c.onready=this.onready),this.texture=c,d&&(this.mapping=d,this.onready()))}var b=a.undef,c=a.enums,d=a.GLCore,e=a.aabb,f=a.primitives,g=a.mat4,h=0;j.prototype={isWireframe:function(){return this.wireframe},setWireframe:function(a){this.wireframe=a},addEvent:function(b){this.eventHandler||(this.eventHandler=new a.EventHandler);var c=this.eventHandler.addEvent(b);return c.setSubject(this),c},removeEvent:function(a){if(!this.eventHandler)return;this.eventHandler.removeEvent(a)},hasEvents:function(){return!!this.eventHandler},getEventHandler:function(){return this.eventHandler},setMesh:function(a){this.obj=a},getMesh:function(){return this.obj},getProperties:function(){return this.properties},setProperties:function(a){this.properties=a},getProperty:function(a){return this.properties[a]},setProperty:function(a,b){this.properties[a]=b},getInstanceMaterials:function(){if(!this.obj)return null;if(this.instanceMaterials)return this.instanceMaterials;this.instanceMaterials=[];for(var a=0,b=this.obj.materials.length;a<b;a++)this.instanceMaterials[a]=this.obj.materials[a].clone();return this.instanceMaterials},getInstanceMaterial:function(a){var b=this.getInstanceMaterials();for(var c=0,d=b.length;c<d;c++)if(b[c].name==a)return b[c];return null},setMorphSource:function(a){this.morphSource=a},setMorphTarget:function(a){this.morphTarget=a},getMorphSource:function(){return this.morphSource},getMorphTarget:function(){return this.morphTarget},setMorphWeight:function(a){this.morphWeight=a},morphTargetCount:function(){return this.obj.morphTargets!==null?this.obj.morphTargets.length:0},setMatrixLock:function(a){this.matrixLock=a},getMatrixLock:function(){return this.matrixLock},setMatrix:function(a){if(a){this.tMatrix=a.slice(0),this.matrixLock=!0;if(this.hasEvents()){var b=this.getEventHandler();if(b.hasEvent(c.event.MATRIX_UPDATE)){var d=b.triggerEvent(c.event.MATRIX_UPDATE);d.matrix=this.tMatrix}}}else this.matrixLock=!1},doTransform:function(d){var e=a.vec3;if(!this.matrixLock&&(!e.equal(this.lposition,this.position)||!e.equal(this.lrotation,this.rotation)||!e.equal(this.lscale,this.scale)||d!==b)){d!==b?this.tMatrix=d.slice(0):g.identity(this.tMatrix),g.identity(this.lMatrix),g.translate(this.position[0],this.position[1],this.position[2],this.lMatrix),g.rotate(this.rotation[0],this.rotation[1],this.rotation[2],this.lMatrix),(this.scale[0]!==1||this.scale[1]!==1||this.scale[2]!==1)&&g.scale(this.scale[0],this.scale[1],this.scale[2],this.lMatrix),g.multiply(this.tMatrix.slice(0),this.lMatrix,this.tMatrix),this.lposition[0]=this.position[0],this.lposition[1]=this.position[1],this.lposition[2]=this.position[2],this.lrotation[0]=this.rotation[0],this.lrotation[1]=this.rotation[1],this.lrotation[2]=this.rotation[2],this.lscale[0]=this.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&&(d<k||f<l||g<m||h>n||i>o||j>p)){for(var q=0;q<this.octree_leaves.length;++q)this.octree_leaves[q].remove(this);this.octree_leaves=[],this.static_lights=[];var r=this.octree_common_root;this.octree_common_root=null;if(r!==null){for(;;){if(!!r.contains_point(a[0])&&!!r.contains_point(a[1]))break;if(r._root===b||r._root===null)break;r=r._root}e.reset(this.octree_aabb,this.position),r.insert(this)}}},bindChild:function(a){this.children===null&&(this.children=[]),a.parent=this,this.children.push(a)},control:function(a,b,d){a===c.motion.POS?this.position[b]=d:a===c.motion.SCL?this.scale[b]=d:a===c.motion.ROT&&(this.rotation[b]=d)},getAABB:function(){var c=a.mat4,d=a.vec3;if(this.dirty){var e=new Array(8);this.doTransform();var f,g;if(this.obj){if(!this.obj.bb)return this.aabb=[d.add([-1,-1,-1],this.position),d.add([1,1,1],this.position)],this.aabb;f=this.obj.bb[0],g=this.obj.bb[1]}if(!this.obj||f===b||g===b)return this.aabb=[d.add([-1,-1,-1],this.position),d.add([1,1,1],this.position)],this.aabb;var h=f,i=d.subtract(g,f);e[0]=[h[0],h[1],h[2]],e[1]=[h[0],h[1],h[2]+i[2]],e[2]=[h[0]+i[0],h[1],h[2]],e[3]=[h[0]+i[0],h[1],h[2]+i[2]],e[4]=[h[0],h[1]+i[1],h[2]],e[5]=[h[0],h[1]+i[1],h[2]+i[2]],e[6]=[h[0]+i[0],h[1]+i[1],h[2]],e[7]=[h[0]+i[0],h[1]+i[1],h[2]+i[2]];var j;j=c.vec3_multiply(e[0],this.tMatrix),f=[j[0],j[1],j[2]],g=[j[0],j[1],j[2]];for(var k=1;k<8;++k)j=c.vec3_multiply(e[k],this.tMatrix),f[0]>j[0]&&(f[0]=j[0]),f[1]>j[1]&&(f[1]=j[1]),f[2]>j[2]&&(f[2]=j[2]),g[0]<j[0]&&(g[0]=j[0]),g[1]<j[1]&&(g[1]=j[1]),g[2]<j[2]&&(g[2]=j[2]);this.aabb[0]=f,this.aabb[1]=g,this.dirty=!1}return this.aabb}};var k=0;l.prototype={isWireframe:function(){return this.wireframe},setWireframe:function(a){this.wireframe=a},attachOctree:function(a){this.octree=a,a.init&&a.init(this);var c=this.lights;this.lights=[];for(var d=0,f=c.length;d<f;d++)this.bindLight(c[d]);var g=this.sceneObjects;if(this.octree!==b)for(var i=0,j=g.length;i<j;++i){var k=g[i];if(k.obj===null)continue;k.id<0&&(k.id=h,++h),this.sceneObjectsById[k.id]=k,e.reset(k.octree_aabb,k.position),this.octree.insert(k),(k.octree_common_root===undefined||k.octree_common_root===null)&&log("!!",k.name,"octree_common_root is null")}},setSkyBox:function(a){this.skybox=a},getSceneObject:function(a){return this.sceneObjectsByName[a]},bindSceneObject:function(a,c,d){if(this.sceneObjects.indexOf(a)!=-1)return;this.sceneObjects.push(a),c!==b&&c&&this.pickables.push(a),a.name!==null&&(this.sceneObjectsByName[a.name]=a),this.octree!==b&&(d===b||d==="true")&&(a.id<0&&(a.id=h,++h),this.sceneObjectsById[a.id]=a,e.reset(a.octree_aabb,a.position),this.octree.insert(a));if(a.children)for(var f=0,g=a.children.length;f<g;f++)this.bindSceneObject(a.children[f],c,d);return a},removeLight:function(a){var b=this.lights.indexOf(a);b>=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<e;d++)this.removeSceneObject(a.children[d])},bindLight:function(a,d){this.lights.push(a),this.octree!==b&&(d===b||d==="true")&&(a.method===c.light.method.GLOBAL?this.global_lights.push(a):(a.method===c.light.method.DYNAMIC&&this.dynamic_lights.push(a),this.octree.insert_light(a))),this.lights=this.lights.sort(i)},bindCamera:function(a){this.cameras.indexOf(a)===-1&&(this.cameras.push(a),this.camerasByName[a.name]=a),this.camera=a},removeCamera:function(a){return typeof a!="object"&&(a=this.getCamera(camName)),this.cameras.indexOf(a)===-1&&(this.cameras.push(a),this.camerasByName[a.name]=a),a},bind:function(b){b instanceof a.Light?this.bindLight(b):b instanceof a.SceneObject?this.bindSceneObject(b):b instanceof a.Camera?this.bindCamera(b):b instanceof a.Vehicle?b.bindToScene(this):b instanceof a.RigidBody&&this.bindSceneObject(b.getSceneObject())},remove:function(b){b instanceof a.Light?this.removeLight(b):b instanceof a.SceneObject?this.removeSceneObject(b):b instanceof a.Camera?this.removeCamera(b):b instanceof bsae.RigidBody&&this.removeSceneObject(b.getSceneObject())},setCamera:function(a){if(!a)return;typeof a!="object"&&(a=this.getCamera(a)),this.camera=a},getCamera:function(a){return a===b?this.camera:this.camerasByName[a]},evaluate:function(a){var b,c;for(b=0,c=this.sceneObjects.length;b<c;b++){if(!this.sceneObjects[b].motion)continue;this.sceneObjects[b].motion.apply(a,this.sceneObjects[b])}this.camera.motion!==null&&(this.camera.targetSceneObject!==null&&(this.camera.target=this.camera.targetSceneObject.position),this.camera.motion.apply(a,this.camera));for(b=0,c=this.lights.length;b<c;b++){var d=this.lights[b];d.motion!==null&&d.motion.apply(a,d)}},prepareTransforms:function(a){var b,c;if(!a){if(this.sceneObjects.length===0)return;for(b=0,c=this.sceneObjects.length;b<c;++b)this.prepareTransforms(this.sceneObjects[b])}else{a.doTransform();if(a.children)for(b=0,c=a.children.length;b<c;b++)a.children[b].doTransform(a.tMatrix),this.prepareTransforms(a.children[b])}},updateShadows:function(b){var e=d.gl,f=!1;b=b||!1;if(this.shadows_updated)return!1;b||this.doTransform(),this.shadows_updated=!0;if(!a.features.lightShadows)return;var g=e.getParameter(e.FRAMEBUFFER_BINDING),h=!1,i=e.getParameter(e.VIEWPORT);for(var j=0,k=this.lights.length;j<k;j++){var l=this.lights[j];if(l.light_type==c.light.type.SPOT_SHADOW||l.light_type==c.light.type.SPOT_SHADOW_PROJECTOR||l.light_type==c.light.type.AREA){h=!0;var m=[new a.Light(c.light.type.DEPTH_PACK)];l.light_type===c.light.type.AREA&&(l.areaCam=this.camera,l.updateAreaLight()),d.shadow_near=l.dummyCam.nearclip,d.shadow_far=l.dummyCam.farclip,l.shadowBegin();for(var n=0,o=this.sceneObjects.length;n<o;n++){var p=this.sceneObjects[n];if(p.parent)continue;if(p.visible===!1||p.shadowCast===!1)continue;this.renderSceneObject(p,l.dummyCam,m,!1,!0)}l.shadowEnd(),g&&e.bindFramebuffer(e.FRAMEBUFFER,g)}}h&&e.viewport(i[0],i[1],i[2],i[3])},updateCamera:function(){var a=d.gl;this.camera.manual===!1&&(this.camera.targeted?this.camera.lookat(this.camera.position[0],this.camera.position[1],this.camera.position[2],this.camera.target[0],this.camera.target[1],this.camera.target[2],0,1,0):this.camera.calcProjection()),d.depth_alpha_near=this.camera.nearclip,d.depth_alpha_far=this.camera.farclip},resize:function(a,b){this.camera&&this.camera.setDimensions(a,b)},doTransform:function(){var a=this.octree!==b;for(var c=0,e=this.sceneObjects.length;c<e;c++){var f=this.sceneObjects[c];if(f.parent!==null)continue;this.prepareTransforms(f);if(a){lights=[],f.dirty&&f.obj!==null&&f.adjust_octree();if(f.visible===!1||a&&(f.ignore_octree||f.drawn_this_frame===!0||f.culled===!0))continue;lights=f.dynamic_lights,lights=lights.concat(f.static_lights),lights=lights.concat(this.global_lights),this.collect_stats&&(this.lights_rendered=Math.max(lights.length,this.lights_rendered),this.lights_rendered===lights.length&&(lights_list=lights),++this.objects_rendered),lights.length===0?lights=[d.emptyLight]:lights=lights.sort(i),f.drawn_this_frame=!0}else if(f.visible===!1)continue}},renderSceneObject:function(c,e,f,g,h,i,j){var k=!1,l=d.gl;g=g!==b&&g,h=h||!1,i=i||!1;if(c.visible&&c.obj){c.scale[0]<0&&(k=!k),c.scale[1]<0&&(k=!k),c.scale[2]<0&&(k=!k),k&&l.cullFace(l.FRONT);var m=c.obj;m.morphTargets!==null&&(c.morphSource!==-1&&m.setMorphSource(c.morphSource),c.morphTarget!==-1&&m.setMorphTarget(c.morphTarget),c.morphWeight!==null&&(m.morphWeight=c.morphWeight)),c.instanceMaterials&&m.bindInstanceMaterials(c.instanceMaterials),a.renderObject(m,e,c.tMatrix,f,h,i,this.isWireframe()||c.isWireframe())&&j&&j.push(c),c.instanceMaterials&&m.bindInstanceMaterials(null),k&&l.cullFace(l.BACK),k=!1}var n=c.children;if(g&&n)for(var o=0,p=n.length;o<p;o++){var q=n[o];this.renderSceneObject(q,e,f,!0,h,i,j)}},runEvents:function(a){var b,c;this.lockState=!0,!a.getSeconds||(a=a.getSeconds());for(b=0,c=this.sceneObjects.length;b<c;b++){var d=this.sceneObjects[b];d.hasEvents()&&d.getEventHandler().update(a)}this.lockState=!1;if(this.lockRemovals)for(b=0,c=this.lockRemovals.length;b<c;b++)this.removeSceneObject(this.lockRemovals[b]);this.lockRemovals=null},render:function(c){++this.frames,c=c||{},c.postProcess&&c.postProcess.begin(!c.postBuffer);var e=d.gl,f,h=this.octree!==b;this.lights_rendered=0,h&&(this.octree.reset_node_visibility(),this.octree.cleanup(),f=this.octree.get_frustum_hits(this.camera),this.lights_rendered=f.lights.length),this.doTransform(),this.updateCamera(),this.updateShadows(!0),this.shadows_updated=!1;var i,j;for(i=0,j=this.lights.length;i<j;i++){var k=this.lights[i];k.prepare(this.camera)}this.objects_rendered=0;var l=[],m=[],n=this.lights;for(i=0,j=this.sceneObjects.length;i<j;i++){var o=this.sceneObjects[i];if(o.visible===!1||o.parent!==null)continue;this.renderSceneObject(o,this.camera,n,!0,!0,!1,m)}for(i=0,j=m.length;i<j;i++)this.renderSceneObject(m[i],this.camera,n,!1,!1,!0);this.collect_stats&&(this.stats["objects.num_rendered"]=this.objects_rendered,this.stats["lights.num_rendered"]=this.lights_rendered,this.stats["lights.rendered"]=l,this.stats["lights.num_global"]=this.global_lights.length,this.stats["lights.num_dynamic"]=this.dynamic_lights.length);if(this.skybox!==null&&this.skybox.ready===!0){e.cullFace(e.FRONT);var p=this.camera.farclip*2/Math.sqrt(3);this.camera.parent?this.skybox.scene_object.position=g.vec3_multiply(this.camera.position,this.camera.parent.tMatrix):this.skybox.scene_object.position=[this.camera.position[0],this.camera.position[1],this.camera.position[2]],this.skybox.scene_object.scale=[p,p,p],this.skybox.scene_object.doTransform(),a.renderObject(this.skybox.scene_object.obj,this.camera,this.skybox.scene_object.tMatrix,[]),e.cullFace(e.BACK)}c.postProcess&&(c.postProcess.end(),c.postBuffer||c.postProcess.render())},bbRayTest:function(b,c,d){var e=a.vec3,f,g,h=[];c.length===2?c=this.camera.unProject(c[0],c[1]):c=e.add(b,c),f=b,g=c;for(var i in this.pickables)if(this.pickables.hasOwnProperty(i)){var j=this.pickables[i];if(j.visible!==!0)continue;var k,l,m=j.getAABB();k=m[0],l=m[1];var n=.2;l[0]-k[0]<n&&(k[0]-=n/2,l[0]+=n/2),l[1]-k[1]<n&&(k[1]-=n/2,l[1]+=n/2),l[2]-k[2]<n&&(k[2]-=n/2,l[2]+=n/2);var o=e.multiply(e.add(k,l),.5),p=e.getClosestTo(f,g,o),q=e.length(e.subtract(p,o)),r=(p[0]>=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.dist<b.dist?-1:1}),h}},m.prototype={addMesh:function(a,c,d){this.meshBin[a]===b&&(this.meshBin[a]=[],this.meshBinPtr[a]===b&&(this.meshBinPtr[a]=0)),this.meshMap[c]===b&&(this.meshMap[c]=d,this.meshBin[a].push(d))},addImage:function(a,c,d){this.imageBin[a]===b&&(this.imageBin[a]=[],this.imageBinPtr[a]===b&&(this.imageBinPtr[a]=0)),this.imageMap[c]===b&&(this.imageMap[c]=d,this.imageBin[a].push(d))},getMeshes:function(a){return this.meshBin[a]},getImages:function(a){return this.imageBin[a]},rewindMeshes:function(a){this.meshBinPtr[a]=0},rewindImages:function(a){this.imageBinPtr[a]=0},getNextMesh:function(a){var b=this.meshBinPtr[a];return b<this.meshBin[a].length?(this.meshBinPtr[a]++,this.meshBin[a][b]):null},loadNextMesh:function(a){var b=this.getNextMesh(a);return b!==null?(b.compiled===null&&(b.triangulateQuads(),b.compile(),b.clean()),!0):!1},isMeshBinEmpty:function(a){return this.meshBinPtr[a]===this.meshBin[a].length},loadNextImage:function(a){var b=this.getNextImage(a);b!==null&&(b.src=b.deferredSrc)},getNextImage:function(a){var b=this.imageBinPtr[a];return b<this.imageBin[a].length?(this.imageBinPtr[a]++,this.imageBin[a][b]):null},isImageBinEmpty:function(a){return this.imageBinPtr[a]===this.imageBin[a].length}};var o={Scene:l,SceneObject:j,SkyBox:n,DeferredBin:m};return o}),CubicVR.RegisterModule("ScenePhysics",function(a){function m(a,b){b.setX(a[0]),b.setY(a[1]),b.setZ(a[2])}function n(a,b){b[0]=a.x(),b[1]=a.y(),b[2]=a.z()}function o(a,b){b.setX(a.x),b.setY(a.y),b.setZ(a.z),b.setW(a.w)}function p(a,b){b.x=a.x(),b.y=a.y(),b.z=a.z(),b.w=a.w()}function q(a){return new Ammo.btVector3(a[0],a[1],a[2])}function r(a){var b=new Ammo.btQuaternion;return b.setEulerZYX(a[2]*(Math.PI/180),a[1]*(Math.PI/180),a[0]*(Math.PI/180)),b}function s(a){return h.fromEuler(a[0],a[1],a[2]),[h.x,h.y,h.z,h.w]}function t(a){return[a.x(),a.y(),a.z()]}function v(b){var c=b.getCollisionMap();if(c.getResult())return c.getResult();var d=c.getShapes(),f,h,i,j,k,l,n,o=[],p=null;for(h=0,i=d.length;h<i;h++){f=d[h],p=null;if(f.type===e.collision.shape.BOX)p=new Ammo.btBoxShape(new Ammo.btVector3(f.size[0]/2,f.size[1]/2,f.size[2]/2));else if(f.type===e.collision.shape.SPHERE)p=new Ammo.btSphereShape(f.radius);else if(f.type===e.collision.shape.CAPSULE)p=new Ammo.btCapsuleShape(f.radius,f.height);else if(f.type===e.collision.shape.CYLINDER)p=new Ammo.btCylinderShape(new Ammo.btVector3(f.size[0]/2,f.size[1]/2,f.size[2]/2));else if(f.type===e.collision.shape.CONE)p=new Ammo.btConeShape(f.radius,f.height);else if(f.type===e.collision.shape.MESH){n=f.mesh;var s=new Ammo.btTriangleMesh;l=f.size;var t=new Ammo.btVector3(0,0,0),u=new Ammo.btVector3(0,0,0),v=new Ammo.btVector3(0,0,0),w=n.getMaterials();for(j=0,k=n.faces.length;j<k;j++){var x=n.faces[j],y=w[x.material];if(!y.collision)continue;if(x.points.length!==3)continue;t.setValue(n.points[x.points[0]][0]*l[0],n.points[x.points[0]][1]*l[1],n.points[x.points[0]][2]*l[2]),u.setValue(n.points[x.points[1]][0]*l[0],n.points[x.points[1]][1]*l[1],n.points[x.points[1]][2]*l[2]),v.setValue(n.points[x.points[2]][0]*l[0],n.points[x.points[2]][1]*l[1],n.points[x.points[2]][2]*l[2]),s.addTriangle(t,u,v)}b.getMass()===0||b.getType()==e.physics.body.STATIC||b.getType()==e.physics.body.GHOST?(b.setMass(0),p=new Ammo.btBvhTriangleMeshShape(s,!0)):p=new Ammo.btConvexTriangleMeshShape(s,!0)}else if(f.type===e.collision.shape.CONVEX_HULL){n=f.mesh,l=f.size;var z=new Ammo.btVector3(0,0,0);p=new Ammo.btConvexHullShape;for(j=0,k=n.points.length;j<k;j++)m([n.points[j][0]*l[0],n.points[j][1]*l[1],n.points[j][2]*l[2]],z),p.addPoint(z)}else if(f.type===e.collision.shape.HEIGHTFIELD){n=f.mesh;var A=0,B=0,C=0,D=0,E;if(!(f.landscape&&f.landscape instanceof a.Landscape))continue;A=f.landscape.divisions_w,C=f.landscape.divisions_h,B=f.landscape.size_w,D=f.landscape.size_h,E=f.landscape.getMesh().points;var F=1,G=100,H=!1,I=Ammo.allocate(E.length*4,"float",Ammo.ALLOC_NORMAL);for(j=0,k=A*C;j<k;j++)Ammo.setValue(I+(j<<2),E[j][1],"float");var J={FLOAT:0,DOUBLE:1,INTEGER:2,SHORT:3,FIXEDPOINT88:4,UCHAR:5};p=new Ammo.btHeightfieldTerrainShape(A,C,I,1,-G,G,F,J.FLOAT,H),p.setUseDiamondSubdivision(!0);var K=new Ammo.btVector3(B/A,1,D/C);p.setLocalScaling(K)}p&&(f.margin!==0&&p.setMargin(f.margin),o.push({cShape:f,btShape:p}))}var L=null;if(o.length===1)L=o[0].btShape;else if(o.length>1){g=new Ammo.btTransform,L=new Ammo.btCompoundShape(!1);for(h=0,i=o.length;h<i;h++)g.setIdentity(),g.setOrigin(q(o[h].cShape.position)),g.setRotation(r(o[h].cShape.rotation)),L.addChildShape(g,o[h].btShape)}return c.setResult(L),L}function z(a){this.setManifold(a)}var b=a.undef,c=a.util,d=a.vec3,e=a.enums,f=a.nop;e.physics={body:{STATIC:0,DYNAMIC:1,GHOST:2,SOFT:3},constraint:{P2P:0},collision_flags:{STATIC_OBJECT:1,KINEMATIC_OBJECT:2,NO_CONTACT_RESPONSE:4,CUSTOM_MATERIAL_CALLBACK:8,CHARACTER_OBJECT:16,DISABLE_VISUALIZE_OBJECT:32},rigid_flags:{DISABLE_WORLD_GRAVITY:1},collision_types:{COLLISION_OBJECT:1,RIGID_BODY:2,GHOST_OBJECT:3,SOFT_BODY:4,HF_FLUID:5},collision_states:{ACTIVE_TAG:1,ISLAND_SLEEPING:2,WANTS_DEACTIVATION:3,DISABLE_DEACTIVATION:4,DISABLE_SIMULATION:5}};var g,h,i,k,l,u=[],w=function(c){this.type=a.parseEnum(e.physics.body,c.type),this.mass=c.mass!==b?c.mass:this.type?1:0,this.size=c.size||[1,1,1],this.restitution=c.restitution||(this.type?0:1),this.friction=c.friction||1,this.collision=c.collision,this.collision&&!this.collision.getShapes&&(this.collision=new a.CollisionMap(this.collision)),this.blocker=c.blocker||!1},x=function(b,c,d){var e;!b.position&&b.sceneObject&&(e=b,b=b.sceneObject,c=e.properties,d=e.collision),e=a.get(e)||{},this.properties=new a.RigidProperties(c?a.get(c):{collision:d}),this.collisionEvents=[],this.parent=null,this.init_position=b.position.slice(0),this.init_rotation=b.rotation.slice(0),this.init_linearVelocity=this.linearVelocity=e.linearVelocity||[0,0,0],this.init_angularVelocity=this.angularVelocity=e.angularVelocity||[0,0,0],this.init_impulse=this.impulse=e.impulse||[0,0,0],this.init_impulsePosition=this.impulsePosition=e.impulsePosition||[0,0,0],this.rigid_flags=null,this.collision_flags=null,this.sceneObject=b,this.transform=new Ammo.btTransform,this.transform.setIdentity(),this.transform.setOrigin(q(this.init_position)),this.transform.setRotation(r(this.init_rotation)),this.shape=null,this.motionState=new Ammo.btDefaultMotionState(this.transform),this.localInertia=new Ammo.btVector3(0,0,0),this.bodyInit=null,this.body=null,this.ghost=null,this.noDeactivate=!1};x.prototype={getProperties:function(){return this.properties},getSceneObject:function(){return this.sceneObject},getInitialPosition:function(){return this.init_position},getInitialRotation:function(){return this.init_rotation},setInitialPosition:function(){this.init_position=init_position_in},setInitialRotation:function(){this.init_rotation=init_rotation_in},getType:function(){return this.properties.type},getMass:function(){return this.properties.mass},getRestitution:function(){return this.properties.restitution},getCollisionMap:function(){return this.properties.collision},setMass:function(a){this.properties.mass=a,this.body&&this.body.setMassProps(a,this.localInertia)},setRestitution:function(a){this.restitution=a},getBody:function(){if(!this.body&&!this.ghost){var b=this.getCollisionShape();this.getType()===e.physics.body.GHOST?(this.body=null,this.ghost=new Ammo.btGhostObject,this.ghost.setCollisionShape(b),this.ghost.setWorldTransform(this.transform),this.ghost._cvr_rigidbody=this):(this.getMass()&&b.calculateLocalInertia(this.getMass(),this.localInertia),this.bodyInit=new Ammo.btRigidBodyConstructionInfo(this.getMass(),this.motionState,b,this.localInertia),this.friction&&this.bodyInit.set_m_friction(this.friction),this.body=new Ammo.btRigidBody(this.bodyInit),this.getRestitution()&&this.body.setRestitution(this.getRestitution()),m(this.linearVelocity,k),this.body.setLinearVelocity(k),m(this.angularVelocity,k),this.body.setAngularVelocity(k),a.vec3.equal([0,0,0],this.impulse)||(m(this.impulse,k),m(this.impulsePosition,l),this.body.applyImpulse(k,l)),this.rigid_flags&&this.body.setFlags(this.rigid_flags),this.collision_flags&&this.body.setFlags(this.collision_flags),this.body._cvr_rigidbody=this)}return this.body||this.ghost},updateSceneObject:function(a){if(!this.body)return;if(this.body.isActive()||a){this.body.getMotionState().getWorldTransform(g);var b=g.getOrigin();b.x!=b.x?console.log("origin is NaN"):(this.sceneObject.position[0]=b.x(),this.sceneObject.position[1]=b.y(),this.sceneObject.position[2]=b.z());var c=g.getRotation();h.x=c.x(),h.y=c.y(),h.z=c.z(),h.w=c.w();if(h.x!=h.x)console.log("rotation is NaN");else{var d=h.toEuler();this.sceneObject.rotation[0]=d[0],this.sceneObject.rotation[1]=d[1],this.sceneObject.rotation[2]=d[2]}return!0}},reset:function(a,b){if(!this.body)return;var c=this.body.getWorldTransform().getOrigin();m(this.init_position,c);var d=this.body.getWorldTransform().getRotation();this.resetMotion();var e=s(this.init_rotation);i.setX(e[0]),i.setY(e[1]),i.setZ(e[2]),i.setW(e[3]),this.body.getWorldTransform().setRotation(i),this.activate()},resetMotion:function(){m(this.init_linearVelocity,k),this.body.setLinearVelocity(k),m(this.init_angularVelocity,k),this.body.setAngularVelocity(k),a.vec3.equal([0,0,0],this.init_impulse)||(m(this.init_impulse,k),m(this.init_impulsePosition,l),this.body.applyImpulse(k,l))},getCollisionShape:function(){return this.shape||(this.shape=v(this)),this.shape},setAngularVelocity:function(a){this.angularVelocity=a;if(!this.body)return;m(a,k),this.body.setAngularVelocity(k)},setGravity:function(a){this.gravity=a;if(!this.body)return;m(a,k),this.body.setGravity(k)},getGravity:function(){return this.gravity&&!this.body?this.gravity:t(this.body.getGravity())},setLinearVelocity:function(a){this.linearVelocity=a;if(!this.body)return;m(a,k),this.body.setLinearVelocity(k)},applyImpulse:function(b,c){this.impulse=b||[0,0,0],this.impulsePosition=c||[0,0,0];if(!this.body)return;a.vec3.equal([0,0,0],b)||(m(this.impulse,k),m(this.impulsePosition,l),this.body.applyImpulse(k,l))},applyForce:function(b,c){if(!this.body)return;a.vec3.equal([0,0,0],b)||(m(b,k),m(c,l),this.body.applyImpulse(k,l))},getAngularVelocity:function(){return t(this.body.getAngularVelocity())},getLinearVelocity:function(){return t(this.body.getLinearVelocity())},activate:function(a){this.noDeactivate=a||!1,this.body&&(this.noDeactivate&&this.body.setActivationState(e.physics.collision_states.DISABLE_DEACTIVATION),this.body.activate())},setAngularFactor:function(a){this.body&&a!==b&&(a.length||(a=[a,a,a]),m(a,k),this.body.setAngularFactor(k))},isActive:function(){return this.body?this.body.isActive():!1},isStatic:function(){return this.properties.type==e.physics.body.STATIC},setRigidFlags:function(a){this.rigid_flags=a,this.body&&this.body.setFlags(a)},setCollisionFlags:function(b){b=a.parseEnum(e.physics.collision_flags,b),this.collision_flags=b,this.body&&this.body.setCollisionFlags(b)},setPosition:function(a){this.position=a;if(!this.body&&!this.ghost)return;m(a,k),this.body&&this.body.getCenterOfMassTransform().setOrigin(k),this.ghost&&this.ghost.getWorldTransform().setOrigin(k)},getRotation:function(){if(!this.body&&!this.ghost)return this.init_rotation;this.body&&this.body.getCenterOfMassTransform().getRotation(i),this.ghost&&this.ghost.getWorldTransform().getRotation(i);var b=new a.Quaternion;return p(i,b),b},setRotation:function(a){this.rotation=a.toEuler();if(!this.body&&!this.ghost)return;o(a,i),this.body&&this.body.getCenterOfMassTransform().setRotation(i),this.ghost&&this.ghost.getWorldTransform().setRotation(i)},getRotationEuler:function(){if(!this.body&&!this.ghost)return this.init_rotation;var b=new a.Quaternion;return this.body&&this.body.getCenterOfMassTransform().getRotation(i),this.ghost&&this.ghost.getWorldTransform().getRotation(i),p(i,b),b.toEuler()},setRotationEuler:function(a){this.rotation=a,i.setEuler(this.rotation[2]*(Math.PI/180),this.rotation[1]*(Math.PI/180),this.rotation[0]*(Math.PI/180)),this.body&&this.body.getCenterOfMassTransform().setRotation(i),this.ghost&&this.body.getWorldTransform().setRotation(i)}};var y=function(c){c=c||{},this.ctype=a.parseEnum(e.physics.constraint,c.ctype)||e.physics.constraint.P2P,this.strength=c.strength||.1,this.maxImpulse=c.maxImpulse||0,this.rigidBodyA=c.rigidBodyA||c.rigidBody||null,this.rigidBodyB=c.rigidBodyB||null,this.positionA=c.positionA||[0,0,0],this.positionB=c.positionB||c.position||[0,0,0],this.damping=c.damping!=b?c.damping:1,this.btConstraint=null,this.localPivotA=q(this.positionA),this.localPivotB=q(this.positionB)};y.prototype={getConstraint:function(){if(!this.btConstraint){if(!this.rigidBodyA)return!1;this.ctype===e.physics.constraint.P2P&&(this.rigidBodyA&&this.rigidBodyB?this.btConstraint=new Ammo.btPoint2PointConstraint(this.rigidBodyA.getBody(),this.rigidBodyB.getBody(),this.localPivotA,this.localPivotB):this.btConstraint=new Ammo.btPoint2PointConstraint(this.rigidBodyA.getBody(),this.localPivotA),this.btConstraint.get_m_setting().set_m_tau(this.strength),this.btConstraint.get_m_setting().set_m_damping(this.damping),this.maxImpulse&&this.btConstraint.get_m_setting().set_m_impulseClamp(this.maxImpulse),this.btConstraint===Ammo.NULL&&(this.btConstraint=null))}return this.btConstraint},setStrength:function(a){this.strength=a,this.btConstraint&&this.btConstraint.get_m_setting().set_m_tau(this.strength)},setDamping:function(a){this.damping=a,this.btConstraint&&this.btConstraint.get_m_setting().set_damping(this.damping)},setMaxImpulse:function(a){this.maxImpulse=a,this.btConstraint&&this.btConstraint.get_m_setting().set_impulseClamp(this.maxImpulse)},getStrength:function(){return this.strength},setPosition:function(a){this.positionB=a,this.btConstraint&&(m(this.positionB,this.localPivotB),this.btConstraint.setPivotB(this.localPivotB))},getPosition:function(){return this.positionB}},z.prototype={getContact:function(a){var b=this.manifold.getContactPoint(j);if(b===Ammo.NULL)return null;var c={impulse:b.getAppliedImpulse(),lifetime:b.getLifeTime(),friction:b.get_m_combinedFriction(),positionA:t(b.getPositionWorldOnA()),positionB:t(b.getPositionWorldOnB())};return c},setManifold:function(a){this.numContacts=a.getNumContacts(),this.manifold=a}};var A=function(b,c){this.rigidObjects=[],this.ghostObjects=[],this.contactObjects=[],this.collisionObjects=[],this.active_count=0,this.collisionConfiguration=new Ammo.btDefaultCollisionConfiguration,this.dispatcher=new Ammo.btCollisionDispatcher(this.collisionConfiguration),this.overlappingPairCache=new Ammo.btDbvtBroadphase,this.solver=new Ammo.btSequentialImpulseConstraintSolver,this.dynamicsWorld=new Ammo.btDiscreteDynamicsWorld(this.dispatcher,this.overlappingPairCache,this.solver,this.collisionConfiguration),this.dynamicsWorld.setGravity(new Ammo.btVector3(0,-10,0)),this.overlappingPairCache.getOverlappingPairCache().setInternalGhostPairCallback(new Ammo.btGhostPairCallback);if(!g||!h)k=new Ammo.btVector3,l=new Ammo.btVector3,g=new Ammo.btTransform,h=new a.Quaternion,i=new Ammo.btQuaternion};A.prototype={addConstraint:function(a){var b=a.getConstraint();return b?(this.dynamicsWorld.addConstraint(b),a.rigidBodyA.activate(!0),!0):!1},removeConstraint:function(a){var b=a.getConstraint();return b?(this.dynamicsWorld.removeConstraint(b),!0):!1},setGravity:function(a){m(a,k),this.dynamicsWorld.setGravity(k)},bindSceneObject:function(b,c){var d=new a.RigidBody(b,c);this.rigidObjects.push(d);var e=d.getBody();return d.activate(),this.dynamicsWorld.addRigidBody(d.getBody()),d.updateSceneObject(!0),d},bind:function(b){b instanceof a.Vehicle?b.initBody(this):b instanceof a.RigidBody&&this.bindRigidBody(b)},remove:function(b){b instanceof a.RigidBody&&this.removeRigidBody(b)},bindRigidBody:function(a){if(a.getType()===e.physics.body.GHOST){if(this.ghostObjects.indexOf(a)!==-1)return;this.ghostObjects.push(a);var b=a.getBody();a.properties.blocker||b.setCollisionFlags(b.getCollisionFlags()+e.physics.collision_flags.NO_CONTACT_RESPONSE),this.dynamicsWorld.addCollisionObject(b)}else{if(this.rigidObjects.indexOf(a)!==-1)return;this.rigidObjects.push(a);var c=a.getBody();a.activate(),this.dynamicsWorld.addRigidBody(c),a.updateSceneObject(!0)}var d,f;!!(d=a.getSceneObject())&&!!(f=d.getEventHandler())&&(f.hasEvent(e.event.CONTACT)&&this.contactObjects.push(a),f.hasEvent(e.event.COLLIDE)&&this.collisionObjects.push(a))},removeRigidBody:function(a){if(a.getType()===e.physics.body.GHOST){if(this.ghostObjects.indexOf(a)===-1)return;this.ghostObjects.splice(this.ghostObjects.indexOf(a),1);var b=a.getBody();this.dynamicsWorld.removeCollisionObject(b)}else{if(this.rigidObjects.indexOf(a)===-1)return;this.rigidObjects.splice(this.rigidObjects.indexOf(a),1);var c=a.getBody();this.dynamicsWorld.removeRigidBody(c)}var d,f;!!(d=a.getSceneObject())&&!!(f=d.getEventHandler())&&(f.hasEvent(e.event.CONTACT)&&this.contactObjects.indexOf(a)!==-1&&this.contactObjects.splice(this.contactObjects.indexOf(a),1),f.hasEvent(e.event.COLLIDE)&&this.collisionObjects.indexOf(a)!==-1&&this.collisionObjects.splice(this.collisionObjects.indexOf(a),1))},getActiveCount:function(){return this.active_count},stepSimulation:function(a,b){this.dynamicsWorld.stepSimulation(a,b||2);var c=0;for(var d=0,e=this.rigidObjects.length;d<e;d++){var f=this.rigidObjects[d];f.updateSceneObject()&&c++}this.active_count=c},triggerEvents:function(){var a,b,c,d,f,g=this.dynamicsWorld;if(this.contactObjects.length){var h=g.getDispatcher().getNumManifolds();for(a=0;a<h;a++){var i=g.getDispatcher().getManifoldByIndexInternal(a),j=Ammo.wrapPointer(i.getBody0(),Ammo.btRigidBody),k=j._cvr_rigidbody||null,l=Ammo.wrapPointer(i.getBody1(),Ammo.btRigidBody),m=l._cvr_rigidbody||null;!k||!(f=k.getSceneObject())||!(c=f.getEventHandler())||!c.hasEvent(e.event.CONTACT)?!!m&&m.isStatic()&&!!(f=m.getSceneObject())&&!!(c=f.getEventHandler())&&c.hasEvent(e.event.CONTACT)&&(d=c.triggerEvent(e.event.CONTACT),d.other=k,d.self=m,d.contacts?d.contacts.setManifold(i):d.contacts=new z(i)):(d=c.triggerEvent(e.event.CONTACT),d.self=k,d.other=m,d.contacts?d.contacts.setManifold(i):d.contacts=new z(i))}}var n=this.collisionObjects.length;for(a=0;a<n;a++){var o=this.collisionObjects[a];if(!!(f=o.getSceneObject())&&!!(c=f.getEventHandler())&&c.hasEvent(e.event.COLLIDE)){var p=c.getProperties(e.event.COLLIDE),q=p.collidesWith;p.mf=p.mf||[],p.alg=p.alg||[];if(q&&q.length){var r=[],s=o.getBody();for(a=0,iMax=q.length;a<iMax;a++){var t=q[a],u=t.getBody();p.mf[a]||(p.mf[a]=new Ammo.btManifoldResult(s,u)),p.alg[a]||(p.alg[a]=this.dynamicsWorld.getDispatcher().findAlgorithm(s,u)),p.alg[a].processCollision(s,u,this.dynamicsWorld.getDispatchInfo(),p.mf[a]),p.mf[a].getPersistentManifold().getNumContacts()>0&&(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;a<v;a++){var w=this.ghostObjects[a];f=w.getSceneObject();if(f){c=f.getEventHandler();if(c&&c.hasEvent(e.event.CONTACT_GHOST)){var x=w.getBody(),y=x.getNumOverlappingObjects();if(y){d=c.triggerEvent(e.event.CONTACT_GHOST),d.contacts=d.contacts||[],d.contacts.length>y&&(d.contacts.length=y);for(b=0;b<y;b++){var A=Ammo.btRigidBody.prototype.upcast(x.getOverlappingObject(b));d.contacts[b]=A._cvr_rigidbody||null}}}}}},reset:function(){for(var a=0,b=this.rigidObjects.length;a<b;a++)this.rigidObjects[a].reset()},getRayHit:function(a,b,c,d){var e,f;e=q(a),f=q(b),c=c||!1,d=d||!1;var g=new Ammo.ClosestRayResultCallback(e,f);this.dynamicsWorld.rayTest(e,f,g);if(g.hasHit()){body=Ammo.btRigidBody.prototype.upcast(g.get_m_collisionObject());if(body!==Ammo.NULL&&!(body.isStaticObject()&&!c||body.isKinematicObject()&&!d)){var h=body,i=g.get_m_hitPointWorld(),j=h.getCenterOfMassTransform().inverse().op_mul(i),k=h._cvr_rigidbody;return k?(Ammo.destroy(g),{position:t(i),localPosition:t(j),rigidBody:k,ammoBody:h}):(Ammo.destroy(g),{position:t(i),localPosition:t(j),rigidBody:null,ammoBody:h})}}Ammo.destroy(g)}};var B={ScenePhysics:A,Constraint:y,RigidProperties:w,RigidBody:x,vec3bt_copy:m,btvec3_copy:n,quatbt_copy:o,btquat_copy:p};return B}),CubicVR.RegisterModule("Shader",function(a){function j(b,d){var f=a.util,i,j,k,l,m=c.gl;this.uniforms=[],this.uniform_type=[],this.uniform_typelist=[],this.success=!0,this.vertexLog="",this.fragmentLog="",b.indexOf("\n")!==-1?(k=b,i=g(c.gl,b,"x-shader/x-vertex")):(i=h(c.gl,b),i===null&&(k=f.getURL(b),i=g(c.gl,k,"x-shader/x-vertex"))),m.getShaderParameter(i,m.COMPILE_STATUS)||(this.vertexLog=m.getShaderInfoLog(i),this.success=!1),d.indexOf("\n")!==-1?(l=d,j=g(c.gl,d,"x-shader/x-fragment")):(j=h(c.gl,d),j===null&&(l=f.getURL(d),j=g(c.gl,l,"x-shader/x-fragment"))),m.getShaderParameter(j,m.COMPILE_STATUS)||(this.fragmentLog=m.getShaderInfoLog(j),this.success=!1);if(this.success)this.shader=m.createProgram(),m.attachShader(this.shader,i),m.attachShader(this.shader,j),m.linkProgram(this.shader),c.gl.getProgramParameter(this.shader,m.LINK_STATUS)||(e("Error linking shader:\n"+m.getProgramInfoLog(this.shader)),this.success=!1);else{var n=f.multiSplit(this.vertexLog,";\n"),o=f.multiSplit(this.fragmentLog,";\n");n.length&&this.dumpErrors(n,k),o.length&&this.dumpErrors(o,l)}}function l(b){this._update=b.update||null,this._init=b.init||null,this._vertex=a.get(b.vertex)||null,this._fragment=a.get(b.fragment)||null,this._bindings=[],this._shader=null,this._shaderInfo=null,this._shaderVars=null,this._initialized=!1;var c=(this._vertex||"")+(this.
_fragment||"");c.trim()!==""?this._hasDepthPack=/\s\!?LIGHT_DEPTH_PASS\s/.test(c):this._hasDepthPack=!1}var b=a.undef,c=a.GLCore,d=a.enums,e=a.log,f=a.util;d.shader={map:{COLOR:1,SPECULAR:2,NORMAL:4,BUMP:8,REFLECT:16,ENVSPHERE:32,AMBIENT:64,ALPHA:128,COLORMAP:256},uniform:{MATRIX:0,VECTOR:1,FLOAT:2,ARRAY_VERTEX:3,ARRAY_UV:4,ARRAY_FLOAT:5,INT:6}};var g=function(a,b,c){var d;if(c==="x-shader/x-fragment")d=a.createShader(a.FRAGMENT_SHADER);else{if(c!=="x-shader/x-vertex")return null;d=a.createShader(a.VERTEX_SHADER)}return a.shaderSource(d,b),a.compileShader(d),d},h=function(a,b){var c=document.getElementById(b);if(!c)return null;var d="",e=c.firstChild;while(e)e.nodeType===3&&(d+=e.textContent),e=e.nextSibling;var f;if(c.type==="x-shader/x-fragment")f=a.createShader(a.FRAGMENT_SHADER);else{if(c.type!=="x-shader/x-vertex")return null;f=a.createShader(a.VERTEX_SHADER)}return a.shaderSource(f,d),a.compileShader(f),f};j.prototype={isCompiled:function(){return this.success},dumpErrors:function(a,b,c){c=c||"Error on line",c+=" ";var d="ERROR: ",e=b.split("\n");for(var f=0,g=a.length;f<g;f++){var h=a[f];if(h.indexOf(d)===0){var i=h.substr(d.length).trim(),j=i.substr(0,i.indexOf(" "));i=i.substr(j.length);var k=j.split(":"),l=parseInt(k[1],10),m=e[l-1];console.log(l+"> "+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;i<iMax;i++){var d=c[i];if(d.indexOf("#define")===0){var e=d.split(" ");e.length>2&&(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<e;d++){i=p[d],s===-1&&i.indexOf("struct")===0?s=d:t===-1&&s!==-1&&i.indexOf("}")!==-1&&(t=d+1);if(s!==-1&&t!==-1){var u=p.slice(s,t).join("\n").replace(/(\{|\})/g,"\n").replace(/ +$/gm,"").replace(/^ +/gm,"").replace(/\n\n/gm,"\n");r.push({start:s,end:t,struct:u.split("\n")}),s=-1,t=-1}}for(d=0,e=r.length;d<e;d++){var v=r[d].struct,w=null;for(g=0,h=v.length;g<h;g++){i=v[g].split(" ");if(i.length<=1)continue;i[0]=="struct"?(w=i[1],o[w]={}):w&&(o[w][i[1]]=i[0])}}n.struct=o;for(d=0,e=l.length;d<e;d++)n[l[d]]=[];for(d=0,e=p.length;d<e;d++){i=p[d];for(g=0,h=l.length;g<h;g++){var x=l[g];if(i.indexOf(x)===0){j=i.split(" ");if(j.length===3&&j[0]==x&&m.indexOf(j[2])===-1){m.push(j[2]);if(j[2].indexOf("[")!==-1){var y=j[2].split("["),z=y[1].replace("]",""),A=parseInt(z,10),B=A!==A;B||(z=A),n[x].push({name:y[0],type:j[1],isArray:!0,len:z})}else n[x].push({name:j[2],type:j[1]})}}}}return n},genShaderVarList:function(a,b){var c=a[b],d=[],e,f,g,h,i,j;if(!c)return[];for(e=0,f=c.length;e<f;e++){var k=c[e];if(a.struct[k.type]){var l=a.struct[k.type];if(l&&k.isArray)for(g=0,h=k.len;g<h;g++){i=k.name+"["+g+"]";for(j in l){if(!l.hasOwnProperty(j))continue;d.push({location:i+"."+j,type:l[j],basename:k.name})}}else for(j in l)d.push({location:k.name+"."+j,type:l[j],basename:k.name})}else if(k.isArray)for(g=0,h=k.len;g<h;g++)i=k.name+"["+g+"]",d.push({location:i,type:k.type,basename:k.name});else d.push({location:k.name,type:k.type,basename:k.name})}return d},getShaderVars:function(a){var b={};return b.uniform=k.genShaderVarList(a,"uniform"),b.attribute=k.genShaderVarList(a,"attribute"),b}};l.prototype={use:function(){this._initialized&&this._shader.use()},getShader:function(){return this._shader},ready:function(){return this._initialized},isReady:function(){return this._initialized},hasDepthPack:function(){return this._hasDepthPack},_init_shader:function(c,d,e,f,g){e=e||[];var h=a.util.get(c),i=a.util.get(d);g=g||"#define customShader_splice",f=f===b?this._vertex||this._fragment:f;if(f){var j=h.indexOf(g),l=i.indexOf(g);j!==-1&&this._vertex&&(h=h.substr(0,j)+this._vertex),l!==-1&&this._fragment&&(i=i.substr(0,l)+this._fragment)}this._shader=new a.Shader(h,i),this._shaderInfo=k.getShaderInfo(h,i),this._shaderVars=k.getShaderVars(this._shaderInfo),this._appendShaderVars(this._shaderVars,"uniform",e),this._appendShaderVars(this._shaderVars,"attribute",e),this._initialized=this._shader.isCompiled(),this._initialized&&this._init&&this._init(this)},_appendShaderVars:function(a,b,c){for(var d=0,e=this._shaderVars[b].length;d<e;d++){var f=this._shaderVars[b][d],g=f.location,h=f.basename;if(c.indexOf(h)!==-1)continue;var i=f.type;i==="vec3"?b==="attribute"?this._shader.addVertexArray(g):this._shader.addVector(g):i==="vec2"?b==="attribute"?this._shader.addUVArray(g):this._shader.addVector(g):i==="float"?b==="attribute"?this._shader.addFloatArray(g):this._shader.addFloat(g):i==="sampler2D"||i==="int"?this._shader.addInt(g):(i==="mat4"||i==="mat3"||i==="mat2")&&this._shader.addMatrix(g),this._bindSelf(g)}},_bindSelf:function(a){var c,d,e,f,g;if(this._shader.uniforms[a]===null)return;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]={}),g={location:this._shader.uniforms[a],value:null,type:this._shader.uniform_type[a]},this[e][d][f]=g,this._bindings.push(g)):(c=a.split("."),e=c[0],f=c[1],this[e]===b&&(this[e]={}),g={location:this._shader.uniforms[a],value:null,type:this._shader.uniform_type[a]},this[e][f]=g,this._bindings.push(g)):a.indexOf("[")!==-1?(c=a.split("["),e=c[0],c=c[1].split("]"),d=c[0],this[e]===b&&(this[e]=[]),g={location:this._shader.uniforms[a],value:null,type:this._shader.uniform_type[a]},this[e][d]=g,this._bindings.push(g)):(g={location:this._shader.uniforms[a],value:null,type:this._shader.uniform_type[a]},this[a]=g,this._bindings.push(g)),g&&(g.set=function(a,b){return function(b){g.value=b,a.update(g)}}(this,g))},_doUpdate:function(){if(!this._initialized)return;if(this._update)this._update(this);else for(var a=0,b=this._bindings.length;a<b;a++)this.update(this._bindings[a])},update:function(a){if(!this._initialized)return;var b=c.gl,e,f=a.value,g=a.location;if(g===null)return;a.type===d.shader.uniform.MATRIX?(e=f.length,e===16?b.uniformMatrix4fv(g,!1,f):e===9?b.uniformMatrix3fv(g,!1,f):e===4&&b.uniformMatrix2fv(g,!1,f)):a.type===d.shader.uniform.INT?b.uniform1i(g,f):a.type===d.shader.uniform.VECTOR?(e=f.length,e===3?b.uniform3fv(g,f):e===2?b.uniform2fv(g,f):b.uniform4fv(g,f)):a.type===d.shader.uniform.FLOAT?b.uniform1f(g,f):a.type===d.shader.uniform.ARRAY_VERTEX?(b.bindBuffer(b.ARRAY_BUFFER,f),b.vertexAttribPointer(g,3,b.FLOAT,!1,0,0),b.enableVertexAttribArray(g)):a.type===d.shader.uniform.ARRAY_UV?(b.bindBuffer(b.ARRAY_BUFFER,f),b.vertexAttribPointer(g,2,b.FLOAT,!1,0,0),b.enableVertexAttribArray(g)):a.type===d.shader.uniform.ARRAY_FLOAT&&(b.bindBuffer(b.ARRAY_BUFFER,f),b.vertexAttribPointer(g,1,b.FLOAT,!1,0,0),b.enableVertexAttribArray(g))}};var m={Shader:j,shader_util:k,CustomShader:l};return m}),CubicVR.RegisterModule("UVMapper",function(a){function j(c){c=a.get(c)||{},this.rotation=c.rotation===b?[0,0,0]:c.rotation,this.scale=c.scale===b?[1,1,1]:c.scale,this.center=c.center===b?[0,0,0]:c.center,this.projection_mode=c.projectionMode===b?d.uv.projection.PLANAR:a.parseEnum(d.uv.projection,c.projectionMode),this.projection_axis=c.projectionAxis===b?d.uv.axis.X:a.parseEnum(d.uv.axis,c.projectionAxis),this.wrap_w_count=c.wrapW===b?1:c.wrapW,this.wrap_h_count=c.wrapH===b?1:c.wrapH}var b=a.undef,c=a.GLCore,d=a.enums,e=a.util,f=2*Math.PI,g=Math.PI/2;d.uv={axis:{X:0,Y:1,Z:2},projection:{UV:0,PLANAR:1,CYLINDRICAL:2,SPHERICAL:3,CUBIC:4,SKY:5}};var h=function(a,b,c){var d;return a===0&&c===0?d=0:c===0?d=a<0?g:-g:c<0?d=-Math.atan(a/c)+Math.PI:d=-Math.atan(a/c),d},i=function(a,b,c){var d,e;return a===0&&c===0?(d=0,b!==0?e=b<0?-g:g:e=0):(c===0?d=a<0?g:-g:c<0?d=-Math.atan(a/c)+Math.PI:d=-Math.atan(a/c),a=Math.sqrt(a*a+c*c),a===0?e=b<0?-g:g:e=Math.atan(b/a)),[d,e]};j.prototype={setRotation:function(a){this.rotation=a},setScale:function(a){this.scale=a},setCenter:function(a){this.center=a},setProjectionAxis:function(a){this.projection_axis=a},setProjectionMode:function(a){this.projection_mode=a},setWrapW:function(a){this.wrap_w_count=a},setWrapH:function(a){this.wrap_h_count=a},apply:function(c,e,j,k,l){var m=a.mat4,n,o,p,q,r,s,t=new a.Transform,u=!1,v=null;if(this.center[0]||this.center[1]||this.center[2])t.translate(-this.center[0],-this.center[1],-this.center[2]),u=!0;if(this.rotation[0]||this.rotation[1]||this.rotation[2])this.rotation[0]&&t.rotate(this.rotation[2],0,0,1),this.rotation[1]&&t.rotate(this.rotation[1],0,1,0),this.rotation[2]&&t.rotate(this.rotation[0],1,0,0),u=!0;u&&(v=t.getResult()),typeof e=="object"&&(e=c.materials.indexOf(e));var w=0,x=c.faces.length;k&&(w=k),l&&(x=l+1);for(;w<x;w++){if(c.faces[w].material!==e)continue;if(j!==b&&c.faces[w].segment!==j)continue;var y,z,A;if(this.projection_mode===d.uv.projection.CUBIC||this.projection_mode===d.uv.projection.SKY)y=Math.abs(c.faces[w].normal[0]),z=Math.abs(c.faces[w].normal[1]),A=Math.abs(c.faces[w].normal[2]);var B=[];for(var C=0,D=c.faces[w].points.length;C<D;C++){var E=c.faces[w].points[C],F=c.faces[w].points[(C+1)%3],G=c.faces[w].points[(C+2)%3],H=c.points[E],I=c.points[F],J=c.points[G],K;u&&(H=m.vec3_multiply(H,v));var L=this.projection_mode;if(L===d.uv.projection.SKY){var M=c.sky_mapping;y>=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;d<e;++d){var l=j(b.materials[d],new h);for(var m=0,n=l.textures.length;m<n;++m){var o=l.textures[d];l.textures[d]=new g(k+o.img_path,o.filter_type)}b.materials[d]=l}var p=new i(b);c.bindSceneObject(p)})}})},this.loadFile=function(a,b){b=b||function(b){c[a]=b};var d=new CubicVR.Worker({type:"file",data:mesh,message:function(a){b(a.data)}})}}function o(a){this.worker=new Worker(CubicVR.getScriptLocation()+"CubicVR.js"),this.message=a.message||function(){},this.error=a.error||function(a){console.log("Error: "+a.message+": "+a.lineno)},this.type=a.type;var b=this;this.worker.onmessage=function(a){b.message(a.data)},this.worker.onerror=function(a){b.error(a)},this.init=function(a){b.send("init",{type:b.type,data:a})},this.send=function(a,c){b.worker.postMessage({message:a,data:c})},this.send("CubicVR_InitWorker",CubicVR.getScriptLocation()),(a.data||a.autoStart)&&b.init(a.data)}function p(a){var b=this;this.message=a.message||function(){},this.send=function(a,b){postMessage({message:a,data:b})},self.addEventListener("message",function(a){a.data.message!=="init"&&b.message(a.data)},!1)}function q(a){function c(a){setTimeout(function(){d.send("test",a)},1e3)}var b=this;a&&c(a);var d=new p({message:c})}function r(a){function d(a){var b=m.getURL(a);c.send("done",b.length)}var b=this,c;c=new p({message:function(a){d(a)}}),a&&d(a)}function s(a){function g(a){e=a;var b=m.getURL(a);c.send("loaded",b)}var b=this,c,d,e,f;c=new p({message:function(a){if(a.message==="parse")d=new l,f=CubicVR.loadCollada("","",d,a.data),c.send("parsed");else{if(a.message!=="getMesh")throw new Error("Not a SceneFileWorker command: "+a.message);var b=d.meshMap[":"+a.data];if(b){var e=b.triangulateQuads().compileVBO(b.compileMap());c.send("getMesh",{mesh:b,vbo:e})}}}}),a&&g(a)}function t(a){function d(a){var b=new f;for(var d in a)a.hasOwnProperty(d)&&(b[d]=a[d]);var e=b.triangulateQuads().compileVBO(b.compileMap());c.send("done",e)}var b=this,c;c=new p({message:function(a){d(a)}}),a&&d(a)}function u(a,b){var c=this;this.size=a,this.depth=b,this.worker=new o({message:function(a){console.log("Octree Worker Message:",a)},error:function(a){console.log("Octree Worker Error:",a)},type:"octree"}),this.worker.start(),this.init=function(a){c.scene=a,c.worker.init({size:c.size,max_depth:c.depth,camera:a.camera})},this.insert=function(a){c.worker.send({message:"insert",node:a})},this.draw_on_map=function(){return},this.reset_node_visibility=function(){return},this.get_frustum_hits=function(){}}function v(){this.octree=null,this.nodes=[],this.camera=null}function w(a,b){this.camera=b,this.worker=a,this.draw_on_map=function(a){return}}function x(a,b,c,d){var l;try{l=new Worker(CubicVR.getScriptLocation()+"collada.js")}catch(m){throw new Error("Can't find collada.js")}var n=[],o=[];l.onmessage=function(b){function p(a,b){for(var c in a)b[c]=a[c]}function q(a){if(a.motion){var b=a.motion.controllers,c=[];for(var d=0,e=b.length;d<e;++d){var f=b[d];if(!f){b[d]=null;continue}var g=[];for(var h=0,i=f.length;h<i;++h){var l=f[h];if(!l){f[h]=null;continue}var m=l.keys[0];l.keys.length>1&&(m.prev=null,m.next=l.keys[1],m=l.keys[1]);for(var n=1,o=l.keys.length-1;n<o;++n)m.prev=l.keys[n-1],m.next=l.keys[n+1],m=l.keys[n+1];l.keys.length>1&&(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;j<k;++j){var l=h.faces[j],m=l.material,q=n[m];q!==e?l.material=n[m]:l.material=0}}}else c.obj.triangulateQuads(),c.obj.calcNormals(),c.obj.compile(),c.obj.clean()}else c.obj=g}return c.trans=new Transform,b.children&&b.children.length>0&&(c.children=[],s(b,c)),c}function s(a,b){if(a.children)for(var c=0,d=a.children.length;c<d;++c){var e=r(a.children[c]);b.bindChild(e)}}var l,m,t=b.data.message;if(t=="materials"){var u=JSON.parse(b.data.data);for(l=0,m=u.length;l<m;++l){var v=new h(u[l].name),w=v.material_id;p(u[l],v),v.material_id=w,n[u[l].material_id]=w;for(var x=0,y=u[l].textures.length;x<y;++x){var z=u[l].textures[x];if(z){var A=Texture_ref[z.img_path];if(A===e){var B=new g(z.img_path,z.filter_type,d,a);v.textures[x]=B}else v.textures[x]=Textures_obj[A]}else v.textures[x]=0}}}else if(t=="scene"){var C=JSON.parse(b.data.data);for(l=0,m=C.sceneObjects.length;l<m;++l){var D=C.sceneObjects[l];D.obj!==null&&nop(),D.reassembled===e&&(q(D),D.reassembled=!0),C.sceneObjects[l]=r(D)}var E=new Scene,F=E.camera,G=F.transform;p(C.camera,F),p(C.camera.transform,G),q(F),E.camera=F,E.camera.transform=G,E.camera.frustum=new Frustum;for(l=0,m=C.sceneObjects.length;l<m;++l){var H=C.sceneObjects[l];E.bindSceneObject(H);try{H.getAABB()}catch(I){}}for(l=0,m=C.lights.length;l<m;++l){var J=new Light;p(C.lights[l],J),J.trans=new Transform,q(J),E.bindLight(J)}c(E)}else console.log("message from collada worker:",b.data.message)},l.onerror=function(a){console.log("error from collada worker:",a.message)},l.postMessage({message:"start",params:{meshUrl:a,prefix:b,rootDir:CubicVR.getScriptLocation()}})}function y(){var a={test:q,prepareMesh:t,file:r,sceneFile:s};self.addEventListener("message",function(b){var c=b.data.message;if(c==="init"){var d=b.data.data.type;if(!(d in a))throw new Error("Invalid worker type.");new a[d](b.data.data.data)}},!1)}try{window||(self.window=self,self.document={},self.fakeWindow=!0,self.console={log:function(){}})}catch(b){self.window=self,self.document={},self.fakeWindow=!0,self.console={log:function(){}}}var c=a.GLCore,d=CubicVR.enums,e=a.undef,f=CubicVR.Mesh,g=CubicVR.Texture,h=CubicVR.Material,i=CubicVR.SceneObject,j=CubicVR.Motion,k=CubicVR.Envelope,l=CubicVR.DeferredBin,m=CubicVR.util;return v.prototype.onmessage=function(a){var b=a.message;if(b==="init"){var c=a.data;this.octree=new Octree(c.size,c.max_depth),this.camera=new Camera}else if(type==="set_camera"){var d=b.data;this.camera.mvMatrix=d.mvMatrix,this.camera.pMatrix=d.pMatrix,this.camera.position=d.position,this.camera.target=d.target,this.camera.frustum.extract(this.camera,this.camera.mvMatrix,this.camera.pMatrix)}else if(type==="insert"){var e=JSON.parse(b.data),f=new i,g=new Transform,h;for(h in e)e.hasOwnProperty(h)&&(f[h]=e[h]);for(h in e.trans)e.trans.hasOwnProperty(h)&&(g[h]=e.trans[h]);f.trans=g,f.id=e.id,this.octree.insert(f),this.nodes[f.id]=f}else type==="cleaup"&&this.octree.cleanup()},w.prototype.extract=function(a,b,c){this.worker.send({type:"set_camera",data:{mvMatrix:this.camera.mvMatrix,pMatrix:this.camera.pMatrix,position:this.camera.position,target:this.camera.target}})},{Worker:o,ResourcePool:n,loadColladaWorker:x,InitWorker:y}}),CubicVR.RegisterModule("RigidVehicle",function(a){var b=a.undef,c=a.util,d=a.vec3,e=a.enums,f,g,h,i,j,k=function(c){c=a.get(c)||{};var d=c.mesh,e=c.collision;this.maxEngineForce=c.maxEngineForce||2e3,this.maxBreakingForce=c.maxBreakingForce||125,this.steeringClamp=c.steeringClamp||.51,this.mass=c.mass||400,this.gEngineForce=0,this.gBreakingForce=0,this.gVehicleSteering=0,this.rightIndex=0,this.upIndex=1,this.forwardIndex=2,this.m_vehicleRayCaster=null,this.m_vehicle=null,this.m_tuning=null,this.wheelDirectionCS0=new Ammo.btVector3,this.wheelAxleCS=new Ammo.btVector3,this.wheels=[],this.bodyMesh=d,this.bodyCollision=new a.CollisionMap(e),this.sceneObject=new a.SceneObject(this.bodyMesh);if(!f||!g)i=new Ammo.btVector3,j=new Ammo.btVector3,f=new Ammo.btTransform,g=new a.Quaternion,h=new Ammo.btQuaternion;if(c.wheels!=b)for(var k=0,l=c.wheels.length;k<l;k++){var m=c.wheels[k];m instanceof a.VehicleWheel?this.addWheel(m):this.addWheel(new a.VehicleWheel(m))}};k.prototype={getSceneObject:function(){return this.sceneObject},initBody:function(b){this.body=new a.RigidBody(this.sceneObject,{collision:this.bodyCollision,mass:this.mass,restitution:.1}),a.vec3bt_copy([0,-1,0],this.wheelDirectionCS0),a.vec3bt_copy([-1,0,0],this.wheelAxleCS),this.gVehicleSteering=0,this.body.setLinearVelocity([0,0,0]),this.body.setAngularVelocity([0,0,0]),this.m_vehicleRayCaster=new Ammo.btDefaultVehicleRaycaster(b.dynamicsWorld),this.m_tuning=new Ammo.btVehicleTuning,this.m_vehicle=new Ammo.btRaycastVehicle(this.m_tuning,this.body.getBody(),this.m_vehicleRayCaster),this.body.getBody().setActivationState(e.physics.collision_states.DISABLE_DEACTIVATION),this.m_vehicle.setCoordinateSystem(this.rightIndex,this.upIndex,this.forwardIndex);var c=new Ammo.btVector3;for(var d=0;d<this.wheels.length;d++)a.vec3bt_copy(this.wheels[d].getWheelPosition(),c),this.m_vehicle.addWheel(c,this.wheelDirectionCS0,this.wheelAxleCS,this.wheels[d].getSuspensionRest(),this.wheels[d].getWheelRadius(),this.m_tuning,this.wheels[d].getSteering());b.dynamicsWorld.addVehicle(this.m_vehicle),b.bind(this.body),this.updateSuspension()},evaluate:function(){var a=[],b=this.m_vehicle.getNumWheels();for(var c=0;c<b;c++){this.wheels[c].isSteering()&&this.m_vehicle.setSteeringValue(this.gVehicleSteering,c),this.wheels[c].isBraking()&&this.m_vehicle.setBrake(this.gBrakingForce,c),this.wheels[c].isDriving()&&this.m_vehicle.applyEngineForce(this.gEngineForce,c),this.m_vehicle.updateWheelTransform(c,!0);var d=this.m_vehicle.getWheelTransformWS(c),e=d.getOrigin();this.wheels[c].wheelObj.position[0]=e.x(),this.wheels[c].wheelObj.position[1]=e.y(),this.wheels[c].wheelObj.position[2]=e.z();var f=d.getRotation();g.x=f.x(),g.y=f.y(),g.z=f.z(),g.w=f.w();var h=g.toEuler();this.wheels[c].wheelObj.rotation[0]=h[0],this.wheels[c].wheelObj.rotation[1]=h[1],this.wheels[c].wheelObj.rotation[2]=h[2]}this.body.isActive()||this.body.activate(),this.updateSceneObject(!0)},getRigidBody:function(){return this.body},updateSceneObject:function(a){if(!this.body)return;if(this.body.isActive()||a){this.body.getBody().getMotionState().getWorldTransform(f);var b=f.getOrigin();b.x!=b.x?console.log("origin is NaN"):(this.sceneObject.position[0]=b.x(),this.sceneObject.position[1]=b.y(),this.sceneObject.position[2]=b.z());var c=f.getRotation();g.x=c.x(),g.y=c.y(),g.z=c.z(),g.w=c.w();if(g.x!=g.x)console.log("rotation is NaN");else{var d=g.toEuler();this.sceneObject.rotation[0]=d[0],this.sceneObject.rotation[1]=d[1],this.sceneObject.rotation[2]=d[2]}return!0}},setEngineForce:function(a){this.gEngineForce=a,this.gEngineForce>this.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;c<b;c++)a.bind(this.getWheelObj(c));a.bind(this.getSceneObject())},getWheelObj:function(a){var b=this.getWheel(a);return b.wheelObj},updateSuspension:function(){var a,b=this.m_vehicle.getNumWheels();for(a=0;a<b;a++){var c=this.m_vehicle.getWheelInfo(a);c.set_m_suspensionStiffness(this.wheels[a].getSuspensionStiffness()),c.set_m_suspensionRestLength1(this.wheels[a].getSuspensionRest()),c.set_m_wheelsDampingRelaxation(this.wheels[a].getDampingRelaxation()),c.set_m_wheelsDampingCompression(this.wheels[a].getDampingCompression()),c.set_m_frictionSlip(this.wheels[a].getFrictionSlip()),c.set_m_rollInfluence(this.wheels[a].getRollInfluence())}if(this.m_vehicle){this.m_vehicle.resetSuspension();for(a=0;a<b;a++)this.m_vehicle.updateWheelTransform(a,!0)}},getMass:function(){return this.mass},setMass:function(a){this.mass=a,this.body&&this.body.setMass(this.mass)}};var l=function(c){c=a.get(c)||{},this.wheelRef=new a.SceneObject,this.wheelObj=new a.SceneObject,this.wheelRef.scale=c.scale||[1,1,1],this.wheelRadius=c.radius||0,this.wheelWidth=c.width||0,c.mesh!=b&&this.setModel(c.mesh),this.suspensionStiffness=c.suspensionStiffness||40,this.suspensionRest=c.suspensionRest||.05,this.dampingRelaxation=c.dampingRelaxation||2.3,this.dampingCompression=c.dampingCompression||2.4,this.frictionSlip=c.frictionSlip||.94,this.rollInfluence=c.rollInfluence||.5,this.wheelPosition=c.position||[0,0,0],this.wheelRotation=[0,0,0],this.steering=c.steering||!1,this.braking=c.braking||!1,this.driving=c.driving||!1};l.prototype={setModel:function(a,b,c){this.wheelModel=a,this.wheelRadius=b||0,this.wheelWidth=c||0,this.wheelRadius===0&&(this.wheelRadius=(this.wheelModel.bb[1][1]-this.wheelModel.bb[0][1])/2,this.wheelRadius+=(this.wheelModel.bb[1][2]-this.wheelModel.bb[0][2])/2,this.wheelRadius/=2),this.wheelWidth===0&&(this.wheelWidth=this.wheelModel.bb[1][0]-this.wheelModel.bb[0][0]),this.wheelRef.obj=this.wheelModel,this.wheelObj.bindChild(this.wheelRef)},setSuspensionStiffness:function(a){this.suspensionStiffness=a},getSuspensionStiffness:function(){return this.suspensionStiffness},setSuspensionRest:function(a){this.suspensionRest=a},getSuspensionRest:function(){return this.suspensionRest},setDampingRelaxation:function(a){this.dampingRelaxation=a},getDampingRelaxation:function(){return this.dampingRelaxation},setDampingCompression:function(a){this.dampingCompression=a},getDampingCompression:function(){return this.dampingCompression},setFrictionSlip:function(a){this.frictionSlip=a},getFrictionSlip:function(){return this.frictionSlip},setRollInfluence:function(a){this.rollInfluence=a},getRollInfluence:function(){return this.rollInfluence},setWheelRadius:function(a){this.wheelRadius=a},getWheelRadius:function(){return this.wheelRadius},setWheelWidth:function(a){this.wheelWidth=a},getWheelWidth:function(){return this.wheelWidth},setWheelRotation:function(a){this.wheelRotation=a,this.wheelRef.setRotation(wheelRotation)},getWheelRotation:function(){return this.wheelRotation},setWheelPosition:function(a){this.wheelPosition=a,this.wheelObj.position=wheelPosition},getWheelPosition:function(){return this.wheelPosition},setSteering:function(a){this.steering=a},getSteering:function(){return this.steering},isSteering:function(){return this.steering},setBraking:function(a){this.braking=this.braking_in},isBraking:function(){return this.braking},setDriving:function(a){this.driving=a},isDriving:function(){return this.driving}};var m={Vehicle:k,VehicleWheel:l};return m}),window.CubicVRShader.CubicVRCoreVS="attribute vec3 vertexPosition;\nattribute vec3 vertexNormal;\nattribute vec2 vertexTexCoord;\n#if VERTEX_COLOR\nattribute vec3 vertexColor;\nvarying vec3 vertexColorOut;\n#endif\n#if VERTEX_MORPH\nattribute vec3 vertexMorphPosition;\nattribute vec3 vertexMorphNormal;\nuniform float materialMorphWeight;\n#endif\nvarying vec2 vertexTexCoordOut;\nuniform vec2 materialTexOffset;\n#if !LIGHT_PERPIXEL\n#if LIGHT_IS_POINT||LIGHT_IS_DIRECTIONAL||LIGHT_IS_SPOT||LIGHT_IS_AREA\nuniform vec3 lightDirection[LIGHT_COUNT];\nuniform vec3 lightPosition[LIGHT_COUNT];\nuniform vec3 lightSpecular[LIGHT_COUNT];\nuniform vec3 lightDiffuse[LIGHT_COUNT];\nuniform float lightIntensity[LIGHT_COUNT];\nuniform float lightDistance[LIGHT_COUNT];\n#if LIGHT_IS_SPOT\nuniform float lightCutOffAngle[LIGHT_COUNT];\n#endif\nvarying vec3 lightColorOut;\nvarying vec3 lightSpecularOut;\n#endif\nuniform vec3 materialDiffuse;\nuniform vec3 materialSpecular;\nuniform float materialShininess;\n#endif\nuniform mat4 matrixModelView;\nuniform mat4 matrixProjection;\nuniform mat4 matrixObject;\nuniform mat3 matrixNormal;\nvarying vec3 vertexNormalOut;\nvarying vec4 vertexPositionOut;\n#if !LIGHT_DEPTH_PASS\n#if LIGHT_SHADOWED\nvarying vec4 lightProjectionOut[LIGHT_COUNT];\nuniform mat4 lightShadowMatrix[LIGHT_COUNT];\n#endif\n#if TEXTURE_ENVSPHERE\n#if TEXTURE_NORMAL\nvarying vec3 envTexCoordOut;\n#else\nvarying vec2 envTexCoordOut;\n#endif\n#endif\n#if TEXTURE_BUMP||TEXTURE_NORMAL\nvarying vec3 envEyeVectorOut;\n#endif\n#endif \nvoid cubicvr_normalMap() {\n#if !LIGHT_DEPTH_PASS\n#if TEXTURE_BUMP||TEXTURE_NORMAL\nvec3 tangent;\nvec3 binormal;\nvec3 c1 = cross( vertexNormal, vec3(0.0, 0.0, 1.0) );\nvec3 c2 = cross( vertexNormal, vec3(0.0, 1.0, 0.0) );\nif ( length(c1) > length(c2) ) {\ntangent = c1;\n} else {\ntangent = c2;\n}\ntangent = normalize(tangent);\nbinormal = cross(vertexNormal, tangent);\nbinormal = normalize(binormal);\nmat4 uMVOMatrix = matrixModelView * matrixObject;\nmat3 TBNMatrix = mat3( (vec3 (uMVOMatrix * vec4 (tangent, 0.0))),\n(vec3 (uMVOMatrix * vec4 (binormal, 0.0))),\n(vec3 (uMVOMatrix * vec4 (vertexNormal, 0.0)))\n);\nenvEyeVectorOut = vec3(uMVOMatrix * vec4(vertexPosition,1.0)) * TBNMatrix;\n#endif\n#endif\n}\nvoid cubicvr_environmentMap() {\n#if !LIGHT_DEPTH_PASS\n#if TEXTURE_ENVSPHERE\n#if TEXTURE_NORMAL\nenvTexCoordOut = normalize( vertexPositionOut.xyz );\n#else\nvec3 ws = (matrixModelView * vec4(vertexPosition,1.0)).xyz;\nvec3 r = reflect(ws, vertexNormalOut );\nfloat m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );\nenvTexCoordOut.s = r.x/m + 0.5;\nenvTexCoordOut.t = r.y/m + 0.5;\n#endif\n#endif\n#if VERTEX_COLOR\nvertexColorOut = vertexColor;\n#endif\n#endif\n}\nvoid cubicvr_shadowMap() {\n#if (LIGHT_IS_SPOT||LIGHT_IS_AREA) && LIGHT_SHADOWED\nfor (int i = 0; i < LIGHT_COUNT; i++)\n{\n#if LIGHT_SHADOWED\n#if VERTEX_MORPH\nlightProjectionOut[i] = lightShadowMatrix[i] * (matrixObject * vec4(vertexPosition+(vertexMorphPosition-vertexPosition)*materialMorphWeight, 1.0));\n#else\nlightProjectionOut[i] = lightShadowMatrix[i] * (matrixObject * vec4(vertexPosition, 1.0));\n#endif\n#endif\n}\n#endif\n}\nvoid cubicvr_lighting() {\n#if !LIGHT_PERPIXEL\n#if LIGHT_IS_POINT\nvec3 specTotal = vec3(0.0,0.0,0.0);\nvec3 accum = vec3(0.0,0.0,0.0);\nfor (int i = 0; i < LIGHT_COUNT; i++) {\nvec3 lightDirection = lightPosition[i]-vertexPositionOut.xyz;\nfloat dist = length(lightDirection);\nvec3 halfVector = normalize(vec3(0.0,0.0,1.0)+lightDirection);\nfloat NdotL = max(dot(normalize(lightDirection),vertexNormalOut),0.0);\nif (NdotL > 0.0) {\nfloat att = clamp(((lightDistance[i]-dist)/lightDistance[i]), 0.0, 1.0)*lightIntensity[i];\naccum += att * NdotL * lightDiffuse[i] * materialDiffuse;\nfloat NdotHV = max(dot(vertexNormalOut, halfVector),0.0);\nvec3 spec2 = lightSpecular[i] * materialSpecular * pow(NdotHV,materialShininess);\nspecTotal += spec2;\n}\n}\nlightColorOut = accum;\nlightSpecularOut = specTotal;\n#endif\n#if LIGHT_IS_DIRECTIONAL\nfloat NdotL;\nfloat NdotHV = 0.0;\nvec3 specTotal = vec3(0.0,0.0,0.0);\nvec3 spec2 = vec3(0.0,0.0,0.0);\nvec3 accum = vec3(0.0,0.0,0.0);\nvec3 halfVector;\nfor (int i = 0; i < LIGHT_COUNT; i++) {\nhalfVector = normalize(vec3(0.0,0.0,1.0)-lightDirection[i]);\nNdotL = max(dot(normalize(-lightDirection[i]),vertexNormalOut),0.0);\nif (NdotL > 0.0) {\naccum += lightIntensity[i] * materialDiffuse * lightDiffuse[i] * NdotL;\nNdotHV = max(dot(vertexNormalOut, halfVector),0.0);\nspec2 = lightSpecular[i] * materialSpecular * pow(NdotHV,materialShininess);\nspecTotal += spec2;\n}\n}\nlightColorOut = accum;\nlightSpecularOut = specTotal;\n#endif\n#if LIGHT_IS_SPOT\nvec3 specTotal = vec3(0.0,0.0,0.0);\nvec3 spec2 = vec3(0.0,0.0,0.0);\nvec3 accum = vec3(0.0,0.0,0.0);\nvec3 halfVector;\nfloat spotEffect;\nfloat spotDot;\nfloat power;\nfor (int i = 0; i < LIGHT_COUNT; i++) {\nvec3 l = lightPosition[i]-vertexPositionOut.xyz;\nfloat dist = length(l);\nfloat att = clamp(((lightDistance[i]-dist)/lightDistance[i]), 0.0, 1.0)*lightIntensity[i];\natt = clamp(att,0.0,1.0);\nspotDot = dot(normalize(-l), normalize(lightDirection[i]));\nif ( spotDot < cos((lightCutOffAngle[i]/2.0)*(3.14159/180.0)) ) {\nspotEffect = 0.0;\n}\nelse {\nspotEffect = pow(spotDot, 1.0);\n}\natt *= spotEffect;\nvec3 v = normalize(-vertexPositionOut.xyz);\nvec3 h = normalize(l + v);\nfloat NdotL = max(0.0, dot(vertexNormalOut, normalize(l)));\nfloat NdotH = max(0.0, dot(vertexNormalOut, h));\nif (NdotL > 0.0) {\npower = pow(NdotH, materialShininess);\n}\nelse {\npower = 0.0;\n}\naccum += att * lightDiffuse[i] * materialDiffuse * NdotL;\nspec2 = lightSpecular[i] * materialSpecular * power;\nspecTotal += spec2*spotEffect;\n}\nlightColorOut = accum;\nlightSpecularOut = specTotal;\n#endif\n#endif \ncubicvr_normalMap();\ncubicvr_shadowMap();\ncubicvr_environmentMap();\n}\nvec2 cubicvr_texCoord() {\nreturn vertexTexCoord + materialTexOffset;\n}\nvec4 cubicvr_transform() {\n#if LIGHT_DEPTH_PASS\nvertexNormalOut = vec3(0.0,0.0,0.0);\n#endif\n#if VERTEX_MORPH\nvec4 vPos = matrixObject * vec4(vertexPosition+(vertexMorphPosition-vertexPosition)*materialMorphWeight, 1.0);\n#else\nvec4 vPos = matrixObject * vec4(vertexPosition, 1.0);\n#endif\nvertexPositionOut = matrixModelView * vPos;\nreturn vPos;\n}\nvec3 cubicvr_normal() {\n#if VERTEX_MORPH\nreturn normalize(matrixObject*vec4(vertexNormal+(vertexMorphNormal-vertexNormal)*materialMorphWeight,0.0)).xyz;\n#else\nreturn normalize(matrixObject*vec4(vertexNormal,0.0)).xyz;\n#endif\n}\n#define customShader_splice 1\nvoid main(void)\n{\nvertexTexCoordOut = cubicvr_texCoord();\ngl_Position = matrixProjection * matrixModelView * cubicvr_transform();\n#if !LIGHT_DEPTH_PASS \nvertexNormalOut = matrixNormal * cubicvr_normal();\ncubicvr_lighting();\n#endif \n}\n"
,window.CubicVRShader.CubicVRCoreFS="#ifdef GL_ES\n#if LIGHT_PERPIXEL\nprecision highp float;\n#else\nprecision lowp float;\n#endif\n#endif\nuniform vec3 materialAmbient;\nuniform vec3 lightAmbient;\nuniform vec3 materialColor;\n#if LIGHT_PERPIXEL\nuniform vec3 materialDiffuse;\nuniform vec3 materialSpecular;\nuniform float materialShininess;\n#if LIGHT_IS_POINT||LIGHT_IS_DIRECTIONAL||LIGHT_IS_SPOT||LIGHT_IS_AREA\nuniform vec3 lightDirection[LIGHT_COUNT];\nuniform vec3 lightPosition[LIGHT_COUNT];\nuniform vec3 lightSpecular[LIGHT_COUNT];\nuniform vec3 lightDiffuse[LIGHT_COUNT];\nuniform float lightIntensity[LIGHT_COUNT];\nuniform float lightDistance[LIGHT_COUNT];\n#if LIGHT_IS_SPOT\nuniform float lightCutOffAngle[LIGHT_COUNT];\n#endif\n#endif\n#if LIGHT_IS_PROJECTOR\nuniform sampler2D lightProjectionMap[LIGHT_COUNT];\n#endif\n#if LIGHT_SHADOWED\nvarying vec4 lightProjectionOut[LIGHT_COUNT];\nuniform sampler2D lightShadowMap[LIGHT_COUNT];\nuniform vec3 lightDepthClip[LIGHT_COUNT];\n#endif\n#else \nvarying vec3 lightColorOut;\nvarying vec3 lightSpecularOut;\n#endif \nvarying vec3 vertexNormalOut;\nvarying vec2 vertexTexCoordOut;\n#if VERTEX_COLOR\nvarying vec3 vertexColorOut;\n#endif\n#if FX_DEPTH_ALPHA||LIGHT_DEPTH_PASS||LIGHT_SHADOWED\nuniform vec3 postDepthInfo;\nfloat ConvertDepth3(float d) { return (postDepthInfo.x*postDepthInfo.y)/(postDepthInfo.y-d*(postDepthInfo.y-postDepthInfo.x)); }\nfloat DepthRange( float d ) { return ( d - postDepthInfo.x ) / ( postDepthInfo.y - postDepthInfo.x ); }\nfloat ConvertDepth3A(float d, float near, float far) { return (near*far)/(far-d*(far-near)); }\nfloat DepthRangeA( float d, float near, float far ) { return ( d - near ) / ( far - near ); }\n#endif\n#if LIGHT_DEPTH_PASS\nvec4 packFloatToVec4i(const float value)\n{\nconst vec4 bitSh = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\nconst vec4 bitMsk = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\nvec4 res = fract(value * bitSh);\nres -= res.xxyz * bitMsk;\nreturn res;\n}\n#endif\n#if LIGHT_SHADOWED\nfloat unpackFloatFromVec4i(const vec4 value)\n{\nconst vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\nreturn(dot(value, bitSh));\n}\n#if LIGHT_SHADOWED_SOFT\nfloat getShadowVal(sampler2D shadowTex,vec4 shadowCoord, float proj, float texel_size) {\nvec2 filterTaps[6];\nfilterTaps[0] = vec2(-0.326212,-0.40581);\nfilterTaps[1] = vec2(-0.840144,-0.07358);\nfilterTaps[2] = vec2(-0.695914,0.457137);\nfilterTaps[3] = vec2(-0.203345,0.620716);\nfilterTaps[4] = vec2(0.96234,-0.194983);\nfilterTaps[5] = vec2(0.473434,-0.480026);\n/* filterTaps[6] = vec2(0.519456,0.767022);\nfilterTaps[7] = vec2(0.185461,-0.893124);\nfilterTaps[8] = vec2(0.507431,0.064425);\nfilterTaps[9] = vec2(0.89642,0.412458) ;\nfilterTaps[10] =vec2(-0.32194,-0.932615);\nfilterTaps[11] =vec2(-0.791559,-0.59771); */\nfloat shadow = 0.0;\nvec4 shadowSample;\nfloat distanceFromLight;\nfor (int i = 0; i < 6; i++) {\nshadowSample = texture2D(shadowTex,shadowCoord.st+filterTaps[i]*(2.0*texel_size));\ndistanceFromLight = unpackFloatFromVec4i(shadowSample);\nshadow += distanceFromLight <= shadowCoord.z ? 0.0 : 1.0 ;\n}\nshadow /= 6.0;\nreturn shadow;\n}\n#else\nfloat getShadowVal(sampler2D shadowTex,vec4 shadowCoord, float proj, float texel_size) {\nvec4 shadowSample = texture2D(shadowTex,shadowCoord.st);\nfloat distanceFromLight = unpackFloatFromVec4i(shadowSample);\nfloat shadow = 1.0;\nshadow = distanceFromLight <= (shadowCoord.z) ? 0.0 : 1.0 ;\nreturn shadow;\n}\n#endif\n#endif\n#if !LIGHT_DEPTH_PASS\n#if TEXTURE_COLOR\nuniform sampler2D textureColor;\n#endif\n#if TEXTURE_BUMP||TEXTURE_NORMAL\nvarying vec3 envEyeVectorOut;\n#endif\n#if TEXTURE_BUMP\nuniform sampler2D textureBump;\n#endif\n#if TEXTURE_ENVSPHERE\nuniform sampler2D textureEnvSphere;\nuniform float materialEnvironment;\n#if TEXTURE_NORMAL\nvarying vec3 envTexCoordOut;\n#else\nvarying vec2 envTexCoordOut;\n#endif\n#endif\n#if TEXTURE_REFLECT\nuniform sampler2D textureReflect;\n#endif\n#if TEXTURE_NORMAL\nuniform sampler2D textureNormal;\n#endif\nuniform float materialAlpha;\n#if TEXTURE_AMBIENT\nuniform sampler2D textureAmbient;\n#endif\n#if TEXTURE_SPECULAR\nuniform sampler2D textureSpecular;\n#endif\n#endif \n#if TEXTURE_ALPHA\nuniform sampler2D textureAlpha;\n#endif\nvarying vec4 vertexPositionOut;\nvec2 cubicvr_texCoord() {\n#if LIGHT_DEPTH_PASS\nreturn vertexTexCoordOut;\n#else\n#if TEXTURE_BUMP\nfloat height = texture2D(textureBump, vertexTexCoordOut.xy).r;\nfloat v = (height) * 0.05 - 0.04; \nvec3 eye = normalize(envEyeVectorOut);\nreturn vertexTexCoordOut.xy + (eye.xy * v);\n#else\nreturn vertexTexCoordOut;\n#endif\n#endif\n}\nvec3 cubicvr_normal(vec2 texCoord) {\n#if TEXTURE_NORMAL && !LIGHT_DEPTH_PASS\nvec3 bumpNorm = vec3(texture2D(textureNormal, texCoord));\nvec3 n = (vec4(normalize(vertexNormalOut),1.0)).xyz;\nbumpNorm = (bumpNorm-0.5)*2.0;\nbumpNorm.y = -bumpNorm.y;\nreturn normalize((n+bumpNorm)/2.0);\n#else\nreturn normalize(vertexNormalOut);\n#endif\n}\nvec4 cubicvr_color(vec2 texCoord) {\nvec4 color = vec4(0.0,0.0,0.0,0.0);\n#if !LIGHT_DEPTH_PASS\n#if TEXTURE_COLOR\n#if !(LIGHT_IS_POINT||LIGHT_IS_DIRECTIONAL||LIGHT_IS_SPOT||LIGHT_IS_AREA)\ncolor = texture2D(textureColor, texCoord).rgba;\ncolor.rgb *= materialColor;\n#else\ncolor = texture2D(textureColor, texCoord).rgba;\n#if !TEXTURE_ALPHA\nif (color.a<=0.9) {\ndiscard;\n}\n#endif\ncolor.rgb *= materialColor;\n#endif\n#if VERTEX_COLOR\ncolor *= vec4(vertexColorOut,1.0);\n#endif\n#else\n#if VERTEX_COLOR\ncolor = vec4(vertexColorOut,1.0);\n#else\ncolor = vec4(materialColor,1.0);\n#endif\n#endif\n#if TEXTURE_ALPHA\ncolor.a = texture2D(textureAlpha, texCoord).r;\n#if FX_DEPTH_ALPHA\nif (color.a < 0.9) discard;\n#else\n#if MATERIAL_ALPHA\nif (color.a == 0.0) discard;\n#else\nif (color.a < 0.9) discard;\n#endif\n#endif\n#else\n#if MATERIAL_ALPHA\ncolor.a = materialAlpha;\n#endif\n#endif\n#endif\nreturn color;\n}\nvec4 cubicvr_lighting(vec4 color_in, vec3 n, vec2 texCoord) {\nvec4 color = color_in;\n#if !LIGHT_DEPTH_PASS\nvec3 accum = lightAmbient;\n#if LIGHT_PERPIXEL\n#if LIGHT_IS_POINT\nvec3 specTotal = vec3(0.0,0.0,0.0);\nfor (int i = 0; i < LIGHT_COUNT; i++) {\nvec3 lightDirection = lightPosition[i]-vertexPositionOut.xyz;\nfloat dist = length(lightDirection);\nvec3 halfVector = normalize(vec3(0.0,0.0,1.0)+lightDirection);\nfloat NdotL = max(dot(normalize(lightDirection),n),0.0);\nif (NdotL > 0.0) {\nfloat att = clamp(((lightDistance[i]-dist)/lightDistance[i]), 0.0, 1.0)*lightIntensity[i];\naccum += att * NdotL * lightDiffuse[i] * materialDiffuse;\nfloat NdotHV = max(dot(n, halfVector),0.0);\n#if TEXTURE_SPECULAR\nvec3 spec2 = lightSpecular[i] * texture2D(textureSpecular, vec2(texCoord.s, texCoord.t)).rgb * pow(NdotHV,materialShininess);\n#else\nvec3 spec2 = lightSpecular[i] * materialSpecular * pow(NdotHV,materialShininess);\n#endif\nspecTotal += spec2;\n}\n}\ncolor.rgb *= accum;\ncolor.rgb += specTotal;\n#endif\n#if LIGHT_IS_DIRECTIONAL\nfloat NdotL;\nfloat NdotHV = 0.0;\nvec3 specTotal = vec3(0.0,0.0,0.0);\nvec3 spec2 = vec3(0.0,0.0,0.0);\nvec3 halfVector;\nfor (int i = 0; i < LIGHT_COUNT; i++) {\nhalfVector = normalize(vec3(0.0,0.0,1.0)-lightDirection[i]);\nNdotL = max(dot(normalize(-lightDirection[i]),n),0.0);\nif (NdotL > 0.0) {\naccum += lightIntensity[i] * materialDiffuse * lightDiffuse[i] * NdotL;\nNdotHV = max(dot(n, halfVector),0.0);\n#if TEXTURE_SPECULAR\nspec2 = lightSpecular[i] * texture2D(textureSpecular, vec2(texCoord.s, texCoord.t)).rgb * pow(NdotHV,materialShininess);\n#else\nspec2 = lightSpecular[i] * materialSpecular * pow(NdotHV,materialShininess);\n#endif\nspecTotal += spec2;\n}\n}\ncolor.rgb *= accum;\ncolor.rgb += specTotal;\n#endif\n#if LIGHT_IS_AREA\nvec3 specTotal = vec3(0.0,0.0,0.0);\nvec3 spec2 = vec3(0.0,0.0,0.0);\nfloat NdotL;\nfloat NdotHV = 0.0;\nvec3 halfVector;\nfor (int i = 0; i < LIGHT_COUNT; i++) {\nhalfVector = normalize(vec3(0.0,0.0,1.0)-lightDirection[i]);\nNdotL = max(dot(normalize(-lightDirection[i]),n),0.0);\nif (NdotL > 0.0) {\nNdotHV = max(dot(n, halfVector),0.0);\n#if LIGHT_SHADOWED\nvec4 shadowCoord = lightProjectionOut[i] / lightProjectionOut[i].w;\nshadowCoord.z = DepthRangeA(ConvertDepth3A(shadowCoord.z,lightDepthClip[i].x,lightDepthClip[i].y),lightDepthClip[i].x,lightDepthClip[i].y);\nvec4 shadowSample;\nfloat shadow = 1.0;\nif (shadowCoord.s > 0.000&&shadowCoord.s < 1.000 && shadowCoord.t > 0.000 && shadowCoord.t < 1.000) if (i == 0) { shadow = getShadowVal(lightShadowMap[0],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z);}\n#if LIGHT_COUNT>1\nelse if (i == 1) { shadow = getShadowVal(lightShadowMap[1],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>2\nelse if (i == 2) { shadow = getShadowVal(lightShadowMap[2],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>3\nelse if (i == 3) { shadow = getShadowVal(lightShadowMap[3],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>4\nelse if (i == 4) { shadow = getShadowVal(lightShadowMap[4],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>5\nelse if (i == 5) { shadow = getShadowVal(lightShadowMap[5],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>6\nelse if (i == 6) { shadow = getShadowVal(lightShadowMap[6],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>7\nelse if (i == 7) { shadow = getShadowVal(lightShadowMap[7],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\naccum += shadow * lightIntensity[i] * materialDiffuse * lightDiffuse[i] * NdotL;\n#else\naccum += lightIntensity[i] * materialDiffuse * lightDiffuse[i] * NdotL;\n#endif\n#if TEXTURE_SPECULAR\nspec2 = lightSpecular[i] * texture2D(textureSpecular, vec2(texCoord.s, texCoord.t)).rgb * pow(NdotHV,materialShininess);\n#else\nspec2 = lightSpecular[i] * materialSpecular * pow(NdotHV,materialShininess);\n#endif\n#if LIGHT_SHADOWED\nspec2 *= shadow;\n#endif\nspecTotal += spec2;\n#if LIGHT_SHADOWED\n#endif\n}\n}\ncolor.rgb *= accum;\ncolor.rgb += specTotal;\n#endif\n#if LIGHT_IS_SPOT\nvec3 specTotal = vec3(0.0,0.0,0.0);\nvec3 spec2 = vec3(0.0,0.0,0.0);\nvec3 halfVector;\nfloat spotEffect;\nfloat spotDot;\nfloat power;\nfor (int i = 0; i < LIGHT_COUNT; i++) {\nvec3 l = lightPosition[i]-vertexPositionOut.xyz;\nfloat dist = length(l);\nfloat att = clamp(((lightDistance[i]-dist)/lightDistance[i]), 0.0, 1.0)*lightIntensity[i];\natt = clamp(att,0.0,1.0);\nspotDot = dot(normalize(-l), normalize(lightDirection[i]));\nif ( spotDot < cos((lightCutOffAngle[i]/2.0)*(3.14159/180.0)) ) {\nspotEffect = 0.0;\n}\nelse {\nspotEffect = pow(spotDot, 1.0);\n}\n#if !LIGHT_IS_PROJECTOR\natt *= spotEffect;\n#endif\nvec3 v = normalize(-vertexPositionOut.xyz);\nvec3 h = normalize(l + v);\nfloat NdotL = max(0.0, dot(n, normalize(l)));\nfloat NdotH = max(0.0, dot(n, h));\nif (NdotL > 0.0) {\npower = pow(NdotH, materialShininess);\n}\nelse {\npower = 0.0;\n}\n#if LIGHT_SHADOWED\nvec4 shadowCoord = lightProjectionOut[i] / lightProjectionOut[i].w;\nshadowCoord.z = DepthRangeA(ConvertDepth3A(shadowCoord.z,lightDepthClip[i].x,lightDepthClip[i].y),lightDepthClip[i].x,lightDepthClip[i].y);\nvec4 shadowSample;\nfloat shadow = 1.0;\nif (shadowCoord.s >= 0.000&&shadowCoord.s <= 1.000 && shadowCoord.t >= 0.000 && shadowCoord.t <= 1.000) if (i == 0) { shadow = getShadowVal(lightShadowMap[0],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z);}\n#if LIGHT_COUNT>1\nelse if (i == 1) { shadow = getShadowVal(lightShadowMap[1],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>2\nelse if (i == 2) { shadow = getShadowVal(lightShadowMap[2],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>3\nelse if (i == 3) { shadow = getShadowVal(lightShadowMap[3],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>4\nelse if (i == 4) { shadow = getShadowVal(lightShadowMap[4],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>5\nelse if (i == 5) { shadow = getShadowVal(lightShadowMap[5],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>6\nelse if (i == 6) { shadow = getShadowVal(lightShadowMap[6],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\n#if LIGHT_COUNT>7\nelse if (i == 7) { shadow = getShadowVal(lightShadowMap[7],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }\n#endif\natt = att * shadow;\n#endif\n#if LIGHT_IS_PROJECTOR && LIGHT_SHADOWED\nif (shadowCoord.s >= 0.0&&shadowCoord.s <= 1.0 && shadowCoord.t >= 0.0 && shadowCoord.t <= 1.0 && spotDot > cos((90.0)*(3.14159/180.0))) {\nvec3 projTex = texture2D(lightProjectionMap[i],shadowCoord.st).rgb;\naccum += att * projTex * lightIntensity[i] * materialDiffuse * lightDiffuse[i] * NdotL;\n}\n#else\naccum += att * lightDiffuse[i] * materialDiffuse * NdotL;\n#endif\n#if TEXTURE_SPECULAR\nspec2 = lightSpecular[i] * texture2D(textureSpecular, vec2(texCoord.s, texCoord.t)).rgb * power;\n#else\nspec2 = lightSpecular[i] * materialSpecular * power;\n#endif\n#if LIGHT_SHADOWED\nspec2 *= shadow;\n#endif\nspecTotal += spec2*spotEffect;\n}\ncolor.rgb *= accum;\ncolor.rgb += specTotal;\n#if LIGHT_SHADOWED\n#endif\n#endif\n#else\n#if LIGHT_IS_POINT||LIGHT_IS_DIRECTIONAL||LIGHT_IS_SPOT||LIGHT_IS_AREA\ncolor.rgb *= lightColorOut;\ncolor.rgb += lightSpecularOut;\n#endif\n#endif \n#if TEXTURE_AMBIENT\n#if LIGHT_IS_POINT||LIGHT_IS_DIRECTIONAL||LIGHT_IS_SPOT||LIGHT_IS_AREA\ncolor.rgb += texture2D(textureAmbient, texCoord).rgb*(vec3(1.0,1.0,1.0)+materialColor*materialAmbient);\n#else\ncolor.rgb = color.rgb*texture2D(textureAmbient, texCoord).rgb;\n#endif\n#else\n#if TEXTURE_COLOR\ncolor.rgb += materialAmbient*texture2D(textureColor, texCoord).rgb;\n#else\ncolor.rgb += materialColor*materialAmbient;\n#endif\n#endif\n#endif\nreturn color;\n}\nvec4 cubicvr_environment(vec4 color_in, vec3 n, vec2 texCoord) {\nvec4 color = color_in;\n#if !LIGHT_DEPTH_PASS\n#if TEXTURE_REFLECT\nfloat environmentAmount = texture2D( textureReflect, texCoord).r;\n#endif\n#if TEXTURE_ENVSPHERE\n#if TEXTURE_NORMAL\nvec3 r = reflect( envTexCoordOut, n );\nfloat m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );\nvec3 coord;\ncoord.s = r.x/m + 0.5;\ncoord.t = r.y/m + 0.5;\n#if TEXTURE_REFLECT\ncolor.rgb += materialColor*texture2D( textureEnvSphere, coord.st).rgb * environmentAmount;\n#else\ncolor.rgb += materialColor*texture2D( textureEnvSphere, coord.st).rgb * materialEnvironment;\n#endif\n#else\n#if TEXTURE_REFLECT\ncolor.rgb += materialColor*texture2D( textureEnvSphere, envTexCoordOut).rgb * environmentAmount;\n#else\ncolor.rgb += materialColor*texture2D( textureEnvSphere, envTexCoordOut).rgb * materialEnvironment;\n#endif\n#endif\n#endif \n#endif \n#if FX_DEPTH_ALPHA\n#if !MATERIAL_ALPHA\nfloat linear_depth = DepthRange( ConvertDepth3(gl_FragCoord.z) );\ncolor.a = linear_depth;\n#endif\n#endif\nreturn color;\n}\n#if LIGHT_DEPTH_PASS\nvec4 cubicvr_depthPack(vec2 texCoord) {\n#if TEXTURE_ALPHA\nfloat alphaVal = texture2D(textureAlpha, texCoord).r;\nif (alphaVal < 0.9) discard;\n#endif\nreturn packFloatToVec4i(DepthRange( ConvertDepth3(gl_FragCoord.z)));\n}\n#endif\n#define customShader_splice 1\nvoid main(void)\n{\nvec2 texCoord = cubicvr_texCoord();\n#if !LIGHT_DEPTH_PASS\nvec4 color = cubicvr_color(texCoord);\nvec3 normal = cubicvr_normal(texCoord);\ncolor = cubicvr_environment(color,normal,texCoord);\ncolor = cubicvr_lighting(color,normal,texCoord);\ngl_FragColor = clamp(color,0.0,1.0);\n#else \ngl_FragColor = cubicvr_depthPack(texCoord);\n#endif\n}\n",define("CubicVR",function(){});if(typeof define!="function")var define=require("amdefine")(module);define("src/services/target",["require","common/guid","CubicVR"],function(a){var b=a("common/guid");a("CubicVR");var c=function(a){this.element=a,this.context=CubicVR.init({context:b(),canvas:this.element})};return c});if(typeof define!="function")var define=require("amdefine")(module);define("core/event",["require"],function(a){var b=function(a,b,c){function d(){var a,b;for(a=0,b=arguments.length;a<b;++a)try{var c=arguments[a];c.handleEvent&&c.handleEvent(d)}catch(e){console.log(e)}}return d.type=a,d.data=b,d.queue=undefined!==c?c:!0,d};return b});if(typeof define!="function")var define=require("amdefine")(module);define("src/services/renderer",["require","base/service","CubicVR","src/services/target","core/event"],function(a){function f(){var a=this.target.context,b=this._registeredComponents,c=a.GLCore.gl,e={},f,g,h,i=new d("Update",undefined,!1);for(var j in b)for(var k in b[j]){h=b[j][k];while(h.handleQueuedEvent());i(h)}c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT);var l=Object.keys(b.Camera||{});l.forEach(function(a){var c=b.Camera[a].owner.space;e.hasOwnProperty(c.id)||(e[c.id]=c)});var m=Object.keys(e);for(f=0,g=m.length;f<g;++f){var n=m[f],o=e[n],p,q,r=o.findAllWith("Camera"),s=o.findAllWith("Model"),t=o.findAllWith("Light"),u=[];for(p=0,q=t.length;p<q;++p){var v=t[p].findComponent("Light");u.push(v._cubicvrLight)}for(p=0,q=r.length;p<q;++p){var w=r[p].findComponent("Camera");u.forEach(function(a){a.prepare(w._cubicvrCamera)});for(var x=0,y=s.length;x<y;++x){var z=s[x].findComponent("Model"),A=s[x].findComponent("Transform");z._cubicvrMesh.instanceMaterials=[z._cubicvrMaterialDefinition],a.renderObject(z._cubicvrMesh,w._cubicvrCamera,A.absolute(),u),z._cubicvrMesh.instanceMaterials=null}}}}var b=a("base/service");a("CubicVR");var c=a("src/services/target"),d=a("core/event"),e=function(a,d){d=d||{};var e={render:{tags:["@render","graphics"],dependsOn:[]}};b.call(this,a,e),this.target=new c(d.canvas)};return e.prototype=new b,e.prototype.constructor=e,e.prototype.render=f,e});if(typeof define!="function")var define=require("amdefine")(module);define("common/extend",["require"],function(a){function b(a,b){for(var c in b)!a.hasOwnProperty(c)&&b.hasOwnProperty(c)&&(a[c]=b[c]);return a}return b});if(typeof define!="function")var define=require("amdefine")(module);define("base/component",["require","core/event"],function(a){function d(a){if(a!==this.owner){var c=this.owner;this.owner=a;var d=new b("ComponentOwnerChanged",{current:a,previous:c},!1);d(this)}}function e(a){if("on"+a.type in this)if(a.queue)this._queuedEvents.push(a);else{var b=this["on"+a.type];try{b.call(this,a)}catch(c){console.log(c)}}}function f(){if(this._queuedEvents.length>0){var a=this._queuedEvents.shift();if("on"+a.type in this){var b=this["on"+a.type];try{b.call(this,a)}catch(c){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;p<b.length;p++){r=o(b[p],g),l=r.f;if(l==="require")h[p]=k(a);else if(l==="exports")h[p]=e[a]={},i=!0;else if(l==="module")j=h[p]={id:a,uri:"",exports:e[a]};else if(e.hasOwnProperty(l)||f.hasOwnProperty(l))h[p]=n(l);else{if(!r.p)throw a+" missing "+l;r.p.load(r.n,k(g,!0),m(l),{}),h[p]=e[l]}}q=c.apply(e[a],h),a&&(j&&j.exports!==d?e[a]=j.exports:i||(e[a]=q))}else a&&(e[a]=c)},a=i=function(a,b,c,e){return typeof a=="string"?n(o(a,b).f):(a.splice||(b.splice?(a=b,b=arguments[2]):a=[]),e?h(d,a,b,c):setTimeout(function(){h(d,a,b,c)},15),i)},i.config=function(){return i},b||(b=i),c=function(a,b,d){b.splice||(d=b,b=[]),c.unordered?f[a]=[a,b,d]:h(a,b,d)},c.amd={jQuery:!0}}(),c("../tools/almond",function(){}),Array.prototype.remove||(Array.prototype.remove=function(a,b){var c=this.slice((b||a)+1||this.length);return this.length=a<0?this.length+a:a,this.push.apply(this,c)}),c("lang",["require"],function(a){return{bind:function(b,c){return function(){return c.apply(b,arguments)}},extend:function(b,c){for(var d in c)!b.hasOwnProperty(d)&&c.hasOwnProperty(d)&&(b[d]=c[d])}}}),c("constants",["require"],function(a){return function(){var a={TAU:2*Math.PI,PI:Math.PI,HALF_PI:Math.PI/2};return a}}),c("vector/vector",["require"],function(a){return function(a){var b=function(b,c){var d=null;1===c.length?d=c[0]:d=c;var e=new a(b);for(var f=0;f<b;++f)e[f]=d[f];return e},c={$:b,add:function(a,b,c){for(var d=0;d<a.length;++d)c[d]+=a[d]+b[d];return c},clear:function(a){for(var b=0;b<a.length;++b)a[b]=0},dot:function(a,b){var c=0;for(var d=0;d<a.length;++d)c+=a[d]*b[d];return c},equal:function(a,b,c){c=c||1e-6;if(a.length!=b.length)return!1;var d=a.length;for(var e=0;e<d;++e)if(Math.abs(a[e]-b[e])>c)return!1;return!0},length:function(a){var b=0;for(var c=0;c<a.length;++c)b+=a[c]*a[c];return Math.sqrt(b)},multiply:function(a,b,c){for(var d=0;d<a.length;++d)c[d]=a[d]*b;return c},negate:function(a,b){for(var c=0;c<a.length;++c)b[c]=a[c]*-1;return b},normalize:function(a,b){var d=a.length;for(var e=0,f=c.length(a);e<d;++e)b[e]=a[e]/f;return b},subtract:function(a,b,c){for(var d=0;d<a.length;++d)c[d]=a[d]-b[d];return c}};return Object.defineProperty(c,"x",{get:function(){return Vector2([1,0])},enumerable:!0}),Object.defineProperty(c,"u",{get:function(){return Vector2([1,0])},enumerable:!0}),Object.defineProperty(c,"y",{get:function(){return Vector2([0,1])},enumerable:!0}),Object.defineProperty(c,"v",{get:function(){return Vector2([0,1])},enumerable:!0}),Object.defineProperty(c,"zero",{get:function(){return Vector2([0,0])},enumerable:!0}),Object.defineProperty(c,"one",{get:function(){return Vector2([1,1])},enumerable:!0}),c}}),c("vector/vector2",["require","./vector","../constants"],function(a){return function(b){var c=a("./vector")(b),d=a("../constants")(),e=function(){return 0===arguments.length?c.$(2,[0,0]):c.$(2,arguments)},f={$:e,add:function(a,b,d){return d=d||e(),c.add(a,b,d)},angle:function(a,b){var d=e(),f=e();return c.normalize(a,d),c.normalize(b,f),Math.acos(c.dot(d,f))},clear:c.clear,dot:c.dot,equal:c.equal,length:c.length,multiply:function(a,b,d){return d=d||e(),c.multiply(a,b,d)},negate:function(a,b){return b=b||e(),c.negate(a,b)},normalize:function(a,b){b=b||e();var d=c.length(a);return b[0]=a[0]/d,b[1]=a[1]/d,b},project:function(a,b,c){c=c||e();var d=a[0]*b[0]+a[1]*b[1],f=d/(b[0]*b[0]+b[1]*b[1]);return c[0]=f*b[0],c[1]=f*b[1],c},set:function(a,b,c){a[0]=b,a[1]=c},subtract:function(a,b,d){return d=d||e(),c.subtract(a,b,d)}};return Object.defineProperty(f,"x",{get:function(){return e([1,0])},enumerable:!0}),Object.defineProperty(f,"u",{get:function(){return e([1,0])},enumerable:!0}),Object.defineProperty(f,"y",{get:function(){return e([0,1])},enumerable:!0}),Object.defineProperty(f,"v",{get:function(){return e([0,1])},enumerable:!0}),Object.defineProperty(f,"zero",{get:function(){return e([0,0])},enumerable:!0}),Object.defineProperty(f,"one",{get:function(){return e([1,1])},enumerable:!0}),f}}),c("vector/vector3",["require","./vector"],function(a){return function(b){var c=a("./vector")(b),d=function(){return 0===arguments.length?c.$(3,[0,0,0]):c.$(3,arguments)},e={$:d,add:function(a,b,e){return e=e||d(),c.add(a,b,e)},angle:function(a,b){return Math.acos((a[0]*b[0]+a[1]*b[1]+a[2]*b[2])/(Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])*Math.sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2])))},clear:c.clear,cross:function(a,b,c){return c=c||d(),c[0]=a[1]*b[2]-b[1]*a[2],c[1]=a[2]*b[0]-b[2]*a[0],c[2]=a[0]*b[1]-b[0]*a[1],c},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},equal:c.equal,length:c.length,multiply:function(a,b,e){return e=e||d(),c.multiply(a,b,e)},normal:function(a,b,c){return c=c||d(),d.cross(a,b,c)},normalize:function(a,b){b=b||d();var e=c.length(a);return b[0]=a[0]/e,b[1]=a[1]/e,b[2]=a[2]/e,b},set:function(a,b,c,d){a[0]=b,a[1]=c,a[2]=d},subtract:function(a,b,e){return e=e||d(),c.subtract(a,b,e)}};return Object.defineProperty(e,"x",{get:function(){return d([1,0,0])},enumerable:!0}),Object.defineProperty(e,"y",{get:function(){return d([0,1,0])},enumerable:!0}),Object.defineProperty(e,"z",{get:function(){return d([0,0,1])},enumerable:!0}),Object.defineProperty(e,"zero",{get:function(){return d([0,0,0])},enumerable:!0}),Object.defineProperty(e,"one",{get:function(){return d([1,1,1])},enumerable:!0}),e}}),c("vector/vector4",["require","./vector"],function(a){return function(b){var c=a("./vector")(b),d=function(){return 0===arguments.length?c.$(4,[0,0,0,0]):c.$(4,arguments)},e={$:d,add:function(a,b,c){return c=c||d(),c[0]=a[0]+b[0],c[1]=a[1]+b[1],c[2]=a[2]+b[2],c[3]=a[3]+b[3],c},angle:function(a,b){return Math.acos((a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3])/(Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3])*Math.sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2]+b[3]*b[3])))},clear:c.clear,dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},equal:c.equal,length:c.length,multiply:function(a,b,e){return e=e||d(),c.multiply(a,b,e)},normalize:function(a,b){b=b||d();var e=c.length(a);return b[0]=a[0]/e,b[1]=a[1]/e,b[2]=a[2]/e,b[3]=a[3]/e,b},set:function(a,b,c,d,e){a[0]=b,a[1]=c,a[2]=d,a[3]=e},subtract:function(a,b,e){return e=e||d(),c.subtract(a,b,e)}};return Object.defineProperty(e,"x",{get:function(){return d([1,0,0,0])},enumerable:!0}),Object.defineProperty(e,"y",{get:function(){return d([0,1,0,0])},enumerable:!0}),Object.defineProperty(e,"z",{get:function(){return d([0,0,1,0])},enumerable:!0}),Object.defineProperty(e,"w",{get:function(){return d([0,0,0,1])},enumerable:!0}),Object.defineProperty(e,"zero",{get:function(){return d([0,0,0,0])},enumerable:!0}),Object.defineProperty(e,"one",{get:function(){return d([1,1,1,1])},enumerable:!0}),e}}),c("vector/quaternion",["require","./vector4","./vector3"],function(a){return function(b){var c=a("./vector4")(b),d=a("./vector3")(b),e=c.$,f={$:e,to:{rpy:function(a,b){var c=b||d.$(),e=Math.atan2,f=Math.asin;c[0]=e(2*a[0]*a[1]+2*a[2]*a[3],1-2*a[1]*a[1]+2*a[2]*a[2]),c[1]=f(2*a[0]*a[2]-2*a[3]*a[1]),c[2]=e(2*a[0]*a[3]+2*a[1]*a[2],1-2*a[2]*a[2]+2*a[3]*a[3]);if(!b)return c}},from:{rpy:function(a,b){var c=b||f.$(),d=Math.sin,e=Math.cos,g=a[0]/2,h=a[1]/2,i=a[2]/2,j=d(g),k=e(g),l=d(h),m=e(h),n=d(i),o=e(i);c[0]=k*m*o+j*l*n,c[1]=j*m*o-k*l*n,c[2]=k*l*o+j*m*n,c[3]=k*m*n-j*l*o;if(!b)return c}},length:c.length,multiply:function(a,b,c){var d=c||f.$();d[0]=a[3]*b[0]+a[0]*b[3]+a[1]*b[2]-a[2]*b[1],d[1]=a[3]*b[1]-a[0]*b[2]+a[1]*b[3]+a[2]*b[0],d[2]=a[3]*b[2]+a[0]*b[1]-a[1]*b[0]+a[2]*b[3],d[3]=a[3]*b[3]-a[0]*b[0]-a[1]*b[1]-a[2]*b[2];if(!c)return d},normalize:c.normalize};return Object.defineProperty(f,"identity",{get:function(){return e([0,0,0,1])},enumerable:!0}),f}}),c("matrix/matrix",["require"],function(a){return function(a){var b=function(b,c){var d=null;1===c.length?d=c[0]:d=c;var e=new a(b);for(var f=0;f<b;++f)e[f]=d[f];return e},c={$:b,add:function(a,b,c){for(var d=0;d<a.length;++d)c[d]+=a[d]+b[d];return c},subtract:function(a,b,c){for(var d=0;d<a.length;++d)a[d]-=b[d];return a},clear:function(a){for(var b=0;b<a.length;++b)a[b]=0},equal:function(a,b,c){c=c||1e-6;if(a.length!=b.length)return!1;var d=a.length;for(var e=0;e<d;++e)if(Math.abs(a[e]-b[e])>c)return!1;return!0}};return c}}),c("matrix/matrix2",["require","./matrix"],function(a){return function(b){var c=a("./matrix")(b),d=function(){return 0===arguments.length?c.$(4,[0,0,0,0]):c.$(4,arguments)},e={$:d,add:function(a,b){b=b||d();var e=a[0];if(a.length==1)b=e;else for(var f=1;f<a.length;++f)b=c.add(e,a[f],b),e=b;return b},subtract:function(a,b){b=b||d();var e=a[0];if(a.length==1)b=e;else{var e=a[0];for(var f=1;f<a.length;++f)b=c.subtract(e,a[f],b),e=b}return b},clear:c.clear,equal:c.equal,determinant:function(a){return a[0]*a[3]-a[1]*a[2]},inverse:function(a,b){var c=e.determinant(a);if(c==0)throw"matrix is singular";return b=b||d(),b[0]=a[3]/c,b[1]=a[1]*-1/c,b[2]=a[2]*-1/c,b[3]=a[0]/c,b},multiply:function(a,b){b=b||d();if(a.length==1)return a[0];var c=a[0];for(var e=1;e<a.length;++e)b[0]=c[0]*a[e][0]+c[1]*a[e][2],b[1]=c[0]*a[e][1]+c[1]*a[e][3],b[2]=c[2]*a[e][0]+c[3]*a[e][2],b[3]=c[2]*a[e][1]+c[3]*a[e][3],c=b;return b},transpose:function(a,b){b=b||d();var c=a[1];return b[0]=a[0],b[1]=a[2],b[2]=c,b[3]=a[3],b}};return Object.defineProperty(e,"zero",{get:function(){return d([0,0,0,0])},enumerable:!0}),Object.defineProperty(e,"one",{get:function(){return d([1,1,1,1])},enumerable:!0}),Object.defineProperty(e,"identity",{get:function(){return d([1,0,0,1])},enumerable:!0}),e}}),c("matrix/matrix3",["require","./matrix"],function(a){return function(b){var c=a("./matrix")(b),d=function(){return 0===arguments.length?c.$(9,[0,0,0,0,0,0,0,0,0]):c.$(9,arguments)},e={$:d,add:function(a,b){b=b||d();if(a.length==1)return a[0];var e=a[0];for(var f=1;f<a.length;++f)b=c.add(e,a[f],b),e=b;return b},subtract:function(a,b){b=b||d();var e=a[0];if(a.length==1)b=e;else for(var f=1;f<a.length;++f)b=c.subtract(e,a[f],b),e=b;return b},clear:c.clear,equal:c.equal,determinant:function(a){return a[0]*(a[4]*a[8]-a[5]*a[7])-a[1]*(a[3]*a[8]-a[5]*a[6])+a[2]*(a[3]*a[7]-a[4]*a[6])},inverse:function(a,b){var c=e.determinant(a);if(c==0)throw"matrix is singular";return b=b||d(),b[0]=(a[8]*a[4]-a[7]*a[5])/c,b[1]=-(a[8]*a[1]-a[7]*[2])/c,b[2]=(a[5]*a[1]-a[4]*a[2])/c,b[3]=-(a[8]*a[3]-a[6]*a[5])/c,b[4]=(a[8]*a[0]-a[6]*a[2])/c,b[5]=-(a[5]*a[0]-a[3]*a[2])/c,b[6]=(a[7]*a[3]-a[6]*a[4])/c,b[7]=-(a[7]*a[0]-a[6]*a[1])/c,b[8]=(a[4]*a[0]-a[3]*a[1])/c,b},multiply:function(a,b){b=b||d();if(a.length==1)return a[0];var c=a[0];for(var e=1;e<a.length;++e)b[0]=c[0]*a[e][0]+c[1]*a[e][3]+c[2]*a[e][6],b[1]=c[0]*a[e][1]+c[1]*a[e][4]+c[2]*a[e][7],b[2]=c[0]*a[e][2]+c[1]*a[e][5]+c[2]*a[e][8],b[3]=c[3]*a[e][0]+c[4]*a[e][3]+c[5]*a[e][6],b[4]=c[3]*a[e][1]+c[4]*a[e][4]+c[5]*a[e][7],b[5]=c[3]*a[e][2]+c[4]*a[e][5]+c[5]*a[e][8],b[6]=c[6]*a[e][0]+c[7]*a[e][3]+c[8]*a[e][6],b[7]=c[6]*a[e][1]+c[7]*a[e][4]+c[8]*a[e][7],b[8]=c[6]*a[e][2]+c[7]*a[e][5]+c[8]*a[e][8],c=b;return b},rotate:function(a,b){var c=b||e.identity,d,f,g;0!==a[2]&&(d=Math.sin(a[2]),f=Math.cos(a[2]),g=[],g.push(e.$([f,d,0,-d,f,0,0,0,1])),g.push(e.$(c)),e.multiply(g,c)),0!==a[1]&&(d=Math.sin(a[1]),f=Math.cos(a[1]),g=[],g.push(e.$([f,0,-d,0,1,0,d,0,f])),g.push(e.$(c)),e.multiply(g,c)),0!==a[0]&&(d=Math.sin(a[0]),f=Math.cos(a[0]),g=[],g.push(e.$([1,0,0,0,f,d,0,-d,f])),g.push(e.$(c)),e.multiply(g,c));if(!b)return c},transpose:function(a,b){b=b||d();var c=a[1],e=a[2],f=a[5];return b[0]=a[0],b[1]=a[3],b[2]=a[6],b[3]=c,b[4]=a[4],b[5]=a[7],b[6]=e,b[7]=f,b[8]=a[8],b}};return Object.defineProperty(e,"zero",{get:function(){return d([0,0,0,0,0,0,0,0,0])},enumerable:!0}),Object.defineProperty(e,"one",{get:function(){return d([1,1,1,1,1,1,1,1,1])},enumerable:!0}),Object.defineProperty(e,"identity",{get:function(){return d([1,0,0,0,1,0,0,0,1])},enumerable:!0}),e}}),c("matrix/matrix4",["require","./matrix","../vector/vector3"],function(a){return function(b){var c=a("./matrix")(b),d=a("../vector/vector3")(b),e=function(){return 0===arguments.length?c.$(16,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]):c.$(16,arguments)},f={$:e,add:function(a,b){b=b||e();if(a.length==1)return a[0];var d=a[0];for(var f=1;f<a.length;++f)b=c.add(d,a[f],b),d=b;return b},subtract:function(a,b){b=b||e();var d=a[0];if(a.length==1)b=d;else for(var f=1;f<a.length;++f)b=c.subtract(d,a[f],b),d=b;return b},clear:c.clear,equal:c.equal,multiply:function(a,b){b=b||e();if(a.length==1)return a[0];var c=a[0];for(var d=1;d<a.length;++d)b[0]=c[0]*a[d][0]+c[1]*a[d][4]+c[2]*a[d][8]+c[3]*a[d][12],b[1]=c[0]*a[d][1]+c[1]*a[d][5]+c[2]*a[d][9]+c[3]*a[d][13],b[2]=c[0]*a[d][2]+c[1]*a[d][6]+c[2]*a[d][10]+c[3]*a[d][14],b[3]=c[0]*a[d][3]+c[1]*a[d][7]+c[2]*a[d][11]+c[3]*a[d][15],b[4]=c[4]*a[d][0]+c[5]*a[d][4]+c[6]*a[d][8]+c[7]*a[d][12],b[5]=c[4]*a[d][1]+c[5]*a[d][5]+c[6]*a[d][9]+c[7]*a[d][13],b[6]=c[4]*a[d][2]+c[5]*a[d][6]+c[6]*a[d][10]+c[7]*a[d][14],b[7]=c[4]*a[d][3]+c[5]*a[d][7]+c[6]*a[d][11]+c[7]*
a[d][15],b[8]=c[8]*a[d][0]+c[9]*a[d][4]+c[10]*a[d][8]+c[11]*a[d][12],b[9]=c[8]*a[d][1]+c[9]*a[d][5]+c[10]*a[d][9]+c[11]*a[d][13],b[10]=c[8]*a[d][2]+c[9]*a[d][6]+c[10]*a[d][10]+c[11]*a[d][14],b[11]=c[8]*a[d][3]+c[9]*a[d][7]+c[10]*a[d][11]+c[11]*a[d][15],b[12]=c[12]*a[d][0]+c[13]*a[d][4]+c[14]*a[d][8]+c[15]*a[d][12],b[13]=c[12]*a[d][1]+c[13]*a[d][5]+c[14]*a[d][9]+c[15]*a[d][13],b[14]=c[12]*a[d][2]+c[13]*a[d][6]+c[14]*a[d][10]+c[15]*a[d][14],b[15]=c[12]*a[d][3]+c[13]*a[d][7]+c[14]*a[d][11]+c[15]*a[d][15],c=b;return b},multiplyVector3:function(a,b,c){return c=c||d.$(),c[0]=a[0]*b[0]+a[4]*b[1]+a[8]*b[2]+a[12],c[1]=a[1]*b[0]+a[5]*b[1]+a[9]*b[2]+a[13],c[2]=a[2]*b[0]+a[6]*b[1]+a[10]*b[2]+a[14],c},determinant:function(a){var b=a[0]*a[5]-a[1]*a[4],c=a[0]*a[6]-a[2]*a[4],d=a[0]*a[7]-a[3]*a[4],e=a[1]*a[6]-a[2]*a[5],f=a[1]*a[7]-a[3]*a[5],g=a[2]*a[7]-a[3]*a[6],h=a[8]*a[13]-a[9]*a[12],i=a[8]*a[14]-a[10]*a[12],j=a[8]*a[15]-a[11]*a[12],k=a[9]*a[14]-a[10]*a[13],l=a[9]*a[15]-a[11]*a[13],m=a[10]*a[15]-a[11]*a[14],n=b*m-c*l+d*k+e*j-f*i+g*h;return n},transpose:function(a,b){return b=b||e(),b[0]=a[0],b[1]=a[4],b[2]=a[8],b[3]=a[12],b[4]=a[1],b[5]=a[5],b[6]=a[9],b[7]=a[13],b[8]=a[2],b[9]=a[6],b[10]=a[10],b[11]=a[14],b[12]=a[3],b[13]=a[7],b[14]=a[11],b[15]=a[15],b},inverse:function(a,b){b=b||e();var c=a[0],d=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=a[9],n=a[10],o=a[11],p=a[12],q=a[13],r=a[14],s=a[15],t=c*i-d*h,u=c*j-f*h,v=c*k-g*h,w=d*j-f*i,x=d*k-g*i,y=f*k-g*j,z=l*q-m*p,A=l*r-n*p,B=l*s-o*p,C=m*r-n*q,D=m*s-o*q,E=n*s-o*r,F=t*E-u*D+v*C+w*B-x*A+y*z,G;if(!F)throw"matrix is singular";return G=1/F,b[0]=(i*E-j*D+k*C)*G,b[1]=(-d*E+f*D-g*C)*G,b[2]=(q*y-r*x+s*w)*G,b[3]=(-m*y+n*x-o*w)*G,b[4]=(-h*E+j*B-k*A)*G,b[5]=(c*E-f*B+g*A)*G,b[6]=(-p*y+r*v-s*u)*G,b[7]=(l*y-n*v+o*u)*G,b[8]=(h*D-i*B+k*z)*G,b[9]=(-c*D+d*B-g*z)*G,b[10]=(p*x-q*v+s*t)*G,b[11]=(-l*x+m*v-o*t)*G,b[12]=(-h*C+i*A-j*z)*G,b[13]=(c*C-d*A+f*z)*G,b[14]=(-p*w+q*u-r*t)*G,b[15]=(l*w-m*u+n*t)*G,b},toHTML:function(a){var b="[ ";for(var c=0;c<4;++c){b+="<br>";for(var d=0;d<4;++d)b+=" ("+a[4*c+d]+") "}return b+=" ]",b}};return Object.defineProperty(f,"zero",{get:function(){return e([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])},enumerable:!0}),Object.defineProperty(f,"one",{get:function(){return e([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1])},enumerable:!0}),Object.defineProperty(f,"identity",{get:function(){return e([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])},enumerable:!0}),f}}),c("matrix/transform",["require","./matrix4"],function(a){return function(b){var c=a("./matrix4")(b),d=c.$,e={$:d,fixed:function(a,b,d){var f=c.identity;return a&&e.translate(a,f),b&&e.rotate(b,f),d&&e.scale(d,f),f},rotate:function(a,b){var d=b||c.identity,e,f,g;0!==a[2]&&(e=Math.sin(a[2]),f=Math.cos(a[2]),g=[],g.push(c.$([f,e,0,0,-e,f,0,0,0,0,1,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d)),0!==a[1]&&(e=Math.sin(a[1]),f=Math.cos(a[1]),g=[],g.push(c.$([f,0,-e,0,0,1,0,0,e,0,f,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d)),0!==a[0]&&(e=Math.sin(a[0]),f=Math.cos(a[0]),g=[],g.push(c.$([1,0,0,0,0,f,e,0,0,-e,f,0,0,0,0,1])),g.push(c.$(d)),c.multiply(g,d));if(!b)return d},scale:function(a,b){var d=[a[0],0,0,0,0,a[1],0,0,0,0,a[2],0,0,0,0,1];if(!b)return d;c.multiply([d,c.$(b)],b)},translate:function(a,b){var d=[1,0,0,0,0,1,0,0,0,0,1,0,a[0],a[1],a[2],1];if(!b)return d;c.multiply([d,c.$(b)],b)}};return e}}),c("_math",["require","./lang","./constants","./vector/vector2","./vector/vector3","./vector/vector4","./vector/quaternion","./matrix/matrix2","./matrix/matrix3","./matrix/matrix4","./matrix/transform"],function(a){var b=a("./lang"),c=a("./constants"),d=a("./vector/vector2"),e=a("./vector/vector3"),f=a("./vector/vector4"),g=a("./vector/quaternion"),h=a("./matrix/matrix2"),i=a("./matrix/matrix3"),j=a("./matrix/matrix4"),k=a("./matrix/transform"),l=function(a){var l={Float32:Float32Array,Float64:Float64Array},m=l.Float32;Object.defineProperty(this,"ARRAY_TYPE",{get:function(){return m},enumerable:!0}),b.extend(this,c());var n=d(m),o=e(m),p=f(m),q=g(m),r=h(m),s=i(m),t=j(m),u=k(m);Object.defineProperty(this,"Vector2",{get:function(){return n.$},enumerable:!0}),Object.defineProperty(this,"vector2",{get:function(){return n},enumerable:!0}),Object.defineProperty(this,"Vector3",{get:function(){return o.$},enumerable:!0}),Object.defineProperty(this,"vector3",{get:function(){return o},enumerable:!0}),Object.defineProperty(this,"Vector4",{get:function(){return p.$},enumerable:!0}),Object.defineProperty(this,"vector4",{get:function(){return p},enumerable:!0}),Object.defineProperty(this,"Quaternion",{get:function(){return q.$},enumerable:!0}),Object.defineProperty(this,"quaternion",{get:function(){return q},enumerable:!0}),Object.defineProperty(this,"Matrix2",{get:function(){return r.$},enumerable:!0}),Object.defineProperty(this,"matrix2",{get:function(){return r},enumerable:!0}),Object.defineProperty(this,"Matrix3",{get:function(){return s.$},enumerable:!0}),Object.defineProperty(this,"matrix3",{get:function(){return s},enumerable:!0}),Object.defineProperty(this,"Matrix4",{get:function(){return t.$},enumerable:!0}),Object.defineProperty(this,"matrix4",{get:function(){return t},enumerable:!0}),Object.defineProperty(this,"Transform",{get:function(){return u.$},enumerable:!0}),Object.defineProperty(this,"transform",{get:function(){return u},enumerable:!0})};return new l}),b("_math")});if(typeof 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<f.length;b++)this._cubicvrLight[f[b]]=this[f[b]];this._cubicvrLight.parent.tMatrix=this.owner.findComponent("Transform").absolute()}function i(a){var b=a.data;b.previous===null&&b.current!==null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),this.owner&&(this._cubicvrLight.parent.tMatrix=this.owner.findComponent("Transform").absolute()),b.previous!==null&&b.current===null&&this.owner!==null&&this.provider.unregisterComponent(this.owner.id,this)}function j(a){var b=a.data;b.previous===null&&this.owner!==null&&this.provider.registerComponent(this.owner.id,this),this.owner&&(this._cubicvrLight.parent.tMatrix=this.owner.findComponent("Transform").absolute()),this.owner===null&&b.previous!==null&&this.provider.unregisterComponent(b.previous.id,this)}function k(a){var b=a.data;b?this.provider.registerComponent(this.owner.id,this):this.provider.unregisterComponent(this.owner.id,this)}var b=a("src/resources/light-definition"),c=a("base/component"),d=a("common/extend"),e=a("_math"),f=["light_type","diffuse","specular","intensity","distance","cutoff","map_res","method","areaCeiling","areaFloor","areaAxis"],g=function(a,d){c.call(this,"Light",a,["Transform"]),d instanceof b||(d=new b),this._cubicvrLight=new a.target.context.Light(d),this._cubicvrLight.parent={tMatrix:e.matrix4.identity};for(var g=0;g<f.length;g++)this[f[g]]=d[f[g]]};g.prototype=new c,g.prototype.constructor=g;var l={onUpdate:h,onEntitySpaceChanged:i,onComponentOwnerChanged:j,onEntityActivationChanged:k};return d(g.prototype,l),g});if(typeof define!="function")var define=require("amdefine")(module);define("../src/gladius-cubicvr",["require","base/extension","src/services/renderer","src/components/camera","src/components/light","src/components/model","src/resources/mesh","src/resources/material-definition","src/resources/light-definition"],function(a){var b=a("base/extension");return new b("gladius-cubicvr",{services:{renderer:{service:a("src/services/renderer"),components:{Camera:a("src/components/camera"),Light:a("src/components/light"),Model:a("src/components/model")},resources:{Mesh:a("src/resources/mesh"),MaterialDefinition:a("src/resources/material-definition")}}},components:{},resources:{LightDefinition:a("src/resources/light-definition")}})});var extension=require("../src/gladius-cubicvr");return extension});