I have a mesh with 1.5M vertices, and I'm trying to round off vertex positions to reduce the filesize of my exported .obj file. Each vertex has a very high level of precision, which I don't really need for this project. For example, I have a vertex at [492.98198, 382.19873, 274.98789]
, and would like to run a Python script to round it to [493, 382, 275]
, effectively reducing my output by over 50%!
Is there a python script that I could run to round off all 1.5M of my vertices in one go? This is as far as I've gone:
for vertex in bpy.data.meshes['meshname'].vertices:
vertex.co[0] = round(vertex.co[0], 0)
vertex.co[1] = round(vertex.co[1], 0)
vertex.co[2] = round(vertex.co[2], 0)
But it seems like I can't really change the vertex values this way because mesh.vertices
is a readonly attribute.
Anybody know how to modify the script so my vertices all snap to the nearest integer?
v 1.000000 1.000000 1.000000
in the obj file wont it? Running the rounding script over the obj file (or editing exporter to do so) would be more likely to help in this regard. $\endgroup$fw('v %.6f %.6f %.6f\n' % (ob_mat * pt.co.to_3d())[:])
to the output using a format string. You could do a global replace on%.6f
to%.1f
to have the format round the floats to 1 decimal place. $\endgroup$.000000
$\endgroup$