Code/AutoRig/Solve/FloorSolver.cs

A fallback rigging solver that always succeeds by creating a single root bone and rigidly binding all mesh vertices to it. It positions the root at the mesh bounds bottom-center and returns a RigResult marked degraded with explanatory text.

using AutoRig.Analyze;
using AutoRig.Rig;

namespace AutoRig.Solve;

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

/// <summary>
/// The never-fail floor: one root bone, everything rigidly bound. Produced when no
/// better solver applies (or one crashed). Root sits at the bounds-bottom center
/// (bounds-center X/Z, minimum Y — source files are Y-up more often than not; the
/// exporter re-orients per engine conventions later).
/// </summary>
public static class FloorSolver
{
    public static RigResult Rig( AnalysisResult analysis )
    {
        ArgumentNullException.ThrowIfNull( analysis );

        var bounds = analysis.Mesh.ComputeBounds();
        var skeleton = new RigSkeleton
        {
            Joints =
            {
                new RigJoint
                {
                    Name = "root",
                    Parent = -1,
                    Position = new Vector3( bounds.Center.X, bounds.Min.Y, bounds.Center.Z ),
                },
            },
        };

        var vertexBone = new int[analysis.Mesh.Positions.Length]; // all zero = root
        return new RigResult
        {
            Skeleton = skeleton,
            Weights = SkinWeights.Rigid( analysis.Mesh.Positions.Length, vertexBone ),
            SolverName = "floor",
            Degraded = true,
            Explanation = "Single-bone rig: the mesh moves as one piece. Adjust joints manually "
                + "or wait for a specialized solver to support this mesh type.",
        };
    }
}