title: Given a mesh face, find its neighboring faces
body: <p>I'm trying to efficiently find all neighboring faces of a given face.
  I'm taking a sly approach, but I wonder if can be improved upon.</p>
  
  <p>The approach I've taken so far is to create a data structure after my mesh geometry is created. I build a hash of arrays to map vertices to the faces that are comprised of them:</p>
  
  <pre><code>var vertexToFace = [];
  
  function crossReference(g) {
  
      for (var fx = 0; fx &lt; g.faces.length; fx++) {
          vertexToFace[fx] = new Array();
      }
      for (var fx = 0; fx &lt; g.faces.length; fx++) {
          var f = g.faces[fx];
          var ax = f.a;
          var bx = f.b;
          var cx = f.c;
  
          vertexToFace[ax].push(fx);
          vertexToFace[bx].push(fx);
          vertexToFace[cx].push(fx);
      }
  }
  </code></pre>
  
  <p>Now that I have the hash of arrays, I can retrieve a given face's neighbors:</p>
  
  <pre><code>var neighbors = [];
  
  neighbors.push( vertexToFace(face.a), vertexToFace(face.b), vertexToFace(face.c) );
  </code></pre>
  
  <p>This works fine, but I'm wondering if its over-kill.  I know that each face in geometry.faces contains members a,b,c that are indices into geometry.vertices. </p>
  
  <p>I don't believe the reverse information is stored, although, tantalizingly, each vertex in geometry.vertices does have the member .index, but it doesn't seem to correspond to faces.</p>
  
  <p>Am I missing something obvious?</p>
  
  <p>Thanks/.</p>