Skip to content

Instantly share code, notes, and snippets.

@furby-tm
Created March 20, 2019 15:52
Show Gist options
  • Save furby-tm/8d7e686748a3d6409343169c1c9429b3 to your computer and use it in GitHub Desktop.
Save furby-tm/8d7e686748a3d6409343169c1c9429b3 to your computer and use it in GitHub Desktop.
def view_draw(engine, depsgraph, region, space_data, region_data):
#print(">>> view_draw [%f]:" % time.clock(), engine)
try:
region = bpy.context.region
v3d = bpy.context.space_data
rv3d = bpy.context.region_data
data = {}
_camera = {}
ipr = engine._ipr
width = region.width
height = region.height
view_matrix = rv3d.view_matrix
if view_matrix != ipr.view_matrix:
ipr.view_matrix = view_matrix.copy()
_camera['matrix'] = ('MATRIX', numpy.reshape(view_matrix.inverted().transposed(), -1))
view_perspective = rv3d.view_perspective
if view_perspective != ipr.view_perspective:
ipr.view_perspective = view_perspective
if view_perspective == 'CAMERA':
ipr.camera_data = _view_update_camera(region.width / region.height, v3d, rv3d, _camera)
elif view_perspective == 'PERSP':
ipr.camera_data = _view_update_persp(v3d, _camera)
else:
# TODO: orpho
return
elif view_perspective == 'CAMERA':
cdata = v3d.camera.data
fit = cdata.sensor_fit
sensor = cdata.sensor_height if fit == 'VERTICAL' else cdata.sensor_width
offset_x, offset_y = rv3d.view_camera_offset
camera_data = (rv3d.view_camera_zoom, fit, sensor, cdata.lens,
offset_x, offset_y, cdata.shift_x, cdata.shift_y)
if camera_data != ipr.camera_data:
ipr.camera_data = _view_update_camera(region.width / region.height, v3d, rv3d, _camera)
elif view_perspective == 'PERSP':
lens = v3d.lens
if lens != ipr.camera_data[0]:
_camera['fov'] = ('FLOAT', math.degrees(2 * math.atan(64.0 / (2 * lens))))
ipr.camera_data = (lens, )
else:
# TODO: orpho
return
if _camera:
data.setdefault('nodes', {})['__camera'] = _camera
(width, height), rect = ipr.update(width, height, data)
# Draw IPR OpenGL to Viewport
OpenGL.draw(width, height, rect)
except:
print("~" * 30)
traceback.print_exc()
print("~" * 30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment