Skip to content

Instantly share code, notes, and snippets.

@timknip
Created November 30, 2018 00:57
Show Gist options
  • Save timknip/ea406a8034149fa22f3318ca04d5c8c3 to your computer and use it in GitHub Desktop.
Save timknip/ea406a8034149fa22f3318ca04d5c8c3 to your computer and use it in GitHub Desktop.
import openmesh as om
import numpy as np
mesh = om.read_trimesh('earth.obj', vertex_normal=True, vertex_tex_coord=True)
# make mesh handle these attributes
mesh.request_vertex_normals()
mesh.request_vertex_texcoords2D()
# create decimater
decimator = om.TriMeshDecimater(mesh)
# Quadric decimater module (there's other modules as well..)
# print dir(om)
modQ = om.TriMeshModQuadricHandle()
# add it to the decimater
decimator.add(modQ)
# setup Quadric module
decimator.module(modQ).set_max_err(1e-5)
decimator.module(modQ).set_binary(False)
# initialize
decimator.initialize()
# go!
decimator.decimate_to(int(len(mesh.points()) * 0.1))
# always needed after decimation
mesh.garbage_collection()
om.write_mesh('test.obj', mesh, vertex_normal=True, vertex_tex_coord=True)
@SMY19999
Copy link

I just found it didn't work in my program and the model retained the same verts and faces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment