import math
import cv2
import numpy as np
def twiddle_tile(srcfile, destfile, twiddlefunc):
for line in srcfile:
gps = line.split()
if len(gps) == 4 and gps[0] == "v":
vert = [float(v) for v in gps[1:]]
if vert[1] < 0.0: # don't twiddle bottom of tile
dest.write(line + "\n")
else:
vert_prime = twiddlefunc(vert[0], vert[1], vert[2])
dest.write("v {} {} {}\n".format(*vert_prime))
else: # line is not a vertex, so write it back unchanged
dest.write(line + "\n")
def make_image(image):
stored_image = image
width,height,channels = stored_image.shape
def twiddle(x,y,z):
u = int(((x/35.0) + 1.0) * (float(width)*.5))
v = int(((z/35.0) + 1.0) * (float(height)*.5))
if u < 0:
u = 0
if v < 0:
v = 0
if u >= width:
u = width - 1
if v >= height:
v = height - 1
xp = x
yp = y + (stored_image[u, v, 0] * .05)
zp = z
return (xp, yp, zp)
return twiddle
if __name__ == '__main__':
srcfn = "tile_blank_hires.obj"
destfn = "computed_tile.obj"
image = cv2.imread("newtexture.png")
with open(srcfn, "rt") as src:
with open(destfn, "wt") as dest:
twiddle_tile(src, dest, make_image(image))
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .