# Removing doubles on imported 3DXML ngon mesh

Pertaining to building objects created from the script shown in the answer here https://blender.stackexchange.com/a/42590/15543

The import data has seperate vert data for each surface, so each face can be selected and moved ( as shown in image ) which produces a lot of doubles. For example a simple cube would have 6 x 4 verts which after remove doubles would be reduced to 8.

Each surface has uv texture coordinates.

To vastly reduce the amount of verts in the scene I thought I would remove doubles. However, running the bpy.ops or bmesh.ops remove doubles also removes faces such as the one highlighted, leaving gaping holes in buildings.

Any suggestions on how to approach removing doubles on such meshes leaving faces intact, which can be ultimately be scripted?

If the poly is opened up like shown then remove doubles works well. If remove doubles is run on the separated but "closed" poly then remove doubles fills the holes with edges.

• Blender also removes the face when I execute Remove Doubles within the UI (Merge Distance is set to 0.00001), seems there is something wrong with the mesh... – p2or Dec 7 '15 at 15:16
• @poor Yep, same result as script. The import data simply gives a list of 3d verts and their corresponding 2d texture coords, which leads to some out there polys. Added a pic of the corresponding UV map. How to handle the verts on the "closed" edges is the hassle it seems. Architects are to blame lol. – batFINGER Dec 7 '15 at 15:48
• Hmm ok probably worked out how to do this.. if the surface has more than 1 double, remove those verts from the remove double op. – batFINGER Dec 7 '15 at 15:54
• All 'Clean up' operations tested, without any success. – p2or Dec 7 '15 at 16:00

EDIT

A better approach would be to look for the two "ripped" edges in a face that share the same geometry. (edges parallel with same mid point test or similar), and remove the edges verts from the remove doubles list.

Thanks for your help guys, The answer kinda came to me when I was creating pics to explain the situation and opened up the poly.

The trick was looking at faces with more than one double and removing them from the remove doubles operator, otherwise will end up trying to make a poly with holes, which ends up being a hole.

The following reduces vert count of building.014 from 4205 to 1258... and leaves the roof intact.

import bpy
import bmesh
context = bpy.context
obj = context.object
print("X" * 80)
bm = bmesh.new()
bm.from_mesh(obj.data)
bm.faces.ensure_lookup_table()
ignore_doubles = []
for f in bm.faces:
verts = f.verts
dubs = bmesh.ops.find_doubles(bm,
verts=verts,
dist=0.00001)
double_verts = dubs['targetmap']
if len(double_verts.keys()) > 1:
for k, v in double_verts.items():
ignore_doubles.append(v)

verts = list(set(bm.verts) - set(ignore_doubles))
bmesh.ops.remove_doubles(bm, verts=verts, dist=0.00001)

bm.to_mesh(context.object.data)


It appears that if you triangulate your mesh before removing doubles, it will prevent the deletion of these faces.

I hope the original n-gon topology isn't important to you :)

• Thanks, Certainly an option. I ended up with some rips in buildings when using ctrl-T. What did you use to triangulate? As in a comment to poor, the trick will be looking at faces with more than one double and removing them from the remove doubles operator, otherwise end up trying to make a poly with holes, which ends up being a hole. – batFINGER Dec 7 '15 at 16:11
• Great! Converting 'tris' to 'quads' afterwards could also be an option, but has (apparently) no effect on the n-gons. – p2or Dec 7 '15 at 16:11
• I used the ordinary Ctrl-T shortcut to triangulate in this example. It does appear that there are still some rips after this operation (selecting non-manifold shows this nicely, should have tried it before). Not all verts are double, it would seem. Perhaps you can use a higher distance threshold. – TLousky Dec 7 '15 at 16:12
• OK, used a higher distance threshold for remove doubles and it did get rid of most non manifold verts, but some still persist due to other issues. – TLousky Dec 7 '15 at 16:17