From 020cfab2d692510c8c366d31654d6cd102dad94f Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 15 Oct 2020 09:58:54 +0100 Subject: [PATCH] Fixed issue with no mesh specified and texture getting --- src/geom/mesh/GenerateGridVerts.js | 22 ++++++++++++++++---- src/geom/mesh/typedefs/GenerateGridConfig.js | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/geom/mesh/GenerateGridVerts.js b/src/geom/mesh/GenerateGridVerts.js index 7ab0beb35..1f20c76d5 100644 --- a/src/geom/mesh/GenerateGridVerts.js +++ b/src/geom/mesh/GenerateGridVerts.js @@ -46,7 +46,7 @@ var tempMatrix = new Matrix4(); var GenerateGridVerts = function (config) { var mesh = GetFastValue(config, 'mesh'); - var texture = GetFastValue(config, 'texture', (mesh) ? mesh.texture : null); + var texture = GetFastValue(config, 'texture', null); var frame = GetFastValue(config, 'frame'); var width = GetFastValue(config, 'width', 1); var height = GetFastValue(config, 'height', width); @@ -59,7 +59,7 @@ var GenerateGridVerts = function (config) var rotateY = GetFastValue(config, 'rotateY', 0); var rotateZ = GetFastValue(config, 'rotateZ', 0); var zIsUp = GetFastValue(config, 'zIsUp', true); - var isOrtho = GetFastValue(config, 'isOrtho', mesh.dirtyCache[11]); + var isOrtho = GetFastValue(config, 'isOrtho', (mesh) ? mesh.dirtyCache[11] : false); var colors = GetFastValue(config, 'colors', [ 0xffffff ]); var alphas = GetFastValue(config, 'alphas', [ 1 ]); var tile = GetFastValue(config, 'tile', false); @@ -75,11 +75,25 @@ var GenerateGridVerts = function (config) tempRotation.set(rotateX, rotateY, rotateZ); tempMatrix.fromRotationXYTranslation(tempRotation, tempPosition, zIsUp); + if (!texture && mesh) + { + texture = mesh.texture; + } + else if (mesh && typeof(texture) === 'string') + { + texture = mesh.scene.sys.textures.get(texture); + } + else + { + // There's nothing more we can do without a texture + return result; + } + + var textureFrame = texture.get(frame); + // If the Mesh is ortho and no width/height is given, we'll default to texture sizes (if set!) if (!widthSet && isOrtho && texture) { - var textureFrame = texture.get(frame); - var renderer = mesh.scene.sys.renderer; width = textureFrame.width / renderer.height; diff --git a/src/geom/mesh/typedefs/GenerateGridConfig.js b/src/geom/mesh/typedefs/GenerateGridConfig.js index fef885dfb..e53862099 100644 --- a/src/geom/mesh/typedefs/GenerateGridConfig.js +++ b/src/geom/mesh/typedefs/GenerateGridConfig.js @@ -2,7 +2,7 @@ * @typedef {object} Phaser.Types.Geom.Mesh.GenerateGridConfig * @since 3.50.0 * - * @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. + * @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. * @property {(string|integer)} [frame] - The name or index of the frame within the Texture. * @property {Phaser.GameObjects.Mesh} [mesh] - If specified, the vertices of the generated grid will be added to this Mesh Game Object. * @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.