diff --git a/org.budnhead/core/SquaredMap.cs b/org.budnhead/core/SquaredMap.cs index f12337e..4845ccd 100644 --- a/org.budnhead/core/SquaredMap.cs +++ b/org.budnhead/core/SquaredMap.cs @@ -155,6 +155,7 @@ namespace org.budnhead.core model.computeNormals(); model.colorMap(); + model.smoothNormals(); model.rebind(); } diff --git a/org.budnhead/graphics/Model3D.cs b/org.budnhead/graphics/Model3D.cs index 3fea30e..089c233 100644 --- a/org.budnhead/graphics/Model3D.cs +++ b/org.budnhead/graphics/Model3D.cs @@ -4,6 +4,7 @@ using OpenTK.Graphics.OpenGL; using OpenTK; using org.budnhead.core; +using System.Collections.Generic; namespace org.budnhead.graphics { @@ -227,6 +228,37 @@ namespace org.budnhead.graphics { } + public void smoothNormals(){ + Dictionary> dnormals = new Dictionary>(); + + for (int n = 0; n < vertexes.Length ; n++){ + if (!dnormals.ContainsKey(vertexes[n])){ + dnormals.Add(vertexes[n],new List()); + } + + dnormals[vertexes[n]].Add(n); + } + + foreach (Vector3 v in dnormals.Keys){ + Vector3 norm = new Vector3(); + List ind = dnormals[v]; + foreach (int p in ind){ + norm += normals[p]; + } + + norm /= ind.Count; + + foreach (int p in ind){ + normals[p] = norm; + } + } + + bindNormals(); + + } + + + public class Triangle{ Model3D model; int n;