if ((mode==SHADING_MODE) || (mode==FLAT_MODE)) {
if (mode==SHADING_MODE) ca.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
if (mode==FLAT_MODE) ca.setShadeModel(ColoringAttributes.SHADE_FLAT);
a.setColoringAttributes(ca);
a.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0));
Material m = new Material();
Color selectedColor;
if (on) selectedColor = highlightColor;
else selectedColor = baseColor;
float[] colors = selectedColor.getRGBColorComponents(null);
m.setAmbientColor(colors[0], colors[1], colors[2]);
// Squash specular toward white => keep only hue
float[] hsb = Color.RGBtoHSB(selectedColor.getRed(), selectedColor.getGreen(), selectedColor.getBlue(), null);
Color.getHSBColor(hsb[0],hsb[1]/10,1.0f).getRGBColorComponents(colors);
m.setSpecularColor(colors[0], colors[1], colors[2]);
// diffuse is same hue and saturation but darker
Color.getHSBColor(hsb[0],hsb[1],hsb[2]/2).getRGBColorComponents(colors);
m.setDiffuseColor(colors[0], colors[1], colors[2]);
// no emissive color
m.setEmissiveColor(0f,0f,0f);
/* m.setAmbientColor(1.0f,0.0f,0.0f);
m.setSpecularColor(1.0f,0.9f,0.9f);
m.setDiffuseColor(0.8f,0.0f,0.0f);
m.setEmissiveColor(0f,0f,0f);*/
m.setLightingEnable(true);
a.setMaterial(m);
}
shape.setAppearance(a);
}