Changeset View
Changeset View
Standalone View
Standalone View
source/blender/modifiers/intern/MOD_mask.cc
| Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | static void compute_vertex_mask__armature_mode(MDeformVert *dvert, | ||||
| for (bDeformGroup *def : ListBaseWrapper<bDeformGroup>(ob->defbase)) { | for (bDeformGroup *def : ListBaseWrapper<bDeformGroup>(ob->defbase)) { | ||||
| bPoseChannel *pchan = BKE_pose_channel_find_name(armature_ob->pose, def->name); | bPoseChannel *pchan = BKE_pose_channel_find_name(armature_ob->pose, def->name); | ||||
| bool bone_for_group_exists = pchan && pchan->bone && (pchan->bone->flag & BONE_SELECTED); | bool bone_for_group_exists = pchan && pchan->bone && (pchan->bone->flag & BONE_SELECTED); | ||||
| selected_bone_uses_group.append(bone_for_group_exists); | selected_bone_uses_group.append(bone_for_group_exists); | ||||
| } | } | ||||
| Span<bool> use_vertex_group = selected_bone_uses_group; | Span<bool> use_vertex_group = selected_bone_uses_group; | ||||
| for (int i : r_vertex_mask.index_range()) { | for (int i : iter_indices(r_vertex_mask)) { | ||||
| Span<MDeformWeight> weights(dvert[i].dw, dvert[i].totweight); | Span<MDeformWeight> weights(dvert[i].dw, dvert[i].totweight); | ||||
| r_vertex_mask[i] = false; | r_vertex_mask[i] = false; | ||||
| /* check the groups that vertex is assigned to, and see if it was any use */ | /* check the groups that vertex is assigned to, and see if it was any use */ | ||||
| for (const MDeformWeight &dw : weights) { | for (const MDeformWeight &dw : weights) { | ||||
| if (use_vertex_group.get(dw.def_nr, false)) { | if (use_vertex_group.get(dw.def_nr, false)) { | ||||
| if (dw.weight > threshold) { | if (dw.weight > threshold) { | ||||
| r_vertex_mask[i] = true; | r_vertex_mask[i] = true; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* A vertex will be in the mask if the vertex group influences it more than a certain threshold. */ | /* A vertex will be in the mask if the vertex group influences it more than a certain threshold. */ | ||||
| static void compute_vertex_mask__vertex_group_mode(MDeformVert *dvert, | static void compute_vertex_mask__vertex_group_mode(MDeformVert *dvert, | ||||
| int defgrp_index, | int defgrp_index, | ||||
| float threshold, | float threshold, | ||||
| MutableSpan<bool> r_vertex_mask) | MutableSpan<bool> r_vertex_mask) | ||||
| { | { | ||||
| for (int i : r_vertex_mask.index_range()) { | for (int i : iter_indices(r_vertex_mask)) { | ||||
| const bool found = BKE_defvert_find_weight(&dvert[i], defgrp_index) > threshold; | const bool found = BKE_defvert_find_weight(&dvert[i], defgrp_index) > threshold; | ||||
| r_vertex_mask[i] = found; | r_vertex_mask[i] = found; | ||||
| } | } | ||||
| } | } | ||||
| static void invert_boolean_array(MutableSpan<bool> array) | static void invert_boolean_array(MutableSpan<bool> array) | ||||
| { | { | ||||
| for (bool &value : array) { | for (bool &value : array) { | ||||
| value = !value; | value = !value; | ||||
| } | } | ||||
| } | } | ||||
| static void compute_masked_vertices(Span<bool> vertex_mask, | static void compute_masked_vertices(Span<bool> vertex_mask, | ||||
| MutableSpan<int> r_vertex_map, | MutableSpan<int> r_vertex_map, | ||||
| uint *r_num_masked_vertices) | uint *r_num_masked_vertices) | ||||
| { | { | ||||
| BLI_assert(vertex_mask.size() == r_vertex_map.size()); | BLI_assert(vertex_mask.size() == r_vertex_map.size()); | ||||
| uint num_masked_vertices = 0; | uint num_masked_vertices = 0; | ||||
| for (uint i_src : r_vertex_map.index_range()) { | for (uint i_src : iter_indices(r_vertex_map)) { | ||||
| if (vertex_mask[i_src]) { | if (vertex_mask[i_src]) { | ||||
| r_vertex_map[i_src] = num_masked_vertices; | r_vertex_map[i_src] = num_masked_vertices; | ||||
| num_masked_vertices++; | num_masked_vertices++; | ||||
| } | } | ||||
| else { | else { | ||||
| r_vertex_map[i_src] = -1; | r_vertex_map[i_src] = -1; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static void computed_masked_polygons(const Mesh *mesh, | ||||
| *r_num_masked_loops = num_masked_loops; | *r_num_masked_loops = num_masked_loops; | ||||
| } | } | ||||
| static void copy_masked_vertices_to_new_mesh(const Mesh &src_mesh, | static void copy_masked_vertices_to_new_mesh(const Mesh &src_mesh, | ||||
| Mesh &dst_mesh, | Mesh &dst_mesh, | ||||
| Span<int> vertex_map) | Span<int> vertex_map) | ||||
| { | { | ||||
| BLI_assert(src_mesh.totvert == vertex_map.size()); | BLI_assert(src_mesh.totvert == vertex_map.size()); | ||||
| for (const int i_src : vertex_map.index_range()) { | for (const int i_src : iter_indices(vertex_map)) { | ||||
| const int i_dst = vertex_map[i_src]; | const int i_dst = vertex_map[i_src]; | ||||
| if (i_dst == -1) { | if (i_dst == -1) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| const MVert &v_src = src_mesh.mvert[i_src]; | const MVert &v_src = src_mesh.mvert[i_src]; | ||||
| MVert &v_dst = dst_mesh.mvert[i_dst]; | MVert &v_dst = dst_mesh.mvert[i_dst]; | ||||
| Show All 27 Lines | |||||
| static void copy_masked_polys_to_new_mesh(const Mesh &src_mesh, | static void copy_masked_polys_to_new_mesh(const Mesh &src_mesh, | ||||
| Mesh &dst_mesh, | Mesh &dst_mesh, | ||||
| Span<int> vertex_map, | Span<int> vertex_map, | ||||
| Span<int> edge_map, | Span<int> edge_map, | ||||
| Span<int> masked_poly_indices, | Span<int> masked_poly_indices, | ||||
| Span<int> new_loop_starts) | Span<int> new_loop_starts) | ||||
| { | { | ||||
| for (const int i_dst : masked_poly_indices.index_range()) { | for (const int i_dst : iter_indices(masked_poly_indices)) { | ||||
| const int i_src = masked_poly_indices[i_dst]; | const int i_src = masked_poly_indices[i_dst]; | ||||
| const MPoly &mp_src = src_mesh.mpoly[i_src]; | const MPoly &mp_src = src_mesh.mpoly[i_src]; | ||||
| MPoly &mp_dst = dst_mesh.mpoly[i_dst]; | MPoly &mp_dst = dst_mesh.mpoly[i_dst]; | ||||
| const int i_ml_src = mp_src.loopstart; | const int i_ml_src = mp_src.loopstart; | ||||
| const int i_ml_dst = new_loop_starts[i_dst]; | const int i_ml_dst = new_loop_starts[i_dst]; | ||||
| CustomData_copy_data(&src_mesh.pdata, &dst_mesh.pdata, i_src, i_dst, 1); | CustomData_copy_data(&src_mesh.pdata, &dst_mesh.pdata, i_src, i_dst, 1); | ||||
| ▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines | |||||