fog updates

beta.r3js.org
-=yb4f310 2017-11-14 09:37:48 +01:00
parent 5bc7bf611d
commit b16492f347
2 changed files with 76 additions and 41 deletions

View File

@ -76,8 +76,9 @@ GameLib.D3.Fog.prototype.createInstance = function() {
}; };
GameLib.D3.Fog.prototype.updateInstance = function() { GameLib.D3.Fog.prototype.updateInstance = function(property) {
if (property === 'exponential') {
if ( if (
this.exponential && this.exponential &&
!(this.instance instanceof THREE.FogExp2) !(this.instance instanceof THREE.FogExp2)
@ -93,17 +94,29 @@ GameLib.D3.Fog.prototype.updateInstance = function() {
this.createInstance(); this.createInstance();
return; 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 (property === 'near' || property === 'far') {
if (this.instance instanceof THREE.Fog) { if (this.instance instanceof THREE.Fog) {
this.instance.near = this.near; this.instance.near = this.near;
this.instance.far = this.far; this.instance.far = this.far;
} }
}
if (property === 'density') {
if (this.instance instanceof THREE.FogExp2) { if (this.instance instanceof THREE.FogExp2) {
this.instance.density = this.density; this.instance.density = this.density;
} }
}
}; };

View File

@ -209,24 +209,37 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
/** /**
* *
*/ */
GameLib.D3.Renderer.prototype.updateInstance = function() { GameLib.D3.Renderer.prototype.updateInstance = function(property) {
if (!this.instance) { if (!this.instance) {
try { try {
this.createInstance(); this.createInstance();
} catch (error) { } catch (error) {
console.error(error.message); console.error(error.message);
}
return; return;
} }
if (!property) {
console.error('no property for renderer');
} }
if (property === 'localClipping') {
this.instance.localClippingEnabled = this.localClipping; this.instance.localClippingEnabled = this.localClipping;
}
if (property === 'width' || 'height') {
this.instance.setSize( this.instance.setSize(
this.width, this.width,
this.height this.height
); );
this.instance.domElement.width = this.width;
this.instance.domElement.height = this.height;
}
if (property === 'clearColor') {
this.instance.setClearColor( this.instance.setClearColor(
new THREE.Color( new THREE.Color(
this.clearColor.r, this.clearColor.r,
@ -235,12 +248,16 @@ GameLib.D3.Renderer.prototype.updateInstance = function() {
), ),
1 - this.clearColor.a 1 - this.clearColor.a
); );
}
this.instance.domElement.width = this.width;
this.instance.domElement.height = this.height;
if (property === 'autoClear') {
this.instance.autoClear = this.autoClear; this.instance.autoClear = this.autoClear;
}
if (property === 'preserveDrawingBuffer') {
this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer; this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
}
if (this.clippingPlanes.length > 0) { if (this.clippingPlanes.length > 0) {
this.instance.clippingPlanes = this.clippingPlanes.map( this.instance.clippingPlanes = this.clippingPlanes.map(
@ -257,7 +274,9 @@ GameLib.D3.Renderer.prototype.updateInstance = function() {
this.instance.clippingPlanes = []; this.instance.clippingPlanes = [];
} }
if (property === 'sortObjects') {
this.instance.sortObjects = this.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) { GameLib.D3.Renderer.prototype.setSize = function(width, height) {
this.width = width; this.width = width;
this.height = height; this.height = height;
this.updateInstance(); this.instance.setSize(
this.width,
this.height
);
}; };