input controls again

beta.r3js.org
-=yb4f310 2017-05-11 17:52:33 +02:00
parent b29cb12bee
commit 625fcfedb9
8 changed files with 241 additions and 330 deletions

View File

@ -10,6 +10,7 @@ GameLib.API.EntityManager = function(
id,
name,
entities,
// systems,
parentEntity
) {
GameLib.Component.call(
@ -17,6 +18,7 @@ GameLib.API.EntityManager = function(
GameLib.Component.COMPONENT_ENTITY_MANAGER,
{
'entities' : [GameLib.Entity]
// 'systems' : [GameLib.System]
},
null,
parentEntity
@ -36,6 +38,11 @@ GameLib.API.EntityManager = function(
entities = [];
}
this.entities = entities;
// if (GameLib.Utils.UndefinedOrNull(systems)) {
// systems = [];
// }
// this.systems = systems;
};
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(
objectEntityManager.id,
objectEntityManager.name,
apiEntities,
// apiSystems,
objectEntityManager.parentEntity
);
};

View File

@ -3,13 +3,7 @@
* @param id String
* @param name String
* @param domElement
* @param domContainer
* @param editor GameLib.D3.API.Editor
* @param camera
* @param widthOffset
* @param heightOffset
* @param containerWidthOffset
* @param containerHeightOffset
* @param selectDelayMs
* @param parentEntity
* @constructor
@ -18,13 +12,7 @@ GameLib.D3.API.Input.Editor = function (
id,
name,
domElement,
// domContainer,
editor,
camera,
widthOffset,
heightOffset,
containerWidthOffset,
containerHeightOffset,
selectDelayMs,
parentEntity
) {
@ -32,7 +20,6 @@ GameLib.D3.API.Input.Editor = function (
this,
GameLib.Component.COMPONENT_INPUT_EDITOR,
{
'editor' : GameLib.D3.Editor,
'camera' : GameLib.D3.Camera
},
null,
@ -53,42 +40,12 @@ GameLib.D3.API.Input.Editor = function (
domElement = null;
}
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)) {
camera = null;
}
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)) {
selectDelayMs = 300;
}
@ -109,13 +66,7 @@ GameLib.D3.API.Input.Editor.FromObjectComponent = function(objectComponent) {
objectComponent.id,
objectComponent.name,
objectComponent.domElement,
// objectComponent.domContainer,
objectComponent.editor,
objectComponent.camera,
objectComponent.widthOffset,
objectComponent.heightOffset,
objectComponent.containerWidthOffset,
objectComponent.containerHeightOffset,
objectComponent.selectDelayMs,
objectComponent.parentEntity
);

View File

