goat3d

diff 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 diff
     1.1 --- a/exporters/blendgoat/src/blendgoat.py	Sat Oct 05 21:19:10 2013 +0300
     1.2 +++ b/exporters/blendgoat/src/blendgoat.py	Sun Oct 06 15:34:45 2013 +0300
     1.3 @@ -1,6 +1,10 @@
     1.4  # Goat3D Blender >2.5 exporter
     1.5  import bpy;
     1.6  from bpy_extras.io_utils import ExportHelper
     1.7 +import ctypes
     1.8 +from ctypes import *
     1.9 +from ctypes.util import find_library
    1.10 +import os
    1.11  
    1.12  bl_info = {
    1.13  	"name": "Goat3D scene",
    1.14 @@ -13,22 +17,51 @@
    1.15  
    1.16  class ExportGoat3D(bpy.types.Operator, ExportHelper):
    1.17  	bl_idname = "export.goat3d"
    1.18 -	bl_label = "Goat3D scene export"
    1.19 +	bl_label = "export"
    1.20 +	bl_options = {'PRESET'}
    1.21 +	filename_ext = ".goatsce"
    1.22  
    1.23 -	fname = bpy.props.Stringproperty(subtype="FILE_PATH")
    1.24 +	fname = bpy.props.StringProperty(subtype="FILE_PATH")
    1.25  
    1.26  	@classmethod
    1.27  	def poll(cls, ctx):
    1.28  		return ctx.object is not None
    1.29  
    1.30 -	def execute(self, context):
    1.31 -		file = open(self.filepath, "w")
    1.32 -		file.write("foobar " + ctx.object.name)
    1.33 +	def execute(self, ctx):
    1.34 +		libname = find_library("goat3d")
    1.35 +		if not libname:
    1.36 +			self.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
    1.37 +			return {'CANCELLED'}
    1.38 +		libgoat = CDLL(libname)
    1.39 +		if not libgoat:
    1.40 +			self.report({'ERROR'}, "Could not open goat3d library!")
    1.41 +			return {'CANCELLED'}
    1.42 +
    1.43 +		goat3d_create = libgoat.goat3d_create
    1.44 +		goat3d_create.argtypes = None
    1.45 +		goat3d_create.restype = c_void_p
    1.46 +
    1.47 +		goat3d_free = libgoat.goat3d_free
    1.48 +		goat3d_free.argtypes = [c_void_p]
    1.49 +		goat3d_free.restype = None
    1.50 +
    1.51 +		goat3d_save_file = libgoat.goat3d_save_file
    1.52 +		goat3d_save_file.argtypes = [c_void_p, c_char_p]
    1.53 +
    1.54 +		self.report({'INFO'}, "Exporting goat3d file")
    1.55 +
    1.56 +		goat = goat3d_create()
    1.57 +		if not goat:
    1.58 +			self.report({'ERROR'}, "Failed to create goat3d object")
    1.59 +			return {'CANCELLED'}
    1.60 +
    1.61 +		goat3d_save_file(goat, "/tmp/lala.xml")
    1.62 +		goat3d_free(goat)
    1.63  		return {'FINISHED'}
    1.64  
    1.65  def menu_func(self, ctx):
    1.66  	self.layout.operator_context = 'INVOKE_DEFAULT'
    1.67 -	self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export")
    1.68 +	self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export (.goatsce)")
    1.69  
    1.70  def register():
    1.71  	bpy.utils.register_module(__name__)