[Bf-blender-cvs] [c8f9b02acd5] refactor-mesh-selection-generic: Progress
Hans Goudey
noreply at git.blender.org
Fri Aug 26 04:35:03 CEST 2022
Commit: c8f9b02acd5c6c92b34884f551070464e5c36fc5
Author: Hans Goudey
Date: Thu Aug 25 14:46:35 2022 -0400
Branches: refactor-mesh-selection-generic
https://developer.blender.org/rBc8f9b02acd5c6c92b34884f551070464e5c36fc5
Progress
===================================================================
M source/blender/blenkernel/BKE_mesh_legacy_convert.h
M source/blender/blenkernel/intern/mesh.cc
M source/blender/blenkernel/intern/mesh_evaluate.cc
M source/blender/blenkernel/intern/mesh_legacy_convert.cc
M source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
M source/blender/editors/mesh/mesh_data.cc
M source/blender/editors/sculpt_paint/paint_image_proj.c
M source/blender/makesdna/DNA_meshdata_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh_legacy_convert.h b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
index bbc61d5af5e..c9c428e0dec 100644
--- a/source/blender/blenkernel/BKE_mesh_legacy_convert.h
+++ b/source/blender/blenkernel/BKE_mesh_legacy_convert.h
@@ -27,6 +27,16 @@ void BKE_mesh_legacy_convert_hide_layers_to_flags(struct Mesh *mesh);
*/
void BKE_mesh_legacy_convert_flags_to_hide_layers(struct Mesh *mesh);
+/**
+ * Convert the selected element attributes to the old flag format for writing.
+ */
+void BKE_mesh_legacy_convert_selection_layers_to_flags(struct Mesh *mesh);
+/**
+ * Convert the old selection flags (#SELECT/#ME_FACE_SEL) to the selected element attribute for
+ * reading. Only add the attributes when there are any elements in each domain selected.
+ */
+void BKE_mesh_legacy_convert_flags_to_selection_layers(struct Mesh *mesh);
+
/**
* Recreate #MFace Tessellation.
*
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 6aa59834472..7ff00fe700f 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -249,6 +249,7 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
Set<std::string> names_to_skip;
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"});
}
@@ -337,6 +338,7 @@ static void mesh_blend_read_data(BlendDataReader *reader, ID *id)
if (!BLO_read_data_is_undo(reader)) {
BKE_mesh_legacy_convert_flags_to_hide_layers(mesh);
+ BKE_mesh_legacy_convert_flags_to_selection_layers(mesh);
}
/* We don't expect to load normals from files, since they are derived data. */
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.cc b/source/blender/blenkernel/intern/mesh_evaluate.cc
index 2a3a62731f3..2294cb1c4af 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.cc
+++ b/source/blender/blenkernel/intern/mesh_evaluate.cc
@@ -837,7 +837,7 @@ void BKE_mesh_flush_select_from_polys(Mesh *me)
".selection_edge", ATTR_DOMAIN_EDGE);
/* Use generic domain interpolation to read the polygon attribute on the other domains.
- * Assume selected faces are not hidden and none of their verts/edges are hidden. */
+ * Assume selected faces are not hidden and none of their vertices/edges are hidden. */
attributes.lookup_or_default<bool>(".selection_poly", ATTR_DOMAIN_POINT, false)
.materialize(selection_vert.span);
attributes.lookup_or_default<bool>(".selection_poly", ATTR_DOMAIN_EDGE, false)
@@ -856,6 +856,7 @@ static void mesh_flush_select_from_verts(const Span<MEdge> edges,
MutableSpan<bool> selection_edge,
MutableSpan<bool> selection_poly)
{
+ /* Select visible edges that have both of their vertices selected. */
for (const int i : edges.index_range()) {
if (!hide_edge[i]) {
const MEdge &edge = edges[i];
@@ -863,6 +864,7 @@ static void mesh_flush_select_from_verts(const Span<MEdge> edges,
}
}
+ /* Select visible faces that have all of their vertices selected. */
for (const int i : polys.index_range()) {
if (!hide_poly[i]) {
const MPoly &poly = polys[i];
diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
index cc96a5e8c60..bfe7c588ca0 100644
--- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc
@@ -13,6 +13,7 @@
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
#include "BLI_edgehash.h"
#include "BLI_math.h"
@@ -962,3 +963,89 @@ void BKE_mesh_legacy_convert_flags_to_hide_layers(Mesh *mesh)
}
/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Selection Attribute and Legacy Flag Conversion
+ * \{ */
+
+void BKE_mesh_legacy_convert_selection_layers_to_flags(Mesh *mesh)
+{
+ using namespace blender;
+ using namespace blender::bke;
+ const AttributeAccessor attributes = mesh_attributes(*mesh);
+
+ MutableSpan<MVert> verts(mesh->mvert, mesh->totvert);
+ const VArray<bool> selection_vert = attributes.lookup_or_default<bool>(
+ ".selection_vert", ATTR_DOMAIN_POINT, false);
+ threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
+ for (const int i : range) {
+ SET_FLAG_FROM_TEST(verts[i].flag, selection_vert[i], SELECT);
+ }
+ });
+
+ MutableSpan<MEdge> edges(mesh->medge, mesh->totedge);
+ const VArray<bool> selection_edge = attributes.lookup_or_default<bool>(
+ ".selection_edge", ATTR_DOMAIN_EDGE, false);
+ threading::parallel_for(edges.index_range(), 4096, [&](IndexRange range) {
+ for (const int i : range) {
+ SET_FLAG_FROM_TEST(edges[i].flag, selection_edge[i], SELECT);
+ }
+ });
+
+ MutableSpan<MPoly> polys(mesh->mpoly, mesh->totpoly);
+ const VArray<bool> selection_poly = attributes.lookup_or_default<bool>(
+ ".selection_poly", ATTR_DOMAIN_FACE, false);
+ threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
+ for (const int i : range) {
+ SET_FLAG_FROM_TEST(polys[i].flag, selection_poly[i], ME_FACE_SEL);
+ }
+ });
+}
+
+void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
+{
+ using namespace blender;
+ using namespace blender::bke;
+ MutableAttributeAccessor attributes = mesh_attributes_for_write(*mesh);
+
+ const Span<MVert> verts(mesh->mvert, mesh->totvert);
+ if (std::any_of(
+ verts.begin(), verts.end(), [](const MVert &vert) { return vert.flag & SELECT; })) {
+ SpanAttributeWriter<bool> selection_vert = attributes.lookup_or_add_for_write_only_span<bool>(
+ ".selection_vert", ATTR_DOMAIN_POINT);
+ threading::parallel_for(verts.index_range(), 4096, [&](IndexRange range) {
+ for (const int i : range) {
+ selection_vert.span[i] = verts[i].flag & SELECT;
+ }
+ });
+ selection_vert.finish();
+ }
+
+ const Span<MEdge> edges(mesh->medge, mesh->totedge);
+ if (std::any_of(
+ edges.begin(), edges.end(), [](const MEdge &edge) { return edge.flag & SELECT; })) {
+ SpanAttributeWriter<bool> selection_edge = attributes.lookup_or_add_for_write_only_span<bool>(
+ ".selection_edge", ATTR_DOMAIN_EDGE);
+ threading::parallel_for(edges.index_range(), 4096, [&](IndexRange range) {
+ for (const int i : range) {
+ selection_edge.span[i] = edges[i].flag & SELECT;
+ }
+ });
+ selection_edge.finish();
+ }
+
+ const Span<MPoly> polys(mesh->mpoly, mesh->totpoly);
+ if (std::any_of(
+ polys.begin(), polys.end(), [](const MPoly &poly) { return poly.flag & ME_FACE_SEL; })) {
+ SpanAttributeWriter<bool> selection_poly = attributes.lookup_or_add_for_write_only_span<bool>(
+ ".selection_poly", ATTR_DOMAIN_FACE);
+ threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
+ for (const int i : range) {
+ selection_poly.span[i] = polys[i].flag & ME_FACE_SEL;
+ }
+ });
+ selection_poly.finish();
+ }
+}
+
+/** \} */
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
index df482a694ad..fa39957a7fc 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_edituv.cc
@@ -283,7 +283,6 @@ static void extract_edituv_lines_iter_subdiv_mesh(const DRWSubdivCache *subdiv_c
const MPoly *coarse_poly)
{
MeshExtract_EditUvElem_Data *data = static_cast<MeshExtract_EditUvElem_Data *>(_data);
-
int *subdiv_loop_edge_index = (int *)GPU_vertbuf_get_data(subdiv_cache->edges_orig_index);
const BMFace *efa = bm_original_face_get(mr, coarse_poly - mr->mpoly);
diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc
index 5e789388a7b..d6c18bafa4f 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -869,6 +869,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, bool calc_edges, bool calc_edges_lo
static void mesh_add_verts(Mesh *mesh, int len)
{
+ using namespace blender;
if (len == 0) {
return;
}
@@ -899,6 +900,7 @@ static void mesh_add_verts(Mesh *mesh, int len)
static void mesh_add_edges(Mesh *mesh, int len)
{
+ using namespace blender;
CustomData edata;
MEdge *medge;
int i, totedge;
@@ -995,7 +997,6 @@ static void mesh_add_polys(Mesh *mesh, int len)
mesh->totpoly = totpoly;
- /* TODO: Make selection optional. */
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);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 8f460635e40..680b3661dbf 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4144,7 +4144,6 @@ static bool project_paint_clone_face_skip(ProjPaintState *ps,
}
typedef struct {
- const MPoly *mpoly_orig;
const bool *selection_poly_orig;
const int *index_mp_to_orig;
@@ -4156,7 +4155,6 @@ static void proj_paint_face_lookup_init(const ProjPaintState *ps, ProjPaintFaceL
if (ps->do_face_sel) {
Mesh *orig_mesh = (Mesh *)ps->ob->data;
face_lookup->index_mp_to_orig = CustomData_get_layer(&ps->me_eval->pdata, CD_ORIGINDEX);
- face_lookup->mpoly_orig = orig_mesh->mpoly;
face_lookup->selection_poly_orig = CustomData_get_layer_named(
&orig_mesh->pdata, CD_PROP_BOOL, ".selection_poly");
}
diff --git a/source/blender/
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list