GP: Move grid parameters to GP object data level

The grid now can be configured by object because this helps to identify objects and allows to define diferent grid parameters for each objects.

Also added a color option.
This commit is contained in:
Antonio Vazquez 2018-10-04 23:27:34 +02:00
parent 65f77ccea1
commit 3a1e9b9997
12 changed files with 110 additions and 106 deletions

View File

@ -347,6 +347,26 @@ class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
layout.prop(gpd, "zdepth_offset", text="Surface Offset")
class DATA_PT_gpencil_canvas(DataButtonsPanel, Panel):
bl_label = "Canvas"
bl_parent_id = 'DATA_PT_gpencil_display'
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
layout.use_property_split = True
gpd = context.gpencil_data
row = layout.row(align=True)
col = row.column()
col.prop(gpd, "grid_color")
col.prop(gpd, "grid_scale")
row = layout.row(align=True)
col = row.column()
col.prop(gpd, "grid_lines", text="Subdivisions")
col.prop(gpd, "grid_axis", text="Plane")
class DATA_PT_custom_props_gpencil(DataButtonsPanel, PropertyPanel, Panel):
_context_path = "object.data"
_property_type = bpy.types.GreasePencil
@ -362,6 +382,7 @@ classes = (
DATA_PT_gpencil_parentpanel,
DATA_PT_gpencil_vertexpanel,
DATA_PT_gpencil_display,
DATA_PT_gpencil_canvas,
DATA_PT_custom_props_gpencil,
GPENCIL_UL_vgroups,

View File

@ -4927,15 +4927,6 @@ class VIEW3D_PT_overlay_gpencil_options(Panel):
sub.active = overlay.use_gpencil_grid
sub.prop(overlay, "gpencil_grid_opacity", text="Canvas Grid", slider=True)
if overlay.use_gpencil_grid:
row = layout.row(align=True)
col = row.column()
col.prop(overlay, "gpencil_grid_scale")
row = layout.row(align=True)
col = row.column()
col.prop(overlay, "gpencil_grid_lines", text="Subdivisions")
col.prop(overlay, "gpencil_grid_axis", text="Plane")
if context.object.mode in {'GPENCIL_EDIT', 'GPENCIL_SCULPT', 'GPENCIL_WEIGHT'}:
layout.prop(overlay, "use_gpencil_edit_lines", text="Edit Lines")
layout.prop(overlay, "use_gpencil_multiedit_line_only", text="Show Edit Lines only in multiframe")

View File

@ -467,6 +467,12 @@ bGPdata *BKE_gpencil_data_addnew(Main *bmain, const char name[])
gpd->runtime.batch_cache_data = NULL;
gpd->pixfactor = GP_DEFAULT_PIX_FACTOR;
/* grid settings */
ARRAY_SET_ITEMS(gpd->grid.color, 0.5f, 0.5f, 0.5f); // Color
ARRAY_SET_ITEMS(gpd->grid.scale, 1.0f, 1.0f); // Scale
gpd->grid.lines = GP_DEFAULT_GRID_LINES; // Number of lines
gpd->grid.axis = V3D_GP_GRID_AXIS_Y;
/* onion-skinning settings (datablock level) */
gpd->onion_flag |= (GP_ONION_GHOST_PREVCOL | GP_ONION_GHOST_NEXTCOL);
gpd->onion_flag |= GP_ONION_FADE;

View File

@ -1151,10 +1151,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
ARRAY_SET_ITEMS(v3d->overlay.gpencil_grid_scale, 1.0f, 1.0f); // Scale
v3d->overlay.gpencil_grid_lines = GP_DEFAULT_GRID_LINES; // NUmber of lines
v3d->overlay.gpencil_paper_opacity = 0.5f;
v3d->overlay.gpencil_grid_axis = V3D_GP_GRID_AXIS_Y;
v3d->overlay.gpencil_grid_opacity = 0.9f;
}
}
@ -1925,18 +1922,6 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "gpencil_grid_scale")) {
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
ARRAY_SET_ITEMS(v3d->overlay.gpencil_grid_scale, 1.0f, 1.0f);
}
}
}
}
}
if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "gpencil_paper_opacity")) {
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
@ -1961,30 +1946,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "int", "gpencil_grid_axis")) {
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
v3d->overlay.gpencil_grid_axis = V3D_GP_GRID_AXIS_Y;
}
}
}
}
}
if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "int", "gpencil_grid_lines")) {
for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
v3d->overlay.gpencil_grid_lines = GP_DEFAULT_GRID_LINES;
}
}
}
}
}
/* default loc axis */
if (!DNA_struct_elem_find(fd->filesdna, "GP_BrushEdit_Settings", "int", "lock_axis")) {
for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
@ -2192,5 +2154,15 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
unit->time_unit = bUnit_GetBaseUnitOfType(USER_UNIT_NONE, B_UNIT_TIME);
}
/* gpencil grid settings */
for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) {
ARRAY_SET_ITEMS(gpd->grid.color, 0.5f, 0.5f, 0.5f); // Color
ARRAY_SET_ITEMS(gpd->grid.scale, 1.0f, 1.0f); // Scale
gpd->grid.lines = GP_DEFAULT_GRID_LINES; // Number of lines
gpd->grid.axis = V3D_GP_GRID_AXIS_Y;
}
}
}

