aframe-extras.primitives.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. require('./src/primitives');
  4. },{"./src/primitives":8}],2:[function(require,module,exports){
  5. "use strict";
  6. module.exports = {
  7. "size": 5,
  8. "cellSize": 10,
  9. "extrudeSettings": {
  10. "amount": 1,
  11. "bevelEnabled": true,
  12. "bevelSegments": 1,
  13. "steps": 1,
  14. "bevelSize": 0.5,
  15. "bevelThickness": 0.5
  16. },
  17. "autogenerated": true,
  18. "cells": [{
  19. "q": -1,
  20. "r": 0,
  21. "s": 1,
  22. "h": 1,
  23. "walkable": true,
  24. "userData": {}
  25. }, {
  26. "q": 0,
  27. "r": -1,
  28. "s": 1,
  29. "h": 1,
  30. "walkable": true,
  31. "userData": {}
  32. }, {
  33. "q": 0,
  34. "r": 0,
  35. "s": 0,
  36. "h": 1,
  37. "walkable": true,
  38. "userData": {}
  39. }, {
  40. "q": 1,
  41. "r": -1,
  42. "s": 0,
  43. "h": 1,
  44. "walkable": true,
  45. "userData": {}
  46. }, {
  47. "q": -1,
  48. "r": 1,
  49. "s": 0,
  50. "h": 0,
  51. "walkable": true,
  52. "userData": {}
  53. }, {
  54. "q": 0,
  55. "r": 1,
  56. "s": -1,
  57. "h": 0,
  58. "walkable": true,
  59. "userData": {}
  60. }, {
  61. "q": 1,
  62. "r": 0,
  63. "s": -1,
  64. "h": 0,
  65. "walkable": true,
  66. "userData": {}
  67. }]
  68. };
  69. },{}],3:[function(require,module,exports){
  70. "use strict";
  71. var _typeof2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  72. var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
  73. return typeof obj === "undefined" ? "undefined" : _typeof2(obj);
  74. } : function (obj) {
  75. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : _typeof2(obj);
  76. };
  77. var vg = module.exports = { 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 (e, t) {
  78. if (!e) 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(t), vg.Loader.init(), this.setGrid(e);
  79. }, vg.Board.prototype = { setEntityOnTile: function setEntityOnTile(e, t) {
  80. var i = this.grid.cellToPixel(t.cell);e.position.copy(i), e.position.y += e.heightOffset || 0, e.tile && (e.tile.entity = null), e.tile = t, t.entity = e;
  81. }, addTile: function addTile(e) {
  82. var t = this.tiles.indexOf(e);-1 === t && (this.tiles.push(e), this.snapTileToGrid(e), e.position.y = 0, this.tileGroup.add(e.mesh), this.grid.add(e.cell), e.cell.tile = e);
  83. }, removeTile: function removeTile(e) {
  84. if (e) {
  85. var t = this.tiles.indexOf(e);this.grid.remove(e.cell), -1 !== t && this.tiles.splice(t, 1), e.dispose();
  86. }
  87. }, removeAllTiles: function removeAllTiles() {
  88. if (this.tileGroup) for (var e = this.tileGroup.children, t = 0; t < e.length; t++) {
  89. this.tileGroup.remove(e[t]);
  90. }
  91. }, getTileAtCell: function getTileAtCell(e) {
  92. var t = this.grid.cellToHash(e);return e.tile || ("undefined" != typeof this.grid.cells[t] ? this.grid.cells[t].tile : null);
  93. }, snapToGrid: function snapToGrid(e) {
  94. var t = this.grid.pixelToCell(e);e.copy(this.grid.cellToPixel(t));
  95. }, snapTileToGrid: function snapTileToGrid(e) {
  96. if (e.cell) e.position.copy(this.grid.cellToPixel(e.cell));else {
  97. var t = this.grid.pixelToCell(e.position);e.position.copy(this.grid.cellToPixel(t));
  98. }return e;
  99. }, getRandomTile: function getRandomTile() {
  100. var e = vg.Tools.randomInt(0, this.tiles.length - 1);return this.tiles[e];
  101. }, findPath: function findPath(e, t, i) {
  102. return this.finder.findPath(e.cell, t.cell, i, this.grid);
  103. }, setGrid: function setGrid(e) {
  104. this.group.remove(this.tileGroup), this.grid && e !== this.grid && (this.removeAllTiles(), this.tiles.forEach(function (e) {
  105. this.grid.remove(e.cell), e.dispose();
  106. }), this.grid.dispose()), this.grid = e, this.tiles = [], this.tileGroup = new THREE.Object3D(), this.group.add(this.tileGroup);
  107. }, generateOverlay: function generateOverlay(e) {
  108. var t = new THREE.LineBasicMaterial({ color: 0, opacity: .3 });this.overlay && this.group.remove(this.overlay), this.overlay = new THREE.Object3D(), this.grid.generateOverlay(e, this.overlay, t), this.group.add(this.overlay);
  109. }, generateTilemap: function generateTilemap(e) {
  110. this.reset();var t = this.grid.generateTiles(e);this.tiles = t, this.tileGroup = new THREE.Object3D();for (var i = 0; i < t.length; i++) {
  111. this.tileGroup.add(t[i].mesh);
  112. }this.group.add(this.tileGroup);
  113. }, reset: function reset() {
  114. this.removeAllTiles(), this.tileGroup && this.group.remove(this.tileGroup);
  115. } }, vg.Board.prototype.constructor = vg.Board, vg.Cell = function (e, t, i, s) {
  116. this.q = e || 0, this.r = t || 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();
  117. }, vg.Cell.prototype = { set: function set(e, t, i) {
  118. return this.q = e, this.r = t, this.s = i, this;
  119. }, copy: function copy(e) {
  120. return this.q = e.q, this.r = e.r, this.s = e.s, this.h = e.h, this.tile = e.tile || null, this.userData = e.userData || {}, this.walkable = e.walkable, this;
  121. }, add: function add(e) {
  122. return this.q += e.q, this.r += e.r, this.s += e.s, this;
  123. }, equals: function equals(e) {
  124. return this.q === e.q && this.r === e.r && this.s === e.s;
  125. } }, vg.Cell.prototype.constructor = vg.Cell, vg.HexGrid = function (e) {
  126. e = e || {}, this.type = vg.HEX, this.size = 5, this.cellSize = "undefined" == typeof e.cellSize ? 10 : e.cellSize, this.cells = {}, this.numCells = 0, this.extrudeSettings = null, this.autogenerated = !1;var t,
  127. i = [];for (t = 0; 6 > t; t++) {
  128. i.push(this._createVertex(t));
  129. }for (this.cellShape = new THREE.Shape(), this.cellShape.moveTo(i[0].x, i[0].y), t = 1; 6 > t; t++) {
  130. this.cellShape.lineTo(i[t].x, i[t].y);
  131. }this.cellShape.lineTo(i[0].x, i[0].y), this.cellShape.autoClose = !0, this.cellGeo = new THREE.Geometry(), this.cellGeo.vertices = i, this.cellGeo.verticesNeedUpdate = !0, this.cellShapeGeo = new THREE.ShapeGeometry(this.cellShape), this._cellWidth = 2 * this.cellSize, this._cellLength = .5 * vg.SQRT3 * this._cellWidth, this._hashDelimeter = ".", this._directions = [new vg.Cell(1, -1, 0), new vg.Cell(1, 0, -1), new vg.Cell(0, 1, -1), new vg.Cell(-1, 1, 0), new vg.Cell(-1, 0, 1), new vg.Cell(0, -1, 1)], this._diagonals = [new vg.Cell(2, -1, -1), new vg.Cell(1, 1, -2), new vg.Cell(-1, 2, -1), new vg.Cell(-2, 1, 1), new vg.Cell(-1, -1, 2), new vg.Cell(1, -2, 1)], this._list = [], this._vec3 = new THREE.Vector3(), this._cel = new vg.Cell(), this._conversionVec = new THREE.Vector3(), this._geoCache = [], this._matCache = [];
  132. }, vg.HexGrid.TWO_THIRDS = 2 / 3, vg.HexGrid.prototype = { cellToPixel: function cellToPixel(e) {
  133. return this._vec3.x = e.q * this._cellWidth * .75, this._vec3.y = e.h, this._vec3.z = -((e.s - e.r) * this._cellLength * .5), this._vec3;
  134. }, pixelToCell: function pixelToCell(e) {
  135. var t = e.x * (vg.HexGrid.TWO_THIRDS / this.cellSize),
  136. i = (-e.x / 3 + vg.SQRT3 / 3 * e.z) / this.cellSize;return this._cel.set(t, i, -t - i), this._cubeRound(this._cel);
  137. }, getCellAt: function getCellAt(e) {
  138. var t = e.x * (vg.HexGrid.TWO_THIRDS / this.cellSize),
  139. i = (-e.x / 3 + vg.SQRT3 / 3 * e.z) / this.cellSize;return this._cel.set(t, i, -t - i), this._cubeRound(this._cel), this.cells[this.cellToHash(this._cel)];
  140. }, getNeighbors: function getNeighbors(e, t, i) {
  141. var s,
  142. n,
  143. l = this._directions.length;for (this._list.length = 0, s = 0; l > s; s++) {
  144. this._cel.copy(e), this._cel.add(this._directions[s]), n = this.cells[this.cellToHash(this._cel)], !n || i && !i(e, n) || this._list.push(n);
  145. }if (t) for (s = 0; l > s; s++) {
  146. this._cel.copy(e), this._cel.add(this._diagonals[s]), n = this.cells[this.cellToHash(this._cel)], !n || i && !i(e, n) || this._list.push(n);
  147. }return this._list;
  148. }, getRandomCell: function getRandomCell() {
  149. var e,
  150. t = 0,
  151. i = vg.Tools.randomInt(0, this.numCells);for (e in this.cells) {
  152. if (t === i) return this.cells[e];t++;
  153. }return this.cells[e];
  154. }, cellToHash: function cellToHash(e) {
  155. return e.q + this._hashDelimeter + e.r + this._hashDelimeter + e.s;
  156. }, distance: function distance(e, t) {
  157. var i = Math.max(Math.abs(e.q - t.q), Math.abs(e.r - t.r), Math.abs(e.s - t.s));return i += t.h - e.h;
  158. }, clearPath: function clearPath() {
  159. var e, t;for (e in this.cells) {
  160. t = this.cells[e], t._calcCost = 0, t._priority = 0, t._parent = null, t._visited = !1;
  161. }
  162. }, traverse: function traverse(e) {
  163. var t;for (t in this.cells) {
  164. e(this.cells[t]);
  165. }
  166. }, generateTile: function generateTile(e, t, i) {
  167. var s = Math.abs(e.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 l = new vg.Tile({ size: this.cellSize, scale: t, cell: e, geometry: n, material: i });return e.tile = l, l;
  168. }, generateTiles: function generateTiles(e) {
  169. e = e || {};var t = [],
  170. 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, e), this.cellSize = i.cellSize, this._cellWidth = 2 * this.cellSize, this._cellLength = .5 * vg.SQRT3 * this._cellWidth, this.autogenerated = !0, this.extrudeSettings = i.extrudeSettings;var s, n, l;for (s in this.cells) {
  171. l = this.cells[s], n = this.generateTile(l, i.tileScale, i.material), n.position.copy(this.cellToPixel(l)), n.position.y = 0, t.push(n);
  172. }return t;
  173. }, generateTilePoly: function generateTilePoly(e) {
  174. e || (e = new THREE.MeshBasicMaterial({ color: 2405631 }));var t = new THREE.Mesh(this.cellShapeGeo, e);return this._vec3.set(1, 0, 0), t.rotateOnAxis(this._vec3, vg.PI / 2), t;
  175. }, generate: function generate(e) {
  176. e = e || {}, this.size = "undefined" == typeof e.size ? this.size : e.size;var t, i, s, n;for (t = -this.size; t < this.size + 1; t++) {
  177. for (i = -this.size; i < this.size + 1; i++) {
  178. s = -t - i, Math.abs(t) <= this.size && Math.abs(i) <= this.size && Math.abs(s) <= this.size && (n = new vg.Cell(t, i, s), this.add(n));
  179. }
  180. }
  181. }, generateOverlay: function generateOverlay(e, t, i) {
  182. var s,
  183. n,
  184. l,
  185. r = this.cellShape.createPointsGeometry();for (s = -e; e + 1 > s; s++) {
  186. for (n = -e; e + 1 > n; n++) {
  187. if (l = -s - n, Math.abs(s) <= e && Math.abs(n) <= e && Math.abs(l) <= e) {
  188. this._cel.set(s, n, l);var h = new THREE.Line(r, i);h.position.copy(this.cellToPixel(this._cel)), h.rotation.x = 90 * vg.DEG_TO_RAD, t.add(h);
  189. }
  190. }
  191. }
  192. }, add: function add(e) {
  193. var t = this.cellToHash(e);if (!this.cells[t]) return this.cells[t] = e, this.numCells++, e;
  194. }, remove: function remove(e) {
  195. var t = this.cellToHash(e);this.cells[t] && (delete this.cells[t], this.numCells--);
  196. }, dispose: function dispose() {
  197. 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;
  198. }, load: function load(e, t, i) {
  199. var s = this;vg.Tools.getJSON({ url: e, callback: function callback(e) {
  200. s.fromJSON(e), t.call(i || null, e);
  201. }, cache: !1, scope: s });
  202. }, fromJSON: function fromJSON(e) {
  203. var t,
  204. i,
  205. s = e.cells;for (this.cells = {}, this.numCells = 0, this.size = e.size, this.cellSize = e.cellSize, this._cellWidth = 2 * this.cellSize, this._cellLength = .5 * vg.SQRT3 * this._cellWidth, this.extrudeSettings = e.extrudeSettings, this.autogenerated = e.autogenerated, t = 0; t < s.length; t++) {
  206. i = new vg.Cell(), i.copy(s[t]), this.add(i);
  207. }
  208. }, toJSON: function toJSON() {
  209. var e,
  210. t,
  211. i = { size: this.size, cellSize: this.cellSize, extrudeSettings: this.extrudeSettings, autogenerated: this.autogenerated },
  212. s = [];for (t in this.cells) {
  213. e = this.cells[t], s.push({ q: e.q, r: e.r, s: e.s, h: e.h, walkable: e.walkable, userData: e.userData });
  214. }return i.cells = s, i;
  215. }, _createVertex: function _createVertex(e) {
  216. var t = vg.TAU / 6 * e;return new THREE.Vector3(this.cellSize * Math.cos(t), this.cellSize * Math.sin(t), 0);
  217. }, _cubeRound: function _cubeRound(e) {
  218. var t = Math.round(e.q),
  219. i = Math.round(e.r),
  220. s = Math.round(e.s),
  221. n = Math.abs(t - e.q),
  222. l = Math.abs(i - e.r),
  223. r = Math.abs(s - e.s);return n > l && n > r ? t = -i - s : l > r ? i = -t - s : s = -t - i, this._cel.set(t, i, s);
  224. } }, vg.HexGrid.prototype.constructor = vg.HexGrid, vg.SqrGrid = function (e) {
  225. e = e || {}, this.type = vg.SQR, this.size = 5, this.cellSize = "undefined" == typeof e.cellSize ? 10 : e.cellSize, this.cells = {}, this.numCells = 0, this.extrudeSettings = null, this.autogenerated = !1;var t = [];t.push(new THREE.Vector3()), t.push(new THREE.Vector3(-this.cellSize, this.cellSize)), t.push(new THREE.Vector3(this.cellSize, this.cellSize)), t.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 = t, 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 = [];
  226. }, vg.SqrGrid.prototype = { cellToPixel: function cellToPixel(e) {
  227. return this._vec3.x = e.q * this._fullCellSize, this._vec3.y = e.h, this._vec3.z = e.r * this._fullCellSize, this._vec3;
  228. }, pixelToCell: function pixelToCell(e) {
  229. var t = Math.round(e.x / this._fullCellSize),
  230. i = Math.round(e.z / this._fullCellSize);return this._cel.set(t, i, 0);
  231. }, getCellAt: function getCellAt(e) {
  232. var t = Math.round(e.x / this._fullCellSize),
  233. i = Math.round(e.z / this._fullCellSize);return this._cel.set(t, i), this.cells[this.cellToHash(this._cel)];
  234. }, getNeighbors: function getNeighbors(e, t, i) {
  235. var s,
  236. n,
  237. l = this._directions.length;for (this._list.length = 0, s = 0; l > s; s++) {
  238. this._cel.copy(e), this._cel.add(this._directions[s]), n = this.cells[this.cellToHash(this._cel)], !n || i && !i(e, n) || this._list.push(n);
  239. }if (t) for (s = 0; l > s; s++) {
  240. this._cel.copy(e), this._cel.add(this._diagonals[s]), n = this.cells[this.cellToHash(this._cel)], !n || i && !i(e, n) || this._list.push(n);
  241. }return this._list;
  242. }, getRandomCell: function getRandomCell() {
  243. var e,
  244. t = 0,
  245. i = vg.Tools.randomInt(0, this.numCells);for (e in this.cells) {
  246. if (t === i) return this.cells[e];t++;
  247. }return this.cells[e];
  248. }, cellToHash: function cellToHash(e) {
  249. return e.q + this._hashDelimeter + e.r;
  250. }, distance: function distance(e, t) {
  251. var i = Math.max(Math.abs(e.q - t.q), Math.abs(e.r - t.r));return i += t.h - e.h;
  252. }, clearPath: function clearPath() {
  253. var e, t;for (e in this.cells) {
  254. t = this.cells[e], t._calcCost = 0, t._priority = 0, t._parent = null, t._visited = !1;
  255. }
  256. }, traverse: function traverse(e) {
  257. var t;for (t in this.cells) {
  258. e(this.cells[t]);
  259. }
  260. }, generateTile: function generateTile(e, t, i) {
  261. var s = Math.abs(e.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 l = new vg.Tile({ size: this.cellSize, scale: t, cell: e, geometry: n, material: i });return e.tile = l, l;
  262. }, generateTiles: function generateTiles(e) {
  263. e = e || {};var t = [],
  264. 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, e), this.cellSize = i.cellSize, this._fullCellSize = 2 * this.cellSize, this.autogenerated = !0, this.extrudeSettings = i.extrudeSettings;var s, n, l;for (s in this.cells) {
  265. l = this.cells[s], n = this.generateTile(l, i.tileScale, i.material), n.position.copy(this.cellToPixel(l)), n.position.y = 0, t.push(n);
  266. }return t;
  267. }, generateTilePoly: function generateTilePoly(e) {
  268. e || (e = new THREE.MeshBasicMaterial({ color: 2405631 }));var t = new THREE.Mesh(this.cellShapeGeo, e);return this._vec3.set(1, 0, 0), t.rotateOnAxis(this._vec3, vg.PI / 2), t;
  269. }, generate: function generate(e) {
  270. e = e || {}, this.size = "undefined" == typeof e.size ? this.size : e.size;var t,
  271. i,
  272. s,
  273. n = Math.ceil(this.size / 2);for (t = -n; n > t; t++) {
  274. for (i = -n; n > i; i++) {
  275. s = new vg.Cell(t, i + 1), this.add(s);
  276. }
  277. }
  278. }, generateOverlay: function generateOverlay(e, t, i) {
  279. var s,
  280. n,
  281. l = Math.ceil(e / 2);for (s = -l; l > s; s++) {
  282. for (n = -l; l > n; n++) {
  283. this._cel.set(s, n);var r = new THREE.Line(this.cellGeo, i);r.position.copy(this.cellToPixel(this._cel)), r.rotation.x = 90 * vg.DEG_TO_RAD, t.add(r);
  284. }
  285. }
  286. }, add: function add(e) {
  287. var t = this.cellToHash(e);if (!this.cells[t]) return this.cells[t] = e, this.numCells++, e;
  288. }, remove: function remove(e) {
  289. var t = this.cellToHash(e);this.cells[t] && (delete this.cells[t], this.numCells--);
  290. }, dispose: function dispose() {
  291. 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;
  292. }, load: function load(e, t, i) {
  293. vg.Tools.getJSON({ url: e, callback: function callback(e) {
  294. this.fromJSON(e), t.call(i || null, e);
  295. }, cache: !1, scope: this });
  296. }, fromJSON: function fromJSON(e) {
  297. var t,
  298. i,
  299. s = e.cells;for (this.cells = {}, this.numCells = 0, this.size = e.size, this.cellSize = e.cellSize, this._fullCellSize = 2 * this.cellSize, this.extrudeSettings = e.extrudeSettings, this.autogenerated = e.autogenerated, t = 0; t < s.length; t++) {
  300. i = new vg.Cell(), i.copy(s[t]), this.add(i);
  301. }
  302. }, toJSON: function toJSON() {
  303. var e,
  304. t,
  305. i = { size: this.size, cellSize: this.cellSize, extrudeSettings: this.extrudeSettings, autogenerated: this.autogenerated },
  306. s = [];for (t in this.cells) {
  307. e = this.cells[t], s.push({ q: e.q, r: e.r, s: e.s, h: e.h, walkable: e.walkable, userData: e.userData });
  308. }return i.cells = s, i;
  309. } }, vg.SqrGrid.prototype.constructor = vg.SqrGrid, vg.Tile = function (e) {
  310. e = e || {};var t = { cell: null, geometry: null, material: null };if (t = vg.Tools.merge(t, e), !t.cell || !t.geometry) throw new Error("Missing vg.Tile configuration");this.cell = t.cell, this.cell.tile && this.cell.tile !== this && this.cell.tile.dispose(), this.cell.tile = this, this.uniqueID = vg.Tools.generateID(), this.geometry = t.geometry, this.material = t.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(t.scale, t.scale, 1), this.material.emissive ? this._emissive = this.material.emissive.getHex() : this._emissive = null;
  311. }, vg.Tile.prototype = { select: function select() {
  312. return this.material.emissive && this.material.emissive.setHex(this.highlight), this.selected = !0, this;
  313. }, deselect: function deselect() {
  314. return null !== this._emissive && this.material.emissive && this.material.emissive.setHex(this._emissive), this.selected = !1, this;
  315. }, toggle: function toggle() {
  316. return this.selected ? this.deselect() : this.select(), this;
  317. }, dispose: function dispose() {
  318. 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;
  319. } }, vg.Tile.prototype.constructor = vg.Tile, function () {
  320. var e = function e() {
  321. this.obj = null, this.next = null, this.prev = null, this.free = !0;
  322. },
  323. t = function t() {
  324. this.first = null, this.last = null, this.length = 0, this.objToNodeMap = {}, this.uniqueID = Date.now() + "" + Math.floor(1e3 * Math.random()), this.sortArray = [];
  325. };t.generateID = function () {
  326. return Math.random().toString(36).slice(2) + Date.now();
  327. }, t.prototype = { getNode: function getNode(e) {
  328. return this.objToNodeMap[e.uniqueID];
  329. }, addNode: function addNode(i) {
  330. var s = new e();if (!i.uniqueID) try {
  331. i.uniqueID = t.generateID();
  332. } catch (n) {
  333. return console.error("[LinkedList.addNode] obj passed is immutable: cannot attach necessary identifier"), null;
  334. }return s.obj = i, s.free = !1, this.objToNodeMap[i.uniqueID] = s, s;
  335. }, swapObjects: function swapObjects(e, t) {
  336. this.objToNodeMap[e.obj.uniqueID] = null, this.objToNodeMap[t.uniqueID] = e, e.obj = t;
  337. }, add: function add(e) {
  338. var t = this.objToNodeMap[e.uniqueID];if (t) {
  339. if (t.free === !1) return;t.obj = e, t.free = !1, t.next = null, t.prev = null;
  340. } else t = this.addNode(e);if (this.first) {
  341. if (!this.last) throw new Error("[LinkedList.add] No last in the list -- that shouldn't happen here");this.last.next = t, t.prev = this.last, this.last = t, t.next = null;
  342. } else this.first = t, this.last = t, t.next = null, t.prev = null;this.length++, this.showDebug && this.dump("after add");
  343. }, has: function has(e) {
  344. return !!this.objToNodeMap[e.uniqueID];
  345. }, moveUp: function moveUp(e) {
  346. this.dump("before move up");var t = this.getNode(e);if (!t) throw "Oops, trying to move an object that isn't in the list";if (t.prev) {
  347. var i = t.prev,
  348. s = i.prev;t == this.last && (this.last = i);var n = t.next;s && (s.next = t), t.next = i, t.prev = i.prev, i.next = n, i.prev = t, this.first == i && (this.first = t);
  349. }
  350. }, moveDown: function moveDown(e) {
  351. var t = this.getNode(e);if (!t) throw "Oops, trying to move an object that isn't in the list";if (t.next) {
  352. var i = t.next;this.moveUp(i.obj), this.last == i && (this.last = t);
  353. }
  354. }, sort: function sort(e) {
  355. var t,
  356. i,
  357. s = this.sortArray,
  358. n = this.first;for (s.length = 0; n;) {
  359. s.push(n.obj), n = n.next;
  360. }for (this.clear(), s.sort(e), i = s.length, t = 0; i > t; t++) {
  361. this.add(s[t]);
  362. }
  363. }, remove: function remove(e) {
  364. var t = this.getNode(e);return !t || t.free ? !1 : (t.prev && (t.prev.next = t.next), t.next && (t.next.prev = t.prev), t.prev || (this.first = t.next), t.next || (this.last = t.prev), t.free = !0, t.prev = null, t.next = null, this.length--, !0);
  365. }, shift: function shift() {
  366. var e = this.first;return 0 === this.length ? null : (e.prev && (e.prev.next = e.next), e.next && (e.next.prev = e.prev), this.first = e.next, e.next || (this.last = null), e.free = !0, e.prev = null, e.next = null, this.length--, e.obj);
  367. }, pop: function pop() {
  368. var e = this.last;return 0 === this.length ? null : (e.prev && (e.prev.next = e.next), e.next && (e.next.prev = e.prev), this.last = e.prev, e.prev || (this.first = null), e.free = !0, e.prev = null, e.next = null, this.length--, e.obj);
  369. }, concat: function concat(e) {
  370. for (var t = e.first; t;) {
  371. this.add(t.obj), t = t.next;
  372. }
  373. }, clear: function clear() {
  374. for (var e = this.first; e;) {
  375. e.free = !0, e = e.next;
  376. }this.first = null, this.length = 0;
  377. }, dispose: function dispose() {
  378. for (var e = this.first; e;) {
  379. e.obj = null, e = e.next;
  380. }this.first = null, this.objToNodeMap = null;
  381. }, dump: function dump(e) {
  382. console.log("====================" + e + "=====================");for (var t = this.first; t;) {
  383. console.log("{" + t.obj.toString() + "} previous=" + (t.prev ? t.prev.obj : "NULL")), t = t.next();
  384. }console.log("==================================="), console.log("Last: {" + (this.last ? this.last.obj : "NULL") + "} First: {" + (this.first ? this.first.obj : "NULL") + "}");
  385. } }, t.prototype.constructor = t, vg.LinkedList = t;
  386. }(), function () {
  387. var e = function e(_e, t, i, s, n) {
  388. this._listener = t, this.isOnce = i, this.context = s, this.signal = _e, this._priority = n || 0;
  389. };e.prototype = { active: !0, params: null, execute: function execute(e) {
  390. var t, i;return this.active && this._listener && (i = this.params ? this.params.concat(e) : e, t = this._listener.apply(this.context, i), this.isOnce && this.detach()), t;
  391. }, detach: function detach() {
  392. return this.isBound() ? this.signal.remove(this._listener, this.context) : null;
  393. }, isBound: function isBound() {
  394. return !!this.signal && !!this._listener;
  395. }, _destroy: function _destroy() {
  396. delete this.signal, delete this._listener, delete this.context;
  397. }, toString: function toString() {
  398. return "[SignalBinding isOnce:" + this.isOnce + ", isBound:" + this.isBound() + ", active:" + this.active + "]";
  399. } }, e.prototype.constructor = e;var t = function t() {
  400. this._bindings = [], this._prevParams = null;var e = this;this.dispatch = function () {
  401. t.prototype.dispatch.apply(e, arguments);
  402. };
  403. };t.prototype = { memorize: !1, _shouldPropagate: !0, active: !0, validateListener: function validateListener(e, t) {
  404. if ("function" != typeof e) throw new Error("Signal: listener is a required param of {fn}() and should be a Function.".replace("{fn}", t));
  405. }, _registerListener: function _registerListener(t, i, s, n) {
  406. var l,
  407. r = this._indexOfListener(t, s);if (-1 !== r) {
  408. if (l = this._bindings[r], l.isOnce !== i) throw new Error("You cannot add" + (i ? "" : "Once") + "() then add" + (i ? "Once" : "") + "() the same listener without removing the relationship first.");
  409. } else l = new e(this, t, i, s, n), this._addBinding(l);return this.memorize && this._prevParams && l.execute(this._prevParams), l;
  410. }, _addBinding: function _addBinding(e) {
  411. var t = this._bindings.length;do {
  412. t--;
  413. } while (this._bindings[t] && e._priority <= this._bindings[t]._priority);this._bindings.splice(t + 1, 0, e);
  414. }, _indexOfListener: function _indexOfListener(e, t) {
  415. for (var i, s = this._bindings.length; s--;) {
  416. if (i = this._bindings[s], i._listener === e && i.context === t) return s;
  417. }return -1;
  418. }, has: function has(e, t) {
  419. return -1 !== this._indexOfListener(e, t);
  420. }, add: function add(e, t, i) {
  421. return this.validateListener(e, "add"), this._registerListener(e, !1, t, i);
  422. }, addOnce: function addOnce(e, t, i) {
  423. return this.validateListener(e, "addOnce"), this._registerListener(e, !0, t, i);
  424. }, remove: function remove(e, t) {
  425. this.validateListener(e, "remove");var i = this._indexOfListener(e, t);return -1 !== i && (this._bindings[i]._destroy(), this._bindings.splice(i, 1)), e;
  426. }, removeAll: function removeAll(e) {
  427. "undefined" == typeof e && (e = null);for (var t = this._bindings.length; t--;) {
  428. e ? this._bindings[t].context === e && (this._bindings[t]._destroy(), this._bindings.splice(t, 1)) : this._bindings[t]._destroy();
  429. }e || (this._bindings.length = 0);
  430. }, getNumListeners: function getNumListeners() {
  431. return this._bindings.length;
  432. }, halt: function halt() {
  433. this._shouldPropagate = !1;
  434. }, dispatch: function dispatch() {
  435. if (this.active) {
  436. var e,
  437. t = Array.prototype.slice.call(arguments),
  438. i = this._bindings.length;if (this.memorize && (this._prevParams = t), i) {
  439. e = this._bindings.slice(), this._shouldPropagate = !0;do {
  440. i--;
  441. } while (e[i] && this._shouldPropagate && e[i].execute(t) !== !1);
  442. }
  443. }
  444. }, forget: function forget() {
  445. this._prevParams = null;
  446. }, dispose: function dispose() {
  447. this.removeAll(), delete this._bindings, delete this._prevParams;
  448. }, toString: function toString() {
  449. return "[Signal active:" + this.active + " numListeners:" + this.getNumListeners() + "]";
  450. } }, t.prototype.constructor = t, vg.Signal = t;
  451. }(), vg.AStarFinder = function (e) {
  452. e = e || {};var t = { allowDiagonal: !1, heuristicFilter: null };t = vg.Tools.merge(t, e), this.allowDiagonal = t.allowDiagonal, this.heuristicFilter = t.heuristicFilter, this.list = new vg.LinkedList();
  453. }, vg.AStarFinder.prototype = { findPath: function findPath(e, t, i, s) {
  454. var n, l, r, h, o, a;for (i = i || this.heuristicFilter, s.clearPath(), this.list.clear(), this.list.add(e); this.list.length > 0;) {
  455. if (this.list.sort(this.compare), n = this.list.shift(), n._visited = !0, n === t) return vg.PathUtil.backtrace(t);for (r = s.getNeighbors(n, this.allowDiagonal, i), o = 0, a = r.length; a > o; o++) {
  456. if (h = r[o], h.walkable && (l = n._calcCost + s.distance(n, h), !h._visited || l < h._calcCost)) {
  457. if (h._visited = !0, h._parent = n, h._calcCost = l, h._priority = l + s.distance(t, h), h === t) return vg.PathUtil.backtrace(t);this.list.add(h);
  458. }
  459. }
  460. }return null;
  461. }, compare: function compare(e, t) {
  462. return e._priority - t._priority;
  463. } }, vg.AStarFinder.prototype.constructor = vg.AStarFinder, vg.PathUtil = { backtrace: function backtrace(e) {
  464. for (var t = [e]; e._parent;) {
  465. e = e._parent, t.push(e);
  466. }return t.reverse();
  467. }, biBacktrace: function biBacktrace(e, t) {
  468. var i = this.backtrace(e),
  469. s = this.backtrace(t);return i.concat(s.reverse());
  470. }, pathLength: function pathLength(e) {
  471. var t,
  472. i,
  473. s,
  474. n,
  475. l,
  476. r = 0;for (t = 1; t < e.length; ++t) {
  477. i = e[t - 1], s = e[t], n = i[0] - s[0], l = i[1] - s[1], r += Math.sqrt(n * n + l * l);
  478. }return r;
  479. }, interpolate: function interpolate(e, t, i, s) {
  480. var n,
  481. l,
  482. r,
  483. h,
  484. o,
  485. a,
  486. c = Math.abs,
  487. u = [];for (r = c(i - e), h = c(s - t), n = i > e ? 1 : -1, l = s > t ? 1 : -1, o = r - h; e !== i || t !== s;) {
  488. u.push([e, t]), a = 2 * o, a > -h && (o -= h, e += n), r > a && (o += r, t += l);
  489. }return u;
  490. }, expandPath: function expandPath(e) {
  491. var t,
  492. i,
  493. s,
  494. n,
  495. l,
  496. r,
  497. h = [],
  498. o = e.length;if (2 > o) return h;for (l = 0; o - 1 > l; ++l) {
  499. for (t = e[l], i = e[l + 1], s = this.interpolate(t[0], t[1], i[0], i[1]), n = s.length, r = 0; n - 1 > r; ++r) {
  500. h.push(s[r]);
  501. }
  502. }return h.push(e[o - 1]), h;
  503. }, smoothenPath: function smoothenPath(e, t) {
  504. var i,
  505. s,
  506. n,
  507. l,
  508. r,
  509. h,
  510. o,
  511. a,
  512. c,
  513. u,
  514. d,
  515. g,
  516. p = t.length,
  517. v = t[0][0],
  518. f = t[0][1],
  519. m = t[p - 1][0],
  520. _ = t[p - 1][1];for (i = v, s = f, r = [[i, s]], o = 2; p > o; ++o) {
  521. for (c = t[o], n = c[0], l = c[1], u = this.interpolate(i, s, n, l), g = !1, a = 1; a < u.length; ++a) {
  522. if (d = u[a], !e.isWalkableAt(d[0], d[1])) {
  523. g = !0;break;
  524. }
  525. }g && (h = t[o - 1], r.push(h), i = h[0], s = h[1]);
  526. }return r.push([m, _]), r;
  527. }, compressPath: function compressPath(e) {
  528. if (e.length < 3) return e;var t,
  529. i,
  530. s,
  531. n,
  532. l,
  533. r,
  534. h = [],
  535. o = e[0][0],
  536. a = e[0][1],
  537. c = e[1][0],
  538. u = e[1][1],
  539. d = c - o,
  540. g = u - a;for (l = Math.sqrt(d * d + g * g), d /= l, g /= l, h.push([o, a]), r = 2; r < e.length; r++) {
  541. t = c, i = u, s = d, n = g, c = e[r][0], u = e[r][1], d = c - t, g = u - i, l = Math.sqrt(d * d + g * g), d /= l, g /= l, (d !== s || g !== n) && h.push([t, i]);
  542. }return h.push([c, u]), h;
  543. } }, vg.Loader = { manager: null, imageLoader: null, crossOrigin: !1, init: function init(e) {
  544. this.crossOrigin = e || !1, this.manager = new THREE.LoadingManager(function () {}, function () {}, function () {
  545. console.warn("Error loading images");
  546. }), this.imageLoader = new THREE.ImageLoader(this.manager), this.imageLoader.crossOrigin = e;
  547. }, loadTexture: function loadTexture(e, t, i, s) {
  548. var n = new THREE.Texture(null, t);return this.imageLoader.load(e, function (e) {
  549. n.image = e, n.needsUpdate = !0, i && i(n);
  550. }, null, function (e) {
  551. s && s(e);
  552. }), n.sourceFile = e, n;
  553. } }, vg.MouseCaster = function (e, t, i) {
  554. 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 = e, this._camera = t, 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);
  555. }, 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 update() {
  556. if (this.active) {
  557. this._raycaster.setFromCamera(this.screenPosition, this._camera);var e,
  558. t,
  559. i = this._raycaster.intersectObject(this.group, !0);i.length > 0 ? (e = i[0], t = e.object.userData.structure, this.pickedObject != t && (this.pickedObject && this.signal.dispatch(vg.MouseCaster.OUT, this.pickedObject), this.pickedObject = t, this.selectedObject = null, this.signal.dispatch(vg.MouseCaster.OVER, this.pickedObject)), this.position.copy(e.point), this.screenPosition.z = e.distance) : (this.pickedObject && this.signal.dispatch(vg.MouseCaster.OUT, this.pickedObject), this.pickedObject = null, this.selectedObject = null), this.allHits = i;
  560. }
  561. }, preventDefault: function preventDefault() {
  562. this._preventDefault = !0;
  563. }, _onDocumentMouseDown: function _onDocumentMouseDown(e) {
  564. return e = e || window.event, e.preventDefault(), this._preventDefault ? (this._preventDefault = !1, !1) : (this.pickedObject && (this.selectedObject = this.pickedObject), this.shift = e.shiftKey, this.ctrl = e.ctrlKey, this.down = 1 === e.which, this.rightDown = 3 === e.which, void this.signal.dispatch(vg.MouseCaster.DOWN, this.pickedObject));
  565. }, _onDocumentMouseUp: function _onDocumentMouseUp(e) {
  566. return e.preventDefault(), this._preventDefault ? (this._preventDefault = !1, !1) : (this.shift = e.shiftKey, this.ctrl = e.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 === e.which ? !1 : this.down, void (this.rightDown = 3 === e.which ? !1 : this.rightDown));
  567. }, _onDocumentMouseMove: function _onDocumentMouseMove(e) {
  568. e.preventDefault(), this.screenPosition.x = e.clientX / window.innerWidth * 2 - 1, this.screenPosition.y = 2 * -(e.clientY / window.innerHeight) + 1;
  569. }, _onMouseWheel: function _onMouseWheel(e) {
  570. if (this.active) {
  571. e.preventDefault(), e.stopPropagation();var t = 0;void 0 !== e.wheelDelta ? t = e.wheelDelta : void 0 !== e.detail && (t = -e.detail), t > 0 ? this.wheel++ : this.wheel--, this.signal.dispatch(vg.MouseCaster.WHEEL, this.wheel);
  572. }
  573. } }, vg.MouseCaster.prototype.constructor = vg.MouseCaster, vg.Scene = function (e, t) {
  574. 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 },
  575. s = { minDistance: 100, maxDistance: 1e3, zoomSpeed: 2, noZoom: !1 };if (i = vg.Tools.merge(i, e), "boolean" != typeof t && (s = vg.Tools.merge(s, t)), 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) {
  576. var n = window.innerWidth / this.orthoZoom,
  577. l = window.innerHeight / this.orthoZoom;this.camera = new THREE.OrthographicCamera(n / -2, n / 2, l / 2, l / -2, 1, 5e3);
  578. } else this.camera = new THREE.PerspectiveCamera(50, this.width / this.height, 1, 5e3);this.contolled = !!t, 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 () {
  579. if (this.width = window.innerWidth, this.height = window.innerHeight, "OrthographicCamera" === this.camera.type) {
  580. var e = this.width / this.orthoZoom,
  581. t = this.height / this.orthoZoom;this.camera.left = e / -2, this.camera.right = e / 2, this.camera.top = t / 2, this.camera.bottom = t / -2;
  582. } else this.camera.aspect = this.width / this.height;this.camera.updateProjectionMatrix(), this.renderer.setSize(this.width, this.height);
  583. }.bind(this), !1), this.attachTo(i.element);
  584. }, vg.Scene.prototype = { attachTo: function attachTo(e) {
  585. e.style.width = this.width + "px", e.style.height = this.height + "px", this.renderer.setPixelRatio(window.devicePixelRatio), this.renderer.setSize(this.width, this.height), e.appendChild(this.renderer.domElement);
  586. }, add: function add(e) {
  587. this.container.add(e);
  588. }, remove: function remove(e) {
  589. this.container.remove(e);
  590. }, render: function render() {
  591. this.contolled && this.controls.update(), this.renderer.render(this.container, this.camera);
  592. }, updateOrthoZoom: function updateOrthoZoom() {
  593. if (this.orthoZoom <= 0) return void (this.orthoZoom = 0);var e = this.width / this.orthoZoom,
  594. t = this.height / this.orthoZoom;this.camera.left = e / -2, this.camera.right = e / 2, this.camera.top = t / 2, this.camera.bottom = t / -2, this.camera.updateProjectionMatrix();
  595. }, focusOn: function focusOn(e) {
  596. this.camera.lookAt(e.position);
  597. } }, vg.Scene.prototype.constructor = vg.Scene, vg.SelectionManager = function (e) {
  598. this.mouse = e, this.onSelect = new vg.Signal(), this.onDeselect = new vg.Signal(), this.selected = null, this.toggleSelection = !1, this.mouse.signal.add(this.onMouse, this);
  599. }, vg.SelectionManager.prototype = { select: function select(e, t) {
  600. e && (t = t || !0, this.selected !== e && this.clearSelection(t), e.selected ? this.toggleSelection && (t && this.onDeselect.dispatch(e), e.deselect()) : e.select(), this.selected = e, t && this.onSelect.dispatch(e));
  601. }, clearSelection: function clearSelection(e) {
  602. e = e || !0, this.selected && (e && this.onDeselect.dispatch(this.selected), this.selected.deselect()), this.selected = null;
  603. }, onMouse: function onMouse(e, t) {
  604. switch (e) {case vg.MouseCaster.DOWN:
  605. t || this.clearSelection();break;case vg.MouseCaster.CLICK:
  606. this.select(t);}
  607. } }, vg.SelectionManager.prototype.constructor = vg.SelectionManager, vg.Tools = { clamp: function clamp(e, t, i) {
  608. return Math.max(t, Math.min(i, e));
  609. }, sign: function sign(e) {
  610. return e && e / Math.abs(e);
  611. }, random: function random(e, t) {
  612. return 1 === arguments.length ? Math.random() * e - .5 * e : Math.random() * (t - e) + e;
  613. }, randomInt: function randomInt(e, t) {
  614. return 1 === arguments.length ? Math.random() * e - .5 * e | 0 : Math.random() * (t - e + 1) + e | 0;
  615. }, normalize: function normalize(e, t, i) {
  616. return (e - t) / (i - t);
  617. }, getShortRotation: function getShortRotation(e) {
  618. return e %= this.TAU, e > this.PI ? e -= this.TAU : e < -this.PI && (e += this.TAU), e;
  619. }, generateID: function generateID() {
  620. return Math.random().toString(36).slice(2) + Date.now();
  621. }, isPlainObject: function isPlainObject(e) {
  622. if ("object" != (typeof e === "undefined" ? "undefined" : _typeof(e)) || e.nodeType || e === e.window) return !1;try {
  623. if (e.constructor && !Object.prototype.hasOwnProperty.call(e.constructor.prototype, "isPrototypeOf")) return !1;
  624. } catch (t) {
  625. return !1;
  626. }return !0;
  627. }, merge: function merge(e, t) {
  628. var i = this,
  629. s = Array.isArray(t),
  630. n = s && [] || {};return s ? (e = e || [], n = n.concat(e), t.forEach(function (t, s) {
  631. "undefined" == typeof n[s] ? n[s] = t : i.isPlainObject(t) ? n[s] = i.merge(e[s], t) : -1 === e.indexOf(t) && n.push(t);
  632. }), n) : (e && i.isPlainObject(e) && Object.keys(e).forEach(function (t) {
  633. n[t] = e[t];
  634. }), Object.keys(t).forEach(function (s) {
  635. t[s] && i.isPlainObject(t[s]) && e[s] ? n[s] = i.merge(e[s], t[s]) : n[s] = t[s];
  636. }), n);
  637. }, now: function now() {
  638. return window.nwf ? window.nwf.system.Performance.elapsedTime : window.performance.now();
  639. }, empty: function empty(e) {
  640. for (; e.lastChild;) {
  641. e.removeChild(e.lastChild);
  642. }
  643. }, radixSort: function radixSort(e, t, i, s) {
  644. if (t = t || 0, i = i || e.length, s = s || 31, !(t >= i - 1 || 0 > s)) {
  645. for (var n = t, l = i, r = 1 << s; l > n;) {
  646. if (e[n] & r) {
  647. --l;var h = e[n];e[n] = e[l], e[l] = h;
  648. } else ++n;
  649. }this.radixSort(e, t, l, s - 1), this.radixSort(e, l, i, s - 1);
  650. }
  651. }, randomizeRGB: function randomizeRGB(e, t) {
  652. var i,
  653. s,
  654. n = e.split(","),
  655. l = "rgb(";for (t = this.randomInt(t), i = 0; 3 > i; i++) {
  656. s = parseInt(n[i]) + t, 0 > s ? s = 0 : s > 255 && (s = 255), l += s + ",";
  657. }return l = l.substring(0, l.length - 1), l += ")";
  658. }, getJSON: function getJSON(e) {
  659. var t = new XMLHttpRequest(),
  660. i = "undefined" == typeof e.cache ? !1 : e.cache,
  661. s = i ? e.url : e.url + "?t=" + Math.floor(1e4 * Math.random()) + Date.now();t.onreadystatechange = function () {
  662. if (200 === this.status) {
  663. var t = null;try {
  664. t = JSON.parse(this.responseText);
  665. } catch (i) {
  666. return;
  667. }return void e.callback.call(e.scope || null, t);
  668. }0 !== this.status && console.warn("[Tools.getJSON] Error: " + this.status + " (" + this.statusText + ") :: " + e.url);
  669. }, t.open("GET", s, !0), t.setRequestHeader("Accept", "application/json"), t.setRequestHeader("Content-Type", "application/json"), t.send("");
  670. } };
  671. },{}],4:[function(require,module,exports){
  672. 'use strict';
  673. /**
  674. * Flat grid.
  675. *
  676. * Defaults to 75x75.
  677. */
  678. module.exports = AFRAME.registerPrimitive('a-grid', {
  679. defaultComponents: {
  680. geometry: {
  681. primitive: 'plane',
  682. width: 75,
  683. height: 75
  684. },
  685. rotation: { x: -90, y: 0, z: 0 },
  686. material: {
  687. src: 'url(https://cdn.rawgit.com/donmccurdy/aframe-extras/v1.16.3/assets/grid.png)',
  688. repeat: '75 75'
  689. }
  690. },
  691. mappings: {
  692. width: 'geometry.width',
  693. height: 'geometry.height',
  694. src: 'material.src'
  695. }
  696. });
  697. },{}],5:[function(require,module,exports){
  698. 'use strict';
  699. var vg = require('../../lib/hex-grid.min.js');
  700. var defaultHexGrid = require('../../lib/default-hex-grid');
  701. /**
  702. * Hex grid.
  703. */
  704. module.exports.Primitive = AFRAME.registerPrimitive('a-hexgrid', {
  705. defaultComponents: {
  706. 'hexgrid': {}
  707. },
  708. mappings: {
  709. src: 'hexgrid.src'
  710. }
  711. });
  712. module.exports.Component = AFRAME.registerComponent('hexgrid', {
  713. dependencies: ['material'],
  714. schema: {
  715. src: { type: 'asset' }
  716. },
  717. init: function init() {
  718. var _this = this;
  719. var data = this.data;
  720. if (data.src) {
  721. fetch(data.src).then(function (response) {
  722. return response.json();
  723. }).then(function (json) {
  724. return _this.addMesh(json);
  725. });
  726. } else {
  727. this.addMesh(defaultHexGrid);
  728. }
  729. },
  730. addMesh: function addMesh(json) {
  731. var grid = new vg.HexGrid();
  732. grid.fromJSON(json);
  733. var board = new vg.Board(grid);
  734. board.generateTilemap();
  735. this.el.setObject3D('mesh', board.group);
  736. this.addMaterial();
  737. },
  738. addMaterial: function addMaterial() {
  739. var materialComponent = this.el.components.material;
  740. var material = (materialComponent || {}).material;
  741. if (!material) return;
  742. this.el.object3D.traverse(function (node) {
  743. if (node.isMesh) {
  744. node.material = material;
  745. }
  746. });
  747. },
  748. remove: function remove() {
  749. this.el.removeObject3D('mesh');
  750. }
  751. });
  752. },{"../../lib/default-hex-grid":2,"../../lib/hex-grid.min.js":3}],6:[function(require,module,exports){
  753. 'use strict';
  754. /**
  755. * Flat-shaded ocean primitive.
  756. *
  757. * Based on a Codrops tutorial:
  758. * http://tympanus.net/codrops/2016/04/26/the-aviator-animating-basic-3d-scene-threejs/
  759. */
  760. module.exports.Primitive = AFRAME.registerPrimitive('a-ocean', {
  761. defaultComponents: {
  762. ocean: {},
  763. rotation: { x: -90, y: 0, z: 0 }
  764. },
  765. mappings: {
  766. width: 'ocean.width',
  767. depth: 'ocean.depth',
  768. density: 'ocean.density',
  769. amplitude: 'ocean.amplitude',
  770. amplitudeVariance: 'ocean.amplitudeVariance',
  771. speed: 'ocean.speed',
  772. speedVariance: 'ocean.speedVariance',
  773. color: 'ocean.color',
  774. opacity: 'ocean.opacity'
  775. }
  776. });
  777. module.exports.Component = AFRAME.registerComponent('ocean', {
  778. schema: {
  779. // Dimensions of the ocean area.
  780. width: { default: 10, min: 0 },
  781. depth: { default: 10, min: 0 },
  782. // Density of waves.
  783. density: { default: 10 },
  784. // Wave amplitude and variance.
  785. amplitude: { default: 0.1 },
  786. amplitudeVariance: { default: 0.3 },
  787. // Wave speed and variance.
  788. speed: { default: 1 },
  789. speedVariance: { default: 2 },
  790. // Material.
  791. color: { default: '#7AD2F7', type: 'color' },
  792. opacity: { default: 0.8 }
  793. },
  794. /**
  795. * Use play() instead of init(), because component mappings – unavailable as dependencies – are
  796. * not guaranteed to have parsed when this component is initialized.
  797. */
  798. play: function play() {
  799. var el = this.el,
  800. data = this.data;
  801. var material = el.components.material;
  802. var geometry = new THREE.PlaneGeometry(data.width, data.depth, data.density, data.density);
  803. geometry.mergeVertices();
  804. this.waves = [];
  805. for (var v, i = 0, l = geometry.vertices.length; i < l; i++) {
  806. v = geometry.vertices[i];
  807. this.waves.push({
  808. z: v.z,
  809. ang: Math.random() * Math.PI * 2,
  810. amp: data.amplitude + Math.random() * data.amplitudeVariance,
  811. speed: (data.speed + Math.random() * data.speedVariance) / 1000 // radians / frame
  812. });
  813. }
  814. if (!material) {
  815. material = {};
  816. material.material = new THREE.MeshPhongMaterial({
  817. color: data.color,
  818. transparent: data.opacity < 1,
  819. opacity: data.opacity,
  820. shading: THREE.FlatShading
  821. });
  822. }
  823. this.mesh = new THREE.Mesh(geometry, material.material);
  824. el.setObject3D('mesh', this.mesh);
  825. },
  826. remove: function remove() {
  827. this.el.removeObject3D('mesh');
  828. },
  829. tick: function tick(t, dt) {
  830. if (!dt) return;
  831. var verts = this.mesh.geometry.vertices;
  832. for (var v, vprops, i = 0; v = verts[i]; i++) {
  833. vprops = this.waves[i];
  834. v.z = vprops.z + Math.sin(vprops.ang) * vprops.amp;
  835. vprops.ang += vprops.speed * dt;
  836. }
  837. this.mesh.geometry.verticesNeedUpdate = true;
  838. }
  839. });
  840. },{}],7:[function(require,module,exports){
  841. 'use strict';
  842. /**
  843. * Tube following a custom path.
  844. *
  845. * Usage:
  846. *
  847. * ```html
  848. * <a-tube path="5 0 5, 5 0 -5, -5 0 -5" radius="0.5"></a-tube>
  849. * ```
  850. */
  851. module.exports.Primitive = AFRAME.registerPrimitive('a-tube', {
  852. defaultComponents: {
  853. tube: {}
  854. },
  855. mappings: {
  856. path: 'tube.path',
  857. segments: 'tube.segments',
  858. radius: 'tube.radius',
  859. radialSegments: 'tube.radialSegments',
  860. closed: 'tube.closed'
  861. }
  862. });
  863. module.exports.Component = AFRAME.registerComponent('tube', {
  864. schema: {
  865. path: { default: [] },
  866. segments: { default: 64 },
  867. radius: { default: 1 },
  868. radialSegments: { default: 8 },
  869. closed: { default: false }
  870. },
  871. init: function init() {
  872. var el = this.el,
  873. data = this.data;
  874. var material = el.components.material;
  875. if (!data.path.length) {
  876. console.error('[a-tube] `path` property expected but not found.');
  877. return;
  878. }
  879. var curve = new THREE.CatmullRomCurve3(data.path.map(function (point) {
  880. point = point.split(' ');
  881. return new THREE.Vector3(Number(point[0]), Number(point[1]), Number(point[2]));
  882. }));
  883. var geometry = new THREE.TubeGeometry(curve, data.segments, data.radius, data.radialSegments, data.closed);
  884. if (!material) {
  885. material = {};
  886. material.material = new THREE.MeshPhongMaterial();
  887. }
  888. this.mesh = new THREE.Mesh(geometry, material.material);
  889. this.el.setObject3D('mesh', this.mesh);
  890. },
  891. remove: function remove() {
  892. if (this.mesh) this.el.removeObject3D('mesh');
  893. }
  894. });
  895. },{}],8:[function(require,module,exports){
  896. 'use strict';
  897. require('./a-grid');
  898. require('./a-hexgrid');
  899. require('./a-ocean');
  900. require('./a-tube');
  901. },{"./a-grid":4,"./a-hexgrid":5,"./a-ocean":6,"./a-tube":7}]},{},[1]);