Currently I’m trying to implement a Blender addon to add a file format to be able to load meshes into Blender. The file format stores animations as key frames, and I can convert these into fcurves by reading the values into labelled arrays:
for anim in animHeader:
self.view.seek(anim['offset'])
for i in range(0, anim['count']):
data = self.view.read(0x30)
s = unpack('hHfffffffffff', data)
boneId = s[0]
flags = s[1]
time = s[2]
frame = int(time * anim['fps'] + 0.5)
bone = self.bones[boneId]
if flags & DASH_ANIMATION_POS:
anim['tracks']['X Location (%s)' % bone.name].append( ( frame, s[3] ))
anim['tracks']['Y Location (%s)' % bone.name].append( ( frame, s[4] ))
anim['tracks']['Z Location (%s)' % bone.name].append( ( frame, s[5] ))
if flags & DASH_ANIMATION_ROT:
anim['tracks']['W Quarternion Rotation (%s)' % bone.name].append( ( frame, s[9] ))
anim['tracks']['X Quarternion Rotation (%s)' % bone.name].append( ( frame, s[6] ))
anim['tracks']['Y Quarternion Rotation (%s)' % bone.name].append( ( frame, s[7] ))
anim['tracks']['Z Quarternion Rotation (%s)' % bone.name].append( ( frame, s[8] ))
if flags & DASH_ANIMATION_SCL:
anim['tracks']['X Scale (%s)' % bone.name].append( ( frame, s[10] ))
anim['tracks']['Y Scale (%s)' % bone.name].append( ( frame, s[11] ))
anim['tracks']['Z Scale (%s)' % bone.name].append( ( frame, s[12] ))
The problem occurs when I try to create an animation (action) and set it to the armature
axis_lookup = [ 0, 1, 2, 0, 1, 2, 3, 0, 1, 2]
for anim in animHeader:
action = bpy.data.actions.new(name=anim['name'])
if self.arm_obj.animation_data.action is None:
self.arm_obj.animation_data.action = action
axis_i = -1
for key in anim['tracks']:
axis_i += 1
index = axis_lookup[axis_i % 10]
curve = action.fcurves.new(data_path=str(key), index=index)
keyframe_points = curve.keyframe_points
keyframe_points.add(len(anim['tracks'][key]))
for i in range(len(anim['tracks'][key])):
keyframe_points[i].co = anim['tracks'][key][i]
The problem is that after doing this, Blender seems to show there is an animation listed next to the Armature, and the dope sheet shows that data is included in the animation. I cannot get the action to play in the 3d viewer.
As a test, I loaded the model, and moved the bones manually to test to see if weights were being applied correctly. And I can manually moved the bones in pose mode, and have the mesh deform. But again I can’t get the animation to play, even the normal disfigured way that comes with testing animations for the first time.
For context I have a sample model here: Files · master · DashGL / Dash Model Format · GitLab
And then full source for the Import Addon here: Files · master · DashGL / Dash Model Format · GitLab