fonts, text meshes, lines, input system refactorings

beta.r3js.org
-=yb4f310 2017-10-08 03:17:36 +02:00
parent 79b809996d
commit c3475ccef7
19 changed files with 949 additions and 374 deletions

View File

@ -99,6 +99,10 @@ GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
GameLib.Event.ANIMATION_MESH_REMOVED = 0x52; GameLib.Event.ANIMATION_MESH_REMOVED = 0x52;
GameLib.Event.GET_SCENE = 0x53; GameLib.Event.GET_SCENE = 0x53;
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54; GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
GameLib.Event.LOAD_FONT = 0x55;
GameLib.Event.FONT_NOT_FOUND = 0x56;
GameLib.Event.FONT_INSTANCE_CREATED = 0x57;
GameLib.Event.REGISTER_DEPENDENCIES = 0x58;
/** /**
* Returns string name of event ID * Returns string name of event ID
@ -193,6 +197,10 @@ GameLib.Event.GetEventName = function(number) {
case 0x52 : return 'animation_mesh_removed'; case 0x52 : return 'animation_mesh_removed';
case 0x53 : return 'get_scene'; case 0x53 : return 'get_scene';
case 0x54 : return 'custom_code_window_resize'; case 0x54 : return 'custom_code_window_resize';
case 0x55 : return 'load_font';
case 0x56 : return 'font_not_found';
case 0x57 : return 'font_instance_created';
case 0x58 : return 'register_dependencies';
break; break;
} }

View File

@ -37,6 +37,13 @@ GameLib.Component = function(
} }
); );
// GameLib.Event.Emit(
// GameLib.Event.COMPONENT_CREATED,
// {
// component : this
// }
// );
if (this.dependencies.length === 0) { if (this.dependencies.length === 0) {
delete this.dependencies; delete this.dependencies;
@ -48,6 +55,13 @@ GameLib.Component = function(
this.buildIdToObject(); this.buildIdToObject();
GameLib.Event.EmitInstanceEvents(this); GameLib.Event.EmitInstanceEvents(this);
} }
} else {
GameLib.Event.Emit(
GameLib.Event.REGISTER_DEPENDENCIES,
{
component : this
}
);
} }
@ -76,16 +90,33 @@ GameLib.Component.prototype.getDependencies = function() {
this.hasOwnProperty(property) this.hasOwnProperty(property)
){ ){
if (typeof this[property] === 'string') { if (typeof this[property] === 'string') {
dependencies.push(this[property]); GameLib.Utils.PushUnique(dependencies, this[property]);
} }
if (this[property] instanceof Array) { if (this[property] instanceof Array) {
this[property].map(function(arrayProperty){ this[property].map(function(arrayProperty){
if (typeof arrayProperty === 'string') {
dependencies.push(arrayProperty); if (typeof arrayProperty === 'string') {
GameLib.Utils.PushUnique(dependencies, arrayProperty);
} }
if (arrayProperty &&
typeof arrayProperty === 'object' &&
arrayProperty.hasOwnProperty('loaded') &&
arrayProperty.loaded === false
) {
GameLib.Utils.PushUnique(dependencies, arrayProperty.id);
}
}); });
} }
if (this[property] &&
typeof this[property] === 'object' &&
this[property].hasOwnProperty('loaded') &&
this[property].loaded === false
) {
GameLib.Utils.PushUnique(dependencies, this[property].id);
}
} }
} }
@ -154,6 +185,8 @@ GameLib.Component.COMPONENT_CLOCK = 0x37;
GameLib.Component.COMPONENT_ANIMATION = 0x38; GameLib.Component.COMPONENT_ANIMATION = 0x38;
GameLib.Component.COMPONENT_CONTROLS_KEYBOARD = 0x39; GameLib.Component.COMPONENT_CONTROLS_KEYBOARD = 0x39;
GameLib.Component.COMPONENT_CONTROLS_MOUSE = 0x3a; GameLib.Component.COMPONENT_CONTROLS_MOUSE = 0x3a;
GameLib.Component.COMPONENT_MESH_TEXT = 0x3b;
GameLib.Component.COMPONENT_FONT = 0x3c;
/** /**
* Returns string name for component number * Returns string name for component number
@ -221,6 +254,8 @@ GameLib.Component.GetComponentName = function(number) {
case 0x38 : return 'GameLib.D3.Animation'; case 0x38 : return 'GameLib.D3.Animation';
case 0x39 : return 'GameLib.D3.Controls.Keyboard'; case 0x39 : return 'GameLib.D3.Controls.Keyboard';
case 0x3a : return 'GameLib.D3.Controls.Mouse'; case 0x3a : return 'GameLib.D3.Controls.Mouse';
case 0x3b : return 'GameLib.D3.Mesh.Text';
case 0x3c : return 'GameLib.D3.Font';
break; break;
} }

View File

@ -0,0 +1,51 @@
/**
* Raw Font API object - should always correspond with the Font Schema
* @param id
* @param name
* @param url
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Font = function(
id,
name,
url,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Font (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(url)) {
url = '/apiRelative/path/to/font';
}
this.url = url;
if (GameLib.Utils.UndefinedOrNull(parentEntity)){
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Font.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Font.prototype.constructor = GameLib.D3.API.Font;
/**
* Returns an API light from an Object light
* @param objectFont
* @constructor
*/
GameLib.D3.API.Font.FromObject = function(objectFont) {
return new GameLib.D3.API.Font(
objectFont.id,
objectFont.name,
objectFont.url,
objectFont.parentEntity
);
};

View File

@ -81,7 +81,7 @@ GameLib.D3.API.Light = function(
this.intensity = intensity; this.intensity = intensity;
if (GameLib.Utils.UndefinedOrNull(position)) { if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3(0,10,0); position = new GameLib.API.Vector3(10,10,10);
} }
this.position = position; this.position = position;

View File

