goat3d

view exporters/blendgoat/src/blendgoat.py @ 37:d259a5094390

trying to figure out how to properly call C functions from the python plugin
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 06 Oct 2013 17:42:43 +0300
parents 9a211986a28b
children
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_scene.goat3d"
20 bl_label = "Export Goat3D Scene"
21 bl_options = {'PRESET'}
22 filename_ext = ".goatsce"
23 filter_glob = bpy.props.StringProperty(default="*.goatsce", options={'HIDDEN'})
25 @classmethod
26 def poll(cls, ctx):
27 return ctx.object is not None
29 def execute(self, ctx):
30 libname = find_library("goat3d")
31 if not libname:
32 self.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
33 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 = libgoat.goat3d_save
49 goat3d_save.argtypes = [c_void_p, c_char_p]
51 print("Exporting goat3d file: " + self.filepath)
53 goat = goat3d_create()
54 if not goat:
55 self.report({'ERROR'}, "Failed to create goat3d object")
56 return {'CANCELLED'}
58 print(type(goat))
59 print(type(self.filepath))
60 goat3d_save(goat, c_char_p(self.filepath))
61 goat3d_free(goat)
62 return {'FINISHED'}
64 def menu_func(self, ctx):
65 self.layout.operator_context = 'INVOKE_DEFAULT'
66 self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export (.goatsce)")
68 def register():
69 bpy.utils.register_module(__name__)
70 bpy.types.INFO_MT_file_export.append(menu_func)
72 def unregister():
73 bpy.utils.unregister_module(__name__)
74 bpy.types.INFO_MT_file_export.remove(menu_func)
76 if __name__ == "__main__":
77 register()