fix: correct API calls and cleanup documentation

- Replace .Ptr with .GetUnsafePtr() for UnsafeList access
- Use proper MeshOptApi method names (CamelCase): ComputeClusterBounds, BuildMeshletsBound, PartitionClusters, etc.
- Fix SimplifyVertex_Protect constant access
- Remove IMPLEMENTATION_COMPLETE.md
- Rename AGENT_GUIDELINES.md to AGENT.md
This commit is contained in:
2026-03-17 00:23:42 +00:00
parent 2ba60c4bae
commit f7fb7da496
7 changed files with 38 additions and 172 deletions

View File

@@ -9,7 +9,7 @@ internal static class ClodBoundsHelper
{
public static ClodBounds ComputeBounds(ClodMesh mesh, UnsafeList<uint> indices, float error)
{
var bounds = MeshOptApi.meshopt_computeClusterBounds(indices.Ptr, (nuint)indices.Length, mesh.vertexPositions, mesh.vertexCount, mesh.vertexPositionsStride);
var bounds = MeshOptApi.ComputeClusterBounds(indices.GetUnsafePtr(), (nuint)indices.Length, mesh.vertexPositions, mesh.vertexCount, mesh.vertexPositionsStride);
var result = new ClodBounds();
result.center = new Vector3(bounds.center[0], bounds.center[1], bounds.center[2]);
@@ -29,11 +29,11 @@ internal static class ClodBoundsHelper
boundsList[j] = clusters[group[j]].bounds;
}
var merged = MeshOptApi.meshopt_computeSphereBounds(
(float*)boundsList.Ptr,
var merged = MeshOptApi.ComputeSphereBounds(
(float*)boundsList.GetUnsafePtr(),
(nuint)group.Length,
(nuint)sizeof(ClodBounds),
(float*)boundsList.Ptr + 3, // offset to radius field
(float*)boundsList.GetUnsafePtr() + 3, // offset to radius field
(nuint)sizeof(ClodBounds)
);

View File

@@ -35,7 +35,7 @@ public unsafe static class ClodBuilder
// Generate position-only remap
var remap = new UnsafeList<uint>((int)mesh.vertexCount, allocator);
remap.Resize(mesh.vertexCount);
MeshOptApi.meshopt_generatePositionRemap(remap.Ptr, mesh.vertexPositions, mesh.vertexCount, mesh.vertexPositionsStride);
MeshOptApi.GeneratePositionRemap(remap.GetUnsafePtr(), mesh.vertexPositions, mesh.vertexCount, mesh.vertexPositionsStride);
// Set up protect bits on UV seams
if (mesh.attributeProtectMask != 0)
@@ -50,7 +50,7 @@ public unsafe static class ClodBuilder
{
if (mesh.vertexAttributes[i * maxAttributes + j] != mesh.vertexAttributes[r * maxAttributes + j])
{
locks[(int)i] |= (byte)MeshOptApi.meshopt_SimplifyVertex_Protect;
locks[(int)i] |= (byte)MeshOptApi.SimplifyVertex_Protect;
}
}
}
@@ -119,7 +119,7 @@ public unsafe static class ClodBuilder
}
// Clusterize simplified mesh
var split = ClodInternal.Clusterize(config, mesh, simplified.Ptr, simplified.Length, allocator);
var split = ClodInternal.Clusterize(config, mesh, simplified.GetUnsafePtr(), simplified.Length, allocator);
for (int j = 0; j < (int)split.Length; j++)
{
split[j].refined = refined;
@@ -184,14 +184,14 @@ public unsafe static class ClodBuilder
dstCluster.bounds = (config.optimizeBounds && srcCluster.refined != -1)
? ClodBoundsHelper.ComputeBounds(mesh, srcCluster.indices, srcCluster.bounds.error)
: srcCluster.bounds;
dstCluster.indices = srcCluster.indices.Ptr;
dstCluster.indices = srcCluster.indices.GetUnsafePtr();
dstCluster.indexCount = (nuint)srcCluster.indices.Length;
dstCluster.vertexCount = srcCluster.vertices;
}
var clodGroup = new ClodGroup { Depth = depth, Simplified = simplified };
int result = outputCallback != null
? outputCallback(outputContext, clodGroup, (ClodCluster*)groupClusters.Ptr, (nuint)groupClusters.Length)
? outputCallback(outputContext, clodGroup, (ClodCluster*)groupClusters.GetUnsafePtr(), (nuint)groupClusters.Length)
: -1;
groupClusters.Dispose();

View File

