goat3d

changeset 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
files exporters/blendgoat/Makefile exporters/blendgoat/src/blendgoat.py
diffstat 2 files changed, 72 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/exporters/blendgoat/Makefile	Sun Oct 06 15:34:45 2013 +0300
     1.3 @@ -0,0 +1,33 @@
     1.4 +scriptfile = blendgoat.py
     1.5 +scriptfile_path := $(shell pwd)/src/$(scriptfile)
     1.6 +
     1.7 +ifeq ($(shell uname -s), Darwin)
     1.8 +	cfgpath = $(HOME)/Library/Application\ Support/Blender
     1.9 +else
    1.10 +	cfgpath = $(HOME)/.config/blender/
    1.11 +endif
    1.12 +
    1.13 +.PHONY: all
    1.14 +all:
    1.15 +	@echo Just type \"$(MAKE) install\" to install the blender exporter.
    1.16 +	@echo Also make sure you have installed the main libgoat3d library.
    1.17 +
    1.18 +.PHONY: install
    1.19 +install:
    1.20 +	@cd $(cfgpath) && \
    1.21 +	for i in *; do \
    1.22 +		echo "installing src/$(scriptfile) -> $(cfgpath)/$$i/scripts/addons/$(scriptfile)"; \
    1.23 +		mkdir -p $$i/scripts/addons; \
    1.24 +		rm -f $$i/scripts/addons/$(scriptfile); \
    1.25 +		cp $(scriptfile_path) $$i/scripts/addons/$(scriptfile); \
    1.26 +	done
    1.27 +
    1.28 +.PHONY: link
    1.29 +link:
    1.30 +	cd $(cfgpath) && \
    1.31 +	for i in *; do \
    1.32 +		echo "linking src/$(scriptfile) to $(cfgpath)/$$i/scripts/addons/$(scriptfile)"; \
    1.33 +		mkdir -p $$i/scripts/addons; \
    1.34 +		rm -f $$i/scripts/addons/$(scriptfile); \
    1.35 +		ln -s $(scriptfile_path) $$i/scripts/addons/$(scriptfile); \
    1.36 +	done
     2.1 --- a/exporters/blendgoat/src/blendgoat.py	Sat Oct 05 21:19:10 2013 +0300
     2.2 +++ b/exporters/blendgoat/src/blendgoat.py	Sun Oct 06 15:34:45 2013 +0300
     2.3 @@ -1,6 +1,10 @@
     2.4  # Goat3D Blender >2.5 exporter
     2.5  import bpy;
     2.6  from bpy_extras.io_utils import ExportHelper
     2.7 +import ctypes
     2.8 +from ctypes import *
     2.9 +from ctypes.util import find_library
    2.10 +import os
    2.11  
    2.12  bl_info = {
    2.13  	"name": "Goat3D scene",
    2.14 @@ -13,22 +17,51 @@
    2.15  
    2.16  class ExportGoat3D(bpy.types.Operator, ExportHelper):
    2.17  	bl_idname = "export.goat3d"
    2.18 -	bl_label = "Goat3D scene export"
    2.19 +	bl_label = "export"
    2.20 +	bl_options = {'PRESET'}
    2.21 +	filename_ext = ".goatsce"
    2.22  
    2.23 -	fname = bpy.props.Stringproperty(subtype="FILE_PATH")
    2.24 +	fname = bpy.props.StringProperty(subtype="FILE_PATH")
    2.25  
    2.26  	@classmethod
    2.27  	def poll(cls, ctx):
    2.28  		return ctx.object is not None
    2.29  
    2.30 -	def execute(self, context):
    2.31 -		file = open(self.filepath, "w")
    2.32 -		file.write("foobar " + ctx.object.name)
    2.33 +	def execute(self, ctx):
    2.34 +		libname = find_library("goat3d")
    2.35 +		if not libname:
    2.36 +			self.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
    2.37 +			return {'CANCELLED'}
    2.38 +		libgoat = CDLL(libname)
    2.39 +		if not libgoat:
    2.40 +			self.report({'ERROR'}, "Could not open goat3d library!")
    2.41 +			return {'CANCELLED'}
    2.42 +
    2.43 +		goat3d_create = libgoat.goat3d_create
    2.44 +		goat3d_create.argtypes = None
    2.45 +		goat3d_create.restype = c_void_p
    2.46 +
    2.47 +		goat3d_free = libgoat.goat3d_free
    2.48 +		goat3d_free.argtypes = [c_void_p]
    2.49 +		goat3d_free.restype = None
    2.50 +
    2.51 +		goat3d_save_file = libgoat.goat3d_save_file
    2.52 +		goat3d_save_file.argtypes = [c_void_p, c_char_p]
    2.53 +
    2.54 +		self.report({'INFO'}, "Exporting goat3d file")
    2.55 +
    2.56 +		goat = goat3d_create()
    2.57 +		if not goat:
    2.58 +			self.report({'ERROR'}, "Failed to create goat3d object")
    2.59 +			return {'CANCELLED'}
    2.60 +
    2.61 +		goat3d_save_file(goat, "/tmp/lala.xml")
    2.62 +		goat3d_free(goat)
    2.63  		return {'FINISHED'}
    2.64  
    2.65  def menu_func(self, ctx):
    2.66  	self.layout.operator_context = 'INVOKE_DEFAULT'
    2.67 -	self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export")
    2.68 +	self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export (.goatsce)")
    2.69  
    2.70  def register():
    2.71  	bpy.utils.register_module(__name__)