import bpy import gpu import random from mathutils import Matrix from gpu_extras.presets import draw_circle_2d IMAGE_NAME = "Generated Image" WIDTH = 512 HEIGHT = 512 RING_AMOUNT = 10 class OBJECT_OT_Jabol(bpy.types.Operator): bl_idname = "object.jabol" bl_label = "Jabol" bl_options = {"REGISTER","UNDO"} @classmethod def poll(cls, context): return context.active_object def execute(self, 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 = gpu.types.GPUOffScreen(WIDTH, HEIGHT) with offscreen.bind(): #gpu.matrix.load_matrix(view_matrix) #gpu.matrix.load_projection_matrix(projection_matrix) fb = gpu.state.active_framebuffer_get() # fb.bind() buffer = fb.read_color(0, 0, WIDTH, HEIGHT, 4, 0, 'UBYTE') offscreen.free() if not IMAGE_NAME in bpy.data.images: bpy.data.images.new(IMAGE_NAME, WIDTH, HEIGHT) image = bpy.data.images[IMAGE_NAME] image.scale(WIDTH, HEIGHT) buffer.dimensions = WIDTH * HEIGHT * 4 image.pixels = [v / 255 for v in buffer] return {"FINISHED"} def register(): bpy.utils.register_class(OBJECT_OT_Jabol) def unregister(): bpy.utils.unregister_class(OBJECT_OT_Jabol) if __name__ == "__main__": register()