[Bf-blender-cvs] [ea7edbd4670] temp-3d-texture-brush-prototype: Initial commit for 3d texture brush.
Jeroen Bakker
noreply at git.blender.org
Tue Feb 22 15:36:54 CET 2022
Commit: ea7edbd46707ebc689a47e34dfc3ea17a78a9c0f
Author: Jeroen Bakker
Date: Tue Feb 22 15:36:21 2022 +0100
Branches: temp-3d-texture-brush-prototype
https://developer.blender.org/rBea7edbd46707ebc689a47e34dfc3ea17a78a9c0f
Initial commit for 3d texture brush.
Still early development, nothing working yet.
===================================================================
M source/blender/editors/sculpt_paint/CMakeLists.txt
A source/blender/editors/sculpt_paint/paint_image_3d.cc
A source/blender/editors/sculpt_paint/paint_image_3d.hh
M source/blender/editors/sculpt_paint/paint_image_ops_paint.cc
===================================================================
diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index de7888aa1e8..5261e902722 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -33,6 +33,7 @@ set(SRC
paint_image_ops_paint.cc
paint_image_2d.c
paint_image_2d_curve_mask.cc
+ paint_image_3d.cc
paint_image_proj.c
paint_mask.c
paint_ops.c
diff --git a/source/blender/editors/sculpt_paint/paint_image_3d.cc b/source/blender/editors/sculpt_paint/paint_image_3d.cc
new file mode 100644
index 00000000000..1f2f63a70dd
--- /dev/null
+++ b/source/blender/editors/sculpt_paint/paint_image_3d.cc
@@ -0,0 +1,123 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup edsculpt
+ * \brief 3D perspective painting.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "BKE_context.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+#include "BKE_paint.h"
+#include "BKE_pbvh.h"
+
+#include "BLI_math.h"
+
+#include "paint_image_3d.hh"
+
+#include "CLG_log.h"
+
+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;
+
+ virtual ~StrokeHandle()
+ {
+ if (pbvh && owns_pbvh) {
+ BKE_pbvh_free(pbvh);
+ }
+ pbvh = nullptr;
+ owns_pbvh = false;
+ }
+};
+
+struct StrokeHandle *stroke_new(bContext *C, Object *ob)
+{
+ CLOG_INFO(&LOG, 2, "create new stroke");
+ const Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
+
+ ToolSettings *ts = scene->toolsettings;
+ BLI_assert_msg(ts->imapaint.mode == IMAGEPAINT_MODE_IMAGE, "Only Image mode implemented");
+ Image *image = ts->imapaint.canvas;
+ CLOG_INFO(&LOG, 2, " paint target image: %s", image->id.name);
+
+ StrokeHandle *stroke_handle = MEM_new<StrokeHandle>("StrokeHandle");
+
+ PBVH *pbvh = pbvh_from_evaluated_object(depsgraph, ob);
+ stroke_handle->pbvh = pbvh;
+ stroke_handle->owns_pbvh = true;
+
+ return stroke_handle;
+}
+
+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)
+{
+ CLOG_INFO(&LOG, 2, "free stroke");
+ MEM_delete(stroke_handle);
+}
+
+} // namespace blender::ed::sculpt_paint::image3d
\ No newline at end of file
diff --git a/source/blender/editors/sculpt_paint/paint_image_3d.hh b/source/blender/editors/sculpt_paint/paint_image_3d.hh
new file mode 100644
index 00000000000..304507285c3
--- /dev/null
+++ b/source/blender/editors/sculpt_paint/paint_image_3d.hh
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup edsculpt
+ */
+
+#pragma once
+
+extern "C" {
+/* Forward declarations. */
+struct bContext;
+struct Object;
+}
+
+#include "BLI_math_vec_types.hh"
+
+namespace blender::ed::sculpt_paint::image3d {
+struct StrokeHandle;
+
+struct StrokeHandle *stroke_new(bContext *C, Object *ob);
+void stroke_update(struct StrokeHandle *stroke_handle, float2 prev_mouse, float2 mouse);
+void stroke_free(struct StrokeHandle *stroke_handle);
+
+} // namespace blender::ed::sculpt_paint::image3d
diff --git a/source/blender/editors/sculpt_paint/paint_image_ops_paint.cc b/source/blender/editors/sculpt_paint/paint_image_ops_paint.cc
index 79701bba01c..c37da72313b 100644
--- a/source/blender/editors/sculpt_paint/paint_image_ops_paint.cc
+++ b/source/blender/editors/sculpt_paint/paint_image_ops_paint.cc
@@ -36,6 +36,8 @@
#include "paint_intern.h"
+#include "paint_image_3d.hh"
+
namespace blender::ed::sculpt_paint::image::ops::paint {
/**
@@ -211,6 +213,57 @@ class ProjectionPaintMode : public AbstractPaintMode {
}
};
+class PerspectivePaintMode : public AbstractPaintMode {
+
+ public:
+ void *paint_new_stroke(
+ bContext *C, wmOperator *UNUSED(op), Object *ob, const float mouse[2], int mode) override
+ {
+ return image3d::stroke_new(C, ob);
+ }
+
+ void paint_stroke(bContext *C,
+ void *stroke_handle,
+ float prev_mouse[2],
+ float mouse[2],
+ int eraser,
+ float pressure,
+ float distance,
+ float size) override
+ {
+ image3d::stroke_update(static_cast<image3d::StrokeHandle *>(stroke_handle), prev_mouse, mouse);
+ };
+
+ void paint_stroke_redraw(const bContext *C, void *stroke_handle, bool final) override
+ {
+ }
+
+ void paint_stroke_done(void *stroke_handle) override
+ {
+ image3d::stroke_free(static_cast<image3d::StrokeHandle *>(stroke_handle));
+ }
+
+ void paint_gradient_fill(const bContext *C,
+ const Scene *scene,
+ Brush *brush,
+ struct PaintStroke *stroke,
+ void *stroke_handle,
+ float mouse_start[2],
+ float mouse_end[2]) override
+ {
+ }
+
+ void paint_bucket_fill(const bContext *C,
+ const Scene *scene,
+ Brush *brush,
+ struct PaintStroke *stroke,
+ void *stroke_handle,
+ float mouse_start[2],
+ float mouse_end[2]) override
+ {
+ }
+};
+
struct PaintOperation {
AbstractPaintMode *mode = nullptr;
@@ -301,7 +354,13 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo
WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, nullptr);
return nullptr;
}
+
+/* Set to 1 to switch back to original implementation. */
+#if 0
pop->mode = MEM_new<ProjectionPaintMode>("ProjectionPaintMode");
+#else
+ pop->mode = MEM_new<PerspectivePaintMode>("PerspectivePaintMode");
+#endif
}
else {
pop->mode = MEM_new<ImagePaintMode>("ImagePaintMode");
More information about the Bf-blender-cvs
mailing list