Skip to main content
3 of 3
Added escape character to the * in the block quote to prevent italic formatting
MarcoB
  • 67.7k
  • 18
  • 96
  • 198

How to control floating point precision when `Export`ing to obj format?

Suppose we have a MeshRegion that we want to export to an obj file with, say double precision. Is that possible with Export? And how would we do that? The documentation on "OBJ" does not list any options. I am asking explicitly about Export. Of course, I could write my own OBJ exporter, but this would be somewhat awkward. (I've actually done it already.)

The default seems to export only about 6 decimal digits as the following example is supposed to show:

R = MeshRegion[
   {{0., 0., 0.}, {Sqrt[2.], 0., 0.}, {0., Sqrt[2.], 0.}},
   Triangle[{{1, 2, 3}}]
   ];
file = FileNameJoin[{$TemporaryDirectory, "a.obj"}];
Export[file, R];
MeshCoordinates[Import[file]] - MeshCoordinates[R]

{{0., 0., 0.}, {-3.60048*10^-6, 0., 0.}, {0., -3.60048*10^-6, 0.}}

Henrik Schumacher
  • 109.5k
  • 7
  • 186
  • 323