Page MenuHome

Add generic precision to x3d and obj exporter
Needs RevisionPublic

Authored by Marcelo F (marceloferrante) on Jun 2 2020, 1:31 AM.

Details

Summary

Number of precision digits can be easily changed on _precision variables, for loc, rot, sca, normal and uv.

Diff Detail

Event Timeline

Marcelo F (marceloferrante) requested review of this revision.Jun 2 2020, 1:31 AM
Marcelo F (marceloferrante) created this revision.
This comment was removed by Marcelo F (marceloferrante).

Changed the variables positions from start of file to inside of the export().
Created a basic interface.

Added precision options to obj file

Marcelo F (marceloferrante) retitled this revision from Add generic precision to x3d exporter to Add generic precision to x3d and obj exporter.Jun 3 2020, 2:35 AM
Bastien Montagne (mont29) requested changes to this revision.Aug 28 2020, 4:24 PM

Wouldn't mind getting @Campbell Barton (campbellbarton)'s view on this patch, but already noted several important points below.

io_scene_obj/__init__.py
291–297 ↗(On Diff #25430)

What is the added value of this option? Why would one want to keep extra zeros?

298–316 ↗(On Diff #25430)

Think we could keep it to two precision values? Or even one? I can see why one could want to carefully optimize its precision versus file size, but imho this adds way too many new parameters for a very limited usecase.

io_scene_obj/export_obj.py
32–33 ↗(On Diff #25430)

f is forced in non-exponential notation, so precision varies actually with its value (since high numbers will get more digits than small numbers).

g uses either flat or exponential notation, ensuring always the same amount of significant digits.

The choice between those therefore goes way beyond 'remove trailing zeros'. And am not even sure whether OBJ supports actually scientific notation, there is nothing in the specs about it...

149 ↗(On Diff #25430)

Using format still has a significant overhead compared to old 'printf' like syntax, afaik.

This revision now requires changes to proceed.Aug 28 2020, 4:24 PM
io_scene_obj/__init__.py
291–297 ↗(On Diff #25430)

I thought about the line alignment, for editing with awk / sed (I don't know if it makes a difference)

298–316 ↗(On Diff #25430)

Yes, makes sense. Maybe one option, and make normal and vertices proportional to this one, with a minimum size (like 2 digits)?
For example, make the normal be 2/3 of the general precision, with a minimum value. (I thought 2/3 because of the current values, the normal/uv being 4 and general 6 digits)

io_scene_obj/export_obj.py
32–33 ↗(On Diff #25430)

So, we can't use %g ...
I will stick with %f and remove the zeros with some function (like .strip ("0")).

149 ↗(On Diff #25430)

Yes, shall be. I used it due to the %f / %g option. Removing it allows the use of printf.

Maybe f-strings will look better in the above diff?