# HG changeset patch # User John Tsiombikas # Date 1381326059 -10800 # Node ID 0e48907847addb28a2e7757e5f20e24cf6115763 # Parent 60f2037680eeb45f72293500918adbb3bf82a34d slugishly progressing with the blender exporter diff -r 60f2037680ee -r 0e48907847ad exporters/blendgoat/src/__init__.py --- a/exporters/blendgoat/src/__init__.py Mon Oct 07 20:02:57 2013 +0300 +++ b/exporters/blendgoat/src/__init__.py Wed Oct 09 16:40:59 2013 +0300 @@ -2,6 +2,7 @@ "name": "Goat3D scene", "author": "John Tsiombikas", "version": (0, 1), + "blender": (2, 63, 0), "location": "File > Import-Export", "description": "Mutant Stargoat, Goat3D scene file format: http://code.google.com/p/goat3d/", "category": "Import-Export" diff -r 60f2037680ee -r 0e48907847ad exporters/blendgoat/src/export_goat.py --- a/exporters/blendgoat/src/export_goat.py Mon Oct 07 20:02:57 2013 +0300 +++ b/exporters/blendgoat/src/export_goat.py Wed Oct 09 16:40:59 2013 +0300 @@ -1,4 +1,4 @@ -# Goat3D Blender >2.5 exporter +# Goat3D Blender >2.63 exporter import bpy; import ctypes from ctypes import * @@ -8,123 +8,141 @@ def export(oper, ctx, fname): print("Exporting goat3d file: " + fname) + lib = init_libgoat() + if not lib: + return False + + # initiaize a goat3d object and start filling it up with data + goat = lib.goat3d_create() + if not goat: + oper.report({'ERROR'}, "Failed to create goat3d object") + return False + + lib.goat3d_set_name(goat, fname.encode('utf-8')) + + export_env(ctx, goat, lib) + export_materials(ctx, goat, lib) + export_meshes(ctx, goat, lib) + export_nodes(ctx, goat, lib) + + lib.goat3d_save(goat, fname.encode('utf-8')) + lib.goat3d_free(goat) + return True + +def export_env(ctx, goat, lib): + return False + +def export_materials(ctx, goat, lib): + return False + +def export_meshes(ctx, goat, lib): + print("exporting " + str(len(ctx.scene.objects)) + " objects") + for obj in ctx.scene.objects: + if obj.type != 'MESH': + continue + + mesh = obj.data + # make sure we get a tesselated mesh + mesh.update(calc_tessface = True) + + triangles = [] + for idx, face in enumerate(mesh.tessfaces): + fverts = face.vertices + triangles.append(fverts[0]) + triangles.append(fverts[1]) + triangles.append(fverts[2]) + + print("creating native array of " + str(len(triangles)) + " triangles") + IndexArrayType = c_int * len(triangles) + indices = IndexArrayType(triangles) + return False + + +def export_nodes(ctx, goat, lib): + return False + +def init_libgoat(): # load all relevant functions from libgoat3d libname = find_library("goat3d") if not libname: oper.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.") - return False + return None - libgoat = CDLL(libname) - if not libgoat: + lib = CDLL(libname) + if not lib: oper.report({'ERROR'}, "Could not open goat3d library!") - return False + return None - goat3d_create = libgoat.goat3d_create - goat3d_create.argtypes = None - goat3d_create.restype = c_void_p + lib.goat3d_create.argtypes = None + lib.goat3d_create.restype = c_void_p - goat3d_free = libgoat.goat3d_free - goat3d_free.argtypes = [c_void_p] - goat3d_free.restype = None + lib.goat3d_free.argtypes = [c_void_p] + lib.goat3d_free.restype = None - goat3d_set_name = libgoat.goat3d_set_name - goat3d_set_name.argtypes = [c_void_p, c_char_p] + lib.goat3d_set_name.argtypes = [c_void_p, c_char_p] - goat3d_set_ambient3f = libgoat.goat3d_set_ambient3f - goat3d_set_ambient3f.argtypes = [c_void_p, c_float, c_float, c_float] - goat3d_set_ambient3f.restype = None + lib.goat3d_set_ambient3f.argtypes = [c_void_p, c_float, c_float, c_float] + lib.goat3d_set_ambient3f.restype = None - goat3d_add_mtl = libgoat.goat3d_add_mtl - goat3d_add_mtl.argtypes = [c_void_p, c_void_p] - goat3d_add_mtl.restype = None + lib.goat3d_add_mtl.argtypes = [c_void_p, c_void_p] + lib.goat3d_add_mtl.restype = None - goat3d_create_mtl = libgoat.goat3d_create_mtl - goat3d_create_mtl.argtypes = None - goat3d_create_mtl.restype = c_void_p + lib.goat3d_create_mtl.argtypes = None + lib.goat3d_create_mtl.restype = c_void_p - goat3d_set_mtl_name = libgoat.goat3d_set_mtl_name - goat3d_set_mtl_name.argtypes = [c_void_p, c_char_p] - goat3d_set_mtl_name.restype = None + lib.goat3d_set_mtl_name.argtypes = [c_void_p, c_char_p] + lib.goat3d_set_mtl_name.restype = None - goat3d_set_mtl_attrib4f = libgoat.goat3d_set_mtl_attrib4f - goat3d_set_mtl_attrib4f.argtypes = [c_void_p, c_char_p, c_float, c_float, c_float, c_float] - goat3d_set_mtl_attrib4f.restype = None + lib.goat3d_set_mtl_attrib4f.argtypes = [c_void_p, c_char_p, c_float, c_float, c_float, c_float] + lib.goat3d_set_mtl_attrib4f.restype = None - goat3d_set_mtl_attrib_map = libgoat.goat3d_set_mtl_attrib_map - goat3d_set_mtl_attrib_map.argtypes = [c_void_p, c_char_p, c_char_p] - goat3d_set_mtl_attrib_map.restype = None + lib.goat3d_set_mtl_attrib_map.argtypes = [c_void_p, c_char_p, c_char_p] + lib.goat3d_set_mtl_attrib_map.restype = None - goat3d_add_mesh = libgoat.goat3d_add_mesh - goat3d_add_mesh.argtypes = [c_void_p, c_void_p] - goat3d_add_mesh.restype = None + lib.goat3d_add_mesh.argtypes = [c_void_p, c_void_p] + lib.goat3d_add_mesh.restype = None - goat3d_create_mesh = libgoat.goat3d_create_mesh - goat3d_create_mesh.argtypes = None - goat3d_create_mesh.restype = c_void_p + lib.goat3d_create_mesh.argtypes = None + lib.goat3d_create_mesh.restype = c_void_p - goat3d_set_mesh_name = libgoat.goat3d_set_mesh_name - goat3d_set_mesh_name.argtypes = [c_void_p, c_char_p] - goat3d_set_mesh_name.restype = None + lib.goat3d_set_mesh_name.argtypes = [c_void_p, c_char_p] + lib.goat3d_set_mesh_name.restype = None - goat3d_set_mesh_mtl = libgoat.goat3d_set_mesh_mtl - goat3d_set_mesh_mtl.argtypes = [c_void_p, c_void_p] - goat3d_set_mesh_mtl.restype = None + lib.goat3d_set_mesh_mtl.argtypes = [c_void_p, c_void_p] + lib.goat3d_set_mesh_mtl.restype = None - goat3d_set_mesh_attribs = libgoat.goat3d_set_mesh_attribs - goat3d_set_mesh_attribs.argtypes = [c_void_p, c_int, c_void_p, c_int] - goat3d_set_mesh_attribs.restype = None + lib.goat3d_set_mesh_attribs.argtypes = [c_void_p, c_int, c_void_p, c_int] + lib.goat3d_set_mesh_attribs.restype = None - goat3d_set_mesh_faces = libgoat.goat3d_set_mesh_faces - goat3d_set_mesh_faces.argtypes = [c_void_p, c_void_p, c_int] - goat3d_set_mesh_faces.restype = None + lib.goat3d_set_mesh_faces.argtypes = [c_void_p, c_void_p, c_int] + lib.goat3d_set_mesh_faces.restype = None - goat3d_add_node = libgoat.goat3d_add_node - goat3d_add_node.argtypes = [c_void_p, c_void_p] - goat3d_add_node.restype = None + lib.goat3d_add_node.argtypes = [c_void_p, c_void_p] + lib.goat3d_add_node.restype = None - goat3d_create_node = libgoat.goat3d_create_node - goat3d_create_node.argtypes = None - goat3d_create_node.restype = c_void_p + lib.goat3d_create_node.argtypes = None + lib.goat3d_create_node.restype = c_void_p - goat3d_set_node_name = libgoat.goat3d_set_node_name - goat3d_set_node_name.argtypes = [c_void_p, c_char_p] - goat3d_set_node_name.restype = None + lib.goat3d_set_node_name.argtypes = [c_void_p, c_char_p] + lib.goat3d_set_node_name.restype = None - goat3d_set_node_object = libgoat.goat3d_set_node_object - goat3d_set_node_object.argtypes = [c_void_p, c_int, c_void_p] - goat3d_set_node_object.restype = None + lib.goat3d_set_node_object.argtypes = [c_void_p, c_int, c_void_p] + lib.goat3d_set_node_object.restype = None - goat3d_add_node_child = libgoat.goat3d_add_node_child - goat3d_add_node_child.argtypes = [c_void_p, c_void_p] - goat3d_add_node_child.restype = None + lib.goat3d_add_node_child.argtypes = [c_void_p, c_void_p] + lib.goat3d_add_node_child.restype = None - goat3d_set_node_position = libgoat.goat3d_set_node_position - goat3d_set_node_position.argtypes = [c_void_p, c_float, c_float, c_float, c_long] - goat3d_set_node_position.restype = None + lib.goat3d_set_node_position.argtypes = [c_void_p, c_float, c_float, c_float, c_long] + lib.goat3d_set_node_position.restype = None - goat3d_set_node_rotation = libgoat.goat3d_set_node_rotation - goat3d_set_node_rotation.argtypes = [c_void_p, c_float, c_float, c_float, c_float, c_long] - goat3d_set_node_rotation.restype = None + lib.goat3d_set_node_rotation.argtypes = [c_void_p, c_float, c_float, c_float, c_float, c_long] + lib.goat3d_set_node_rotation.restype = None - goat3d_set_node_scaling = libgoat.goat3d_set_node_scaling - goat3d_set_node_scaling.argtypes = [c_void_p, c_float, c_float, c_float, c_long] - goat3d_set_node_scaling.restype = None + lib.goat3d_set_node_scaling.argtypes = [c_void_p, c_float, c_float, c_float, c_long] + lib.goat3d_set_node_scaling.restype = None - goat3d_set_node_pivot = libgoat.goat3d_set_node_pivot - goat3d_set_node_pivot.argtypes = [c_void_p, c_float, c_float, c_float] - goat3d_set_node_pivot.restype = None + lib.goat3d_set_node_pivot.argtypes = [c_void_p, c_float, c_float, c_float] + lib.goat3d_set_node_pivot.restype = None - goat3d_save = libgoat.goat3d_save - goat3d_save.argtypes = [c_void_p, c_char_p] - - # initiaize a goat3d object and start filling it up with data - goat = goat3d_create() - if not goat: - oper.report({'ERROR'}, "Failed to create goat3d object") - return False - - goat3d_save(goat, fname.encode('utf-8')) - goat3d_free(goat) - return True - - + lib.goat3d_save.argtypes = [c_void_p, c_char_p] + return lib