This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
"use strict";
var core = require("@pixi/core"), SimplePlane = require("./SimplePlane.js");
const DEFAULT_BORDER_SIZE = 10;
class NineSlicePlane extends SimplePlane.SimplePlane {
/**
* @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)
*/
constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) {
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 ?? texture.defaultBorders?.left ?? DEFAULT_BORDER_SIZE, this._rightWidth = rightWidth ?? texture.defaultBorders?.right ?? DEFAULT_BORDER_SIZE, this._topHeight = topHeight ?? texture.defaultBorders?.top ?? DEFAULT_BORDER_SIZE, this._bottomHeight = bottomHeight ?? texture.defaultBorders?.bottom ?? DEFAULT_BORDER_SIZE, 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;
}
/** Updates the horizontal vertices. */
updateHorizontalVertices() {
const vertices = this.vertices, 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. */
updateVerticalVertices() {
const vertices = this.vertices, 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.
*/
_getMinScale() {
const w = this._leftWidth + this._rightWidth, scaleW = this._width > w ? 1 : this._width / w, h = this._topHeight + this._bottomHeight, scaleH = this._height > h ? 1 : this._height / h;
return Math.min(scaleW, scaleH);
}
/** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
get width() {
return this._width;
}
set width(value) {
this._width = value, this._refresh();
}
/** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
get height() {
return this._height;
}
set height(value) {
this._height = value, this._refresh();
}
/** The width of the left column. */
get leftWidth() {
return this._leftWidth;
}
set leftWidth(value) {
this._leftWidth = value, this._refresh();
}
/** The width of the right column. */
get rightWidth() {
return this._rightWidth;
}
set rightWidth(value) {
this._rightWidth = value, this._refresh();
}
/** The height of the top row. */
get topHeight() {
return this._topHeight;
}
set topHeight(value) {
this._topHeight = value, this._refresh();
}
/** The height of the bottom row. */
get bottomHeight() {
return this._bottomHeight;
}
set bottomHeight(value) {
this._bottomHeight = value, this._refresh();
}
/** Refreshes NineSlicePlane coords. All of them. */
_refresh() {
const texture = this.texture, uvs = this.geometry.buffers[1].data;
this._origWidth = texture.orig.width, this._origHeight = texture.orig.height;
const _uvw = 1 / this._origWidth, _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;
//# sourceMappingURL=NineSlicePlane.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,95 @@
import { Texture } from "@pixi/core";
import { SimplePlane } from "./SimplePlane.mjs";
const DEFAULT_BORDER_SIZE = 10;
class NineSlicePlane extends SimplePlane {
/**
* @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)
*/
constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) {
super(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 ?? texture.defaultBorders?.left ?? DEFAULT_BORDER_SIZE, this._rightWidth = rightWidth ?? texture.defaultBorders?.right ?? DEFAULT_BORDER_SIZE, this._topHeight = topHeight ?? texture.defaultBorders?.top ?? DEFAULT_BORDER_SIZE, this._bottomHeight = bottomHeight ?? texture.defaultBorders?.bottom ?? DEFAULT_BORDER_SIZE, 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;
}
/** Updates the horizontal vertices. */
updateHorizontalVertices() {
const vertices = this.vertices, 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. */
updateVerticalVertices() {
const vertices = this.vertices, 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.
*/
_getMinScale() {
const w = this._leftWidth + this._rightWidth, scaleW = this._width > w ? 1 : this._width / w, h = this._topHeight + this._bottomHeight, scaleH = this._height > h ? 1 : this._height / h;
return Math.min(scaleW, scaleH);
}
/** The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
get width() {
return this._width;
}
set width(value) {
this._width = value, this._refresh();
}
/** The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane. */
get height() {
return this._height;
}
set height(value) {
this._height = value, this._refresh();
}
/** The width of the left column. */
get leftWidth() {
return this._leftWidth;
}
set leftWidth(value) {
this._leftWidth = value, this._refresh();
}
/** The width of the right column. */
get rightWidth() {
return this._rightWidth;
}
set rightWidth(value) {
this._rightWidth = value, this._refresh();
}
/** The height of the top row. */
get topHeight() {
return this._topHeight;
}
set topHeight(value) {
this._topHeight = value, this._refresh();
}
/** The height of the bottom row. */
get bottomHeight() {
return this._bottomHeight;
}
set bottomHeight(value) {
this._bottomHeight = value, this._refresh();
}
/** Refreshes NineSlicePlane coords. All of them. */
_refresh() {
const texture = this.texture, uvs = this.geometry.buffers[1].data;
this._origWidth = texture.orig.width, this._origHeight = texture.orig.height;
const _uvw = 1 / this._origWidth, _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();
}
}
export {
NineSlicePlane
};
//# sourceMappingURL=NineSlicePlane.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,32 @@
"use strict";
var core = require("@pixi/core"), mesh = require("@pixi/mesh");
class SimpleMesh extends mesh.Mesh {
/**
* @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
*/
constructor(texture = core.Texture.EMPTY, vertices, uvs, indices, drawMode) {
const geometry = new mesh.MeshGeometry(vertices, uvs, indices);
geometry.getBuffer("aVertexPosition").static = !1;
const meshMaterial = new mesh.MeshMaterial(texture);
super(geometry, meshMaterial, null, drawMode), this.autoUpdate = !0;
}
/**
* Collection of vertices data.
* @type {Float32Array}
*/
get vertices() {
return this.geometry.getBuffer("aVertexPosition").data;
}
set vertices(value) {
this.geometry.getBuffer("aVertexPosition").data = value;
}
_render(renderer) {
this.autoUpdate && this.geometry.getBuffer("aVertexPosition").update(), super._render(renderer);
}
}
exports.SimpleMesh = SimpleMesh;
//# sourceMappingURL=SimpleMesh.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SimpleMesh.js","sources":["../src/SimpleMesh.ts"],"sourcesContent":["import { Texture } from '@pixi/core';\nimport { Mesh, MeshGeometry, MeshMaterial } from '@pixi/mesh';\n\nimport type { DRAW_MODES, IArrayBuffer, ITypedArray, Renderer } from '@pixi/core';\n\n/**\n * The Simple Mesh class mimics Mesh in PixiJS v4, providing easy-to-use constructor arguments.\n * For more robust customization, use {@link PIXI.Mesh}.\n * @memberof PIXI\n */\nexport class SimpleMesh extends Mesh\n{\n /** Upload vertices buffer each frame. */\n public autoUpdate: boolean;\n\n /**\n * @param texture - The texture to use\n * @param {Float32Array} [vertices] - if you want to specify the vertices\n * @param {Float32Array} [uvs] - if you want to specify the uvs\n * @param {Uint16Array} [indices] - if you want to specify the indices\n * @param drawMode - the drawMode, can be any of the Mesh.DRAW_MODES consts\n */\n constructor(\n texture: Texture = Texture.EMPTY,\n vertices?: IArrayBuffer,\n uvs?: IArrayBuffer,\n indices?: IArrayBuffer,\n drawMode?: DRAW_MODES\n )\n {\n const geometry = new MeshGeometry(vertices, uvs, indices);\n\n geometry.getBuffer('aVertexPosition').static = false;\n\n const meshMaterial = new MeshMaterial(texture);\n\n super(geometry, meshMaterial, null, drawMode);\n\n this.autoUpdate = true;\n }\n\n /**\n * Collection of vertices data.\n * @type {Float32Array}\n */\n get vertices(): ITypedArray\n {\n return this.geometry.getBuffer('aVertexPosition').data;\n }\n set vertices(value: ITypedArray)\n {\n this.geometry.getBuffer('aVertexPosition').data = value;\n }\n\n _render(renderer: Renderer): void\n {\n if (this.autoUpdate)\n {\n this.geometry.getBuffer('aVertexPosition').update();\n }\n\n super._render(renderer);\n }\n}\n"],"names":["Mesh","Texture","MeshGeometry","MeshMaterial"],"mappings":";;AAUO,MAAM,mBAAmBA,KAAAA,KAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWI,YACI,UAAmBC,aAAQ,OAC3B,UACA,KACA,SACA,UAEJ;AACI,UAAM,WAAW,IAAIC,KAAa,aAAA,UAAU,KAAK,OAAO;AAE/C,aAAA,UAAU,iBAAiB,EAAE,SAAS;AAEzC,UAAA,eAAe,IAAIC,kBAAa,OAAO;AAEvC,UAAA,UAAU,cAAc,MAAM,QAAQ,GAE5C,KAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,WACJ;AACI,WAAO,KAAK,SAAS,UAAU,iBAAiB,EAAE;AAAA,EACtD;AAAA,EACA,IAAI,SAAS,OACb;AACI,SAAK,SAAS,UAAU,iBAAiB,EAAE,OAAO;AAAA,EACtD;AAAA,EAEA,QAAQ,UACR;AACQ,SAAK,cAEL,KAAK,SAAS,UAAU,iBAAiB,EAAE,UAG/C,MAAM,QAAQ,QAAQ;AAAA,EAC1B;AACJ;;"}

View File

@@ -0,0 +1,34 @@
import { Texture } from "@pixi/core";
import { Mesh, MeshGeometry, MeshMaterial } from "@pixi/mesh";
class SimpleMesh extends Mesh {
/**
* @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
*/
constructor(texture = Texture.EMPTY, vertices, uvs, indices, drawMode) {
const geometry = new MeshGeometry(vertices, uvs, indices);
geometry.getBuffer("aVertexPosition").static = !1;
const meshMaterial = new MeshMaterial(texture);
super(geometry, meshMaterial, null, drawMode), this.autoUpdate = !0;
}
/**
* Collection of vertices data.
* @type {Float32Array}
*/
get vertices() {
return this.geometry.getBuffer("aVertexPosition").data;
}
set vertices(value) {
this.geometry.getBuffer("aVertexPosition").data = value;
}
_render(renderer) {
this.autoUpdate && this.geometry.getBuffer("aVertexPosition").update(), super._render(renderer);
}
}
export {
SimpleMesh
};
//# sourceMappingURL=SimpleMesh.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SimpleMesh.mjs","sources":["../src/SimpleMesh.ts"],"sourcesContent":["import { Texture } from '@pixi/core';\nimport { Mesh, MeshGeometry, MeshMaterial } from '@pixi/mesh';\n\nimport type { DRAW_MODES, IArrayBuffer, ITypedArray, Renderer } from '@pixi/core';\n\n/**\n * The Simple Mesh class mimics Mesh in PixiJS v4, providing easy-to-use constructor arguments.\n * For more robust customization, use {@link PIXI.Mesh}.\n * @memberof PIXI\n */\nexport class SimpleMesh extends Mesh\n{\n /** Upload vertices buffer each frame. */\n public autoUpdate: boolean;\n\n /**\n * @param texture - The texture to use\n * @param {Float32Array} [vertices] - if you want to specify the vertices\n * @param {Float32Array} [uvs] - if you want to specify the uvs\n * @param {Uint16Array} [indices] - if you want to specify the indices\n * @param drawMode - the drawMode, can be any of the Mesh.DRAW_MODES consts\n */\n constructor(\n texture: Texture = Texture.EMPTY,\n vertices?: IArrayBuffer,\n uvs?: IArrayBuffer,\n indices?: IArrayBuffer,\n drawMode?: DRAW_MODES\n )\n {\n const geometry = new MeshGeometry(vertices, uvs, indices);\n\n geometry.getBuffer('aVertexPosition').static = false;\n\n const meshMaterial = new MeshMaterial(texture);\n\n super(geometry, meshMaterial, null, drawMode);\n\n this.autoUpdate = true;\n }\n\n /**\n * Collection of vertices data.\n * @type {Float32Array}\n */\n get vertices(): ITypedArray\n {\n return this.geometry.getBuffer('aVertexPosition').data;\n }\n set vertices(value: ITypedArray)\n {\n this.geometry.getBuffer('aVertexPosition').data = value;\n }\n\n _render(renderer: Renderer): void\n {\n if (this.autoUpdate)\n {\n this.geometry.getBuffer('aVertexPosition').update();\n }\n\n super._render(renderer);\n }\n}\n"],"names":[],"mappings":";;AAUO,MAAM,mBAAmB,KAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWI,YACI,UAAmB,QAAQ,OAC3B,UACA,KACA,SACA,UAEJ;AACI,UAAM,WAAW,IAAI,aAAa,UAAU,KAAK,OAAO;AAE/C,aAAA,UAAU,iBAAiB,EAAE,SAAS;AAEzC,UAAA,eAAe,IAAI,aAAa,OAAO;AAEvC,UAAA,UAAU,cAAc,MAAM,QAAQ,GAE5C,KAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,WACJ;AACI,WAAO,KAAK,SAAS,UAAU,iBAAiB,EAAE;AAAA,EACtD;AAAA,EACA,IAAI,SAAS,OACb;AACI,SAAK,SAAS,UAAU,iBAAiB,EAAE,OAAO;AAAA,EACtD;AAAA,EAEA,QAAQ,UACR;AACQ,SAAK,cAEL,KAAK,SAAS,UAAU,iBAAiB,EAAE,UAG/C,MAAM,QAAQ,QAAQ;AAAA,EAC1B;AACJ;"}

View File

@@ -0,0 +1,36 @@
"use strict";
var core = require("@pixi/core"), mesh = require("@pixi/mesh"), PlaneGeometry = require("./geometry/PlaneGeometry.js");
class SimplePlane extends mesh.Mesh {
/**
* @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
*/
constructor(texture, verticesX, verticesY) {
const planeGeometry = new PlaneGeometry.PlaneGeometry(texture.width, texture.height, verticesX, verticesY), meshMaterial = new mesh.MeshMaterial(core.Texture.WHITE);
super(planeGeometry, meshMaterial), this.texture = texture, this.autoResize = !0;
}
/**
* 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.
*/
textureUpdated() {
this._textureID = this.shader.texture._updateID;
const geometry = this.geometry, { width, height } = this.shader.texture;
this.autoResize && (geometry.width !== width || geometry.height !== height) && (geometry.width = this.shader.texture.width, geometry.height = this.shader.texture.height, geometry.build());
}
set texture(value) {
this.shader.texture !== value && (this.shader.texture = value, this._textureID = -1, value.baseTexture.valid ? this.textureUpdated() : value.once("update", this.textureUpdated, this));
}
get texture() {
return this.shader.texture;
}
_render(renderer) {
this._textureID !== this.shader.texture._updateID && this.textureUpdated(), super._render(renderer);
}
destroy(options) {
this.shader.texture.off("update", this.textureUpdated, this), super.destroy(options);
}
}
exports.SimplePlane = SimplePlane;
//# sourceMappingURL=SimplePlane.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SimplePlane.js","sources":["../src/SimplePlane.ts"],"sourcesContent":["import { Texture } from '@pixi/core';\nimport { Mesh, MeshMaterial } from '@pixi/mesh';\nimport { PlaneGeometry } from './geometry/PlaneGeometry';\n\nimport type{ Renderer } from '@pixi/core';\nimport type { IDestroyOptions } from '@pixi/display';\n\n/**\n * The SimplePlane allows you to draw a texture across several points and then manipulate these points\n * @example\n * import { Point, SimplePlane, Texture } from 'pixi.js';\n *\n * for (let i = 0; i < 20; i++) {\n * points.push(new Point(i * 50, 0));\n * }\n * const SimplePlane = new SimplePlane(Texture.from('snake.png'), points);\n * @memberof PIXI\n */\nexport class SimplePlane extends Mesh\n{\n /** The geometry is automatically updated when the texture size changes. */\n public autoResize: boolean;\n\n protected _textureID: number;\n\n /**\n * @param texture - The texture to use on the SimplePlane.\n * @param verticesX - The number of vertices in the x-axis\n * @param verticesY - The number of vertices in the y-axis\n */\n constructor(texture: Texture, verticesX?: number, verticesY?: number)\n {\n const planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY);\n const meshMaterial = new MeshMaterial(Texture.WHITE);\n\n super(planeGeometry, meshMaterial);\n\n // lets call the setter to ensure all necessary updates are performed\n this.texture = texture;\n this.autoResize = true;\n }\n\n /**\n * Method used for overrides, to do something in case texture frame was changed.\n * Meshes based on plane can override it and change more details based on texture.\n */\n public textureUpdated(): void\n {\n this._textureID = this.shader.texture._updateID;\n\n const geometry: PlaneGeometry = this.geometry as any;\n const { width, height } = this.shader.texture;\n\n if (this.autoResize && (geometry.width !== width || geometry.height !== height))\n {\n geometry.width = this.shader.texture.width;\n geometry.height = this.shader.texture.height;\n geometry.build();\n }\n }\n\n set texture(value: Texture)\n {\n // Track texture same way sprite does.\n // For generated meshes like NineSlicePlane it can change the geometry.\n // Unfortunately, this method might not work if you directly change texture in material.\n\n if (this.shader.texture === value)\n {\n return;\n }\n\n this.shader.texture = value;\n this._textureID = -1;\n\n if (value.baseTexture.valid)\n {\n this.textureUpdated();\n }\n else\n {\n value.once('update', this.textureUpdated, this);\n }\n }\n\n get texture(): Texture\n {\n return this.shader.texture;\n }\n\n _render(renderer: Renderer): void\n {\n if (this._textureID !== this.shader.texture._updateID)\n {\n this.textureUpdated();\n }\n\n super._render(renderer);\n }\n\n public destroy(options?: IDestroyOptions | boolean): void\n {\n this.shader.texture.off('update', this.textureUpdated, this);\n super.destroy(options);\n }\n}\n"],"names":["Mesh","PlaneGeometry","MeshMaterial","Texture"],"mappings":";;AAkBO,MAAM,oBAAoBA,KAAAA,KACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWI,YAAY,SAAkB,WAAoB,WAClD;AACI,UAAM,gBAAgB,IAAIC,cAAc,cAAA,QAAQ,OAAO,QAAQ,QAAQ,WAAW,SAAS,GACrF,eAAe,IAAIC,KAAA,aAAaC,aAAQ,KAAK;AAEnD,UAAM,eAAe,YAAY,GAG5B,KAAA,UAAU,SACf,KAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,iBACP;AACS,SAAA,aAAa,KAAK,OAAO,QAAQ;AAEhC,UAAA,WAA0B,KAAK,UAC/B,EAAE,OAAO,WAAW,KAAK,OAAO;AAElC,SAAK,eAAe,SAAS,UAAU,SAAS,SAAS,WAAW,YAEpE,SAAS,QAAQ,KAAK,OAAO,QAAQ,OACrC,SAAS,SAAS,KAAK,OAAO,QAAQ,QACtC,SAAS,MAAM;AAAA,EAEvB;AAAA,EAEA,IAAI,QAAQ,OACZ;AAKQ,SAAK,OAAO,YAAY,UAK5B,KAAK,OAAO,UAAU,OACtB,KAAK,aAAa,IAEd,MAAM,YAAY,QAElB,KAAK,eAAe,IAIpB,MAAM,KAAK,UAAU,KAAK,gBAAgB,IAAI;AAAA,EAEtD;AAAA,EAEA,IAAI,UACJ;AACI,WAAO,KAAK,OAAO;AAAA,EACvB;AAAA,EAEA,QAAQ,UACR;AACQ,SAAK,eAAe,KAAK,OAAO,QAAQ,aAExC,KAAK,eAAe,GAGxB,MAAM,QAAQ,QAAQ;AAAA,EAC1B;AAAA,EAEO,QAAQ,SACf;AACS,SAAA,OAAO,QAAQ,IAAI,UAAU,KAAK,gBAAgB,IAAI,GAC3D,MAAM,QAAQ,OAAO;AAAA,EACzB;AACJ;;"}

View File

@@ -0,0 +1,39 @@
import { Texture } from "@pixi/core";
import { Mesh, MeshMaterial } from "@pixi/mesh";
import { PlaneGeometry } from "./geometry/PlaneGeometry.mjs";
class SimplePlane extends Mesh {
/**
* @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
*/
constructor(texture, verticesX, verticesY) {
const planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY), meshMaterial = new MeshMaterial(Texture.WHITE);
super(planeGeometry, meshMaterial), this.texture = texture, this.autoResize = !0;
}
/**
* 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.
*/
textureUpdated() {
this._textureID = this.shader.texture._updateID;
const geometry = this.geometry, { width, height } = this.shader.texture;
this.autoResize && (geometry.width !== width || geometry.height !== height) && (geometry.width = this.shader.texture.width, geometry.height = this.shader.texture.height, geometry.build());
}
set texture(value) {
this.shader.texture !== value && (this.shader.texture = value, this._textureID = -1, value.baseTexture.valid ? this.textureUpdated() : value.once("update", this.textureUpdated, this));
}
get texture() {
return this.shader.texture;
}
_render(renderer) {
this._textureID !== this.shader.texture._updateID && this.textureUpdated(), super._render(renderer);
}
destroy(options) {
this.shader.texture.off("update", this.textureUpdated, this), super.destroy(options);
}
}
export {
SimplePlane
};
//# sourceMappingURL=SimplePlane.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SimplePlane.mjs","sources":["../src/SimplePlane.ts"],"sourcesContent":["import { Texture } from '@pixi/core';\nimport { Mesh, MeshMaterial } from '@pixi/mesh';\nimport { PlaneGeometry } from './geometry/PlaneGeometry';\n\nimport type{ Renderer } from '@pixi/core';\nimport type { IDestroyOptions } from '@pixi/display';\n\n/**\n * The SimplePlane allows you to draw a texture across several points and then manipulate these points\n * @example\n * import { Point, SimplePlane, Texture } from 'pixi.js';\n *\n * for (let i = 0; i < 20; i++) {\n * points.push(new Point(i * 50, 0));\n * }\n * const SimplePlane = new SimplePlane(Texture.from('snake.png'), points);\n * @memberof PIXI\n */\nexport class SimplePlane extends Mesh\n{\n /** The geometry is automatically updated when the texture size changes. */\n public autoResize: boolean;\n\n protected _textureID: number;\n\n /**\n * @param texture - The texture to use on the SimplePlane.\n * @param verticesX - The number of vertices in the x-axis\n * @param verticesY - The number of vertices in the y-axis\n */\n constructor(texture: Texture, verticesX?: number, verticesY?: number)\n {\n const planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY);\n const meshMaterial = new MeshMaterial(Texture.WHITE);\n\n super(planeGeometry, meshMaterial);\n\n // lets call the setter to ensure all necessary updates are performed\n this.texture = texture;\n this.autoResize = true;\n }\n\n /**\n * Method used for overrides, to do something in case texture frame was changed.\n * Meshes based on plane can override it and change more details based on texture.\n */\n public textureUpdated(): void\n {\n this._textureID = this.shader.texture._updateID;\n\n const geometry: PlaneGeometry = this.geometry as any;\n const { width, height } = this.shader.texture;\n\n if (this.autoResize && (geometry.width !== width || geometry.height !== height))\n {\n geometry.width = this.shader.texture.width;\n geometry.height = this.shader.texture.height;\n geometry.build();\n }\n }\n\n set texture(value: Texture)\n {\n // Track texture same way sprite does.\n // For generated meshes like NineSlicePlane it can change the geometry.\n // Unfortunately, this method might not work if you directly change texture in material.\n\n if (this.shader.texture === value)\n {\n return;\n }\n\n this.shader.texture = value;\n this._textureID = -1;\n\n if (value.baseTexture.valid)\n {\n this.textureUpdated();\n }\n else\n {\n value.once('update', this.textureUpdated, this);\n }\n }\n\n get texture(): Texture\n {\n return this.shader.texture;\n }\n\n _render(renderer: Renderer): void\n {\n if (this._textureID !== this.shader.texture._updateID)\n {\n this.textureUpdated();\n }\n\n super._render(renderer);\n }\n\n public destroy(options?: IDestroyOptions | boolean): void\n {\n this.shader.texture.off('update', this.textureUpdated, this);\n super.destroy(options);\n }\n}\n"],"names":[],"mappings":";;;AAkBO,MAAM,oBAAoB,KACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWI,YAAY,SAAkB,WAAoB,WAClD;AACI,UAAM,gBAAgB,IAAI,cAAc,QAAQ,OAAO,QAAQ,QAAQ,WAAW,SAAS,GACrF,eAAe,IAAI,aAAa,QAAQ,KAAK;AAEnD,UAAM,eAAe,YAAY,GAG5B,KAAA,UAAU,SACf,KAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,iBACP;AACS,SAAA,aAAa,KAAK,OAAO,QAAQ;AAEhC,UAAA,WAA0B,KAAK,UAC/B,EAAE,OAAO,WAAW,KAAK,OAAO;AAElC,SAAK,eAAe,SAAS,UAAU,SAAS,SAAS,WAAW,YAEpE,SAAS,QAAQ,KAAK,OAAO,QAAQ,OACrC,SAAS,SAAS,KAAK,OAAO,QAAQ,QACtC,SAAS,MAAM;AAAA,EAEvB;AAAA,EAEA,IAAI,QAAQ,OACZ;AAKQ,SAAK,OAAO,YAAY,UAK5B,KAAK,OAAO,UAAU,OACtB,KAAK,aAAa,IAEd,MAAM,YAAY,QAElB,KAAK,eAAe,IAIpB,MAAM,KAAK,UAAU,KAAK,gBAAgB,IAAI;AAAA,EAEtD;AAAA,EAEA,IAAI,UACJ;AACI,WAAO,KAAK,OAAO;AAAA,EACvB;AAAA,EAEA,QAAQ,UACR;AACQ,SAAK,eAAe,KAAK,OAAO,QAAQ,aAExC,KAAK,eAAe,GAGxB,MAAM,QAAQ,QAAQ;AAAA,EAC1B;AAAA,EAEO,QAAQ,SACf;AACS,SAAA,OAAO,QAAQ,IAAI,UAAU,KAAK,gBAAgB,IAAI,GAC3D,MAAM,QAAQ,OAAO;AAAA,EACzB;AACJ;"}

View File

@@ -0,0 +1,22 @@
"use strict";
var core = require("@pixi/core"), mesh = require("@pixi/mesh"), RopeGeometry = require("./geometry/RopeGeometry.js");
class SimpleRope extends mesh.Mesh {
/**
* Note: The wrap mode of the texture is set to REPEAT if `textureScale` is positive.
* @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.
*/
constructor(texture, points, textureScale = 0) {
const ropeGeometry = new RopeGeometry.RopeGeometry(texture.height, points, textureScale), meshMaterial = new mesh.MeshMaterial(texture);
textureScale > 0 && (texture.baseTexture.wrapMode = core.WRAP_MODES.REPEAT), super(ropeGeometry, meshMaterial), this.autoUpdate = !0;
}
_render(renderer) {
const geometry = this.geometry;
(this.autoUpdate || geometry._width !== this.shader.texture.height) && (geometry._width = this.shader.texture.height, geometry.update()), super._render(renderer);
}
}
exports.SimpleRope = SimpleRope;
//# sourceMappingURL=SimpleRope.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SimpleRope.js","sources":["../src/SimpleRope.ts"],"sourcesContent":["import { WRAP_MODES } from '@pixi/core';\nimport { Mesh, MeshMaterial } from '@pixi/mesh';\nimport { RopeGeometry } from './geometry/RopeGeometry';\n\nimport type { IPoint, Renderer, Texture } from '@pixi/core';\n\n/**\n * The rope allows you to draw a texture across several points and then manipulate these points\n * @example\n * import { Point, SimpleRope, Texture } from 'pixi.js';\n *\n * for (let i = 0; i < 20; i++) {\n * points.push(new Point(i * 50, 0));\n * };\n * const rope = new SimpleRope(Texture.from('snake.png'), points);\n * @memberof PIXI\n */\nexport class SimpleRope extends Mesh\n{\n public autoUpdate: boolean;\n\n /**\n * Note: The wrap mode of the texture is set to REPEAT if `textureScale` is positive.\n * @param texture - The texture to use on the rope.\n * @param points - An array of {@link PIXI.Point} objects to construct this rope.\n * @param {number} textureScale - Optional. Positive values scale rope texture\n * keeping its aspect ratio. You can reduce alpha channel artifacts by providing a larger texture\n * and downsampling here. If set to zero, texture will be stretched instead.\n */\n constructor(texture: Texture, points: IPoint[], textureScale = 0)\n {\n const ropeGeometry = new RopeGeometry(texture.height, points, textureScale);\n const meshMaterial = new MeshMaterial(texture);\n\n if (textureScale > 0)\n {\n // attempt to set UV wrapping, will fail on non-power of two textures\n texture.baseTexture.wrapMode = WRAP_MODES.REPEAT;\n }\n super(ropeGeometry, meshMaterial);\n\n /**\n * re-calculate vertices by rope points each frame\n * @member {boolean}\n */\n this.autoUpdate = true;\n }\n\n _render(renderer: Renderer): void\n {\n const geometry: RopeGeometry = this.geometry as any;\n\n if (this.autoUpdate || geometry._width !== this.shader.texture.height)\n {\n geometry._width = this.shader.texture.height;\n geometry.update();\n }\n\n super._render(renderer);\n }\n}\n"],"names":["Mesh","RopeGeometry","MeshMaterial","WRAP_MODES"],"mappings":";;AAiBO,MAAM,mBAAmBA,KAAAA,KAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWI,YAAY,SAAkB,QAAkB,eAAe,GAC/D;AACU,UAAA,eAAe,IAAIC,0BAAa,QAAQ,QAAQ,QAAQ,YAAY,GACpE,eAAe,IAAIC,KAAA,aAAa,OAAO;AAEzC,mBAAe,MAGf,QAAQ,YAAY,WAAWC,KAAAA,WAAW,SAE9C,MAAM,cAAc,YAAY,GAMhC,KAAK,aAAa;AAAA,EACtB;AAAA,EAEA,QAAQ,UACR;AACI,UAAM,WAAyB,KAAK;AAEpC,KAAI,KAAK,cAAc,SAAS,WAAW,KAAK,OAAO,QAAQ,YAE3D,SAAS,SAAS,KAAK,OAAO,QAAQ,QACtC,SAAS,OAGb,IAAA,MAAM,QAAQ,QAAQ;AAAA,EAC1B;AACJ;;"}

View File

@@ -0,0 +1,25 @@
import { WRAP_MODES } from "@pixi/core";
import { Mesh, MeshMaterial } from "@pixi/mesh";
import { RopeGeometry } from "./geometry/RopeGeometry.mjs";
class SimpleRope extends Mesh {
/**
* Note: The wrap mode of the texture is set to REPEAT if `textureScale` is positive.
* @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.
*/
constructor(texture, points, textureScale = 0) {
const ropeGeometry = new RopeGeometry(texture.height, points, textureScale), meshMaterial = new MeshMaterial(texture);
textureScale > 0 && (texture.baseTexture.wrapMode = WRAP_MODES.REPEAT), super(ropeGeometry, meshMaterial), this.autoUpdate = !0;
}
_render(renderer) {
const geometry = this.geometry;
(this.autoUpdate || geometry._width !== this.shader.texture.height) && (geometry._width = this.shader.texture.height, geometry.update()), super._render(renderer);
}
}
export {
SimpleRope
};
//# sourceMappingURL=SimpleRope.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SimpleRope.mjs","sources":["../src/SimpleRope.ts"],"sourcesContent":["import { WRAP_MODES } from '@pixi/core';\nimport { Mesh, MeshMaterial } from '@pixi/mesh';\nimport { RopeGeometry } from './geometry/RopeGeometry';\n\nimport type { IPoint, Renderer, Texture } from '@pixi/core';\n\n/**\n * The rope allows you to draw a texture across several points and then manipulate these points\n * @example\n * import { Point, SimpleRope, Texture } from 'pixi.js';\n *\n * for (let i = 0; i < 20; i++) {\n * points.push(new Point(i * 50, 0));\n * };\n * const rope = new SimpleRope(Texture.from('snake.png'), points);\n * @memberof PIXI\n */\nexport class SimpleRope extends Mesh\n{\n public autoUpdate: boolean;\n\n /**\n * Note: The wrap mode of the texture is set to REPEAT if `textureScale` is positive.\n * @param texture - The texture to use on the rope.\n * @param points - An array of {@link PIXI.Point} objects to construct this rope.\n * @param {number} textureScale - Optional. Positive values scale rope texture\n * keeping its aspect ratio. You can reduce alpha channel artifacts by providing a larger texture\n * and downsampling here. If set to zero, texture will be stretched instead.\n */\n constructor(texture: Texture, points: IPoint[], textureScale = 0)\n {\n const ropeGeometry = new RopeGeometry(texture.height, points, textureScale);\n const meshMaterial = new MeshMaterial(texture);\n\n if (textureScale > 0)\n {\n // attempt to set UV wrapping, will fail on non-power of two textures\n texture.baseTexture.wrapMode = WRAP_MODES.REPEAT;\n }\n super(ropeGeometry, meshMaterial);\n\n /**\n * re-calculate vertices by rope points each frame\n * @member {boolean}\n */\n this.autoUpdate = true;\n }\n\n _render(renderer: Renderer): void\n {\n const geometry: RopeGeometry = this.geometry as any;\n\n if (this.autoUpdate || geometry._width !== this.shader.texture.height)\n {\n geometry._width = this.shader.texture.height;\n geometry.update();\n }\n\n super._render(renderer);\n }\n}\n"],"names":[],"mappings":";;;AAiBO,MAAM,mBAAmB,KAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWI,YAAY,SAAkB,QAAkB,eAAe,GAC/D;AACU,UAAA,eAAe,IAAI,aAAa,QAAQ,QAAQ,QAAQ,YAAY,GACpE,eAAe,IAAI,aAAa,OAAO;AAEzC,mBAAe,MAGf,QAAQ,YAAY,WAAW,WAAW,SAE9C,MAAM,cAAc,YAAY,GAMhC,KAAK,aAAa;AAAA,EACtB;AAAA,EAEA,QAAQ,UACR;AACI,UAAM,WAAyB,KAAK;AAEpC,KAAI,KAAK,cAAc,SAAS,WAAW,KAAK,OAAO,QAAQ,YAE3D,SAAS,SAAS,KAAK,OAAO,QAAQ,QACtC,SAAS,OAGb,IAAA,MAAM,QAAQ,QAAQ;AAAA,EAC1B;AACJ;"}

View File

@@ -0,0 +1,39 @@
"use strict";
var mesh = require("@pixi/mesh");
class PlaneGeometry extends mesh.MeshGeometry {
/**
* @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.
*/
constructor(width = 100, height = 100, segWidth = 10, segHeight = 10) {
super(), this.segWidth = segWidth, this.segHeight = segHeight, this.width = width, this.height = height, this.build();
}
/**
* Refreshes plane coordinates
* @private
*/
build() {
const total = this.segWidth * this.segHeight, verts = [], uvs = [], indices = [], segmentsX = this.segWidth - 1, segmentsY = this.segHeight - 1, sizeX = this.width / segmentsX, sizeY = this.height / segmentsY;
for (let i = 0; i < total; i++) {
const x = i % this.segWidth, 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, ypos = i / segmentsX | 0, value = ypos * this.segWidth + xpos, value2 = ypos * this.segWidth + xpos + 1, value3 = (ypos + 1) * this.segWidth + xpos, 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();
}
}
exports.PlaneGeometry = PlaneGeometry;
//# sourceMappingURL=PlaneGeometry.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"PlaneGeometry.js","sources":["../../src/geometry/PlaneGeometry.ts"],"sourcesContent":["import { MeshGeometry } from '@pixi/mesh';\n\n/**\n * @memberof PIXI\n */\nexport class PlaneGeometry extends MeshGeometry\n{\n public segWidth: number;\n public segHeight: number;\n public width: number;\n public height: number;\n\n /**\n * @param width - The width of the plane.\n * @param height - The height of the plane.\n * @param segWidth - Number of horizontal segments.\n * @param segHeight - Number of vertical segments.\n */\n constructor(width = 100, height = 100, segWidth = 10, segHeight = 10)\n {\n super();\n\n this.segWidth = segWidth;\n this.segHeight = segHeight;\n\n this.width = width;\n this.height = height;\n\n this.build();\n }\n\n /**\n * Refreshes plane coordinates\n * @private\n */\n build(): void\n {\n const total = this.segWidth * this.segHeight;\n const verts = [];\n const uvs = [];\n const indices = [];\n\n const segmentsX = this.segWidth - 1;\n const segmentsY = this.segHeight - 1;\n\n const sizeX = (this.width) / segmentsX;\n const sizeY = (this.height) / segmentsY;\n\n for (let i = 0; i < total; i++)\n {\n const x = (i % this.segWidth);\n const y = ((i / this.segWidth) | 0);\n\n verts.push(x * sizeX, y * sizeY);\n uvs.push(x / segmentsX, y / segmentsY);\n }\n\n const totalSub = segmentsX * segmentsY;\n\n for (let i = 0; i < totalSub; i++)\n {\n const xpos = i % segmentsX;\n const ypos = (i / segmentsX) | 0;\n\n const value = (ypos * this.segWidth) + xpos;\n const value2 = (ypos * this.segWidth) + xpos + 1;\n const value3 = ((ypos + 1) * this.segWidth) + xpos;\n const value4 = ((ypos + 1) * this.segWidth) + xpos + 1;\n\n indices.push(value, value2, value3,\n value2, value4, value3);\n }\n\n this.buffers[0].data = new Float32Array(verts);\n this.buffers[1].data = new Float32Array(uvs);\n this.indexBuffer.data = new Uint16Array(indices);\n\n // ensure that the changes are uploaded\n this.buffers[0].update();\n this.buffers[1].update();\n this.indexBuffer.update();\n }\n}\n"],"names":["MeshGeometry"],"mappings":";;AAKO,MAAM,sBAAsBA,KAAAA,aACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYI,YAAY,QAAQ,KAAK,SAAS,KAAK,WAAW,IAAI,YAAY,IAClE;AACU,aAEN,KAAK,WAAW,UAChB,KAAK,YAAY,WAEjB,KAAK,QAAQ,OACb,KAAK,SAAS,QAEd,KAAK,MAAM;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QACA;AACI,UAAM,QAAQ,KAAK,WAAW,KAAK,WAC7B,QAAQ,CAAC,GACT,MAAM,CACN,GAAA,UAAU,CAAC,GAEX,YAAY,KAAK,WAAW,GAC5B,YAAY,KAAK,YAAY,GAE7B,QAAS,KAAK,QAAS,WACvB,QAAS,KAAK,SAAU;AAE9B,aAAS,IAAI,GAAG,IAAI,OAAO,KAC3B;AACI,YAAM,IAAK,IAAI,KAAK,UACd,IAAM,IAAI,KAAK,WAAY;AAE3B,YAAA,KAAK,IAAI,OAAO,IAAI,KAAK,GAC/B,IAAI,KAAK,IAAI,WAAW,IAAI,SAAS;AAAA,IACzC;AAEA,UAAM,WAAW,YAAY;AAE7B,aAAS,IAAI,GAAG,IAAI,UAAU,KAC9B;AACI,YAAM,OAAO,IAAI,WACX,OAAQ,IAAI,YAAa,GAEzB,QAAS,OAAO,KAAK,WAAY,MACjC,SAAU,OAAO,KAAK,WAAY,OAAO,GACzC,UAAW,OAAO,KAAK,KAAK,WAAY,MACxC,UAAW,OAAO,KAAK,KAAK,WAAY,OAAO;AAE7C,cAAA;AAAA,QAAK;AAAA,QAAO;AAAA,QAAQ;AAAA,QACxB;AAAA,QAAQ;AAAA,QAAQ;AAAA,MAAA;AAAA,IACxB;AAEA,SAAK,QAAQ,CAAC,EAAE,OAAO,IAAI,aAAa,KAAK,GAC7C,KAAK,QAAQ,CAAC,EAAE,OAAO,IAAI,aAAa,GAAG,GAC3C,KAAK,YAAY,OAAO,IAAI,YAAY,OAAO,GAG/C,KAAK,QAAQ,CAAC,EAAE,OAChB,GAAA,KAAK,QAAQ,CAAC,EAAE,UAChB,KAAK,YAAY;EACrB;AACJ;;"}

View File

@@ -0,0 +1,40 @@
import { MeshGeometry } from "@pixi/mesh";
class PlaneGeometry extends MeshGeometry {
/**
* @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.
*/
constructor(width = 100, height = 100, segWidth = 10, segHeight = 10) {
super(), this.segWidth = segWidth, this.segHeight = segHeight, this.width = width, this.height = height, this.build();
}
/**
* Refreshes plane coordinates
* @private
*/
build() {
const total = this.segWidth * this.segHeight, verts = [], uvs = [], indices = [], segmentsX = this.segWidth - 1, segmentsY = this.segHeight - 1, sizeX = this.width / segmentsX, sizeY = this.height / segmentsY;
for (let i = 0; i < total; i++) {
const x = i % this.segWidth, 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, ypos = i / segmentsX | 0, value = ypos * this.segWidth + xpos, value2 = ypos * this.segWidth + xpos + 1, value3 = (ypos + 1) * this.segWidth + xpos, 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();
}
}
export {
PlaneGeometry
};
//# sourceMappingURL=PlaneGeometry.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"PlaneGeometry.mjs","sources":["../../src/geometry/PlaneGeometry.ts"],"sourcesContent":["import { MeshGeometry } from '@pixi/mesh';\n\n/**\n * @memberof PIXI\n */\nexport class PlaneGeometry extends MeshGeometry\n{\n public segWidth: number;\n public segHeight: number;\n public width: number;\n public height: number;\n\n /**\n * @param width - The width of the plane.\n * @param height - The height of the plane.\n * @param segWidth - Number of horizontal segments.\n * @param segHeight - Number of vertical segments.\n */\n constructor(width = 100, height = 100, segWidth = 10, segHeight = 10)\n {\n super();\n\n this.segWidth = segWidth;\n this.segHeight = segHeight;\n\n this.width = width;\n this.height = height;\n\n this.build();\n }\n\n /**\n * Refreshes plane coordinates\n * @private\n */\n build(): void\n {\n const total = this.segWidth * this.segHeight;\n const verts = [];\n const uvs = [];\n const indices = [];\n\n const segmentsX = this.segWidth - 1;\n const segmentsY = this.segHeight - 1;\n\n const sizeX = (this.width) / segmentsX;\n const sizeY = (this.height) / segmentsY;\n\n for (let i = 0; i < total; i++)\n {\n const x = (i % this.segWidth);\n const y = ((i / this.segWidth) | 0);\n\n verts.push(x * sizeX, y * sizeY);\n uvs.push(x / segmentsX, y / segmentsY);\n }\n\n const totalSub = segmentsX * segmentsY;\n\n for (let i = 0; i < totalSub; i++)\n {\n const xpos = i % segmentsX;\n const ypos = (i / segmentsX) | 0;\n\n const value = (ypos * this.segWidth) + xpos;\n const value2 = (ypos * this.segWidth) + xpos + 1;\n const value3 = ((ypos + 1) * this.segWidth) + xpos;\n const value4 = ((ypos + 1) * this.segWidth) + xpos + 1;\n\n indices.push(value, value2, value3,\n value2, value4, value3);\n }\n\n this.buffers[0].data = new Float32Array(verts);\n this.buffers[1].data = new Float32Array(uvs);\n this.indexBuffer.data = new Uint16Array(indices);\n\n // ensure that the changes are uploaded\n this.buffers[0].update();\n this.buffers[1].update();\n this.indexBuffer.update();\n }\n}\n"],"names":[],"mappings":";AAKO,MAAM,sBAAsB,aACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYI,YAAY,QAAQ,KAAK,SAAS,KAAK,WAAW,IAAI,YAAY,IAClE;AACU,aAEN,KAAK,WAAW,UAChB,KAAK,YAAY,WAEjB,KAAK,QAAQ,OACb,KAAK,SAAS,QAEd,KAAK,MAAM;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QACA;AACI,UAAM,QAAQ,KAAK,WAAW,KAAK,WAC7B,QAAQ,CAAC,GACT,MAAM,CACN,GAAA,UAAU,CAAC,GAEX,YAAY,KAAK,WAAW,GAC5B,YAAY,KAAK,YAAY,GAE7B,QAAS,KAAK,QAAS,WACvB,QAAS,KAAK,SAAU;AAE9B,aAAS,IAAI,GAAG,IAAI,OAAO,KAC3B;AACI,YAAM,IAAK,IAAI,KAAK,UACd,IAAM,IAAI,KAAK,WAAY;AAE3B,YAAA,KAAK,IAAI,OAAO,IAAI,KAAK,GAC/B,IAAI,KAAK,IAAI,WAAW,IAAI,SAAS;AAAA,IACzC;AAEA,UAAM,WAAW,YAAY;AAE7B,aAAS,IAAI,GAAG,IAAI,UAAU,KAC9B;AACI,YAAM,OAAO,IAAI,WACX,OAAQ,IAAI,YAAa,GAEzB,QAAS,OAAO,KAAK,WAAY,MACjC,SAAU,OAAO,KAAK,WAAY,OAAO,GACzC,UAAW,OAAO,KAAK,KAAK,WAAY,MACxC,UAAW,OAAO,KAAK,KAAK,WAAY,OAAO;AAE7C,cAAA;AAAA,QAAK;AAAA,QAAO;AAAA,QAAQ;AAAA,QACxB;AAAA,QAAQ;AAAA,QAAQ;AAAA,MAAA;AAAA,IACxB;AAEA,SAAK,QAAQ,CAAC,EAAE,OAAO,IAAI,aAAa,KAAK,GAC7C,KAAK,QAAQ,CAAC,EAAE,OAAO,IAAI,aAAa,GAAG,GAC3C,KAAK,YAAY,OAAO,IAAI,YAAY,OAAO,GAG/C,KAAK,QAAQ,CAAC,EAAE,OAChB,GAAA,KAAK,QAAQ,CAAC,EAAE,UAChB,KAAK,YAAY;EACrB;AACJ;"}

View File

@@ -0,0 +1,80 @@
"use strict";
var mesh = require("@pixi/mesh");
class RopeGeometry extends mesh.MeshGeometry {
/**
* @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.
*/
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();
}
/**
* The width (i.e., thickness) of the rope.
* @readonly
*/
get width() {
return this._width;
}
/** Refreshes Rope indices and uvs */
build() {
const points = this.points;
if (!points)
return;
const vertexBuffer = this.getBuffer("aVertexPosition"), uvBuffer = this.getBuffer("aTextureCoord"), indexBuffer = this.getIndex();
if (points.length < 1)
return;
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));
const uvs = uvBuffer.data, indices = indexBuffer.data;
uvs[0] = 0, uvs[1] = 0, uvs[2] = 0, uvs[3] = 1;
let amount = 0, prev = points[0];
const textureWidth = this._width * this.textureScale, 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, dy = prev.y - points[i].y, 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;
}
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();
}
/** refreshes vertices of Rope mesh */
updateVertices() {
const points = this.points;
if (points.length < 1)
return;
let lastPoint = points[0], nextPoint, perpX = 0, perpY = 0;
const vertices = this.buffers[0].data, total = points.length, halfWidth = this.textureScale > 0 ? this.textureScale * this._width / 2 : this._width / 2;
for (let i = 0; i < total; i++) {
const point = points[i], index = i * 4;
i < points.length - 1 ? nextPoint = points[i + 1] : nextPoint = point, perpY = -(nextPoint.x - lastPoint.x), perpX = nextPoint.y - lastPoint.y;
let ratio = (1 - i / (total - 1)) * 10;
ratio > 1 && (ratio = 1);
const perpLength = Math.sqrt(perpX * perpX + perpY * perpY);
perpLength < 1e-6 ? (perpX = 0, perpY = 0) : (perpX /= perpLength, perpY /= perpLength, perpX *= halfWidth, perpY *= halfWidth), 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() {
this.textureScale > 0 ? this.build() : this.updateVertices();
}
}
exports.RopeGeometry = RopeGeometry;
//# sourceMappingURL=RopeGeometry.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,81 @@
import { MeshGeometry } from "@pixi/mesh";
class RopeGeometry extends MeshGeometry {
/**
* @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.
*/
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();
}
/**
* The width (i.e., thickness) of the rope.
* @readonly
*/
get width() {
return this._width;
}
/** Refreshes Rope indices and uvs */
build() {
const points = this.points;
if (!points)
return;
const vertexBuffer = this.getBuffer("aVertexPosition"), uvBuffer = this.getBuffer("aTextureCoord"), indexBuffer = this.getIndex();
if (points.length < 1)
return;
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));
const uvs = uvBuffer.data, indices = indexBuffer.data;
uvs[0] = 0, uvs[1] = 0, uvs[2] = 0, uvs[3] = 1;
let amount = 0, prev = points[0];
const textureWidth = this._width * this.textureScale, 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, dy = prev.y - points[i].y, 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;
}
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();
}
/** refreshes vertices of Rope mesh */
updateVertices() {
const points = this.points;
if (points.length < 1)
return;
let lastPoint = points[0], nextPoint, perpX = 0, perpY = 0;
const vertices = this.buffers[0].data, total = points.length, halfWidth = this.textureScale > 0 ? this.textureScale * this._width / 2 : this._width / 2;
for (let i = 0; i < total; i++) {
const point = points[i], index = i * 4;
i < points.length - 1 ? nextPoint = points[i + 1] : nextPoint = point, perpY = -(nextPoint.x - lastPoint.x), perpX = nextPoint.y - lastPoint.y;
let ratio = (1 - i / (total - 1)) * 10;
ratio > 1 && (ratio = 1);
const perpLength = Math.sqrt(perpX * perpX + perpY * perpY);
perpLength < 1e-6 ? (perpX = 0, perpY = 0) : (perpX /= perpLength, perpY /= perpLength, perpX *= halfWidth, perpY *= halfWidth), 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() {
this.textureScale > 0 ? this.build() : this.updateVertices();
}
}
export {
RopeGeometry
};
//# sourceMappingURL=RopeGeometry.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,9 @@
"use strict";
var PlaneGeometry = require("./geometry/PlaneGeometry.js"), RopeGeometry = require("./geometry/RopeGeometry.js"), NineSlicePlane = require("./NineSlicePlane.js"), SimpleMesh = require("./SimpleMesh.js"), SimplePlane = require("./SimplePlane.js"), SimpleRope = require("./SimpleRope.js");
exports.PlaneGeometry = PlaneGeometry.PlaneGeometry;
exports.RopeGeometry = RopeGeometry.RopeGeometry;
exports.NineSlicePlane = NineSlicePlane.NineSlicePlane;
exports.SimpleMesh = SimpleMesh.SimpleMesh;
exports.SimplePlane = SimplePlane.SimplePlane;
exports.SimpleRope = SimpleRope.SimpleRope;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}

View File

@@ -0,0 +1,15 @@
import { PlaneGeometry } from "./geometry/PlaneGeometry.mjs";
import { RopeGeometry } from "./geometry/RopeGeometry.mjs";
import { NineSlicePlane } from "./NineSlicePlane.mjs";
import { SimpleMesh } from "./SimpleMesh.mjs";
import { SimplePlane } from "./SimplePlane.mjs";
import { SimpleRope } from "./SimpleRope.mjs";
export {
NineSlicePlane,
PlaneGeometry,
RopeGeometry,
SimpleMesh,
SimplePlane,
SimpleRope
};
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}