Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Geom . Mesh . Vertex

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Geom . Mesh . Vertex

A Vertex Geometry Object.

This class consists of all the information required for a single vertex within a Face Geometry Object.

Faces, and thus Vertex objects, are used by the Mesh Game Object in order to render objects in WebGL.

Constructor:

new Vertex(x, y, z, u, v, [color], [alpha], [nx], [ny], [nz])

Parameters:

name type arguments Default description
x number

The x position of the vertex.

y number

The y position of the vertex.

z number

The z position of the vertex.

u number

The UV u coordinate of the vertex.

v number

The UV v coordinate of the vertex.

color number <optional> 0xffffff

The color value of the vertex.

alpha number <optional> 1

The alpha value of the vertex.

nx number <optional> 0

The x normal value of the vertex.

ny number <optional> 0

The y normal value of the vertex.

nz number <optional> 0

The z normal value of the vertex.

Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 11)

Extends


Members

alpha: number
Focus
Focus

Description:

The alpha value of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 133)
Focus
Focus
color: number
Focus
Focus

Description:

The color value of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 124)
Focus
Focus
nx: number
Focus
Focus

Description:

The projected x coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 79)
Focus
Focus
ny: number
Focus
Focus

Description:

The projected y coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 88)
Focus
Focus
nz: number
Focus
Focus

Description:

The projected z coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 97)
Focus
Focus
ta: number
Focus
Focus

Description:

The translated alpha value of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 160)
Focus
Focus
tx: number
Focus
Focus

Description:

The translated x coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 142)
Focus
Focus
ty: number
Focus
Focus

Description:

The translated y coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 151)
Focus
Focus
u: number
Focus
Focus

Description:

UV u coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 106)
Focus
Focus
v: number
Focus
Focus

Description:

UV v coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 115)
Focus
Focus
vx: number
Focus
Focus

Description:

The projected x coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 52)
Focus
Focus
vy: number
Focus
Focus

Description:

The projected y coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 61)
Focus
Focus
vz: number
Focus
Focus

Description:

The projected z coordinate of this vertex.

Type:
number
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 70)
Focus
Focus
x: number
Focus
Focus

Description:

The x component of this Vector.

Type:
number
Default: 0
Inherited from: Phaser.Math.Vector3#x
Since: 3.0.0
Source: src/math/Vector3.js (Line 33)
Focus
Focus
y: number
Focus
Focus

Description:

The y component of this Vector.

Type:
number
Default: 0
Inherited from: Phaser.Math.Vector3#y
Since: 3.0.0
Source: src/math/Vector3.js (Line 43)
Focus
Focus
z: number
Focus
Focus

Description:

The z component of this Vector.

Type:
number
Default: 0
Inherited from: Phaser.Math.Vector3#z
Since: 3.0.0
Source: src/math/Vector3.js (Line 53)
Focus
Focus

Methods

add(v)
Focus
Focus

Description:

Add a given Vector to this Vector. Addition is component-wise.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to add to this Vector.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#add
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 317)
Focus
Focus
addScalar(s)
Focus
Focus

Description:

Add the given value to each component of this Vector.

Parameters:

name type description
s number

The amount to add to this Vector.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#addScalar
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 336)
Focus
Focus
addScale(v, scale)
Focus
Focus

Description:

Add and scale a given Vector to this Vector. Addition is component-wise.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to add to this Vector.

scale number

The amount to scale v by.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#addScale
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 355)
Focus
Focus
addVectors(a, b)
Focus
Focus

Description:

Adds the two given Vector3s and sets the results into this Vector3.

Parameters:

name type description
a Phaser.Math.Vector3

The first Vector to add.

b Phaser.Math.Vector3

The second Vector to add.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#addVectors
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 147)
Focus
Focus
applyMatrix3(mat3)
Focus
Focus

Description:

Takes a Matrix3 and applies it to this Vector3.

Parameters:

name type description
mat3 Phaser.Math.Matrix3

