|
|
The following example will show you how to interactively modify the 3D scene.
For example, if the diffuse color should be set to red, the Material node is referenced by its id and the attribute diffuseColor is set to "1.0 0.0 0.0". The attribute value is always a string.
var mat = document.getElementById("material");
mat.setAttribute("diffuseColor", "1.0 0.0 0.0");
In the example, the RGB value is fetched from the slider. As the slider gives the RGB values between 0 and 255,
they have to be transformed to
arithmetic values between 0.0 and 1.0. After that, the RBG value has to be formatted as string.
var mat = document.getElementById("material");
rgbstring = " "+ red/255 + " " + green/255 + " " + blue/255;
mat.setAttribute("diffuseColor", rgbstring);
|