Search code examples
c++assimp

How to export higher precision output files from ASSIMP?


When exporting meshes with assimp through code as shown below I receive very limited precision output. Is there a way in assimp to increase export precision? (Nothing hints at this in the documentation.)

void export(aiScene* scene, const std::string & outputFile)
{
    Assimp::Exporter exporter;

    // exporter.mOutput.precision(16); ???

    exporter.Export(scene, "obj", outputFile);
}

Output in the .obj file will contain no more than 6 digits per value:

v  557760 4.07449e+06 -49.1995
v  557760 4.07449e+06 -49.095
v  557760 4.0745e+06 -49.0082
v  557760 4.0745e+06 -49.1127

When looking at the actual exporter class (ObjExporter.cpp) all data is written through a public stringstream:

public:
    std::ostringstream mOutput, mOutputMat;

[...]

mOutput << "# " << vp.size() << " vertex positions" << endl;
for(const aiVector3D& v : vp) {
    mOutput << "v  " << v.x << " " << v.y << " " << v.z << endl;
}
mOutput << endl;

Is there a way I could increase the stringstream precision (http://www.cplusplus.com/reference/ios/ios_base/precision/) without having to change the assimp source?


Solution

  • When looking at the different exporter classes in detail it becomes apparent that some of them indeed have set a higher precision for the stringstream internally, but there is no way to (globally) define this or externally pass a request in for a higher precision export.

    Technically, you may be able to instantiate the actual export class and update the stringstream manually (since it's a public member variable), but this makes the export a lot more complicated and the point of using assimp was to easily export to different formats.

    I thus have updated assimp to export higher precision floating point values as (for example) discussed here: How do I print a double value with full precision using cout?