1
$\begingroup$

I'm working with some huge STL models broken into multiple meshes. To automate mesh refining, I'm using this code:

import bpy

scene = bpy.context.scene
selected = bpy.context.selected_objects

for obj in selected:
    scene.objects.active = obj
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.remove_doubles()
    bpy.ops.mesh.normals_make_consistent()
    bpy.ops.object.mode_set(mode='OBJECT')

It takes a significant amount of time to process. Am I doing this right, or is there a quicker way, perhaps with bpy.data?

$\endgroup$
1
$\begingroup$

The equivalent using BMesh and bmesh.ops would be:

import bpy
import bmesh

for obj in bpy.context.selected_objects:

    bm = bmesh.new()   # create an empty BMesh
    bm.from_mesh(obj.data)   # fill it in from a Mesh

    d = 0.0001
    bm_verts = bm.verts[:]
    bmesh.ops.remove_doubles(bm, verts=bm_verts, dist=d)

    bm_faces = bm.faces[:]
    bmesh.ops.recalc_face_normals(bm, faces=bm_faces)

    bm.to_mesh(obj.data)
    bm.free()

But, i doubt it will be much faster.

$\endgroup$
2
  • $\begingroup$ bmesh is much faster ( ~ 20x as fast ). Perhaps something wrong with my build. $\endgroup$ – Bartłomiej Szczepaniak Feb 21 '15 at 17:50
  • $\begingroup$ cool. I wonder how many objects you are doing this to? $\endgroup$ – zeffii Feb 21 '15 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.