1
$\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$
0
$\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.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.