From ca3147865e70ad6b3dcfa9b94a06a6f003a3d422 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Wed, 28 Dec 2016 18:54:02 -0800 Subject: [PATCH] Implement face flat/smoothing shading Really I guess this is implementing non-smoothing, since we previously treated all faces as if they had smoothing enabled. It's technically a breaking change, but should make Plasma with runtime lighting match what you'd expect from the Blender 3D viewport. It also matches how PlasmaMax treats meshes by default with no smoothing groups attached. --- korman/exporter/mesh.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/korman/exporter/mesh.py b/korman/exporter/mesh.py index e7e69f5..204806d 100644 --- a/korman/exporter/mesh.py +++ b/korman/exporter/mesh.py @@ -190,6 +190,7 @@ class MeshConverter: for i, tessface in enumerate(mesh.tessfaces): data = geodata[tessface.material_index] face_verts = [] + use_smooth = tessface.use_smooth # Unpack the UV coordinates from each UV Texture layer # NOTE: Blender has no third (W) coordinate @@ -229,7 +230,14 @@ class MeshConverter: source = mesh.vertices[vertex] geoVertex = plGeometrySpan.TempVertex() geoVertex.position = hsVector3(*source.co) - geoVertex.normal = hsVector3(*source.normal) + + # If this face has smoothing, use the vertex normal + # Otherwise, use the face normal + if use_smooth: + geoVertex.normal = hsVector3(*source.normal) + else: + geoVertex.normal = hsVector3(*tessface.normal) + geoVertex.color = hsColor32(*vertex_color) geoVertex.uvs = [hsVector3(uv[0], 1.0 - uv[1], 0.0) for uv in uvws] data.blender2gs[vertex][coluv] = len(data.vertices)