Merge pull request #17 from RamesTheGeneric/main

More shapes update
This commit is contained in:
Summer authored and GitHub committed 2023-05-31 11:26:31 -07:00
commit 0ef06f7e51
17 files changed
+156 -3051

No files matched your search

+69 -78
View File
@@ -57,13 +57,16 @@ class Calibration(object):
self.calib = json.load(user_file)
self._last_update = os.fstat(user_file.fileno()).st_mtime
self.jsonminmax = [
[self.calib["cheekPuff"]["min"],self.calib["cheekPuff"]["max"]], # CheekPuff
[self.calib["noseSneerLeft"]["min"],self.calib["noseSneerLeft"]["max"]], # noseSneerLeft
[self.calib["noseSneerRight"]["min"],self.calib["noseSneerRight"]["max"]], # noseSneerRight
[self.calib["cheekPuffLeft"]["min"],self.calib["cheekPuffLeft"]["max"]], # CheekPuff
[self.calib["cheekPuffRight"]["min"],self.calib["cheekPuffRight"]["max"]], # CheekPuff
[self.calib["cheekSuckLeft"]["min"],self.calib["cheekSuckLeft"]["max"]], # CheekPuff
[self.calib["cheekSuckRight"]["min"],self.calib["cheekSuckRight"]["max"]], # CheekPuff
[self.calib["jawOpen"]["min"],self.calib["jawOpen"]["max"]], # jawOpen
[self.calib["jawForward"]["min"],self.calib["jawForward"]["max"]], # jawForward
[self.calib["jawLeft"]["min"],self.calib["jawLeft"]["max"]], # jawLeft
[self.calib["jawRight"]["min"],self.calib["jawRight"]["max"]], # jawRight
[self.calib["noseSneerLeft"]["min"],self.calib["noseSneerLeft"]["max"]], # noseSneerLeft
[self.calib["noseSneerRight"]["min"],self.calib["noseSneerRight"]["max"]], # noseSneerRight
[self.calib["mouthFunnel"]["min"],self.calib["mouthFunnel"]["max"]], # mouthFunnel
[self.calib["mouthPucker"]["min"],self.calib["mouthPucker"]["max"]], # mouthPucker
[self.calib["mouthLeft"]["min"],self.calib["mouthLeft"]["max"]], # mouthLeft
@@ -88,49 +91,20 @@ class Calibration(object):
[self.calib["mouthStretchLeft"]["min"],self.calib["mouthStretchLeft"]["max"]], # mouthStretchLeft
[self.calib["mouthStretchRight"]["min"],self.calib["mouthStretchRight"]["max"]], # mouthStretchRight
[self.calib["tongueOut"]["min"],self.calib["tongueOut"]["max"]], # tongueOut
[self.calib["tongueUp"]["min"],self.calib["tongueUp"]["max"]], # tongueOut
[self.calib["tongueDown"]["min"],self.calib["tongueDown"]["max"]], # tongueOut
[self.calib["tongueLeft"]["min"],self.calib["tongueLeft"]["max"]], # tongueOut
[self.calib["tongueRight"]["min"],self.calib["tongueRight"]["max"]], # tongueOut
[self.calib["tongueRoll"]["min"],self.calib["tongueRoll"]["max"]], # tongueOut
[self.calib["tongueBendDown"]["min"],self.calib["tongueBendDown"]["max"]], # tongueOut
[self.calib["tongueCurlUp"]["min"],self.calib["tongueCurlUp"]["max"]], # tongueOut
[self.calib["tongueSquish"]["min"],self.calib["tongueSquish"]["max"]], # tongueOut
[self.calib["tongueFlat"]["min"],self.calib["tongueFlat"]["max"]], # tongueOut
[self.calib["tongueTwistLeft"]["min"],self.calib["tongueTwistLeft"]["max"]], # tongueOut
[self.calib["tongueTwistRight"]["min"],self.calib["tongueTwistRight"]["max"]], # tongueOut
]
return self.jsonminmax
def onesizefitsallminmaxarray(): # Some predefined ranges in stored values instead of the generated ones
stored_values = [
[0.2, 0.6], # CheekPuff
[0, 1], # cheekSquintLeft
[0, 1], # cheekSquintRight
[0, 1], # noseSneerLeft
[0, 1], # noseSneerRight
[0.03, 0.6], # jawOpen
[0.1, 0.8], # jawForward
[0.05, 0.5], # jawLeft
[0.05, 0.5], # jawRight
[0.1, 0.6], # mouthFunnel
[0.4, 1], # mouthPucker
[0.05, 0.5], # mouthLeft
[0.05, 0.5], # mouthRight
[0, 0.5], # mouthRollUpper
[0, 0.3], # mouthRollLower
[0.03, 0.5], # mouthShrugUpper
[0.03, 0.5], # mouthShrugLower
[0, 0.5], # mouthClose
[0.1, 1], # mouthSmileLeft
[0.1, 1], # mouthSmileRight
[0, 0.6], # mouthFrownLeft
[0, 0.6], # mouthFrownRight
[0, 1], # mouthDimpleLeft
[0, 1], # mouthDimpleRight
[0.02, 0.8], # mouthUpperUpLeft
[0.02, 0.8], # mouthUpperUpRight
[0.02, 0.8], # mouthLowerDownLeft
[0.02, 0.8], # mouthLowerDownRight
[0, 1], # mouthPressLeft
[0, 1], # mouthPressRight
[0.3, 1], # mouthStretchLeft
[0.3, 1], # mouthStretchRight
[0.2, 0.8], # tongueOut
]
return stored_values
def makeminmaxarray(amount):
stored_values = []
@@ -168,11 +142,11 @@ sg.theme('DarkAmber') # Add a touch of color
layout = [
[sg.Image(key = '-IMAGE-')],
[sg.Text('Enter Webcam URL or Number (Defualts to 0)'), sg.Input(key = '-URL-', size = (30, 1))],
[sg.Text('Enter Onnx model name (Defualts to EffnetB0300K.onnx)'), sg.Input(key = '-MODEL-', size = (30, 1))],
[sg.Text('Enter Onnx model name (Defualts to EFV2300K45E57.onnx)'), sg.Input(key = '-MODEL-', size = (30, 1))],
[sg.Text('OSC Location Address'), sg.Input(key = '-LOC-', size = (30, 1))],
[sg.Text('Output Mutiplier (defualts to 1. Please use 100 if you are using the unity demo.)'), sg.Input(key = '-MULT-', size = (30, 1))],
[sg.Text('Enter OSC IP (Defualts to 127.0.0.1)'), sg.Input(key = '-OSC-', size = (30, 1))],
[sg.Text('Enter OSC Port (Defualts to 9000)'), sg.Input(key = '-PORT-', size = (30, 1))],
[sg.Text('Enter OSC Port (Defualts to 8888)'), sg.Input(key = '-PORT-', size = (30, 1))],
[sg.Text('Enter Calibration file name (Defaults to calib.json)'), sg.Input(key = '-JSON_FILE-', size = (30, 1))],
[sg.Text('Press Ok to start the webcam')],
[sg.Checkbox('Flip 180', key = '-FLIP180-')],
@@ -199,7 +173,9 @@ while True:
OSCip="127.0.0.1"
OSCport= values['-PORT-'] #VR Chat OSC port
if OSCport == '':
OSCport = 9000
OSCport = 8888
else:
OSCport = int(OSCport)
multi = values['-MULT-']
if multi == '':
multi = 1
@@ -208,7 +184,7 @@ while True:
client = udp_client.SimpleUDPClient(OSCip, OSCport)
model = values['-MODEL-']
if model == '':
model = 'EffnetB0300K.onnx'
model = 'EFV2300K45E57.onnx'
if calibjson == '':
calibjson = 'calib.json'
usegpu = values['-GPU-']
@@ -254,6 +230,7 @@ while True:
if flip90r:
frame = cv2.rotate(frame, cv2.ROTATE_90_COUNTERCLOCKWISE)
frame2 = frame
#frame = cv2.flip(frame, 1)
calibration.update_calib(calibjson) # Checks and updates values of the json file
stored_values = calibration.jsonminmax
frame = cv2.resize(frame, (256, 256))
@@ -282,37 +259,51 @@ while True:
array = output
for i in range(len(output)): # Clip values between 0 - 1
output[i] = max(min(output[i], 1), 0)
client.send_message(location + "/cheekPuff", array[0] * multi)
client.send_message(location + "/noseSneerLeft", output[5] * multi)
client.send_message(location + "/noseSneerRight", output[6] * multi)
client.send_message(location + "/jawOpen", array[1] * multi)
client.send_message(location + "/jawForward", array[2] * multi)
client.send_message(location + "/jawLeft", array[3] * multi)
client.send_message(location + "/jawRight", array[4] * multi)
client.send_message(location + "/mouthFunnel", array[7] * multi)
client.send_message(location + "/mouthPucker", array[8] * multi)
client.send_message(location + "/mouthLeft", array[9] * multi)
client.send_message(location + "/mouthRight", array[10] * multi)
client.send_message(location + "/mouthRollUpper", array[11] * multi)
client.send_message(location + "/mouthRollLower", array[12] * multi)
client.send_message(location + "/mouthShrugUpper", array[13] * multi)
client.send_message(location + "/mouthShrugLower", array[14] * multi)
client.send_message(location + "/mouthClose", output[15] * multi)
client.send_message(location + "/mouthSmileLeft", array[16] * multi)
client.send_message(location + "/mouthSmileRight", array[17] * multi)
client.send_message(location + "/mouthFrownLeft", array[18] * multi)
client.send_message(location + "/mouthFrownRight", array[19] * multi)
client.send_message(location + "/mouthDimpleLeft", array[20] * multi)
client.send_message(location + "/mouthDimpleRight", array[21] * multi)
client.send_message(location + "/mouthUpperUpLeft", array[22] * multi)
client.send_message(location + "/mouthUpperUpRight", array[23] * multi)
client.send_message(location + "/mouthLowerDownLeft", array[24] * multi)
client.send_message(location + "/mouthLowerDownRight", array[25] * multi)
client.send_message(location + "/mouthPressLeft", array[26] * multi)
client.send_message(location + "/mouthPressRight", array[27] * multi)
client.send_message(location + "/mouthStretchLeft", array[28] * multi)
client.send_message(location + "/mouthStretchRight", array[29] * multi)
client.send_message(location + "/tongueOut", array[30] * multi)
client.send_message(location + "/cheekPuffLeft", array[0] * multi)
client.send_message(location + "/cheekPuffRight", array[1] * multi)
client.send_message(location + "/cheekSuckLeft", array[2] * multi)
client.send_message(location + "/cheekSuckRight", array[3] * multi)
client.send_message(location + "/jawOpen", array[4] * multi)
client.send_message(location + "/jawForward", array[5] * multi)
client.send_message(location + "/jawLeft", array[6] * multi)
client.send_message(location + "/jawRight", array[7] * multi)
client.send_message(location + "/noseSneerLeft", array[8] * multi)
client.send_message(location + "/noseSneerRight", array[9] * multi)
client.send_message(location + "/mouthFunnel", array[10] * multi)
client.send_message(location + "/mouthPucker", array[11] * multi)
client.send_message(location + "/mouthLeft", array[12] * multi)
client.send_message(location + "/mouthRight", array[13] * multi)
client.send_message(location + "/mouthRollUpper", array[14] * multi)
client.send_message(location + "/mouthRollLower", array[15] * multi)
client.send_message(location + "/mouthShrugUpper", array[16] * multi)
client.send_message(location + "/mouthShrugLower", array[17] * multi)
client.send_message(location + "/mouthClose", output[18] * multi)
client.send_message(location + "/mouthSmileLeft", array[19] * multi)
client.send_message(location + "/mouthSmileRight", array[20] * multi)
client.send_message(location + "/mouthFrownLeft", array[21] * multi)
client.send_message(location + "/mouthFrownRight", array[22] * multi)
client.send_message(location + "/mouthDimpleLeft", array[23] * multi)
client.send_message(location + "/mouthDimpleRight", array[24] * multi)
client.send_message(location + "/mouthUpperUpLeft", array[25] * multi)
client.send_message(location + "/mouthUpperUpRight", array[26] * multi)
client.send_message(location + "/mouthLowerDownLeft", array[27] * multi)
client.send_message(location + "/mouthLowerDownRight", array[28] * multi)
client.send_message(location + "/mouthPressLeft", array[29] * multi)
client.send_message(location + "/mouthPressRight", array[30] * multi)
client.send_message(location + "/mouthStretchLeft", array[31] * multi)
client.send_message(location + "/mouthStretchRight", array[32] * multi)
client.send_message(location + "/tongueOut", array[33] * multi)
client.send_message(location + "/tongueUp", array[34] * multi)
client.send_message(location + "/tongueDown", array[35] * multi)
client.send_message(location + "/tongueLeft", array[36] * multi)
client.send_message(location + "/tongueRight", array[37] * multi)
client.send_message(location + "/tongueRoll", array[38] * multi)
client.send_message(location + "/tongueBendDown", array[39] * multi)
client.send_message(location + "/tongueCurlUp", array[40] * multi)
client.send_message(location + "/tongueSquish", array[41] * multi)
client.send_message(location + "/tongueFlat", array[42] * multi)
client.send_message(location + "/tongueTwistLeft", array[43] * multi)
client.send_message(location + "/tongueTwistRight", array[44] * multi)
frame2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
imgbytes = cv2.imencode('.png', frame2)[1].tobytes() # ditto
window['-IMAGE-'].update(data=imgbytes)
+87 -40
View File
@@ -1,13 +1,33 @@
{
"cheekPuff": {
"min": 0.0,
"max": 0.5
"cheekPuffLeft": {
"min": 0.1,
"max": 1.0
},
"cheekSquintLeft": {
"cheekPuffRight": {
"min": 0.1,
"max": 1.0
},
"cheekSuckLeft": {
"min": 0.1,
"max": 1.0
},
"cheekSuckRight": {
"min": 0.1,
"max": 1.0
},
"jawOpen": {
"min": 0.0,
"max": 1.0
},
"jawForward": {
"min": 0.0,
"max": 1.0
},
"cheekSquintRight": {
"jawLeft": {
"min": 0.0,
"max": 1.0
},
"jawRight": {
"min": 0.0,
"max": 1.0
},
@@ -19,57 +39,41 @@
"min": 0.0,
"max": 1.0
},
"jawOpen": {
"min": 0.0,
"max": 0.7
},
"jawForward": {
"min": 0.1,
"max": 0.8
},
"jawLeft": {
"min": 0.0,
"max": 0.5
},
"jawRight": {
"min": 0.0,
"max": 0.5
},
"mouthFunnel": {
"min": 0.05,
"max": 0.8
"max": 1.0
},
"mouthPucker": {
"min": 0.0,
"max": 0.8
"max": 1.0
},
"mouthLeft": {
"min": 0.05,
"max": 0.7
"max": 1.0
},
"mouthRight": {
"min": 0.05,
"max": 0.7
"max": 1.0
},
"mouthRollUpper": {
"min": 0.0,
"max": 0.7
"max": 1.0
},
"mouthRollLower": {
"min": 0.0,
"max": 0.7
"max": 1.0
},
"mouthShrugUpper": {
"min": 0.03,
"max": 0.6
"min": 0.0,
"max": 1.0
},
"mouthShrugLower": {
"min": 0.03,
"max": 0.6
"min": 0.0,
"max": 1.0
},
"mouthClose": {
"min": 0.2,
"max": 0.7
"min": 0.0,
"max": 1.0
},
"mouthSmileLeft": {
"min": 0.0,
@@ -81,11 +85,11 @@
},
"mouthFrownLeft": {
"min": 0.0,
"max": 0.7
"max": 1.0
},
"mouthFrownRight": {
"min": 0.0,
"max": 0.7
"max": 1.0
},
"mouthDimpleLeft": {
"min": 0.0,
@@ -120,16 +124,59 @@
"max": 1.0
},
"mouthStretchLeft": {
"min": 0.3,
"min": 0.05,
"max": 1.0
},
"mouthStretchRight": {
"min": 0.3,
"min": 0.05,
"max": 1.0
},
"tongueOut": {
"min": 0.2,
"max": 0.8
"min": 0.05,
"max": 1.0
},
"tongueUp": {
"min": 0.05,
"max": 1.0
},
"tongueDown": {
"min": 0.05,
"max": 1.0
},
"tongueLeft": {
"min": 0.05,
"max": 1.0
},
"tongueRight": {
"min": 0.05,
"max": 1.0
},
"tongueRoll": {
"min": 0.05,
"max": 1.0
},
"tongueBendDown": {
"min": 0.05,
"max": 1.0
},
"tongueCurlUp": {
"min": 0.05,
"max": 1.0
},
"tongueSquish": {
"min": 0.05,
"max": 1.0
},
"tongueFlat": {
"min": 0.05,
"max": 1.0
},
"tongueTwistLeft": {
"min": 0.05,
"max": 1.0
},
"tongueTwistRight": {
"min": 0.05,
"max": 1.0
}
}
File diff suppressed because it is too large. Load diff
-300
View File
@@ -1,300 +0,0 @@
import bpy
import copy
import random
import os
import time
def get_objs(collection): # Returns all meshes in a collection
collection = bpy.data.collections[collection]
for obj in collection.all_objects:
ob = bpy.data.objects[str(obj.name)]
if ob.type == 'MESH':
mesh_name = obj.name
#shapekey_name = shapekey_name.split()
return mesh_name
def clamp(num, min_value, max_value):
return max(min(num, max_value), min_value)
def zero(ob):
ob = bpy.data.objects[ob]
for shape in ob.data.shape_keys.key_blocks:
shape.value=0
shape.keyframe_insert(data_path="value", frame=bpy.context.scene.frame_current)
class Defines():
shape_defs = dict( # 29 shapes
cheekPuff = 'cheekPuff',
jawOpen = 'jawOpen',
jawForward = 'jawForward', # added
jawLeft = 'jawLeft', # added
jawRight = 'jawRight', # added
noseSneerLeft = 'noseSneerLeft', # added
noseSneerRight = 'noseSneerRight', # added
mouthFunnel = 'mouthFunnel', # added
mouthPucker = 'mouthPucker', # fixed in vrcft master
mouthLeft = 'mouthLeft', # added
mouthRight = 'mouthRight', # added
mouthRollUpper = 'mouthRollUpper', # fixed in vrcft master
mouthRollLower = 'mouthRollLower', # fixed in vrcft master
mouthShrugUpper = 'mouthShrugUpper', # added
mouthShrugLower = 'mouthShrugLower', # added
mouthClose = 'mouthClose', # MUST BE EQUAL TO jawOpen
mouthSmileLeft = 'mouthSmileL', # added
mouthSmileRight = 'mouthSmileR', # added
mouthFrownLeft = 'mouthFrownLeft', # added
mouthFrownRight = 'mouthFrownRight', # added
mouthDimpleLeft = 'mouthDimple_L', # added
mouthDimpleRight = 'mouthDimple_R', # added
mouthUpperUpLeft = 'mouthUpperUp_L', # added
mouthUpperUpRight = 'mouthUpperUp_R', # added
mouthLowerDownLeft = 'mouthLowerDown_L', # added
mouthLowerDownRight = 'mouthLowerDown_R', # added
mouthPressLeft = 'mouthPress_L', # added
mouthPressRight = 'mouthPress_R', # added
mouthStretchLeft = 'mouthStretch_L', # added
mouthStretchRight = 'mouthStretch_R', # added
tongueOut = 'tongueOut'
)
shape_index = ["cheekPuff", "jawOpen", "jawForward", "jawLeft", "jawRight", "noseSneerLeft", "noseSneerRight", "mouthFunnel", "mouthPucker", "mouthLeft", "mouthRight",
"mouthRollUpper", "mouthRollLower", "mouthShrugUpper", "mouthShrugLower", "mouthClose", "mouthSmileLeft",
"mouthSmileRight", "mouthFrownLeft", "mouthFrownRight", "mouthDimpleLeft", "mouthDimpleRight", "mouthUpperUpLeft",
"mouthUpperUpRight", "mouthLowerDownLeft", "mouthLowerDownRight", "mouthPressLeft", "mouthPressRight", "mouthStretchLeft",
"mouthStretchRight", "tongueOut"]
exclusives = [ # mark these combinations for special treatment after generating values(combined values, etc...)
['mouthClose', 'jawOpen'],
['mouthShrugUpper', 'mouthShrugLower'],
['tongueOut', 'jawOpen'],
['mouthSmileLeft', 'mouthSmileRight']
]
shape_bl = dict(
cheekPuff = ['cheekPuff', 'jawOpen', 'mouthFunnel', 'mouthShrugUpper', 'mouthShrugLower', 'mouthClose', 'mouthUpperUpLeft', 'mouthUpperUpRight', 'mouthLowerDownLeft', 'mouthLowerDownRight', 'tongueOut'],
jawOpen = ['cheekPuff', 'jawOpen', 'mouthShrugLower', 'mouthShrugUpper'],
jawForward = ['jawForward'],
jawLeft = ['jawLeft', 'jawRight'],
jawRight = ['jawRight', 'jawLeft'],
noseSneerLeft = ['noseSneerLeft'],
noseSneerRight = ['noseSneerRight'],
mouthFunnel = ['mouthFunnel', 'cheekPuff', 'mouthPucker', 'mouthRollUpper', 'mouthRollLower', 'mouthClose'],
mouthPucker = ['mouthPucker', 'jawLeft', 'jawRight', 'mouthFunnel', 'mouthRollUpper', 'mouthRollLower', 'mouthClose'],
mouthLeft = ['mouthLeft', 'mouthRight'],
mouthRight = ['mouthRight', 'mouthLeft'],
mouthRollUpper = ['mouthRollUpper', 'jawOpen', 'mouthFunnel', 'mouthPucker', 'mouthClose', 'mouthUpperUpLeft', 'mouthUpperUpRight'],
mouthRollLower = ['mouthRollLower', 'jawOpen', 'mouthFunnel', 'mouthPucker', 'mouthClose', 'mouthLowerDownLeft', 'mouthLowerDownRight'],
mouthShrugUpper = ['mouthShrugUpper', 'jawOpen', 'mouthClose', 'tongueOut'],
mouthShrugLower = ['mouthShrugLower', 'jawOpen', 'mouthClose', 'tongueOut'],
mouthClose = ['mouthPucker', 'mouthClose', 'mouthShrugUpper', 'mouthShrugLower', 'tongueOut', 'mouthUpperUpLeft', 'mouthUpperUpRight', 'mouthLowerDownLeft', 'mouthLowerDownRight'],
mouthSmileLeft = ['mouthSmileLeft', 'mouthFrownLeft', 'mouthDimpleLeft', 'mouthPressLeft', 'mouthStretchLeft', 'mouthShrugUpper', 'mouthShrugLower'],
mouthSmileRight = ['mouthSmileRight', 'mouthFrownRight', 'mouthDimpleRight', 'mouthPressRight', 'mouthStretchRight', 'mouthShrugUpper', 'mouthShrugLower'],
mouthFrownLeft = ['mouthSmileLeft', 'mouthFrownLeft', 'mouthDimpleLeft', 'mouthPressLeft', 'mouthStretchLeft'],
mouthFrownRight = ['mouthSmileRight', 'mouthFrownRight', 'mouthDimpleRight', 'mouthPressRight', 'mouthStretchRight'],
mouthDimpleLeft = ['mouthSmileLeft', 'mouthFrownLeft', 'mouthDimpleLeft', 'mouthPressLeft', 'mouthStretchLeft'],
mouthDimpleRight = ['mouthSmileRight', 'mouthFrownRight', 'mouthDimpleRight', 'mouthPressRight', 'mouthStretchRight'],
mouthUpperUpLeft = ['mouthUpperUpLeft', 'mouthRollUpper', 'cheekPuff'],
mouthUpperUpRight = ['mouthUpperUpRight', 'mouthRollUpper', 'cheekPuff'],
mouthLowerDownLeft = ['mouthLowerDownLeft', 'mouthRollLower', 'cheekPuff'],
mouthLowerDownRight = ['mouthLowerDownRight', 'mouthRollLower', 'cheekPuff'],
mouthPressLeft = ['mouthSmileLeft', 'mouthFrownLeft', 'mouthDimpleLeft', 'mouthPressLeft', 'mouthStretchLeft'],
mouthPressRight = ['mouthSmileRight', 'mouthFrownRight', 'mouthDimpleRight', 'mouthPressRight', 'mouthStretchRight'],
mouthStretchLeft = ['mouthSmileLeft', 'mouthFrownLeft', 'mouthDimpleLeft', 'mouthPressLeft', 'mouthStretchLeft'],
mouthStretchRight = ['mouthSmileRight', 'mouthFrownRight', 'mouthDimpleRight', 'mouthPressRight', 'mouthStretchRight'],
tongueOut = ['tongueOut', 'mouthClose']
)
class ShapeSetter():
def __init__(self):
self.blacklist = []
self.randomized_shapes = []
self.possible_shapes = []
self.selected_shapes = []
self.selected_shapes_index = []
self.total_shapes = 0
self.count = 0
def reset(self, DefsClass):
defs = DefsClass
self.blacklist = []
self.randomized_shapes = []
self.selected_shapes = []
self.selected_shapes_index = []
self.total_shapes = len(defs.shape_defs)
self.possible_shapes = copy.copy(defs.shape_index)
def convert_to_defined(self, defs):
defines_list = []
for i in range(len(self.selected_shapes_index)):
defines_list.append(defs.shape_defs[self.selected_shapes_index[i]])
return(defines_list)
def get_avalible_shapes(self, defs, shape): # Adds the shape's blacklist to the list and returns the remaining potential shapes
self.blacklist.append(defs.shape_bl[shape])
for i in range(len(self.possible_shapes)):
for j in range(len(self.blacklist)):
for k in range(len(self.blacklist[j])):
if self.blacklist[j][k] in self.possible_shapes:
self.possible_shapes.pop(self.possible_shapes.index(self.blacklist[j][k]))
return(self.possible_shapes)
def process_exclusives(self, defs):
if defs.exclusives[0][0] in self.selected_shapes_index and not defs.exclusives[0][1] in self.selected_shapes_index: # mouthClose = jawOpen
self.selected_shapes_index.append(defs.exclusives[0][1]) # Add jawOpen value if missing
self.selected_shapes.append(0.0)
if all(item in self.selected_shapes_index for item in defs.exclusives[0]):
self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[0][1])] = self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[0][0])] # set jawOpen = mouthClose
if defs.exclusives[1][0] in self.selected_shapes_index and not defs.exclusives[1][1] in self.selected_shapes_index: # mouthShrugLower = mouthShrugUpper
self.selected_shapes_index.append(defs.exclusives[1][1]) # Add jawOpen value if missing
self.selected_shapes.append(self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[1][0])])
if defs.exclusives[1][1] in self.selected_shapes_index and not defs.exclusives[1][0] in self.selected_shapes_index:
self.selected_shapes_index.append(defs.exclusives[1][0]) # Add jawOpen value if missing
self.selected_shapes.append(self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[1][1])])
if defs.exclusives[1][1] in self.selected_shapes_index and defs.exclusives[1][0] in self.selected_shapes_index:
self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[1][1])] = self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[1][0])]
if defs.exclusives[2][0] in self.selected_shapes_index and not defs.exclusives[2][1] in self.selected_shapes_index: # tongueOut requires jawOpen >= 0.35
self.selected_shapes_index.append(defs.exclusives[2][1]) # Add jawOpen value if missing
self.selected_shapes.append(0.0)
if defs.exclusives[2][0] in self.selected_shapes_index and self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[2][1])] <= 0.35:
self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[2][1])] = clamp(random.uniform(0.35, 1.05), 0, 1)
if defs.exclusives[3][1] in self.selected_shapes_index and defs.exclusives[3][0] in self.selected_shapes_index: # randomly make mouthSmileLeft and mouthSmileRight equal to the greater value
if random.randint(0, 1) == 1: # 50% chance to make values equal
if self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[3][1])] > self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[3][0])]:
self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[3][0])] = self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[3][1])]
if self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[3][0])] > self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[3][1])]:
self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[3][1])] = self.selected_shapes[self.selected_shapes_index.index(defs.exclusives[3][0])]
def generate_example(self, DefsClass, range, classExample):
defs = DefsClass
self.reset(defs)
if type(classExample) == int: classExample = defs.shape_index[classExample] # Take either String or int
if type(classExample) == str: classExample = defs.shape_index[defs.shape_index.index(classExample)]
self.selected_shapes.append(clamp(random.uniform(range[0], range[1]), 0, 1))
self.selected_shapes_index.append(classExample)
shape = random.choice(self.get_avalible_shapes(defs, classExample))
while len(self.possible_shapes) > 0:
if 0.75 >= random.uniform(0,1): # 75% chance for shape to be set
self.selected_shapes.append(clamp(random.uniform(-0.1, self.selected_shapes[0] - 0.1), 0, 1))
self.selected_shapes_index.append(shape)
try: shape = random.choice(self.get_avalible_shapes(defs, shape))
except: break
self.process_exclusives(defs)
self.tick()
return self.selected_shapes, self.convert_to_defined(defs)
def tick(self):
self.count += 1
if self.count == self.total_shapes:
self.count = 0
class EncodeDecode():
def float_to_uint24(self, f):
f = round(f, 8)
f_clamped = max(0, min(1, f))
uint24 = int(f_clamped * ((1 << 24) - 1))
return uint24
def uint24_to_float(self, uint24):
f = uint24 / ((1 << 24) - 1)
return f
def encode(self, f, index): # uint24 to blender pixel (1.0, 1.0, 1.0)
hex_str = format(f, '06x')
hex_str = list(hex_str.strip(" "))
bpy.data.scenes["Scene"].node_tree.nodes["Group.002"].inputs[index].default_value = ((int('0x' + hex_str[0] + hex_str[1], 0) / 255),(int('0x' + hex_str[2] + hex_str[3], 0) / 255),(int('0x' + hex_str[4] + hex_str[5], 0) / 255),1)
return ((int('0x' + hex_str[0] + hex_str[1], 0) / 255),(int('0x' + hex_str[2] + hex_str[3], 0) / 255),(int('0x' + hex_str[4] + hex_str[5], 0) / 255),1)
def decode(self, pixel): # Pixel to uint24 (255, 255, 255)
output_hex = ('0x' + hex(pixel[0]).replace('0x', '').rjust(2, "0") + hex(pixel[1]).replace('0x', '').rjust(2, "0") + hex(pixel[2]).replace('0x', '').rjust(2, "0"))
output_hex = int(output_hex, 0)
return(output_hex)
FRAME_START = bpy.context.scene.frame_start
FRAME_END = bpy.context.scene.frame_end
defs = Defines()
ss = ShapeSetter()
encdec = EncodeDecode()
tick = 0
range_select = 0
range_list = [
[0.6,1.05],
[0.4, 0.7],
[-0.2, 0.5]
]
mesh = 'BabbleCA_M'
ob = bpy.data.objects[mesh]
for frame in range(FRAME_START, FRAME_END+1): # Iterate over each frame in the range
model_shapes = []
print(f"Generated {frame} of {FRAME_END} shapes")
ob = ob
if tick == ss.total_shapes:
tick = 0
range_select += 1
if range_select > 2:range_select = 0
values, names = ss.generate_example(defs, range_list[range_select], defs.shape_index[ss.count])
bpy.context.scene.frame_set(frame)# Go to the current frame
zero(mesh)
shapecount = len(defs.shape_index)
for i in range(shapecount): # Reset compositor data
encdec.encode(encdec.float_to_uint24(ob.data.shape_keys.key_blocks[defs.shape_defs[defs.shape_index[i]]].value), i + 2)
for i in range(shapecount): # Write reset Compositor data
bpy.data.scenes["Scene"].node_tree.nodes["Group.002"].inputs[i + 2].keyframe_insert(data_path="default_value", frame=frame)
for i in range(len(values)): # Iterate over each shape key
ob.data.shape_keys.key_blocks[names[i]].value = values[i]
key = ob.data.shape_keys.key_blocks[names[i]]
key.keyframe_insert(data_path="value", frame=frame)
hmd_type = random.randint(0,2)
ob = bpy.data.objects['Pimax']
ob.hide_render = True
ob.keyframe_insert(data_path="hide_render", frame=frame)
ob = bpy.data.objects['Quest2']
ob.hide_render = True
ob.keyframe_insert(data_path="hide_render", frame=frame)
if hmd_type == 0:
ob = bpy.data.objects['Pimax']
ob.hide_render = True
ob.keyframe_insert(data_path="hide_render", frame=frame)
ob = bpy.data.objects['Quest2']
ob.hide_render = True
ob.keyframe_insert(data_path="hide_render", frame=frame)
if hmd_type == 1:
ob = bpy.data.objects['Pimax']
ob.hide_render = False
ob.keyframe_insert(data_path="hide_render", frame=frame)
if hmd_type == 2:
ob = bpy.data.objects['Quest2']
ob.hide_render = False
ob.keyframe_insert(data_path="hide_render", frame=frame)
camera_type = random.randint(0,1)
ob = bpy.data.objects['ViveCamera']
ob.hide_render = True
ob.keyframe_insert(data_path="hide_render", frame=frame)
ob = bpy.data.objects['PhoneCamera']
ob.hide_render = True
ob.keyframe_insert(data_path="hide_render", frame=frame)
if camera_type == 0:
ob = bpy.data.objects['ViveCamera']
ob.hide_render = False
ob.keyframe_insert(data_path="hide_render", frame=frame)
if camera_type == 1:
ob = bpy.data.objects['PhoneCamera']
ob.hide_render = False
ob.keyframe_insert(data_path="hide_render", frame=frame)
ob = bpy.data.objects[mesh]
encdec.encode(shapecount, 1)
bpy.data.scenes["Scene"].node_tree.nodes["Group.002"].inputs[1].keyframe_insert(data_path="default_value", frame=frame)
for i in range(shapecount):
encdec.encode(encdec.float_to_uint24(ob.data.shape_keys.key_blocks[defs.shape_defs[defs.shape_index[i]]].value), i + 2)
for i in range(shapecount):
bpy.data.scenes["Scene"].node_tree.nodes["Group.002"].inputs[i + 2].keyframe_insert(data_path="default_value", frame=frame)
tick += 1
-57
View File
@@ -1,57 +0,0 @@
from PIL import Image, ImageFilter
import os
class EncodeDecode():
def float_to_uint24(self, f):
f = round(f, 8)
f_clamped = max(0, min(1, f))
uint24 = int(f_clamped * ((1 << 24) - 1))
return uint24
def uint24_to_float(self, uint24):
f = uint24 / ((1 << 24) - 1)
return f
def encode(self, f, index): # uint24 to blender pixel (1.0, 1.0, 1.0) RGB
hex_str = format(f, '06x')
hex_str = list(hex_str.strip(" "))
#bpy.data.scenes["Scene"].node_tree.nodes["Group.002"].inputs[index].default_value = ((int('0x' + hex_str[0] + hex_str[1], 0) / 255),(int('0x' + hex_str[2] + hex_str[3], 0) / 255),(int('0x' + hex_str[4] + hex_str[5], 0) / 255),1)
return ((int('0x' + hex_str[0] + hex_str[1], 0) / 255),(int('0x' + hex_str[2] + hex_str[3], 0) / 255),(int('0x' + hex_str[4] + hex_str[5], 0) / 255),1)
def decode(self, pixel): # Pixel to uint24 (255, 255, 255) RGB
output_hex = ('0x' + hex(pixel[0]).replace('0x', '').rjust(2, "0") + hex(pixel[1]).replace('0x', '').rjust(2, "0") + hex(pixel[2]).replace('0x', '').rjust(2, "0"))
output_hex = int(output_hex, 0)
return(output_hex)
def get_shapes(ed, img):
px = img.load()
output = ed.decode(px[0, 256]) # Shape count
shapes = []
for i in range(output):
uint = ed.decode(px[(i + 1), 256])
shapes.append(ed.uint24_to_float(uint))
return shapes
shape_index = ["cheekPuff", "jawOpen", "jawForward", "jawLeft", "jawRight", "noseSneerLeft", "noseSneerRight", "mouthFunnel", "mouthPucker", "mouthLeft", "mouthRight",
"mouthRollUpper", "mouthRollLower", "mouthShrugUpper", "mouthShrugLower", "mouthClose", "mouthSmileLeft",
"mouthSmileRight", "mouthFrownLeft", "mouthFrownRight", "mouthDimpleLeft", "mouthDimpleRight", "mouthUpperUpLeft",
"mouthUpperUpRight", "mouthLowerDownLeft", "mouthLowerDownRight", "mouthPressLeft", "mouthPressRight", "mouthStretchLeft",
"mouthStretchRight", "tongueOut"]
path = r'Z:/BabbleDataGeneration/BabbleDataGeneration/render/'
dir_list = os.listdir(path)
ed = EncodeDecode()
shapes = []
'''
for i in range(len(dir_list)):
img = Image.open(path + dir_list[i])
shapes.append(get_shapes(ed, img))
'''
box = (0, 0, 256, 256)
img = Image.open(path + dir_list[1]).crop(box)
img = img.filter(ImageFilter.GaussianBlur(1.5))
#box = (0, 0, 256, 256)
#img = img.crop(box)
img.show()
print(shapes)
-39
View File
@@ -1,39 +0,0 @@
import os
# Path to subdirectory containing text files
path_to_files = "lipcsv"
# Output file name
output_file = "dataset_30K3.2_mar-23-2023_OV2640-160.csv"
# Header row
header = str(['cheekPuff','cheekSquintLeft','cheekSquintRight','noseSneerLeft','noseSneerLeft','jawOpen',
'jawForward','jawLeft','jawRight','mouthFunnel','mouthPucker','mouthLeft','mouthRight',
'mouthRollUpper','mouthRollLower','mouthShrugUpper','mouthShrugLower','mouthClose',
'mouthSmileLeft','mouthSmileRight','mouthFrownLeft','mouthFrownRight','mouthDimpleLeft','mouthDimpleRight',
'mouthUpperUpLeft','mouthUpperUpRight','mouthLowerDownLeft','mouthLowerDownRight','mouthPressLeft',
'mouthPressRight','mouthStretchLeft','mouthStretchRight','tongueOut','filename'])
header = header.replace("'", "")
header = header.replace("[", "")
header = header.replace("]", "")
header = header.replace(' ', "")
count = 0
# Open output file for writing and write header row
with open(output_file, "w", buffering=10000) as outfile:
outfile.write(header)
# Loop over all files in subdirectory
for filename in os.listdir(path_to_files):
# Only process files with .csv extension
if filename.endswith(".csv"):
with open(os.path.join(path_to_files, filename), "r") as infile:
# Read data from input file and write to output file
contents = infile.read()
if count == 0:
outfile.write(f"\n{contents}\n")
else:
outfile.write(f"{contents}\n")
print(f"Combined {count} files!")
count += 1
@@ -1,123 +0,0 @@
import os
from PIL import Image
class EncodeDecode():
def float_to_uint24(self, f):
f = round(f, 8)
f_clamped = max(0, min(1, f))
uint24 = int(f_clamped * ((1 << 24) - 1))
return uint24
def uint24_to_float(self, uint24):
f = uint24 / ((1 << 24) - 1)
return f
def encode(self, f, index): # uint24 to blender pixel (1.0, 1.0, 1.0)
hex_str = format(f, '06x')
hex_str = list(hex_str.strip(" "))
#print(hex_str)
#bpy.data.scenes["Scene"].node_tree.nodes["Group.002"].inputs[index].default_value = ((int('0x' + hex_str[0] + hex_str[1], 0) / 255),(int('0x' + hex_str[2] + hex_str[3], 0) / 255),(int('0x' + hex_str[4] + hex_str[5], 0) / 255),1)
return ((int('0x' + hex_str[0] + hex_str[1], 0) / 255),(int('0x' + hex_str[2] + hex_str[3], 0) / 255),(int('0x' + hex_str[4] + hex_str[5], 0) / 255),1)
def decode(self, pixel): # Pixel to uint24 (255, 255, 255)
output_hex = ('0x' + hex(pixel[0]).replace('0x', '').rjust(2, "0") + hex(pixel[1]).replace('0x', '').rjust(2, "0") + hex(pixel[2]).replace('0x', '').rjust(2, "0"))
output_hex = int(output_hex, 0)
return(output_hex)
# Path to subdirectory containing text files
path_to_files = "X:/Downloads/render/render/"
# Output file name
output_file = "babble_dataset.csv"
# Header row
header = str(["cheekPuff", "jawOpen", "jawForward", "jawLeft", "jawRight", "noseSneerLeft", "noseSneerRight", "mouthFunnel", "mouthPucker", "mouthLeft", "mouthRight",
"mouthRollUpper", "mouthRollLower", "mouthShrugUpper", "mouthShrugLower", "mouthClose", "mouthSmileLeft",
"mouthSmileRight", "mouthFrownLeft", "mouthFrownRight", "mouthDimpleLeft", "mouthDimpleRight", "mouthUpperUpLeft",
"mouthUpperUpRight", "mouthLowerDownLeft", "mouthLowerDownRight", "mouthPressLeft", "mouthPressRight", "mouthStretchLeft",
"mouthStretchRight", "tongueOut", "filename"])
header = header.replace("'", "")
header = header.replace("[", "")
header = header.replace("]", "")
header = header.replace(' ', "")
# Open output file for writing and write header row
shape_index = ["cheekPuff", "jawOpen", "jawForward", "jawLeft", "jawRight", "noseSneerLeft", "noseSneerRight", "mouthFunnel", "mouthPucker", "mouthLeft", "mouthRight",
"mouthRollUpper", "mouthRollLower", "mouthShrugUpper", "mouthShrugLower", "mouthClose", "mouthSmileLeft",
"mouthSmileRight", "mouthFrownLeft", "mouthFrownRight", "mouthDimpleLeft", "mouthDimpleRight", "mouthUpperUpLeft",
"mouthUpperUpRight", "mouthLowerDownLeft", "mouthLowerDownRight", "mouthPressLeft", "mouthPressRight", "mouthStretchLeft",
"mouthStretchRight", "tongueOut"]
def get_shapes(ed, img):
px = img.load()
output = ed.decode(px[0, 256]) # Shape count
shapes = []
for i in range(output):
uint = ed.decode(px[(i + 1), 256]) # Skip the bottom left pixel because it's a uint24 of the shape count
shapes.append(ed.uint24_to_float(uint))
return shapes
ed = EncodeDecode()
shape_defs = dict( # 31 shapes
cheekPuff = [],
jawOpen = [],
jawForward = [], # added
jawLeft = [], # added
jawRight = [], # added
noseSneerLeft = [], # added
noseSneerRight = [], # added
mouthFunnel = [], # added
mouthPucker = [], # fixed in vrcft master
mouthLeft = [], # added
mouthRight = [], # added
mouthRollUpper = [], # fixed in vrcft master
mouthRollLower = [], # fixed in vrcft master
mouthShrugUpper = [], # added
mouthShrugLower = [], # added
mouthClose = [], # MUST BE EQUAL TO jawOpen
mouthSmileLeft = [], # added
mouthSmileRight = [], # added
mouthFrownLeft = [], # added
mouthFrownRight = [], # added
mouthDimpleLeft = [], # added
mouthDimpleRight = [], # added
mouthUpperUpLeft = [], # added
mouthUpperUpRight = [], # added
mouthLowerDownLeft = [], # added
mouthLowerDownRight = [], # added
mouthPressLeft = [], # added
mouthPressRight = [], # added
mouthStretchLeft = [], # added
mouthStretchRight = [], # added
tongueOut = [],
filename = []
)
count = 0
with open(output_file, "w", buffering=10000) as outfile:
outfile.write(header)
# Loop over all files in subdirectory
for filename in os.listdir(path_to_files):
# Only process files with .csv extension
if filename.endswith(".png"):
# Read data from input file and write to output file
data = []
img = Image.open(path_to_files + filename)
data = get_shapes(ed, img)
data.append(path_to_files + filename)
data = str(data)
data = data.replace("'", "")
data = data.replace("[", "")
data = data.replace("]", "")
data = data.replace(' ', "")
contents = data
if count == 0:
outfile.write(f"\n{contents}\n")
else:
outfile.write(f"{contents}\n")
print(f"Combined {count} files!")
count += 1
@@ -1,21 +0,0 @@
import os
# specify the directories
dir1 = "C:\\Users\\epicm\\Desktop\\BabbleTraining\\lipcsv"
dir2 = "C:\\Users\\epicm\\Desktop\\BabbleTraining\\lipimages"
# get a list of all files in the first directory
files1 = [os.path.splitext(file)[0] for file in os.listdir(dir1)]
# get a list of all files in the second directory
files2 = [os.path.splitext(file)[0] for file in os.listdir(dir2)]
# find the files in the first directory that don't have a pair in the second directory
for file1 in files1:
if file1 not in files2:
print(f"{file1} doesn't have a pair in the second directory")
# find the files in the second directory that don't have a pair in the first directory
for file2 in files2:
if file2 not in files1:
print(f"{file2} doesn't have a pair in the first directory")
@@ -1,23 +0,0 @@
import csv
# Open the CSV file for reading
with open('your_file.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
fieldnames = csv_reader.fieldnames
# Open a new CSV file for writing
with open('new_file.csv', mode='w', newline='') as new_csv_file:
writer = csv.DictWriter(new_csv_file, fieldnames=fieldnames)
writer.writeheader()
# Iterate over each row in the original CSV file
for row in csv_reader:
# Check if the row has values for both mouthLeft and mouthRight columns
if row.get('mouthLeft') and row.get('mouthRight'):
# If it does, skip this row
continue
else:
# Otherwise, write this row to the new CSV file
writer.writerow(row)
print('Filtered CSV created successfully')
-23
View File
@@ -1,23 +0,0 @@
import os
import shutil
# specify the directories
source_dir = "C:\\Users\\epicm\\Desktop\\BabbleTraining\\lipimages"
destination_dir = "C:\\Users\\epicm\\Desktop\\BabbleTraining\\lipcsv"
# create the destination directory if it doesn't exist
if not os.path.exists(destination_dir):
os.makedirs(destination_dir)
# loop through all files in the source directory
for file_name in os.listdir(source_dir):
# check if the file is a CSV file
if file_name.endswith('.csv'):
# construct the full path to the file
source_file = os.path.join(source_dir, file_name)
destination_file = os.path.join(destination_dir, file_name)
# move the file to the destination directory
shutil.move(source_file, destination_file)
print("CSV files moved successfully!")
@@ -1,304 +0,0 @@
# For use with the RenderSceneV2 Blender project
################################
# Blender will appear to hang when run
# That's just how blender runs scripts :shrug:
################################
import bpy
import math
import random
import socket
import pickle
import struct
from time import sleep
# Set path for enviroment
path = "C:\\Users\\epicm\\Documents\\GitHub\\ProjectBabble\\datageneration\\Output\\"
res_x = 800
res_y = 800
blendshape_list = (
'eyeLeftSqueeze',
'eyeRightSqueeze',
'Expressions_eyeSquintL_max',
'Expressions_eyeSquintR_max',
'Expressions_eyeClosedL_max',
'eyeLookInLeft',
'eyeLookOutLeft',
'eyeLookUpLeft',
'eyeLookDownLeft',
'Expressions_eyeClosedR_max',
'eyeLookOutRight',
'eyeLookInRight',
'eyeLookUpRight',
'eyeLookDownRight',
'Expressions_eyeClosedL_min',
'Expressions_eyeClosedR_min',
'eyesDilationLeft',
'eyesDilationRight',
'eyesConstrictLeft',
'eyesConstrictRight',
'browInnerUpLeft',
'browInnerUpRight',
'Expressions_browOutVertL_min',
'Expressions_browOutVertR_min',
'Expressions_browOutVertL_max',
'Expressions_browOutVertR_max',
'Expressions_eyeSquintL_max',
'Expressions_eyeSquintR_max',
'cheekPuffLeft',
'cheekPuffRight',
'Expressions_cheekSneerL_max',
'Expressions_cheekSneerR_max',
'Expressions_mouthInflated_min',
'lipSuckLeftBottom',
'lipSuckLeftTop',
'lipSuckRightBottom',
'lipSuckRightTop',
'Expressions_mouthOpen_max',
'Expressions_jawHoriz_max',
'Expressions_jawHoriz_min',
'Expressions_jawOut_max',
'Expressions_mouthOpenO_min',
'Expressions_mouthOpenO_max',
'Expressions_mouthOpenLarge_min',
'mouthClose',
'mouthApeShape',
'Expressions_mouthHoriz_max',
'Expressions_mouthHoriz_min',
'Expressions_mouthSmileL_max',
'Expressions_mouthSmileR_max',
'mouthFrownLeft',
'mouthFrownRight',
'mouthDimpleLeft',
'mouthDimpleRight',
'mouthRollUpper',
'Expressions_mouthLowerOut_min',
'mouthShrugUpper',
'mouthLowerOverturn',
'mouthShrugLower',
'mouthUpperUpLeft',
'mouthUpperUpRight',
'mouthLowerDownLeft',
'mouthLowerDownRight',
'mouthPressLeft',
'mouthPressRight',
'mouthStretchLeft',
'mouthStretchRight',
'Expressions_tongueOut_max',
'Expressions_tongueVert_min',
'Expressions_tongueVert_max',
'Expressions_tongueHoriz_max',
'Expressions_tongueHoriz_min',
'tongueRoll'
)
def send_msg(sock, msg):
# Prefix each message with a 4-byte length (network byte order)
msg = struct.pack('>I', len(msg)) + msg
sock.sendall(msg)
def recv_msg(sock):
# Read message length and unpack it into an integer
raw_msglen = recvall(sock, 4)
if not raw_msglen:
return None
msglen = struct.unpack('>I', raw_msglen)[0]
# Read the message data
return recvall(sock, msglen)
def recvall(sock, n):
# Helper function to recv n bytes or return None if EOF is hit
data = bytearray()
while len(data) < n:
packet = sock.recv(n - len(data))
if not packet:
return None
data.extend(packet)
return data
def zero_blendshapes(ob): # Resets all Blendshapes to 0
for shape in ob.data.shape_keys.key_blocks:
shape.value=0
def get_set_values(ob, blendshape_list, set_list): # Debug function to get the value of blendshapes
for shape in ob.data.shape_keys.key_blocks:
if shape.name in blendshape_list:
set_list.append(shape.value)
def zero_bg(): # Sets the Z position of all backgrounds to 0
for i in range(14):
ob = bpy.data.objects['BG' + str(i + 1)]
ob.location[1] = 0
def randomize_bg(): # Moves a random background plane to be in view
ob = bpy.data.objects['BG' + str(random.randint(1, 14))]
ob.location[1] = -0.1
def zero_camera(): # Sets the camera rig to a known rest pose.
ob = bpy.data.objects['CameraRig']
bpy.context.view_layer.objects.active = ob
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['Camera']
pbone.rotation_euler = (0, 0, 0)
pbone = ob.pose.bones['CameraArm']
pbone.rotation_euler = (0, 0, 0)
pbone = ob.pose.bones['MBLabHead']
pbone.rotation_euler = (0, 0, 0)
bpy.ops.object.mode_set(mode='OBJECT')
def randomize_scene(): # Randomizes various scene parameters like lighting and camera focal length
ob = bpy.data.cameras['Camera']
ob.lens = round(random.uniform(22, 30), 2)
ob = bpy.data.scenes["Scene"].node_tree.nodes["Lens Distortion"].inputs[1] # Compositer Lens Distortion
ob.default_value = random.uniform(0.01, 0.27)
# Camera
ob = bpy.data.objects['CameraRig'] # The thing we're talking about
bpy.context.view_layer.objects.active = ob # Click it (make it the active selection)
bpy.ops.object.mode_set(mode='POSE') # Go into pose mode
pbone = ob.pose.bones['Camera'] # Select the bone to rotate
pbone.rotation_mode = 'XYZ' # Set rotations to euler because quaternions are an alien technology
axis = 'Z' # Select rotaion axis (local)
angle = random.uniform(-2, 3)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle)) # Do the rotation
# Camera Arm
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['CameraArm']
pbone.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(-2, 2)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle))
# MLabHead
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['MBLabHead']
pbone.rotation_mode = 'XYZ'
axis = 'Y'
angle = random.uniform(-3, 3)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle))
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['MBLabHead']
pbone.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(-3, 3)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle))
bpy.ops.object.mode_set(mode='OBJECT')
# Applies random rotation to the 3 scene lights
ob = bpy.data.objects['Light1']
ob.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(0, 360)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
axis = 'Y'
angle = random.uniform(-40, 40)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
ob = bpy.data.objects['Light2']
ob.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(0, 360)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
axis = 'Y'
angle = random.uniform(-40, 40)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
ob = bpy.data.objects['Light3']
ob.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(0, 360)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
axis = 'Y'
angle = random.uniform(-40, 40)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
def set_shape(shapekey_name, ob, value): # Set a value to a blendshape
ob.data.shape_keys.key_blocks[shapekey_name].value = value
bpy.ops.wm.console_toggle() # Toggle the system console
# Setup Connection
HOST = 'localhost'
PORT = 50000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(5)
scene=bpy.context.scene
scene.render.resolution_x = res_x
scene.render.resolution_y = res_y
try:
while True: # Recieve Blendshape List
conn, (address, port) = s.accept()
data = recv_msg(conn)
render_job = pickle.loads(data)
print(f'Got Blendshapes containing {render_job}')
# Acknowledge blendshape list
ack_msg = pickle.dumps('Got Blendshape Lists')
send_msg(conn, ack_msg)
ob = bpy.data.objects['MBLab_CA_M']
print('Set Object')
set_list = []
if render_job:
print('Starting Render')
image_count = 0
for i in render_job:
c = 0
zero_camera()
zero_blendshapes(ob)
zero_bg()
for value in i:
#print(f'Setting Blendshape of: {blendshape_list[c]}')
set_shape(blendshape_list[c], ob, value)
c += 1
get_set_values(ob, blendshape_list, set_list)
print('Started Blender Render Process')
randomize_bg()
randomize_scene()
# Blender render stuff
imagename = str(image_count).zfill(3)
img_filename = str(imagename + '.png')
scene.render.filepath = (
path
+ imagename
)
bpy.ops.render.render( #{'dict': "override"},
#'INVOKE_DEFAULT',
False,
animation=False,
write_still=True
)
image_count += 1
render_job = None
else:
print('No renderjob')
fin_msg = pickle.dumps("Fin")
send_msg(conn, fin_msg)
except:
print('Failed, Closing socket')
s.close()
@@ -1,79 +0,0 @@
import random
import socket
import pickle
import math
import struct
def send_msg(sock, msg):
# Prefix each message with a 4-byte length (network byte order)
msg = struct.pack('>I', len(msg)) + msg
sock.sendall(msg)
def recv_msg(sock):
# Read message length and unpack it into an integer
raw_msglen = recvall(sock, 4)
if not raw_msglen:
return None
msglen = struct.unpack('>I', raw_msglen)[0]
# Read the message data
return recvall(sock, msglen)
def recvall(sock, n):
# Helper function to recv n bytes or return None if EOF is hit
data = bytearray()
while len(data) < n:
packet = sock.recv(n - len(data))
if not packet:
return None
data.extend(packet)
return data
# Generates random values for blendshape predictions and file names.
predictions = []
for i in range(200):
prediction = []
for j in range(72):
blendshape = round(random.uniform(0, 1), 3)
prediction.append(blendshape)
#prediction.append(f'{i}.png')
predictions.append(prediction)
print('generated blendshapes')
# Establish a connection to the render server
HOST = 'localhost'
PORT = 50000
HEADERSIZE = 10
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
# Send predicted values
send_msg(s, pickle.dumps(predictions))
# Confirmation from the server that blendshapes were recieved
ack = pickle.loads(recv_msg(s))
print(ack)
# Wait on finished renders
# Render Server notifies that rendering has completed
fin = pickle.loads(recv_msg(s))
print(fin)
@@ -1,21 +0,0 @@
import os
import shutil
import threading
# specify the directories
source_dir = "X:\\Documents\\GitHub\\ProjectBabble\\datageneration\\training\\lipimages"
destination_dir = "C:\\Users\\epicm\\Desktop\\BabbleTraining\\lipimages"
# get a list of all files in the source directory
files = os.listdir(source_dir)
# loop through each file and copy it to the destination directory
for file_name in files:
# construct the full path to the file
source_file = os.path.join(source_dir, file_name)
destination_file = os.path.join(destination_dir, file_name)
# copy the file to the destination directory
shutil.copy2(source_file, destination_file)
print("Files copied successfully!")
Binary file not shown.
-533
View File
@@ -1,533 +0,0 @@
'''
Dataset Generation Script made with the tears of Rames The Generic#3540
Randomizes the lighting setup, camera position, background, and blendshapes.
Each image also gets a corrisponding csv file with the generated blendshapes.
Blendfile with MB_Lab_Base collection can be found at:
https://drive.google.com/drive/folders/1JGOK7CJwX83kSTxbHzlhOmTmYGHx_Zpq?usp=sharing
How to use:
1. Create a character with the MBLab plugin, randomize the facial features and finalize
2. Append the MB_Lab_Base collection to the Scene Collection
3. Rename the root of the character to MBLab_SK and the body mesh like so:
Possible mesh naming schemees for automatic blendshape generation (WIP):
MBLab_(Race)_(Sex)
Race:
Afro: AF
Asian: AS
Caucasian: CA
Latino: LA
Sex:
Female: F
Male: M
Ex: MBLab_AS_M
4. Add a Copy Location modifier to the CameraRig and set the Target to MBLab_SK and
the newly created bone slot to head
5. Sent the end frame, file output path, and run the script with the play button.
'''
import bpy
import math
import random
import csv
from time import sleep
cheekPuff = 'Expressions_mouthInflated_max'
cheekSquint_L = 'cheekSquint_L'
cheekSquint_R = 'cheekSquint_R'
noseSneer_L = 'Expressions_cheekSneerL_max'
noseSneer_R = 'Expressions_cheekSneerR_max'
jawOpen = 'Expressions_mouthOpenLarge_max'
jawForward = 'Expressions_jawOut_max'
jawLeft = 'Expressions_jawHoriz_max'
jawRight = 'Expressions_jawHoriz_min'
mouthFunnel = 'Expressions_mouthOpenO_max'
mouthPucker = 'Expressions_mouthOpenLarge_min'
mouthLeft = 'Expressions_mouthHoriz_max'
mouthRight = 'Expressions_mouthHoriz_min'
mouthRollUpper = 'Expressions_mouthLowerOut_min'
mouthRollLower = 'Expressions_mouthLowerOut_max'
mouthShrugUpper = 'mouthShrugUpper'
mouthShrugLower = 'mouthShrugLower'
mouthClose = 'Expressions_mouthSmileOpen2_min'
mouthSmile_L = 'Expressions_mouthSmileL_max'
mouthSmile_R = 'Expressions_mouthSmileR_max'
mouthFrown_L = 'Expressions_mouthSmile_min'
mouthFrown_R = 'Expressions_mouthSmile_min'
mouthDimple_L = 'mouthDimple_L'
mouthDimple_R = 'mouthDimple_R'
mouthUpperUp_L = 'mouthUpperUp_L'
mouthUpperUp_R = 'mouthUpperUp_R'
mouthLowerDown_L = 'mouthLowerDown_L'
mouthLowerDown_R = 'mouthLowerDown_R'
mouthPress_L = 'mouthPress_L'
mouthPress_R = 'mouthPress_R'
mouthStretch_L = 'mouthStretch_L'
mouthStretch_R = 'mouthStretch_R'
tongueOut = 'Expressions_tongueOut_max'
lables_name = ['cheekPuff','cheekSquint_L','cheekSquint_R','noseSneer_L','noseSneer_R','jawOpen',
'jawForward','jawLeft','jawRight','mouthFunnel','mouthPucker','mouthLeft','mouthRight',
'mouthRollUpper','mouthRollLower','mouthShrugUpper','mouthShrugLower','mouthClose',
'mouthSmile_L','mouthSmile_R','mouthFrown_L','mouthFrown_R','mouthDimple_L','mouthDimple_R',
'mouthUpperUp_L','mouthUpperUp_R','mouthLowerDown_L','mouthLowerDown_R','mouthPress_L',
'mouthPress_R','mouthStretch_L','mouthStretch_R','tongueOut','filename']
def get_objs(collection): # Returns all meshes in a collection
collection = bpy.data.collections[collection]
for obj in collection.all_objects:
ob = bpy.data.objects[str(obj.name)]
if ob.type == 'MESH':
mesh_name = obj.name
#shapekey_name = shapekey_name.split()
return mesh_name
def copy_all_shape_keys(source, dest): # Transfers Blendshapes from one mesh to another assuming they have identical geometry
bpy.data.objects[source].select_set(True)
bpy.data.objects[dest].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects[dest]
source = bpy.data.objects[source]
dest = bpy.data.objects[dest]
if len(bpy.context.selected_objects) == 2:
for v in bpy.context.selected_objects:
if v is not dest:
source = v
break
print("Source: ", source.name)
print("Destination: ", dest.name)
if source.data.shape_keys is None:
print("Source object has no shape keys!")
else:
for idx in range(1, len(source.data.shape_keys.key_blocks)):
source.active_shape_key_index = idx
print("Copying Shape Key - ", source.active_shape_key.name)
bpy.ops.object.shape_key_transfer()
bpy.context.object.show_only_shape_key = False
print("Disabling show_only_shape_key")
else:
print('No selected Objects')
def select_model_armature():
for obj in bpy.data.collections['MB_LAB_Character'].all_objects:
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
return obj
def select_camera_armature():
obj = bpy.data_objects['CameraRig'].select_set(True)
bpy.context.view_layer.objects.active = obj
return obj
def zero_camera(): # Sets the camera rig to a known rest pose.
ob = bpy.data.objects['CameraRig']
bpy.context.view_layer.objects.active = ob
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['Camera']
pbone.rotation_euler = (0, 0, 0)
pbone = ob.pose.bones['CameraArm']
pbone.rotation_euler = (0, 0, 0)
pbone = ob.pose.bones['MBLabHead']
pbone.rotation_euler = (0, 0, 0)
bpy.ops.object.mode_set(mode='OBJECT')
def zero_lights(): # Sets the rotation of all lights to 0
bpy.ops.object.mode_set(mode='OBJECT')
ob = bpy.data.objects['Light1']
ob.rotation_euler = (0, 0, 0)
ob = bpy.data.objects['Light2']
ob.rotation_euler = (0, 0, 0)
ob = bpy.data.objects['Light3']
ob.rotation_euler = (0, 0, 0)
def zero_bg(): # Sets the Z position of all backgrounds to 0
for i in range(14):
ob = bpy.data.objects['BG' + str(i + 1)]
ob.location[1] = 0
def set_index(shapekey_name, shapekey_value, setShapes): # Checks for blendshape name to set the randomized value in a list
if str(shapekey_name) == cheekPuff:
setShapes[0] = shapekey_value
if str(shapekey_name) == cheekSquint_L:
setShapes[1] = shapekey_value
if str(shapekey_name) == cheekSquint_R:
setShapes[2] = shapekey_value
if str(shapekey_name) == noseSneer_L:
setShapes[3] = shapekey_value
if str(shapekey_name) == noseSneer_R:
setShapes[4] = shapekey_value
if str(shapekey_name) == jawOpen:
setShapes[5] = shapekey_value
if str(shapekey_name) == jawForward:
setShapes[6] = shapekey_value
if str(shapekey_name) == jawLeft:
setShapes[7] = shapekey_value
if str(shapekey_name) == jawRight:
setShapes[8] = shapekey_value
if str(shapekey_name) == mouthFunnel:
setShapes[9] = shapekey_value
if str(shapekey_name) == mouthPucker:
setShapes[10] = shapekey_value
if str(shapekey_name) == mouthLeft:
setShapes[11] = shapekey_value
if str(shapekey_name) == mouthRight:
setShapes[12] = shapekey_value
if str(shapekey_name) == mouthRollUpper:
setShapes[13] = shapekey_value
if str(shapekey_name) == mouthRollLower:
setShapes[14] = shapekey_value
if str(shapekey_name) == mouthShrugUpper:
setShapes[15] = shapekey_value
if str(shapekey_name) == mouthShrugLower:
setShapes[16] = shapekey_value
if str(shapekey_name) == mouthClose:
setShapes[17] = shapekey_value
if str(shapekey_name) == mouthSmile_L:
setShapes[18] = shapekey_value
if str(shapekey_name) == mouthSmile_R:
setShapes[19] = shapekey_value
if str(shapekey_name) == mouthFrown_L:
setShapes[20] = shapekey_value
if str(shapekey_name) == mouthFrown_R:
setShapes[21] = shapekey_value
if str(shapekey_name) == mouthDimple_L:
setShapes[22] = shapekey_value
if str(shapekey_name) == mouthDimple_R:
setShapes[23] = shapekey_value
if str(shapekey_name) == mouthUpperUp_L:
setShapes[24] = shapekey_value
if str(shapekey_name) == mouthUpperUp_R:
setShapes[25] = shapekey_value
if str(shapekey_name) == mouthLowerDown_L:
setShapes[26] = shapekey_value
if str(shapekey_name) == mouthLowerDown_R:
setShapes[27] = shapekey_value
if str(shapekey_name) == mouthPress_L:
setShapes[28] = shapekey_value
if str(shapekey_name) == mouthPress_R:
setShapes[29] = shapekey_value
if str(shapekey_name) == mouthStretch_L:
setShapes[30] = shapekey_value
if str(shapekey_name) == mouthStretch_R:
setShapes[31] = shapekey_value
if str(shapekey_name) == tongueOut:
setShapes[32] = shapekey_value
def rand_shape(shapekey_name, chance1, chance2, shape, setShapes, range1 = 0, range2 = 1): # Randomize specified blendshape
if random.randint(chance1, chance2) == 0:
if (shape.name == shapekey_name):
shape.slider_min = -1
shape.value=round(random.uniform(range1, range2), 3)
if range1 < 0:
print(str(shape.value))
set_index(shapekey_name, (-1 * round(shape.value, 3)), setShapes)
else:
set_index(shapekey_name, round(shape.value, 3), setShapes)
def zero_blendshapes(dest): # Set all blendshape values to 0
ob = bpy.data.objects[dest]
for shape in ob.data.shape_keys.key_blocks:
shape.value=0
def combo1(ob, setShapes): # Different manually selected combinations of blenshapes that won't create unnatural results
for shape in ob.data.shape_keys.key_blocks:
rand_shape(mouthFunnel, 0, 1, shape, setShapes)
rand_shape(mouthRollUpper, 0, 1, shape, setShapes)
rand_shape(mouthRollLower, 0, 1, shape, setShapes)
rand_shape(mouthUpperUp_L, 0, 1, shape, setShapes)
rand_shape(mouthUpperUp_R, 0, 1, shape, setShapes)
rand_shape(mouthLowerDown_L, 0, 1, shape, setShapes)
rand_shape(mouthLowerDown_R, 0, 1, shape, setShapes)
rand_shape(tongueOut, 0, 4, shape, setShapes)
def combo2(ob, setShapes):
for shape in ob.data.shape_keys.key_blocks:
rand_shape(jawForward, 0, 1, shape, setShapes)
rand_shape(jawLeft, 0, 1, shape, setShapes)
rand_shape(jawRight, 0, 1, shape, setShapes)
rand_shape(mouthPucker, 0, 2, shape, setShapes)
rand_shape(mouthLeft, 0, 1, shape, setShapes)
rand_shape(mouthRight, 0, 1, shape, setShapes)
if random.randint(0, 3) == 0:
rand_shape(mouthShrugUpper, 0, 0, shape, setShapes)
rand_shape(mouthShrugLower, 0, 0, shape, setShapes)
else:
if random.randint(0, 1) == 0:
rand_shape(mouthSmile_L, 0, 1, shape, setShapes)
rand_shape(mouthSmile_R, 0, 1, shape, setShapes)
else:
rand_shape(mouthFrown_L, 0, 1, shape, setShapes, -1, 0)
rand_shape(mouthFrown_R, 0, 1, shape, setShapes, -1, 0)
rand_shape(mouthClose, 0, 1, shape, setShapes)
rand_shape(mouthDimple_L, 0, 1, shape, setShapes)
rand_shape(mouthDimple_R, 0, 1, shape, setShapes)
rand_shape(mouthPress_L, 0, 1, shape, setShapes)
rand_shape(mouthPress_R, 0, 1, shape, setShapes)
rand_shape(mouthStretch_L, 0, 1, shape, setShapes)
rand_shape(mouthStretch_R, 0, 1, shape, setShapes)
def combo3(ob, setShapes):
for shape in ob.data.shape_keys.key_blocks:
rand_shape(mouthFunnel, 0, 2, shape, setShapes)
rand_shape(mouthRollUpper, 0, 1, shape, setShapes)
rand_shape(mouthRollLower, 0, 1, shape, setShapes)
rand_shape(mouthUpperUp_L, 0, 1, shape, setShapes)
rand_shape(mouthUpperUp_R, 0, 1, shape, setShapes)
rand_shape(mouthLowerDown_L, 0, 1, shape, setShapes)
rand_shape(mouthLowerDown_R, 0, 1, shape, setShapes)
if random.randint(0, 2) == 0:
rand_shape(jawOpen, 0, 0, shape, setShapes)
rand_shape(tongueOut, 0, 0, shape, setShapes)
else:
rand_shape(mouthClose, 0, 1, shape, setShapes)
def combo4(ob, setShapes):
for shape in ob.data.shape_keys.key_blocks:
rand_shape(cheekPuff, 0, 1, shape, setShapes)
rand_shape(noseSneer_L, 0, 1, shape, setShapes)
rand_shape(noseSneer_R, 0, 1, shape, setShapes)
#rand_shape(noseSneer_L, 0, 2, shape, setShapes)
#rand_shape(noseSneer_R, 0, 2, shape, setShapes)
def combo5(ob, setShapes):
for shape in ob.data.shape_keys.key_blocks:
rand_shape(mouthFunnel, 0, 2, shape, setShapes)
rand_shape(mouthSmile_L, 0, 1, shape, setShapes)
rand_shape(mouthSmile_R, 0, 1, shape, setShapes)
def combo6(ob, setShapes):
for shape in ob.data.shape_keys.key_blocks:
if random.randint(0, 1) == 0:
if random.randint(0, 1) == 0:
rand_shape(mouthSmile_L, 0, 1, shape, setShapes)
rand_shape(mouthSmile_R, 0, 1, shape, setShapes)
else:
rand_shape(mouthPress_L, 0, 1, shape, setShapes)
rand_shape(mouthPress_R, 0, 1, shape, setShapes)
else:
rand_shape(mouthFrown_L, 0, 1, shape, setShapes)
rand_shape(mouthFrown_R, 0, 1, shape, setShapes)
rand_shape(jawOpen, 0, 1, shape, setShapes)
s=bpy.context.scene
s.render.resolution_x = 256
s.render.resolution_y = 256
def main(dest):
setShapes = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,'filename']
# Applies random rotation to the camera rig
ob = bpy.data.cameras['Camera'] # Camera Focallength
ob.lens = round(random.uniform(26, 34), 2)
ob = bpy.data.scenes["Scene"].node_tree.nodes["Lens Distortion"].inputs[1] # Compositer Lens Distortion
ob.default_value = random.uniform(0.01, 0.27)
# Camera
ob = bpy.data.objects['CameraRig'] # The thing we're talking about
bpy.context.view_layer.objects.active = ob # Click it (make it the active selection)
bpy.ops.object.mode_set(mode='POSE') # Go into pose mode
pbone = ob.pose.bones['Camera'] # Select the bone to rotate
pbone.rotation_mode = 'XYZ' # Set rotations to euler because quaternions are an alien technology
axis = 'Z' # Select rotaion axis (local)
angle = random.uniform(-5, 7)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle)) # Do the rotation
# Camera Arm
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['CameraArm']
pbone.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(-4, 4)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle))
# MLabHead
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['MBLabHead']
pbone.rotation_mode = 'XYZ'
axis = 'Y'
angle = random.uniform(-4, 4)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle))
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['MBLabHead']
pbone.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(-4, 4)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle))
bpy.ops.object.mode_set(mode='OBJECT')
# Applies random rotation to the 3 scene lights
ob = bpy.data.objects['Light1']
ob.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(0, 360)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
axis = 'Y'
angle = random.uniform(-40, 40)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
ob = bpy.data.objects['Light2']
ob.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(0, 360)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
axis = 'Y'
angle = random.uniform(-40, 40)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
ob = bpy.data.objects['Light3']
ob.rotation_mode = 'XYZ' # Set rotations to euler because quaternions are an alien technology
axis = 'Z'
angle = random.uniform(0, 360)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
axis = 'Y'
angle = random.uniform(-40, 40)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
# Background Randomization
ob = bpy.data.objects['BG' + str(random.randint(1, 14))]
ob.location[1] = -0.1
######## Blendshape Randomization ########
ob = bpy.data.objects[dest]
#for shape in ob.data.shape_keys.key_blocks:
selector = random.randint(0, 5)
if selector == 0:
combo1(ob, setShapes)
if selector == 1:
combo2(ob, setShapes)
if selector == 2:
combo3(ob, setShapes)
if selector == 3:
combo4(ob, setShapes)
if selector == 4:
combo5(ob, setShapes)
if selector == 5:
combo6(ob, setShapes)
return setShapes
#bpy.app.handlers.frame_change_post.append(main)
bpy.ops.wm.console_toggle()
print("Start Transfer")
dest = get_objs('MB_LAB_Character')
source = None
if dest == 'MBLab_CA_M':
source = 'MBLabBase_CA_M'
if dest == 'MBLab_CA_F':
source = 'MBLabBase_CA_F'
if dest == 'MBLab_AF_M':
source = 'MBLabBase_AF_M'
if dest == 'MBLab_AF_F':
source = 'MBLabBase_AF_F'
if dest == 'MBLab_AS_M':
source = 'MBLabBase_AS_M'
if dest == 'MBLab_AS_F':
source = 'MBLabBase_AS_F'
if dest == 'MBLab_LA_M':
source = 'MBLabBase_LA_M'
if dest == 'MBLab_LA_F':
source = 'MBLabBase_LA_F'
copy_all_shape_keys(source, dest)
print("End Transfer")
for i in range(s.frame_start,s.frame_end): # Rendering stuff
path = "C:\\Users\\epicm\\Documents\\GitHub\\ProjectBabble\\datageneration\\Output\\"
#for i in range(1):
s.frame_current = i
imagename = str(s.frame_current ).zfill(3)
zero_camera()
zero_lights()
zero_blendshapes(dest)
filename = str(imagename + '.csv')
img_filename = str(imagename + '.png')
data = main(dest)
data[33] = img_filename
joined_string = ','.join(map(str, data))
lables = ','.join(map(str, lables_name))
with open(path + filename, 'w') as file:
file.write('{}\n{}\n'.format(lables,joined_string))
file.close()
print(data)
sleep(.150) # Without the sleep the blendshapes become "out of sync" with the images, I don't know the cause of it is so there it is
s.render.filepath = (
path
+ imagename
)
bpy.ops.render.render( #{'dict': "override"},
#'INVOKE_DEFAULT',
False,
animation=False,
write_still=True
)
# Do whatever you want that can't be done normally here (Changing resolution during animation, etc...)
-304
View File
@@ -1,304 +0,0 @@
# For use with the RenderSceneV2 Blender project
################################
# Blender will appear to hang when run
# That's just how blender runs scripts :shrug:
################################
import bpy
import math
import random
import socket
import pickle
import struct
from time import sleep
# Set path for enviroment
path = "C:\\Users\\epicm\\Documents\\GitHub\\ProjectBabble\\datageneration\\Output\\"
res_x = 800
res_y = 800
blendshape_list = (
'eyeLeftSqueeze',
'eyeRightSqueeze',
'Expressions_eyeSquintL_max',
'Expressions_eyeSquintR_max',
'Expressions_eyeClosedL_max',
'eyeLookInLeft',
'eyeLookOutLeft',
'eyeLookUpLeft',
'eyeLookDownLeft',
'Expressions_eyeClosedR_max',
'eyeLookOutRight',
'eyeLookInRight',
'eyeLookUpRight',
'eyeLookDownRight',
'Expressions_eyeClosedL_min',
'Expressions_eyeClosedR_min',
'eyesDilationLeft',
'eyesDilationRight',
'eyesConstrictLeft',
'eyesConstrictRight',
'browInnerUpLeft',
'browInnerUpRight',
'Expressions_browOutVertL_min',
'Expressions_browOutVertR_min',
'Expressions_browOutVertL_max',
'Expressions_browOutVertR_max',
'Expressions_eyeSquintL_max',
'Expressions_eyeSquintR_max',
'cheekPuffLeft',
'cheekPuffRight',
'Expressions_cheekSneerL_max',
'Expressions_cheekSneerR_max',
'Expressions_mouthInflated_min',
'lipSuckLeftBottom',
'lipSuckLeftTop',
'lipSuckRightBottom',
'lipSuckRightTop',
'Expressions_mouthOpen_max',
'Expressions_jawHoriz_max',
'Expressions_jawHoriz_min',
'Expressions_jawOut_max',
'Expressions_mouthOpenO_min',
'Expressions_mouthOpenO_max',
'Expressions_mouthOpenLarge_min',
'mouthClose',
'mouthApeShape',
'Expressions_mouthHoriz_max',
'Expressions_mouthHoriz_min',
'Expressions_mouthSmileL_max',
'Expressions_mouthSmileR_max',
'mouthFrownLeft',
'mouthFrownRight',
'mouthDimpleLeft',
'mouthDimpleRight',
'mouthRollUpper',
'Expressions_mouthLowerOut_min',
'mouthShrugUpper',
'mouthLowerOverturn',
'mouthShrugLower',
'mouthUpperUpLeft',
'mouthUpperUpRight',
'mouthLowerDownLeft',
'mouthLowerDownRight',
'mouthPressLeft',
'mouthPressRight',
'mouthStretchLeft',
'mouthStretchRight',
'Expressions_tongueOut_max',
'Expressions_tongueVert_min',
'Expressions_tongueVert_max',
'Expressions_tongueHoriz_max',
'Expressions_tongueHoriz_min',
'tongueRoll'
)
def send_msg(sock, msg):
# Prefix each message with a 4-byte length (network byte order)
msg = struct.pack('>I', len(msg)) + msg
sock.sendall(msg)
def recv_msg(sock):
# Read message length and unpack it into an integer
raw_msglen = recvall(sock, 4)
if not raw_msglen:
return None
msglen = struct.unpack('>I', raw_msglen)[0]
# Read the message data
return recvall(sock, msglen)
def recvall(sock, n):
# Helper function to recv n bytes or return None if EOF is hit
data = bytearray()
while len(data) < n:
packet = sock.recv(n - len(data))
if not packet:
return None
data.extend(packet)
return data
def zero_blendshapes(ob): # Resets all Blendshapes to 0
for shape in ob.data.shape_keys.key_blocks:
shape.value=0
def get_set_values(ob, blendshape_list, set_list): # Debug function to get the value of blendshapes
for shape in ob.data.shape_keys.key_blocks:
if shape.name in blendshape_list:
set_list.append(shape.value)
def zero_bg(): # Sets the Z position of all backgrounds to 0
for i in range(14):
ob = bpy.data.objects['BG' + str(i + 1)]
ob.location[1] = 0
def randomize_bg(): # Moves a random background plane to be in view
ob = bpy.data.objects['BG' + str(random.randint(1, 14))]
ob.location[1] = -0.1
def zero_camera(): # Sets the camera rig to a known rest pose.
ob = bpy.data.objects['CameraRig']
bpy.context.view_layer.objects.active = ob
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['Camera']
pbone.rotation_euler = (0, 0, 0)
pbone = ob.pose.bones['CameraArm']
pbone.rotation_euler = (0, 0, 0)
pbone = ob.pose.bones['MBLabHead']
pbone.rotation_euler = (0, 0, 0)
bpy.ops.object.mode_set(mode='OBJECT')
def randomize_scene(): # Randomizes various scene parameters like lighting and camera focal length
ob = bpy.data.cameras['Camera']
ob.lens = round(random.uniform(22, 30), 2)
ob = bpy.data.scenes["Scene"].node_tree.nodes["Lens Distortion"].inputs[1] # Compositer Lens Distortion
ob.default_value = random.uniform(0.01, 0.27)
# Camera
ob = bpy.data.objects['CameraRig'] # The thing we're talking about
bpy.context.view_layer.objects.active = ob # Click it (make it the active selection)
bpy.ops.object.mode_set(mode='POSE') # Go into pose mode
pbone = ob.pose.bones['Camera'] # Select the bone to rotate
pbone.rotation_mode = 'XYZ' # Set rotations to euler because quaternions are an alien technology
axis = 'Z' # Select rotaion axis (local)
angle = random.uniform(-2, 3)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle)) # Do the rotation
# Camera Arm
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['CameraArm']
pbone.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(-2, 2)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle))
# MLabHead
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['MBLabHead']
pbone.rotation_mode = 'XYZ'
axis = 'Y'
angle = random.uniform(-3, 3)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle))
bpy.ops.object.mode_set(mode='POSE')
pbone = ob.pose.bones['MBLabHead']
pbone.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(-3, 3)
pbone.rotation_euler.rotate_axis(axis, math.radians(angle))
bpy.ops.object.mode_set(mode='OBJECT')
# Applies random rotation to the 3 scene lights
ob = bpy.data.objects['Light1']
ob.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(0, 360)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
axis = 'Y'
angle = random.uniform(-40, 40)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
ob = bpy.data.objects['Light2']
ob.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(0, 360)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
axis = 'Y'
angle = random.uniform(-40, 40)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
ob = bpy.data.objects['Light3']
ob.rotation_mode = 'XYZ'
axis = 'Z'
angle = random.uniform(0, 360)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
axis = 'Y'
angle = random.uniform(-40, 40)
ob.rotation_euler.rotate_axis(axis, math.radians(angle))
def set_shape(shapekey_name, ob, value): # Set a value to a blendshape
ob.data.shape_keys.key_blocks[shapekey_name].value = value
bpy.ops.wm.console_toggle() # Toggle the system console
# Setup Connection
HOST = 'localhost'
PORT = 50000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(5)
scene=bpy.context.scene
scene.render.resolution_x = res_x
scene.render.resolution_y = res_y
try:
while True: # Recieve Blendshape List
conn, (address, port) = s.accept()
data = recv_msg(conn)
render_job = pickle.loads(data)
print(f'Got Blendshapes containing {render_job}')
# Acknowledge blendshape list
ack_msg = pickle.dumps('Got Blendshape Lists')
send_msg(conn, ack_msg)
ob = bpy.data.objects['MBLab_CA_M']
print('Set Object')
set_list = []
if render_job:
print('Starting Render')
image_count = 0
for i in render_job:
c = 0
zero_camera()
zero_blendshapes(ob)
zero_bg()
for value in i:
#print(f'Setting Blendshape of: {blendshape_list[c]}')
set_shape(blendshape_list[c], ob, value)
c += 1
get_set_values(ob, blendshape_list, set_list)
print('Started Blender Render Process')
randomize_bg()
randomize_scene()
# Blender render stuff
imagename = str(image_count).zfill(3)
img_filename = str(imagename + '.png')
scene.render.filepath = (
path
+ imagename
)
bpy.ops.render.render( #{'dict': "override"},
#'INVOKE_DEFAULT',
False,
animation=False,
write_still=True
)
image_count += 1
render_job = None
else:
print('No renderjob')
fin_msg = pickle.dumps("Fin")
send_msg(conn, fin_msg)
except:
print('Failed, Closing socket')
s.close()
@@ -1,79 +0,0 @@
import random
import socket
import pickle
import math
import struct
def send_msg(sock, msg):
# Prefix each message with a 4-byte length (network byte order)
msg = struct.pack('>I', len(msg)) + msg
sock.sendall(msg)
def recv_msg(sock):
# Read message length and unpack it into an integer
raw_msglen = recvall(sock, 4)
if not raw_msglen:
return None
msglen = struct.unpack('>I', raw_msglen)[0]
# Read the message data
return recvall(sock, msglen)
def recvall(sock, n):
# Helper function to recv n bytes or return None if EOF is hit
data = bytearray()
while len(data) < n:
packet = sock.recv(n - len(data))
if not packet:
return None
data.extend(packet)
return data
# Generates random values for blendshape predictions and file names.
predictions = []
for i in range(200):
prediction = []
for j in range(72):
blendshape = round(random.uniform(0, 1), 3)
prediction.append(blendshape)
#prediction.append(f'{i}.png')
predictions.append(prediction)
print('generated blendshapes')
# Establish a connection to the render server
HOST = 'localhost'
PORT = 50000
HEADERSIZE = 10
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
# Send predicted values
send_msg(s, pickle.dumps(predictions))
# Confirmation from the server that blendshapes were recieved
ack = pickle.loads(recv_msg(s))
print(ack)
# Wait on finished renders
# Render Server notifies that rendering has completed
fin = pickle.loads(recv_msg(s))
print(fin)