Previous topic TOC

Use colors and textures

Next topic


If no colors are set, all objects will display the default white color. To obtain a more attractive looking scene, an object may be decorated with a color or a texture. A color is build up of several components:

  • diffuse: defines the diffuse reflective color component of an object. This is the basic color of an object. The color property is equivalent to the diffuse property.
  • specular: defines the specular reflective color component of an object. This component defines the glossy appearance of a surface. It is only valid if the sharpness property is set as well. This property defines how sharp a light is reflected on the object's surface
  • emissive: defines the emissive color component of an object. If set, the object will be visible, even if no light is shining on the object.
  • ambient: defines the ambient color component of an object. This component defines how much of the ambient color of the scene should be visible on the object.


// create a box
var a = Box(10,10,10);        
// set diffuse color component to yellow
a.diffuse = RGB(255,255,0);
// set specular color component to red  
a.specular = RGB(255,0,0);
// set sharpness to 30, the reflection will 
// be rather concentrated  
a.sharpness = 30; 
Use the Script->Step command to see how each line is changing the appearance of the box. To see the specular component, rotate the view so one of the default lights is reflected in a surface of the box.
Texture One or more surfaces of the box may be decorated with a texture. In order to do so, we first have to define the texture we want to use:
// create a texture based on the jpeg file 
var tex = Texture("MyPicture.jpg"); 
This defines a texture object that can be used to decorate one or more objects. The texture is based on a picture file (jpeg, png, gif or bitmap). Now we can assign this texture to an opbject:
// create a texture based on the jpeg file 
var tex = Texture("MyPicture.jpg");
var a = Box(20,20,20);
On every side, the box 'a' will be decorated with texture 'tex'. Also, the texture is blended with the color of the box. When you use the method useTexture, you can also specify which side of the box should be decorated, and it is also possible to tile the texture. See the help documentation for more details.
Scene The 'scene' object is a predefined object that keeps specific information about the scene. For example, the backColor is a property of the scene that defines the background color. The method 'defaultLights' specifies if a default set of lights should be enabled or not, the intensity of these lights and how many of these lights should generate a shadow. The intensity of the default lights can be changed by the luminance slider in the render window toolbar. Next to this slider, a checkbox is shown that enables or disables the rendering of shadows.