- Source: src/geom/mesh/index.js (Line 7)
Classes
Methods
-
<static> GenerateGridVerts(config)
-
Creates a grid of vertices based on the given configuration object and optionally adds it to a Mesh.
The size of the grid is given in pixels. An example configuration may be:
{ width: 256, height: 256, widthSegments: 2, heightSegments: 2, tile: true }This will create a grid 256 x 256 pixels in size, split into 2 x 2 segments, with the texture tiling across the cells.
You can split the grid into segments both vertically and horizontally. This will generate two faces per grid segment as a result.
The
tileparameter allows you to control if the tile will repeat across the grid segments, or be displayed in full.If adding this grid to a Mesh you can offset the grid via the
xandyproperties.UV coordinates are generated based on the given texture and frame in the config. For example, no frame is given, the UVs will be in the range 0 to 1. If a frame is given, such as from a texture atlas, the UVs will be generated within the range of that frame.
Parameters:
Name Type Description configPhaser.Types.Geom.Mesh.GenerateGridConfig A Grid configuration object.
- Since: 3.50.0
- Source: src/geom/mesh/GenerateGridVerts.js (Line 17)
Returns:
A Grid Result object, containing the generated vertices and indicies.
-
<static> GenerateObjVerts(data [, mesh] [, scale] [, x] [, y] [, z] [, rotateX] [, rotateY] [, rotateZ] [, zIsUp])
-
This method will return an object containing Face and Vertex instances, generated from the parsed triangulated OBJ Model data given to this function.
The obj data should have been parsed in advance via the ParseObj function:
var data = Phaser.Geom.Mesh.ParseObj(rawData, flipUV); var results = GenerateObjVerts(data);Alternatively, you can parse obj files loaded via the OBJFile loader:
preload () { this.load.obj('alien', 'assets/3d/alien.obj); } var results = GenerateObjVerts(this.cache.obj.get('alien));Make sure your 3D package has triangulated the model data prior to exporting it.
You can use the data returned by this function to populate the vertices of a Mesh Game Object.
You may add multiple models to a single Mesh, although they will act as one when moved or rotated. You can scale the model data, should it be too small (or large) to visualize. You can also offset the model via the
x,yandzparameters.Parameters:
Name Type Argument Default Description dataPhaser.Types.Geom.Mesh.OBJData The parsed OBJ model data.
meshPhaser.GameObjects.Mesh <optional>
An optional Mesh Game Object. If given, the generated Faces will be automatically added to this Mesh. Set to
nullto skip.scalenumber <optional>
1 An amount to scale the model data by. Use this if the model has exported too small, or large, to see.
xnumber <optional>
0 Translate the model x position by this amount.
ynumber <optional>
0 Translate the model y position by this amount.
znumber <optional>
0 Translate the model z position by this amount.
rotateXnumber <optional>
0 Rotate the model on the x axis by this amount, in radians.
rotateYnumber <optional>
0 Rotate the model on the y axis by this amount, in radians.
rotateZnumber <optional>
0 Rotate the model on the z axis by this amount, in radians.
zIsUpboolean <optional>
true Is the z axis up (true), or is y axis up (false)?
- Since: 3.50.0
- Source: src/geom/mesh/GenerateObjVerts.js (Line 16)
Returns:
The parsed Face and Vertex objects.
-
<static> GenerateVerts(vertices, uvs [, indicies] [, containsZ] [, normals] [, colors] [, alphas])
-
Generates a set of Face and Vertex objects by parsing the given data.
This method will take vertex data in one of two formats, based on the
containsZparameter.If your vertex data are
x,ypairs, thencontainsZshould befalse(this is the default)If your vertex data is groups of
x,yandzvalues, then thecontainsZparameter must be true.The
uvsparameter is a numeric array consisting ofuandvpairs.The
normalsparameter is a numeric array consisting ofx,yvertex normal values and, ifcontainsZis true,zvalues as well.The
indiciesparameter is an optional array that, if given, is an indexed list of vertices to be added.The
colorsparameter is an optional array, or single value, that if given sets the color of each vertex created.The
alphasparameter is an optional array, or single value, that if given sets the alpha of each vertex created.When providing indexed data it is assumed that all of the arrays are indexed, not just the vertices.
The following example will create a 256 x 256 sized quad using an index array:
const vertices = [ -128, 128, 128, 128, -128, -128, 128, -128 ]; const uvs = [ 0, 1, 1, 1, 0, 0, 1, 0 ]; const indices = [ 0, 2, 1, 2, 3, 1 ]; GenerateVerts(vertices, uvs, indicies);If the data is not indexed, it's assumed that the arrays all contain sequential data.
Parameters:
Name Type Argument Default Description verticesArray.<number> The vertices array. Either
xypairs, orxyzif thecontainsZparameter istrue.uvsArray.<number> The UVs pairs array.
indiciesArray.<number> <optional>
Optional vertex indicies array. If you don't have one, pass
nullor an empty array.containsZboolean <optional>
false Does the vertices data include a
zcomponent?normalsArray.<number> <optional>
Optional vertex normals array. If you don't have one, pass
nullor an empty array.colorsnumber | Array.<number> <optional>
0xffffff An array of colors, one per vertex, or a single color value applied to all vertices.
alphasnumber | Array.<number> <optional>
1 An array of alpha values, one per vertex, or a single alpha value applied to all vertices.
- Since: 3.50.0
- Source: src/geom/mesh/GenerateVerts.js (Line 10)
Returns:
The parsed Face and Vertex objects.
-
<static> ParseObj(data [, flipUV])
-
Parses a Wavefront OBJ File, extracting the models from it and returning them in an array.
The model data must be triangulated for a Mesh Game Object to be able to render it.
Parameters:
Name Type Argument Default Description datastring The OBJ File data as a raw string.
flipUVboolean <optional>
true Flip the UV coordinates?
- Since: 3.50.0
- Source: src/geom/mesh/ParseObj.js (Line 226)
Returns:
The parsed model and material data.
-
<static> ParseObjMaterial(mtl)
-
Takes a Wavefront Material file and extracts the diffuse reflectivity of the named materials, converts them to integer color values and returns them.
This is used internally by the
addOBJandaddModelmethods, but is exposed for public consumption as well.Note this only works with diffuse values, specified in the
Kd r g bformat, wheregandbare optional, butris required. It does not support spectral rfl files, or any other material statement (such asKaorKs)Parameters:
Name Type Description mtlstring The OBJ MTL file as a raw string, i.e. loaded via
this.load.text.- Since: 3.50.0
- Source: src/geom/mesh/ParseObjMaterial.js (Line 9)
Returns:
The parsed material colors, where each property of the object matches the material name.
- Type
- object
-
<static> RotateFace(face, angle [, cx] [, cy])
-
Rotates the vertices of a Face to the given angle.
The actual vertex positions are adjusted, not their transformed positions.
Therefore, this updates the vertex data directly.
Parameters:
Name Type Argument Description facePhaser.Geom.Mesh.Face The Face to rotate.
anglenumber The angle to rotate to, in radians.
cxnumber <optional>
An optional center of rotation. If not given, the Face in-center is used.
cynumber <optional>
An optional center of rotation. If not given, the Face in-center is used.
- Since: 3.50.0
- Source: src/geom/mesh/RotateFace.js (Line 7)
