You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/gameobjects/mesh/Mesh.js
+21-9Lines changed: 21 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -28,9 +28,11 @@ var Vertex = require('../../geom/mesh/Vertex');
28
28
* Support for generating mesh data from grids, model data or Wavefront OBJ Files is included.
29
29
*
30
30
* 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.
34
36
*
35
37
* The rendering process will iterate through the faces of this Mesh and render out each face
36
38
* 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');
73
75
* @param {number} [y] - The vertical position of this Game Object in the world.
74
76
* @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.
75
77
* @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).
77
79
* @param {number[]} [uvs] - The UVs pairs array.
78
80
* @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`.
80
82
* @param {number[]} [normals] - Optional vertex normals array. If you don't have one, pass `null` or an empty array.
81
83
* @param {number|number[]} [colors=0xffffff] - An array of colors, one per vertex, or a single color value applied to all vertices.
82
84
* @param {number|number[]} [alphas=1] - An array of alpha values, one per vertex, or a single alpha value applied to all vertices.
* Translates the view position of this Mesh on the z axis by the given amount.
409
411
*
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
+
*
410
415
* @method Phaser.GameObjects.Mesh#panZ
411
416
* @since 3.50.0
412
417
*
@@ -424,6 +429,8 @@ var Mesh = new Class({
424
429
/**
425
430
* Builds a new perspective projection matrix from the given values.
426
431
*
432
+
* These are also the initial projection matrix & parameters for `Mesh` (and see `panZ` for more discussion).
433
+
*
427
434
* See also `setOrtho`.
428
435
*
429
436
* @method Phaser.GameObjects.Mesh#setPerspective
@@ -455,7 +462,8 @@ var Mesh = new Class({
455
462
* If using this mode you will often need to set `Mesh.hideCCW` to `false` as well.
456
463
*
457
464
* 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)`.
459
467
*
460
468
* See also `setPerspective`.
461
469
*
@@ -642,7 +650,7 @@ var Mesh = new Class({
642
650
*
643
651
* This method will take vertex data in one of two formats, based on the `containsZ` parameter.
644
652
*
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).
646
654
*
647
655
* If your vertex data is groups of `x`, `y` and `z` values, then the `containsZ` parameter must be true.
648
656
*
@@ -661,6 +669,7 @@ var Mesh = new Class({
661
669
* The following example will create a 256 x 256 sized quad using an index array:
662
670
*
663
671
* ```javascript
672
+
* let mesh = new Mesh(this); // Assuming `this` is a scene!
664
673
* const vertices = [
665
674
* -128, 128,
666
675
* 128, 128,
@@ -678,6 +687,9 @@ var Mesh = new Class({
678
687
* const indices = [ 0, 2, 1, 2, 3, 1 ];
679
688
*
680
689
* 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);
681
693
* ```
682
694
*
683
695
* If the data is not indexed, it's assumed that the arrays all contain sequential data.
@@ -688,7 +700,7 @@ var Mesh = new Class({
688
700
* @param {number[]} vertices - The vertices array. Either `xy` pairs, or `xyz` if the `containsZ` parameter is `true`.
689
701
* @param {number[]} uvs - The UVs pairs array.
690
702
* @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`.
692
704
* @param {number[]} [normals] - Optional vertex normals array. If you don't have one, pass `null` or an empty array.
693
705
* @param {number|number[]} [colors=0xffffff] - An array of colors, one per vertex, or a single color value applied to all vertices.
694
706
* @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