Get visible vertices of a 3D mesh.

14 次查看(过去 30 天)
Gaurav
Gaurav 2017-4-8
编辑: Matt J 2024-2-10
Hi all,
I have a mesh with 'V' vertices and 'F' faces, I can plot the mesh using h = patch('vertices', V, 'faces', F, 'FaceVertexCData',repmat([0 0 1],[size(faces,1),1]),'FaceColor','none', 'EdgeColor', 'blue');
then I can do 'hidden on' and back faces/vertices are not visible [just like back face culling, here I guess internally being done by opengl renderer]. My question is: , How can I find which vertices are currently hidden? (in terms of hidden vertex/face indices).
Essentially I want to find indices of visible vertices of a solid object from a view point. I know there are some algorithms (intersecting meshes with lines etc.) but they are highly computationally intensive.) Now in Matlab using the simple 'hidden' functionality I can view it but can't get access to what are the things that are hidden.
Any help will be highly appreciated.
Thank you :)
  1 个评论
shuai zhang
shuai zhang 2022-7-31
Hi, currently I just have the same need as yours. the "hidden on" functionality in MATLAB can hidden the in-visible vertices. it will be great it enable the access to indices of in-visible vertices.
Any help will be highly appreciated!
Best regards :)

请先登录,再进行评论。

回答(2 个)

George Abrahams
George Abrahams 2024-2-10
编辑:George Abrahams 2024-2-10
Hi @Gaurav. You essentially want the rasterization process, but using the subpixel location of the vertices on the image plane, rather than the quantized pixel locations used to render an image. For this reason, the renderer in MATLAB likely doesn't know which vertices are visible, only which faces are visible at each pixel location.
Most of this can be done directly using my 3D Rendering Toolbox on File Exchange, but the later steps will require some minor modification to the code. To summarise:
  1. Project the vertices to the image plane. Use world2image. Any vertices which are removed by clipping are not visible, as they're outside of the camera's field-of-view. Vertices removed by back face culling may or may not be visible, depending on how you choose to define visible.
  2. For each of the (original) vertices, test which faces it is within, in 2D, and calculate its barycentric coordinates for those faces. Use edgefcn.
  3. Exclude faces that it is connected to. For each of the remaining faces, find the depth of the triangle at that 2D location. Calculate Z depth from the barycentric coordinates, as in rasterize.
  4. If any of these faces has a the depth at this location which is less than the vertex's Z coordinate, it is not visible. Otherwise, it is visible.

Matt J
Matt J 2024-2-10
编辑:Matt J 2024-2-10
You could,
(1) Use campos to get the position of the camera.
(2) Draw rays from the camera center to each of the vertices.
(3) Find the intersection of each of these rays with each mesh triangle, e.g., using intersectionHull.
(4) Test that both the following criteria is satisfied to see if a vertex is hidden:
(i) It's ray has a non-empty intersection with the interior of at least one triangle and,
(ii) The intersection point lies between the vertex and the camera

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by