]> git.mxchange.org Git - flightgear.git/blobdiff - utils/Modeller/uv_pack.py
Merge branch 'next' of git://gitorious.org/fg/flightgear into next
[flightgear.git] / utils / Modeller / uv_pack.py
index 6cd1918ed9ee7b8ee6e44f5d4de8300ed9d758b8..245a429c8e6778f620e44509309b329b455a9854 100644 (file)
@@ -33,11 +33,32 @@ Usage:
 (7) export UV layout to SVG (UVs->Scripts->Save UV Face Layout)
 """
 
+
+#--------------------------------------------------------------------------------
+# Copyright (C) 2008  Melchior FRANZ  < mfranz # aon : at >
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#--------------------------------------------------------------------------------
+
+
 MARGIN = 10 # px
 GAP = 10    # px
 
 
-import Blender, math, random
+import Blender
+from random import randint as rand
 
 
 class Abort(Exception):
@@ -67,7 +88,7 @@ def pack():
 
 
        boxes = []
-       meshes = {}
+       unique_meshes = {}
 
        BIG = 1<<30
        Blender.Window.DrawProgressBar(0.0, "packing")
@@ -78,10 +99,10 @@ def pack():
                mesh = o.getData(mesh = 1)
                if not mesh.faceUV:
                        continue
-               if mesh.name in meshes:
+               if mesh.name in unique_meshes:
                        #print "dropping duplicate mesh", mesh.name, "of object", o.name
                        continue
-               meshes[mesh.name] = True
+               unique_meshes[mesh.name] = True
 
                print "\tobject '%s'" % o.name
                xmin = ymin = BIG
@@ -106,9 +127,11 @@ def pack():
        xscale = (1.0 - 2.0 * margin[0]) / boxmax
        yscale = (1.0 - 2.0 * margin[1]) / boxmax
 
-       Blender.Window.DrawProgressBar(0.2, "Erasing texture")
-       drawrect(0, 0, 1, 1) # erase texture
-       for box in boxes:
+       image.reload()
+       #drawrect(0, 0, 1, 1) # erase texture
+
+       for i, box in enumerate(boxes):
+               Blender.Window.DrawProgressBar(float(i) * len(boxes), "Drawing")
                xmin = ymin = BIG
                xmax = ymax = -BIG
                for f in box[6].faces:
@@ -121,8 +144,7 @@ def pack():
                                ymin = min(ymin, p[1])
                                ymax = max(ymax, p[1])
 
-               drawrect(xmin, ymin, xmax, ymax, (random.randint(128, 255), random.randint(128, 255),
-                               random.randint(128, 255), 255))
+               drawrect(xmin, ymin, xmax, ymax, (rand(128, 255), rand(128, 255), rand(128, 255), 255))
                box[6].update()
 
        Blender.Window.RedrawAll()