@ -3,15 +3,10 @@
* @param id String * @param id String
* @param name String * @param name String
* @param meshes [GameLib.D3.API.Mesh] * @param meshes [GameLib.D3.API.Mesh]
* @param position GameLib.API.Vector3
* @param quaternion GameLib.API.Quaternion
* @param scale GameLib.API.Vector3
* @param parentGameId
* @param lights [GameLib.D3.API.Light] * @param lights [GameLib.D3.API.Light]
* @param textures [GameLib.D3.API.Texture] * @param textures [GameLib.D3.API.Texture]
* @param materials [GameLib.D3.API.Material] * @param materials [GameLib.D3.API.Material]
* @param images * @param images
* @param activeCamera [GameLib.D3.Camera]
* @param parentEntity * @param parentEntity
* @constructor * @constructor
*/ */
@ -19,15 +14,10 @@ GameLib.D3.API.Scene = function(
id, id,
name, name,
meshes, meshes,
position,
quaternion,
scale,
parentGameId,
lights, lights,
textures, textures,
materials, materials,
images, images,
activeCamera,
parentEntity parentEntity
) { ) {
@ -46,26 +36,6 @@ GameLib.D3.API.Scene = function(
} }
this.meshes = meshes; this.meshes = meshes;
if (GameLib.Utils.UndefinedOrNull(position)) {
position = new GameLib.API.Vector3();
}
this.position = position;
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
quaternion = new GameLib.API.Quaternion();
}
this.quaternion = quaternion;
if (GameLib.Utils.UndefinedOrNull(scale)) {
scale = new GameLib.API.Vector3(1,1,1);
}
this.scale = scale;
if (GameLib.Utils.UndefinedOrNull(parentGameId)) {
parentGameId = null;
}
this.parentGameId = parentGameId;
if (GameLib.Utils.UndefinedOrNull(lights)) { if (GameLib.Utils.UndefinedOrNull(lights)) {
lights = []; lights = [];
} }
@ -86,11 +56,6 @@ GameLib.D3.API.Scene = function(
} }
this.images = images; this.images = images;
if (GameLib.Utils.UndefinedOrNull(activeCamera)) {
activeCamera = null;
}
this.activeCamera = activeCamera;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) { if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null; parentEntity = null;
} }
@ -114,12 +79,6 @@ GameLib.D3.API.Scene.FromObject = function(objectScene) {
var apiMaterials = []; var apiMaterials = [];
var apiImages = []; var apiImages = [];
var apiPosition = new GameLib.API.Vector3();
var apiQuaternion = new GameLib.API.Quaternion();
var apiScale = new GameLib.API.Vector3(1,1,1);
var apiActiveCamera = null;
if (objectScene.meshes) { if (objectScene.meshes) {
apiMeshes = objectScene.meshes.map( apiMeshes = objectScene.meshes.map(
function(objectMesh) { function(objectMesh) {
@ -180,35 +139,14 @@ GameLib.D3.API.Scene.FromObject = function(objectScene) {
) )
} }
if (objectScene.position) {
apiPosition = GameLib.API.Vector3.FromObject(objectScene.position);
}
if (objectScene.quaternion) {
apiQuaternion = GameLib.API.Quaternion.FromObject(objectScene.quaternion);
}
if (objectScene.scale) {
apiScale = GameLib.API.Vector3.FromObject(objectScene.scale);
}
if (objectScene.activeCamera) {
apiActiveCamera = objectScene.activeCamera;
}
return new GameLib.D3.API.Scene( return new GameLib.D3.API.Scene(
objectScene.id, objectScene.id,
objectScene.name, objectScene.name,
apiMeshes, apiMeshes,
apiPosition,
apiQuaternion,
apiScale,
objectScene.parentGameId,
apiLights, apiLights,
apiTextures, apiTextures,
apiMaterials, apiMaterials,
apiImages, apiImages,
apiActiveCamera,
objectScene.parentEntity objectScene.parentEntity
); );

View File

@ -38,8 +38,8 @@ GameLib.D3.Controls = function (
componentType = GameLib.Component.COMPONENT_CONTROLS_EDITOR; componentType = GameLib.Component.COMPONENT_CONTROLS_EDITOR;
linkedObjects.raycaster = GameLib.D3.Raycaster; linkedObjects.raycaster = GameLib.D3.Raycaster;
linkedObjects.renderer = GameLib.D3.Renderer; linkedObjects.camera = GameLib.D3.Camera;
} }
if (this.controlsType === GameLib.D3.Controls.CONTROLS_TYPE_TOUCH) { if (this.controlsType === GameLib.D3.Controls.CONTROLS_TYPE_TOUCH) {

View File

@ -3,14 +3,14 @@
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param apiControls GameLib.D3.API.Controls * @param apiControls GameLib.D3.API.Controls
* @param raycaster * @param raycaster
* @param renderer * @param camera
* @constructor * @constructor
*/ */
GameLib.D3.Controls.Editor = function ( GameLib.D3.Controls.Editor = function (
graphics, graphics,
apiControls, apiControls,
raycaster, raycaster,
renderer camera
) { ) {
this.graphics = graphics; this.graphics = graphics;
@ -21,10 +21,10 @@ GameLib.D3.Controls.Editor = function (
} }
this.raycaster = raycaster; this.raycaster = raycaster;
if (GameLib.Utils.UndefinedOrNull(renderer)) { if (GameLib.Utils.UndefinedOrNull(camera)) {
renderer = null; camera = null;
} }
this.renderer = renderer; this.camera = camera;
if (this.raycaster instanceof GameLib.D3.API.Raycaster) { if (this.raycaster instanceof GameLib.D3.API.Raycaster) {
this.raycaster = new GameLib.D3.Raycaster( this.raycaster = new GameLib.D3.Raycaster(
@ -33,10 +33,10 @@ GameLib.D3.Controls.Editor = function (
); );
} }
if (this.renderer instanceof GameLib.D3.API.Renderer) { if (this.camera instanceof GameLib.D3.API.Camera) {
this.renderer = new GameLib.D3.Renderer( this.camera = new GameLib.D3.Camera(
this.graphics, this.graphics,
this.renderer this.camera
) )
} }
@ -66,29 +66,17 @@ GameLib.D3.Controls.Editor.prototype.delayedInstance = function() {
console.log('GameLib.D3.Controls.Editor.delayedInstance() called'); console.log('GameLib.D3.Controls.Editor.delayedInstance() called');
if (!this.renderer) { if (!this.camera || !this.camera.instance) {
throw new Error('No renderer at time of creating instance');
}
if (!this.renderer.camera) {
throw new Error('No camera at time of instance'); throw new Error('No camera at time of instance');
} }
if (!this.renderer.domElement) { if (!this.domElement || !this.domElement.instance) {
throw new Error('No dom element at time of instance'); throw new Error('No dom element at time of instance');
} }
if (!this.renderer.camera.instance) {
throw new Error('No camera instance at time of instance');
}
if (!this.renderer.domElement.instance) {
throw new Error('No dom element instance at time of instance');
}
var instance = new THREE.EditorControls( var instance = new THREE.EditorControls(
this.renderer.camera.instance, this.camera.instance,
this.renderer.domElement.instance this.domElement.instance
); );
return instance; return instance;
@ -119,8 +107,8 @@ GameLib.D3.Controls.Editor.prototype.toApiObject = function() {
var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this); var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this);
apiControls.raycaster = GameLib.Utils.IdOrNull(this.raycaster); apiControls.raycaster = GameLib.Utils.IdOrNull(this.raycaster);
apiControls.renderer = GameLib.Utils.IdOrNull(this.renderer); apiControls.camera = GameLib.Utils.IdOrNull(this.camera);
return apiControls; return apiControls;
}; };
@ -136,12 +124,11 @@ GameLib.D3.Controls.Editor.FromObject = function(graphics, objectControls) {
var apiControls = GameLib.D3.API.Controls.FromObject(objectControls); var apiControls = GameLib.D3.API.Controls.FromObject(objectControls);
apiControls.renderer = objectControls.renderer;
apiControls.raycaster = objectControls.raycaster;
return new GameLib.D3.Controls.Editor( return new GameLib.D3.Controls.Editor(
graphics, graphics,
apiControls apiControls,
apiControls.raycaster,
apiControls.camera
); );
}; };

93
src/game-lib-d3-font.js Normal file
View File

@ -0,0 +1,93 @@
/**
* Font Superset - The apiFont properties get moved into the Font object itself, and then the instance is created
* @param graphics GameLib.D3.Graphics
* @param apiFont GameLib.D3.API.Font
* @constructor
*/
GameLib.D3.Font = function(
graphics,
apiFont
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiFont)) {
apiFont = {};
}
if (apiFont instanceof GameLib.D3.Font) {
return apiFont;
}
GameLib.D3.API.Font.call(
this,
apiFont.id,
apiFont.name,
apiFont.url,
apiFont.parentEntity
);
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_FONT
);
};
GameLib.D3.Font.prototype = Object.create(GameLib.D3.API.Font.prototype);
GameLib.D3.Font.prototype.constructor = GameLib.D3.Font;
/**
* Creates a light instance
* @returns {*}
*/
GameLib.D3.Font.prototype.createInstance = function() {
GameLib.Event.Emit(
GameLib.Event.LOAD_FONT,
{
font : this
}
);
return null;
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Font.prototype.updateInstance = function() {
GameLib.Event.Emit(
GameLib.Event.LOAD_FONT,
{
font : this
}
);
};
/**
* Converts a GameLib.D3.Font to a GameLib.D3.API.Font
* @returns {GameLib.D3.API.Font}
*/
GameLib.D3.Font.prototype.toApiObject = function() {
return new GameLib.D3.API.Font(
this.id,
this.name,
this.url,
GameLib.Utils.IdOrNull(this.parentEntity)
);
};
/**
* Returns a new GameLib.D3.Font from a GameLib.D3.API.Font
* @param graphics GameLib.D3.Graphics
* @param objectFont GameLib.D3.API.Font
* @returns {GameLib.D3.Font}
*/
GameLib.D3.Font.FromObject = function(graphics, objectFont) {
return new GameLib.D3.Font(
graphics,
GameLib.D3.API.Font.FromObject(objectFont)
);
};

View File

@ -36,6 +36,7 @@ GameLib.D3.Light = function(
apiLight.power, apiLight.power,
apiLight.angle, apiLight.angle,
apiLight.penumbra, apiLight.penumbra,
apiLight.parentScene,
apiLight.parentEntity apiLight.parentEntity
); );
@ -295,6 +296,7 @@ GameLib.D3.Light.prototype.toApiObject = function() {
this.power, this.power,
this.angle, this.angle,
this.penumbra, this.penumbra,
GameLib.Utils.IdOrNull(this.parentScene),
GameLib.Utils.IdOrNull(this.parentEntity) GameLib.Utils.IdOrNull(this.parentEntity)
); );
}; };

