diff options
author | Hans Goudey <h.goudey@me.com> | 2022-04-03 20:54:42 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-04-03 20:54:42 +0300 |
commit | 933d56d9e98d3bedd828abc6cea7d7e37fb7206b (patch) | |
tree | 596b40be314d8c22bbefeac6eb530976447c3e2c /source/blender | |
parent | f6baba695cc0a7fb0efcd2586457466774e8f843 (diff) |
Curves: Support set origin and apply transform operators
Add support for the Curves object to the "Set Origin" and "Apply Object
Tansform" operators. Also change the automatic handle calculation to
avoid adding Bezier attributes if they don't need to be added.
Differential Revision: https://developer.blender.org/D14526
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/curves_geometry.cc | 4 | ||||
-rw-r--r-- | source/blender/editors/object/object_transform.cc | 49 |
2 files changed, 51 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index b0a97bb0df8..552d7622932 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -772,6 +772,10 @@ void CurvesGeometry::calculate_bezier_auto_handles() if (types.is_single() && types.get_internal_single() != CURVE_TYPE_BEZIER) { return; } + if (std::as_const(*this).handle_positions_left().is_empty() || + std::as_const(*this).handle_positions_right().is_empty()) { + return; + } const VArray<bool> cyclic = std::as_const(*this).cyclic(); const Span<int8_t> types_left = this->handle_types_left(); const Span<int8_t> types_right = this->handle_types_right(); diff --git a/source/blender/editors/object/object_transform.cc b/source/blender/editors/object/object_transform.cc index 235ffb61738..4c61e95c9e9 100644 --- a/source/blender/editors/object/object_transform.cc +++ b/source/blender/editors/object/object_transform.cc @@ -7,6 +7,7 @@ #include <cstdlib> #include <cstring> +#include <numeric> #include "DNA_anim_types.h" #include "DNA_armature_types.h" @@ -29,6 +30,7 @@ #include "BKE_armature.h" #include "BKE_context.h" #include "BKE_curve.h" +#include "BKE_curves.hh" #include "BKE_editmesh.h" #include "BKE_gpencil.h" #include "BKE_gpencil_geom.h" @@ -68,6 +70,7 @@ using blender::Array; using blender::float2; +using blender::float3; using blender::Vector; /* -------------------------------------------------------------------- */ @@ -691,7 +694,8 @@ static int apply_objects_internal(bContext *C, OB_CURVES_LEGACY, OB_SURF, OB_FONT, - OB_GPENCIL)) { + OB_GPENCIL, + OB_CURVES)) { ID *obdata = static_cast<ID *>(ob->data); if (!do_multi_user && ID_REAL_USERS(obdata) > 1) { BKE_reportf(reports, @@ -923,6 +927,11 @@ static int apply_objects_internal(bContext *C, bGPdata *gpd = static_cast<bGPdata *>(ob->data); BKE_gpencil_transform(gpd, mat); } + else if (ob->type == OB_CURVES) { + Curves &curves = *static_cast<Curves *>(ob->data); + blender::bke::CurvesGeometry::wrap(curves.geometry).transform(mat); + blender::bke::CurvesGeometry::wrap(curves.geometry).calculate_bezier_auto_handles(); + } else if (ob->type == OB_CAMERA) { MovieClip *clip = BKE_object_movieclip_get(scene, ob, false); @@ -1185,7 +1194,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) Object *obact = CTX_data_active_object(C); Object *obedit = CTX_data_edit_object(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - float cent[3], cent_neg[3], centn[3]; + float3 cent, cent_neg, centn; const float *cursor = scene->cursor.location; int centermode = RNA_enum_get(op->ptr, "type"); @@ -1574,6 +1583,42 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) } } } + else if (ob->type == OB_CURVES) { + using namespace blender; + Curves &curves_id = *static_cast<Curves *>(ob->data); + bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry); + if (ELEM(centermode, ORIGIN_TO_CENTER_OF_MASS_SURFACE, ORIGIN_TO_CENTER_OF_MASS_VOLUME) || + !ELEM(around, V3D_AROUND_CENTER_BOUNDS, V3D_AROUND_CENTER_MEDIAN)) { + BKE_report( + op->reports, RPT_WARNING, "Curves Object does not support this set origin operation"); + continue; + } + + if (curves.points_num() == 0) { + continue; + } + + if (centermode == ORIGIN_TO_CURSOR) { + /* done */ + } + else if (around == V3D_AROUND_CENTER_BOUNDS) { + float3 min; + float3 max; + if (curves.bounds_min_max(min, max)) { + cent = math::midpoint(min, max); + } + } + else if (around == V3D_AROUND_CENTER_MEDIAN) { + Span<float3> positions = curves.positions(); + cent = std::accumulate(positions.begin(), positions.end(), float3(0)) / + curves.points_num(); + } + + tot_change++; + curves.translate(-cent); + curves_id.id.tag |= LIB_TAG_DOIT; + do_inverse_offset = true; + } /* offset other selected objects */ if (do_inverse_offset && (centermode != GEOMETRY_TO_ORIGIN)) { |