forked from bartvdbraak/blender
Fix for #6946 Save UV layout broken for large wire sizes
This also helped me pinpoint a couple of off by one errors in the UV rasterizing code. One especially noteworthy was that all UV at 1.0 (on the 0..1 scale) didn't render properly.
This commit is contained in:
parent
3d0feeb471
commit
becc4feb5f
@ -9,7 +9,7 @@ Tooltip: 'Export the UV face layout of the selected object to a .TGA or .SVG fil
|
|||||||
|
|
||||||
__author__ = "Martin 'theeth' Poirier"
|
__author__ = "Martin 'theeth' Poirier"
|
||||||
__url__ = ("http://www.blender.org", "http://blenderartists.org/")
|
__url__ = ("http://www.blender.org", "http://blenderartists.org/")
|
||||||
__version__ = "2.4"
|
__version__ = "2.5"
|
||||||
|
|
||||||
__bpydoc__ = """\
|
__bpydoc__ = """\
|
||||||
This script exports the UV face layout of the selected mesh object to
|
This script exports the UV face layout of the selected mesh object to
|
||||||
@ -96,6 +96,11 @@ Notes:<br>See change logs in scripts for a list of contributors.
|
|||||||
# Version 2.4
|
# Version 2.4
|
||||||
# Port from NMesh to Mesh by Daniel Salazar (zanqdo)
|
# Port from NMesh to Mesh by Daniel Salazar (zanqdo)
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
# Version 2.5
|
||||||
|
# Fixed some old off by one rasterizing errors (didn't render points at 1.0 in the UV scale properly).
|
||||||
|
# Fixed wire drawing for non 1 wire size (didn't wrap or stretch properly
|
||||||
|
# and would often raise exceptions)
|
||||||
|
# --------------------------
|
||||||
|
|
||||||
|
|
||||||
FullPython = False
|
FullPython = False
|
||||||
@ -322,7 +327,7 @@ def UV_Export_TGA(vList, size, wsize, wrap, file):
|
|||||||
|
|
||||||
step = 0
|
step = 0
|
||||||
|
|
||||||
img = Buffer(size+1,size+1)
|
img = Buffer(size,size)
|
||||||
|
|
||||||
if wrap:
|
if wrap:
|
||||||
wrapSize = size
|
wrapSize = size
|
||||||
@ -333,15 +338,16 @@ def UV_Export_TGA(vList, size, wsize, wrap, file):
|
|||||||
for f in vList:
|
for f in vList:
|
||||||
for v in f:
|
for v in f:
|
||||||
x = int(v[0] * size)
|
x = int(v[0] * size)
|
||||||
maxx = max (x, maxx)
|
maxx = max (x + wsize - 1, maxx)
|
||||||
minx = min (x, minx)
|
minx = min (x - wsize + 1, minx)
|
||||||
|
|
||||||
y = int(v[1] * size)
|
y = int(v[1] * size)
|
||||||
maxy = max (y, maxy)
|
maxy = max (y + wsize - 1, maxy)
|
||||||
miny = min (y, miny)
|
miny = min (y - wsize + 1, miny)
|
||||||
wrapSize = max (maxx - minx + 1, maxy - miny + 1)
|
wrapSize = max (maxx - minx + 1, maxy - miny + 1)
|
||||||
scale = float (size) / float (wrapSize)
|
scale = float (size) / float (wrapSize)
|
||||||
|
|
||||||
|
max_index = size - 1 # max index of the buffer (height or width)
|
||||||
fnum = 0
|
fnum = 0
|
||||||
fcnt = len (vList)
|
fcnt = len (vList)
|
||||||
|
|
||||||
@ -361,31 +367,31 @@ def UV_Export_TGA(vList, size, wsize, wrap, file):
|
|||||||
if step:
|
if step:
|
||||||
try:
|
try:
|
||||||
for t in xrange(step):
|
for t in xrange(step):
|
||||||
x = int(floor((co1[0] + t*(co2[0]-co1[0])/step) * size))
|
x = int(floor((co1[0] + t*(co2[0]-co1[0])/step) * max_index))
|
||||||
y = int(floor((co1[1] + t*(co2[1]-co1[1])/step) * size))
|
y = int(floor((co1[1] + t*(co2[1]-co1[1])/step) * max_index))
|
||||||
|
|
||||||
|
for dx in range(-1*wsize + 1, wsize):
|
||||||
if wrap:
|
if wrap:
|
||||||
x = x % wrapSize
|
wx = (x + dx) % wrapSize
|
||||||
y = y % wrapSize
|
|
||||||
else:
|
else:
|
||||||
x = int ((x - minx) * scale)
|
wx = int ((x - minx + dx) * scale)
|
||||||
y = int ((y - miny) * scale)
|
|
||||||
|
|
||||||
co = x * 1 + y * 1 * size;
|
for dy in range(-1*wsize + 1, wsize):
|
||||||
|
if wrap:
|
||||||
|
wy = (y + dy) % wrapSize
|
||||||
|
else:
|
||||||
|
wy = int ((y - miny + dy) * scale)
|
||||||
|
|
||||||
|
co = wx * 1 + wy * 1 * size
|
||||||
img[co] = 0
|
img[co] = 0
|
||||||
if wsize > 1:
|
|
||||||
for x in range(-1*wsize + 1,wsize):
|
|
||||||
for y in range(-1*wsize,wsize):
|
|
||||||
img[co + 1 * x + y * 1 * size] = 0
|
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
if not extreme_warning:
|
if not extreme_warning:
|
||||||
print "Skipping extremely long UV edges, check your layout for excentric values"
|
print "Skipping extremely long UV edges, check your layout for excentric values"
|
||||||
extreme_warning = True
|
extreme_warning = True
|
||||||
|
|
||||||
for v in f:
|
for v in f:
|
||||||
x = int(v[0] * size)
|
x = int(v[0] * max_index)
|
||||||
y = int(v[1] * size)
|
y = int(v[1] * max_index)
|
||||||
|
|
||||||
if wrap:
|
if wrap:
|
||||||
x = x % wrapSize
|
x = x % wrapSize
|
||||||
|
Loading…
Reference in New Issue
Block a user