goat3d

view exporters/blendgoat/src/blendgoat.py @ 36:9a211986a28b

writing the blender plugin
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 06 Oct 2013 15:34:45 +0300
parents 4f8383183d62
children d259a5094390
line source
1 # Goat3D Blender >2.5 exporter
2 import bpy;
3 from bpy_extras.io_utils import ExportHelper
4 import ctypes
5 from ctypes import *
6 from ctypes.util import find_library
7 import os
9 bl_info = {
10 "name": "Goat3D scene",
11 "author": "John Tsiombikas",
12 "version": (0, 1),
13 "location": "File > Import-Export",
14 "description": "Mutant Stargoat, Goat3D scene file format: http://code.google.com/p/goat3d/",
15 "category": "Import-Export"
16 }
18 class ExportGoat3D(bpy.types.Operator, ExportHelper):
19 bl_idname = "export.goat3d"
20 bl_label = "export"
21 bl_options = {'PRESET'}
22 filename_ext = ".goatsce"
24 fname = bpy.props.StringProperty(subtype="FILE_PATH")
26 @classmethod
27 def poll(cls, ctx):
28 return ctx.object is not None
30 def execute(self, ctx):
31 libname = find_library("goat3d")
32 if not libname:
33 self.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
34 return {'CANCELLED'}
35 libgoat = CDLL(libname)
36 if not libgoat:
37 self.report({'ERROR'}, "Could not open goat3d library!")
38 return {'CANCELLED'}
40 goat3d_create = libgoat.goat3d_create
41 goat3d_create.argtypes = None
42 goat3d_create.restype = c_void_p
44 goat3d_free = libgoat.goat3d_free
45 goat3d_free.argtypes = [c_void_p]
46 goat3d_free.restype = None
48 goat3d_save_file = libgoat.goat3d_save_file
49 goat3d_save_file.argtypes = [c_void_p, c_char_p]
51 self.report({'INFO'}, "Exporting goat3d file")
53 goat = goat3d_create()
54 if not goat:
55 self.report({'ERROR'}, "Failed to create goat3d object")
56 return {'CANCELLED'}
58 goat3d_save_file(goat, "/tmp/lala.xml")
59 goat3d_free(goat)
60 return {'FINISHED'}
62 def menu_func(self, ctx):
63 self.layout.operator_context = 'INVOKE_DEFAULT'
64 self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export (.goatsce)")
66 def register():
67 bpy.utils.register_module(__name__)
68 bpy.types.INFO_MT_file_export.append(menu_func)
70 def unregister():
71 bpy.utils.unregister_module(__name__)
72 bpy.types.INFO_MT_file_export.remove(menu_func)
74 if __name__ == "__main__":
75 register()