I generate my mesh procedurally, everything works out great, but then I need to smooth it out, for the most part the smoothing works great, but in narrow places the smoothing is not uniform.
Here is the code I use for smoothing
public NativeHashMap<int3, int> verticesDic;
public NativeList<int> trianglesList;
public NativeArray<float3> vertexSum;
public NativeArray<int> vertexCount;
{
.....
for(int _i = 0; _i < 3; _i++){ SmoothMesh(); }
.....
}
private void SmoothMesh(){
for(int _i = 0; _i < data[8]; _i++){ vertexSum[_i] = float3.zero; vertexCount[_i] = 0; }
for(int _i = 0; _i < data[9]; _i += 3){
int _v1 = trianglesList[_i];
int _v2 = trianglesList[_i + 1];
int _v3 = trianglesList[_i + 2];
vertexSum[_v1] += vertices[_v2] + vertices[_v3];
vertexSum[_v2] += vertices[_v1] + vertices[_v3];
vertexSum[_v3] += vertices[_v1] + vertices[_v2];
vertexCount[_v1] += 2;
vertexCount[_v2] += 2;
vertexCount[_v3] += 2;
}
for(int _i = 0; _i < data[8]; _i++){
if(vertexCount[_i] > 0){ vertices[_i] = vertexSum[_i] / vertexCount[_i]; }
}
}
Tell me what can be changed in this case for more uniform smoothing?
or maybe some other smoothing option?
Here are the examples that I get




