Пример #1
0
    def view_draw_image(self, context, width, height, raw):
        region = context.region
        view = context.region_data

        vmat = view.view_matrix.copy()
        vmat_inv = vmat.inverted()
        pmat = view.perspective_matrix * vmat_inv

        viewport = [region.x, region.y, region.width, region.height]

        self.update_view(vmat, pmat, viewport)
        #raw = [[255, 0, 0, 255]] * (width * height)
        pixel_count = width * height
        print("VIEW DRAW RAW:" + str(len(raw)) + " count:" +
              str(pixel_count * 4))
        bitmap = bgl.Buffer(bgl.GL_BYTE, [pixel_count * 4], raw)
        # bgl.glBitmap(self.size_x, self.size_y, 0, 0, 0, 0, bitmap)
        scalex = 1.0 / width * 2
        scaley = 1.0 / height * 2
        bgl.glRasterPos2i(0, 0)
        # bgl.glWindowPos2i(0,0)
        #bgl.glPixelZoom( scalex,-scaley );
        bgl.glDrawPixels(
            width,
            height,
            # Blender.BGL.GL_BGRA, Blender.BGL.GL_UNSIGNED_BYTE,
            # 0x80E1 0x1908
            0x1908,
            0x1401,
            # bgl.GL_BGRA, bgl.GL_UNSIGNED_BYTE,
            bitmap)
Пример #2
0
	def view_draw(self, context):
		print("LuxCore view_draw call")
		
		# Check if the size of the window is changed
		if (self.filmWidth != context.region.width) or (self.filmHeight != context.region.height):
			self.view_update(context)
		
		# Update statistics
		self.session.UpdateStats()

		stats = self.session.GetStats();
		print("[Elapsed time: %3d][Samples %4d][Avg. samples/sec % 3.2fM on %.1fK tris]" % (
				stats.Get("stats.renderengine.time").GetFloat(),
				stats.Get("stats.renderengine.pass").GetInt(),
				(stats.Get("stats.renderengine.total.samplesec").GetFloat()  / 1000000.0),
				(stats.Get("stats.dataset.trianglecount").GetFloat() / 1000.0)))
		
		# Update the screen
		self.session.GetFilm().GetOutputFloat(pyluxcore.FilmOutputType.RGB_TONEMAPPED, self.imageBufferFloat)
		glBuffer = bgl.Buffer(bgl.GL_FLOAT, [self.filmWidth * self.filmHeight * 3], self.imageBufferFloat)
		bgl.glRasterPos2i(0, 0)
		bgl.glDrawPixels(self.filmWidth, self.filmHeight, bgl.GL_RGB, bgl.GL_FLOAT, glBuffer);
		
		# Trigger another update
		self.tag_redraw()
Пример #3
0
    def view_draw(self, context):
        print("LuxCore view_draw call")

        # Check if the size of the window is changed
        if (self.filmWidth != context.region.width) or (self.filmHeight !=
                                                        context.region.height):
            self.view_update(context)

        # Update statistics
        self.session.UpdateStats()

        stats = self.session.GetStats()
        print(
            "[Elapsed time: %3d][Samples %4d][Avg. samples/sec % 3.2fM on %.1fK tris]"
            % (stats.Get("stats.renderengine.time").GetFloat(),
               stats.Get("stats.renderengine.pass").GetInt(),
               (stats.Get("stats.renderengine.total.samplesec").GetFloat() /
                1000000.0),
               (stats.Get("stats.dataset.trianglecount").GetFloat() / 1000.0)))

        # Update the screen
        self.session.GetFilm().GetOutputFloat(
            pyluxcore.FilmOutputType.RGB_TONEMAPPED, self.imageBufferFloat)
        glBuffer = bgl.Buffer(bgl.GL_FLOAT,
                              [self.filmWidth * self.filmHeight * 3],
                              self.imageBufferFloat)
        bgl.glRasterPos2i(0, 0)
        bgl.glDrawPixels(self.filmWidth, self.filmHeight, bgl.GL_RGB,
                         bgl.GL_FLOAT, glBuffer)

        # Trigger another update
        self.tag_redraw()
