2016-10-25 17:57:32 +02:00
|
|
|
/**
|
|
|
|
* Graphics Superset
|
2017-01-12 17:40:17 +01:00
|
|
|
* @param apiGraphics
|
2016-10-25 17:57:32 +02:00
|
|
|
* @constructor
|
|
|
|
*/
|
2016-11-21 16:08:39 +01:00
|
|
|
GameLib.D3.Graphics = function Graphics(
|
2017-01-12 17:40:17 +01:00
|
|
|
apiGraphics
|
2016-10-25 17:57:32 +02:00
|
|
|
) {
|
2017-01-12 17:40:17 +01:00
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiGraphics)) {
|
|
|
|
apiGraphics = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
GameLib.D3.API.Graphics.call(
|
|
|
|
this,
|
|
|
|
apiGraphics.id,
|
|
|
|
apiGraphics.name,
|
|
|
|
apiGraphics.graphicsType,
|
|
|
|
apiGraphics.parentEntity
|
|
|
|
);
|
|
|
|
|
|
|
|
this.instance = this.createInstance();
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Graphics.prototype = Object.create(GameLib.D3.API.Graphics.prototype);
|
|
|
|
GameLib.D3.Graphics.prototype.constructor = GameLib.D3.Graphics;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a GameLib.D3.Graphics to a new GameLib.D3.API.Graphics
|
|
|
|
* @returns {GameLib.D3.API.Graphics}
|
|
|
|
*/
|
|
|
|
GameLib.D3.Graphics.prototype.toApiGraphics = function() {
|
|
|
|
return new GameLib.D3.API.Graphics(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
|
|
|
this.graphicsType,
|
|
|
|
this.parentEntity
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts from an Object Graphics to a GameLib.D3.Graphics
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @param objectGraphics Object
|
|
|
|
* @returns {GameLib.D3.Graphics}
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.Graphics.FromObjectGraphics = function(graphics, objectGraphics) {
|
|
|
|
|
|
|
|
var apiGraphics = GameLib.D3.API.Graphics.FromObjectComponent(objectGraphics);
|
|
|
|
|
|
|
|
return new GameLib.D3.Graphics(
|
|
|
|
graphics,
|
|
|
|
apiGraphics
|
|
|
|
);
|
|
|
|
|
2016-10-25 17:57:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
}
|
|
|
|
};
|