0

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?

Chris
  • 3,245
  • 4
  • 29
  • 53
  • 6 is the default precision for streams, did you try using std::setprecision (http://en.cppreference.com/w/cpp/io/manip/setprecision)? – kfsone Jul 06 '16 at 04:20
  • no I did not try that, but could I just do that in my code (that statically links with `assimp`) ? (to be clear - I was looking for a solution without changing code in `assimp`, but this may not be realistic) – Chris Jul 06 '16 at 04:22
  • Maybe the format doesn't allow more precision? – Mikhail Jul 06 '16 at 04:44
  • No, OBJ, STL, PLY are all text based formats - you can use much higher precision that 6 digits - it's an implementation error in `assimp` that I am fixing now. – Chris Jul 06 '16 at 04:53

1 Answers1

0

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?

Community
  • 1
  • 1
Chris
  • 3,245
  • 4
  • 29
  • 53