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
This commit is contained in:
parent
f6baba695c
commit
933d56d9e9
Notes:
blender-bot
2024-03-22 15:57:27 +01:00
Referenced by commit 6f38ce5a40
, Fix T103679: Add missing operators in object context menu for point cloud and curves
|
@ -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();
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue