From 937c4293e5f6484f22e10bb2ea2a84a1647d2134 Mon Sep 17 00:00:00 2001
From: sasha240100 <siteprogcom@gmail.com>
Date: Sun, 14 Feb 2016 22:28:30 +0200
Subject: [PATCH] Wagner moved to plugins. Fixed #53

---
 CHANGELOG.md                    |   1 +
 build/whitestorm.js             | 167 --------------------------------
 build/whitestorm.min.js         |   6 +-
 build/whitestorm.test.js        |   6 +-
 examples/basic.html             |   5 -
 examples/basic_material.html    |   5 -
 examples/basic_model.html       |   4 -
 examples/fps.html               |   1 +
 examples/js/game.js             |  13 ++-
 examples/plugin_example.html    |   4 -
 examples/plugins/whs.preload.js |   2 +-
 examples/plugins/whs.wagner.js  | 205 ++++++++++++++++++++++++++++++++++++++++
 examples/skybox.html            |   5 -
 examples/stone_wall.html        |   7 +-
 gulpfile.js                     |   3 -
 src/Core.js                     |   5 +-
 src/Wagner/AddWagner.js         | 172 ---------------------------------
 src/Wagner/addWagner.js         | 172 ---------------------------------
 18 files changed, 222 insertions(+), 561 deletions(-)
 create mode 100644 examples/plugins/whs.wagner.js
 delete mode 100644 src/Wagner/AddWagner.js
 delete mode 100644 src/Wagner/addWagner.js

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2d3610b..560e028 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@
    - _process in start()
    - *this.update -> this._update*
    - _initScene()
+- #53: Wagner moved to plugins.
 
 **v0.0.7**
 - Fixed #16 "object.assign() chrome bug."
