rudimentary uv editing capabilities - face select mode

beta.r3js.org
-=yb4f310 2018-01-19 15:04:54 +01:00
parent 3bc46a2d6f
commit b3d9556461
21 changed files with 630 additions and 426 deletions

View File

@ -97,7 +97,7 @@ GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f;
GameLib.Event.CAST_SOURCE_CHANGED = 0x50; GameLib.Event.CAST_SOURCE_CHANGED = 0x50;
GameLib.Event.ANIMATION_MESH_ADDED = 0x51; GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
GameLib.Event.ANIMATION_MESH_REMOVED = 0x52; GameLib.Event.ANIMATION_MESH_REMOVED = 0x52;
GameLib.Event.DOM_ELEMENT_CHANGE = 0x53; GameLib.Event.CANVAS_CHANGE = 0x53;
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54; GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
GameLib.Event.LOAD_FONT = 0x55; GameLib.Event.LOAD_FONT = 0x55;
GameLib.Event.FONT_NOT_FOUND = 0x56; GameLib.Event.FONT_NOT_FOUND = 0x56;
@ -123,6 +123,9 @@ GameLib.Event.CUSTOM_GAME_START = 0x69;
GameLib.Event.AUDIO_MUTED = 0x6a; GameLib.Event.AUDIO_MUTED = 0x6a;
GameLib.Event.AUDIO_UNMUTED = 0x6b; GameLib.Event.AUDIO_UNMUTED = 0x6b;
GameLib.Event.RECEIVE_DESTINATION_CHANGED = 0x6c; GameLib.Event.RECEIVE_DESTINATION_CHANGED = 0x6c;
GameLib.Event.SELECTION_MODE_CHANGE = 0x6d;
GameLib.Event.MESH_FACE_SELECTED = 0x6e;
GameLib.Event.MESH_FACE_DESELECTED = 0x6f;
/** /**
* Returns string name of event ID * Returns string name of event ID
@ -241,6 +244,9 @@ GameLib.Event.GetEventName = function(number) {
case 0x6a : return 'audio_muted'; case 0x6a : return 'audio_muted';
case 0x6b : return 'audio_unmuted'; case 0x6b : return 'audio_unmuted';
case 0x6c : return 'receive_destination_changed'; case 0x6c : return 'receive_destination_changed';
case 0x6d : return 'selection_mode_change';
case 0x6e : return 'mesh_face_selected';
case 0x6f : return 'mesh_face_deselected';
break; break;
} }

View File

@ -220,7 +220,7 @@ GameLib.Component.PASS = 0xd;
GameLib.Component.SCENE = 0xe; GameLib.Component.SCENE = 0xe;
GameLib.Component.RAYCASTER = 0xf; GameLib.Component.RAYCASTER = 0xf;
GameLib.Component.TEXT = 0x10; GameLib.Component.TEXT = 0x10;
//GameLib.Component.EDITOR = 0x11; GameLib.Component.FACE = 0x11;
GameLib.Component.VIEWPORT = 0x12; GameLib.Component.VIEWPORT = 0x12;
GameLib.Component.SYSTEM = 0x13; GameLib.Component.SYSTEM = 0x13;
GameLib.Component.GRAPHICS = 0x14; GameLib.Component.GRAPHICS = 0x14;
@ -405,7 +405,12 @@ GameLib.Component.GetComponentInfo = function(number) {
constructor : GameLib.D3.Text, constructor : GameLib.D3.Text,
apiConstructor : GameLib.D3.API.Text apiConstructor : GameLib.D3.API.Text
}; };
case 0x11 : return null; case 0x11 : return {
name : 'GameLib.D3.Face',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Face,
apiConstructor : GameLib.D3.API.Face
};
case 0x12 : return { case 0x12 : return {
name : 'GameLib.D3.Viewport', name : 'GameLib.D3.Viewport',
runtime : GameLib.Component.GRAPHICS_RUNTIME, runtime : GameLib.Component.GRAPHICS_RUNTIME,

View File

@ -3,7 +3,7 @@
* @param id * @param id
* @param controlsType * @param controlsType
* @param name * @param name
* @param domElement * @param canvas
* @param parentEntity * @param parentEntity
* @constructor * @constructor
*/ */
@ -11,7 +11,7 @@ GameLib.API.Controls = function(
id, id,
name, name,
controlsType, controlsType,
domElement, canvas,
parentEntity parentEntity
) { ) {
if (GameLib.Utils.UndefinedOrNull(id)) { if (GameLib.Utils.UndefinedOrNull(id)) {
@ -65,10 +65,10 @@ GameLib.API.Controls = function(
} }
this.name = name; this.name = name;
if (GameLib.Utils.UndefinedOrNull(domElement)) { if (GameLib.Utils.UndefinedOrNull(canvas)) {
domElement = null; canvas = null;
} }
this.domElement = domElement; this.canvas = canvas;
var componentType = GameLib.Component.CONTROLS; var componentType = GameLib.Component.CONTROLS;
@ -108,19 +108,3 @@ GameLib.API.Controls.CONTROLS_TYPE_EDITOR = 0x0;
GameLib.API.Controls.CONTROLS_TYPE_TOUCH = 0x1; GameLib.API.Controls.CONTROLS_TYPE_TOUCH = 0x1;
GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD = 0x2; GameLib.API.Controls.CONTROLS_TYPE_KEYBOARD = 0x2;
GameLib.API.Controls.CONTROLS_TYPE_MOUSE = 0x3; GameLib.API.Controls.CONTROLS_TYPE_MOUSE = 0x3;
/**
* Returns an API Controls from an Object
* @param objectControls
* @constructor
*/
GameLib.API.Controls.FromObject = function (objectControls){
return new GameLib.API.Controls(
objectControls.id,
objectControls.name,
objectControls.controlsType,
objectControls.domElement,
objectControls.parentEntity
);
};

View File

@ -21,7 +21,7 @@ GameLib.API.Controls.D3.Editor = function(
apiControls.id, apiControls.id,
apiControls.name, apiControls.name,
apiControls.controlsType, apiControls.controlsType,
apiControls.domElement, apiControls.canvas,
apiControls.parentEntity apiControls.parentEntity
); );
@ -43,19 +43,3 @@ GameLib.API.Controls.D3.Editor = function(
GameLib.API.Controls.D3.Editor.prototype = Object.create(GameLib.API.Controls.prototype); GameLib.API.Controls.D3.Editor.prototype = Object.create(GameLib.API.Controls.prototype);
GameLib.API.Controls.D3.Editor.prototype.constructor = GameLib.API.Controls.D3.Editor; GameLib.API.Controls.D3.Editor.prototype.constructor = GameLib.API.Controls.D3.Editor;
/**
* Creates an API.Controls.D3.Editor from an Object Cast
* @param objectControls
* @constructor
*/
GameLib.API.Controls.D3.Editor.FromObject = function(objectControls) {
var apiControls = GameLib.API.Controls.FromObject(objectControls);
return new GameLib.API.Controls.D3.Editor(
apiControls,
objectControls.raycaster,
objectControls.camera
);
};

View File

@ -17,7 +17,7 @@ GameLib.API.Controls.Keyboard = function(
apiControls.id, apiControls.id,
apiControls.name, apiControls.name,
apiControls.controlsType, apiControls.controlsType,
apiControls.domElement, apiControls.canvas,
apiControls.parentEntity apiControls.parentEntity
); );
@ -29,17 +29,3 @@ GameLib.API.Controls.Keyboard = function(
GameLib.API.Controls.Keyboard.prototype = Object.create(GameLib.API.Controls.prototype); GameLib.API.Controls.Keyboard.prototype = Object.create(GameLib.API.Controls.prototype);
GameLib.API.Controls.Keyboard.prototype.constructor = GameLib.API.Controls.Keyboard; GameLib.API.Controls.Keyboard.prototype.constructor = GameLib.API.Controls.Keyboard;
/**
* Creates an API.Controls.Keyboard from an Object Cast
* @param objectControls
* @constructor
*/
GameLib.API.Controls.Keyboard.FromObject = function(objectControls) {
var apiControls = GameLib.API.Controls.FromObject(objectControls);
return new GameLib.API.Controls.Keyboard(
apiControls
);
};

View File

@ -17,7 +17,7 @@ GameLib.API.Controls.Mouse = function(
apiControls.id, apiControls.id,
apiControls.name, apiControls.name,
apiControls.controlsType, apiControls.controlsType,
apiControls.domElement, apiControls.canvas,
apiControls.parentEntity apiControls.parentEntity
); );
@ -30,16 +30,3 @@ GameLib.API.Controls.Mouse = function(
GameLib.API.Controls.Mouse.prototype = Object.create(GameLib.API.Controls.prototype); GameLib.API.Controls.Mouse.prototype = Object.create(GameLib.API.Controls.prototype);
GameLib.API.Controls.Mouse.prototype.constructor = GameLib.API.Controls.Mouse; GameLib.API.Controls.Mouse.prototype.constructor = GameLib.API.Controls.Mouse;
/**
* Creates an API.Controls.Mouse from an Object Cast
* @param objectControls
* @constructor
*/
GameLib.API.Controls.Mouse.FromObject = function(objectControls) {
var apiControls = GameLib.API.Controls.FromObject(objectControls);
return new GameLib.API.Controls.Mouse(
apiControls
);
};

View File

@ -19,7 +19,7 @@ GameLib.API.Controls.Touch = function(
apiControls.id, apiControls.id,
apiControls.name, apiControls.name,
apiControls.controlsType, apiControls.controlsType,
apiControls.domElement, apiControls.canvas,
apiControls.parentEntity apiControls.parentEntity
); );
@ -36,18 +36,3 @@ GameLib.API.Controls.Touch = function(
GameLib.API.Controls.Touch.prototype = Object.create(GameLib.API.Controls.prototype); GameLib.API.Controls.Touch.prototype = Object.create(GameLib.API.Controls.prototype);
GameLib.API.Controls.Touch.prototype.constructor = GameLib.API.Controls.Touch; GameLib.API.Controls.Touch.prototype.constructor = GameLib.API.Controls.Touch;
/**
* Creates an API.Controls.Touch from an Object Cast
* @param objectControls
* @constructor
*/
GameLib.API.Controls.Touch.FromObject = function(objectControls) {
var apiControls = GameLib.API.Controls.FromObject(objectControls);
return new GameLib.API.Controls.Touch(
apiControls,
objectControls.sensitivity
);
};

View File

@ -16,12 +16,12 @@ GameLib.Controls = function (
apiControls.id, apiControls.id,
apiControls.name, apiControls.name,
apiControls.controlsType, apiControls.controlsType,
apiControls.domElement, apiControls.canvas,
apiControls.parentEntity apiControls.parentEntity
); );
var linkedObjects = { var linkedObjects = {
domElement : GameLib.Canvas canvas : GameLib.Canvas
}; };
var delayed = false; var delayed = false;
@ -58,9 +58,9 @@ GameLib.Controls.prototype.createInstance = function() {
*/ */
GameLib.Controls.prototype.updateInstance = function(property) { GameLib.Controls.prototype.updateInstance = function(property) {
if (property === 'domElement') { if (property === 'canvas') {
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.DOM_ELEMENT_CHANGE, GameLib.Event.CANVAS_CHANGE,
{ {
component: this component: this
} }
@ -80,24 +80,9 @@ GameLib.Controls.prototype.toApiObject = function() {
this.id, this.id,
this.name, this.name,
this.controlsType, this.controlsType,
GameLib.Utils.IdOrNull(this.domElement), GameLib.Utils.IdOrNull(this.canvas),
GameLib.Utils.IdOrNull(this.parentEntity) GameLib.Utils.IdOrNull(this.parentEntity)
); );
return apiControls; return apiControls;
}; };
/**
* Converts a data object to a GameLib.Controls
* @param objectControls {Object}
* @constructor
*/
GameLib.Controls.FromObject = function(objectControls) {
var apiControls = GameLib.API.Controls.FromObject(objectControls);
return new GameLib.Controls(
apiControls
);
};

View File

@ -63,13 +63,13 @@ GameLib.Controls.D3.Editor.prototype.createInstance = function() {
throw new Error('No camera at time of instance'); throw new Error('No camera at time of instance');
} }
if (!this.domElement || !this.domElement.instance) { if (!this.canvas || !this.canvas.instance) {
throw new Error('No dom element at time of instance'); throw new Error('No canvas at time of instance');
} }
this.instance = new THREE.EditorControls( this.instance = new THREE.EditorControls(
this.camera.instance, this.camera.instance,
this.domElement.instance this.canvas.instance
); );
GameLib.Controls.prototype.createInstance.call(this); GameLib.Controls.prototype.createInstance.call(this);

View File

@ -11,6 +11,7 @@
* @param vertexColors * @param vertexColors
* @param vertexNormals * @param vertexNormals
* @param normal * @param normal
* @param selected
* @constructor * @constructor
*/ */
GameLib.D3.API.Face = function( GameLib.D3.API.Face = function(
@ -24,7 +25,10 @@ GameLib.D3.API.Face = function(
color, color,
vertexColors, vertexColors,
vertexNormals, vertexNormals,
normal normal,
selected,
parentMesh,
parentEntity
) { ) {
if (GameLib.Utils.UndefinedOrNull(id)) { if (GameLib.Utils.UndefinedOrNull(id)) {
@ -81,96 +85,111 @@ GameLib.D3.API.Face = function(
normal = null; normal = null;
} }
this.normal = normal; this.normal = normal;
if (GameLib.Utils.UndefinedOrNull(selected)) {
selected = false;
}
this.selected = selected;
if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
parentMesh = null;
}
this.parentMesh = parentMesh;
GameLib.API.Component.call(
this,
GameLib.Component.FACE,
parentEntity
);
}; };
/** /**
* We don't inherit from component - it makes the entitymanager too heavy - all faces end up in the register etc.. * We don't inherit from component - it makes the entitymanager too heavy - all faces end up in the register etc..
*/ */
// GameLib.D3.API.Face.prototype = Object.create(GameLib.API.Component.prototype); GameLib.D3.API.Face.prototype = Object.create(GameLib.API.Component.prototype);
// GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face; GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face;
/** /**
* Returns an API Face from a data object * Returns an API Face from a data object
* @constructor * @constructor
* @param objectFace * @param objectFace
*/ */
GameLib.D3.API.Face.FromObject = function(objectFace) { // GameLib.D3.API.Face.FromObject = function(objectFace) {
//
var apiUvs = objectFace.uvs.reduce( // var apiUvs = objectFace.uvs.reduce(
//
function(result, uvArray, index) { // function(result, uvArray, index) {
//
result[index] = uvArray.reduce( // result[index] = uvArray.reduce(
function(uvResult, uv) { // function(uvResult, uv) {
uvResult.push(GameLib.API.Vector2.FromObject(uv)); // uvResult.push(GameLib.API.Vector2.FromObject(uv));
return uvResult; // return uvResult;
}, // },
[] // []
); // );
//
return result; // return result;
}, // },
[] // []
); // );
//
var apiVertexColors = objectFace.vertexColors.map( // var apiVertexColors = objectFace.vertexColors.map(
function(vertexColor) { // function(vertexColor) {
return GameLib.API.Color.FromObject(vertexColor); // return GameLib.API.Color.FromObject(vertexColor);
} // }
); // );
//
var apiColor = null; // var apiColor = null;
if (objectFace.color) { // if (objectFace.color) {
apiColor = GameLib.API.Color.FromObject(objectFace.color); // apiColor = GameLib.API.Color.FromObject(objectFace.color);
} // }
//
var apiVertexNormals = objectFace.vertexNormals.map( // var apiVertexNormals = objectFace.vertexNormals.map(
function(vertexNormal) { // function(vertexNormal) {
return GameLib.API.Vector3.FromObject(vertexNormal); // return GameLib.API.Vector3.FromObject(vertexNormal);
} // }
); // );
//
var apiNormal = null; // var apiNormal = null;
if (objectFace.normal) { // if (objectFace.normal) {
apiNormal = GameLib.API.Vector3.FromObject(objectFace.normal); // apiNormal = GameLib.API.Vector3.FromObject(objectFace.normal);
} // }
//
return new GameLib.D3.API.Face( // return new GameLib.D3.API.Face(
objectFace.id, // objectFace.id,
objectFace.name, // objectFace.name,
objectFace.v0index, // objectFace.v0index,
objectFace.v1index, // objectFace.v1index,
objectFace.v2index, // objectFace.v2index,
objectFace.materialIndex, // objectFace.materialIndex,
apiUvs, // apiUvs,
apiColor, // apiColor,
apiVertexColors, // apiVertexColors,
apiVertexNormals, // apiVertexNormals,
apiNormal // apiNormal
); // );
}; // };
//
/** // /**
* Clone a Face // * Clone a Face
* @returns {GameLib.D3.API.Face} // * @returns {GameLib.D3.API.Face}
*/ // */
GameLib.D3.API.Face.prototype.clone = function(){ // GameLib.D3.API.Face.prototype.clone = function(){
return new GameLib.D3.API.Face( // return new GameLib.D3.API.Face(
this.id, // this.id,
this.name, // this.name,
this.v0index, // this.v0index,
this.v1index, // this.v1index,
this.v2index, // this.v2index,
this.materialIndex, // this.materialIndex,
this.uvs, // this.uvs,
this.color, // this.color,
this.vertexColors, // this.vertexColors,
this.vertexNormals, // this.vertexNormals,
this.normal // this.normal
); // );
// };
};
/** /**
* Returns true if two triangles are equal (their vertex indices match in some order) * Returns true if two triangles are equal (their vertex indices match in some order)

View File

@ -249,7 +249,7 @@ GameLib.D3.API.Material = function(
this.wireframeLineJoin = wireframeLineJoin; this.wireframeLineJoin = wireframeLineJoin;
if (GameLib.Utils.UndefinedOrNull(vertexColors)) { if (GameLib.Utils.UndefinedOrNull(vertexColors)) {
vertexColors = GameLib.D3.Material.TYPE_NO_COLORS; vertexColors = GameLib.D3.Material.TYPE_FACE_COLORS;
} }
this.vertexColors = vertexColors; this.vertexColors = vertexColors;

View File

@ -308,7 +308,7 @@ GameLib.D3.API.Renderer = function (
camera = new GameLib.D3.API.Camera( camera = new GameLib.D3.API.Camera(
null, null,
GameLib.D3.API.Camera.PERSPECTIVE_CAMERA, GameLib.D3.API.Camera.PERSPECTIVE_CAMERA,
null, 'Render Camera',
null, null,
this.width / this.height this.width / this.height
); );
@ -319,7 +319,7 @@ GameLib.D3.API.Renderer = function (
editCamera = new GameLib.D3.API.Camera( editCamera = new GameLib.D3.API.Camera(
null, null,
GameLib.D3.API.Camera.PERSPECTIVE_CAMERA, GameLib.D3.API.Camera.PERSPECTIVE_CAMERA,
null, 'Edit Camera',
null, null,
this.width / this.height this.width / this.height
); );

View File

@ -89,7 +89,7 @@ GameLib.D3.API.Scene = function(
this.gridSize = gridSize; this.gridSize = gridSize;
if (GameLib.Utils.UndefinedOrNull(gridColor)) { if (GameLib.Utils.UndefinedOrNull(gridColor)) {
gridColor = new GameLib.API.Color(0.1, 0.1, 0.1); gridColor = new GameLib.API.Color(0.14117641, 0.576470588, 0.882352941);
} }
this.gridColor = gridColor; this.gridColor = gridColor;

View File

@ -34,7 +34,10 @@ GameLib.D3.Face = function Face(
apiFace.color, apiFace.color,
apiFace.vertexColors, apiFace.vertexColors,
apiFace.vertexNormals, apiFace.vertexNormals,
apiFace.normal apiFace.normal,
apiFace.selected,
apiFace.parentMesh,
apiFace.parentEntity
); );
if (this.implementation instanceof GameLib.GraphicsRuntime) { if (this.implementation instanceof GameLib.GraphicsRuntime) {
@ -77,9 +80,9 @@ GameLib.D3.Face = function Face(
this.uvs = this.uvs.reduce( this.uvs = this.uvs.reduce(
function(result, uvArray, index) { function(result, uvs, uvSet) {
result[index] = uvArray.reduce( result[uvSet] = uvs.reduce(
function(uvResult, uv) { function(uvResult, uv) {
uvResult.push( uvResult.push(
@ -113,12 +116,60 @@ GameLib.D3.Face = function Face(
GameLib.D3.Face.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.Face.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Face.prototype.constructor = GameLib.D3.Face; GameLib.D3.Face.prototype.constructor = GameLib.D3.Face;
GameLib.D3.Face.prototype.createInstance = function() { /**
* We don't follow the standard procedure for Faces - We don't want them in the EntityManager registry - so
* they don't call component createinstance
* @param parentMesh
*/
GameLib.D3.Face.prototype.createInstance = function(parentMesh) {
this.instance = new THREE.Face3(
this.v0index,
this.v1index,
this.v2index
);
if (this.normal) {
this.instance.normal = new THREE.Vector3(
this.normal.x,
this.normal.y,
this.normal.z
);
}
if (this.color) {
this.instance.color = new THREE.Color(
this.color.r,
this.color.g,
this.color.b
)
}
this.instance.materialIndex = this.materialIndex;
if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
console.warn('please pass a parentmesh to face createInstance()');
}
this.parentMesh = parentMesh;
}; };
GameLib.D3.Face.prototype.updateInstance = function() { GameLib.D3.Face.prototype.updateInstance = function(property, uvSet, uvIndex) {
if (property === 'materialIndex') {
this.instance.materialIndex = this.materialIndex;
this.parentMesh.instance.geometry.groupsNeedUpdate = true;
return;
}
if (property === 'uvs') {
this.uvs[uvSet][uvIndex].instance.x = this.uvs[uvSet][uvIndex].x;
this.uvs[uvSet][uvIndex].instance.y = this.uvs[uvSet][uvIndex].y;
this.parentMesh.instance.geometry.uvsNeedUpdate = true;
return;
}
console.warn('todo: update face property: ' + property);
}; };
GameLib.D3.Face.prototype.toApiObject = function() { GameLib.D3.Face.prototype.toApiObject = function() {
@ -159,20 +210,60 @@ GameLib.D3.Face.prototype.toApiObject = function() {
this.vertexNormals.map(function(vertexNormal){ this.vertexNormals.map(function(vertexNormal){
return vertexNormal.toApiObject(); return vertexNormal.toApiObject();
}), }),
this.normal.toApiObject() this.normal.toApiObject(),
this.selected
); );
}; };
/**
* @param implementation GameLib.D3.Face.prototype.createHelper = function(mesh) {
* @param objectFace
* @returns {GameLib.D3.Face} this.backupProperties = {
* @constructor color : {
*/ r: this.color.r,
GameLib.D3.Face.FromObject = function(implementation, objectFace) { g: this.color.g,
return new GameLib.D3.Face( b: this.color.b
implementation, },
GameLib.D3.API.Face.FromObject(objectFace) material : {
); emissive : {
r: mesh.materials[this.materialIndex].emissive.r,
g: mesh.materials[this.materialIndex].emissive.g,
b: mesh.materials[this.materialIndex].emissive.b
}
},
vertexColors : mesh.materials[this.materialIndex].vertexColors
};
this.instance.color.r = 1;
this.instance.color.g = 0;
this.instance.color.b = 0;
mesh.instance.geometry.colorsNeedUpdate = true;
//
// mesh.materials[this.materialIndex].emissive.r = 0.5;
// mesh.materials[this.materialIndex].emissive.g = 0.5;
// mesh.materials[this.materialIndex].emissive.b = 0.5;
// mesh.materials[this.materialIndex].updateInstance('emissive');
mesh.materials[this.materialIndex].vertexColors = GameLib.D3.Material.TYPE_FACE_COLORS;
mesh.materials[this.materialIndex].updateInstance('vertexColors');
}; };
GameLib.D3.Face.prototype.removeHelper = function(mesh) {
this.instance.color.r = this.backupProperties.color.r;
this.instance.color.g = this.backupProperties.color.g;
this.instance.color.b = this.backupProperties.color.b;
mesh.instance.geometry.colorsNeedUpdate = true;
// mesh.materials[this.materialIndex].emissive.r = this.backupProperties.material.emissive.r;
// mesh.materials[this.materialIndex].emissive.g = this.backupProperties.material.emissive.g;
// mesh.materials[this.materialIndex].emissive.b = this.backupProperties.material.emissive.b;
// mesh.materials[this.materialIndex].updateInstance('emissive');
mesh.materials[this.materialIndex].vertexColors = this.backupProperties.vertexColors;
mesh.materials[this.materialIndex].updateInstance('vertexColors');
};

