diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-08-15 06:13:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-08-15 06:18:47 +0300 |
commit | 4f1c1bbe7ab0846879de7e6499738d9778265a1f (patch) | |
tree | 3f31289bc29e9c2c57c36d4a02eace966a79aef6 /release/datafiles | |
parent | 4a3348cfe049620b9f8bcf421562ff8264bc79fa (diff) |
Icons: geometry now checks quantized area
Previously back-facing normal was checked which isn't ideal
because a triangle that starts out zero-area may become
visible once it's coordinates are quantized.
Diffstat (limited to 'release/datafiles')
-rw-r--r-- | release/datafiles/blender_icons_geom.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/release/datafiles/blender_icons_geom.py b/release/datafiles/blender_icons_geom.py index bb7a6568767..f3af7f997c1 100644 --- a/release/datafiles/blender_icons_geom.py +++ b/release/datafiles/blender_icons_geom.py @@ -43,6 +43,11 @@ the ``.dat`` file extension should be used. # This script writes out geometry-icons. import bpy +# Generic functions + +def area_tri_signed_2x_v2(v1, v2, v3): + return (v1[0] - v2[0]) * (v2[1] - v3[1]) + (v1[1] - v2[1]) * (v3[0] - v2[0]) + class TriMesh: """ @@ -116,10 +121,7 @@ def mesh_data_lists_from_mesh(me, material_colors): tris_data = [] for p in me_polys: - # Backface culling (allows using spheres without tedious manual deleting). - if p.normal.z <= 0.0: - continue - + # Note, all faces are handled, backfacing/zero area is checked just before writing. material_index = p.material_index if material_index < len(material_colors): base_color = material_colors[p.material_index] @@ -179,7 +181,7 @@ def mesh_data_lists_from_objects(ob_parent, ob_children): for ob in (ob_parent, *ob_children): with TriMesh(ob) as me: if has_parent: - me.transform(parent_matrix_inverted * ob.matrix_world) + me.transform(parent_matrix_inverted @ ob.matrix_world) tris_data.extend( mesh_data_lists_from_mesh( @@ -243,10 +245,18 @@ def write_mesh_to_py(fh, ob, ob_children): # X, Y fw(bytes((0, 0))) - for (_, tri_coords, _) in tris_data: - for vert in tri_coords: - fw(bytes(vert_as_byte_pair(vert))) - for (_, _, tri_color) in tris_data: + # Once converted into bytes, the triangle might become zero area + tri_skip = [False] * len(tris_data) + for i, (_, tri_coords, _) in enumerate(tris_data): + tri_coords_as_byte = [vert_as_byte_pair(vert) for vert in tri_coords] + if area_tri_signed_2x_v2(*tri_coords_as_byte) <= 0: + tri_skip[i] = True + continue + for vert_byte in tri_coords_as_byte: + fw(bytes(vert_byte)) + for i, (_, _, tri_color) in enumerate(tris_data): + if tri_skip[i]: + continue for color in tri_color: fw(bytes(color)) |