@pixi/mesh-extras
Advanced tools
Comparing version 7.2.4 to 7.3.0-rc
@@ -1,51 +0,39 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var mesh = require('@pixi/mesh'); | ||
"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(); | ||
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; | ||
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; | ||
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; | ||
const y = i / this.segWidth | 0; | ||
verts.push(x * sizeX, y * sizeY); | ||
uvs.push(x / segmentsX, y / segmentsY); | ||
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; | ||
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); | ||
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(); | ||
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 |
@@ -1,18 +0,30 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var mesh = require('@pixi/mesh'); | ||
"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(); | ||
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() { | ||
@@ -22,38 +34,18 @@ const points = this.points; | ||
return; | ||
const vertexBuffer = this.getBuffer("aVertexPosition"); | ||
const uvBuffer = this.getBuffer("aTextureCoord"); | ||
const indexBuffer = this.getIndex(); | ||
if (points.length < 1) { | ||
const vertexBuffer = this.getBuffer("aVertexPosition"), uvBuffer = this.getBuffer("aTextureCoord"), indexBuffer = this.getIndex(); | ||
if (points.length < 1) | ||
return; | ||
} | ||
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); | ||
} | ||
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; | ||
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; | ||
const dy = prev.y - points[i].y; | ||
const distance = Math.sqrt(dx * dx + dy * dy); | ||
prev = points[i]; | ||
amount += distance / textureWidth; | ||
} else { | ||
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; | ||
uvs[index] = amount, uvs[index + 1] = 0, uvs[index + 2] = amount, uvs[index + 3] = 1; | ||
} | ||
@@ -63,54 +55,20 @@ let indexCount = 0; | ||
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; | ||
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(); | ||
uvBuffer.update(), indexBuffer.update(), this.updateVertices(); | ||
} | ||
/** refreshes vertices of Rope mesh */ | ||
updateVertices() { | ||
const points = this.points; | ||
if (points.length < 1) { | ||
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; | ||
const halfWidth = this.textureScale > 0 ? this.textureScale * this._width / 2 : this._width / 2; | ||
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]; | ||
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 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; | ||
if (ratio > 1) { | ||
ratio = 1; | ||
} | ||
ratio > 1 && (ratio = 1); | ||
const perpLength = Math.sqrt(perpX * perpX + perpY * perpY); | ||
if (perpLength < 1e-6) { | ||
perpX = 0; | ||
perpY = 0; | ||
} else { | ||
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; | ||
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; | ||
} | ||
@@ -120,11 +78,6 @@ this.buffers[0].update(); | ||
update() { | ||
if (this.textureScale > 0) { | ||
this.build(); | ||
} else { | ||
this.updateVertices(); | ||
} | ||
this.textureScale > 0 ? this.build() : this.updateVertices(); | ||
} | ||
} | ||
exports.RopeGeometry = RopeGeometry; | ||
//# sourceMappingURL=RopeGeometry.js.map |
@@ -1,14 +0,3 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var PlaneGeometry = require('./geometry/PlaneGeometry.js'); | ||
var RopeGeometry = require('./geometry/RopeGeometry.js'); | ||
var NineSlicePlane = require('./NineSlicePlane.js'); | ||
var SimpleMesh = require('./SimpleMesh.js'); | ||
var SimplePlane = require('./SimplePlane.js'); | ||
var SimpleRope = require('./SimpleRope.js'); | ||
"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; | ||
@@ -15,0 +4,0 @@ exports.RopeGeometry = RopeGeometry.RopeGeometry; |
@@ -1,25 +0,17 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var core = require('@pixi/core'); | ||
var SimplePlane = require('./SimplePlane.js'); | ||
"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; | ||
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(); | ||
this._textureID = this.shader.texture._updateID, this._refresh(); | ||
} | ||
@@ -32,24 +24,21 @@ get vertices() { | ||
} | ||
/** Updates the horizontal vertices. */ | ||
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; | ||
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; | ||
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; | ||
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; | ||
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; | ||
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() { | ||
@@ -59,5 +48,5 @@ return this._width; | ||
set width(value) { | ||
this._width = value; | ||
this._refresh(); | ||
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() { | ||
@@ -67,5 +56,5 @@ return this._height; | ||
set height(value) { | ||
this._height = value; | ||
this._refresh(); | ||
this._height = value, this._refresh(); | ||
} | ||
/** The width of the left column. */ | ||
get leftWidth() { | ||
@@ -75,5 +64,5 @@ return this._leftWidth; | ||
set leftWidth(value) { | ||
this._leftWidth = value; | ||
this._refresh(); | ||
this._leftWidth = value, this._refresh(); | ||
} | ||
/** The width of the right column. */ | ||
get rightWidth() { | ||
@@ -83,5 +72,5 @@ return this._rightWidth; | ||
set rightWidth(value) { | ||
this._rightWidth = value; | ||
this._refresh(); | ||
this._rightWidth = value, this._refresh(); | ||
} | ||
/** The height of the top row. */ | ||
get topHeight() { | ||
@@ -91,5 +80,5 @@ return this._topHeight; | ||
set topHeight(value) { | ||
this._topHeight = value; | ||
this._refresh(); | ||
this._topHeight = value, this._refresh(); | ||
} | ||
/** The height of the bottom row. */ | ||
get bottomHeight() { | ||
@@ -99,28 +88,13 @@ return this._bottomHeight; | ||
set bottomHeight(value) { | ||
this._bottomHeight = value; | ||
this._refresh(); | ||
this._bottomHeight = value, this._refresh(); | ||
} | ||
/** Refreshes NineSlicePlane coords. All of them. */ | ||
_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(); | ||
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 |
@@ -1,16 +0,21 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var core = require('@pixi/core'); | ||
var mesh = require('@pixi/mesh'); | ||
"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 = false; | ||
geometry.getBuffer("aVertexPosition").static = !1; | ||
const meshMaterial = new mesh.MeshMaterial(texture); | ||
super(geometry, meshMaterial, null, drawMode); | ||
this.autoUpdate = true; | ||
super(geometry, meshMaterial, null, drawMode), this.autoUpdate = !0; | ||
} | ||
/** | ||
* Collection of vertices data. | ||
* @type {Float32Array} | ||
*/ | ||
get vertices() { | ||
@@ -23,10 +28,6 @@ return this.geometry.getBuffer("aVertexPosition").data; | ||
_render(renderer) { | ||
if (this.autoUpdate) { | ||
this.geometry.getBuffer("aVertexPosition").update(); | ||
} | ||
super._render(renderer); | ||
this.autoUpdate && this.geometry.getBuffer("aVertexPosition").update(), super._render(renderer); | ||
} | ||
} | ||
exports.SimpleMesh = SimpleMesh; | ||
//# sourceMappingURL=SimpleMesh.js.map |
@@ -1,38 +0,24 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var core = require('@pixi/core'); | ||
var mesh = require('@pixi/mesh'); | ||
var PlaneGeometry = require('./geometry/PlaneGeometry.js'); | ||
"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); | ||
const meshMaterial = new mesh.MeshMaterial(core.Texture.WHITE); | ||
super(planeGeometry, meshMaterial); | ||
this.texture = texture; | ||
this.autoResize = true; | ||
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; | ||
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(); | ||
} | ||
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) { | ||
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); | ||
} | ||
this.shader.texture !== value && (this.shader.texture = value, this._textureID = -1, value.baseTexture.valid ? this.textureUpdated() : value.once("update", this.textureUpdated, this)); | ||
} | ||
@@ -43,14 +29,9 @@ get texture() { | ||
_render(renderer) { | ||
if (this._textureID !== this.shader.texture._updateID) { | ||
this.textureUpdated(); | ||
} | ||
super._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); | ||
this.shader.texture.off("update", this.textureUpdated, this), super.destroy(options); | ||
} | ||
} | ||
exports.SimplePlane = SimplePlane; | ||
//# sourceMappingURL=SimplePlane.js.map |
@@ -1,30 +0,22 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var core = require('@pixi/core'); | ||
var mesh = require('@pixi/mesh'); | ||
var RopeGeometry = require('./geometry/RopeGeometry.js'); | ||
"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); | ||
const meshMaterial = new mesh.MeshMaterial(texture); | ||
if (textureScale > 0) { | ||
texture.baseTexture.wrapMode = core.WRAP_MODES.REPEAT; | ||
} | ||
super(ropeGeometry, meshMaterial); | ||
this.autoUpdate = true; | ||
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; | ||
if (this.autoUpdate || geometry._width !== this.shader.texture.height) { | ||
geometry._width = this.shader.texture.height; | ||
geometry.update(); | ||
} | ||
super._render(renderer); | ||
(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 |
{ | ||
"name": "@pixi/mesh-extras", | ||
"version": "7.2.4", | ||
"version": "7.3.0-rc", | ||
"main": "lib/index.js", | ||
@@ -39,5 +39,5 @@ "module": "lib/index.mjs", | ||
"peerDependencies": { | ||
"@pixi/core": "7.2.4", | ||
"@pixi/mesh": "7.2.4" | ||
"@pixi/core": "7.3.0-rc", | ||
"@pixi/mesh": "7.3.0-rc" | ||
} | ||
} |
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
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
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110462
911
1