Browse Source

Smarter handling of BMesh. Sharp edges are ignored only if auto-smooth

is on, just like Blender does.
pull/270/head
Jrius 3 years ago
parent
commit
8c6e49ea50
  1. 23
      korman/exporter/etlight.py

23
korman/exporter/etlight.py

@ -201,19 +201,13 @@ class LightBaker:
# (If the object has an edge split modifier, well, screw you!) # (If the object has an edge split modifier, well, screw you!)
for bo in blender_objects: for bo in blender_objects:
mesh = bo.data mesh = bo.data
bm = bmesh.new() if self.vcol_layer_name not in mesh.vertex_colors:
bm.from_mesh(mesh) # No vertex color. Baking either failed or is turned off.
light_vcol = bm.loops.layers.color.get(self.vcol_layer_name)
# If no vertex color is found, then baking either failed (error raised by oven)
# or is turned off. Either way, bail out.
if light_vcol is None:
bm.free()
del bm
continue continue
with bmesh_from_object(bo) as bm:
bm.faces.ensure_lookup_table() bm.faces.ensure_lookup_table()
light_vcol = bm.loops.layers.color.get(self.vcol_layer_name)
for face in bm.faces: for face in bm.faces:
for loop in face.loops: for loop in face.loops:
@ -227,9 +221,10 @@ class LightBaker:
if len(edge.link_faces) != 2: if len(edge.link_faces) != 2:
# Either a border edge, or an abomination. # Either a border edge, or an abomination.
continue continue
if not edge.smooth or (mesh.use_auto_smooth and if mesh.use_auto_smooth and (not edge.smooth
edge.calc_face_angle() > mesh.auto_smooth_angle): or edge.calc_face_angle() > mesh.auto_smooth_angle):
# Sharp edge. Don't care. # Normals are split for edges marked as sharp by the user, and edges
# whose angle is above the theshold. Auto smooth must be on in both cases.
continue continue
if face in edge.link_faces: if face in edge.link_faces:
# Alright, this edge is connected to our loop AND our face. # Alright, this edge is connected to our loop AND our face.
@ -247,8 +242,6 @@ class LightBaker:
loop[light_vcol] = max_color loop[light_vcol] = max_color
bm.to_mesh(mesh) bm.to_mesh(mesh)
bm.free()
del bm
def _generate_lightgroup(self, bo, user_lg=None): def _generate_lightgroup(self, bo, user_lg=None):
"""Makes a new light group for the baking process that excludes all Plasma RT lamps""" """Makes a new light group for the baking process that excludes all Plasma RT lamps"""

Loading…
Cancel
Save