| | | 1 | | //======================================================================= |
| | | 2 | | // MeshSlabFaceRegions.Joined.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using FixedMathSharp; |
| | | 10 | | using FixedMathSharp.Geometry; |
| | | 11 | | using Gravitas.Colliders; |
| | | 12 | | using Gravitas.Materials; |
| | | 13 | | using SwiftCollections; |
| | | 14 | | using SwiftCollections.Query; |
| | | 15 | | using Member = Gravitas.CollisionHandling.Member<FixedMathSharp.Geometry.FiniteSlabRayFrame>; |
| | | 16 | | |
| | | 17 | | namespace Gravitas.CollisionHandling; |
| | | 18 | | |
| | | 19 | | /// <content>Combines native finite extrusion supports across declared surface members.</content> |
| | | 20 | | internal sealed partial class MeshSlabFaceRegions |
| | | 21 | | { |
| | | 22 | | private MeshJoinedSurfaceRegions<FiniteSlabRayFrame> _joined = null!; |
| | | 23 | | |
| | 10332 | 24 | | private readonly SwiftList<Sample> _joinedEvents = new(); |
| | 10332 | 25 | | private readonly MeshSurfaceConnectivity _boundaryConnectivity = new(); |
| | 10332 | 26 | | private Vector2d[] _boxOffsets = new Vector2d[4]; |
| | 30996 | 27 | | private int[] _memberCounts = Array.Empty<int>(), _orientations = Array.Empty<int>(), _dimensions = Array.Empty<int> |
| | 10332 | 28 | | private bool[] _completeSupports = Array.Empty<bool>(); |
| | 10332 | 29 | | private int _member = -1, _otherMember; |
| | | 30 | | private FixedBoundVolume _slabBounds; |
| | | 31 | | private FiniteSlabRayCandidateVisitor? _joinVisitor; |
| | | 32 | | private FiniteSlabRayCandidateVisitor? _convexSupportVisitor; |
| | | 33 | | private bool _convexSupportCovered; |
| | | 34 | | internal ReadOnlyMemory<Vector2d> PrismOffsets { get; private set; } |
| | 1086 | 35 | | internal int SourceId => _member < 0 ? 0 : _joined.Members[_member].Collider.Id + 1; |
| | 1086 | 36 | | internal int SourceOrder => _member < 0 ? 0 : ((IPhysicsColliderRegistryItem)_joined.Members[_member].Collider).Repl |
| | | 37 | | |
| | 584 | 38 | | internal void ReleaseJoined() { _joined = null!; _member = -1; _joinedEvents.FastClear(); } |
| | | 39 | | |
| | | 40 | | internal void BuildJoined(ReadOnlySpan<(LSMeshCollider Collider, int Triangle)> sources, |
| | | 41 | | LSCollider mover, Fixed64 radius, Fixed64 halfThickness, Vector2d halfFootprint, |
| | | 42 | | ReadOnlySpan<PhysicsMesh> meshes, SwiftDictionary<(PhysicsMesh, int), MeshSurfaceBoundaryDomain> boundaries) |
| | | 43 | | { |
| | 5517 | 44 | | Span<Vector2d> offsets = stackalloc Vector2d[4]; |
| | 5517 | 45 | | if (halfFootprint != Vector2d.Zero) |
| | | 46 | | { |
| | 5544 | 47 | | offsets[0] = -halfFootprint; offsets[1] = new(halfFootprint.X, -halfFootprint.Y); |
| | 5544 | 48 | | offsets[2] = halfFootprint; offsets[3] = new(-halfFootprint.X, halfFootprint.Y); |
| | | 49 | | } |
| | 5517 | 50 | | BuildJoined(sources, mover.Center, mover.Rotation, Fixed64.Zero, radius, halfThickness, |
| | 5517 | 51 | | halfFootprint == Vector2d.Zero ? ReadOnlySpan<Vector2d>.Empty : offsets, |
| | 5517 | 52 | | new(mover.BoundsMin, mover.BoundsMax), mover is LSCylinderCollider, meshes, boundaries); |
| | 5517 | 53 | | } |
| | | 54 | | |
| | | 55 | | internal void BuildJoined(ReadOnlySpan<(LSMeshCollider Collider, int Triangle)> sources, |
| | | 56 | | Vector3d center, FixedQuaternion rotation, Fixed64 length, Fixed64 radius, Fixed64 halfThickness, |
| | | 57 | | ReadOnlySpan<Vector2d> offsets, FixedBoundVolume bounds, bool fullHeight, |
| | | 58 | | ReadOnlySpan<PhysicsMesh> meshes, SwiftDictionary<(PhysicsMesh, int), MeshSurfaceBoundaryDomain> boundaries) |
| | | 59 | | { |
| | 7377 | 60 | | _slabBounds = bounds; |
| | 7379 | 61 | | if (_boxOffsets.Length < offsets.Length) Array.Resize(ref _boxOffsets, offsets.Length); |
| | 7377 | 62 | | offsets.CopyTo(_boxOffsets); |
| | 7377 | 63 | | PrismOffsets = _boxOffsets.AsMemory(0, offsets.Length); |
| | 7377 | 64 | | _joined ??= new(); |
| | 14754 | 65 | | _joined.Prepare(sources, meshes, boundaries); _joinedEvents.FastClear(); |
| | 7377 | 66 | | if (_memberCounts.Length < _joined.Inputs.Count) |
| | | 67 | | { |
| | 162 | 68 | | Array.Resize(ref _memberCounts, _joined.Inputs.Count); |
| | 324 | 69 | | Array.Resize(ref _orientations, _joined.Inputs.Count); Array.Resize(ref _dimensions, _joined.Inputs.Count); |
| | 162 | 70 | | Array.Resize(ref _completeSupports, _joined.Inputs.Count); |
| | | 71 | | } |
| | 7377 | 72 | | _joined.PrepareResponseComponents(); |
| | 41824 | 73 | | for (int index = 0; index < _joined.Inputs.Count; index++) |
| | 27070 | 74 | | { _memberCounts[index] = 0; _completeSupports[index] = true; } |
| | 41824 | 75 | | for (int index = 0; index < _joined.Inputs.Count; index++) |
| | | 76 | | { |
| | 27070 | 77 | | Member member = _joined.Members[index]; PhysicsMesh mesh = member.Collider.Mesh; |
| | 13535 | 78 | | mesh.GetGeometryTriangleVertices(member.Triangle, out Vector3d a, out Vector3d b, out Vector3d c); |
| | 13535 | 79 | | member.Frame = new(new FixedTriangle(a, b, c), mesh.GeometryFrame, |
| | 13535 | 80 | | center, rotation, length, radius, halfThickness, fullHeight: fullHeight); |
| | 27070 | 81 | | member.Admitted.FastClear(); member.Collider.GetTrianglesInBounds(bounds, _joined.Candidates); |
| | 64834 | 82 | | foreach (int triangle in _joined.Candidates.AsReadOnlySpan()) |
| | | 83 | | { |
| | 18882 | 84 | | if (mesh.GetManifoldSurfaceOwner(triangle) != member.Owner) continue; |
| | 18862 | 85 | | mesh.GetGeometryTriangleVertices(triangle, out a, out b, out c); |
| | 28270 | 86 | | if (member.Frame.Section.IntersectsTriangle(new FixedTriangle(a, b, c), PrismOffsets.Span)) member.Admit |
| | | 87 | | } |
| | 22704 | 88 | | if (member.Admitted.Count > 0) _joined.AddAdmittedMember(index); |
| | | 89 | | } |
| | 7377 | 90 | | bool wideBanks = false; |
| | 41824 | 91 | | foreach (Member member in _joined.Members.AsReadOnlySpan()[.._joined.Inputs.Count]) |
| | | 92 | | { |
| | 13535 | 93 | | wideBanks |= member.Frame.UsesWideBanks; |
| | 189781 | 94 | | foreach (var span in member.Boundary.Spans) wideBanks |= span.Interval.HasWideBounds; |
| | | 95 | | } |
| | 7377 | 96 | | if (wideBanks) |
| | 30 | 97 | | foreach (Member member in _joined.Members.AsReadOnlySpan()[.._joined.Inputs.Count]) |
| | 10 | 98 | | member.Frame = member.Frame.WithWideParameters(); |
| | 7377 | 99 | | CertifyCompleteSupports(); |
| | 41824 | 100 | | for (int index = 0; index < _joined.Inputs.Count; index++) |
| | | 101 | | { |
| | 13535 | 102 | | Member member = _joined.Members[index]; |
| | | 103 | | // Only an actually intersected coplanar component owns response. |
| | | 104 | | // The carrier's pair remains an ordinary, genuine overlap; samples |
| | | 105 | | // keep their own finite supplier, material and provenance. |
| | 13591 | 106 | | if (_joined.GetResponseMember(index) < 0) { _joined.AddRegions(index, 0); continue; } |
| | 13507 | 107 | | PhysicsMesh mesh = member.Collider.Mesh; |
| | 20387 | 108 | | if (_completeSupports[_joined.FindResponseComponent(index)] && member.Admitted.Count == 0) { _joined.AddRegi |
| | 10067 | 109 | | if (!CanReachSupport(member.Frame, mesh, member.Collider.Bounds)) |
| | 1438 | 110 | | { _joined.AddRegions(index, 0); continue; } |
| | 9348 | 111 | | member.Connectivity.BuildSlab(mesh, member.Triangle, member.Frame.Section, PrismOffsets, member.Admitted.AsR |
| | 18696 | 112 | | _member = index; PrepareFrame(member.Frame, PrismOffsets.Span); |
| | 18696 | 113 | | _orientations[index] = _orientation; _dimensions[index] = _supportDimension; |
| | 9348 | 114 | | if (_completeSupports[_joined.FindResponseComponent(index)]) |
| | | 115 | | { |
| | 22185 | 116 | | _events.FastClear(); _region = 0; _intrinsicOnly = _usesSupportGraph = false; |
| | | 117 | | // An admitted member without a pole still connects neighboring |
| | | 118 | | // suppliers through the shared finite span graph. |
| | 7395 | 119 | | RegionCount = 1; |
| | 7395 | 120 | | VisitPlane(PrismOffsets.Span); |
| | | 121 | | } |
| | 2514 | 122 | | else if (!TryUseConvexSupport(mesh, member.Triangle)) Build(mesh, member.Triangle, member.Connectivity, Pris |
| | 561 | 123 | | member.Admitted.Count > 0 && ContainsSection(mesh, member.Triangle, member.Frame, PrismOffsets.Span)); |
| | 18696 | 124 | | _memberCounts[index] = RegionCount; _joined.AddRegions(index, RegionCount); |
| | 111711 | 125 | | foreach (Sample sample in _events.AsReadOnlySpan()) _joinedEvents.Add(sample.WithRegion(member.Offset + samp |
| | | 126 | | } |
| | 14754 | 127 | | JoinSupportSpans(); _joined.CompleteRegions(); |
| | 7377 | 128 | | RegionCount = _joined.Roots.Count; |
| | 76764 | 129 | | for (int index = 0; index < _joinedEvents.Count; index++) |
| | | 130 | | { |
| | 31005 | 131 | | Sample sample = _joinedEvents[index]; |
| | 31005 | 132 | | _joinedEvents[index] = sample.WithRegion(_joined.RegionByRoot[_joined.Find(sample.Region)]); |
| | | 133 | | } |
| | 7377 | 134 | | _joined.Commit(); |
| | 7377 | 135 | | } |
| | | 136 | | |
| | | 137 | | private bool TryUseConvexSupport(PhysicsMesh mesh, int triangle) |
| | | 138 | | { |
| | | 139 | | // A nonaxial extrusion support is a point, segment or rectangle. Its |
| | | 140 | | // exact extremes inside one convex fill certify the entire support. |
| | | 141 | | // Axial disk caps need the existing perimeter proof, not sampled poles. |
| | 1953 | 142 | | if (mesh.GetConvexCoplanarPatchCornerVertexIndices(triangle).IsEmpty |
| | 2019 | 143 | | || _frame.Plane.Normal.X.IsZero && _frame.Plane.Normal.Z.IsZero) return false; |
| | 5661 | 144 | | _events.FastClear(); _region = 0; _intrinsicOnly = _usesSupportGraph = false; |
| | 1887 | 145 | | _convexSupportCovered = true; |
| | 1887 | 146 | | _convexSupportVisitor ??= AdmitConvexSupport; |
| | 1887 | 147 | | VisitPlane(PrismOffsets.Span, _convexSupportVisitor); |
| | 2877 | 148 | | if (!_convexSupportCovered || _events.Count == 0) { _events.FastClear(); return false; } |
| | 1392 | 149 | | RegionCount = 1; |
| | 1392 | 150 | | return true; |
| | | 151 | | } |
| | | 152 | | |
| | | 153 | | private void AdmitConvexSupport(scoped in FiniteSlabRaySelection candidate) |
| | | 154 | | { |
| | 4960 | 155 | | if (candidate.CompareDepth(BorrowPeak()) != 0) return; |
| | 4634 | 156 | | Member member = _joined.Members[_member]; |
| | 4634 | 157 | | PhysicsMesh mesh = member.Collider.Mesh; |
| | 4634 | 158 | | ReadOnlySpan<int> corners = mesh.GetConvexCoplanarPatchCornerVertexIndices(member.Triangle); |
| | 4634 | 159 | | ReadOnlySpan<Vector3d> vertices = mesh.GeometryVertices; |
| | 16824 | 160 | | for (int corner = 1; corner < corners.Length - 1; corner++) |
| | 7487 | 161 | | if (candidate.ContainsTrianglePoint(member.Frame, |
| | 7487 | 162 | | new(vertices[corners[0]], vertices[corners[corner]], vertices[corners[corner + 1]]), member.Frame)) |
| | 7418 | 163 | | { AdmitPoint(candidate); return; } |
| | 925 | 164 | | _convexSupportCovered = false; |
| | 925 | 165 | | } |
| | | 166 | | |
| | | 167 | | private void CertifyCompleteSupports() |
| | | 168 | | { |
| | 41824 | 169 | | for (int index = 0; index < _joined.Inputs.Count; index++) |
| | | 170 | | { |
| | 27070 | 171 | | Member member = _joined.Members[index]; int component = _joined.FindResponseComponent(index); |
| | 13535 | 172 | | if (!_completeSupports[component]) continue; |
| | 12394 | 173 | | if (!member.BoundaryTrusted || !member.Frame.Plane.Normal.X.IsZero || !member.Frame.Plane.Normal.Z.IsZero) |
| | 3064 | 174 | | { _completeSupports[component] = false; continue; } |
| | | 175 | | // For an axial cap the support footprint equals the original |
| | | 176 | | // convex section. One filled point and no real perimeter crossing |
| | | 177 | | // certify complete fill, including exclusion of enclosed holes. |
| | 108594 | 178 | | for (int span = 0; span < member.Boundary.Spans.Length; span++) |
| | | 179 | | { |
| | 43452 | 180 | | var edge = member.Boundary.Spans[span]; |
| | 43452 | 181 | | if (!member.JoinedSpans[span] && member.Frame.Section.IntersectsSegment(new FixedSegment(edge.Start, edg |
| | 34 | 182 | | { _completeSupports[component] = false; break; } |
| | | 183 | | } |
| | | 184 | | } |
| | 7377 | 185 | | } |
| | | 186 | | |
| | | 187 | | private bool ContainsSupportPoint(scoped in FiniteSlabRaySelection candidate) |
| | | 188 | | { |
| | 33680 | 189 | | Member member = _joined.Members[_member]; |
| | 107791 | 190 | | foreach (int triangle in member.Admitted.AsReadOnlySpan()) |
| | | 191 | | { |
| | 33738 | 192 | | member.Collider.Mesh.GetGeometryTriangleVertices(triangle, out Vector3d a, out Vector3d b, out Vector3d c); |
| | 60783 | 193 | | if (candidate.ContainsTrianglePoint(member.Frame, new(a, b, c), member.Frame)) return true; |
| | | 194 | | } |
| | 6635 | 195 | | return false; |
| | | 196 | | } |
| | | 197 | | |
| | | 198 | | private void GatherJoinedBoundary(PhysicsMesh mesh, int triangle, MeshSurfaceConnectivity connectivity) |
| | | 199 | | { |
| | 261 | 200 | | Member member = _joined.Members[_member]; |
| | 261 | 201 | | Span<ulong> values = stackalloc ulong[SelectionWords]; |
| | 261 | 202 | | Span<sbyte> signs = stackalloc sbyte[FiniteSlabRaySelection.SignCount]; |
| | 2780 | 203 | | for (int span = 0; span < member.Boundary.Spans.Length; span++) |
| | | 204 | | { |
| | 1129 | 205 | | var piece = member.Boundary.Spans[span]; |
| | 1129 | 206 | | if (member.JoinedSpans[span]) continue; |
| | 853 | 207 | | FixedBoundBox bounds = mesh.GeometryFrame.GetWorldBounds(Vector3d.Min(piece.Start, piece.End), |
| | 853 | 208 | | Vector3d.Max(piece.Start, piece.End)); |
| | 853 | 209 | | if (!CanReachSupport(member.Frame, mesh, bounds)) continue; |
| | 93 | 210 | | RationalSegmentInterval clip = member.GetRetainedInterval(ref span); |
| | 93 | 211 | | _region = _usesSupportGraph ? MeshSurfaceBoundaryTopology.FindSupportEdgeRegion(mesh, member.Owner, |
| | 93 | 212 | | piece.First, piece.Second, connectivity, this, null) : 0; |
| | 93 | 213 | | if (_region < 0) continue; |
| | 85 | 214 | | var maximum = new FiniteSlabRaySelection(values, signs, _fieldWords); |
| | 85 | 215 | | FiniteSlabRayExtrema.AccumulateSegment(_frame, new FixedSegment(piece.Start, piece.End), clip, |
| | 85 | 216 | | PrismOffsets.Span, _orientation, ref maximum, _visitor); |
| | | 217 | | } |
| | 261 | 218 | | } |
| | | 219 | | |
| | | 220 | | private bool CanReachSupport(in FiniteSlabRayFrame frame, PhysicsMesh mesh, FixedBoundBox bounds) |
| | | 221 | | { |
| | | 222 | | // Translation along the exact plane normal leaves its zero components |
| | | 223 | | // unchanged. Disjoint outward bounds on those axes cannot supply support. |
| | 10920 | 224 | | WideDirection3d normal = new WideDirection3d(frame.Plane.AuthoredNormal).Transform(mesh.GeometryFrame.GeometryBa |
| | 10920 | 225 | | return (!normal.X.IsZero || bounds.Max.X >= _slabBounds.Min.X && bounds.Min.X <= _slabBounds.Max.X) |
| | 10920 | 226 | | && (!normal.Y.IsZero || bounds.Max.Y >= _slabBounds.Min.Y && bounds.Min.Y <= _slabBounds.Max.Y) |
| | 10920 | 227 | | && (!normal.Z.IsZero || bounds.Max.Z >= _slabBounds.Min.Z && bounds.Min.Z <= _slabBounds.Max.Z); |
| | | 228 | | } |
| | | 229 | | |
| | | 230 | | private void SelectJoinedMember(int index) |
| | | 231 | | { |
| | 37362 | 232 | | _member = index; _frame = _joined.Members[index].Frame; |
| | 18681 | 233 | | _fieldWords = _frame.FieldWords; |
| | 37362 | 234 | | _orientation = _orientations[index]; _supportDimension = _dimensions[index]; |
| | 18681 | 235 | | } |
| | | 236 | | |
| | | 237 | | private void JoinSupportSpans() |
| | | 238 | | { |
| | 7377 | 239 | | _joinVisitor ??= JoinAtSupportPoint; |
| | 7377 | 240 | | Span<ulong> values = stackalloc ulong[SelectionWords]; |
| | 7377 | 241 | | Span<sbyte> signs = stackalloc sbyte[FiniteSlabRaySelection.SignCount]; |
| | 41824 | 242 | | for (int index = 0; index < _joined.Inputs.Count; index++) |
| | | 243 | | { |
| | 13535 | 244 | | if (_memberCounts[index] == 0) continue; |
| | 18104 | 245 | | SelectJoinedMember(index); Member member = _joined.Members[index]; |
| | 90698 | 246 | | for (int span = 0; span < member.Boundary.Spans.Length; span++) |
| | | 247 | | { |
| | 36297 | 248 | | if (!member.JoinedSpans[span]) continue; |
| | 7836 | 249 | | var edge = member.Boundary.Spans[span]; |
| | 7836 | 250 | | _otherMember = _joined.MemberBySurface[(_joined.Meshes[edge.OtherMember], edge.OtherSurface)]; |
| | 7836 | 251 | | if (_memberCounts[_otherMember] == 0) continue; |
| | 3406 | 252 | | var maximum = new FiniteSlabRaySelection(values, signs, _fieldWords); |
| | 3406 | 253 | | FiniteSlabRayExtrema.AccumulateSegment(_frame, new FixedSegment(edge.Start, edge.End), edge.Interval, |
| | 3406 | 254 | | PrismOffsets.Span, _orientation, ref maximum, _joinVisitor); |
| | | 255 | | } |
| | | 256 | | } |
| | 7377 | 257 | | } |
| | | 258 | | |
| | | 259 | | private void JoinAtSupportPoint(scoped in FiniteSlabRaySelection candidate) |
| | | 260 | | { |
| | 13830 | 261 | | if (candidate.CompareDepth(BorrowPeak()) != 0) return; |
| | 27500 | 262 | | Member first = _joined.Members[_member], second = _joined.Members[_otherMember]; |
| | 13750 | 263 | | if (_memberCounts[_member] == 1 && _memberCounts[_otherMember] == 1) |
| | | 264 | | { |
| | 13606 | 265 | | _joined.Union(first.Offset, second.Offset); |
| | 13606 | 266 | | return; |
| | | 267 | | } |
| | | 268 | | // The certified joined span already lies in both finite owners. A |
| | | 269 | | // unique support region needs no initial-section triangle lookup: |
| | | 270 | | // oblique support projections can lie outside that initial section. |
| | 144 | 271 | | Span<int> singleton = stackalloc int[1] { -1 }; |
| | 144 | 272 | | ReadOnlySpan<int> firstDomain = _memberCounts[_member] == 1 ? singleton : first.Connectivity.TriangleIndices; |
| | 144 | 273 | | ReadOnlySpan<int> secondDomain = _memberCounts[_otherMember] == 1 ? singleton : second.Connectivity.TriangleIndi |
| | 1108 | 274 | | foreach (int a in firstDomain) |
| | | 275 | | { |
| | 410 | 276 | | if (a >= 0) |
| | | 277 | | { |
| | 378 | 278 | | first.Collider.Mesh.GetGeometryTriangleVertices(a, out Vector3d aa, out Vector3d ab, out Vector3d ac); |
| | 378 | 279 | | if (!candidate.ContainsTrianglePoint(first.Frame, new(aa, ab, ac), _frame)) continue; |
| | | 280 | | } |
| | 1304 | 281 | | foreach (int b in secondDomain) |
| | | 282 | | { |
| | 486 | 283 | | if (b >= 0) |
| | | 284 | | { |
| | 454 | 285 | | second.Collider.Mesh.GetGeometryTriangleVertices(b, out Vector3d ba, out Vector3d bb, out Vector3d b |
| | 454 | 286 | | if (!candidate.ContainsTrianglePoint(second.Frame, new(ba, bb, bc), _frame)) continue; |
| | | 287 | | } |
| | 192 | 288 | | _joined.Union(first.Offset + (a < 0 ? 0 : first.Connectivity.GetRegionOrdinal(a)), |
| | 192 | 289 | | second.Offset + (b < 0 ? 0 : second.Connectivity.GetRegionOrdinal(b))); |
| | | 290 | | } |
| | | 291 | | } |
| | 144 | 292 | | } |
| | | 293 | | |
| | | 294 | | internal bool AppendJoinedContacts(LSMeshCollider collider, PhysicsMaterial material, MeshSlabSurfaceBoundary bounda |
| | | 295 | | ContactManifold manifold, LSCollider2D? embedded = null, int namespace3D = 0, int namespace2D = 0) |
| | | 296 | | { |
| | 9801 | 297 | | Span<int> chosen = stackalloc int[ContactManifold.MaxContactsPerGroup]; |
| | 39180 | 298 | | for (int region = 0; region < _joined.Roots.Count; region++) |
| | | 299 | | { |
| | 9789 | 300 | | int rootMember = _joined.NodeMembers[_joined.Roots[region]]; |
| | 9789 | 301 | | Member root = _joined.Members[rootMember]; |
| | 9789 | 302 | | if (_joined.Members[_joined.GetResponseMember(rootMember)].Collider != collider) continue; |
| | 7773 | 303 | | int count = ReduceSamples(region, _joinedEvents.AsReadOnlySpan(), |
| | 7773 | 304 | | new WidePlaneMetrics(root.Frame.SourcePlane, root.Collider.Mesh.GeometryFrame), _dimensions[rootMember], |
| | 72376 | 305 | | for (int index = 0; index < count; index++) |
| | | 306 | | { |
| | 56830 | 307 | | Sample sample = _pool[chosen[index]]; Member supplier = _joined.Members[sample.Member]; |
| | 28415 | 308 | | manifold.AddContact(new ContactAnchor(new FixedPointAnchor(supplier.Frame.Center, FixedQuaternion.Identi |
| | 28415 | 309 | | new ContactAnchor(sample.Exit), sample.Depth, root.Frame.GetNormal(_orientations[rootMember]), suppl |
| | 28415 | 310 | | material, sample.Clamped, featureNamespaceA: namespace3D, featureNamespaceB: namespace2D, |
| | 28415 | 311 | | group: new ContactGroupKey(namespace3D, namespace2D, supplier.Owner + 1, 0, region, sourceIdA: suppl |
| | 28415 | 312 | | sourceOrderA: ((IPhysicsColliderRegistryItem)supplier.Collider).ReplayOrder + 1)); |
| | | 313 | | } |
| | | 314 | | } |
| | 9801 | 315 | | bool overlaps = false; |
| | 55944 | 316 | | for (int member = 0; member < _joined.Inputs.Count; member++) |
| | | 317 | | { |
| | 18171 | 318 | | Member source = _joined.Members[member]; |
| | 18171 | 319 | | if (source.Admitted.Count == 0) continue; |
| | 13495 | 320 | | overlaps |= source.Collider == collider; |
| | 13495 | 321 | | if (_joined.Members[_joined.GetResponseMember(member)].Collider != collider) continue; |
| | 9629 | 322 | | SelectJoinedMember(member); |
| | | 323 | | // Keep the component's face and perimeter rows in one solver pass; |
| | | 324 | | // otherwise matching normals receive positional correction twice. |
| | 9629 | 325 | | _boundaryConnectivity.BuildSlab(source.Collider.Mesh, source.Triangle, source.Frame.Section, PrismOffsets, s |
| | 9629 | 326 | | boundary.BuildSurfaceContacts(source.Collider, embedded, source.Triangle, _boundaryConnectivity, this, |
| | 9629 | 327 | | manifold, namespace3D, namespace2D, material); |
| | | 328 | | } |
| | 9801 | 329 | | return overlaps; |
| | | 330 | | } |
| | | 331 | | |
| | 11017 | 332 | | internal MeshSurfaceBoundaryDomain? JoinedBoundary => _member < 0 ? null : _joined.Members[_member].Boundary; |
| | 38612 | 333 | | internal bool IsJoinedSpan(int span) => _joined.Members[_member].JoinedSpans[span]; |
| | 224 | 334 | | internal RationalSegmentInterval GetRetainedInterval(ref int span) => _joined.Members[_member].GetRetainedInterval(r |
| | | 335 | | internal ReadOnlySpan<WideAxis3> GetJoinedCornerFan(LSMeshCollider collider, int triangle, int vertex, out bool supp |
| | 192 | 336 | | _joined.GetCornerFan(collider, triangle, vertex, out suppress); |
| | | 337 | | |
| | | 338 | | internal bool TryGetContinuousFamily(in ContactGroupKey group, out LSMeshCollider supplier, out int owner) |
| | | 339 | | { |
| | 248 | 340 | | supplier = null!; owner = -1; |
| | | 341 | | System.Diagnostics.Debug.Assert(_joined != null && _joined.Active); |
| | | 342 | | // This producer's nonnegative regions are native face groups. Boundary |
| | | 343 | | // groups use negative regions and different surface ordinals. |
| | 125 | 344 | | if (group.Region < 0 || group.Region >= _joined.Roots.Count) return false; |
| | 340 | 345 | | for (int index = 0; index < _joined.Inputs.Count; index++) |
| | | 346 | | { |
| | 168 | 347 | | Member member = _joined.Members[index]; |
| | 168 | 348 | | if (member.Collider.Id + 1 != group.SourceIdA || member.Owner + 1 != group.SurfaceA) continue; |
| | 121 | 349 | | int rootMember = _joined.NodeMembers[_joined.Roots[group.Region]]; |
| | 122 | 350 | | if (_joined.FindResponseComponent(index) != _joined.FindResponseComponent(rootMember)) return false; |
| | 360 | 351 | | supplier = member.Collider; owner = member.Owner; return true; |
| | | 352 | | } |
| | 2 | 353 | | return false; |
| | | 354 | | } |
| | | 355 | | |
| | | 356 | | internal bool IsSameContinuousFamily(LSMeshCollider collider, int owner, LSMeshCollider supplier, int supplierOwner) |
| | | 357 | | { |
| | | 358 | | System.Diagnostics.Debug.Assert(_joined != null && _joined.Active); |
| | 412 | 359 | | if (!_joined.MemberBySurface.TryGetValue((collider.Mesh, owner), out int member) |
| | 468 | 360 | | || !_joined.MemberBySurface.TryGetValue((supplier.Mesh, supplierOwner), out int resolved)) return false; |
| | | 361 | | // The caller's handoff is phase-local and callback-free. Prepare owns |
| | | 362 | | // cross-step geometry/lifetime validation; missing local owners stay unknown. |
| | 356 | 363 | | return _joined.FindResponseComponent(member) == _joined.FindResponseComponent(resolved); |
| | | 364 | | } |
| | | 365 | | |
| | | 366 | | internal bool IntersectsContinuousBoundary(LSMeshCollider collider, int owner, in FiniteSlabSectionFrame section) |
| | | 367 | | { |
| | 278 | 368 | | Member member = _joined.Members[_joined.MemberBySurface[(collider.Mesh, owner)]]; |
| | 278 | 369 | | ReadOnlySpan<BoundarySpan3D> pieces = member.Boundary.Spans; |
| | 2726 | 370 | | for (int span = 0; span < pieces.Length; span++) |
| | | 371 | | { |
| | 1168 | 372 | | if (member.JoinedSpans[span]) continue; |
| | 960 | 373 | | var piece = pieces[span]; |
| | 960 | 374 | | RationalSegmentInterval clip = member.GetRetainedInterval(ref span); |
| | 1043 | 375 | | if (section.IntersectsSegment(new FixedSegment(piece.Start, piece.End), clip)) return true; |
| | | 376 | | } |
| | 195 | 377 | | return false; |
| | | 378 | | } |
| | | 379 | | } |