From ed5029ab2b39d768910e722e9b2931541d5b540d Mon Sep 17 00:00:00 2001 From: MANOLOV02 Date: Fri, 24 Apr 2026 21:47:09 -0300 Subject: [PATCH 1/2] OptimizeFor toSSE: honor withoutNormals when creating bsOptShape The toSSE branch computed `withoutNormals = true` for ModelSpace shaders but always passed `geomData.Normals` to bsOptShape.Create, so the flag had no effect. Normals ended up persisted on shapes that should not carry them. Matches C++ nifly NifFile.cpp:1565-1569, where the toSSE equivalent sets the `normals` pointer to `nullptr` before calling Create at NifFile.cpp:1652. The toLE branch in the same C# file already had the correct `!withoutNormals ? ... : null` pattern; this brings the toSSE branch in line. --- NiflySharp/NifFile.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NiflySharp/NifFile.cs b/NiflySharp/NifFile.cs index 75a912d..02e1863 100644 --- a/NiflySharp/NifFile.cs +++ b/NiflySharp/NifFile.cs @@ -1970,7 +1970,10 @@ public NifFileOptimizeResult OptimizeFor(NifFileOptimizeOptions options) bsOptShape.Rotation = shape.Rotation; bsOptShape.Scale = shape.Scale; - bsOptShape.Create(Header.Version, geomData.Vertices, geomData.Triangles, geomData.UVSets, geomData.Normals); + // Honor the withoutNormals flag — ModelSpace shaders must drop normals. + // Matches C++ nifly NifFile.cpp:1565-1569 nulling `normals` before the + // equivalent Create call at NifFile.cpp:1652. + bsOptShape.Create(Header.Version, geomData.Vertices, geomData.Triangles, geomData.UVSets, !withoutNormals ? geomData.Normals : null); bsOptShape.Flags_ui = shape.Flags_ui; // Restore old bounds for static meshes or when calc bounds is off From bdafad45572149fbb682af34a70b2a805f4da658 Mon Sep 17 00:00:00 2001 From: ousnius Date: Sat, 25 Apr 2026 23:27:06 +0200 Subject: [PATCH 2/2] Remove nifly comment --- NiflySharp/NifFile.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/NiflySharp/NifFile.cs b/NiflySharp/NifFile.cs index 02e1863..43a2f4e 100644 --- a/NiflySharp/NifFile.cs +++ b/NiflySharp/NifFile.cs @@ -1971,8 +1971,6 @@ public NifFileOptimizeResult OptimizeFor(NifFileOptimizeOptions options) bsOptShape.Scale = shape.Scale; // Honor the withoutNormals flag — ModelSpace shaders must drop normals. - // Matches C++ nifly NifFile.cpp:1565-1569 nulling `normals` before the - // equivalent Create call at NifFile.cpp:1652. bsOptShape.Create(Header.Version, geomData.Vertices, geomData.Triangles, geomData.UVSets, !withoutNormals ? geomData.Normals : null); bsOptShape.Flags_ui = shape.Flags_ui;