goat3d

annotate 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
rev   line source
nuclear@33 1 # Goat3D Blender >2.5 exporter
nuclear@33 2 import bpy;
nuclear@33 3 from bpy_extras.io_utils import ExportHelper
nuclear@36 4 import ctypes
nuclear@36 5 from ctypes import *
nuclear@36 6 from ctypes.util import find_library
nuclear@36 7 import os
nuclear@33 8
nuclear@33 9 bl_info = {
nuclear@33 10 "name": "Goat3D scene",
nuclear@33 11 "author": "John Tsiombikas",
nuclear@33 12 "version": (0, 1),
nuclear@33 13 "location": "File > Import-Export",
nuclear@33 14 "description": "Mutant Stargoat, Goat3D scene file format: http://code.google.com/p/goat3d/",
nuclear@33 15 "category": "Import-Export"
nuclear@33 16 }
nuclear@33 17
nuclear@33 18 class ExportGoat3D(bpy.types.Operator, ExportHelper):
nuclear@37 19 bl_idname = "export_scene.goat3d"
nuclear@37 20 bl_label = "Export Goat3D Scene"
nuclear@36 21 bl_options = {'PRESET'}
nuclear@36 22 filename_ext = ".goatsce"
nuclear@37 23 filter_glob = bpy.props.StringProperty(default="*.goatsce", options={'HIDDEN'})
nuclear@33 24
nuclear@33 25 @classmethod
nuclear@33 26 def poll(cls, ctx):
nuclear@33 27 return ctx.object is not None
nuclear@33 28
nuclear@36 29 def execute(self, ctx):
nuclear@36 30 libname = find_library("goat3d")
nuclear@36 31 if not libname:
nuclear@36 32 self.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
nuclear@36 33 return {'CANCELLED'}
nuclear@37 34
nuclear@36 35 libgoat = CDLL(libname)
nuclear@36 36 if not libgoat:
nuclear@36 37 self.report({'ERROR'}, "Could not open goat3d library!")
nuclear@36 38 return {'CANCELLED'}
nuclear@36 39
nuclear@36 40 goat3d_create = libgoat.goat3d_create
nuclear@36 41 goat3d_create.argtypes = None
nuclear@36 42 goat3d_create.restype = c_void_p
nuclear@36 43
nuclear@36 44 goat3d_free = libgoat.goat3d_free
nuclear@36 45 goat3d_free.argtypes = [c_void_p]
nuclear@36 46 goat3d_free.restype = None
nuclear@36 47
nuclear@37 48 goat3d_save = libgoat.goat3d_save
nuclear@37 49 goat3d_save.argtypes = [c_void_p, c_char_p]
nuclear@36 50
nuclear@37 51 print("Exporting goat3d file: " + self.filepath)
nuclear@36 52
nuclear@36 53 goat = goat3d_create()
nuclear@36 54 if not goat:
nuclear@36 55 self.report({'ERROR'}, "Failed to create goat3d object")
nuclear@36 56 return {'CANCELLED'}
nuclear@36 57
nuclear@37 58 print(type(goat))
nuclear@37 59 print(type(self.filepath))
nuclear@37 60 goat3d_save(goat, c_char_p(self.filepath))
nuclear@36 61 goat3d_free(goat)
nuclear@33 62 return {'FINISHED'}
nuclear@33 63
nuclear@33 64 def menu_func(self, ctx):
nuclear@33 65 self.layout.operator_context = 'INVOKE_DEFAULT'
nuclear@36 66 self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export (.goatsce)")
nuclear@33 67
nuclear@33 68 def register():
nuclear@33 69 bpy.utils.register_module(__name__)
nuclear@33 70 bpy.types.INFO_MT_file_export.append(menu_func)
nuclear@33 71
nuclear@33 72 def unregister():
nuclear@33 73 bpy.utils.unregister_module(__name__)
nuclear@33 74 bpy.types.INFO_MT_file_export.remove(menu_func)
nuclear@33 75
nuclear@33 76 if __name__ == "__main__":
nuclear@33 77 register()