@@ -8,7 +8,7 @@ internal static class ClodInternal
{
public static UnsafeList<Cluster> Clusterize(ClodConfig config, ClodMesh mesh, uint* indices, nuint indexCount, Allocator allocator)
{
nuint maxMeshlets = MeshOptApi.meshopt_buildMeshletsBound(indexCount, config.maxVertices, config.minTriangles);
nuint maxMeshlets = MeshOptApi.BuildMeshletsBound(indexCount, config.maxVertices, config.minTriangles);
var meshlets = new UnsafeList<meshopt_Meshlet>(maxMeshlets, allocator);
var meshletVertices = new UnsafeList<uint>(indexCount, allocator);
@@ -19,10 +19,10 @@ internal static class ClodInternal
nuint meshletCount;
if (config.clusterSpatial)
{
meshletCount = MeshOptApi.meshopt_buildMeshletsSpatial(
meshlets.Ptr,
meshletVertices.Ptr,
meshletTriangles.Ptr,
meshletCount = MeshOptApi.BuildMeshletsSpatial(
meshlets.GetUnsafePtr(),
meshletVertices.GetUnsafePtr(),
meshletTriangles.GetUnsafePtr(),
indices,
indexCount,
mesh.vertexPositions,
@@ -36,10 +36,10 @@ internal static class ClodInternal
}
else
{
meshletCount = MeshOptApi.meshopt_buildMeshletsFlex(
meshlets.Ptr,
meshletVertices.Ptr,
meshletTriangles.Ptr,
meshletCount = MeshOptApi.BuildMeshletsFlex(
meshlets.GetUnsafePtr(),
meshletVertices.GetUnsafePtr(),
meshletTriangles.GetUnsafePtr(),
indices,
indexCount,
mesh.vertexPositions,
@@ -62,9 +62,9 @@ internal static class ClodInternal
if (config.optimizeClusters)
{
MeshOptApi.meshopt_optimizeMeshlet(
meshletVertices.Ptr + meshlet.vertexOffset,
meshletTriangles.Ptr + meshlet.triangleOffset,
MeshOptApi.OptimizeMeshlet(
meshletVertices.GetUnsafePtr() + meshlet.vertexOffset,
meshletTriangles.GetUnsafePtr() + meshlet.triangleOffset,
meshlet.triangleCount,
meshlet.vertexCount
);
@@ -80,7 +80,7 @@ internal static class ClodInternal
for (nuint j = 0; j < meshlet.triangleCount * 3; j++)
{
cluster.indices.Add(meshletVertices[meshlet.vertexOffset + meshletTriangles[meshlet.triangleOffset + j]]);
cluster.indices.Add(meshletVertices[(int)(meshlet.vertexOffset + meshletTriangles[(int)(meshlet.triangleOffset + j)])]);
}
clusters.Add(cluster);

View File

@@ -45,11 +45,11 @@ internal static class ClodPartition
var clusterPart = new UnsafeList<uint>(pending.Length, stackScope.AllocationHandle);
clusterPart.Resize((nuint)pending.Length);
nuint partitionCount = MeshOptApi.meshopt_partitionClusters(
clusterPart.Ptr,
clusterIndices.Ptr,
nuint partitionCount = MeshOptApi.PartitionClusters(
clusterPart.GetUnsafePtr(),
clusterIndices.GetUnsafePtr(),
totalIndexCount,
clusterCounts.Ptr,
clusterCounts.GetUnsafePtr(),
(nuint)pending.Length,
config.partitionSpatial ? mesh.vertexPositions : null,
remap.Length,

View File

@@ -24,15 +24,15 @@ internal static class ClodSimplify
var lod = new UnsafeList<uint>(indices.Length, scope.AllocationHandle);
lod.Resize((nuint)indices.Length);
uint options = MeshOptApi.meshopt_SimplifySparse | MeshOptApi.meshopt_SimplifyErrorAbsolute;
uint options = MeshOptApi.SimplifySparse | MeshOptApi.SimplifyErrorAbsolute;
if (config.simplifyPermissive)
options |= MeshOptApi.meshopt_SimplifyPermissive;
options |= MeshOptApi.SimplifyPermissive;
if (config.simplifyRegularize)
options |= MeshOptApi.meshopt_SimplifyRegularize;
options |= MeshOptApi.SimplifyRegularize;
nuint resultSize = MeshOptApi.meshopt_simplifyWithAttributes(
lod.Ptr,
indices.Ptr,
nuint resultSize = MeshOptApi.SimplifyWithAttributes(
lod.GetUnsafePtr(),
indices.GetUnsafePtr(),
(nuint)indices.Length,
mesh.vertexPositions,
mesh.vertexCount,
@@ -41,7 +41,7 @@ internal static class ClodSimplify
mesh.vertexAttributesStride,
mesh.attributeWeights,
mesh.attributeCount,
locks.Ptr,
locks.GetUnsafePtr(),
targetCount,
float.MaxValue,
options,
@@ -53,10 +53,10 @@ internal static class ClodSimplify
// Fallback to permissive if needed
if (lod.Length > targetCount && config.simplifyFallbackPermissive && !config.simplifyPermissive)
{
options |= MeshOptApi.meshopt_SimplifyPermissive;
resultSize = MeshOptApi.meshopt_simplifyWithAttributes(
lod.Ptr,
indices.Ptr,
options |= MeshOptApi.SimplifyPermissive;
resultSize = MeshOptApi.SimplifyWithAttributes(
lod.GetUnsafePtr(),
indices.GetUnsafePtr(),
(nuint)indices.Length,
mesh.vertexPositions,
mesh.vertexCount,
@@ -65,7 +65,7 @@ internal static class ClodSimplify
mesh.vertexAttributesStride,
mesh.attributeWeights,
mesh.attributeCount,
locks.Ptr,
locks.GetUnsafePtr(),
targetCount,
float.MaxValue,
options,