render: unified MultiMeshPartPool with MechPaint, PomDecalPool, and per-weapon VFX

This commit is contained in:
Meta Vens 2026-12-04 23:56:30 +01:00
commit 2529ba62d2
9 changed files with 2593 additions and 871 deletions

View file

@ -875,12 +875,108 @@ public static class VehicleRigAnimator
}
var list = new List<WalkerFootSample>();
var stack = new List<Node3D>();
float cutoffY = visual.Template.MinY + 0.75f;
int count = visual.ModelRoot.GetChildCount();
for (int i = 0; i < count; i++)
var parts = visual.StaticParts;
for (int i = 0; i < parts.Count; i++)
{
CollectFootSamplesRecursive(visual.ModelRoot.GetChild(i), Transform3D.Identity, cutoffY, stack, list);
var part = parts[i];
if (!GodotObject.IsInstanceValid(part.Pivot))
{
continue;
}
// Build chain from ModelRoot -> part.Pivot
var chain = new List<Node3D>();
Transform3D toModel = Transform3D.Identity;
for (Node? cur = part.Pivot; cur is Node3D n3d && !ReferenceEquals(cur, visual.ModelRoot); cur = cur.GetParent())
{
chain.Add(n3d);
toModel = n3d.Transform * toModel;
}
chain.Reverse();
Aabb aabb = part.Mesh.GetAabb();
float aabbMinY = float.PositiveInfinity;
for (int c = 0; c < 8; c++)
{
Vector3 corner = aabb.Position + new Vector3(
(c & 1) != 0 ? aabb.Size.X : 0f,
(c & 2) != 0 ? aabb.Size.Y : 0f,
(c & 4) != 0 ? aabb.Size.Z : 0f);
float wy = (toModel * corner).Y;
if (wy < aabbMinY)
{
aabbMinY = wy;
}
}
if (aabbMinY >= cutoffY)
{
continue;
}
var bestPts = new Vector3[FootSupportDirs.Length];
var bestDots = new float[FootSupportDirs.Length];
for (int d = 0; d < FootSupportDirs.Length; d++)
{
bestDots[d] = float.NegativeInfinity;
}
bool anyVert = false;
int surfCount = part.Mesh.GetSurfaceCount();
for (int s = 0; s < surfCount; s++)
{
var arrays = part.Mesh.SurfaceGetArrays(s);
if (arrays.Count <= (int)Mesh.ArrayType.Vertex ||
arrays[(int)Mesh.ArrayType.Vertex].VariantType != Variant.Type.PackedVector3Array)
{
continue;
}
Vector3[] verts = arrays[(int)Mesh.ArrayType.Vertex].AsVector3Array();
for (int v = 0; v < verts.Length; v++)
{
Vector3 localPt = verts[v];
Vector3 mPt = toModel * localPt;
for (int d = 0; d < FootSupportDirs.Length; d++)
{
float score = mPt.Dot(FootSupportDirs[d]);
if (score > bestDots[d])
{
bestDots[d] = score;
bestPts[d] = localPt;
}
}
anyVert = true;
}
}
if (anyVert)
{
var unique = new List<Vector3>(FootSupportDirs.Length);
for (int d = 0; d < bestPts.Length; d++)
{
bool dup = false;
for (int u = 0; u < unique.Count; u++)
{
if ((unique[u] - bestPts[d]).LengthSquared() < 1e-6f)
{
dup = true;
break;
}
}
if (!dup)
{
unique.Add(bestPts[d]);
}
}
list.Add(new WalkerFootSample
{
ChainFromModelRoot = chain.ToArray(),
LocalPoints = unique.ToArray()
});
}
}
st.FootSamples = list;
}
@ -898,117 +994,6 @@ public static class VehicleRigAnimator
new(-0.45f, -1f, -0.45f),
};
private static void CollectFootSamplesRecursive(
Node cur,
Transform3D parentToModel,
float cutoffY,
List<Node3D> stack,
List<WalkerFootSample> list)
{
Transform3D toModel = parentToModel;
bool pushed = false;
if (cur is Node3D n3d)
{
toModel = parentToModel * n3d.Transform;
stack.Add(n3d);
pushed = true;
}
if (cur is MeshInstance3D mi && mi.Mesh is { } mesh)
{
Aabb aabb = mesh.GetAabb();
float aabbMinY = float.PositiveInfinity;
for (int c = 0; c < 8; c++)
{
Vector3 corner = aabb.Position + new Vector3(
(c & 1) != 0 ? aabb.Size.X : 0f,
(c & 2) != 0 ? aabb.Size.Y : 0f,
(c & 4) != 0 ? aabb.Size.Z : 0f);
float wy = (toModel * corner).Y;
if (wy < aabbMinY)
{
aabbMinY = wy;
}
}
if (aabbMinY < cutoffY)
{
var bestPts = new Vector3[FootSupportDirs.Length];
var bestDots = new float[FootSupportDirs.Length];
for (int d = 0; d < FootSupportDirs.Length; d++)
{
bestDots[d] = float.NegativeInfinity;
}
bool anyVert = false;
int surfCount = mesh.GetSurfaceCount();
for (int s = 0; s < surfCount; s++)
{
var arrays = mesh.SurfaceGetArrays(s);
if (arrays.Count <= (int)Mesh.ArrayType.Vertex ||
arrays[(int)Mesh.ArrayType.Vertex].VariantType != Variant.Type.PackedVector3Array)
{
continue;
}
Vector3[] verts = arrays[(int)Mesh.ArrayType.Vertex].AsVector3Array();
for (int v = 0; v < verts.Length; v++)
{
Vector3 localPt = verts[v];
Vector3 mPt = toModel * localPt;
for (int d = 0; d < FootSupportDirs.Length; d++)
{
float score = mPt.Dot(FootSupportDirs[d]);
if (score > bestDots[d])
{
bestDots[d] = score;
bestPts[d] = localPt;
}
}
anyVert = true;
}
}
if (anyVert)
{
var unique = new List<Vector3>(FootSupportDirs.Length);
for (int d = 0; d < bestPts.Length; d++)
{
bool dup = false;
for (int u = 0; u < unique.Count; u++)
{
if ((unique[u] - bestPts[d]).LengthSquared() < 1e-6f)
{
dup = true;
break;
}
}
if (!dup)
{
unique.Add(bestPts[d]);
}
}
list.Add(new WalkerFootSample
{
ChainFromModelRoot = stack.ToArray(),
LocalPoints = unique.ToArray()
});
}
}
}
int childCount = cur.GetChildCount();
for (int i = 0; i < childCount; i++)
{
CollectFootSamplesRecursive(cur.GetChild(i), toModel, cutoffY, stack, list);
}
if (pushed)
{
stack.RemoveAt(stack.Count - 1);
}
}
private static void ApplyWalkerFloorClearance(VehicleVisualInstance visual, RigState st, string rootNodeName)
{
var samples = st.FootSamples;