[Bf-blender-cvs] [489f334dd6e] temp-3d-texture-brush-prototype: Use sculptsession and reuse its PBVH.
Jeroen Bakker
noreply at git.blender.org
Tue Feb 22 16:04:38 CET 2022
Commit: 489f334dd6edacc9c915e0c9be4f73bb69ba22cf
Author: Jeroen Bakker
Date: Tue Feb 22 15:52:44 2022 +0100
Branches: temp-3d-texture-brush-prototype
https://developer.blender.org/rB489f334dd6edacc9c915e0c9be4f73bb69ba22cf
Use sculptsession and reuse its PBVH.
===================================================================
M source/blender/editors/sculpt_paint/paint_image_3d.cc
M source/blender/editors/util/ed_util.c
M source/blender/makesdna/DNA_object_enums.h
===================================================================
diff --git a/source/blender/editors/sculpt_paint/paint_image_3d.cc b/source/blender/editors/sculpt_paint/paint_image_3d.cc
index 1f2f63a70dd..769824bdac8 100644
--- a/source/blender/editors/sculpt_paint/paint_image_3d.cc
+++ b/source/blender/editors/sculpt_paint/paint_image_3d.cc
@@ -32,47 +32,6 @@ static CLG_LogRef LOG = {"ed.sculpt_paint.image3d"};
namespace blender::ed::sculpt_paint::image3d {
-static PBVH *build_pbvh_from_regular_mesh(Object *ob, Mesh *me_eval_deform, bool respect_hide)
-{
- Mesh *me = BKE_object_get_original_mesh(ob);
- const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop);
- PBVH *pbvh = BKE_pbvh_new();
- BKE_pbvh_respect_hide_set(pbvh, respect_hide);
-
- MLoopTri *looptri = static_cast<MLoopTri *>(
- MEM_malloc_arrayN(looptris_num, sizeof(MLoopTri), __func__));
-
- BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri);
-
- BKE_sculpt_sync_face_set_visibility(me, NULL);
-
- BKE_pbvh_build_mesh(pbvh,
- me,
- me->mpoly,
- me->mloop,
- me->mvert,
- me->totvert,
- &me->vdata,
- &me->ldata,
- &me->pdata,
- looptri,
- looptris_num);
-
- return pbvh;
-}
-
-static PBVH *pbvh_from_evaluated_object(Depsgraph *depsgraph, Object *ob)
-{
- const bool respect_hide = true;
- PBVH *pbvh = nullptr;
- Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
- // Mesh *mesh_eval = static_cast<Mesh *>(object_eval->data);
- BLI_assert_msg(ob->type == OB_MESH, "Only mesh objects are supported");
- Mesh *me_eval_deform = object_eval->runtime.mesh_deform_eval;
- pbvh = build_pbvh_from_regular_mesh(ob, me_eval_deform, respect_hide);
- return pbvh;
-}
-
struct StrokeHandle {
PBVH *pbvh = nullptr;
bool owns_pbvh = false;
@@ -98,11 +57,15 @@ struct StrokeHandle *stroke_new(bContext *C, Object *ob)
Image *image = ts->imapaint.canvas;
CLOG_INFO(&LOG, 2, " paint target image: %s", image->id.name);
- StrokeHandle *stroke_handle = MEM_new<StrokeHandle>("StrokeHandle");
+ if (ob->sculpt == nullptr) {
+ BKE_object_sculpt_data_create(ob);
+ }
+ PBVH *pbvh = BKE_sculpt_object_pbvh_ensure(depsgraph, ob);
+ BLI_assert_msg(pbvh != nullptr, "Unable to retrieve PBVH from sculptsession");
- PBVH *pbvh = pbvh_from_evaluated_object(depsgraph, ob);
+ StrokeHandle *stroke_handle = MEM_new<StrokeHandle>("StrokeHandle");
stroke_handle->pbvh = pbvh;
- stroke_handle->owns_pbvh = true;
+ stroke_handle->owns_pbvh = false;
return stroke_handle;
}
@@ -110,8 +73,6 @@ struct StrokeHandle *stroke_new(bContext *C, Object *ob)
void stroke_update(struct StrokeHandle *stroke_handle, float2 prev_mouse, float2 mouse)
{
CLOG_INFO(&LOG, 2, "new stroke step");
-
-
}
void stroke_free(struct StrokeHandle *stroke_handle)
diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c
index 15fe944be49..495dce3eb4b 100644
--- a/source/blender/editors/util/ed_util.c
+++ b/source/blender/editors/util/ed_util.c
@@ -154,6 +154,9 @@ void ED_editors_init(bContext *C)
else if (mode == OB_MODE_WEIGHT_PAINT) {
ED_object_wpaintmode_enter_ex(bmain, depsgraph, scene, ob);
}
+ else if (mode == OB_MODE_TEXTURE_PAINT) {
+ ED_object_texture_paint_mode_enter_ex(bmain, scene, ob);
+ }
else {
BLI_assert_unreachable();
}
diff --git a/source/blender/makesdna/DNA_object_enums.h b/source/blender/makesdna/DNA_object_enums.h
index 3a3e4a01d7c..50e8cca4108 100644
--- a/source/blender/makesdna/DNA_object_enums.h
+++ b/source/blender/makesdna/DNA_object_enums.h
@@ -49,7 +49,8 @@ typedef enum eDrawType {
OB_MODE_VERTEX_GPENCIL)
/** Any mode that uses Object.sculpt. */
-#define OB_MODE_ALL_SCULPT (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)
+#define OB_MODE_ALL_SCULPT \
+ (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)
/** Any mode that uses weightpaint. */
#define OB_MODE_ALL_WEIGHT_PAINT (OB_MODE_WEIGHT_PAINT | OB_MODE_WEIGHT_GPENCIL)
More information about the Bf-blender-cvs
mailing list