Removing doubles on imported 3DXML ngon mesh

by batFINGER   Last Updated July 07, 2018 11:15 AM

Pertaining to building objects created from the script shown in the answer here

enter image description here

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.

enter image description here

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.

enter image description here

Tags : python mesh bmesh

Answers 2

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 :)

enter image description here

December 07, 2015 15:55 PM


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 =
ignore_doubles = []
for f in bm.faces:
    verts = f.verts
    dubs = bmesh.ops.find_doubles(bm,
    double_verts = dubs['targetmap']
    if len(double_verts.keys()) > 1:
        for k, v in double_verts.items():

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

December 07, 2015 16:49 PM

Related Questions

Blender Alters .Obj vertex list

Updated March 26, 2015 07:27 AM

Fix t-junction in mesh

Updated March 28, 2015 11:05 AM

BMesh get edge loop

Updated May 21, 2017 19:15 PM

Can't write bmesh object back to mesh datablock

Updated August 08, 2015 14:06 PM

Problem with BMesh Vertex Location Precision

Updated March 03, 2017 20:15 PM