[Bf-blender-cvs] [e3203434c37] temp-T96710-pbvh-pixels: Build pixels when using sculpt paint brush.
Jeroen Bakker
noreply at git.blender.org
Fri Apr 1 12:31:26 CEST 2022
Commit: e3203434c37f324fdc165871e0a094d63b927e89
Author: Jeroen Bakker
Date: Fri Apr 1 09:42:49 2022 +0200
Branches: temp-T96710-pbvh-pixels
https://developer.blender.org/rBe3203434c37f324fdc165871e0a094d63b927e89
Build pixels when using sculpt paint brush.
===================================================================
M source/blender/blenkernel/intern/pbvh_pixels.cc
M source/blender/editors/sculpt_paint/sculpt.c
===================================================================
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc
index 7148df6d1bc..2323ac271b8 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -78,6 +78,8 @@ static void extract_barycentric_pixels(TileData &tile_data,
}
package.num_pixels = x - package.start_image_coordinate.x;
if (package.num_pixels > best_num_pixels) {
+ // TODO(jbakker): this could be done even when barycentric coordinates are outside the
+ // triangle, no need to find best location to perform the calculation.
triangle.add_barycentric_coord_x = (barycentric - package.start_barycentric_coord.decode()) /
package.num_pixels;
best_num_pixels = package.num_pixels;
@@ -198,6 +200,9 @@ static void init(PBVH *pbvh,
Vector<PBVHNode *> nodes_to_initialize;
for (int n = 0; n < pbvh->totnode; n++) {
PBVHNode *node = &pbvh->nodes[n];
+ if ((node->flag & PBVH_Leaf) == 0) {
+ continue;
+ }
NodeData *node_data = static_cast<NodeData *>(node->pixels.node_data);
if (node_data != nullptr) {
continue;
@@ -233,12 +238,17 @@ static void init(PBVH *pbvh,
BKE_pbvh_parallel_range_settings(&settings, true, nodes_to_initialize.size());
BLI_task_parallel_range(0, nodes_to_initialize.size(), &user_data, do_encode_pixels, &settings);
+//#define DO_PRINT_STATISTICS
+#ifdef DO_PRINT_STATISTICS
/* Print some statistics about compression ratio. */
{
int64_t compressed_data_len = 0;
int64_t num_pixels = 0;
for (int n = 0; n < pbvh->totnode; n++) {
PBVHNode *node = &pbvh->nodes[n];
+ if ((node->flag & PBVH_Leaf) == 0) {
+ continue;
+ }
NodeData *node_data = static_cast<NodeData *>(node->pixels.node_data);
compressed_data_len += node_data->triangles.mem_size();
for (const TileData &tile_data : node_data->tiles) {
@@ -253,6 +263,7 @@ static void init(PBVH *pbvh,
compressed_data_len,
float(compressed_data_len) / num_pixels);
}
+#endif
//#define DO_WATERTIGHT_CHECK
#ifdef DO_WATERTIGHT_CHECK
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index be105a23a84..3a97e7fcc05 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -25,6 +25,7 @@
#include "DNA_brush_types.h"
#include "DNA_customdata_types.h"
+#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_node_types.h"
@@ -40,6 +41,7 @@
#include "BKE_key.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
+#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_mesh_mirror.h"
@@ -57,6 +59,7 @@
#include "BKE_subdiv_ccg.h"
#include "BKE_subsurf.h"
+#include "NOD_shader.h"
#include "NOD_texture.h"
#include "DEG_depsgraph.h"
@@ -2738,6 +2741,63 @@ static void update_brush_local_mat(Sculpt *sd, Object *ob)
/** \} */
+/* -------------------------------------------------------------------- */
+/** \name Texture painting
+ * \{ */
+
+static bool sculpt_needs_pbvh_pixels(const Brush *brush /*, const PaintModeSettings *settings*/)
+{
+ if (brush->sculpt_tool == SCULPT_TOOL_PAINT /*&& U.experimental.use_sculpt_texture_paint*/) {
+ return true;
+ }
+
+ return false;
+}
+
+static void sculpt_pbvh_update_pixels(SculptSession *ss, Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+ Mesh *mesh = (Mesh *)ob->data;
+ /* TODO: should be determined from PaintModeSettings */
+ Material *mat = BKE_object_material_get(ob, ob->actcol);
+ if (mat == NULL) {
+ return;
+ }
+ if (mat->use_nodes == false) {
+ return;
+ }
+ bNode *node = nodeGetActiveTexture(mat->nodetree);
+ if (node == NULL) {
+ return;
+ }
+ if (node->type != SH_NODE_TEX_IMAGE) {
+ return;
+ }
+
+ Image *image = (Image *)node->id;
+ if (image == NULL) {
+ return;
+ }
+ NodeTexImage *storage = node->storage;
+ ImageUser *image_user = &storage->iuser;
+
+ BKE_pbvh_build_pixels(ss->pbvh,
+ ss->pmap,
+ mesh->mpoly,
+ mesh->mloop,
+ mesh->mvert,
+ mesh->totvert,
+ &mesh->vdata,
+ &mesh->ldata,
+ &mesh->pdata,
+ NULL, /* looptri */
+ mesh->totpoly,
+ image,
+ image_user);
+}
+
+/** \} */
+
/* -------------------------------------------------------------------- */
/** \name Generic Brush Plane & Symmetry Utilities
* \{ */
@@ -3196,6 +3256,10 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
nodes = sculpt_pbvh_gather_generic(ob, sd, brush, use_original, radius_scale, &totnode);
}
+ if (sculpt_needs_pbvh_pixels(brush)) {
+ sculpt_pbvh_update_pixels(ss, ob);
+ }
+
/* Draw Face Sets in draw mode makes a single undo push, in alt-smooth mode deforms the
* vertices and uses regular coords undo. */
/* It also assigns the paint_face_set here as it needs to be done regardless of the stroke type
@@ -4593,7 +4657,8 @@ static bool sculpt_needs_connectivity_info(const Sculpt *sd,
(brush->sculpt_tool == SCULPT_TOOL_SLIDE_RELAX) ||
(brush->sculpt_tool == SCULPT_TOOL_CLOTH) || (brush->sculpt_tool == SCULPT_TOOL_SMEAR) ||
(brush->sculpt_tool == SCULPT_TOOL_DRAW_FACE_SETS) ||
- (brush->sculpt_tool == SCULPT_TOOL_DISPLACEMENT_SMEAR));
+ (brush->sculpt_tool == SCULPT_TOOL_DISPLACEMENT_SMEAR) ||
+ (brush->sculpt_tool == SCULPT_TOOL_PAINT));
}
void SCULPT_stroke_modifiers_check(const bContext *C, Object *ob, const Brush *brush)
More information about the Bf-blender-cvs
mailing list