if i understand your problem this may be the sort of thig your after ?
all you really need is the COLTABLE(ie Color) and CHANGECOL(ie Script) the
rest is just selecting etc
#VRML V2.0 utf8
DEF STILL Viewpoint { jump TRUE position 0 0 50 description "still"}
DEF COLTABLE Color {color[0 0 1,0 1 0,0 1 1,1 0 0,1 0 1,1 1 0]}
Transform {children [Shape {
geometry IndexedFaceSet{
color USE COLTABLE
coord Coordinate {point [0 0 0,-1 1 0,1 1 0,1 -1 0,-1 -1 0]}
colorIndex [0,0,0,-1,1,1,1-1,2,2,2,-1,3,3,3,-1]
coordIndex [0,1,2,-1,0,2,3,-1,0,3,4,-1,0,4,1,-1]
Quote:
}}]rotation 1 0 0 3.142 translation -6 0 0}
Transform {children [Shape {
geometry IndexedFaceSet{
color USE COLTABLE
coord Coordinate {point [0 0 0,-1 1 0,1 1 0,1 -1 0,-1 -1 0]}
colorIndex [1,1,1,-1,2,2,2-1,3,3,3,-1,4,4,4,-1]
coordIndex [0,1,2,-1,0,2,3,-1,0,3,4,-1,0,4,1,-1]
Quote:
}}]rotation 1 0 0 3.142 translation 0 0 0}
Transform {children [Shape {
geometry IndexedFaceSet{
color USE COLTABLE
coord Coordinate {point [0 0 0,-1 1 0,1 1 0,1 -1 0,-1 -1 0]}
colorIndex [5,5,5,-1,2,2,2-1,4,4,4,-1,0,0,0,-1]
coordIndex [0,1,2,-1,0,2,3,-1,0,3,4,-1,0,4,1,-1]
Quote:
}}]rotation 1 0 0 3.142 translation 6 0 0}
DEF CHANGECOL Script {
field SFNode color USE COLTABLE
field MFColor colororig []
field SFInt32 colorprev 0
eventIn SFInt32 highlight
directOutput TRUE
url "javascript:
function initialize()
{
for(c = 0;c < color.color.length;c++)
{
colororig[c] = new
SFColor(color.color[c][0],color.color[c][1],color.color[c][2]);
}
Quote:
}
function highlight(value)
{
if(value < color.color.length)
{
color.color[colorprev] = new
SFColor(colororig[colorprev][0],colororig[colorprev][1],colororig[colorprev
]
[2]);
color.color[value] = new SFColor(1,1,1);//ie a highlight col
colorprev = value;
}
Quote:
}
"
}
PROTO Button[
field SFNode script NULL
field SFInt32 color 0
field SFVec3f pos 0 0 0
eventIn SFBool pressed
]
{
Transform{ children [
DEF ToS TouchSensor{}
Shape {geometry Box{size 2 2 1}}]translation IS pos}
DEF Buttonscript Script{
field SFInt32 color IS color
field SFNode script IS script
eventIn SFBool pressed
url"javascript:
function pressed(value)
{
if(value == true)
{
script.highlight = color;
Quote:
}
}
"
}
ROUTE ToS.isActive TO Buttonscript.pressed
Quote:
}
Button{pos -6 3 0 color 0 script USE CHANGECOL}
Button{pos -3 3 0 color 1 script USE CHANGECOL}
Button{pos 3 3 0 color 2 script USE CHANGECOL}
Button{pos 6 3 0 color 3 script USE CHANGECOL}
Quote:
> Thank you for your reaction, but can you also explain how it works with
> directOutput, because we want to fill the colors in the color field of an
> IndexedFaceSet node and not in the material node (diffuseColor). We hope
you can
> tell us how this works. At this moment thanks.
> Our problem is that we've got a legend and when we activate one block of
the
> legend we want to change the color of all the shapes with the same color.
We
> hope anybody can tell us the principle of this.
> Greetings Marnix and Marco