goat3d

changeset 38:60f2037680ee

split the exporter into two files to make it more readable (and maybe make an importer too at some point?)
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 07 Oct 2013 20:02:57 +0300
parents d259a5094390
children 0e48907847ad
files .hgignore exporters/blendgoat/Makefile exporters/blendgoat/src/__init__.py exporters/blendgoat/src/blendgoat.py exporters/blendgoat/src/export_goat.py
diffstat 5 files changed, 192 insertions(+), 86 deletions(-) [+]
line diff
     1.1 --- a/.hgignore	Sun Oct 06 17:42:43 2013 +0300
     1.2 +++ b/.hgignore	Mon Oct 07 20:02:57 2013 +0300
     1.3 @@ -15,3 +15,4 @@
     1.4  goatprim$
     1.5  goatview$
     1.6  ass2goat$
     1.7 +__pycache__
     2.1 --- a/exporters/blendgoat/Makefile	Sun Oct 06 17:42:43 2013 +0300
     2.2 +++ b/exporters/blendgoat/Makefile	Mon Oct 07 20:02:57 2013 +0300
     2.3 @@ -1,5 +1,6 @@
     2.4 +name = blendgoat
     2.5  scriptfile = blendgoat.py
     2.6 -scriptfile_path := $(shell pwd)/src/$(scriptfile)
     2.7 +srcpath := $(shell pwd)/src
     2.8  
     2.9  ifeq ($(shell uname -s), Darwin)
    2.10  	cfgpath = $(HOME)/Library/Application\ Support/Blender
    2.11 @@ -16,18 +17,25 @@
    2.12  install:
    2.13  	@cd $(cfgpath) && \
    2.14  	for i in *; do \
    2.15 -		echo "installing src/$(scriptfile) -> $(cfgpath)/$$i/scripts/addons/$(scriptfile)"; \
    2.16 -		mkdir -p $$i/scripts/addons; \
    2.17 -		rm -f $$i/scripts/addons/$(scriptfile); \
    2.18 -		cp $(scriptfile_path) $$i/scripts/addons/$(scriptfile); \
    2.19 +		echo "installing to $(cfgpath)/$$i/scripts/addons/$(name)"; \
    2.20 +		rm -f $$i/scripts/addons/$(name)/*; \
    2.21 +		mkdir -p $$i/scripts/addons/$(name); \
    2.22 +		cp $(srcpath)/*.py $$i/scripts/addons/$(name)/; \
    2.23  	done
    2.24  
    2.25  .PHONY: link
    2.26  link:
    2.27 +	@cd $(cfgpath) && \
    2.28 +	for i in *; do \
    2.29 +		echo "linking to $(cfgpath)/$$i/scripts/addons/$(name)"; \
    2.30 +		mkdir -p $$i/scripts/addons; \
    2.31 +		rm -rf $$i/scripts/addons/$(name); \
    2.32 +		ln -s $(srcpath) $$i/scripts/addons/$(name); \
    2.33 +	done
    2.34 +
    2.35 +.PHONY: uninstall
    2.36 +uninstall:
    2.37  	cd $(cfgpath) && \
    2.38  	for i in *; do \
    2.39 -		echo "linking src/$(scriptfile) to $(cfgpath)/$$i/scripts/addons/$(scriptfile)"; \
    2.40 -		mkdir -p $$i/scripts/addons; \
    2.41 -		rm -f $$i/scripts/addons/$(scriptfile); \
    2.42 -		ln -s $(scriptfile_path) $$i/scripts/addons/$(scriptfile); \
    2.43 +		rm -rf $$i/scripts/addons/$(name); \
    2.44  	done
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/exporters/blendgoat/src/__init__.py	Mon Oct 07 20:02:57 2013 +0300
     3.3 @@ -0,0 +1,44 @@
     3.4 +bl_info = {
     3.5 +	"name": "Goat3D scene",
     3.6 +	"author": "John Tsiombikas",
     3.7 +	"version": (0, 1),
     3.8 +	"location": "File > Import-Export",
     3.9 +	"description": "Mutant Stargoat, Goat3D scene file format: http://code.google.com/p/goat3d/",
    3.10 +	"category": "Import-Export"
    3.11 +}
    3.12 +
    3.13 +if "bpy" in locals():
    3.14 +	import imp
    3.15 +	if "export_goat" in locals():
    3.16 +		imp.reload(export_goat)
    3.17 +
    3.18 +import bpy
    3.19 +from bpy_extras.io_utils import ExportHelper
    3.20 +
    3.21 +class ExportGoat3D(bpy.types.Operator, ExportHelper):
    3.22 +	bl_idname = "export_scene.goat3d"
    3.23 +	bl_label = "Export Goat3D Scene"
    3.24 +	bl_options = {'PRESET'}
    3.25 +	filename_ext = ".goatsce"
    3.26 +	filter_glob = bpy.props.StringProperty(default="*.goatsce", options={'HIDDEN'})
    3.27 +
    3.28 +	def execute(self, ctx):
    3.29 +		from . import export_goat
    3.30 +		if not export_goat.export(self, ctx, self.filepath):
    3.31 +			return {'CANCELLED'}
    3.32 +		return {'FINISHED'}
    3.33 +
    3.34 +def menu_func(self, ctx):
    3.35 +	self.layout.operator_context = 'INVOKE_DEFAULT'
    3.36 +	self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export (.goatsce)")
    3.37 +
    3.38 +def register():
    3.39 +	bpy.utils.register_module(__name__)
    3.40 +	bpy.types.INFO_MT_file_export.append(menu_func)
    3.41 +
    3.42 +def unregister():
    3.43 +	bpy.utils.unregister_module(__name__)
    3.44 +	bpy.types.INFO_MT_file_export.remove(menu_func)
    3.45 +
    3.46 +if __name__ == "__main__":
    3.47 +	register()
     4.1 --- a/exporters/blendgoat/src/blendgoat.py	Sun Oct 06 17:42:43 2013 +0300
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,77 +0,0 @@
     4.4 -# Goat3D Blender >2.5 exporter
     4.5 -import bpy;
     4.6 -from bpy_extras.io_utils import ExportHelper
     4.7 -import ctypes
     4.8 -from ctypes import *
     4.9 -from ctypes.util import find_library
    4.10 -import os
    4.11 -
    4.12 -bl_info = {
    4.13 -	"name": "Goat3D scene",
    4.14 -	"author": "John Tsiombikas",
    4.15 -	"version": (0, 1),
    4.16 -	"location": "File > Import-Export",
    4.17 -	"description": "Mutant Stargoat, Goat3D scene file format: http://code.google.com/p/goat3d/",
    4.18 -	"category": "Import-Export"
    4.19 -}
    4.20 -
    4.21 -class ExportGoat3D(bpy.types.Operator, ExportHelper):
    4.22 -	bl_idname = "export_scene.goat3d"
    4.23 -	bl_label = "Export Goat3D Scene"
    4.24 -	bl_options = {'PRESET'}
    4.25 -	filename_ext = ".goatsce"
    4.26 -	filter_glob = bpy.props.StringProperty(default="*.goatsce", options={'HIDDEN'})
    4.27 -
    4.28 -	@classmethod
    4.29 -	def poll(cls, ctx):
    4.30 -		return ctx.object is not None
    4.31 -
    4.32 -	def execute(self, ctx):
    4.33 -		libname = find_library("goat3d")
    4.34 -		if not libname:
    4.35 -			self.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
    4.36 -			return {'CANCELLED'}
    4.37 -
    4.38 -		libgoat = CDLL(libname)
    4.39 -		if not libgoat:
    4.40 -			self.report({'ERROR'}, "Could not open goat3d library!")
    4.41 -			return {'CANCELLED'}
    4.42 -
    4.43 -		goat3d_create = libgoat.goat3d_create
    4.44 -		goat3d_create.argtypes = None
    4.45 -		goat3d_create.restype = c_void_p
    4.46 -
    4.47 -		goat3d_free = libgoat.goat3d_free
    4.48 -		goat3d_free.argtypes = [c_void_p]
    4.49 -		goat3d_free.restype = None
    4.50 -
    4.51 -		goat3d_save = libgoat.goat3d_save
    4.52 -		goat3d_save.argtypes = [c_void_p, c_char_p]
    4.53 -
    4.54 -		print("Exporting goat3d file: " + self.filepath)
    4.55 -
    4.56 -		goat = goat3d_create()
    4.57 -		if not goat:
    4.58 -			self.report({'ERROR'}, "Failed to create goat3d object")
    4.59 -			return {'CANCELLED'}
    4.60 -
    4.61 -		print(type(goat))
    4.62 -		print(type(self.filepath))
    4.63 -		goat3d_save(goat, c_char_p(self.filepath))
    4.64 -		goat3d_free(goat)
    4.65 -		return {'FINISHED'}
    4.66 -
    4.67 -def menu_func(self, ctx):
    4.68 -	self.layout.operator_context = 'INVOKE_DEFAULT'
    4.69 -	self.layout.operator(ExportGoat3D.bl_idname, text="Goat3D scene export (.goatsce)")
    4.70 -
    4.71 -def register():
    4.72 -	bpy.utils.register_module(__name__)
    4.73 -	bpy.types.INFO_MT_file_export.append(menu_func)
    4.74 -
    4.75 -def unregister():
    4.76 -	bpy.utils.unregister_module(__name__)
    4.77 -	bpy.types.INFO_MT_file_export.remove(menu_func)
    4.78 -
    4.79 -if __name__ == "__main__":
    4.80 -	register()
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/exporters/blendgoat/src/export_goat.py	Mon Oct 07 20:02:57 2013 +0300
     5.3 @@ -0,0 +1,130 @@
     5.4 +# Goat3D Blender >2.5 exporter
     5.5 +import bpy;
     5.6 +import ctypes
     5.7 +from ctypes import *
     5.8 +from ctypes.util import find_library
     5.9 +
    5.10 +
    5.11 +def export(oper, ctx, fname):
    5.12 +	print("Exporting goat3d file: " + fname)
    5.13 +
    5.14 +	# load all relevant functions from libgoat3d
    5.15 +	libname = find_library("goat3d")
    5.16 +	if not libname:
    5.17 +		oper.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
    5.18 +		return False
    5.19 +
    5.20 +	libgoat = CDLL(libname)
    5.21 +	if not libgoat:
    5.22 +		oper.report({'ERROR'}, "Could not open goat3d library!")
    5.23 +		return False
    5.24 +
    5.25 +	goat3d_create = libgoat.goat3d_create
    5.26 +	goat3d_create.argtypes = None
    5.27 +	goat3d_create.restype = c_void_p
    5.28 +
    5.29 +	goat3d_free = libgoat.goat3d_free
    5.30 +	goat3d_free.argtypes = [c_void_p]
    5.31 +	goat3d_free.restype = None
    5.32 +
    5.33 +	goat3d_set_name = libgoat.goat3d_set_name
    5.34 +	goat3d_set_name.argtypes = [c_void_p, c_char_p]
    5.35 +
    5.36 +	goat3d_set_ambient3f = libgoat.goat3d_set_ambient3f
    5.37 +	goat3d_set_ambient3f.argtypes = [c_void_p, c_float, c_float, c_float]
    5.38 +	goat3d_set_ambient3f.restype = None
    5.39 +
    5.40 +	goat3d_add_mtl = libgoat.goat3d_add_mtl
    5.41 +	goat3d_add_mtl.argtypes = [c_void_p, c_void_p]
    5.42 +	goat3d_add_mtl.restype = None
    5.43 +
    5.44 +	goat3d_create_mtl = libgoat.goat3d_create_mtl
    5.45 +	goat3d_create_mtl.argtypes = None
    5.46 +	goat3d_create_mtl.restype = c_void_p
    5.47 +
    5.48 +	goat3d_set_mtl_name = libgoat.goat3d_set_mtl_name
    5.49 +	goat3d_set_mtl_name.argtypes = [c_void_p, c_char_p]
    5.50 +	goat3d_set_mtl_name.restype = None
    5.51 +
    5.52 +	goat3d_set_mtl_attrib4f = libgoat.goat3d_set_mtl_attrib4f
    5.53 +	goat3d_set_mtl_attrib4f.argtypes = [c_void_p, c_char_p, c_float, c_float, c_float, c_float]
    5.54 +	goat3d_set_mtl_attrib4f.restype = None
    5.55 +
    5.56 +	goat3d_set_mtl_attrib_map = libgoat.goat3d_set_mtl_attrib_map
    5.57 +	goat3d_set_mtl_attrib_map.argtypes = [c_void_p, c_char_p, c_char_p]
    5.58 +	goat3d_set_mtl_attrib_map.restype = None
    5.59 +
    5.60 +	goat3d_add_mesh = libgoat.goat3d_add_mesh
    5.61 +	goat3d_add_mesh.argtypes = [c_void_p, c_void_p]
    5.62 +	goat3d_add_mesh.restype = None
    5.63 +
    5.64 +	goat3d_create_mesh = libgoat.goat3d_create_mesh
    5.65 +	goat3d_create_mesh.argtypes = None
    5.66 +	goat3d_create_mesh.restype = c_void_p
    5.67 +
    5.68 +	goat3d_set_mesh_name = libgoat.goat3d_set_mesh_name
    5.69 +	goat3d_set_mesh_name.argtypes = [c_void_p, c_char_p]
    5.70 +	goat3d_set_mesh_name.restype = None
    5.71 +
    5.72 +	goat3d_set_mesh_mtl = libgoat.goat3d_set_mesh_mtl
    5.73 +	goat3d_set_mesh_mtl.argtypes = [c_void_p, c_void_p]
    5.74 +	goat3d_set_mesh_mtl.restype = None
    5.75 +
    5.76 +	goat3d_set_mesh_attribs = libgoat.goat3d_set_mesh_attribs
    5.77 +	goat3d_set_mesh_attribs.argtypes = [c_void_p, c_int, c_void_p, c_int]
    5.78 +	goat3d_set_mesh_attribs.restype = None
    5.79 +
    5.80 +	goat3d_set_mesh_faces = libgoat.goat3d_set_mesh_faces
    5.81 +	goat3d_set_mesh_faces.argtypes = [c_void_p, c_void_p, c_int]
    5.82 +	goat3d_set_mesh_faces.restype = None
    5.83 +
    5.84 +	goat3d_add_node = libgoat.goat3d_add_node
    5.85 +	goat3d_add_node.argtypes = [c_void_p, c_void_p]
    5.86 +	goat3d_add_node.restype = None
    5.87 +
    5.88 +	goat3d_create_node = libgoat.goat3d_create_node
    5.89 +	goat3d_create_node.argtypes = None
    5.90 +	goat3d_create_node.restype = c_void_p
    5.91 +
    5.92 +	goat3d_set_node_name = libgoat.goat3d_set_node_name
    5.93 +	goat3d_set_node_name.argtypes = [c_void_p, c_char_p]
    5.94 +	goat3d_set_node_name.restype = None
    5.95 +
    5.96 +	goat3d_set_node_object = libgoat.goat3d_set_node_object
    5.97 +	goat3d_set_node_object.argtypes = [c_void_p, c_int, c_void_p]
    5.98 +	goat3d_set_node_object.restype = None
    5.99 +
   5.100 +	goat3d_add_node_child = libgoat.goat3d_add_node_child
   5.101 +	goat3d_add_node_child.argtypes = [c_void_p, c_void_p]
   5.102 +	goat3d_add_node_child.restype = None
   5.103 +
   5.104 +	goat3d_set_node_position = libgoat.goat3d_set_node_position
   5.105 +	goat3d_set_node_position.argtypes = [c_void_p, c_float, c_float, c_float, c_long]
   5.106 +	goat3d_set_node_position.restype = None
   5.107 +
   5.108 +	goat3d_set_node_rotation = libgoat.goat3d_set_node_rotation
   5.109 +	goat3d_set_node_rotation.argtypes = [c_void_p, c_float, c_float, c_float, c_float, c_long]
   5.110 +	goat3d_set_node_rotation.restype = None
   5.111 +
   5.112 +	goat3d_set_node_scaling = libgoat.goat3d_set_node_scaling
   5.113 +	goat3d_set_node_scaling.argtypes = [c_void_p, c_float, c_float, c_float, c_long]
   5.114 +	goat3d_set_node_scaling.restype = None
   5.115 +
   5.116 +	goat3d_set_node_pivot = libgoat.goat3d_set_node_pivot
   5.117 +	goat3d_set_node_pivot.argtypes = [c_void_p, c_float, c_float, c_float]
   5.118 +	goat3d_set_node_pivot.restype = None
   5.119 +
   5.120 +	goat3d_save = libgoat.goat3d_save
   5.121 +	goat3d_save.argtypes = [c_void_p, c_char_p]
   5.122 +
   5.123 +	# initiaize a goat3d object and start filling it up with data
   5.124 +	goat = goat3d_create()
   5.125 +	if not goat:
   5.126 +		oper.report({'ERROR'}, "Failed to create goat3d object")
   5.127 +		return False
   5.128 +
   5.129 +	goat3d_save(goat, fname.encode('utf-8'))
   5.130 +	goat3d_free(goat)
   5.131 +	return True
   5.132 +
   5.133 +