I am a highschool student working at a college's engineering department for the summer. I just began working in blender and have intermediate knowledge of python. Could anyone share a script that:
Read a .csv file of xyz coordinates and a .csv file of quaternion coordinates into python.
Turn these points into some type of curve or path that an object can then follow to model the path the coordinates map out
My .csv files
(around 250 lines) have three and four points on each line. All the coordinates would need to be floats on account that they are decimals.
Here you can find both example .csv files: https://gist.github.com/anonymous/a1a4cbe6e959ac14e5af to play with. My code looks like:
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'
# os.path.join takes care of joining folder with filename.
positions = os.path.join(base_folder, 'xyzposition.csv')
quaternions = os.path.join(base_folder, 'quaternions.csv')
set_keyframes(bpy.context.active_object, positions, quaternions)