Implement mesh patch material arrays and device transfer
Mesh materials are transitioning from per-facet to per-patch granularity. This adds the infrastructure to store and transfer patch material data to device memory, parallel to existing facet arrays.
Changes
Type Definitions
- Added
patchID_t(uint16_t) for patch identification
API-Level Arrays
-
m_mesh_facet_patch- maps each facet to its parent patch -
m_mesh_patch_owner- owner ID per patch (flattened across meshes) -
m_mesh_patch_materials- material offset per patch -
nMeshPatches- total patch count - Marked
m_mesh_facet_materialsas deprecated
Device Arrays (dT)
-
triPatchID- patch ID per triangle -
ownerMeshPatch- owner per patch -
patchMaterialOffset- material offset per patch
Initialization
- Meshes without explicit patches default to single patch (ID 0)
- Patch materials derived from constituent facet materials
- Data flows through
initGPUArrays→populateEntityArrays→ device arrays
Example Usage
auto mesh = DEMSim.LoadMeshType("mesh.obj", material);
mesh->SplitIntoConvexPatches(30.0); // Creates patches
// At initialization:
// m_mesh_patch_owner: [0, 0, 0, ...] // One entry per patch
// m_mesh_facet_patch: [0, 0, 1, 1, 2, ...] // Maps facets to patches
// m_mesh_patch_materials: [mat_id, mat_id, ...] // One per patch
Force model integration (using triPatchID to index patchMaterialOffset) deferred to follow-up work.
Original prompt
Implicitly, all mesh patches have IDs, just like triangle facets. Now we need to do something about them. 1. We already have flattened arrays m_mesh_patch_owner and m_mesh_patch_materials (but are currently not used). These should now store flattened triangle mesh information at initialization, and then transfer the information to dT, very similar to the triangle facet info. Also, as now only patches have material properties, m_mesh_facet_materials should retire now and its usage is replaced by m_mesh_patch_materials. 2. We need to add m_mesh_facet_patch to store the facets' patch belonging info (which is useful in the force model when the model acquires material info; but the actual implementation of this can be done later). For now, just prepare the flattened info in these arrays and transfer to dT, similar to what we already do for facets.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.