Page MenuHome

GPencil: Make camera "Frame Selected" logic work with GPencil objects
ClosedPublic

Authored by Julian Eisel (Severin) on Jul 6 2021, 8:05 PM.

Details

Summary

Using the "Camera Fit Frame to Selected" operator didn't work for Grease Pencil
objects. The same issue caused grease pencil preview thumbnails to be useless
(e.g. when using "Mark Asset" on a Grease Pencil object).
Reason was that there was no logic to handle grease pencil data and its strokes
for the object display-point iterators used for the "Frame Selected" logic.

Diff Detail

Repository
rB Blender

Event Timeline

Julian Eisel (Severin) requested review of this revision.Jul 6 2021, 8:05 PM
Julian Eisel (Severin) created this revision.
source/blender/blenkernel/intern/object.c
4192–4193

Instead of this we could also run some simpler logic to iterate over the points, like BKE_gpencil_data_minmax() does. But that's effectively what BKE_gpencil_visible_stroke_iter() does as well, just with additional features that we don't use.

Antonio Vazquez (antoniov) added inline comments.
source/blender/blenkernel/intern/object.c
4192–4193

The problem with BKE_gpencil_data_minmax() is that is running for all datablock and for the preview we just need the active (visible) frames.

The best solution would be to create a BKE_gpencil_strokes_visible_minmax() to consider only the active frames. If you agree, I can do it.

source/blender/blenkernel/intern/object.c
4192–4193

My mistake...looking at BKE_gpencil_data_minmax() does only active frame, so this is what we need.

source/blender/blenkernel/intern/object.c
4192–4193

The problem with BKE_gpencil_data_minmax() is that is running for all datablock and for the preview we just need the active (visible) frames.

Are you sure about that? It uses bGPDlayer.actframe for drawing.

The best solution would be to create a BKE_gpencil_strokes_visible_minmax() to consider only the active frames. If you agree, I can do it.

We can't simply use the normal min-max calculation since that is axis aligned. The camera fitting should be view aligned.

What BKE_camera_view_frame_fit_to_scene() does is iterate over visible points and executes a callback for each, we should just extend this iteration code to support the grease pencil case.
What I meant with my earlier comment was, that we don't have to use the (rather complex) BKE_gpencil_visible_stroke_iter() for this. We could do a simpler iteration like BKE_gpencil_data_minmax() does it. The important point is that we can execute a callback for each visible point.

  • Use new simplified BKE_object_foreach_display_point()

One thing that's odd, for mesh objects we get the evaluated mesh through Object.runtime.data_eval (see BKE_object_get_evaluated_mesh()), so I'd expect that to be the evaluated grease pencil data for grease pencil objects. That's not the case though, it's NULL, so I directly use Object.data. Not sure if that is correct.

The eval data is in the gpd_eval datablock. I will test the patch and test how it's working with modifiers.

Works perfect with modifiers.

This revision is now accepted and ready to land.Jul 7 2021, 8:39 PM

Accepting w/ minor edits.

source/blender/blenkernel/intern/object.c
4146

This isn't a stroke iterator, it iterates over stroke points, suggest GPencilStrokePointIterData.

4149

Include arguments for clarity.