View File

@ -339,6 +339,14 @@ GameLib.D3.Material.MATERIAL_TYPE_STANDARD = 0x8;
GameLib.D3.Material.MATERIAL_TYPE_POINTS = 0x9; GameLib.D3.Material.MATERIAL_TYPE_POINTS = 0x9;
GameLib.D3.Material.MATERIAL_TYPE_SPRITE = 0xa; GameLib.D3.Material.MATERIAL_TYPE_SPRITE = 0xa;
GameLib.D3.Material.LINE_CAP_BUTT = 0x1;//'butt';
GameLib.D3.Material.LINE_CAP_ROUND = 0x2;//'round';
GameLib.D3.Material.LINE_CAP_SQUARE = 0x3;//'square';
GameLib.D3.Material.LINE_JOIN_ROUND = 0x1;//'round';
GameLib.D3.Material.LINE_JOIN_BEVEL = 0x2;//'bevel';
GameLib.D3.Material.LINE_JOIN_MITER = 0x3;//'miter';
GameLib.D3.Material.prototype.createStandardMaterialInstance = function() { GameLib.D3.Material.prototype.createStandardMaterialInstance = function() {
return new THREE.MeshStandardMaterial({ return new THREE.MeshStandardMaterial({
name: this.name, name: this.name,
@ -413,6 +421,57 @@ GameLib.D3.Material.prototype.createPointsMaterialInstance = function() {
}); });
}; };
GameLib.D3.Material.prototype.createLineBasicMaterialInstance = function() {
var linecap = 'round';
if (this.lineCap === GameLib.D3.Material.LINE_CAP_BUTT) {
linecap = 'butt';
}
if (this.lineCap === GameLib.D3.Material.LINE_CAP_SQUARE) {
linecap = 'square';
}
var linejoin = 'round';
if (this.lineJoin === GameLib.D3.Material.LINE_JOIN_BEVEL) {
linejoin = 'bevel';
}
if (this.lineJoin === GameLib.D3.Material.LINE_JOIN_MITER) {
linejoin = 'miter';
}
return new THREE.LineBasicMaterial({
name: this.name,
opacity: this.opacity,
transparent: this.transparent,
// blending: this.blending,
// blendSrc: this.blendSrc,
// blendDst: this.blendDst,
// blendEquation: this.blendEquation,
depthTest: this.depthTest,
depthFunc: this.depthFunc,
depthWrite: this.depthWrite,
// polygonOffset: this.polygonOffset,
// polygonOffsetFactor: this.polygonOffsetFactor,
// polygonOffsetUnits: this.polygonOffsetUnits,
// alphaTest: this.alphaTest,
// clippingPlanes: this.clippingPlanes,
// clipShadows: this.clipShadows,
// overdraw: this.overdraw,
visible: this.visible,
side: this.side,
color: this.color.instance,
linewidth: this.lineWidth,
linecap: linecap,
linejoin: linejoin
// vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS,
// fog: this.fog
});
};
GameLib.D3.Material.prototype.createPhongMaterialInstance = function() { GameLib.D3.Material.prototype.createPhongMaterialInstance = function() {
return new THREE.MeshPhongMaterial({ return new THREE.MeshPhongMaterial({
name: this.name, name: this.name,
@ -644,6 +703,58 @@ GameLib.D3.Material.prototype.updatePointsMaterialInstance = function() {
//this.instance.fog = this.fog; //this.instance.fog = this.fog;
}; };
GameLib.D3.Material.prototype.updateLineBasicMaterialInstance = function() {
var linecap = 'round';
if (this.lineCap === GameLib.D3.Material.LINE_CAP_BUTT) {
linecap = 'butt';
}
if (this.lineCap === GameLib.D3.Material.LINE_CAP_SQUARE) {
linecap = 'square';
}
var linejoin = 'round';
if (this.lineJoin === GameLib.D3.Material.LINE_JOIN_BEVEL) {
linejoin = 'bevel';
}
if (this.lineJoin === GameLib.D3.Material.LINE_JOIN_MITER) {
linejoin = 'miter';
}
this.instance.name = this.name;
this.instance.opacity = this.opacity;
this.instance.transparent = this.transparent;
// this.instance.blending = this.blending;
// this.instance.blendSrc = this.blendSrc;
// this.instance.blendDst = this.blendDst;
// this.instance.blendEquation = this.blendEquation;
// this.instance.depthTest = this.depthTest;
this.instance.depthFunc = this.depthFunc;
this.instance.depthWrite = this.depthWrite;
// this.instance.polygonOffset = this.polygonOffset;
// this.instance.polygonOffsetFactor = this.polygonOffsetFactor;
// this.instance.polygonOffsetUnits = this.polygonOffsetUnits;
// this.instance.alphaTest = this.alphaTest;
// this.instance.clippingPlanes = this.clippingPlanes;
// this.instance.clipShadows = this.clipShadows;
// this.instance.overdraw = this.overdraw;
this.instance.visible = this.visible;
this.instance.side = this.side;
this.instance.color = this.color.instance;
this.instance.linewidth = this.lineWidth;
this.instance.linecap = linecap;
this.instance.linejoin = linejoin;
//this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS;
//this.instance.fog = this.fog;
};
GameLib.D3.Material.prototype.updatePhongMaterialInstance = function() { GameLib.D3.Material.prototype.updatePhongMaterialInstance = function() {
this.instance.name = this.name; this.instance.name = this.name;
this.instance.opacity = this.opacity; this.instance.opacity = this.opacity;
@ -740,6 +851,10 @@ GameLib.D3.Material.prototype.createInstance = function() {
instance = this.createMeshBasicMaterialInstance(); instance = this.createMeshBasicMaterialInstance();
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC) {
instance = this.createLineBasicMaterialInstance();
} else { } else {
console.warn("material type is not implemented yet: " + this.materialType); console.warn("material type is not implemented yet: " + this.materialType);
} }
@ -761,7 +876,7 @@ GameLib.D3.Material.prototype.updateInstance = function() {
// console.log('material update instance'); // console.log('material update instance');
if (!this.instance) { if (!this.instance) {
console.warn('Attempt to update a non-existent instance'); //console.warn('Attempt to update a non-existent instance');
return; return;
} }
@ -795,6 +910,13 @@ GameLib.D3.Material.prototype.updateInstance = function() {
} else { } else {
this.updateMeshBasicMaterialInstance(); this.updateMeshBasicMaterialInstance();
} }
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC) {
if (!(this.instance instanceof THREE.LineBasicMaterial)) {
this.instance = this.createLineBasicMaterialInstance();
typeChange = true;
} else {
this.updateLineBasicMaterialInstance();
}
} else { } else {
console.warn('not yet implemented (material type = ' + this.materialType + ')'); console.warn('not yet implemented (material type = ' + this.materialType + ')');
} }

View File

@ -122,12 +122,19 @@ GameLib.D3.Mesh = function (
this this
); );
this.size = new GameLib.Vector3( this.dimensions = new GameLib.Vector3(
this.graphics, this.graphics,
new GameLib.API.Vector3(), new GameLib.API.Vector3(),
this this
); );
var linkedObjects = {
'parentMesh' : GameLib.D3.Mesh,
'parentScene' : GameLib.D3.Scene,
'materials' : [GameLib.D3.Material],
'skeleton' : GameLib.D3.Skeleton
};
var componentType = GameLib.Component.COMPONENT_MESH; var componentType = GameLib.Component.COMPONENT_MESH;
if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_PLANE) { if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_PLANE) {
@ -138,6 +145,11 @@ GameLib.D3.Mesh = function (
componentType = GameLib.Component.COMPONENT_MESH_SPHERE componentType = GameLib.Component.COMPONENT_MESH_SPHERE
} }
if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_TEXT) {
componentType = GameLib.Component.COMPONENT_MESH_TEXT;
linkedObjects.font = GameLib.D3.Font;
}
/** /**
* Runtime meshes have helpers too * Runtime meshes have helpers too
* @type {null} * @type {null}
@ -149,12 +161,7 @@ GameLib.D3.Mesh = function (
GameLib.Component.call( GameLib.Component.call(
this, this,
componentType, componentType,
{ linkedObjects
'parentMesh' : GameLib.D3.Mesh,
'parentScene' : GameLib.D3.Scene,
'materials' : [GameLib.D3.Material],
'skeleton' : GameLib.D3.Skeleton
}
); );
}; };
@ -172,6 +179,7 @@ GameLib.D3.Mesh.MESH_TYPE_SPHERE = 0x3;
GameLib.D3.Mesh.MESH_TYPE_PLANE = 0x4; GameLib.D3.Mesh.MESH_TYPE_PLANE = 0x4;
GameLib.D3.Mesh.MESH_TYPE_BOX = 0x5; GameLib.D3.Mesh.MESH_TYPE_BOX = 0x5;
GameLib.D3.Mesh.MESH_TYPE_CYLINDER = 0x6; GameLib.D3.Mesh.MESH_TYPE_CYLINDER = 0x6;
GameLib.D3.Mesh.MESH_TYPE_TEXT = 0x7;
GameLib.D3.Mesh.prototype.createInstanceGeometry = function(instanceGeometry) { GameLib.D3.Mesh.prototype.createInstanceGeometry = function(instanceGeometry) {
@ -1353,7 +1361,11 @@ GameLib.D3.Mesh.prototype.addMaterial = function(material) {
if (this.materials.length === 1) { if (this.materials.length === 1) {
this.instance.material = material.instance; this.instance.material = material.instance;
} else { } else {
this.instance.material.push(material.instance); this.instance.material = this.materials.map(
function(material) {
return material.instance;
}
);
} }
}; };
@ -1397,7 +1409,7 @@ GameLib.D3.Mesh.prototype.computeBoundingBox = function(geometry) {
} }
geometry.computeBoundingBox(); geometry.computeBoundingBox();
this.size.x = geometry.boundingBox.getSize().x; this.dimensions.x = geometry.boundingBox.getSize().x;
this.size.y = geometry.boundingBox.getSize().y; this.dimensions.y = geometry.boundingBox.getSize().y;
this.size.z = geometry.boundingBox.getSize().z; this.dimensions.z = geometry.boundingBox.getSize().z;
}; };

View File

@ -0,0 +1,219 @@
/**
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
* @param graphics GameLib.D3.Graphics
* @param apiMesh GameLib.D3.API.Mesh
* @param font
* @param size
* @param height
* @param curveSegments
* @param bevelEnabled
* @param bevelThickness
* @param bevelSize
* @param bevelSegments
* @param text
* @constructor
*/
GameLib.D3.Mesh.Text = function (
graphics,
apiMesh,
text,
font,
size,
height,
curveSegments,
bevelEnabled,
bevelThickness,
bevelSize,
bevelSegments
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(text)) {
text = '-=<yb4f310';
}
this.text = text;
if (GameLib.Utils.UndefinedOrNull(font)) {
font = new GameLib.D3.Font(
this.graphics
);
}
this.font = font;
if (GameLib.Utils.UndefinedOrNull(size)) {
size = 100;
}
this.size = size;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 50;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(curveSegments)) {
curveSegments = 12;
}
this.curveSegments = curveSegments;
if (GameLib.Utils.UndefinedOrNull(bevelEnabled)) {
bevelEnabled = false;
}
this.bevelEnabled = bevelEnabled;
if (GameLib.Utils.UndefinedOrNull(bevelThickness)) {
bevelThickness = 10;
}
this.bevelThickness = bevelThickness;
if (GameLib.Utils.UndefinedOrNull(bevelSize)) {
bevelSize = 8;
}
this.bevelSize = bevelSize;
if (GameLib.Utils.UndefinedOrNull(bevelSegments)) {
bevelSegments = 3;
}
this.bevelSegments = bevelSegments;
GameLib.D3.Mesh.call(
this,
this.graphics,
apiMesh
);
};
GameLib.D3.Mesh.Text.prototype = Object.create(GameLib.D3.Mesh.prototype);
GameLib.D3.Mesh.Text.prototype.constructor = GameLib.D3.Mesh.Text;
GameLib.D3.Mesh.Text.prototype.createInstance = function() {
var geometry = null;
if (this.vertices.length === 0) {
geometry = new THREE.TextGeometry(
this.text,
{
font: this.font.instance,
size: this.size,
height: this.height,
curveSegments: this.curveSegments,
bevelEnabled: this.bevelEnabled,
bevelThickness: this.bevelThickness,
bevelSize: this.bevelSize,
bevelSegments: this.bevelSegments
}
);
this.updateVerticesFromGeometryInstance(geometry);
}
var instance = GameLib.D3.Mesh.prototype.createInstance.call(this);
instance.userData.font = this.font;
instance.userData.size = this.size;
instance.userData.height = this.height;
instance.userData.curveSegments = this.curveSegments;
instance.userData.bevelEnabled = this.bevelEnabled;
instance.userData.bevelThickness = this.bevelThickness;
instance.userData.bevelSize = this.bevelSize;
instance.userData.bevelSegments = this.bevelSegments;
return instance;
};
GameLib.D3.Mesh.Text.prototype.updateInstance = function() {
if (
this.instance.userData.text !== this.text ||
this.instance.userData.font !== this.font ||
this.instance.userData.size !== this.size ||
this.instance.userData.height !== this.height ||
this.instance.userData.curveSegments !== this.curveSegments ||
this.instance.userData.bevelEnabled !== this.bevelEnabled ||
this.instance.userData.bevelThickness !== this.bevelThickness ||
this.instance.userData.bevelSize !== this.bevelSize ||
this.instance.userData.bevelSegments !== this.bevelSegments
) {
this.instance.userData.text = this.text;
this.instance.userData.font = this.font;
this.instance.userData.size = this.size;
this.instance.userData.height = this.height;
this.instance.userData.curveSegments = this.curveSegments;
this.instance.userData.bevelEnabled = this.bevelEnabled;
this.instance.userData.bevelThickness = this.bevelThickness;
this.instance.userData.bevelSize = this.bevelSize;
this.instance.userData.bevelSegments = this.bevelSegments;
var geometry = new THREE.TextGeometry(
this.text,
{
font: this.font.instance,
size: this.size,
height: this.height,
curveSegments: this.curveSegments,
bevelEnabled: this.bevelEnabled,
bevelThickness: this.bevelThickness,
bevelSize: this.bevelSize,
bevelSegments: this.bevelSegments
}
);
this.updateVerticesFromGeometryInstance(geometry);
geometry = this.createInstanceGeometry();
this.instance.geometry = geometry;
}
GameLib.D3.Mesh.prototype.updateInstance.call(this);
};
/**
* Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh
* @returns {GameLib.D3.API.Mesh}
*/
GameLib.D3.Mesh.Text.prototype.toApiObject = function() {
var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this);
apiMesh.text = this.text;
apiMesh.font = GameLib.Utils.IdOrNull(this.font);
apiMesh.size = this.size;
apiMesh.height = this.height;
apiMesh.curveSegments = this.curveSegments;
apiMesh.bevelEnabled = this.bevelEnabled;
apiMesh.bevelThickness = this.bevelThickness;
apiMesh.bevelSize = this.bevelSize;
apiMesh.bevelSegments = this.bevelSegments;
return apiMesh;
};
/**
* Converts a standard object mesh to a GameLib.D3.Mesh
* @param graphics GameLib.D3.Graphics
* @param objectMesh {Object}
* @constructor
*/
GameLib.D3.Mesh.Text.FromObject = function(graphics, objectMesh) {
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh);
return new GameLib.D3.Mesh.Text(
graphics,
apiMesh,
objectMesh.text,
objectMesh.font,
objectMesh.size,
objectMesh.height,
objectMesh.curveSegments,
objectMesh.bevelEnabled,
objectMesh.bevelThickness,
objectMesh.bevelSize,
objectMesh.bevelSegments
);
};

