goat3d

changeset 39:0e48907847ad

slugishly progressing with the blender exporter
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 09 Oct 2013 16:40:59 +0300
parents 60f2037680ee
children a5c5cec3cb88
files exporters/blendgoat/src/__init__.py exporters/blendgoat/src/export_goat.py
diffstat 2 files changed, 109 insertions(+), 90 deletions(-) [+]
line diff
     1.1 --- a/exporters/blendgoat/src/__init__.py	Mon Oct 07 20:02:57 2013 +0300
     1.2 +++ b/exporters/blendgoat/src/__init__.py	Wed Oct 09 16:40:59 2013 +0300
     1.3 @@ -2,6 +2,7 @@
     1.4  	"name": "Goat3D scene",
     1.5  	"author": "John Tsiombikas",
     1.6  	"version": (0, 1),
     1.7 +	"blender": (2, 63, 0),
     1.8  	"location": "File > Import-Export",
     1.9  	"description": "Mutant Stargoat, Goat3D scene file format: http://code.google.com/p/goat3d/",
    1.10  	"category": "Import-Export"
     2.1 --- a/exporters/blendgoat/src/export_goat.py	Mon Oct 07 20:02:57 2013 +0300
     2.2 +++ b/exporters/blendgoat/src/export_goat.py	Wed Oct 09 16:40:59 2013 +0300
     2.3 @@ -1,4 +1,4 @@
     2.4 -# Goat3D Blender >2.5 exporter
     2.5 +# Goat3D Blender >2.63 exporter
     2.6  import bpy;
     2.7  import ctypes
     2.8  from ctypes import *
     2.9 @@ -8,123 +8,141 @@
    2.10  def export(oper, ctx, fname):
    2.11  	print("Exporting goat3d file: " + fname)
    2.12  
    2.13 +	lib = init_libgoat()
    2.14 +	if not lib:
    2.15 +		return False
    2.16 +
    2.17 +	# initiaize a goat3d object and start filling it up with data
    2.18 +	goat = lib.goat3d_create()
    2.19 +	if not goat:
    2.20 +		oper.report({'ERROR'}, "Failed to create goat3d object")
    2.21 +		return False
    2.22 +
    2.23 +	lib.goat3d_set_name(goat, fname.encode('utf-8'))
    2.24 +
    2.25 +	export_env(ctx, goat, lib)
    2.26 +	export_materials(ctx, goat, lib)
    2.27 +	export_meshes(ctx, goat, lib)
    2.28 +	export_nodes(ctx, goat, lib)
    2.29 +
    2.30 +	lib.goat3d_save(goat, fname.encode('utf-8'))
    2.31 +	lib.goat3d_free(goat)
    2.32 +	return True
    2.33 +
    2.34 +def export_env(ctx, goat, lib):
    2.35 +	return False
    2.36 +
    2.37 +def export_materials(ctx, goat, lib):
    2.38 +	return False
    2.39 +
    2.40 +def export_meshes(ctx, goat, lib):
    2.41 +	print("exporting " + str(len(ctx.scene.objects)) + " objects")
    2.42 +	for obj in ctx.scene.objects:
    2.43 +		if obj.type != 'MESH':
    2.44 +			continue
    2.45 +
    2.46 +		mesh = obj.data
    2.47 +		# make sure we get a tesselated mesh
    2.48 +		mesh.update(calc_tessface = True)
    2.49 +
    2.50 +		triangles = []
    2.51 +		for idx, face in enumerate(mesh.tessfaces):
    2.52 +			fverts = face.vertices
    2.53 +			triangles.append(fverts[0])
    2.54 +			triangles.append(fverts[1])
    2.55 +			triangles.append(fverts[2])
    2.56 +
    2.57 +		print("creating native array of " + str(len(triangles)) + " triangles")
    2.58 +		IndexArrayType = c_int * len(triangles)
    2.59 +		indices = IndexArrayType(triangles)
    2.60 +	return False
    2.61 +
    2.62 +
    2.63 +def export_nodes(ctx, goat, lib):
    2.64 +	return False
    2.65 +
    2.66 +def init_libgoat():
    2.67  	# load all relevant functions from libgoat3d
    2.68  	libname = find_library("goat3d")
    2.69  	if not libname:
    2.70  		oper.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
    2.71 -		return False
    2.72 +		return None
    2.73  
    2.74 -	libgoat = CDLL(libname)
    2.75 -	if not libgoat:
    2.76 +	lib = CDLL(libname)
    2.77 +	if not lib:
    2.78  		oper.report({'ERROR'}, "Could not open goat3d library!")
    2.79 -		return False
    2.80 +		return None
    2.81  
    2.82 -	goat3d_create = libgoat.goat3d_create
    2.83 -	goat3d_create.argtypes = None
    2.84 -	goat3d_create.restype = c_void_p
    2.85 +	lib.goat3d_create.argtypes = None
    2.86 +	lib.goat3d_create.restype = c_void_p
    2.87  
    2.88 -	goat3d_free = libgoat.goat3d_free
    2.89 -	goat3d_free.argtypes = [c_void_p]
    2.90 -	goat3d_free.restype = None
    2.91 +	lib.goat3d_free.argtypes = [c_void_p]
    2.92 +	lib.goat3d_free.restype = None
    2.93  
    2.94 -	goat3d_set_name = libgoat.goat3d_set_name
    2.95 -	goat3d_set_name.argtypes = [c_void_p, c_char_p]
    2.96 +	lib.goat3d_set_name.argtypes = [c_void_p, c_char_p]
    2.97  
    2.98 -	goat3d_set_ambient3f = libgoat.goat3d_set_ambient3f
    2.99 -	goat3d_set_ambient3f.argtypes = [c_void_p, c_float, c_float, c_float]
   2.100 -	goat3d_set_ambient3f.restype = None
   2.101 +	lib.goat3d_set_ambient3f.argtypes = [c_void_p, c_float, c_float, c_float]
   2.102 +	lib.goat3d_set_ambient3f.restype = None
   2.103  
   2.104 -	goat3d_add_mtl = libgoat.goat3d_add_mtl
   2.105 -	goat3d_add_mtl.argtypes = [c_void_p, c_void_p]
   2.106 -	goat3d_add_mtl.restype = None
   2.107 +	lib.goat3d_add_mtl.argtypes = [c_void_p, c_void_p]
   2.108 +	lib.goat3d_add_mtl.restype = None
   2.109  
   2.110 -	goat3d_create_mtl = libgoat.goat3d_create_mtl
   2.111 -	goat3d_create_mtl.argtypes = None
   2.112 -	goat3d_create_mtl.restype = c_void_p
   2.113 +	lib.goat3d_create_mtl.argtypes = None
   2.114 +	lib.goat3d_create_mtl.restype = c_void_p
   2.115  
   2.116 -	goat3d_set_mtl_name = libgoat.goat3d_set_mtl_name
   2.117 -	goat3d_set_mtl_name.argtypes = [c_void_p, c_char_p]
   2.118 -	goat3d_set_mtl_name.restype = None
   2.119 +	lib.goat3d_set_mtl_name.argtypes = [c_void_p, c_char_p]
   2.120 +	lib.goat3d_set_mtl_name.restype = None
   2.121  
   2.122 -	goat3d_set_mtl_attrib4f = libgoat.goat3d_set_mtl_attrib4f
   2.123 -	goat3d_set_mtl_attrib4f.argtypes = [c_void_p, c_char_p, c_float, c_float, c_float, c_float]
   2.124 -	goat3d_set_mtl_attrib4f.restype = None
   2.125 +	lib.goat3d_set_mtl_attrib4f.argtypes = [c_void_p, c_char_p, c_float, c_float, c_float, c_float]
   2.126 +	lib.goat3d_set_mtl_attrib4f.restype = None
   2.127  
   2.128 -	goat3d_set_mtl_attrib_map = libgoat.goat3d_set_mtl_attrib_map
   2.129 -	goat3d_set_mtl_attrib_map.argtypes = [c_void_p, c_char_p, c_char_p]
   2.130 -	goat3d_set_mtl_attrib_map.restype = None
   2.131 +	lib.goat3d_set_mtl_attrib_map.argtypes = [c_void_p, c_char_p, c_char_p]
   2.132 +	lib.goat3d_set_mtl_attrib_map.restype = None
   2.133  
   2.134 -	goat3d_add_mesh = libgoat.goat3d_add_mesh
   2.135 -	goat3d_add_mesh.argtypes = [c_void_p, c_void_p]
   2.136 -	goat3d_add_mesh.restype = None
   2.137 +	lib.goat3d_add_mesh.argtypes = [c_void_p, c_void_p]
   2.138 +	lib.goat3d_add_mesh.restype = None
   2.139  
   2.140 -	goat3d_create_mesh = libgoat.goat3d_create_mesh
   2.141 -	goat3d_create_mesh.argtypes = None
   2.142 -	goat3d_create_mesh.restype = c_void_p
   2.143 +	lib.goat3d_create_mesh.argtypes = None
   2.144 +	lib.goat3d_create_mesh.restype = c_void_p
   2.145  
   2.146 -	goat3d_set_mesh_name = libgoat.goat3d_set_mesh_name
   2.147 -	goat3d_set_mesh_name.argtypes = [c_void_p, c_char_p]
   2.148 -	goat3d_set_mesh_name.restype = None
   2.149 +	lib.goat3d_set_mesh_name.argtypes = [c_void_p, c_char_p]
   2.150 +	lib.goat3d_set_mesh_name.restype = None
   2.151  
   2.152 -	goat3d_set_mesh_mtl = libgoat.goat3d_set_mesh_mtl
   2.153 -	goat3d_set_mesh_mtl.argtypes = [c_void_p, c_void_p]
   2.154 -	goat3d_set_mesh_mtl.restype = None
   2.155 +	lib.goat3d_set_mesh_mtl.argtypes = [c_void_p, c_void_p]
   2.156 +	lib.goat3d_set_mesh_mtl.restype = None
   2.157  
   2.158 -	goat3d_set_mesh_attribs = libgoat.goat3d_set_mesh_attribs
   2.159 -	goat3d_set_mesh_attribs.argtypes = [c_void_p, c_int, c_void_p, c_int]
   2.160 -	goat3d_set_mesh_attribs.restype = None
   2.161 +	lib.goat3d_set_mesh_attribs.argtypes = [c_void_p, c_int, c_void_p, c_int]
   2.162 +	lib.goat3d_set_mesh_attribs.restype = None
   2.163  
   2.164 -	goat3d_set_mesh_faces = libgoat.goat3d_set_mesh_faces
   2.165 -	goat3d_set_mesh_faces.argtypes = [c_void_p, c_void_p, c_int]
   2.166 -	goat3d_set_mesh_faces.restype = None
   2.167 +	lib.goat3d_set_mesh_faces.argtypes = [c_void_p, c_void_p, c_int]
   2.168 +	lib.goat3d_set_mesh_faces.restype = None
   2.169  
   2.170 -	goat3d_add_node = libgoat.goat3d_add_node
   2.171 -	goat3d_add_node.argtypes = [c_void_p, c_void_p]
   2.172 -	goat3d_add_node.restype = None
   2.173 +	lib.goat3d_add_node.argtypes = [c_void_p, c_void_p]
   2.174 +	lib.goat3d_add_node.restype = None
   2.175  
   2.176 -	goat3d_create_node = libgoat.goat3d_create_node
   2.177 -	goat3d_create_node.argtypes = None
   2.178 -	goat3d_create_node.restype = c_void_p
   2.179 +	lib.goat3d_create_node.argtypes = None
   2.180 +	lib.goat3d_create_node.restype = c_void_p
   2.181  
   2.182 -	goat3d_set_node_name = libgoat.goat3d_set_node_name
   2.183 -	goat3d_set_node_name.argtypes = [c_void_p, c_char_p]
   2.184 -	goat3d_set_node_name.restype = None
   2.185 +	lib.goat3d_set_node_name.argtypes = [c_void_p, c_char_p]
   2.186 +	lib.goat3d_set_node_name.restype = None
   2.187  
   2.188 -	goat3d_set_node_object = libgoat.goat3d_set_node_object
   2.189 -	goat3d_set_node_object.argtypes = [c_void_p, c_int, c_void_p]
   2.190 -	goat3d_set_node_object.restype = None
   2.191 +	lib.goat3d_set_node_object.argtypes = [c_void_p, c_int, c_void_p]
   2.192 +	lib.goat3d_set_node_object.restype = None
   2.193  
   2.194 -	goat3d_add_node_child = libgoat.goat3d_add_node_child
   2.195 -	goat3d_add_node_child.argtypes = [c_void_p, c_void_p]
   2.196 -	goat3d_add_node_child.restype = None
   2.197 +	lib.goat3d_add_node_child.argtypes = [c_void_p, c_void_p]
   2.198 +	lib.goat3d_add_node_child.restype = None
   2.199  
   2.200 -	goat3d_set_node_position = libgoat.goat3d_set_node_position
   2.201 -	goat3d_set_node_position.argtypes = [c_void_p, c_float, c_float, c_float, c_long]
   2.202 -	goat3d_set_node_position.restype = None
   2.203 +	lib.goat3d_set_node_position.argtypes = [c_void_p, c_float, c_float, c_float, c_long]
   2.204 +	lib.goat3d_set_node_position.restype = None
   2.205  
   2.206 -	goat3d_set_node_rotation = libgoat.goat3d_set_node_rotation
   2.207 -	goat3d_set_node_rotation.argtypes = [c_void_p, c_float, c_float, c_float, c_float, c_long]
   2.208 -	goat3d_set_node_rotation.restype = None
   2.209 +	lib.goat3d_set_node_rotation.argtypes = [c_void_p, c_float, c_float, c_float, c_float, c_long]
   2.210 +	lib.goat3d_set_node_rotation.restype = None
   2.211  
   2.212 -	goat3d_set_node_scaling = libgoat.goat3d_set_node_scaling
   2.213 -	goat3d_set_node_scaling.argtypes = [c_void_p, c_float, c_float, c_float, c_long]
   2.214 -	goat3d_set_node_scaling.restype = None
   2.215 +	lib.goat3d_set_node_scaling.argtypes = [c_void_p, c_float, c_float, c_float, c_long]
   2.216 +	lib.goat3d_set_node_scaling.restype = None
   2.217  
   2.218 -	goat3d_set_node_pivot = libgoat.goat3d_set_node_pivot
   2.219 -	goat3d_set_node_pivot.argtypes = [c_void_p, c_float, c_float, c_float]
   2.220 -	goat3d_set_node_pivot.restype = None
   2.221 +	lib.goat3d_set_node_pivot.argtypes = [c_void_p, c_float, c_float, c_float]
   2.222 +	lib.goat3d_set_node_pivot.restype = None
   2.223  
   2.224 -	goat3d_save = libgoat.goat3d_save
   2.225 -	goat3d_save.argtypes = [c_void_p, c_char_p]
   2.226 -
   2.227 -	# initiaize a goat3d object and start filling it up with data
   2.228 -	goat = goat3d_create()
   2.229 -	if not goat:
   2.230 -		oper.report({'ERROR'}, "Failed to create goat3d object")
   2.231 -		return False
   2.232 -
   2.233 -	goat3d_save(goat, fname.encode('utf-8'))
   2.234 -	goat3d_free(goat)
   2.235 -	return True
   2.236 -
   2.237 -
   2.238 +	lib.goat3d_save.argtypes = [c_void_p, c_char_p]
   2.239 +	return lib