Recover and verify static collision traversal and body contracts
This commit is contained in:
1 parent
7c0d1a4b0c
commit
df0263b26e
34 files changed
+1962
-17
No files matched your search
@@ -15,6 +15,7 @@ public struct MeshVertex(Vector3 position, Vector2 uv, Vector3 color)
|
||||
public sealed record Mesh(MeshVertex[] Vertices, uint[] Indices)
|
||||
{
|
||||
public MeshPolygonSource[] CollisionPolygons { get; init; } = [];
|
||||
public bool HasCollisionMaterialIds { get; init; }
|
||||
public MeshDraw[] Draws { get; init; } = [];
|
||||
public bool HasExplicitDraws { get; init; }
|
||||
public Dictionary<int,PngImage> Textures { get; init; } = [];
|
||||
@@ -55,7 +56,9 @@ public sealed record Mesh(MeshVertex[] Vertices, uint[] Indices)
|
||||
? polygonList.EnumerateArray().Select(p => new MeshPolygonSource(p.GetProperty("shapeId").GetInt32(),
|
||||
p.GetProperty("polygonIndex").GetInt32(),
|
||||
new Vector3(p.GetProperty("normal")[0].GetSingle(), p.GetProperty("normal")[1].GetSingle(), p.GetProperty("normal")[2].GetSingle()),
|
||||
p.GetProperty("materialName").GetString(), shapeNames.GetValueOrDefault(p.GetProperty("shapeId").GetInt32()))).ToArray() : [];
|
||||
p.GetProperty("materialName").GetString(), shapeNames.GetValueOrDefault(p.GetProperty("shapeId").GetInt32()),
|
||||
p.TryGetProperty("materialId", out var materialId) && materialId.ValueKind == JsonValueKind.Number
|
||||
? materialId.GetInt32() : null)).ToArray() : [];
|
||||
if (collisionPolygons.Length != 0 && (collisionPolygons.Length != indices.Length / 3
|
||||
|| collisionPolygons.Any(p => !float.IsFinite(p.Normal.X + p.Normal.Y + p.Normal.Z))))
|
||||
throw new InvalidDataException("Invalid source collision polygon metadata");
|
||||
@@ -92,11 +95,15 @@ public sealed record Mesh(MeshVertex[] Vertices, uint[] Indices)
|
||||
for(var i=first;i<first+count;i++)vertices[indices[i]].Color=material.Item2;
|
||||
draws.Add(new MeshDraw(first,count,material.Item1));
|
||||
}
|
||||
return new Mesh(vertices, indices){Draws=draws.ToArray(),HasExplicitDraws=true,Textures=textures,CollisionPolygons=collisionPolygons};
|
||||
return new Mesh(vertices, indices){Draws=draws.ToArray(),HasExplicitDraws=true,Textures=textures,CollisionPolygons=collisionPolygons,
|
||||
HasCollisionMaterialIds=root.TryGetProperty("collisionPolygons", out var sourcePolygons)
|
||||
&& sourcePolygons.EnumerateArray().All(p => p.TryGetProperty("materialId", out var id)
|
||||
&& id.ValueKind is JsonValueKind.Number or JsonValueKind.Null)};
|
||||
}
|
||||
}
|
||||
|
||||
public readonly record struct MeshPolygonSource(int ShapeId, int PolygonIndex, Vector3 Normal, string? MaterialName, string? ShapeName = null)
|
||||
public readonly record struct MeshPolygonSource(int ShapeId, int PolygonIndex, Vector3 Normal, string? MaterialName,
|
||||
string? ShapeName = null, int? MaterialId = null)
|
||||
{
|
||||
public bool TerrainCollision => ShapeName?.StartsWith("nc", StringComparison.OrdinalIgnoreCase) != true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user