Skip to content

Commit

Permalink
Merge pull request #1 from gandalf3/master
Browse files Browse the repository at this point in the history
 Fix animation render with keyframed typewriter properties
  • Loading branch information
doakey3 authored Jul 5, 2020
2 parents 875c0cb + 4249157 commit 1c92961
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
29 changes: 16 additions & 13 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def randomize(t,width):
return(nt)


def uptext(text):
def uptext(text, eval_text):
'''
slice the source text up to the character_count
'''
Expand All @@ -68,29 +68,32 @@ def uptext(text):
t = source

#randomize
if text.use_randomize and len(t) > text.character_count:
t = randomize(t[:text.character_count], text.randomize_width)
if eval_text.use_randomize and len(t) > eval_text.character_count:
t = randomize(t[:eval_text.character_count], eval_text.randomize_width)

prefix = ''
if text.preserve_newline and text.character_start > 0:
prefix = '\n' * t.count('\n', 0, text.character_start)
if text.preserve_space and text.character_start > 0:
prefix += ' ' * (text.character_start - (t.rfind('\n', 0, text.character_start) + 1))
if eval_text.preserve_newline and eval_text.character_start > 0:
prefix = '\n' * t.count('\n', 0, eval_text.character_start)
if eval_text.preserve_space and eval_text.character_start > 0:
prefix += ' ' * (eval_text.character_start - (t.rfind('\n', 0, eval_text.character_start) + 1))

new_text = prefix + t[text.character_start:text.character_count]
count = text.character_count
new_text = prefix + t[eval_text.character_start:eval_text.character_count]
count = eval_text.character_count

text.body = new_text


@persistent
def typewriter_text_update_frame(scene):
def typewriter_text_update_frame(scene, depsgraph):
'''
sadly we need this for frame change updating
'''

for text in scene.objects:
if text.type == 'FONT' and text.data.use_animated_text:
uptext(text.data)
eval_text = text.evaluated_get(depsgraph)
uptext(text.data, eval_text.data)


def update_func(self, context):
'''
Expand Down Expand Up @@ -207,15 +210,15 @@ def register():
register_class(cls)

# add the frame change handler
bpy.app.handlers.frame_change_pre.append(typewriter_text_update_frame)
bpy.app.handlers.frame_change_post.append(typewriter_text_update_frame)


def unregister():
'''
addon unregistration function
'''
# remove the frame change handler
bpy.app.handlers.frame_change_pre.remove(typewriter_text_update_frame)
bpy.app.handlers.frame_change_post.remove(typewriter_text_update_frame)

# remove the panel
from bpy.utils import unregister_class
Expand Down

0 comments on commit 1c92961

Please sign in to comment.