For this line of code:
bm = bmesh.from_edit_mesh(mesh)
I am encountering the error 'ValueError: The mesh must be in editmode'
I am not certain how to fix this problem. For context, I am adapting the code solution at the bottom of this post, which was for an earlier version of Blender. My full code is here:
scene = bpy.context.scene
cam = bpy.data.objects['Camera']
obj = bpy.data.objects['Cube']
mesh = obj.data
mat_world = obj.matrix_world
cs, ce = cam.data.clip_start, cam.data.clip_end
bpy.ops.object.mode_set(mode='EDIT')
bm = bmesh.from_edit_mesh(mesh)
for v in bm.verts:
co_ndc = world_to_camera_view(scene, cam, mat_world * v.co)
#check wether point is inside frustum
if (0.0 < co_ndc.x < 1.0 and 0.0 < co_ndc.y < 1.0 and cs < co_ndc.z < ce):
v.select = True
else:
v.select = False
bmesh.update_edit_mesh(mesh, False, False)
bm = bmesh.from_mesh(mesh)? ... from the Text Editor > Python > Bmesh Simple. – brockmann Sep 10 '19 at 19:51bm=bmesh.from_mesh(mesh)throws the error "module 'bmesh' has no attribute 'from_mesh'" – vndep Sep 10 '19 at 20:43*with@and run it.... – brockmann Sep 10 '19 at 21:02context scene– HikariTW Sep 10 '19 at 22:32