diff --git a/src/game-lib-a-1-event.js b/src/game-lib-a-1-event.js index 17f0be4..70bcd07 100644 --- a/src/game-lib-a-1-event.js +++ b/src/game-lib-a-1-event.js @@ -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; diff --git a/src/game-lib-d3-api-mesh-0.js b/src/game-lib-d3-api-mesh-0.js index 21d05ee..06d7def 100644 --- a/src/game-lib-d3-api-mesh-0.js +++ b/src/game-lib-d3-api-mesh-0.js @@ -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 = []; } diff --git a/src/game-lib-d3-api-mesh-box.js b/src/game-lib-d3-api-mesh-box.js index 62dbcb8..f901e9a 100644 --- a/src/game-lib-d3-api-mesh-box.js +++ b/src/game-lib-d3-api-mesh-box.js @@ -43,6 +43,7 @@ GameLib.D3.API.Mesh.Box = function( apiMesh.id, apiMesh.name, apiMesh.meshType, + apiMesh.excludeFromEnvironment, apiMesh.vertices, apiMesh.faces, apiMesh.materials, diff --git a/src/game-lib-d3-api-mesh-curve.js b/src/game-lib-d3-api-mesh-curve.js index 9a14000..9321808 100644 --- a/src/game-lib-d3-api-mesh-curve.js +++ b/src/game-lib-d3-api-mesh-curve.js @@ -29,6 +29,7 @@ GameLib.D3.API.Mesh.Curve = function( apiMesh.id, apiMesh.name, apiMesh.meshType, + apiMesh.excludeFromEnvironment, apiMesh.vertices, apiMesh.faces, apiMesh.materials, diff --git a/src/game-lib-d3-api-mesh-cylinder.js b/src/game-lib-d3-api-mesh-cylinder.js index 6c254c9..49d6743 100644 --- a/src/game-lib-d3-api-mesh-cylinder.js +++ b/src/game-lib-d3-api-mesh-cylinder.js @@ -77,6 +77,7 @@ GameLib.D3.API.Mesh.Cylinder = function( apiMesh.id, apiMesh.name, apiMesh.meshType, + apiMesh.excludeFromEnvironment, apiMesh.vertices, apiMesh.faces, apiMesh.materials, diff --git a/src/game-lib-d3-api-mesh-line.js b/src/game-lib-d3-api-mesh-line.js index c819f20..e920897 100644 --- a/src/game-lib-d3-api-mesh-line.js +++ b/src/game-lib-d3-api-mesh-line.js @@ -29,6 +29,7 @@ GameLib.D3.API.Mesh.Line = function( apiMesh.id, apiMesh.name, apiMesh.meshType, + apiMesh.excludeFromEnvironment, apiMesh.vertices, apiMesh.faces, apiMesh.materials, diff --git a/src/game-lib-d3-api-mesh-plane.js b/src/game-lib-d3-api-mesh-plane.js index 44ea58d..6533d02 100644 --- a/src/game-lib-d3-api-mesh-plane.js +++ b/src/game-lib-d3-api-mesh-plane.js @@ -99,6 +99,7 @@ GameLib.D3.API.Mesh.Plane = function( apiMesh.id, apiMesh.name, apiMesh.meshType, + apiMesh.excludeFromEnvironment, apiMesh.vertices, apiMesh.faces, apiMesh.materials, diff --git a/src/game-lib-d3-api-mesh-sphere.js b/src/game-lib-d3-api-mesh-sphere.js index 972b75c..3f5093c 100644 --- a/src/game-lib-d3-api-mesh-sphere.js +++ b/src/game-lib-d3-api-mesh-sphere.js @@ -43,6 +43,7 @@ GameLib.D3.API.Mesh.Sphere = function( apiMesh.id, apiMesh.name, apiMesh.meshType, + apiMesh.excludeFromEnvironment, apiMesh.vertices, apiMesh.faces, apiMesh.materials, diff --git a/src/game-lib-d3-api-mesh-text.js b/src/game-lib-d3-api-mesh-text.js index c90eb0f..6961fec 100644 --- a/src/game-lib-d3-api-mesh-text.js +++ b/src/game-lib-d3-api-mesh-text.js @@ -85,6 +85,7 @@ GameLib.D3.API.Mesh.Text = function( apiMesh.id, apiMesh.name, apiMesh.meshType, + apiMesh.excludeFromEnvironment, apiMesh.vertices, apiMesh.faces, apiMesh.materials, diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index ed01064..1951eb1 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -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(); diff --git a/src/game-lib-system-render.js b/src/game-lib-system-render.js index 1992a73..557acb8 100644 --- a/src/game-lib-system-render.js +++ b/src/game-lib-system-render.js @@ -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 */