Add generic precision option for text-based formats exporters (e.g. X3D, OBJ...) #51865

Open
opened 2017-06-21 23:52:40 +02:00 by Steve Holland · 25 comments

io_scene_x3d importer/exporter texture coordinate precision is inadequate for some applications.

The x3d importer/exporter is hardwired to 4 decimal digit precision in generated texture coordinates.

For example, a finely meshed filleted edge on a large object with a single texture could easily have coordinate spacing in (u,v) of less than 1x10^-4, in which case you get a (u,v) space triangle with two vertices that have identical coordinates in the file, and thus zero area, etc. etc. which makes for all sorts of potential problems when the file is read back in.

The relevant lines from https://developer.blender.org/diffusion/BA/browse/master/io_scene_x3d/export_x3d.py
are:
813: fw('%.4f %.4f ' % x3d_v- [x][slot_uv])
and
931: fw('%.4f %.4f ' % uv[:])
Obviously adjusting the precision to (say) 6 digits is a trivial modification.

Here is a patch that makes the precision default to 6, but also be adjustable:
io_scene_x3d.patch

io_scene_x3d importer/exporter texture coordinate precision is inadequate for some applications. The x3d importer/exporter is hardwired to 4 decimal digit precision in generated texture coordinates. For example, a finely meshed filleted edge on a large object with a single texture could easily have coordinate spacing in (u,v) of less than 1x10^-4, in which case you get a (u,v) space triangle with two vertices that have identical coordinates in the file, and thus zero area, etc. etc. which makes for all sorts of potential problems when the file is read back in. The relevant lines from https://developer.blender.org/diffusion/BA/browse/master/io_scene_x3d/export_x3d.py are: `813: fw('%.4f %.4f ' % x3d_v- [x][slot_uv])` and `931: fw('%.4f %.4f ' % uv[:])` Obviously adjusting the precision to (say) 6 digits is a trivial modification. Here is a patch that makes the precision default to 6, but also be adjustable: [io_scene_x3d.patch](https://archive.blender.org/developer/F638098/io_scene_x3d.patch)
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @sdh4

Added subscriber: @sdh4

Added subscriber: @mont29

Added subscriber: @mont29

Thanks for the report, but there is no bug here, textual format will always have limited precision in their values…

Tweaking the amount of precision here (which is a tradeoff between precision and size of generated file) could be nice to add in a generic way for all exporters handling text-based format (can of OBJ at least, others for sure) is a nice and quite simple TODO though (add generic option, and use it to generate a float printf template…).

Thanks for the report, but there is no bug here, textual format will always have limited precision in their values… Tweaking the amount of precision here (which is a tradeoff between precision and size of generated file) could be nice to add in a generic way for all exporters handling text-based format (can of OBJ at least, others for sure) is a nice and quite simple TODO though (add generic option, and use it to generate a float printf template…).
Bastien Montagne changed title from X3D texture coordinate precision is inadequate for some applications. to Add generic precision option for text-based formats exporters (e.g. X3D, OBJ...) 2017-07-04 15:42:24 +02:00
Member

Added subscriber: @JohnRoper

Added subscriber: @JohnRoper
Member

What needs to be done here? I would like to help, but I'm not exactly sure what the final result should be.

What needs to be done here? I would like to help, but I'm not exactly sure what the final result should be.

Added subscriber: @alourenco

Added subscriber: @alourenco

In #51865#474665, @JohnRoper wrote:
What needs to be done here? I would like to help, but I'm not exactly sure what the final result should be.

Hey John. Are you taking care of this one?

> In #51865#474665, @JohnRoper wrote: > What needs to be done here? I would like to help, but I'm not exactly sure what the final result should be. Hey John. Are you taking care of this one?
Member

I'd like to try, but still not sure what the goal is?

I'd like to try, but still not sure what the goal is?

In #51865#480185, @JohnRoper wrote:
I'd like to try, but still not sure what the goal is?

I am starting now, so I am not the best person to answer you. Still, as I understood, the idea is to give the user the option to define a float precision on export, because certain applications don't work with certain float precision. But you better ask someone with more experience in IRC to confirm this.

> In #51865#480185, @JohnRoper wrote: > I'd like to try, but still not sure what the goal is? I am starting now, so I am not the best person to answer you. Still, as I understood, the idea is to give the user the option to define a float precision on export, because certain applications don't work with certain float precision. But you better ask someone with more experience in IRC to confirm this.

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Not sure this is a good quick hack - mainly because it's quite a detailed option - should all ascii formats have precision for UV's and verts, ... normals too?

Probably if there are cases precision needs to be increased - we can increase it and not add too many options to exporters.

Not sure this is a good quick hack - mainly because it's quite a detailed option - should all ascii formats have precision for UV's and verts, ... normals too? Probably if there are cases precision needs to be increased - we can increase it and not add too many options to exporters.

Added subscriber: @brecht

Added subscriber: @brecht

I suggest to use %.7g. It will ensure you have 7 digits of precision on both sides of the decimal combined, like float values have. For very small or large numbers it switches to scientific notation.

I suggest to use `%.7g`. It will ensure you have 7 digits of precision on both sides of the decimal combined, like `float` values have. For very small or large numbers it switches to scientific notation.

@brecht LGTM, although think this is only needed for UV's and vertices, think normals can be left at 4 (%.4g is fine too).

@brecht LGTM, although think this is only needed for UV's and vertices, think normals can be left at 4 (`%.4g` is fine too).

Added subscriber: @brutzman

Added subscriber: @brutzman

Added subscriber: @shimanzhang2000

Added subscriber: @shimanzhang2000

I would like to take this task!

I would like to take this task!

Just wondering: one of the above comments suggested changing the precision of all fields to %.7g. Are we still following this, or just the UV's and vertices. Also, should import also be changed?

Just wondering: one of the above comments suggested changing the precision of all fields to %.7g. Are we still following this, or just the UV's and vertices. Also, should import also be changed?

suggest that trailing zeroes and trailing decimal points get removed as well to reduce file-size bloat.

suggest that trailing zeroes and trailing decimal points get removed as well to reduce file-size bloat.

@shimanzhang2000, hard to say if it should be all fields. @ideasman42 suggested %.7g for uvs and vertices, and %.4g for normals. I think most other should be %.7g too, but you need to look at it case by case if it makes sense.

Import would not be affected as far as I know.

@brutzman, %g does that.

@shimanzhang2000, hard to say if it should be all fields. @ideasman42 suggested `%.7g` for uvs and vertices, and `%.4g` for normals. I think most other should be `%.7g` too, but you need to look at it case by case if it makes sense. Import would not be affected as far as I know. @brutzman, `%g` does that.

Added subscriber: @propersquid

Added subscriber: @propersquid

Added subscriber: @Marcelo-Amaral-Ferrante

Added subscriber: @Marcelo-Amaral-Ferrante

Hi,
I made a patch to easily change precision, https://developer.blender.org/D7899

Hi, I made a patch to easily change precision, https://developer.blender.org/D7899
Marcelo F self-assigned this 2020-06-20 05:30:10 +02:00

Hi,
I made a patch to easily change precision, https://developer.blender.org/D7899

Dont know how to proceed from now.

Hi, I made a patch to easily change precision, https://developer.blender.org/D7899 Dont know how to proceed from now.
Sign in to join this conversation.
No Milestone
No project
No Assignees
10 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#51865
No description provided.