利用者:Antoniov/Grease Pencil Design Changes

提供: wiki
移動先: 案内検索

Grease Pencil: Design Changes

Introduction

As part of the new design, we have tried to keep the old structure as much as possible in order to avoid problems with add-ons and other tools that are working with GP.

These revamp is focused on converting the grease pencil in a tool for 2D animators, so we have been working in the artistic part of the tool and we have not changed anything related to other uses of the tool like ruler or motion tracking.

As we have kept the current GPdata->GPDlayer->GPDframe->GPDstroke->GPDpoint structure, all the main functionality remains equal and should be no problem for other tools.

Data structure

Dev-gp-datamodel.jpg

The main structure has not changed, and only some API have changed (see https://wiki.blender.org/index.php/User:Antoniov/Grease_Pencil_Api_Changes)

Blender3D FreeTip.png
Future Changes
The bGPDpalette and bGPDpalettecolor will be removed in Blender 2.8 and replace by Blender palette and palettecolor. To see more details: https://wiki.blender.org/index.php/User:Antoniov/Convert_bGPDpalettes_to_BlenderPalettes


New data

In order to store new information, we have added the following structures:

bGPDPalette: This listbase is stored in bGPdata and contains the palettes asociated to a GPD block. The initial idea was to create a palette for all GPdata, but for tecnical and artistic reasons, finally was added to GP data block.

A palette works as a container for all the colors (bGPDpalettecolor).

bGPDpalettecolor: Contains the information of color and fill attributes. The stroke saves the color name (not pointer) but during drawing a temporary pointer to the color is used.


bGPDtriangle: Contains information of the triangulation necessary to generate the fill. This information is only recalculated when the stroke is modified or a new file is loaded. The information is available in python.


bGPDbrush: Added as part of scene toolsettings, contains the information of the current drawing brush. This is information is not saved in the stroke or point and is only used during drawing in order to calculate the position of the points and color strength.

Drawing Brushes

All drawing brushes play with three parameters: Position, Pressure and Strength.

The position of the point defines where the point is in 3D space. The pressure is used to calculate the thickness. The thickness is the result of multiply the stroke thickness (base thickness) by pressure. A pressure can be any value >= 0.

The color strength is used to define the alpha factor of the color. This value must be between 0.0 and 1.0.

For effects as marker brush (defined by angle parameter), the program calculates the direction of the current point (using previous one to create a vector) and compare this vector with the full thickness vector.

Using the angle in a range of 90 degress, the pressure value is adjusted to get the thickness. This idea is described in the image below.

Dev-gp-marker.jpg

Additionally, a minimum value for pressure is used in order to avoid invisible lines.

All brush information is not saved in the stroke. The stroke saves the result of apply brush values to the current position and pressure.

Parenting

Parent strokes to objects and bones is an important requirement. As the GP block is not an object and the artist needs to parent different layer of the same scene to different objects/bones in the same GP block, the following fields have been added to layer:

  • Parent object
  • Parent inverse Matrix
  • Parent type (Object, Armature or Bone)
  • Parent substring (only if bone type)

When the user parent a layer, the current inverse matrix is calculated and saved in inverse field.

During drawing, the difference matrix between inverse matrix and current transformation matrix is calculated and applied to the position of the point. If the type is Bone, the Parent substring is used to find the corresponding bone pose transformation matrix.

In order to calculate very fast the current position of the parent object, a internal reference to the parented object is included in the layer.

If the user removes the object or clear the parent, the stroke is recalculated and keeps the current position, not the position before parenting. This is more convinient for GP drawings.

Example parent panel:

Dev-gp-parent-panel.jpg

Conversion of old file

Dev-gp-file-conversion.jpg

When loading new files, the Blender file version is checked to verify if the file needs conversion.

To convert, all bGPdata block are read and for each of them a new palette is added. Next, a loop reads all layers and create a color for each layer in the palette. Now all frames and strokes are read, and the color information and thickness is set at bGPDstroke level.

For each point of the stroke, only the new field strength is filled with 1, because the conversion assume that the color is full strength.

For the triangle information (bGPDtriangle), the flag is set to force a new recalculation of the cache. The information will be filled in the next drawing. The same logic is used with the pointer to stroke color. The conversion only fills the color name, and set the color pointer to NULL. In the first drawing, the pointer is checked and then is filled with the corresponding pointer to bGPDpalettecolor in order to speed up the drawing routines.