Choosing Between MFnMesh::boundingBox + MItGeometry and MBoundingBox + Custom Octree for Paginated Large Mesh Queries
0 reputation · 22 Jul 2021, 04:17 UTC
0 reputation · 22 Jul 2021, 04:17 UTC
Goal: Retrieve vertex subsets of a large polygon mesh that fall inside a world‑space bounding box while processing the results in paginated chunks to keep memory usage low.
Constraint: Using MFnMesh::boundingBox requires multiplying the object‑space AABB by the mesh’s inclusive transformation matrix for each query, adding a per‑call matrix multiplication. MItGeometry can step through components with a fixed stride, giving a pagination‑like flow, but it does not expose a page number or offset and may produce non‑deterministic order on non‑manifold topology, forcing the caller to track counts and sort results. Alternatively, building an MBoundingBox‑based octree or kd‑tree enables fast spatial culling, yet the acceleration structure must be constructed once, consuming extra memory and time, and must be updated if the mesh is deformed.
Uncertainty: For a mesh that is static or changes infrequently but is queried many times with varying boxes and pagination needs, which combination—MFnMesh::boundingBox + MItGeometry or MBoundingBox + custom spatial index—delivers lower overall latency and predictable paging without excessive preprocessing overhead?
35275 reputation · 22 Jul 2021, 06:20 UTC
For a mesh that is static or changes infrequently but is queried many times with varying world‑space boxes, the MBoundingBox‑based spatial index (e.g., an octree) combined with a pagination wrapper yields lower per‑query latency and deterministic paging, provided you can afford the one‑time build cost and extra memory.
MFnMesh::boundingBox returns the object‑space AABB of the whole mesh; to test a world‑space box you must multiply that AABB by the mesh’s inclusive transformation matrix on every query.MItGeometry walks vertices, edges, faces or UVs with a fixed stride; each traversal is O(N) and does not expose a page number or offset, so the caller must count results and sort them if a deterministic order is required.MBoundingBox is an incremental accumulator; when used to build a custom octree (or kd‑tree) the construction is O(N) and once built a spatial query is O(log N + k) where k is the number of reported vertices.MFnMesh+MItGeometry path needs no extra structures.MFnMesh::boundingBox + MItGeometryTo finalize the recommendation, please specify the expected query frequency (e.g., average number of bounding‑box queries per frame or per second). This determines whether the amortized build cost of the octree is outweighed by per‑query savings.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 22 Jul 2021, 08:00 UTC
Additionally, to ensure deterministic pagination, the spatial index should store vertex indices in a sorted array within leaf nodes. Since MItGeometry does not provide a native offset or page number, relying on it for pagination requires the caller to manually count and skip results, which becomes a bottleneck on large meshes, especially those with non-manifold topology.