Skip to content

Commit

Permalink
Fixed falsey 0.0's
Browse files Browse the repository at this point in the history
  • Loading branch information
theFroh committed Oct 19, 2015
1 parent 39e90ec commit 8a791a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion imagepacker/imagepacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,20 @@ def pack_images(image_paths, background=(0,0,0,0), format="PNG", extents=None, t
for filename in image_paths:
print("opening", filename)
image = Image.open(filename)
# print(image.size)

image = image.transpose(Image.FLIP_TOP_BOTTOM)
# rescale images
changes = None
if extents and extents[filename]:
# print(filename, image.size)
# print(filename, extents)
image, changes = crop_by_extents(image, extents[filename], tile, crop)

images.append(image)
image_name_map[filename] = image

w,h = image.size
# print(w,h, filename)
# using filename so we can pass back UV info without storing it in image
blocks.append(Block(w,h, data=(filename, changes)))

Expand Down
22 changes: 13 additions & 9 deletions objuvpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def main():

parser.add_argument('--no-crop', dest='crop', action='store_false', help="do not attempt to crop textures to just what is used")
parser.add_argument('--no-tile', dest='tile', action='store_false', help="do not attempt to tile textures outside of UV space (must be cropping)")
parser.add_argument('--no-wrap', dest='wrap', action='store_false', help="don't shift remaining UV verts into [0,1] space")

parser.set_defaults(crop=True)

Expand Down Expand Up @@ -162,10 +163,10 @@ def __init__(self, min_x=None, min_y=None, max_x=None, max_y=None):
self.to_tile = False

def add(self, x,y):
self.min_x = min(self.min_x, x) if self.min_x else x
self.min_y = min(self.min_y, y) if self.min_y else y
self.max_x = max(self.max_x, x) if self.max_x else x
self.max_y = max(self.max_y, y) if self.max_y else y
self.min_x = min(self.min_x, x) if self.min_x is not None else x
self.min_y = min(self.min_y, y) if self.min_y is not None else y
self.max_x = max(self.max_x, x) if self.max_x is not None else x
self.max_y = max(self.max_y, y) if self.max_y is not None else y

def uv_wrap(self):
return (self.max_x - self.min_x, self.max_y - self.min_y)
Expand Down Expand Up @@ -211,7 +212,6 @@ def __repr__(self):
textents[texmap[curr_mtl]].add(uv[0], uv[1])
else:
print(curr_mtl, "not in texmap")
# print(curr_mtl, textents)
# get uv values at uv_idx
# alter them in the original file

Expand All @@ -223,10 +223,10 @@ def __repr__(self):
# to see if the user wishes to tile the texture

for name, extent in textents.items():
# print(name, extent)
print(name, extent)
if extent.tiling():
h_w, v_w = extent.tiling()
if h_w >= 2 or v_w >= 2:
if h_w > 1 or v_w > 1:
print("\nWARNING: The following texture has coordinates that imply it tiles {}x{} times:\n\t{}".format(round(h_w, 1), round(v_w, 1), name))
print("This may be intentional (i.e. tank track textures), or a sign of problematic UV coordinates.")
print("Consider only unwrapping/tiling this if you know that it is intentional.")
Expand Down Expand Up @@ -279,10 +279,14 @@ def __repr__(self):

if curr_mtl and curr_mtl in texmap:
changes = uv_changes[texmap[curr_mtl]]
uv[0] = uv[0] * changes["aspect"][0] + changes["offset"][0]
uv[1] = uv[1] * changes["aspect"][1] + changes["offset"][1]


new_obj_lines[uv_line_idx] = "vt {0} {1}".format(
(uv[0] * changes["aspect"][0] + changes["offset"][0]),
(uv[1] * changes["aspect"][1] + changes["offset"][1])
uv[0], uv[1]
# (uv[0] * changes["aspect"][0] + changes["offset"][0]),
# (uv[1] * changes["aspect"][1] + changes["offset"][1])
)

# get uv values at uv_idx
Expand Down

0 comments on commit 8a791a3

Please sign in to comment.