1
$\begingroup$

I'd like to create a countdown timer, something like this, using cycles: 1]

I have found a pretty straightforward video about the problem (https://www.youtube.com/watch?v=5fClNkcP0KA), and it works just fine, but couldn't solve the problem of viewing the output of the script in the cycles renderer. I'd like to create a video of it, so probably I should somehow provide a framerate for the script as well, but don't have any idea how to start. Thanks!

$\endgroup$
  • $\begingroup$ BGE != cycles. Scripts for one will not work in the other. $\endgroup$ – sdfgeoff Sep 2 '17 at 9:17
  • $\begingroup$ I was afraid to hear as well. Then is there any way to solve this for cycles? $\endgroup$ – lhgergo Sep 2 '17 at 9:21
3
$\begingroup$

Please have a try with this script By Respected fellow: batFINGER:

import bpy
import math
from bpy.props import BoolProperty
def countdown_timer(scene):
    # look for all font objects with _timer property
    timers = [ob.data for ob in scene.objects if ob.type == 'FONT' and ob.data.is_timer]
    for font in timers:
        secs = font["timer"]
        countdown_frames = secs * scene.render.fps / scene.render.fps_base
        frame = countdown_frames - scene.frame_current + 1 
        if frame < 0:
            continue
        t = float(frame * scene.render.fps_base ) / float(scene.render.fps)
        minutes = t // 60
        t %= 60
        seconds = math.floor(t)
        t = t - seconds
        hundreds = math.floor(100 * (t))
        font.body = "%02d:%02d:%02d" % (minutes,seconds,hundreds)
    return None
def is_timer(self, context):
    if self.is_timer:
        if "timer" not in self.keys():
            self["timer"] = 10 # 10 seconds default
    return None
class TimerPanel(bpy.types.Panel):
    """Timer Panel"""
    bl_label = "Countdown Timer"
    bl_idname = "FONT_PT_timer"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "data"

    @classmethod
    def poll(cls, context):
        return (context.object and context.object.type in {'FONT'} and context.curve)
    def draw_header(self, context):
        font = context.object.data

        self.layout.prop(font, "is_timer", text="")
    def draw(self, context):
        font = context.object.data
        layout = self.layout
        if font.is_timer:
            row = layout.row()
            row.prop(font,'["timer"]', text="Seconds")
def register():
    bpy.types.TextCurve.is_timer = BoolProperty(default=False, update=is_timer, description="Make countdown timer")

    bpy.app.handlers.frame_change_pre.append(countdown_timer)    
    bpy.utils.register_class(TimerPanel)

def unregister():
    bpy.utils.unregister_class(TimerPanel)
    bpy.app.handlers.frame_change_pre.pop()

if __name__ == "__main__":
    register()

Copy it to the Text Editor enter image description here

Dont forget to hit run script

Create a new text and you will get a new option box under fonts. enter image description here

Adjust the value as per your needs

enter image description here

Play it! It can be used in Cycles or gaming engine !

You will have a full control of materials fonts size and rotations etc

Best of luck

$\endgroup$
  • $\begingroup$ Good abswer, but please use proper code tags for formatting your answer from the toolbar, otherwise it will display wrongly $\endgroup$ – Duarte Farrajota Ramos Sep 2 '17 at 11:36
  • $\begingroup$ Thank you for your guide line, I tried to update it as per code but not looking good, can you please update it for me or guide me for the steps $\endgroup$ – Blender For You Sep 2 '17 at 12:10
  • $\begingroup$ While editing your post there are buttons in the toolbar on top for this purpose $\endgroup$ – Duarte Farrajota Ramos Sep 2 '17 at 12:28
  • 4
    $\begingroup$ @DuarteFarrajotaRamos , yeah gotta agree good answer... Wait a minute it Looks Familiar ... commented about it recently worth an UV lol. $\endgroup$ – batFINGER Sep 2 '17 at 18:16
  • 1
    $\begingroup$ Hey that is cheating! Copy pasting someone else's code without giving credit for your own profit is bad. Too bad one can't retract vote now :( $\endgroup$ – Duarte Farrajota Ramos Sep 3 '17 at 0:18
1
$\begingroup$

Another way to do it is with Animation Nodes.

http://animation-nodes-manual.readthedocs.io/en/latest/user_guide/nodes/animation/animate_float.html

Free Download by Jacques Lucke here

enter image description here

  1. Make Sure Animation Nodes is installed as an addon and enabled.
  2. Set up your nodes as above.
    • Time info node just finds the current frame
    • Animate Float (animates the numbers, you pick any numbers)
    • Round number (converts it to a whole number)
    • Convert to text (Self Explanatory)
    • Text Object (Choose your text in the text object box, make sure the button is highlighted next to text.)

This is all from the well documented manual.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.