}
protected void setAppearanceForHighlight(boolean on) {
if (shape==null) return;
Appearance a=new Appearance();
a.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
a.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
a.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
a.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
a.setCapability(Appearance.ALLOW_MATERIAL_READ);
a.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
a.setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_READ);
a.setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_WRITE);
a.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_READ);
a.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);
a.setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_READ);
a.setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE);
a.setCapability(Appearance.ALLOW_TEXGEN_READ);
a.setCapability(Appearance.ALLOW_TEXGEN_WRITE);
a.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_READ);
a.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);
a.setCapability(Appearance.ALLOW_TEXTURE_READ);
a.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
a.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_READ);
a.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE);
a.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
a.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
ColoringAttributes ca = new ColoringAttributes();
// don't use light
if ((mode==WIREFRAME_MODE) || (mode==FILLED_MODE)) {
int attribute = (mode==FILLED_MODE) ? PolygonAttributes.POLYGON_FILL : PolygonAttributes.POLYGON_LINE;
PolygonAttributes pa = new PolygonAttributes(attribute, PolygonAttributes.CULL_NONE, 0);
unlockPolygonAttributes(pa);
pa.setPolygonOffset(polygonOffset);
pa.setPolygonOffsetFactor(polygonOffsetFactor);
a.setPolygonAttributes(pa);
Color selectedColor;
if (on) selectedColor = highlightColor;
else selectedColor = baseColor;
float[] colors = selectedColor.getRGBColorComponents(null);
ca.setColor(colors[0], colors[1], colors[2]);
a.setColoringAttributes(ca);
}
// use light
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);
PolygonAttributes pa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0);
unlockPolygonAttributes(pa);
pa.setPolygonOffset(polygonOffset);
pa.setPolygonOffsetFactor(polygonOffsetFactor);
pa.setBackFaceNormalFlip(true);
a.setPolygonAttributes(pa);
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.setLightingEnable(true);
a.setMaterial(m);
}
shape.setAppearance(a);
}