# HG changeset patch # User John Tsiombikas # Date 1381062885 -10800 # Node ID 9a211986a28b88193f1f7d1bfd75502e35b87684 # Parent 4f8383183d628521393987c436c965d6c19ba373 writing the blender plugin diff -r 4f8383183d62 -r 9a211986a28b exporters/blendgoat/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exporters/blendgoat/Makefile Sun Oct 06 15:34:45 2013 +0300 @@ -0,0 +1,33 @@ +scriptfile = blendgoat.py +scriptfile_path := $(shell pwd)/src/$(scriptfile) + +ifeq ($(shell uname -s), Darwin) + cfgpath = $(HOME)/Library/Application\ Support/Blender +else + cfgpath = $(HOME)/.config/blender/ +endif + +.PHONY: all +all: + @echo Just type \"$(MAKE) install\" to install the blender exporter. + @echo Also make sure you have installed the main libgoat3d library. + +.PHONY: install +install: + @cd $(cfgpath) && \ + for i in *; do \ + echo "installing src/$(scriptfile) -> $(cfgpath)/$$i/scripts/addons/$(scriptfile)"; \ + mkdir -p $$i/scripts/addons; \ + rm -f $$i/scripts/addons/$(scriptfile); \ + cp $(scriptfile_path) $$i/scripts/addons/$(scriptfile); \ + done + +.PHONY: link +link: + cd $(cfgpath) && \ + for i in *; do \ + echo "linking src/$(scriptfile) to $(cfgpath)/$$i/scripts/addons/$(scriptfile)"; \ + mkdir -p $$i/scripts/addons; \ + rm -f $$i/scripts/addons/$(scriptfile); \ + ln -s $(scriptfile_path) $$i/scripts/addons/$(scriptfile); \ + done diff -r 4f8383183d62 -r 9a211986a28b exporters/blendgoat/src/blendgoat.py --- a/exporters/blendgoat/src/blendgoat.py Sat Oct 05 21:19:10 2013 +0300 +++ b/exporters/blendgoat/src/blendgoat.py Sun Oct 06 15:34:45 2013 +0300 @@ -1,6 +1,10 @@ # Goat3D Blender >2.5 exporter import bpy; from bpy_extras.io_utils import ExportHelper +import ctypes +from ctypes import * +from ctypes.util import find_library +import os bl_info = { "name": "Goat3D scene", @@ -13,22 +17,51 @@ class ExportGoat3D(bpy.types.Operator, ExportHelper): bl_idname = "export.goat3d" - bl_label = "Goat3D scene export" + bl_label = "export" + bl_options = {'PRESET'} + filename_ext = ".goatsce" - fname = bpy.props.Stringproperty(subtype="FILE_PATH") + fname = bpy.props.StringProperty(subtype="FILE_PATH") @classmethod def poll(cls, ctx): return ctx.object is not None - def execute(self, context): - file = open(self.filepath, "w") - file.write("foobar " + ctx.object.name) + def execute(self, ctx): + libname = find_library("goat3d") + if not libname: + self.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.") + return {'CANCELLED'} + libgoat = CDLL(libname) + if not libgoat: + self.report({'ERROR'}, "Could not open goat3d library!") + return {'CANCELLED'} + + goat3d_create = libgoat.goat3d_create + goat3d_create.argtypes = None + goat3d_create.restype = c_void_p + + goat3d_free = libgoat.goat3d_free + goat3d_free.argtypes = [c_void_p] + goat3d_free.restype = None + + goat3d_save_file = libgoat.goat3d_save_file + goat3d_save_file.argtypes = [c_void_p, c_char_p] + + self.report({'INFO'}, "Exporting goat3d file") + + goat = goat3d_create() + if not goat: + self.report({'ERROR'}, "Failed to create goat3d object") + return {'CANCELLED'} + + goat3d_save_file(goat, "/tmp/lala.xml") + goat3d_free(goat) return {'FINISHED'} def menu_func(self, ctx): self.layout.operator_context = 'INVOKE_DEFAULT' - self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export") + self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export (.goatsce)") def register(): bpy.utils.register_module(__name__)