Skip to content

Commit

Permalink
Merge pull request #4 from NickTiny/fix/improve_documentation
Browse files Browse the repository at this point in the history
Fix/improve documentation
  • Loading branch information
NickTiny authored Dec 18, 2022
2 parents 76e83f4 + dfcf796 commit c2e0b32
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 77 deletions.
19 changes: 10 additions & 9 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from . import ops, props, ui, prefs

__version__ = "3.0.2"
"""Forked from https://github.com/scaredyfish/blender-rhubarb-lipsync/"""

__version__ = "1.0.0"

bl_info = {
"name": "Rhubarb Lipsync-DEV",
"author": "Customized by Nick Alberelli, based on: Addon by Andrew Charlton, includes Rhubarb Lip Sync by Daniel S. Wolf",
"version": (3, 0, 2),
"name": "Blender Rhubarb 2D Lipsync",
"author": "By Nick Alberelli, forked from Addon by Andrew Charlton, includes Rhubarb Lip Sync by Daniel S. Wolf",
"version": (1, 0, 0),
"blender": (3, 0, 0),
"location": "VIEW3D > Sidebar > AI Lipsync",
"description": "Integrate Rhubarb Lipsync into Tiny Media Blender Workflow",
"wiki_url": "https://github.com/adcharlton/blender-rhubarb-lipsync",
"tracker_url": "https://github.com/adcharlton/blender-rhubarb-lipsync/issues",
"location": "VIEW3D > Sidebar > Rhubarb 2D Lipsync",
"description": "Integrate Rhubarb Lipsync into Blender",
"wiki_url": "https://github.com/NickTiny/blender-rhubarb-2d-lipsync",
"tracker_url": "https://github.com/NickTiny/blender-rhubarb-2d-lipsync/issues",
"support": "COMMUNITY",
"category": "Animation",
"warning": "This addon is in development and NOT ready to for production.",
}


Expand Down
115 changes: 67 additions & 48 deletions core.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,23 @@
from types import NoneType
import bpy
from bpy_extras.io_utils import ImportHelper
import bpy, mathutils

mouth_shapes = (
"mouth_a",
"mouth_b",
"mouth_c",
"mouth_d",
"mouth_e",
"mouth_f",
"mouth_g",
"mouth_h",
"mouth_x",
)

# List to store target's avaliable props
# List to store avaliable target properties
prop_list = []


def initlize_props(rig_settings):
"""Integer Properties must be initilized if they are not already set to a value
NOTE: Default value on prop doesn't return as integer until user resets integer to default."""
# if a single setting is set do not initilie props
initilized = True
for index, mouth in enumerate(mouth_shapes):
if not rig_settings.get(mouth):
initilized = False
if initilized:
return

for index, mouth in enumerate(mouth_shapes):
if not rig_settings.get(mouth):
rig_settings[mouth] = index


def debugger(msg):
print(f"Blender Rhubarb Lip Sync: {msg}")
def find_target_and_refresh_properties(context):
"""Returns target's object and updates list
of avaliable target properties from the target
to populate target property list"""
prop_list.clear()
target, object = get_target(context)
if target:
get_target_properties(context.window_manager.rhubarb_panel_settings, target)
return object


def get_target(context):
"""Returns target item, based on user selected obj_mode."""
sc = context.scene
obj = context.active_object
rhubarb = context.window_manager.rhubarb_panel_settings
Expand All @@ -53,23 +31,64 @@ def get_target(context):
return target, obj


def refresh_target(context):
prop_list.clear()
target, object = get_target(context)
if target:
update_list(context.window_manager.rhubarb_panel_settings, target)
return object


def update_list(rhubarb_settings, target):
def get_target_properties(rhubarb_settings, target):
"""Update items in target props list"""
# Reset list and append avaliable properties
for prop_name, _ in target.items():
# if GPencil find TimeOffset modifier's offset property
if rhubarb_settings.obj_modes != "timeoffset":
if "int" in str(type(target[f"{prop_name}"])) or "float" in str(
type(target[f"{prop_name}"])
):
prop_list.append((prop_name, prop_name, prop_name))
if "int" in str(type(target[f"{prop_name}"])):
prop_list.append(
(
prop_name,
prop_name,
f"Integer '{prop_name}' on object '{target.id_data.name}' ",
)
)
if "float" in str(type(target[f"{prop_name}"])):
prop_list.append(
(
prop_name,
prop_name,
f"Float '{prop_name}' on object '{target.id_data.name}' ",
)
)
else:
# else find INT properties on selected bone
prop_list.append((prop_name, prop_name, prop_name))
prop_list.append(
(
prop_name,
prop_name,
f"Modifier '{prop_name}' on grease pencil object '{target.id_data.name}' ",
)
)


