GPv3: Implement view_selected for edit mode

This adds `view_selected` (i.e. `NUMPAD_PERIOD`) when in edit mode of a
grease pencil object.

Pull Request: https://projects.blender.org/blender/blender/pulls/126448
This commit is contained in:
Casey Bianco-Davis
2024-09-19 14:18:03 +02:00
committed by Falk David
parent bdb4233279
commit 2a4b298802
3 changed files with 46 additions and 5 deletions

View File

@@ -171,7 +171,7 @@ Object *ED_view3d_cameracontrol_object_get(View3DCameraControl *vctrl);
* Calculates the bounding box corners (min and max) for \a obedit.
* The returned values are in global space.
*/
bool ED_view3d_minmax_verts(Object *obedit, float min[3], float max[3]);
bool ED_view3d_minmax_verts(const Scene *scene, Object *obedit, float min[3], float max[3]);
void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot);
void VIEW3D_OT_snap_selected_to_cursor(wmOperatorType *ot);

View File

@@ -388,7 +388,7 @@ static int viewselected_exec(bContext *C, wmOperator *op)
FOREACH_OBJECT_IN_MODE_BEGIN (
scene_eval, view_layer_eval, v3d, obedit->type, obedit->mode, ob_eval_iter)
{
ok |= ED_view3d_minmax_verts(ob_eval_iter, min, max);
ok |= ED_view3d_minmax_verts(scene_eval, ob_eval_iter, min, max);
}
FOREACH_OBJECT_IN_MODE_END;
}
@@ -415,7 +415,7 @@ static int viewselected_exec(bContext *C, wmOperator *op)
FOREACH_OBJECT_IN_MODE_BEGIN (
scene_eval, view_layer_eval, v3d, ob_eval->type, ob_eval->mode, ob_eval_iter)
{
ok |= ED_view3d_minmax_verts(ob_eval_iter, min, max);
ok |= ED_view3d_minmax_verts(scene_eval, ob_eval_iter, min, max);
}
FOREACH_OBJECT_IN_MODE_END;
}

View File

@@ -43,6 +43,7 @@
#include "ED_anim_api.hh"
#include "ED_curves.hh"
#include "ED_grease_pencil.hh"
#include "ED_keyframing.hh"
#include "ED_object.hh"
#include "ED_screen.hh"
@@ -1007,7 +1008,7 @@ static std::optional<blender::Bounds<blender::float3>> bounds_min_max_with_trans
return threading::parallel_reduce(
mask.index_range(),
1024,
Bounds<float3>(math::transform_point(transform, positions.first())),
Bounds<float3>(math::transform_point(transform, positions[mask.first()])),
[&](const IndexRange range, Bounds<float3> init) {
mask.slice(range).foreach_index([&](const int i) {
math::min_max(math::transform_point(transform, positions[i]), init.min, init.max);
@@ -1017,7 +1018,7 @@ static std::optional<blender::Bounds<blender::float3>> bounds_min_max_with_trans
[](const Bounds<float3> &a, const Bounds<float3> &b) { return bounds::merge(a, b); });
}
bool ED_view3d_minmax_verts(Object *obedit, float r_min[3], float r_max[3])
bool ED_view3d_minmax_verts(const Scene *scene, Object *obedit, float r_min[3], float r_max[3])
{
using namespace blender;
using namespace blender::ed;
@@ -1062,6 +1063,46 @@ bool ED_view3d_minmax_verts(Object *obedit, float r_min[3], float r_max[3])
}
return false;
}
if (obedit->type == OB_GREASE_PENCIL) {
Object &ob_orig = *DEG_get_original_object(obedit);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob_orig.data);
std::optional<Bounds<float3>> grease_pencil_bounds = std::nullopt;
const Vector<greasepencil::MutableDrawingInfo> drawings =
greasepencil::retrieve_editable_drawings(*scene, grease_pencil);
for (const greasepencil::MutableDrawingInfo info : drawings) {
const bke::CurvesGeometry &curves = info.drawing.strokes();
if (curves.points_num() == 0) {
continue;
}
IndexMaskMemory memory;
const IndexMask points = greasepencil::retrieve_editable_and_selected_points(
ob_orig, info.drawing, info.layer_index, memory);
if (points.is_empty()) {
continue;
}
const bke::crazyspace::GeometryDeformation deformation =
bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
obedit, ob_orig, info.layer_index, info.frame_number);
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const float4x4 layer_to_world = layer.to_world_space(*obedit);
grease_pencil_bounds = bounds::merge(
grease_pencil_bounds,
bounds_min_max_with_transform(layer_to_world, deformation.positions, points));
}
if (grease_pencil_bounds) {
minmax_v3v3_v3(r_min, r_max, grease_pencil_bounds->min);
minmax_v3v3_v3(r_min, r_max, grease_pencil_bounds->max);
return true;
}
return false;
}
if (ED_transverts_check_obedit(obedit)) {
ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS | TM_CALC_MAPLOC);