Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2022-07-22 16:39:41 +0300
committerJacques Lucke <jacques@blender.org>2022-07-22 16:39:41 +0300
commit1f94b56d774440d08eb92f2a7a47b9a6a7aa7b84 (patch)
tree06928c94d524852c7031aa310d578691735dc0a8 /source/blender/blenkernel/intern/crazyspace.cc
parent98bf714b37c1f1b05a162b6ffdaca367b312de1f (diff)
Curves: support sculpting on deformed curves
Previously, curves sculpt tools only worked on original data. This was very limiting, because one could effectively only sculpt the curves when all procedural effects were turned off. This patch adds support for curves sculpting while looking the result of procedural effects (like deformation based on the surface mesh). This functionality is also known as "crazy space" support in Blender. For more details see D15407. Differential Revision: https://developer.blender.org/D15407
Diffstat (limited to 'source/blender/blenkernel/intern/crazyspace.cc')
-rw-r--r--source/blender/blenkernel/intern/crazyspace.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/crazyspace.cc b/source/blender/blenkernel/intern/crazyspace.cc
index c3db3095343..978606ef1fa 100644
--- a/source/blender/blenkernel/intern/crazyspace.cc
+++ b/source/blender/blenkernel/intern/crazyspace.cc
@@ -19,7 +19,10 @@
#include "BKE_DerivedMesh.h"
#include "BKE_crazyspace.h"
+#include "BKE_crazyspace.hh"
+#include "BKE_curves.hh"
#include "BKE_editmesh.h"
+#include "BKE_geometry_set.hh"
#include "BKE_lib_id.h"
#include "BKE_mesh.h"
#include "BKE_mesh_wrapper.h"
@@ -586,3 +589,64 @@ void BKE_crazyspace_api_eval_clear(Object *object)
}
/** \} */
+
+namespace blender::bke::crazyspace {
+
+GeometryDeformation get_evaluated_curves_deformation(const Depsgraph &depsgraph,
+ const Object &ob_orig)
+{
+ BLI_assert(ob_orig.type == OB_CURVES);
+ const Curves &curves_id_orig = *static_cast<const Curves *>(ob_orig.data);
+ const CurvesGeometry &curves_orig = CurvesGeometry::wrap(curves_id_orig.geometry);
+ const int points_num = curves_orig.points_num();
+
+ GeometryDeformation deformation;
+ /* Use the undeformed positions by default. */
+ deformation.positions = curves_orig.positions();
+
+ const Object *ob_eval = DEG_get_evaluated_object(&depsgraph, const_cast<Object *>(&ob_orig));
+ if (ob_eval == nullptr) {
+ return deformation;
+ }
+ const GeometrySet *geometry_eval = ob_eval->runtime.geometry_set_eval;
+ if (geometry_eval == nullptr) {
+ return deformation;
+ }
+
+ /* If available, use deformation information generated during evaluation. */
+ const GeometryComponentEditData *edit_component_eval =
+ geometry_eval->get_component_for_read<GeometryComponentEditData>();
+ bool uses_extra_positions = false;
+ if (edit_component_eval != nullptr) {
+ const CurvesEditHints *edit_hints = edit_component_eval->curves_edit_hints_.get();
+ if (edit_hints != nullptr && &edit_hints->curves_id_orig == &curves_id_orig) {
+ if (edit_hints->positions.has_value()) {
+ BLI_assert(edit_hints->positions->size() == points_num);
+ deformation.positions = *edit_hints->positions;
+ uses_extra_positions = true;
+ }
+ if (edit_hints->deform_mats.has_value()) {
+ BLI_assert(edit_hints->deform_mats->size() == points_num);
+ deformation.deform_mats = *edit_hints->deform_mats;
+ }
+ }
+ }
+
+ /* Use the positions of the evaluated curves directly, if the number of points matches. */
+ if (!uses_extra_positions) {
+ const CurveComponent *curves_component_eval =
+ geometry_eval->get_component_for_read<CurveComponent>();
+ if (curves_component_eval != nullptr) {
+ const Curves *curves_id_eval = curves_component_eval->get_for_read();
+ if (curves_id_eval != nullptr) {
+ const CurvesGeometry &curves_eval = CurvesGeometry::wrap(curves_id_eval->geometry);
+ if (curves_eval.points_num() == points_num) {
+ deformation.positions = curves_eval.positions();
+ }
+ }
+ }
+ }
+ return deformation;
+}
+
+} // namespace blender::bke::crazyspace