Last active
June 2, 2020 11:19
-
-
Save iCyP/abdcd4f5e0a275c2b22aedcf35444a2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#UNDER MIT LINCENCE @ ICYP 2020 | |
#bone roll must be 0 | |
import csv | |
import bpy | |
from math import radians | |
from mathutils import Vector,Euler,Quaternion | |
with open("C:\\Users\\hornt\\Downloads\\michicon_motion_20200601_123822.csv",newline="") as byebyecsv: | |
motionreader = csv.reader(byebyecsv) | |
names = None | |
for row in motionreader: | |
if names == None: | |
names = row | |
bonenames = [ names[i][0].lower() + names[i][1:] for i in range(len(row))] | |
continue | |
for col,i in zip(row,range(len(row))): | |
xyz = col.split() | |
if i==0: | |
bpy.ops.anim.keyframe_insert_menu(type='Rotation') | |
bpy.context.scene.frame_current = float(xyz[0])*60 | |
elif i ==1: | |
bpy.data.objects['skelton'].pose.bones["Hips"].location = [float(f)/1000 for f in xyz] | |
bpy.ops.anim.keyframe_insert_menu(type='Location') | |
else: | |
bonename = bpy.data.armatures["Armature"][bonenames[i]] | |
b = bpy.data.objects['skelton'].pose.bones[bonename] | |
a = Euler(Vector( | |
[ | |
radians(+float(xyz[0])), | |
radians(+float(xyz[2])), | |
radians(-float(xyz[1])) | |
] | |
)).to_quaternion() | |
b.rotation_quaternion = a | |
if True: | |
b.rotation_quaternion = (bpy.data.armatures['Armature'].bones[bonename].matrix_local.inverted_safe() \ | |
@ b.rotation_quaternion.to_matrix().to_4x4() \ | |
@ bpy.data.armatures['Armature'].bones[bonename].matrix_local | |
).to_quaternion() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment