Curves: Add cursor snapping support #104967
|
@ -3,7 +3,36 @@
|
|||
#include "BKE_curves.hh"
|
||||
#include "BKE_geometry_fields.hh"
|
||||
|
||||
#include "BLI_task.hh"
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "ED_curves.h"
|
||||
#include "ED_transverts.h"
|
||||
|
||||
namespace blender::ed::curves {
|
||||
|
||||
void transverts_from_curves_positions_create(bke::CurvesGeometry &curves, TransVertStore *tvs)
|
||||
{
|
||||
Vector<int64_t> selected_indices;
|
||||
IndexMask selection = retrieve_selected_points(curves, selected_indices);
|
||||
MutableSpan<float3> positions = curves.positions_for_write();
|
||||
|
||||
tvs->transverts = static_cast<TransVert *>(
|
||||
MEM_calloc_arrayN(selection.size(), sizeof(TransVert), __func__));
|
||||
tvs->transverts_tot = selection.size();
|
||||
|
||||
threading::parallel_for(selection.index_range(), 1024, [&](const IndexRange selection_range) {
|
||||
for (const int point_i : selection_range) {
|
||||
|
||||
TransVert &tv = tvs->transverts[point_i];
|
||||
Hans Goudey
commented
Might be better to use Might be better to use `SELECT` for now, since that's how the other object types do it
|
||||
tv.loc = positions[selection[point_i]];
|
||||
tv.flag = SELECT;
|
||||
copy_v3_v3(tv.oldloc, tv.loc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace blender::ed::curves
|
||||
|
||||
float (*ED_curves_point_normals_array_create(const Curves *curves_id))[3]
|
||||
{
|
||||
|
@ -21,3 +50,10 @@ float (*ED_curves_point_normals_array_create(const Curves *curves_id))[3]
|
|||
|
||||
return reinterpret_cast<float(*)[3]>(data);
|
||||
}
|
||||
|
||||
void ED_curves_transverts_create(Curves *curves_id, TransVertStore *tvs)
|
||||
{
|
||||
using namespace blender;
|
||||
bke::CurvesGeometry &curves = curves_id->geometry.wrap();
|
||||
ed::curves::transverts_from_curves_positions_create(curves, tvs);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ struct UndoType;
|
|||
struct SelectPick_Params;
|
||||
struct ViewContext;
|
||||
struct rcti;
|
||||
struct TransVertStore;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -32,6 +33,11 @@ void ED_keymap_curves(struct wmKeyConfig *keyconf);
|
|||
*/
|
||||
float (*ED_curves_point_normals_array_create(const struct Curves *curves_id))[3];
|
||||
|
||||
/**
|
||||
* Wrapper for `transverts_from_curves_positions_create`.
|
||||
*/
|
||||
void ED_curves_transverts_create(struct Curves *curves_id, struct TransVertStore *tvs);
|
||||
|
||||
/** \} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -56,6 +62,13 @@ bke::CurvesGeometry primitive_random_sphere(int curves_size, int points_per_curv
|
|||
VectorSet<Curves *> get_unique_editable_curves(const bContext &C);
|
||||
void ensure_surface_deformation_node_exists(bContext &C, Object &curves_ob);
|
||||
|
||||
/**
|
||||
* Allocate an array of `TransVert` for cursor/selection snapping (See
|
||||
* `ED_transverts_create_from_obedit` in `view3d_snap.c`).
|
||||
* \note: the `TransVert` elements in \a tvs are expected to write to the positions of \a curves.
|
||||
Hans Goudey
commented
`* Note:` -> `* \note:`
|
||||
*/
|
||||
void transverts_from_curves_positions_create(bke::CurvesGeometry &curves, TransVertStore *tvs);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Poll Functions
|
||||
* \{ */
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "DNA_armature_types.h"
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_curves_types.h"
|
||||
#include "DNA_lattice_types.h"
|
||||
#include "DNA_meta_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
@ -30,6 +31,7 @@
|
|||
#include "DEG_depsgraph.h"
|
||||
|
||||
#include "ED_armature.h"
|
||||
#include "ED_curves.h"
|
||||
|
||||
#include "ED_transverts.h" /* own include */
|
||||
|
||||
|
@ -181,8 +183,14 @@ static void set_mapped_co(void *vuserdata, int index, const float co[3], const f
|
|||
|
||||
bool ED_transverts_check_obedit(const Object *obedit)
|
||||
{
|
||||
return (
|
||||
ELEM(obedit->type, OB_ARMATURE, OB_LATTICE, OB_MESH, OB_SURF, OB_CURVES_LEGACY, OB_MBALL));
|
||||
return (ELEM(obedit->type,
|
||||
OB_ARMATURE,
|
||||
OB_LATTICE,
|
||||
OB_MESH,
|
||||
OB_SURF,
|
||||
OB_CURVES_LEGACY,
|
||||
OB_MBALL,
|
||||
OB_CURVES));
|
||||
}
|
||||
|
||||
void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit, const int mode)
|
||||
|
@ -481,6 +489,10 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit,
|
|||
bp++;
|
||||
}
|
||||
}
|
||||
else if (obedit->type == OB_CURVES) {
|
||||
Curves *curves_id = obedit->data;
|
||||
ED_curves_transverts_create(curves_id, tvs);
|
||||
}
|
||||
|
||||
if (!tvs->transverts_tot && tvs->transverts) {
|
||||
/* Prevent memory leak. happens for curves/lattices due to
|
||||
|
|
Loading…
Reference in New Issue
Just
tv.loc = positions[selection[point_i]];
worked okay for me.