Jump to content

  • Log In with Google      Sign In   
  • Create Account





vortxGE 2.0 progress : Blender animaion export

Posted by Lee A. Stripp, 01 February 2012 · 472 views

After bashing my head against a wall for a day, I think I have the basic export working. Only one thing that I'm not sure on, the RNA array_index? I'm using it as the x,y,z reference in my own properties and I'm hoping this is right LOL. Here's the code.

EDIT: code update to include skeleton support.

# -*- coding: utf-8 -*-
#
# vortX GE export animation
#

import os
from math import radians

import bpy
from mathutils import *


# my OP ###

class ExportVXA(bpy.types.Operator):
    bl_idname = "object.export_vxa"
    bl_label = "Export VXA"
    
    @classmethod
    def poll(cls, context):
        return context.active_object != None
        
    def objToLine( self, obj ):
        line = "find_actor "
        line += obj.name
        return line[:] + "\n"
        
    def fpsToLine( self, scn ):
        line = "set_animframerate "
        # fps
        line += str( scn.render.fps )
        return line[:] + "\n"
    
    def keysToLines( self, scn, obj ):
        line = ""
        if obj.animation_data:
            Action = obj.animation_data.action
            if Action:
                for FCurve in Action.fcurves:
                    if FCurve:
                        line += "\naddkeys "
                        line += FCurve.data_path
                        line += " "
                        line += str( FCurve.array_index )
                        line += "\n"
                        for Keyframe in FCurve.keyframe_points:
                            print( Keyframe.co )
                            line += "addkey "
                            line += str( Keyframe.co[0] )
                            line += " "
                            line += str( Keyframe.co[1] )
                            line += "\n"
        
        return line[:] + "\n"
    
    def outvxa(self, path, scn, obj ):
        filename = path + obj.name + ".vxa"
        file = open(filename, "w")
        file.write("# vortX GE animation v0.1\n\n")
        
        file.write(self.objToLine( obj ))
        file.write(self.fpsToLine( scn ))
        file.write(self.keysToLines( scn, obj ))
        
        file.close()
    
    def execute(self, context):
        print("Run Export VXA")
        # print( dir( context ) )
        rd = context.scene.render
        path = rd.filepath
        obj = context.active_object
        scn = context.scene
        self.outvxa(path, scn, obj)
        return {'FINISHED'}

# my PANEL
class OBJECT_PT_export_vxa(bpy.types.Panel):
    bl_label = "Export VXA"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
    
    def draw(self, context):
        layout = self.layout
        rd = context.scene.render
        obj = context.active_object
        
        row = layout.row()
        row.label(text="Active Object : " + obj.name)
        
        row = layout.row()
        layout.prop(rd, "filepath", text="")
        
        row = layout.row()
        row.operator("object.export_vxa", text="Export Animation")

def register():
    bpy.utils.register_class(ExportVXA)
    bpy.utils.register_class(OBJECT_PT_export_vxa)

def unregister():
    bpy.utils.unregister_class(OBJECT_PT_export_vxa)
    bpy.utils.unregister_class(ExportVXA)

if __name__ == "__main__":
    register()

And here is the output file.

# vortX GE animation v0.1

find_actor Armature
set_animframerate 25

addkeys pose.bones["Bone"].location 0
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0
addkey 201.0 3.0106971138366134e-08
addkey 251.0 0.0

addkeys pose.bones["Bone"].location 1
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0
addkey 201.0 2.525481939315796
addkey 251.0 0.0

addkeys pose.bones["Bone"].location 2
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0
addkey 201.0 -7.125141792130307e-07
addkey 251.0 0.0

addkeys pose.bones["Bone"].rotation_quaternion 0
addkey 1.0 1.0
addkey 51.0 0.960628867149353
addkey 101.0 0.9623659253120422
addkey 151.0 1.0
addkey 201.0 1.0
addkey 251.0 1.0

addkeys pose.bones["Bone"].rotation_quaternion 1
addkey 1.0 0.0
addkey 51.0 3.312142116129735e-09
addkey 101.0 -3.239685852918228e-09
addkey 151.0 0.0
addkey 201.0 0.0
addkey 251.0 0.0

