A fallback rigging solver that produces a single-root-bone rig for a mesh. It computes mesh bounds, creates one root joint positioned at bounds bottom-center, assigns all vertices to that root rigidly, and returns a RigResult marked degraded with an explanatory message.
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.",
};
}
}