[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2245] contrib/py/scripts/addons/ io_import_lipSync_Importer.py: ===Updated to version 0.3===
yousef harfoush
bat3a at msn.com
Mon Aug 15 05:16:18 CEST 2011
Revision: 2245
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2245
Author: bat3a
Date: 2011-08-15 03:16:14 +0000 (Mon, 15 Aug 2011)
Log Message:
-----------
===Updated to version 0.3===
-Updated the UI a bit.
-Added support for Yolo exported Moho file.
-Added random generator for blinks.
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-08-12 06:32:21 UTC (rev 2244)
+++ contrib/py/scripts/addons/io_import_lipSync_Importer.py 2011-08-15 03:16:14 UTC (rev 2245)
@@ -19,11 +19,11 @@
bl_info = {
"name": "LipSync Importer & Blinker",
"author": "Yousef Harfoush - bat3a ;)",
- "version": (0, 2, 6),
- "blender": (2, 5, 6),
- "api": 35816,
+ "version": (0, 3, 0),
+ "blender": (2, 5, 9),
+ "api": 39300,
"location": "3D window > Tool Shelf",
- "description": "Plot Papagayo's (or Jlipsync) voice file to frames and adds automatic blinking",
+ "description": "Plot Papagayo's (or Jlipsync or Yolo) Moho 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",
@@ -32,11 +32,10 @@
import bpy, re
from bpy.props import *
+from random import random
-mnulast = '1'
-
global phnmlst
-phnmlst="rest"
+phnmlst="nothing"
# truning off relative path - it causes an error if it was true
if bpy.context.user_preferences.filepaths.use_relative_paths == True:
@@ -51,21 +50,31 @@
global blink, blinkphnm
blink="off"
- blinkphnm=1983
+ blinkphnm=-1
sk=len(obj.data.shape_keys.key_blocks)
+ # searching for blink shapekey index
for x in range(sk):
obj.active_shape_key_index = x
if obj.active_shape_key.name=="blink": blink="on"; blinkphnm=x
- for y in range(scn['blinkNm']):
+ if blinkphnm!=-1:
+
+ if scn.remnuTypes['enumBlinks'] == 0:
+ modifier = 0
+ elif scn.remnuTypes['enumBlinks'] == 1:
+ modifier = scn['blinkMod']
+
+ #creating keys with blinkNm count
+ for y in range(scn['blinkNm']):
+
+ blinkfrm = y * scn['blinkSp'] + int(random()*modifier)
+
+ crtkey(blinkphnm, blinkfrm)
- blinkSpm=scn["blinkSp"]*y
- if blinkphnm!=1983: crtkey(blinkphnm, blinkSpm)
-
-# mapping shape keys to phonemes vars.
+# checking what shape keys available to phonemes vars.
def mapper():
obj = bpy.context.object
@@ -82,18 +91,19 @@
for x in range(sk):
obj.active_shape_key_index = x
+ oask=obj.active_shape_key.name
+
+ 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
- if obj.active_shape_key.name=="AI": AI="on"; AIphnm=x
- elif obj.active_shape_key.name=="O": O="on"; Ophnm=x
- elif obj.active_shape_key.name=="E": E="on"; Ephnm=x
- elif obj.active_shape_key.name=="U": U="on"; Uphnm=x
- elif obj.active_shape_key.name=="etc": etc="on"; etcphnm=x
- elif obj.active_shape_key.name=="L": L="on"; Lphnm=x
- elif obj.active_shape_key.name=="WQ": WQ="on"; WQphnm=x
- elif obj.active_shape_key.name=="MBP": MBP="on"; MBPphnm=x
- elif obj.active_shape_key.name=="FV": FV="on"; FVphnm=x
- elif obj.active_shape_key.name=="rest": rest="on"; restphnm=x
-
# calling file splitter
splitter()
@@ -105,7 +115,7 @@
f=open(scn.fpath) # importing file
f.readline() # reading the 1st line that we don"t need
- print("hhhh")
+
for line in f:
# removing new lines
@@ -114,86 +124,68 @@
# building a list of frames & shapes indexes
lst = re.split(":? ", lsta[0])# making a list of a frame number &
frm = int(lst[0])
-
- # passing to create keys
- if lst[1]==("AI" or "A" or "I")and AI=="on": crtkey(AIphnm, frm)
+
+ # 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 "C" or "D" or "G" or "K" or "N" or "R" or "S" or "TH" or "SH") and etc=="on": crtkey(etcphnm, 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 "W" or "Q") and WQ=="on": crtkey(WQphnm, frm)
- elif lst[1]==("MBP" or "M" or "P" or "B") and MBP=="on": crtkey(MBPphnm, frm)
- elif lst[1]==("FV" or "F" or "V") and FV=="on": crtkey(FVphnm, frm)
- elif lst[1]==("rest" or "closed") and rest=="on": crtkey(restphnm, 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)
-# creating keys with offset and eases
-def crtkey(phoneme, Skey):
+# creating keys with offset and eases for a phonem @ the Skframe
+def crtkey(phoneme, Skframe):
global phnmlst
scn = bpy.context.scene
obj = bpy.context.object
-
objSK=obj.data.shape_keys
+
+ #setting the active shape key to phonem
obj.active_shape_key_index=phoneme
- offst=scn['offset'] # offset value
- skVlu=scn['skscale'] # shape key value
- frmIn=scn['easeIn'] # ease in value
- frmOut=scn['easeOut'] # ease out value
- hldIn=scn['holdGap'] # holding time value
+ offst = scn['offset'] # offset value
+ skVlu = scn['skscale'] # shape key value
+
+ #in case of Papagayo format
+ if scn.remnuTypes['enumFiles'] == 0 :
+ frmIn = scn['easeIn'] # ease in value
+ frmOut = scn['easeOut'] # ease out value
+ hldIn = scn['holdGap'] # holding time value
+
+ #in case of Jlipsync format or Yolo
+ elif scn.remnuTypes['enumFiles'] == 1 or scn.remnuTypes['enumFiles'] == 2:
+ frmIn = 1
+ frmOut = 1
+ hldIn = 0
- if bpy.context.scene['jlip'] == 1:
-
- if phnmlst!=phoneme:
- obj.active_shape_key.value=0.0
- objSK.key_blocks[phoneme].keyframe_insert("value",
- -1, offst+Skey-1, "Lipsync")
-
- obj.active_shape_key.value=skVlu
- objSK.key_blocks[phoneme].keyframe_insert("value",
- -1, offst+Skey, "Lipsync")
-
+ # inserting the In key only when phonem change or when blinking
+ if phnmlst!=phoneme or eval(scn.mnuFunc) == 1:
obj.active_shape_key.value=0.0
- objSK.key_blocks[phoneme].keyframe_insert("value",
- -1, offst+Skey+1, "Lipsync")
-
- phnmlst=phoneme
-
- elif bpy.context.scene['jlip'] != 1:
-
- obj.active_shape_key.value=0.0
objSK.key_blocks[phoneme].keyframe_insert("value",
- -1, offst+Skey-frmIn, "Lipsync")
+ -1, offst+Skframe-frmIn, "Lipsync")
+
- obj.active_shape_key.value=skVlu
- objSK.key_blocks[phoneme].keyframe_insert("value",
- -1, offst+Skey, "Lipsync")
-
- obj.active_shape_key.value=skVlu
- objSK.key_blocks[phoneme].keyframe_insert("value",
- -1, offst+Skey+hldIn, "Lipsync")
-
- obj.active_shape_key.value=0.0
- objSK.key_blocks[phoneme].keyframe_insert("value",
- -1, offst+Skey+hldIn+frmOut, "Lipsync")
-
-# clearing vars
-def clear_properties():
-
- # can happen on reload
- if bpy.context.scene is None:
- return
-
- props = ["offset", "skscale", "easeIn", "easeOut", "blinkSp", "blinkNm", "holdGap", "jlip"]
- for p in props:
- if p in bpy.types.Scene.bl_rna.properties:
- exec("del bpy.types.Scene."+p)
- if p in bpy.context.scene:
- del bpy.context.scene[p]
-
-# creating ui button to run things
+ obj.active_shape_key.value=skVlu
+ objSK.key_blocks[phoneme].keyframe_insert("value",
+ -1, offst+Skframe, "Lipsync")
+
+ obj.active_shape_key.value=skVlu
+ objSK.key_blocks[phoneme].keyframe_insert("value",
+ -1, offst+Skframe+hldIn, "Lipsync")
+
+ obj.active_shape_key.value=0.0
+ objSK.key_blocks[phoneme].keyframe_insert("value",
+ -1, offst+Skframe+hldIn+frmOut, "Lipsync")
+
+ phnmlst=phoneme
+
+# lipsyncer operation start
class Lipsyncer(bpy.types.Operator):
bl_idname = 'lipsync.go'
bl_label = 'Start Processing'
@@ -208,15 +200,16 @@
if obj!=None and obj.type=="MESH":
if obj.data.shape_keys!=None:
if scn.fpath!='': mapper()
- else: print ("select a voice file")
+ 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):
bl_idname = 'blink.go'
bl_label = 'Start Processing'
- bl_description = 'Adds Random or Specifice blinks'
+ bl_description = 'Adds random or specifice blinks'
def execute(self, context):
@@ -231,21 +224,20 @@
else: print ("Object is not mesh or not selected ")
return {'FINISHED'}
-class mnuSelect(bpy.types.Operator):
- bl_idname = 'view.operator'
- bl_label = 'Operator'
-
- # define possible operations
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list