Skip to content

Commit 7287a76

Browse files
committed
Added ParseOBJ type defs
1 parent 85ba803 commit 7287a76

9 files changed

Lines changed: 68 additions & 6 deletions

File tree

src/gameobjects/mesh/Mesh.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ var Mesh = new Class({
255255
* moved or rotated. You can scale the model data, should it be too small, or too large, to see.
256256
* You can also offset the vertices of the model via the `x`, `y` and `z` parameters.
257257
*
258+
* If you wish to add OBJ data to this Mesh without loading it, you can call the `Mesh.addModel` method directly.
259+
*
258260
* @method Phaser.GameObjects.Mesh#addOBJ
259261
* @since 3.50.0
260262
*
@@ -369,7 +371,7 @@ var Mesh = new Class({
369371
* The obj should have been parsed in advance via the ParseObj function:
370372
*
371373
* ```javascript
372-
* var data = Phaser.Geom.ParseObj(rawData, flipUV);
374+
* var data = Phaser.Geom.Mesh.ParseObj(rawData, flipUV);
373375
*
374376
* Mesh.addModel(data);
375377
* ```
@@ -385,7 +387,7 @@ var Mesh = new Class({
385387
* @method Phaser.GameObjects.Mesh#addModel
386388
* @since 3.50.0
387389
*
388-
* @param {array} data - The parsed model data array.
390+
* @param {Phaser.Types.Geom.Mesh.OBJData} data - The parsed OBJ model data.
389391
* @param {number} [scale=1] - An amount to scale the model data by. Use this if the model has exported too small, or large, to see.
390392
* @param {number} [x=0] - Offset the model x position by this amount.
391393
* @param {number} [y=0] - Offset the model y position by this amount.

src/geom/mesh/ParseObj.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,17 @@ function parseUseMtl (lineItems)
224224
}
225225

226226
/**
227-
* Parses a Wavefront OBJ File, extracting the models from it and returning them
228-
* in an array. The model data *must* be triangulated.
227+
* Parses a Wavefront OBJ File, extracting the models from it and returning them in an array.
228+
*
229+
* The model data *must* be triangulated for a Mesh Game Object to be able to render it.
229230
*
230231
* @function Phaser.Geom.Mesh.ParseObj
231232
* @since 3.50.0
232233
*
233234
* @param {string} data - The OBJ File data as a raw string.
234-
* @param {boolean} [flipUV=true] - Flip the UV data?
235+
* @param {boolean} [flipUV=true] - Flip the UV coordinates?
235236
*
236-
* @return {object} The parsed model data.
237+
* @return {Phaser.Types.Geom.Mesh.OBJData} The parsed model and material data.
237238
*/
238239
var ParseObj = function (data, flipUV)
239240
{

src/geom/mesh/typedefs/OBJData.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @typedef {object} Phaser.Types.Geom.Mesh.OBJData
3+
* @since 3.50.0
4+
*
5+
* @property {string[]} materialLibraries - An array of material libraries in the OBJ file.
6+
* @property {Phaser.Types.Geom.Mesh.OBJModel[]} models - An array of parsed models extracted from the OBJ file.
7+
*/

src/geom/mesh/typedefs/OBJFace.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @typedef {object} Phaser.Types.Geom.Mesh.OBJFace
3+
* @since 3.50.0
4+
*
5+
* @property {string} group - The name of the Group this Face is in.
6+
* @property {string} material - The name of the material this Face uses.
7+
* @property {Phaser.Types.Geom.Mesh.OBJFaceVertice[]} vertices - An array of vertices in this Face.
8+
*/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @typedef {object} Phaser.Types.Geom.Mesh.OBJFaceVertice
3+
* @since 3.50.0
4+
*
5+
* @property {number} textureCoordsIndex - The index in the `textureCoords` array that this vertex uses.
6+
* @property {number} vertexIndex - The index in the `vertices` array that this vertex uses.
7+
* @property {number} vertexNormalIndex - The index in the `vertexNormals` array that this vertex uses.
8+
*/

src/geom/mesh/typedefs/OBJModel.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @typedef {object} Phaser.Types.Geom.Mesh.OBJModel
3+
* @since 3.50.0
4+
*
5+
* @property {Phaser.Types.Geom.Mesh.OBJFace[]} faces - An array of Faces.
6+
* @property {string} name - The name of the model.
7+
* @property {Phaser.Types.Geom.Mesh.UV[]} textureCoords - An array of texture coordinates.
8+
* @property {Phaser.Types.Math.Vector3Like[]} vertexNormals - An array of vertex normals.
9+
* @property {Phaser.Types.Math.Vector3Like[]} vertices - An array of vertices in the model.
10+
*/

src/geom/mesh/typedefs/UV.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @typedef {object} Phaser.Types.Geom.Mesh.UV
3+
* @since 3.50.0
4+
*
5+
* @property {number} u - The u component.
6+
* @property {number} v - The v component.
7+
* @property {number} w - The w component.
8+
*/

src/geom/mesh/typedefs/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* @namespace Phaser.Types.Geom.Mesh
9+
*/

src/geom/typedefs/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* @namespace Phaser.Types.Geom
9+
*/

0 commit comments

Comments
 (0)