@SuppressWarnings("unchecked")
protected void loadXML(XMLElement xml) {
int n = xml.getChildCount();
String name, content;
XMLElement child;
GLTexture[] texturesList;
ArrayList<PVector> verticesList;
ArrayList<PVector>[] texCoordsList;
ArrayList<float[]>[] vertexAttribsList;
ArrayList<PVector> normalsList;
ArrayList<float[]> colorsList;
String[] texNames;
String[] attrNames;
int[] attrSizes;
texturesList = null;
verticesList = new ArrayList<PVector>();
texCoordsList = null;
vertexAttribsList = null;
normalsList = new ArrayList<PVector>();
colorsList = new ArrayList<float[]>();
texNames = null;
attrNames = null;
attrSizes = null;
for (int i = 0; i < n; i++) {
child = xml.getChild(i);
name = child.getName();
if (name.equals("description")) {
description = child.getContent();
} else if (name.equals("size")) {
size = PApplet.parseInt(child.getContent());
} else if (name.equals("geometry")) {
content = child.getContent();
vertexMode = GLUtils.parsePrimitive(content);
if (vertexMode == GL.GL_POINTS && content.equals("POINT_SPRITES")) {
vertexMode = GL.GL_POINTS;
usingPointSprites = true;
maxSpriteSize = GLState.glMaxAntialiasedPointSize;
}
} else if (name.equals("mode")) {
vboUsage = GLUtils.parseVBOMode(child.getContent());
} else if (name.equals("textures")) {
int ntex = child.getChildCount();
texturesList = new GLTexture[ntex];
texNames = new String[ntex];
texCoordsList = new ArrayList[ntex];
loadTextures(child, texturesList, texCoordsList, texNames);
} else if (name.equals("vertexattribs")) {
int nattr = child.getChildCount();
vertexAttribsList = new ArrayList[nattr];
attrNames = new String[nattr];
attrSizes = new int[nattr];
loadVertexAttribs(child, vertexAttribsList, attrNames, attrSizes);
} else if (name.equals("vertices")) {
String binfile = child.getString("file");
if (binfile != null)
loadVertices(binfile, verticesList);
else
loadVertices(child, verticesList);
} else if (name.equals("texcoords")) {
if (texCoordsList != null) {
int unit = child.getInt("unit");
if (texCoordsList[unit] != null) {
String binfile = child.getString("file");
if (binfile != null)
loadTexCoords(binfile, texCoordsList[unit]);
else
loadTexCoords(child, texCoordsList[unit]);
}
}
} else if (name.equals("colors")) {
String binfile = child.getString("file");
if (binfile != null)
loadColors(binfile, colorsList);
else
loadColors(child, colorsList);
} else if (name.equals("normals")) {
String binfile = child.getString("file");
if (binfile != null)
loadNormals(binfile, normalsList);
else
loadNormals(child, normalsList);
} else if (name.equals("attribs")) {
if (vertexAttribsList != null && attrSizes != null) {
int num = child.getInt("number");
if (vertexAttribsList[num] != null) {
String binfile = child.getString("file");
if (binfile != null)
loadVertexAttrib(binfile, vertexAttribsList[num], attrSizes[num]);
else
loadVertexAttrib(child, vertexAttribsList[num], attrSizes[num]);
}