[Bf-blender-cvs] [15d85c54c3f] master: UI: Use full word for face set operator name, tweak description

Hans Goudey noreply at git.blender.org
Fri Sep 16 06:05:17 CEST 2022


Commit: 15d85c54c3f960814068074bcdff0a5546fa4d5a
Author: Hans Goudey
Date:   Thu Sep 15 23:04:55 2022 -0500
Branches: master
https://developer.blender.org/rB15d85c54c3f960814068074bcdff0a5546fa4d5a

UI: Use full word for face set operator name, tweak description

"Init" shouldn't be used in the UI, and avoid repeating the operator
name in its description.

===================================================================

A	source/blender/editors/sculpt_paint/sculpt_face_set.cc

===================================================================

diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc
new file mode 100644
index 00000000000..1d59ba34d3e
--- /dev/null
+++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc
@@ -0,0 +1,1505 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2020 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup edsculpt
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_hash.h"
+#include "BLI_math.h"
+#include "BLI_task.h"
+
+#include "DNA_brush_types.h"
+#include "DNA_customdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_brush.h"
+#include "BKE_ccg.h"
+#include "BKE_colortools.h"
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_fair.h"
+#include "BKE_mesh_mapping.h"
+#include "BKE_multires.h"
+#include "BKE_node.h"
+#include "BKE_object.h"
+#include "BKE_paint.h"
+#include "BKE_pbvh.h"
+#include "BKE_scene.h"
+
+#include "DEG_depsgraph.h"
+
+#include "WM_api.h"
+#include "WM_message.h"
+#include "WM_toolsystem.h"
+#include "WM_types.h"
+
+#include "ED_object.h"
+#include "ED_screen.h"
+#include "ED_sculpt.h"
+#include "ED_view3d.h"
+#include "paint_intern.h"
+#include "sculpt_intern.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "bmesh.h"
+
+#include <math.h>
+#include <stdlib.h>
+
+/* Utils. */
+
+int ED_sculpt_face_sets_find_next_available_id(struct Mesh *mesh)
+{
+  const int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
+  if (!face_sets) {
+    return SCULPT_FACE_SET_NONE;
+  }
+
+  int next_face_set_id = 0;
+  for (int i = 0; i < mesh->totpoly; i++) {
+    next_face_set_id = max_ii(next_face_set_id, face_sets[i]);
+  }
+  next_face_set_id++;
+
+  return next_face_set_id;
+}
+
+void ED_sculpt_face_sets_initialize_none_to_id(struct Mesh *mesh, const int new_id)
+{
+  int *face_sets = CustomData_get_layer(&mesh->pdata, CD_SCULPT_FACE_SETS);
+  if (!face_sets) {
+    return;
+  }
+
+  for (int i = 0; i < mesh->totpoly; i++) {
+    if (face_sets[i] == SCULPT_FACE_SET_NONE) {
+      face_sets[i] = new_id;
+    }
+  }
+}
+
+int ED_sculpt_face_sets_active_update_and_get(bContext *C, Object *ob, const float mval[2])
+{
+  SculptSession *ss = ob->sculpt;
+  if (!ss) {
+    return SCULPT_FACE_SET_NONE;
+  }
+
+  SculptCursorGeometryInfo gi;
+  if (!SCULPT_cursor_geometry_info_update(C, &gi, mval, false)) {
+    return SCULPT_FACE_SET_NONE;
+  }
+
+  return SCULPT_active_face_set_get(ss);
+}
+
+/* Draw Face Sets Brush. */
+
+static void do_draw_face_sets_brush_task_cb_ex(void *__restrict userdata,
+                                               const int n,
+                                               const TaskParallelTLS *__restrict tls)
+{
+  SculptThreadedTaskData *data = userdata;
+  SculptSession *ss = data->ob->sculpt;
+  const Brush *brush = data->brush;
+  const float bstrength = ss->cache->bstrength;
+
+  PBVHVertexIter vd;
+
+  SculptBrushTest test;
+  SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
+      ss, &test, data->brush->falloff_shape);
+  const int thread_id = BLI_task_parallel_thread_id(tls);
+
+  MVert *mvert = SCULPT_mesh_deformed_mverts_get(ss);
+
+  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
+    if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) {
+      MeshElemMap *vert_map = &ss->pmap[vd.index];
+      for (int j = 0; j < ss->pmap[vd.index].count; j++) {
+        const MPoly *p = &ss->mpoly[vert_map->indices[j]];
+
+        float poly_center[3];
+        BKE_mesh_calc_poly_center(p, &ss->mloop[p->loopstart], mvert, poly_center);
+
+        if (!sculpt_brush_test_sq_fn(&test, poly_center)) {
+          continue;
+        }
+        const bool face_hidden = ss->hide_poly && ss->hide_poly[vert_map->indices[j]];
+        if (face_hidden) {
+          continue;
+        }
+        const float fade = bstrength * SCULPT_brush_strength_factor(ss,
+                                                                    brush,
+                                                                    vd.co,
+                                                                    sqrtf(test.dist),
+                                                                    vd.no,
+                                                                    vd.fno,
+                                                                    vd.mask ? *vd.mask : 0.0f,
+                                                                    vd.vertex,
+                                                                    thread_id);
+
+        if (fade > 0.05f) {
+          ss->face_sets[vert_map->indices[j]] = ss->cache->paint_face_set;
+        }
+      }
+    }
+    else if (BKE_pbvh_type(ss->pbvh) == PBVH_GRIDS) {
+      if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
+        continue;
+      }
+      const float fade = bstrength * SCULPT_brush_strength_factor(ss,
+                                                                  brush,
+                                                                  vd.co,
+                                                                  sqrtf(test.dist),
+                                                                  vd.no,
+                                                                  vd.fno,
+                                                                  vd.mask ? *vd.mask : 0.0f,
+                                                                  vd.vertex,
+                                                                  thread_id);
+
+      if (fade > 0.05f) {
+        SCULPT_vertex_face_set_set(ss, vd.vertex, ss->cache->paint_face_set);
+      }
+    }
+  }
+  BKE_pbvh_vertex_iter_end;
+}
+
+static void do_relax_face_sets_brush_task_cb_ex(void *__restrict userdata,
+                                                const int n,
+                                                const TaskParallelTLS *__restrict tls)
+{
+  SculptThreadedTaskData *data = userdata;
+  SculptSession *ss = data->ob->sculpt;
+  const Brush *brush = data->brush;
+  float bstrength = ss->cache->bstrength;
+
+  PBVHVertexIter vd;
+
+  SculptBrushTest test;
+  SculptBrushTestFn sculpt_brush_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
+      ss, &test, data->brush->falloff_shape);
+
+  const bool relax_face_sets = !(ss->cache->iteration_count % 3 == 0);
+  /* This operations needs a strength tweak as the relax deformation is too weak by default. */
+  if (relax_face_sets) {
+    bstrength *= 2.0f;
+  }
+
+  const int thread_id = BLI_task_parallel_thread_id(tls);
+
+  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
+    if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
+      continue;
+    }
+    if (relax_face_sets == SCULPT_vertex_has_unique_face_set(ss, vd.vertex)) {
+      continue;
+    }
+
+    const float fade = bstrength * SCULPT_brush_strength_factor(ss,
+                                                                brush,
+                                                                vd.co,
+                                                                sqrtf(test.dist),
+                                                                vd.no,
+                                                                vd.fno,
+                                                                vd.mask ? *vd.mask : 0.0f,
+                                                                vd.vertex,
+                                                                thread_id);
+
+    SCULPT_relax_vertex(ss, &vd, fade * bstrength, relax_face_sets, vd.co);
+    if (vd.mvert) {
+      BKE_pbvh_vert_tag_update_normal(ss->pbvh, vd.vertex);
+    }
+  }
+  BKE_pbvh_vertex_iter_end;
+}
+
+void SCULPT_do_draw_face_sets_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
+{
+  SculptSession *ss = ob->sculpt;
+  Brush *brush = BKE_paint_brush(&sd->paint);
+
+  BKE_curvemapping_init(brush->curve);
+
+  /* Threaded loop over nodes. */
+  SculptThreadedTaskData data = {
+      .sd = sd,
+      .ob = ob,
+      .brush = brush,
+      .nodes = nodes,
+  };
+
+  TaskParallelSettings settings;
+  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
+  if (ss->cache->alt_smooth) {
+    SCULPT_boundary_info_ensure(ob);
+    for (int i = 0; i < 4; i++) {
+      BLI_task_parallel_range(0, totnode, &data, do_relax_face_sets_brush_task_cb_ex, &settings);
+    }
+  }
+  else {
+    BLI_task_parallel_range(0, totnode, &data, do_draw_face_sets_brush_task_cb_ex, &settings);
+  }
+}
+
+/* Face Sets Operators */
+
+typedef enum eSculptFaceGroupsCreateModes {
+  SCULPT_FACE_SET_MASKED = 0,
+  SCULPT_FACE_SET_VISIBLE = 1,
+  SCULPT_FACE_SET_ALL = 2,
+  SCULPT_FACE_SET_SELECTION = 3,
+} eSculptFaceGroupsCreateModes;
+
+static EnumPropertyItem prop_sculpt_face_set_create_types[] = {
+    {
+        SCULPT_FACE_SET_MASKED,
+        "MASKED",
+        0,
+        "Face Set from Masked",
+        "Create a new Face Set from the masked faces",
+    },
+    {
+        SCULPT_FACE_SET_VISIBLE,
+        "VISIBLE",
+        0,
+        "Face Set from Visible",
+        "Create a new Face Set from the visible vertices",
+    },
+    {
+        SCULPT_FACE_SET_ALL,
+        "ALL",
+        0,
+        "Face Set Full Mesh",
+        "Create an unique Face Set with all faces in the sculpt",
+    },
+    {
+        SCULPT_FACE_SET_SELECTION,
+        "SELECTION",
+        0,
+        "Face Set from Edit Mode Selection",
+        "Create an Face Set corresponding to the Edit Mode face selection",
+    },
+    {0, nullptr, 0, nullptr, nullptr},
+};
+
+static int sculpt_face_set_create_exec(bContext *C, wmOperator *op)
+{
+  Object *ob = CTX_data_active_object(C);
+  SculptSession *ss = ob->sculpt;
+  Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
+
+  const int mode = RNA_enum_get(op->ptr, "mode");
+
+  /* Dyntopo not supported. */
+  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
+    return OPERATOR_CANCELLED;
+  }
+
+  Mesh *mesh = ob->data;
+  ss->face_sets = BKE_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list