new BufferedOutputStream(new FileOutputStream(this.mtlFileName)), "ISO-8859-1");
writeHeader(writer);
for (Map.Entry<ComparableAppearance, String> appearanceEntry : this.appearances.entrySet()) {
checkCurrentThreadIsntInterrupted();
Appearance appearance = appearanceEntry.getKey().getAppearance();
String appearanceName = appearanceEntry.getValue();
writer.write("\nnewmtl " + appearanceName + "\n");
Material material = appearance.getMaterial();
if (material != null) {
if (material instanceof OBJMaterial
&& ((OBJMaterial)material).isIlluminationModelSet()) {
writer.write("illum " + ((OBJMaterial)material).getIlluminationModel() + "\n");
} else if (material.getShininess() > 1) {
writer.write("illum 2\n");
} else if (material.getLightingEnable()) {
writer.write("illum 1\n");
} else {
writer.write("illum 0\n");
}
Color3f color = new Color3f();
material.getAmbientColor(color);
writer.write("Ka " + format(color.x) + " " + format(color.y) + " " + format(color.z) + "\n");
material.getDiffuseColor(color);
writer.write("Kd " + format(color.x) + " " + format(color.y) + " " + format(color.z) + "\n");
material.getSpecularColor(color);
writer.write("Ks " + format(color.x) + " " + format(color.y) + " " + format(color.z) + "\n");
writer.write("Ns " + format(material.getShininess()) + "\n");
if (material instanceof OBJMaterial) {
OBJMaterial objMaterial = (OBJMaterial)material;
if (objMaterial.isOpticalDensitySet()) {
writer.write("Ni " + format(objMaterial.getOpticalDensity()) + "\n");
}
if (objMaterial.isSharpnessSet()) {
writer.write("sharpness " + format(objMaterial.getSharpness()) + "\n");
}
}
} else {
ColoringAttributes coloringAttributes = appearance.getColoringAttributes();
if (coloringAttributes != null) {
writer.write("illum 0\n");
Color3f color = new Color3f();
coloringAttributes.getColor(color);
writer.write("Ka " + format(color.x) + " " + format(color.y) + " " + format(color.z) + "\n");
writer.write("Kd " + format(color.x) + " " + format(color.y) + " " + format(color.z) + "\n");
writer.write("Ks " + format(color.x) + " " + format(color.y) + " " + format(color.z) + "\n");
}
}
TransparencyAttributes transparency = appearance.getTransparencyAttributes();
if (transparency != null) {
if (!(material instanceof OBJMaterial)) {
writer.write("Ni 1\n");
}
writer.write("d " + format(1f - transparency.getTransparency()) + "\n");
}
Texture texture = appearance.getTexture();
if (texture != null) {
writer.write("map_Kd " + this.textures.get(texture).getName() + "\n");
}
}