diff --git a/README.md b/README.md index ce83416..53a9cee 100644 --- a/README.md +++ b/README.md @@ -307,8 +307,10 @@ to change geometry explicitly: - **Decimate** reduces triangles toward a percentage target within an approximate error limit expressed as a percentage of mesh size. Open borders are preserved by default. Vertex colors are retained, but this is not a guarantee that a precision mating surface remains unchanged. -- **Voxel remesh** rebuilds a closed, manifold mesh at a resolution of 24–128. It can remove thin - details and change mating surfaces. Vertex colors are removed; material tint remains. +- **Voxel remesh** rebuilds a closed, manifold mesh at a resolution of 24–256 (default 128). + Higher values use smaller voxels and can preserve finer features. Lower the resolution if the + job reaches the voxel memory or one-million-triangle limit. Remeshing can remove thin details + and change mating surfaces. It removes vertex colors and retains material tint. **Prepare mesh** processes in a worker and reports the actual triangle count before applying. Cancel stops the worker. By default, applying creates an independent part in the same position diff --git a/docs/acceleration-opportunities.md b/docs/acceleration-opportunities.md index 142381d..f221882 100644 --- a/docs/acceleration-opportunities.md +++ b/docs/acceleration-opportunities.md @@ -102,4 +102,4 @@ Run `npm test`, `npm run build`, `npm run test:e2e:acceleration`, and the mesh-p ## Further work -No SIMD speedup is claimed. The vendored simplifier's embedded WASM is unchanged; only its remesh binding is patched. A SIMD build needs separate profiling and equivalence checks. Native adjacency kernels, GPU solid operations, inspection surface-band batching and a GPU MCP snapshot renderer remain separate projects. The previous Manifold experiment changed triangulation and did not consistently beat the existing engine, so the Boolean engine is retained. +The vendored simplifier's WASM includes the same 128 MiB occupied-voxel limit as the native remesher. A SIMD build needs separate profiling and equivalence checks. Native adjacency kernels, GPU solid operations, inspection surface-band batching and a GPU MCP snapshot renderer remain separate projects. The previous Manifold experiment changed triangulation and did not consistently beat the existing engine, so the Boolean engine is retained. diff --git a/native/README.md b/native/README.md index 2cbda45..387352c 100644 --- a/native/README.md +++ b/native/README.md @@ -1,14 +1,15 @@ # Optional native mesh kernels -`meshoptimizer/` contains unmodified source files from `zeux/meshoptimizer` tag -`v1.3`, commit `9e1f07b159d3cb777f1c67ed31fc11fd117986f4`, under its included MIT -license. Keep these aligned with `src/vendor/meshoptimizer/`. +`meshoptimizer/` contains source files from `zeux/meshoptimizer` tag `v1.3`, +commit `9e1f07b159d3cb777f1c67ed31fc11fd117986f4`, under its included MIT license. +The remesher has a Kitbasher patch that caps occupied-voxel storage at 128 MiB +before allocation. Keep this patch aligned with `src/vendor/meshoptimizer/`. `mesh-kernel.cpp` is Kitbasher's bounded, one-job binary stdin/stdout adapter. It reduces indexed meshes, including colors and locked borders, or remeshes into -an arena of at most one million triangles. It validates dimensions, finite data -and index bounds before entering the kernel. It reads no scene files and opens -no network connections. +an arena of at most one million triangles at resolutions 24 through 256. It +validates dimensions, finite data and index bounds before entering the kernel. +It reads no scene files and opens no network connections. Build with `npm run build:native`. Use `KITBASHER_NATIVE_MESH=1` when launching the local host to opt into native reduction; `all` additionally enables remeshing diff --git a/native/mesh-kernel.cpp b/native/mesh-kernel.cpp index d9f62fc..54388f3 100644 --- a/native/mesh-kernel.cpp +++ b/native/mesh-kernel.cpp @@ -25,7 +25,7 @@ int main() { count<3 || count>30000000 || count%3 || colors>1 || lock>1 || !std::isfinite(error) || error<0 || error>1 || (mode==0 && (target<3 || target>count || target%3)) || - (mode==1 && (resolution<24 || resolution>128))) return fail("Invalid mesh kernel request."); + (mode==1 && (resolution<24 || resolution>256))) return fail("Invalid mesh kernel request."); const size_t bytes=size_t(vertices)*12*(colors?2:1)+size_t(count)*4; if(bytes>512u*1024u*1024u) return fail("Native mesh request exceeds the memory limit."); std::vector positions(size_t(vertices)*3), attributes(colors?size_t(vertices)*3:0); @@ -49,6 +49,7 @@ int main() { const size_t capacity=1000000; surface.resize(capacity*9); result=meshopt_remesh(surface.data(),capacity,indices.data(),count,positions.data(),vertices,12,resolution,0); + if(result==size_t(-1)) return fail("The remesh exceeded the voxel memory limit. Lower voxel resolution."); if(result>capacity) return fail("The remesh exceeded one million triangles. Lower voxel resolution."); result*=9; } diff --git a/native/meshoptimizer/remesher.cpp b/native/meshoptimizer/remesher.cpp index 9279cc3..ca047dd 100644 --- a/native/meshoptimizer/remesher.cpp +++ b/native/meshoptimizer/remesher.cpp @@ -738,6 +738,10 @@ size_t meshopt_remesh(float* destination, size_t max_triangle_count, const unsig if (destination) { + // Kitbasher: bound occupied-voxel scratch before allocating it. + if (voxel_count > (128u * 1024u * 1024u) / sizeof(Voxel)) + return size_t(-1); + voxels = allocator.allocate(voxel_count); memset(voxels, 0, voxel_count * sizeof(Voxel)); } diff --git a/src/components/MeshProcessingDialog.tsx b/src/components/MeshProcessingDialog.tsx index d915d3b..5a679d8 100644 --- a/src/components/MeshProcessingDialog.tsx +++ b/src/components/MeshProcessingDialog.tsx @@ -2,6 +2,12 @@ import { useEffect, useRef, useState } from 'react'; import type { BufferGeometry } from 'three'; import { triangleCount } from '../core/geometry'; import { processMeshInWorker } from '../core/mesh-job'; +import { + DEFAULT_REMESH_RESOLUTION, + isRemeshResolution, + MAX_REMESH_RESOLUTION, + MIN_REMESH_RESOLUTION, +} from '../core/remesh-settings'; import { useActivity } from '../core/activity'; import { useEditor } from '../core/store'; import { Modal, RadioGroup } from './ui'; @@ -17,7 +23,7 @@ export function MeshProcessingDialog() { const [mode, setMode] = useState<'decimate' | 'remesh'>('decimate'); const [percent, setPercent] = useState(25); const [errorLimit, setErrorLimit] = useState(0.1); - const [resolution, setResolution] = useState(64); + const [resolution, setResolution] = useState(DEFAULT_REMESH_RESOLUTION); const [lockBorder, setLockBorder] = useState(true); const [keepOriginal, setKeepOriginal] = useState(true); const [busy, setBusy] = useState(false); @@ -114,7 +120,7 @@ export function MeshProcessingDialog() { const valid = mode === 'decimate' ? percent > 0 && percent <= 100 && errorLimit >= 0 && errorLimit <= 100 - : Number.isInteger(resolution) && resolution >= 24 && resolution <= 128; + : isRemeshResolution(resolution); return ( ) : ( )}