@pixi/mesh-extras
Advanced tools
Comparing version 6.5.3 to 7.0.0-alpha
/*! | ||
* @pixi/mesh-extras - v6.5.3 | ||
* Compiled Fri, 09 Sep 2022 13:55:20 UTC | ||
* @pixi/mesh-extras - v7.0.0-alpha | ||
* Compiled Fri, 09 Sep 2022 16:09:18 UTC | ||
* | ||
@@ -13,621 +13,354 @@ * @pixi/mesh-extras is licensed under the MIT License. | ||
var mesh = require('@pixi/mesh'); | ||
var constants = require('@pixi/constants'); | ||
var core = require('@pixi/core'); | ||
/*! ***************************************************************************** | ||
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 __()); | ||
class PlaneGeometry extends mesh.MeshGeometry { | ||
constructor(width = 100, height = 100, segWidth = 10, segHeight = 10) { | ||
super(); | ||
this.segWidth = segWidth; | ||
this.segHeight = segHeight; | ||
this.width = width; | ||
this.height = height; | ||
this.build(); | ||
} | ||
build() { | ||
const total = this.segWidth * this.segHeight; | ||
const verts = []; | ||
const uvs = []; | ||
const indices = []; | ||
const segmentsX = this.segWidth - 1; | ||
const segmentsY = this.segHeight - 1; | ||
const sizeX = this.width / segmentsX; | ||
const sizeY = this.height / segmentsY; | ||
for (let i = 0; i < total; i++) { | ||
const x = i % this.segWidth; | ||
const y = i / this.segWidth | 0; | ||
verts.push(x * sizeX, y * sizeY); | ||
uvs.push(x / segmentsX, y / segmentsY); | ||
} | ||
const totalSub = segmentsX * segmentsY; | ||
for (let i = 0; i < totalSub; i++) { | ||
const xpos = i % segmentsX; | ||
const ypos = i / segmentsX | 0; | ||
const value = ypos * this.segWidth + xpos; | ||
const value2 = ypos * this.segWidth + xpos + 1; | ||
const value3 = (ypos + 1) * this.segWidth + xpos; | ||
const 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); | ||
this.buffers[0].update(); | ||
this.buffers[1].update(); | ||
this.indexBuffer.update(); | ||
} | ||
} | ||
/** | ||
* @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; | ||
class RopeGeometry extends mesh.MeshGeometry { | ||
constructor(width = 200, points, textureScale = 0) { | ||
super(new Float32Array(points.length * 4), new Float32Array(points.length * 4), new Uint16Array((points.length - 1) * 6)); | ||
this.points = points; | ||
this._width = width; | ||
this.textureScale = textureScale; | ||
this.build(); | ||
} | ||
get width() { | ||
return this._width; | ||
} | ||
build() { | ||
const points = this.points; | ||
if (!points) | ||
return; | ||
const vertexBuffer = this.getBuffer("aVertexPosition"); | ||
const uvBuffer = this.getBuffer("aTextureCoord"); | ||
const indexBuffer = this.getIndex(); | ||
if (points.length < 1) { | ||
return; | ||
} | ||
/** | ||
* 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; | ||
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); | ||
} | ||
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 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; | ||
const uvs = uvBuffer.data; | ||
const indices = indexBuffer.data; | ||
uvs[0] = 0; | ||
uvs[1] = 0; | ||
uvs[2] = 0; | ||
uvs[3] = 1; | ||
let amount = 0; | ||
let prev = points[0]; | ||
const textureWidth = this._width * this.textureScale; | ||
const total = points.length; | ||
for (let i = 0; i < total; i++) { | ||
const index = i * 4; | ||
if (this.textureScale > 0) { | ||
const dx = prev.x - points[i].x; | ||
const dy = prev.y - points[i].y; | ||
const distance = Math.sqrt(dx * dx + dy * dy); | ||
prev = points[i]; | ||
amount += distance / textureWidth; | ||
} else { | ||
amount = i / (total - 1); | ||
} | ||
uvs[index] = amount; | ||
uvs[index + 1] = 0; | ||
uvs[index + 2] = amount; | ||
uvs[index + 3] = 1; | ||
} | ||
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)); | ||
let indexCount = 0; | ||
for (let i = 0; i < total - 1; i++) { | ||
const 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; | ||
} | ||
uvBuffer.update(); | ||
indexBuffer.update(); | ||
this.updateVertices(); | ||
} | ||
updateVertices() { | ||
const points = this.points; | ||
if (points.length < 1) { | ||
return; | ||
} | ||
let lastPoint = points[0]; | ||
let nextPoint; | ||
let perpX = 0; | ||
let perpY = 0; | ||
const vertices = this.buffers[0].data; | ||
const total = points.length; | ||
for (let i = 0; i < total; i++) { | ||
const point = points[i]; | ||
const 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; | ||
const perpLength = Math.sqrt(perpX * perpX + perpY * perpY); | ||
const 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(); | ||
} | ||
update() { | ||
if (this.textureScale > 0) { | ||
this.build(); | ||
} else { | ||
this.updateVertices(); | ||
} | ||
} | ||
} | ||
/** | ||
* 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; | ||
class SimpleRope extends mesh.Mesh { | ||
constructor(texture, points, textureScale = 0) { | ||
const ropeGeometry = new RopeGeometry(texture.height, points, textureScale); | ||
const meshMaterial = new mesh.MeshMaterial(texture); | ||
if (textureScale > 0) { | ||
texture.baseTexture.wrapMode = core.WRAP_MODES.REPEAT; | ||
} | ||
/** | ||
* 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)); | ||
super(ropeGeometry, meshMaterial); | ||
this.autoUpdate = true; | ||
} | ||
_render(renderer) { | ||
const geometry = this.geometry; | ||
if (this.autoUpdate || geometry._width !== this.shader.texture.height) { | ||
geometry._width = this.shader.texture.height; | ||
geometry.update(); | ||
} | ||
super._render(renderer); | ||
} | ||
} | ||
/** | ||
* 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; | ||
class SimplePlane extends mesh.Mesh { | ||
constructor(texture, verticesX, verticesY) { | ||
const planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY); | ||
const meshMaterial = new mesh.MeshMaterial(core.Texture.WHITE); | ||
super(planeGeometry, meshMaterial); | ||
this.texture = texture; | ||
this.autoResize = true; | ||
} | ||
textureUpdated() { | ||
this._textureID = this.shader.texture._updateID; | ||
const geometry = this.geometry; | ||
const { width, height } = this.shader.texture; | ||
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(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)); | ||
} | ||
set texture(value) { | ||
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); | ||
} | ||
} | ||
get texture() { | ||
return this.shader.texture; | ||
} | ||
_render(renderer) { | ||
if (this._textureID !== this.shader.texture._updateID) { | ||
this.textureUpdated(); | ||
} | ||
super._render(renderer); | ||
} | ||
destroy(options) { | ||
this.shader.texture.off("update", this.textureUpdated, this); | ||
super.destroy(options); | ||
} | ||
} | ||
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; | ||
class SimpleMesh extends mesh.Mesh { | ||
constructor(texture = core.Texture.EMPTY, vertices, uvs, indices, drawMode) { | ||
const geometry = new mesh.MeshGeometry(vertices, uvs, indices); | ||
geometry.getBuffer("aVertexPosition").static = false; | ||
const meshMaterial = new mesh.MeshMaterial(texture); | ||
super(geometry, meshMaterial, null, drawMode); | ||
this.autoUpdate = true; | ||
} | ||
get vertices() { | ||
return this.geometry.getBuffer("aVertexPosition").data; | ||
} | ||
set vertices(value) { | ||
this.geometry.getBuffer("aVertexPosition").data = value; | ||
} | ||
_render(renderer) { | ||
if (this.autoUpdate) { | ||
this.geometry.getBuffer("aVertexPosition").update(); | ||
} | ||
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)); | ||
super._render(renderer); | ||
} | ||
} | ||
const DEFAULT_BORDER_SIZE = 10; | ||
class NineSlicePlane extends SimplePlane { | ||
constructor(texture, leftWidth = DEFAULT_BORDER_SIZE, topHeight = DEFAULT_BORDER_SIZE, rightWidth = DEFAULT_BORDER_SIZE, bottomHeight = DEFAULT_BORDER_SIZE) { | ||
super(core.Texture.WHITE, 4, 4); | ||
this._origWidth = texture.orig.width; | ||
this._origHeight = texture.orig.height; | ||
this._width = this._origWidth; | ||
this._height = this._origHeight; | ||
this._leftWidth = leftWidth; | ||
this._rightWidth = rightWidth; | ||
this._topHeight = topHeight; | ||
this._bottomHeight = bottomHeight; | ||
this.texture = texture; | ||
} | ||
textureUpdated() { | ||
this._textureID = this.shader.texture._updateID; | ||
this._refresh(); | ||
} | ||
get vertices() { | ||
return this.geometry.getBuffer("aVertexPosition").data; | ||
} | ||
set vertices(value) { | ||
this.geometry.getBuffer("aVertexPosition").data = value; | ||
} | ||
updateHorizontalVertices() { | ||
const vertices = this.vertices; | ||
const 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; | ||
} | ||
updateVerticalVertices() { | ||
const vertices = this.vertices; | ||
const 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; | ||
} | ||
_getMinScale() { | ||
const w = this._leftWidth + this._rightWidth; | ||
const scaleW = this._width > w ? 1 : this._width / w; | ||
const h = this._topHeight + this._bottomHeight; | ||
const scaleH = this._height > h ? 1 : this._height / h; | ||
const scale = Math.min(scaleW, scaleH); | ||
return scale; | ||
} | ||
get width() { | ||
return this._width; | ||
} | ||
set width(value) { | ||
this._width = value; | ||
this._refresh(); | ||
} | ||
get height() { | ||
return this._height; | ||
} | ||
set height(value) { | ||
this._height = value; | ||
this._refresh(); | ||
} | ||
get leftWidth() { | ||
return this._leftWidth; | ||
} | ||
set leftWidth(value) { | ||
this._leftWidth = value; | ||
this._refresh(); | ||
} | ||
get rightWidth() { | ||
return this._rightWidth; | ||
} | ||
set rightWidth(value) { | ||
this._rightWidth = value; | ||
this._refresh(); | ||
} | ||
get topHeight() { | ||
return this._topHeight; | ||
} | ||
set topHeight(value) { | ||
this._topHeight = value; | ||
this._refresh(); | ||
} | ||
get bottomHeight() { | ||
return this._bottomHeight; | ||
} | ||
set bottomHeight(value) { | ||
this._bottomHeight = value; | ||
this._refresh(); | ||
} | ||
_refresh() { | ||
const texture = this.texture; | ||
const uvs = this.geometry.buffers[1].data; | ||
this._origWidth = texture.orig.width; | ||
this._origHeight = texture.orig.height; | ||
const _uvw = 1 / this._origWidth; | ||
const _uvh = 1 / 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(); | ||
} | ||
} | ||
exports.NineSlicePlane = NineSlicePlane; | ||
@@ -634,0 +367,0 @@ exports.PlaneGeometry = PlaneGeometry; |
@@ -1,9 +0,8 @@ | ||
/*! | ||
* @pixi/mesh-extras - v6.5.3 | ||
* Compiled Fri, 09 Sep 2022 13:55:20 UTC | ||
"use strict";/*! | ||
* @pixi/mesh-extras - v7.0.0-alpha | ||
* Compiled Fri, 09 Sep 2022 16:09:18 UTC | ||
* | ||
* @pixi/mesh-extras is licensed under the MIT License. | ||
* http://www.opensource.org/licenses/mit-license | ||
*/ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@pixi/mesh"),e=require("@pixi/constants"),i=require("@pixi/core"),r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])},r(t,e)};function h(t,e){function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var o=function(t){function e(e,i,r,h){void 0===e&&(e=100),void 0===i&&(i=100),void 0===r&&(r=10),void 0===h&&(h=10);var o=t.call(this)||this;return o.segWidth=r,o.segHeight=h,o.width=e,o.height=i,o.build(),o}return h(e,t),e.prototype.build=function(){for(var t=this.segWidth*this.segHeight,e=[],i=[],r=[],h=this.segWidth-1,o=this.segHeight-1,s=this.width/h,n=this.height/o,a=0;a<t;a++){var u=a%this.segWidth,d=a/this.segWidth|0;e.push(u*s,d*n),i.push(u/h,d/o)}var p=h*o;for(a=0;a<p;a++){var f=a%h,g=a/h|0,c=g*this.segWidth+f,l=g*this.segWidth+f+1,_=(g+1)*this.segWidth+f,y=(g+1)*this.segWidth+f+1;r.push(c,l,_,l,y,_)}this.buffers[0].data=new Float32Array(e),this.buffers[1].data=new Float32Array(i),this.indexBuffer.data=new Uint16Array(r),this.buffers[0].update(),this.buffers[1].update(),this.indexBuffer.update()},e}(t.MeshGeometry),s=function(t){function e(e,i,r){void 0===e&&(e=200),void 0===r&&(r=0);var h=t.call(this,new Float32Array(4*i.length),new Float32Array(4*i.length),new Uint16Array(6*(i.length-1)))||this;return h.points=i,h._width=e,h.textureScale=r,h.build(),h}return h(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),e.prototype.build=function(){var t=this.points;if(t){var e=this.getBuffer("aVertexPosition"),i=this.getBuffer("aTextureCoord"),r=this.getIndex();if(!(t.length<1)){e.data.length/4!==t.length&&(e.data=new Float32Array(4*t.length),i.data=new Float32Array(4*t.length),r.data=new Uint16Array(6*(t.length-1)));var h=i.data,o=r.data;h[0]=0,h[1]=0,h[2]=0,h[3]=1;for(var s=0,n=t[0],a=this._width*this.textureScale,u=t.length,d=0;d<u;d++){var p=4*d;if(this.textureScale>0){var f=n.x-t[d].x,g=n.y-t[d].y,c=Math.sqrt(f*f+g*g);n=t[d],s+=c/a}else s=d/(u-1);h[p]=s,h[p+1]=0,h[p+2]=s,h[p+3]=1}var l=0;for(d=0;d<u-1;d++){p=2*d;o[l++]=p,o[l++]=p+1,o[l++]=p+2,o[l++]=p+2,o[l++]=p+1,o[l++]=p+3}i.update(),r.update(),this.updateVertices()}}},e.prototype.updateVertices=function(){var t=this.points;if(!(t.length<1)){for(var e,i=t[0],r=0,h=0,o=this.buffers[0].data,s=t.length,n=0;n<s;n++){var a=t[n],u=4*n;h=-((e=n<t.length-1?t[n+1]:a).x-i.x),r=e.y-i.y;var d=Math.sqrt(r*r+h*h),p=this.textureScale>0?this.textureScale*this._width/2:this._width/2;r/=d,h/=d,r*=p,h*=p,o[u]=a.x+r,o[u+1]=a.y+h,o[u+2]=a.x-r,o[u+3]=a.y-h,i=a}this.buffers[0].update()}},e.prototype.update=function(){this.textureScale>0?this.build():this.updateVertices()},e}(t.MeshGeometry),n=function(i){function r(r,h,o){void 0===o&&(o=0);var n=this,a=new s(r.height,h,o),u=new t.MeshMaterial(r);return o>0&&(r.baseTexture.wrapMode=e.WRAP_MODES.REPEAT),(n=i.call(this,a,u)||this).autoUpdate=!0,n}return h(r,i),r.prototype._render=function(t){var e=this.geometry;(this.autoUpdate||e._width!==this.shader.texture.height)&&(e._width=this.shader.texture.height,e.update()),i.prototype._render.call(this,t)},r}(t.Mesh),a=function(e){function r(r,h,s){var n=this,a=new o(r.width,r.height,h,s),u=new t.MeshMaterial(i.Texture.WHITE);return(n=e.call(this,a,u)||this).texture=r,n.autoResize=!0,n}return h(r,e),r.prototype.textureUpdated=function(){this._textureID=this.shader.texture._updateID;var t=this.geometry,e=this.shader.texture,i=e.width,r=e.height;!this.autoResize||t.width===i&&t.height===r||(t.width=this.shader.texture.width,t.height=this.shader.texture.height,t.build())},Object.defineProperty(r.prototype,"texture",{get:function(){return this.shader.texture},set:function(t){this.shader.texture!==t&&(this.shader.texture=t,this._textureID=-1,t.baseTexture.valid?this.textureUpdated():t.once("update",this.textureUpdated,this))},enumerable:!1,configurable:!0}),r.prototype._render=function(t){this._textureID!==this.shader.texture._updateID&&this.textureUpdated(),e.prototype._render.call(this,t)},r.prototype.destroy=function(t){this.shader.texture.off("update",this.textureUpdated,this),e.prototype.destroy.call(this,t)},r}(t.Mesh),u=function(e){function r(r,h,o,s,n){void 0===r&&(r=i.Texture.EMPTY);var a=this,u=new t.MeshGeometry(h,o,s);u.getBuffer("aVertexPosition").static=!1;var d=new t.MeshMaterial(r);return(a=e.call(this,u,d,null,n)||this).autoUpdate=!0,a}return h(r,e),Object.defineProperty(r.prototype,"vertices",{get:function(){return this.geometry.getBuffer("aVertexPosition").data},set:function(t){this.geometry.getBuffer("aVertexPosition").data=t},enumerable:!1,configurable:!0}),r.prototype._render=function(t){this.autoUpdate&&this.geometry.getBuffer("aVertexPosition").update(),e.prototype._render.call(this,t)},r}(t.Mesh),d=function(t){function e(e,r,h,o,s){void 0===r&&(r=10),void 0===h&&(h=10),void 0===o&&(o=10),void 0===s&&(s=10);var n=t.call(this,i.Texture.WHITE,4,4)||this;return n._origWidth=e.orig.width,n._origHeight=e.orig.height,n._width=n._origWidth,n._height=n._origHeight,n._leftWidth=r,n._rightWidth=o,n._topHeight=h,n._bottomHeight=s,n.texture=e,n}return h(e,t),e.prototype.textureUpdated=function(){this._textureID=this.shader.texture._updateID,this._refresh()},Object.defineProperty(e.prototype,"vertices",{get:function(){return this.geometry.getBuffer("aVertexPosition").data},set:function(t){this.geometry.getBuffer("aVertexPosition").data=t},enumerable:!1,configurable:!0}),e.prototype.updateHorizontalVertices=function(){var t=this.vertices,e=this._getMinScale();t[9]=t[11]=t[13]=t[15]=this._topHeight*e,t[17]=t[19]=t[21]=t[23]=this._height-this._bottomHeight*e,t[25]=t[27]=t[29]=t[31]=this._height},e.prototype.updateVerticalVertices=function(){var t=this.vertices,e=this._getMinScale();t[2]=t[10]=t[18]=t[26]=this._leftWidth*e,t[4]=t[12]=t[20]=t[28]=this._width-this._rightWidth*e,t[6]=t[14]=t[22]=t[30]=this._width},e.prototype._getMinScale=function(){var t=this._leftWidth+this._rightWidth,e=this._width>t?1:this._width/t,i=this._topHeight+this._bottomHeight,r=this._height>i?1:this._height/i;return Math.min(e,r)},Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"leftWidth",{get:function(){return this._leftWidth},set:function(t){this._leftWidth=t,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rightWidth",{get:function(){return this._rightWidth},set:function(t){this._rightWidth=t,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"topHeight",{get:function(){return this._topHeight},set:function(t){this._topHeight=t,this._refresh()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bottomHeight",{get:function(){return this._bottomHeight},set:function(t){this._bottomHeight=t,this._refresh()},enumerable:!1,configurable:!0}),e.prototype._refresh=function(){var t=this.texture,e=this.geometry.buffers[1].data;this._origWidth=t.orig.width,this._origHeight=t.orig.height;var i=1/this._origWidth,r=1/this._origHeight;e[0]=e[8]=e[16]=e[24]=0,e[1]=e[3]=e[5]=e[7]=0,e[6]=e[14]=e[22]=e[30]=1,e[25]=e[27]=e[29]=e[31]=1,e[2]=e[10]=e[18]=e[26]=i*this._leftWidth,e[4]=e[12]=e[20]=e[28]=1-i*this._rightWidth,e[9]=e[11]=e[13]=e[15]=r*this._topHeight,e[17]=e[19]=e[21]=e[23]=1-r*this._bottomHeight,this.updateHorizontalVertices(),this.updateVerticalVertices(),this.geometry.buffers[0].update(),this.geometry.buffers[1].update()},e}(a);exports.NineSlicePlane=d,exports.PlaneGeometry=o,exports.RopeGeometry=s,exports.SimpleMesh=u,exports.SimplePlane=a,exports.SimpleRope=n; | ||
*/Object.defineProperty(exports,"__esModule",{value:!0});var c=require("@pixi/mesh"),x=require("@pixi/core");class m extends c.MeshGeometry{constructor(t=100,e=100,i=10,s=10){super(),this.segWidth=i,this.segHeight=s,this.width=t,this.height=e,this.build()}build(){const t=this.segWidth*this.segHeight,e=[],i=[],s=[],h=this.segWidth-1,d=this.segHeight-1,g=this.width/h,n=this.height/d;for(let a=0;a<t;a++){const o=a%this.segWidth,r=a/this.segWidth|0;e.push(o*g,r*n),i.push(o/h,r/d)}const l=h*d;for(let a=0;a<l;a++){const o=a%h,r=a/h|0,u=r*this.segWidth+o,p=r*this.segWidth+o+1,f=(r+1)*this.segWidth+o,y=(r+1)*this.segWidth+o+1;s.push(u,p,f,p,y,f)}this.buffers[0].data=new Float32Array(e),this.buffers[1].data=new Float32Array(i),this.indexBuffer.data=new Uint16Array(s),this.buffers[0].update(),this.buffers[1].update(),this.indexBuffer.update()}}class W extends c.MeshGeometry{constructor(t=200,e,i=0){super(new Float32Array(e.length*4),new Float32Array(e.length*4),new Uint16Array((e.length-1)*6)),this.points=e,this._width=t,this.textureScale=i,this.build()}get width(){return this._width}build(){const t=this.points;if(!t)return;const e=this.getBuffer("aVertexPosition"),i=this.getBuffer("aTextureCoord"),s=this.getIndex();if(t.length<1)return;e.data.length/4!==t.length&&(e.data=new Float32Array(t.length*4),i.data=new Float32Array(t.length*4),s.data=new Uint16Array((t.length-1)*6));const h=i.data,d=s.data;h[0]=0,h[1]=0,h[2]=0,h[3]=1;let g=0,n=t[0];const l=this._width*this.textureScale,a=t.length;for(let r=0;r<a;r++){const u=r*4;if(this.textureScale>0){const p=n.x-t[r].x,f=n.y-t[r].y,y=Math.sqrt(p*p+f*f);n=t[r],g+=y/l}else g=r/(a-1);h[u]=g,h[u+1]=0,h[u+2]=g,h[u+3]=1}let o=0;for(let r=0;r<a-1;r++){const u=r*2;d[o++]=u,d[o++]=u+1,d[o++]=u+2,d[o++]=u+2,d[o++]=u+1,d[o++]=u+3}i.update(),s.update(),this.updateVertices()}updateVertices(){const t=this.points;if(t.length<1)return;let e=t[0],i,s=0,h=0;const d=this.buffers[0].data,g=t.length;for(let n=0;n<g;n++){const l=t[n],a=n*4;n<t.length-1?i=t[n+1]:i=l,h=-(i.x-e.x),s=i.y-e.y;const o=Math.sqrt(s*s+h*h),r=this.textureScale>0?this.textureScale*this._width/2:this._width/2;s/=o,h/=o,s*=r,h*=r,d[a]=l.x+s,d[a+1]=l.y+h,d[a+2]=l.x-s,d[a+3]=l.y-h,e=l}this.buffers[0].update()}update(){this.textureScale>0?this.build():this.updateVertices()}}class H extends c.Mesh{constructor(t,e,i=0){const s=new W(t.height,e,i),h=new c.MeshMaterial(t);i>0&&(t.baseTexture.wrapMode=x.WRAP_MODES.REPEAT),super(s,h),this.autoUpdate=!0}_render(t){const e=this.geometry;(this.autoUpdate||e._width!==this.shader.texture.height)&&(e._width=this.shader.texture.height,e.update()),super._render(t)}}class b extends c.Mesh{constructor(t,e,i){const s=new m(t.width,t.height,e,i),h=new c.MeshMaterial(x.Texture.WHITE);super(s,h),this.texture=t,this.autoResize=!0}textureUpdated(){this._textureID=this.shader.texture._updateID;const t=this.geometry,{width:e,height:i}=this.shader.texture;this.autoResize&&(t.width!==e||t.height!==i)&&(t.width=this.shader.texture.width,t.height=this.shader.texture.height,t.build())}set texture(t){this.shader.texture!==t&&(this.shader.texture=t,this._textureID=-1,t.baseTexture.valid?this.textureUpdated():t.once("update",this.textureUpdated,this))}get texture(){return this.shader.texture}_render(t){this._textureID!==this.shader.texture._updateID&&this.textureUpdated(),super._render(t)}destroy(t){this.shader.texture.off("update",this.textureUpdated,this),super.destroy(t)}}class M extends c.Mesh{constructor(t=x.Texture.EMPTY,e,i,s,h){const d=new c.MeshGeometry(e,i,s);d.getBuffer("aVertexPosition").static=!1;const g=new c.MeshMaterial(t);super(d,g,null,h),this.autoUpdate=!0}get vertices(){return this.geometry.getBuffer("aVertexPosition").data}set vertices(t){this.geometry.getBuffer("aVertexPosition").data=t}_render(t){this.autoUpdate&&this.geometry.getBuffer("aVertexPosition").update(),super._render(t)}}const w=10;class S extends b{constructor(t,e=w,i=w,s=w,h=w){super(x.Texture.WHITE,4,4),this._origWidth=t.orig.width,this._origHeight=t.orig.height,this._width=this._origWidth,this._height=this._origHeight,this._leftWidth=e,this._rightWidth=s,this._topHeight=i,this._bottomHeight=h,this.texture=t}textureUpdated(){this._textureID=this.shader.texture._updateID,this._refresh()}get vertices(){return this.geometry.getBuffer("aVertexPosition").data}set vertices(t){this.geometry.getBuffer("aVertexPosition").data=t}updateHorizontalVertices(){const t=this.vertices,e=this._getMinScale();t[9]=t[11]=t[13]=t[15]=this._topHeight*e,t[17]=t[19]=t[21]=t[23]=this._height-this._bottomHeight*e,t[25]=t[27]=t[29]=t[31]=this._height}updateVerticalVertices(){const t=this.vertices,e=this._getMinScale();t[2]=t[10]=t[18]=t[26]=this._leftWidth*e,t[4]=t[12]=t[20]=t[28]=this._width-this._rightWidth*e,t[6]=t[14]=t[22]=t[30]=this._width}_getMinScale(){const t=this._leftWidth+this._rightWidth,e=this._width>t?1:this._width/t,i=this._topHeight+this._bottomHeight,s=this._height>i?1:this._height/i;return Math.min(e,s)}get width(){return this._width}set width(t){this._width=t,this._refresh()}get height(){return this._height}set height(t){this._height=t,this._refresh()}get leftWidth(){return this._leftWidth}set leftWidth(t){this._leftWidth=t,this._refresh()}get rightWidth(){return this._rightWidth}set rightWidth(t){this._rightWidth=t,this._refresh()}get topHeight(){return this._topHeight}set topHeight(t){this._topHeight=t,this._refresh()}get bottomHeight(){return this._bottomHeight}set bottomHeight(t){this._bottomHeight=t,this._refresh()}_refresh(){const t=this.texture,e=this.geometry.buffers[1].data;this._origWidth=t.orig.width,this._origHeight=t.orig.height;const i=1/this._origWidth,s=1/this._origHeight;e[0]=e[8]=e[16]=e[24]=0,e[1]=e[3]=e[5]=e[7]=0,e[6]=e[14]=e[22]=e[30]=1,e[25]=e[27]=e[29]=e[31]=1,e[2]=e[10]=e[18]=e[26]=i*this._leftWidth,e[4]=e[12]=e[20]=e[28]=1-i*this._rightWidth,e[9]=e[11]=e[13]=e[15]=s*this._topHeight,e[17]=e[19]=e[21]=e[23]=1-s*this._bottomHeight,this.updateHorizontalVertices(),this.updateVerticalVertices(),this.geometry.buffers[0].update(),this.geometry.buffers[1].update()}}exports.NineSlicePlane=S,exports.PlaneGeometry=m,exports.RopeGeometry=W,exports.SimpleMesh=M,exports.SimplePlane=b,exports.SimpleRope=H; | ||
//# sourceMappingURL=mesh-extras.min.js.map |
/// <reference path="./global.d.ts" /> | ||
import type { DRAW_MODES } from '@pixi/constants'; | ||
import type { DRAW_MODES } from '@pixi/core'; | ||
import type { IArrayBuffer } from '@pixi/core'; | ||
import type { IDestroyOptions } from '@pixi/display'; | ||
import type { IPoint } from '@pixi/math'; | ||
import type { IPoint } from '@pixi/core'; | ||
import type { ITypedArray } from '@pixi/core'; | ||
@@ -8,0 +8,0 @@ import { Mesh } from '@pixi/mesh'; |
{ | ||
"name": "@pixi/mesh-extras", | ||
"version": "6.5.3", | ||
"version": "7.0.0-alpha", | ||
"main": "dist/cjs/mesh-extras.js", | ||
"module": "dist/esm/mesh-extras.mjs", | ||
"bundle": "dist/browser/mesh-extras.js", | ||
"types": "index.d.ts", | ||
@@ -36,14 +35,10 @@ "exports": { | ||
"files": [ | ||
"lib", | ||
"dist", | ||
"*.d.ts" | ||
], | ||
"peerDependencies": { | ||
"@pixi/constants": "6.5.3", | ||
"@pixi/core": "6.5.3", | ||
"@pixi/math": "6.5.3", | ||
"@pixi/mesh": "6.5.3", | ||
"@pixi/utils": "6.5.3" | ||
}, | ||
"gitHead": "28e6b2841a65837a5e2873a3d5a9c27cabbe795a" | ||
"pixiRequirements": [ | ||
"@pixi/core", | ||
"@pixi/mesh" | ||
], | ||
"gitHead": "da993226df64b804a9c00ed9ee4d011191467b8a" | ||
} |
@@ -12,9 +12,6 @@ # @pixi/mesh-extras | ||
```js | ||
import { MeshRenderer } from '@pixi/mesh'; | ||
import { extensions } from '@pixi/core'; | ||
import '@pixi/mesh'; | ||
import { Rope } from '@pixi/mesh-extras'; | ||
extensions.add('mesh', MeshRenderer); | ||
const rope = new Rope(); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
197407
13
1032
2
16
1