Пример #4
0
 def processMessage(self, header_sizeBytes, header_messageType, data):
     if header_messageType == FromServer.Result:
         self.renderedView = True
         resolution = struct.unpack_from('=HH', memoryview(data))
         imageSizeBytes = resolution[0] * resolution[1] * 4
         glBuffer = bgl.Buffer(bgl.GL_BYTE, [imageSizeBytes],
                               list(data[4:4 + imageSizeBytes]))
         bgl.glRasterPos2i(0, 0)
         bgl.glDrawPixels(resolution[0], resolution[1], bgl.GL_RGBA,
                          bgl.GL_UNSIGNED_BYTE, glBuffer)
Пример #5
0
 def view_draw_image(self, width, height, raw):
     # raw = [[0, 255, 0, 255]] * (width * height)
     pixel_count = width * height
     bitmap = bgl.Buffer(bgl.GL_BYTE, [pixel_count * 4], raw)
     # bgl.glBitmap(self.size_x, self.size_y, 0, 0, 0, 0, bitmap)
     bgl.glRasterPos2i(0, 0)
     bgl.glDrawPixels(width, height,
                      # Blender.BGL.GL_BGRA, Blender.BGL.GL_UNSIGNED_BYTE,
                      0x80E1, 0x1401,
                      # bgl.GL_BGRA, bgl.GL_UNSIGNED_BYTE,
                      bitmap
                      )
Пример #6
0
def drawIcon(image_file, pos_x, pos_y):
    bgl.glPushClientAttrib(bgl.GL_CURRENT_BIT|bgl.GL_ENABLE_BIT)

    # transparence
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

    bgl.glRasterPos2f(pos_x, pos_y)

    buf = buffers[image_file]
    bgl.glDrawPixels(ICON_SIZE, ICON_SIZE, bgl.GL_RGBA, bgl.GL_FLOAT, buf)

    bgl.glPopClientAttrib()
Пример #7
0
    def view_draw(self, context):
        region = context.region
        view_3d = context.region_data

        pixels = self.do_render(
            context.scene, region.width, region.height, view_3d.view_matrix,
            view_3d.window_matrix,
            view_3d.view_matrix.inverted().transposed()[3][:3])

        pixel_count = region.width * region.height
        bitmap = bgl.Buffer(bgl.GL_FLOAT, [pixel_count * 3], pixels)

        bgl.glRasterPos2i(0, 0)
        bgl.glDrawPixels(region.width, region.height, bgl.GL_RGB, bgl.GL_FLOAT,
                         bitmap)
