88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
|
/**
|
||
|
* This component renders a scene
|
||
|
* @param id String
|
||
|
* @param name String
|
||
|
* @param helperType
|
||
|
* @param object
|
||
|
* @param parentEntity
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.API.Helper = function (
|
||
|
id,
|
||
|
name,
|
||
|
helperType,
|
||
|
object,
|
||
|
parentEntity
|
||
|
) {
|
||
|
|
||
|
GameLib.Component.call(
|
||
|
this,
|
||
|
GameLib.Component.COMPONENT_HELPER,
|
||
|
null,
|
||
|
null,
|
||
|
parentEntity
|
||
|
);
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||
|
id = GameLib.Utils.RandomId();
|
||
|
}
|
||
|
this.id = id;
|
||
|
|
||
|
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');
|
||
|
}
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(helperType)) {
|
||
|
if (
|
||
|
object instanceof GameLib.D3.Mesh &&
|
||
|
object.meshType != GameLib.D3.Mesh.TYPE_CURVE
|
||
|
) {
|
||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_WIREFRAME;
|
||
|
}
|
||
|
|
||
|
if (object instanceof GameLib.D3.Light) {
|
||
|
if (object.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT;
|
||
|
}
|
||
|
|
||
|
if (object.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT;
|
||
|
}
|
||
|
|
||
|
if (object.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT) {
|
||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (object instanceof GameLib.D3.Skeleton) {
|
||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_SKELETON;
|
||
|
}
|
||
|
}
|
||
|
this.helperType = helperType;
|
||
|
|
||
|
};
|
||
|
|
||
|
GameLib.D3.API.Helper.prototype = Object.create(GameLib.Component.prototype);
|
||
|
GameLib.D3.API.Helper.prototype.constructor = GameLib.D3.API.Helper;
|
||
|
|
||
|
/**
|
||
|
* Object to GameLib.D3.API.Helper
|
||
|
* @param objectComponent
|
||
|
* @constructor
|
||
|
*/
|
||
|
GameLib.D3.API.Helper.FromObjectComponent = function(objectComponent) {
|
||
|
return new GameLib.D3.API.Helper(
|
||
|
objectComponent.id,
|
||
|
objectComponent.name,
|
||
|
objectComponent.helperType,
|
||
|
objectComponent.object,
|
||
|
objectComponent.parentEntity
|
||
|
);
|
||
|
};
|