Skip to content

Report a bug in signed_distance_to_mesh function. #97

@Maikouuu

Description

@Maikouuu

Hi,

Thanks for your excellent implementation.

I am calling signed_distance_to_mesh() to compute the signed distances of a triangle mesh with a uniform sampled volume. However, I find something quite strange when I apply a marching cube to the signed distance: the extracted mesh suffers a significant distortion from the original. The images below show that the signed distances of the left hood may be incorrect.

Original:
截屏2024-09-08 03 28 59

Extracted:
截屏2024-09-08 03 30 18

The car.obj file and code block are attached to reproduce it.

car.obj.zip

import numpy as np
import trimesh
import point_cloud_utils as pcu
from skimage.measure import marching_cubes

# init query point
octree_depth = 7
boundary = 1.0
bbox_min = np.array([-boundary, -boundary, -boundary])
bbox_max = np.array([boundary, boundary, boundary])
bbox_size = bbox_max - bbox_min
length = bbox_max - bbox_min
num_cells = np.exp2(octree_depth)
x = np.linspace(bbox_min[0], bbox_max[0], int(num_cells) + 2, dtype=np.float32)
y = np.linspace(bbox_min[1], bbox_max[1], int(num_cells) + 2, dtype=np.float32)
z = np.linspace(bbox_min[2], bbox_max[2], int(num_cells) + 2, dtype=np.float32)
[xs, ys, zs] = np.meshgrid(x, y, z, indexing="ij")
xyz = np.stack((xs, ys, zs), axis=-1)
query_points = xyz.reshape(-1, 3)
grid_size = [int(num_cells) + 2, int(num_cells) + 2, int(num_cells) + 2]

# load mesh
mesh = trimesh.load('car.obj')
v = mesh.vertices
f = mesh.faces

# compute sdf
sdf = mesh2sdf.core.compute(v, f, size=int(np.exp2(octree_depth)))
sdf.resize(grid_size[0], grid_size[1], grid_size[2])

# extract mesh
vertices, faces, normals, _ = marching_cubes(query_sdf, level=0)
watertight_mesh = trimesh.Trimesh(vertices, faces, normals=normals)
watertight_mesh.export('watertight_mesh.obj')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions