44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import random
|
|
import numpy
|
|
import cv2
|
|
|
|
img_path = "noise.png"
|
|
img = cv2.imread(img_path, 0)
|
|
|
|
|
|
with open("generatedTerrain.obj", 'w') as f:
|
|
increment = 450/110
|
|
for i in range(111):
|
|
for j in range(111):
|
|
height = (img[i][j] - 50)/3
|
|
line = "v " + str(-250 + i * increment) + " " + str(height) + " " + str(-250 + j * increment)
|
|
f.write(line + "\n")
|
|
incrementTx = 1/110
|
|
for i in range(111):
|
|
for j in range(111):
|
|
line = "vt " + str(0 + i * incrementTx) + " " + str(0 + j * incrementTx) + "\n"
|
|
f.write(line)
|
|
#f.write("vt 0.0 0.0\nvt 1.0 1.0\nvt 0.0 1.0\nvt 1.0 1.0\n")
|
|
f.write("s off\n")
|
|
f.write("vn 1.0 1.0 1.0\nvn 1.0 1.0 0.0\n\
|
|
vn 1.0 1.0 -1.0\nvn 0.0 1.0 1.0\nvn 0.0 1.0 0.0\nvn 0.0 1.0 -1.0\n")
|
|
textureIdx = 0
|
|
normalIdx = 0
|
|
for i in range(111*110):
|
|
j = i + 1
|
|
if (j) % 111 == 0:
|
|
pass
|
|
else:
|
|
lineA = "f " + str(j) + "/" + str(j) + "/" + str((normalIdx % 6) + 1) + " "
|
|
textureIdx += 1
|
|
lineB = str(j + 1) + "/" + str(j + 1) + "/" + str((normalIdx % 6) + 1) + " "
|
|
textureIdx += 1
|
|
lineC = str(j + 1 + 111) + "/" + str(j + 1 + 111) + "/" + str((normalIdx % 6) + 1) + " "
|
|
textureIdx += 1
|
|
lineD = str(j + 111) + "/" + str(j + 111) + "/" + str((normalIdx % 6) + 1) + "\n"
|
|
textureIdx += 2
|
|
normalIdx += 1
|
|
line = lineA + lineB + lineC + lineD
|
|
# print(line)
|
|
f.write(line)
|
|
# print(lineA, lineB, lineC, lineD) |