Initial Grease Pencil 3.0 stage #106848

Merged
Falk David merged 224 commits from filedescriptor/blender:grease-pencil-v3 into main 2023-05-30 11:14:22 +02:00
10 changed files with 200 additions and 1 deletions
Showing only changes of commit de2ac3ab17 - Show all commits

View File

@ -10,6 +10,7 @@
#include "BLI_function_ref.hh"
#include "BLI_map.hh"
#include "BLI_math_vector.h"
#include "BLI_math_vector_types.hh"
#include "BLI_shared_cache.hh"
#include "BLI_stack.hh"
#include "BLI_string.h"
@ -439,7 +440,13 @@ class GreasePencilRuntime {
struct Main;
struct Depsgraph;
struct BoundBox;
struct Scene;
struct Object;
void *BKE_grease_pencil_add(Main *bmain, const char *name);
GreasePencil *BKE_grease_pencil_new_nomain();
BoundBox *BKE_grease_pencil_boundbox_get(Object *ob);
void BKE_grease_pencil_eval_geometry(Depsgraph *depsgraph, GreasePencil &grease_pencil);
void BKE_grease_pencil_data_update(struct Depsgraph *depsgraph,
struct Scene *scene,
struct Object *object);

View File

@ -268,6 +268,13 @@ void *BKE_grease_pencil_add(Main *bmain, const char *name)
return grease_pencil;
}
GreasePencil *BKE_grease_pencil_new_nomain()
{
GreasePencil *grease_pencil = static_cast<GreasePencil *>(BKE_id_new_nomain(ID_GP, nullptr));
grease_pencil_init_data(&grease_pencil->id);
return grease_pencil;
}
BoundBox *BKE_grease_pencil_boundbox_get(Object *ob)
{
BLI_assert(ob->type == OB_GREASE_PENCIL);
@ -309,6 +316,27 @@ BoundBox *BKE_grease_pencil_boundbox_get(Object *ob)
return ob->runtime.bb;
}
void BKE_grease_pencil_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Object *object)
{
/* Free any evaluated data and restore original data. */
BKE_object_free_derived_caches(object);
GreasePencil *grease_pencil = static_cast<GreasePencil *>(object->data);
/* Evaluate modifiers. */
/* TODO. */
/* Assign evaluated object. */
/* TODO: Get eval from modifiers geometry set. */
GreasePencil *grease_pencil_eval = nullptr;
if (grease_pencil_eval == nullptr) {
grease_pencil_eval = BKE_grease_pencil_new_nomain();
BKE_object_eval_assign_data(object, &grease_pencil_eval->id, true);
}
else {
BKE_object_eval_assign_data(object, &grease_pencil_eval->id, false);
}
}
static void grease_pencil_drawing_calculate_fill_triangles(GreasePencilDrawing &drawing)
{
using namespace blender;

View File

@ -32,6 +32,7 @@
#include "BKE_gpencil_legacy.h"
#include "BKE_gpencil_modifier_legacy.h"
#include "BKE_grease_pencil.h"
#include "BKE_grease_pencil.hh"
#include "BKE_image.h"
#include "BKE_key.h"
#include "BKE_lattice.h"
@ -198,7 +199,7 @@ void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *o
BKE_volume_data_update(depsgraph, scene, ob);
break;
case OB_GREASE_PENCIL:
/* TODO: data update. */
BKE_grease_pencil_data_update(depsgraph, scene, ob);
break;
}

View File

