Package processing.xml

Examples of processing.xml.XMLElement


  public GLModel(PApplet parent, String filename) {
    initModelCommon(parent);
    this.parent = parent;

    filename = filename.replace('\\', '/');
    XMLElement xml = new XMLElement(parent, filename);

    loadXML(xml);
  }
View Full Code Here


    this.parent = parent;

    try {
      String xmlText = PApplet
          .join(PApplet.loadStrings(url.openStream()), "\n");
      XMLElement xml = new XMLElement(xmlText);
      loadXML(xml);
    } catch (IOException e) {
      System.err.println("Error loading effect: " + e.getMessage());
    }
  }
View Full Code Here

 
  @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]);
          }
View Full Code Here

  }

  protected void loadTextures(XMLElement xml, GLTexture[] texturesList,
      ArrayList<PVector>[] texCoordsList, String[] texNames) {
    int n = xml.getChildCount();
    XMLElement child;
    String name;

    String unitStr, fn;
    int unit;
    for (int i = 0; i < n; i++) {
      child = xml.getChild(i);
      name = child.getName();
      if (name.equals("texture")) {
        unitStr = child.getContent();
        unit = PApplet.parseInt(unitStr);

        texCoordsList[unit] = new ArrayList<PVector>();

        texNames[unit] = child.getString("name");
        fn = child.getString("file");
        texturesList[unit] = new GLTexture(parent, fn);
        texturesList[unit].setName(texNames[unit]);
      }
    }
  }
View Full Code Here

  protected void loadVertexAttribs(XMLElement xml,
      ArrayList<float[]>[] vertexAttribsList, String[] attrNames,
      int[] attrSizes) {
    int n = xml.getChildCount();
    XMLElement child;
    String name;

    String numStr;
    int num;
    for (int i = 0; i < n; i++) {
      child = xml.getChild(i);
      name = child.getName();
      if (name.equals("vertexattrib")) {
        numStr = child.getContent();
        num = PApplet.parseInt(numStr);

        vertexAttribsList[num] = new ArrayList<float[]>();

        attrNames[num] = child.getString("name");
        attrSizes[num] = child.getInt("size");
      }
    }
  }
View Full Code Here

    }
  }

  protected void loadVertices(XMLElement xml, ArrayList<PVector> verticesList) {
    int n = xml.getChildCount();
    XMLElement child;
    String name;

    String coordStr;
    float[] coord;
    for (int i = 0; i < n; i++) {
      child = xml.getChild(i);
      name = child.getName();
      if (name.equals("vertex")) {
        coordStr = child.getContent();
        coord = PApplet.parseFloat(PApplet.split(coordStr, ' '));

        if (coord.length == 3)
          verticesList.add(new PVector(coord[0], coord[1], coord[2]));
      }
View Full Code Here

    loadPVectorArrayListFromBinary(binaryFN, verticesList, 3);
  }

  protected void loadTexCoords(XMLElement xml, ArrayList<PVector> texCoordsList) {
    int n = xml.getChildCount();
    XMLElement child;
    String name;

    String coordStr;
    float[] coord;
    for (int i = 0; i < n; i++) {
      child = xml.getChild(i);
      name = child.getName();
      if (name.equals("texcoord")) {
        coordStr = child.getContent();
        coord = PApplet.parseFloat(PApplet.split(coordStr, ' '));

        if (coord.length == 2)
          texCoordsList.add(new PVector(coord[0], coord[1]));
      }
View Full Code Here

    loadPVectorArrayListFromBinary(binaryFN, texCoordsList, 2);
  }

  protected void loadColors(XMLElement xml, ArrayList<float[]> colorsList) {
    int n = xml.getChildCount();
    XMLElement child;
    String name;

    String coordStr;
    float[] coord;
    for (int i = 0; i < n; i++) {
      child = xml.getChild(i);
      name = child.getName();
      if (name.equals("color")) {
        coordStr = child.getContent();
        coord = PApplet.parseFloat(PApplet.split(coordStr, ' '));

        if (coord.length == 4)
          colorsList.add(coord);
      }
View Full Code Here

    loadFloatArrayListFromBinary(binaryFN, colorsList, 4);
  }

  protected void loadNormals(XMLElement xml, ArrayList<PVector> normalsList) {
    int n = xml.getChildCount();
    XMLElement child;
    String name;

    String coordStr;
    float[] coord;
    for (int i = 0; i < n; i++) {
      child = xml.getChild(i);
      name = child.getName();
      if (name.equals("normal")) {
        coordStr = child.getContent();
        coord = PApplet.parseFloat(PApplet.split(coordStr, ' '));

        if (coord.length == 3)
          normalsList.add(new PVector(coord[0], coord[1], coord[2]));
      }
View Full Code Here

  }

  protected void loadVertexAttrib(XMLElement xml,
      ArrayList<float[]> vertexAttribsList, int attrSize) {
    int n = xml.getChildCount();
    XMLElement child;
    String name;

    String coordStr;
    float[] coord;
    for (int i = 0; i < n; i++) {
      child = xml.getChild(i);
      name = child.getName();
      if (name.equals("attrib")) {
        coordStr = child.getContent();
        coord = PApplet.parseFloat(PApplet.split(coordStr, ' '));

        if (coord.length == attrSize)
          vertexAttribsList.add(coord);
      }
View Full Code Here

TOP

Related Classes of processing.xml.XMLElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.