From 453ec6d498ee75b2a4bddfe1181d058c70b0b58f Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Thu, 8 Feb 2018 09:03:17 +0100 Subject: [PATCH] start to fix cube camera --- src/game-lib-a-1-event.js | 4 +- src/game-lib-a-component-a.js | 15 +++- src/game-lib-d3-api-render-target-a.js | 98 ++++++++++++++--------- src/game-lib-d3-api-render-target-cube.js | 10 +++ src/game-lib-d3-camera-cube.js | 13 +-- src/game-lib-d3-render-target-a.js | 12 +-- src/game-lib-d3-render-target-cube.js | 33 ++++---- src/game-lib-d3-texture-a.js | 37 ++++----- src/game-lib-d3-texture-cube.js | 2 +- src/game-lib-d3-texture-image.js | 11 ++- src/game-lib-system-gui.js | 3 +- src/game-lib-system-linking.js | 36 --------- src/game-lib-system-render.js | 45 ++++++++++- 13 files changed, 177 insertions(+), 142 deletions(-) diff --git a/src/game-lib-a-1-event.js b/src/game-lib-a-1-event.js index a94eaaf..4c42acd 100644 --- a/src/game-lib-a-1-event.js +++ b/src/game-lib-a-1-event.js @@ -61,7 +61,7 @@ GameLib.Event.RENDER = 0x2b; GameLib.Event.EVENT_LIST = 0x2c; GameLib.Event.COMPILE_SUCCESS = 0x2d; GameLib.Event.COMPILE_FAILED = 0x2e; -GameLib.Event.IMAGE_CHANGED = 0x2f; +GameLib.Event.TEXTURE_IMAGE_UPDATED = 0x2f; //GameLib.Event.PARENT_ENTITY_CHANGED = 0x30; GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31; GameLib.Event.DELETE_COMPONENT_ERROR = 0x32; @@ -188,7 +188,7 @@ GameLib.Event.GetEventName = function(number) { case 0x2c : return 'event_list'; case 0x2d : return 'compile_success'; case 0x2e : return 'compile_failed'; - case 0x2f : return 'image_changed'; + case 0x2f : return 'texture_image_updated'; case 0x30 : return 'unused'; case 0x31 : return 'material_textures_updated'; case 0x32 : return 'delete_component_error'; diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 529f1cf..705c5bb 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -277,7 +277,7 @@ GameLib.Component.SHAPE_CONVEX_HULL = 0x2c; GameLib.Component.SHAPE_CONVEX_HULL_CYLINDER = 0x2d; GameLib.Component.SHAPE_HEIGHT_MAP = 0x2e; GameLib.Component.SHAPE_PLANE = 0x2f; -//GameLib.Component.CONTROLS = 0x30; +GameLib.Component.CONTROLS = 0x30; GameLib.Component.CONTROLS_EDITOR = 0x31; GameLib.Component.CONTROLS_TOUCH = 0x32; GameLib.Component.FRICTION_MATERIAL = 0x33; @@ -332,7 +332,8 @@ GameLib.Component.PASS_BLOOM = 0x63; GameLib.Component.PASS_FXAA = 0x64; GameLib.Component.RENDER_CONFIGURATION = 0x65; GameLib.Component.MATERIAL_BASIC = 0x66; -GameLib.Component.MAX_COMPONENTS = 0x67; +GameLib.Component.TEXTURE = 0x67; +GameLib.Component.MAX_COMPONENTS = 0x68; GameLib.Component.GRAPHICS_RUNTIME = 0x1; GameLib.Component.PHYSICS_RUNTIME = 0x2; @@ -635,12 +636,12 @@ GameLib.Component.GetComponentInfo = function(number) { constructor : GameLib.D3.Shape.Plane, apiConstructor : GameLib.D3.API.Shape }; - case 0x30 : return null;/*return { + case 0x30 : return { name : 'GameLib.Controls', runtime : GameLib.Component.DEFAULT_RUNTIME, constructor : GameLib.Controls, apiConstructor : GameLib.API.Controls - };*/ + }; case 0x31 : return { name : 'GameLib.Controls.D3.Editor', runtime : GameLib.Component.GRAPHICS_RUNTIME, @@ -965,6 +966,12 @@ GameLib.Component.GetComponentInfo = function(number) { constructor : GameLib.D3.Material.Basic, apiConstructor : GameLib.D3.API.Material.Basic }; + case 0x67 : return { + name : 'GameLib.D3.Texture', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Texture, + apiConstructor : GameLib.D3.API.Texture + }; break; } diff --git a/src/game-lib-d3-api-render-target-a.js b/src/game-lib-d3-api-render-target-a.js index 1d9f2da..ee17a6e 100644 --- a/src/game-lib-d3-api-render-target-a.js +++ b/src/game-lib-d3-api-render-target-a.js @@ -27,16 +27,26 @@ GameLib.D3.API.RenderTarget = function ( } this.id = id; - if (GameLib.Utils.UndefinedOrNull(name)) { - name = 'Render Target (' + id + ')'; - } - this.name = name; - if (GameLib.Utils.UndefinedOrNull(renderTargetType)) { renderTargetType = GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL; } this.renderTargetType = renderTargetType; + if (GameLib.Utils.UndefinedOrNull(name)) { + + switch (this.renderTargetType) { + case GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE : + name = 'Render Target Cube'; + break; + default: + console.log('just a normal render target'); + name = 'Render Target'; + } + + name += ' (' + id + ')'; + } + this.name = name; + if (GameLib.Utils.UndefinedOrNull(width)) { width = 512; } @@ -58,44 +68,34 @@ GameLib.D3.API.RenderTarget = function ( this.textureParameters = textureParameters; if (GameLib.Utils.UndefinedOrNull(texture)) { - - switch (this.renderTargetType) { - case GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL : - - texture = new GameLib.D3.API.Texture( - null, - 'Texture (Render Target ' + this.id + ')', - GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE - ); - break; - - case GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE : - - texture = new GameLib.D3.API.Texture( - null, - 'Cube Texture (Render Target ' + this.id + ')', - GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE - ); - break; - - default : - throw new Error('Unknown render target type: ' + this.renderTargetType); - } + texture = null; + // + // switch (this.renderTargetType) { + // case GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL : + // + // texture = new GameLib.D3.API.Texture( + // null, + // 'Texture (Render Target ' + this.id + ')', + // GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE + // ); + // break; + // + // case GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE : + // + // texture = new GameLib.D3.API.Texture( + // null, + // 'Cube Texture (Render Target ' + this.id + ')', + // GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE + // ); + // break; + // + // default : + // throw new Error('Unknown render target type: ' + this.renderTargetType); + // } } this.texture = texture; - var componentType = null; - - switch (this.renderTargetType) { - case GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL : - componentType = GameLib.Component.RENDER_TARGET; - break; - case GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE : - componentType = GameLib.Component.RENDER_TARGET_CUBE; - break; - default : - throw new Error('Unknown render target type: ' + this.renderTargetType); - } + var componentType = GameLib.D3.API.RenderTarget.GetComponentType(this.renderTargetType); GameLib.API.Component.call( this, @@ -105,6 +105,24 @@ GameLib.D3.API.RenderTarget = function ( }; +GameLib.D3.API.RenderTarget.GetComponentType = function(renderTargetType) { + + var componentType = null; + + switch (renderTargetType) { + case GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL : + componentType = GameLib.Component.RENDER_TARGET; + break; + case GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE : + componentType = GameLib.Component.RENDER_TARGET_CUBE; + break; + default : + throw new Error('Unknown render target type: ' + renderTargetType); + } + + return componentType; +}; + GameLib.D3.API.RenderTarget.prototype = Object.create(GameLib.API.Component.prototype); GameLib.D3.API.RenderTarget.prototype.constructor = GameLib.D3.API.RenderTarget; diff --git a/src/game-lib-d3-api-render-target-cube.js b/src/game-lib-d3-api-render-target-cube.js index be38099..8b424f3 100644 --- a/src/game-lib-d3-api-render-target-cube.js +++ b/src/game-lib-d3-api-render-target-cube.js @@ -17,6 +17,16 @@ GameLib.D3.API.RenderTarget.Cube = function ( apiRenderTarget.renderTargetType = GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE; } + if (GameLib.Utils.UndefinedOrNull(apiRenderTarget.textureParameters)) { + apiRenderTarget.textureParameters = { + minFilter : GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER + } + } + + if (GameLib.Utils.UndefinedOrNull(apiRenderTarget.textureParameters.minFilter)) { + apiRenderTarget.textureParameters.minFilter = GameLib.D3.API.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER; + } + GameLib.D3.API.RenderTarget.call( this, apiRenderTarget.id, diff --git a/src/game-lib-d3-camera-cube.js b/src/game-lib-d3-camera-cube.js index 6a9bbd1..e002cc2 100644 --- a/src/game-lib-d3-camera-cube.js +++ b/src/game-lib-d3-camera-cube.js @@ -27,8 +27,8 @@ GameLib.D3.Camera.Cube = function( apiCubeCamera.renderTarget ); - if (this.renderTarget instanceof GameLib.D3.API.RenderTarget) { - this.renderTarget = new GameLib.D3.RenderTarget( + if (this.renderTarget instanceof GameLib.D3.API.RenderTarget.Cube) { + this.renderTarget = new GameLib.D3.RenderTarget.Cube( this.graphics, this.renderTarget ) @@ -57,16 +57,11 @@ GameLib.D3.Camera.Cube.prototype.createInstance = function() { this.cubeResolution ); - /** - if (this.renderTarget && this.renderTarget.instance) { - this.instance.renderTarget = this.renderTarget.instance; - }*/ - this.renderTarget.instance = this.instance.renderTarget; this.renderTarget.instance.texture = this.instance.renderTarget.texture; - - this.renderTarget.texture.instance = this.instance.renderTarget.texture; + // + // this.renderTarget.texture.instance = this.instance.renderTarget.texture; GameLib.D3.Camera.prototype.createInstance.call(this); }; diff --git a/src/game-lib-d3-render-target-a.js b/src/game-lib-d3-render-target-a.js index d38c791..b871ec2 100644 --- a/src/game-lib-d3-render-target-a.js +++ b/src/game-lib-d3-render-target-a.js @@ -30,12 +30,12 @@ GameLib.D3.RenderTarget = function ( apiRenderTarget.texture ); - if (this.texture instanceof GameLib.D3.API.Texture) { - this.texture = new GameLib.D3.Texture( - this.graphics, - this.texture - ) - } + // if (this.texture instanceof GameLib.D3.API.Texture) { + // this.texture = new GameLib.D3.Texture( + // this.graphics, + // this.texture + // ) + // } GameLib.Component.call( this, diff --git a/src/game-lib-d3-render-target-cube.js b/src/game-lib-d3-render-target-cube.js index 891a957..9ba2379 100644 --- a/src/game-lib-d3-render-target-cube.js +++ b/src/game-lib-d3-render-target-cube.js @@ -39,12 +39,12 @@ GameLib.D3.RenderTarget.Cube.prototype.constructor = GameLib.D3.RenderTarget.Cub */ GameLib.D3.RenderTarget.Cube.prototype.createInstance = function() { - if (GameLib.Utils.UndefinedOrNull(this.texture)) { - throw new Error('no texture'); - } - - if (GameLib.Utils.UndefinedOrNull(this.texture.instance)) { - throw new Error('no texture instance'); + if ( + GameLib.Utils.UndefinedOrNull(this.texture) || + GameLib.Utils.UndefinedOrNull(this.texture.instance) + ) { + console.warn('render target texture not ready'); + return; } this.instance = new THREE.WebGLRenderTargetCube( @@ -53,16 +53,12 @@ GameLib.D3.RenderTarget.Cube.prototype.createInstance = function() { this.textureParameters ); - this.instance.texture.minFilter = THREE.LinearMipMapLinearFilter; - /** * The instance texture is automatically generated - we assign it to our texture and update from instance */ - //this.texture.instance = this.instance.texture; - //this.texture.updateFromInstance(); - - //this.instance.texture = this.texture.instance; + this.texture.instance = this.instance.texture; + this.texture.updateFromInstance(); GameLib.Component.prototype.createInstance.call(this); }; @@ -72,6 +68,15 @@ GameLib.D3.RenderTarget.Cube.prototype.createInstance = function() { */ GameLib.D3.RenderTarget.Cube.prototype.updateInstance = function(property) { + if (property === 'texture') { + if (GameLib.Utils.UndefinedOrNull(this.instance)) { + this.createInstance(); + } else { + this.instance.dispose(); + this.createInstance(); + } + } + if ( property === 'width' || property === 'height' @@ -83,9 +88,7 @@ GameLib.D3.RenderTarget.Cube.prototype.updateInstance = function(property) { this.instance.stencilBuffer = this.stencilBuffer; } - if (property === 'texture') { - this.instance.texture = this.texture.instance; - } + }; diff --git a/src/game-lib-d3-texture-a.js b/src/game-lib-d3-texture-a.js index ff358fe..8aaf802 100644 --- a/src/game-lib-d3-texture-a.js +++ b/src/game-lib-d3-texture-a.js @@ -3,6 +3,7 @@ * created * @param apiTexture * @param graphics GameLib.GraphicsRuntime + * @property textureType * @constructor */ GameLib.D3.Texture = function( @@ -50,29 +51,23 @@ GameLib.D3.Texture = function( apiTexture.forward ); - if (this.offset instanceof GameLib.API.Vector2) { - this.offset = new GameLib.Vector2( - this.graphics, - this.offset, - this - ) - } + this.offset = new GameLib.Vector2( + this.graphics, + this.offset, + this + ); - if (this.repeat instanceof GameLib.API.Vector2) { - this.repeat = new GameLib.Vector2( - this.graphics, - this.repeat, - this - ) - } + this.repeat = new GameLib.Vector2( + this.graphics, + this.repeat, + this + ); - if (this.center instanceof GameLib.API.Vector2) { - this.center = new GameLib.Vector2( - this.graphics, - this.center, - this - ) - } + this.center = new GameLib.Vector2( + this.graphics, + this.center, + this + ); var linkedObjects = {}; diff --git a/src/game-lib-d3-texture-cube.js b/src/game-lib-d3-texture-cube.js index 5303514..e9d7054 100644 --- a/src/game-lib-d3-texture-cube.js +++ b/src/game-lib-d3-texture-cube.js @@ -107,7 +107,7 @@ GameLib.D3.Texture.Cube.prototype.updateInstance = function(property) { } this.publish( - GameLib.Event.IMAGE_CHANGED, + GameLib.Event.TEXTURE_IMAGE_UPDATED, { texture : this } diff --git a/src/game-lib-d3-texture-image.js b/src/game-lib-d3-texture-image.js index 47cf056..963e4ab 100644 --- a/src/game-lib-d3-texture-image.js +++ b/src/game-lib-d3-texture-image.js @@ -68,15 +68,18 @@ GameLib.D3.Texture.Image.prototype.updateInstance = function(property) { if (property === 'image') { + if (this.image && this.image.instance) { + this.instance.image = this.image.instance; + this.instance.needsUpdate = true; + } + this.publish( - GameLib.Event.IMAGE_CHANGED, + GameLib.Event.TEXTURE_IMAGE_UPDATED, { texture : this } ); - - this.instance.needsUpdate = true; - + return; } diff --git a/src/game-lib-system-gui.js b/src/game-lib-system-gui.js index aa13fd5..0524ff6 100644 --- a/src/game-lib-system-gui.js +++ b/src/game-lib-system-gui.js @@ -1610,7 +1610,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, ) { controllers.push(folder.add(object, property, -Math.PI * 2, Math.PI * 2, 0.01)); } else if ( - property === 'port' + property === 'port' || + property === 'far' ) { controllers.push(folder.add(object, property, 1, 65536, 1)); } else if ( diff --git a/src/game-lib-system-linking.js b/src/game-lib-system-linking.js index 20a92be..a76e8aa 100644 --- a/src/game-lib-system-linking.js +++ b/src/game-lib-system-linking.js @@ -49,11 +49,6 @@ GameLib.System.Linking = function( */ this.removeMeshSubscription = null; - /** - * Images - */ - this.imageChangedSubscription = null; - /** * Materials */ @@ -135,14 +130,6 @@ GameLib.System.Linking.prototype.start = function() { this.removeMesh ); - /** - * Images - */ - this.imageChangedSubscription = this.subscribe( - GameLib.Event.IMAGE_CHANGED, - this.imageChanged - ); - /** * Materials */ @@ -559,24 +546,6 @@ GameLib.System.Linking.prototype.removeComponent = function(data) { // } }; -GameLib.System.Linking.prototype.imageChanged = function(data) { - - var materials = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.MATERIAL); - - materials.map(function(material){ - - var textures = material.getTextures(); - - if (textures.indexOf(data.texture) !== -1) { - if (material.loaded) { - material.updateInstance('diffuseMap'); - } - } - - }); - -}; - GameLib.System.Linking.prototype.arrayItemAdded = function(data) { if ( data.component instanceof GameLib.D3.PhysicsWorld && @@ -930,11 +899,6 @@ GameLib.System.Linking.prototype.stop = function() { */ this.removeMeshSubscription.remove(); - /** - * Images - */ - this.imageChangedSubscription.remove(); - /** * Materials */ diff --git a/src/game-lib-system-render.js b/src/game-lib-system-render.js index 446b653..07dc07e 100644 --- a/src/game-lib-system-render.js +++ b/src/game-lib-system-render.js @@ -26,6 +26,11 @@ GameLib.System.Render = function( this.activeRenderConfiguration = null; + /** + * Images + */ + this.imageChangedSubscription = null; + this.renderConfigurations = []; this.renderers = []; @@ -82,12 +87,17 @@ GameLib.System.Render.prototype.start = function() { this.windowResize ); - this.getRenderConfigurationSubscription = this.subscribe( + this.imageChangedSubscription = this.subscribe( + GameLib.Event.TEXTURE_IMAGE_UPDATED, + this.imageChanged + ); + + this.getRenderConfigurationSubscription = this.subscribe( GameLib.Event.GET_RENDER_CONFIGURATION, this.getRenderConfiguration ); - this.setACtiveRenderConfigurationSubscription = this.subscribe( + this.setActiveRenderConfigurationSubscription = this.subscribe( GameLib.Event.SET_ACTIVE_RENDER_CONFIGURATION, this.setActiveRenderConfiguration ); @@ -221,6 +231,30 @@ GameLib.System.Render.prototype.windowResize = function(data) { }; +GameLib.System.Render.prototype.imageChanged = function(data) { + + // var textures = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Texture).map( + // function(texture) { + // if (texture.image ===) + // } + // ); + + var materials = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Material); + + materials.map(function(material){ + + var textures = material.getTextures(); + + if (textures.indexOf(data.texture) !== -1) { + if (material.loaded) { + material.updateInstance('diffuseMap'); + } + } + + }); + +}; + /** * From now on we want to track everything about a component, only from the systems that are active * @param data @@ -593,7 +627,12 @@ GameLib.System.Render.prototype.stop = function() { this.getRenderConfigurationSubscription.remove(); - this.setACtiveRenderConfigurationSubscription.remove(); + this.setActiveRenderConfigurationSubscription.remove(); + + /** + * Images + */ + this.imageChangedSubscription.remove(); // this.delayedInstanceEncounteredSubscription.remove();