Skip to content

Commit b1697f5

Browse files
committed
Merge branch 'master' of https://github.com/photonstorm/phaser
2 parents 3db71de + b916284 commit b1697f5

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

src/gameobjects/mesh/Mesh.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ var Vertex = require('../../geom/mesh/Vertex');
2828
* Support for generating mesh data from grids, model data or Wavefront OBJ Files is included.
2929
*
3030
* Although you can use this to render 3D objects, its primary use is for displaying more complex
31-
* Sprites, or Sprites where you need fine-grained control over the vertice positions in order to
32-
* achieve special effects in your games. Note that rendering still takes place using Phasers
33-
* orthographic camera. As a result, all depth and face tests are done in orthographic space.
31+
* Sprites, or Sprites where you need fine-grained control over the vertex positions in order to
32+
* achieve special effects in your games. Note that rendering still takes place using Phaser's
33+
* orthographic camera (after being transformed via `projectionMesh`, see `setPerspective`,
34+
* `setOrtho`, and `panZ` methods). As a result, all depth and face tests are done in an eventually
35+
* orthographic space.
3436
*
3537
* The rendering process will iterate through the faces of this Mesh and render out each face
3638
* that is considered as being in view of the camera. No depth buffer is used, and because of this,
@@ -73,10 +75,10 @@ var Vertex = require('../../geom/mesh/Vertex');
7375
* @param {number} [y] - The vertical position of this Game Object in the world.
7476
* @param {string|Phaser.Textures.Texture} [texture] - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager.
7577
* @param {string|number} [frame] - An optional frame from the Texture this Game Object is rendering with.
76-
* @param {number[]} [vertices] - The vertices array. Either `xy` pairs, or `xyz` if the `containsZ` parameter is `true`.
78+
* @param {number[]} [vertices] - The vertices array. Either `xy` pairs, or `xyz` if the `containsZ` parameter is `true` (but see note).
7779
* @param {number[]} [uvs] - The UVs pairs array.
7880
* @param {number[]} [indicies] - Optional vertex indicies array. If you don't have one, pass `null` or an empty array.
79-
* @param {boolean} [containsZ=false] - Does the vertices data include a `z` component?
81+
* @param {boolean} [containsZ=false] - Does the vertices data include a `z` component? Note: If not, it will be assumed `z=0`, see method `panZ` or `setOrtho`.
8082
* @param {number[]} [normals] - Optional vertex normals array. If you don't have one, pass `null` or an empty array.
8183
* @param {number|number[]} [colors=0xffffff] - An array of colors, one per vertex, or a single color value applied to all vertices.
8284
* @param {number|number[]} [alphas=1] - An array of alpha values, one per vertex, or a single alpha value applied to all vertices.
@@ -350,7 +352,7 @@ var Mesh = new Class({
350352
this.setSize(renderer.width, renderer.height);
351353
this.initPipeline();
352354

353-
this.setPerspective(renderer.width, renderer.height, 45, 0.01, 1000);
355+
this.setPerspective(renderer.width, renderer.height);
354356

355357
if (vertices)
356358
{
@@ -407,6 +409,9 @@ var Mesh = new Class({
407409
/**
408410
* Translates the view position of this Mesh on the z axis by the given amount.
409411
*
412+
* As the default `panZ` value is 0, vertices with `z=0` (the default) need special care or else they will not display as they are behind the camera.
413+
* Consider using `mesh.panZ(mesh.height / (2 * Math.tan(Math.PI / 16)))`, which will interpret vertex geometry 1:1 with pixel geometry (or see `setOrtho`).
414+
*
410415
* @method Phaser.GameObjects.Mesh#panZ
411416
* @since 3.50.0
412417
*
@@ -424,6 +429,8 @@ var Mesh = new Class({
424429
/**
425430
* Builds a new perspective projection matrix from the given values.
426431
*
432+
* These are also the initial projection matrix & parameters for `Mesh` (and see `panZ` for more discussion).
433+
*
427434
* See also `setOrtho`.
428435
*
429436
* @method Phaser.GameObjects.Mesh#setPerspective
@@ -455,7 +462,8 @@ var Mesh = new Class({
455462
* If using this mode you will often need to set `Mesh.hideCCW` to `false` as well.
456463
*
457464
* By default, calling this method with no parameters will set the scaleX value to
458-
* match the renderers aspect ratio.
465+
* match the renderer's aspect ratio. If you would like to render vertex positions 1:1
466+
* to pixel positions, consider calling as `mesh.setOrtho(mesh.width, mesh.height)`.
459467
*
460468
* See also `setPerspective`.
461469
*
@@ -642,7 +650,7 @@ var Mesh = new Class({
642650
*
643651
* This method will take vertex data in one of two formats, based on the `containsZ` parameter.
644652
*
645-
* If your vertex data are `x`, `y` pairs, then `containsZ` should be `false` (this is the default)
653+
* If your vertex data are `x`, `y` pairs, then `containsZ` should be `false` (this is the default, and will result in `z=0` for each vertex).
646654
*
647655
* If your vertex data is groups of `x`, `y` and `z` values, then the `containsZ` parameter must be true.
648656
*
@@ -661,6 +669,7 @@ var Mesh = new Class({
661669
* The following example will create a 256 x 256 sized quad using an index array:
662670
*
663671
* ```javascript
672+
* let mesh = new Mesh(this); // Assuming `this` is a scene!
664673
* const vertices = [
665674
* -128, 128,
666675
* 128, 128,
@@ -678,6 +687,9 @@ var Mesh = new Class({
678687
* const indices = [ 0, 2, 1, 2, 3, 1 ];
679688
*
680689
* mesh.addVertices(vertices, uvs, indicies);
690+
* // Note: Otherwise the added points will be "behind" the camera! This value will project vertex `x` & `y` values 1:1 to pixel values.
691+
* mesh.hideCCW = false;
692+
* mesh.setOrtho(mesh.width, mesh.height);
681693
* ```
682694
*
683695
* If the data is not indexed, it's assumed that the arrays all contain sequential data.
@@ -688,7 +700,7 @@ var Mesh = new Class({
688700
* @param {number[]} vertices - The vertices array. Either `xy` pairs, or `xyz` if the `containsZ` parameter is `true`.
689701
* @param {number[]} uvs - The UVs pairs array.
690702
* @param {number[]} [indicies] - Optional vertex indicies array. If you don't have one, pass `null` or an empty array.
691-
* @param {boolean} [containsZ=false] - Does the vertices data include a `z` component?
703+
* @param {boolean} [containsZ=false] - Does the vertices data include a `z` component? If not, it will be assumed `z=0`, see methods `panZ` or `setOrtho`.
692704
* @param {number[]} [normals] - Optional vertex normals array. If you don't have one, pass `null` or an empty array.
693705
* @param {number|number[]} [colors=0xffffff] - An array of colors, one per vertex, or a single color value applied to all vertices.
694706
* @param {number|number[]} [alphas=1] - An array of alpha values, one per vertex, or a single alpha value applied to all vertices.

0 commit comments

Comments
 (0)