}
} else if (node instanceof Link) {
setColorAndTexture(((Link)node).getSharedGroup(), color, texture, shininess, waitTextureLoadingEnd,
pieceSize, modelSize, modifiedAppearances);
} else if (node instanceof Shape3D) {
final Shape3D shape = (Shape3D)node;
String shapeName = (String)shape.getUserData();
// Change material and texture of all shapes that are not window panes
if (shapeName == null
|| !shapeName.startsWith(ModelManager.WINDOW_PANE_SHAPE_PREFIX)) {
Appearance appearance = shape.getAppearance();
if (appearance == null) {
appearance = createAppearanceWithChangeCapabilities();
((Shape3D)node).setAppearance(appearance);
}
// Check appearance wasn't already changed
if (!modifiedAppearances.contains(appearance)) {
// Use appearance user data to store shape default material
DefaultMaterialAndTexture defaultMaterialAndTexture = (DefaultMaterialAndTexture)appearance.getUserData();
if (defaultMaterialAndTexture == null) {
defaultMaterialAndTexture = new DefaultMaterialAndTexture(appearance);
appearance.setUserData(defaultMaterialAndTexture);
}
float materialShininess = shininess != null
? shininess.floatValue()
: (appearance.getMaterial() != null
? appearance.getMaterial().getShininess() / 128f
: 0);
if (color != null && defaultMaterialAndTexture.getTexture() == null) {
// Change material if no default texture is displayed on the shape
// (textures always keep the colors of their image file)
appearance.setMaterial(getMaterial(color, color, materialShininess));
appearance.setTransparencyAttributes(defaultMaterialAndTexture.getTransparencyAttributes());
appearance.setPolygonAttributes(defaultMaterialAndTexture.getPolygonAttributes());
appearance.setTexCoordGeneration(defaultMaterialAndTexture.getTexCoordGeneration());
appearance.setTextureAttributes(defaultMaterialAndTexture.getTextureAttributes());
appearance.setTexture(null);
} else if (color == null && texture != null) {
// Change material to white then texture
appearance.setMaterial(getMaterial(DEFAULT_COLOR, DEFAULT_AMBIENT_COLOR, materialShininess));
TexCoordGeneration texCoordGeneration = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
TexCoordGeneration.TEXTURE_COORDINATE_2,
new Vector4f(-pieceSize.x / modelSize.x / texture.getWidth(), 0, 0, 0),
new Vector4f(0, pieceSize.y / modelSize.y / texture.getHeight(), pieceSize.z / modelSize.z / texture.getHeight(), 0));
appearance.setTexCoordGeneration(texCoordGeneration);
appearance.setTextureAttributes(MODULATE_TEXTURE_ATTRIBUTES);
TextureManager.getInstance().loadTexture(texture.getImage(), waitTextureLoadingEnd,
new TextureManager.TextureObserver() {
public void textureUpdated(Texture texture) {
if (TextureManager.getInstance().isTextureTransparent(texture)) {
shape.getAppearance().setTransparencyAttributes(DEFAULT_TEXTURED_SHAPE_TRANSPARENCY_ATTRIBUTES);
shape.getAppearance().setPolygonAttributes(DEFAULT_TEXTURED_SHAPE_POLYGON_ATTRIBUTES);
}
shape.getAppearance().setTexture(texture);
}
});
} else {
// Restore default material and texture
Material defaultMaterial = defaultMaterialAndTexture.getMaterial();