]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_mesh.py
Add an object property to control compound exporting
[libs/gl.git] / blender / io_mspgl / export_mesh.py
index c1dd2ac09b488cd87e5e856b7a46ebdedf10b42d..cc8ee6ff9abbc1696fe2e13b16e752761ae7c58c 100644 (file)
@@ -194,6 +194,15 @@ class MeshExporter:
        def export(self, context, out_file):
                if self.compound:
                        objs = context.selected_objects
+                       check = objs
+                       while check:
+                               children = []
+                               for o in check:
+                                       for c in o.children:
+                                               if c.compound:
+                                                       children.append(c)
+                               objs += children
+                               check = children
                else:
                        objs = [context.active_object]
 
@@ -206,7 +215,7 @@ class MeshExporter:
                from .mesh import Mesh
                from .util import Progress
 
-               progress = Progress()
+               progress = Progress(context)
                progress.set_task("Preparing", 0.0, 0.0)
 
                mesh = None
@@ -243,13 +252,20 @@ class MeshExporter:
                        mesh.generate_material_uv()
 
                texunits = []
-               if mesh.uv_layers and self.export_uv!="NONE":
+               force_unit0 = False
+               if mesh.uv_layers and (self.export_uv!="NONE" or self.material_tex):
                        # Figure out which UV layers to export
-                       if self.export_uv=="UNIT0":
-                               if mesh.uv_layers[0].unit==0:
-                                       texunits = [0]
-                       else:
+                       if self.export_uv=="ALL":
                                texunits = range(len(mesh.uv_layers))
+                       elif self.material_tex:
+                               # The material UV layer is always the last one
+                               texunits = [len(mesh.uv_layers)-1]
+                               force_unit0 = True
+                       else:
+                               for i, u in enumerate(mesh.uv_layers):
+                                       if u.unit==0:
+                                               texunits = [i]
+                                               break
                        texunits = [(i, mesh.uv_layers[i]) for i in texunits]
                        texunits = [u for u in texunits if not u[1].hidden]
 
@@ -285,7 +301,7 @@ class MeshExporter:
                fmt = ["NORMAL3"]
                if texunits:
                        for i, u in texunits:
-                               if u.unit==0:
+                               if u.unit==0 or force_unit0:
                                        fmt.append("TEXCOORD2")
                                else:
                                        fmt.append("TEXCOORD2_%d"%u.unit)
@@ -296,7 +312,7 @@ class MeshExporter:
                fmt.append("VERTEX3")
                out_file.begin("vertices", *fmt)
                normal = None
-               uvs = [None]*len(texunits)
+               uvs = [None]*(max(u[0] for u in texunits)+1)
                tan = None
                bino = None
                group = None
@@ -306,7 +322,7 @@ class MeshExporter:
                                normal = v.normal
                        for i, u in texunits:
                                if v.uvs[i]!=uvs[i]:
-                                       if u.unit==0:
+                                       if u.unit==0 or force_unit0:
                                                out_file.write("texcoord2", *v.uvs[i])
                                        else:
                                                out_file.write("multitexcoord2", u.unit, *v.uvs[i])