Jump to content

  • Log In with Google      Sign In   
  • Create Account





Skeleton structure : Blender export script

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

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





And keep in mind the data is in Blenders 3D space.. Swap y,z for OpenGL.

December 2014 »

S M T W T F S
 123456
78910111213
14151617181920
21222324252627
28 293031   

Recent Comments

PARTNERS