Changeset View
Standalone View
source/blender/editors/transform/transform_convert_curves.cc
- This file was added.
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||||||||||||||||||||||||||||||||||
| /** \file | ||||||||||||||||||||||||||||||||||||
| * \ingroup edtransform | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
| #include "BLI_array.hh" | ||||||||||||||||||||||||||||||||||||
| #include "BLI_index_mask_ops.hh" | ||||||||||||||||||||||||||||||||||||
| #include "BLI_span.hh" | ||||||||||||||||||||||||||||||||||||
| #include "BKE_curves.hh" | ||||||||||||||||||||||||||||||||||||
| #include "ED_curves.h" | ||||||||||||||||||||||||||||||||||||
HooglyBoogly: This one is redundant with `BKE_curves.hh` | ||||||||||||||||||||||||||||||||||||
| #include "MEM_guardedalloc.h" | ||||||||||||||||||||||||||||||||||||
| #include "transform.h" | ||||||||||||||||||||||||||||||||||||
| #include "transform_convert.h" | ||||||||||||||||||||||||||||||||||||
| /* -------------------------------------------------------------------- */ | ||||||||||||||||||||||||||||||||||||
| /** \name Curve/Surfaces Transform Creation | ||||||||||||||||||||||||||||||||||||
| * \{ */ | ||||||||||||||||||||||||||||||||||||
| namespace blender::ed::transform::curves { | ||||||||||||||||||||||||||||||||||||
Not Done Inline Actions
HooglyBoogly: | ||||||||||||||||||||||||||||||||||||
| static void createTransCurvesVerts(bContext * /*C*/, TransInfo *t) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| MutableSpan<TransDataContainer> trans_data_contrainers(t->data_container, t->data_container_len); | ||||||||||||||||||||||||||||||||||||
| Array<Vector<int64_t>> selected_indices_per_object(t->data_container_len); | ||||||||||||||||||||||||||||||||||||
| Array<IndexMask> selection_per_object(t->data_container_len); | ||||||||||||||||||||||||||||||||||||
Not Done Inline ActionsThe indices might be empty if everything is selected, so two separate arrays will be necessary-- one of index masks and one of the vectors HooglyBoogly: The indices might be empty if everything is selected, so two separate arrays will be necessary… | ||||||||||||||||||||||||||||||||||||
| /* Count selected elements per object and create TransData structs. */ | ||||||||||||||||||||||||||||||||||||
| for (const int i : trans_data_contrainers.index_range()) { | ||||||||||||||||||||||||||||||||||||
Not Done Inline ActionsWhat about selection_per_object? The index_mask part is included in the type I think HooglyBoogly: What about `selection_per_object`? The `index_mask` part is included in the type I think | ||||||||||||||||||||||||||||||||||||
| TransDataContainer &tc = trans_data_contrainers[i]; | ||||||||||||||||||||||||||||||||||||
| Curves *curves_id = static_cast<Curves *>(tc.obedit->data); | ||||||||||||||||||||||||||||||||||||
Not Done Inline Actions
HooglyBoogly: | ||||||||||||||||||||||||||||||||||||
| bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); | ||||||||||||||||||||||||||||||||||||
| selection_per_object[i] = ed::curves::retrieve_selected_points(curves, | ||||||||||||||||||||||||||||||||||||
| selected_indices_per_object[i]); | ||||||||||||||||||||||||||||||||||||
| tc.data_len = selection_per_object[i].size(); | ||||||||||||||||||||||||||||||||||||
| if (tc.data_len > 0) { | ||||||||||||||||||||||||||||||||||||
| tc.data = MEM_cnew_array<TransData>(tc.data_len, __func__); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| /* Populate TransData structs. */ | ||||||||||||||||||||||||||||||||||||
Not Done Inline ActionsThis is already a utility-- curves::retrieve_selected_points HooglyBoogly: This is already a utility-- `curves::retrieve_selected_points` | ||||||||||||||||||||||||||||||||||||
Done Inline ActionsI saw that, but I couldn't include things from editor in this file. Maybe there is a way? filedescriptor: I saw that, but I couldn't include things from `editor` in this file. Maybe there is a way? | ||||||||||||||||||||||||||||||||||||
Not Done Inline ActionsHmm, including ED_curves.h worked for me, and should be covered by the ../include item in cmake. Maybe there's something else going on though. HooglyBoogly: Hmm, including `ED_curves.h` worked for me, and should be covered by the ` ../include` item in… | ||||||||||||||||||||||||||||||||||||
Done Inline ActionsChanging the namespace like you did made it work! filedescriptor: Changing the namespace like you did made it work! | ||||||||||||||||||||||||||||||||||||
| for (const int i : trans_data_contrainers.index_range()) { | ||||||||||||||||||||||||||||||||||||
| TransDataContainer &tc = trans_data_contrainers[i]; | ||||||||||||||||||||||||||||||||||||
| if (tc.data_len == 0) { | ||||||||||||||||||||||||||||||||||||
Not Done Inline Actions
HooglyBoogly: | ||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| Curves *curves_id = static_cast<Curves *>(tc.obedit->data); | ||||||||||||||||||||||||||||||||||||
| bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); | ||||||||||||||||||||||||||||||||||||
| IndexMask selected_indices = selection_per_object[i]; | ||||||||||||||||||||||||||||||||||||
| float mtx[3][3], smtx[3][3]; | ||||||||||||||||||||||||||||||||||||
| copy_m3_m4(mtx, tc.obedit->object_to_world); | ||||||||||||||||||||||||||||||||||||
| pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON); | ||||||||||||||||||||||||||||||||||||
| MutableSpan<float3> positions = curves.positions_for_write(); | ||||||||||||||||||||||||||||||||||||
| threading::parallel_for(selected_indices.index_range(), 1024, [&](const IndexRange range) { | ||||||||||||||||||||||||||||||||||||
| for (const int selection_i : range) { | ||||||||||||||||||||||||||||||||||||
| TransData *td = &tc.data[selection_i]; | ||||||||||||||||||||||||||||||||||||
| float *elem = reinterpret_cast<float *>(&positions[selected_indices[selection_i]]); | ||||||||||||||||||||||||||||||||||||
| copy_v3_v3(td->iloc, elem); | ||||||||||||||||||||||||||||||||||||
| copy_v3_v3(td->center, td->iloc); | ||||||||||||||||||||||||||||||||||||
| td->loc = elem; | ||||||||||||||||||||||||||||||||||||
Done Inline ActionsThis is still very ugly, but the transform code needs a raw pointer to work, so not sure what else to do here. filedescriptor: This is still very ugly, but the transform code needs a raw pointer to work, so not sure what… | ||||||||||||||||||||||||||||||||||||
| td->flag = TD_SELECTED; | ||||||||||||||||||||||||||||||||||||
| td->ext = nullptr; | ||||||||||||||||||||||||||||||||||||
| copy_m3_m3(td->smtx, smtx); | ||||||||||||||||||||||||||||||||||||
| copy_m3_m3(td->mtx, mtx); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| static void recalcData_curves(TransInfo *t) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| Span<TransDataContainer> trans_data_contrainers(t->data_container, t->data_container_len); | ||||||||||||||||||||||||||||||||||||
| for (const TransDataContainer &tc : trans_data_contrainers) { | ||||||||||||||||||||||||||||||||||||
Not Done Inline Actions
Might as well parallelize this HooglyBoogly: Might as well parallelize this | ||||||||||||||||||||||||||||||||||||
| Curves *curves_id = static_cast<Curves *>(tc.obedit->data); | ||||||||||||||||||||||||||||||||||||
Not Done Inline Actions
Careful about making copies by mistake, I noticed this earlier with Vector<int64_t> too (not in the patch anymore) HooglyBoogly: Careful about making copies by mistake, I noticed this earlier with `Vector<int64_t>` too (not… | ||||||||||||||||||||||||||||||||||||
| bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry); | ||||||||||||||||||||||||||||||||||||
| curves.calculate_bezier_auto_handles(); | ||||||||||||||||||||||||||||||||||||
| curves.tag_positions_changed(); | ||||||||||||||||||||||||||||||||||||
| DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
Not Done Inline Actions
Might as well put this here now. It won't make Bezier's work fully, but it will help a bit. HooglyBoogly: Might as well put this here now. It won't make Bezier's work fully, but it will help a bit. | ||||||||||||||||||||||||||||||||||||
| } // namespace blender::ed::transform::curves | ||||||||||||||||||||||||||||||||||||
| /** \} */ | ||||||||||||||||||||||||||||||||||||
| TransConvertTypeInfo TransConvertType_Curves = { | ||||||||||||||||||||||||||||||||||||
| /*flags*/ (T_EDIT | T_POINTS), | ||||||||||||||||||||||||||||||||||||
| /*createTransData*/ blender::ed::transform::curves::createTransCurvesVerts, | ||||||||||||||||||||||||||||||||||||
| /*recalcData*/ blender::ed::transform::curves::recalcData_curves, | ||||||||||||||||||||||||||||||||||||
| /*special_aftertrans_update*/ nullptr, | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
Not Done Inline ActionsMissing newline HooglyBoogly: Missing newline | ||||||||||||||||||||||||||||||||||||
This one is redundant with BKE_curves.hh