示例#1
0
        public void Execute()
        {
            var maxPairs     = GeometryMath.GetTriangleArraySize(treeBrushIndices.Length);
            var brushPairMap = new NativeHashMap <BrushPair, FindBrushPairsJob.Empty>(maxPairs, Allocator.Temp);
            var empty        = new Empty();

            for (int b0 = 0; b0 < treeBrushIndices.Length; b0++)
            {
                var brushNodeIndex0 = treeBrushIndices[b0];
                //var brushesTouchedByBrush = touchedBrushesByTreeBrushes[b0];
                if (!brushesTouchedByBrushes.TryGetValue(brushNodeIndex0, out BlobAssetReference <BrushesTouchedByBrush> brushesTouchedByBrush))
                {
                    continue;
                }

                ref var intersections = ref brushesTouchedByBrush.Value.brushIntersections;
                if (intersections.Length == 0)
                {
                    continue;
                }

                // Find all intersections between brushes
                for (int i = 0; i < intersections.Length; i++)
                {
                    var intersection    = intersections[i];
                    var brushNodeIndex1 = intersection.nodeIndex;

                    var brushPair = new BrushPair
                    {
                        type            = intersection.type,
                        brushNodeIndex0 = brushNodeIndex0,
                        brushNodeIndex1 = brushNodeIndex1
                    };

                    if (brushNodeIndex0 > brushNodeIndex1) // ensures we do calculations exactly the same for each brush pair
                    {
                        brushPair.Flip();
                    }

                    if (brushPairMap.TryAdd(brushPair, empty))
                    {
                        uniqueBrushPairs.AddNoResize(brushPair);
                    }
                }
            }
示例#2
0
        static bool IsDegenerate(HashedVertices hashedVertices, NativeArray <Edge> edges, int edgeCount)
        {
            if (edgeCount < 3)
            {
                return(true);
            }

            for (int i = 0; i < edgeCount; i++)
            {
                var vertexIndex1 = edges[i].index1;
                var vertex1      = hashedVertices[vertexIndex1];
                for (int j = 0; j < edgeCount; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    var vertexIndexA = edges[j].index1;
                    var vertexIndexB = edges[j].index2;

                    // Loop loops back on same vertex
                    if (vertexIndex1 == vertexIndexA ||
                        vertexIndex1 == vertexIndexB ||
                        vertexIndexA == vertexIndexB)
                    {
                        continue;
                    }

                    var vertexA = hashedVertices[vertexIndexA];
                    var vertexB = hashedVertices[vertexIndexB];

                    var distance = GeometryMath.SqrDistanceFromPointToLineSegment(vertex1, vertexA, vertexB);
                    if (distance <= CSGConstants.kSqrDistanceEpsilon)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }