Пример #1
0
  public void loadBuffers() {
    SurfCell curSurf; // the current surface being worked with
    PolyCell curPoly; // the current polygon in the surface
    VertListCell curVertLC;

    curSurf = surfHead;
    int vertCount;
    while (curSurf != null) {
      int vertsPerPrim;
      vertCount = 0;
      curPoly = curSurf.polyHead;
      // vertCount += curPoly.numVerts;
      vertsPerPrim = curPoly.numVerts;
      while (curPoly != null) {
        vertCount += curPoly.numVerts;
        if (curPoly.numVerts != vertsPerPrim) {
          System.out.printf("Surface %s: Unequal number of vertices ", curSurf.name);
          System.out.printf(
              "\n    First prim had %d Cur Prim has %d\n", curPoly.numVerts, vertsPerPrim);
          return;
        }
        curPoly = curPoly.next;
      }
      curSurf.numVerts = vertCount;
      float vertices[] = new float[vertCount * 3];
      int vInd = 0;
      float normals[] = new float[vertCount * 3];
      int nInd = 0;
      curPoly = curSurf.polyHead;
      while (curPoly != null) {
        curVertLC = curPoly.vert;
        while (curVertLC != null) {
          // for(int i = 0; i < curPoly.numVerts; i++);{
          VertCell curVert = vertArray.get(curVertLC.vert);
          vertices[vInd++] = (float) curVert.worldPos.x;
          vertices[vInd++] = (float) curVert.worldPos.y;
          vertices[vInd++] = (float) curVert.worldPos.z;
          normals[nInd++] = (float) vertNormArray[curVertLC.vert].x;
          normals[nInd++] = (float) vertNormArray[curVertLC.vert].y;
          normals[nInd++] = (float) vertNormArray[curVertLC.vert].z;
          curVertLC = curVertLC.next;
        }
        curPoly = curPoly.next;
      }
      // now put vertices and normals into VertexArray or Buffer
      curSurf.vertexBuffer = Buffers.newDirectFloatBuffer(vertices.length);
      curSurf.vertexBuffer.put(vertices);
      curSurf.vertexBuffer.rewind();

      curSurf.normalBuffer = Buffers.newDirectFloatBuffer(normals.length);
      curSurf.normalBuffer.put(normals);
      curSurf.normalBuffer.rewind();

      curSurf = curSurf.next;
    }
  }