The Matrix3 to apply to this Vector3.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#applyMatrix3
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 651)
Focus
Focus
applyMatrix4(mat4)
Focus
Focus

Description:

Takes a Matrix4 and applies it to this Vector3.

Parameters:

name type description
mat4 Phaser.Math.Matrix4

The Matrix4 to apply to this Vector3.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#applyMatrix4
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 675)
Focus
Focus
clone()
Focus
Focus

Description:

Make a clone of this Vector3.

Returns:
Description:

A new Vector3 object containing this Vectors values.

Inherited from: Phaser.Math.Vector3#clone
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 134)
Focus
Focus
copy(src)
Focus
Focus

Description:

Copy the components of a given Vector into this Vector.

Parameters:

name type description
src Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to copy the components from.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#copy
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 211)
Focus
Focus
cross(v)
Focus
Focus

Description:

Calculate the cross (vector) product of this Vector (which will be modified) and the given Vector.

Parameters:

name type description
v Phaser.Math.Vector3

The Vector to cross product with.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#cross
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 597)
Focus
Focus
crossVectors(a, b)
Focus
Focus

Description:

Calculate the cross (vector) product of two given Vectors.

Parameters:

name type description
a Phaser.Math.Vector3

The first Vector to multiply.

b Phaser.Math.Vector3

The second Vector to multiply.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#crossVectors
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 167)
Focus
Focus
distance(v)
Focus
Focus

Description:

Calculate the distance between this Vector and the given Vector.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to calculate the distance to.

Returns:
Description:

The distance from this Vector to the given Vector.

Type:
  • number
Inherited from: Phaser.Math.Vector3#distance
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 481)
Focus
Focus
distanceSq(v)
Focus
Focus

Description:

Calculate the distance between this Vector and the given Vector, squared.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to calculate the distance to.

Returns:
Description:

The distance from this Vector to the given Vector, squared.

Type:
  • number
Inherited from: Phaser.Math.Vector3#distanceSq
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 500)
Focus
Focus
divide(v)
Focus
Focus

Description:

Perform a component-wise division between this Vector and the given Vector.

Divides this Vector by the given Vector.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to divide this Vector by.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#divide
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 443)
Focus
Focus
dot(v)
Focus
Focus

Description:

Calculate the dot product of this Vector and the given Vector.

Parameters:

name type description
v Phaser.Math.Vector3

The Vector3 to dot product with this Vector3.

Returns:
Description:

The dot product of this Vector and v.

Type:
  • number
Inherited from: Phaser.Math.Vector3#dot
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 582)
Focus
Focus
equals(v)
Focus
Focus

Description:

Check whether this Vector is equal to a given Vector.

Performs a strict equality check against each Vector's components.

Parameters:

name type description
v Phaser.Math.Vector3

The Vector3 to compare against.

Returns:
Description:

True if the two vectors strictly match, otherwise false.

Type:
  • boolean
Inherited from: Phaser.Math.Vector3#equals
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 194)
Focus
Focus
fromArray(array, [offset])
Focus
Focus

Description:

Sets the components of this Vector3 from the given array, based on the offset.

Vector3.x = array[offset] Vector3.y = array[offset + 1] Vector3.z = array[offset + 2]

Parameters:

name type arguments description
array Array.<number>

The array of values to get this Vector from.

offset number <optional>

The offset index into the array.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#fromArray
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 291)
Focus
Focus
length()
Focus
Focus

Description:

Calculate the length (or magnitude) of this Vector.

Returns:
Description:

The length of this Vector.

Type:
  • number
Inherited from: Phaser.Math.Vector3#length
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 519)
Focus
Focus
lengthSq()
Focus
Focus

Description:

Calculate the length of this Vector squared.

Returns:
Description:

The length of this Vector, squared.

Type:
  • number
Inherited from: Phaser.Math.Vector3#lengthSq
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 536)
Focus
Focus
lerp(v, [t])
Focus
Focus

Description:

Linearly interpolate between this Vector and the given Vector.

Interpolates this Vector towards the given Vector.

Parameters:

name type arguments description
v Phaser.Math.Vector3

