Code/AutoRig/Analyze/PartContact.cs

Data model representing a detected contact region between two mesh parts. It stores indices of the two parts, the contact cloud centroid, principal direction, plane normal, extent radius, and sample count.

using System.Numerics;

namespace AutoRig.Analyze;

// s&box compat: the engine defines Vector2/Vector3 in the GLOBAL namespace, which
// shadows using-directive imports - alias explicitly to System.Numerics.
using Vector2 = System.Numerics.Vector2;
using Vector3 = System.Numerics.Vector3;


/// <summary>A detected contact region between two mesh parts.</summary>
public sealed class PartContact
{
    /// <summary>Index of the first part (always &lt; <see cref="PartB"/>).</summary>
    public required int PartA { get; init; }

    /// <summary>Index of the second part.</summary>
    public required int PartB { get; init; }

    /// <summary>Mean of the contact sample points.</summary>
    public required Vector3 Center { get; init; }

    /// <summary>Principal axis of the contact point cloud (unit; sign toward +X/+Y/+Z).</summary>
    public required Vector3 Direction { get; init; }

    /// <summary>
    /// Unit normal of the contact region (smallest-variance axis of the contact cloud),
    /// signed toward the smaller part's centroid. For a flat interface (turret ring,
    /// door face) this is the natural hinge-axis candidate.
    /// </summary>
    public required Vector3 PlaneNormal { get; init; }

    /// <summary>Largest distance of a contact sample from <see cref="Center"/>.</summary>
    public required float Extent { get; init; }

    /// <summary>Number of surface samples that landed within tolerance.</summary>
    public required int SampleCount { get; init; }
}