2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-04-20 10:20:18 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-04-20 10:20:18 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2008, Blender Foundation
|
|
|
|
|
* This is a new part of Blender
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Joshua Leung
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
2011-02-27 20:40:57 +00:00
|
|
|
|
|
|
|
|
/** \file blender/blenkernel/intern/gpencil.c
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*/
|
|
|
|
|
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2013-11-06 10:59:05 +00:00
|
|
|
#include "BLI_math_vector.h"
|
2009-04-20 10:20:18 +00:00
|
|
|
|
2013-03-25 08:29:06 +00:00
|
|
|
#include "BLF_translation.h"
|
|
|
|
|
|
2009-04-20 10:20:18 +00:00
|
|
|
#include "DNA_gpencil_types.h"
|
2013-09-28 19:28:41 +00:00
|
|
|
#include "DNA_userdef_types.h"
|
2009-04-20 10:20:18 +00:00
|
|
|
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
#include "BKE_animsys.h"
|
2009-04-20 10:20:18 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_gpencil.h"
|
|
|
|
|
#include "BKE_library.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ************************************************** */
|
|
|
|
|
/* GENERAL STUFF */
|
|
|
|
|
|
|
|
|
|
/* --------- Memory Management ------------ */
|
|
|
|
|
|
|
|
|
|
/* Free strokes belonging to a gp-frame */
|
2013-11-25 04:55:26 +01:00
|
|
|
bool free_gpencil_strokes(bGPDframe *gpf)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDstroke *gps, *gpsn;
|
2014-02-08 06:07:10 +11:00
|
|
|
bool changed = (BLI_listbase_is_empty(&gpf->strokes) == false);
|
2013-12-03 09:22:29 +11:00
|
|
|
|
2009-04-20 10:20:18 +00:00
|
|
|
/* free strokes */
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gps = gpf->strokes.first; gps; gps = gpsn) {
|
|
|
|
|
gpsn = gps->next;
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* free stroke memory arrays, then stroke itself */
|
|
|
|
|
if (gps->points) MEM_freeN(gps->points);
|
|
|
|
|
BLI_freelinkN(&gpf->strokes, gps);
|
|
|
|
|
}
|
2013-11-25 04:55:26 +01:00
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
return changed;
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free all of a gp-layer's frames */
|
2012-04-29 17:11:40 +00:00
|
|
|
void free_gpencil_frames(bGPDlayer *gpl)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDframe *gpf, *gpfn;
|
|
|
|
|
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (gpl == NULL) return;
|
|
|
|
|
|
|
|
|
|
/* free frames */
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpfn) {
|
|
|
|
|
gpfn = gpf->next;
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* free strokes and their associated memory */
|
|
|
|
|
free_gpencil_strokes(gpf);
|
|
|
|
|
BLI_freelinkN(&gpl->frames, gpf);
|
|
|
|
|
}
|
2012-10-07 20:07:30 +00:00
|
|
|
gpl->actframe = NULL;
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free all of the gp-layers for a viewport (list should be &gpd->layers or so) */
|
2012-04-29 17:11:40 +00:00
|
|
|
void free_gpencil_layers(ListBase *list)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDlayer *gpl, *gpln;
|
|
|
|
|
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (list == NULL) return;
|
|
|
|
|
|
2012-08-17 14:43:20 +00:00
|
|
|
/* delete layers */
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gpl = list->first; gpl; gpl = gpln) {
|
|
|
|
|
gpln = gpl->next;
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* free layers and their data */
|
|
|
|
|
free_gpencil_frames(gpl);
|
|
|
|
|
BLI_freelinkN(list, gpl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free all of GPencil datablock's related data, but not the block itself */
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_gpencil_free(bGPdata *gpd)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
/* free layers */
|
|
|
|
|
free_gpencil_layers(&gpd->layers);
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
|
|
|
|
|
/* free animation data */
|
|
|
|
|
if (gpd->adt) {
|
2015-04-04 15:13:56 +11:00
|
|
|
BKE_animdata_free(&gpd->id);
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
gpd->adt = NULL;
|
|
|
|
|
}
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------- Container Creation ---------- */
|
|
|
|
|
|
|
|
|
|
/* add a new gp-frame to the given layer */
|
2012-05-06 15:15:33 +00:00
|
|
|
bGPDframe *gpencil_frame_addnew(bGPDlayer *gpl, int cframe)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDframe *gpf, *gf;
|
2012-05-06 15:15:33 +00:00
|
|
|
short state = 0;
|
2009-04-20 10:20:18 +00:00
|
|
|
|
2013-09-28 19:28:41 +00:00
|
|
|
/* error checking (neg frame only if they are not allowed in Blender!) */
|
2015-04-17 12:27:27 +12:00
|
|
|
if (gpl == NULL)
|
2009-04-20 10:20:18 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* allocate memory for this frame */
|
2012-05-06 15:15:33 +00:00
|
|
|
gpf = MEM_callocN(sizeof(bGPDframe), "bGPDframe");
|
|
|
|
|
gpf->framenum = cframe;
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* find appropriate place to add frame */
|
|
|
|
|
if (gpl->frames.first) {
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gf = gpl->frames.first; gf; gf = gf->next) {
|
2009-04-20 10:20:18 +00:00
|
|
|
/* check if frame matches one that is supposed to be added */
|
|
|
|
|
if (gf->framenum == cframe) {
|
2012-05-06 15:15:33 +00:00
|
|
|
state = -1;
|
2009-04-20 10:20:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if current frame has already exceeded the frame to add, add before */
|
|
|
|
|
if (gf->framenum > cframe) {
|
|
|
|
|
BLI_insertlinkbefore(&gpl->frames, gf, gpf);
|
2012-05-06 15:15:33 +00:00
|
|
|
state = 1;
|
2009-04-20 10:20:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check whether frame was added successfully */
|
|
|
|
|
if (state == -1) {
|
|
|
|
|
MEM_freeN(gpf);
|
2012-03-31 00:59:17 +00:00
|
|
|
printf("Error: frame (%d) existed already for this layer\n", cframe);
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
else if (state == 0) {
|
|
|
|
|
/* add to end then! */
|
|
|
|
|
BLI_addtail(&gpl->frames, gpf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* return frame */
|
|
|
|
|
return gpf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add a new gp-layer and make it the active layer */
|
2012-10-05 19:51:11 +00:00
|
|
|
bGPDlayer *gpencil_layer_addnew(bGPdata *gpd, const char *name, int setactive)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDlayer *gpl;
|
|
|
|
|
|
|
|
|
|
/* check that list is ok */
|
|
|
|
|
if (gpd == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* allocate memory for frame and add to end of list */
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl = MEM_callocN(sizeof(bGPDlayer), "bGPDlayer");
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* add to datablock */
|
|
|
|
|
BLI_addtail(&gpd->layers, gpl);
|
|
|
|
|
|
|
|
|
|
/* set basic settings */
|
2013-11-06 10:59:05 +00:00
|
|
|
copy_v4_v4(gpl->color, U.gpencil_new_layer_col);
|
2009-04-20 10:20:18 +00:00
|
|
|
gpl->thickness = 3;
|
|
|
|
|
|
|
|
|
|
/* auto-name */
|
2012-12-16 08:43:05 +00:00
|
|
|
BLI_strncpy(gpl->info, name, sizeof(gpl->info));
|
2013-03-25 08:29:06 +00:00
|
|
|
BLI_uniquename(&gpd->layers, gpl, DATA_("GP_Layer"), '.', offsetof(bGPDlayer, info), sizeof(gpl->info));
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* make this one the active one */
|
2012-10-05 19:51:11 +00:00
|
|
|
if (setactive)
|
2012-12-20 00:29:31 +00:00
|
|
|
gpencil_layer_setactive(gpd, gpl);
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* return layer */
|
|
|
|
|
return gpl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add a new gp-datablock */
|
2012-05-06 15:15:33 +00:00
|
|
|
bGPdata *gpencil_data_addnew(const char name[])
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPdata *gpd;
|
|
|
|
|
|
|
|
|
|
/* allocate memory for a new block */
|
2014-01-15 16:37:03 +01:00
|
|
|
gpd = BKE_libblock_alloc(G.main, ID_GD, name);
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* initial settings */
|
2012-05-06 15:15:33 +00:00
|
|
|
gpd->flag = (GP_DATA_DISPINFO | GP_DATA_EXPAND);
|
2009-04-20 10:20:18 +00:00
|
|
|
|
2009-08-30 11:37:29 +00:00
|
|
|
/* for now, stick to view is also enabled by default
|
|
|
|
|
* since this is more useful...
|
|
|
|
|
*/
|
|
|
|
|
gpd->flag |= GP_DATA_VIEWALIGN;
|
|
|
|
|
|
2009-04-20 10:20:18 +00:00
|
|
|
return gpd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------- Data Duplication ---------- */
|
|
|
|
|
|
|
|
|
|
/* make a copy of a given gpencil frame */
|
2012-05-06 15:15:33 +00:00
|
|
|
bGPDframe *gpencil_frame_duplicate(bGPDframe *src)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDstroke *gps, *gpsd;
|
|
|
|
|
bGPDframe *dst;
|
|
|
|
|
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (src == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* make a copy of the source frame */
|
2012-05-06 15:15:33 +00:00
|
|
|
dst = MEM_dupallocN(src);
|
|
|
|
|
dst->prev = dst->next = NULL;
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* copy strokes */
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(&dst->strokes);
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gps = src->strokes.first; gps; gps = gps->next) {
|
2009-04-20 10:20:18 +00:00
|
|
|
/* make copy of source stroke, then adjust pointer to points too */
|
2012-05-06 15:15:33 +00:00
|
|
|
gpsd = MEM_dupallocN(gps);
|
|
|
|
|
gpsd->points = MEM_dupallocN(gps->points);
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
BLI_addtail(&dst->strokes, gpsd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* return new frame */
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* make a copy of a given gpencil layer */
|
2012-05-06 15:15:33 +00:00
|
|
|
bGPDlayer *gpencil_layer_duplicate(bGPDlayer *src)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDframe *gpf, *gpfd;
|
|
|
|
|
bGPDlayer *dst;
|
|
|
|
|
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (src == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* make a copy of source layer */
|
2012-05-06 15:15:33 +00:00
|
|
|
dst = MEM_dupallocN(src);
|
|
|
|
|
dst->prev = dst->next = NULL;
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* copy frames */
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(&dst->frames);
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gpf = src->frames.first; gpf; gpf = gpf->next) {
|
2009-04-20 10:20:18 +00:00
|
|
|
/* make a copy of source frame */
|
2012-05-06 15:15:33 +00:00
|
|
|
gpfd = gpencil_frame_duplicate(gpf);
|
2009-04-20 10:20:18 +00:00
|
|
|
BLI_addtail(&dst->frames, gpfd);
|
|
|
|
|
|
|
|
|
|
/* if source frame was the current layer's 'active' frame, reassign that too */
|
|
|
|
|
if (gpf == dst->actframe)
|
2012-05-06 15:15:33 +00:00
|
|
|
dst->actframe = gpfd;
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* return new layer */
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* make a copy of a given gpencil datablock */
|
2014-11-22 18:03:37 +13:00
|
|
|
bGPdata *gpencil_data_duplicate(bGPdata *src, bool internal_copy)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDlayer *gpl, *gpld;
|
|
|
|
|
bGPdata *dst;
|
|
|
|
|
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (src == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* make a copy of the base-data */
|
2014-11-22 18:03:37 +13:00
|
|
|
if (internal_copy) {
|
|
|
|
|
/* make a straight copy for undo buffers used during stroke drawing */
|
|
|
|
|
dst = MEM_dupallocN(src);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* make a copy when others use this */
|
|
|
|
|
dst = BKE_libblock_copy(&src->id);
|
|
|
|
|
}
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* copy layers */
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(&dst->layers);
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gpl = src->layers.first; gpl; gpl = gpl->next) {
|
2009-04-20 10:20:18 +00:00
|
|
|
/* make a copy of source layer and its data */
|
2012-05-06 15:15:33 +00:00
|
|
|
gpld = gpencil_layer_duplicate(gpl);
|
2009-04-20 10:20:18 +00:00
|
|
|
BLI_addtail(&dst->layers, gpld);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* return new */
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
/* -------- GP-Stroke API --------- */
|
|
|
|
|
|
|
|
|
|
/* ensure selection status of stroke is in sync with its points */
|
|
|
|
|
void gpencil_stroke_sync_selection(bGPDstroke *gps)
|
|
|
|
|
{
|
|
|
|
|
bGPDspoint *pt;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (gps == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* we'll stop when we find the first selected point,
|
|
|
|
|
* so initially, we must deselect
|
|
|
|
|
*/
|
|
|
|
|
gps->flag &= ~GP_STROKE_SELECT;
|
|
|
|
|
|
|
|
|
|
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
|
|
|
|
|
if (pt->flag & GP_SPOINT_SELECT) {
|
|
|
|
|
gps->flag |= GP_STROKE_SELECT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-20 10:20:18 +00:00
|
|
|
/* -------- GP-Frame API ---------- */
|
|
|
|
|
|
|
|
|
|
/* delete the last stroke of the given frame */
|
2012-04-29 17:11:40 +00:00
|
|
|
void gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
bGPDstroke *gps = (gpf) ? gpf->strokes.last : NULL;
|
2009-08-31 01:58:11 +00:00
|
|
|
int cfra = (gpf) ? gpf->framenum : 0; /* assume that the current frame was not locked */
|
2009-04-20 10:20:18 +00:00
|
|
|
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (ELEM(NULL, gpf, gps))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* free the stroke and its data */
|
|
|
|
|
MEM_freeN(gps->points);
|
|
|
|
|
BLI_freelinkN(&gpf->strokes, gps);
|
|
|
|
|
|
|
|
|
|
/* if frame has no strokes after this, delete it */
|
2014-02-08 06:07:10 +11:00
|
|
|
if (BLI_listbase_is_empty(&gpf->strokes)) {
|
2009-04-20 10:20:18 +00:00
|
|
|
gpencil_layer_delframe(gpl, gpf);
|
|
|
|
|
gpencil_layer_getframe(gpl, cfra, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------- GP-Layer API ---------- */
|
|
|
|
|
|
2012-06-08 22:07:57 +00:00
|
|
|
bGPDframe *BKE_gpencil_layer_find_frame(bGPDlayer *gpl, int cframe)
|
|
|
|
|
{
|
|
|
|
|
bGPDframe *gpf;
|
|
|
|
|
|
|
|
|
|
for (gpf = gpl->frames.last; gpf; gpf = gpf->prev) {
|
|
|
|
|
if (gpf->framenum == cframe) {
|
|
|
|
|
return gpf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-20 10:20:18 +00:00
|
|
|
/* get the appropriate gp-frame from a given layer
|
|
|
|
|
* - this sets the layer's actframe var (if allowed to)
|
|
|
|
|
* - extension beyond range (if first gp-frame is after all frame in interest and cannot add)
|
|
|
|
|
*/
|
2012-05-06 15:15:33 +00:00
|
|
|
bGPDframe *gpencil_layer_getframe(bGPDlayer *gpl, int cframe, short addnew)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDframe *gpf = NULL;
|
|
|
|
|
short found = 0;
|
|
|
|
|
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (gpl == NULL) return NULL;
|
|
|
|
|
|
|
|
|
|
/* check if there is already an active frame */
|
|
|
|
|
if (gpl->actframe) {
|
2012-05-06 15:15:33 +00:00
|
|
|
gpf = gpl->actframe;
|
2009-04-20 10:20:18 +00:00
|
|
|
|
2010-01-08 01:39:41 +00:00
|
|
|
/* do not allow any changes to layer's active frame if layer is locked from changes
|
|
|
|
|
* or if the layer has been set to stay on the current frame
|
|
|
|
|
*/
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
if (gpl->flag & GP_LAYER_FRAMELOCK)
|
2009-04-20 10:20:18 +00:00
|
|
|
return gpf;
|
|
|
|
|
/* do not allow any changes to actframe if frame has painting tag attached to it */
|
|
|
|
|
if (gpf->flag & GP_FRAME_PAINT)
|
|
|
|
|
return gpf;
|
|
|
|
|
|
|
|
|
|
/* try to find matching frame */
|
|
|
|
|
if (gpf->framenum < cframe) {
|
2012-05-06 15:15:33 +00:00
|
|
|
for (; gpf; gpf = gpf->next) {
|
2009-04-20 10:20:18 +00:00
|
|
|
if (gpf->framenum == cframe) {
|
2012-05-06 15:15:33 +00:00
|
|
|
found = 1;
|
2009-04-20 10:20:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if ((gpf->next) && (gpf->next->framenum > cframe)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
found = 1;
|
2009-04-20 10:20:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set the appropriate frame */
|
|
|
|
|
if (addnew) {
|
|
|
|
|
if ((found) && (gpf->framenum == cframe))
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpf;
|
2009-04-20 10:20:18 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpencil_frame_addnew(gpl, cframe);
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
else if (found)
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpf;
|
2009-04-20 10:20:18 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpl->frames.last;
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
for (; gpf; gpf = gpf->prev) {
|
2009-04-20 10:20:18 +00:00
|
|
|
if (gpf->framenum <= cframe) {
|
2012-05-06 15:15:33 +00:00
|
|
|
found = 1;
|
2009-04-20 10:20:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set the appropriate frame */
|
|
|
|
|
if (addnew) {
|
|
|
|
|
if ((found) && (gpf->framenum == cframe))
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpf;
|
2009-04-20 10:20:18 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpencil_frame_addnew(gpl, cframe);
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
else if (found)
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpf;
|
2009-04-20 10:20:18 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpl->frames.first;
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (gpl->frames.first) {
|
|
|
|
|
/* check which of the ends to start checking from */
|
2012-05-06 15:15:33 +00:00
|
|
|
const int first = ((bGPDframe *)(gpl->frames.first))->framenum;
|
|
|
|
|
const int last = ((bGPDframe *)(gpl->frames.last))->framenum;
|
2009-04-20 10:20:18 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (abs(cframe - first) > abs(cframe - last)) {
|
2009-04-20 10:20:18 +00:00
|
|
|
/* find gp-frame which is less than or equal to cframe */
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gpf = gpl->frames.last; gpf; gpf = gpf->prev) {
|
2009-04-20 10:20:18 +00:00
|
|
|
if (gpf->framenum <= cframe) {
|
2012-05-06 15:15:33 +00:00
|
|
|
found = 1;
|
2009-04-20 10:20:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* find gp-frame which is less than or equal to cframe */
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
|
2009-04-20 10:20:18 +00:00
|
|
|
if (gpf->framenum <= cframe) {
|
2012-05-06 15:15:33 +00:00
|
|
|
found = 1;
|
2009-04-20 10:20:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set the appropriate frame */
|
|
|
|
|
if (addnew) {
|
|
|
|
|
if ((found) && (gpf->framenum == cframe))
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpf;
|
2009-04-20 10:20:18 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpencil_frame_addnew(gpl, cframe);
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
else if (found)
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpf;
|
2009-04-20 10:20:18 +00:00
|
|
|
else {
|
|
|
|
|
/* unresolved errogenous situation! */
|
2012-03-31 00:59:17 +00:00
|
|
|
printf("Error: cannot find appropriate gp-frame\n");
|
2009-04-20 10:20:18 +00:00
|
|
|
/* gpl->actframe should still be NULL */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* currently no frames (add if allowed to) */
|
|
|
|
|
if (addnew)
|
2012-05-06 15:15:33 +00:00
|
|
|
gpl->actframe = gpencil_frame_addnew(gpl, cframe);
|
2009-04-20 10:20:18 +00:00
|
|
|
else {
|
|
|
|
|
/* don't do anything... this may be when no frames yet! */
|
|
|
|
|
/* gpl->actframe should still be NULL */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* return */
|
|
|
|
|
return gpl->actframe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* delete the given frame from a layer */
|
2013-11-25 04:55:26 +01:00
|
|
|
bool gpencil_layer_delframe(bGPDlayer *gpl, bGPDframe *gpf)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
2013-11-26 06:39:14 +11:00
|
|
|
bool changed = false;
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
|
2009-04-20 10:20:18 +00:00
|
|
|
/* error checking */
|
|
|
|
|
if (ELEM(NULL, gpl, gpf))
|
2013-11-25 04:55:26 +01:00
|
|
|
return false;
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
|
|
|
|
|
/* if this frame was active, make the previous frame active instead
|
|
|
|
|
* since it's tricky to set active frame otherwise
|
|
|
|
|
*/
|
|
|
|
|
if (gpl->actframe == gpf)
|
|
|
|
|
gpl->actframe = gpf->prev;
|
|
|
|
|
else
|
|
|
|
|
gpl->actframe = NULL;
|
|
|
|
|
|
2009-04-20 10:20:18 +00:00
|
|
|
/* free the frame and its data */
|
2013-11-26 06:39:14 +11:00
|
|
|
changed = free_gpencil_strokes(gpf);
|
2009-04-20 10:20:18 +00:00
|
|
|
BLI_freelinkN(&gpl->frames, gpf);
|
Grease Pencil - Storyboarding Features (merge from GPencil_EditStrokes branch)
This merge-commit brings in a number of new features and workflow/UI improvements for
working with Grease Pencil. While these were originally targetted at improving
the workflow for creating 3D storyboards in Blender using the Grease Pencil,
many of these changes should also prove useful in other workflows too.
The main highlights here are:
1) It is now possible to edit Grease Pencil strokes
- Use D Tab, or toggle the "Enable Editing" toggles in the Toolbar/Properties regions
to enter "Stroke Edit Mode". In this mode, many common editing tools will
operate on Grease Pencil stroke points instead.
- Tools implemented include Select, Select All/Border/Circle/Linked/More/Less,
Grab, Rotate, Scale, Bend, Shear, To Sphere, Mirror, Duplicate, Delete.
- Proportional Editing works when using the transform tools
2) Grease Pencil stroke settings can now be animated
NOTE: Currently drivers don't work, but if time allows, this may still be
added before the release.
3) Strokes can be drawn with "filled" interiors, using a separate set of
colour/opacity settings to the ones used for the lines themselves.
This makes use of OpenGL filled polys, which has the limitation of only
being able to fill convex shapes. Some artifacts may be visible on concave
shapes (e.g. pacman's mouth will be overdrawn)
4) "Volumetric Strokes" - An alternative drawing technique for stroke drawing
has been added which draws strokes as a series of screen-aligned discs.
While this was originally a partial experimental technique at getting better
quality 3D lines, the effects possible using this technique were interesting
enough to warrant making this a dedicated feature. Best results when partial
opacity and large stroke widths are used.
5) Improved Onion Skinning Support
- Different colours can be selected for the before/after ghosts. To do so,
enable the "colour wheel" toggle beside the Onion Skinning toggle, and set
the colours accordingly.
- Different numbers of ghosts can be shown before/after the current frame
6) Grease Pencil datablocks are now attached to the scene by default instead of
the active object.
- For a long time, the object-attachment has proved to be quite problematic
for users to keep track of. Now that this is done at scene level, it is
easier for most users to use.
- An exception for old files (and for any addons which may benefit from object
attachment instead), is that if the active object has a Grease Pencil datablock,
that will be used instead.
- It is not currently possible to choose object-attachment from the UI, but
it is simple to do this from the console instead, by doing:
context.active_object.grease_pencil = bpy.data.grease_pencil["blah"]
7) Various UI Cleanups
- The layers UI has been cleaned up to use a list instead of the nested-panels
design. Apart from saving space, this is also much nicer to look at now.
- The UI code is now all defined in Python. To support this, it has been necessary
to add some new context properties to make it easier to access these settings.
e.g. "gpencil_data" for the datablock
"active_gpencil_layer" and "active_gpencil_frame" for active data,
"editable_gpencil_strokes" for the strokes that can be edited
- The "stroke placement/alignment" settings (previously "Drawing Settings" at the
bottom of the Grease Pencil panel in the Properties Region) is now located in
the toolbar. These were more toolsettings than properties for how GPencil got drawn.
- "Use Sketching Sessions" has been renamed "Continuous Drawing", as per a
suggestion for an earlier discussion on developer.blender.org
- By default, the painting operator will wait for a mouse button to be pressed
before it starts creating the stroke. This is to make it easier to include
this operator in various toolbars/menus/etc. To get it immediately starting
(as when you hold down DKEy to draw), set "wait_for_input" to False.
- GPencil Layers can be rearranged in the "Grease Pencil" mode of the Action Editor
- Toolbar panels have been added to all the other editors which support these.
8) Pie menus for quick-access to tools
A set of experimental pie menus has been included for quick access to many
tools and settings. It is not necessary to use these to get things done,
but they have been designed to help make certain common tasks easier.
- Ctrl-D = The main pie menu. Reveals tools in a context sensitive and
spatially stable manner.
- D Q = "Quick Settings" pie. This allows quick access to the active
layer's settings. Notably, colours, thickness, and turning
onion skinning on/off.
2014-12-01 01:52:06 +13:00
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
return changed;
|
2009-04-20 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get the active gp-layer for editing */
|
2012-05-06 15:15:33 +00:00
|
|
|
bGPDlayer *gpencil_layer_getactive(bGPdata *gpd)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDlayer *gpl;
|
|
|
|
|
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (ELEM(NULL, gpd, gpd->layers.first))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* loop over layers until found (assume only one active) */
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
|
2009-04-20 10:20:18 +00:00
|
|
|
if (gpl->flag & GP_LAYER_ACTIVE)
|
|
|
|
|
return gpl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* no active layer found */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set the active gp-layer */
|
2012-04-29 17:11:40 +00:00
|
|
|
void gpencil_layer_setactive(bGPdata *gpd, bGPDlayer *active)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
bGPDlayer *gpl;
|
|
|
|
|
|
|
|
|
|
/* error checking */
|
2014-07-20 01:30:29 +10:00
|
|
|
if (ELEM(NULL, gpd, gpd->layers.first, active))
|
2009-04-20 10:20:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* loop over layers deactivating all */
|
2012-05-06 15:15:33 +00:00
|
|
|
for (gpl = gpd->layers.first; gpl; gpl = gpl->next)
|
2009-04-20 10:20:18 +00:00
|
|
|
gpl->flag &= ~GP_LAYER_ACTIVE;
|
|
|
|
|
|
|
|
|
|
/* set as active one */
|
|
|
|
|
active->flag |= GP_LAYER_ACTIVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* delete the active gp-layer */
|
2012-10-05 19:51:11 +00:00
|
|
|
void gpencil_layer_delete(bGPdata *gpd, bGPDlayer *gpl)
|
2009-04-20 10:20:18 +00:00
|
|
|
{
|
|
|
|
|
/* error checking */
|
|
|
|
|
if (ELEM(NULL, gpd, gpl))
|
|
|
|
|
return;
|
|
|
|
|
|
2012-10-21 05:46:41 +00:00
|
|
|
/* free layer */
|
2009-04-20 10:20:18 +00:00
|
|
|
free_gpencil_frames(gpl);
|
|
|
|
|
BLI_freelinkN(&gpd->layers, gpl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************************************************** */
|