From b16492f34708c23907c7ebe9043554897b1ea60b Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Tue, 14 Nov 2017 09:37:48 +0100 Subject: [PATCH] fog updates --- src/game-lib-d3-fog.js | 53 ++++++++++++++++++------------ src/game-lib-d3-renderer.js | 64 +++++++++++++++++++++++++------------ 2 files changed, 76 insertions(+), 41 deletions(-) diff --git a/src/game-lib-d3-fog.js b/src/game-lib-d3-fog.js index dd779f6..7cec179 100644 --- a/src/game-lib-d3-fog.js +++ b/src/game-lib-d3-fog.js @@ -76,33 +76,46 @@ GameLib.D3.Fog.prototype.createInstance = function() { }; -GameLib.D3.Fog.prototype.updateInstance = function() { +GameLib.D3.Fog.prototype.updateInstance = function(property) { - if ( - this.exponential && - !(this.instance instanceof THREE.FogExp2) - ) { - this.createInstance(); - return; + if (property === 'exponential') { + if ( + this.exponential && + !(this.instance instanceof THREE.FogExp2) + ) { + this.createInstance(); + return; + } + + if ( + !this.exponential && + !(this.instance instanceof THREE.Fog) + ) { + this.createInstance(); + return; + } } - if ( - !this.exponential && - !(this.instance instanceof THREE.Fog) - ) { - this.createInstance(); - return; + if (property === 'color') { + this.color.instance.setRGB( + this.color.r, + this.color.g, + this.color.b + ); + this.instance.color = this.color.instance; } - this.instance.color = this.color.instance; - - if (this.instance instanceof THREE.Fog) { - this.instance.near = this.near; - this.instance.far = this.far; + if (property === 'near' || property === 'far') { + if (this.instance instanceof THREE.Fog) { + this.instance.near = this.near; + this.instance.far = this.far; + } } - if (this.instance instanceof THREE.FogExp2) { - this.instance.density = this.density; + if (property === 'density') { + if (this.instance instanceof THREE.FogExp2) { + this.instance.density = this.density; + } } }; diff --git a/src/game-lib-d3-renderer.js b/src/game-lib-d3-renderer.js index 4b09646..01edd1d 100644 --- a/src/game-lib-d3-renderer.js +++ b/src/game-lib-d3-renderer.js @@ -209,38 +209,55 @@ GameLib.D3.Renderer.prototype.createInstance = function() { /** * */ -GameLib.D3.Renderer.prototype.updateInstance = function() { +GameLib.D3.Renderer.prototype.updateInstance = function(property) { if (!this.instance) { try { this.createInstance(); } catch (error) { console.error(error.message); - return; } + return; } - this.instance.localClippingEnabled = this.localClipping; + if (!property) { + console.error('no property for renderer'); + } - this.instance.setSize( - this.width, - this.height - ); + if (property === 'localClipping') { + this.instance.localClippingEnabled = this.localClipping; + } - this.instance.setClearColor( - new THREE.Color( - this.clearColor.r, - this.clearColor.g, - this.clearColor.b - ), - 1 - this.clearColor.a - ); + if (property === 'width' || 'height') { + this.instance.setSize( + this.width, + this.height + ); - this.instance.domElement.width = this.width; - this.instance.domElement.height = this.height; + this.instance.domElement.width = this.width; + this.instance.domElement.height = this.height; + } - this.instance.autoClear = this.autoClear; - this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer; + + if (property === 'clearColor') { + this.instance.setClearColor( + new THREE.Color( + this.clearColor.r, + this.clearColor.g, + this.clearColor.b + ), + 1 - this.clearColor.a + ); + } + + + if (property === 'autoClear') { + this.instance.autoClear = this.autoClear; + } + + if (property === 'preserveDrawingBuffer') { + this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer; + } if (this.clippingPlanes.length > 0) { this.instance.clippingPlanes = this.clippingPlanes.map( @@ -257,7 +274,9 @@ GameLib.D3.Renderer.prototype.updateInstance = function() { this.instance.clippingPlanes = []; } - this.instance.sortObjects = this.sortObjects; + if (property === 'sortObjects') { + this.instance.sortObjects = this.sortObjects; + } }; /** @@ -403,6 +422,9 @@ GameLib.D3.Renderer.prototype.render = function(delta, scenes) { GameLib.D3.Renderer.prototype.setSize = function(width, height) { this.width = width; this.height = height; - this.updateInstance(); + this.instance.setSize( + this.width, + this.height + ); };