1

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!

lhgergo
  • 11
  • 1
  • 2

2 Answers2

3

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

Blender For You
  • 1,640
  • 12
  • 23
  • Good abswer, but please use proper code tags for formatting your answer from the toolbar, otherwise it will display wrongly – Duarte Farrajota Ramos Sep 02 '17 at 11:36
  • 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 – Blender For You Sep 02 '17 at 12:10
  • While editing your post there are buttons in the toolbar on top for this purpose – Duarte Farrajota Ramos Sep 02 '17 at 12:28
  • Great, Thank you very much ! Vote it up as you liked the answer :) – Blender For You Sep 02 '17 at 12:29
  • 4
    @DuarteFarrajotaRamos , yeah gotta agree good answer... Wait a minute it Looks Familiar ... commented about it recently worth an UV lol. – batFINGER Sep 02 '17 at 18:16
  • 1
    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 :( – Duarte Farrajota Ramos Sep 03 '17 at 00:18
  • @batFINGER and DuarteFarrajotaRamos: I am sorry, I don't wanted to cheat, I was not sure about the source, I did not claim its my code,

    Any ways, Credit added for you. If its not good enough yet, please edit it for me to understand the credit in a batter way. I am junior here and would like to learn more about the stackexchange system and ethics under your (you experienced people) kind guide line and help

    Thanks in advance

    If even than its not seems to good, please let me know, I will delete the answer!

    Sorry once again :(

    – Blender For You Sep 03 '17 at 04:08
  • How can I change the code to get rid of milliseconds? I just want minutes and seconds. – Tucker Dec 23 '17 at 23:46
  • @Tucker If you want to get rid of the hundreths of a second just change line 24 from font.body = "%02d:%02d:%02d" % (minutes,seconds,hundreds) to font.body = "%02d:%02d" % (minutes,seconds) – piridium Feb 18 '18 at 15:34
1

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.

icYou520
  • 5,479
  • 4
  • 27
  • 55