Python API example "rendering-the-3d-view-into-a-texture" doesn't work. #92238

Closed
opened 2021-10-15 17:01:18 +02:00 by Evan Wilson · 3 comments
Member

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce GTX 470/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 391.35

Blender Version
Broken: version: 3.0.0 Alpha, branch: master, commit date: 2021-10-13 21:57, hash: blender/blender@9dff3de6ac
Worked: (newest version of Blender that worked as expected)

Short description of error
No window is produced when running the following example code from the python API documentation:
https://docs.blender.org/api/master/gpu.html#rendering-the-3d-view-into-a-texture
Checking the console reveals:

Read prefs: C:\Users\Evan\Downloads\blender-3.0.0-alpha+master.9dff3de6acb3-windows.amd64-release\3.0\config\userpref.blend
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

File "\Text", line 20, in draw

TypeError: draw_view3d() takes exactly 6 positional arguments (7 given)
Traceback (most recent call last):

Exact steps for others to reproduce the error
Run the following code in the scripting workspace.

import bpy
import gpu
from gpu_extras.presets import draw_texture_2d

WIDTH = 512
HEIGHT = 256

offscreen = gpu.types.GPUOffScreen(WIDTH, HEIGHT)


def draw():

context = bpy.context
scene = context.scene


view_matrix = scene.camera.matrix_world.inverted()


projection_matrix = scene.camera.calc_matrix_camera(
context.evaluated_depsgraph_get(), x=WIDTH, y=HEIGHT)


offscreen.draw_view3d(
scene,
context.view_layer,
context.space_data,
context.region,
view_matrix,
projection_matrix,
True)


gpu.state.depth_mask_set(False)
draw_texture_2d(offscreen.texture_color, (10, 10), WIDTH, HEIGHT)



bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL')

Changing the 7th argument on line 27 from True to do_color_management=True allows the script to run. As Python knowledge isn't my specialty, I am not sure if simply updating the example to use do_color_management=True is the proper fix, or if this error reveals a deeper issue.

**System Information** Operating system: Windows-10-10.0.19041-SP0 64 Bits Graphics card: GeForce GTX 470/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 391.35 **Blender Version** Broken: version: 3.0.0 Alpha, branch: master, commit date: 2021-10-13 21:57, hash: `blender/blender@9dff3de6ac` Worked: (newest version of Blender that worked as expected) **Short description of error** No window is produced when running the following example code from the python API documentation: https://docs.blender.org/api/master/gpu.html#rendering-the-3d-view-into-a-texture Checking the console reveals: ```lines Read prefs: C:\Users\Evan\Downloads\blender-3.0.0-alpha+master.9dff3de6acb3-windows.amd64-release\3.0\config\userpref.blend Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` File "\Text", line 20, in draw ``` TypeError: draw_view3d() takes exactly 6 positional arguments (7 given) Traceback (most recent call last): ``` **Exact steps for others to reproduce the error** Run the following code in the scripting workspace. ``` import bpy import gpu from gpu_extras.presets import draw_texture_2d WIDTH = 512 HEIGHT = 256 offscreen = gpu.types.GPUOffScreen(WIDTH, HEIGHT) def draw(): ``` context = bpy.context scene = context.scene ``` ``` view_matrix = scene.camera.matrix_world.inverted() ``` ``` projection_matrix = scene.camera.calc_matrix_camera( context.evaluated_depsgraph_get(), x=WIDTH, y=HEIGHT) ``` ``` offscreen.draw_view3d( scene, context.view_layer, context.space_data, context.region, view_matrix, projection_matrix, True) ``` ``` gpu.state.depth_mask_set(False) draw_texture_2d(offscreen.texture_color, (10, 10), WIDTH, HEIGHT) ``` bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL') ``` Changing the 7th argument on line 27 from `True` to `do_color_management=True` allows the script to run. As Python knowledge isn't my specialty, I am not sure if simply updating the example to use `do_color_management=True` is the proper fix, or if this error reveals a deeper issue.
Author
Member

Added subscriber: @EAW

Added subscriber: @EAW

This issue was referenced by blender/blender@138fdf78ba

This issue was referenced by blender/blender@138fdf78ba4c4d691e1ed3a474735b5cffa553b7
Member

Changed status from 'Needs Triage' to: 'Resolved'

Changed status from 'Needs Triage' to: 'Resolved'
Aaron Carlisle self-assigned this 2021-10-15 23:56:44 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-manual#92238
No description provided.