From 7b963ce0852259f7a94be36f2fa2f2b55c7da3ff Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Fri, 27 Oct 2017 10:08:16 +0200 Subject: [PATCH] canvas check for textures --- src/game-lib-d3-texture.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/game-lib-d3-texture.js b/src/game-lib-d3-texture.js index 3278c6c..25267df 100644 --- a/src/game-lib-d3-texture.js +++ b/src/game-lib-d3-texture.js @@ -203,15 +203,18 @@ GameLib.D3.Texture.prototype.createInstance = function() { } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_NORMAL) { - if (GameLib.Utils.UndefinedOrNull(this.image)) { + if ( + GameLib.Utils.UndefinedOrNull(this.image) || + GameLib.Utils.UndefinedOrNull(this.image.instance) + ) { this.instance = new THREE.Texture(); } else { - if (GameLib.Utils.UndefinedOrNull(this.image.instance)) { - throw new Error('no image instance'); - } + //if (GameLib.Utils.UndefinedOrNull(this.image.instance)) { + // throw new Error('no image instance'); + //} this.instance = new THREE.Texture( this.image.instance @@ -304,7 +307,26 @@ GameLib.D3.Texture.prototype.updateInstance = function() { } else if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CANVAS) { - console.log('todo : canvas change check here'); + 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) {