diff --git a/build/whitestorm.js b/build/whitestorm.js
index e2e26b0..861bf6f 100644
--- a/build/whitestorm.js
+++ b/build/whitestorm.js
@@ -2680,14 +2680,12 @@ WHS.init = function() {
 
         if (!THREE) console.warn('whitestormJS requires THREE.js. {Object} THREE not found.');
         if (!Physijs) console.warn('whitestormJS requires PHYSI.js. {Object} Physijs not found.');
-        if (!WAGNER) console.warn('whitestormJS requires WAGNER.js. {Object} WAGNER not found.');
 
         var target = api.extend(params, {
 
             anaglyph: false,
             helper: false,
             stats: false,
-            wagner: true,
             autoresize: false,
 
             shadowmap: true,
@@ -4136,171 +4134,6 @@ WHS.init.prototype.SpotLight = function(params) {
 };
 
 /**
- * Wagner.
- *
- * @param {Object} type Type of wagner effect. (REQUIRED)
- * @param {Object} params Parameters. (OPTIONAL)
- * @return {Object} Scope.
- */
-WHS.init.prototype.addWagner = function(type, params) {
-
-    'use strict';
-
-    params = params || {};
-
-    var scope = {
-        _composer: this._composer
-    };
-
-    var target = api.extend(params, {
-        hex: 0x000000,
-        near: 0.015,
-        far: 1000,
-        density: 0.00025
-    });
-
-    switch (type) {
-        case "ZoomBlurPass":
-            scope.effect = new WAGNER.ZoomBlurPass();
-
-            target = api.extend(target, {
-                strength: .05,
-
-                center: {
-                    x: .5 * this._composer.width,
-                    y: .5 * this._composer.height
-                }
-            });
-
-            break;
-
-        case "MultiPassBloomPass":
-            scope.effect = new WAGNER.MultiPassBloomPass();
-
-            target = api.extend(target, {
-                strength: .5,
-                blurAmount: 1.32,
-                applyZoomBlur: true,
-                zoomBlurStrength: 0.84,
-                useTexture: true,
-
-                center: {
-                    x: .5 * this._composer.width,
-                    y: .5 * this._composer.height
-                }
-            });
-
-            scope.effect.glowTexture = WAGNER.Pass.prototype.getOfflineTexture(this._composer.width, this._composer.height, false);
-
-            break;
-
-        case "VignettePass":
-            scope.effect = new WAGNER.VignettePass();
-
-            target = api.extend(target, {
-                amount: 0.7,
-                falloff: 0.2
-            });
-
-            break;
-
-        case "DirectionalBlurPass":
-            scope.effect = new WAGNER.DirectionalBlurPass();
-
-            target = api.extend(target, {
-                delta: 0.1
-            });
-
-            break;
-
-        case "MotionBlurPass":
-            scope.effect = new WAGNER.DirectionalBlurPass();
-
-            scope.motionBlurEnable = true;
-
-            target = api.extend(target, {
-                delta: 0
-            });
-
-            break;
-
-        case "ASCIIPass":
-            scope.effect = new WAGNER.ASCIIPass();
-
-            break;
-
-        case "DotScreenPass":
-            scope.effect = new WAGNER.DotScreenPass();
-
-            break;
-
-        case "FxaaPass":
-            scope.effect = new WAGNER.FXAAPass();
-
-            break;
-
-        case "ChromaticAberrationPass":
-            scope.effect = new WAGNER.ChromaticAberrationPass();
-
-            break;
-
-        case "DirtPass":
-            scope.effect = new WAGNER.DirtPass();
-
-            break;
-
-        case "EdgeDetectionPass":
-            scope.effect = new WAGNER.SobelEdgeDetectionPass();
-
-            break;
-
-        case "HighPassPass":
-            scope.effect = new WAGNER.HighPassPass();
-
-            break;
-
-        case "GrayscalePass":
-            scope.effect = new WAGNER.GrayscalePass();
-
-            break;
-
-        case "HalftonePass":
-            scope.effect = new WAGNER.HalftonePass();
-
-            break;
-
-        case "InvertPass":
-            scope.effect = new WAGNER.InvertPass();
-
-            break;
-
-        default:
-            console.warn("No Wagner effect \"" + type + "\" exists. If it should exist, open an issue. (@addWagner)");
-
-            return;
-    }
-
-    scope.effect.params = target;
-
-    this._composer.stack.addPass(type, true, target);
-
-    return scope;
-};
-
-WHS.init.prototype.initWagner = function() {
-
-    this._composer = new WAGNER.Composer(this._renderer);
-
-    this._composer.setSize(this._settings.rWidth, this._settings.rHeight);
-    this._composer.autoClearColor = true;
-
-    this._composer.reset();
-    this._composer.render(this.scene, this._camera);
-
-    this._composer.stack = new WAGNER.Stack(new WAGNER.ShadersPool());
-};
-
-/**
  * MAKEFIRSTPERSON.
  *
  * @param {Object} object *WHS* figure/object. (REQUIRED)
diff --git a/build/whitestorm.min.js b/build/whitestorm.min.js
index 7354021..b1e94e0 100644
--- a/build/whitestorm.min.js
+++ b/build/whitestorm.min.js
@@ -4,6 +4,6 @@
  * Email: alexbuzin88@gmail.com
 */
 
-"use strict";function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Events(e){var t={},r=[];e=e||this,e.on=function(e,r,n){(t[e]=t[e]||[]).push([r,n])},e.off=function(e,n){e||(t={});for(var o=t[e]||r,a=o.length=n?o.length:0;a--;)n==o[a][0]&&o.splice(a,1)},e.emit=function(e){for(var n,o=t[e]||r,a=0;n=o[a++];)n[0].apply(n[1],r.slice.call(arguments,1))}}function addCSSRule(e,t,r,n){e.insertRule?e.insertRule(t+"{"+r+"}",n):e.addRule&&e.addRule(t,r,n)}var _get=function e(t,r,n){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,r);if(void 0===o){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,n)}if("value"in o)return o.value;var i=o.get;if(void 0!==i)return i.call(n)},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};THREE.AnaglyphEffect=function(e,t,r){var n,o,a,i,s=new THREE.Matrix4,c=new THREE.Matrix4,l=125,h=new THREE.PerspectiveCamera;h.matrixAutoUpdate=!1;var u=new THREE.PerspectiveCamera;u.matrixAutoUpdate=!1;var p=new THREE.OrthographicCamera(-1,1,1,-1,0,1),d=new THREE.Scene,m={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat};void 0===t&&(t=512),void 0===r&&(r=512);var f=new THREE.WebGLRenderTarget(t,r,m),g=new THREE.WebGLRenderTarget(t,r,m),y=new THREE.ShaderMaterial({uniforms:{mapLeft:{type:"t",value:f},mapRight:{type:"t",value:g}},vertexShader:["varying vec2 vUv;","void main() {","	vUv = vec2( uv.x, uv.y );","	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform sampler2D mapLeft;","uniform sampler2D mapRight;","varying vec2 vUv;","void main() {","	vec4 colorL, colorR;","	vec2 uv = vUv;","	colorL = texture2D( mapLeft, uv );","	colorR = texture2D( mapRight, uv );","	gl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;","}"].join("\n")}),E=new THREE.Mesh(new THREE.PlaneBufferGeometry(2,2),y);d.add(E),this.setSize=function(t,r){f&&f.dispose(),g&&g.dispose(),f=new THREE.WebGLRenderTarget(t,r,m),g=new THREE.WebGLRenderTarget(t,r,m),y.uniforms.mapLeft.value=f,y.uniforms.mapRight.value=g,e.setSize(t,r)},this.render=function(t,r){t.updateMatrixWorld(),void 0===r.parent&&r.updateMatrixWorld();var m=n!==r.aspect||o!==r.near||a!==r.far||i!==r.fov;if(m){n=r.aspect,o=r.near,a=r.far,i=r.fov;var y,E,v=r.projectionMatrix.clone(),_=l/30*.5,b=_*o/l,w=o*Math.tan(THREE.Math.degToRad(.5*i));s.elements[12]=_,c.elements[12]=-_,y=-w*n+b,E=w*n+b,v.elements[0]=2*o/(E-y),v.elements[8]=(E+y)/(E-y),h.projectionMatrix.copy(v),y=-w*n-b,E=w*n-b,v.elements[0]=2*o/(E-y),v.elements[8]=(E+y)/(E-y),u.projectionMatrix.copy(v)}h.matrixWorld.copy(r.matrixWorld).multiply(c),h.position.copy(r.position),h.near=r.near,h.far=r.far,e.render(t,h,f,!0),u.matrixWorld.copy(r.matrixWorld).multiply(s),u.position.copy(r.position),u.near=r.near,u.far=r.far,e.render(t,u,g,!0),e.render(d,p)},this.dispose=function(){f&&f.dispose(),g&&g.dispose()}},THREE.BufferGeometryUtils={computeTangents:function(e){function t(e,t,r){m.fromArray(i,3*e),f.fromArray(i,3*t),g.fromArray(i,3*r),y.fromArray(c,2*e),E.fromArray(c,2*t),v.fromArray(c,2*r);var n=f.x-m.x,o=g.x-m.x,a=f.y-m.y,s=g.y-m.y,l=f.z-m.z,h=g.z-m.z,d=E.x-y.x,w=v.x-y.x,H=E.y-y.y,T=v.y-y.y,S=1/(d*T-w*H);_.set((T*n-H*o)*S,(T*a-H*s)*S,(T*l-H*h)*S),b.set((d*o-w*n)*S,(d*s-w*a)*S,(d*h-w*l)*S),u[e].add(_),u[t].add(_),u[r].add(_),p[e].add(b),p[t].add(b),p[r].add(b)}function r(e){L.fromArray(s,3*e),A.copy(L),C=u[e],M.copy(C),M.sub(L.multiplyScalar(L.dot(C))).normalize(),j.crossVectors(A,C),W=j.dot(p[e]),P=0>W?-1:1,h[4*e]=M.x,h[4*e+1]=M.y,h[4*e+2]=M.z,h[4*e+3]=P}var n=e.index,o=e.attributes;if(null===n||void 0===o.position||void 0===o.normal||void 0===o.uv)return void console.warn("THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()");var a=n.array,i=o.position.array,s=o.normal.array,c=o.uv.array,l=i.length/3;void 0===o.tangent&&e.addAttribute("tangent",new THREE.BufferAttribute(new Float32Array(4*l),4));for(var h=o.tangent.array,u=[],p=[],d=0;l>d;d++)u[d]=new THREE.Vector3,p[d]=new THREE.Vector3;var m=new THREE.Vector3,f=new THREE.Vector3,g=new THREE.Vector3,y=new THREE.Vector2,E=new THREE.Vector2,v=new THREE.Vector2,_=new THREE.Vector3,b=new THREE.Vector3,w=e.groups;0===w.length&&(w=[{start:0,count:a.length}]);for(var H=0,T=w.length;T>H;++H)for(var S=w[H],R=S.start,x=S.count,k=R,O=R+x;O>k;k+=3)t(a[k+0],a[k+1],a[k+2]);for(var P,C,W,M=new THREE.Vector3,j=new THREE.Vector3,L=new THREE.Vector3,A=new THREE.Vector3,H=0,T=w.length;T>H;++H)for(var S=w[H],R=S.start,x=S.count,k=R,O=R+x;O>k;k+=3)r(a[k+0]),r(a[k+1]),r(a[k+2])}},THREE.OrbitControls=function(e,t){function r(){return 2*Math.PI/60/60*p.autoRotateSpeed}function n(){return Math.pow(.95,p.zoomSpeed)}function o(e){if(p.enabled!==!1){if(e.preventDefault(),0===e.button){if(p.noRotate===!0)return;O=k.ROTATE,m.set(e.clientX,e.clientY)}else if(1===e.button){if(p.noZoom===!0)return;O=k.DOLLY,_.set(e.clientX,e.clientY)}else if(2===e.button){if(p.noPan===!0)return;O=k.PAN,y.set(e.clientX,e.clientY)}p.domElement.addEventListener("mousemove",a,!1),p.domElement.addEventListener("mouseup",i,!1)}}function a(e){if(p.enabled!==!1){e.preventDefault();var t=p.domElement===document?p.domElement.body:p.domElement;if(O===k.ROTATE){if(p.noRotate===!0)return;f.set(e.clientX,e.clientY),g.subVectors(f,m),p.rotateLeft(2*Math.PI*g.x/t.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*g.y/t.clientHeight*p.rotateSpeed),m.copy(f)}else if(O===k.DOLLY){if(p.noZoom===!0)return;b.set(e.clientX,e.clientY),w.subVectors(b,_),w.y>0?p.dollyIn():p.dollyOut(),_.copy(b)}else if(O===k.PAN){if(p.noPan===!0)return;E.set(e.clientX,e.clientY),v.subVectors(E,y),p.pan(v),y.copy(E)}p.update()}}function i(){p.enabled!==!1&&(p.domElement.removeEventListener("mousemove",a,!1),p.domElement.removeEventListener("mouseup",i,!1),O=k.NONE)}function s(e){if(p.enabled!==!1&&p.noZoom!==!0){var t=0;e.wheelDelta?t=e.wheelDelta:e.detail&&(t=-e.detail),t>0?p.dollyOut():p.dollyIn()}}function c(e){if(p.enabled!==!1&&p.noKeys!==!0&&p.noPan!==!0){var t=!1;switch(e.keyCode){case p.keys.UP:p.pan(new THREE.Vector2(0,p.keyPanSpeed)),t=!0;break;case p.keys.BOTTOM:p.pan(new THREE.Vector2(0,-p.keyPanSpeed)),t=!0;break;case p.keys.LEFT:p.pan(new THREE.Vector2(p.keyPanSpeed,0)),t=!0;break;case p.keys.RIGHT:p.pan(new THREE.Vector2(-p.keyPanSpeed,0)),t=!0}t&&p.update()}}function l(e){if(p.enabled!==!1)switch(e.touches.length){case 1:if(p.noRotate===!0)return;O=k.TOUCH_ROTATE,m.set(e.touches[0].pageX,e.touches[0].pageY);break;case 2:if(p.noZoom===!0)return;O=k.TOUCH_DOLLY;var t=e.touches[0].pageX-e.touches[1].pageX,r=e.touches[0].pageY-e.touches[1].pageY,n=Math.sqrt(t*t+r*r);_.set(0,n);break;case 3:if(p.noPan===!0)return;O=k.TOUCH_PAN,y.set(e.touches[0].pageX,e.touches[0].pageY);break;default:O=k.NONE}}function h(e){if(p.enabled!==!1){e.preventDefault(),e.stopPropagation();var t=p.domElement===document?p.domElement.body:p.domElement;switch(e.touches.length){case 1:if(p.noRotate===!0)return;if(O!==k.TOUCH_ROTATE)return;f.set(e.touches[0].pageX,e.touches[0].pageY),g.subVectors(f,m),p.rotateLeft(2*Math.PI*g.x/t.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*g.y/t.clientHeight*p.rotateSpeed),m.copy(f);break;case 2:if(p.noZoom===!0)return;if(O!==k.TOUCH_DOLLY)return;var r=e.touches[0].pageX-e.touches[1].pageX,n=e.touches[0].pageY-e.touches[1].pageY,o=Math.sqrt(r*r+n*n);b.set(0,o),w.subVectors(b,_),w.y>0?p.dollyOut():p.dollyIn(),_.copy(b);break;case 3:if(p.noPan===!0)return;if(O!==k.TOUCH_PAN)return;E.set(e.touches[0].pageX,e.touches[0].pageY),v.subVectors(E,y),p.pan(v),y.copy(E);break;default:O=k.NONE}}}function u(){p.enabled!==!1&&(O=k.NONE)}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.target=new THREE.Vector3,this.center=this.target,this.noZoom=!1,this.zoomSpeed=1,this.minDistance=0,this.maxDistance=1/0,this.noRotate=!1,this.rotateSpeed=1,this.noPan=!1,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.noKeys=!1,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40};var p=this,d=1e-6,m=new THREE.Vector2,f=new THREE.Vector2,g=new THREE.Vector2,y=new THREE.Vector2,E=new THREE.Vector2,v=new THREE.Vector2,_=new THREE.Vector2,b=new THREE.Vector2,w=new THREE.Vector2,H=0,T=0,S=1,R=new THREE.Vector3,x=new THREE.Vector3,k={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},O=k.NONE,P={type:"change"};this.rotateLeft=function(e){void 0===e&&(e=r()),T-=e},this.rotateUp=function(e){void 0===e&&(e=r()),H-=e},this.panLeft=function(e){var t=new THREE.Vector3,r=this.object.matrix.elements;t.set(r[0],r[1],r[2]),t.multiplyScalar(-e),R.add(t)},this.panUp=function(e){var t=new THREE.Vector3,r=this.object.matrix.elements;t.set(r[4],r[5],r[6]),t.multiplyScalar(e),R.add(t)},this.pan=function(e){var t=p.domElement===document?p.domElement.body:p.domElement;if(void 0!==p.object.fov){var r=p.object.position,n=r.clone().sub(p.target),o=n.length();o*=Math.tan(p.object.fov/2*Math.PI/180),p.panLeft(2*e.x*o/t.clientHeight),p.panUp(2*e.y*o/t.clientHeight)}else void 0!==p.object.top?(p.panLeft(e.x*(p.object.right-p.object.left)/t.clientWidth),p.panUp(e.y*(p.object.top-p.object.bottom)/t.clientHeight)):console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.")},this.dollyIn=function(e){void 0===e&&(e=n()),S/=e},this.dollyOut=function(e){void 0===e&&(e=n()),S*=e},this.update=function(){var e=this.object.position,t=e.clone().sub(this.target),n=Math.atan2(t.x,t.z),o=Math.atan2(Math.sqrt(t.x*t.x+t.z*t.z),t.y);this.autoRotate&&this.rotateLeft(r()),n+=T,o+=H,o=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,o)),o=Math.max(d,Math.min(Math.PI-d,o));var a=t.length()*S;a=Math.max(this.minDistance,Math.min(this.maxDistance,a)),this.target.add(R),t.x=a*Math.sin(o)*Math.sin(n),t.y=a*Math.cos(o),t.z=a*Math.sin(o)*Math.cos(n),e.copy(this.target).add(t),this.object.lookAt(this.target),T=0,H=0,S=1,R.set(0,0,0),x.distanceTo(this.object.position)>0&&(this.dispatchEvent(P),x.copy(this.object.position))},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",o,!1),this.domElement.addEventListener("mousewheel",s,!1),this.domElement.addEventListener("DOMMouseScroll",s,!1),this.domElement.addEventListener("keydown",c,!1),this.domElement.addEventListener("touchstart",l,!1),this.domElement.addEventListener("touchend",u,!1),this.domElement.addEventListener("touchmove",h,!1)},THREE.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype);var Stats=function(){function e(e,t,r){return e=document.createElement(e),e.id=t,e.style.cssText=r,e}function t(t,r,n){var o=e("div",t,"padding:0 0 3px 3px;text-align:left;background:"+n),a=e("div",t+"Text","font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px;color:"+r);for(a.innerHTML=t.toUpperCase(),o.appendChild(a),t=e("div",t+"Graph","width:74px;height:30px;background:"+r),o.appendChild(t),r=0;74>r;r++)t.appendChild(e("span","","width:1px;height:30px;float:left;opacity:0.9;background:"+n));return o}function r(e){for(var t=l.children,r=0;r<t.length;r++)t[r].style.display=r===e?"block":"none";c=e}function n(e,t){e.appendChild(e.firstChild).style.height=Math.min(30,30-30*t)+"px"}var o=self.performance&&self.performance.now?self.performance.now.bind(performance):Date.now,a=o(),i=a,s=0,c=0,l=e("div","stats","width:80px;opacity:0.9;cursor:pointer");l.addEventListener("mousedown",function(e){e.preventDefault(),r(++c%l.children.length)},!1);var h=0,u=1/0,p=0,d=t("fps","#0ff","#002"),m=d.children[0],f=d.children[1];l.appendChild(d);var g=0,y=1/0,E=0,d=t("ms","#0f0","#020"),v=d.children[0],_=d.children[1];if(l.appendChild(d),self.performance&&self.performance.memory){var b=0,w=1/0,H=0,d=t("mb","#f08","#201"),T=d.children[0],S=d.children[1];l.appendChild(d)}return r(c),{REVISION:14,domElement:l,setMode:r,begin:function(){a=o()},end:function(){var e=o();if(g=e-a,y=Math.min(y,g),E=Math.max(E,g),v.textContent=(0|g)+" MS ("+(0|y)+"-"+(0|E)+")",n(_,g/200),s++,e>i+1e3&&(h=Math.round(1e3*s/(e-i)),u=Math.min(u,h),p=Math.max(p,h),m.textContent=h+" FPS ("+u+"-"+p+")",n(f,h/100),i=e,s=0,void 0!==b)){var t=performance.memory.usedJSHeapSize,r=performance.memory.jsHeapSizeLimit;b=Math.round(9.54e-7*t),w=Math.min(w,b),H=Math.max(H,b),T.textContent=b+" MB ("+w+"-"+H+")",n(S,t/r)}return e},update:function(){a=this.end()}}};"object"===("undefined"==typeof module?"undefined":_typeof(module))&&(module.exports=Stats),THREE.SubdivisionModifier=function(e){this.subdivisions=void 0===e?1:e},THREE.SubdivisionModifier.prototype.modify=function(e){for(var t=this.subdivisions;t-- >0;)this.smooth(e);delete e.__tmpVertices,e.computeFaceNormals(),e.computeVertexNormals()},function(){function e(e,t,r){var n=Math.min(e,t),o=Math.max(e,t),a=n+"_"+o;return r[a]}function t(e,t,r,n,o,a){var i,s=Math.min(e,t),c=Math.max(e,t),l=s+"_"+c;if(l in n)i=n[l];else{var h=r[s],u=r[c];i={a:h,b:u,newEdge:null,faces:[]},n[l]=i}i.faces.push(o),a[e].edges.push(i),a[t].edges.push(i)}function r(e,r,n,o){var a,i,s;for(a=0,i=e.length;i>a;a++)n[a]={edges:[]};for(a=0,i=r.length;i>a;a++)s=r[a],t(s.a,s.b,e,o,s,n),t(s.b,s.c,e,o,s,n),t(s.c,s.a,e,o,s,n)}function n(e,t,r,n){e.push(new THREE.Face3(t,r,n))}var o=!1,a=["a","b","c"];THREE.SubdivisionModifier.prototype.smooth=function(t){var i,s,c,l,h,u,p,d,m,f,g,g,y,E,v=new THREE.Vector3;i=t.vertices,s=t.faces,f=new Array(i.length),g={},r(i,s,f,g),y=[];var _,b,w,H,T,S,R;for(u in g){for(b=g[u],w=new THREE.Vector3,T=3/8,S=1/8,R=b.faces.length,2!=R&&(T=.5,S=0,1!=R&&o&&console.warn("Subdivision Modifier: Number of connected faces != 2, is: ",R,b)),w.addVectors(b.a,b.b).multiplyScalar(T),v.set(0,0,0),d=0;R>d;d++){for(H=b.faces[d],m=0;3>m&&(_=i[H[a[m]]],_===b.a||_===b.b);m++);v.add(_)}v.multiplyScalar(S),w.add(v),b.newEdge=y.length,y.push(w)}var x,k,O,P,C,W,M;for(E=[],u=0,p=i.length;p>u;u++){for(W=i[u],C=f[u].edges,h=C.length,3==h?x=3/16:h>3&&(x=3/(8*h)),k=1-h*x,O=x,2>=h&&(2==h?(o&&console.warn("2 connecting edges",C),k=.75,O=1/8):1==h?o&&console.warn("only 1 connecting edge"):0==h&&o&&console.warn("0 connecting edges")),M=W.clone().multiplyScalar(k),v.set(0,0,0),d=0;h>d;d++)P=C[d],_=P.a!==W?P.a:P.b,v.add(_);v.multiplyScalar(O),M.add(v),E.push(M)}c=E.concat(y);var j,L,A,D=E.length;for(l=[],u=0,p=s.length;p>u;u++)H=s[u],j=e(H.a,H.b,g).newEdge+D,L=e(H.b,H.c,g).newEdge+D,A=e(H.c,H.a,g).newEdge+D,n(l,j,L,A),n(l,H.a,j,A),n(l,H.b,L,j),n(l,H.c,A,L);t.vertices=c,t.faces=l}}(),addCSSRule(document.styleSheets[0],"@keyframes fadeOut","to {opacity: 0}",0),addCSSRule(document.styleSheets[0],"@keyframes fadeIn","from {opacity: 0} to {opacity: 1}",0),Element.prototype.fadeOut=function(e){this.style.webkitAnimationDuration=(e||1)+"s",this.style.webkitAnimationName="fadeOut",this.style.webkitAnimationPlayState="running",this.addEventListener("animationend",function(){this.style.display="none",this.style.webkitAnimationPlayState="paused"})},Element.prototype.fadeIn=function(e,t){this.style.display=t||"block",this.style.webkitAnimationDuration=(e||1)+"s",this.style.webkitAnimationName="fadeIn",this.style.webkitAnimationPlayState="running",this.addEventListener("animationend",function(){this.style.display=t||"block"})},"undefined"==typeof Array.isArray&&(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),function(){if(!MouseEvent.prototype.hasOwnProperty("movementX")||!MouseEvent.prototype.hasOwnProperty("mozMovementX")){var e={lastX:0,lastY:0};MouseEvent.prototype.getMovementX=function(){var t=this.clientX-e.lastX;return e.lastX=this.clientX,t},MouseEvent.prototype.getMovementY=function(){var t=this.clientY-e.lastY;return e.lastY=this.clientY,t}}}(),Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(void 0===e||null===e)throw new TypeError("Cannot convert first argument to object");for(var t=Object(e),r=1;r<arguments.length;r++){var n=arguments[r];if(void 0!==n&&null!==n){n=Object(n);for(var o=Object.keys(n),a=0,i=o.length;i>a;a++){var s=o[a],c=Object.getOwnPropertyDescriptor(n,s);void 0!==c&&c.enumerable&&(t[s]=n[s])}}}return t}});var WHS={REVISION:"7",API:{},_settings:{assets:"./assets",path_worker:"../libs/physijs_worker.js",path_ammo:"../libs/ammo.js"},loops:[],grounds:[]},api=WHS.API;"function"==typeof define&&define.amd?define("whitestorm",WHS):"undefined"!=typeof exports&&"undefined"!=typeof module&&(module.exports=WHS),THREE.ShaderTerrain={terrain:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{enableDiffuse1:{type:"i",value:0},enableDiffuse2:{type:"i",value:0},enableSpecular:{type:"i",value:0},enableReflection:{type:"i",value:0},tDiffuse1:{type:"t",value:null},tDiffuse2:{type:"t",value:null},tDetail:{type:"t",value:null},tNormal:{type:"t",value:null},tSpecular:{type:"t",value:null},tDisplacement:{type:"t",value:null},uNormalScale:{type:"f",value:1},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},diffuse:{type:"c",value:new THREE.Color(15658734)},specular:{type:"c",value:new THREE.Color(1118481)},shininess:{type:"f",value:30},opacity:{type:"f",value:1},uRepeatBase:{type:"v2",value:new THREE.Vector2(1,1)},uRepeatOverlay:{type:"v2",value:new THREE.Vector2(1,1)},uOffset:{type:"v2",value:new THREE.Vector2(0,0)}}]),fragmentShader:["\n		        uniform vec3 diffuse;\n		        uniform vec3 emissive;\n		        uniform float opacity;\n		        uniform vec3 ambientLightColor;\n		        varying vec3 vLightFront;\n		        #ifdef DOUBLE_SIDED\n			        varying vec3 vLightBack;\n			        uniform vec2 uRepeatOverlay;\n			        uniform vec2 uRepeatBase;\n			        uniform vec2 uOffset;\n			        uniform float uNormalScale;\n			        uniform sampler2D tNormal;\n		        #endif\n		        uniform sampler2D oceanTexture;\n		        uniform sampler2D sandyTexture;\n		        uniform sampler2D grassTexture;\n		        uniform sampler2D rockyTexture;\n		        uniform sampler2D snowyTexture;\n		        varying vec3 vTangent;\n		        varying vec3 vBinormal;\n		        varying vec3 vNormal;\n		        varying vec3 vViewPosition;\n		"+[THREE.ShaderChunk.common,THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.alphamap_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.specularmap_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment].join("\n")+"\n		        varying vec2 vUv;\n		        varying float vAmount;\n		        void main() {\n		        	// UVs.\n		            vec2 uvOverlay = uRepeatOverlay * vUv + uOffset;\n		            vec2 uvBase = uRepeatBase * vUv;\n					vec3 specularTex = vec3( 1.0 );\n		            vec3 normalTex = texture2D( tNormal, uvOverlay ).xyz * 2.0 - 1.0;\n		            normalTex.xy *= uNormalScale;\n		            normalTex = normalize( normalTex );\n		            mat3 tsb = mat3( vTangent, vBinormal, vNormal );\n		            vec3 finalNormal = tsb * normalTex;\n		            vec3 normal = normalize( finalNormal );\n		            vec3 viewPosition = normalize( vViewPosition );\n		            vec3 shadowMask = vec3( 1.0 );\n		            vec3 outgoingLight = vec3( 0.0 );\n		            vec3 totalAmbientLight = ambientLightColor;\n		            vec4 diffuseColor = vec4(0.0);\n		            // Color by texture.\n		            vec4 water = (smoothstep(0.01, 0.25, vAmount)\n		            - smoothstep(0.24, 0.26, vAmount))\n		            * texture2D( oceanTexture, vUv * 10.0 );\n		            vec4 sandy = (smoothstep(0.24, 0.27, vAmount)\n		            - smoothstep(0.28, 0.31, vAmount))\n		            * texture2D( sandyTexture, vUv * 10.0 );\n		            vec4 grass = (smoothstep(0.28, 0.32, vAmount)\n		            - smoothstep(0.35, 0.40, vAmount))\n		            * texture2D( grassTexture, vUv * 20.0 );\n		            vec4 rocky = (smoothstep(0.30, 0.40, vAmount)\n		            - smoothstep(0.40, 0.70, vAmount))\n		            * texture2D( rockyTexture, vUv * 20.0 );\n		            vec4 snowy = (smoothstep(0.42, 0.45, vAmount))\n		            * texture2D( snowyTexture, vUv * 10.0 );\n		            diffuseColor = vec4(0.0, 0.0, 0.0, 1.0)\n		            + water + sandy + grass + rocky + snowy;\n		"+[THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphamap_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.specularmap_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment].join("\n")+"\n		            #ifdef DOUBLE_SIDED\n		                if ( gl_FrontFacing )\n		                    outgoingLight += diffuseColor.rgb * \n		                		( vLightFront * shadowMask + totalAmbientLight )\n		                		+ emissive;\n		                else\n		                    outgoingLight += diffuseColor.rgb * \n		                		( vLightBack * shadowMask + totalAmbientLight )\n		                		+ emissive;\n		            #else\n		                outgoingLight += diffuseColor.rgb * \n		                	( vLightFront * shadowMask + totalAmbientLight )\n		                	+ emissive;\n		            #endif\n		           gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n		      }\n		"],vertexShader:["\n		    #define TERRAIN;\n		    varying vec3 vLightFront;\n		    #ifdef DOUBLE_SIDED\n		        varying vec3 vLightBack;\n		    #endif\n		    \n		    varying float vAmount;\n		    attribute vec4 tangent;\n		    uniform vec2 uRepeatBase;\n		    uniform sampler2D tNormal;\n		    #ifdef VERTEX_TEXTURES\n			    uniform sampler2D tDisplacement;\n			    uniform float uDisplacementScale;\n			    uniform float uDisplacementBias;\n		    #endif\n		    varying vec3 vTangent;\n		    varying vec3 vBinormal;\n		    varying vec3 vNormal;\n		    varying vec2 vUv;\n		    varying vec3 vViewPosition;\n		"+[THREE.ShaderChunk.common,THREE.ShaderChunk.uv_pars_vertex,THREE.ShaderChunk.uv2_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_lambert_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex].join("\n")+"\n		    void main() {\n		"+[THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.beginnormal_vertex,THREE.ShaderChunk.morphnormal_vertex,THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.skinnormal_vertex,THREE.ShaderChunk.defaultnormal_vertex,THREE.ShaderChunk.begin_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.project_vertex,THREE.ShaderChunk.logdepthbuf_vertex,THREE.ShaderChunk.uv_vertex,THREE.ShaderChunk.uv2_vertex].join("\n")+"\n			    vNormal = normalize( normalMatrix * normal);\n			    // Tangent and binormal vectors.\n			    vTangent = normalize( normalMatrix * tangent.xyz );\n			    vBinormal = cross( vNormal, vTangent ) * tangent.w;\n			    vBinormal = normalize( vBinormal );\n			    // Texture coordinates.\n			    vUv = uv;\n			    vec2 uvBase = uv * uRepeatBase;\n			    // displacement mapping\n			    vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n			    mvPosition = modelViewMatrix * vec4( position, 1.0 );\n			    transformedNormal = normalize( normalMatrix * normal );\n			    gl_Position = projectionMatrix * mvPosition;\n			    vViewPosition = -mvPosition.xyz;\n			    vAmount = position.z * 0.005 + 0.1;\n		"+[THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.lights_lambert_vertex,THREE.ShaderChunk.shadowmap_vertex].join("\n")+"\n		   }\n		"],side:THREE.DoubleSide,shading:THREE.SmoothShading}},WHS.API.extend=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;t>n;n++)r[n-1]=arguments[n];var o=!0,a=!1,i=void 0;try{for(var s,c=r[Symbol.iterator]();!(o=(s=c.next()).done);o=!0){var l=s.value;if(l){var h=!0,u=!1,p=void 0;try{for(var d,m=Object.getOwnPropertyNames(l)[Symbol.iterator]();!(h=(d=m.next()).done);h=!0){var f=d.value;void 0!=e[f]&&"[object Object]"==e[f].toString()&&"[object Object]"==l[f].toString()?WHS.API.extend(e[f],l[f]):e[f]=0===e[f]?0:e[f]||l[f]}}catch(g){u=!0,p=g}finally{try{!h&&m["return"]&&m["return"]()}finally{if(u)throw p}}}}}catch(g){a=!0,i=g}finally{try{!o&&c["return"]&&c["return"]()}finally{if(a)throw i}}return e},WHS.API.getheight=function(e,t,r,n){return t=t||1e3,n=n||1,this.raycaster=new THREE.Raycaster(new THREE.Vector3(e.x,t,n*e.y),new THREE.Vector3(0,-1,0)),this.intersect=this.raycaster.intersectObject(r.mesh),this.intersect},WHS.Light=function(){function e(t,r){_classCallCheck(this,e);var n=function(e,t,r){this.x=e,this.y=t,this.z=r};t.pos&&(t.pos.set=n),t.rot&&(t.rot.set=n),t.target&&(t.target.set=n);var o=api.extend(t,{light:{color:16777215,skyColor:16777215,groundColor:16777215,intensity:1,distance:100,angle:Math.PI/3},shadowmap:{cast:!0,bias:1e-4,width:1024,height:1024,near:!0,far:400,fov:60,darkness:.3,top:200,bottom:-200,left:-200,right:200},pos:{x:0,y:0,z:0,set:n},rot:{x:0,y:0,z:0,set:n},target:{x:0,y:0,z:0,set:n}}),a=0,i={_key:a,_type:r,_whsobject:!0,_name:r+a,__releaseTime:(new Date).getTime(),_pos:o.pos,_rot:o.rot,_target:o.target,_light:o.light,_shadowmap:o.shadowmap,ready:new Events};return Object.assign(this,i),this}return _createClass(e,[{key:"build",value:function(){for(var e=this,t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];var o=this.mesh,a=this;return this.build_state=new Promise(function(t,n){try{o.castShadow=!0,o.receiveShadow=!0,o.position.set(e._pos.x,e._pos.y,e._pos.z),o.rotation.set(e._rot.x,e._rot.y,e._rot.z),r.forEach(function(e){a[e]=!0}),t()}catch(i){console.error(i.message),n()}}),this}},{key:"addTo",value:function(e){this.root=e;var t=this.mesh,r=this;return console.log(this),this._key=this.root.modellingQueue.length,r._state=new Promise(function(e,n){try{api.merge(r.root.scene,t),r.root.modellingQueue.push(r)}catch(o){console.error(o.message),n()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),r.ready.emit("ready"))}}),r.root.children.push(r),this}},{key:"buildShadow",value:function(){this.mesh.shadowMapWidth=this._shadowmap.width,this.mesh.shadowMapHeight=this._shadowmap.height,this.mesh.shadowBias=this._shadowmap.bias,this.mesh.shadowCameraNear=this._shadowmap.near,this.mesh.shadowCameraFar=this._shadowmap.far,this.mesh.shadowCameraFov=this._shadowmap.fov,this.mesh.shadowDarkness=this._shadowmap.darkness,this.mesh.shadowCameraLeft=this._shadowmap.left,this.mesh.shadowCameraRight=this._shadowmap.right,this.mesh.shadowCameraTop=this._shadowmap.top,this.mesh.shadowCameraBottom=this._shadowmap.bottom}},{key:"remove",value:function(){return this.root.scene.remove(this.mesh),this}},{key:"retrieve",value:function(){return this.root.scene.add(this.mesh),this}}]),e}(),WHS.API.JSONLoader=function(){return new THREE.JSONLoader},WHS.API.TextureLoader=function(){return new THREE.TextureLoader},WHS.API.loadMaterial=function(e){"string"!=typeof e.kind&&console.error("Type of material is undefined or not a string. @loadMaterial");var t={_type:e.kind,_restitution:e.restitution||e.rest||.3,_friction:e.friction||e.fri||.8},r=api.extend({},e);switch(delete r.kind,delete r.friction,delete r.fri,delete r.restitution,delete r.rest,e.kind){case"basic":t._material=new THREE.MeshBasicMaterial(r);break;case"linebasic":t._params=new THREE.LineBasicMaterial(r);break;case"linedashed":t._material=new THREE.LineDashedMaterial(r);break;case"material":t._material=new THREE.Material(r);break;case"depth":t._material=new THREE.MeshDepthMaterial(r);break;case"face":t._material=new THREE.MeshFaceMaterial(r);break;case"lambert":t._material=new THREE.MeshLambertMaterial(r);break;case"normal":t._material=new THREE.MeshNormalMaterial(r);break;case"phong":t._material=new THREE.MeshPhongMaterial(r);break;case"pointcloud":t._material=new THREE.PointCloudMaterial(r);break;case"rawshader":t._material=new THREE.RawShaderMaterial(r);break;case"shader":t._material=new THREE.ShaderMaterial(r);break;case"spritecanvas":t._material=new THREE.SpriteCanvasMaterial(r);break;case"sprite":t._material=new THREE.SpriteMaterial(r)}return t._material=Physijs.createMaterial(t._material,t._friction,t._restitution),console.log(t._friction),t},WHS.API.merge=function(e,t){if(("object"!==("undefined"==typeof e?"undefined":_typeof(e))||"object"!==("undefined"==typeof t?"undefined":_typeof(t)))&&console.error("No rabbits for the box. (arguments)",["undefined"==typeof e?"undefined":_typeof(e),"undefined"==typeof t?"undefined":_typeof(t)]),e)if(Array.isArray(t)&&1===t.length)e.add(t[0]);else if(Array.isArray(t)&&t.length>1&&e)for(var r=0;r<t.length;r++)e.add(t[r]);else Array.isArray(t)||e.add(t);else console.error("box is undefined. Line "+(new Error).lineNumber+". Func merge.",[e,t])},WHS.API.PackUvs=function(e){e.computeBoundingBox();var t=e.boundingBox.max,r=e.boundingBox.min,n=new THREE.Vector2(0-r.x,0-r.y),o=new THREE.Vector2(t.x-r.x,t.y-r.y);e.faceVertexUvs[0]=[];for(var a=e.faces,i=0;i<e.faces.length;i++){var s=e.vertices[a[i].a],c=e.vertices[a[i].b],l=e.vertices[a[i].c];e.faceVertexUvs[0].push([new THREE.Vector2((s.x+n.x)/o.x,(s.y+n.y)/o.y),new THREE.Vector2((c.x+n.x)/o.x,(c.y+n.y)/o.y),new THREE.Vector2((l.x+n.x)/o.x,(l.y+n.y)/o.y)])}e.uvsNeedUpdate=!0},WHS.API.removeDuplicateFaces=function(e){function t(){return!(a1.sort()>a2.sort()||a1.sort()<a2.sort())}for(var r=0;r<e.faces.length;r++)for(var n=e.faces[r],o=[n.a,n.b,n.c,n.d].sort(),a=0;r>a;a++){var i=e.faces[a];if(void 0!==i){var s=[i.a,i.b,i.c,i.d].sort();t(o,s)&&(delete e.faces[r],delete e.faces[a])}}return e.faces=e.faces.filter(function(e){return void 0===e}),e},WHS.API.rotateGeometry=function(e,t){var r=new THREE.Matrix4;r.makeRotationFromEuler(new THREE.Euler(t.x,t.y,t.z,"XYZ"));for(var n in e.vertices)e.vertices[n].applyMatrix4(r);return e},WHS.Shape=function(){function e(t,r){_classCallCheck(this,e);var n=function(e,t,r){this.x=e,this.y=t,this.z=r};api.extend(t,{mass:10,pos:{x:0,y:0,z:0,set:n},rot:{x:0,y:0,z:0,set:n},scale:{x:1,y:1,z:1,set:n},target:{x:0,y:0,z:0,set:n},morph:{speed:1,duration:1},onlyvis:!1});var o=0,a={_key:o,_type:r,_whsobject:!0,_name:r+o,__releaseTime:(new Date).getTime(),_pos:t.pos,_rot:t.rot,_scale:t.scale,_morph:t.morph,_target:t.target,_onlyvis:t.onlyvis,ready:new Events};return Object.assign(this,a),this}return _createClass(e,[{key:"build",value:function(){console.log(this);for(var e=this,t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];return r.indexOf("wait")>=0?e._loading.then(function(){e.build_state=new Promise(function(t,r){try{e.mesh.castShadow=!0,e.mesh.receiveShadow=!0,e.mesh.position.set(e._pos.x,e._pos.y,e._pos.z),e.mesh.rotation.set(e._rot.x,e._rot.y,e._rot.z),e.mesh.scale.set(e._scale.x,e._scale.y,e._scale.z),
-e._pos=e.mesh.position,e._rot=e.mesh.rotation,e._scale=e.mesh.scale,t()}catch(n){console.error(n.message),r()}})}):e.build_state=new Promise(function(t,r){try{e.mesh.castShadow=!0,e.mesh.receiveShadow=!0,e.mesh.position.set(e._pos.x,e._pos.y,e._pos.z),e.mesh.rotation.set(e._rot.x,e._rot.y,e._rot.z),e.mesh.scale.set(e._scale.x,e._scale.y,e._scale.z),e._pos=e.mesh.position,e._rot=e.mesh.rotation,e._scale=e.mesh.scale,t()}catch(n){console.error(n.message),r()}}),this}},{key:"addTo",value:function(e){this.root=e;var t=this.mesh,r=this;this._key=this.root.modellingQueue.length;for(var n=arguments.length,o=Array(n>1?n-1:0),a=1;n>a;a++)o[a-1]=arguments[a];return console.log([o,o.indexOf("wait"),r]),o.indexOf("wait")>=0?r._loading.then(function(){r._state=new Promise(function(e,t){try{api.merge(r.root.scene,r.mesh),r.root.modellingQueue.push(r)}catch(n){console.error(n.message),t()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),r.ready.emit("ready"))}})}):r._state=new Promise(function(e,n){try{api.merge(r.root.scene,t),r.root.modellingQueue.push(r)}catch(o){console.error(o.message),n()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),console.log("wqd"),r.ready.emit("ready"))}}),r.root.children.push(r),this}},{key:"_initMaterial",value:function(e){return api.loadMaterial(e)._material}},{key:"remove",value:function(){return this.root.scene.remove(this.mesh),this}},{key:"retrieve",value:function(){return this.root.scene.add(this.mesh),this}}]),e}(),WHS.API.texture=function(e,t){var r=api.TextureLoader().load(e);if(t){var n=api.extend(t,{offset:{x:0,y:0},repeat:{x:1,y:1}});r.wrapS=r.wrapT=THREE.RepeatWrapping,r.offset.set(n.offset.x,n.offset.y),r.repeat.set(n.repeat.x,n.repeat.y),r.magFilter=THREE.NearestFilter,r.minFilter=THREE.LinearMipMapLinearFilter}return r},WHS.API.Triangulate=function(e,t){if(e instanceof THREE.Geometry){if(t){var r=new THREE.Geometry,n=[];e.faces.forEach(function(o){var a=new THREE.Geometry;[].push.apply(a.vertices,[e.vertices[o.a],e.vertices[o.b],e.vertices[o.c]]),a.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(0,1),new THREE.Vector2(1,1),new THREE.Vector2(1,0)]),a.faces.push(new THREE.Face3(0,1,2)),a.computeFaceNormals();var i=new THREE.Mesh(a,t);i.updateMatrix(),r.merge(i.geometry,i.matrix),n.push(t)});var o=new THREE.Mesh(r,new THREE.MeshFaceMaterial(n));return o}}else console.error("No THREE.js geometry")},WHS.Watch=function(e){return this._queue=Array.isArray(e)?e.slice():[],this},WHS.Watch.prototype.add=function(e){return this._queue.push(e),this},WHS.Watch.prototype.remove=function(e){return this._queue=this._queue.filter(function(t){return t!=e}),this},WHS.loop=function(e){this.loop={func:e,id:WHS.loops.length,enabled:!1},WHS.loops.push(this.loop)},WHS.loop.prototype.start=function(){this.loop.enabled=!0},WHS.loop.prototype.stop=function(){this.loop.enabled=!1},WHS.init=function(){function e(t){_classCallCheck(this,e),console.log("WHS.init",WHS.REVISION),THREE||console.warn("whitestormJS requires THREE.js. {Object} THREE not found."),Physijs||console.warn("whitestormJS requires PHYSI.js. {Object} Physijs not found."),WAGNER||console.warn("whitestormJS requires WAGNER.js. {Object} WAGNER not found.");var r=api.extend(t,{anaglyph:!1,helper:!1,stats:!1,wagner:!0,autoresize:!1,shadowmap:!0,gravity:{x:0,y:0,z:0},camera:{aspect:75,near:1,far:1e3,x:0,y:0,z:0},rWidth:window.innerWidth,rHeight:window.innerHeight,width:window.innerWidth,height:window.innerHeight,physics:{quatNormalizeSkip:0,quatNormalizeFast:!1,solver:{iterations:20,tolerance:0},defMaterial:{contactEquationStiffness:1e8,contactEquationRegularizationTime:3}},background:0,assets:"./assets",container:document.body,path_worker:"../libs/physijs_worker.js",path_ammo:"../libs/ammo.js"});this._settings=r,this._initScene(),this._initDOM(),this._initStats(),this._initCamera(),this._initRenderer();var n=this;return r.autoresize&&window.addEventListener("load resize",function(){n.resize()}),n}return _createClass(e,[{key:"_initScene",value:function(){this._initPhysiJS(),this.scene=new Physijs.Scene,this.scene.setGravity(new THREE.Vector3(this._settings.gravity.x,this._settings.gravity.y,this._settings.gravity.z)),this.modellingQueue=[],this.children=[]}},{key:"_initPhysiJS",value:function(){Physijs.scripts.worker=this._settings.path_worker,Physijs.scripts.ammo=this._settings.path_ammo}},{key:"_initDOM",value:function(){return this._settings.container.style.margin=0,this._settings.container.style.padding=0,this._settings.container.style.position="relative",this._settings.container.style.overflow="hidden",this._dom=document.createElement("div"),this._dom.className="whs",this._settings.container.appendChild(this._dom),this._dom}},{key:"_initStats",value:function(){this._settings.stats&&(this._stats=new Stats,"fps"==this._settings.stats?this._stats.setMode(0):"ms"==this._settings.stats?this._stats.setMode(1):"mb"==this._settings.stats?this._stats.setMode(1):(this._stats.setMode(0),console.warn([this._stats],"Please, apply stats mode [fps, ms, mb] .")),this._stats.domElement.style.position="absolute",this._stats.domElement.style.left="0px",this._stats.domElement.style.bottom="0px",this._dom.appendChild(this._stats.domElement))}},{key:"_initCamera",value:function(){this._camera=new THREE.PerspectiveCamera(this._settings.camera.aspect,this._settings.width/this._settings.height,this._settings.camera.near,this._settings.camera.far),this._camera.position.set(this._settings.camera.x,this._settings.camera.y,this._settings.camera.z),this.scene.add(this._camera)}},{key:"_initRenderer",value:function(){this._renderer=new THREE.WebGLRenderer,this._renderer.setClearColor(this._settings.background),this._renderer.shadowMap.enabled=this._settings.shadowmap,this._renderer.shadowMap.type=THREE.PCFSoftShadowMap,this._renderer.shadowMap.cascade=!0,this._renderer.setSize(this._settings.rWidth,this._settings.rHeight),this._renderer.render(this.scene,this._camera),this._dom.appendChild(this._renderer.domElement),this._renderer.domElement.style.width="100%",this._renderer.domElement.style.height="100%"}},{key:"start",value:function(){function e(n){requestAnimationFrame(e),r._stats&&r._stats.begin(),r._process(t),r.scene.simulate(),r._updateControls(),r._composer?(r._composer.reset(),r._composer.render(r.scene,r._camera),r._composer.pass(r._composer.stack),r._composer.toScreen()):r._renderer.render(r.scene,r._camera),r._loop(n),r._stats&&r._stats.end()}var t=new THREE.Clock,r=this;this._update=e,r._update()}},{key:"_loop",value:function(e){WHS.loops.forEach(function(t){t.enabled&&t.func(e)})}},{key:"_updateControls",value:function(){this.controls&&(this.controls.update(Date.now()-this.time),this.time=Date.now())}},{key:"_process",value:function(e){for(var t=0;t<this.modellingQueue.length;t++)"morph"==this.modellingQueue[t]._type&&this.modellingQueue[t].mesh.mixer.update(e.getDelta())}},{key:"resize",value:function(){this._camera.aspect=window.innerWidth/window.innerHeight,this._camera.updateProjectionMatrix(),this._renderer.setSize(this._settings.rWidth,this._settings.rHeight)}}]),e}(),WHS.Cube=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"cube"));return api.extend(e.geometry,{width:1,height:1,depth:1}),r.mesh=new Physijs.BoxMesh(new THREE.BoxGeometry(e.geometry.width,e.geometry.height,e.geometry.depth),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Cube=function(e){return new WHS.Cube(e).addTo(this)},WHS.Cylinder=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"cylinder"));return api.extend(e.geometry,{radiusTop:1,radiusBottom:1,height:1,radiusSegments:32}),r.mesh=new Physijs.CylinderMesh(new THREE.CylinderGeometry(e.geometry.radiusTop,e.geometry.radiusBottom,e.geometry.height,e.geometry.radiusSegments),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Cylinder=function(e){return new WHS.Cylinder(e).addTo(this)},WHS.Dodecahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"dodecahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.DodecahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Dodecahedron=function(e){return new WHS.Dodecahedron(e).addTo(this)},WHS.Extrude=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"extrude"));return api.extend(e.geometry,{shapes:[],options:{}}),r.mesh=new Physijs.ConvexMesh(new THREE.ExtrudeGeometry(e.geometry.shapes,e.geometry.options),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Extrude=function(e){return new WHS.Extrude(e).addTo(this)},WHS.Icosahderon=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"icosahderon"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.IcosahderonGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Icosahderon=function(e){return new WHS.Icosahderon(e).addTo(this)},WHS.Lathe=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"lathe"));return api.extend(e.geometry,{points:[]}),r.mesh=new Physijs.ConvexMesh(new THREE.LatheGeometry(e.geometry.points),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Lathe=function(e){return new WHS.Lathe(e).addTo(this)},WHS.Model=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"model"));api.extend(e.geometry,{path:""});var n=r,o=_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material);return r._loading=new Promise(function(t,r){api.JSONLoader().load(e.geometry.path,function(r){r.computeFaceNormals(),r.computeVertexNormals(),n.mesh=new Physijs.ConvexMesh(r,o,e.mass),t()})}),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"wait"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Model=function(e){return new WHS.Model(e).addTo(this,"wait")},WHS.Morph=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"morph"));api.extend(e.geometry,{path:""}),console.log(r);var n=r;return r._loading=new Promise(function(t,r){api.JSONLoader().load(e.geometry.path,function(r){var o=new THREE.MeshLambertMaterial({color:16755285,morphTargets:!0,vertexColors:THREE.FaceColors});r.computeFaceNormals(),r.computeVertexNormals(),n.mesh=new THREE.Mesh(r,o),n.mesh.speed=e.morph.speed,n.mesh.mixer=new THREE.AnimationMixer(n.mesh),n.mesh.mixer.addAction(new THREE.AnimationAction(r.animations[0]).warpToDuration(.5)),n.mesh.mixer.update(600*Math.random()),n._rot.y=Math.PI/2,t()})}),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"wait"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Morph=function(e){return new WHS.Morph(e).addTo(this,"wait")},WHS.Octahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"octahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.OctahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Octahedron=function(e){return new WHS.Octahedron(e).addTo(this)},WHS.Parametric=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"parametric"));return api.extend(e.geometry,{func:function(){},slices:10,stacks:10}),r.mesh=new Physijs.ConvexMesh(new THREE.ParametricGeometry(e.geometry.func,e.geometry.slices,e.geometry.stacks),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Parametric=function(e){return new WHS.Parametric(e).addTo(this)},WHS.Plane=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"plane"));return api.extend(e.geometry,{width:10,height:10,segments:32}),r.mesh=new Physijs.ConvexMesh(new THREE.PlaneBufferGeometry(e.geometry.width,e.geometry.height,e.geometry.segments),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Plane=function(e){return new WHS.Plane(e).addTo(this)},WHS.Polyhedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"polyhedron"));return api.extend(e.geometry,{verticesOfCube:[],indicesOfFaces:[],radius:1,detail:1}),r.mesh=new Physijs.ConvexMesh(new THREE.PolyhedronGeometry(e.geometry.verticesOfCube,e.geometry.indicesOfFaces,e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Polyhedron=function(e){return new WHS.Polyhedron(e).addTo(this)},WHS.Ring=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"ring"));return api.extend(e.geometry,{innerRadius:2,outerRadius:5,thetaSegments:30,phiSegments:30,thetaStart:0,thetaLength:2*Math.PI}),r.mesh=new Physijs.ConcaveMesh(new THREE.TorusGeometry(e.geometry.innerRadius,e.geometry.outerRadius,e.geometry.thetaSegments,e.geometry.phiSegments,e.geometry.thetaStart,e.geometry.thetaLength),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Ring=function(e){return new WHS.Ring(e).addTo(this)},WHS.Shape2D=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"shape2D"));return api.extend(e.geometry,{shapes:[]}),r.mesh=new THREE.Mesh(new THREE.ShapeGeometry(e.geometry.shapes),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"onlyvis"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Shape2D=function(e){return new WHS.Shape2D(e).addTo(this)},WHS.Sphere=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"sphere"));return api.extend(e.geometry,{radius:1,segmentA:32,segmentB:32}),r.mesh=new Physijs.SphereMesh(new THREE.SphereGeometry(e.geometry.radius,e.geometry.segmentA,e.geometry.segmentB),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Sphere=function(e){return new WHS.Sphere(e).addTo(this)},WHS.Tetrahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"tetrahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.TetrahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Tetrahedron=function(e){return new WHS.Tetrahedron(e).addTo(this)},WHS.Text=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"text"));return api.extend(e.geometry,{text:"Hello World!",parameters:{size:1,height:50,curveSegments:1,font:"Adelle",weight:"normal",style:"normal",bevelEnabled:!1,bevelThickness:10,bevelSize:8}}),r.mesh=new Physijs.ConcaveMesh(new THREE.TextGeometry(e.geometry.text,e.geometry.parameters),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Text=function(e){return new WHS.Text(e).addTo(this)},WHS.Torus=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"torus"));return api.extend(e.geometry,{radius:100,tube:40,radialSegments:8,tubularSegments:6,arc:2*Math.PI}),r.mesh=new Physijs.ConvexMesh(new THREE.TorusGeometry(e.geometry.radius,e.geometry.tube,e.geometry.radialSegments,e.geometry.tubularSegments,e.geometry.arc),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Torus=function(e){return new WHS.Torus(e).addTo(this)},WHS.Torusknot=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"Torusknot"));return api.extend(e.geometry,{radius:100,tube:40,radialSegments:64,tubularSegments:8,p:2,q:3,heightScale:1}),r.mesh=new Physijs.ConvexMesh(new THREE.TorusKnotGeometry(e.geometry.radius,e.geometry.tube,e.geometry.radialSegments,e.geometry.tubularSegments,e.geometry.p,e.geometry.q,e.geometry.heightScale),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Torusknot=function(e){return new WHS.Torusknot(e).addTo(this)},WHS.Tube=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"tube"));return api.extend(e.geometry,{path:options.geometryOptions.path?new r.CustomSinCurve(100):!1,segments:20,radius:2,radiusSegments:8,closed:!1}),r.mesh=new Physijs.ConvexMesh(new THREE.TubeGeometry(e.geometry.path,e.geometry.segments,e.geometry.radius,e.geometry.radiusSegments,e.geometry.closed),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),_createClass(t,[{key:"CustomSinCurve",get:function(){return THREE.Curve.create(function(e){this.scale=e||1},function(e){var t=3*e-1.5,r=Math.sin(2*Math.PI*e),n=0;return new THREE.Vector3(t,r,n).multiplyScalar(this.scale)})}}]),t}(WHS.Shape),WHS.init.prototype.Tube=function(e){return new WHS.Tube(e).addTo(this)},WHS.init.prototype.addGrass=function(e,t){var r={};r.root=this,r.opts=t,r.onlyvis=!0,r.opts.coords||console.warn("Please add grass objects coordinates! @addGrass"),r.grassMeshes=[];var n=new THREE.Mesh(new THREE.Geometry,new THREE.MeshFaceMaterial);return r.opts.coords.forEach(function(t){var o=new THREE.Mesh(new THREE.Geometry,new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("assets/textures/thingrass.png"),side:THREE.DoubleSide,blending:THREE.NormalBlending,transparent:!0,alphaTest:.5})),a=WHS.API.getheight({x:t.x,y:t.y},500,e,-1)[0],i=a.object.geometry.vertices,s=new THREE.Geometry;s.faces.push(new THREE.Face3(0,1,2)),s.vertices.push(i[a.face.a]),s.vertices.push(i[a.face.c]),s.vertices.push(i[a.face.b]),s.computeFaceNormals(),o.position.set(0,0,0),o.geometry.vertices.push(i[a.face.a].clone()),o.geometry.vertices.push(i[a.face.c].clone()),o.geometry.vertices.push(i[a.face.a].clone().add(s.faces[0].normal)),o.geometry.vertices.push(i[a.face.c].clone().add(s.faces[0].normal));var c=new THREE.Vector3(i[a.face.a].clone().x/2+i[a.face.c].clone().x/2,i[a.face.a].clone().y/2+i[a.face.c].clone().y/2,i[a.face.a].clone().z/2+i[a.face.c].clone().z/2);o.geometry.vertices.push(c.clone().add(c.clone().sub(i[a.face.b].clone()))),o.geometry.vertices.push(i[a.face.b].clone()),o.geometry.vertices.push(i[a.face.b].clone().add(s.faces[0].normal)),o.geometry.vertices.push(c.clone().add(c.clone().sub(i[a.face.b].clone())).add(s.faces[0].normal)),o.geometry.faces.push(new THREE.Face3(0,1,2)),o.geometry.faces.push(new THREE.Face3(1,2,3)),o.geometry.faces.push(new THREE.Face3(4,6,5)),o.geometry.faces.push(new THREE.Face3(4,6,7)),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,0),new THREE.Vector2(0,1)]),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(0,1)]),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(1,0)]),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(0,1)]),o.geometry.uvsNeedUpdate=!0,n.geometry.merge(o.geometry,o.matrix),n.material.materials.push(o.material),r.grassMeshes.push(o)}),r.wrap(n),r.update=function(){},r.update(),r},WHS.Smooth=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"smooth"));return api.extend(e.geometry,{width:10,height:10}),r.mesh=new Physijs.BoxMesh(new THREE.BoxGeometry(e.geometry.width,1,e.geometry.height),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),0),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Smooth=function(e){return new WHS.Smooth(e).addTo(this)},WHS.Terrain=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"terrain"));api.extend(e.geometry,{width:1,height:1,depth:1,map:!1});var n=document.createElement("canvas");if(n.setAttribute("width",e.geometry.width),n.setAttribute("height",e.geometry.height),n.getContext){var o=n.getContext("2d");o.drawImage(e.geometry.map,0,0)}var a=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/dirt-512.jpg");a.wrapS=a.wrapT=THREE.RepeatWrapping;var i=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/sand-512.jpg");i.wrapS=i.wrapT=THREE.RepeatWrapping;var s=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/grass-512.jpg");s.wrapS=s.wrapT=THREE.RepeatWrapping;var c=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/rock-512.jpg");c.wrapS=c.wrapT=THREE.RepeatWrapping;var l=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/snow-512.jpg");l.wrapS=l.wrapT=THREE.RepeatWrapping;var h=(THREE.NormalMapShader,256),u=256,p={minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBFormat},d=new THREE.WebGLRenderTarget(h,u,p);d.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/default_terrain.png");var m=new THREE.WebGLRenderTarget(h,u,p);m.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/NormalMap.png");var f=new THREE.WebGLRenderTarget(256,256,p);f.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/default_terrain.png");var g=THREE.ShaderTerrain.terrain,y=Object.assign(THREE.UniformsUtils.clone(g.uniforms),{oceanTexture:{type:"t",value:a},sandyTexture:{type:"t",value:i},grassTexture:{type:"t",value:s},rockyTexture:{type:"t",value:c},snowyTexture:{type:"t",value:l},fog:!0,lights:!0},THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}});y.tDisplacement.value=d,y.shadowMap.value=[m],y.uDisplacementScale.value=100,y.uRepeatOverlay.value.set(6,6);var E=new THREE.ShaderMaterial({uniforms:y,vertexShader:g.vertexShader,fragmentShader:g.fragmentShader,lights:!0,fog:!0,side:THREE.DoubleSide,shading:THREE.SmoothShading}),v=new THREE.PlaneGeometry(256,256,255,255);v.verticesNeedUpdate=!0,r._rot.set(Math.PI/180*-90,0,0);for(var _=0,b=0,w=o.getImageData(0,0,256,256).data,H=0;255>=H;H++)for(var T=255;T>=0;T--)v.vertices[_].z=w[b]/255*100,b+=4,_++;return r.mesh=new Physijs.HeightfieldMesh(v,Physijs.createMaterial(E,.8,.1)),v.computeVertexNormals(),v.computeFaceNormals(),v.computeTangents(),r.mesh.updateMatrix(),r.mesh.castShadow=!0,r.mesh.receiveShadow=!0,_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"skip"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Terrain=function(e){return new WHS.Terrain(e).addTo(this)},WHS.init.prototype.addFog=function(e,t){var r={};switch(api.extend(t,{hex:0,near:.015,far:1e3,density:25e-5}),e){case"fog":r=new THREE.Fog(t.hex,t.near,t.far);break;case"fogexp2":r=new THREE.FogExp2(t.hex,t.density)}return r},WHS.AmbientLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"ambientlight"));return r.mesh=new THREE.AmbientLight(e.light.color),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.AmbientLight=function(e){return new WHS.AmbientLight(e).addTo(this)},WHS.DirectionalLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"directionallight"));return r.mesh=new THREE.DirectionalLight(e.light.color,e.light.intensity),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.DirectionalLight=function(e){return new WHS.DirectionalLight(e).addTo(this)},WHS.HemisphereLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"hemispherelight"));return r.mesh=new THREE.HemisphereLight(e.light.skyColor,e.light.groundColor,e.light.intensity),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.HemisphereLight=function(e){return new WHS.HemisphereLight(e).addTo(this)},WHS.NormalLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"normallight"));return r.mesh=new THREE.Light(e.light.color),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.NormalLight=function(e){return new WHS.NormalLight(e).addTo(this)},WHS.PointLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"pointlight"));return r.mesh=new THREE.PointLight(e.light.color,e.light.intensity,e.light.distance),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.PointLight=function(e){return new WHS.PointLight(e).addTo(this)},WHS.SpotLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"spotlight"));return r.mesh=new THREE.SpotLight(e.light.color,e.light.intensity,e.light.distance,e.light.angle),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.SpotLight=function(e){return new WHS.SpotLight(e).addTo(this)},WHS.init.prototype.addWagner=function(e,t){t=t||{};var r={_composer:this._composer},n=api.extend(t,{hex:0,near:.015,far:1e3,density:25e-5});switch(e){case"ZoomBlurPass":r.effect=new WAGNER.ZoomBlurPass,n=api.extend(n,{strength:.05,center:{x:.5*this._composer.width,y:.5*this._composer.height}});break;case"MultiPassBloomPass":r.effect=new WAGNER.MultiPassBloomPass,n=api.extend(n,{strength:.5,blurAmount:1.32,applyZoomBlur:!0,zoomBlurStrength:.84,useTexture:!0,center:{x:.5*this._composer.width,y:.5*this._composer.height}}),r.effect.glowTexture=WAGNER.Pass.prototype.getOfflineTexture(this._composer.width,this._composer.height,!1);break;case"VignettePass":r.effect=new WAGNER.VignettePass,n=api.extend(n,{amount:.7,falloff:.2});break;case"DirectionalBlurPass":r.effect=new WAGNER.DirectionalBlurPass,n=api.extend(n,{delta:.1});break;case"MotionBlurPass":r.effect=new WAGNER.DirectionalBlurPass,r.motionBlurEnable=!0,n=api.extend(n,{delta:0});break;case"ASCIIPass":r.effect=new WAGNER.ASCIIPass;break;case"DotScreenPass":r.effect=new WAGNER.DotScreenPass;break;case"FxaaPass":r.effect=new WAGNER.FXAAPass;break;case"ChromaticAberrationPass":r.effect=new WAGNER.ChromaticAberrationPass;break;case"DirtPass":r.effect=new WAGNER.DirtPass;break;case"EdgeDetectionPass":r.effect=new WAGNER.SobelEdgeDetectionPass;break;case"HighPassPass":r.effect=new WAGNER.HighPassPass;break;case"GrayscalePass":r.effect=new WAGNER.GrayscalePass;break;case"HalftonePass":r.effect=new WAGNER.HalftonePass;break;case"InvertPass":r.effect=new WAGNER.InvertPass;break;default:return void console.warn('No Wagner effect "'+e+'" exists. If it should exist, open an issue. (@addWagner)')}return r.effect.params=n,this._composer.stack.addPass(e,!0,n),r},WHS.init.prototype.initWagner=function(){this._composer=new WAGNER.Composer(this._renderer),this._composer.setSize(this._settings.rWidth,this._settings.rHeight),this._composer.autoClearColor=!0,this._composer.reset(),this._composer.render(this.scene,this._camera),this._composer.stack=new WAGNER.Stack(new WAGNER.ShadersPool)};var PI_2=Math.PI/2;WHS.init.prototype.MakeFirstPerson=function(e,t){var r=WHS.API.extend(t,{block:document.getElementById("blocker"),speed:1,ypos:1});this.controls=new function(e,t,r){function n(e){if(c.enabled!==!1){var t=e.movementX||e.mozMovementX||e.getMovementX()||0,r=e.movementY||e.mozMovementY||e.getMovementY()||0;u.rotation.y-=.002*t,h.rotation.x-=.002*r,h.rotation.x=Math.max(-PI_2,Math.min(PI_2,h.rotation.x))}}function o(e){switch(e.keyCode){case 38:case 87:d=!0;break;case 37:case 65:f=!0;break;case 40:case 83:m=!0;break;case 39:case 68:g=!0;break;case 32:1==y&&(l.applyCentralImpulse({x:0,y:300,z:0}),console.log(l.applyCentralImpulse)),y=!1;break;case 16:s=.5}}function a(e){switch(e.keyCode){case 38:case 87:d=!1;break;case 37:case 65:f=!1;break;case 40:case 83:m=!1;break;case 39:case 68:g=!1;break;case 16:s=.25}}var i=1,s=.25;t.setAngularFactor({x:0,y:0,z:0});var c=this,l=t,h=new THREE.Object3D;h.add(e);var u=new THREE.Object3D;u.position.y=r.ypos,u.add(h);var p=new THREE.Quaternion,d=!1,m=!1,f=!1,g=!1,y=!1;l.addEventListener("collision",function(e,t,r,n){n.y<.5&&(y=!0)}),document.body.addEventListener("mousemove",n,!1),document.body.addEventListener("keydown",o,!1),
-document.body.addEventListener("keyup",a,!1),this.enabled=!1,this.getObject=function(){return u},this.getDirection=function(e){e.set(0,0,-1),p.multiplyVector3(e)};var E=new THREE.Vector3,v=new THREE.Euler;this.update=function(e){new THREE.Vector3;if(c.enabled!==!1){e=e||.5,e=Math.min(e,.5),E.set(0,0,0);var t=i*e*r.speed*s;d&&(E.z=-t),m&&(E.z=t),f&&(E.x=-t),g&&(E.x=t),v.x=h.rotation.x,v.y=u.rotation.y,v.order="XYZ",p.setFromEuler(v),E.applyQuaternion(p),l.applyCentralImpulse({x:10*E.x,y:0,z:10*E.z}),l.setAngularVelocity({x:10*E.z,y:0,z:10*-E.x}),l.setAngularFactor({x:0,y:0,z:0}),u.position.copy(l.position)}}}(this._camera,e.mesh,r);var n=this.controls;if(WHS.API.merge(this.scene,this.controls.getObject()),"pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document){var o=document.body;this.pointerlockchange=function(){document.pointerLockElement===o||document.mozPointerLockElement===o||document.webkitPointerLockElement===o?(n.enabled=!0,r.block.fadeOut()):(n.enabled=!1,r.block.fadeIn())}}else console.warn("Your browser does not support the PointerLock API.");document.addEventListener("pointerlockchange",this.pointerlockchange,!1),document.addEventListener("mozpointerlockchange",this.pointerlockchange,!1),document.addEventListener("webkitpointerlockchange",this.pointerlockchange,!1),this.pointerlockerror=function(){console.warn("Pointer lock error.")},document.addEventListener("pointerlockerror",this.pointerlockerror,!1),document.addEventListener("mozpointerlockerror",this.pointerlockerror,!1),document.addEventListener("webkitpointerlockerror",this.pointerlockerror,!1),r.block.addEventListener("click",function(){if(o.requestPointerLock=o.requestPointerLock||o.mozRequestPointerLock||o.webkitRequestPointerLock,o.requestFullscreen=o.requestFullscreen||o.mozRequestFullscreen||o.mozRequestFullScreen||o.webkitRequestFullscreen,/Firefox/i.test(navigator.userAgent)){var e=function t(){(document.fullscreenElement===o||document.mozFullscreenElement===o||document.mozFullScreenElement===o)&&(document.removeEventListener("fullscreenchange",t),document.removeEventListener("mozfullscreenchange",t),o.requestPointerLock())};document.addEventListener("fullscreenchange",e,!1),document.addEventListener("mozfullscreenchange",e,!1),o.requestFullscreen()}else o.requestPointerLock()})},WHS.init.prototype.OrbitControls=function(e){if(this.controls=new THREE.OrbitControls(this._camera,this._renderer.domElement),e)if(e._whsobject){var t=e?e.mesh.position:new THREE.Vector3(0,0,0);this.controls.target=t}else"object"==("undefined"==typeof e?"undefined":_typeof(e))?this.controls.target.copy(t):console.error("Object must be a THREE.JS vector! @OrbitControls")},WHS.Skybox=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"skybox"));api.extend(e,{skyType:"box",detail:".png",radius:10,path:""});var n,o;switch(e.skyType){case"box":var a=["xpos","xneg","ypos","yneg","zpos","zneg"];n=new THREE.CubeGeometry(e.radius,e.radius,e.radius);for(var i=[],s=0;6>s;s++)i.push(new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture(e.path+a[s]+e.imgSuffix),side:THREE.BackSide}));o=new THREE.MeshFaceMaterial(i);break;case"sphere":n=new THREE.SphereGeometry(e.radius/2,60,40),o=new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture(e.path+e.imgSuffix),side:THREE.BackSide})}return r.mesh=new THREE.Mesh(n,o),r.mesh.renderDepth=1e3,_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Skybox=function(e){return new WHS.Skybox(e).addTo(this)};
\ No newline at end of file
+"use strict";function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Events(e){var t={},r=[];e=e||this,e.on=function(e,r,n){(t[e]=t[e]||[]).push([r,n])},e.off=function(e,n){e||(t={});for(var o=t[e]||r,a=o.length=n?o.length:0;a--;)n==o[a][0]&&o.splice(a,1)},e.emit=function(e){for(var n,o=t[e]||r,a=0;n=o[a++];)n[0].apply(n[1],r.slice.call(arguments,1))}}function addCSSRule(e,t,r,n){e.insertRule?e.insertRule(t+"{"+r+"}",n):e.addRule&&e.addRule(t,r,n)}var _get=function e(t,r,n){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,r);if(void 0===o){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,n)}if("value"in o)return o.value;var i=o.get;if(void 0!==i)return i.call(n)},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};THREE.AnaglyphEffect=function(e,t,r){var n,o,a,i,s=new THREE.Matrix4,c=new THREE.Matrix4,l=125,h=new THREE.PerspectiveCamera;h.matrixAutoUpdate=!1;var u=new THREE.PerspectiveCamera;u.matrixAutoUpdate=!1;var p=new THREE.OrthographicCamera(-1,1,1,-1,0,1),d=new THREE.Scene,m={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat};void 0===t&&(t=512),void 0===r&&(r=512);var f=new THREE.WebGLRenderTarget(t,r,m),g=new THREE.WebGLRenderTarget(t,r,m),y=new THREE.ShaderMaterial({uniforms:{mapLeft:{type:"t",value:f},mapRight:{type:"t",value:g}},vertexShader:["varying vec2 vUv;","void main() {","	vUv = vec2( uv.x, uv.y );","	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform sampler2D mapLeft;","uniform sampler2D mapRight;","varying vec2 vUv;","void main() {","	vec4 colorL, colorR;","	vec2 uv = vUv;","	colorL = texture2D( mapLeft, uv );","	colorR = texture2D( mapRight, uv );","	gl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;","}"].join("\n")}),E=new THREE.Mesh(new THREE.PlaneBufferGeometry(2,2),y);d.add(E),this.setSize=function(t,r){f&&f.dispose(),g&&g.dispose(),f=new THREE.WebGLRenderTarget(t,r,m),g=new THREE.WebGLRenderTarget(t,r,m),y.uniforms.mapLeft.value=f,y.uniforms.mapRight.value=g,e.setSize(t,r)},this.render=function(t,r){t.updateMatrixWorld(),void 0===r.parent&&r.updateMatrixWorld();var m=n!==r.aspect||o!==r.near||a!==r.far||i!==r.fov;if(m){n=r.aspect,o=r.near,a=r.far,i=r.fov;var y,E,v=r.projectionMatrix.clone(),_=l/30*.5,b=_*o/l,H=o*Math.tan(THREE.Math.degToRad(.5*i));s.elements[12]=_,c.elements[12]=-_,y=-H*n+b,E=H*n+b,v.elements[0]=2*o/(E-y),v.elements[8]=(E+y)/(E-y),h.projectionMatrix.copy(v),y=-H*n-b,E=H*n-b,v.elements[0]=2*o/(E-y),v.elements[8]=(E+y)/(E-y),u.projectionMatrix.copy(v)}h.matrixWorld.copy(r.matrixWorld).multiply(c),h.position.copy(r.position),h.near=r.near,h.far=r.far,e.render(t,h,f,!0),u.matrixWorld.copy(r.matrixWorld).multiply(s),u.position.copy(r.position),u.near=r.near,u.far=r.far,e.render(t,u,g,!0),e.render(d,p)},this.dispose=function(){f&&f.dispose(),g&&g.dispose()}},THREE.BufferGeometryUtils={computeTangents:function(e){function t(e,t,r){m.fromArray(i,3*e),f.fromArray(i,3*t),g.fromArray(i,3*r),y.fromArray(c,2*e),E.fromArray(c,2*t),v.fromArray(c,2*r);var n=f.x-m.x,o=g.x-m.x,a=f.y-m.y,s=g.y-m.y,l=f.z-m.z,h=g.z-m.z,d=E.x-y.x,H=v.x-y.x,w=E.y-y.y,T=v.y-y.y,S=1/(d*T-H*w);_.set((T*n-w*o)*S,(T*a-w*s)*S,(T*l-w*h)*S),b.set((d*o-H*n)*S,(d*s-H*a)*S,(d*h-H*l)*S),u[e].add(_),u[t].add(_),u[r].add(_),p[e].add(b),p[t].add(b),p[r].add(b)}function r(e){L.fromArray(s,3*e),A.copy(L),P=u[e],j.copy(P),j.sub(L.multiplyScalar(L.dot(P))).normalize(),W.crossVectors(A,P),M=W.dot(p[e]),C=0>M?-1:1,h[4*e]=j.x,h[4*e+1]=j.y,h[4*e+2]=j.z,h[4*e+3]=C}var n=e.index,o=e.attributes;if(null===n||void 0===o.position||void 0===o.normal||void 0===o.uv)return void console.warn("THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()");var a=n.array,i=o.position.array,s=o.normal.array,c=o.uv.array,l=i.length/3;void 0===o.tangent&&e.addAttribute("tangent",new THREE.BufferAttribute(new Float32Array(4*l),4));for(var h=o.tangent.array,u=[],p=[],d=0;l>d;d++)u[d]=new THREE.Vector3,p[d]=new THREE.Vector3;var m=new THREE.Vector3,f=new THREE.Vector3,g=new THREE.Vector3,y=new THREE.Vector2,E=new THREE.Vector2,v=new THREE.Vector2,_=new THREE.Vector3,b=new THREE.Vector3,H=e.groups;0===H.length&&(H=[{start:0,count:a.length}]);for(var w=0,T=H.length;T>w;++w)for(var S=H[w],R=S.start,x=S.count,O=R,k=R+x;k>O;O+=3)t(a[O+0],a[O+1],a[O+2]);for(var C,P,M,j=new THREE.Vector3,W=new THREE.Vector3,L=new THREE.Vector3,A=new THREE.Vector3,w=0,T=H.length;T>w;++w)for(var S=H[w],R=S.start,x=S.count,O=R,k=R+x;k>O;O+=3)r(a[O+0]),r(a[O+1]),r(a[O+2])}},THREE.OrbitControls=function(e,t){function r(){return 2*Math.PI/60/60*p.autoRotateSpeed}function n(){return Math.pow(.95,p.zoomSpeed)}function o(e){if(p.enabled!==!1){if(e.preventDefault(),0===e.button){if(p.noRotate===!0)return;k=O.ROTATE,m.set(e.clientX,e.clientY)}else if(1===e.button){if(p.noZoom===!0)return;k=O.DOLLY,_.set(e.clientX,e.clientY)}else if(2===e.button){if(p.noPan===!0)return;k=O.PAN,y.set(e.clientX,e.clientY)}p.domElement.addEventListener("mousemove",a,!1),p.domElement.addEventListener("mouseup",i,!1)}}function a(e){if(p.enabled!==!1){e.preventDefault();var t=p.domElement===document?p.domElement.body:p.domElement;if(k===O.ROTATE){if(p.noRotate===!0)return;f.set(e.clientX,e.clientY),g.subVectors(f,m),p.rotateLeft(2*Math.PI*g.x/t.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*g.y/t.clientHeight*p.rotateSpeed),m.copy(f)}else if(k===O.DOLLY){if(p.noZoom===!0)return;b.set(e.clientX,e.clientY),H.subVectors(b,_),H.y>0?p.dollyIn():p.dollyOut(),_.copy(b)}else if(k===O.PAN){if(p.noPan===!0)return;E.set(e.clientX,e.clientY),v.subVectors(E,y),p.pan(v),y.copy(E)}p.update()}}function i(){p.enabled!==!1&&(p.domElement.removeEventListener("mousemove",a,!1),p.domElement.removeEventListener("mouseup",i,!1),k=O.NONE)}function s(e){if(p.enabled!==!1&&p.noZoom!==!0){var t=0;e.wheelDelta?t=e.wheelDelta:e.detail&&(t=-e.detail),t>0?p.dollyOut():p.dollyIn()}}function c(e){if(p.enabled!==!1&&p.noKeys!==!0&&p.noPan!==!0){var t=!1;switch(e.keyCode){case p.keys.UP:p.pan(new THREE.Vector2(0,p.keyPanSpeed)),t=!0;break;case p.keys.BOTTOM:p.pan(new THREE.Vector2(0,-p.keyPanSpeed)),t=!0;break;case p.keys.LEFT:p.pan(new THREE.Vector2(p.keyPanSpeed,0)),t=!0;break;case p.keys.RIGHT:p.pan(new THREE.Vector2(-p.keyPanSpeed,0)),t=!0}t&&p.update()}}function l(e){if(p.enabled!==!1)switch(e.touches.length){case 1:if(p.noRotate===!0)return;k=O.TOUCH_ROTATE,m.set(e.touches[0].pageX,e.touches[0].pageY);break;case 2:if(p.noZoom===!0)return;k=O.TOUCH_DOLLY;var t=e.touches[0].pageX-e.touches[1].pageX,r=e.touches[0].pageY-e.touches[1].pageY,n=Math.sqrt(t*t+r*r);_.set(0,n);break;case 3:if(p.noPan===!0)return;k=O.TOUCH_PAN,y.set(e.touches[0].pageX,e.touches[0].pageY);break;default:k=O.NONE}}function h(e){if(p.enabled!==!1){e.preventDefault(),e.stopPropagation();var t=p.domElement===document?p.domElement.body:p.domElement;switch(e.touches.length){case 1:if(p.noRotate===!0)return;if(k!==O.TOUCH_ROTATE)return;f.set(e.touches[0].pageX,e.touches[0].pageY),g.subVectors(f,m),p.rotateLeft(2*Math.PI*g.x/t.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*g.y/t.clientHeight*p.rotateSpeed),m.copy(f);break;case 2:if(p.noZoom===!0)return;if(k!==O.TOUCH_DOLLY)return;var r=e.touches[0].pageX-e.touches[1].pageX,n=e.touches[0].pageY-e.touches[1].pageY,o=Math.sqrt(r*r+n*n);b.set(0,o),H.subVectors(b,_),H.y>0?p.dollyOut():p.dollyIn(),_.copy(b);break;case 3:if(p.noPan===!0)return;if(k!==O.TOUCH_PAN)return;E.set(e.touches[0].pageX,e.touches[0].pageY),v.subVectors(E,y),p.pan(v),y.copy(E);break;default:k=O.NONE}}}function u(){p.enabled!==!1&&(k=O.NONE)}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.target=new THREE.Vector3,this.center=this.target,this.noZoom=!1,this.zoomSpeed=1,this.minDistance=0,this.maxDistance=1/0,this.noRotate=!1,this.rotateSpeed=1,this.noPan=!1,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.noKeys=!1,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40};var p=this,d=1e-6,m=new THREE.Vector2,f=new THREE.Vector2,g=new THREE.Vector2,y=new THREE.Vector2,E=new THREE.Vector2,v=new THREE.Vector2,_=new THREE.Vector2,b=new THREE.Vector2,H=new THREE.Vector2,w=0,T=0,S=1,R=new THREE.Vector3,x=new THREE.Vector3,O={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},k=O.NONE,C={type:"change"};this.rotateLeft=function(e){void 0===e&&(e=r()),T-=e},this.rotateUp=function(e){void 0===e&&(e=r()),w-=e},this.panLeft=function(e){var t=new THREE.Vector3,r=this.object.matrix.elements;t.set(r[0],r[1],r[2]),t.multiplyScalar(-e),R.add(t)},this.panUp=function(e){var t=new THREE.Vector3,r=this.object.matrix.elements;t.set(r[4],r[5],r[6]),t.multiplyScalar(e),R.add(t)},this.pan=function(e){var t=p.domElement===document?p.domElement.body:p.domElement;if(void 0!==p.object.fov){var r=p.object.position,n=r.clone().sub(p.target),o=n.length();o*=Math.tan(p.object.fov/2*Math.PI/180),p.panLeft(2*e.x*o/t.clientHeight),p.panUp(2*e.y*o/t.clientHeight)}else void 0!==p.object.top?(p.panLeft(e.x*(p.object.right-p.object.left)/t.clientWidth),p.panUp(e.y*(p.object.top-p.object.bottom)/t.clientHeight)):console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.")},this.dollyIn=function(e){void 0===e&&(e=n()),S/=e},this.dollyOut=function(e){void 0===e&&(e=n()),S*=e},this.update=function(){var e=this.object.position,t=e.clone().sub(this.target),n=Math.atan2(t.x,t.z),o=Math.atan2(Math.sqrt(t.x*t.x+t.z*t.z),t.y);this.autoRotate&&this.rotateLeft(r()),n+=T,o+=w,o=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,o)),o=Math.max(d,Math.min(Math.PI-d,o));var a=t.length()*S;a=Math.max(this.minDistance,Math.min(this.maxDistance,a)),this.target.add(R),t.x=a*Math.sin(o)*Math.sin(n),t.y=a*Math.cos(o),t.z=a*Math.sin(o)*Math.cos(n),e.copy(this.target).add(t),this.object.lookAt(this.target),T=0,w=0,S=1,R.set(0,0,0),x.distanceTo(this.object.position)>0&&(this.dispatchEvent(C),x.copy(this.object.position))},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",o,!1),this.domElement.addEventListener("mousewheel",s,!1),this.domElement.addEventListener("DOMMouseScroll",s,!1),this.domElement.addEventListener("keydown",c,!1),this.domElement.addEventListener("touchstart",l,!1),this.domElement.addEventListener("touchend",u,!1),this.domElement.addEventListener("touchmove",h,!1)},THREE.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype);var Stats=function(){function e(e,t,r){return e=document.createElement(e),e.id=t,e.style.cssText=r,e}function t(t,r,n){var o=e("div",t,"padding:0 0 3px 3px;text-align:left;background:"+n),a=e("div",t+"Text","font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px;color:"+r);for(a.innerHTML=t.toUpperCase(),o.appendChild(a),t=e("div",t+"Graph","width:74px;height:30px;background:"+r),o.appendChild(t),r=0;74>r;r++)t.appendChild(e("span","","width:1px;height:30px;float:left;opacity:0.9;background:"+n));return o}function r(e){for(var t=l.children,r=0;r<t.length;r++)t[r].style.display=r===e?"block":"none";c=e}function n(e,t){e.appendChild(e.firstChild).style.height=Math.min(30,30-30*t)+"px"}var o=self.performance&&self.performance.now?self.performance.now.bind(performance):Date.now,a=o(),i=a,s=0,c=0,l=e("div","stats","width:80px;opacity:0.9;cursor:pointer");l.addEventListener("mousedown",function(e){e.preventDefault(),r(++c%l.children.length)},!1);var h=0,u=1/0,p=0,d=t("fps","#0ff","#002"),m=d.children[0],f=d.children[1];l.appendChild(d);var g=0,y=1/0,E=0,d=t("ms","#0f0","#020"),v=d.children[0],_=d.children[1];if(l.appendChild(d),self.performance&&self.performance.memory){var b=0,H=1/0,w=0,d=t("mb","#f08","#201"),T=d.children[0],S=d.children[1];l.appendChild(d)}return r(c),{REVISION:14,domElement:l,setMode:r,begin:function(){a=o()},end:function(){var e=o();if(g=e-a,y=Math.min(y,g),E=Math.max(E,g),v.textContent=(0|g)+" MS ("+(0|y)+"-"+(0|E)+")",n(_,g/200),s++,e>i+1e3&&(h=Math.round(1e3*s/(e-i)),u=Math.min(u,h),p=Math.max(p,h),m.textContent=h+" FPS ("+u+"-"+p+")",n(f,h/100),i=e,s=0,void 0!==b)){var t=performance.memory.usedJSHeapSize,r=performance.memory.jsHeapSizeLimit;b=Math.round(9.54e-7*t),H=Math.min(H,b),w=Math.max(w,b),T.textContent=b+" MB ("+H+"-"+w+")",n(S,t/r)}return e},update:function(){a=this.end()}}};"object"===("undefined"==typeof module?"undefined":_typeof(module))&&(module.exports=Stats),THREE.SubdivisionModifier=function(e){this.subdivisions=void 0===e?1:e},THREE.SubdivisionModifier.prototype.modify=function(e){for(var t=this.subdivisions;t-- >0;)this.smooth(e);delete e.__tmpVertices,e.computeFaceNormals(),e.computeVertexNormals()},function(){function e(e,t,r){var n=Math.min(e,t),o=Math.max(e,t),a=n+"_"+o;return r[a]}function t(e,t,r,n,o,a){var i,s=Math.min(e,t),c=Math.max(e,t),l=s+"_"+c;if(l in n)i=n[l];else{var h=r[s],u=r[c];i={a:h,b:u,newEdge:null,faces:[]},n[l]=i}i.faces.push(o),a[e].edges.push(i),a[t].edges.push(i)}function r(e,r,n,o){var a,i,s;for(a=0,i=e.length;i>a;a++)n[a]={edges:[]};for(a=0,i=r.length;i>a;a++)s=r[a],t(s.a,s.b,e,o,s,n),t(s.b,s.c,e,o,s,n),t(s.c,s.a,e,o,s,n)}function n(e,t,r,n){e.push(new THREE.Face3(t,r,n))}var o=!1,a=["a","b","c"];THREE.SubdivisionModifier.prototype.smooth=function(t){var i,s,c,l,h,u,p,d,m,f,g,g,y,E,v=new THREE.Vector3;i=t.vertices,s=t.faces,f=new Array(i.length),g={},r(i,s,f,g),y=[];var _,b,H,w,T,S,R;for(u in g){for(b=g[u],H=new THREE.Vector3,T=3/8,S=1/8,R=b.faces.length,2!=R&&(T=.5,S=0,1!=R&&o&&console.warn("Subdivision Modifier: Number of connected faces != 2, is: ",R,b)),H.addVectors(b.a,b.b).multiplyScalar(T),v.set(0,0,0),d=0;R>d;d++){for(w=b.faces[d],m=0;3>m&&(_=i[w[a[m]]],_===b.a||_===b.b);m++);v.add(_)}v.multiplyScalar(S),H.add(v),b.newEdge=y.length,y.push(H)}var x,O,k,C,P,M,j;for(E=[],u=0,p=i.length;p>u;u++){for(M=i[u],P=f[u].edges,h=P.length,3==h?x=3/16:h>3&&(x=3/(8*h)),O=1-h*x,k=x,2>=h&&(2==h?(o&&console.warn("2 connecting edges",P),O=.75,k=1/8):1==h?o&&console.warn("only 1 connecting edge"):0==h&&o&&console.warn("0 connecting edges")),j=M.clone().multiplyScalar(O),v.set(0,0,0),d=0;h>d;d++)C=P[d],_=C.a!==M?C.a:C.b,v.add(_);v.multiplyScalar(k),j.add(v),E.push(j)}c=E.concat(y);var W,L,A,V=E.length;for(l=[],u=0,p=s.length;p>u;u++)w=s[u],W=e(w.a,w.b,g).newEdge+V,L=e(w.b,w.c,g).newEdge+V,A=e(w.c,w.a,g).newEdge+V,n(l,W,L,A),n(l,w.a,W,A),n(l,w.b,L,W),n(l,w.c,A,L);t.vertices=c,t.faces=l}}(),addCSSRule(document.styleSheets[0],"@keyframes fadeOut","to {opacity: 0}",0),addCSSRule(document.styleSheets[0],"@keyframes fadeIn","from {opacity: 0} to {opacity: 1}",0),Element.prototype.fadeOut=function(e){this.style.webkitAnimationDuration=(e||1)+"s",this.style.webkitAnimationName="fadeOut",this.style.webkitAnimationPlayState="running",this.addEventListener("animationend",function(){this.style.display="none",this.style.webkitAnimationPlayState="paused"})},Element.prototype.fadeIn=function(e,t){this.style.display=t||"block",this.style.webkitAnimationDuration=(e||1)+"s",this.style.webkitAnimationName="fadeIn",this.style.webkitAnimationPlayState="running",this.addEventListener("animationend",function(){this.style.display=t||"block"})},"undefined"==typeof Array.isArray&&(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),function(){if(!MouseEvent.prototype.hasOwnProperty("movementX")||!MouseEvent.prototype.hasOwnProperty("mozMovementX")){var e={lastX:0,lastY:0};MouseEvent.prototype.getMovementX=function(){var t=this.clientX-e.lastX;return e.lastX=this.clientX,t},MouseEvent.prototype.getMovementY=function(){var t=this.clientY-e.lastY;return e.lastY=this.clientY,t}}}(),Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(void 0===e||null===e)throw new TypeError("Cannot convert first argument to object");for(var t=Object(e),r=1;r<arguments.length;r++){var n=arguments[r];if(void 0!==n&&null!==n){n=Object(n);for(var o=Object.keys(n),a=0,i=o.length;i>a;a++){var s=o[a],c=Object.getOwnPropertyDescriptor(n,s);void 0!==c&&c.enumerable&&(t[s]=n[s])}}}return t}});var WHS={REVISION:"7",API:{},_settings:{assets:"./assets",path_worker:"../libs/physijs_worker.js",path_ammo:"../libs/ammo.js"},loops:[],grounds:[]},api=WHS.API;"function"==typeof define&&define.amd?define("whitestorm",WHS):"undefined"!=typeof exports&&"undefined"!=typeof module&&(module.exports=WHS),THREE.ShaderTerrain={terrain:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{enableDiffuse1:{type:"i",value:0},enableDiffuse2:{type:"i",value:0},enableSpecular:{type:"i",value:0},enableReflection:{type:"i",value:0},tDiffuse1:{type:"t",value:null},tDiffuse2:{type:"t",value:null},tDetail:{type:"t",value:null},tNormal:{type:"t",value:null},tSpecular:{type:"t",value:null},tDisplacement:{type:"t",value:null},uNormalScale:{type:"f",value:1},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},diffuse:{type:"c",value:new THREE.Color(15658734)},specular:{type:"c",value:new THREE.Color(1118481)},shininess:{type:"f",value:30},opacity:{type:"f",value:1},uRepeatBase:{type:"v2",value:new THREE.Vector2(1,1)},uRepeatOverlay:{type:"v2",value:new THREE.Vector2(1,1)},uOffset:{type:"v2",value:new THREE.Vector2(0,0)}}]),fragmentShader:["\n		        uniform vec3 diffuse;\n		        uniform vec3 emissive;\n		        uniform float opacity;\n		        uniform vec3 ambientLightColor;\n		        varying vec3 vLightFront;\n		        #ifdef DOUBLE_SIDED\n			        varying vec3 vLightBack;\n			        uniform vec2 uRepeatOverlay;\n			        uniform vec2 uRepeatBase;\n			        uniform vec2 uOffset;\n			        uniform float uNormalScale;\n			        uniform sampler2D tNormal;\n		        #endif\n		        uniform sampler2D oceanTexture;\n		        uniform sampler2D sandyTexture;\n		        uniform sampler2D grassTexture;\n		        uniform sampler2D rockyTexture;\n		        uniform sampler2D snowyTexture;\n		        varying vec3 vTangent;\n		        varying vec3 vBinormal;\n		        varying vec3 vNormal;\n		        varying vec3 vViewPosition;\n		"+[THREE.ShaderChunk.common,THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.alphamap_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.specularmap_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment].join("\n")+"\n		        varying vec2 vUv;\n		        varying float vAmount;\n		        void main() {\n		        	// UVs.\n		            vec2 uvOverlay = uRepeatOverlay * vUv + uOffset;\n		            vec2 uvBase = uRepeatBase * vUv;\n					vec3 specularTex = vec3( 1.0 );\n		            vec3 normalTex = texture2D( tNormal, uvOverlay ).xyz * 2.0 - 1.0;\n		            normalTex.xy *= uNormalScale;\n		            normalTex = normalize( normalTex );\n		            mat3 tsb = mat3( vTangent, vBinormal, vNormal );\n		            vec3 finalNormal = tsb * normalTex;\n		            vec3 normal = normalize( finalNormal );\n		            vec3 viewPosition = normalize( vViewPosition );\n		            vec3 shadowMask = vec3( 1.0 );\n		            vec3 outgoingLight = vec3( 0.0 );\n		            vec3 totalAmbientLight = ambientLightColor;\n		            vec4 diffuseColor = vec4(0.0);\n		            // Color by texture.\n		            vec4 water = (smoothstep(0.01, 0.25, vAmount)\n		            - smoothstep(0.24, 0.26, vAmount))\n		            * texture2D( oceanTexture, vUv * 10.0 );\n		            vec4 sandy = (smoothstep(0.24, 0.27, vAmount)\n		            - smoothstep(0.28, 0.31, vAmount))\n		            * texture2D( sandyTexture, vUv * 10.0 );\n		            vec4 grass = (smoothstep(0.28, 0.32, vAmount)\n		            - smoothstep(0.35, 0.40, vAmount))\n		            * texture2D( grassTexture, vUv * 20.0 );\n		            vec4 rocky = (smoothstep(0.30, 0.40, vAmount)\n		            - smoothstep(0.40, 0.70, vAmount))\n		            * texture2D( rockyTexture, vUv * 20.0 );\n		            vec4 snowy = (smoothstep(0.42, 0.45, vAmount))\n		            * texture2D( snowyTexture, vUv * 10.0 );\n		            diffuseColor = vec4(0.0, 0.0, 0.0, 1.0)\n		            + water + sandy + grass + rocky + snowy;\n		"+[THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphamap_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.specularmap_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment].join("\n")+"\n		            #ifdef DOUBLE_SIDED\n		                if ( gl_FrontFacing )\n		                    outgoingLight += diffuseColor.rgb * \n		                		( vLightFront * shadowMask + totalAmbientLight )\n		                		+ emissive;\n		                else\n		                    outgoingLight += diffuseColor.rgb * \n		                		( vLightBack * shadowMask + totalAmbientLight )\n		                		+ emissive;\n		            #else\n		                outgoingLight += diffuseColor.rgb * \n		                	( vLightFront * shadowMask + totalAmbientLight )\n		                	+ emissive;\n		            #endif\n		           gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n		      }\n		"],vertexShader:["\n		    #define TERRAIN;\n		    varying vec3 vLightFront;\n		    #ifdef DOUBLE_SIDED\n		        varying vec3 vLightBack;\n		    #endif\n		    \n		    varying float vAmount;\n		    attribute vec4 tangent;\n		    uniform vec2 uRepeatBase;\n		    uniform sampler2D tNormal;\n		    #ifdef VERTEX_TEXTURES\n			    uniform sampler2D tDisplacement;\n			    uniform float uDisplacementScale;\n			    uniform float uDisplacementBias;\n		    #endif\n		    varying vec3 vTangent;\n		    varying vec3 vBinormal;\n		    varying vec3 vNormal;\n		    varying vec2 vUv;\n		    varying vec3 vViewPosition;\n		"+[THREE.ShaderChunk.common,THREE.ShaderChunk.uv_pars_vertex,THREE.ShaderChunk.uv2_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_lambert_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex].join("\n")+"\n		    void main() {\n		"+[THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.beginnormal_vertex,THREE.ShaderChunk.morphnormal_vertex,THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.skinnormal_vertex,THREE.ShaderChunk.defaultnormal_vertex,THREE.ShaderChunk.begin_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.project_vertex,THREE.ShaderChunk.logdepthbuf_vertex,THREE.ShaderChunk.uv_vertex,THREE.ShaderChunk.uv2_vertex].join("\n")+"\n			    vNormal = normalize( normalMatrix * normal);\n			    // Tangent and binormal vectors.\n			    vTangent = normalize( normalMatrix * tangent.xyz );\n			    vBinormal = cross( vNormal, vTangent ) * tangent.w;\n			    vBinormal = normalize( vBinormal );\n			    // Texture coordinates.\n			    vUv = uv;\n			    vec2 uvBase = uv * uRepeatBase;\n			    // displacement mapping\n			    vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n			    mvPosition = modelViewMatrix * vec4( position, 1.0 );\n			    transformedNormal = normalize( normalMatrix * normal );\n			    gl_Position = projectionMatrix * mvPosition;\n			    vViewPosition = -mvPosition.xyz;\n			    vAmount = position.z * 0.005 + 0.1;\n		"+[THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.lights_lambert_vertex,THREE.ShaderChunk.shadowmap_vertex].join("\n")+"\n		   }\n		"],side:THREE.DoubleSide,shading:THREE.SmoothShading}},WHS.API.extend=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;t>n;n++)r[n-1]=arguments[n];var o=!0,a=!1,i=void 0;try{for(var s,c=r[Symbol.iterator]();!(o=(s=c.next()).done);o=!0){var l=s.value;if(l){var h=!0,u=!1,p=void 0;try{for(var d,m=Object.getOwnPropertyNames(l)[Symbol.iterator]();!(h=(d=m.next()).done);h=!0){var f=d.value;void 0!=e[f]&&"[object Object]"==e[f].toString()&&"[object Object]"==l[f].toString()?WHS.API.extend(e[f],l[f]):e[f]=0===e[f]?0:e[f]||l[f]}}catch(g){u=!0,p=g}finally{try{!h&&m["return"]&&m["return"]()}finally{if(u)throw p}}}}}catch(g){a=!0,i=g}finally{try{!o&&c["return"]&&c["return"]()}finally{if(a)throw i}}return e},WHS.API.getheight=function(e,t,r,n){return t=t||1e3,n=n||1,this.raycaster=new THREE.Raycaster(new THREE.Vector3(e.x,t,n*e.y),new THREE.Vector3(0,-1,0)),this.intersect=this.raycaster.intersectObject(r.mesh),this.intersect},WHS.Light=function(){function e(t,r){_classCallCheck(this,e);var n=function(e,t,r){this.x=e,this.y=t,this.z=r};t.pos&&(t.pos.set=n),t.rot&&(t.rot.set=n),t.target&&(t.target.set=n);var o=api.extend(t,{light:{color:16777215,skyColor:16777215,groundColor:16777215,intensity:1,distance:100,angle:Math.PI/3},shadowmap:{cast:!0,bias:1e-4,width:1024,height:1024,near:!0,far:400,fov:60,darkness:.3,top:200,bottom:-200,left:-200,right:200},pos:{x:0,y:0,z:0,set:n},rot:{x:0,y:0,z:0,set:n},target:{x:0,y:0,z:0,set:n}}),a=0,i={_key:a,_type:r,_whsobject:!0,_name:r+a,__releaseTime:(new Date).getTime(),_pos:o.pos,_rot:o.rot,_target:o.target,_light:o.light,_shadowmap:o.shadowmap,ready:new Events};return Object.assign(this,i),this}return _createClass(e,[{key:"build",value:function(){for(var e=this,t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];var o=this.mesh,a=this;return this.build_state=new Promise(function(t,n){try{o.castShadow=!0,o.receiveShadow=!0,o.position.set(e._pos.x,e._pos.y,e._pos.z),o.rotation.set(e._rot.x,e._rot.y,e._rot.z),r.forEach(function(e){a[e]=!0}),t()}catch(i){console.error(i.message),n()}}),this}},{key:"addTo",value:function(e){this.root=e;var t=this.mesh,r=this;return console.log(this),this._key=this.root.modellingQueue.length,r._state=new Promise(function(e,n){try{api.merge(r.root.scene,t),r.root.modellingQueue.push(r)}catch(o){console.error(o.message),n()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),r.ready.emit("ready"))}}),r.root.children.push(r),this}},{key:"buildShadow",value:function(){this.mesh.shadowMapWidth=this._shadowmap.width,this.mesh.shadowMapHeight=this._shadowmap.height,this.mesh.shadowBias=this._shadowmap.bias,this.mesh.shadowCameraNear=this._shadowmap.near,this.mesh.shadowCameraFar=this._shadowmap.far,this.mesh.shadowCameraFov=this._shadowmap.fov,this.mesh.shadowDarkness=this._shadowmap.darkness,this.mesh.shadowCameraLeft=this._shadowmap.left,this.mesh.shadowCameraRight=this._shadowmap.right,this.mesh.shadowCameraTop=this._shadowmap.top,this.mesh.shadowCameraBottom=this._shadowmap.bottom}},{key:"remove",value:function(){return this.root.scene.remove(this.mesh),this}},{key:"retrieve",value:function(){return this.root.scene.add(this.mesh),this}}]),e}(),WHS.API.JSONLoader=function(){return new THREE.JSONLoader},WHS.API.TextureLoader=function(){return new THREE.TextureLoader},WHS.API.loadMaterial=function(e){"string"!=typeof e.kind&&console.error("Type of material is undefined or not a string. @loadMaterial");var t={_type:e.kind,_restitution:e.restitution||e.rest||.3,_friction:e.friction||e.fri||.8},r=api.extend({},e);switch(delete r.kind,delete r.friction,delete r.fri,delete r.restitution,delete r.rest,e.kind){case"basic":t._material=new THREE.MeshBasicMaterial(r);break;case"linebasic":t._params=new THREE.LineBasicMaterial(r);break;case"linedashed":t._material=new THREE.LineDashedMaterial(r);break;case"material":t._material=new THREE.Material(r);break;case"depth":t._material=new THREE.MeshDepthMaterial(r);break;case"face":t._material=new THREE.MeshFaceMaterial(r);break;case"lambert":t._material=new THREE.MeshLambertMaterial(r);break;case"normal":t._material=new THREE.MeshNormalMaterial(r);break;case"phong":t._material=new THREE.MeshPhongMaterial(r);break;case"pointcloud":t._material=new THREE.PointCloudMaterial(r);break;case"rawshader":t._material=new THREE.RawShaderMaterial(r);break;case"shader":t._material=new THREE.ShaderMaterial(r);break;case"spritecanvas":t._material=new THREE.SpriteCanvasMaterial(r);break;case"sprite":t._material=new THREE.SpriteMaterial(r)}return t._material=Physijs.createMaterial(t._material,t._friction,t._restitution),console.log(t._friction),t},WHS.API.merge=function(e,t){if(("object"!==("undefined"==typeof e?"undefined":_typeof(e))||"object"!==("undefined"==typeof t?"undefined":_typeof(t)))&&console.error("No rabbits for the box. (arguments)",["undefined"==typeof e?"undefined":_typeof(e),"undefined"==typeof t?"undefined":_typeof(t)]),e)if(Array.isArray(t)&&1===t.length)e.add(t[0]);else if(Array.isArray(t)&&t.length>1&&e)for(var r=0;r<t.length;r++)e.add(t[r]);else Array.isArray(t)||e.add(t);else console.error("box is undefined. Line "+(new Error).lineNumber+". Func merge.",[e,t])},WHS.API.PackUvs=function(e){e.computeBoundingBox();var t=e.boundingBox.max,r=e.boundingBox.min,n=new THREE.Vector2(0-r.x,0-r.y),o=new THREE.Vector2(t.x-r.x,t.y-r.y);e.faceVertexUvs[0]=[];for(var a=e.faces,i=0;i<e.faces.length;i++){var s=e.vertices[a[i].a],c=e.vertices[a[i].b],l=e.vertices[a[i].c];e.faceVertexUvs[0].push([new THREE.Vector2((s.x+n.x)/o.x,(s.y+n.y)/o.y),new THREE.Vector2((c.x+n.x)/o.x,(c.y+n.y)/o.y),new THREE.Vector2((l.x+n.x)/o.x,(l.y+n.y)/o.y)])}e.uvsNeedUpdate=!0},WHS.API.removeDuplicateFaces=function(e){function t(){return!(a1.sort()>a2.sort()||a1.sort()<a2.sort())}for(var r=0;r<e.faces.length;r++)for(var n=e.faces[r],o=[n.a,n.b,n.c,n.d].sort(),a=0;r>a;a++){var i=e.faces[a];if(void 0!==i){var s=[i.a,i.b,i.c,i.d].sort();t(o,s)&&(delete e.faces[r],delete e.faces[a])}}return e.faces=e.faces.filter(function(e){return void 0===e}),e},WHS.API.rotateGeometry=function(e,t){var r=new THREE.Matrix4;r.makeRotationFromEuler(new THREE.Euler(t.x,t.y,t.z,"XYZ"));for(var n in e.vertices)e.vertices[n].applyMatrix4(r);return e},WHS.Shape=function(){function e(t,r){_classCallCheck(this,e);var n=function(e,t,r){this.x=e,this.y=t,this.z=r};api.extend(t,{mass:10,pos:{x:0,y:0,z:0,set:n},rot:{x:0,y:0,z:0,set:n},scale:{x:1,y:1,z:1,set:n},target:{x:0,y:0,z:0,set:n},morph:{speed:1,duration:1},onlyvis:!1});var o=0,a={_key:o,_type:r,_whsobject:!0,_name:r+o,__releaseTime:(new Date).getTime(),_pos:t.pos,_rot:t.rot,_scale:t.scale,_morph:t.morph,_target:t.target,_onlyvis:t.onlyvis,ready:new Events};return Object.assign(this,a),this}return _createClass(e,[{key:"build",value:function(){console.log(this);for(var e=this,t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];return r.indexOf("wait")>=0?e._loading.then(function(){e.build_state=new Promise(function(t,r){try{e.mesh.castShadow=!0,e.mesh.receiveShadow=!0,e.mesh.position.set(e._pos.x,e._pos.y,e._pos.z),e.mesh.rotation.set(e._rot.x,e._rot.y,e._rot.z),e.mesh.scale.set(e._scale.x,e._scale.y,e._scale.z),
+e._pos=e.mesh.position,e._rot=e.mesh.rotation,e._scale=e.mesh.scale,t()}catch(n){console.error(n.message),r()}})}):e.build_state=new Promise(function(t,r){try{e.mesh.castShadow=!0,e.mesh.receiveShadow=!0,e.mesh.position.set(e._pos.x,e._pos.y,e._pos.z),e.mesh.rotation.set(e._rot.x,e._rot.y,e._rot.z),e.mesh.scale.set(e._scale.x,e._scale.y,e._scale.z),e._pos=e.mesh.position,e._rot=e.mesh.rotation,e._scale=e.mesh.scale,t()}catch(n){console.error(n.message),r()}}),this}},{key:"addTo",value:function(e){this.root=e;var t=this.mesh,r=this;this._key=this.root.modellingQueue.length;for(var n=arguments.length,o=Array(n>1?n-1:0),a=1;n>a;a++)o[a-1]=arguments[a];return console.log([o,o.indexOf("wait"),r]),o.indexOf("wait")>=0?r._loading.then(function(){r._state=new Promise(function(e,t){try{api.merge(r.root.scene,r.mesh),r.root.modellingQueue.push(r)}catch(n){console.error(n.message),t()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),r.ready.emit("ready"))}})}):r._state=new Promise(function(e,n){try{api.merge(r.root.scene,t),r.root.modellingQueue.push(r)}catch(o){console.error(o.message),n()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),console.log("wqd"),r.ready.emit("ready"))}}),r.root.children.push(r),this}},{key:"_initMaterial",value:function(e){return api.loadMaterial(e)._material}},{key:"remove",value:function(){return this.root.scene.remove(this.mesh),this}},{key:"retrieve",value:function(){return this.root.scene.add(this.mesh),this}}]),e}(),WHS.API.texture=function(e,t){var r=api.TextureLoader().load(e);if(t){var n=api.extend(t,{offset:{x:0,y:0},repeat:{x:1,y:1}});r.wrapS=r.wrapT=THREE.RepeatWrapping,r.offset.set(n.offset.x,n.offset.y),r.repeat.set(n.repeat.x,n.repeat.y),r.magFilter=THREE.NearestFilter,r.minFilter=THREE.LinearMipMapLinearFilter}return r},WHS.API.Triangulate=function(e,t){if(e instanceof THREE.Geometry){if(t){var r=new THREE.Geometry,n=[];e.faces.forEach(function(o){var a=new THREE.Geometry;[].push.apply(a.vertices,[e.vertices[o.a],e.vertices[o.b],e.vertices[o.c]]),a.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(0,1),new THREE.Vector2(1,1),new THREE.Vector2(1,0)]),a.faces.push(new THREE.Face3(0,1,2)),a.computeFaceNormals();var i=new THREE.Mesh(a,t);i.updateMatrix(),r.merge(i.geometry,i.matrix),n.push(t)});var o=new THREE.Mesh(r,new THREE.MeshFaceMaterial(n));return o}}else console.error("No THREE.js geometry")},WHS.Watch=function(e){return this._queue=Array.isArray(e)?e.slice():[],this},WHS.Watch.prototype.add=function(e){return this._queue.push(e),this},WHS.Watch.prototype.remove=function(e){return this._queue=this._queue.filter(function(t){return t!=e}),this},WHS.loop=function(e){this.loop={func:e,id:WHS.loops.length,enabled:!1},WHS.loops.push(this.loop)},WHS.loop.prototype.start=function(){this.loop.enabled=!0},WHS.loop.prototype.stop=function(){this.loop.enabled=!1},WHS.init=function(){function e(t){_classCallCheck(this,e),console.log("WHS.init",WHS.REVISION),THREE||console.warn("whitestormJS requires THREE.js. {Object} THREE not found."),Physijs||console.warn("whitestormJS requires PHYSI.js. {Object} Physijs not found.");var r=api.extend(t,{anaglyph:!1,helper:!1,stats:!1,autoresize:!1,shadowmap:!0,gravity:{x:0,y:0,z:0},camera:{aspect:75,near:1,far:1e3,x:0,y:0,z:0},rWidth:window.innerWidth,rHeight:window.innerHeight,width:window.innerWidth,height:window.innerHeight,physics:{quatNormalizeSkip:0,quatNormalizeFast:!1,solver:{iterations:20,tolerance:0},defMaterial:{contactEquationStiffness:1e8,contactEquationRegularizationTime:3}},background:0,assets:"./assets",container:document.body,path_worker:"../libs/physijs_worker.js",path_ammo:"../libs/ammo.js"});this._settings=r,this._initScene(),this._initDOM(),this._initStats(),this._initCamera(),this._initRenderer();var n=this;return r.autoresize&&window.addEventListener("load resize",function(){n.resize()}),n}return _createClass(e,[{key:"_initScene",value:function(){this._initPhysiJS(),this.scene=new Physijs.Scene,this.scene.setGravity(new THREE.Vector3(this._settings.gravity.x,this._settings.gravity.y,this._settings.gravity.z)),this.modellingQueue=[],this.children=[]}},{key:"_initPhysiJS",value:function(){Physijs.scripts.worker=this._settings.path_worker,Physijs.scripts.ammo=this._settings.path_ammo}},{key:"_initDOM",value:function(){return this._settings.container.style.margin=0,this._settings.container.style.padding=0,this._settings.container.style.position="relative",this._settings.container.style.overflow="hidden",this._dom=document.createElement("div"),this._dom.className="whs",this._settings.container.appendChild(this._dom),this._dom}},{key:"_initStats",value:function(){this._settings.stats&&(this._stats=new Stats,"fps"==this._settings.stats?this._stats.setMode(0):"ms"==this._settings.stats?this._stats.setMode(1):"mb"==this._settings.stats?this._stats.setMode(1):(this._stats.setMode(0),console.warn([this._stats],"Please, apply stats mode [fps, ms, mb] .")),this._stats.domElement.style.position="absolute",this._stats.domElement.style.left="0px",this._stats.domElement.style.bottom="0px",this._dom.appendChild(this._stats.domElement))}},{key:"_initCamera",value:function(){this._camera=new THREE.PerspectiveCamera(this._settings.camera.aspect,this._settings.width/this._settings.height,this._settings.camera.near,this._settings.camera.far),this._camera.position.set(this._settings.camera.x,this._settings.camera.y,this._settings.camera.z),this.scene.add(this._camera)}},{key:"_initRenderer",value:function(){this._renderer=new THREE.WebGLRenderer,this._renderer.setClearColor(this._settings.background),this._renderer.shadowMap.enabled=this._settings.shadowmap,this._renderer.shadowMap.type=THREE.PCFSoftShadowMap,this._renderer.shadowMap.cascade=!0,this._renderer.setSize(this._settings.rWidth,this._settings.rHeight),this._renderer.render(this.scene,this._camera),this._dom.appendChild(this._renderer.domElement),this._renderer.domElement.style.width="100%",this._renderer.domElement.style.height="100%"}},{key:"start",value:function(){function e(n){requestAnimationFrame(e),r._stats&&r._stats.begin(),r._process(t),r.scene.simulate(),r._updateControls(),r._composer?(r._composer.reset(),r._composer.render(r.scene,r._camera),r._composer.pass(r._composer.stack),r._composer.toScreen()):r._renderer.render(r.scene,r._camera),r._loop(n),r._stats&&r._stats.end()}var t=new THREE.Clock,r=this;this._update=e,r._update()}},{key:"_loop",value:function(e){WHS.loops.forEach(function(t){t.enabled&&t.func(e)})}},{key:"_updateControls",value:function(){this.controls&&(this.controls.update(Date.now()-this.time),this.time=Date.now())}},{key:"_process",value:function(e){for(var t=0;t<this.modellingQueue.length;t++)"morph"==this.modellingQueue[t]._type&&this.modellingQueue[t].mesh.mixer.update(e.getDelta())}},{key:"resize",value:function(){this._camera.aspect=window.innerWidth/window.innerHeight,this._camera.updateProjectionMatrix(),this._renderer.setSize(this._settings.rWidth,this._settings.rHeight)}}]),e}(),WHS.Cube=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"cube"));return api.extend(e.geometry,{width:1,height:1,depth:1}),r.mesh=new Physijs.BoxMesh(new THREE.BoxGeometry(e.geometry.width,e.geometry.height,e.geometry.depth),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Cube=function(e){return new WHS.Cube(e).addTo(this)},WHS.Cylinder=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"cylinder"));return api.extend(e.geometry,{radiusTop:1,radiusBottom:1,height:1,radiusSegments:32}),r.mesh=new Physijs.CylinderMesh(new THREE.CylinderGeometry(e.geometry.radiusTop,e.geometry.radiusBottom,e.geometry.height,e.geometry.radiusSegments),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Cylinder=function(e){return new WHS.Cylinder(e).addTo(this)},WHS.Dodecahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"dodecahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.DodecahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Dodecahedron=function(e){return new WHS.Dodecahedron(e).addTo(this)},WHS.Extrude=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"extrude"));return api.extend(e.geometry,{shapes:[],options:{}}),r.mesh=new Physijs.ConvexMesh(new THREE.ExtrudeGeometry(e.geometry.shapes,e.geometry.options),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Extrude=function(e){return new WHS.Extrude(e).addTo(this)},WHS.Icosahderon=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"icosahderon"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.IcosahderonGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Icosahderon=function(e){return new WHS.Icosahderon(e).addTo(this)},WHS.Lathe=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"lathe"));return api.extend(e.geometry,{points:[]}),r.mesh=new Physijs.ConvexMesh(new THREE.LatheGeometry(e.geometry.points),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Lathe=function(e){return new WHS.Lathe(e).addTo(this)},WHS.Model=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"model"));api.extend(e.geometry,{path:""});var n=r,o=_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material);return r._loading=new Promise(function(t,r){api.JSONLoader().load(e.geometry.path,function(r){r.computeFaceNormals(),r.computeVertexNormals(),n.mesh=new Physijs.ConvexMesh(r,o,e.mass),t()})}),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"wait"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Model=function(e){return new WHS.Model(e).addTo(this,"wait")},WHS.Morph=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"morph"));api.extend(e.geometry,{path:""}),console.log(r);var n=r;return r._loading=new Promise(function(t,r){api.JSONLoader().load(e.geometry.path,function(r){var o=new THREE.MeshLambertMaterial({color:16755285,morphTargets:!0,vertexColors:THREE.FaceColors});r.computeFaceNormals(),r.computeVertexNormals(),n.mesh=new THREE.Mesh(r,o),n.mesh.speed=e.morph.speed,n.mesh.mixer=new THREE.AnimationMixer(n.mesh),n.mesh.mixer.addAction(new THREE.AnimationAction(r.animations[0]).warpToDuration(.5)),n.mesh.mixer.update(600*Math.random()),n._rot.y=Math.PI/2,t()})}),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"wait"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Morph=function(e){return new WHS.Morph(e).addTo(this,"wait")},WHS.Octahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"octahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.OctahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Octahedron=function(e){return new WHS.Octahedron(e).addTo(this)},WHS.Parametric=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"parametric"));return api.extend(e.geometry,{func:function(){},slices:10,stacks:10}),r.mesh=new Physijs.ConvexMesh(new THREE.ParametricGeometry(e.geometry.func,e.geometry.slices,e.geometry.stacks),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Parametric=function(e){return new WHS.Parametric(e).addTo(this)},WHS.Plane=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"plane"));return api.extend(e.geometry,{width:10,height:10,segments:32}),r.mesh=new Physijs.ConvexMesh(new THREE.PlaneBufferGeometry(e.geometry.width,e.geometry.height,e.geometry.segments),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Plane=function(e){return new WHS.Plane(e).addTo(this)},WHS.Polyhedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"polyhedron"));return api.extend(e.geometry,{verticesOfCube:[],indicesOfFaces:[],radius:1,detail:1}),r.mesh=new Physijs.ConvexMesh(new THREE.PolyhedronGeometry(e.geometry.verticesOfCube,e.geometry.indicesOfFaces,e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Polyhedron=function(e){return new WHS.Polyhedron(e).addTo(this)},WHS.Ring=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"ring"));return api.extend(e.geometry,{innerRadius:2,outerRadius:5,thetaSegments:30,phiSegments:30,thetaStart:0,thetaLength:2*Math.PI}),r.mesh=new Physijs.ConcaveMesh(new THREE.TorusGeometry(e.geometry.innerRadius,e.geometry.outerRadius,e.geometry.thetaSegments,e.geometry.phiSegments,e.geometry.thetaStart,e.geometry.thetaLength),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Ring=function(e){return new WHS.Ring(e).addTo(this)},WHS.Shape2D=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"shape2D"));return api.extend(e.geometry,{shapes:[]}),r.mesh=new THREE.Mesh(new THREE.ShapeGeometry(e.geometry.shapes),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"onlyvis"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Shape2D=function(e){return new WHS.Shape2D(e).addTo(this)},WHS.Sphere=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"sphere"));return api.extend(e.geometry,{radius:1,segmentA:32,segmentB:32}),r.mesh=new Physijs.SphereMesh(new THREE.SphereGeometry(e.geometry.radius,e.geometry.segmentA,e.geometry.segmentB),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Sphere=function(e){return new WHS.Sphere(e).addTo(this)},WHS.Tetrahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"tetrahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.TetrahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Tetrahedron=function(e){return new WHS.Tetrahedron(e).addTo(this)},WHS.Text=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"text"));return api.extend(e.geometry,{text:"Hello World!",parameters:{size:1,height:50,curveSegments:1,font:"Adelle",weight:"normal",style:"normal",bevelEnabled:!1,bevelThickness:10,bevelSize:8}}),r.mesh=new Physijs.ConcaveMesh(new THREE.TextGeometry(e.geometry.text,e.geometry.parameters),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Text=function(e){return new WHS.Text(e).addTo(this)},WHS.Torus=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"torus"));return api.extend(e.geometry,{radius:100,tube:40,radialSegments:8,tubularSegments:6,arc:2*Math.PI}),r.mesh=new Physijs.ConvexMesh(new THREE.TorusGeometry(e.geometry.radius,e.geometry.tube,e.geometry.radialSegments,e.geometry.tubularSegments,e.geometry.arc),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Torus=function(e){return new WHS.Torus(e).addTo(this)},WHS.Torusknot=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"Torusknot"));return api.extend(e.geometry,{radius:100,tube:40,radialSegments:64,tubularSegments:8,p:2,q:3,heightScale:1}),r.mesh=new Physijs.ConvexMesh(new THREE.TorusKnotGeometry(e.geometry.radius,e.geometry.tube,e.geometry.radialSegments,e.geometry.tubularSegments,e.geometry.p,e.geometry.q,e.geometry.heightScale),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Torusknot=function(e){return new WHS.Torusknot(e).addTo(this)},WHS.Tube=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"tube"));return api.extend(e.geometry,{path:options.geometryOptions.path?new r.CustomSinCurve(100):!1,segments:20,radius:2,radiusSegments:8,closed:!1}),r.mesh=new Physijs.ConvexMesh(new THREE.TubeGeometry(e.geometry.path,e.geometry.segments,e.geometry.radius,e.geometry.radiusSegments,e.geometry.closed),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),_createClass(t,[{key:"CustomSinCurve",get:function(){return THREE.Curve.create(function(e){this.scale=e||1},function(e){var t=3*e-1.5,r=Math.sin(2*Math.PI*e),n=0;return new THREE.Vector3(t,r,n).multiplyScalar(this.scale)})}}]),t}(WHS.Shape),WHS.init.prototype.Tube=function(e){return new WHS.Tube(e).addTo(this)},WHS.init.prototype.addGrass=function(e,t){var r={};r.root=this,r.opts=t,r.onlyvis=!0,r.opts.coords||console.warn("Please add grass objects coordinates! @addGrass"),r.grassMeshes=[];var n=new THREE.Mesh(new THREE.Geometry,new THREE.MeshFaceMaterial);return r.opts.coords.forEach(function(t){var o=new THREE.Mesh(new THREE.Geometry,new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("assets/textures/thingrass.png"),side:THREE.DoubleSide,blending:THREE.NormalBlending,transparent:!0,alphaTest:.5})),a=WHS.API.getheight({x:t.x,y:t.y},500,e,-1)[0],i=a.object.geometry.vertices,s=new THREE.Geometry;s.faces.push(new THREE.Face3(0,1,2)),s.vertices.push(i[a.face.a]),s.vertices.push(i[a.face.c]),s.vertices.push(i[a.face.b]),s.computeFaceNormals(),o.position.set(0,0,0),o.geometry.vertices.push(i[a.face.a].clone()),o.geometry.vertices.push(i[a.face.c].clone()),o.geometry.vertices.push(i[a.face.a].clone().add(s.faces[0].normal)),o.geometry.vertices.push(i[a.face.c].clone().add(s.faces[0].normal));var c=new THREE.Vector3(i[a.face.a].clone().x/2+i[a.face.c].clone().x/2,i[a.face.a].clone().y/2+i[a.face.c].clone().y/2,i[a.face.a].clone().z/2+i[a.face.c].clone().z/2);o.geometry.vertices.push(c.clone().add(c.clone().sub(i[a.face.b].clone()))),o.geometry.vertices.push(i[a.face.b].clone()),o.geometry.vertices.push(i[a.face.b].clone().add(s.faces[0].normal)),o.geometry.vertices.push(c.clone().add(c.clone().sub(i[a.face.b].clone())).add(s.faces[0].normal)),o.geometry.faces.push(new THREE.Face3(0,1,2)),o.geometry.faces.push(new THREE.Face3(1,2,3)),o.geometry.faces.push(new THREE.Face3(4,6,5)),o.geometry.faces.push(new THREE.Face3(4,6,7)),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,0),new THREE.Vector2(0,1)]),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(0,1)]),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(1,0)]),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(0,1)]),o.geometry.uvsNeedUpdate=!0,n.geometry.merge(o.geometry,o.matrix),n.material.materials.push(o.material),r.grassMeshes.push(o)}),r.wrap(n),r.update=function(){},r.update(),r},WHS.Smooth=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"smooth"));return api.extend(e.geometry,{width:10,height:10}),r.mesh=new Physijs.BoxMesh(new THREE.BoxGeometry(e.geometry.width,1,e.geometry.height),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),0),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Smooth=function(e){return new WHS.Smooth(e).addTo(this)},WHS.Terrain=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"terrain"));api.extend(e.geometry,{width:1,height:1,depth:1,map:!1});var n=document.createElement("canvas");if(n.setAttribute("width",e.geometry.width),n.setAttribute("height",e.geometry.height),n.getContext){var o=n.getContext("2d");o.drawImage(e.geometry.map,0,0)}var a=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/dirt-512.jpg");a.wrapS=a.wrapT=THREE.RepeatWrapping;var i=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/sand-512.jpg");i.wrapS=i.wrapT=THREE.RepeatWrapping;var s=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/grass-512.jpg");s.wrapS=s.wrapT=THREE.RepeatWrapping;var c=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/rock-512.jpg");c.wrapS=c.wrapT=THREE.RepeatWrapping;var l=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/snow-512.jpg");l.wrapS=l.wrapT=THREE.RepeatWrapping;var h=(THREE.NormalMapShader,256),u=256,p={minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBFormat},d=new THREE.WebGLRenderTarget(h,u,p);d.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/default_terrain.png");var m=new THREE.WebGLRenderTarget(h,u,p);m.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/NormalMap.png");var f=new THREE.WebGLRenderTarget(256,256,p);f.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/default_terrain.png");var g=THREE.ShaderTerrain.terrain,y=Object.assign(THREE.UniformsUtils.clone(g.uniforms),{oceanTexture:{type:"t",value:a},sandyTexture:{type:"t",value:i},grassTexture:{type:"t",value:s},rockyTexture:{type:"t",value:c},snowyTexture:{type:"t",value:l},fog:!0,lights:!0},THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}});y.tDisplacement.value=d,y.shadowMap.value=[m],y.uDisplacementScale.value=100,y.uRepeatOverlay.value.set(6,6);var E=new THREE.ShaderMaterial({uniforms:y,vertexShader:g.vertexShader,fragmentShader:g.fragmentShader,lights:!0,fog:!0,side:THREE.DoubleSide,shading:THREE.SmoothShading}),v=new THREE.PlaneGeometry(256,256,255,255);v.verticesNeedUpdate=!0,r._rot.set(Math.PI/180*-90,0,0);for(var _=0,b=0,H=o.getImageData(0,0,256,256).data,w=0;255>=w;w++)for(var T=255;T>=0;T--)v.vertices[_].z=H[b]/255*100,b+=4,_++;return r.mesh=new Physijs.HeightfieldMesh(v,Physijs.createMaterial(E,.8,.1)),v.computeVertexNormals(),v.computeFaceNormals(),v.computeTangents(),r.mesh.updateMatrix(),r.mesh.castShadow=!0,r.mesh.receiveShadow=!0,_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"skip"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Terrain=function(e){return new WHS.Terrain(e).addTo(this)},WHS.init.prototype.addFog=function(e,t){var r={};switch(api.extend(t,{hex:0,near:.015,far:1e3,density:25e-5}),e){case"fog":r=new THREE.Fog(t.hex,t.near,t.far);break;case"fogexp2":r=new THREE.FogExp2(t.hex,t.density)}return r},WHS.AmbientLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"ambientlight"));return r.mesh=new THREE.AmbientLight(e.light.color),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.AmbientLight=function(e){return new WHS.AmbientLight(e).addTo(this)},WHS.DirectionalLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"directionallight"));return r.mesh=new THREE.DirectionalLight(e.light.color,e.light.intensity),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.DirectionalLight=function(e){return new WHS.DirectionalLight(e).addTo(this)},WHS.HemisphereLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"hemispherelight"));return r.mesh=new THREE.HemisphereLight(e.light.skyColor,e.light.groundColor,e.light.intensity),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.HemisphereLight=function(e){return new WHS.HemisphereLight(e).addTo(this)},WHS.NormalLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"normallight"));return r.mesh=new THREE.Light(e.light.color),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.NormalLight=function(e){return new WHS.NormalLight(e).addTo(this)},WHS.PointLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"pointlight"));return r.mesh=new THREE.PointLight(e.light.color,e.light.intensity,e.light.distance),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.PointLight=function(e){return new WHS.PointLight(e).addTo(this)},WHS.SpotLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"spotlight"));return r.mesh=new THREE.SpotLight(e.light.color,e.light.intensity,e.light.distance,e.light.angle),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.SpotLight=function(e){return new WHS.SpotLight(e).addTo(this)};var PI_2=Math.PI/2;WHS.init.prototype.MakeFirstPerson=function(e,t){var r=WHS.API.extend(t,{block:document.getElementById("blocker"),speed:1,ypos:1});this.controls=new function(e,t,r){function n(e){if(c.enabled!==!1){var t=e.movementX||e.mozMovementX||e.getMovementX()||0,r=e.movementY||e.mozMovementY||e.getMovementY()||0;u.rotation.y-=.002*t,h.rotation.x-=.002*r,h.rotation.x=Math.max(-PI_2,Math.min(PI_2,h.rotation.x))}}function o(e){switch(e.keyCode){case 38:case 87:d=!0;break;case 37:case 65:f=!0;break;case 40:case 83:m=!0;break;case 39:case 68:g=!0;break;case 32:1==y&&(l.applyCentralImpulse({x:0,y:300,z:0}),console.log(l.applyCentralImpulse)),y=!1;break;case 16:s=.5}}function a(e){switch(e.keyCode){case 38:case 87:d=!1;break;case 37:case 65:f=!1;break;case 40:case 83:m=!1;break;case 39:case 68:g=!1;break;case 16:s=.25}}var i=1,s=.25;t.setAngularFactor({x:0,y:0,z:0});var c=this,l=t,h=new THREE.Object3D;h.add(e);var u=new THREE.Object3D;u.position.y=r.ypos,u.add(h);var p=new THREE.Quaternion,d=!1,m=!1,f=!1,g=!1,y=!1;l.addEventListener("collision",function(e,t,r,n){n.y<.5&&(y=!0)}),document.body.addEventListener("mousemove",n,!1),document.body.addEventListener("keydown",o,!1),document.body.addEventListener("keyup",a,!1),this.enabled=!1,this.getObject=function(){return u},this.getDirection=function(e){e.set(0,0,-1),p.multiplyVector3(e)};var E=new THREE.Vector3,v=new THREE.Euler;this.update=function(e){new THREE.Vector3;if(c.enabled!==!1){e=e||.5,e=Math.min(e,.5),E.set(0,0,0);var t=i*e*r.speed*s;d&&(E.z=-t),m&&(E.z=t),f&&(E.x=-t),g&&(E.x=t),v.x=h.rotation.x,v.y=u.rotation.y,v.order="XYZ",p.setFromEuler(v),E.applyQuaternion(p),l.applyCentralImpulse({x:10*E.x,y:0,z:10*E.z}),l.setAngularVelocity({x:10*E.z,y:0,z:10*-E.x}),l.setAngularFactor({x:0,y:0,z:0}),u.position.copy(l.position)}}}(this._camera,e.mesh,r);var n=this.controls;if(WHS.API.merge(this.scene,this.controls.getObject()),"pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document){var o=document.body;this.pointerlockchange=function(){document.pointerLockElement===o||document.mozPointerLockElement===o||document.webkitPointerLockElement===o?(n.enabled=!0,r.block.fadeOut()):(n.enabled=!1,r.block.fadeIn())}}else console.warn("Your browser does not support the PointerLock API.");document.addEventListener("pointerlockchange",this.pointerlockchange,!1),document.addEventListener("mozpointerlockchange",this.pointerlockchange,!1),document.addEventListener("webkitpointerlockchange",this.pointerlockchange,!1),this.pointerlockerror=function(){console.warn("Pointer lock error.")},document.addEventListener("pointerlockerror",this.pointerlockerror,!1),document.addEventListener("mozpointerlockerror",this.pointerlockerror,!1),document.addEventListener("webkitpointerlockerror",this.pointerlockerror,!1),r.block.addEventListener("click",function(){if(o.requestPointerLock=o.requestPointerLock||o.mozRequestPointerLock||o.webkitRequestPointerLock,o.requestFullscreen=o.requestFullscreen||o.mozRequestFullscreen||o.mozRequestFullScreen||o.webkitRequestFullscreen,/Firefox/i.test(navigator.userAgent)){var e=function t(){(document.fullscreenElement===o||document.mozFullscreenElement===o||document.mozFullScreenElement===o)&&(document.removeEventListener("fullscreenchange",t),document.removeEventListener("mozfullscreenchange",t),
+o.requestPointerLock())};document.addEventListener("fullscreenchange",e,!1),document.addEventListener("mozfullscreenchange",e,!1),o.requestFullscreen()}else o.requestPointerLock()})},WHS.init.prototype.OrbitControls=function(e){if(this.controls=new THREE.OrbitControls(this._camera,this._renderer.domElement),e)if(e._whsobject){var t=e?e.mesh.position:new THREE.Vector3(0,0,0);this.controls.target=t}else"object"==("undefined"==typeof e?"undefined":_typeof(e))?this.controls.target.copy(t):console.error("Object must be a THREE.JS vector! @OrbitControls")},WHS.Skybox=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"skybox"));api.extend(e,{skyType:"box",detail:".png",radius:10,path:""});var n,o;switch(e.skyType){case"box":var a=["xpos","xneg","ypos","yneg","zpos","zneg"];n=new THREE.CubeGeometry(e.radius,e.radius,e.radius);for(var i=[],s=0;6>s;s++)i.push(new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture(e.path+a[s]+e.imgSuffix),side:THREE.BackSide}));o=new THREE.MeshFaceMaterial(i);break;case"sphere":n=new THREE.SphereGeometry(e.radius/2,60,40),o=new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture(e.path+e.imgSuffix),side:THREE.BackSide})}return r.mesh=new THREE.Mesh(n,o),r.mesh.renderDepth=1e3,_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Skybox=function(e){return new WHS.Skybox(e).addTo(this)};
\ No newline at end of file
diff --git a/build/whitestorm.test.js b/build/whitestorm.test.js
index d84a0f6..f4be2c6 100644
--- a/build/whitestorm.test.js
+++ b/build/whitestorm.test.js
@@ -4,6 +4,6 @@
  * Email: alexbuzin88@gmail.com
 */
 
