if (0 != libraryMaterialsSet.size()) {
if (1 != libraryMaterialsSet.size()) {
throw new ColladaParseException("Found " + libraryMaterialsSet.size() + " library Material sets for geometry id="
+ geometry.id() + " name=" + geometry.name());
}
Element libraryMaterials = libraryMaterialsSet.first();
Element material;
try {
// TODO: this one isn't standard like the others, and sometimes it doesn't exist
material = libraryMaterials.select("#" + facesMaterial);
if (null == material) {
throw new ColladaParseException("No material for " + facesMaterial + " for geometry id=" + geometry.id() + " name=" + geometry.name());
}
ElementSet instanceEffectSet = material.find("instance_effect");
if (1 != instanceEffectSet.size()) {
throw new ColladaParseException("Found " + instanceEffectSet.size() + " instance_effect sets for material " + facesMaterial + " for geometry id="
+ geometry.id() + " name=" + geometry.name());
}
Element instanceEffect = instanceEffectSet.first();
String effectUrl = instanceEffect.attr("url");
ElementSet libraryEffectsSet = rootElement.find("library_effects");
if (0 != libraryEffectsSet.size()) {
if (1 != libraryEffectsSet.size()) {
throw new ColladaParseException("Found " + libraryEffectsSet.size() + " library effects sets for geometry id=" + geometry.id() + " name="
+ geometry.name());
}
Element libraryEffects = libraryEffectsSet.first();
Element effect = libraryEffects.select(effectUrl);
if (null == effect) {
throw new ColladaParseException("No effect for " + effectUrl + " for geometry id=" + geometry.id() + " name=" + geometry.name());
}
ElementSet colorSet = effect.find("profile_COMMON", "technique", "lambert", "diffuse", "color");
if (1 == colorSet.size()) {
Element color = colorSet.first();
String colorListString = color.text();
String[] colorString = getItemsInString(colorListString);
if (4 != colorString.length) {
throw new ColladaParseException("mesh only supports 4-float color arrays but color list was '" + colorListString + "' for geometry id="
+ geometry.id() + " name=" + geometry.name());
}
vertexColors = new float[colorString.length];
for (int i = 0; i < colorString.length; i++) {
vertexColors[i] = Float.parseFloat(colorString[i]);
}
}
}
} catch (NonMatchingPathException e) {
// If we don't find the material, then we're done.
}
}
for (Input faceInput : faceInputs) {
if ("VERTEX".equals(faceInput.semantic)) {
ElementSet verticesSet = mesh.find("vertices");
if (1 != verticesSet.size()) {
throw new ColladaParseException("Found " + verticesSet.size() + " vertices sets for geometry id=" + geometry.id() + " name=" + geometry.name());
}
Element verticesElement = verticesSet.first();
ElementSet verticesInputSet = verticesElement.find("input");
List<Input> verticesInputs = parseInputs(verticesInputSet);
for (Input vertexInput : verticesInputs) {
if ("POSITION".equals(vertexInput.semantic)) {
Element vertexSourceElement = mesh.select(vertexInput.sourceName);
faceInput.vertexPositionSource = parseSource(vertexSourceElement);
} else if ("NORMAL".equals(vertexInput.semantic)) {
Element normalSourceElement = mesh.select(vertexInput.sourceName);
faceInput.vertexNormalSource = parseSource(normalSourceElement);
} else {
throw new ColladaParseException("Found unexpected vertex Input semantic " + vertexInput.semantic +
" for geometry id=" + geometry.id() + " name=" + geometry.name());
}
}
} else if ("NORMAL".equals(faceInput.semantic)) {
Element normalSourceElement = mesh.select(faceInput.sourceName);
faceInput.normalSource = parseSource(normalSourceElement);
if (3 != faceInput.normalSource.stride) {
throw new ColladaParseException("Found stride of " + faceInput.normalSource.stride
+ " for triangle Input semantic " + faceInput.semantic +
" for geometry id=" + geometry.id() + " name=" + geometry.name());
}
} else if ("TEXCOORD".equals(faceInput.semantic)) {
Element texCoordSourceElement = mesh.select(faceInput.sourceName);
faceInput.texCoordSource = parseSource(texCoordSourceElement);
if (2 != faceInput.texCoordSource.stride) {
logger.warn("Found non-2 stride of " + faceInput.texCoordSource.stride
+ " for vertex Input semantic " + faceInput.semantic +
" for geometry id=" + geometry.id() + " name=" + geometry.name()
+ ". Ignoring all but first two texture coordinate values.");
}
} else {
throw new ColladaParseException("Found unexpected triangle Input semantic " + faceInput.semantic +
" for geometry id=" + geometry.id() + " name=" + geometry.name());
}
}
ElementSet faceDataSet = faces.find("p");
if (1 != faceDataSet.size()) {
throw new ColladaParseException("Found " + faceDataSet.size() + " triangleData sets for geometry id=" + geometry.id() + " name=" + geometry.name());
}
Element faceData = faceDataSet.first();
String faceDataString = faceData.text();
String[] facesStrings = getItemsInString(faceDataString);
// TODO: for now, assume the offsets will always perfectly match the sorted-by-offset list indexes
Collections.sort(faceInputs, new Comparator<Input>() {
@Override