From 40020924ebc8b2a82b6f6cea3dc04561121cebfd Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 8 Oct 2010 18:28:50 +0000 Subject: [PATCH] Blender exporter: support exporting multiple objects as a single compound object --- mesh_export.py | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/mesh_export.py b/mesh_export.py index de11602c..4c18bb48 100644 --- a/mesh_export.py +++ b/mesh_export.py @@ -31,9 +31,6 @@ class Edge: def __getattr__(self, attr): return getattr(self._medge, attr) - def __cmp__(self, other): - return self is other - def check_smooth(self, limit): if len(self.faces)!=2: return @@ -61,7 +58,6 @@ class Vertex: else: self._mvert = mv self.uv = None - self.orig_index = self._mvert.index self.flag = False self.faces = [] self.tan = None @@ -152,6 +148,7 @@ class Mesh: smooth_limit = math.cos(m.degr*math.pi/180) else: smooth_limit = -1 + for e in self.edges.itervalues(): e.v1 = self.verts[e.v1.index] e.v2 = self.verts[e.v2.index] @@ -160,6 +157,23 @@ class Mesh: def __getattr__(self, attr): return getattr(self._mesh, attr) + def splice(self, other): + offset = len(self.verts) + for v in other.verts: + v.index += offset + self.verts.append(v) + + offset = len(self.faces) + for f in other.faces: + f.index += offset + self.faces.append(f) + + for e in other.edges.itervalues(): + e.key = make_edge_key(e.v1.index, e.v2.index) + self.edges[e.key] = e + + self.lines += other.lines + def split_vertices(self, find_group_func, debug): groups = [] for v in self.verts: @@ -389,6 +403,7 @@ class Exporter: self.cache_size = 64 self.export_lines = True self.tbn_vecs = False + self.compound = False self.debug = False self.strip_debug = False self.split_debug = False @@ -499,13 +514,23 @@ class Exporter: def export(self): scene = bpy.data.scenes.active - obj = scene.objects.active - if obj.getType()!="Mesh": - raise Exception, "Can only export Mesh data" + objs = Blender.Object.GetSelected() + if not objs: + raise Exception, "Nothing to export" + for o in objs: + if o.getType()!="Mesh": + raise Exception, "Can only export Mesh data" mesh = Blender.Mesh.New("export_tmp") - mesh.getFromObject(obj) + mesh.getFromObject(objs[0]) mesh = Mesh(mesh) + if self.compound: + bmeshes = [] + for o in objs[1:]: + bmesh = Blender.Mesh.New("export_tmp") + bmesh.getFromObject(o) + bmeshes.append(bmesh) + mesh.splice(Mesh(bmesh)) if self.debug: ntris = sum([len(f.verts)-2 for f in mesh.faces]) @@ -528,6 +553,7 @@ class Exporter: mesh.compute_tbn() strips = [] + loose = mesh.faces if self.use_strips: strips, loose = self.stripify(mesh) @@ -596,6 +622,7 @@ class FrontEnd: self.cache_size = Blender.Draw.Create(self.config.get('cache_size', 64)) self.export_lines = Blender.Draw.Create(self.config.get('export_lines', False)) self.tbn_vecs = Blender.Draw.Create(self.config.get('tbn_vecs', False)) + self.compound = Blender.Draw.Create(self.config.get('compound', False)) self.debug = Blender.Draw.Create(self.config.get('debug', False)) self.strip_debug = Blender.Draw.Create(self.config.get('strip_debug', False)) self.split_debug = Blender.Draw.Create(self.config.get('split_debug', False)) @@ -607,13 +634,14 @@ class FrontEnd: ("Cache size", self.cache_size, 8, 1024, "Cache size to optimize for"), ("Export lines", self.export_lines, "Export lone edges as lines"), ("Compute T/B vecs", self.tbn_vecs, "Compute tangent/binormal vectors for bumpmapping"), + ("Compound", self.compound, "Create a compound mesh of all selected objects"), ("Debugging options"), ("Debug", self.debug), ("Debug strips", self.strip_debug), ("Debug splitting", self.split_debug)]) if ret: dirname = self.temp_config.get("dirname", Blender.sys.dirname(Blender.Get("filename"))) - obj = bpy.data.scenes.active.objects.active + obj = Blender.Object.GetSelected()[0] Blender.Window.FileSelector(self.export, "Export MSP GL mesh", "%s/%s.mesh"%(dirname, obj.name)) def draw(self): @@ -627,6 +655,7 @@ class FrontEnd: self.config['cache_size'] = self.cache_size.val self.config['export_lines'] = self.export_lines.val self.config['tbn_vecs'] = self.tbn_vecs.val + self.config['compound'] = self.compound.val self.config['debug'] = self.debug.val self.config['strip_debug'] = self.strip_debug.val self.config['split_debug'] = self.split_debug.val @@ -644,6 +673,7 @@ class FrontEnd: exp.cache_size = self.cache_size.val exp.export_lines = self.export_lines.val exp.tbn_vecs = self.tbn_vecs.val + exp.compound = self.compound.val exp.debug = self.debug.val exp.strip_debug = self.strip_debug.val exp.split_debug = self.split_debug.val -- 2.43.0