text: var vg={VERSION:"0.1.1",PI:Math.PI,TAU:2*Math.PI,DEG_TO_RAD:.0174532925,RAD_TO_DEG:57.2957795,SQRT3:Math.sqrt(3),TILE:"tile",ENT:"entity",STR:"structure",HEX:"hex",SQR:"square",ABS:"abstract"};vg.Board=function(t,e){if(!t)throw new Error("You must pass in a grid system for the board to use.");this.tiles=[],this.tileGroup=null,this.group=new THREE.Object3D,this.grid=null,this.overlay=null,this.finder=new vg.AStarFinder(e),vg.Loader.init(),this.setGrid(t)},vg.Board.prototype={setEntityOnTile:function(t,e){var i=this.grid.cellToPixel(e.cell);t.position.copy(i),t.position.y+=t.heightOffset||0,t.tile&&(t.tile.entity=null),t.tile=e,e.entity=t},addTile:function(t){var e=this.tiles.indexOf(t);-1===e&&(this.tiles.push(t),this.snapTileToGrid(t),t.position.y=0,this.tileGroup.add(t.mesh),this.grid.add(t.cell),t.cell.tile=t)},removeTile:function(t){if(t){var e=this.tiles.indexOf(t);this.grid.remove(t.cell),-1!==e&&this.tiles.splice(e,1),t.dispose()}},removeAllTiles:function(){if(this.tileGroup)for(var t=this.tileGroup.children,e=0;e<t.length;e++)this.tileGroup.remove(t[e])},getTileAtCell:function(t){var e=this.grid.cellToHash(t);return t.tile||("undefined"!=typeof this.grid.cells[e]?this.grid.cells[e].tile:null)},snapToGrid:function(t){var e=this.grid.pixelToCell(t);t.copy(this.grid.cellToPixel(e))},snapTileToGrid:function(t){if(t.cell)t.position.copy(this.grid.cellToPixel(t.cell));else{var e=this.grid.pixelToCell(t.position);t.position.copy(this.grid.cellToPixel(e))}return t},getRandomTile:function(){var t=vg.Tools.randomInt(0,this.tiles.length-1);return this.tiles[t]},findPath:function(t,e,i){return this.finder.findPath(t.cell,e.cell,i,this.grid)},setGrid:function(t){this.group.remove(this.tileGroup),this.grid&&t!==this.grid&&(this.removeAllTiles(),this.tiles.forEach(function(t){this.grid.remove(t.cell),t.dispose()}),this.grid.dispose()),this.grid=t,this.tiles=[],this.tileGroup=new THREE.Object3D,this.group.add(this.tileGroup)},generateOverlay:function(t){var e=new THREE.LineBasicMaterial({color:0,opacity:.3});this.overlay&&this.group.remove(this.overlay),this.overlay=new THREE.Object3D,this.grid.generateOverlay(t,this.overlay,e),this.group.add(this.overlay)},generateTilemap:function(t){this.reset();var e=this.grid.generateTiles(t);this.tiles=e,this.tileGroup=new THREE.Object3D;for(var i=0;i<e.length;i++)this.tileGroup.add(e[i].mesh);this.group.add(this.tileGroup)},reset:function(){this.removeAllTiles(),this.tileGroup&&this.group.remove(this.tileGroup)}},vg.Board.prototype.constructor=vg.Board,vg.Cell=function(t,e,i,s){this.q=t||0,this.r=e||0,this.s=i||0,this.h=s||1,this.tile=null,this.userData={},this.walkable=!0,this._calcCost=0,this._priority=0,this._visited=!1,this._parent=null,this.uniqueID=vg.LinkedList.generateID()},vg.Cell.prototype={set:function(t,e,i){return this.q=t,this.r=e,this.s=i,this},copy:function(t){return this.q=t.q,this.r=t.r,this.s=t.s,this.h=t.h,this.tile=t.tile||null,this.userData=t.userData||{},this.walkable=t.walkable,this},add:function(t){return this.q+=t.q,this.r+=t.r,this.s+=t.s,this},equals:function(t){return this.q===t.q&&this.r===t.r&&this.s===t.s}},vg.Cell.prototype.constructor=vg.Cell,vg.SqrGrid=function(t){t=t||{},this.type=vg.SQR,this.size=5,this.cellSize="undefined"==typeof t.cellSize?10:t.cellSize,this.cells={},this.numCells=0,this.extrudeSettings=null,this.autogenerated=!1;var e=[];e.push(new THREE.Vector3),e.push(new THREE.Vector3(-this.cellSize,this.cellSize)),e.push(new THREE.Vector3(this.cellSize,this.cellSize)),e.push(new THREE.Vector3(this.cellSize,-this.cellSize)),this.cellShape=new THREE.Shape,this.cellShape.moveTo(-this.cellSize,-this.cellSize),this.cellShape.lineTo(-this.cellSize,this.cellSize),this.cellShape.lineTo(this.cellSize,this.cellSize),this.cellShape.lineTo(this.cellSize,-this.cellSize),this.cellShape.lineTo(-this.cellSize,-this.cellSize),this.cellGeo=new THREE.Geometry,this.cellGeo.vertices=e,this.cellGeo.verticesNeedUpdate=!0,this.cellShapeGeo=new THREE.ShapeGeometry(this.cellShape),this._fullCellSize=2*this.cellSize,this._hashDelimeter=".",this._directions=[new vg.Cell(1,0,0),new vg.Cell(0,-1,0),new vg.Cell(-1,0,0),new vg.Cell(0,1,0)],this._diagonals=[new vg.Cell(-1,-1,0),new vg.Cell(-1,1,0),new vg.Cell(1,1,0),new vg.Cell(1,-1,0)],this._list=[],this._vec3=new THREE.Vector3,this._cel=new vg.Cell,this._conversionVec=new THREE.Vector3,this._geoCache=[],this._matCache=[]},vg.SqrGrid.prototype={cellToPixel:function(t){return this._vec3.x=t.q*this._fullCellSize,this._vec3.y=t.h,this._vec3.z=t.r*this._fullCellSize,this._vec3},pixelToCell:function(t){var e=Math.round(t.x/this._fullCellSize),i=Math.round(t.z/this._fullCellSize);return this._cel.set(e,i,0)},getCellAt:function(t){var e=Math.round(t.x/this._fullCellSize),i=Math.round(t.z/this._fullCellSize);return this._cel.set(e,i),this.cells[this.cellToHash(this._cel)]},getNeighbors:function(t,e,i){var s,n,r=this._directions.length;for(this._list.length=0,s=0;r>s;s++)this._cel.copy(t),this._cel.add(this._directions[s]),n=this.cells[this.cellToHash(this._cel)],!n||i&&!i(t,n)||this._list.push(n);if(e)for(s=0;r>s;s++)this._cel.copy(t),this._cel.add(this._diagonals[s]),n=this.cells[this.cellToHash(this._cel)],!n||i&&!i(t,n)||this._list.push(n);return this._list},getRandomCell:function(){var t,e=0,i=vg.Tools.randomInt(0,this.numCells);for(t in this.cells){if(e===i)return this.cells[t];e++}return this.cells[t]},cellToHash:function(t){return t.q+this._hashDelimeter+t.r},distance:function(t,e){var i=Math.max(Math.abs(t.q-e.q),Math.abs(t.r-e.r));return i+=e.h-t.h},clearPath:function(){var t,e;for(t in this.cells)e=this.cells[t],e._calcCost=0,e._priority=0,e._parent=null,e._visited=!1},traverse:function(t){var e;for(e in this.cells)t(this.cells[e])},generateTile:function(t,e,i){var s=Math.abs(t.h);1>s&&(s=1);var n=this._geoCache[s];n||(this.extrudeSettings.amount=s,n=new THREE.ExtrudeGeometry(this.cellShape,this.extrudeSettings),this._geoCache[s]=n);var r=new vg.Tile({size:this.cellSize,scale:e,cell:t,geometry:n,material:i});return t.tile=r,r},generateTiles:function(t){t=t||{};var e=[],i={tileScale:.95,cellSize:this.cellSize,material:null,extrudeSettings:{amount:1,bevelEnabled:!0,bevelSegments:1,steps:1,bevelSize:.5,bevelThickness:.5}};i=vg.Tools.merge(i,t),this.cellSize=i.cellSize,this._fullCellSize=2*this.cellSize,this.autogenerated=!0,this.extrudeSettings=i.extrudeSettings;var s,n,r;for(s in this.cells)r=this.cells[s],n=this.generateTile(r,i.tileScale,i.material),n.position.copy(this.cellToPixel(r)),n.position.y=0,e.push(n);return e},generateTilePoly:function(t){t||(t=new THREE.MeshBasicMaterial({color:2405631}));var e=new THREE.Mesh(this.cellShapeGeo,t);return this._vec3.set(1,0,0),e.rotateOnAxis(this._vec3,vg.PI/2),e},generate:function(t){t=t||{},this.size="undefined"==typeof t.size?this.size:t.size;var e,i,s,n=Math.ceil(this.size/2);for(e=-n;n>e;e++)for(i=-n;n>i;i++)s=new vg.Cell(e,i+1),this.add(s)},generateOverlay:function(t,e,i){var s,n,r=Math.ceil(t/2);for(s=-r;r>s;s++)for(n=-r;r>n;n++){this._cel.set(s,n);var o=new THREE.Line(this.cellGeo,i);o.position.copy(this.cellToPixel(this._cel)),o.rotation.x=90*vg.DEG_TO_RAD,e.add(o)}},add:function(t){var e=this.cellToHash(t);if(!this.cells[e])return this.cells[e]=t,this.numCells++,t},remove:function(t){var e=this.cellToHash(t);this.cells[e]&&(delete this.cells[e],this.numCells--)},dispose:function(){this.cells=null,this.numCells=0,this.cellShape=null,this.cellGeo.dispose(),this.cellGeo=null,this.cellShapeGeo.dispose(),this.cellShapeGeo=null,this._list=null,this._vec3=null,this._conversionVec=null,this._geoCache=null,this._matCache=null},load:function(t,e,i){vg.Tools.getJSON({url:t,callback:function(t){this.fromJSON(t),e.call(i||null,t)},cache:!1,scope:this})},fromJSON:function(t){var e,i,s=t.cells;for(this.cells={},this.numCells=0,this.size=t.size,this.cellSize=t.cellSize,this._fullCellSize=2*this.cellSize,this.extrudeSettings=t.extrudeSettings,this.autogenerated=t.autogenerated,e=0;e<s.length;e++)i=new vg.Cell,i.copy(s[e]),this.add(i)},toJSON:function(){var t,e,i={size:this.size,cellSize:this.cellSize,extrudeSettings:this.extrudeSettings,autogenerated:this.autogenerated},s=[];for(e in this.cells)t=this.cells[e],s.push({q:t.q,r:t.r,s:t.s,h:t.h,walkable:t.walkable,userData:t.userData});return i.cells=s,i}},vg.SqrGrid.prototype.constructor=vg.SqrGrid,vg.Tile=function(t){t=t||{};var e={cell:null,geometry:null,material:null};if(e=vg.Tools.merge(e,t),!e.cell||!e.geometry)throw new Error("Missing vg.Tile configuration");this.cell=e.cell,this.cell.tile&&this.cell.tile!==this&&this.cell.tile.dispose(),this.cell.tile=this,this.uniqueID=vg.Tools.generateID(),this.geometry=e.geometry,this.material=e.material,this.material||(this.material=new THREE.MeshPhongMaterial({color:vg.Tools.randomizeRGB("30, 30, 30",13)})),this.objectType=vg.TILE,this.entity=null,this.userData={},this.selected=!1,this.highlight="0x0084cc",this.mesh=new THREE.Mesh(this.geometry,this.material),this.mesh.userData.structure=this,this.position=this.mesh.position,this.rotation=this.mesh.rotation,this.rotation.x=-90*vg.DEG_TO_RAD,this.mesh.scale.set(e.scale,e.scale,1),this.material.emissive?this._emissive=this.material.emissive.getHex():this._emissive=null},vg.Tile.prototype={select:function(){return this.material.emissive&&this.material.emissive.setHex(this.highlight),this.selected=!0,this},deselect:function(){return null!==this._emissive&&this.material.emissive&&this.material.emissive.setHex(this._emissive),this.selected=!1,this},toggle:function(){return this.selected?this.deselect():this.select(),this},dispose:function(){this.cell&&this.cell.tile&&(this.cell.tile=null),this.cell=null,this.position=null,this.rotation=null,this.mesh.parent&&this.mesh.parent.remove(this.mesh),this.mesh.userData.structure=null,this.mesh=null,this.material=null,this.userData=null,this.entity=null,this.geometry=null,this._emissive=null}},vg.Tile.prototype.constructor=vg.Tile,function(){var t=function(){this.obj=null,this.next=null,this.prev=null,this.free=!0},e=function(){this.first=null,this.last=null,this.length=0,this.objToNodeMap={},this.uniqueID=Date.now()+""+Math.floor(1e3*Math.random()),this.sortArray=[]};e.generateID=function(){return Math.random().toString(36).slice(2)+Date.now()},e.prototype={getNode:function(t){return this.objToNodeMap[t.uniqueID]},addNode:function(i){var s=new t;if(!i.uniqueID)try{i.uniqueID=e.generateID()}catch(n){return console.error("[LinkedList.addNode] obj passed is immutable: cannot attach necessary identifier"),null}return s.obj=i,s.free=!1,this.objToNodeMap[i.uniqueID]=s,s},swapObjects:function(t,e){this.objToNodeMap[t.obj.uniqueID]=null,this.objToNodeMap[e.uniqueID]=t,t.obj=e},add:function(t){var e=this.objToNodeMap[t.uniqueID];if(e){if(e.free===!1)return;e.obj=t,e.free=!1,e.next=null,e.prev=null}else e=this.addNode(t);if(this.first){if(!this.last)throw new Error("[LinkedList.add] No last in the list -- that shouldn't happen here");this.last.next=e,e.prev=this.last,this.last=e,e.next=null}else this.first=e,this.last=e,e.next=null,e.prev=null;this.length++,this.showDebug&&this.dump("after add")},has:function(t){return!!this.objToNodeMap[t.uniqueID]},moveUp:function(t){this.dump("before move up");var e=this.getNode(t);if(!e)throw"Oops, trying to move an object that isn't in the list";if(e.prev){var i=e.prev,s=i.prev;e==this.last&&(this.last=i);var n=e.next;s&&(s.next=e),e.next=i,e.prev=i.prev,i.next=n,i.prev=e,this.first==i&&(this.first=e)}},moveDown:function(t){var e=this.getNode(t);if(!e)throw"Oops, trying to move an object that isn't in the list";if(e.next){var i=e.next;this.moveUp(i.obj),this.last==i&&(this.last=e)}},sort:function(t){var e,i,s=this.sortArray,n=this.first;for(s.length=0;n;)s.push(n.obj),n=n.next;for(this.clear(),s.sort(t),i=s.length,e=0;i>e;e++)this.add(s[e])},remove:function(t){var e=this.getNode(t);return!e||e.free?!1:(e.prev&&(e.prev.next=e.next),e.next&&(e.next.prev=e.prev),e.prev||(this.first=e.next),e.next||(this.last=e.prev),e.free=!0,e.prev=null,e.next=null,this.length--,!0)},shift:function(){var t=this.first;return 0===this.length?null:(t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.first=t.next,t.next||(this.last=null),t.free=!0,t.prev=null,t.next=null,this.length--,t.obj)},pop:function(){var t=this.last;return 0===this.length?null:(t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.last=t.prev,t.prev||(this.first=null),t.free=!0,t.prev=null,t.next=null,this.length--,t.obj)},concat:function(t){for(var e=t.first;e;)this.add(e.obj),e=e.next},clear:function(){for(var t=this.first;t;)t.free=!0,t=t.next;this.first=null,this.length=0},dispose:function(){for(var t=this.first;t;)t.obj=null,t=t.next;this.first=null,this.objToNodeMap=null},dump:function(t){console.log("===================="+t+"=====================");for(var e=this.first;e;)console.log("{"+e.obj.toString()+"} previous="+(e.prev?e.prev.obj:"NULL")),e=e.next();console.log("==================================="),console.log("Last: {"+(this.last?this.last.obj:"NULL")+"} First: {"+(this.first?this.first.obj:"NULL")+"}")}},e.prototype.constructor=e,vg.LinkedList=e}(),function(){var t=function(t,e,i,s,n){this._listener=e,this.isOnce=i,this.context=s,this.signal=t,this._priority=n||0};t.prototype={active:!0,params:null,execute:function(t){var e,i;return this.active&&this._listener&&(i=this.params?this.params.concat(t):t,e=this._listener.apply(this.context,i),this.isOnce&&this.detach()),e},detach:function(){return this.isBound()?this.signal.remove(this._listener,this.context):null},isBound:function(){return!!this.signal&&!!this._listener},_destroy:function(){delete this.signal,delete this._listener,delete this.context},toString:function(){return"[SignalBinding isOnce:"+this.isOnce+", isBound:"+this.isBound()+", active:"+this.active+"]"}},t.prototype.constructor=t;var e=function(){this._bindings=[],this._prevParams=null;var t=this;this.dispatch=function(){e.prototype.dispatch.apply(t,arguments)}};e.prototype={memorize:!1,_shouldPropagate:!0,active:!0,validateListener:function(t,e){if("function"!=typeof t)throw new Error("Signal: listener is a required param of {fn}() and should be a Function.".replace("{fn}",e))},_registerListener:function(e,i,s,n){var r,o=this._indexOfListener(e,s);if(-1!==o){if(r=this._bindings[o],r.isOnce!==i)throw new Error("You cannot add"+(i?"":"Once")+"() then add"+(i?"Once":"")+"() the same listener without removing the relationship first.")}else r=new t(this,e,i,s,n),this._addBinding(r);return this.memorize&&this._prevParams&&r.execute(this._prevParams),r},_addBinding:function(t){var e=this._bindings.length;do e--;while(this._bindings[e]&&t._priority<=this._bindings[e]._priority);this._bindings.splice(e+1,0,t)},_indexOfListener:function(t,e){for(var i,s=this._bindings.length;s--;)if(i=this._bindings[s],i._listener===t&&i.context===e)return s;return-1},has:function(t,e){return-1!==this._indexOfListener(t,e)},add:function(t,e,i){return this.validateListener(t,"add"),this._registerListener(t,!1,e,i)},addOnce:function(t,e,i){return this.validateListener(t,"addOnce"),this._registerListener(t,!0,e,i)},remove:function(t,e){this.validateListener(t,"remove");var i=this._indexOfListener(t,e);return-1!==i&&(this._bindings[i]._destroy(),this._bindings.splice(i,1)),t},removeAll:function(t){"undefined"==typeof t&&(t=null);for(var e=this._bindings.length;e--;)t?this._bindings[e].context===t&&(this._bindings[e]._destroy(),this._bindings.splice(e,1)):this._bindings[e]._destroy();t||(this._bindings.length=0)},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},dispatch:function(){if(this.active){var t,e=Array.prototype.slice.call(arguments),i=this._bindings.length;if(this.memorize&&(this._prevParams=e),i){t=this._bindings.slice(),this._shouldPropagate=!0;do i--;while(t[i]&&this._shouldPropagate&&t[i].execute(e)!==!1)}}},forget:function(){this._prevParams=null},dispose:function(){this.removeAll(),delete this._bindings,delete this._prevParams},toString:function(){return"[Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"}},e.prototype.constructor=e,vg.Signal=e}(),vg.AStarFinder=function(t){t=t||{};var e={allowDiagonal:!1,heuristicFilter:null};e=vg.Tools.merge(e,t),this.allowDiagonal=e.allowDiagonal,this.heuristicFilter=e.heuristicFilter,this.list=new vg.LinkedList},vg.AStarFinder.prototype={findPath:function(t,e,i,s){var n,r,o,l,h,a;for(i=i||this.heuristicFilter,s.clearPath(),this.list.clear(),this.list.add(t);this.list.length>0;){if(this.list.sort(this.compare),n=this.list.shift(),n._visited=!0,n===e)return vg.PathUtil.backtrace(e);for(o=s.getNeighbors(n,this.allowDiagonal,i),h=0,a=o.length;a>h;h++)if(l=o[h],l.walkable&&(r=n._calcCost+s.distance(n,l),!l._visited||r<l._calcCost)){if(l._visited=!0,l._parent=n,l._calcCost=r,l._priority=r+s.distance(e,l),l===e)return vg.PathUtil.backtrace(e);this.list.add(l)}}return null},compare:function(t,e){return t._priority-e._priority}},vg.AStarFinder.prototype.constructor=vg.AStarFinder,vg.PathUtil={backtrace:function(t){for(var e=[t];t._parent;)t=t._parent,e.push(t);return e.reverse()},biBacktrace:function(t,e){var i=this.backtrace(t),s=this.backtrace(e);return i.concat(s.reverse())},pathLength:function(t){var e,i,s,n,r,o=0;for(e=1;e<t.length;++e)i=t[e-1],s=t[e],n=i[0]-s[0],r=i[1]-s[1],o+=Math.sqrt(n*n+r*r);return o},interpolate:function(t,e,i,s){var n,r,o,l,h,a,c=Math.abs,u=[];for(o=c(i-t),l=c(s-e),n=i>t?1:-1,r=s>e?1:-1,h=o-l;t!==i||e!==s;)u.push([t,e]),a=2*h,a>-l&&(h-=l,t+=n),o>a&&(h+=o,e+=r);return u},expandPath:function(t){var e,i,s,n,r,o,l=[],h=t.length;if(2>h)return l;for(r=0;h-1>r;++r)for(e=t[r],i=t[r+1],s=this.interpolate(e[0],e[1],i[0],i[1]),n=s.length,o=0;n-1>o;++o)l.push(s[o]);return l.push(t[h-1]),l},smoothenPath:function(t,e){var i,s,n,r,o,l,h,a,c,u,d,g,p=e.length,f=e[0][0],v=e[0][1],m=e[p-1][0],w=e[p-1][1];for(i=f,s=v,o=[[i,s]],h=2;p>h;++h){for(c=e[h],n=c[0],r=c[1],u=this.interpolate(i,s,n,r),g=!1,a=1;a<u.length;++a)if(d=u[a],!t.isWalkableAt(d[0],d[1])){g=!0;break}g&&(l=e[h-1],o.push(l),i=l[0],s=l[1])}return o.push([m,w]),o},compressPath:function(t){if(t.length<3)return t;var e,i,s,n,r,o,l=[],h=t[0][0],a=t[0][1],c=t[1][0],u=t[1][1],d=c-h,g=u-a;for(r=Math.sqrt(d*d+g*g),d/=r,g/=r,l.push([h,a]),o=2;o<t.length;o++)e=c,i=u,s=d,n=g,c=t[o][0],u=t[o][1],d=c-e,g=u-i,r=Math.sqrt(d*d+g*g),d/=r,g/=r,(d!==s||g!==n)&&l.push([e,i]);return l.push([c,u]),l}},vg.Loader={manager:null,imageLoader:null,crossOrigin:!1,init:function(t){this.crossOrigin=t||!1,this.manager=new THREE.LoadingManager(function(){},function(){},function(){console.warn("Error loading images")}),this.imageLoader=new THREE.ImageLoader(this.manager),this.imageLoader.crossOrigin=t},loadTexture:function(t,e,i,s){var n=new THREE.Texture(null,e);return this.imageLoader.load(t,function(t){n.image=t,n.needsUpdate=!0,i&&i(n)},null,function(t){s&&s(t)}),n.sourceFile=t,n}},vg.MouseCaster=function(t,e,i){this.down=!1,this.rightDown=!1,this.pickedObject=null,this.selectedObject=null,this.allHits=null,this.active=!0,this.shift=!1,this.ctrl=!1,this.wheel=0,this.position=new THREE.Vector3,this.screenPosition=new THREE.Vector2,this.signal=new vg.Signal,this.group=t,this._camera=e,this._raycaster=new THREE.Raycaster,this._preventDefault=!1,i=i||document,i.addEventListener("mousemove",this._onDocumentMouseMove.bind(this),!1),i.addEventListener("mousedown",this._onDocumentMouseDown.bind(this),!1),i.addEventListener("mouseup",this._onDocumentMouseUp.bind(this),!1),i.addEventListener("mousewheel",this._onMouseWheel.bind(this),!1),i.addEventListener("DOMMouseScroll",this._onMouseWheel.bind(this),!1)},vg.MouseCaster.OVER="over",vg.MouseCaster.OUT="out",vg.MouseCaster.DOWN="down",vg.MouseCaster.UP="up",vg.MouseCaster.CLICK="click",vg.MouseCaster.WHEEL="wheel",vg.MouseCaster.prototype={update:function(){if(this.active){this._raycaster.setFromCamera(this.screenPosition,this._camera);var t,e,i=this._raycaster.intersectObject(this.group,!0);i.length>0?(t=i[0],e=t.object.userData.structure,this.pickedObject!=e&&(this.pickedObject&&this.signal.dispatch(vg.MouseCaster.OUT,this.pickedObject),this.pickedObject=e,this.selectedObject=null,this.signal.dispatch(vg.MouseCaster.OVER,this.pickedObject)),this.position.copy(t.point),this.screenPosition.z=t.distance):(this.pickedObject&&this.signal.dispatch(vg.MouseCaster.OUT,this.pickedObject),this.pickedObject=null,this.selectedObject=null),this.allHits=i}},preventDefault:function(){this._preventDefault=!0},_onDocumentMouseDown:function(t){return t=t||window.event,t.preventDefault(),this._preventDefault?(this._preventDefault=!1,!1):(this.pickedObject&&(this.selectedObject=this.pickedObject),this.shift=t.shiftKey,this.ctrl=t.ctrlKey,this.down=1===t.which,this.rightDown=3===t.which,void this.signal.dispatch(vg.MouseCaster.DOWN,this.pickedObject))},_onDocumentMouseUp:function(t){return t.preventDefault(),this._preventDefault?(this._preventDefault=!1,!1):(this.shift=t.shiftKey,this.ctrl=t.ctrlKey,this.signal.dispatch(vg.MouseCaster.UP,this.pickedObject),this.selectedObject&&this.pickedObject&&this.selectedObject.uniqueID===this.pickedObject.uniqueID&&this.signal.dispatch(vg.MouseCaster.CLICK,this.pickedObject),this.down=1===t.which?!1:this.down,void(this.rightDown=3===t.which?!1:this.rightDown))},_onDocumentMouseMove:function(t){t.preventDefault(),this.screenPosition.x=t.clientX/window.innerWidth*2-1,this.screenPosition.y=2*-(t.clientY/window.innerHeight)+1},_onMouseWheel:function(t){if(this.active){t.preventDefault(),t.stopPropagation();var e=0;void 0!==t.wheelDelta?e=t.wheelDelta:void 0!==t.detail&&(e=-t.detail),e>0?this.wheel++:this.wheel--,this.signal.dispatch(vg.MouseCaster.WHEEL,this.wheel)}}},vg.MouseCaster.prototype.constructor=vg.MouseCaster,vg.Scene=function(t,e){var i={element:document.body,alpha:!0,antialias:!0,clearColor:"#fff",sortObjects:!1,fog:null,light:new THREE.DirectionalLight(16777215),lightPosition:null,cameraType:"PerspectiveCamera",cameraPosition:null,orthoZoom:4},s={minDistance:100,maxDistance:1e3,zoomSpeed:2,noZoom:!1};if(i=vg.Tools.merge(i,t),"boolean"!=typeof e&&(s=vg.Tools.merge(s,e)),this.renderer=new THREE.WebGLRenderer({alpha:i.alpha,antialias:i.antialias}),this.renderer.setClearColor(i.clearColor,0),this.renderer.sortObjects=i.sortObjects,this.width=window.innerWidth,this.height=window.innerHeight,this.orthoZoom=i.orthoZoom,this.container=new THREE.Scene,this.container.fog=i.fog,this.container.add(new THREE.AmbientLight(14540253)),i.lightPosition||i.light.position.set(-1,1,-1).normalize(),this.container.add(i.light),"OrthographicCamera"===i.cameraType){var n=window.innerWidth/this.orthoZoom,r=window.innerHeight/this.orthoZoom;this.camera=new THREE.OrthographicCamera(n/-2,n/2,r/2,r/-2,1,5e3)}else this.camera=new THREE.PerspectiveCamera(50,this.width/this.height,1,5e3);this.contolled=!!e,this.contolled&&(this.controls=new THREE.OrbitControls(this.camera,this.renderer.domElement),this.controls.minDistance=s.minDistance,this.controls.maxDistance=s.maxDistance,this.controls.zoomSpeed=s.zoomSpeed,this.controls.noZoom=s.noZoom),i.cameraPosition&&this.camera.position.copy(i.cameraPosition),window.addEventListener("resize",function(){if(this.width=window.innerWidth,this.height=window.innerHeight,"OrthographicCamera"===this.camera.type){var t=this.width/this.orthoZoom,e=this.height/this.orthoZoom;this.camera.left=t/-2,this.camera.right=t/2,this.camera.top=e/2,this.camera.bottom=e/-2}else this.camera.aspect=this.width/this.height;this.camera.updateProjectionMatrix(),this.renderer.setSize(this.width,this.height)}.bind(this),!1),this.attachTo(i.element)},vg.Scene.prototype={attachTo:function(t){t.style.width=this.width+"px",t.style.height=this.height+"px",this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(this.width,this.height),t.appendChild(this.renderer.domElement)},add:function(t){this.container.add(t)},remove:function(t){this.container.remove(t)},render:function(){this.contolled&&this.controls.update(),this.renderer.render(this.container,this.camera)},updateOrthoZoom:function(){if(this.orthoZoom<=0)return void(this.orthoZoom=0);var t=this.width/this.orthoZoom,e=this.height/this.orthoZoom;this.camera.left=t/-2,this.camera.right=t/2,this.camera.top=e/2,this.camera.bottom=e/-2,this.camera.updateProjectionMatrix()},focusOn:function(t){this.camera.lookAt(t.position)}},vg.Scene.prototype.constructor=vg.Scene,vg.SelectionManager=function(t){this.mouse=t,this.onSelect=new vg.Signal,this.onDeselect=new vg.Signal,this.selected=null,this.toggleSelection=!1,this.mouse.signal.add(this.onMouse,this)},vg.SelectionManager.prototype={select:function(t,e){t&&(e=e||!0,this.selected!==t&&this.clearSelection(e),t.selected?this.toggleSelection&&(e&&this.onDeselect.dispatch(t),t.deselect()):t.select(),this.selected=t,e&&this.onSelect.dispatch(t))},clearSelection:function(t){t=t||!0,this.selected&&(t&&this.onDeselect.dispatch(this.selected),this.selected.deselect()),this.selected=null},onMouse:function(t,e){switch(t){case vg.MouseCaster.DOWN:e||this.clearSelection();break;case vg.MouseCaster.CLICK:this.select(e)}}},vg.SelectionManager.prototype.constructor=vg.SelectionManager,vg.Tools={clamp:function(t,e,i){return Math.max(e,Math.min(i,t))},sign:function(t){return t&&t/Math.abs(t)},random:function(t,e){return 1===arguments.length?Math.random()*t-.5*t:Math.random()*(e-t)+t},randomInt:function(t,e){return 1===arguments.length?Math.random()*t-.5*t|0:Math.random()*(e-t+1)+t|0},normalize:function(t,e,i){return(t-e)/(i-e)},getShortRotation:function(t){return t%=this.TAU,t>this.PI?t-=this.TAU:t<-this.PI&&(t+=this.TAU),t},generateID:function(){return Math.random().toString(36).slice(2)+Date.now()},isPlainObject:function(t){if("object"!=typeof t||t.nodeType||t===t.window)return!1;try{if(t.constructor&&!Object.prototype.hasOwnProperty.call(t.constructor.prototype,"isPrototypeOf"))return!1}catch(e){return!1}return!0},merge:function(t,e){var i=this,s=Array.isArray(e),n=s&&[]||{};return s?(t=t||[],n=n.concat(t),e.forEach(function(e,s){"undefined"==typeof n[s]?n[s]=e:i.isPlainObject(e)?n[s]=i.merge(t[s],e):-1===t.indexOf(e)&&n.push(e)}),n):(t&&i.isPlainObject(t)&&Object.keys(t).forEach(function(e){n[e]=t[e]}),Object.keys(e).forEach(function(s){e[s]&&i.isPlainObject(e[s])&&t[s]?n[s]=i.merge(t[s],e[s]):n[s]=e[s]}),n)},now:function(){return window.nwf?window.nwf.system.Performance.elapsedTime:window.performance.now()},empty:function(t){for(;t.lastChild;)t.removeChild(t.lastChild)},radixSort:function(t,e,i,s){if(e=e||0,i=i||t.length,s=s||31,!(e>=i-1||0>s)){for(var n=e,r=i,o=1<<s;r>n;)if(t[n]&o){--r;var l=t[n];t[n]=t[r],t[r]=l}else++n;this.radixSort(t,e,r,s-1),this.radixSort(t,r,i,s-1)}},randomizeRGB:function(t,e){var i,s,n=t.split(","),r="rgb(";for(e=this.randomInt(e),i=0;3>i;i++)s=parseInt(n[i])+e,0>s?s=0:s>255&&(s=255),r+=s+",";return r=r.substring(0,r.length-1),r+=")"},getJSON:function(t){var e=new XMLHttpRequest,i="undefined"==typeof t.cache?!1:t.cache,s=i?t.url:t.url+"?t="+Math.floor(1e4*Math.random())+Date.now();e.onreadystatechange=function(){if(200===this.status){var e=null;try{e=JSON.parse(this.responseText)}catch(i){return}return void t.callback.call(t.scope||null,e)}0!==this.status&&console.warn("[Tools.getJSON] Error: "+this.status+" ("+this.statusText+") :: "+t.url)},e.open("GET",s,!0),e.setRequestHeader("Accept","application/json"),e.setRequestHeader("Content-Type","application/json"),e.send("")}};
  //# sourceMappingURL=sqr-grid.min.js.map
  