-function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Events(e){var t={},r=[];e=e||this,e.on=function(e,r,o){(t[e]=t[e]||[]).push([r,o])},e.off=function(e,o){e||(t={});for(var n=t[e]||r,a=n.length=o?n.length:0;a--;)o==n[a][0]&&n.splice(a,1)},e.emit=function(e){for(var o,n=t[e]||r,a=0;o=n[a++];)o[0].apply(o[1],r.slice.call(arguments,1))}}var THREE=require("three"),jQuery=require("jquery"),_get=function e(t,r,o){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,r);if(void 0===n){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,o)}if("value"in n)return n.value;var i=n.get;if(void 0!==i)return i.call(o)},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};THREE.AnaglyphEffect=function(e,t,r){var o,n,a,i,s=new THREE.Matrix4,c=new THREE.Matrix4,l=125,h=new THREE.PerspectiveCamera;h.matrixAutoUpdate=!1;var u=new THREE.PerspectiveCamera;u.matrixAutoUpdate=!1;var p=new THREE.OrthographicCamera(-1,1,1,-1,0,1),d=new THREE.Scene,m={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat};void 0===t&&(t=512),void 0===r&&(r=512);var f=new THREE.WebGLRenderTarget(t,r,m),g=new THREE.WebGLRenderTarget(t,r,m),y=new THREE.ShaderMaterial({uniforms:{mapLeft:{type:"t",value:f},mapRight:{type:"t",value:g}},vertexShader:["varying vec2 vUv;","void main() {","	vUv = vec2( uv.x, uv.y );","	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform sampler2D mapLeft;","uniform sampler2D mapRight;","varying vec2 vUv;","void main() {","	vec4 colorL, colorR;","	vec2 uv = vUv;","	colorL = texture2D( mapLeft, uv );","	colorR = texture2D( mapRight, uv );","	gl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;","}"].join("\n")}),E=new THREE.Mesh(new THREE.PlaneBufferGeometry(2,2),y);d.add(E),this.setSize=function(t,r){f&&f.dispose(),g&&g.dispose(),f=new THREE.WebGLRenderTarget(t,r,m),g=new THREE.WebGLRenderTarget(t,r,m),y.uniforms.mapLeft.value=f,y.uniforms.mapRight.value=g,e.setSize(t,r)},this.render=function(t,r){t.updateMatrixWorld(),void 0===r.parent&&r.updateMatrixWorld();var m=o!==r.aspect||n!==r.near||a!==r.far||i!==r.fov;if(m){o=r.aspect,n=r.near,a=r.far,i=r.fov;var y,E,v=r.projectionMatrix.clone(),_=l/30*.5,b=_*n/l,H=n*Math.tan(THREE.Math.degToRad(.5*i));s.elements[12]=_,c.elements[12]=-_,y=-H*o+b,E=H*o+b,v.elements[0]=2*n/(E-y),v.elements[8]=(E+y)/(E-y),h.projectionMatrix.copy(v),y=-H*o-b,E=H*o-b,v.elements[0]=2*n/(E-y),v.elements[8]=(E+y)/(E-y),u.projectionMatrix.copy(v)}h.matrixWorld.copy(r.matrixWorld).multiply(c),h.position.copy(r.position),h.near=r.near,h.far=r.far,e.render(t,h,f,!0),u.matrixWorld.copy(r.matrixWorld).multiply(s),u.position.copy(r.position),u.near=r.near,u.far=r.far,e.render(t,u,g,!0),e.render(d,p)},this.dispose=function(){f&&f.dispose(),g&&g.dispose()}},THREE.BufferGeometryUtils={computeTangents:function(e){function t(e,t,r){m.fromArray(i,3*e),f.fromArray(i,3*t),g.fromArray(i,3*r),y.fromArray(c,2*e),E.fromArray(c,2*t),v.fromArray(c,2*r);var o=f.x-m.x,n=g.x-m.x,a=f.y-m.y,s=g.y-m.y,l=f.z-m.z,h=g.z-m.z,d=E.x-y.x,H=v.x-y.x,w=E.y-y.y,T=v.y-y.y,S=1/(d*T-H*w);_.set((T*o-w*n)*S,(T*a-w*s)*S,(T*l-w*h)*S),b.set((d*n-H*o)*S,(d*s-H*a)*S,(d*h-H*l)*S),u[e].add(_),u[t].add(_),u[r].add(_),p[e].add(b),p[t].add(b),p[r].add(b)}function r(e){L.fromArray(s,3*e),A.copy(L),C=u[e],M.copy(C),M.sub(L.multiplyScalar(L.dot(C))).normalize(),j.crossVectors(A,C),W=j.dot(p[e]),O=0>W?-1:1,h[4*e]=M.x,h[4*e+1]=M.y,h[4*e+2]=M.z,h[4*e+3]=O}var o=e.index,n=e.attributes;if(null===o||void 0===n.position||void 0===n.normal||void 0===n.uv)return void console.warn("THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()");var a=o.array,i=n.position.array,s=n.normal.array,c=n.uv.array,l=i.length/3;void 0===n.tangent&&e.addAttribute("tangent",new THREE.BufferAttribute(new Float32Array(4*l),4));for(var h=n.tangent.array,u=[],p=[],d=0;l>d;d++)u[d]=new THREE.Vector3,p[d]=new THREE.Vector3;var m=new THREE.Vector3,f=new THREE.Vector3,g=new THREE.Vector3,y=new THREE.Vector2,E=new THREE.Vector2,v=new THREE.Vector2,_=new THREE.Vector3,b=new THREE.Vector3,H=e.groups;0===H.length&&(H=[{start:0,count:a.length}]);for(var w=0,T=H.length;T>w;++w)for(var S=H[w],R=S.start,x=S.count,P=R,k=R+x;k>P;P+=3)t(a[P+0],a[P+1],a[P+2]);for(var O,C,W,M=new THREE.Vector3,j=new THREE.Vector3,L=new THREE.Vector3,A=new THREE.Vector3,w=0,T=H.length;T>w;++w)for(var S=H[w],R=S.start,x=S.count,P=R,k=R+x;k>P;P+=3)r(a[P+0]),r(a[P+1]),r(a[P+2])}},THREE.OrbitControls=function(e,t){function r(){return 2*Math.PI/60/60*p.autoRotateSpeed}function o(){return Math.pow(.95,p.zoomSpeed)}function n(e){if(p.enabled!==!1){if(e.preventDefault(),0===e.button){if(p.noRotate===!0)return;k=P.ROTATE,m.set(e.clientX,e.clientY)}else if(1===e.button){if(p.noZoom===!0)return;k=P.DOLLY,_.set(e.clientX,e.clientY)}else if(2===e.button){if(p.noPan===!0)return;k=P.PAN,y.set(e.clientX,e.clientY)}p.domElement.addEventListener("mousemove",a,!1),p.domElement.addEventListener("mouseup",i,!1)}}function a(e){if(p.enabled!==!1){e.preventDefault();var t=p.domElement===document?p.domElement.body:p.domElement;if(k===P.ROTATE){if(p.noRotate===!0)return;f.set(e.clientX,e.clientY),g.subVectors(f,m),p.rotateLeft(2*Math.PI*g.x/t.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*g.y/t.clientHeight*p.rotateSpeed),m.copy(f)}else if(k===P.DOLLY){if(p.noZoom===!0)return;b.set(e.clientX,e.clientY),H.subVectors(b,_),H.y>0?p.dollyIn():p.dollyOut(),_.copy(b)}else if(k===P.PAN){if(p.noPan===!0)return;E.set(e.clientX,e.clientY),v.subVectors(E,y),p.pan(v),y.copy(E)}p.update()}}function i(){p.enabled!==!1&&(p.domElement.removeEventListener("mousemove",a,!1),p.domElement.removeEventListener("mouseup",i,!1),k=P.NONE)}function s(e){if(p.enabled!==!1&&p.noZoom!==!0){var t=0;e.wheelDelta?t=e.wheelDelta:e.detail&&(t=-e.detail),t>0?p.dollyOut():p.dollyIn()}}function c(e){if(p.enabled!==!1&&p.noKeys!==!0&&p.noPan!==!0){var t=!1;switch(e.keyCode){case p.keys.UP:p.pan(new THREE.Vector2(0,p.keyPanSpeed)),t=!0;break;case p.keys.BOTTOM:p.pan(new THREE.Vector2(0,-p.keyPanSpeed)),t=!0;break;case p.keys.LEFT:p.pan(new THREE.Vector2(p.keyPanSpeed,0)),t=!0;break;case p.keys.RIGHT:p.pan(new THREE.Vector2(-p.keyPanSpeed,0)),t=!0}t&&p.update()}}function l(e){if(p.enabled!==!1)switch(e.touches.length){case 1:if(p.noRotate===!0)return;k=P.TOUCH_ROTATE,m.set(e.touches[0].pageX,e.touches[0].pageY);break;case 2:if(p.noZoom===!0)return;k=P.TOUCH_DOLLY;var t=e.touches[0].pageX-e.touches[1].pageX,r=e.touches[0].pageY-e.touches[1].pageY,o=Math.sqrt(t*t+r*r);_.set(0,o);break;case 3:if(p.noPan===!0)return;k=P.TOUCH_PAN,y.set(e.touches[0].pageX,e.touches[0].pageY);break;default:k=P.NONE}}function h(e){if(p.enabled!==!1){e.preventDefault(),e.stopPropagation();var t=p.domElement===document?p.domElement.body:p.domElement;switch(e.touches.length){case 1:if(p.noRotate===!0)return;if(k!==P.TOUCH_ROTATE)return;f.set(e.touches[0].pageX,e.touches[0].pageY),g.subVectors(f,m),p.rotateLeft(2*Math.PI*g.x/t.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*g.y/t.clientHeight*p.rotateSpeed),m.copy(f);break;case 2:if(p.noZoom===!0)return;if(k!==P.TOUCH_DOLLY)return;var r=e.touches[0].pageX-e.touches[1].pageX,o=e.touches[0].pageY-e.touches[1].pageY,n=Math.sqrt(r*r+o*o);b.set(0,n),H.subVectors(b,_),H.y>0?p.dollyOut():p.dollyIn(),_.copy(b);break;case 3:if(p.noPan===!0)return;if(k!==P.TOUCH_PAN)return;E.set(e.touches[0].pageX,e.touches[0].pageY),v.subVectors(E,y),p.pan(v),y.copy(E);break;default:k=P.NONE}}}function u(){p.enabled!==!1&&(k=P.NONE)}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.target=new THREE.Vector3,this.center=this.target,this.noZoom=!1,this.zoomSpeed=1,this.minDistance=0,this.maxDistance=1/0,this.noRotate=!1,this.rotateSpeed=1,this.noPan=!1,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.noKeys=!1,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40};var p=this,d=1e-6,m=new THREE.Vector2,f=new THREE.Vector2,g=new THREE.Vector2,y=new THREE.Vector2,E=new THREE.Vector2,v=new THREE.Vector2,_=new THREE.Vector2,b=new THREE.Vector2,H=new THREE.Vector2,w=0,T=0,S=1,R=new THREE.Vector3,x=new THREE.Vector3,P={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},k=P.NONE,O={type:"change"};this.rotateLeft=function(e){void 0===e&&(e=r()),T-=e},this.rotateUp=function(e){void 0===e&&(e=r()),w-=e},this.panLeft=function(e){var t=new THREE.Vector3,r=this.object.matrix.elements;t.set(r[0],r[1],r[2]),t.multiplyScalar(-e),R.add(t)},this.panUp=function(e){var t=new THREE.Vector3,r=this.object.matrix.elements;t.set(r[4],r[5],r[6]),t.multiplyScalar(e),R.add(t)},this.pan=function(e){var t=p.domElement===document?p.domElement.body:p.domElement;if(void 0!==p.object.fov){var r=p.object.position,o=r.clone().sub(p.target),n=o.length();n*=Math.tan(p.object.fov/2*Math.PI/180),p.panLeft(2*e.x*n/t.clientHeight),p.panUp(2*e.y*n/t.clientHeight)}else void 0!==p.object.top?(p.panLeft(e.x*(p.object.right-p.object.left)/t.clientWidth),p.panUp(e.y*(p.object.top-p.object.bottom)/t.clientHeight)):console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.")},this.dollyIn=function(e){void 0===e&&(e=o()),S/=e},this.dollyOut=function(e){void 0===e&&(e=o()),S*=e},this.update=function(){var e=this.object.position,t=e.clone().sub(this.target),o=Math.atan2(t.x,t.z),n=Math.atan2(Math.sqrt(t.x*t.x+t.z*t.z),t.y);this.autoRotate&&this.rotateLeft(r()),o+=T,n+=w,n=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,n)),n=Math.max(d,Math.min(Math.PI-d,n));var a=t.length()*S;a=Math.max(this.minDistance,Math.min(this.maxDistance,a)),this.target.add(R),t.x=a*Math.sin(n)*Math.sin(o),t.y=a*Math.cos(n),t.z=a*Math.sin(n)*Math.cos(o),e.copy(this.target).add(t),this.object.lookAt(this.target),T=0,w=0,S=1,R.set(0,0,0),x.distanceTo(this.object.position)>0&&(this.dispatchEvent(O),x.copy(this.object.position))},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",n,!1),this.domElement.addEventListener("mousewheel",s,!1),this.domElement.addEventListener("DOMMouseScroll",s,!1),this.domElement.addEventListener("keydown",c,!1),this.domElement.addEventListener("touchstart",l,!1),this.domElement.addEventListener("touchend",u,!1),this.domElement.addEventListener("touchmove",h,!1)},THREE.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype);var Stats=function(){function e(e,t,r){return e=document.createElement(e),e.id=t,e.style.cssText=r,e}function t(t,r,o){var n=e("div",t,"padding:0 0 3px 3px;text-align:left;background:"+o),a=e("div",t+"Text","font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px;color:"+r);for(a.innerHTML=t.toUpperCase(),n.appendChild(a),t=e("div",t+"Graph","width:74px;height:30px;background:"+r),n.appendChild(t),r=0;74>r;r++)t.appendChild(e("span","","width:1px;height:30px;float:left;opacity:0.9;background:"+o));return n}function r(e){for(var t=l.children,r=0;r<t.length;r++)t[r].style.display=r===e?"block":"none";c=e}function o(e,t){e.appendChild(e.firstChild).style.height=Math.min(30,30-30*t)+"px"}var n=self.performance&&self.performance.now?self.performance.now.bind(performance):Date.now,a=n(),i=a,s=0,c=0,l=e("div","stats","width:80px;opacity:0.9;cursor:pointer");l.addEventListener("mousedown",function(e){e.preventDefault(),r(++c%l.children.length)},!1);var h=0,u=1/0,p=0,d=t("fps","#0ff","#002"),m=d.children[0],f=d.children[1];l.appendChild(d);var g=0,y=1/0,E=0,d=t("ms","#0f0","#020"),v=d.children[0],_=d.children[1];if(l.appendChild(d),self.performance&&self.performance.memory){var b=0,H=1/0,w=0,d=t("mb","#f08","#201"),T=d.children[0],S=d.children[1];l.appendChild(d)}return r(c),{REVISION:14,domElement:l,setMode:r,begin:function(){a=n()},end:function(){var e=n();if(g=e-a,y=Math.min(y,g),E=Math.max(E,g),v.textContent=(0|g)+" MS ("+(0|y)+"-"+(0|E)+")",o(_,g/200),s++,e>i+1e3&&(h=Math.round(1e3*s/(e-i)),u=Math.min(u,h),p=Math.max(p,h),m.textContent=h+" FPS ("+u+"-"+p+")",o(f,h/100),i=e,s=0,void 0!==b)){var t=performance.memory.usedJSHeapSize,r=performance.memory.jsHeapSizeLimit;b=Math.round(9.54e-7*t),H=Math.min(H,b),w=Math.max(w,b),T.textContent=b+" MB ("+H+"-"+w+")",o(S,t/r)}return e},update:function(){a=this.end()}}};"object"===("undefined"==typeof module?"undefined":_typeof(module))&&(module.exports=Stats),THREE.SubdivisionModifier=function(e){"use strict";this.subdivisions=void 0===e?1:e},THREE.SubdivisionModifier.prototype.modify=function(e){for(var t=this.subdivisions;t-- >0;)this.smooth(e);delete e.__tmpVertices,e.computeFaceNormals(),e.computeVertexNormals()},function(){function e(e,t,r){var o=Math.min(e,t),n=Math.max(e,t),a=o+"_"+n;return r[a]}function t(e,t,r,o,n,a){var i,s=Math.min(e,t),c=Math.max(e,t),l=s+"_"+c;if(l in o)i=o[l];else{var h=r[s],u=r[c];i={a:h,b:u,newEdge:null,faces:[]},o[l]=i}i.faces.push(n),a[e].edges.push(i),a[t].edges.push(i)}function r(e,r,o,n){var a,i,s;for(a=0,i=e.length;i>a;a++)o[a]={edges:[]};for(a=0,i=r.length;i>a;a++)s=r[a],t(s.a,s.b,e,n,s,o),t(s.b,s.c,e,n,s,o),t(s.c,s.a,e,n,s,o)}function o(e,t,r,o){e.push(new THREE.Face3(t,r,o))}var n=!1,a=["a","b","c"];THREE.SubdivisionModifier.prototype.smooth=function(t){var i,s,c,l,h,u,p,d,m,f,g,g,y,E,v=new THREE.Vector3;i=t.vertices,s=t.faces,f=new Array(i.length),g={},r(i,s,f,g),y=[];var _,b,H,w,T,S,R;for(u in g){for(b=g[u],H=new THREE.Vector3,T=3/8,S=1/8,R=b.faces.length,2!=R&&(T=.5,S=0,1!=R&&n&&console.warn("Subdivision Modifier: Number of connected faces != 2, is: ",R,b)),H.addVectors(b.a,b.b).multiplyScalar(T),v.set(0,0,0),d=0;R>d;d++){for(w=b.faces[d],m=0;3>m&&(_=i[w[a[m]]],_===b.a||_===b.b);m++);v.add(_)}v.multiplyScalar(S),H.add(v),b.newEdge=y.length,y.push(H)}var x,P,k,O,C,W,M;for(E=[],u=0,p=i.length;p>u;u++){for(W=i[u],C=f[u].edges,h=C.length,3==h?x=3/16:h>3&&(x=3/(8*h)),P=1-h*x,k=x,2>=h&&(2==h?(n&&console.warn("2 connecting edges",C),P=.75,k=1/8):1==h?n&&console.warn("only 1 connecting edge"):0==h&&n&&console.warn("0 connecting edges")),M=W.clone().multiplyScalar(P),v.set(0,0,0),d=0;h>d;d++)O=C[d],_=O.a!==W?O.a:O.b,v.add(_);v.multiplyScalar(k),M.add(v),E.push(M)}c=E.concat(y);var j,L,A,D=E.length;for(l=[],u=0,p=s.length;p>u;u++)w=s[u],j=e(w.a,w.b,g).newEdge+D,L=e(w.b,w.c,g).newEdge+D,A=e(w.c,w.a,g).newEdge+D,o(l,j,L,A),o(l,w.a,j,A),o(l,w.b,L,j),o(l,w.c,A,L);t.vertices=c,t.faces=l}}();var WHS={REVISION:"7",API:{},_settings:{assets:"./assets",path_worker:"../libs/physijs_worker.js",path_ammo:"../libs/ammo.js"},loops:[],grounds:[]},api=WHS.API;"function"==typeof define&&define.amd?define("whitestorm",WHS):"undefined"!=typeof exports&&"undefined"!=typeof module&&(module.exports=WHS),THREE.ShaderTerrain={terrain:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{enableDiffuse1:{type:"i",value:0},enableDiffuse2:{type:"i",value:0},enableSpecular:{type:"i",value:0},enableReflection:{type:"i",value:0},tDiffuse1:{type:"t",value:null},tDiffuse2:{type:"t",value:null},tDetail:{type:"t",value:null},tNormal:{type:"t",value:null},tSpecular:{type:"t",value:null},tDisplacement:{type:"t",value:null},uNormalScale:{type:"f",value:1},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},diffuse:{type:"c",value:new THREE.Color(15658734)},specular:{type:"c",value:new THREE.Color(1118481)},shininess:{type:"f",value:30},opacity:{type:"f",value:1},uRepeatBase:{type:"v2",value:new THREE.Vector2(1,1)},uRepeatOverlay:{type:"v2",value:new THREE.Vector2(1,1)},uOffset:{type:"v2",value:new THREE.Vector2(0,0)}}]),fragmentShader:["\n		        uniform vec3 diffuse;\n		        uniform vec3 emissive;\n		        uniform float opacity;\n		        uniform vec3 ambientLightColor;\n		        varying vec3 vLightFront;\n		        #ifdef DOUBLE_SIDED\n			        varying vec3 vLightBack;\n			        uniform vec2 uRepeatOverlay;\n			        uniform vec2 uRepeatBase;\n			        uniform vec2 uOffset;\n			        uniform float uNormalScale;\n			        uniform sampler2D tNormal;\n		        #endif\n		        uniform sampler2D oceanTexture;\n		        uniform sampler2D sandyTexture;\n		        uniform sampler2D grassTexture;\n		        uniform sampler2D rockyTexture;\n		        uniform sampler2D snowyTexture;\n		        varying vec3 vTangent;\n		        varying vec3 vBinormal;\n		        varying vec3 vNormal;\n		        varying vec3 vViewPosition;\n		"+[THREE.ShaderChunk.common,THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.alphamap_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.specularmap_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment].join("\n")+"\n		        varying vec2 vUv;\n		        varying float vAmount;\n		        void main() {\n		        	// UVs.\n		            vec2 uvOverlay = uRepeatOverlay * vUv + uOffset;\n		            vec2 uvBase = uRepeatBase * vUv;\n					vec3 specularTex = vec3( 1.0 );\n		            vec3 normalTex = texture2D( tNormal, uvOverlay ).xyz * 2.0 - 1.0;\n		            normalTex.xy *= uNormalScale;\n		            normalTex = normalize( normalTex );\n		            mat3 tsb = mat3( vTangent, vBinormal, vNormal );\n		            vec3 finalNormal = tsb * normalTex;\n		            vec3 normal = normalize( finalNormal );\n		            vec3 viewPosition = normalize( vViewPosition );\n		            vec3 shadowMask = vec3( 1.0 );\n		            vec3 outgoingLight = vec3( 0.0 );\n		            vec3 totalAmbientLight = ambientLightColor;\n		            vec4 diffuseColor = vec4(0.0);\n		            // Color by texture.\n		            vec4 water = (smoothstep(0.01, 0.25, vAmount)\n		            - smoothstep(0.24, 0.26, vAmount))\n		            * texture2D( oceanTexture, vUv * 10.0 );\n		            vec4 sandy = (smoothstep(0.24, 0.27, vAmount)\n		            - smoothstep(0.28, 0.31, vAmount))\n		            * texture2D( sandyTexture, vUv * 10.0 );\n		            vec4 grass = (smoothstep(0.28, 0.32, vAmount)\n		            - smoothstep(0.35, 0.40, vAmount))\n		            * texture2D( grassTexture, vUv * 20.0 );\n		            vec4 rocky = (smoothstep(0.30, 0.40, vAmount)\n		            - smoothstep(0.40, 0.70, vAmount))\n		            * texture2D( rockyTexture, vUv * 20.0 );\n		            vec4 snowy = (smoothstep(0.42, 0.45, vAmount))\n		            * texture2D( snowyTexture, vUv * 10.0 );\n		            diffuseColor = vec4(0.0, 0.0, 0.0, 1.0)\n		            + water + sandy + grass + rocky + snowy;\n		"+[THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphamap_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.specularmap_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment].join("\n")+"\n		            #ifdef DOUBLE_SIDED\n		                if ( gl_FrontFacing )\n		                    outgoingLight += diffuseColor.rgb * \n		                		( vLightFront * shadowMask + totalAmbientLight )\n		                		+ emissive;\n		                else\n		                    outgoingLight += diffuseColor.rgb * \n		                		( vLightBack * shadowMask + totalAmbientLight )\n		                		+ emissive;\n		            #else\n		                outgoingLight += diffuseColor.rgb * \n		                	( vLightFront * shadowMask + totalAmbientLight )\n		                	+ emissive;\n		            #endif\n		           gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n		      }\n		"],vertexShader:["\n		    #define TERRAIN;\n		    varying vec3 vLightFront;\n		    #ifdef DOUBLE_SIDED\n		        varying vec3 vLightBack;\n		    #endif\n		    \n		    varying float vAmount;\n		    attribute vec4 tangent;\n		    uniform vec2 uRepeatBase;\n		    uniform sampler2D tNormal;\n		    #ifdef VERTEX_TEXTURES\n			    uniform sampler2D tDisplacement;\n			    uniform float uDisplacementScale;\n			    uniform float uDisplacementBias;\n		    #endif\n		    varying vec3 vTangent;\n		    varying vec3 vBinormal;\n		    varying vec3 vNormal;\n		    varying vec2 vUv;\n		    varying vec3 vViewPosition;\n		"+[THREE.ShaderChunk.common,THREE.ShaderChunk.uv_pars_vertex,THREE.ShaderChunk.uv2_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_lambert_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex].join("\n")+"\n		    void main() {\n		"+[THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.beginnormal_vertex,THREE.ShaderChunk.morphnormal_vertex,THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.skinnormal_vertex,THREE.ShaderChunk.defaultnormal_vertex,THREE.ShaderChunk.begin_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.project_vertex,THREE.ShaderChunk.logdepthbuf_vertex,THREE.ShaderChunk.uv_vertex,THREE.ShaderChunk.uv2_vertex].join("\n")+"\n			    vNormal = normalize( normalMatrix * normal);\n			    // Tangent and binormal vectors.\n			    vTangent = normalize( normalMatrix * tangent.xyz );\n			    vBinormal = cross( vNormal, vTangent ) * tangent.w;\n			    vBinormal = normalize( vBinormal );\n			    // Texture coordinates.\n			    vUv = uv;\n			    vec2 uvBase = uv * uRepeatBase;\n			    // displacement mapping\n			    vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n			    mvPosition = modelViewMatrix * vec4( position, 1.0 );\n			    transformedNormal = normalize( normalMatrix * normal );\n			    gl_Position = projectionMatrix * mvPosition;\n			    vViewPosition = -mvPosition.xyz;\n			    vAmount = position.z * 0.005 + 0.1;\n		"+[THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.lights_lambert_vertex,THREE.ShaderChunk.shadowmap_vertex].join("\n")+"\n		   }\n		"],side:THREE.DoubleSide,shading:THREE.SmoothShading}},WHS.API.extend=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),o=1;t>o;o++)r[o-1]=arguments[o];var n=!0,a=!1,i=void 0;try{for(var s,c=r[Symbol.iterator]();!(n=(s=c.next()).done);n=!0){var l=s.value;if(l){var h=!0,u=!1,p=void 0;try{for(var d,m=Object.getOwnPropertyNames(l)[Symbol.iterator]();!(h=(d=m.next()).done);h=!0){var f=d.value;void 0!=e[f]&&"[object Object]"==e[f].toString()&&"[object Object]"==l[f].toString()?WHS.API.extend(e[f],l[f]):e[f]=0===e[f]?0:e[f]||l[f]}}catch(g){u=!0,p=g}finally{try{!h&&m["return"]&&m["return"]()}finally{if(u)throw p}}}}}catch(g){a=!0,i=g}finally{try{!n&&c["return"]&&c["return"]()}finally{if(a)throw i}}return e},WHS.API.getheight=function(e,t,r,o){"use strict";return t=t||1e3,o=o||1,this.raycaster=new THREE.Raycaster(new THREE.Vector3(e.x,t,o*e.y),new THREE.Vector3(0,-1,0)),this.intersect=this.raycaster.intersectObject(r.mesh),this.intersect},WHS.Light=function(){function e(t,r){_classCallCheck(this,e);var o=function(e,t,r){this.x=e,this.y=t,this.z=r};t.pos&&(t.pos.set=o),t.rot&&(t.rot.set=o),t.target&&(t.target.set=o);var n=api.extend(t,{light:{color:16777215,skyColor:16777215,groundColor:16777215,intensity:1,distance:100,angle:Math.PI/3},shadowmap:{cast:!0,bias:1e-4,width:1024,height:1024,near:!0,far:400,fov:60,darkness:.3,top:200,bottom:-200,left:-200,right:200},pos:{x:0,y:0,z:0,set:o},rot:{x:0,y:0,z:0,set:o},target:{x:0,y:0,z:0,set:o}}),a=0,i={_key:a,_type:r,_whsobject:!0,_name:r+a,__releaseTime:(new Date).getTime(),_pos:n.pos,_rot:n.rot,_target:n.target,_light:n.light,_shadowmap:n.shadowmap,ready:new Events};return Object.assign(this,i),this}return _createClass(e,[{key:"build",value:function(){"use strict";for(var e=this,t=arguments.length,r=Array(t),o=0;t>o;o++)r[o]=arguments[o];var n=this.mesh,a=this;return this.build_state=new Promise(function(t,o){try{n.castShadow=!0,n.receiveShadow=!0,n.position.set(e._pos.x,e._pos.y,e._pos.z),n.rotation.set(e._rot.x,e._rot.y,e._rot.z),r.forEach(function(e){a[e]=!0}),t()}catch(i){console.error(i.message),o()}}),this}},{key:"addTo",value:function(e){"use strict";this.root=e;var t=this.mesh,r=this;return console.log(this),this._key=this.root.modellingQueue.length,r._state=new Promise(function(e,o){try{api.merge(r.root.scene,t),r.root.modellingQueue.push(r)}catch(n){console.error(n.message),o()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),r.ready.emit("ready"))}}),r.root.children.push(r),this}},{key:"buildShadow",value:function(){this.mesh.shadowMapWidth=this._shadowmap.width,this.mesh.shadowMapHeight=this._shadowmap.height,this.mesh.shadowBias=this._shadowmap.bias,this.mesh.shadowCameraNear=this._shadowmap.near,this.mesh.shadowCameraFar=this._shadowmap.far,this.mesh.shadowCameraFov=this._shadowmap.fov,this.mesh.shadowDarkness=this._shadowmap.darkness,this.mesh.shadowCameraLeft=this._shadowmap.left,this.mesh.shadowCameraRight=this._shadowmap.right,this.mesh.shadowCameraTop=this._shadowmap.top,this.mesh.shadowCameraBottom=this._shadowmap.bottom}},{key:"remove",value:function(){return this.root.scene.remove(this.mesh),this}},{key:"retrieve",value:function(){return this.root.scene.add(this.mesh),this}}]),e}(),WHS.API.JSONLoader=function(){return new THREE.JSONLoader},WHS.API.TextureLoader=function(){return new THREE.TextureLoader},WHS.API.loadMaterial=function(e){"use strict";"string"!=typeof e.kind&&console.error("Type of material is undefined or not a string. @loadMaterial");var t={_type:e.kind,_restitution:e.restitution||e.rest||.3,_friction:e.friction||e.fri||.8},r=api.extend({},e);switch(delete r.kind,delete r.friction,delete r.fri,delete r.restitution,delete r.rest,e.kind){case"basic":t._material=new THREE.MeshBasicMaterial(r);break;case"linebasic":t._params=new THREE.LineBasicMaterial(r);break;case"linedashed":t._material=new THREE.LineDashedMaterial(r);break;case"material":t._material=new THREE.Material(r);break;case"depth":t._material=new THREE.MeshDepthMaterial(r);break;case"face":t._material=new THREE.MeshFaceMaterial(r);break;case"lambert":t._material=new THREE.MeshLambertMaterial(r);break;case"normal":t._material=new THREE.MeshNormalMaterial(r);break;case"phong":t._material=new THREE.MeshPhongMaterial(r);break;case"pointcloud":t._material=new THREE.PointCloudMaterial(r);break;case"rawshader":t._material=new THREE.RawShaderMaterial(r);break;case"shader":t._material=new THREE.ShaderMaterial(r);break;case"spritecanvas":t._material=new THREE.SpriteCanvasMaterial(r);break;case"sprite":t._material=new THREE.SpriteMaterial(r)}return t._material=Physijs.createMaterial(t._material,t._friction,t._restitution),console.log(t._friction),t},WHS.API.merge=function(e,t){"use strict";if(("object"!==("undefined"==typeof e?"undefined":_typeof(e))||"object"!==("undefined"==typeof t?"undefined":_typeof(t)))&&console.error("No rabbits for the box. (arguments)",["undefined"==typeof e?"undefined":_typeof(e),"undefined"==typeof t?"undefined":_typeof(t)]),e)if(Array.isArray(t)&&1===t.length)e.add(t[0]);else if(Array.isArray(t)&&t.length>1&&e)for(var r=0;r<t.length;r++)e.add(t[r]);else Array.isArray(t)||e.add(t);else console.error("box is undefined. Line "+(new Error).lineNumber+". Func merge.",[e,t])},WHS.API.PackUvs=function(e){e.computeBoundingBox();var t=e.boundingBox.max,r=e.boundingBox.min,o=new THREE.Vector2(0-r.x,0-r.y),n=new THREE.Vector2(t.x-r.x,t.y-r.y);e.faceVertexUvs[0]=[];for(var a=e.faces,i=0;i<e.faces.length;i++){var s=e.vertices[a[i].a],c=e.vertices[a[i].b],l=e.vertices[a[i].c];e.faceVertexUvs[0].push([new THREE.Vector2((s.x+o.x)/n.x,(s.y+o.y)/n.y),new THREE.Vector2((c.x+o.x)/n.x,(c.y+o.y)/n.y),new THREE.Vector2((l.x+o.x)/n.x,(l.y+o.y)/n.y)])}e.uvsNeedUpdate=!0},WHS.API.removeDuplicateFaces=function(e){function t(){return!(a1.sort()>a2.sort()||a1.sort()<a2.sort())}for(var r=0;r<e.faces.length;r++)for(var o=e.faces[r],n=[o.a,o.b,o.c,o.d].sort(),a=0;r>a;a++){var i=e.faces[a];if(void 0!==i){var s=[i.a,i.b,i.c,i.d].sort();t(n,s)&&(delete e.faces[r],delete e.faces[a])}}return e.faces=e.faces.filter(function(e){return void 0===e}),e},WHS.API.rotateGeometry=function(e,t){"use strict";var r=new THREE.Matrix4;r.makeRotationFromEuler(new THREE.Euler(t.x,t.y,t.z,"XYZ"));for(var o in e.vertices)e.vertices[o].applyMatrix4(r);return e},WHS.Shape=function(){function e(t,r){_classCallCheck(this,e);var o=function(e,t,r){this.x=e,this.y=t,this.z=r};api.extend(t,{mass:10,pos:{x:0,y:0,z:0,set:o},rot:{x:0,y:0,z:0,set:o},scale:{x:1,y:1,z:1,set:o},target:{x:0,y:0,z:0,set:o},morph:{speed:1,duration:1},onlyvis:!1});var n=0,a={_key:n,_type:r,_whsobject:!0,_name:r+n,__releaseTime:(new Date).getTime(),_pos:t.pos,_rot:t.rot,_scale:t.scale,_morph:t.morph,_target:t.target,_onlyvis:t.onlyvis,ready:new Events};return Object.assign(this,a),this}return _createClass(e,[{key:"build",value:function(){"use strict";console.log(this);for(var e=this,t=arguments.length,r=Array(t),o=0;t>o;o++)r[o]=arguments[o];return r.indexOf("wait")>=0?e._loading.then(function(){e.build_state=new Promise(function(t,r){try{e.mesh.castShadow=!0,e.mesh.receiveShadow=!0,e.mesh.position.set(e._pos.x,e._pos.y,e._pos.z),e.mesh.rotation.set(e._rot.x,e._rot.y,e._rot.z),e.mesh.scale.set(e._scale.x,e._scale.y,e._scale.z),e._pos=e.mesh.position,e._rot=e.mesh.rotation,e._scale=e.mesh.scale,t()}catch(o){console.error(o.message),r()}})}):e.build_state=new Promise(function(t,r){try{e.mesh.castShadow=!0,e.mesh.receiveShadow=!0,e.mesh.position.set(e._pos.x,e._pos.y,e._pos.z),e.mesh.rotation.set(e._rot.x,e._rot.y,e._rot.z),e.mesh.scale.set(e._scale.x,e._scale.y,e._scale.z),e._pos=e.mesh.position,e._rot=e.mesh.rotation,e._scale=e.mesh.scale,t()}catch(o){console.error(o.message),r()}}),this}},{key:"addTo",value:function(e){"use strict";this.root=e;var t=this.mesh,r=this;this._key=this.root.modellingQueue.length;for(var o=arguments.length,n=Array(o>1?o-1:0),a=1;o>a;a++)n[a-1]=arguments[a];return console.log([n,n.indexOf("wait"),r]),n.indexOf("wait")>=0?r._loading.then(function(){r._state=new Promise(function(e,t){try{api.merge(r.root.scene,r.mesh),r.root.modellingQueue.push(r)}catch(o){console.error(o.message),t()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),r.ready.emit("ready"))}})}):r._state=new Promise(function(e,o){try{api.merge(r.root.scene,t),r.root.modellingQueue.push(r)}catch(n){console.error(n.message),o()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),console.log("wqd"),r.ready.emit("ready"))}}),r.root.children.push(r),this}},{key:"_initMaterial",value:function(e){return api.loadMaterial(e)._material}},{key:"remove",value:function(){return this.root.scene.remove(this.mesh),this}},{key:"retrieve",value:function(){return this.root.scene.add(this.mesh),this}}]),e}(),WHS.API.texture=function(e,t){"use strict";
-var r=api.TextureLoader().load(e);if(t){var o=api.extend(t,{offset:{x:0,y:0},repeat:{x:1,y:1}});r.wrapS=r.wrapT=THREE.RepeatWrapping,r.offset.set(o.offset.x,o.offset.y),r.repeat.set(o.repeat.x,o.repeat.y),r.magFilter=THREE.NearestFilter,r.minFilter=THREE.LinearMipMapLinearFilter}return r},WHS.API.Triangulate=function(e,t){"use strict";if(e instanceof THREE.Geometry){if(t){var r=new THREE.Geometry,o=[];e.faces.forEach(function(n){var a=new THREE.Geometry;[].push.apply(a.vertices,[e.vertices[n.a],e.vertices[n.b],e.vertices[n.c]]),a.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(0,1),new THREE.Vector2(1,1),new THREE.Vector2(1,0)]),a.faces.push(new THREE.Face3(0,1,2)),a.computeFaceNormals();var i=new THREE.Mesh(a,t);i.updateMatrix(),r.merge(i.geometry,i.matrix),o.push(t)});var n=new THREE.Mesh(r,new THREE.MeshFaceMaterial(o));return n}}else console.error("No THREE.js geometry")},WHS.Watch=function(e){"use strict";return this._queue=Array.isArray(e)?e.slice():[],this},WHS.Watch.prototype.add=function(e){"use strict";return this._queue.push(e),this},WHS.Watch.prototype.remove=function(e){"use strict";return this._queue=this._queue.filter(function(t){return t!=e}),this},WHS.loop=function(e){this.loop={func:e,id:WHS.loops.length,enabled:!1},WHS.loops.push(this.loop)},WHS.loop.prototype.start=function(){this.loop.enabled=!0},WHS.loop.prototype.stop=function(){this.loop.enabled=!1},WHS.init=function(){function e(t){"use strict";_classCallCheck(this,e),console.log("WHS.init",WHS.REVISION),THREE||console.warn("whitestormJS requires THREE.js. {Object} THREE not found."),Physijs||console.warn("whitestormJS requires PHYSI.js. {Object} Physijs not found."),WAGNER||console.warn("whitestormJS requires WAGNER.js. {Object} WAGNER not found.");var r=api.extend(t,{anaglyph:!1,helper:!1,stats:!1,wagner:!0,autoresize:!1,shadowmap:!0,gravity:{x:0,y:0,z:0},camera:{aspect:75,near:1,far:1e3,x:0,y:0,z:0},rWidth:window.innerWidth,rHeight:window.innerHeight,width:window.innerWidth,height:window.innerHeight,physics:{quatNormalizeSkip:0,quatNormalizeFast:!1,solver:{iterations:20,tolerance:0},defMaterial:{contactEquationStiffness:1e8,contactEquationRegularizationTime:3}},background:0,assets:"./assets",container:document.body,path_worker:"../libs/physijs_worker.js",path_ammo:"../libs/ammo.js"});this._settings=r,this._initScene(),this._initDOM(),this._initStats(),this._initCamera(),this._initRenderer();var o=this;return r.autoresize&&window.addEventListener("load resize",function(){o.resize()}),o}return _createClass(e,[{key:"_initScene",value:function(){this._initPhysiJS(),this.scene=new Physijs.Scene,this.scene.setGravity(new THREE.Vector3(this._settings.gravity.x,this._settings.gravity.y,this._settings.gravity.z)),this.modellingQueue=[],this.children=[]}},{key:"_initPhysiJS",value:function(){Physijs.scripts.worker=this._settings.path_worker,Physijs.scripts.ammo=this._settings.path_ammo}},{key:"_initDOM",value:function(){return this._settings.container.style.margin=0,this._settings.container.style.padding=0,this._settings.container.style.position="relative",this._settings.container.style.overflow="hidden",this._dom=document.createElement("div"),this._dom.className="whs",this._settings.container.appendChild(this._dom),this._dom}},{key:"_initStats",value:function(){this._settings.stats&&(this._stats=new Stats,"fps"==this._settings.stats?this._stats.setMode(0):"ms"==this._settings.stats?this._stats.setMode(1):"mb"==this._settings.stats?this._stats.setMode(1):(this._stats.setMode(0),console.warn([this._stats],"Please, apply stats mode [fps, ms, mb] .")),this._stats.domElement.style.position="absolute",this._stats.domElement.style.left="0px",this._stats.domElement.style.bottom="0px",this._dom.appendChild(this._stats.domElement))}},{key:"_initCamera",value:function(){this._camera=new THREE.PerspectiveCamera(this._settings.camera.aspect,this._settings.width/this._settings.height,this._settings.camera.near,this._settings.camera.far),this._camera.position.set(this._settings.camera.x,this._settings.camera.y,this._settings.camera.z),this.scene.add(this._camera)}},{key:"_initRenderer",value:function(){this._renderer=new THREE.WebGLRenderer,this._renderer.setClearColor(this._settings.background),this._renderer.shadowMap.enabled=this._settings.shadowmap,this._renderer.shadowMap.type=THREE.PCFSoftShadowMap,this._renderer.shadowMap.cascade=!0,this._renderer.setSize(this._settings.rWidth,this._settings.rHeight),this._renderer.render(this.scene,this._camera),this._dom.appendChild(this._renderer.domElement),this._renderer.domElement.style.width="100%",this._renderer.domElement.style.height="100%"}},{key:"start",value:function(){"use strict";function e(o){requestAnimationFrame(e),r._stats&&r._stats.begin(),r._process(t),r.scene.simulate(),r._updateControls(),r._composer?(r._composer.reset(),r._composer.render(r.scene,r._camera),r._composer.pass(r._composer.stack),r._composer.toScreen()):r._renderer.render(r.scene,r._camera),r._loop(o),r._stats&&r._stats.end()}var t=new THREE.Clock,r=this;this._update=e,r._update()}},{key:"_loop",value:function(e){WHS.loops.forEach(function(t){t.enabled&&t.func(e)})}},{key:"_updateControls",value:function(){this.controls&&(this.controls.update(Date.now()-this.time),this.time=Date.now())}},{key:"_process",value:function(e){for(var t=0;t<this.modellingQueue.length;t++)"morph"==this.modellingQueue[t]._type&&this.modellingQueue[t].mesh.mixer.update(e.getDelta())}},{key:"resize",value:function(){this._camera.aspect=window.innerWidth/window.innerHeight,this._camera.updateProjectionMatrix(),this._renderer.setSize(this._settings.rWidth,this._settings.rHeight)}}]),e}(),WHS.Cube=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"cube"));return api.extend(e.geometry,{width:1,height:1,depth:1}),r.mesh=new Physijs.BoxMesh(new THREE.BoxGeometry(e.geometry.width,e.geometry.height,e.geometry.depth),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Cube=function(e){return new WHS.Cube(e).addTo(this)},WHS.Cylinder=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"cylinder"));return api.extend(e.geometry,{radiusTop:1,radiusBottom:1,height:1,radiusSegments:32}),r.mesh=new Physijs.CylinderMesh(new THREE.CylinderGeometry(e.geometry.radiusTop,e.geometry.radiusBottom,e.geometry.height,e.geometry.radiusSegments),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Cylinder=function(e){return new WHS.Cylinder(e).addTo(this)},WHS.Dodecahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"dodecahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.DodecahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Dodecahedron=function(e){return new WHS.Dodecahedron(e).addTo(this)},WHS.Extrude=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"extrude"));return api.extend(e.geometry,{shapes:[],options:{}}),r.mesh=new Physijs.ConvexMesh(new THREE.ExtrudeGeometry(e.geometry.shapes,e.geometry.options),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Extrude=function(e){return new WHS.Extrude(e).addTo(this)},WHS.Icosahderon=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"icosahderon"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.IcosahderonGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Icosahderon=function(e){return new WHS.Icosahderon(e).addTo(this)},WHS.Lathe=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"lathe"));return api.extend(e.geometry,{points:[]}),r.mesh=new Physijs.ConvexMesh(new THREE.LatheGeometry(e.geometry.points),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Lathe=function(e){return new WHS.Lathe(e).addTo(this)},WHS.Model=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"model"));api.extend(e.geometry,{path:""});var o=r,n=_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material);return r._loading=new Promise(function(t,r){api.JSONLoader().load(e.geometry.path,function(r){r.computeFaceNormals(),r.computeVertexNormals(),o.mesh=new Physijs.ConvexMesh(r,n,e.mass),t()})}),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"wait"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Model=function(e){return new WHS.Model(e).addTo(this,"wait")},WHS.Morph=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"morph"));api.extend(e.geometry,{path:""}),console.log(r);var o=r;return r._loading=new Promise(function(t,r){api.JSONLoader().load(e.geometry.path,function(r){var n=new THREE.MeshLambertMaterial({color:16755285,morphTargets:!0,vertexColors:THREE.FaceColors});r.computeFaceNormals(),r.computeVertexNormals(),o.mesh=new THREE.Mesh(r,n),o.mesh.speed=e.morph.speed,o.mesh.mixer=new THREE.AnimationMixer(o.mesh),o.mesh.mixer.addAction(new THREE.AnimationAction(r.animations[0]).warpToDuration(.5)),o.mesh.mixer.update(600*Math.random()),o._rot.y=Math.PI/2,t()})}),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"wait"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Morph=function(e){return new WHS.Morph(e).addTo(this,"wait")},WHS.Octahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"octahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.OctahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Octahedron=function(e){return new WHS.Octahedron(e).addTo(this)},WHS.Parametric=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"parametric"));return api.extend(e.geometry,{func:function(){},slices:10,stacks:10}),r.mesh=new Physijs.ConvexMesh(new THREE.ParametricGeometry(e.geometry.func,e.geometry.slices,e.geometry.stacks),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Parametric=function(e){return new WHS.Parametric(e).addTo(this)},WHS.Plane=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"plane"));return api.extend(e.geometry,{width:10,height:10,segments:32}),r.mesh=new Physijs.ConvexMesh(new THREE.PlaneBufferGeometry(e.geometry.width,e.geometry.height,e.geometry.segments),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Plane=function(e){return new WHS.Plane(e).addTo(this)},WHS.Polyhedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"polyhedron"));return api.extend(e.geometry,{verticesOfCube:[],indicesOfFaces:[],radius:1,detail:1}),r.mesh=new Physijs.ConvexMesh(new THREE.PolyhedronGeometry(e.geometry.verticesOfCube,e.geometry.indicesOfFaces,e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Polyhedron=function(e){return new WHS.Polyhedron(e).addTo(this)},WHS.Ring=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"ring"));return api.extend(e.geometry,{innerRadius:2,outerRadius:5,thetaSegments:30,phiSegments:30,thetaStart:0,thetaLength:2*Math.PI}),r.mesh=new Physijs.ConcaveMesh(new THREE.TorusGeometry(e.geometry.innerRadius,e.geometry.outerRadius,e.geometry.thetaSegments,e.geometry.phiSegments,e.geometry.thetaStart,e.geometry.thetaLength),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Ring=function(e){return new WHS.Ring(e).addTo(this)},WHS.Shape2D=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"shape2D"));return api.extend(e.geometry,{shapes:[]}),r.mesh=new THREE.Mesh(new THREE.ShapeGeometry(e.geometry.shapes),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"onlyvis"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Shape2D=function(e){return new WHS.Shape2D(e).addTo(this)},WHS.Sphere=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"sphere"));return api.extend(e.geometry,{radius:1,segmentA:32,segmentB:32}),r.mesh=new Physijs.SphereMesh(new THREE.SphereGeometry(e.geometry.radius,e.geometry.segmentA,e.geometry.segmentB),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Sphere=function(e){return new WHS.Sphere(e).addTo(this)},WHS.Tetrahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"tetrahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.TetrahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Tetrahedron=function(e){return new WHS.Tetrahedron(e).addTo(this)},WHS.Text=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"text"));return api.extend(e.geometry,{text:"Hello World!",parameters:{size:1,height:50,curveSegments:1,font:"Adelle",weight:"normal",style:"normal",bevelEnabled:!1,bevelThickness:10,bevelSize:8}}),r.mesh=new Physijs.ConcaveMesh(new THREE.TextGeometry(e.geometry.text,e.geometry.parameters),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Text=function(e){return new WHS.Text(e).addTo(this)},WHS.Torus=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"torus"));return api.extend(e.geometry,{radius:100,tube:40,radialSegments:8,tubularSegments:6,arc:2*Math.PI}),r.mesh=new Physijs.ConvexMesh(new THREE.TorusGeometry(e.geometry.radius,e.geometry.tube,e.geometry.radialSegments,e.geometry.tubularSegments,e.geometry.arc),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Torus=function(e){return new WHS.Torus(e).addTo(this)},WHS.Torusknot=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"Torusknot"));return api.extend(e.geometry,{radius:100,tube:40,radialSegments:64,tubularSegments:8,p:2,q:3,heightScale:1}),r.mesh=new Physijs.ConvexMesh(new THREE.TorusKnotGeometry(e.geometry.radius,e.geometry.tube,e.geometry.radialSegments,e.geometry.tubularSegments,e.geometry.p,e.geometry.q,e.geometry.heightScale),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Torusknot=function(e){return new WHS.Torusknot(e).addTo(this)},WHS.Tube=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"tube"));return api.extend(e.geometry,{path:options.geometryOptions.path?new r.CustomSinCurve(100):!1,segments:20,radius:2,radiusSegments:8,closed:!1}),r.mesh=new Physijs.ConvexMesh(new THREE.TubeGeometry(e.geometry.path,e.geometry.segments,e.geometry.radius,e.geometry.radiusSegments,e.geometry.closed),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),_createClass(t,[{key:"CustomSinCurve",get:function(){return THREE.Curve.create(function(e){this.scale=e||1},function(e){var t=3*e-1.5,r=Math.sin(2*Math.PI*e),o=0;return new THREE.Vector3(t,r,o).multiplyScalar(this.scale)})}}]),t}(WHS.Shape),WHS.init.prototype.Tube=function(e){return new WHS.Tube(e).addTo(this)},WHS.init.prototype.addGrass=function(e,t){"use strict";var r={};r.root=this,r.opts=t,r.onlyvis=!0,r.opts.coords||console.warn("Please add grass objects coordinates! @addGrass"),r.grassMeshes=[];var o=new THREE.Mesh(new THREE.Geometry,new THREE.MeshFaceMaterial);return r.opts.coords.forEach(function(t){var n=new THREE.Mesh(new THREE.Geometry,new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("assets/textures/thingrass.png"),side:THREE.DoubleSide,blending:THREE.NormalBlending,transparent:!0,alphaTest:.5})),a=WHS.API.getheight({x:t.x,y:t.y},500,e,-1)[0],i=a.object.geometry.vertices,s=new THREE.Geometry;s.faces.push(new THREE.Face3(0,1,2)),s.vertices.push(i[a.face.a]),s.vertices.push(i[a.face.c]),s.vertices.push(i[a.face.b]),s.computeFaceNormals(),n.position.set(0,0,0),n.geometry.vertices.push(i[a.face.a].clone()),n.geometry.vertices.push(i[a.face.c].clone()),n.geometry.vertices.push(i[a.face.a].clone().add(s.faces[0].normal)),n.geometry.vertices.push(i[a.face.c].clone().add(s.faces[0].normal));var c=new THREE.Vector3(i[a.face.a].clone().x/2+i[a.face.c].clone().x/2,i[a.face.a].clone().y/2+i[a.face.c].clone().y/2,i[a.face.a].clone().z/2+i[a.face.c].clone().z/2);n.geometry.vertices.push(c.clone().add(c.clone().sub(i[a.face.b].clone()))),n.geometry.vertices.push(i[a.face.b].clone()),n.geometry.vertices.push(i[a.face.b].clone().add(s.faces[0].normal)),n.geometry.vertices.push(c.clone().add(c.clone().sub(i[a.face.b].clone())).add(s.faces[0].normal)),n.geometry.faces.push(new THREE.Face3(0,1,2)),n.geometry.faces.push(new THREE.Face3(1,2,3)),n.geometry.faces.push(new THREE.Face3(4,6,5)),n.geometry.faces.push(new THREE.Face3(4,6,7)),n.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,0),new THREE.Vector2(0,1)]),n.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(0,1)]),n.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(1,0)]),n.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(0,1)]),n.geometry.uvsNeedUpdate=!0,o.geometry.merge(n.geometry,n.matrix),o.material.materials.push(n.material),r.grassMeshes.push(n)}),r.wrap(o),r.update=function(){},r.update(),r},WHS.Smooth=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"smooth"));return api.extend(e.geometry,{width:10,height:10}),r.mesh=new Physijs.BoxMesh(new THREE.BoxGeometry(e.geometry.width,1,e.geometry.height),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),0),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Smooth=function(e){return new WHS.Smooth(e).addTo(this)},WHS.Terrain=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"terrain"));api.extend(e.geometry,{width:1,height:1,depth:1,map:!1});var o=document.createElement("canvas");if(o.setAttribute("width",e.geometry.width),o.setAttribute("height",e.geometry.height),o.getContext){var n=o.getContext("2d");n.drawImage(e.geometry.map,0,0)}var a=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/dirt-512.jpg");a.wrapS=a.wrapT=THREE.RepeatWrapping;var i=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/sand-512.jpg");i.wrapS=i.wrapT=THREE.RepeatWrapping;var s=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/grass-512.jpg");s.wrapS=s.wrapT=THREE.RepeatWrapping;var c=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/rock-512.jpg");c.wrapS=c.wrapT=THREE.RepeatWrapping;var l=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/snow-512.jpg");l.wrapS=l.wrapT=THREE.RepeatWrapping;var h=(THREE.NormalMapShader,256),u=256,p={minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBFormat},d=new THREE.WebGLRenderTarget(h,u,p);d.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/default_terrain.png");var m=new THREE.WebGLRenderTarget(h,u,p);m.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/NormalMap.png");var f=new THREE.WebGLRenderTarget(256,256,p);f.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/default_terrain.png");var g=THREE.ShaderTerrain.terrain,y=Object.assign(THREE.UniformsUtils.clone(g.uniforms),{oceanTexture:{type:"t",value:a},sandyTexture:{type:"t",value:i},grassTexture:{type:"t",value:s},rockyTexture:{type:"t",value:c},snowyTexture:{type:"t",value:l},fog:!0,lights:!0},THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}});y.tDisplacement.value=d,y.shadowMap.value=[m],y.uDisplacementScale.value=100,y.uRepeatOverlay.value.set(6,6);var E=new THREE.ShaderMaterial({uniforms:y,vertexShader:g.vertexShader,fragmentShader:g.fragmentShader,lights:!0,fog:!0,side:THREE.DoubleSide,shading:THREE.SmoothShading}),v=new THREE.PlaneGeometry(256,256,255,255);v.verticesNeedUpdate=!0,r._rot.set(Math.PI/180*-90,0,0);for(var _=0,b=0,H=n.getImageData(0,0,256,256).data,w=0;255>=w;w++)for(var T=255;T>=0;T--)v.vertices[_].z=H[b]/255*100,b+=4,_++;return r.mesh=new Physijs.HeightfieldMesh(v,Physijs.createMaterial(E,.8,.1)),v.computeVertexNormals(),v.computeFaceNormals(),v.computeTangents(),r.mesh.updateMatrix(),r.mesh.castShadow=!0,r.mesh.receiveShadow=!0,_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"skip"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Terrain=function(e){return new WHS.Terrain(e).addTo(this)},WHS.init.prototype.addFog=function(e,t){"use strict";var r={};switch(api.extend(t,{hex:0,near:.015,far:1e3,density:25e-5}),e){case"fog":r=new THREE.Fog(t.hex,t.near,t.far);break;case"fogexp2":r=new THREE.FogExp2(t.hex,t.density)}return r},WHS.AmbientLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"ambientlight"));return r.mesh=new THREE.AmbientLight(e.light.color),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.AmbientLight=function(e){return new WHS.AmbientLight(e).addTo(this)},WHS.DirectionalLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"directionallight"));return r.mesh=new THREE.DirectionalLight(e.light.color,e.light.intensity),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.DirectionalLight=function(e){return new WHS.DirectionalLight(e).addTo(this)},WHS.HemisphereLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"hemispherelight"));return r.mesh=new THREE.HemisphereLight(e.light.skyColor,e.light.groundColor,e.light.intensity),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.HemisphereLight=function(e){return new WHS.HemisphereLight(e).addTo(this)},WHS.NormalLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"normallight"));return r.mesh=new THREE.Light(e.light.color),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.NormalLight=function(e){return new WHS.NormalLight(e).addTo(this)},WHS.PointLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"pointlight"));return r.mesh=new THREE.PointLight(e.light.color,e.light.intensity,e.light.distance),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.PointLight=function(e){return new WHS.PointLight(e).addTo(this)},WHS.SpotLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"spotlight"));return r.mesh=new THREE.SpotLight(e.light.color,e.light.intensity,e.light.distance,e.light.angle),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.SpotLight=function(e){return new WHS.SpotLight(e).addTo(this)},WHS.init.prototype.addWagner=function(e,t){"use strict";t=t||{};var r={_composer:this._composer},o=api.extend(t,{hex:0,near:.015,far:1e3,density:25e-5});switch(e){case"ZoomBlurPass":r.effect=new WAGNER.ZoomBlurPass,o=api.extend(o,{strength:.05,center:{x:.5*this._composer.width,y:.5*this._composer.height}});break;case"MultiPassBloomPass":r.effect=new WAGNER.MultiPassBloomPass,o=api.extend(o,{strength:.5,blurAmount:1.32,applyZoomBlur:!0,zoomBlurStrength:.84,useTexture:!0,center:{x:.5*this._composer.width,y:.5*this._composer.height}}),r.effect.glowTexture=WAGNER.Pass.prototype.getOfflineTexture(this._composer.width,this._composer.height,!1);break;case"VignettePass":r.effect=new WAGNER.VignettePass,o=api.extend(o,{amount:.7,falloff:.2});break;case"DirectionalBlurPass":r.effect=new WAGNER.DirectionalBlurPass,o=api.extend(o,{delta:.1});break;case"MotionBlurPass":r.effect=new WAGNER.DirectionalBlurPass,r.motionBlurEnable=!0,o=api.extend(o,{delta:0});break;case"ASCIIPass":r.effect=new WAGNER.ASCIIPass;break;case"DotScreenPass":r.effect=new WAGNER.DotScreenPass;break;case"FxaaPass":r.effect=new WAGNER.FXAAPass;break;case"ChromaticAberrationPass":r.effect=new WAGNER.ChromaticAberrationPass;break;case"DirtPass":r.effect=new WAGNER.DirtPass;break;case"EdgeDetectionPass":r.effect=new WAGNER.SobelEdgeDetectionPass;break;case"HighPassPass":r.effect=new WAGNER.HighPassPass;break;case"GrayscalePass":r.effect=new WAGNER.GrayscalePass;break;case"HalftonePass":r.effect=new WAGNER.HalftonePass;break;case"InvertPass":r.effect=new WAGNER.InvertPass;break;default:return void console.warn('No Wagner effect "'+e+'" exists. If it should exist, open an issue. (@addWagner)')}return r.effect.params=o,this._composer.stack.addPass(e,!0,o),r},WHS.init.prototype.initWagner=function(){this._composer=new WAGNER.Composer(this._renderer),this._composer.setSize(this._settings.rWidth,this._settings.rHeight),this._composer.autoClearColor=!0,this._composer.reset(),this._composer.render(this.scene,this._camera),this._composer.stack=new WAGNER.Stack(new WAGNER.ShadersPool)};var PI_2=Math.PI/2;WHS.init.prototype.MakeFirstPerson=function(e,t){"use strict";var r=WHS.API.extend(t,{block:document.getElementById("blocker"),speed:1,ypos:1});this.controls=new function(e,t,r){function o(e){if(c.enabled!==!1){var t=e.movementX||e.mozMovementX||e.getMovementX()||0,r=e.movementY||e.mozMovementY||e.getMovementY()||0;u.rotation.y-=.002*t,h.rotation.x-=.002*r,h.rotation.x=Math.max(-PI_2,Math.min(PI_2,h.rotation.x))}}function n(e){switch(e.keyCode){case 38:case 87:d=!0;break;case 37:case 65:f=!0;break;case 40:case 83:m=!0;break;case 39:case 68:g=!0;break;case 32:1==y&&(l.applyCentralImpulse({x:0,y:300,z:0}),console.log(l.applyCentralImpulse)),y=!1;break;case 16:s=.5}}function a(e){switch(e.keyCode){case 38:case 87:d=!1;break;case 37:case 65:f=!1;break;case 40:case 83:m=!1;break;case 39:case 68:g=!1;break;case 16:s=.25}}var i=1,s=.25;t.setAngularFactor({x:0,y:0,z:0});var c=this,l=t,h=new THREE.Object3D;h.add(e);var u=new THREE.Object3D;u.position.y=r.ypos,u.add(h);var p=new THREE.Quaternion,d=!1,m=!1,f=!1,g=!1,y=!1;l.addEventListener("collision",function(e,t,r,o){o.y<.5&&(y=!0)}),document.body.addEventListener("mousemove",o,!1),document.body.addEventListener("keydown",n,!1),document.body.addEventListener("keyup",a,!1),this.enabled=!1,this.getObject=function(){return u},this.getDirection=function(e){e.set(0,0,-1),p.multiplyVector3(e)};var E=new THREE.Vector3,v=new THREE.Euler;this.update=function(e){new THREE.Vector3;if(c.enabled!==!1){e=e||.5,e=Math.min(e,.5),E.set(0,0,0);var t=i*e*r.speed*s;d&&(E.z=-t),m&&(E.z=t),f&&(E.x=-t),g&&(E.x=t),v.x=h.rotation.x,v.y=u.rotation.y,v.order="XYZ",p.setFromEuler(v),E.applyQuaternion(p),l.applyCentralImpulse({x:10*E.x,y:0,z:10*E.z}),l.setAngularVelocity({x:10*E.z,y:0,z:10*-E.x}),l.setAngularFactor({x:0,y:0,z:0}),u.position.copy(l.position)}}}(this._camera,e.mesh,r);var o=this.controls;if(WHS.API.merge(this.scene,this.controls.getObject()),"pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document){var n=document.body;this.pointerlockchange=function(){document.pointerLockElement===n||document.mozPointerLockElement===n||document.webkitPointerLockElement===n?(o.enabled=!0,r.block.fadeOut()):(o.enabled=!1,r.block.fadeIn())}}else console.warn("Your browser does not support the PointerLock API.");document.addEventListener("pointerlockchange",this.pointerlockchange,!1),document.addEventListener("mozpointerlockchange",this.pointerlockchange,!1),document.addEventListener("webkitpointerlockchange",this.pointerlockchange,!1),this.pointerlockerror=function(){console.warn("Pointer lock error.")},document.addEventListener("pointerlockerror",this.pointerlockerror,!1),
-document.addEventListener("mozpointerlockerror",this.pointerlockerror,!1),document.addEventListener("webkitpointerlockerror",this.pointerlockerror,!1),r.block.addEventListener("click",function(){if(n.requestPointerLock=n.requestPointerLock||n.mozRequestPointerLock||n.webkitRequestPointerLock,n.requestFullscreen=n.requestFullscreen||n.mozRequestFullscreen||n.mozRequestFullScreen||n.webkitRequestFullscreen,/Firefox/i.test(navigator.userAgent)){var e=function t(){(document.fullscreenElement===n||document.mozFullscreenElement===n||document.mozFullScreenElement===n)&&(document.removeEventListener("fullscreenchange",t),document.removeEventListener("mozfullscreenchange",t),n.requestPointerLock())};document.addEventListener("fullscreenchange",e,!1),document.addEventListener("mozfullscreenchange",e,!1),n.requestFullscreen()}else n.requestPointerLock()})},WHS.init.prototype.OrbitControls=function(e){if(this.controls=new THREE.OrbitControls(this._camera,this._renderer.domElement),e)if(e._whsobject){var t=e?e.mesh.position:new THREE.Vector3(0,0,0);this.controls.target=t}else"object"==("undefined"==typeof e?"undefined":_typeof(e))?this.controls.target.copy(t):console.error("Object must be a THREE.JS vector! @OrbitControls")},WHS.Skybox=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"skybox"));api.extend(e,{skyType:"box",detail:".png",radius:10,path:""});var o,n;switch(e.skyType){case"box":var a=["xpos","xneg","ypos","yneg","zpos","zneg"];o=new THREE.CubeGeometry(e.radius,e.radius,e.radius);for(var i=[],s=0;6>s;s++)i.push(new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture(e.path+a[s]+e.imgSuffix),side:THREE.BackSide}));n=new THREE.MeshFaceMaterial(i);break;case"sphere":o=new THREE.SphereGeometry(e.radius/2,60,40),n=new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture(e.path+e.imgSuffix),side:THREE.BackSide})}return r.mesh=new THREE.Mesh(o,n),r.mesh.renderDepth=1e3,_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Skybox=function(e){return new WHS.Skybox(e).addTo(this)};
\ No newline at end of file
+function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Events(e){var t={},r=[];e=e||this,e.on=function(e,r,n){(t[e]=t[e]||[]).push([r,n])},e.off=function(e,n){e||(t={});for(var o=t[e]||r,a=o.length=n?o.length:0;a--;)n==o[a][0]&&o.splice(a,1)},e.emit=function(e){for(var n,o=t[e]||r,a=0;n=o[a++];)n[0].apply(n[1],r.slice.call(arguments,1))}}var THREE=require("three"),jQuery=require("jquery"),_get=function e(t,r,n){null===t&&(t=Function.prototype);var o=Object.getOwnPropertyDescriptor(t,r);if(void 0===o){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,n)}if("value"in o)return o.value;var i=o.get;if(void 0!==i)return i.call(n)},_createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};THREE.AnaglyphEffect=function(e,t,r){var n,o,a,i,s=new THREE.Matrix4,c=new THREE.Matrix4,l=125,h=new THREE.PerspectiveCamera;h.matrixAutoUpdate=!1;var u=new THREE.PerspectiveCamera;u.matrixAutoUpdate=!1;var p=new THREE.OrthographicCamera(-1,1,1,-1,0,1),d=new THREE.Scene,m={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat};void 0===t&&(t=512),void 0===r&&(r=512);var f=new THREE.WebGLRenderTarget(t,r,m),g=new THREE.WebGLRenderTarget(t,r,m),y=new THREE.ShaderMaterial({uniforms:{mapLeft:{type:"t",value:f},mapRight:{type:"t",value:g}},vertexShader:["varying vec2 vUv;","void main() {","	vUv = vec2( uv.x, uv.y );","	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform sampler2D mapLeft;","uniform sampler2D mapRight;","varying vec2 vUv;","void main() {","	vec4 colorL, colorR;","	vec2 uv = vUv;","	colorL = texture2D( mapLeft, uv );","	colorR = texture2D( mapRight, uv );","	gl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;","}"].join("\n")}),E=new THREE.Mesh(new THREE.PlaneBufferGeometry(2,2),y);d.add(E),this.setSize=function(t,r){f&&f.dispose(),g&&g.dispose(),f=new THREE.WebGLRenderTarget(t,r,m),g=new THREE.WebGLRenderTarget(t,r,m),y.uniforms.mapLeft.value=f,y.uniforms.mapRight.value=g,e.setSize(t,r)},this.render=function(t,r){t.updateMatrixWorld(),void 0===r.parent&&r.updateMatrixWorld();var m=n!==r.aspect||o!==r.near||a!==r.far||i!==r.fov;if(m){n=r.aspect,o=r.near,a=r.far,i=r.fov;var y,E,v=r.projectionMatrix.clone(),_=l/30*.5,H=_*o/l,b=o*Math.tan(THREE.Math.degToRad(.5*i));s.elements[12]=_,c.elements[12]=-_,y=-b*n+H,E=b*n+H,v.elements[0]=2*o/(E-y),v.elements[8]=(E+y)/(E-y),h.projectionMatrix.copy(v),y=-b*n-H,E=b*n-H,v.elements[0]=2*o/(E-y),v.elements[8]=(E+y)/(E-y),u.projectionMatrix.copy(v)}h.matrixWorld.copy(r.matrixWorld).multiply(c),h.position.copy(r.position),h.near=r.near,h.far=r.far,e.render(t,h,f,!0),u.matrixWorld.copy(r.matrixWorld).multiply(s),u.position.copy(r.position),u.near=r.near,u.far=r.far,e.render(t,u,g,!0),e.render(d,p)},this.dispose=function(){f&&f.dispose(),g&&g.dispose()}},THREE.BufferGeometryUtils={computeTangents:function(e){function t(e,t,r){m.fromArray(i,3*e),f.fromArray(i,3*t),g.fromArray(i,3*r),y.fromArray(c,2*e),E.fromArray(c,2*t),v.fromArray(c,2*r);var n=f.x-m.x,o=g.x-m.x,a=f.y-m.y,s=g.y-m.y,l=f.z-m.z,h=g.z-m.z,d=E.x-y.x,b=v.x-y.x,w=E.y-y.y,T=v.y-y.y,S=1/(d*T-b*w);_.set((T*n-w*o)*S,(T*a-w*s)*S,(T*l-w*h)*S),H.set((d*o-b*n)*S,(d*s-b*a)*S,(d*h-b*l)*S),u[e].add(_),u[t].add(_),u[r].add(_),p[e].add(H),p[t].add(H),p[r].add(H)}function r(e){L.fromArray(s,3*e),V.copy(L),P=u[e],W.copy(P),W.sub(L.multiplyScalar(L.dot(P))).normalize(),j.crossVectors(V,P),M=j.dot(p[e]),k=0>M?-1:1,h[4*e]=W.x,h[4*e+1]=W.y,h[4*e+2]=W.z,h[4*e+3]=k}var n=e.index,o=e.attributes;if(null===n||void 0===o.position||void 0===o.normal||void 0===o.uv)return void console.warn("THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()");var a=n.array,i=o.position.array,s=o.normal.array,c=o.uv.array,l=i.length/3;void 0===o.tangent&&e.addAttribute("tangent",new THREE.BufferAttribute(new Float32Array(4*l),4));for(var h=o.tangent.array,u=[],p=[],d=0;l>d;d++)u[d]=new THREE.Vector3,p[d]=new THREE.Vector3;var m=new THREE.Vector3,f=new THREE.Vector3,g=new THREE.Vector3,y=new THREE.Vector2,E=new THREE.Vector2,v=new THREE.Vector2,_=new THREE.Vector3,H=new THREE.Vector3,b=e.groups;0===b.length&&(b=[{start:0,count:a.length}]);for(var w=0,T=b.length;T>w;++w)for(var S=b[w],R=S.start,x=S.count,O=R,C=R+x;C>O;O+=3)t(a[O+0],a[O+1],a[O+2]);for(var k,P,M,W=new THREE.Vector3,j=new THREE.Vector3,L=new THREE.Vector3,V=new THREE.Vector3,w=0,T=b.length;T>w;++w)for(var S=b[w],R=S.start,x=S.count,O=R,C=R+x;C>O;O+=3)r(a[O+0]),r(a[O+1]),r(a[O+2])}},THREE.OrbitControls=function(e,t){function r(){return 2*Math.PI/60/60*p.autoRotateSpeed}function n(){return Math.pow(.95,p.zoomSpeed)}function o(e){if(p.enabled!==!1){if(e.preventDefault(),0===e.button){if(p.noRotate===!0)return;C=O.ROTATE,m.set(e.clientX,e.clientY)}else if(1===e.button){if(p.noZoom===!0)return;C=O.DOLLY,_.set(e.clientX,e.clientY)}else if(2===e.button){if(p.noPan===!0)return;C=O.PAN,y.set(e.clientX,e.clientY)}p.domElement.addEventListener("mousemove",a,!1),p.domElement.addEventListener("mouseup",i,!1)}}function a(e){if(p.enabled!==!1){e.preventDefault();var t=p.domElement===document?p.domElement.body:p.domElement;if(C===O.ROTATE){if(p.noRotate===!0)return;f.set(e.clientX,e.clientY),g.subVectors(f,m),p.rotateLeft(2*Math.PI*g.x/t.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*g.y/t.clientHeight*p.rotateSpeed),m.copy(f)}else if(C===O.DOLLY){if(p.noZoom===!0)return;H.set(e.clientX,e.clientY),b.subVectors(H,_),b.y>0?p.dollyIn():p.dollyOut(),_.copy(H)}else if(C===O.PAN){if(p.noPan===!0)return;E.set(e.clientX,e.clientY),v.subVectors(E,y),p.pan(v),y.copy(E)}p.update()}}function i(){p.enabled!==!1&&(p.domElement.removeEventListener("mousemove",a,!1),p.domElement.removeEventListener("mouseup",i,!1),C=O.NONE)}function s(e){if(p.enabled!==!1&&p.noZoom!==!0){var t=0;e.wheelDelta?t=e.wheelDelta:e.detail&&(t=-e.detail),t>0?p.dollyOut():p.dollyIn()}}function c(e){if(p.enabled!==!1&&p.noKeys!==!0&&p.noPan!==!0){var t=!1;switch(e.keyCode){case p.keys.UP:p.pan(new THREE.Vector2(0,p.keyPanSpeed)),t=!0;break;case p.keys.BOTTOM:p.pan(new THREE.Vector2(0,-p.keyPanSpeed)),t=!0;break;case p.keys.LEFT:p.pan(new THREE.Vector2(p.keyPanSpeed,0)),t=!0;break;case p.keys.RIGHT:p.pan(new THREE.Vector2(-p.keyPanSpeed,0)),t=!0}t&&p.update()}}function l(e){if(p.enabled!==!1)switch(e.touches.length){case 1:if(p.noRotate===!0)return;C=O.TOUCH_ROTATE,m.set(e.touches[0].pageX,e.touches[0].pageY);break;case 2:if(p.noZoom===!0)return;C=O.TOUCH_DOLLY;var t=e.touches[0].pageX-e.touches[1].pageX,r=e.touches[0].pageY-e.touches[1].pageY,n=Math.sqrt(t*t+r*r);_.set(0,n);break;case 3:if(p.noPan===!0)return;C=O.TOUCH_PAN,y.set(e.touches[0].pageX,e.touches[0].pageY);break;default:C=O.NONE}}function h(e){if(p.enabled!==!1){e.preventDefault(),e.stopPropagation();var t=p.domElement===document?p.domElement.body:p.domElement;switch(e.touches.length){case 1:if(p.noRotate===!0)return;if(C!==O.TOUCH_ROTATE)return;f.set(e.touches[0].pageX,e.touches[0].pageY),g.subVectors(f,m),p.rotateLeft(2*Math.PI*g.x/t.clientWidth*p.rotateSpeed),p.rotateUp(2*Math.PI*g.y/t.clientHeight*p.rotateSpeed),m.copy(f);break;case 2:if(p.noZoom===!0)return;if(C!==O.TOUCH_DOLLY)return;var r=e.touches[0].pageX-e.touches[1].pageX,n=e.touches[0].pageY-e.touches[1].pageY,o=Math.sqrt(r*r+n*n);H.set(0,o),b.subVectors(H,_),b.y>0?p.dollyOut():p.dollyIn(),_.copy(H);break;case 3:if(p.noPan===!0)return;if(C!==O.TOUCH_PAN)return;E.set(e.touches[0].pageX,e.touches[0].pageY),v.subVectors(E,y),p.pan(v),y.copy(E);break;default:C=O.NONE}}}function u(){p.enabled!==!1&&(C=O.NONE)}this.object=e,this.domElement=void 0!==t?t:document,this.enabled=!0,this.target=new THREE.Vector3,this.center=this.target,this.noZoom=!1,this.zoomSpeed=1,this.minDistance=0,this.maxDistance=1/0,this.noRotate=!1,this.rotateSpeed=1,this.noPan=!1,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.noKeys=!1,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40};var p=this,d=1e-6,m=new THREE.Vector2,f=new THREE.Vector2,g=new THREE.Vector2,y=new THREE.Vector2,E=new THREE.Vector2,v=new THREE.Vector2,_=new THREE.Vector2,H=new THREE.Vector2,b=new THREE.Vector2,w=0,T=0,S=1,R=new THREE.Vector3,x=new THREE.Vector3,O={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},C=O.NONE,k={type:"change"};this.rotateLeft=function(e){void 0===e&&(e=r()),T-=e},this.rotateUp=function(e){void 0===e&&(e=r()),w-=e},this.panLeft=function(e){var t=new THREE.Vector3,r=this.object.matrix.elements;t.set(r[0],r[1],r[2]),t.multiplyScalar(-e),R.add(t)},this.panUp=function(e){var t=new THREE.Vector3,r=this.object.matrix.elements;t.set(r[4],r[5],r[6]),t.multiplyScalar(e),R.add(t)},this.pan=function(e){var t=p.domElement===document?p.domElement.body:p.domElement;if(void 0!==p.object.fov){var r=p.object.position,n=r.clone().sub(p.target),o=n.length();o*=Math.tan(p.object.fov/2*Math.PI/180),p.panLeft(2*e.x*o/t.clientHeight),p.panUp(2*e.y*o/t.clientHeight)}else void 0!==p.object.top?(p.panLeft(e.x*(p.object.right-p.object.left)/t.clientWidth),p.panUp(e.y*(p.object.top-p.object.bottom)/t.clientHeight)):console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.")},this.dollyIn=function(e){void 0===e&&(e=n()),S/=e},this.dollyOut=function(e){void 0===e&&(e=n()),S*=e},this.update=function(){var e=this.object.position,t=e.clone().sub(this.target),n=Math.atan2(t.x,t.z),o=Math.atan2(Math.sqrt(t.x*t.x+t.z*t.z),t.y);this.autoRotate&&this.rotateLeft(r()),n+=T,o+=w,o=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,o)),o=Math.max(d,Math.min(Math.PI-d,o));var a=t.length()*S;a=Math.max(this.minDistance,Math.min(this.maxDistance,a)),this.target.add(R),t.x=a*Math.sin(o)*Math.sin(n),t.y=a*Math.cos(o),t.z=a*Math.sin(o)*Math.cos(n),e.copy(this.target).add(t),this.object.lookAt(this.target),T=0,w=0,S=1,R.set(0,0,0),x.distanceTo(this.object.position)>0&&(this.dispatchEvent(k),x.copy(this.object.position))},this.domElement.addEventListener("contextmenu",function(e){e.preventDefault()},!1),this.domElement.addEventListener("mousedown",o,!1),this.domElement.addEventListener("mousewheel",s,!1),this.domElement.addEventListener("DOMMouseScroll",s,!1),this.domElement.addEventListener("keydown",c,!1),this.domElement.addEventListener("touchstart",l,!1),this.domElement.addEventListener("touchend",u,!1),this.domElement.addEventListener("touchmove",h,!1)},THREE.OrbitControls.prototype=Object.create(THREE.EventDispatcher.prototype);var Stats=function(){function e(e,t,r){return e=document.createElement(e),e.id=t,e.style.cssText=r,e}function t(t,r,n){var o=e("div",t,"padding:0 0 3px 3px;text-align:left;background:"+n),a=e("div",t+"Text","font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px;color:"+r);for(a.innerHTML=t.toUpperCase(),o.appendChild(a),t=e("div",t+"Graph","width:74px;height:30px;background:"+r),o.appendChild(t),r=0;74>r;r++)t.appendChild(e("span","","width:1px;height:30px;float:left;opacity:0.9;background:"+n));return o}function r(e){for(var t=l.children,r=0;r<t.length;r++)t[r].style.display=r===e?"block":"none";c=e}function n(e,t){e.appendChild(e.firstChild).style.height=Math.min(30,30-30*t)+"px"}var o=self.performance&&self.performance.now?self.performance.now.bind(performance):Date.now,a=o(),i=a,s=0,c=0,l=e("div","stats","width:80px;opacity:0.9;cursor:pointer");l.addEventListener("mousedown",function(e){e.preventDefault(),r(++c%l.children.length)},!1);var h=0,u=1/0,p=0,d=t("fps","#0ff","#002"),m=d.children[0],f=d.children[1];l.appendChild(d);var g=0,y=1/0,E=0,d=t("ms","#0f0","#020"),v=d.children[0],_=d.children[1];if(l.appendChild(d),self.performance&&self.performance.memory){var H=0,b=1/0,w=0,d=t("mb","#f08","#201"),T=d.children[0],S=d.children[1];l.appendChild(d)}return r(c),{REVISION:14,domElement:l,setMode:r,begin:function(){a=o()},end:function(){var e=o();if(g=e-a,y=Math.min(y,g),E=Math.max(E,g),v.textContent=(0|g)+" MS ("+(0|y)+"-"+(0|E)+")",n(_,g/200),s++,e>i+1e3&&(h=Math.round(1e3*s/(e-i)),u=Math.min(u,h),p=Math.max(p,h),m.textContent=h+" FPS ("+u+"-"+p+")",n(f,h/100),i=e,s=0,void 0!==H)){var t=performance.memory.usedJSHeapSize,r=performance.memory.jsHeapSizeLimit;H=Math.round(9.54e-7*t),b=Math.min(b,H),w=Math.max(w,H),T.textContent=H+" MB ("+b+"-"+w+")",n(S,t/r)}return e},update:function(){a=this.end()}}};"object"===("undefined"==typeof module?"undefined":_typeof(module))&&(module.exports=Stats),THREE.SubdivisionModifier=function(e){"use strict";this.subdivisions=void 0===e?1:e},THREE.SubdivisionModifier.prototype.modify=function(e){for(var t=this.subdivisions;t-- >0;)this.smooth(e);delete e.__tmpVertices,e.computeFaceNormals(),e.computeVertexNormals()},function(){function e(e,t,r){var n=Math.min(e,t),o=Math.max(e,t),a=n+"_"+o;return r[a]}function t(e,t,r,n,o,a){var i,s=Math.min(e,t),c=Math.max(e,t),l=s+"_"+c;if(l in n)i=n[l];else{var h=r[s],u=r[c];i={a:h,b:u,newEdge:null,faces:[]},n[l]=i}i.faces.push(o),a[e].edges.push(i),a[t].edges.push(i)}function r(e,r,n,o){var a,i,s;for(a=0,i=e.length;i>a;a++)n[a]={edges:[]};for(a=0,i=r.length;i>a;a++)s=r[a],t(s.a,s.b,e,o,s,n),t(s.b,s.c,e,o,s,n),t(s.c,s.a,e,o,s,n)}function n(e,t,r,n){e.push(new THREE.Face3(t,r,n))}var o=!1,a=["a","b","c"];THREE.SubdivisionModifier.prototype.smooth=function(t){var i,s,c,l,h,u,p,d,m,f,g,g,y,E,v=new THREE.Vector3;i=t.vertices,s=t.faces,f=new Array(i.length),g={},r(i,s,f,g),y=[];var _,H,b,w,T,S,R;for(u in g){for(H=g[u],b=new THREE.Vector3,T=3/8,S=1/8,R=H.faces.length,2!=R&&(T=.5,S=0,1!=R&&o&&console.warn("Subdivision Modifier: Number of connected faces != 2, is: ",R,H)),b.addVectors(H.a,H.b).multiplyScalar(T),v.set(0,0,0),d=0;R>d;d++){for(w=H.faces[d],m=0;3>m&&(_=i[w[a[m]]],_===H.a||_===H.b);m++);v.add(_)}v.multiplyScalar(S),b.add(v),H.newEdge=y.length,y.push(b)}var x,O,C,k,P,M,W;for(E=[],u=0,p=i.length;p>u;u++){for(M=i[u],P=f[u].edges,h=P.length,3==h?x=3/16:h>3&&(x=3/(8*h)),O=1-h*x,C=x,2>=h&&(2==h?(o&&console.warn("2 connecting edges",P),O=.75,C=1/8):1==h?o&&console.warn("only 1 connecting edge"):0==h&&o&&console.warn("0 connecting edges")),W=M.clone().multiplyScalar(O),v.set(0,0,0),d=0;h>d;d++)k=P[d],_=k.a!==M?k.a:k.b,v.add(_);v.multiplyScalar(C),W.add(v),E.push(W)}c=E.concat(y);var j,L,V,A=E.length;for(l=[],u=0,p=s.length;p>u;u++)w=s[u],j=e(w.a,w.b,g).newEdge+A,L=e(w.b,w.c,g).newEdge+A,V=e(w.c,w.a,g).newEdge+A,n(l,j,L,V),n(l,w.a,j,V),n(l,w.b,L,j),n(l,w.c,V,L);t.vertices=c,t.faces=l}}();var WHS={REVISION:"7",API:{},_settings:{assets:"./assets",path_worker:"../libs/physijs_worker.js",path_ammo:"../libs/ammo.js"},loops:[],grounds:[]},api=WHS.API;"function"==typeof define&&define.amd?define("whitestorm",WHS):"undefined"!=typeof exports&&"undefined"!=typeof module&&(module.exports=WHS),THREE.ShaderTerrain={terrain:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{enableDiffuse1:{type:"i",value:0},enableDiffuse2:{type:"i",value:0},enableSpecular:{type:"i",value:0},enableReflection:{type:"i",value:0},tDiffuse1:{type:"t",value:null},tDiffuse2:{type:"t",value:null},tDetail:{type:"t",value:null},tNormal:{type:"t",value:null},tSpecular:{type:"t",value:null},tDisplacement:{type:"t",value:null},uNormalScale:{type:"f",value:1},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},diffuse:{type:"c",value:new THREE.Color(15658734)},specular:{type:"c",value:new THREE.Color(1118481)},shininess:{type:"f",value:30},opacity:{type:"f",value:1},uRepeatBase:{type:"v2",value:new THREE.Vector2(1,1)},uRepeatOverlay:{type:"v2",value:new THREE.Vector2(1,1)},uOffset:{type:"v2",value:new THREE.Vector2(0,0)}}]),fragmentShader:["\n		        uniform vec3 diffuse;\n		        uniform vec3 emissive;\n		        uniform float opacity;\n		        uniform vec3 ambientLightColor;\n		        varying vec3 vLightFront;\n		        #ifdef DOUBLE_SIDED\n			        varying vec3 vLightBack;\n			        uniform vec2 uRepeatOverlay;\n			        uniform vec2 uRepeatBase;\n			        uniform vec2 uOffset;\n			        uniform float uNormalScale;\n			        uniform sampler2D tNormal;\n		        #endif\n		        uniform sampler2D oceanTexture;\n		        uniform sampler2D sandyTexture;\n		        uniform sampler2D grassTexture;\n		        uniform sampler2D rockyTexture;\n		        uniform sampler2D snowyTexture;\n		        varying vec3 vTangent;\n		        varying vec3 vBinormal;\n		        varying vec3 vNormal;\n		        varying vec3 vViewPosition;\n		"+[THREE.ShaderChunk.common,THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.alphamap_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.specularmap_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment].join("\n")+"\n		        varying vec2 vUv;\n		        varying float vAmount;\n		        void main() {\n		        	// UVs.\n		            vec2 uvOverlay = uRepeatOverlay * vUv + uOffset;\n		            vec2 uvBase = uRepeatBase * vUv;\n					vec3 specularTex = vec3( 1.0 );\n		            vec3 normalTex = texture2D( tNormal, uvOverlay ).xyz * 2.0 - 1.0;\n		            normalTex.xy *= uNormalScale;\n		            normalTex = normalize( normalTex );\n		            mat3 tsb = mat3( vTangent, vBinormal, vNormal );\n		            vec3 finalNormal = tsb * normalTex;\n		            vec3 normal = normalize( finalNormal );\n		            vec3 viewPosition = normalize( vViewPosition );\n		            vec3 shadowMask = vec3( 1.0 );\n		            vec3 outgoingLight = vec3( 0.0 );\n		            vec3 totalAmbientLight = ambientLightColor;\n		            vec4 diffuseColor = vec4(0.0);\n		            // Color by texture.\n		            vec4 water = (smoothstep(0.01, 0.25, vAmount)\n		            - smoothstep(0.24, 0.26, vAmount))\n		            * texture2D( oceanTexture, vUv * 10.0 );\n		            vec4 sandy = (smoothstep(0.24, 0.27, vAmount)\n		            - smoothstep(0.28, 0.31, vAmount))\n		            * texture2D( sandyTexture, vUv * 10.0 );\n		            vec4 grass = (smoothstep(0.28, 0.32, vAmount)\n		            - smoothstep(0.35, 0.40, vAmount))\n		            * texture2D( grassTexture, vUv * 20.0 );\n		            vec4 rocky = (smoothstep(0.30, 0.40, vAmount)\n		            - smoothstep(0.40, 0.70, vAmount))\n		            * texture2D( rockyTexture, vUv * 20.0 );\n		            vec4 snowy = (smoothstep(0.42, 0.45, vAmount))\n		            * texture2D( snowyTexture, vUv * 10.0 );\n		            diffuseColor = vec4(0.0, 0.0, 0.0, 1.0)\n		            + water + sandy + grass + rocky + snowy;\n		"+[THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphamap_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.specularmap_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment].join("\n")+"\n		            #ifdef DOUBLE_SIDED\n		                if ( gl_FrontFacing )\n		                    outgoingLight += diffuseColor.rgb * \n		                		( vLightFront * shadowMask + totalAmbientLight )\n		                		+ emissive;\n		                else\n		                    outgoingLight += diffuseColor.rgb * \n		                		( vLightBack * shadowMask + totalAmbientLight )\n		                		+ emissive;\n		            #else\n		                outgoingLight += diffuseColor.rgb * \n		                	( vLightFront * shadowMask + totalAmbientLight )\n		                	+ emissive;\n		            #endif\n		           gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n		      }\n		"],vertexShader:["\n		    #define TERRAIN;\n		    varying vec3 vLightFront;\n		    #ifdef DOUBLE_SIDED\n		        varying vec3 vLightBack;\n		    #endif\n		    \n		    varying float vAmount;\n		    attribute vec4 tangent;\n		    uniform vec2 uRepeatBase;\n		    uniform sampler2D tNormal;\n		    #ifdef VERTEX_TEXTURES\n			    uniform sampler2D tDisplacement;\n			    uniform float uDisplacementScale;\n			    uniform float uDisplacementBias;\n		    #endif\n		    varying vec3 vTangent;\n		    varying vec3 vBinormal;\n		    varying vec3 vNormal;\n		    varying vec2 vUv;\n		    varying vec3 vViewPosition;\n		"+[THREE.ShaderChunk.common,THREE.ShaderChunk.uv_pars_vertex,THREE.ShaderChunk.uv2_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_lambert_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex].join("\n")+"\n		    void main() {\n		"+[THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.beginnormal_vertex,THREE.ShaderChunk.morphnormal_vertex,THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.skinnormal_vertex,THREE.ShaderChunk.defaultnormal_vertex,THREE.ShaderChunk.begin_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.project_vertex,THREE.ShaderChunk.logdepthbuf_vertex,THREE.ShaderChunk.uv_vertex,THREE.ShaderChunk.uv2_vertex].join("\n")+"\n			    vNormal = normalize( normalMatrix * normal);\n			    // Tangent and binormal vectors.\n			    vTangent = normalize( normalMatrix * tangent.xyz );\n			    vBinormal = cross( vNormal, vTangent ) * tangent.w;\n			    vBinormal = normalize( vBinormal );\n			    // Texture coordinates.\n			    vUv = uv;\n			    vec2 uvBase = uv * uRepeatBase;\n			    // displacement mapping\n			    vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n			    mvPosition = modelViewMatrix * vec4( position, 1.0 );\n			    transformedNormal = normalize( normalMatrix * normal );\n			    gl_Position = projectionMatrix * mvPosition;\n			    vViewPosition = -mvPosition.xyz;\n			    vAmount = position.z * 0.005 + 0.1;\n		"+[THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.lights_lambert_vertex,THREE.ShaderChunk.shadowmap_vertex].join("\n")+"\n		   }\n		"],side:THREE.DoubleSide,shading:THREE.SmoothShading}},WHS.API.extend=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;t>n;n++)r[n-1]=arguments[n];var o=!0,a=!1,i=void 0;try{for(var s,c=r[Symbol.iterator]();!(o=(s=c.next()).done);o=!0){var l=s.value;if(l){var h=!0,u=!1,p=void 0;try{for(var d,m=Object.getOwnPropertyNames(l)[Symbol.iterator]();!(h=(d=m.next()).done);h=!0){var f=d.value;void 0!=e[f]&&"[object Object]"==e[f].toString()&&"[object Object]"==l[f].toString()?WHS.API.extend(e[f],l[f]):e[f]=0===e[f]?0:e[f]||l[f]}}catch(g){u=!0,p=g}finally{try{!h&&m["return"]&&m["return"]()}finally{if(u)throw p}}}}}catch(g){a=!0,i=g}finally{try{!o&&c["return"]&&c["return"]()}finally{if(a)throw i}}return e},WHS.API.getheight=function(e,t,r,n){"use strict";return t=t||1e3,n=n||1,this.raycaster=new THREE.Raycaster(new THREE.Vector3(e.x,t,n*e.y),new THREE.Vector3(0,-1,0)),this.intersect=this.raycaster.intersectObject(r.mesh),this.intersect},WHS.Light=function(){function e(t,r){_classCallCheck(this,e);var n=function(e,t,r){this.x=e,this.y=t,this.z=r};t.pos&&(t.pos.set=n),t.rot&&(t.rot.set=n),t.target&&(t.target.set=n);var o=api.extend(t,{light:{color:16777215,skyColor:16777215,groundColor:16777215,intensity:1,distance:100,angle:Math.PI/3},shadowmap:{cast:!0,bias:1e-4,width:1024,height:1024,near:!0,far:400,fov:60,darkness:.3,top:200,bottom:-200,left:-200,right:200},pos:{x:0,y:0,z:0,set:n},rot:{x:0,y:0,z:0,set:n},target:{x:0,y:0,z:0,set:n}}),a=0,i={_key:a,_type:r,_whsobject:!0,_name:r+a,__releaseTime:(new Date).getTime(),_pos:o.pos,_rot:o.rot,_target:o.target,_light:o.light,_shadowmap:o.shadowmap,ready:new Events};return Object.assign(this,i),this}return _createClass(e,[{key:"build",value:function(){"use strict";for(var e=this,t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];var o=this.mesh,a=this;return this.build_state=new Promise(function(t,n){try{o.castShadow=!0,o.receiveShadow=!0,o.position.set(e._pos.x,e._pos.y,e._pos.z),o.rotation.set(e._rot.x,e._rot.y,e._rot.z),r.forEach(function(e){a[e]=!0}),t()}catch(i){console.error(i.message),n()}}),this}},{key:"addTo",value:function(e){"use strict";this.root=e;var t=this.mesh,r=this;return console.log(this),this._key=this.root.modellingQueue.length,r._state=new Promise(function(e,n){try{api.merge(r.root.scene,t),r.root.modellingQueue.push(r)}catch(o){console.error(o.message),n()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),r.ready.emit("ready"))}}),r.root.children.push(r),this}},{key:"buildShadow",value:function(){this.mesh.shadowMapWidth=this._shadowmap.width,this.mesh.shadowMapHeight=this._shadowmap.height,this.mesh.shadowBias=this._shadowmap.bias,this.mesh.shadowCameraNear=this._shadowmap.near,this.mesh.shadowCameraFar=this._shadowmap.far,this.mesh.shadowCameraFov=this._shadowmap.fov,this.mesh.shadowDarkness=this._shadowmap.darkness,this.mesh.shadowCameraLeft=this._shadowmap.left,this.mesh.shadowCameraRight=this._shadowmap.right,this.mesh.shadowCameraTop=this._shadowmap.top,this.mesh.shadowCameraBottom=this._shadowmap.bottom}},{key:"remove",value:function(){return this.root.scene.remove(this.mesh),this}},{key:"retrieve",value:function(){return this.root.scene.add(this.mesh),this}}]),e}(),WHS.API.JSONLoader=function(){return new THREE.JSONLoader},WHS.API.TextureLoader=function(){return new THREE.TextureLoader},WHS.API.loadMaterial=function(e){"use strict";"string"!=typeof e.kind&&console.error("Type of material is undefined or not a string. @loadMaterial");var t={_type:e.kind,_restitution:e.restitution||e.rest||.3,_friction:e.friction||e.fri||.8},r=api.extend({},e);switch(delete r.kind,delete r.friction,delete r.fri,delete r.restitution,delete r.rest,e.kind){case"basic":t._material=new THREE.MeshBasicMaterial(r);break;case"linebasic":t._params=new THREE.LineBasicMaterial(r);break;case"linedashed":t._material=new THREE.LineDashedMaterial(r);break;case"material":t._material=new THREE.Material(r);break;case"depth":t._material=new THREE.MeshDepthMaterial(r);break;case"face":t._material=new THREE.MeshFaceMaterial(r);break;case"lambert":t._material=new THREE.MeshLambertMaterial(r);break;case"normal":t._material=new THREE.MeshNormalMaterial(r);break;case"phong":t._material=new THREE.MeshPhongMaterial(r);break;case"pointcloud":t._material=new THREE.PointCloudMaterial(r);break;case"rawshader":t._material=new THREE.RawShaderMaterial(r);break;case"shader":t._material=new THREE.ShaderMaterial(r);break;case"spritecanvas":t._material=new THREE.SpriteCanvasMaterial(r);break;case"sprite":t._material=new THREE.SpriteMaterial(r)}return t._material=Physijs.createMaterial(t._material,t._friction,t._restitution),console.log(t._friction),t},WHS.API.merge=function(e,t){"use strict";if(("object"!==("undefined"==typeof e?"undefined":_typeof(e))||"object"!==("undefined"==typeof t?"undefined":_typeof(t)))&&console.error("No rabbits for the box. (arguments)",["undefined"==typeof e?"undefined":_typeof(e),"undefined"==typeof t?"undefined":_typeof(t)]),e)if(Array.isArray(t)&&1===t.length)e.add(t[0]);else if(Array.isArray(t)&&t.length>1&&e)for(var r=0;r<t.length;r++)e.add(t[r]);else Array.isArray(t)||e.add(t);else console.error("box is undefined. Line "+(new Error).lineNumber+". Func merge.",[e,t])},WHS.API.PackUvs=function(e){e.computeBoundingBox();var t=e.boundingBox.max,r=e.boundingBox.min,n=new THREE.Vector2(0-r.x,0-r.y),o=new THREE.Vector2(t.x-r.x,t.y-r.y);e.faceVertexUvs[0]=[];for(var a=e.faces,i=0;i<e.faces.length;i++){var s=e.vertices[a[i].a],c=e.vertices[a[i].b],l=e.vertices[a[i].c];e.faceVertexUvs[0].push([new THREE.Vector2((s.x+n.x)/o.x,(s.y+n.y)/o.y),new THREE.Vector2((c.x+n.x)/o.x,(c.y+n.y)/o.y),new THREE.Vector2((l.x+n.x)/o.x,(l.y+n.y)/o.y)])}e.uvsNeedUpdate=!0},WHS.API.removeDuplicateFaces=function(e){function t(){return!(a1.sort()>a2.sort()||a1.sort()<a2.sort())}for(var r=0;r<e.faces.length;r++)for(var n=e.faces[r],o=[n.a,n.b,n.c,n.d].sort(),a=0;r>a;a++){var i=e.faces[a];if(void 0!==i){var s=[i.a,i.b,i.c,i.d].sort();t(o,s)&&(delete e.faces[r],delete e.faces[a])}}return e.faces=e.faces.filter(function(e){return void 0===e}),e},WHS.API.rotateGeometry=function(e,t){"use strict";var r=new THREE.Matrix4;r.makeRotationFromEuler(new THREE.Euler(t.x,t.y,t.z,"XYZ"));for(var n in e.vertices)e.vertices[n].applyMatrix4(r);return e},WHS.Shape=function(){function e(t,r){_classCallCheck(this,e);var n=function(e,t,r){this.x=e,this.y=t,this.z=r};api.extend(t,{mass:10,pos:{x:0,y:0,z:0,set:n},rot:{x:0,y:0,z:0,set:n},scale:{x:1,y:1,z:1,set:n},target:{x:0,y:0,z:0,set:n},morph:{speed:1,duration:1},onlyvis:!1});var o=0,a={_key:o,_type:r,_whsobject:!0,_name:r+o,__releaseTime:(new Date).getTime(),_pos:t.pos,_rot:t.rot,_scale:t.scale,_morph:t.morph,_target:t.target,_onlyvis:t.onlyvis,ready:new Events};return Object.assign(this,a),this}return _createClass(e,[{key:"build",value:function(){"use strict";console.log(this);for(var e=this,t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];return r.indexOf("wait")>=0?e._loading.then(function(){e.build_state=new Promise(function(t,r){try{e.mesh.castShadow=!0,e.mesh.receiveShadow=!0,e.mesh.position.set(e._pos.x,e._pos.y,e._pos.z),e.mesh.rotation.set(e._rot.x,e._rot.y,e._rot.z),e.mesh.scale.set(e._scale.x,e._scale.y,e._scale.z),e._pos=e.mesh.position,e._rot=e.mesh.rotation,e._scale=e.mesh.scale,t()}catch(n){console.error(n.message),r()}})}):e.build_state=new Promise(function(t,r){try{e.mesh.castShadow=!0,e.mesh.receiveShadow=!0,e.mesh.position.set(e._pos.x,e._pos.y,e._pos.z),e.mesh.rotation.set(e._rot.x,e._rot.y,e._rot.z),e.mesh.scale.set(e._scale.x,e._scale.y,e._scale.z),e._pos=e.mesh.position,e._rot=e.mesh.rotation,e._scale=e.mesh.scale,t()}catch(n){console.error(n.message),r()}}),this}},{key:"addTo",value:function(e){"use strict";this.root=e;var t=this.mesh,r=this;this._key=this.root.modellingQueue.length;for(var n=arguments.length,o=Array(n>1?n-1:0),a=1;n>a;a++)o[a-1]=arguments[a];return console.log([o,o.indexOf("wait"),r]),o.indexOf("wait")>=0?r._loading.then(function(){r._state=new Promise(function(e,t){try{api.merge(r.root.scene,r.mesh),r.root.modellingQueue.push(r)}catch(n){console.error(n.message),t()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),r.ready.emit("ready"))}})}):r._state=new Promise(function(e,n){try{api.merge(r.root.scene,t),r.root.modellingQueue.push(r)}catch(o){console.error(o.message),n()}finally{r._wait?r._mesh.addEventListener("ready",function(){e(),r.ready.emit("ready")}):(e(),console.log("wqd"),r.ready.emit("ready"))}}),r.root.children.push(r),this}},{key:"_initMaterial",value:function(e){return api.loadMaterial(e)._material}},{key:"remove",value:function(){return this.root.scene.remove(this.mesh),this}},{key:"retrieve",value:function(){return this.root.scene.add(this.mesh),this}}]),e}(),WHS.API.texture=function(e,t){"use strict";
+var r=api.TextureLoader().load(e);if(t){var n=api.extend(t,{offset:{x:0,y:0},repeat:{x:1,y:1}});r.wrapS=r.wrapT=THREE.RepeatWrapping,r.offset.set(n.offset.x,n.offset.y),r.repeat.set(n.repeat.x,n.repeat.y),r.magFilter=THREE.NearestFilter,r.minFilter=THREE.LinearMipMapLinearFilter}return r},WHS.API.Triangulate=function(e,t){"use strict";if(e instanceof THREE.Geometry){if(t){var r=new THREE.Geometry,n=[];e.faces.forEach(function(o){var a=new THREE.Geometry;[].push.apply(a.vertices,[e.vertices[o.a],e.vertices[o.b],e.vertices[o.c]]),a.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(0,1),new THREE.Vector2(1,1),new THREE.Vector2(1,0)]),a.faces.push(new THREE.Face3(0,1,2)),a.computeFaceNormals();var i=new THREE.Mesh(a,t);i.updateMatrix(),r.merge(i.geometry,i.matrix),n.push(t)});var o=new THREE.Mesh(r,new THREE.MeshFaceMaterial(n));return o}}else console.error("No THREE.js geometry")},WHS.Watch=function(e){"use strict";return this._queue=Array.isArray(e)?e.slice():[],this},WHS.Watch.prototype.add=function(e){"use strict";return this._queue.push(e),this},WHS.Watch.prototype.remove=function(e){"use strict";return this._queue=this._queue.filter(function(t){return t!=e}),this},WHS.loop=function(e){this.loop={func:e,id:WHS.loops.length,enabled:!1},WHS.loops.push(this.loop)},WHS.loop.prototype.start=function(){this.loop.enabled=!0},WHS.loop.prototype.stop=function(){this.loop.enabled=!1},WHS.init=function(){function e(t){"use strict";_classCallCheck(this,e),console.log("WHS.init",WHS.REVISION),THREE||console.warn("whitestormJS requires THREE.js. {Object} THREE not found."),Physijs||console.warn("whitestormJS requires PHYSI.js. {Object} Physijs not found.");var r=api.extend(t,{anaglyph:!1,helper:!1,stats:!1,autoresize:!1,shadowmap:!0,gravity:{x:0,y:0,z:0},camera:{aspect:75,near:1,far:1e3,x:0,y:0,z:0},rWidth:window.innerWidth,rHeight:window.innerHeight,width:window.innerWidth,height:window.innerHeight,physics:{quatNormalizeSkip:0,quatNormalizeFast:!1,solver:{iterations:20,tolerance:0},defMaterial:{contactEquationStiffness:1e8,contactEquationRegularizationTime:3}},background:0,assets:"./assets",container:document.body,path_worker:"../libs/physijs_worker.js",path_ammo:"../libs/ammo.js"});this._settings=r,this._initScene(),this._initDOM(),this._initStats(),this._initCamera(),this._initRenderer();var n=this;return r.autoresize&&window.addEventListener("load resize",function(){n.resize()}),n}return _createClass(e,[{key:"_initScene",value:function(){this._initPhysiJS(),this.scene=new Physijs.Scene,this.scene.setGravity(new THREE.Vector3(this._settings.gravity.x,this._settings.gravity.y,this._settings.gravity.z)),this.modellingQueue=[],this.children=[]}},{key:"_initPhysiJS",value:function(){Physijs.scripts.worker=this._settings.path_worker,Physijs.scripts.ammo=this._settings.path_ammo}},{key:"_initDOM",value:function(){return this._settings.container.style.margin=0,this._settings.container.style.padding=0,this._settings.container.style.position="relative",this._settings.container.style.overflow="hidden",this._dom=document.createElement("div"),this._dom.className="whs",this._settings.container.appendChild(this._dom),this._dom}},{key:"_initStats",value:function(){this._settings.stats&&(this._stats=new Stats,"fps"==this._settings.stats?this._stats.setMode(0):"ms"==this._settings.stats?this._stats.setMode(1):"mb"==this._settings.stats?this._stats.setMode(1):(this._stats.setMode(0),console.warn([this._stats],"Please, apply stats mode [fps, ms, mb] .")),this._stats.domElement.style.position="absolute",this._stats.domElement.style.left="0px",this._stats.domElement.style.bottom="0px",this._dom.appendChild(this._stats.domElement))}},{key:"_initCamera",value:function(){this._camera=new THREE.PerspectiveCamera(this._settings.camera.aspect,this._settings.width/this._settings.height,this._settings.camera.near,this._settings.camera.far),this._camera.position.set(this._settings.camera.x,this._settings.camera.y,this._settings.camera.z),this.scene.add(this._camera)}},{key:"_initRenderer",value:function(){this._renderer=new THREE.WebGLRenderer,this._renderer.setClearColor(this._settings.background),this._renderer.shadowMap.enabled=this._settings.shadowmap,this._renderer.shadowMap.type=THREE.PCFSoftShadowMap,this._renderer.shadowMap.cascade=!0,this._renderer.setSize(this._settings.rWidth,this._settings.rHeight),this._renderer.render(this.scene,this._camera),this._dom.appendChild(this._renderer.domElement),this._renderer.domElement.style.width="100%",this._renderer.domElement.style.height="100%"}},{key:"start",value:function(){"use strict";function e(n){requestAnimationFrame(e),r._stats&&r._stats.begin(),r._process(t),r.scene.simulate(),r._updateControls(),r._composer?(r._composer.reset(),r._composer.render(r.scene,r._camera),r._composer.pass(r._composer.stack),r._composer.toScreen()):r._renderer.render(r.scene,r._camera),r._loop(n),r._stats&&r._stats.end()}var t=new THREE.Clock,r=this;this._update=e,r._update()}},{key:"_loop",value:function(e){WHS.loops.forEach(function(t){t.enabled&&t.func(e)})}},{key:"_updateControls",value:function(){this.controls&&(this.controls.update(Date.now()-this.time),this.time=Date.now())}},{key:"_process",value:function(e){for(var t=0;t<this.modellingQueue.length;t++)"morph"==this.modellingQueue[t]._type&&this.modellingQueue[t].mesh.mixer.update(e.getDelta())}},{key:"resize",value:function(){this._camera.aspect=window.innerWidth/window.innerHeight,this._camera.updateProjectionMatrix(),this._renderer.setSize(this._settings.rWidth,this._settings.rHeight)}}]),e}(),WHS.Cube=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"cube"));return api.extend(e.geometry,{width:1,height:1,depth:1}),r.mesh=new Physijs.BoxMesh(new THREE.BoxGeometry(e.geometry.width,e.geometry.height,e.geometry.depth),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Cube=function(e){return new WHS.Cube(e).addTo(this)},WHS.Cylinder=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"cylinder"));return api.extend(e.geometry,{radiusTop:1,radiusBottom:1,height:1,radiusSegments:32}),r.mesh=new Physijs.CylinderMesh(new THREE.CylinderGeometry(e.geometry.radiusTop,e.geometry.radiusBottom,e.geometry.height,e.geometry.radiusSegments),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Cylinder=function(e){return new WHS.Cylinder(e).addTo(this)},WHS.Dodecahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"dodecahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.DodecahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Dodecahedron=function(e){return new WHS.Dodecahedron(e).addTo(this)},WHS.Extrude=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"extrude"));return api.extend(e.geometry,{shapes:[],options:{}}),r.mesh=new Physijs.ConvexMesh(new THREE.ExtrudeGeometry(e.geometry.shapes,e.geometry.options),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Extrude=function(e){return new WHS.Extrude(e).addTo(this)},WHS.Icosahderon=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"icosahderon"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.IcosahderonGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Icosahderon=function(e){return new WHS.Icosahderon(e).addTo(this)},WHS.Lathe=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"lathe"));return api.extend(e.geometry,{points:[]}),r.mesh=new Physijs.ConvexMesh(new THREE.LatheGeometry(e.geometry.points),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Lathe=function(e){return new WHS.Lathe(e).addTo(this)},WHS.Model=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"model"));api.extend(e.geometry,{path:""});var n=r,o=_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material);return r._loading=new Promise(function(t,r){api.JSONLoader().load(e.geometry.path,function(r){r.computeFaceNormals(),r.computeVertexNormals(),n.mesh=new Physijs.ConvexMesh(r,o,e.mass),t()})}),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"wait"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Model=function(e){return new WHS.Model(e).addTo(this,"wait")},WHS.Morph=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"morph"));api.extend(e.geometry,{path:""}),console.log(r);var n=r;return r._loading=new Promise(function(t,r){api.JSONLoader().load(e.geometry.path,function(r){var o=new THREE.MeshLambertMaterial({color:16755285,morphTargets:!0,vertexColors:THREE.FaceColors});r.computeFaceNormals(),r.computeVertexNormals(),n.mesh=new THREE.Mesh(r,o),n.mesh.speed=e.morph.speed,n.mesh.mixer=new THREE.AnimationMixer(n.mesh),n.mesh.mixer.addAction(new THREE.AnimationAction(r.animations[0]).warpToDuration(.5)),n.mesh.mixer.update(600*Math.random()),n._rot.y=Math.PI/2,t()})}),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"wait"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Morph=function(e){return new WHS.Morph(e).addTo(this,"wait")},WHS.Octahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"octahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.OctahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Octahedron=function(e){return new WHS.Octahedron(e).addTo(this)},WHS.Parametric=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"parametric"));return api.extend(e.geometry,{func:function(){},slices:10,stacks:10}),r.mesh=new Physijs.ConvexMesh(new THREE.ParametricGeometry(e.geometry.func,e.geometry.slices,e.geometry.stacks),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Parametric=function(e){return new WHS.Parametric(e).addTo(this)},WHS.Plane=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"plane"));return api.extend(e.geometry,{width:10,height:10,segments:32}),r.mesh=new Physijs.ConvexMesh(new THREE.PlaneBufferGeometry(e.geometry.width,e.geometry.height,e.geometry.segments),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Plane=function(e){return new WHS.Plane(e).addTo(this)},WHS.Polyhedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"polyhedron"));return api.extend(e.geometry,{verticesOfCube:[],indicesOfFaces:[],radius:1,detail:1}),r.mesh=new Physijs.ConvexMesh(new THREE.PolyhedronGeometry(e.geometry.verticesOfCube,e.geometry.indicesOfFaces,e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Polyhedron=function(e){return new WHS.Polyhedron(e).addTo(this)},WHS.Ring=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"ring"));return api.extend(e.geometry,{innerRadius:2,outerRadius:5,thetaSegments:30,phiSegments:30,thetaStart:0,thetaLength:2*Math.PI}),r.mesh=new Physijs.ConcaveMesh(new THREE.TorusGeometry(e.geometry.innerRadius,e.geometry.outerRadius,e.geometry.thetaSegments,e.geometry.phiSegments,e.geometry.thetaStart,e.geometry.thetaLength),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Ring=function(e){return new WHS.Ring(e).addTo(this)},WHS.Shape2D=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"shape2D"));return api.extend(e.geometry,{shapes:[]}),r.mesh=new THREE.Mesh(new THREE.ShapeGeometry(e.geometry.shapes),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"onlyvis"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Shape2D=function(e){return new WHS.Shape2D(e).addTo(this)},WHS.Sphere=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"sphere"));return api.extend(e.geometry,{radius:1,segmentA:32,segmentB:32}),r.mesh=new Physijs.SphereMesh(new THREE.SphereGeometry(e.geometry.radius,e.geometry.segmentA,e.geometry.segmentB),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Sphere=function(e){return new WHS.Sphere(e).addTo(this)},WHS.Tetrahedron=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"tetrahedron"));return api.extend(e.geometry,{radius:1,detail:0}),r.mesh=new Physijs.ConvexMesh(new THREE.TetrahedronGeometry(e.geometry.radius,e.geometry.detail),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Tetrahedron=function(e){return new WHS.Tetrahedron(e).addTo(this)},WHS.Text=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"text"));return api.extend(e.geometry,{text:"Hello World!",parameters:{size:1,height:50,curveSegments:1,font:"Adelle",weight:"normal",style:"normal",bevelEnabled:!1,bevelThickness:10,bevelSize:8}}),r.mesh=new Physijs.ConcaveMesh(new THREE.TextGeometry(e.geometry.text,e.geometry.parameters),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Text=function(e){return new WHS.Text(e).addTo(this)},WHS.Torus=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"torus"));return api.extend(e.geometry,{radius:100,tube:40,radialSegments:8,tubularSegments:6,arc:2*Math.PI}),r.mesh=new Physijs.ConvexMesh(new THREE.TorusGeometry(e.geometry.radius,e.geometry.tube,e.geometry.radialSegments,e.geometry.tubularSegments,e.geometry.arc),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Torus=function(e){return new WHS.Torus(e).addTo(this)},WHS.Torusknot=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"Torusknot"));return api.extend(e.geometry,{radius:100,tube:40,radialSegments:64,tubularSegments:8,p:2,q:3,heightScale:1}),r.mesh=new Physijs.ConvexMesh(new THREE.TorusKnotGeometry(e.geometry.radius,e.geometry.tube,e.geometry.radialSegments,e.geometry.tubularSegments,e.geometry.p,e.geometry.q,e.geometry.heightScale),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Torusknot=function(e){return new WHS.Torusknot(e).addTo(this)},WHS.Tube=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"tube"));return api.extend(e.geometry,{path:options.geometryOptions.path?new r.CustomSinCurve(100):!1,segments:20,radius:2,radiusSegments:8,closed:!1}),r.mesh=new Physijs.ConvexMesh(new THREE.TubeGeometry(e.geometry.path,e.geometry.segments,e.geometry.radius,e.geometry.radiusSegments,e.geometry.closed),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),e.mass),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),_createClass(t,[{key:"CustomSinCurve",get:function(){return THREE.Curve.create(function(e){this.scale=e||1},function(e){var t=3*e-1.5,r=Math.sin(2*Math.PI*e),n=0;return new THREE.Vector3(t,r,n).multiplyScalar(this.scale)})}}]),t}(WHS.Shape),WHS.init.prototype.Tube=function(e){return new WHS.Tube(e).addTo(this)},WHS.init.prototype.addGrass=function(e,t){"use strict";var r={};r.root=this,r.opts=t,r.onlyvis=!0,r.opts.coords||console.warn("Please add grass objects coordinates! @addGrass"),r.grassMeshes=[];var n=new THREE.Mesh(new THREE.Geometry,new THREE.MeshFaceMaterial);return r.opts.coords.forEach(function(t){var o=new THREE.Mesh(new THREE.Geometry,new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture("assets/textures/thingrass.png"),side:THREE.DoubleSide,blending:THREE.NormalBlending,transparent:!0,alphaTest:.5})),a=WHS.API.getheight({x:t.x,y:t.y},500,e,-1)[0],i=a.object.geometry.vertices,s=new THREE.Geometry;s.faces.push(new THREE.Face3(0,1,2)),s.vertices.push(i[a.face.a]),s.vertices.push(i[a.face.c]),s.vertices.push(i[a.face.b]),s.computeFaceNormals(),o.position.set(0,0,0),o.geometry.vertices.push(i[a.face.a].clone()),o.geometry.vertices.push(i[a.face.c].clone()),o.geometry.vertices.push(i[a.face.a].clone().add(s.faces[0].normal)),o.geometry.vertices.push(i[a.face.c].clone().add(s.faces[0].normal));var c=new THREE.Vector3(i[a.face.a].clone().x/2+i[a.face.c].clone().x/2,i[a.face.a].clone().y/2+i[a.face.c].clone().y/2,i[a.face.a].clone().z/2+i[a.face.c].clone().z/2);o.geometry.vertices.push(c.clone().add(c.clone().sub(i[a.face.b].clone()))),o.geometry.vertices.push(i[a.face.b].clone()),o.geometry.vertices.push(i[a.face.b].clone().add(s.faces[0].normal)),o.geometry.vertices.push(c.clone().add(c.clone().sub(i[a.face.b].clone())).add(s.faces[0].normal)),o.geometry.faces.push(new THREE.Face3(0,1,2)),o.geometry.faces.push(new THREE.Face3(1,2,3)),o.geometry.faces.push(new THREE.Face3(4,6,5)),o.geometry.faces.push(new THREE.Face3(4,6,7)),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,0),new THREE.Vector2(0,1)]),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(0,1)]),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(1,0)]),o.geometry.faceVertexUvs[0].push([new THREE.Vector2(0,0),new THREE.Vector2(1,1),new THREE.Vector2(0,1)]),o.geometry.uvsNeedUpdate=!0,n.geometry.merge(o.geometry,o.matrix),n.material.materials.push(o.material),r.grassMeshes.push(o)}),r.wrap(n),r.update=function(){},r.update(),r},WHS.Smooth=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"smooth"));return api.extend(e.geometry,{width:10,height:10}),r.mesh=new Physijs.BoxMesh(new THREE.BoxGeometry(e.geometry.width,1,e.geometry.height),_get(Object.getPrototypeOf(t.prototype),"_initMaterial",r).call(r,e.material),0),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Smooth=function(e){return new WHS.Smooth(e).addTo(this)},WHS.Terrain=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"terrain"));api.extend(e.geometry,{width:1,height:1,depth:1,map:!1});var n=document.createElement("canvas");if(n.setAttribute("width",e.geometry.width),n.setAttribute("height",e.geometry.height),n.getContext){var o=n.getContext("2d");o.drawImage(e.geometry.map,0,0)}var a=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/dirt-512.jpg");a.wrapS=a.wrapT=THREE.RepeatWrapping;var i=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/sand-512.jpg");i.wrapS=i.wrapT=THREE.RepeatWrapping;var s=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/grass-512.jpg");s.wrapS=s.wrapT=THREE.RepeatWrapping;var c=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/rock-512.jpg");c.wrapS=c.wrapT=THREE.RepeatWrapping;var l=api.TextureLoader().load(WHS._settings.assets+"/textures/terrain/snow-512.jpg");l.wrapS=l.wrapT=THREE.RepeatWrapping;var h=(THREE.NormalMapShader,256),u=256,p={minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBFormat},d=new THREE.WebGLRenderTarget(h,u,p);d.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/default_terrain.png");var m=new THREE.WebGLRenderTarget(h,u,p);m.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/NormalMap.png");var f=new THREE.WebGLRenderTarget(256,256,p);f.texture=api.TextureLoader().load(WHS._settings.assets+"/terrain/default_terrain.png");var g=THREE.ShaderTerrain.terrain,y=Object.assign(THREE.UniformsUtils.clone(g.uniforms),{oceanTexture:{type:"t",value:a},sandyTexture:{type:"t",value:i},grassTexture:{type:"t",value:s},rockyTexture:{type:"t",value:c},snowyTexture:{type:"t",value:l},fog:!0,lights:!0},THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}});y.tDisplacement.value=d,y.shadowMap.value=[m],y.uDisplacementScale.value=100,y.uRepeatOverlay.value.set(6,6);var E=new THREE.ShaderMaterial({uniforms:y,vertexShader:g.vertexShader,fragmentShader:g.fragmentShader,lights:!0,fog:!0,side:THREE.DoubleSide,shading:THREE.SmoothShading}),v=new THREE.PlaneGeometry(256,256,255,255);v.verticesNeedUpdate=!0,r._rot.set(Math.PI/180*-90,0,0);for(var _=0,H=0,b=o.getImageData(0,0,256,256).data,w=0;255>=w;w++)for(var T=255;T>=0;T--)v.vertices[_].z=b[H]/255*100,H+=4,_++;return r.mesh=new Physijs.HeightfieldMesh(v,Physijs.createMaterial(E,.8,.1)),v.computeVertexNormals(),v.computeFaceNormals(),v.computeTangents(),r.mesh.updateMatrix(),r.mesh.castShadow=!0,r.mesh.receiveShadow=!0,_get(Object.getPrototypeOf(t.prototype),"build",r).call(r,"skip"),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Terrain=function(e){return new WHS.Terrain(e).addTo(this)},WHS.init.prototype.addFog=function(e,t){"use strict";var r={};switch(api.extend(t,{hex:0,near:.015,far:1e3,density:25e-5}),e){case"fog":r=new THREE.Fog(t.hex,t.near,t.far);break;case"fogexp2":r=new THREE.FogExp2(t.hex,t.density)}return r},WHS.AmbientLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"ambientlight"));return r.mesh=new THREE.AmbientLight(e.light.color),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.AmbientLight=function(e){return new WHS.AmbientLight(e).addTo(this)},WHS.DirectionalLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"directionallight"));return r.mesh=new THREE.DirectionalLight(e.light.color,e.light.intensity),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.DirectionalLight=function(e){return new WHS.DirectionalLight(e).addTo(this)},WHS.HemisphereLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"hemispherelight"));return r.mesh=new THREE.HemisphereLight(e.light.skyColor,e.light.groundColor,e.light.intensity),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.HemisphereLight=function(e){return new WHS.HemisphereLight(e).addTo(this)},WHS.NormalLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"normallight"));return r.mesh=new THREE.Light(e.light.color),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.NormalLight=function(e){return new WHS.NormalLight(e).addTo(this)},WHS.PointLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"pointlight"));return r.mesh=new THREE.PointLight(e.light.color,e.light.intensity,e.light.distance),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.PointLight=function(e){return new WHS.PointLight(e).addTo(this)},WHS.SpotLight=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"spotlight"));return r.mesh=new THREE.SpotLight(e.light.color,e.light.intensity,e.light.distance,e.light.angle),_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),_get(Object.getPrototypeOf(t.prototype),"buildShadow",r).call(r),r}return _inherits(t,e),t}(WHS.Light),WHS.init.prototype.SpotLight=function(e){return new WHS.SpotLight(e).addTo(this)};var PI_2=Math.PI/2;WHS.init.prototype.MakeFirstPerson=function(e,t){"use strict";var r=WHS.API.extend(t,{block:document.getElementById("blocker"),speed:1,ypos:1});this.controls=new function(e,t,r){function n(e){if(c.enabled!==!1){var t=e.movementX||e.mozMovementX||e.getMovementX()||0,r=e.movementY||e.mozMovementY||e.getMovementY()||0;u.rotation.y-=.002*t,h.rotation.x-=.002*r,h.rotation.x=Math.max(-PI_2,Math.min(PI_2,h.rotation.x))}}function o(e){switch(e.keyCode){case 38:case 87:d=!0;break;case 37:case 65:f=!0;break;case 40:case 83:m=!0;break;case 39:case 68:g=!0;break;case 32:1==y&&(l.applyCentralImpulse({x:0,y:300,z:0}),console.log(l.applyCentralImpulse)),y=!1;break;case 16:s=.5}}function a(e){switch(e.keyCode){case 38:case 87:d=!1;break;case 37:case 65:f=!1;break;case 40:case 83:m=!1;break;case 39:case 68:g=!1;break;case 16:s=.25}}var i=1,s=.25;t.setAngularFactor({x:0,y:0,z:0});var c=this,l=t,h=new THREE.Object3D;h.add(e);var u=new THREE.Object3D;u.position.y=r.ypos,u.add(h);var p=new THREE.Quaternion,d=!1,m=!1,f=!1,g=!1,y=!1;l.addEventListener("collision",function(e,t,r,n){n.y<.5&&(y=!0)}),document.body.addEventListener("mousemove",n,!1),document.body.addEventListener("keydown",o,!1),document.body.addEventListener("keyup",a,!1),this.enabled=!1,this.getObject=function(){return u},this.getDirection=function(e){e.set(0,0,-1),p.multiplyVector3(e)};var E=new THREE.Vector3,v=new THREE.Euler;this.update=function(e){new THREE.Vector3;if(c.enabled!==!1){e=e||.5,e=Math.min(e,.5),E.set(0,0,0);var t=i*e*r.speed*s;d&&(E.z=-t),m&&(E.z=t),f&&(E.x=-t),g&&(E.x=t),v.x=h.rotation.x,v.y=u.rotation.y,v.order="XYZ",p.setFromEuler(v),E.applyQuaternion(p),l.applyCentralImpulse({x:10*E.x,y:0,z:10*E.z}),l.setAngularVelocity({x:10*E.z,y:0,z:10*-E.x}),l.setAngularFactor({x:0,y:0,z:0}),u.position.copy(l.position)}}}(this._camera,e.mesh,r);var n=this.controls;if(WHS.API.merge(this.scene,this.controls.getObject()),"pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document){var o=document.body;this.pointerlockchange=function(){document.pointerLockElement===o||document.mozPointerLockElement===o||document.webkitPointerLockElement===o?(n.enabled=!0,r.block.fadeOut()):(n.enabled=!1,r.block.fadeIn())}}else console.warn("Your browser does not support the PointerLock API.");document.addEventListener("pointerlockchange",this.pointerlockchange,!1),document.addEventListener("mozpointerlockchange",this.pointerlockchange,!1),document.addEventListener("webkitpointerlockchange",this.pointerlockchange,!1),this.pointerlockerror=function(){console.warn("Pointer lock error.")},document.addEventListener("pointerlockerror",this.pointerlockerror,!1),document.addEventListener("mozpointerlockerror",this.pointerlockerror,!1),document.addEventListener("webkitpointerlockerror",this.pointerlockerror,!1),r.block.addEventListener("click",function(){if(o.requestPointerLock=o.requestPointerLock||o.mozRequestPointerLock||o.webkitRequestPointerLock,o.requestFullscreen=o.requestFullscreen||o.mozRequestFullscreen||o.mozRequestFullScreen||o.webkitRequestFullscreen,/Firefox/i.test(navigator.userAgent)){var e=function t(){(document.fullscreenElement===o||document.mozFullscreenElement===o||document.mozFullScreenElement===o)&&(document.removeEventListener("fullscreenchange",t),document.removeEventListener("mozfullscreenchange",t),o.requestPointerLock())};document.addEventListener("fullscreenchange",e,!1),document.addEventListener("mozfullscreenchange",e,!1),o.requestFullscreen()}else o.requestPointerLock()})},WHS.init.prototype.OrbitControls=function(e){if(this.controls=new THREE.OrbitControls(this._camera,this._renderer.domElement),e)if(e._whsobject){var t=e?e.mesh.position:new THREE.Vector3(0,0,0);this.controls.target=t}else"object"==("undefined"==typeof e?"undefined":_typeof(e))?this.controls.target.copy(t):console.error("Object must be a THREE.JS vector! @OrbitControls")},WHS.Skybox=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e,"skybox"));api.extend(e,{skyType:"box",detail:".png",radius:10,path:""});var n,o;switch(e.skyType){case"box":var a=["xpos","xneg","ypos","yneg","zpos","zneg"];n=new THREE.CubeGeometry(e.radius,e.radius,e.radius);for(var i=[],s=0;6>s;s++)i.push(new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture(e.path+a[s]+e.imgSuffix),side:THREE.BackSide}));o=new THREE.MeshFaceMaterial(i);break;case"sphere":n=new THREE.SphereGeometry(e.radius/2,60,40),o=new THREE.MeshBasicMaterial({map:THREE.ImageUtils.loadTexture(e.path+e.imgSuffix),side:THREE.BackSide})}return r.mesh=new THREE.Mesh(n,o),r.mesh.renderDepth=1e3,_get(Object.getPrototypeOf(t.prototype),"build",r).call(r),r}return _inherits(t,e),t}(WHS.Shape),WHS.init.prototype.Skybox=function(e){
+return new WHS.Skybox(e).addTo(this)};
\ No newline at end of file
diff --git a/examples/basic.html b/examples/basic.html
index 5659878..14199a0 100644
--- a/examples/basic.html
+++ b/examples/basic.html
@@ -24,8 +24,6 @@
     <meta name="msapplication-square150x150logo" content="../development/art/logo/Icon-72@2.png" />
     <script src="../libs/three.js"></script>
     <script src="../libs/physi.js"></script>
-    <script src="../libs/Wagner.js"></script>
-    <script src="../libs/Wagner.base.js"></script>
     <script src="plugins/whs.preload.js"></script>
     <style>
 /* Preloading animation */
@@ -102,10 +100,7 @@
 
 var GAME = new WHS.init({
 
-    anaglyph: false,
-    helper: true,
     stats: "fps", // fps, ms, mb
-    wagner: WAGNER,
     autoresize: true,
 
     gravity: {
diff --git a/examples/basic_material.html b/examples/basic_material.html
index e9d2b9a..ff89b1e 100644
--- a/examples/basic_material.html
+++ b/examples/basic_material.html
@@ -24,8 +24,6 @@
     <meta name="msapplication-square150x150logo" content="../development/art/logo/Icon-72@2.png" />
     <script src="../libs/three.js"></script>
     <script src="../libs/physi.js"></script>
-    <script src="../libs/Wagner.js"></script>
-    <script src="../libs/Wagner.base.js"></script>
 
     <script src="plugins/whs.preload.js"></script>
     <style>
@@ -103,10 +101,7 @@
 
 var GAME = new WHS.init({
     
-    anaglyph: false,
-    helper: true,
     stats: "fps", // fps, ms, mb
-    wagner: WAGNER,
     autoresize: true,
 
     gravity: {
diff --git a/examples/basic_model.html b/examples/basic_model.html
index fe0507f..6c4c882 100644
--- a/examples/basic_model.html
+++ b/examples/basic_model.html
@@ -24,8 +24,6 @@
     <meta name="msapplication-square150x150logo" content="../development/art/logo/Icon-72@2.png" />
     <script src="../libs/three.js"></script>
     <script src="../libs/physi.js"></script>
-    <script src="../libs/Wagner.js"></script>
-    <script src="../libs/Wagner.base.js"></script>
     <script src="plugins/whs.preload.js"></script>
     <style>
 /* Preloading animation */
@@ -102,9 +100,7 @@
 
 var GAME = new WHS.init({
 
-    anaglyph: false,
     stats: "fps", // fps, ms, mb
-    wagner: WAGNER,
     autoresize: true,
 
     gravity: {
diff --git a/examples/fps.html b/examples/fps.html
index 0dcf6dd..41507b1 100644
--- a/examples/fps.html
+++ b/examples/fps.html
@@ -119,6 +119,7 @@
 
   <script src="assets/terrain/default_terrain.js"></script>
   <script src="../build/whitestorm.js" defer></script>
+  <script src="plugins/whs.wagner.js" defer></script>
   <script src="plugins/whs.preload.js" defer></script>
   <script src="js/game.js" defer></script>
 </body>
diff --git a/examples/js/game.js b/examples/js/game.js
index f618e89..e8d2918 100644
--- a/examples/js/game.js
+++ b/examples/js/game.js
@@ -2,10 +2,8 @@ var preloader = Preloader();
 
 // INITIALIZATION SCENE.
 var GAME = new WHS.init( {
-    anaglyph: false,
-    //helper: true,
+    
     stats: "fps", // fps, ms, mb
-    wagner: true,
     autoresize: true,
 
     gravity: {
@@ -183,11 +181,12 @@ GAME.person = GAME.Sphere( {
 
 } );
 
-GAME.initWagner();
-
 // EFFECTS.
-var zoomEffect = GAME.addWagner( "ZoomBlurPass", {} );
-var vignettePass = GAME.addWagner( "VignettePass", {} );
+var effects = GAME.Wagner();
+
+effects.add( "ZoomBlurPass", {} );
+effects.add( "VignettePass", {} );
+
 //var directionalblurEffect = GAME.addWagner( "motionBlurPass", {} ).apply();
 
 GAME.MakeFirstPerson( GAME.person, { // *WHS* object, Pointer lock controls object, Jquery blocker div selector.
diff --git a/examples/plugin_example.html b/examples/plugin_example.html
index 4da55e8..5763b3d 100644
--- a/examples/plugin_example.html
+++ b/examples/plugin_example.html
@@ -24,8 +24,6 @@
   <meta name="msapplication-square150x150logo" content="../development/art/logo/Icon-72@2.png" />
   <script src="../libs/three.js"></script>
   <script src="../libs/physi.js"></script>
-  <script src="../libs/Wagner.js"></script>
-  <script src="../libs/Wagner.base.js"></script>
   <script src="plugins/whs.preload.js"></script>
   <style>
 /* Preloading animation */
@@ -180,9 +178,7 @@
 
 var GAME = new WHS.init({
 
-    anaglyph: false,
     stats: "fps", // fps, ms, mb
-    wagner: WAGNER,
     autoresize: true,
 
     gravity: {
diff --git a/examples/plugins/whs.preload.js b/examples/plugins/whs.preload.js
index 3b3da66..18031d7 100644
--- a/examples/plugins/whs.preload.js
+++ b/examples/plugins/whs.preload.js
@@ -15,7 +15,7 @@ var Preloader = function() {
 
 		done: function() {
 			console.log("Objects loaded!");
-			setTimeout(function() {scope.element.fadeOut("slow")}, 1000);
+			setTimeout(function() { scope.element.fadeOut(1) }, 1000);
 		},
 
 		check: function(...objects) {
diff --git a/examples/plugins/whs.wagner.js b/examples/plugins/whs.wagner.js
new file mode 100644
index 0000000..8befbab
--- /dev/null
+++ b/examples/plugins/whs.wagner.js
@@ -0,0 +1,205 @@
+"use strict";
+
+var _createClass = function() {
+    function defineProperties(target, props) {
+        for (var i = 0; i < props.length; i++) {
+            var descriptor = props[i];
+            descriptor.enumerable = descriptor.enumerable || false;
+            descriptor.configurable = true;
+            if ("value" in descriptor) descriptor.writable = true;
+            Object.defineProperty(target, descriptor.key, descriptor);
+        }
+    }
+    return function(Constructor, protoProps, staticProps) {
+        if (protoProps) defineProperties(Constructor.prototype, protoProps);
+        if (staticProps) defineProperties(Constructor, staticProps);
+        return Constructor;
+    };
+}();
+
+function _classCallCheck(instance, Constructor) {
+    if (!(instance instanceof Constructor)) {
+        throw new TypeError("Cannot call a class as a function");
+    }
+}
+
+/**
+ * © Alexander Buzin, 2014-2015
+ * Site: http://alexbuzin.me/
+ * Email: alexbuzin88@gmail.com
+ */
+
+/**
+ * Wagner.
+ *
+ * @param {Object} type Type of wagner effect. (REQUIRED)
+ * @param {Object} params Parameters. (OPTIONAL)
+ * @return {Object} Scope.
+ */
+
+WHS.Wagner = function() {
+    function Wagner(scope) {
+        _classCallCheck(this, Wagner);
+
+        scope._composer = new WAGNER.Composer(scope._renderer);
+
+        scope._composer.setSize(scope._settings.rWidth, scope._settings.rHeight);
+        scope._composer.autoClearColor = true;
+
+        scope._composer.reset();
+        scope._composer.render(scope.scene, scope._camera);
+
+        scope._composer.stack = new WAGNER.Stack(new WAGNER.ShadersPool());
+
+        this._settings = {
+            composer: scope._composer
+        };
+    }
+
+    _createClass(Wagner, [{
+        key: "add",
+        value: function add(type, params) {
+
+            'use strict';
+
+            var target = api.extend(params, {
+                hex: 0x000000,
+                near: 0.015,
+                far: 1000,
+                density: 0.00025
+            });
+
+            switch (type) {
+                case "ZoomBlurPass":
+
+                    target = api.extend(target, {
+                        strength: .05,
+
+                        center: {
+                            x: .5 * this._settings.composer.width,
+                            y: .5 * this._settings.composer.height
+                        }
+                    });
+
+                    break;
+
+                case "MultiPassBloomPass":
+
+                    target = api.extend(target, {
+                        strength: .5,
+                        blurAmount: 1.32,
+                        applyZoomBlur: true,
+                        zoomBlurStrength: 0.84,
+                        useTexture: true,
+
+                        center: {
+                            x: .5 * this._settings.composer.width,
+                            y: .5 * this._settings.composer.height
+                        }
+                    });
+
+                    break;
+
+                case "VignettePass":
+
+                    target = api.extend(target, {
+                        amount: 0.7,
+                        falloff: 0.2
+                    });
+
+                    break;
+
+                case "DirectionalBlurPass":
+
+                    target = api.extend(target, {
+                        delta: 0.1
+                    });
+
+                    break;
+
+                case "MotionBlurPass":
+
+                    target = api.extend(target, {
+                        delta: 0
+                    });
+
+                    break;
+
+                case "ASCIIPass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                case "DotScreenPass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                case "FxaaPass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                case "ChromaticAberrationPass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                case "DirtPass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                case "EdgeDetectionPass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                case "HighPassPass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                case "GrayscalePass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                case "HalftonePass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                case "InvertPass":
+
+                    // TODO: Params defaults for this effect.
+
+                    break;
+
+                default:
+                    console.warn("No Wagner effect \"" + type + "\" exists. If it should exist, open an issue. (@addWagner)");
+
+                    return;
+            }
+
+            this._settings.composer.stack.addPass(type, true, target);
+
+            return this;
+        }
+    }]);
+
+    return Wagner;
+}();
+
+WHS.init.prototype.Wagner = function() {
+    return new WHS.Wagner(this);
+};
\ No newline at end of file
diff --git a/examples/skybox.html b/examples/skybox.html
index e34c3f9..6fd4091 100644
--- a/examples/skybox.html
+++ b/examples/skybox.html
@@ -24,8 +24,6 @@
     <meta name="msapplication-square150x150logo" content="../development/art/logo/Icon-72@2.png" />
     <script src="../libs/three.js"></script>
     <script src="../libs/physi.js"></script>
-    <script src="../libs/Wagner.js"></script>
-    <script src="../libs/Wagner.base.js"></script>
     <script src="plugins/whs.preload.js"></script>
     <style>
 /* Preloading animation */
@@ -101,10 +99,7 @@
 
 var GAME = new WHS.init({
 
-    anaglyph: false,
-    helper: true,
     stats: "fps", // fps, ms, mb
-    wagner: WAGNER,
     autoresize: true,
 
     gravity: {
diff --git a/examples/stone_wall.html b/examples/stone_wall.html
index 6b972d4..5689fe3 100644
--- a/examples/stone_wall.html
+++ b/examples/stone_wall.html
@@ -24,8 +24,6 @@
     <meta name="msapplication-square150x150logo" content="../development/art/logo/Icon-72@2.png" />
     <script src="../libs/three.js"></script>
     <script src="../libs/physi.js"></script>
-    <script src="../libs/Wagner.js"></script>
-    <script src="../libs/Wagner.base.js"></script>
     <script src="plugins/whs.preload.js"></script>
     <style>
 /* Preloading animation */
@@ -101,11 +99,8 @@
 var preloader = Preloader();
 
 var GAME = new WHS.init({
-
-    anaglyph: false,
-    helper: true,
+    
     stats: "fps", // fps, ms, mb
-    wagner: WAGNER,
     autoresize: true,
 
     gravity: {
diff --git a/gulpfile.js b/gulpfile.js
index 9b45568..32b58fa 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -23,7 +23,6 @@ var sources = [
     'src/Ground/*.js',
     'src/Fog/*.js',
     'src/Light/*.js',
-    'src/Wagner/*.js',
     'src/Controls/*.js',
     'src/GUI/*.js',
     'src/Skybox/*.js'
@@ -43,7 +42,6 @@ var sources_test = [
     'src/Ground/*.js',
     'src/Fog/*.js',
     'src/Light/*.js',
-    'src/Wagner/*.js',
     'src/Controls/*.js',
     'src/GUI/*.js',
     'src/Skybox/*.js'
@@ -60,7 +58,6 @@ var codes = [
     'src/Ground/*.js',
     'src/Fog/*.js',
     'src/Light/*.js',
-    'src/Wagner/*.js',
     'src/Controls/*.js',
     'src/GUI/*.js',
     'src/Skybox/*.js'
diff --git a/src/Core.js b/src/Core.js
index 31deaaf..bcb3deb 100644
--- a/src/Core.js
+++ b/src/Core.js
@@ -12,7 +12,7 @@
  */
 WHS.init = class {
 
-    constructor (params) {
+    constructor( params ) {
 
         'use strict';
 
@@ -22,15 +22,12 @@ WHS.init = class {
             console.warn('whitestormJS requires THREE.js. {Object} THREE not found.');
         if (!Physijs)
             console.warn('whitestormJS requires PHYSI.js. {Object} Physijs not found.');
-        if (!WAGNER)
-            console.warn('whitestormJS requires WAGNER.js. {Object} WAGNER not found.');
 
         var target = api.extend(params, {
 
             anaglyph: false,
             helper: false,
             stats: false,
-            wagner: true,
             autoresize: false,
 
             shadowmap: true,
diff --git a/src/Wagner/AddWagner.js b/src/Wagner/AddWagner.js
deleted file mode 100644
index b7b51cb..0000000
--- a/src/Wagner/AddWagner.js
+++ /dev/null
@@ -1,172 +0,0 @@
-/**
- * © Alexander Buzin, 2014-2015
- * Site: http://alexbuzin.me/
- * Email: alexbuzin88@gmail.com
-*/
-
-/**
- * Wagner.
- *
- * @param {Object} type Type of wagner effect. (REQUIRED)
- * @param {Object} params Parameters. (OPTIONAL)
- * @return {Object} Scope.
- */
-WHS.init.prototype.addWagner = function( type, params ) {
-
-    'use strict';
-
-    params = params || {};
-
-    var scope = {
-        _composer: this._composer
-    };
-
-    var target = api.extend(params, {
-        hex: 0x000000,
-        near: 0.015,
-        far: 1000,
-        density: 0.00025
-    });
-
-    switch (type) {
-        case "ZoomBlurPass":
-            scope.effect = new WAGNER.ZoomBlurPass();
-
-            target = api.extend(target, { 
-                strength: .05,
-
-                center: {
-                    x: .5 * this._composer.width,
-                    y: .5 * this._composer.height
-                }
-            });
-
-            break;
-
-        case "MultiPassBloomPass":
-            scope.effect = new WAGNER.MultiPassBloomPass();
-
-            target = api.extend(target, { 
-                strength: .5,
-                blurAmount: 1.32,
-                applyZoomBlur: true,
-                zoomBlurStrength: 0.84,
-                useTexture: true,
-
-                center: {
-                    x: .5 * this._composer.width,
-                    y: .5 * this._composer.height
-                }
-            });
-
-            scope.effect.glowTexture = WAGNER.Pass.prototype.getOfflineTexture(
-                this._composer.width,
-                this._composer.height,
-                false
-            );
-
-            break;
-
-        case "VignettePass":
-            scope.effect = new WAGNER.VignettePass();
-
-            target = api.extend(target, { 
-                amount: 0.7,
-                falloff: 0.2
-            });
-
-            break;
-
-        case "DirectionalBlurPass":
-            scope.effect = new WAGNER.DirectionalBlurPass();
-
-            target = api.extend(target, { delta: 0.1 });
-
-            break;
-
-        case "MotionBlurPass":
-            scope.effect = new WAGNER.DirectionalBlurPass();
-
-            scope.motionBlurEnable = true;
-
-            target = api.extend(target, { delta: 0 });
-
-            break;
-
-        case "ASCIIPass":
-            scope.effect = new WAGNER.ASCIIPass();
-
-            break;
-
-        case "DotScreenPass":
-            scope.effect = new WAGNER.DotScreenPass();
-
-            break;
-
-        case "FxaaPass":
-            scope.effect = new WAGNER.FXAAPass();
-
-            break;
-
-        case "ChromaticAberrationPass":
-            scope.effect = new WAGNER.ChromaticAberrationPass();
-
-            break;
-
-        case "DirtPass":
-            scope.effect = new WAGNER.DirtPass();
-
-            break;
-
-        case "EdgeDetectionPass":
-            scope.effect = new WAGNER.SobelEdgeDetectionPass();
-
-            break;
-
-        case "HighPassPass":
-            scope.effect = new WAGNER.HighPassPass();
-
-            break;
-            
-        case "GrayscalePass":
-            scope.effect = new WAGNER.GrayscalePass();
-
-            break;
-            
-        case "HalftonePass":
-            scope.effect = new WAGNER.HalftonePass();
-
-            break;
-            
-        case "InvertPass":
-            scope.effect = new WAGNER.InvertPass();
-
-            break;
-
-        default:
-            console.warn("No Wagner effect \"" + type + "\" exists. If it should exist, open an issue. (@addWagner)");
-
-            return;
-    }
-
-    scope.effect.params = target;
-
-    this._composer.stack.addPass(type, true, target);
-
-    return scope;
-    
-}
-
-WHS.init.prototype.initWagner = function() {
-
-    this._composer = new WAGNER.Composer(this._renderer);
-    
-    this._composer.setSize(this._settings.rWidth, this._settings.rHeight);
-    this._composer.autoClearColor = true;
-
-    this._composer.reset();
-    this._composer.render(this.scene, this._camera);
-
-    this._composer.stack = new WAGNER.Stack( new WAGNER.ShadersPool() );
-
-}
diff --git a/src/Wagner/addWagner.js b/src/Wagner/addWagner.js
deleted file mode 100644
index b7b51cb..0000000
--- a/src/Wagner/addWagner.js
+++ /dev/null
@@ -1,172 +0,0 @@
-/**
- * © Alexander Buzin, 2014-2015
- * Site: http://alexbuzin.me/
- * Email: alexbuzin88@gmail.com
-*/
-
-/**
- * Wagner.
- *
- * @param {Object} type Type of wagner effect. (REQUIRED)
- * @param {Object} params Parameters. (OPTIONAL)
- * @return {Object} Scope.
- */
-WHS.init.prototype.addWagner = function( type, params ) {
-
-    'use strict';
-
-    params = params || {};
-
-    var scope = {
-        _composer: this._composer
-    };
-
-    var target = api.extend(params, {
-        hex: 0x000000,
-        near: 0.015,
-        far: 1000,
-        density: 0.00025
-    });
-
-    switch (type) {
-        case "ZoomBlurPass":
-            scope.effect = new WAGNER.ZoomBlurPass();
-
-            target = api.extend(target, { 
-                strength: .05,
-
-                center: {
-                    x: .5 * this._composer.width,
-                    y: .5 * this._composer.height
-                }
-            });
-
-            break;
-
-        case "MultiPassBloomPass":
-            scope.effect = new WAGNER.MultiPassBloomPass();
-
-            target = api.extend(target, { 
-                strength: .5,
-                blurAmount: 1.32,
-                applyZoomBlur: true,
-                zoomBlurStrength: 0.84,
-                useTexture: true,
-
-                center: {
-                    x: .5 * this._composer.width,
-                    y: .5 * this._composer.height
-                }
-            });
-
-            scope.effect.glowTexture = WAGNER.Pass.prototype.getOfflineTexture(
-                this._composer.width,
-                this._composer.height,
-                false
-            );
-
-            break;
-
-        case "VignettePass":
-            scope.effect = new WAGNER.VignettePass();
-
-            target = api.extend(target, { 
-                amount: 0.7,
-                falloff: 0.2
-            });
-
-            break;
-
-        case "DirectionalBlurPass":
-            scope.effect = new WAGNER.DirectionalBlurPass();
-
-            target = api.extend(target, { delta: 0.1 });
-
-            break;
-
-        case "MotionBlurPass":
-            scope.effect = new WAGNER.DirectionalBlurPass();
-
-            scope.motionBlurEnable = true;
-
-            target = api.extend(target, { delta: 0 });
-
-            break;
-
-        case "ASCIIPass":
-            scope.effect = new WAGNER.ASCIIPass();
-
-            break;
-
-        case "DotScreenPass":
-            scope.effect = new WAGNER.DotScreenPass();
-
-            break;
-
-        case "FxaaPass":
-            scope.effect = new WAGNER.FXAAPass();
-
-            break;
-
-        case "ChromaticAberrationPass":
-            scope.effect = new WAGNER.ChromaticAberrationPass();
-
-            break;
-
-        case "DirtPass":
-            scope.effect = new WAGNER.DirtPass();
-
-            break;
-
-        case "EdgeDetectionPass":
-            scope.effect = new WAGNER.SobelEdgeDetectionPass();
-
-            break;
-
-        case "HighPassPass":
-            scope.effect = new WAGNER.HighPassPass();
-
-            break;
-            
-        case "GrayscalePass":
-            scope.effect = new WAGNER.GrayscalePass();
-
-            break;
-            
-        case "HalftonePass":
-            scope.effect = new WAGNER.HalftonePass();
-
-            break;
-            
-        case "InvertPass":
-            scope.effect = new WAGNER.InvertPass();
-
-            break;
-
-        default:
-            console.warn("No Wagner effect \"" + type + "\" exists. If it should exist, open an issue. (@addWagner)");
-
-            return;
-    }
-
-    scope.effect.params = target;
-
-    this._composer.stack.addPass(type, true, target);
-
-    return scope;
-    
-}
-
-WHS.init.prototype.initWagner = function() {
-
-    this._composer = new WAGNER.Composer(this._renderer);
-    
-    this._composer.setSize(this._settings.rWidth, this._settings.rHeight);
-    this._composer.autoClearColor = true;
-
-    this._composer.reset();
-    this._composer.render(this.scene, this._camera);
-
-    this._composer.stack = new WAGNER.Stack( new WAGNER.ShadersPool() );
-
-}
