GPv3: Add "Select Box" operator
This implements the `VIEW3D_OT_select_box` for the new grease pencil data-block. Note that this also adds a `get_evaluated_grease_pencil_drawing_deformation` function, but there are TODOs left. This will have to be updated once the modifier logic is in place. Pull Request: https://projects.blender.org/blender/blender/pulls/108661
This commit is contained in:
parent
42fe8de6f9
commit
7f4f771442
@ -3111,7 +3111,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
|
||||
*_tools_annotate,
|
||||
],
|
||||
'EDIT_GPENCIL': [
|
||||
*_tools_gpencil_select,
|
||||
*_tools_select,
|
||||
_defs_view3d_generic.cursor,
|
||||
None,
|
||||
*_tools_transform,
|
||||
|
@ -51,5 +51,8 @@ struct GeometryDeformation {
|
||||
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig);
|
||||
GeometryDeformation get_evaluated_curves_deformation(const Depsgraph &depsgraph,
|
||||
const Object &ob_orig);
|
||||
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval,
|
||||
const Object &ob_orig,
|
||||
int drawing_index);
|
||||
|
||||
} // namespace blender::bke::crazyspace
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "BKE_curves.hh"
|
||||
#include "BKE_editmesh.h"
|
||||
#include "BKE_geometry_set.hh"
|
||||
#include "BKE_grease_pencil.hh"
|
||||
#include "BKE_lib_id.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_mesh_wrapper.h"
|
||||
@ -662,4 +663,37 @@ GeometryDeformation get_evaluated_curves_deformation(const Depsgraph &depsgraph,
|
||||
return get_evaluated_curves_deformation(ob_eval, ob_orig);
|
||||
}
|
||||
|
||||
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval,
|
||||
const Object &ob_orig,
|
||||
const int drawing_index)
|
||||
{
|
||||
BLI_assert(ob_orig.type == OB_GREASE_PENCIL);
|
||||
const GreasePencil &grease_pencil_orig = *static_cast<const GreasePencil *>(ob_orig.data);
|
||||
|
||||
GreasePencilDrawingBase *drawing_base = grease_pencil_orig.drawings()[drawing_index];
|
||||
|
||||
GeometryDeformation deformation;
|
||||
if (drawing_base->type == GP_DRAWING) {
|
||||
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_base);
|
||||
/* Use the undeformed positions by default. */
|
||||
deformation.positions = drawing->geometry.wrap().positions();
|
||||
}
|
||||
else if (drawing_base->type == GP_DRAWING_REFERENCE) {
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
if (ob_eval == nullptr) {
|
||||
return deformation;
|
||||
}
|
||||
const GeometrySet *geometry_eval = ob_eval->runtime.geometry_set_eval;
|
||||
if (geometry_eval == nullptr) {
|
||||
return deformation;
|
||||
}
|
||||
|
||||
/* TODO: Read `GeometryComponentEditData` from `geometry_eval` and populate deformation with it.
|
||||
*/
|
||||
|
||||
return deformation;
|
||||
}
|
||||
|
||||
} // namespace blender::bke::crazyspace
|
||||
|
@ -1061,7 +1061,7 @@ enum ForeachDrawingMode {
|
||||
static void foreach_drawing_ex(GreasePencil &grease_pencil,
|
||||
int frame,
|
||||
ForeachDrawingMode mode,
|
||||
blender::FunctionRef<void(GreasePencilDrawing &)> function)
|
||||
blender::FunctionRef<void(int, GreasePencilDrawing &)> function)
|
||||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
|
||||
@ -1089,7 +1089,7 @@ static void foreach_drawing_ex(GreasePencil &grease_pencil,
|
||||
GreasePencilDrawingBase *drawing_base = drawings[index];
|
||||
if (drawing_base->type == GP_DRAWING) {
|
||||
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_base);
|
||||
function(*drawing);
|
||||
function(index, *drawing);
|
||||
}
|
||||
else if (drawing_base->type == GP_DRAWING_REFERENCE) {
|
||||
/* TODO */
|
||||
@ -1098,13 +1098,13 @@ static void foreach_drawing_ex(GreasePencil &grease_pencil,
|
||||
}
|
||||
|
||||
void GreasePencil::foreach_visible_drawing(
|
||||
int frame, blender::FunctionRef<void(GreasePencilDrawing &)> function)
|
||||
int frame, blender::FunctionRef<void(int, GreasePencilDrawing &)> function)
|
||||
{
|
||||
foreach_drawing_ex(*this, frame, VISIBLE, function);
|
||||
}
|
||||
|
||||
void GreasePencil::foreach_editable_drawing(
|
||||
int frame, blender::FunctionRef<void(GreasePencilDrawing &)> function)
|
||||
int frame, blender::FunctionRef<void(int, GreasePencilDrawing &)> function)
|
||||
{
|
||||
foreach_drawing_ex(*this, frame, EDITABLE, function);
|
||||
}
|
||||
|
@ -204,7 +204,8 @@ static void grease_pencil_geom_batch_ensure(GreasePencil &grease_pencil, int cfr
|
||||
/* Get the visible drawings. */
|
||||
Vector<const GreasePencilDrawing *> drawings;
|
||||
grease_pencil.foreach_visible_drawing(
|
||||
cfra, [&](GreasePencilDrawing &drawing) { drawings.append(&drawing); });
|
||||
cfra,
|
||||
[&](int /*drawing_index*/, GreasePencilDrawing &drawing) { drawings.append(&drawing); });
|
||||
|
||||
/* First, count how many vertices and triangles are needed for the whole object. Also record the
|
||||
* offsets into the curves for the vertices and triangles. */
|
||||
|
@ -48,10 +48,11 @@ static int select_all_exec(bContext *C, wmOperator *op)
|
||||
Object *object = CTX_data_active_object(C);
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
|
||||
|
||||
grease_pencil.foreach_editable_drawing(scene->r.cfra, [action](GreasePencilDrawing &drawing) {
|
||||
// TODO: Support different selection domains.
|
||||
blender::ed::curves::select_all(drawing.geometry.wrap(), ATTR_DOMAIN_POINT, action);
|
||||
});
|
||||
grease_pencil.foreach_editable_drawing(
|
||||
scene->r.cfra, [action](int /*drawing_index*/, GreasePencilDrawing &drawing) {
|
||||
// TODO: Support different selection domains.
|
||||
blender::ed::curves::select_all(drawing.geometry.wrap(), ATTR_DOMAIN_POINT, action);
|
||||
});
|
||||
|
||||
/* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
|
||||
* attribute for now. */
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include "BKE_crazyspace.hh"
|
||||
#include "BKE_curve.h"
|
||||
#include "BKE_editmesh.h"
|
||||
#include "BKE_grease_pencil.hh"
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_mball.h"
|
||||
#include "BKE_mesh.hh"
|
||||
@ -4028,6 +4029,32 @@ static bool do_pose_box_select(bContext *C,
|
||||
return changed_multi;
|
||||
}
|
||||
|
||||
static bool do_grease_pencil_box_select(ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
|
||||
{
|
||||
using namespace blender;
|
||||
Scene *scene = vc->scene;
|
||||
const Object *ob_eval = DEG_get_evaluated_object(vc->depsgraph,
|
||||
const_cast<Object *>(vc->obedit));
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(vc->obedit->data);
|
||||
|
||||
bool changed = false;
|
||||
grease_pencil.foreach_editable_drawing(
|
||||
scene->r.cfra, [&](int drawing_index, GreasePencilDrawing &drawing) {
|
||||
bke::crazyspace::GeometryDeformation deformation =
|
||||
bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
|
||||
ob_eval, *vc->obedit, drawing_index);
|
||||
changed |= ed::curves::select_box(
|
||||
*vc, drawing.geometry.wrap(), deformation.positions, ATTR_DOMAIN_POINT, *rect, sel_op);
|
||||
});
|
||||
|
||||
if (changed) {
|
||||
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(vc->C, NC_GEOM | ND_DATA, &grease_pencil);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int view3d_box_select_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
using namespace blender;
|
||||
@ -4113,6 +4140,10 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OB_GREASE_PENCIL: {
|
||||
changed = do_grease_pencil_box_select(&vc, &rect, sel_op);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BLI_assert_msg(0, "box select on incorrect object type");
|
||||
break;
|
||||
|
@ -453,9 +453,9 @@ typedef struct GreasePencil {
|
||||
void remove_drawing(int index);
|
||||
|
||||
void foreach_visible_drawing(int frame,
|
||||
blender::FunctionRef<void(GreasePencilDrawing &)> function);
|
||||
blender::FunctionRef<void(int, GreasePencilDrawing &)> function);
|
||||
void foreach_editable_drawing(int frame,
|
||||
blender::FunctionRef<void(GreasePencilDrawing &)> function);
|
||||
blender::FunctionRef<void(int, GreasePencilDrawing &)> function);
|
||||
|
||||
bool bounds_min_max(blender::float3 &min, blender::float3 &max) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user