mesh-extras.mjs 24 KB

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