Skip to content

Commit 2261a0d

Browse files
authored
amended last commit
1 parent c10acd1 commit 2261a0d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/SharpGLTF.Toolkit/Geometry/VertexTypes/VertexPreprocessorLambdas.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,16 @@ static class VertexPreprocessorLambdas
156156

157157
if (vertex.TryGetNormal(out Vector3 n))
158158
{
159-
if (!n._IsFinite()) n = p;
160-
if (n == Vector3.Zero) n = p;
159+
bool dirty = false;
160+
161+
if (!n._IsFinite()) { n = p; dirty = true; }
162+
if (n == Vector3.Zero) { n = p; dirty = true; }
161163
if (n == Vector3.Zero) return null;
162164

163165
var l = n.Length();
164-
if (Math.Abs(l-1) > 0.01f) vertex.SetNormal(Vector3.Normalize(n));
166+
if (Math.Abs(l - 1) > 0.01f) dirty = true;
167+
168+
if (dirty) vertex.SetNormal(Vector3.Normalize(n));
165169
}
166170

167171
if (vertex.TryGetTangent(out Vector4 tw))
@@ -171,13 +175,19 @@ static class VertexPreprocessorLambdas
171175
var t = new Vector3(tw.X, tw.Y, tw.Z);
172176
if (t == Vector3.Zero) return null;
173177

174-
if (tw.W > 0) tw.W = 1;
175-
if (tw.W < 0) tw.W = -1;
178+
bool dirty = false;
179+
180+
if (tw.W > 0) { tw.W = 1; dirty = true; }
181+
if (tw.W < 0) { tw.W = -1; dirty = true; }
176182

177183
var l = t.Length();
178-
if (Math.Abs(l - 1) > 0.01f) t = Vector3.Normalize(t);
184+
if (Math.Abs(l - 1) > 0.01f)
185+
{
186+
t = Vector3.Normalize(t);
187+
dirty = true;
188+
}
179189

180-
vertex.SetTangent(new Vector4(t, tw.W));
190+
if (dirty) vertex.SetTangent(new Vector4(t, tw.W));
181191
}
182192

183193
return vertex;

0 commit comments

Comments
 (0)