Beispiel #1
0
        public RawMesh Run()
        {
            var groupIndex = new int[_mesh.Vertices.Length];

            _vgroup.MakeGroup(_mesh.Vertices, _clusterSize, groupIndex, out var groupCount);

            var triangleGroup = new TriangleGroup(_mesh, groupIndex, groupCount);

            _merger.SetMeshData(_mesh, groupIndex, groupCount, triangleGroup);

            var newVertices = new Vector3[groupCount];

            for (int i = 0; i < newVertices.Length; ++i)
            {
                newVertices[i] = _merger.GetMergedForGroup(i);
            }

            var newTriangles = new List <RawMesh.Triangle>();

            foreach (var tt in triangleGroup.GetAllExternalTriangles())
            {
                newTriangles.Add(new RawMesh.Triangle
                {
                    Va = groupIndex[_mesh.Triangles[tt].Va],
                    Vb = groupIndex[_mesh.Triangles[tt].Vb],
                    Vc = groupIndex[_mesh.Triangles[tt].Vc],
                });
            }

            //TODO eliminate same triangles (two triangles with same 3 vertices in different order)?

            return(new RawMesh
            {
                Vertices = newVertices,
                Triangles = newTriangles.ToArray(),
            });
        }
        public override void SetMeshData(RawMesh mesh, int[] vertexGroup, int groupCount, TriangleGroup triangleGroup)
        {
            //Calculate average for bias.
            var sum   = new Vector3[groupCount];
            var count = new int[groupCount];

            for (int i = 0; i < mesh.Vertices.Length; ++i)
            {
                var g = vertexGroup[i];
                sum[g]   += mesh.Vertices[i];
                count[g] += 1;
            }

            //Run qf solver
            _results = new Vector3[groupCount];
            var c = new QFCoefficient();

            for (int i = 0; i < groupCount; ++i)
            {
                c.Reset();
                var nFaces   = 0;
                var vertices = Enumerable.Range(0, vertexGroup.Length).Where(ii => vertexGroup[ii] == i).ToArray();
                foreach (var tt in triangleGroup.GetExternalTriangles(i))
                {
                    var v1 = mesh.Vertices[mesh.Triangles[tt].Va];
                    var v2 = mesh.Vertices[mesh.Triangles[tt].Vb];
                    var v3 = mesh.Vertices[mesh.Triangles[tt].Vc];
                    var n  = Vector3.Normalize(Vector3.Cross(v2 - v1, v3 - v1));
                    c.AddPlane(v1, n);
                    nFaces += 1;
                }
                c.AddBias(sum[i] / count[i], nFaces * 0.01f + 0.01f);
                _results[i] = QFSolver.Solve(c);
            }
        }
        public override void SetMeshData(RawMesh mesh, int[] vertexGroup, int groupCount, TriangleGroup triangleGroup)
        {
            _sum   = new Vector3[groupCount];
            _count = new int[groupCount];

            for (int i = 0; i < mesh.Vertices.Length; ++i)
            {
                var g = vertexGroup[i];
                _sum[g]   += mesh.Vertices[i];
                _count[g] += 1;
            }
        }
 public abstract void SetMeshData(RawMesh mesh, int[] vertexGroup, int groupCount, TriangleGroup triangleGroup);