goat3d

view exporters/blendgoat/src/export_goat.py @ 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
line source
1 # Goat3D Blender >2.63 exporter
2 import bpy;
3 import ctypes
4 from ctypes import *
5 from ctypes.util import find_library
8 def export(oper, ctx, fname):
9 print("Exporting goat3d file: " + fname)
11 lib = init_libgoat()
12 if not lib:
13 return False
15 # initiaize a goat3d object and start filling it up with data
16 goat = lib.goat3d_create()
17 if not goat:
18 oper.report({'ERROR'}, "Failed to create goat3d object")
19 return False
21 lib.goat3d_set_name(goat, fname.encode('utf-8'))
23 export_env(ctx, goat, lib)
24 export_materials(ctx, goat, lib)
25 export_meshes(ctx, goat, lib)
26 export_nodes(ctx, goat, lib)
28 lib.goat3d_save(goat, fname.encode('utf-8'))
29 lib.goat3d_free(goat)
30 return True
32 def export_env(ctx, goat, lib):
33 return False
35 def export_materials(ctx, goat, lib):
36 return False
38 def export_meshes(ctx, goat, lib):
39 print("exporting " + str(len(ctx.scene.objects)) + " objects")
40 for obj in ctx.scene.objects:
41 if obj.type != 'MESH':
42 continue
44 mesh = obj.data
45 # make sure we get a tesselated mesh
46 mesh.update(calc_tessface = True)
48 triangles = []
49 for idx, face in enumerate(mesh.tessfaces):
50 fverts = face.vertices
51 triangles.append(fverts[0])
52 triangles.append(fverts[1])
53 triangles.append(fverts[2])
55 print("creating native array of " + str(len(triangles)) + " triangles")
56 IndexArrayType = c_int * len(triangles)
57 indices = IndexArrayType(triangles)
58 return False
61 def export_nodes(ctx, goat, lib):
62 return False
64 def init_libgoat():
65 # load all relevant functions from libgoat3d
66 libname = find_library("goat3d")
67 if not libname:
68 oper.report({'ERROR'}, "Could not find the goat3d library! make sure it's installed.")
69 return None
71 lib = CDLL(libname)
72 if not lib:
73 oper.report({'ERROR'}, "Could not open goat3d library!")
74 return None
76 lib.goat3d_create.argtypes = None
77 lib.goat3d_create.restype = c_void_p
79 lib.goat3d_free.argtypes = [c_void_p]
80 lib.goat3d_free.restype = None
82 lib.goat3d_set_name.argtypes = [c_void_p, c_char_p]
84 lib.goat3d_set_ambient3f.argtypes = [c_void_p, c_float, c_float, c_float]
85 lib.goat3d_set_ambient3f.restype = None
87 lib.goat3d_add_mtl.argtypes = [c_void_p, c_void_p]
88 lib.goat3d_add_mtl.restype = None
90 lib.goat3d_create_mtl.argtypes = None
91 lib.goat3d_create_mtl.restype = c_void_p
93 lib.goat3d_set_mtl_name.argtypes = [c_void_p, c_char_p]
94 lib.goat3d_set_mtl_name.restype = None
96 lib.goat3d_set_mtl_attrib4f.argtypes = [c_void_p, c_char_p, c_float, c_float, c_float, c_float]
97 lib.goat3d_set_mtl_attrib4f.restype = None
99 lib.goat3d_set_mtl_attrib_map.argtypes = [c_void_p, c_char_p, c_char_p]
100 lib.goat3d_set_mtl_attrib_map.restype = None
102 lib.goat3d_add_mesh.argtypes = [c_void_p, c_void_p]
103 lib.goat3d_add_mesh.restype = None
105 lib.goat3d_create_mesh.argtypes = None
106 lib.goat3d_create_mesh.restype = c_void_p
108 lib.goat3d_set_mesh_name.argtypes = [c_void_p, c_char_p]
109 lib.goat3d_set_mesh_name.restype = None
111 lib.goat3d_set_mesh_mtl.argtypes = [c_void_p, c_void_p]
112 lib.goat3d_set_mesh_mtl.restype = None
114 lib.goat3d_set_mesh_attribs.argtypes = [c_void_p, c_int, c_void_p, c_int]
115 lib.goat3d_set_mesh_attribs.restype = None
117 lib.goat3d_set_mesh_faces.argtypes = [c_void_p, c_void_p, c_int]
118 lib.goat3d_set_mesh_faces.restype = None
120 lib.goat3d_add_node.argtypes = [c_void_p, c_void_p]
121 lib.goat3d_add_node.restype = None
123 lib.goat3d_create_node.argtypes = None
124 lib.goat3d_create_node.restype = c_void_p
126 lib.goat3d_set_node_name.argtypes = [c_void_p, c_char_p]
127 lib.goat3d_set_node_name.restype = None
129 lib.goat3d_set_node_object.argtypes = [c_void_p, c_int, c_void_p]
130 lib.goat3d_set_node_object.restype = None
132 lib.goat3d_add_node_child.argtypes = [c_void_p, c_void_p]
133 lib.goat3d_add_node_child.restype = None
135 lib.goat3d_set_node_position.argtypes = [c_void_p, c_float, c_float, c_float, c_long]
136 lib.goat3d_set_node_position.restype = None
138 lib.goat3d_set_node_rotation.argtypes = [c_void_p, c_float, c_float, c_float, c_float, c_long]
139 lib.goat3d_set_node_rotation.restype = None
141 lib.goat3d_set_node_scaling.argtypes = [c_void_p, c_float, c_float, c_float, c_long]
142 lib.goat3d_set_node_scaling.restype = None
144 lib.goat3d_set_node_pivot.argtypes = [c_void_p, c_float, c_float, c_float]
145 lib.goat3d_set_node_pivot.restype = None
147 lib.goat3d_save.argtypes = [c_void_p, c_char_p]
148 return lib