| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841 |
- /*!
- * @pixi/mesh-extras - v6.5.10
- * Compiled Thu, 06 Jul 2023 15:25:11 UTC
- *
- * @pixi/mesh-extras is licensed under the MIT License.
- * http://www.opensource.org/licenses/mit-license
- */
- this.PIXI = this.PIXI || {};
- var _pixi_mesh_extras = (function (exports, mesh, constants, core) {
- 'use strict';
- /*! *****************************************************************************
- Copyright (c) Microsoft Corporation.
- Permission to use, copy, modify, and/or distribute this software for any
- purpose with or without fee is hereby granted.
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- PERFORMANCE OF THIS SOFTWARE.
- ***************************************************************************** */
- /* global Reflect, Promise */
- var extendStatics = function(d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
- return extendStatics(d, b);
- };
- function __extends(d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- }
- var __assign = function() {
- __assign = Object.assign || function __assign(t) {
- var arguments$1 = arguments;
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments$1[i];
- for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p)) { t[p] = s[p]; } }
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- function __rest(s, e) {
- var t = {};
- for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
- { t[p] = s[p]; } }
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
- { for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
- { t[p[i]] = s[p[i]]; }
- } }
- return t;
- }
- function __decorate(decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") { r = Reflect.decorate(decorators, target, key, desc); }
- else { for (var i = decorators.length - 1; i >= 0; i--) { if (d = decorators[i]) { r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; } } }
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- }
- function __param(paramIndex, decorator) {
- return function (target, key) { decorator(target, key, paramIndex); }
- }
- function __metadata(metadataKey, metadataValue) {
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") { return Reflect.metadata(metadataKey, metadataValue); }
- }
- function __awaiter(thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- }
- function __generator(thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) { throw t[1]; } return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) { throw new TypeError("Generator is already executing."); }
- while (_) { try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) { return t; }
- if (y = 0, t) { op = [op[0] & 2, t.value]; }
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) { _.ops.pop(); }
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } }
- if (op[0] & 5) { throw op[1]; } return { value: op[0] ? op[1] : void 0, done: true };
- }
- }
- function __createBinding(o, m, k, k2) {
- if (k2 === undefined) { k2 = k; }
- o[k2] = m[k];
- }
- function __exportStar(m, exports) {
- for (var p in m) { if (p !== "default" && !exports.hasOwnProperty(p)) { exports[p] = m[p]; } }
- }
- function __values(o) {
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
- if (m) { return m.call(o); }
- if (o && typeof o.length === "number") { return {
- next: function () {
- if (o && i >= o.length) { o = void 0; }
- return { value: o && o[i++], done: !o };
- }
- }; }
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
- }
- function __read(o, n) {
- var m = typeof Symbol === "function" && o[Symbol.iterator];
- if (!m) { return o; }
- var i = m.call(o), r, ar = [], e;
- try {
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) { ar.push(r.value); }
- }
- catch (error) { e = { error: error }; }
- finally {
- try {
- if (r && !r.done && (m = i["return"])) { m.call(i); }
- }
- finally { if (e) { throw e.error; } }
- }
- return ar;
- }
- function __spread() {
- var arguments$1 = arguments;
- for (var ar = [], i = 0; i < arguments.length; i++)
- { ar = ar.concat(__read(arguments$1[i])); }
- return ar;
- }
- function __spreadArrays() {
- var arguments$1 = arguments;
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) { s += arguments$1[i].length; }
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
- { for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
- { r[k] = a[j]; } }
- return r;
- };
- function __await(v) {
- return this instanceof __await ? (this.v = v, this) : new __await(v);
- }
- function __asyncGenerator(thisArg, _arguments, generator) {
- if (!Symbol.asyncIterator) { throw new TypeError("Symbol.asyncIterator is not defined."); }
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
- function verb(n) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } }
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
- function fulfill(value) { resume("next", value); }
- function reject(value) { resume("throw", value); }
- function settle(f, v) { if (f(v), q.shift(), q.length) { resume(q[0][0], q[0][1]); } }
- }
- function __asyncDelegator(o) {
- var i, p;
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
- }
- function __asyncValues(o) {
- if (!Symbol.asyncIterator) { throw new TypeError("Symbol.asyncIterator is not defined."); }
- var m = o[Symbol.asyncIterator], i;
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
- }
- function __makeTemplateObject(cooked, raw) {
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
- return cooked;
- };
- function __importStar(mod) {
- if (mod && mod.__esModule) { return mod; }
- var result = {};
- if (mod != null) { for (var k in mod) { if (Object.hasOwnProperty.call(mod, k)) { result[k] = mod[k]; } } }
- result.default = mod;
- return result;
- }
- function __importDefault(mod) {
- return (mod && mod.__esModule) ? mod : { default: mod };
- }
- function __classPrivateFieldGet(receiver, privateMap) {
- if (!privateMap.has(receiver)) {
- throw new TypeError("attempted to get private field on non-instance");
- }
- return privateMap.get(receiver);
- }
- function __classPrivateFieldSet(receiver, privateMap, value) {
- if (!privateMap.has(receiver)) {
- throw new TypeError("attempted to set private field on non-instance");
- }
- privateMap.set(receiver, value);
- return value;
- }
- /**
- * @memberof PIXI
- */
- var PlaneGeometry = /** @class */ (function (_super) {
- __extends(PlaneGeometry, _super);
- /**
- * @param width - The width of the plane.
- * @param height - The height of the plane.
- * @param segWidth - Number of horizontal segments.
- * @param segHeight - Number of vertical segments.
- */
- function PlaneGeometry(width, height, segWidth, segHeight) {
- if (width === void 0) { width = 100; }
- if (height === void 0) { height = 100; }
- if (segWidth === void 0) { segWidth = 10; }
- if (segHeight === void 0) { segHeight = 10; }
- var _this = _super.call(this) || this;
- _this.segWidth = segWidth;
- _this.segHeight = segHeight;
- _this.width = width;
- _this.height = height;
- _this.build();
- return _this;
- }
- /**
- * Refreshes plane coordinates
- * @private
- */
- PlaneGeometry.prototype.build = function () {
- var total = this.segWidth * this.segHeight;
- var verts = [];
- var uvs = [];
- var indices = [];
- var segmentsX = this.segWidth - 1;
- var segmentsY = this.segHeight - 1;
- var sizeX = (this.width) / segmentsX;
- var sizeY = (this.height) / segmentsY;
- for (var i = 0; i < total; i++) {
- var x = (i % this.segWidth);
- var y = ((i / this.segWidth) | 0);
- verts.push(x * sizeX, y * sizeY);
- uvs.push(x / segmentsX, y / segmentsY);
- }
- var totalSub = segmentsX * segmentsY;
- for (var i = 0; i < totalSub; i++) {
- var xpos = i % segmentsX;
- var ypos = (i / segmentsX) | 0;
- var value = (ypos * this.segWidth) + xpos;
- var value2 = (ypos * this.segWidth) + xpos + 1;
- var value3 = ((ypos + 1) * this.segWidth) + xpos;
- var value4 = ((ypos + 1) * this.segWidth) + xpos + 1;
- indices.push(value, value2, value3, value2, value4, value3);
- }
- this.buffers[0].data = new Float32Array(verts);
- this.buffers[1].data = new Float32Array(uvs);
- this.indexBuffer.data = new Uint16Array(indices);
- // ensure that the changes are uploaded
- this.buffers[0].update();
- this.buffers[1].update();
- this.indexBuffer.update();
- };
- return PlaneGeometry;
- }(mesh.MeshGeometry));
- /**
- * RopeGeometry allows you to draw a geometry across several points and then manipulate these points.
- *
- * ```js
- * for (let i = 0; i < 20; i++) {
- * points.push(new PIXI.Point(i * 50, 0));
- * };
- * const rope = new PIXI.RopeGeometry(100, points);
- * ```
- * @memberof PIXI
- */
- var RopeGeometry = /** @class */ (function (_super) {
- __extends(RopeGeometry, _super);
- /**
- * @param width - The width (i.e., thickness) of the rope.
- * @param points - An array of {@link PIXI.Point} objects to construct this rope.
- * @param textureScale - By default the rope texture will be stretched to match
- * rope length. If textureScale is positive this value will be treated as a scaling
- * factor and the texture will preserve its aspect ratio instead. To create a tiling rope
- * set baseTexture.wrapMode to {@link PIXI.WRAP_MODES.REPEAT} and use a power of two texture,
- * then set textureScale=1 to keep the original texture pixel size.
- * In order to reduce alpha channel artifacts provide a larger texture and downsample -
- * i.e. set textureScale=0.5 to scale it down twice.
- */
- function RopeGeometry(width, points, textureScale) {
- if (width === void 0) { width = 200; }
- if (textureScale === void 0) { textureScale = 0; }
- var _this = _super.call(this, new Float32Array(points.length * 4), new Float32Array(points.length * 4), new Uint16Array((points.length - 1) * 6)) || this;
- _this.points = points;
- _this._width = width;
- _this.textureScale = textureScale;
- _this.build();
- return _this;
- }
- Object.defineProperty(RopeGeometry.prototype, "width", {
- /**
- * The width (i.e., thickness) of the rope.
- * @readonly
- */
- get: function () {
- return this._width;
- },
- enumerable: false,
- configurable: true
- });
- /** Refreshes Rope indices and uvs */
- RopeGeometry.prototype.build = function () {
- var points = this.points;
- if (!points)
- { return; }
- var vertexBuffer = this.getBuffer('aVertexPosition');
- var uvBuffer = this.getBuffer('aTextureCoord');
- var indexBuffer = this.getIndex();
- // if too little points, or texture hasn't got UVs set yet just move on.
- if (points.length < 1) {
- return;
- }
- // if the number of points has changed we will need to recreate the arraybuffers
- if (vertexBuffer.data.length / 4 !== points.length) {
- vertexBuffer.data = new Float32Array(points.length * 4);
- uvBuffer.data = new Float32Array(points.length * 4);
- indexBuffer.data = new Uint16Array((points.length - 1) * 6);
- }
- var uvs = uvBuffer.data;
- var indices = indexBuffer.data;
- uvs[0] = 0;
- uvs[1] = 0;
- uvs[2] = 0;
- uvs[3] = 1;
- var amount = 0;
- var prev = points[0];
- var textureWidth = this._width * this.textureScale;
- var total = points.length; // - 1;
- for (var i = 0; i < total; i++) {
- // time to do some smart drawing!
- var index = i * 4;
- if (this.textureScale > 0) {
- // calculate pixel distance from previous point
- var dx = prev.x - points[i].x;
- var dy = prev.y - points[i].y;
- var distance = Math.sqrt((dx * dx) + (dy * dy));
- prev = points[i];
- amount += distance / textureWidth;
- }
- else {
- // stretch texture
- amount = i / (total - 1);
- }
- uvs[index] = amount;
- uvs[index + 1] = 0;
- uvs[index + 2] = amount;
- uvs[index + 3] = 1;
- }
- var indexCount = 0;
- for (var i = 0; i < total - 1; i++) {
- var index = i * 2;
- indices[indexCount++] = index;
- indices[indexCount++] = index + 1;
- indices[indexCount++] = index + 2;
- indices[indexCount++] = index + 2;
- indices[indexCount++] = index + 1;
- indices[indexCount++] = index + 3;
- }
- // ensure that the changes are uploaded
- uvBuffer.update();
- indexBuffer.update();
- this.updateVertices();
- };
- /** refreshes vertices of Rope mesh */
- RopeGeometry.prototype.updateVertices = function () {
- var points = this.points;
- if (points.length < 1) {
- return;
- }
- var lastPoint = points[0];
- var nextPoint;
- var perpX = 0;
- var perpY = 0;
- var vertices = this.buffers[0].data;
- var total = points.length;
- for (var i = 0; i < total; i++) {
- var point = points[i];
- var index = i * 4;
- if (i < points.length - 1) {
- nextPoint = points[i + 1];
- }
- else {
- nextPoint = point;
- }
- perpY = -(nextPoint.x - lastPoint.x);
- perpX = nextPoint.y - lastPoint.y;
- var ratio = (1 - (i / (total - 1))) * 10;
- if (ratio > 1) {
- ratio = 1;
- }
- var perpLength = Math.sqrt((perpX * perpX) + (perpY * perpY));
- var num = this.textureScale > 0 ? this.textureScale * this._width / 2 : this._width / 2;
- perpX /= perpLength;
- perpY /= perpLength;
- perpX *= num;
- perpY *= num;
- vertices[index] = point.x + perpX;
- vertices[index + 1] = point.y + perpY;
- vertices[index + 2] = point.x - perpX;
- vertices[index + 3] = point.y - perpY;
- lastPoint = point;
- }
- this.buffers[0].update();
- };
- RopeGeometry.prototype.update = function () {
- if (this.textureScale > 0) {
- this.build(); // we need to update UVs
- }
- else {
- this.updateVertices();
- }
- };
- return RopeGeometry;
- }(mesh.MeshGeometry));
- /**
- * The rope allows you to draw a texture across several points and then manipulate these points
- *
- *```js
- * for (let i = 0; i < 20; i++) {
- * points.push(new PIXI.Point(i * 50, 0));
- * };
- * let rope = new PIXI.SimpleRope(PIXI.Texture.from("snake.png"), points);
- * ```
- * @memberof PIXI
- */
- var SimpleRope = /** @class */ (function (_super) {
- __extends(SimpleRope, _super);
- /**
- * @param texture - The texture to use on the rope.
- * @param points - An array of {@link PIXI.Point} objects to construct this rope.
- * @param {number} textureScale - Optional. Positive values scale rope texture
- * keeping its aspect ratio. You can reduce alpha channel artifacts by providing a larger texture
- * and downsampling here. If set to zero, texture will be stretched instead.
- */
- function SimpleRope(texture, points, textureScale) {
- if (textureScale === void 0) { textureScale = 0; }
- var _this = this;
- var ropeGeometry = new RopeGeometry(texture.height, points, textureScale);
- var meshMaterial = new mesh.MeshMaterial(texture);
- if (textureScale > 0) {
- // attempt to set UV wrapping, will fail on non-power of two textures
- texture.baseTexture.wrapMode = constants.WRAP_MODES.REPEAT;
- }
- _this = _super.call(this, ropeGeometry, meshMaterial) || this;
- /**
- * re-calculate vertices by rope points each frame
- * @member {boolean}
- */
- _this.autoUpdate = true;
- return _this;
- }
- SimpleRope.prototype._render = function (renderer) {
- var geometry = this.geometry;
- if (this.autoUpdate || geometry._width !== this.shader.texture.height) {
- geometry._width = this.shader.texture.height;
- geometry.update();
- }
- _super.prototype._render.call(this, renderer);
- };
- return SimpleRope;
- }(mesh.Mesh));
- /**
- * The SimplePlane allows you to draw a texture across several points and then manipulate these points
- *
- *```js
- * for (let i = 0; i < 20; i++) {
- * points.push(new PIXI.Point(i * 50, 0));
- * };
- * let SimplePlane = new PIXI.SimplePlane(PIXI.Texture.from("snake.png"), points);
- * ```
- * @memberof PIXI
- */
- var SimplePlane = /** @class */ (function (_super) {
- __extends(SimplePlane, _super);
- /**
- * @param texture - The texture to use on the SimplePlane.
- * @param verticesX - The number of vertices in the x-axis
- * @param verticesY - The number of vertices in the y-axis
- */
- function SimplePlane(texture, verticesX, verticesY) {
- var _this = this;
- var planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY);
- var meshMaterial = new mesh.MeshMaterial(core.Texture.WHITE);
- _this = _super.call(this, planeGeometry, meshMaterial) || this;
- // lets call the setter to ensure all necessary updates are performed
- _this.texture = texture;
- _this.autoResize = true;
- return _this;
- }
- /**
- * Method used for overrides, to do something in case texture frame was changed.
- * Meshes based on plane can override it and change more details based on texture.
- */
- SimplePlane.prototype.textureUpdated = function () {
- this._textureID = this.shader.texture._updateID;
- var geometry = this.geometry;
- var _a = this.shader.texture, width = _a.width, height = _a.height;
- if (this.autoResize && (geometry.width !== width || geometry.height !== height)) {
- geometry.width = this.shader.texture.width;
- geometry.height = this.shader.texture.height;
- geometry.build();
- }
- };
- Object.defineProperty(SimplePlane.prototype, "texture", {
- get: function () {
- return this.shader.texture;
- },
- set: function (value) {
- // Track texture same way sprite does.
- // For generated meshes like NineSlicePlane it can change the geometry.
- // Unfortunately, this method might not work if you directly change texture in material.
- if (this.shader.texture === value) {
- return;
- }
- this.shader.texture = value;
- this._textureID = -1;
- if (value.baseTexture.valid) {
- this.textureUpdated();
- }
- else {
- value.once('update', this.textureUpdated, this);
- }
- },
- enumerable: false,
- configurable: true
- });
- SimplePlane.prototype._render = function (renderer) {
- if (this._textureID !== this.shader.texture._updateID) {
- this.textureUpdated();
- }
- _super.prototype._render.call(this, renderer);
- };
- SimplePlane.prototype.destroy = function (options) {
- this.shader.texture.off('update', this.textureUpdated, this);
- _super.prototype.destroy.call(this, options);
- };
- return SimplePlane;
- }(mesh.Mesh));
- /**
- * The Simple Mesh class mimics Mesh in PixiJS v4, providing easy-to-use constructor arguments.
- * For more robust customization, use {@link PIXI.Mesh}.
- * @memberof PIXI
- */
- var SimpleMesh = /** @class */ (function (_super) {
- __extends(SimpleMesh, _super);
- /**
- * @param texture - The texture to use
- * @param {Float32Array} [vertices] - if you want to specify the vertices
- * @param {Float32Array} [uvs] - if you want to specify the uvs
- * @param {Uint16Array} [indices] - if you want to specify the indices
- * @param drawMode - the drawMode, can be any of the Mesh.DRAW_MODES consts
- */
- function SimpleMesh(texture, vertices, uvs, indices, drawMode) {
- if (texture === void 0) { texture = core.Texture.EMPTY; }
- var _this = this;
- var geometry = new mesh.MeshGeometry(vertices, uvs, indices);
- geometry.getBuffer('aVertexPosition').static = false;
- var meshMaterial = new mesh.MeshMaterial(texture);
- _this = _super.call(this, geometry, meshMaterial, null, drawMode) || this;
- _this.autoUpdate = true;
- return _this;
- }
- Object.defineProperty(SimpleMesh.prototype, "vertices", {
- /**
- * Collection of vertices data.
- * @type {Float32Array}
- */
- get: function () {
- return this.geometry.getBuffer('aVertexPosition').data;
- },
- set: function (value) {
- this.geometry.getBuffer('aVertexPosition').data = value;
- },
- enumerable: false,
- configurable: true
- });
- SimpleMesh.prototype._render = function (renderer) {
- if (this.autoUpdate) {
- this.geometry.getBuffer('aVertexPosition').update();
- }
- _super.prototype._render.call(this, renderer);
- };
- return SimpleMesh;
- }(mesh.Mesh));
- var DEFAULT_BORDER_SIZE = 10;
- /**
- * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful
- * for buttons with rounded corners for example) and the other areas will be scaled horizontally and or vertically
- *
- *```js
- * let Plane9 = new PIXI.NineSlicePlane(PIXI.Texture.from('BoxWithRoundedCorners.png'), 15, 15, 15, 15);
- * ```
- * <pre>
- * A B
- * +---+----------------------+---+
- * C | 1 | 2 | 3 |
- * +---+----------------------+---+
- * | | | |
- * | 4 | 5 | 6 |
- * | | | |
- * +---+----------------------+---+
- * D | 7 | 8 | 9 |
- * +---+----------------------+---+
- * When changing this objects width and/or height:
- * areas 1 3 7 and 9 will remain unscaled.
- * areas 2 and 8 will be stretched horizontally
- * areas 4 and 6 will be stretched vertically
- * area 5 will be stretched both horizontally and vertically
- * </pre>
- * @memberof PIXI
- */
- var NineSlicePlane = /** @class */ (function (_super) {
- __extends(NineSlicePlane, _super);
- /**
- * @param texture - The texture to use on the NineSlicePlane.
- * @param {number} [leftWidth=10] - size of the left vertical bar (A)
- * @param {number} [topHeight=10] - size of the top horizontal bar (C)
- * @param {number} [rightWidth=10] - size of the right vertical bar (B)
- * @param {number} [bottomHeight=10] - size of the bottom horizontal bar (D)
- */
- function NineSlicePlane(texture, leftWidth, topHeight, rightWidth, bottomHeight) {
- if (leftWidth === void 0) { leftWidth = DEFAULT_BORDER_SIZE; }
- if (topHeight === void 0) { topHeight = DEFAULT_BORDER_SIZE; }
- if (rightWidth === void 0) { rightWidth = DEFAULT_BORDER_SIZE; }
- if (bottomHeight === void 0) { bottomHeight = DEFAULT_BORDER_SIZE; }
- var _this = _super.call(this, core.Texture.WHITE, 4, 4) || this;
- _this._origWidth = texture.orig.width;
- _this._origHeight = texture.orig.height;
- /** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
- _this._width = _this._origWidth;
- /** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
- _this._height = _this._origHeight;
- _this._leftWidth = leftWidth;
- _this._rightWidth = rightWidth;
- _this._topHeight = topHeight;
- _this._bottomHeight = bottomHeight;
- // lets call the setter to ensure all necessary updates are performed
- _this.texture = texture;
- return _this;
- }
- NineSlicePlane.prototype.textureUpdated = function () {
- this._textureID = this.shader.texture._updateID;
- this._refresh();
- };
- Object.defineProperty(NineSlicePlane.prototype, "vertices", {
- get: function () {
- return this.geometry.getBuffer('aVertexPosition').data;
- },
- set: function (value) {
- this.geometry.getBuffer('aVertexPosition').data = value;
- },
- enumerable: false,
- configurable: true
- });
- /** Updates the horizontal vertices. */
- NineSlicePlane.prototype.updateHorizontalVertices = function () {
- var vertices = this.vertices;
- var scale = this._getMinScale();
- vertices[9] = vertices[11] = vertices[13] = vertices[15] = this._topHeight * scale;
- vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - (this._bottomHeight * scale);
- vertices[25] = vertices[27] = vertices[29] = vertices[31] = this._height;
- };
- /** Updates the vertical vertices. */
- NineSlicePlane.prototype.updateVerticalVertices = function () {
- var vertices = this.vertices;
- var scale = this._getMinScale();
- vertices[2] = vertices[10] = vertices[18] = vertices[26] = this._leftWidth * scale;
- vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - (this._rightWidth * scale);
- vertices[6] = vertices[14] = vertices[22] = vertices[30] = this._width;
- };
- /**
- * Returns the smaller of a set of vertical and horizontal scale of nine slice corners.
- * @returns Smaller number of vertical and horizontal scale.
- */
- NineSlicePlane.prototype._getMinScale = function () {
- var w = this._leftWidth + this._rightWidth;
- var scaleW = this._width > w ? 1.0 : this._width / w;
- var h = this._topHeight + this._bottomHeight;
- var scaleH = this._height > h ? 1.0 : this._height / h;
- var scale = Math.min(scaleW, scaleH);
- return scale;
- };
- Object.defineProperty(NineSlicePlane.prototype, "width", {
- /** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
- get: function () {
- return this._width;
- },
- set: function (value) {
- this._width = value;
- this._refresh();
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(NineSlicePlane.prototype, "height", {
- /** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
- get: function () {
- return this._height;
- },
- set: function (value) {
- this._height = value;
- this._refresh();
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(NineSlicePlane.prototype, "leftWidth", {
- /** The width of the left column. */
- get: function () {
- return this._leftWidth;
- },
- set: function (value) {
- this._leftWidth = value;
- this._refresh();
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(NineSlicePlane.prototype, "rightWidth", {
- /** The width of the right column. */
- get: function () {
- return this._rightWidth;
- },
- set: function (value) {
- this._rightWidth = value;
- this._refresh();
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(NineSlicePlane.prototype, "topHeight", {
- /** The height of the top row. */
- get: function () {
- return this._topHeight;
- },
- set: function (value) {
- this._topHeight = value;
- this._refresh();
- },
- enumerable: false,
- configurable: true
- });
- Object.defineProperty(NineSlicePlane.prototype, "bottomHeight", {
- /** The height of the bottom row. */
- get: function () {
- return this._bottomHeight;
- },
- set: function (value) {
- this._bottomHeight = value;
- this._refresh();
- },
- enumerable: false,
- configurable: true
- });
- /** Refreshes NineSlicePlane coords. All of them. */
- NineSlicePlane.prototype._refresh = function () {
- var texture = this.texture;
- var uvs = this.geometry.buffers[1].data;
- this._origWidth = texture.orig.width;
- this._origHeight = texture.orig.height;
- var _uvw = 1.0 / this._origWidth;
- var _uvh = 1.0 / this._origHeight;
- uvs[0] = uvs[8] = uvs[16] = uvs[24] = 0;
- uvs[1] = uvs[3] = uvs[5] = uvs[7] = 0;
- uvs[6] = uvs[14] = uvs[22] = uvs[30] = 1;
- uvs[25] = uvs[27] = uvs[29] = uvs[31] = 1;
- uvs[2] = uvs[10] = uvs[18] = uvs[26] = _uvw * this._leftWidth;
- uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - (_uvw * this._rightWidth);
- uvs[9] = uvs[11] = uvs[13] = uvs[15] = _uvh * this._topHeight;
- uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - (_uvh * this._bottomHeight);
- this.updateHorizontalVertices();
- this.updateVerticalVertices();
- this.geometry.buffers[0].update();
- this.geometry.buffers[1].update();
- };
- return NineSlicePlane;
- }(SimplePlane));
- exports.NineSlicePlane = NineSlicePlane;
- exports.PlaneGeometry = PlaneGeometry;
- exports.RopeGeometry = RopeGeometry;
- exports.SimpleMesh = SimpleMesh;
- exports.SimplePlane = SimplePlane;
- exports.SimpleRope = SimpleRope;
- Object.defineProperty(exports, '__esModule', { value: true });
- return exports;
- })({}, PIXI, PIXI, PIXI);
- Object.assign(this.PIXI, _pixi_mesh_extras);
- //# sourceMappingURL=mesh-extras.js.map
|