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, 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
); );
}; };

View File

@ -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
); );

View File

@ -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;

View File

@ -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;

View File

@ -4,7 +4,7 @@
* @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
) { ) {
@ -69,6 +69,12 @@ GameLib.D3.Light = function Light(
this this
); );
this.rotation = new GameLib.Vector3(
graphics,
this.rotation,
this
);
this.instance = this.createInstance(); this.instance = this.createInstance();
}; };
@ -90,7 +96,6 @@ 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) { if (update) {

View File

@ -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();
}; };

View File

@ -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,6 +45,22 @@ GameLib.EntityManager = function(
}.bind(this) }.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.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
); );

View File

@ -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();
}); });
} }
); );