@ -0,0 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2023 Blender Foundation. */
/** \file
* \ingroup editors
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void ED_operatortypes_grease_pencil_draw(void);
#ifdef __cplusplus
}
#endif

View File

@ -82,6 +82,11 @@ static const char *object_mode_op_string(eObjectMode mode)
if (mode == OB_MODE_EDIT_GPENCIL) {
return "GPENCIL_OT_editmode_toggle";
}
if (U.experimental.use_grease_pencil_version3) {
if (mode == OB_MODE_PAINT_GPENCIL) {
return "GREASE_PENCIL_OT_draw_mode_toggle";
}
}
if (mode == OB_MODE_PAINT_GPENCIL) {
return "GPENCIL_OT_paintmode_toggle";
}

View File

@ -41,6 +41,7 @@ set(SRC
curves_sculpt_slide.cc
curves_sculpt_smooth.cc
curves_sculpt_snake_hook.cc
grease_pencil_draw_ops.cc
paint_canvas.cc
paint_cursor.cc
paint_curve.c

View File

@ -0,0 +1,127 @@
/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2023 Blender Foundation. */
#include "BKE_context.h"
#include "BKE_grease_pencil.hh"
#include "DEG_depsgraph_query.h"
#include "DNA_brush_types.h"
#include "DNA_grease_pencil_types.h"
#include "ED_grease_pencil_draw.h"
#include "ED_object.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
#include "WM_api.h"
#include "WM_message.h"
#include "WM_toolsystem.h"
#include "paint_intern.h"
namespace blender::ed::sculpt_paint {
/* -------------------------------------------------------------------- */
/** \name Toggle Draw Mode
* \{ */
static bool grease_pencil_poll(bContext *C)
{
Object *object = CTX_data_active_object(C);
if (object == nullptr || object->type != OB_GREASE_PENCIL) {
return false;
}
return true;
}
static void grease_pencil_draw_mode_enter(bContext *C)
{
Scene *scene = CTX_data_scene(C);
wmMsgBus *mbus = CTX_wm_message_bus(C);
Object *ob = CTX_data_active_object(C);
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->gp_paint);
GpPaint *grease_pencil_paint = scene->toolsettings->gp_paint;
ob->mode = OB_MODE_PAINT_GPENCIL;
Review

I am not really sure what the goal is here. If the goal is to somehow ensure all cases are handled it is much better to not use default and let compiler tell you where cases are missing at the compile time.

I am not really sure what the goal is here. If the goal is to somehow ensure all cases are handled it is much better to not use `default` and let compiler tell you where cases are missing at the compile time.
/* Setup cursor color. BKE_paint_init() could be used, but creates an additional brush. */
Paint *paint = BKE_paint_get_active_from_paintmode(scene, PAINT_MODE_GPENCIL);
// copy_v3_v3_uchar(paint->paint_cursor_col, PAINT_CURSOR_GREASE_PENCIL);
// paint->paint_cursor_col[3] = 128;
// ED_paint_cursor_start(&grease_pencil_paint->paint, GREASE_PENCIL_mode_poll_view3d);
paint_init_pivot(ob, scene);
/* Necessary to change the object mode on the evaluated object. */
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
WM_event_add_notifier(C, NC_SCENE | ND_MODE, nullptr);
}
static void grease_pencil_draw_mode_exit(bContext *C)
{
Object *ob = CTX_data_active_object(C);
ob->mode = OB_MODE_OBJECT;
}
static int grease_pencil_draw_mode_toggle_exec(bContext *C, wmOperator *op)
{
Object *ob = CTX_data_active_object(C);
wmMsgBus *mbus = CTX_wm_message_bus(C);
const bool is_mode_set = ob->mode == OB_MODE_PAINT_GPENCIL;
if (is_mode_set) {
if (!ED_object_mode_compat_set(C, ob, OB_MODE_PAINT_GPENCIL, op->reports)) {
return OPERATOR_CANCELLED;
}
}
if (is_mode_set) {
grease_pencil_draw_mode_exit(C);
}
else {
grease_pencil_draw_mode_enter(C);
}
WM_toolsystem_update_from_context_view3d(C);
/* Necessary to change the object mode on the evaluated object. */
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
WM_event_add_notifier(C, NC_SCENE | ND_MODE, nullptr);
return OPERATOR_FINISHED;
}
static void GREASE_PENCIL_OT_draw_mode_toggle(wmOperatorType *ot)
{
ot->name = "Grease Pencil Draw Mode Toggle";
ot->idname = "GREASE_PENCIL_OT_draw_mode_toggle";
ot->description = "Enter/Exit draw mode for grease pencil";
ot->exec = grease_pencil_draw_mode_toggle_exec;
ot->poll = grease_pencil_poll;
ot->flag = OPTYPE_UNDO | OPTYPE_REGISTER;
}
/** \} */
} // namespace blender::ed::sculpt_paint
/* -------------------------------------------------------------------- */
/** \name Registration
* \{ */
void ED_operatortypes_grease_pencil_draw()
{
using namespace blender::ed::sculpt_paint;
WM_operatortype_append(GREASE_PENCIL_OT_draw_mode_toggle);
}
filedescriptor marked this conversation as resolved Outdated

Is the explicit cast to void* needed?

Is the explicit cast to `void*` needed?
/** \} */

View File

@ -818,6 +818,12 @@ static void paint_init_pivot_curves(Object *ob, float location[3])
interp_v3_v3v3(location, bbox->vec[0], bbox->vec[6], 0.5f);
}
static void paint_init_pivot_grease_pencil(Object *ob, float location[3])
{
const BoundBox *bbox = BKE_object_boundbox_get(ob);
interp_v3_v3v3(location, bbox->vec[0], bbox->vec[6], 0.5f);
}
void paint_init_pivot(Object *ob, Scene *scene)
{
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
@ -830,6 +836,9 @@ void paint_init_pivot(Object *ob, Scene *scene)
case OB_CURVES:
paint_init_pivot_curves(ob, location);
break;
case OB_GREASE_PENCIL:
paint_init_pivot_grease_pencil(ob, location);
break;
default:
BLI_assert_unreachable();
ups->last_stroke_valid = false;

View File

@ -34,6 +34,7 @@
#include "ED_geometry.h"
#include "ED_gizmo_library.h"
#include "ED_gpencil.h"
#include "ED_grease_pencil_draw.h"
#include "ED_lattice.h"
#include "ED_markers.h"
#include "ED_mask.h"
@ -91,6 +92,7 @@ void ED_spacetypes_init(void)
ED_operatortypes_anim();
ED_operatortypes_animchannels();
ED_operatortypes_asset();
ED_operatortypes_grease_pencil_draw();
ED_operatortypes_gpencil();
ED_operatortypes_object();
ED_operatortypes_lattice();

View File

@ -53,6 +53,7 @@ set(SRC
../include/ED_gizmo_library.h
../include/ED_gizmo_utils.h
../include/ED_gpencil.h
../include/ED_grease_pencil_draw.h
../include/ED_image.h
../include/ED_info.h
../include/ED_keyframes_draw.h