From eb0731d3be9ba36336289a4319e73b6084c081a3 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 24 Jan 2023 13:43:52 +0000 Subject: [PATCH] Added translated uv coords + scrollUV and scaleUV methods --- src/geom/mesh/Vertex.js | 76 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/src/geom/mesh/Vertex.js b/src/geom/mesh/Vertex.js index a7ef68a36..147074ce7 100644 --- a/src/geom/mesh/Vertex.js +++ b/src/geom/mesh/Vertex.js @@ -165,11 +165,32 @@ var Vertex = new Class({ * @since 3.50.0 */ this.ta = 0; + + /** + * The translated uv u coordinate of this vertex. + * + * @name Phaser.Geom.Mesh.Vertex#tu + * @type {number} + * @since 3.60.0 + */ + this.tu = u; + + /** + * The translated uv v coordinate of this vertex. + * + * @name Phaser.Geom.Mesh.Vertex#tv + * @type {number} + * @since 3.60.0 + */ + this.tv = v; }, /** * Sets the U and V properties. * + * Also resets the translated uv properties, undoing any scale + * or shift they may have had. + * * @method Phaser.Geom.Mesh.Vertex#setUVs * @since 3.50.0 * @@ -183,6 +204,57 @@ var Vertex = new Class({ this.u = u; this.v = v; + this.tu = u; + this.tv = v; + + return this; + }, + + /** + * Translates the original UV positions by the given amounts. + * + * The original properties `Vertex.u` and `Vertex.v` + * remain unchanged, only the translated properties + * `Vertex.tu` and `Vertex.tv`, as used in rendering, + * are updated. + * + * @method Phaser.Geom.Mesh.Vertex#scrollUV + * @since 3.60.0 + * + * @param {number} x - The amount to scroll the UV u coordinate by. + * @param {number} y - The amount to scroll the UV v coordinate by. + * + * @return {this} This Vertex. + */ + scrollUV: function (x, y) + { + this.tu += x; + this.tv += y; + + return this; + }, + + /** + * Scales the original UV values by the given amounts. + * + * The original properties `Vertex.u` and `Vertex.v` + * remain unchanged, only the translated properties + * `Vertex.tu` and `Vertex.tv`, as used in rendering, + * are updated. + * + * @method Phaser.Geom.Mesh.Vertex#scaleUV + * @since 3.60.0 + * + * @param {number} x - The amount to scale the UV u coordinate by. + * @param {number} y - The amount to scale the UV v coordinate by. + * + * @return {this} This Vertex. + */ + scaleUV: function (x, y) + { + this.tu = this.u * x; + this.tv = this.v * y; + return this; }, @@ -322,8 +394,8 @@ var Vertex = new Class({ { F32[++offset] = this.tx; F32[++offset] = this.ty; - F32[++offset] = this.u; - F32[++offset] = this.v; + F32[++offset] = this.tu; + F32[++offset] = this.tv; F32[++offset] = textureUnit; F32[++offset] = tintEffect; U32[++offset] = Utils.getTintAppendFloatAlpha(this.color, this.ta);