Skip to content

Commit

Permalink
Migrate WorldViewer to Mlang
Browse files Browse the repository at this point in the history
  • Loading branch information
Helco committed Jan 14, 2024
1 parent 9d529c4 commit c28eaf9
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 230 deletions.
46 changes: 40 additions & 6 deletions zzre.core/rendering/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ namespace zzre.rendering;

public class Mesh : BaseDisposable
{
public readonly record struct SubMesh(int IndexOffset, int IndexCount, int Material) : IComparable<SubMesh>
public readonly record struct SubMesh(int IndexOffset, int IndexCount, int Material, int Section = 0) : IComparable<SubMesh>
{
public int CompareTo(SubMesh other)
{
if (other.Material == Material)
return IndexOffset - other.IndexOffset;
return Material - other.Material;
if (other.Section != Section)
return Section - other.Section;
if (other.Material != Material)
return Material - other.Material;
return IndexOffset - other.IndexOffset;
}
}

Expand Down Expand Up @@ -170,6 +172,38 @@ public void AddSubMesh(SubMesh subMesh)
subMeshes.Insert(index, subMesh);
}

public void AddSubMesh(int indexOffset, int indexCount, int material = 0) =>
AddSubMesh(new(indexOffset, indexCount, material));
public void AddSubMesh(int indexOffset, int indexCount, int material = 0, int section = 0) =>
AddSubMesh(new(indexOffset, indexCount, material, section));

public Range GetSubMeshRange(int? section = null, int? material = null)
{
if (subMeshes.Count == 0)
return 0..0;
int first = 0, last = subMeshes.Count - 1;
if (section.HasValue)
{
first = subMeshes.FindIndex(m => m.Section == section);
last = subMeshes.FindLastIndex(m => m.Section == section);
if (first < 0)
return 0..0;
}
if (material.HasValue)
{
first = subMeshes.FindIndex(first, (last - first + 1), m => m.Material == material);
if (first < 0)
return 0..0;
last = subMeshes.FindLastIndex(first, (last - first + 1), m => m.Material == material);

if (section is null && first != last)
{
var expectedSection = subMeshes[first].Section;
if (subMeshes.Skip(first).Take(last - first + 1).Any(m => m.Section != expectedSection))
throw new ArgumentException("Cannot get single submesh range for material filter alone");
}
}
return first..(last + 1);
}

public IEnumerable<SubMesh> GetSubMeshes(int? section = null, int? material = null) =>
subMeshes.Range(GetSubMeshRange(section, material));
}
3 changes: 3 additions & 0 deletions zzre.core/rendering/ShaderVariantCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public IBuiltVariantPipeline GetBuiltPipeline(ShaderVariantKey variantKey)
VertexLayouts = CreateVertexLayouts(variant)
}
});
pipeline.Name = $"Pipeline {variantKey}";
var builtPipeline = new BuiltPipeline()
{
ShaderVariant = variant,
Expand All @@ -130,6 +131,8 @@ private BuiltPrograms GetBuiltPrograms(ShaderVariant variant)
Vertex = Factory.CreateShader(new(ShaderStages.Vertex, variant.VertexShader.ToArray(), "main")),
Fragment = Factory.CreateShader(new(ShaderStages.Fragment, variant.FragmentShader.ToArray(), "main"))
};
newPrograms.Vertex.Name = $"Vertex {invariantKey}";
newPrograms.Fragment.Name = $"Fragment {invariantKey}";
builtPrograms.Add(invariantKey, newPrograms);
return newPrograms;
}
Expand Down
2 changes: 1 addition & 1 deletion zzre/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static void Main(string[] args)

#if DEBUG
//new ZanzarahWindow(diContainer);
diContainer.GetTag<OpenDocumentSet>().OpenWith<ActorEditor>("resources/models/actorsex/CHR01.AED");
diContainer.GetTag<OpenDocumentSet>().OpenWith<WorldViewer>("resources/worlds/SC_2222.BSP");
#endif

window.Resized += () =>
Expand Down
156 changes: 0 additions & 156 deletions zzre/rendering/ClumpBuffersDeinterleaved.cs

This file was deleted.

Loading

0 comments on commit c28eaf9

Please sign in to comment.