'How does a mesh become normal?
I found a pre-written function that seems to normalize the vertices of the mesh, but I can not figure out what v1, v2, f_n, and f_ y are?
def readFaceInfo(obj_path):
vert_list = np.zeros((1,3), dtype='float32')
face_pts = np.zeros((1,3,3), dtype='float32')
face_axis = np.zeros((1,3,3), dtype='float32')
with open(obj_path, 'r') as f:
while(True):
line = f.readline()
if not line:
break
if line[0:2] == 'v ':
t = line.split('v')[1] # ' 0.1 0.2 0.3'
vertex = np.fromstring(t, sep=' ').reshape((1,3))
vert_list = np.append(vert_list, vertex, axis=0)
elif line[0:2] == 'f ':
t = line.split() # ['f', '1//2', '1/2/3', '1']
p1,p2,p3 = [int(t[i].split('/')[0]) for i in range(1,4)]
points = np.array([vert_list[p1], vert_list[p2], vert_list[p3]])
face_pts = np.append(face_pts, points.reshape(1,3,3), axis=0)
###!!!!!!!!!!!!###
v1 = vert_list[p2] - vert_list[p1] # x axis
v2 = vert_list[p3] - vert_list[p1]
f_n = np.cross(v1, v2) # z axis, face normal
f_y = np.cross(v1, f_n) # y axis
new_axis = np.array([unit(v1), unit(f_y), unit(f_n)])
face_axis = np.append(face_axis, new_axis.reshape((1,3,3)), axis=0)
face_pts = np.delete(face_pts, 0, 0)
face_axis = np.delete(face_axis, 0, 0)
return face_pts, face_axis
I checked the range of vertices and they are all between 0.5 and -0.5. However, does the difference between two vertices in 3D space normalize vertices?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
