1 Commits

Author SHA1 Message Date
bc78c8fbee docs: add XML summary comments to public Meshlet types and methods 2026-03-17 04:02:28 +00:00
4 changed files with 73 additions and 21 deletions

View File

@@ -2,9 +2,15 @@ using System.Numerics;
namespace Ghost.Graphics.Meshlet;
/// <summary>
/// Represents the bounding sphere and simplification error for a LOD cluster.
/// </summary>
public struct ClodBounds
{
/// <summary> The center of the bounding sphere. </summary>
public Vector3 center;
/// <summary> The radius of the bounding sphere. </summary>
public float radius;
/// <summary> The simplification error associated with this LOD level. </summary>
public float error;
}

View File

@@ -15,8 +15,19 @@ internal struct Cluster
public ClodBounds bounds;
}
/// <summary>
/// Provides methods to build a hierarchical Cluster LOD mesh.
/// </summary>
public unsafe static class ClodBuilder
{
/// <summary>
/// Builds a cluster LOD hierarchy from the input mesh.
/// </summary>
/// <param name="config">The configuration parameters for the LOD building process.</param>
/// <param name="mesh">The input mesh data.</param>
/// <param name="outputContext">Optional context pointer passed to the output callback.</param>
/// <param name="outputCallback">Delegate invoked for each generated LOD group.</param>
/// <returns>The total count of generated clusters.</returns>
public static nuint Build(ClodConfig config, ClodMesh mesh, void* outputContext, ClodOutputDelegate outputCallback)
{
Debug.Assert(mesh.vertexAttributesStride % (nuint)sizeof(float) == 0, "vertexAttributesStride must be a multiple of sizeof(float)");

View File

@@ -1,37 +1,52 @@
using System;
namespace Ghost.Graphics.Meshlet;
/// <summary>
/// Configuration parameters for the cluster LOD generation pipeline.
/// </summary>
public struct ClodConfig
{
/// <summary> The maximum number of vertices per meshlet. </summary>
public nuint maxVertices;
/// <summary> The minimum number of triangles per meshlet. </summary>
public nuint minTriangles;
/// <summary> The maximum number of triangles per meshlet. </summary>
public nuint maxTriangles;
/// <summary> Whether to use spatial partitioning during meshlet building. </summary>
public bool partitionSpatial;
/// <summary> Whether to sort clusters after partitioning. </summary>
public bool partitionSort;
/// <summary> The target size for partitions. </summary>
public nuint partitionSize;
/// <summary> Whether to cluster meshlets using spatial clustering. </summary>
public bool clusterSpatial;
/// <summary> Weight factor for cluster fill calculation. </summary>
public float clusterFillWeight;
/// <summary> Split factor for flexible clustering. </summary>
public float clusterSplitFactor;
/// <summary> The simplification ratio to achieve per LOD level. </summary>
public float simplifyRatio;
/// <summary> Threshold for stopping simplification. </summary>
public float simplifyThreshold;
/// <summary> Error factor used when merging previous LOD level errors. </summary>
public float simplifyErrorMergePrevious;
/// <summary> Additive error factor when merging LOD levels. </summary>
public float simplifyErrorMergeAdditive;
/// <summary> Error factor for sloppy simplification. </summary>
public float simplifyErrorFactorSloppy;
/// <summary> Edge length limit error factor. </summary>
public float simplifyErrorEdgeLimit;
/// <summary> Whether to allow permissive simplification. </summary>
public bool simplifyPermissive;
/// <summary> Whether to fallback to permissive simplification. </summary>
public bool simplifyFallbackPermissive;
/// <summary> Whether to fallback to sloppy simplification. </summary>
public bool simplifyFallbackSloppy;
/// <summary> Whether to regularize the mesh during simplification. </summary>
public bool simplifyRegularize;
/// <summary> Whether to optimize cluster bounds. </summary>
public bool optimizeBounds;
/// <summary> Whether to optimize clusters post-build. </summary>
public bool optimizeClusters;
}

View File

@@ -1,43 +1,63 @@
using System;
using Ghost.MeshOptimizer;
using Misaki.HighPerformance.LowLevel.Collections;
using Misaki.HighPerformance.LowLevel;
using Misaki.HighPerformance.LowLevel.Buffer;
namespace Ghost.Graphics.Meshlet;
/// <summary>
/// Contains input data for the Cluster LOD generation pipeline.
/// </summary>
public unsafe struct ClodMesh
{
/// <summary> Pointer to vertex position data (float array). </summary>
public float* vertexPositions;
/// <summary> Number of vertices in the mesh. </summary>
public nuint vertexCount;
/// <summary> Stride in bytes for vertex position data. </summary>
public nuint vertexPositionsStride;
/// <summary> Pointer to vertex attribute data (float array). </summary>
public float* vertexAttributes;
/// <summary> Stride in bytes for vertex attribute data. </summary>
public nuint vertexAttributesStride;
/// <summary> Pointer to attribute weights for simplification. </summary>
public float* attributeWeights;
/// <summary> Number of vertex attributes. </summary>
public nuint attributeCount;
/// <summary> Pointer to index data. </summary>
public uint* indices;
/// <summary> Number of indices in the mesh. </summary>
public nuint indexCount;
/// <summary> Pointer to per-vertex lock flags (1 byte per vertex). </summary>
public byte* vertexLock;
/// <summary> Mask indicating which attributes are protected during simplification. </summary>
public uint attributeProtectMask;
}
/// <summary>
/// Defines a group of clusters in the LOD hierarchy.
/// </summary>
public struct ClodGroup
{
/// <summary> LOD hierarchy depth of this group. </summary>
public int depth;
/// <summary> Bounding information for the simplified group. </summary>
public ClodBounds simplified;
}
/// <summary>
/// Represents a cluster of meshlets in the LOD hierarchy.
/// </summary>
public unsafe struct ClodCluster
{
/// <summary> Refinement level of the cluster. </summary>
public int refined;
/// <summary> Bounding info for the cluster. </summary>
public ClodBounds bounds;
/// <summary> Pointer to indices for this cluster. </summary>
public uint* indices;
/// <summary> Number of indices. </summary>
public nuint indexCount;
/// <summary> Number of vertices in the cluster. </summary>
public nuint vertexCount;
}
/// <summary>
/// Delegate type for processing generated LOD groups.
/// </summary>
public unsafe delegate int ClodOutputDelegate(void* context, ClodGroup group, ClodCluster* clusters, nuint clusterCount);