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@33
|
19 bl_idname = "export.goat3d"
|
nuclear@36
|
20 bl_label = "export"
|
nuclear@36
|
21 bl_options = {'PRESET'}
|
nuclear@36
|
22 filename_ext = ".goatsce"
|
nuclear@33
|
23
|
nuclear@36
|
24 fname = bpy.props.StringProperty(subtype="FILE_PATH")
|
nuclear@33
|
25
|
nuclear@33
|
26 @classmethod
|
nuclear@33
|
27 def poll(cls, ctx):
|
nuclear@33
|
28 return ctx.object is not None
|
nuclear@33
|
29
|
nuclear@36
|
30 def execute(self, ctx):
|
nuclear@36
|
31 libname = find_library("goat3d")
|
nuclear@36
|
32 if not libname:
|
nuclear@36
|
33 self.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
|
nuclear@36
|
34 return {'CANCELLED'}
|
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@36
|
48 goat3d_save_file = libgoat.goat3d_save_file
|
nuclear@36
|
49 goat3d_save_file.argtypes = [c_void_p, c_char_p]
|
nuclear@36
|
50
|
nuclear@36
|
51 self.report({'INFO'}, "Exporting goat3d file")
|
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@36
|
58 goat3d_save_file(goat, "/tmp/lala.xml")
|
nuclear@36
|
59 goat3d_free(goat)
|
nuclear@33
|
60 return {'FINISHED'}
|
nuclear@33
|
61
|
nuclear@33
|
62 def menu_func(self, ctx):
|
nuclear@33
|
63 self.layout.operator_context = 'INVOKE_DEFAULT'
|
nuclear@36
|
64 self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export (.goatsce)")
|
nuclear@33
|
65
|
nuclear@33
|
66 def register():
|
nuclear@33
|
67 bpy.utils.register_module(__name__)
|
nuclear@33
|
68 bpy.types.INFO_MT_file_export.append(menu_func)
|
nuclear@33
|
69
|
nuclear@33
|
70 def unregister():
|
nuclear@33
|
71 bpy.utils.unregister_module(__name__)
|
nuclear@33
|
72 bpy.types.INFO_MT_file_export.remove(menu_func)
|
nuclear@33
|
73
|
nuclear@33
|
74 if __name__ == "__main__":
|
nuclear@33
|
75 register()
|