Skip to content

Commit 020cfab

Browse files
committed
Fixed issue with no mesh specified and texture getting
1 parent 1e01f74 commit 020cfab

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/geom/mesh/GenerateGridVerts.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var tempMatrix = new Matrix4();
4646
var GenerateGridVerts = function (config)
4747
{
4848
var mesh = GetFastValue(config, 'mesh');
49-
var texture = GetFastValue(config, 'texture', (mesh) ? mesh.texture : null);
49+
var texture = GetFastValue(config, 'texture', null);
5050
var frame = GetFastValue(config, 'frame');
5151
var width = GetFastValue(config, 'width', 1);
5252
var height = GetFastValue(config, 'height', width);
@@ -59,7 +59,7 @@ var GenerateGridVerts = function (config)
5959
var rotateY = GetFastValue(config, 'rotateY', 0);
6060
var rotateZ = GetFastValue(config, 'rotateZ', 0);
6161
var zIsUp = GetFastValue(config, 'zIsUp', true);
62-
var isOrtho = GetFastValue(config, 'isOrtho', mesh.dirtyCache[11]);
62+
var isOrtho = GetFastValue(config, 'isOrtho', (mesh) ? mesh.dirtyCache[11] : false);
6363
var colors = GetFastValue(config, 'colors', [ 0xffffff ]);
6464
var alphas = GetFastValue(config, 'alphas', [ 1 ]);
6565
var tile = GetFastValue(config, 'tile', false);
@@ -75,11 +75,25 @@ var GenerateGridVerts = function (config)
7575
tempRotation.set(rotateX, rotateY, rotateZ);
7676
tempMatrix.fromRotationXYTranslation(tempRotation, tempPosition, zIsUp);
7777

78+
if (!texture && mesh)
79+
{
80+
texture = mesh.texture;
81+
}
82+
else if (mesh && typeof(texture) === 'string')
83+
{
84+
texture = mesh.scene.sys.textures.get(texture);
85+
}
86+
else
87+
{
88+
// There's nothing more we can do without a texture
89+
return result;
90+
}
91+
92+
var textureFrame = texture.get(frame);
93+
7894
// If the Mesh is ortho and no width/height is given, we'll default to texture sizes (if set!)
7995
if (!widthSet && isOrtho && texture)
8096
{
81-
var textureFrame = texture.get(frame);
82-
8397
var renderer = mesh.scene.sys.renderer;
8498

8599
width = textureFrame.width / renderer.height;

src/geom/mesh/typedefs/GenerateGridConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @typedef {object} Phaser.Types.Geom.Mesh.GenerateGridConfig
33
* @since 3.50.0
44
*
5-
* @property {(string|Phaser.Textures.Texture)} key - The key of the texture to be used for this Grid, as stored in the Texture Manager, or a Texture instance.
5+
* @property {(string|Phaser.Textures.Texture)} texture - The texture to be used for this Grid. Must be a Texture instance. Can also be a string but only if the `mesh` property is set.
66
* @property {(string|integer)} [frame] - The name or index of the frame within the Texture.
77
* @property {Phaser.GameObjects.Mesh} [mesh] - If specified, the vertices of the generated grid will be added to this Mesh Game Object.
88
* @property {number} [width=1] - The width of the grid in 3D units. If you wish to get a pixel accurate grid based on a texture, you can use an Ortho Mesh or the `isOrtho` parameter.

0 commit comments

Comments
 (0)