Fix #130688: Grease Pencil: Multiframe Editing not applying falloff curve

Mutliframe editing wasn't using the falloff.

The fix adds a new field `Vector<float> grease_pencil_falloffs` to
`struct CurvesTransformData`. References it's values with `TransData.extra`.

Pull Request: https://projects.blender.org/blender/blender/pulls/131147
This commit is contained in:
Laurynas Duburas
2024-12-09 10:40:08 +01:00
committed by Falk David
parent a8a526d088
commit cfa63bfefa
6 changed files with 33 additions and 15 deletions

View File

@@ -99,6 +99,12 @@ struct CurvesTransformData {
*/
blender::Vector<int> layer_offsets;
/**
* Grease pencil multi-frame editing falloff. One value for each drawing in a
* `TransDataContainer`.
*/
blender::Vector<float> grease_pencil_falloffs;
/**
* Copy of all positions being transformed.
*/
@@ -184,7 +190,8 @@ void curve_populate_trans_data_structs(
const blender::Span<blender::IndexMask> points_to_transform_indices,
const blender::IndexMask &affected_curves,
bool use_connected_only,
const blender::IndexMask &bezier_curves);
const blender::IndexMask &bezier_curves,
void *extra = nullptr);
CurvesTransformData *create_curves_transform_custom_data(TransCustomData &custom_data);

View File

@@ -447,7 +447,8 @@ void curve_populate_trans_data_structs(
const blender::Span<blender::IndexMask> points_to_transform_per_attr,
const blender::IndexMask &affected_curves,
bool use_connected_only,
const blender::IndexMask &bezier_curves)
const blender::IndexMask &bezier_curves,
void *extra)
{
using namespace blender;
const std::array<Span<float3>, 3> src_positions_per_selection_attr = {
@@ -503,6 +504,8 @@ void curve_populate_trans_data_structs(
td.flag = TD_SELECTED;
}
td.extra = extra;
if (value_attribute) {
float *value = &((*value_attribute)[point_in_domain_i]);
td.val = value;

View File

@@ -48,7 +48,7 @@ static void createTransGreasePencilVerts(bContext *C, TransInfo *t)
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(tc.obedit->data);
Vector<ed::greasepencil::MutableDrawingInfo> drawings =
ed::greasepencil::retrieve_editable_drawings(*scene, grease_pencil);
ed::greasepencil::retrieve_editable_drawings_with_falloff(*scene, grease_pencil);
if (blender::animrig::is_autokey_on(scene)) {
for (const int info_i : drawings.index_range()) {
@@ -61,7 +61,7 @@ static void createTransGreasePencilVerts(bContext *C, TransInfo *t)
target_layer, *target_layer.start_frame_at(current_frame), current_frame, false);
}
}
drawings = ed::greasepencil::retrieve_editable_drawings(*scene, grease_pencil);
drawings = ed::greasepencil::retrieve_editable_drawings_with_falloff(*scene, grease_pencil);
}
all_drawings.append(drawings);
@@ -80,6 +80,7 @@ static void createTransGreasePencilVerts(bContext *C, TransInfo *t)
tc.data_len = 0;
const Vector<ed::greasepencil::MutableDrawingInfo> drawings = all_drawings[i];
curves_transform_data->grease_pencil_falloffs.reinitialize(drawings.size());
for (ed::greasepencil::MutableDrawingInfo info : drawings) {
const bke::CurvesGeometry &curves = info.drawing.strokes();
Span<StringRef> selection_attribute_names = ed::curves::get_curves_selection_attribute_names(
@@ -186,7 +187,8 @@ static void createTransGreasePencilVerts(bContext *C, TransInfo *t)
Span<const bke::greasepencil::Layer *> layers = grease_pencil.layers();
const Vector<ed::greasepencil::MutableDrawingInfo> drawings = all_drawings[i];
for (ed::greasepencil::MutableDrawingInfo info : drawings) {
for (const int drawing : drawings.index_range()) {
ed::greasepencil::MutableDrawingInfo info = drawings[drawing];
const bke::greasepencil::Layer &layer = *layers[info.layer_index];
const float4x4 layer_space_to_world_space = layer.to_world_space(*object_eval);
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
@@ -205,6 +207,11 @@ static void createTransGreasePencilVerts(bContext *C, TransInfo *t)
ed::greasepencil::retrieve_editable_strokes(
*object, info.drawing, info.layer_index, memory) :
IndexMask();
CurvesTransformData &curves_transform_data = *static_cast<CurvesTransformData *>(
tc.custom.type.data);
curves_transform_data.grease_pencil_falloffs[drawing] = info.multi_frame_falloff;
float &drawing_falloff = curves_transform_data.grease_pencil_falloffs[drawing];
curve_populate_trans_data_structs(tc,
curves,
layer_space_to_world_space,
@@ -212,7 +219,8 @@ static void createTransGreasePencilVerts(bContext *C, TransInfo *t)
points_to_transform_per_attribute[layer_offset],
affected_strokes,
use_connected_only,
bezier_curves[layer_offset]);
bezier_curves[layer_offset],
&drawing_falloff);
layer_offset++;
}
}

View File

@@ -110,9 +110,9 @@ static void transdata_elem_bend(const TransInfo *t,
if (t->options & CTX_GPENCIL_STROKES) {
/* Grease pencil multi-frame falloff. */
bGPDstroke *gps = (bGPDstroke *)td->extra;
if (gps != nullptr) {
fac_scaled = fac * td->factor * gps->runtime.multi_frame_falloff;
float *gp_falloff = static_cast<float *>(td->extra);
if (gp_falloff != nullptr) {
fac_scaled = fac * td->factor * *gp_falloff;
}
else {
fac_scaled = fac * td->factor;

View File

@@ -70,9 +70,9 @@ static void transdata_elem_shear(const TransInfo *t,
if (t->options & CTX_GPENCIL_STROKES) {
/* Grease pencil multi-frame falloff. */
bGPDstroke *gps = (bGPDstroke *)td->extra;
if (gps != nullptr) {
mul_v3_fl(vec, td->factor * gps->runtime.multi_frame_falloff);
float *gp_falloff = static_cast<float *>(td->extra);
if (gp_falloff != nullptr) {
mul_v3_fl(vec, td->factor * *gp_falloff);
}
else {
mul_v3_fl(vec, td->factor);

View File

@@ -141,9 +141,9 @@ static void transdata_elem_translate(const TransInfo *t,
if (t->options & CTX_GPENCIL_STROKES) {
/* Grease pencil multi-frame falloff. */
bGPDstroke *gps = (bGPDstroke *)td->extra;
if (gps != nullptr) {
mul_v3_fl(tvec, td->factor * gps->runtime.multi_frame_falloff);
float *gp_falloff = static_cast<float *>(td->extra);
if (gp_falloff != nullptr) {
mul_v3_fl(tvec, td->factor * *gp_falloff);
}
else {
mul_v3_fl(tvec, td->factor);