HTML5+CSS on Canvas 3D WebGL (TM) Library
 

ambientAdjust Library Method

Short Description: Ajust Ambient Color

Signature: x.ambientAdjust (f[,d,[a]])
Class: taccglMTLFile Class
 

"Repairs" ambient (and possibly adapts diffuse) colors in a model that does not have correct ambient color definitions. Obviously the "right" thing to do would be to fix models with ambient color problems within the program that created them. However, often this method is a good work around.

ambientAdjust sets the ambient light adjustment factor f. This is useful if you, for some reason, do not set the ambient color in the MTL file. Per default f is 0, which does not modify the ambient color values in the MTL file. If f>0 the diffuse color is multiplied by f and added to the ambient color.

In addition the diffuse factor d can be set. The diffuse factor d defaults to 1. If specified all diffuse color values in the MTL file are multiplied by d. Typically a value <1 is used to reduce diffuse colors a bit in order to compensate for increased ambient colors using f.

The ambient color factor a defaults to 1. All ambient color values in the MTL file are multiplied by a. For example a value of a=0 is useful in case ambient color values in the file are broken and should not be used.

If taccgl™ detects that all ambient color values in a file created with blender are 0 then it automatically does ambientAdjust (0.6,0.6). If all ambient color values are >0.8 or 0 then ambientAdjust (0.6,0.6,0). If this is not intended, ambientAdjust can be called again before the model is used, to set correct values.

In the sample MTL file used for the examples below, the ambient color has not been set at all, i.e. it is (0,0,0). ambientAdjust is used to set the ambient color to a certain percentage of the diffuse Color in the MTL file.

Examples

var to=taccgl.objFile().read('/objtest/taccgldoc.obj',false);
to.mtl.ambientAdjust(0.4);
var a=taccgl.a("Layout",to.scene()).modFit(). rotateMiddle(Math.sqrt(1/3),Math.sqrt(1/3),Math.sqrt(1/3)).dur(8).start();
RUN
var to=taccgl.objFile().read('/objtest/taccgldoc.obj',false);
to.mtl.ambientAdjust(0.0);
var a=taccgl.a("Layout",to.scene()).modFit(). rotateMiddle(Math.sqrt(1/3),Math.sqrt(1/3),Math.sqrt(1/3)).dur(8).start();
RUN
var to=taccgl.objFile().read('/objtest/taccgldoc.obj',false);
to.mtl.ambientAdjust(0.8,0.4);
var a=taccgl.a("Layout",to.scene()).modFit(). rotateMiddle(Math.sqrt(1/3),Math.sqrt(1/3),Math.sqrt(1/3)).dur(8).start();
RUN
var to=taccgl.objFile().read('/objtest/taccgldoc.obj',false);
to.mtl.ambientAdjust(0.6,0.6);
var a=taccgl.a("Layout",to.scene()).modFit(). rotateMiddle(Math.sqrt(1/3),Math.sqrt(1/3),Math.sqrt(1/3)).dur(8).start();
RUN
var to=taccgl.objFile().read('/objtest/taccgldoc.obj',false);
to.mtl.ambientAdjust(0.8,0.6);
var a=taccgl.a("Layout",to.scene()).modFit(). rotateMiddle(Math.sqrt(1/3),Math.sqrt(1/3),Math.sqrt(1/3)).dur(8).start();
RUN
var to=taccgl.objFile().read('/objtest/taccgldoc.obj',false);
to.mtl.ambientAdjust(0.6);
var a=taccgl.a("Layout",to.scene()).modFit(). rotateMiddle(Math.sqrt(1/3),Math.sqrt(1/3),Math.sqrt(1/3)).dur(8).start();
RUN
var to=taccgl.objFile().read('/objtest/taccgldoc.obj',false);
to.mtl.ambientAdjust(1.0);
var a=taccgl.a("Layout",to.scene()).modFit(). rotateMiddle(Math.sqrt(1/3),Math.sqrt(1/3),Math.sqrt(1/3)).dur(8).start();
RUN
var to=taccgl.objFile().read('/objtest/taccgldoc.obj',false);
to.mtl.ambientAdjust(1,0);
var a=taccgl.a("Layout",to.scene()).modFit(). rotateMiddle(Math.sqrt(1/3),Math.sqrt(1/3),Math.sqrt(1/3)).dur(8).start();
RUN

WebGL™ is a trademark of the Khronos Group Inc.

Next Page:taccgl3DObject Class
Previous Page: taccglMTLFile.error - Return error message