addkeys pose.bones["Bone"].rotation_quaternion 2
addkey 1.0 0.0
addkey 51.0 -4.105595863279632e-08
addkey 101.0 4.015781485122716e-08
addkey 151.0 0.0
addkey 201.0 0.0
addkey 251.0 0.0

addkeys pose.bones["Bone"].rotation_quaternion 3
addkey 1.0 0.0
addkey 51.0 -0.27783477306365967
addkey 101.0 0.27175694704055786
addkey 151.0 0.0
addkey 201.0 0.0
addkey 251.0 0.0

addkeys pose.bones["Bone.001"].location 0
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0

addkeys pose.bones["Bone.001"].location 1
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0

addkeys pose.bones["Bone.001"].location 2
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0

addkeys pose.bones["Bone.001"].rotation_quaternion 0
addkey 1.0 1.0
addkey 51.0 0.960628867149353
addkey 101.0 0.9623659253120422
addkey 151.0 1.0

addkeys pose.bones["Bone.001"].rotation_quaternion 1
addkey 1.0 0.0
addkey 51.0 -0.14311659336090088
addkey 101.0 0.1399858295917511
addkey 151.0 0.0

addkeys pose.bones["Bone.001"].rotation_quaternion 2
addkey 1.0 0.0
addkey 51.0 1.1246113729157514e-07
addkey 101.0 -8.195638656616211e-08
addkey 151.0 0.0

addkeys pose.bones["Bone.001"].rotation_quaternion 3
addkey 1.0 0.0
addkey 51.0 0.23813818395137787
addkey 101.0 -0.2329287827014923
addkey 151.0 0.0

addkeys pose.bones["Bone.002"].location 0
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0

addkeys pose.bones["Bone.002"].location 1
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0

addkeys pose.bones["Bone.002"].location 2
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0

addkeys pose.bones["Bone.002"].rotation_quaternion 0
addkey 1.0 1.0
addkey 51.0 0.960628867149353
addkey 101.0 0.9623660445213318
addkey 151.0 1.0

addkeys pose.bones["Bone.002"].rotation_quaternion 1
addkey 1.0 0.0
addkey 51.0 -0.27151045203208923
addkey 101.0 0.2655709981918335
addkey 151.0 0.0

addkeys pose.bones["Bone.002"].rotation_quaternion 2
addkey 1.0 0.0
addkey 51.0 1.2409505245614127e-07
addkey 101.0 -1.1920928955078125e-07
addkey 151.0 0.0

addkeys pose.bones["Bone.002"].rotation_quaternion 3
addkey 1.0 0.0
addkey 51.0 -0.058942679315805435
addkey 101.0 0.057653311640024185
addkey 151.0 0.0

addkeys pose.bones["Bone.003"].location 0
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0

addkeys pose.bones["Bone.003"].location 1
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0

addkeys pose.bones["Bone.003"].location 2
addkey 1.0 0.0
addkey 51.0 0.0
addkey 101.0 0.0
addkey 151.0 0.0

addkeys pose.bones["Bone.003"].rotation_quaternion 0
addkey 1.0 1.0
addkey 51.0 0.960628867149353
addkey 101.0 0.9623659253120422
addkey 151.0 1.0

addkeys pose.bones["Bone.003"].rotation_quaternion 1
addkey 1.0 0.0
addkey 51.0 -1.2420189321460384e-08
addkey 101.0 2.088668082933509e-08
addkey 151.0 0.0

addkeys pose.bones["Bone.003"].rotation_quaternion 2
addkey 1.0 0.0
addkey 51.0 9.626557329056595e-08
addkey 101.0 -1.2016418793336925e-07
addkey 151.0 0.0

addkeys pose.bones["Bone.003"].rotation_quaternion 3
addkey 1.0 0.0
addkey 51.0 0.27783477306365967
addkey 101.0 -0.27175694704055786
addkey 151.0 0.0





October 2014 »

S M T W T F S
   1234
567891011
12131415161718
192021222324 25
262728293031 

Recent Comments

PARTNERS