public void Execute() { var maxPairs = (maxOrder * maxOrder); NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref usedLookup, maxPairs); uniqueBrushPairs.Clear(); int requiredCapacity = 0; for (int b0 = 0; b0 < allUpdateBrushIndexOrders.Length; b0++) { var brushIndexOrder0 = allUpdateBrushIndexOrders[b0]; int brushNodeOrder0 = brushIndexOrder0.nodeOrder; var brushesTouchedByBrush = brushesTouchedByBrushes[brushNodeOrder0]; if (brushesTouchedByBrush == ChiselBlobAssetReference <BrushesTouchedByBrush> .Null) { continue; } ref var intersections = ref brushesTouchedByBrush.Value.brushIntersections; if (intersections.Length == 0) { continue; } requiredCapacity += intersections.Length + 1; }
// TODO: turn into job void FindPlanePairs(IntersectionType type, [NoAlias] ref BrushMeshBlob mesh, [NoAlias] NativeArray <int> intersectingPlanes, int intersectingPlanesLength, [NoAlias] NativeArray <float4> localSpacePlanesPtr, [NoAlias] ref NativeArray <int> vertexUsed, float4x4 vertexTransform, bool needTransform, [NoAlias] ref NativeArray <PlanePair> usedPlanePairs, [NoAlias] ref NativeArray <float3> usedVertices, out int usedPlanePairsLength, out int usedVerticesLength) { NativeCollectionHelpers.EnsureMinimumSize(ref usedVertices, mesh.localVertices.Length); NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref usedPlanePairs, mesh.halfEdges.Length); if (type != IntersectionType.Intersection) { usedPlanePairsLength = 0; usedVerticesLength = mesh.localVertices.Length; for (int i = 0; i < mesh.localVertices.Length; i++) { usedVertices[i] = mesh.localVertices[i]; } return; } NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref vertexUsed, mesh.localVertices.Length); NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref planeAvailable, mesh.localPlanes.Length); // TODO: this can be partially stored in brushmesh // TODO: optimize ref var halfEdgePolygonIndices = ref mesh.halfEdgePolygonIndices;
public void Execute() { var maxPairs = (maxOrder * maxOrder); NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref usedLookup, maxPairs); for (int b0 = 0; b0 < allUpdateBrushIndexOrders.Length; b0++) { var brushIndexOrder0 = allUpdateBrushIndexOrders[b0]; int brushNodeOrder0 = brushIndexOrder0.nodeOrder; var brushesTouchedByBrush = brushesTouchedByBrushes[brushNodeOrder0]; if (brushesTouchedByBrush == ChiselBlobAssetReference <BrushesTouchedByBrush> .Null) { continue; } ref var intersections = ref brushesTouchedByBrush.Value.brushIntersections; if (intersections.Length == 0) { continue; } if (uniqueBrushPairs->Capacity < intersections.Length) { uniqueBrushPairs->Capacity = intersections.Length; } // Find all intersections between brushes for (int i = 0; i < intersections.Length; i++) { var intersection = intersections[i]; var brushIndexOrder1 = intersection.nodeIndexOrder; int brushNodeOrder1 = brushIndexOrder1.nodeOrder; var brushPair = new BrushPair2 { type = intersection.type, brushIndexOrder0 = brushIndexOrder0, brushIndexOrder1 = brushIndexOrder1 }; if (brushNodeOrder0 > brushNodeOrder1) // ensures we do calculations exactly the same for each brush pair { brushPair.Flip(); } int testIndex = (brushPair.brushIndexOrder0.nodeOrder * maxOrder) + brushPair.brushIndexOrder1.nodeOrder; if (!usedLookup.IsSet(testIndex)) { usedLookup.Set(testIndex, true); uniqueBrushPairs->AddNoResize(brushPair); } } }
public void Execute() { NativeCollectionHelpers.EnsureCapacityAndClear(ref requiredTemporaryBullShitByDOTS, allTreeBrushIndexOrders.Length); NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref foundBrushes, allTreeBrushIndexOrders.Length); for (int i = 0; i < rebuildTreeBrushIndexOrders.Length; i++) { foundBrushes.Set(rebuildTreeBrushIndexOrders[i].nodeOrder, true); requiredTemporaryBullShitByDOTS.AddNoResize(rebuildTreeBrushIndexOrders[i]); } for (int i = 0; i < brushesThatNeedIndirectUpdate.Length; i++) { var indexOrder = brushesThatNeedIndirectUpdate[i]; if (!foundBrushes.IsSet(indexOrder.nodeOrder)) { requiredTemporaryBullShitByDOTS.AddNoResize(indexOrder); foundBrushes.Set(indexOrder.nodeOrder, true); } } requiredTemporaryBullShitByDOTS.Sort(new IntersectionUtility.IndexOrderComparer()); allUpdateBrushIndexOrders.AddRangeNoResize(requiredTemporaryBullShitByDOTS); }
public void Execute(int index1) { if (allTreeBrushIndexOrders.Length == rebuildTreeBrushIndexOrders.Length) { //for (int index1 = 0; index1 < updateBrushIndicesArray.Length; index1++) { var brush1IndexOrder = rebuildTreeBrushIndexOrders[index1]; int brush1NodeOrder = brush1IndexOrder.nodeOrder; NativeListArray <BrushIntersectWith> .NativeList brush1Intersections; if (!brushBrushIntersections.IsAllocated(brush1NodeOrder)) { brush1Intersections = brushBrushIntersections.AllocateWithCapacityForIndex(brush1NodeOrder, 16); } else { brush1Intersections = brushBrushIntersections[brush1NodeOrder]; } for (int index0 = 0; index0 < rebuildTreeBrushIndexOrders.Length; index0++) { var brush0IndexOrder = rebuildTreeBrushIndexOrders[index0]; int brush0NodeOrder = brush0IndexOrder.nodeOrder; if (brush0NodeOrder <= brush1NodeOrder) { continue; } var result = IntersectionUtility.FindIntersection(brush0NodeOrder, brush1NodeOrder, ref brushMeshLookup, ref brushTreeSpaceBounds, ref transformationCache, ref transformedPlanes0, ref transformedPlanes1); if (result == IntersectionType.NoIntersection) { continue; } result = IntersectionUtility.Flip(result); IntersectionUtility.StoreIntersection(brush1Intersections, brush0IndexOrder, result); } } return; } NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref foundBrushes, allTreeBrushIndexOrders.Length); NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref usedBrushes, allTreeBrushIndexOrders.Length); // TODO: figure out a way to avoid needing this for (int a = 0; a < rebuildTreeBrushIndexOrders.Length; a++) { foundBrushes.Set(rebuildTreeBrushIndexOrders[a].nodeOrder, true); } //for (int index1 = 0; index1 < updateBrushIndicesArray.Length; index1++) { var brush1IndexOrder = rebuildTreeBrushIndexOrders[index1]; int brush1NodeOrder = brush1IndexOrder.nodeOrder; NativeListArray <BrushIntersectWith> .NativeList brush1Intersections; if (!brushBrushIntersections.IsAllocated(brush1NodeOrder)) { brush1Intersections = brushBrushIntersections.AllocateWithCapacityForIndex(brush1NodeOrder, 16); } else { brush1Intersections = brushBrushIntersections[brush1NodeOrder]; } for (int index0 = 0; index0 < allTreeBrushIndexOrders.Length; index0++) { var brush0IndexOrder = allTreeBrushIndexOrders[index0]; int brush0NodeOrder = brush0IndexOrder.nodeOrder; if (brush0NodeOrder == brush1NodeOrder) { continue; } var found = foundBrushes.IsSet(brush0NodeOrder); if (brush0NodeOrder < brush1NodeOrder && found) { continue; } var result = IntersectionUtility.FindIntersection(brush0NodeOrder, brush1NodeOrder, ref brushMeshLookup, ref brushTreeSpaceBounds, ref transformationCache, ref transformedPlanes0, ref transformedPlanes1); if (result == IntersectionType.NoIntersection) { continue; } if (!found) { if (!usedBrushes.IsSet(brush0IndexOrder.nodeOrder)) { usedBrushes.Set(brush0IndexOrder.nodeOrder, true); brushesThatNeedIndirectUpdateHashMap.Add(brush0IndexOrder); result = IntersectionUtility.Flip(result); IntersectionUtility.StoreIntersection(brush1Intersections, brush0IndexOrder, result); } } else { if (brush0NodeOrder > brush1NodeOrder) { result = IntersectionUtility.Flip(result); IntersectionUtility.StoreIntersection(brush1Intersections, brush0IndexOrder, result); } } } } }
public void Execute(int index) { var count = input.BeginForEachIndex(index); if (count == 0) { return; } var brushIndexOrder = input.Read <IndexOrder>(); var brushNodeOrder = brushIndexOrder.nodeOrder; var vertexCount = input.Read <int>(); NativeCollectionHelpers.EnsureCapacityAndClear(ref brushVertices, vertexCount); for (int v = 0; v < vertexCount; v++) { var vertex = input.Read <float3>(); brushVertices.AddNoResize(vertex); } var surfaceOuterCount = input.Read <int>(); NativeCollectionHelpers.EnsureSizeAndClear(ref surfaceLoopIndices, surfaceOuterCount); for (int o = 0; o < surfaceOuterCount; o++) { UnsafeList <int> inner = default; var surfaceInnerCount = input.Read <int>(); if (surfaceInnerCount > 0) { inner = new UnsafeList <int>(surfaceInnerCount, Allocator.Temp); //inner.ResizeUninitialized(surfaceInnerCount); for (int i = 0; i < surfaceInnerCount; i++) { inner.AddNoResize(input.Read <int>()); } } surfaceLoopIndices[o] = inner; } var surfaceLoopCount = input.Read <int>(); NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref surfaceLoopAllInfos, surfaceLoopCount); NativeCollectionHelpers.EnsureSizeAndClear(ref surfaceLoopAllEdges, surfaceLoopCount); for (int l = 0; l < surfaceLoopCount; l++) { surfaceLoopAllInfos[l] = input.Read <SurfaceInfo>(); var edgeCount = input.Read <int>(); if (edgeCount > 0) { var edgesInner = new UnsafeList <Edge>(edgeCount, Allocator.Temp); //edgesInner.ResizeUninitialized(edgeCount); for (int e = 0; e < edgeCount; e++) { edgesInner.AddNoResize(input.Read <Edge>()); } surfaceLoopAllEdges[l] = edgesInner; } } input.EndForEachIndex(); if (!basePolygonCache[brushNodeOrder].IsCreated) { return; } var maxLoops = 0; var maxIndices = 0; for (int s = 0; s < surfaceLoopIndices.Length; s++) { if (!surfaceLoopIndices[s].IsCreated) { continue; } var length = surfaceLoopIndices[s].Length; maxIndices += length; maxLoops = math.max(maxLoops, length); } ref var baseSurfaces = ref basePolygonCache[brushNodeOrder].Value.surfaces;