Пример #8
0
 def view_draw(self, context):
     bgl.glRasterPos2i(0, 0)
     bgl.glDrawPixels(self.width, self.height, bgl.GL_RGB, bgl.GL_FLOAT,
                      self.glbuffer)
     bgl.glDisable(bgl.GL_BLEND)
    def draw_callback_px_moving_arrow(self, context):
        #print("drawing")

        DPI = bpy.context.user_preferences.system.dpi
        print("Rendering moving arrow with DPI " + str(DPI))

        int_selection_num = int(self.selection_num)
        n_items = len(self.selectable_items)

        # Phylosophy
        # We try to use the fraction of the current heght of the area, but up to a maximum font size

        # Number of items to really display
        n_items_to_display = min(MAX_DISPLAY_ELEMENTS,
                                 len(self.selectable_items))

        # Calculate the top point
        text_top_y = context.region.height * (
            (1 + SELECTION_DISPLAY_HEIGHT) / 2)

        # calc the desired text area height
        desired_bottom_y = context.region.height * (
            (1 - SELECTION_DISPLAY_HEIGHT) / 2)
        desired_text_area_height = text_top_y - desired_bottom_y
        # calc the desired the font size
        font_size = int(desired_text_area_height / n_items_to_display)
        # But limit the font size to their maximum
        font_size = min(font_size, self.FONT_MAX_SIZE)
        # The effective size of the text area, according to the chosen font size
        text_area_height = font_size * n_items_to_display
        # recompute the bottom point according to chosen font size
        text_bottom_y = text_top_y - text_area_height

        #print("Font_size = " + str(font_size))

        bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)

        blf.size(0, font_size, DPI)

        #
        # Draw background
        max_text_width = 0
        for item in self.selectable_items:
            item_w, item_h = blf.dimensions(0, item)
            if (item_w > max_text_width):
                max_text_width = item_w

        self.draw_bg(context=context,
                     top_y=text_top_y,
                     bottom_y=text_bottom_y,
                     width=max_text_width * 1.5)

        #
        # Draw entries
        pos_x = 0
        pos_y = text_top_y - font_size
        pos_y += self.selection_window_first_item * font_size

        for item_id in range(0, len(self.selectable_items)):
            item = self.selectable_items[item_id]

            item_w, item_h = blf.dimensions(0, item)
            pos_x = (context.region.width / 2) - item_w

            blf.position(0, pos_x, pos_y, 0)

            if (item_id == int_selection_num):
                bgl.glColor4f(*self.SELECTED_FONT_RGBA)
            else:
                bgl.glColor4f(*self.FONT_RGBA)

            blf.draw(0, item)
            pos_y -= font_size

        bgl.glPopAttrib()

        #
        # Draw pointing finger
        bgl.glPushClientAttrib(bgl.GL_CURRENT_BIT | bgl.GL_ENABLE_BIT)

        # transparence
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        if (not self.selector_visible):
            pos_x = (context.region.width / 2) + self.ICON_SIZE
            pos_y = text_top_y - self.ICON_SIZE
            bgl.glRasterPos2f(pos_x, pos_y)
            bgl.glDrawPixels(self.ICON_SIZE, self.ICON_SIZE, bgl.GL_RGBA,
                             bgl.GL_FLOAT, icon_pointing_finger_missing)
        else:
            pos_x = (context.region.width / 2)
            pos_y = text_bottom_y + self.normalized_finger_y * text_area_height - (
                self.ICON_SIZE * 0.625)
            bgl.glRasterPos2f(pos_x, pos_y)
            bgl.glDrawPixels(self.ICON_SIZE, self.ICON_SIZE, bgl.GL_RGBA,
                             bgl.GL_FLOAT, icon_pointing_finger)

        bgl.glPopClientAttrib()

        pass
    def draw_callback_px_moving_text(self, context):

        DPI = bpy.context.user_preferences.system.dpi
        #print("Rendering moving text with DPI "+str(DPI))

        #print("selection= "+str(self.selection_num))
        int_selection_num = int(self.selection_num)

        n_items = len(self.selectable_items)

        # Phylosophy
        # We try to use the fraction of the current heght of the area, but up to a maximum font size

        # Number of items to really display
        n_items_to_display = min(MAX_DISPLAY_ELEMENTS,
                                 len(self.selectable_items))

        # Calculate the top point
        text_top_y = context.region.height * (
            (1 + SELECTION_DISPLAY_HEIGHT) / 2)

        # calc the desired text area height
        desired_bottom_y = context.region.height * (
            (1 - SELECTION_DISPLAY_HEIGHT) / 2)
        desired_text_area_height = text_top_y - desired_bottom_y
        # calc the desired the font size
        font_size = int(desired_text_area_height / n_items_to_display)
        # But limit the font size to their maximum
        font_size = min(font_size, self.FONT_MAX_SIZE)
        # The effective size of the text area, according to the chosen font size
        text_area_height = font_size * n_items_to_display
        # recompute the bottom point according to chosen font size
        text_bottom_y = text_top_y - text_area_height

        #print(str(self.FONT_MAX_SIZE)+" fs="+str(font_size))

        central_y = text_bottom_y + int(text_area_height / 2)

        bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)

        # Set the font size now, because it will be needed to estimate the background size.
        blf.size(0, font_size, DPI)

        #
        # Draw background
        max_text_width = 0
        for item in self.selectable_items:
            item_w, item_h = blf.dimensions(0, item)
            if (item_w > max_text_width):
                max_text_width = item_w
        self.draw_bg(context,
                     top_y=text_top_y,
                     bottom_y=text_bottom_y,
                     width=max_text_width * 1.5,
                     cover_pointer=True)

        #
        # Draw entries
        #
        pos_x = 0

        # The first item will be drawn on the very top, according to the current selection and its position on screen
        # The offset uses (self.selection_num - 1) because the text is written with the y at the bottom line.
        # However, it is easier to calculate thinking of its beginning at the top. So we shift the text up of one line.
        pos_y = central_y + ((self.selection_num - 1) * font_size)

        for item_id in range(0, n_items):
            item = self.selectable_items[item_id]

            item_w, item_h = blf.dimensions(0, item)
            pos_x = (context.region.width / 2) - item_w

            blf.position(0, pos_x, pos_y, 0)

            if (item_id == int_selection_num):
                bgl.glColor4f(*self.SELECTED_FONT_RGBA)
            else:
                bgl.glColor4f(*self.FONT_RGBA)

            #print("Drawing item at "+str(pos_x) + "\t" + str(pos_y))
            blf.draw(0, item)

            pos_y -= font_size

        bgl.glPopAttrib()

        #
        # Draw pointing finger
        bgl.glPushClientAttrib(bgl.GL_CURRENT_BIT | bgl.GL_ENABLE_BIT)

        # transparence
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        # The finger icon (64x64) has the finget tip at pixel 23 from the top, or 40 from the bottom
        pos_y = central_y - 40

        if (not self.selector_visible):
            pos_x = (context.region.width / 2) + self.ICON_SIZE
            bgl.glRasterPos2f(pos_x, pos_y)
            bgl.glDrawPixels(self.ICON_SIZE, self.ICON_SIZE, bgl.GL_RGBA,
                             bgl.GL_FLOAT, icon_pointing_finger_missing)
        else:
            pos_x = (context.region.width / 2)
            bgl.glRasterPos2f(pos_x, pos_y)
            bgl.glDrawPixels(self.ICON_SIZE, self.ICON_SIZE, bgl.GL_RGBA,
                             bgl.GL_FLOAT, icon_pointing_finger)

        bgl.glPopClientAttrib()

        pass
    def draw_highlight(self, leap_modal, context):
        #print("Callback draw")

        if (s_registration_active_space != None):
            if (not (s_registration_active_space.as_pointer()
                     == context.area.spaces.active.as_pointer())):
                #print("Skipping...")
                return

        #glDrawPixels(width, height, format, type, pixels)
        #Write a block of pixels to the frame buffer
        #
        #height (width,) – Specify the dimensions of the pixel rectangle to be written into the frame buffer.
        #format (Enumerated constant) – Specifies the format of the pixel data.
        #type (Enumerated constant) – Specifies the data type for pixels.
        #pixels (bgl.Buffer object) – Specifies a pointer to the pixel data.

        # transparence
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        ICON_SIZE = 64
        GRID_SIZE = 3
        BORDER_SIZE = 5

        # The number of the cell to highlight has been passed (as string) in the userData from the Keymaps
        if (leap_modal.userData == ""
            ):  # in case we didn't call this, just jump out
            #print("No Userdata, skipping")
            return

        highlight_cell_num = int(leap_modal.userData)

        # Cycle to draw all the cells
        cell_num = 0
        pos_y = context.region.height - ICON_SIZE - BORDER_SIZE
        for buffers_line in self.buffers:
            #pos_x = (context.region.width - (ICON_SIZE * GRID_SIZE) - (BORDER_SIZE * (GRID_SIZE-1)) ) / 2
            pos_x = context.region.width - (
                (ICON_SIZE + BORDER_SIZE) * GRID_SIZE)

            for buf in buffers_line:
                #print("Drawing icon for pos "+ str(cell_num))
                bgl.glRasterPos2f(pos_x, pos_y)
                #bgl.glDrawPixels(ICON_SIZE, ICON_SIZE, bgl.GL_RGBA, bgl.GL_FLOAT, buf)

                # eventually, draw the highlight contour for the selected operation
                if (cell_num == highlight_cell_num):
                    bgl.glDrawPixels(ICON_SIZE, ICON_SIZE, bgl.GL_RGBA,
                                     bgl.GL_FLOAT, self.highlight_buf)

                cell_num += 1
                pos_x += ICON_SIZE + BORDER_SIZE

            pos_y -= ICON_SIZE + BORDER_SIZE

        #
        # Draw the usage hint icons
        #pos_x = (context.region.width - ICON_SIZE ) / 2
        pos_x = context.region.width - (
            (ICON_SIZE + BORDER_SIZE) * (GRID_SIZE - 1))  #- (ICON_SIZE/2)
        pos_y = context.region.height - (ICON_SIZE + BORDER_SIZE) * (
            GRID_SIZE + 2)  #- (BORDER_SIZE*2)
        bgl.glRasterPos2f(pos_x, pos_y)

        if (leap_modal.translationUseFinger or leap_modal.rotationUseFinger
                or leap_modal.isElbowSwivelRotating):
            bgl.glDrawPixels(ICON_SIZE, ICON_SIZE, bgl.GL_RGBA, bgl.GL_FLOAT,
                             self.one_finger_buf)
        else:
            bgl.glDrawPixels(ICON_SIZE, ICON_SIZE, bgl.GL_RGBA, bgl.GL_FLOAT,
                             self.five_fingers_buf)

        if (leap_modal.isTranslating):
            bgl.glDrawPixels(ICON_SIZE, ICON_SIZE, bgl.GL_RGBA, bgl.GL_FLOAT,
                             self.translate_arrows_buf)

        if (leap_modal.isRotating or leap_modal.isElbowSwivelRotating):
            bgl.glDrawPixels(ICON_SIZE, ICON_SIZE, bgl.GL_RGBA, bgl.GL_FLOAT,
                             self.rotate_arrows_buf)

        pass
    def drawIcons(self):
        global s_registration_active_space

        #print("Callback drawIcons")

        context = bpy.context

        #print("Drawing Icons in active space "+str(context.area.spaces.active.as_pointer()))
        if (s_registration_active_space != None):
            if (not (s_registration_active_space.as_pointer()
                     == context.area.spaces.active.as_pointer())):
                #print("Skipping...")
                return

        #print("Drawing icons on context " + str(context) + "\tarea is " + str(context.area) + "(" + context.area.type +")")

        #glDrawPixels(width, height, format, type, pixels)
        #Write a block of pixels to the frame buffer
        #
        #height (width,) – Specify the dimensions of the pixel rectangle to be written into the frame buffer.
        #format (Enumerated constant) – Specifies the format of the pixel data.
        #type (Enumerated constant) – Specifies the data type for pixels.
        #pixels (bgl.Buffer object) – Specifies a pointer to the pixel data.

        bgl.glPushClientAttrib(bgl.GL_CURRENT_BIT | bgl.GL_ENABLE_BIT)

        # transparence
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        ICON_SIZE = 64
        GRID_SIZE = 3
        BORDER_SIZE = 5

        blf.size(0, self.FONT_SIZE, 72)
        #bgl.glColor4f(*self.FONT_RGBA)
        blf.blur(0, 1)

        #bgl.glScalef(0.5,0.5,0.5)

        # Cycle to draw all the cells
        cell_num = 0
        pos_y = context.region.height - ICON_SIZE - BORDER_SIZE
        for buffers_line in self.buffers:
            #pos_x = (context.region.width - (ICON_SIZE * GRID_SIZE) - (BORDER_SIZE * (GRID_SIZE-1)) ) / 2
            pos_x = context.region.width - (
                (ICON_SIZE + BORDER_SIZE) * GRID_SIZE)

            for buf in buffers_line:
                #print("Drawing icon for pos "+ str(cell_num))
                bgl.glRasterPos2f(pos_x, pos_y)
                bgl.glDrawPixels(ICON_SIZE, ICON_SIZE, bgl.GL_RGBA,
                                 bgl.GL_FLOAT, buf)

                # Print the char
                blf.position(0, pos_x, pos_y, 0)
                #bgl.glPushClientAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS) #CURRENT_BIT|bgl.GL_ENABLE_BIT)
                bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)
                blf.size(0, self.FONT_SIZE, 72)
                #blf.blur(0, 10)
                #blf.shadow(0, 3, 0.5, 0.5, 0.5, 0.2)
                #blf.shadow_offset(0, int(self.FONT_SIZE/10), int(self.FONT_SIZE/10))
                bgl.glColor4f(*self.FONT_RGBA)
                blf.draw(0, self.shortcut_keys[cell_num])
                bgl.glPopAttrib()
                #bgl.glPopClientAttrib()

                pos_x += ICON_SIZE + BORDER_SIZE
                cell_num += 1

            pos_y -= ICON_SIZE + BORDER_SIZE

        bgl.glPopClientAttrib()

        pass