From 53db0897bfa542b4c0e9313a9babd137875fefad Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 11 Feb 2020 12:53:19 -0500 Subject: [PATCH] Ensure normals have no zero component. MOUL/DX9 will not rt light any vertex with a near-zero component in its normal. This prevents shadows and decals from appearing on flat surfaces in Ages exported for the MOUL engine. Instead of fighting with the pipeline and vertex buffer code in Plasma, we'll just clamp the values here. --- korman/exporter/mesh.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/korman/exporter/mesh.py b/korman/exporter/mesh.py index dd4ad5e..f6fdba2 100644 --- a/korman/exporter/mesh.py +++ b/korman/exporter/mesh.py @@ -363,10 +363,13 @@ class MeshConverter(_MeshManager): # 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) + normal = source.normal if use_smooth else tessface.normal + + # MOUL/DX9 craps its pants if any element of the normal is exactly 0.0 + normal = map(lambda x: max(x, 0.01) if x >= 0.0 else min(x, -0.01), normal) + normal = hsVector3(*normal) + normal.normalize() + geoVertex.normal = normal geoVertex.color = hsColor32(*vertex_color) uvs = [hsVector3(uv[0], 1.0 - uv[1], 0.0) for uv in uvws]