Page MenuHome

X3D Exporter generates duplicate edges and splits the mesh when exporting with Triangulate
Open, NormalPublic

Description

System Information
Windows 10, NVidia GTX 780

Blender Version
Broken: 2.76, 2.78 RC1, 2.78 RC2
Worked: Unknown

Short description of error
When running the x3d exporter with Triangulate enabled some of the vertices in the mesh get saved multiple times resulting in duplicate vertices and edges. The result is a "cut" in the surface that can be opened up by moving one of the duplicate vertices or edges.
The attached screenshot shows the original mesh (to the left, with one of the edges that get duplicated selected) and the mesh after exporting and then reimporting the mesh with Triangulate enabled (to the right) with the "cut" opened to show which edges are being duplicated.

Exact steps for others to reproduce the error

  1. Open the .blend file.
  2. Export to .x3d, with Triangulate enabled
  3. Reimport the .x3d file into blender or open it in any other software that supports .x3d files.

Details

Type
Bug

Event Timeline

I have already done some analysis of the bug and discovered the following:

In io_scene_x3d/export_x3d.py down by line 750, when the vertices that get duplicated are being stored in vert_tri_list, the key that is stored in vertex_hash is a tuple containing the uv coordinates of that vertex. From my observation there seems to be a risk of some of the faces that are enumerated over that contain the same edges having slightly different UV coordinates stored (which seems like it might be a float precision problem.)
The solution I am using to get around this which seems to work is to replace line 736:

mesh_faces_uv[fidx].uv[f_cnr_idx][:],

with

tuple([round(val, 7) for val in mesh_faces_uv[fidx].uv[f_cnr_idx][:]]),

Which means I'm really just rounding it down to 7 decimal points, at which point the precision error seems to go away on the meshes I have gotten the problem in.
This might not be the root cause (as it might be a bug that the UV coordinates differ) which is why I am submitting this as a bug rather than a patch.

I am also not sure if there is a reason why the UV coordinates are stored as the key instead of the vertex index (v_idx), it is possible that using that index instead of relying on the UV coordinates might be a better solution.

Sergey Sharybin (sergey) triaged this task as Normal priority.Sep 27 2016, 12:31 PM

@Bastien Montagne (mont29), see you in the addon maintainers! ;) Mind having a look here? :)

The workaround I described turned out to not work for cases where a split is actually intended, since any vertices that are at the same coordinates will end up being merged.
My new approach, which so far seems to work, was to still round the coordinates down to the 7th decimal but to also add the vertex id to the key when matching on uv.

So

elif is_uv:
    slot_uv = 0

    def vertex_key(fidx, f_cnr_idx):
        return (
            mesh_faces_uv[fidx].uv[f_cnr_idx][:],
        )

instead becomes

elif is_uv:
    slot_uv = 0

    def vertex_key(fidx, f_cnr_idx, v_idx):
        return (
            tuple([round(val, 7) for val in mesh_faces_uv[fidx].uv[f_cnr_idx][:]] + [v_idx]),
        )

And I then just made sure to pass in v_idx to vertex_key when looping through the faces right below in the code.

It's been a while since this was commited, anyone how can find the time to review this? Thanks

sorry to bother. Any updates on this?

any feedback would be greatly appreciated so that we can move forward with other exporter contributions for the blender community.

Sorry to bother again. Any news on this? We submitted it over a year ago.