[Bf-blender-cvs] [66a64bf43bc] greasepencil-object: GPencil: Add option to reproject Mesh Bake
Antonio Vazquez
noreply at git.blender.org
Fri Apr 3 22:18:53 CEST 2020
Commit: 66a64bf43bc16595c2d02a77cadc1cea1e5afeda
Author: Antonio Vazquez
Date: Fri Apr 3 22:18:47 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB66a64bf43bc16595c2d02a77cadc1cea1e5afeda
GPencil: Add option to reproject Mesh Bake
===================================================================
M release/scripts/startup/bl_operators/gpencil_mesh_bake.py
M source/blender/editors/gpencil/gpencil_mesh.c
M source/blender/editors/include/ED_gpencil.h
===================================================================
diff --git a/release/scripts/startup/bl_operators/gpencil_mesh_bake.py b/release/scripts/startup/bl_operators/gpencil_mesh_bake.py
index 8be49af4d47..e1dacd4254a 100644
--- a/release/scripts/startup/bl_operators/gpencil_mesh_bake.py
+++ b/release/scripts/startup/bl_operators/gpencil_mesh_bake.py
@@ -110,6 +110,18 @@ class GPENCIL_OT_mesh_bake(Operator):
min=1, max=300000,
default=1,
)
+ project_type: EnumProperty(
+ name="Reproject Type",
+ description="Type of projection",
+ items=(
+ ("KEEP", "No Reproject", ""),
+ ("FRONT", "Front", "Reproject the strokes using the X-Z plane"),
+ ("SIDE", "Side", "Reproject the strokes using the Y-Z plane"),
+ ("TOP", "Top", "Reproject the strokes using the X-Y plane"),
+ ("VIEW", "View", "Reproject the strokes to current viewpoint"),
+ ("CURSOR", "Cursor", "Reproject the strokes using the orientation of 3D cursor")
+ )
+ )
@classmethod
def poll(self, context):
@@ -129,7 +141,8 @@ class GPENCIL_OT_mesh_bake(Operator):
faces=self.faces,
offset=self.offset,
target=self.target,
- frame_target=self.frame_target
+ frame_target=self.frame_target,
+ project_type=self.project_type
)
return {'FINISHED'}
diff --git a/source/blender/editors/gpencil/gpencil_mesh.c b/source/blender/editors/gpencil/gpencil_mesh.c
index 465737237cd..b45a0cb9852 100644
--- a/source/blender/editors/gpencil/gpencil_mesh.c
+++ b/source/blender/editors/gpencil/gpencil_mesh.c
@@ -51,6 +51,9 @@
#include "RNA_define.h"
#include "ED_gpencil.h"
+#include "ED_transform_snap_object_context.h"
+
+#include "gpencil_intern.h"
/* Check frame_end is always > start frame! */
static void gp_bake_set_frame_end(struct Main *UNUSED(main),
@@ -82,6 +85,7 @@ static int gp_bake_mesh_animation_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Scene *scene = CTX_data_scene(C);
+ ARegion *region = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
Object *ob = CTX_data_active_object(C);
Object *ob_gpencil = NULL;
@@ -116,6 +120,7 @@ static int gp_bake_mesh_animation_exec(bContext *C, wmOperator *op)
const int frame_offset = RNA_int_get(op->ptr, "frame_target") - frame_start;
char target[64];
RNA_string_get(op->ptr, "target", target);
+ const int project_type = RNA_enum_get(op->ptr, "project_type");
/* Create a new grease pencil object in origin. */
if (STREQ(target, "*NEW")) {
@@ -131,6 +136,26 @@ static int gp_bake_mesh_animation_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
+ bGPdata *gpd = (bGPdata *)ob_gpencil->data;
+ GP_SpaceConversion gsc = {NULL};
+ SnapObjectContext *sctx = NULL;
+ if (project_type != GP_REPROJECT_KEEP) {
+ /* Init space conversion stuff. */
+ gp_point_conversion_init(C, &gsc);
+ /* Init snap context for geometry projection. */
+ sctx = ED_transform_snap_object_context_create_view3d(
+ bmain, scene, 0, region, CTX_wm_view3d(C));
+
+ /* Tag all existing strokes to avoid reprojections. */
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+ gps->flag |= GP_STROKE_TAG;
+ }
+ }
+ }
+ }
+
/* Loop all frame range. */
int oldframe = (int)DEG_get_ctime(depsgraph);
int key = -1;
@@ -158,6 +183,22 @@ static int gp_bake_mesh_animation_exec(bContext *C, wmOperator *op)
frame_offset,
use_seams,
use_faces);
+
+ /* Reproject all untaged created strokes. */
+ if (project_type != GP_REPROJECT_KEEP) {
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ bGPDframe *gpf = gpl->actframe;
+ if (gpf != NULL) {
+ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+ if ((gps->flag & GP_STROKE_TAG) == 0) {
+ ED_gpencil_stroke_reproject(
+ depsgraph, &gsc, sctx, gpl, gpf, gps, project_type, false);
+ gps->flag |= GP_STROKE_TAG;
+ }
+ }
+ }
+ }
+ }
}
/* Return scene frame state and DB to original state. */
@@ -178,6 +219,22 @@ static int gp_bake_mesh_animation_exec(bContext *C, wmOperator *op)
}
ob_gpencil->actcol = actcol;
+ /* Untag all strokes. */
+ if (project_type != GP_REPROJECT_KEEP) {
+ LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+ gps->flag &= ~GP_STROKE_TAG;
+ }
+ }
+ }
+ }
+
+ /* Free memory. */
+ if (sctx != NULL) {
+ ED_transform_snap_object_context_destroy(sctx);
+ }
+
/* notifiers */
DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_OBJECT | NA_ADDED, NULL);
@@ -192,6 +249,25 @@ static int gp_bake_mesh_animation_exec(bContext *C, wmOperator *op)
void GPENCIL_OT_bake_mesh_animation(wmOperatorType *ot)
{
+ static const EnumPropertyItem reproject_type[] = {
+ {GP_REPROJECT_KEEP, "KEEP", 0, "No Reproject", ""},
+ {GP_REPROJECT_FRONT, "FRONT", 0, "Front", "Reproject the strokes using the X-Z plane"},
+ {GP_REPROJECT_SIDE, "SIDE", 0, "Side", "Reproject the strokes using the Y-Z plane"},
+ {GP_REPROJECT_TOP, "TOP", 0, "Top", "Reproject the strokes using the X-Y plane"},
+ {GP_REPROJECT_VIEW,
+ "VIEW",
+ 0,
+ "View",
+ "Reproject the strokes to end up on the same plane, as if drawn from the current viewpoint "
+ "using 'Cursor' Stroke Placement"},
+ {GP_REPROJECT_CURSOR,
+ "CURSOR",
+ 0,
+ "Cursor",
+ "Reproject the strokes using the orientation of 3D cursor"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
PropertyRNA *prop;
/* identifiers */
@@ -240,4 +316,6 @@ void GPENCIL_OT_bake_mesh_animation(wmOperatorType *ot)
64,
"",
"Target grease pencil object name. Leave empty for new object");
+
+ RNA_def_enum(ot->srna, "project_type", reproject_type, GP_REPROJECT_VIEW, "Projection Type", "");
}
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index fbee0b7ad6c..635f6a28ee5 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -75,6 +75,8 @@ typedef enum eGP_ReprojectModes {
GP_REPROJECT_SURFACE,
/* Reprojected on 3D cursor orientation */
GP_REPROJECT_CURSOR,
+ /* Keep equals (used in some operators) */
+ GP_REPROJECT_KEEP,
} eGP_ReprojectModes;
/* ------------- Grease-Pencil Runtime Data ---------------- */
More information about the Bf-blender-cvs
mailing list