sigma update

This commit is contained in:
2026-01-16 11:00:58 +09:00
parent 59ed03a825
commit 96123d00a2
51 changed files with 6640 additions and 1382 deletions

View File

@@ -239,11 +239,14 @@ namespace MeshDecimator.Algorithms
private ResizableArray<Vector3> vertNormals = null;
private ResizableArray<Vector4> vertTangents = null;
private ResizableArray<Vector4> vertTangents2 = null;
private UVChannels<Vector2> vertUV2D = null;
private UVChannels<Vector3> vertUV3D = null;
private UVChannels<Vector4> vertUV4D = null;
private ResizableArray<Vector4> vertColors = null;
private ResizableArray<BoneWeight> vertBoneWeights = null;
private ResizableArray<float> vertPositionWs = null;
private ResizableArray<float> vertNormalWs = null;
private int remainingVertices = 0;
@@ -508,10 +511,22 @@ namespace MeshDecimator.Algorithms
{
vertNormals[i0] = vertNormals[i1];
}
if (vertPositionWs != null)
{
vertPositionWs[i0] = vertPositionWs[i1];
}
if (vertNormalWs != null)
{
vertNormalWs[i0] = vertNormalWs[i1];
}
if (vertTangents != null)
{
vertTangents[i0] = vertTangents[i1];
}
if (vertTangents2 != null)
{
vertTangents2[i0] = vertTangents2[i1];
}
if (vertUV2D != null)
{
for (int i = 0; i < Mesh.UVChannelCount; i++)
@@ -561,10 +576,22 @@ namespace MeshDecimator.Algorithms
{
vertNormals[i0] = (vertNormals[i0] + vertNormals[i1]) * 0.5f;
}
if (vertPositionWs != null)
{
vertPositionWs[i0] = (vertPositionWs[i0] + vertPositionWs[i1]) * 0.5f;
}
if (vertNormalWs != null)
{
vertNormalWs[i0] = (vertNormalWs[i0] + vertNormalWs[i1]) * 0.5f;
}
if (vertTangents != null)
{
vertTangents[i0] = (vertTangents[i0] + vertTangents[i1]) * 0.5f;
}
if (vertTangents2 != null)
{
vertTangents2[i0] = (vertTangents2[i0] + vertTangents2[i1]) * 0.5f;
}
if (vertUV2D != null)
{
for (int i = 0; i < Mesh.UVChannelCount; i++)
@@ -1080,11 +1107,14 @@ namespace MeshDecimator.Algorithms
var vertNormals = (this.vertNormals != null ? this.vertNormals.Data : null);
var vertTangents = (this.vertTangents != null ? this.vertTangents.Data : null);
var vertTangents2 = (this.vertTangents2 != null ? this.vertTangents2.Data : null);
var vertUV2D = (this.vertUV2D != null ? this.vertUV2D.Data : null);
var vertUV3D = (this.vertUV3D != null ? this.vertUV3D.Data : null);
var vertUV4D = (this.vertUV4D != null ? this.vertUV4D.Data : null);
var vertColors = (this.vertColors != null ? this.vertColors.Data : null);
var vertBoneWeights = (this.vertBoneWeights != null ? this.vertBoneWeights.Data : null);
var vertPositionWs = (this.vertPositionWs != null ? this.vertPositionWs.Data : null);
var vertNormalWs = (this.vertNormalWs != null ? this.vertNormalWs.Data : null);
var triangles = this.triangles.Data;
int triangleCount = this.triangles.Length;
@@ -1102,6 +1132,14 @@ namespace MeshDecimator.Algorithms
{
vertBoneWeights[iDest] = vertBoneWeights[iSrc];
}
if (vertPositionWs != null)
{
vertPositionWs[iDest] = vertPositionWs[iSrc];
}
if (vertNormalWs != null)
{
vertNormalWs[iDest] = vertNormalWs[iSrc];
}
triangle.v0 = triangle.va0;
}
if (triangle.va1 != triangle.v1)
@@ -1113,6 +1151,14 @@ namespace MeshDecimator.Algorithms
{
vertBoneWeights[iDest] = vertBoneWeights[iSrc];
}
if (vertPositionWs != null)
{
vertPositionWs[iDest] = vertPositionWs[iSrc];
}
if (vertNormalWs != null)
{
vertNormalWs[iDest] = vertNormalWs[iSrc];
}
triangle.v1 = triangle.va1;
}
if (triangle.va2 != triangle.v2)
@@ -1124,6 +1170,14 @@ namespace MeshDecimator.Algorithms
{
vertBoneWeights[iDest] = vertBoneWeights[iSrc];
}
if (vertPositionWs != null)
{
vertPositionWs[iDest] = vertPositionWs[iSrc];
}
if (vertNormalWs != null)
{
vertNormalWs[iDest] = vertNormalWs[iSrc];
}
triangle.v2 = triangle.va2;
}
@@ -1153,6 +1207,7 @@ namespace MeshDecimator.Algorithms
vertices[dst].p = vert.p;
if (vertNormals != null) vertNormals[dst] = vertNormals[i];
if (vertTangents != null) vertTangents[dst] = vertTangents[i];
if (vertTangents2 != null) vertTangents2[dst] = vertTangents2[i];
if (vertUV2D != null)
{
for (int j = 0; j < Mesh.UVChannelCount; j++)
@@ -1188,6 +1243,8 @@ namespace MeshDecimator.Algorithms
}
if (vertColors != null) vertColors[dst] = vertColors[i];
if (vertBoneWeights != null) vertBoneWeights[dst] = vertBoneWeights[i];
if (vertPositionWs != null) vertPositionWs[dst] = vertPositionWs[i];
if (vertNormalWs != null) vertNormalWs[dst] = vertNormalWs[i];
}
++dst;
}
@@ -1206,11 +1263,14 @@ namespace MeshDecimator.Algorithms
this.vertices.Resize(vertexCount);
if (vertNormals != null) this.vertNormals.Resize(vertexCount, true);
if (vertTangents != null) this.vertTangents.Resize(vertexCount, true);
if (vertTangents2 != null) this.vertTangents2.Resize(vertexCount, true);
if (vertUV2D != null) this.vertUV2D.Resize(vertexCount, true);
if (vertUV3D != null) this.vertUV3D.Resize(vertexCount, true);
if (vertUV4D != null) this.vertUV4D.Resize(vertexCount, true);
if (vertColors != null) this.vertColors.Resize(vertexCount, true);
if (vertBoneWeights != null) this.vertBoneWeights.Resize(vertexCount, true);
if (vertPositionWs != null) this.vertPositionWs.Resize(vertexCount, true);
if (vertNormalWs != null) this.vertNormalWs.Resize(vertexCount, true);
}
#endregion
#endregion
@@ -1230,7 +1290,10 @@ namespace MeshDecimator.Algorithms
int meshTriangleCount = mesh.TriangleCount;
var meshVertices = mesh.Vertices;
var meshNormals = mesh.Normals;
var meshPositionWs = mesh.PositionWs;
var meshNormalWs = mesh.NormalWs;
var meshTangents = mesh.Tangents;
var meshTangents2 = mesh.Tangents2;
var meshColors = mesh.Colors;
var meshBoneWeights = mesh.BoneWeights;
subMeshCount = meshSubMeshCount;
@@ -1260,7 +1323,10 @@ namespace MeshDecimator.Algorithms
}
vertNormals = InitializeVertexAttribute(meshNormals, "normals");
vertPositionWs = InitializeVertexAttribute(meshPositionWs, "positionWs");
vertNormalWs = InitializeVertexAttribute(meshNormalWs, "normalWs");
vertTangents = InitializeVertexAttribute(meshTangents, "tangents");
vertTangents2 = InitializeVertexAttribute(meshTangents2, "tangents2");
vertColors = InitializeVertexAttribute(meshColors, "colors");
vertBoneWeights = InitializeVertexAttribute(meshBoneWeights, "boneWeights");
@@ -1492,10 +1558,22 @@ namespace MeshDecimator.Algorithms
{
newMesh.Normals = vertNormals.Data;
}
if (vertPositionWs != null)
{
newMesh.PositionWs = vertPositionWs.Data;
}
if (vertNormalWs != null)
{
newMesh.NormalWs = vertNormalWs.Data;
}
if (vertTangents != null)
{
newMesh.Tangents = vertTangents.Data;
}
if (vertTangents2 != null)
{
newMesh.Tangents2 = vertTangents2.Data;
}
if (vertColors != null)
{
newMesh.Colors = vertColors.Data;

View File

@@ -47,11 +47,14 @@ namespace MeshDecimator
private int[][] indices = null;
private Vector3[] normals = null;
private Vector4[] tangents = null;
private Vector4[] tangents2 = null;
private Vector2[][] uvs2D = null;
private Vector3[][] uvs3D = null;
private Vector4[][] uvs4D = null;
private Vector4[] colors = null;
private BoneWeight[] boneWeights = null;
private float[] positionWs = null;
private float[] normalWs = null;
private static readonly int[] emptyIndices = new int[0];
#endregion
@@ -168,6 +171,36 @@ namespace MeshDecimator
}
}
/// <summary>
/// Gets or sets the position W components for this mesh.
/// </summary>
public float[] PositionWs
{
get { return positionWs; }
set
{
if (value != null && value.Length != vertices.Length)
throw new ArgumentException(string.Format("The position Ws must be as many as the vertices. Assigned: {0} Require: {1}", value.Length, vertices.Length));
positionWs = value;
}
}
/// <summary>
/// Gets or sets the normal W components for this mesh.
/// </summary>
public float[] NormalWs
{
get { return normalWs; }
set
{
if (value != null && value.Length != vertices.Length)
throw new ArgumentException(string.Format("The normal Ws must be as many as the vertices. Assigned: {0} Require: {1}", value.Length, vertices.Length));
normalWs = value;
}
}
/// <summary>
/// Gets or sets the tangents for this mesh.
/// </summary>
@@ -183,6 +216,21 @@ namespace MeshDecimator
}
}
/// <summary>
/// Gets or sets the second tangent set for this mesh.
/// </summary>
public Vector4[] Tangents2
{
get { return tangents2; }
set
{
if (value != null && value.Length != vertices.Length)
throw new ArgumentException(string.Format("The second vertex tangents must be as many as the vertices. Assigned: {0} Require: {1}", value.Length, vertices.Length));
tangents2 = value;
}
}
/// <summary>
/// Gets or sets the first UV set for this mesh.
/// </summary>
@@ -298,11 +346,14 @@ namespace MeshDecimator
{
normals = null;
tangents = null;
tangents2 = null;
uvs2D = null;
uvs3D = null;
uvs4D = null;
colors = null;
boneWeights = null;
positionWs = null;
normalWs = null;
}
#endregion