View File

@ -108,10 +108,6 @@ GameLib.D3.Renderer = function (
} }
this.statistics = statistics; this.statistics = statistics;
this.mouse = new GameLib.Mouse(
this.graphics
);
GameLib.Component.call( GameLib.Component.call(
this, this,
GameLib.Component.COMPONENT_RENDERER, GameLib.Component.COMPONENT_RENDERER,

View File

@ -22,19 +22,14 @@ GameLib.D3.Scene = function (
GameLib.D3.API.Scene.call( GameLib.D3.API.Scene.call(
this, this,
apiScene.id, apiScene.id,
apiScene.name, apiScene.name,
apiScene.meshes, apiScene.meshes,
apiScene.position,
apiScene.quaternion,
apiScene.scale,
apiScene.parentGameId,
apiScene.lights, apiScene.lights,
apiScene.textures, apiScene.textures,
apiScene.materials, apiScene.materials,
apiScene.images, apiScene.images,
apiScene.activeCamera, apiScene.parentEntity
apiScene.parentEntity
); );
this.meshes = this.meshes.map( this.meshes = this.meshes.map(
@ -56,24 +51,6 @@ GameLib.D3.Scene = function (
}.bind(this) }.bind(this)
); );
this.position = new GameLib.Vector3(
this.graphics,
this.position,
this
);
this.quaternion = new GameLib.Quaternion(
this.graphics,
this.quaternion,
this
);
this.scale = new GameLib.Vector3(
this.graphics,
this.scale,
this
);
this.lights = this.lights.map( this.lights = this.lights.map(
function(apiLight) { function(apiLight) {
@ -146,13 +123,6 @@ GameLib.D3.Scene = function (
}.bind(this) }.bind(this)
); );
if (this.activeCamera instanceof GameLib.D3.API.Camera) {
this.activeCamera = new GameLib.D3.Camera(
this.graphics,
this.activeCamera
);
}
/** /**
* Runtime scenes have helpers (just used to store which helper belongs to which scene) * Runtime scenes have helpers (just used to store which helper belongs to which scene)
* @type {Array} * @type {Array}
@ -167,8 +137,7 @@ GameLib.D3.Scene = function (
'lights' : [GameLib.D3.Light], 'lights' : [GameLib.D3.Light],
'textures' : [GameLib.D3.Texture], 'textures' : [GameLib.D3.Texture],
'materials' : [GameLib.D3.Material], 'materials' : [GameLib.D3.Material],
'images' : [GameLib.D3.Image], 'images' : [GameLib.D3.Image]
'activeCamera' : GameLib.D3.Camera
} }
); );
}; };
@ -186,15 +155,82 @@ GameLib.D3.Scene.prototype.createInstance = function() {
instance.name = this.name; instance.name = this.name;
instance.position = this.position.instance; this.meshes.map(
function(mesh) {
instance.add(mesh.instance);
}.bind(this)
);
instance.scale = this.scale.instance; this.lights.map(
function(light) {
instance.quaternion = this.quaternion.instance; instance.add(light.instance);
}
);
return instance; return instance;
}; };
GameLib.D3.Scene.prototype.updateInstance = function() {
this.instance.name = this.name;
/**
* Add missing meshes
*/
this.meshes.map(
function(mesh) {
if (this.instance.children.indexOf(mesh.instance === -1)) {
this.instance.add(mesh.instance);
}
}.bind(this)
);
/**
* Add missing lights
*/
this.lights.map(
function(light) {
if (this.instance.children.indexOf(light.instance) === -1) {
this.instance.add(light.instance);
}
}.bind(this)
);
/**
* Remove extra meshes and lights
*/
this.instance.children.map(
function(instanceObject) {
var instanceMeshes = this.meshes.map(
function(mesh) {
return mesh.instance;
}
);
var instanceLights = this.lights.map(
function(light) {
return light.instance;
}
);
if (
(
instanceObject instanceof THREE.Mesh ||
instanceObject instanceof THREE.Light
) &&
(
instanceLights.indexOf(instanceObject) === -1 &&
instanceMeshes.indexOf(instanceObject) === -1
)
) {
this.instance.remove(instanceObject);
}
}.bind(this)
)
};
/** /**
* Converts a GameLib.D3.Scene to a GameLib.D3.API.Scene * Converts a GameLib.D3.Scene to a GameLib.D3.API.Scene
* @returns {GameLib.D3.API.Scene} * @returns {GameLib.D3.API.Scene}
@ -203,25 +239,31 @@ GameLib.D3.Scene.prototype.toApiObject = function() {
var apiMeshes = this.meshes.map( var apiMeshes = this.meshes.map(
function(mesh) { function(mesh) {
return mesh.id; return GameLib.Utils.IdOrNull(mesh);
} }
); );
var apiLights = this.lights.map( var apiLights = this.lights.map(
function(light) { function(light) {
return light.id; return GameLib.Utils.IdOrNull(light);
} }
); );
var apiTextures = this.textures.map( var apiTextures = this.textures.map(
function(texture) { function(texture) {
return texture.id; return GameLib.Utils.IdOrNull(texture);
} }
); );
var apiMaterials = this.materials.map( var apiMaterials = this.materials.map(
function(material) { function(material) {
return material.id; return GameLib.Utils.IdOrNull(material);
}
);
var apiImages = this.images.map(
function(image) {
return GameLib.Utils.IdOrNull(image);
} }
); );
@ -229,14 +271,10 @@ GameLib.D3.Scene.prototype.toApiObject = function() {
this.id, this.id,
this.name, this.name,
apiMeshes, apiMeshes,
this.position.toApiObject(),
this.quaternion.toApiObject(),
this.scale.toApiObject(),
this.parentGameId,
apiLights, apiLights,
apiTextures, apiTextures,
apiMaterials, apiMaterials,
GameLib.Utils.IdOrNull(this.activeCamera), apiImages,
GameLib.Utils.IdOrNull(this.parentEntity) GameLib.Utils.IdOrNull(this.parentEntity)
); );
}; };

View File

@ -77,9 +77,9 @@ GameLib.D3.Shape.ConvexHull.Cylinder.prototype.updateInstance = function() {
}; };
GameLib.D3.Shape.ConvexHull.Cylinder.prototype.setFromMesh = function() { GameLib.D3.Shape.ConvexHull.Cylinder.prototype.setFromMesh = function() {
this.radiusTop = this.parentMesh.size.x / 2; this.radiusTop = this.parentMesh.dimensions.x / 2;
this.radiusBottom = this.parentMesh.size.x / 2; this.radiusBottom = this.parentMesh.dimensions.x / 2;
this.height = this.parentMesh.size.z; this.height = this.parentMesh.dimensions.z;
}; };
GameLib.D3.Shape.ConvexHull.Cylinder.prototype.toApiObject = function() { GameLib.D3.Shape.ConvexHull.Cylinder.prototype.toApiObject = function() {

View File

@ -383,6 +383,10 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp
constructor = GameLib.D3.PhysicsWorld; constructor = GameLib.D3.PhysicsWorld;
} }
if (property === 'parentScene') {
constructor = GameLib.D3.Scene;
}
var options = GameLib.EntityManager.Instance.queryComponents(constructor).reduce( var options = GameLib.EntityManager.Instance.queryComponents(constructor).reduce(
function(result, object) { function(result, object) {
result[object.name] = object; result[object.name] = object;
@ -434,6 +438,16 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp
) )
} }
if (property === 'parentScene') {
GameLib.Event.Emit(
GameLib.Event.PARENT_SCENE_CHANGE,
{
originalScene: this.initialValue,
newScene: newComponent,
object: component
}
);
}
}.bind(this) }.bind(this)
); );
@ -557,10 +571,12 @@ GameLib.System.GUI.prototype.buildColorControl = function(folder, componentTempl
var object = componentTemplate.template; var object = componentTemplate.template;
var tempObject = {
hexColor : object[property].toHex()
};
folder.addColor( folder.addColor(
{ tempObject,
hexColor : object[property].toHex()
},
'hexColor' 'hexColor'
).name(property).listen().onChange( ).name(property).listen().onChange(
function(value) { function(value) {
@ -573,6 +589,20 @@ GameLib.System.GUI.prototype.buildColorControl = function(folder, componentTempl
} }
); );
folder.add(
tempObject,
'hexColor'
).name(property).listen().onChange(
function(value) {
componentTemplate.affected.map(
function(component) {
component[property].fromHex(value);
component[property].updateInstance();
}
)
}
)
}; };
GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemplate, property) { GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemplate, property) {
@ -617,8 +647,6 @@ GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemp
var newComponent = null; var newComponent = null;
var originalComponent = this.initialValue;
if (value !== 'null') { if (value !== 'null') {
newComponent = idToObject[value]; newComponent = idToObject[value];
} }
@ -627,28 +655,6 @@ GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemp
function(component) { function(component) {
component[property] = newComponent; component[property] = newComponent;
component.updateInstance(); component.updateInstance();
if (property === 'parentScene') {
GameLib.Event.Emit(
GameLib.Event.PARENT_SCENE_CHANGE,
{
originalScene: originalComponent,
newScene: newComponent,
object: component
}
);
}
if (property === 'parentWorld') {
GameLib.Event.Emit(
GameLib.Event.PARENT_WORLD_CHANGE,
{
originalWorld : originalComponent,
newWorld : newComponent,
object : component
}
)
}
} }
); );
@ -743,7 +749,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
'plane' : GameLib.D3.Mesh.MESH_TYPE_PLANE, 'plane' : GameLib.D3.Mesh.MESH_TYPE_PLANE,
'sphere' : GameLib.D3.Mesh.MESH_TYPE_SPHERE, 'sphere' : GameLib.D3.Mesh.MESH_TYPE_SPHERE,
'box' : GameLib.D3.Mesh.MESH_TYPE_BOX, 'box' : GameLib.D3.Mesh.MESH_TYPE_BOX,
'cylinder' : GameLib.D3.Mesh.MESH_TYPE_CYLINDER 'cylinder' : GameLib.D3.Mesh.MESH_TYPE_CYLINDER,
'text' : GameLib.D3.Mesh.MESH_TYPE_TEXT
} }
) )
); );
@ -767,7 +774,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
'standard': GameLib.D3.Material.MATERIAL_TYPE_STANDARD, 'standard': GameLib.D3.Material.MATERIAL_TYPE_STANDARD,
'basic': GameLib.D3.Material.MATERIAL_TYPE_BASIC, 'basic': GameLib.D3.Material.MATERIAL_TYPE_BASIC,
'phong': GameLib.D3.Material.MATERIAL_TYPE_PHONG, 'phong': GameLib.D3.Material.MATERIAL_TYPE_PHONG,
'points': GameLib.D3.Material.MATERIAL_TYPE_POINTS 'points': GameLib.D3.Material.MATERIAL_TYPE_POINTS,
'line basic' : GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC
} }
) )
); );
@ -1084,14 +1092,18 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
controllers.push(folder.add(object, property, -255, 255, 1)); controllers.push(folder.add(object, property, -255, 255, 1));
} else if ( } else if (
property === 'aspect' || property === 'aspect' ||
property === 'wireframeLineWidth' property === 'wireframeLineWidth' ||
property === 'lineWidth'
) { ) {
controllers.push(folder.add(object, property, 0, 5, 0.001)); controllers.push(folder.add(object, property, 0, 5, 0.001));
} else if ( } else if (
property === 'bumpScale' ||
property === 'normalScale' ||
property === 'displacementScale' ||
property === 'heightMapScale' || property === 'heightMapScale' ||
property === 'intensity' property === 'intensity'
) { ) {
controllers.push(folder.add(object, property, 0, 10, 0.001)); controllers.push(folder.add(object, property, -10, 10, 0.001));
} else if ( } else if (
property === 'minX' || property === 'minX' ||
property === 'minY' || property === 'minY' ||
@ -1596,7 +1608,8 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
if ( if (
templateProperty === 'parentEntity' || templateProperty === 'parentEntity' ||
templateProperty === 'parentWorld' || templateProperty === 'parentWorld' ||
templateProperty === 'parentMesh' templateProperty === 'parentMesh' ||
templateProperty === 'parentScene'
) { ) {
this.buildParentSelectionControl(folder, componentTemplate, templateProperty); this.buildParentSelectionControl(folder, componentTemplate, templateProperty);
continue; continue;

View File

@ -1,20 +1,20 @@
/** /**
* System takes care of updating all the entities (based on their component data) * System takes care of updating all the entities (based on their component data)
* @param apiSystem GameLib.API.System * @param apiSystem GameLib.API.System
* @param graphics
* @constructor * @constructor
*/ */
GameLib.System.Input = function( GameLib.System.Input = function(
apiSystem apiSystem,
graphics
) { ) {
GameLib.System.call( GameLib.System.call(
this, this,
apiSystem apiSystem
); );
// this.meshMoveMode = false; this.graphics = graphics;
// this.meshMoveXMode = false; this.graphics.isNotThreeThrow();
// this.meshMoveYMode = false;
// this.meshMoveZMode = false;
/** /**
* We need new function pointers with scope bound to this so we can remove the * We need new function pointers with scope bound to this so we can remove the
@ -39,14 +39,25 @@ GameLib.System.Input = function(
this.keyboardControls = []; this.keyboardControls = [];
this.mouseControls = []; this.mouseControls = [];
this.touchStart = this.onTouchStart.bind(this); this.touchStart = this.onTouchStart.bind(this);
this.touchMove = this.onTouchMove.bind(this); this.touchMove = this.onTouchMove.bind(this);
this.touchEnd = this.onTouchEnd.bind(this); this.touchEnd = this.onTouchEnd.bind(this);
this.touchCancel = this.onTouchCancel.bind(this); this.touchCancel = this.onTouchCancel.bind(this);
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this); this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this); this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
this.mouseDown = this.onMouseDown.bind(this);
this.mouseMove = this.onMouseMove.bind(this);
this.mouseWheel = this.onMouseWheel.bind(this);
this.mouseUp = this.onMouseUp.bind(this);
this.keyDown = this.onKeyDown.bind(this);
this.keyUp = this.onKeyUp.bind(this);
this.mouse = new GameLib.Mouse(
graphics
)
}; };
GameLib.System.Input.prototype = Object.create(GameLib.System.prototype); GameLib.System.Input.prototype = Object.create(GameLib.System.prototype);
@ -59,13 +70,13 @@ GameLib.System.Input.prototype.start = function() {
GameLib.System.prototype.start.call(this); GameLib.System.prototype.start.call(this);
this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Editor); this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Editor);
this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Touch); this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Touch);
this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Keyboard); this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Keyboard);
this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Mouse); this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Mouse);
/** /**
* If we have touch controls - inject them first so we can override editor controls if necessary * If we have touch controls - inject them first so we can override editor controls if necessary
@ -103,7 +114,6 @@ GameLib.System.Input.prototype.start = function() {
this.touchCancel, this.touchCancel,
false false
); );
} }
/** /**
@ -128,75 +138,47 @@ GameLib.System.Input.prototype.start = function() {
} }
if (this.editorControls.length > 0) { if (this.editorControls.length > 0) {
this.editorControls.map(
this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer); function(editorControl) {
editorControl.domElement.instance.addEventListener(
this.renderers.map(
function(renderer) {
renderer.controls = this.editorControls.reduce(
function(result, editorControl) {
if (editorControl.renderer === renderer) {
result = editorControl;
}
return result;
},
null
);
renderer.mouseDown = this.onMouseDown(renderer, renderer.controls).bind(this);
renderer.domElement.instance.addEventListener(
'mousedown', 'mousedown',
renderer.mouseDown, this.mouseDown,
false false
); );
renderer.mouseMove = this.onMouseMove.bind(this); editorControl.domElement.instance.addEventListener(
renderer.domElement.instance.addEventListener(
'mousemove', 'mousemove',
renderer.mouseMove, this.mouseMove,
false false
); );
renderer.keyDown = this.onKeyDown.bind(this); editorControl.domElement.instance.addEventListener(
renderer.domElement.instance.addEventListener(
'keydown', 'keydown',
renderer.keyDown, this.keyDown,
false false
); );
renderer.keyUp = this.onKeyUp.bind(this); editorControl.domElement.instance.addEventListener(
renderer.domElement.instance.addEventListener(
'keyup', 'keyup',
renderer.keyUp, this.keyUp,
false false
); );
if (renderer.controls) { editorControl.instance = editorControl.delayedInstance();
/**
* Create the delayed instance here - it affects the order of event listeners attached to DOM
*/
renderer.controls.instance = renderer.controls.delayedInstance();
} else {
console.warn('no third party controls for renderer : ' + renderer.name);
}
renderer.mouseWheel = this.onMouseWheel(renderer.camera).bind(this); editorControl.domElement.instance.addEventListener(
renderer.domElement.instance.addEventListener(
'mousewheel', 'mousewheel',
renderer.mouseWheel, this.mouseWheel,
false false
); );
renderer.mouseUp = this.onMouseUp(renderer.camera, renderer.controls).bind(this); editorControl.domElement.instance.addEventListener(
renderer.domElement.instance.addEventListener(
'mouseup', 'mouseup',
renderer.mouseUp, this.mouseUp,
false false
); );
}.bind(this) }.bind(this)
); )
} }
}; };
@ -293,7 +275,7 @@ GameLib.System.Input.prototype.onTouchMove = function (event) {
this.touches[id].pageX = event.changedTouches[t].pageX; this.touches[id].pageX = event.changedTouches[t].pageX;
this.touches[id].pageY = event.changedTouches[t].pageY; this.touches[id].pageY = event.changedTouches[t].pageY;
console.log(this.touches[id]); //console.log(this.touches[id]);
} }
this.touches.event = event; this.touches.event = event;
@ -424,89 +406,92 @@ GameLib.System.Input.prototype.onKeyUp = function(event) {
} }
}; };
GameLib.System.Input.prototype.onMouseDown = function(renderer, controls) { GameLib.System.Input.prototype.onMouseDown = function(event) {
return function(event) { if (event.button === 2) {
if (event.button === 2) { this.editorControls.map(
if (this.controlLeft) { function(editorControl) {
return;
}
renderer.mouse.x = (event.offsetX / renderer.instance.domElement.width) * 2 - 1; if (this.controlLeft) {
renderer.mouse.y = -(event.offsetY / renderer.instance.domElement.height) * 2 + 1; return;
}
var scenes = renderer.scenes; this.mouse.x = (event.offsetX / event.target.width ) * 2 - 1;
this.mouse.y = -(event.offsetY / event.target.height) * 2 + 1;
var intersects = scenes.reduce( var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene);
function(result, scene) { var intersects = scenes.reduce(
controls.raycaster.instance.setFromCamera( function (result, scene) {
renderer.mouse,
renderer.camera.instance
);
intersects = controls.raycaster.getIntersectedObjects(scene.meshes); editorControl.raycaster.instance.setFromCamera(
this.mouse,
editorControl.camera.instance
);
intersects.map(function(intersect){ intersects = editorControl.raycaster.getIntersectedObjects(scene.meshes);
result.push(intersect);
});
return result; intersects.map(function (intersect) {
}.bind(this), result.push(intersect);
[] });
);
intersects.sort( return result;
function(a, b) { }.bind(this),
if (a.distance < b.distance) { []
return -1; );
}
if (a.distance > b.distance) { intersects.sort(
return 1; function (a, b) {
} if (a.distance < b.distance) {
return -1;
}
return 0; if (a.distance > b.distance) {
} return 1;
); }
var meshes = intersects.map(function(intersect){ return 0;
return intersect.mesh; }
}); );
var mesh = meshes[0]; var meshes = intersects.map(function (intersect) {
return intersect.mesh;
});
if (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 * Prevent default action (like context menu or whatever)
*/ */
event.stopImmediatePropagation(); event.preventDefault();
if (mesh.selected) { /**
this.deSelectMesh(mesh); * Prevent other event listeners for 'mousedown' from executing their actions
} else { */
this.selectMesh(mesh); event.stopImmediatePropagation();
}
/** if (mesh.selected) {
* Notify our GUI system to build a GUI this.deSelectMesh(mesh);
*/ } else {
GameLib.Event.Emit( this.selectMesh(mesh);
GameLib.Event.BUILD_GUI, }
null
) /**
} * Notify our GUI system to build a GUI
} */
}.bind(this); GameLib.Event.Emit(
GameLib.Event.BUILD_GUI,
null
)
}
}.bind(this)
);
}
}; };
/** /**
@ -519,41 +504,42 @@ GameLib.System.Input.prototype.onMouseMove = function(event) {
/** /**
* Update the camera position etc. after mouse up * Update the camera position etc. after mouse up
* @param __camera
* @param __controls
* @returns {Function} * @returns {Function}
* @param event
*/ */
GameLib.System.Input.prototype.onMouseUp = function(__camera, __controls) { GameLib.System.Input.prototype.onMouseUp = function(event) {
return function(event) { this.editorControls.map(
function(editorControl) {
editorControl.camera.position.x = editorControl.camera.instance.position.x;
editorControl.camera.position.y = editorControl.camera.instance.position.y;
editorControl.camera.position.z = editorControl.camera.instance.position.z;
__camera.position.x = __camera.instance.position.x; editorControl.camera.quaternion.x = editorControl.camera.instance.quaternion.x;
__camera.position.y = __camera.instance.position.y; editorControl.camera.quaternion.y = editorControl.camera.instance.quaternion.y;
__camera.position.z = __camera.instance.position.z; editorControl.camera.quaternion.z = editorControl.camera.instance.quaternion.z;
editorControl.camera.quaternion.w = editorControl.camera.instance.quaternion.w;
__camera.quaternion.x = __camera.instance.quaternion.x; editorControl.camera.lookAt.x = editorControl.instance.center.x;
__camera.quaternion.y = __camera.instance.quaternion.y; editorControl.camera.lookAt.y = editorControl.instance.center.y;
__camera.quaternion.z = __camera.instance.quaternion.z; editorControl.camera.lookAt.z = editorControl.instance.center.z;
__camera.quaternion.w = __camera.instance.quaternion.w; editorControl.camera.lookAt.instance.copy(editorControl.instance.center);
}
__camera.lookAt.x = __controls.instance.center.x; );
__camera.lookAt.y = __controls.instance.center.y;
__camera.lookAt.z = __controls.instance.center.z;
__camera.lookAt.instance.copy(__controls.instance.center);
};
}; };
/** /**
* Update our camera position after moving the mouse wheel * Update our camera position after moving the mouse wheel
* @param __camera
* @returns {Function} * @returns {Function}
* @param event
*/ */
GameLib.System.Input.prototype.onMouseWheel = function(__camera) { GameLib.System.Input.prototype.onMouseWheel = function(event) {
return function(event) { this.editorControls.map(
__camera.position.x = __camera.instance.position.x; function(editorControl) {
__camera.position.y = __camera.instance.position.y; editorControl.camera.position.x = editorControl.camera.instance.position.x;
__camera.position.z = __camera.instance.position.z; editorControl.camera.position.y = editorControl.camera.instance.position.y;
} editorControl.camera.position.z = editorControl.camera.instance.position.z;
}
);
}; };
GameLib.System.Input.prototype.selectMesh = function(mesh) { GameLib.System.Input.prototype.selectMesh = function(mesh) {
@ -606,56 +592,49 @@ GameLib.System.Input.prototype.stop = function() {
/** /**
* Now remove all input capabilities * Now remove all input capabilities
*/ */
this.renderers.map( this.editorControls.map(
function(editorControl) {
function(renderer) { editorControl.domElement.instance.removeEventListener(
renderer.domElement.instance.removeEventListener(
'mousedown', 'mousedown',
renderer.mouseDown, this.mouseDown,
false false
); );
renderer.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'mousemove', 'mousemove',
renderer.mouseMove, this.mouseMove,
false false
); );
renderer.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'keydown', 'keydown',
renderer.keyDown, this.keyDown,
false false
); );
renderer.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'keyup', 'keyup',
renderer.keyUp, this.keyUp,
false false
); );
if (renderer.controls && renderer.controls.instance) { editorControl.instance.dispose();
renderer.controls.instance.dispose();
} else {
console.warn('no third party controls to stop for renderer : ' + renderer.name);
}
renderer.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'mousewheel', 'mousewheel',
renderer.mouseWheel, this.mouseWheel,
false false
); );
renderer.domElement.instance.removeEventListener( editorControl.domElement.instance.removeEventListener(
'mouseup', 'mouseup',
renderer.mouseUp, this.mouseUp,
false false
); );
}.bind(this) }.bind(this)
); )
} }
if (this.touchControls.length > 0) { if (this.touchControls.length > 0) {
this.touchControls.map( this.touchControls.map(

View File

@ -33,6 +33,7 @@ GameLib.System.Linking = function(
this.lightInstanceCreatedSubscription = null; this.lightInstanceCreatedSubscription = null;
this.sceneInstanceCreatedSubscription = null; this.sceneInstanceCreatedSubscription = null;
this.imageInstanceCreatedSubscription = null; this.imageInstanceCreatedSubscription = null;
this.fontInstanceCreatedSubscription = null;
this.textureInstanceCreatedSubscription = null; this.textureInstanceCreatedSubscription = null;
this.materialInstanceCreatedSubscription = null; this.materialInstanceCreatedSubscription = null;
this.meshDeletedSubscription = null; this.meshDeletedSubscription = null;
@ -42,6 +43,7 @@ GameLib.System.Linking = function(
this.instanceCreatedSubscription = null; this.instanceCreatedSubscription = null;
this.shapeInstanceCreatedSubscription = null; this.shapeInstanceCreatedSubscription = null;
this.solverInstanceCreatedSubscription = null; this.solverInstanceCreatedSubscription = null;
this.registerDependenciesSubscription = null;
}; };
@ -92,6 +94,11 @@ GameLib.System.Linking.prototype.start = function() {
this.imageInstanceCreated this.imageInstanceCreated
); );
this.fontInstanceCreatedSubscription = this.subscribe(
GameLib.Event.FONT_INSTANCE_CREATED,
this.fontInstanceCreated
);
this.textureInstanceCreatedSubscription = this.subscribe( this.textureInstanceCreatedSubscription = this.subscribe(
GameLib.Event.TEXTURE_INSTANCE_CREATED, GameLib.Event.TEXTURE_INSTANCE_CREATED,
this.textureInstanceCreated this.textureInstanceCreated
@ -152,6 +159,15 @@ GameLib.System.Linking.prototype.start = function() {
this.instanceCreated this.instanceCreated
); );
this.registerDependenciesSubscription = this.subscribe(
GameLib.Event.REGISTER_DEPENDENCIES,
this.registerDependenciesDirect
)
};
GameLib.System.Linking.prototype.registerDependenciesDirect = function(data) {
this.registerDependencies(data.component);
}; };
GameLib.System.Linking.prototype.link = function(component, data) { GameLib.System.Linking.prototype.link = function(component, data) {
@ -560,8 +576,8 @@ GameLib.System.Linking.prototype.meshInstanceCreated = function(data) {
var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene); var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene);
scenes.map(function(scene){ scenes.map(function(scene){
if (data.mesh.parentScene === scene) { if (data.mesh.parentScene === scene.id) {
scene.addObject(data.mesh); data.mesh.parentScene = scene;
} }
}); });
@ -627,6 +643,8 @@ GameLib.System.Linking.prototype.lightInstanceCreated = function(data) {
scenes.map(function(scene){ scenes.map(function(scene){
if (data.light.parentScene === scene) { if (data.light.parentScene === scene) {
scene.addObject(data.light); scene.addObject(data.light);
//scene.updateInstance();
} }
}); });
@ -642,12 +660,21 @@ GameLib.System.Linking.prototype.sceneInstanceCreated = function(data) {
var objects = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh,GameLib.D3.Light]); var objects = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh,GameLib.D3.Light]);
objects.map(function(object){ objects.map(function(object){
if ( if (
object.parentScene === data.scene object.parentScene === data.scene.id
) { ) {
data.scene.addObject(object); object.parentScene = data.scene;
} }
}); });
//data.scene.updateInstance();
};
GameLib.System.Linking.prototype.fontInstanceCreated = function(data) {
/**
* We resolve the dependencies
*/
this.resolveDependencies(data.font);
}; };
GameLib.System.Linking.prototype.imageInstanceCreated = function(data) { GameLib.System.Linking.prototype.imageInstanceCreated = function(data) {
@ -1017,6 +1044,7 @@ GameLib.System.Linking.prototype.stop = function() {
this.lightInstanceCreatedSubscription.remove(); this.lightInstanceCreatedSubscription.remove();
this.sceneInstanceCreatedSubscription.remove(); this.sceneInstanceCreatedSubscription.remove();
this.imageInstanceCreatedSubscription.remove(); this.imageInstanceCreatedSubscription.remove();
this.fontInstanceCreatedSubscription.remove();
this.textureInstanceCreatedSubscription.remove(); this.textureInstanceCreatedSubscription.remove();
this.materialInstanceCreatedSubscription.remove(); this.materialInstanceCreatedSubscription.remove();
this.meshDeletedSubscription.remove(); this.meshDeletedSubscription.remove();
@ -1027,5 +1055,6 @@ GameLib.System.Linking.prototype.stop = function() {
this.physicsWorldInstanceCreatedSubscription.remove(); this.physicsWorldInstanceCreatedSubscription.remove();
this.shapeInstanceCreatedSubscription.remove(); this.shapeInstanceCreatedSubscription.remove();
this.solverInstanceCreatedSubscription.remove(); this.solverInstanceCreatedSubscription.remove();
this.registerDependenciesSubscription.remove();
}; };

View File

@ -128,6 +128,11 @@ GameLib.System.Storage.prototype.start = function() {
this.loadImage this.loadImage
); );
this.loadFontSubscription = this.subscribe(
GameLib.Event.LOAD_FONT,
this.loadFont
);
this.blenderDataSubscription = this.subscribe( this.blenderDataSubscription = this.subscribe(
GameLib.Event.BLENDER_DATA_RECEIVED, GameLib.Event.BLENDER_DATA_RECEIVED,
this.processBlenderData this.processBlenderData
@ -855,6 +860,53 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) {
*/ */
}; };
GameLib.System.Storage.prototype.loadFont = function(data) {
console.log('loading font : ' + data.font.name);
this.publish(
GameLib.Event.GET_API_URL,
null,
function(urlData) {
var url = urlData.apiUrl + '/fonts/' + data.font.url + '?ts=' + Date.now();
var loader = new THREE.FontLoader();
loader.load(
url,
function ( font ) {
if (GameLib.Utils.IsEmpty(font.data)) {
GameLib.Event.Emit(
GameLib.Event.FONT_NOT_FOUND,
{
font: data.font
}
);
} else {
data.font.instance = font;
data.font.loaded = true;
GameLib.Event.Emit(
GameLib.Event.FONT_INSTANCE_CREATED,
{
font: data.font
}
);
}
}
);
}.bind(this),
function(error) {
console.error(error.message);
throw new Error(error.message);
}
);
};
GameLib.System.Storage.prototype.loadImage = function(data) { GameLib.System.Storage.prototype.loadImage = function(data) {
console.log('loading image : ' + data.image.name); console.log('loading image : ' + data.image.name);
@ -1006,6 +1058,7 @@ GameLib.System.Storage.prototype.stop = function() {
this.loadSubscription.remove(); this.loadSubscription.remove();
this.saveSubscription.remove(); this.saveSubscription.remove();
this.loadImageSubscription.remove(); this.loadImageSubscription.remove();
this.loadFontSubscription.remove();
this.blenderDataSubscription.remove(); this.blenderDataSubscription.remove();
this.imageUploadCompleteSubscription.remove(); this.imageUploadCompleteSubscription.remove();
this.deleteSubscription.remove(); this.deleteSubscription.remove();