Open Herzdame opened 3 years ago
Hi,
I hope that this answer may help you.
According to my understanding, Triangle ID
outputs the names or the numbers of the triangles in the overall 3d model that are closest to the points in question. If you have a mesh with 5000 triangles, you will get a column with the "name/number" of each triangle between #0 and #4999 that is closest to a point.
The function mesh.triangles
returns the coordinates of the vertices that span the respective triangle in the 3D model. So in this example, you should get an array with 5000, 3, 3 values. Each triangle is described by 3 points with X, Y and Z values.
What helped me was to analyze the 3d model in Meshlab. Import it, turn the wireframe
view on and press the Get Info
button. There you will see, that each triangle has an ID and 3 vertices.
I hope that I could help you further :)
`import pywavefront import trimesh import numpy as np from trimesh import proximity from trimesh import util from trimesh import triangles
model = pywavefront.Wavefront('C:/Users/Darija/Documents/Modell.obj', collect_faces=True)
print(model.vertices) # gibt dir alle Punkte aus
for mesh in model.mesh_list: # Die Flächen "faces" stecken in den "meshes" print(mesh.faces)
mesh = trimesh.Trimesh(model.vertices, mesh.faces)
ray_origins = np.tile(np.array([2.0,6.5,1.5]), (1000,1))
ray_directions = np.random.uniform(-1, 1, (1000,3))
print(mesh.ray.intersects_location.doc) print(ray_directions) locations, index_ray, index_tri = mesh.ray.intersects_location( ray_origins = ray_origins, ray_directions = ray_directions, multiple_hits=False)
print('Strahl trifft Mesh bei folgender Koordinate:\n', locations)
ray_visualize = trimesh.load_path(np.hstack((ray_origins, ray_origins + ray_directions*5.0)).reshape(-1, 2, 3))
unmerge so viewer doesn't smooth
mesh.unmerge_vertices()
make mesh white- ish
mesh.visual.face_colors = [255,255,255,255] mesh.visual.face_colors[index_tri] = [255, 0, 0, 255]
create a visualization scene with rays, hits, and mesh
scene = trimesh.Scene([mesh,
show the visualization
scene.show()
p = np.loadtxt('C:/Users/Darija/PycharmProjects/Punktwolke/Punktwolke_Raum1_asbuilt_5000_S.txt')
faces = mesh.triangles[index_tri]
print('Triangles:', mesh.triangles)
def closest_point_naive2(mesh, points): """ Given a mesh and a list of points find the closest point on any triangle.
dist = closest_point_naive2(mesh, p)
print(index_tri)
print(mesh.triangles[index_tri])`
When I run the code it gives me triangle_ids that are not in mesh.triangles [index_tri]. I don't know where the problem is. Can someone help me?