diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-03-20 10:23:09 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-03-20 10:23:09 +0300 |
commit | a51477093b93fdbca69b47165012c762c46c7e34 (patch) | |
tree | 2f6d626a46c3c2825d8991373a61f977d2d47c63 /release/scripts | |
parent | 1ebc28bead0c28a505cc972b355b5515c0394b4e (diff) |
Geometry.c - rewrote my python box-packer algo in C,
packing 2400 rectanges is about 38x faster.
Use the C implimentation in uvcalc_lightmap and uvcalc_smart_project
Blender.c - filename returning None raises errors with existing scripts, just return "" so string functions on the filename dont raise an error.
Diffstat (limited to 'release/scripts')
-rw-r--r-- | release/scripts/uvcalc_lightmap.py | 17 | ||||
-rw-r--r-- | release/scripts/uvcalc_smart_project.py | 21 |
2 files changed, 18 insertions, 20 deletions
diff --git a/release/scripts/uvcalc_lightmap.py b/release/scripts/uvcalc_lightmap.py index b3a2bcfd9bf..cfca4656444 100644 --- a/release/scripts/uvcalc_lightmap.py +++ b/release/scripts/uvcalc_lightmap.py @@ -38,7 +38,7 @@ from Blender import * import BPyMesh # reload(BPyMesh) -import boxpack2d +# import boxpack2d # reload(boxpack2d) # for developing. from math import sqrt @@ -437,8 +437,9 @@ def lightmap_uvpack(me, BOX_DIV = 8, MARGIN_DIV = 512): # boxes2Pack.append([islandIdx, w,h]) print 'packing boxes', len(pretty_faces), '...', - boxes2Pack = [ [i, pf.width, pf.height] for i, pf in enumerate(pretty_faces)] - packWidth, packHeight, packedLs = boxpack2d.boxPackIter(boxes2Pack) + boxes2Pack = [ [0.0, 0.0, pf.width, pf.height, i] for i, pf in enumerate(pretty_faces)] + packWidth, packHeight = Geometry.BoxPack2D(boxes2Pack) + # print packWidth, packHeight packWidth = float(packWidth) @@ -453,9 +454,9 @@ def lightmap_uvpack(me, BOX_DIV = 8, MARGIN_DIV = 512): # Apply the boxes back to the UV coords. print 'writing back UVs', - for box in enumerate(packedLs): - pf = pretty_faces[box[1][0]] - pf.place(box[1][1], box[1][2], packWidth, packHeight, margin_w, margin_h) + for i, box in enumerate(boxes2Pack): + pretty_faces[i].place(box[0], box[1], packWidth, packHeight, margin_w, margin_h) + # pf.place(box[1][1], box[1][2], packWidth, packHeight, margin_w, margin_h) print 'done' Window.WaitCursor(1) @@ -475,12 +476,12 @@ def main(): return me = ob.getData(mesh=1) - BOX_DIV = Draw.Create(8) + BOX_DIV = Draw.Create(12) MARGIN_DIV = Draw.Create(0.1) if not Draw.PupBlock('Lightmap Pack', [\ - ('Pack Quality: ', BOX_DIV, 1, 32, 'Pre Packing before the complex boxpack'),\ + ('Pack Quality: ', BOX_DIV, 1, 48, 'Pre Packing before the complex boxpack'),\ ('Margin: ', MARGIN_DIV, 0.001, 1.0, 'Size of the margin as a division of the UV')\ ]): return diff --git a/release/scripts/uvcalc_smart_project.py b/release/scripts/uvcalc_smart_project.py index a224ec3ebe4..1bb6dc70ac9 100644 --- a/release/scripts/uvcalc_smart_project.py +++ b/release/scripts/uvcalc_smart_project.py @@ -56,7 +56,7 @@ global USER_FILL_HOLES_QUALITY USER_FILL_HOLES = None USER_FILL_HOLES_QUALITY = None -import boxpack2d +# import boxpack2d # reload(boxpack2d) # for developing. dict_matrix = {} @@ -718,7 +718,7 @@ def packIslands(islandList): # Make a synchronised list with the islands # so we can box pak the islands. - boxes2Pack = [] + packBoxes = [] # Keep a list of X/Y offset so we can save time by writing the # uv's and packed data in one pass. @@ -753,17 +753,18 @@ def packIslands(islandList): islandOffsetList.append((minx, miny)) # Add to boxList. use the island idx for the BOX id. - boxes2Pack.append([islandIdx, w,h]) + packBoxes.append([0, 0, w, h]) islandIdx+=1 - + # Now we have a list of boxes to pack that syncs # with the islands. #print '\tPacking UV Islands...' - Window.DrawProgressBar(0.7, 'Packing %i UV Islands...' % len(boxes2Pack) ) + Window.DrawProgressBar(0.7, 'Packing %i UV Islands...' % len(packBoxes) ) time1 = sys.time() - packWidth, packHeight, packedLs = boxpack2d.boxPackIter(boxes2Pack) + packWidth, packHeight = Geometry.BoxPack2D(packBoxes) + # print 'Box Packing Time:', sys.time() - time1 #if len(pa ckedLs) != len(islandList): @@ -773,9 +774,6 @@ def packIslands(islandList): Window.DrawProgressBar(0.8, 'Writing Packed Data to faces') # Sort by ID, so there in sync again - try: packedLs.sort(lambda key = A: A[0]) - except: packedLs.sort(lambda A, B: cmp(A[0] , B[0])) - islandIdx = len(islandList) # Having these here avoids devide by 0 if islandIdx: @@ -792,9 +790,8 @@ def packIslands(islandList): islandIdx -=1 # Write the packed values to the UV's - - xoffset = packedLs[islandIdx][1] - islandOffsetList[islandIdx][0] - yoffset = packedLs[islandIdx][2] - islandOffsetList[islandIdx][1] + xoffset = packBoxes[islandIdx][0] - islandOffsetList[islandIdx][0] + yoffset = packBoxes[islandIdx][1] - islandOffsetList[islandIdx][1] for f in islandList[islandIdx]: # Offsetting the UV's so they fit in there packed box for uv in f.uv: |