Skip to content

Added operator for Rhubarb lipsync #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Blender/coa_tools/__pycache__
Blender/coa_tools/operators/__pycache__
Blender/coa_tools/operators/__pycache__
.idea/
79 changes: 79 additions & 0 deletions Blender/coa_tools/operators/rhubarb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import bpy
import math
import random

class RhubarbOperator(bpy.types.Operator):
bl_idname = "action.rhubarb_lipsync"
bl_label = "Rhubarb Lipsync"
bl_options = {'REGISTER', 'UNDO'}

filename = bpy.props.StringProperty(
name="Rhubarb file",
description="File with Lipsync data created by Rhubarb",
subtype='FILE_PATH'
)

startAtCurrentFrame = bpy.props.BoolProperty(
name="Start at current frame",
description="Add keyframes starting at current frame."
)

fps = 24

shapes = {
'A': 0,
'B': 1,
'C': 2,
'D': 3,
'E': 4,
'F': 5,
'G': 6,
'H': 7,
'X': 8,
}

def execute(self, context):
self.fps = bpy.context.scene.render.fps
if self.filename:
data = self.parseRhubarbFile(self.filename)
self.createKeyframes(data)

return {'FINISHED'}

def parseRhubarbFile(self, filename):
data = []

with open(filename) as lines:
for line in lines:
r = line.split()
data.append((round(float(r[0]) * self.fps), self.shapes[r[1]]))

return data

def createKeyframes(self, data):
length = data[len(data)-1][0]

frame_current = bpy.context.scene.frame_current
frame_end = bpy.context.scene.frame_end

f = 0

if self.startAtCurrentFrame and frame_end < frame_current + length + 1:
bpy.context.scene.frame_end = frame_current + length + 1
f = frame_current
elif frame_end < length + 1:
bpy.context.scene.frame_end = length + 1

sprite = bpy.context.scene.objects.active

if sprite:
for key in data:
sprite.coa_sprite_frame = key[1]
sprite.keyframe_insert(data_path='["coa_sprite_frame"]', frame=(f + key[0]+1))


def register():
bpy.utils.register_class(RhubarbOperator)

if __name__ == "__main__":
register()
4 changes: 3 additions & 1 deletion Blender/coa_tools/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ def draw(self, context):
if sprite_object.coa_edit_mesh == False and sprite_object.coa_edit_armature == False and sprite_object.coa_edit_weights == False and not(obj.type == "MESH" and obj.mode=="EDIT") and (sprite_object) != None:
row = layout.row(align=True)
row.operator("object.coa_edit_weights",text="Edit Weights",icon="MOD_VERTEX_WEIGHT")
row = layout.row(align=True)
row.operator("action.rhubarb_lipsync", text="Lipsync", icon="CLIP")
elif sprite_object.coa_edit_weights:
row = layout.row(align=True)
row.prop(sprite_object,"coa_edit_weights", text="Finish Edit Weights", toggle=True, icon="MOD_VERTEX_WEIGHT")
Expand All @@ -570,7 +572,7 @@ def draw(self, context):
row.prop(tool_settings.unified_paint_settings,"use_pressure_strength",text="")
row = col.row(align=True)
row.prop(tool_settings,"use_auto_normalize",text="Auto Normalize")

if context.active_object != None and "coa_sprite" in obj and context.active_object.mode == "EDIT" and context.active_object.type == "MESH" and sprite_object.coa_edit_mesh:
row = layout.row(align=True)
row.label(text="Mesh Tools:")
Expand Down
Binary file added Sample Files/ken-mouth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.