Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The number of faces is 4x larger compared to vhacd in a test model #15

Closed
fy0 opened this issue May 23, 2023 · 2 comments
Closed

The number of faces is 4x larger compared to vhacd in a test model #15

fy0 opened this issue May 23, 2023 · 2 comments

Comments

@fy0
Copy link

fy0 commented May 23, 2023

out.glb is coacd result, 25 piceces, 1254 triangles
image

code:

import coacd
import trimesh
import numpy as np

input_file = './input.obj'
mesh = trimesh.load(input_file, force="mesh")
mesh = coacd.Mesh(mesh.vertices, mesh.faces)

parts = coacd.run_coacd(mesh, merge=True, threshold=0.05, resolution=2000, preprocess_resolution=50) # a list of convex hulls.

mesh_parts = []
for vs, fs in parts:
    mesh_parts.append(trimesh.Trimesh(vs, fs))

scene = trimesh.Scene()
np.random.seed(0)
for p in mesh_parts:
    p.visual.vertex_colors[:, :3] = (np.random.rand(3) * 255).astype(np.uint8)
    scene.add_geometry(p)

scene.export('./out.glb')

out2.glb is vhacd, 27 piceces, 374 triangles
image

code:

import trimesh
import numpy as np

input_file = './input.obj'
mesh = trimesh.load(input_file, force="mesh")

parts = trimesh.interfaces.vhacd.convex_decomposition(mesh, maxhulls=10)

#print(parts)

#mesh_parts = []
#for vs, fs in parts:
#    mesh_parts.append(trimesh.Trimesh(vs, fs))

scene = trimesh.Scene()
np.random.seed(0)
for p in parts:
    p.visual.vertex_colors[:, :3] = (np.random.rand(3) * 255).astype(np.uint8)
    scene.add_geometry(p)

scene.export('./out2.glb')

source model:
image

files:
test.zip

I feel like the triangles are mainly on the smooth edges. Is there a way to make the edges of the model sharper?

P.S. windows verison seems not work, tested on 2 computers, windows11 anaconda python 3.10.

@Lootheo
Copy link

Lootheo commented Jun 1, 2023

I have this same issue, is there a way to not generate those smooth edges?

Also I cant seem to be able compile on windows.

@SarahWeiii
Copy link
Owner

SarahWeiii commented Jun 1, 2023

The smooth edge problem is caused by mesh pre-processing, which turns a non-manifold mesh into manifold one, and it can introduce more triangles and smoothen the edges.
You may disable the pre-process by adding preprocess=False to run_coacd and then the algorithm will keep the original shape as much as possible. Though using non-manifold mesh as input may have the risk of breaking the algorithm, it works in most cases in practice.

This is the result disabling pre-process with default parameters. (python py_example.py -i input.obj -o coacd_out.obj --no-preprocess)
[17 pieces / 145 vertices / 222 faces]
image
coacd_out.zip

For the windows compiling problem, make sure you are using the latest code (we have updated it for windows a few weeks ago), and you may try installing vc redist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants