Skip to content

Instantly share code, notes, and snippets.

@UuuNyaa
Last active October 20, 2023 16:46
Show Gist options
  • Select an option

  • Save UuuNyaa/441bd14f2283fea50ae6b0fd9a8c952f to your computer and use it in GitHub Desktop.

Select an option

Save UuuNyaa/441bd14f2283fea50ae6b0fd9a8c952f to your computer and use it in GitHub Desktop.
Face normals correction for toon shader
# 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)
@UuuNyaa
Copy link
Author

UuuNyaa commented May 20, 2022

00002
face_normals

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