77 lines
1.6 KiB
JavaScript
77 lines
1.6 KiB
JavaScript
/**
|
|
* Graphics
|
|
* @param id
|
|
* @param name
|
|
* @param graphicsType
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.Graphics = function Graphics(
|
|
id,
|
|
name,
|
|
graphicsType
|
|
) {
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
id = GameLib.Utils.RandomId();
|
|
}
|
|
this.id = id;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
name = 'Graphics (' + id + ')';
|
|
}
|
|
this.name = name;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(graphicsType)) {
|
|
graphicsType = GameLib.D3.Graphics.GRAPHICS_TYPE_THREE;
|
|
}
|
|
this.graphicsType = graphicsType;
|
|
|
|
this.instance = this.createInstance();
|
|
};
|
|
|
|
/**
|
|
* GameLib.D3.Graphics Types
|
|
* @type {number}
|
|
*/
|
|
GameLib.D3.Graphics.GRAPHICS_TYPE_THREE = 0x1;
|
|
|
|
/**
|
|
* @returns {THREE.Graphics}
|
|
*/
|
|
GameLib.D3.Graphics.prototype.createInstance = function(update) {
|
|
|
|
var instance = null;
|
|
|
|
if (update) {
|
|
instance = this.instance;
|
|
} else {
|
|
instance = THREE;
|
|
}
|
|
|
|
return instance;
|
|
};
|
|
|
|
/**
|
|
* Updates the instance with the current state
|
|
*/
|
|
GameLib.D3.Graphics.prototype.updateInstance = function() {
|
|
this.instance = this.createInstance(true);
|
|
};
|
|
|
|
/**
|
|
* True if THREE physics
|
|
* @returns {boolean}
|
|
*/
|
|
GameLib.D3.Graphics.prototype.isThree = function() {
|
|
return (this.graphicsType == GameLib.D3.Graphics.GRAPHICS_TYPE_THREE)
|
|
};
|
|
|
|
/**
|
|
* Logs a warning and throws an error if not cannon
|
|
*/
|
|
GameLib.D3.Graphics.prototype.isNotThreeThrow = function() {
|
|
if (this.graphicsType != GameLib.D3.Graphics.GRAPHICS_TYPE_THREE) {
|
|
console.warn('Only THREE supported for this function');
|
|
throw new Error('Only THREE supported for this function');
|
|
}
|
|
};
|