'WebGL: Converting JSON IFS 3D Model Data to Float32Arrays

I have a project I'm working on that involves rendering 3D models in WebGL, GitHub here. In pulling together several different resources, I've found two different formats for the model data: one with JSON entries like so:

var houseIFS =
{
   "vertices": [
      [ 2, -1, 2 ],
      [ 2, -1, -2 ],
      [ 2, 1, -2 ],
      [ 2, 1, 2 ],
      [ 1.5, 1.5, 0 ],
      [ -1.5, 1.5, 0 ],
      [ -2, -1, 2 ],
      [ -2, 1, 2 ],
      [ -2, 1, -2 ],
      [ -2, -1, -2 ]
   ],
   "faces": [
      [ 0, 1, 2, 3 ],
      [ 3, 2, 4 ],
      [ 7, 3, 4, 5 ],
      [ 2, 8, 5, 4 ],
      [ 5, 8, 7 ],
      [ 0, 3, 7, 6 ],
      [ 0, 6, 9, 1 ],
      [ 2, 1, 9, 8 ],
      [ 6, 7, 8, 9 ]
   ],
   "normals": [
      [ 1, 0, 0 ],
      [ 0.7071, 0.7071, 0 ],
      [ 0, 0.9701, 0.2425 ],
      [ 0, 0.9701, -0.2425 ],
      [ -0.7071, 0.7071, 0 ],
      [ 0, 0, 1 ],
      [ 0, -1, 0 ],
      [ 0, 0, -1 ],
      [ -1, 0, 0 ]
   ],
   "faceColors": [
      [ 1, .8, .8 ],
      [ .7, .7, 1 ],
      [ 0, 0, 1 ],
      [ 0, 0, .7 ],
      [ .7, .7, 1 ],
      [ 1, 0, 0 ],
      [ .4, .4, .4 ],
      [ 1, 0, 0 ],
      [ 1, .8, .8 ],
   ]
};

and another with more primitive return types:

/** The return value of each function is an object, model, with properties:
 * 
 *    model.vertexPositions -- the vertex coordinates;
 *    model.vertexNormals -- the normal vectors;
 *    model.vertexTextureCoords -- the texture coordinates;
 *    model.indices -- the face indices.
 *
 * The first three properties are of type Float32Array, while
 * model.indices is of type Uint16Array.
 */

I tried to create a method to convert the data from the "modern" version to the "primitive":

function convertPoly(model) {
     return {
      vertexPositions: new Float32Array(model.vertices),
      vertexNormals: new Float32Array(model.normals),
      vertexTextureCoords: new Float32Array(model.faces),
      indices: new Uint16Array(model.faces)
   }
}

but I don't think this is correct, and I don't see anything rendered after trying to render it. How can I compute indices from the vertices or faces? I guess I don't really understand what the indices really represent or how they work (is it triangle vertices of the faces?).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source