View File

@ -643,36 +643,38 @@ static void set_grid_point(
}
/* Draw grid lines */
GPUBatch *DRW_gpencil_get_grid(void)
GPUBatch *DRW_gpencil_get_grid(Object *ob)
{
const DRWContextState *draw_ctx = DRW_context_state_get();
Scene *scene = draw_ctx->scene;
ToolSettings *ts = scene->toolsettings;
View3D *v3d = draw_ctx->v3d;
const bool do_center = (v3d->overlay.gpencil_grid_lines <= 0) ? false : true;
bGPdata *gpd = (bGPdata *)ob->data;
const bool do_center = (gpd->grid.lines <= 0) ? false : true;
float col_grid[4];
/* verify we have something to draw and valid values */
if (v3d->overlay.gpencil_grid_scale[0] == 0.0f) {
v3d->overlay.gpencil_grid_scale[0] = 1.0f;
if (gpd->grid.scale[0] == 0.0f) {
gpd->grid.scale[0] = 1.0f;
}
if (v3d->overlay.gpencil_grid_scale[1] == 0.0f) {
v3d->overlay.gpencil_grid_scale[1] = 1.0f;
if (gpd->grid.scale[1] == 0.0f) {
gpd->grid.scale[1] = 1.0f;
}
if (v3d->overlay.gpencil_grid_opacity < 0.1f) {
v3d->overlay.gpencil_grid_opacity = 0.1f;
}
UI_GetThemeColor3fv(TH_GRID, col_grid);
/* set color */
copy_v3_v3(col_grid, gpd->grid.color);
col_grid[3] = v3d->overlay.gpencil_grid_opacity;
/* if use locked axis, copy value */
int axis = v3d->overlay.gpencil_grid_axis;
if ((v3d->overlay.gpencil_grid_axis & V3D_GP_GRID_AXIS_LOCK) == 0) {
int axis = gpd->grid.axis;
if ((gpd->grid.axis & V3D_GP_GRID_AXIS_LOCK) == 0) {
axis = v3d->overlay.gpencil_grid_axis;
axis = gpd->grid.axis;
}
else {
switch (ts->gp_sculpt.lock_axis) {
@ -696,9 +698,9 @@ GPUBatch *DRW_gpencil_get_grid(void)
}
const char *grid_unit = NULL;
const int gridlines = (v3d->overlay.gpencil_grid_lines <= 0) ? 1 : v3d->overlay.gpencil_grid_lines;
const float grid_w = v3d->overlay.gpencil_grid_scale[0] * ED_scene_grid_scale(scene, &grid_unit);
const float grid_h = v3d->overlay.gpencil_grid_scale[1] * ED_scene_grid_scale(scene, &grid_unit);
const int gridlines = (gpd->grid.lines <= 0) ? 1 : gpd->grid.lines;
const float grid_w = gpd->grid.scale[0] * ED_scene_grid_scale(scene, &grid_unit);
const float grid_h = gpd->grid.scale[1] * ED_scene_grid_scale(scene, &grid_unit);
const float space_w = (grid_w / gridlines);
const float space_h = (grid_h / gridlines);

View File

@ -606,7 +606,7 @@ void GPENCIL_cache_populate(void *vedata, Object *ob)
GPU_BATCH_DISCARD_SAFE(e_data.batch_grid);
MEM_SAFE_FREE(e_data.batch_grid);
e_data.batch_grid = DRW_gpencil_get_grid();
e_data.batch_grid = DRW_gpencil_get_grid(ob);
DRW_shgroup_call_add(
stl->g_data->shgrps_grid,
e_data.batch_grid,

View File

@ -316,7 +316,7 @@ struct GPUBatch *DRW_gpencil_get_edlin_geom(struct bGPDstroke *gps, float alpha,
struct GPUBatch *DRW_gpencil_get_buffer_stroke_geom(struct bGPdata *gpd, short thickness);
struct GPUBatch *DRW_gpencil_get_buffer_fill_geom(struct bGPdata *gpd);
struct GPUBatch *DRW_gpencil_get_buffer_point_geom(struct bGPdata *gpd, short thickness);
struct GPUBatch *DRW_gpencil_get_grid(void);
struct GPUBatch *DRW_gpencil_get_grid(Object *ob);
/* object cache functions */
struct tGPencilObjectCache *gpencil_object_cache_add(

View File

@ -350,10 +350,7 @@ static SpaceLink *view3d_new(const ScrArea *UNUSED(sa), const Scene *scene)
v3d->near = 0.01f;
v3d->far = 1000.0f;
ARRAY_SET_ITEMS(v3d->overlay.gpencil_grid_scale, 1.0f, 1.0f); // Scales
v3d->overlay.gpencil_grid_lines = GP_DEFAULT_GRID_LINES; // NUmber of Lines
v3d->overlay.gpencil_paper_opacity = 0.5f;
v3d->overlay.gpencil_grid_axis = V3D_GP_GRID_AXIS_Y;
v3d->overlay.gpencil_grid_opacity = 0.9f;
v3d->bundle_size = 0.2f;

View File

@ -39,7 +39,6 @@ struct CurveMapping;
struct GHash;
struct MDeformVert;
/* TODO: add size as userprefs parameter */
#define GP_OBGPENCIL_DEFAULT_SIZE 0.2f
#define GP_DEFAULT_PIX_FACTOR 1.0f
#define GP_DEFAULT_GRID_LINES 4
@ -325,6 +324,16 @@ typedef struct bGPdata_runtime {
char pad_[6];
} bGPdata_runtime;
/* grid configuration */
typedef struct bGPgrid {
float color[3];
float scale[2];
char _pad1[4];
int lines;
int axis;
} bGPgrid;
/* Grease-Pencil Annotations - 'DataBlock' */
typedef struct bGPdata {
ID id; /* Grease Pencil data is a datablock */
@ -366,6 +375,7 @@ typedef struct bGPdata {
int totpoint;
char pad_3[4];
bGPdata_runtime runtime;
bGPgrid grid;
} bGPdata;
/* bGPdata->flag */
@ -461,6 +471,14 @@ typedef enum eGP_DepthOrdering {
GP_XRAY_BACK = 2
} eGP_DepthOrdering;
/* gpencil_grid_axis */
enum {
V3D_GP_GRID_AXIS_LOCK = (1 << 0),
V3D_GP_GRID_AXIS_X = (1 << 1),
V3D_GP_GRID_AXIS_Y = (1 << 2),
V3D_GP_GRID_AXIS_Z = (1 << 3),
};
/* ***************************************** */
/* Mode Checking Macros */

View File

@ -190,10 +190,7 @@ typedef struct View3DOverlay {
float wireframe_threshold;
/* grease pencil settings */
float gpencil_grid_scale[2];
float gpencil_paper_opacity;
int gpencil_grid_lines;
int gpencil_grid_axis;
float gpencil_grid_opacity;
char _pad1[4];
@ -518,12 +515,4 @@ enum {
#define RV3D_CAMZOOM_MIN_FACTOR 0.1657359312880714853f
#define RV3D_CAMZOOM_MAX_FACTOR 44.9852813742385702928f
/* View3d.gpencil_grid_axis */
enum {
V3D_GP_GRID_AXIS_LOCK = (1 << 0),
V3D_GP_GRID_AXIS_X = (1 << 1),
V3D_GP_GRID_AXIS_Y = (1 << 2),
V3D_GP_GRID_AXIS_Z = (1 << 3),
};
#endif

View File

@ -71,6 +71,14 @@ static EnumPropertyItem rna_enum_gpencil_onion_modes_items[] = {
{ GP_ONION_MODE_SELECTED, "SELECTED", 0, "Selected", "Only Selected Frames" },
{ 0, NULL, 0, NULL, NULL }
};
static const EnumPropertyItem rna_enum_gpencil_grid_axis_items[] = {
{V3D_GP_GRID_AXIS_LOCK, "LOCK", 0, "Drawing Plane", "Use current drawing locked axis" },
{V3D_GP_GRID_AXIS_X, "X", 0, "Y-Z", ""},
{V3D_GP_GRID_AXIS_Y, "Y", 0, "X-Z", ""},
{V3D_GP_GRID_AXIS_Z, "Z", 0, "X-Y", ""},
{0, NULL, 0, NULL, NULL}
};
#endif
#ifdef RNA_RUNTIME
@ -1412,6 +1420,34 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
"Offset amount when drawing in surface mode");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
/* grid config */
prop = RNA_def_property(srna, "grid_scale", PROP_FLOAT, PROP_XYZ);
RNA_def_property_float_sdna(prop, NULL, "grid.scale");
RNA_def_property_range(prop, 0.01f, FLT_MAX);
RNA_def_property_float_default(prop, 1.0f);
RNA_def_property_ui_text(prop, "Grid Scale", "Grid scale");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "grid_color", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "grid.color");
RNA_def_property_array(prop, 3);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Grid Color", "Color for grid lines");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
prop = RNA_def_property(srna, "grid_lines", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "grid.lines");
RNA_def_property_range(prop, 0, INT_MAX);
RNA_def_property_int_default(prop, GP_DEFAULT_GRID_LINES);
RNA_def_property_ui_text(prop, "Grid Subdivisions", "Number of subdivisions in each side of symmetry line");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "grid_axis", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "grid.axis");
RNA_def_property_enum_items(prop, rna_enum_gpencil_grid_axis_items);
RNA_def_property_ui_text(prop, "Canvas Plane", "Axis to display grid");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
/* API Functions */
func = RNA_def_function(srna, "clear", "rna_GPencil_clear");
RNA_def_function_ui_description(func, "Remove all the grease pencil data");

View File

@ -310,14 +310,6 @@ const EnumPropertyItem rna_enum_file_sort_items[] = {
{0, NULL, 0, NULL, NULL}
};
static const EnumPropertyItem rna_enum_gpencil_grid_axis_items[] = {
{V3D_GP_GRID_AXIS_LOCK, "LOCK", 0, "Drawing Plane", "Use current drawing locked axis" },
{V3D_GP_GRID_AXIS_X, "X", 0, "Y-Z", ""},
{V3D_GP_GRID_AXIS_Y, "Y", 0, "X-Z", ""},
{V3D_GP_GRID_AXIS_Z, "Z", 0, "X-Y", ""},
{0, NULL, 0, NULL, NULL}
};
#ifdef RNA_RUNTIME
#include "DNA_anim_types.h"
@ -2961,26 +2953,6 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
"Display a grid over grease pencil paper");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "gpencil_grid_scale", PROP_FLOAT, PROP_XYZ);
RNA_def_property_float_sdna(prop, NULL, "overlay.gpencil_grid_scale");
RNA_def_property_range(prop, 0.01f, FLT_MAX);
RNA_def_property_float_default(prop, 1.0f);
RNA_def_property_ui_text(prop, "Scale", "Grid scale");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "gpencil_grid_lines", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "overlay.gpencil_grid_lines");
RNA_def_property_range(prop, 0, INT_MAX);
RNA_def_property_int_default(prop, GP_DEFAULT_GRID_LINES);
RNA_def_property_ui_text(prop, "Subdivisions", "Number of subdivisions in each side of symmetry line");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "gpencil_grid_axis", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "overlay.gpencil_grid_axis");
RNA_def_property_enum_items(prop, rna_enum_gpencil_grid_axis_items);
RNA_def_property_ui_text(prop, "Canvas Plane", "Axis to display grid");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "gpencil_grid_opacity", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "overlay.gpencil_grid_opacity");
RNA_def_property_range(prop, 0.1f, 1.0f);