diff options
Diffstat (limited to 'source/blender/editors/object/object_transform.cc')
-rw-r--r-- | source/blender/editors/object/object_transform.cc | 49 |
1 files changed, 47 insertions, 2 deletions
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)) { |