This is a general 3d file converter written in C++. It defines an inner structure for 3d data, and abstact classes for file loaders and writers. This version contains a wavefront obj loader and a binary stl writer.
For a loaded mesh a D3Data object is used. The data is stored as in wavefront objects. There are separate vectors for vertices, normals, texture coordinates and faces. The faces contain indexes for their data. There is a cached face vector to save time on derefering the indexes, and making usage easier. These cached faces store pointers to the data structures for the face.
The representation is written only for triangles, it could be easily extended for polygons however.
Supported formats (for loading) have their own loader classes. They create a D3Data object and store the data in it from the given files on usage. They all inherit from Loader class, and all have a load function, which only needs a path parameter. The load function gives back the generated D3Data object.
Supported formats (for writing) also have a class for outputting data. They work from a D3Data object and write the data according to their file format to a file. They all inherit from the Writer class, and all have a write function, which needs a path parameter and a D3Data object parameter to write from.
There are some extra functionalities implemented on D3Data format. These are in static functions in the Utilities class. For example volume and surface of the given D3Data object can be calculated with these.
The correct loader has to be instantiated, and its load function has to be called with the path of the file that is needed to be parsed. The function gives back the D3Data object. Needed metrics can be calculated on the object using the static functions of the Utilities class.
The data can be then written out to a file using a Writer class. The class for the needed format has to be instantiated, then its write function has to be called with the intended path and the D3Data object.
Loads a default wavefront object file. It only support v, vt, vn and f lines. During parsing if the syntax is not correct throws an InvalidFormatException. However if the file can be parsed by throwing away lines that does not start with a specified keyword from the obj specification, it parses the file (That way it ignores unsupported lines). It supports basic triangularization for polygons, but only for convex polygons. If the model involves concave polygons the triangulariazation has to be turned off, using the parameter in the load function. There is no checking for convexity during parsing.
Writes out a binary stl file from a D3Data object. According to the specification, the number of triangles after the header will be written in little endian. The rest of the file uses the default endianity. Normals are written out in normalized form.
For each new format a new class should be written for either loading or writing. They shoud inherit from the abstract base classes respectively, and the default load/write function should be accessible through the virtual function from the base class.
Other functionailites can be added to the Utilities class that use the D3Data format.
An example of usage can be found in the Main.cpp file. It reades a basic cube obj file and writes it out into a mycube stl file. After loading it writes out the surface and volume of the mesh.