[Bf-blender-cvs] [d927f54da60] sculpt-dev: Merge branch 'arcpatch-D9622' into sculpt-dev
Pablo Dobarro
noreply at git.blender.org
Sun Feb 7 20:46:27 CET 2021
Commit: d927f54da6017cfe0011f28362a842070625ab4e
Author: Pablo Dobarro
Date: Sun Feb 7 19:18:46 2021 +0100
Branches: sculpt-dev
https://developer.blender.org/rBd927f54da6017cfe0011f28362a842070625ab4e
Merge branch 'arcpatch-D9622' into sculpt-dev
===================================================================
===================================================================
diff --cc source/blender/editors/sculpt_paint/sculpt_expand.c
index d5ecef86e59,00000000000..e3d4eed8ce1
mode 100644,000000..100644
--- a/source/blender/editors/sculpt_paint/sculpt_expand.c
+++ b/source/blender/editors/sculpt_paint/sculpt_expand.c
@@@ -1,1688 -1,0 +1,1688 @@@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup edsculpt
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_linklist_stack.h"
+#include "BLI_math.h"
+#include "BLI_task.h"
+
+#include "BLT_translation.h"
+
+#include "DNA_brush_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_brush.h"
+#include "BKE_ccg.h"
+#include "BKE_colortools.h"
+#include "BKE_context.h"
+#include "BKE_mesh.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 "RNA_access.h"
+#include "RNA_define.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 "IMB_colormanagement.h"
+#include "IMB_imbuf.h"
+
+#include "bmesh.h"
+
+#include <math.h>
+#include <stdlib.h>
+
+#define SCULPT_EXPAND_VERTEX_NONE -1
+
+enum {
+ SCULPT_EXPAND_MODAL_CONFIRM = 1,
+ SCULPT_EXPAND_MODAL_CANCEL,
+ SCULPT_EXPAND_MODAL_INVERT,
+ SCULPT_EXPAND_MODAL_PRESERVE_TOGGLE,
+ SCULPT_EXPAND_MODAL_GRADIENT_TOGGLE,
+ SCULPT_EXPAND_MODAL_FALLOFF_CYCLE,
+ SCULPT_EXPAND_MODAL_RECURSION_STEP_GEODESIC,
+ SCULPT_EXPAND_MODAL_RECURSION_STEP_TOPOLOGY,
+ SCULPT_EXPAND_MODAL_MOVE_TOGGLE,
+ SCULPT_EXPAND_MODAL_FALLOFF_GEODESIC,
+ SCULPT_EXPAND_MODAL_FALLOFF_TOPOLOGY,
+ SCULPT_EXPAND_MODAL_FALLOFF_TOPOLOGY_DIAGONALS,
+ SCULPT_EXPAND_MODAL_FALLOFF_SPHERICAL,
+ SCULPT_EXPAND_MODAL_SNAP_TOGGLE,
+ SCULPT_EXPAND_MODAL_LOOP_COUNT_INCREASE,
+ SCULPT_EXPAND_MODAL_LOOP_COUNT_DECREASE,
+ SCULPT_EXPAND_MODAL_BRUSH_GRADIENT_TOGGLE,
+};
+
+static EnumPropertyItem prop_sculpt_expand_falloff_type_items[] = {
+ {SCULPT_EXPAND_FALLOFF_GEODESIC, "GEODESIC", 0, "Geodesic", ""},
+ {SCULPT_EXPAND_FALLOFF_TOPOLOGY, "TOPOLOGY", 0, "Topology", ""},
+ {SCULPT_EXPAND_FALLOFF_TOPOLOGY_DIAGONALS, "TOPOLOGY_DIAGONALS", 0, "Topology Diagonals", ""},
+ {SCULPT_EXPAND_FALLOFF_NORMALS, "NORMALS", 0, "Normals", ""},
+ {SCULPT_EXPAND_FALLOFF_SPHERICAL, "SPHERICAL", 0, "Spherical", ""},
+ {SCULPT_EXPAND_FALLOFF_BOUNDARY_TOPOLOGY, "BOUNDARY_TOPOLOGY", 0, "Boundary Topology", ""},
+ {SCULPT_EXPAND_FALLOFF_BOUNDARY_FACE_SET, "BOUNDARY_FACE_SET", 0, "Boundary Face Set", ""},
+ {SCULPT_EXPAND_FALLOFF_ACTIVE_FACE_SET, "ACTIVE_FACE_SET", 0, "Active Face Set", ""},
+ {0, NULL, 0, NULL, NULL},
+};
+
+static EnumPropertyItem prop_sculpt_expand_target_type_items[] = {
+ {SCULPT_EXPAND_TARGET_MASK, "MASK", 0, "Mask", ""},
+ {SCULPT_EXPAND_TARGET_FACE_SETS, "FACE_SETS", 0, "Face Sets", ""},
+ {SCULPT_EXPAND_TARGET_COLORS, "COLOR", 0, "Color", ""},
+ {0, NULL, 0, NULL, NULL},
+};
+
+#define SCULPT_EXPAND_LOOP_THRESHOLD 0.00001f
+
+static bool sculpt_expand_state_get(SculptSession *ss, ExpandCache *expand_cache, const int i)
+{
+ if (!SCULPT_vertex_visible_get(ss, i)) {
+ return false;
+ }
+
+ bool enabled = false;
+
+ if (expand_cache->snap) {
+ const int face_set = SCULPT_vertex_face_set_get(ss, i);
+ enabled = BLI_gset_haskey(expand_cache->snap_enabled_face_sets, POINTER_FROM_INT(face_set));
+ }
+ else {
+ const float loop_len = (expand_cache->max_falloff_factor / expand_cache->loop_count) +
+ SCULPT_EXPAND_LOOP_THRESHOLD;
+
+ const float active_factor = fmod(expand_cache->active_factor, loop_len);
+ const float falloff_factor = fmod(expand_cache->falloff_factor[i], loop_len);
+
+ enabled = falloff_factor < active_factor;
+ }
+
+ if (expand_cache->invert) {
+ enabled = !enabled;
+ }
+ return enabled;
+}
+
+static bool sculpt_expand_face_state_get(SculptSession *ss, ExpandCache *expand_cache, const int f)
+{
+ if (ss->face_sets[f] <= 0) {
+ return false;
+ }
+
+ bool enabled = false;
+
+
+ if (expand_cache->snap_enabled_face_sets) {
+ const int face_set = ss->face_sets[f];
+ enabled = BLI_gset_haskey(expand_cache->snap_enabled_face_sets, POINTER_FROM_INT(face_set));
+ }
+ else {
+ const float loop_len = (expand_cache->max_face_falloff_factor / expand_cache->loop_count) +
+ SCULPT_EXPAND_LOOP_THRESHOLD;
+ const float active_factor = fmod(expand_cache->active_factor, loop_len);
+ const float falloff_factor = fmod(expand_cache->face_falloff_factor[f], loop_len);
+ enabled = falloff_factor < active_factor;
+ }
+
+ if (expand_cache->falloff_factor_type == SCULPT_EXPAND_FALLOFF_ACTIVE_FACE_SET) {
+ if (ss->face_sets[f] == expand_cache->initial_active_face_set) {
+ enabled = false;
+ }
+ }
+
+ if (expand_cache->invert) {
+ enabled = !enabled;
+ }
+
+ return enabled;
+}
+
+static float sculpt_expand_gradient_falloff_get(ExpandCache *expand_cache, const int i)
+{
+ if (!expand_cache->falloff_gradient) {
+ return 1.0f;
+ }
+
+ const float loop_len = (expand_cache->max_falloff_factor / expand_cache->loop_count) +
+ SCULPT_EXPAND_LOOP_THRESHOLD;
+ const float active_factor = fmod(expand_cache->active_factor, loop_len);
+ const float falloff_factor = fmod(expand_cache->falloff_factor[i], loop_len);
+
+ float linear_falloff;
+
+ if (expand_cache->invert) {
+ linear_falloff = (falloff_factor - active_factor) / (loop_len - active_factor);
+ }
+ else {
+ linear_falloff = 1.0f - (falloff_factor / active_factor);
+ }
+
+ if (!expand_cache->brush_gradient) {
+ return linear_falloff;
+ }
+
+ return BKE_brush_curve_strength(expand_cache->brush, linear_falloff, 1.0f);
+}
+
+static float *sculpt_expand_geodesic_falloff_create(Sculpt *sd, Object *ob, const int vertex)
+{
+ return SCULPT_geodesic_from_vertex_and_symm(sd, ob, vertex, FLT_MAX);
+}
+
+typedef struct ExpandFloodFillData {
+ float original_normal[3];
+ float edge_sensitivity;
+ float *dists;
+ float *edge_factor;
+} ExpandFloodFillData;
+
+static bool expand_topology_floodfill_cb(
+ SculptSession *UNUSED(ss), int from_v, int to_v, bool is_duplicate, void *userdata)
+{
+ ExpandFloodFillData *data = userdata;
+ if (!is_duplicate) {
+ const float to_it = data->dists[from_v] + 1.0f;
+ data->dists[to_v] = to_it;
+ }
+ else {
+ data->dists[to_v] = data->dists[from_v];
+ }
+ return true;
+}
+
+static float *sculpt_expand_topology_falloff_create(Sculpt *sd, Object *ob, const int vertex)
+{
+ SculptSession *ss = ob->sculpt;
+ const int totvert = SCULPT_vertex_count_get(ss);
+ float *dists = MEM_calloc_arrayN(sizeof(float), totvert, "topology dist");
+
+ SculptFloodFill flood;
+ SCULPT_floodfill_init(ss, &flood);
+ SCULPT_floodfill_add_initial_with_symmetry(sd, ob, ss, &flood, vertex, FLT_MAX);
+
+ ExpandFloodFillData fdata;
+ fdata.dists = dists;
+
+ SCULPT_floodfill_execute(ss, &flood, expand_topology_floodfill_cb, &fdata);
+ SCULPT_floodfill_free(&flood);
+
+ return dists;
+}
+
+static bool mask_expand_normal_floodfill_cb(
+ SculptSession *ss, int from_v, int to_v, bool is_duplicate, void *userdata)
+{
+ ExpandFloodFillData *data = userdata;
+ if (!is_duplicate) {
+ float current_normal[3], prev_normal[3];
+ SCULPT_vertex_normal_get(ss, to_v, current_normal);
+ SCULPT_vertex_normal_get(ss, from_v, prev_normal);
+ const float from_edge_factor = data->edge_factor[from_v];
+ data->edge_factor[to_v] = dot_v3v3(current_normal, prev_normal) * from_edge_factor;
+ data->dists[to_v] = dot_v3v3(data->original_normal, current_normal) *
+ powf(from_edge_factor, data->edge_sensitivity);
+ CLAMP(data->dists[to_v], 0.0f, 1.0f);
+ }
+ else {
+ /* PBVH_GRIDS duplicate handling. */
+ data->edge_factor[to_v] = data->edge_factor[from_v];
+ data->dists[to_v] = data->dists[from_v];
+ }
+
+ return true;
+}
+
+static float *sculpt_expand_normal_falloff_create(Sculpt *sd,
+ Object *ob,
+ const int vertex,
+ const float edge_sensitivity)
+{
+ SculptSession *ss = ob->sculpt;
+ const int totvert = SCULPT_vertex_count_get(ss);
+ float *dists = MEM_malloc_arrayN(sizeof(float), totvert, "normal dist");
+ float *edge_factor = MEM_callocN(sizeof(float) * totvert, "mask edge factor");
+ for (int i = 0; i < totvert; i++) {
+ edge_factor[i] = 1.0f;
+ }
+
+ SculptFloodFill flood;
+ SCULPT_floodfill_init(ss, &flood);
+ SCULPT_floodfill_add_initial_with_symmetry(sd, ob, ss, &flood, vertex, FLT_MAX);
+
+ ExpandFloodFillData fdata;
+ fdata.dists = dists;
+ fdata.edge_factor = edge_factor;
+ fdata.edge_sensitivity = edge_sensitivity;
+ SCULPT_vertex_normal_get
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list