I don't know the reason but this works:
if (isShadow){
for (int i=0;i<shapes.size();i++){
Appearance app = shapes.get(i).getAppearance();
Material mat = app.getMaterial();
mat.setAmbientColor(Colorf.BLACK);
mat.setDiffuseColor(Colorf.BLACK);
mat.setSpecularColor(Colorf.BLACK);
mat.setEmissiveColor(Colorf.BLACK);
}
}else{
// init transparency
TransparencyAttributes transparencyAttrs = new TransparencyAttributes(
TransparencyAttributes.BLENDED, 0f,TransparencyAttributes.BLEND_ONE,
TransparencyAttributes.BLEND_SRC_ALPHA);
ColoringAttributes colorAttr = new ColoringAttributes();
colorAttr.setShadeModel(ColoringAttributes.NICEST);
for (int i=0;i<shapes.size();i++){
Shape3D shape = shapes.get(i);
Appearance app = shape.getAppearance();
if (shape.getName().endsWith("_transparent")){
app.setTransparencyAttributes(transparencyAttrs);
}
Material mat = app.getMaterial();
mat.setShininess(100);
mat.setLightingEnabled(true);
mat.setSpecularColor(new Colorf(1.0f,1.0f,1.0f));
}
}
and this doesn't work (unfortunatly I can't highlight the changes with a color in the code)
if (isShadow){
Texture texture = null;
PolygonAttributes polyAttrs = new PolygonAttributes(PolygonAttributes.CULL_BACK);
for (int i=0;i<shapes.size();i++){
Appearance app = shapes.get(i).getAppearance();
app.setTexture(texture);
app.setPolygonAttributes(polyAttrs);
Material mat = app.getMaterial();
mat.setAmbientColor(Colorf.BLACK);
mat.setDiffuseColor(Colorf.BLACK);
mat.setSpecularColor(Colorf.BLACK);
mat.setEmissiveColor(Colorf.BLACK);
}
}else{
// init transparency
TransparencyAttributes transparencyAttrs = new TransparencyAttributes(
TransparencyAttributes.BLENDED,0f, TransparencyAttributes.BLEND_ONE, TransparencyAttributes.BLEND_SRC_ALPHA);
ColoringAttributes colorAttr = new ColoringAttributes();
colorAttr.setShadeModel(ColoringAttributes.NICEST);
TextureAttributes textureAttr = new TextureAttributes();
textureAttr.setTextureMode(TextureAttributes.MODULATE);
textureAttr.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
for (int i=0;i<shapes.size();i++){
Shape3D shape = shapes.get(i);
Appearance app = shape.getAppearance();
if (shape.getName().endsWith("_transparent")){
app.setTransparencyAttributes(transparencyAttrs);
}
Material mat = app.getMaterial();
mat.setShininess(100);
mat.setLightingEnabled(true);
mat.setSpecularColor(new Colorf(1.0f,1.0f,1.0f));
app.setTextureAttributes(textureAttr);
}
}