diff --git a/packages/core/src/textures/TextureMatrix.js b/packages/core/src/textures/TextureMatrix.js index d3fd369..ade6b94 100644 --- a/packages/core/src/textures/TextureMatrix.js +++ b/packages/core/src/textures/TextureMatrix.js @@ -84,7 +84,7 @@ set texture(value) // eslint-disable-line require-jsdoc { this._texture = value; - this._lastTextureID = -1; + this._updateID = -1; } /** diff --git a/packages/core/src/textures/TextureMatrix.js b/packages/core/src/textures/TextureMatrix.js index d3fd369..ade6b94 100644 --- a/packages/core/src/textures/TextureMatrix.js +++ b/packages/core/src/textures/TextureMatrix.js @@ -84,7 +84,7 @@ set texture(value) // eslint-disable-line require-jsdoc { this._texture = value; - this._lastTextureID = -1; + this._updateID = -1; } /** diff --git a/packages/mesh-extras/src/NineSlicePlane.js b/packages/mesh-extras/src/NineSlicePlane.js index e5a4086..e5adf73 100644 --- a/packages/mesh-extras/src/NineSlicePlane.js +++ b/packages/mesh-extras/src/NineSlicePlane.js @@ -1,3 +1,4 @@ +import { Texture } from '@pixi/core'; import SimplePlane from './SimplePlane'; const DEFAULT_BORDER_SIZE = 10; @@ -44,7 +45,7 @@ */ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { - super(texture, 4, 4); + super(Texture.WHITE, 4, 4); this._origWidth = texture.orig.width; this._origHeight = texture.orig.height; @@ -102,10 +103,14 @@ * @override */ this._bottomHeight = typeof bottomHeight !== 'undefined' ? bottomHeight : DEFAULT_BORDER_SIZE; + + // lets call the setter to ensure all necessary updates are performed + this.texture = texture; } textureUpdated() { + this._textureID = this.shader.texture._updateID; this._refresh(); } diff --git a/packages/core/src/textures/TextureMatrix.js b/packages/core/src/textures/TextureMatrix.js index d3fd369..ade6b94 100644 --- a/packages/core/src/textures/TextureMatrix.js +++ b/packages/core/src/textures/TextureMatrix.js @@ -84,7 +84,7 @@ set texture(value) // eslint-disable-line require-jsdoc { this._texture = value; - this._lastTextureID = -1; + this._updateID = -1; } /** diff --git a/packages/mesh-extras/src/NineSlicePlane.js b/packages/mesh-extras/src/NineSlicePlane.js index e5a4086..e5adf73 100644 --- a/packages/mesh-extras/src/NineSlicePlane.js +++ b/packages/mesh-extras/src/NineSlicePlane.js @@ -1,3 +1,4 @@ +import { Texture } from '@pixi/core'; import SimplePlane from './SimplePlane'; const DEFAULT_BORDER_SIZE = 10; @@ -44,7 +45,7 @@ */ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { - super(texture, 4, 4); + super(Texture.WHITE, 4, 4); this._origWidth = texture.orig.width; this._origHeight = texture.orig.height; @@ -102,10 +103,14 @@ * @override */ this._bottomHeight = typeof bottomHeight !== 'undefined' ? bottomHeight : DEFAULT_BORDER_SIZE; + + // lets call the setter to ensure all necessary updates are performed + this.texture = texture; } textureUpdated() { + this._textureID = this.shader.texture._updateID; this._refresh(); } diff --git a/packages/mesh-extras/src/SimpleMesh.js b/packages/mesh-extras/src/SimpleMesh.js index 283ddef..1c78a39 100644 --- a/packages/mesh-extras/src/SimpleMesh.js +++ b/packages/mesh-extras/src/SimpleMesh.js @@ -28,6 +28,10 @@ super(geometry, meshMaterial, null, drawMode); + /** + * upload vertices buffer each frame + * @member {boolean} + */ this.autoUpdate = true; } diff --git a/packages/core/src/textures/TextureMatrix.js b/packages/core/src/textures/TextureMatrix.js index d3fd369..ade6b94 100644 --- a/packages/core/src/textures/TextureMatrix.js +++ b/packages/core/src/textures/TextureMatrix.js @@ -84,7 +84,7 @@ set texture(value) // eslint-disable-line require-jsdoc { this._texture = value; - this._lastTextureID = -1; + this._updateID = -1; } /** diff --git a/packages/mesh-extras/src/NineSlicePlane.js b/packages/mesh-extras/src/NineSlicePlane.js index e5a4086..e5adf73 100644 --- a/packages/mesh-extras/src/NineSlicePlane.js +++ b/packages/mesh-extras/src/NineSlicePlane.js @@ -1,3 +1,4 @@ +import { Texture } from '@pixi/core'; import SimplePlane from './SimplePlane'; const DEFAULT_BORDER_SIZE = 10; @@ -44,7 +45,7 @@ */ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { - super(texture, 4, 4); + super(Texture.WHITE, 4, 4); this._origWidth = texture.orig.width; this._origHeight = texture.orig.height; @@ -102,10 +103,14 @@ * @override */ this._bottomHeight = typeof bottomHeight !== 'undefined' ? bottomHeight : DEFAULT_BORDER_SIZE; + + // lets call the setter to ensure all necessary updates are performed + this.texture = texture; } textureUpdated() { + this._textureID = this.shader.texture._updateID; this._refresh(); } diff --git a/packages/mesh-extras/src/SimpleMesh.js b/packages/mesh-extras/src/SimpleMesh.js index 283ddef..1c78a39 100644 --- a/packages/mesh-extras/src/SimpleMesh.js +++ b/packages/mesh-extras/src/SimpleMesh.js @@ -28,6 +28,10 @@ super(geometry, meshMaterial, null, drawMode); + /** + * upload vertices buffer each frame + * @member {boolean} + */ this.autoUpdate = true; } diff --git a/packages/mesh-extras/src/SimplePlane.js b/packages/mesh-extras/src/SimplePlane.js index be35b50..1e2eab8 100644 --- a/packages/mesh-extras/src/SimplePlane.js +++ b/packages/mesh-extras/src/SimplePlane.js @@ -1,3 +1,4 @@ +import { Texture } from '@pixi/core'; import { Mesh, MeshMaterial } from '@pixi/mesh'; import PlaneGeometry from './geometry/PlaneGeometry'; @@ -26,22 +27,64 @@ constructor(texture, verticesX, verticesY) { const planeGeometry = new PlaneGeometry(texture.width, texture.height, verticesX, verticesY); - const meshMaterial = new MeshMaterial(texture); + const meshMaterial = new MeshMaterial(Texture.WHITE); super(planeGeometry, meshMaterial); - // wait for the texture to load - if (!texture.baseTexture.valid) - { - texture.once('update', this.textureUpdated, this); - } + // lets call the setter to ensure all necessary updates are performed + this.texture = texture; } + /** + * Method used for overrides, to do something in case texture frame was changed. + * Meshes based on plane can override it and change more details based on texture. + */ textureUpdated() { + this._textureID = this.shader.texture._updateID; + this.geometry.width = this.shader.texture.width; this.geometry.height = this.shader.texture.height; this.geometry.build(); } + + set texture(value) + { + // Track texture same way sprite does. + // For generated meshes like NineSlicePlane it can change the geometry. + // Unfortunately, this method might not work if you directly change texture in material. + + if (this.shader.texture === value) + { + return; + } + + this.shader.texture = value; + this._textureID = -1; + + if (value.baseTexture.valid) + { + this.textureUpdated(); + } + else + { + value.once('update', this.textureUpdated, this); + } + } + + get texture() + { + return this.shader.texture; + } + + _render(renderer) + { + if (this._textureID !== this.shader.texture._updateID) + { + this.textureUpdated(); + } + + super._render(renderer); + } }