code cleanup: pass mval to ED_view3d_cursor3d_position() rather then
event x/y
code cleanup: no need to use list(range()), just use range()