exclude meshes from environment maps

beta.r3js.org
-=yb4f310 2018-02-08 14:21:31 +01:00
parent 08e92548ef
commit 25d79e72ea
11 changed files with 79 additions and 7 deletions

View File

@ -17,7 +17,7 @@ GameLib.Event.OnceSubscriptions = {};
*/
GameLib.Event.WINDOW_RESIZE = 0x1;
GameLib.Event.PARENT_SCENE_CHANGE = 0x2;
//GameLib.Event.PARENT_ENTITY_CHANGE = 0x3;
GameLib.Event.EXCLUDE_FROM_ENVIRONMENT = 0x3;
GameLib.Event.INSTANCE_CLONED = 0x4;
GameLib.Event.LOAD_IMAGE = 0x5;
GameLib.Event.NEW_ENTITY = 0x6;

View File

@ -2,7 +2,6 @@
* GameLib.D3.API.Mesh
* @param id
* @param meshType
* @param name
* @param vertices
* @param faces
@ -31,6 +30,7 @@ GameLib.D3.API.Mesh = function(
id,
name,
meshType,
excludeFromEnvironment,
vertices,
faces,
materials,
@ -99,6 +99,11 @@ GameLib.D3.API.Mesh = function(
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(excludeFromEnvironment)) {
excludeFromEnvironment = false;
}
this.excludeFromEnvironment = excludeFromEnvironment;
if (GameLib.Utils.UndefinedOrNull(vertices)) {
vertices = [];
}

View File

@ -43,6 +43,7 @@ GameLib.D3.API.Mesh.Box = function(
apiMesh.id,
apiMesh.name,
apiMesh.meshType,
apiMesh.excludeFromEnvironment,
apiMesh.vertices,
apiMesh.faces,
apiMesh.materials,

View File

@ -29,6 +29,7 @@ GameLib.D3.API.Mesh.Curve = function(
apiMesh.id,
apiMesh.name,
apiMesh.meshType,
apiMesh.excludeFromEnvironment,
apiMesh.vertices,
apiMesh.faces,
apiMesh.materials,

View File

@ -77,6 +77,7 @@ GameLib.D3.API.Mesh.Cylinder = function(
apiMesh.id,
apiMesh.name,
apiMesh.meshType,
apiMesh.excludeFromEnvironment,
apiMesh.vertices,
apiMesh.faces,
apiMesh.materials,

View File

@ -29,6 +29,7 @@ GameLib.D3.API.Mesh.Line = function(
apiMesh.id,
apiMesh.name,
apiMesh.meshType,
apiMesh.excludeFromEnvironment,
apiMesh.vertices,
apiMesh.faces,
apiMesh.materials,

View File

@ -99,6 +99,7 @@ GameLib.D3.API.Mesh.Plane = function(
apiMesh.id,
apiMesh.name,
apiMesh.meshType,
apiMesh.excludeFromEnvironment,
apiMesh.vertices,
apiMesh.faces,
apiMesh.materials,

View File

@ -43,6 +43,7 @@ GameLib.D3.API.Mesh.Sphere = function(
apiMesh.id,
apiMesh.name,
apiMesh.meshType,
apiMesh.excludeFromEnvironment,
apiMesh.vertices,
apiMesh.faces,
apiMesh.materials,

View File

@ -85,6 +85,7 @@ GameLib.D3.API.Mesh.Text = function(
apiMesh.id,
apiMesh.name,
apiMesh.meshType,
apiMesh.excludeFromEnvironment,
apiMesh.vertices,
apiMesh.faces,
apiMesh.materials,

View File

@ -22,6 +22,7 @@ GameLib.D3.Mesh = function (
apiMesh.id,
apiMesh.name,
apiMesh.meshType,
apiMesh.excludeFromEnvironment,
apiMesh.vertices,
apiMesh.faces,
apiMesh.materials,
@ -544,6 +545,15 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
console.warn('unknown mesh property update');
}
if (property === 'excludeFromEnvironment') {
GameLib.Event.Emit(
GameLib.Event.EXCLUDE_FROM_ENVIRONMENT,
{
component : this
}
)
}
if (property === 'isBufferMesh') {
if (( this.isBufferMesh && !(this.instance.geometry instanceof THREE.BufferGeometry)) ||
( !this.isBufferMesh && (this.instance.geometry instanceof THREE.BufferGeometry)))
@ -1044,6 +1054,7 @@ GameLib.D3.Mesh.prototype.toApiObject = function() {
this.id,
this.name,
this.meshType,
this.excludeFromEnvironment,
this.vertices.map(
function (vertex) {
return vertex.toApiObject();

View File

@ -26,6 +26,8 @@ GameLib.System.Render = function(
this.activeRenderConfiguration = null;
this.excludeFromEnvironmentSubscription = null;
/**
* Images
*/
@ -62,6 +64,21 @@ GameLib.System.Render.prototype.start = function() {
this.cubeCameras = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAMERA_CUBE);
this.excludedFromEnvironment = [];
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh).map(
function(mesh) {
if (mesh.excludeFromEnvironment) {
this.excludedFromEnvironment.push(mesh);
}
}.bind(this)
);
this.excludeFromEnvironmentSubscription = this.subscribe(
GameLib.Event.EXCLUDE_FROM_ENVIRONMENT,
this.excludeFromEnvironmentUpdate
);
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this)
@ -165,6 +182,20 @@ GameLib.System.Render.prototype.getRenderConfiguration = function (data, callbac
callback(this.activeRenderConfiguration);
};
GameLib.System.Render.prototype.excludeFromEnvironmentUpdate = function (data) {
if (data.component.excludeFromEnvironment) {
console.log('excluding ' + data.component.name + ' from environment');
GameLib.Utils.PushUnique(this.excludedFromEnvironment, data.component);
} else {
var index = this.excludedFromEnvironment.indexOf(data.component);
if (index !== -1) {
this.excludedFromEnvironment.splice(index,1);
}
console.log('including ' + data.component.name + ' in environment');
}
};
GameLib.System.Render.prototype.setActiveRenderConfiguration = function (data) {
if (this.renderConfigurations.indexOf(data.renderConfiguration) !== -1) {
@ -296,6 +327,13 @@ GameLib.System.Render.prototype.instanceCreated = function(data) {
this.cubeCameras.push(data.component);
}
if (
data.component instanceof GameLib.D3.Mesh &&
data.component.excludeFromEnvironment
) {
GameLib.Utils.PushUnique(this.excludedFromEnvironment, data.component);
}
if (data.component instanceof GameLib.D3.Texture) {
/**
@ -483,6 +521,14 @@ GameLib.System.Render.prototype.removeComponent = function(data) {
console.log('failed to find the cube camera in the system : ' + data.component.name);
}
}
if (data.component instanceof GameLib.D3.Mesh) {
index = this.excludedFromEnvironment.indexOf(data.component);
if (index !== -1) {
console.log('removing excluded environment mesh from system');
this.excludedFromEnvironment.splice(index, 1);
}
}
};
/**
@ -564,8 +610,8 @@ GameLib.System.Render.prototype.render = function(data) {
this.cubeCameras.map(
function(cubeCamera) {
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh.Box).map(
function(mesh) {
this.excludedFromEnvironment.map(
function(mesh){
mesh.visible = false;
mesh.updateInstance('visible');
}
@ -577,13 +623,14 @@ GameLib.System.Render.prototype.render = function(data) {
}
);
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh.Box).map(
function(mesh) {
this.excludedFromEnvironment.map(
function(mesh){
mesh.visible = true;
mesh.updateInstance('visible');
}
);
}
}.bind(this)
);
if (configuration.enableComposer) {
@ -656,6 +703,8 @@ GameLib.System.Render.prototype.stop = function() {
this.setActiveRenderConfigurationSubscription.remove();
this.excludeFromEnvironmentSubscription.remove();
/**
* Images
*/