File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -437,6 +437,30 @@ function merge_vertex_indices(
437437end
438438
439439
440+ """
441+ split_mesh(mesh::Mesh, views::Vector{UnitRange{Int}} = mesh.views)
442+
443+ Creates a new mesh containing `faces(mesh)[range]` for each range in `views`.
444+ This also removes unused vertices.
445+ """
446+ function split_mesh (mesh:: Mesh , views:: Vector{UnitRange{Int}} = mesh. views)
447+ return map (views) do idxs
448+ new_fs, maps = merge_vertex_indices ((view (faces (mesh), idxs),))
449+ new_va = Dict {Symbol, VertexAttributeType} ()
450+
451+ for (k, v) in vertex_attributes (mesh)
452+ if v isa FaceView
453+ _fs, _maps = merge_vertex_indices ((view (faces (v), idxs),))
454+ new_va[k] = FaceView (values (v)[_maps[1 ]], _fs)
455+ else
456+ new_va[k] = v[maps[1 ]]
457+ end
458+ end
459+
460+ return Mesh (new_va, new_fs)
461+ end
462+ end
463+
440464
441465function map_coordinates (f, mesh:: Mesh )
442466 result = copy (mesh)
You can’t perform that action at this time.
0 commit comments