def initilize_mouth_values(rig_settings):
"""Integer Properties must be initilized if they are not already set to a value
NOTE: Default value on prop doesn't return as integer until user resets integer to default."""
# if a single setting is set do not initilie props
mouth_shapes = (
"mouth_a",
"mouth_b",
"mouth_c",
"mouth_d",
"mouth_e",
"mouth_f",
"mouth_g",
"mouth_h",
"mouth_x",
)
initilized = True
for index, mouth in enumerate(mouth_shapes):
if not rig_settings.get(mouth):
initilized = False
if initilized:
return

for index, mouth in enumerate(mouth_shapes):
if not rig_settings.get(mouth):
rig_settings[mouth] = index


def debugger(msg):
print(f"Blender Rhubarb Lip Sync: {msg}")
13 changes: 1 addition & 12 deletions ops.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
from distutils.util import execute
import enum
import bpy
from bpy import types
from bpy.props import IntProperty, FloatProperty
import blf
import bgl
import io
import sys
import select
import subprocess
from threading import Thread, local
from queue import Queue, Empty
import json
import os
from .core import get_target, debugger


class RHUBARB_OT_Execute_Rhubarb_Lipsync(bpy.types.Operator):
"""Run Rhubarb lipsync"""
"""Run Rhubarb 2D Lipsync"""

bl_idname = "rhubarb.execute_rhubarb_lipsync"
bl_label = "Rhubarb lipsync"
Expand Down
9 changes: 5 additions & 4 deletions props.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
# Generate list of items from target's props
def enum_items_generator(self, context):
enum_items = []
for e, d in enumerate(prop_list):
enum_items.append((d[0], d[0], d[0], e))
for index, prop in enumerate(prop_list):
# Enum items order(key, name, description, position)
enum_items.append((prop[0], prop[0], prop[2], index))
return enum_items


def mode_options_generator(self, context):
obj_enum = (
"obj",
"Object",
"Keyframe integer or float property on any object's data",
"Keyframe a custom integer or float property on the active object's data",
"OBJECT_DATA",
1,
)
bone_enum = (
"bone",
"Bone",
"Keyframe integer or float property on any bone in Pose Mode",
"Keyframe a custom integer or float property on the active pose bone in Pose Mode",
"BONE_DATA",
2,
)
Expand Down
8 changes: 4 additions & 4 deletions ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bpy

from .core import refresh_target, initlize_props
from .core import find_target_and_refresh_properties, initilize_mouth_values


class RHUBARB_PT_Main_Panel(bpy.types.Panel):
Expand All @@ -10,7 +10,7 @@ class RHUBARB_PT_Main_Panel(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Rhubarb Lipsync"
bl_label = "Rhubarb Lipsync"
bl_label = "Rhubarb 2D Lipsync"

# Pointer definitions
bpy.types.Scene.obj_selection = bpy.props.PointerProperty(type=bpy.types.Object)
Expand All @@ -24,7 +24,7 @@ def draw(self, context):
mode_row = target_col.row(align=True)
mode_row.prop(rhubarb, "obj_modes", text="Target Type", toggle=True)

obj = refresh_target(context)
obj = find_target_and_refresh_properties(context)
if not obj:
return

Expand All @@ -42,7 +42,7 @@ def draw(self, context):
)

# User editable Mouth Definitions
initlize_props(rhubarb)
initilize_mouth_values(rhubarb)
prop_col = layout.column()
prop_col.prop(rhubarb, "mouth_b", text="Mouth B (EE/etc)")
prop_col.prop(rhubarb, "mouth_c", text="Mouth C (E)")
Expand Down

0 comments on commit c2e0b32

Please sign in to comment.