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

Defect Insertion #2158

Open
anshul49 opened this issue Feb 21, 2024 · 0 comments
Open

Defect Insertion #2158

anshul49 opened this issue Feb 21, 2024 · 0 comments

Comments

@anshul49
Copy link

import trimesh
import numpy as np

# Load meshes
try_mesh = trimesh.load_mesh('/Users/xd_anshul/Desktop/Research/Defect/obj.stl')
defect_mesh = trimesh.load_mesh('/Users/xd_anshul/Desktop/Research/Defect/sphere.ply')
defect_mesh.apply_scale(0.04)

# Voxelize object mesh
voxel_grid = trimesh.voxel.creation.voxelize(try_mesh, 0.003)  # Adjust resolution as needed

# Get all voxel centers
voxel_centers = voxel_grid.points

# Select a random voxel center
random_voxel_index = np.random.randint(len(voxel_centers))
random_voxel_center = voxel_centers[random_voxel_index]

# Translate defect mesh to random voxel center
defect_mesh.apply_translation(random_voxel_center)
defect_mesh.visual.vertex_colors = trimesh.visual.random_color()

# Perform Boolean difference (using a suitable engine)
try_mesh = trimesh.boolean.difference([try_mesh, defect_mesh], engine="blender")  # Adjust engine if needed

scene = trimesh.Scene([try_mesh,defect_mesh])
scene.show()  # Visualize

This could add a surface defect wasily, but I wanted to insert the defecr completely! Any suggestion?

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

1 participant