4

I am trying to find the vertices that are visible in camera view i.e inside camera range and not being hidden by another object.

Ive tried using ray casting but it seems it only check if the vertex is hidden the object itself not other objects

This is my current scene for reference. enter image description here

EDIT: My end goal is to select find a bounding box for each object based on whats visible in the object. So solutions like merging all the objects wont be helpful

Viplav Prakash
  • 595
  • 2
  • 13
  • You can use this. Simply you'll need to merge all concerned objects vertices (in world space) in the bvh tree. https://blender.stackexchange.com/questions/77607/how-to-get-the-3d-coordinates-of-the-visible-vertices-in-a-rendered-image-in-ble/77747#77747 – lemon Mar 17 '20 at 12:16
  • @brockmann "not being hidden by another object." – lemon Mar 17 '20 at 12:18
  • @lemon Yes I've already looked at that, the thing is I need to select some specific vertex on each object out of the visible ones. So merging them won't be useful for me. – Viplav Prakash Mar 17 '20 at 12:25
  • @ViplavPrakash, merging is only for the bvh. But you can iterate the test from each object vertices. – lemon Mar 17 '20 at 12:27
  • @lemon Well first of all I am not really keen on using ray casting seeing how its quite inaccurate. missing even 1 vertex in my case will result in a completely wrong bounding box.

    And second I am not sure how would I go about doing what you said, could you provide a little more detailed answer?

    – Viplav Prakash Mar 17 '20 at 12:33
  • @ViplavPrakash, about raycasting accuracy we can't do better... only possible trick looking at some vertices (say like a cube) around each real vertex. But that may lead to include unwanted vertices. So I don't think there is a better way. (and I don't beleive Blender coders have let a bug in the raycast, or possibly the script in the other question has a bug) – lemon Mar 17 '20 at 12:40
  • @lemon Another idea I had was to replicate this, when in object mode select all objects and to go edit mode then with select box tool draw a box on the screen and that selects all the visible vertices. Thing is I have no idea how to go about the drawing the box on-screen part with python – Viplav Prakash Mar 17 '20 at 12:47
  • 2
    Given can edit all mesh objects at once in 2.8 could use this method. https://blender.stackexchange.com/a/40826/15543 – batFINGER Mar 17 '20 at 12:49

1 Answers1

1

Alright, so I found I was to do this but this is not really ideal,

Basically, this will select all the visible vertices on the currently selected objects. As for how first go into camera view then into edit mode and draw a box using box selection and it will select every vertice that's visible

def selectVerts():
    bpy.ops.object.editmode_toggle()    
    for area in bpy.context.screen.areas:
        if area.type == "VIEW_3D":
            for region in area.regions:
                if region.type == "WINDOW":
                    view3dArea = area
                    view3dRegion = region
                    break

    override = bpy.context.copy()
    override['area'] = view3dArea
    override['region'] = view3dRegion
    bpy.ops.view3d.view_camera(override)
    bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=10)
    bpy.ops.view3d.select_box(override,  xmin=0, xmax=10000, ymin=0, ymax=10000, mode='SET')
    bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=10)
    bpy.ops.view3d.select_box(override,  xmin=0, xmax=10000, ymin=0, ymax=10000, mode='SET')
    bpy.ops.object.editmode_toggle()    
    bpy.ops.view3d.view_camera(override)

The biggest issue with this method is that if the object is too far away not all vertices are drawn by blender, so it gives really inaccurate results in such cases.

Viplav Prakash
  • 595
  • 2
  • 13