1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| import csv
vertices = []
tex_coords = []
faces = []
with open('kjj.csv', 'r') as csvfile: reader = csv.DictReader(csvfile) for row in reader: vertex = [ float(row[' Position.x']), float(row[' Position.y']), float(row[' Position.z']), ] vertices.append(vertex) tex_coord = [ float(row[' UV0.x']), float(row[' UV0.y']) ] tex_coords.append(tex_coord)
for i in range(0, len(vertices), 3): face = f"f {i+1}/{i+1}/{i+1} {i+2}/{i+2}/{i+2} {i+3}/{i+3}/{i+3}\n" faces.append(face)
with open('kjj.obj', 'w') as obj_file: for vertex in vertices: obj_file.write(f"v {vertex[0]} {vertex[1]} {vertex[2]}\n") for tex_coord in tex_coords: obj_file.write(f"vt {tex_coord[0]} {tex_coord[1]}\n") for face in faces: obj_file.write(face)
|