1
$\begingroup$

I couldn't find anything that answered my question, so here it goes:

I'm doing a basic draw method that writes something on the viewport, but I want it to fade out. This much I got working. The problem is, unless I'm actually moving the viewport, the text won't update (video).

https://youtu.be/VWcwE7n0yOs

Is there a way to force the viewport to update every time I fade out the text or is this a blender limitation?

Here's my code (just paste it on Blender's text editor and press play)

import blf
import bpy
import time

fade = 1


class DrawMessage:
    def __init__(self, context, text) -> None:
        self.text = text
        self.handle = bpy.types.SpaceView3D.draw_handler_add(
            self.draw_text_callback, (context,), 'WINDOW', 'POST_PIXEL'
        )

    def draw_text_callback(self, context):
        font_id = 0

        # Draw some text:
        blf.position(font_id, 2, 80, 0)
        blf.color(0, 1, 1, 1, fade)
        blf.size(font_id, 50, 72)
        blf.draw(font_id, "{} and {}".format(context.scene.name, self.text))

    def fade_out(self):
        global fade
        fade -= 0.025
        print(fade)
        if fade <= 0:
            bpy.types.SpaceView3D.draw_handler_remove(self.handle, 'WINDOW')
            print("REMOVIDO DEPOIS DO FADE OUT!")
            return None
        return 0.1

    def remove_handle(self):
        bpy.types.SpaceView3D.draw_handler_remove(self.handle, 'WINDOW')
        print("REMOVIDO!")


context = bpy.context
dc = DrawMessage(context, "DRAW THIS ON SCREEN")

timer = bpy.app.timers.register(dc.fade_out, first_interval=3)

Thanks a lot for your time! :)

$\endgroup$
2
  • $\begingroup$ Sounds like this Q: blender.stackexchange.com/questions/28673/… $\endgroup$
    – HISEROD
    Feb 13, 2021 at 3:59
  • $\begingroup$ I've tried using wm.redraw_timer() maybe I've used it wrong. I've already went trough that answer before as well :/ It works for 3d objects. $\endgroup$
    – elamhut
    Feb 13, 2021 at 17:26

0

You must log in to answer this question.

Browse other questions tagged .