96 lines
2.1 KiB
JavaScript
96 lines
2.1 KiB
JavaScript
/**
|
|
* GameLib.D3.Texture.Canvas
|
|
* @param graphics
|
|
* @param apiTextureCanvas
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.Texture.Canvas = function(
|
|
graphics,
|
|
apiTextureCanvas
|
|
) {
|
|
this.graphics = graphics;
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiTextureCanvas)) {
|
|
apiTextureCanvas = {
|
|
textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS
|
|
};
|
|
}
|
|
|
|
GameLib.D3.API.Texture.Canvas.call(
|
|
this,
|
|
apiTextureCanvas,
|
|
apiTextureCanvas.canvas
|
|
);
|
|
|
|
if (this.canvas instanceof GameLib.API.Canvas) {
|
|
this.canvas = new GameLib.Canvas(
|
|
this.canvas
|
|
);
|
|
}
|
|
|
|
GameLib.D3.Texture.call(
|
|
this,
|
|
this.graphics,
|
|
this
|
|
);
|
|
|
|
};
|
|
|
|
GameLib.D3.Texture.Canvas.prototype = Object.create(GameLib.D3.Texture.prototype);
|
|
GameLib.D3.Texture.Canvas.prototype.constructor = GameLib.D3.Texture.Canvas;
|
|
|
|
/**
|
|
* Creates an instance of our texture object
|
|
* @returns {*}
|
|
*/
|
|
GameLib.D3.Texture.Canvas.prototype.createInstance = function() {
|
|
|
|
if (
|
|
GameLib.Utils.UndefinedOrNull(this.canvas) ||
|
|
GameLib.Utils.UndefinedOrNull(this.canvas.instance)
|
|
) {
|
|
console.warn('canvas not ready at time of texture create instance');
|
|
return;
|
|
}
|
|
|
|
this.canvas.parentTexture = this;
|
|
|
|
this.instance = new THREE.Texture(
|
|
this.canvas.instance
|
|
);
|
|
|
|
GameLib.D3.Texture.prototype.createInstance.call(this);
|
|
};
|
|
|
|
/**
|
|
* Updates the instance with the current state
|
|
*/
|
|
GameLib.D3.Texture.Canvas.prototype.updateInstance = function(property) {
|
|
|
|
if (property === 'canvas') {
|
|
|
|
this.createInstance();
|
|
|
|
return;
|
|
}
|
|
|
|
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
|
|
};
|
|
|
|
/**
|
|
* Converts a GameLib.D3.Texture.Canvas to a GameLib.D3.API.Texture.Canvas
|
|
* @returns {GameLib.D3.API.Texture.Canvas}
|
|
*/
|
|
GameLib.D3.Texture.Canvas.prototype.toApiObject = function() {
|
|
|
|
var apiTexture = GameLib.D3.Texture.prototype.toApiObject.call(this);
|
|
|
|
var apiTextureCanvas = new GameLib.D3.API.Texture.Canvas(
|
|
apiTexture,
|
|
GameLib.Utils.IdOrNull(this.canvas)
|
|
);
|
|
|
|
return apiTextureCanvas;
|
|
};
|