[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2301] contrib/py/scripts/addons/ io_import_lipSync_Importer.py: -major refactor to simplify things
yousef harfoush
bat3a at msn.com
Sun Sep 4 18:37:52 CEST 2011
Revision: 2301
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2301
Author: bat3a
Date: 2011-09-04 16:37:51 +0000 (Sun, 04 Sep 2011)
Log Message:
-----------
-major refactor to simplify things
-add retarget WIP
Modified Paths:
--------------
contrib/py/scripts/addons/io_import_lipSync_Importer.py
Modified: contrib/py/scripts/addons/io_import_lipSync_Importer.py
===================================================================
--- contrib/py/scripts/addons/io_import_lipSync_Importer.py 2011-09-04 11:59:59 UTC (rev 2300)
+++ contrib/py/scripts/addons/io_import_lipSync_Importer.py 2011-09-04 16:37:51 UTC (rev 2301)
@@ -19,11 +19,11 @@
bl_info = {
"name": "LipSync Importer & Blinker",
"author": "Yousef Harfoush - bat3a ;)",
- "version": (0, 3, 1),
+ "version": (0, 4, 0),
"blender": (2, 5, 9),
- "api": 39800,
+ "api": 39900,
"location": "3D window > Tool Shelf",
- "description": "Plot Papagayo's (or Jlipsync or Yolo) Moho file to frames and adds automatic blinking",
+ "description": "Plot Moho (Papagayo, Jlipsync, Yolo) file to frames and adds automatic blinking",
"warning": "",
"wiki_url": "http://wiki.blender.org/index.php?title=Extensions:2.5/Py/Scripts/Import-Export/Lipsync_Importer",
"tracker_url": "http://projects.blender.org/tracker/index.php?func=detail&aid=24080&group_id=153&atid=468",
@@ -31,8 +31,9 @@
import bpy, re
+from random import random
from bpy.props import *
-from random import random
+from bpy.props import IntProperty, FloatProperty, StringProperty
global phnmlst
phnmlst="nothing"
@@ -74,42 +75,32 @@
crtkey(blinkphnm, blinkfrm)
-# checking what shape keys available to phonemes vars.
-def mapper():
-
+# reading imported file & creating keys
+def lipsyncer():
+
obj = bpy.context.object
+ scn = bpy.context.scene
+
+ f=open(scn.fpath) # importing file
+ f.readline() # reading the 1st line that we don"t need
+
+ for line in f:
- global AI, O, E, U, etc, L, WQ, MBP, FV, rest
- global AIphnm, Ophnm, Ephnm, Uphnm, etcphnm, Lphnm
- global WQphnm, MBPphnm, FVphnm, restphnm
+ # removing new lines
+ lsta = re.split("\n+", line)
- AI="off"; O="off"; E="off"; U="off"; etc="off"; L="off"
- WQ="off"; MBP="off"; FV="off"; rest="off"
-
- sk=len(obj.data.shape_keys.key_blocks)
-
- for x in range(sk):
-
- obj.active_shape_key_index = x
- oask=obj.active_shape_key.name
+ # building a list of frames & shapes indexes
+ lst = re.split(":? ", lsta[0])# making a list of a frame number &
+ frm = int(lst[0])
- if oask=="AI" or oask=="A" or oask=="I": AI="on"; AIphnm=x
- elif oask=="O": O="on"; Ophnm=x
- elif oask=="E": E="on"; Ephnm=x
- elif oask=="U": U="on"; Uphnm=x
- elif oask=="etc" or oask=="C" or oask=="D" or oask=="G" or oask=="K" or oask=="N" or oask=="R" or oask=="S" or oask=="TH" or oask=="SH": etc="on"; etcphnm=x
- elif oask=="L": L="on"; Lphnm=x
- elif oask=="WQ" or oask=="W" or oask=="Q": WQ="on"; WQphnm=x
- elif oask=="MBP" or oask=="M" or oask=="P" or oask=="B": MBP="on"; MBPphnm=x
- elif oask=="FV" or oask=="F" or oask=="V": FV="on"; FVphnm=x
- elif oask=="rest" or oask=="closed": rest="on"; restphnm=x
+ sk=len(obj.data.shape_keys.key_blocks)
+ for x in range(sk):
+ obj.active_shape_key_index = x
+ oask=obj.active_shape_key.name
+ if lst[1]==oask: crtkey(x, frm)
- # calling file splitter
- splitter()
-
-
-# reading imported file & creating keys
-def splitter():
+# retargetting?? ------WIP
+def retargeter():
scn = bpy.context.scene
@@ -117,26 +108,20 @@
f.readline() # reading the 1st line that we don"t need
for line in f:
-
# removing new lines
lsta = re.split("\n+", line)
-
+
# building a list of frames & shapes indexes
lst = re.split(":? ", lsta[0])# making a list of a frame number &
frm = int(lst[0])
- # create keys based on if key is in the line or not
- if (lst[1]=="AI" or lst[1]=="A" or lst[1]=="I") and AI=="on": crtkey(AIphnm, frm)
- elif lst[1]=="O" and O=="on": crtkey(Ophnm, frm)
- elif lst[1]=="E" and E=="on": crtkey(Ephnm, frm)
- elif lst[1]=="U" and U=="on": crtkey(Uphnm, frm)
- elif (lst[1]=="etc" or lst[1]=="C" or lst[1]=="D" or lst[1]=="G" or lst[1]=="K" or lst[1]=="N" or lst[1]=="R" or lst[1]=="S" or lst[1]=="TH" or lst[1]=="SH") and etc=="on": crtkey(etcphnm, frm)
- elif lst[1]=="L" and L=="on": crtkey(Lphnm, frm)
- elif (lst[1]=="WQ" or lst[1]=="W" or lst[1]=="Q") and WQ=="on": crtkey(WQphnm, frm)
- elif (lst[1]=="MBP" or lst[1]=="M" or lst[1]=="P" or lst[1]=="B") and MBP=="on": crtkey(MBPphnm, frm)
- elif (lst[1]=="FV" or lst[1]=="F" or lst[1]=="V") and FV=="on": crtkey(FVphnm, frm)
- elif (lst[1]=="rest" or lst[1]=="closed") and rest=="on": crtkey(restphnm, frm)
-
+ sk=len(obj.data.shape_keys.key_blocks)
+
+ for x in range(sk):
+ obj.active_shape_key_index = x
+ oask=obj.active_shape_key.name
+ if lst[1]==oask: crtkey(x, frm)
+
# creating keys with offset and eases for a phonem @ the Skframe
def crtkey(phoneme, Skframe):
@@ -159,7 +144,7 @@
hldIn = scn.holdGap # holding time value
#in case of Jlipsync format or Yolo
- elif scn.remnuTypes.enumFiles == '1' or scn.remnuTypes.enumFiles == '2':
+ elif scn.remnuTypes.enumFiles == '1' :
frmIn = 1
frmOut = 1
hldIn = 0
@@ -170,7 +155,6 @@
objSK.key_blocks[phoneme].keyframe_insert("value",
-1, offst+Skframe-frmIn, "Lipsync")
-
obj.active_shape_key.value=skVlu
objSK.key_blocks[phoneme].keyframe_insert("value",
-1, offst+Skframe, "Lipsync")
@@ -186,7 +170,7 @@
phnmlst=phoneme
# lipsyncer operation start
-class Lipsyncer(bpy.types.Operator):
+class btn_lipsyncer(bpy.types.Operator):
bl_idname = 'lipsync.go'
bl_label = 'Start Processing'
bl_description = 'Plots the voice file keys to timeline'
@@ -199,14 +183,14 @@
# testing if a mesh object with shape keys is selected
if obj!=None and obj.type=="MESH":
if obj.data.shape_keys!=None:
- if scn.fpath!='': mapper()
+ if scn.fpath!='': lipsyncer()
else: print ("select a Moho file")
else: print("add shape keys PLEASE")
else: print ("Object is not mesh or not selected ")
return {'FINISHED'}
# blinker operation start
-class Blinker_go(bpy.types.Operator):
+class btn_blinker(bpy.types.Operator):
bl_idname = 'blink.go'
bl_label = 'Start Processing'
bl_description = 'Adds random or specifice blinks'
@@ -218,8 +202,51 @@
# testing if a mesh object with blink shape keys is selected
if obj!=None and obj.type=="MESH":
+ if obj.data.shape_keys!=None: blinker()
+ else: print("add shape keys PLEASE")
+ else: print ("Object is not mesh or not selected ")
+ return {'FINISHED'}
+
+# retargetting operation start
+class btn_retarget(bpy.types.Operator):
+ bl_idname = 'retarget.go'
+ bl_label = 'Start Processing'
+ bl_description = 'Refresh Shape Keys List'
+
+ def execute(self, context):
+
+ obj = context.object
+
+ # testing if a mesh object with blink shape keys is selected
+ if obj!=None and obj.type=="MESH":
+ if obj.data.shape_keys!=None: retargeter()
+ else: print("add shape keys PLEASE")
+ else: print ("Object is not mesh or not selected ")
+ return {'FINISHED'}
+
+# getting props from current shape keys
+class btn_refresh(bpy.types.Operator):
+ bl_idname = 'refresh.go'
+ bl_label = 'Start Processing'
+ bl_description = 'Refresh Shape Keys List'
+
+ def execute(self, context):
+
+ scn = context.scene
+ obj = context.object
+
+ # testing if a mesh object with blink shape keys is selected
+ if obj!=None and obj.type=="MESH":
if obj.data.shape_keys!=None:
- blinker()
+
+ obj = bpy.context.object
+ typ = bpy.types.Scene
+ sk = len(obj.data.shape_keys.key_blocks)
+
+ for x in range(sk):
+ obj.active_shape_key_index=x
+ exec("typ.sk"+str(x)+"=StringProperty(name="+"obj.active_shape_key.name"+")")
+
else: print("add shape keys PLEASE")
else: print ("Object is not mesh or not selected ")
return {'FINISHED'}
@@ -228,8 +255,9 @@
class mnuTypes(bpy.types.PropertyGroup):
enumFiles = EnumProperty( items =( ('0', 'Papagayo', ''),
- ('1', 'Jlipsync', ''),
- ('2', 'Yolo','')),
+ ('1', 'Jlipsync Or Yolo', '')
+ #,('2', 'Retarget', '')
+ ),
name = 'test',
default = '0' )
@@ -237,7 +265,7 @@
('1', 'Random','')),
name = 'test',
default = '0' )
-
+
# drawing the user interface
class LipSyncUI(bpy.types.Panel):
bl_space_type = "VIEW_3D"
@@ -246,24 +274,24 @@
typ = bpy.types.Scene
scn = bpy.context.scene
- var = bpy.props
- typ.mnuFunc = var.EnumProperty(name="Select Mode ", description="Select function",
+ typ.mnuFunc = EnumProperty(name="Select Mode ", description="Select function",
items=(('0', 'Lipsyncer', ''), ('1', 'Blinker', '')), default='0')
- typ.fpath = var.StringProperty(name="Import File ", description="Select your voice file", subtype="FILE_PATH")
- typ.skscale = var.FloatProperty(description="Smoothing shape key values", min=0.1, max=1.0, default=0.8)
- typ.offset = var.IntProperty(description="Offset your frames", default=0)
+ typ.fpath = StringProperty(name="Import File ", description="Select your voice file", subtype="FILE_PATH")
+ typ.skscale = FloatProperty(description="Smoothing shape key values", min=0.1, max=1.0, default=0.8)
+ typ.offset = IntProperty(description="Offset your frames", default=0)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list