Q:

Multiple meshes into single wavefront OBJ file

I have multiple meshes [VertexBuffer + IndexBuffer] (just Points(v3) and int16[] indices)
I want to save them into same wavefront OBJ file.
How can i do that?
Purpose: Want to feed the final "big" mesh to Recast to construct the navigation mesh.
Thanks!

A:

Some pseudocode:
vector<int> indices;
vector<Vector3> vertices;

vector<string> filenames {"a.obj", "b.obj", "c.obj" };

for(auto it = begin(filenames); it != end(filenames); ++it)
{
  vector<Vector3> localVertices;
  vector<int> localIndices;

  // load this model's data
  ParseOBJ(*it, localVertices, localIndices);

  // get new starting vertex number to renumber new indices    
  auto startIndex = vertices.size();
  // reserve some space and copy the new vertices over to the master collection
  vertices.reserve(vertices.size() + localVertices.size());
  vertices.insert(end(vertices), begin(localVertices), end(localVertices));

  // could do this with std::transform, probably
  std::transform(begin(localIndices), end(localIndices), end(indices),
[](int index) -> int { return index + startIndex; });
  // or a loop.
/*      
      indices.reserve(indices.size() + localIndices.size());
      // add an offset to each of the "new" indices so that they reference the correct vertices
      for(int i = 0; i < localIndices.size(); ++i);
      {
        indices.push_back(startIndex + localIndices[i]);
      }
  */ 

}

// vertices and indices now contains all of your models.

... ish. Note that it's pseudocode, and you'll have to provide your own method for parsing the OBJ. (The tubes can help you on that one.)
Also, you might want to look at TriMesh, which (I think) provides functions for this. I haven't used that tool, so YMMV. 

