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 (
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;
}
}
};

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) {
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
);
};