This commit is contained in:
Hans Goudey 2022-08-25 17:21:08 -04:00
parent c8f9b02acd
commit 304864219c
18 changed files with 205 additions and 114 deletions

View File

@ -1448,7 +1448,6 @@ Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
for (int i = 0; i < mesh->totvert; i++) {
copy_v3_v3(mvert[i].co, process.co[i]);
mvert->bweight = 0;
mvert->flag = 0;
}
MEM_freeN(process.co);

View File

@ -250,8 +250,13 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
if (!BLO_write_is_undo(writer)) {
BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
BKE_mesh_legacy_convert_selection_layers_to_flags(mesh);
/* When converting to the old mesh format, don't save redunant attributes. */
names_to_skip.add_multiple_new({".hide_vert", ".hide_edge", ".hide_poly"});
/* When converting to the old mesh format, don't save redundant attributes. */
names_to_skip.add_multiple_new({".hide_vert",
".hide_edge",
".hide_poly",
".selection_vert",
".selection_edge",
".selection_poly"});
}
CustomData_blend_write_prepare(mesh->vdata, vert_layers, names_to_skip);

View File

@ -375,7 +375,6 @@ static void copy_vert_attributes(Mesh *dest_mesh,
int index_in_orig_me)
{
mv->bweight = orig_mv->bweight;
mv->flag = orig_mv->flag;
/* For all layers in the orig mesh, copy the layer information. */
CustomData *target_cd = &dest_mesh->vdata;

View File

@ -165,14 +165,14 @@ bool BKE_object_defgroup_clear(Object *ob, bDeformGroup *dg, const bool use_sele
}
else {
if (me->dvert) {
MVert *mv;
const bool *selection_vert = (const bool *)CustomData_get_layer_named(
&me->vdata, CD_PROP_BOOL, ".selection_vert");
int i;
mv = me->mvert;
dv = me->dvert;
for (i = 0; i < me->totvert; i++, mv++, dv++) {
if (dv->dw && (!use_selection || (mv->flag & SELECT))) {
for (i = 0; i < me->totvert; i++, dv++) {
if (dv->dw && (!use_selection || (selection_vert && selection_vert[i]))) {
MDeformWeight *dw = BKE_defvert_find_index(dv, def_nr);
BKE_defvert_remove_group(dv, dw); /* dw can be NULL */
changed = true;

View File

@ -1116,8 +1116,6 @@ static void subdiv_mesh_vertex_of_loose_edge(const SubdivForeachContext *foreach
MVert *subdiv_vertex = &subdiv_mvert[subdiv_vertex_index];
BKE_subdiv_mesh_interpolate_position_on_edge(
coarse_mesh, coarse_edge, is_simple, u, subdiv_vertex->co);
/* Reset flags and such. */
subdiv_vertex->flag = 0;
/* TODO(sergey): This matches old behavior, but we can as well interpolate
* it. Maybe even using vertex varying attributes. */
subdiv_vertex->bweight = 0.0f;

View File

@ -720,8 +720,7 @@ BMesh *BM_mesh_copy(BMesh *bm_old)
char BM_edge_flag_from_mflag(const short mflag)
{
return ((((mflag & ME_SEAM) ? BM_ELEM_SEAM : 0) |
((mflag & ME_EDGEDRAW) ? BM_ELEM_DRAW : 0) |
return (((mflag & ME_SEAM) ? BM_ELEM_SEAM : 0) | ((mflag & ME_EDGEDRAW) ? BM_ELEM_DRAW : 0) |
((mflag & ME_SHARP) == 0 ? BM_ELEM_SMOOTH : 0));
}
char BM_face_flag_from_mflag(const char mflag)

View File

@ -202,10 +202,13 @@ static void envelope_bone_weighting(Object *ob,
use_mask = true;
}
const bool *selection_vert = (const bool *)CustomData_get_layer_named(
&mesh->vdata, CD_PROP_BOOL, ".selection_vert");
/* for each vertex in the mesh */
for (int i = 0; i < mesh->totvert; i++) {
if (use_mask && !(mesh->mvert[i].flag & SELECT)) {
if (use_mask && !(selection_vert && selection_vert[i])) {
continue;
}

View File

@ -652,7 +652,6 @@ void heat_bone_weighting(Object *ob,
int a, tris_num, j, bbone, firstsegment, lastsegment;
bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0;
MVert *mvert = me->mvert;
bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;

View File

@ -891,9 +891,9 @@ static void mesh_add_verts(Mesh *mesh, int len)
mesh->totvert = totvert;
const bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
const bke::SpanAttributeWriter<bool> selection_vert =
attributes.lookup_or_add_for_write_span<bool>(".selection_vert", ATTR_DOMAIN_POINT);
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
bke::SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_span<bool>(
".selection_vert", ATTR_DOMAIN_POINT);
selection_vert.span.take_back(len).fill(true);
selection_vert.finish();
}
@ -933,9 +933,9 @@ static void mesh_add_edges(Mesh *mesh, int len)
mesh->totedge = totedge;
const bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
const bke::SpanAttributeWriter<bool> selection_edge =
attributes.lookup_or_add_for_write_span<bool>(".selection_edge", ATTR_DOMAIN_EDGE);
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
bke::SpanAttributeWriter<bool> selection_edge = attributes.lookup_or_add_for_write_span<bool>(
".selection_edge", ATTR_DOMAIN_EDGE);
selection_edge.span.take_back(len).fill(true);
selection_edge.finish();
}
@ -972,8 +972,7 @@ static void mesh_add_polys(Mesh *mesh, int len)
{
using namespace blender;
CustomData pdata;
MPoly *mpoly;
int i, totpoly;
int totpoly;
if (len == 0) {
return;
@ -997,9 +996,9 @@ static void mesh_add_polys(Mesh *mesh, int len)
mesh->totpoly = totpoly;
const bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
const bke::SpanAttributeWriter<bool> selection_poly =
attributes.lookup_or_add_for_write_span<bool>(".selection_poly", ATTR_DOMAIN_FACE);
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*mesh);
bke::SpanAttributeWriter<bool> selection_poly = attributes.lookup_or_add_for_write_span<bool>(
".selection_poly", ATTR_DOMAIN_FACE);
selection_poly.span.take_back(len).fill(true);
selection_poly.finish();
}

View File

@ -526,6 +526,7 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList *UNUSED(reports),
Object *ob,
ModifierData *md)
{
using namespace blender;
int cvert = 0;
if (md->type != eModifierType_ParticleSystem) {
@ -590,16 +591,22 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList *UNUSED(reports),
me->medge = (MEdge *)CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, nullptr, edges_num);
me->mface = (MFace *)CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, nullptr, 0);
int vert_index = 0;
MVert *mvert = me->mvert;
MEdge *medge = me->medge;
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_span<bool>(
".selection_vert", ATTR_DOMAIN_POINT);
/* copy coordinates */
cache = psys_eval->pathcache;
for (int a = 0; a < part_num; a++) {
ParticleCacheKey *key = cache[a];
int kmax = key->segments;
for (int k = 0; k <= kmax; k++, key++, cvert++, mvert++) {
copy_v3_v3(mvert->co, key->co);
for (int k = 0; k <= kmax; k++, key++, cvert++, vert_index++) {
copy_v3_v3(mvert[vert_index].co, key->co);
if (k) {
medge->v1 = cvert - 1;
medge->v2 = cvert;
@ -608,7 +615,7 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList *UNUSED(reports),
}
else {
/* cheap trick to select the roots */
mvert->flag |= SELECT;
selection_vert.span[vert_index] = true;
}
}
}
@ -617,8 +624,8 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList *UNUSED(reports),
for (int a = 0; a < child_num; a++) {
ParticleCacheKey *key = cache[a];
int kmax = key->segments;
for (int k = 0; k <= kmax; k++, key++, cvert++, mvert++) {
copy_v3_v3(mvert->co, key->co);
for (int k = 0; k <= kmax; k++, key++, cvert++, vert_index++) {
copy_v3_v3(mvert[vert_index].co, key->co);
if (k) {
medge->v1 = cvert - 1;
medge->v2 = cvert;
@ -627,11 +634,13 @@ bool ED_object_modifier_convert_psys_to_mesh(ReportList *UNUSED(reports),
}
else {
/* cheap trick to select the roots */
mvert->flag |= SELECT;
selection_vert.span[vert_index] = true;
}
}
}
selection_vert.finish();
DEG_relations_tag_update(bmain);
return true;

View File

@ -31,6 +31,7 @@
#include "BLI_utildefines_stack.h"
#include "BLI_vector.hh"
#include "BKE_attribute.hh"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_deform.h"
@ -151,6 +152,7 @@ bool ED_vgroup_parray_alloc(ID *id,
int *dvert_tot,
const bool use_vert_sel)
{
using namespace blender;
*dvert_tot = 0;
*dvert_arr = nullptr;
@ -197,7 +199,6 @@ bool ED_vgroup_parray_alloc(ID *id,
return true;
}
if (me->dvert) {
MVert *mvert = me->mvert;
MDeformVert *dvert = me->dvert;
*dvert_tot = me->totvert;
@ -205,8 +206,12 @@ bool ED_vgroup_parray_alloc(ID *id,
MEM_mallocN(sizeof(void *) * me->totvert, __func__));
if (use_vert_sel) {
const bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
".selection_vert", ATTR_DOMAIN_POINT, false);
for (int i = 0; i < me->totvert; i++) {
(*dvert_arr)[i] = (mvert[i].flag & SELECT) ? &dvert[i] : nullptr;
(*dvert_arr)[i] = selection_vert[i] ? &dvert[i] : nullptr;
}
}
else {
@ -632,6 +637,7 @@ static bool vgroup_normalize_active_vertex(Object *ob, eVGroupSelect subset_type
static void vgroup_copy_active_to_sel(Object *ob, eVGroupSelect subset_type)
{
using namespace blender;
Mesh *me = static_cast<Mesh *>(ob->data);
BMEditMesh *em = me->edit_mesh;
MDeformVert *dvert_act;
@ -659,14 +665,19 @@ static void vgroup_copy_active_to_sel(Object *ob, eVGroupSelect subset_type)
}
}
else {
const bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
".selection_vert", ATTR_DOMAIN_POINT, false);
MDeformVert *dv;
int v_act;
dvert_act = ED_mesh_active_dvert_get_ob(ob, &v_act);
if (dvert_act) {
dv = me->dvert;
for (i = 0; i < me->totvert; i++, dv++) {
if ((me->mvert[i].flag & SELECT) && dv != dvert_act) {
if (selection_vert[i] && dv != dvert_act) {
BKE_defvert_copy_subset(dv, dvert_act, vgroup_validmap, vgroup_tot);
if (me->symmetry & ME_SYMMETRY_X) {
ED_mesh_defvert_mirror_update_ob(ob, -1, i);
@ -1006,6 +1017,7 @@ void ED_vgroup_select_by_name(Object *ob, const char *name)
/* only in editmode */
static void vgroup_select_verts(Object *ob, int select)
{
using namespace blender;
const int def_nr = BKE_object_defgroup_active_index_get(ob) - 1;
const ListBase *defbase = BKE_object_defgroup_list(ob);
@ -1045,28 +1057,24 @@ static void vgroup_select_verts(Object *ob, int select)
}
else {
if (me->dvert) {
const bool *hide_vert = (const bool *)CustomData_get_layer_named(
&me->vdata, CD_PROP_BOOL, ".hide_vert");
MVert *mv;
MDeformVert *dv;
int i;
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
".hide_vert", ATTR_DOMAIN_POINT, false);
bke::SpanAttributeWriter<bool> selection_vert =
attributes.lookup_or_add_for_write_only_span<bool>(".selection_vert",
ATTR_DOMAIN_POINT);
mv = me->mvert;
dv = me->dvert;
const MDeformVert *dverts = me->dvert;
for (i = 0; i < me->totvert; i++, mv++, dv++) {
if (hide_vert != nullptr && !hide_vert[i]) {
if (BKE_defvert_find_index(dv, def_nr)) {
if (select) {
mv->flag |= SELECT;
}
else {
mv->flag &= ~SELECT;
}
for (const int i : selection_vert.span.index_range()) {
if (hide_vert[i]) {
if (BKE_defvert_find_index(&dverts[i], def_nr)) {
selection_vert.span[i] = select;
}
}
}
selection_vert.finish();
paintvert_flush_flags(ob);
}
}
@ -1512,6 +1520,7 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph,
static void vgroup_fix(
const bContext *C, Scene *UNUSED(scene), Object *ob, float distToBe, float strength, float cp)
{
using namespace blender;
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
@ -1522,8 +1531,11 @@ static void vgroup_fix(
if (!(me->editflag & ME_EDIT_PAINT_VERT_SEL)) {
return;
}
const bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
".selection_vert", ATTR_DOMAIN_POINT, false);
for (i = 0; i < me->totvert && mvert; i++, mvert++) {
if (mvert->flag & SELECT) {
if (selection_vert[i]) {
blender::Vector<int> verts = getSurroundingVerts(me, i);
const int count = verts.size();
if (!verts.is_empty()) {
@ -1883,6 +1895,7 @@ static void vgroup_smooth_subset(Object *ob,
const int repeat,
const float fac_expand)
{
using namespace blender;
const float ifac = 1.0f - fac;
MDeformVert **dvert_array = nullptr;
int dvert_tot = 0;
@ -1902,6 +1915,10 @@ static void vgroup_smooth_subset(Object *ob,
BMesh *bm = em ? em->bm : nullptr;
Mesh *me = em ? nullptr : static_cast<Mesh *>(ob->data);
const bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
".selection_vert", ATTR_DOMAIN_POINT, false);
MeshElemMap *emap;
int *emap_mem;
@ -1945,7 +1962,7 @@ static void vgroup_smooth_subset(Object *ob,
nullptr;
#define IS_ME_VERT_READ(v) (use_hide ? (hide_vert && hide_vert[v]) : true)
#define IS_ME_VERT_WRITE(v) (use_select ? (((v)->flag & SELECT) != 0) : true)
#define IS_ME_VERT_WRITE(v) (use_select ? selection_vert[v] : true)
/* initialize used verts */
if (bm) {
@ -1966,8 +1983,7 @@ static void vgroup_smooth_subset(Object *ob,
}
else {
for (int i = 0; i < dvert_tot; i++) {
const MVert *v = &me->mvert[i];
if (IS_ME_VERT_WRITE(v)) {
if (IS_ME_VERT_WRITE(i)) {
for (int j = 0; j < emap[i].count; j++) {
const MEdge *e = &me->medge[emap[i].indices[j]];
const int i_other = (e->v1 == i) ? e->v2 : e->v1;
@ -2040,7 +2056,7 @@ static void vgroup_smooth_subset(Object *ob,
int j;
/* checked already */
BLI_assert(IS_ME_VERT_WRITE(&me->mvert[i]));
BLI_assert(IS_ME_VERT_WRITE(i));
for (j = 0; j < emap[i].count; j++) {
MEdge *e = &me->medge[emap[i].indices[j]];
@ -2347,6 +2363,7 @@ void ED_vgroup_mirror(Object *ob,
int *r_totmirr,
int *r_totfail)
{
using namespace blender;
/* TODO: vgroup locking.
* TODO: face masking. */
@ -2444,7 +2461,7 @@ void ED_vgroup_mirror(Object *ob,
}
else {
/* object mode / weight paint */
MVert *mv, *mv_mirr;
MVert *mv;
int vidx, vidx_mirr;
const bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
@ -2458,16 +2475,19 @@ void ED_vgroup_mirror(Object *ob,
BLI_bitmap *vert_tag = BLI_BITMAP_NEW(me->totvert, __func__);
const bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
".selection_vert", ATTR_DOMAIN_POINT, false);
for (vidx = 0, mv = me->mvert; vidx < me->totvert; vidx++, mv++) {
if (!BLI_BITMAP_TEST(vert_tag, vidx)) {
if ((vidx_mirr = mesh_get_x_mirror_vert(ob, nullptr, vidx, use_topology)) != -1) {
if (vidx != vidx_mirr) {
mv_mirr = &me->mvert[vidx_mirr];
if (!BLI_BITMAP_TEST(vert_tag, vidx_mirr)) {
if (use_vert_sel) {
sel = mv->flag & SELECT;
sel_mirr = mv_mirr->flag & SELECT;
sel = selection_vert[vidx];
sel_mirr = selection_vert[vidx_mirr];
}
if (sel || sel_mirr) {
@ -2571,6 +2591,7 @@ static void vgroup_delete_active(Object *ob)
/* only in editmode */
static void vgroup_assign_verts(Object *ob, const float weight)
{
using namespace blender;
const int def_nr = BKE_object_defgroup_active_index_get(ob) - 1;
const ListBase *defbase = BKE_object_defgroup_list(ob);
@ -2609,6 +2630,10 @@ static void vgroup_assign_verts(Object *ob, const float weight)
}
}
else {
const bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
".selection_vert", ATTR_DOMAIN_POINT, false);
if (!me->dvert) {
BKE_object_defgroup_data_create(&me->id);
}
@ -2617,7 +2642,7 @@ static void vgroup_assign_verts(Object *ob, const float weight)
MDeformVert *dv = me->dvert;
for (int i = 0; i < me->totvert; i++, mv++, dv++) {
if (mv->flag & SELECT) {
if (selection_vert[i]) {
MDeformWeight *dw;
dw = BKE_defvert_ensure_index(dv, def_nr);
if (dw) {
@ -4298,6 +4323,7 @@ void OBJECT_OT_vertex_group_move(wmOperatorType *ot)
static void vgroup_copy_active_to_sel_single(Object *ob, const int def_nr)
{
using namespace blender;
MDeformVert *dvert_act;
Mesh *me = static_cast<Mesh *>(ob->data);
@ -4340,9 +4366,13 @@ static void vgroup_copy_active_to_sel_single(Object *ob, const int def_nr)
return;
}
const bke::AttributeAccessor attributes = bke::mesh_attributes(*me);
const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
".selection_vert", ATTR_DOMAIN_POINT, false);
dv = me->dvert;
for (i = 0; i < me->totvert; i++, dv++) {
if ((me->mvert[i].flag & SELECT) && (dv != dvert_act)) {
if (selection_vert[i] && (dv != dvert_act)) {
BKE_defvert_copy_index(dv, def_nr, dvert_act, def_nr);

View File

@ -3059,7 +3059,6 @@ static void do_vpaint_brush_blur_loops(bContext *C,
const int p_index = gmap->vert_to_poly[v_index].indices[j];
const int l_index = gmap->vert_to_loop[v_index].indices[j];
BLI_assert(me->mloop[l_index].v == v_index);
const MPoly *mp = &me->mpoly[p_index];
if (!use_face_sel || selection_poly[p_index]) {
Color color_orig(0, 0, 0, 0); /* unused when array is nullptr */
@ -3208,7 +3207,6 @@ static void do_vpaint_brush_blur_verts(bContext *C,
BLI_assert(me->mloop[gmap->vert_to_loop[v_index].indices[j]].v == v_index);
const MPoly *mp = &me->mpoly[p_index];
if (!use_face_sel || selection_poly[p_index]) {
Color color_orig(0, 0, 0, 0); /* unused when array is nullptr */
@ -3389,7 +3387,6 @@ static void do_vpaint_brush_smear(bContext *C,
BLI_assert(me->mloop[l_index].v == v_index);
}
const MPoly *mp = &me->mpoly[p_index];
if (!use_face_sel || selection_poly[p_index]) {
/* Get the previous element color */
Color color_orig(0, 0, 0, 0); /* unused when array is nullptr */
@ -3646,7 +3643,6 @@ static void vpaint_do_draw(bContext *C,
const int p_index = gmap->vert_to_poly[v_index].indices[j];
const int l_index = gmap->vert_to_loop[v_index].indices[j];
BLI_assert(me->mloop[l_index].v == v_index);
const MPoly *mp = &me->mpoly[p_index];
if (!use_face_sel || selection_poly[p_index]) {
Color color_orig = Color(0, 0, 0, 0); /* unused when array is nullptr */

View File

@ -45,6 +45,7 @@
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_attribute.hh"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_editmesh.h"
@ -334,26 +335,31 @@ static bool edbm_backbuf_check_and_select_verts_obmode(Mesh *me,
EditSelectBuf_Cache *esel,
const eSelectOp sel_op)
{
using namespace blender;
MVert *mv = me->mvert;
bool changed = false;
const BLI_bitmap *select_bitmap = esel->select_bitmap;
if (mv) {
const bool *hide_vert = (const bool *)CustomData_get_layer_named(
&me->vdata, CD_PROP_BOOL, ".hide_vert");
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_span<bool>(
".selection_vert", ATTR_DOMAIN_POINT);
const VArray<bool> hide_vert = attributes.lookup_or_default<bool>(
".hide_vert", ATTR_DOMAIN_POINT, false);
for (int index = 0; index < me->totvert; index++, mv++) {
if (!(hide_vert && hide_vert[index])) {
const bool is_select = mv->flag & SELECT;
if (!hide_vert[index]) {
const bool is_select = selection_vert.span[index];
const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
if (sel_op_result != -1) {
SET_FLAG_FROM_TEST(mv->flag, sel_op_result, SELECT);
selection_vert.span[index] = sel_op_result == 1;
changed = true;
}
}
}
selection_vert.finish();
}
return changed;
}
@ -363,22 +369,26 @@ static bool edbm_backbuf_check_and_select_faces_obmode(Mesh *me,
EditSelectBuf_Cache *esel,
const eSelectOp sel_op)
{
using namespace blender;
MPoly *mpoly = me->mpoly;
bool changed = false;
const BLI_bitmap *select_bitmap = esel->select_bitmap;
if (mpoly) {
const bool *hide_poly = (const bool *)CustomData_get_layer_named(
&me->pdata, CD_PROP_BOOL, ".hide_poly");
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::SpanAttributeWriter<bool> selection_poly = attributes.lookup_or_add_for_write_span<bool>(
".selection_poly", ATTR_DOMAIN_FACE);
const VArray<bool> hide_poly = attributes.lookup_or_default<bool>(
".hide_poly", ATTR_DOMAIN_FACE, false);
for (int index = 0; index < me->totpoly; index++, mpoly++) {
if (!(hide_poly && hide_poly[index])) {
const bool is_select = mpoly->flag & ME_FACE_SEL;
if (!hide_poly[index]) {
const bool is_select = selection_poly.span[index];
const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
if (sel_op_result != -1) {
SET_FLAG_FROM_TEST(mpoly->flag, sel_op_result, ME_FACE_SEL);
selection_poly.span[index] = sel_op_result == 1;
changed = true;
}
}
@ -1150,20 +1160,27 @@ static bool do_lasso_select_meta(ViewContext *vc,
return data.is_changed;
}
struct LassoSelectUserData_ForMeshVert {
LassoSelectUserData lasso_data;
blender::MutableSpan<bool> selection_vert;
};
static void do_lasso_select_meshobject__doSelectVert(void *userData,
MVert *mv,
MVert * /*mv*/,
const float screen_co[2],
int UNUSED(index))
int index)
{
LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
const bool is_select = mv->flag & SELECT;
using namespace blender;
LassoSelectUserData_ForMeshVert *mesh_data = static_cast<LassoSelectUserData_ForMeshVert *>(
userData);
LassoSelectUserData *data = &mesh_data->lasso_data;
const bool is_select = mesh_data->selection_vert[index];
const bool is_inside =
(BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
BLI_lasso_is_point_inside(
data->mcoords, data->mcoords_len, screen_co[0], screen_co[1], IS_CLIPPED));
const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
if (sel_op_result != -1) {
SET_FLAG_FROM_TEST(mv->flag, sel_op_result, SELECT);
mesh_data->selection_vert[index] = sel_op_result == 1;
data->is_changed = true;
}
}
@ -1173,6 +1190,7 @@ static bool do_lasso_select_paintvert(ViewContext *vc,
const int mcoords_len,
const eSelectOp sel_op)
{
using namespace blender;
const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
Object *ob = vc->obact;
Mesh *me = static_cast<Mesh *>(ob->data);
@ -1206,16 +1224,23 @@ static bool do_lasso_select_paintvert(ViewContext *vc,
}
}
else {
LassoSelectUserData data;
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_span<bool>(
".selection_vert", ATTR_DOMAIN_POINT);
view3d_userdata_lassoselect_init(&data, vc, &rect, mcoords, mcoords_len, sel_op);
LassoSelectUserData_ForMeshVert data;
data.selection_vert = selection_vert.span;
view3d_userdata_lassoselect_init(&data.lasso_data, vc, &rect, mcoords, mcoords_len, sel_op);
ED_view3d_init_mats_rv3d(vc->obact, vc->rv3d);
meshobject_foreachScreenVert(
vc, do_lasso_select_meshobject__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
changed |= data.is_changed;
changed |= data.lasso_data.is_changed;
selection_vert.finish();
}
if (changed) {
@ -2806,18 +2831,22 @@ static bool ed_wpaint_vertex_select_pick(bContext *C,
const SelectPick_Params *params,
Object *obact)
{
using namespace blender;
View3D *v3d = CTX_wm_view3d(C);
const bool use_zbuf = !XRAY_ENABLED(v3d);
Mesh *me = static_cast<Mesh *>(obact->data); /* already checked for nullptr */
uint index = 0;
MVert *mv;
bool changed = false;
bool found = ED_mesh_pick_vert(C, obact, mval, ED_MESH_PICK_DEFAULT_VERT_DIST, use_zbuf, &index);
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::AttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write<bool>(
".selection_vert", ATTR_DOMAIN_POINT);
if (params->sel_op == SEL_OP_SET) {
if ((found && params->select_passthrough) && (me->mvert[index].flag & SELECT)) {
if ((found && params->select_passthrough) && selection_vert.varray[index]) {
found = false;
}
else if (found || params->deselect_all) {
@ -2827,23 +2856,22 @@ static bool ed_wpaint_vertex_select_pick(bContext *C,
}
if (found) {
mv = &me->mvert[index];
switch (params->sel_op) {
case SEL_OP_ADD: {
mv->flag |= SELECT;
selection_vert.varray.set(index, true);
break;
}
case SEL_OP_SUB: {
mv->flag &= ~SELECT;
selection_vert.varray.set(index, false);
break;
}
case SEL_OP_XOR: {
mv->flag ^= SELECT;
selection_vert.varray.set(index, !selection_vert.varray[index]);
break;
}
case SEL_OP_SET: {
paintvert_deselect_all_visible(obact, SEL_DESELECT, false);
mv->flag |= SELECT;
selection_vert.varray.set(index, true);
break;
}
case SEL_OP_AND: {
@ -2853,13 +2881,15 @@ static bool ed_wpaint_vertex_select_pick(bContext *C,
}
/* update mselect */
if (mv->flag & SELECT) {
if (selection_vert.varray[index]) {
BKE_mesh_mselect_active_set(me, index, ME_VSEL);
}
else {
BKE_mesh_mselect_validate(me);
}
selection_vert.finish();
paintvert_flush_flags(obact);
changed = true;
@ -3092,17 +3122,23 @@ bool edge_inside_circle(const float cent[2],
return (dist_squared_to_line_segment_v2(cent, screen_co_a, screen_co_b) < radius_squared);
}
struct BoxSelectUserData_ForMeshVert {
BoxSelectUserData box_data;
blender::MutableSpan<bool> selection_vert;
};
static void do_paintvert_box_select__doSelectVert(void *userData,
MVert *mv,
MVert * /*mv*/,
const float screen_co[2],
int UNUSED(index))
int index)
{
BoxSelectUserData *data = static_cast<BoxSelectUserData *>(userData);
const bool is_select = mv->flag & SELECT;
BoxSelectUserData_ForMeshVert *mesh_data = static_cast<BoxSelectUserData_ForMeshVert *>(
userData);
BoxSelectUserData *data = &mesh_data->box_data;
const bool is_select = mesh_data->selection_vert[index];
const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
if (sel_op_result != -1) {
SET_FLAG_FROM_TEST(mv->flag, sel_op_result, SELECT);
mesh_data->selection_vert[index] = sel_op_result == 1;
data->is_changed = true;
}
}
@ -3111,6 +3147,7 @@ static bool do_paintvert_box_select(ViewContext *vc,
const rcti *rect,
const eSelectOp sel_op)
{
using namespace blender;
const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
Mesh *me = static_cast<Mesh *>(vc->obact->data);
@ -3139,15 +3176,22 @@ static bool do_paintvert_box_select(ViewContext *vc,
}
}
else {
BoxSelectUserData data;
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_span<bool>(
".selection_vert", ATTR_DOMAIN_POINT);
view3d_userdata_boxselect_init(&data, vc, rect, sel_op);
BoxSelectUserData_ForMeshVert data;
data.selection_vert = selection_vert.span;
view3d_userdata_boxselect_init(&data.box_data, vc, rect, sel_op);
ED_view3d_init_mats_rv3d(vc->obact, vc->rv3d);
meshobject_foreachScreenVert(
vc, do_paintvert_box_select__doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
changed |= data.is_changed;
changed |= data.box_data.is_changed;
selection_vert.finish();
}
if (changed) {
@ -3425,8 +3469,7 @@ static bool do_mesh_box_select(ViewContext *vc,
}
if (ts->selectmode & SCE_SELECT_EDGE) {
/* Does both use_zbuf and non-use_zbuf versions (need screen cos for both) */
struct BoxSelectUserData_ForMeshEdge cb_data {
};
struct BoxSelectUserData_ForMeshEdge cb_data {};
cb_data.data = &data;
cb_data.esel = use_zbuf ? esel : nullptr;
cb_data.backbuf_offset = use_zbuf ? DRW_select_buffer_context_offset_for_object_elem(
@ -4099,15 +4142,21 @@ static bool paint_facesel_circle_select(ViewContext *vc,
return changed;
}
struct CircleSelectUserData_ForMeshVert {
CircleSelectUserData circle_data;
blender::MutableSpan<bool> selection_vert;
};
static void paint_vertsel_circle_select_doSelectVert(void *userData,
MVert *mv,
MVert * /*mv*/,
const float screen_co[2],
int UNUSED(index))
int index)
{
CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
CircleSelectUserData_ForMeshVert *mesh_data = static_cast<CircleSelectUserData_ForMeshVert *>(
userData);
CircleSelectUserData *data = &mesh_data->circle_data;
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
SET_FLAG_FROM_TEST(mv->flag, data->select, SELECT);
mesh_data->selection_vert[index] = data->select;
data->is_changed = true;
}
}
@ -4117,6 +4166,7 @@ static bool paint_vertsel_circle_select(ViewContext *vc,
const int mval[2],
float rad)
{
using namespace blender;
BLI_assert(ELEM(sel_op, SEL_OP_SET, SEL_OP_ADD, SEL_OP_SUB));
const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
Object *ob = vc->obact;
@ -4148,14 +4198,21 @@ static bool paint_vertsel_circle_select(ViewContext *vc,
}
}
else {
CircleSelectUserData data;
bke::MutableAttributeAccessor attributes = bke::mesh_attributes_for_write(*me);
bke::SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_span<bool>(
".selection_vert", ATTR_DOMAIN_POINT);
CircleSelectUserData_ForMeshVert data;
data.selection_vert = selection_vert.span;
ED_view3d_init_mats_rv3d(vc->obact, vc->rv3d); /* for foreach's screen/vert projection */
view3d_userdata_circleselect_init(&data, vc, select, mval, rad);
view3d_userdata_circleselect_init(&data.circle_data, vc, select, mval, rad);
meshobject_foreachScreenVert(
vc, paint_vertsel_circle_select_doSelectVert, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
changed |= data.is_changed;
changed |= data.circle_data.is_changed;
selection_vert.finish();
}
if (changed) {

View File

@ -1268,7 +1268,6 @@ static void customdata_weld(
no[2] += mv_src_no[2];
#endif
bweight += mv_src->bweight;
flag |= mv_src->flag;
}
}
else if (type == CD_MEDGE) {
@ -1324,7 +1323,6 @@ static void customdata_weld(
mv_no[2] = (short)no[2];
#endif
mv->flag = (char)flag;
mv->bweight = (char)bweight;
}
else if (type == CD_MEDGE) {

View File

@ -27,7 +27,7 @@ typedef struct MVert {
float co[3];
char flag DNA_DEPRECATED;
char bweight;
char _pad[3];
char _pad[2];
} MVert;
/** #MVert.flag */

View File

@ -289,8 +289,7 @@ static void mesh_merge_transform(Mesh *result,
for (i = 0; i < cap_nverts; i++, mv++) {
mul_m4_v3(cap_offset, mv->co);
/* Reset MVert flags for caps */
mv->flag = mv->bweight = 0;
mv->bweight = 0;
}
/* We have to correct normals too, if we do not tag them as dirty later! */

View File

@ -5,6 +5,8 @@
* \ingroup modifiers
*/
#define DNA_DEPRECATED_ALLOW /* For #ME_FACE_SEL. */
#include "BLI_utildefines.h"
#include "BLI_edgehash.h"

View File

@ -2009,7 +2009,6 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
if (g->new_vert != MOD_SOLIDIFY_EMPTY_TAG) {
CustomData_copy_data(&mesh->vdata, &result->vdata, (int)i, (int)g->new_vert, 1);
copy_v3_v3(mvert[g->new_vert].co, g->co);
mvert[g->new_vert].flag = orig_mvert[i].flag;
}
}
}