View File

@ -382,7 +382,7 @@ GameLib.D3.Material.prototype.createToonMaterialInstance = function() {
wireframeLinewidth: this.wireframeLineWidth, wireframeLinewidth: this.wireframeLineWidth,
wireframeLinecap: this.wireframeLineCap, wireframeLinecap: this.wireframeLineCap,
wireframeLinejoin: this.wireframeLineJoin, wireframeLinejoin: this.wireframeLineJoin,
vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS, vertexColors: this.vertexColors,
skinning: this.skinning, skinning: this.skinning,
morphTargets: this.morphTargets, morphTargets: this.morphTargets,
morphNormals: this.morphNormals morphNormals: this.morphNormals
@ -428,7 +428,7 @@ GameLib.D3.Material.prototype.createStandardMaterialInstance = function() {
wireframeLinewidth: this.wireframeLineWidth, wireframeLinewidth: this.wireframeLineWidth,
wireframeLinecap: this.wireframeLineCap, wireframeLinecap: this.wireframeLineCap,
wireframeLinejoin: this.wireframeLineJoin, wireframeLinejoin: this.wireframeLineJoin,
vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS, vertexColors: this.vertexColors,
skinning: this.skinning, skinning: this.skinning,
morphTargets: this.morphTargets, morphTargets: this.morphTargets,
morphNormals: this.morphNormals morphNormals: this.morphNormals
@ -554,7 +554,7 @@ GameLib.D3.Material.prototype.createPhongMaterialInstance = function() {
wireframeLinewidth: this.wireframeLineWidth, wireframeLinewidth: this.wireframeLineWidth,
wireframeLinecap: this.wireframeLineCap, wireframeLinecap: this.wireframeLineCap,
wireframeLinejoin: this.wireframeLineJoin, wireframeLinejoin: this.wireframeLineJoin,
vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS, vertexColors: this.vertexColors,
skinning: this.skinning, skinning: this.skinning,
morphTargets: this.morphTargets, morphTargets: this.morphTargets,
morphNormals: this.morphNormals morphNormals: this.morphNormals
@ -583,7 +583,7 @@ GameLib.D3.Material.prototype.createMeshBasicMaterialInstance = function() {
visible: this.visible, visible: this.visible,
side: this.side, side: this.side,
color: this.color.instance, color: this.color.instance,
vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS, vertexColors: this.vertexColors,
fog: this.fog fog: this.fog
}); });
}; };
@ -713,7 +713,7 @@ GameLib.D3.Material.prototype.updateToonMaterialInstance = function(property) {
this.instance.wireframeLinewidth = this.wireframeLineWidth; this.instance.wireframeLinewidth = this.wireframeLineWidth;
this.instance.wireframeLinecap = this.wireframeLineCap; this.instance.wireframeLinecap = this.wireframeLineCap;
this.instance.wireframeLinejoin = this.wireframeLineJoin; this.instance.wireframeLinejoin = this.wireframeLineJoin;
this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS; this.instance.vertexColors = this.vertexColors;
this.instance.skinning = this.skinning; this.instance.skinning = this.skinning;
this.instance.morphTargets = this.morphTargets; this.instance.morphTargets = this.morphTargets;
this.instance.morphNormals = this.morphNormals; this.instance.morphNormals = this.morphNormals;
@ -757,7 +757,7 @@ GameLib.D3.Material.prototype.updateStandardMaterialInstance = function(property
this.instance.wireframeLinewidth = this.wireframeLineWidth; this.instance.wireframeLinewidth = this.wireframeLineWidth;
this.instance.wireframeLinecap = this.wireframeLineCap; this.instance.wireframeLinecap = this.wireframeLineCap;
this.instance.wireframeLinejoin = this.wireframeLineJoin; this.instance.wireframeLinejoin = this.wireframeLineJoin;
this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS; this.instance.vertexColors = this.vertexColors;
this.instance.skinning = this.skinning; this.instance.skinning = this.skinning;
this.instance.morphTargets = this.morphTargets; this.instance.morphTargets = this.morphTargets;
this.instance.morphNormals = this.morphNormals; this.instance.morphNormals = this.morphNormals;
@ -786,7 +786,7 @@ GameLib.D3.Material.prototype.updatePointsMaterialInstance = function(property)
this.instance.color = this.color.instance; this.instance.color = this.color.instance;
this.instance.size = this.pointSize; this.instance.size = this.pointSize;
this.instance.sizeAttenuation = this.pointSizeAttenuation; this.instance.sizeAttenuation = this.pointSizeAttenuation;
//this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS; //this.instance.vertexColors = this.vertexColors;
//this.instance.fog = this.fog; //this.instance.fog = this.fog;
}; };
@ -837,7 +837,7 @@ GameLib.D3.Material.prototype.updateLineBasicMaterialInstance = function(propert
this.instance.linecap = linecap; this.instance.linecap = linecap;
this.instance.linejoin = linejoin; this.instance.linejoin = linejoin;
//this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS; //this.instance.vertexColors = this.vertexColors;
//this.instance.fog = this.fog; //this.instance.fog = this.fog;
}; };
@ -881,7 +881,7 @@ GameLib.D3.Material.prototype.updatePhongMaterialInstance = function(property) {
this.instance.wireframeLinewidth = this.wireframeLineWidth; this.instance.wireframeLinewidth = this.wireframeLineWidth;
this.instance.wireframeLinecap = this.wireframeLineCap; this.instance.wireframeLinecap = this.wireframeLineCap;
this.instance.wireframeLinejoin = this.wireframeLineJoin; this.instance.wireframeLinejoin = this.wireframeLineJoin;
this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS; this.instance.vertexColors = this.vertexColors;
this.instance.skinning = this.skinning; this.instance.skinning = this.skinning;
this.instance.morphTargets = this.morphTargets; this.instance.morphTargets = this.morphTargets;
this.instance.morphNormals = this.morphNormals; this.instance.morphNormals = this.morphNormals;
@ -908,7 +908,7 @@ GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function(propert
this.instance.visible = this.visible; this.instance.visible = this.visible;
this.instance.side = this.side; this.instance.side = this.side;
this.instance.color = this.color.instance; this.instance.color = this.color.instance;
this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS; this.instance.vertexColors = this.vertexColors;
this.instance.fog = this.fog; this.instance.fog = this.fog;
}; };
@ -994,6 +994,16 @@ GameLib.D3.Material.prototype.updateInstance = function(property) {
this.updateTextures(); this.updateTextures();
} }
if (property === 'emissive') {
this.emissive.instance.r = this.emissive.r;
this.emissive.instance.g = this.emissive.g;
this.emissive.instance.b = this.emissive.b;
this.instance.emissive.copy(this.emissive.instance);
return;
}
if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_STANDARD) { if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
this.updateStandardMaterialInstance(property); this.updateStandardMaterialInstance(property);
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_POINTS) { } else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_POINTS) {

View File

@ -372,41 +372,18 @@ GameLib.D3.Mesh.prototype.createInstanceGeometry = function(instanceGeometry) {
standardUvs.push( standardUvs.push(
face.uvs[0].map( face.uvs[0].map(
function(uv) { function(uv) {
return new THREE.Vector2( return uv.instance;
uv.x,
uv.y
)
} }
) )
); );
} }
var faceInstance = new THREE.Face3( if (!face.instance) {
face.v0index, face.createInstance(this);
face.v1index, }
face.v2index
);
if (face.normal) { return face.instance;
faceInstance.normal = new THREE.Vector3( }.bind(this)
face.normal.x,
face.normal.y,
face.normal.z
);
}
if (face.color) {
faceInstance.color = new THREE.Color(
face.color.r,
face.color.g,
face.color.b
)
}
faceInstance.materialIndex = face.materialIndex;
return faceInstance;
}
); );
/** /**

View File

@ -180,7 +180,9 @@ GameLib.D3.Raycaster.prototype.getIntersectedObjects = function(meshes) {
result.push( result.push(
{ {
mesh: mesh, mesh: mesh,
distance : intersects[0].distance distance : intersects[0].distance,
face: mesh.faces[intersects[0].faceIndex],
faceIndex: intersects[0].faceIndex
} }
); );
} }

View File

@ -29,7 +29,7 @@ GameLib.Mouse.prototype.constructor = GameLib.Mouse;
* createInstance * createInstance
*/ */
GameLib.Mouse.prototype.createInstance = function() { GameLib.Mouse.prototype.createInstance = function() {
this.instance = true; this.instance = {};
GameLib.Component.prototype.createInstance.call(this); GameLib.Component.prototype.createInstance.call(this);
}; };
@ -38,9 +38,15 @@ GameLib.Mouse.prototype.createInstance = function() {
* @param property * @param property
*/ */
GameLib.Mouse.prototype.updateInstance = function(property) { GameLib.Mouse.prototype.updateInstance = function(property) {
if (GameLib.Utils.UndefinedOrNull(property)) {
console.warn('unknown property update for Mouse: ' + property); if (property === 'x') {
this.instance.x = this.x;
} }
if (property === 'y') {
this.instance.y = this.y;
}
}; };
/** /**
@ -56,15 +62,3 @@ GameLib.Mouse.prototype.toApiObject = function() {
this.parentEntity this.parentEntity
); );
}; };
/**
* GameLib.Mouse from Object
* @param objectMouse
* @returns {GameLib.Mouse}
* @constructor
*/
GameLib.Mouse.FromObject = function(objectMouse) {
return new GameLib.Mouse(
GameLib.API.Mouse.FromObject(objectMouse)
);
};

View File

@ -22,6 +22,8 @@ GameLib.System.GUI = function(
*/ */
this.backupComponents = []; this.backupComponents = [];
this.faces = [];
this.exclusiveMode = false; this.exclusiveMode = false;
this.buildGUISubscription = null; this.buildGUISubscription = null;
@ -43,7 +45,11 @@ GameLib.System.GUI = function(
this.removeComponentSubscription = null; this.removeComponentSubscription = null;
this.windowResizeSubscription = null; this.windowResizeSubscription = null;
this.meshFaceSelectedSubscription = null;
this.meshFaceDeselectedSubscription = null;
}; };
GameLib.System.GUI.prototype = Object.create(GameLib.System.prototype); GameLib.System.GUI.prototype = Object.create(GameLib.System.prototype);
@ -112,6 +118,16 @@ GameLib.System.GUI.prototype.start = function() {
this.windowResize.bind(this) this.windowResize.bind(this)
); );
this.meshFaceSelectedSubscription = GameLib.Event.Subscribe(
GameLib.Event.MESH_FACE_SELECTED,
this.meshFaceSelected.bind(this)
);
this.meshFaceDeselectedSubscription = GameLib.Event.Subscribe(
GameLib.Event.MESH_FACE_DESELECTED,
this.meshFaceDeselected.bind(this)
);
this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.GUI); this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.GUI);
this.guis.map( this.guis.map(
function(gui){ function(gui){
@ -539,14 +555,14 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp
}; };
GameLib.System.GUI.prototype.buildArrayManagerControl = function( GameLib.System.GUI.prototype.buildArrayManagerControl = function(
folder, folder,
componentTemplate, componentTemplate,
property property
) { ) {
var constructors = componentTemplate.template.linkedObjects[property]; var constructors = componentTemplate.template.linkedObjects[property];
if (constructors instanceof Array) { if (constructors instanceof Array) {
/** /**
* All good * All good
*/ */
@ -558,49 +574,49 @@ GameLib.System.GUI.prototype.buildArrayManagerControl = function(
return; return;
} }
var object = componentTemplate.template; var object = componentTemplate.template;
var array = object[property]; var array = object[property];
var addArrayItem = function(item, index){ var addArrayItem = function(item, index){
var name = 'invalid item'; var name = 'invalid item';
if (item && item.name) { if (item && item.name) {
name = item.name; name = item.name;
} }
var controller = folder.add( var controller = folder.add(
{ {
'remove' : function() { 'remove' : function() {
componentTemplate.affected.map(function(component){ componentTemplate.affected.map(function(component){
component[property].splice(index, 1); component[property].splice(index, 1);
folder.remove(controller); folder.remove(controller);
}); });
} }
}, },
'remove' 'remove'
).name('remove ' + property + '[' + index + '] - ' + name); ).name('remove ' + property + '[' + index + '] - ' + name);
folder.updateDisplay(); folder.updateDisplay();
}; };
array.map(addArrayItem); array.map(addArrayItem);
var idObject = {}; var idObject = {};
var selectionObject = GameLib.EntityManager.Instance.queryComponentsByConstructor(constructors).reduce( var selectionObject = GameLib.EntityManager.Instance.queryComponentsByConstructor(constructors).reduce(
function(result, component) { function(result, component) {
result[component.name] = component; result[component.name] = component;
idObject[component.id] = component; idObject[component.id] = component;
return result; return result;
}, },
{ {
'none' : null 'none' : null
} }
); );
var activeSelection = { var activeSelection = {
component: null, component: null,
add: function () { add: function () {
@ -629,17 +645,60 @@ GameLib.System.GUI.prototype.buildArrayManagerControl = function(
} }
}; };
folder.add(activeSelection, 'component', selectionObject).name('select ' + property).onChange( folder.add(activeSelection, 'component', selectionObject).name('select ' + property).onChange(
function(value){ function(value){
if (value === 'null') { if (value === 'null') {
activeSelection['component'] = null; activeSelection['component'] = null;
} else { } else {
activeSelection['component'] = idObject[value]; activeSelection['component'] = idObject[value];
} }
} }
).listen(); ).listen();
folder.add(activeSelection, 'add').name('add to ' + property);
};
/**
* This is only for uvs right now
*/
GameLib.System.GUI.prototype.buildUVManagerControl = function(
folder,
componentTemplate,
property
) {
var object = componentTemplate.template;
var array = object[property];
array.map(
function(uvs, uvSet) {
/**
* uvs should be an array of three vector2's
*/
uvs.map(
function(uv, uvIndex) {
var onChange = function(__uvSet, __uvIndex, __property) {
return function(value) {
componentTemplate.affected.map(
function (component) {
component.uvs[__uvSet][__uvIndex][__property] = value;
component.updateInstance('uvs', __uvSet, __uvIndex);
}
);
}
};
folder.add(uv, 'x').name('uvs[' + uvSet + '][' + uvIndex +'].x').onChange(onChange(uvSet, uvIndex, 'x')).listen();
folder.add(uv, 'y').name('uvs[' + uvSet + '][' + uvIndex +'].y').onChange(onChange(uvSet, uvIndex, 'y')).listen();
}
)
}
);
folder.add(activeSelection, 'add').name('add to ' + property);
}; };
@ -1566,6 +1625,33 @@ GameLib.System.GUI.prototype.meshDeslected = function(data) {
}; };
GameLib.System.GUI.prototype.meshFaceSelected = function(data) {
this.faces.push(data.face);
this.buildGUI({
components : this.faces
})
};
GameLib.System.GUI.prototype.meshFaceDeselected = function(data) {
var index = this.faces.indexOf(data.face);
if (index !== -1) {
this.faces.splice(index, 1);
if (this.faces.length === 0) {
this.buildGUI({});
} else {
this.buildGUI({components : this.faces})
}
} else {
console.warn('could not remove face');
}
};
/** /**
* This function responds to the BUILD_GUI event, data contains the components to build a GUI for data. * This function responds to the BUILD_GUI event, data contains the components to build a GUI for data.
* *
@ -1938,6 +2024,10 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
continue; continue;
} }
if (templateProperty === 'uvs') {
this.buildUVManagerControl(folder, componentTemplate, templateProperty);
}
if ( if (
componentTemplate.template.linkedObjects && componentTemplate.template.linkedObjects &&
componentTemplate.template.linkedObjects[templateProperty] instanceof Array componentTemplate.template.linkedObjects[templateProperty] instanceof Array
@ -2045,6 +2135,10 @@ GameLib.System.GUI.prototype.stop = function() {
this.windowResizeSubscription.remove(); this.windowResizeSubscription.remove();
this.meshFaceSelectedSubscription.remove();
this.meshFaceDeselectedSubscription.remove();
this.guis = []; this.guis = [];
}; };

View File

@ -62,7 +62,10 @@ GameLib.System.Input = function(
this.delayedInstanceEncounteredSubscription = null; this.delayedInstanceEncounteredSubscription = null;
this.instanceCreatedSubscription = null; this.instanceCreatedSubscription = null;
this.removeComponentSubscription = null; this.removeComponentSubscription = null;
this.domElementChangeSubscription = null; this.canvasChangeSubscription = null;
this.selectionModeChangeSubscription = null;
this.selectionMode = GameLib.System.Input.SELECTION_MODE_DEFAULT;
this.mouse = new GameLib.Mouse(); this.mouse = new GameLib.Mouse();
}; };
@ -70,6 +73,10 @@ GameLib.System.Input = function(
GameLib.System.Input.prototype = Object.create(GameLib.System.prototype); GameLib.System.Input.prototype = Object.create(GameLib.System.prototype);
GameLib.System.Input.prototype.constructor = GameLib.System.Input; GameLib.System.Input.prototype.constructor = GameLib.System.Input;
GameLib.System.Input.SELECTION_MODE_MESH = 0x1;
GameLib.System.Input.SELECTION_MODE_FACE = 0x2;
GameLib.System.Input.SELECTION_MODE_DEFAULT = 0x1;
/** /**
* *
*/ */
@ -92,9 +99,14 @@ GameLib.System.Input.prototype.start = function() {
this.delayedInstanceEncountered.bind(this) this.delayedInstanceEncountered.bind(this)
); );
this.domElementChangeSubscription = GameLib.Event.Subscribe( this.canvasChangeSubscription = GameLib.Event.Subscribe(
GameLib.Event.DOM_ELEMENT_CHANGE, GameLib.Event.CANVAS_CHANGE,
this.domElementChange.bind(this) this.canvasChange.bind(this)
);
this.selectionModeChangeSubscription = GameLib.Event.Subscribe(
GameLib.Event.SELECTION_MODE_CHANGE,
this.selectionModeChange.bind(this)
); );
this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_EDITOR); this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CONTROLS_EDITOR);
@ -147,7 +159,9 @@ GameLib.System.Input.prototype.stop = function() {
this.delayedInstanceEncounteredSubscription.remove(); this.delayedInstanceEncounteredSubscription.remove();
this.domElementChangeSubscription.remove(); this.canvasChangeSubscription.remove();
this.selectionModeChangeSubscription.remove();
this.touchControls.map( this.touchControls.map(
function(touchControl){ function(touchControl){
@ -187,12 +201,20 @@ GameLib.System.Input.prototype.stop = function() {
* *
* @param data * @param data
*/ */
GameLib.System.Input.prototype.domElementChange = function(data) { GameLib.System.Input.prototype.canvasChange = function(data) {
if (data.component instanceof GameLib.Controls) { if (data.component instanceof GameLib.Controls) {
console.log('todo: implement dom element change'); console.log('todo: implement dom element change');
} }
}; };
/**
* Changes the selection mode from face to mesh etc.
* @param data
*/
GameLib.System.Input.prototype.selectionModeChange = function(data) {
this.selectionMode = data.selectionMode;
};
/** /**
* From now on we want to track everything about a component, only from the systems that are active * From now on we want to track everything about a component, only from the systems that are active
* @param data * @param data
@ -330,28 +352,28 @@ GameLib.System.Input.prototype.delayedInstanceEncountered = function(data) {
GameLib.System.Input.prototype.registerTouchControls = function(touchControl) { GameLib.System.Input.prototype.registerTouchControls = function(touchControl) {
if (!touchControl.domElement || !touchControl.domElement.instance) { if (!touchControl.canvas || !touchControl.canvas.instance) {
console.warn('no domElement at time of registration of touch controls - this part will be skipped'); console.warn('no canvas at time of registration of touch controls - this part will be skipped');
return; return;
} }
touchControl.domElement.instance.addEventListener( touchControl.canvas.instance.addEventListener(
'touchstart', 'touchstart',
this.touchStart, this.touchStart,
true true
); );
touchControl.domElement.instance.addEventListener( touchControl.canvas.instance.addEventListener(
'touchmove', 'touchmove',
this.touchMove, this.touchMove,
true true
); );
touchControl.domElement.instance.addEventListener( touchControl.canvas.instance.addEventListener(
'touchend', 'touchend',
this.touchEnd, this.touchEnd,
true true
); );
touchControl.domElement.instance.addEventListener( touchControl.canvas.instance.addEventListener(
'touchcancel', 'touchcancel',
this.touchCancel, this.touchCancel,
true true
@ -360,18 +382,18 @@ GameLib.System.Input.prototype.registerTouchControls = function(touchControl) {
GameLib.System.Input.prototype.registerKeyboardControls = function(keyboardControl) { GameLib.System.Input.prototype.registerKeyboardControls = function(keyboardControl) {
if (!keyboardControl.domElement || !keyboardControl.domElement.instance) { if (!keyboardControl.canvas || !keyboardControl.canvas.instance) {
console.warn('no domElement at time of registration of keyboard controls - this part will be skipped'); console.warn('no canvas at time of registration of keyboard controls - this part will be skipped');
return; return;
} }
keyboardControl.domElement.instance.addEventListener( keyboardControl.canvas.instance.addEventListener(
'keyup', 'keyup',
this.keyboardKeyUp, this.keyboardKeyUp,
true true
); );
keyboardControl.domElement.instance.addEventListener( keyboardControl.canvas.instance.addEventListener(
'keydown', 'keydown',
this.keyboardKeyDown, this.keyboardKeyDown,
true true
@ -380,30 +402,30 @@ GameLib.System.Input.prototype.registerKeyboardControls = function(keyboardContr
GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) { GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) {
if (!mouseControl.domElement || !mouseControl.domElement.instance) { if (!mouseControl.canvas || !mouseControl.canvas.instance) {
console.warn('no domElement at time of registration of mouse controls - this part will be skipped'); console.warn('no canvas at time of registration of mouse controls - this part will be skipped');
return; return;
} }
mouseControl.domElement.instance.addEventListener( mouseControl.canvas.instance.addEventListener(
'mousedown', 'mousedown',
this.mouseDown, this.mouseDown,
false false
); );
mouseControl.domElement.instance.addEventListener( mouseControl.canvas.instance.addEventListener(
'mousemove', 'mousemove',
this.mouseMove, this.mouseMove,
false false
); );
mouseControl.domElement.instance.addEventListener( mouseControl.canvas.instance.addEventListener(
'wheel', 'wheel',
this.mouseWheel, this.mouseWheel,
false false
); );
mouseControl.domElement.instance.addEventListener( mouseControl.canvas.instance.addEventListener(
'mouseup', 'mouseup',
this.mouseUp, this.mouseUp,
false false
@ -422,7 +444,7 @@ GameLib.System.Input.prototype.registerEditorControls = function(editorControl)
*/ */
// this.mouseControls.map( // this.mouseControls.map(
// function(mouseControl) { // function(mouseControl) {
// if (mouseControl.domElement.instance === editorControl.domElement.instance) { // if (mouseControl.canvas.instance === editorControl.canvas.instance) {
// this.deRegisterMouseControls(mouseControl); // this.deRegisterMouseControls(mouseControl);
// } // }
// }.bind(this) // }.bind(this)
@ -433,36 +455,36 @@ GameLib.System.Input.prototype.registerEditorControls = function(editorControl)
*/ */
this.keyboardControls.map( this.keyboardControls.map(
function(keyboardControl) { function(keyboardControl) {
if (keyboardControl.domElement.instance === editorControl.domElement.instance) { if (keyboardControl.canvas.instance === editorControl.canvas.instance) {
this.deRegisterKeyboardControls(keyboardControl); this.deRegisterKeyboardControls(keyboardControl);
} }
}.bind(this) }.bind(this)
); );
if (!editorControl.domElement || !editorControl.domElement.instance) { if (!editorControl.canvas || !editorControl.canvas.instance) {
console.warn('no domElement at time of registration of editor controls - are you sure you know what you are doing?'); console.warn('no canvas at time of registration of editor controls - are you sure you know what you are doing?');
return; return;
} }
editorControl.domElement.instance.addEventListener( editorControl.canvas.instance.addEventListener(
'mousedown', 'mousedown',
this.mouseDownEdit, this.mouseDownEdit,
true true
); );
editorControl.domElement.instance.addEventListener( editorControl.canvas.instance.addEventListener(
'mousemove', 'mousemove',
this.mouseMoveEdit, this.mouseMoveEdit,
true true
); );
editorControl.domElement.instance.addEventListener( editorControl.canvas.instance.addEventListener(
'keydown', 'keydown',
this.keyDown, this.keyDown,
true true
); );
editorControl.domElement.instance.addEventListener( editorControl.canvas.instance.addEventListener(
'keyup', 'keyup',
this.keyUp, this.keyUp,
true true
@ -473,13 +495,13 @@ GameLib.System.Input.prototype.registerEditorControls = function(editorControl)
*/ */
editorControl.createInstance(); editorControl.createInstance();
editorControl.domElement.instance.addEventListener( editorControl.canvas.instance.addEventListener(
'wheel', 'wheel',
this.mouseWheelEdit, this.mouseWheelEdit,
true true
); );
editorControl.domElement.instance.addEventListener( editorControl.canvas.instance.addEventListener(
'mouseup', 'mouseup',
this.mouseUpEdit, this.mouseUpEdit,
true true
@ -488,25 +510,25 @@ GameLib.System.Input.prototype.registerEditorControls = function(editorControl)
GameLib.System.Input.prototype.deRegisterEditorControls = function(editorControl) { GameLib.System.Input.prototype.deRegisterEditorControls = function(editorControl) {
editorControl.domElement.instance.removeEventListener( editorControl.canvas.instance.removeEventListener(
'mousedown', 'mousedown',
this.mouseDownEdit, this.mouseDownEdit,
true true
); );
editorControl.domElement.instance.removeEventListener( editorControl.canvas.instance.removeEventListener(
'mousemove', 'mousemove',
this.mouseMoveEdit, this.mouseMoveEdit,
true true
); );
editorControl.domElement.instance.removeEventListener( editorControl.canvas.instance.removeEventListener(
'keydown', 'keydown',
this.keyDown, this.keyDown,
true true
); );
editorControl.domElement.instance.removeEventListener( editorControl.canvas.instance.removeEventListener(
'keyup', 'keyup',
this.keyUp, this.keyUp,
true true
@ -514,13 +536,13 @@ GameLib.System.Input.prototype.deRegisterEditorControls = function(editorControl
editorControl.instance.dispose(); editorControl.instance.dispose();
editorControl.domElement.instance.removeEventListener( editorControl.canvas.instance.removeEventListener(
'wheel', 'wheel',
this.mouseWheelEdit, this.mouseWheelEdit,
true true
); );
editorControl.domElement.instance.removeEventListener( editorControl.canvas.instance.removeEventListener(
'mouseup', 'mouseup',
this.mouseUpEdit, this.mouseUpEdit,
true true
@ -530,25 +552,25 @@ GameLib.System.Input.prototype.deRegisterEditorControls = function(editorControl
GameLib.System.Input.prototype.deRegisterTouchControls = function(touchControl) { GameLib.System.Input.prototype.deRegisterTouchControls = function(touchControl) {
touchControl.domElement.instance.removeEventListener( touchControl.canvas.instance.removeEventListener(
'touchstart', 'touchstart',
this.touchStart, this.touchStart,
true true
); );
touchControl.domElement.instance.removeEventListener( touchControl.canvas.instance.removeEventListener(
'touchmove', 'touchmove',
this.touchMove, this.touchMove,
true true
); );
touchControl.domElement.instance.removeEventListener( touchControl.canvas.instance.removeEventListener(
'touchend', 'touchend',
this.touchEnd, this.touchEnd,
true true
); );
touchControl.domElement.instance.removeEventListener( touchControl.canvas.instance.removeEventListener(
'touchcancel', 'touchcancel',
this.touchCancel, this.touchCancel,
true true
@ -558,13 +580,13 @@ GameLib.System.Input.prototype.deRegisterTouchControls = function(touchControl)
GameLib.System.Input.prototype.deRegisterKeyboardControls = function(keyboardControl) { GameLib.System.Input.prototype.deRegisterKeyboardControls = function(keyboardControl) {
keyboardControl.domElement.instance.removeEventListener( keyboardControl.canvas.instance.removeEventListener(
'keydown', 'keydown',
this.keyboardKeyDown, this.keyboardKeyDown,
true true
); );
keyboardControl.domElement.instance.removeEventListener( keyboardControl.canvas.instance.removeEventListener(
'keyup', 'keyup',
this.keyboardKeyUp, this.keyboardKeyUp,
true true
@ -575,25 +597,25 @@ GameLib.System.Input.prototype.deRegisterKeyboardControls = function(keyboardCon
GameLib.System.Input.prototype.deRegisterMouseControls = function(mouseControl) { GameLib.System.Input.prototype.deRegisterMouseControls = function(mouseControl) {
mouseControl.domElement.instance.removeEventListener( mouseControl.canvas.instance.removeEventListener(
'mousedown', 'mousedown',
this.mouseDown, this.mouseDown,
false false
); );
mouseControl.domElement.instance.removeEventListener( mouseControl.canvas.instance.removeEventListener(
'mousemove', 'mousemove',
this.mouseMove, this.mouseMove,
false false
); );
mouseControl.domElement.instance.removeEventListener( mouseControl.canvas.instance.removeEventListener(
'wheel', 'wheel',
this.mouseWheel, this.mouseWheel,
false false
); );
mouseControl.domElement.instance.removeEventListener( mouseControl.canvas.instance.removeEventListener(
'mouseup', 'mouseup',
this.mouseUp, this.mouseUp,
false false
@ -859,15 +881,20 @@ GameLib.System.Input.prototype.onKeyDown = function(event) {
this.selectAll = !this.selectAll; this.selectAll = !this.selectAll;
meshes = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh); if (this.selectionMode === GameLib.System.Input.SELECTION_MODE_MESH) {
meshes.map(function(mesh){ meshes = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh);
if (this.selectAll) {
this.selectMesh(mesh); meshes.map(function (mesh) {
} else { if (this.selectAll) {
this.deSelectMesh(mesh); this.selectMesh(mesh);
} } else {
}.bind(this)); this.deselectMesh(mesh);
}
}.bind(this));
} else {
console.warn('todo: implement face select all');
}
GameLib.Event.Emit( GameLib.Event.Emit(
GameLib.Event.BUILD_GUI, GameLib.Event.BUILD_GUI,
@ -950,74 +977,96 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) {
this.mouse.x = (event.offsetX / event.target.width ) * 2 - 1; this.mouse.x = (event.offsetX / event.target.width ) * 2 - 1;
this.mouse.y = -(event.offsetY / event.target.height) * 2 + 1; this.mouse.y = -(event.offsetY / event.target.height) * 2 + 1;
var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE); var renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER);
var intersects = scenes.reduce( renderers.map(
function(renderer) {
function (result, scene) { var intersects = renderer.scenes.reduce(
editorControl.raycaster.instance.setFromCamera( function (result, scene) {
this.mouse,
editorControl.camera.instance editorControl.raycaster.setFromCamera(
this.mouse,
renderer.editCamera
);
intersects = editorControl.raycaster.getIntersectedObjects(scene.meshes);
intersects.map(function (intersect) {
result.push(intersect);
});
return result;
}.bind(this),
[]
); );
intersects = editorControl.raycaster.getIntersectedObjects(scene.meshes); if (intersects.length < 1) {
return;
intersects.map(function (intersect) {
result.push(intersect);
});
return result;
}.bind(this),
[]
);
intersects.sort(
function (a, b) {
if (a.distance < b.distance) {
return -1;
} }
if (a.distance > b.distance) { /**
return 1; * Find the closest intersected mesh
*/
intersects.sort(
function (a, b) {
if (a.distance < b.distance) {
return -1;
}
if (a.distance > b.distance) {
return 1;
}
return 0;
}
);
var mesh = intersects[0].mesh;
var face = intersects[0].face;
var faceIndex = intersects[0].faceIndex;
/**
* Prevent default action (like context menu or whatever)
*/
event.preventDefault();
/**
* Prevent other event listeners for 'mousedown' from executing their actions
*/
event.stopImmediatePropagation();
if (this.selectionMode === GameLib.System.Input.SELECTION_MODE_MESH) {
if (mesh.selected) {
this.deselectMesh(mesh);
} else {
this.selectMesh(mesh);
}
} else {
if (face.selected) {
this.deselectFace(mesh, face);
} else {
this.selectFace(mesh, face);
}
} }
return 0; /**
} * Notify our GUI system to build a GUI
*/
GameLib.Event.Emit(
GameLib.Event.BUILD_GUI,
null
)
}.bind(this)
); );
var meshes = intersects.map(function (intersect) {
return intersect.mesh;
});
var mesh = meshes[0];
if (mesh) {
/**
* Prevent default action (like context menu or whatever)
*/
event.preventDefault();
/**
* Prevent other event listeners for 'mousedown' from executing their actions
*/
event.stopImmediatePropagation();
if (mesh.selected) {
this.deSelectMesh(mesh);
} else {
this.selectMesh(mesh);
}
/**
* Notify our GUI system to build a GUI
*/
GameLib.Event.Emit(
GameLib.Event.BUILD_GUI,
null
)
}
}.bind(this) }.bind(this)
); );
} }
@ -1028,7 +1077,12 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) {
* @param event * @param event
*/ */
GameLib.System.Input.prototype.onMouseMoveEdit = function(event) { GameLib.System.Input.prototype.onMouseMoveEdit = function(event) {
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MOUSE).map(
function(mouse) {
mouse.x = event.clientX;
mouse.y = event.clientY;
}
)
}; };
/** /**
@ -1071,6 +1125,32 @@ GameLib.System.Input.prototype.onMouseWheelEdit = function(event) {
); );
}; };
GameLib.System.Input.prototype.selectFace = function(mesh, face) {
/**
* If mesh is already selected, do nothing
*/
if (face.selected === true) {
return;
}
/**
* Notify our component as being 'selected'
* @type {boolean}
*/
face.selected = true;
face.createHelper(mesh);
GameLib.Event.Emit(
GameLib.Event.MESH_FACE_SELECTED,
{
mesh : mesh,
face : face
}
);
};
GameLib.System.Input.prototype.selectMesh = function(mesh) { GameLib.System.Input.prototype.selectMesh = function(mesh) {
/** /**
@ -1096,7 +1176,22 @@ GameLib.System.Input.prototype.selectMesh = function(mesh) {
); );
}; };
GameLib.System.Input.prototype.deSelectMesh = function(mesh) { GameLib.System.Input.prototype.deselectFace = function(mesh, face) {
face.selected = false;
face.removeHelper(mesh);
GameLib.Event.Emit(
GameLib.Event.MESH_FACE_DESELECTED,
{
mesh : mesh,
face : face
}
);
};
GameLib.System.Input.prototype.deselectMesh = function(mesh) {
mesh.selected = false; mesh.selected = false;

View File

@ -380,7 +380,7 @@ GameLib.System.Render.prototype.stop = function() {
function(renderer) { function(renderer) {
if (renderer.statistics) { if (renderer.statistics) {
renderer.statistics.resize(); renderer.statistics.resize();
renderer.domElement.instance.parentElement.removeChild(renderer.statistics.instance.dom); renderer.canvas.instance.parentElement.removeChild(renderer.statistics.instance.dom);
} }
} }
); );