Moved uvScroll, uvScale and rotate setters to Mesh

This commit is contained in:
Richard Davey 2023-01-27 17:46:17 +00:00
parent dae80ee845
commit 674bcbe6f8

View file

@ -9,11 +9,12 @@ var Components = require('../components');
var DegToRad = require('../../math/DegToRad');
var Face = require('../../geom/mesh/Face');
var GameObject = require('../GameObject');
var GenerateVerts = require('../../geom/mesh/GenerateVerts');
var GenerateObjVerts = require('../../geom/mesh/GenerateObjVerts');
var GenerateVerts = require('../../geom/mesh/GenerateVerts');
var GetCalcMatrix = require('../GetCalcMatrix');
var Matrix4 = require('../../math/Matrix4');
var MeshRender = require('./MeshRender');
var RadToDeg = require('../../math/RadToDeg');
var StableSort = require('../../utils/array/StableSort');
var Vector3 = require('../../math/Vector3');
var Vertex = require('../../geom/mesh/Vertex');
@ -62,13 +63,14 @@ var Vertex = require('../../geom/mesh/Vertex');
* @extends Phaser.GameObjects.Components.AlphaSingle
* @extends Phaser.GameObjects.Components.BlendMode
* @extends Phaser.GameObjects.Components.Depth
* @extends Phaser.GameObjects.Components.FX
* @extends Phaser.GameObjects.Components.Mask
* @extends Phaser.GameObjects.Components.Pipeline
* @extends Phaser.GameObjects.Components.ScrollFactor
* @extends Phaser.GameObjects.Components.Size
* @extends Phaser.GameObjects.Components.Texture
* @extends Phaser.GameObjects.Components.Transform
* @extends Phaser.GameObjects.Components.Visible
* @extends Phaser.GameObjects.Components.ScrollFactor
*
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
* @param {number} [x] - The horizontal position of this Game Object in the world.
@ -91,13 +93,14 @@ var Mesh = new Class({
Components.AlphaSingle,
Components.BlendMode,
Components.Depth,
Components.FX,
Components.Mask,
Components.Pipeline,
Components.ScrollFactor,
Components.Size,
Components.Texture,
Components.Transform,
Components.Visible,
Components.ScrollFactor,
MeshRender
],
@ -1175,6 +1178,82 @@ var Mesh = new Class({
return this;
},
/**
* Scrolls the UV texture coordinates of all faces in this Mesh by
* adding the given x/y amounts to them.
*
* If you only wish to scroll one coordinate, pass a value of zero
* to the other.
*
* Use small values for scrolling. UVs are set from the range 0
* to 1, so you should increment (or decrement) them by suitably
* small values, such as 0.01.
*
* Due to a limitation in WebGL1 you can only UV scroll textures
* that are a power-of-two in size. Scrolling NPOT textures will
* work but will result in clamping the pixels to the edges.
*
* Note that if this Mesh is using a _frame_ from a texture atlas
* then you will be unable to UV scroll its texture.
*
* @method Phaser.GameObjects.Mesh#uvScroll
* @webglOnly
* @since 3.60.0
*
* @param {number} x - The amount to horizontally shift the UV coordinates by.
* @param {number} y - The amount to vertically shift the UV coordinates by.
*
* @return {this} This Game Object instance.
*/
uvScroll: function (x, y)
{
var faces = this.faces;
for (var i = 0; i < faces.length; i++)
{
faces[i].scrollUV(x, y);
}
return this;
},
/**
* Scales the UV texture coordinates of all faces in this Mesh by
* the exact given amounts.
*
* If you only wish to scale one coordinate, pass a value of one
* to the other.
*
* Due to a limitation in WebGL1 you can only UV scale textures
* that are a power-of-two in size. Scaling NPOT textures will
* work but will result in clamping the pixels to the edges if
* you scale beyond a value of 1. Scaling below 1 will work
* regardless of texture size.
*
* Note that if this Mesh is using a _frame_ from a texture atlas
* then you will be unable to UV scale its texture.
*
* @method Phaser.GameObjects.Mesh#uvScale
* @webglOnly
* @since 3.60.0
*
* @param {number} x - The amount to horizontally scale the UV coordinates by.
* @param {number} y - The amount to vertically scale the UV coordinates by.
*
* @return {this} This Game Object instance.
*/
uvScale: function (x, y)
{
var faces = this.faces;
for (var i = 0; i < faces.length; i++)
{
faces[i].scaleUV(x, y);
}
return this;
},
/**
* The tint value being applied to the whole of the Game Object.
* This property is a setter-only.
@ -1190,7 +1269,77 @@ var Mesh = new Class({
{
this.setTint(value);
}
},
/**
* The x rotation of the Model in 3D space, as specified in degrees.
*
* If you need the value in radians use the `modelRotation.x` property directly.
*
* @method Phaser.GameObjects.Mesh#rotateX
* @type {number}
* @since 3.60.0
*/
rotateX: {
get: function ()
{
return RadToDeg(this.modelRotation.x);
},
set: function (value)
{
this.modelRotation.x = DegToRad(value);
}
},
/**
* The y rotation of the Model in 3D space, as specified in degrees.
*
* If you need the value in radians use the `modelRotation.y` property directly.
*
* @method Phaser.GameObjects.Mesh#rotateY
* @type {number}
* @since 3.60.0
*/
rotateY: {
get: function ()
{
return RadToDeg(this.modelRotation.y);
},
set: function (value)
{
this.modelRotation.y = DegToRad(value);
}
},
/**
* The z rotation of the Model in 3D space, as specified in degrees.
*
* If you need the value in radians use the `modelRotation.z` property directly.
*
* @method Phaser.GameObjects.Mesh#rotateZ
* @type {number}
* @since 3.60.0
*/
rotateZ: {
get: function ()
{
return RadToDeg(this.modelRotation.z);
},
set: function (value)
{
this.modelRotation.z = DegToRad(value);
}
}
});
module.exports = Mesh;