keydown and up - tex map fixes - delete objects
parent
8c2ae310fb
commit
4cad81bb8f
|
@ -58,6 +58,8 @@ GameLib.D3.Input.Editor = function (
|
|||
this.mouseUp = null;
|
||||
this.mouseWheel = null;
|
||||
|
||||
this.controlLeft = false;
|
||||
|
||||
this.raycaster = new GameLib.D3.Raycaster(
|
||||
this.graphics
|
||||
);
|
||||
|
@ -118,13 +120,69 @@ GameLib.D3.Input.Editor.FromObjectComponent = function(graphics, objectComponent
|
|||
/**
|
||||
* Keypress events
|
||||
* @param entity
|
||||
* @param entityManager
|
||||
* @returns {Function}
|
||||
*/
|
||||
GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity) {
|
||||
GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
|
||||
|
||||
return function(event) {
|
||||
console.log('entity ' + entity.name + 'emitted keypress ' + event.code);
|
||||
|
||||
if (event.code === 'Delete') {
|
||||
var meshes = entity.getComponents(GameLib.D3.Mesh);
|
||||
var gui = entity.getFirstComponent(GameLib.GUI);
|
||||
|
||||
meshes.map(
|
||||
function(mesh) {
|
||||
if (mesh.selected) {
|
||||
this.removeHelper(mesh, entity);
|
||||
entity.removeComponent(mesh);
|
||||
entity.buildIdToObject();
|
||||
|
||||
gui.removeObject(mesh);
|
||||
|
||||
var scene = mesh.parentScene;
|
||||
scene.removeObject(mesh);
|
||||
scene.buildIdToObject();
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
|
||||
|
||||
gui.build(entityManager);
|
||||
}
|
||||
|
||||
if (event.code === 'ControlLeft') {
|
||||
this.controlLeft = true;
|
||||
}
|
||||
|
||||
// BELOW is just a test to stop systems from keypress - it works nicely :)
|
||||
// but of course, when the system is stopped it can no longer be started by keypress
|
||||
// var inputSystem = entity.getComponents(GameLib.System).reduce(
|
||||
// function(result, system){
|
||||
// if (system.systemType === GameLib.System.SYSTEM_TYPE_INPUT) {
|
||||
// result = system;
|
||||
// }
|
||||
// return result;
|
||||
// },
|
||||
// null
|
||||
// );
|
||||
//
|
||||
// inputSystem.stop();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Input.Editor.prototype.onKeyUp = function(entity, entityManager) {
|
||||
|
||||
return function(event) {
|
||||
console.log('entity ' + entity.name + 'emitted keypress ' + event.code);
|
||||
|
||||
if (event.code === 'ControlLeft') {
|
||||
this.controlLeft = false;
|
||||
}
|
||||
|
||||
// BELOW is just a test to stop systems from keypress - it works nicely :)
|
||||
// but of course, when the system is stopped it can no longer be started by keypress
|
||||
// var inputSystem = entity.getComponents(GameLib.System).reduce(
|
||||
|
@ -172,6 +230,36 @@ GameLib.D3.Input.Editor.prototype.onMouseWheel = function(entity) {
|
|||
};
|
||||
};
|
||||
|
||||
GameLib.D3.Input.Editor.prototype.removeHelper = function(mesh, entity) {
|
||||
|
||||
var components = entity.getComponents(GameLib.D3.Helper);
|
||||
|
||||
var helper = components.reduce(
|
||||
function (result, component) {
|
||||
if (component.object === mesh) {
|
||||
result = component;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
if (helper) {
|
||||
|
||||
mesh.parentScene.instance.remove(helper.instance);
|
||||
|
||||
/**
|
||||
* Restore the polygonOffset value
|
||||
*/
|
||||
mesh.instance.material.polygonOffset = mesh.polygonOffset;
|
||||
|
||||
entity.removeComponent(helper);
|
||||
|
||||
} else {
|
||||
console.warn('failed to locate helper object which should exist for ' + mesh.name);
|
||||
}
|
||||
return helper;
|
||||
};
|
||||
/**
|
||||
* MouseDown events
|
||||
* @param entity GameLib.Entity
|
||||
|
@ -184,6 +272,10 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity, entityManager)
|
|||
|
||||
if (event.button === 2) {
|
||||
|
||||
if (this.controlLeft) {
|
||||
return;
|
||||
}
|
||||
|
||||
var renderer = entity.getFirstComponent(GameLib.D3.Renderer);
|
||||
|
||||
this.mouse.x = (event.offsetX / renderer.instance.domElement.width) * 2 - 1;
|
||||
|
@ -296,32 +388,7 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity, entityManager)
|
|||
|
||||
gui.removeObject(mesh);
|
||||
|
||||
var components = entity.getComponents(GameLib.D3.Helper);
|
||||
|
||||
helper = components.reduce(
|
||||
function(result, component) {
|
||||
if (component.object === mesh) {
|
||||
result = component;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
if (helper) {
|
||||
|
||||
scene.instance.remove(helper.instance);
|
||||
|
||||
/**
|
||||
* Restore the polygonOffset value
|
||||
*/
|
||||
mesh.instance.material.polygonOffset = mesh.polygonOffset;
|
||||
|
||||
entity.removeComponent(helper);
|
||||
|
||||
} else {
|
||||
console.warn('failed to locate helper object which should exist for ' + mesh.name);
|
||||
}
|
||||
this.removeHelper(mesh, entity);
|
||||
}
|
||||
|
||||
gui.build(entityManager);
|
||||
|
|
|
@ -170,6 +170,12 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
|||
console.warn('trying to update a non-existent texture instance');
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.image.instance)) {
|
||||
console.warn('trying to update while no image instance');
|
||||
return;
|
||||
}
|
||||
|
||||
this.instance.name = this.name;
|
||||
this.instance.flipY = this.flipY;
|
||||
this.instance.encoding = this.encoding;
|
||||
|
@ -179,6 +185,8 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
|||
this.instance.repeat.y = this.repeat.y;
|
||||
this.instance.mapping = this.mapping;
|
||||
this.instance.format = this.format;
|
||||
this.instance.wrapS = this.wrapS;
|
||||
this.instance.wrapT = this.wrapT;
|
||||
|
||||
this.publish(
|
||||
GameLib.Event.TEXTURE_LOADED,
|
||||
|
@ -207,8 +215,10 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
|||
instance.repeat.y = this.repeat.y;
|
||||
instance.mapping = this.mapping;
|
||||
instance.format = this.format;
|
||||
instance.wrapS = this.wrapS;
|
||||
instance.wrapT = this.wrapT;
|
||||
|
||||
this.publish(
|
||||
this.publish(
|
||||
GameLib.Event.TEXTURE_LOADED,
|
||||
{
|
||||
texture : this
|
||||
|
@ -235,34 +245,42 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
|||
}
|
||||
}
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (data.cubeTexture) {
|
||||
|
||||
this.instance = data.cubeTexture;
|
||||
this.instance.name = this.name;
|
||||
this.mapping = this.instance.mapping;
|
||||
this.offset.x = this.instance.offset.x;
|
||||
this.offset.y = this.instance.offset.y;
|
||||
this.flipY = this.instance.flipY;
|
||||
this.encoding = this.instance.encoding;
|
||||
this.repeat.x = this.instance.offset.x;
|
||||
this.repeat.y = this.instance.offset.y;
|
||||
this.format = this.instance.format;
|
||||
instance = data.cubeTexture;
|
||||
|
||||
if (this.mapping !== GameLib.D3.Texture.TYPE_CUBE_REFLECTION_MAPPING &&
|
||||
this.mapping !== GameLib.D3.Texture.TYPE_CUBE_REFRACTION_MAPPING
|
||||
) {
|
||||
this.mapping = GameLib.D3.Texture.TYPE_CUBE_REFLECTION_MAPPING;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
var instance = new THREE.Texture(
|
||||
data.imageInstance
|
||||
);
|
||||
instance.name = this.name;
|
||||
instance.flipY = this.flipY;
|
||||
instance.encoding = this.encoding;
|
||||
instance.offset.x = this.offset.x;
|
||||
instance.offset.y = this.offset.y;
|
||||
instance.repeat.x = this.repeat.x;
|
||||
instance.repeat.y = this.repeat.y;
|
||||
this.format = instance.format;
|
||||
this.instance = instance;
|
||||
}
|
||||
instance = new THREE.Texture(
|
||||
data.imageInstance
|
||||
);
|
||||
|
||||
if (this.mapping !== GameLib.D3.Texture.TYPE_UV_MAPPING) {
|
||||
this.mapping = GameLib.D3.Texture.TYPE_UV_MAPPING;
|
||||
}
|
||||
}
|
||||
|
||||
instance.name = this.name;
|
||||
instance.flipY = this.flipY;
|
||||
instance.encoding = this.encoding;
|
||||
instance.offset.x = this.offset.x;
|
||||
instance.offset.y = this.offset.y;
|
||||
instance.repeat.x = this.repeat.x;
|
||||
instance.repeat.y = this.repeat.y;
|
||||
instance.mapping = this.mapping;
|
||||
instance.format = this.format;
|
||||
instance.wrapS = this.wrapS;
|
||||
instance.wrapT = this.wrapT;
|
||||
|
||||
this.instance = instance;
|
||||
|
||||
this.publish(
|
||||
GameLib.Event.TEXTURE_LOADED,
|
||||
|
@ -286,15 +304,15 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
|||
instance = new THREE.Texture();
|
||||
} else {
|
||||
instance = new THREE.Texture(this.image.instance);
|
||||
instance.needsUpdate = true;
|
||||
instance.name = this.name;
|
||||
instance.flipY = this.flipY;
|
||||
instance.encoding = this.encoding;
|
||||
instance.offset.x = this.offset.x;
|
||||
instance.offset.y = this.offset.y;
|
||||
instance.repeat.x = this.repeat.x;
|
||||
instance.repeat.y = this.repeat.y;
|
||||
this.format = instance.format;
|
||||
// instance.needsUpdate = true;
|
||||
// instance.name = this.name;
|
||||
// instance.flipY = this.flipY;
|
||||
// instance.encoding = this.encoding;
|
||||
// instance.offset.x = this.offset.x;
|
||||
// instance.offset.y = this.offset.y;
|
||||
// instance.repeat.x = this.repeat.x;
|
||||
// instance.repeat.y = this.repeat.y;
|
||||
// this.format = instance.format;
|
||||
}
|
||||
|
||||
this.instance = instance;
|
||||
|
|
|
@ -745,7 +745,7 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di
|
|||
'w',
|
||||
-100,
|
||||
100
|
||||
).name(property + '.w').listen().onChange(function(){object.updateInstance()});
|
||||
).name(property + '.w').listen().step(0.1).onChange(function(){object.updateInstance()});
|
||||
}
|
||||
|
||||
folder.add(
|
||||
|
@ -753,7 +753,7 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di
|
|||
'x',
|
||||
-100,
|
||||
100
|
||||
).name(property + '.x').listen().onChange(
|
||||
).name(property + '.x').listen().step(0.1).onChange(
|
||||
function(){
|
||||
object.updateInstance()
|
||||
}
|
||||
|
@ -764,7 +764,7 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di
|
|||
'y',
|
||||
-100,
|
||||
100
|
||||
).name(property + '.y').listen().onChange(function(){object.updateInstance()});
|
||||
).name(property + '.y').listen().step(0.1).onChange(function(){object.updateInstance()});
|
||||
|
||||
if (
|
||||
dimension === 3 ||
|
||||
|
@ -775,7 +775,7 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di
|
|||
'z',
|
||||
-100,
|
||||
100
|
||||
).name(property + '.z').listen().onChange(function () {
|
||||
).name(property + '.z').listen().step(0.1).onChange(function () {
|
||||
object.updateInstance()
|
||||
});
|
||||
}
|
||||
|
|
|
@ -68,11 +68,13 @@ GameLib.System.prototype.start = function() {
|
|||
|
||||
component.mouseDown = component.onMouseDown(entity, this.entityManager).bind(component);
|
||||
component.mouseMove = component.onMouseMove(entity).bind(component);
|
||||
component.keyDown = component.onKeyDown(entity).bind(component);
|
||||
component.keyDown = component.onKeyDown(entity, this.entityManager).bind(component);
|
||||
component.keyUp = component.onKeyUp(entity, this.entityManager).bind(component);
|
||||
|
||||
component.domElement.instance.addEventListener('mousedown', component.mouseDown, false);
|
||||
component.domElement.instance.addEventListener('mousemove', component.mouseMove, false);
|
||||
component.domElement.instance.addEventListener('keydown', component.keyDown, false);
|
||||
component.domElement.instance.addEventListener('keyup', component.keyUp, false);
|
||||
|
||||
component.controls = new THREE.EditorControls(
|
||||
component.camera.instance,
|
||||
|
@ -300,6 +302,7 @@ GameLib.System.prototype.stop = function() {
|
|||
component.domElement.instance.removeEventListener('mousedown', component.mouseDown, false);
|
||||
component.domElement.instance.removeEventListener('mousemove', component.mouseMove, false);
|
||||
component.domElement.instance.removeEventListener('keydown', component.keyDown, false);
|
||||
component.domElement.instance.removeEventListener('keyup', component.keyUp, false);
|
||||
component.controls.dispose();
|
||||
component.domElement.instance.removeEventListener('mouseup', component.mouseUp, false);
|
||||
component.domElement.instance.removeEventListener('mousewheel', component.mouseWheel, false);
|
||||
|
|
Loading…
Reference in New Issue