Skip to content

Commit 2cc5143

Browse files
PratikBorhade302Pratik Borhade
authored andcommitted
UI: Curves and Grease Pencil dimensions in transform side panel
In edit mode, positions of selected points is not shown in transform side panel. Following existing logic, now introduced `TransformMedian_GreasePencil`, `TransformMedian_Curves` to track the median of selected points of grease pencil and Curves respectively. Resolves #136332 Pull Request: https://projects.blender.org/blender/blender/pulls/136592
1 parent dc38872 commit 2cc5143

File tree

3 files changed

+155
-4
lines changed

3 files changed

+155
-4
lines changed

source/blender/editors/curves/intern/curves_data.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ Vector<MutableSpan<float3>> get_curves_positions_for_write(bke::CurvesGeometry &
2222
return positions_per_attribute;
2323
}
2424

25+
Vector<Span<float3>> get_curves_positions(const bke::CurvesGeometry &curves)
26+
{
27+
Vector<Span<float3>> positions_per_attribute;
28+
positions_per_attribute.append(curves.positions());
29+
if (curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
30+
positions_per_attribute.append(curves.handle_positions_left());
31+
positions_per_attribute.append(curves.handle_positions_right());
32+
}
33+
return positions_per_attribute;
34+
}
35+
2536
void transverts_from_curves_positions_create(bke::CurvesGeometry &curves,
2637
TransVertStore *tvs,
2738
const bool skip_handles)

source/blender/editors/include/ED_curves.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Span<StringRef> get_curves_selection_attribute_names(const bke::CurvesGeometry &
6060
*/
6161
Vector<MutableSpan<float3>> get_curves_positions_for_write(bke::CurvesGeometry &curves);
6262

63+
/**
64+
* Get read-only positions per selection attribute for given curve.
65+
*/
66+
Vector<Span<float3>> get_curves_positions(const bke::CurvesGeometry &curves);
67+
6368
/* Get all possible curve selection attribute names. */
6469
Span<StringRef> get_curves_all_selection_attribute_names();
6570

source/blender/editors/space_view3d/view3d_buttons.cc

Lines changed: 139 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
#include "BLI_math_vector.h"
3131
#include "BLI_string.h"
3232
#include "BLI_utildefines.h"
33+
#include "BLI_vector.hh"
3334

3435
#include "BKE_action.hh"
3536
#include "BKE_armature.hh"
3637
#include "BKE_context.hh"
3738
#include "BKE_curve.hh"
39+
#include "BKE_curves.hh"
3840
#include "BKE_customdata.hh"
3941
#include "BKE_deform.hh"
4042
#include "BKE_editmesh.hh"
@@ -55,6 +57,8 @@
5557
#include "RNA_access.hh"
5658
#include "RNA_prototypes.hh"
5759

60+
#include "ED_curves.hh"
61+
#include "ED_grease_pencil.hh"
5862
#include "ED_mesh.hh"
5963
#include "ED_object.hh"
6064
#include "ED_object_vgroup.hh"
@@ -92,11 +96,21 @@ struct TransformMedian_Lattice {
9296
float location[3], weight;
9397
};
9498

99+
struct TransformMedian_GreasePencil {
100+
float location[3];
101+
};
102+
103+
struct TransformMedian_Curves {
104+
float location[3];
105+
};
106+
95107
union TransformMedian {
96108
TransformMedian_Generic generic;
97109
TransformMedian_Mesh mesh;
98110
TransformMedian_Curve curve;
99111
TransformMedian_Lattice lattice;
112+
TransformMedian_GreasePencil grease_pencil;
113+
TransformMedian_Curves curves;
100114
};
101115

102116
/* temporary struct for storing transform properties */
@@ -293,8 +307,10 @@ static TransformProperties *v3d_transform_props_ensure(View3D *v3d)
293307
}
294308

295309
/* is used for both read and write... */
296-
static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float lim)
310+
static void v3d_editvertex_buts(
311+
const bContext *C, uiLayout *layout, View3D *v3d, Object *ob, float lim)
297312
{
313+
using namespace blender;
298314
uiBlock *block = (layout) ? uiLayoutAbsoluteBlock(layout) : nullptr;
299315
TransformProperties *tfp = v3d_transform_props_ensure(v3d);
300316
TransformMedian median_basis, ve_median_basis;
@@ -468,6 +484,61 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
468484
data_ptr = RNA_pointer_create_discrete(&lt->id, seltype, selp);
469485
}
470486
}
487+
else if (ob->type == OB_GREASE_PENCIL) {
488+
using namespace blender::ed::greasepencil;
489+
using namespace ed::curves;
490+
Scene &scene = *CTX_data_scene(C);
491+
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob->data);
492+
blender::Vector<MutableDrawingInfo> drawings = retrieve_editable_drawings(scene,
493+
grease_pencil);
494+
495+
threading::parallel_for_each(drawings, [&](const MutableDrawingInfo &info) {
496+
const bke::CurvesGeometry &curves = info.drawing.strokes();
497+
if (curves.is_empty()) {
498+
return;
499+
}
500+
501+
const Span<StringRef> selection_names = get_curves_selection_attribute_names(curves);
502+
Vector<Span<float3>> positions = get_curves_positions(curves);
503+
TransformMedian_Curves &median = median_basis.curves;
504+
for (int attribute_i : selection_names.index_range()) {
505+
IndexMaskMemory memory;
506+
const IndexMask selection = retrieve_selected_points(
507+
curves, selection_names[attribute_i], memory);
508+
if (selection.is_empty()) {
509+
continue;
510+
}
511+
512+
tot += selection.size();
513+
selection.foreach_index(
514+
[&](const int point) { add_v3_v3(median.location, positions[attribute_i][point]); });
515+
}
516+
});
517+
}
518+
else if (ob->type == OB_CURVES) {
519+
using namespace ed::curves;
520+
const Curves &curves_id = *static_cast<Curves *>(ob->data);
521+
const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
522+
if (curves.is_empty()) {
523+
return;
524+
}
525+
526+
const Span<StringRef> selection_names = get_curves_selection_attribute_names(curves);
527+
const Vector<Span<float3>> positions = get_curves_positions(curves);
528+
TransformMedian_Curves &median = median_basis.curves;
529+
for (int attribute_i : selection_names.index_range()) {
530+
IndexMaskMemory memory;
531+
const IndexMask selection = retrieve_selected_points(
532+
curves, selection_names[attribute_i], memory);
533+
if (selection.is_empty()) {
534+
continue;
535+
}
536+
537+
tot += selection.size();
538+
selection.foreach_index(
539+
[&](const int point) { add_v3_v3(median.location, positions[attribute_i][point]); });
540+
}
541+
}
471542