The Vector3 to interpolate towards.

t number <optional>

The interpolation percentage, between 0 and 1.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#lerp
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 623)
Focus
Focus
load(F32, U32, offset, textureUnit, tintEffect)
Focus
Focus

Description:

Loads the data from this Vertex into the given Typed Arrays.

Parameters:

name type description
F32 Float32Array

A Float32 Array to insert the position, UV and unit data in to.

U32 Uint32Array

A Uint32 Array to insert the color and alpha data in to.

offset number

The index of the array to insert this Vertex to.

textureUnit number

The texture unit currently in use.

tintEffect number

The tint effect to use.

Returns:
Description:

The new array offset.

Type:
  • number
Examples:
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 261)
Focus
Focus
max(v)
Focus
Focus

Description:

Sets the components of this Vector to be the Math.max result from the given vector.

Parameters:

name type description
v Phaser.Math.Vector3

The Vector3 to check the maximum values against.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#max
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 115)
Focus
Focus
min(v)
Focus
Focus

Description:

Sets the components of this Vector to be the Math.min result from the given vector.

Parameters:

name type description
v Phaser.Math.Vector3

The Vector3 to check the minimum values against.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#min
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 96)
Focus
Focus
multiply(v)
Focus
Focus

Description:

Perform a component-wise multiplication between this Vector and the given Vector.

Multiplies this Vector by the given Vector.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to multiply this Vector by.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#multiply
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 394)
Focus
Focus
negate()
Focus
Focus

Description:

Negate the x, y and z components of this Vector.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#negate
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 464)
Focus
Focus
normalize()
Focus
Focus

Description:

Normalize this Vector.

Makes the vector a unit length vector (magnitude of 1) in the same direction.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#normalize
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 553)
Focus
Focus
project(mat)
Focus
Focus

Description:

Multiplies this Vector3 by the specified matrix, applying a W divide. This is useful for projection, e.g. unprojecting a 2D point into 3D space.

Parameters:

name type description
mat Phaser.Math.Matrix4

The Matrix4 to multiply this Vector3 with.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#project
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 813)
Focus
Focus
projectViewMatrix(viewMatrix, projectionMatrix)
Focus
Focus

Description:

Multiplies this Vector3 by the given view and projection matrices.

Parameters:

name type description
viewMatrix Phaser.Math.Matrix4

A View Matrix.

projectionMatrix Phaser.Math.Matrix4

A Projection Matrix.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#projectViewMatrix
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 857)
Focus
Focus
reset()
Focus
Focus

Description:

Make this Vector the zero vector (0, 0, 0).

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#reset
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 925)
Focus
Focus
scale(scale)
Focus
Focus

Description:

Scale this Vector by the given value.

Parameters:

name type description
scale number

The value to scale this Vector by.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#scale
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 415)
Focus
Focus
set(x, [y], [z])
Focus
Focus

Description:

Set the x, y, and z components of this Vector to the given x, y, and z values.

Parameters:

name type arguments description
x number | object

The x value to set for this Vector, or an object containing x, y and z components.

y number <optional>

The y value to set for this Vector.

z number <optional>

The z value to set for this Vector.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#set
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 230)
Focus
Focus
setFromMatrixColumn(mat4, index)
Focus
Focus

Description:

Sets the components of this Vector3 from the Matrix4 column specified.

Parameters:

name type description
mat4 Phaser.Math.Matrix4

The Matrix4 to get the column from.

index number

The column index.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#setFromMatrixColumn
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 275)
Focus
Focus
setFromMatrixPosition(mat4)
Focus
Focus

Description:

Sets the components of this Vector3 from the position of the given Matrix4.

Parameters:

name type description
mat4 Phaser.Math.Matrix4

The Matrix4 to get the position from.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#setFromMatrixPosition
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 260)
Focus
Focus
setUVs(u, v)
Focus
Focus

Description:

Sets the U and V properties.

Parameters:

name type description
u number

The UV u coordinate of the vertex.

v number

The UV v coordinate of the vertex.

