Last active
October 20, 2023 16:46
-
-
Save UuuNyaa/441bd14f2283fea50ae6b0fd9a8c952f to your computer and use it in GitHub Desktop.
Face normals correction for toon shader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Face normals correction | |
| # Usage: | |
| # 1. Select a mesh | |
| # 2. Enter edit mode | |
| # 3. Select face vertices | |
| # 4. Return to object mode | |
| # 5. Run this script | |
| # 6. Return to object mode | |
| # 7. Enter edit mode | |
| # 8. Normals are displayed correctly. | |
| import bpy | |
| import bmesh | |
| from mathutils import Vector | |
| mesh: bpy.types.Mesh = bpy.context.active_object.data | |
| normals = [] | |
| vert: bpy.types.MeshVertex | |
| for vert in mesh.vertices: | |
| if not vert.select: | |
| normals.append(Vector()) | |
| else: | |
| normal = vert.normal.copy() | |
| normal.z = 0.0 | |
| normal.normalize() | |
| normals.append(normal) | |
| mesh.normals_split_custom_set_from_vertices(normals) |
Author
UuuNyaa
commented
May 20, 2022


Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment