| | def normalize_obj_custom(old_file, new_file):
|
| | vertices = []
|
| | other_lines = []
|
| |
|
| |
|
| | with open(old_file, 'r') as file:
|
| | for line in file:
|
| | if line.startswith('v '):
|
| | parts = line.split()
|
| | vertices.append([float(parts[1]), float(parts[2]), float(parts[3])])
|
| | else:
|
| | other_lines.append(line)
|
| |
|
| |
|
| | min_x = min(vertex[0] for vertex in vertices)
|
| | max_x = max(vertex[0] for vertex in vertices)
|
| | min_y = min(vertex[1] for vertex in vertices)
|
| | max_y = max(vertex[1] for vertex in vertices)
|
| | min_z = min(vertex[2] for vertex in vertices)
|
| | max_z = max(vertex[2] for vertex in vertices)
|
| |
|
| |
|
| | normalized_vertices = [
|
| | [
|
| | 2 * ((vertex[0] - min_x) / (max_x - min_x)) - 1,
|
| | 2 * ((vertex[1] - min_y) / (max_y - min_y)) - 1,
|
| | 2 * ((vertex[2] - min_z) / (max_z - min_z))
|
| | ]
|
| | for vertex in vertices
|
| | ]
|
| |
|
| |
|
| | with open(new_file, 'w') as file:
|
| |
|
| | for vertex in normalized_vertices:
|
| | file.write(f"v {vertex[0]} {vertex[1]} {vertex[2]}\n")
|
| |
|
| | file.writelines(other_lines)
|
| |
|
| |
|
| | normalize_obj_custom('textured.obj', 'new.obj') |