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.WINDOW_RESIZE = 0x1;
GameLib.Event.PARENT_SCENE_CHANGE = 0x2; 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.INSTANCE_CLONED = 0x4;
GameLib.Event.LOAD_IMAGE = 0x5; GameLib.Event.LOAD_IMAGE = 0x5;
GameLib.Event.NEW_ENTITY = 0x6; GameLib.Event.NEW_ENTITY = 0x6;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,6 +26,8 @@ GameLib.System.Render = function(
this.activeRenderConfiguration = null; this.activeRenderConfiguration = null;
this.excludeFromEnvironmentSubscription = null;
/** /**
* Images * Images
*/ */
@ -62,6 +64,21 @@ GameLib.System.Render.prototype.start = function() {
this.cubeCameras = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAMERA_CUBE); 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( this.instanceCreatedSubscription = GameLib.Event.Subscribe(
GameLib.Event.INSTANCE_CREATED, GameLib.Event.INSTANCE_CREATED,
this.instanceCreated.bind(this) this.instanceCreated.bind(this)
@ -165,6 +182,20 @@ GameLib.System.Render.prototype.getRenderConfiguration = function (data, callbac
callback(this.activeRenderConfiguration); 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) { GameLib.System.Render.prototype.setActiveRenderConfiguration = function (data) {
if (this.renderConfigurations.indexOf(data.renderConfiguration) !== -1) { if (this.renderConfigurations.indexOf(data.renderConfiguration) !== -1) {
@ -296,6 +327,13 @@ GameLib.System.Render.prototype.instanceCreated = function(data) {
this.cubeCameras.push(data.component); 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) { 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); 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( this.cubeCameras.map(
function(cubeCamera) { function(cubeCamera) {
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh.Box).map( this.excludedFromEnvironment.map(
function(mesh) { function(mesh){
mesh.visible = false; mesh.visible = false;
mesh.updateInstance('visible'); mesh.updateInstance('visible');
} }
@ -577,13 +623,14 @@ GameLib.System.Render.prototype.render = function(data) {
} }
); );
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh.Box).map( this.excludedFromEnvironment.map(
function(mesh) { function(mesh){
mesh.visible = true; mesh.visible = true;
mesh.updateInstance('visible'); mesh.updateInstance('visible');
} }
); );
}
}.bind(this)
); );
if (configuration.enableComposer) { if (configuration.enableComposer) {
@ -656,6 +703,8 @@ GameLib.System.Render.prototype.stop = function() {
this.setActiveRenderConfigurationSubscription.remove(); this.setActiveRenderConfigurationSubscription.remove();
this.excludeFromEnvironmentSubscription.remove();
/** /**
* Images * Images
*/ */