MCPcopy Create free account
hub / github.com/ICE27182/Python-3D-renderer / get_normal

Method get_normal

v1.0/main.py:130–147  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

128
129
130 def get_normal(self):
131 self.vn = []
132 for index, face in enumerate(self.f):
133 v = Tool.vec3_minus_vec3(self.v[face[0][1]], self.v[face[0][0]])
134 u = Tool.vec3_minus_vec3(self.v[face[0][2]], self.v[face[0][0]])
135 normal = [v[1] * u[2] - v[2] * u[1],
136 v[2] * u[0] - v[0] * u[2],
137 v[0] * u[1] - v[1] * u[0]]
138 length = self.sqrt(sum([normal[index]**2 for index in range(3)]))
139 if length == 0:
140 print(f"There might be an issue with the mesh \"{self.name}\". The {self.f.index(face) + 1}th face is either a line or a point.")
141 continue
142 normal = [normal[0] / length, normal[1] / length, normal[2] / length]
143 if normal in self.vn:
144 self.f[index][-1] = self.vn.index(normal)
145 else:
146 self.f[index][-1] = len(self.vn)
147 self.vn.append(normal)
148
149
150 def move_mesh(self, destination):

Callers 2

example.pyFile · 0.45
load_objMethod · 0.45

Calls 1

vec3_minus_vec3Method · 0.80

Tested by

no test coverage detected