4
$\begingroup$

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

$\endgroup$
9
  • $\begingroup$ Does this answer your question? Python: Check if vertex is on camera field of view $\endgroup$
    – brockmann
    Mar 17, 2020 at 12:16
  • $\begingroup$ You can use this. Simply you'll need to merge all concerned objects vertices (in world space) in the bvh tree. blender.stackexchange.com/questions/77607/… $\endgroup$
    – lemon
    Mar 17, 2020 at 12:16
  • $\begingroup$ @brockmann "not being hidden by another object." $\endgroup$
    – lemon
    Mar 17, 2020 at 12:18
  • $\begingroup$ @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. $\endgroup$ Mar 17, 2020 at 12:25
  • 2
    $\begingroup$ Given can edit all mesh objects at once in 2.8 could use this method. blender.stackexchange.com/a/40826/15543 $\endgroup$
    – batFINGER
    Mar 17, 2020 at 12:49

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .