mesh-extras.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*!
  2. * @pixi/mesh-extras - v6.5.10
  3. * Compiled Thu, 06 Jul 2023 15:25:11 UTC
  4. *
  5. * @pixi/mesh-extras is licensed under the MIT License.
  6. * http://www.opensource.org/licenses/mit-license
  7. */
  8. 'use strict';
  9. Object.defineProperty(exports, '__esModule', { value: true });
  10. var mesh = require('@pixi/mesh');
  11. var constants = require('@pixi/constants');
  12. var core = require('@pixi/core');
  13. /*! *****************************************************************************
  14. Copyright (c) Microsoft Corporation.
  15. Permission to use, copy, modify, and/or distribute this software for any
  16. purpose with or without fee is hereby granted.
  17. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  18. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  19. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  20. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  21. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  23. PERFORMANCE OF THIS SOFTWARE.
  24. ***************************************************************************** */
  25. /* global Reflect, Promise */
  26. var extendStatics = function(d, b) {
  27. extendStatics = Object.setPrototypeOf ||
  28. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  29. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  30. return extendStatics(d, b);
  31. };
  32. function __extends(d, b) {
  33. extendStatics(d, b);
  34. function __() { this.constructor = d; }
  35. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  36. }
  37. /**
  38. * @memberof PIXI
  39. */
  40. var PlaneGeometry = /** @class */ (function (_super) {
  41. __extends(PlaneGeometry, _super);
  42. /**
  43. * @param width - The width of the plane.
  44. * @param height - The height of the plane.
  45. * @param segWidth - Number of horizontal segments.
  46. * @param segHeight - Number of vertical segments.
  47. */
  48. function PlaneGeometry(width, height, segWidth, segHeight) {
  49. if (width === void 0) { width = 100; }
  50. if (height === void 0) { height = 100; }
  51. if (segWidth === void 0) { segWidth = 10; }
  52. if (segHeight === void 0) { segHeight = 10; }
  53. var _this = _super.call(this) || this;
  54. _this.segWidth = segWidth;
  55. _this.segHeight = segHeight;
  56. _this.width = width;
  57. _this.height = height;
  58. _this.build();
  59. return _this;
  60. }
  61. /**
  62. * Refreshes plane coordinates
  63. * @private
  64. */
  65. PlaneGeometry.prototype.build = function () {
  66. var total = this.segWidth * this.segHeight;
  67. var verts = [];
  68. var uvs = [];
  69. var indices = [];
  70. var segmentsX = this.segWidth - 1;
  71. var segmentsY = this.segHeight - 1;
  72. var sizeX = (this.width) / segmentsX;
  73. var sizeY = (this.height) / segmentsY;
  74. for (var i = 0; i < total; i++) {
  75. var x = (i % this.segWidth);
  76. var y = ((i / this.segWidth) | 0);
  77. verts.push(x * sizeX, y * sizeY);
  78. uvs.push(x / segmentsX, y / segmentsY);
  79. }
  80. var totalSub = segmentsX * segmentsY;
  81. for (var i = 0; i < totalSub; i++) {
  82. var xpos = i % segmentsX;
  83. var ypos = (i / segmentsX) | 0;
  84. var value = (ypos * this.segWidth) + xpos;
  85. var value2 = (ypos * this.segWidth) + xpos + 1;
  86. var value3 = ((ypos + 1) * this.segWidth) + xpos;
  87. var value4 = ((ypos + 1) * this.segWidth) + xpos + 1;
  88. indices.push(value, value2, value3, value2, value4, value3);
  89. }
  90. this.buffers[0].data = new Float32Array(verts);
  91. this.buffers[1].data = new Float32Array(uvs);
  92. this.indexBuffer.data = new Uint16Array(indices);
  93. // ensure that the changes are uploaded
  94. this.buffers[0].update();
  95. this.buffers[1].update();
  96. this.indexBuffer.update();
  97. };
  98. return PlaneGeometry;
  99. }(mesh.MeshGeometry));
  100. /**
  101. * RopeGeometry allows you to draw a geometry across several points and then manipulate these points.
  102. *
  103. * ```js
  104. * for (let i = 0; i < 20; i++) {
  105. * points.push(new PIXI.Point(i * 50, 0));
  106. * };
  107. * const rope = new PIXI.RopeGeometry(100, points);
  108. * ```
  109. * @memberof PIXI
  110. */
  111. var RopeGeometry = /** @class */ (function (_super) {
  112. __extends(RopeGeometry, _super);
  113. /**
  114. * @param width - The width (i.e., thickness) of the rope.
  115. * @param points - An array of {@link PIXI.Point} objects to construct this rope.
  116. * @param textureScale - By default the rope texture will be stretched to match
  117. * rope length. If textureScale is positive this value will be treated as a scaling
  118. * factor and the texture will preserve its aspect ratio instead. To create a tiling rope
  119. * set baseTexture.wrapMode to {@link PIXI.WRAP_MODES.REPEAT} and use a power of two texture,
  120. * then set textureScale=1 to keep the original texture pixel size.
  121. * In order to reduce alpha channel artifacts provide a larger texture and downsample -
  122. * i.e. set textureScale=0.5 to scale it down twice.
  123. */
  124. function RopeGeometry(width, points, textureScale) {
  125. if (width === void 0) { width = 200; }
  126. if (textureScale === void 0) { textureScale = 0; }
  127. var _this = _super.call(this, new Float32Array(points.length * 4), new Float32Array(points.length * 4), new Uint16Array((points.length - 1) * 6)) || this;
  128. _this.points = points;
  129. _this._width = width;
  130. _this.textureScale = textureScale;
  131. _this.build();
  132. return _this;
  133. }
  134. Object.defineProperty(RopeGeometry.prototype, "width", {
  135. /**
  136. * The width (i.e., thickness) of the rope.
  137. * @readonly
  138. */
  139. get: function () {
  140. return this._width;
  141. },
  142. enumerable: false,
  143. configurable: true
  144. });
  145. /** Refreshes Rope indices and uvs */
  146. RopeGeometry.prototype.build = function () {
  147. var points = this.points;
  148. if (!points)
  149. { return; }
  150. var vertexBuffer = this.getBuffer('aVertexPosition');
  151. var uvBuffer = this.getBuffer('aTextureCoord');
  152. var indexBuffer = this.getIndex();
  153. // if too little points, or texture hasn't got UVs set yet just move on.
  154. if (points.length < 1) {
  155. return;
  156. }
  157. // if the number of points has changed we will need to recreate the arraybuffers
  158. if (vertexBuffer.data.length / 4 !== points.length) {
  159. vertexBuffer.data = new Float32Array(points.length * 4);
  160. uvBuffer.data = new Float32Array(points.length * 4);
  161. indexBuffer.data = new Uint16Array((points.length - 1) * 6);
  162. }
  163. var uvs = uvBuffer.data;
  164. var indices = indexBuffer.data;
  165. uvs[0] = 0;
  166. uvs[1] = 0;
  167. uvs[2] = 0;
  168. uvs[3] = 1;
  169. var amount = 0;
  170. var prev = points[0];
  171. var textureWidth = this._width * this.textureScale;
  172. var total = points.length; // - 1;
  173. for (var i = 0; i < total; i++) {
  174. // time to do some smart drawing!
  175. var index = i * 4;
  176. if (this.textureScale > 0) {
  177. // calculate pixel distance from previous point
  178. var dx = prev.x - points[i].x;
  179. var dy = prev.y - points[i].y;
  180. var distance = Math.sqrt((dx * dx) + (dy * dy));
  181. prev = points[i];
  182. amount += distance / textureWidth;
  183. }
  184. else {
  185. // stretch texture
  186. amount = i / (total - 1);
  187. }
  188. uvs[index] = amount;
  189. uvs[index + 1] = 0;
  190. uvs[index + 2] = amount;
  191. uvs[index + 3] = 1;
  192. }
  193. var indexCount = 0;
  194. for (var i = 0; i < total - 1; i++) {
  195. var index = i * 2;
  196. indices[indexCount++] = index;
  197. indices[indexCount++] = index + 1;
  198. indices[indexCount++] = index + 2;
  199. indices[indexCount++] = index + 2;
  200. indices[indexCount++] = index + 1;
  201. indices[indexCount++] = index + 3;
  202. }
  203. // ensure that the changes are uploaded
  204. uvBuffer.update();
  205. indexBuffer.update();
  206. this.updateVertices();
  207. };
  208. /** refreshes vertices of Rope mesh */
  209. RopeGeometry.prototype.updateVertices = function () {
  210. var points = this.points;
  211. if (points.length < 1) {
  212. return;
  213. }
  214. var lastPoint = points[0];
  215. var nextPoint;
  216. var perpX = 0;
  217. var perpY = 0;
  218. var vertices = this.buffers[0].data;
  219. var total = points.length;
  220. for (var i = 0; i < total; i++) {
  221. var point = points[i];
  222. var index = i * 4;
  223. if (i < points.length - 1) {
  224. nextPoint = points[i + 1];
  225. }
  226. else {
  227. nextPoint = point;
  228. }
  229. perpY = -(nextPoint.x - lastPoint.x);
  230. perpX = nextPoint.y - lastPoint.y;
  231. var perpLength = Math.sqrt((perpX * perpX) + (perpY * perpY));
  232. var num = this.textureScale > 0 ? this.textureScale * this._width / 2 : this._width / 2;
  233. perpX /= perpLength;
  234. perpY /= perpLength;
  235. perpX *= num;
  236. perpY *= num;
  237. vertices[index] = point.x + perpX;
  238. vertices[index + 1] = point.y + perpY;
  239. vertices[index + 2] = point.x - perpX;
  240. vertices[index + 3] = point.y - perpY;
  241. lastPoint = point;
  242. }
  243. this.buffers[0].update();
  244. };
  245. RopeGeometry.prototype.update = function () {
  246. if (this.textureScale > 0) {
  247. this.build(); // we need to update UVs
  248. }
  249. else {
  250. this.updateVertices();
  251. }
  252. };
  253. return RopeGeometry;
  254. }(mesh.MeshGeometry));
  255. /**
  256. * The rope allows you to draw a texture across several points and then manipulate these points
  257. *
  258. *```js
  259. * for (let i = 0; i < 20; i++) {
  260. * points.push(new PIXI.Point(i * 50, 0));
  261. * };
  262. * let rope = new PIXI.SimpleRope(PIXI.Texture.from("snake.png"), points);
  263. * ```
  264. * @memberof PIXI
  265. */
  266. var SimpleRope = /** @class */ (function (_super) {
  267. __extends(SimpleRope, _super);
  268. /**
  269. * @param texture - The texture to use on the rope.
  270. * @param points - An array of {@link PIXI.Point} objects to construct this rope.
  271. * @param {number} textureScale - Optional. Positive values scale rope texture
  272. * keeping its aspect ratio. You can reduce alpha channel artifacts by providing a larger texture
  273. * and downsampling here. If set to zero, texture will be stretched instead.
  274. */
  275. function SimpleRope(texture, points, textureScale) {
  276. if (textureScale === void 0) { textureScale = 0; }
  277. var _this = this;
  278. var ropeGeometry = new RopeGeometry(texture.height, points, textureScale);
  279. var meshMaterial = new mesh.MeshMaterial(texture);
  280. if (textureScale > 0) {
  281. // attempt to set UV wrapping, will fail on non-power of two textures
  282. texture.baseTexture.wrapMode = constants.WRAP_MODES.REPEAT;
  283. }
  284. _this = _super.call(this, ropeGeometry, meshMaterial) || this;
  285. /**
  286. * re-calculate vertices by rope points each frame
  287. * @member {boolean}
  288. */
  289. _this.autoUpdate = true;
  290. return _this;
  291. }
  292. SimpleRope.prototype._render = function (renderer) {
  293. var geometry = this.geometry;
  294. if (this.autoUpdate || geometry._width !== this.shader.texture.height) {
  295. geometry._width = this.shader.texture.height;
  296. geometry.update();
  297. }
  298. _super.prototype._render.call(this, renderer);
  299. };
  300. return SimpleRope;
  301. }(mesh.Mesh));
  302. /**
  303. * The SimplePlane allows you to draw a texture across several points and then manipulate these points
  304. *
  305. *```js
  306. * for (let i = 0; i < 20; i++) {
  307. * points.push(new PIXI.Point(i * 50, 0));
  308. * };
  309. * let SimplePlane = new PIXI.SimplePlane(PIXI.Texture.from("snake.png"), points);
  310. * ```
  311. * @memberof PIXI
  312. */
  313. var SimplePlane = /** @class */ (function (_super) {
  314. __extends(SimplePlane, _super);
  315. /**
  316. * @param texture - The texture to use on the SimplePlane.
  317. * @param verticesX - The number of vertices in the x-axis
  318. * @param verticesY - The number of vertices in the y-axis
  319. */
  320. function SimplePlane(texture, verticesX, verticesY) {
  321. var _this = this;
  322. var planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY);
  323. var meshMaterial = new mesh.MeshMaterial(core.Texture.WHITE);
  324. _this = _super.call(this, planeGeometry, meshMaterial) || this;
  325. // lets call the setter to ensure all necessary updates are performed
  326. _this.texture = texture;
  327. _this.autoResize = true;
  328. return _this;
  329. }
  330. /**
  331. * Method used for overrides, to do something in case texture frame was changed.
  332. * Meshes based on plane can override it and change more details based on texture.
  333. */
  334. SimplePlane.prototype.textureUpdated = function () {
  335. this._textureID = this.shader.texture._updateID;
  336. var geometry = this.geometry;
  337. var _a = this.shader.texture, width = _a.width, height = _a.height;
  338. if (this.autoResize && (geometry.width !== width || geometry.height !== height)) {
  339. geometry.width = this.shader.texture.width;
  340. geometry.height = this.shader.texture.height;
  341. geometry.build();
  342. }
  343. };
  344. Object.defineProperty(SimplePlane.prototype, "texture", {
  345. get: function () {
  346. return this.shader.texture;
  347. },
  348. set: function (value) {
  349. // Track texture same way sprite does.
  350. // For generated meshes like NineSlicePlane it can change the geometry.
  351. // Unfortunately, this method might not work if you directly change texture in material.
  352. if (this.shader.texture === value) {
  353. return;
  354. }
  355. this.shader.texture = value;
  356. this._textureID = -1;
  357. if (value.baseTexture.valid) {
  358. this.textureUpdated();
  359. }
  360. else {
  361. value.once('update', this.textureUpdated, this);
  362. }
  363. },
  364. enumerable: false,
  365. configurable: true
  366. });
  367. SimplePlane.prototype._render = function (renderer) {
  368. if (this._textureID !== this.shader.texture._updateID) {
  369. this.textureUpdated();
  370. }
  371. _super.prototype._render.call(this, renderer);
  372. };
  373. SimplePlane.prototype.destroy = function (options) {
  374. this.shader.texture.off('update', this.textureUpdated, this);
  375. _super.prototype.destroy.call(this, options);
  376. };
  377. return SimplePlane;
  378. }(mesh.Mesh));
  379. /**
  380. * The Simple Mesh class mimics Mesh in PixiJS v4, providing easy-to-use constructor arguments.
  381. * For more robust customization, use {@link PIXI.Mesh}.
  382. * @memberof PIXI
  383. */
  384. var SimpleMesh = /** @class */ (function (_super) {
  385. __extends(SimpleMesh, _super);
  386. /**
  387. * @param texture - The texture to use
  388. * @param {Float32Array} [vertices] - if you want to specify the vertices
  389. * @param {Float32Array} [uvs] - if you want to specify the uvs
  390. * @param {Uint16Array} [indices] - if you want to specify the indices
  391. * @param drawMode - the drawMode, can be any of the Mesh.DRAW_MODES consts
  392. */
  393. function SimpleMesh(texture, vertices, uvs, indices, drawMode) {
  394. if (texture === void 0) { texture = core.Texture.EMPTY; }
  395. var _this = this;
  396. var geometry = new mesh.MeshGeometry(vertices, uvs, indices);
  397. geometry.getBuffer('aVertexPosition').static = false;
  398. var meshMaterial = new mesh.MeshMaterial(texture);
  399. _this = _super.call(this, geometry, meshMaterial, null, drawMode) || this;
  400. _this.autoUpdate = true;
  401. return _this;
  402. }
  403. Object.defineProperty(SimpleMesh.prototype, "vertices", {
  404. /**
  405. * Collection of vertices data.
  406. * @type {Float32Array}
  407. */
  408. get: function () {
  409. return this.geometry.getBuffer('aVertexPosition').data;
  410. },
  411. set: function (value) {
  412. this.geometry.getBuffer('aVertexPosition').data = value;
  413. },
  414. enumerable: false,
  415. configurable: true
  416. });
  417. SimpleMesh.prototype._render = function (renderer) {
  418. if (this.autoUpdate) {
  419. this.geometry.getBuffer('aVertexPosition').update();
  420. }
  421. _super.prototype._render.call(this, renderer);
  422. };
  423. return SimpleMesh;
  424. }(mesh.Mesh));
  425. var DEFAULT_BORDER_SIZE = 10;
  426. /**
  427. * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful
  428. * for buttons with rounded corners for example) and the other areas will be scaled horizontally and or vertically
  429. *
  430. *```js
  431. * let Plane9 = new PIXI.NineSlicePlane(PIXI.Texture.from('BoxWithRoundedCorners.png'), 15, 15, 15, 15);
  432. * ```
  433. * <pre>
  434. * A B
  435. * +---+----------------------+---+
  436. * C | 1 | 2 | 3 |
  437. * +---+----------------------+---+
  438. * | | | |
  439. * | 4 | 5 | 6 |
  440. * | | | |
  441. * +---+----------------------+---+
  442. * D | 7 | 8 | 9 |
  443. * +---+----------------------+---+
  444. * When changing this objects width and/or height:
  445. * areas 1 3 7 and 9 will remain unscaled.
  446. * areas 2 and 8 will be stretched horizontally
  447. * areas 4 and 6 will be stretched vertically
  448. * area 5 will be stretched both horizontally and vertically
  449. * </pre>
  450. * @memberof PIXI
  451. */
  452. var NineSlicePlane = /** @class */ (function (_super) {
  453. __extends(NineSlicePlane, _super);
  454. /**
  455. * @param texture - The texture to use on the NineSlicePlane.
  456. * @param {number} [leftWidth=10] - size of the left vertical bar (A)
  457. * @param {number} [topHeight=10] - size of the top horizontal bar (C)
  458. * @param {number} [rightWidth=10] - size of the right vertical bar (B)
  459. * @param {number} [bottomHeight=10] - size of the bottom horizontal bar (D)
  460. */
  461. function NineSlicePlane(texture, leftWidth, topHeight, rightWidth, bottomHeight) {
  462. if (leftWidth === void 0) { leftWidth = DEFAULT_BORDER_SIZE; }
  463. if (topHeight === void 0) { topHeight = DEFAULT_BORDER_SIZE; }
  464. if (rightWidth === void 0) { rightWidth = DEFAULT_BORDER_SIZE; }
  465. if (bottomHeight === void 0) { bottomHeight = DEFAULT_BORDER_SIZE; }
  466. var _this = _super.call(this, core.Texture.WHITE, 4, 4) || this;
  467. _this._origWidth = texture.orig.width;
  468. _this._origHeight = texture.orig.height;
  469. /** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
  470. _this._width = _this._origWidth;
  471. /** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
  472. _this._height = _this._origHeight;
  473. _this._leftWidth = leftWidth;
  474. _this._rightWidth = rightWidth;
  475. _this._topHeight = topHeight;
  476. _this._bottomHeight = bottomHeight;
  477. // lets call the setter to ensure all necessary updates are performed
  478. _this.texture = texture;
  479. return _this;
  480. }
  481. NineSlicePlane.prototype.textureUpdated = function () {
  482. this._textureID = this.shader.texture._updateID;
  483. this._refresh();
  484. };
  485. Object.defineProperty(NineSlicePlane.prototype, "vertices", {
  486. get: function () {
  487. return this.geometry.getBuffer('aVertexPosition').data;
  488. },
  489. set: function (value) {
  490. this.geometry.getBuffer('aVertexPosition').data = value;
  491. },
  492. enumerable: false,
  493. configurable: true
  494. });
  495. /** Updates the horizontal vertices. */
  496. NineSlicePlane.prototype.updateHorizontalVertices = function () {
  497. var vertices = this.vertices;
  498. var scale = this._getMinScale();
  499. vertices[9] = vertices[11] = vertices[13] = vertices[15] = this._topHeight * scale;
  500. vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - (this._bottomHeight * scale);
  501. vertices[25] = vertices[27] = vertices[29] = vertices[31] = this._height;
  502. };
  503. /** Updates the vertical vertices. */
  504. NineSlicePlane.prototype.updateVerticalVertices = function () {
  505. var vertices = this.vertices;
  506. var scale = this._getMinScale();
  507. vertices[2] = vertices[10] = vertices[18] = vertices[26] = this._leftWidth * scale;
  508. vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - (this._rightWidth * scale);
  509. vertices[6] = vertices[14] = vertices[22] = vertices[30] = this._width;
  510. };
  511. /**
  512. * Returns the smaller of a set of vertical and horizontal scale of nine slice corners.
  513. * @returns Smaller number of vertical and horizontal scale.
  514. */
  515. NineSlicePlane.prototype._getMinScale = function () {
  516. var w = this._leftWidth + this._rightWidth;
  517. var scaleW = this._width > w ? 1.0 : this._width / w;
  518. var h = this._topHeight + this._bottomHeight;
  519. var scaleH = this._height > h ? 1.0 : this._height / h;
  520. var scale = Math.min(scaleW, scaleH);
  521. return scale;
  522. };
  523. Object.defineProperty(NineSlicePlane.prototype, "width", {
  524. /** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
  525. get: function () {
  526. return this._width;
  527. },
  528. set: function (value) {
  529. this._width = value;
  530. this._refresh();
  531. },
  532. enumerable: false,
  533. configurable: true
  534. });
  535. Object.defineProperty(NineSlicePlane.prototype, "height", {
  536. /** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
  537. get: function () {
  538. return this._height;
  539. },
  540. set: function (value) {
  541. this._height = value;
  542. this._refresh();
  543. },
  544. enumerable: false,
  545. configurable: true
  546. });
  547. Object.defineProperty(NineSlicePlane.prototype, "leftWidth", {
  548. /** The width of the left column. */
  549. get: function () {
  550. return this._leftWidth;
  551. },
  552. set: function (value) {
  553. this._leftWidth = value;
  554. this._refresh();
  555. },
  556. enumerable: false,
  557. configurable: true
  558. });
  559. Object.defineProperty(NineSlicePlane.prototype, "rightWidth", {
  560. /** The width of the right column. */
  561. get: function () {
  562. return this._rightWidth;
  563. },
  564. set: function (value) {
  565. this._rightWidth = value;
  566. this._refresh();
  567. },
  568. enumerable: false,
  569. configurable: true
  570. });
  571. Object.defineProperty(NineSlicePlane.prototype, "topHeight", {
  572. /** The height of the top row. */
  573. get: function () {
  574. return this._topHeight;
  575. },
  576. set: function (value) {
  577. this._topHeight = value;
  578. this._refresh();
  579. },
  580. enumerable: false,
  581. configurable: true
  582. });
  583. Object.defineProperty(NineSlicePlane.prototype, "bottomHeight", {
  584. /** The height of the bottom row. */
  585. get: function () {
  586. return this._bottomHeight;
  587. },
  588. set: function (value) {
  589. this._bottomHeight = value;
  590. this._refresh();
  591. },
  592. enumerable: false,
  593. configurable: true
  594. });
  595. /** Refreshes NineSlicePlane coords. All of them. */
  596. NineSlicePlane.prototype._refresh = function () {
  597. var texture = this.texture;
  598. var uvs = this.geometry.buffers[1].data;
  599. this._origWidth = texture.orig.width;
  600. this._origHeight = texture.orig.height;
  601. var _uvw = 1.0 / this._origWidth;
  602. var _uvh = 1.0 / this._origHeight;
  603. uvs[0] = uvs[8] = uvs[16] = uvs[24] = 0;
  604. uvs[1] = uvs[3] = uvs[5] = uvs[7] = 0;
  605. uvs[6] = uvs[14] = uvs[22] = uvs[30] = 1;
  606. uvs[25] = uvs[27] = uvs[29] = uvs[31] = 1;
  607. uvs[2] = uvs[10] = uvs[18] = uvs[26] = _uvw * this._leftWidth;
  608. uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - (_uvw * this._rightWidth);
  609. uvs[9] = uvs[11] = uvs[13] = uvs[15] = _uvh * this._topHeight;
  610. uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - (_uvh * this._bottomHeight);
  611. this.updateHorizontalVertices();
  612. this.updateVerticalVertices();
  613. this.geometry.buffers[0].update();
  614. this.geometry.buffers[1].update();
  615. };
  616. return NineSlicePlane;
  617. }(SimplePlane));
  618. exports.NineSlicePlane = NineSlicePlane;
  619. exports.PlaneGeometry = PlaneGeometry;
  620. exports.RopeGeometry = RopeGeometry;
  621. exports.SimpleMesh = SimpleMesh;
  622. exports.SimplePlane = SimplePlane;
  623. exports.SimpleRope = SimpleRope;
  624. //# sourceMappingURL=mesh-extras.js.map