diff --git a/src/game-lib-a-1-event.js b/src/game-lib-a-1-event.js index f2e213e..5968134 100644 --- a/src/game-lib-a-1-event.js +++ b/src/game-lib-a-1-event.js @@ -23,6 +23,8 @@ GameLib.Event.LOAD_IMAGE = 0x7; GameLib.Event.MATERIAL_LOADED = 0x8; GameLib.Event.IMAGE_CHANGE = 0x9; GameLib.Event.TEXTURE_TYPE_CHANGE = 0xa; +GameLib.Event.NEW_ENTITY = 0xb; +GameLib.Event.MATERIAL_TYPE_CHANGED = 0xc; /** * Subscribe to some events diff --git a/src/game-lib-d3-material.js b/src/game-lib-d3-material.js index 469cb7b..86ab36c 100644 --- a/src/game-lib-d3-material.js +++ b/src/game-lib-d3-material.js @@ -315,17 +315,16 @@ GameLib.D3.Material.TYPE_SMOOTH_SHADING = 2; * Material Type * @type {string} */ -GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC = "LineBasicMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_LINE_DASHED = "LineDashedMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_BASIC = "MeshBasicMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_DEPTH = "MeshDepthMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_LAMBERT = "MeshLambertMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_NORMAL = "MeshNormalMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_PHONG = "MeshPhongMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_STANDARD = "MeshStandardMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_POINTS = "PointsMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_SPRITE = "SpriteMaterial"; -GameLib.D3.Material.MATERIAL_TYPE_MULTIPLE = "MultiMaterial"; +GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC = 0x1; +GameLib.D3.Material.MATERIAL_TYPE_LINE_DASHED = 0x2; +GameLib.D3.Material.MATERIAL_TYPE_BASIC = 0x3; +GameLib.D3.Material.MATERIAL_TYPE_DEPTH = 0x4; +GameLib.D3.Material.MATERIAL_TYPE_LAMBERT = 0x5; +GameLib.D3.Material.MATERIAL_TYPE_NORMAL = 0x6; +GameLib.D3.Material.MATERIAL_TYPE_PHONG = 0x7; +GameLib.D3.Material.MATERIAL_TYPE_STANDARD = 0x8; +GameLib.D3.Material.MATERIAL_TYPE_POINTS = 0x9; +GameLib.D3.Material.MATERIAL_TYPE_SPRITE = 0xa; GameLib.D3.Material.prototype.createStandardMaterialInstance = function() { return new THREE.MeshStandardMaterial({ @@ -689,28 +688,34 @@ GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function() { GameLib.D3.Material.prototype.createInstance = function(update) { if (update) { - + + var typeChange = false; + if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_STANDARD) { if (!(this.instance instanceof THREE.MeshStandardMaterial)) { this.instance = this.createStandardMaterialInstance(); + typeChange = true; } else { this.updateStandardMaterialInstance(); } } else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_POINTS) { if (!(this.instance instanceof THREE.PointsMaterial)) { this.instance = this.createPointsMaterialInstance(); + typeChange = true; } else { this.updatePointsMaterialInstance(); } } else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_PHONG) { if (!(this.instance instanceof THREE.MeshPhongMaterial)) { this.instance = this.createPhongMaterialInstance(); + typeChange = true; } else { this.updatePhongMaterialInstance(); } } else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_BASIC) { if (!(this.instance instanceof THREE.MeshBasicMaterial)) { this.instance = this.createMeshBasicMaterialInstance(); + typeChange = true; } else { this.updateMeshBasicMaterialInstance(); } @@ -720,8 +725,19 @@ GameLib.D3.Material.prototype.createInstance = function(update) { this.updateTextures(); + if (typeChange) { + this.publish( + GameLib.Event.MATERIAL_TYPE_CHANGED, + { + material: this + } + ); + } + this.instance.needsUpdate = true; + + } else { var instance = null; diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index 4f1c91d..641312c 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -447,6 +447,16 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) { } ); + this.subscribe( + GameLib.Event.MATERIAL_TYPE_CHANGED, + function(data) { + if (this.materials[0].id === data.material.id) { + this.instance.material = data.material.instance; + this.instance.geometry.uvsNeedUpdate = true; + } + } + ); + return instance; } }; diff --git a/src/game-lib-entity-manager.js b/src/game-lib-entity-manager.js index 9e33ffb..a90d91a 100644 --- a/src/game-lib-entity-manager.js +++ b/src/game-lib-entity-manager.js @@ -103,6 +103,13 @@ GameLib.EntityManager.prototype.createEntity = function(name) { this.entities.push(entity); + GameLib.Event.Emit( + GameLib.Event.NEW_ENTITY, + { + entity : entity + } + ); + return entity; }; diff --git a/src/game-lib-gui.js b/src/game-lib-gui.js index f84543f..ca247f3 100644 --- a/src/game-lib-gui.js +++ b/src/game-lib-gui.js @@ -269,7 +269,20 @@ GameLib.GUI.prototype.buildControl = function(folder, object, property, entityMa // ); // } else - if (object instanceof GameLib.D3.Material && property === 'side') { + if (object instanceof GameLib.D3.Material && property === 'materialType') { + handles.push( + folder.add( + object, + property, + { + 'standard': GameLib.D3.Material.MATERIAL_TYPE_STANDARD, + 'basic': GameLib.D3.Material.MATERIAL_TYPE_BASIC, + 'phong': GameLib.D3.Material.MATERIAL_TYPE_PHONG, + 'points': GameLib.D3.Material.MATERIAL_TYPE_POINTS + } + ).name(property).listen() + ); + } else if (object instanceof GameLib.D3.Material && property === 'side') { handles.push( folder.add( object,