Returns:
Description:

This Vertex.

Examples:
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 170)
Focus
Focus
subtract(v)
Focus
Focus

Description:

Subtract the given Vector from this Vector. Subtraction is component-wise.

Parameters:

name type description
v Phaser.Math.Vector2 | Phaser.Math.Vector3

The Vector to subtract from this Vector.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#subtract
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 375)
Focus
Focus
transformCoordinates(mat)
Focus
Focus

Description:

Transforms the coordinates of this Vector3 with the given Matrix4.

Parameters:

name type description
mat Phaser.Math.Matrix4

The Matrix4 to transform this Vector3 with.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#transformCoordinates
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 749)
Focus
Focus
transformCoordinatesLocal(transformMatrix, width, height, cameraZ)
Focus
Focus

Description:

Transforms this vertex by the given matrix, storing the results in vx, vy and vz.

Parameters:

name type description
transformMatrix Phaser.Math.Matrix4

The transform matrix to apply to this vertex.

width number

The width of the parent Mesh.

height number

The height of the parent Mesh.

cameraZ number

The z position of the MeshCamera.

Examples:
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 189)
Focus
Focus
transformMat3(mat)
Focus
Focus

Description:

Transform this Vector with the given Matrix.

Parameters:

name type description
mat Phaser.Math.Matrix3

The Matrix3 to transform this Vector3 with.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#transformMat3
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 701)
Focus
Focus
transformMat4(mat)
Focus
Focus

Description:

Transform this Vector with the given Matrix4.

Parameters:

name type description
mat Phaser.Math.Matrix4

The Matrix4 to transform this Vector3 with.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#transformMat4
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 725)
Focus
Focus
transformQuat(q)
Focus
Focus

Description:

Transform this Vector with the given Quaternion.

Parameters:

name type description
q Phaser.Math.Quaternion

The Quaternion to transform this Vector with.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#transformQuat
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 778)
Focus
Focus
unproject(viewport, invProjectionView)
Focus
Focus

Description:

Unproject this point from 2D space to 3D space. The point should have its x and y properties set to 2D screen space, and the z either at 0 (near plane) or 1 (far plane). The provided matrix is assumed to already be combined, i.e. projection * view * model.

After this operation, this vector's (x, y, z) components will represent the unprojected 3D coordinate.

Parameters:

name type description
viewport Phaser.Math.Vector4

Screen x, y, width and height in pixels.

invProjectionView Phaser.Math.Matrix4

Combined projection and view matrix.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#unproject
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 889)
Focus
Focus
unprojectViewMatrix(projectionMatrix, worldMatrix)
Focus
Focus

Description:

Multiplies this Vector3 by the given inversed projection matrix and world matrix.

Parameters:

name type description
projectionMatrix Phaser.Math.Matrix4

An inversed Projection Matrix.

worldMatrix Phaser.Math.Matrix4

A World View Matrix.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#unprojectViewMatrix
Examples:
Since: 3.50.0
Source: src/math/Vector3.js (Line 873)
Focus
Focus
up()
Focus
Focus

Description:

Set this Vector to point up.

Sets the y component of the vector to 1, and the others to 0.

Returns:
Description:

This Vector3.

Inherited from: Phaser.Math.Vector3#up
Examples:
Since: 3.0.0
Source: src/math/Vector3.js (Line 77)
Focus
Focus
update(a, b, c, d, e, f, roundPixels, alpha)
Focus
Focus

Description:

Updates this Vertex based on the given transform.

Parameters:

name type description
a number

The parent transform matrix data a component.

b number

The parent transform matrix data b component.

c number

The parent transform matrix data c component.

d number

The parent transform matrix data d component.

e number

The parent transform matrix data e component.

f number

The parent transform matrix data f component.

roundPixels boolean

Round the vertex position or not?

alpha number

The alpha of the parent object.

Returns:
Description:

This Vertex.

Examples:
Since: 3.50.0
Source: src/geom/mesh/Vertex.js (Line 226)
Focus
Focus