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

Method calculate_face_normals

pyrender.py:239–261  ·  view source on GitHub ↗

Check whether obj.faces stores the normal or not If not, it will go over every face and calculate the normal

(self)

Source from the content-addressed store, hash-verified

237
238
239 def calculate_face_normals(self):
240 """
241 Check whether obj.faces stores the normal or not
242 If not, it will go over every face and calculate the normal
243 """
244 if self.faces[0][2] is not None:
245 return
246 for face in self.faces:
247 v = (self.v[face[0][2]][0] - self.v[face[0][0]][0],
248 self.v[face[0][2]][1] - self.v[face[0][0]][1],
249 self.v[face[0][2]][2] - self.v[face[0][0]][2])
250 u = (self.v[face[0][1]][0] - self.v[face[0][0]][0],
251 self.v[face[0][1]][1] - self.v[face[0][0]][1],
252 self.v[face[0][1]][2] - self.v[face[0][0]][2])
253 normal = [v[1] * u[2] - v[2] * u[1],
254 v[2] * u[0] - v[0] * u[2],
255 v[0] * u[1] - v[1] * u[0]]
256 try:
257 index = self.vn.index(normal)
258 except ValueError:
259 index = len(self.vn)
260 self.vn.append(normal)
261 face[2] = index
262
263
264 def calculate_smooth_shading_normals(self):

Callers 2

load_objMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected