} else if ("Ka".equals(tokenizer.sval)) {
// Read ambient color Ka r g b
Color3f ambiantColor = new Color3f(parseNumber(tokenizer),
parseNumber(tokenizer), parseNumber(tokenizer));
if (currentAppearance != null) {
Material material = getMaterial(currentAppearance);
material.setAmbientColor(ambiantColor);
}
} else if ("Kd".equals(tokenizer.sval)) {
// Read diffuse or emissive color Kd r g b
Color3f diffuseColor = new Color3f(parseNumber(tokenizer),
parseNumber(tokenizer), parseNumber(tokenizer));
if (currentAppearance != null) {
OBJMaterial material = getMaterial(currentAppearance);
material.setDiffuseColor(diffuseColor);
currentAppearance.setColoringAttributes(
new ColoringAttributes(diffuseColor, ColoringAttributes.SHADE_GOURAUD));
}
} else if ("Ks".equals(tokenizer.sval)) {
// Read specular color Ks r g b
Color3f specularColor = new Color3f(parseNumber(tokenizer),
parseNumber(tokenizer), parseNumber(tokenizer));
if (currentAppearance != null) {
OBJMaterial material = getMaterial(currentAppearance);
if (!material.isIlluminationModelSet()
|| material.getIlluminationModel() >= 2) {
material.setSpecularColor(specularColor);
} else {
material.setSpecularColor(0, 0, 0);
}
}
} else if ("Ns".equals(tokenizer.sval)) {
// Read shininess Ns val with 0 <= val <= 1000
float shininess = parseNumber(tokenizer);
if (currentAppearance != null) {
OBJMaterial material = getMaterial(currentAppearance);
if (!material.isIlluminationModelSet()
|| material.getIlluminationModel() >= 2) {
// Use shininess at a max value equal to 128
material.setShininess(Math.max(1f, Math.min(shininess, 128f)));
} else {
material.setShininess(1f);
}
}
} else if ("Ni".equals(tokenizer.sval)) {
// Read optical density Ni val
float opticalDensity = parseNumber(tokenizer);
if (currentAppearance != null) {
OBJMaterial material = getMaterial(currentAppearance);
material.setOpticalDensity(opticalDensity);
}
} else if ("sharpness".equals(tokenizer.sval)) {
// Read sharpness sharpness val
float sharpness = parseNumber(tokenizer);
if (currentAppearance != null) {
OBJMaterial material = getMaterial(currentAppearance);
material.setSharpness(sharpness);
}
} else if ("d".equals(tokenizer.sval)) {
// Read transparency d val with 0 <= val <= 1
if (tokenizer.nextToken() == StreamTokenizer.TT_WORD) {
if ("-halo".equals(tokenizer.sval)) {
// Ignore halo transparency
parseNumber(tokenizer);
} else {
tokenizer.pushBack();
float transparency = parseNumber(tokenizer);
if (currentAppearance != null) {
if (transparency >= 1) {
currentAppearance.setTransparencyAttributes(null);
} else {
currentAppearance.setTransparencyAttributes(new TransparencyAttributes(
TransparencyAttributes.NICEST, 1f - Math.max(0f, transparency)));
}
}
}
} else {
throw new IncorrectFormatException("Expected transparency factor at line " + tokenizer.lineno());
}
} else if ("illum".equals(tokenizer.sval)) {
// Read illumination setting illum n
int illumination = parseInteger(tokenizer);
if (currentAppearance != null) {
OBJMaterial material = getMaterial(currentAppearance);
material.setIlluminationModel(illumination);
material.setLightingEnable(illumination >= 1);
if (illumination <= 1) {
material.setSpecularColor(0, 0, 0);
material.setShininess(1f);
}
}
} else if ("map_Kd".equals(tokenizer.sval)) {
// Read material texture map_Kd name
// Search last parameter that matches image file name