@ -69,52 +69,52 @@ GameLib.D3.API.Light = function(
}
this.intensity = intensity;
if (typeof position == 'undefined') {
if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3(0,10,0);
}
this.position = position;
if (typeof targetPosition == 'undefined') {
if (GameLib.Utils.UndefinedOrNull(targetPosition)) {
targetPosition = new GameLib.API.Vector3(0,0,0);
}
this.targetPosition = targetPosition;
if (typeof quaternion == 'undefined'){
if (GameLib.Utils.UndefinedOrNull(quaternion)){
quaternion = new GameLib.API.Quaternion();
}
this.quaternion = quaternion;
if (typeof rotation == 'undefined'){
if (GameLib.Utils.UndefinedOrNull(rotation)){
rotation = new GameLib.API.Vector3(0,0,0);
}
this.rotation = rotation;
if (typeof scale == 'undefined'){
if (GameLib.Utils.UndefinedOrNull(scale)){
scale = new GameLib.API.Vector3(1,1,1);
}
this.scale = scale;
if (typeof distance == 'undefined'){
if (GameLib.Utils.UndefinedOrNull(distance)){
distance = 0;
}
this.distance = distance;
if (typeof decay == 'undefined'){
if (GameLib.Utils.UndefinedOrNull(decay)){
decay = 1;
}
this.decay = decay;
if (typeof power == 'undefined'){
if (GameLib.Utils.UndefinedOrNull(power)){
power = 4 * Math.PI;
}
this.power = power;
if (typeof angle == 'undefined'){
if (GameLib.Utils.UndefinedOrNull(angle)){
angle = Math.PI / 3;
}
this.angle = angle;
if (typeof penumbra == 'undefined'){
if (GameLib.Utils.UndefinedOrNull(penumbra)){
penumbra = 0;
}
this.penumbra = penumbra;

View File

@ -25,50 +25,17 @@ GameLib.D3.Input.Editor = function (
apiInputEditor.id,
apiInputEditor.name,
apiInputEditor.domElement,
// apiInputEditor.domContainer,
apiInputEditor.editor,
apiInputEditor.camera,
apiInputEditor.widthOffset,
apiInputEditor.heightOffset,
apiInputEditor.containerWidthOffset,
apiInputEditor.containerHeightOffset,
apiInputEditor.selectDelayMs,
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) {
this.domElement = new GameLib.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) {
this.camera = new GameLib.D3.Camera(
this.graphics,
@ -123,23 +90,23 @@ GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
)
}
this.domElement.instance.addEventListener(
'mousemove',
this.mouseMove,
false
);
this.domElement.instance.addEventListener(
'contextmenu',
this.contextMenu,
false
);
this.domElement.instance.addEventListener(
'mousedown',
this.mouseDown,
false
);
// this.domElement.instance.addEventListener(
// 'mousemove',
// this.mouseMove,
// false
// );
//
// this.domElement.instance.addEventListener(
// 'contextmenu',
// this.contextMenu,
// false
// );
//
// this.domElement.instance.addEventListener(
// 'mousedown',
// this.mouseDown,
// false
// );
this.domElement.instance.addEventListener(
'keydown',
@ -171,13 +138,7 @@ GameLib.D3.Input.Editor.prototype.toApiComponent = function() {
this.id,
this.name,
this.domElementId,
// this.domContainerId,
GameLib.Utils.IdOrNull(this.editor),
GameLib.Utils.IdOrNull(this.camera),
this.widthOffset,
this.heightOffset,
this.containerWidthOffset,
this.containerHeightOffset,
this.selectDelayMs,
GameLib.Utils.IdOrNull(this.parentEntity)
);
@ -236,6 +197,12 @@ GameLib.D3.Input.Editor.prototype.onWindowResize = function() {
*/
GameLib.D3.Input.Editor.prototype.onKeyPress = function(event) {
console.log('keypressed ' + event.code);
if (event.code === 'KeyV') {
//todo - change view
};
if (event.code == "KeyQ") {
this.editor.allSelected = !this.editor.allSelected;

View File

@ -4,7 +4,7 @@
* @param apiLight GameLib.D3.API.Light
* @constructor
*/
GameLib.D3.Light = function Light(
GameLib.D3.Light = function(
graphics,
apiLight
) {
@ -69,6 +69,12 @@ GameLib.D3.Light = function Light(
this
);
this.rotation = new GameLib.Vector3(
graphics,
this.rotation,
this
);
this.instance = this.createInstance();
};
@ -90,7 +96,6 @@ GameLib.D3.Light.LIGHT_TYPE_SPOT = 0x4;
*/
GameLib.D3.Light.prototype.createInstance = function(update) {
var instance = null;
if (update) {

View File

@ -57,7 +57,9 @@ GameLib.D3.Renderer.prototype.createInstance = function(update) {
if (update) {
instance = this.instance;
} else {
instance = new THREE.WebGLRenderer();
instance = new THREE.WebGLRenderer({
canvas : this.domElement.instance
});
}
instance.localClippingEnabled = this.localClipping;
@ -121,7 +123,6 @@ GameLib.D3.Renderer.prototype.render = function() {
GameLib.D3.Renderer.prototype.setSize = function(width, height) {
this.width = width;
this.height = height;
this.updateInstance();
};

View File

@ -25,6 +25,7 @@ GameLib.EntityManager = function(
apiEntityManager.id,
apiEntityManager.name,
apiEntityManager.entities,
// apiEntityManager.systems,
apiEntityManager.parentEntity
);
@ -44,6 +45,22 @@ GameLib.EntityManager = function(
}.bind(this)
);
// 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();
@ -64,7 +81,7 @@ GameLib.EntityManager.prototype.createInstance = function() {
};
/**
* Creates an GameLib.Entity
* Creates an GameLib.Entity and adds it to entities array
* @returns {*}
*/
GameLib.EntityManager.prototype.createEntity = function(name) {
@ -86,12 +103,20 @@ GameLib.EntityManager.prototype.createEntity = function(name) {
/**
* Adds an entity to this manager
* @param entity
* @param entity GameLib.Entity
*/
GameLib.EntityManager.prototype.addEntity = function(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
* @param name
@ -156,72 +181,6 @@ GameLib.EntityManager.prototype.query = function(components) {
);
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(
this.id,
this.name,
apiEntities,
// apiSystems,
this.parentEntity
);

View File

@ -76,13 +76,13 @@ GameLib.System.prototype.start = function() {
//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(
function (renderer) {
renderer.domElement.instance.appendChild(renderer.instance.domElement);
}.bind(this)
);
// this.renderers.forEach(
// function (renderer) {
// renderer.domElement.instance.appendChild(renderer.instance.domElement);
// }.bind(this)
// );
this.renderEntities = this.entityManager.query(
[
@ -180,11 +180,18 @@ GameLib.System.prototype.update = function(deltaTime) {
var scenes = renderEntity.getComponent(GameLib.D3.Scene);
if (scenes.length > 1) {
renderer.instance.autoClear = false;
}
renderer.instance.clear();
scenes.map(function(scene){
renderer.instance.render(
scene.instance,
camera.instance
);
renderer.instance.clearDepth();
});
}
);