Last active
August 29, 2015 14:27
-
-
Save zeffii/81ba97b5d5253cee8784 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
import os | |
import bpy | |
import csv | |
from mathutils import Vector | |
def set_keyframes(obj, loc_txt, quat_txt): | |
obj.rotation_mode = 'QUATERNION' | |
with open(loc_txt, 'r') as loc_fh: | |
with open(quat_txt, 'r') as quat_fh: | |
r_loc = csv.reader(loc_fh, delimiter=',') | |
r_quat = csv.reader(quat_fh, delimiter=',') | |
i = 0 | |
for row_loc in r_loc: | |
row_quat = r_quat.__next__() | |
row_loc = [ float(x.strip()) for x in row_loc[:3]] | |
row_quat = [ float(x.strip()) for x in row_quat[:4]] | |
fr = 10+2*i | |
obj.location = Vector(row_loc) * 10 | |
obj.rotation_quaternion = row_quat | |
obj.keyframe_insert(data_path="location", frame=fr) | |
obj.keyframe_insert(data_path="rotation_quaternion", frame=fr) | |
i += 1 | |
#base_folder = '/Users/sharonshorak/Desktop/ARYA_PYTHON' | |
base_folder = '/home/zeffii/Desktop/ARYA_PYTHON' # < you just change this to the right path. | |
# os.path.join takes care of the forward slashes. | |
positions = os.path.join(base_folder, 'xyzposition.csv') | |
quaternions = os.path.join(base_folder, 'quaternions.csv') | |
set_keyframes(bpy.context.active_object, positions, quaternions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment