92 lines
2.4 KiB
JavaScript
92 lines
2.4 KiB
JavaScript
/**
|
|
* Helpers for displaying outlines or making 'invisible' scene objects visible
|
|
* @param id
|
|
* @param object GameLib.D3.Object
|
|
* @param name
|
|
* @param graphics
|
|
* @param helperType
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.Helper = function Helper(
|
|
id,
|
|
object,
|
|
helperType,
|
|
name,
|
|
graphics
|
|
) {
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
id = GameLib.Utils.RandomId();
|
|
}
|
|
this.id = id;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(object)) {
|
|
throw new Error('Cannot create helpers for unknown objects');
|
|
}
|
|
this.object = object;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(helperType)) {
|
|
helperType = GameLib.D3.Helper.HELPER_TYPE_EDGES;
|
|
}
|
|
this.helperType = helperType;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
name = 'Helper (' + this.helperType + ')';
|
|
}
|
|
this.name = name;
|
|
|
|
this.graphics = graphics;
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
this.instance = this.createInstance();
|
|
};
|
|
|
|
/**
|
|
* Helper types
|
|
* @type {string}
|
|
*/
|
|
GameLib.D3.Helper.HELPER_TYPE_EDGES = 'edges';
|
|
GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT = 'directional-light';
|
|
GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT = 'spot-light';
|
|
GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT = 'point-light';
|
|
GameLib.D3.Helper.HELPER_TYPE_WIREFRAME = 'wireframe';
|
|
|
|
|
|
/**
|
|
* Creates a helper instance
|
|
* @param update
|
|
*/
|
|
GameLib.D3.Helper.prototype.createInstance = function(update) {
|
|
|
|
var instance = null;
|
|
|
|
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_EDGES) {
|
|
instance = new this.graphics.instance.EdgesHelper(this.object.instance, 0x007700);
|
|
}
|
|
|
|
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT) {
|
|
instance = new this.graphics.instance.DirectionalLightHelper(this.object.instance);
|
|
}
|
|
|
|
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT) {
|
|
instance = new this.graphics.instance.PointLightHelper(this.object.instance, 1);
|
|
}
|
|
|
|
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT) {
|
|
instance = new this.graphics.instance.SpotLightHelper(this.object.instance);
|
|
}
|
|
|
|
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_WIREFRAME) {
|
|
instance = new this.graphics.instance.WireframeHelper(this.object.instance, 0x007700);
|
|
}
|
|
|
|
if (!instance) {
|
|
throw new Error('Unsupported helper type: ' + this.helperType);
|
|
}
|
|
|
|
if (update) {
|
|
this.instance = instance;
|
|
}
|
|
|
|
return instance;
|
|
};
|