Skip to content

Commit

Permalink
Line 24 head_movement=False to speed up data receiving in Blender
Browse files Browse the repository at this point in the history
  • Loading branch information
NumesSanguis committed Oct 27, 2018
1 parent ff071a3 commit 079da24
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions blender/facsvatar_zeromq.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class FACSvatarZeroMQ(bpy.types.Operator):

_timer = None

def __init__(self, address='127.0.0.1', port='5572'):
def __init__(self, address='127.0.0.1', port='5572', head_movement=True):
print("FACSvatar ZeroMQ initialising...")

self.head_movement = head_movement

# init ZeroMQ subscriber
url = "tcp://{}:{}".format(address, port)
ctx = zmq.Context.instance()
Expand Down Expand Up @@ -109,28 +111,32 @@ def modal(self, context, event):
self.find_MBLabModel()

# # set pose only if pose data is available and not empty
# if 'pose' in msg[2] and msg[2]['pose']:
# # set head rotation
# if len(self.head_bones) == 2:
# bpy.context.scene.objects.active = self.mb_obj
# bpy.ops.object.mode_set(mode='POSE') # mode for bone rotation
#
# # for pose_name in enumerate(msg_json['data']['head_pose']):
# pose_head = msg[2]['pose']
# self.rotate_head_bones(0, pose_head['pose_Rx']) # pitch
# self.rotate_head_bones(1, pose_head['pose_Ry'], -1) # jaw
# self.rotate_head_bones(2, pose_head['pose_Rz'], -1) # roll
#
# # set key frames
# bpy.ops.object.mode_set(mode='OBJECT') # mode for key frame
# self.head_bones[0].keyframe_insert(data_path="rotation_euler", frame=self.frame)
# self.head_bones[1].keyframe_insert(data_path="rotation_euler", frame=self.frame)
#
# else:
# print("Head bone and neck bone not found")
#
# else:
# print("No pose data found")
if self.head_movement:
if 'pose' in msg[2] and msg[2]['pose']:
# set head rotation
if len(self.head_bones) == 2:
bpy.context.scene.objects.active = self.mb_obj
bpy.ops.object.mode_set(mode='POSE') # mode for bone rotation

# for pose_name in enumerate(msg_json['data']['head_pose']):
pose_head = msg[2]['pose']
self.rotate_head_bones(0, pose_head['pose_Rx']) # pitch
self.rotate_head_bones(1, pose_head['pose_Ry'], -1) # jaw
self.rotate_head_bones(2, pose_head['pose_Rz'], -1) # roll

# set key frames
bpy.ops.object.mode_set(mode='OBJECT') # mode for key frame
self.head_bones[0].keyframe_insert(data_path="rotation_euler", frame=self.frame)
self.head_bones[1].keyframe_insert(data_path="rotation_euler", frame=self.frame)

else:
print("Head bone and neck bone not found")

else:
print("No pose data found")

else:
print("Head movement data ignored")

# set blendshapes only if blendshape data is available and not empty
if 'blendshapes' in msg[2] and msg[2]['blendshapes']:
Expand Down

0 comments on commit 079da24

Please sign in to comment.