472543
if (tot == 0) {
473544
uiDefBut(
@@ -527,6 +598,9 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
527598
/* Curve */
528599
c = IFACE_("Control Point:");
529600
}
601+
else if (ELEM(ob->type, OB_CURVES, OB_GREASE_PENCIL)) {
602+
c = IFACE_("Point:");
603+
}
530604
else {
531605
/* Mesh or lattice */
532606
c = IFACE_("Vertex:");
@@ -1168,9 +1242,70 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
11681242
bp++;
11691243
}
11701244
}
1245+
else if (ob->type == OB_GREASE_PENCIL && apply_vcos) {
1246+
using namespace blender::ed::greasepencil;
1247+
using namespace ed::curves;
1248+
Scene &scene = *CTX_data_scene(C);
1249+
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob->data);
1250+
blender::Vector<MutableDrawingInfo> drawings = retrieve_editable_drawings(scene,
1251+
grease_pencil);
1252+
1253+
threading::parallel_for_each(drawings, [&](const MutableDrawingInfo &info) {
1254+
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
1255+
if (curves.is_empty()) {
1256+
return;
1257+
}
11711258

1172-
// ED_undo_push(C, "Transform properties");
1259+
TransformMedian_GreasePencil &median = median_basis.grease_pencil;
1260+
TransformMedian_GreasePencil &ve_median = ve_median_basis.grease_pencil;
1261+
IndexMaskMemory memory;
1262+
const Span<StringRef> selection_names = get_curves_selection_attribute_names(curves);
1263+
const Vector<MutableSpan<float3>> positions = get_curves_positions_for_write(curves);
1264+
for (int attribute_i : selection_names.index_range()) {
1265+
const IndexMask selection = retrieve_selected_points(
1266+
curves, selection_names[attribute_i], memory);
1267+
if (selection.is_empty()) {
1268+
continue;
1269+
}
1270+
1271+
selection.foreach_index([&](const int point) {
1272+
apply_raw_diff_v3(
1273+
positions[attribute_i][point], tot, ve_median.location, median.location);
1274+
});
1275+
info.drawing.tag_positions_changed();
1276+
}
1277+
});
1278+
}
1279+
else if (ob->type == OB_CURVES && apply_vcos) {
1280+
using namespace ed::curves;
1281+
Curves &curves_id = *static_cast<Curves *>(ob->data);
1282+
bke::CurvesGeometry &curves = curves_id.geometry.wrap();
1283+
if (curves.is_empty()) {
1284+
return;
1285+
}
1286+
1287+
TransformMedian_Curves &median = median_basis.curves;
1288+
TransformMedian_Curves &ve_median = ve_median_basis.curves;
1289+
IndexMaskMemory memory;
1290+
const Span<StringRef> selection_names = get_curves_selection_attribute_names(curves);
1291+
Vector<MutableSpan<float3>> positions = get_curves_positions_for_write(curves);
1292+
for (int attribute_i : selection_names.index_range()) {
1293+
const IndexMask selection = retrieve_selected_points(
1294+
curves, selection_names[attribute_i], memory);
1295+
if (selection.is_empty()) {
1296+
continue;
1297+
}
1298+
1299+
selection.foreach_index([&](const int point) {
1300+
apply_raw_diff_v3(
1301+
positions[attribute_i][point], tot, ve_median.location, median.location);
1302+
});
1303+
}
1304+
curves.tag_positions_changed();
1305+
}
11731306
}
1307+
1308+
// ED_undo_push(C, "Transform properties");
11741309
}
11751310

11761311
#undef TRANSFORM_MEDIAN_ARRAY_LEN
@@ -1691,7 +1826,7 @@ static void do_view3d_region_buttons(bContext *C, void * /*index*/, int event)
16911826

16921827
case B_TRANSFORM_PANEL_MEDIAN:
16931828
if (ob) {
1694-
v3d_editvertex_buts(nullptr, v3d, ob, 1.0);
1829+
v3d_editvertex_buts(C, nullptr, v3d, ob, 1.0);
16951830
DEG_id_tag_update(static_cast<ID *>(ob->data), ID_RECALC_GEOMETRY);
16961831
}
16971832
break;
@@ -1738,7 +1873,7 @@ static void view3d_panel_transform(const bContext *C, Panel *panel)
17381873
}
17391874
else {
17401875
View3D *v3d = CTX_wm_view3d(C);
1741-
v3d_editvertex_buts(col, v3d, ob, FLT_MAX);
1876+
v3d_editvertex_buts(C, col, v3d, ob, FLT_MAX);
17421877
}
17431878
}
17441879
else if (ob->mode & OB_MODE_POSE) {

0 commit comments

Comments
 (0)