Reconstruct lab story, interactions, patrol and jet pack practice flow
This commit is contained in:
1 parent
58424120bb
commit
c929f942e1
84 files changed
+7957
-305
No files matched your search
@@ -14,6 +14,7 @@ public struct MeshVertex(Vector3 position, Vector2 uv, Vector3 color)
|
||||
|
||||
public sealed record Mesh(MeshVertex[] Vertices, uint[] Indices)
|
||||
{
|
||||
public MeshPolygonSource[] CollisionPolygons { get; init; } = [];
|
||||
public MeshDraw[] Draws { get; init; } = [];
|
||||
public bool HasExplicitDraws { get; init; }
|
||||
public Dictionary<int,PngImage> Textures { get; init; } = [];
|
||||
@@ -38,6 +39,14 @@ public sealed record Mesh(MeshVertex[] Vertices, uint[] Indices)
|
||||
var indices = root.GetProperty("indices").EnumerateArray().Select(p => p.GetUInt32()).ToArray();
|
||||
if (indices.Length % 3 != 0 || indices.Any(i => i >= vertices.Length)) throw new InvalidDataException("Invalid scene triangle indices.");
|
||||
if (vertices.Length == 0 || indices.Length == 0) throw new InvalidDataException("Empty scene mesh.");
|
||||
var collisionPolygons = root.TryGetProperty("collisionPolygons", out var polygonList)
|
||||
? 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())).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");
|
||||
var textures = new Dictionary<int,PngImage>();
|
||||
if(root.TryGetProperty("textures",out var textureList)) foreach(var t in textureList.EnumerateArray())
|
||||
{
|
||||
@@ -71,8 +80,14 @@ 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};
|
||||
return new Mesh(vertices, indices){Draws=draws.ToArray(),HasExplicitDraws=true,Textures=textures,CollisionPolygons=collisionPolygons};
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record MeshDraw(uint FirstIndex,uint IndexCount,int TextureId);
|
||||
public readonly record struct MeshPolygonSource(int ShapeId, int PolygonIndex, Vector3 Normal, string? MaterialName);
|
||||
|
||||
public sealed record MeshDraw(uint FirstIndex,uint IndexCount,int TextureId)
|
||||
{
|
||||
public bool Visible { get; set; } = true;
|
||||
public bool ScreenSpace { get; init; }
|
||||
}
|
||||
Reference in new issue
Block a user