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,33 +76,46 @@ GameLib.D3.Fog.prototype.createInstance = function() {
}; };
GameLib.D3.Fog.prototype.updateInstance = function() { GameLib.D3.Fog.prototype.updateInstance = function(property) {
if ( if (property === 'exponential') {
this.exponential && if (
!(this.instance instanceof THREE.FogExp2) this.exponential &&
) { !(this.instance instanceof THREE.FogExp2)
this.createInstance(); ) {
return; this.createInstance();
return;
}
if (
!this.exponential &&
!(this.instance instanceof THREE.Fog)
) {
this.createInstance();
return;
}
} }
if ( if (property === 'color') {
!this.exponential && this.color.instance.setRGB(
!(this.instance instanceof THREE.Fog) this.color.r,
) { this.color.g,
this.createInstance(); this.color.b
return; );
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 (this.instance instanceof THREE.FogExp2) { if (property === 'density') {
this.instance.density = this.density; if (this.instance instanceof THREE.FogExp2) {
this.instance.density = this.density;
}
} }
}; };

View File

@ -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) { if (!this.instance) {
try { try {
this.createInstance(); this.createInstance();
} catch (error) { } catch (error) {
console.error(error.message); console.error(error.message);
return;
} }
return;
} }
this.instance.localClippingEnabled = this.localClipping; if (!property) {
console.error('no property for renderer');
}
this.instance.setSize( if (property === 'localClipping') {
this.width, this.instance.localClippingEnabled = this.localClipping;
this.height }
);
this.instance.setClearColor( if (property === 'width' || 'height') {
new THREE.Color( this.instance.setSize(
this.clearColor.r, this.width,
this.clearColor.g, this.height
this.clearColor.b );
),
1 - this.clearColor.a
);
this.instance.domElement.width = this.width; this.instance.domElement.width = this.width;
this.instance.domElement.height = this.height; 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) { 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 = [];
} }
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) { 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
);
}; };