Skip to content

Commit b774df9

Browse files
committed
More documentation
1 parent 7f646d8 commit b774df9

1 file changed

Lines changed: 41 additions & 14 deletions

File tree

src/gameobjects/mesh/Mesh.js

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ var Mesh = new Class({
108108
*
109109
* A Face consists of 3 Vertex objects.
110110
*
111-
* This array is populated during the `setVertices` method.
111+
* This array is populated during calls such as `addFace` or `addOBJ`.
112112
*
113113
* @name Phaser.GameObjects.Mesh#faces
114114
* @type {Phaser.Geom.Mesh.Face[]}
@@ -119,7 +119,7 @@ var Mesh = new Class({
119119
/**
120120
* An array containing Vertex instances. One instance per vertex in this Mesh.
121121
*
122-
* This array is populated during the `setVertices` method.
122+
* This array is populated during calls such as `addVertex` or `addOBJ`.
123123
*
124124
* @name Phaser.GameObjects.Mesh#vertices
125125
* @type {Phaser.Geom.Mesh.Vertex[]}
@@ -131,7 +131,7 @@ var Mesh = new Class({
131131
* The tint fill mode.
132132
*
133133
* `false` = An additive tint (the default), where vertices colors are blended with the texture.
134-
* `true` = A fill tint, where the vertices colors replace the texture, but respects texture alpha.
134+
* `true` = A fill tint, where the vertex colors replace the texture, but respects texture alpha.
135135
*
136136
* @name Phaser.GameObjects.Mesh#tintFill
137137
* @type {boolean}
@@ -157,6 +157,8 @@ var Mesh = new Class({
157157
*
158158
* To disable rendering, set this property back to `null`.
159159
*
160+
* Please note that high vertex count Meshes will struggle to debug properly.
161+
*
160162
* @name Phaser.GameObjects.Mesh#debugCallback
161163
* @type {function}
162164
* @since 3.50.0
@@ -177,6 +179,7 @@ var Mesh = new Class({
177179
* When rendering, skip any Face that isn't counter clockwise?
178180
*
179181
* Enable this to hide backward-facing Faces during rendering.
182+
*
180183
* Disable it to render all Faces.
181184
*
182185
* @name Phaser.GameObjects.Mesh#hideCCW
@@ -212,8 +215,8 @@ var Mesh = new Class({
212215
},
213216

214217
/**
215-
* Iterates and destroys all current Faces in this Mesh, if any.
216-
* Then resets the Face and Vertices arrays.
218+
* Iterates and destroys all current Faces in this Mesh, then resets the
219+
* `faces` and `vertices` arrays.
217220
*
218221
* @method Phaser.GameObjects.Mesh#clearVertices
219222
* @since 3.50.0
@@ -234,21 +237,21 @@ var Mesh = new Class({
234237
},
235238

236239
/**
237-
* This method will add the model data from a loaded triangulated Wavefront OBJ file to this Mesh.
240+
* This method will add the data from a triangulated Wavefront OBJ model file to this Mesh.
238241
*
239-
* The obj should have been loaded via the OBJFile:
242+
* The data should have been loaded via the OBJFile:
240243
*
241244
* ```javascript
242245
* this.load.obj(key, url);
243246
* ```
244247
*
245-
* Then use the key it was loaded under in this call.
248+
* Then use the same `key` as the first parameter to this method.
246249
*
247-
* Multiple Mesh objects can use the same model data without impacting on each other.
250+
* Multiple Mesh Game Objects can use the same model data without impacting on each other.
248251
*
249252
* Make sure your 3D package has triangulated the model data prior to exporting it.
250253
*
251-
* You may add multiple models to a single Mesh, although they will act as one when
254+
* You can add multiple models to a single Mesh, although they will act as one when
252255
* moved or rotated. You can scale the model data, should it be too small, or too large, to see.
253256
* You can also offset the vertices of the model via the `x`, `y` and `z` parameters.
254257
*
@@ -275,10 +278,34 @@ var Mesh = new Class({
275278
return this;
276279
},
277280

278-
addGrid: function (width, height, widthSegments, heightSegments)
281+
/**
282+
* Creates a grid based on the given parameters and adds it to this Mesh.
283+
*
284+
* The size of the grid is given in pixels.
285+
*
286+
* You can optionally split the grid into segments both vertically and horizontally. This will
287+
* generate two faces per grid segment as a result.
288+
*
289+
* You may add multiple grids to a single Mesh, although they will act as one when
290+
* moved or rotated. You can offset the model via the `posX`, `posY` and `posZ` parameters.
291+
*
292+
* @method Phaser.GameObjects.Mesh#addGrid
293+
* @since 3.50.0
294+
*
295+
* @param {number} [width=128] - The width of the grid in pixels.
296+
* @param {number} [height=128] - The height of the grid in pixels.
297+
* @param {number} [widthSegments=1] - The number of segments to split the grid horizontally in to.
298+
* @param {number} [heightSegments=1] - The number of segments to split the grid vertically in to.
299+
* @param {number} [posX=0] - Offset the grid x position by this amount.
300+
* @param {number} [posY=0] - Offset the grid y position by this amount.
301+
* @param {number} [posZ=0] - Offset the grid z position by this amount.
302+
*
303+
* @return {this} This Mesh Game Object.
304+
*/
305+
addGrid: function (width, height, widthSegments, heightSegments, posX, posY, posZ)
279306
{
280-
if (width === undefined) { width = 1; }
281-
if (height === undefined) { height = 1; }
307+
if (width === undefined) { width = 128; }
308+
if (height === undefined) { height = 128; }
282309
if (widthSegments === undefined) { widthSegments = 1; }
283310
if (heightSegments === undefined) { heightSegments = 1; }
284311

@@ -330,7 +357,7 @@ var Mesh = new Class({
330357
}
331358
}
332359

333-
return { vertices: vertices, uvs: uvs, indices: indices };
360+
return this.addModel({ vertices: vertices, uvs: uvs, indices: indices }, 1, posX, posY, posZ);
334361
},
335362

336363
/**

0 commit comments

Comments
 (0)