Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'release/scripts/uvcalc_lightmap.py')
-rw-r--r--release/scripts/uvcalc_lightmap.py56
1 files changed, 43 insertions, 13 deletions
diff --git a/release/scripts/uvcalc_lightmap.py b/release/scripts/uvcalc_lightmap.py
index af9acb09e17..1433ccbd13a 100644
--- a/release/scripts/uvcalc_lightmap.py
+++ b/release/scripts/uvcalc_lightmap.py
@@ -5,8 +5,8 @@ Blender: 242
Group: 'UVCalculation'
Tooltip: 'Give each face non overlapping space on a texture.'
"""
-__author__ = "Campbell Barton"
-__url__ = ("blender", "elysiun")
+__author__ = "Campbell Barton aka ideasman42"
+__url__ = ("blender", "blenderartists.org")
__version__ = "1.0 2006/02/07"
__bpydoc__ = """\
@@ -41,6 +41,18 @@ import BPyMesh
from math import sqrt
+def AngleBetweenVecs(a1,a2):
+ try:
+ return Mathutils.AngleBetweenVecs(a1,a2)
+ except:
+ return 180.0
+
+# python 2.3 has no reversed() iterator. this will only work on lists and tuples
+try:
+ reversed
+except:
+ def reversed(l): return l[::-1]
+
class prettyface(object):
__slots__ = 'uv', 'width', 'height', 'children', 'xoff', 'yoff', 'has_parent', 'rot'
def __init__(self, data):
@@ -148,9 +160,9 @@ class prettyface(object):
if len(uv) == 2:
# match the order of angle sizes of the 3d verts with the UV angles and rotate.
def get_tri_angles(v1,v2,v3):
- a1= Mathutils.AngleBetweenVecs(v2-v1,v3-v1)
- a2= Mathutils.AngleBetweenVecs(v1-v2,v3-v2)
- a3 = 180 - (a1+a2) #a3= Mathutils.AngleBetweenVecs(v2-v3,v1-v3)
+ a1= AngleBetweenVecs(v2-v1,v3-v1)
+ a2= AngleBetweenVecs(v1-v2,v3-v2)
+ a3 = 180 - (a1+a2) #a3= AngleBetweenVecs(v2-v3,v1-v3)
return [(a1,0),(a2,1),(a3,2)]
@@ -237,8 +249,17 @@ PREF_MARGIN_DIV= 512):
face_groups.append(faces)
if PREF_NEW_UVLAYER:
- me.addUVLayer('lightmap')
- me.activeUVLayer = 'lightmap'
+ uvname_org = uvname = 'lightmap'
+ uvnames = me.getUVLayerNames()
+ i = 1
+ while uvname in uvnames:
+ uvname = '%s.%03d' % (uvname_org, i)
+ i+=1
+
+ me.addUVLayer(uvname)
+ me.activeUVLayer = uvname
+
+ del uvnames, uvname_org, uvname
for face_sel in face_groups:
print "\nStarting unwrap"
@@ -328,6 +349,9 @@ PREF_MARGIN_DIV= 512):
if curr_len/4 < side_len/PREF_MARGIN_DIV:
break
+ if not lengths:
+ lengths.append(curr_len)
+
# convert into ints
lengths_to_ints = {}
@@ -399,11 +423,14 @@ PREF_MARGIN_DIV= 512):
# ...limiting this is needed or you end up with bug unused texture spaces
# ...however if its too high, boxpacking is way too slow for high poly meshes.
float_to_int_factor = lengths_to_ints[0][0]
- max_int_dimension = int(((side_len / float_to_int_factor)) / PREF_BOX_DIV)
-
+ if float_to_int_factor > 0:
+ max_int_dimension = int(((side_len / float_to_int_factor)) / PREF_BOX_DIV)
+ ok = True
+ else:
+ max_int_dimension = 0.0 # wont be used
+ ok = False
# RECURSIVE prettyface grouping
- ok = True
while ok:
ok = False
@@ -430,7 +457,10 @@ PREF_MARGIN_DIV= 512):
# Even boxes in groups of 4
for d, boxes in even_dict.items():
if d < max_int_dimension:
- boxes.sort(key = lambda a: len(a.children))
+ # py 2.3 compat
+ try: boxes.sort(key = lambda a: len(a.children))
+ except: boxes.sort(lambda a, b: cmp(len(a.children), len(b.children)))
+
while len(boxes) >= 4:
# print "bar", len(boxes)
ok = True
@@ -517,7 +547,7 @@ def main():
if not Draw.PupBlock('Lightmap Pack', [\
'Context...',
- ('Active Object', PREF_ACT_ONLY, 'If disabled, use all objects for packing the lightmap.'),\
+ ('Active Object', PREF_ACT_ONLY, 'If disabled, include other selected objects for packing the lightmap.'),\
('Selected Faces', PREF_SEL_ONLY, 'Use only selected faces from all selected meshes.'),\
'Image & UVs...',
('Share Tex Space', PREF_PACK_IN_ONE, 'Objects Share texture space, map all objects into 1 uvmap'),\
@@ -538,7 +568,7 @@ def main():
return
meshes = [ ob.getData(mesh=1) ]
else:
- meshes = dict([ (me.name, me) for ob in scn.objects.context for me in (ob.getData(mesh=1),) if not me.lib])
+ meshes = dict([ (me.name, me) for ob in scn.objects.context if ob.type == 'Mesh' for me in (ob.getData(mesh=1),) if not me.lib if len(me.faces)])
meshes = meshes.values()
if not meshes:
Draw.PupMenu('Error%t|No mesh objects selected.')