change material type fixed finally
parent
4cad81bb8f
commit
0e9a760d17
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue