Hi all,
I am working with Blender 2.63 to animate a bipedal robot. I have no trouble animating it by hand, however my goal is to be able to import specific 3D data sets with time (or frames) to produce an animation out of this walking data (from Matlab). This data is in a .txt file, but can be converted to whatever format is needed. I have found an old script to perform this action, however it is from Blender 2.49, so the script is incompatible with 2.63. Is there a script out there that can perform this action in the latest Blender? If not, I have also included the old code below in the hopes that someone could help me convert it.
Thanks,
Dean
#!BPY
"""
Name: '01_My_Export__KeyData'
Blender: 249
Group: 'Export'
Tooltip: 'Export Anim Key Data'
"""
import Blender
import bpy
from Blender import Armature, Mathutils, Ipo
# Exports animation key data into a text file. Key data has the following format
# <frame>,<bone name>,<x-loc>,<y-loc>,<z-loc>,<x-rot>,<y-rot>,<z-rot>
def get_keys():
f = open('A:\_EXPORT_keys.txt', 'w') ###### file for export data ######
arm = Blender.Object.Get('Scene Root')
mypose = arm.getPose()
bones_ipo = arm.getAction().getAllChannelIpos()
keydata = []
# iterate through all interesting bones
for bone in ( 'Bip01 Op1.R', 'Bip01 Op1.L', 'Bip01 Op2.R', 'Bip01 Op2.L' ):
# for bone, bonename in ( mypose.bones.items() ):
# for bone in ( 'Bip01 Head', 'Bip01 Hand.L', 'Bip01 Hand.R', 'Bip01 UpperArm.L', 'Bip01 UpperArm.R', 'Bip01 ForearmTwist.L', 'Bip01 ForearmTwist.R', \
# 'Bip01 UpperArmTwist.L', 'Bip01 UpperArmTwist.R', 'Bip01 Forearm.L', 'Bip01 Forearm.R', 'Bip01 Spine', 'Bip01 Spine1', 'Bip01 Spine2', 'Bip01 Clavicle.L', 'Bip01 Clavicle.R' ):
ipo = bones_ipo[bone]
ipo_curves = ipo.curveConsts.values()
maxframe = 0
# read translation data from ipo(s) and add to key data
for curve in ipo_curves:
if ipo[curve] is None:
# print >> f, "NOT a curve"
continue
for btriple in ipo[curve].bezierPoints:
frame = int(btriple.pt[0])
maxframe = frame
Blender.Set('curframe', frame)
ploc = mypose.bones[bone].loc
x1 = ploc[0]
y1 = ploc[1]
z1 = ploc[2]
myRot = mypose.bones[bone].quat.toEuler()
rx = myRot[0]
ry = myRot[1]
rz = myRot[2]
s = "%3d,%s,%.2f,%.2f,%.2f,%.0f,%.0f,%.0f" % (frame,bone,x1,y1,z1,rx,ry,rz)
keydata.append(s)
# sort selected keydata and export
dic={}
for i in keydata:
dic[i]=''
keydata=dic.keys()
keydata.sort()
for line in keydata:
print >> f, line
get_keys()