diff --git a/src/game-lib-d3-texture.js b/src/game-lib-d3-texture.js index 6561ecd..a173e67 100644 --- a/src/game-lib-d3-texture.js +++ b/src/game-lib-d3-texture.js @@ -271,7 +271,7 @@ GameLib.D3.Texture.prototype.createInstance = function() { /** * Updates the instance with the current state */ -GameLib.D3.Texture.prototype.updateInstance = function() { +GameLib.D3.Texture.prototype.updateInstance = function(property) { if (GameLib.Utils.UndefinedOrNull(this.instance)) { try { @@ -282,81 +282,106 @@ GameLib.D3.Texture.prototype.updateInstance = function() { } } - var imageChanged = false; - - if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_NORMAL) { - - if ( - GameLib.Utils.UndefinedOrNull(this.image) && - this.instance.image - ) { - try { - this.createInstance(); - imageChanged = true; - } catch (error) { - console.error(error); - } - } - - if (this.image && this.image.instance && this.instance.image !== this.image.instance) { - try { - this.createInstance(); - imageChanged = true; - } catch (error) { - console.error(error); - } - } - - } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CANVAS) { - - if ( - GameLib.Utils.UndefinedOrNull(this.canvas) && - this.instance.canvas - ) { - try { - this.createInstance(); - imageChanged = true; - } catch (error) { - console.error(error); - } - } - - if (this.canvas && this.canvas.instance && this.instance.image !== this.canvas.instance) { - try { - this.createInstance(); - imageChanged = true; - } catch (error) { - console.error(error); - } - } - - } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CUBE) { - - console.log('todo : cube images change check here'); - + if (GameLib.Utils.UndefinedOrNull(property)) { + //throw new Error('need to specify a property'); } - this.instance.name = this.name; - this.instance.flipY = this.flipY; - this.instance.encoding = this.encoding; - this.instance.offset.x = this.offset.x; - this.instance.offset.y = this.offset.y; - this.instance.repeat.x = this.repeat.x; - this.instance.repeat.y = this.repeat.y; - this.instance.mapping = this.mapping; - this.instance.format = this.format; - this.instance.wrapS = this.wrapS; - this.instance.wrapT = this.wrapT; + if (property === 'image') { - this.instance.needsUpdate = true; + if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_NORMAL) { - if (imageChanged) { - this.publish( - GameLib.Event.IMAGE_CHANGED, - { - texture : this - } - ) + if ( + GameLib.Utils.UndefinedOrNull(this.image) && + this.instance.image + ) { + try { + this.createInstance(); + } catch (error) { + console.error(error); + } + } + + if (this.image && this.image.instance && this.instance.image !== this.image.instance) { + try { + this.createInstance(); + } catch (error) { + console.error(error); + } + } + + } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CANVAS) { + + if ( + GameLib.Utils.UndefinedOrNull(this.canvas) && + this.instance.canvas + ) { + try { + this.createInstance(); + } catch (error) { + console.error(error); + } + } + + if (this.canvas && this.canvas.instance && this.instance.image !== this.canvas.instance) { + try { + this.createInstance(); + } catch (error) { + console.error(error); + } + } + + } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CUBE) { + + console.log('todo : cube images change check here'); + + } + + this.publish( + GameLib.Event.IMAGE_CHANGED, + { + texture : this + } + ); + + this.instance.needsUpdate = true; + } + + if (property === 'name') { + this.instance.name = this.name; + } + + if (property === 'flipY') { + this.instance.flipY = this.flipY; + } + + if (property === 'encoding') { + this.instance.encoding = this.encoding; + } + + if (property === 'offset') { + this.instance.offset.x = this.offset.x; + this.instance.offset.y = this.offset.y; + } + + if (property === 'repeat') { + this.instance.repeat.x = this.repeat.x; + this.instance.repeat.y = this.repeat.y; + } + + if (property === 'mapping') { + this.instance.mapping = this.mapping; + } + + if (property === 'format') { + this.instance.format = this.format; + } + + if (property === 'wrapS') { + this.instance.wrapS = this.wrapS; + } + + if (property === 'wrapT') { + this.instance.wrapT = this.wrapT; } }; diff --git a/src/game-lib-system-linking.js b/src/game-lib-system-linking.js index 2a0d235..a3d7ebe 100644 --- a/src/game-lib-system-linking.js +++ b/src/game-lib-system-linking.js @@ -583,7 +583,7 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) { /** * Ok - this image is in use - this should notify materials when its image changes */ - texture.updateInstance(); + texture.updateInstance('image'); } } );