I have a simple mesh like below. I want to do a Limited Dissolve (15 degrees) followed by a Convex Hull operation on the same. When I do it via Blender UI, I get the result as expected. But when I do the same via python script, I get incorrect result. The resulting geometry is not only different, it has some odd edges hanging out, which makes it completely unusable.

Can someone please suggest the correct code to reproduce the same result as below through python scripts?

Note: I am not so keen about keeping the original geometry intact. If the shape of the object somewhat changes after the operations, it is completely okay for me. But the resulting geometry has to be perfectly clean for further processing (like UV mapping etc). And the method should work on any arbitrary object since I have to run it for thousands of random objects of similar (but not same) shapes.

The original mesh without any edit done:

The original mesh without any edit done.

After limited dissolve in the edit mode:

After limited dissolve in the edit mode.

After converting it into a convex hull:

After converting it into a convex hull.

We have a clean topology, as seen here:

We have a clean topology, as seen here.

Same object after running this script:

Same object after running this script.

Here is the script that I am using. The blend file is also attached.

import bpy
import bmesh
import math

scene = bpy.context.scene
object = bpy.context.active_object

me = object.data
bm = bmesh.new()

# Limited dissolve.
bmesh.ops.dissolve_limit(bm, angle_limit=math.radians(15), use_dissolve_boundaries=False, verts=bm.verts, edges=bm.edges, delimit={'NORMAL'})

# Convert to a convex hull.
me = bpy.data.meshes.new("%s convexhull" % me.name)
ch = bmesh.ops.convex_hull(bm, input=bm.verts, use_existing_faces=True)
bmesh.ops.delete(bm, geom=ch["geom_unused"] + ch["geom_interior"], context='VERTS',)

object.data = me

What is my ultimate goal: I am trying to reduce the poly count of this mesh programmatically. I have hundreds of such meshes with thousands of vertices. I want to reduce the vertex count for each of them to less than hundred. That is my final goal. In the process, I am willing to compromise with the shape a bit, but not much. The output mesh can be slightly different in shape, it is okay, but it has to have a clean geometry. If someone has a better suggestion to reach that goal, instead of a direct solution of the above, it is surely welcome!

  • $\begingroup$ Your Blend-Exchange link seems to be broken $\endgroup$
    – Psyonic
    Dec 24, 2022 at 4:47
  • $\begingroup$ @Psyonic I have opened this page without any login, clicked on the file link, downloaded it, and opened it in Blender. It opened flawlessly. So I believe the link is perfect. But if you are unable to access it for some reason, I can send it via mail. Please let me know your mail ID. Thanks for your kind attention! $\endgroup$
    – Jeet GT
    Dec 24, 2022 at 18:06
  • $\begingroup$ It's working now, maybe Blend-Exchange was having a bad day yesterday $\endgroup$
    – Psyonic
    Dec 24, 2022 at 21:28


You must log in to answer this question.

Browse other questions tagged .