2016-12-01 18:37:57 +01:00
|
|
|
/**
|
|
|
|
* Helpers for displaying outlines or making 'invisible' scene objects visible
|
2017-01-12 17:40:17 +01:00
|
|
|
* @param graphics GameLib.D3.Graphics
|
2017-01-19 17:50:11 +01:00
|
|
|
* @param id
|
|
|
|
* @param name
|
|
|
|
* @param object
|
|
|
|
* @param helperType
|
2017-06-16 20:03:55 +02:00
|
|
|
* @param parentEntity
|
2016-12-01 18:37:57 +01:00
|
|
|
* @constructor
|
|
|
|
*/
|
2017-05-16 11:50:06 +02:00
|
|
|
GameLib.D3.Helper = function(
|
2017-01-12 17:40:17 +01:00
|
|
|
graphics,
|
2017-01-19 17:50:11 +01:00
|
|
|
id,
|
|
|
|
name,
|
|
|
|
object,
|
2017-06-16 20:03:55 +02:00
|
|
|
helperType,
|
|
|
|
parentEntity
|
2016-12-01 18:37:57 +01:00
|
|
|
) {
|
2017-01-12 17:40:17 +01:00
|
|
|
this.graphics = graphics;
|
|
|
|
this.graphics.isNotThreeThrow();
|
2016-12-01 18:37:57 +01:00
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
|
|
id = GameLib.Utils.RandomId();
|
2016-12-01 18:37:57 +01:00
|
|
|
}
|
2017-01-19 17:50:11 +01:00
|
|
|
this.id = id;
|
2016-12-01 18:37:57 +01:00
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
|
|
name = 'Helper (' + id + ')';
|
|
|
|
}
|
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(object)) {
|
|
|
|
console.warn('Cannot create a helper for an Object which does not exist');
|
|
|
|
throw new Error('Cannot create a helper for an Object which does not exist');
|
|
|
|
}
|
|
|
|
this.object = object;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(helperType)) {
|
|
|
|
|
|
|
|
helperType = GameLib.D3.Helper.HELPER_TYPE_NONE;
|
|
|
|
|
|
|
|
if (
|
|
|
|
object instanceof GameLib.D3.Mesh &&
|
2017-06-23 14:31:41 +02:00
|
|
|
object.meshType !== GameLib.D3.Mesh.MESH_TYPE_CURVE
|
2017-01-19 17:50:11 +01:00
|
|
|
) {
|
2017-02-01 16:09:34 +01:00
|
|
|
helperType = GameLib.D3.Helper.HELPER_TYPE_EDGES;
|
2017-01-19 17:50:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (object instanceof GameLib.D3.Light) {
|
2017-05-16 11:50:06 +02:00
|
|
|
if (object.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
2017-01-19 17:50:11 +01:00
|
|
|
helperType = GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT;
|
|
|
|
}
|
|
|
|
|
2017-05-16 11:50:06 +02:00
|
|
|
if (object.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
2017-01-19 17:50:11 +01:00
|
|
|
helperType = GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT;
|
|
|
|
}
|
|
|
|
|
2017-05-16 11:50:06 +02:00
|
|
|
if (object.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT) {
|
2017-01-19 17:50:11 +01:00
|
|
|
helperType = GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object instanceof GameLib.D3.Skeleton) {
|
|
|
|
helperType = GameLib.D3.Helper.HELPER_TYPE_SKELETON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.helperType = helperType;
|
2016-12-01 18:37:57 +01:00
|
|
|
|
2017-06-16 20:03:55 +02:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
|
|
parentEntity = null;
|
|
|
|
}
|
|
|
|
this.parentEntity = parentEntity;
|
|
|
|
|
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
|
|
|
GameLib.Component.COMPONENT_HELPER
|
|
|
|
);
|
2016-12-01 18:37:57 +01:00
|
|
|
};
|
|
|
|
|
2017-06-04 14:36:13 +02:00
|
|
|
GameLib.D3.Helper.prototype = Object.create(GameLib.Component.prototype);
|
|
|
|
GameLib.D3.Helper.prototype.constructor = GameLib.D3.Helper;
|
|
|
|
|
2016-12-01 18:37:57 +01:00
|
|
|
/**
|
|
|
|
* Helper types
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2017-01-19 17:50:11 +01:00
|
|
|
GameLib.D3.Helper.HELPER_TYPE_NONE = 0x0;
|
|
|
|
GameLib.D3.Helper.HELPER_TYPE_EDGES = 0x1;
|
|
|
|
GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT = 0x2;
|
|
|
|
GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT = 0x3;
|
|
|
|
GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT = 0x4;
|
|
|
|
GameLib.D3.Helper.HELPER_TYPE_WIREFRAME = 0x5;
|
|
|
|
GameLib.D3.Helper.HELPER_TYPE_SKELETON = 0x6;
|
2016-12-01 18:37:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a helper instance
|
|
|
|
*/
|
2017-06-28 17:09:06 +02:00
|
|
|
GameLib.D3.Helper.prototype.createInstance = function() {
|
2017-01-12 17:40:17 +01:00
|
|
|
|
2017-06-16 20:03:55 +02:00
|
|
|
var instance = null;
|
|
|
|
|
2017-05-16 11:50:06 +02:00
|
|
|
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_EDGES) {
|
|
|
|
instance = new THREE.EdgesHelper(this.object.instance, 0x00FF00);
|
2016-12-01 18:37:57 +01:00
|
|
|
}
|
|
|
|
|
2017-05-16 11:50:06 +02:00
|
|
|
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT) {
|
2016-12-23 16:07:10 +01:00
|
|
|
instance = new THREE.DirectionalLightHelper(this.object.instance);
|
2016-12-01 18:37:57 +01:00
|
|
|
}
|
|
|
|
|
2017-05-16 11:50:06 +02:00
|
|
|
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT) {
|
2016-12-23 16:07:10 +01:00
|
|
|
instance = new THREE.PointLightHelper(this.object.instance, 1);
|
2016-12-01 18:37:57 +01:00
|
|
|
}
|
|
|
|
|
2017-05-16 11:50:06 +02:00
|
|
|
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT) {
|
2016-12-23 16:07:10 +01:00
|
|
|
instance = new THREE.SpotLightHelper(this.object.instance);
|
2016-12-01 18:37:57 +01:00
|
|
|
}
|
|
|
|
|
2017-05-16 11:50:06 +02:00
|
|
|
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_WIREFRAME) {
|
|
|
|
instance = new THREE.WireframeGeometry(this.object.instance, 0x00FF00);
|
2016-12-23 16:07:10 +01:00
|
|
|
}
|
|
|
|
|
2017-05-16 11:50:06 +02:00
|
|
|
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_SKELETON) {
|
2017-01-12 17:40:17 +01:00
|
|
|
instance = new THREE.SkeletonHelper(this.object.instance);
|
2016-12-01 18:37:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
};
|
2017-01-12 17:40:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the instance with the current state
|
|
|
|
*/
|
|
|
|
GameLib.D3.Helper.prototype.updateInstance = function() {
|
|
|
|
};
|