input controls again
parent
b29cb12bee
commit
625fcfedb9
|
@ -10,6 +10,7 @@ GameLib.API.EntityManager = function(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
entities,
|
entities,
|
||||||
|
// systems,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
|
@ -17,6 +18,7 @@ GameLib.API.EntityManager = function(
|
||||||
GameLib.Component.COMPONENT_ENTITY_MANAGER,
|
GameLib.Component.COMPONENT_ENTITY_MANAGER,
|
||||||
{
|
{
|
||||||
'entities' : [GameLib.Entity]
|
'entities' : [GameLib.Entity]
|
||||||
|
// 'systems' : [GameLib.System]
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
|
@ -36,6 +38,11 @@ GameLib.API.EntityManager = function(
|
||||||
entities = [];
|
entities = [];
|
||||||
}
|
}
|
||||||
this.entities = entities;
|
this.entities = entities;
|
||||||
|
|
||||||
|
// if (GameLib.Utils.UndefinedOrNull(systems)) {
|
||||||
|
// systems = [];
|
||||||
|
// }
|
||||||
|
// this.systems = systems;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.API.EntityManager.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.API.EntityManager.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
@ -54,10 +61,17 @@ GameLib.API.EntityManager.FromObjectEntityManager = function(objectEntityManager
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// var apiSystems = objectEntityManager.systems.map(
|
||||||
|
// function (objectSystem) {
|
||||||
|
// return GameLib.API.System.FromObjectComponent(objectSystem);
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
return new GameLib.API.EntityManager(
|
return new GameLib.API.EntityManager(
|
||||||
objectEntityManager.id,
|
objectEntityManager.id,
|
||||||
objectEntityManager.name,
|
objectEntityManager.name,
|
||||||
apiEntities,
|
apiEntities,
|
||||||
|
// apiSystems,
|
||||||
objectEntityManager.parentEntity
|
objectEntityManager.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,13 +3,7 @@
|
||||||
* @param id String
|
* @param id String
|
||||||
* @param name String
|
* @param name String
|
||||||
* @param domElement
|
* @param domElement
|
||||||
* @param domContainer
|
|
||||||
* @param editor GameLib.D3.API.Editor
|
|
||||||
* @param camera
|
* @param camera
|
||||||
* @param widthOffset
|
|
||||||
* @param heightOffset
|
|
||||||
* @param containerWidthOffset
|
|
||||||
* @param containerHeightOffset
|
|
||||||
* @param selectDelayMs
|
* @param selectDelayMs
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -18,13 +12,7 @@ GameLib.D3.API.Input.Editor = function (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
domElement,
|
domElement,
|
||||||
// domContainer,
|
|
||||||
editor,
|
|
||||||
camera,
|
camera,
|
||||||
widthOffset,
|
|
||||||
heightOffset,
|
|
||||||
containerWidthOffset,
|
|
||||||
containerHeightOffset,
|
|
||||||
selectDelayMs,
|
selectDelayMs,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
|
@ -32,7 +20,6 @@ GameLib.D3.API.Input.Editor = function (
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_INPUT_EDITOR,
|
GameLib.Component.COMPONENT_INPUT_EDITOR,
|
||||||
{
|
{
|
||||||
'editor' : GameLib.D3.Editor,
|
|
||||||
'camera' : GameLib.D3.Camera
|
'camera' : GameLib.D3.Camera
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
|
@ -53,42 +40,12 @@ GameLib.D3.API.Input.Editor = function (
|
||||||
domElement = null;
|
domElement = null;
|
||||||
}
|
}
|
||||||
this.domElement = domElement;
|
this.domElement = domElement;
|
||||||
//
|
|
||||||
// if (GameLib.Utils.UndefinedOrNull(domContainer)) {
|
|
||||||
// domContainer = null;
|
|
||||||
// }
|
|
||||||
// this.domContainer = domContainer;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(editor)) {
|
|
||||||
editor = null;
|
|
||||||
}
|
|
||||||
this.editor = editor;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
camera = null;
|
camera = null;
|
||||||
}
|
}
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(widthOffset)) {
|
|
||||||
widthOffset = 400;
|
|
||||||
}
|
|
||||||
this.widthOffset = widthOffset;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(heightOffset)) {
|
|
||||||
heightOffset = 0;
|
|
||||||
}
|
|
||||||
this.heightOffset = heightOffset;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(containerWidthOffset)) {
|
|
||||||
containerWidthOffset = 0;
|
|
||||||
}
|
|
||||||
this.containerWidthOffset = containerWidthOffset;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(containerHeightOffset)) {
|
|
||||||
containerHeightOffset = 80;
|
|
||||||
}
|
|
||||||
this.containerHeightOffset = containerHeightOffset;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(selectDelayMs)) {
|
if (GameLib.Utils.UndefinedOrNull(selectDelayMs)) {
|
||||||
selectDelayMs = 300;
|
selectDelayMs = 300;
|
||||||
}
|
}
|
||||||
|
@ -109,13 +66,7 @@ GameLib.D3.API.Input.Editor.FromObjectComponent = function(objectComponent) {
|
||||||
objectComponent.id,
|
objectComponent.id,
|
||||||
objectComponent.name,
|
objectComponent.name,
|
||||||
objectComponent.domElement,
|
objectComponent.domElement,
|
||||||
// objectComponent.domContainer,
|
|
||||||
objectComponent.editor,
|
|
||||||
objectComponent.camera,
|
objectComponent.camera,
|
||||||
objectComponent.widthOffset,
|
|
||||||
objectComponent.heightOffset,
|
|
||||||
objectComponent.containerWidthOffset,
|
|
||||||
objectComponent.containerHeightOffset,
|
|
||||||
objectComponent.selectDelayMs,
|
objectComponent.selectDelayMs,
|
||||||
objectComponent.parentEntity
|
objectComponent.parentEntity
|
||||||
);
|
);
|
||||||
|
|
|
@ -69,52 +69,52 @@ GameLib.D3.API.Light = function(
|
||||||
}
|
}
|
||||||
this.intensity = intensity;
|
this.intensity = intensity;
|
||||||
|
|
||||||
if (typeof position == 'undefined') {
|
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||||
position = new GameLib.API.Vector3(0,10,0);
|
position = new GameLib.API.Vector3(0,10,0);
|
||||||
}
|
}
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
||||||
if (typeof targetPosition == 'undefined') {
|
if (GameLib.Utils.UndefinedOrNull(targetPosition)) {
|
||||||
targetPosition = new GameLib.API.Vector3(0,0,0);
|
targetPosition = new GameLib.API.Vector3(0,0,0);
|
||||||
}
|
}
|
||||||
this.targetPosition = targetPosition;
|
this.targetPosition = targetPosition;
|
||||||
|
|
||||||
if (typeof quaternion == 'undefined'){
|
if (GameLib.Utils.UndefinedOrNull(quaternion)){
|
||||||
quaternion = new GameLib.API.Quaternion();
|
quaternion = new GameLib.API.Quaternion();
|
||||||
}
|
}
|
||||||
this.quaternion = quaternion;
|
this.quaternion = quaternion;
|
||||||
|
|
||||||
if (typeof rotation == 'undefined'){
|
if (GameLib.Utils.UndefinedOrNull(rotation)){
|
||||||
rotation = new GameLib.API.Vector3(0,0,0);
|
rotation = new GameLib.API.Vector3(0,0,0);
|
||||||
}
|
}
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
|
|
||||||
if (typeof scale == 'undefined'){
|
if (GameLib.Utils.UndefinedOrNull(scale)){
|
||||||
scale = new GameLib.API.Vector3(1,1,1);
|
scale = new GameLib.API.Vector3(1,1,1);
|
||||||
}
|
}
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
|
|
||||||
if (typeof distance == 'undefined'){
|
if (GameLib.Utils.UndefinedOrNull(distance)){
|
||||||
distance = 0;
|
distance = 0;
|
||||||
}
|
}
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
|
|
||||||
if (typeof decay == 'undefined'){
|
if (GameLib.Utils.UndefinedOrNull(decay)){
|
||||||
decay = 1;
|
decay = 1;
|
||||||
}
|
}
|
||||||
this.decay = decay;
|
this.decay = decay;
|
||||||
|
|
||||||
if (typeof power == 'undefined'){
|
if (GameLib.Utils.UndefinedOrNull(power)){
|
||||||
power = 4 * Math.PI;
|
power = 4 * Math.PI;
|
||||||
}
|
}
|
||||||
this.power = power;
|
this.power = power;
|
||||||
|
|
||||||
if (typeof angle == 'undefined'){
|
if (GameLib.Utils.UndefinedOrNull(angle)){
|
||||||
angle = Math.PI / 3;
|
angle = Math.PI / 3;
|
||||||
}
|
}
|
||||||
this.angle = angle;
|
this.angle = angle;
|
||||||
|
|
||||||
if (typeof penumbra == 'undefined'){
|
if (GameLib.Utils.UndefinedOrNull(penumbra)){
|
||||||
penumbra = 0;
|
penumbra = 0;
|
||||||
}
|
}
|
||||||
this.penumbra = penumbra;
|
this.penumbra = penumbra;
|
||||||
|
|
|
@ -25,50 +25,17 @@ GameLib.D3.Input.Editor = function (
|
||||||
apiInputEditor.id,
|
apiInputEditor.id,
|
||||||
apiInputEditor.name,
|
apiInputEditor.name,
|
||||||
apiInputEditor.domElement,
|
apiInputEditor.domElement,
|
||||||
// apiInputEditor.domContainer,
|
|
||||||
apiInputEditor.editor,
|
|
||||||
apiInputEditor.camera,
|
apiInputEditor.camera,
|
||||||
apiInputEditor.widthOffset,
|
|
||||||
apiInputEditor.heightOffset,
|
|
||||||
apiInputEditor.containerWidthOffset,
|
|
||||||
apiInputEditor.containerHeightOffset,
|
|
||||||
apiInputEditor.selectDelayMs,
|
apiInputEditor.selectDelayMs,
|
||||||
apiInputEditor.parentEntity
|
apiInputEditor.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
// if (GameLib.Utils.UndefinedOrNull(dom)) {
|
|
||||||
// console.warn('Cannot create window resize event without handle to the DOM');
|
|
||||||
// dom = null;
|
|
||||||
// // throw new Error('Cannot create Input without an handle to the DOM');
|
|
||||||
// }
|
|
||||||
// this.dom = dom;
|
|
||||||
|
|
||||||
if (this.domElement instanceof GameLib.API.DomElement) {
|
if (this.domElement instanceof GameLib.API.DomElement) {
|
||||||
this.domElement = new GameLib.DomElement(
|
this.domElement = new GameLib.DomElement(
|
||||||
this.domElement
|
this.domElement
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (this.domContainer instanceof GameLib.API.DomElement) {
|
|
||||||
// this.domContainer = new GameLib.DomElement(
|
|
||||||
// this.domContainer
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cannot create a new Editor object here - it will cause an infinite loop
|
|
||||||
*
|
|
||||||
* Parent runtime objects can create their child runtime objects - but child runtime objects should not
|
|
||||||
* create their parent runtime objects.
|
|
||||||
*
|
|
||||||
if (this.editor instanceof GameLib.D3.API.Editor) {
|
|
||||||
this.editor = new GameLib.D3.Editor(
|
|
||||||
this.graphics,
|
|
||||||
this.editor
|
|
||||||
)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (this.camera instanceof GameLib.D3.API.Camera) {
|
if (this.camera instanceof GameLib.D3.API.Camera) {
|
||||||
this.camera = new GameLib.D3.Camera(
|
this.camera = new GameLib.D3.Camera(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
|
@ -123,23 +90,23 @@ GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.domElement.instance.addEventListener(
|
// this.domElement.instance.addEventListener(
|
||||||
'mousemove',
|
// 'mousemove',
|
||||||
this.mouseMove,
|
// this.mouseMove,
|
||||||
false
|
// false
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
this.domElement.instance.addEventListener(
|
// this.domElement.instance.addEventListener(
|
||||||
'contextmenu',
|
// 'contextmenu',
|
||||||
this.contextMenu,
|
// this.contextMenu,
|
||||||
false
|
// false
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
this.domElement.instance.addEventListener(
|
// this.domElement.instance.addEventListener(
|
||||||
'mousedown',
|
// 'mousedown',
|
||||||
this.mouseDown,
|
// this.mouseDown,
|
||||||
false
|
// false
|
||||||
);
|
// );
|
||||||
|
|
||||||
this.domElement.instance.addEventListener(
|
this.domElement.instance.addEventListener(
|
||||||
'keydown',
|
'keydown',
|
||||||
|
@ -171,13 +138,7 @@ GameLib.D3.Input.Editor.prototype.toApiComponent = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.domElementId,
|
this.domElementId,
|
||||||
// this.domContainerId,
|
|
||||||
GameLib.Utils.IdOrNull(this.editor),
|
|
||||||
GameLib.Utils.IdOrNull(this.camera),
|
GameLib.Utils.IdOrNull(this.camera),
|
||||||
this.widthOffset,
|
|
||||||
this.heightOffset,
|
|
||||||
this.containerWidthOffset,
|
|
||||||
this.containerHeightOffset,
|
|
||||||
this.selectDelayMs,
|
this.selectDelayMs,
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
@ -236,6 +197,12 @@ GameLib.D3.Input.Editor.prototype.onWindowResize = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Input.Editor.prototype.onKeyPress = function(event) {
|
GameLib.D3.Input.Editor.prototype.onKeyPress = function(event) {
|
||||||
|
|
||||||
|
console.log('keypressed ' + event.code);
|
||||||
|
|
||||||
|
if (event.code === 'KeyV') {
|
||||||
|
//todo - change view
|
||||||
|
};
|
||||||
|
|
||||||
if (event.code == "KeyQ") {
|
if (event.code == "KeyQ") {
|
||||||
|
|
||||||
this.editor.allSelected = !this.editor.allSelected;
|
this.editor.allSelected = !this.editor.allSelected;
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
* @param apiLight GameLib.D3.API.Light
|
* @param apiLight GameLib.D3.API.Light
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Light = function Light(
|
GameLib.D3.Light = function(
|
||||||
graphics,
|
graphics,
|
||||||
apiLight
|
apiLight
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||||
apiLight = {};
|
apiLight = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiLight instanceof GameLib.D3.Light) {
|
if (apiLight instanceof GameLib.D3.Light) {
|
||||||
return apiLight;
|
return apiLight;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Light.call(
|
GameLib.D3.API.Light.call(
|
||||||
this,
|
this,
|
||||||
apiLight.id,
|
apiLight.id,
|
||||||
apiLight.lightType,
|
apiLight.lightType,
|
||||||
apiLight.name,
|
apiLight.name,
|
||||||
apiLight.color,
|
apiLight.color,
|
||||||
apiLight.intensity,
|
apiLight.intensity,
|
||||||
|
@ -35,41 +35,47 @@ GameLib.D3.Light = function Light(
|
||||||
apiLight.decay,
|
apiLight.decay,
|
||||||
apiLight.power,
|
apiLight.power,
|
||||||
apiLight.angle,
|
apiLight.angle,
|
||||||
apiLight.penumbra,
|
apiLight.penumbra,
|
||||||
apiLight.parentEntity
|
apiLight.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
this.color = new GameLib.Color(
|
this.color = new GameLib.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this.color,
|
this.color,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this.position,
|
this.position,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.targetPosition = new GameLib.Vector3(
|
this.targetPosition = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this.targetPosition,
|
this.targetPosition,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.scale = new GameLib.Vector3(
|
this.scale = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this.scale,
|
this.scale,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.quaternion = new GameLib.Quaternion(
|
this.quaternion = new GameLib.Quaternion(
|
||||||
graphics,
|
graphics,
|
||||||
this.quaternion,
|
this.quaternion,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.rotation = new GameLib.Vector3(
|
||||||
|
graphics,
|
||||||
|
this.rotation,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Light.prototype = Object.create(GameLib.D3.API.Light.prototype);
|
GameLib.D3.Light.prototype = Object.create(GameLib.D3.API.Light.prototype);
|
||||||
|
@ -90,106 +96,105 @@ GameLib.D3.Light.LIGHT_TYPE_SPOT = 0x4;
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Light.prototype.createInstance = function(update) {
|
GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
var instance = null;
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
if (update) {
|
if (!instance) {
|
||||||
instance = this.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!instance) {
|
if (
|
||||||
|
this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT ||
|
||||||
|
this.lightType === 'AmbientLight'
|
||||||
|
) {
|
||||||
|
instance = new THREE.AmbientLight(
|
||||||
|
this.color.instance,
|
||||||
|
this.intensity
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT ||
|
this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL ||
|
||||||
this.lightType === 'AmbientLight'
|
this.lightType === 'DirectionalLight'
|
||||||
) {
|
) {
|
||||||
instance = new THREE.AmbientLight(
|
instance = new THREE.DirectionalLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL ||
|
this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT ||
|
||||||
this.lightType === 'DirectionalLight'
|
this.lightType === 'PointLight'
|
||||||
) {
|
) {
|
||||||
instance = new THREE.DirectionalLight(
|
instance = new THREE.PointLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
}
|
instance.distance = this.distance;
|
||||||
|
instance.decay = this.decay;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT ||
|
this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT ||
|
||||||
this.lightType === 'PointLight'
|
this.lightType === 'SpotLight'
|
||||||
) {
|
) {
|
||||||
instance = new THREE.PointLight(
|
instance = new THREE.SpotLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
instance.distance = this.distance;
|
instance.distance = this.distance;
|
||||||
instance.decay = this.decay;
|
instance.angle = this.angle;
|
||||||
}
|
instance.penumbra = this.penumbra;
|
||||||
|
instance.decay = this.decay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (!instance) {
|
||||||
this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT ||
|
console.warn('Do not support lights of type : ' + this.lightType + ' - is your DB out of date?');
|
||||||
this.lightType === 'SpotLight'
|
throw new Error('Do not support lights of type : ' + this.lightType + ' - is your DB out of date?');
|
||||||
) {
|
}
|
||||||
instance = new THREE.SpotLight(
|
|
||||||
this.color.instance,
|
|
||||||
this.intensity
|
|
||||||
);
|
|
||||||
instance.distance = this.distance;
|
|
||||||
instance.angle = this.angle;
|
|
||||||
instance.penumbra = this.penumbra;
|
|
||||||
instance.decay = this.decay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!instance) {
|
instance.gameLibObject = this;
|
||||||
console.warn('Do not support lights of type : ' + this.lightType + ' - is your DB out of date?');
|
|
||||||
throw new Error('Do not support lights of type : ' + this.lightType + ' - is your DB out of date?');
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.gameLibObject = this;
|
instance.name = this.name;
|
||||||
|
|
||||||
instance.name = this.name;
|
instance.position.x = this.position.x;
|
||||||
|
instance.position.y = this.position.y;
|
||||||
|
instance.position.z = this.position.z;
|
||||||
|
|
||||||
instance.position.x = this.position.x;
|
instance.scale.x = this.scale.x;
|
||||||
instance.position.y = this.position.y;
|
instance.scale.y = this.scale.y;
|
||||||
instance.position.z = this.position.z;
|
instance.scale.z = this.scale.z;
|
||||||
|
|
||||||
instance.scale.x = this.scale.x;
|
if (instance.target) {
|
||||||
instance.scale.y = this.scale.y;
|
instance.target.position.x = this.targetPosition.x;
|
||||||
instance.scale.z = this.scale.z;
|
instance.target.position.y = this.targetPosition.y;
|
||||||
|
instance.target.position.z = this.targetPosition.z;
|
||||||
|
}
|
||||||
|
|
||||||
if (instance.target) {
|
instance.quaternion.x = this.quaternion.x;
|
||||||
instance.target.position.x = this.targetPosition.x;
|
instance.quaternion.y = this.quaternion.y;
|
||||||
instance.target.position.y = this.targetPosition.y;
|
instance.quaternion.z = this.quaternion.z;
|
||||||
instance.target.position.z = this.targetPosition.z;
|
instance.quaternion.w = this.quaternion.w;
|
||||||
}
|
|
||||||
|
|
||||||
instance.quaternion.x = this.quaternion.x;
|
instance.intensity = this.intensity;
|
||||||
instance.quaternion.y = this.quaternion.y;
|
|
||||||
instance.quaternion.z = this.quaternion.z;
|
|
||||||
instance.quaternion.w = this.quaternion.w;
|
|
||||||
|
|
||||||
instance.intensity = this.intensity;
|
instance.color.set(this.color.toHex());
|
||||||
|
|
||||||
instance.color.set(this.color.toHex());
|
return instance;
|
||||||
|
|
||||||
return instance;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the instance with the current state
|
* Updates the instance with the current state
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Light.prototype.updateInstance = function() {
|
GameLib.D3.Light.prototype.updateInstance = function() {
|
||||||
this.instance = this.createInstance(true);
|
this.instance = this.createInstance(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Light.prototype.clone = function() {
|
GameLib.D3.Light.prototype.clone = function() {
|
||||||
return _.cloneDeep(this);
|
return _.cloneDeep(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -197,24 +202,24 @@ GameLib.D3.Light.prototype.clone = function() {
|
||||||
* @returns {GameLib.D3.API.Light}
|
* @returns {GameLib.D3.API.Light}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Light.prototype.toApiLight = function() {
|
GameLib.D3.Light.prototype.toApiLight = function() {
|
||||||
return new GameLib.D3.API.Light(
|
return new GameLib.D3.API.Light(
|
||||||
this.id,
|
this.id,
|
||||||
this.lightType,
|
this.lightType,
|
||||||
this.name,
|
this.name,
|
||||||
this.color.toApiColor(),
|
this.color.toApiColor(),
|
||||||
this.intensity,
|
this.intensity,
|
||||||
this.position.toApiVector(),
|
this.position.toApiVector(),
|
||||||
this.targetPosition.toApiVector(),
|
this.targetPosition.toApiVector(),
|
||||||
this.quaternion.toApiQuaternion(),
|
this.quaternion.toApiQuaternion(),
|
||||||
this.rotation,
|
this.rotation,
|
||||||
this.scale.toApiVector(),
|
this.scale.toApiVector(),
|
||||||
this.distance,
|
this.distance,
|
||||||
this.decay,
|
this.decay,
|
||||||
this.power,
|
this.power,
|
||||||
this.angle,
|
this.angle,
|
||||||
this.penumbra,
|
this.penumbra,
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -225,9 +230,9 @@ GameLib.D3.Light.prototype.toApiLight = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Light.FromObjectLight = function(graphics, objectLight) {
|
GameLib.D3.Light.FromObjectLight = function(graphics, objectLight) {
|
||||||
|
|
||||||
return new GameLib.D3.Light(
|
return new GameLib.D3.Light(
|
||||||
graphics,
|
graphics,
|
||||||
GameLib.D3.API.Light.FromObjectLight(objectLight)
|
GameLib.D3.API.Light.FromObjectLight(objectLight)
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
|
@ -57,7 +57,9 @@ GameLib.D3.Renderer.prototype.createInstance = function(update) {
|
||||||
if (update) {
|
if (update) {
|
||||||
instance = this.instance;
|
instance = this.instance;
|
||||||
} else {
|
} else {
|
||||||
instance = new THREE.WebGLRenderer();
|
instance = new THREE.WebGLRenderer({
|
||||||
|
canvas : this.domElement.instance
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.localClippingEnabled = this.localClipping;
|
instance.localClippingEnabled = this.localClipping;
|
||||||
|
@ -121,7 +123,6 @@ GameLib.D3.Renderer.prototype.render = function() {
|
||||||
GameLib.D3.Renderer.prototype.setSize = function(width, height) {
|
GameLib.D3.Renderer.prototype.setSize = function(width, height) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
this.updateInstance();
|
this.updateInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ GameLib.EntityManager = function(
|
||||||
apiEntityManager.id,
|
apiEntityManager.id,
|
||||||
apiEntityManager.name,
|
apiEntityManager.name,
|
||||||
apiEntityManager.entities,
|
apiEntityManager.entities,
|
||||||
|
// apiEntityManager.systems,
|
||||||
apiEntityManager.parentEntity
|
apiEntityManager.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -44,7 +45,23 @@ GameLib.EntityManager = function(
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.buildIdToObject();
|
// this.systems = this.systems.map(
|
||||||
|
// function(apiSystem) {
|
||||||
|
//
|
||||||
|
// if (apiSystem instanceof GameLib.API.System) {
|
||||||
|
// return new GameLib.System(
|
||||||
|
// this.graphics,
|
||||||
|
// apiSystem
|
||||||
|
// )
|
||||||
|
// } else {
|
||||||
|
// console.warn('System not of type API.System');
|
||||||
|
// throw new Error('System not of type API.System');
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }.bind(this)
|
||||||
|
// );
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
@ -64,7 +81,7 @@ GameLib.EntityManager.prototype.createInstance = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an GameLib.Entity
|
* Creates an GameLib.Entity and adds it to entities array
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.EntityManager.prototype.createEntity = function(name) {
|
GameLib.EntityManager.prototype.createEntity = function(name) {
|
||||||
|
@ -86,12 +103,20 @@ GameLib.EntityManager.prototype.createEntity = function(name) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an entity to this manager
|
* Adds an entity to this manager
|
||||||
* @param entity
|
* @param entity GameLib.Entity
|
||||||
*/
|
*/
|
||||||
GameLib.EntityManager.prototype.addEntity = function(entity) {
|
GameLib.EntityManager.prototype.addEntity = function(entity) {
|
||||||
this.entities.push(entity);
|
this.entities.push(entity);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Adds a system to this manager
|
||||||
|
// * @param system GameLib.System
|
||||||
|
// */
|
||||||
|
// GameLib.EntityManager.prototype.addSystem = function(system) {
|
||||||
|
// this.systems.push(system);
|
||||||
|
// };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns entity by name
|
* Returns entity by name
|
||||||
* @param name
|
* @param name
|
||||||
|
@ -156,72 +181,6 @@ GameLib.EntityManager.prototype.query = function(components) {
|
||||||
);
|
);
|
||||||
|
|
||||||
return entities;
|
return entities;
|
||||||
|
|
||||||
// var result = this.entities.reduce(
|
|
||||||
//
|
|
||||||
// function(__queryComponents) {
|
|
||||||
//
|
|
||||||
// return function(result, entity) {
|
|
||||||
//
|
|
||||||
// var results = __queryComponents.reduce(
|
|
||||||
//
|
|
||||||
// function(__entity) {
|
|
||||||
//
|
|
||||||
// return function(componentResult, queryComponent) {
|
|
||||||
//
|
|
||||||
// var components = __entity.components.reduce(
|
|
||||||
//
|
|
||||||
// function(__queryComponent) {
|
|
||||||
//
|
|
||||||
// return function(__components, entityComponent) {
|
|
||||||
//
|
|
||||||
// if (__queryComponent === entityComponent.constructor) {
|
|
||||||
// // arrow should point towards a window or sergej --->
|
|
||||||
// __components[entityComponent.id] = entityComponent;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return __components;
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }(queryComponent),
|
|
||||||
// {}
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// for (var property in components) {
|
|
||||||
// if (components.hasOwnProperty(property)) {
|
|
||||||
// componentResult[property] = components[property];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return componentResult;
|
|
||||||
// }
|
|
||||||
// }(entity),
|
|
||||||
// {}
|
|
||||||
//
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// for (var property in results) {
|
|
||||||
// if (results.hasOwnProperty(property)) {
|
|
||||||
// result[property] = results[property];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return result;
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }(components),
|
|
||||||
// {}
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// var array = [];
|
|
||||||
//
|
|
||||||
// for (var property in result) {
|
|
||||||
// if (result.hasOwnProperty(property)) {
|
|
||||||
// array.push(result[property]);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return array;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,10 +217,17 @@ GameLib.EntityManager.prototype.toApiEntityManager = function() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// var apiSystems = this.systems.map(
|
||||||
|
// function (system) {
|
||||||
|
// return system.toApiSystem();
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
var apiEntityManager = new GameLib.API.EntityManager(
|
var apiEntityManager = new GameLib.API.EntityManager(
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
apiEntities,
|
apiEntities,
|
||||||
|
// apiSystems,
|
||||||
this.parentEntity
|
this.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -76,13 +76,13 @@ GameLib.System.prototype.start = function() {
|
||||||
//this.domElement.instance.appendChild(this.domStats.instance);
|
//this.domElement.instance.appendChild(this.domStats.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.renderers = this.entityManager.queryComponents(GameLib.D3.Renderer);
|
// this.renderers = this.entityManager.queryComponents(GameLib.D3.Renderer);
|
||||||
|
|
||||||
this.renderers.forEach(
|
// this.renderers.forEach(
|
||||||
function (renderer) {
|
// function (renderer) {
|
||||||
renderer.domElement.instance.appendChild(renderer.instance.domElement);
|
// renderer.domElement.instance.appendChild(renderer.instance.domElement);
|
||||||
}.bind(this)
|
// }.bind(this)
|
||||||
);
|
// );
|
||||||
|
|
||||||
this.renderEntities = this.entityManager.query(
|
this.renderEntities = this.entityManager.query(
|
||||||
[
|
[
|
||||||
|
@ -180,11 +180,18 @@ GameLib.System.prototype.update = function(deltaTime) {
|
||||||
|
|
||||||
var scenes = renderEntity.getComponent(GameLib.D3.Scene);
|
var scenes = renderEntity.getComponent(GameLib.D3.Scene);
|
||||||
|
|
||||||
|
if (scenes.length > 1) {
|
||||||
|
renderer.instance.autoClear = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.instance.clear();
|
||||||
|
|
||||||
scenes.map(function(scene){
|
scenes.map(function(scene){
|
||||||
renderer.instance.render(
|
renderer.instance.render(
|
||||||
scene.instance,
|
scene.instance,
|
||||||
camera.instance
|
camera.instance
|
||||||
);
|
);
|
||||||
|
renderer.instance.clearDepth();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue