🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

vortxGE 2.0 progress : Blender animaion export

Published February 01, 2012
Advertisement
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
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

vortxGE : Threads

2452 views

C++11 Threads

3150 views

My Business

2305 views

Still Alive

2116 views

vortxEDIT : video

2236 views

vortxGE : Update

6078 views

vortxEDIT : Save

1995 views
Advertisement