-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.py
More file actions
38 lines (29 loc) · 1.14 KB
/
Copy pathscript.py
File metadata and controls
38 lines (29 loc) · 1.14 KB
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
import trimesh
import numpy as np
file_path = "/content/ваз 2108.obj"
mesh = trimesh.load(file_path)
if isinstance(mesh, trimesh.Scene):
# If the OBJ file contains multiple objects, take only the first one
mesh = mesh.geometry[list(mesh.geometry.keys())[0]]
# Get the vertices and triangles
vertices = mesh.vertices
triangles = mesh.faces
# Determine the maximum and minimum values for each vertex dimension
x_min = np.min(vertices[:, 0])
x_max = np.max(vertices[:, 0])
y_min = np.min(vertices[:, 1])
y_max = np.max(vertices[:, 1])
z_min = np.min(vertices[:, 2])
z_max = np.max(vertices[:, 2])
# Normalize the vertices to the range [0, 1]
normalized_vertices = (vertices - [x_min, y_min, z_min]) / [x_max - x_min, y_max - y_min, z_max - z_min]
# Open the output file for writing
output_file = open("output.txt", "w")
# Write the normalized vertices to the file
for vertex in normalized_vertices:
output_file.write(f"v {vertex[0]} {vertex[1]} {vertex[2]}\n")
# Write the triangles to the file
for triangle in triangles:
output_file.write(f"f {triangle[0] + 1} {triangle[1] + 1} {triangle[2] + 1}\n")
# Close the output file
output_file.close()