diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index f85df10..3869a39 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -63,17 +63,24 @@ for (let i = 0; i < total; i++) { - const x = (i % this.verticesX); - const y = ((i / this.verticesX) | 0); + if (texture._uvs) + { + const x = (i % this.verticesX); + const y = ((i / this.verticesX) | 0); - verts.push((x * sizeX), - (y * sizeY)); + verts.push((x * sizeX), + (y * sizeY)); - // this works for rectangular textures. - uvs.push( - texture._uvs.x0 + ((texture._uvs.x1 - texture._uvs.x0) * (x / (this.verticesX - 1))), - texture._uvs.y0 + ((texture._uvs.y3 - texture._uvs.y0) * (y / (this.verticesY - 1))) - ); + // this works for rectangular textures. + uvs.push( + texture._uvs.x0 + ((texture._uvs.x1 - texture._uvs.x0) * (x / (this.verticesX - 1))), + texture._uvs.y0 + ((texture._uvs.y3 - texture._uvs.y0) * (y / (this.verticesY - 1))) + ); + } + else + { + uvs.push(0); + } } // cons diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index f85df10..3869a39 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -63,17 +63,24 @@ for (let i = 0; i < total; i++) { - const x = (i % this.verticesX); - const y = ((i / this.verticesX) | 0); + if (texture._uvs) + { + const x = (i % this.verticesX); + const y = ((i / this.verticesX) | 0); - verts.push((x * sizeX), - (y * sizeY)); + verts.push((x * sizeX), + (y * sizeY)); - // this works for rectangular textures. - uvs.push( - texture._uvs.x0 + ((texture._uvs.x1 - texture._uvs.x0) * (x / (this.verticesX - 1))), - texture._uvs.y0 + ((texture._uvs.y3 - texture._uvs.y0) * (y / (this.verticesY - 1))) - ); + // this works for rectangular textures. + uvs.push( + texture._uvs.x0 + ((texture._uvs.x1 - texture._uvs.x0) * (x / (this.verticesX - 1))), + texture._uvs.y0 + ((texture._uvs.y3 - texture._uvs.y0) * (y / (this.verticesY - 1))) + ); + } + else + { + uvs.push(0); + } } // cons diff --git a/test/core/Plane.js b/test/core/Plane.js new file mode 100644 index 0000000..ab2f460 --- /dev/null +++ b/test/core/Plane.js @@ -0,0 +1,25 @@ +'use strict'; + +describe('PIXI.mesh.Plane', function () +{ + it('should create a plane from an external image', function (done) + { + PIXI.loader.add('testBitmap', `file://${__dirname}/../renders/tests/assets/bitmap-1.png`) + .load(function (loader, resources) + { + const plane = new PIXI.mesh.Plane(resources.testBitmap.texture, 100, 100); + + expect(plane.verticesX).to.equal(100); + expect(plane.verticesY).to.equal(100); + done(); + }); + }); + + it('should create a new empty textured Plane', function () + { + const plane = new PIXI.mesh.Plane(PIXI.Texture.EMPTY, 100, 100); + + expect(plane.verticesX).to.equal(100); + expect(plane.verticesY).to.equal(100); + }); +}); diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index f85df10..3869a39 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -63,17 +63,24 @@ for (let i = 0; i < total; i++) { - const x = (i % this.verticesX); - const y = ((i / this.verticesX) | 0); + if (texture._uvs) + { + const x = (i % this.verticesX); + const y = ((i / this.verticesX) | 0); - verts.push((x * sizeX), - (y * sizeY)); + verts.push((x * sizeX), + (y * sizeY)); - // this works for rectangular textures. - uvs.push( - texture._uvs.x0 + ((texture._uvs.x1 - texture._uvs.x0) * (x / (this.verticesX - 1))), - texture._uvs.y0 + ((texture._uvs.y3 - texture._uvs.y0) * (y / (this.verticesY - 1))) - ); + // this works for rectangular textures. + uvs.push( + texture._uvs.x0 + ((texture._uvs.x1 - texture._uvs.x0) * (x / (this.verticesX - 1))), + texture._uvs.y0 + ((texture._uvs.y3 - texture._uvs.y0) * (y / (this.verticesY - 1))) + ); + } + else + { + uvs.push(0); + } } // cons diff --git a/test/core/Plane.js b/test/core/Plane.js new file mode 100644 index 0000000..ab2f460 --- /dev/null +++ b/test/core/Plane.js @@ -0,0 +1,25 @@ +'use strict'; + +describe('PIXI.mesh.Plane', function () +{ + it('should create a plane from an external image', function (done) + { + PIXI.loader.add('testBitmap', `file://${__dirname}/../renders/tests/assets/bitmap-1.png`) + .load(function (loader, resources) + { + const plane = new PIXI.mesh.Plane(resources.testBitmap.texture, 100, 100); + + expect(plane.verticesX).to.equal(100); + expect(plane.verticesY).to.equal(100); + done(); + }); + }); + + it('should create a new empty textured Plane', function () + { + const plane = new PIXI.mesh.Plane(PIXI.Texture.EMPTY, 100, 100); + + expect(plane.verticesX).to.equal(100); + expect(plane.verticesY).to.equal(100); + }); +}); diff --git a/test/core/index.js b/test/core/index.js index ae67d59..22ee185 100755 --- a/test/core/index.js +++ b/test/core/index.js @@ -11,6 +11,7 @@ require('./toLocal'); require('./getGlobalPosition'); require('./util'); +require('./Plane'); require('./Point'); require('./ObservablePoint'); require('./Matrix');