NLA.NewAction.setActive() overwrites Animations

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Post Reply
Posts: 1
Joined: Sun Jul 08, 2012 8:01 am

NLA.NewAction.setActive() overwrites Animations

Post by sabooakhter » Sun Jul 08, 2012 8:11 am

Hi there,

I'm using blender 2.49b to import multiple animation files that are in a different file format. I found a script to import these animations but it constantly writes over my previous animation. Any help would be awesome, thanks.

Here's the excerpt of code I believe is giving the problem:

Code: Select all

action_name = Blender.sys.basename(
action_name = action_name[0:action_name.find('.')]

action = Blender.Armature.NLA.NewAction(action_name)

for x in xrange(mesh_count):
     read_mesh_transformations(file_object, version, armature_object)

def ani_read_mesh_transformations(file_object, version, armature_object):
    key_frames = {}

    armature_pose = armature_object.getPose()

    armature_pose_bones = armature_pose.bones

    mesh_name =

    mesh_name = mesh_name[0:mesh_name.find('\0')]

    mesh_name = elu_to_blender_name(mesh_name)

    print "transform %s start 0x%x" % (mesh_name, file_object.tell() - 44)

    pm = struct.unpack('<16f',

    pose_matrix = Blender.Mathutils.Matrix([pm[0], pm[2], pm[1], pm[3]], \
                                           [pm[8], pm[10], pm[9], pm[11]], \
                                           [pm[4], pm[6], pm[5], pm[7]], \
                                           [pm[12], pm[14], pm[13], pm[15]])

    translation_count = struct.unpack('<I',[0]

#    print "translation count %d" % translation_count

    for x in xrange(translation_count):
        tx, ty, tz = struct.unpack('<3f',

        translation = Blender.Mathutils.Vector(tx, tz, ty)

        key_frame_second = int(struct.unpack('<I',[0] / 60)

        translation_matrix = Blender.Mathutils.TranslationMatrix(translation)

        key_frames[key_frame_second] = translation_matrix

    rotation_count = struct.unpack('<I',[0]

#    print "rotation count %d" % rotation_count

    for x in xrange(rotation_count):
        rotation_matrix = Blender.Mathutils.Matrix()


        rx, ry, rz, rw = struct.unpack('<4f',

        if version >= 0x1003:
            rotation = Blender.Mathutils.Quaternion(-rw, rx, rz, ry)

            rotation_matrix *= rotation.toMatrix().resize4x4()
            rotation = Blender.Mathutils.Quaternion([rx, rz, ry], math.degrees(-rw))

            rotation_matrix *= rotation.toMatrix().resize4x4()

        key_frame_second = int(struct.unpack('<I',[0] / 60)

        if key_frame_second in key_frames:
            key_frames[key_frame_second] = rotation_matrix * key_frames[key_frame_second]
            parent_inverse_pose_matrix = Blender.Mathutils.Matrix()


            if mesh_name in armature_pose_bones.keys():
                if armature_pose_bones[mesh_name].parent is not None:
                    parent_inverse_pose_matrix *= armature_pose_bones[mesh_name].parent.poseMatrix.copy()


            key_frames[key_frame_second] = rotation_matrix * Blender.Mathutils.TranslationMatrix((pose_matrix * parent_inverse_pose_matrix).translationPart())

    if mesh_name in armature_pose_bones.keys():
        if len(key_frames) > 0:
            for key_frame_second, key_frame_transformation in key_frames.iteritems():
                if armature_pose_bones[mesh_name].parent is not None:
                    key_frame_transformation *= armature_pose_bones[mesh_name].parent.poseMatrix.copy()

                armature_pose_bones[mesh_name].poseMatrix = key_frame_transformation


                armature_pose_bones[mesh_name].insertKey(armature_object, key_frame_second + 1)

            armature_pose_bones[mesh_name].poseMatrix = pose_matrix

            armature_pose_bones[mesh_name].poseMatrix = pose_matrix


            armature_pose_bones[mesh_name].insertKey(armature_object, 1)

Post Reply

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests