Skeleton structure : Blender export script

Published February 01, 2012
Advertisement
Getting easier working with blender, but sadly I'm done for now.

Here is the export script for skeleton structure. Tested in Blender 2.61


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

import os
from math import radians

import bpy
from mathutils import *


# my OP ###

class ExportVSO(bpy.types.Operator):
bl_idname = "object.export_vso"
bl_label = "Export VSO"

@classmethod
def poll(cls, context):
return context.active_object != None

def objToLine( self, obj ):
line = "add_skeleton "
line += obj.name
return line[:] + "\n"

def boneToLine( self, bone ):
line = "add_bone "
line += bone.name
line += " "
if bone.parent:
line += bone.parent.name
else:
line += "NONE"
# Head
line += " "
line += str( bone.head_local[0] )
line += " "
line += str( bone.head_local[1] )
line += " "
line += str( bone.head_local[2] )
return line[:] + "\n"

def outvso(self, path, scn, obj ):
filename = path + obj.name + ".vso"
file = open(filename, "w")
file.write("# vortX GE skeleton v0.1\n\n")

file.write(self.objToLine( obj ))
# bone structure
for bone in obj.data.bones:
file.write(self.boneToLine( bone ))

file.close()

def execute(self, context):
print("Run Export VSO")
# print( dir( context ) )
rd = context.scene.render
path = rd.filepath
obj = context.active_object
scn = context.scene
self.outvso(path, scn, obj)
return {'FINISHED'}

# my PANEL
class OBJECT_PT_export_vso(bpy.types.Panel):
bl_label = "Export VSO"
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_vso", text="Export Skeleton")

def register():
bpy.utils.register_class(ExportVSO)
bpy.utils.register_class(OBJECT_PT_export_vso)

def unregister():
bpy.utils.unregister_class(OBJECT_PT_export_vso)
bpy.utils.unregister_class(ExportVSO)

if __name__ == "__main__":
register()



And once again here's the exported file


# vortX GE skeleton v0.1

add_skeleton Armature
add_bone Bone NONE 0.0 0.0 0.0
add_bone Bone.001 Bone -1.4901161193847656e-08 -1.4404456294414558e-07 1.2499637603759766
add_bone Bone.002 Bone.001 -3.973643103449831e-08 -1.2914340175029793e-07 2.4999637603759766
add_bone Bone.003 Bone.002 -3.973643103449831e-08 -1.2417635275596695e-07 3.7499632835388184
1 likes 1 comments

Comments

mixmaster
And keep in mind the data is in Blenders 3D space.. Swap y,z for OpenGL.
February 01, 2012 11:58 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

vortxGE : Threads

2342 views

C++11 Threads

3042 views

My Business

2198 views

Still Alive

2025 views

vortxEDIT : video

2139 views

vortxGE : Update

5989 views

vortxEDIT : Save

1899 views
Advertisement