Check whether obj.faces stores the normal or not If not, it will go over every face and calculate the normal
(self)
| 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): |
no outgoing calls
no test coverage detected