}
final Element blinnPhongLambert = technique.getChild(type);
if (mInfo != null) {
mInfo.setTechnique(type);
}
final MaterialState mState = new MaterialState();
// TODO: implement proper transparency handling
Texture diffuseTexture = null;
ColorRGBA transparent = new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
float transparency = 1.0f;
boolean useTransparency = false;
String opaqueMode = "A_ONE";
/*
* place holder for current property, we import material properties in fixed order (for texture order)
*/
Element property = null;
/* Diffuse property */
property = blinnPhongLambert.getChild("diffuse");
if (property != null) {
final Element propertyValue = property.getChildren().get(0);
if ("color".equals(propertyValue.getName())) {
final ColorRGBA color = _colladaDOMUtil.getColor(propertyValue.getText());
mState.setDiffuse(MaterialFace.FrontAndBack, color);
} else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
diffuseTexture = populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo,
"diffuse");
}
}
/* Ambient property */
property = blinnPhongLambert.getChild("ambient");
if (property != null) {
final Element propertyValue = property.getChildren().get(0);
if ("color".equals(propertyValue.getName())) {
final ColorRGBA color = _colladaDOMUtil.getColor(propertyValue.getText());
mState.setAmbient(MaterialFace.FrontAndBack, color);
} else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "ambient");
}
}
/* Transparent property */
property = blinnPhongLambert.getChild("transparent");
if (property != null) {
final Element propertyValue = property.getChildren().get(0);
if ("color".equals(propertyValue.getName())) {
transparent = _colladaDOMUtil.getColor(propertyValue.getText());
// TODO: use this
useTransparency = true;
} else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "transparent");
}
opaqueMode = property.getAttributeValue("opaque", "A_ONE");
}
/* Transparency property */
property = blinnPhongLambert.getChild("transparency");
if (property != null) {
final Element propertyValue = property.getChildren().get(0);
if ("float".equals(propertyValue.getName())) {
transparency = Float.parseFloat(propertyValue.getText().replace(",", "."));
// TODO: use this
if (_flipTransparency) {
transparency = 1f - transparency;
}
useTransparency = true;
} else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "transparency");
}
}
/* Emission property */
property = blinnPhongLambert.getChild("emission");
if (property != null) {
final Element propertyValue = property.getChildren().get(0);
if ("color".equals(propertyValue.getName())) {
mState.setEmissive(MaterialFace.FrontAndBack, _colladaDOMUtil.getColor(propertyValue.getText()));
} else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "emissive");
}
}
/* Specular property */
property = blinnPhongLambert.getChild("specular");
if (property != null) {
final Element propertyValue = property.getChildren().get(0);
if ("color".equals(propertyValue.getName())) {
mState.setSpecular(MaterialFace.FrontAndBack, _colladaDOMUtil.getColor(propertyValue.getText()));
} else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "specular");
}
}
/* Shininess property */
property = blinnPhongLambert.getChild("shininess");
if (property != null) {
final Element propertyValue = property.getChildren().get(0);
if ("float".equals(propertyValue.getName())) {
float shininess = Float.parseFloat(propertyValue.getText().replace(",", "."));
if (shininess >= 0.0f && shininess <= 1.0f) {
final float oldShininess = shininess;
shininess *= 128;
logger.finest("Shininess - " + oldShininess
+ " - was in the [0,1] range. Scaling to [0, 128] - " + shininess);
} else if (shininess < 0 || shininess > 128) {
final float oldShininess = shininess;
shininess = MathUtils.clamp(shininess, 0, 128);
logger.warning("Shininess must be between 0 and 128. Shininess " + oldShininess
+ " was clamped to " + shininess);
}
mState.setShininess(MaterialFace.FrontAndBack, shininess);
} else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "shininess");
}
}
/* Reflectivity property */