Пример #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
        public void Execute()
        {
            var minCount = brushBrushIntersections.Count * 16;

            NativeCollectionHelpers.EnsureCapacityAndClear(ref intersections, minCount);

            for (int i = 0; i < brushBrushIntersections.Count; i++)
            {
                if (!brushBrushIntersections.IsAllocated(i))
                {
                    continue;
                }
                var subArray = brushBrushIntersections[i];
                for (int j = 0; j < subArray.Count; j++)
                {
                    var intersectWith = subArray[j];
                    var pair          = new BrushPair
                    {
                        brushNodeOrder0 = i,
                        brushNodeOrder1 = intersectWith.brushNodeOrder1,
                        type            = intersectWith.type
                    };
                    intersections.Add(pair);
                    pair.Flip();
                    intersections.Add(pair);
                }
            }
            brushIntersectionsWith->Clear();
            if (intersections.Length == 0)
            {
                return;
            }

            intersections.Sort(new ListComparer());

            var currentPair   = intersections[0];
            int previousOrder = currentPair.brushNodeOrder0;

            brushIntersectionsWith->Add(new BrushIntersectWith
            {
                brushNodeOrder1 = currentPair.brushNodeOrder1,
                type            = currentPair.type,
            });
            int2 range = new int2(0, 1);

            for (int i = 1; i < intersections.Length; i++)
            {
                currentPair = intersections[i];
                int currentOrder = currentPair.brushNodeOrder0;
                brushIntersectionsWith->Add(new BrushIntersectWith
                {
                    brushNodeOrder1 = currentPair.brushNodeOrder1,
                    type            = currentPair.type,
                });
                if (currentOrder != previousOrder)
                {
                    //Debug.Log($"{previousOrder} {range}");
                    brushIntersectionsWithRange[previousOrder] = range;
                    previousOrder = currentOrder;
                    range.x       = i;
                    range.y       = 1;
                }
                else
                {
                    range.y++;
                }
            }
            brushIntersectionsWithRange[previousOrder] = range;
        }