Exemple #1
0
        private void ProcessEdges(FaceIndexTriplet[] faceIndexTriplets, Vector3[] vertices)
        {
            var vertexTriangleMap = new Dictionary <int, HashSet <FaceIndexTriplet> >();

            foreach (var triplet in faceIndexTriplets)
            {
                for (int i = 0; i < 3; i++)
                {
                    var vertex = triplet[i];
                    if (!vertexTriangleMap.ContainsKey(vertex))
                    {
                        vertexTriangleMap.Add(vertex, new HashSet <FaceIndexTriplet>());
                    }
                    vertexTriangleMap[vertex].Add(triplet);
                }
            }


            //Contains all edges, linked to the triangles that connect to them.
            var edgeTriangleMap = new Dictionary <EdgeIndices, HashSet <FaceIndexTriplet> >();

            //Make a list of all edge index pairs, there are 3 per triangle
            foreach (var triplet in faceIndexTriplets)
            {
                for (int i = 0; i < 3; i++)
                {
                    var i1 = triplet[i];
                    var i2 = triplet[(i + 1) % 3];

                    var edge = new EdgeIndices(i1, i2);

                    if (!edgeTriangleMap.ContainsKey(edge))
                    {
                        edgeTriangleMap.Add(edge, new HashSet <FaceIndexTriplet>());
                    }
                    edgeTriangleMap[edge].UnionWith(vertexTriangleMap[i1]);
                    edgeTriangleMap[edge].UnionWith(vertexTriangleMap[i2]);
                }
            }

            foreach (var edge in edgeTriangleMap)
            {
                _edgeGaussArea.Add(edge.Key, ProcessEdge(edge.Key, edge.Value.ToArray(), vertices));
            }
            //If an edge only has 1 triangle connected to it, it's a mesh edge, and should not have any gaussian area.
        }
Exemple #2
0
        private float ProcessEdge(EdgeIndices edge, FaceIndexTriplet[] connectedTriangles, Vector3[] vertices)
        {
            var v1 = vertices[edge.I1];
            var v2 = vertices[edge.I2];

            var dv = (v2 - v1).normalized;

            var n1 = _pivotNormals[edge.I1];
            var n2 = _pivotNormals[edge.I2];

            var ne = (n1 + n2).normalized;

            var side1 = Vector3.Cross(ne, dv).normalized;
            var side2 = -side1;

            //For v1 on side 1:
            //get the triangle edges on side 1 (dot(n1, v1-t1) should be more than 0)
            //where v1 is the vertex and t1 the side of the triangle pointing away from the vertex
            //then check if said triangles are actually connected to v1 (might be faster to do it the other way around, idk)

            //Side 1
            var nS1V1 = CalculateSidedPivot(edge.I1, connectedTriangles, side1, ne, dv, vertices);
            var nS1V2 = CalculateSidedPivot(edge.I2, connectedTriangles, side1, ne, dv, vertices);

            //Side 2
            var nS2V1 = CalculateSidedPivot(edge.I1, connectedTriangles, side2, ne, dv, vertices);
            var nS2V2 = CalculateSidedPivot(edge.I2, connectedTriangles, side2, ne, dv, vertices);

            var polygon = new UnitSpherePolygon(CircularlySortNormals(new List <Vector3>
            {
                nS1V1,
                nS1V2,
                nS2V1,
                nS2V2
            }));

            return(polygon.GetArea());
        }