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

Method get_normal

v1.0/renderer.py:129–146  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

127
128
129 def get_normal(self):
130 self.vn = []
131 for index, face in enumerate(self.f):
132 v = (self.v[face[0][1]][0] - self.v[face[0][0]][0], self.v[face[0][1]][1] - self.v[face[0][0]][1], self.v[face[0][1]][2] - self.v[face[0][0]][2])
133 u = (self.v[face[0][2]][0] - self.v[face[0][0]][0], self.v[face[0][2]][1] - self.v[face[0][0]][1], self.v[face[0][2]][2] - self.v[face[0][0]][2])
134 normal = [v[1] * u[2] - v[2] * u[1],
135 v[2] * u[0] - v[0] * u[2],
136 v[0] * u[1] - v[1] * u[0]]
137 length = self.sqrt(sum([normal[index]**2 for index in range(3)]))
138 if length == 0:
139 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.")
140 continue
141 normal = [normal[0] / length, normal[1] / length, normal[2] / length]
142 if normal in self.vn:
143 self.f[index][-1] = self.vn.index(normal)
144 else:
145 self.f[index][-1] = len(self.vn)
146 self.vn.append(normal)
147
148
149 def move_mesh(self, destination):

Callers 2

rotate_meshMethod · 0.95
load_objMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected