graphics.Model3D: +smoothNormals()
parent
5b2a6632e4
commit
0945834780
|
@ -155,6 +155,7 @@ namespace org.budnhead.core
|
|||
|
||||
model.computeNormals();
|
||||
model.colorMap();
|
||||
model.smoothNormals();
|
||||
|
||||
model.rebind();
|
||||
}
|
||||
|
|
|
@ -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<Vector3, List<int>> dnormals = new Dictionary<Vector3, List<int>>();
|
||||
|
||||
for (int n = 0; n < vertexes.Length ; n++){
|
||||
if (!dnormals.ContainsKey(vertexes[n])){
|
||||
dnormals.Add(vertexes[n],new List<int>());
|
||||
}
|
||||
|
||||
dnormals[vertexes[n]].Add(n);
|
||||
}
|
||||
|
||||
foreach (Vector3 v in dnormals.Keys){
|
||||
Vector3 norm = new Vector3();
|
||||
List<int> 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;
|
||||
|
|
Loading…
Reference in New Issue